Merge commit '85082fd7cbe3173198aac0eb5e85ab1edcc6352c' into test-build
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 15 Jul 2008 05:44:51 +0000 (15:44 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 15 Jul 2008 05:44:51 +0000 (15:44 +1000)
Manual fixup of:

arch/powerpc/Kconfig

1940 files changed:
Documentation/ABI/testing/sysfs-block
Documentation/ABI/testing/sysfs-bus-css [new file with mode: 0644]
Documentation/ABI/testing/sysfs-firmware-memmap [new file with mode: 0644]
Documentation/block/data-integrity.txt [new file with mode: 0644]
Documentation/ftrace.txt
Documentation/i386/IO-APIC.txt [deleted file]
Documentation/i386/boot.txt [deleted file]
Documentation/i386/usb-legacy-support.txt [deleted file]
Documentation/i386/zero-page.txt [deleted file]
Documentation/ioctl-number.txt
Documentation/kdump/kdump.txt
Documentation/kernel-parameters.txt
Documentation/nmi_watchdog.txt
Documentation/scheduler/sched-domains.txt
Documentation/scheduler/sched-rt-group.txt
Documentation/sound/alsa/ALSA-Configuration.txt
Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
Documentation/tracers/mmiotrace.txt [new file with mode: 0644]
Documentation/x86/i386/IO-APIC.txt [new file with mode: 0644]
Documentation/x86/i386/boot.txt [new file with mode: 0644]
Documentation/x86/i386/usb-legacy-support.txt [new file with mode: 0644]
Documentation/x86/i386/zero-page.txt [new file with mode: 0644]
Documentation/x86/x86_64/00-INDEX [new file with mode: 0644]
Documentation/x86/x86_64/boot-options.txt [new file with mode: 0644]
Documentation/x86/x86_64/cpu-hotplug-spec [new file with mode: 0644]
Documentation/x86/x86_64/fake-numa-for-cpusets [new file with mode: 0644]
Documentation/x86/x86_64/kernel-stacks [new file with mode: 0644]
Documentation/x86/x86_64/machinecheck [new file with mode: 0644]
Documentation/x86/x86_64/mm.txt [new file with mode: 0644]
Documentation/x86/x86_64/uefi.txt [new file with mode: 0644]
Documentation/x86_64/00-INDEX [deleted file]
Documentation/x86_64/boot-options.txt [deleted file]
Documentation/x86_64/cpu-hotplug-spec [deleted file]
Documentation/x86_64/fake-numa-for-cpusets [deleted file]
Documentation/x86_64/kernel-stacks [deleted file]
Documentation/x86_64/machinecheck [deleted file]
Documentation/x86_64/mm.txt [deleted file]
Documentation/x86_64/uefi.txt [deleted file]
MAINTAINERS
Makefile
arch/arm/Kconfig
arch/arm/Makefile
arch/arm/boot/compressed/Makefile
arch/arm/boot/compressed/head.S
arch/arm/common/Makefile
arch/arm/common/rtctime.c [deleted file]
arch/arm/common/sharpsl_pm.c
arch/arm/configs/at91cap9adk_defconfig
arch/arm/configs/at91rm9200dk_defconfig
arch/arm/configs/at91rm9200ek_defconfig
arch/arm/configs/at91sam9260ek_defconfig
arch/arm/configs/at91sam9261ek_defconfig
arch/arm/configs/at91sam9263ek_defconfig
arch/arm/configs/at91sam9g20ek_defconfig [new file with mode: 0644]
arch/arm/configs/at91sam9rlek_defconfig
arch/arm/configs/ateb9200_defconfig
arch/arm/configs/cm_x270_defconfig [deleted file]
arch/arm/configs/collie_defconfig
arch/arm/configs/corgi_defconfig
arch/arm/configs/ecbat91_defconfig
arch/arm/configs/em_x270_defconfig [deleted file]
arch/arm/configs/ep93xx_defconfig
arch/arm/configs/eseries_pxa_defconfig
arch/arm/configs/imx27ads_defconfig [new file with mode: 0644]
arch/arm/configs/iop13xx_defconfig
arch/arm/configs/iop32x_defconfig
arch/arm/configs/iop33x_defconfig
arch/arm/configs/ixp2000_defconfig
arch/arm/configs/ixp23xx_defconfig
arch/arm/configs/ixp4xx_defconfig
arch/arm/configs/kafa_defconfig
arch/arm/configs/kb9202_defconfig
arch/arm/configs/kirkwood_defconfig [new file with mode: 0644]
arch/arm/configs/ks8695_defconfig
arch/arm/configs/loki_defconfig [new file with mode: 0644]
arch/arm/configs/lpd270_defconfig
arch/arm/configs/lpd7a404_defconfig
arch/arm/configs/mv78xx0_defconfig [new file with mode: 0644]
arch/arm/configs/mx31ads_defconfig [new file with mode: 0644]
arch/arm/configs/mx31litekit_defconfig [new file with mode: 0644]
arch/arm/configs/netx_defconfig
arch/arm/configs/onearm_defconfig
arch/arm/configs/orion5x_defconfig
arch/arm/configs/pcm037_defconfig [new file with mode: 0644]
arch/arm/configs/pcm038_defconfig [new file with mode: 0644]
arch/arm/configs/picotux200_defconfig
arch/arm/configs/pnx4008_defconfig
arch/arm/configs/qil-a9260_defconfig [new file with mode: 0644]
arch/arm/configs/realview-smp_defconfig
arch/arm/configs/realview_defconfig
arch/arm/configs/rpc_defconfig
arch/arm/configs/s3c2410_defconfig
arch/arm/configs/sam9_l9260_defconfig
arch/arm/configs/spitz_defconfig
arch/arm/configs/tct_hammer_defconfig
arch/arm/configs/trizeps4_defconfig
arch/arm/configs/usb-a9260_defconfig [new file with mode: 0644]
arch/arm/configs/usb-a9263_defconfig [new file with mode: 0644]
arch/arm/configs/versatile_defconfig
arch/arm/configs/xm_x270_defconfig [new file with mode: 0644]
arch/arm/kernel/Makefile
arch/arm/kernel/armksyms.c
arch/arm/kernel/atags.c
arch/arm/kernel/ecard.c
arch/arm/kernel/ecard.h
arch/arm/kernel/entry-common.S
arch/arm/kernel/ftrace.c [new file with mode: 0644]
arch/arm/kernel/kprobes.c
arch/arm/kernel/process.c
arch/arm/kernel/stacktrace.c
arch/arm/kernel/time.c
arch/arm/lib/copy_template.S
arch/arm/lib/memmove.S
arch/arm/lib/memset.S
arch/arm/lib/memzero.S
arch/arm/mach-at91/Kconfig
arch/arm/mach-at91/Makefile
arch/arm/mach-at91/at91cap9_devices.c
arch/arm/mach-at91/at91sam9260.c
arch/arm/mach-at91/at91sam9260_devices.c
arch/arm/mach-at91/at91sam9261_devices.c
arch/arm/mach-at91/at91sam9263_devices.c
arch/arm/mach-at91/at91sam9rl_devices.c
arch/arm/mach-at91/board-cap9adk.c
arch/arm/mach-at91/board-carmeva.c
arch/arm/mach-at91/board-csb637.c
arch/arm/mach-at91/board-dk.c
arch/arm/mach-at91/board-eb9200.c
arch/arm/mach-at91/board-ek.c
arch/arm/mach-at91/board-kb9202.c
arch/arm/mach-at91/board-qil-a9260.c [new file with mode: 0644]
arch/arm/mach-at91/board-sam9g20ek.c [new file with mode: 0644]
arch/arm/mach-at91/board-sam9rlek.c
arch/arm/mach-at91/board-usb-a9260.c [new file with mode: 0644]
arch/arm/mach-at91/board-usb-a9263.c [new file with mode: 0644]
arch/arm/mach-at91/board-yl-9200.c
arch/arm/mach-at91/clock.c
arch/arm/mach-at91/pm.c
arch/arm/mach-ep93xx/clock.c
arch/arm/mach-footbridge/Makefile
arch/arm/mach-footbridge/co285.c [deleted file]
arch/arm/mach-footbridge/common.c
arch/arm/mach-footbridge/ebsa285-leds.c
arch/arm/mach-footbridge/time.c
arch/arm/mach-imx/Makefile
arch/arm/mach-imx/clock.c [new file with mode: 0644]
arch/arm/mach-imx/cpufreq.c
arch/arm/mach-imx/dma.c
arch/arm/mach-imx/generic.c
arch/arm/mach-imx/mx1ads.c
arch/arm/mach-imx/time.c
arch/arm/mach-integrator/Makefile
arch/arm/mach-integrator/time.c [deleted file]
arch/arm/mach-ixp4xx/Kconfig
arch/arm/mach-ixp4xx/Makefile
arch/arm/mach-ixp4xx/common.c
arch/arm/mach-ixp4xx/fsg-pci.c [new file with mode: 0644]
arch/arm/mach-ixp4xx/fsg-setup.c [new file with mode: 0644]
arch/arm/mach-kirkwood/Kconfig [new file with mode: 0644]
arch/arm/mach-kirkwood/Makefile [new file with mode: 0644]
arch/arm/mach-kirkwood/Makefile.boot [new file with mode: 0644]
arch/arm/mach-kirkwood/addr-map.c [new file with mode: 0644]
arch/arm/mach-kirkwood/common.c [new file with mode: 0644]
arch/arm/mach-kirkwood/common.h [new file with mode: 0644]
arch/arm/mach-kirkwood/db88f6281-bp-setup.c [new file with mode: 0644]
arch/arm/mach-kirkwood/irq.c [new file with mode: 0644]
arch/arm/mach-kirkwood/pcie.c [new file with mode: 0644]
arch/arm/mach-kirkwood/rd88f6192-nas-setup.c [new file with mode: 0644]
arch/arm/mach-kirkwood/rd88f6281-setup.c [new file with mode: 0644]
arch/arm/mach-loki/Kconfig [new file with mode: 0644]
arch/arm/mach-loki/Makefile [new file with mode: 0644]
arch/arm/mach-loki/Makefile.boot [new file with mode: 0644]
arch/arm/mach-loki/addr-map.c [new file with mode: 0644]
arch/arm/mach-loki/common.c [new file with mode: 0644]
arch/arm/mach-loki/common.h [new file with mode: 0644]
arch/arm/mach-loki/irq.c [new file with mode: 0644]
arch/arm/mach-loki/lb88rc8480-setup.c [new file with mode: 0644]
arch/arm/mach-mv78xx0/Kconfig [new file with mode: 0644]
arch/arm/mach-mv78xx0/Makefile [new file with mode: 0644]
arch/arm/mach-mv78xx0/Makefile.boot [new file with mode: 0644]
arch/arm/mach-mv78xx0/addr-map.c [new file with mode: 0644]
arch/arm/mach-mv78xx0/common.c [new file with mode: 0644]
arch/arm/mach-mv78xx0/common.h [new file with mode: 0644]
arch/arm/mach-mv78xx0/db78x00-bp-setup.c [new file with mode: 0644]
arch/arm/mach-mv78xx0/irq.c [new file with mode: 0644]
arch/arm/mach-mv78xx0/pcie.c [new file with mode: 0644]
arch/arm/mach-mx2/Kconfig [new file with mode: 0644]
arch/arm/mach-mx2/Makefile [new file with mode: 0644]
arch/arm/mach-mx2/Makefile.boot [new file with mode: 0644]
arch/arm/mach-mx2/clock_imx27.c [new file with mode: 0644]
arch/arm/mach-mx2/cpu_imx27.c [new file with mode: 0644]
arch/arm/mach-mx2/crm_regs.h [new file with mode: 0644]
arch/arm/mach-mx2/devices.c [new file with mode: 0644]
arch/arm/mach-mx2/generic.c [new file with mode: 0644]
arch/arm/mach-mx2/mx27ads.c [new file with mode: 0644]
arch/arm/mach-mx2/pcm038.c [new file with mode: 0644]
arch/arm/mach-mx2/pcm970-baseboard.c [new file with mode: 0644]
arch/arm/mach-mx2/serial.c [new file with mode: 0644]
arch/arm/mach-mx2/system.c [new file with mode: 0644]
arch/arm/mach-mx3/Kconfig
arch/arm/mach-mx3/Makefile
arch/arm/mach-mx3/clock.c [new file with mode: 0644]
arch/arm/mach-mx3/crm_regs.h [new file with mode: 0644]
arch/arm/mach-mx3/devices.c [new file with mode: 0644]
arch/arm/mach-mx3/iomux.c [new file with mode: 0644]
arch/arm/mach-mx3/mx31ads.c
arch/arm/mach-mx3/mx31lite.c [new file with mode: 0644]
arch/arm/mach-mx3/pcm037.c [new file with mode: 0644]
arch/arm/mach-mx3/time.c [deleted file]
arch/arm/mach-omap1/Makefile
arch/arm/mach-omap1/board-nokia770.c
arch/arm/mach-omap1/board-osk.c
arch/arm/mach-omap1/fpga.c
arch/arm/mach-omap1/mcbsp.c [new file with mode: 0644]
arch/arm/mach-omap1/pm.c
arch/arm/mach-omap1/sram.S [new file with mode: 0644]
arch/arm/mach-omap2/Makefile
arch/arm/mach-omap2/clock.c
arch/arm/mach-omap2/clock.h
arch/arm/mach-omap2/clock24xx.c
arch/arm/mach-omap2/clock24xx.h
arch/arm/mach-omap2/clock34xx.c
arch/arm/mach-omap2/clock34xx.h
arch/arm/mach-omap2/cm-regbits-34xx.h
arch/arm/mach-omap2/cm.h
arch/arm/mach-omap2/control.c
arch/arm/mach-omap2/id.c
arch/arm/mach-omap2/mcbsp.c [new file with mode: 0644]
arch/arm/mach-omap2/memory.c
arch/arm/mach-omap2/mux.c
arch/arm/mach-omap2/pm.c
arch/arm/mach-omap2/prcm-common.h
arch/arm/mach-omap2/prcm.c
arch/arm/mach-omap2/prm.h
arch/arm/mach-omap2/sdrc.h
arch/arm/mach-omap2/sram-fn.S [deleted file]
arch/arm/mach-omap2/sram242x.S [new file with mode: 0644]
arch/arm/mach-omap2/sram243x.S [new file with mode: 0644]
arch/arm/mach-omap2/timer-gp.c
arch/arm/mach-orion5x/Kconfig
arch/arm/mach-orion5x/Makefile
arch/arm/mach-orion5x/addr-map.c
arch/arm/mach-orion5x/common.c
arch/arm/mach-orion5x/common.h
arch/arm/mach-orion5x/db88f5281-setup.c
arch/arm/mach-orion5x/dns323-setup.c
arch/arm/mach-orion5x/gpio.c
arch/arm/mach-orion5x/irq.c
arch/arm/mach-orion5x/kurobox_pro-setup.c
arch/arm/mach-orion5x/mpp.c [new file with mode: 0644]
arch/arm/mach-orion5x/mpp.h [new file with mode: 0644]
arch/arm/mach-orion5x/mss2-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/mv2120-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/pci.c
arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/rd88f5181l-ge-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/rd88f5182-setup.c
arch/arm/mach-orion5x/ts209-setup.c
arch/arm/mach-orion5x/ts409-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/ts78xx-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/tsx09-common.c [new file with mode: 0644]
arch/arm/mach-orion5x/tsx09-common.h [new file with mode: 0644]
arch/arm/mach-orion5x/wnr854t-setup.c [new file with mode: 0644]
arch/arm/mach-orion5x/wrt350n-v2-setup.c [new file with mode: 0644]
arch/arm/mach-pxa/Kconfig
arch/arm/mach-pxa/Makefile
arch/arm/mach-pxa/clock.c
arch/arm/mach-pxa/clock.h
arch/arm/mach-pxa/cm-x270-pci.c
arch/arm/mach-pxa/cm-x270.c
arch/arm/mach-pxa/corgi.c
arch/arm/mach-pxa/corgi_pm.c
arch/arm/mach-pxa/devices.c
arch/arm/mach-pxa/devices.h
arch/arm/mach-pxa/em-x270.c
arch/arm/mach-pxa/generic.c
arch/arm/mach-pxa/irq.c
arch/arm/mach-pxa/lpd270.c
arch/arm/mach-pxa/lubbock.c
arch/arm/mach-pxa/magician.c
arch/arm/mach-pxa/mainstone.c
arch/arm/mach-pxa/mfp-pxa2xx.c
arch/arm/mach-pxa/pcm990-baseboard.c
arch/arm/mach-pxa/poodle.c
arch/arm/mach-pxa/pwm.c [new file with mode: 0644]
arch/arm/mach-pxa/pxa25x.c
arch/arm/mach-pxa/pxa27x.c
arch/arm/mach-pxa/pxa2xx.c [new file with mode: 0644]
arch/arm/mach-pxa/pxa3xx.c
arch/arm/mach-pxa/spitz_pm.c
arch/arm/mach-pxa/standby.S
arch/arm/mach-pxa/trizeps4.c
arch/arm/mach-pxa/zylonite.c
arch/arm/mach-pxa/zylonite_pxa300.c
arch/arm/mach-pxa/zylonite_pxa320.c
arch/arm/mach-s3c2410/Kconfig
arch/arm/mach-s3c2410/Makefile
arch/arm/mach-s3c2410/bast-ide.c [new file with mode: 0644]
arch/arm/mach-s3c2410/mach-bast.c
arch/arm/mach-s3c2410/mach-n30.c
arch/arm/mach-s3c2410/mach-vr1000.c
arch/arm/mach-s3c2410/nor-simtec.c [new file with mode: 0644]
arch/arm/mach-s3c2410/nor-simtec.h [new file with mode: 0644]
arch/arm/mach-s3c2412/Kconfig
arch/arm/mach-s3c2412/Makefile
arch/arm/mach-s3c2412/clock.c
arch/arm/mach-s3c2412/mach-jive.c [new file with mode: 0644]
arch/arm/mach-s3c2440/Kconfig
arch/arm/mach-s3c2440/Makefile
arch/arm/mach-s3c2440/mach-anubis.c
arch/arm/mach-s3c2440/mach-at2440evb.c [new file with mode: 0644]
arch/arm/mach-s3c2440/mach-osiris.c
arch/arm/mach-s3c2443/clock.c
arch/arm/mm/Kconfig
arch/arm/mm/Makefile
arch/arm/mm/cache-feroceon-l2.c [new file with mode: 0644]
arch/arm/mm/fault-armv.c
arch/arm/mm/flush.c
arch/arm/mm/proc-feroceon.S
arch/arm/plat-iop/gpio.c
arch/arm/plat-mxc/Kconfig
arch/arm/plat-mxc/Makefile
arch/arm/plat-mxc/clock.c [new file with mode: 0644]
arch/arm/plat-mxc/gpio.c [new file with mode: 0644]
arch/arm/plat-mxc/iomux-mx1-mx2.c [new file with mode: 0644]
arch/arm/plat-mxc/irq.c
arch/arm/plat-mxc/time.c [new file with mode: 0644]
arch/arm/plat-omap/Makefile
arch/arm/plat-omap/clock.c
arch/arm/plat-omap/common.c
arch/arm/plat-omap/devices.c
arch/arm/plat-omap/dma.c
arch/arm/plat-omap/dmtimer.c
arch/arm/plat-omap/mcbsp.c
arch/arm/plat-omap/sram-fn.S [deleted file]
arch/arm/plat-omap/sram.c
arch/arm/plat-omap/usb.c
arch/arm/plat-orion/irq.c
arch/arm/plat-orion/pcie.c
arch/arm/plat-orion/time.c
arch/arm/plat-s3c24xx/Kconfig
arch/arm/plat-s3c24xx/Makefile
arch/arm/plat-s3c24xx/devs.c
arch/arm/plat-s3c24xx/gpiolib.c [new file with mode: 0644]
arch/arm/plat-s3c24xx/pwm-clock.c [new file with mode: 0644]
arch/arm/plat-s3c24xx/pwm.c [new file with mode: 0644]
arch/arm/tools/mach-types
arch/avr32/Kconfig
arch/avr32/boards/atngw100/setup.c
arch/avr32/boards/atstk1000/atstk1002.c
arch/avr32/boards/atstk1000/atstk1003.c
arch/avr32/boards/atstk1000/atstk1004.c
arch/avr32/kernel/entry-avr32b.S
arch/avr32/kernel/signal.c
arch/avr32/kernel/time.c
arch/avr32/kernel/vmlinux.lds.S
arch/avr32/lib/io-readsb.S
arch/avr32/mach-at32ap/Makefile
arch/avr32/mach-at32ap/at32ap.c [deleted file]
arch/avr32/mach-at32ap/at32ap700x.c
arch/avr32/mach-at32ap/intc.c
arch/avr32/mach-at32ap/pdc.c [new file with mode: 0644]
arch/avr32/mach-at32ap/pio.c
arch/avr32/mach-at32ap/pio.h
arch/avr32/mach-at32ap/pm-at32ap700x.S
arch/avr32/mach-at32ap/pm.c [new file with mode: 0644]
arch/avr32/mach-at32ap/sdramc.h [new file with mode: 0644]
arch/avr32/mm/init.c
arch/avr32/mm/tlb.c
arch/blackfin/mach-bf561/coreb.c
arch/cris/arch-v10/drivers/eeprom.c
arch/cris/arch-v10/drivers/gpio.c
arch/cris/arch-v10/drivers/i2c.c
arch/cris/arch-v10/drivers/sync_serial.c
arch/cris/arch-v32/drivers/cryptocop.c
arch/cris/arch-v32/drivers/i2c.c
arch/cris/arch-v32/drivers/mach-a3/gpio.c
arch/cris/arch-v32/drivers/mach-fs/gpio.c
arch/cris/arch-v32/drivers/sync_serial.c
arch/m68k/bvme6000/rtc.c
arch/m68k/mvme16x/rtc.c
arch/mips/basler/excite/excite_iodev.c
arch/mips/kernel/rtlx.c
arch/mips/kernel/vpe.c
arch/mips/sibyte/common/sb_tbprof.c
arch/parisc/kernel/perf.c
arch/parisc/kernel/vmlinux.lds.S
arch/powerpc/Kconfig
arch/powerpc/kernel/Makefile
arch/powerpc/kernel/entry_32.S
arch/powerpc/kernel/entry_64.S
arch/powerpc/kernel/ftrace.c [new file with mode: 0644]
arch/powerpc/kernel/io.c
arch/powerpc/kernel/irq.c
arch/powerpc/kernel/ppc_ksyms.c
arch/powerpc/kernel/setup_32.c
arch/powerpc/kernel/vmlinux.lds.S
arch/powerpc/platforms/powermac/Makefile
arch/s390/Kconfig
arch/s390/appldata/appldata.h
arch/s390/appldata/appldata_base.c
arch/s390/appldata/appldata_mem.c
arch/s390/appldata/appldata_net_sum.c
arch/s390/appldata/appldata_os.c
arch/s390/crypto/crypt_s390.h
arch/s390/crypto/prng.c
arch/s390/hypfs/inode.c
arch/s390/kernel/Makefile
arch/s390/kernel/binfmt_elf32.c [deleted file]
arch/s390/kernel/compat_ptrace.h
arch/s390/kernel/debug.c
arch/s390/kernel/early.c
arch/s390/kernel/ipl.c
arch/s390/kernel/kprobes.c
arch/s390/kernel/machine_kexec.c
arch/s390/kernel/mem_detect.c [new file with mode: 0644]
arch/s390/kernel/process.c
arch/s390/kernel/ptrace.c
arch/s390/kernel/setup.c
arch/s390/kernel/time.c
arch/s390/kernel/topology.c
arch/s390/kernel/vmlinux.lds.S
arch/s390/kernel/vtime.c
arch/s390/mm/init.c
arch/sh/boards/landisk/gio.c
arch/sh/configs/landisk_defconfig
arch/sh/configs/lboxre2_defconfig
arch/sh/configs/se7705_defconfig
arch/sh/configs/se7712_defconfig
arch/sh/configs/se7750_defconfig
arch/sh/kernel/vmlinux_32.lds.S
arch/sh/kernel/vmlinux_64.lds.S
arch/sparc/kernel/apc.c
arch/sparc64/Kconfig
arch/sparc64/Kconfig.debug
arch/sparc64/kernel/Makefile
arch/sparc64/kernel/ftrace.c [new file with mode: 0644]
arch/sparc64/kernel/sparc64_ksyms.c
arch/sparc64/kernel/time.c
arch/sparc64/lib/mcount.S
arch/um/drivers/harddog_kern.c
arch/um/drivers/mmapper_kern.c
arch/um/drivers/random.c
arch/x86/Kconfig
arch/x86/Kconfig.cpu
arch/x86/Kconfig.debug
arch/x86/Makefile
arch/x86/boot/a20.c
arch/x86/boot/compressed/head_64.S
arch/x86/boot/compressed/misc.c
arch/x86/boot/compressed/relocs.c
arch/x86/boot/cpu.c
arch/x86/boot/main.c
arch/x86/boot/memory.c
arch/x86/boot/pmjump.S
arch/x86/boot/video-vga.c
arch/x86/configs/i386_defconfig
arch/x86/configs/x86_64_defconfig
arch/x86/ia32/ia32entry.S
arch/x86/kernel/Makefile
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/acpi/sleep.c
arch/x86/kernel/alternative.c
arch/x86/kernel/amd_iommu.c [new file with mode: 0644]
arch/x86/kernel/amd_iommu_init.c [new file with mode: 0644]
arch/x86/kernel/aperture_64.c
arch/x86/kernel/apic_32.c
arch/x86/kernel/apic_64.c
arch/x86/kernel/apm_32.c
arch/x86/kernel/asm-offsets_32.c
arch/x86/kernel/asm-offsets_64.c
arch/x86/kernel/bugs_64.c [deleted file]
arch/x86/kernel/cpu/Makefile
arch/x86/kernel/cpu/addon_cpuid_features.c
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/cpu/amd_64.c [new file with mode: 0644]
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/cpu/bugs_64.c [new file with mode: 0644]
arch/x86/kernel/cpu/centaur_64.c [new file with mode: 0644]
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/common_64.c [new file with mode: 0644]
arch/x86/kernel/cpu/cpu.h
arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
arch/x86/kernel/cpu/intel.c
arch/x86/kernel/cpu/intel_64.c [new file with mode: 0644]
arch/x86/kernel/cpu/intel_cacheinfo.c
arch/x86/kernel/cpu/mcheck/k7.c
arch/x86/kernel/cpu/mcheck/mce_64.c
arch/x86/kernel/cpu/mcheck/p4.c
arch/x86/kernel/cpu/mtrr/generic.c
arch/x86/kernel/cpu/mtrr/main.c
arch/x86/kernel/cpu/mtrr/mtrr.h
arch/x86/kernel/cpu/perfctr-watchdog.c
arch/x86/kernel/cpuid.c
arch/x86/kernel/e820.c [new file with mode: 0644]
arch/x86/kernel/e820_32.c [deleted file]
arch/x86/kernel/e820_64.c [deleted file]
arch/x86/kernel/early-quirks.c
arch/x86/kernel/early_printk.c
arch/x86/kernel/efi.c
arch/x86/kernel/efi_64.c
arch/x86/kernel/entry_32.S
arch/x86/kernel/entry_64.S
arch/x86/kernel/ftrace.c [new file with mode: 0644]
arch/x86/kernel/genapic_64.c
arch/x86/kernel/genx2apic_uv_x.c
arch/x86/kernel/head.c [new file with mode: 0644]
arch/x86/kernel/head32.c
arch/x86/kernel/head64.c
arch/x86/kernel/head_32.S
arch/x86/kernel/head_64.S
arch/x86/kernel/hpet.c
arch/x86/kernel/i386_ksyms_32.c
arch/x86/kernel/i387.c
arch/x86/kernel/i8259.c [new file with mode: 0644]
arch/x86/kernel/i8259_32.c [deleted file]
arch/x86/kernel/i8259_64.c [deleted file]
arch/x86/kernel/io_apic_32.c
arch/x86/kernel/io_apic_64.c
arch/x86/kernel/ipi.c
arch/x86/kernel/irq_32.c
arch/x86/kernel/irq_64.c
arch/x86/kernel/irqinit_32.c [new file with mode: 0644]
arch/x86/kernel/irqinit_64.c [new file with mode: 0644]
arch/x86/kernel/ldt.c
arch/x86/kernel/machine_kexec_32.c
arch/x86/kernel/machine_kexec_64.c
arch/x86/kernel/microcode.c
arch/x86/kernel/mmconf-fam10h_64.c
arch/x86/kernel/mpparse.c
arch/x86/kernel/msr.c
arch/x86/kernel/nmi.c [new file with mode: 0644]
arch/x86/kernel/nmi_32.c [deleted file]
arch/x86/kernel/nmi_64.c [deleted file]
arch/x86/kernel/numaq_32.c
arch/x86/kernel/paravirt.c
arch/x86/kernel/paravirt_patch_32.c
arch/x86/kernel/paravirt_patch_64.c
arch/x86/kernel/pci-calgary_64.c
arch/x86/kernel/pci-dma.c
arch/x86/kernel/pci-gart_64.c
arch/x86/kernel/pci-swiotlb_64.c
arch/x86/kernel/probe_roms_32.c [new file with mode: 0644]
arch/x86/kernel/process.c
arch/x86/kernel/process_32.c
arch/x86/kernel/process_64.c
arch/x86/kernel/ptrace.c
arch/x86/kernel/quirks.c
arch/x86/kernel/reboot.c
arch/x86/kernel/reboot_fixups_32.c
arch/x86/kernel/setup.c
arch/x86/kernel/setup64.c [deleted file]
arch/x86/kernel/setup_32.c [deleted file]
arch/x86/kernel/setup_64.c [deleted file]
arch/x86/kernel/setup_percpu.c [new file with mode: 0644]
arch/x86/kernel/smpboot.c
arch/x86/kernel/srat_32.c [deleted file]
arch/x86/kernel/summit_32.c
arch/x86/kernel/sys_i386_32.c
arch/x86/kernel/time_32.c
arch/x86/kernel/time_64.c
arch/x86/kernel/tlb_64.c
arch/x86/kernel/tlb_uv.c [new file with mode: 0644]
arch/x86/kernel/trampoline.c
arch/x86/kernel/traps_32.c
arch/x86/kernel/traps_64.c
arch/x86/kernel/tsc.c [new file with mode: 0644]
arch/x86/kernel/tsc_32.c [deleted file]
arch/x86/kernel/tsc_64.c [deleted file]
arch/x86/kernel/visws_quirks.c [new file with mode: 0644]
arch/x86/kernel/vmi_32.c
arch/x86/kernel/vmiclock_32.c
arch/x86/kernel/vmlinux_32.lds.S
arch/x86/kernel/vmlinux_64.lds.S
arch/x86/kernel/vsmp_64.c
arch/x86/kernel/vsyscall_64.c
arch/x86/kernel/x8664_ksyms_64.c
arch/x86/lguest/Kconfig
arch/x86/lguest/boot.c
arch/x86/lib/Makefile
arch/x86/lib/copy_user_64.S
arch/x86/lib/copy_user_nocache_64.S
arch/x86/lib/delay.c [new file with mode: 0644]
arch/x86/lib/delay_32.c [deleted file]
arch/x86/lib/delay_64.c [deleted file]
arch/x86/lib/getuser.S [new file with mode: 0644]
arch/x86/lib/getuser_32.S [deleted file]
arch/x86/lib/getuser_64.S [deleted file]
arch/x86/lib/putuser.S [new file with mode: 0644]
arch/x86/lib/putuser_32.S [deleted file]
arch/x86/lib/putuser_64.S [deleted file]
arch/x86/lib/thunk_32.S [new file with mode: 0644]
arch/x86/lib/thunk_64.S
arch/x86/lib/usercopy_64.c
arch/x86/mach-default/setup.c
arch/x86/mach-es7000/Makefile
arch/x86/mach-es7000/es7000plat.c
arch/x86/mach-generic/Makefile
arch/x86/mach-generic/bigsmp.c
arch/x86/mach-generic/numaq.c [new file with mode: 0644]
arch/x86/mach-generic/probe.c
arch/x86/mach-visws/Makefile [deleted file]
arch/x86/mach-visws/mpparse.c [deleted file]
arch/x86/mach-visws/reboot.c [deleted file]
arch/x86/mach-visws/setup.c [deleted file]
arch/x86/mach-visws/traps.c [deleted file]
arch/x86/mach-visws/visws_apic.c [deleted file]
arch/x86/mach-voyager/setup.c
arch/x86/mach-voyager/voyager_smp.c
arch/x86/math-emu/reg_constant.c
arch/x86/mm/Makefile
arch/x86/mm/discontig_32.c
arch/x86/mm/dump_pagetables.c
arch/x86/mm/fault.c
arch/x86/mm/init_32.c
arch/x86/mm/init_64.c
arch/x86/mm/ioremap.c
arch/x86/mm/k8topology_64.c
arch/x86/mm/kmmio.c [new file with mode: 0644]
arch/x86/mm/mmio-mod.c [new file with mode: 0644]
arch/x86/mm/numa_64.c
arch/x86/mm/pageattr-test.c
arch/x86/mm/pageattr.c
arch/x86/mm/pat.c
arch/x86/mm/pf_in.c [new file with mode: 0644]
arch/x86/mm/pf_in.h [new file with mode: 0644]
arch/x86/mm/pgtable.c
arch/x86/mm/pgtable_32.c
arch/x86/mm/srat_32.c [new file with mode: 0644]
arch/x86/mm/srat_64.c
arch/x86/mm/testmmiotrace.c [new file with mode: 0644]
arch/x86/oprofile/nmi_int.c
arch/x86/pci/Makefile
arch/x86/pci/Makefile_32 [deleted file]
arch/x86/pci/Makefile_64 [deleted file]
arch/x86/pci/acpi.c
arch/x86/pci/amd_bus.c [new file with mode: 0644]
arch/x86/pci/common.c
arch/x86/pci/direct.c
arch/x86/pci/i386.c
arch/x86/pci/init.c
arch/x86/pci/irq.c
arch/x86/pci/k8-bus_64.c [deleted file]
arch/x86/pci/legacy.c
arch/x86/pci/mmconfig-shared.c
arch/x86/pci/mp_bus_to_node.c [deleted file]
arch/x86/pci/numa.c
arch/x86/pci/pci.h
arch/x86/pci/visws.c
arch/x86/power/hibernate_64.c
arch/x86/vdso/vclock_gettime.c
arch/x86/vdso/vdso32-setup.c
arch/x86/vdso/vgetcpu.c
arch/x86/vdso/vma.c
arch/x86/xen/Kconfig
arch/x86/xen/Makefile
arch/x86/xen/enlighten.c
arch/x86/xen/manage.c [deleted file]
arch/x86/xen/mmu.c
arch/x86/xen/mmu.h
arch/x86/xen/multicalls.c
arch/x86/xen/multicalls.h
arch/x86/xen/setup.c
arch/x86/xen/smp.c
arch/x86/xen/suspend.c [new file with mode: 0644]
arch/x86/xen/time.c
arch/x86/xen/xen-head.S
arch/x86/xen/xen-ops.h
block/Kconfig
block/Makefile
block/as-iosched.c
block/blk-core.c
block/blk-integrity.c [new file with mode: 0644]
block/blk-map.c
block/blk-merge.c
block/blk-settings.c
block/blk.h
block/blktrace.c
block/bsg.c
block/cfq-iosched.c
block/cmd-filter.c [new file with mode: 0644]
block/elevator.c
block/genhd.c
block/scsi_ioctl.c
crypto/Kconfig
crypto/Makefile
crypto/ahash.c [new file with mode: 0644]
crypto/api.c
crypto/camellia.c
crypto/crc32c.c
crypto/cryptd.c
crypto/digest.c
crypto/hash.c
crypto/hmac.c
crypto/internal.h
crypto/prng.c [new file with mode: 0644]
crypto/prng.h [new file with mode: 0644]
crypto/ripemd.h [new file with mode: 0644]
crypto/rmd128.c [new file with mode: 0644]
crypto/rmd160.c [new file with mode: 0644]
crypto/rmd256.c [new file with mode: 0644]
crypto/rmd320.c [new file with mode: 0644]
crypto/tcrypt.c
crypto/tcrypt.h
drivers/Makefile
drivers/acorn/char/Makefile [deleted file]
drivers/acorn/char/defkeymap-l7200.c [deleted file]
drivers/acpi/Kconfig
drivers/ata/libata-scsi.c
drivers/base/power/trace.c
drivers/base/topology.c
drivers/block/DAC960.c
drivers/block/aoe/aoechr.c
drivers/block/aoe/aoecmd.c
drivers/block/paride/pg.c
drivers/block/paride/pt.c
drivers/block/pktcdvd.c
drivers/block/xen-blkfront.c
drivers/bluetooth/hci_vhci.c
drivers/cdrom/cdrom.c
drivers/char/Makefile
drivers/char/agp/amd64-agp.c
drivers/char/agp/frontend.c
drivers/char/apm-emulation.c
drivers/char/briq_panel.c
drivers/char/cs5535_gpio.c
drivers/char/drm/Kconfig [deleted file]
drivers/char/drm/Makefile [deleted file]
drivers/char/drm/README.drm [deleted file]
drivers/char/drm/ati_pcigart.c [deleted file]
drivers/char/drm/drm.h [deleted file]
drivers/char/drm/drmP.h [deleted file]
drivers/char/drm/drm_agpsupport.c [deleted file]
drivers/char/drm/drm_auth.c [deleted file]
drivers/char/drm/drm_bufs.c [deleted file]
drivers/char/drm/drm_context.c [deleted file]
drivers/char/drm/drm_core.h [deleted file]
drivers/char/drm/drm_dma.c [deleted file]
drivers/char/drm/drm_drawable.c [deleted file]
drivers/char/drm/drm_drv.c [deleted file]
drivers/char/drm/drm_fops.c [deleted file]
drivers/char/drm/drm_hashtab.c [deleted file]
drivers/char/drm/drm_hashtab.h [deleted file]
drivers/char/drm/drm_ioc32.c [deleted file]
drivers/char/drm/drm_ioctl.c [deleted file]
drivers/char/drm/drm_irq.c [deleted file]
drivers/char/drm/drm_lock.c [deleted file]
drivers/char/drm/drm_memory.c [deleted file]
drivers/char/drm/drm_memory.h [deleted file]
drivers/char/drm/drm_memory_debug.h [deleted file]
drivers/char/drm/drm_mm.c [deleted file]
drivers/char/drm/drm_os_linux.h [deleted file]
drivers/char/drm/drm_pci.c [deleted file]
drivers/char/drm/drm_pciids.h [deleted file]
drivers/char/drm/drm_proc.c [deleted file]
drivers/char/drm/drm_sarea.h [deleted file]
drivers/char/drm/drm_scatter.c [deleted file]
drivers/char/drm/drm_sman.c [deleted file]
drivers/char/drm/drm_sman.h [deleted file]
drivers/char/drm/drm_stub.c [deleted file]
drivers/char/drm/drm_sysfs.c [deleted file]
drivers/char/drm/drm_vm.c [deleted file]
drivers/char/drm/i810_dma.c [deleted file]
drivers/char/drm/i810_drm.h [deleted file]
drivers/char/drm/i810_drv.c [deleted file]
drivers/char/drm/i810_drv.h [deleted file]
drivers/char/drm/i830_dma.c [deleted file]
drivers/char/drm/i830_drm.h [deleted file]
drivers/char/drm/i830_drv.c [deleted file]
drivers/char/drm/i830_drv.h [deleted file]
drivers/char/drm/i830_irq.c [deleted file]
drivers/char/drm/i915_dma.c [deleted file]
drivers/char/drm/i915_drm.h [deleted file]
drivers/char/drm/i915_drv.c [deleted file]
drivers/char/drm/i915_drv.h [deleted file]
drivers/char/drm/i915_ioc32.c [deleted file]
drivers/char/drm/i915_irq.c [deleted file]
drivers/char/drm/i915_mem.c [deleted file]
drivers/char/drm/mga_dma.c [deleted file]
drivers/char/drm/mga_drm.h [deleted file]
drivers/char/drm/mga_drv.c [deleted file]
drivers/char/drm/mga_drv.h [deleted file]
drivers/char/drm/mga_ioc32.c [deleted file]
drivers/char/drm/mga_irq.c [deleted file]
drivers/char/drm/mga_state.c [deleted file]
drivers/char/drm/mga_ucode.h [deleted file]
drivers/char/drm/mga_warp.c [deleted file]
drivers/char/drm/r128_cce.c [deleted file]
drivers/char/drm/r128_drm.h [deleted file]
drivers/char/drm/r128_drv.c [deleted file]
drivers/char/drm/r128_drv.h [deleted file]
drivers/char/drm/r128_ioc32.c [deleted file]
drivers/char/drm/r128_irq.c [deleted file]
drivers/char/drm/r128_state.c [deleted file]
drivers/char/drm/r300_cmdbuf.c [deleted file]
drivers/char/drm/r300_reg.h [deleted file]
drivers/char/drm/radeon_cp.c [deleted file]
drivers/char/drm/radeon_drm.h [deleted file]
drivers/char/drm/radeon_drv.c [deleted file]
drivers/char/drm/radeon_drv.h [deleted file]
drivers/char/drm/radeon_ioc32.c [deleted file]
drivers/char/drm/radeon_irq.c [deleted file]
drivers/char/drm/radeon_mem.c [deleted file]
drivers/char/drm/radeon_microcode.h [deleted file]
drivers/char/drm/radeon_state.c [deleted file]
drivers/char/drm/savage_bci.c [deleted file]
drivers/char/drm/savage_drm.h [deleted file]
drivers/char/drm/savage_drv.c [deleted file]
drivers/char/drm/savage_drv.h [deleted file]
drivers/char/drm/savage_state.c [deleted file]
drivers/char/drm/sis_drm.h [deleted file]
drivers/char/drm/sis_drv.c [deleted file]
drivers/char/drm/sis_drv.h [deleted file]
drivers/char/drm/sis_mm.c [deleted file]
drivers/char/drm/tdfx_drv.c [deleted file]
drivers/char/drm/tdfx_drv.h [deleted file]
drivers/char/drm/via_3d_reg.h [deleted file]
drivers/char/drm/via_dma.c [deleted file]
drivers/char/drm/via_dmablit.c [deleted file]
drivers/char/drm/via_dmablit.h [deleted file]
drivers/char/drm/via_drm.h [deleted file]
drivers/char/drm/via_drv.c [deleted file]
drivers/char/drm/via_drv.h [deleted file]
drivers/char/drm/via_irq.c [deleted file]
drivers/char/drm/via_map.c [deleted file]
drivers/char/drm/via_mm.c [deleted file]
drivers/char/drm/via_verifier.c [deleted file]
drivers/char/drm/via_verifier.h [deleted file]
drivers/char/drm/via_video.c [deleted file]
drivers/char/ds1286.c
drivers/char/ds1620.c
drivers/char/dsp56k.c
drivers/char/dtlk.c
drivers/char/efirtc.c
drivers/char/genrtc.c
drivers/char/hpet.c
drivers/char/hvc_xen.c
drivers/char/hw_random/core.c
drivers/char/ip2/ip2main.c
drivers/char/ip27-rtc.c
drivers/char/ipmi/ipmi_devintf.c
drivers/char/ipmi/ipmi_watchdog.c
drivers/char/lcd.c
drivers/char/lp.c
drivers/char/mbcs.c
drivers/char/mem.c
drivers/char/misc.c
drivers/char/mwave/mwavedd.c
drivers/char/nvram.c
drivers/char/pc8736x_gpio.c
drivers/char/pcmcia/cm4000_cs.c
drivers/char/pcmcia/cm4040_cs.c
drivers/char/pcmcia/ipwireless/main.c
drivers/char/ppdev.c
drivers/char/raw.c
drivers/char/rtc.c
drivers/char/scx200_gpio.c
drivers/char/snsc.c
drivers/char/sonypi.c
drivers/char/tb0219.c
drivers/char/tlclk.c
drivers/char/tpm/tpm.c
drivers/char/tty_io.c
drivers/char/vc_screen.c
drivers/char/viotape.c
drivers/char/vr41xx_giu.c
drivers/char/xilinx_hwicap/xilinx_hwicap.c
drivers/crypto/Kconfig
drivers/crypto/Makefile
drivers/crypto/hifn_795x.c
drivers/crypto/ixp4xx_crypto.c [new file with mode: 0644]
drivers/crypto/padlock-aes.c
drivers/crypto/padlock-sha.c
drivers/crypto/talitos.c [new file with mode: 0644]
drivers/crypto/talitos.h [new file with mode: 0644]
drivers/firmware/Kconfig
drivers/firmware/Makefile
drivers/firmware/dmi_scan.c
drivers/firmware/memmap.c [new file with mode: 0644]
drivers/gpu/Makefile [new file with mode: 0644]
drivers/gpu/drm/Kconfig [new file with mode: 0644]
drivers/gpu/drm/Makefile [new file with mode: 0644]
drivers/gpu/drm/README.drm [new file with mode: 0644]
drivers/gpu/drm/ati_pcigart.c [new file with mode: 0644]
drivers/gpu/drm/drm_agpsupport.c [new file with mode: 0644]
drivers/gpu/drm/drm_auth.c [new file with mode: 0644]
drivers/gpu/drm/drm_bufs.c [new file with mode: 0644]
drivers/gpu/drm/drm_context.c [new file with mode: 0644]
drivers/gpu/drm/drm_dma.c [new file with mode: 0644]
drivers/gpu/drm/drm_drawable.c [new file with mode: 0644]
drivers/gpu/drm/drm_drv.c [new file with mode: 0644]
drivers/gpu/drm/drm_fops.c [new file with mode: 0644]
drivers/gpu/drm/drm_hashtab.c [new file with mode: 0644]
drivers/gpu/drm/drm_ioc32.c [new file with mode: 0644]
drivers/gpu/drm/drm_ioctl.c [new file with mode: 0644]
drivers/gpu/drm/drm_irq.c [new file with mode: 0644]
drivers/gpu/drm/drm_lock.c [new file with mode: 0644]
drivers/gpu/drm/drm_memory.c [new file with mode: 0644]
drivers/gpu/drm/drm_mm.c [new file with mode: 0644]
drivers/gpu/drm/drm_pci.c [new file with mode: 0644]
drivers/gpu/drm/drm_proc.c [new file with mode: 0644]
drivers/gpu/drm/drm_scatter.c [new file with mode: 0644]
drivers/gpu/drm/drm_sman.c [new file with mode: 0644]
drivers/gpu/drm/drm_stub.c [new file with mode: 0644]
drivers/gpu/drm/drm_sysfs.c [new file with mode: 0644]
drivers/gpu/drm/drm_vm.c [new file with mode: 0644]
drivers/gpu/drm/i810/Makefile [new file with mode: 0644]
drivers/gpu/drm/i810/i810_dma.c [new file with mode: 0644]
drivers/gpu/drm/i810/i810_drv.c [new file with mode: 0644]
drivers/gpu/drm/i810/i810_drv.h [new file with mode: 0644]
drivers/gpu/drm/i830/Makefile [new file with mode: 0644]
drivers/gpu/drm/i830/i830_dma.c [new file with mode: 0644]
drivers/gpu/drm/i830/i830_drv.c [new file with mode: 0644]
drivers/gpu/drm/i830/i830_drv.h [new file with mode: 0644]
drivers/gpu/drm/i830/i830_irq.c [new file with mode: 0644]
drivers/gpu/drm/i915/Makefile [new file with mode: 0644]
drivers/gpu/drm/i915/i915_dma.c [new file with mode: 0644]
drivers/gpu/drm/i915/i915_drv.c [new file with mode: 0644]
drivers/gpu/drm/i915/i915_drv.h [new file with mode: 0644]
drivers/gpu/drm/i915/i915_ioc32.c [new file with mode: 0644]
drivers/gpu/drm/i915/i915_irq.c [new file with mode: 0644]
drivers/gpu/drm/i915/i915_mem.c [new file with mode: 0644]
drivers/gpu/drm/mga/Makefile [new file with mode: 0644]
drivers/gpu/drm/mga/mga_dma.c [new file with mode: 0644]
drivers/gpu/drm/mga/mga_drv.c [new file with mode: 0644]
drivers/gpu/drm/mga/mga_drv.h [new file with mode: 0644]
drivers/gpu/drm/mga/mga_ioc32.c [new file with mode: 0644]
drivers/gpu/drm/mga/mga_irq.c [new file with mode: 0644]
drivers/gpu/drm/mga/mga_state.c [new file with mode: 0644]
drivers/gpu/drm/mga/mga_ucode.h [new file with mode: 0644]
drivers/gpu/drm/mga/mga_warp.c [new file with mode: 0644]
drivers/gpu/drm/r128/Makefile [new file with mode: 0644]
drivers/gpu/drm/r128/r128_cce.c [new file with mode: 0644]
drivers/gpu/drm/r128/r128_drv.c [new file with mode: 0644]
drivers/gpu/drm/r128/r128_drv.h [new file with mode: 0644]
drivers/gpu/drm/r128/r128_ioc32.c [new file with mode: 0644]
drivers/gpu/drm/r128/r128_irq.c [new file with mode: 0644]
drivers/gpu/drm/r128/r128_state.c [new file with mode: 0644]
drivers/gpu/drm/radeon/Makefile [new file with mode: 0644]
drivers/gpu/drm/radeon/r300_cmdbuf.c [new file with mode: 0644]
drivers/gpu/drm/radeon/r300_reg.h [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_cp.c [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_drv.c [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_drv.h [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_ioc32.c [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_irq.c [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_mem.c [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_microcode.h [new file with mode: 0644]
drivers/gpu/drm/radeon/radeon_state.c [new file with mode: 0644]
drivers/gpu/drm/savage/Makefile [new file with mode: 0644]
drivers/gpu/drm/savage/savage_bci.c [new file with mode: 0644]
drivers/gpu/drm/savage/savage_drv.c [new file with mode: 0644]
drivers/gpu/drm/savage/savage_drv.h [new file with mode: 0644]
drivers/gpu/drm/savage/savage_state.c [new file with mode: 0644]
drivers/gpu/drm/sis/Makefile [new file with mode: 0644]
drivers/gpu/drm/sis/sis_drv.c [new file with mode: 0644]
drivers/gpu/drm/sis/sis_drv.h [new file with mode: 0644]
drivers/gpu/drm/sis/sis_mm.c [new file with mode: 0644]
drivers/gpu/drm/tdfx/Makefile [new file with mode: 0644]
drivers/gpu/drm/tdfx/tdfx_drv.c [new file with mode: 0644]
drivers/gpu/drm/tdfx/tdfx_drv.h [new file with mode: 0644]
drivers/gpu/drm/via/Makefile [new file with mode: 0644]
drivers/gpu/drm/via/via_3d_reg.h [new file with mode: 0644]
drivers/gpu/drm/via/via_dma.c [new file with mode: 0644]
drivers/gpu/drm/via/via_dmablit.c [new file with mode: 0644]
drivers/gpu/drm/via/via_dmablit.h [new file with mode: 0644]
drivers/gpu/drm/via/via_drv.c [new file with mode: 0644]
drivers/gpu/drm/via/via_drv.h [new file with mode: 0644]
drivers/gpu/drm/via/via_irq.c [new file with mode: 0644]
drivers/gpu/drm/via/via_map.c [new file with mode: 0644]
drivers/gpu/drm/via/via_mm.c [new file with mode: 0644]
drivers/gpu/drm/via/via_verifier.c [new file with mode: 0644]
drivers/gpu/drm/via/via_verifier.h [new file with mode: 0644]
drivers/gpu/drm/via/via_video.c [new file with mode: 0644]
drivers/hid/hidraw.c
drivers/i2c/busses/i2c-pxa.c
drivers/i2c/chips/isp1301_omap.c
drivers/i2c/i2c-dev.c
drivers/ide/ide-tape.c
drivers/ide/legacy/ide-cs.c
drivers/infiniband/core/ucm.c
drivers/infiniband/core/ucma.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs_main.c
drivers/infiniband/hw/ipath/ipath_file_ops.c
drivers/input/input.c
drivers/input/misc/hp_sdc_rtc.c
drivers/input/misc/uinput.c
drivers/input/mousedev.c
drivers/input/serio/serio_raw.c
drivers/input/xen-kbdfront.c
drivers/isdn/capi/capi.c
drivers/isdn/hardware/eicon/divamnt.c
drivers/isdn/hardware/eicon/divasi.c
drivers/isdn/hardware/eicon/divasmain.c
drivers/isdn/i4l/isdn_common.c
drivers/lguest/Kconfig
drivers/lguest/lg.h
drivers/macintosh/adb.c
drivers/macintosh/ans-lcd.c
drivers/macintosh/smu.c
drivers/macintosh/via-pmu.c
drivers/md/linear.c
drivers/md/raid0.c
drivers/md/raid10.c
drivers/md/raid5.c
drivers/media/dvb/dvb-core/dvbdev.c
drivers/media/radio/miropcm20-rds.c
drivers/media/video/videodev.c
drivers/message/fusion/mptctl.c
drivers/message/i2o/i2o_config.c
drivers/misc/atmel_pwm.c
drivers/misc/hdpuftrs/hdpu_cpustate.c
drivers/misc/phantom.c
drivers/misc/sony-laptop.c
drivers/mmc/host/imxmmc.c
drivers/mtd/ftl.c
drivers/mtd/maps/omap_nor.c
drivers/mtd/maps/pcmciamtd.c
drivers/mtd/mtdchar.c
drivers/mtd/nand/orion_nand.c
drivers/mtd/ubi/cdev.c
drivers/net/Kconfig
drivers/net/arm/etherh.c
drivers/net/irda/pxaficp_ir.c
drivers/net/macb.c
drivers/net/ppp_generic.c
drivers/net/tun.c
drivers/net/wan/cosa.c
drivers/net/xen-netfront.c
drivers/parisc/eisa_eeprom.c
drivers/pci/intel-iommu.c
drivers/pcmcia/Kconfig
drivers/pcmcia/Makefile
drivers/pcmcia/au1000_generic.h
drivers/pcmcia/au1000_pb1x00.c
drivers/pcmcia/au1000_xxs1500.c
drivers/pcmcia/bfin_cf_pcmcia.c [new file with mode: 0644]
drivers/pcmcia/cardbus.c
drivers/pcmcia/cistpl.c
drivers/pcmcia/cs.c
drivers/pcmcia/cs_internal.h
drivers/pcmcia/ds.c
drivers/pcmcia/hd64465_ss.c
drivers/pcmcia/i82092.c
drivers/pcmcia/i82092aa.h
drivers/pcmcia/i82365.c
drivers/pcmcia/m8xx_pcmcia.c
drivers/pcmcia/omap_cf.c
drivers/pcmcia/pcmcia_ioctl.c
drivers/pcmcia/pcmcia_resource.c
drivers/pcmcia/pxa2xx_base.c
drivers/pcmcia/pxa2xx_cm_x270.c
drivers/pcmcia/pxa2xx_mainstone.c
drivers/pcmcia/pxa2xx_sharpsl.c
drivers/pcmcia/rsrc_mgr.c
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/soc_common.h
drivers/pcmcia/socket_sysfs.c
drivers/pcmcia/ti113x.h
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-at32ap700x.c
drivers/rtc/rtc-at91rm9200.c
drivers/rtc/rtc-at91sam9.c
drivers/rtc/rtc-dev.c
drivers/rtc/rtc-m41t80.c
drivers/rtc/rtc-omap.c
drivers/rtc/rtc-pl030.c [new file with mode: 0644]
drivers/rtc/rtc-pl031.c
drivers/rtc/rtc-s3c.c
drivers/rtc/rtc-sa1100.c
drivers/s390/block/dasd.c
drivers/s390/block/dasd_3990_erp.c
drivers/s390/block/dasd_eckd.c
drivers/s390/block/dasd_eer.c
drivers/s390/block/dasd_fba.c
drivers/s390/block/dcssblk.c
drivers/s390/block/xpram.c
drivers/s390/char/con3215.c
drivers/s390/char/con3270.c
drivers/s390/char/fs3270.c
drivers/s390/char/monreader.c
drivers/s390/char/monwriter.c
drivers/s390/char/raw3270.c
drivers/s390/char/sclp.c
drivers/s390/char/sclp_cmd.c
drivers/s390/char/sclp_con.c
drivers/s390/char/sclp_config.c
drivers/s390/char/sclp_cpi_sys.c
drivers/s390/char/sclp_quiesce.c
drivers/s390/char/sclp_rw.c
drivers/s390/char/sclp_sdias.c
drivers/s390/char/sclp_tty.c
drivers/s390/char/sclp_tty.h
drivers/s390/char/sclp_vt220.c
drivers/s390/char/tape_34xx.c
drivers/s390/char/tape_3590.c
drivers/s390/char/tape_char.c
drivers/s390/char/tape_core.c
drivers/s390/char/tty3270.c
drivers/s390/char/vmcp.c
drivers/s390/char/vmlogrdr.c
drivers/s390/char/vmur.c
drivers/s390/char/vmwatchdog.c
drivers/s390/char/zcore.c
drivers/s390/cio/Makefile
drivers/s390/cio/airq.c
drivers/s390/cio/chp.c
drivers/s390/cio/chp.h
drivers/s390/cio/chsc.c
drivers/s390/cio/chsc.h
drivers/s390/cio/chsc_sch.c [new file with mode: 0644]
drivers/s390/cio/chsc_sch.h [new file with mode: 0644]
drivers/s390/cio/cio.c
drivers/s390/cio/cio.h
drivers/s390/cio/cmf.c
drivers/s390/cio/css.c
drivers/s390/cio/css.h
drivers/s390/cio/device.c
drivers/s390/cio/device.h
drivers/s390/cio/device_fsm.c
drivers/s390/cio/device_id.c
drivers/s390/cio/device_ops.c
drivers/s390/cio/device_pgid.c
drivers/s390/cio/device_status.c
drivers/s390/cio/fcx.c [new file with mode: 0644]
drivers/s390/cio/idset.h
drivers/s390/cio/io_sch.h
drivers/s390/cio/ioasm.h
drivers/s390/cio/isc.c [new file with mode: 0644]
drivers/s390/cio/itcw.c [new file with mode: 0644]
drivers/s390/cio/qdio.c
drivers/s390/cio/qdio.h
drivers/s390/cio/schid.h [deleted file]
drivers/s390/cio/scsw.c [new file with mode: 0644]
drivers/s390/crypto/ap_bus.c
drivers/s390/crypto/ap_bus.h
drivers/s390/crypto/zcrypt_api.c
drivers/s390/crypto/zcrypt_api.h
drivers/s390/crypto/zcrypt_cex2a.c
drivers/s390/crypto/zcrypt_error.h
drivers/s390/crypto/zcrypt_pcica.c
drivers/s390/crypto/zcrypt_pcicc.c
drivers/s390/crypto/zcrypt_pcixcc.c
drivers/s390/net/claw.c
drivers/s390/net/ctcm_fsms.c
drivers/s390/net/ctcm_main.c
drivers/s390/net/cu3088.c
drivers/s390/net/cu3088.h
drivers/s390/net/lcs.c
drivers/s390/net/netiucv.c
drivers/s390/net/qeth_core_main.c
drivers/s390/net/qeth_l3_main.c
drivers/s390/net/smsgiucv.c
drivers/s390/s390mach.c
drivers/s390/s390mach.h
drivers/sbus/char/bpp.c
drivers/sbus/char/cpwatchdog.c
drivers/sbus/char/display7seg.c
drivers/sbus/char/envctrl.c
drivers/sbus/char/flash.c
drivers/sbus/char/jsflash.c
drivers/sbus/char/openprom.c
drivers/sbus/char/riowatchdog.c
drivers/sbus/char/rtc.c
drivers/sbus/char/uctrl.c
drivers/sbus/char/vfc_dev.c
drivers/scsi/3w-9xxx.c
drivers/scsi/3w-xxxx.c
drivers/scsi/aacraid/linit.c
drivers/scsi/arm/Kconfig
drivers/scsi/arm/acornscsi-io.S
drivers/scsi/arm/acornscsi.c
drivers/scsi/arm/acornscsi.h
drivers/scsi/ch.c
drivers/scsi/dpt_i2o.c
drivers/scsi/gdth.c
drivers/scsi/megaraid.c
drivers/scsi/megaraid/megaraid_mm.c
drivers/scsi/megaraid/megaraid_sas.c
drivers/scsi/osst.c
drivers/scsi/scsi_tgt_if.c
drivers/scsi/sg.c
drivers/scsi/sr.c
drivers/scsi/st.c
drivers/serial/Kconfig
drivers/serial/Makefile
drivers/serial/atmel_serial.c
drivers/serial/imx.c
drivers/serial/s3c2400.c [new file with mode: 0644]
drivers/serial/s3c2410.c
drivers/serial/s3c2412.c [new file with mode: 0644]
drivers/serial/s3c2440.c [new file with mode: 0644]
drivers/serial/samsung.c [new file with mode: 0644]
drivers/serial/samsung.h [new file with mode: 0644]
drivers/spi/spi_imx.c
drivers/spi/spidev.c
drivers/telephony/phonedev.c
drivers/uio/uio.c
drivers/usb/core/devio.c
drivers/usb/core/file.c
drivers/usb/gadget/Kconfig
drivers/usb/gadget/Makefile
drivers/usb/gadget/at91_udc.c
drivers/usb/gadget/ether.c
drivers/usb/gadget/gadget_chips.h
drivers/usb/gadget/inode.c
drivers/usb/gadget/omap_udc.c
drivers/usb/gadget/omap_udc.h
drivers/usb/gadget/printer.c
drivers/usb/gadget/pxa25x_udc.c [new file with mode: 0644]
drivers/usb/gadget/pxa25x_udc.h [new file with mode: 0644]
drivers/usb/gadget/pxa27x_udc.c
drivers/usb/gadget/pxa27x_udc.h
drivers/usb/gadget/pxa2xx_udc.c [deleted file]
drivers/usb/gadget/pxa2xx_udc.h [deleted file]
drivers/usb/host/ohci-omap.c
drivers/usb/host/ohci-pxa27x.c
drivers/usb/mon/mon_bin.c
drivers/video/Kconfig
drivers/video/backlight/Kconfig
drivers/video/backlight/Makefile
drivers/video/backlight/pwm_bl.c [new file with mode: 0644]
drivers/video/fbmem.c
drivers/video/pxafb.c
drivers/video/sgivwfb.c
drivers/video/xen-fbfront.c
drivers/xen/Makefile
drivers/xen/balloon.c
drivers/xen/events.c
drivers/xen/grant-table.c
drivers/xen/manage.c [new file with mode: 0644]
drivers/xen/xenbus/xenbus_client.c
drivers/xen/xenbus/xenbus_comms.c
drivers/xen/xenbus/xenbus_xs.c
fs/Kconfig
fs/Makefile
fs/bio-integrity.c [new file with mode: 0644]
fs/bio.c
fs/char_dev.c
fs/cifs/cifsfs.c
fs/dlm/user.c
fs/ecryptfs/file.c
fs/fat/cache.c
fs/fat/dir.c
fs/fat/file.c
fs/fat/inode.c
fs/fcntl.c
fs/gfs2/ops_file.c
fs/msdos/namei.c
fs/namespace.c
fs/ncpfs/file.c
fs/nfs/file.c
fs/ocfs2/stack_user.c
fs/proc/base.c
fs/proc/proc_misc.c
fs/proc/task_mmu.c
fs/proc/task_nommu.c
fs/ramfs/file-mmu.c
fs/ramfs/file-nommu.c
fs/read_write.c
fs/smbfs/file.c
fs/splice.c
fs/vfat/namei.c
include/Kbuild
include/asm-arm/arch-at91/at91_pmc.h
include/asm-arm/arch-at91/at91cap9.h
include/asm-arm/arch-at91/at91cap9_matrix.h
include/asm-arm/arch-at91/at91sam9260.h
include/asm-arm/arch-at91/at91sam9rl.h
include/asm-arm/arch-at91/board.h
include/asm-arm/arch-at91/cpu.h
include/asm-arm/arch-at91/hardware.h
include/asm-arm/arch-at91/timex.h
include/asm-arm/arch-ebsa285/hardware.h
include/asm-arm/arch-ebsa285/memory.h
include/asm-arm/arch-ebsa285/vmalloc.h
include/asm-arm/arch-imx/hardware.h
include/asm-arm/arch-imx/imx-dma.h
include/asm-arm/arch-imx/imx-uart.h
include/asm-arm/arch-iop13xx/dma.h
include/asm-arm/arch-iop32x/gpio.h [new file with mode: 0644]
include/asm-arm/arch-iop33x/gpio.h [new file with mode: 0644]
include/asm-arm/arch-ixp4xx/fsg.h [new file with mode: 0644]
include/asm-arm/arch-ixp4xx/hardware.h
include/asm-arm/arch-ixp4xx/irqs.h
include/asm-arm/arch-kirkwood/debug-macro.S [new file with mode: 0644]
include/asm-arm/arch-kirkwood/dma.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/entry-macro.S [new file with mode: 0644]
include/asm-arm/arch-kirkwood/hardware.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/io.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/irqs.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/kirkwood.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/memory.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/system.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/timex.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/uncompress.h [new file with mode: 0644]
include/asm-arm/arch-kirkwood/vmalloc.h [new file with mode: 0644]
include/asm-arm/arch-loki/debug-macro.S [new file with mode: 0644]
include/asm-arm/arch-loki/dma.h [new file with mode: 0644]
include/asm-arm/arch-loki/entry-macro.S [new file with mode: 0644]
include/asm-arm/arch-loki/hardware.h [new file with mode: 0644]
include/asm-arm/arch-loki/io.h [new file with mode: 0644]
include/asm-arm/arch-loki/irqs.h [new file with mode: 0644]
include/asm-arm/arch-loki/loki.h [new file with mode: 0644]
include/asm-arm/arch-loki/memory.h [new file with mode: 0644]
include/asm-arm/arch-loki/system.h [new file with mode: 0644]
include/asm-arm/arch-loki/timex.h [new file with mode: 0644]
include/asm-arm/arch-loki/uncompress.h [new file with mode: 0644]
include/asm-arm/arch-loki/vmalloc.h [new file with mode: 0644]
include/asm-arm/arch-msm/irqs.h
include/asm-arm/arch-msm/timex.h
include/asm-arm/arch-mv78xx0/debug-macro.S [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/dma.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/entry-macro.S [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/hardware.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/io.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/irqs.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/memory.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/mv78xx0.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/system.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/timex.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/uncompress.h [new file with mode: 0644]
include/asm-arm/arch-mv78xx0/vmalloc.h [new file with mode: 0644]
include/asm-arm/arch-mxc/board-mx27ads.h [new file with mode: 0644]
include/asm-arm/arch-mxc/board-mx31ads.h
include/asm-arm/arch-mxc/board-mx31lite.h [new file with mode: 0644]
include/asm-arm/arch-mxc/board-pcm037.h [new file with mode: 0644]
include/asm-arm/arch-mxc/board-pcm038.h [new file with mode: 0644]
include/asm-arm/arch-mxc/clock.h [new file with mode: 0644]
include/asm-arm/arch-mxc/common.h
include/asm-arm/arch-mxc/debug-macro.S [new file with mode: 0644]
include/asm-arm/arch-mxc/gpio.h [new file with mode: 0644]
include/asm-arm/arch-mxc/hardware.h
include/asm-arm/arch-mxc/iim.h [new file with mode: 0644]
include/asm-arm/arch-mxc/imx-uart.h [new file with mode: 0644]
include/asm-arm/arch-mxc/iomux-mx1-mx2.h [new file with mode: 0644]
include/asm-arm/arch-mxc/iomux-mx3.h [new file with mode: 0644]
include/asm-arm/arch-mxc/irqs.h
include/asm-arm/arch-mxc/mx27.h [new file with mode: 0644]
include/asm-arm/arch-mxc/mx31.h
include/asm-arm/arch-mxc/mxc.h
include/asm-arm/arch-mxc/mxc_timer.h [new file with mode: 0644]
include/asm-arm/arch-ns9xxx/hardware.h
include/asm-arm/arch-omap/board-2430sdp.h
include/asm-arm/arch-omap/board-h3.h
include/asm-arm/arch-omap/board-innovator.h
include/asm-arm/arch-omap/board-perseus2.h
include/asm-arm/arch-omap/clock.h
include/asm-arm/arch-omap/common.h
include/asm-arm/arch-omap/control.h
include/asm-arm/arch-omap/cpu.h
include/asm-arm/arch-omap/dma.h
include/asm-arm/arch-omap/dmtimer.h
include/asm-arm/arch-omap/fpga.h
include/asm-arm/arch-omap/hardware.h
include/asm-arm/arch-omap/io.h
include/asm-arm/arch-omap/irqs.h
include/asm-arm/arch-omap/mcbsp.h
include/asm-arm/arch-omap/omap34xx.h [new file with mode: 0644]
include/asm-arm/arch-omap/sram.h
include/asm-arm/arch-omap/tc.h
include/asm-arm/arch-omap/usb.h
include/asm-arm/arch-orion5x/io.h
include/asm-arm/arch-orion5x/orion5x.h
include/asm-arm/arch-orion5x/uncompress.h
include/asm-arm/arch-pxa/audio.h
include/asm-arm/arch-pxa/hardware.h
include/asm-arm/arch-pxa/irda.h
include/asm-arm/arch-pxa/pxa-regs.h
include/asm-arm/arch-pxa/pxa25x-udc.h [new file with mode: 0644]
include/asm-arm/arch-pxa/pxa27x-udc.h [new file with mode: 0644]
include/asm-arm/arch-pxa/pxa2xx-gpio.h
include/asm-arm/arch-pxa/pxa2xx-regs.h
include/asm-arm/arch-pxa/system.h
include/asm-arm/arch-pxa/zylonite.h
include/asm-arm/arch-rpc/io.h
include/asm-arm/arch-s3c2410/gpio.h
include/asm-arm/arch-s3c2410/regs-clock.h
include/asm-arm/assembler.h
include/asm-arm/cacheflush.h
include/asm-arm/dyntick.h [deleted file]
include/asm-arm/ecard.h
include/asm-arm/ftrace.h [new file with mode: 0644]
include/asm-arm/hardware/iop3xx-gpio.h [new file with mode: 0644]
include/asm-arm/hw_irq.h
include/asm-arm/kexec.h
include/asm-arm/kprobes.h
include/asm-arm/mach/time.h
include/asm-arm/mmu_context.h
include/asm-arm/plat-orion/cache-feroceon-l2.h [new file with mode: 0644]
include/asm-arm/plat-orion/orion_nand.h
include/asm-arm/plat-orion/pcie.h
include/asm-arm/plat-s3c/regs-timer.h
include/asm-arm/plat-s3c24xx/devs.h
include/asm-arm/rtc.h [deleted file]
include/asm-arm/tlbflush.h
include/asm-avr32/arch-at32ap/board.h
include/asm-avr32/arch-at32ap/init.h
include/asm-avr32/arch-at32ap/pm.h
include/asm-avr32/arch-at32ap/sram.h [new file with mode: 0644]
include/asm-avr32/mmu_context.h
include/asm-avr32/pci.h
include/asm-avr32/pgalloc.h
include/asm-avr32/pgtable.h
include/asm-avr32/thread_info.h
include/asm-avr32/tlbflush.h
include/asm-generic/pgtable.h
include/asm-generic/topology.h
include/asm-generic/vmlinux.lds.h
include/asm-mips/mach-au1x00/au1xxx_psc.h
include/asm-powerpc/ftrace.h [new file with mode: 0644]
include/asm-powerpc/hw_irq.h
include/asm-s390/Kbuild
include/asm-s390/airq.h
include/asm-s390/ccwdev.h
include/asm-s390/chpid.h
include/asm-s390/chsc.h [new file with mode: 0644]
include/asm-s390/cio.h
include/asm-s390/elf.h
include/asm-s390/etr.h
include/asm-s390/fcx.h [new file with mode: 0644]
include/asm-s390/ipl.h
include/asm-s390/isc.h [new file with mode: 0644]
include/asm-s390/itcw.h [new file with mode: 0644]
include/asm-s390/pgtable.h
include/asm-s390/processor.h
include/asm-s390/ptrace.h
include/asm-s390/schid.h [new file with mode: 0644]
include/asm-s390/sclp.h
include/asm-s390/setup.h
include/asm-s390/sparsemem.h
include/asm-s390/timer.h
include/asm-s390/zcrypt.h
include/asm-sparc64/ftrace.h [new file with mode: 0644]
include/asm-x86/acpi.h
include/asm-x86/alternative.h
include/asm-x86/amd_iommu.h [new file with mode: 0644]
include/asm-x86/amd_iommu_types.h [new file with mode: 0644]
include/asm-x86/apic.h
include/asm-x86/asm.h
include/asm-x86/atomic_64.h
include/asm-x86/bios_ebda.h
include/asm-x86/bitops.h
include/asm-x86/bootparam.h
include/asm-x86/cmpxchg_64.h
include/asm-x86/cpufeature.h
include/asm-x86/current.h
include/asm-x86/current_32.h [deleted file]
include/asm-x86/current_64.h [deleted file]
include/asm-x86/desc.h
include/asm-x86/desc_defs.h
include/asm-x86/dmi.h
include/asm-x86/dwarf2.h
include/asm-x86/dwarf2_32.h [deleted file]
include/asm-x86/dwarf2_64.h [deleted file]
include/asm-x86/e820.h
include/asm-x86/e820_32.h [deleted file]
include/asm-x86/e820_64.h [deleted file]
include/asm-x86/efi.h
include/asm-x86/elf.h
include/asm-x86/fixmap.h
include/asm-x86/fixmap_32.h
include/asm-x86/fixmap_64.h
include/asm-x86/ftrace.h [new file with mode: 0644]
include/asm-x86/gart.h
include/asm-x86/genapic_64.h
include/asm-x86/hardirq.h
include/asm-x86/highmem.h
include/asm-x86/hpet.h
include/asm-x86/hw_irq.h
include/asm-x86/hw_irq_32.h [deleted file]
include/asm-x86/hw_irq_64.h [deleted file]
include/asm-x86/i8259.h
include/asm-x86/io.h
include/asm-x86/io_32.h
include/asm-x86/io_64.h
include/asm-x86/io_apic.h
include/asm-x86/iommu.h
include/asm-x86/ipi.h
include/asm-x86/irq.h
include/asm-x86/irq_32.h [deleted file]
include/asm-x86/irq_64.h [deleted file]
include/asm-x86/irq_vectors.h [new file with mode: 0644]
include/asm-x86/irqflags.h
include/asm-x86/mach-bigsmp/mach_apic.h
include/asm-x86/mach-bigsmp/mach_mpspec.h [deleted file]
include/asm-x86/mach-default/irq_vectors.h [deleted file]
include/asm-x86/mach-default/irq_vectors_limits.h [deleted file]
include/asm-x86/mach-default/mach_apic.h
include/asm-x86/mach-default/setup_arch.h
include/asm-x86/mach-default/smpboot_hooks.h
include/asm-x86/mach-es7000/mach_mpspec.h [deleted file]
include/asm-x86/mach-generic/mach_mpparse.h
include/asm-x86/mach-numaq/mach_apic.h
include/asm-x86/mach-numaq/mach_mpparse.h
include/asm-x86/mach-numaq/mach_mpspec.h [deleted file]
include/asm-x86/mach-summit/mach_mpspec.h [deleted file]
include/asm-x86/mach-visws/cobalt.h [deleted file]
include/asm-x86/mach-visws/irq_vectors.h [deleted file]
include/asm-x86/mach-visws/lithium.h [deleted file]
include/asm-x86/mach-visws/mach_apic.h
include/asm-x86/mach-visws/mach_apicdef.h
include/asm-x86/mach-visws/piix4.h [deleted file]
include/asm-x86/mach-visws/setup_arch.h
include/asm-x86/mach-visws/smpboot_hooks.h
include/asm-x86/mach-voyager/irq_vectors.h [deleted file]
include/asm-x86/mmconfig.h [new file with mode: 0644]
include/asm-x86/mmu_context.h
include/asm-x86/mmu_context_32.h
include/asm-x86/mmu_context_64.h
include/asm-x86/mmzone_32.h
include/asm-x86/mpspec.h
include/asm-x86/mpspec_def.h
include/asm-x86/msr-index.h
include/asm-x86/msr.h
include/asm-x86/nmi.h
include/asm-x86/numa_32.h
include/asm-x86/numa_64.h
include/asm-x86/numaq.h
include/asm-x86/page.h
include/asm-x86/page_32.h
include/asm-x86/page_64.h
include/asm-x86/paravirt.h
include/asm-x86/pat.h
include/asm-x86/pci.h
include/asm-x86/pci_32.h
include/asm-x86/pda.h
include/asm-x86/percpu.h
include/asm-x86/pgalloc.h
include/asm-x86/pgtable.h
include/asm-x86/pgtable_32.h
include/asm-x86/pgtable_64.h
include/asm-x86/processor-flags.h
include/asm-x86/processor.h
include/asm-x86/proto.h
include/asm-x86/ptrace.h
include/asm-x86/reboot.h
include/asm-x86/required-features.h
include/asm-x86/resume-trace.h
include/asm-x86/seccomp_32.h
include/asm-x86/seccomp_64.h
include/asm-x86/segment.h
include/asm-x86/setup.h
include/asm-x86/smp.h
include/asm-x86/srat.h
include/asm-x86/string_32.h
include/asm-x86/suspend_32.h
include/asm-x86/system.h
include/asm-x86/thread_info.h
include/asm-x86/thread_info_32.h [deleted file]
include/asm-x86/thread_info_64.h [deleted file]
include/asm-x86/time.h
include/asm-x86/timer.h
include/asm-x86/topology.h
include/asm-x86/tsc.h
include/asm-x86/uaccess.h
include/asm-x86/uaccess_32.h
include/asm-x86/uaccess_64.h
include/asm-x86/unistd_64.h
include/asm-x86/uv/uv_bau.h [new file with mode: 0644]
include/asm-x86/uv/uv_hub.h
include/asm-x86/uv/uv_mmrs.h
include/asm-x86/visws/cobalt.h [new file with mode: 0644]
include/asm-x86/visws/lithium.h [new file with mode: 0644]
include/asm-x86/visws/piix4.h [new file with mode: 0644]
include/asm-x86/visws/sgivw.h [new file with mode: 0644]
include/asm-x86/vm86.h
include/asm-x86/vmi_time.h
include/asm-x86/vsyscall.h
include/asm-x86/xen/hypercall.h
include/asm-x86/xen/page.h
include/asm-x86/xor_32.h
include/asm-x86/xor_64.h
include/crypto/hash.h [new file with mode: 0644]
include/crypto/internal/hash.h [new file with mode: 0644]
include/drm/Kbuild [new file with mode: 0644]
include/drm/drm.h [new file with mode: 0644]
include/drm/drmP.h [new file with mode: 0644]
include/drm/drm_core.h [new file with mode: 0644]
include/drm/drm_hashtab.h [new file with mode: 0644]
include/drm/drm_memory.h [new file with mode: 0644]
include/drm/drm_memory_debug.h [new file with mode: 0644]
include/drm/drm_os_linux.h [new file with mode: 0644]
include/drm/drm_pciids.h [new file with mode: 0644]
include/drm/drm_sarea.h [new file with mode: 0644]
include/drm/drm_sman.h [new file with mode: 0644]
include/drm/i810_drm.h [new file with mode: 0644]
include/drm/i830_drm.h [new file with mode: 0644]
include/drm/i915_drm.h [new file with mode: 0644]
include/drm/mga_drm.h [new file with mode: 0644]
include/drm/r128_drm.h [new file with mode: 0644]
include/drm/radeon_drm.h [new file with mode: 0644]
include/drm/savage_drm.h [new file with mode: 0644]
include/drm/sis_drm.h [new file with mode: 0644]
include/drm/via_drm.h [new file with mode: 0644]
include/linux/acpi.h
include/linux/bio.h
include/linux/blkdev.h
include/linux/blktrace_api.h
include/linux/bootmem.h
include/linux/console.h
include/linux/crypto.h
include/linux/delay.h
include/linux/efi.h
include/linux/firmware-map.h [new file with mode: 0644]
include/linux/fs.h
include/linux/ftrace.h [new file with mode: 0644]
include/linux/genhd.h
include/linux/interrupt.h
include/linux/iocontext.h
include/linux/irqflags.h
include/linux/kernel.h
include/linux/kernel_stat.h
include/linux/kprobes.h
include/linux/linkage.h
include/linux/lockdep.h
include/linux/marker.h
include/linux/mm.h
include/linux/mmiotrace.h [new file with mode: 0644]
include/linux/mod_devicetable.h
include/linux/page-flags.h
include/linux/pageblock-flags.h
include/linux/preempt.h
include/linux/ptrace.h
include/linux/pwm.h [new file with mode: 0644]
include/linux/pwm_backlight.h [new file with mode: 0644]
include/linux/resume-trace.h
include/linux/sched.h
include/linux/security.h
include/linux/smp_lock.h
include/linux/writeback.h
include/pcmcia/bulkmem.h [deleted file]
include/pcmcia/cistpl.h
include/pcmcia/cs.h
include/pcmcia/cs_types.h
include/pcmcia/ds.h
include/pcmcia/ss.h
include/pcmcia/version.h [deleted file]
include/sound/ad1843.h [new file with mode: 0644]
include/sound/control.h
include/sound/core.h
include/sound/cs4231-regs.h
include/sound/cs4231.h
include/sound/emu10k1.h
include/sound/seq_kernel.h
include/sound/soc-dapm.h
include/sound/soc.h
include/sound/uda1341.h
include/sound/version.h
include/xen/events.h
include/xen/grant_table.h
include/xen/hvc-console.h
include/xen/interface/elfnote.h
include/xen/interface/features.h
include/xen/interface/io/fbif.h
include/xen/interface/io/kbdif.h
include/xen/interface/memory.h
include/xen/interface/xen.h
include/xen/xen-ops.h
init/calibrate.c
kernel/Makefile
kernel/cpu.c
kernel/cpuset.c
kernel/exit.c
kernel/fork.c
kernel/hrtimer.c
kernel/kthread.c
kernel/lockdep.c
kernel/lockdep_internals.h
kernel/lockdep_proc.c
kernel/marker.c
kernel/mutex-debug.c
kernel/mutex.c
kernel/pm_qos_params.c
kernel/printk.c
kernel/ptrace.c
kernel/rcuclassic.c
kernel/rcupreempt.c
kernel/sched.c
kernel/sched_clock.c
kernel/sched_cpupri.c [new file with mode: 0644]
kernel/sched_cpupri.h [new file with mode: 0644]
kernel/sched_debug.c
kernel/sched_fair.c
kernel/sched_features.h
kernel/sched_rt.c
kernel/sched_stats.h
kernel/semaphore.c
kernel/softirq.c
kernel/spinlock.c
kernel/stop_machine.c
kernel/sysctl.c
kernel/time/tick-broadcast.c
kernel/time/tick-sched.c
kernel/timer.c
kernel/trace/Kconfig [new file with mode: 0644]
kernel/trace/Makefile [new file with mode: 0644]
kernel/trace/ftrace.c [new file with mode: 0644]
kernel/trace/trace.c [new file with mode: 0644]
kernel/trace/trace.h [new file with mode: 0644]
kernel/trace/trace_functions.c [new file with mode: 0644]
kernel/trace/trace_irqsoff.c [new file with mode: 0644]
kernel/trace/trace_mmiotrace.c [new file with mode: 0644]
kernel/trace/trace_sched_switch.c [new file with mode: 0644]
kernel/trace/trace_sched_wakeup.c [new file with mode: 0644]
kernel/trace/trace_selftest.c [new file with mode: 0644]
kernel/trace/trace_selftest_dynamic.c [new file with mode: 0644]
kernel/trace/trace_sysprof.c [new file with mode: 0644]
lib/Kconfig.debug
lib/Makefile
lib/smp_processor_id.c
mm/Kconfig
mm/mprotect.c
mm/page-writeback.c
mm/page_alloc.c
mm/slub.c
net/core/dev.c
net/irda/irnet/irnet.h
net/irda/irnet/irnet_ppp.c
net/iucv/af_iucv.c
net/iucv/iucv.c
scripts/Makefile.lib
scripts/mod/file2alias.c
security/Kconfig
security/Makefile
security/capability.c
security/commoncap.c
security/dummy.c [deleted file]
security/root_plug.c
security/security.c
security/selinux/hooks.c
security/selinux/include/audit.h
security/selinux/include/avc.h
security/selinux/include/objsec.h
security/selinux/include/security.h
security/selinux/netnode.c
security/selinux/netport.c
security/selinux/selinuxfs.c
security/selinux/ss/avtab.c
security/selinux/ss/context.h
security/selinux/ss/mls.c
security/selinux/ss/mls.h
security/selinux/ss/policydb.c
security/selinux/ss/services.c
security/selinux/ss/sidtab.c
security/selinux/ss/sidtab.h
security/smack/smack_lsm.c
sound/Kconfig
sound/aoa/Kconfig
sound/aoa/codecs/Kconfig
sound/aoa/fabrics/Kconfig
sound/aoa/soundbus/Kconfig
sound/arm/Kconfig
sound/arm/sa11xx-uda1341.c
sound/core/Kconfig
sound/core/control.c
sound/core/init.c
sound/core/memalloc.c
sound/core/pcm_native.c
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_device.c
sound/core/sound.c
sound/core/timer.c
sound/drivers/Kconfig
sound/drivers/vx/vx_hwdep.c
sound/i2c/cs8427.c
sound/i2c/l3/uda1341.c
sound/isa/Kconfig
sound/isa/cs423x/cs4231_lib.c
sound/isa/opti9xx/opti92x-ad1848.c
sound/isa/sb/Makefile
sound/isa/wavefront/wavefront_synth.c
sound/mips/Kconfig
sound/mips/Makefile
sound/mips/ad1843.c [new file with mode: 0644]
sound/mips/hal2.c [new file with mode: 0644]
sound/mips/hal2.h [new file with mode: 0644]
sound/mips/sgio2audio.c [new file with mode: 0644]
sound/oss/Kconfig
sound/oss/dmasound/dmasound_core.c
sound/oss/dmasound/dmasound_paula.c
sound/oss/dmasound/dmasound_q40.c
sound/oss/msnd.c
sound/oss/msnd.h
sound/oss/msnd_classic.h
sound/oss/msnd_pinnacle.c
sound/oss/msnd_pinnacle.h
sound/oss/vwsnd.c
sound/parisc/Kconfig
sound/pci/Kconfig
sound/pci/Makefile
sound/pci/ac97/Makefile
sound/pci/ac97/ac97_codec.c
sound/pci/ac97/ac97_patch.c
sound/pci/ac97/ak4531_codec.c [deleted file]
sound/pci/ak4531_codec.c [new file with mode: 0644]
sound/pci/au88x0/au88x0_game.c
sound/pci/azt3328.c
sound/pci/azt3328.h
sound/pci/ca0106/ca0106_main.c
sound/pci/emu10k1/emu10k1_main.c
sound/pci/emu10k1/emumixer.c
sound/pci/emu10k1/memory.c
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_codec.h
sound/pci/hda/hda_hwdep.c
sound/pci/hda/hda_intel.c
sound/pci/hda/hda_proc.c
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c
sound/pci/ice1712/envy24ht.h
sound/pci/ice1712/ice1712.h
sound/pci/ice1712/ice1724.c
sound/pci/maestro3.c
sound/pci/nm256/nm256.c
sound/pci/oxygen/hifier.c
sound/pci/oxygen/oxygen.c
sound/pci/oxygen/oxygen.h
sound/pci/oxygen/oxygen_io.c
sound/pci/oxygen/oxygen_lib.c
sound/pci/oxygen/oxygen_pcm.c
sound/pci/oxygen/virtuoso.c
sound/pci/pcxhr/pcxhr.c
sound/pci/pcxhr/pcxhr_core.c
sound/pci/trident/trident_main.c
sound/pci/trident/trident_memory.c
sound/pci/via82xx.c
sound/pci/ymfpci/ymfpci_main.c
sound/pcmcia/Kconfig
sound/pcmcia/vx/vxp_ops.c
sound/ppc/Kconfig
sound/ppc/daca.c
sound/ppc/tumbler.c
sound/sh/Kconfig
sound/soc/Kconfig
sound/soc/Makefile
sound/soc/at32/Kconfig [new file with mode: 0644]
sound/soc/at32/Makefile [new file with mode: 0644]
sound/soc/at32/at32-pcm.c [new file with mode: 0644]
sound/soc/at32/at32-pcm.h [new file with mode: 0644]
sound/soc/at32/at32-ssc.c [new file with mode: 0644]
sound/soc/at32/at32-ssc.h [new file with mode: 0644]
sound/soc/at32/playpaq_wm8510.c [new file with mode: 0644]
sound/soc/at91/Kconfig
sound/soc/at91/at91-pcm.c
sound/soc/at91/at91-ssc.c
sound/soc/at91/at91-ssc.h
sound/soc/at91/eti_b1_wm8731.c
sound/soc/au1x/Kconfig [new file with mode: 0644]
sound/soc/au1x/Makefile [new file with mode: 0644]
sound/soc/au1x/dbdma2.c [new file with mode: 0644]
sound/soc/au1x/psc-ac97.c [new file with mode: 0644]
sound/soc/au1x/psc-i2s.c [new file with mode: 0644]
sound/soc/au1x/psc.h [new file with mode: 0644]
sound/soc/au1x/sample-ac97.c [new file with mode: 0644]
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/ac97.c
sound/soc/codecs/ac97.h
sound/soc/codecs/ak4535.c [new file with mode: 0644]
sound/soc/codecs/ak4535.h [new file with mode: 0644]
sound/soc/codecs/cs4270.c
sound/soc/codecs/cs4270.h
sound/soc/codecs/tlv320aic3x.c
sound/soc/codecs/tlv320aic3x.h
sound/soc/codecs/uda1380.c [new file with mode: 0644]
sound/soc/codecs/uda1380.h [new file with mode: 0644]
sound/soc/codecs/wm8510.c [new file with mode: 0644]
sound/soc/codecs/wm8510.h [new file with mode: 0644]
sound/soc/codecs/wm8731.c
sound/soc/codecs/wm8731.h
sound/soc/codecs/wm8750.c
sound/soc/codecs/wm8750.h
sound/soc/codecs/wm8753.c
sound/soc/codecs/wm8753.h
sound/soc/codecs/wm8990.c [new file with mode: 0644]
sound/soc/codecs/wm8990.h [new file with mode: 0644]
sound/soc/codecs/wm9712.c
sound/soc/codecs/wm9712.h
sound/soc/codecs/wm9713.c
sound/soc/codecs/wm9713.h
sound/soc/davinci/Kconfig
sound/soc/davinci/davinci-evm.c
sound/soc/davinci/davinci-i2s.c
sound/soc/davinci/davinci-i2s.h
sound/soc/davinci/davinci-pcm.c
sound/soc/fsl/Kconfig
sound/soc/fsl/fsl_dma.c
sound/soc/fsl/fsl_dma.h
sound/soc/fsl/fsl_ssi.c
sound/soc/fsl/fsl_ssi.h
sound/soc/fsl/mpc8610_hpcd.c
sound/soc/omap/Kconfig
sound/soc/omap/n810.c
sound/soc/omap/omap-mcbsp.c
sound/soc/omap/omap-mcbsp.h
sound/soc/omap/omap-pcm.c
sound/soc/pxa/Kconfig
sound/soc/pxa/Makefile
sound/soc/pxa/corgi.c
sound/soc/pxa/em-x270.c [new file with mode: 0644]
sound/soc/pxa/poodle.c
sound/soc/pxa/pxa2xx-ac97.c
sound/soc/pxa/pxa2xx-ac97.h
sound/soc/pxa/pxa2xx-i2s.c
sound/soc/pxa/pxa2xx-i2s.h
sound/soc/pxa/pxa2xx-pcm.c
sound/soc/pxa/spitz.c
sound/soc/pxa/tosa.c
sound/soc/s3c24xx/Kconfig
sound/soc/s3c24xx/neo1973_wm8753.c
sound/soc/s3c24xx/s3c2412-i2s.c
sound/soc/s3c24xx/s3c2412-i2s.h
sound/soc/s3c24xx/s3c2443-ac97.c
sound/soc/s3c24xx/s3c24xx-ac97.h
sound/soc/s3c24xx/s3c24xx-i2s.c
sound/soc/s3c24xx/s3c24xx-i2s.h
sound/soc/s3c24xx/s3c24xx-pcm.c
sound/soc/s3c24xx/smdk2443_wm9710.c
sound/soc/sh/Kconfig
sound/soc/sh/dma-sh7760.c
sound/soc/sh/hac.c
sound/soc/sh/sh7760-ac97.c
sound/soc/sh/ssi.c
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/sound_core.c
sound/sparc/Kconfig
sound/sparc/dbri.c
sound/spi/Kconfig
sound/usb/Kconfig
sound/usb/caiaq/caiaq-audio.c
sound/usb/caiaq/caiaq-device.c
sound/usb/caiaq/caiaq-device.h
sound/usb/usbaudio.c
sound/usb/usbquirks.h

index 4bd9ea5..44f52a4 100644 (file)
@@ -26,3 +26,37 @@ Description:
                I/O statistics of partition <part>. The format is the
                same as the above-written /sys/block/<disk>/stat
                format.
+
+
+What:          /sys/block/<disk>/integrity/format
+Date:          June 2008
+Contact:       Martin K. Petersen <martin.petersen@oracle.com>
+Description:
+               Metadata format for integrity capable block device.
+               E.g. T10-DIF-TYPE1-CRC.
+
+
+What:          /sys/block/<disk>/integrity/read_verify
+Date:          June 2008
+Contact:       Martin K. Petersen <martin.petersen@oracle.com>
+Description:
+               Indicates whether the block layer should verify the
+               integrity of read requests serviced by devices that
+               support sending integrity metadata.
+
+
+What:          /sys/block/<disk>/integrity/tag_size
+Date:          June 2008
+Contact:       Martin K. Petersen <martin.petersen@oracle.com>
+Description:
+               Number of bytes of integrity tag space available per
+               512 bytes of data.
+
+
+What:          /sys/block/<disk>/integrity/write_generate
+Date:          June 2008
+Contact:       Martin K. Petersen <martin.petersen@oracle.com>
+Description:
+               Indicates whether the block layer should automatically
+               generate checksums for write requests bound for
+               devices that support receiving integrity metadata.
diff --git a/Documentation/ABI/testing/sysfs-bus-css b/Documentation/ABI/testing/sysfs-bus-css
new file mode 100644 (file)
index 0000000..b585ec2
--- /dev/null
@@ -0,0 +1,35 @@
+What:          /sys/bus/css/devices/.../type
+Date:          March 2008
+Contact:       Cornelia Huck <cornelia.huck@de.ibm.com>
+               linux-s390@vger.kernel.org
+Description:   Contains the subchannel type, as reported by the hardware.
+               This attribute is present for all subchannel types.
+
+What:          /sys/bus/css/devices/.../modalias
+Date:          March 2008
+Contact:       Cornelia Huck <cornelia.huck@de.ibm.com>
+               linux-s390@vger.kernel.org
+Description:   Contains the module alias as reported with uevents.
+               It is of the format css:t<type> and present for all
+               subchannel types.
+
+What:          /sys/bus/css/drivers/io_subchannel/.../chpids
+Date:          December 2002
+Contact:       Cornelia Huck <cornelia.huck@de.ibm.com>
+               linux-s390@vger.kernel.org
+Description:   Contains the ids of the channel paths used by this
+               subchannel, as reported by the channel subsystem
+               during subchannel recognition.
+               Note: This is an I/O-subchannel specific attribute.
+Users:         s390-tools, HAL
+
+What:          /sys/bus/css/drivers/io_subchannel/.../pimpampom
+Date:          December 2002
+Contact:       Cornelia Huck <cornelia.huck@de.ibm.com>
+               linux-s390@vger.kernel.org
+Description:   Contains the PIM/PAM/POM values, as reported by the
+               channel subsystem when last queried by the common I/O
+               layer (this implies that this attribute is not neccessarily
+               in sync with the values current in the channel subsystem).
+               Note: This is an I/O-subchannel specific attribute.
+Users:         s390-tools, HAL
diff --git a/Documentation/ABI/testing/sysfs-firmware-memmap b/Documentation/ABI/testing/sysfs-firmware-memmap
new file mode 100644 (file)
index 0000000..0d99ee6
--- /dev/null
@@ -0,0 +1,71 @@
+What:          /sys/firmware/memmap/
+Date:          June 2008
+Contact:       Bernhard Walle <bwalle@suse.de>
+Description:
+               On all platforms, the firmware provides a memory map which the
+               kernel reads. The resources from that memory map are registered
+               in the kernel resource tree and exposed to userspace via
+               /proc/iomem (together with other resources).
+
+               However, on most architectures that firmware-provided memory
+               map is modified afterwards by the kernel itself, either because
+               the kernel merges that memory map with other information or
+               just because the user overwrites that memory map via command
+               line.
+
+               kexec needs the raw firmware-provided memory map to setup the
+               parameter segment of the kernel that should be booted with
+               kexec. Also, the raw memory map is useful for debugging. For
+               that reason, /sys/firmware/memmap is an interface that provides
+               the raw memory map to userspace.
+
+               The structure is as follows: Under /sys/firmware/memmap there
+               are subdirectories with the number of the entry as their name:
+
+                       /sys/firmware/memmap/0
+                       /sys/firmware/memmap/1
+                       /sys/firmware/memmap/2
+                       /sys/firmware/memmap/3
+                       ...
+
+               The maximum depends on the number of memory map entries provided
+               by the firmware. The order is just the order that the firmware
+               provides.
+
+               Each directory contains three files:
+
+               start   : The start address (as hexadecimal number with the
+                         '0x' prefix).
+               end     : The end address, inclusive (regardless whether the
+                         firmware provides inclusive or exclusive ranges).
+               type    : Type of the entry as string. See below for a list of
+                         valid types.
+
+               So, for example:
+
+                       /sys/firmware/memmap/0/start
+                       /sys/firmware/memmap/0/end
+                       /sys/firmware/memmap/0/type
+                       /sys/firmware/memmap/1/start
+                       ...
+
+               Currently following types exist:
+
+                 - System RAM
+                 - ACPI Tables
+                 - ACPI Non-volatile Storage
+                 - reserved
+
+               Following shell snippet can be used to display that memory
+               map in a human-readable format:
+
+               -------------------- 8< ----------------------------------------
+                 #!/bin/bash
+                 cd /sys/firmware/memmap
+                 for dir in * ; do
+                     start=$(cat $dir/start)
+                     end=$(cat $dir/end)
+                     type=$(cat $dir/type)
+                     printf "%016x-%016x (%s)\n" $start $[ $end +1] "$type"
+                 done
+               -------------------- >8 ----------------------------------------
diff --git a/Documentation/block/data-integrity.txt b/Documentation/block/data-integrity.txt
new file mode 100644 (file)
index 0000000..e9dc8d8
--- /dev/null
@@ -0,0 +1,327 @@
+----------------------------------------------------------------------
+1. INTRODUCTION
+
+Modern filesystems feature checksumming of data and metadata to
+protect against data corruption.  However, the detection of the
+corruption is done at read time which could potentially be months
+after the data was written.  At that point the original data that the
+application tried to write is most likely lost.
+
+The solution is to ensure that the disk is actually storing what the
+application meant it to.  Recent additions to both the SCSI family
+protocols (SBC Data Integrity Field, SCC protection proposal) as well
+as SATA/T13 (External Path Protection) try to remedy this by adding
+support for appending integrity metadata to an I/O.  The integrity
+metadata (or protection information in SCSI terminology) includes a
+checksum for each sector as well as an incrementing counter that
+ensures the individual sectors are written in the right order.  And
+for some protection schemes also that the I/O is written to the right
+place on disk.
+
+Current storage controllers and devices implement various protective
+measures, for instance checksumming and scrubbing.  But these
+technologies are working in their own isolated domains or at best
+between adjacent nodes in the I/O path.  The interesting thing about
+DIF and the other integrity extensions is that the protection format
+is well defined and every node in the I/O path can verify the
+integrity of the I/O and reject it if corruption is detected.  This
+allows not only corruption prevention but also isolation of the point
+of failure.
+
+----------------------------------------------------------------------
+2. THE DATA INTEGRITY EXTENSIONS
+
+As written, the protocol extensions only protect the path between
+controller and storage device.  However, many controllers actually
+allow the operating system to interact with the integrity metadata
+(IMD).  We have been working with several FC/SAS HBA vendors to enable
+the protection information to be transferred to and from their
+controllers.
+
+The SCSI Data Integrity Field works by appending 8 bytes of protection
+information to each sector.  The data + integrity metadata is stored
+in 520 byte sectors on disk.  Data + IMD are interleaved when
+transferred between the controller and target.  The T13 proposal is
+similar.
+
+Because it is highly inconvenient for operating systems to deal with
+520 (and 4104) byte sectors, we approached several HBA vendors and
+encouraged them to allow separation of the data and integrity metadata
+scatter-gather lists.
+
+The controller will interleave the buffers on write and split them on
+read.  This means that the Linux can DMA the data buffers to and from
+host memory without changes to the page cache.
+
+Also, the 16-bit CRC checksum mandated by both the SCSI and SATA specs
+is somewhat heavy to compute in software.  Benchmarks found that
+calculating this checksum had a significant impact on system
+performance for a number of workloads.  Some controllers allow a
+lighter-weight checksum to be used when interfacing with the operating
+system.  Emulex, for instance, supports the TCP/IP checksum instead.
+The IP checksum received from the OS is converted to the 16-bit CRC
+when writing and vice versa.  This allows the integrity metadata to be
+generated by Linux or the application at very low cost (comparable to
+software RAID5).
+
+The IP checksum is weaker than the CRC in terms of detecting bit
+errors.  However, the strength is really in the separation of the data
+buffers and the integrity metadata.  These two distinct buffers much
+match up for an I/O to complete.
+
+The separation of the data and integrity metadata buffers as well as
+the choice in checksums is referred to as the Data Integrity
+Extensions.  As these extensions are outside the scope of the protocol
+bodies (T10, T13), Oracle and its partners are trying to standardize
+them within the Storage Networking Industry Association.
+
+----------------------------------------------------------------------
+3. KERNEL CHANGES
+
+The data integrity framework in Linux enables protection information
+to be pinned to I/Os and sent to/received from controllers that
+support it.
+
+The advantage to the integrity extensions in SCSI and SATA is that
+they enable us to protect the entire path from application to storage
+device.  However, at the same time this is also the biggest
+disadvantage. It means that the protection information must be in a
+format that can be understood by the disk.
+
+Generally Linux/POSIX applications are agnostic to the intricacies of
+the storage devices they are accessing.  The virtual filesystem switch
+and the block layer make things like hardware sector size and
+transport protocols completely transparent to the application.
+
+However, this level of detail is required when preparing the
+protection information to send to a disk.  Consequently, the very
+concept of an end-to-end protection scheme is a layering violation.
+It is completely unreasonable for an application to be aware whether
+it is accessing a SCSI or SATA disk.
+
+The data integrity support implemented in Linux attempts to hide this
+from the application.  As far as the application (and to some extent
+the kernel) is concerned, the integrity metadata is opaque information
+that's attached to the I/O.
+
+The current implementation allows the block layer to automatically
+generate the protection information for any I/O.  Eventually the
+intent is to move the integrity metadata calculation to userspace for
+user data.  Metadata and other I/O that originates within the kernel
+will still use the automatic generation interface.
+
+Some storage devices allow each hardware sector to be tagged with a
+16-bit value.  The owner of this tag space is the owner of the block
+device.  I.e. the filesystem in most cases.  The filesystem can use
+this extra space to tag sectors as they see fit.  Because the tag
+space is limited, the block interface allows tagging bigger chunks by
+way of interleaving.  This way, 8*16 bits of information can be
+attached to a typical 4KB filesystem block.
+
+This also means that applications such as fsck and mkfs will need
+access to manipulate the tags from user space.  A passthrough
+interface for this is being worked on.
+
+
+----------------------------------------------------------------------
+4. BLOCK LAYER IMPLEMENTATION DETAILS
+
+4.1 BIO
+
+The data integrity patches add a new field to struct bio when
+CONFIG_BLK_DEV_INTEGRITY is enabled.  bio->bi_integrity is a pointer
+to a struct bip which contains the bio integrity payload.  Essentially
+a bip is a trimmed down struct bio which holds a bio_vec containing
+the integrity metadata and the required housekeeping information (bvec
+pool, vector count, etc.)
+
+A kernel subsystem can enable data integrity protection on a bio by
+calling bio_integrity_alloc(bio).  This will allocate and attach the
+bip to the bio.
+
+Individual pages containing integrity metadata can subsequently be
+attached using bio_integrity_add_page().
+
+bio_free() will automatically free the bip.
+
+
+4.2 BLOCK DEVICE
+
+Because the format of the protection data is tied to the physical
+disk, each block device has been extended with a block integrity
+profile (struct blk_integrity).  This optional profile is registered
+with the block layer using blk_integrity_register().
+
+The profile contains callback functions for generating and verifying
+the protection data, as well as getting and setting application tags.
+The profile also contains a few constants to aid in completing,
+merging and splitting the integrity metadata.
+
+Layered block devices will need to pick a profile that's appropriate
+for all subdevices.  blk_integrity_compare() can help with that.  DM
+and MD linear, RAID0 and RAID1 are currently supported.  RAID4/5/6
+will require extra work due to the application tag.
+
+
+----------------------------------------------------------------------
+5.0 BLOCK LAYER INTEGRITY API
+
+5.1 NORMAL FILESYSTEM
+
+    The normal filesystem is unaware that the underlying block device
+    is capable of sending/receiving integrity metadata.  The IMD will
+    be automatically generated by the block layer at submit_bio() time
+    in case of a WRITE.  A READ request will cause the I/O integrity
+    to be verified upon completion.
+
+    IMD generation and verification can be toggled using the
+
+      /sys/block/<bdev>/integrity/write_generate
+
+    and
+
+      /sys/block/<bdev>/integrity/read_verify
+
+    flags.
+
+
+5.2 INTEGRITY-AWARE FILESYSTEM
+
+    A filesystem that is integrity-aware can prepare I/Os with IMD
+    attached.  It can also use the application tag space if this is
+    supported by the block device.
+
+
+    int bdev_integrity_enabled(block_device, int rw);
+
+      bdev_integrity_enabled() will return 1 if the block device
+      supports integrity metadata transfer for the data direction
+      specified in 'rw'.
+
+      bdev_integrity_enabled() honors the write_generate and
+      read_verify flags in sysfs and will respond accordingly.
+
+
+    int bio_integrity_prep(bio);
+
+      To generate IMD for WRITE and to set up buffers for READ, the
+      filesystem must call bio_integrity_prep(bio).
+
+      Prior to calling this function, the bio data direction and start
+      sector must be set, and the bio should have all data pages
+      added.  It is up to the caller to ensure that the bio does not
+      change while I/O is in progress.
+
+      bio_integrity_prep() should only be called if
+      bio_integrity_enabled() returned 1.
+
+
+    int bio_integrity_tag_size(bio);
+
+      If the filesystem wants to use the application tag space it will
+      first have to find out how much storage space is available.
+      Because tag space is generally limited (usually 2 bytes per
+      sector regardless of sector size), the integrity framework
+      supports interleaving the information between the sectors in an
+      I/O.
+
+      Filesystems can call bio_integrity_tag_size(bio) to find out how
+      many bytes of storage are available for that particular bio.
+
+      Another option is bdev_get_tag_size(block_device) which will
+      return the number of available bytes per hardware sector.
+
+
+    int bio_integrity_set_tag(bio, void *tag_buf, len);
+
+      After a successful return from bio_integrity_prep(),
+      bio_integrity_set_tag() can be used to attach an opaque tag
+      buffer to a bio.  Obviously this only makes sense if the I/O is
+      a WRITE.
+
+
+    int bio_integrity_get_tag(bio, void *tag_buf, len);
+
+      Similarly, at READ I/O completion time the filesystem can
+      retrieve the tag buffer using bio_integrity_get_tag().
+
+
+6.3 PASSING EXISTING INTEGRITY METADATA
+
+    Filesystems that either generate their own integrity metadata or
+    are capable of transferring IMD from user space can use the
+    following calls:
+
+
+    struct bip * bio_integrity_alloc(bio, gfp_mask, nr_pages);
+
+      Allocates the bio integrity payload and hangs it off of the bio.
+      nr_pages indicate how many pages of protection data need to be
+      stored in the integrity bio_vec list (similar to bio_alloc()).
+
+      The integrity payload will be freed at bio_free() time.
+
+
+    int bio_integrity_add_page(bio, page, len, offset);
+
+      Attaches a page containing integrity metadata to an existing
+      bio.  The bio must have an existing bip,
+      i.e. bio_integrity_alloc() must have been called.  For a WRITE,
+      the integrity metadata in the pages must be in a format
+      understood by the target device with the notable exception that
+      the sector numbers will be remapped as the request traverses the
+      I/O stack.  This implies that the pages added using this call
+      will be modified during I/O!  The first reference tag in the
+      integrity metadata must have a value of bip->bip_sector.
+
+      Pages can be added using bio_integrity_add_page() as long as
+      there is room in the bip bio_vec array (nr_pages).
+
+      Upon completion of a READ operation, the attached pages will
+      contain the integrity metadata received from the storage device.
+      It is up to the receiver to process them and verify data
+      integrity upon completion.
+
+
+6.4 REGISTERING A BLOCK DEVICE AS CAPABLE OF EXCHANGING INTEGRITY
+    METADATA
+
+    To enable integrity exchange on a block device the gendisk must be
+    registered as capable:
+
+    int blk_integrity_register(gendisk, blk_integrity);
+
+      The blk_integrity struct is a template and should contain the
+      following:
+
+        static struct blk_integrity my_profile = {
+            .name                   = "STANDARDSBODY-TYPE-VARIANT-CSUM",
+            .generate_fn            = my_generate_fn,
+                   .verify_fn              = my_verify_fn,
+                   .get_tag_fn             = my_get_tag_fn,
+                   .set_tag_fn             = my_set_tag_fn,
+           .tuple_size             = sizeof(struct my_tuple_size),
+           .tag_size               = <tag bytes per hw sector>,
+        };
+
+      'name' is a text string which will be visible in sysfs.  This is
+      part of the userland API so chose it carefully and never change
+      it.  The format is standards body-type-variant.
+      E.g. T10-DIF-TYPE1-IP or T13-EPP-0-CRC.
+
+      'generate_fn' generates appropriate integrity metadata (for WRITE).
+
+      'verify_fn' verifies that the data buffer matches the integrity
+      metadata.
+
+      'tuple_size' must be set to match the size of the integrity
+      metadata per sector.  I.e. 8 for DIF and EPP.
+
+      'tag_size' must be set to identify how many bytes of tag space
+      are available per hardware sector.  For DIF this is either 2 or
+      0 depending on the value of the Control Mode Page ATO bit.
+
+      See 6.2 for a description of get_tag_fn and set_tag_fn.
+
+----------------------------------------------------------------------
+2007-12-24 Martin K. Petersen <martin.petersen@oracle.com>
index 13e4bf0..77d3faa 100644 (file)
@@ -2,8 +2,11 @@
                ========================
 
 Copyright 2008 Red Hat Inc.
-Author: Steven Rostedt <srostedt@redhat.com>
+   Author:   Steven Rostedt <srostedt@redhat.com>
+  License:   The GNU Free Documentation License, Version 1.2
+Reviewers:   Elias Oltmanns and Randy Dunlap
 
+Writen for: 2.6.26-rc8 linux-2.6-tip.git tip/tracing/ftrace branch
 
 Introduction
 ------------
@@ -46,7 +49,7 @@ of ftrace. Here is a list of some of the key files:
                that is configured.
 
   available_tracers : This holds the different types of tracers that
-               has been compiled into the kernel. The tracers
+               have been compiled into the kernel. The tracers
                listed here can be configured by echoing in their
                name into current_tracer.
 
@@ -90,11 +93,13 @@ of ftrace. Here is a list of some of the key files:
   trace_entries : This sets or displays the number of trace
                entries each CPU buffer can hold. The tracer buffers
                are the same size for each CPU, so care must be
-               taken when modifying the trace_entries. The number
-               of actually entries will be the number given
-               times the number of possible CPUS. The buffers
-               are saved as individual pages, and the actual entries
-               will always be rounded up to entries per page.
+               taken when modifying the trace_entries. The trace
+               buffers are allocated in pages (blocks of memory that
+               the kernel uses for allocation, usually 4 KB in size).
+               Since each entry is smaller than a page, if the last
+               allocated page has room for more entries than were
+               requested, the rest of the page is used to allocate
+               entries.
 
                This can only be updated when the current_tracer
                is set to "none".
@@ -114,13 +119,13 @@ of ftrace. Here is a list of some of the key files:
                in performance.  This also has a side effect of
                enabling or disabling specific functions to be
                traced.  Echoing in names of functions into this
-               file will limit the trace to only those files.
+               file will limit the trace to only these functions.
 
   set_ftrace_notrace: This has the opposite effect that
                set_ftrace_filter has. Any function that is added
                here will not be traced. If a function exists
-               in both set_ftrace_filter and set_ftrace_notrace
-               the function will _not_ bet traced.
+               in both set_ftrace_filter and set_ftrace_notrace,
+               the function will _not_ be traced.
 
   available_filter_functions : When a function is encountered the first
                time by the dynamic tracer, it is recorded and
@@ -138,7 +143,7 @@ Here are the list of current tracers that can be configured.
 
   ftrace - function tracer that uses mcount to trace all functions.
                It is possible to filter out which functions that are
-               traced when dynamic ftrace is configured in.
+               to be traced when dynamic ftrace is configured in.
 
   sched_switch - traces the context switches between tasks.
 
@@ -297,13 +302,13 @@ explains which is which.
 
 The above is mostly meaningful for kernel developers.
 
-  time: This differs from the trace output where as the trace output
-       contained a absolute timestamp. This timestamp is relative
-       to the start of the first entry in the the trace.
+  time: This differs from the trace file output. The trace file output
+       included an absolute timestamp. The timestamp used by the
+       latency_trace file is relative to the start of the trace.
 
   delay: This is just to help catch your eye a bit better. And
        needs to be fixed to be only relative to the same CPU.
-       The marks is determined by the difference between this
+       The marks are determined by the difference between this
        current trace and the next trace.
         '!' - greater than preempt_mark_thresh (default 100)
         '+' - greater than 1 microsecond
@@ -322,13 +327,13 @@ output. To see what is available, simply cat the file:
   print-parent nosym-offset nosym-addr noverbose noraw nohex nobin \
  noblock nostacktrace nosched-tree
 
-To disable one of the options, echo in the option appended with "no".
+To disable one of the options, echo in the option prepended with "no".
 
   echo noprint-parent > /debug/tracing/iter_ctrl
 
 To enable an option, leave off the "no".
 
-  echo sym-offest > /debug/tracing/iter_ctrl
+  echo sym-offset > /debug/tracing/iter_ctrl
 
 Here are the available options:
 
@@ -344,7 +349,7 @@ Here are the available options:
 
   sym-offset - Display not only the function name, but also the offset
                in the function. For example, instead of seeing just
-               "ktime_get" you will see "ktime_get+0xb/0x20"
+               "ktime_get", you will see "ktime_get+0xb/0x20".
 
   sym-offset:
    bash-4000  [01]  1477.606694: simple_strtoul+0x6/0xa0
@@ -364,7 +369,7 @@ Here are the available options:
        user applications that can translate the raw numbers better than
        having it done in the kernel.
 
-  hex - similar to raw, but the numbers will be in a hexadecimal format.
+  hex - Similar to raw, but the numbers will be in a hexadecimal format.
 
   bin - This will print out the formats in raw binary.
 
@@ -381,7 +386,7 @@ sched_switch
 ------------
 
 This tracer simply records schedule switches. Here's an example
-on how to implement it.
+of how to use it.
 
  # echo sched_switch > /debug/tracing/current_tracer
  # echo 1 > /debug/tracing/tracing_enabled
@@ -470,7 +475,7 @@ interrupt from triggering or the mouse interrupt from letting the
 kernel know of a new mouse event. The result is a latency with the
 reaction time.
 
-The irqsoff tracer tracks the time interrupts are disabled and when
+The irqsoff tracer tracks the time interrupts are disabled to the time
 they are re-enabled. When a new maximum latency is hit, it saves off
 the trace so that it may be retrieved at a later time. Every time a
 new maximum in reached, the old saved trace is discarded and the new
@@ -519,7 +524,7 @@ The difference between the 6 and the displayed timestamp 7us is
 because the clock must have incremented between the time of recording
 the max latency and recording the function that had that latency.
 
-Note the above had ftrace_enabled not set. If we set the ftrace_enabled
+Note the above had ftrace_enabled not set. If we set the ftrace_enabled,
 we get a much larger output:
 
 # tracer: irqsoff
@@ -570,21 +575,21 @@ vim:ft=help
 
 
 Here we traced a 50 microsecond latency. But we also see all the
-functions that were called during that time. Note that enabling
-function tracing we endure an added overhead. This overhead may
-extend the latency times. But never the less, this trace has provided
-some very helpful debugging.
+functions that were called during that time. Note that by enabling
+function tracing, we endure an added overhead. This overhead may
+extend the latency times. But nevertheless, this trace has provided
+some very helpful debugging information.
 
 
 preemptoff
 ----------
 
-When preemption is disabled we may be able to receive interrupts but
-the task can not be preempted and a higher priority task must wait
+When preemption is disabled, we may be able to receive interrupts but
+the task cannot be preempted and a higher priority task must wait
 for preemption to be enabled again before it can preempt a lower
 priority task.
 
-The preemptoff tracer traces the places that disables preemption.
+The preemptoff tracer traces the places that disable preemption.
 Like the irqsoff, it records the maximum latency that preemption
 was disabled. The control of preemptoff is much like the irqsoff.
 
@@ -696,7 +701,7 @@ Notice that the __do_softirq when called doesn't have a preempt_count.
 It may seem that we missed a preempt enabled. What really happened
 is that the preempt count is held on the threads stack and we
 switched to the softirq stack (4K stacks in effect). The code
-does not copy the preempt count, but because interrupts are disabled
+does not copy the preempt count, but because interrupts are disabled,
 we don't need to worry about it. Having a tracer like this is good
 to let people know what really happens inside the kernel.
 
@@ -732,7 +737,7 @@ To record this time, use the preemptirqsoff tracer.
 
 Again, using this trace is much like the irqsoff and preemptoff tracers.
 
- # echo preemptoff > /debug/tracing/current_tracer
+ # echo preemptirqsoff > /debug/tracing/current_tracer
  # echo 0 > /debug/tracing/tracing_max_latency
  # echo 1 > /debug/tracing/tracing_enabled
  # ls -ltr
@@ -862,9 +867,9 @@ This is a very interesting trace. It started with the preemption of
 the ls task. We see that the task had the "need_resched" bit set
 with the 'N' in the trace.  Interrupts are disabled in the spin_lock
 and the trace started. We see that a schedule took place to run
-sshd.  When the interrupts were enabled we took an interrupt.
-On return of the interrupt the softirq ran. We took another interrupt
-while running the softirq as we see with the capital 'H'.
+sshd.  When the interrupts were enabled, we took an interrupt.
+On return from the interrupt handler, the softirq ran. We took another
+interrupt while running the softirq as we see with the capital 'H'.
 
 
 wakeup
@@ -876,9 +881,9 @@ time it executes. This is also known as "schedule latency".
 I stress the point that this is about RT tasks. It is also important
 to know the scheduling latency of non-RT tasks, but the average
 schedule latency is better for non-RT tasks. Tools like
-LatencyTop is more appropriate for such measurements.
+LatencyTop are more appropriate for such measurements.
 
-Real-Time environments is interested in the worst case latency.
+Real-Time environments are interested in the worst case latency.
 That is the longest latency it takes for something to happen, and
 not the average. We can have a very fast scheduler that may only
 have a large latency once in a while, but that would not work well
@@ -889,8 +894,8 @@ tasks that are unpredictable will overwrite the worst case latency
 of RT tasks.
 
 Since this tracer only deals with RT tasks, we will run this slightly
-different than we did with the previous tracers. Instead of performing
-an 'ls' we will run 'sleep 1' under 'chrt' which changes the
+differently than we did with the previous tracers. Instead of performing
+an 'ls', we will run 'sleep 1' under 'chrt' which changes the
 priority of the task.
 
  # echo wakeup > /debug/tracing/current_tracer
@@ -924,9 +929,9 @@ wakeup latency trace v1.1.5 on 2.6.26-rc8
 vim:ft=help
 
 
-Running this on an idle system we see that it only took 4 microseconds
+Running this on an idle system, we see that it only took 4 microseconds
 to perform the task switch.  Note, since the trace marker in the
-schedule is before the actual "switch" we stop the tracing when
+schedule is before the actual "switch", we stop the tracing when
 the recorded task is about to schedule in. This may change if
 we add a new marker at the end of the scheduler.
 
@@ -992,12 +997,15 @@ ksoftirq-7     1d..4   50us : schedule (__cond_resched)
 
 The interrupt went off while running ksoftirqd. This task runs at
 SCHED_OTHER. Why didn't we see the 'N' set early? This may be
-a harmless bug with x86_32 and 4K stacks. The need_reched() function
-that tests if we need to reschedule looks on the actual stack.
-Where as the setting of the NEED_RESCHED bit happens on the
-task's stack. But because we are in a hard interrupt, the test
-is with the interrupts stack which has that to be false. We don't
-see the 'N' until we switch back to the task's stack.
+a harmless bug with x86_32 and 4K stacks. On x86_32 with 4K stacks
+configured, the interrupt and softirq runs with their own stack.
+Some information is held on the top of the task's stack (need_resched
+and preempt_count are both stored there). The setting of the NEED_RESCHED
+bit is done directly to the task's stack, but the reading of the
+NEED_RESCHED is done by looking at the current stack, which in this case
+is the stack for the hard interrupt. This hides the fact that NEED_RESCHED
+has been set. We don't see the 'N' until we switch back to the task's
+assigned stack.
 
 ftrace
 ------
@@ -1067,10 +1075,10 @@ this works is the mcount function call (placed at the start of
 every kernel function, produced by the -pg switch in gcc), starts
 of pointing to a simple return.
 
-When dynamic ftrace is initialized, it calls kstop_machine to make it
-act like a uniprocessor so that it can freely modify code without
-worrying about other processors executing that same code.  At
-initialization, the mcount calls are change to call a "record_ip"
+When dynamic ftrace is initialized, it calls kstop_machine to make
+the machine act like a uniprocessor so that it can freely modify code
+without worrying about other processors executing that same code.  At
+initialization, the mcount calls are changed to call a "record_ip"
 function.  After this, the first time a kernel function is called,
 it has the calling address saved in a hash table.
 
@@ -1085,8 +1093,8 @@ traced, is that we can now selectively choose which functions we
 want to trace and which ones we want the mcount calls to remain as
 nops.
 
-Two files that contain to the enabling and disabling of recorded
-functions are:
+Two files are used, one for enabling and one for disabling the tracing
+of recorded functions. They are:
 
   set_ftrace_filter
 
@@ -1094,7 +1102,7 @@ and
 
   set_ftrace_notrace
 
-A list of available functions that you can add to this files is listed
+A list of available functions that you can add to these files is listed
 in:
 
    available_filter_functions
@@ -1133,9 +1141,9 @@ sys_nanosleep
 
 
 Perhaps this isn't enough. The filters also allow simple wild cards.
-Only the following is currently available
+Only the following are currently available
 
-  <match>*  - will match functions that begins with <match>
+  <match>*  - will match functions that begin with <match>
   *<match>  - will match functions that end with <match>
   *<match>* - will match functions that have <match> in it
 
@@ -1187,7 +1195,7 @@ This is because the '>' and '>>' act just like they do in bash.
 To rewrite the filters, use '>'
 To append to the filters, use '>>'
 
-To clear out a filter so that all functions will be recorded again.
+To clear out a filter so that all functions will be recorded again:
 
  # echo > /debug/tracing/set_ftrace_filter
  # cat /debug/tracing/set_ftrace_filter
@@ -1246,8 +1254,8 @@ ftraced
 
 As mentioned above, when dynamic ftrace is configured in, a kernel
 thread wakes up once a second and checks to see if there are mcount
-calls that need to be converted into nops. If there is not, then
-it simply goes back to sleep. But if there is, it will call
+calls that need to be converted into nops. If there are not any, then
+it simply goes back to sleep. But if there are some, it will call
 kstop_machine to convert the calls to nops.
 
 There may be a case that you do not want this added latency.
@@ -1262,8 +1270,8 @@ mcount calls to nops. Remember that there's a large overhead
 to calling mcount. Without this kernel thread, that overhead will
 exist.
 
-Any write to the ftraced_enabled file will cause the kstop_machine
-to run if there are recorded calls to mcount. This means that a
+If there are recorded calls to mcount, any write to the ftraced_enabled
+file will cause the kstop_machine to run. This means that a
 user can manually perform the updates when they want to by simply
 echoing a '0' into the ftraced_enabled file.
 
@@ -1315,7 +1323,7 @@ trace entries
 
 Having too much or not enough data can be troublesome in diagnosing
 some issue in the kernel. The file trace_entries is used to modify
-the size of the internal trace buffers. The numbers listed
+the size of the internal trace buffers. The number listed
 is the number of entries that can be recorded per CPU. To know
 the full size, multiply the number of possible CPUS with the
 number of entries.
@@ -1323,7 +1331,7 @@ number of entries.
  # cat /debug/tracing/trace_entries
 65620
 
-Note, to modify this you must have tracing fulling disabled. To do that,
+Note, to modify this, you must have tracing completely disabled. To do that,
 echo "none" into the current_tracer.
 
  # echo none > /debug/tracing/current_tracer
@@ -1344,7 +1352,7 @@ it will add them.
 This shows us that 85 entries can fit on a single page.
 
 The number of pages that will be allocated is a percentage of available
-memory. Allocating too much will produces an error.
+memory. Allocating too much will produce an error.
 
  # echo 1000000000000 > /debug/tracing/trace_entries
 -bash: echo: write error: Cannot allocate memory
diff --git a/Documentation/i386/IO-APIC.txt b/Documentation/i386/IO-APIC.txt
deleted file mode 100644 (file)
index 30b4c71..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-Most (all) Intel-MP compliant SMP boards have the so-called 'IO-APIC',
-which is an enhanced interrupt controller. It enables us to route
-hardware interrupts to multiple CPUs, or to CPU groups. Without an
-IO-APIC, interrupts from hardware will be delivered only to the
-CPU which boots the operating system (usually CPU#0).
-
-Linux supports all variants of compliant SMP boards, including ones with
-multiple IO-APICs. Multiple IO-APICs are used in high-end servers to
-distribute IRQ load further.
-
-There are (a few) known breakages in certain older boards, such bugs are
-usually worked around by the kernel. If your MP-compliant SMP board does
-not boot Linux, then consult the linux-smp mailing list archives first.
-
-If your box boots fine with enabled IO-APIC IRQs, then your
-/proc/interrupts will look like this one:
-
-   ---------------------------->
-  hell:~> cat /proc/interrupts
-             CPU0
-    0:    1360293    IO-APIC-edge  timer
-    1:          4    IO-APIC-edge  keyboard
-    2:          0          XT-PIC  cascade
-   13:          1          XT-PIC  fpu
-   14:       1448    IO-APIC-edge  ide0
-   16:      28232   IO-APIC-level  Intel EtherExpress Pro 10/100 Ethernet
-   17:      51304   IO-APIC-level  eth0
-  NMI:          0
-  ERR:          0
-  hell:~>
-  <----------------------------
-
-Some interrupts are still listed as 'XT PIC', but this is not a problem;
-none of those IRQ sources is performance-critical.
-
-
-In the unlikely case that your board does not create a working mp-table,
-you can use the pirq= boot parameter to 'hand-construct' IRQ entries. This
-is non-trivial though and cannot be automated. One sample /etc/lilo.conf
-entry:
-
-       append="pirq=15,11,10"
-
-The actual numbers depend on your system, on your PCI cards and on their
-PCI slot position. Usually PCI slots are 'daisy chained' before they are
-connected to the PCI chipset IRQ routing facility (the incoming PIRQ1-4
-lines):
-
-               ,-.        ,-.        ,-.        ,-.        ,-.
-     PIRQ4 ----| |-.    ,-| |-.    ,-| |-.    ,-| |--------| |
-               |S|  \  /  |S|  \  /  |S|  \  /  |S|        |S|
-     PIRQ3 ----|l|-. `/---|l|-. `/---|l|-. `/---|l|--------|l|
-               |o|  \/    |o|  \/    |o|  \/    |o|        |o|
-     PIRQ2 ----|t|-./`----|t|-./`----|t|-./`----|t|--------|t|
-               |1| /\     |2| /\     |3| /\     |4|        |5|
-     PIRQ1 ----| |-  `----| |-  `----| |-  `----| |--------| |
-               `-'        `-'        `-'        `-'        `-'
-
-Every PCI card emits a PCI IRQ, which can be INTA, INTB, INTC or INTD:
-
-                               ,-.
-                         INTD--| |
-                               |S|
-                         INTC--|l|
-                               |o|
-                         INTB--|t|
-                               |x|
-                         INTA--| |
-                               `-'
-
-These INTA-D PCI IRQs are always 'local to the card', their real meaning
-depends on which slot they are in. If you look at the daisy chaining diagram,
-a card in slot4, issuing INTA IRQ, it will end up as a signal on PIRQ4 of
-the PCI chipset. Most cards issue INTA, this creates optimal distribution
-between the PIRQ lines. (distributing IRQ sources properly is not a
-necessity, PCI IRQs can be shared at will, but it's a good for performance
-to have non shared interrupts). Slot5 should be used for videocards, they
-do not use interrupts normally, thus they are not daisy chained either.
-
-so if you have your SCSI card (IRQ11) in Slot1, Tulip card (IRQ9) in
-Slot2, then you'll have to specify this pirq= line:
-
-       append="pirq=11,9"
-
-the following script tries to figure out such a default pirq= line from
-your PCI configuration:
-
-       echo -n pirq=; echo `scanpci | grep T_L | cut -c56-` | sed 's/ /,/g'
-
-note that this script wont work if you have skipped a few slots or if your
-board does not do default daisy-chaining. (or the IO-APIC has the PIRQ pins
-connected in some strange way). E.g. if in the above case you have your SCSI
-card (IRQ11) in Slot3, and have Slot1 empty:
-
-       append="pirq=0,9,11"
-
-[value '0' is a generic 'placeholder', reserved for empty (or non-IRQ emitting)
-slots.]
-
-Generally, it's always possible to find out the correct pirq= settings, just
-permute all IRQ numbers properly ... it will take some time though. An
-'incorrect' pirq line will cause the booting process to hang, or a device
-won't function properly (e.g. if it's inserted as a module).
-
-If you have 2 PCI buses, then you can use up to 8 pirq values, although such
-boards tend to have a good configuration.
-
-Be prepared that it might happen that you need some strange pirq line:
-
-       append="pirq=0,0,0,0,0,0,9,11"
-
-Use smart trial-and-error techniques to find out the correct pirq line ...
-
-Good luck and mail to linux-smp@vger.kernel.org or
-linux-kernel@vger.kernel.org if you have any problems that are not covered
-by this document.
-
--- mingo
-
diff --git a/Documentation/i386/boot.txt b/Documentation/i386/boot.txt
deleted file mode 100644 (file)
index 95ad15c..0000000
+++ /dev/null
@@ -1,887 +0,0 @@
-                    THE LINUX/I386 BOOT PROTOCOL
-                    ----------------------------
-
-                   H. Peter Anvin <hpa@zytor.com>
-                       Last update 2007-05-23
-
-On the i386 platform, the Linux kernel uses a rather complicated boot
-convention.  This has evolved partially due to historical aspects, as
-well as the desire in the early days to have the kernel itself be a
-bootable image, the complicated PC memory model and due to changed
-expectations in the PC industry caused by the effective demise of
-real-mode DOS as a mainstream operating system.
-
-Currently, the following versions of the Linux/i386 boot protocol exist.
-
-Old kernels:   zImage/Image support only.  Some very early kernels
-               may not even support a command line.
-
-Protocol 2.00: (Kernel 1.3.73) Added bzImage and initrd support, as
-               well as a formalized way to communicate between the
-               boot loader and the kernel.  setup.S made relocatable,
-               although the traditional setup area still assumed
-               writable.
-
-Protocol 2.01: (Kernel 1.3.76) Added a heap overrun warning.
-
-Protocol 2.02: (Kernel 2.4.0-test3-pre3) New command line protocol.
-               Lower the conventional memory ceiling.  No overwrite
-               of the traditional setup area, thus making booting
-               safe for systems which use the EBDA from SMM or 32-bit
-               BIOS entry points.  zImage deprecated but still
-               supported.
-
-Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly makes the highest possible
-               initrd address available to the bootloader.
-
-Protocol 2.04: (Kernel 2.6.14) Extend the syssize field to four bytes.
-
-Protocol 2.05: (Kernel 2.6.20) Make protected mode kernel relocatable.
-               Introduce relocatable_kernel and kernel_alignment fields.
-
-Protocol 2.06: (Kernel 2.6.22) Added a field that contains the size of
-               the boot command line.
-
-Protocol 2.07: (Kernel 2.6.24) Added paravirtualised boot protocol.
-               Introduced hardware_subarch and hardware_subarch_data
-               and KEEP_SEGMENTS flag in load_flags.
-
-Protocol 2.08: (Kernel 2.6.26) Added crc32 checksum and ELF format
-               payload. Introduced payload_offset and payload length
-               fields to aid in locating the payload.
-
-Protocol 2.09: (Kernel 2.6.26) Added a field of 64-bit physical
-               pointer to single linked list of struct setup_data.
-
-**** MEMORY LAYOUT
-
-The traditional memory map for the kernel loader, used for Image or
-zImage kernels, typically looks like:
-
-       |                        |
-0A0000 +------------------------+
-       |  Reserved for BIOS     |      Do not use.  Reserved for BIOS EBDA.
-09A000 +------------------------+
-       |  Command line          |
-       |  Stack/heap            |      For use by the kernel real-mode code.
-098000 +------------------------+      
-       |  Kernel setup          |      The kernel real-mode code.
-090200 +------------------------+
-       |  Kernel boot sector    |      The kernel legacy boot sector.
-090000 +------------------------+
-       |  Protected-mode kernel |      The bulk of the kernel image.
-010000 +------------------------+
-       |  Boot loader           |      <- Boot sector entry point 0000:7C00
-001000 +------------------------+
-       |  Reserved for MBR/BIOS |
-000800 +------------------------+
-       |  Typically used by MBR |
-000600 +------------------------+ 
-       |  BIOS use only         |
-000000 +------------------------+
-
-
-When using bzImage, the protected-mode kernel was relocated to
-0x100000 ("high memory"), and the kernel real-mode block (boot sector,
-setup, and stack/heap) was made relocatable to any address between
-0x10000 and end of low memory. Unfortunately, in protocols 2.00 and
-2.01 the 0x90000+ memory range is still used internally by the kernel;
-the 2.02 protocol resolves that problem.
-
-It is desirable to keep the "memory ceiling" -- the highest point in
-low memory touched by the boot loader -- as low as possible, since
-some newer BIOSes have begun to allocate some rather large amounts of
-memory, called the Extended BIOS Data Area, near the top of low
-memory.         The boot loader should use the "INT 12h" BIOS call to verify
-how much low memory is available.
-
-Unfortunately, if INT 12h reports that the amount of memory is too
-low, there is usually nothing the boot loader can do but to report an
-error to the user.  The boot loader should therefore be designed to
-take up as little space in low memory as it reasonably can.  For
-zImage or old bzImage kernels, which need data written into the
-0x90000 segment, the boot loader should make sure not to use memory
-above the 0x9A000 point; too many BIOSes will break above that point.
-
-For a modern bzImage kernel with boot protocol version >= 2.02, a
-memory layout like the following is suggested:
-
-       ~                        ~
-        |  Protected-mode kernel |
-100000  +------------------------+
-       |  I/O memory hole       |
-0A0000 +------------------------+
-       |  Reserved for BIOS     |      Leave as much as possible unused
-       ~                        ~
-       |  Command line          |      (Can also be below the X+10000 mark)
-X+10000        +------------------------+
-       |  Stack/heap            |      For use by the kernel real-mode code.
-X+08000        +------------------------+      
-       |  Kernel setup          |      The kernel real-mode code.
-       |  Kernel boot sector    |      The kernel legacy boot sector.
-X       +------------------------+
-       |  Boot loader           |      <- Boot sector entry point 0000:7C00
-001000 +------------------------+
-       |  Reserved for MBR/BIOS |
-000800 +------------------------+
-       |  Typically used by MBR |
-000600 +------------------------+ 
-       |  BIOS use only         |
-000000 +------------------------+
-
-... where the address X is as low as the design of the boot loader
-permits.
-
-
-**** THE REAL-MODE KERNEL HEADER
-
-In the following text, and anywhere in the kernel boot sequence, "a
-sector" refers to 512 bytes.  It is independent of the actual sector
-size of the underlying medium.
-
-The first step in loading a Linux kernel should be to load the
-real-mode code (boot sector and setup code) and then examine the
-following header at offset 0x01f1.  The real-mode code can total up to
-32K, although the boot loader may choose to load only the first two
-sectors (1K) and then examine the bootup sector size.
-
-The header looks like:
-
-Offset Proto   Name            Meaning
-/Size
-
-01F1/1 ALL(1   setup_sects     The size of the setup in sectors
-01F2/2 ALL     root_flags      If set, the root is mounted readonly
-01F4/4 2.04+(2 syssize         The size of the 32-bit code in 16-byte paras
-01F8/2 ALL     ram_size        DO NOT USE - for bootsect.S use only
-01FA/2 ALL     vid_mode        Video mode control
-01FC/2 ALL     root_dev        Default root device number
-01FE/2 ALL     boot_flag       0xAA55 magic number
-0200/2 2.00+   jump            Jump instruction
-0202/4 2.00+   header          Magic signature "HdrS"
-0206/2 2.00+   version         Boot protocol version supported
-0208/4 2.00+   realmode_swtch  Boot loader hook (see below)
-020C/2 2.00+   start_sys       The load-low segment (0x1000) (obsolete)
-020E/2 2.00+   kernel_version  Pointer to kernel version string
-0210/1 2.00+   type_of_loader  Boot loader identifier
-0211/1 2.00+   loadflags       Boot protocol option flags
-0212/2 2.00+   setup_move_size Move to high memory size (used with hooks)
-0214/4 2.00+   code32_start    Boot loader hook (see below)
-0218/4 2.00+   ramdisk_image   initrd load address (set by boot loader)
-021C/4 2.00+   ramdisk_size    initrd size (set by boot loader)
-0220/4 2.00+   bootsect_kludge DO NOT USE - for bootsect.S use only
-0224/2 2.01+   heap_end_ptr    Free memory after setup end
-0226/2 N/A     pad1            Unused
-0228/4 2.02+   cmd_line_ptr    32-bit pointer to the kernel command line
-022C/4 2.03+   initrd_addr_max Highest legal initrd address
-0230/4 2.05+   kernel_alignment Physical addr alignment required for kernel
-0234/1 2.05+   relocatable_kernel Whether kernel is relocatable or not
-0235/3 N/A     pad2            Unused
-0238/4 2.06+   cmdline_size    Maximum size of the kernel command line
-023C/4 2.07+   hardware_subarch Hardware subarchitecture
-0240/8 2.07+   hardware_subarch_data Subarchitecture-specific data
-0248/4 2.08+   payload_offset  Offset of kernel payload
-024C/4 2.08+   payload_length  Length of kernel payload
-0250/8 2.09+   setup_data      64-bit physical pointer to linked list
-                               of struct setup_data
-
-(1) For backwards compatibility, if the setup_sects field contains 0, the
-    real value is 4.
-
-(2) For boot protocol prior to 2.04, the upper two bytes of the syssize
-    field are unusable, which means the size of a bzImage kernel
-    cannot be determined.
-
-If the "HdrS" (0x53726448) magic number is not found at offset 0x202,
-the boot protocol version is "old".  Loading an old kernel, the
-following parameters should be assumed:
-
-       Image type = zImage
-       initrd not supported
-       Real-mode kernel must be located at 0x90000.
-
-Otherwise, the "version" field contains the protocol version,
-e.g. protocol version 2.01 will contain 0x0201 in this field.  When
-setting fields in the header, you must make sure only to set fields
-supported by the protocol version in use.
-
-
-**** DETAILS OF HEADER FIELDS
-
-For each field, some are information from the kernel to the bootloader
-("read"), some are expected to be filled out by the bootloader
-("write"), and some are expected to be read and modified by the
-bootloader ("modify").
-
-All general purpose boot loaders should write the fields marked
-(obligatory).  Boot loaders who want to load the kernel at a
-nonstandard address should fill in the fields marked (reloc); other
-boot loaders can ignore those fields.
-
-The byte order of all fields is littleendian (this is x86, after all.)
-
-Field name:    setup_sects
-Type:          read
-Offset/size:   0x1f1/1
-Protocol:      ALL
-
-  The size of the setup code in 512-byte sectors.  If this field is
-  0, the real value is 4.  The real-mode code consists of the boot
-  sector (always one 512-byte sector) plus the setup code.
-
-Field name:     root_flags
-Type:           modify (optional)
-Offset/size:    0x1f2/2
-Protocol:       ALL
-
-  If this field is nonzero, the root defaults to readonly.  The use of
-  this field is deprecated; use the "ro" or "rw" options on the
-  command line instead.
-
-Field name:    syssize
-Type:          read
-Offset/size:   0x1f4/4 (protocol 2.04+) 0x1f4/2 (protocol ALL)
-Protocol:      2.04+
-
-  The size of the protected-mode code in units of 16-byte paragraphs.
-  For protocol versions older than 2.04 this field is only two bytes
-  wide, and therefore cannot be trusted for the size of a kernel if
-  the LOAD_HIGH flag is set.
-
-Field name:    ram_size
-Type:          kernel internal
-Offset/size:   0x1f8/2
-Protocol:      ALL
-
-  This field is obsolete.
-
-Field name:    vid_mode
-Type:          modify (obligatory)
-Offset/size:   0x1fa/2
-
-  Please see the section on SPECIAL COMMAND LINE OPTIONS.
-
-Field name:    root_dev
-Type:          modify (optional)
-Offset/size:   0x1fc/2
-Protocol:      ALL
-
-  The default root device device number.  The use of this field is
-  deprecated, use the "root=" option on the command line instead.
-
-Field name:    boot_flag
-Type:          read
-Offset/size:   0x1fe/2
-Protocol:      ALL
-
-  Contains 0xAA55.  This is the closest thing old Linux kernels have
-  to a magic number.
-
-Field name:    jump
-Type:          read
-Offset/size:   0x200/2
-Protocol:      2.00+
-
-  Contains an x86 jump instruction, 0xEB followed by a signed offset
-  relative to byte 0x202.  This can be used to determine the size of
-  the header.
-
-Field name:    header
-Type:          read
-Offset/size:   0x202/4
-Protocol:      2.00+
-
-  Contains the magic number "HdrS" (0x53726448).
-
-Field name:    version
-Type:          read
-Offset/size:   0x206/2
-Protocol:      2.00+
-
-  Contains the boot protocol version, in (major << 8)+minor format,
-  e.g. 0x0204 for version 2.04, and 0x0a11 for a hypothetical version
-  10.17.
-
-Field name:    readmode_swtch
-Type:          modify (optional)
-Offset/size:   0x208/4
-Protocol:      2.00+
-
-  Boot loader hook (see ADVANCED BOOT LOADER HOOKS below.)
-
-Field name:    start_sys
-Type:          read
-Offset/size:   0x20c/4
-Protocol:      2.00+
-
-  The load low segment (0x1000).  Obsolete.
-
-Field name:    kernel_version
-Type:          read
-Offset/size:   0x20e/2
-Protocol:      2.00+
-
-  If set to a nonzero value, contains a pointer to a NUL-terminated
-  human-readable kernel version number string, less 0x200.  This can
-  be used to display the kernel version to the user.  This value
-  should be less than (0x200*setup_sects).
-
-  For example, if this value is set to 0x1c00, the kernel version
-  number string can be found at offset 0x1e00 in the kernel file.
-  This is a valid value if and only if the "setup_sects" field
-  contains the value 15 or higher, as:
-
-       0x1c00  < 15*0x200 (= 0x1e00) but
-       0x1c00 >= 14*0x200 (= 0x1c00)
-
-       0x1c00 >> 9 = 14, so the minimum value for setup_secs is 15.
-
-Field name:    type_of_loader
-Type:          write (obligatory)
-Offset/size:   0x210/1
-Protocol:      2.00+
-
-  If your boot loader has an assigned id (see table below), enter
-  0xTV here, where T is an identifier for the boot loader and V is
-  a version number.  Otherwise, enter 0xFF here.
-
-  Assigned boot loader ids:
-       0  LILO                 (0x00 reserved for pre-2.00 bootloader)
-       1  Loadlin
-       2  bootsect-loader      (0x20, all other values reserved)
-       3  SYSLINUX
-       4  EtherBoot
-       5  ELILO
-       7  GRuB
-       8  U-BOOT
-       9  Xen
-       A  Gujin
-       B  Qemu
-
-  Please contact <hpa@zytor.com> if you need a bootloader ID
-  value assigned.
-
-Field name:    loadflags
-Type:          modify (obligatory)
-Offset/size:   0x211/1
-Protocol:      2.00+
-
-  This field is a bitmask.
-
-  Bit 0 (read):        LOADED_HIGH
-       - If 0, the protected-mode code is loaded at 0x10000.
-       - If 1, the protected-mode code is loaded at 0x100000.
-
-  Bit 6 (write): KEEP_SEGMENTS
-       Protocol: 2.07+
-       - if 0, reload the segment registers in the 32bit entry point.
-       - if 1, do not reload the segment registers in the 32bit entry point.
-               Assume that %cs %ds %ss %es are all set to flat segments with
-               a base of 0 (or the equivalent for their environment).
-
-  Bit 7 (write): CAN_USE_HEAP
-       Set this bit to 1 to indicate that the value entered in the
-       heap_end_ptr is valid.  If this field is clear, some setup code
-       functionality will be disabled.
-
-Field name:    setup_move_size
-Type:          modify (obligatory)
-Offset/size:   0x212/2
-Protocol:      2.00-2.01
-
-  When using protocol 2.00 or 2.01, if the real mode kernel is not
-  loaded at 0x90000, it gets moved there later in the loading
-  sequence.  Fill in this field if you want additional data (such as
-  the kernel command line) moved in addition to the real-mode kernel
-  itself.
-
-  The unit is bytes starting with the beginning of the boot sector.
-  
-  This field is can be ignored when the protocol is 2.02 or higher, or
-  if the real-mode code is loaded at 0x90000.
-
-Field name:    code32_start
-Type:          modify (optional, reloc)
-Offset/size:   0x214/4
-Protocol:      2.00+
-
-  The address to jump to in protected mode.  This defaults to the load
-  address of the kernel, and can be used by the boot loader to
-  determine the proper load address.
-
-  This field can be modified for two purposes:
-
-  1. as a boot loader hook (see ADVANCED BOOT LOADER HOOKS below.)
-
-  2. if a bootloader which does not install a hook loads a
-     relocatable kernel at a nonstandard address it will have to modify
-     this field to point to the load address.
-
-Field name:    ramdisk_image
-Type:          write (obligatory)
-Offset/size:   0x218/4
-Protocol:      2.00+
-
-  The 32-bit linear address of the initial ramdisk or ramfs.  Leave at
-  zero if there is no initial ramdisk/ramfs.
-
-Field name:    ramdisk_size
-Type:          write (obligatory)
-Offset/size:   0x21c/4
-Protocol:      2.00+
-
-  Size of the initial ramdisk or ramfs.  Leave at zero if there is no
-  initial ramdisk/ramfs.
-
-Field name:    bootsect_kludge
-Type:          kernel internal
-Offset/size:   0x220/4
-Protocol:      2.00+
-
-  This field is obsolete.
-
-Field name:    heap_end_ptr
-Type:          write (obligatory)
-Offset/size:   0x224/2
-Protocol:      2.01+
-
-  Set this field to the offset (from the beginning of the real-mode
-  code) of the end of the setup stack/heap, minus 0x0200.
-
-Field name:    cmd_line_ptr
-Type:          write (obligatory)
-Offset/size:   0x228/4
-Protocol:      2.02+
-
-  Set this field to the linear address of the kernel command line.
-  The kernel command line can be located anywhere between the end of
-  the setup heap and 0xA0000; it does not have to be located in the
-  same 64K segment as the real-mode code itself.
-
-  Fill in this field even if your boot loader does not support a
-  command line, in which case you can point this to an empty string
-  (or better yet, to the string "auto".)  If this field is left at
-  zero, the kernel will assume that your boot loader does not support
-  the 2.02+ protocol.
-
-Field name:    initrd_addr_max
-Type:          read
-Offset/size:   0x22c/4
-Protocol:      2.03+
-
-  The maximum address that may be occupied by the initial
-  ramdisk/ramfs contents.  For boot protocols 2.02 or earlier, this
-  field is not present, and the maximum address is 0x37FFFFFF.  (This
-  address is defined as the address of the highest safe byte, so if
-  your ramdisk is exactly 131072 bytes long and this field is
-  0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
-
-Field name:    kernel_alignment
-Type:          read (reloc)
-Offset/size:   0x230/4
-Protocol:      2.05+
-
-  Alignment unit required by the kernel (if relocatable_kernel is true.)
-
-Field name:    relocatable_kernel
-Type:          read (reloc)
-Offset/size:   0x234/1
-Protocol:      2.05+
-
-  If this field is nonzero, the protected-mode part of the kernel can
-  be loaded at any address that satisfies the kernel_alignment field.
-  After loading, the boot loader must set the code32_start field to
-  point to the loaded code, or to a boot loader hook.
-
-Field name:    cmdline_size
-Type:          read
-Offset/size:   0x238/4
-Protocol:      2.06+
-
-  The maximum size of the command line without the terminating
-  zero. This means that the command line can contain at most
-  cmdline_size characters. With protocol version 2.05 and earlier, the
-  maximum size was 255.
-
-Field name:    hardware_subarch
-Type:          write
-Offset/size:   0x23c/4
-Protocol:      2.07+
-
-  In a paravirtualized environment the hardware low level architectural
-  pieces such as interrupt handling, page table handling, and
-  accessing process control registers needs to be done differently.
-
-  This field allows the bootloader to inform the kernel we are in one
-  one of those environments.
-
-  0x00000000   The default x86/PC environment
-  0x00000001   lguest
-  0x00000002   Xen
-
-Field name:    hardware_subarch_data
-Type:          write
-Offset/size:   0x240/8
-Protocol:      2.07+
-
-  A pointer to data that is specific to hardware subarch
-
-Field name:    payload_offset
-Type:          read
-Offset/size:   0x248/4
-Protocol:      2.08+
-
-  If non-zero then this field contains the offset from the end of the
-  real-mode code to the payload.
-
-  The payload may be compressed. The format of both the compressed and
-  uncompressed data should be determined using the standard magic
-  numbers. Currently only gzip compressed ELF is used.
-  
-Field name:    payload_length
-Type:          read
-Offset/size:   0x24c/4
-Protocol:      2.08+
-
-  The length of the payload.
-
-**** THE IMAGE CHECKSUM
-
-From boot protocol version 2.08 onwards the CRC-32 is calculated over
-the entire file using the characteristic polynomial 0x04C11DB7 and an
-initial remainder of 0xffffffff.  The checksum is appended to the
-file; therefore the CRC of the file up to the limit specified in the
-syssize field of the header is always 0.
-
-**** THE KERNEL COMMAND LINE
-
-The kernel command line has become an important way for the boot
-loader to communicate with the kernel.  Some of its options are also
-relevant to the boot loader itself, see "special command line options"
-below.
-
-The kernel command line is a null-terminated string. The maximum
-length can be retrieved from the field cmdline_size.  Before protocol
-version 2.06, the maximum was 255 characters.  A string that is too
-long will be automatically truncated by the kernel.
-
-If the boot protocol version is 2.02 or later, the address of the
-kernel command line is given by the header field cmd_line_ptr (see
-above.)  This address can be anywhere between the end of the setup
-heap and 0xA0000.
-
-If the protocol version is *not* 2.02 or higher, the kernel
-command line is entered using the following protocol:
-
-       At offset 0x0020 (word), "cmd_line_magic", enter the magic
-       number 0xA33F.
-
-       At offset 0x0022 (word), "cmd_line_offset", enter the offset
-       of the kernel command line (relative to the start of the
-       real-mode kernel).
-       
-       The kernel command line *must* be within the memory region
-       covered by setup_move_size, so you may need to adjust this
-       field.
-
-Field name:    setup_data
-Type:          write (obligatory)
-Offset/size:   0x250/8
-Protocol:      2.09+
-
-  The 64-bit physical pointer to NULL terminated single linked list of
-  struct setup_data. This is used to define a more extensible boot
-  parameters passing mechanism. The definition of struct setup_data is
-  as follow:
-
-  struct setup_data {
-         u64 next;
-         u32 type;
-         u32 len;
-         u8  data[0];
-  };
-
-  Where, the next is a 64-bit physical pointer to the next node of
-  linked list, the next field of the last node is 0; the type is used
-  to identify the contents of data; the len is the length of data
-  field; the data holds the real payload.
-
-
-**** MEMORY LAYOUT OF THE REAL-MODE CODE
-
-The real-mode code requires a stack/heap to be set up, as well as
-memory allocated for the kernel command line.  This needs to be done
-in the real-mode accessible memory in bottom megabyte.
-
-It should be noted that modern machines often have a sizable Extended
-BIOS Data Area (EBDA).  As a result, it is advisable to use as little
-of the low megabyte as possible.
-
-Unfortunately, under the following circumstances the 0x90000 memory
-segment has to be used:
-
-       - When loading a zImage kernel ((loadflags & 0x01) == 0).
-       - When loading a 2.01 or earlier boot protocol kernel.
-
-         -> For the 2.00 and 2.01 boot protocols, the real-mode code
-            can be loaded at another address, but it is internally
-            relocated to 0x90000.  For the "old" protocol, the
-            real-mode code must be loaded at 0x90000.
-
-When loading at 0x90000, avoid using memory above 0x9a000.
-
-For boot protocol 2.02 or higher, the command line does not have to be
-located in the same 64K segment as the real-mode setup code; it is
-thus permitted to give the stack/heap the full 64K segment and locate
-the command line above it.
-
-The kernel command line should not be located below the real-mode
-code, nor should it be located in high memory.
-
-
-**** SAMPLE BOOT CONFIGURATION
-
-As a sample configuration, assume the following layout of the real
-mode segment:
-
-    When loading below 0x90000, use the entire segment:
-
-       0x0000-0x7fff   Real mode kernel
-       0x8000-0xdfff   Stack and heap
-       0xe000-0xffff   Kernel command line
-
-    When loading at 0x90000 OR the protocol version is 2.01 or earlier:
-
-       0x0000-0x7fff   Real mode kernel
-       0x8000-0x97ff   Stack and heap
-       0x9800-0x9fff   Kernel command line
-
-Such a boot loader should enter the following fields in the header:
-
-       unsigned long base_ptr; /* base address for real-mode segment */
-
-       if ( setup_sects == 0 ) {
-               setup_sects = 4;
-       }
-
-       if ( protocol >= 0x0200 ) {
-               type_of_loader = <type code>;
-               if ( loading_initrd ) {
-                       ramdisk_image = <initrd_address>;
-                       ramdisk_size = <initrd_size>;
-               }
-
-               if ( protocol >= 0x0202 && loadflags & 0x01 )
-                       heap_end = 0xe000;
-               else
-                       heap_end = 0x9800;
-
-               if ( protocol >= 0x0201 ) {
-                       heap_end_ptr = heap_end - 0x200;
-                       loadflags |= 0x80; /* CAN_USE_HEAP */
-               }
-
-               if ( protocol >= 0x0202 ) {
-                       cmd_line_ptr = base_ptr + heap_end;
-                       strcpy(cmd_line_ptr, cmdline);
-               } else {
-                       cmd_line_magic  = 0xA33F;
-                       cmd_line_offset = heap_end;
-                       setup_move_size = heap_end + strlen(cmdline)+1;
-                       strcpy(base_ptr+cmd_line_offset, cmdline);
-               }
-       } else {
-               /* Very old kernel */
-
-               heap_end = 0x9800;
-
-               cmd_line_magic  = 0xA33F;
-               cmd_line_offset = heap_end;
-
-               /* A very old kernel MUST have its real-mode code
-                  loaded at 0x90000 */
-
-               if ( base_ptr != 0x90000 ) {
-                       /* Copy the real-mode kernel */
-                       memcpy(0x90000, base_ptr, (setup_sects+1)*512);
-                       base_ptr = 0x90000;              /* Relocated */
-               }
-
-               strcpy(0x90000+cmd_line_offset, cmdline);
-
-               /* It is recommended to clear memory up to the 32K mark */
-               memset(0x90000 + (setup_sects+1)*512, 0,
-                      (64-(setup_sects+1))*512);
-       }
-
-
-**** LOADING THE REST OF THE KERNEL
-
-The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
-in the kernel file (again, if setup_sects == 0 the real value is 4.)
-It should be loaded at address 0x10000 for Image/zImage kernels and
-0x100000 for bzImage kernels.
-
-The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01
-bit (LOAD_HIGH) in the loadflags field is set:
-
-       is_bzImage = (protocol >= 0x0200) && (loadflags & 0x01);
-       load_address = is_bzImage ? 0x100000 : 0x10000;
-
-Note that Image/zImage kernels can be up to 512K in size, and thus use
-the entire 0x10000-0x90000 range of memory.  This means it is pretty
-much a requirement for these kernels to load the real-mode part at
-0x90000.  bzImage kernels allow much more flexibility.
-
-
-**** SPECIAL COMMAND LINE OPTIONS
-
-If the command line provided by the boot loader is entered by the
-user, the user may expect the following command line options to work.
-They should normally not be deleted from the kernel command line even
-though not all of them are actually meaningful to the kernel.  Boot
-loader authors who need additional command line options for the boot
-loader itself should get them registered in
-Documentation/kernel-parameters.txt to make sure they will not
-conflict with actual kernel options now or in the future.
-
-  vga=<mode>
-       <mode> here is either an integer (in C notation, either
-       decimal, octal, or hexadecimal) or one of the strings
-       "normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask"
-       (meaning 0xFFFD).  This value should be entered into the
-       vid_mode field, as it is used by the kernel before the command
-       line is parsed.
-
-  mem=<size>
-       <size> is an integer in C notation optionally followed by
-       (case insensitive) K, M, G, T, P or E (meaning << 10, << 20,
-       << 30, << 40, << 50 or << 60).  This specifies the end of
-       memory to the kernel. This affects the possible placement of
-       an initrd, since an initrd should be placed near end of
-       memory.  Note that this is an option to *both* the kernel and
-       the bootloader!
-
-  initrd=<file>
-       An initrd should be loaded.  The meaning of <file> is
-       obviously bootloader-dependent, and some boot loaders
-       (e.g. LILO) do not have such a command.
-
-In addition, some boot loaders add the following options to the
-user-specified command line:
-
-  BOOT_IMAGE=<file>
-       The boot image which was loaded.  Again, the meaning of <file>
-       is obviously bootloader-dependent.
-
-  auto
-       The kernel was booted without explicit user intervention.
-
-If these options are added by the boot loader, it is highly
-recommended that they are located *first*, before the user-specified
-or configuration-specified command line.  Otherwise, "init=/bin/sh"
-gets confused by the "auto" option.
-
-
-**** RUNNING THE KERNEL
-
-The kernel is started by jumping to the kernel entry point, which is
-located at *segment* offset 0x20 from the start of the real mode
-kernel.  This means that if you loaded your real-mode kernel code at
-0x90000, the kernel entry point is 9020:0000.
-
-At entry, ds = es = ss should point to the start of the real-mode
-kernel code (0x9000 if the code is loaded at 0x90000), sp should be
-set up properly, normally pointing to the top of the heap, and
-interrupts should be disabled.  Furthermore, to guard against bugs in
-the kernel, it is recommended that the boot loader sets fs = gs = ds =
-es = ss.
-
-In our example from above, we would do:
-
-       /* Note: in the case of the "old" kernel protocol, base_ptr must
-          be == 0x90000 at this point; see the previous sample code */
-
-       seg = base_ptr >> 4;
-
-       cli();  /* Enter with interrupts disabled! */
-
-       /* Set up the real-mode kernel stack */
-       _SS = seg;
-       _SP = heap_end;
-
-       _DS = _ES = _FS = _GS = seg;
-       jmp_far(seg+0x20, 0);   /* Run the kernel */
-
-If your boot sector accesses a floppy drive, it is recommended to
-switch off the floppy motor before running the kernel, since the
-kernel boot leaves interrupts off and thus the motor will not be
-switched off, especially if the loaded kernel has the floppy driver as
-a demand-loaded module!
-
-
-**** ADVANCED BOOT LOADER HOOKS
-
-If the boot loader runs in a particularly hostile environment (such as
-LOADLIN, which runs under DOS) it may be impossible to follow the
-standard memory location requirements.  Such a boot loader may use the
-following hooks that, if set, are invoked by the kernel at the
-appropriate time.  The use of these hooks should probably be
-considered an absolutely last resort!
-
-IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and
-%edi across invocation.
-
-  realmode_swtch:
-       A 16-bit real mode far subroutine invoked immediately before
-       entering protected mode.  The default routine disables NMI, so
-       your routine should probably do so, too.
-
-  code32_start:
-       A 32-bit flat-mode routine *jumped* to immediately after the
-       transition to protected mode, but before the kernel is
-       uncompressed.  No segments, except CS, are guaranteed to be
-       set up (current kernels do, but older ones do not); you should
-       set them up to BOOT_DS (0x18) yourself.
-
-       After completing your hook, you should jump to the address
-       that was in this field before your boot loader overwrote it
-       (relocated, if appropriate.)
-
-
-**** 32-bit BOOT PROTOCOL
-
-For machine with some new BIOS other than legacy BIOS, such as EFI,
-LinuxBIOS, etc, and kexec, the 16-bit real mode setup code in kernel
-based on legacy BIOS can not be used, so a 32-bit boot protocol needs
-to be defined.
-
-In 32-bit boot protocol, the first step in loading a Linux kernel
-should be to setup the boot parameters (struct boot_params,
-traditionally known as "zero page"). The memory for struct boot_params
-should be allocated and initialized to all zero. Then the setup header
-from offset 0x01f1 of kernel image on should be loaded into struct
-boot_params and examined. The end of setup header can be calculated as
-follow:
-
-       0x0202 + byte value at offset 0x0201
-
-In addition to read/modify/write the setup header of the struct
-boot_params as that of 16-bit boot protocol, the boot loader should
-also fill the additional fields of the struct boot_params as that
-described in zero-page.txt.
-
-After setupping the struct boot_params, the boot loader can load the
-32/64-bit kernel in the same way as that of 16-bit boot protocol.
-
-In 32-bit boot protocol, the kernel is started by jumping to the
-32-bit kernel entry point, which is the start address of loaded
-32/64-bit kernel.
-
-At entry, the CPU must be in 32-bit protected mode with paging
-disabled; a GDT must be loaded with the descriptors for selectors
-__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat
-segment; __BOOS_CS must have execute/read permission, and __BOOT_DS
-must have read/write permission; CS must be __BOOT_CS and DS, ES, SS
-must be __BOOT_DS; interrupt must be disabled; %esi must hold the base
-address of the struct boot_params; %ebp, %edi and %ebx must be zero.
diff --git a/Documentation/i386/usb-legacy-support.txt b/Documentation/i386/usb-legacy-support.txt
deleted file mode 100644 (file)
index 1894cdf..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-USB Legacy support
-~~~~~~~~~~~~~~~~~~
-
-Vojtech Pavlik <vojtech@suse.cz>, January 2004
-
-
-Also known as "USB Keyboard" or "USB Mouse support" in the BIOS Setup is a
-feature that allows one to use the USB mouse and keyboard as if they were
-their classic PS/2 counterparts.  This means one can use an USB keyboard to
-type in LILO for example.
-
-It has several drawbacks, though:
-
-1) On some machines, the emulated PS/2 mouse takes over even when no USB
-   mouse is present and a real PS/2 mouse is present.  In that case the extra
-   features (wheel, extra buttons, touchpad mode) of the real PS/2 mouse may
-   not be available.
-
-2) If CONFIG_HIGHMEM64G is enabled, the PS/2 mouse emulation can cause
-   system crashes, because the SMM BIOS is not expecting to be in PAE mode.
-   The Intel E7505 is a typical machine where this happens.
-
-3) If AMD64 64-bit mode is enabled, again system crashes often happen,
-   because the SMM BIOS isn't expecting the CPU to be in 64-bit mode.  The
-   BIOS manufacturers only test with Windows, and Windows doesn't do 64-bit
-   yet.
-
-Solutions:
-
-Problem 1) can be solved by loading the USB drivers prior to loading the
-PS/2 mouse driver. Since the PS/2 mouse driver is in 2.6 compiled into
-the kernel unconditionally, this means the USB drivers need to be
-compiled-in, too.
-
-Problem 2) can currently only be solved by either disabling HIGHMEM64G
-in the kernel config or USB Legacy support in the BIOS. A BIOS update
-could help, but so far no such update exists.
-
-Problem 3) is usually fixed by a BIOS update. Check the board
-manufacturers web site. If an update is not available, disable USB
-Legacy support in the BIOS. If this alone doesn't help, try also adding
-idle=poll on the kernel command line. The BIOS may be entering the SMM
-on the HLT instruction as well.
-
diff --git a/Documentation/i386/zero-page.txt b/Documentation/i386/zero-page.txt
deleted file mode 100644 (file)
index 169ad42..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-The additional fields in struct boot_params as a part of 32-bit boot
-protocol of kernel. These should be filled by bootloader or 16-bit
-real-mode setup code of the kernel. References/settings to it mainly
-are in:
-
-  include/asm-x86/bootparam.h
-
-
-Offset Proto   Name            Meaning
-/Size
-
-000/040        ALL     screen_info     Text mode or frame buffer information
-                               (struct screen_info)
-040/014        ALL     apm_bios_info   APM BIOS information (struct apm_bios_info)
-060/010        ALL     ist_info        Intel SpeedStep (IST) BIOS support information
-                               (struct ist_info)
-080/010        ALL     hd0_info        hd0 disk parameter, OBSOLETE!!
-090/010        ALL     hd1_info        hd1 disk parameter, OBSOLETE!!
-0A0/010        ALL     sys_desc_table  System description table (struct sys_desc_table)
-140/080        ALL     edid_info       Video mode setup (struct edid_info)
-1C0/020        ALL     efi_info        EFI 32 information (struct efi_info)
-1E0/004        ALL     alk_mem_k       Alternative mem check, in KB
-1E4/004        ALL     scratch         Scratch field for the kernel setup code
-1E8/001        ALL     e820_entries    Number of entries in e820_map (below)
-1E9/001        ALL     eddbuf_entries  Number of entries in eddbuf (below)
-1EA/001        ALL     edd_mbr_sig_buf_entries Number of entries in edd_mbr_sig_buffer
-                               (below)
-290/040        ALL     edd_mbr_sig_buffer EDD MBR signatures
-2D0/A00        ALL     e820_map        E820 memory map table
-                               (array of struct e820entry)
-D00/1EC        ALL     eddbuf          EDD data (array of struct edd_info)
index 240ce7a..3bb5f46 100644 (file)
@@ -117,6 +117,7 @@ Code        Seq#    Include File            Comments
                                        <mailto:natalia@nikhefk.nikhef.nl>
 'c'    00-7F   linux/comstats.h        conflict!
 'c'    00-7F   linux/coda.h            conflict!
+'c'    80-9F   asm-s390/chsc.h
 'd'    00-FF   linux/char/drm/drm/h    conflict!
 'd'    00-DF   linux/video_decoder.h   conflict!
 'd'    F0-FF   linux/digi1.h
index b8e52c0..9691c7f 100644 (file)
@@ -109,7 +109,7 @@ There are two possible methods of using Kdump.
 2) Or use the system kernel binary itself as dump-capture kernel and there is
    no need to build a separate dump-capture kernel. This is possible
    only with the architecutres which support a relocatable kernel. As
-   of today i386 and ia64 architectures support relocatable kernel.
+   of today, i386, x86_64 and ia64 architectures support relocatable kernel.
 
 Building a relocatable kernel is advantageous from the point of view that
 one does not have to build a second kernel for capturing the dump. But
index b52f47d..b3a5aad 100644 (file)
@@ -271,6 +271,17 @@ and is between 256 and 4096 characters. It is defined in the file
        aic79xx=        [HW,SCSI]
                        See Documentation/scsi/aic79xx.txt.
 
+       amd_iommu=      [HW,X86-84]
+                       Pass parameters to the AMD IOMMU driver in the system.
+                       Possible values are:
+                       isolate - enable device isolation (each device, as far
+                                 as possible, will get its own protection
+                                 domain)
+       amd_iommu_size= [HW,X86-64]
+                       Define the size of the aperture for the AMD IOMMU
+                       driver. Possible values are:
+                       '32M', '64M' (default), '128M', '256M', '512M', '1G'
+
        amijoy.map=     [HW,JOY] Amiga joystick support
                        Map of devices attached to JOY0DAT and JOY1DAT
                        Format: <a>,<b>
@@ -599,6 +610,29 @@ and is between 256 and 4096 characters. It is defined in the file
                        See drivers/char/README.epca and
                        Documentation/digiepca.txt.
 
+       disable_mtrr_cleanup [X86]
+       enable_mtrr_cleanup [X86]
+                       The kernel tries to adjust MTRR layout from continuous
+                       to discrete, to make X server driver able to add WB
+                       entry later. This parameter enables/disables that.
+
+       mtrr_chunk_size=nn[KMG] [X86]
+                       used for mtrr cleanup. It is largest continous chunk
+                       that could hold holes aka. UC entries.
+
+       mtrr_gran_size=nn[KMG] [X86]
+                       Used for mtrr cleanup. It is granularity of mtrr block.
+                       Default is 1.
+                       Large value could prevent small alignment from
+                       using up MTRRs.
+
+       mtrr_spare_reg_nr=n [X86]
+                       Format: <integer>
+                       Range: 0,7 : spare reg number
+                       Default : 1
+                       Used for mtrr cleanup. It is spare mtrr entries number.
+                       Set to 2 or more if your graphical card needs more.
+
        disable_mtrr_trim [X86, Intel and AMD only]
                        By default the kernel will trim any uncacheable
                        memory out of your available memory pool based on
@@ -1208,6 +1242,11 @@ and is between 256 and 4096 characters. It is defined in the file
        mtdparts=       [MTD]
                        See drivers/mtd/cmdlinepart.c.
 
+       mtdset=         [ARM]
+                       ARM/S3C2412 JIVE boot control
+
+                       See arch/arm/mach-s3c2412/mach-jive.c
+
        mtouchusb.raw_coordinates=
                        [HW] Make the MicroTouch USB driver use raw coordinates
                        ('y', default) or cooked coordinates ('n')
@@ -2116,6 +2155,9 @@ and is between 256 and 4096 characters. It is defined in the file
        usbhid.mousepoll=
                        [USBHID] The interval which mice are to be polled at.
 
+       add_efi_memmap  [EFI; x86-32,X86-64] Include EFI memory map in
+                       kernel's map of available physical RAM.
+
        vdso=           [X86-32,SH,x86-64]
                        vdso=2: enable compat VDSO (default with COMPAT_VDSO)
                        vdso=1: enable VDSO (default)
index 757c729..90aa453 100644 (file)
@@ -10,7 +10,7 @@ us to generate 'watchdog NMI interrupts'.  (NMI: Non Maskable Interrupt
 which get executed even if the system is otherwise locked up hard).
 This can be used to debug hard kernel lockups.  By executing periodic
 NMI interrupts, the kernel can monitor whether any CPU has locked up,
-and print out debugging messages if so.  
+and print out debugging messages if so.
 
 In order to use the NMI watchdog, you need to have APIC support in your
 kernel. For SMP kernels, APIC support gets compiled in automatically. For
@@ -22,8 +22,7 @@ CONFIG_X86_UP_IOAPIC is for uniprocessor with an IO-APIC. [Note: certain
 kernel debugging options, such as Kernel Stack Meter or Kernel Tracer,
 may implicitly disable the NMI watchdog.]
 
-For x86-64, the needed APIC is always compiled in, and the NMI watchdog is
-always enabled with I/O-APIC mode (nmi_watchdog=1).
+For x86-64, the needed APIC is always compiled in.
 
 Using local APIC (nmi_watchdog=2) needs the first performance register, so
 you can't use it for other purposes (such as high precision performance
@@ -63,16 +62,15 @@ when the system is idle), but if your system locks up on anything but the
 "hlt", then you are out of luck -- the event will not happen at all and the
 watchdog won't trigger. This is a shortcoming of the local APIC watchdog
 -- unfortunately there is no "clock ticks" event that would work all the
-time. The I/O APIC watchdog is driven externally and has no such shortcoming.  
+time. The I/O APIC watchdog is driven externally and has no such shortcoming.
 But its NMI frequency is much higher, resulting in a more significant hit
 to the overall system performance.
 
-NOTE: starting with 2.4.2-ac18 the NMI-oopser is disabled by default,
-you have to enable it with a boot time parameter.  Prior to 2.4.2-ac18
-the NMI-oopser is enabled unconditionally on x86 SMP boxes.
+On x86 nmi_watchdog is disabled by default so you have to enable it with
+a boot time parameter.
 
-On x86-64 the NMI oopser is on by default. On 64bit Intel CPUs
-it uses IO-APIC by default and on AMD it uses local APIC.
+NOTE: In kernels prior to 2.4.2-ac18 the NMI-oopser is enabled unconditionally
+on x86 SMP boxes.
 
 [ feel free to send bug reports, suggestions and patches to
   Ingo Molnar <mingo@redhat.com> or the Linux SMP mailing
index a9e990a..373ceac 100644 (file)
@@ -61,10 +61,7 @@ builder by #define'ing ARCH_HASH_SCHED_DOMAIN, and exporting your
 arch_init_sched_domains function. This function will attach domains to all
 CPUs using cpu_attach_domain.
 
-Implementors should change the line
-#undef SCHED_DOMAIN_DEBUG
-to
-#define SCHED_DOMAIN_DEBUG
-in kernel/sched.c as this enables an error checking parse of the sched domains
+The sched-domains debugging infrastructure can be enabled by enabling
+CONFIG_SCHED_DEBUG. This enables an error checking parse of the sched domains
 which should catch most possible errors (described above). It also prints out
 the domain structure in a visual format.
index 14f901f..3ef339f 100644 (file)
@@ -51,9 +51,9 @@ needs only about 3% CPU time to do so, it can do with a 0.03 * 0.005s =
 0.00015s. So this group can be scheduled with a period of 0.005s and a run time
 of 0.00015s.
 
-The remaining CPU time will be used for user input and other tass. Because
+The remaining CPU time will be used for user input and other tasks. Because
 realtime tasks have explicitly allocated the CPU time they need to perform
-their tasks, buffer underruns in the graphocs or audio can be eliminated.
+their tasks, buffer underruns in the graphics or audio can be eliminated.
 
 NOTE: the above example is not fully implemented as of yet (2.6.25). We still
 lack an EDF scheduler to make non-uniform periods usable.
index 0bbee38..72aff61 100644 (file)
@@ -753,8 +753,11 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
 
     [Multiple options for each card instance]
     model      - force the model name
-    position_fix - Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size)
+    position_fix - Fix DMA pointer (0 = auto, 1 = use LPIB, 2 = POSBUF)
     probe_mask  - Bitmask to probe codecs (default = -1, meaning all slots)
+    bdl_pos_adj        - Specifies the DMA IRQ timing delay in samples.
+               Passing -1 will make the driver to choose the appropriate
+               value based on the controller chip.
     
     [Single (global) options]
     single_cmd  - Use single immediate commands to communicate with
@@ -845,7 +848,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
        ALC269
          basic         Basic preset
 
-       ALC662
+       ALC662/663
          3stack-dig    3-stack (2-channel) with SPDIF
          3stack-6ch     3-stack (6-channel)
          3stack-6ch-dig 3-stack (6-channel) with SPDIF
@@ -853,6 +856,10 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
          lenovo-101e    Lenovo laptop
          eeepc-p701    ASUS Eeepc P701
          eeepc-ep20    ASUS Eeepc EP20
+         m51va         ASUS M51VA
+         g71v          ASUS G71V
+         h13           ASUS H13
+         g50v          ASUS G50V
          auto          auto-config reading BIOS (default)
 
        ALC882/885
@@ -1091,7 +1098,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
     This occurs when the access to non-existing or non-working codec slot
     (likely a modem one) causes a stall of the communication via HD-audio
     bus.  You can see which codec slots are probed by enabling
-    CONFIG_SND_DEBUG_DETECT, or simply from the file name of the codec
+    CONFIG_SND_DEBUG_VERBOSE, or simply from the file name of the codec
     proc files.  Then limit the slots to probe by probe_mask option.
     For example, probe_mask=1 means to probe only the first slot, and
     probe_mask=4 means only the third slot.
@@ -2267,6 +2274,10 @@ case above again, the first two slots are already reserved.  If any
 other driver (e.g. snd-usb-audio) is loaded before snd-interwave or
 snd-ens1371, it will be assigned to the third or later slot.
 
+When a module name is given with '!', the slot will be given for any
+modules but that name.  For example, "slots=!snd-pcsp" will reserve
+the first slot for any modules but snd-pcsp. 
+
 
 ALSA PCM devices to OSS devices mapping
 =======================================
index b03df4d..e13c4e6 100644 (file)
@@ -6127,8 +6127,8 @@ struct _snd_pcm_runtime {
 
       <para>
         <function>snd_printdd()</function> is compiled in only when
-      <constant>CONFIG_SND_DEBUG_DETECT</constant> is set. Please note
-      that <constant>DEBUG_DETECT</constant> is not set as default
+      <constant>CONFIG_SND_DEBUG_VERBOSE</constant> is set. Please note
+      that <constant>CONFIG_SND_DEBUG_VERBOSE</constant> is not set as default
       even if you configure the alsa-driver with
       <option>--with-debug=full</option> option. You need to give
       explicitly <option>--with-debug=detect</option> option instead. 
diff --git a/Documentation/tracers/mmiotrace.txt b/Documentation/tracers/mmiotrace.txt
new file mode 100644 (file)
index 0000000..a4afb56
--- /dev/null
@@ -0,0 +1,164 @@
+               In-kernel memory-mapped I/O tracing
+
+
+Home page and links to optional user space tools:
+
+       http://nouveau.freedesktop.org/wiki/MmioTrace
+
+MMIO tracing was originally developed by Intel around 2003 for their Fault
+Injection Test Harness. In Dec 2006 - Jan 2007, using the code from Intel,
+Jeff Muizelaar created a tool for tracing MMIO accesses with the Nouveau
+project in mind. Since then many people have contributed.
+
+Mmiotrace was built for reverse engineering any memory-mapped IO device with
+the Nouveau project as the first real user. Only x86 and x86_64 architectures
+are supported.
+
+Out-of-tree mmiotrace was originally modified for mainline inclusion and
+ftrace framework by Pekka Paalanen <pq@iki.fi>.
+
+
+Preparation
+-----------
+
+Mmiotrace feature is compiled in by the CONFIG_MMIOTRACE option. Tracing is
+disabled by default, so it is safe to have this set to yes. SMP systems are
+supported, but tracing is unreliable and may miss events if more than one CPU
+is on-line, therefore mmiotrace takes all but one CPU off-line during run-time
+activation. You can re-enable CPUs by hand, but you have been warned, there
+is no way to automatically detect if you are losing events due to CPUs racing.
+
+
+Usage Quick Reference
+---------------------
+
+$ mount -t debugfs debugfs /debug
+$ echo mmiotrace > /debug/tracing/current_tracer
+$ cat /debug/tracing/trace_pipe > mydump.txt &
+Start X or whatever.
+$ echo "X is up" > /debug/tracing/marker
+$ echo none > /debug/tracing/current_tracer
+Check for lost events.
+
+
+Usage
+-----
+
+Make sure debugfs is mounted to /debug. If not, (requires root privileges)
+$ mount -t debugfs debugfs /debug
+
+Check that the driver you are about to trace is not loaded.
+
+Activate mmiotrace (requires root privileges):
+$ echo mmiotrace > /debug/tracing/current_tracer
+
+Start storing the trace:
+$ cat /debug/tracing/trace_pipe > mydump.txt &
+The 'cat' process should stay running (sleeping) in the background.
+
+Load the driver you want to trace and use it. Mmiotrace will only catch MMIO
+accesses to areas that are ioremapped while mmiotrace is active.
+
+[Unimplemented feature:]
+During tracing you can place comments (markers) into the trace by
+$ echo "X is up" > /debug/tracing/marker
+This makes it easier to see which part of the (huge) trace corresponds to
+which action. It is recommended to place descriptive markers about what you
+do.
+
+Shut down mmiotrace (requires root privileges):
+$ echo none > /debug/tracing/current_tracer
+The 'cat' process exits. If it does not, kill it by issuing 'fg' command and
+pressing ctrl+c.
+
+Check that mmiotrace did not lose events due to a buffer filling up. Either
+$ grep -i lost mydump.txt
+which tells you exactly how many events were lost, or use
+$ dmesg
+to view your kernel log and look for "mmiotrace has lost events" warning. If
+events were lost, the trace is incomplete. You should enlarge the buffers and
+try again. Buffers are enlarged by first seeing how large the current buffers
+are:
+$ cat /debug/tracing/trace_entries
+gives you a number. Approximately double this number and write it back, for
+instance:
+$ echo 128000 > /debug/tracing/trace_entries
+Then start again from the top.
+
+If you are doing a trace for a driver project, e.g. Nouveau, you should also
+do the following before sending your results:
+$ lspci -vvv > lspci.txt
+$ dmesg > dmesg.txt
+$ tar zcf pciid-nick-mmiotrace.tar.gz mydump.txt lspci.txt dmesg.txt
+and then send the .tar.gz file. The trace compresses considerably. Replace
+"pciid" and "nick" with the PCI ID or model name of your piece of hardware
+under investigation and your nick name.
+
+
+How Mmiotrace Works
+-------------------
+
+Access to hardware IO-memory is gained by mapping addresses from PCI bus by
+calling one of the ioremap_*() functions. Mmiotrace is hooked into the
+__ioremap() function and gets called whenever a mapping is created. Mapping is
+an event that is recorded into the trace log. Note, that ISA range mappings
+are not caught, since the mapping always exists and is returned directly.
+
+MMIO accesses are recorded via page faults. Just before __ioremap() returns,
+the mapped pages are marked as not present. Any access to the pages causes a
+fault. The page fault handler calls mmiotrace to handle the fault. Mmiotrace
+marks the page present, sets TF flag to achieve single stepping and exits the
+fault handler. The instruction that faulted is executed and debug trap is
+entered. Here mmiotrace again marks the page as not present. The instruction
+is decoded to get the type of operation (read/write), data width and the value
+read or written. These are stored to the trace log.
+
+Setting the page present in the page fault handler has a race condition on SMP
+machines. During the single stepping other CPUs may run freely on that page
+and events can be missed without a notice. Re-enabling other CPUs during
+tracing is discouraged.
+
+
+Trace Log Format
+----------------
+
+The raw log is text and easily filtered with e.g. grep and awk. One record is
+one line in the log. A record starts with a keyword, followed by keyword
+dependant arguments. Arguments are separated by a space, or continue until the
+end of line. The format for version 20070824 is as follows:
+
+Explanation    Keyword Space separated arguments
+---------------------------------------------------------------------------
+
+read event     R       width, timestamp, map id, physical, value, PC, PID
+write event    W       width, timestamp, map id, physical, value, PC, PID
+ioremap event  MAP     timestamp, map id, physical, virtual, length, PC, PID
+iounmap event  UNMAP   timestamp, map id, PC, PID
+marker         MARK    timestamp, text
+version                VERSION the string "20070824"
+info for reader        LSPCI   one line from lspci -v
+PCI address map        PCIDEV  space separated /proc/bus/pci/devices data
+unk. opcode    UNKNOWN timestamp, map id, physical, data, PC, PID
+
+Timestamp is in seconds with decimals. Physical is a PCI bus address, virtual
+is a kernel virtual address. Width is the data width in bytes and value is the
+data value. Map id is an arbitrary id number identifying the mapping that was
+used in an operation. PC is the program counter and PID is process id. PC is
+zero if it is not recorded. PID is always zero as tracing MMIO accesses
+originating in user space memory is not yet supported.
+
+For instance, the following awk filter will pass all 32-bit writes that target
+physical addresses in the range [0xfb73ce40, 0xfb800000[
+
+$ awk '/W 4 / { adr=strtonum($5); if (adr >= 0xfb73ce40 &&
+adr < 0xfb800000) print; }'
+
+
+Tools for Developers
+--------------------
+
+The user space tools include utilities for:
+- replacing numeric addresses and values with hardware register names
+- replaying MMIO logs, i.e., re-executing the recorded writes
+
+
diff --git a/Documentation/x86/i386/IO-APIC.txt b/Documentation/x86/i386/IO-APIC.txt
new file mode 100644 (file)
index 0000000..30b4c71
--- /dev/null
@@ -0,0 +1,119 @@
+Most (all) Intel-MP compliant SMP boards have the so-called 'IO-APIC',
+which is an enhanced interrupt controller. It enables us to route
+hardware interrupts to multiple CPUs, or to CPU groups. Without an
+IO-APIC, interrupts from hardware will be delivered only to the
+CPU which boots the operating system (usually CPU#0).
+
+Linux supports all variants of compliant SMP boards, including ones with
+multiple IO-APICs. Multiple IO-APICs are used in high-end servers to
+distribute IRQ load further.
+
+There are (a few) known breakages in certain older boards, such bugs are
+usually worked around by the kernel. If your MP-compliant SMP board does
+not boot Linux, then consult the linux-smp mailing list archives first.
+
+If your box boots fine with enabled IO-APIC IRQs, then your
+/proc/interrupts will look like this one:
+
+   ---------------------------->
+  hell:~> cat /proc/interrupts
+             CPU0
+    0:    1360293    IO-APIC-edge  timer
+    1:          4    IO-APIC-edge  keyboard
+    2:          0          XT-PIC  cascade
+   13:          1          XT-PIC  fpu
+   14:       1448    IO-APIC-edge  ide0
+   16:      28232   IO-APIC-level  Intel EtherExpress Pro 10/100 Ethernet
+   17:      51304   IO-APIC-level  eth0
+  NMI:          0
+  ERR:          0
+  hell:~>
+  <----------------------------
+
+Some interrupts are still listed as 'XT PIC', but this is not a problem;
+none of those IRQ sources is performance-critical.
+
+
+In the unlikely case that your board does not create a working mp-table,
+you can use the pirq= boot parameter to 'hand-construct' IRQ entries. This
+is non-trivial though and cannot be automated. One sample /etc/lilo.conf
+entry:
+
+       append="pirq=15,11,10"
+
+The actual numbers depend on your system, on your PCI cards and on their
+PCI slot position. Usually PCI slots are 'daisy chained' before they are
+connected to the PCI chipset IRQ routing facility (the incoming PIRQ1-4
+lines):
+
+               ,-.        ,-.        ,-.        ,-.        ,-.
+     PIRQ4 ----| |-.    ,-| |-.    ,-| |-.    ,-| |--------| |
+               |S|  \  /  |S|  \  /  |S|  \  /  |S|        |S|
+     PIRQ3 ----|l|-. `/---|l|-. `/---|l|-. `/---|l|--------|l|
+               |o|  \/    |o|  \/    |o|  \/    |o|        |o|
+     PIRQ2 ----|t|-./`----|t|-./`----|t|-./`----|t|--------|t|
+               |1| /\     |2| /\     |3| /\     |4|        |5|
+     PIRQ1 ----| |-  `----| |-  `----| |-  `----| |--------| |
+               `-'        `-'        `-'        `-'        `-'
+
+Every PCI card emits a PCI IRQ, which can be INTA, INTB, INTC or INTD:
+
+                               ,-.
+                         INTD--| |
+                               |S|
+                         INTC--|l|
+                               |o|
+                         INTB--|t|
+                               |x|
+                         INTA--| |
+                               `-'
+
+These INTA-D PCI IRQs are always 'local to the card', their real meaning
+depends on which slot they are in. If you look at the daisy chaining diagram,
+a card in slot4, issuing INTA IRQ, it will end up as a signal on PIRQ4 of
+the PCI chipset. Most cards issue INTA, this creates optimal distribution
+between the PIRQ lines. (distributing IRQ sources properly is not a
+necessity, PCI IRQs can be shared at will, but it's a good for performance
+to have non shared interrupts). Slot5 should be used for videocards, they
+do not use interrupts normally, thus they are not daisy chained either.
+
+so if you have your SCSI card (IRQ11) in Slot1, Tulip card (IRQ9) in
+Slot2, then you'll have to specify this pirq= line:
+
+       append="pirq=11,9"
+
+the following script tries to figure out such a default pirq= line from
+your PCI configuration:
+
+       echo -n pirq=; echo `scanpci | grep T_L | cut -c56-` | sed 's/ /,/g'
+
+note that this script wont work if you have skipped a few slots or if your
+board does not do default daisy-chaining. (or the IO-APIC has the PIRQ pins
+connected in some strange way). E.g. if in the above case you have your SCSI
+card (IRQ11) in Slot3, and have Slot1 empty:
+
+       append="pirq=0,9,11"
+
+[value '0' is a generic 'placeholder', reserved for empty (or non-IRQ emitting)
+slots.]
+
+Generally, it's always possible to find out the correct pirq= settings, just
+permute all IRQ numbers properly ... it will take some time though. An
+'incorrect' pirq line will cause the booting process to hang, or a device
+won't function properly (e.g. if it's inserted as a module).
+
+If you have 2 PCI buses, then you can use up to 8 pirq values, although such
+boards tend to have a good configuration.
+
+Be prepared that it might happen that you need some strange pirq line:
+
+       append="pirq=0,0,0,0,0,0,9,11"
+
+Use smart trial-and-error techniques to find out the correct pirq line ...
+
+Good luck and mail to linux-smp@vger.kernel.org or
+linux-kernel@vger.kernel.org if you have any problems that are not covered
+by this document.
+
+-- mingo
+
diff --git a/Documentation/x86/i386/boot.txt b/Documentation/x86/i386/boot.txt
new file mode 100644 (file)
index 0000000..147bfe5
--- /dev/null
@@ -0,0 +1,900 @@
+                    THE LINUX/x86 BOOT PROTOCOL
+                    ---------------------------
+
+On the x86 platform, the Linux kernel uses a rather complicated boot
+convention.  This has evolved partially due to historical aspects, as
+well as the desire in the early days to have the kernel itself be a
+bootable image, the complicated PC memory model and due to changed
+expectations in the PC industry caused by the effective demise of
+real-mode DOS as a mainstream operating system.
+
+Currently, the following versions of the Linux/x86 boot protocol exist.
+
+Old kernels:   zImage/Image support only.  Some very early kernels
+               may not even support a command line.
+
+Protocol 2.00: (Kernel 1.3.73) Added bzImage and initrd support, as
+               well as a formalized way to communicate between the
+               boot loader and the kernel.  setup.S made relocatable,
+               although the traditional setup area still assumed
+               writable.
+
+Protocol 2.01: (Kernel 1.3.76) Added a heap overrun warning.
+
+Protocol 2.02: (Kernel 2.4.0-test3-pre3) New command line protocol.
+               Lower the conventional memory ceiling.  No overwrite
+               of the traditional setup area, thus making booting
+               safe for systems which use the EBDA from SMM or 32-bit
+               BIOS entry points.  zImage deprecated but still
+               supported.
+
+Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly makes the highest possible
+               initrd address available to the bootloader.
+
+Protocol 2.04: (Kernel 2.6.14) Extend the syssize field to four bytes.
+
+Protocol 2.05: (Kernel 2.6.20) Make protected mode kernel relocatable.
+               Introduce relocatable_kernel and kernel_alignment fields.
+
+Protocol 2.06: (Kernel 2.6.22) Added a field that contains the size of
+               the boot command line.
+
+Protocol 2.07: (Kernel 2.6.24) Added paravirtualised boot protocol.
+               Introduced hardware_subarch and hardware_subarch_data
+               and KEEP_SEGMENTS flag in load_flags.
+
+Protocol 2.08: (Kernel 2.6.26) Added crc32 checksum and ELF format
+               payload. Introduced payload_offset and payload length
+               fields to aid in locating the payload.
+
+Protocol 2.09: (Kernel 2.6.26) Added a field of 64-bit physical
+               pointer to single linked list of struct setup_data.
+
+**** MEMORY LAYOUT
+
+The traditional memory map for the kernel loader, used for Image or
+zImage kernels, typically looks like:
+
+       |                        |
+0A0000 +------------------------+
+       |  Reserved for BIOS     |      Do not use.  Reserved for BIOS EBDA.
+09A000 +------------------------+
+       |  Command line          |
+       |  Stack/heap            |      For use by the kernel real-mode code.
+098000 +------------------------+      
+       |  Kernel setup          |      The kernel real-mode code.
+090200 +------------------------+
+       |  Kernel boot sector    |      The kernel legacy boot sector.
+090000 +------------------------+
+       |  Protected-mode kernel |      The bulk of the kernel image.
+010000 +------------------------+
+       |  Boot loader           |      <- Boot sector entry point 0000:7C00
+001000 +------------------------+
+       |  Reserved for MBR/BIOS |
+000800 +------------------------+
+       |  Typically used by MBR |
+000600 +------------------------+ 
+       |  BIOS use only         |
+000000 +------------------------+
+
+
+When using bzImage, the protected-mode kernel was relocated to
+0x100000 ("high memory"), and the kernel real-mode block (boot sector,
+setup, and stack/heap) was made relocatable to any address between
+0x10000 and end of low memory. Unfortunately, in protocols 2.00 and
+2.01 the 0x90000+ memory range is still used internally by the kernel;
+the 2.02 protocol resolves that problem.
+
+It is desirable to keep the "memory ceiling" -- the highest point in
+low memory touched by the boot loader -- as low as possible, since
+some newer BIOSes have begun to allocate some rather large amounts of
+memory, called the Extended BIOS Data Area, near the top of low
+memory.         The boot loader should use the "INT 12h" BIOS call to verify
+how much low memory is available.
+
+Unfortunately, if INT 12h reports that the amount of memory is too
+low, there is usually nothing the boot loader can do but to report an
+error to the user.  The boot loader should therefore be designed to
+take up as little space in low memory as it reasonably can.  For
+zImage or old bzImage kernels, which need data written into the
+0x90000 segment, the boot loader should make sure not to use memory
+above the 0x9A000 point; too many BIOSes will break above that point.
+
+For a modern bzImage kernel with boot protocol version >= 2.02, a
+memory layout like the following is suggested:
+
+       ~                        ~
+        |  Protected-mode kernel |
+100000  +------------------------+
+       |  I/O memory hole       |
+0A0000 +------------------------+
+       |  Reserved for BIOS     |      Leave as much as possible unused
+       ~                        ~
+       |  Command line          |      (Can also be below the X+10000 mark)
+X+10000        +------------------------+
+       |  Stack/heap            |      For use by the kernel real-mode code.
+X+08000        +------------------------+      
+       |  Kernel setup          |      The kernel real-mode code.
+       |  Kernel boot sector    |      The kernel legacy boot sector.
+X       +------------------------+
+       |  Boot loader           |      <- Boot sector entry point 0000:7C00
+001000 +------------------------+
+       |  Reserved for MBR/BIOS |
+000800 +------------------------+
+       |  Typically used by MBR |
+000600 +------------------------+ 
+       |  BIOS use only         |
+000000 +------------------------+
+
+... where the address X is as low as the design of the boot loader
+permits.
+
+
+**** THE REAL-MODE KERNEL HEADER
+
+In the following text, and anywhere in the kernel boot sequence, "a
+sector" refers to 512 bytes.  It is independent of the actual sector
+size of the underlying medium.
+
+The first step in loading a Linux kernel should be to load the
+real-mode code (boot sector and setup code) and then examine the
+following header at offset 0x01f1.  The real-mode code can total up to
+32K, although the boot loader may choose to load only the first two
+sectors (1K) and then examine the bootup sector size.
+
+The header looks like:
+
+Offset Proto   Name            Meaning
+/Size
+
+01F1/1 ALL(1   setup_sects     The size of the setup in sectors
+01F2/2 ALL     root_flags      If set, the root is mounted readonly
+01F4/4 2.04+(2 syssize         The size of the 32-bit code in 16-byte paras
+01F8/2 ALL     ram_size        DO NOT USE - for bootsect.S use only
+01FA/2 ALL     vid_mode        Video mode control
+01FC/2 ALL     root_dev        Default root device number
+01FE/2 ALL     boot_flag       0xAA55 magic number
+0200/2 2.00+   jump            Jump instruction
+0202/4 2.00+   header          Magic signature "HdrS"
+0206/2 2.00+   version         Boot protocol version supported
+0208/4 2.00+   realmode_swtch  Boot loader hook (see below)
+020C/2 2.00+   start_sys       The load-low segment (0x1000) (obsolete)
+020E/2 2.00+   kernel_version  Pointer to kernel version string
+0210/1 2.00+   type_of_loader  Boot loader identifier
+0211/1 2.00+   loadflags       Boot protocol option flags
+0212/2 2.00+   setup_move_size Move to high memory size (used with hooks)
+0214/4 2.00+   code32_start    Boot loader hook (see below)
+0218/4 2.00+   ramdisk_image   initrd load address (set by boot loader)
+021C/4 2.00+   ramdisk_size    initrd size (set by boot loader)
+0220/4 2.00+   bootsect_kludge DO NOT USE - for bootsect.S use only
+0224/2 2.01+   heap_end_ptr    Free memory after setup end
+0226/2 N/A     pad1            Unused
+0228/4 2.02+   cmd_line_ptr    32-bit pointer to the kernel command line
+022C/4 2.03+   initrd_addr_max Highest legal initrd address
+0230/4 2.05+   kernel_alignment Physical addr alignment required for kernel
+0234/1 2.05+   relocatable_kernel Whether kernel is relocatable or not
+0235/3 N/A     pad2            Unused
+0238/4 2.06+   cmdline_size    Maximum size of the kernel command line
+023C/4 2.07+   hardware_subarch Hardware subarchitecture
+0240/8 2.07+   hardware_subarch_data Subarchitecture-specific data
+0248/4 2.08+   payload_offset  Offset of kernel payload
+024C/4 2.08+   payload_length  Length of kernel payload
+0250/8 2.09+   setup_data      64-bit physical pointer to linked list
+                               of struct setup_data
+
+(1) For backwards compatibility, if the setup_sects field contains 0, the
+    real value is 4.
+
+(2) For boot protocol prior to 2.04, the upper two bytes of the syssize
+    field are unusable, which means the size of a bzImage kernel
+    cannot be determined.
+
+If the "HdrS" (0x53726448) magic number is not found at offset 0x202,
+the boot protocol version is "old".  Loading an old kernel, the
+following parameters should be assumed:
+
+       Image type = zImage
+       initrd not supported
+       Real-mode kernel must be located at 0x90000.
+
+Otherwise, the "version" field contains the protocol version,
+e.g. protocol version 2.01 will contain 0x0201 in this field.  When
+setting fields in the header, you must make sure only to set fields
+supported by the protocol version in use.
+
+
+**** DETAILS OF HEADER FIELDS
+
+For each field, some are information from the kernel to the bootloader
+("read"), some are expected to be filled out by the bootloader
+("write"), and some are expected to be read and modified by the
+bootloader ("modify").
+
+All general purpose boot loaders should write the fields marked
+(obligatory).  Boot loaders who want to load the kernel at a
+nonstandard address should fill in the fields marked (reloc); other
+boot loaders can ignore those fields.
+
+The byte order of all fields is littleendian (this is x86, after all.)
+
+Field name:    setup_sects
+Type:          read
+Offset/size:   0x1f1/1
+Protocol:      ALL
+
+  The size of the setup code in 512-byte sectors.  If this field is
+  0, the real value is 4.  The real-mode code consists of the boot
+  sector (always one 512-byte sector) plus the setup code.
+
+Field name:     root_flags
+Type:           modify (optional)
+Offset/size:    0x1f2/2
+Protocol:       ALL
+
+  If this field is nonzero, the root defaults to readonly.  The use of
+  this field is deprecated; use the "ro" or "rw" options on the
+  command line instead.
+
+Field name:    syssize
+Type:          read
+Offset/size:   0x1f4/4 (protocol 2.04+) 0x1f4/2 (protocol ALL)
+Protocol:      2.04+
+
+  The size of the protected-mode code in units of 16-byte paragraphs.
+  For protocol versions older than 2.04 this field is only two bytes
+  wide, and therefore cannot be trusted for the size of a kernel if
+  the LOAD_HIGH flag is set.
+
+Field name:    ram_size
+Type:          kernel internal
+Offset/size:   0x1f8/2
+Protocol:      ALL
+
+  This field is obsolete.
+
+Field name:    vid_mode
+Type:          modify (obligatory)
+Offset/size:   0x1fa/2
+
+  Please see the section on SPECIAL COMMAND LINE OPTIONS.
+
+Field name:    root_dev
+Type:          modify (optional)
+Offset/size:   0x1fc/2
+Protocol:      ALL
+
+  The default root device device number.  The use of this field is
+  deprecated, use the "root=" option on the command line instead.
+
+Field name:    boot_flag
+Type:          read
+Offset/size:   0x1fe/2
+Protocol:      ALL
+
+  Contains 0xAA55.  This is the closest thing old Linux kernels have
+  to a magic number.
+
+Field name:    jump
+Type:          read
+Offset/size:   0x200/2
+Protocol:      2.00+
+
+  Contains an x86 jump instruction, 0xEB followed by a signed offset
+  relative to byte 0x202.  This can be used to determine the size of
+  the header.
+
+Field name:    header
+Type:          read
+Offset/size:   0x202/4
+Protocol:      2.00+
+
+  Contains the magic number "HdrS" (0x53726448).
+
+Field name:    version
+Type:          read
+Offset/size:   0x206/2
+Protocol:      2.00+
+
+  Contains the boot protocol version, in (major << 8)+minor format,
+  e.g. 0x0204 for version 2.04, and 0x0a11 for a hypothetical version
+  10.17.
+
+Field name:    readmode_swtch
+Type:          modify (optional)
+Offset/size:   0x208/4
+Protocol:      2.00+
+
+  Boot loader hook (see ADVANCED BOOT LOADER HOOKS below.)
+
+Field name:    start_sys
+Type:          read
+Offset/size:   0x20c/4
+Protocol:      2.00+
+
+  The load low segment (0x1000).  Obsolete.
+
+Field name:    kernel_version
+Type:          read
+Offset/size:   0x20e/2
+Protocol:      2.00+
+
+  If set to a nonzero value, contains a pointer to a NUL-terminated
+  human-readable kernel version number string, less 0x200.  This can
+  be used to display the kernel version to the user.  This value
+  should be less than (0x200*setup_sects).
+
+  For example, if this value is set to 0x1c00, the kernel version
+  number string can be found at offset 0x1e00 in the kernel file.
+  This is a valid value if and only if the "setup_sects" field
+  contains the value 15 or higher, as:
+
+       0x1c00  < 15*0x200 (= 0x1e00) but
+       0x1c00 >= 14*0x200 (= 0x1c00)
+
+       0x1c00 >> 9 = 14, so the minimum value for setup_secs is 15.
+
+Field name:    type_of_loader
+Type:          write (obligatory)
+Offset/size:   0x210/1
+Protocol:      2.00+
+
+  If your boot loader has an assigned id (see table below), enter
+  0xTV here, where T is an identifier for the boot loader and V is
+  a version number.  Otherwise, enter 0xFF here.
+
+  Assigned boot loader ids:
+       0  LILO                 (0x00 reserved for pre-2.00 bootloader)
+       1  Loadlin
+       2  bootsect-loader      (0x20, all other values reserved)
+       3  SYSLINUX
+       4  EtherBoot
+       5  ELILO
+       7  GRuB
+       8  U-BOOT
+       9  Xen
+       A  Gujin
+       B  Qemu
+
+  Please contact <hpa@zytor.com> if you need a bootloader ID
+  value assigned.
+
+Field name:    loadflags
+Type:          modify (obligatory)
+Offset/size:   0x211/1
+Protocol:      2.00+
+
+  This field is a bitmask.
+
+  Bit 0 (read):        LOADED_HIGH
+       - If 0, the protected-mode code is loaded at 0x10000.
+       - If 1, the protected-mode code is loaded at 0x100000.
+
+  Bit 5 (write): QUIET_FLAG
+       - If 0, print early messages.
+       - If 1, suppress early messages.
+               This requests to the kernel (decompressor and early
+               kernel) to not write early messages that require
+               accessing the display hardware directly.
+
+  Bit 6 (write): KEEP_SEGMENTS
+       Protocol: 2.07+
+       - If 0, reload the segment registers in the 32bit entry point.
+       - If 1, do not reload the segment registers in the 32bit entry point.
+               Assume that %cs %ds %ss %es are all set to flat segments with
+               a base of 0 (or the equivalent for their environment).
+
+  Bit 7 (write): CAN_USE_HEAP
+       Set this bit to 1 to indicate that the value entered in the
+       heap_end_ptr is valid.  If this field is clear, some setup code
+       functionality will be disabled.
+
+Field name:    setup_move_size
+Type:          modify (obligatory)
+Offset/size:   0x212/2
+Protocol:      2.00-2.01
+
+  When using protocol 2.00 or 2.01, if the real mode kernel is not
+  loaded at 0x90000, it gets moved there later in the loading
+  sequence.  Fill in this field if you want additional data (such as
+  the kernel command line) moved in addition to the real-mode kernel
+  itself.
+
+  The unit is bytes starting with the beginning of the boot sector.
+  
+  This field is can be ignored when the protocol is 2.02 or higher, or
+  if the real-mode code is loaded at 0x90000.
+
+Field name:    code32_start
+Type:          modify (optional, reloc)
+Offset/size:   0x214/4
+Protocol:      2.00+
+
+  The address to jump to in protected mode.  This defaults to the load
+  address of the kernel, and can be used by the boot loader to
+  determine the proper load address.
+
+  This field can be modified for two purposes:
+
+  1. as a boot loader hook (see ADVANCED BOOT LOADER HOOKS below.)
+
+  2. if a bootloader which does not install a hook loads a
+     relocatable kernel at a nonstandard address it will have to modify
+     this field to point to the load address.
+
+Field name:    ramdisk_image
+Type:          write (obligatory)
+Offset/size:   0x218/4
+Protocol:      2.00+
+
+  The 32-bit linear address of the initial ramdisk or ramfs.  Leave at
+  zero if there is no initial ramdisk/ramfs.
+
+Field name:    ramdisk_size
+Type:          write (obligatory)
+Offset/size:   0x21c/4
+Protocol:      2.00+
+
+  Size of the initial ramdisk or ramfs.  Leave at zero if there is no
+  initial ramdisk/ramfs.
+
+Field name:    bootsect_kludge
+Type:          kernel internal
+Offset/size:   0x220/4
+Protocol:      2.00+
+
+  This field is obsolete.
+
+Field name:    heap_end_ptr
+Type:          write (obligatory)
+Offset/size:   0x224/2
+Protocol:      2.01+
+
+  Set this field to the offset (from the beginning of the real-mode
+  code) of the end of the setup stack/heap, minus 0x0200.
+
+Field name:    cmd_line_ptr
+Type:          write (obligatory)
+Offset/size:   0x228/4
+Protocol:      2.02+
+
+  Set this field to the linear address of the kernel command line.
+  The kernel command line can be located anywhere between the end of
+  the setup heap and 0xA0000; it does not have to be located in the
+  same 64K segment as the real-mode code itself.
+
+  Fill in this field even if your boot loader does not support a
+  command line, in which case you can point this to an empty string
+  (or better yet, to the string "auto".)  If this field is left at
+  zero, the kernel will assume that your boot loader does not support
+  the 2.02+ protocol.
+
+Field name:    initrd_addr_max
+Type:          read
+Offset/size:   0x22c/4
+Protocol:      2.03+
+
+  The maximum address that may be occupied by the initial
+  ramdisk/ramfs contents.  For boot protocols 2.02 or earlier, this
+  field is not present, and the maximum address is 0x37FFFFFF.  (This
+  address is defined as the address of the highest safe byte, so if
+  your ramdisk is exactly 131072 bytes long and this field is
+  0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
+
+Field name:    kernel_alignment
+Type:          read (reloc)
+Offset/size:   0x230/4
+Protocol:      2.05+
+
+  Alignment unit required by the kernel (if relocatable_kernel is true.)
+
+Field name:    relocatable_kernel
+Type:          read (reloc)
+Offset/size:   0x234/1
+Protocol:      2.05+
+
+  If this field is nonzero, the protected-mode part of the kernel can
+  be loaded at any address that satisfies the kernel_alignment field.
+  After loading, the boot loader must set the code32_start field to
+  point to the loaded code, or to a boot loader hook.
+
+Field name:    cmdline_size
+Type:          read
+Offset/size:   0x238/4
+Protocol:      2.06+
+
+  The maximum size of the command line without the terminating
+  zero. This means that the command line can contain at most
+  cmdline_size characters. With protocol version 2.05 and earlier, the
+  maximum size was 255.
+
+Field name:    hardware_subarch
+Type:          write (optional, defaults to x86/PC)
+Offset/size:   0x23c/4
+Protocol:      2.07+
+
+  In a paravirtualized environment the hardware low level architectural
+  pieces such as interrupt handling, page table handling, and
+  accessing process control registers needs to be done differently.
+
+  This field allows the bootloader to inform the kernel we are in one
+  one of those environments.
+
+  0x00000000   The default x86/PC environment
+  0x00000001   lguest
+  0x00000002   Xen
+
+Field name:    hardware_subarch_data
+Type:          write (subarch-dependent)
+Offset/size:   0x240/8
+Protocol:      2.07+
+
+  A pointer to data that is specific to hardware subarch
+  This field is currently unused for the default x86/PC environment,
+  do not modify.
+
+Field name:    payload_offset
+Type:          read
+Offset/size:   0x248/4
+Protocol:      2.08+
+
+  If non-zero then this field contains the offset from the end of the
+  real-mode code to the payload.
+
+  The payload may be compressed. The format of both the compressed and
+  uncompressed data should be determined using the standard magic
+  numbers. Currently only gzip compressed ELF is used.
+  
+Field name:    payload_length
+Type:          read
+Offset/size:   0x24c/4
+Protocol:      2.08+
+
+  The length of the payload.
+
+Field name:    setup_data
+Type:          write (special)
+Offset/size:   0x250/8
+Protocol:      2.09+
+
+  The 64-bit physical pointer to NULL terminated single linked list of
+  struct setup_data. This is used to define a more extensible boot
+  parameters passing mechanism. The definition of struct setup_data is
+  as follow:
+
+  struct setup_data {
+         u64 next;
+         u32 type;
+         u32 len;
+         u8  data[0];
+  };
+
+  Where, the next is a 64-bit physical pointer to the next node of
+  linked list, the next field of the last node is 0; the type is used
+  to identify the contents of data; the len is the length of data
+  field; the data holds the real payload.
+
+  This list may be modified at a number of points during the bootup
+  process.  Therefore, when modifying this list one should always make
+  sure to consider the case where the linked list already contains
+  entries.
+
+
+**** THE IMAGE CHECKSUM
+
+From boot protocol version 2.08 onwards the CRC-32 is calculated over
+the entire file using the characteristic polynomial 0x04C11DB7 and an
+initial remainder of 0xffffffff.  The checksum is appended to the
+file; therefore the CRC of the file up to the limit specified in the
+syssize field of the header is always 0.
+
+
+**** THE KERNEL COMMAND LINE
+
+The kernel command line has become an important way for the boot
+loader to communicate with the kernel.  Some of its options are also
+relevant to the boot loader itself, see "special command line options"
+below.
+
+The kernel command line is a null-terminated string. The maximum
+length can be retrieved from the field cmdline_size.  Before protocol
+version 2.06, the maximum was 255 characters.  A string that is too
+long will be automatically truncated by the kernel.
+
+If the boot protocol version is 2.02 or later, the address of the
+kernel command line is given by the header field cmd_line_ptr (see
+above.)  This address can be anywhere between the end of the setup
+heap and 0xA0000.
+
+If the protocol version is *not* 2.02 or higher, the kernel
+command line is entered using the following protocol:
+
+       At offset 0x0020 (word), "cmd_line_magic", enter the magic
+       number 0xA33F.
+
+       At offset 0x0022 (word), "cmd_line_offset", enter the offset
+       of the kernel command line (relative to the start of the
+       real-mode kernel).
+       
+       The kernel command line *must* be within the memory region
+       covered by setup_move_size, so you may need to adjust this
+       field.
+
+
+**** MEMORY LAYOUT OF THE REAL-MODE CODE
+
+The real-mode code requires a stack/heap to be set up, as well as
+memory allocated for the kernel command line.  This needs to be done
+in the real-mode accessible memory in bottom megabyte.
+
+It should be noted that modern machines often have a sizable Extended
+BIOS Data Area (EBDA).  As a result, it is advisable to use as little
+of the low megabyte as possible.
+
+Unfortunately, under the following circumstances the 0x90000 memory
+segment has to be used:
+
+       - When loading a zImage kernel ((loadflags & 0x01) == 0).
+       - When loading a 2.01 or earlier boot protocol kernel.
+
+         -> For the 2.00 and 2.01 boot protocols, the real-mode code
+            can be loaded at another address, but it is internally
+            relocated to 0x90000.  For the "old" protocol, the
+            real-mode code must be loaded at 0x90000.
+
+When loading at 0x90000, avoid using memory above 0x9a000.
+
+For boot protocol 2.02 or higher, the command line does not have to be
+located in the same 64K segment as the real-mode setup code; it is
+thus permitted to give the stack/heap the full 64K segment and locate
+the command line above it.
+
+The kernel command line should not be located below the real-mode
+code, nor should it be located in high memory.
+
+
+**** SAMPLE BOOT CONFIGURATION
+
+As a sample configuration, assume the following layout of the real
+mode segment:
+
+    When loading below 0x90000, use the entire segment:
+
+       0x0000-0x7fff   Real mode kernel
+       0x8000-0xdfff   Stack and heap
+       0xe000-0xffff   Kernel command line
+
+    When loading at 0x90000 OR the protocol version is 2.01 or earlier:
+
+       0x0000-0x7fff   Real mode kernel
+       0x8000-0x97ff   Stack and heap
+       0x9800-0x9fff   Kernel command line
+
+Such a boot loader should enter the following fields in the header:
+
+       unsigned long base_ptr; /* base address for real-mode segment */
+
+       if ( setup_sects == 0 ) {
+               setup_sects = 4;
+       }
+
+       if ( protocol >= 0x0200 ) {
+               type_of_loader = <type code>;
+               if ( loading_initrd ) {
+                       ramdisk_image = <initrd_address>;
+                       ramdisk_size = <initrd_size>;
+               }
+
+               if ( protocol >= 0x0202 && loadflags & 0x01 )
+                       heap_end = 0xe000;
+               else
+                       heap_end = 0x9800;
+
+               if ( protocol >= 0x0201 ) {
+                       heap_end_ptr = heap_end - 0x200;
+                       loadflags |= 0x80; /* CAN_USE_HEAP */
+               }
+
+               if ( protocol >= 0x0202 ) {
+                       cmd_line_ptr = base_ptr + heap_end;
+                       strcpy(cmd_line_ptr, cmdline);
+               } else {
+                       cmd_line_magic  = 0xA33F;
+                       cmd_line_offset = heap_end;
+                       setup_move_size = heap_end + strlen(cmdline)+1;
+                       strcpy(base_ptr+cmd_line_offset, cmdline);
+               }
+       } else {
+               /* Very old kernel */
+
+               heap_end = 0x9800;
+
+               cmd_line_magic  = 0xA33F;
+               cmd_line_offset = heap_end;
+
+               /* A very old kernel MUST have its real-mode code
+                  loaded at 0x90000 */
+
+               if ( base_ptr != 0x90000 ) {
+                       /* Copy the real-mode kernel */
+                       memcpy(0x90000, base_ptr, (setup_sects+1)*512);
+                       base_ptr = 0x90000;              /* Relocated */
+               }
+
+               strcpy(0x90000+cmd_line_offset, cmdline);
+
+               /* It is recommended to clear memory up to the 32K mark */
+               memset(0x90000 + (setup_sects+1)*512, 0,
+                      (64-(setup_sects+1))*512);
+       }
+
+
+**** LOADING THE REST OF THE KERNEL
+
+The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
+in the kernel file (again, if setup_sects == 0 the real value is 4.)
+It should be loaded at address 0x10000 for Image/zImage kernels and
+0x100000 for bzImage kernels.
+
+The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01
+bit (LOAD_HIGH) in the loadflags field is set:
+
+       is_bzImage = (protocol >= 0x0200) && (loadflags & 0x01);
+       load_address = is_bzImage ? 0x100000 : 0x10000;
+
+Note that Image/zImage kernels can be up to 512K in size, and thus use
+the entire 0x10000-0x90000 range of memory.  This means it is pretty
+much a requirement for these kernels to load the real-mode part at
+0x90000.  bzImage kernels allow much more flexibility.
+
+
+**** SPECIAL COMMAND LINE OPTIONS
+
+If the command line provided by the boot loader is entered by the
+user, the user may expect the following command line options to work.
+They should normally not be deleted from the kernel command line even
+though not all of them are actually meaningful to the kernel.  Boot
+loader authors who need additional command line options for the boot
+loader itself should get them registered in
+Documentation/kernel-parameters.txt to make sure they will not
+conflict with actual kernel options now or in the future.
+
+  vga=<mode>
+       <mode> here is either an integer (in C notation, either
+       decimal, octal, or hexadecimal) or one of the strings
+       "normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask"
+       (meaning 0xFFFD).  This value should be entered into the
+       vid_mode field, as it is used by the kernel before the command
+       line is parsed.
+
+  mem=<size>
+       <size> is an integer in C notation optionally followed by
+       (case insensitive) K, M, G, T, P or E (meaning << 10, << 20,
+       << 30, << 40, << 50 or << 60).  This specifies the end of
+       memory to the kernel. This affects the possible placement of
+       an initrd, since an initrd should be placed near end of
+       memory.  Note that this is an option to *both* the kernel and
+       the bootloader!
+
+  initrd=<file>
+       An initrd should be loaded.  The meaning of <file> is
+       obviously bootloader-dependent, and some boot loaders
+       (e.g. LILO) do not have such a command.
+
+In addition, some boot loaders add the following options to the
+user-specified command line:
+
+  BOOT_IMAGE=<file>
+       The boot image which was loaded.  Again, the meaning of <file>
+       is obviously bootloader-dependent.
+
+  auto
+       The kernel was booted without explicit user intervention.
+
+If these options are added by the boot loader, it is highly
+recommended that they are located *first*, before the user-specified
+or configuration-specified command line.  Otherwise, "init=/bin/sh"
+gets confused by the "auto" option.
+
+
+**** RUNNING THE KERNEL
+
+The kernel is started by jumping to the kernel entry point, which is
+located at *segment* offset 0x20 from the start of the real mode
+kernel.  This means that if you loaded your real-mode kernel code at
+0x90000, the kernel entry point is 9020:0000.
+
+At entry, ds = es = ss should point to the start of the real-mode
+kernel code (0x9000 if the code is loaded at 0x90000), sp should be
+set up properly, normally pointing to the top of the heap, and
+interrupts should be disabled.  Furthermore, to guard against bugs in
+the kernel, it is recommended that the boot loader sets fs = gs = ds =
+es = ss.
+
+In our example from above, we would do:
+
+       /* Note: in the case of the "old" kernel protocol, base_ptr must
+          be == 0x90000 at this point; see the previous sample code */
+
+       seg = base_ptr >> 4;
+
+       cli();  /* Enter with interrupts disabled! */
+
+       /* Set up the real-mode kernel stack */
+       _SS = seg;
+       _SP = heap_end;
+
+       _DS = _ES = _FS = _GS = seg;
+       jmp_far(seg+0x20, 0);   /* Run the kernel */
+
+If your boot sector accesses a floppy drive, it is recommended to
+switch off the floppy motor before running the kernel, since the
+kernel boot leaves interrupts off and thus the motor will not be
+switched off, especially if the loaded kernel has the floppy driver as
+a demand-loaded module!
+
+
+**** ADVANCED BOOT LOADER HOOKS
+
+If the boot loader runs in a particularly hostile environment (such as
+LOADLIN, which runs under DOS) it may be impossible to follow the
+standard memory location requirements.  Such a boot loader may use the
+following hooks that, if set, are invoked by the kernel at the
+appropriate time.  The use of these hooks should probably be
+considered an absolutely last resort!
+
+IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and
+%edi across invocation.
+
+  realmode_swtch:
+       A 16-bit real mode far subroutine invoked immediately before
+       entering protected mode.  The default routine disables NMI, so
+       your routine should probably do so, too.
+
+  code32_start:
+       A 32-bit flat-mode routine *jumped* to immediately after the
+       transition to protected mode, but before the kernel is
+       uncompressed.  No segments, except CS, are guaranteed to be
+       set up (current kernels do, but older ones do not); you should
+       set them up to BOOT_DS (0x18) yourself.
+
+       After completing your hook, you should jump to the address
+       that was in this field before your boot loader overwrote it
+       (relocated, if appropriate.)
+
+
+**** 32-bit BOOT PROTOCOL
+
+For machine with some new BIOS other than legacy BIOS, such as EFI,
+LinuxBIOS, etc, and kexec, the 16-bit real mode setup code in kernel
+based on legacy BIOS can not be used, so a 32-bit boot protocol needs
+to be defined.
+
+In 32-bit boot protocol, the first step in loading a Linux kernel
+should be to setup the boot parameters (struct boot_params,
+traditionally known as "zero page"). The memory for struct boot_params
+should be allocated and initialized to all zero. Then the setup header
+from offset 0x01f1 of kernel image on should be loaded into struct
+boot_params and examined. The end of setup header can be calculated as
+follow:
+
+       0x0202 + byte value at offset 0x0201
+
+In addition to read/modify/write the setup header of the struct
+boot_params as that of 16-bit boot protocol, the boot loader should
+also fill the additional fields of the struct boot_params as that
+described in zero-page.txt.
+
+After setupping the struct boot_params, the boot loader can load the
+32/64-bit kernel in the same way as that of 16-bit boot protocol.
+
+In 32-bit boot protocol, the kernel is started by jumping to the
+32-bit kernel entry point, which is the start address of loaded
+32/64-bit kernel.
+
+At entry, the CPU must be in 32-bit protected mode with paging
+disabled; a GDT must be loaded with the descriptors for selectors
+__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat
+segment; __BOOS_CS must have execute/read permission, and __BOOT_DS
+must have read/write permission; CS must be __BOOT_CS and DS, ES, SS
+must be __BOOT_DS; interrupt must be disabled; %esi must hold the base
+address of the struct boot_params; %ebp, %edi and %ebx must be zero.
diff --git a/Documentation/x86/i386/usb-legacy-support.txt b/Documentation/x86/i386/usb-legacy-support.txt
new file mode 100644 (file)
index 0000000..1894cdf
--- /dev/null
@@ -0,0 +1,44 @@
+USB Legacy support
+~~~~~~~~~~~~~~~~~~
+
+Vojtech Pavlik <vojtech@suse.cz>, January 2004
+
+
+Also known as "USB Keyboard" or "USB Mouse support" in the BIOS Setup is a
+feature that allows one to use the USB mouse and keyboard as if they were
+their classic PS/2 counterparts.  This means one can use an USB keyboard to
+type in LILO for example.
+
+It has several drawbacks, though:
+
+1) On some machines, the emulated PS/2 mouse takes over even when no USB
+   mouse is present and a real PS/2 mouse is present.  In that case the extra
+   features (wheel, extra buttons, touchpad mode) of the real PS/2 mouse may
+   not be available.
+
+2) If CONFIG_HIGHMEM64G is enabled, the PS/2 mouse emulation can cause
+   system crashes, because the SMM BIOS is not expecting to be in PAE mode.
+   The Intel E7505 is a typical machine where this happens.
+
+3) If AMD64 64-bit mode is enabled, again system crashes often happen,
+   because the SMM BIOS isn't expecting the CPU to be in 64-bit mode.  The
+   BIOS manufacturers only test with Windows, and Windows doesn't do 64-bit
+   yet.
+
+Solutions:
+
+Problem 1) can be solved by loading the USB drivers prior to loading the
+PS/2 mouse driver. Since the PS/2 mouse driver is in 2.6 compiled into
+the kernel unconditionally, this means the USB drivers need to be
+compiled-in, too.
+
+Problem 2) can currently only be solved by either disabling HIGHMEM64G
+in the kernel config or USB Legacy support in the BIOS. A BIOS update
+could help, but so far no such update exists.
+
+Problem 3) is usually fixed by a BIOS update. Check the board
+manufacturers web site. If an update is not available, disable USB
+Legacy support in the BIOS. If this alone doesn't help, try also adding
+idle=poll on the kernel command line. The BIOS may be entering the SMM
+on the HLT instruction as well.
+
diff --git a/Documentation/x86/i386/zero-page.txt b/Documentation/x86/i386/zero-page.txt
new file mode 100644 (file)
index 0000000..169ad42
--- /dev/null
@@ -0,0 +1,31 @@
+The additional fields in struct boot_params as a part of 32-bit boot
+protocol of kernel. These should be filled by bootloader or 16-bit
+real-mode setup code of the kernel. References/settings to it mainly
+are in:
+
+  include/asm-x86/bootparam.h
+
+
+Offset Proto   Name            Meaning
+/Size
+
+000/040        ALL     screen_info     Text mode or frame buffer information
+                               (struct screen_info)
+040/014        ALL     apm_bios_info   APM BIOS information (struct apm_bios_info)
+060/010        ALL     ist_info        Intel SpeedStep (IST) BIOS support information
+                               (struct ist_info)
+080/010        ALL     hd0_info        hd0 disk parameter, OBSOLETE!!
+090/010        ALL     hd1_info        hd1 disk parameter, OBSOLETE!!
+0A0/010        ALL     sys_desc_table  System description table (struct sys_desc_table)
+140/080        ALL     edid_info       Video mode setup (struct edid_info)
+1C0/020        ALL     efi_info        EFI 32 information (struct efi_info)
+1E0/004        ALL     alk_mem_k       Alternative mem check, in KB
+1E4/004        ALL     scratch         Scratch field for the kernel setup code
+1E8/001        ALL     e820_entries    Number of entries in e820_map (below)
+1E9/001        ALL     eddbuf_entries  Number of entries in eddbuf (below)
+1EA/001        ALL     edd_mbr_sig_buf_entries Number of entries in edd_mbr_sig_buffer
+                               (below)
+290/040        ALL     edd_mbr_sig_buffer EDD MBR signatures
+2D0/A00        ALL     e820_map        E820 memory map table
+                               (array of struct e820entry)
+D00/1EC        ALL     eddbuf          EDD data (array of struct edd_info)
diff --git a/Documentation/x86/x86_64/00-INDEX b/Documentation/x86/x86_64/00-INDEX
new file mode 100644 (file)
index 0000000..92fc20a
--- /dev/null
@@ -0,0 +1,16 @@
+00-INDEX
+       - This file
+boot-options.txt
+       - AMD64-specific boot options.
+cpu-hotplug-spec
+       - Firmware support for CPU hotplug under Linux/x86-64
+fake-numa-for-cpusets
+       - Using numa=fake and CPUSets for Resource Management
+kernel-stacks
+       - Context-specific per-processor interrupt stacks.
+machinecheck
+       - Configurable sysfs parameters for the x86-64 machine check code.
+mm.txt
+       - Memory layout of x86-64 (4 level page tables, 46 bits physical).
+uefi.txt
+       - Booting Linux via Unified Extensible Firmware Interface.
diff --git a/Documentation/x86/x86_64/boot-options.txt b/Documentation/x86/x86_64/boot-options.txt
new file mode 100644 (file)
index 0000000..b0c7b6c
--- /dev/null
@@ -0,0 +1,314 @@
+AMD64 specific boot options
+
+There are many others (usually documented in driver documentation), but
+only the AMD64 specific ones are listed here.
+
+Machine check
+
+   mce=off disable machine check
+   mce=bootlog Enable logging of machine checks left over from booting.
+               Disabled by default on AMD because some BIOS leave bogus ones.
+               If your BIOS doesn't do that it's a good idea to enable though
+               to make sure you log even machine check events that result
+               in a reboot. On Intel systems it is enabled by default.
+   mce=nobootlog
+               Disable boot machine check logging.
+   mce=tolerancelevel (number)
+               0: always panic on uncorrected errors, log corrected errors
+               1: panic or SIGBUS on uncorrected errors, log corrected errors
+               2: SIGBUS or log uncorrected errors, log corrected errors
+               3: never panic or SIGBUS, log all errors (for testing only)
+               Default is 1
+               Can be also set using sysfs which is preferable.
+
+   nomce (for compatibility with i386): same as mce=off
+
+   Everything else is in sysfs now.
+
+APICs
+
+   apic                 Use IO-APIC. Default
+
+   noapic       Don't use the IO-APIC.
+
+   disableapic  Don't use the local APIC
+
+   nolapic      Don't use the local APIC (alias for i386 compatibility)
+
+   pirq=...     See Documentation/i386/IO-APIC.txt
+
+   noapictimer  Don't set up the APIC timer
+
+   no_timer_check Don't check the IO-APIC timer. This can work around
+                problems with incorrect timer initialization on some boards.
+
+   apicmaintimer Run time keeping from the local APIC timer instead
+                 of using the PIT/HPET interrupt for this. This is useful
+                 when the PIT/HPET interrupts are unreliable.
+
+   noapicmaintimer  Don't do time keeping using the APIC timer.
+                Useful when this option was auto selected, but doesn't work.
+
+   apicpmtimer
+                Do APIC timer calibration using the pmtimer. Implies
+                apicmaintimer. Useful when your PIT timer is totally
+                broken.
+
+   disable_8254_timer / enable_8254_timer
+                Enable interrupt 0 timer routing over the 8254 in addition to over
+                the IO-APIC. The kernel tries to set a sensible default.
+
+Early Console
+
+   syntax: earlyprintk=vga
+           earlyprintk=serial[,ttySn[,baudrate]]
+
+   The early console is useful when the kernel crashes before the
+   normal console is initialized. It is not enabled by
+   default because it has some cosmetic problems.
+   Append ,keep to not disable it when the real console takes over.
+   Only vga or serial at a time, not both.
+   Currently only ttyS0 and ttyS1 are supported.
+   Interaction with the standard serial driver is not very good.
+   The VGA output is eventually overwritten by the real console.
+
+Timing
+
+  notsc
+  Don't use the CPU time stamp counter to read the wall time.
+  This can be used to work around timing problems on multiprocessor systems
+  with not properly synchronized CPUs.
+
+  report_lost_ticks
+  Report when timer interrupts are lost because some code turned off
+  interrupts for too long.
+
+  nmi_watchdog=NUMBER[,panic]
+  NUMBER can be:
+  0 don't use an NMI watchdog
+  1 use the IO-APIC timer for the NMI watchdog
+  2 use the local APIC for the NMI watchdog using a performance counter. Note
+  This will use one performance counter and the local APIC's performance
+  vector.
+  When panic is specified panic when an NMI watchdog timeout occurs.
+  This is useful when you use a panic=... timeout and need the box
+  quickly up again.
+
+  nohpet
+  Don't use the HPET timer.
+
+Idle loop
+
+  idle=poll
+  Don't do power saving in the idle loop using HLT, but poll for rescheduling
+  event. This will make the CPUs eat a lot more power, but may be useful
+  to get slightly better performance in multiprocessor benchmarks. It also
+  makes some profiling using performance counters more accurate.
+  Please note that on systems with MONITOR/MWAIT support (like Intel EM64T
+  CPUs) this option has no performance advantage over the normal idle loop.
+  It may also interact badly with hyperthreading.
+
+Rebooting
+
+   reboot=b[ios] | t[riple] | k[bd] | a[cpi] | e[fi] [, [w]arm | [c]old]
+   bios          Use the CPU reboot vector for warm reset
+   warm   Don't set the cold reboot flag
+   cold   Set the cold reboot flag
+   triple Force a triple fault (init)
+   kbd    Use the keyboard controller. cold reset (default)
+   acpi   Use the ACPI RESET_REG in the FADT. If ACPI is not configured or the
+          ACPI reset does not work, the reboot path attempts the reset using
+          the keyboard controller.
+   efi    Use efi reset_system runtime service. If EFI is not configured or the
+          EFI reset does not work, the reboot path attempts the reset using
+          the keyboard controller.
+
+   Using warm reset will be much faster especially on big memory
+   systems because the BIOS will not go through the memory check.
+   Disadvantage is that not all hardware will be completely reinitialized
+   on reboot so there may be boot problems on some systems.
+
+   reboot=force
+
+   Don't stop other CPUs on reboot. This can make reboot more reliable
+   in some cases.
+
+Non Executable Mappings
+
+  noexec=on|off
+
+  on      Enable(default)
+  off     Disable
+
+SMP
+
+  additional_cpus=NUM Allow NUM more CPUs for hotplug
+                (defaults are specified by the BIOS, see Documentation/x86_64/cpu-hotplug-spec)
+
+NUMA
+
+  numa=off     Only set up a single NUMA node spanning all memory.
+
+  numa=noacpi   Don't parse the SRAT table for NUMA setup
+
+  numa=fake=CMDLINE
+               If a number, fakes CMDLINE nodes and ignores NUMA setup of the
+               actual machine.  Otherwise, system memory is configured
+               depending on the sizes and coefficients listed.  For example:
+                       numa=fake=2*512,1024,4*256,*128
+               gives two 512M nodes, a 1024M node, four 256M nodes, and the
+               rest split into 128M chunks.  If the last character of CMDLINE
+               is a *, the remaining memory is divided up equally among its
+               coefficient:
+                       numa=fake=2*512,2*
+               gives two 512M nodes and the rest split into two nodes.
+               Otherwise, the remaining system RAM is allocated to an
+               additional node.
+
+  numa=hotadd=percent
+               Only allow hotadd memory to preallocate page structures upto
+               percent of already available memory.
+               numa=hotadd=0 will disable hotadd memory.
+
+ACPI
+
+  acpi=off     Don't enable ACPI
+  acpi=ht      Use ACPI boot table parsing, but don't enable ACPI
+               interpreter
+  acpi=force   Force ACPI on (currently not needed)
+
+  acpi=strict   Disable out of spec ACPI workarounds.
+
+  acpi_sci={edge,level,high,low}  Set up ACPI SCI interrupt.
+
+  acpi=noirq   Don't route interrupts
+
+PCI
+
+  pci=off      Don't use PCI
+  pci=conf1    Use conf1 access.
+  pci=conf2    Use conf2 access.
+  pci=rom      Assign ROMs.
+  pci=assign-busses    Assign busses
+  pci=irqmask=MASK            Set PCI interrupt mask to MASK
+  pci=lastbus=NUMBER          Scan upto NUMBER busses, no matter what the mptable says.
+  pci=noacpi           Don't use ACPI to set up PCI interrupt routing.
+
+IOMMU (input/output memory management unit)
+
+ Currently four x86-64 PCI-DMA mapping implementations exist:
+
+   1. <arch/x86_64/kernel/pci-nommu.c>: use no hardware/software IOMMU at all
+      (e.g. because you have < 3 GB memory).
+      Kernel boot message: "PCI-DMA: Disabling IOMMU"
+
+   2. <arch/x86_64/kernel/pci-gart.c>: AMD GART based hardware IOMMU.
+      Kernel boot message: "PCI-DMA: using GART IOMMU"
+
+   3. <arch/x86_64/kernel/pci-swiotlb.c> : Software IOMMU implementation. Used
+      e.g. if there is no hardware IOMMU in the system and it is need because
+      you have >3GB memory or told the kernel to us it (iommu=soft))
+      Kernel boot message: "PCI-DMA: Using software bounce buffering
+      for IO (SWIOTLB)"
+
+   4. <arch/x86_64/pci-calgary.c> : IBM Calgary hardware IOMMU. Used in IBM
+      pSeries and xSeries servers. This hardware IOMMU supports DMA address
+      mapping with memory protection, etc.
+      Kernel boot message: "PCI-DMA: Using Calgary IOMMU"
+
+ iommu=[<size>][,noagp][,off][,force][,noforce][,leak[=<nr_of_leak_pages>]
+       [,memaper[=<order>]][,merge][,forcesac][,fullflush][,nomerge]
+       [,noaperture][,calgary]
+
+  General iommu options:
+    off                Don't initialize and use any kind of IOMMU.
+    noforce            Don't force hardware IOMMU usage when it is not needed.
+                       (default).
+    force              Force the use of the hardware IOMMU even when it is
+                       not actually needed (e.g. because < 3 GB memory).
+    soft               Use software bounce buffering (SWIOTLB) (default for
+                       Intel machines). This can be used to prevent the usage
+                       of an available hardware IOMMU.
+
+  iommu options only relevant to the AMD GART hardware IOMMU:
+    <size>             Set the size of the remapping area in bytes.
+    allowed            Overwrite iommu off workarounds for specific chipsets.
+    fullflush          Flush IOMMU on each allocation (default).
+    nofullflush        Don't use IOMMU fullflush.
+    leak               Turn on simple iommu leak tracing (only when
+                       CONFIG_IOMMU_LEAK is on). Default number of leak pages
+                       is 20.
+    memaper[=<order>]  Allocate an own aperture over RAM with size 32MB<<order.
+                       (default: order=1, i.e. 64MB)
+    merge              Do scatter-gather (SG) merging. Implies "force"
+                       (experimental).
+    nomerge            Don't do scatter-gather (SG) merging.
+    noaperture         Ask the IOMMU not to touch the aperture for AGP.
+    forcesac           Force single-address cycle (SAC) mode for masks <40bits
+                       (experimental).
+    noagp              Don't initialize the AGP driver and use full aperture.
+    allowdac           Allow double-address cycle (DAC) mode, i.e. DMA >4GB.
+                       DAC is used with 32-bit PCI to push a 64-bit address in
+                       two cycles. When off all DMA over >4GB is forced through
+                       an IOMMU or software bounce buffering.
+    nodac              Forbid DAC mode, i.e. DMA >4GB.
+    panic              Always panic when IOMMU overflows.
+    calgary            Use the Calgary IOMMU if it is available
+
+  iommu options only relevant to the software bounce buffering (SWIOTLB) IOMMU
+  implementation:
+    swiotlb=<pages>[,force]
+    <pages>            Prereserve that many 128K pages for the software IO
+                       bounce buffering.
+    force              Force all IO through the software TLB.
+
+  Settings for the IBM Calgary hardware IOMMU currently found in IBM
+  pSeries and xSeries machines:
+
+    calgary=[64k,128k,256k,512k,1M,2M,4M,8M]
+    calgary=[translate_empty_slots]
+    calgary=[disable=<PCI bus number>]
+    panic              Always panic when IOMMU overflows
+
+    64k,...,8M - Set the size of each PCI slot's translation table
+    when using the Calgary IOMMU. This is the size of the translation
+    table itself in main memory. The smallest table, 64k, covers an IO
+    space of 32MB; the largest, 8MB table, can cover an IO space of
+    4GB. Normally the kernel will make the right choice by itself.
+
+    translate_empty_slots - Enable translation even on slots that have
+    no devices attached to them, in case a device will be hotplugged
+    in the future.
+
+    disable=<PCI bus number> - Disable translation on a given PHB. For
+    example, the built-in graphics adapter resides on the first bridge
+    (PCI bus number 0); if translation (isolation) is enabled on this
+    bridge, X servers that access the hardware directly from user
+    space might stop working. Use this option if you have devices that
+    are accessed from userspace directly on some PCI host bridge.
+
+Debugging
+
+  oops=panic   Always panic on oopses. Default is to just kill the process,
+               but there is a small probability of deadlocking the machine.
+               This will also cause panics on machine check exceptions.
+               Useful together with panic=30 to trigger a reboot.
+
+  kstack=N     Print N words from the kernel stack in oops dumps.
+
+  pagefaulttrace  Dump all page faults. Only useful for extreme debugging
+               and will create a lot of output.
+
+  call_trace=[old|both|newfallback|new]
+               old: use old inexact backtracer
+               new: use new exact dwarf2 unwinder
+               both: print entries from both
+               newfallback: use new unwinder but fall back to old if it gets
+                       stuck (default)
+
+Miscellaneous
+
+       nogbpages
+               Do not use GB pages for kernel direct mappings.
+       gbpages
+               Use GB pages for kernel direct mappings.
diff --git a/Documentation/x86/x86_64/cpu-hotplug-spec b/Documentation/x86/x86_64/cpu-hotplug-spec
new file mode 100644 (file)
index 0000000..3c23e05
--- /dev/null
@@ -0,0 +1,21 @@
+Firmware support for CPU hotplug under Linux/x86-64
+---------------------------------------------------
+
+Linux/x86-64 supports CPU hotplug now. For various reasons Linux wants to
+know in advance of boot time the maximum number of CPUs that could be plugged
+into the system. ACPI 3.0 currently has no official way to supply
+this information from the firmware to the operating system.
+
+In ACPI each CPU needs an LAPIC object in the MADT table (5.2.11.5 in the
+ACPI 3.0 specification).  ACPI already has the concept of disabled LAPIC
+objects by setting the Enabled bit in the LAPIC object to zero.
+
+For CPU hotplug Linux/x86-64 expects now that any possible future hotpluggable
+CPU is already available in the MADT. If the CPU is not available yet
+it should have its LAPIC Enabled bit set to 0. Linux will use the number
+of disabled LAPICs to compute the maximum number of future CPUs.
+
+In the worst case the user can overwrite this choice using a command line
+option (additional_cpus=...), but it is recommended to supply the correct
+number (or a reasonable approximation of it, with erring towards more not less)
+in the MADT to avoid manual configuration.
diff --git a/Documentation/x86/x86_64/fake-numa-for-cpusets b/Documentation/x86/x86_64/fake-numa-for-cpusets
new file mode 100644 (file)
index 0000000..d1a985c
--- /dev/null
@@ -0,0 +1,66 @@
+Using numa=fake and CPUSets for Resource Management
+Written by David Rientjes <rientjes@cs.washington.edu>
+
+This document describes how the numa=fake x86_64 command-line option can be used
+in conjunction with cpusets for coarse memory management.  Using this feature,
+you can create fake NUMA nodes that represent contiguous chunks of memory and
+assign them to cpusets and their attached tasks.  This is a way of limiting the
+amount of system memory that are available to a certain class of tasks.
+
+For more information on the features of cpusets, see Documentation/cpusets.txt.
+There are a number of different configurations you can use for your needs.  For
+more information on the numa=fake command line option and its various ways of
+configuring fake nodes, see Documentation/x86_64/boot-options.txt.
+
+For the purposes of this introduction, we'll assume a very primitive NUMA
+emulation setup of "numa=fake=4*512,".  This will split our system memory into
+four equal chunks of 512M each that we can now use to assign to cpusets.  As
+you become more familiar with using this combination for resource control,
+you'll determine a better setup to minimize the number of nodes you have to deal
+with.
+
+A machine may be split as follows with "numa=fake=4*512," as reported by dmesg:
+
+       Faking node 0 at 0000000000000000-0000000020000000 (512MB)
+       Faking node 1 at 0000000020000000-0000000040000000 (512MB)
+       Faking node 2 at 0000000040000000-0000000060000000 (512MB)
+       Faking node 3 at 0000000060000000-0000000080000000 (512MB)
+       ...
+       On node 0 totalpages: 130975
+       On node 1 totalpages: 131072
+       On node 2 totalpages: 131072
+       On node 3 totalpages: 131072
+
+Now following the instructions for mounting the cpusets filesystem from
+Documentation/cpusets.txt, you can assign fake nodes (i.e. contiguous memory
+address spaces) to individual cpusets:
+
+       [root@xroads /]# mkdir exampleset
+       [root@xroads /]# mount -t cpuset none exampleset
+       [root@xroads /]# mkdir exampleset/ddset
+       [root@xroads /]# cd exampleset/ddset
+       [root@xroads /exampleset/ddset]# echo 0-1 > cpus
+       [root@xroads /exampleset/ddset]# echo 0-1 > mems
+
+Now this cpuset, 'ddset', will only allowed access to fake nodes 0 and 1 for
+memory allocations (1G).
+
+You can now assign tasks to these cpusets to limit the memory resources
+available to them according to the fake nodes assigned as mems:
+
+       [root@xroads /exampleset/ddset]# echo $$ > tasks
+       [root@xroads /exampleset/ddset]# dd if=/dev/zero of=tmp bs=1024 count=1G
+       [1] 13425
+
+Notice the difference between the system memory usage as reported by
+/proc/meminfo between the restricted cpuset case above and the unrestricted
+case (i.e. running the same 'dd' command without assigning it to a fake NUMA
+cpuset):
+                               Unrestricted    Restricted
+       MemTotal:               3091900 kB      3091900 kB
+       MemFree:                  42113 kB      1513236 kB
+
+This allows for coarse memory management for the tasks you assign to particular
+cpusets.  Since cpusets can form a hierarchy, you can create some pretty
+interesting combinations of use-cases for various classes of tasks for your
+memory management needs.
diff --git a/Documentation/x86/x86_64/kernel-stacks b/Documentation/x86/x86_64/kernel-stacks
new file mode 100644 (file)
index 0000000..5ad65d5
--- /dev/null
@@ -0,0 +1,99 @@
+Most of the text from Keith Owens, hacked by AK
+
+x86_64 page size (PAGE_SIZE) is 4K.
+
+Like all other architectures, x86_64 has a kernel stack for every
+active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
+These stacks contain useful data as long as a thread is alive or a
+zombie. While the thread is in user space the kernel stack is empty
+except for the thread_info structure at the bottom.
+
+In addition to the per thread stacks, there are specialized stacks
+associated with each CPU.  These stacks are only used while the kernel
+is in control on that CPU; when a CPU returns to user space the
+specialized stacks contain no useful data.  The main CPU stacks are:
+
+* Interrupt stack.  IRQSTACKSIZE
+
+  Used for external hardware interrupts.  If this is the first external
+  hardware interrupt (i.e. not a nested hardware interrupt) then the
+  kernel switches from the current task to the interrupt stack.  Like
+  the split thread and interrupt stacks on i386 (with CONFIG_4KSTACKS),
+  this gives more room for kernel interrupt processing without having
+  to increase the size of every per thread stack.
+
+  The interrupt stack is also used when processing a softirq.
+
+Switching to the kernel interrupt stack is done by software based on a
+per CPU interrupt nest counter. This is needed because x86-64 "IST"
+hardware stacks cannot nest without races.
+
+x86_64 also has a feature which is not available on i386, the ability
+to automatically switch to a new stack for designated events such as
+double fault or NMI, which makes it easier to handle these unusual
+events on x86_64.  This feature is called the Interrupt Stack Table
+(IST).  There can be up to 7 IST entries per CPU. The IST code is an
+index into the Task State Segment (TSS). The IST entries in the TSS
+point to dedicated stacks; each stack can be a different size.
+
+An IST is selected by a non-zero value in the IST field of an
+interrupt-gate descriptor.  When an interrupt occurs and the hardware
+loads such a descriptor, the hardware automatically sets the new stack
+pointer based on the IST value, then invokes the interrupt handler.  If
+software wants to allow nested IST interrupts then the handler must
+adjust the IST values on entry to and exit from the interrupt handler.
+(This is occasionally done, e.g. for debug exceptions.)
+
+Events with different IST codes (i.e. with different stacks) can be
+nested.  For example, a debug interrupt can safely be interrupted by an
+NMI.  arch/x86_64/kernel/entry.S::paranoidentry adjusts the stack
+pointers on entry to and exit from all IST events, in theory allowing
+IST events with the same code to be nested.  However in most cases, the
+stack size allocated to an IST assumes no nesting for the same code.
+If that assumption is ever broken then the stacks will become corrupt.
+
+The currently assigned IST stacks are :-
+
+* STACKFAULT_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
+
+  Used for interrupt 12 - Stack Fault Exception (#SS).
+
+  This allows the CPU to recover from invalid stack segments. Rarely
+  happens.
+
+* DOUBLEFAULT_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
+
+  Used for interrupt 8 - Double Fault Exception (#DF).
+
+  Invoked when handling one exception causes another exception. Happens
+  when the kernel is very confused (e.g. kernel stack pointer corrupt).
+  Using a separate stack allows the kernel to recover from it well enough
+  in many cases to still output an oops.
+
+* NMI_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
+
+  Used for non-maskable interrupts (NMI).
+
+  NMI can be delivered at any time, including when the kernel is in the
+  middle of switching stacks.  Using IST for NMI events avoids making
+  assumptions about the previous state of the kernel stack.
+
+* DEBUG_STACK.  DEBUG_STKSZ
+
+  Used for hardware debug interrupts (interrupt 1) and for software
+  debug interrupts (INT3).
+
+  When debugging a kernel, debug interrupts (both hardware and
+  software) can occur at any time.  Using IST for these interrupts
+  avoids making assumptions about the previous state of the kernel
+  stack.
+
+* MCE_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
+
+  Used for interrupt 18 - Machine Check Exception (#MC).
+
+  MCE can be delivered at any time, including when the kernel is in the
+  middle of switching stacks.  Using IST for MCE events avoids making
+  assumptions about the previous state of the kernel stack.
+
+For more details see the Intel IA32 or AMD AMD64 architecture manuals.
diff --git a/Documentation/x86/x86_64/machinecheck b/Documentation/x86/x86_64/machinecheck
new file mode 100644 (file)
index 0000000..a05e58e
--- /dev/null
@@ -0,0 +1,77 @@
+
+Configurable sysfs parameters for the x86-64 machine check code.
+
+Machine checks report internal hardware error conditions detected
+by the CPU. Uncorrected errors typically cause a machine check
+(often with panic), corrected ones cause a machine check log entry.
+
+Machine checks are organized in banks (normally associated with
+a hardware subsystem) and subevents in a bank. The exact meaning
+of the banks and subevent is CPU specific.
+
+mcelog knows how to decode them.
+
+When you see the "Machine check errors logged" message in the system
+log then mcelog should run to collect and decode machine check entries
+from /dev/mcelog. Normally mcelog should be run regularly from a cronjob.
+
+Each CPU has a directory in /sys/devices/system/machinecheck/machinecheckN
+(N = CPU number)
+
+The directory contains some configurable entries:
+
+Entries:
+
+bankNctl
+(N bank number)
+       64bit Hex bitmask enabling/disabling specific subevents for bank N
+       When a bit in the bitmask is zero then the respective
+       subevent will not be reported.
+       By default all events are enabled.
+       Note that BIOS maintain another mask to disable specific events
+       per bank.  This is not visible here
+
+The following entries appear for each CPU, but they are truly shared
+between all CPUs.
+
+check_interval
+       How often to poll for corrected machine check errors, in seconds
+       (Note output is hexademical). Default 5 minutes.  When the poller
+       finds MCEs it triggers an exponential speedup (poll more often) on
+       the polling interval.  When the poller stops finding MCEs, it
+       triggers an exponential backoff (poll less often) on the polling
+       interval. The check_interval variable is both the initial and
+       maximum polling interval.
+
+tolerant
+       Tolerance level. When a machine check exception occurs for a non
+       corrected machine check the kernel can take different actions.
+       Since machine check exceptions can happen any time it is sometimes
+       risky for the kernel to kill a process because it defies
+       normal kernel locking rules. The tolerance level configures
+       how hard the kernel tries to recover even at some risk of
+       deadlock.  Higher tolerant values trade potentially better uptime
+       with the risk of a crash or even corruption (for tolerant >= 3).
+
+       0: always panic on uncorrected errors, log corrected errors
+       1: panic or SIGBUS on uncorrected errors, log corrected errors
+       2: SIGBUS or log uncorrected errors, log corrected errors
+       3: never panic or SIGBUS, log all errors (for testing only)
+
+       Default: 1
+
+       Note this only makes a difference if the CPU allows recovery
+       from a machine check exception. Current x86 CPUs generally do not.
+
+trigger
+       Program to run when a machine check event is detected.
+       This is an alternative to running mcelog regularly from cron
+       and allows to detect events faster.
+
+TBD document entries for AMD threshold interrupt configuration
+
+For more details about the x86 machine check architecture
+see the Intel and AMD architecture manuals from their developer websites.
+
+For more details about the architecture see
+see http://one.firstfloor.org/~andi/mce.pdf
diff --git a/Documentation/x86/x86_64/mm.txt b/Documentation/x86/x86_64/mm.txt
new file mode 100644 (file)
index 0000000..efce750
--- /dev/null
@@ -0,0 +1,28 @@
+
+<previous description obsolete, deleted>
+
+Virtual memory map with 4 level page tables:
+
+0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm
+hole caused by [48:63] sign extension
+ffff800000000000 - ffff80ffffffffff (=40 bits) guard hole
+ffff810000000000 - ffffc0ffffffffff (=46 bits) direct mapping of all phys. memory
+ffffc10000000000 - ffffc1ffffffffff (=40 bits) hole
+ffffc20000000000 - ffffe1ffffffffff (=45 bits) vmalloc/ioremap space
+ffffe20000000000 - ffffe2ffffffffff (=40 bits) virtual memory map (1TB)
+... unused hole ...
+ffffffff80000000 - ffffffffa0000000 (=512 MB)  kernel text mapping, from phys 0
+ffffffffa0000000 - fffffffffff00000 (=1536 MB) module mapping space
+
+The direct mapping covers all memory in the system up to the highest
+memory address (this means in some cases it can also include PCI memory
+holes).
+
+vmalloc space is lazily synchronized into the different PML4 pages of
+the processes using the page fault handler, with init_level4_pgt as
+reference.
+
+Current X86-64 implementations only support 40 bits of address space,
+but we support up to 46 bits. This expands into MBZ space in the page tables.
+
+-Andi Kleen, Jul 2004
diff --git a/Documentation/x86/x86_64/uefi.txt b/Documentation/x86/x86_64/uefi.txt
new file mode 100644 (file)
index 0000000..a5e2b4f
--- /dev/null
@@ -0,0 +1,42 @@
+General note on [U]EFI x86_64 support
+-------------------------------------
+
+The nomenclature EFI and UEFI are used interchangeably in this document.
+
+Although the tools below are _not_ needed for building the kernel,
+the needed bootloader support and associated tools for x86_64 platforms
+with EFI firmware and specifications are listed below.
+
+1. UEFI specification:  http://www.uefi.org
+
+2. Booting Linux kernel on UEFI x86_64 platform requires bootloader
+   support. Elilo with x86_64 support can be used.
+
+3. x86_64 platform with EFI/UEFI firmware.
+
+Mechanics:
+---------
+- Build the kernel with the following configuration.
+       CONFIG_FB_EFI=y
+       CONFIG_FRAMEBUFFER_CONSOLE=y
+  If EFI runtime services are expected, the following configuration should
+  be selected.
+       CONFIG_EFI=y
+       CONFIG_EFI_VARS=y or m          # optional
+- Create a VFAT partition on the disk
+- Copy the following to the VFAT partition:
+       elilo bootloader with x86_64 support, elilo configuration file,
+       kernel image built in first step and corresponding
+       initrd. Instructions on building elilo  and its dependencies
+       can be found in the elilo sourceforge project.
+- Boot to EFI shell and invoke elilo choosing the kernel image built
+  in first step.
+- If some or all EFI runtime services don't work, you can try following
+  kernel command line parameters to turn off some or all EFI runtime
+  services.
+       noefi           turn off all EFI runtime services
+       reboot_type=k   turn off EFI reboot runtime service
+- If the EFI memory map has additional entries not in the E820 map,
+  you can include those entries in the kernels memory map of available
+  physical RAM by using the following kernel command line parameter.
+       add_efi_memmap  include EFI memory map of available physical RAM
diff --git a/Documentation/x86_64/00-INDEX b/Documentation/x86_64/00-INDEX
deleted file mode 100644 (file)
index 92fc20a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-00-INDEX
-       - This file
-boot-options.txt
-       - AMD64-specific boot options.
-cpu-hotplug-spec
-       - Firmware support for CPU hotplug under Linux/x86-64
-fake-numa-for-cpusets
-       - Using numa=fake and CPUSets for Resource Management
-kernel-stacks
-       - Context-specific per-processor interrupt stacks.
-machinecheck
-       - Configurable sysfs parameters for the x86-64 machine check code.
-mm.txt
-       - Memory layout of x86-64 (4 level page tables, 46 bits physical).
-uefi.txt
-       - Booting Linux via Unified Extensible Firmware Interface.
diff --git a/Documentation/x86_64/boot-options.txt b/Documentation/x86_64/boot-options.txt
deleted file mode 100644 (file)
index b0c7b6c..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-AMD64 specific boot options
-
-There are many others (usually documented in driver documentation), but
-only the AMD64 specific ones are listed here.
-
-Machine check
-
-   mce=off disable machine check
-   mce=bootlog Enable logging of machine checks left over from booting.
-               Disabled by default on AMD because some BIOS leave bogus ones.
-               If your BIOS doesn't do that it's a good idea to enable though
-               to make sure you log even machine check events that result
-               in a reboot. On Intel systems it is enabled by default.
-   mce=nobootlog
-               Disable boot machine check logging.
-   mce=tolerancelevel (number)
-               0: always panic on uncorrected errors, log corrected errors
-               1: panic or SIGBUS on uncorrected errors, log corrected errors
-               2: SIGBUS or log uncorrected errors, log corrected errors
-               3: never panic or SIGBUS, log all errors (for testing only)
-               Default is 1
-               Can be also set using sysfs which is preferable.
-
-   nomce (for compatibility with i386): same as mce=off
-
-   Everything else is in sysfs now.
-
-APICs
-
-   apic                 Use IO-APIC. Default
-
-   noapic       Don't use the IO-APIC.
-
-   disableapic  Don't use the local APIC
-
-   nolapic      Don't use the local APIC (alias for i386 compatibility)
-
-   pirq=...     See Documentation/i386/IO-APIC.txt
-
-   noapictimer  Don't set up the APIC timer
-
-   no_timer_check Don't check the IO-APIC timer. This can work around
-                problems with incorrect timer initialization on some boards.
-
-   apicmaintimer Run time keeping from the local APIC timer instead
-                 of using the PIT/HPET interrupt for this. This is useful
-                 when the PIT/HPET interrupts are unreliable.
-
-   noapicmaintimer  Don't do time keeping using the APIC timer.
-                Useful when this option was auto selected, but doesn't work.
-
-   apicpmtimer
-                Do APIC timer calibration using the pmtimer. Implies
-                apicmaintimer. Useful when your PIT timer is totally
-                broken.
-
-   disable_8254_timer / enable_8254_timer
-                Enable interrupt 0 timer routing over the 8254 in addition to over
-                the IO-APIC. The kernel tries to set a sensible default.
-
-Early Console
-
-   syntax: earlyprintk=vga
-           earlyprintk=serial[,ttySn[,baudrate]]
-
-   The early console is useful when the kernel crashes before the
-   normal console is initialized. It is not enabled by
-   default because it has some cosmetic problems.
-   Append ,keep to not disable it when the real console takes over.
-   Only vga or serial at a time, not both.
-   Currently only ttyS0 and ttyS1 are supported.
-   Interaction with the standard serial driver is not very good.
-   The VGA output is eventually overwritten by the real console.
-
-Timing
-
-  notsc
-  Don't use the CPU time stamp counter to read the wall time.
-  This can be used to work around timing problems on multiprocessor systems
-  with not properly synchronized CPUs.
-
-  report_lost_ticks
-  Report when timer interrupts are lost because some code turned off
-  interrupts for too long.
-
-  nmi_watchdog=NUMBER[,panic]
-  NUMBER can be:
-  0 don't use an NMI watchdog
-  1 use the IO-APIC timer for the NMI watchdog
-  2 use the local APIC for the NMI watchdog using a performance counter. Note
-  This will use one performance counter and the local APIC's performance
-  vector.
-  When panic is specified panic when an NMI watchdog timeout occurs.
-  This is useful when you use a panic=... timeout and need the box
-  quickly up again.
-
-  nohpet
-  Don't use the HPET timer.
-
-Idle loop
-
-  idle=poll
-  Don't do power saving in the idle loop using HLT, but poll for rescheduling
-  event. This will make the CPUs eat a lot more power, but may be useful
-  to get slightly better performance in multiprocessor benchmarks. It also
-  makes some profiling using performance counters more accurate.
-  Please note that on systems with MONITOR/MWAIT support (like Intel EM64T
-  CPUs) this option has no performance advantage over the normal idle loop.
-  It may also interact badly with hyperthreading.
-
-Rebooting
-
-   reboot=b[ios] | t[riple] | k[bd] | a[cpi] | e[fi] [, [w]arm | [c]old]
-   bios          Use the CPU reboot vector for warm reset
-   warm   Don't set the cold reboot flag
-   cold   Set the cold reboot flag
-   triple Force a triple fault (init)
-   kbd    Use the keyboard controller. cold reset (default)
-   acpi   Use the ACPI RESET_REG in the FADT. If ACPI is not configured or the
-          ACPI reset does not work, the reboot path attempts the reset using
-          the keyboard controller.
-   efi    Use efi reset_system runtime service. If EFI is not configured or the
-          EFI reset does not work, the reboot path attempts the reset using
-          the keyboard controller.
-
-   Using warm reset will be much faster especially on big memory
-   systems because the BIOS will not go through the memory check.
-   Disadvantage is that not all hardware will be completely reinitialized
-   on reboot so there may be boot problems on some systems.
-
-   reboot=force
-
-   Don't stop other CPUs on reboot. This can make reboot more reliable
-   in some cases.
-
-Non Executable Mappings
-
-  noexec=on|off
-
-  on      Enable(default)
-  off     Disable
-
-SMP
-
-  additional_cpus=NUM Allow NUM more CPUs for hotplug
-                (defaults are specified by the BIOS, see Documentation/x86_64/cpu-hotplug-spec)
-
-NUMA
-
-  numa=off     Only set up a single NUMA node spanning all memory.
-
-  numa=noacpi   Don't parse the SRAT table for NUMA setup
-
-  numa=fake=CMDLINE
-               If a number, fakes CMDLINE nodes and ignores NUMA setup of the
-               actual machine.  Otherwise, system memory is configured
-               depending on the sizes and coefficients listed.  For example:
-                       numa=fake=2*512,1024,4*256,*128
-               gives two 512M nodes, a 1024M node, four 256M nodes, and the
-               rest split into 128M chunks.  If the last character of CMDLINE
-               is a *, the remaining memory is divided up equally among its
-               coefficient:
-                       numa=fake=2*512,2*
-               gives two 512M nodes and the rest split into two nodes.
-               Otherwise, the remaining system RAM is allocated to an
-               additional node.
-
-  numa=hotadd=percent
-               Only allow hotadd memory to preallocate page structures upto
-               percent of already available memory.
-               numa=hotadd=0 will disable hotadd memory.
-
-ACPI
-
-  acpi=off     Don't enable ACPI
-  acpi=ht      Use ACPI boot table parsing, but don't enable ACPI
-               interpreter
-  acpi=force   Force ACPI on (currently not needed)
-
-  acpi=strict   Disable out of spec ACPI workarounds.
-
-  acpi_sci={edge,level,high,low}  Set up ACPI SCI interrupt.
-
-  acpi=noirq   Don't route interrupts
-
-PCI
-
-  pci=off      Don't use PCI
-  pci=conf1    Use conf1 access.
-  pci=conf2    Use conf2 access.
-  pci=rom      Assign ROMs.
-  pci=assign-busses    Assign busses
-  pci=irqmask=MASK            Set PCI interrupt mask to MASK
-  pci=lastbus=NUMBER          Scan upto NUMBER busses, no matter what the mptable says.
-  pci=noacpi           Don't use ACPI to set up PCI interrupt routing.
-
-IOMMU (input/output memory management unit)
-
- Currently four x86-64 PCI-DMA mapping implementations exist:
-
-   1. <arch/x86_64/kernel/pci-nommu.c>: use no hardware/software IOMMU at all
-      (e.g. because you have < 3 GB memory).
-      Kernel boot message: "PCI-DMA: Disabling IOMMU"
-
-   2. <arch/x86_64/kernel/pci-gart.c>: AMD GART based hardware IOMMU.
-      Kernel boot message: "PCI-DMA: using GART IOMMU"
-
-   3. <arch/x86_64/kernel/pci-swiotlb.c> : Software IOMMU implementation. Used
-      e.g. if there is no hardware IOMMU in the system and it is need because
-      you have >3GB memory or told the kernel to us it (iommu=soft))
-      Kernel boot message: "PCI-DMA: Using software bounce buffering
-      for IO (SWIOTLB)"
-
-   4. <arch/x86_64/pci-calgary.c> : IBM Calgary hardware IOMMU. Used in IBM
-      pSeries and xSeries servers. This hardware IOMMU supports DMA address
-      mapping with memory protection, etc.
-      Kernel boot message: "PCI-DMA: Using Calgary IOMMU"
-
- iommu=[<size>][,noagp][,off][,force][,noforce][,leak[=<nr_of_leak_pages>]
-       [,memaper[=<order>]][,merge][,forcesac][,fullflush][,nomerge]
-       [,noaperture][,calgary]
-
-  General iommu options:
-    off                Don't initialize and use any kind of IOMMU.
-    noforce            Don't force hardware IOMMU usage when it is not needed.
-                       (default).
-    force              Force the use of the hardware IOMMU even when it is
-                       not actually needed (e.g. because < 3 GB memory).
-    soft               Use software bounce buffering (SWIOTLB) (default for
-                       Intel machines). This can be used to prevent the usage
-                       of an available hardware IOMMU.
-
-  iommu options only relevant to the AMD GART hardware IOMMU:
-    <size>             Set the size of the remapping area in bytes.
-    allowed            Overwrite iommu off workarounds for specific chipsets.
-    fullflush          Flush IOMMU on each allocation (default).
-    nofullflush        Don't use IOMMU fullflush.
-    leak               Turn on simple iommu leak tracing (only when
-                       CONFIG_IOMMU_LEAK is on). Default number of leak pages
-                       is 20.
-    memaper[=<order>]  Allocate an own aperture over RAM with size 32MB<<order.
-                       (default: order=1, i.e. 64MB)
-    merge              Do scatter-gather (SG) merging. Implies "force"
-                       (experimental).
-    nomerge            Don't do scatter-gather (SG) merging.
-    noaperture         Ask the IOMMU not to touch the aperture for AGP.
-    forcesac           Force single-address cycle (SAC) mode for masks <40bits
-                       (experimental).
-    noagp              Don't initialize the AGP driver and use full aperture.
-    allowdac           Allow double-address cycle (DAC) mode, i.e. DMA >4GB.
-                       DAC is used with 32-bit PCI to push a 64-bit address in
-                       two cycles. When off all DMA over >4GB is forced through
-                       an IOMMU or software bounce buffering.
-    nodac              Forbid DAC mode, i.e. DMA >4GB.
-    panic              Always panic when IOMMU overflows.
-    calgary            Use the Calgary IOMMU if it is available
-
-  iommu options only relevant to the software bounce buffering (SWIOTLB) IOMMU
-  implementation:
-    swiotlb=<pages>[,force]
-    <pages>            Prereserve that many 128K pages for the software IO
-                       bounce buffering.
-    force              Force all IO through the software TLB.
-
-  Settings for the IBM Calgary hardware IOMMU currently found in IBM
-  pSeries and xSeries machines:
-
-    calgary=[64k,128k,256k,512k,1M,2M,4M,8M]
-    calgary=[translate_empty_slots]
-    calgary=[disable=<PCI bus number>]
-    panic              Always panic when IOMMU overflows
-
-    64k,...,8M - Set the size of each PCI slot's translation table
-    when using the Calgary IOMMU. This is the size of the translation
-    table itself in main memory. The smallest table, 64k, covers an IO
-    space of 32MB; the largest, 8MB table, can cover an IO space of
-    4GB. Normally the kernel will make the right choice by itself.
-
-    translate_empty_slots - Enable translation even on slots that have
-    no devices attached to them, in case a device will be hotplugged
-    in the future.
-
-    disable=<PCI bus number> - Disable translation on a given PHB. For
-    example, the built-in graphics adapter resides on the first bridge
-    (PCI bus number 0); if translation (isolation) is enabled on this
-    bridge, X servers that access the hardware directly from user
-    space might stop working. Use this option if you have devices that
-    are accessed from userspace directly on some PCI host bridge.
-
-Debugging
-
-  oops=panic   Always panic on oopses. Default is to just kill the process,
-               but there is a small probability of deadlocking the machine.
-               This will also cause panics on machine check exceptions.
-               Useful together with panic=30 to trigger a reboot.
-
-  kstack=N     Print N words from the kernel stack in oops dumps.
-
-  pagefaulttrace  Dump all page faults. Only useful for extreme debugging
-               and will create a lot of output.
-
-  call_trace=[old|both|newfallback|new]
-               old: use old inexact backtracer
-               new: use new exact dwarf2 unwinder
-               both: print entries from both
-               newfallback: use new unwinder but fall back to old if it gets
-                       stuck (default)
-
-Miscellaneous
-
-       nogbpages
-               Do not use GB pages for kernel direct mappings.
-       gbpages
-               Use GB pages for kernel direct mappings.
diff --git a/Documentation/x86_64/cpu-hotplug-spec b/Documentation/x86_64/cpu-hotplug-spec
deleted file mode 100644 (file)
index 3c23e05..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-Firmware support for CPU hotplug under Linux/x86-64
----------------------------------------------------
-
-Linux/x86-64 supports CPU hotplug now. For various reasons Linux wants to
-know in advance of boot time the maximum number of CPUs that could be plugged
-into the system. ACPI 3.0 currently has no official way to supply
-this information from the firmware to the operating system.
-
-In ACPI each CPU needs an LAPIC object in the MADT table (5.2.11.5 in the
-ACPI 3.0 specification).  ACPI already has the concept of disabled LAPIC
-objects by setting the Enabled bit in the LAPIC object to zero.
-
-For CPU hotplug Linux/x86-64 expects now that any possible future hotpluggable
-CPU is already available in the MADT. If the CPU is not available yet
-it should have its LAPIC Enabled bit set to 0. Linux will use the number
-of disabled LAPICs to compute the maximum number of future CPUs.
-
-In the worst case the user can overwrite this choice using a command line
-option (additional_cpus=...), but it is recommended to supply the correct
-number (or a reasonable approximation of it, with erring towards more not less)
-in the MADT to avoid manual configuration.
diff --git a/Documentation/x86_64/fake-numa-for-cpusets b/Documentation/x86_64/fake-numa-for-cpusets
deleted file mode 100644 (file)
index d1a985c..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-Using numa=fake and CPUSets for Resource Management
-Written by David Rientjes <rientjes@cs.washington.edu>
-
-This document describes how the numa=fake x86_64 command-line option can be used
-in conjunction with cpusets for coarse memory management.  Using this feature,
-you can create fake NUMA nodes that represent contiguous chunks of memory and
-assign them to cpusets and their attached tasks.  This is a way of limiting the
-amount of system memory that are available to a certain class of tasks.
-
-For more information on the features of cpusets, see Documentation/cpusets.txt.
-There are a number of different configurations you can use for your needs.  For
-more information on the numa=fake command line option and its various ways of
-configuring fake nodes, see Documentation/x86_64/boot-options.txt.
-
-For the purposes of this introduction, we'll assume a very primitive NUMA
-emulation setup of "numa=fake=4*512,".  This will split our system memory into
-four equal chunks of 512M each that we can now use to assign to cpusets.  As
-you become more familiar with using this combination for resource control,
-you'll determine a better setup to minimize the number of nodes you have to deal
-with.
-
-A machine may be split as follows with "numa=fake=4*512," as reported by dmesg:
-
-       Faking node 0 at 0000000000000000-0000000020000000 (512MB)
-       Faking node 1 at 0000000020000000-0000000040000000 (512MB)
-       Faking node 2 at 0000000040000000-0000000060000000 (512MB)
-       Faking node 3 at 0000000060000000-0000000080000000 (512MB)
-       ...
-       On node 0 totalpages: 130975
-       On node 1 totalpages: 131072
-       On node 2 totalpages: 131072
-       On node 3 totalpages: 131072
-
-Now following the instructions for mounting the cpusets filesystem from
-Documentation/cpusets.txt, you can assign fake nodes (i.e. contiguous memory
-address spaces) to individual cpusets:
-
-       [root@xroads /]# mkdir exampleset
-       [root@xroads /]# mount -t cpuset none exampleset
-       [root@xroads /]# mkdir exampleset/ddset
-       [root@xroads /]# cd exampleset/ddset
-       [root@xroads /exampleset/ddset]# echo 0-1 > cpus
-       [root@xroads /exampleset/ddset]# echo 0-1 > mems
-
-Now this cpuset, 'ddset', will only allowed access to fake nodes 0 and 1 for
-memory allocations (1G).
-
-You can now assign tasks to these cpusets to limit the memory resources
-available to them according to the fake nodes assigned as mems:
-
-       [root@xroads /exampleset/ddset]# echo $$ > tasks
-       [root@xroads /exampleset/ddset]# dd if=/dev/zero of=tmp bs=1024 count=1G
-       [1] 13425
-
-Notice the difference between the system memory usage as reported by
-/proc/meminfo between the restricted cpuset case above and the unrestricted
-case (i.e. running the same 'dd' command without assigning it to a fake NUMA
-cpuset):
-                               Unrestricted    Restricted
-       MemTotal:               3091900 kB      3091900 kB
-       MemFree:                  42113 kB      1513236 kB
-
-This allows for coarse memory management for the tasks you assign to particular
-cpusets.  Since cpusets can form a hierarchy, you can create some pretty
-interesting combinations of use-cases for various classes of tasks for your
-memory management needs.
diff --git a/Documentation/x86_64/kernel-stacks b/Documentation/x86_64/kernel-stacks
deleted file mode 100644 (file)
index 5ad65d5..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-Most of the text from Keith Owens, hacked by AK
-
-x86_64 page size (PAGE_SIZE) is 4K.
-
-Like all other architectures, x86_64 has a kernel stack for every
-active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
-These stacks contain useful data as long as a thread is alive or a
-zombie. While the thread is in user space the kernel stack is empty
-except for the thread_info structure at the bottom.
-
-In addition to the per thread stacks, there are specialized stacks
-associated with each CPU.  These stacks are only used while the kernel
-is in control on that CPU; when a CPU returns to user space the
-specialized stacks contain no useful data.  The main CPU stacks are:
-
-* Interrupt stack.  IRQSTACKSIZE
-
-  Used for external hardware interrupts.  If this is the first external
-  hardware interrupt (i.e. not a nested hardware interrupt) then the
-  kernel switches from the current task to the interrupt stack.  Like
-  the split thread and interrupt stacks on i386 (with CONFIG_4KSTACKS),
-  this gives more room for kernel interrupt processing without having
-  to increase the size of every per thread stack.
-
-  The interrupt stack is also used when processing a softirq.
-
-Switching to the kernel interrupt stack is done by software based on a
-per CPU interrupt nest counter. This is needed because x86-64 "IST"
-hardware stacks cannot nest without races.
-
-x86_64 also has a feature which is not available on i386, the ability
-to automatically switch to a new stack for designated events such as
-double fault or NMI, which makes it easier to handle these unusual
-events on x86_64.  This feature is called the Interrupt Stack Table
-(IST).  There can be up to 7 IST entries per CPU. The IST code is an
-index into the Task State Segment (TSS). The IST entries in the TSS
-point to dedicated stacks; each stack can be a different size.
-
-An IST is selected by a non-zero value in the IST field of an
-interrupt-gate descriptor.  When an interrupt occurs and the hardware
-loads such a descriptor, the hardware automatically sets the new stack
-pointer based on the IST value, then invokes the interrupt handler.  If
-software wants to allow nested IST interrupts then the handler must
-adjust the IST values on entry to and exit from the interrupt handler.
-(This is occasionally done, e.g. for debug exceptions.)
-
-Events with different IST codes (i.e. with different stacks) can be
-nested.  For example, a debug interrupt can safely be interrupted by an
-NMI.  arch/x86_64/kernel/entry.S::paranoidentry adjusts the stack
-pointers on entry to and exit from all IST events, in theory allowing
-IST events with the same code to be nested.  However in most cases, the
-stack size allocated to an IST assumes no nesting for the same code.
-If that assumption is ever broken then the stacks will become corrupt.
-
-The currently assigned IST stacks are :-
-
-* STACKFAULT_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
-
-  Used for interrupt 12 - Stack Fault Exception (#SS).
-
-  This allows the CPU to recover from invalid stack segments. Rarely
-  happens.
-
-* DOUBLEFAULT_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
-
-  Used for interrupt 8 - Double Fault Exception (#DF).
-
-  Invoked when handling one exception causes another exception. Happens
-  when the kernel is very confused (e.g. kernel stack pointer corrupt).
-  Using a separate stack allows the kernel to recover from it well enough
-  in many cases to still output an oops.
-
-* NMI_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
-
-  Used for non-maskable interrupts (NMI).
-
-  NMI can be delivered at any time, including when the kernel is in the
-  middle of switching stacks.  Using IST for NMI events avoids making
-  assumptions about the previous state of the kernel stack.
-
-* DEBUG_STACK.  DEBUG_STKSZ
-
-  Used for hardware debug interrupts (interrupt 1) and for software
-  debug interrupts (INT3).
-
-  When debugging a kernel, debug interrupts (both hardware and
-  software) can occur at any time.  Using IST for these interrupts
-  avoids making assumptions about the previous state of the kernel
-  stack.
-
-* MCE_STACK.  EXCEPTION_STKSZ (PAGE_SIZE).
-
-  Used for interrupt 18 - Machine Check Exception (#MC).
-
-  MCE can be delivered at any time, including when the kernel is in the
-  middle of switching stacks.  Using IST for MCE events avoids making
-  assumptions about the previous state of the kernel stack.
-
-For more details see the Intel IA32 or AMD AMD64 architecture manuals.
diff --git a/Documentation/x86_64/machinecheck b/Documentation/x86_64/machinecheck
deleted file mode 100644 (file)
index a05e58e..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-
-Configurable sysfs parameters for the x86-64 machine check code.
-
-Machine checks report internal hardware error conditions detected
-by the CPU. Uncorrected errors typically cause a machine check
-(often with panic), corrected ones cause a machine check log entry.
-
-Machine checks are organized in banks (normally associated with
-a hardware subsystem) and subevents in a bank. The exact meaning
-of the banks and subevent is CPU specific.
-
-mcelog knows how to decode them.
-
-When you see the "Machine check errors logged" message in the system
-log then mcelog should run to collect and decode machine check entries
-from /dev/mcelog. Normally mcelog should be run regularly from a cronjob.
-
-Each CPU has a directory in /sys/devices/system/machinecheck/machinecheckN
-(N = CPU number)
-
-The directory contains some configurable entries:
-
-Entries:
-
-bankNctl
-(N bank number)
-       64bit Hex bitmask enabling/disabling specific subevents for bank N
-       When a bit in the bitmask is zero then the respective
-       subevent will not be reported.
-       By default all events are enabled.
-       Note that BIOS maintain another mask to disable specific events
-       per bank.  This is not visible here
-
-The following entries appear for each CPU, but they are truly shared
-between all CPUs.
-
-check_interval
-       How often to poll for corrected machine check errors, in seconds
-       (Note output is hexademical). Default 5 minutes.  When the poller
-       finds MCEs it triggers an exponential speedup (poll more often) on
-       the polling interval.  When the poller stops finding MCEs, it
-       triggers an exponential backoff (poll less often) on the polling
-       interval. The check_interval variable is both the initial and
-       maximum polling interval.
-
-tolerant
-       Tolerance level. When a machine check exception occurs for a non
-       corrected machine check the kernel can take different actions.
-       Since machine check exceptions can happen any time it is sometimes
-       risky for the kernel to kill a process because it defies
-       normal kernel locking rules. The tolerance level configures
-       how hard the kernel tries to recover even at some risk of
-       deadlock.  Higher tolerant values trade potentially better uptime
-       with the risk of a crash or even corruption (for tolerant >= 3).
-
-       0: always panic on uncorrected errors, log corrected errors
-       1: panic or SIGBUS on uncorrected errors, log corrected errors
-       2: SIGBUS or log uncorrected errors, log corrected errors
-       3: never panic or SIGBUS, log all errors (for testing only)
-
-       Default: 1
-
-       Note this only makes a difference if the CPU allows recovery
-       from a machine check exception. Current x86 CPUs generally do not.
-
-trigger
-       Program to run when a machine check event is detected.
-       This is an alternative to running mcelog regularly from cron
-       and allows to detect events faster.
-
-TBD document entries for AMD threshold interrupt configuration
-
-For more details about the x86 machine check architecture
-see the Intel and AMD architecture manuals from their developer websites.
-
-For more details about the architecture see
-see http://one.firstfloor.org/~andi/mce.pdf
diff --git a/Documentation/x86_64/mm.txt b/Documentation/x86_64/mm.txt
deleted file mode 100644 (file)
index b89b6d2..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-
-<previous description obsolete, deleted>
-
-Virtual memory map with 4 level page tables:
-
-0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm
-hole caused by [48:63] sign extension
-ffff800000000000 - ffff80ffffffffff (=40 bits) guard hole
-ffff810000000000 - ffffc0ffffffffff (=46 bits) direct mapping of all phys. memory
-ffffc10000000000 - ffffc1ffffffffff (=40 bits) hole
-ffffc20000000000 - ffffe1ffffffffff (=45 bits) vmalloc/ioremap space
-ffffe20000000000 - ffffe2ffffffffff (=40 bits) virtual memory map (1TB)
-... unused hole ...
-ffffffff80000000 - ffffffff82800000 (=40 MB)   kernel text mapping, from phys 0
-... unused hole ...
-ffffffff88000000 - fffffffffff00000 (=1919 MB) module mapping space
-
-The direct mapping covers all memory in the system up to the highest
-memory address (this means in some cases it can also include PCI memory
-holes).
-
-vmalloc space is lazily synchronized into the different PML4 pages of
-the processes using the page fault handler, with init_level4_pgt as
-reference.
-
-Current X86-64 implementations only support 40 bits of address space,
-but we support up to 46 bits. This expands into MBZ space in the page tables.
-
--Andi Kleen, Jul 2004
diff --git a/Documentation/x86_64/uefi.txt b/Documentation/x86_64/uefi.txt
deleted file mode 100644 (file)
index 7d77120..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-General note on [U]EFI x86_64 support
--------------------------------------
-
-The nomenclature EFI and UEFI are used interchangeably in this document.
-
-Although the tools below are _not_ needed for building the kernel,
-the needed bootloader support and associated tools for x86_64 platforms
-with EFI firmware and specifications are listed below.
-
-1. UEFI specification:  http://www.uefi.org
-
-2. Booting Linux kernel on UEFI x86_64 platform requires bootloader
-   support. Elilo with x86_64 support can be used.
-
-3. x86_64 platform with EFI/UEFI firmware.
-
-Mechanics:
----------
-- Build the kernel with the following configuration.
-       CONFIG_FB_EFI=y
-       CONFIG_FRAMEBUFFER_CONSOLE=y
-  If EFI runtime services are expected, the following configuration should
-  be selected.
-       CONFIG_EFI=y
-       CONFIG_EFI_VARS=y or m          # optional
-- Create a VFAT partition on the disk
-- Copy the following to the VFAT partition:
-       elilo bootloader with x86_64 support, elilo configuration file,
-       kernel image built in first step and corresponding
-       initrd. Instructions on building elilo  and its dependencies
-       can be found in the elilo sourceforge project.
-- Boot to EFI shell and invoke elilo choosing the kernel image built
-  in first step.
-- If some or all EFI runtime services don't work, you can try following
-  kernel command line parameters to turn off some or all EFI runtime
-  services.
-       noefi           turn off all EFI runtime services
-       reboot_type=k   turn off EFI reboot runtime service
index 8619861..e4d7466 100644 (file)
@@ -376,6 +376,12 @@ L: linux-geode@lists.infradead.org (moderated for non-subscribers)
 W:     http://www.amd.com/us-en/ConnectivitySolutions/TechnicalResources/0,,50_2334_2452_11363,00.html
 S:     Supported
 
+AMD IOMMU (AMD-VI)
+P:     Joerg Roedel
+M:     joerg.roedel@amd.com
+L:     iommu@lists.linux-foundation.org
+S:     Supported
+
 AMS (Apple Motion Sensor) DRIVER
 P:     Stelian Pop
 M:     stelian@popies.net
index 7c917e9..6189110 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -529,6 +529,10 @@ KBUILD_CFLAGS      += -g
 KBUILD_AFLAGS  += -gdwarf-2
 endif
 
+ifdef CONFIG_FTRACE
+KBUILD_CFLAGS  += -pg
+endif
+
 # We trigger additional mismatches with less inlining
 ifdef CONFIG_DEBUG_SECTION_MISMATCH
 KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
index b786e68..258f136 100644 (file)
@@ -14,6 +14,8 @@ config ARM
        select HAVE_OPROFILE
        select HAVE_KPROBES if (!XIP_KERNEL)
        select HAVE_KRETPROBES if (HAVE_KPROBES)
+       select HAVE_FTRACE if (!XIP_KERNEL)
+       select HAVE_DYNAMIC_FTRACE if (HAVE_FTRACE)
        help
          The ARM series is a line of low-power-consumption RISC chip designs
          licensed by ARM Ltd and targeted at embedded applications and
@@ -22,6 +24,9 @@ config ARM
          Europe.  There is an ARM Linux project with a web page at
          <http://www.arm.linux.org.uk/>.
 
+config HAVE_PWM
+       bool
+
 config SYS_SUPPORTS_APM_EMULATION
        bool
 
@@ -84,6 +89,11 @@ config STACKTRACE_SUPPORT
        bool
        default y
 
+config HAVE_LATENCYTOP_SUPPORT
+       bool
+       depends on !SMP
+       default y
+
 config LOCKDEP_SUPPORT
        bool
        default y
@@ -147,6 +157,10 @@ config FIQ
 config ARCH_MTD_XIP
        bool
 
+config GENERIC_HARDIRQS_NO__DO_IRQ
+       bool
+       def_bool y
+
 if OPROFILE
 
 config OPROFILE_ARMV6
@@ -232,13 +246,6 @@ config ARCH_CLPS711X
        help
          Support for Cirrus Logic 711x/721x based boards.
 
-config ARCH_CO285
-       bool "Co-EBSA285"
-       select FOOTBRIDGE
-       select FOOTBRIDGE_ADDIN
-       help
-         Support for Intel's EBSA285 companion chip.
-
 config ARCH_EBSA110
        bool "EBSA-110"
        select ISA
@@ -299,6 +306,8 @@ config ARCH_IOP32X
        depends on MMU
        select PLAT_IOP
        select PCI
+       select GENERIC_GPIO
+       select HAVE_GPIO_LIB
        help
          Support for Intel's 80219 and IOP32X (XScale) family of
          processors.
@@ -308,6 +317,8 @@ config ARCH_IOP33X
        depends on MMU
        select PLAT_IOP
        select PCI
+       select GENERIC_GPIO
+       select HAVE_GPIO_LIB
        help
          Support for Intel's IOP33X (XScale) family of processors.
 
@@ -347,6 +358,16 @@ config ARCH_L7200
          If you have any questions or comments about the Linux kernel port
          to this board, send e-mail to <sjhill@cotw.com>.
 
+config ARCH_KIRKWOOD
+       bool "Marvell Kirkwood"
+       select PCI
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
+       select PLAT_ORION
+       help
+         Support for the following Marvell Kirkwood series SoCs:
+         88F6180, 88F6192 and 88F6281.
+
 config ARCH_KS8695
        bool "Micrel/Kendin KS8695"
        select GENERIC_GPIO
@@ -365,9 +386,31 @@ config ARCH_NS9XXX
 
          <http://www.digi.com/products/microprocessors/index.jsp>
 
+config ARCH_LOKI
+       bool "Marvell Loki (88RC8480)"
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
+       select PLAT_ORION
+       help
+         Support for the Marvell Loki (88RC8480) SoC.
+
+config ARCH_MV78XX0
+       bool "Marvell MV78xx0"
+       select PCI
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
+       select PLAT_ORION
+       help
+         Support for the following Marvell MV78xx0 series SoCs:
+         MV781x0, MV782x0.
+
 config ARCH_MXC
        bool "Freescale MXC/iMX-based"
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
        select ARCH_MTD_XIP
+       select GENERIC_GPIO
+       select HAVE_GPIO_LIB
        help
          Support for Freescale MXC/iMX-based family of processors
 
@@ -381,7 +424,8 @@ config ARCH_ORION5X
        select PLAT_ORION
        help
          Support for the following Marvell Orion 5x series SoCs:
-         Orion-1 (5181), Orion-NAS (5182), Orion-2 (5281.)
+         Orion-1 (5181), Orion-VoIP (5181L), Orion-NAS (5182),
+         Orion-2 (5281).
 
 config ARCH_PNX4008
        bool "Philips Nexperia PNX4008 Mobile"
@@ -406,6 +450,7 @@ config ARCH_RPC
        select FIQ
        select TIMER_ACORN
        select ARCH_MAY_HAVE_PC_FDC
+       select HAVE_PATA_PLATFORM
        select ISA_DMA_API
        select NO_IOPORT
        help
@@ -502,6 +547,10 @@ source "arch/arm/mach-ixp2000/Kconfig"
 
 source "arch/arm/mach-ixp23xx/Kconfig"
 
+source "arch/arm/mach-loki/Kconfig"
+
+source "arch/arm/mach-mv78xx0/Kconfig"
+
 source "arch/arm/mach-pxa/Kconfig"
 
 source "arch/arm/mach-sa1100/Kconfig"
@@ -514,6 +563,8 @@ source "arch/arm/mach-omap2/Kconfig"
 
 source "arch/arm/mach-orion5x/Kconfig"
 
+source "arch/arm/mach-kirkwood/Kconfig"
+
 source "arch/arm/plat-s3c24xx/Kconfig"
 source "arch/arm/plat-s3c/Kconfig"
 
@@ -703,27 +754,6 @@ config PREEMPT
          Say Y here if you are building a kernel for a desktop, embedded
          or real-time system.  Say N if you are unsure.
 
-config NO_IDLE_HZ
-       bool "Dynamic tick timer"
-       depends on !GENERIC_CLOCKEVENTS
-       help
-         Select this option if you want to disable continuous timer ticks
-         and have them programmed to occur as required. This option saves
-         power as the system can remain in idle state for longer.
-
-         By default dynamic tick is disabled during the boot, and can be
-         manually enabled with:
-
-           echo 1 > /sys/devices/system/timer/timer0/dyn_tick
-
-         Alternatively, if you want dynamic tick automatically enabled
-         during boot, pass "dyntick=enable" via the kernel command string.
-
-         Please note that dynamic tick may affect the accuracy of
-         timekeeping on some platforms depending on the implementation.
-         Currently at least OMAP, PXA2xx and SA11x0 platforms are known
-         to have accurate timekeeping with dynamic tick.
-
 config HZ
        int
        default 128 if ARCH_L7200
@@ -789,7 +819,7 @@ source "mm/Kconfig"
 
 config LEDS
        bool "Timer and CPU usage LEDs"
-       depends on ARCH_CDB89712 || ARCH_CO285 || ARCH_EBSA110 || \
+       depends on ARCH_CDB89712 || ARCH_EBSA110 || \
                   ARCH_EBSA285 || ARCH_IMX || ARCH_INTEGRATOR || \
                   ARCH_LUBBOCK || MACH_MAINSTONE || ARCH_NETWINDER || \
                   ARCH_OMAP || ARCH_P720T || ARCH_PXA_IDP || \
index e72db27..b20995a 100644 (file)
@@ -100,8 +100,6 @@ textofs-y   := 0x00008000
   incdir-$(CONFIG_ARCH_CLPS7500)   := cl7500
  machine-$(CONFIG_FOOTBRIDGE)     := footbridge
   incdir-$(CONFIG_FOOTBRIDGE)     := ebsa285
- machine-$(CONFIG_ARCH_CO285)     := footbridge
-  incdir-$(CONFIG_ARCH_CO285)     := ebsa285
  machine-$(CONFIG_ARCH_SHARK)     := shark
  machine-$(CONFIG_ARCH_SA1100)    := sa1100
 ifeq ($(CONFIG_ARCH_SA1100),y)
@@ -135,11 +133,15 @@ endif
  machine-$(CONFIG_ARCH_NETX)      := netx
  machine-$(CONFIG_ARCH_NS9XXX)    := ns9xxx
  machine-$(CONFIG_ARCH_DAVINCI)           := davinci
+ machine-$(CONFIG_ARCH_KIRKWOOD)   := kirkwood
  machine-$(CONFIG_ARCH_KS8695)     := ks8695
   incdir-$(CONFIG_ARCH_MXC)       := mxc
+ machine-$(CONFIG_ARCH_MX2)       := mx2
  machine-$(CONFIG_ARCH_MX3)       := mx3
  machine-$(CONFIG_ARCH_ORION5X)           := orion5x
  machine-$(CONFIG_ARCH_MSM7X00A)   := msm
+ machine-$(CONFIG_ARCH_LOKI)       := loki
+ machine-$(CONFIG_ARCH_MV78XX0)    := mv78xx0
 
 ifeq ($(CONFIG_ARCH_EBSA110),y)
 # This is what happens if you forget the IOCS16 line.
@@ -190,8 +192,6 @@ core-$(CONFIG_PLAT_S3C24XX)         += arch/arm/plat-s3c24xx/
 core-$(CONFIG_ARCH_MXC)                += arch/arm/plat-mxc/
 
 drivers-$(CONFIG_OPROFILE)      += arch/arm/oprofile/
-drivers-$(CONFIG_ARCH_CLPS7500)        += drivers/acorn/char/
-drivers-$(CONFIG_ARCH_L7200)   += drivers/acorn/char/
 
 libs-y                         := arch/arm/lib/ $(libs-y)
 
index de9d9ee..95baac4 100644 (file)
@@ -69,6 +69,12 @@ SEDFLAGS     = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
 
 targets       := vmlinux vmlinux.lds piggy.gz piggy.o font.o font.c \
                 head.o misc.o $(OBJS)
+
+ifeq ($(CONFIG_FTRACE),y)
+ORIG_CFLAGS := $(KBUILD_CFLAGS)
+KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
+endif
+
 EXTRA_CFLAGS  := -fpic -fno-builtin
 EXTRA_AFLAGS  :=
 
index 3c2c8f2..de41dae 100644 (file)
@@ -623,8 +623,8 @@ proc_types:
                b       __armv4_mmu_cache_off
                b       __armv4_mmu_cache_flush
 
-               .word   0x56055310              @ Feroceon
-               .word   0xfffffff0
+               .word   0x56050000              @ Feroceon
+               .word   0xff0f0000
                b       __armv4_mmu_cache_on
                b       __armv4_mmu_cache_off
                b       __armv5tej_mmu_cache_flush
index 3d0b9fa..325e4b6 100644 (file)
@@ -2,7 +2,6 @@
 # Makefile for the linux kernel.
 #
 
-obj-y                          += rtctime.o
 obj-$(CONFIG_ARM_GIC)          += gic.o
 obj-$(CONFIG_ARM_VIC)          += vic.o
 obj-$(CONFIG_ICST525)          += icst525.o
diff --git a/arch/arm/common/rtctime.c b/arch/arm/common/rtctime.c
deleted file mode 100644 (file)
index aa8f773..0000000
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- *  linux/arch/arm/common/rtctime.c
- *
- *  Copyright (C) 2003 Deep Blue Solutions Ltd.
- *  Based on sa1100-rtc.c, Nils Faerber, CIH, Nicolas Pitre.
- *  Based on rtc.c by Paul Gortmaker
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/time.h>
-#include <linux/rtc.h>
-#include <linux/poll.h>
-#include <linux/proc_fs.h>
-#include <linux/miscdevice.h>
-#include <linux/spinlock.h>
-#include <linux/capability.h>
-#include <linux/device.h>
-#include <linux/mutex.h>
-
-#include <asm/rtc.h>
-
-static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
-static struct fasync_struct *rtc_async_queue;
-
-/*
- * rtc_lock protects rtc_irq_data
- */
-static DEFINE_SPINLOCK(rtc_lock);
-static unsigned long rtc_irq_data;
-
-/*
- * rtc_sem protects rtc_inuse and rtc_ops
- */
-static DEFINE_MUTEX(rtc_mutex);
-static unsigned long rtc_inuse;
-static struct rtc_ops *rtc_ops;
-
-#define rtc_epoch 1900UL
-
-/*
- * Calculate the next alarm time given the requested alarm time mask
- * and the current time.
- */
-void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm)
-{
-       unsigned long next_time;
-       unsigned long now_time;
-
-       next->tm_year = now->tm_year;
-       next->tm_mon = now->tm_mon;
-       next->tm_mday = now->tm_mday;
-       next->tm_hour = alrm->tm_hour;
-       next->tm_min = alrm->tm_min;
-       next->tm_sec = alrm->tm_sec;
-
-       rtc_tm_to_time(now, &now_time);
-       rtc_tm_to_time(next, &next_time);
-
-       if (next_time < now_time) {
-               /* Advance one day */
-               next_time += 60 * 60 * 24;
-               rtc_time_to_tm(next_time, next);
-       }
-}
-EXPORT_SYMBOL(rtc_next_alarm_time);
-
-static inline int rtc_arm_read_time(struct rtc_ops *ops, struct rtc_time *tm)
-{
-       memset(tm, 0, sizeof(struct rtc_time));
-       return ops->read_time(tm);
-}
-
-static inline int rtc_arm_set_time(struct rtc_ops *ops, struct rtc_time *tm)
-{
-       int ret;
-
-       ret = rtc_valid_tm(tm);
-       if (ret == 0)
-               ret = ops->set_time(tm);
-
-       return ret;
-}
-
-static inline int rtc_arm_read_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm)
-{
-       int ret = -EINVAL;
-       if (ops->read_alarm) {
-               memset(alrm, 0, sizeof(struct rtc_wkalrm));
-               ret = ops->read_alarm(alrm);
-       }
-       return ret;
-}
-
-static inline int rtc_arm_set_alarm(struct rtc_ops *ops, struct rtc_wkalrm *alrm)
-{
-       int ret = -EINVAL;
-       if (ops->set_alarm)
-               ret = ops->set_alarm(alrm);
-       return ret;
-}
-
-void rtc_update(unsigned long num, unsigned long events)
-{
-       spin_lock(&rtc_lock);
-       rtc_irq_data = (rtc_irq_data + (num << 8)) | events;
-       spin_unlock(&rtc_lock);
-
-       wake_up_interruptible(&rtc_wait);
-       kill_fasync(&rtc_async_queue, SIGIO, POLL_IN);
-}
-EXPORT_SYMBOL(rtc_update);
-
-
-static ssize_t
-rtc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
-{
-       DECLARE_WAITQUEUE(wait, current);
-       unsigned long data;
-       ssize_t ret;
-
-       if (count < sizeof(unsigned long))
-               return -EINVAL;
-
-       add_wait_queue(&rtc_wait, &wait);
-       do {
-               __set_current_state(TASK_INTERRUPTIBLE);
-
-               spin_lock_irq(&rtc_lock);
-               data = rtc_irq_data;
-               rtc_irq_data = 0;
-               spin_unlock_irq(&rtc_lock);
-
-               if (data != 0) {
-                       ret = 0;
-                       break;
-               }
-               if (file->f_flags & O_NONBLOCK) {
-                       ret = -EAGAIN;
-                       break;
-               }
-               if (signal_pending(current)) {
-                       ret = -ERESTARTSYS;
-                       break;
-               }
-               schedule();
-       } while (1);
-       set_current_state(TASK_RUNNING);
-       remove_wait_queue(&rtc_wait, &wait);
-
-       if (ret == 0) {
-               ret = put_user(data, (unsigned long __user *)buf);
-               if (ret == 0)
-                       ret = sizeof(unsigned long);
-       }
-       return ret;
-}
-
-static unsigned int rtc_poll(struct file *file, poll_table *wait)
-{
-       unsigned long data;
-
-       poll_wait(file, &rtc_wait, wait);
-
-       spin_lock_irq(&rtc_lock);
-       data = rtc_irq_data;
-       spin_unlock_irq(&rtc_lock);
-
-       return data != 0 ? POLLIN | POLLRDNORM : 0;
-}
-
-static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-                    unsigned long arg)
-{
-       struct rtc_ops *ops = file->private_data;
-       struct rtc_time tm;
-       struct rtc_wkalrm alrm;
-       void __user *uarg = (void __user *)arg;
-       int ret = -EINVAL;
-
-       switch (cmd) {
-       case RTC_ALM_READ:
-               ret = rtc_arm_read_alarm(ops, &alrm);
-               if (ret)
-                       break;
-               ret = copy_to_user(uarg, &alrm.time, sizeof(tm));
-               if (ret)
-                       ret = -EFAULT;
-               break;
-
-       case RTC_ALM_SET:
-               ret = copy_from_user(&alrm.time, uarg, sizeof(tm));
-               if (ret) {
-                       ret = -EFAULT;
-                       break;
-               }
-               alrm.enabled = 0;
-               alrm.pending = 0;
-               alrm.time.tm_mday = -1;
-               alrm.time.tm_mon = -1;
-               alrm.time.tm_year = -1;
-               alrm.time.tm_wday = -1;
-               alrm.time.tm_yday = -1;
-               alrm.time.tm_isdst = -1;
-               ret = rtc_arm_set_alarm(ops, &alrm);
-               break;
-
-       case RTC_RD_TIME:
-               ret = rtc_arm_read_time(ops, &tm);
-               if (ret)
-                       break;
-               ret = copy_to_user(uarg, &tm, sizeof(tm));
-               if (ret)
-                       ret = -EFAULT;
-               break;
-
-       case RTC_SET_TIME:
-               if (!capable(CAP_SYS_TIME)) {
-                       ret = -EACCES;
-                       break;
-               }
-               ret = copy_from_user(&tm, uarg, sizeof(tm));
-               if (ret) {
-                       ret = -EFAULT;
-                       break;
-               }
-               ret = rtc_arm_set_time(ops, &tm);
-               break;
-
-       case RTC_EPOCH_SET:
-#ifndef rtc_epoch
-               /*
-                * There were no RTC clocks before 1900.
-                */
-               if (arg < 1900) {
-                       ret = -EINVAL;
-                       break;
-               }
-               if (!capable(CAP_SYS_TIME)) {
-                       ret = -EACCES;
-                       break;
-               }
-               rtc_epoch = arg;
-               ret = 0;
-#endif
-               break;
-
-       case RTC_EPOCH_READ:
-               ret = put_user(rtc_epoch, (unsigned long __user *)uarg);
-               break;
-
-       case RTC_WKALM_SET:
-               ret = copy_from_user(&alrm, uarg, sizeof(alrm));
-               if (ret) {
-                       ret = -EFAULT;
-                       break;
-               }
-               ret = rtc_arm_set_alarm(ops, &alrm);
-               break;
-
-       case RTC_WKALM_RD:
-               ret = rtc_arm_read_alarm(ops, &alrm);
-               if (ret)
-                       break;
-               ret = copy_to_user(uarg, &alrm, sizeof(alrm));
-               if (ret)
-                       ret = -EFAULT;
-               break;
-
-       default:
-               if (ops->ioctl)
-                       ret = ops->ioctl(cmd, arg);
-               break;
-       }
-       return ret;
-}
-
-static int rtc_open(struct inode *inode, struct file *file)
-{
-       int ret;
-
-       mutex_lock(&rtc_mutex);
-
-       if (rtc_inuse) {
-               ret = -EBUSY;
-       } else if (!rtc_ops || !try_module_get(rtc_ops->owner)) {
-               ret = -ENODEV;
-       } else {
-               file->private_data = rtc_ops;
-
-               ret = rtc_ops->open ? rtc_ops->open() : 0;
-               if (ret == 0) {
-                       spin_lock_irq(&rtc_lock);
-                       rtc_irq_data = 0;
-                       spin_unlock_irq(&rtc_lock);
-
-                       rtc_inuse = 1;
-               }
-       }
-       mutex_unlock(&rtc_mutex);
-
-       return ret;
-}
-
-static int rtc_release(struct inode *inode, struct file *file)
-{
-       struct rtc_ops *ops = file->private_data;
-
-       if (ops->release)
-               ops->release();
-
-       spin_lock_irq(&rtc_lock);
-       rtc_irq_data = 0;
-       spin_unlock_irq(&rtc_lock);
-
-       module_put(rtc_ops->owner);
-       rtc_inuse = 0;
-
-       return 0;
-}
-
-static int rtc_fasync(int fd, struct file *file, int on)
-{
-       return fasync_helper(fd, file, on, &rtc_async_queue);
-}
-
-static const struct file_operations rtc_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .read           = rtc_read,
-       .poll           = rtc_poll,
-       .ioctl          = rtc_ioctl,
-       .open           = rtc_open,
-       .release        = rtc_release,
-       .fasync         = rtc_fasync,
-};
-
-static struct miscdevice rtc_miscdev = {
-       .minor          = RTC_MINOR,
-       .name           = "rtc",
-       .fops           = &rtc_fops,
-};
-
-
-static int rtc_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
-{
-       struct rtc_ops *ops = data;
-       struct rtc_wkalrm alrm;
-       struct rtc_time tm;
-       char *p = page;
-
-       if (rtc_arm_read_time(ops, &tm) == 0) {
-               p += sprintf(p,
-                       "rtc_time\t: %02d:%02d:%02d\n"
-                       "rtc_date\t: %04d-%02d-%02d\n"
-                       "rtc_epoch\t: %04lu\n",
-                       tm.tm_hour, tm.tm_min, tm.tm_sec,
-                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-                       rtc_epoch);
-       }
-
-       if (rtc_arm_read_alarm(ops, &alrm) == 0) {
-               p += sprintf(p, "alrm_time\t: ");
-               if ((unsigned int)alrm.time.tm_hour <= 24)
-                       p += sprintf(p, "%02d:", alrm.time.tm_hour);
-               else
-                       p += sprintf(p, "**:");
-               if ((unsigned int)alrm.time.tm_min <= 59)
-                       p += sprintf(p, "%02d:", alrm.time.tm_min);
-               else
-                       p += sprintf(p, "**:");
-               if ((unsigned int)alrm.time.tm_sec <= 59)
-                       p += sprintf(p, "%02d\n", alrm.time.tm_sec);
-               else
-                       p += sprintf(p, "**\n");
-
-               p += sprintf(p, "alrm_date\t: ");
-               if ((unsigned int)alrm.time.tm_year <= 200)
-                       p += sprintf(p, "%04d-", alrm.time.tm_year + 1900);
-               else
-                       p += sprintf(p, "****-");
-               if ((unsigned int)alrm.time.tm_mon <= 11)
-                       p += sprintf(p, "%02d-", alrm.time.tm_mon + 1);
-               else
-                       p += sprintf(p, "**-");
-               if ((unsigned int)alrm.time.tm_mday <= 31)
-                       p += sprintf(p, "%02d\n", alrm.time.tm_mday);
-               else
-                       p += sprintf(p, "**\n");
-               p += sprintf(p, "alrm_wakeup\t: %s\n",
-                            alrm.enabled ? "yes" : "no");
-               p += sprintf(p, "alrm_pending\t: %s\n",
-                            alrm.pending ? "yes" : "no");
-       }
-
-       if (ops->proc)
-               p += ops->proc(p);
-
-       return p - page;
-}
-
-int register_rtc(struct rtc_ops *ops)
-{
-       int ret = -EBUSY;
-
-       mutex_lock(&rtc_mutex);
-       if (rtc_ops == NULL) {
-               rtc_ops = ops;
-
-               ret = misc_register(&rtc_miscdev);
-               if (ret == 0)
-                       create_proc_read_entry("driver/rtc", 0, NULL,
-                                              rtc_read_proc, ops);
-       }
-       mutex_unlock(&rtc_mutex);
-
-       return ret;
-}
-EXPORT_SYMBOL(register_rtc);
-
-void unregister_rtc(struct rtc_ops *rtc)
-{
-       mutex_lock(&rtc_mutex);
-       if (rtc == rtc_ops) {
-               remove_proc_entry("driver/rtc", NULL);
-               misc_deregister(&rtc_miscdev);
-               rtc_ops = NULL;
-       }
-       mutex_unlock(&rtc_mutex);
-}
-EXPORT_SYMBOL(unregister_rtc);
index 5bba525..8822b68 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/irq.h>
 #include <asm/arch/pm.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/sharpsl.h>
 #include <asm/hardware/sharpsl_pm.h>
 
@@ -157,6 +158,7 @@ static void sharpsl_battery_thread(struct work_struct *private_)
        dev_dbg(sharpsl_pm.dev, "Battery: voltage: %d, status: %d, percentage: %d, time: %ld\n", voltage,
                        sharpsl_pm.battstat.mainbat_status, sharpsl_pm.battstat.mainbat_percent, jiffies);
 
+#ifdef CONFIG_BACKLIGHT_CORGI
        /* If battery is low. limit backlight intensity to save power. */
        if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
                        && ((sharpsl_pm.battstat.mainbat_status == APM_BATTERY_STATUS_LOW) ||
@@ -169,6 +171,7 @@ static void sharpsl_battery_thread(struct work_struct *private_)
                sharpsl_pm.machinfo->backlight_limit(0);
                sharpsl_pm.flags &= ~SHARPSL_BL_LIMIT;
        }
+#endif
 
        /* Suspend if critical battery level */
        if ((sharpsl_pm.battstat.ac_status != APM_AC_ONLINE)
index e32e736..be2b2f3 100644 (file)
@@ -213,7 +213,6 @@ CONFIG_CPU_CP15_MMU=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 CONFIG_AEABI=y
 CONFIG_OABI_COMPAT=y
@@ -907,7 +906,32 @@ CONFIG_USB_MON=y
 #
 # USB Gadget Support
 #
-# CONFIG_USB_GADGET is not set
+CONFIG_USB_GADGET=y
+# CONFIG_USB_GADGET_DEBUG is not set
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_SELECTED=y
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+CONFIG_USB_GADGET_ATMEL_USBA=y
+CONFIG_USB_ATMEL_USBA=y
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_PXA2XX is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+# CONFIG_USB_GADGET_AT91 is not set
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+CONFIG_USB_GADGET_DUALSPEED=y
+# CONFIG_USB_ZERO is not set
+CONFIG_USB_ETH=m
+CONFIG_USB_ETH_RNDIS=y
+# CONFIG_USB_GADGETFS is not set
+CONFIG_USB_FILE_STORAGE=m
+# CONFIG_USB_FILE_STORAGE_TEST is not set
+# CONFIG_USB_G_SERIAL is not set
+# CONFIG_USB_MIDI_GADGET is not set
 CONFIG_MMC=y
 # CONFIG_MMC_DEBUG is not set
 # CONFIG_MMC_UNSAFE_RESUME is not set
@@ -926,7 +950,59 @@ CONFIG_MMC_AT91=y
 # CONFIG_MMC_SPI is not set
 # CONFIG_NEW_LEDS is not set
 CONFIG_RTC_LIB=y
-# CONFIG_RTC_CLASS is not set
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_R9701 is not set
+# CONFIG_RTC_DRV_RS5C348 is not set
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_AT91SAM9=y
+CONFIG_RTC_DRV_AT91SAM9_RTT=0
+CONFIG_RTC_DRV_AT91SAM9_GPBR=0
 
 #
 # File systems
index 2dbbbc3..868fb7b 100644 (file)
@@ -169,7 +169,6 @@ CONFIG_AT91_CF=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 CONFIG_FLATMEM_MANUAL=y
index 6e994f7..de43fc6 100644 (file)
@@ -160,7 +160,6 @@ CONFIG_ISA_DMA_API=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 CONFIG_FLATMEM_MANUAL=y
index f659c93..2011adf 100644 (file)
@@ -220,7 +220,6 @@ CONFIG_CPU_CP15_MMU=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 3802e85..4049768 100644 (file)
@@ -213,7 +213,6 @@ CONFIG_CPU_CP15_MMU=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 32a0d74..fa1c5ae 100644 (file)
@@ -213,7 +213,6 @@ CONFIG_CPU_CP15_MMU=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/at91sam9g20ek_defconfig b/arch/arm/configs/at91sam9g20ek_defconfig
new file mode 100644 (file)
index 0000000..c068638
--- /dev/null
@@ -0,0 +1,1168 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.24
+# Tue Jun 10 15:51:52 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_FAIR_GROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+# CONFIG_RELAY is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+CONFIG_DEFAULT_AS=y
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="anticipatory"
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+CONFIG_ARCH_AT91=y
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Atmel AT91 System-on-Chip
+#
+# CONFIG_ARCH_AT91RM9200 is not set
+# CONFIG_ARCH_AT91SAM9260 is not set
+# CONFIG_ARCH_AT91SAM9261 is not set
+# CONFIG_ARCH_AT91SAM9263 is not set
+# CONFIG_ARCH_AT91SAM9RL is not set
+CONFIG_ARCH_AT91SAM9G20=y
+# CONFIG_ARCH_AT91CAP9 is not set
+# CONFIG_ARCH_AT91X40 is not set
+CONFIG_AT91_PMC_UNIT=y
+
+#
+# AT91SAM9G20 Board Type
+#
+CONFIG_MACH_AT91SAM9G20EK=y
+
+#
+# AT91 Board Options
+#
+# CONFIG_MTD_AT91_DATAFLASH_CARD is not set
+# CONFIG_MTD_NAND_AT91_BUSWIDTH_16 is not set
+
+#
+# AT91 Feature Selections
+#
+CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
+# CONFIG_AT91_SLOW_CLOCK is not set
+CONFIG_AT91_TIMER_HZ=100
+CONFIG_AT91_EARLY_DBGU=y
+# CONFIG_AT91_EARLY_USART0 is not set
+# CONFIG_AT91_EARLY_USART1 is not set
+# CONFIG_AT91_EARLY_USART2 is not set
+# CONFIG_AT91_EARLY_USART3 is not set
+# CONFIG_AT91_EARLY_USART4 is not set
+# CONFIG_AT91_EARLY_USART5 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+# CONFIG_ARM_THUMB is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_TICK_ONESHOT is not set
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_LEDS=y
+CONFIG_LEDS_CPU=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,3145728 root=/dev/ram0 rw"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_LEGACY is not set
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND_UP_POSSIBLE=y
+CONFIG_SUSPEND=y
+# CONFIG_APM_EMULATION is not set
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_FW_LOADER is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+CONFIG_MTD_CONCAT=y
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+# CONFIG_MTD_CFI is not set
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+CONFIG_MTD_DATAFLASH=y
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+CONFIG_MTD_NAND_AT91=y
+CONFIG_MTD_NAND_AT91_ECC_SOFT=y
+# CONFIG_MTD_NAND_AT91_ECC_HW is not set
+# CONFIG_MTD_NAND_AT91_ECC_NONE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+CONFIG_MISC_DEVICES=y
+CONFIG_ATMEL_PWM=y
+# CONFIG_EEPROM_93CX6 is not set
+CONFIG_ATMEL_SSC=y
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+# CONFIG_SCSI_LOWLEVEL is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+CONFIG_PHYLIB=y
+
+#
+# MII PHY device drivers
+#
+# CONFIG_MARVELL_PHY is not set
+# CONFIG_DAVICOM_PHY is not set
+# CONFIG_QSEMI_PHY is not set
+# CONFIG_LXT_PHY is not set
+# CONFIG_CICADA_PHY is not set
+# CONFIG_VITESSE_PHY is not set
+# CONFIG_SMSC_PHY is not set
+# CONFIG_BROADCOM_PHY is not set
+# CONFIG_ICPLUS_PHY is not set
+# CONFIG_FIXED_PHY is not set
+# CONFIG_MDIO_BITBANG is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+CONFIG_MACB=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_SHAPER is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=320
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=240
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ATKBD is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+CONFIG_KEYBOARD_GPIO=y
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+CONFIG_SERIO_SERPORT=y
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_ATMEL=y
+CONFIG_SERIAL_ATMEL_CONSOLE=y
+# CONFIG_SERIAL_ATMEL_TTYAT is not set
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=y
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+
+#
+# SPI support
+#
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_ATMEL=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+CONFIG_SPI_SPIDEV=y
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+CONFIG_SOUND=y
+
+#
+# Advanced Linux Sound Architecture
+#
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+CONFIG_SND_SEQUENCER=y
+# CONFIG_SND_SEQ_DUMMY is not set
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=y
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_PCM_OSS_PLUGINS=y
+CONFIG_SND_SEQUENCER_OSS=y
+# CONFIG_SND_DYNAMIC_MINORS is not set
+CONFIG_SND_SUPPORT_OLD_API=y
+# CONFIG_SND_VERBOSE_PROCFS is not set
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+
+#
+# Generic devices
+#
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_VIRMIDI is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# ALSA ARM devices
+#
+# CONFIG_SND_AT91_AC97 is not set
+
+#
+# SPI devices
+#
+CONFIG_SND_AT73C213=y
+CONFIG_SND_AT73C213_TARGET_BITRATE=48000
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_CAIAQ is not set
+
+#
+# System on Chip audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
+# SoC Audio support for SuperH
+#
+
+#
+# Open Sound System
+#
+# CONFIG_SOUND_PRIME is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_DEVICE_CLASS is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_PERSIST is not set
+# CONFIG_USB_OTG is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+
+#
+# USB DSL modem support
+#
+
+#
+# USB Gadget Support
+#
+CONFIG_USB_GADGET=y
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_SELECTED=y
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+# CONFIG_USB_GADGET_ATMEL_USBA is not set
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_PXA2XX is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+CONFIG_USB_GADGET_AT91=y
+CONFIG_USB_AT91=y
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+# CONFIG_USB_GADGET_DUALSPEED is not set
+CONFIG_USB_ZERO=m
+# CONFIG_USB_ETH is not set
+CONFIG_USB_GADGETFS=m
+CONFIG_USB_FILE_STORAGE=m
+# CONFIG_USB_FILE_STORAGE_TEST is not set
+CONFIG_USB_G_SERIAL=m
+# CONFIG_USB_MIDI_GADGET is not set
+CONFIG_MMC=y
+# CONFIG_MMC_DEBUG is not set
+# CONFIG_MMC_UNSAFE_RESUME is not set
+
+#
+# MMC/SD Card Drivers
+#
+CONFIG_MMC_BLOCK=y
+CONFIG_MMC_BLOCK_BOUNCE=y
+# CONFIG_SDIO_UART is not set
+
+#
+# MMC/SD Host Controller Drivers
+#
+CONFIG_MMC_AT91=y
+# CONFIG_MMC_SPI is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+CONFIG_LEDS_ATMEL_PWM=y
+CONFIG_LEDS_GPIO=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_TIMER=y
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_RS5C348 is not set
+# CONFIG_RTC_DRV_MAX6902 is not set
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_AT91SAM9=y
+CONFIG_RTC_DRV_AT91SAM9_RTT=0
+CONFIG_RTC_DRV_AT91SAM9_GPBR=0
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+CONFIG_JFFS2_SUMMARY=y
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+CONFIG_NLS_ISO8859_15=y
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+CONFIG_NLS_UTF8=y
+# CONFIG_DLM is not set
+# CONFIG_INSTRUMENTATION is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
+CONFIG_ENABLE_MUST_CHECK=y
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_FRAME_POINTER=y
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
index 98e6746..d8ec5f9 100644 (file)
@@ -211,7 +211,6 @@ CONFIG_CPU_CP15_MMU=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index d846a49..85c80f7 100644 (file)
@@ -171,7 +171,6 @@ CONFIG_AT91_CF=m
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-CONFIG_NO_IDLE_HZ=y
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/cm_x270_defconfig b/arch/arm/configs/cm_x270_defconfig
deleted file mode 100644 (file)
index 5cab083..0000000
+++ /dev/null
@@ -1,1410 +0,0 @@
-#
-# Automatically generated make config: don't edit
-# Linux kernel version: 2.6.22
-# Wed Jul 18 14:11:48 2007
-#
-CONFIG_ARM=y
-CONFIG_SYS_SUPPORTS_APM_EMULATION=y
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_TIME=y
-# CONFIG_GENERIC_CLOCKEVENTS is not set
-CONFIG_MMU=y
-# CONFIG_NO_IOPORT is not set
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_LOCKDEP_SUPPORT=y
-CONFIG_TRACE_IRQFLAGS_SUPPORT=y
-CONFIG_HARDIRQS_SW_RESEND=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_ZONE_DMA=y
-CONFIG_ARCH_MTD_XIP=y
-CONFIG_VECTORS_BASE=0xffff0000
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
-CONFIG_LOCALVERSION=""
-# CONFIG_LOCALVERSION_AUTO is not set
-CONFIG_SWAP=y
-CONFIG_SYSVIPC=y
-CONFIG_SYSVIPC_SYSCTL=y
-# CONFIG_POSIX_MQUEUE is not set
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_USER_NS is not set
-# CONFIG_AUDIT is not set
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=17
-CONFIG_SYSFS_DEPRECATED=y
-# CONFIG_RELAY is not set
-CONFIG_BLK_DEV_INITRD=y
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_CC_OPTIMIZE_FOR_SIZE=y
-CONFIG_SYSCTL=y
-CONFIG_EMBEDDED=y
-CONFIG_UID16=y
-CONFIG_SYSCTL_SYSCALL=y
-CONFIG_KALLSYMS=y
-# CONFIG_KALLSYMS_ALL is not set
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
-CONFIG_HOTPLUG=y
-CONFIG_PRINTK=y
-CONFIG_BUG=y
-CONFIG_ELF_CORE=y
-CONFIG_BASE_FULL=y
-CONFIG_FUTEX=y
-CONFIG_ANON_INODES=y
-# CONFIG_EPOLL is not set
-# CONFIG_SIGNALFD is not set
-# CONFIG_TIMERFD is not set
-# CONFIG_EVENTFD is not set
-CONFIG_SHMEM=y
-CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_SLAB=y
-# CONFIG_SLUB is not set
-# CONFIG_SLOB is not set
-CONFIG_RT_MUTEXES=y
-# CONFIG_TINY_SHMEM is not set
-CONFIG_BASE_SMALL=0
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-CONFIG_MODULE_FORCE_UNLOAD=y
-# CONFIG_MODVERSIONS is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_KMOD=y
-CONFIG_BLOCK=y
-# CONFIG_LBD is not set
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_LSF is not set
-# CONFIG_BLK_DEV_BSG is not set
-
-#
-# IO Schedulers
-#
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IOSCHED_AS=y
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_CFQ=y
-CONFIG_DEFAULT_AS=y
-# CONFIG_DEFAULT_DEADLINE is not set
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="anticipatory"
-
-#
-# System Type
-#
-# CONFIG_ARCH_AAEC2000 is not set
-# CONFIG_ARCH_INTEGRATOR is not set
-# CONFIG_ARCH_REALVIEW is not set
-# CONFIG_ARCH_VERSATILE is not set
-# CONFIG_ARCH_AT91 is not set
-# CONFIG_ARCH_CLPS7500 is not set
-# CONFIG_ARCH_CLPS711X is not set
-# CONFIG_ARCH_CO285 is not set
-# CONFIG_ARCH_EBSA110 is not set
-# CONFIG_ARCH_EP93XX is not set
-# CONFIG_ARCH_FOOTBRIDGE is not set
-# CONFIG_ARCH_NETX is not set
-# CONFIG_ARCH_H720X is not set
-# CONFIG_ARCH_IMX is not set
-# CONFIG_ARCH_IOP13XX is not set
-# CONFIG_ARCH_IOP32X is not set
-# CONFIG_ARCH_IOP33X is not set
-# CONFIG_ARCH_IXP23XX is not set
-# CONFIG_ARCH_IXP2000 is not set
-# CONFIG_ARCH_IXP4XX is not set
-# CONFIG_ARCH_L7200 is not set
-# CONFIG_ARCH_KS8695 is not set
-# CONFIG_ARCH_NS9XXX is not set
-# CONFIG_ARCH_PNX4008 is not set
-CONFIG_ARCH_PXA=y
-# CONFIG_ARCH_RPC is not set
-# CONFIG_ARCH_SA1100 is not set
-# CONFIG_ARCH_S3C2410 is not set
-# CONFIG_ARCH_SHARK is not set
-# CONFIG_ARCH_LH7A40X is not set
-# CONFIG_ARCH_DAVINCI is not set
-# CONFIG_ARCH_OMAP is not set
-CONFIG_DMABOUNCE=y
-
-#
-# Intel PXA2xx Implementations
-#
-# CONFIG_ARCH_LUBBOCK is not set
-# CONFIG_MACH_LOGICPD_PXA270 is not set
-# CONFIG_MACH_MAINSTONE is not set
-# CONFIG_ARCH_PXA_IDP is not set
-# CONFIG_PXA_SHARPSL is not set
-# CONFIG_MACH_TRIZEPS4 is not set
-CONFIG_MACH_ARMCORE=y
-CONFIG_PXA27x=y
-
-#
-# Processor Type
-#
-CONFIG_CPU_32=y
-CONFIG_CPU_XSCALE=y
-CONFIG_CPU_32v5=y
-CONFIG_CPU_ABRT_EV5T=y
-CONFIG_CPU_CACHE_VIVT=y
-CONFIG_CPU_TLB_V4WBI=y
-CONFIG_CPU_CP15=y
-CONFIG_CPU_CP15_MMU=y
-
-#
-# Processor Features
-#
-CONFIG_ARM_THUMB=y
-# CONFIG_CPU_DCACHE_DISABLE is not set
-# CONFIG_OUTER_CACHE is not set
-CONFIG_IWMMXT=y
-CONFIG_XSCALE_PMU=y
-
-#
-# Bus support
-#
-CONFIG_PCI=y
-CONFIG_PCI_SYSCALL=y
-CONFIG_PCI_HOST_ITE8152=y
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_DEBUG is not set
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
-# CONFIG_PCCARD is not set
-
-#
-# Kernel Features
-#
-# CONFIG_TICK_ONESHOT is not set
-# CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
-CONFIG_HZ=100
-# CONFIG_AEABI is not set
-# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
-# CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-CONFIG_FLATMEM=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_SPARSEMEM_STATIC is not set
-CONFIG_SPLIT_PTLOCK_CPUS=4096
-# CONFIG_RESOURCES_64BIT is not set
-CONFIG_ZONE_DMA_FLAG=1
-CONFIG_BOUNCE=y
-CONFIG_VIRT_TO_BUS=y
-CONFIG_ALIGNMENT_TRAP=y
-
-#
-# Boot options
-#
-CONFIG_ZBOOT_ROM_TEXT=0x0
-CONFIG_ZBOOT_ROM_BSS=0x0
-CONFIG_CMDLINE=""
-# CONFIG_XIP_KERNEL is not set
-# CONFIG_KEXEC is not set
-
-#
-# Floating point emulation
-#
-
-#
-# At least one emulation must be selected
-#
-CONFIG_FPE_NWFPE=y
-# CONFIG_FPE_NWFPE_XP is not set
-# CONFIG_FPE_FASTFPE is not set
-
-#
-# Userspace binary formats
-#
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_AOUT is not set
-# CONFIG_BINFMT_MISC is not set
-# CONFIG_ARTHUR is not set
-
-#
-# Power management options
-#
-CONFIG_PM=y
-# CONFIG_PM_LEGACY is not set
-# CONFIG_PM_DEBUG is not set
-# CONFIG_PM_SYSFS_DEPRECATED is not set
-# CONFIG_APM_EMULATION is not set
-
-#
-# Networking
-#
-CONFIG_NET=y
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_UNIX=y
-CONFIG_XFRM=y
-# CONFIG_XFRM_USER is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-# CONFIG_XFRM_MIGRATE is not set
-# CONFIG_NET_KEY is not set
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-CONFIG_IP_FIB_HASH=y
-CONFIG_IP_PNP=y
-CONFIG_IP_PNP_DHCP=y
-CONFIG_IP_PNP_BOOTP=y
-# CONFIG_IP_PNP_RARP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_ARPD is not set
-# CONFIG_SYN_COOKIES is not set
-# CONFIG_INET_AH is not set
-# CONFIG_INET_ESP is not set
-# CONFIG_INET_IPCOMP is not set
-# CONFIG_INET_XFRM_TUNNEL is not set
-# CONFIG_INET_TUNNEL is not set
-CONFIG_INET_XFRM_MODE_TRANSPORT=y
-CONFIG_INET_XFRM_MODE_TUNNEL=y
-CONFIG_INET_XFRM_MODE_BEET=y
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_TCP_CONG_ADVANCED is not set
-CONFIG_TCP_CONG_CUBIC=y
-CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
-# CONFIG_IPV6 is not set
-# CONFIG_INET6_XFRM_TUNNEL is not set
-# CONFIG_INET6_TUNNEL is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_IP_DCCP is not set
-# CONFIG_IP_SCTP is not set
-# CONFIG_TIPC is not set
-# CONFIG_ATM is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_VLAN_8021Q is not set
-# CONFIG_DECNET is not set
-# CONFIG_LLC2 is not set
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Network testing
-#
-# CONFIG_NET_PKTGEN is not set
-# CONFIG_HAMRADIO is not set
-# CONFIG_IRDA is not set
-# CONFIG_BT is not set
-# CONFIG_AF_RXRPC is not set
-
-#
-# Wireless
-#
-# CONFIG_CFG80211 is not set
-CONFIG_WIRELESS_EXT=y
-# CONFIG_MAC80211 is not set
-CONFIG_IEEE80211=m
-# CONFIG_IEEE80211_DEBUG is not set
-CONFIG_IEEE80211_CRYPT_WEP=m
-CONFIG_IEEE80211_CRYPT_CCMP=m
-# CONFIG_IEEE80211_CRYPT_TKIP is not set
-# CONFIG_IEEE80211_SOFTMAC is not set
-# CONFIG_RFKILL is not set
-# CONFIG_NET_9P is not set
-
-#
-# Device Drivers
-#
-
-#
-# Generic Driver Options
-#
-CONFIG_STANDALONE=y
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-CONFIG_FW_LOADER=y
-# CONFIG_DEBUG_DRIVER is not set
-# CONFIG_DEBUG_DEVRES is not set
-# CONFIG_SYS_HYPERVISOR is not set
-# CONFIG_CONNECTOR is not set
-CONFIG_MTD=m
-# CONFIG_MTD_DEBUG is not set
-# CONFIG_MTD_CONCAT is not set
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_AFS_PARTS is not set
-
-#
-# User Modules And Translation Layers
-#
-CONFIG_MTD_CHAR=m
-CONFIG_MTD_BLKDEVS=m
-CONFIG_MTD_BLOCK=m
-# CONFIG_MTD_BLOCK_RO is not set
-# CONFIG_FTL is not set
-# CONFIG_NFTL is not set
-# CONFIG_INFTL is not set
-# CONFIG_RFD_FTL is not set
-# CONFIG_SSFDC is not set
-
-#
-# RAM/ROM/Flash chip drivers
-#
-# CONFIG_MTD_CFI is not set
-# CONFIG_MTD_JEDECPROBE is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_ABSENT is not set
-
-#
-# Mapping drivers for chip access
-#
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-# CONFIG_MTD_SHARP_SL is not set
-# CONFIG_MTD_PLATRAM is not set
-
-#
-# Self-contained MTD device drivers
-#
-# CONFIG_MTD_PMC551 is not set
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_BLOCK2MTD is not set
-
-#
-# Disk-On-Chip Device Drivers
-#
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_NAND=m
-# CONFIG_MTD_NAND_VERIFY_WRITE is not set
-# CONFIG_MTD_NAND_ECC_SMC is not set
-# CONFIG_MTD_NAND_MUSEUM_IDS is not set
-# CONFIG_MTD_NAND_H1900 is not set
-CONFIG_MTD_NAND_IDS=m
-# CONFIG_MTD_NAND_DISKONCHIP is not set
-# CONFIG_MTD_NAND_SHARPSL is not set
-# CONFIG_MTD_NAND_CAFE is not set
-CONFIG_MTD_NAND_CM_X270=m
-# CONFIG_MTD_NAND_NANDSIM is not set
-# CONFIG_MTD_NAND_PLATFORM is not set
-# CONFIG_MTD_ONENAND is not set
-
-#
-# UBI - Unsorted block images
-#
-# CONFIG_MTD_UBI is not set
-# CONFIG_PARPORT is not set
-CONFIG_BLK_DEV=y
-# CONFIG_BLK_CPQ_DA is not set
-# CONFIG_BLK_CPQ_CISS_DA is not set
-# CONFIG_BLK_DEV_DAC960 is not set
-# CONFIG_BLK_DEV_UMEM is not set
-# CONFIG_BLK_DEV_COW_COMMON is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_CRYPTOLOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_SX8 is not set
-# CONFIG_BLK_DEV_UB is not set
-CONFIG_BLK_DEV_RAM=y
-CONFIG_BLK_DEV_RAM_COUNT=16
-CONFIG_BLK_DEV_RAM_SIZE=12000
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_CDROM_PKTCDVD is not set
-# CONFIG_ATA_OVER_ETH is not set
-CONFIG_IDE=m
-CONFIG_IDE_MAX_HWIFS=4
-CONFIG_BLK_DEV_IDE=m
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_IDE_SATA is not set
-CONFIG_BLK_DEV_IDEDISK=m
-# CONFIG_IDEDISK_MULTI_MODE is not set
-CONFIG_BLK_DEV_IDECD=m
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-# CONFIG_IDE_TASK_IOCTL is not set
-CONFIG_IDE_PROC_FS=y
-
-#
-# IDE chipset support/bugfixes
-#
-# CONFIG_IDE_GENERIC is not set
-# CONFIG_BLK_DEV_IDEPCI is not set
-# CONFIG_IDEPCI_PCIBUS_ORDER is not set
-# CONFIG_IDE_ARM is not set
-# CONFIG_BLK_DEV_IDEDMA is not set
-# CONFIG_BLK_DEV_HD is not set
-
-#
-# SCSI device support
-#
-# CONFIG_RAID_ATTRS is not set
-CONFIG_SCSI=y
-CONFIG_SCSI_DMA=y
-# CONFIG_SCSI_TGT is not set
-# CONFIG_SCSI_NETLINK is not set
-# CONFIG_SCSI_PROC_FS is not set
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-# CONFIG_CHR_DEV_SCH is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-# CONFIG_SCSI_SCAN_ASYNC is not set
-CONFIG_SCSI_WAIT_SCAN=m
-
-#
-# SCSI Transports
-#
-# CONFIG_SCSI_SPI_ATTRS is not set
-# CONFIG_SCSI_FC_ATTRS is not set
-# CONFIG_SCSI_ISCSI_ATTRS is not set
-# CONFIG_SCSI_SAS_ATTRS is not set
-# CONFIG_SCSI_SAS_LIBSAS is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_ISCSI_TCP is not set
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AACRAID is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_AIC79XX is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_LPFC is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_NSP32 is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_SCSI_SRP is not set
-# CONFIG_ATA is not set
-# CONFIG_MD is not set
-
-#
-# Fusion MPT device support
-#
-# CONFIG_FUSION is not set
-# CONFIG_FUSION_SPI is not set
-# CONFIG_FUSION_FC is not set
-# CONFIG_FUSION_SAS is not set
-
-#
-# IEEE 1394 (FireWire) support
-#
-# CONFIG_FIREWIRE is not set
-# CONFIG_IEEE1394 is not set
-# CONFIG_I2O is not set
-CONFIG_NETDEVICES=y
-# CONFIG_NETDEVICES_MULTIQUEUE is not set
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_MACVLAN is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_ARCNET is not set
-# CONFIG_PHYLIB is not set
-CONFIG_NET_ETHERNET=y
-CONFIG_MII=y
-# CONFIG_AX88796 is not set
-# CONFIG_HAPPYMEAL is not set
-# CONFIG_SUNGEM is not set
-# CONFIG_CASSINI is not set
-# CONFIG_NET_VENDOR_3COM is not set
-# CONFIG_SMC91X is not set
-CONFIG_DM9000=y
-# CONFIG_SMC911X is not set
-# CONFIG_NET_TULIP is not set
-# CONFIG_HP100 is not set
-CONFIG_NET_PCI=y
-# CONFIG_PCNET32 is not set
-# CONFIG_AMD8111_ETH is not set
-# CONFIG_ADAPTEC_STARFIRE is not set
-# CONFIG_B44 is not set
-# CONFIG_FORCEDETH is not set
-# CONFIG_DGRS is not set
-# CONFIG_EEPRO100 is not set
-# CONFIG_E100 is not set
-# CONFIG_FEALNX is not set
-# CONFIG_NATSEMI is not set
-# CONFIG_NE2K_PCI is not set
-# CONFIG_8139CP is not set
-CONFIG_8139TOO=m
-# CONFIG_8139TOO_PIO is not set
-# CONFIG_8139TOO_TUNE_TWISTER is not set
-# CONFIG_8139TOO_8129 is not set
-# CONFIG_8139_OLD_RX_RESET is not set
-# CONFIG_SIS900 is not set
-# CONFIG_EPIC100 is not set
-# CONFIG_SUNDANCE is not set
-# CONFIG_TLAN is not set
-# CONFIG_VIA_RHINE is not set
-# CONFIG_SC92031 is not set
-CONFIG_NETDEV_1000=y
-# CONFIG_ACENIC is not set
-# CONFIG_DL2K is not set
-# CONFIG_E1000 is not set
-# CONFIG_NS83820 is not set
-# CONFIG_HAMACHI is not set
-# CONFIG_YELLOWFIN is not set
-# CONFIG_R8169 is not set
-# CONFIG_SIS190 is not set
-# CONFIG_SKGE is not set
-# CONFIG_SKY2 is not set
-# CONFIG_VIA_VELOCITY is not set
-# CONFIG_TIGON3 is not set
-# CONFIG_BNX2 is not set
-# CONFIG_QLA3XXX is not set
-# CONFIG_ATL1 is not set
-CONFIG_NETDEV_10000=y
-# CONFIG_CHELSIO_T1 is not set
-# CONFIG_CHELSIO_T3 is not set
-# CONFIG_IXGB is not set
-# CONFIG_S2IO is not set
-# CONFIG_MYRI10GE is not set
-# CONFIG_NETXEN_NIC is not set
-# CONFIG_MLX4_CORE is not set
-# CONFIG_TR is not set
-
-#
-# Wireless LAN
-#
-# CONFIG_WLAN_PRE80211 is not set
-# CONFIG_WLAN_80211 is not set
-
-#
-# USB Network Adapters
-#
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_USBNET_MII is not set
-# CONFIG_USB_USBNET is not set
-# CONFIG_WAN is not set
-# CONFIG_FDDI is not set
-# CONFIG_HIPPI is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-# CONFIG_NET_FC is not set
-# CONFIG_SHAPER is not set
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETPOLL is not set
-# CONFIG_NET_POLL_CONTROLLER is not set
-# CONFIG_ISDN is not set
-
-#
-# Input device support
-#
-CONFIG_INPUT=y
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_POLLDEV is not set
-
-#
-# Userland interfaces
-#
-# CONFIG_INPUT_MOUSEDEV is not set
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
-CONFIG_INPUT_EVDEV=y
-# CONFIG_INPUT_EVBUG is not set
-
-#
-# Input Device Drivers
-#
-# CONFIG_INPUT_KEYBOARD is not set
-# CONFIG_INPUT_MOUSE is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_TABLET is not set
-CONFIG_INPUT_TOUCHSCREEN=y
-# CONFIG_TOUCHSCREEN_GUNZE is not set
-# CONFIG_TOUCHSCREEN_ELO is not set
-# CONFIG_TOUCHSCREEN_MTOUCH is not set
-# CONFIG_TOUCHSCREEN_MK712 is not set
-# CONFIG_TOUCHSCREEN_PENMOUNT is not set
-# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
-# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
-CONFIG_TOUCHSCREEN_UCB1400=m
-# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
-# CONFIG_INPUT_MISC is not set
-
-#
-# Hardware I/O ports
-#
-# CONFIG_SERIO is not set
-# CONFIG_GAMEPORT is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-
-#
-# Serial drivers
-#
-# CONFIG_SERIAL_8250 is not set
-
-#
-# Non-8250 serial port support
-#
-CONFIG_SERIAL_PXA=y
-CONFIG_SERIAL_PXA_CONSOLE=y
-CONFIG_SERIAL_CORE=y
-CONFIG_SERIAL_CORE_CONSOLE=y
-# CONFIG_SERIAL_JSM is not set
-CONFIG_UNIX98_PTYS=y
-CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=256
-# CONFIG_IPMI_HANDLER is not set
-# CONFIG_WATCHDOG is not set
-CONFIG_HW_RANDOM=m
-# CONFIG_NVRAM is not set
-# CONFIG_R3964 is not set
-# CONFIG_APPLICOM is not set
-# CONFIG_DRM is not set
-# CONFIG_RAW_DRIVER is not set
-# CONFIG_TCG_TPM is not set
-CONFIG_DEVPORT=y
-# CONFIG_I2C is not set
-
-#
-# SPI support
-#
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
-# CONFIG_W1 is not set
-# CONFIG_HWMON is not set
-CONFIG_MISC_DEVICES=y
-# CONFIG_PHANTOM is not set
-# CONFIG_EEPROM_93CX6 is not set
-# CONFIG_SGI_IOC4 is not set
-# CONFIG_TIFM_CORE is not set
-
-#
-# Multifunction device drivers
-#
-# CONFIG_MFD_SM501 is not set
-
-#
-# LED devices
-#
-CONFIG_NEW_LEDS=y
-CONFIG_LEDS_CLASS=y
-
-#
-# LED drivers
-#
-CONFIG_LEDS_CM_X270=y
-
-#
-# LED Triggers
-#
-CONFIG_LEDS_TRIGGERS=y
-# CONFIG_LEDS_TRIGGER_TIMER is not set
-# CONFIG_LEDS_TRIGGER_IDE_DISK is not set
-CONFIG_LEDS_TRIGGER_HEARTBEAT=y
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-# CONFIG_DVB_CORE is not set
-CONFIG_DAB=y
-# CONFIG_USB_DABUSB is not set
-
-#
-# Graphics support
-#
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
-
-#
-# Display device support
-#
-# CONFIG_DISPLAY_SUPPORT is not set
-# CONFIG_VGASTATE is not set
-CONFIG_FB=y
-# CONFIG_FIRMWARE_EDID is not set
-# CONFIG_FB_DDC is not set
-CONFIG_FB_CFB_FILLRECT=y
-CONFIG_FB_CFB_COPYAREA=y
-CONFIG_FB_CFB_IMAGEBLIT=y
-# CONFIG_FB_SYS_FILLRECT is not set
-# CONFIG_FB_SYS_COPYAREA is not set
-# CONFIG_FB_SYS_IMAGEBLIT is not set
-# CONFIG_FB_SYS_FOPS is not set
-CONFIG_FB_DEFERRED_IO=y
-# CONFIG_FB_SVGALIB is not set
-# CONFIG_FB_MACMODES is not set
-# CONFIG_FB_BACKLIGHT is not set
-# CONFIG_FB_MODE_HELPERS is not set
-# CONFIG_FB_TILEBLITTING is not set
-
-#
-# Frame buffer hardware drivers
-#
-# CONFIG_FB_CIRRUS is not set
-# CONFIG_FB_PM2 is not set
-# CONFIG_FB_CYBER2000 is not set
-# CONFIG_FB_ASILIANT is not set
-# CONFIG_FB_IMSTT is not set
-# CONFIG_FB_S1D13XXX is not set
-# CONFIG_FB_NVIDIA is not set
-# CONFIG_FB_RIVA is not set
-# CONFIG_FB_MATROX is not set
-# CONFIG_FB_RADEON is not set
-# CONFIG_FB_ATY128 is not set
-# CONFIG_FB_ATY is not set
-# CONFIG_FB_S3 is not set
-# CONFIG_FB_SAVAGE is not set
-# CONFIG_FB_SIS is not set
-# CONFIG_FB_NEOMAGIC is not set
-# CONFIG_FB_KYRO is not set
-# CONFIG_FB_3DFX is not set
-# CONFIG_FB_VOODOO1 is not set
-# CONFIG_FB_VT8623 is not set
-# CONFIG_FB_TRIDENT is not set
-# CONFIG_FB_ARK is not set
-# CONFIG_FB_PM3 is not set
-CONFIG_FB_PXA=y
-# CONFIG_FB_PXA_PARAMETERS is not set
-CONFIG_FB_MBX=m
-# CONFIG_FB_VIRTUAL is not set
-
-#
-# Console display driver support
-#
-# CONFIG_VGA_CONSOLE is not set
-CONFIG_DUMMY_CONSOLE=y
-CONFIG_FRAMEBUFFER_CONSOLE=y
-# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
-# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
-# CONFIG_FONTS is not set
-CONFIG_FONT_8x8=y
-CONFIG_FONT_8x16=y
-CONFIG_LOGO=y
-CONFIG_LOGO_LINUX_MONO=y
-CONFIG_LOGO_LINUX_VGA16=y
-CONFIG_LOGO_LINUX_CLUT224=y
-
-#
-# Sound
-#
-CONFIG_SOUND=m
-
-#
-# Advanced Linux Sound Architecture
-#
-CONFIG_SND=m
-CONFIG_SND_TIMER=m
-CONFIG_SND_PCM=m
-# CONFIG_SND_SEQUENCER is not set
-CONFIG_SND_OSSEMUL=y
-CONFIG_SND_MIXER_OSS=m
-CONFIG_SND_PCM_OSS=m
-CONFIG_SND_PCM_OSS_PLUGINS=y
-# CONFIG_SND_DYNAMIC_MINORS is not set
-CONFIG_SND_SUPPORT_OLD_API=y
-CONFIG_SND_VERBOSE_PROCFS=y
-# CONFIG_SND_VERBOSE_PRINTK is not set
-# CONFIG_SND_DEBUG is not set
-
-#
-# Generic devices
-#
-CONFIG_SND_AC97_CODEC=m
-# CONFIG_SND_DUMMY is not set
-# CONFIG_SND_MTPAV is not set
-# CONFIG_SND_SERIAL_U16550 is not set
-# CONFIG_SND_MPU401 is not set
-
-#
-# PCI devices
-#
-# CONFIG_SND_AD1889 is not set
-# CONFIG_SND_ALS300 is not set
-# CONFIG_SND_ALI5451 is not set
-# CONFIG_SND_ATIIXP is not set
-# CONFIG_SND_ATIIXP_MODEM is not set
-# CONFIG_SND_AU8810 is not set
-# CONFIG_SND_AU8820 is not set
-# CONFIG_SND_AU8830 is not set
-# CONFIG_SND_AZT3328 is not set
-# CONFIG_SND_BT87X is not set
-# CONFIG_SND_CA0106 is not set
-# CONFIG_SND_CMIPCI is not set
-# CONFIG_SND_CS4281 is not set
-# CONFIG_SND_CS46XX is not set
-# CONFIG_SND_DARLA20 is not set
-# CONFIG_SND_GINA20 is not set
-# CONFIG_SND_LAYLA20 is not set
-# CONFIG_SND_DARLA24 is not set
-# CONFIG_SND_GINA24 is not set
-# CONFIG_SND_LAYLA24 is not set
-# CONFIG_SND_MONA is not set
-# CONFIG_SND_MIA is not set
-# CONFIG_SND_ECHO3G is not set
-# CONFIG_SND_INDIGO is not set
-# CONFIG_SND_INDIGOIO is not set
-# CONFIG_SND_INDIGODJ is not set
-# CONFIG_SND_EMU10K1 is not set
-# CONFIG_SND_EMU10K1X is not set
-# CONFIG_SND_ENS1370 is not set
-# CONFIG_SND_ENS1371 is not set
-# CONFIG_SND_ES1938 is not set
-# CONFIG_SND_ES1968 is not set
-# CONFIG_SND_FM801 is not set
-# CONFIG_SND_HDA_INTEL is not set
-# CONFIG_SND_HDSP is not set
-# CONFIG_SND_HDSPM is not set
-# CONFIG_SND_ICE1712 is not set
-# CONFIG_SND_ICE1724 is not set
-# CONFIG_SND_INTEL8X0 is not set
-# CONFIG_SND_INTEL8X0M is not set
-# CONFIG_SND_KORG1212 is not set
-# CONFIG_SND_MAESTRO3 is not set
-# CONFIG_SND_MIXART is not set
-# CONFIG_SND_NM256 is not set
-# CONFIG_SND_PCXHR is not set
-# CONFIG_SND_RIPTIDE is not set
-# CONFIG_SND_RME32 is not set
-# CONFIG_SND_RME96 is not set
-# CONFIG_SND_RME9652 is not set
-# CONFIG_SND_SONICVIBES is not set
-# CONFIG_SND_TRIDENT is not set
-# CONFIG_SND_VIA82XX is not set
-# CONFIG_SND_VIA82XX_MODEM is not set
-# CONFIG_SND_VX222 is not set
-# CONFIG_SND_YMFPCI is not set
-# CONFIG_SND_AC97_POWER_SAVE is not set
-
-#
-# ALSA ARM devices
-#
-CONFIG_SND_PXA2XX_PCM=m
-CONFIG_SND_PXA2XX_AC97=m
-
-#
-# USB devices
-#
-# CONFIG_SND_USB_AUDIO is not set
-# CONFIG_SND_USB_CAIAQ is not set
-
-#
-# System on Chip audio support
-#
-# CONFIG_SND_SOC is not set
-
-#
-# Open Sound System
-#
-# CONFIG_SOUND_PRIME is not set
-CONFIG_AC97_BUS=m
-CONFIG_HID_SUPPORT=y
-CONFIG_HID=y
-# CONFIG_HID_DEBUG is not set
-
-#
-# USB Input Devices
-#
-CONFIG_USB_HID=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_HID_FF is not set
-# CONFIG_USB_HIDDEV is not set
-CONFIG_USB_SUPPORT=y
-CONFIG_USB_ARCH_HAS_HCD=y
-CONFIG_USB_ARCH_HAS_OHCI=y
-CONFIG_USB_ARCH_HAS_EHCI=y
-CONFIG_USB=y
-# CONFIG_USB_DEBUG is not set
-
-#
-# Miscellaneous USB options
-#
-CONFIG_USB_DEVICEFS=y
-# CONFIG_USB_DEVICE_CLASS is not set
-# CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
-# CONFIG_USB_PERSIST is not set
-# CONFIG_USB_OTG is not set
-
-#
-# USB Host Controller Drivers
-#
-# CONFIG_USB_EHCI_HCD is not set
-# CONFIG_USB_ISP116X_HCD is not set
-CONFIG_USB_OHCI_HCD=y
-# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
-# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
-CONFIG_USB_OHCI_LITTLE_ENDIAN=y
-# CONFIG_USB_UHCI_HCD is not set
-# CONFIG_USB_SL811_HCD is not set
-# CONFIG_USB_R8A66597_HCD is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
-#
-
-#
-# may also be needed; see USB_STORAGE Help for more information
-#
-CONFIG_USB_STORAGE=y
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_USBAT is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_SDDR55 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_STORAGE_ALAUDA is not set
-# CONFIG_USB_STORAGE_KARMA is not set
-# CONFIG_USB_LIBUSUAL is not set
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_MICROTEK is not set
-CONFIG_USB_MON=y
-
-#
-# USB port drivers
-#
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_EMI62 is not set
-# CONFIG_USB_EMI26 is not set
-# CONFIG_USB_ADUTUX is not set
-# CONFIG_USB_AUERSWALD is not set
-# CONFIG_USB_RIO500 is not set
-# CONFIG_USB_LEGOTOWER is not set
-# CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
-# CONFIG_USB_LED is not set
-# CONFIG_USB_CYPRESS_CY7C63 is not set
-# CONFIG_USB_CYTHERM is not set
-# CONFIG_USB_PHIDGET is not set
-# CONFIG_USB_IDMOUSE is not set
-# CONFIG_USB_FTDI_ELAN is not set
-# CONFIG_USB_APPLEDISPLAY is not set
-# CONFIG_USB_LD is not set
-# CONFIG_USB_TRANCEVIBRATOR is not set
-# CONFIG_USB_IOWARRIOR is not set
-# CONFIG_USB_TEST is not set
-
-#
-# USB DSL modem support
-#
-
-#
-# USB Gadget Support
-#
-# CONFIG_USB_GADGET is not set
-CONFIG_MMC=m
-# CONFIG_MMC_DEBUG is not set
-# CONFIG_MMC_UNSAFE_RESUME is not set
-
-#
-# MMC/SD Card Drivers
-#
-CONFIG_MMC_BLOCK=m
-CONFIG_MMC_BLOCK_BOUNCE=y
-
-#
-# MMC/SD Host Controller Drivers
-#
-CONFIG_MMC_PXA=m
-# CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_TIFM_SD is not set
-
-#
-# Real Time Clock
-#
-CONFIG_RTC_LIB=y
-CONFIG_RTC_CLASS=y
-CONFIG_RTC_HCTOSYS=y
-CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
-# CONFIG_RTC_DEBUG is not set
-
-#
-# RTC interfaces
-#
-CONFIG_RTC_INTF_SYSFS=y
-CONFIG_RTC_INTF_PROC=y
-CONFIG_RTC_INTF_DEV=y
-# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
-# CONFIG_RTC_DRV_TEST is not set
-
-#
-# Platform RTC drivers
-#
-# CONFIG_RTC_DRV_CMOS is not set
-# CONFIG_RTC_DRV_DS1553 is not set
-# CONFIG_RTC_DRV_DS1742 is not set
-# CONFIG_RTC_DRV_M48T86 is not set
-# CONFIG_RTC_DRV_M48T59 is not set
-CONFIG_RTC_DRV_V3020=y
-
-#
-# on-CPU RTC drivers
-#
-CONFIG_RTC_DRV_SA1100=y
-
-#
-# DMA Engine support
-#
-# CONFIG_DMA_ENGINE is not set
-
-#
-# DMA Clients
-#
-
-#
-# DMA Devices
-#
-
-#
-# File systems
-#
-CONFIG_EXT2_FS=y
-# CONFIG_EXT2_FS_XATTR is not set
-# CONFIG_EXT2_FS_XIP is not set
-CONFIG_EXT3_FS=y
-CONFIG_EXT3_FS_XATTR=y
-# CONFIG_EXT3_FS_POSIX_ACL is not set
-# CONFIG_EXT3_FS_SECURITY is not set
-# CONFIG_EXT4DEV_FS is not set
-CONFIG_JBD=y
-# CONFIG_JBD_DEBUG is not set
-CONFIG_FS_MBCACHE=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
-# CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_INOTIFY=y
-CONFIG_INOTIFY_USER=y
-# CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_FUSE_FS is not set
-
-#
-# CD-ROM/DVD Filesystems
-#
-# CONFIG_ISO9660_FS is not set
-# CONFIG_UDF_FS is not set
-
-#
-# DOS/FAT/NT Filesystems
-#
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-CONFIG_VFAT_FS=y
-CONFIG_FAT_DEFAULT_CODEPAGE=437
-CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
-# CONFIG_NTFS_FS is not set
-
-#
-# Pseudo filesystems
-#
-CONFIG_PROC_FS=y
-CONFIG_PROC_SYSCTL=y
-CONFIG_SYSFS=y
-CONFIG_TMPFS=y
-# CONFIG_TMPFS_POSIX_ACL is not set
-# CONFIG_HUGETLB_PAGE is not set
-CONFIG_RAMFS=y
-# CONFIG_CONFIGFS_FS is not set
-
-#
-# Miscellaneous filesystems
-#
-# CONFIG_ADFS_FS is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_HFSPLUS_FS is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_EFS_FS is not set
-# CONFIG_JFFS2_FS is not set
-# CONFIG_CRAMFS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_SYSV_FS is not set
-# CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
-# CONFIG_NFSD is not set
-CONFIG_ROOT_NFS=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-CONFIG_NFS_COMMON=y
-CONFIG_SUNRPC=y
-# CONFIG_SUNRPC_BIND34 is not set
-# CONFIG_RPCSEC_GSS_KRB5 is not set
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
-CONFIG_SMB_FS=y
-# CONFIG_SMB_NLS_DEFAULT is not set
-# CONFIG_CIFS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_CODA_FS is not set
-# CONFIG_AFS_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS=y
-CONFIG_NLS_DEFAULT="iso8859-1"
-CONFIG_NLS_CODEPAGE_437=y
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1250 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-CONFIG_NLS_ISO8859_1=y
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Distributed Lock Manager
-#
-# CONFIG_DLM is not set
-
-#
-# Profiling support
-#
-# CONFIG_PROFILING is not set
-
-#
-# Kernel hacking
-#
-# CONFIG_PRINTK_TIME is not set
-CONFIG_ENABLE_MUST_CHECK=y
-CONFIG_MAGIC_SYSRQ=y
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_HEADERS_CHECK is not set
-CONFIG_DEBUG_KERNEL=y
-# CONFIG_DEBUG_SHIRQ is not set
-# CONFIG_DETECT_SOFTLOCKUP is not set
-CONFIG_SCHED_DEBUG=y
-# CONFIG_SCHEDSTATS is not set
-# CONFIG_TIMER_STATS is not set
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_RT_MUTEXES is not set
-# CONFIG_RT_MUTEX_TESTER is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_DEBUG_MUTEXES is not set
-# CONFIG_DEBUG_LOCK_ALLOC is not set
-# CONFIG_PROVE_LOCKING is not set
-# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
-# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-# CONFIG_DEBUG_KOBJECT is not set
-# CONFIG_DEBUG_BUGVERBOSE is not set
-CONFIG_DEBUG_INFO=y
-# CONFIG_DEBUG_VM is not set
-# CONFIG_DEBUG_LIST is not set
-CONFIG_FRAME_POINTER=y
-CONFIG_FORCED_INLINING=y
-# CONFIG_RCU_TORTURE_TEST is not set
-# CONFIG_FAULT_INJECTION is not set
-CONFIG_DEBUG_USER=y
-CONFIG_DEBUG_ERRORS=y
-CONFIG_DEBUG_LL=y
-# CONFIG_DEBUG_ICEDCC is not set
-
-#
-# Security options
-#
-# CONFIG_KEYS is not set
-# CONFIG_SECURITY is not set
-CONFIG_CRYPTO=y
-CONFIG_CRYPTO_ALGAPI=m
-CONFIG_CRYPTO_BLKCIPHER=m
-CONFIG_CRYPTO_MANAGER=m
-# CONFIG_CRYPTO_HMAC is not set
-# CONFIG_CRYPTO_XCBC is not set
-# CONFIG_CRYPTO_NULL is not set
-# CONFIG_CRYPTO_MD4 is not set
-# CONFIG_CRYPTO_MD5 is not set
-# CONFIG_CRYPTO_SHA1 is not set
-# CONFIG_CRYPTO_SHA256 is not set
-# CONFIG_CRYPTO_SHA512 is not set
-# CONFIG_CRYPTO_WP512 is not set
-# CONFIG_CRYPTO_TGR192 is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-CONFIG_CRYPTO_ECB=m
-CONFIG_CRYPTO_CBC=m
-CONFIG_CRYPTO_PCBC=m
-# CONFIG_CRYPTO_LRW is not set
-# CONFIG_CRYPTO_CRYPTD is not set
-# CONFIG_CRYPTO_DES is not set
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_BLOWFISH is not set
-# CONFIG_CRYPTO_TWOFISH is not set
-# CONFIG_CRYPTO_SERPENT is not set
-CONFIG_CRYPTO_AES=m
-# CONFIG_CRYPTO_CAST5 is not set
-# CONFIG_CRYPTO_CAST6 is not set
-# CONFIG_CRYPTO_TEA is not set
-CONFIG_CRYPTO_ARC4=m
-# CONFIG_CRYPTO_KHAZAD is not set
-# CONFIG_CRYPTO_ANUBIS is not set
-# CONFIG_CRYPTO_DEFLATE is not set
-# CONFIG_CRYPTO_MICHAEL_MIC is not set
-# CONFIG_CRYPTO_CRC32C is not set
-# CONFIG_CRYPTO_CAMELLIA is not set
-# CONFIG_CRYPTO_TEST is not set
-CONFIG_CRYPTO_HW=y
-
-#
-# Library routines
-#
-CONFIG_BITREVERSE=y
-# CONFIG_CRC_CCITT is not set
-# CONFIG_CRC16 is not set
-# CONFIG_CRC_ITU_T is not set
-CONFIG_CRC32=y
-# CONFIG_CRC7 is not set
-# CONFIG_LIBCRC32C is not set
-CONFIG_PLIST=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HAS_DMA=y
index 4264e27..f7622e6 100644 (file)
@@ -166,7 +166,6 @@ CONFIG_PCMCIA_SA1100=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 CONFIG_ARCH_DISCONTIGMEM_ENABLE=y
index e8980a9..9b8748a 100644 (file)
@@ -165,7 +165,6 @@ CONFIG_PCMCIA_PXA2XX=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 CONFIG_FLATMEM_MANUAL=y
index 90ed214..cfeb817 100644 (file)
@@ -230,7 +230,6 @@ CONFIG_AT91_CF=y
 #
 # CONFIG_TICK_ONESHOT is not set
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/em_x270_defconfig b/arch/arm/configs/em_x270_defconfig
deleted file mode 100644 (file)
index 6bea090..0000000
+++ /dev/null
@@ -1,1265 +0,0 @@
-#
-# Automatically generated make config: don't edit
-# Linux kernel version: 2.6.22
-# Mon Jul  9 15:18:20 2007
-#
-CONFIG_ARM=y
-CONFIG_SYS_SUPPORTS_APM_EMULATION=y
-CONFIG_GENERIC_GPIO=y
-CONFIG_GENERIC_TIME=y
-# CONFIG_GENERIC_CLOCKEVENTS is not set
-CONFIG_MMU=y
-# CONFIG_NO_IOPORT is not set
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_LOCKDEP_SUPPORT=y
-CONFIG_TRACE_IRQFLAGS_SUPPORT=y
-CONFIG_HARDIRQS_SW_RESEND=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_ZONE_DMA=y
-CONFIG_ARCH_MTD_XIP=y
-CONFIG_VECTORS_BASE=0xffff0000
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
-
-#
-# Code maturity level options
-#
-CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
-CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
-CONFIG_LOCALVERSION="-em-x270"
-# CONFIG_LOCALVERSION_AUTO is not set
-CONFIG_SWAP=y
-CONFIG_SYSVIPC=y
-# CONFIG_IPC_NS is not set
-CONFIG_SYSVIPC_SYSCTL=y
-# CONFIG_POSIX_MQUEUE is not set
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_UTS_NS is not set
-# CONFIG_AUDIT is not set
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=17
-CONFIG_SYSFS_DEPRECATED=y
-# CONFIG_RELAY is not set
-CONFIG_BLK_DEV_INITRD=y
-CONFIG_INITRAMFS_SOURCE=""
-CONFIG_CC_OPTIMIZE_FOR_SIZE=y
-CONFIG_SYSCTL=y
-CONFIG_EMBEDDED=y
-CONFIG_UID16=y
-CONFIG_SYSCTL_SYSCALL=y
-CONFIG_KALLSYMS=y
-# CONFIG_KALLSYMS_ALL is not set
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
-CONFIG_HOTPLUG=y
-CONFIG_PRINTK=y
-CONFIG_BUG=y
-CONFIG_ELF_CORE=y
-CONFIG_BASE_FULL=y
-CONFIG_FUTEX=y
-CONFIG_ANON_INODES=y
-CONFIG_EPOLL=y
-CONFIG_SIGNALFD=y
-CONFIG_TIMERFD=y
-CONFIG_EVENTFD=y
-CONFIG_SHMEM=y
-CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_SLAB=y
-# CONFIG_SLUB is not set
-# CONFIG_SLOB is not set
-CONFIG_RT_MUTEXES=y
-# CONFIG_TINY_SHMEM is not set
-CONFIG_BASE_SMALL=0
-
-#
-# Loadable module support
-#
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-CONFIG_MODULE_FORCE_UNLOAD=y
-# CONFIG_MODVERSIONS is not set
-# CONFIG_MODULE_SRCVERSION_ALL is not set
-CONFIG_KMOD=y
-
-#
-# Block layer
-#
-CONFIG_BLOCK=y
-# CONFIG_LBD is not set
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_LSF is not set
-
-#
-# IO Schedulers
-#
-CONFIG_IOSCHED_NOOP=y
-CONFIG_IOSCHED_AS=y
-CONFIG_IOSCHED_DEADLINE=y
-CONFIG_IOSCHED_CFQ=y
-CONFIG_DEFAULT_AS=y
-# CONFIG_DEFAULT_DEADLINE is not set
-# CONFIG_DEFAULT_CFQ is not set
-# CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="anticipatory"
-
-#
-# System Type
-#
-# CONFIG_ARCH_AAEC2000 is not set
-# CONFIG_ARCH_INTEGRATOR is not set
-# CONFIG_ARCH_REALVIEW is not set
-# CONFIG_ARCH_VERSATILE is not set
-# CONFIG_ARCH_AT91 is not set
-# CONFIG_ARCH_CLPS7500 is not set
-# CONFIG_ARCH_CLPS711X is not set
-# CONFIG_ARCH_CO285 is not set
-# CONFIG_ARCH_EBSA110 is not set
-# CONFIG_ARCH_EP93XX is not set
-# CONFIG_ARCH_FOOTBRIDGE is not set
-# CONFIG_ARCH_NETX is not set
-# CONFIG_ARCH_H720X is not set
-# CONFIG_ARCH_IMX is not set
-# CONFIG_ARCH_IOP13XX is not set
-# CONFIG_ARCH_IOP32X is not set
-# CONFIG_ARCH_IOP33X is not set
-# CONFIG_ARCH_IXP23XX is not set
-# CONFIG_ARCH_IXP2000 is not set
-# CONFIG_ARCH_IXP4XX is not set
-# CONFIG_ARCH_L7200 is not set
-# CONFIG_ARCH_KS8695 is not set
-# CONFIG_ARCH_NS9XXX is not set
-# CONFIG_ARCH_PNX4008 is not set
-CONFIG_ARCH_PXA=y
-# CONFIG_ARCH_RPC is not set
-# CONFIG_ARCH_SA1100 is not set
-# CONFIG_ARCH_S3C2410 is not set
-# CONFIG_ARCH_SHARK is not set
-# CONFIG_ARCH_LH7A40X is not set
-# CONFIG_ARCH_DAVINCI is not set
-# CONFIG_ARCH_OMAP is not set
-
-#
-# Intel PXA2xx Implementations
-#
-# CONFIG_ARCH_LUBBOCK is not set
-# CONFIG_MACH_LOGICPD_PXA270 is not set
-# CONFIG_MACH_MAINSTONE is not set
-# CONFIG_ARCH_PXA_IDP is not set
-# CONFIG_PXA_SHARPSL is not set
-# CONFIG_MACH_TRIZEPS4 is not set
-CONFIG_MACH_EM_X270=y
-CONFIG_PXA27x=y
-
-#
-# Processor Type
-#
-CONFIG_CPU_32=y
-CONFIG_CPU_XSCALE=y
-CONFIG_CPU_32v5=y
-CONFIG_CPU_ABRT_EV5T=y
-CONFIG_CPU_CACHE_VIVT=y
-CONFIG_CPU_TLB_V4WBI=y
-CONFIG_CPU_CP15=y
-CONFIG_CPU_CP15_MMU=y
-
-#
-# Processor Features
-#
-CONFIG_ARM_THUMB=y
-# CONFIG_CPU_DCACHE_DISABLE is not set
-# CONFIG_OUTER_CACHE is not set
-CONFIG_IWMMXT=y
-CONFIG_XSCALE_PMU=y
-
-#
-# Bus support
-#
-# CONFIG_ARCH_SUPPORTS_MSI is not set
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
-# CONFIG_PCCARD is not set
-
-#
-# Kernel Features
-#
-# CONFIG_TICK_ONESHOT is not set
-# CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
-CONFIG_HZ=100
-CONFIG_AEABI=y
-CONFIG_OABI_COMPAT=y
-# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
-CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
-# CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-CONFIG_FLATMEM=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_SPARSEMEM_STATIC is not set
-CONFIG_SPLIT_PTLOCK_CPUS=4096
-# CONFIG_RESOURCES_64BIT is not set
-CONFIG_ZONE_DMA_FLAG=1
-CONFIG_ALIGNMENT_TRAP=y
-
-#
-# Boot options
-#
-CONFIG_ZBOOT_ROM_TEXT=0x0
-CONFIG_ZBOOT_ROM_BSS=0x0
-CONFIG_CMDLINE=""
-# CONFIG_XIP_KERNEL is not set
-# CONFIG_KEXEC is not set
-
-#
-# Floating point emulation
-#
-
-#
-# At least one emulation must be selected
-#
-CONFIG_FPE_NWFPE=y
-# CONFIG_FPE_NWFPE_XP is not set
-# CONFIG_FPE_FASTFPE is not set
-
-#
-# Userspace binary formats
-#
-CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_AOUT is not set
-# CONFIG_BINFMT_MISC is not set
-
-#
-# Power management options
-#
-CONFIG_PM=y
-CONFIG_PM_LEGACY=y
-# CONFIG_PM_DEBUG is not set
-# CONFIG_PM_SYSFS_DEPRECATED is not set
-CONFIG_APM_EMULATION=m
-
-#
-# Networking
-#
-CONFIG_NET=y
-
-#
-# Networking options
-#
-CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
-CONFIG_UNIX=y
-CONFIG_XFRM=y
-# CONFIG_XFRM_USER is not set
-# CONFIG_XFRM_SUB_POLICY is not set
-# CONFIG_XFRM_MIGRATE is not set
-# CONFIG_NET_KEY is not set
-CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
-# CONFIG_IP_ADVANCED_ROUTER is not set
-CONFIG_IP_FIB_HASH=y
-CONFIG_IP_PNP=y
-CONFIG_IP_PNP_DHCP=y
-CONFIG_IP_PNP_BOOTP=y
-# CONFIG_IP_PNP_RARP is not set
-# CONFIG_NET_IPIP is not set
-# CONFIG_NET_IPGRE is not set
-# CONFIG_ARPD is not set
-# CONFIG_SYN_COOKIES is not set
-# CONFIG_INET_AH is not set
-# CONFIG_INET_ESP is not set
-# CONFIG_INET_IPCOMP is not set
-# CONFIG_INET_XFRM_TUNNEL is not set
-# CONFIG_INET_TUNNEL is not set
-CONFIG_INET_XFRM_MODE_TRANSPORT=y
-CONFIG_INET_XFRM_MODE_TUNNEL=y
-CONFIG_INET_XFRM_MODE_BEET=y
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_TCP_CONG_ADVANCED is not set
-CONFIG_TCP_CONG_CUBIC=y
-CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
-# CONFIG_IPV6 is not set
-# CONFIG_INET6_XFRM_TUNNEL is not set
-# CONFIG_INET6_TUNNEL is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETFILTER is not set
-# CONFIG_IP_DCCP is not set
-# CONFIG_IP_SCTP is not set
-# CONFIG_TIPC is not set
-# CONFIG_ATM is not set
-# CONFIG_BRIDGE is not set
-# CONFIG_VLAN_8021Q is not set
-# CONFIG_DECNET is not set
-# CONFIG_LLC2 is not set
-# CONFIG_IPX is not set
-# CONFIG_ATALK is not set
-# CONFIG_X25 is not set
-# CONFIG_LAPB is not set
-# CONFIG_ECONET is not set
-# CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
-
-#
-# Network testing
-#
-# CONFIG_NET_PKTGEN is not set
-# CONFIG_HAMRADIO is not set
-# CONFIG_IRDA is not set
-CONFIG_BT=m
-CONFIG_BT_L2CAP=m
-CONFIG_BT_SCO=m
-CONFIG_BT_RFCOMM=m
-# CONFIG_BT_RFCOMM_TTY is not set
-CONFIG_BT_BNEP=m
-# CONFIG_BT_BNEP_MC_FILTER is not set
-# CONFIG_BT_BNEP_PROTO_FILTER is not set
-CONFIG_BT_HIDP=m
-
-#
-# Bluetooth device drivers
-#
-CONFIG_BT_HCIUSB=m
-# CONFIG_BT_HCIUSB_SCO is not set
-CONFIG_BT_HCIUART=m
-# CONFIG_BT_HCIUART_H4 is not set
-# CONFIG_BT_HCIUART_BCSP is not set
-CONFIG_BT_HCIBCM203X=m
-CONFIG_BT_HCIBPA10X=m
-CONFIG_BT_HCIBFUSB=m
-# CONFIG_BT_HCIVHCI is not set
-# CONFIG_AF_RXRPC is not set
-
-#
-# Wireless
-#
-# CONFIG_CFG80211 is not set
-# CONFIG_WIRELESS_EXT is not set
-# CONFIG_MAC80211 is not set
-CONFIG_IEEE80211=m
-# CONFIG_IEEE80211_DEBUG is not set
-CONFIG_IEEE80211_CRYPT_WEP=m
-CONFIG_IEEE80211_CRYPT_CCMP=m
-# CONFIG_IEEE80211_CRYPT_TKIP is not set
-# CONFIG_IEEE80211_SOFTMAC is not set
-# CONFIG_RFKILL is not set
-
-#
-# Device Drivers
-#
-
-#
-# Generic Driver Options
-#
-CONFIG_STANDALONE=y
-CONFIG_PREVENT_FIRMWARE_BUILD=y
-CONFIG_FW_LOADER=y
-# CONFIG_DEBUG_DRIVER is not set
-# CONFIG_DEBUG_DEVRES is not set
-# CONFIG_SYS_HYPERVISOR is not set
-
-#
-# Connector - unified userspace <-> kernelspace linker
-#
-# CONFIG_CONNECTOR is not set
-CONFIG_MTD=y
-# CONFIG_MTD_DEBUG is not set
-CONFIG_MTD_CONCAT=y
-CONFIG_MTD_PARTITIONS=y
-# CONFIG_MTD_REDBOOT_PARTS is not set
-# CONFIG_MTD_CMDLINE_PARTS is not set
-# CONFIG_MTD_AFS_PARTS is not set
-
-#
-# User Modules And Translation Layers
-#
-CONFIG_MTD_CHAR=y
-CONFIG_MTD_BLKDEVS=y
-CONFIG_MTD_BLOCK=y
-# CONFIG_FTL is not set
-# CONFIG_NFTL is not set
-# CONFIG_INFTL is not set
-# CONFIG_RFD_FTL is not set
-# CONFIG_SSFDC is not set
-
-#
-# RAM/ROM/Flash chip drivers
-#
-# CONFIG_MTD_CFI is not set
-# CONFIG_MTD_JEDECPROBE is not set
-# CONFIG_MTD_CFI_NOSWAP is not set
-# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
-# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
-CONFIG_MTD_MAP_BANK_WIDTH_1=y
-CONFIG_MTD_MAP_BANK_WIDTH_2=y
-CONFIG_MTD_MAP_BANK_WIDTH_4=y
-# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
-# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
-CONFIG_MTD_CFI_I1=y
-CONFIG_MTD_CFI_I2=y
-# CONFIG_MTD_CFI_I4 is not set
-# CONFIG_MTD_CFI_I8 is not set
-# CONFIG_MTD_RAM is not set
-# CONFIG_MTD_ROM is not set
-# CONFIG_MTD_ABSENT is not set
-
-#
-# Mapping drivers for chip access
-#
-# CONFIG_MTD_COMPLEX_MAPPINGS is not set
-# CONFIG_MTD_SHARP_SL is not set
-# CONFIG_MTD_PLATRAM is not set
-
-#
-# Self-contained MTD device drivers
-#
-# CONFIG_MTD_SLRAM is not set
-# CONFIG_MTD_PHRAM is not set
-# CONFIG_MTD_MTDRAM is not set
-# CONFIG_MTD_BLOCK2MTD is not set
-
-#
-# Disk-On-Chip Device Drivers
-#
-# CONFIG_MTD_DOC2000 is not set
-# CONFIG_MTD_DOC2001 is not set
-# CONFIG_MTD_DOC2001PLUS is not set
-CONFIG_MTD_NAND=y
-# CONFIG_MTD_NAND_VERIFY_WRITE is not set
-# CONFIG_MTD_NAND_ECC_SMC is not set
-# CONFIG_MTD_NAND_MUSEUM_IDS is not set
-# CONFIG_MTD_NAND_H1900 is not set
-CONFIG_MTD_NAND_IDS=y
-# CONFIG_MTD_NAND_DISKONCHIP is not set
-# CONFIG_MTD_NAND_SHARPSL is not set
-# CONFIG_MTD_NAND_NANDSIM is not set
-CONFIG_MTD_NAND_PLATFORM=y
-# CONFIG_MTD_ONENAND is not set
-
-#
-# UBI - Unsorted block images
-#
-# CONFIG_MTD_UBI is not set
-
-#
-# Parallel port support
-#
-# CONFIG_PARPORT is not set
-
-#
-# Plug and Play support
-#
-# CONFIG_PNPACPI is not set
-
-#
-# Block devices
-#
-# CONFIG_BLK_DEV_COW_COMMON is not set
-CONFIG_BLK_DEV_LOOP=y
-# CONFIG_BLK_DEV_CRYPTOLOOP is not set
-# CONFIG_BLK_DEV_NBD is not set
-# CONFIG_BLK_DEV_UB is not set
-CONFIG_BLK_DEV_RAM=y
-CONFIG_BLK_DEV_RAM_COUNT=16
-CONFIG_BLK_DEV_RAM_SIZE=12000
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
-# CONFIG_CDROM_PKTCDVD is not set
-# CONFIG_ATA_OVER_ETH is not set
-# CONFIG_IDE is not set
-
-#
-# SCSI device support
-#
-# CONFIG_RAID_ATTRS is not set
-CONFIG_SCSI=y
-# CONFIG_SCSI_TGT is not set
-# CONFIG_SCSI_NETLINK is not set
-# CONFIG_SCSI_PROC_FS is not set
-
-#
-# SCSI support type (disk, tape, CD-ROM)
-#
-CONFIG_BLK_DEV_SD=y
-# CONFIG_CHR_DEV_ST is not set
-# CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
-# CONFIG_CHR_DEV_SG is not set
-# CONFIG_CHR_DEV_SCH is not set
-
-#
-# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
-#
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
-# CONFIG_SCSI_LOGGING is not set
-# CONFIG_SCSI_SCAN_ASYNC is not set
-CONFIG_SCSI_WAIT_SCAN=m
-
-#
-# SCSI Transports
-#
-# CONFIG_SCSI_SPI_ATTRS is not set
-# CONFIG_SCSI_FC_ATTRS is not set
-# CONFIG_SCSI_ISCSI_ATTRS is not set
-# CONFIG_SCSI_SAS_ATTRS is not set
-# CONFIG_SCSI_SAS_LIBSAS is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_ISCSI_TCP is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_ATA is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
-# CONFIG_MD is not set
-
-#
-# Network device support
-#
-CONFIG_NETDEVICES=y
-# CONFIG_DUMMY is not set
-# CONFIG_BONDING is not set
-# CONFIG_EQUALIZER is not set
-# CONFIG_TUN is not set
-# CONFIG_PHYLIB is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
-CONFIG_NET_ETHERNET=y
-CONFIG_MII=y
-# CONFIG_SMC91X is not set
-CONFIG_DM9000=y
-# CONFIG_SMC911X is not set
-# CONFIG_NETDEV_1000 is not set
-# CONFIG_NETDEV_10000 is not set
-
-#
-# Wireless LAN
-#
-# CONFIG_WLAN_PRE80211 is not set
-# CONFIG_WLAN_80211 is not set
-
-#
-# USB Network Adapters
-#
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_USBNET_MII is not set
-# CONFIG_USB_USBNET is not set
-# CONFIG_WAN is not set
-# CONFIG_PPP is not set
-# CONFIG_SLIP is not set
-# CONFIG_SHAPER is not set
-# CONFIG_NETCONSOLE is not set
-# CONFIG_NETPOLL is not set
-# CONFIG_NET_POLL_CONTROLLER is not set
-
-#
-# ISDN subsystem
-#
-# CONFIG_ISDN is not set
-
-#
-# Input device support
-#
-CONFIG_INPUT=y
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_POLLDEV is not set
-
-#
-# Userland interfaces
-#
-CONFIG_INPUT_MOUSEDEV=y
-# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
-CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
-CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
-# CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
-CONFIG_INPUT_EVDEV=y
-# CONFIG_INPUT_EVBUG is not set
-
-#
-# Input Device Drivers
-#
-CONFIG_INPUT_KEYBOARD=y
-# CONFIG_KEYBOARD_ATKBD is not set
-# CONFIG_KEYBOARD_SUNKBD is not set
-# CONFIG_KEYBOARD_LKKBD is not set
-# CONFIG_KEYBOARD_XTKBD is not set
-# CONFIG_KEYBOARD_NEWTON is not set
-# CONFIG_KEYBOARD_STOWAWAY is not set
-CONFIG_KEYBOARD_PXA27x=m
-# CONFIG_KEYBOARD_GPIO is not set
-# CONFIG_INPUT_MOUSE is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_TABLET is not set
-CONFIG_INPUT_TOUCHSCREEN=y
-# CONFIG_TOUCHSCREEN_GUNZE is not set
-# CONFIG_TOUCHSCREEN_ELO is not set
-# CONFIG_TOUCHSCREEN_MTOUCH is not set
-# CONFIG_TOUCHSCREEN_MK712 is not set
-# CONFIG_TOUCHSCREEN_PENMOUNT is not set
-# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
-# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
-# CONFIG_TOUCHSCREEN_UCB1400 is not set
-# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
-# CONFIG_INPUT_MISC is not set
-
-#
-# Hardware I/O ports
-#
-CONFIG_SERIO=y
-# CONFIG_SERIO_SERPORT is not set
-CONFIG_SERIO_LIBPS2=y
-# CONFIG_SERIO_RAW is not set
-# CONFIG_GAMEPORT is not set
-
-#
-# Character devices
-#
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
-
-#
-# Serial drivers
-#
-# CONFIG_SERIAL_8250 is not set
-
-#
-# Non-8250 serial port support
-#
-CONFIG_SERIAL_PXA=y
-CONFIG_SERIAL_PXA_CONSOLE=y
-CONFIG_SERIAL_CORE=y
-CONFIG_SERIAL_CORE_CONSOLE=y
-CONFIG_UNIX98_PTYS=y
-CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=256
-
-#
-# IPMI
-#
-# CONFIG_IPMI_HANDLER is not set
-# CONFIG_WATCHDOG is not set
-CONFIG_HW_RANDOM=m
-# CONFIG_NVRAM is not set
-# CONFIG_R3964 is not set
-# CONFIG_RAW_DRIVER is not set
-
-#
-# TPM devices
-#
-# CONFIG_TCG_TPM is not set
-# CONFIG_I2C is not set
-
-#
-# SPI support
-#
-# CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
-
-#
-# Dallas's 1-wire bus
-#
-# CONFIG_W1 is not set
-# CONFIG_HWMON is not set
-
-#
-# Misc devices
-#
-
-#
-# Multifunction device drivers
-#
-# CONFIG_MFD_SM501 is not set
-
-#
-# LED devices
-#
-# CONFIG_NEW_LEDS is not set
-
-#
-# LED drivers
-#
-
-#
-# LED Triggers
-#
-
-#
-# Multimedia devices
-#
-# CONFIG_VIDEO_DEV is not set
-# CONFIG_DVB_CORE is not set
-# CONFIG_DAB is not set
-
-#
-# Graphics support
-#
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
-
-#
-# Display device support
-#
-# CONFIG_DISPLAY_SUPPORT is not set
-# CONFIG_VGASTATE is not set
-CONFIG_FB=y
-# CONFIG_FIRMWARE_EDID is not set
-# CONFIG_FB_DDC is not set
-CONFIG_FB_CFB_FILLRECT=y
-CONFIG_FB_CFB_COPYAREA=y
-CONFIG_FB_CFB_IMAGEBLIT=y
-# CONFIG_FB_SYS_FILLRECT is not set
-# CONFIG_FB_SYS_COPYAREA is not set
-# CONFIG_FB_SYS_IMAGEBLIT is not set
-# CONFIG_FB_SYS_FOPS is not set
-CONFIG_FB_DEFERRED_IO=y
-# CONFIG_FB_SVGALIB is not set
-# CONFIG_FB_MACMODES is not set
-# CONFIG_FB_BACKLIGHT is not set
-# CONFIG_FB_MODE_HELPERS is not set
-# CONFIG_FB_TILEBLITTING is not set
-
-#
-# Frame buffer hardware drivers
-#
-# CONFIG_FB_S1D13XXX is not set
-CONFIG_FB_PXA=y
-# CONFIG_FB_PXA_PARAMETERS is not set
-# CONFIG_FB_MBX is not set
-# CONFIG_FB_VIRTUAL is not set
-
-#
-# Console display driver support
-#
-# CONFIG_VGA_CONSOLE is not set
-CONFIG_DUMMY_CONSOLE=y
-CONFIG_FRAMEBUFFER_CONSOLE=y
-# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
-# CONFIG_FONTS is not set
-CONFIG_FONT_8x8=y
-CONFIG_FONT_8x16=y
-CONFIG_LOGO=y
-CONFIG_LOGO_LINUX_MONO=y
-CONFIG_LOGO_LINUX_VGA16=y
-CONFIG_LOGO_LINUX_CLUT224=y
-
-#
-# Sound
-#
-CONFIG_SOUND=m
-
-#
-# Advanced Linux Sound Architecture
-#
-CONFIG_SND=m
-CONFIG_SND_TIMER=m
-CONFIG_SND_PCM=m
-# CONFIG_SND_SEQUENCER is not set
-CONFIG_SND_OSSEMUL=y
-CONFIG_SND_MIXER_OSS=m
-CONFIG_SND_PCM_OSS=m
-CONFIG_SND_PCM_OSS_PLUGINS=y
-# CONFIG_SND_DYNAMIC_MINORS is not set
-CONFIG_SND_SUPPORT_OLD_API=y
-CONFIG_SND_VERBOSE_PROCFS=y
-# CONFIG_SND_VERBOSE_PRINTK is not set
-# CONFIG_SND_DEBUG is not set
-
-#
-# Generic devices
-#
-CONFIG_SND_AC97_CODEC=m
-# CONFIG_SND_DUMMY is not set
-# CONFIG_SND_MTPAV is not set
-# CONFIG_SND_SERIAL_U16550 is not set
-# CONFIG_SND_MPU401 is not set
-
-#
-# ALSA ARM devices
-#
-CONFIG_SND_PXA2XX_PCM=m
-CONFIG_SND_PXA2XX_AC97=m
-
-#
-# USB devices
-#
-# CONFIG_SND_USB_AUDIO is not set
-# CONFIG_SND_USB_CAIAQ is not set
-
-#
-# System on Chip audio support
-#
-# CONFIG_SND_SOC is not set
-
-#
-# Open Sound System
-#
-# CONFIG_SOUND_PRIME is not set
-CONFIG_AC97_BUS=m
-
-#
-# HID Devices
-#
-CONFIG_HID=y
-# CONFIG_HID_DEBUG is not set
-
-#
-# USB Input Devices
-#
-CONFIG_USB_HID=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_HID_FF is not set
-# CONFIG_USB_HIDDEV is not set
-
-#
-# USB support
-#
-CONFIG_USB_ARCH_HAS_HCD=y
-CONFIG_USB_ARCH_HAS_OHCI=y
-# CONFIG_USB_ARCH_HAS_EHCI is not set
-CONFIG_USB=y
-# CONFIG_USB_DEBUG is not set
-
-#
-# Miscellaneous USB options
-#
-CONFIG_USB_DEVICEFS=y
-# CONFIG_USB_DEVICE_CLASS is not set
-# CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
-# CONFIG_USB_OTG is not set
-
-#
-# USB Host Controller Drivers
-#
-# CONFIG_USB_ISP116X_HCD is not set
-CONFIG_USB_OHCI_HCD=y
-# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
-# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
-CONFIG_USB_OHCI_LITTLE_ENDIAN=y
-# CONFIG_USB_SL811_HCD is not set
-
-#
-# USB Device Class drivers
-#
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
-
-#
-# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
-#
-
-#
-# may also be needed; see USB_STORAGE Help for more information
-#
-CONFIG_USB_STORAGE=y
-# CONFIG_USB_STORAGE_DEBUG is not set
-# CONFIG_USB_STORAGE_DATAFAB is not set
-# CONFIG_USB_STORAGE_FREECOM is not set
-# CONFIG_USB_STORAGE_DPCM is not set
-# CONFIG_USB_STORAGE_USBAT is not set
-# CONFIG_USB_STORAGE_SDDR09 is not set
-# CONFIG_USB_STORAGE_SDDR55 is not set
-# CONFIG_USB_STORAGE_JUMPSHOT is not set
-# CONFIG_USB_STORAGE_ALAUDA is not set
-# CONFIG_USB_STORAGE_KARMA is not set
-# CONFIG_USB_LIBUSUAL is not set
-
-#
-# USB Imaging devices
-#
-# CONFIG_USB_MDC800 is not set
-# CONFIG_USB_MICROTEK is not set
-# CONFIG_USB_MON is not set
-
-#
-# USB port drivers
-#
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
-
-#
-# USB Miscellaneous drivers
-#
-# CONFIG_USB_EMI62 is not set
-# CONFIG_USB_EMI26 is not set
-# CONFIG_USB_ADUTUX is not set
-# CONFIG_USB_AUERSWALD is not set
-# CONFIG_USB_RIO500 is not set
-# CONFIG_USB_LEGOTOWER is not set
-# CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
-# CONFIG_USB_LED is not set
-# CONFIG_USB_CYPRESS_CY7C63 is not set
-# CONFIG_USB_CYTHERM is not set
-# CONFIG_USB_PHIDGET is not set
-# CONFIG_USB_IDMOUSE is not set
-# CONFIG_USB_FTDI_ELAN is not set
-# CONFIG_USB_APPLEDISPLAY is not set
-# CONFIG_USB_LD is not set
-# CONFIG_USB_TRANCEVIBRATOR is not set
-# CONFIG_USB_IOWARRIOR is not set
-# CONFIG_USB_TEST is not set
-
-#
-# USB DSL modem support
-#
-
-#
-# USB Gadget Support
-#
-# CONFIG_USB_GADGET is not set
-CONFIG_MMC=m
-# CONFIG_MMC_DEBUG is not set
-# CONFIG_MMC_UNSAFE_RESUME is not set
-
-#
-# MMC/SD Card Drivers
-#
-CONFIG_MMC_BLOCK=m
-
-#
-# MMC/SD Host Controller Drivers
-#
-CONFIG_MMC_PXA=m
-
-#
-# Real Time Clock
-#
-CONFIG_RTC_LIB=y
-CONFIG_RTC_CLASS=m
-
-#
-# RTC interfaces
-#
-CONFIG_RTC_INTF_SYSFS=y
-CONFIG_RTC_INTF_PROC=y
-CONFIG_RTC_INTF_DEV=y
-# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
-# CONFIG_RTC_DRV_TEST is not set
-
-#
-# I2C RTC drivers
-#
-
-#
-# SPI RTC drivers
-#
-
-#
-# Platform RTC drivers
-#
-# CONFIG_RTC_DRV_CMOS is not set
-# CONFIG_RTC_DRV_DS1553 is not set
-# CONFIG_RTC_DRV_DS1742 is not set
-# CONFIG_RTC_DRV_M48T86 is not set
-CONFIG_RTC_DRV_V3020=m
-
-#
-# on-CPU RTC drivers
-#
-CONFIG_RTC_DRV_SA1100=m
-
-#
-# File systems
-#
-CONFIG_EXT2_FS=y
-# CONFIG_EXT2_FS_XATTR is not set
-# CONFIG_EXT2_FS_XIP is not set
-CONFIG_EXT3_FS=y
-CONFIG_EXT3_FS_XATTR=y
-# CONFIG_EXT3_FS_POSIX_ACL is not set
-# CONFIG_EXT3_FS_SECURITY is not set
-# CONFIG_EXT4DEV_FS is not set
-CONFIG_JBD=y
-# CONFIG_JBD_DEBUG is not set
-CONFIG_FS_MBCACHE=y
-# CONFIG_REISERFS_FS is not set
-# CONFIG_JFS_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
-# CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
-CONFIG_INOTIFY=y
-CONFIG_INOTIFY_USER=y
-# CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
-# CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_FUSE_FS is not set
-
-#
-# CD-ROM/DVD Filesystems
-#
-# CONFIG_ISO9660_FS is not set
-# CONFIG_UDF_FS is not set
-
-#
-# DOS/FAT/NT Filesystems
-#
-CONFIG_FAT_FS=y
-CONFIG_MSDOS_FS=y
-CONFIG_VFAT_FS=y
-CONFIG_FAT_DEFAULT_CODEPAGE=437
-CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
-# CONFIG_NTFS_FS is not set
-
-#
-# Pseudo filesystems
-#
-CONFIG_PROC_FS=y
-CONFIG_PROC_SYSCTL=y
-CONFIG_SYSFS=y
-CONFIG_TMPFS=y
-# CONFIG_TMPFS_POSIX_ACL is not set
-# CONFIG_HUGETLB_PAGE is not set
-CONFIG_RAMFS=y
-# CONFIG_CONFIGFS_FS is not set
-
-#
-# Miscellaneous filesystems
-#
-# CONFIG_ADFS_FS is not set
-# CONFIG_AFFS_FS is not set
-# CONFIG_HFS_FS is not set
-# CONFIG_HFSPLUS_FS is not set
-# CONFIG_BEFS_FS is not set
-# CONFIG_BFS_FS is not set
-# CONFIG_EFS_FS is not set
-CONFIG_JFFS2_FS=y
-CONFIG_JFFS2_FS_DEBUG=0
-CONFIG_JFFS2_FS_WRITEBUFFER=y
-CONFIG_JFFS2_SUMMARY=y
-# CONFIG_JFFS2_FS_XATTR is not set
-# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
-CONFIG_JFFS2_ZLIB=y
-CONFIG_JFFS2_RTIME=y
-# CONFIG_JFFS2_RUBIN is not set
-# CONFIG_CRAMFS is not set
-# CONFIG_VXFS_FS is not set
-# CONFIG_HPFS_FS is not set
-# CONFIG_QNX4FS_FS is not set
-# CONFIG_SYSV_FS is not set
-# CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
-# CONFIG_NFSD is not set
-CONFIG_ROOT_NFS=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-CONFIG_NFS_COMMON=y
-CONFIG_SUNRPC=y
-# CONFIG_SUNRPC_BIND34 is not set
-# CONFIG_RPCSEC_GSS_KRB5 is not set
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
-CONFIG_SMB_FS=y
-# CONFIG_SMB_NLS_DEFAULT is not set
-# CONFIG_CIFS is not set
-# CONFIG_NCP_FS is not set
-# CONFIG_CODA_FS is not set
-# CONFIG_AFS_FS is not set
-# CONFIG_9P_FS is not set
-
-#
-# Partition Types
-#
-# CONFIG_PARTITION_ADVANCED is not set
-CONFIG_MSDOS_PARTITION=y
-
-#
-# Native Language Support
-#
-CONFIG_NLS=y
-CONFIG_NLS_DEFAULT="iso8859-1"
-CONFIG_NLS_CODEPAGE_437=y
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1250 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-CONFIG_NLS_ISO8859_1=y
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-CONFIG_NLS_UTF8=y
-
-#
-# Distributed Lock Manager
-#
-# CONFIG_DLM is not set
-
-#
-# Profiling support
-#
-# CONFIG_PROFILING is not set
-
-#
-# Kernel hacking
-#
-# CONFIG_PRINTK_TIME is not set
-CONFIG_ENABLE_MUST_CHECK=y
-CONFIG_MAGIC_SYSRQ=y
-# CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_DEBUG_FS is not set
-# CONFIG_HEADERS_CHECK is not set
-CONFIG_DEBUG_KERNEL=y
-# CONFIG_DEBUG_SHIRQ is not set
-# CONFIG_DETECT_SOFTLOCKUP is not set
-# CONFIG_SCHEDSTATS is not set
-# CONFIG_TIMER_STATS is not set
-# CONFIG_DEBUG_SLAB is not set
-# CONFIG_DEBUG_RT_MUTEXES is not set
-# CONFIG_RT_MUTEX_TESTER is not set
-# CONFIG_DEBUG_SPINLOCK is not set
-# CONFIG_DEBUG_MUTEXES is not set
-# CONFIG_DEBUG_LOCK_ALLOC is not set
-# CONFIG_PROVE_LOCKING is not set
-# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
-# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-# CONFIG_DEBUG_KOBJECT is not set
-# CONFIG_DEBUG_BUGVERBOSE is not set
-CONFIG_DEBUG_INFO=y
-# CONFIG_DEBUG_VM is not set
-# CONFIG_DEBUG_LIST is not set
-CONFIG_FRAME_POINTER=y
-CONFIG_FORCED_INLINING=y
-# CONFIG_RCU_TORTURE_TEST is not set
-# CONFIG_FAULT_INJECTION is not set
-CONFIG_DEBUG_USER=y
-CONFIG_DEBUG_ERRORS=y
-CONFIG_DEBUG_LL=y
-# CONFIG_DEBUG_ICEDCC is not set
-
-#
-# Security options
-#
-# CONFIG_KEYS is not set
-# CONFIG_SECURITY is not set
-
-#
-# Cryptographic options
-#
-CONFIG_CRYPTO=y
-CONFIG_CRYPTO_ALGAPI=m
-CONFIG_CRYPTO_BLKCIPHER=m
-CONFIG_CRYPTO_MANAGER=m
-# CONFIG_CRYPTO_HMAC is not set
-# CONFIG_CRYPTO_XCBC is not set
-# CONFIG_CRYPTO_NULL is not set
-# CONFIG_CRYPTO_MD4 is not set
-# CONFIG_CRYPTO_MD5 is not set
-# CONFIG_CRYPTO_SHA1 is not set
-# CONFIG_CRYPTO_SHA256 is not set
-# CONFIG_CRYPTO_SHA512 is not set
-# CONFIG_CRYPTO_WP512 is not set
-# CONFIG_CRYPTO_TGR192 is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-CONFIG_CRYPTO_ECB=m
-CONFIG_CRYPTO_CBC=m
-CONFIG_CRYPTO_PCBC=m
-# CONFIG_CRYPTO_LRW is not set
-# CONFIG_CRYPTO_CRYPTD is not set
-# CONFIG_CRYPTO_DES is not set
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_BLOWFISH is not set
-# CONFIG_CRYPTO_TWOFISH is not set
-# CONFIG_CRYPTO_SERPENT is not set
-CONFIG_CRYPTO_AES=m
-# CONFIG_CRYPTO_CAST5 is not set
-# CONFIG_CRYPTO_CAST6 is not set
-# CONFIG_CRYPTO_TEA is not set
-CONFIG_CRYPTO_ARC4=m
-# CONFIG_CRYPTO_KHAZAD is not set
-# CONFIG_CRYPTO_ANUBIS is not set
-# CONFIG_CRYPTO_DEFLATE is not set
-# CONFIG_CRYPTO_MICHAEL_MIC is not set
-# CONFIG_CRYPTO_CRC32C is not set
-# CONFIG_CRYPTO_CAMELLIA is not set
-# CONFIG_CRYPTO_TEST is not set
-
-#
-# Hardware crypto devices
-#
-
-#
-# Library routines
-#
-CONFIG_BITREVERSE=y
-# CONFIG_CRC_CCITT is not set
-# CONFIG_CRC16 is not set
-# CONFIG_CRC_ITU_T is not set
-CONFIG_CRC32=y
-# CONFIG_LIBCRC32C is not set
-CONFIG_ZLIB_INFLATE=y
-CONFIG_ZLIB_DEFLATE=y
-CONFIG_PLIST=y
-CONFIG_HAS_IOMEM=y
-CONFIG_HAS_IOPORT=y
-CONFIG_HAS_DMA=y
index 24a701a..21aa013 100644 (file)
@@ -184,7 +184,6 @@ CONFIG_ARM_AMBA=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index ed487b9..493ecee 100644 (file)
@@ -251,7 +251,6 @@ CONFIG_PCMCIA_PXA2XX=m
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 CONFIG_AEABI=y
 CONFIG_OABI_COMPAT=y
diff --git a/arch/arm/configs/imx27ads_defconfig b/arch/arm/configs/imx27ads_defconfig
new file mode 100644 (file)
index 0000000..bcd95b8
--- /dev/null
@@ -0,0 +1,826 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc6
+# Fri Jun 20 16:29:34 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_POSIX_MQUEUE=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+# CONFIG_KMOD is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_AS is not set
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+CONFIG_DEFAULT_NOOP=y
+CONFIG_DEFAULT_IOSCHED="noop"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_MXC=y
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Freescale MXC Implementations
+#
+CONFIG_ARCH_MX2=y
+# CONFIG_ARCH_MX3 is not set
+
+#
+# MX2 family CPU support
+#
+CONFIG_MACH_MX27=y
+
+#
+# MX2 Platforms
+#
+CONFIG_MACH_MX27ADS=y
+# CONFIG_MACH_PCM038 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+# CONFIG_IP_PNP_BOOTP is not set
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_FW_LOADER is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+# CONFIG_MTD_CFI_I2 is not set
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+# CONFIG_MTD_CFI_AMDSTD is not set
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+# CONFIG_MTD_XIP is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x00000000
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=2
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+# CONFIG_MTD_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_FEC_OLD is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+# CONFIG_SERIAL_IMX is not set
+CONFIG_UNIX98_PTYS=y
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_HAVE_GPIO_LIB=y
+
+#
+# GPIO Support
+#
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+# CONFIG_EXT2_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_DNOTIFY is not set
+# CONFIG_INOTIFY is not set
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=m
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=m
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+CONFIG_NLS_ISO8859_15=m
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index 988b4d1..482e570 100644 (file)
@@ -197,7 +197,6 @@ CONFIG_PCI_LEGACY=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 83f40d4..8612f58 100644 (file)
@@ -201,7 +201,6 @@ CONFIG_PCI_LEGACY=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 917afb5..8b0098d 100644 (file)
@@ -197,7 +197,6 @@ CONFIG_PCI_LEGACY=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index f8f9793..84680db 100644 (file)
@@ -184,7 +184,6 @@ CONFIG_PCI=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 27cf022..4a2f7b2 100644 (file)
@@ -180,7 +180,6 @@ CONFIG_PCI=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index efa0485..fc14932 100644 (file)
@@ -165,6 +165,7 @@ CONFIG_ARCH_PRPMC1100=y
 CONFIG_MACH_NAS100D=y
 CONFIG_MACH_DSMG600=y
 CONFIG_ARCH_IXDP4XX=y
+CONFIG_MACH_FSG=y
 CONFIG_CPU_IXP46X=y
 CONFIG_CPU_IXP43X=y
 CONFIG_MACH_GTWX5715=y
@@ -770,7 +771,7 @@ CONFIG_ATA=y
 # CONFIG_SATA_SIL24 is not set
 # CONFIG_SATA_SIS is not set
 # CONFIG_SATA_ULI is not set
-# CONFIG_SATA_VIA is not set
+CONFIG_SATA_VIA=y
 # CONFIG_SATA_VITESSE is not set
 # CONFIG_SATA_INIC162X is not set
 # CONFIG_PATA_ALI is not set
@@ -1143,7 +1144,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_VIA686A is not set
 # CONFIG_SENSORS_VT1211 is not set
 # CONFIG_SENSORS_VT8231 is not set
-# CONFIG_SENSORS_W83781D is not set
+CONFIG_SENSORS_W83781D=y
 # CONFIG_SENSORS_W83791D is not set
 # CONFIG_SENSORS_W83792D is not set
 # CONFIG_SENSORS_W83793 is not set
@@ -1334,8 +1335,8 @@ CONFIG_LEDS_CLASS=y
 #
 # LED drivers
 #
-# CONFIG_LEDS_IXP4XX is not set
 CONFIG_LEDS_GPIO=y
+CONFIG_LEDS_FSG=y
 
 #
 # LED Triggers
@@ -1367,7 +1368,7 @@ CONFIG_RTC_INTF_DEV=y
 # CONFIG_RTC_DRV_DS1672 is not set
 # CONFIG_RTC_DRV_MAX6900 is not set
 # CONFIG_RTC_DRV_RS5C372 is not set
-# CONFIG_RTC_DRV_ISL1208 is not set
+CONFIG_RTC_DRV_ISL1208=y
 CONFIG_RTC_DRV_X1205=y
 CONFIG_RTC_DRV_PCF8563=y
 # CONFIG_RTC_DRV_PCF8583 is not set
index ae51a40..6dd95a2 100644 (file)
@@ -162,7 +162,6 @@ CONFIG_CPU_TLB_V4WBI=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index c16537d..8e74c66 100644 (file)
@@ -126,7 +126,6 @@ CONFIG_ISA_DMA_API=y
 #
 # Kernel Features
 #
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_FLATMEM=y
 CONFIG_FLAT_NODE_MEM_MAP=y
diff --git a/arch/arm/configs/kirkwood_defconfig b/arch/arm/configs/kirkwood_defconfig
new file mode 100644 (file)
index 0000000..e3357ba
--- /dev/null
@@ -0,0 +1,1426 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc5
+# Sun Jun 22 15:51:25 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+# CONFIG_KMOD is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+CONFIG_ARCH_KIRKWOOD=y
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Marvell Kirkwood Implementations
+#
+CONFIG_MACH_DB88F6281_BP=y
+CONFIG_MACH_RD88F6192_NAS=y
+CONFIG_MACH_RD88F6281=y
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+CONFIG_PLAT_ORION=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_FEROCEON=y
+# CONFIG_CPU_FEROCEON_OLD_ID is not set
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5T=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_FEROCEON=y
+CONFIG_CPU_TLB_FEROCEON=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+CONFIG_OUTER_CACHE=y
+CONFIG_CACHE_FEROCEON_L2=y
+
+#
+# Bus support
+#
+CONFIG_PCI=y
+CONFIG_PCI_SYSCALL=y
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+CONFIG_PCI_LEGACY=y
+# CONFIG_PCI_DEBUG is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+CONFIG_NET_PKTGEN=m
+# CONFIG_NET_TCPPROBE is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_EXT=y
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+# CONFIG_MTD_CFI_AMDSTD is not set
+CONFIG_MTD_CFI_STAA=y
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=0
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_IMPA7 is not set
+# CONFIG_MTD_INTEL_VR_NOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_PMC551 is not set
+# CONFIG_MTD_DATAFLASH is not set
+CONFIG_MTD_M25P80=y
+CONFIG_M25PXX_USE_FAST_READ=y
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+CONFIG_MTD_NAND_VERIFY_WRITE=y
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_CAFE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+CONFIG_MTD_NAND_ORION=y
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+CONFIG_BLK_DEV_SR=m
+# CONFIG_BLK_DEV_SR_VENDOR is not set
+CONFIG_CHR_DEV_SG=m
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
+# CONFIG_SCSI_3W_9XXX is not set
+# CONFIG_SCSI_ACARD is not set
+# CONFIG_SCSI_AACRAID is not set
+# CONFIG_SCSI_AIC7XXX is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_AIC79XX is not set
+# CONFIG_SCSI_AIC94XX is not set
+# CONFIG_SCSI_DPT_I2O is not set
+# CONFIG_SCSI_ADVANSYS is not set
+# CONFIG_SCSI_ARCMSR is not set
+# CONFIG_MEGARAID_NEWGEN is not set
+# CONFIG_MEGARAID_LEGACY is not set
+# CONFIG_MEGARAID_SAS is not set
+# CONFIG_SCSI_HPTIOP is not set
+# CONFIG_SCSI_DMX3191D is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_IPS is not set
+# CONFIG_SCSI_INITIO is not set
+# CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_MVSAS is not set
+# CONFIG_SCSI_STEX is not set
+# CONFIG_SCSI_SYM53C8XX_2 is not set
+# CONFIG_SCSI_IPR is not set
+# CONFIG_SCSI_QLOGIC_1280 is not set
+# CONFIG_SCSI_QLA_FC is not set
+# CONFIG_SCSI_QLA_ISCSI is not set
+# CONFIG_SCSI_LPFC is not set
+# CONFIG_SCSI_DC395x is not set
+# CONFIG_SCSI_DC390T is not set
+# CONFIG_SCSI_NSP32 is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_SCSI_SRP is not set
+CONFIG_ATA=y
+# CONFIG_ATA_NONSTANDARD is not set
+CONFIG_SATA_PMP=y
+# CONFIG_SATA_AHCI is not set
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
+# CONFIG_SATA_SVW is not set
+# CONFIG_ATA_PIIX is not set
+CONFIG_SATA_MV=y
+# CONFIG_SATA_NV is not set
+# CONFIG_PDC_ADMA is not set
+# CONFIG_SATA_QSTOR is not set
+# CONFIG_SATA_PROMISE is not set
+# CONFIG_SATA_SX4 is not set
+# CONFIG_SATA_SIL is not set
+# CONFIG_SATA_SIS is not set
+# CONFIG_SATA_ULI is not set
+# CONFIG_SATA_VIA is not set
+# CONFIG_SATA_VITESSE is not set
+# CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ALI is not set
+# CONFIG_PATA_AMD is not set
+# CONFIG_PATA_ARTOP is not set
+# CONFIG_PATA_ATIIXP is not set
+# CONFIG_PATA_CMD640_PCI is not set
+# CONFIG_PATA_CMD64X is not set
+# CONFIG_PATA_CS5520 is not set
+# CONFIG_PATA_CS5530 is not set
+# CONFIG_PATA_CYPRESS is not set
+# CONFIG_PATA_EFAR is not set
+# CONFIG_ATA_GENERIC is not set
+# CONFIG_PATA_HPT366 is not set
+# CONFIG_PATA_HPT37X is not set
+# CONFIG_PATA_HPT3X2N is not set
+# CONFIG_PATA_HPT3X3 is not set
+# CONFIG_PATA_IT821X is not set
+# CONFIG_PATA_IT8213 is not set
+# CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_TRIFLEX is not set
+# CONFIG_PATA_MARVELL is not set
+# CONFIG_PATA_MPIIX is not set
+# CONFIG_PATA_OLDPIIX is not set
+# CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NINJA32 is not set
+# CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
+# CONFIG_PATA_OPTI is not set
+# CONFIG_PATA_OPTIDMA is not set
+# CONFIG_PATA_PDC_OLD is not set
+# CONFIG_PATA_RADISYS is not set
+# CONFIG_PATA_RZ1000 is not set
+# CONFIG_PATA_SC1200 is not set
+# CONFIG_PATA_SERVERWORKS is not set
+# CONFIG_PATA_PDC2027X is not set
+# CONFIG_PATA_SIL680 is not set
+# CONFIG_PATA_SIS is not set
+# CONFIG_PATA_VIA is not set
+# CONFIG_PATA_WINBOND is not set
+# CONFIG_PATA_PLATFORM is not set
+# CONFIG_PATA_SCH is not set
+# CONFIG_MD is not set
+# CONFIG_FUSION is not set
+
+#
+# IEEE 1394 (FireWire) support
+#
+# CONFIG_FIREWIRE is not set
+# CONFIG_IEEE1394 is not set
+# CONFIG_I2O is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_ARCNET is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_CASSINI is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_NET_TULIP is not set
+# CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_B44 is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_8139CP is not set
+# CONFIG_8139TOO is not set
+# CONFIG_R6040 is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_SC92031 is not set
+CONFIG_NETDEV_1000=y
+# CONFIG_ACENIC is not set
+# CONFIG_DL2K is not set
+CONFIG_E1000=y
+CONFIG_E1000_NAPI=y
+# CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
+# CONFIG_E1000E is not set
+# CONFIG_E1000E_ENABLED is not set
+# CONFIG_IP1000 is not set
+# CONFIG_IGB is not set
+# CONFIG_NS83820 is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
+# CONFIG_SIS190 is not set
+# CONFIG_SKGE is not set
+# CONFIG_SKY2 is not set
+# CONFIG_VIA_VELOCITY is not set
+# CONFIG_TIGON3 is not set
+# CONFIG_BNX2 is not set
+CONFIG_MV643XX_ETH=y
+# CONFIG_QLA3XXX is not set
+# CONFIG_ATL1 is not set
+# CONFIG_NETDEV_10000 is not set
+# CONFIG_TR is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NET_FC is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_MOUSEDEV_PSAUX=y
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+# CONFIG_DEVKMEM is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+# CONFIG_NOZOMI is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+# CONFIG_SERIAL_8250_PCI is not set
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=2
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_JSM is not set
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_DEVPORT=y
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_GPIO is not set
+# CONFIG_I2C_I801 is not set
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+# CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+CONFIG_I2C_MV64XXX=y
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+CONFIG_SPI=y
+# CONFIG_SPI_DEBUG is not set
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+# CONFIG_SPI_BITBANG is not set
+CONFIG_SPI_ORION=y
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_DRM is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+CONFIG_USB_ARCH_HAS_EHCI=y
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_C67X00_HCD is not set
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_ROOT_HUB_TT=y
+CONFIG_USB_EHCI_TT_NEWSCHED=y
+# CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
+# CONFIG_USB_OHCI_HCD is not set
+# CONFIG_USB_UHCI_HCD is not set
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+CONFIG_USB_PRINTER=y
+# CONFIG_USB_WDM is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+CONFIG_USB_STORAGE_DATAFAB=y
+CONFIG_USB_STORAGE_FREECOM=y
+# CONFIG_USB_STORAGE_ISD200 is not set
+CONFIG_USB_STORAGE_DPCM=y
+# CONFIG_USB_STORAGE_USBAT is not set
+CONFIG_USB_STORAGE_SDDR09=y
+CONFIG_USB_STORAGE_SDDR55=y
+CONFIG_USB_STORAGE_JUMPSHOT=y
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_MON is not set
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_SISUSBVGA is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+# CONFIG_USB_ISIGHTFW is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+# CONFIG_LEDS_CLASS is not set
+
+#
+# LED drivers
+#
+
+#
+# LED Triggers
+#
+# CONFIG_LEDS_TRIGGERS is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+CONFIG_RTC_DRV_MV=y
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_R9701 is not set
+# CONFIG_RTC_DRV_RS5C348 is not set
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_DMADEVICES=y
+
+#
+# DMA Devices
+#
+CONFIG_MV_XOR=y
+CONFIG_DMA_ENGINE=y
+
+#
+# DMA Clients
+#
+# CONFIG_NET_DMA is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_FS_XATTR is not set
+# CONFIG_EXT4DEV_FS is not set
+CONFIG_JBD=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+CONFIG_XFS_FS=y
+# CONFIG_XFS_QUOTA is not set
+# CONFIG_XFS_POSIX_ACL is not set
+# CONFIG_XFS_RT is not set
+# CONFIG_XFS_DEBUG is not set
+# CONFIG_OCFS2_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+CONFIG_ISO9660_FS=y
+CONFIG_JOLIET=y
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=m
+CONFIG_UDF_NLS=y
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+CONFIG_NLS_ISO8859_2=y
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+CONFIG_NLS_UTF8=y
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_PREEMPT is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_LKDTM is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_ASYNC_CORE=y
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=m
+CONFIG_CRYPTO_BLKCIPHER=m
+CONFIG_CRYPTO_MANAGER=m
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=m
+# CONFIG_CRYPTO_LRW is not set
+CONFIG_CRYPTO_PCBC=m
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+# CONFIG_CRYPTO_DEV_HIFN_795X is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_CRC_CCITT=y
+CONFIG_CRC16=y
+CONFIG_CRC_ITU_T=m
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+CONFIG_LIBCRC32C=y
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index 8ab21a0..6077f2c 100644 (file)
@@ -174,7 +174,6 @@ CONFIG_PCCARD_NONSTATIC=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/loki_defconfig b/arch/arm/configs/loki_defconfig
new file mode 100644 (file)
index 0000000..17da7c3
--- /dev/null
@@ -0,0 +1,1147 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc5
+# Fri Jun 13 03:07:49 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+# CONFIG_GENERIC_GPIO is not set
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+# CONFIG_KMOD is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_LOKI=y
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Marvell Loki (88RC8480) Implementations
+#
+CONFIG_MACH_LB88RC8480=y
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+CONFIG_PLAT_ORION=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_FEROCEON=y
+# CONFIG_CPU_FEROCEON_OLD_ID is not set
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5T=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_FEROCEON=y
+CONFIG_CPU_TLB_FEROCEON=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+CONFIG_NET_PKTGEN=m
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_EXT=y
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+CONFIG_FTL=y
+CONFIG_NFTL=y
+# CONFIG_NFTL_RW is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+CONFIG_MTD_CFI_I4=y
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_CFI_AMDSTD=y
+CONFIG_MTD_CFI_STAA=y
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=0
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_IMPA7 is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_DATAFLASH is not set
+CONFIG_MTD_M25P80=y
+CONFIG_M25PXX_USE_FAST_READ=y
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+CONFIG_MTD_NAND_VERIFY_WRITE=y
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+CONFIG_MTD_NAND_ORION=y
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+CONFIG_BLK_DEV_SR=m
+# CONFIG_BLK_DEV_SR_VENDOR is not set
+CONFIG_CHR_DEV_SG=m
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_DEBUG is not set
+CONFIG_ATA=y
+# CONFIG_ATA_NONSTANDARD is not set
+CONFIG_SATA_PMP=y
+CONFIG_ATA_SFF=y
+CONFIG_SATA_MV=y
+# CONFIG_PATA_PLATFORM is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+CONFIG_NETDEV_1000=y
+# CONFIG_E1000E_ENABLED is not set
+CONFIG_MV643XX_ETH=y
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_MOUSEDEV_PSAUX=y
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=2
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=m
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+CONFIG_I2C_MV64XXX=y
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+# CONFIG_USB_ARCH_HAS_OHCI is not set
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_C67X00_HCD is not set
+# CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+CONFIG_USB_PRINTER=y
+# CONFIG_USB_WDM is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+CONFIG_USB_STORAGE_DATAFAB=y
+CONFIG_USB_STORAGE_FREECOM=y
+# CONFIG_USB_STORAGE_ISD200 is not set
+CONFIG_USB_STORAGE_DPCM=y
+# CONFIG_USB_STORAGE_USBAT is not set
+CONFIG_USB_STORAGE_SDDR09=y
+CONFIG_USB_STORAGE_SDDR55=y
+CONFIG_USB_STORAGE_JUMPSHOT=y
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_MON is not set
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+# CONFIG_USB_ISIGHTFW is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+# CONFIG_LEDS_CLASS is not set
+
+#
+# LED drivers
+#
+
+#
+# LED Triggers
+#
+# CONFIG_LEDS_TRIGGERS is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_FS_XATTR is not set
+# CONFIG_EXT4DEV_FS is not set
+CONFIG_JBD=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+CONFIG_XFS_FS=y
+# CONFIG_XFS_QUOTA is not set
+# CONFIG_XFS_POSIX_ACL is not set
+# CONFIG_XFS_RT is not set
+# CONFIG_XFS_DEBUG is not set
+# CONFIG_OCFS2_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+CONFIG_ISO9660_FS=y
+# CONFIG_JOLIET is not set
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=m
+CONFIG_UDF_NLS=y
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_BSD_DISKLABEL=y
+CONFIG_MINIX_SUBPARTITION=y
+CONFIG_SOLARIS_X86_PARTITION=y
+CONFIG_UNIXWARE_DISKLABEL=y
+CONFIG_LDM_PARTITION=y
+CONFIG_LDM_DEBUG=y
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+CONFIG_SUN_PARTITION=y
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+CONFIG_NLS_ISO8859_2=y
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=m
+CONFIG_CRYPTO_BLKCIPHER=m
+CONFIG_CRYPTO_MANAGER=m
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=m
+# CONFIG_CRYPTO_LRW is not set
+CONFIG_CRYPTO_PCBC=m
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_CRC_CCITT=y
+CONFIG_CRC16=y
+CONFIG_CRC_ITU_T=m
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+CONFIG_LIBCRC32C=y
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index a3bf583..1a38d8e 100644 (file)
@@ -173,7 +173,6 @@ CONFIG_XSCALE_PMU=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 46a0f7f..7a2e932 100644 (file)
@@ -148,7 +148,6 @@ CONFIG_ARM_AMBA=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_AEABI is not set
 CONFIG_ARCH_DISCONTIGMEM_ENABLE=y
 CONFIG_SELECT_MEMORY_MODEL=y
diff --git a/arch/arm/configs/mv78xx0_defconfig b/arch/arm/configs/mv78xx0_defconfig
new file mode 100644 (file)
index 0000000..d38ebf8
--- /dev/null
@@ -0,0 +1,1445 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc5
+# Fri Jun 13 02:57:32 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+# CONFIG_GENERIC_GPIO is not set
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_ALL=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+# CONFIG_SLUB_DEBUG is not set
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+# CONFIG_KMOD is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_LOKI is not set
+CONFIG_ARCH_MV78XX0=y
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Marvell MV78xx0 Implementations
+#
+CONFIG_MACH_DB78X00_BP=y
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+CONFIG_PLAT_ORION=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_FEROCEON=y
+CONFIG_CPU_FEROCEON_OLD_ID=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5T=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_FEROCEON=y
+CONFIG_CPU_TLB_FEROCEON=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+CONFIG_OUTER_CACHE=y
+CONFIG_CACHE_FEROCEON_L2=y
+
+#
+# Bus support
+#
+CONFIG_PCI=y
+CONFIG_PCI_SYSCALL=y
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+CONFIG_PCI_LEGACY=y
+# CONFIG_PCI_DEBUG is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+CONFIG_VFP=y
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+CONFIG_NET_PKTGEN=m
+# CONFIG_NET_TCPPROBE is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_EXT=y
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_CFI_AMDSTD=y
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=0
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_IMPA7 is not set
+# CONFIG_MTD_INTEL_VR_NOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_PMC551 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+CONFIG_MTD_NAND_VERIFY_WRITE=y
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_CAFE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+CONFIG_MTD_NAND_ORION=y
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_PHANTOM is not set
+# CONFIG_EEPROM_93CX6 is not set
+# CONFIG_SGI_IOC4 is not set
+# CONFIG_TIFM_CORE is not set
+# CONFIG_ENCLOSURE_SERVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_SCSI_PROC_FS is not set
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+CONFIG_BLK_DEV_SR=m
+# CONFIG_BLK_DEV_SR_VENDOR is not set
+CONFIG_CHR_DEV_SG=m
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
+# CONFIG_SCSI_3W_9XXX is not set
+# CONFIG_SCSI_ACARD is not set
+# CONFIG_SCSI_AACRAID is not set
+# CONFIG_SCSI_AIC7XXX is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_AIC79XX is not set
+# CONFIG_SCSI_AIC94XX is not set
+# CONFIG_SCSI_DPT_I2O is not set
+# CONFIG_SCSI_ADVANSYS is not set
+# CONFIG_SCSI_ARCMSR is not set
+# CONFIG_MEGARAID_NEWGEN is not set
+# CONFIG_MEGARAID_LEGACY is not set
+# CONFIG_MEGARAID_SAS is not set
+# CONFIG_SCSI_HPTIOP is not set
+# CONFIG_SCSI_DMX3191D is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_IPS is not set
+# CONFIG_SCSI_INITIO is not set
+# CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_MVSAS is not set
+# CONFIG_SCSI_STEX is not set
+# CONFIG_SCSI_SYM53C8XX_2 is not set
+# CONFIG_SCSI_IPR is not set
+# CONFIG_SCSI_QLOGIC_1280 is not set
+# CONFIG_SCSI_QLA_FC is not set
+# CONFIG_SCSI_QLA_ISCSI is not set
+# CONFIG_SCSI_LPFC is not set
+# CONFIG_SCSI_DC395x is not set
+# CONFIG_SCSI_DC390T is not set
+# CONFIG_SCSI_NSP32 is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_SCSI_SRP is not set
+CONFIG_ATA=y
+# CONFIG_ATA_NONSTANDARD is not set
+CONFIG_SATA_PMP=y
+# CONFIG_SATA_AHCI is not set
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
+# CONFIG_SATA_SVW is not set
+# CONFIG_ATA_PIIX is not set
+CONFIG_SATA_MV=y
+# CONFIG_SATA_NV is not set
+# CONFIG_PDC_ADMA is not set
+# CONFIG_SATA_QSTOR is not set
+# CONFIG_SATA_PROMISE is not set
+# CONFIG_SATA_SX4 is not set
+# CONFIG_SATA_SIL is not set
+# CONFIG_SATA_SIS is not set
+# CONFIG_SATA_ULI is not set
+# CONFIG_SATA_VIA is not set
+# CONFIG_SATA_VITESSE is not set
+# CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ALI is not set
+# CONFIG_PATA_AMD is not set
+# CONFIG_PATA_ARTOP is not set
+# CONFIG_PATA_ATIIXP is not set
+# CONFIG_PATA_CMD640_PCI is not set
+# CONFIG_PATA_CMD64X is not set
+# CONFIG_PATA_CS5520 is not set
+# CONFIG_PATA_CS5530 is not set
+# CONFIG_PATA_CYPRESS is not set
+# CONFIG_PATA_EFAR is not set
+# CONFIG_ATA_GENERIC is not set
+# CONFIG_PATA_HPT366 is not set
+# CONFIG_PATA_HPT37X is not set
+# CONFIG_PATA_HPT3X2N is not set
+# CONFIG_PATA_HPT3X3 is not set
+# CONFIG_PATA_IT821X is not set
+# CONFIG_PATA_IT8213 is not set
+# CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_TRIFLEX is not set
+# CONFIG_PATA_MARVELL is not set
+# CONFIG_PATA_MPIIX is not set
+# CONFIG_PATA_OLDPIIX is not set
+# CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NINJA32 is not set
+# CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
+# CONFIG_PATA_OPTI is not set
+# CONFIG_PATA_OPTIDMA is not set
+# CONFIG_PATA_PDC_OLD is not set
+# CONFIG_PATA_RADISYS is not set
+# CONFIG_PATA_RZ1000 is not set
+# CONFIG_PATA_SC1200 is not set
+# CONFIG_PATA_SERVERWORKS is not set
+# CONFIG_PATA_PDC2027X is not set
+# CONFIG_PATA_SIL680 is not set
+# CONFIG_PATA_SIS is not set
+# CONFIG_PATA_VIA is not set
+# CONFIG_PATA_WINBOND is not set
+# CONFIG_PATA_PLATFORM is not set
+# CONFIG_PATA_SCH is not set
+# CONFIG_MD is not set
+# CONFIG_FUSION is not set
+
+#
+# IEEE 1394 (FireWire) support
+#
+# CONFIG_FIREWIRE is not set
+# CONFIG_IEEE1394 is not set
+# CONFIG_I2O is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_ARCNET is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_CASSINI is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_NET_TULIP is not set
+# CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_B44 is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_8139CP is not set
+# CONFIG_8139TOO is not set
+# CONFIG_R6040 is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_SC92031 is not set
+CONFIG_NETDEV_1000=y
+# CONFIG_ACENIC is not set
+# CONFIG_DL2K is not set
+# CONFIG_E1000 is not set
+# CONFIG_E1000E is not set
+# CONFIG_E1000E_ENABLED is not set
+# CONFIG_IP1000 is not set
+# CONFIG_IGB is not set
+# CONFIG_NS83820 is not set
+# CONFIG_HAMACHI is not set
+# CONFIG_YELLOWFIN is not set
+# CONFIG_R8169 is not set
+# CONFIG_SIS190 is not set
+# CONFIG_SKGE is not set
+# CONFIG_SKY2 is not set
+# CONFIG_VIA_VELOCITY is not set
+# CONFIG_TIGON3 is not set
+# CONFIG_BNX2 is not set
+CONFIG_MV643XX_ETH=y
+# CONFIG_QLA3XXX is not set
+# CONFIG_ATL1 is not set
+# CONFIG_NETDEV_10000 is not set
+# CONFIG_TR is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NET_FC is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+# CONFIG_NOZOMI is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+# CONFIG_SERIAL_8250_PCI is not set
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=2
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_JSM is not set
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_DEVPORT=y
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_I801 is not set
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+# CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+CONFIG_I2C_MV64XXX=y
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+# CONFIG_SPI is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+CONFIG_HWMON=y
+# CONFIG_HWMON_VID is not set
+# CONFIG_SENSORS_AD7418 is not set
+# CONFIG_SENSORS_ADM1021 is not set
+# CONFIG_SENSORS_ADM1025 is not set
+# CONFIG_SENSORS_ADM1026 is not set
+# CONFIG_SENSORS_ADM1029 is not set
+# CONFIG_SENSORS_ADM1031 is not set
+# CONFIG_SENSORS_ADM9240 is not set
+# CONFIG_SENSORS_ADT7470 is not set
+# CONFIG_SENSORS_ADT7473 is not set
+# CONFIG_SENSORS_ATXP1 is not set
+# CONFIG_SENSORS_DS1621 is not set
+# CONFIG_SENSORS_I5K_AMB is not set
+# CONFIG_SENSORS_F71805F is not set
+# CONFIG_SENSORS_F71882FG is not set
+# CONFIG_SENSORS_F75375S is not set
+# CONFIG_SENSORS_GL518SM is not set
+# CONFIG_SENSORS_GL520SM is not set
+# CONFIG_SENSORS_IT87 is not set
+# CONFIG_SENSORS_LM63 is not set
+# CONFIG_SENSORS_LM75 is not set
+# CONFIG_SENSORS_LM77 is not set
+# CONFIG_SENSORS_LM78 is not set
+# CONFIG_SENSORS_LM80 is not set
+# CONFIG_SENSORS_LM83 is not set
+# CONFIG_SENSORS_LM85 is not set
+# CONFIG_SENSORS_LM87 is not set
+# CONFIG_SENSORS_LM90 is not set
+# CONFIG_SENSORS_LM92 is not set
+# CONFIG_SENSORS_LM93 is not set
+# CONFIG_SENSORS_MAX1619 is not set
+# CONFIG_SENSORS_MAX6650 is not set
+# CONFIG_SENSORS_PC87360 is not set
+# CONFIG_SENSORS_PC87427 is not set
+# CONFIG_SENSORS_SIS5595 is not set
+# CONFIG_SENSORS_DME1737 is not set
+# CONFIG_SENSORS_SMSC47M1 is not set
+# CONFIG_SENSORS_SMSC47M192 is not set
+# CONFIG_SENSORS_SMSC47B397 is not set
+# CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_THMC50 is not set
+# CONFIG_SENSORS_VIA686A is not set
+# CONFIG_SENSORS_VT1211 is not set
+# CONFIG_SENSORS_VT8231 is not set
+# CONFIG_SENSORS_W83781D is not set
+# CONFIG_SENSORS_W83791D is not set
+# CONFIG_SENSORS_W83792D is not set
+# CONFIG_SENSORS_W83793 is not set
+# CONFIG_SENSORS_W83L785TS is not set
+# CONFIG_SENSORS_W83L786NG is not set
+# CONFIG_SENSORS_W83627HF is not set
+# CONFIG_SENSORS_W83627EHF is not set
+# CONFIG_HWMON_DEBUG_CHIP is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_DRM is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+CONFIG_USB_ARCH_HAS_EHCI=y
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_C67X00_HCD is not set
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_EHCI_ROOT_HUB_TT=y
+CONFIG_USB_EHCI_TT_NEWSCHED=y
+# CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
+# CONFIG_USB_OHCI_HCD is not set
+# CONFIG_USB_UHCI_HCD is not set
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+CONFIG_USB_PRINTER=y
+# CONFIG_USB_WDM is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+CONFIG_USB_STORAGE_DATAFAB=y
+CONFIG_USB_STORAGE_FREECOM=y
+# CONFIG_USB_STORAGE_ISD200 is not set
+CONFIG_USB_STORAGE_DPCM=y
+# CONFIG_USB_STORAGE_USBAT is not set
+CONFIG_USB_STORAGE_SDDR09=y
+CONFIG_USB_STORAGE_SDDR55=y
+CONFIG_USB_STORAGE_JUMPSHOT=y
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+# CONFIG_USB_MON is not set
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_SISUSBVGA is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+# CONFIG_USB_ISIGHTFW is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_TIMER=y
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+CONFIG_RTC_DRV_DS1307=y
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+CONFIG_RTC_DRV_RS5C372=y
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+CONFIG_RTC_DRV_M41T80=y
+# CONFIG_RTC_DRV_M41T80_WDT is not set
+# CONFIG_RTC_DRV_S35390A is not set
+
+#
+# SPI RTC drivers
+#
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_FS_XATTR is not set
+# CONFIG_EXT4DEV_FS is not set
+CONFIG_JBD=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+CONFIG_ISO9660_FS=m
+CONFIG_JOLIET=y
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=m
+CONFIG_UDF_NLS=y
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_BSD_DISKLABEL=y
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+CONFIG_NLS_ISO8859_2=y
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+CONFIG_SCHEDSTATS=y
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+CONFIG_DEBUG_PREEMPT=y
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_LKDTM is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=m
+CONFIG_CRYPTO_BLKCIPHER=m
+CONFIG_CRYPTO_MANAGER=m
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=m
+# CONFIG_CRYPTO_LRW is not set
+CONFIG_CRYPTO_PCBC=m
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+# CONFIG_CRYPTO_DEV_HIFN_795X is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+CONFIG_CRC_ITU_T=m
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/mx31ads_defconfig b/arch/arm/configs/mx31ads_defconfig
new file mode 100644 (file)
index 0000000..e052717
--- /dev/null
@@ -0,0 +1,839 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc6
+# Fri Jun 20 16:21:11 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_MXC=y
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Freescale MXC Implementations
+#
+# CONFIG_ARCH_MX2 is not set
+CONFIG_ARCH_MX3=y
+
+#
+# MX3 Options
+#
+CONFIG_MACH_MX31ADS=y
+# CONFIG_MACH_PCM037 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_V6=y
+# CONFIG_CPU_32v6K is not set
+CONFIG_CPU_32v6=y
+CONFIG_CPU_ABRT_EV6=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_V6=y
+CONFIG_CPU_CACHE_VIPT=y
+CONFIG_CPU_COPY_V6=y
+CONFIG_CPU_TLB_V6=y
+CONFIG_CPU_HAS_ASID=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_BPREDICT_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="noinitrd console=ttymxc0,115200 root=/dev/mtdblock2 rw ip=off"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_VFP=y
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+# CONFIG_IP_PNP_BOOTP is not set
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+CONFIG_MTD_REDBOOT_PARTS=y
+CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
+# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
+# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+# CONFIG_MTD_CFI_I2 is not set
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+# CONFIG_MTD_CFI_INTELEXT is not set
+CONFIG_MTD_CFI_AMDSTD=y
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+CONFIG_MTD_RAM=y
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+# CONFIG_MTD_XIP is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PHYSMAP is not set
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+# CONFIG_BLK_DEV is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+# CONFIG_INPUT is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_IMX=y
+CONFIG_SERIAL_IMX_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_HAVE_GPIO_LIB=y
+
+#
+# GPIO Support
+#
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+# CONFIG_EXT2_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_DNOTIFY is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_NLS is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+CONFIG_PRINTK_TIME=y
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/mx31litekit_defconfig b/arch/arm/configs/mx31litekit_defconfig
new file mode 100644 (file)
index 0000000..4f41c41
--- /dev/null
@@ -0,0 +1,1100 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc5
+# Fri Jun 13 14:23:39 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+# CONFIG_GENERIC_GPIO is not set
+# CONFIG_GENERIC_TIME is not set
+# CONFIG_GENERIC_CLOCKEVENTS is not set
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_MXC=y
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Freescale MXC Implementations
+#
+CONFIG_ARCH_MX3=y
+
+#
+# MX3 Options
+#
+# CONFIG_MACH_MX31ADS is not set
+CONFIG_MACH_MX31LITE=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_V6=y
+# CONFIG_CPU_32v6K is not set
+CONFIG_CPU_32v6=y
+CONFIG_CPU_ABRT_EV6=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_V6=y
+CONFIG_CPU_CACHE_VIPT=y
+CONFIG_CPU_COPY_V6=y
+CONFIG_CPU_TLB_V6=y
+CONFIG_CPU_HAS_ASID=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_BPREDICT_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+CONFIG_PCCARD=m
+# CONFIG_PCMCIA_DEBUG is not set
+# CONFIG_PCMCIA is not set
+
+#
+# PC-card bridges
+#
+
+#
+# Kernel Features
+#
+# CONFIG_TICK_ONESHOT is not set
+CONFIG_PREEMPT=y
+# CONFIG_NO_IDLE_HZ is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="noinitrd console=ttymxc0,115200 root=/dev/mtdblock2 rw ip=off"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_VFP=y
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+CONFIG_BINFMT_AOUT=y
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_DEBUG is not set
+# CONFIG_SUSPEND is not set
+# CONFIG_APM_EMULATION is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+# CONFIG_IP_PNP_BOOTP is not set
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+CONFIG_MTD_REDBOOT_PARTS=y
+CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
+# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
+# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+# CONFIG_MTD_CFI_I2 is not set
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+# CONFIG_MTD_CFI_INTELEXT is not set
+CONFIG_MTD_CFI_AMDSTD=y
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+CONFIG_MTD_RAM=y
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+# CONFIG_MTD_XIP is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PHYSMAP is not set
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+# CONFIG_BLK_DEV is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ATKBD is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
+# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=y
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_NOWAYOUT=y
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+
+#
+# USB-based Watchdog Cards
+#
+# CONFIG_USBPCWATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+CONFIG_VIDEO_DEV=y
+CONFIG_VIDEO_V4L2_COMMON=y
+CONFIG_VIDEO_ALLOW_V4L1=y
+CONFIG_VIDEO_V4L1_COMPAT=y
+# CONFIG_DVB_CORE is not set
+CONFIG_VIDEO_MEDIA=y
+
+#
+# Multimedia drivers
+#
+# CONFIG_MEDIA_ATTACH is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_VIDEO_V4L1=y
+CONFIG_VIDEO_CAPTURE_DRIVERS=y
+# CONFIG_VIDEO_ADV_DEBUG is not set
+CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
+# CONFIG_VIDEO_VIVI is not set
+# CONFIG_VIDEO_CPIA is not set
+# CONFIG_VIDEO_CPIA2 is not set
+CONFIG_V4L_USB_DRIVERS=y
+# CONFIG_USB_VICAM is not set
+# CONFIG_USB_IBMCAM is not set
+# CONFIG_USB_KONICAWC is not set
+# CONFIG_USB_QUICKCAM_MESSENGER is not set
+# CONFIG_USB_ET61X251 is not set
+# CONFIG_USB_OV511 is not set
+# CONFIG_USB_SE401 is not set
+# CONFIG_USB_SN9C102 is not set
+# CONFIG_USB_STV680 is not set
+# CONFIG_USB_ZC0301 is not set
+# CONFIG_USB_PWC is not set
+# CONFIG_USB_ZR364XX is not set
+# CONFIG_USB_STKWEBCAM is not set
+# CONFIG_SOC_CAMERA is not set
+CONFIG_RADIO_ADAPTERS=y
+# CONFIG_USB_DSBR is not set
+# CONFIG_USB_SI470X is not set
+CONFIG_DAB=y
+# CONFIG_USB_DABUSB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+# CONFIG_FB_CFB_FILLRECT is not set
+# CONFIG_FB_CFB_COPYAREA is not set
+# CONFIG_FB_CFB_IMAGEBLIT is not set
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+# CONFIG_FB_MODE_HELPERS is not set
+# CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_S1D13XXX is not set
+# CONFIG_FB_VIRTUAL is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+CONFIG_FRAMEBUFFER_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
+# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
+# CONFIG_FONTS is not set
+CONFIG_FONT_8x8=y
+CONFIG_FONT_8x16=y
+CONFIG_LOGO=y
+# CONFIG_LOGO_LINUX_MONO is not set
+# CONFIG_LOGO_LINUX_VGA16 is not set
+CONFIG_LOGO_LINUX_CLUT224=y
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+# CONFIG_USB_ARCH_HAS_OHCI is not set
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+# CONFIG_USB_DEVICEFS is not set
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_C67X00_HCD is not set
+# CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+# CONFIG_USB_WDM is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+# CONFIG_USB_STORAGE is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_ISIGHTFW is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+# CONFIG_EXT2_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_DNOTIFY is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_CRAMFS=y
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_NLS is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+CONFIG_PRINTK_TIME=y
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_DEBUG_SLAB is not set
+CONFIG_DEBUG_PREEMPT=y
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_CRC_CCITT=m
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index 57f32f3..0884f23 100644 (file)
@@ -154,7 +154,6 @@ CONFIG_ARM_AMBA=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 650a248..418ca2f 100644 (file)
@@ -202,7 +202,6 @@ CONFIG_AT91_CF=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 52cd99b..9578b5d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.24
-# Thu Feb  7 14:10:30 2008
+# Linux kernel version: 2.6.26-rc4
+# Mon Jun  2 23:54:48 2008
 #
 CONFIG_ARM=y
 CONFIG_SYS_SUPPORTS_APM_EMULATION=y
@@ -21,6 +21,7 @@ CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_ARCH_HAS_ILOG2_U64 is not set
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
 CONFIG_ZONE_DMA=y
 CONFIG_VECTORS_BASE=0xffff0000
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -40,24 +41,24 @@ CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
-# CONFIG_USER_NS is not set
-# CONFIG_PID_NS is not set
 # CONFIG_AUDIT is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
 # CONFIG_CGROUPS is not set
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_FAIR_USER_SCHED=y
-# CONFIG_FAIR_CGROUP_SCHED is not set
+# CONFIG_GROUP_SCHED is not set
 CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
 # CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
 # CONFIG_BLK_DEV_INITRD is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_EMBEDDED=y
 CONFIG_UID16=y
 CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_ALL=y
 # CONFIG_KALLSYMS_EXTRA_PASS is not set
 CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
@@ -73,20 +74,25 @@ CONFIG_TIMERFD=y
 CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
 CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_SLAB=y
-# CONFIG_SLUB is not set
+# CONFIG_SLUB_DEBUG is not set
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
 # CONFIG_SLOB is not set
-# CONFIG_PROFILING is not set
+CONFIG_PROFILING=y
 # CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
-# CONFIG_KPROBES is not set
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
 CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
 CONFIG_PROC_PAGE_MONITOR=y
-CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
 CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
 CONFIG_MODULE_UNLOAD=y
 # CONFIG_MODULE_FORCE_UNLOAD is not set
 # CONFIG_MODVERSIONS is not set
@@ -111,7 +117,6 @@ CONFIG_DEFAULT_CFQ=y
 # CONFIG_DEFAULT_NOOP is not set
 CONFIG_DEFAULT_IOSCHED="cfq"
 CONFIG_CLASSIC_RCU=y
-# CONFIG_PREEMPT_RCU is not set
 
 #
 # System Type
@@ -160,6 +165,15 @@ CONFIG_MACH_RD88F5182=y
 CONFIG_MACH_KUROBOX_PRO=y
 CONFIG_MACH_DNS323=y
 CONFIG_MACH_TS209=y
+CONFIG_MACH_LINKSTATION_PRO=y
+CONFIG_MACH_TS409=y
+CONFIG_MACH_WRT350N_V2=y
+CONFIG_MACH_TS78XX=y
+CONFIG_MACH_MV2120=y
+CONFIG_MACH_MSS2=y
+CONFIG_MACH_WNR854T=y
+CONFIG_MACH_RD88F5181L_GE=y
+CONFIG_MACH_RD88F5181L_FXO=y
 
 #
 # Boot options
@@ -168,6 +182,7 @@ CONFIG_MACH_TS209=y
 #
 # Power management
 #
+CONFIG_PLAT_ORION=y
 
 #
 # Processor Type
@@ -177,8 +192,9 @@ CONFIG_CPU_FEROCEON=y
 CONFIG_CPU_FEROCEON_OLD_ID=y
 CONFIG_CPU_32v5=y
 CONFIG_CPU_ABRT_EV5T=y
+CONFIG_CPU_PABRT_NOIFAR=y
 CONFIG_CPU_CACHE_VIVT=y
-CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_COPY_FEROCEON=y
 CONFIG_CPU_TLB_V4WBI=y
 CONFIG_CPU_CP15=y
 CONFIG_CPU_CP15_MMU=y
@@ -189,7 +205,6 @@ CONFIG_CPU_CP15_MMU=y
 CONFIG_ARM_THUMB=y
 # CONFIG_CPU_ICACHE_DISABLE is not set
 # CONFIG_CPU_DCACHE_DISABLE is not set
-# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
 # CONFIG_OUTER_CACHE is not set
 
 #
@@ -199,6 +214,7 @@ CONFIG_PCI=y
 CONFIG_PCI_SYSCALL=y
 # CONFIG_ARCH_SUPPORTS_MSI is not set
 CONFIG_PCI_LEGACY=y
+# CONFIG_PCI_DEBUG is not set
 # CONFIG_PCCARD is not set
 
 #
@@ -221,6 +237,7 @@ CONFIG_FLATMEM=y
 CONFIG_FLAT_NODE_MEM_MAP=y
 # CONFIG_SPARSEMEM_STATIC is not set
 # CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4096
 # CONFIG_RESOURCES_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=1
@@ -238,7 +255,6 @@ CONFIG_ZBOOT_ROM_BSS=0x0
 CONFIG_CMDLINE=""
 # CONFIG_XIP_KERNEL is not set
 # CONFIG_KEXEC is not set
-# CONFIG_ATAGS_PROC is not set
 
 #
 # Floating point emulation
@@ -311,8 +327,6 @@ CONFIG_TCP_CONG_CUBIC=y
 CONFIG_DEFAULT_TCP_CONG="cubic"
 # CONFIG_TCP_MD5SIG is not set
 # CONFIG_IPV6 is not set
-# CONFIG_INET6_XFRM_TUNNEL is not set
-# CONFIG_INET6_TUNNEL is not set
 # CONFIG_NETWORK_SECMARK is not set
 # CONFIG_NETFILTER is not set
 # CONFIG_IP_DCCP is not set
@@ -335,6 +349,7 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 CONFIG_NET_PKTGEN=m
+# CONFIG_NET_TCPPROBE is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -362,6 +377,8 @@ CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
 CONFIG_FW_LOADER=y
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
 # CONFIG_SYS_HYPERVISOR is not set
 # CONFIG_CONNECTOR is not set
 CONFIG_MTD=y
@@ -371,6 +388,7 @@ CONFIG_MTD_PARTITIONS=y
 # CONFIG_MTD_REDBOOT_PARTS is not set
 CONFIG_MTD_CMDLINE_PARTS=y
 # CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
 
 #
 # User Modules And Translation Layers
@@ -378,9 +396,8 @@ CONFIG_MTD_CMDLINE_PARTS=y
 CONFIG_MTD_CHAR=y
 CONFIG_MTD_BLKDEVS=y
 CONFIG_MTD_BLOCK=y
-CONFIG_FTL=y
-CONFIG_NFTL=y
-# CONFIG_NFTL_RW is not set
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
 # CONFIG_INFTL is not set
 # CONFIG_RFD_FTL is not set
 # CONFIG_SSFDC is not set
@@ -405,12 +422,12 @@ CONFIG_MTD_MAP_BANK_WIDTH_4=y
 # CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
 CONFIG_MTD_CFI_I1=y
 CONFIG_MTD_CFI_I2=y
-CONFIG_MTD_CFI_I4=y
+# CONFIG_MTD_CFI_I4 is not set
 # CONFIG_MTD_CFI_I8 is not set
 # CONFIG_MTD_OTP is not set
 CONFIG_MTD_CFI_INTELEXT=y
 CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_CFI_STAA=y
+# CONFIG_MTD_CFI_STAA is not set
 CONFIG_MTD_CFI_UTIL=y
 # CONFIG_MTD_RAM is not set
 # CONFIG_MTD_ROM is not set
@@ -481,6 +498,9 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_EEPROM_93CX6 is not set
 # CONFIG_SGI_IOC4 is not set
 # CONFIG_TIFM_CORE is not set
+# CONFIG_ENCLOSURE_SERVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
 
 #
 # SCSI device support
@@ -542,6 +562,7 @@ CONFIG_SCSI_LOWLEVEL=y
 # CONFIG_SCSI_IPS is not set
 # CONFIG_SCSI_INITIO is not set
 # CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_MVSAS is not set
 # CONFIG_SCSI_STEX is not set
 # CONFIG_SCSI_SYM53C8XX_2 is not set
 # CONFIG_SCSI_IPR is not set
@@ -556,7 +577,10 @@ CONFIG_SCSI_LOWLEVEL=y
 # CONFIG_SCSI_SRP is not set
 CONFIG_ATA=y
 # CONFIG_ATA_NONSTANDARD is not set
+CONFIG_SATA_PMP=y
 # CONFIG_SATA_AHCI is not set
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
 # CONFIG_SATA_SVW is not set
 # CONFIG_ATA_PIIX is not set
 CONFIG_SATA_MV=y
@@ -566,7 +590,6 @@ CONFIG_SATA_MV=y
 # CONFIG_SATA_PROMISE is not set
 # CONFIG_SATA_SX4 is not set
 # CONFIG_SATA_SIL is not set
-# CONFIG_SATA_SIL24 is not set
 # CONFIG_SATA_SIS is not set
 # CONFIG_SATA_ULI is not set
 # CONFIG_SATA_VIA is not set
@@ -611,6 +634,7 @@ CONFIG_SATA_MV=y
 # CONFIG_PATA_VIA is not set
 # CONFIG_PATA_WINBOND is not set
 # CONFIG_PATA_PLATFORM is not set
+# CONFIG_PATA_SCH is not set
 # CONFIG_MD is not set
 # CONFIG_FUSION is not set
 
@@ -652,7 +676,7 @@ CONFIG_NET_PCI=y
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_EEPRO100 is not set
-CONFIG_E100=y
+# CONFIG_E100 is not set
 # CONFIG_FEALNX is not set
 # CONFIG_NATSEMI is not set
 # CONFIG_NE2K_PCI is not set
@@ -668,9 +692,7 @@ CONFIG_E100=y
 CONFIG_NETDEV_1000=y
 # CONFIG_ACENIC is not set
 # CONFIG_DL2K is not set
-CONFIG_E1000=y
-CONFIG_E1000_NAPI=y
-# CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
+# CONFIG_E1000 is not set
 # CONFIG_E1000E is not set
 # CONFIG_E1000E_ENABLED is not set
 # CONFIG_IP1000 is not set
@@ -680,27 +702,15 @@ CONFIG_E1000_NAPI=y
 # CONFIG_YELLOWFIN is not set
 # CONFIG_R8169 is not set
 # CONFIG_SIS190 is not set
-CONFIG_SKGE=y
-CONFIG_SKY2=y
-# CONFIG_SK98LIN is not set
+# CONFIG_SKGE is not set
+# CONFIG_SKY2 is not set
 # CONFIG_VIA_VELOCITY is not set
-CONFIG_TIGON3=y
+# CONFIG_TIGON3 is not set
 # CONFIG_BNX2 is not set
 CONFIG_MV643XX_ETH=y
 # CONFIG_QLA3XXX is not set
 # CONFIG_ATL1 is not set
-CONFIG_NETDEV_10000=y
-# CONFIG_CHELSIO_T1 is not set
-# CONFIG_CHELSIO_T3 is not set
-# CONFIG_IXGBE is not set
-# CONFIG_IXGB is not set
-# CONFIG_S2IO is not set
-# CONFIG_MYRI10GE is not set
-# CONFIG_NETXEN_NIC is not set
-# CONFIG_NIU is not set
-# CONFIG_MLX4_CORE is not set
-# CONFIG_TEHUTI is not set
-# CONFIG_BNX2X is not set
+# CONFIG_NETDEV_10000 is not set
 # CONFIG_TR is not set
 
 #
@@ -708,6 +718,7 @@ CONFIG_NETDEV_10000=y
 #
 # CONFIG_WLAN_PRE80211 is not set
 # CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
 
 #
 # USB Network Adapters
@@ -738,12 +749,9 @@ CONFIG_INPUT=y
 #
 # Userland interfaces
 #
-CONFIG_INPUT_MOUSEDEV=y
-CONFIG_INPUT_MOUSEDEV_PSAUX=y
-CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
-CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_MOUSEDEV is not set
 # CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_EVDEV is not set
+CONFIG_INPUT_EVDEV=y
 # CONFIG_INPUT_EVBUG is not set
 
 #
@@ -765,10 +773,8 @@ CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 #
 # Character devices
 #
-CONFIG_VT=y
-CONFIG_VT_CONSOLE=y
-CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
+# CONFIG_VT is not set
+CONFIG_DEVKMEM=y
 # CONFIG_SERIAL_NONSTANDARD is not set
 # CONFIG_NOZOMI is not set
 
@@ -777,7 +783,7 @@ CONFIG_HW_CONSOLE=y
 #
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
-CONFIG_SERIAL_8250_PCI=y
+# CONFIG_SERIAL_8250_PCI is not set
 CONFIG_SERIAL_8250_NR_UARTS=4
 CONFIG_SERIAL_8250_RUNTIME_UARTS=2
 # CONFIG_SERIAL_8250_EXTENDED is not set
@@ -792,7 +798,7 @@ CONFIG_UNIX98_PTYS=y
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=16
 # CONFIG_IPMI_HANDLER is not set
-CONFIG_HW_RANDOM=m
+# CONFIG_HW_RANDOM is not set
 # CONFIG_NVRAM is not set
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
@@ -803,13 +809,6 @@ CONFIG_I2C=y
 CONFIG_I2C_BOARDINFO=y
 CONFIG_I2C_CHARDEV=y
 
-#
-# I2C Algorithms
-#
-# CONFIG_I2C_ALGOBIT is not set
-# CONFIG_I2C_ALGOPCF is not set
-# CONFIG_I2C_ALGOPCA is not set
-
 #
 # I2C Hardware Bus support
 #
@@ -837,6 +836,7 @@ CONFIG_I2C_CHARDEV=y
 # CONFIG_I2C_VIA is not set
 # CONFIG_I2C_VIAPRO is not set
 # CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
 CONFIG_I2C_MV64XXX=y
 
 #
@@ -847,19 +847,13 @@ CONFIG_I2C_MV64XXX=y
 # CONFIG_SENSORS_PCF8574 is not set
 # CONFIG_PCF8575 is not set
 # CONFIG_SENSORS_PCF8591 is not set
-# CONFIG_TPS65010 is not set
 # CONFIG_SENSORS_MAX6875 is not set
 # CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
 # CONFIG_I2C_DEBUG_CHIP is not set
-
-#
-# SPI support
-#
 # CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
 # CONFIG_W1 is not set
 # CONFIG_POWER_SUPPLY is not set
 CONFIG_HWMON=y
@@ -872,6 +866,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
 # CONFIG_SENSORS_ADT7470 is not set
+# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_I5K_AMB is not set
@@ -901,6 +896,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_SMSC47M1 is not set
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
+# CONFIG_SENSORS_ADS7828 is not set
 # CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_VIA686A is not set
 # CONFIG_SENSORS_VT1211 is not set
@@ -910,6 +906,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_W83792D is not set
 # CONFIG_SENSORS_W83793 is not set
 # CONFIG_SENSORS_W83L785TS is not set
+# CONFIG_SENSORS_W83L786NG is not set
 # CONFIG_SENSORS_W83627HF is not set
 # CONFIG_SENSORS_W83627EHF is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
@@ -925,14 +922,24 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_PASIC3 is not set
 
 #
 # Multimedia devices
 #
+
+#
+# Multimedia core support
+#
 # CONFIG_VIDEO_DEV is not set
 # CONFIG_DVB_CORE is not set
-CONFIG_DAB=y
-# CONFIG_USB_DABUSB is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
 
 #
 # Graphics support
@@ -948,12 +955,6 @@ CONFIG_DAB=y
 #
 # CONFIG_DISPLAY_SUPPORT is not set
 
-#
-# Console display driver support
-#
-# CONFIG_VGA_CONSOLE is not set
-CONFIG_DUMMY_CONSOLE=y
-
 #
 # Sound
 #
@@ -985,14 +986,18 @@ CONFIG_USB_DEVICEFS=y
 CONFIG_USB_DEVICE_CLASS=y
 # CONFIG_USB_DYNAMIC_MINORS is not set
 # CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
 
 #
 # USB Host Controller Drivers
 #
+# CONFIG_USB_C67X00_HCD is not set
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_ROOT_HUB_TT=y
 CONFIG_USB_EHCI_TT_NEWSCHED=y
 # CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
 # CONFIG_USB_OHCI_HCD is not set
 # CONFIG_USB_UHCI_HCD is not set
 # CONFIG_USB_SL811_HCD is not set
@@ -1003,6 +1008,7 @@ CONFIG_USB_EHCI_TT_NEWSCHED=y
 #
 # CONFIG_USB_ACM is not set
 CONFIG_USB_PRINTER=y
+# CONFIG_USB_WDM is not set
 
 #
 # NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
@@ -1022,7 +1028,9 @@ CONFIG_USB_STORAGE_SDDR09=y
 CONFIG_USB_STORAGE_SDDR55=y
 CONFIG_USB_STORAGE_JUMPSHOT=y
 # CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
 # CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
 # CONFIG_USB_LIBUSUAL is not set
 
 #
@@ -1060,6 +1068,7 @@ CONFIG_USB_STORAGE_JUMPSHOT=y
 # CONFIG_USB_TRANCEVIBRATOR is not set
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
+# CONFIG_USB_ISIGHTFW is not set
 # CONFIG_USB_GADGET is not set
 # CONFIG_MMC is not set
 CONFIG_NEW_LEDS=y
@@ -1068,7 +1077,7 @@ CONFIG_LEDS_CLASS=y
 #
 # LED drivers
 #
-# CONFIG_LEDS_GPIO is not set
+CONFIG_LEDS_GPIO=y
 
 #
 # LED Triggers
@@ -1076,6 +1085,7 @@ CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_TRIGGERS=y
 CONFIG_LEDS_TRIGGER_TIMER=y
 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
 CONFIG_RTC_LIB=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_HCTOSYS=y
@@ -1105,6 +1115,7 @@ CONFIG_RTC_DRV_RS5C372=y
 # CONFIG_RTC_DRV_PCF8583 is not set
 CONFIG_RTC_DRV_M41T80=y
 # CONFIG_RTC_DRV_M41T80_WDT is not set
+# CONFIG_RTC_DRV_S35390A is not set
 
 #
 # SPI RTC drivers
@@ -1125,6 +1136,7 @@ CONFIG_RTC_DRV_M41T80=y
 #
 # on-CPU RTC drivers
 #
+# CONFIG_UIO is not set
 
 #
 # File systems
@@ -1140,14 +1152,11 @@ CONFIG_JBD=y
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
 # CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
 # CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
+CONFIG_DNOTIFY=y
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
 # CONFIG_AUTOFS_FS is not set
 # CONFIG_AUTOFS4_FS is not set
 # CONFIG_FUSE_FS is not set
@@ -1155,8 +1164,8 @@ CONFIG_DNOTIFY=y
 #
 # CD-ROM/DVD Filesystems
 #
-CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
+CONFIG_ISO9660_FS=m
+CONFIG_JOLIET=y
 # CONFIG_ZISOFS is not set
 CONFIG_UDF_FS=m
 CONFIG_UDF_NLS=y
@@ -1205,8 +1214,10 @@ CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
 CONFIG_CRAMFS=y
 # CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
 # CONFIG_HPFS_FS is not set
 # CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
 CONFIG_NETWORK_FILESYSTEMS=y
@@ -1214,7 +1225,6 @@ CONFIG_NFS_FS=y
 CONFIG_NFS_V3=y
 # CONFIG_NFS_V3_ACL is not set
 # CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
 # CONFIG_NFSD is not set
 CONFIG_ROOT_NFS=y
 CONFIG_LOCKD=y
@@ -1241,14 +1251,13 @@ CONFIG_PARTITION_ADVANCED=y
 # CONFIG_MAC_PARTITION is not set
 CONFIG_MSDOS_PARTITION=y
 CONFIG_BSD_DISKLABEL=y
-CONFIG_MINIX_SUBPARTITION=y
-CONFIG_SOLARIS_X86_PARTITION=y
-CONFIG_UNIXWARE_DISKLABEL=y
-CONFIG_LDM_PARTITION=y
-CONFIG_LDM_DEBUG=y
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
 # CONFIG_SGI_PARTITION is not set
 # CONFIG_ULTRIX_PARTITION is not set
-CONFIG_SUN_PARTITION=y
+# CONFIG_SUN_PARTITION is not set
 # CONFIG_KARMA_PARTITION is not set
 # CONFIG_EFI_PARTITION is not set
 # CONFIG_SYSV68_PARTITION is not set
@@ -1300,15 +1309,48 @@ CONFIG_NLS_ISO8859_2=y
 # CONFIG_PRINTK_TIME is not set
 CONFIG_ENABLE_WARN_DEPRECATED=y
 CONFIG_ENABLE_MUST_CHECK=y
-# CONFIG_MAGIC_SYSRQ is not set
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
 # CONFIG_UNUSED_SYMBOLS is not set
 # CONFIG_DEBUG_FS is not set
 # CONFIG_HEADERS_CHECK is not set
-# CONFIG_DEBUG_KERNEL is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+CONFIG_SCHEDSTATS=y
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+CONFIG_DEBUG_PREEMPT=y
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
 # CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
 CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_LKDTM is not set
+# CONFIG_FAULT_INJECTION is not set
 # CONFIG_SAMPLES is not set
 CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
 
 #
 # Security options
@@ -1317,50 +1359,79 @@ CONFIG_DEBUG_USER=y
 # CONFIG_SECURITY is not set
 # CONFIG_SECURITY_FILE_CAPABILITIES is not set
 CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
 CONFIG_CRYPTO_ALGAPI=m
 CONFIG_CRYPTO_BLKCIPHER=m
-# CONFIG_CRYPTO_SEQIV is not set
 CONFIG_CRYPTO_MANAGER=m
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=m
+# CONFIG_CRYPTO_LRW is not set
+CONFIG_CRYPTO_PCBC=m
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
 # CONFIG_CRYPTO_HMAC is not set
 # CONFIG_CRYPTO_XCBC is not set
-# CONFIG_CRYPTO_NULL is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
 # CONFIG_CRYPTO_MD4 is not set
 # CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
 # CONFIG_CRYPTO_SHA1 is not set
 # CONFIG_CRYPTO_SHA256 is not set
 # CONFIG_CRYPTO_SHA512 is not set
-# CONFIG_CRYPTO_WP512 is not set
 # CONFIG_CRYPTO_TGR192 is not set
-# CONFIG_CRYPTO_GF128MUL is not set
-CONFIG_CRYPTO_ECB=m
-CONFIG_CRYPTO_CBC=m
-CONFIG_CRYPTO_PCBC=m
-# CONFIG_CRYPTO_LRW is not set
-# CONFIG_CRYPTO_XTS is not set
-# CONFIG_CRYPTO_CTR is not set
-# CONFIG_CRYPTO_GCM is not set
-# CONFIG_CRYPTO_CCM is not set
-# CONFIG_CRYPTO_CRYPTD is not set
-# CONFIG_CRYPTO_DES is not set
-# CONFIG_CRYPTO_FCRYPT is not set
-# CONFIG_CRYPTO_BLOWFISH is not set
-# CONFIG_CRYPTO_TWOFISH is not set
-# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
 # CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
 # CONFIG_CRYPTO_CAST5 is not set
 # CONFIG_CRYPTO_CAST6 is not set
-# CONFIG_CRYPTO_TEA is not set
-# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
 # CONFIG_CRYPTO_KHAZAD is not set
-# CONFIG_CRYPTO_ANUBIS is not set
-# CONFIG_CRYPTO_SEED is not set
 # CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
 # CONFIG_CRYPTO_DEFLATE is not set
-# CONFIG_CRYPTO_MICHAEL_MIC is not set
-# CONFIG_CRYPTO_CRC32C is not set
-# CONFIG_CRYPTO_CAMELLIA is not set
-# CONFIG_CRYPTO_TEST is not set
-# CONFIG_CRYPTO_AUTHENC is not set
 # CONFIG_CRYPTO_LZO is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
@@ -1369,12 +1440,14 @@ CONFIG_CRYPTO_HW=y
 # Library routines
 #
 CONFIG_BITREVERSE=y
-CONFIG_CRC_CCITT=y
-CONFIG_CRC16=y
-# CONFIG_CRC_ITU_T is not set
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+CONFIG_CRC_ITU_T=m
 CONFIG_CRC32=y
 # CONFIG_CRC7 is not set
-CONFIG_LIBCRC32C=y
+# CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=y
 CONFIG_PLIST=y
diff --git a/arch/arm/configs/pcm037_defconfig b/arch/arm/configs/pcm037_defconfig
new file mode 100644 (file)
index 0000000..6274745
--- /dev/null
@@ -0,0 +1,748 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc6
+# Wed Jun 25 11:52:42 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_MXC=y
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Freescale MXC Implementations
+#
+CONFIG_ARCH_MX3=y
+
+#
+# MX3 Options
+#
+# CONFIG_MACH_MX31ADS is not set
+CONFIG_MACH_PCM037=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_V6=y
+# CONFIG_CPU_32v6K is not set
+CONFIG_CPU_32v6=y
+CONFIG_CPU_ABRT_EV6=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_V6=y
+CONFIG_CPU_CACHE_VIPT=y
+CONFIG_CPU_COPY_V6=y
+CONFIG_CPU_TLB_V6=y
+CONFIG_CPU_HAS_ASID=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_BPREDICT_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="noinitrd console=ttymxc0,115200 root=/dev/mtdblock2 rw ip=off"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_VFP=y
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+# CONFIG_IP_PNP_BOOTP is not set
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+# CONFIG_MTD_CFI_ADV_OPTIONS is not set
+# CONFIG_MTD_CFI_NOSWAP is not set
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_CFI_INTELEXT is not set
+# CONFIG_MTD_CFI_AMDSTD is not set
+# CONFIG_MTD_CFI_STAA is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0
+CONFIG_MTD_PHYSMAP_LEN=0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=2
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+# CONFIG_MTD_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+# CONFIG_BLK_DEV is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+CONFIG_SMC91X=y
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+# CONFIG_INPUT is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_IMX=y
+CONFIG_SERIAL_IMX_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+CONFIG_HAVE_GPIO_LIB=y
+
+#
+# GPIO Support
+#
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+# CONFIG_EXT2_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_DNOTIFY is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+# CONFIG_NFS_V3 is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_NLS is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
+# CONFIG_ENABLE_MUST_CHECK is not set
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/pcm038_defconfig b/arch/arm/configs/pcm038_defconfig
new file mode 100644 (file)
index 0000000..6b798c2
--- /dev/null
@@ -0,0 +1,1008 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.26-rc6
+# Fri Jun 20 16:38:36 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_POSIX_MQUEUE=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_RT_GROUP_SCHED=y
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+# CONFIG_COMPAT_BRK is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_MARKERS=y
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+# CONFIG_KMOD is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_AS is not set
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+CONFIG_DEFAULT_NOOP=y
+CONFIG_DEFAULT_IOSCHED="noop"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+CONFIG_ARCH_MXC=y
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Freescale MXC Implementations
+#
+CONFIG_ARCH_MX2=y
+# CONFIG_ARCH_MX3 is not set
+
+#
+# MX2 family CPU support
+#
+CONFIG_MACH_MX27=y
+
+#
+# MX2 Platforms
+#
+# CONFIG_MACH_MX27ADS is not set
+CONFIG_MACH_PCM038=y
+CONFIG_MACH_PCM970_BASEBOARD=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+# CONFIG_IP_PNP_BOOTP is not set
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_NET_TCPPROBE is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+# CONFIG_MTD_CFI_I2 is not set
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+# CONFIG_MTD_CFI_AMDSTD is not set
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+# CONFIG_MTD_XIP is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x00000000
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=2
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_DATAFLASH is not set
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+# CONFIG_MTD_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+CONFIG_FEC_OLD=y
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_ADS7846 is not set
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_IMX=y
+CONFIG_SERIAL_IMX_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+# CONFIG_I2C_CHARDEV is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_GPIO is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_TPS65010 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_BITBANG=y
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+CONFIG_HAVE_GPIO_LIB=y
+
+#
+# GPIO Support
+#
+
+#
+# I2C GPIO expanders:
+#
+# CONFIG_GPIO_PCA953X is not set
+# CONFIG_GPIO_PCF857X is not set
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_GPIO_MCP23S08 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+CONFIG_VIDEO_DEV=y
+CONFIG_VIDEO_V4L2_COMMON=y
+CONFIG_VIDEO_ALLOW_V4L1=y
+CONFIG_VIDEO_V4L1_COMPAT=y
+# CONFIG_DVB_CORE is not set
+CONFIG_VIDEO_MEDIA=y
+
+#
+# Multimedia drivers
+#
+# CONFIG_MEDIA_ATTACH is not set
+CONFIG_MEDIA_TUNER=y
+# CONFIG_MEDIA_TUNER_CUSTOMIZE is not set
+CONFIG_MEDIA_TUNER_SIMPLE=y
+CONFIG_MEDIA_TUNER_TDA8290=y
+CONFIG_MEDIA_TUNER_TDA9887=y
+CONFIG_MEDIA_TUNER_TEA5761=y
+CONFIG_MEDIA_TUNER_TEA5767=y
+CONFIG_MEDIA_TUNER_MT20XX=y
+CONFIG_MEDIA_TUNER_XC2028=y
+CONFIG_MEDIA_TUNER_XC5000=y
+CONFIG_VIDEO_V4L2=y
+CONFIG_VIDEO_V4L1=y
+CONFIG_VIDEO_CAPTURE_DRIVERS=y
+# CONFIG_VIDEO_ADV_DEBUG is not set
+CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
+# CONFIG_VIDEO_VIVI is not set
+# CONFIG_VIDEO_CPIA is not set
+# CONFIG_VIDEO_SAA5246A is not set
+# CONFIG_VIDEO_SAA5249 is not set
+# CONFIG_TUNER_3036 is not set
+# CONFIG_SOC_CAMERA is not set
+# CONFIG_RADIO_ADAPTERS is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+# CONFIG_FB_CFB_FILLRECT is not set
+# CONFIG_FB_CFB_COPYAREA is not set
+# CONFIG_FB_CFB_IMAGEBLIT is not set
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+# CONFIG_FB_MODE_HELPERS is not set
+# CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_S1D13XXX is not set
+# CONFIG_FB_VIRTUAL is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+CONFIG_FRAMEBUFFER_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
+# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
+CONFIG_FONTS=y
+CONFIG_FONT_8x8=y
+# CONFIG_FONT_8x16 is not set
+# CONFIG_FONT_6x11 is not set
+# CONFIG_FONT_7x14 is not set
+# CONFIG_FONT_PEARL_8x8 is not set
+# CONFIG_FONT_ACORN_8x8 is not set
+# CONFIG_FONT_MINI_4x6 is not set
+# CONFIG_FONT_SUN8x16 is not set
+# CONFIG_FONT_SUN12x22 is not set
+# CONFIG_FONT_10x18 is not set
+# CONFIG_LOGO is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+CONFIG_RTC_DRV_PCF8563=y
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
+# CONFIG_RTC_DRV_FM3130 is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_R9701 is not set
+# CONFIG_RTC_DRV_RS5C348 is not set
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+# CONFIG_EXT2_FS is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_DNOTIFY is not set
+# CONFIG_INOTIFY is not set
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=m
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=m
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+CONFIG_NLS_ISO8859_15=m
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_SAMPLES is not set
+# CONFIG_DEBUG_USER is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index 95a22f5..14826f0 100644 (file)
@@ -201,7 +201,6 @@ CONFIG_ARM_THUMB=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-CONFIG_NO_IDLE_HZ=y
 CONFIG_HZ=100
 CONFIG_AEABI=y
 CONFIG_OABI_COMPAT=y
index b5e11aa..811b8f6 100644 (file)
@@ -151,7 +151,6 @@ CONFIG_ARM_THUMB=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/qil-a9260_defconfig b/arch/arm/configs/qil-a9260_defconfig
new file mode 100644 (file)
index 0000000..ef903be
--- /dev/null
@@ -0,0 +1,1256 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.24
+# Tue Apr 15 12:28:38 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_FAIR_USER_SCHED=y
+# CONFIG_FAIR_CGROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED is not set
+# CONFIG_RELAY is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+CONFIG_DEFAULT_AS=y
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="anticipatory"
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+CONFIG_ARCH_AT91=y
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Atmel AT91 System-on-Chip
+#
+# CONFIG_ARCH_AT91RM9200 is not set
+CONFIG_ARCH_AT91SAM9260=y
+# CONFIG_ARCH_AT91SAM9261 is not set
+# CONFIG_ARCH_AT91SAM9263 is not set
+# CONFIG_ARCH_AT91SAM9RL is not set
+# CONFIG_ARCH_AT91CAP9 is not set
+# CONFIG_ARCH_AT91X40 is not set
+CONFIG_AT91_PMC_UNIT=y
+
+#
+# AT91SAM9260 Variants
+#
+# CONFIG_ARCH_AT91SAM9260_SAM9XE is not set
+
+#
+# AT91SAM9260 / AT91SAM9XE Board Type
+#
+# CONFIG_MACH_AT91SAM9260EK is not set
+# CONFIG_MACH_CAM60 is not set
+# CONFIG_MACH_SAM9_L9260 is not set
+# CONFIG_MACH_USB_A9260 is not set
+CONFIG_MACH_QIL_A9260=y
+
+#
+# AT91 Board Options
+#
+
+#
+# AT91 Feature Selections
+#
+# CONFIG_AT91_PROGRAMMABLE_CLOCKS is not set
+CONFIG_AT91_SLOW_CLOCK=y
+CONFIG_AT91_TIMER_HZ=100
+# CONFIG_AT91_EARLY_DBGU is not set
+CONFIG_AT91_EARLY_USART0=y
+# CONFIG_AT91_EARLY_USART1 is not set
+# CONFIG_AT91_EARLY_USART2 is not set
+# CONFIG_AT91_EARLY_USART3 is not set
+# CONFIG_AT91_EARLY_USART4 is not set
+# CONFIG_AT91_EARLY_USART5 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+# CONFIG_ARM_THUMB is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_TICK_ONESHOT is not set
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+# CONFIG_LEDS is not set
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="mem=64M console=ttyS1,115200"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_LEGACY is not set
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND_UP_POSSIBLE=y
+CONFIG_SUSPEND=y
+# CONFIG_APM_EMULATION is not set
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_ASK_IP_FIB_HASH=y
+# CONFIG_IP_FIB_TRIE is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_MULTIPLE_TABLES is not set
+# CONFIG_IP_ROUTE_MULTIPATH is not set
+CONFIG_IP_ROUTE_VERBOSE=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_BOOTP=y
+CONFIG_IP_PNP_RARP=y
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_FW_LOADER is not set
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+# CONFIG_MTD_CFI is not set
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+CONFIG_MTD_DATAFLASH=y
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+CONFIG_MTD_NAND_AT91=y
+CONFIG_MTD_NAND_AT91_ECC_SOFT=y
+# CONFIG_MTD_NAND_AT91_ECC_HW is not set
+# CONFIG_MTD_NAND_AT91_ECC_NONE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+CONFIG_PHYLIB=y
+
+#
+# MII PHY device drivers
+#
+# CONFIG_MARVELL_PHY is not set
+# CONFIG_DAVICOM_PHY is not set
+# CONFIG_QSEMI_PHY is not set
+# CONFIG_LXT_PHY is not set
+# CONFIG_CICADA_PHY is not set
+# CONFIG_VITESSE_PHY is not set
+# CONFIG_SMSC_PHY is not set
+# CONFIG_BROADCOM_PHY is not set
+# CONFIG_ICPLUS_PHY is not set
+# CONFIG_FIXED_PHY is not set
+# CONFIG_MDIO_BITBANG is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+CONFIG_MACB=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+CONFIG_NETDEV_1000=y
+CONFIG_NETDEV_10000=y
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_SHAPER is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+CONFIG_INPUT_EVBUG=y
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ATKBD is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+CONFIG_KEYBOARD_GPIO=y
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_ATMEL=y
+CONFIG_SERIAL_ATMEL_CONSOLE=y
+# CONFIG_SERIAL_ATMEL_TTYAT is not set
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=y
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_CHARDEV=y
+
+#
+# I2C Algorithms
+#
+# CONFIG_I2C_ALGOBIT is not set
+# CONFIG_I2C_ALGOPCF is not set
+# CONFIG_I2C_ALGOPCA is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_GPIO is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_PCA is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_SENSORS_DS1337 is not set
+# CONFIG_SENSORS_DS1374 is not set
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_SENSORS_PCA9539 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+
+#
+# SPI support
+#
+CONFIG_SPI=y
+# CONFIG_SPI_DEBUG is not set
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_ATMEL=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_NOWAYOUT=y
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+# CONFIG_AT91SAM9_WATCHDOG is not set
+
+#
+# USB-based Watchdog Cards
+#
+# CONFIG_USBPCWATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+# CONFIG_USB_HID is not set
+
+#
+# USB HID Boot Protocol drivers
+#
+# CONFIG_USB_KBD is not set
+# CONFIG_USB_MOUSE is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_PERSIST is not set
+# CONFIG_USB_OTG is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+
+#
+# USB DSL modem support
+#
+
+#
+# USB Gadget Support
+#
+CONFIG_USB_GADGET=y
+# CONFIG_USB_GADGET_DEBUG is not set
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_SELECTED=y
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+# CONFIG_USB_GADGET_ATMEL_USBA is not set
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_PXA2XX is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+CONFIG_USB_GADGET_AT91=y
+CONFIG_USB_AT91=y
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+# CONFIG_USB_GADGET_DUALSPEED is not set
+# CONFIG_USB_ZERO is not set
+CONFIG_USB_ETH=y
+CONFIG_USB_ETH_RNDIS=y
+# CONFIG_USB_GADGETFS is not set
+# CONFIG_USB_FILE_STORAGE is not set
+# CONFIG_USB_G_SERIAL is not set
+# CONFIG_USB_MIDI_GADGET is not set
+CONFIG_MMC=y
+# CONFIG_MMC_DEBUG is not set
+# CONFIG_MMC_UNSAFE_RESUME is not set
+
+#
+# MMC/SD Card Drivers
+#
+CONFIG_MMC_BLOCK=y
+CONFIG_MMC_BLOCK_BOUNCE=y
+# CONFIG_SDIO_UART is not set
+
+#
+# MMC/SD Host Controller Drivers
+#
+CONFIG_MMC_AT91=y
+# CONFIG_MMC_SPI is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+CONFIG_LEDS_GPIO=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_RS5C348 is not set
+# CONFIG_RTC_DRV_MAX6902 is not set
+CONFIG_RTC_DRV_M41T94=y
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+# CONFIG_RTC_DRV_AT91SAM9 is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+CONFIG_FS_POSIX_ACL=y
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=m
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+# CONFIG_MSDOS_FS is not set
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_ACL_SUPPORT=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+CONFIG_SUNRPC_GSS=y
+# CONFIG_SUNRPC_BIND34 is not set
+CONFIG_RPCSEC_GSS_KRB5=y
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+# CONFIG_INSTRUMENTATION is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+CONFIG_FORCED_INLINING=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+# CONFIG_DEBUG_ERRORS is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_MANAGER=y
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_WP512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_ECB is not set
+CONFIG_CRYPTO_CBC=y
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_XTS is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_TEST is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index fc39ba1..0c09b23 100644 (file)
@@ -177,7 +177,6 @@ CONFIG_NR_CPUS=4
 CONFIG_HOTPLUG_CPU=y
 CONFIG_LOCAL_TIMERS=y
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index accbf52..907e543 100644 (file)
@@ -126,7 +126,6 @@ CONFIG_ISA_DMA_API=y
 #
 # Kernel Features
 #
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_FLATMEM=y
 CONFIG_FLAT_NODE_MEM_MAP=y
index 5ddecb9..f62d181 100644 (file)
@@ -190,7 +190,6 @@ CONFIG_ISA_DMA_API=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index f8a1645..35faaea 100644 (file)
@@ -1,15 +1,18 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.21-rc6
-# Mon Apr  9 10:12:58 2007
+# Linux kernel version: 2.6.26-rc8
+# Mon Jul  7 16:59:23 2008
 #
 CONFIG_ARM=y
 CONFIG_SYS_SUPPORTS_APM_EMULATION=y
 CONFIG_GENERIC_GPIO=y
 # CONFIG_GENERIC_TIME is not set
+# CONFIG_GENERIC_CLOCKEVENTS is not set
 CONFIG_MMU=y
 CONFIG_NO_IOPORT=y
 CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
 CONFIG_TRACE_IRQFLAGS_SUPPORT=y
 CONFIG_HARDIRQS_SW_RESEND=y
 CONFIG_GENERIC_IRQ_PROBE=y
@@ -18,34 +21,39 @@ CONFIG_RWSEM_GENERIC_SPINLOCK=y
 # CONFIG_ARCH_HAS_ILOG2_U64 is not set
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
 CONFIG_ZONE_DMA=y
 CONFIG_VECTORS_BASE=0xffff0000
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 
 #
-# Code maturity level options
+# General setup
 #
 CONFIG_EXPERIMENTAL=y
 CONFIG_BROKEN_ON_SMP=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
 CONFIG_LOCALVERSION=""
 CONFIG_LOCALVERSION_AUTO=y
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
-# CONFIG_IPC_NS is not set
 CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 # CONFIG_TASKSTATS is not set
-# CONFIG_UTS_NS is not set
 # CONFIG_AUDIT is not set
-# CONFIG_IKCONFIG is not set
+CONFIG_IKCONFIG=m
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=16
+# CONFIG_CGROUPS is not set
+# CONFIG_GROUP_SCHED is not set
 CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
 # CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
@@ -53,6 +61,7 @@ CONFIG_SYSCTL=y
 # CONFIG_EMBEDDED is not set
 CONFIG_UID16=y
 CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_KALLSYMS=y
 # CONFIG_KALLSYMS_ALL is not set
 # CONFIG_KALLSYMS_EXTRA_PASS is not set
@@ -60,34 +69,43 @@ CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
 CONFIG_BUG=y
 CONFIG_ELF_CORE=y
+CONFIG_COMPAT_BRK=y
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
 CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
-CONFIG_SLAB=y
 CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
-# CONFIG_SLOB is not set
-
-#
-# Loadable module support
-#
 CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
 CONFIG_MODULE_UNLOAD=y
 # CONFIG_MODULE_FORCE_UNLOAD is not set
 # CONFIG_MODVERSIONS is not set
 # CONFIG_MODULE_SRCVERSION_ALL is not set
 CONFIG_KMOD=y
-
-#
-# Block layer
-#
 CONFIG_BLOCK=y
 # CONFIG_LBD is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
 # CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
 
 #
 # IO Schedulers
@@ -101,6 +119,7 @@ CONFIG_DEFAULT_AS=y
 # CONFIG_DEFAULT_CFQ is not set
 # CONFIG_DEFAULT_NOOP is not set
 CONFIG_DEFAULT_IOSCHED="anticipatory"
+CONFIG_CLASSIC_RCU=y
 
 #
 # System Type
@@ -119,14 +138,17 @@ CONFIG_DEFAULT_IOSCHED="anticipatory"
 # CONFIG_ARCH_NETX is not set
 # CONFIG_ARCH_H720X is not set
 # CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
 # CONFIG_ARCH_IOP32X is not set
 # CONFIG_ARCH_IOP33X is not set
-# CONFIG_ARCH_IOP13XX is not set
-# CONFIG_ARCH_IXP4XX is not set
-# CONFIG_ARCH_IXP2000 is not set
 # CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
 # CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
 # CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_ORION5X is not set
 # CONFIG_ARCH_PNX4008 is not set
 # CONFIG_ARCH_PXA is not set
 # CONFIG_ARCH_RPC is not set
@@ -134,18 +156,32 @@ CONFIG_DEFAULT_IOSCHED="anticipatory"
 CONFIG_ARCH_S3C2410=y
 # CONFIG_ARCH_SHARK is not set
 # CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
 # CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
 CONFIG_PLAT_S3C24XX=y
 CONFIG_CPU_S3C244X=y
+# CONFIG_S3C24XX_PWM is not set
 CONFIG_PM_SIMTEC=y
+CONFIG_S3C2410_DMA=y
+# CONFIG_S3C2410_DMA_DEBUG is not set
+CONFIG_MACH_SMDK=y
+CONFIG_PLAT_S3C=y
+CONFIG_CPU_LLSERIAL_S3C2410=y
+CONFIG_CPU_LLSERIAL_S3C2440=y
+
+#
+# Boot options
+#
 # CONFIG_S3C_BOOT_WATCHDOG is not set
 # CONFIG_S3C_BOOT_ERROR_RESET is not set
+
+#
+# Power management
+#
 # CONFIG_S3C2410_PM_DEBUG is not set
 # CONFIG_S3C2410_PM_CHECK is not set
 CONFIG_S3C_LOWLEVEL_UART_PORT=0
-CONFIG_S3C2410_DMA=y
-# CONFIG_S3C2410_DMA_DEBUG is not set
-CONFIG_MACH_SMDK=y
 
 #
 # S3C2400 Machines
@@ -155,6 +191,8 @@ CONFIG_CPU_S3C2410_DMA=y
 CONFIG_S3C2410_PM=y
 CONFIG_S3C2410_GPIO=y
 CONFIG_S3C2410_CLOCK=y
+CONFIG_SIMTEC_NOR=y
+CONFIG_MACH_BAST_IDE=y
 
 #
 # S3C2410 Machines
@@ -167,6 +205,7 @@ CONFIG_ARCH_BAST=y
 CONFIG_MACH_OTOM=y
 CONFIG_MACH_AML_M5900=y
 CONFIG_BAST_PC104_IRQ=y
+# CONFIG_MACH_TCT_HAMMER is not set
 CONFIG_MACH_VR1000=y
 CONFIG_MACH_QT2410=y
 CONFIG_CPU_S3C2412=y
@@ -176,8 +215,10 @@ CONFIG_S3C2412_PM=y
 #
 # S3C2412 Machines
 #
+# CONFIG_MACH_JIVE is not set
 CONFIG_MACH_SMDK2413=y
 CONFIG_MACH_S3C2413=y
+# CONFIG_MACH_SMDK2412 is not set
 CONFIG_MACH_VSTMS=y
 CONFIG_CPU_S3C2440=y
 CONFIG_S3C2440_DMA=y
@@ -191,6 +232,7 @@ CONFIG_MACH_RX3715=y
 CONFIG_ARCH_S3C2440=y
 CONFIG_MACH_NEXCODER_2440=y
 CONFIG_SMDK2440_CPU2440=y
+# CONFIG_MACH_AT2440EVB is not set
 CONFIG_CPU_S3C2442=y
 
 #
@@ -215,6 +257,7 @@ CONFIG_CPU_32v4T=y
 CONFIG_CPU_32v5=y
 CONFIG_CPU_ABRT_EV4T=y
 CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_NOIFAR=y
 CONFIG_CPU_CACHE_V4WT=y
 CONFIG_CPU_CACHE_VIVT=y
 CONFIG_CPU_COPY_V4WB=y
@@ -236,17 +279,15 @@ CONFIG_CPU_CP15_MMU=y
 # Bus support
 #
 CONFIG_ISA=y
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
 # CONFIG_PCCARD is not set
 
 #
 # Kernel Features
 #
+# CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=200
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
@@ -257,9 +298,13 @@ CONFIG_FLATMEM_MANUAL=y
 CONFIG_FLATMEM=y
 CONFIG_FLAT_NODE_MEM_MAP=y
 # CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4096
 # CONFIG_RESOURCES_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
 CONFIG_ALIGNMENT_TRAP=y
 
 #
@@ -279,7 +324,7 @@ CONFIG_CMDLINE="root=/dev/hda1 ro init=/bin/bash console=ttySAC0"
 # At least one emulation must be selected
 #
 CONFIG_FPE_NWFPE=y
-# CONFIG_FPE_NWFPE_XP is not set
+CONFIG_FPE_NWFPE_XP=y
 # CONFIG_FPE_FASTFPE is not set
 # CONFIG_VFP is not set
 
@@ -295,10 +340,12 @@ CONFIG_BINFMT_AOUT=y
 # Power management options
 #
 CONFIG_PM=y
-# CONFIG_PM_LEGACY is not set
 # CONFIG_PM_DEBUG is not set
-# CONFIG_PM_SYSFS_DEPRECATED is not set
-# CONFIG_APM_EMULATION is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND=y
+CONFIG_SUSPEND_FREEZER=y
+CONFIG_APM_EMULATION=m
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
 
 #
 # Networking
@@ -308,59 +355,67 @@ CONFIG_NET=y
 #
 # Networking options
 #
-# CONFIG_NETDEBUG is not set
-# CONFIG_PACKET is not set
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
 # CONFIG_XFRM_SUB_POLICY is not set
 # CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
-# CONFIG_IP_MULTICAST is not set
+CONFIG_IP_MULTICAST=y
 # CONFIG_IP_ADVANCED_ROUTER is not set
 CONFIG_IP_FIB_HASH=y
 CONFIG_IP_PNP=y
-# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_DHCP=y
 CONFIG_IP_PNP_BOOTP=y
 # CONFIG_IP_PNP_RARP is not set
 # CONFIG_NET_IPIP is not set
 # CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
 # CONFIG_ARPD is not set
 # CONFIG_SYN_COOKIES is not set
 # CONFIG_INET_AH is not set
 # CONFIG_INET_ESP is not set
 # CONFIG_INET_IPCOMP is not set
 # CONFIG_INET_XFRM_TUNNEL is not set
-# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_TUNNEL=m
 CONFIG_INET_XFRM_MODE_TRANSPORT=y
 CONFIG_INET_XFRM_MODE_TUNNEL=y
 CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
 CONFIG_INET_DIAG=y
 CONFIG_INET_TCP_DIAG=y
 # CONFIG_TCP_CONG_ADVANCED is not set
 CONFIG_TCP_CONG_CUBIC=y
 CONFIG_DEFAULT_TCP_CONG="cubic"
 # CONFIG_TCP_MD5SIG is not set
-# CONFIG_IPV6 is not set
-# CONFIG_INET6_XFRM_TUNNEL is not set
-# CONFIG_INET6_TUNNEL is not set
+CONFIG_IPV6=m
+CONFIG_IPV6_PRIVACY=y
+CONFIG_IPV6_ROUTER_PREF=y
+# CONFIG_IPV6_ROUTE_INFO is not set
+# CONFIG_IPV6_OPTIMISTIC_DAD is not set
+CONFIG_INET6_AH=m
+CONFIG_INET6_ESP=m
+CONFIG_INET6_IPCOMP=m
+CONFIG_IPV6_MIP6=m
+CONFIG_INET6_XFRM_TUNNEL=m
+CONFIG_INET6_TUNNEL=m
+CONFIG_INET6_XFRM_MODE_TRANSPORT=m
+CONFIG_INET6_XFRM_MODE_TUNNEL=m
+CONFIG_INET6_XFRM_MODE_BEET=m
+CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
+CONFIG_IPV6_SIT=m
+CONFIG_IPV6_NDISC_NODETYPE=y
+CONFIG_IPV6_TUNNEL=m
+# CONFIG_IPV6_MULTIPLE_TABLES is not set
+# CONFIG_IPV6_MROUTE is not set
 # CONFIG_NETWORK_SECMARK is not set
 # CONFIG_NETFILTER is not set
-
-#
-# DCCP Configuration (EXPERIMENTAL)
-#
 # CONFIG_IP_DCCP is not set
-
-#
-# SCTP Configuration (EXPERIMENTAL)
-#
 # CONFIG_IP_SCTP is not set
-
-#
-# TIPC Configuration (EXPERIMENTAL)
-#
 # CONFIG_TIPC is not set
 # CONFIG_ATM is not set
 # CONFIG_BRIDGE is not set
@@ -373,20 +428,71 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # CONFIG_LAPB is not set
 # CONFIG_ECONET is not set
 # CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
 # CONFIG_NET_SCHED is not set
+CONFIG_NET_SCH_FIFO=y
 
 #
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
 # CONFIG_IRDA is not set
-# CONFIG_BT is not set
+CONFIG_BT=m
+CONFIG_BT_L2CAP=m
+CONFIG_BT_SCO=m
+CONFIG_BT_RFCOMM=m
+CONFIG_BT_RFCOMM_TTY=y
+CONFIG_BT_BNEP=m
+CONFIG_BT_BNEP_MC_FILTER=y
+CONFIG_BT_BNEP_PROTO_FILTER=y
+CONFIG_BT_HIDP=m
+
+#
+# Bluetooth device drivers
+#
+CONFIG_BT_HCIUSB=m
+CONFIG_BT_HCIUSB_SCO=y
+CONFIG_BT_HCIUART=m
+CONFIG_BT_HCIUART_H4=y
+CONFIG_BT_HCIUART_BCSP=y
+CONFIG_BT_HCIUART_LL=y
+CONFIG_BT_HCIBCM203X=m
+CONFIG_BT_HCIBPA10X=m
+CONFIG_BT_HCIBFUSB=m
+CONFIG_BT_HCIVHCI=m
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+CONFIG_CFG80211=m
+CONFIG_NL80211=y
+CONFIG_WIRELESS_EXT=y
+CONFIG_MAC80211=m
+
+#
+# Rate control algorithm selection
+#
+CONFIG_MAC80211_RC_DEFAULT_PID=y
+# CONFIG_MAC80211_RC_DEFAULT_NONE is not set
+
+#
+# Selecting 'y' for an algorithm will
+#
+
+#
+# build the algorithm into mac80211.
+#
+CONFIG_MAC80211_RC_DEFAULT="pid"
+CONFIG_MAC80211_RC_PID=y
+CONFIG_MAC80211_MESH=y
+CONFIG_MAC80211_LEDS=y
+# CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT is not set
+# CONFIG_MAC80211_DEBUG is not set
 # CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
 
 #
 # Device Drivers
@@ -395,21 +501,14 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 #
 # Generic Driver Options
 #
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
-# CONFIG_FW_LOADER is not set
+CONFIG_FW_LOADER=m
 # CONFIG_DEBUG_DRIVER is not set
 # CONFIG_DEBUG_DEVRES is not set
 # CONFIG_SYS_HYPERVISOR is not set
-
-#
-# Connector - unified userspace <-> kernelspace linker
-#
 # CONFIG_CONNECTOR is not set
-
-#
-# Memory Technology Devices (MTD)
-#
 CONFIG_MTD=y
 # CONFIG_MTD_DEBUG is not set
 # CONFIG_MTD_CONCAT is not set
@@ -420,6 +519,7 @@ CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED=y
 # CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
 CONFIG_MTD_CMDLINE_PARTS=y
 # CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
 
 #
 # User Modules And Translation Layers
@@ -432,6 +532,7 @@ CONFIG_MTD_BLOCK=y
 # CONFIG_INFTL is not set
 # CONFIG_RFD_FTL is not set
 # CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
 
 #
 # RAM/ROM/Flash chip drivers
@@ -457,7 +558,6 @@ CONFIG_MTD_CFI_UTIL=y
 # CONFIG_MTD_RAM is not set
 CONFIG_MTD_ROM=y
 # CONFIG_MTD_ABSENT is not set
-# CONFIG_MTD_OBSOLETE_CHIPS is not set
 
 #
 # Mapping drivers for chip access
@@ -486,13 +586,10 @@ CONFIG_MTD_BAST_MAXSIZE=4
 # CONFIG_MTD_DOC2000 is not set
 # CONFIG_MTD_DOC2001 is not set
 # CONFIG_MTD_DOC2001PLUS is not set
-
-#
-# NAND Flash Device Drivers
-#
 CONFIG_MTD_NAND=y
 # CONFIG_MTD_NAND_VERIFY_WRITE is not set
 # CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
 CONFIG_MTD_NAND_IDS=y
 CONFIG_MTD_NAND_S3C2410=y
 # CONFIG_MTD_NAND_S3C2410_DEBUG is not set
@@ -500,30 +597,25 @@ CONFIG_MTD_NAND_S3C2410=y
 # CONFIG_MTD_NAND_S3C2410_CLKSTOP is not set
 # CONFIG_MTD_NAND_DISKONCHIP is not set
 # CONFIG_MTD_NAND_NANDSIM is not set
-
-#
-# OneNAND Flash Device Drivers
-#
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
 # CONFIG_MTD_ONENAND is not set
 
 #
-# Parallel port support
+# UBI - Unsorted block images
 #
+# CONFIG_MTD_UBI is not set
 CONFIG_PARPORT=y
-# CONFIG_PARPORT_PC is not set
+CONFIG_PARPORT_PC=m
+# CONFIG_PARPORT_PC_FIFO is not set
+# CONFIG_PARPORT_PC_SUPERIO is not set
 # CONFIG_PARPORT_GSC is not set
-# CONFIG_PARPORT_AX88796 is not set
+CONFIG_PARPORT_AX88796=m
 CONFIG_PARPORT_1284=y
-
-#
-# Plug and Play support
-#
+CONFIG_PARPORT_NOT_PC=y
 # CONFIG_PNP is not set
-# CONFIG_PNPACPI is not set
-
-#
-# Block devices
-#
+CONFIG_BLK_DEV=y
+# CONFIG_PARIDE is not set
 # CONFIG_BLK_DEV_COW_COMMON is not set
 CONFIG_BLK_DEV_LOOP=y
 # CONFIG_BLK_DEV_CRYPTOLOOP is not set
@@ -532,34 +624,34 @@ CONFIG_BLK_DEV_NBD=m
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_COUNT=16
 CONFIG_BLK_DEV_RAM_SIZE=4096
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
+# CONFIG_BLK_DEV_XIP is not set
 # CONFIG_CDROM_PKTCDVD is not set
 CONFIG_ATA_OVER_ETH=m
-
-#
-# ATA/ATAPI/MFM/RLL support
-#
+CONFIG_MISC_DEVICES=y
+# CONFIG_EEPROM_93CX6 is not set
+# CONFIG_ENCLOSURE_SERVICES is not set
+CONFIG_HAVE_IDE=y
 CONFIG_IDE=y
 CONFIG_BLK_DEV_IDE=y
 
 #
-# Please see Documentation/ide.txt for help/info on IDE drives
+# Please see Documentation/ide/ide.txt for help/info on IDE drives
 #
 # CONFIG_BLK_DEV_IDE_SATA is not set
 CONFIG_BLK_DEV_IDEDISK=y
 # CONFIG_IDEDISK_MULTI_MODE is not set
 CONFIG_BLK_DEV_IDECD=y
+CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS=y
 CONFIG_BLK_DEV_IDETAPE=m
 CONFIG_BLK_DEV_IDEFLOPPY=m
+# CONFIG_BLK_DEV_IDESCSI is not set
 # CONFIG_IDE_TASK_IOCTL is not set
+CONFIG_IDE_PROC_FS=y
 
 #
 # IDE chipset support/bugfixes
 #
-CONFIG_IDE_GENERIC=y
-# CONFIG_IDE_ARM is not set
-CONFIG_BLK_DEV_IDE_BAST=y
-# CONFIG_IDE_CHIPSETS is not set
+# CONFIG_BLK_DEV_PLATFORM is not set
 # CONFIG_BLK_DEV_IDEDMA is not set
 # CONFIG_BLK_DEV_HD is not set
 
@@ -567,101 +659,119 @@ CONFIG_BLK_DEV_IDE_BAST=y
 # SCSI device support
 #
 # CONFIG_RAID_ATTRS is not set
-# CONFIG_SCSI is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+CONFIG_SCSI_TGT=m
 # CONFIG_SCSI_NETLINK is not set
-
-#
-# Serial ATA (prod) and Parallel ATA (experimental) drivers
-#
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+CONFIG_CHR_DEV_ST=m
+# CONFIG_CHR_DEV_OSST is not set
+CONFIG_BLK_DEV_SR=m
+CONFIG_BLK_DEV_SR_VENDOR=y
+CONFIG_CHR_DEV_SG=y
+CONFIG_CHR_DEV_SCH=m
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+CONFIG_SCSI_CONSTANTS=y
+# CONFIG_SCSI_LOGGING is not set
+CONFIG_SCSI_SCAN_ASYNC=y
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_AHA152X is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_ADVANSYS is not set
+# CONFIG_SCSI_IN2000 is not set
+# CONFIG_SCSI_DTC3280 is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_GENERIC_NCR5380 is not set
+# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set
+# CONFIG_SCSI_PPA is not set
+# CONFIG_SCSI_IMM is not set
+# CONFIG_SCSI_NCR53C406A is not set
+# CONFIG_SCSI_PAS16 is not set
+# CONFIG_SCSI_QLOGIC_FAS is not set
+# CONFIG_SCSI_SYM53C416 is not set
+# CONFIG_SCSI_T128 is not set
+# CONFIG_SCSI_DEBUG is not set
 # CONFIG_ATA is not set
-
-#
-# Multi-device support (RAID and LVM)
-#
+CONFIG_HAVE_PATA_PLATFORM=y
 # CONFIG_MD is not set
-
-#
-# Fusion MPT device support
-#
-# CONFIG_FUSION is not set
-
-#
-# IEEE 1394 (FireWire) support
-#
-
-#
-# I2O device support
-#
-
-#
-# Network device support
-#
 CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
 # CONFIG_DUMMY is not set
 # CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
 # CONFIG_EQUALIZER is not set
 # CONFIG_TUN is not set
-
-#
-# ARCnet devices
-#
+# CONFIG_VETH is not set
 # CONFIG_ARCNET is not set
-
-#
-# PHY device support
-#
 # CONFIG_PHYLIB is not set
-
-#
-# Ethernet (10 or 100Mbit)
-#
 CONFIG_NET_ETHERNET=y
 CONFIG_MII=y
+# CONFIG_AX88796 is not set
 # CONFIG_NET_VENDOR_3COM is not set
 # CONFIG_NET_VENDOR_SMC is not set
 # CONFIG_SMC91X is not set
 CONFIG_DM9000=y
+# CONFIG_ENC28J60 is not set
+CONFIG_DM9000_DEBUGLEVEL=4
 # CONFIG_NET_VENDOR_RACAL is not set
 # CONFIG_AT1700 is not set
 # CONFIG_DEPCA is not set
 # CONFIG_HP100 is not set
 # CONFIG_NET_ISA is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
 # CONFIG_NET_PCI is not set
+# CONFIG_B44 is not set
 # CONFIG_NET_POCKET is not set
-
-#
-# Ethernet (1000 Mbit)
-#
-
-#
-# Ethernet (10000 Mbit)
-#
-
-#
-# Token Ring devices
-#
+CONFIG_NETDEV_1000=y
+# CONFIG_E1000E_ENABLED is not set
+CONFIG_NETDEV_10000=y
 # CONFIG_TR is not set
 
 #
-# Wireless LAN (non-hamradio)
+# Wireless LAN
 #
-# CONFIG_NET_RADIO is not set
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
 
 #
-# Wan interfaces
+# USB Network Adapters
 #
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
 # CONFIG_WAN is not set
 # CONFIG_PLIP is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
-# CONFIG_SHAPER is not set
 # CONFIG_NETCONSOLE is not set
 # CONFIG_NETPOLL is not set
 # CONFIG_NET_POLL_CONTROLLER is not set
-
-#
-# ISDN subsystem
-#
 # CONFIG_ISDN is not set
 
 #
@@ -669,6 +779,7 @@ CONFIG_DM9000=y
 #
 CONFIG_INPUT=y
 # CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
 
 #
 # Userland interfaces
@@ -678,7 +789,6 @@ CONFIG_INPUT_MOUSEDEV_PSAUX=y
 CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
 CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 # CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
 # CONFIG_INPUT_EVDEV is not set
 # CONFIG_INPUT_EVBUG is not set
 
@@ -695,12 +805,21 @@ CONFIG_KEYBOARD_ATKBD=y
 # CONFIG_KEYBOARD_GPIO is not set
 CONFIG_INPUT_MOUSE=y
 CONFIG_MOUSE_PS2=y
+CONFIG_MOUSE_PS2_ALPS=y
+CONFIG_MOUSE_PS2_LOGIPS2PP=y
+CONFIG_MOUSE_PS2_SYNAPTICS=y
+CONFIG_MOUSE_PS2_LIFEBOOK=y
+CONFIG_MOUSE_PS2_TRACKPOINT=y
+# CONFIG_MOUSE_PS2_TOUCHKIT is not set
 # CONFIG_MOUSE_SERIAL is not set
+# CONFIG_MOUSE_APPLETOUCH is not set
 # CONFIG_MOUSE_INPORT is not set
 # CONFIG_MOUSE_LOGIBM is not set
 # CONFIG_MOUSE_PC110PAD is not set
 # CONFIG_MOUSE_VSXXXAA is not set
+# CONFIG_MOUSE_GPIO is not set
 # CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
 # CONFIG_INPUT_TOUCHSCREEN is not set
 # CONFIG_INPUT_MISC is not set
 
@@ -721,6 +840,7 @@ CONFIG_VT=y
 CONFIG_VT_CONSOLE=y
 CONFIG_HW_CONSOLE=y
 # CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
 CONFIG_SERIAL_NONSTANDARD=y
 # CONFIG_COMPUTONE is not set
 # CONFIG_ROCKETPORT is not set
@@ -728,8 +848,6 @@ CONFIG_SERIAL_NONSTANDARD=y
 # CONFIG_DIGIEPCA is not set
 # CONFIG_MOXA_INTELLIO is not set
 # CONFIG_MOXA_SMARTIO is not set
-# CONFIG_MOXA_SMARTIO_NEW is not set
-# CONFIG_SYNCLINKMP is not set
 # CONFIG_N_HDLC is not set
 # CONFIG_RISCOM8 is not set
 # CONFIG_SPECIALIX is not set
@@ -758,8 +876,12 @@ CONFIG_SERIAL_8250_SHARE_IRQ=y
 #
 # Non-8250 serial port support
 #
+CONFIG_SERIAL_SAMSUNG=y
+# CONFIG_SERIAL_SAMSUNG_DEBUG is not set
+CONFIG_SERIAL_SAMSUNG_CONSOLE=y
 CONFIG_SERIAL_S3C2410=y
-CONFIG_SERIAL_S3C2410_CONSOLE=y
+CONFIG_SERIAL_S3C2412=y
+CONFIG_SERIAL_S3C2440=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 CONFIG_UNIX98_PTYS=y
@@ -768,89 +890,50 @@ CONFIG_LEGACY_PTY_COUNT=256
 CONFIG_PRINTER=y
 # CONFIG_LP_CONSOLE is not set
 CONFIG_PPDEV=y
-# CONFIG_TIPAR is not set
-
-#
-# IPMI
-#
 # CONFIG_IPMI_HANDLER is not set
-
-#
-# Watchdog Cards
-#
-CONFIG_WATCHDOG=y
-# CONFIG_WATCHDOG_NOWAYOUT is not set
-
-#
-# Watchdog Device Drivers
-#
-# CONFIG_SOFT_WATCHDOG is not set
-CONFIG_S3C2410_WATCHDOG=y
-
-#
-# ISA-based Watchdog Cards
-#
-# CONFIG_PCWATCHDOG is not set
-# CONFIG_MIXCOMWD is not set
-# CONFIG_WDT is not set
-
-#
-# USB-based Watchdog Cards
-#
-# CONFIG_USBPCWATCHDOG is not set
 CONFIG_HW_RANDOM=y
 # CONFIG_NVRAM is not set
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
 # CONFIG_RAW_DRIVER is not set
-
-#
-# TPM devices
-#
 # CONFIG_TCG_TPM is not set
-
-#
-# I2C support
-#
+CONFIG_DEVPORT=y
 CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
 CONFIG_I2C_CHARDEV=m
-
-#
-# I2C Algorithms
-#
-CONFIG_I2C_ALGOBIT=m
-# CONFIG_I2C_ALGOPCF is not set
-# CONFIG_I2C_ALGOPCA is not set
+CONFIG_I2C_ALGOBIT=y
 
 #
 # I2C Hardware Bus support
 #
 # CONFIG_I2C_ELEKTOR is not set
+# CONFIG_I2C_GPIO is not set
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_PARPORT is not set
 # CONFIG_I2C_PARPORT_LIGHT is not set
 CONFIG_I2C_S3C2410=y
+CONFIG_I2C_SIMTEC=y
+# CONFIG_I2C_TAOS_EVM is not set
 # CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
 # CONFIG_I2C_PCA_ISA is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
 
 #
 # Miscellaneous I2C Chip support
 #
-# CONFIG_SENSORS_DS1337 is not set
-# CONFIG_SENSORS_DS1374 is not set
+# CONFIG_DS1682 is not set
 CONFIG_SENSORS_EEPROM=m
 # CONFIG_SENSORS_PCF8574 is not set
-# CONFIG_SENSORS_PCA9539 is not set
+# CONFIG_PCF8575 is not set
 # CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_TPS65010 is not set
 # CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
 # CONFIG_I2C_DEBUG_CHIP is not set
-
-#
-# SPI support
-#
 CONFIG_SPI=y
 # CONFIG_SPI_DEBUG is not set
 CONFIG_SPI_MASTER=y
@@ -860,6 +943,7 @@ CONFIG_SPI_MASTER=y
 #
 CONFIG_SPI_BITBANG=m
 # CONFIG_SPI_BUTTERFLY is not set
+# CONFIG_SPI_LM70_LLP is not set
 CONFIG_SPI_S3C24XX=m
 CONFIG_SPI_S3C24XX_GPIO=m
 
@@ -867,30 +951,43 @@ CONFIG_SPI_S3C24XX_GPIO=m
 # SPI Protocol Masters
 #
 # CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+CONFIG_HAVE_GPIO_LIB=y
 
 #
-# Dallas's 1-wire bus
+# GPIO Support
 #
-# CONFIG_W1 is not set
+# CONFIG_DEBUG_GPIO is not set
 
 #
-# Hardware Monitoring support
+# I2C GPIO expanders:
+#
+# CONFIG_GPIO_PCA953X is not set
+# CONFIG_GPIO_PCF857X is not set
+
 #
+# SPI GPIO expanders:
+#
+# CONFIG_GPIO_MCP23S08 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
 CONFIG_HWMON=y
 CONFIG_HWMON_VID=m
-# CONFIG_SENSORS_ABITUGURU is not set
+# CONFIG_SENSORS_AD7418 is not set
 # CONFIG_SENSORS_ADM1021 is not set
 # CONFIG_SENSORS_ADM1025 is not set
 # CONFIG_SENSORS_ADM1026 is not set
 # CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
-# CONFIG_SENSORS_ASB100 is not set
+# CONFIG_SENSORS_ADT7470 is not set
+# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_F71805F is not set
-# CONFIG_SENSORS_FSCHER is not set
-# CONFIG_SENSORS_FSCPOS is not set
+# CONFIG_SENSORS_F71882FG is not set
+# CONFIG_SENSORS_F75375S is not set
 # CONFIG_SENSORS_GL518SM is not set
 # CONFIG_SENSORS_GL520SM is not set
 # CONFIG_SENSORS_IT87 is not set
@@ -905,72 +1002,95 @@ CONFIG_SENSORS_LM85=m
 # CONFIG_SENSORS_LM87 is not set
 # CONFIG_SENSORS_LM90 is not set
 # CONFIG_SENSORS_LM92 is not set
+# CONFIG_SENSORS_LM93 is not set
 # CONFIG_SENSORS_MAX1619 is not set
+# CONFIG_SENSORS_MAX6650 is not set
 # CONFIG_SENSORS_PC87360 is not set
 # CONFIG_SENSORS_PC87427 is not set
+# CONFIG_SENSORS_DME1737 is not set
 # CONFIG_SENSORS_SMSC47M1 is not set
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
+# CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_VT1211 is not set
 # CONFIG_SENSORS_W83781D is not set
 # CONFIG_SENSORS_W83791D is not set
 # CONFIG_SENSORS_W83792D is not set
 # CONFIG_SENSORS_W83793 is not set
 # CONFIG_SENSORS_W83L785TS is not set
+# CONFIG_SENSORS_W83L786NG is not set
 # CONFIG_SENSORS_W83627HF is not set
 # CONFIG_SENSORS_W83627EHF is not set
 # CONFIG_HWMON_DEBUG_CHIP is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
 
 #
-# Misc devices
+# Watchdog Device Drivers
 #
+# CONFIG_SOFT_WATCHDOG is not set
+CONFIG_S3C2410_WATCHDOG=y
 
 #
-# Multifunction device drivers
+# ISA-based Watchdog Cards
 #
-# CONFIG_MFD_SM501 is not set
+# CONFIG_PCWATCHDOG is not set
+# CONFIG_MIXCOMWD is not set
+# CONFIG_WDT is not set
 
 #
-# LED devices
+# USB-based Watchdog Cards
 #
-CONFIG_NEW_LEDS=y
-CONFIG_LEDS_CLASS=m
+# CONFIG_USBPCWATCHDOG is not set
 
 #
-# LED drivers
+# Sonics Silicon Backplane
 #
-CONFIG_LEDS_S3C24XX=m
-CONFIG_LEDS_H1940=m
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
 
 #
-# LED Triggers
+# Multifunction device drivers
 #
-CONFIG_LEDS_TRIGGERS=y
-CONFIG_LEDS_TRIGGER_TIMER=m
-# CONFIG_LEDS_TRIGGER_IDE_DISK is not set
-CONFIG_LEDS_TRIGGER_HEARTBEAT=m
+CONFIG_MFD_SM501=y
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
 
 #
 # Multimedia devices
 #
+
+#
+# Multimedia core support
+#
 # CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
 
 #
-# Digital Video Broadcasting Devices
+# Multimedia drivers
 #
-# CONFIG_DVB is not set
-# CONFIG_USB_DABUSB is not set
+# CONFIG_DAB is not set
 
 #
 # Graphics support
 #
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
 CONFIG_FB=y
 CONFIG_FIRMWARE_EDID=y
 # CONFIG_FB_DDC is not set
 CONFIG_FB_CFB_FILLRECT=y
 CONFIG_FB_CFB_COPYAREA=y
 CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
 # CONFIG_FB_SVGALIB is not set
 # CONFIG_FB_MACMODES is not set
 # CONFIG_FB_BACKLIGHT is not set
@@ -978,12 +1098,19 @@ CONFIG_FB_MODE_HELPERS=y
 # CONFIG_FB_TILEBLITTING is not set
 
 #
-# Frambuffer hardware drivers
+# Frambuffer hardware drivers
 #
 # CONFIG_FB_S1D13XXX is not set
 CONFIG_FB_S3C2410=y
 # CONFIG_FB_S3C2410_DEBUG is not set
+CONFIG_FB_SM501=y
 # CONFIG_FB_VIRTUAL is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
 
 #
 # Console display driver support
@@ -992,40 +1119,45 @@ CONFIG_FB_S3C2410=y
 # CONFIG_MDA_CONSOLE is not set
 CONFIG_DUMMY_CONSOLE=y
 CONFIG_FRAMEBUFFER_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
 # CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
 # CONFIG_FONTS is not set
 CONFIG_FONT_8x8=y
 CONFIG_FONT_8x16=y
-
-#
-# Logo configuration
-#
 # CONFIG_LOGO is not set
 
 #
 # Sound
 #
 # CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
 
 #
-# HID Devices
+# USB Input Devices
 #
-CONFIG_HID=y
-# CONFIG_HID_DEBUG is not set
+# CONFIG_USB_HID is not set
 
 #
-# USB support
+# USB HID Boot Protocol drivers
 #
+# CONFIG_USB_KBD is not set
+# CONFIG_USB_MOUSE is not set
+CONFIG_USB_SUPPORT=y
 CONFIG_USB_ARCH_HAS_HCD=y
 CONFIG_USB_ARCH_HAS_OHCI=y
 # CONFIG_USB_ARCH_HAS_EHCI is not set
 CONFIG_USB=y
 # CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
 
 #
 # Miscellaneous USB options
 #
 CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
 # CONFIG_USB_DYNAMIC_MINORS is not set
 # CONFIG_USB_SUSPEND is not set
 # CONFIG_USB_OTG is not set
@@ -1033,18 +1165,22 @@ CONFIG_USB_DEVICEFS=y
 #
 # USB Host Controller Drivers
 #
+# CONFIG_USB_C67X00_HCD is not set
 # CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
 CONFIG_USB_OHCI_HCD=y
 # CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
 # CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
 CONFIG_USB_OHCI_LITTLE_ENDIAN=y
 # CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
 
 #
 # USB Device Class drivers
 #
-# CONFIG_USB_ACM is not set
-# CONFIG_USB_PRINTER is not set
+CONFIG_USB_ACM=m
+CONFIG_USB_PRINTER=m
+CONFIG_USB_WDM=m
 
 #
 # NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
@@ -1053,57 +1189,78 @@ CONFIG_USB_OHCI_LITTLE_ENDIAN=y
 #
 # may also be needed; see USB_STORAGE Help for more information
 #
-# CONFIG_USB_LIBUSUAL is not set
-
-#
-# USB Input Devices
-#
-# CONFIG_USB_HID is not set
-
-#
-# USB HID Boot Protocol drivers
-#
-# CONFIG_USB_KBD is not set
-# CONFIG_USB_MOUSE is not set
-# CONFIG_USB_AIPTEK is not set
-# CONFIG_USB_WACOM is not set
-# CONFIG_USB_ACECAD is not set
-# CONFIG_USB_KBTAB is not set
-# CONFIG_USB_POWERMATE is not set
-# CONFIG_USB_TOUCHSCREEN is not set
-# CONFIG_USB_YEALINK is not set
-# CONFIG_USB_XPAD is not set
-# CONFIG_USB_ATI_REMOTE is not set
-# CONFIG_USB_ATI_REMOTE2 is not set
-# CONFIG_USB_KEYSPAN_REMOTE is not set
-# CONFIG_USB_APPLETOUCH is not set
-# CONFIG_USB_GTCO is not set
+CONFIG_USB_STORAGE=m
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+CONFIG_USB_LIBUSUAL=y
 
 #
 # USB Imaging devices
 #
 # CONFIG_USB_MDC800 is not set
-
-#
-# USB Network Adapters
-#
-# CONFIG_USB_CATC is not set
-# CONFIG_USB_KAWETH is not set
-# CONFIG_USB_PEGASUS is not set
-# CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_USBNET_MII is not set
-# CONFIG_USB_USBNET is not set
+# CONFIG_USB_MICROTEK is not set
 CONFIG_USB_MON=y
 
 #
 # USB port drivers
 #
 # CONFIG_USB_USS720 is not set
-
-#
-# USB Serial Converter support
-#
-# CONFIG_USB_SERIAL is not set
+CONFIG_USB_SERIAL=y
+# CONFIG_USB_SERIAL_CONSOLE is not set
+# CONFIG_USB_EZUSB is not set
+CONFIG_USB_SERIAL_GENERIC=y
+# CONFIG_USB_SERIAL_AIRCABLE is not set
+# CONFIG_USB_SERIAL_AIRPRIME is not set
+# CONFIG_USB_SERIAL_ARK3116 is not set
+# CONFIG_USB_SERIAL_BELKIN is not set
+# CONFIG_USB_SERIAL_CH341 is not set
+# CONFIG_USB_SERIAL_WHITEHEAT is not set
+# CONFIG_USB_SERIAL_DIGI_ACCELEPORT is not set
+# CONFIG_USB_SERIAL_CP2101 is not set
+# CONFIG_USB_SERIAL_CYPRESS_M8 is not set
+# CONFIG_USB_SERIAL_EMPEG is not set
+CONFIG_USB_SERIAL_FTDI_SIO=y
+# CONFIG_USB_SERIAL_FUNSOFT is not set
+# CONFIG_USB_SERIAL_VISOR is not set
+# CONFIG_USB_SERIAL_IPAQ is not set
+# CONFIG_USB_SERIAL_IR is not set
+# CONFIG_USB_SERIAL_EDGEPORT is not set
+# CONFIG_USB_SERIAL_EDGEPORT_TI is not set
+# CONFIG_USB_SERIAL_GARMIN is not set
+# CONFIG_USB_SERIAL_IPW is not set
+# CONFIG_USB_SERIAL_IUU is not set
+# CONFIG_USB_SERIAL_KEYSPAN_PDA is not set
+# CONFIG_USB_SERIAL_KEYSPAN is not set
+# CONFIG_USB_SERIAL_KLSI is not set
+# CONFIG_USB_SERIAL_KOBIL_SCT is not set
+# CONFIG_USB_SERIAL_MCT_U232 is not set
+# CONFIG_USB_SERIAL_MOS7720 is not set
+# CONFIG_USB_SERIAL_MOS7840 is not set
+# CONFIG_USB_SERIAL_MOTOROLA is not set
+CONFIG_USB_SERIAL_NAVMAN=m
+CONFIG_USB_SERIAL_PL2303=y
+# CONFIG_USB_SERIAL_OTI6858 is not set
+# CONFIG_USB_SERIAL_SPCP8X5 is not set
+# CONFIG_USB_SERIAL_HP4X is not set
+# CONFIG_USB_SERIAL_SAFE is not set
+# CONFIG_USB_SERIAL_SIERRAWIRELESS is not set
+# CONFIG_USB_SERIAL_TI is not set
+# CONFIG_USB_SERIAL_CYBERJACK is not set
+# CONFIG_USB_SERIAL_XIRCOM is not set
+CONFIG_USB_SERIAL_OPTION=m
+# CONFIG_USB_SERIAL_OMNINET is not set
+# CONFIG_USB_SERIAL_DEBUG is not set
 
 #
 # USB Miscellaneous drivers
@@ -1116,35 +1273,38 @@ CONFIG_USB_MON=y
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
 # CONFIG_USB_BERRY_CHARGE is not set
-# CONFIG_USB_LED is not set
+CONFIG_USB_LED=m
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
 # CONFIG_USB_PHIDGET is not set
 # CONFIG_USB_IDMOUSE is not set
 # CONFIG_USB_FTDI_ELAN is not set
 # CONFIG_USB_APPLEDISPLAY is not set
-# CONFIG_USB_LD is not set
+CONFIG_USB_LD=m
 # CONFIG_USB_TRANCEVIBRATOR is not set
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
-
-#
-# USB DSL modem support
-#
-
-#
-# USB Gadget Support
-#
+# CONFIG_USB_ISIGHTFW is not set
 # CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=m
 
 #
-# MMC/SD Card support
+# LED drivers
 #
-# CONFIG_MMC is not set
+CONFIG_LEDS_S3C24XX=m
+CONFIG_LEDS_H1940=m
+# CONFIG_LEDS_GPIO is not set
 
 #
-# Real Time Clock
+# LED Triggers
 #
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_TIMER=m
+# CONFIG_LEDS_TRIGGER_IDE_DISK is not set
+CONFIG_LEDS_TRIGGER_HEARTBEAT=m
+# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
 CONFIG_RTC_LIB=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_HCTOSYS=y
@@ -1158,61 +1318,86 @@ CONFIG_RTC_INTF_SYSFS=y
 CONFIG_RTC_INTF_PROC=y
 CONFIG_RTC_INTF_DEV=y
 # CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
 
 #
-# RTC drivers
+# I2C RTC drivers
 #
-# CONFIG_RTC_DRV_CMOS is not set
-# CONFIG_RTC_DRV_X1205 is not set
 # CONFIG_RTC_DRV_DS1307 is not set
-# CONFIG_RTC_DRV_DS1553 is not set
-# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
 # CONFIG_RTC_DRV_DS1672 is not set
-# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
 # CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
+# CONFIG_RTC_DRV_FM3130 is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_R9701 is not set
 # CONFIG_RTC_DRV_RS5C348 is not set
-# CONFIG_RTC_DRV_RS5C372 is not set
-CONFIG_RTC_DRV_S3C=y
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
 # CONFIG_RTC_DRV_M48T86 is not set
-# CONFIG_RTC_DRV_TEST is not set
-# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
 # CONFIG_RTC_DRV_V3020 is not set
 
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_S3C=y
+# CONFIG_UIO is not set
+
 #
 # File systems
 #
 CONFIG_EXT2_FS=y
-# CONFIG_EXT2_FS_XATTR is not set
+CONFIG_EXT2_FS_XATTR=y
+CONFIG_EXT2_FS_POSIX_ACL=y
+CONFIG_EXT2_FS_SECURITY=y
 # CONFIG_EXT2_FS_XIP is not set
 CONFIG_EXT3_FS=y
 CONFIG_EXT3_FS_XATTR=y
-# CONFIG_EXT3_FS_POSIX_ACL is not set
+CONFIG_EXT3_FS_POSIX_ACL=y
 # CONFIG_EXT3_FS_SECURITY is not set
 # CONFIG_EXT4DEV_FS is not set
 CONFIG_JBD=y
-# CONFIG_JBD_DEBUG is not set
 CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
+CONFIG_FS_POSIX_ACL=y
 # CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
 # CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-CONFIG_ROMFS_FS=y
+CONFIG_DNOTIFY=y
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
 # CONFIG_AUTOFS_FS is not set
 # CONFIG_AUTOFS4_FS is not set
 # CONFIG_FUSE_FS is not set
+CONFIG_GENERIC_ACL=y
 
 #
 # CD-ROM/DVD Filesystems
 #
-# CONFIG_ISO9660_FS is not set
-# CONFIG_UDF_FS is not set
+CONFIG_ISO9660_FS=y
+CONFIG_JOLIET=y
+# CONFIG_ZISOFS is not set
+CONFIG_UDF_FS=m
+CONFIG_UDF_NLS=y
 
 #
 # DOS/FAT/NT Filesystems
@@ -1222,7 +1407,9 @@ CONFIG_MSDOS_FS=y
 CONFIG_VFAT_FS=y
 CONFIG_FAT_DEFAULT_CODEPAGE=437
 CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
-# CONFIG_NTFS_FS is not set
+CONFIG_NTFS_FS=m
+# CONFIG_NTFS_DEBUG is not set
+# CONFIG_NTFS_RW is not set
 
 #
 # Pseudo filesystems
@@ -1230,10 +1417,10 @@ CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
 CONFIG_PROC_FS=y
 CONFIG_PROC_SYSCTL=y
 CONFIG_SYSFS=y
-# CONFIG_TMPFS is not set
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
 # CONFIG_HUGETLB_PAGE is not set
-CONFIG_RAMFS=y
-# CONFIG_CONFIGFS_FS is not set
+CONFIG_CONFIGFS_FS=m
 
 #
 # Miscellaneous filesystems
@@ -1248,31 +1435,32 @@ CONFIG_RAMFS=y
 CONFIG_JFFS2_FS=y
 CONFIG_JFFS2_FS_DEBUG=0
 CONFIG_JFFS2_FS_WRITEBUFFER=y
-# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+CONFIG_JFFS2_SUMMARY=y
 # CONFIG_JFFS2_FS_XATTR is not set
 # CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
 CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
 CONFIG_CRAMFS=y
 # CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
 # CONFIG_HPFS_FS is not set
 # CONFIG_QNX4FS_FS is not set
+CONFIG_ROMFS_FS=y
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
+CONFIG_NETWORK_FILESYSTEMS=y
 CONFIG_NFS_FS=y
 # CONFIG_NFS_V3 is not set
 # CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
 # CONFIG_NFSD is not set
 CONFIG_ROOT_NFS=y
 CONFIG_LOCKD=y
 CONFIG_NFS_COMMON=y
 CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
@@ -1280,7 +1468,6 @@ CONFIG_SUNRPC=y
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
 # CONFIG_AFS_FS is not set
-# CONFIG_9P_FS is not set
 
 #
 # Partition Types
@@ -1302,94 +1489,93 @@ CONFIG_SOLARIS_X86_PARTITION=y
 # CONFIG_SUN_PARTITION is not set
 # CONFIG_KARMA_PARTITION is not set
 # CONFIG_EFI_PARTITION is not set
-
-#
-# Native Language Support
-#
+# CONFIG_SYSV68_PARTITION is not set
 CONFIG_NLS=y
 CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
-# CONFIG_NLS_CODEPAGE_737 is not set
-# CONFIG_NLS_CODEPAGE_775 is not set
-# CONFIG_NLS_CODEPAGE_850 is not set
-# CONFIG_NLS_CODEPAGE_852 is not set
-# CONFIG_NLS_CODEPAGE_855 is not set
-# CONFIG_NLS_CODEPAGE_857 is not set
-# CONFIG_NLS_CODEPAGE_860 is not set
-# CONFIG_NLS_CODEPAGE_861 is not set
-# CONFIG_NLS_CODEPAGE_862 is not set
-# CONFIG_NLS_CODEPAGE_863 is not set
-# CONFIG_NLS_CODEPAGE_864 is not set
-# CONFIG_NLS_CODEPAGE_865 is not set
-# CONFIG_NLS_CODEPAGE_866 is not set
-# CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
-# CONFIG_NLS_CODEPAGE_874 is not set
-# CONFIG_NLS_ISO8859_8 is not set
-# CONFIG_NLS_CODEPAGE_1250 is not set
-# CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-# CONFIG_NLS_ISO8859_1 is not set
-# CONFIG_NLS_ISO8859_2 is not set
-# CONFIG_NLS_ISO8859_3 is not set
-# CONFIG_NLS_ISO8859_4 is not set
-# CONFIG_NLS_ISO8859_5 is not set
-# CONFIG_NLS_ISO8859_6 is not set
-# CONFIG_NLS_ISO8859_7 is not set
-# CONFIG_NLS_ISO8859_9 is not set
-# CONFIG_NLS_ISO8859_13 is not set
-# CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
-# CONFIG_NLS_KOI8_R is not set
-# CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
-
-#
-# Distributed Lock Manager
-#
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_CODEPAGE_737=m
+CONFIG_NLS_CODEPAGE_775=m
+CONFIG_NLS_CODEPAGE_850=y
+CONFIG_NLS_CODEPAGE_852=m
+CONFIG_NLS_CODEPAGE_855=m
+CONFIG_NLS_CODEPAGE_857=m
+CONFIG_NLS_CODEPAGE_860=m
+CONFIG_NLS_CODEPAGE_861=m
+CONFIG_NLS_CODEPAGE_862=m
+CONFIG_NLS_CODEPAGE_863=m
+CONFIG_NLS_CODEPAGE_864=m
+CONFIG_NLS_CODEPAGE_865=m
+CONFIG_NLS_CODEPAGE_866=m
+CONFIG_NLS_CODEPAGE_869=m
+CONFIG_NLS_CODEPAGE_936=m
+CONFIG_NLS_CODEPAGE_950=m
+CONFIG_NLS_CODEPAGE_932=m
+CONFIG_NLS_CODEPAGE_949=m
+CONFIG_NLS_CODEPAGE_874=m
+CONFIG_NLS_ISO8859_8=m
+CONFIG_NLS_CODEPAGE_1250=m
+CONFIG_NLS_CODEPAGE_1251=m
+CONFIG_NLS_ASCII=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_NLS_ISO8859_2=m
+CONFIG_NLS_ISO8859_3=m
+CONFIG_NLS_ISO8859_4=m
+CONFIG_NLS_ISO8859_5=m
+CONFIG_NLS_ISO8859_6=m
+CONFIG_NLS_ISO8859_7=m
+CONFIG_NLS_ISO8859_9=m
+CONFIG_NLS_ISO8859_13=m
+CONFIG_NLS_ISO8859_14=m
+CONFIG_NLS_ISO8859_15=m
+CONFIG_NLS_KOI8_R=m
+CONFIG_NLS_KOI8_U=m
+CONFIG_NLS_UTF8=m
 # CONFIG_DLM is not set
 
-#
-# Profiling support
-#
-# CONFIG_PROFILING is not set
-
 #
 # Kernel hacking
 #
 # CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
 CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_UNUSED_SYMBOLS is not set
 # CONFIG_DEBUG_FS is not set
 # CONFIG_HEADERS_CHECK is not set
 CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SHIRQ is not set
-CONFIG_LOG_BUF_SHIFT=16
 CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
 # CONFIG_SCHEDSTATS is not set
 # CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
 CONFIG_DEBUG_MUTEXES=y
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
 # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 CONFIG_DEBUG_INFO=y
 # CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
 # CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
 CONFIG_FRAME_POINTER=y
-CONFIG_FORCED_INLINING=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
 # CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
 CONFIG_DEBUG_USER=y
-# CONFIG_DEBUG_ERRORS is not set
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
 CONFIG_DEBUG_LL=y
 # CONFIG_DEBUG_ICEDCC is not set
 CONFIG_DEBUG_S3C_PORT=y
@@ -1400,21 +1586,100 @@ CONFIG_DEBUG_S3C_UART=0
 #
 # CONFIG_KEYS is not set
 # CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=m
+CONFIG_CRYPTO_AEAD=m
+CONFIG_CRYPTO_BLKCIPHER=m
+CONFIG_CRYPTO_HASH=m
+CONFIG_CRYPTO_MANAGER=m
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_AUTHENC=m
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=m
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=m
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+CONFIG_CRYPTO_HMAC=m
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=m
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+CONFIG_CRYPTO_SHA1=m
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+CONFIG_CRYPTO_AES=m
+# CONFIG_CRYPTO_ANUBIS is not set
+CONFIG_CRYPTO_ARC4=m
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+CONFIG_CRYPTO_DES=m
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
 
 #
-# Cryptographic options
+# Compression
 #
-# CONFIG_CRYPTO is not set
+CONFIG_CRYPTO_DEFLATE=m
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
 
 #
 # Library routines
 #
 CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
 # CONFIG_CRC_CCITT is not set
 # CONFIG_CRC16 is not set
+CONFIG_CRC_ITU_T=m
 CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
 # CONFIG_LIBCRC32C is not set
 CONFIG_ZLIB_INFLATE=y
 CONFIG_ZLIB_DEFLATE=y
 CONFIG_PLIST=y
 CONFIG_HAS_IOMEM=y
+CONFIG_HAS_DMA=y
index 484dc97..8688362 100644 (file)
@@ -211,7 +211,6 @@ CONFIG_ARM_THUMB=y
 #
 # CONFIG_TICK_ONESHOT is not set
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index aa7a011..7d59fb1 100644 (file)
@@ -164,7 +164,6 @@ CONFIG_PCMCIA_PXA2XX=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 CONFIG_FLATMEM_MANUAL=y
index 576b833..07dfb98 100644 (file)
@@ -247,7 +247,6 @@ CONFIG_ARM_THUMB=y
 #
 # CONFIG_TICK_ONESHOT is not set
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=200
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
index 6db6392..8b7a431 100644 (file)
@@ -195,7 +195,6 @@ CONFIG_PCMCIA_PXA2XX=y
 # Kernel Features
 #
 CONFIG_PREEMPT=y
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 CONFIG_AEABI=y
 CONFIG_OABI_COMPAT=y
diff --git a/arch/arm/configs/usb-a9260_defconfig b/arch/arm/configs/usb-a9260_defconfig
new file mode 100644 (file)
index 0000000..3680bd2
--- /dev/null
@@ -0,0 +1,1142 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.24
+# Tue Apr 15 11:39:35 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_FAIR_USER_SCHED=y
+# CONFIG_FAIR_CGROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED is not set
+# CONFIG_RELAY is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+CONFIG_DEFAULT_AS=y
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="anticipatory"
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+CONFIG_ARCH_AT91=y
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Atmel AT91 System-on-Chip
+#
+# CONFIG_ARCH_AT91RM9200 is not set
+CONFIG_ARCH_AT91SAM9260=y
+# CONFIG_ARCH_AT91SAM9261 is not set
+# CONFIG_ARCH_AT91SAM9263 is not set
+# CONFIG_ARCH_AT91SAM9RL is not set
+# CONFIG_ARCH_AT91CAP9 is not set
+# CONFIG_ARCH_AT91X40 is not set
+CONFIG_AT91_PMC_UNIT=y
+
+#
+# AT91SAM9260 Variants
+#
+# CONFIG_ARCH_AT91SAM9260_SAM9XE is not set
+
+#
+# AT91SAM9260 / AT91SAM9XE Board Type
+#
+# CONFIG_MACH_AT91SAM9260EK is not set
+# CONFIG_MACH_CAM60 is not set
+# CONFIG_MACH_SAM9_L9260 is not set
+CONFIG_MACH_USB_A9260=y
+# CONFIG_MACH_QIL_A9260 is not set
+
+#
+# AT91 Board Options
+#
+
+#
+# AT91 Feature Selections
+#
+# CONFIG_AT91_PROGRAMMABLE_CLOCKS is not set
+CONFIG_AT91_SLOW_CLOCK=y
+CONFIG_AT91_TIMER_HZ=100
+CONFIG_AT91_EARLY_DBGU=y
+# CONFIG_AT91_EARLY_USART0 is not set
+# CONFIG_AT91_EARLY_USART1 is not set
+# CONFIG_AT91_EARLY_USART2 is not set
+# CONFIG_AT91_EARLY_USART3 is not set
+# CONFIG_AT91_EARLY_USART4 is not set
+# CONFIG_AT91_EARLY_USART5 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+# CONFIG_ARM_THUMB is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_TICK_ONESHOT is not set
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+# CONFIG_LEDS is not set
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="mem=64M console=ttyS0,115200"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_LEGACY is not set
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND_UP_POSSIBLE=y
+CONFIG_SUSPEND=y
+# CONFIG_APM_EMULATION is not set
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_ASK_IP_FIB_HASH=y
+# CONFIG_IP_FIB_TRIE is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_MULTIPLE_TABLES is not set
+# CONFIG_IP_ROUTE_MULTIPATH is not set
+CONFIG_IP_ROUTE_VERBOSE=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_BOOTP=y
+CONFIG_IP_PNP_RARP=y
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_FW_LOADER is not set
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+# CONFIG_MTD_CFI is not set
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+CONFIG_MTD_DATAFLASH=y
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+CONFIG_MTD_NAND_AT91=y
+CONFIG_MTD_NAND_AT91_ECC_SOFT=y
+# CONFIG_MTD_NAND_AT91_ECC_HW is not set
+# CONFIG_MTD_NAND_AT91_ECC_NONE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+CONFIG_PHYLIB=y
+
+#
+# MII PHY device drivers
+#
+# CONFIG_MARVELL_PHY is not set
+# CONFIG_DAVICOM_PHY is not set
+# CONFIG_QSEMI_PHY is not set
+# CONFIG_LXT_PHY is not set
+# CONFIG_CICADA_PHY is not set
+# CONFIG_VITESSE_PHY is not set
+# CONFIG_SMSC_PHY is not set
+# CONFIG_BROADCOM_PHY is not set
+# CONFIG_ICPLUS_PHY is not set
+# CONFIG_FIXED_PHY is not set
+# CONFIG_MDIO_BITBANG is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+CONFIG_MACB=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+CONFIG_NETDEV_1000=y
+CONFIG_NETDEV_10000=y
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_SHAPER is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+CONFIG_INPUT_EVBUG=y
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ATKBD is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+CONFIG_KEYBOARD_GPIO=y
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_ATMEL=y
+CONFIG_SERIAL_ATMEL_CONSOLE=y
+# CONFIG_SERIAL_ATMEL_TTYAT is not set
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=y
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+
+#
+# SPI support
+#
+CONFIG_SPI=y
+# CONFIG_SPI_DEBUG is not set
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_ATMEL=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+# CONFIG_USB_HID is not set
+
+#
+# USB HID Boot Protocol drivers
+#
+# CONFIG_USB_KBD is not set
+# CONFIG_USB_MOUSE is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_PERSIST is not set
+# CONFIG_USB_OTG is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+
+#
+# USB DSL modem support
+#
+
+#
+# USB Gadget Support
+#
+CONFIG_USB_GADGET=y
+# CONFIG_USB_GADGET_DEBUG is not set
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_SELECTED=y
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+# CONFIG_USB_GADGET_ATMEL_USBA is not set
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_PXA2XX is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+CONFIG_USB_GADGET_AT91=y
+CONFIG_USB_AT91=y
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+# CONFIG_USB_GADGET_DUALSPEED is not set
+# CONFIG_USB_ZERO is not set
+CONFIG_USB_ETH=y
+CONFIG_USB_ETH_RNDIS=y
+# CONFIG_USB_GADGETFS is not set
+# CONFIG_USB_FILE_STORAGE is not set
+# CONFIG_USB_G_SERIAL is not set
+# CONFIG_USB_MIDI_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+CONFIG_LEDS_GPIO=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+CONFIG_FS_POSIX_ACL=y
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=m
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+# CONFIG_MSDOS_FS is not set
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_ACL_SUPPORT=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+CONFIG_SUNRPC_GSS=y
+# CONFIG_SUNRPC_BIND34 is not set
+CONFIG_RPCSEC_GSS_KRB5=y
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+# CONFIG_INSTRUMENTATION is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+CONFIG_FORCED_INLINING=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+# CONFIG_DEBUG_ERRORS is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_MANAGER=y
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_WP512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_ECB is not set
+CONFIG_CRYPTO_CBC=y
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_XTS is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_TEST is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/usb-a9263_defconfig b/arch/arm/configs/usb-a9263_defconfig
new file mode 100644 (file)
index 0000000..48d455b
--- /dev/null
@@ -0,0 +1,1134 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.24
+# Tue Apr 15 11:15:19 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ZONE_DMA=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_FAIR_USER_SCHED=y
+# CONFIG_FAIR_CGROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED is not set
+# CONFIG_RELAY is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+CONFIG_DEFAULT_AS=y
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="anticipatory"
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+CONFIG_ARCH_AT91=y
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Atmel AT91 System-on-Chip
+#
+# CONFIG_ARCH_AT91RM9200 is not set
+# CONFIG_ARCH_AT91SAM9260 is not set
+# CONFIG_ARCH_AT91SAM9261 is not set
+CONFIG_ARCH_AT91SAM9263=y
+# CONFIG_ARCH_AT91SAM9RL is not set
+# CONFIG_ARCH_AT91CAP9 is not set
+# CONFIG_ARCH_AT91X40 is not set
+CONFIG_AT91_PMC_UNIT=y
+
+#
+# AT91SAM9263 Board Type
+#
+# CONFIG_MACH_AT91SAM9263EK is not set
+CONFIG_MACH_USB_A9263=y
+
+#
+# AT91 Board Options
+#
+
+#
+# AT91 Feature Selections
+#
+# CONFIG_AT91_PROGRAMMABLE_CLOCKS is not set
+CONFIG_AT91_SLOW_CLOCK=y
+CONFIG_AT91_TIMER_HZ=100
+CONFIG_AT91_EARLY_DBGU=y
+# CONFIG_AT91_EARLY_USART0 is not set
+# CONFIG_AT91_EARLY_USART1 is not set
+# CONFIG_AT91_EARLY_USART2 is not set
+# CONFIG_AT91_EARLY_USART3 is not set
+# CONFIG_AT91_EARLY_USART4 is not set
+# CONFIG_AT91_EARLY_USART5 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+# CONFIG_ARM_THUMB is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_CPU_CACHE_ROUND_ROBIN is not set
+# CONFIG_OUTER_CACHE is not set
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_TICK_ONESHOT is not set
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+# CONFIG_LEDS is not set
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="mem=64M console=ttyS0,115200"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_LEGACY is not set
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND_UP_POSSIBLE=y
+CONFIG_SUSPEND=y
+# CONFIG_APM_EMULATION is not set
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_ASK_IP_FIB_HASH=y
+# CONFIG_IP_FIB_TRIE is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_MULTIPLE_TABLES is not set
+# CONFIG_IP_ROUTE_MULTIPATH is not set
+CONFIG_IP_ROUTE_VERBOSE=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_BOOTP=y
+CONFIG_IP_PNP_RARP=y
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_FW_LOADER is not set
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+# CONFIG_MTD_CFI is not set
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+CONFIG_MTD_DATAFLASH=y
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+CONFIG_MTD_NAND_AT91=y
+CONFIG_MTD_NAND_AT91_ECC_SOFT=y
+# CONFIG_MTD_NAND_AT91_ECC_HW is not set
+# CONFIG_MTD_NAND_AT91_ECC_NONE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+# CONFIG_BLK_DEV_RAM is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+CONFIG_PHYLIB=y
+
+#
+# MII PHY device drivers
+#
+# CONFIG_MARVELL_PHY is not set
+# CONFIG_DAVICOM_PHY is not set
+# CONFIG_QSEMI_PHY is not set
+# CONFIG_LXT_PHY is not set
+# CONFIG_CICADA_PHY is not set
+# CONFIG_VITESSE_PHY is not set
+# CONFIG_SMSC_PHY is not set
+# CONFIG_BROADCOM_PHY is not set
+# CONFIG_ICPLUS_PHY is not set
+# CONFIG_FIXED_PHY is not set
+# CONFIG_MDIO_BITBANG is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+CONFIG_MACB=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+CONFIG_NETDEV_1000=y
+CONFIG_NETDEV_10000=y
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_SHAPER is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+CONFIG_INPUT_EVBUG=y
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ATKBD is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+CONFIG_KEYBOARD_GPIO=y
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_ATMEL=y
+CONFIG_SERIAL_ATMEL_CONSOLE=y
+# CONFIG_SERIAL_ATMEL_TTYAT is not set
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+CONFIG_HW_RANDOM=y
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+
+#
+# SPI support
+#
+CONFIG_SPI=y
+# CONFIG_SPI_DEBUG is not set
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_ATMEL=y
+# CONFIG_SPI_BITBANG is not set
+
+#
+# SPI Protocol Masters
+#
+# CONFIG_SPI_AT25 is not set
+# CONFIG_SPI_SPIDEV is not set
+# CONFIG_SPI_TLE62X0 is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+# CONFIG_HID_DEBUG is not set
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+# CONFIG_USB_HID is not set
+
+#
+# USB HID Boot Protocol drivers
+#
+# CONFIG_USB_KBD is not set
+# CONFIG_USB_MOUSE is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+CONFIG_USB_DEVICE_CLASS=y
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_PERSIST is not set
+# CONFIG_USB_OTG is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+
+#
+# USB Serial Converter support
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+
+#
+# USB DSL modem support
+#
+
+#
+# USB Gadget Support
+#
+CONFIG_USB_GADGET=y
+# CONFIG_USB_GADGET_DEBUG is not set
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_SELECTED=y
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+# CONFIG_USB_GADGET_ATMEL_USBA is not set
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_PXA2XX is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+CONFIG_USB_GADGET_AT91=y
+CONFIG_USB_AT91=y
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+# CONFIG_USB_GADGET_DUALSPEED is not set
+# CONFIG_USB_ZERO is not set
+CONFIG_USB_ETH=y
+CONFIG_USB_ETH_RNDIS=y
+# CONFIG_USB_GADGETFS is not set
+# CONFIG_USB_FILE_STORAGE is not set
+# CONFIG_USB_G_SERIAL is not set
+# CONFIG_USB_MIDI_GADGET is not set
+# CONFIG_MMC is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+CONFIG_LEDS_GPIO=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4DEV_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+CONFIG_FS_POSIX_ACL=y
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_ROMFS_FS is not set
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=m
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+# CONFIG_MSDOS_FS is not set
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_ACL_SUPPORT=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+CONFIG_SUNRPC_GSS=y
+# CONFIG_SUNRPC_BIND34 is not set
+CONFIG_RPCSEC_GSS_KRB5=y
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+# CONFIG_INSTRUMENTATION is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+CONFIG_FORCED_INLINING=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+# CONFIG_DEBUG_ERRORS is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_MANAGER=y
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_WP512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_ECB is not set
+CONFIG_CRYPTO_CBC=y
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_XTS is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_TEST is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index 48dca69..8355f88 100644 (file)
@@ -151,7 +151,6 @@ CONFIG_ARM_AMBA=y
 # Kernel Features
 #
 # CONFIG_PREEMPT is not set
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_HZ=100
 # CONFIG_AEABI is not set
 # CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
diff --git a/arch/arm/configs/xm_x270_defconfig b/arch/arm/configs/xm_x270_defconfig
new file mode 100644 (file)
index 0000000..aa40d91
--- /dev/null
@@ -0,0 +1,1741 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.25
+# Sun May 11 15:12:52 2008
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+# CONFIG_NO_IOPORT is not set
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ZONE_DMA=y
+CONFIG_ARCH_MTD_XIP=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+# CONFIG_COMPAT_BRK is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+# CONFIG_SLUB_DEBUG is not set
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+# CONFIG_MARKERS is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_KMOD=y
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LSF is not set
+# CONFIG_BLK_DEV_BSG is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
+
+#
+# System Type
+#
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS7500 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_CO285 is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IMX is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_PNX4008 is not set
+CONFIG_ARCH_PXA=y
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_MSM7X00A is not set
+CONFIG_DMABOUNCE=y
+
+#
+# Intel PXA2xx/PXA3xx Implementations
+#
+
+#
+# Select target boards
+#
+# CONFIG_ARCH_GUMSTIX is not set
+# CONFIG_ARCH_LUBBOCK is not set
+# CONFIG_MACH_LOGICPD_PXA270 is not set
+# CONFIG_MACH_MAINSTONE is not set
+# CONFIG_ARCH_PXA_IDP is not set
+# CONFIG_PXA_SHARPSL is not set
+# CONFIG_ARCH_PXA_ESERIES is not set
+# CONFIG_MACH_TRIZEPS4 is not set
+CONFIG_MACH_EM_X270=y
+# CONFIG_MACH_COLIBRI is not set
+# CONFIG_MACH_ZYLONITE is not set
+# CONFIG_MACH_LITTLETON is not set
+CONFIG_MACH_ARMCORE=y
+# CONFIG_MACH_MAGICIAN is not set
+# CONFIG_MACH_PCM027 is not set
+CONFIG_PXA27x=y
+# CONFIG_PXA_PWM is not set
+
+#
+# Boot options
+#
+
+#
+# Power management
+#
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_XSCALE=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5T=y
+CONFIG_CPU_PABRT_NOIFAR=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_OUTER_CACHE is not set
+CONFIG_IWMMXT=y
+CONFIG_XSCALE_PMU=y
+
+#
+# Bus support
+#
+CONFIG_PCI=y
+CONFIG_PCI_SYSCALL=y
+CONFIG_PCI_HOST_ITE8152=y
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+CONFIG_PCI_LEGACY=y
+# CONFIG_PCI_DEBUG is not set
+CONFIG_PCCARD=m
+# CONFIG_PCMCIA_DEBUG is not set
+CONFIG_PCMCIA=m
+CONFIG_PCMCIA_LOAD_CIS=y
+CONFIG_PCMCIA_IOCTL=y
+CONFIG_CARDBUS=y
+
+#
+# PC-card bridges
+#
+CONFIG_YENTA=m
+# CONFIG_YENTA_O2 is not set
+# CONFIG_YENTA_RICOH is not set
+CONFIG_YENTA_TI=y
+# CONFIG_YENTA_ENE_TUNE is not set
+# CONFIG_YENTA_TOSHIBA is not set
+# CONFIG_PD6729 is not set
+# CONFIG_I82092 is not set
+CONFIG_PCMCIA_PXA2XX=m
+CONFIG_PCCARD_NONSTATIC=m
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_DISCONTIGMEM_ENABLE is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=1
+CONFIG_BOUNCE=y
+CONFIG_VIRT_TO_BUS=y
+CONFIG_ALIGNMENT_TRAP=y
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="root=1f03 mem=32M"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Frequency scaling
+#
+# CONFIG_CPU_FREQ is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+CONFIG_FPE_NWFPE=y
+# CONFIG_FPE_NWFPE_XP is not set
+# CONFIG_FPE_FASTFPE is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND=y
+CONFIG_SUSPEND_FREEZER=y
+CONFIG_APM_EMULATION=m
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+CONFIG_IP_PNP_DHCP=y
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+CONFIG_INET_XFRM_MODE_TRANSPORT=y
+CONFIG_INET_XFRM_MODE_TUNNEL=y
+CONFIG_INET_XFRM_MODE_BEET=y
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+CONFIG_BT=m
+CONFIG_BT_L2CAP=m
+CONFIG_BT_SCO=m
+CONFIG_BT_RFCOMM=m
+# CONFIG_BT_RFCOMM_TTY is not set
+CONFIG_BT_BNEP=m
+# CONFIG_BT_BNEP_MC_FILTER is not set
+# CONFIG_BT_BNEP_PROTO_FILTER is not set
+CONFIG_BT_HIDP=m
+
+#
+# Bluetooth device drivers
+#
+CONFIG_BT_HCIUSB=m
+CONFIG_BT_HCIUSB_SCO=y
+# CONFIG_BT_HCIBTSDIO is not set
+# CONFIG_BT_HCIUART is not set
+# CONFIG_BT_HCIBCM203X is not set
+# CONFIG_BT_HCIBPA10X is not set
+# CONFIG_BT_HCIBFUSB is not set
+# CONFIG_BT_HCIDTL1 is not set
+# CONFIG_BT_HCIBT3C is not set
+# CONFIG_BT_HCIBLUECARD is not set
+# CONFIG_BT_HCIBTUART is not set
+# CONFIG_BT_HCIVHCI is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_EXT=y
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=m
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_GEOMETRY is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_CFI_AMDSTD=y
+CONFIG_MTD_CFI_STAA=y
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+# CONFIG_MTD_XIP is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x0
+CONFIG_MTD_PHYSMAP_LEN=0x400000
+CONFIG_MTD_PHYSMAP_BANKWIDTH=2
+CONFIG_MTD_PXA2XX=y
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_IMPA7 is not set
+# CONFIG_MTD_SHARP_SL is not set
+# CONFIG_MTD_INTEL_VR_NOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_PMC551 is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+CONFIG_MTD_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+# CONFIG_MTD_NAND_H1900 is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_SHARPSL is not set
+# CONFIG_MTD_NAND_CAFE is not set
+CONFIG_MTD_NAND_CM_X270=y
+# CONFIG_MTD_NAND_NANDSIM is not set
+CONFIG_MTD_NAND_PLATFORM=y
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_CPQ_DA is not set
+# CONFIG_BLK_CPQ_CISS_DA is not set
+# CONFIG_BLK_DEV_DAC960 is not set
+# CONFIG_BLK_DEV_UMEM is not set
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_SX8 is not set
+# CONFIG_BLK_DEV_UB is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=4096
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+
+#
+# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
+#
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_ISCSI_TCP is not set
+# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
+# CONFIG_SCSI_3W_9XXX is not set
+# CONFIG_SCSI_ACARD is not set
+# CONFIG_SCSI_AACRAID is not set
+# CONFIG_SCSI_AIC7XXX is not set
+# CONFIG_SCSI_AIC7XXX_OLD is not set
+# CONFIG_SCSI_AIC79XX is not set
+# CONFIG_SCSI_AIC94XX is not set
+# CONFIG_SCSI_DPT_I2O is not set
+# CONFIG_SCSI_ADVANSYS is not set
+# CONFIG_SCSI_ARCMSR is not set
+# CONFIG_MEGARAID_NEWGEN is not set
+# CONFIG_MEGARAID_LEGACY is not set
+# CONFIG_MEGARAID_SAS is not set
+# CONFIG_SCSI_HPTIOP is not set
+# CONFIG_SCSI_DMX3191D is not set
+# CONFIG_SCSI_FUTURE_DOMAIN is not set
+# CONFIG_SCSI_IPS is not set
+# CONFIG_SCSI_INITIO is not set
+# CONFIG_SCSI_INIA100 is not set
+# CONFIG_SCSI_MVSAS is not set
+# CONFIG_SCSI_STEX is not set
+# CONFIG_SCSI_SYM53C8XX_2 is not set
+# CONFIG_SCSI_IPR is not set
+# CONFIG_SCSI_QLOGIC_1280 is not set
+# CONFIG_SCSI_QLA_FC is not set
+# CONFIG_SCSI_QLA_ISCSI is not set
+# CONFIG_SCSI_LPFC is not set
+# CONFIG_SCSI_DC395x is not set
+# CONFIG_SCSI_DC390T is not set
+# CONFIG_SCSI_NSP32 is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_SCSI_SRP is not set
+# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
+CONFIG_ATA=m
+# CONFIG_ATA_NONSTANDARD is not set
+# CONFIG_SATA_PMP is not set
+# CONFIG_SATA_AHCI is not set
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
+# CONFIG_SATA_SVW is not set
+# CONFIG_ATA_PIIX is not set
+# CONFIG_SATA_MV is not set
+# CONFIG_SATA_NV is not set
+# CONFIG_PDC_ADMA is not set
+# CONFIG_SATA_QSTOR is not set
+# CONFIG_SATA_PROMISE is not set
+# CONFIG_SATA_SX4 is not set
+# CONFIG_SATA_SIL is not set
+# CONFIG_SATA_SIS is not set
+# CONFIG_SATA_ULI is not set
+# CONFIG_SATA_VIA is not set
+# CONFIG_SATA_VITESSE is not set
+# CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ALI is not set
+# CONFIG_PATA_AMD is not set
+# CONFIG_PATA_ARTOP is not set
+# CONFIG_PATA_ATIIXP is not set
+# CONFIG_PATA_CMD640_PCI is not set
+# CONFIG_PATA_CMD64X is not set
+# CONFIG_PATA_CS5520 is not set
+# CONFIG_PATA_CS5530 is not set
+# CONFIG_PATA_CYPRESS is not set
+# CONFIG_PATA_EFAR is not set
+# CONFIG_ATA_GENERIC is not set
+# CONFIG_PATA_HPT366 is not set
+# CONFIG_PATA_HPT37X is not set
+# CONFIG_PATA_HPT3X2N is not set
+# CONFIG_PATA_HPT3X3 is not set
+# CONFIG_PATA_IT821X is not set
+# CONFIG_PATA_IT8213 is not set
+# CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_TRIFLEX is not set
+# CONFIG_PATA_MARVELL is not set
+# CONFIG_PATA_MPIIX is not set
+# CONFIG_PATA_OLDPIIX is not set
+# CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NINJA32 is not set
+# CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
+# CONFIG_PATA_OPTI is not set
+# CONFIG_PATA_OPTIDMA is not set
+CONFIG_PATA_PCMCIA=m
+# CONFIG_PATA_PDC_OLD is not set
+# CONFIG_PATA_RADISYS is not set
+# CONFIG_PATA_RZ1000 is not set
+# CONFIG_PATA_SC1200 is not set
+# CONFIG_PATA_SERVERWORKS is not set
+# CONFIG_PATA_PDC2027X is not set
+# CONFIG_PATA_SIL680 is not set
+# CONFIG_PATA_SIS is not set
+# CONFIG_PATA_VIA is not set
+# CONFIG_PATA_WINBOND is not set
+# CONFIG_PATA_PLATFORM is not set
+# CONFIG_MD is not set
+# CONFIG_FUSION is not set
+
+#
+# IEEE 1394 (FireWire) support
+#
+# CONFIG_FIREWIRE is not set
+# CONFIG_IEEE1394 is not set
+# CONFIG_I2O is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_ARCNET is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+# CONFIG_AX88796 is not set
+# CONFIG_HAPPYMEAL is not set
+# CONFIG_SUNGEM is not set
+# CONFIG_CASSINI is not set
+# CONFIG_NET_VENDOR_3COM is not set
+# CONFIG_SMC91X is not set
+CONFIG_DM9000=y
+CONFIG_DM9000_DEBUGLEVEL=1
+# CONFIG_SMC911X is not set
+# CONFIG_NET_TULIP is not set
+# CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+CONFIG_NET_PCI=y
+# CONFIG_PCNET32 is not set
+# CONFIG_AMD8111_ETH is not set
+# CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_B44 is not set
+# CONFIG_FORCEDETH is not set
+# CONFIG_EEPRO100 is not set
+# CONFIG_E100 is not set
+# CONFIG_FEALNX is not set
+# CONFIG_NATSEMI is not set
+# CONFIG_NE2K_PCI is not set
+# CONFIG_8139CP is not set
+CONFIG_8139TOO=y
+# CONFIG_8139TOO_PIO is not set
+# CONFIG_8139TOO_TUNE_TWISTER is not set
+# CONFIG_8139TOO_8129 is not set
+# CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_R6040 is not set
+# CONFIG_SIS900 is not set
+# CONFIG_EPIC100 is not set
+# CONFIG_SUNDANCE is not set
+# CONFIG_TLAN is not set
+# CONFIG_VIA_RHINE is not set
+# CONFIG_SC92031 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+# CONFIG_TR is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+CONFIG_WLAN_80211=y
+# CONFIG_PCMCIA_RAYCS is not set
+# CONFIG_IPW2100 is not set
+# CONFIG_IPW2200 is not set
+CONFIG_LIBERTAS=m
+# CONFIG_LIBERTAS_USB is not set
+# CONFIG_LIBERTAS_CS is not set
+CONFIG_LIBERTAS_SDIO=m
+# CONFIG_LIBERTAS_DEBUG is not set
+# CONFIG_HERMES is not set
+# CONFIG_ATMEL is not set
+# CONFIG_AIRO_CS is not set
+# CONFIG_PCMCIA_WL3501 is not set
+# CONFIG_PRISM54 is not set
+# CONFIG_USB_ZD1201 is not set
+# CONFIG_USB_NET_RNDIS_WLAN is not set
+# CONFIG_IWLWIFI is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_HOSTAP is not set
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_NET_PCMCIA is not set
+# CONFIG_WAN is not set
+# CONFIG_FDDI is not set
+# CONFIG_HIPPI is not set
+CONFIG_PPP=m
+CONFIG_PPP_MULTILINK=y
+CONFIG_PPP_FILTER=y
+CONFIG_PPP_ASYNC=m
+# CONFIG_PPP_SYNC_TTY is not set
+CONFIG_PPP_DEFLATE=m
+CONFIG_PPP_BSDCOMP=m
+# CONFIG_PPP_MPPE is not set
+# CONFIG_PPPOE is not set
+# CONFIG_PPPOL2TP is not set
+# CONFIG_SLIP is not set
+CONFIG_SLHC=m
+# CONFIG_NET_FC is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+CONFIG_INPUT_MOUSEDEV_PSAUX=y
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+# CONFIG_INPUT_APMPOWER is not set
+
+#
+# Input Device Drivers
+#
+CONFIG_INPUT_KEYBOARD=y
+CONFIG_KEYBOARD_ATKBD=y
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+CONFIG_KEYBOARD_PXA27x=m
+# CONFIG_KEYBOARD_GPIO is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+CONFIG_TOUCHSCREEN_UCB1400=m
+CONFIG_TOUCHSCREEN_WM97XX=m
+# CONFIG_TOUCHSCREEN_WM9705 is not set
+CONFIG_TOUCHSCREEN_WM9712=y
+# CONFIG_TOUCHSCREEN_WM9713 is not set
+# CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE is not set
+# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+# CONFIG_SERIO_SERPORT is not set
+# CONFIG_SERIO_PCIPS2 is not set
+CONFIG_SERIO_LIBPS2=y
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+# CONFIG_NOZOMI is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_PXA=y
+CONFIG_SERIAL_PXA_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_JSM is not set
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_NVRAM is not set
+# CONFIG_R3964 is not set
+# CONFIG_APPLICOM is not set
+
+#
+# PCMCIA character devices
+#
+# CONFIG_SYNCLINK_CS is not set
+# CONFIG_CARDMAN_4000 is not set
+# CONFIG_CARDMAN_4040 is not set
+# CONFIG_IPWIRELESS is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_DEVPORT=y
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_CHARDEV=m
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+# CONFIG_I2C_GPIO is not set
+# CONFIG_I2C_I801 is not set
+# CONFIG_I2C_I810 is not set
+CONFIG_I2C_PXA=y
+# CONFIG_I2C_PXA_SLAVE is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+# CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_TPS65010 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+# CONFIG_SPI is not set
+CONFIG_HAVE_GPIO_LIB=y
+
+#
+# GPIO Support
+#
+# CONFIG_DEBUG_GPIO is not set
+
+#
+# I2C GPIO expanders:
+#
+# CONFIG_GPIO_PCA953X is not set
+# CONFIG_GPIO_PCF857X is not set
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_DRM is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+CONFIG_FB_CFB_FILLRECT=y
+CONFIG_FB_CFB_COPYAREA=y
+CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+CONFIG_FB_DEFERRED_IO=y
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+# CONFIG_FB_MODE_HELPERS is not set
+# CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_CIRRUS is not set
+# CONFIG_FB_PM2 is not set
+# CONFIG_FB_CYBER2000 is not set
+# CONFIG_FB_ASILIANT is not set
+# CONFIG_FB_IMSTT is not set
+# CONFIG_FB_S1D13XXX is not set
+# CONFIG_FB_NVIDIA is not set
+# CONFIG_FB_RIVA is not set
+# CONFIG_FB_MATROX is not set
+# CONFIG_FB_RADEON is not set
+# CONFIG_FB_ATY128 is not set
+# CONFIG_FB_ATY is not set
+# CONFIG_FB_S3 is not set
+# CONFIG_FB_SAVAGE is not set
+# CONFIG_FB_SIS is not set
+# CONFIG_FB_NEOMAGIC is not set
+# CONFIG_FB_KYRO is not set
+# CONFIG_FB_3DFX is not set
+# CONFIG_FB_VOODOO1 is not set
+# CONFIG_FB_VT8623 is not set
+# CONFIG_FB_TRIDENT is not set
+# CONFIG_FB_ARK is not set
+# CONFIG_FB_PM3 is not set
+CONFIG_FB_PXA=y
+# CONFIG_FB_PXA_SMARTPANEL is not set
+CONFIG_FB_PXA_PARAMETERS=y
+CONFIG_FB_MBX=m
+# CONFIG_FB_AM200EPD is not set
+# CONFIG_FB_VIRTUAL is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+CONFIG_FRAMEBUFFER_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
+# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
+# CONFIG_FONTS is not set
+CONFIG_FONT_8x8=y
+CONFIG_FONT_8x16=y
+CONFIG_LOGO=y
+CONFIG_LOGO_LINUX_MONO=y
+CONFIG_LOGO_LINUX_VGA16=y
+CONFIG_LOGO_LINUX_CLUT224=y
+
+#
+# Sound
+#
+CONFIG_SOUND=m
+
+#
+# Advanced Linux Sound Architecture
+#
+CONFIG_SND=m
+CONFIG_SND_TIMER=m
+CONFIG_SND_PCM=m
+# CONFIG_SND_SEQUENCER is not set
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=m
+CONFIG_SND_PCM_OSS=m
+CONFIG_SND_PCM_OSS_PLUGINS=y
+# CONFIG_SND_DYNAMIC_MINORS is not set
+CONFIG_SND_SUPPORT_OLD_API=y
+CONFIG_SND_VERBOSE_PROCFS=y
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+
+#
+# Generic devices
+#
+CONFIG_SND_AC97_CODEC=m
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# PCI devices
+#
+# CONFIG_SND_AD1889 is not set
+# CONFIG_SND_ALS300 is not set
+# CONFIG_SND_ALI5451 is not set
+# CONFIG_SND_ATIIXP is not set
+# CONFIG_SND_ATIIXP_MODEM is not set
+# CONFIG_SND_AU8810 is not set
+# CONFIG_SND_AU8820 is not set
+# CONFIG_SND_AU8830 is not set
+# CONFIG_SND_AW2 is not set
+# CONFIG_SND_AZT3328 is not set
+# CONFIG_SND_BT87X is not set
+# CONFIG_SND_CA0106 is not set
+# CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_OXYGEN is not set
+# CONFIG_SND_CS4281 is not set
+# CONFIG_SND_CS46XX is not set
+# CONFIG_SND_DARLA20 is not set
+# CONFIG_SND_GINA20 is not set
+# CONFIG_SND_LAYLA20 is not set
+# CONFIG_SND_DARLA24 is not set
+# CONFIG_SND_GINA24 is not set
+# CONFIG_SND_LAYLA24 is not set
+# CONFIG_SND_MONA is not set
+# CONFIG_SND_MIA is not set
+# CONFIG_SND_ECHO3G is not set
+# CONFIG_SND_INDIGO is not set
+# CONFIG_SND_INDIGOIO is not set
+# CONFIG_SND_INDIGODJ is not set
+# CONFIG_SND_EMU10K1 is not set
+# CONFIG_SND_EMU10K1X is not set
+# CONFIG_SND_ENS1370 is not set
+# CONFIG_SND_ENS1371 is not set
+# CONFIG_SND_ES1938 is not set
+# CONFIG_SND_ES1968 is not set
+# CONFIG_SND_FM801 is not set
+# CONFIG_SND_HDA_INTEL is not set
+# CONFIG_SND_HDSP is not set
+# CONFIG_SND_HDSPM is not set
+# CONFIG_SND_HIFIER is not set
+# CONFIG_SND_ICE1712 is not set
+# CONFIG_SND_ICE1724 is not set
+# CONFIG_SND_INTEL8X0 is not set
+# CONFIG_SND_INTEL8X0M is not set
+# CONFIG_SND_KORG1212 is not set
+# CONFIG_SND_MAESTRO3 is not set
+# CONFIG_SND_MIXART is not set
+# CONFIG_SND_NM256 is not set
+# CONFIG_SND_PCXHR is not set
+# CONFIG_SND_RIPTIDE is not set
+# CONFIG_SND_RME32 is not set
+# CONFIG_SND_RME96 is not set
+# CONFIG_SND_RME9652 is not set
+# CONFIG_SND_SONICVIBES is not set
+# CONFIG_SND_TRIDENT is not set
+# CONFIG_SND_VIA82XX is not set
+# CONFIG_SND_VIA82XX_MODEM is not set
+# CONFIG_SND_VIRTUOSO is not set
+# CONFIG_SND_VX222 is not set
+# CONFIG_SND_YMFPCI is not set
+# CONFIG_SND_AC97_POWER_SAVE is not set
+
+#
+# ALSA ARM devices
+#
+CONFIG_SND_PXA2XX_PCM=m
+CONFIG_SND_PXA2XX_AC97=m
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_CAIAQ is not set
+
+#
+# PCMCIA devices
+#
+# CONFIG_SND_VXPOCKET is not set
+# CONFIG_SND_PDAUDIOCF is not set
+
+#
+# System on Chip audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
+# ALSA SoC audio for Freescale SOCs
+#
+
+#
+# SoC Audio for the Texas Instruments OMAP
+#
+
+#
+# Open Sound System
+#
+# CONFIG_SOUND_PRIME is not set
+CONFIG_AC97_BUS=m
+CONFIG_HID_SUPPORT=y
+CONFIG_HID=y
+CONFIG_HID_DEBUG=y
+# CONFIG_HIDRAW is not set
+
+#
+# USB Input Devices
+#
+CONFIG_USB_HID=y
+# CONFIG_USB_HIDINPUT_POWERBOOK is not set
+# CONFIG_HID_FF is not set
+# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+CONFIG_USB_ARCH_HAS_EHCI=y
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_DEVICE_CLASS is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_SUSPEND is not set
+# CONFIG_USB_OTG is not set
+# CONFIG_USB_OTG_WHITELIST is not set
+# CONFIG_USB_OTG_BLACKLIST_HUB is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_EHCI_HCD is not set
+# CONFIG_USB_ISP116X_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_UHCI_HCD is not set
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+
+#
+# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
+#
+
+#
+# may also be needed; see USB_STORAGE Help for more information
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_DPCM is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+CONFIG_USB_MON=y
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_AUERSWALD is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_BERRY_CHARGE is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_PHIDGET is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+# CONFIG_USB_GADGET is not set
+CONFIG_MMC=m
+# CONFIG_MMC_DEBUG is not set
+# CONFIG_MMC_UNSAFE_RESUME is not set
+
+#
+# MMC/SD Card Drivers
+#
+CONFIG_MMC_BLOCK=m
+CONFIG_MMC_BLOCK_BOUNCE=y
+# CONFIG_SDIO_UART is not set
+
+#
+# MMC/SD Host Controller Drivers
+#
+CONFIG_MMC_PXA=m
+# CONFIG_MMC_SDHCI is not set
+# CONFIG_MMC_TIFM_SD is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+# CONFIG_LEDS_GPIO is not set
+CONFIG_LEDS_CM_X270=y
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
+
+#
+# SPI RTC drivers
+#
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+CONFIG_RTC_DRV_V3020=y
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_SA1100=y
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+# CONFIG_EXT3_FS_SECURITY is not set
+# CONFIG_EXT4DEV_FS is not set
+CONFIG_JBD=y
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=m
+# CONFIG_MSDOS_FS is not set
+CONFIG_VFAT_FS=m
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+CONFIG_JFFS2_SUMMARY=y
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+CONFIG_CIFS=m
+# CONFIG_CIFS_STATS is not set
+# CONFIG_CIFS_WEAK_PW_HASH is not set
+# CONFIG_CIFS_XATTR is not set
+# CONFIG_CIFS_DEBUG2 is not set
+# CONFIG_CIFS_EXPERIMENTAL is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=m
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=m
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=m
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+CONFIG_NLS_UTF8=m
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=0
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+# CONFIG_DETECT_SOFTLOCKUP is not set
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+# CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+# CONFIG_DEBUG_INFO is not set
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_SAMPLES is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_LL=y
+# CONFIG_DEBUG_ICEDCC is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_GENERIC_FIND_FIRST_BIT is not set
+# CONFIG_GENERIC_FIND_NEXT_BIT is not set
+CONFIG_CRC_CCITT=m
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
index ad455ff..eb9092c 100644 (file)
@@ -4,6 +4,10 @@
 
 AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
 
+ifdef CONFIG_DYNAMIC_FTRACE
+CFLAGS_REMOVE_ftrace.o = -pg
+endif
+
 # Object file lists.
 
 obj-y          := compat.o entry-armv.o entry-common.o irq.o \
@@ -18,6 +22,7 @@ obj-$(CONFIG_ARTHUR)          += arthur.o
 obj-$(CONFIG_ISA_DMA)          += dma-isa.o
 obj-$(CONFIG_PCI)              += bios32.o isa.o
 obj-$(CONFIG_SMP)              += smp.o
+obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
 obj-$(CONFIG_KEXEC)            += machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_KPROBES)          += kprobes.o kprobes-decode.o
 obj-$(CONFIG_ATAGS_PROC)       += atags.o
index 688b7b1..cc7b246 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <asm/ftrace.h>
 
 /*
  * libgcc functions - functions that are used internally by the
@@ -181,3 +182,7 @@ EXPORT_SYMBOL(_find_next_bit_be);
 #endif
 
 EXPORT_SYMBOL(copy_page);
+
+#ifdef CONFIG_FTRACE
+EXPORT_SYMBOL(mcount);
+#endif
index 64c4208..42a1a14 100644 (file)
@@ -1,5 +1,4 @@
 #include <linux/slab.h>
-#include <linux/kexec.h>
 #include <linux/proc_fs.h>
 #include <asm/setup.h>
 #include <asm/types.h>
@@ -7,9 +6,8 @@
 
 struct buffer {
        size_t size;
-       char *data;
+       char data[];
 };
-static struct buffer tags_buffer;
 
 static int
 read_buffer(char* page, char** start, off_t off, int count,
@@ -29,58 +27,57 @@ read_buffer(char* page, char** start, off_t off, int count,
        return count;
 }
 
-
-static int
-create_proc_entries(void)
-{
-       struct proc_dir_entry* tags_entry;
-
-       tags_entry = create_proc_read_entry("atags", 0400, NULL, read_buffer, &tags_buffer);
-       if (!tags_entry)
-               return -ENOMEM;
-
-       return 0;
-}
-
-
-static char __initdata atags_copy_buf[KEXEC_BOOT_PARAMS_SIZE];
-static char __initdata *atags_copy;
+#define BOOT_PARAMS_SIZE 1536
+static char __initdata atags_copy[BOOT_PARAMS_SIZE];
 
 void __init save_atags(const struct tag *tags)
 {
-       atags_copy = atags_copy_buf;
-       memcpy(atags_copy, tags, KEXEC_BOOT_PARAMS_SIZE);
+       memcpy(atags_copy, tags, sizeof(atags_copy));
 }
 
-
 static int __init init_atags_procfs(void)
 {
-       struct tag *tag;
-       int error;
+       /*
+        * This cannot go into save_atags() because kmalloc and proc don't work
+        * yet when it is called.
+        */
+       struct proc_dir_entry *tags_entry;
+       struct tag *tag = (struct tag *)atags_copy;
+       struct buffer *b;
+       size_t size;
 
-       if (!atags_copy) {
-               printk(KERN_WARNING "Exporting ATAGs: No saved tags found\n");
-               return -EIO;
+       if (tag->hdr.tag != ATAG_CORE) {
+               printk(KERN_INFO "No ATAGs?");
+               return -EINVAL;
        }
 
-       for (tag = (struct tag *) atags_copy; tag->hdr.size; tag = tag_next(tag))
+       for (; tag->hdr.size; tag = tag_next(tag))
                ;
 
-       tags_buffer.size = ((char *) tag - atags_copy) + sizeof(tag->hdr);
-       tags_buffer.data = kmalloc(tags_buffer.size, GFP_KERNEL);
-       if (tags_buffer.data == NULL)
-               return -ENOMEM;
-       memcpy(tags_buffer.data, atags_copy, tags_buffer.size);
-
-       error = create_proc_entries();
-       if (error) {
-               printk(KERN_ERR "Exporting ATAGs: not enough memory\n");
-               kfree(tags_buffer.data);
-               tags_buffer.size = 0;
-               tags_buffer.data = NULL;
-       }
+       /* include the terminating ATAG_NONE */
+       size = (char *)tag - atags_copy + sizeof(struct tag_header);
 
-       return error;
-}
+       WARN_ON(tag->hdr.tag != ATAG_NONE);
+
+       b = kmalloc(sizeof(*b) + size, GFP_KERNEL);
+       if (!b)
+               goto nomem;
 
+       b->size = size;
+       memcpy(b->data, atags_copy, size);
+
+       tags_entry = create_proc_read_entry("atags", 0400,
+                       NULL, read_buffer, b);
+
+       if (!tags_entry)
+               goto nomem;
+
+       return 0;
+
+nomem:
+       kfree(b);
+       printk(KERN_ERR "Exporting ATAGs: not enough memory\n");
+
+       return -ENOMEM;
+}
 arch_initcall(init_atags_procfs);
index a53c0ab..8bfd299 100644 (file)
@@ -680,7 +680,7 @@ static int __init ecard_probeirqhw(void)
 #define IO_EC_MEMC8_BASE 0
 #endif
 
-unsigned int __ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
+static unsigned int __ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
 {
        unsigned long address = 0;
        int slot = ec->slot_no;
@@ -1002,7 +1002,7 @@ ecard_probe(int slot, card_type_t type)
        }
 
        rc = -ENODEV;
-       if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
+       if ((ec->podaddr = __ecard_address(ec, type, ECARD_SYNC)) == 0)
                goto nodev;
 
        cid.r_zero = 1;
@@ -1141,10 +1141,10 @@ static int ecard_drv_probe(struct device *dev)
 
        id = ecard_match_device(drv->id_table, ec);
 
-       ecard_claim(ec);
+       ec->claimed = 1;
        ret = drv->probe(ec, id);
        if (ret)
-               ecard_release(ec);
+               ec->claimed = 0;
        return ret;
 }
 
@@ -1154,7 +1154,7 @@ static int ecard_drv_remove(struct device *dev)
        struct ecard_driver *drv = ECARD_DRV(dev->driver);
 
        drv->remove(ec);
-       ecard_release(ec);
+       ec->claimed = 0;
 
        /*
         * Restore the default operations.  We ensure that the
@@ -1182,7 +1182,7 @@ static void ecard_drv_shutdown(struct device *dev)
        if (dev->driver) {
                if (drv->shutdown)
                        drv->shutdown(ec);
-               ecard_release(ec);
+               ec->claimed = 0;
        }
 
        /*
@@ -1239,7 +1239,6 @@ static int ecard_bus_init(void)
 postcore_initcall(ecard_bus_init);
 
 EXPORT_SYMBOL(ecard_readchunk);
-EXPORT_SYMBOL(__ecard_address);
 EXPORT_SYMBOL(ecard_register_driver);
 EXPORT_SYMBOL(ecard_remove_driver);
 EXPORT_SYMBOL(ecard_bus_type);
index d7c2dac..4642d43 100644 (file)
@@ -54,3 +54,16 @@ struct ex_chunk_dir {
 #define c_len(x)       ((x)->r_len[0]|((x)->r_len[1]<<8)|((x)->r_len[2]<<16))
 #define c_start(x)     ((x)->r_start)
 };
+
+typedef enum ecard_type {              /* Cards address space          */
+       ECARD_IOC,
+       ECARD_MEMC,
+       ECARD_EASI
+} card_type_t;
+
+typedef enum {                         /* Speed for ECARD_IOC space    */
+       ECARD_SLOW       = 0,
+       ECARD_MEDIUM     = 1,
+       ECARD_FAST       = 2,
+       ECARD_SYNC       = 3
+} card_speed_t;
index 597ed00..84694e8 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <asm/unistd.h>
+#include <asm/ftrace.h>
 #include <asm/arch/entry-macro.S>
 
 #include "entry-header.S"
@@ -99,6 +100,56 @@ ENTRY(ret_from_fork)
 #undef CALL
 #define CALL(x) .long x
 
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+ENTRY(mcount)
+       stmdb sp!, {r0-r3, lr}
+       mov r0, lr
+       sub r0, r0, #MCOUNT_INSN_SIZE
+
+       .globl mcount_call
+mcount_call:
+       bl ftrace_stub
+       ldmia sp!, {r0-r3, pc}
+
+ENTRY(ftrace_caller)
+       stmdb sp!, {r0-r3, lr}
+       ldr r1, [fp, #-4]
+       mov r0, lr
+       sub r0, r0, #MCOUNT_INSN_SIZE
+
+       .globl ftrace_call
+ftrace_call:
+       bl ftrace_stub
+       ldmia sp!, {r0-r3, pc}
+
+#else
+
+ENTRY(mcount)
+       stmdb sp!, {r0-r3, lr}
+       ldr r0, =ftrace_trace_function
+       ldr r2, [r0]
+       adr r0, ftrace_stub
+       cmp r0, r2
+       bne trace
+       ldmia sp!, {r0-r3, pc}
+
+trace:
+       ldr r1, [fp, #-4]
+       mov r0, lr
+       sub r0, r0, #MCOUNT_INSN_SIZE
+       mov lr, pc
+       mov pc, r2
+       ldmia sp!, {r0-r3, pc}
+
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
+       .globl ftrace_stub
+ftrace_stub:
+       mov pc, lr
+
+#endif /* CONFIG_FTRACE */
+
 /*=============================================================================
  * SWI handler
  *-----------------------------------------------------------------------------
diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c
new file mode 100644 (file)
index 0000000..76d50e6
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Dynamic function tracing support.
+ *
+ * Copyright (C) 2008 Abhishek Sagar <sagar.abhishek@gmail.com>
+ *
+ * For licencing details, see COPYING.
+ *
+ * Defines low-level handling of mcount calls when the kernel
+ * is compiled with the -pg flag. When using dynamic ftrace, the
+ * mcount call-sites get patched lazily with NOP till they are
+ * enabled. All code mutation routines here take effect atomically.
+ */
+
+#include <linux/ftrace.h>
+
+#include <asm/cacheflush.h>
+#include <asm/ftrace.h>
+
+#define PC_OFFSET      8
+#define BL_OPCODE      0xeb000000
+#define BL_OFFSET_MASK 0x00ffffff
+
+static unsigned long bl_insn;
+static const unsigned long NOP = 0xe1a00000; /* mov r0, r0 */
+
+unsigned char *ftrace_nop_replace(void)
+{
+       return (char *)&NOP;
+}
+
+/* construct a branch (BL) instruction to addr */
+unsigned char *ftrace_call_replace(unsigned long pc, unsigned long addr)
+{
+       long offset;
+
+       offset = (long)addr - (long)(pc + PC_OFFSET);
+       if (unlikely(offset < -33554432 || offset > 33554428)) {
+               /* Can't generate branches that far (from ARM ARM). Ftrace
+                * doesn't generate branches outside of kernel text.
+                */
+               WARN_ON_ONCE(1);
+               return NULL;
+       }
+       offset = (offset >> 2) & BL_OFFSET_MASK;
+       bl_insn = BL_OPCODE | offset;
+       return (unsigned char *)&bl_insn;
+}
+
+int ftrace_modify_code(unsigned long pc, unsigned char *old_code,
+                      unsigned char *new_code)
+{
+       unsigned long err = 0, replaced = 0, old, new;
+
+       old = *(unsigned long *)old_code;
+       new = *(unsigned long *)new_code;
+
+       __asm__ __volatile__ (
+               "1:  ldr    %1, [%2]  \n"
+               "    cmp    %1, %4    \n"
+               "2:  streq  %3, [%2]  \n"
+               "    cmpne  %1, %3    \n"
+               "    movne  %0, #2    \n"
+               "3:\n"
+
+               ".section .fixup, \"ax\"\n"
+               "4:  mov  %0, #1  \n"
+               "    b    3b      \n"
+               ".previous\n"
+
+               ".section __ex_table, \"a\"\n"
+               "    .long 1b, 4b \n"
+               "    .long 2b, 4b \n"
+               ".previous\n"
+
+               : "=r"(err), "=r"(replaced)
+               : "r"(pc), "r"(new), "r"(old), "0"(err), "1"(replaced)
+               : "memory");
+
+       if (!err && (replaced == old))
+               flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
+
+       return err;
+}
+
+int ftrace_update_ftrace_func(ftrace_func_t func)
+{
+       int ret;
+       unsigned long pc, old;
+       unsigned char *new;
+
+       pc = (unsigned long)&ftrace_call;
+       memcpy(&old, &ftrace_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(pc, (unsigned long)func);
+       ret = ftrace_modify_code(pc, (unsigned char *)&old, new);
+       return ret;
+}
+
+int ftrace_mcount_set(unsigned long *data)
+{
+       unsigned long pc, old;
+       unsigned long *addr = data;
+       unsigned char *new;
+
+       pc = (unsigned long)&mcount_call;
+       memcpy(&old, &mcount_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(pc, *addr);
+       *addr = ftrace_modify_code(pc, (unsigned char *)&old, new);
+       return 0;
+}
+
+/* run from kstop_machine */
+int __init ftrace_dyn_arch_init(void *data)
+{
+       ftrace_mcount_set(data);
+       return 0;
+}
index 5593dd2..5ee39e1 100644 (file)
@@ -274,7 +274,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
  * for kretprobe handlers which should normally be interested in r0 only
  * anyway.
  */
-static void __attribute__((naked)) __kprobes kretprobe_trampoline(void)
+void __naked __kprobes kretprobe_trampoline(void)
 {
        __asm__ __volatile__ (
                "stmdb  sp!, {r0 - r11}         \n\t"
index 46bf2ed..199b368 100644 (file)
@@ -133,10 +133,8 @@ static void default_idle(void)
                cpu_relax();
        else {
                local_irq_disable();
-               if (!need_resched()) {
-                       timer_dyn_reprogram();
+               if (!need_resched())
                        arch_idle();
-               }
                local_irq_enable();
        }
 }
index ae31deb..90e0c35 100644 (file)
@@ -36,6 +36,7 @@ EXPORT_SYMBOL(walk_stackframe);
 #ifdef CONFIG_STACKTRACE
 struct stack_trace_data {
        struct stack_trace *trace;
+       unsigned int no_sched_functions;
        unsigned int skip;
 };
 
@@ -43,27 +44,52 @@ static int save_trace(struct stackframe *frame, void *d)
 {
        struct stack_trace_data *data = d;
        struct stack_trace *trace = data->trace;
+       unsigned long addr = frame->lr;
 
+       if (data->no_sched_functions && in_sched_functions(addr))
+               return 0;
        if (data->skip) {
                data->skip--;
                return 0;
        }
 
-       trace->entries[trace->nr_entries++] = frame->lr;
+       trace->entries[trace->nr_entries++] = addr;
 
        return trace->nr_entries >= trace->max_entries;
 }
 
-void save_stack_trace(struct stack_trace *trace)
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 {
        struct stack_trace_data data;
        unsigned long fp, base;
 
        data.trace = trace;
        data.skip = trace->skip;
-       base = (unsigned long)task_stack_page(current);
-       asm("mov %0, fp" : "=r" (fp));
+       base = (unsigned long)task_stack_page(tsk);
+
+       if (tsk != current) {
+#ifdef CONFIG_SMP
+               /*
+                * What guarantees do we have here that 'tsk'
+                * is not running on another CPU?
+                */
+               BUG();
+#else
+               data.no_sched_functions = 1;
+               fp = thread_saved_fp(tsk);
+#endif
+       } else {
+               data.no_sched_functions = 0;
+               asm("mov %0, fp" : "=r" (fp));
+       }
 
        walk_stackframe(fp, base, base + THREAD_SIZE, save_trace, &data);
+       if (trace->nr_entries < trace->max_entries)
+               trace->entries[trace->nr_entries++] = ULONG_MAX;
+}
+
+void save_stack_trace(struct stack_trace *trace)
+{
+       save_stack_trace_tsk(current, trace);
 }
 #endif
index b5867ec..cc5145b 100644 (file)
@@ -365,108 +365,6 @@ static struct sysdev_class timer_sysclass = {
        .resume         = timer_resume,
 };
 
-#ifdef CONFIG_NO_IDLE_HZ
-static int timer_dyn_tick_enable(void)
-{
-       struct dyn_tick_timer *dyn_tick = system_timer->dyn_tick;
-       unsigned long flags;
-       int ret = -ENODEV;
-
-       if (dyn_tick) {
-               spin_lock_irqsave(&dyn_tick->lock, flags);
-               ret = 0;
-               if (!(dyn_tick->state & DYN_TICK_ENABLED)) {
-                       ret = dyn_tick->enable();
-
-                       if (ret == 0)
-                               dyn_tick->state |= DYN_TICK_ENABLED;
-               }
-               spin_unlock_irqrestore(&dyn_tick->lock, flags);
-       }
-
-       return ret;
-}
-
-static int timer_dyn_tick_disable(void)
-{
-       struct dyn_tick_timer *dyn_tick = system_timer->dyn_tick;
-       unsigned long flags;
-       int ret = -ENODEV;
-
-       if (dyn_tick) {
-               spin_lock_irqsave(&dyn_tick->lock, flags);
-               ret = 0;
-               if (dyn_tick->state & DYN_TICK_ENABLED) {
-                       ret = dyn_tick->disable();
-
-                       if (ret == 0)
-                               dyn_tick->state &= ~DYN_TICK_ENABLED;
-               }
-               spin_unlock_irqrestore(&dyn_tick->lock, flags);
-       }
-
-       return ret;
-}
-
-/*
- * Reprogram the system timer for at least the calculated time interval.
- * This function should be called from the idle thread with IRQs disabled,
- * immediately before sleeping.
- */
-void timer_dyn_reprogram(void)
-{
-       struct dyn_tick_timer *dyn_tick = system_timer->dyn_tick;
-       unsigned long next, seq, flags;
-
-       if (!dyn_tick)
-               return;
-
-       spin_lock_irqsave(&dyn_tick->lock, flags);
-       if (dyn_tick->state & DYN_TICK_ENABLED) {
-               next = next_timer_interrupt();
-               do {
-                       seq = read_seqbegin(&xtime_lock);
-                       dyn_tick->reprogram(next - jiffies);
-               } while (read_seqretry(&xtime_lock, seq));
-       }
-       spin_unlock_irqrestore(&dyn_tick->lock, flags);
-}
-
-static ssize_t timer_show_dyn_tick(struct sys_device *dev, char *buf)
-{
-       return sprintf(buf, "%i\n",
-                      (system_timer->dyn_tick->state & DYN_TICK_ENABLED) >> 1);
-}
-
-static ssize_t timer_set_dyn_tick(struct sys_device *dev, const char *buf,
-                                 size_t count)
-{
-       unsigned int enable = simple_strtoul(buf, NULL, 2);
-
-       if (enable)
-               timer_dyn_tick_enable();
-       else
-               timer_dyn_tick_disable();
-
-       return count;
-}
-static SYSDEV_ATTR(dyn_tick, 0644, timer_show_dyn_tick, timer_set_dyn_tick);
-
-/*
- * dyntick=enable|disable
- */
-static char dyntick_str[4] __initdata = "";
-
-static int __init dyntick_setup(char *str)
-{
-       if (str)
-               strlcpy(dyntick_str, str, sizeof(dyntick_str));
-       return 1;
-}
-
-__setup("dyntick=", dyntick_setup);
-#endif
-
 static int __init timer_init_sysfs(void)
 {
        int ret = sysdev_class_register(&timer_sysclass);
@@ -475,19 +373,6 @@ static int __init timer_init_sysfs(void)
                ret = sysdev_register(&system_timer->dev);
        }
 
-#ifdef CONFIG_NO_IDLE_HZ
-       if (ret == 0 && system_timer->dyn_tick) {
-               ret = sysdev_create_file(&system_timer->dev, &attr_dyn_tick);
-
-               /*
-                * Turn on dynamic tick after calibrate delay
-                * for correct bogomips
-                */
-               if (ret == 0 && dyntick_str[0] == 'e')
-                       ret = timer_dyn_tick_enable();
-       }
-#endif
-
        return ret;
 }
 
@@ -500,10 +385,5 @@ void __init time_init(void)
                system_timer->offset = dummy_gettimeoffset;
 #endif
        system_timer->init();
-
-#ifdef CONFIG_NO_IDLE_HZ
-       if (system_timer->dyn_tick)
-               spin_lock_init(&system_timer->dyn_tick->lock);
-#endif
 }
 
index cab355c..139cce6 100644 (file)
  *  published by the Free Software Foundation.
  */
 
-/*
- * This can be used to enable code to cacheline align the source pointer.
- * Experiments on tested architectures (StrongARM and XScale) didn't show
- * this a worthwhile thing to do.  That might be different in the future.
- */
-//#define CALGN(code...)       code
-#define CALGN(code...)
-
 /*
  * Theory of operation
  * -------------------
@@ -82,7 +74,7 @@
                stmfd   sp!, {r5 - r8}
                blt     5f
 
-       CALGN(  ands    ip, r1, #31             )
+       CALGN(  ands    ip, r0, #31             )
        CALGN(  rsb     r3, ip, #32             )
        CALGN(  sbcnes  r4, r3, r2              )  @ C is always set here
        CALGN(  bcs     2f                      )
                subs    r2, r2, #28
                blt     14f
 
-       CALGN(  ands    ip, r1, #31             )
+       CALGN(  ands    ip, r0, #31             )
        CALGN(  rsb     ip, ip, #32             )
        CALGN(  sbcnes  r4, ip, r2              )  @ C is always set here
        CALGN(  subcc   r2, r2, ip              )
index ef7fddc..2e301b7 100644 (file)
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-/*
- * This can be used to enable code to cacheline align the source pointer.
- * Experiments on tested architectures (StrongARM and XScale) didn't show
- * this a worthwhile thing to do.  That might be different in the future.
- */
-//#define CALGN(code...)        code
-#define CALGN(code...)
-
                .text
 
 /*
@@ -55,11 +47,12 @@ ENTRY(memmove)
                stmfd   sp!, {r5 - r8}
                blt     5f
 
-       CALGN(  ands    ip, r1, #31             )
+       CALGN(  ands    ip, r0, #31             )
        CALGN(  sbcnes  r4, ip, r2              )  @ C is always set here
        CALGN(  bcs     2f                      )
        CALGN(  adr     r4, 6f                  )
        CALGN(  subs    r2, r2, ip              )  @ C is set here
+       CALGN(  rsb     ip, ip, #32             )
        CALGN(  add     pc, r4, ip              )
 
        PLD(    pld     [r1, #-4]               )
@@ -138,8 +131,7 @@ ENTRY(memmove)
                subs    r2, r2, #28
                blt     14f
 
-       CALGN(  ands    ip, r1, #31             )
-       CALGN(  rsb     ip, ip, #32             )
+       CALGN(  ands    ip, r0, #31             )
        CALGN(  sbcnes  r4, ip, r2              )  @ C is always set here
        CALGN(  subcc   r2, r2, ip              )
        CALGN(  bcc     15f                     )
index 95b110b..b477d4a 100644 (file)
@@ -39,6 +39,9 @@ ENTRY(memset)
        mov     r3, r1
        cmp     r2, #16
        blt     4f
+
+#if ! CALGN(1)+0
+
 /*
  * We need an extra register for this loop - save the return address and
  * use the LR
@@ -64,6 +67,49 @@ ENTRY(memset)
        stmneia r0!, {r1, r3, ip, lr}
        ldr     lr, [sp], #4
 
+#else
+
+/*
+ * This version aligns the destination pointer in order to write
+ * whole cache lines at once.
+ */
+
+       stmfd   sp!, {r4-r7, lr}
+       mov     r4, r1
+       mov     r5, r1
+       mov     r6, r1
+       mov     r7, r1
+       mov     ip, r1
+       mov     lr, r1
+
+       cmp     r2, #96
+       tstgt   r0, #31
+       ble     3f
+
+       and     ip, r0, #31
+       rsb     ip, ip, #32
+       sub     r2, r2, ip
+       movs    ip, ip, lsl #(32 - 4)
+       stmcsia r0!, {r4, r5, r6, r7}
+       stmmiia r0!, {r4, r5}
+       tst     ip, #(1 << 30)
+       mov     ip, r1
+       strne   r1, [r0], #4
+
+3:     subs    r2, r2, #64
+       stmgeia r0!, {r1, r3-r7, ip, lr}
+       stmgeia r0!, {r1, r3-r7, ip, lr}
+       bgt     3b
+       ldmeqfd sp!, {r4-r7, pc}
+
+       tst     r2, #32
+       stmneia r0!, {r1, r3-r7, ip, lr}
+       tst     r2, #16
+       stmneia r0!, {r4-r7}
+       ldmfd   sp!, {r4-r7, lr}
+
+#endif
+
 4:     tst     r2, #8
        stmneia r0!, {r1, r3}
        tst     r2, #4
index abf2508..b8f79d8 100644 (file)
@@ -39,6 +39,9 @@ ENTRY(__memzero)
  */
        cmp     r1, #16                 @ 1 we can skip this chunk if we
        blt     4f                      @ 1 have < 16 bytes
+
+#if ! CALGN(1)+0
+
 /*
  * We need an extra register for this loop - save the return address and
  * use the LR
@@ -64,6 +67,47 @@ ENTRY(__memzero)
        stmneia r0!, {r2, r3, ip, lr}   @ 4
        ldr     lr, [sp], #4            @ 1
 
+#else
+
+/*
+ * This version aligns the destination pointer in order to write
+ * whole cache lines at once.
+ */
+
+       stmfd   sp!, {r4-r7, lr}
+       mov     r4, r2
+       mov     r5, r2
+       mov     r6, r2
+       mov     r7, r2
+       mov     ip, r2
+       mov     lr, r2
+
+       cmp     r1, #96
+       andgts  ip, r0, #31
+       ble     3f
+
+       rsb     ip, ip, #32
+       sub     r1, r1, ip
+       movs    ip, ip, lsl #(32 - 4)
+       stmcsia r0!, {r4, r5, r6, r7}
+       stmmiia r0!, {r4, r5}
+       movs    ip, ip, lsl #2
+       strcs   r2, [r0], #4
+
+3:     subs    r1, r1, #64
+       stmgeia r0!, {r2-r7, ip, lr}
+       stmgeia r0!, {r2-r7, ip, lr}
+       bgt     3b
+       ldmeqfd sp!, {r4-r7, pc}
+
+       tst     r1, #32
+       stmneia r0!, {r2-r7, ip, lr}
+       tst     r1, #16
+       stmneia r0!, {r4-r7}
+       ldmfd   sp!, {r4-r7, lr}
+
+#endif
+
 4:     tst     r1, #8                  @ 1 8 bytes or more?
        stmneia r0!, {r2, r3}           @ 2
        tst     r1, #4                  @ 1 4 bytes or more?
index 0fc07b6..5bad6b9 100644 (file)
@@ -30,6 +30,11 @@ config ARCH_AT91SAM9RL
        select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
 
+config ARCH_AT91SAM9G20
+       bool "AT91SAM9G20"
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
+
 config ARCH_AT91CAP9
        bool "AT91CAP9"
        select GENERIC_TIME
@@ -126,6 +131,12 @@ config MACH_ECBAT91
          Select this if you are using emQbit's ECB_AT91 board.
          <http://wiki.emqbit.com/free-ecb-at91>
 
+config MACH_YL9200
+       bool "ucDragon YL-9200"
+       depends on ARCH_AT91RM9200
+       help
+         Select this if you are using the ucDragon YL-9200 board.
+
 endif
 
 # ----------------------------------------------------------
@@ -164,6 +175,20 @@ config MACH_SAM9_L9260
          Select this if you are using Olimex's SAM9-L9260 board based on the Atmel AT91SAM9260.
          <http://www.olimex.com/dev/sam9-L9260.html>
 
+config MACH_USB_A9260
+       bool "CALAO USB-A9260"
+       depends on ARCH_AT91SAM9260
+       help
+         Select this if you are using a Calao Systems USB-A9260.
+         <http://www.calao-systems.com>
+
+config MACH_QIL_A9260
+       bool "CALAO QIL-A9260 board"
+       depends on ARCH_AT91SAM9260
+       help
+         Select this if you are using a Calao Systems QIL-A9260 Board.
+         <http://www.calao-systems.com>
+
 endif
 
 # ----------------------------------------------------------
@@ -194,6 +219,13 @@ config MACH_AT91SAM9263EK
          Select this if you are using Atmel's AT91SAM9263-EK Evaluation Kit.
          <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4057>
 
+config MACH_USB_A9263
+       bool "CALAO USB-A9263"
+       depends on ARCH_AT91SAM9263
+       help
+         Select this if you are using a Calao Systems USB-A9263.
+         <http://www.calao-systems.com>
+
 endif
 
 # ----------------------------------------------------------
@@ -212,6 +244,20 @@ endif
 
 # ----------------------------------------------------------
 
+if ARCH_AT91SAM9G20
+
+comment "AT91SAM9G20 Board Type"
+
+config MACH_AT91SAM9G20EK
+       bool "Atmel AT91SAM9G20-EK Evaluation Kit"
+       depends on ARCH_AT91SAM9G20
+       help
+         Select this if you are using Atmel's AT91SAM9G20-EK Evaluation Kit.
+
+endif
+
+# ----------------------------------------------------------
+
 if ARCH_AT91CAP9
 
 comment "AT91CAP9 Board Type"
@@ -247,13 +293,13 @@ comment "AT91 Board Options"
 
 config MTD_AT91_DATAFLASH_CARD
        bool "Enable DataFlash Card support"
-       depends on (ARCH_AT91RM9200DK || MACH_AT91RM9200EK || MACH_AT91SAM9260EK || MACH_AT91SAM9261EK || MACH_AT91SAM9263EK || MACH_AT91CAP9ADK || MACH_SAM9_L9260 || MACH_ECBAT91)
+       depends on (ARCH_AT91RM9200DK || MACH_AT91RM9200EK || MACH_AT91SAM9260EK || MACH_AT91SAM9261EK || MACH_AT91SAM9263EK || MACH_AT91SAM9G20EK || MACH_ECBAT91 || MACH_SAM9_L9260 || MACH_AT91CAP9ADK)
        help
          Enable support for the DataFlash card.
 
 config MTD_NAND_AT91_BUSWIDTH_16
        bool "Enable 16-bit data bus interface to NAND flash"
-       depends on (MACH_AT91SAM9260EK || MACH_AT91SAM9261EK || MACH_AT91SAM9263EK || MACH_AT91CAP9ADK)
+       depends on (MACH_AT91SAM9260EK || MACH_AT91SAM9261EK || MACH_AT91SAM9263EK || MACH_AT91SAM9G20EK || MACH_AT91CAP9ADK)
        help
          On AT91SAM926x boards both types of NAND flash can be present
          (8 and 16 bit data bus width).
@@ -302,15 +348,15 @@ config AT91_EARLY_USART2
 
 config AT91_EARLY_USART3
        bool "USART3"
-       depends on (ARCH_AT91RM9200 || ARCH_AT91SAM9RL || ARCH_AT91SAM9260)
+       depends on (ARCH_AT91RM9200 || ARCH_AT91SAM9RL || ARCH_AT91SAM9260 || ARCH_AT91SAM9G20)
 
 config AT91_EARLY_USART4
        bool "USART4"
-       depends on ARCH_AT91SAM9260
+       depends on ARCH_AT91SAM9260 || ARCH_AT91SAM9G20
 
 config AT91_EARLY_USART5
        bool "USART5"
-       depends on ARCH_AT91SAM9260
+       depends on ARCH_AT91SAM9260 || ARCH_AT91SAM9G20
 
 endchoice
 
index 8d9bc01..7d641f9 100644 (file)
@@ -15,6 +15,7 @@ obj-$(CONFIG_ARCH_AT91SAM9260)        += at91sam9260.o at91sam926x_time.o at91sam9260_d
 obj-$(CONFIG_ARCH_AT91SAM9261) += at91sam9261.o at91sam926x_time.o at91sam9261_devices.o
 obj-$(CONFIG_ARCH_AT91SAM9263) += at91sam9263.o at91sam926x_time.o at91sam9263_devices.o
 obj-$(CONFIG_ARCH_AT91SAM9RL)  += at91sam9rl.o at91sam926x_time.o at91sam9rl_devices.o
+obj-$(CONFIG_ARCH_AT91SAM9G20) += at91sam9260.o at91sam926x_time.o at91sam9260_devices.o
 obj-$(CONFIG_ARCH_AT91CAP9)    += at91cap9.o at91sam926x_time.o at91cap9_devices.o
 obj-$(CONFIG_ARCH_AT91X40)     += at91x40.o at91x40_time.o
 
@@ -30,21 +31,28 @@ obj-$(CONFIG_MACH_ATEB9200) += board-eb9200.o
 obj-$(CONFIG_MACH_KAFA)                += board-kafa.o
 obj-$(CONFIG_MACH_PICOTUX2XX)  += board-picotux200.o
 obj-$(CONFIG_MACH_ECBAT91)     += board-ecbat91.o
+obj-$(CONFIG_MACH_YL9200)      += board-yl-9200.o
 
 # AT91SAM9260 board-specific support
 obj-$(CONFIG_MACH_AT91SAM9260EK) += board-sam9260ek.o
 obj-$(CONFIG_MACH_CAM60)       += board-cam60.o
 obj-$(CONFIG_MACH_SAM9_L9260)  += board-sam9-l9260.o
+obj-$(CONFIG_MACH_USB_A9260)   += board-usb-a9260.o
+obj-$(CONFIG_MACH_QIL_A9260)   += board-qil-a9260.o
 
 # AT91SAM9261 board-specific support
 obj-$(CONFIG_MACH_AT91SAM9261EK) += board-sam9261ek.o
 
 # AT91SAM9263 board-specific support
 obj-$(CONFIG_MACH_AT91SAM9263EK) += board-sam9263ek.o
+obj-$(CONFIG_MACH_USB_A9263)   += board-usb-a9263.o
 
 # AT91SAM9RL board-specific support
 obj-$(CONFIG_MACH_AT91SAM9RLEK)        += board-sam9rlek.o
 
+# AT91SAM9G20 board-specific support
+obj-$(CONFIG_MACH_AT91SAM9G20EK) += board-sam9g20ek.o
+
 # AT91CAP9 board-specific support
 obj-$(CONFIG_MACH_AT91CAP9ADK) += board-cap9adk.o
 
index be52674..747b9de 100644 (file)
@@ -83,6 +83,105 @@ void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
 #endif
 
 
+/* --------------------------------------------------------------------
+ *  USB HS Device (Gadget)
+ * -------------------------------------------------------------------- */
+
+#if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
+
+static struct resource usba_udc_resources[] = {
+       [0] = {
+               .start  = AT91CAP9_UDPHS_FIFO,
+               .end    = AT91CAP9_UDPHS_FIFO + SZ_512K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = AT91CAP9_BASE_UDPHS,
+               .end    = AT91CAP9_BASE_UDPHS + SZ_1K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [2] = {
+               .start  = AT91CAP9_ID_UDPHS,
+               .end    = AT91CAP9_ID_UDPHS,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+#define EP(nam, idx, maxpkt, maxbk, dma, isoc)                 \
+       [idx] = {                                               \
+               .name           = nam,                          \
+               .index          = idx,                          \
+               .fifo_size      = maxpkt,                       \
+               .nr_banks       = maxbk,                        \
+               .can_dma        = dma,                          \
+               .can_isoc       = isoc,                         \
+       }
+
+static struct usba_ep_data usba_udc_ep[] = {
+       EP("ep0", 0,   64, 1, 0, 0),
+       EP("ep1", 1, 1024, 3, 1, 1),
+       EP("ep2", 2, 1024, 3, 1, 1),
+       EP("ep3", 3, 1024, 2, 1, 1),
+       EP("ep4", 4, 1024, 2, 1, 1),
+       EP("ep5", 5, 1024, 2, 1, 0),
+       EP("ep6", 6, 1024, 2, 1, 0),
+       EP("ep7", 7, 1024, 2, 0, 0),
+};
+
+#undef EP
+
+/*
+ * pdata doesn't have room for any endpoints, so we need to
+ * append room for the ones we need right after it.
+ */
+static struct {
+       struct usba_platform_data pdata;
+       struct usba_ep_data ep[8];
+} usba_udc_data;
+
+static struct platform_device at91_usba_udc_device = {
+       .name           = "atmel_usba_udc",
+       .id             = -1,
+       .dev            = {
+                               .platform_data  = &usba_udc_data.pdata,
+       },
+       .resource       = usba_udc_resources,
+       .num_resources  = ARRAY_SIZE(usba_udc_resources),
+};
+
+void __init at91_add_device_usba(struct usba_platform_data *data)
+{
+       at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS |
+                                         AT91_MATRIX_UDPHS_BYPASS_LOCK);
+
+       /*
+        * Invalid pins are 0 on AT91, but the usba driver is shared
+        * with AVR32, which use negative values instead. Once/if
+        * gpio_is_valid() is ported to AT91, revisit this code.
+        */
+       usba_udc_data.pdata.vbus_pin = -EINVAL;
+       usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
+       memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
+
+       if (data && data->vbus_pin > 0) {
+               at91_set_gpio_input(data->vbus_pin, 0);
+               at91_set_deglitch(data->vbus_pin, 1);
+               usba_udc_data.pdata.vbus_pin = data->vbus_pin;
+       }
+
+       /* Pullup pin is handled internally by USB device peripheral */
+
+       /* Clocks */
+       at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
+       at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
+
+       platform_device_register(&at91_usba_udc_device);
+}
+#else
+void __init at91_add_device_usba(struct usba_platform_data *data) {}
+#endif
+
+
 /* --------------------------------------------------------------------
  *  Ethernet
  * -------------------------------------------------------------------- */
index ee26550..380f12a 100644 (file)
@@ -47,6 +47,20 @@ static struct map_desc at91sam9260_sram_desc[] __initdata = {
        }
 };
 
+static struct map_desc at91sam9g20_sram_desc[] __initdata = {
+       {
+               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE,
+               .pfn            = __phys_to_pfn(AT91SAM9G20_SRAM0_BASE),
+               .length         = AT91SAM9G20_SRAM0_SIZE,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = AT91_IO_VIRT_BASE - AT91SAM9G20_SRAM0_SIZE - AT91SAM9G20_SRAM1_SIZE,
+               .pfn            = __phys_to_pfn(AT91SAM9G20_SRAM1_BASE),
+               .length         = AT91SAM9G20_SRAM1_SIZE,
+               .type           = MT_DEVICE,
+       }
+};
+
 static struct map_desc at91sam9xe_sram_desc[] __initdata = {
        {
                .pfn            = __phys_to_pfn(AT91SAM9XE_SRAM_BASE),
@@ -307,6 +321,8 @@ void __init at91sam9260_initialize(unsigned long main_clock)
 
        if (cpu_is_at91sam9xe())
                at91sam9xe_initialize();
+       else if (cpu_is_at91sam9g20())
+               iotable_init(at91sam9g20_sram_desc, ARRAY_SIZE(at91sam9g20_sram_desc));
        else
                iotable_init(at91sam9260_sram_desc, ARRAY_SIZE(at91sam9260_sram_desc));
 
index 393a32a..86cba4a 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <asm/arch/board.h>
 #include <asm/arch/gpio.h>
+#include <asm/arch/cpu.h>
 #include <asm/arch/at91sam9260.h>
 #include <asm/arch/at91sam9260_matrix.h>
 #include <asm/arch/at91sam9_smc.h>
@@ -320,20 +321,41 @@ void __init at91_add_device_nand(struct at91_nand_data *data)
        csa = at91_sys_read(AT91_MATRIX_EBICSA);
        at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
 
-       /* set the bus interface characteristics */
-       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
-                       | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
+       if (cpu_is_at91sam9260()) {
+               /* Timing for sam9260 */
+               /* set the bus interface characteristics */
+               at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
+                               | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
 
-       at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
-                       | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
+               at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
+                               | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
 
-       at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
+               at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
 
-       if (data->bus_width_16)
-               mode = AT91_SMC_DBW_16;
-       else
-               mode = AT91_SMC_DBW_8;
-       at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
+               if (data->bus_width_16)
+                       mode = AT91_SMC_DBW_16;
+               else
+                       mode = AT91_SMC_DBW_8;
+               at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
+       }
+
+       if (cpu_is_at91sam9g20()) {
+               /* Timing for sam9g20 */
+               /* set the bus interface characteristics */
+               at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(0)
+                               | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(0));
+
+               at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(4)
+                               | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(4));
+
+               at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
+
+               if (data->bus_width_16)
+                       mode = AT91_SMC_DBW_16;
+               else
+                       mode = AT91_SMC_DBW_8;
+               at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(3));
+       }
 
        /* enable pin */
        if (data->enable_pin)
index 0babb64..ec18913 100644 (file)
@@ -232,19 +232,19 @@ void __init at91_add_device_nand(struct at91_nand_data *data)
        at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
 
        /* set the bus interface characteristics */
-       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
-                       | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
+       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
+                       | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
 
-       at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
-                       | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
+       at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
+                       | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
 
-       at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
+       at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
 
        if (data->bus_width_16)
                mode = AT91_SMC_DBW_16;
        else
                mode = AT91_SMC_DBW_8;
-       at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
+       at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
 
        /* enable pin */
        if (data->enable_pin)
index 719667e..8a81f76 100644 (file)
@@ -391,8 +391,8 @@ void __init at91_add_device_nand(struct at91_nand_data *data)
        at91_sys_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
 
        /* set the bus interface characteristics */
-       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
-                       | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
+       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
+                       | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
 
        at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
                        | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
index 450db30..ae28101 100644 (file)
 #include "generic.h"
 
 
+/* --------------------------------------------------------------------
+ *  USB HS Device (Gadget)
+ * -------------------------------------------------------------------- */
+
+#if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
+
+static struct resource usba_udc_resources[] = {
+       [0] = {
+               .start  = AT91SAM9RL_UDPHS_FIFO,
+               .end    = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = AT91SAM9RL_BASE_UDPHS,
+               .end    = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [2] = {
+               .start  = AT91SAM9RL_ID_UDPHS,
+               .end    = AT91SAM9RL_ID_UDPHS,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+#define EP(nam, idx, maxpkt, maxbk, dma, isoc)                 \
+       [idx] = {                                               \
+               .name           = nam,                          \
+               .index          = idx,                          \
+               .fifo_size      = maxpkt,                       \
+               .nr_banks       = maxbk,                        \
+               .can_dma        = dma,                          \
+               .can_isoc       = isoc,                         \
+       }
+
+static struct usba_ep_data usba_udc_ep[] __initdata = {
+       EP("ep0", 0, 64, 1, 0, 0),
+       EP("ep1", 1, 1024, 2, 1, 1),
+       EP("ep2", 2, 1024, 2, 1, 1),
+       EP("ep3", 3, 1024, 3, 1, 0),
+       EP("ep4", 4, 1024, 3, 1, 0),
+       EP("ep5", 5, 1024, 3, 1, 1),
+       EP("ep6", 6, 1024, 3, 1, 1),
+};
+
+#undef EP
+
+/*
+ * pdata doesn't have room for any endpoints, so we need to
+ * append room for the ones we need right after it.
+ */
+static struct {
+       struct usba_platform_data pdata;
+       struct usba_ep_data ep[7];
+} usba_udc_data;
+
+static struct platform_device at91_usba_udc_device = {
+       .name           = "atmel_usba_udc",
+       .id             = -1,
+       .dev            = {
+                               .platform_data  = &usba_udc_data.pdata,
+       },
+       .resource       = usba_udc_resources,
+       .num_resources  = ARRAY_SIZE(usba_udc_resources),
+};
+
+void __init at91_add_device_usba(struct usba_platform_data *data)
+{
+       /*
+        * Invalid pins are 0 on AT91, but the usba driver is shared
+        * with AVR32, which use negative values instead. Once/if
+        * gpio_is_valid() is ported to AT91, revisit this code.
+        */
+       usba_udc_data.pdata.vbus_pin = -EINVAL;
+       usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
+       memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
+
+       if (data && data->vbus_pin > 0) {
+               at91_set_gpio_input(data->vbus_pin, 0);
+               at91_set_deglitch(data->vbus_pin, 1);
+               usba_udc_data.pdata.vbus_pin = data->vbus_pin;
+       }
+
+       /* Pullup pin is handled internally by USB device peripheral */
+
+       /* Clocks */
+       at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
+       at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
+
+       platform_device_register(&at91_usba_udc_device);
+}
+#else
+void __init at91_add_device_usba(struct usba_platform_data *data) {}
+#endif
+
+
 /* --------------------------------------------------------------------
  *  MMC / SD
  * -------------------------------------------------------------------- */
@@ -138,15 +233,15 @@ void __init at91_add_device_nand(struct at91_nand_data *data)
        at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
 
        /* set the bus interface characteristics */
-       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
-                       | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
+       at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
+                       | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
 
-       at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
-                       | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
+       at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
+                       | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
 
-       at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
+       at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
 
-       at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
+       at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
 
        /* enable pin */
        if (data->enable_pin)
index e5512d1..8a2a958 100644 (file)
@@ -78,6 +78,12 @@ static struct at91_usbh_data __initdata cap9adk_usbh_data = {
        .ports          = 2,
 };
 
+/*
+ * USB HS Device port
+ */
+static struct usba_platform_data __initdata cap9adk_usba_udc_data = {
+       .vbus_pin       = AT91_PIN_PB31,
+};
 
 /*
  * ADS7846 Touchscreen
@@ -326,6 +332,9 @@ static void __init cap9adk_board_init(void)
        /* USB Host */
        set_irq_type(AT91CAP9_ID_UHP, IRQT_HIGH);
        at91_add_device_usbh(&cap9adk_usbh_data);
+       /* USB HS */
+       set_irq_type(AT91CAP9_ID_UDPHS, IRQT_HIGH);
+       at91_add_device_usba(&cap9adk_usba_udc_data);
        /* SPI */
        at91_add_device_spi(cap9adk_spi_devices, ARRAY_SIZE(cap9adk_spi_devices));
        /* Touchscreen */
index 0f08782..9854fc3 100644 (file)
 #include "generic.h"
 
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- */
-static struct at91_uart_config __initdata carmeva_uart_config = {
-       .console_tty    = 0,                            /* ttyS0 */
-       .nr_tty         = 2,
-       .tty_map        = { 4, 1, -1, -1, -1 }          /* ttyS0, ..., ttyS4 */
-};
-
 static void __init carmeva_map_io(void)
 {
        /* Initialize processor: 20.000 MHz crystal */
        at91rm9200_initialize(20000000, AT91RM9200_BGA);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&carmeva_uart_config);
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                          | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                          | ATMEL_UART_RI);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
 static void __init carmeva_init_irq(void)
index 419fd19..bb1a547 100644 (file)
@@ -45,10 +45,10 @@ static void __init csb637_map_io(void)
        /* Initialize processor: 3.6864 MHz crystal */
        at91rm9200_initialize(3686400, AT91RM9200_BGA);
 
-       /* DBGU on ttyS0 */
+       /* DBGU on ttyS0. (Rx & Tx only) */
        at91_register_uart(0, 0, 0);
 
-       /* make console=ttyS0 the default */
+       /* make console=ttyS0 (ie, DBGU) the default */
        at91_set_serial_console(0);
 }
 
index c1a813c..dab958d 100644 (file)
 #include "generic.h"
 
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- */
-static struct at91_uart_config __initdata dk_uart_config = {
-       .console_tty    = 0,                            /* ttyS0 */
-       .nr_tty         = 2,
-       .tty_map        = { 4, 1, -1, -1, -1 }          /* ttyS0, ..., ttyS4 */
-};
-
 static void __init dk_map_io(void)
 {
        /* Initialize processor: 18.432 MHz crystal */
@@ -64,8 +53,16 @@ static void __init dk_map_io(void)
        /* Setup the LEDs */
        at91_init_leds(AT91_PIN_PB2, AT91_PIN_PB2);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&dk_uart_config);
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                          | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                          | ATMEL_UART_RI);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
 static void __init dk_init_irq(void)
@@ -163,7 +160,7 @@ static struct at91_nand_data __initdata dk_nand_data = {
 #define DK_FLASH_SIZE  0x200000
 
 static struct physmap_flash_data dk_flash_data = {
-       .width  = 2,
+       .width          = 2,
 };
 
 static struct resource dk_flash_resource = {
index af1a1d8..3fe054e 100644 (file)
 #include "generic.h"
 
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- */
-static struct at91_uart_config __initdata eb9200_uart_config = {
-       .console_tty    = 0,                            /* ttyS0 */
-       .nr_tty         = 2,
-       .tty_map        = { 4, 1, -1, -1, -1 }          /* ttyS0, ..., ttyS4 */
-};
-
 static void __init eb9200_map_io(void)
 {
        /* Initialize processor: 18.432 MHz crystal */
        at91rm9200_initialize(18432000, AT91RM9200_BGA);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&eb9200_uart_config);
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                       | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                       | ATMEL_UART_RI);
+
+       /* USART2 on ttyS2. (Rx, Tx) - IRDA */
+       at91_register_uart(AT91RM9200_ID_US2, 2, 0);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
 static void __init eb9200_init_irq(void)
index 0574e50..74aa432 100644 (file)
 #include "generic.h"
 
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- */
-static struct at91_uart_config __initdata ek_uart_config = {
-       .console_tty    = 0,                            /* ttyS0 */
-       .nr_tty         = 2,
-       .tty_map        = { 4, 1, -1, -1, -1 }          /* ttyS0, ..., ttyS4 */
-};
-
 static void __init ek_map_io(void)
 {
        /* Initialize processor: 18.432 MHz crystal */
@@ -64,8 +53,16 @@ static void __init ek_map_io(void)
        /* Setup the LEDs */
        at91_init_leds(AT91_PIN_PB1, AT91_PIN_PB2);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&ek_uart_config);
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                          | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                          | ATMEL_UART_RI);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
 static void __init ek_init_irq(void)
@@ -122,7 +119,7 @@ static struct i2c_board_info __initdata ek_i2c_devices[] = {
 #define EK_FLASH_SIZE  0x200000
 
 static struct physmap_flash_data ek_flash_data = {
-       .width  = 2,
+       .width          = 2,
 };
 
 static struct resource ek_flash_resource = {
index 4b39b9c..cb065fe 100644 (file)
 #include <asm/arch/board.h>
 #include <asm/arch/gpio.h>
 
-#include "generic.h"
+#include <asm/arch/at91rm9200_mc.h>
 
+#include "generic.h"
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- */
-static struct at91_uart_config __initdata kb9202_uart_config = {
-       .console_tty    = 0,                                    /* ttyS0 */
-       .nr_tty         = 3,
-       .tty_map        = { 4, 0, 1, -1, -1 }                   /* ttyS0, ..., ttyS4 */
-};
 
 static void __init kb9202_map_io(void)
 {
@@ -59,8 +50,20 @@ static void __init kb9202_map_io(void)
        /* Set up the LEDs */
        at91_init_leds(AT91_PIN_PC19, AT91_PIN_PC18);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&kb9202_uart_config);
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART0 on ttyS1 (Rx & Tx only) */
+       at91_register_uart(AT91RM9200_ID_US0, 1, 0);
+
+       /* USART1 on ttyS2 (Rx & Tx only) - IRDA (optional) */
+       at91_register_uart(AT91RM9200_ID_US1, 2, 0);
+
+       /* USART3 on ttyS3 (Rx, Tx, CTS, RTS) - RS485 (optional) */
+       at91_register_uart(AT91RM9200_ID_US3, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
 static void __init kb9202_init_irq(void)
diff --git a/arch/arm/mach-at91/board-qil-a9260.c b/arch/arm/mach-at91/board-qil-a9260.c
new file mode 100644 (file)
index 0000000..99b4ec3
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * linux/arch/arm/mach-at91/board-qil-a9260.c
+ *
+ *  Copyright (C) 2005 SAN People
+ *  Copyright (C) 2006 Atmel
+ *  Copyright (C) 2007 Calao-systems
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/clk.h>
+
+#include <asm/hardware.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/irq.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/board.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/at91_shdwc.h>
+
+#include "generic.h"
+
+
+static void __init ek_map_io(void)
+{
+       /* Initialize processor: 12.000 MHz crystal */
+       at91sam9260_initialize(12000000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                          | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                          | ATMEL_UART_RI);
+
+       /* USART1 on ttyS2. (Rx, Tx, CTS, RTS) */
+       at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* USART2 on ttyS3. (Rx, Tx, CTS, RTS) */
+       at91_register_uart(AT91SAM9260_ID_US2, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* set serial console to ttyS1 (ie, USART0) */
+       at91_set_serial_console(1);
+
+}
+
+static void __init ek_init_irq(void)
+{
+       at91sam9260_init_interrupts(NULL);
+}
+
+
+/*
+ * USB Host port
+ */
+static struct at91_usbh_data __initdata ek_usbh_data = {
+       .ports          = 2,
+};
+
+/*
+ * USB Device port
+ */
+static struct at91_udc_data __initdata ek_udc_data = {
+       .vbus_pin       = AT91_PIN_PC5,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+/*
+ * SPI devices.
+ */
+static struct spi_board_info ek_spi_devices[] = {
+#if defined(CONFIG_RTC_DRV_M41T94)
+       {       /* M41T94 RTC */
+               .modalias       = "m41t94",
+               .chip_select    = 0,
+               .max_speed_hz   = 1 * 1000 * 1000,
+               .bus_num        = 0,
+       }
+#endif
+};
+
+/*
+ * MACB Ethernet device
+ */
+static struct at91_eth_data __initdata ek_macb_data = {
+       .phy_irq_pin    = AT91_PIN_PA31,
+       .is_rmii        = 1,
+};
+
+/*
+ * NAND flash
+ */
+static struct mtd_partition __initdata ek_nand_partition[] = {
+       {
+               .name   = "Uboot & Kernel",
+               .offset = 0x00000000,
+               .size   = 16 * 1024 * 1024,
+       },
+       {
+               .name   = "Root FS",
+               .offset = 0x01000000,
+               .size   = 120 * 1024 * 1024,
+       },
+       {
+               .name   = "FS",
+               .offset = 0x08800000,
+               .size   = 120 * 1024 * 1024,
+       },
+};
+
+static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
+{
+       *num_partitions = ARRAY_SIZE(ek_nand_partition);
+       return ek_nand_partition;
+}
+
+static struct at91_nand_data __initdata ek_nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+//     .det_pin        = ... not connected
+       .rdy_pin        = AT91_PIN_PC13,
+       .enable_pin     = AT91_PIN_PC14,
+       .partition_info = nand_partitions,
+#if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
+       .bus_width_16   = 1,
+#else
+       .bus_width_16   = 0,
+#endif
+};
+
+/*
+ * MCI (SD/MMC)
+ */
+static struct at91_mmc_data __initdata ek_mmc_data = {
+       .slot_b         = 0,
+       .wire4          = 1,
+//     .det_pin        = ... not connected
+//     .wp_pin         = ... not connected
+//     .vcc_pin        = ... not connected
+};
+
+/*
+ * GPIO Buttons
+ */
+#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
+static struct gpio_keys_button ek_buttons[] = {
+       {       /* USER PUSH BUTTON */
+               .code           = KEY_ENTER,
+               .gpio           = AT91_PIN_PB10,
+               .active_low     = 1,
+               .desc           = "user_pb",
+               .wakeup         = 1,
+       }
+};
+
+static struct gpio_keys_platform_data ek_button_data = {
+       .buttons        = ek_buttons,
+       .nbuttons       = ARRAY_SIZE(ek_buttons),
+};
+
+static struct platform_device ek_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &ek_button_data,
+       }
+};
+
+static void __init ek_add_device_buttons(void)
+{
+       at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
+       at91_set_deglitch(AT91_PIN_PB10, 1);
+
+       platform_device_register(&ek_button_device);
+}
+#else
+static void __init ek_add_device_buttons(void) {}
+#endif
+
+/*
+ * LEDs
+ */
+static struct gpio_led ek_leds[] = {
+       {       /* user_led (green) */
+               .name                   = "user_led",
+               .gpio                   = AT91_PIN_PB21,
+               .active_low             = 0,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+static void __init ek_board_init(void)
+{
+       /* Serial */
+       at91_add_device_serial();
+       /* USB Host */
+       at91_add_device_usbh(&ek_usbh_data);
+       /* USB Device */
+       at91_add_device_udc(&ek_udc_data);
+       /* SPI */
+       at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
+       /* NAND */
+       at91_add_device_nand(&ek_nand_data);
+       /* I2C */
+       at91_add_device_i2c(NULL, 0);
+       /* Ethernet */
+       at91_add_device_eth(&ek_macb_data);
+       /* MMC */
+       at91_add_device_mmc(0, &ek_mmc_data);
+       /* Push Buttons */
+       ek_add_device_buttons();
+       /* LEDs */
+       at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
+       /* shutdown controller, wakeup button (5 msec low) */
+       at91_sys_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10) | AT91_SHDW_WKMODE0_LOW
+                               | AT91_SHDW_RTTWKEN);
+}
+
+MACHINE_START(QIL_A9260, "CALAO QIL_A9260")
+       /* Maintainer: calao-systems */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = ek_map_io,
+       .init_irq       = ek_init_irq,
+       .init_machine   = ek_board_init,
+MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
new file mode 100644 (file)
index 0000000..45617c2
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ *  Copyright (C) 2005 SAN People
+ *  Copyright (C) 2008 Atmel
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/at73c213.h>
+#include <linux/clk.h>
+
+#include <asm/hardware.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/irq.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/board.h>
+#include <asm/arch/gpio.h>
+
+#include "generic.h"
+
+
+static void __init ek_map_io(void)
+{
+       /* Initialize processor: 18.432 MHz crystal */
+       at91sam9260_initialize(18432000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                          | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                          | ATMEL_UART_RI);
+
+       /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
+       at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
+}
+
+static void __init ek_init_irq(void)
+{
+       at91sam9260_init_interrupts(NULL);
+}
+
+
+/*
+ * USB Host port
+ */
+static struct at91_usbh_data __initdata ek_usbh_data = {
+       .ports          = 2,
+};
+
+/*
+ * USB Device port
+ */
+static struct at91_udc_data __initdata ek_udc_data = {
+       .vbus_pin       = AT91_PIN_PC5,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+
+/*
+ * SPI devices.
+ */
+static struct spi_board_info ek_spi_devices[] = {
+#if !defined(CONFIG_MMC_AT91)
+       {       /* DataFlash chip */
+               .modalias       = "mtd_dataflash",
+               .chip_select    = 1,
+               .max_speed_hz   = 15 * 1000 * 1000,
+               .bus_num        = 0,
+       },
+#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
+       {       /* DataFlash card */
+               .modalias       = "mtd_dataflash",
+               .chip_select    = 0,
+               .max_speed_hz   = 15 * 1000 * 1000,
+               .bus_num        = 0,
+       },
+#endif
+#endif
+};
+
+
+/*
+ * MACB Ethernet device
+ */
+static struct at91_eth_data __initdata ek_macb_data = {
+       .phy_irq_pin    = AT91_PIN_PA7,
+       .is_rmii        = 1,
+};
+
+
+/*
+ * NAND flash
+ */
+static struct mtd_partition __initdata ek_nand_partition[] = {
+       {
+               .name   = "Bootstrap",
+               .offset = 0,
+               .size   = 4 * 1024 * 1024,
+       },
+       {
+               .name   = "Partition 1",
+               .offset = 4 * 1024 * 1024,
+               .size   = 60 * 1024 * 1024,
+       },
+       {
+               .name   = "Partition 2",
+               .offset = 64 * 1024 * 1024,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
+{
+       *num_partitions = ARRAY_SIZE(ek_nand_partition);
+       return ek_nand_partition;
+}
+
+/* det_pin is not connected */
+static struct at91_nand_data __initdata ek_nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+       .rdy_pin        = AT91_PIN_PC13,
+       .enable_pin     = AT91_PIN_PC14,
+       .partition_info = nand_partitions,
+#if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
+       .bus_width_16   = 1,
+#else
+       .bus_width_16   = 0,
+#endif
+};
+
+
+/*
+ * MCI (SD/MMC)
+ * det_pin, wp_pin and vcc_pin are not connected
+ */
+static struct at91_mmc_data __initdata ek_mmc_data = {
+       .slot_b         = 1,
+       .wire4          = 1,
+};
+
+
+/*
+ * LEDs
+ */
+static struct gpio_led ek_leds[] = {
+       {       /* "bottom" led, green, userled1 to be defined */
+               .name                   = "ds5",
+               .gpio                   = AT91_PIN_PA6,
+               .active_low             = 1,
+               .default_trigger        = "none",
+       },
+       {       /* "power" led, yellow */
+               .name                   = "ds1",
+               .gpio                   = AT91_PIN_PA9,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+static void __init ek_board_init(void)
+{
+       /* Serial */
+       at91_add_device_serial();
+       /* USB Host */
+       at91_add_device_usbh(&ek_usbh_data);
+       /* USB Device */
+       at91_add_device_udc(&ek_udc_data);
+       /* SPI */
+       at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
+       /* NAND */
+       at91_add_device_nand(&ek_nand_data);
+       /* Ethernet */
+       at91_add_device_eth(&ek_macb_data);
+       /* MMC */
+       at91_add_device_mmc(0, &ek_mmc_data);
+       /* I2C */
+       at91_add_device_i2c(NULL, 0);
+       /* LEDs */
+       at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
+}
+
+MACHINE_START(AT91SAM9G20EK, "Atmel AT91SAM9G20-EK")
+       /* Maintainer: Atmel */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = ek_map_io,
+       .init_irq       = ek_init_irq,
+       .init_machine   = ek_board_init,
+MACHINE_END
index ffc0597..b6a70fc 100644 (file)
@@ -55,6 +55,14 @@ static void __init ek_init_irq(void)
 }
 
 
+/*
+ * USB HS Device port
+ */
+static struct usba_platform_data __initdata ek_usba_udc_data = {
+       .vbus_pin       = AT91_PIN_PA8,
+};
+
+
 /*
  * MCI (SD/MMC)
  */
@@ -175,6 +183,8 @@ static void __init ek_board_init(void)
 {
        /* Serial */
        at91_add_device_serial();
+       /* USB HS */
+       at91_add_device_usba(&ek_usba_udc_data);
        /* I2C */
        at91_add_device_i2c(NULL, 0);
        /* NAND */
diff --git a/arch/arm/mach-at91/board-usb-a9260.c b/arch/arm/mach-at91/board-usb-a9260.c
new file mode 100644 (file)
index 0000000..837aedf
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * linux/arch/arm/mach-at91/board-usb-a9260.c
+ *
+ *  Copyright (C) 2005 SAN People
+ *  Copyright (C) 2006 Atmel
+ *  Copyright (C) 2007 Calao-systems
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/clk.h>
+
+#include <asm/hardware.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/irq.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/board.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/at91_shdwc.h>
+
+#include "generic.h"
+
+
+static void __init ek_map_io(void)
+{
+       /* Initialize processor: 12.000 MHz crystal */
+       at91sam9260_initialize(12000000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
+}
+
+static void __init ek_init_irq(void)
+{
+       at91sam9260_init_interrupts(NULL);
+}
+
+
+/*
+ * USB Host port
+ */
+static struct at91_usbh_data __initdata ek_usbh_data = {
+       .ports          = 2,
+};
+
+/*
+ * USB Device port
+ */
+static struct at91_udc_data __initdata ek_udc_data = {
+       .vbus_pin       = AT91_PIN_PC5,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+/*
+ * MACB Ethernet device
+ */
+static struct at91_eth_data __initdata ek_macb_data = {
+       .phy_irq_pin    = AT91_PIN_PA31,
+       .is_rmii        = 1,
+};
+
+/*
+ * NAND flash
+ */
+static struct mtd_partition __initdata ek_nand_partition[] = {
+       {
+               .name   = "Uboot & Kernel",
+               .offset = 0x00000000,
+               .size   = 16 * 1024 * 1024,
+       },
+       {
+               .name   = "Root FS",
+               .offset = 0x01000000,
+               .size   = 120 * 1024 * 1024,
+       },
+       {
+               .name   = "FS",
+               .offset = 0x08800000,
+               .size   = 120 * 1024 * 1024,
+       }
+};
+
+static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
+{
+       *num_partitions = ARRAY_SIZE(ek_nand_partition);
+       return ek_nand_partition;
+}
+
+static struct at91_nand_data __initdata ek_nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+//     .det_pin        = ... not connected
+       .rdy_pin        = AT91_PIN_PC13,
+       .enable_pin     = AT91_PIN_PC14,
+       .partition_info = nand_partitions,
+#if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
+       .bus_width_16   = 1,
+#else
+       .bus_width_16   = 0,
+#endif
+};
+
+/*
+ * GPIO Buttons
+ */
+
+#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
+static struct gpio_keys_button ek_buttons[] = {
+       {       /* USER PUSH BUTTON */
+               .code           = KEY_ENTER,
+               .gpio           = AT91_PIN_PB10,
+               .active_low     = 1,
+               .desc           = "user_pb",
+               .wakeup         = 1,
+       }
+};
+
+static struct gpio_keys_platform_data ek_button_data = {
+       .buttons        = ek_buttons,
+       .nbuttons       = ARRAY_SIZE(ek_buttons),
+};
+
+static struct platform_device ek_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &ek_button_data,
+       }
+};
+
+static void __init ek_add_device_buttons(void)
+{
+       at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
+       at91_set_deglitch(AT91_PIN_PB10, 1);
+
+       platform_device_register(&ek_button_device);
+}
+#else
+static void __init ek_add_device_buttons(void) {}
+#endif
+
+/*
+ * LEDs
+ */
+static struct gpio_led ek_leds[] = {
+       {       /* user_led (green) */
+               .name                   = "user_led",
+               .gpio                   = AT91_PIN_PB21,
+               .active_low             = 0,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+static void __init ek_board_init(void)
+{
+       /* Serial */
+       at91_add_device_serial();
+       /* USB Host */
+       at91_add_device_usbh(&ek_usbh_data);
+       /* USB Device */
+       at91_add_device_udc(&ek_udc_data);
+       /* NAND */
+       at91_add_device_nand(&ek_nand_data);
+       /* I2C */
+       at91_add_device_i2c(NULL, 0);
+       /* Ethernet */
+       at91_add_device_eth(&ek_macb_data);
+       /* Push Buttons */
+       ek_add_device_buttons();
+       /* LEDs */
+       at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
+       /* shutdown controller, wakeup button (5 msec low) */
+       at91_sys_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10) | AT91_SHDW_WKMODE0_LOW
+                               | AT91_SHDW_RTTWKEN);
+}
+
+MACHINE_START(USB_A9260, "CALAO USB_A9260")
+       /* Maintainer: calao-systems */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = ek_map_io,
+       .init_irq       = ek_init_irq,
+       .init_machine   = ek_board_init,
+MACHINE_END
diff --git a/arch/arm/mach-at91/board-usb-a9263.c b/arch/arm/mach-at91/board-usb-a9263.c
new file mode 100644 (file)
index 0000000..95800d3
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ * linux/arch/arm/mach-at91/board-usb-a9263.c
+ *
+ *  Copyright (C) 2005 SAN People
+ *  Copyright (C) 2007 Atmel Corporation.
+ *  Copyright (C) 2007 Calao-systems
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+
+#include <asm/hardware.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/irq.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/board.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/at91_shdwc.h>
+
+#include "generic.h"
+
+
+static void __init ek_map_io(void)
+{
+       /* Initialize processor: 12.00 MHz crystal */
+       at91sam9263_initialize(12000000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
+}
+
+static void __init ek_init_irq(void)
+{
+       at91sam9263_init_interrupts(NULL);
+}
+
+
+/*
+ * USB Host port
+ */
+static struct at91_usbh_data __initdata ek_usbh_data = {
+       .ports          = 2,
+};
+
+/*
+ * USB Device port
+ */
+static struct at91_udc_data __initdata ek_udc_data = {
+       .vbus_pin       = AT91_PIN_PB11,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+/*
+ * SPI devices.
+ */
+static struct spi_board_info ek_spi_devices[] = {
+#if !defined(CONFIG_MMC_AT91)
+       {       /* DataFlash chip */
+               .modalias       = "mtd_dataflash",
+               .chip_select    = 0,
+               .max_speed_hz   = 15 * 1000 * 1000,
+               .bus_num        = 0,
+       }
+#endif
+};
+
+/*
+ * MACB Ethernet device
+ */
+static struct at91_eth_data __initdata ek_macb_data = {
+       .phy_irq_pin    = AT91_PIN_PE31,
+       .is_rmii        = 1,
+};
+
+/*
+ * NAND flash
+ */
+static struct mtd_partition __initdata ek_nand_partition[] = {
+       {
+               .name   = "Linux Kernel",
+               .offset = 0x00000000,
+               .size   = 16 * 1024 * 1024,
+       },
+       {
+               .name   = "Root FS",
+               .offset = 0x01000000,
+               .size   = 120 * 1024 * 1024,
+       },
+       {
+               .name   = "FS",
+               .offset = 0x08800000,
+               .size   = 120 * 1024 * 1024,
+       }
+};
+
+static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
+{
+       *num_partitions = ARRAY_SIZE(ek_nand_partition);
+       return ek_nand_partition;
+}
+
+static struct at91_nand_data __initdata ek_nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+//     .det_pin        = ... not connected
+       .rdy_pin        = AT91_PIN_PA22,
+       .enable_pin     = AT91_PIN_PD15,
+       .partition_info = nand_partitions,
+#if defined(CONFIG_MTD_NAND_AT91_BUSWIDTH_16)
+       .bus_width_16   = 1,
+#else
+       .bus_width_16   = 0,
+#endif
+};
+
+/*
+ * GPIO Buttons
+ */
+#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
+static struct gpio_keys_button ek_buttons[] = {
+       {       /* USER PUSH BUTTON */
+               .code           = KEY_ENTER,
+               .gpio           = AT91_PIN_PB10,
+               .active_low     = 1,
+               .desc           = "user_pb",
+               .wakeup         = 1,
+       }
+};
+
+static struct gpio_keys_platform_data ek_button_data = {
+       .buttons        = ek_buttons,
+       .nbuttons       = ARRAY_SIZE(ek_buttons),
+};
+
+static struct platform_device ek_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &ek_button_data,
+       }
+};
+
+static void __init ek_add_device_buttons(void)
+{
+       at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* user push button, pull up enabled */
+       at91_set_deglitch(AT91_PIN_PB10, 1);
+
+       platform_device_register(&ek_button_device);
+}
+#else
+static void __init ek_add_device_buttons(void) {}
+#endif
+
+/*
+ * LEDs
+ */
+static struct gpio_led ek_leds[] = {
+       {       /* user_led (green) */
+               .name                   = "user_led",
+               .gpio                   = AT91_PIN_PB21,
+               .active_low             = 1,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+
+static void __init ek_board_init(void)
+{
+       /* Serial */
+       at91_add_device_serial();
+       /* USB Host */
+       at91_add_device_usbh(&ek_usbh_data);
+       /* USB Device */
+       at91_add_device_udc(&ek_udc_data);
+       /* SPI */
+       at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
+       /* Ethernet */
+       at91_add_device_eth(&ek_macb_data);
+       /* NAND */
+       at91_add_device_nand(&ek_nand_data);
+       /* I2C */
+       at91_add_device_i2c(NULL, 0);
+       /* Push Buttons */
+       ek_add_device_buttons();
+       /* LEDs */
+       at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
+       /* shutdown controller, wakeup button (5 msec low) */
+       at91_sys_write(AT91_SHDW_MR, AT91_SHDW_CPTWK0_(10) | AT91_SHDW_WKMODE0_LOW
+                               | AT91_SHDW_RTTWKEN);
+}
+
+MACHINE_START(USB_A9263, "CALAO USB_A9263")
+       /* Maintainer: calao-systems */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = ek_map_io,
+       .init_irq       = ek_init_irq,
+       .init_machine   = ek_board_init,
+MACHINE_END
index b571710..7079050 100755 (executable)
@@ -1,11 +1,10 @@
 /*
  * linux/arch/arm/mach-at91/board-yl-9200.c
  *
- * Adapted from:
- *various board files in
- * /arch/arm/mach-at91
- * modifications  to convert to  YL-9200 platform
- *  Copyright (C) 2007 S.Birtles
+ * Adapted from various board files in arch/arm/mach-at91
+ *
+ * Modifications for YL-9200 platform:
+ *  Copyright (C) 2007 S. Birtles
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
-/*#include <linux/can_bus/candata.h>*/
 #include <linux/spi/ads7846.h>
 #include <linux/mtd/physmap.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
 
-/*#include <sound/gpio_sounder.h>*/
 #include <asm/hardware.h>
 #include <asm/setup.h>
 #include <asm/mach-types.h>
 #include <asm/arch/board.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/at91rm9200_mc.h>
-#include <linux/gpio_keys.h>
-#include <linux/input.h>
 
 #include "generic.h"
-#include <asm/arch/at91_pio.h>
 
-#define YL_9200_FLASH_BASE     AT91_CHIPSELECT_0
-#define YL_9200_FLASH_SIZE     0x800000
 
-/*
- * Serial port configuration.
- *    0 .. 3 = USART0 .. USART3
- *    4      = DBGU
- *atmel_usart.0: ttyS0 at MMIO 0xfefff200 (irq = 1) is a ATMEL_SERIAL
- *atmel_usart.1: ttyS1 at MMIO 0xfffc0000 (irq = 6) is a ATMEL_SERIAL
- *atmel_usart.2: ttyS2 at MMIO 0xfffc4000 (irq = 7) is a ATMEL_SERIAL
- *atmel_usart.3: ttyS3 at MMIO 0xfffc8000 (irq = 8) is a ATMEL_SERIAL
- *atmel_usart.4: ttyS4 at MMIO 0xfffcc000 (irq = 9) is a ATMEL_SERIAL
- * on the YL-9200 we are sitting at the following
- *ttyS0 at MMIO 0xfefff200 (irq = 1) is a AT91_SERIAL
- *ttyS1 at MMIO 0xfefc4000 (irq = 7) is a AT91_SERIAL
- */
+static void __init yl9200_map_io(void)
+{
+       /* Initialize processor: 18.432 MHz crystal */
+       at91rm9200_initialize(18432000, AT91RM9200_PQFP);
 
-/* extern void __init yl_9200_add_device_sounder(struct gpio_sounder *sounders, int nr);*/
+       /* Setup the LEDs D2=PB17 (timer), D3=PB16 (cpu) */
+       at91_init_leds(AT91_PIN_PB16, AT91_PIN_PB17);
 
-static struct at91_uart_config __initdata yl_9200_uart_config = {
-       .console_tty    = 0,                            /* ttyS0 */
-       .nr_tty         = 3,
-       .tty_map        = { 4, 1, 0, -1, -1 }           /* ttyS0, ..., ttyS4 */
-};
+       /* DBGU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
 
-static void __init yl_9200_map_io(void)
-{
-       /* Initialize processor: 18.432 MHz crystal */
-       /*Also initialises register clocks & gpio*/
-       at91rm9200_initialize(18432000, AT91RM9200_PQFP); /*we have a 3 bank system*/
+       /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                       | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
+                       | ATMEL_UART_RI);
 
-       /* Setup the serial ports and console */
-       at91_init_serial(&yl_9200_uart_config);
+       /* USART0 on ttyS2. (Rx & Tx only to JP3) */
+       at91_register_uart(AT91RM9200_ID_US0, 2, 0);
 
-       /* Setup the LEDs D2=PB17,D3=PB16 */
-       at91_init_leds(AT91_PIN_PB16,AT91_PIN_PB17); /*cpu-led,timer-led*/
+       /* USART3 on ttyS3. (Rx, Tx, RTS - RS485 interface) */
+       at91_register_uart(AT91RM9200_ID_US3, 3, ATMEL_UART_RTS);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
 }
 
-static void __init yl_9200_init_irq(void)
+static void __init yl9200_init_irq(void)
 {
        at91rm9200_init_interrupts(NULL);
 }
 
-static struct at91_eth_data __initdata yl_9200_eth_data = {
-       .phy_irq_pin    = AT91_PIN_PB28,
-       .is_rmii        = 1,
-};
 
-static struct at91_usbh_data __initdata yl_9200_usbh_data = {
-       .ports          = 1,  /* this should be 1 not 2 for the Yl9200*/
+/*
+ * LEDs
+ */
+static struct gpio_led yl9200_leds[] = {
+       {       /* D2 */
+               .name                   = "led2",
+               .gpio                   = AT91_PIN_PB17,
+               .active_low             = 1,
+               .default_trigger        = "timer",
+       },
+       {       /* D3 */
+               .name                   = "led3",
+               .gpio                   = AT91_PIN_PB16,
+               .active_low             = 1,
+               .default_trigger        = "heartbeat",
+       },
+       {       /* D4 */
+               .name                   = "led4",
+               .gpio                   = AT91_PIN_PB15,
+               .active_low             = 1,
+       },
+       {       /* D5 */
+               .name                   = "led5",
+               .gpio                   = AT91_PIN_PB8,
+               .active_low             = 1,
+       }
 };
 
-static struct at91_udc_data __initdata yl_9200_udc_data = {
-/*on sheet 7 Schemitic rev 1.0*/
-       .pullup_pin     = AT91_PIN_PC4,
-       .vbus_pin=  AT91_PIN_PC5,
-       .pullup_active_low = 1, /*ACTIVE LOW!! due to PNP transistor on page 7*/
-
-};
 /*
-static struct at91_cf_data __initdata yl_9200_cf_data = {
-TODO S.BIRTLES
-       .det_pin        = AT91_PIN_xxx,
-       .rst_pin        = AT91_PIN_xxx,
-       .irq_pin        = ... not connected
-       .vcc_pin        = ... always powered
-
+ * Ethernet
+ */
+static struct at91_eth_data __initdata yl9200_eth_data = {
+       .phy_irq_pin            = AT91_PIN_PB28,
+       .is_rmii                = 1,
 };
-*/
-static struct at91_mmc_data __initdata yl_9200_mmc_data = {
-       .det_pin        = AT91_PIN_PB9, /*THIS LOOKS CORRECT SHEET7*/
-/*     .wp_pin         = ... not connected  SHEET7*/
-       .slot_b         = 0,
-       .wire4          = 1,
 
+/*
+ * USB Host
+ */
+static struct at91_usbh_data __initdata yl9200_usbh_data = {
+       .ports                  = 1,    /* PQFP version of AT91RM9200 */
 };
 
-/* --------------------------------------------------------------------
- *  Touch screen
- * -------------------------------------------------------------------- */
-#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
-static int ads7843_pendown_state(void)
-{
-       return !at91_get_gpio_value(AT91_PIN_PB11);     /* Touchscreen PENIRQ */
-}
-
-static void __init at91_init_device_ts(void)
-{
-/*IMPORTANT NOTE THE SPI INTERFACE IS ALREADY CONFIGURED BY XXX_DEVICES.C
-THAT IS TO SAY THAT  MISO,MOSI,SPCK AND CS  are already configured
-we only need to enable the other datapins which are:
-PB10/RK1 BUSY
-*/
-/* Touchscreen BUSY signal ,  pin,use pullup ( TODO not currently used in the ADS7843/6.c driver)*/
-at91_set_gpio_input(AT91_PIN_PB10, 1);
-}
-
-#else
-static void __init at91_init_device_ts(void) {}
-#endif
-
-static struct ads7846_platform_data ads_info = {
-       .model                  = 7843,
-       .x_min                  = 150,
-       .x_max                  = 3830,
-       .y_min                  = 190,
-       .y_max                  = 3830,
-       .vref_delay_usecs       = 100,
-/* for a 8" touch screen*/
-       //.x_plate_ohms         = 603, //= 450, S.Birtles TODO
-       //.y_plate_ohms         = 332, //= 250, S.Birtles TODO
-/*for a 10.4" touch screen*/
-       //.x_plate_ohms         =611,
-       //.y_plate_ohms         =325,
-
-       .x_plate_ohms   = 576,
-       .y_plate_ohms   = 366,
-               //
-       .pressure_max           = 15000, /*generally nonsense on the 7843*/
-        /*number of times to send query to chip in a given run 0 equals one time (do not set to 0!! ,there is a bug in ADS 7846 code)*/
-       .debounce_max           = 1,
-       .debounce_rep           = 0,
-       .debounce_tol           = (~0),
-       .get_pendown_state      = ads7843_pendown_state,
-};
+/*
+ * USB Device
+ */
+static struct at91_udc_data __initdata yl9200_udc_data = {
+       .pullup_pin             = AT91_PIN_PC4,
+       .vbus_pin               = AT91_PIN_PC5,
+       .pullup_active_low      = 1,    /* Active Low due to PNP transistor (pg 7) */
 
-/*static struct canbus_platform_data can_info = {
-       .model                  = 2510,
 };
-*/
-
-static struct spi_board_info yl_9200_spi_devices[] = {
-/*this sticks it at:
- /sys/devices/platform/atmel_spi.0/spi0.0
- /sys/bus/platform/devices/
-Documentation/spi IIRC*/
 
-#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
- /*(this IS correct 04-NOV-2007)*/
-       {
-               .modalias               = "ads7846", /* because the driver is called ads7846*/
-               .chip_select    = 0, /*THIS MUST BE AN INDEX INTO AN ARRAY OF  pins */
-/*this is ONLY TO BE USED if chipselect above is not used, it passes a pin directly for the chip select*/
-               /*.controller_data =AT91_PIN_PA3 ,*/
-               .max_speed_hz   = 5000*26, /*(4700 * 26)-125000 * 26, (max sample rate @ 3V) * (cmd + data + overhead) */
-               .bus_num                = 0,
-               .platform_data  = &ads_info,
-               .irq                    = AT91_PIN_PB11,
-       },
-#endif
-/*we need to put our CAN driver data here!!*/
-/*THIS IS ALL DUMMY DATA*/
-/*     {
-               .modalias               = "mcp2510", //DUMMY for MCP2510 chip
-               .chip_select    = 1,*/ /*THIS MUST BE AN INDEX INTO AN ARRAY OF  pins */
-       /*this is ONLY TO BE USED if chipselect above is not used, it passes a pin directly for the chip select */
-       /*  .controller_data =AT91_PIN_PA4 ,
-               .max_speed_hz   = 25000 * 26,
-               .bus_num                = 0,
-               .platform_data  = &can_info,
-               .irq                    = AT91_PIN_PC0,
-       },
-       */
-       //max SPI chip needs to go here
+/*
+ * MMC
+ */
+static struct at91_mmc_data __initdata yl9200_mmc_data = {
+       .det_pin        = AT91_PIN_PB9,
+       // .wp_pin      = ... not connected
+       .wire4          = 1,
 };
 
-static struct mtd_partition __initdata yl_9200_nand_partition[] = {
+/*
+ * NAND Flash
+ */
+static struct mtd_partition __initdata yl9200_nand_partition[] = {
        {
                .name   = "AT91 NAND partition 1, boot",
                .offset = 0,
@@ -242,442 +171,434 @@ static struct mtd_partition __initdata yl_9200_nand_partition[] = {
                .name   = "AT91 NAND partition 5, ext-fs",
                .offset = 32 * SZ_1M,
                .size   = 32 * SZ_1M
-       },
+       }
 };
 
 static struct mtd_partition * __init nand_partitions(int size, int *num_partitions)
 {
-       *num_partitions = ARRAY_SIZE(yl_9200_nand_partition);
-       return yl_9200_nand_partition;
+       *num_partitions = ARRAY_SIZE(yl9200_nand_partition);
+       return yl9200_nand_partition;
 }
 
-static struct at91_nand_data __initdata yl_9200_nand_data = {
-       .ale= 6,
-       .cle= 7,
-       /*.det_pin      = AT91_PIN_PCxx,*/   /*we don't have a det pin because NandFlash is fixed to board*/
-       .rdy_pin        = AT91_PIN_PC14,  /*R/!B Sheet10*/
-       .enable_pin     = AT91_PIN_PC15,  /*!CE  Sheet10 */
+static struct at91_nand_data __initdata yl9200_nand_data = {
+       .ale            = 6,
+       .cle            = 7,
+       // .det_pin     = ... not connected
+       .rdy_pin        = AT91_PIN_PC14,        /* R/!B (Sheet10) */
+       .enable_pin     = AT91_PIN_PC15,        /* !CE  (Sheet10) */
        .partition_info = nand_partitions,
 };
 
-
-
 /*
-TODO S.Birtles
-potentially a problem with the size above
-physmap platform flash device: 00800000 at 10000000
-physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank
-NOR chip too large to fit in mapping. Attempting to cope...
- Intel/Sharp Extended Query Table at 0x0031
-Using buffer write method
-cfi_cmdset_0001: Erase suspend on write enabled
-Reducing visibility of 16384KiB chip to 8192KiB
-*/
+ * NOR Flash
+ */
+#define YL9200_FLASH_BASE      AT91_CHIPSELECT_0
+#define YL9200_FLASH_SIZE      0x1000000
 
-static struct mtd_partition yl_9200_flash_partitions[] = {
+static struct mtd_partition yl9200_flash_partitions[] = {
+       {
+               .name           = "Bootloader",
+               .size           = 0x00040000,
+               .offset         = 0,
+               .mask_flags     = MTD_WRITEABLE,        /* force read-only */
+       },
        {
-               .name =         "Bootloader",
-               .size =         0x00040000,
-               .offset =       0,
-               .mask_flags =   MTD_WRITEABLE  /* force read-only */
-       },{
-               .name =         "Kernel",
-               .size =         0x001C0000,
-               .offset =       0x00040000,
-       },{
-               .name =         "Filesystem",
-               .size =         MTDPART_SIZ_FULL,
-               .offset =       0x00200000
+               .name           = "Kernel",
+               .size           = 0x001C0000,
+               .offset         = 0x00040000,
+       },
+       {
+               .name           = "Filesystem",
+               .size           = MTDPART_SIZ_FULL,
+               .offset         = 0x00200000
        }
-
 };
 
-static struct physmap_flash_data yl_9200_flash_data = {
-       .width  = 2,
-       .parts          = yl_9200_flash_partitions,
-       .nr_parts       = ARRAY_SIZE(yl_9200_flash_partitions),
+static struct physmap_flash_data yl9200_flash_data = {
+       .width          = 2,
+       .parts          = yl9200_flash_partitions,
+       .nr_parts       = ARRAY_SIZE(yl9200_flash_partitions),
 };
 
-static struct resource yl_9200_flash_resources[] = {
-{
-       .start          = YL_9200_FLASH_BASE,
-       .end            = YL_9200_FLASH_BASE + YL_9200_FLASH_SIZE - 1,
-       .flags          = IORESOURCE_MEM,
+static struct resource yl9200_flash_resources[] = {
+       {
+               .start  = YL9200_FLASH_BASE,
+               .end    = YL9200_FLASH_BASE + YL9200_FLASH_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
        }
 };
 
-static struct platform_device yl_9200_flash = {
+static struct platform_device yl9200_flash = {
        .name           = "physmap-flash",
        .id             = 0,
        .dev            = {
-                               .platform_data  = &yl_9200_flash_data,
+                               .platform_data  = &yl9200_flash_data,
                        },
-       .resource       = yl_9200_flash_resources,
-       .num_resources  = ARRAY_SIZE(yl_9200_flash_resources),
+       .resource       = yl9200_flash_resources,
+       .num_resources  = ARRAY_SIZE(yl9200_flash_resources),
 };
 
-
-static struct gpio_led yl_9200_leds[] = {
-/*D2 &D3 are passed directly in via at91_init_leds*/
-       {
-               .name                   = "led4",  /*D4*/
-               .gpio                   = AT91_PIN_PB15,
-               .active_low             = 1,
-               .default_trigger        = "heartbeat",
-               /*.default_trigger      = "timer",*/
-       },
-       {
-               .name                   = "led5",  /*D5*/
-               .gpio                   = AT91_PIN_PB8,
-               .active_low             = 1,
-               .default_trigger        = "heartbeat",
-       }
-};
-
-//static struct gpio_sounder yl_9200_sounder[] = {*/
-/*This is a simple speaker attached to a gpo line*/
-
-//     {
-//             .name                   = "Speaker",  /*LS1*/
-//             .gpio                   = AT91_PIN_PA22,
-//             .active_low             = 0,
-//             .default_trigger        = "heartbeat",
-               /*.default_trigger      = "timer",*/
-//     },
-//};
-
-
-
-static struct i2c_board_info __initdata yl_9200_i2c_devices[] = {
-       {
-       /*TODO*/
-               I2C_BOARD_INFO("CS4334", 0x00),
+/*
+ * I2C (TWI)
+ */
+static struct i2c_board_info __initdata yl9200_i2c_devices[] = {
+       {       /* EEPROM */
+               I2C_BOARD_INFO("24c128", 0x50),
        }
 };
 
-
- /*
+/*
  * GPIO Buttons
- */
+*/
 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
-static struct gpio_keys_button yl_9200_buttons[] = {
+static struct gpio_keys_button yl9200_buttons[] = {
        {
                .gpio           = AT91_PIN_PA24,
-               .code   = BTN_2,
+               .code           = BTN_2,
                .desc           = "SW2",
                .active_low     = 1,
                .wakeup         = 1,
        },
        {
                .gpio           = AT91_PIN_PB1,
-               .code   = BTN_3,
+               .code           = BTN_3,
                .desc           = "SW3",
                .active_low     = 1,
                .wakeup         = 1,
        },
        {
                .gpio           = AT91_PIN_PB2,
-               .code   = BTN_4,
+               .code           = BTN_4,
                .desc           = "SW4",
                .active_low     = 1,
                .wakeup         = 1,
        },
        {
                .gpio           = AT91_PIN_PB6,
-               .code   = BTN_5,
+               .code           = BTN_5,
                .desc           = "SW5",
                .active_low     = 1,
                .wakeup         = 1,
-       },
-
+       }
 };
 
-static struct gpio_keys_platform_data yl_9200_button_data = {
-       .buttons        = yl_9200_buttons,
-       .nbuttons       = ARRAY_SIZE(yl_9200_buttons),
+static struct gpio_keys_platform_data yl9200_button_data = {
+       .buttons        = yl9200_buttons,
+       .nbuttons       = ARRAY_SIZE(yl9200_buttons),
 };
 
-static struct platform_device yl_9200_button_device = {
+static struct platform_device yl9200_button_device = {
        .name           = "gpio-keys",
        .id             = -1,
        .num_resources  = 0,
        .dev            = {
-       .platform_data  = &yl_9200_button_data,
+               .platform_data  = &yl9200_button_data,
        }
 };
 
-static void __init yl_9200_add_device_buttons(void)
+static void __init yl9200_add_device_buttons(void)
 {
-       //SW2
-       at91_set_gpio_input(AT91_PIN_PA24, 0);
+       at91_set_gpio_input(AT91_PIN_PA24, 1);  /* SW2 */
        at91_set_deglitch(AT91_PIN_PA24, 1);
-
-       //SW3
-       at91_set_gpio_input(AT91_PIN_PB1, 0);
+       at91_set_gpio_input(AT91_PIN_PB1, 1);   /* SW3 */
        at91_set_deglitch(AT91_PIN_PB1, 1);
-       //SW4
-       at91_set_gpio_input(AT91_PIN_PB2, 0);
+       at91_set_gpio_input(AT91_PIN_PB2, 1);   /* SW4 */
        at91_set_deglitch(AT91_PIN_PB2, 1);
-
-       //SW5
-       at91_set_gpio_input(AT91_PIN_PB6, 0);
+       at91_set_gpio_input(AT91_PIN_PB6, 1);   /* SW5 */
        at91_set_deglitch(AT91_PIN_PB6, 1);
 
+       /* Enable buttons (Sheet 5) */
+       at91_set_gpio_output(AT91_PIN_PB7, 1);
+
+       platform_device_register(&yl9200_button_device);
+}
+#else
+static void __init yl9200_add_device_buttons(void) {}
+#endif
+
+/*
+ * Touchscreen
+ */
+#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
+static int ads7843_pendown_state(void)
+{
+       return !at91_get_gpio_value(AT91_PIN_PB11);     /* Touchscreen PENIRQ */
+}
+
+static struct ads7846_platform_data ads_info = {
+       .model                  = 7843,
+       .x_min                  = 150,
+       .x_max                  = 3830,
+       .y_min                  = 190,
+       .y_max                  = 3830,
+       .vref_delay_usecs       = 100,
+
+       /* For a 8" touch-screen */
+       // .x_plate_ohms                = 603,
+       // .y_plate_ohms                = 332,
+
+       /* For a 10.4" touch-screen */
+       // .x_plate_ohms                = 611,
+       // .y_plate_ohms                = 325,
+
+       .x_plate_ohms           = 576,
+       .y_plate_ohms           = 366,
+
+       .pressure_max           = 15000, /* generally nonsense on the 7843 */
+       .debounce_max           = 1,
+       .debounce_rep           = 0,
+       .debounce_tol           = (~0),
+       .get_pendown_state      = ads7843_pendown_state,
+};
 
-       at91_set_gpio_output(AT91_PIN_PB7, 1);  /* #TURN BUTTONS ON, SHEET 5  of schematics */
-       platform_device_register(&yl_9200_button_device);
+static void __init yl9200_add_device_ts(void)
+{
+       at91_set_gpio_input(AT91_PIN_PB11, 1);  /* Touchscreen interrupt pin */
+       at91_set_gpio_input(AT91_PIN_PB10, 1);  /* Touchscreen BUSY signal - not used! */
 }
 #else
-static void __init yl_9200_add_device_buttons(void) {}
+static void __init yl9200_add_device_ts(void) {}
+#endif
+
+/*
+ * SPI devices
+ */
+static struct spi_board_info yl9200_spi_devices[] = {
+#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
+       {       /* Touchscreen */
+               .modalias       = "ads7846",
+               .chip_select    = 0,
+               .max_speed_hz   = 5000 * 26,
+               .platform_data  = &ads_info,
+               .irq            = AT91_PIN_PB11,
+       },
 #endif
+       {       /* CAN */
+               .modalias       = "mcp2510",
+               .chip_select    = 1,
+               .max_speed_hz   = 25000 * 26,
+               .irq            = AT91_PIN_PC0,
+       }
+};
 
+/*
+ * LCD / VGA
+ *
+ * EPSON S1D13806 FB (discontinued chip)
+ * EPSON S1D13506 FB
+ */
 #if defined(CONFIG_FB_S1D135XX) || defined(CONFIG_FB_S1D13XXX_MODULE)
 #include <video/s1d13xxxfb.h>
 
-/* EPSON S1D13806 FB (discontinued chip)*/
-/* EPSON S1D13506 FB */
-
 #define AT91_FB_REG_BASE       0x80000000L
 #define AT91_FB_REG_SIZE       0x200
 #define AT91_FB_VMEM_BASE      0x80200000L
 #define AT91_FB_VMEM_SIZE      0x200000L
 
-/*#define S1D_DISPLAY_WIDTH           640*/
-/*#define S1D_DISPLAY_HEIGHT          480*/
-
-
-static void __init yl_9200_init_video(void)
+static void __init yl9200_init_video(void)
 {
-       at91_sys_write(AT91_PIOC + PIO_ASR,AT91_PIN_PC6);
-       at91_sys_write(AT91_PIOC + PIO_BSR,0);
-       at91_sys_write(AT91_PIOC + PIO_ASR,AT91_PIN_PC6);
-
-       at91_sys_write( AT91_SMC_CSR(2),
-       AT91_SMC_NWS_(0x4) |
-       AT91_SMC_WSEN |
-       AT91_SMC_TDF_(0x100) |
-       AT91_SMC_DBW
-       );
-
-
+       /* NWAIT Signal */
+       at91_set_A_periph(AT91_PIN_PC6, 0);
 
+       /* Initialization of the Static Memory Controller for Chip Select 2 */
+       at91_sys_write(AT91_SMC_CSR(2), AT91_SMC_DBW_16         /* 16 bit */
+                       | AT91_SMC_WSEN | AT91_SMC_NWS_(0x4)    /* wait states */
+                       | AT91_SMC_TDF_(0x100)                  /* float time */
+       );
 }
 
-
-static struct s1d13xxxfb_regval yl_9200_s1dfb_initregs[] =
+static struct s1d13xxxfb_regval yl9200_s1dfb_initregs[] =
 {
-       {S1DREG_MISC,                           0x00},   /* Miscellaneous Register*/
-       {S1DREG_COM_DISP_MODE,          0x01},   /* Display Mode Register, LCD only*/
-       {S1DREG_GPIO_CNF0,                      0x00},   /* General IO Pins Configuration Register*/
-       {S1DREG_GPIO_CTL0,                      0x00},   /* General IO Pins Control Register*/
-       {S1DREG_CLK_CNF,                        0x11},   /* Memory Clock Configuration Register*/
-       {S1DREG_LCD_CLK_CNF,            0x10},   /* LCD Pixel Clock Configuration Register*/
-       {S1DREG_CRT_CLK_CNF,            0x12},   /* CRT/TV Pixel Clock Configuration Register*/
-       {S1DREG_MPLUG_CLK_CNF,          0x01},   /* MediaPlug Clock Configuration Register*/
-       {S1DREG_CPU2MEM_WST_SEL,        0x02},   /* CPU To Memory Wait State Select Register*/
-       {S1DREG_MEM_CNF,                        0x00},   /* Memory Configuration Register*/
-       {S1DREG_SDRAM_REF_RATE,         0x04},   /* DRAM Refresh Rate Register, MCLK source*/
-       {S1DREG_SDRAM_TC0,                      0x12},   /* DRAM Timings Control Register 0*/
-       {S1DREG_SDRAM_TC1,                      0x02},   /* DRAM Timings Control Register 1*/
-       {S1DREG_PANEL_TYPE,                     0x25},   /* Panel Type Register*/
-       {S1DREG_MOD_RATE,                       0x00},   /* MOD Rate Register*/
-       {S1DREG_LCD_DISP_HWIDTH,        0x4F},   /* LCD Horizontal Display Width Register*/
-       {S1DREG_LCD_NDISP_HPER,         0x13},   /* LCD Horizontal Non-Display Period Register*/
-       {S1DREG_TFT_FPLINE_START,       0x01},   /* TFT FPLINE Start Position Register*/
-       {S1DREG_TFT_FPLINE_PWIDTH,      0x0c},   /* TFT FPLINE Pulse Width Register*/
-       {S1DREG_LCD_DISP_VHEIGHT0,      0xDF},   /* LCD Vertical Display Height Register 0*/
-       {S1DREG_LCD_DISP_VHEIGHT1,      0x01},   /* LCD Vertical Display Height Register 1*/
-       {S1DREG_LCD_NDISP_VPER,         0x2c},   /* LCD Vertical Non-Display Period Register*/
-       {S1DREG_TFT_FPFRAME_START,      0x0a},   /* TFT FPFRAME Start Position Register*/
-       {S1DREG_TFT_FPFRAME_PWIDTH,     0x02},   /* TFT FPFRAME Pulse Width Register*/
-       {S1DREG_LCD_DISP_MODE,          0x05},   /* LCD Display Mode Register*/
-       {S1DREG_LCD_MISC,                       0x01},   /* LCD Miscellaneous Register*/
-       {S1DREG_LCD_DISP_START0,        0x00},   /* LCD Display Start Address Register 0*/
-       {S1DREG_LCD_DISP_START1,        0x00},   /* LCD Display Start Address Register 1*/
-       {S1DREG_LCD_DISP_START2,        0x00},   /* LCD Display Start Address Register 2*/
-       {S1DREG_LCD_MEM_OFF0,           0x80},   /* LCD Memory Address Offset Register 0*/
-       {S1DREG_LCD_MEM_OFF1,           0x02},   /* LCD Memory Address Offset Register 1*/
-       {S1DREG_LCD_PIX_PAN,            0x03},   /* LCD Pixel Panning Register*/
-       {S1DREG_LCD_DISP_FIFO_HTC,      0x00},   /* LCD Display FIFO High Threshold Control Register*/
-       {S1DREG_LCD_DISP_FIFO_LTC,      0x00},   /* LCD Display FIFO Low Threshold Control Register*/
-       {S1DREG_CRT_DISP_HWIDTH,        0x4F},   /* CRT/TV Horizontal Display Width Register*/
-       {S1DREG_CRT_NDISP_HPER,         0x13},   /* CRT/TV Horizontal Non-Display Period Register*/
-       {S1DREG_CRT_HRTC_START,         0x01},   /* CRT/TV HRTC Start Position Register*/
-       {S1DREG_CRT_HRTC_PWIDTH,        0x0B},   /* CRT/TV HRTC Pulse Width Register*/
-       {S1DREG_CRT_DISP_VHEIGHT0,      0xDF},   /* CRT/TV Vertical Display Height Register 0*/
-       {S1DREG_CRT_DISP_VHEIGHT1,      0x01},   /* CRT/TV Vertical Display Height Register 1*/
-       {S1DREG_CRT_NDISP_VPER,         0x2B},   /* CRT/TV Vertical Non-Display Period Register*/
-       {S1DREG_CRT_VRTC_START,         0x09},   /* CRT/TV VRTC Start Position Register*/
-       {S1DREG_CRT_VRTC_PWIDTH,        0x01},   /* CRT/TV VRTC Pulse Width Register*/
-       {S1DREG_TV_OUT_CTL,                     0x18},   /* TV Output Control Register */
-       {S1DREG_CRT_DISP_MODE,          0x05},   /* CRT/TV Display Mode Register, 16BPP*/
-       {S1DREG_CRT_DISP_START0,        0x00},   /* CRT/TV Display Start Address Register 0*/
-       {S1DREG_CRT_DISP_START1,        0x00},   /* CRT/TV Display Start Address Register 1*/
-       {S1DREG_CRT_DISP_START2,        0x00},   /* CRT/TV Display Start Address Register 2*/
-       {S1DREG_CRT_MEM_OFF0,           0x80},   /* CRT/TV Memory Address Offset Register 0*/
-       {S1DREG_CRT_MEM_OFF1,           0x02},   /* CRT/TV Memory Address Offset Register 1*/
-       {S1DREG_CRT_PIX_PAN,            0x00},   /* CRT/TV Pixel Panning Register*/
-       {S1DREG_CRT_DISP_FIFO_HTC,      0x00},   /* CRT/TV Display FIFO High Threshold Control Register*/
-       {S1DREG_CRT_DISP_FIFO_LTC,      0x00},   /* CRT/TV Display FIFO Low Threshold Control Register*/
-       {S1DREG_LCD_CUR_CTL,            0x00},   /* LCD Ink/Cursor Control Register*/
-       {S1DREG_LCD_CUR_START,          0x01},   /* LCD Ink/Cursor Start Address Register*/
-       {S1DREG_LCD_CUR_XPOS0,          0x00},   /* LCD Cursor X Position Register 0*/
-       {S1DREG_LCD_CUR_XPOS1,          0x00},   /* LCD Cursor X Position Register 1*/
-       {S1DREG_LCD_CUR_YPOS0,          0x00},   /* LCD Cursor Y Position Register 0*/
-       {S1DREG_LCD_CUR_YPOS1,          0x00},   /* LCD Cursor Y Position Register 1*/
-       {S1DREG_LCD_CUR_BCTL0,          0x00},   /* LCD Ink/Cursor Blue Color 0 Register*/
-       {S1DREG_LCD_CUR_GCTL0,          0x00},   /* LCD Ink/Cursor Green Color 0 Register*/
-       {S1DREG_LCD_CUR_RCTL0,          0x00},   /* LCD Ink/Cursor Red Color 0 Register*/
-       {S1DREG_LCD_CUR_BCTL1,          0x1F},   /* LCD Ink/Cursor Blue Color 1 Register*/
-       {S1DREG_LCD_CUR_GCTL1,          0x3F},   /* LCD Ink/Cursor Green Color 1 Register*/
-       {S1DREG_LCD_CUR_RCTL1,          0x1F},   /* LCD Ink/Cursor Red Color 1 Register*/
-       {S1DREG_LCD_CUR_FIFO_HTC,       0x00},   /* LCD Ink/Cursor FIFO Threshold Register*/
-       {S1DREG_CRT_CUR_CTL,            0x00},   /* CRT/TV Ink/Cursor Control Register*/
-       {S1DREG_CRT_CUR_START,          0x01},   /* CRT/TV Ink/Cursor Start Address Register*/
-       {S1DREG_CRT_CUR_XPOS0,          0x00},   /* CRT/TV Cursor X Position Register 0*/
-       {S1DREG_CRT_CUR_XPOS1,          0x00},   /* CRT/TV Cursor X Position Register 1*/
-       {S1DREG_CRT_CUR_YPOS0,          0x00},   /* CRT/TV Cursor Y Position Register 0*/
-       {S1DREG_CRT_CUR_YPOS1,          0x00},   /* CRT/TV Cursor Y Position Register 1*/
-       {S1DREG_CRT_CUR_BCTL0,          0x00},   /* CRT/TV Ink/Cursor Blue Color 0 Register*/
-       {S1DREG_CRT_CUR_GCTL0,          0x00},   /* CRT/TV Ink/Cursor Green Color 0 Register*/
-       {S1DREG_CRT_CUR_RCTL0,          0x00},   /* CRT/TV Ink/Cursor Red Color 0 Register*/
-       {S1DREG_CRT_CUR_BCTL1,          0x1F},   /* CRT/TV Ink/Cursor Blue Color 1 Register*/
-       {S1DREG_CRT_CUR_GCTL1,          0x3F},   /* CRT/TV Ink/Cursor Green Color 1 Register*/
-       {S1DREG_CRT_CUR_RCTL1,          0x1F},   /* CRT/TV Ink/Cursor Red Color 1 Register*/
-       {S1DREG_CRT_CUR_FIFO_HTC,       0x00},   /* CRT/TV Ink/Cursor FIFO Threshold Register*/
-       {S1DREG_BBLT_CTL0,                      0x00},   /* BitBlt Control Register 0*/
-       {S1DREG_BBLT_CTL1,                      0x01},   /* BitBlt Control Register 1*/
-       {S1DREG_BBLT_CC_EXP,            0x00},   /* BitBlt ROP Code/Color Expansion Register*/
-       {S1DREG_BBLT_OP,                        0x00},   /* BitBlt Operation Register*/
-       {S1DREG_BBLT_SRC_START0,        0x00},   /* BitBlt Source Start Address Register 0*/
-       {S1DREG_BBLT_SRC_START1,        0x00},   /* BitBlt Source Start Address Register 1*/
-       {S1DREG_BBLT_SRC_START2,        0x00},   /* BitBlt Source Start Address Register 2*/
-       {S1DREG_BBLT_DST_START0,        0x00},   /* BitBlt Destination Start Address Register 0*/
-       {S1DREG_BBLT_DST_START1,        0x00},   /* BitBlt Destination Start Address Register 1*/
-       {S1DREG_BBLT_DST_START2,        0x00},   /* BitBlt Destination Start Address Register 2*/
-       {S1DREG_BBLT_MEM_OFF0,          0x00},   /* BitBlt Memory Address Offset Register 0*/
-       {S1DREG_BBLT_MEM_OFF1,          0x00},   /* BitBlt Memory Address Offset Register 1*/
-       {S1DREG_BBLT_WIDTH0,            0x00},   /* BitBlt Width Register 0*/
-       {S1DREG_BBLT_WIDTH1,            0x00},   /* BitBlt Width Register 1*/
-       {S1DREG_BBLT_HEIGHT0,           0x00},   /* BitBlt Height Register 0*/
-       {S1DREG_BBLT_HEIGHT1,           0x00},   /* BitBlt Height Register 1*/
-       {S1DREG_BBLT_BGC0,                      0x00},   /* BitBlt Background Color Register 0*/
-       {S1DREG_BBLT_BGC1,                      0x00},   /* BitBlt Background Color Register 1*/
-       {S1DREG_BBLT_FGC0,                      0x00},   /* BitBlt Foreground Color Register 0*/
-       {S1DREG_BBLT_FGC1,                      0x00},   /* BitBlt Foreground Color Register 1*/
-       {S1DREG_LKUP_MODE,                      0x00},   /* Look-Up Table Mode Register*/
-       {S1DREG_LKUP_ADDR,                      0x00},   /* Look-Up Table Address Register*/
-       {S1DREG_PS_CNF,                         0x00},   /* Power Save Configuration Register*/
-       {S1DREG_PS_STATUS,                      0x00},   /* Power Save Status Register*/
-       {S1DREG_CPU2MEM_WDOGT,          0x00},   /* CPU-to-Memory Access Watchdog Timer Register*/
-       {S1DREG_COM_DISP_MODE,          0x01},   /* Display Mode Register, LCD only*/
+       {S1DREG_MISC,                   0x00},  /* Miscellaneous Register*/
+       {S1DREG_COM_DISP_MODE,          0x01},  /* Display Mode Register, LCD only*/
+       {S1DREG_GPIO_CNF0,              0x00},  /* General IO Pins Configuration Register*/
+       {S1DREG_GPIO_CTL0,              0x00},  /* General IO Pins Control Register*/
+       {S1DREG_CLK_CNF,                0x11},  /* Memory Clock Configuration Register*/
+       {S1DREG_LCD_CLK_CNF,            0x10},  /* LCD Pixel Clock Configuration Register*/
+       {S1DREG_CRT_CLK_CNF,            0x12},  /* CRT/TV Pixel Clock Configuration Register*/
+       {S1DREG_MPLUG_CLK_CNF,          0x01},  /* MediaPlug Clock Configuration Register*/
+       {S1DREG_CPU2MEM_WST_SEL,        0x02},  /* CPU To Memory Wait State Select Register*/
+       {S1DREG_MEM_CNF,                0x00},  /* Memory Configuration Register*/
+       {S1DREG_SDRAM_REF_RATE,         0x04},  /* DRAM Refresh Rate Register, MCLK source*/
+       {S1DREG_SDRAM_TC0,              0x12},  /* DRAM Timings Control Register 0*/
+       {S1DREG_SDRAM_TC1,              0x02},  /* DRAM Timings Control Register 1*/
+       {S1DREG_PANEL_TYPE,             0x25},  /* Panel Type Register*/
+       {S1DREG_MOD_RATE,               0x00},  /* MOD Rate Register*/
+       {S1DREG_LCD_DISP_HWIDTH,        0x4F},  /* LCD Horizontal Display Width Register*/
+       {S1DREG_LCD_NDISP_HPER,         0x13},  /* LCD Horizontal Non-Display Period Register*/
+       {S1DREG_TFT_FPLINE_START,       0x01},  /* TFT FPLINE Start Position Register*/
+       {S1DREG_TFT_FPLINE_PWIDTH,      0x0c},  /* TFT FPLINE Pulse Width Register*/
+       {S1DREG_LCD_DISP_VHEIGHT0,      0xDF},  /* LCD Vertical Display Height Register 0*/
+       {S1DREG_LCD_DISP_VHEIGHT1,      0x01},  /* LCD Vertical Display Height Register 1*/
+       {S1DREG_LCD_NDISP_VPER,         0x2c},  /* LCD Vertical Non-Display Period Register*/
+       {S1DREG_TFT_FPFRAME_START,      0x0a},  /* TFT FPFRAME Start Position Register*/
+       {S1DREG_TFT_FPFRAME_PWIDTH,     0x02},  /* TFT FPFRAME Pulse Width Register*/
+       {S1DREG_LCD_DISP_MODE,          0x05},  /* LCD Display Mode Register*/
+       {S1DREG_LCD_MISC,               0x01},  /* LCD Miscellaneous Register*/
+       {S1DREG_LCD_DISP_START0,        0x00},  /* LCD Display Start Address Register 0*/
+       {S1DREG_LCD_DISP_START1,        0x00},  /* LCD Display Start Address Register 1*/
+       {S1DREG_LCD_DISP_START2,        0x00},  /* LCD Display Start Address Register 2*/
+       {S1DREG_LCD_MEM_OFF0,           0x80},  /* LCD Memory Address Offset Register 0*/
+       {S1DREG_LCD_MEM_OFF1,           0x02},  /* LCD Memory Address Offset Register 1*/
+       {S1DREG_LCD_PIX_PAN,            0x03},  /* LCD Pixel Panning Register*/
+       {S1DREG_LCD_DISP_FIFO_HTC,      0x00},  /* LCD Display FIFO High Threshold Control Register*/
+       {S1DREG_LCD_DISP_FIFO_LTC,      0x00},  /* LCD Display FIFO Low Threshold Control Register*/
+       {S1DREG_CRT_DISP_HWIDTH,        0x4F},  /* CRT/TV Horizontal Display Width Register*/
+       {S1DREG_CRT_NDISP_HPER,         0x13},  /* CRT/TV Horizontal Non-Display Period Register*/
+       {S1DREG_CRT_HRTC_START,         0x01},  /* CRT/TV HRTC Start Position Register*/
+       {S1DREG_CRT_HRTC_PWIDTH,        0x0B},  /* CRT/TV HRTC Pulse Width Register*/
+       {S1DREG_CRT_DISP_VHEIGHT0,      0xDF},  /* CRT/TV Vertical Display Height Register 0*/
+       {S1DREG_CRT_DISP_VHEIGHT1,      0x01},  /* CRT/TV Vertical Display Height Register 1*/
+       {S1DREG_CRT_NDISP_VPER,         0x2B},  /* CRT/TV Vertical Non-Display Period Register*/
+       {S1DREG_CRT_VRTC_START,         0x09},  /* CRT/TV VRTC Start Position Register*/
+       {S1DREG_CRT_VRTC_PWIDTH,        0x01},  /* CRT/TV VRTC Pulse Width Register*/
+       {S1DREG_TV_OUT_CTL,             0x18},  /* TV Output Control Register */
+       {S1DREG_CRT_DISP_MODE,          0x05},  /* CRT/TV Display Mode Register, 16BPP*/
+       {S1DREG_CRT_DISP_START0,        0x00},  /* CRT/TV Display Start Address Register 0*/
+       {S1DREG_CRT_DISP_START1,        0x00},  /* CRT/TV Display Start Address Register 1*/
+       {S1DREG_CRT_DISP_START2,        0x00},  /* CRT/TV Display Start Address Register 2*/
+       {S1DREG_CRT_MEM_OFF0,           0x80},  /* CRT/TV Memory Address Offset Register 0*/
+       {S1DREG_CRT_MEM_OFF1,           0x02},  /* CRT/TV Memory Address Offset Register 1*/
+       {S1DREG_CRT_PIX_PAN,            0x00},  /* CRT/TV Pixel Panning Register*/
+       {S1DREG_CRT_DISP_FIFO_HTC,      0x00},  /* CRT/TV Display FIFO High Threshold Control Register*/
+       {S1DREG_CRT_DISP_FIFO_LTC,      0x00},  /* CRT/TV Display FIFO Low Threshold Control Register*/
+       {S1DREG_LCD_CUR_CTL,            0x00},  /* LCD Ink/Cursor Control Register*/
+       {S1DREG_LCD_CUR_START,          0x01},  /* LCD Ink/Cursor Start Address Register*/
+       {S1DREG_LCD_CUR_XPOS0,          0x00},  /* LCD Cursor X Position Register 0*/
+       {S1DREG_LCD_CUR_XPOS1,          0x00},  /* LCD Cursor X Position Register 1*/
+       {S1DREG_LCD_CUR_YPOS0,          0x00},  /* LCD Cursor Y Position Register 0*/
+       {S1DREG_LCD_CUR_YPOS1,          0x00},  /* LCD Cursor Y Position Register 1*/
+       {S1DREG_LCD_CUR_BCTL0,          0x00},  /* LCD Ink/Cursor Blue Color 0 Register*/
+       {S1DREG_LCD_CUR_GCTL0,          0x00},  /* LCD Ink/Cursor Green Color 0 Register*/
+       {S1DREG_LCD_CUR_RCTL0,          0x00},  /* LCD Ink/Cursor Red Color 0 Register*/
+       {S1DREG_LCD_CUR_BCTL1,          0x1F},  /* LCD Ink/Cursor Blue Color 1 Register*/
+       {S1DREG_LCD_CUR_GCTL1,          0x3F},  /* LCD Ink/Cursor Green Color 1 Register*/
+       {S1DREG_LCD_CUR_RCTL1,          0x1F},  /* LCD Ink/Cursor Red Color 1 Register*/
+       {S1DREG_LCD_CUR_FIFO_HTC,       0x00},  /* LCD Ink/Cursor FIFO Threshold Register*/
+       {S1DREG_CRT_CUR_CTL,            0x00},  /* CRT/TV Ink/Cursor Control Register*/
+       {S1DREG_CRT_CUR_START,          0x01},  /* CRT/TV Ink/Cursor Start Address Register*/
+       {S1DREG_CRT_CUR_XPOS0,          0x00},  /* CRT/TV Cursor X Position Register 0*/
+       {S1DREG_CRT_CUR_XPOS1,          0x00},  /* CRT/TV Cursor X Position Register 1*/
+       {S1DREG_CRT_CUR_YPOS0,          0x00},  /* CRT/TV Cursor Y Position Register 0*/
+       {S1DREG_CRT_CUR_YPOS1,          0x00},  /* CRT/TV Cursor Y Position Register 1*/
+       {S1DREG_CRT_CUR_BCTL0,          0x00},  /* CRT/TV Ink/Cursor Blue Color 0 Register*/
+       {S1DREG_CRT_CUR_GCTL0,          0x00},  /* CRT/TV Ink/Cursor Green Color 0 Register*/
+       {S1DREG_CRT_CUR_RCTL0,          0x00},  /* CRT/TV Ink/Cursor Red Color 0 Register*/
+       {S1DREG_CRT_CUR_BCTL1,          0x1F},  /* CRT/TV Ink/Cursor Blue Color 1 Register*/
+       {S1DREG_CRT_CUR_GCTL1,          0x3F},  /* CRT/TV Ink/Cursor Green Color 1 Register*/
+       {S1DREG_CRT_CUR_RCTL1,          0x1F},  /* CRT/TV Ink/Cursor Red Color 1 Register*/
+       {S1DREG_CRT_CUR_FIFO_HTC,       0x00},  /* CRT/TV Ink/Cursor FIFO Threshold Register*/
+       {S1DREG_BBLT_CTL0,              0x00},  /* BitBlt Control Register 0*/
+       {S1DREG_BBLT_CTL1,              0x01},  /* BitBlt Control Register 1*/
+       {S1DREG_BBLT_CC_EXP,            0x00},  /* BitBlt ROP Code/Color Expansion Register*/
+       {S1DREG_BBLT_OP,                0x00},  /* BitBlt Operation Register*/
+       {S1DREG_BBLT_SRC_START0,        0x00},  /* BitBlt Source Start Address Register 0*/
+       {S1DREG_BBLT_SRC_START1,        0x00},  /* BitBlt Source Start Address Register 1*/
+       {S1DREG_BBLT_SRC_START2,        0x00},  /* BitBlt Source Start Address Register 2*/
+       {S1DREG_BBLT_DST_START0,        0x00},  /* BitBlt Destination Start Address Register 0*/
+       {S1DREG_BBLT_DST_START1,        0x00},  /* BitBlt Destination Start Address Register 1*/
+       {S1DREG_BBLT_DST_START2,        0x00},  /* BitBlt Destination Start Address Register 2*/
+       {S1DREG_BBLT_MEM_OFF0,          0x00},  /* BitBlt Memory Address Offset Register 0*/
+       {S1DREG_BBLT_MEM_OFF1,          0x00},  /* BitBlt Memory Address Offset Register 1*/
+       {S1DREG_BBLT_WIDTH0,            0x00},  /* BitBlt Width Register 0*/
+       {S1DREG_BBLT_WIDTH1,            0x00},  /* BitBlt Width Register 1*/
+       {S1DREG_BBLT_HEIGHT0,           0x00},  /* BitBlt Height Register 0*/
+       {S1DREG_BBLT_HEIGHT1,           0x00},  /* BitBlt Height Register 1*/
+       {S1DREG_BBLT_BGC0,              0x00},  /* BitBlt Background Color Register 0*/
+       {S1DREG_BBLT_BGC1,              0x00},  /* BitBlt Background Color Register 1*/
+       {S1DREG_BBLT_FGC0,              0x00},  /* BitBlt Foreground Color Register 0*/
+       {S1DREG_BBLT_FGC1,              0x00},  /* BitBlt Foreground Color Register 1*/
+       {S1DREG_LKUP_MODE,              0x00},  /* Look-Up Table Mode Register*/
+       {S1DREG_LKUP_ADDR,              0x00},  /* Look-Up Table Address Register*/
+       {S1DREG_PS_CNF,                 0x00},  /* Power Save Configuration Register*/
+       {S1DREG_PS_STATUS,              0x00},  /* Power Save Status Register*/
+       {S1DREG_CPU2MEM_WDOGT,          0x00},  /* CPU-to-Memory Access Watchdog Timer Register*/
+       {S1DREG_COM_DISP_MODE,          0x01},  /* Display Mode Register, LCD only*/
 };
 
-static u64 s1dfb_dmamask = 0xffffffffUL;
+static u64 s1dfb_dmamask = DMA_BIT_MASK(32);
 
-static struct s1d13xxxfb_pdata yl_9200_s1dfb_pdata = {
-               .initregs                               = yl_9200_s1dfb_initregs,
-               .initregssize                   = ARRAY_SIZE(yl_9200_s1dfb_initregs),
-               .platform_init_video    = yl_9200_init_video,
+static struct s1d13xxxfb_pdata yl9200_s1dfb_pdata = {
+       .initregs               = yl9200_s1dfb_initregs,
+       .initregssize           = ARRAY_SIZE(yl9200_s1dfb_initregs),
+       .platform_init_video    = yl9200_init_video,
 };
 
-static struct resource yl_9200_s1dfb_resource[] = {
+static struct resource yl9200_s1dfb_resource[] = {
        [0] = { /* video mem */
-               .name   = "s1d13xxxfb memory",
-       /*      .name   = "s1d13806 memory",*/
-               .start  = AT91_FB_VMEM_BASE,
-               .end    = AT91_FB_VMEM_BASE + AT91_FB_VMEM_SIZE -1,
-               .flags  = IORESOURCE_MEM,
+               .name   = "s1d13xxxfb memory",
+               .start  = AT91_FB_VMEM_BASE,
+               .end    = AT91_FB_VMEM_BASE + AT91_FB_VMEM_SIZE -1,
+               .flags  = IORESOURCE_MEM,
        },
        [1] = { /* video registers */
-               .name   = "s1d13xxxfb registers",
-       /*      .name   = "s1d13806 registers",*/
-               .start  = AT91_FB_REG_BASE,
-               .end    = AT91_FB_REG_BASE + AT91_FB_REG_SIZE -1,
-               .flags  = IORESOURCE_MEM,
+               .name   = "s1d13xxxfb registers",
+               .start  = AT91_FB_REG_BASE,
+               .end    = AT91_FB_REG_BASE + AT91_FB_REG_SIZE -1,
+               .flags  = IORESOURCE_MEM,
        },
 };
 
-static struct platform_device yl_9200_s1dfb_device = {
-       /*TODO S.Birtles , really we need the chip revision in here as well*/
-               .name           = "s1d13806fb",
-       /*  .name               = "s1d13506fb",*/
-               .id                     = -1,
-               .dev            = {
-       /*TODO theres a waring here!!*/
-       /*WARNING: vmlinux.o(.data+0x2dbc): Section mismatch: reference to .init.text: (between 'yl_9200_s1dfb_pdata' and 's1dfb_dmamask')*/
+static struct platform_device yl9200_s1dfb_device = {
+       .name           = "s1d13806fb",
+       .id             = -1,
+       .dev    = {
                .dma_mask               = &s1dfb_dmamask,
-               .coherent_dma_mask      = 0xffffffff,
-               .platform_data          = &yl_9200_s1dfb_pdata,
+               .coherent_dma_mask      = DMA_BIT_MASK(32),
+               .platform_data          = &yl9200_s1dfb_pdata,
        },
-       .resource       = yl_9200_s1dfb_resource,
-       .num_resources  = ARRAY_SIZE(yl_9200_s1dfb_resource),
+       .resource       = yl9200_s1dfb_resource,
+       .num_resources  = ARRAY_SIZE(yl9200_s1dfb_resource),
 };
 
-void __init yl_9200_add_device_video(void)
+void __init yl9200_add_device_video(void)
 {
-       platform_device_register(&yl_9200_s1dfb_device);
+       platform_device_register(&yl9200_s1dfb_device);
 }
 #else
-       void __init yl_9200_add_device_video(void) {}
+void __init yl9200_add_device_video(void) {}
 #endif
 
-/*this is not called first , yl_9200_map_io is called first*/
-static void __init yl_9200_board_init(void)
+
+static void __init yl9200_board_init(void)
 {
        /* Serial */
        at91_add_device_serial();
        /* Ethernet */
-       at91_add_device_eth(&yl_9200_eth_data);
+       at91_add_device_eth(&yl9200_eth_data);
        /* USB Host */
-       at91_add_device_usbh(&yl_9200_usbh_data);
+       at91_add_device_usbh(&yl9200_usbh_data);
        /* USB Device */
-       at91_add_device_udc(&yl_9200_udc_data);
-       /* pullup_pin it is  actually active low, but this is not needed, driver sets it up */
-       /*at91_set_multi_drive(yl_9200_udc_data.pullup_pin, 0);*/
-
-       /* Compact Flash */
-       /*at91_add_device_cf(&yl_9200_cf_data);*/
-
+       at91_add_device_udc(&yl9200_udc_data);
        /* I2C */
-       at91_add_device_i2c(yl_9200_i2c_devices, ARRAY_SIZE(yl_9200_i2c_devices));
-       /* SPI */
-       /*TODO YL9200 we have 2 spi interfaces touch screen & CAN*/
-       /* AT91_PIN_PA5, AT91_PIN_PA6 , are used on the  max 485 NOT SPI*/
-
-       /*touch screen and CAN*/
-       at91_add_device_spi(yl_9200_spi_devices, ARRAY_SIZE(yl_9200_spi_devices));
-
-       /*Basically the  TS uses  PB11 & PB10 , PB11 is configured by the SPI system BP10 IS NOT USED!!*/
-       /* we need this incase the board is running without a touch screen*/
-       #if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
-       at91_init_device_ts(); /*init the touch screen device*/
-       #endif
-       /* DataFlash card */
-       at91_add_device_mmc(0, &yl_9200_mmc_data);
+       at91_add_device_i2c(yl9200_i2c_devices, ARRAY_SIZE(yl9200_i2c_devices));
+       /* MMC */
+       at91_add_device_mmc(0, &yl9200_mmc_data);
        /* NAND */
-       at91_add_device_nand(&yl_9200_nand_data);
+       at91_add_device_nand(&yl9200_nand_data);
        /* NOR Flash */
-       platform_device_register(&yl_9200_flash);
-       /* LEDs. Note!! this does not include the led's we passed for the processor status */
-       at91_gpio_leds(yl_9200_leds, ARRAY_SIZE(yl_9200_leds));
-       /* VGA  */
-       /*this is self registered by including the s1d13xxx chip in the kernel build*/
-       yl_9200_add_device_video();
+       platform_device_register(&yl9200_flash);
+#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
+       /* SPI */
+       at91_add_device_spi(yl9200_spi_devices, ARRAY_SIZE(yl9200_spi_devices));
+       /* Touchscreen */
+       yl9200_add_device_ts();
+#endif
+       /* LEDs. */
+       at91_gpio_leds(yl9200_leds, ARRAY_SIZE(yl9200_leds));
        /* Push Buttons */
-       yl_9200_add_device_buttons();
-       /*TODO fixup the Sounder */
-//     yl_9200_add_device_sounder(yl_9200_sounder,ARRAY_SIZE(yl_9200_sounder));
-
+       yl9200_add_device_buttons();
+       /* VGA */
+       yl9200_add_device_video();
 }
 
 MACHINE_START(YL9200, "uCdragon YL-9200")
-       /* Maintainer: S.Birtles*/
-       .phys_io                = AT91_BASE_SYS,
+       /* Maintainer: S.Birtles */
+       .phys_io        = AT91_BASE_SYS,
        .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
        .boot_params    = AT91_SDRAM_BASE + 0x100,
-       .timer                  = &at91rm9200_timer,
-       .map_io                 = yl_9200_map_io,
-       .init_irq               = yl_9200_init_irq,
-       .init_machine   = yl_9200_board_init,
+       .timer          = &at91rm9200_timer,
+       .map_io         = yl9200_map_io,
+       .init_irq       = yl9200_init_irq,
+       .init_machine   = yl9200_board_init,
 MACHINE_END
index a33dfe4..464bdbb 100644 (file)
@@ -112,12 +112,34 @@ static void pmc_sys_mode(struct clk *clk, int is_on)
                at91_sys_write(AT91_PMC_SCDR, clk->pmc_mask);
 }
 
+static void pmc_uckr_mode(struct clk *clk, int is_on)
+{
+       unsigned int uckr = at91_sys_read(AT91_CKGR_UCKR);
+
+       if (is_on) {
+               is_on = AT91_PMC_LOCKU;
+               at91_sys_write(AT91_CKGR_UCKR, uckr | clk->pmc_mask);
+       } else
+               at91_sys_write(AT91_CKGR_UCKR, uckr & ~(clk->pmc_mask));
+
+       do {
+               cpu_relax();
+       } while ((at91_sys_read(AT91_PMC_SR) & AT91_PMC_LOCKU) != is_on);
+}
+
 /* USB function clocks (PLLB must be 48 MHz) */
 static struct clk udpck = {
        .name           = "udpck",
        .parent         = &pllb,
        .mode           = pmc_sys_mode,
 };
+static struct clk utmi_clk = {
+       .name           = "utmi_clk",
+       .parent         = &main_clk,
+       .pmc_mask       = AT91_PMC_UPLLEN,      /* in CKGR_UCKR */
+       .mode           = pmc_uckr_mode,
+       .type           = CLK_TYPE_PLL,
+};
 static struct clk uhpck = {
        .name           = "uhpck",
        .parent         = &pllb,
@@ -361,7 +383,7 @@ static void __init init_programmable_clock(struct clk *clk)
 
 static int at91_clk_show(struct seq_file *s, void *unused)
 {
-       u32             scsr, pcsr, sr;
+       u32             scsr, pcsr, uckr = 0, sr;
        struct clk      *clk;
 
        seq_printf(s, "SCSR = %8x\n", scsr = at91_sys_read(AT91_PMC_SCSR));
@@ -369,7 +391,10 @@ static int at91_clk_show(struct seq_file *s, void *unused)
        seq_printf(s, "MOR  = %8x\n", at91_sys_read(AT91_CKGR_MOR));
        seq_printf(s, "MCFR = %8x\n", at91_sys_read(AT91_CKGR_MCFR));
        seq_printf(s, "PLLA = %8x\n", at91_sys_read(AT91_CKGR_PLLAR));
-       seq_printf(s, "PLLB = %8x\n", at91_sys_read(AT91_CKGR_PLLBR));
+       if (!cpu_is_at91sam9rl())
+               seq_printf(s, "PLLB = %8x\n", at91_sys_read(AT91_CKGR_PLLBR));
+       if (cpu_is_at91cap9() || cpu_is_at91sam9rl())
+               seq_printf(s, "UCKR = %8x\n", uckr = at91_sys_read(AT91_CKGR_UCKR));
        seq_printf(s, "MCKR = %8x\n", at91_sys_read(AT91_PMC_MCKR));
        seq_printf(s, "SR   = %8x\n", sr = at91_sys_read(AT91_PMC_SR));
 
@@ -382,6 +407,8 @@ static int at91_clk_show(struct seq_file *s, void *unused)
                        state = (scsr & clk->pmc_mask) ? "on" : "off";
                else if (clk->mode == pmc_periph_mode)
                        state = (pcsr & clk->pmc_mask) ? "on" : "off";
+               else if (clk->mode == pmc_uckr_mode)
+                       state = (uckr & clk->pmc_mask) ? "on" : "off";
                else if (clk->pmc_mask)
                        state = (sr & clk->pmc_mask) ? "on" : "off";
                else if (clk == &clk32k || clk == &main_clk)
@@ -488,14 +515,19 @@ static unsigned __init at91_pll_calc(unsigned main_freq, unsigned out_freq)
                /*
                 * PLL input between 1MHz and 32MHz per spec, but lower
                 * frequences seem necessary in some cases so allow 100K.
+                * Warning: some newer products need 2MHz min.
                 */
                input = main_freq / i;
+               if (cpu_is_at91sam9g20() && input < 2000000)
+                       continue;
                if (input < 100000)
                        continue;
                if (input > 32000000)
                        continue;
 
                mul1 = out_freq / input;
+               if (cpu_is_at91sam9g20() && mul > 63)
+                       continue;
                if (mul1 > 2048)
                        continue;
                if (mul1 < 2)
@@ -555,7 +587,8 @@ int __init at91_clock_init(unsigned long main_clock)
 
        /* report if PLLA is more than mildly overclocked */
        plla.rate_hz = at91_pll_rate(&plla, main_clock, at91_sys_read(AT91_CKGR_PLLAR));
-       if (plla.rate_hz > 209000000)
+       if ((!cpu_is_at91sam9g20() && plla.rate_hz > 209000000)
+          || (cpu_is_at91sam9g20() && plla.rate_hz > 800000000))
                pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
 
        /*
@@ -570,7 +603,7 @@ int __init at91_clock_init(unsigned long main_clock)
                uhpck.pmc_mask = AT91RM9200_PMC_UHP;
                udpck.pmc_mask = AT91RM9200_PMC_UDP;
                at91_sys_write(AT91_PMC_SCER, AT91RM9200_PMC_MCKUDP);
-       } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || cpu_is_at91sam9263()) {
+       } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
                uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
                udpck.pmc_mask = AT91SAM926x_PMC_UDP;
        } else if (cpu_is_at91cap9()) {
@@ -581,6 +614,17 @@ int __init at91_clock_init(unsigned long main_clock)
        udpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
        uhpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, at91_pllb_usb_init);
 
+       /*
+        * USB HS clock init
+        */
+       if (cpu_is_at91cap9() || cpu_is_at91sam9rl()) {
+               /*
+                * multiplier is hard-wired to 40
+                * (obtain the USB High Speed 480 MHz when input is 12 MHz)
+                */
+               utmi_clk.rate_hz = 40 * utmi_clk.parent->rate_hz;
+       }
+
        /*
         * MCK and CPU derive from one of those primary clocks.
         * For now, assume this parentage won't change.
@@ -591,13 +635,21 @@ int __init at91_clock_init(unsigned long main_clock)
        freq /= (1 << ((mckr & AT91_PMC_PRES) >> 2));                           /* prescale */
        if (cpu_is_at91rm9200())
                mck.rate_hz = freq / (1 + ((mckr & AT91_PMC_MDIV) >> 8));       /* mdiv */
-       else
-               mck.rate_hz = freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8));      /* mdiv */
+       else if (cpu_is_at91sam9g20()) {
+               mck.rate_hz = (mckr & AT91_PMC_MDIV) ?
+                       freq / ((mckr & AT91_PMC_MDIV) >> 7) : freq;    /* mdiv ; (x >> 7) = ((x >> 8) * 2) */
+               if (mckr & AT91_PMC_PDIV)
+                       freq /= 2;              /* processor clock division */
+       } else
+               mck.rate_hz = freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8));      /* mdiv */
 
        /* Register the PMC's standard clocks */
        for (i = 0; i < ARRAY_SIZE(standard_pmc_clocks); i++)
                list_add_tail(&standard_pmc_clocks[i]->node, &clocks);
 
+       if (cpu_is_at91cap9() || cpu_is_at91sam9rl())
+               list_add_tail(&utmi_clk.node, &clocks);
+
        /* MCK and CPU clock are "always on" */
        clk_enable(&mck);
 
index aa863c1..8ab4feb 100644 (file)
@@ -202,7 +202,7 @@ static int at91_pm_verify_clocks(void)
                        pr_debug("AT91: PM - Suspend-to-RAM with USB still active\n");
                        return 0;
                }
-       } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || cpu_is_at91sam9263()) {
+       } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
                if ((scsr & (AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP)) != 0) {
                        pr_debug("AT91: PM - Suspend-to-RAM with USB still active\n");
                        return 0;
index 9d7515c..f62c355 100644 (file)
@@ -74,6 +74,7 @@ struct clk *clk_get(struct device *dev, const char *id)
 
        return ERR_PTR(-ENOENT);
 }
+EXPORT_SYMBOL(clk_get);
 
 int clk_enable(struct clk *clk)
 {
@@ -86,6 +87,7 @@ int clk_enable(struct clk *clk)
 
        return 0;
 }
+EXPORT_SYMBOL(clk_enable);
 
 void clk_disable(struct clk *clk)
 {
@@ -96,15 +98,18 @@ void clk_disable(struct clk *clk)
                __raw_writel(value & ~clk->enable_mask, clk->enable_reg);
        }
 }
+EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
        return clk->rate;
 }
+EXPORT_SYMBOL(clk_get_rate);
 
 void clk_put(struct clk *clk)
 {
 }
+EXPORT_SYMBOL(clk_put);
 
 
 
index 0694ad6..32f8609 100644 (file)
@@ -14,12 +14,10 @@ pci-$(CONFIG_ARCH_EBSA285_HOST) += ebsa285-pci.o
 pci-$(CONFIG_ARCH_NETWINDER) += netwinder-pci.o
 pci-$(CONFIG_ARCH_PERSONAL_SERVER) += personal-pci.o
 
-leds-$(CONFIG_ARCH_CO285) += ebsa285-leds.o
 leds-$(CONFIG_ARCH_EBSA285) += ebsa285-leds.o
 leds-$(CONFIG_ARCH_NETWINDER) += netwinder-leds.o
 
 obj-$(CONFIG_ARCH_CATS) += cats-hw.o isa-timer.o
-obj-$(CONFIG_ARCH_CO285) += co285.o dc21285-timer.o
 obj-$(CONFIG_ARCH_EBSA285) += ebsa285.o dc21285-timer.o
 obj-$(CONFIG_ARCH_NETWINDER) += netwinder-hw.o isa-timer.o
 obj-$(CONFIG_ARCH_PERSONAL_SERVER) += personal.o dc21285-timer.o
diff --git a/arch/arm/mach-footbridge/co285.c b/arch/arm/mach-footbridge/co285.c
deleted file mode 100644 (file)
index 4545576..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * linux/arch/arm/mach-footbridge/co285.c
- *
- * CO285 machine fixup
- */
-#include <linux/init.h>
-
-#include <asm/hardware/dec21285.h>
-#include <asm/mach-types.h>
-
-#include <asm/mach/arch.h>
-
-#include "common.h"
-
-static void __init
-fixup_coebsa285(struct machine_desc *desc, struct tag *tags,
-               char **cmdline, struct meminfo *mi)
-{
-       extern unsigned long boot_memory_end;
-       extern char boot_command_line[];
-
-       mi->nr_banks      = 1;
-       mi->bank[0].start = PHYS_OFFSET;
-       mi->bank[0].size  = boot_memory_end;
-       mi->bank[0].node  = 0;
-
-       *cmdline = boot_command_line;
-}
-
-MACHINE_START(CO285, "co-EBSA285")
-       /* Maintainer: Mark van Doesburg */
-       .phys_io        = DC21285_ARMCSR_BASE,
-       .io_pg_offst    = ((0x7cf00000) >> 18) & 0xfffc,
-       .fixup          = fixup_coebsa285,
-       .map_io         = footbridge_map_io,
-       .init_irq       = footbridge_init_irq,
-       .timer          = &footbridge_timer,
-MACHINE_END
-
index ef29fc3..b08ab50 100644 (file)
@@ -177,25 +177,6 @@ static struct map_desc ebsa285_host_io_desc[] __initdata = {
 #endif
 };
 
-/*
- * The CO-ebsa285 mapping.
- */
-static struct map_desc co285_io_desc[] __initdata = {
-#ifdef CONFIG_ARCH_CO285
-       {
-               .virtual        = PCIO_BASE,
-               .pfn            = __phys_to_pfn(DC21285_PCI_IO),
-               .length         = PCIO_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = PCIMEM_BASE,
-               .pfn            = __phys_to_pfn(DC21285_PCI_MEM),
-               .length         = PCIMEM_SIZE,
-               .type           = MT_DEVICE,
-       },
-#endif
-};
-
 void __init footbridge_map_io(void)
 {
        /*
@@ -208,8 +189,6 @@ void __init footbridge_map_io(void)
         * Now, work out what we've got to map in addition on this
         * platform.
         */
-       if (machine_is_co285())
-               iotable_init(co285_io_desc, ARRAY_SIZE(co285_io_desc));
        if (footbridge_cfn_mode())
                iotable_init(ebsa285_host_io_desc, ARRAY_SIZE(ebsa285_host_io_desc));
 }
index a64e222..09c1fbc 100644 (file)
@@ -128,7 +128,7 @@ static void ebsa285_leds_event(led_event_t evt)
 
 static int __init leds_init(void)
 {
-       if (machine_is_ebsa285() || machine_is_co285())
+       if (machine_is_ebsa285())
                leds_event = ebsa285_leds_event;
 
        leds_event(led_start);
index 5d02e95..d5cfcda 100644 (file)
@@ -115,8 +115,7 @@ static int set_isa_cmos_time(void)
 
 void __init isa_rtc_init(void)
 {
-       if (machine_is_co285() ||
-           machine_is_personal_server())
+       if (machine_is_personal_server())
                /*
                 * Add-in 21285s shouldn't access the RTC
                 */
index 88d5e61..b047c7e 100644 (file)
@@ -4,7 +4,7 @@
 
 # Object file lists.
 
-obj-y                  += irq.o time.o dma.o generic.o
+obj-y                  += irq.o time.o dma.o generic.o clock.o
 
 obj-$(CONFIG_CPU_FREQ_IMX)     += cpufreq.o
 
diff --git a/arch/arm/mach-imx/clock.c b/arch/arm/mach-imx/clock.c
new file mode 100644 (file)
index 0000000..6a90fe5
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ *  Copyright (C) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/math64.h>
+#include <linux/err.h>
+
+#include <asm/io.h>
+#include <asm/arch/imx-regs.h>
+
+/*
+ * Very simple approach: We can't disable clocks, so we do
+ * not need refcounting
+ */
+
+struct clk {
+       struct list_head node;
+       const char *name;
+       unsigned long (*get_rate)(void);
+};
+
+/*
+ *  get the system pll clock in Hz
+ *
+ *                  mfi + mfn / (mfd +1)
+ *  f = 2 * f_ref * --------------------
+ *                        pd + 1
+ */
+static unsigned long imx_decode_pll(unsigned int pll, u32 f_ref)
+{
+       unsigned long long ll;
+       unsigned long quot;
+
+       u32 mfi = (pll >> 10) & 0xf;
+       u32 mfn = pll & 0x3ff;
+       u32 mfd = (pll >> 16) & 0x3ff;
+       u32 pd =  (pll >> 26) & 0xf;
+
+       mfi = mfi <= 5 ? 5 : mfi;
+
+       ll = 2 * (unsigned long long)f_ref *
+               ((mfi << 16) + (mfn << 16) / (mfd + 1));
+       quot = (pd + 1) * (1 << 16);
+       ll += quot / 2;
+       do_div(ll, quot);
+       return (unsigned long)ll;
+}
+
+static unsigned long imx_get_system_clk(void)
+{
+       u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
+
+       return imx_decode_pll(SPCTL0, f_ref);
+}
+
+static unsigned long imx_get_mcu_clk(void)
+{
+       return imx_decode_pll(MPCTL0, CLK32 * 512);
+}
+
+/*
+ *  get peripheral clock 1 ( UART[12], Timer[12], PWM )
+ */
+static unsigned long imx_get_perclk1(void)
+{
+       return imx_get_system_clk() / (((PCDR) & 0xf)+1);
+}
+
+/*
+ *  get peripheral clock 2 ( LCD, SD, SPI[12] )
+ */
+static unsigned long imx_get_perclk2(void)
+{
+       return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
+}
+
+/*
+ *  get peripheral clock 3 ( SSI )
+ */
+static unsigned long imx_get_perclk3(void)
+{
+       return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
+}
+
+/*
+ *  get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
+ */
+static unsigned long imx_get_hclk(void)
+{
+       return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
+}
+
+static struct clk clk_system_clk = {
+       .name = "system_clk",
+       .get_rate = imx_get_system_clk,
+};
+
+static struct clk clk_hclk = {
+       .name = "hclk",
+       .get_rate = imx_get_hclk,
+};
+
+static struct clk clk_mcu_clk = {
+       .name = "mcu_clk",
+       .get_rate = imx_get_mcu_clk,
+};
+
+static struct clk clk_perclk1 = {
+       .name = "perclk1",
+       .get_rate = imx_get_perclk1,
+};
+
+static struct clk clk_uart_clk = {
+       .name = "uart_clk",
+       .get_rate = imx_get_perclk1,
+};
+
+static struct clk clk_perclk2 = {
+       .name = "perclk2",
+       .get_rate = imx_get_perclk2,
+};
+
+static struct clk clk_perclk3 = {
+       .name = "perclk3",
+       .get_rate = imx_get_perclk3,
+};
+
+static struct clk *clks[] = {
+       &clk_perclk1,
+       &clk_perclk2,
+       &clk_perclk3,
+       &clk_system_clk,
+       &clk_hclk,
+       &clk_mcu_clk,
+       &clk_uart_clk,
+};
+
+static LIST_HEAD(clocks);
+static DEFINE_MUTEX(clocks_mutex);
+
+struct clk *clk_get(struct device *dev, const char *id)
+{
+       struct clk *p, *clk = ERR_PTR(-ENOENT);
+
+       mutex_lock(&clocks_mutex);
+       list_for_each_entry(p, &clocks, node) {
+               if (!strcmp(p->name, id)) {
+                       clk = p;
+                       goto found;
+               }
+       }
+
+found:
+       mutex_unlock(&clocks_mutex);
+
+       return clk;
+}
+
+void clk_put(struct clk *clk)
+{
+}
+
+int clk_enable(struct clk *clk)
+{
+       return 0;
+}
+
+void clk_disable(struct clk *clk)
+{
+}
+
+unsigned long clk_get_rate(struct clk *clk)
+{
+       return clk->get_rate();
+}
+
+int imx_clocks_init(void)
+{
+       int i;
+
+       mutex_lock(&clocks_mutex);
+       for (i = 0; i < ARRAY_SIZE(clks); i++)
+               list_add(&clks[i]->node, &clocks);
+       mutex_unlock(&clocks_mutex);
+
+       return 0;
+}
+
index e548ba7..be0809b 100644 (file)
@@ -32,6 +32,8 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <asm/system.h>
 
 #include <asm/hardware.h>
@@ -52,6 +54,8 @@
 static u32 mpctl0_at_boot;
 static u32 bclk_div_at_boot;
 
+static struct clk *system_clk, *mcu_clk;
+
 static void imx_set_async_mode(void)
 {
        adjust_cr(CR_920T_CLOCK_MODE, CR_920T_ASYNC_MODE);
@@ -160,10 +164,10 @@ static unsigned int imx_get_speed(unsigned int cpu)
        cr = get_cr();
 
        if((cr & CR_920T_CLOCK_MODE) == CR_920T_FASTBUS_MODE) {
-               freq = imx_get_system_clk();
+               freq = clk_get_rate(system_clk);
                freq = (freq + bclk_div/2) / bclk_div;
        } else {
-               freq = imx_get_mcu_clk();
+               freq = clk_get_rate(mcu_clk);
                if (cscr & CSCR_MPU_PRESC)
                        freq /= 2;
        }
@@ -201,7 +205,7 @@ static int imx_set_target(struct cpufreq_policy *policy,
        pr_debug(KERN_DEBUG "imx: requested frequency %ld Hz, mpctl0 at boot 0x%08x\n",
                        freq, mpctl0_at_boot);
 
-       sysclk = imx_get_system_clk();
+       sysclk = clk_get_rate(system_clk);
 
        if (freq > sysclk / bclk_div_at_boot + 1000000) {
                freq = imx_compute_mpctl(&mpctl0, mpctl0_at_boot, CLK32 * 512, freq, relation);
@@ -290,6 +294,16 @@ static int __init imx_cpufreq_init(void)
        bclk_div_at_boot = __mfld2val(CSCR_BCLK_DIV, CSCR) + 1;
        mpctl0_at_boot = 0;
 
+       system_clk = clk_get(NULL, "system_clk");
+       if (IS_ERR(system_clk))
+               return PTR_ERR(system_clk);
+
+       mcu_clk = clk_get(NULL, "mcu_clk");
+       if (IS_ERR(mcu_clk)) {
+               clk_put(system_clk);
+               return PTR_ERR(mcu_clk);
+       }
+
        if((CSCR & CSCR_MPEN) &&
           ((get_cr() & CR_920T_CLOCK_MODE) != CR_920T_FASTBUS_MODE))
                mpctl0_at_boot = MPCTL0;
index a59ff29..ee1c6f0 100644 (file)
@@ -410,7 +410,6 @@ void imx_dma_free(imx_dmach_t dma_ch)
 
 /**
  * imx_dma_request_by_prio - find and request some of free channels best suiting requested priority
- * @dma_ch: i.MX DMA channel number
  * @name: the driver/caller own non-%NULL identification
  * @prio: one of the hardware distinguished priority level:
  *        %DMA_PRIO_HIGH, %DMA_PRIO_MEDIUM, %DMA_PRIO_LOW
@@ -420,11 +419,9 @@ void imx_dma_free(imx_dmach_t dma_ch)
  * in the higher and then even lower priority groups.
  *
  * Return value: If there is no free channel to allocate, -%ENODEV is returned.
- *               Zero value indicates successful channel allocation.
+ *               On successful allocation channel is returned.
  */
-int
-imx_dma_request_by_prio(imx_dmach_t * pdma_ch, const char *name,
-                       imx_dma_prio prio)
+imx_dmach_t imx_dma_request_by_prio(const char *name, imx_dma_prio prio)
 {
        int i;
        int best;
@@ -444,15 +441,13 @@ imx_dma_request_by_prio(imx_dmach_t * pdma_ch, const char *name,
 
        for (i = best; i < IMX_DMA_CHANNELS; i++) {
                if (!imx_dma_request(i, name)) {
-                       *pdma_ch = i;
-                       return 0;
+                       return i;
                }
        }
 
        for (i = best - 1; i >= 0; i--) {
                if (!imx_dma_request(i, name)) {
-                       *pdma_ch = i;
-                       return 0;
+                       return i;
                }
        }
 
index 4cfc9d3..98ddd8a 100644 (file)
@@ -214,82 +214,6 @@ int imx_irq_to_gpio(unsigned irq)
 
 EXPORT_SYMBOL(imx_irq_to_gpio);
 
-/*
- *  get the system pll clock in Hz
- *
- *                  mfi + mfn / (mfd +1)
- *  f = 2 * f_ref * --------------------
- *                        pd + 1
- */
-static unsigned int imx_decode_pll(unsigned int pll, u32 f_ref)
-{
-       unsigned long long ll;
-       unsigned long quot;
-
-       u32 mfi = (pll >> 10) & 0xf;
-       u32 mfn = pll & 0x3ff;
-       u32 mfd = (pll >> 16) & 0x3ff;
-       u32 pd =  (pll >> 26) & 0xf;
-
-       mfi = mfi <= 5 ? 5 : mfi;
-
-       ll = 2 * (unsigned long long)f_ref * ( (mfi<<16) + (mfn<<16) / (mfd+1) );
-       quot = (pd+1) * (1<<16);
-       ll += quot / 2;
-       do_div(ll, quot);
-       return (unsigned int) ll;
-}
-
-unsigned int imx_get_system_clk(void)
-{
-       u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
-
-       return imx_decode_pll(SPCTL0, f_ref);
-}
-EXPORT_SYMBOL(imx_get_system_clk);
-
-unsigned int imx_get_mcu_clk(void)
-{
-       return imx_decode_pll(MPCTL0, CLK32 * 512);
-}
-EXPORT_SYMBOL(imx_get_mcu_clk);
-
-/*
- *  get peripheral clock 1 ( UART[12], Timer[12], PWM )
- */
-unsigned int imx_get_perclk1(void)
-{
-       return imx_get_system_clk() / (((PCDR) & 0xf)+1);
-}
-EXPORT_SYMBOL(imx_get_perclk1);
-
-/*
- *  get peripheral clock 2 ( LCD, SD, SPI[12] )
- */
-unsigned int imx_get_perclk2(void)
-{
-       return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
-}
-EXPORT_SYMBOL(imx_get_perclk2);
-
-/*
- *  get peripheral clock 3 ( SSI )
- */
-unsigned int imx_get_perclk3(void)
-{
-       return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
-}
-EXPORT_SYMBOL(imx_get_perclk3);
-
-/*
- *  get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
- */
-unsigned int imx_get_hclk(void)
-{
-       return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
-}
-EXPORT_SYMBOL(imx_get_hclk);
-
 static struct resource imx_mmc_resources[] = {
        [0] = {
                .start  = 0x00214000,
index a9778c1..9635d58 100644 (file)
@@ -69,6 +69,11 @@ static struct resource imx_uart1_resources[] = {
                .end    = (UART1_MINT_TX),
                .flags  = IORESOURCE_IRQ,
        },
+       [3] = {
+               .start  = UART1_MINT_RTS,
+               .end    = UART1_MINT_RTS,
+               .flags  = IORESOURCE_IRQ,
+       },
 };
 
 static struct platform_device imx_uart1_device = {
@@ -97,6 +102,11 @@ static struct resource imx_uart2_resources[] = {
                .end    = (UART2_MINT_TX),
                .flags  = IORESOURCE_IRQ,
        },
+       [3] = {
+               .start  = UART2_MINT_RTS,
+               .end    = UART2_MINT_RTS,
+               .flags  = IORESOURCE_IRQ,
+       },
 };
 
 static struct platform_device imx_uart2_device = {
index d86d124..5a41e96 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/time.h>
 #include <linux/clocksource.h>
 #include <linux/clockchips.h>
+#include <linux/clk.h>
 
 #include <asm/hardware.h>
 #include <asm/io.h>
@@ -86,10 +87,10 @@ static struct clocksource clocksource_imx = {
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static int __init imx_clocksource_init(void)
+static int __init imx_clocksource_init(unsigned long rate)
 {
        clocksource_imx.mult =
-               clocksource_hz2mult(imx_get_perclk1(), clocksource_imx.shift);
+               clocksource_hz2mult(rate, clocksource_imx.shift);
        clocksource_register(&clocksource_imx);
 
        return 0;
@@ -174,9 +175,9 @@ static struct clock_event_device clockevent_imx = {
        .rating         = 200,
 };
 
-static int __init imx_clockevent_init(void)
+static int __init imx_clockevent_init(unsigned long rate)
 {
-       clockevent_imx.mult = div_sc(imx_get_perclk1(), NSEC_PER_SEC,
+       clockevent_imx.mult = div_sc(rate, NSEC_PER_SEC,
                                        clockevent_imx.shift);
        clockevent_imx.max_delta_ns =
                clockevent_delta2ns(0xfffffffe, &clockevent_imx);
@@ -190,13 +191,23 @@ static int __init imx_clockevent_init(void)
        return 0;
 }
 
+extern int imx_clocks_init(void);
 
 static void __init imx_timer_init(void)
 {
+       struct clk *clk;
+       unsigned long rate;
+
+       imx_clocks_init();
+
+       clk = clk_get(NULL, "perclk1");
+       clk_enable(clk);
+       rate = clk_get_rate(clk);
+
        imx_timer_hardware_init();
-       imx_clocksource_init();
+       imx_clocksource_init(rate);
 
-       imx_clockevent_init();
+       imx_clockevent_init(rate);
 
        /*
         * Make irqs happen for the system timer
index 158daaf..6a5ef8d 100644 (file)
@@ -4,7 +4,7 @@
 
 # Object file lists.
 
-obj-y                                  := clock.o core.o lm.o time.o
+obj-y                                  := clock.o core.o lm.o
 obj-$(CONFIG_ARCH_INTEGRATOR_AP)       += integrator_ap.o
 obj-$(CONFIG_ARCH_INTEGRATOR_CP)       += integrator_cp.o
 
diff --git a/arch/arm/mach-integrator/time.c b/arch/arm/mach-integrator/time.c
deleted file mode 100644 (file)
index 8508a0d..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- *  linux/arch/arm/mach-integrator/time.c
- *
- *  Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/time.h>
-#include <linux/mc146818rtc.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
-#include <linux/device.h>
-#include <linux/amba/bus.h>
-
-#include <asm/hardware.h>
-#include <asm/io.h>
-#include <asm/uaccess.h>
-#include <asm/rtc.h>
-
-#include <asm/mach/time.h>
-
-#define RTC_DR         (0)
-#define RTC_MR         (4)
-#define RTC_STAT       (8)
-#define RTC_EOI                (8)
-#define RTC_LR         (12)
-#define RTC_CR         (16)
-#define RTC_CR_MIE     (1 << 0)
-
-extern int (*set_rtc)(void);
-static void __iomem *rtc_base;
-
-static int integrator_set_rtc(void)
-{
-       __raw_writel(xtime.tv_sec, rtc_base + RTC_LR);
-       return 1;
-}
-
-static int integrator_rtc_read_alarm(struct rtc_wkalrm *alrm)
-{
-       rtc_time_to_tm(readl(rtc_base + RTC_MR), &alrm->time);
-       return 0;
-}
-
-static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm)
-{
-       unsigned long time;
-       int ret;
-
-       /*
-        * At the moment, we can only deal with non-wildcarded alarm times.
-        */
-       ret = rtc_valid_tm(&alrm->time);
-       if (ret == 0)
-               ret = rtc_tm_to_time(&alrm->time, &time);
-       if (ret == 0)
-               writel(time, rtc_base + RTC_MR);
-       return ret;
-}
-
-static int integrator_rtc_read_time(struct rtc_time *tm)
-{
-       rtc_time_to_tm(readl(rtc_base + RTC_DR), tm);
-       return 0;
-}
-
-/*
- * Set the RTC time.  Unfortunately, we can't accurately set
- * the point at which the counter updates.
- *
- * Also, since RTC_LR is transferred to RTC_CR on next rising
- * edge of the 1Hz clock, we must write the time one second
- * in advance.
- */
-static inline int integrator_rtc_set_time(struct rtc_time *tm)
-{
-       unsigned long time;
-       int ret;
-
-       ret = rtc_tm_to_time(tm, &time);
-       if (ret == 0)
-               writel(time + 1, rtc_base + RTC_LR);
-
-       return ret;
-}
-
-static struct rtc_ops rtc_ops = {
-       .owner          = THIS_MODULE,
-       .read_time      = integrator_rtc_read_time,
-       .set_time       = integrator_rtc_set_time,
-       .read_alarm     = integrator_rtc_read_alarm,
-       .set_alarm      = integrator_rtc_set_alarm,
-};
-
-static irqreturn_t arm_rtc_interrupt(int irq, void *dev_id)
-{
-       writel(0, rtc_base + RTC_EOI);
-       return IRQ_HANDLED;
-}
-
-static int rtc_probe(struct amba_device *dev, void *id)
-{
-       int ret;
-
-       if (rtc_base)
-               return -EBUSY;
-
-       ret = amba_request_regions(dev, NULL);
-       if (ret)
-               goto out;
-
-       rtc_base = ioremap(dev->res.start, SZ_4K);
-       if (!rtc_base) {
-               ret = -ENOMEM;
-               goto res_out;
-       }
-
-       __raw_writel(0, rtc_base + RTC_CR);
-       __raw_writel(0, rtc_base + RTC_EOI);
-
-       xtime.tv_sec = __raw_readl(rtc_base + RTC_DR);
-
-       /* note that 'dev' is merely used for irq disambiguation;
-        * it is not actually referenced in the irq handler
-        */
-       ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED,
-                         "rtc-pl030", dev);
-       if (ret)
-               goto map_out;
-
-       ret = register_rtc(&rtc_ops);
-       if (ret)
-               goto irq_out;
-
-       set_rtc = integrator_set_rtc;
-       return 0;
-
- irq_out:
-       free_irq(dev->irq[0], dev);
- map_out:
-       iounmap(rtc_base);
-       rtc_base = NULL;
- res_out:
-       amba_release_regions(dev);
- out:
-       return ret;
-}
-
-static int rtc_remove(struct amba_device *dev)
-{
-       set_rtc = NULL;
-
-       writel(0, rtc_base + RTC_CR);
-
-       free_irq(dev->irq[0], dev);
-       unregister_rtc(&rtc_ops);
-
-       iounmap(rtc_base);
-       rtc_base = NULL;
-       amba_release_regions(dev);
-
-       return 0;
-}
-
-static struct timespec rtc_delta;
-
-static int rtc_suspend(struct amba_device *dev, pm_message_t state)
-{
-       struct timespec rtc;
-
-       rtc.tv_sec = readl(rtc_base + RTC_DR);
-       rtc.tv_nsec = 0;
-       save_time_delta(&rtc_delta, &rtc);
-
-       return 0;
-}
-
-static int rtc_resume(struct amba_device *dev)
-{
-       struct timespec rtc;
-
-       rtc.tv_sec = readl(rtc_base + RTC_DR);
-       rtc.tv_nsec = 0;
-       restore_time_delta(&rtc_delta, &rtc);
-
-       return 0;
-}
-
-static struct amba_id rtc_ids[] = {
-       {
-               .id     = 0x00041030,
-               .mask   = 0x000fffff,
-       },
-       { 0, 0 },
-};
-
-static struct amba_driver rtc_driver = {
-       .drv            = {
-               .name   = "rtc-pl030",
-       },
-       .probe          = rtc_probe,
-       .remove         = rtc_remove,
-       .suspend        = rtc_suspend,
-       .resume         = rtc_resume,
-       .id_table       = rtc_ids,
-};
-
-static int __init integrator_rtc_init(void)
-{
-       return amba_driver_register(&rtc_driver);
-}
-
-static void __exit integrator_rtc_exit(void)
-{
-       amba_driver_unregister(&rtc_driver);
-}
-
-module_init(integrator_rtc_init);
-module_exit(integrator_rtc_exit);
index e774447..db8b5fe 100644 (file)
@@ -125,6 +125,15 @@ config     ARCH_IXDP4XX
        depends on ARCH_IXDP425 || MACH_IXDP465 || MACH_KIXRP435
        default y
 
+config MACH_FSG
+       bool
+       prompt "Freecom FSG-3"
+       select PCI
+       help
+         Say 'Y' here if you want your kernel to support Freecom's
+         FSG-3 device. For more information on this platform,
+         see http://www.nslu2-linux.org/wiki/FSG3/HomePage
+
 #
 # Certain registers and IRQs are only enabled if supporting IXP465 CPUs
 #
index c195688..2e6bbf9 100644 (file)
@@ -15,6 +15,7 @@ obj-pci-$(CONFIG_MACH_NAS100D)                += nas100d-pci.o
 obj-pci-$(CONFIG_MACH_DSMG600)         += dsmg600-pci.o
 obj-pci-$(CONFIG_MACH_GATEWAY7001)     += gateway7001-pci.o
 obj-pci-$(CONFIG_MACH_WG302V2)         += wg302v2-pci.o
+obj-pci-$(CONFIG_MACH_FSG)             += fsg-pci.o
 
 obj-y  += common.o
 
@@ -28,6 +29,7 @@ obj-$(CONFIG_MACH_NAS100D)    += nas100d-setup.o
 obj-$(CONFIG_MACH_DSMG600)      += dsmg600-setup.o
 obj-$(CONFIG_MACH_GATEWAY7001) += gateway7001-setup.o
 obj-$(CONFIG_MACH_WG302V2)     += wg302v2-setup.o
+obj-$(CONFIG_MACH_FSG)         += fsg-setup.o
 
 obj-$(CONFIG_PCI)              += $(obj-pci-$(CONFIG_PCI)) common-pci.o
 obj-$(CONFIG_IXP4XX_QMGR)      += ixp4xx_qmgr.o
index f6d66dc..3781b3d 100644 (file)
@@ -326,11 +326,11 @@ static struct resource ixp4xx_udc_resources[] = {
 };
 
 /*
- * USB device controller. The IXP4xx uses the same controller as PXA2XX,
+ * USB device controller. The IXP4xx uses the same controller as PXA25X,
  * so we just use the same device.
  */
 static struct platform_device ixp4xx_udc_device = {
-       .name           = "pxa2xx-udc",
+       .name           = "pxa25x-udc",
        .id             = -1,
        .num_resources  = 2,
        .resource       = ixp4xx_udc_resources,
diff --git a/arch/arm/mach-ixp4xx/fsg-pci.c b/arch/arm/mach-ixp4xx/fsg-pci.c
new file mode 100644 (file)
index 0000000..f19f3f6
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * arch/arch/mach-ixp4xx/fsg-pci.c
+ *
+ * FSG board-level PCI initialization
+ *
+ * Author: Rod Whitby <rod@whitby.id.au>
+ * Maintainer: http://www.nslu2-linux.org/
+ *
+ * based on ixdp425-pci.c:
+ *     Copyright (C) 2002 Intel Corporation.
+ *     Copyright (C) 2003-2004 MontaVista Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+
+#include <asm/mach/pci.h>
+#include <asm/mach-types.h>
+
+void __init fsg_pci_preinit(void)
+{
+       set_irq_type(IRQ_FSG_PCI_INTA, IRQT_LOW);
+       set_irq_type(IRQ_FSG_PCI_INTB, IRQT_LOW);
+       set_irq_type(IRQ_FSG_PCI_INTC, IRQT_LOW);
+
+       ixp4xx_pci_preinit();
+}
+
+static int __init fsg_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       static int pci_irq_table[FSG_PCI_IRQ_LINES] = {
+               IRQ_FSG_PCI_INTC,
+               IRQ_FSG_PCI_INTB,
+               IRQ_FSG_PCI_INTA,
+       };
+
+       int irq = -1;
+       slot = slot - 11;
+
+       if (slot >= 1 && slot <= FSG_PCI_MAX_DEV &&
+           pin >= 1 && pin <= FSG_PCI_IRQ_LINES)
+               irq = pci_irq_table[(slot - 1)];
+       printk(KERN_INFO "%s: Mapped slot %d pin %d to IRQ %d\n",
+              __func__, slot, pin, irq);
+
+       return irq;
+}
+
+struct hw_pci fsg_pci __initdata = {
+       .nr_controllers = 1,
+       .preinit =        fsg_pci_preinit,
+       .swizzle =        pci_std_swizzle,
+       .setup =          ixp4xx_setup,
+       .scan =           ixp4xx_scan_bus,
+       .map_irq =        fsg_map_irq,
+};
+
+int __init fsg_pci_init(void)
+{
+       if (machine_is_fsg())
+               pci_common_init(&fsg_pci);
+       return 0;
+}
+
+subsys_initcall(fsg_pci_init);
diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
new file mode 100644 (file)
index 0000000..0db3a90
--- /dev/null
@@ -0,0 +1,276 @@
+/*
+ * arch/arm/mach-ixp4xx/fsg-setup.c
+ *
+ * FSG board-setup
+ *
+ * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
+ *
+ * based on ixdp425-setup.c:
+ *     Copyright (C) 2003-2004 MontaVista Software, Inc.
+ * based on nslu2-power.c
+ *     Copyright (C) 2005 Tower Technologies
+ *
+ * Author: Rod Whitby <rod@whitby.id.au>
+ * Maintainers: http://www.nslu2-linux.org/
+ *
+ */
+
+#include <linux/if_ether.h>
+#include <linux/irq.h>
+#include <linux/serial.h>
+#include <linux/serial_8250.h>
+#include <linux/leds.h>
+#include <linux/reboot.h>
+#include <linux/i2c.h>
+#include <linux/i2c-gpio.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/flash.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+
+static struct flash_platform_data fsg_flash_data = {
+       .map_name               = "cfi_probe",
+       .width                  = 2,
+};
+
+static struct resource fsg_flash_resource = {
+       .flags                  = IORESOURCE_MEM,
+};
+
+static struct platform_device fsg_flash = {
+       .name                   = "IXP4XX-Flash",
+       .id                     = 0,
+       .dev = {
+               .platform_data  = &fsg_flash_data,
+       },
+       .num_resources          = 1,
+       .resource               = &fsg_flash_resource,
+};
+
+static struct i2c_gpio_platform_data fsg_i2c_gpio_data = {
+       .sda_pin                = FSG_SDA_PIN,
+       .scl_pin                = FSG_SCL_PIN,
+};
+
+static struct platform_device fsg_i2c_gpio = {
+       .name                   = "i2c-gpio",
+       .id                     = 0,
+       .dev = {
+               .platform_data  = &fsg_i2c_gpio_data,
+       },
+};
+
+static struct i2c_board_info __initdata fsg_i2c_board_info [] = {
+       {
+               I2C_BOARD_INFO("rtc-isl1208", 0x6f),
+       },
+};
+
+static struct resource fsg_uart_resources[] = {
+       {
+               .start          = IXP4XX_UART1_BASE_PHYS,
+               .end            = IXP4XX_UART1_BASE_PHYS + 0x0fff,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = IXP4XX_UART2_BASE_PHYS,
+               .end            = IXP4XX_UART2_BASE_PHYS + 0x0fff,
+               .flags          = IORESOURCE_MEM,
+       }
+};
+
+static struct plat_serial8250_port fsg_uart_data[] = {
+       {
+               .mapbase        = IXP4XX_UART1_BASE_PHYS,
+               .membase        = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
+               .irq            = IRQ_IXP4XX_UART1,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = IXP4XX_UART_XTAL,
+       },
+       {
+               .mapbase        = IXP4XX_UART2_BASE_PHYS,
+               .membase        = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
+               .irq            = IRQ_IXP4XX_UART2,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = IXP4XX_UART_XTAL,
+       },
+       { }
+};
+
+static struct platform_device fsg_uart = {
+       .name                   = "serial8250",
+       .id                     = PLAT8250_DEV_PLATFORM,
+       .dev = {
+               .platform_data  = fsg_uart_data,
+       },
+       .num_resources          = ARRAY_SIZE(fsg_uart_resources),
+       .resource               = fsg_uart_resources,
+};
+
+static struct platform_device fsg_leds = {
+       .name           = "fsg-led",
+       .id             = -1,
+};
+
+/* Built-in 10/100 Ethernet MAC interfaces */
+static struct eth_plat_info fsg_plat_eth[] = {
+       {
+               .phy            = 5,
+               .rxq            = 3,
+               .txreadyq       = 20,
+       }, {
+               .phy            = 4,
+               .rxq            = 4,
+               .txreadyq       = 21,
+       }
+};
+
+static struct platform_device fsg_eth[] = {
+       {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEB,
+               .dev = {
+                       .platform_data  = fsg_plat_eth,
+               },
+       }, {
+               .name                   = "ixp4xx_eth",
+               .id                     = IXP4XX_ETH_NPEC,
+               .dev = {
+                       .platform_data  = fsg_plat_eth + 1,
+               },
+       }
+};
+
+static struct platform_device *fsg_devices[] __initdata = {
+       &fsg_i2c_gpio,
+       &fsg_flash,
+       &fsg_leds,
+       &fsg_eth[0],
+       &fsg_eth[1],
+};
+
+static irqreturn_t fsg_power_handler(int irq, void *dev_id)
+{
+       /* Signal init to do the ctrlaltdel action, this will bypass init if
+        * it hasn't started and do a kernel_restart.
+        */
+       ctrl_alt_del();
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t fsg_reset_handler(int irq, void *dev_id)
+{
+       /* This is the paper-clip reset which does an emergency reboot. */
+       printk(KERN_INFO "Restarting system.\n");
+       machine_restart(NULL);
+
+       /* This should never be reached. */
+       return IRQ_HANDLED;
+}
+
+static void __init fsg_init(void)
+{
+       DECLARE_MAC_BUF(mac_buf);
+       uint8_t __iomem *f;
+       int i;
+
+       ixp4xx_sys_init();
+
+       fsg_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
+       fsg_flash_resource.end =
+               IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
+
+       *IXP4XX_EXP_CS0 |= IXP4XX_FLASH_WRITABLE;
+       *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
+
+       /* Configure CS2 for operation, 8bit and writable */
+       *IXP4XX_EXP_CS2 = 0xbfff0002;
+
+       i2c_register_board_info(0, fsg_i2c_board_info,
+                               ARRAY_SIZE(fsg_i2c_board_info));
+
+       /* This is only useful on a modified machine, but it is valuable
+        * to have it first in order to see debug messages, and so that
+        * it does *not* get removed if platform_add_devices fails!
+        */
+       (void)platform_device_register(&fsg_uart);
+
+       platform_add_devices(fsg_devices, ARRAY_SIZE(fsg_devices));
+
+       if (request_irq(gpio_to_irq(FSG_RB_GPIO), &fsg_reset_handler,
+                       IRQF_DISABLED | IRQF_TRIGGER_LOW,
+                       "FSG reset button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
+                       gpio_to_irq(FSG_RB_GPIO));
+       }
+
+       if (request_irq(gpio_to_irq(FSG_SB_GPIO), &fsg_power_handler,
+                       IRQF_DISABLED | IRQF_TRIGGER_LOW,
+                       "FSG power button", NULL) < 0) {
+
+               printk(KERN_DEBUG "Power Button IRQ %d not available\n",
+                       gpio_to_irq(FSG_SB_GPIO));
+       }
+
+       /*
+        * Map in a portion of the flash and read the MAC addresses.
+        * Since it is stored in BE in the flash itself, we need to
+        * byteswap it if we're in LE mode.
+        */
+       f = ioremap(IXP4XX_EXP_BUS_BASE(0), 0x400000);
+       if (f) {
+#ifdef __ARMEB__
+               for (i = 0; i < 6; i++) {
+                       fsg_plat_eth[0].hwaddr[i] = readb(f + 0x3C0422 + i);
+                       fsg_plat_eth[1].hwaddr[i] = readb(f + 0x3C043B + i);
+               }
+#else
+
+               /*
+                 Endian-swapped reads from unaligned addresses are
+                 required to extract the two MACs from the big-endian
+                 Redboot config area in flash.
+               */
+
+               fsg_plat_eth[0].hwaddr[0] = readb(f + 0x3C0421);
+               fsg_plat_eth[0].hwaddr[1] = readb(f + 0x3C0420);
+               fsg_plat_eth[0].hwaddr[2] = readb(f + 0x3C0427);
+               fsg_plat_eth[0].hwaddr[3] = readb(f + 0x3C0426);
+               fsg_plat_eth[0].hwaddr[4] = readb(f + 0x3C0425);
+               fsg_plat_eth[0].hwaddr[5] = readb(f + 0x3C0424);
+
+               fsg_plat_eth[1].hwaddr[0] = readb(f + 0x3C0439);
+               fsg_plat_eth[1].hwaddr[1] = readb(f + 0x3C043F);
+               fsg_plat_eth[1].hwaddr[2] = readb(f + 0x3C043E);
+               fsg_plat_eth[1].hwaddr[3] = readb(f + 0x3C043D);
+               fsg_plat_eth[1].hwaddr[4] = readb(f + 0x3C043C);
+               fsg_plat_eth[1].hwaddr[5] = readb(f + 0x3C0443);
+#endif
+               iounmap(f);
+       }
+       printk(KERN_INFO "FSG: Using MAC address %s for port 0\n",
+              print_mac(mac_buf, fsg_plat_eth[0].hwaddr));
+       printk(KERN_INFO "FSG: Using MAC address %s for port 1\n",
+              print_mac(mac_buf, fsg_plat_eth[1].hwaddr));
+
+}
+
+MACHINE_START(FSG, "Freecom FSG-3")
+       /* Maintainer: www.nslu2-linux.org */
+       .phys_io        = IXP4XX_PERIPHERAL_BASE_PHYS,
+       .io_pg_offst    = ((IXP4XX_PERIPHERAL_BASE_VIRT) >> 18) & 0xfffc,
+       .map_io         = ixp4xx_map_io,
+       .init_irq       = ixp4xx_init_irq,
+       .timer          = &ixp4xx_timer,
+       .boot_params    = 0x0100,
+       .init_machine   = fsg_init,
+MACHINE_END
+
diff --git a/arch/arm/mach-kirkwood/Kconfig b/arch/arm/mach-kirkwood/Kconfig
new file mode 100644 (file)
index 0000000..3600cd9
--- /dev/null
@@ -0,0 +1,25 @@
+if ARCH_KIRKWOOD
+
+menu "Marvell Kirkwood Implementations"
+
+config MACH_DB88F6281_BP
+       bool "Marvell DB-88F6281-BP Development Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell DB-88F6281-BP Development Board.
+
+config MACH_RD88F6192_NAS
+       bool "Marvell RD-88F6192-NAS Reference Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell RD-88F6192-NAS Reference Board.
+
+config MACH_RD88F6281
+       bool "Marvell RD-88F6281 Reference Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell RD-88F6281 Reference Board.
+
+endmenu
+
+endif
diff --git a/arch/arm/mach-kirkwood/Makefile b/arch/arm/mach-kirkwood/Makefile
new file mode 100644 (file)
index 0000000..e14bf40
--- /dev/null
@@ -0,0 +1,5 @@
+obj-y                          += common.o addr-map.o irq.o pcie.o
+
+obj-$(CONFIG_MACH_DB88F6281_BP)                += db88f6281-bp-setup.o
+obj-$(CONFIG_MACH_RD88F6192_NAS)       += rd88f6192-nas-setup.o
+obj-$(CONFIG_MACH_RD88F6192_NAS)       += rd88f6281-setup.o
diff --git a/arch/arm/mach-kirkwood/Makefile.boot b/arch/arm/mach-kirkwood/Makefile.boot
new file mode 100644 (file)
index 0000000..67039c3
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00800000
diff --git a/arch/arm/mach-kirkwood/addr-map.c b/arch/arm/mach-kirkwood/addr-map.c
new file mode 100644 (file)
index 0000000..a39f0f3
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * arch/arm/mach-kirkwood/addr-map.c
+ *
+ * Address map functions for Marvell Kirkwood SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/mbus.h>
+#include <linux/io.h>
+#include <asm/hardware.h>
+#include "common.h"
+
+/*
+ * Generic Address Decode Windows bit settings
+ */
+#define TARGET_DDR             0
+#define TARGET_DEV_BUS         1
+#define TARGET_PCIE            4
+#define ATTR_DEV_SPI_ROM       0x1e
+#define ATTR_DEV_BOOT          0x1d
+#define ATTR_DEV_NAND          0x2f
+#define ATTR_DEV_CS3           0x37
+#define ATTR_DEV_CS2           0x3b
+#define ATTR_DEV_CS1           0x3d
+#define ATTR_DEV_CS0           0x3e
+#define ATTR_PCIE_IO           0xe0
+#define ATTR_PCIE_MEM          0xe8
+
+/*
+ * Helpers to get DDR bank info
+ */
+#define DDR_BASE_CS_OFF(n)     (0x0000 + ((n) << 3))
+#define DDR_SIZE_CS_OFF(n)     (0x0004 + ((n) << 3))
+
+/*
+ * CPU Address Decode Windows registers
+ */
+#define WIN_OFF(n)             (BRIDGE_VIRT_BASE + 0x0000 + ((n) << 4))
+#define WIN_CTRL_OFF           0x0000
+#define WIN_BASE_OFF           0x0004
+#define WIN_REMAP_LO_OFF       0x0008
+#define WIN_REMAP_HI_OFF       0x000c
+
+
+struct mbus_dram_target_info kirkwood_mbus_dram_info;
+
+static int __init cpu_win_can_remap(int win)
+{
+       if (win < 4)
+               return 1;
+
+       return 0;
+}
+
+static void __init setup_cpu_win(int win, u32 base, u32 size,
+                                u8 target, u8 attr, int remap)
+{
+       void __iomem *addr = (void __iomem *)WIN_OFF(win);
+       u32 ctrl;
+
+       base &= 0xffff0000;
+       ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
+
+       writel(base, addr + WIN_BASE_OFF);
+       writel(ctrl, addr + WIN_CTRL_OFF);
+       if (cpu_win_can_remap(win)) {
+               if (remap < 0)
+                       remap = base;
+
+               writel(remap & 0xffff0000, addr + WIN_REMAP_LO_OFF);
+               writel(0, addr + WIN_REMAP_HI_OFF);
+       }
+}
+
+void __init kirkwood_setup_cpu_mbus(void)
+{
+       void __iomem *addr;
+       int i;
+       int cs;
+
+       /*
+        * First, disable and clear windows.
+        */
+       for (i = 0; i < 8; i++) {
+               addr = (void __iomem *)WIN_OFF(i);
+
+               writel(0, addr + WIN_BASE_OFF);
+               writel(0, addr + WIN_CTRL_OFF);
+               if (cpu_win_can_remap(i)) {
+                       writel(0, addr + WIN_REMAP_LO_OFF);
+                       writel(0, addr + WIN_REMAP_HI_OFF);
+               }
+       }
+
+       /*
+        * Setup windows for PCIe IO+MEM space.
+        */
+       setup_cpu_win(0, KIRKWOOD_PCIE_IO_PHYS_BASE, KIRKWOOD_PCIE_IO_SIZE,
+                     TARGET_PCIE, ATTR_PCIE_IO, KIRKWOOD_PCIE_IO_BUS_BASE);
+       setup_cpu_win(1, KIRKWOOD_PCIE_MEM_PHYS_BASE, KIRKWOOD_PCIE_MEM_SIZE,
+                     TARGET_PCIE, ATTR_PCIE_MEM, -1);
+
+       /*
+        * Setup window for NAND controller.
+        */
+       setup_cpu_win(2, KIRKWOOD_NAND_MEM_PHYS_BASE, KIRKWOOD_NAND_MEM_SIZE,
+                     TARGET_DEV_BUS, ATTR_DEV_NAND, -1);
+
+       /*
+        * Setup MBUS dram target info.
+        */
+       kirkwood_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
+
+       addr = (void __iomem *)DDR_WINDOW_CPU_BASE;
+
+       for (i = 0, cs = 0; i < 4; i++) {
+               u32 base = readl(addr + DDR_BASE_CS_OFF(i));
+               u32 size = readl(addr + DDR_SIZE_CS_OFF(i));
+
+               /*
+                * Chip select enabled?
+                */
+               if (size & 1) {
+                       struct mbus_dram_window *w;
+
+                       w = &kirkwood_mbus_dram_info.cs[cs++];
+                       w->cs_index = i;
+                       w->mbus_attr = 0xf & ~(1 << i);
+                       w->base = base & 0xffff0000;
+                       w->size = (size | 0x0000ffff) + 1;
+               }
+       }
+       kirkwood_mbus_dram_info.num_cs = cs;
+}
diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
new file mode 100644 (file)
index 0000000..5938a3b
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+ * arch/arm/mach-kirkwood/common.c
+ *
+ * Core functions for Marvell Kirkwood SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/serial_8250.h>
+#include <linux/mbus.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/ata_platform.h>
+#include <asm/page.h>
+#include <asm/timex.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <asm/arch/kirkwood.h>
+#include <asm/plat-orion/cache-feroceon-l2.h>
+#include <asm/plat-orion/ehci-orion.h>
+#include <asm/plat-orion/orion_nand.h>
+#include <asm/plat-orion/time.h>
+#include "common.h"
+
+/*****************************************************************************
+ * I/O Address Mapping
+ ****************************************************************************/
+static struct map_desc kirkwood_io_desc[] __initdata = {
+       {
+               .virtual        = KIRKWOOD_PCIE_IO_VIRT_BASE,
+               .pfn            = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
+               .length         = KIRKWOOD_PCIE_IO_SIZE,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = KIRKWOOD_REGS_VIRT_BASE,
+               .pfn            = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
+               .length         = KIRKWOOD_REGS_SIZE,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init kirkwood_map_io(void)
+{
+       iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
+}
+
+
+/*****************************************************************************
+ * EHCI
+ ****************************************************************************/
+static struct orion_ehci_data kirkwood_ehci_data = {
+       .dram           = &kirkwood_mbus_dram_info,
+};
+
+static u64 ehci_dmamask = 0xffffffffUL;
+
+
+/*****************************************************************************
+ * EHCI0
+ ****************************************************************************/
+static struct resource kirkwood_ehci_resources[] = {
+       {
+               .start  = USB_PHYS_BASE,
+               .end    = USB_PHYS_BASE + 0x0fff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_KIRKWOOD_USB,
+               .end    = IRQ_KIRKWOOD_USB,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device kirkwood_ehci = {
+       .name           = "orion-ehci",
+       .id             = 0,
+       .dev            = {
+               .dma_mask               = &ehci_dmamask,
+               .coherent_dma_mask      = 0xffffffff,
+               .platform_data          = &kirkwood_ehci_data,
+       },
+       .resource       = kirkwood_ehci_resources,
+       .num_resources  = ARRAY_SIZE(kirkwood_ehci_resources),
+};
+
+void __init kirkwood_ehci_init(void)
+{
+       platform_device_register(&kirkwood_ehci);
+}
+
+
+/*****************************************************************************
+ * GE00
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
+       .t_clk          = KIRKWOOD_TCLK,
+       .dram           = &kirkwood_mbus_dram_info,
+};
+
+static struct resource kirkwood_ge00_shared_resources[] = {
+       {
+               .name   = "ge00 base",
+               .start  = GE00_PHYS_BASE + 0x2000,
+               .end    = GE00_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device kirkwood_ge00_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &kirkwood_ge00_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = kirkwood_ge00_shared_resources,
+};
+
+static struct resource kirkwood_ge00_resources[] = {
+       {
+               .name   = "ge00 irq",
+               .start  = IRQ_KIRKWOOD_GE00_SUM,
+               .end    = IRQ_KIRKWOOD_GE00_SUM,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device kirkwood_ge00 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 0,
+       .num_resources  = 1,
+       .resource       = kirkwood_ge00_resources,
+};
+
+void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &kirkwood_ge00_shared;
+       kirkwood_ge00.dev.platform_data = eth_data;
+
+       platform_device_register(&kirkwood_ge00_shared);
+       platform_device_register(&kirkwood_ge00);
+}
+
+
+/*****************************************************************************
+ * SoC RTC
+ ****************************************************************************/
+static struct resource kirkwood_rtc_resource = {
+       .start  = RTC_PHYS_BASE,
+       .end    = RTC_PHYS_BASE + SZ_16 - 1,
+       .flags  = IORESOURCE_MEM,
+};
+
+void __init kirkwood_rtc_init(void)
+{
+       platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
+}
+
+
+/*****************************************************************************
+ * SATA
+ ****************************************************************************/
+static struct resource kirkwood_sata_resources[] = {
+       {
+               .name   = "sata base",
+               .start  = SATA_PHYS_BASE,
+               .end    = SATA_PHYS_BASE + 0x5000 - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "sata irq",
+               .start  = IRQ_KIRKWOOD_SATA,
+               .end    = IRQ_KIRKWOOD_SATA,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device kirkwood_sata = {
+       .name           = "sata_mv",
+       .id             = 0,
+       .dev            = {
+               .coherent_dma_mask      = 0xffffffff,
+       },
+       .num_resources  = ARRAY_SIZE(kirkwood_sata_resources),
+       .resource       = kirkwood_sata_resources,
+};
+
+void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
+{
+       sata_data->dram = &kirkwood_mbus_dram_info;
+       kirkwood_sata.dev.platform_data = sata_data;
+       platform_device_register(&kirkwood_sata);
+}
+
+
+/*****************************************************************************
+ * UART0
+ ****************************************************************************/
+static struct plat_serial8250_port kirkwood_uart0_data[] = {
+       {
+               .mapbase        = UART0_PHYS_BASE,
+               .membase        = (char *)UART0_VIRT_BASE,
+               .irq            = IRQ_KIRKWOOD_UART_0,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = KIRKWOOD_TCLK,
+       }, {
+       },
+};
+
+static struct resource kirkwood_uart0_resources[] = {
+       {
+               .start          = UART0_PHYS_BASE,
+               .end            = UART0_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_KIRKWOOD_UART_0,
+               .end            = IRQ_KIRKWOOD_UART_0,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device kirkwood_uart0 = {
+       .name                   = "serial8250",
+       .id                     = 0,
+       .dev                    = {
+               .platform_data  = kirkwood_uart0_data,
+       },
+       .resource               = kirkwood_uart0_resources,
+       .num_resources          = ARRAY_SIZE(kirkwood_uart0_resources),
+};
+
+void __init kirkwood_uart0_init(void)
+{
+       platform_device_register(&kirkwood_uart0);
+}
+
+
+/*****************************************************************************
+ * UART1
+ ****************************************************************************/
+static struct plat_serial8250_port kirkwood_uart1_data[] = {
+       {
+               .mapbase        = UART1_PHYS_BASE,
+               .membase        = (char *)UART1_VIRT_BASE,
+               .irq            = IRQ_KIRKWOOD_UART_1,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = KIRKWOOD_TCLK,
+       }, {
+       },
+};
+
+static struct resource kirkwood_uart1_resources[] = {
+       {
+               .start          = UART1_PHYS_BASE,
+               .end            = UART1_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_KIRKWOOD_UART_1,
+               .end            = IRQ_KIRKWOOD_UART_1,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device kirkwood_uart1 = {
+       .name                   = "serial8250",
+       .id                     = 1,
+       .dev                    = {
+               .platform_data  = kirkwood_uart1_data,
+       },
+       .resource               = kirkwood_uart1_resources,
+       .num_resources          = ARRAY_SIZE(kirkwood_uart1_resources),
+};
+
+void __init kirkwood_uart1_init(void)
+{
+       platform_device_register(&kirkwood_uart1);
+}
+
+
+/*****************************************************************************
+ * Time handling
+ ****************************************************************************/
+static void kirkwood_timer_init(void)
+{
+       orion_time_init(IRQ_KIRKWOOD_BRIDGE, KIRKWOOD_TCLK);
+}
+
+struct sys_timer kirkwood_timer = {
+       .init = kirkwood_timer_init,
+};
+
+
+/*****************************************************************************
+ * General
+ ****************************************************************************/
+static char * __init kirkwood_id(void)
+{
+       switch (readl(DEVICE_ID) & 0x3) {
+       case 0:
+               return "88F6180";
+       case 1:
+               return "88F6192";
+       case 2:
+               return "88F6281";
+       }
+
+       return "unknown 88F6000 variant";
+}
+
+static int __init is_l2_writethrough(void)
+{
+       return !!(readl(L2_CONFIG_REG) & L2_WRITETHROUGH);
+}
+
+void __init kirkwood_init(void)
+{
+       printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
+               kirkwood_id(), KIRKWOOD_TCLK);
+
+       kirkwood_setup_cpu_mbus();
+
+#ifdef CONFIG_CACHE_FEROCEON_L2
+       feroceon_l2_init(is_l2_writethrough());
+#endif
+}
diff --git a/arch/arm/mach-kirkwood/common.h b/arch/arm/mach-kirkwood/common.h
new file mode 100644 (file)
index 0000000..5dee2f6
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * arch/arm/mach-kirkwood/common.h
+ *
+ * Core functions for Marvell Kirkwood SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ARCH_KIRKWOOD_COMMON_H
+#define __ARCH_KIRKWOOD_COMMON_H
+
+struct mv643xx_eth_platform_data;
+struct mv_sata_platform_data;
+
+/*
+ * Basic Kirkwood init functions used early by machine-setup.
+ */
+void kirkwood_map_io(void);
+void kirkwood_init(void);
+void kirkwood_init_irq(void);
+
+extern struct mbus_dram_target_info kirkwood_mbus_dram_info;
+void kirkwood_setup_cpu_mbus(void);
+void kirkwood_setup_pcie_io_win(int window, u32 base, u32 size,
+                               int maj, int min);
+void kirkwood_setup_pcie_mem_win(int window, u32 base, u32 size,
+                                int maj, int min);
+
+void kirkwood_ehci_init(void);
+void kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data);
+void kirkwood_pcie_init(void);
+void kirkwood_rtc_init(void);
+void kirkwood_sata_init(struct mv_sata_platform_data *sata_data);
+void kirkwood_uart0_init(void);
+void kirkwood_uart1_init(void);
+
+extern struct sys_timer kirkwood_timer;
+
+
+#endif
diff --git a/arch/arm/mach-kirkwood/db88f6281-bp-setup.c b/arch/arm/mach-kirkwood/db88f6281-bp-setup.c
new file mode 100644 (file)
index 0000000..d5c482c
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * arch/arm/mach-kirkwood/db88f6281-bp-setup.c
+ *
+ * Marvell DB-88F6281-BP Development Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/nand.h>
+#include <linux/timer.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/kirkwood.h>
+#include "common.h"
+
+static struct mv643xx_eth_platform_data db88f6281_ge00_data = {
+       .phy_addr       = 8,
+};
+
+static struct mv_sata_platform_data db88f6281_sata_data = {
+       .n_ports        = 2,
+};
+
+static void __init db88f6281_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+
+       kirkwood_ehci_init();
+       kirkwood_ge00_init(&db88f6281_ge00_data);
+       kirkwood_rtc_init();
+       kirkwood_sata_init(&db88f6281_sata_data);
+       kirkwood_uart0_init();
+       kirkwood_uart1_init();
+}
+
+static int __init db88f6281_pci_init(void)
+{
+       if (machine_is_db88f6281_bp())
+               kirkwood_pcie_init();
+
+       return 0;
+}
+subsys_initcall(db88f6281_pci_init);
+
+MACHINE_START(DB88F6281_BP, "Marvell DB-88F6281-BP Development Board")
+       /* Maintainer: Saeed Bishara <saeed@marvell.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = db88f6281_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
diff --git a/arch/arm/mach-kirkwood/irq.c b/arch/arm/mach-kirkwood/irq.c
new file mode 100644 (file)
index 0000000..302bb2c
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * arch/arm/mach-kirkwood/irq.c
+ *
+ * Kirkwood IRQ handling.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <asm/plat-orion/irq.h>
+#include "common.h"
+
+void __init kirkwood_init_irq(void)
+{
+       orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF));
+       orion_irq_init(32, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF));
+}
diff --git a/arch/arm/mach-kirkwood/pcie.c b/arch/arm/mach-kirkwood/pcie.c
new file mode 100644 (file)
index 0000000..8282d0f
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * arch/arm/mach-kirkwood/pcie.c
+ *
+ * PCIe functions for Marvell Kirkwood SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/mbus.h>
+#include <asm/mach/pci.h>
+#include <asm/plat-orion/pcie.h>
+#include "common.h"
+
+
+#define PCIE_BASE      ((void __iomem *)PCIE_VIRT_BASE)
+
+static int pcie_valid_config(int bus, int dev)
+{
+       /*
+        * Don't go out when trying to access --
+        * 1. nonexisting device on local bus
+        * 2. where there's no device connected (no link)
+        */
+       if (bus == 0 && dev == 0)
+               return 1;
+
+       if (!orion_pcie_link_up(PCIE_BASE))
+               return 0;
+
+       if (bus == 0 && dev != 1)
+               return 0;
+
+       return 1;
+}
+
+
+/*
+ * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
+ * and then reading the PCIE_CONF_DATA register. Need to make sure these
+ * transactions are atomic.
+ */
+static DEFINE_SPINLOCK(kirkwood_pcie_lock);
+
+static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
+                       int size, u32 *val)
+{
+       unsigned long flags;
+       int ret;
+
+       if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
+               *val = 0xffffffff;
+               return PCIBIOS_DEVICE_NOT_FOUND;
+       }
+
+       spin_lock_irqsave(&kirkwood_pcie_lock, flags);
+       ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
+
+       return ret;
+}
+
+static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
+                       int where, int size, u32 val)
+{
+       unsigned long flags;
+       int ret;
+
+       if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
+               return PCIBIOS_DEVICE_NOT_FOUND;
+
+       spin_lock_irqsave(&kirkwood_pcie_lock, flags);
+       ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
+
+       return ret;
+}
+
+static struct pci_ops pcie_ops = {
+       .read = pcie_rd_conf,
+       .write = pcie_wr_conf,
+};
+
+
+static int kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+       struct resource *res;
+
+       /*
+        * Generic PCIe unit setup.
+        */
+       orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
+
+       /*
+        * Request resources.
+        */
+       res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
+       if (!res)
+               panic("pcie_setup unable to alloc resources");
+
+       /*
+        * IORESOURCE_IO
+        */
+       res[0].name = "PCIe I/O Space";
+       res[0].flags = IORESOURCE_IO;
+       res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
+       res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
+       if (request_resource(&ioport_resource, &res[0]))
+               panic("Request PCIe IO resource failed\n");
+       sys->resource[0] = &res[0];
+
+       /*
+        * IORESOURCE_MEM
+        */
+       res[1].name = "PCIe Memory Space";
+       res[1].flags = IORESOURCE_MEM;
+       res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
+       res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
+       if (request_resource(&iomem_resource, &res[1]))
+               panic("Request PCIe Memory resource failed\n");
+       sys->resource[1] = &res[1];
+
+       sys->resource[2] = NULL;
+       sys->io_offset = 0;
+
+       return 1;
+}
+
+static void __devinit rc_pci_fixup(struct pci_dev *dev)
+{
+       /*
+        * Prevent enumeration of root complex.
+        */
+       if (dev->bus->parent == NULL && dev->devfn == 0) {
+               int i;
+
+               for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+                       dev->resource[i].start = 0;
+                       dev->resource[i].end   = 0;
+                       dev->resource[i].flags = 0;
+               }
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
+
+static struct pci_bus __init *
+kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
+{
+       struct pci_bus *bus;
+
+       if (nr == 0) {
+               bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
+       } else {
+               bus = NULL;
+               BUG();
+       }
+
+       return bus;
+}
+
+static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       return IRQ_KIRKWOOD_PCIE;
+}
+
+static struct hw_pci kirkwood_pci __initdata = {
+       .nr_controllers = 1,
+       .swizzle        = pci_std_swizzle,
+       .setup          = kirkwood_pcie_setup,
+       .scan           = kirkwood_pcie_scan_bus,
+       .map_irq        = kirkwood_pcie_map_irq,
+};
+
+void __init kirkwood_pcie_init(void)
+{
+       pci_common_init(&kirkwood_pci);
+}
diff --git a/arch/arm/mach-kirkwood/rd88f6192-nas-setup.c b/arch/arm/mach-kirkwood/rd88f6192-nas-setup.c
new file mode 100644 (file)
index 0000000..6cf642c
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * arch/arm/mach-kirkwood/rd88f6192-nas-setup.c
+ *
+ * Marvell RD-88F6192-NAS Reference Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/nand.h>
+#include <linux/timer.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/kirkwood.h>
+#include "common.h"
+
+#define RD88F6192_GPIO_USB_VBUS                10
+
+static struct mv643xx_eth_platform_data rd88f6192_ge00_data = {
+       .phy_addr       = 8,
+};
+
+static struct mv_sata_platform_data rd88f6192_sata_data = {
+       .n_ports        = 2,
+};
+
+static void __init rd88f6192_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+
+       kirkwood_ehci_init();
+       kirkwood_ge00_init(&rd88f6192_ge00_data);
+       kirkwood_rtc_init();
+       kirkwood_sata_init(&rd88f6192_sata_data);
+       kirkwood_uart0_init();
+}
+
+static int __init rd88f6192_pci_init(void)
+{
+       if (machine_is_rd88f6192_nas())
+               kirkwood_pcie_init();
+
+       return 0;
+}
+subsys_initcall(rd88f6192_pci_init);
+
+MACHINE_START(RD88F6192_NAS, "Marvell RD-88F6192-NAS Development Board")
+       /* Maintainer: Saeed Bishara <saeed@marvell.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = rd88f6192_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
diff --git a/arch/arm/mach-kirkwood/rd88f6281-setup.c b/arch/arm/mach-kirkwood/rd88f6281-setup.c
new file mode 100644 (file)
index 0000000..e1f8de2
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * arch/arm/mach-kirkwood/rd88f6281-setup.c
+ *
+ * Marvell RD-88F6281 Reference Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/nand.h>
+#include <linux/timer.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/kirkwood.h>
+#include <asm/plat-orion/orion_nand.h>
+#include "common.h"
+
+static struct mtd_partition rd88f6281_nand_parts[] = {
+       {
+               .name = "u-boot",
+               .offset = 0,
+               .size = SZ_1M
+       }, {
+               .name = "uImage",
+               .offset = MTDPART_OFS_NXTBLK,
+               .size = SZ_2M
+       }, {
+               .name = "root",
+               .offset = MTDPART_OFS_NXTBLK,
+               .size = MTDPART_SIZ_FULL
+       },
+};
+
+static struct resource rd88f6281_nand_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = KIRKWOOD_NAND_MEM_PHYS_BASE,
+       .end            = KIRKWOOD_NAND_MEM_PHYS_BASE +
+                         KIRKWOOD_NAND_MEM_SIZE - 1,
+};
+
+static struct orion_nand_data rd88f6281_nand_data = {
+       .parts          = rd88f6281_nand_parts,
+       .nr_parts       = ARRAY_SIZE(rd88f6281_nand_parts),
+       .cle            = 0,
+       .ale            = 1,
+       .width          = 8,
+       .chip_delay     = 25,
+};
+
+static struct platform_device rd88f6281_nand_flash = {
+       .name           = "orion_nand",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &rd88f6281_nand_data,
+       },
+       .resource       = &rd88f6281_nand_resource,
+       .num_resources  = 1,
+};
+
+static struct mv643xx_eth_platform_data rd88f6281_ge00_data = {
+       .phy_addr       = -1,
+};
+
+static struct mv_sata_platform_data rd88f6281_sata_data = {
+       .n_ports        = 2,
+};
+
+static void __init rd88f6281_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+
+       kirkwood_ehci_init();
+       kirkwood_ge00_init(&rd88f6281_ge00_data);
+       kirkwood_rtc_init();
+       kirkwood_sata_init(&rd88f6281_sata_data);
+       kirkwood_uart0_init();
+       kirkwood_uart1_init();
+
+       platform_device_register(&rd88f6281_nand_flash);
+}
+
+static int __init rd88f6281_pci_init(void)
+{
+       if (machine_is_rd88f6281())
+               kirkwood_pcie_init();
+
+       return 0;
+}
+subsys_initcall(rd88f6281_pci_init);
+
+MACHINE_START(RD88F6281, "Marvell RD-88F6281 Reference Board")
+       /* Maintainer: Saeed Bishara <saeed@marvell.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = rd88f6281_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
diff --git a/arch/arm/mach-loki/Kconfig b/arch/arm/mach-loki/Kconfig
new file mode 100644 (file)
index 0000000..0045bdd
--- /dev/null
@@ -0,0 +1,13 @@
+if ARCH_LOKI
+
+menu "Marvell Loki (88RC8480) Implementations"
+
+config MACH_LB88RC8480
+       bool "Marvell LB88RC8480 Development Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell LB88RC8480 Development Board.
+
+endmenu
+
+endif
diff --git a/arch/arm/mach-loki/Makefile b/arch/arm/mach-loki/Makefile
new file mode 100644 (file)
index 0000000..d43233e
--- /dev/null
@@ -0,0 +1,3 @@
+obj-y                          += common.o addr-map.o irq.o
+
+obj-$(CONFIG_MACH_LB88RC8480)  += lb88rc8480-setup.o
diff --git a/arch/arm/mach-loki/Makefile.boot b/arch/arm/mach-loki/Makefile.boot
new file mode 100644 (file)
index 0000000..67039c3
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00800000
diff --git a/arch/arm/mach-loki/addr-map.c b/arch/arm/mach-loki/addr-map.c
new file mode 100644 (file)
index 0000000..ba25e56
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * arch/arm/mach-loki/addr-map.c
+ *
+ * Address map functions for Marvell Loki (88RC8480) SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/mbus.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include "common.h"
+
+/*
+ * Generic Address Decode Windows bit settings
+ */
+#define TARGET_DDR             0
+#define TARGET_DEV_BUS         1
+#define TARGET_PCIE0           3
+#define TARGET_PCIE1           4
+#define ATTR_DEV_BOOT          0x0f
+#define ATTR_DEV_CS2           0x1b
+#define ATTR_DEV_CS1           0x1d
+#define ATTR_DEV_CS0           0x1e
+#define ATTR_PCIE_IO           0x51
+#define ATTR_PCIE_MEM          0x59
+
+/*
+ * Helpers to get DDR bank info
+ */
+#define DDR_SIZE_CS(n)         DDR_REG(0x1500 + ((n) << 3))
+#define DDR_BASE_CS(n)         DDR_REG(0x1504 + ((n) << 3))
+
+/*
+ * CPU Address Decode Windows registers
+ */
+#define CPU_WIN_CTRL(n)                BRIDGE_REG(0x000 | ((n) << 4))
+#define CPU_WIN_BASE(n)                BRIDGE_REG(0x004 | ((n) << 4))
+#define CPU_WIN_REMAP_LO(n)    BRIDGE_REG(0x008 | ((n) << 4))
+#define CPU_WIN_REMAP_HI(n)    BRIDGE_REG(0x00c | ((n) << 4))
+
+
+struct mbus_dram_target_info loki_mbus_dram_info;
+
+static void __init setup_cpu_win(int win, u32 base, u32 size,
+                                u8 target, u8 attr, int remap)
+{
+       u32 ctrl;
+
+       base &= 0xffff0000;
+       ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (1 << 5) | target;
+
+       writel(base, CPU_WIN_BASE(win));
+       writel(ctrl, CPU_WIN_CTRL(win));
+       if (win < 2) {
+               if (remap < 0)
+                       remap = base;
+
+               writel(remap & 0xffff0000, CPU_WIN_REMAP_LO(win));
+               writel(0, CPU_WIN_REMAP_HI(win));
+       }
+}
+
+void __init loki_setup_cpu_mbus(void)
+{
+       int i;
+       int cs;
+
+       /*
+        * First, disable and clear windows.
+        */
+       for (i = 0; i < 8; i++) {
+               writel(0, CPU_WIN_BASE(i));
+               writel(0, CPU_WIN_CTRL(i));
+               if (i < 2) {
+                       writel(0, CPU_WIN_REMAP_LO(i));
+                       writel(0, CPU_WIN_REMAP_HI(i));
+               }
+       }
+
+       /*
+        * Setup windows for PCIe IO+MEM space.
+        */
+       setup_cpu_win(2, LOKI_PCIE0_MEM_PHYS_BASE, LOKI_PCIE0_MEM_SIZE,
+                     TARGET_PCIE0, ATTR_PCIE_MEM, -1);
+       setup_cpu_win(3, LOKI_PCIE1_MEM_PHYS_BASE, LOKI_PCIE1_MEM_SIZE,
+                     TARGET_PCIE1, ATTR_PCIE_MEM, -1);
+
+       /*
+        * Setup MBUS dram target info.
+        */
+       loki_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
+
+       for (i = 0, cs = 0; i < 4; i++) {
+               u32 base = readl(DDR_BASE_CS(i));
+               u32 size = readl(DDR_SIZE_CS(i));
+
+               /*
+                * Chip select enabled?
+                */
+               if (size & 1) {
+                       struct mbus_dram_window *w;
+
+                       w = &loki_mbus_dram_info.cs[cs++];
+                       w->cs_index = i;
+                       w->mbus_attr = 0xf & ~(1 << i);
+                       w->base = base & 0xffff0000;
+                       w->size = (size | 0x0000ffff) + 1;
+               }
+       }
+       loki_mbus_dram_info.num_cs = cs;
+}
+
+void __init loki_setup_dev_boot_win(u32 base, u32 size)
+{
+       setup_cpu_win(4, base, size, TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);
+}
diff --git a/arch/arm/mach-loki/common.c b/arch/arm/mach-loki/common.c
new file mode 100644 (file)
index 0000000..410f503
--- /dev/null
@@ -0,0 +1,305 @@
+/*
+ * arch/arm/mach-loki/common.c
+ *
+ * Core functions for Marvell Loki (88RC8480) SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/serial_8250.h>
+#include <linux/mbus.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/page.h>
+#include <asm/timex.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <asm/arch/loki.h>
+#include <asm/plat-orion/orion_nand.h>
+#include <asm/plat-orion/time.h>
+#include "common.h"
+
+/*****************************************************************************
+ * I/O Address Mapping
+ ****************************************************************************/
+static struct map_desc loki_io_desc[] __initdata = {
+       {
+               .virtual        = LOKI_REGS_VIRT_BASE,
+               .pfn            = __phys_to_pfn(LOKI_REGS_PHYS_BASE),
+               .length         = LOKI_REGS_SIZE,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init loki_map_io(void)
+{
+       iotable_init(loki_io_desc, ARRAY_SIZE(loki_io_desc));
+}
+
+
+/*****************************************************************************
+ * GE0
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data loki_ge0_shared_data = {
+       .t_clk          = LOKI_TCLK,
+       .dram           = &loki_mbus_dram_info,
+};
+
+static struct resource loki_ge0_shared_resources[] = {
+       {
+               .name   = "ge0 base",
+               .start  = GE0_PHYS_BASE + 0x2000,
+               .end    = GE0_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device loki_ge0_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &loki_ge0_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = loki_ge0_shared_resources,
+};
+
+static struct resource loki_ge0_resources[] = {
+       {
+               .name   = "ge0 irq",
+               .start  = IRQ_LOKI_GBE_A_INT,
+               .end    = IRQ_LOKI_GBE_A_INT,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device loki_ge0 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 0,
+       .num_resources  = 1,
+       .resource       = loki_ge0_resources,
+};
+
+void __init loki_ge0_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &loki_ge0_shared;
+       loki_ge0.dev.platform_data = eth_data;
+
+       writel(0x00079220, GE0_VIRT_BASE + 0x20b0);
+       platform_device_register(&loki_ge0_shared);
+       platform_device_register(&loki_ge0);
+}
+
+
+/*****************************************************************************
+ * GE1
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data loki_ge1_shared_data = {
+       .t_clk          = LOKI_TCLK,
+       .dram           = &loki_mbus_dram_info,
+};
+
+static struct resource loki_ge1_shared_resources[] = {
+       {
+               .name   = "ge1 base",
+               .start  = GE1_PHYS_BASE + 0x2000,
+               .end    = GE1_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device loki_ge1_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 1,
+       .dev            = {
+               .platform_data  = &loki_ge1_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = loki_ge1_shared_resources,
+};
+
+static struct resource loki_ge1_resources[] = {
+       {
+               .name   = "ge1 irq",
+               .start  = IRQ_LOKI_GBE_B_INT,
+               .end    = IRQ_LOKI_GBE_B_INT,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device loki_ge1 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 1,
+       .num_resources  = 1,
+       .resource       = loki_ge1_resources,
+};
+
+void __init loki_ge1_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &loki_ge1_shared;
+       loki_ge1.dev.platform_data = eth_data;
+
+       writel(0x00079220, GE1_VIRT_BASE + 0x20b0);
+       platform_device_register(&loki_ge1_shared);
+       platform_device_register(&loki_ge1);
+}
+
+
+/*****************************************************************************
+ * SAS/SATA
+ ****************************************************************************/
+static struct resource loki_sas_resources[] = {
+       {
+               .name   = "mvsas0 mem",
+               .start  = SAS0_PHYS_BASE,
+               .end    = SAS0_PHYS_BASE + 0x01ff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "mvsas0 irq",
+               .start  = IRQ_LOKI_SAS_A,
+               .end    = IRQ_LOKI_SAS_A,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .name   = "mvsas1 mem",
+               .start  = SAS1_PHYS_BASE,
+               .end    = SAS1_PHYS_BASE + 0x01ff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "mvsas1 irq",
+               .start  = IRQ_LOKI_SAS_B,
+               .end    = IRQ_LOKI_SAS_B,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device loki_sas = {
+       .name           = "mvsas",
+       .id             = 0,
+       .dev            = {
+               .coherent_dma_mask      = 0xffffffff,
+       },
+       .num_resources  = ARRAY_SIZE(loki_sas_resources),
+       .resource       = loki_sas_resources,
+};
+
+void __init loki_sas_init(void)
+{
+       writel(0x8300f707, DDR_REG(0x1424));
+       platform_device_register(&loki_sas);
+}
+
+
+/*****************************************************************************
+ * UART0
+ ****************************************************************************/
+static struct plat_serial8250_port loki_uart0_data[] = {
+       {
+               .mapbase        = UART0_PHYS_BASE,
+               .membase        = (char *)UART0_VIRT_BASE,
+               .irq            = IRQ_LOKI_UART0,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = LOKI_TCLK,
+       }, {
+       },
+};
+
+static struct resource loki_uart0_resources[] = {
+       {
+               .start          = UART0_PHYS_BASE,
+               .end            = UART0_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_LOKI_UART0,
+               .end            = IRQ_LOKI_UART0,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device loki_uart0 = {
+       .name                   = "serial8250",
+       .id                     = 0,
+       .dev                    = {
+               .platform_data  = loki_uart0_data,
+       },
+       .resource               = loki_uart0_resources,
+       .num_resources          = ARRAY_SIZE(loki_uart0_resources),
+};
+
+void __init loki_uart0_init(void)
+{
+       platform_device_register(&loki_uart0);
+}
+
+
+/*****************************************************************************
+ * UART1
+ ****************************************************************************/
+static struct plat_serial8250_port loki_uart1_data[] = {
+       {
+               .mapbase        = UART1_PHYS_BASE,
+               .membase        = (char *)UART1_VIRT_BASE,
+               .irq            = IRQ_LOKI_UART1,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = LOKI_TCLK,
+       }, {
+       },
+};
+
+static struct resource loki_uart1_resources[] = {
+       {
+               .start          = UART1_PHYS_BASE,
+               .end            = UART1_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_LOKI_UART1,
+               .end            = IRQ_LOKI_UART1,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device loki_uart1 = {
+       .name                   = "serial8250",
+       .id                     = 1,
+       .dev                    = {
+               .platform_data  = loki_uart1_data,
+       },
+       .resource               = loki_uart1_resources,
+       .num_resources          = ARRAY_SIZE(loki_uart1_resources),
+};
+
+void __init loki_uart1_init(void)
+{
+       platform_device_register(&loki_uart1);
+}
+
+
+/*****************************************************************************
+ * Time handling
+ ****************************************************************************/
+static void loki_timer_init(void)
+{
+       orion_time_init(IRQ_LOKI_BRIDGE, LOKI_TCLK);
+}
+
+struct sys_timer loki_timer = {
+       .init = loki_timer_init,
+};
+
+
+/*****************************************************************************
+ * General
+ ****************************************************************************/
+void __init loki_init(void)
+{
+       printk(KERN_INFO "Loki ID: 88RC8480. TCLK=%d.\n", LOKI_TCLK);
+
+       loki_setup_cpu_mbus();
+}
diff --git a/arch/arm/mach-loki/common.h b/arch/arm/mach-loki/common.h
new file mode 100644 (file)
index 0000000..26054fd
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * arch/arm/mach-loki/common.h
+ *
+ * Core functions for Marvell Loki (88RC8480) SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ARCH_LOKI_COMMON_H
+#define __ARCH_LOKI_COMMON_H
+
+struct mv643xx_eth_platform_data;
+
+/*
+ * Basic Loki init functions used early by machine-setup.
+ */
+void loki_map_io(void);
+void loki_init(void);
+void loki_init_irq(void);
+
+extern struct mbus_dram_target_info loki_mbus_dram_info;
+void loki_setup_cpu_mbus(void);
+void loki_setup_dev_boot_win(u32 base, u32 size);
+
+void loki_ge0_init(struct mv643xx_eth_platform_data *eth_data);
+void loki_ge1_init(struct mv643xx_eth_platform_data *eth_data);
+void loki_sas_init(void);
+void loki_uart0_init(void);
+void loki_uart1_init(void);
+
+extern struct sys_timer loki_timer;
+
+
+#endif
diff --git a/arch/arm/mach-loki/irq.c b/arch/arm/mach-loki/irq.c
new file mode 100644 (file)
index 0000000..d839af9
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * arch/arm/mach-loki/irq.c
+ *
+ * Marvell Loki (88RC8480) IRQ handling.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/irq.h>
+#include <asm/io.h>
+#include <asm/plat-orion/irq.h>
+#include "common.h"
+
+void __init loki_init_irq(void)
+{
+       orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_OFF));
+}
diff --git a/arch/arm/mach-loki/lb88rc8480-setup.c b/arch/arm/mach-loki/lb88rc8480-setup.c
new file mode 100644 (file)
index 0000000..d1b9e6e
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * arch/arm/mach-loki/lb88rc8480-setup.c
+ *
+ * Marvell LB88RC8480 Development Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/nand.h>
+#include <linux/timer.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/arch/loki.h>
+#include "common.h"
+
+#define LB88RC8480_FLASH_BOOT_CS_BASE  0xf8000000
+#define LB88RC8480_FLASH_BOOT_CS_SIZE  SZ_128M
+
+#define LB88RC8480_NOR_BOOT_BASE       0xff000000
+#define LB88RC8480_NOR_BOOT_SIZE       SZ_16M
+
+static struct mtd_partition lb88rc8480_boot_flash_parts[] = {
+       {
+               .name   = "kernel",
+               .offset = 0,
+               .size   = SZ_2M,
+       }, {
+               .name   = "root-fs",
+               .offset = SZ_2M,
+               .size   = (SZ_8M + SZ_4M + SZ_1M),
+       }, {
+               .name   = "u-boot",
+               .offset = (SZ_8M + SZ_4M + SZ_2M + SZ_1M),
+               .size   = SZ_1M,
+       },
+};
+
+static struct physmap_flash_data lb88rc8480_boot_flash_data = {
+       .parts          = lb88rc8480_boot_flash_parts,
+       .nr_parts       = ARRAY_SIZE(lb88rc8480_boot_flash_parts),
+       .width          = 1,    /* 8 bit bus width */
+};
+
+static struct resource lb88rc8480_boot_flash_resource = {
+       .flags  = IORESOURCE_MEM,
+       .start  = LB88RC8480_NOR_BOOT_BASE,
+       .end    = LB88RC8480_NOR_BOOT_BASE + LB88RC8480_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device lb88rc8480_boot_flash = {
+       .name   = "physmap-flash",
+       .id     = 0,
+       .dev    = {
+               .platform_data  = &lb88rc8480_boot_flash_data,
+       },
+       .num_resources  = 1,
+       .resource       = &lb88rc8480_boot_flash_resource,
+};
+
+static struct mv643xx_eth_platform_data lb88rc8480_ge0_data = {
+       .phy_addr       = 1,
+       .mac_addr       = { 0x00, 0x50, 0x43, 0x11, 0x22, 0x33 },
+};
+
+static void __init lb88rc8480_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       loki_init();
+
+       loki_ge0_init(&lb88rc8480_ge0_data);
+       loki_sas_init();
+       loki_uart0_init();
+       loki_uart1_init();
+
+       loki_setup_dev_boot_win(LB88RC8480_FLASH_BOOT_CS_BASE,
+                               LB88RC8480_FLASH_BOOT_CS_SIZE);
+       platform_device_register(&lb88rc8480_boot_flash);
+}
+
+MACHINE_START(LB88RC8480, "Marvell LB88RC8480 Development Board")
+       /* Maintainer: Ke Wei <kewei@marvell.com> */
+       .phys_io        = LOKI_REGS_PHYS_BASE,
+       .io_pg_offst    = ((LOKI_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = lb88rc8480_init,
+       .map_io         = loki_map_io,
+       .init_irq       = loki_init_irq,
+       .timer          = &loki_timer,
+MACHINE_END
diff --git a/arch/arm/mach-mv78xx0/Kconfig b/arch/arm/mach-mv78xx0/Kconfig
new file mode 100644 (file)
index 0000000..d83cb86
--- /dev/null
@@ -0,0 +1,13 @@
+if ARCH_MV78XX0
+
+menu "Marvell MV78xx0 Implementations"
+
+config MACH_DB78X00_BP
+       bool "Marvell DB-78x00-BP Development Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell DB-78x00-BP Development Board.
+
+endmenu
+
+endif
diff --git a/arch/arm/mach-mv78xx0/Makefile b/arch/arm/mach-mv78xx0/Makefile
new file mode 100644 (file)
index 0000000..ec16c05
--- /dev/null
@@ -0,0 +1,2 @@
+obj-y                          += common.o addr-map.o irq.o pcie.o
+obj-$(CONFIG_MACH_DB78X00_BP)  += db78x00-bp-setup.o
diff --git a/arch/arm/mach-mv78xx0/Makefile.boot b/arch/arm/mach-mv78xx0/Makefile.boot
new file mode 100644 (file)
index 0000000..67039c3
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00800000
diff --git a/arch/arm/mach-mv78xx0/addr-map.c b/arch/arm/mach-mv78xx0/addr-map.c
new file mode 100644 (file)
index 0000000..4004b67
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * arch/arm/mach-mv78xx0/addr-map.c
+ *
+ * Address map functions for Marvell MV78xx0 SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/mbus.h>
+#include <asm/io.h>
+#include "common.h"
+
+/*
+ * Generic Address Decode Windows bit settings
+ */
+#define TARGET_DDR             0
+#define TARGET_DEV_BUS         1
+#define TARGET_PCIE0           4
+#define TARGET_PCIE1           8
+#define TARGET_PCIE(i)         ((i) ? TARGET_PCIE1 : TARGET_PCIE0)
+#define ATTR_DEV_SPI_ROM       0x1f
+#define ATTR_DEV_BOOT          0x2f
+#define ATTR_DEV_CS3           0x37
+#define ATTR_DEV_CS2           0x3b
+#define ATTR_DEV_CS1           0x3d
+#define ATTR_DEV_CS0           0x3e
+#define ATTR_PCIE_IO(l)                (0xf0 & ~(0x10 << (l)))
+#define ATTR_PCIE_MEM(l)       (0xf8 & ~(0x10 << (l)))
+
+/*
+ * Helpers to get DDR bank info
+ */
+#define DDR_BASE_CS_OFF(n)     (0x0000 + ((n) << 3))
+#define DDR_SIZE_CS_OFF(n)     (0x0004 + ((n) << 3))
+
+/*
+ * CPU Address Decode Windows registers
+ */
+#define WIN0_OFF(n)            (BRIDGE_VIRT_BASE + 0x0000 + ((n) << 4))
+#define WIN8_OFF(n)            (BRIDGE_VIRT_BASE + 0x0900 + (((n) - 8) << 4))
+#define WIN_CTRL_OFF           0x0000
+#define WIN_BASE_OFF           0x0004
+#define WIN_REMAP_LO_OFF       0x0008
+#define WIN_REMAP_HI_OFF       0x000c
+
+
+struct mbus_dram_target_info mv78xx0_mbus_dram_info;
+
+static void __init __iomem *win_cfg_base(int win)
+{
+       /*
+        * Find the control register base address for this window.
+        *
+        * BRIDGE_VIRT_BASE points to the right (CPU0's or CPU1's)
+        * MBUS bridge depending on which CPU core we're running on,
+        * so we don't need to take that into account here.
+        */
+
+       return (void __iomem *)((win < 8) ? WIN0_OFF(win) : WIN8_OFF(win));
+}
+
+static int __init cpu_win_can_remap(int win)
+{
+       if (win < 8)
+               return 1;
+
+       return 0;
+}
+
+static void __init setup_cpu_win(int win, u32 base, u32 size,
+                                u8 target, u8 attr, int remap)
+{
+       void __iomem *addr = win_cfg_base(win);
+       u32 ctrl;
+
+       base &= 0xffff0000;
+       ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
+
+       writel(base, addr + WIN_BASE_OFF);
+       writel(ctrl, addr + WIN_CTRL_OFF);
+       if (cpu_win_can_remap(win)) {
+               if (remap < 0)
+                       remap = base;
+
+               writel(remap & 0xffff0000, addr + WIN_REMAP_LO_OFF);
+               writel(0, addr + WIN_REMAP_HI_OFF);
+       }
+}
+
+void __init mv78xx0_setup_cpu_mbus(void)
+{
+       void __iomem *addr;
+       int i;
+       int cs;
+
+       /*
+        * First, disable and clear windows.
+        */
+       for (i = 0; i < 14; i++) {
+               addr = win_cfg_base(i);
+
+               writel(0, addr + WIN_BASE_OFF);
+               writel(0, addr + WIN_CTRL_OFF);
+               if (cpu_win_can_remap(i)) {
+                       writel(0, addr + WIN_REMAP_LO_OFF);
+                       writel(0, addr + WIN_REMAP_HI_OFF);
+               }
+       }
+
+       /*
+        * Setup MBUS dram target info.
+        */
+       mv78xx0_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
+
+       if (mv78xx0_core_index() == 0)
+               addr = (void __iomem *)DDR_WINDOW_CPU0_BASE;
+       else
+               addr = (void __iomem *)DDR_WINDOW_CPU1_BASE;
+
+       for (i = 0, cs = 0; i < 4; i++) {
+               u32 base = readl(addr + DDR_BASE_CS_OFF(i));
+               u32 size = readl(addr + DDR_SIZE_CS_OFF(i));
+
+               /*
+                * Chip select enabled?
+                */
+               if (size & 1) {
+                       struct mbus_dram_window *w;
+
+                       w = &mv78xx0_mbus_dram_info.cs[cs++];
+                       w->cs_index = i;
+                       w->mbus_attr = 0xf & ~(1 << i);
+                       w->base = base & 0xffff0000;
+                       w->size = (size | 0x0000ffff) + 1;
+               }
+       }
+       mv78xx0_mbus_dram_info.num_cs = cs;
+}
+
+void __init mv78xx0_setup_pcie_io_win(int window, u32 base, u32 size,
+                                     int maj, int min)
+{
+       setup_cpu_win(window, base, size, TARGET_PCIE(maj),
+                     ATTR_PCIE_IO(min), -1);
+}
+
+void __init mv78xx0_setup_pcie_mem_win(int window, u32 base, u32 size,
+                                      int maj, int min)
+{
+       setup_cpu_win(window, base, size, TARGET_PCIE(maj),
+                     ATTR_PCIE_MEM(min), -1);
+}
diff --git a/arch/arm/mach-mv78xx0/common.c b/arch/arm/mach-mv78xx0/common.c
new file mode 100644 (file)
index 0000000..d27b83b
--- /dev/null
@@ -0,0 +1,754 @@
+/*
+ * arch/arm/mach-mv78xx0/common.c
+ *
+ * Core functions for Marvell MV78xx0 SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/serial_8250.h>
+#include <linux/mbus.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/ata_platform.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <asm/arch/mv78xx0.h>
+#include <asm/plat-orion/cache-feroceon-l2.h>
+#include <asm/plat-orion/ehci-orion.h>
+#include <asm/plat-orion/orion_nand.h>
+#include <asm/plat-orion/time.h>
+#include "common.h"
+
+
+/*****************************************************************************
+ * Common bits
+ ****************************************************************************/
+int mv78xx0_core_index(void)
+{
+       u32 extra;
+
+       /*
+        * Read Extra Features register.
+        */
+       __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
+
+       return !!(extra & 0x00004000);
+}
+
+static int get_hclk(void)
+{
+       int hclk;
+
+       /*
+        * HCLK tick rate is configured by DEV_D[7:5] pins.
+        */
+       switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
+       case 0:
+               hclk = 166666667;
+               break;
+       case 1:
+               hclk = 200000000;
+               break;
+       case 2:
+               hclk = 266666667;
+               break;
+       case 3:
+               hclk = 333333333;
+               break;
+       case 4:
+               hclk = 400000000;
+               break;
+       default:
+               panic("unknown HCLK PLL setting: %.8x\n",
+                       readl(SAMPLE_AT_RESET_LOW));
+       }
+
+       return hclk;
+}
+
+static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
+{
+       u32 cfg;
+
+       /*
+        * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
+        * PCLK/L2CLK by bits [19:14].
+        */
+       if (core_index == 0) {
+               cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
+       } else {
+               cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
+       }
+
+       /*
+        * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
+        * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
+        */
+       *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
+
+       /*
+        * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
+        * ratio (1, 2, 3).
+        */
+       *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
+}
+
+static int get_tclk(void)
+{
+       int tclk;
+
+       /*
+        * TCLK tick rate is configured by DEV_A[2:0] strap pins.
+        */
+       switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
+       case 1:
+               tclk = 166666667;
+               break;
+       case 3:
+               tclk = 200000000;
+               break;
+       default:
+               panic("unknown TCLK PLL setting: %.8x\n",
+                       readl(SAMPLE_AT_RESET_HIGH));
+       }
+
+       return tclk;
+}
+
+
+/*****************************************************************************
+ * I/O Address Mapping
+ ****************************************************************************/
+static struct map_desc mv78xx0_io_desc[] __initdata = {
+       {
+               .virtual        = MV78XX0_CORE_REGS_VIRT_BASE,
+               .pfn            = 0,
+               .length         = MV78XX0_CORE_REGS_SIZE,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = MV78XX0_PCIE_IO_VIRT_BASE(0),
+               .pfn            = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
+               .length         = MV78XX0_PCIE_IO_SIZE * 8,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = MV78XX0_REGS_VIRT_BASE,
+               .pfn            = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
+               .length         = MV78XX0_REGS_SIZE,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init mv78xx0_map_io(void)
+{
+       unsigned long phys;
+
+       /*
+        * Map the right set of per-core registers depending on
+        * which core we are running on.
+        */
+       if (mv78xx0_core_index() == 0) {
+               phys = MV78XX0_CORE0_REGS_PHYS_BASE;
+       } else {
+               phys = MV78XX0_CORE1_REGS_PHYS_BASE;
+       }
+       mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
+
+       iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
+}
+
+
+/*****************************************************************************
+ * EHCI
+ ****************************************************************************/
+static struct orion_ehci_data mv78xx0_ehci_data = {
+       .dram           = &mv78xx0_mbus_dram_info,
+};
+
+static u64 ehci_dmamask = 0xffffffffUL;
+
+
+/*****************************************************************************
+ * EHCI0
+ ****************************************************************************/
+static struct resource mv78xx0_ehci0_resources[] = {
+       {
+               .start  = USB0_PHYS_BASE,
+               .end    = USB0_PHYS_BASE + 0x0fff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_MV78XX0_USB_0,
+               .end    = IRQ_MV78XX0_USB_0,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ehci0 = {
+       .name           = "orion-ehci",
+       .id             = 0,
+       .dev            = {
+               .dma_mask               = &ehci_dmamask,
+               .coherent_dma_mask      = 0xffffffff,
+               .platform_data          = &mv78xx0_ehci_data,
+       },
+       .resource       = mv78xx0_ehci0_resources,
+       .num_resources  = ARRAY_SIZE(mv78xx0_ehci0_resources),
+};
+
+void __init mv78xx0_ehci0_init(void)
+{
+       platform_device_register(&mv78xx0_ehci0);
+}
+
+
+/*****************************************************************************
+ * EHCI1
+ ****************************************************************************/
+static struct resource mv78xx0_ehci1_resources[] = {
+       {
+               .start  = USB1_PHYS_BASE,
+               .end    = USB1_PHYS_BASE + 0x0fff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_MV78XX0_USB_1,
+               .end    = IRQ_MV78XX0_USB_1,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ehci1 = {
+       .name           = "orion-ehci",
+       .id             = 1,
+       .dev            = {
+               .dma_mask               = &ehci_dmamask,
+               .coherent_dma_mask      = 0xffffffff,
+               .platform_data          = &mv78xx0_ehci_data,
+       },
+       .resource       = mv78xx0_ehci1_resources,
+       .num_resources  = ARRAY_SIZE(mv78xx0_ehci1_resources),
+};
+
+void __init mv78xx0_ehci1_init(void)
+{
+       platform_device_register(&mv78xx0_ehci1);
+}
+
+
+/*****************************************************************************
+ * EHCI2
+ ****************************************************************************/
+static struct resource mv78xx0_ehci2_resources[] = {
+       {
+               .start  = USB2_PHYS_BASE,
+               .end    = USB2_PHYS_BASE + 0x0fff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_MV78XX0_USB_2,
+               .end    = IRQ_MV78XX0_USB_2,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ehci2 = {
+       .name           = "orion-ehci",
+       .id             = 2,
+       .dev            = {
+               .dma_mask               = &ehci_dmamask,
+               .coherent_dma_mask      = 0xffffffff,
+               .platform_data          = &mv78xx0_ehci_data,
+       },
+       .resource       = mv78xx0_ehci2_resources,
+       .num_resources  = ARRAY_SIZE(mv78xx0_ehci2_resources),
+};
+
+void __init mv78xx0_ehci2_init(void)
+{
+       platform_device_register(&mv78xx0_ehci2);
+}
+
+
+/*****************************************************************************
+ * GE00
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data mv78xx0_ge00_shared_data = {
+       .t_clk          = 0,
+       .dram           = &mv78xx0_mbus_dram_info,
+};
+
+static struct resource mv78xx0_ge00_shared_resources[] = {
+       {
+               .name   = "ge00 base",
+               .start  = GE00_PHYS_BASE + 0x2000,
+               .end    = GE00_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device mv78xx0_ge00_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &mv78xx0_ge00_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge00_shared_resources,
+};
+
+static struct resource mv78xx0_ge00_resources[] = {
+       {
+               .name   = "ge00 irq",
+               .start  = IRQ_MV78XX0_GE00_SUM,
+               .end    = IRQ_MV78XX0_GE00_SUM,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ge00 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 0,
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge00_resources,
+};
+
+void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &mv78xx0_ge00_shared;
+       mv78xx0_ge00.dev.platform_data = eth_data;
+
+       platform_device_register(&mv78xx0_ge00_shared);
+       platform_device_register(&mv78xx0_ge00);
+}
+
+
+/*****************************************************************************
+ * GE01
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data mv78xx0_ge01_shared_data = {
+       .t_clk          = 0,
+       .dram           = &mv78xx0_mbus_dram_info,
+};
+
+static struct resource mv78xx0_ge01_shared_resources[] = {
+       {
+               .name   = "ge01 base",
+               .start  = GE01_PHYS_BASE + 0x2000,
+               .end    = GE01_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device mv78xx0_ge01_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 1,
+       .dev            = {
+               .platform_data  = &mv78xx0_ge01_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge01_shared_resources,
+};
+
+static struct resource mv78xx0_ge01_resources[] = {
+       {
+               .name   = "ge01 irq",
+               .start  = IRQ_MV78XX0_GE01_SUM,
+               .end    = IRQ_MV78XX0_GE01_SUM,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ge01 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 1,
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge01_resources,
+};
+
+void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &mv78xx0_ge01_shared;
+       eth_data->shared_smi = &mv78xx0_ge00_shared;
+       mv78xx0_ge01.dev.platform_data = eth_data;
+
+       platform_device_register(&mv78xx0_ge01_shared);
+       platform_device_register(&mv78xx0_ge01);
+}
+
+
+/*****************************************************************************
+ * GE10
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data mv78xx0_ge10_shared_data = {
+       .t_clk          = 0,
+       .dram           = &mv78xx0_mbus_dram_info,
+};
+
+static struct resource mv78xx0_ge10_shared_resources[] = {
+       {
+               .name   = "ge10 base",
+               .start  = GE10_PHYS_BASE + 0x2000,
+               .end    = GE10_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device mv78xx0_ge10_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 2,
+       .dev            = {
+               .platform_data  = &mv78xx0_ge10_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge10_shared_resources,
+};
+
+static struct resource mv78xx0_ge10_resources[] = {
+       {
+               .name   = "ge10 irq",
+               .start  = IRQ_MV78XX0_GE10_SUM,
+               .end    = IRQ_MV78XX0_GE10_SUM,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ge10 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 2,
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge10_resources,
+};
+
+void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &mv78xx0_ge10_shared;
+       eth_data->shared_smi = &mv78xx0_ge00_shared;
+       mv78xx0_ge10.dev.platform_data = eth_data;
+
+       platform_device_register(&mv78xx0_ge10_shared);
+       platform_device_register(&mv78xx0_ge10);
+}
+
+
+/*****************************************************************************
+ * GE11
+ ****************************************************************************/
+struct mv643xx_eth_shared_platform_data mv78xx0_ge11_shared_data = {
+       .t_clk          = 0,
+       .dram           = &mv78xx0_mbus_dram_info,
+};
+
+static struct resource mv78xx0_ge11_shared_resources[] = {
+       {
+               .name   = "ge11 base",
+               .start  = GE11_PHYS_BASE + 0x2000,
+               .end    = GE11_PHYS_BASE + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device mv78xx0_ge11_shared = {
+       .name           = MV643XX_ETH_SHARED_NAME,
+       .id             = 3,
+       .dev            = {
+               .platform_data  = &mv78xx0_ge11_shared_data,
+       },
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge11_shared_resources,
+};
+
+static struct resource mv78xx0_ge11_resources[] = {
+       {
+               .name   = "ge11 irq",
+               .start  = IRQ_MV78XX0_GE11_SUM,
+               .end    = IRQ_MV78XX0_GE11_SUM,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_ge11 = {
+       .name           = MV643XX_ETH_NAME,
+       .id             = 3,
+       .num_resources  = 1,
+       .resource       = mv78xx0_ge11_resources,
+};
+
+void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
+{
+       eth_data->shared = &mv78xx0_ge11_shared;
+       eth_data->shared_smi = &mv78xx0_ge00_shared;
+       mv78xx0_ge11.dev.platform_data = eth_data;
+
+       platform_device_register(&mv78xx0_ge11_shared);
+       platform_device_register(&mv78xx0_ge11);
+}
+
+
+/*****************************************************************************
+ * SATA
+ ****************************************************************************/
+static struct resource mv78xx0_sata_resources[] = {
+       {
+               .name   = "sata base",
+               .start  = SATA_PHYS_BASE,
+               .end    = SATA_PHYS_BASE + 0x5000 - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "sata irq",
+               .start  = IRQ_MV78XX0_SATA,
+               .end    = IRQ_MV78XX0_SATA,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_sata = {
+       .name           = "sata_mv",
+       .id             = 0,
+       .dev            = {
+               .coherent_dma_mask      = 0xffffffff,
+       },
+       .num_resources  = ARRAY_SIZE(mv78xx0_sata_resources),
+       .resource       = mv78xx0_sata_resources,
+};
+
+void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
+{
+       sata_data->dram = &mv78xx0_mbus_dram_info;
+       mv78xx0_sata.dev.platform_data = sata_data;
+       platform_device_register(&mv78xx0_sata);
+}
+
+
+/*****************************************************************************
+ * UART0
+ ****************************************************************************/
+static struct plat_serial8250_port mv78xx0_uart0_data[] = {
+       {
+               .mapbase        = UART0_PHYS_BASE,
+               .membase        = (char *)UART0_VIRT_BASE,
+               .irq            = IRQ_MV78XX0_UART_0,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = 0,
+       }, {
+       },
+};
+
+static struct resource mv78xx0_uart0_resources[] = {
+       {
+               .start          = UART0_PHYS_BASE,
+               .end            = UART0_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_MV78XX0_UART_0,
+               .end            = IRQ_MV78XX0_UART_0,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_uart0 = {
+       .name                   = "serial8250",
+       .id                     = 0,
+       .dev                    = {
+               .platform_data  = mv78xx0_uart0_data,
+       },
+       .resource               = mv78xx0_uart0_resources,
+       .num_resources          = ARRAY_SIZE(mv78xx0_uart0_resources),
+};
+
+void __init mv78xx0_uart0_init(void)
+{
+       platform_device_register(&mv78xx0_uart0);
+}
+
+
+/*****************************************************************************
+ * UART1
+ ****************************************************************************/
+static struct plat_serial8250_port mv78xx0_uart1_data[] = {
+       {
+               .mapbase        = UART1_PHYS_BASE,
+               .membase        = (char *)UART1_VIRT_BASE,
+               .irq            = IRQ_MV78XX0_UART_1,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = 0,
+       }, {
+       },
+};
+
+static struct resource mv78xx0_uart1_resources[] = {
+       {
+               .start          = UART1_PHYS_BASE,
+               .end            = UART1_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_MV78XX0_UART_1,
+               .end            = IRQ_MV78XX0_UART_1,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_uart1 = {
+       .name                   = "serial8250",
+       .id                     = 1,
+       .dev                    = {
+               .platform_data  = mv78xx0_uart1_data,
+       },
+       .resource               = mv78xx0_uart1_resources,
+       .num_resources          = ARRAY_SIZE(mv78xx0_uart1_resources),
+};
+
+void __init mv78xx0_uart1_init(void)
+{
+       platform_device_register(&mv78xx0_uart1);
+}
+
+
+/*****************************************************************************
+ * UART2
+ ****************************************************************************/
+static struct plat_serial8250_port mv78xx0_uart2_data[] = {
+       {
+               .mapbase        = UART2_PHYS_BASE,
+               .membase        = (char *)UART2_VIRT_BASE,
+               .irq            = IRQ_MV78XX0_UART_2,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = 0,
+       }, {
+       },
+};
+
+static struct resource mv78xx0_uart2_resources[] = {
+       {
+               .start          = UART2_PHYS_BASE,
+               .end            = UART2_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_MV78XX0_UART_2,
+               .end            = IRQ_MV78XX0_UART_2,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_uart2 = {
+       .name                   = "serial8250",
+       .id                     = 2,
+       .dev                    = {
+               .platform_data  = mv78xx0_uart2_data,
+       },
+       .resource               = mv78xx0_uart2_resources,
+       .num_resources          = ARRAY_SIZE(mv78xx0_uart2_resources),
+};
+
+void __init mv78xx0_uart2_init(void)
+{
+       platform_device_register(&mv78xx0_uart2);
+}
+
+
+/*****************************************************************************
+ * UART3
+ ****************************************************************************/
+static struct plat_serial8250_port mv78xx0_uart3_data[] = {
+       {
+               .mapbase        = UART3_PHYS_BASE,
+               .membase        = (char *)UART3_VIRT_BASE,
+               .irq            = IRQ_MV78XX0_UART_3,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = 0,
+       }, {
+       },
+};
+
+static struct resource mv78xx0_uart3_resources[] = {
+       {
+               .start          = UART3_PHYS_BASE,
+               .end            = UART3_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_MV78XX0_UART_3,
+               .end            = IRQ_MV78XX0_UART_3,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mv78xx0_uart3 = {
+       .name                   = "serial8250",
+       .id                     = 3,
+       .dev                    = {
+               .platform_data  = mv78xx0_uart3_data,
+       },
+       .resource               = mv78xx0_uart3_resources,
+       .num_resources          = ARRAY_SIZE(mv78xx0_uart3_resources),
+};
+
+void __init mv78xx0_uart3_init(void)
+{
+       platform_device_register(&mv78xx0_uart3);
+}
+
+
+/*****************************************************************************
+ * Time handling
+ ****************************************************************************/
+static void mv78xx0_timer_init(void)
+{
+       orion_time_init(IRQ_MV78XX0_TIMER_1, get_tclk());
+}
+
+struct sys_timer mv78xx0_timer = {
+       .init = mv78xx0_timer_init,
+};
+
+
+/*****************************************************************************
+ * General
+ ****************************************************************************/
+static int __init is_l2_writethrough(void)
+{
+       return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
+}
+
+void __init mv78xx0_init(void)
+{
+       int core_index;
+       int hclk;
+       int pclk;
+       int l2clk;
+       int tclk;
+
+       core_index = mv78xx0_core_index();
+       hclk = get_hclk();
+       get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
+       tclk = get_tclk();
+
+       printk(KERN_INFO "MV78xx0 core #%d, ", core_index);
+       printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
+       printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
+       printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
+       printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
+
+       mv78xx0_setup_cpu_mbus();
+
+#ifdef CONFIG_CACHE_FEROCEON_L2
+       feroceon_l2_init(is_l2_writethrough());
+#endif
+
+       mv78xx0_ge00_shared_data.t_clk = tclk;
+       mv78xx0_ge01_shared_data.t_clk = tclk;
+       mv78xx0_ge10_shared_data.t_clk = tclk;
+       mv78xx0_ge11_shared_data.t_clk = tclk;
+       mv78xx0_uart0_data[0].uartclk = tclk;
+       mv78xx0_uart1_data[0].uartclk = tclk;
+       mv78xx0_uart2_data[0].uartclk = tclk;
+       mv78xx0_uart3_data[0].uartclk = tclk;
+}
diff --git a/arch/arm/mach-mv78xx0/common.h b/arch/arm/mach-mv78xx0/common.h
new file mode 100644 (file)
index 0000000..78af5de
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * arch/arm/mach-mv78xx0/common.h
+ *
+ * Core functions for Marvell MV78xx0 SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ARCH_MV78XX0_COMMON_H
+#define __ARCH_MV78XX0_COMMON_H
+
+struct mv643xx_eth_platform_data;
+struct mv_sata_platform_data;
+
+/*
+ * Basic MV78xx0 init functions used early by machine-setup.
+ */
+int mv78xx0_core_index(void);
+void mv78xx0_map_io(void);
+void mv78xx0_init(void);
+void mv78xx0_init_irq(void);
+
+extern struct mbus_dram_target_info mv78xx0_mbus_dram_info;
+void mv78xx0_setup_cpu_mbus(void);
+void mv78xx0_setup_pcie_io_win(int window, u32 base, u32 size,
+                              int maj, int min);
+void mv78xx0_setup_pcie_mem_win(int window, u32 base, u32 size,
+                               int maj, int min);
+
+void mv78xx0_ehci0_init(void);
+void mv78xx0_ehci1_init(void);
+void mv78xx0_ehci2_init(void);
+void mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data);
+void mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data);
+void mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data);
+void mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data);
+void mv78xx0_pcie_init(int init_port0, int init_port1);
+void mv78xx0_sata_init(struct mv_sata_platform_data *sata_data);
+void mv78xx0_uart0_init(void);
+void mv78xx0_uart1_init(void);
+void mv78xx0_uart2_init(void);
+void mv78xx0_uart3_init(void);
+
+extern struct sys_timer mv78xx0_timer;
+
+
+#endif
diff --git a/arch/arm/mach-mv78xx0/db78x00-bp-setup.c b/arch/arm/mach-mv78xx0/db78x00-bp-setup.c
new file mode 100644 (file)
index 0000000..0c93d19
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * arch/arm/mach-mv78xx0/db78x00-bp-setup.c
+ *
+ * Marvell DB-78x00-BP Development Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/arch/mv78xx0.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include "common.h"
+
+static struct mv643xx_eth_platform_data db78x00_ge00_data = {
+       .phy_addr       = 8,
+};
+
+static struct mv643xx_eth_platform_data db78x00_ge01_data = {
+       .phy_addr       = 9,
+};
+
+static struct mv643xx_eth_platform_data db78x00_ge10_data = {
+       .phy_addr       = -1,
+};
+
+static struct mv643xx_eth_platform_data db78x00_ge11_data = {
+       .phy_addr       = -1,
+};
+
+static struct mv_sata_platform_data db78x00_sata_data = {
+       .n_ports        = 2,
+};
+
+static void __init db78x00_init(void)
+{
+       /*
+        * Basic MV78xx0 setup. Needs to be called early.
+        */
+       mv78xx0_init();
+
+       /*
+        * Partition on-chip peripherals between the two CPU cores.
+        */
+       if (mv78xx0_core_index() == 0) {
+               mv78xx0_ehci0_init();
+               mv78xx0_ehci1_init();
+               mv78xx0_ehci2_init();
+               mv78xx0_ge00_init(&db78x00_ge00_data);
+               mv78xx0_ge01_init(&db78x00_ge01_data);
+               mv78xx0_ge10_init(&db78x00_ge10_data);
+               mv78xx0_ge11_init(&db78x00_ge11_data);
+               mv78xx0_sata_init(&db78x00_sata_data);
+               mv78xx0_uart0_init();
+               mv78xx0_uart2_init();
+       } else {
+               mv78xx0_uart1_init();
+               mv78xx0_uart3_init();
+       }
+}
+
+static int __init db78x00_pci_init(void)
+{
+       if (machine_is_db78x00_bp()) {
+               /*
+                * Assign the x16 PCIe slot on the board to CPU core
+                * #0, and let CPU core #1 have the four x1 slots.
+                */
+               if (mv78xx0_core_index() == 0)
+                       mv78xx0_pcie_init(0, 1);
+               else
+                       mv78xx0_pcie_init(1, 0);
+       }
+
+       return 0;
+}
+subsys_initcall(db78x00_pci_init);
+
+MACHINE_START(DB78X00_BP, "Marvell DB-78x00-BP Development Board")
+       /* Maintainer: Lennert Buytenhek <buytenh@marvell.com> */
+       .phys_io        = MV78XX0_REGS_PHYS_BASE,
+       .io_pg_offst    = ((MV78XX0_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = db78x00_init,
+       .map_io         = mv78xx0_map_io,
+       .init_irq       = mv78xx0_init_irq,
+       .timer          = &mv78xx0_timer,
+MACHINE_END
diff --git a/arch/arm/mach-mv78xx0/irq.c b/arch/arm/mach-mv78xx0/irq.c
new file mode 100644 (file)
index 0000000..60f4ee4
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * arch/arm/mach-mv78xx0/irq.c
+ *
+ * MV78xx0 IRQ handling.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <asm/arch/mv78xx0.h>
+#include <asm/plat-orion/irq.h>
+#include "common.h"
+
+void __init mv78xx0_init_irq(void)
+{
+       orion_irq_init(0, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF));
+       orion_irq_init(32, (void __iomem *)(IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF));
+}
diff --git a/arch/arm/mach-mv78xx0/pcie.c b/arch/arm/mach-mv78xx0/pcie.c
new file mode 100644 (file)
index 0000000..b78e144
--- /dev/null
@@ -0,0 +1,312 @@
+/*
+ * arch/arm/mach-mv78xx0/pcie.c
+ *
+ * PCIe functions for Marvell MV78xx0 SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/mbus.h>
+#include <asm/mach/pci.h>
+#include <asm/plat-orion/pcie.h>
+#include "common.h"
+
+struct pcie_port {
+       u8                      maj;
+       u8                      min;
+       u8                      root_bus_nr;
+       void __iomem            *base;
+       spinlock_t              conf_lock;
+       char                    io_space_name[16];
+       char                    mem_space_name[16];
+       struct resource         res[2];
+};
+
+static struct pcie_port pcie_port[8];
+static int num_pcie_ports;
+static struct resource pcie_io_space;
+static struct resource pcie_mem_space;
+
+
+static void __init mv78xx0_pcie_preinit(void)
+{
+       int i;
+       u32 size_each;
+       u32 start;
+       int win;
+
+       pcie_io_space.name = "PCIe I/O Space";
+       pcie_io_space.start = MV78XX0_PCIE_IO_PHYS_BASE(0);
+       pcie_io_space.end =
+               MV78XX0_PCIE_IO_PHYS_BASE(0) + MV78XX0_PCIE_IO_SIZE * 8 - 1;
+       pcie_io_space.flags = IORESOURCE_IO;
+       if (request_resource(&iomem_resource, &pcie_io_space))
+               panic("can't allocate PCIe I/O space");
+
+       pcie_mem_space.name = "PCIe MEM Space";
+       pcie_mem_space.start = MV78XX0_PCIE_MEM_PHYS_BASE;
+       pcie_mem_space.end =
+               MV78XX0_PCIE_MEM_PHYS_BASE + MV78XX0_PCIE_MEM_SIZE - 1;
+       pcie_mem_space.flags = IORESOURCE_MEM;
+       if (request_resource(&iomem_resource, &pcie_mem_space))
+               panic("can't allocate PCIe MEM space");
+
+       for (i = 0; i < num_pcie_ports; i++) {
+               struct pcie_port *pp = pcie_port + i;
+
+               snprintf(pp->io_space_name, sizeof(pp->io_space_name),
+                       "PCIe %d.%d I/O", pp->maj, pp->min);
+               pp->io_space_name[sizeof(pp->io_space_name) - 1] = 0;
+               pp->res[0].name = pp->io_space_name;
+               pp->res[0].start = MV78XX0_PCIE_IO_PHYS_BASE(i);
+               pp->res[0].end = pp->res[0].start + MV78XX0_PCIE_IO_SIZE - 1;
+               pp->res[0].flags = IORESOURCE_IO;
+
+               snprintf(pp->mem_space_name, sizeof(pp->mem_space_name),
+                       "PCIe %d.%d MEM", pp->maj, pp->min);
+               pp->mem_space_name[sizeof(pp->mem_space_name) - 1] = 0;
+               pp->res[1].name = pp->mem_space_name;
+               pp->res[1].flags = IORESOURCE_MEM;
+       }
+
+       switch (num_pcie_ports) {
+       case 0:
+               size_each = 0;
+               break;
+
+       case 1:
+               size_each = 0x30000000;
+               break;
+
+       case 2 ... 3:
+               size_each = 0x10000000;
+               break;
+
+       case 4 ... 6:
+               size_each = 0x08000000;
+               break;
+
+       case 7:
+               size_each = 0x04000000;
+               break;
+
+       default:
+               panic("invalid number of PCIe ports");
+       }
+
+       start = MV78XX0_PCIE_MEM_PHYS_BASE;
+       for (i = 0; i < num_pcie_ports; i++) {
+               struct pcie_port *pp = pcie_port + i;
+
+               pp->res[1].start = start;
+               pp->res[1].end = start + size_each - 1;
+               start += size_each;
+       }
+
+       for (i = 0; i < num_pcie_ports; i++) {
+               struct pcie_port *pp = pcie_port + i;
+
+               if (request_resource(&pcie_io_space, &pp->res[0]))
+                       panic("can't allocate PCIe I/O sub-space");
+
+               if (request_resource(&pcie_mem_space, &pp->res[1]))
+                       panic("can't allocate PCIe MEM sub-space");
+       }
+
+       win = 0;
+       for (i = 0; i < num_pcie_ports; i++) {
+               struct pcie_port *pp = pcie_port + i;
+
+               mv78xx0_setup_pcie_io_win(win++, pp->res[0].start,
+                       pp->res[0].end - pp->res[0].start + 1,
+                       pp->maj, pp->min);
+
+               mv78xx0_setup_pcie_mem_win(win++, pp->res[1].start,
+                       pp->res[1].end - pp->res[1].start + 1,
+                       pp->maj, pp->min);
+       }
+}
+
+static int __init mv78xx0_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+       struct pcie_port *pp;
+
+       if (nr >= num_pcie_ports)
+               return 0;
+
+       pp = &pcie_port[nr];
+       pp->root_bus_nr = sys->busnr;
+
+       /*
+        * Generic PCIe unit setup.
+        */
+       orion_pcie_set_local_bus_nr(pp->base, sys->busnr);
+       orion_pcie_setup(pp->base, &mv78xx0_mbus_dram_info);
+
+       sys->resource[0] = &pp->res[0];
+       sys->resource[1] = &pp->res[1];
+       sys->resource[2] = NULL;
+
+       return 1;
+}
+
+static struct pcie_port *bus_to_port(int bus)
+{
+       int i;
+
+       for (i = num_pcie_ports - 1; i >= 0; i--) {
+               int rbus = pcie_port[i].root_bus_nr;
+               if (rbus != -1 && rbus <= bus)
+                       break;
+       }
+
+       return i >= 0 ? pcie_port + i : NULL;
+}
+
+static int pcie_valid_config(struct pcie_port *pp, int bus, int dev)
+{
+       /*
+        * Don't go out when trying to access nonexisting devices
+        * on the local bus.
+        */
+       if (bus == pp->root_bus_nr && dev > 1)
+               return 0;
+
+       return 1;
+}
+
+static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
+                       int size, u32 *val)
+{
+       struct pcie_port *pp = bus_to_port(bus->number);
+       unsigned long flags;
+       int ret;
+
+       if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0) {
+               *val = 0xffffffff;
+               return PCIBIOS_DEVICE_NOT_FOUND;
+       }
+
+       spin_lock_irqsave(&pp->conf_lock, flags);
+       ret = orion_pcie_rd_conf(pp->base, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&pp->conf_lock, flags);
+
+       return ret;
+}
+
+static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
+                       int where, int size, u32 val)
+{
+       struct pcie_port *pp = bus_to_port(bus->number);
+       unsigned long flags;
+       int ret;
+
+       if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0)
+               return PCIBIOS_DEVICE_NOT_FOUND;
+
+       spin_lock_irqsave(&pp->conf_lock, flags);
+       ret = orion_pcie_wr_conf(pp->base, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&pp->conf_lock, flags);
+
+       return ret;
+}
+
+static struct pci_ops pcie_ops = {
+       .read = pcie_rd_conf,
+       .write = pcie_wr_conf,
+};
+
+static void __devinit rc_pci_fixup(struct pci_dev *dev)
+{
+       /*
+        * Prevent enumeration of root complex.
+        */
+       if (dev->bus->parent == NULL && dev->devfn == 0) {
+               int i;
+
+               for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+                       dev->resource[i].start = 0;
+                       dev->resource[i].end   = 0;
+                       dev->resource[i].flags = 0;
+               }
+       }
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
+
+static struct pci_bus __init *
+mv78xx0_pcie_scan_bus(int nr, struct pci_sys_data *sys)
+{
+       struct pci_bus *bus;
+
+       if (nr < num_pcie_ports) {
+               bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
+       } else {
+               bus = NULL;
+               BUG();
+       }
+
+       return bus;
+}
+
+static int __init mv78xx0_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       struct pcie_port *pp = bus_to_port(dev->bus->number);
+
+       return IRQ_MV78XX0_PCIE_00 + (pp->maj << 2) + pp->min;
+}
+
+static struct hw_pci mv78xx0_pci __initdata = {
+       .nr_controllers = 8,
+       .preinit        = mv78xx0_pcie_preinit,
+       .swizzle        = pci_std_swizzle,
+       .setup          = mv78xx0_pcie_setup,
+       .scan           = mv78xx0_pcie_scan_bus,
+       .map_irq        = mv78xx0_pcie_map_irq,
+};
+
+static void __init add_pcie_port(int maj, int min, unsigned long base)
+{
+       printk(KERN_INFO "MV78xx0 PCIe port %d.%d: ", maj, min);
+
+       if (orion_pcie_link_up((void __iomem *)base)) {
+               struct pcie_port *pp = &pcie_port[num_pcie_ports++];
+
+               printk("link up\n");
+
+               pp->maj = maj;
+               pp->min = min;
+               pp->root_bus_nr = -1;
+               pp->base = (void __iomem *)base;
+               spin_lock_init(&pp->conf_lock);
+               memset(pp->res, 0, sizeof(pp->res));
+       } else {
+               printk("link down, ignoring\n");
+       }
+}
+
+void __init mv78xx0_pcie_init(int init_port0, int init_port1)
+{
+       if (init_port0) {
+               add_pcie_port(0, 0, PCIE00_VIRT_BASE);
+               if (!orion_pcie_x4_mode((void __iomem *)PCIE00_VIRT_BASE)) {
+                       add_pcie_port(0, 1, PCIE01_VIRT_BASE);
+                       add_pcie_port(0, 2, PCIE02_VIRT_BASE);
+                       add_pcie_port(0, 3, PCIE03_VIRT_BASE);
+               }
+       }
+
+       if (init_port1) {
+               add_pcie_port(1, 0, PCIE10_VIRT_BASE);
+               if (!orion_pcie_x4_mode((void __iomem *)PCIE10_VIRT_BASE)) {
+                       add_pcie_port(1, 1, PCIE11_VIRT_BASE);
+                       add_pcie_port(1, 2, PCIE12_VIRT_BASE);
+                       add_pcie_port(1, 3, PCIE13_VIRT_BASE);
+               }
+       }
+
+       pci_common_init(&mv78xx0_pci);
+}
diff --git a/arch/arm/mach-mx2/Kconfig b/arch/arm/mach-mx2/Kconfig
new file mode 100644 (file)
index 0000000..1eaa97c
--- /dev/null
@@ -0,0 +1,39 @@
+comment "MX2 family CPU support"
+       depends on ARCH_MX2
+
+config MACH_MX27
+       bool "i.MX27 support"
+       depends on ARCH_MX2
+       help
+         This enables support for Freescale's MX2 based i.MX27 processor.
+
+comment "MX2 Platforms"
+       depends on ARCH_MX2
+
+config MACH_MX27ADS
+       bool "MX27ADS platform"
+       depends on MACH_MX27
+       help
+         Include support for MX27ADS platform. This includes specific
+         configurations for the board and its peripherals.
+
+config MACH_PCM038
+       bool "Phytec phyCORE-i.MX27 CPU module (pcm038)"
+       depends on MACH_MX27
+       help
+         Include support for phyCORE-i.MX27 (aka pcm038) platform. This
+         includes specific configurations for the module and its peripherals.
+
+choice
+       prompt "Baseboard"
+       depends on MACH_PCM038
+       default MACH_PCM970_BASEBOARD
+
+config MACH_PCM970_BASEBOARD
+       prompt "PHYTEC PCM970 development board"
+       bool
+       help
+         This adds board specific devices that can be found on Phytec's
+         PCM970 evaluation board.
+
+endchoice
diff --git a/arch/arm/mach-mx2/Makefile b/arch/arm/mach-mx2/Makefile
new file mode 100644 (file)
index 0000000..382d860
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# Makefile for the linux kernel.
+#
+
+# Object file lists.
+
+obj-y  :=  system.o generic.o devices.o serial.o
+
+obj-$(CONFIG_MACH_MX27) += cpu_imx27.o
+obj-$(CONFIG_MACH_MX27) += clock_imx27.o
+
+obj-$(CONFIG_MACH_MX27ADS) += mx27ads.o
+obj-$(CONFIG_MACH_PCM038) += pcm038.o
+obj-$(CONFIG_MACH_PCM970_BASEBOARD) += pcm970-baseboard.o
diff --git a/arch/arm/mach-mx2/Makefile.boot b/arch/arm/mach-mx2/Makefile.boot
new file mode 100644 (file)
index 0000000..696831d
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0xA0008000
+params_phys-y  := 0xA0000100
+initrd_phys-y  := 0xA0800000
diff --git a/arch/arm/mach-mx2/clock_imx27.c b/arch/arm/mach-mx2/clock_imx27.c
new file mode 100644 (file)
index 0000000..0a29ef2
--- /dev/null
@@ -0,0 +1,1626 @@
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+
+#include <asm/arch/clock.h>
+#include <asm/arch/common.h>
+#include <asm/div64.h>
+#include <asm/mach-types.h>
+
+#include "crm_regs.h"
+
+static struct clk ckil_clk;
+static struct clk mpll_clk;
+static struct clk mpll_main_clk[];
+static struct clk spll_clk;
+
+static int _clk_enable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(clk->enable_reg);
+       reg |= 1 << clk->enable_shift;
+       __raw_writel(reg, clk->enable_reg);
+
+       return 0;
+}
+
+static void _clk_disable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(clk->enable_reg);
+       reg &= ~(1 << clk->enable_shift);
+       __raw_writel(reg, clk->enable_reg);
+}
+
+static int _clk_spll_enable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_CSCR);
+       reg |= CCM_CSCR_SPEN;
+       __raw_writel(reg, CCM_CSCR);
+
+       while ((__raw_readl(CCM_SPCTL1) & CCM_SPCTL1_LF) == 0)
+               ;
+
+       return 0;
+}
+
+static void _clk_spll_disable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_CSCR);
+       reg &= ~CCM_CSCR_SPEN;
+       __raw_writel(reg, CCM_CSCR);
+}
+
+static void _clk_pccr01_enable(unsigned long mask0, unsigned long mask1)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR0);
+       reg |= mask0;
+       __raw_writel(reg, CCM_PCCR0);
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg |= mask1;
+       __raw_writel(reg, CCM_PCCR1);
+
+}
+
+static void _clk_pccr01_disable(unsigned long mask0, unsigned long mask1)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR0);
+       reg &= ~mask0;
+       __raw_writel(reg, CCM_PCCR0);
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg &= ~mask1;
+       __raw_writel(reg, CCM_PCCR1);
+}
+
+static void _clk_pccr10_enable(unsigned long mask1, unsigned long mask0)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg |= mask1;
+       __raw_writel(reg, CCM_PCCR1);
+
+       reg = __raw_readl(CCM_PCCR0);
+       reg |= mask0;
+       __raw_writel(reg, CCM_PCCR0);
+}
+
+static void _clk_pccr10_disable(unsigned long mask1, unsigned long mask0)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg &= ~mask1;
+       __raw_writel(reg, CCM_PCCR1);
+
+       reg = __raw_readl(CCM_PCCR0);
+       reg &= ~mask0;
+       __raw_writel(reg, CCM_PCCR0);
+}
+
+static int _clk_dma_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_DMA_MASK, CCM_PCCR1_HCLK_DMA_MASK);
+
+       return 0;
+}
+
+static void _clk_dma_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_DMA_MASK, CCM_PCCR1_HCLK_DMA_MASK);
+}
+
+static int _clk_rtic_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_RTIC_MASK, CCM_PCCR1_HCLK_RTIC_MASK);
+
+       return 0;
+}
+
+static void _clk_rtic_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_RTIC_MASK, CCM_PCCR1_HCLK_RTIC_MASK);
+}
+
+static int _clk_emma_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_EMMA_MASK, CCM_PCCR1_HCLK_EMMA_MASK);
+
+       return 0;
+}
+
+static void _clk_emma_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_EMMA_MASK, CCM_PCCR1_HCLK_EMMA_MASK);
+}
+
+static int _clk_slcdc_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_SLCDC_MASK, CCM_PCCR1_HCLK_SLCDC_MASK);
+
+       return 0;
+}
+
+static void _clk_slcdc_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_SLCDC_MASK, CCM_PCCR1_HCLK_SLCDC_MASK);
+}
+
+static int _clk_fec_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_FEC_MASK, CCM_PCCR1_HCLK_FEC_MASK);
+
+       return 0;
+}
+
+static void _clk_fec_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_FEC_MASK, CCM_PCCR1_HCLK_FEC_MASK);
+}
+
+static int _clk_vpu_enable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg |= CCM_PCCR1_VPU_BAUD_MASK | CCM_PCCR1_HCLK_VPU_MASK;
+       __raw_writel(reg, CCM_PCCR1);
+
+       return 0;
+}
+
+static void _clk_vpu_disable(struct clk *clk)
+{
+       unsigned long reg;
+
+       reg = __raw_readl(CCM_PCCR1);
+       reg &= ~(CCM_PCCR1_VPU_BAUD_MASK | CCM_PCCR1_HCLK_VPU_MASK);
+       __raw_writel(reg, CCM_PCCR1);
+}
+
+static int _clk_sahara2_enable(struct clk *clk)
+{
+       _clk_pccr01_enable(CCM_PCCR0_SAHARA_MASK, CCM_PCCR1_HCLK_SAHARA_MASK);
+
+       return 0;
+}
+
+static void _clk_sahara2_disable(struct clk *clk)
+{
+       _clk_pccr01_disable(CCM_PCCR0_SAHARA_MASK, CCM_PCCR1_HCLK_SAHARA_MASK);
+}
+
+static int _clk_mstick1_enable(struct clk *clk)
+{
+       _clk_pccr10_enable(CCM_PCCR1_MSHC_BAUD_MASK, CCM_PCCR0_MSHC_MASK);
+
+       return 0;
+}
+
+static void _clk_mstick1_disable(struct clk *clk)
+{
+       _clk_pccr10_disable(CCM_PCCR1_MSHC_BAUD_MASK, CCM_PCCR0_MSHC_MASK);
+}
+
+#define CSCR() (__raw_readl(CCM_CSCR))
+#define PCDR0() (__raw_readl(CCM_PCDR0))
+#define PCDR1() (__raw_readl(CCM_PCDR1))
+
+static int _clk_cpu_set_parent(struct clk *clk, struct clk *parent)
+{
+       int cscr = CSCR();
+
+       if (clk->parent == parent)
+               return 0;
+
+       if (mx27_revision() >= CHIP_REV_2_0) {
+               if (parent == &mpll_main_clk[0]) {
+                       cscr |= CCM_CSCR_ARM_SRC;
+               } else {
+                       if (parent == &mpll_main_clk[1])
+                               cscr &= ~CCM_CSCR_ARM_SRC;
+                       else
+                               return -EINVAL;
+               }
+               __raw_writel(cscr, CCM_CSCR);
+       } else
+               return -ENODEV;
+
+       clk->parent = parent;
+       return 0;
+}
+
+static unsigned long _clk_cpu_round_rate(struct clk *clk, unsigned long rate)
+{
+       int div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       div = parent_rate / rate;
+       if (parent_rate % rate)
+               div++;
+
+       if (div > 4)
+               div = 4;
+
+       return parent_rate / div;
+}
+
+static int _clk_cpu_set_rate(struct clk *clk, unsigned long rate)
+{
+       unsigned int div;
+       uint32_t reg;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       div = parent_rate / rate;
+
+       if (div > 4 || div < 1 || ((parent_rate / div) != rate))
+               return -EINVAL;
+
+       div--;
+
+       reg = __raw_readl(CCM_CSCR);
+       if (mx27_revision() >= CHIP_REV_2_0) {
+               reg &= ~CCM_CSCR_ARM_MASK;
+               reg |= div << CCM_CSCR_ARM_OFFSET;
+               reg &= ~0x06;
+               __raw_writel(reg | 0x80000000, CCM_CSCR);
+       } else {
+               printk(KERN_ERR "Cant set CPU frequency!\n");
+       }
+
+       return 0;
+}
+
+static unsigned long _clk_perclkx_round_rate(struct clk *clk,
+                                            unsigned long rate)
+{
+       u32 div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       div = parent_rate / rate;
+       if (parent_rate % rate)
+               div++;
+
+       if (div > 64)
+               div = 64;
+
+       return parent_rate / div;
+}
+
+static int _clk_perclkx_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg;
+       u32 div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       if (clk->id < 0 || clk->id > 3)
+               return -EINVAL;
+
+       div = parent_rate / rate;
+       if (div > 64 || div < 1 || ((parent_rate / div) != rate))
+               return -EINVAL;
+       div--;
+
+       reg =
+           __raw_readl(CCM_PCDR1) & ~(CCM_PCDR1_PERDIV1_MASK <<
+                                      (clk->id << 3));
+       reg |= div << (clk->id << 3);
+       __raw_writel(reg, CCM_PCDR1);
+
+       return 0;
+}
+
+static unsigned long _clk_usb_recalc(struct clk *clk)
+{
+       unsigned long usb_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       usb_pdf = (CSCR() & CCM_CSCR_USB_MASK) >> CCM_CSCR_USB_OFFSET;
+
+       return parent_rate / (usb_pdf + 1U);
+}
+
+static unsigned long _clk_ssi1_recalc(struct clk *clk)
+{
+       unsigned long ssi1_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       ssi1_pdf = (PCDR0() & CCM_PCDR0_SSI1BAUDDIV_MASK) >>
+                                       CCM_PCDR0_SSI1BAUDDIV_OFFSET;
+
+       if (mx27_revision() >= CHIP_REV_2_0)
+               ssi1_pdf += 4;
+       else
+               ssi1_pdf = (ssi1_pdf < 2) ? 124UL : ssi1_pdf;
+
+       return 2UL * parent_rate / ssi1_pdf;
+}
+
+static unsigned long _clk_ssi2_recalc(struct clk *clk)
+{
+       unsigned long ssi2_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       ssi2_pdf = (PCDR0() & CCM_PCDR0_SSI2BAUDDIV_MASK) >>
+           CCM_PCDR0_SSI2BAUDDIV_OFFSET;
+
+       if (mx27_revision() >= CHIP_REV_2_0)
+               ssi2_pdf += 4;
+       else
+               ssi2_pdf = (ssi2_pdf < 2) ? 124UL : ssi2_pdf;
+
+       return 2UL * parent_rate / ssi2_pdf;
+}
+
+static unsigned long _clk_nfc_recalc(struct clk *clk)
+{
+       unsigned long nfc_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       if (mx27_revision() >= CHIP_REV_2_0) {
+               nfc_pdf =
+                   (PCDR0() & CCM_PCDR0_NFCDIV2_MASK) >>
+                   CCM_PCDR0_NFCDIV2_OFFSET;
+       } else {
+               nfc_pdf =
+                   (PCDR0() & CCM_PCDR0_NFCDIV_MASK) >>
+                   CCM_PCDR0_NFCDIV_OFFSET;
+       }
+
+       return parent_rate / (nfc_pdf + 1);
+}
+
+static unsigned long _clk_vpu_recalc(struct clk *clk)
+{
+       unsigned long vpu_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       if (mx27_revision() >= CHIP_REV_2_0) {
+               vpu_pdf =
+                   (PCDR0() & CCM_PCDR0_VPUDIV2_MASK) >>
+                   CCM_PCDR0_VPUDIV2_OFFSET;
+               vpu_pdf += 4;
+       } else {
+               vpu_pdf =
+                   (PCDR0() & CCM_PCDR0_VPUDIV_MASK) >>
+                   CCM_PCDR0_VPUDIV_OFFSET;
+               vpu_pdf = (vpu_pdf < 2) ? 124 : vpu_pdf;
+       }
+       return 2UL * parent_rate / vpu_pdf;
+}
+
+static unsigned long _clk_parent_round_rate(struct clk *clk, unsigned long rate)
+{
+       return clk->parent->round_rate(clk->parent, rate);
+}
+
+static int _clk_parent_set_rate(struct clk *clk, unsigned long rate)
+{
+       return clk->parent->set_rate(clk->parent, rate);
+}
+
+/* in Hz */
+static unsigned long external_high_reference = 26000000;
+
+static unsigned long get_high_reference_clock_rate(struct clk *clk)
+{
+       return external_high_reference;
+}
+
+/*
+ * the high frequency external clock reference
+ * Default case is 26MHz. Could be changed at runtime
+ * with a call to change_external_high_reference()
+ */
+static struct clk ckih_clk = {
+       .name = "ckih",
+       .get_rate = get_high_reference_clock_rate,
+};
+
+/* in Hz */
+static unsigned long external_low_reference = 32768;
+
+static unsigned long get_low_reference_clock_rate(struct clk *clk)
+{
+       return external_low_reference;
+}
+
+/*
+ * the low frequency external clock reference
+ * Default case is 32.768kHz Could be changed at runtime
+ * with a call to change_external_low_reference()
+ */
+static struct clk ckil_clk = {
+       .name = "ckil",
+       .get_rate = get_low_reference_clock_rate,
+};
+
+static unsigned long get_mpll_clk(struct clk *clk)
+{
+       uint32_t reg;
+       unsigned long ref_clk;
+       unsigned long mfi = 0, mfn = 0, mfd = 0, pdf = 0;
+       unsigned long long temp;
+
+       ref_clk = clk_get_rate(clk->parent);
+
+       reg = __raw_readl(CCM_MPCTL0);
+       pdf = (reg & CCM_MPCTL0_PD_MASK) >> CCM_MPCTL0_PD_OFFSET;
+       mfd = (reg & CCM_MPCTL0_MFD_MASK) >> CCM_MPCTL0_MFD_OFFSET;
+       mfi = (reg & CCM_MPCTL0_MFI_MASK) >> CCM_MPCTL0_MFI_OFFSET;
+       mfn = (reg & CCM_MPCTL0_MFN_MASK) >> CCM_MPCTL0_MFN_OFFSET;
+
+       mfi = (mfi <= 5) ? 5 : mfi;
+       temp = 2LL * ref_clk * mfn;
+       do_div(temp, mfd + 1);
+       temp = 2LL * ref_clk * mfi + temp;
+       do_div(temp, pdf + 1);
+
+       return (unsigned long)temp;
+}
+
+static struct clk mpll_clk = {
+       .name = "mpll",
+       .parent = &ckih_clk,
+       .get_rate = get_mpll_clk,
+};
+
+static unsigned long _clk_mpll_main_get_rate(struct clk *clk)
+{
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       /* i.MX27 TO2:
+        * clk->id == 0: arm clock source path 1 which is from 2*MPLL/DIV_2
+        * clk->id == 1: arm clock source path 2 which is from 2*MPLL/DIV_3
+        */
+
+       if (mx27_revision() >= CHIP_REV_2_0 && clk->id == 1)
+               return 2UL * parent_rate / 3UL;
+
+       return parent_rate;
+}
+
+static struct clk mpll_main_clk[] = {
+       {
+               /* For i.MX27 TO2, it is the MPLL path 1 of ARM core
+                * It provide the clock source whose rate is same as MPLL
+                */
+               .name = "mpll_main",
+               .id = 0,
+               .parent = &mpll_clk,
+               .get_rate = _clk_mpll_main_get_rate
+       }, {
+               /* For i.MX27 TO2, it is the MPLL path 2 of ARM core
+                * It provide the clock source whose rate is same MPLL * 2/3
+                */
+               .name = "mpll_main",
+               .id = 1,
+               .parent = &mpll_clk,
+               .get_rate = _clk_mpll_main_get_rate
+       }
+};
+
+static unsigned long get_spll_clk(struct clk *clk)
+{
+       uint32_t reg;
+       unsigned long ref_clk;
+       unsigned long mfi = 0, mfn = 0, mfd = 0, pdf = 0;
+       unsigned long long temp;
+
+       ref_clk = clk_get_rate(clk->parent);
+
+       reg = __raw_readl(CCM_SPCTL0);
+       /*TODO: This is TO2 Bug */
+       if (mx27_revision() >= CHIP_REV_2_0)
+               __raw_writel(reg, CCM_SPCTL0);
+
+       pdf = (reg & CCM_SPCTL0_PD_MASK) >> CCM_SPCTL0_PD_OFFSET;
+       mfd = (reg & CCM_SPCTL0_MFD_MASK) >> CCM_SPCTL0_MFD_OFFSET;
+       mfi = (reg & CCM_SPCTL0_MFI_MASK) >> CCM_SPCTL0_MFI_OFFSET;
+       mfn = (reg & CCM_SPCTL0_MFN_MASK) >> CCM_SPCTL0_MFN_OFFSET;
+
+       mfi = (mfi <= 5) ? 5 : mfi;
+       temp = 2LL * ref_clk * mfn;
+       do_div(temp, mfd + 1);
+       temp = 2LL * ref_clk * mfi + temp;
+       do_div(temp, pdf + 1);
+
+       return (unsigned long)temp;
+}
+
+static struct clk spll_clk = {
+       .name = "spll",
+       .parent = &ckih_clk,
+       .get_rate = get_spll_clk,
+       .enable = _clk_spll_enable,
+       .disable = _clk_spll_disable,
+};
+
+static unsigned long get_cpu_clk(struct clk *clk)
+{
+       u32 div;
+       unsigned long rate;
+
+       if (mx27_revision() >= CHIP_REV_2_0)
+               div = (CSCR() & CCM_CSCR_ARM_MASK) >> CCM_CSCR_ARM_OFFSET;
+       else
+               div = (CSCR() & CCM_CSCR_PRESC_MASK) >> CCM_CSCR_PRESC_OFFSET;
+
+       rate = clk_get_rate(clk->parent);
+       return rate / (div + 1);
+}
+
+static struct clk cpu_clk = {
+       .name = "cpu_clk",
+       .parent = &mpll_main_clk[1],
+       .set_parent = _clk_cpu_set_parent,
+       .round_rate = _clk_cpu_round_rate,
+       .get_rate = get_cpu_clk,
+       .set_rate = _clk_cpu_set_rate,
+};
+
+static unsigned long get_ahb_clk(struct clk *clk)
+{
+       unsigned long rate;
+       unsigned long bclk_pdf;
+
+       if (mx27_revision() >= CHIP_REV_2_0)
+               bclk_pdf = (CSCR() & CCM_CSCR_AHB_MASK)
+                                       >> CCM_CSCR_AHB_OFFSET;
+       else
+               bclk_pdf = (CSCR() & CCM_CSCR_BCLK_MASK)
+                                       >> CCM_CSCR_BCLK_OFFSET;
+
+       rate = clk_get_rate(clk->parent);
+       return rate / (bclk_pdf + 1);
+}
+
+static struct clk ahb_clk = {
+       .name = "ahb_clk",
+       .parent = &mpll_main_clk[1],
+       .get_rate = get_ahb_clk,
+};
+
+static unsigned long get_ipg_clk(struct clk *clk)
+{
+       unsigned long rate;
+       unsigned long ipg_pdf;
+
+       if (mx27_revision() >= CHIP_REV_2_0)
+               return clk_get_rate(clk->parent);
+       else
+               ipg_pdf = (CSCR() & CCM_CSCR_IPDIV) >> CCM_CSCR_IPDIV_OFFSET;
+
+       rate = clk_get_rate(clk->parent);
+       return rate / (ipg_pdf + 1);
+}
+
+static struct clk ipg_clk = {
+       .name = "ipg_clk",
+       .parent = &ahb_clk,
+       .get_rate = get_ipg_clk,
+};
+
+static unsigned long _clk_perclkx_recalc(struct clk *clk)
+{
+       unsigned long perclk_pdf;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       if (clk->id < 0 || clk->id > 3)
+               return 0;
+
+       perclk_pdf = (PCDR1() >> (clk->id << 3)) & CCM_PCDR1_PERDIV1_MASK;
+
+       return parent_rate / (perclk_pdf + 1);
+}
+
+static struct clk per_clk[] = {
+       {
+               .name = "per_clk",
+               .id = 0,
+               .parent = &mpll_main_clk[1],
+               .get_rate = _clk_perclkx_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_PERCLK1_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "per_clk",
+               .id = 1,
+               .parent = &mpll_main_clk[1],
+               .get_rate = _clk_perclkx_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_PERCLK2_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "per_clk",
+               .id = 2,
+               .parent = &mpll_main_clk[1],
+               .round_rate = _clk_perclkx_round_rate,
+               .set_rate = _clk_perclkx_set_rate,
+               .get_rate = _clk_perclkx_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_PERCLK3_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "per_clk",
+               .id = 3,
+               .parent = &mpll_main_clk[1],
+               .round_rate = _clk_perclkx_round_rate,
+               .set_rate = _clk_perclkx_set_rate,
+               .get_rate = _clk_perclkx_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_PERCLK4_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart1_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 0,
+               .parent = &per_clk[0],
+               .secondary = &uart1_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART1_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart2_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 1,
+               .parent = &per_clk[0],
+               .secondary = &uart2_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART2_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart3_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 2,
+               .parent = &per_clk[0],
+               .secondary = &uart3_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 2,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART3_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart4_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 3,
+               .parent = &per_clk[0],
+               .secondary = &uart4_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 3,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART4_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart5_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 4,
+               .parent = &per_clk[0],
+               .secondary = &uart5_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 4,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART5_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+struct clk uart6_clk[] = {
+       {
+               .name = "uart_clk",
+               .id = 5,
+               .parent = &per_clk[0],
+               .secondary = &uart6_clk[1],
+       }, {
+               .name = "uart_ipg_clk",
+               .id = 5,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_UART6_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt1_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 0,
+               .parent = &per_clk[0],
+               .secondary = &gpt1_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT1_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt2_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 1,
+               .parent = &per_clk[0],
+               .secondary = &gpt2_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT2_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt3_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 2,
+               .parent = &per_clk[0],
+               .secondary = &gpt3_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 2,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT3_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt4_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 3,
+               .parent = &per_clk[0],
+               .secondary = &gpt4_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 3,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT4_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt5_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 4,
+               .parent = &per_clk[0],
+               .secondary = &gpt5_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 4,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT5_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk gpt6_clk[] = {
+       {
+               .name = "gpt_clk",
+               .id = 5,
+               .parent = &per_clk[0],
+               .secondary = &gpt6_clk[1],
+       }, {
+               .name = "gpt_ipg_clk",
+               .id = 5,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_GPT6_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk pwm_clk[] = {
+       {
+               .name = "pwm_clk",
+               .parent = &per_clk[0],
+               .secondary = &pwm_clk[1],
+       }, {
+               .name = "pwm_clk",
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_PWM_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk sdhc1_clk[] = {
+       {
+               .name = "sdhc_clk",
+               .id = 0,
+               .parent = &per_clk[1],
+               .secondary = &sdhc1_clk[1],
+       }, {
+               .name = "sdhc_ipg_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_SDHC1_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk sdhc2_clk[] = {
+       {
+               .name = "sdhc_clk",
+               .id = 1,
+               .parent = &per_clk[1],
+               .secondary = &sdhc2_clk[1],
+       }, {
+               .name = "sdhc_ipg_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_SDHC2_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk sdhc3_clk[] = {
+       {
+               .name = "sdhc_clk",
+               .id = 2,
+               .parent = &per_clk[1],
+               .secondary = &sdhc3_clk[1],
+       }, {
+               .name = "sdhc_ipg_clk",
+               .id = 2,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_SDHC3_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk cspi1_clk[] = {
+       {
+               .name = "cspi_clk",
+               .id = 0,
+               .parent = &per_clk[1],
+               .secondary = &cspi1_clk[1],
+       }, {
+               .name = "cspi_ipg_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_CSPI1_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk cspi2_clk[] = {
+       {
+               .name = "cspi_clk",
+               .id = 1,
+               .parent = &per_clk[1],
+               .secondary = &cspi2_clk[1],
+       }, {
+               .name = "cspi_ipg_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_CSPI2_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk cspi3_clk[] = {
+       {
+               .name = "cspi_clk",
+               .id = 2,
+               .parent = &per_clk[1],
+               .secondary = &cspi3_clk[1],
+       }, {
+               .name = "cspi_ipg_clk",
+               .id = 2,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_CSPI3_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk lcdc_clk[] = {
+       {
+               .name = "lcdc_clk",
+               .parent = &per_clk[2],
+               .secondary = &lcdc_clk[1],
+               .round_rate = _clk_parent_round_rate,
+               .set_rate = _clk_parent_set_rate,
+       }, {
+               .name = "lcdc_ipg_clk",
+               .parent = &ipg_clk,
+               .secondary = &lcdc_clk[2],
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_LCDC_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "lcdc_ahb_clk",
+               .parent = &ahb_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_HCLK_LCDC_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk csi_clk[] = {
+       {
+               .name = "csi_perclk",
+               .parent = &per_clk[3],
+               .secondary = &csi_clk[1],
+               .round_rate = _clk_parent_round_rate,
+               .set_rate = _clk_parent_set_rate,
+       }, {
+               .name = "csi_ahb_clk",
+               .parent = &ahb_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_HCLK_CSI_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk usb_clk[] = {
+       {
+               .name = "usb_clk",
+               .parent = &spll_clk,
+               .get_rate = _clk_usb_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_USBOTG_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "usb_ahb_clk",
+               .parent = &ahb_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_HCLK_USBOTG_OFFSET,
+               .disable = _clk_disable,
+       }
+};
+
+static struct clk ssi1_clk[] = {
+       {
+               .name = "ssi_clk",
+               .id = 0,
+               .parent = &mpll_main_clk[1],
+               .secondary = &ssi1_clk[1],
+               .get_rate = _clk_ssi1_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_SSI1_BAUD_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "ssi_ipg_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_SSI1_IPG_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk ssi2_clk[] = {
+       {
+               .name = "ssi_clk",
+               .id = 1,
+               .parent = &mpll_main_clk[1],
+               .secondary = &ssi2_clk[1],
+               .get_rate = _clk_ssi2_recalc,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR1,
+               .enable_shift = CCM_PCCR1_SSI2_BAUD_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "ssi_ipg_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_SSI2_IPG_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk nfc_clk = {
+       .name = "nfc_clk",
+       .parent = &cpu_clk,
+       .get_rate = _clk_nfc_recalc,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR1_NFC_BAUD_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk vpu_clk = {
+       .name = "vpu_clk",
+       .parent = &mpll_main_clk[1],
+       .get_rate = _clk_vpu_recalc,
+       .enable = _clk_vpu_enable,
+       .disable = _clk_vpu_disable,
+};
+
+static struct clk dma_clk = {
+       .name = "dma_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_dma_enable,
+       .disable = _clk_dma_disable,
+};
+
+static struct clk rtic_clk = {
+       .name = "rtic_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_rtic_enable,
+       .disable = _clk_rtic_disable,
+};
+
+static struct clk brom_clk = {
+       .name = "brom_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR1_HCLK_BROM_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk emma_clk = {
+       .name = "emma_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_emma_enable,
+       .disable = _clk_emma_disable,
+};
+
+static struct clk slcdc_clk = {
+       .name = "slcdc_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_slcdc_enable,
+       .disable = _clk_slcdc_disable,
+};
+
+static struct clk fec_clk = {
+       .name = "fec_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_fec_enable,
+       .disable = _clk_fec_disable,
+};
+
+static struct clk emi_clk = {
+       .name = "emi_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR1_HCLK_EMI_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk sahara2_clk = {
+       .name = "sahara_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_sahara2_enable,
+       .disable = _clk_sahara2_disable,
+};
+
+static struct clk ata_clk = {
+       .name = "ata_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR1_HCLK_ATA_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk mstick1_clk = {
+       .name = "mstick1_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_mstick1_enable,
+       .disable = _clk_mstick1_disable,
+};
+
+static struct clk wdog_clk = {
+       .name = "wdog_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR1_WDT_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk gpio_clk = {
+       .name = "gpio_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR1,
+       .enable_shift = CCM_PCCR0_GPIO_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk i2c_clk[] = {
+       {
+               .name = "i2c_clk",
+               .id = 0,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_I2C1_OFFSET,
+               .disable = _clk_disable,
+       }, {
+               .name = "i2c_clk",
+               .id = 1,
+               .parent = &ipg_clk,
+               .enable = _clk_enable,
+               .enable_reg = CCM_PCCR0,
+               .enable_shift = CCM_PCCR0_I2C2_OFFSET,
+               .disable = _clk_disable,
+       },
+};
+
+static struct clk iim_clk = {
+       .name = "iim_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR0,
+       .enable_shift = CCM_PCCR0_IIM_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk kpp_clk = {
+       .name = "kpp_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR0,
+       .enable_shift = CCM_PCCR0_KPP_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk owire_clk = {
+       .name = "owire_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR0,
+       .enable_shift = CCM_PCCR0_OWIRE_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk rtc_clk = {
+       .name = "rtc_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR0,
+       .enable_shift = CCM_PCCR0_RTC_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk scc_clk = {
+       .name = "scc_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = CCM_PCCR0,
+       .enable_shift = CCM_PCCR0_SCC_OFFSET,
+       .disable = _clk_disable,
+};
+
+static unsigned long _clk_clko_round_rate(struct clk *clk, unsigned long rate)
+{
+       u32 div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+       div = parent_rate / rate;
+       if (parent_rate % rate)
+               div++;
+
+       if (div > 8)
+               div = 8;
+
+       return parent_rate / div;
+}
+
+static int _clk_clko_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg;
+       u32 div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       div = parent_rate / rate;
+
+       if (div > 8 || div < 1 || ((parent_rate / div) != rate))
+               return -EINVAL;
+       div--;
+
+       reg = __raw_readl(CCM_PCDR0) & ~CCM_PCDR0_CLKODIV_MASK;
+       reg |= div << CCM_PCDR0_CLKODIV_OFFSET;
+       __raw_writel(reg, CCM_PCDR0);
+
+       return 0;
+}
+
+static unsigned long _clk_clko_recalc(struct clk *clk)
+{
+       u32 div;
+       unsigned long parent_rate;
+
+       parent_rate = clk_get_rate(clk->parent);
+
+       div = __raw_readl(CCM_PCDR0) & CCM_PCDR0_CLKODIV_MASK >>
+               CCM_PCDR0_CLKODIV_OFFSET;
+       div++;
+
+       return parent_rate / div;
+}
+
+static int _clk_clko_set_parent(struct clk *clk, struct clk *parent)
+{
+       u32 reg;
+
+       reg = __raw_readl(CCM_CCSR) & ~CCM_CCSR_CLKOSEL_MASK;
+
+       if (parent == &ckil_clk)
+               reg |= 0 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &ckih_clk)
+               reg |= 2 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == mpll_clk.parent)
+               reg |= 3 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == spll_clk.parent)
+               reg |= 4 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &mpll_clk)
+               reg |= 5 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &spll_clk)
+               reg |= 6 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &cpu_clk)
+               reg |= 7 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &ahb_clk)
+               reg |= 8 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &ipg_clk)
+               reg |= 9 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &per_clk[0])
+               reg |= 0xA << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &per_clk[1])
+               reg |= 0xB << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &per_clk[2])
+               reg |= 0xC << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &per_clk[3])
+               reg |= 0xD << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &ssi1_clk[0])
+               reg |= 0xE << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &ssi2_clk[0])
+               reg |= 0xF << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &nfc_clk)
+               reg |= 0x10 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &mstick1_clk)
+               reg |= 0x11 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &vpu_clk)
+               reg |= 0x12 << CCM_CCSR_CLKOSEL_OFFSET;
+       else if (parent == &usb_clk[0])
+               reg |= 0x15 << CCM_CCSR_CLKOSEL_OFFSET;
+       else
+               return -EINVAL;
+
+       __raw_writel(reg, CCM_CCSR);
+
+       return 0;
+}
+
+static int _clk_clko_enable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(CCM_PCDR0) | CCM_PCDR0_CLKO_EN;
+       __raw_writel(reg, CCM_PCDR0);
+
+       return 0;
+}
+
+static void _clk_clko_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(CCM_PCDR0) & ~CCM_PCDR0_CLKO_EN;
+       __raw_writel(reg, CCM_PCDR0);
+}
+
+static struct clk clko_clk = {
+       .name = "clko_clk",
+       .get_rate = _clk_clko_recalc,
+       .set_rate = _clk_clko_set_rate,
+       .round_rate = _clk_clko_round_rate,
+       .set_parent = _clk_clko_set_parent,
+       .enable = _clk_clko_enable,
+       .disable = _clk_clko_disable,
+};
+
+static struct clk *mxc_clks[] = {
+       &ckih_clk,
+       &ckil_clk,
+       &mpll_clk,
+       &mpll_main_clk[0],
+       &mpll_main_clk[1],
+       &spll_clk,
+       &cpu_clk,
+       &ahb_clk,
+       &ipg_clk,
+       &per_clk[0],
+       &per_clk[1],
+       &per_clk[2],
+       &per_clk[3],
+       &clko_clk,
+       &uart1_clk[0],
+       &uart1_clk[1],
+       &uart2_clk[0],
+       &uart2_clk[1],
+       &uart3_clk[0],
+       &uart3_clk[1],
+       &uart4_clk[0],
+       &uart4_clk[1],
+       &uart5_clk[0],
+       &uart5_clk[1],
+       &uart6_clk[0],
+       &uart6_clk[1],
+       &gpt1_clk[0],
+       &gpt1_clk[1],
+       &gpt2_clk[0],
+       &gpt2_clk[1],
+       &gpt3_clk[0],
+       &gpt3_clk[1],
+       &gpt4_clk[0],
+       &gpt4_clk[1],
+       &gpt5_clk[0],
+       &gpt5_clk[1],
+       &gpt6_clk[0],
+       &gpt6_clk[1],
+       &pwm_clk[0],
+       &pwm_clk[1],
+       &sdhc1_clk[0],
+       &sdhc1_clk[1],
+       &sdhc2_clk[0],
+       &sdhc2_clk[1],
+       &sdhc3_clk[0],
+       &sdhc3_clk[1],
+       &cspi1_clk[0],
+       &cspi1_clk[1],
+       &cspi2_clk[0],
+       &cspi2_clk[1],
+       &cspi3_clk[0],
+       &cspi3_clk[1],
+       &lcdc_clk[0],
+       &lcdc_clk[1],
+       &lcdc_clk[2],
+       &csi_clk[0],
+       &csi_clk[1],
+       &usb_clk[0],
+       &usb_clk[1],
+       &ssi1_clk[0],
+       &ssi1_clk[1],
+       &ssi2_clk[0],
+       &ssi2_clk[1],
+       &nfc_clk,
+       &vpu_clk,
+       &dma_clk,
+       &rtic_clk,
+       &brom_clk,
+       &emma_clk,
+       &slcdc_clk,
+       &fec_clk,
+       &emi_clk,
+       &sahara2_clk,
+       &ata_clk,
+       &mstick1_clk,
+       &wdog_clk,
+       &gpio_clk,
+       &i2c_clk[0],
+       &i2c_clk[1],
+       &iim_clk,
+       &kpp_clk,
+       &owire_clk,
+       &rtc_clk,
+       &scc_clk,
+};
+
+void __init change_external_low_reference(unsigned long new_ref)
+{
+       external_low_reference = new_ref;
+}
+
+unsigned long __init clk_early_get_timer_rate(void)
+{
+       return clk_get_rate(&per_clk[0]);
+}
+
+static void __init probe_mxc_clocks(void)
+{
+       int i;
+
+       if (mx27_revision() >= CHIP_REV_2_0) {
+               if (CSCR() & 0x8000)
+                       cpu_clk.parent = &mpll_main_clk[0];
+
+               if (!(CSCR() & 0x00800000))
+                       ssi2_clk[0].parent = &spll_clk;
+
+               if (!(CSCR() & 0x00400000))
+                       ssi1_clk[0].parent = &spll_clk;
+
+               if (!(CSCR() & 0x00200000))
+                       vpu_clk.parent = &spll_clk;
+       } else {
+               cpu_clk.parent = &mpll_clk;
+               cpu_clk.set_parent = NULL;
+               cpu_clk.round_rate = NULL;
+               cpu_clk.set_rate = NULL;
+               ahb_clk.parent = &mpll_clk;
+
+               for (i = 0; i < sizeof(per_clk) / sizeof(per_clk[0]); i++)
+                       per_clk[i].parent = &mpll_clk;
+
+               ssi1_clk[0].parent = &mpll_clk;
+               ssi2_clk[0].parent = &mpll_clk;
+
+               vpu_clk.parent = &mpll_clk;
+       }
+}
+
+/*
+ * must be called very early to get information about the
+ * available clock rate when the timer framework starts
+ */
+int __init mxc_clocks_init(unsigned long fref)
+{
+       u32 cscr;
+       struct clk **clkp;
+
+       external_high_reference = fref;
+
+       /* detect clock reference for both system PLL */
+       cscr = CSCR();
+       if (cscr & CCM_CSCR_MCU)
+               mpll_clk.parent = &ckih_clk;
+       else
+               mpll_clk.parent = &ckil_clk;
+
+       if (cscr & CCM_CSCR_SP)
+               spll_clk.parent = &ckih_clk;
+       else
+               spll_clk.parent = &ckil_clk;
+
+       probe_mxc_clocks();
+
+       per_clk[0].enable(&per_clk[0]);
+       gpt1_clk[1].enable(&gpt1_clk[1]);
+
+       for (clkp = mxc_clks; clkp < mxc_clks + ARRAY_SIZE(mxc_clks); clkp++)
+               clk_register(*clkp);
+
+       /* Turn off all possible clocks */
+       __raw_writel(CCM_PCCR0_GPT1_MASK, CCM_PCCR0);
+       __raw_writel(CCM_PCCR1_PERCLK1_MASK | CCM_PCCR1_HCLK_EMI_MASK,
+                    CCM_PCCR1);
+       spll_clk.disable(&spll_clk);
+
+       /* This will propagate to all children and init all the clock rates */
+
+       clk_enable(&emi_clk);
+       clk_enable(&gpio_clk);
+       clk_enable(&iim_clk);
+       clk_enable(&gpt1_clk[0]);
+#ifdef CONFIG_DEBUG_LL_CONSOLE
+       clk_enable(&uart1_clk[0]);
+#endif
+       return 0;
+}
diff --git a/arch/arm/mach-mx2/cpu_imx27.c b/arch/arm/mach-mx2/cpu_imx27.c
new file mode 100644 (file)
index 0000000..d6b5c2e
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+/*
+ * i.MX27 specific CPU detection code
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+
+#include <asm/hardware.h>
+
+#include "crm_regs.h"
+
+static int cpu_silicon_rev = -1;
+static int cpu_partnumber;
+
+static void query_silicon_parameter(void)
+{
+       u32 val;
+       /*
+        * now we have access to the IO registers. As we need
+        * the silicon revision very early we read it here to
+        * avoid any further hooks
+       */
+       val = __raw_readl(IO_ADDRESS(SYSCTRL_BASE_ADDR) + SYS_CHIP_ID);
+
+       cpu_silicon_rev = (int)(val >> 28);
+       cpu_partnumber = (int)((val >> 12) & 0xFFFF);
+}
+
+/*
+ * Returns:
+ *     the silicon revision of the cpu
+ *     -EINVAL - not a mx27
+ */
+int mx27_revision(void)
+{
+       if (cpu_silicon_rev == -1)
+               query_silicon_parameter();
+
+       if (cpu_partnumber != 0x8821)
+               return -EINVAL;
+
+       return cpu_silicon_rev;
+}
+EXPORT_SYMBOL(mx27_revision);
diff --git a/arch/arm/mach-mx2/crm_regs.h b/arch/arm/mach-mx2/crm_regs.h
new file mode 100644 (file)
index 0000000..a40a9b9
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef __ARCH_ARM_MACH_MX2_CRM_REGS_H__
+#define __ARCH_ARM_MACH_MX2_CRM_REGS_H__
+
+#include <asm/arch/hardware.h>
+
+/* Register offsets */
+#define CCM_CSCR                (IO_ADDRESS(CCM_BASE_ADDR) + 0x0)
+#define CCM_MPCTL0              (IO_ADDRESS(CCM_BASE_ADDR) + 0x4)
+#define CCM_MPCTL1              (IO_ADDRESS(CCM_BASE_ADDR) + 0x8)
+#define CCM_SPCTL0              (IO_ADDRESS(CCM_BASE_ADDR) + 0xC)
+#define CCM_SPCTL1              (IO_ADDRESS(CCM_BASE_ADDR) + 0x10)
+#define CCM_OSC26MCTL           (IO_ADDRESS(CCM_BASE_ADDR) + 0x14)
+#define CCM_PCDR0               (IO_ADDRESS(CCM_BASE_ADDR) + 0x18)
+#define CCM_PCDR1               (IO_ADDRESS(CCM_BASE_ADDR) + 0x1c)
+#define CCM_PCCR0               (IO_ADDRESS(CCM_BASE_ADDR) + 0x20)
+#define CCM_PCCR1               (IO_ADDRESS(CCM_BASE_ADDR) + 0x24)
+#define CCM_CCSR                (IO_ADDRESS(CCM_BASE_ADDR) + 0x28)
+#define CCM_PMCTL               (IO_ADDRESS(CCM_BASE_ADDR) + 0x2c)
+#define CCM_PMCOUNT             (IO_ADDRESS(CCM_BASE_ADDR) + 0x30)
+#define CCM_WKGDCTL             (IO_ADDRESS(CCM_BASE_ADDR) + 0x34)
+
+#define CCM_CSCR_USB_OFFSET     28
+#define CCM_CSCR_USB_MASK       (0x7 << 28)
+#define CCM_CSCR_SD_OFFSET      24
+#define CCM_CSCR_SD_MASK        (0x3 << 24)
+#define CCM_CSCR_SSI2           (1 << 23)
+#define CCM_CSCR_SSI2_OFFSET    23
+#define CCM_CSCR_SSI1           (1 << 22)
+#define CCM_CSCR_SSI1_OFFSET    22
+#define CCM_CSCR_VPU           (1 << 21)
+#define CCM_CSCR_VPU_OFFSET    21
+#define CCM_CSCR_MSHC           (1 << 20)
+#define CCM_CSCR_SPLLRES        (1 << 19)
+#define CCM_CSCR_MPLLRES        (1 << 18)
+#define CCM_CSCR_SP             (1 << 17)
+#define CCM_CSCR_MCU            (1 << 16)
+/* CCM_CSCR_ARM_xxx just be avaliable on i.MX27 TO2*/
+#define CCM_CSCR_ARM_SRC        (1 << 15)
+#define CCM_CSCR_ARM_OFFSET     12
+#define CCM_CSCR_ARM_MASK       (0x3 << 12)
+/* CCM_CSCR_ARM_xxx just be avaliable on i.MX27 TO2*/
+#define CCM_CSCR_PRESC_OFFSET   13
+#define CCM_CSCR_PRESC_MASK     (0x7 << 13)
+#define CCM_CSCR_BCLK_OFFSET    9
+#define CCM_CSCR_BCLK_MASK      (0xf << 9)
+#define CCM_CSCR_IPDIV_OFFSET   8
+#define CCM_CSCR_IPDIV          (1 << 8)
+/* CCM_CSCR_AHB_xxx just be avaliable on i.MX27 TO2*/
+#define CCM_CSCR_AHB_OFFSET     8
+#define CCM_CSCR_AHB_MASK       (0x3 << 8)
+/* CCM_CSCR_AHB_xxx just be avaliable on i.MX27 TO2*/
+#define CCM_CSCR_OSC26MDIV      (1 << 4)
+#define CCM_CSCR_OSC26M         (1 << 3)
+#define CCM_CSCR_FPM            (1 << 2)
+#define CCM_CSCR_SPEN           (1 << 1)
+#define CCM_CSCR_MPEN           1
+
+#define CCM_MPCTL0_CPLM         (1 << 31)
+#define CCM_MPCTL0_PD_OFFSET    26
+#define CCM_MPCTL0_PD_MASK      (0xf << 26)
+#define CCM_MPCTL0_MFD_OFFSET   16
+#define CCM_MPCTL0_MFD_MASK     (0x3ff << 16)
+#define CCM_MPCTL0_MFI_OFFSET   10
+#define CCM_MPCTL0_MFI_MASK     (0xf << 10)
+#define CCM_MPCTL0_MFN_OFFSET   0
+#define CCM_MPCTL0_MFN_MASK     0x3ff
+
+#define CCM_MPCTL1_LF           (1 << 15)
+#define CCM_MPCTL1_BRMO         (1 << 6)
+
+#define CCM_SPCTL0_CPLM         (1 << 31)
+#define CCM_SPCTL0_PD_OFFSET    26
+#define CCM_SPCTL0_PD_MASK      (0xf << 26)
+#define CCM_SPCTL0_MFD_OFFSET   16
+#define CCM_SPCTL0_MFD_MASK     (0x3ff << 16)
+#define CCM_SPCTL0_MFI_OFFSET   10
+#define CCM_SPCTL0_MFI_MASK     (0xf << 10)
+#define CCM_SPCTL0_MFN_OFFSET   0
+#define CCM_SPCTL0_MFN_MASK     0x3ff
+
+#define CCM_SPCTL1_LF           (1 << 15)
+#define CCM_SPCTL1_BRMO         (1 << 6)
+
+#define CCM_OSC26MCTL_PEAK_OFFSET       16
+#define CCM_OSC26MCTL_PEAK_MASK         (0x3 << 16)
+#define CCM_OSC26MCTL_AGC_OFFSET        8
+#define CCM_OSC26MCTL_AGC_MASK          (0x3f << 8)
+#define CCM_OSC26MCTL_ANATEST_OFFSET    0
+#define CCM_OSC26MCTL_ANATEST_MASK      0x3f
+
+#define CCM_PCDR0_SSI2BAUDDIV_OFFSET    26
+#define CCM_PCDR0_SSI2BAUDDIV_MASK      (0x3f << 26)
+#define CCM_PCDR0_CLKO_EN               25
+#define CCM_PCDR0_CLKODIV_OFFSET        22
+#define CCM_PCDR0_CLKODIV_MASK          (0x7 << 22)
+#define CCM_PCDR0_SSI1BAUDDIV_OFFSET    16
+#define CCM_PCDR0_SSI1BAUDDIV_MASK      (0x3f << 16)
+/*The difinition for i.MX27 TO2*/
+#define CCM_PCDR0_VPUDIV2_OFFSET        10
+#define CCM_PCDR0_VPUDIV2_MASK          (0x3f << 10)
+#define CCM_PCDR0_NFCDIV2_OFFSET         6
+#define CCM_PCDR0_NFCDIV2_MASK           (0xf << 6)
+#define CCM_PCDR0_MSHCDIV2_MASK          0x3f
+/*The difinition for i.MX27 TO2*/
+#define CCM_PCDR0_NFCDIV_OFFSET         12
+#define CCM_PCDR0_NFCDIV_MASK           (0xf << 12)
+#define CCM_PCDR0_VPUDIV_OFFSET        8
+#define CCM_PCDR0_VPUDIV_MASK          (0xf << 8)
+#define CCM_PCDR0_MSHCDIV_OFFSET        0
+#define CCM_PCDR0_MSHCDIV_MASK          0x1f
+
+#define CCM_PCDR1_PERDIV4_OFFSET        24
+#define CCM_PCDR1_PERDIV4_MASK          (0x3f << 24)
+#define CCM_PCDR1_PERDIV3_OFFSET        16
+#define CCM_PCDR1_PERDIV3_MASK          (0x3f << 16)
+#define CCM_PCDR1_PERDIV2_OFFSET        8
+#define CCM_PCDR1_PERDIV2_MASK          (0x3f << 8)
+#define CCM_PCDR1_PERDIV1_OFFSET        0
+#define CCM_PCDR1_PERDIV1_MASK          0x3f
+
+#define CCM_PCCR0_CSPI1_OFFSET          31
+#define CCM_PCCR0_CSPI1_MASK            (1 << 31)
+#define CCM_PCCR0_CSPI2_OFFSET          30
+#define CCM_PCCR0_CSPI2_MASK            (1 << 30)
+#define CCM_PCCR0_CSPI3_OFFSET          29
+#define CCM_PCCR0_CSPI3_MASK            (1 << 29)
+#define CCM_PCCR0_DMA_OFFSET            28
+#define CCM_PCCR0_DMA_MASK              (1 << 28)
+#define CCM_PCCR0_EMMA_OFFSET           27
+#define CCM_PCCR0_EMMA_MASK             (1 << 27)
+#define CCM_PCCR0_FEC_OFFSET            26
+#define CCM_PCCR0_FEC_MASK              (1 << 26)
+#define CCM_PCCR0_GPIO_OFFSET           25
+#define CCM_PCCR0_GPIO_MASK             (1 << 25)
+#define CCM_PCCR0_GPT1_OFFSET           24
+#define CCM_PCCR0_GPT1_MASK             (1 << 24)
+#define CCM_PCCR0_GPT2_OFFSET           23
+#define CCM_PCCR0_GPT2_MASK             (1 << 23)
+#define CCM_PCCR0_GPT3_OFFSET           22
+#define CCM_PCCR0_GPT3_MASK             (1 << 22)
+#define CCM_PCCR0_GPT4_OFFSET           21
+#define CCM_PCCR0_GPT4_MASK             (1 << 21)
+#define CCM_PCCR0_GPT5_OFFSET           20
+#define CCM_PCCR0_GPT5_MASK             (1 << 20)
+#define CCM_PCCR0_GPT6_OFFSET           19
+#define CCM_PCCR0_GPT6_MASK             (1 << 19)
+#define CCM_PCCR0_I2C1_OFFSET           18
+#define CCM_PCCR0_I2C1_MASK             (1 << 18)
+#define CCM_PCCR0_I2C2_OFFSET           17
+#define CCM_PCCR0_I2C2_MASK             (1 << 17)
+#define CCM_PCCR0_IIM_OFFSET            16
+#define CCM_PCCR0_IIM_MASK              (1 << 16)
+#define CCM_PCCR0_KPP_OFFSET            15
+#define CCM_PCCR0_KPP_MASK              (1 << 15)
+#define CCM_PCCR0_LCDC_OFFSET           14
+#define CCM_PCCR0_LCDC_MASK             (1 << 14)
+#define CCM_PCCR0_MSHC_OFFSET           13
+#define CCM_PCCR0_MSHC_MASK             (1 << 13)
+#define CCM_PCCR0_OWIRE_OFFSET          12
+#define CCM_PCCR0_OWIRE_MASK            (1 << 12)
+#define CCM_PCCR0_PWM_OFFSET            11
+#define CCM_PCCR0_PWM_MASK              (1 << 11)
+#define CCM_PCCR0_RTC_OFFSET            9
+#define CCM_PCCR0_RTC_MASK              (1 << 9)
+#define CCM_PCCR0_RTIC_OFFSET           8
+#define CCM_PCCR0_RTIC_MASK             (1 << 8)
+#define CCM_PCCR0_SAHARA_OFFSET         7
+#define CCM_PCCR0_SAHARA_MASK           (1 << 7)
+#define CCM_PCCR0_SCC_OFFSET            6
+#define CCM_PCCR0_SCC_MASK              (1 << 6)
+#define CCM_PCCR0_SDHC1_OFFSET          5
+#define CCM_PCCR0_SDHC1_MASK            (1 << 5)
+#define CCM_PCCR0_SDHC2_OFFSET          4
+#define CCM_PCCR0_SDHC2_MASK            (1 << 4)
+#define CCM_PCCR0_SDHC3_OFFSET          3
+#define CCM_PCCR0_SDHC3_MASK            (1 << 3)
+#define CCM_PCCR0_SLCDC_OFFSET          2
+#define CCM_PCCR0_SLCDC_MASK            (1 << 2)
+#define CCM_PCCR0_SSI1_IPG_OFFSET       1
+#define CCM_PCCR0_SSI1_IPG_MASK         (1 << 1)
+#define CCM_PCCR0_SSI2_IPG_OFFSET       0
+#define CCM_PCCR0_SSI2_IPG_MASK         (1 << 0)
+
+#define CCM_PCCR1_UART1_OFFSET          31
+#define CCM_PCCR1_UART1_MASK            (1 << 31)
+#define CCM_PCCR1_UART2_OFFSET          30
+#define CCM_PCCR1_UART2_MASK            (1 << 30)
+#define CCM_PCCR1_UART3_OFFSET          29
+#define CCM_PCCR1_UART3_MASK            (1 << 29)
+#define CCM_PCCR1_UART4_OFFSET          28
+#define CCM_PCCR1_UART4_MASK            (1 << 28)
+#define CCM_PCCR1_UART5_OFFSET          27
+#define CCM_PCCR1_UART5_MASK            (1 << 27)
+#define CCM_PCCR1_UART6_OFFSET          26
+#define CCM_PCCR1_UART6_MASK            (1 << 26)
+#define CCM_PCCR1_USBOTG_OFFSET         25
+#define CCM_PCCR1_USBOTG_MASK           (1 << 25)
+#define CCM_PCCR1_WDT_OFFSET            24
+#define CCM_PCCR1_WDT_MASK              (1 << 24)
+#define CCM_PCCR1_HCLK_ATA_OFFSET       23
+#define CCM_PCCR1_HCLK_ATA_MASK         (1 << 23)
+#define CCM_PCCR1_HCLK_BROM_OFFSET      22
+#define CCM_PCCR1_HCLK_BROM_MASK        (1 << 22)
+#define CCM_PCCR1_HCLK_CSI_OFFSET       21
+#define CCM_PCCR1_HCLK_CSI_MASK         (1 << 21)
+#define CCM_PCCR1_HCLK_DMA_OFFSET       20
+#define CCM_PCCR1_HCLK_DMA_MASK         (1 << 20)
+#define CCM_PCCR1_HCLK_EMI_OFFSET       19
+#define CCM_PCCR1_HCLK_EMI_MASK         (1 << 19)
+#define CCM_PCCR1_HCLK_EMMA_OFFSET      18
+#define CCM_PCCR1_HCLK_EMMA_MASK        (1 << 18)
+#define CCM_PCCR1_HCLK_FEC_OFFSET       17
+#define CCM_PCCR1_HCLK_FEC_MASK         (1 << 17)
+#define CCM_PCCR1_HCLK_VPU_OFFSET       16
+#define CCM_PCCR1_HCLK_VPU_MASK         (1 << 16)
+#define CCM_PCCR1_HCLK_LCDC_OFFSET      15
+#define CCM_PCCR1_HCLK_LCDC_MASK        (1 << 15)
+#define CCM_PCCR1_HCLK_RTIC_OFFSET      14
+#define CCM_PCCR1_HCLK_RTIC_MASK        (1 << 14)
+#define CCM_PCCR1_HCLK_SAHARA_OFFSET    13
+#define CCM_PCCR1_HCLK_SAHARA_MASK      (1 << 13)
+#define CCM_PCCR1_HCLK_SLCDC_OFFSET     12
+#define CCM_PCCR1_HCLK_SLCDC_MASK       (1 << 12)
+#define CCM_PCCR1_HCLK_USBOTG_OFFSET    11
+#define CCM_PCCR1_HCLK_USBOTG_MASK      (1 << 11)
+#define CCM_PCCR1_PERCLK1_OFFSET        10
+#define CCM_PCCR1_PERCLK1_MASK          (1 << 10)
+#define CCM_PCCR1_PERCLK2_OFFSET        9
+#define CCM_PCCR1_PERCLK2_MASK          (1 << 9)
+#define CCM_PCCR1_PERCLK3_OFFSET        8
+#define CCM_PCCR1_PERCLK3_MASK          (1 << 8)
+#define CCM_PCCR1_PERCLK4_OFFSET        7
+#define CCM_PCCR1_PERCLK4_MASK          (1 << 7)
+#define CCM_PCCR1_VPU_BAUD_OFFSET       6
+#define CCM_PCCR1_VPU_BAUD_MASK         (1 << 6)
+#define CCM_PCCR1_SSI1_BAUD_OFFSET      5
+#define CCM_PCCR1_SSI1_BAUD_MASK        (1 << 5)
+#define CCM_PCCR1_SSI2_BAUD_OFFSET      4
+#define CCM_PCCR1_SSI2_BAUD_MASK        (1 << 4)
+#define CCM_PCCR1_NFC_BAUD_OFFSET       3
+#define CCM_PCCR1_NFC_BAUD_MASK         (1 << 3)
+#define CCM_PCCR1_MSHC_BAUD_OFFSET      2
+#define CCM_PCCR1_MSHC_BAUD_MASK        (1 << 2)
+
+#define CCM_CCSR_32KSR          (1 << 15)
+#define CCM_CCSR_CLKMODE1       (1 << 9)
+#define CCM_CCSR_CLKMODE0       (1 << 8)
+#define CCM_CCSR_CLKOSEL_OFFSET 0
+#define CCM_CCSR_CLKOSEL_MASK   0x1f
+
+#define SYS_FMCR                0x14   /*  Functional Muxing Control Reg */
+#define SYS_CHIP_ID             0x00   /* The offset of CHIP ID register */
+
+#endif /* __ARCH_ARM_MACH_MX2_CRM_REGS_H__ */
diff --git a/arch/arm/mach-mx2/devices.c b/arch/arm/mach-mx2/devices.c
new file mode 100644 (file)
index 0000000..a1f44c3
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * Author: MontaVista Software, Inc.
+ *       <source@mvista.com>
+ *
+ * Based on the OMAP devices.c
+ *
+ * 2005 (c) MontaVista Software, Inc. This file is licensed under the
+ * terms of the GNU General Public License version 2. This program is
+ * licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ *
+ * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <asm/hardware.h>
+
+/*
+ * Resource definition for the MXC IrDA
+ */
+static struct resource mxc_irda_resources[] = {
+       [0] = {
+               .start   = UART3_BASE_ADDR,
+               .end     = UART3_BASE_ADDR + SZ_4K - 1,
+               .flags   = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start   = MXC_INT_UART3,
+               .end     = MXC_INT_UART3,
+               .flags   = IORESOURCE_IRQ,
+       },
+};
+
+/* Platform Data for MXC IrDA */
+struct platform_device mxc_irda_device = {
+       .name = "mxc_irda",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(mxc_irda_resources),
+       .resource = mxc_irda_resources,
+};
+
+/*
+ * General Purpose Timer
+ * - i.MX1: 2 timer (slighly different register handling)
+ * - i.MX21: 3 timer
+ * - i.MX27: 6 timer
+ */
+
+/* We use gpt0 as system timer, so do not add a device for this one */
+
+static struct resource timer1_resources[] = {
+       [0] = {
+               .start  = GPT2_BASE_ADDR,
+               .end    = GPT2_BASE_ADDR + 0x17,
+               .flags  = IORESOURCE_MEM
+       },
+       [1] = {
+               .start   = MXC_INT_GPT2,
+               .end     = MXC_INT_GPT2,
+               .flags   = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device mxc_gpt1 = {
+       .name = "imx_gpt",
+       .id = 1,
+       .num_resources = ARRAY_SIZE(timer1_resources),
+       .resource = timer1_resources
+};
+
+static struct resource timer2_resources[] = {
+       [0] = {
+               .start  = GPT3_BASE_ADDR,
+               .end    = GPT3_BASE_ADDR + 0x17,
+               .flags  = IORESOURCE_MEM
+       },
+       [1] = {
+               .start   = MXC_INT_GPT3,
+               .end     = MXC_INT_GPT3,
+               .flags   = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device mxc_gpt2 = {
+       .name = "imx_gpt",
+       .id = 2,
+       .num_resources = ARRAY_SIZE(timer2_resources),
+       .resource = timer2_resources
+};
+
+#ifdef CONFIG_MACH_MX27
+static struct resource timer3_resources[] = {
+       [0] = {
+               .start  = GPT4_BASE_ADDR,
+               .end    = GPT4_BASE_ADDR + 0x17,
+               .flags  = IORESOURCE_MEM
+       },
+       [1] = {
+               .start   = MXC_INT_GPT4,
+               .end     = MXC_INT_GPT4,
+               .flags   = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device mxc_gpt3 = {
+       .name = "imx_gpt",
+       .id = 3,
+       .num_resources = ARRAY_SIZE(timer3_resources),
+       .resource = timer3_resources
+};
+
+static struct resource timer4_resources[] = {
+       [0] = {
+               .start  = GPT5_BASE_ADDR,
+               .end    = GPT5_BASE_ADDR + 0x17,
+               .flags  = IORESOURCE_MEM
+       },
+       [1] = {
+               .start   = MXC_INT_GPT5,
+               .end     = MXC_INT_GPT5,
+               .flags   = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device mxc_gpt4 = {
+       .name = "imx_gpt",
+       .id = 4,
+       .num_resources = ARRAY_SIZE(timer4_resources),
+       .resource = timer4_resources
+};
+
+static struct resource timer5_resources[] = {
+       [0] = {
+               .start  = GPT6_BASE_ADDR,
+               .end    = GPT6_BASE_ADDR + 0x17,
+               .flags  = IORESOURCE_MEM
+       },
+       [1] = {
+               .start   = MXC_INT_GPT6,
+               .end     = MXC_INT_GPT6,
+               .flags   = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device mxc_gpt5 = {
+       .name = "imx_gpt",
+       .id = 5,
+       .num_resources = ARRAY_SIZE(timer5_resources),
+       .resource = timer5_resources
+};
+#endif
+
+/*
+ * Watchdog:
+ * - i.MX1
+ * - i.MX21
+ * - i.MX27
+ */
+static struct resource mxc_wdt_resources[] = {
+       {
+               .start  = WDOG_BASE_ADDR,
+               .end    = WDOG_BASE_ADDR + 0x30,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device mxc_wdt = {
+       .name = "mxc_wdt",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(mxc_wdt_resources),
+       .resource = mxc_wdt_resources,
+};
+
+/* GPIO port description */
+static struct mxc_gpio_port imx_gpio_ports[] = {
+       [0] = {
+               .chip.label = "gpio-0",
+               .irq = MXC_INT_GPIO,
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 0),
+               .virtual_irq_start = MXC_MAX_INT_LINES,
+       },
+       [1] = {
+               .chip.label = "gpio-1",
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 1),
+               .virtual_irq_start = MXC_MAX_INT_LINES + 32,
+       },
+       [2] = {
+               .chip.label = "gpio-2",
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 2),
+               .virtual_irq_start = MXC_MAX_INT_LINES + 64,
+       },
+       [3] = {
+               .chip.label = "gpio-3",
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 3),
+               .virtual_irq_start = MXC_MAX_INT_LINES + 96,
+       },
+       [4] = {
+               .chip.label = "gpio-4",
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 4),
+               .virtual_irq_start = MXC_MAX_INT_LINES + 128,
+       },
+       [5] = {
+               .chip.label = "gpio-5",
+               .base = (void*)(AIPI_BASE_ADDR_VIRT + 0x15000 + 0x100 * 5),
+               .virtual_irq_start = MXC_MAX_INT_LINES + 160,
+       }
+};
+
+int __init mxc_register_gpios(void)
+{
+       return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
+}
diff --git a/arch/arm/mach-mx2/generic.c b/arch/arm/mach-mx2/generic.c
new file mode 100644 (file)
index 0000000..07875cf
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * generic.c
+ *
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/mm.h>
+#include <linux/init.h>
+#include <asm/hardware.h>
+#include <asm/pgtable.h>
+#include <asm/mach/map.h>
+
+/* MX27 memory map definition */
+static struct map_desc mxc_io_desc[] __initdata = {
+       /*
+        * this fixed mapping covers:
+        * - AIPI1
+        * - AIPI2
+        * - AITC
+        * - ROM Patch
+        * - and some reserved space
+        */
+       {
+               .virtual = AIPI_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(AIPI_BASE_ADDR),
+               .length = AIPI_SIZE,
+               .type = MT_DEVICE
+       },
+       /*
+        * this fixed mapping covers:
+        * - CSI
+        * - ATA
+        */
+       {
+               .virtual = SAHB1_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(SAHB1_BASE_ADDR),
+               .length = SAHB1_SIZE,
+               .type = MT_DEVICE
+       },
+       /*
+        * this fixed mapping covers:
+        * - EMI
+        */
+       {
+               .virtual = X_MEMC_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(X_MEMC_BASE_ADDR),
+               .length = X_MEMC_SIZE,
+               .type = MT_DEVICE
+       }
+};
+
+/*
+ * Initialize the memory map. It is called during the
+ * system startup to create static physical to virtual
+ * memory map for the IO modules.
+ */
+void __init mxc_map_io(void)
+{
+       iotable_init(mxc_io_desc, ARRAY_SIZE(mxc_io_desc));
+}
diff --git a/arch/arm/mach-mx2/mx27ads.c b/arch/arm/mach-mx2/mx27ads.c
new file mode 100644 (file)
index 0000000..a9ff01f
--- /dev/null
@@ -0,0 +1,304 @@
+/*
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *  Copyright (C) 2002 Shane Nay (shane@minirl.com)
+ *  Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/platform_device.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+#include <asm/arch/common.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/imx-uart.h>
+#include <asm/arch/iomux-mx1-mx2.h>
+#include <asm/arch/board-mx27ads.h>
+
+/* ADS's NOR flash */
+static struct physmap_flash_data mx27ads_flash_data = {
+       .width = 2,
+};
+
+static struct resource mx27ads_flash_resource = {
+       .start = 0xc0000000,
+       .end = 0xc0000000 + 0x02000000 - 1,
+       .flags = IORESOURCE_MEM,
+
+};
+
+static struct platform_device mx27ads_nor_mtd_device = {
+       .name = "physmap-flash",
+       .id = 0,
+       .dev = {
+               .platform_data = &mx27ads_flash_data,
+       },
+       .num_resources = 1,
+       .resource = &mx27ads_flash_resource,
+};
+
+static int mxc_uart0_pins[] = {
+       PE12_PF_UART1_TXD,
+       PE13_PF_UART1_RXD,
+       PE14_PF_UART1_CTS,
+       PE15_PF_UART1_RTS
+};
+
+static int uart_mxc_port0_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
+                       ARRAY_SIZE(mxc_uart0_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART0");
+}
+
+static int uart_mxc_port0_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
+                       ARRAY_SIZE(mxc_uart0_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART0");
+}
+
+static int mxc_uart1_pins[] = {
+       PE3_PF_UART2_CTS,
+       PE4_PF_UART2_RTS,
+       PE6_PF_UART2_TXD,
+       PE7_PF_UART2_RXD
+};
+
+static int uart_mxc_port1_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
+                       ARRAY_SIZE(mxc_uart1_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART1");
+}
+
+static int uart_mxc_port1_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
+                       ARRAY_SIZE(mxc_uart1_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART1");
+}
+
+static int mxc_uart2_pins[] = {
+       PE8_PF_UART3_TXD,
+       PE9_PF_UART3_RXD,
+       PE10_PF_UART3_CTS,
+       PE11_PF_UART3_RTS
+};
+
+static int uart_mxc_port2_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
+                       ARRAY_SIZE(mxc_uart2_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART2");
+}
+
+static int uart_mxc_port2_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
+                       ARRAY_SIZE(mxc_uart2_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART2");
+}
+
+static int mxc_uart3_pins[] = {
+       PB26_AF_UART4_RTS,
+       PB28_AF_UART4_TXD,
+       PB29_AF_UART4_CTS,
+       PB31_AF_UART4_RXD
+};
+
+static int uart_mxc_port3_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart3_pins,
+                       ARRAY_SIZE(mxc_uart3_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART3");
+}
+
+static int uart_mxc_port3_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart3_pins,
+                       ARRAY_SIZE(mxc_uart3_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART3");
+}
+
+static int mxc_uart4_pins[] = {
+       PB18_AF_UART5_TXD,
+       PB19_AF_UART5_RXD,
+       PB20_AF_UART5_CTS,
+       PB21_AF_UART5_RTS
+};
+
+static int uart_mxc_port4_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart4_pins,
+                       ARRAY_SIZE(mxc_uart4_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART4");
+}
+
+static int uart_mxc_port4_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart4_pins,
+                       ARRAY_SIZE(mxc_uart4_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART4");
+}
+
+static int mxc_uart5_pins[] = {
+       PB10_AF_UART6_TXD,
+       PB12_AF_UART6_CTS,
+       PB11_AF_UART6_RXD,
+       PB13_AF_UART6_RTS
+};
+
+static int uart_mxc_port5_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart5_pins,
+                       ARRAY_SIZE(mxc_uart5_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART5");
+}
+
+static int uart_mxc_port5_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart5_pins,
+                       ARRAY_SIZE(mxc_uart5_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART5");
+}
+
+static struct platform_device *platform_devices[] __initdata = {
+       &mx27ads_nor_mtd_device,
+};
+
+static int mxc_fec_pins[] = {
+       PD0_AIN_FEC_TXD0,
+       PD1_AIN_FEC_TXD1,
+       PD2_AIN_FEC_TXD2,
+       PD3_AIN_FEC_TXD3,
+       PD4_AOUT_FEC_RX_ER,
+       PD5_AOUT_FEC_RXD1,
+       PD6_AOUT_FEC_RXD2,
+       PD7_AOUT_FEC_RXD3,
+       PD8_AF_FEC_MDIO,
+       PD9_AIN_FEC_MDC,
+       PD10_AOUT_FEC_CRS,
+       PD11_AOUT_FEC_TX_CLK,
+       PD12_AOUT_FEC_RXD0,
+       PD13_AOUT_FEC_RX_DV,
+       PD14_AOUT_FEC_CLR,
+       PD15_AOUT_FEC_COL,
+       PD16_AIN_FEC_TX_ER,
+       PF23_AIN_FEC_TX_EN
+};
+
+static void gpio_fec_active(void)
+{
+       mxc_gpio_setup_multiple_pins(mxc_fec_pins,
+                       ARRAY_SIZE(mxc_fec_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "FEC");
+}
+
+static void gpio_fec_inactive(void)
+{
+       mxc_gpio_setup_multiple_pins(mxc_fec_pins,
+                       ARRAY_SIZE(mxc_fec_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "FEC");
+}
+
+static struct imxuart_platform_data uart_pdata[] = {
+       {
+               .init = uart_mxc_port0_init,
+               .exit = uart_mxc_port0_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port1_init,
+               .exit = uart_mxc_port1_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port2_init,
+               .exit = uart_mxc_port2_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port3_init,
+               .exit = uart_mxc_port3_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port4_init,
+               .exit = uart_mxc_port4_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port5_init,
+               .exit = uart_mxc_port5_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       },
+};
+
+static void __init mx27ads_board_init(void)
+{
+       int i;
+
+       gpio_fec_active();
+
+       for (i = 0; i < 6; i++)
+               imx_init_uart(i, &uart_pdata[i]);
+
+       platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+}
+
+static void __init mx27ads_timer_init(void)
+{
+       unsigned long fref = 26000000;
+
+       if ((__raw_readw(PBC_VERSION_REG) & CKIH_27MHZ_BIT_SET) == 0)
+               fref = 27000000;
+
+       mxc_clocks_init(fref);
+       mxc_timer_init("gpt_clk.0");
+}
+
+struct sys_timer mx27ads_timer = {
+       .init   = mx27ads_timer_init,
+};
+
+static struct map_desc mx27ads_io_desc[] __initdata = {
+       {
+               .virtual = PBC_BASE_ADDRESS,
+               .pfn = __phys_to_pfn(CS4_BASE_ADDR),
+               .length = SZ_1M,
+               .type = MT_DEVICE,
+       },
+};
+
+void __init mx27ads_map_io(void)
+{
+       mxc_map_io();
+       iotable_init(mx27ads_io_desc, ARRAY_SIZE(mx27ads_io_desc));
+}
+
+MACHINE_START(MX27ADS, "Freescale i.MX27ADS")
+       /* maintainer: Freescale Semiconductor, Inc. */
+       .phys_io        = AIPI_BASE_ADDR,
+       .io_pg_offst    = ((AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = mx27ads_map_io,
+       .init_irq       = mxc_init_irq,
+       .init_machine   = mx27ads_board_init,
+       .timer          = &mx27ads_timer,
+MACHINE_END
+
diff --git a/arch/arm/mach-mx2/pcm038.c b/arch/arm/mach-mx2/pcm038.c
new file mode 100644 (file)
index 0000000..a9a28f5
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2007 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+#include <asm/arch/common.h>
+#include <asm/hardware.h>
+#include <asm/arch/iomux-mx1-mx2.h>
+#include <asm/mach/time.h>
+#include <asm/arch/imx-uart.h>
+#include <asm/arch/board-pcm038.h>
+
+/*
+ * Phytec's phyCORE-i.MX27 comes with 32MiB flash,
+ * 16 bit width
+ */
+static struct physmap_flash_data pcm038_flash_data = {
+       .width = 2,
+};
+
+static struct resource pcm038_flash_resource = {
+       .start = 0xc0000000,
+       .end   = 0xc1ffffff,
+       .flags = IORESOURCE_MEM,
+};
+
+static struct platform_device pcm038_nor_mtd_device = {
+       .name = "physmap-flash",
+       .id = 0,
+       .dev = {
+               .platform_data = &pcm038_flash_data,
+       },
+       .num_resources = 1,
+       .resource = &pcm038_flash_resource,
+};
+
+static int mxc_uart0_pins[] = {
+       PE12_PF_UART1_TXD,
+       PE13_PF_UART1_RXD,
+       PE14_PF_UART1_CTS,
+       PE15_PF_UART1_RTS
+};
+
+static int uart_mxc_port0_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
+                       ARRAY_SIZE(mxc_uart0_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART0");
+}
+
+static int uart_mxc_port0_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart0_pins,
+                       ARRAY_SIZE(mxc_uart0_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART0");
+}
+
+static int mxc_uart1_pins[] = {
+       PE3_PF_UART2_CTS,
+       PE4_PF_UART2_RTS,
+       PE6_PF_UART2_TXD,
+       PE7_PF_UART2_RXD
+};
+
+static int uart_mxc_port1_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
+                       ARRAY_SIZE(mxc_uart1_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART1");
+}
+
+static int uart_mxc_port1_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart1_pins,
+                       ARRAY_SIZE(mxc_uart1_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART1");
+}
+
+static int mxc_uart2_pins[] = { PE10_PF_UART3_CTS,
+                               PE9_PF_UART3_RXD,
+                               PE10_PF_UART3_CTS,
+                               PE9_PF_UART3_RXD };
+
+static int uart_mxc_port2_init(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
+                       ARRAY_SIZE(mxc_uart2_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "UART2");
+}
+
+static int uart_mxc_port2_exit(struct platform_device *pdev)
+{
+       return mxc_gpio_setup_multiple_pins(mxc_uart2_pins,
+                       ARRAY_SIZE(mxc_uart2_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "UART2");
+}
+
+static struct imxuart_platform_data uart_pdata[] = {
+       {
+               .init = uart_mxc_port0_init,
+               .exit = uart_mxc_port0_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port1_init,
+               .exit = uart_mxc_port1_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       }, {
+               .init = uart_mxc_port2_init,
+               .exit = uart_mxc_port2_exit,
+               .flags = IMXUART_HAVE_RTSCTS,
+       },
+};
+
+static int mxc_fec_pins[] = {
+       PD0_AIN_FEC_TXD0,
+       PD1_AIN_FEC_TXD1,
+       PD2_AIN_FEC_TXD2,
+       PD3_AIN_FEC_TXD3,
+       PD4_AOUT_FEC_RX_ER,
+       PD5_AOUT_FEC_RXD1,
+       PD6_AOUT_FEC_RXD2,
+       PD7_AOUT_FEC_RXD3,
+       PD8_AF_FEC_MDIO,
+       PD9_AIN_FEC_MDC,
+       PD10_AOUT_FEC_CRS,
+       PD11_AOUT_FEC_TX_CLK,
+       PD12_AOUT_FEC_RXD0,
+       PD13_AOUT_FEC_RX_DV,
+       PD14_AOUT_FEC_CLR,
+       PD15_AOUT_FEC_COL,
+       PD16_AIN_FEC_TX_ER,
+       PF23_AIN_FEC_TX_EN
+};
+
+static void gpio_fec_active(void)
+{
+       mxc_gpio_setup_multiple_pins(mxc_fec_pins,
+                       ARRAY_SIZE(mxc_fec_pins),
+                       MXC_GPIO_ALLOC_MODE_NORMAL, "FEC");
+}
+
+static void gpio_fec_inactive(void)
+{
+       mxc_gpio_setup_multiple_pins(mxc_fec_pins,
+                       ARRAY_SIZE(mxc_fec_pins),
+                       MXC_GPIO_ALLOC_MODE_RELEASE, "FEC");
+}
+
+static struct platform_device *platform_devices[] __initdata = {
+       &pcm038_nor_mtd_device,
+};
+
+static void __init pcm038_init(void)
+{
+       int i;
+       gpio_fec_active();
+
+       for (i = 0; i < 3; i++)
+               imx_init_uart(i, &uart_pdata[i]);
+
+       platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+
+#ifdef CONFIG_MACH_PCM970_BASEBOARD
+       pcm970_baseboard_init();
+#endif
+}
+
+static void __init pcm038_timer_init(void)
+{
+       mxc_clocks_init(26000000);
+       mxc_timer_init("gpt_clk.0");
+}
+
+struct sys_timer pcm038_timer = {
+       .init = pcm038_timer_init,
+};
+
+MACHINE_START(PCM038, "phyCORE-i.MX27")
+       .phys_io        = AIPI_BASE_ADDR,
+       .io_pg_offst    = ((AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = mxc_map_io,
+       .init_irq       = mxc_init_irq,
+       .init_machine   = pcm038_init,
+       .timer          = &pcm038_timer,
+MACHINE_END
diff --git a/arch/arm/mach-mx2/pcm970-baseboard.c b/arch/arm/mach-mx2/pcm970-baseboard.c
new file mode 100644 (file)
index 0000000..028ac4d
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+/*
+ * system init for baseboard usage. Will be called by pcm038 init.
+ *
+ * Add platform devices present on this baseboard and init
+ * them from CPU side as far as required to use them later on
+ */
+void __init pcm970_baseboard_init(void)
+{
+}
diff --git a/arch/arm/mach-mx2/serial.c b/arch/arm/mach-mx2/serial.c
new file mode 100644 (file)
index 0000000..570c02b
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/serial.h>
+#include <asm/hardware.h>
+#include <asm/arch/imx-uart.h>
+
+static struct resource uart0[] = {
+       {
+               .start = UART1_BASE_ADDR,
+               .end = UART1_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART1,
+               .end = MXC_INT_UART1,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device0 = {
+       .name = "imx-uart",
+       .id = 0,
+       .resource = uart0,
+       .num_resources = ARRAY_SIZE(uart0),
+};
+
+static struct resource uart1[] = {
+       {
+               .start = UART2_BASE_ADDR,
+               .end = UART2_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART2,
+               .end = MXC_INT_UART2,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device1 = {
+       .name = "imx-uart",
+       .id = 1,
+       .resource = uart1,
+       .num_resources = ARRAY_SIZE(uart1),
+};
+
+static struct resource uart2[] = {
+       {
+               .start = UART3_BASE_ADDR,
+               .end = UART3_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART3,
+               .end = MXC_INT_UART3,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device2 = {
+       .name = "imx-uart",
+       .id = 2,
+       .resource = uart2,
+       .num_resources = ARRAY_SIZE(uart2),
+};
+
+static struct resource uart3[] = {
+       {
+               .start = UART4_BASE_ADDR,
+               .end = UART4_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART4,
+               .end = MXC_INT_UART4,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device3 = {
+       .name = "imx-uart",
+       .id = 3,
+       .resource = uart3,
+       .num_resources = ARRAY_SIZE(uart3),
+};
+
+static struct resource uart4[] = {
+       {
+               .start = UART5_BASE_ADDR,
+               .end = UART5_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART5,
+               .end = MXC_INT_UART5,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device4 = {
+       .name = "imx-uart",
+       .id = 4,
+       .resource = uart4,
+       .num_resources = ARRAY_SIZE(uart4),
+};
+
+static struct resource uart5[] = {
+       {
+               .start = UART6_BASE_ADDR,
+               .end = UART6_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART6,
+               .end = MXC_INT_UART6,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device5 = {
+       .name = "imx-uart",
+       .id = 5,
+       .resource = uart5,
+       .num_resources = ARRAY_SIZE(uart5),
+};
+
+/*
+ * Register only those UARTs that physically exists
+ */
+int __init imx_init_uart(int uart_no, struct imxuart_platform_data *pdata)
+{
+       switch (uart_no) {
+       case 0:
+               mxc_uart_device0.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device0);
+               break;
+       case 1:
+               mxc_uart_device1.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device1);
+               break;
+#ifndef CONFIG_MXC_IRDA
+       case 2:
+               mxc_uart_device2.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device2);
+               break;
+#endif
+       case 3:
+               mxc_uart_device3.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device3);
+               break;
+       case 4:
+               mxc_uart_device4.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device4);
+               break;
+       case 5:
+               mxc_uart_device5.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device5);
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       return 0;
+}
diff --git a/arch/arm/mach-mx2/system.c b/arch/arm/mach-mx2/system.c
new file mode 100644 (file)
index 0000000..9930464
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 1999 ARM Limited
+ * Copyright (C) 2000 Deep Blue Solutions Ltd
+ * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <asm/arch/hardware.h>
+#include <asm/proc-fns.h>
+#include <asm/system.h>
+
+/*
+ * Put the CPU into idle mode. It is called by default_idle()
+ * in process.c file.
+ */
+void arch_idle(void)
+{
+       /*
+        * This should do all the clock switching
+        * and wait for interrupt tricks.
+        */
+       cpu_do_idle();
+}
+
+#define WDOG_WCR_REG                    IO_ADDRESS(WDOG_BASE_ADDR)
+#define WDOG_WCR_SRS                    (1 << 4)
+
+/*
+ * Reset the system. It is called by machine_restart().
+ */
+void arch_reset(char mode)
+{
+       struct clk *clk;
+
+       clk = clk_get(NULL, "wdog_clk");
+       if (!clk) {
+               printk(KERN_ERR"Cannot activate the watchdog. Giving up\n");
+               return;
+       }
+
+       clk_enable(clk);
+
+       /* Assert SRS signal */
+       __raw_writew(__raw_readw(WDOG_WCR_REG) & ~WDOG_WCR_SRS, WDOG_WCR_REG);
+}
index 5fe8606..db9431d 100644 (file)
@@ -8,5 +8,18 @@ config MACH_MX31ADS
          Include support for MX31ADS platform. This includes specific
          configurations for the board and its peripherals.
 
+config MACH_PCM037
+       bool "Support Phytec pcm037 platforms"
+       help
+         Include support for Phytec pcm037 platform. This includes
+         specific configurations for the board and its peripherals.
+
+config MACH_MX31LITE
+       bool "Support MX31 LITEKIT (LogicPD)"
+       default n
+       help
+         Include support for MX31 LITEKIT platform. This includes specific
+         configurations for the board and its peripherals.
+
 endmenu
 
index cbec997..8b21abb 100644 (file)
@@ -4,5 +4,7 @@
 
 # Object file lists.
 
-obj-y                  := mm.o time.o
+obj-y                  := mm.o clock.o devices.o iomux.o
 obj-$(CONFIG_MACH_MX31ADS)     += mx31ads.o
+obj-$(CONFIG_MACH_MX31LITE)    += mx31lite.o
+obj-$(CONFIG_MACH_PCM037)      += pcm037.o
diff --git a/arch/arm/mach-mx3/clock.c b/arch/arm/mach-mx3/clock.c
new file mode 100644 (file)
index 0000000..2f36359
--- /dev/null
@@ -0,0 +1,1147 @@
+/*
+ * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <asm/arch/clock.h>
+#include <asm/div64.h>
+
+#include "crm_regs.h"
+
+#define PRE_DIV_MIN_FREQ    10000000 /* Minimum Frequency after Predivider */
+
+static void __calc_pre_post_dividers(u32 div, u32 *pre, u32 *post)
+{
+       u32 min_pre, temp_pre, old_err, err;
+
+       if (div >= 512) {
+               *pre = 8;
+               *post = 64;
+       } else if (div >= 64) {
+               min_pre = (div - 1) / 64 + 1;
+               old_err = 8;
+               for (temp_pre = 8; temp_pre >= min_pre; temp_pre--) {
+                       err = div % temp_pre;
+                       if (err == 0) {
+                               *pre = temp_pre;
+                               break;
+                       }
+                       err = temp_pre - err;
+                       if (err < old_err) {
+                               old_err = err;
+                               *pre = temp_pre;
+                       }
+               }
+               *post = (div + *pre - 1) / *pre;
+       } else if (div <= 8) {
+               *pre = div;
+               *post = 1;
+       } else {
+               *pre = 1;
+               *post = div;
+       }
+}
+
+static struct clk mcu_pll_clk;
+static struct clk mcu_main_clk;
+static struct clk usb_pll_clk;
+static struct clk serial_pll_clk;
+static struct clk ipg_clk;
+static struct clk ckih_clk;
+static struct clk ahb_clk;
+
+static int _clk_enable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(clk->enable_reg);
+       reg |= 3 << clk->enable_shift;
+       __raw_writel(reg, clk->enable_reg);
+
+       return 0;
+}
+
+static void _clk_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(clk->enable_reg);
+       reg &= ~(3 << clk->enable_shift);
+       __raw_writel(reg, clk->enable_reg);
+}
+
+static void _clk_emi_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(clk->enable_reg);
+       reg &= ~(3 << clk->enable_shift);
+       reg |= (1 << clk->enable_shift);
+       __raw_writel(reg, clk->enable_reg);
+}
+
+static int _clk_pll_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg;
+       signed long pd = 1;     /* Pre-divider */
+       signed long mfi;        /* Multiplication Factor (Integer part) */
+       signed long mfn;        /* Multiplication Factor (Integer part) */
+       signed long mfd;        /* Multiplication Factor (Denominator Part) */
+       signed long tmp;
+       u32 ref_freq = clk_get_rate(clk->parent);
+
+       while (((ref_freq / pd) * 10) > rate)
+               pd++;
+
+       if ((ref_freq / pd) < PRE_DIV_MIN_FREQ)
+               return -EINVAL;
+
+       /* the ref_freq/2 in the following is to round up */
+       mfi = (((rate / 2) * pd) + (ref_freq / 2)) / ref_freq;
+       if (mfi < 5 || mfi > 15)
+               return -EINVAL;
+
+       /* pick a mfd value that will work
+        * then solve for mfn */
+       mfd = ref_freq / 50000;
+
+       /*
+        *          pll_freq * pd * mfd
+        *   mfn = --------------------  -  (mfi * mfd)
+        *           2 * ref_freq
+        */
+       /* the tmp/2 is for rounding */
+       tmp = ref_freq / 10000;
+       mfn =
+           ((((((rate / 2) + (tmp / 2)) / tmp) * pd) * mfd) / 10000) -
+           (mfi * mfd);
+
+       mfn = mfn & 0x3ff;
+       pd--;
+       mfd--;
+
+       /* Change the Pll value */
+       reg = (mfi << MXC_CCM_PCTL_MFI_OFFSET) |
+           (mfn << MXC_CCM_PCTL_MFN_OFFSET) |
+           (mfd << MXC_CCM_PCTL_MFD_OFFSET) | (pd << MXC_CCM_PCTL_PD_OFFSET);
+
+       if (clk == &mcu_pll_clk)
+               __raw_writel(reg, MXC_CCM_MPCTL);
+       else if (clk == &usb_pll_clk)
+               __raw_writel(reg, MXC_CCM_UPCTL);
+       else if (clk == &serial_pll_clk)
+               __raw_writel(reg, MXC_CCM_SRPCTL);
+
+       return 0;
+}
+
+static unsigned long _clk_pll_get_rate(struct clk *clk)
+{
+       long mfi, mfn, mfd, pdf, ref_clk, mfn_abs;
+       unsigned long reg, ccmr;
+       s64 temp;
+       unsigned int prcs;
+
+       ccmr = __raw_readl(MXC_CCM_CCMR);
+       prcs = (ccmr & MXC_CCM_CCMR_PRCS_MASK) >> MXC_CCM_CCMR_PRCS_OFFSET;
+       if (prcs == 0x1)
+               ref_clk = CKIL_CLK_FREQ * 1024;
+       else
+               ref_clk = clk_get_rate(&ckih_clk);
+
+       if (clk == &mcu_pll_clk) {
+               if ((ccmr & MXC_CCM_CCMR_MPE) == 0)
+                       return ref_clk;
+               if ((ccmr & MXC_CCM_CCMR_MDS) != 0)
+                       return ref_clk;
+               reg = __raw_readl(MXC_CCM_MPCTL);
+       } else if (clk == &usb_pll_clk)
+               reg = __raw_readl(MXC_CCM_UPCTL);
+       else if (clk == &serial_pll_clk)
+               reg = __raw_readl(MXC_CCM_SRPCTL);
+       else {
+               BUG();
+               return 0;
+       }
+
+       pdf = (reg & MXC_CCM_PCTL_PD_MASK) >> MXC_CCM_PCTL_PD_OFFSET;
+       mfd = (reg & MXC_CCM_PCTL_MFD_MASK) >> MXC_CCM_PCTL_MFD_OFFSET;
+       mfi = (reg & MXC_CCM_PCTL_MFI_MASK) >> MXC_CCM_PCTL_MFI_OFFSET;
+       mfi = (mfi <= 5) ? 5 : mfi;
+       mfn = mfn_abs = reg & MXC_CCM_PCTL_MFN_MASK;
+
+       if (mfn >= 0x200) {
+               mfn |= 0xFFFFFE00;
+               mfn_abs = -mfn;
+       }
+
+       ref_clk *= 2;
+       ref_clk /= pdf + 1;
+
+       temp = (u64) ref_clk * mfn_abs;
+       do_div(temp, mfd + 1);
+       if (mfn < 0)
+               temp = -temp;
+       temp = (ref_clk * mfi) + temp;
+
+       return temp;
+}
+
+static int _clk_usb_pll_enable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_CCMR);
+       reg |= MXC_CCM_CCMR_UPE;
+       __raw_writel(reg, MXC_CCM_CCMR);
+
+       /* No lock bit on MX31, so using max time from spec */
+       udelay(80);
+
+       return 0;
+}
+
+static void _clk_usb_pll_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_CCMR);
+       reg &= ~MXC_CCM_CCMR_UPE;
+       __raw_writel(reg, MXC_CCM_CCMR);
+}
+
+static int _clk_serial_pll_enable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_CCMR);
+       reg |= MXC_CCM_CCMR_SPE;
+       __raw_writel(reg, MXC_CCM_CCMR);
+
+       /* No lock bit on MX31, so using max time from spec */
+       udelay(80);
+
+       return 0;
+}
+
+static void _clk_serial_pll_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_CCMR);
+       reg &= ~MXC_CCM_CCMR_SPE;
+       __raw_writel(reg, MXC_CCM_CCMR);
+}
+
+#define PDR0(mask, off) ((__raw_readl(MXC_CCM_PDR0) & mask) >> off)
+#define PDR1(mask, off) ((__raw_readl(MXC_CCM_PDR1) & mask) >> off)
+#define PDR2(mask, off) ((__raw_readl(MXC_CCM_PDR2) & mask) >> off)
+
+static unsigned long _clk_mcu_main_get_rate(struct clk *clk)
+{
+       u32 pmcr0 = __raw_readl(MXC_CCM_PMCR0);
+
+       if ((pmcr0 & MXC_CCM_PMCR0_DFSUP1) == MXC_CCM_PMCR0_DFSUP1_SPLL)
+               return clk_get_rate(&serial_pll_clk);
+       else
+               return clk_get_rate(&mcu_pll_clk);
+}
+
+static unsigned long _clk_hclk_get_rate(struct clk *clk)
+{
+       unsigned long max_pdf;
+
+       max_pdf = PDR0(MXC_CCM_PDR0_MAX_PODF_MASK,
+                      MXC_CCM_PDR0_MAX_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (max_pdf + 1);
+}
+
+static unsigned long _clk_ipg_get_rate(struct clk *clk)
+{
+       unsigned long ipg_pdf;
+
+       ipg_pdf = PDR0(MXC_CCM_PDR0_IPG_PODF_MASK,
+                      MXC_CCM_PDR0_IPG_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (ipg_pdf + 1);
+}
+
+static unsigned long _clk_nfc_get_rate(struct clk *clk)
+{
+       unsigned long nfc_pdf;
+
+       nfc_pdf = PDR0(MXC_CCM_PDR0_NFC_PODF_MASK,
+                      MXC_CCM_PDR0_NFC_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (nfc_pdf + 1);
+}
+
+static unsigned long _clk_hsp_get_rate(struct clk *clk)
+{
+       unsigned long hsp_pdf;
+
+       hsp_pdf = PDR0(MXC_CCM_PDR0_HSP_PODF_MASK,
+                      MXC_CCM_PDR0_HSP_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (hsp_pdf + 1);
+}
+
+static unsigned long _clk_usb_get_rate(struct clk *clk)
+{
+       unsigned long usb_pdf, usb_prepdf;
+
+       usb_pdf = PDR1(MXC_CCM_PDR1_USB_PODF_MASK,
+                      MXC_CCM_PDR1_USB_PODF_OFFSET);
+       usb_prepdf = PDR1(MXC_CCM_PDR1_USB_PRDF_MASK,
+                         MXC_CCM_PDR1_USB_PRDF_OFFSET);
+       return clk_get_rate(clk->parent) / (usb_prepdf + 1) / (usb_pdf + 1);
+}
+
+static unsigned long _clk_csi_get_rate(struct clk *clk)
+{
+       u32 reg, pre, post;
+
+       reg = __raw_readl(MXC_CCM_PDR0);
+       pre = (reg & MXC_CCM_PDR0_CSI_PRDF_MASK) >>
+           MXC_CCM_PDR0_CSI_PRDF_OFFSET;
+       pre++;
+       post = (reg & MXC_CCM_PDR0_CSI_PODF_MASK) >>
+           MXC_CCM_PDR0_CSI_PODF_OFFSET;
+       post++;
+       return clk_get_rate(clk->parent) / (pre * post);
+}
+
+static unsigned long _clk_csi_round_rate(struct clk *clk, unsigned long rate)
+{
+       u32 pre, post, parent = clk_get_rate(clk->parent);
+       u32 div = parent / rate;
+
+       if (parent % rate)
+               div++;
+
+       __calc_pre_post_dividers(div, &pre, &post);
+
+       return parent / (pre * post);
+}
+
+static int _clk_csi_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
+
+       div = parent / rate;
+
+       if ((parent / div) != rate)
+               return -EINVAL;
+
+       __calc_pre_post_dividers(div, &pre, &post);
+
+       /* Set CSI clock divider */
+       reg = __raw_readl(MXC_CCM_PDR0) &
+           ~(MXC_CCM_PDR0_CSI_PODF_MASK | MXC_CCM_PDR0_CSI_PRDF_MASK);
+       reg |= (post - 1) << MXC_CCM_PDR0_CSI_PODF_OFFSET;
+       reg |= (pre - 1) << MXC_CCM_PDR0_CSI_PRDF_OFFSET;
+       __raw_writel(reg, MXC_CCM_PDR0);
+
+       return 0;
+}
+
+static unsigned long _clk_per_get_rate(struct clk *clk)
+{
+       unsigned long per_pdf;
+
+       per_pdf = PDR0(MXC_CCM_PDR0_PER_PODF_MASK,
+                      MXC_CCM_PDR0_PER_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (per_pdf + 1);
+}
+
+static unsigned long _clk_ssi1_get_rate(struct clk *clk)
+{
+       unsigned long ssi1_pdf, ssi1_prepdf;
+
+       ssi1_pdf = PDR1(MXC_CCM_PDR1_SSI1_PODF_MASK,
+                       MXC_CCM_PDR1_SSI1_PODF_OFFSET);
+       ssi1_prepdf = PDR1(MXC_CCM_PDR1_SSI1_PRE_PODF_MASK,
+                          MXC_CCM_PDR1_SSI1_PRE_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (ssi1_prepdf + 1) / (ssi1_pdf + 1);
+}
+
+static unsigned long _clk_ssi2_get_rate(struct clk *clk)
+{
+       unsigned long ssi2_pdf, ssi2_prepdf;
+
+       ssi2_pdf = PDR1(MXC_CCM_PDR1_SSI2_PODF_MASK,
+                       MXC_CCM_PDR1_SSI2_PODF_OFFSET);
+       ssi2_prepdf = PDR1(MXC_CCM_PDR1_SSI2_PRE_PODF_MASK,
+                          MXC_CCM_PDR1_SSI2_PRE_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (ssi2_prepdf + 1) / (ssi2_pdf + 1);
+}
+
+static unsigned long _clk_firi_get_rate(struct clk *clk)
+{
+       unsigned long firi_pdf, firi_prepdf;
+
+       firi_pdf = PDR1(MXC_CCM_PDR1_FIRI_PODF_MASK,
+                       MXC_CCM_PDR1_FIRI_PODF_OFFSET);
+       firi_prepdf = PDR1(MXC_CCM_PDR1_FIRI_PRE_PODF_MASK,
+                          MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET);
+       return clk_get_rate(clk->parent) / (firi_prepdf + 1) / (firi_pdf + 1);
+}
+
+static unsigned long _clk_firi_round_rate(struct clk *clk, unsigned long rate)
+{
+       u32 pre, post;
+       u32 parent = clk_get_rate(clk->parent);
+       u32 div = parent / rate;
+
+       if (parent % rate)
+               div++;
+
+       __calc_pre_post_dividers(div, &pre, &post);
+
+       return parent / (pre * post);
+
+}
+
+static int _clk_firi_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg, div, pre, post, parent = clk_get_rate(clk->parent);
+
+       div = parent / rate;
+
+       if ((parent / div) != rate)
+               return -EINVAL;
+
+       __calc_pre_post_dividers(div, &pre, &post);
+
+       /* Set FIRI clock divider */
+       reg = __raw_readl(MXC_CCM_PDR1) &
+           ~(MXC_CCM_PDR1_FIRI_PODF_MASK | MXC_CCM_PDR1_FIRI_PRE_PODF_MASK);
+       reg |= (pre - 1) << MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET;
+       reg |= (post - 1) << MXC_CCM_PDR1_FIRI_PODF_OFFSET;
+       __raw_writel(reg, MXC_CCM_PDR1);
+
+       return 0;
+}
+
+static unsigned long _clk_mbx_get_rate(struct clk *clk)
+{
+       return clk_get_rate(clk->parent) / 2;
+}
+
+static unsigned long _clk_mstick1_get_rate(struct clk *clk)
+{
+       unsigned long msti_pdf;
+
+       msti_pdf = PDR2(MXC_CCM_PDR2_MST1_PDF_MASK,
+                       MXC_CCM_PDR2_MST1_PDF_OFFSET);
+       return clk_get_rate(clk->parent) / (msti_pdf + 1);
+}
+
+static unsigned long _clk_mstick2_get_rate(struct clk *clk)
+{
+       unsigned long msti_pdf;
+
+       msti_pdf = PDR2(MXC_CCM_PDR2_MST2_PDF_MASK,
+                       MXC_CCM_PDR2_MST2_PDF_OFFSET);
+       return clk_get_rate(clk->parent) / (msti_pdf + 1);
+}
+
+static unsigned long ckih_rate;
+
+static unsigned long clk_ckih_get_rate(struct clk *clk)
+{
+       return ckih_rate;
+}
+
+static struct clk ckih_clk = {
+       .name = "ckih",
+       .get_rate = clk_ckih_get_rate,
+};
+
+static unsigned long clk_ckil_get_rate(struct clk *clk)
+{
+       return CKIL_CLK_FREQ;
+}
+
+static struct clk ckil_clk = {
+       .name = "ckil",
+       .get_rate = clk_ckil_get_rate,
+};
+
+static struct clk mcu_pll_clk = {
+       .name = "mcu_pll",
+       .parent = &ckih_clk,
+       .set_rate = _clk_pll_set_rate,
+       .get_rate = _clk_pll_get_rate,
+};
+
+static struct clk mcu_main_clk = {
+       .name = "mcu_main_clk",
+       .parent = &mcu_pll_clk,
+       .get_rate = _clk_mcu_main_get_rate,
+};
+
+static struct clk serial_pll_clk = {
+       .name = "serial_pll",
+       .parent = &ckih_clk,
+       .set_rate = _clk_pll_set_rate,
+       .get_rate = _clk_pll_get_rate,
+       .enable = _clk_serial_pll_enable,
+       .disable = _clk_serial_pll_disable,
+};
+
+static struct clk usb_pll_clk = {
+       .name = "usb_pll",
+       .parent = &ckih_clk,
+       .set_rate = _clk_pll_set_rate,
+       .get_rate = _clk_pll_get_rate,
+       .enable = _clk_usb_pll_enable,
+       .disable = _clk_usb_pll_disable,
+};
+
+static struct clk ahb_clk = {
+       .name = "ahb_clk",
+       .parent = &mcu_main_clk,
+       .get_rate = _clk_hclk_get_rate,
+};
+
+static struct clk per_clk = {
+       .name = "per_clk",
+       .parent = &usb_pll_clk,
+       .get_rate = _clk_per_get_rate,
+};
+
+static struct clk perclk_clk = {
+       .name = "perclk_clk",
+       .parent = &ipg_clk,
+};
+
+static struct clk cspi_clk[] = {
+       {
+        .name = "cspi_clk",
+        .id = 0,
+        .parent = &ipg_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR2,
+        .enable_shift = MXC_CCM_CGR2_CSPI1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "cspi_clk",
+        .id = 1,
+        .parent = &ipg_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR2,
+        .enable_shift = MXC_CCM_CGR2_CSPI2_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "cspi_clk",
+        .id = 2,
+        .parent = &ipg_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_CSPI3_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk ipg_clk = {
+       .name = "ipg_clk",
+       .parent = &ahb_clk,
+       .get_rate = _clk_ipg_get_rate,
+};
+
+static struct clk emi_clk = {
+       .name = "emi_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR2,
+       .enable_shift = MXC_CCM_CGR2_EMI_OFFSET,
+       .disable = _clk_emi_disable,
+};
+
+static struct clk gpt_clk = {
+       .name = "gpt_clk",
+       .parent = &perclk_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR0,
+       .enable_shift = MXC_CCM_CGR0_GPT_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk pwm_clk = {
+       .name = "pwm_clk",
+       .parent = &perclk_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR0,
+       .enable_shift = MXC_CCM_CGR1_PWM_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk epit_clk[] = {
+       {
+        .name = "epit_clk",
+        .id = 0,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_EPIT1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "epit_clk",
+        .id = 1,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_EPIT2_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk nfc_clk = {
+       .name = "nfc_clk",
+       .parent = &ahb_clk,
+       .get_rate = _clk_nfc_get_rate,
+};
+
+static struct clk scc_clk = {
+       .name = "scc_clk",
+       .parent = &ipg_clk,
+};
+
+static struct clk ipu_clk = {
+       .name = "ipu_clk",
+       .parent = &mcu_main_clk,
+       .get_rate = _clk_hsp_get_rate,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_IPU_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk kpp_clk = {
+       .name = "kpp_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_KPP_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk wdog_clk = {
+       .name = "wdog_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_WDOG_OFFSET,
+       .disable = _clk_disable,
+};
+static struct clk rtc_clk = {
+       .name = "rtc_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_RTC_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk usb_clk[] = {
+       {
+        .name = "usb_clk",
+        .parent = &usb_pll_clk,
+        .get_rate = _clk_usb_get_rate,},
+       {
+        .name = "usb_ahb_clk",
+        .parent = &ahb_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_USBOTG_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk csi_clk = {
+       .name = "csi_clk",
+       .parent = &serial_pll_clk,
+       .get_rate = _clk_csi_get_rate,
+       .round_rate = _clk_csi_round_rate,
+       .set_rate = _clk_csi_set_rate,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_CSI_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk uart_clk[] = {
+       {
+        .name = "uart_clk",
+        .id = 0,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_UART1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "uart_clk",
+        .id = 1,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_UART2_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "uart_clk",
+        .id = 2,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_UART3_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "uart_clk",
+        .id = 3,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_UART4_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "uart_clk",
+        .id = 4,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_UART5_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk i2c_clk[] = {
+       {
+        .name = "i2c_clk",
+        .id = 0,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_I2C1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "i2c_clk",
+        .id = 1,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_I2C2_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "i2c_clk",
+        .id = 2,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_I2C3_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk owire_clk = {
+       .name = "owire_clk",
+       .parent = &perclk_clk,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_OWIRE_OFFSET,
+       .enable = _clk_enable,
+       .disable = _clk_disable,
+};
+
+static struct clk sdhc_clk[] = {
+       {
+        .name = "sdhc_clk",
+        .id = 0,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_SD_MMC1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "sdhc_clk",
+        .id = 1,
+        .parent = &perclk_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_SD_MMC2_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk ssi_clk[] = {
+       {
+        .name = "ssi_clk",
+        .parent = &serial_pll_clk,
+        .get_rate = _clk_ssi1_get_rate,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_SSI1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "ssi_clk",
+        .id = 1,
+        .parent = &serial_pll_clk,
+        .get_rate = _clk_ssi2_get_rate,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR2,
+        .enable_shift = MXC_CCM_CGR2_SSI2_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk firi_clk = {
+       .name = "firi_clk",
+       .parent = &usb_pll_clk,
+       .round_rate = _clk_firi_round_rate,
+       .set_rate = _clk_firi_set_rate,
+       .get_rate = _clk_firi_get_rate,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR2,
+       .enable_shift = MXC_CCM_CGR2_FIRI_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk ata_clk = {
+       .name = "ata_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR0,
+       .enable_shift = MXC_CCM_CGR0_ATA_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk mbx_clk = {
+       .name = "mbx_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR2,
+       .enable_shift = MXC_CCM_CGR2_GACC_OFFSET,
+       .get_rate = _clk_mbx_get_rate,
+};
+
+static struct clk vpu_clk = {
+       .name = "vpu_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR2,
+       .enable_shift = MXC_CCM_CGR2_GACC_OFFSET,
+       .get_rate = _clk_mbx_get_rate,
+};
+
+static struct clk rtic_clk = {
+       .name = "rtic_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR2,
+       .enable_shift = MXC_CCM_CGR2_RTIC_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk rng_clk = {
+       .name = "rng_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR0,
+       .enable_shift = MXC_CCM_CGR0_RNG_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk sdma_clk[] = {
+       {
+        .name = "sdma_ahb_clk",
+        .parent = &ahb_clk,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR0,
+        .enable_shift = MXC_CCM_CGR0_SDMA_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "sdma_ipg_clk",
+        .parent = &ipg_clk,}
+};
+
+static struct clk mpeg4_clk = {
+       .name = "mpeg4_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_HANTRO_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk vl2cc_clk = {
+       .name = "vl2cc_clk",
+       .parent = &ahb_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR1,
+       .enable_shift = MXC_CCM_CGR1_HANTRO_OFFSET,
+       .disable = _clk_disable,
+};
+
+static struct clk mstick_clk[] = {
+       {
+        .name = "mstick_clk",
+        .id = 0,
+        .parent = &usb_pll_clk,
+        .get_rate = _clk_mstick1_get_rate,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_MEMSTICK1_OFFSET,
+        .disable = _clk_disable,},
+       {
+        .name = "mstick_clk",
+        .id = 1,
+        .parent = &usb_pll_clk,
+        .get_rate = _clk_mstick2_get_rate,
+        .enable = _clk_enable,
+        .enable_reg = MXC_CCM_CGR1,
+        .enable_shift = MXC_CCM_CGR1_MEMSTICK2_OFFSET,
+        .disable = _clk_disable,},
+};
+
+static struct clk iim_clk = {
+       .name = "iim_clk",
+       .parent = &ipg_clk,
+       .enable = _clk_enable,
+       .enable_reg = MXC_CCM_CGR0,
+       .enable_shift = MXC_CCM_CGR0_IIM_OFFSET,
+       .disable = _clk_disable,
+};
+
+static unsigned long _clk_cko1_round_rate(struct clk *clk, unsigned long rate)
+{
+       u32 div, parent = clk_get_rate(clk->parent);
+
+       div = parent / rate;
+       if (parent % rate)
+               div++;
+
+       if (div > 8)
+               div = 16;
+       else if (div > 4)
+               div = 8;
+       else if (div > 2)
+               div = 4;
+
+       return parent / div;
+}
+
+static int _clk_cko1_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 reg, div, parent = clk_get_rate(clk->parent);
+
+       div = parent / rate;
+
+       if (div == 16)
+               div = 4;
+       else if (div == 8)
+               div = 3;
+       else if (div == 4)
+               div = 2;
+       else if (div == 2)
+               div = 1;
+       else if (div == 1)
+               div = 0;
+       else
+               return -EINVAL;
+
+       reg = __raw_readl(MXC_CCM_COSR) & ~MXC_CCM_COSR_CLKOUTDIV_MASK;
+       reg |= div << MXC_CCM_COSR_CLKOUTDIV_OFFSET;
+       __raw_writel(reg, MXC_CCM_COSR);
+
+       return 0;
+}
+
+static unsigned long _clk_cko1_get_rate(struct clk *clk)
+{
+       u32 div;
+
+       div = __raw_readl(MXC_CCM_COSR) & MXC_CCM_COSR_CLKOUTDIV_MASK >>
+           MXC_CCM_COSR_CLKOUTDIV_OFFSET;
+
+       return clk_get_rate(clk->parent) / (1 << div);
+}
+
+static int _clk_cko1_set_parent(struct clk *clk, struct clk *parent)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_COSR) & ~MXC_CCM_COSR_CLKOSEL_MASK;
+
+       if (parent == &mcu_main_clk)
+               reg |= 0 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &ipg_clk)
+               reg |= 1 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &usb_pll_clk)
+               reg |= 2 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == mcu_main_clk.parent)
+               reg |= 3 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &ahb_clk)
+               reg |= 5 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &serial_pll_clk)
+               reg |= 7 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &ckih_clk)
+               reg |= 8 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &emi_clk)
+               reg |= 9 << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &ipu_clk)
+               reg |= 0xA << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &nfc_clk)
+               reg |= 0xB << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else if (parent == &uart_clk[0])
+               reg |= 0xC << MXC_CCM_COSR_CLKOSEL_OFFSET;
+       else
+               return -EINVAL;
+
+       __raw_writel(reg, MXC_CCM_COSR);
+
+       return 0;
+}
+
+static int _clk_cko1_enable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_COSR) | MXC_CCM_COSR_CLKOEN;
+       __raw_writel(reg, MXC_CCM_COSR);
+
+       return 0;
+}
+
+static void _clk_cko1_disable(struct clk *clk)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_COSR) & ~MXC_CCM_COSR_CLKOEN;
+       __raw_writel(reg, MXC_CCM_COSR);
+}
+
+static struct clk cko1_clk = {
+       .name = "cko1_clk",
+       .get_rate = _clk_cko1_get_rate,
+       .set_rate = _clk_cko1_set_rate,
+       .round_rate = _clk_cko1_round_rate,
+       .set_parent = _clk_cko1_set_parent,
+       .enable = _clk_cko1_enable,
+       .disable = _clk_cko1_disable,
+};
+
+static struct clk *mxc_clks[] = {
+       &ckih_clk,
+       &ckil_clk,
+       &mcu_pll_clk,
+       &usb_pll_clk,
+       &serial_pll_clk,
+       &mcu_main_clk,
+       &ahb_clk,
+       &per_clk,
+       &perclk_clk,
+       &cko1_clk,
+       &emi_clk,
+       &cspi_clk[0],
+       &cspi_clk[1],
+       &cspi_clk[2],
+       &ipg_clk,
+       &gpt_clk,
+       &pwm_clk,
+       &wdog_clk,
+       &rtc_clk,
+       &epit_clk[0],
+       &epit_clk[1],
+       &nfc_clk,
+       &ipu_clk,
+       &kpp_clk,
+       &usb_clk[0],
+       &usb_clk[1],
+       &csi_clk,
+       &uart_clk[0],
+       &uart_clk[1],
+       &uart_clk[2],
+       &uart_clk[3],
+       &uart_clk[4],
+       &i2c_clk[0],
+       &i2c_clk[1],
+       &i2c_clk[2],
+       &owire_clk,
+       &sdhc_clk[0],
+       &sdhc_clk[1],
+       &ssi_clk[0],
+       &ssi_clk[1],
+       &firi_clk,
+       &ata_clk,
+       &rtic_clk,
+       &rng_clk,
+       &sdma_clk[0],
+       &sdma_clk[1],
+       &mstick_clk[0],
+       &mstick_clk[1],
+       &scc_clk,
+       &iim_clk,
+};
+
+int __init mxc_clocks_init(unsigned long fref)
+{
+       u32 reg;
+       struct clk **clkp;
+
+       ckih_rate = fref;
+
+       for (clkp = mxc_clks; clkp < mxc_clks + ARRAY_SIZE(mxc_clks); clkp++)
+               clk_register(*clkp);
+
+       if (cpu_is_mx31()) {
+               clk_register(&mpeg4_clk);
+               clk_register(&mbx_clk);
+       } else {
+               clk_register(&vpu_clk);
+               clk_register(&vl2cc_clk);
+       }
+
+       /* Turn off all possible clocks */
+       __raw_writel(MXC_CCM_CGR0_GPT_MASK, MXC_CCM_CGR0);
+       __raw_writel(0, MXC_CCM_CGR1);
+
+       __raw_writel(MXC_CCM_CGR2_EMI_MASK |
+                    MXC_CCM_CGR2_IPMUX1_MASK |
+                    MXC_CCM_CGR2_IPMUX2_MASK |
+                    MXC_CCM_CGR2_MXCCLKENSEL_MASK |    /* for MX32 */
+                    MXC_CCM_CGR2_CHIKCAMPEN_MASK |     /* for MX32 */
+                    MXC_CCM_CGR2_OVRVPUBUSY_MASK |     /* for MX32 */
+                    1 << 27 | 1 << 28, /* Bit 27 and 28 are not defined for
+                                          MX32, but still required to be set */
+                    MXC_CCM_CGR2);
+
+       clk_disable(&cko1_clk);
+       clk_disable(&usb_pll_clk);
+
+       pr_info("Clock input source is %ld\n", clk_get_rate(&ckih_clk));
+
+       clk_enable(&gpt_clk);
+       clk_enable(&emi_clk);
+       clk_enable(&iim_clk);
+
+       clk_enable(&serial_pll_clk);
+
+       if (mx31_revision() >= CHIP_REV_2_0) {
+               reg = __raw_readl(MXC_CCM_PMCR1);
+               /* No PLL restart on DVFS switch; enable auto EMI handshake */
+               reg |= MXC_CCM_PMCR1_PLLRDIS | MXC_CCM_PMCR1_EMIRQ_EN;
+               __raw_writel(reg, MXC_CCM_PMCR1);
+       }
+
+       return 0;
+}
+
diff --git a/arch/arm/mach-mx3/crm_regs.h b/arch/arm/mach-mx3/crm_regs.h
new file mode 100644 (file)
index 0000000..4a0e0ed
--- /dev/null
@@ -0,0 +1,401 @@
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef __ARCH_ARM_MACH_MX3_CRM_REGS_H__
+#define __ARCH_ARM_MACH_MX3_CRM_REGS_H__
+
+#define CKIH_CLK_FREQ           26000000
+#define CKIH_CLK_FREQ_27MHZ     27000000
+#define CKIL_CLK_FREQ           32768
+
+#define MXC_CCM_BASE           IO_ADDRESS(CCM_BASE_ADDR)
+
+/* Register addresses */
+#define MXC_CCM_CCMR           (MXC_CCM_BASE + 0x00)
+#define MXC_CCM_PDR0           (MXC_CCM_BASE + 0x04)
+#define MXC_CCM_PDR1           (MXC_CCM_BASE + 0x08)
+#define MXC_CCM_RCSR           (MXC_CCM_BASE + 0x0C)
+#define MXC_CCM_MPCTL          (MXC_CCM_BASE + 0x10)
+#define MXC_CCM_UPCTL          (MXC_CCM_BASE + 0x14)
+#define MXC_CCM_SRPCTL         (MXC_CCM_BASE + 0x18)
+#define MXC_CCM_COSR           (MXC_CCM_BASE + 0x1C)
+#define MXC_CCM_CGR0           (MXC_CCM_BASE + 0x20)
+#define MXC_CCM_CGR1           (MXC_CCM_BASE + 0x24)
+#define MXC_CCM_CGR2           (MXC_CCM_BASE + 0x28)
+#define MXC_CCM_WIMR           (MXC_CCM_BASE + 0x2C)
+#define MXC_CCM_LDC            (MXC_CCM_BASE + 0x30)
+#define MXC_CCM_DCVR0          (MXC_CCM_BASE + 0x34)
+#define MXC_CCM_DCVR1          (MXC_CCM_BASE + 0x38)
+#define MXC_CCM_DCVR2          (MXC_CCM_BASE + 0x3C)
+#define MXC_CCM_DCVR3          (MXC_CCM_BASE + 0x40)
+#define MXC_CCM_LTR0           (MXC_CCM_BASE + 0x44)
+#define MXC_CCM_LTR1           (MXC_CCM_BASE + 0x48)
+#define MXC_CCM_LTR2           (MXC_CCM_BASE + 0x4C)
+#define MXC_CCM_LTR3           (MXC_CCM_BASE + 0x50)
+#define MXC_CCM_LTBR0          (MXC_CCM_BASE + 0x54)
+#define MXC_CCM_LTBR1          (MXC_CCM_BASE + 0x58)
+#define MXC_CCM_PMCR0          (MXC_CCM_BASE + 0x5C)
+#define MXC_CCM_PMCR1          (MXC_CCM_BASE + 0x60)
+#define MXC_CCM_PDR2           (MXC_CCM_BASE + 0x64)
+
+/* Register bit definitions */
+#define MXC_CCM_CCMR_WBEN                       (1 << 27)
+#define MXC_CCM_CCMR_CSCS                       (1 << 25)
+#define MXC_CCM_CCMR_PERCS                      (1 << 24)
+#define MXC_CCM_CCMR_SSI1S_OFFSET               18
+#define MXC_CCM_CCMR_SSI1S_MASK                 (0x3 << 18)
+#define MXC_CCM_CCMR_SSI2S_OFFSET               21
+#define MXC_CCM_CCMR_SSI2S_MASK                 (0x3 << 21)
+#define MXC_CCM_CCMR_LPM_OFFSET                 14
+#define MXC_CCM_CCMR_LPM_MASK                   (0x3 << 14)
+#define MXC_CCM_CCMR_FIRS_OFFSET                11
+#define MXC_CCM_CCMR_FIRS_MASK                  (0x3 << 11)
+#define MXC_CCM_CCMR_UPE                        (1 << 9)
+#define MXC_CCM_CCMR_SPE                        (1 << 8)
+#define MXC_CCM_CCMR_MDS                        (1 << 7)
+#define MXC_CCM_CCMR_SBYCS                      (1 << 4)
+#define MXC_CCM_CCMR_MPE                        (1 << 3)
+#define MXC_CCM_CCMR_PRCS_OFFSET                1
+#define MXC_CCM_CCMR_PRCS_MASK                  (0x3 << 1)
+
+#define MXC_CCM_PDR0_CSI_PODF_OFFSET            26
+#define MXC_CCM_PDR0_CSI_PODF_MASK              (0x3F << 26)
+#define MXC_CCM_PDR0_CSI_PRDF_OFFSET            23
+#define MXC_CCM_PDR0_CSI_PRDF_MASK              (0x7 << 23)
+#define MXC_CCM_PDR0_PER_PODF_OFFSET            16
+#define MXC_CCM_PDR0_PER_PODF_MASK              (0x1F << 16)
+#define MXC_CCM_PDR0_HSP_PODF_OFFSET            11
+#define MXC_CCM_PDR0_HSP_PODF_MASK              (0x7 << 11)
+#define MXC_CCM_PDR0_NFC_PODF_OFFSET            8
+#define MXC_CCM_PDR0_NFC_PODF_MASK              (0x7 << 8)
+#define MXC_CCM_PDR0_IPG_PODF_OFFSET            6
+#define MXC_CCM_PDR0_IPG_PODF_MASK              (0x3 << 6)
+#define MXC_CCM_PDR0_MAX_PODF_OFFSET            3
+#define MXC_CCM_PDR0_MAX_PODF_MASK              (0x7 << 3)
+#define MXC_CCM_PDR0_MCU_PODF_OFFSET            0
+#define MXC_CCM_PDR0_MCU_PODF_MASK              0x7
+
+#define MXC_CCM_PDR0_HSP_DIV_1                  (0x0 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_2                  (0x1 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_3                  (0x2 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_4                  (0x3 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_5                  (0x4 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_6                  (0x5 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_7                  (0x6 << 11)
+#define MXC_CCM_PDR0_HSP_DIV_8                  (0x7 << 11)
+
+#define MXC_CCM_PDR0_IPG_DIV_1                  (0x0 << 6)
+#define MXC_CCM_PDR0_IPG_DIV_2                  (0x1 << 6)
+#define MXC_CCM_PDR0_IPG_DIV_3                  (0x2 << 6)
+#define MXC_CCM_PDR0_IPG_DIV_4                  (0x3 << 6)
+
+#define MXC_CCM_PDR0_MAX_DIV_1                  (0x0 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_2                  (0x1 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_3                  (0x2 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_4                  (0x3 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_5                  (0x4 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_6                  (0x5 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_7                  (0x6 << 3)
+#define MXC_CCM_PDR0_MAX_DIV_8                  (0x7 << 3)
+
+#define MXC_CCM_PDR0_NFC_DIV_1                  (0x0 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_2                  (0x1 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_3                  (0x2 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_4                  (0x3 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_5                  (0x4 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_6                  (0x5 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_7                  (0x6 << 8)
+#define MXC_CCM_PDR0_NFC_DIV_8                  (0x7 << 8)
+
+#define MXC_CCM_PDR0_MCU_DIV_1                  0x0
+#define MXC_CCM_PDR0_MCU_DIV_2                  0x1
+#define MXC_CCM_PDR0_MCU_DIV_3                  0x2
+#define MXC_CCM_PDR0_MCU_DIV_4                  0x3
+#define MXC_CCM_PDR0_MCU_DIV_5                  0x4
+#define MXC_CCM_PDR0_MCU_DIV_6                  0x5
+#define MXC_CCM_PDR0_MCU_DIV_7                  0x6
+#define MXC_CCM_PDR0_MCU_DIV_8                  0x7
+
+#define MXC_CCM_PDR1_USB_PRDF_OFFSET            30
+#define MXC_CCM_PDR1_USB_PRDF_MASK              (0x3 << 30)
+#define MXC_CCM_PDR1_USB_PODF_OFFSET            27
+#define MXC_CCM_PDR1_USB_PODF_MASK              (0x7 << 27)
+#define MXC_CCM_PDR1_FIRI_PRE_PODF_OFFSET       24
+#define MXC_CCM_PDR1_FIRI_PRE_PODF_MASK         (0x7 << 24)
+#define MXC_CCM_PDR1_FIRI_PODF_OFFSET           18
+#define MXC_CCM_PDR1_FIRI_PODF_MASK             (0x3F << 18)
+#define MXC_CCM_PDR1_SSI2_PRE_PODF_OFFSET       15
+#define MXC_CCM_PDR1_SSI2_PRE_PODF_MASK         (0x7 << 15)
+#define MXC_CCM_PDR1_SSI2_PODF_OFFSET           9
+#define MXC_CCM_PDR1_SSI2_PODF_MASK             (0x3F << 9)
+#define MXC_CCM_PDR1_SSI1_PRE_PODF_OFFSET       6
+#define MXC_CCM_PDR1_SSI1_PRE_PODF_MASK         (0x7 << 6)
+#define MXC_CCM_PDR1_SSI1_PODF_OFFSET           0
+#define MXC_CCM_PDR1_SSI1_PODF_MASK             0x3F
+
+/* Bit definitions for RCSR */
+#define MXC_CCM_RCSR_NF16B                     0x80000000
+
+/* Bit definitions for both MCU, USB and SR PLL control registers */
+#define MXC_CCM_PCTL_BRM                        0x80000000
+#define MXC_CCM_PCTL_PD_OFFSET                  26
+#define MXC_CCM_PCTL_PD_MASK                    (0xF << 26)
+#define MXC_CCM_PCTL_MFD_OFFSET                 16
+#define MXC_CCM_PCTL_MFD_MASK                   (0x3FF << 16)
+#define MXC_CCM_PCTL_MFI_OFFSET                 10
+#define MXC_CCM_PCTL_MFI_MASK                   (0xF << 10)
+#define MXC_CCM_PCTL_MFN_OFFSET                 0
+#define MXC_CCM_PCTL_MFN_MASK                   0x3FF
+
+#define MXC_CCM_CGR0_SD_MMC1_OFFSET             0
+#define MXC_CCM_CGR0_SD_MMC1_MASK               (0x3 << 0)
+#define MXC_CCM_CGR0_SD_MMC2_OFFSET             2
+#define MXC_CCM_CGR0_SD_MMC2_MASK               (0x3 << 2)
+#define MXC_CCM_CGR0_GPT_OFFSET                 4
+#define MXC_CCM_CGR0_GPT_MASK                   (0x3 << 4)
+#define MXC_CCM_CGR0_EPIT1_OFFSET               6
+#define MXC_CCM_CGR0_EPIT1_MASK                 (0x3 << 6)
+#define MXC_CCM_CGR0_EPIT2_OFFSET               8
+#define MXC_CCM_CGR0_EPIT2_MASK                 (0x3 << 8)
+#define MXC_CCM_CGR0_IIM_OFFSET                 10
+#define MXC_CCM_CGR0_IIM_MASK                   (0x3 << 10)
+#define MXC_CCM_CGR0_ATA_OFFSET                 12
+#define MXC_CCM_CGR0_ATA_MASK                   (0x3 << 12)
+#define MXC_CCM_CGR0_SDMA_OFFSET                14
+#define MXC_CCM_CGR0_SDMA_MASK                  (0x3 << 14)
+#define MXC_CCM_CGR0_CSPI3_OFFSET               16
+#define MXC_CCM_CGR0_CSPI3_MASK                 (0x3 << 16)
+#define MXC_CCM_CGR0_RNG_OFFSET                 18
+#define MXC_CCM_CGR0_RNG_MASK                   (0x3 << 18)
+#define MXC_CCM_CGR0_UART1_OFFSET               20
+#define MXC_CCM_CGR0_UART1_MASK                 (0x3 << 20)
+#define MXC_CCM_CGR0_UART2_OFFSET               22
+#define MXC_CCM_CGR0_UART2_MASK                 (0x3 << 22)
+#define MXC_CCM_CGR0_SSI1_OFFSET                24
+#define MXC_CCM_CGR0_SSI1_MASK                  (0x3 << 24)
+#define MXC_CCM_CGR0_I2C1_OFFSET                26
+#define MXC_CCM_CGR0_I2C1_MASK                  (0x3 << 26)
+#define MXC_CCM_CGR0_I2C2_OFFSET                28
+#define MXC_CCM_CGR0_I2C2_MASK                  (0x3 << 28)
+#define MXC_CCM_CGR0_I2C3_OFFSET                30
+#define MXC_CCM_CGR0_I2C3_MASK                  (0x3 << 30)
+
+#define MXC_CCM_CGR1_HANTRO_OFFSET              0
+#define MXC_CCM_CGR1_HANTRO_MASK                (0x3 << 0)
+#define MXC_CCM_CGR1_MEMSTICK1_OFFSET           2
+#define MXC_CCM_CGR1_MEMSTICK1_MASK             (0x3 << 2)
+#define MXC_CCM_CGR1_MEMSTICK2_OFFSET           4
+#define MXC_CCM_CGR1_MEMSTICK2_MASK             (0x3 << 4)
+#define MXC_CCM_CGR1_CSI_OFFSET                 6
+#define MXC_CCM_CGR1_CSI_MASK                   (0x3 << 6)
+#define MXC_CCM_CGR1_RTC_OFFSET                 8
+#define MXC_CCM_CGR1_RTC_MASK                   (0x3 << 8)
+#define MXC_CCM_CGR1_WDOG_OFFSET                10
+#define MXC_CCM_CGR1_WDOG_MASK                  (0x3 << 10)
+#define MXC_CCM_CGR1_PWM_OFFSET                 12
+#define MXC_CCM_CGR1_PWM_MASK                   (0x3 << 12)
+#define MXC_CCM_CGR1_SIM_OFFSET                 14
+#define MXC_CCM_CGR1_SIM_MASK                   (0x3 << 14)
+#define MXC_CCM_CGR1_ECT_OFFSET                 16
+#define MXC_CCM_CGR1_ECT_MASK                   (0x3 << 16)
+#define MXC_CCM_CGR1_USBOTG_OFFSET              18
+#define MXC_CCM_CGR1_USBOTG_MASK                (0x3 << 18)
+#define MXC_CCM_CGR1_KPP_OFFSET                 20
+#define MXC_CCM_CGR1_KPP_MASK                   (0x3 << 20)
+#define MXC_CCM_CGR1_IPU_OFFSET                 22
+#define MXC_CCM_CGR1_IPU_MASK                   (0x3 << 22)
+#define MXC_CCM_CGR1_UART3_OFFSET               24
+#define MXC_CCM_CGR1_UART3_MASK                 (0x3 << 24)
+#define MXC_CCM_CGR1_UART4_OFFSET               26
+#define MXC_CCM_CGR1_UART4_MASK                 (0x3 << 26)
+#define MXC_CCM_CGR1_UART5_OFFSET               28
+#define MXC_CCM_CGR1_UART5_MASK                 (0x3 << 28)
+#define MXC_CCM_CGR1_OWIRE_OFFSET               30
+#define MXC_CCM_CGR1_OWIRE_MASK                 (0x3 << 30)
+
+#define MXC_CCM_CGR2_SSI2_OFFSET                0
+#define MXC_CCM_CGR2_SSI2_MASK                  (0x3 << 0)
+#define MXC_CCM_CGR2_CSPI1_OFFSET               2
+#define MXC_CCM_CGR2_CSPI1_MASK                 (0x3 << 2)
+#define MXC_CCM_CGR2_CSPI2_OFFSET               4
+#define MXC_CCM_CGR2_CSPI2_MASK                 (0x3 << 4)
+#define MXC_CCM_CGR2_GACC_OFFSET                6
+#define MXC_CCM_CGR2_GACC_MASK                  (0x3 << 6)
+#define MXC_CCM_CGR2_EMI_OFFSET                 8
+#define MXC_CCM_CGR2_EMI_MASK                   (0x3 << 8)
+#define MXC_CCM_CGR2_RTIC_OFFSET                10
+#define MXC_CCM_CGR2_RTIC_MASK                  (0x3 << 10)
+#define MXC_CCM_CGR2_FIRI_OFFSET                12
+#define MXC_CCM_CGR2_FIRI_MASK                  (0x3 << 12)
+#define MXC_CCM_CGR2_IPMUX1_OFFSET              14
+#define MXC_CCM_CGR2_IPMUX1_MASK                (0x3 << 14)
+#define MXC_CCM_CGR2_IPMUX2_OFFSET              16
+#define MXC_CCM_CGR2_IPMUX2_MASK                (0x3 << 16)
+
+/* These new CGR2 bits are added in MX32 */
+#define MXC_CCM_CGR2_APMSYSCLKSEL_OFFSET       18
+#define MXC_CCM_CGR2_APMSYSCLKSEL_MASK         (0x3 << 18)
+#define MXC_CCM_CGR2_APMSSICLKSEL_OFFSET       20
+#define MXC_CCM_CGR2_APMSSICLKSEL_MASK         (0x3 << 20)
+#define MXC_CCM_CGR2_APMPERCLKSEL_OFFSET       22
+#define MXC_CCM_CGR2_APMPERCLKSEL_MASK         (0x3 << 22)
+#define MXC_CCM_CGR2_MXCCLKENSEL_OFFSET                24
+#define MXC_CCM_CGR2_MXCCLKENSEL_MASK          (0x1 << 24)
+#define MXC_CCM_CGR2_CHIKCAMPEN_OFFSET         25
+#define MXC_CCM_CGR2_CHIKCAMPEN_MASK           (0x1 << 25)
+#define MXC_CCM_CGR2_OVRVPUBUSY_OFFSET         26
+#define MXC_CCM_CGR2_OVRVPUBUSY_MASK           (0x1 << 26)
+#define MXC_CCM_CGR2_APMENA_OFFSET             30
+#define MXC_CCM_CGR2_AOMENA_MASK               (0x1 << 30)
+
+/*
+ * LTR0 register offsets
+ */
+#define MXC_CCM_LTR0_DIV3CK_OFFSET              1
+#define MXC_CCM_LTR0_DIV3CK_MASK                (0x3 << 1)
+#define MXC_CCM_LTR0_DNTHR_OFFSET               16
+#define MXC_CCM_LTR0_DNTHR_MASK                 (0x3F << 16)
+#define MXC_CCM_LTR0_UPTHR_OFFSET               22
+#define MXC_CCM_LTR0_UPTHR_MASK                 (0x3F << 22)
+
+/*
+ * LTR1 register offsets
+ */
+#define MXC_CCM_LTR1_PNCTHR_OFFSET              0
+#define MXC_CCM_LTR1_PNCTHR_MASK                0x3F
+#define MXC_CCM_LTR1_UPCNT_OFFSET               6
+#define MXC_CCM_LTR1_UPCNT_MASK                 (0xFF << 6)
+#define MXC_CCM_LTR1_DNCNT_OFFSET               14
+#define MXC_CCM_LTR1_DNCNT_MASK                 (0xFF << 14)
+#define MXC_CCM_LTR1_LTBRSR_MASK                0x400000
+#define MXC_CCM_LTR1_LTBRSR_OFFSET              22
+#define MXC_CCM_LTR1_LTBRSR                     0x400000
+#define MXC_CCM_LTR1_LTBRSH                     0x800000
+
+/*
+ * LTR2 bit definitions. x ranges from 0 for WSW9 to 6 for WSW15
+ */
+#define MXC_CCM_LTR2_WSW_OFFSET(x)              (11 + (x) * 3)
+#define MXC_CCM_LTR2_WSW_MASK(x)                (0x7 << \
+                                       MXC_CCM_LTR2_WSW_OFFSET((x)))
+#define MXC_CCM_LTR2_EMAC_OFFSET                0
+#define MXC_CCM_LTR2_EMAC_MASK                  0x1FF
+
+/*
+ * LTR3 bit definitions. x ranges from 0 for WSW0 to 8 for WSW8
+ */
+#define MXC_CCM_LTR3_WSW_OFFSET(x)              (5 + (x) * 3)
+#define MXC_CCM_LTR3_WSW_MASK(x)                (0x7 << \
+                                       MXC_CCM_LTR3_WSW_OFFSET((x)))
+
+#define MXC_CCM_PMCR0_DFSUP1                    0x80000000
+#define MXC_CCM_PMCR0_DFSUP1_SPLL               (0 << 31)
+#define MXC_CCM_PMCR0_DFSUP1_MPLL               (1 << 31)
+#define MXC_CCM_PMCR0_DFSUP0                    0x40000000
+#define MXC_CCM_PMCR0_DFSUP0_PLL                (0 << 30)
+#define MXC_CCM_PMCR0_DFSUP0_PDR                (1 << 30)
+#define MXC_CCM_PMCR0_DFSUP_MASK                (0x3 << 30)
+
+#define DVSUP_TURBO                            0
+#define DVSUP_HIGH                             1
+#define DVSUP_MEDIUM                           2
+#define DVSUP_LOW                              3
+#define MXC_CCM_PMCR0_DVSUP_TURBO               (DVSUP_TURBO << 28)
+#define MXC_CCM_PMCR0_DVSUP_HIGH                (DVSUP_HIGH << 28)
+#define MXC_CCM_PMCR0_DVSUP_MEDIUM              (DVSUP_MEDIUM << 28)
+#define MXC_CCM_PMCR0_DVSUP_LOW                 (DVSUP_LOW << 28)
+#define MXC_CCM_PMCR0_DVSUP_OFFSET              28
+#define MXC_CCM_PMCR0_DVSUP_MASK                (0x3 << 28)
+#define MXC_CCM_PMCR0_UDSC                      0x08000000
+#define MXC_CCM_PMCR0_UDSC_MASK                 (1 << 27)
+#define MXC_CCM_PMCR0_UDSC_UP                   (1 << 27)
+#define MXC_CCM_PMCR0_UDSC_DOWN                 (0 << 27)
+
+#define MXC_CCM_PMCR0_VSCNT_1                   (0x0 << 24)
+#define MXC_CCM_PMCR0_VSCNT_2                   (0x1 << 24)
+#define MXC_CCM_PMCR0_VSCNT_3                   (0x2 << 24)
+#define MXC_CCM_PMCR0_VSCNT_4                   (0x3 << 24)
+#define MXC_CCM_PMCR0_VSCNT_5                   (0x4 << 24)
+#define MXC_CCM_PMCR0_VSCNT_6                   (0x5 << 24)
+#define MXC_CCM_PMCR0_VSCNT_7                   (0x6 << 24)
+#define MXC_CCM_PMCR0_VSCNT_8                   (0x7 << 24)
+#define MXC_CCM_PMCR0_VSCNT_OFFSET              24
+#define MXC_CCM_PMCR0_VSCNT_MASK                (0x7 << 24)
+#define MXC_CCM_PMCR0_DVFEV                     0x00800000
+#define MXC_CCM_PMCR0_DVFIS                     0x00400000
+#define MXC_CCM_PMCR0_LBMI                      0x00200000
+#define MXC_CCM_PMCR0_LBFL                      0x00100000
+#define MXC_CCM_PMCR0_LBCF_4                    (0x0 << 18)
+#define MXC_CCM_PMCR0_LBCF_8                    (0x1 << 18)
+#define MXC_CCM_PMCR0_LBCF_12                   (0x2 << 18)
+#define MXC_CCM_PMCR0_LBCF_16                   (0x3 << 18)
+#define MXC_CCM_PMCR0_LBCF_OFFSET               18
+#define MXC_CCM_PMCR0_LBCF_MASK                 (0x3 << 18)
+#define MXC_CCM_PMCR0_PTVIS                     0x00020000
+#define MXC_CCM_PMCR0_UPDTEN                    0x00010000
+#define MXC_CCM_PMCR0_UPDTEN_MASK               (0x1 << 16)
+#define MXC_CCM_PMCR0_FSVAIM                    0x00008000
+#define MXC_CCM_PMCR0_FSVAI_OFFSET              13
+#define MXC_CCM_PMCR0_FSVAI_MASK                (0x3 << 13)
+#define MXC_CCM_PMCR0_DPVCR                     0x00001000
+#define MXC_CCM_PMCR0_DPVV                      0x00000800
+#define MXC_CCM_PMCR0_WFIM                      0x00000400
+#define MXC_CCM_PMCR0_DRCE3                     0x00000200
+#define MXC_CCM_PMCR0_DRCE2                     0x00000100
+#define MXC_CCM_PMCR0_DRCE1                     0x00000080
+#define MXC_CCM_PMCR0_DRCE0                     0x00000040
+#define MXC_CCM_PMCR0_DCR                       0x00000020
+#define MXC_CCM_PMCR0_DVFEN                     0x00000010
+#define MXC_CCM_PMCR0_PTVAIM                    0x00000008
+#define MXC_CCM_PMCR0_PTVAI_OFFSET              1
+#define MXC_CCM_PMCR0_PTVAI_MASK                (0x3 << 1)
+#define MXC_CCM_PMCR0_DPTEN                     0x00000001
+
+#define MXC_CCM_PMCR1_DVGP_OFFSET               0
+#define MXC_CCM_PMCR1_DVGP_MASK                 (0xF)
+
+#define MXC_CCM_PMCR1_PLLRDIS                      (0x1 << 7)
+#define MXC_CCM_PMCR1_EMIRQ_EN                      (0x1 << 8)
+
+#define MXC_CCM_DCVR_ULV_MASK                   (0x3FF << 22)
+#define MXC_CCM_DCVR_ULV_OFFSET                 22
+#define MXC_CCM_DCVR_LLV_MASK                   (0x3FF << 12)
+#define MXC_CCM_DCVR_LLV_OFFSET                 12
+#define MXC_CCM_DCVR_ELV_MASK                   (0x3FF << 2)
+#define MXC_CCM_DCVR_ELV_OFFSET                 2
+
+#define MXC_CCM_PDR2_MST2_PDF_MASK              (0x3F << 7)
+#define MXC_CCM_PDR2_MST2_PDF_OFFSET            7
+#define MXC_CCM_PDR2_MST1_PDF_MASK              0x3F
+#define MXC_CCM_PDR2_MST1_PDF_OFFSET            0
+
+#define MXC_CCM_COSR_CLKOSEL_MASK               0x0F
+#define MXC_CCM_COSR_CLKOSEL_OFFSET             0
+#define MXC_CCM_COSR_CLKOUTDIV_MASK             (0x07 << 6)
+#define MXC_CCM_COSR_CLKOUTDIV_OFFSET           6
+#define MXC_CCM_COSR_CLKOEN                     (1 << 9)
+
+/*
+ * PMCR0 register offsets
+ */
+#define MXC_CCM_PMCR0_LBFL_OFFSET   20
+#define MXC_CCM_PMCR0_DFSUP0_OFFSET 30
+#define MXC_CCM_PMCR0_DFSUP1_OFFSET 31
+
+#endif                         /* __ARCH_ARM_MACH_MX3_CRM_REGS_H__ */
diff --git a/arch/arm/mach-mx3/devices.c b/arch/arm/mach-mx3/devices.c
new file mode 100644 (file)
index 0000000..5c0320f
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/serial.h>
+#include <linux/gpio.h>
+#include <asm/hardware.h>
+#include <asm/arch/imx-uart.h>
+
+static struct resource uart0[] = {
+       {
+               .start = UART1_BASE_ADDR,
+               .end = UART1_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART1,
+               .end = MXC_INT_UART1,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device0 = {
+       .name = "imx-uart",
+       .id = 0,
+       .resource = uart0,
+       .num_resources = ARRAY_SIZE(uart0),
+};
+
+static struct resource uart1[] = {
+       {
+               .start = UART2_BASE_ADDR,
+               .end = UART2_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART2,
+               .end = MXC_INT_UART2,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device1 = {
+       .name = "imx-uart",
+       .id = 1,
+       .resource = uart1,
+       .num_resources = ARRAY_SIZE(uart1),
+};
+
+static struct resource uart2[] = {
+       {
+               .start = UART3_BASE_ADDR,
+               .end = UART3_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART3,
+               .end = MXC_INT_UART3,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device2 = {
+       .name = "imx-uart",
+       .id = 2,
+       .resource = uart2,
+       .num_resources = ARRAY_SIZE(uart2),
+};
+
+static struct resource uart3[] = {
+       {
+               .start = UART4_BASE_ADDR,
+               .end = UART4_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART4,
+               .end = MXC_INT_UART4,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device3 = {
+       .name = "imx-uart",
+       .id = 3,
+       .resource = uart3,
+       .num_resources = ARRAY_SIZE(uart3),
+};
+
+static struct resource uart4[] = {
+       {
+               .start = UART5_BASE_ADDR,
+               .end = UART5_BASE_ADDR + 0x0B5,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MXC_INT_UART5,
+               .end = MXC_INT_UART5,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device mxc_uart_device4 = {
+       .name = "imx-uart",
+       .id = 4,
+       .resource = uart4,
+       .num_resources = ARRAY_SIZE(uart4),
+};
+
+/*
+ * Register only those UARTs that physically exist
+ */
+int __init imx_init_uart(int uart_no, struct imxuart_platform_data *pdata)
+{
+       switch (uart_no) {
+       case 0:
+               mxc_uart_device0.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device0);
+               break;
+       case 1:
+               mxc_uart_device1.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device1);
+               break;
+       case 2:
+               mxc_uart_device2.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device2);
+               break;
+       case 3:
+               mxc_uart_device3.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device3);
+               break;
+       case 4:
+               mxc_uart_device4.dev.platform_data = pdata;
+               platform_device_register(&mxc_uart_device4);
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+/* GPIO port description */
+static struct mxc_gpio_port imx_gpio_ports[] = {
+       [0] = {
+               .chip.label = "gpio-0",
+               .base = IO_ADDRESS(GPIO1_BASE_ADDR),
+               .irq = MXC_INT_GPIO1,
+               .virtual_irq_start = MXC_GPIO_INT_BASE
+       },
+       [1] = {
+               .chip.label = "gpio-1",
+               .base = IO_ADDRESS(GPIO2_BASE_ADDR),
+               .irq = MXC_INT_GPIO2,
+               .virtual_irq_start = MXC_GPIO_INT_BASE + GPIO_NUM_PIN
+       },
+       [2] = {
+               .chip.label = "gpio-2",
+               .base = IO_ADDRESS(GPIO3_BASE_ADDR),
+               .irq = MXC_INT_GPIO3,
+               .virtual_irq_start = MXC_GPIO_INT_BASE + GPIO_NUM_PIN * 2
+       }
+};
+
+int __init mxc_register_gpios(void)
+{
+       return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
+}
diff --git a/arch/arm/mach-mx3/iomux.c b/arch/arm/mach-mx3/iomux.c
new file mode 100644 (file)
index 0000000..adc51fe
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <asm/hardware.h>
+#include <asm/arch/gpio.h>
+#include <asm/arch/iomux-mx3.h>
+
+/*
+ * IOMUX register (base) addresses
+ */
+#define IOMUX_BASE     IO_ADDRESS(IOMUXC_BASE_ADDR)
+#define IOMUXINT_OBS1  (IOMUX_BASE + 0x000)
+#define IOMUXINT_OBS2  (IOMUX_BASE + 0x004)
+#define IOMUXGPR       (IOMUX_BASE + 0x008)
+#define IOMUXSW_MUX_CTL        (IOMUX_BASE + 0x00C)
+#define IOMUXSW_PAD_CTL        (IOMUX_BASE + 0x154)
+
+static DEFINE_SPINLOCK(gpio_mux_lock);
+
+#define IOMUX_REG_MASK (IOMUX_PADNUM_MASK & ~0x3)
+/*
+ * set the mode for a IOMUX pin.
+ */
+int mxc_iomux_mode(unsigned int pin_mode)
+{
+       u32 reg, field, l, mode, ret = 0;
+
+       reg = IOMUXSW_MUX_CTL + (pin_mode & IOMUX_REG_MASK);
+       field = pin_mode & 0x3;
+       mode = (pin_mode & IOMUX_MODE_MASK) >> IOMUX_MODE_SHIFT;
+
+       pr_debug("%s: reg offset = 0x%x field = %d mode = 0x%02x\n",
+                       __func__, (pin_mode & IOMUX_REG_MASK), field, mode);
+
+       spin_lock(&gpio_mux_lock);
+
+       l = __raw_readl(reg);
+       l &= ~(0xff << (field * 8));
+       l |= mode << (field * 8);
+       __raw_writel(l, reg);
+
+       spin_unlock(&gpio_mux_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL(mxc_iomux_mode);
+
+/*
+ * This function configures the pad value for a IOMUX pin.
+ */
+void mxc_iomux_set_pad(enum iomux_pins pin, u32 config)
+{
+       u32 reg, field, l;
+
+       reg = IOMUXSW_PAD_CTL + (pin + 2) / 3;
+       field = (pin + 2) % 3;
+
+       pr_debug("%s: reg offset = 0x%x field = %d\n",
+                       __func__, (pin + 2) / 3, field);
+
+       spin_lock(&gpio_mux_lock);
+
+       l = __raw_readl(reg);
+       l &= ~(0x1ff << (field * 9));
+       l |= config << (field * 9);
+       __raw_writel(l, reg);
+
+       spin_unlock(&gpio_mux_lock);
+}
+EXPORT_SYMBOL(mxc_iomux_set_pad);
+
+/*
+ * This function enables/disables the general purpose function for a particular
+ * signal.
+ */
+void mxc_iomux_set_gpr(enum iomux_gp_func gp, bool en)
+{
+       u32 l;
+
+       spin_lock(&gpio_mux_lock);
+       l = __raw_readl(IOMUXGPR);
+       if (en)
+               l |= gp;
+       else
+               l &= ~gp;
+
+       __raw_writel(l, IOMUXGPR);
+       spin_unlock(&gpio_mux_lock);
+}
+EXPORT_SYMBOL(mxc_iomux_set_gpr);
+
index 7e89bdc..eba3e0c 100644 (file)
 #include <asm/hardware.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
+#include <asm/mach/time.h>
 #include <asm/memory.h>
 #include <asm/mach/map.h>
 #include <asm/arch/common.h>
+#include <asm/arch/board-mx31ads.h>
 
 /*!
  * @file mx31ads.c
@@ -126,6 +128,16 @@ static void __init mxc_board_init(void)
        mxc_init_extuart();
 }
 
+static void __init mx31ads_timer_init(void)
+{
+       mxc_clocks_init(26000000);
+       mxc_timer_init("ipg_clk.0");
+}
+
+struct sys_timer mx31ads_timer = {
+       .init   = mx31ads_timer_init,
+};
+
 /*
  * The following uses standard kernel macros defined in arch.h in order to
  * initialize __mach_desc_MX31ADS data structure.
@@ -138,5 +150,5 @@ MACHINE_START(MX31ADS, "Freescale MX31ADS")
        .map_io         = mx31ads_map_io,
        .init_irq       = mxc_init_irq,
        .init_machine   = mxc_board_init,
-       .timer          = &mxc_timer,
+       .timer          = &mx31ads_timer,
 MACHINE_END
diff --git a/arch/arm/mach-mx3/mx31lite.c b/arch/arm/mach-mx3/mx31lite.c
new file mode 100644 (file)
index 0000000..1372c1a
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *  Copyright (C) 2002 Shane Nay (shane@minirl.com)
+ *  Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/memory.h>
+
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <asm/arch/common.h>
+#include <asm/page.h>
+#include <asm/setup.h>
+#include <asm/arch/board-mx31lite.h>
+
+/*
+ * This file contains the board-specific initialization routines.
+ */
+
+/*
+ * This structure defines the MX31 memory map.
+ */
+static struct map_desc mx31lite_io_desc[] __initdata = {
+       {
+               .virtual = AIPS1_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(AIPS1_BASE_ADDR),
+               .length = AIPS1_SIZE,
+               .type = MT_NONSHARED_DEVICE
+       }, {
+               .virtual = SPBA0_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(SPBA0_BASE_ADDR),
+               .length = SPBA0_SIZE,
+               .type = MT_NONSHARED_DEVICE
+       }, {
+               .virtual = AIPS2_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(AIPS2_BASE_ADDR),
+               .length = AIPS2_SIZE,
+               .type = MT_NONSHARED_DEVICE
+       }, {
+               .virtual = CS4_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(CS4_BASE_ADDR),
+               .length = CS4_SIZE,
+               .type = MT_DEVICE
+       }
+};
+
+/*
+ * Set up static virtual mappings.
+ */
+void __init mx31lite_map_io(void)
+{
+       mxc_map_io();
+       iotable_init(mx31lite_io_desc, ARRAY_SIZE(mx31lite_io_desc));
+}
+
+/*
+ * Board specific initialization.
+ */
+static void __init mxc_board_init(void)
+{
+}
+
+static void __init mx31lite_timer_init(void)
+{
+       mxc_clocks_init(26000000);
+       mxc_timer_init("ipg_clk.0");
+}
+
+struct sys_timer mx31lite_timer = {
+       .init   = mx31lite_timer_init,
+};
+
+/*
+ * The following uses standard kernel macros defined in arch.h in order to
+ * initialize __mach_desc_MX31LITE data structure.
+ */
+
+MACHINE_START(MX31LITE, "LogicPD MX31 LITEKIT")
+       /* Maintainer: Freescale Semiconductor, Inc. */
+       .phys_io        = AIPS1_BASE_ADDR,
+       .io_pg_offst    = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = mx31lite_map_io,
+       .init_irq       = mxc_init_irq,
+       .init_machine   = mxc_board_init,
+       .timer          = &mx31lite_timer,
+MACHINE_END
diff --git a/arch/arm/mach-mx3/pcm037.c b/arch/arm/mach-mx3/pcm037.c
new file mode 100644 (file)
index 0000000..a34ae6d
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ *  Copyright (C) 2008 Sascha Hauer, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/memory.h>
+
+#include <asm/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <asm/arch/common.h>
+#include <asm/arch/imx-uart.h>
+#include <asm/arch/iomux-mx3.h>
+#include <asm/arch/board-pcm037.h>
+
+static struct physmap_flash_data pcm037_flash_data = {
+       .width  = 2,
+};
+
+static struct resource pcm037_flash_resource = {
+       .start  = 0xa0000000,
+       .end    = 0xa1ffffff,
+       .flags  = IORESOURCE_MEM,
+};
+
+static struct platform_device pcm037_flash = {
+       .name   = "physmap-flash",
+       .id     = 0,
+       .dev    = {
+               .platform_data  = &pcm037_flash_data,
+       },
+       .resource = &pcm037_flash_resource,
+       .num_resources = 1,
+};
+
+static struct imxuart_platform_data uart_pdata = {
+       .flags = 0,
+};
+
+static struct platform_device *devices[] __initdata = {
+       &pcm037_flash,
+};
+
+/*
+ * Board specific initialization.
+ */
+static void __init mxc_board_init(void)
+{
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+
+       mxc_iomux_mode(MX31_PIN_CTS1__CTS1);
+       mxc_iomux_mode(MX31_PIN_RTS1__RTS1);
+       mxc_iomux_mode(MX31_PIN_TXD1__TXD1);
+       mxc_iomux_mode(MX31_PIN_RXD1__RXD1);
+
+       imx_init_uart(0, &uart_pdata);
+
+       mxc_iomux_mode(MX31_PIN_CSPI3_MOSI__RXD3);
+       mxc_iomux_mode(MX31_PIN_CSPI3_MISO__TXD3);
+
+       imx_init_uart(2, &uart_pdata);
+}
+
+/*
+ * This structure defines static mappings for the pcm037 board.
+ */
+static struct map_desc pcm037_io_desc[] __initdata = {
+       {
+               .virtual        = AIPS1_BASE_ADDR_VIRT,
+               .pfn            = __phys_to_pfn(AIPS1_BASE_ADDR),
+               .length         = AIPS1_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = AIPS2_BASE_ADDR_VIRT,
+               .pfn            = __phys_to_pfn(AIPS2_BASE_ADDR),
+               .length         = AIPS2_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+/*
+ * Set up static virtual mappings.
+ */
+void __init pcm037_map_io(void)
+{
+       mxc_map_io();
+       iotable_init(pcm037_io_desc, ARRAY_SIZE(pcm037_io_desc));
+}
+
+static void __init pcm037_timer_init(void)
+{
+       mxc_clocks_init(26000000);
+       mxc_timer_init("ipg_clk.0");
+}
+
+struct sys_timer pcm037_timer = {
+       .init   = pcm037_timer_init,
+};
+
+MACHINE_START(PCM037, "Phytec Phycore pcm037")
+       /* Maintainer: Pengutronix */
+       .phys_io        = AIPS1_BASE_ADDR,
+       .io_pg_offst    = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = pcm037_map_io,
+       .init_irq       = mxc_init_irq,
+       .init_machine   = mxc_board_init,
+       .timer          = &pcm037_timer,
+MACHINE_END
+
diff --git a/arch/arm/mach-mx3/time.c b/arch/arm/mach-mx3/time.c
deleted file mode 100644 (file)
index fb565c9..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * System Timer Interrupt reconfigured to run in free-run mode.
- * Author: Vitaly Wool
- * Copyright 2004 MontaVista Software Inc.
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-/*!
- * @file time.c
- * @brief This file contains OS tick and wdog timer implementations.
- *
- * This file contains OS tick and wdog timer implementations.
- *
- * @ingroup Timers
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <asm/hardware.h>
-#include <asm/mach/time.h>
-#include <asm/io.h>
-#include <asm/arch/common.h>
-
-/*!
- * This is the timer interrupt service routine to do required tasks.
- * It also services the WDOG timer at the frequency of twice per WDOG
- * timeout value. For example, if the WDOG's timeout value is 4 (2
- * seconds since the WDOG runs at 0.5Hz), it will be serviced once
- * every 2/2=1 second.
- *
- * @param  irq          GPT interrupt source number (not used)
- * @param  dev_id       this parameter is not used
- * @return always returns \b IRQ_HANDLED as defined in
- *         include/linux/interrupt.h.
- */
-static irqreturn_t mxc_timer_interrupt(int irq, void *dev_id)
-{
-       unsigned int next_match;
-
-       if (__raw_readl(MXC_GPT_GPTSR) & GPTSR_OF1) {
-               do {
-                       timer_tick();
-                       next_match = __raw_readl(MXC_GPT_GPTOCR1) + LATCH;
-                       __raw_writel(GPTSR_OF1, MXC_GPT_GPTSR);
-                       __raw_writel(next_match, MXC_GPT_GPTOCR1);
-               } while ((signed long)(next_match -
-                                      __raw_readl(MXC_GPT_GPTCNT)) <= 0);
-       }
-
-       return IRQ_HANDLED;
-}
-
-/*!
- * This function is used to obtain the number of microseconds since the last
- * timer interrupt. Note that interrupts is disabled by do_gettimeofday().
- *
- * @return the number of microseconds since the last timer interrupt.
- */
-static unsigned long mxc_gettimeoffset(void)
-{
-       unsigned long ticks_to_match, elapsed, usec, tick_usec, i;
-
-       /* Get ticks before next timer match */
-       ticks_to_match =
-           __raw_readl(MXC_GPT_GPTOCR1) - __raw_readl(MXC_GPT_GPTCNT);
-
-       /* We need elapsed ticks since last match */
-       elapsed = LATCH - ticks_to_match;
-
-       /* Now convert them to usec */
-       /* Insure no overflow when calculating the usec below */
-       for (i = 1, tick_usec = tick_nsec / 1000;; i *= 2) {
-               tick_usec /= i;
-               if ((0xFFFFFFFF / tick_usec) > elapsed)
-                       break;
-       }
-       usec = (unsigned long)(elapsed * tick_usec) / (LATCH / i);
-
-       return usec;
-}
-
-/*!
- * The OS tick timer interrupt structure.
- */
-static struct irqaction timer_irq = {
-       .name = "MXC Timer Tick",
-       .flags = IRQF_DISABLED | IRQF_TIMER,
-       .handler = mxc_timer_interrupt
-};
-
-/*!
- * This function is used to initialize the GPT to produce an interrupt
- * based on HZ.  It is called by start_kernel() during system startup.
- */
-void __init mxc_init_time(void)
-{
-       u32 reg, v;
-       reg = __raw_readl(MXC_GPT_GPTCR);
-       reg &= ~GPTCR_ENABLE;
-       __raw_writel(reg, MXC_GPT_GPTCR);
-       reg |= GPTCR_SWR;
-       __raw_writel(reg, MXC_GPT_GPTCR);
-
-       while ((__raw_readl(MXC_GPT_GPTCR) & GPTCR_SWR) != 0)
-               cpu_relax();
-
-       reg = GPTCR_FRR | GPTCR_CLKSRC_HIGHFREQ;
-       __raw_writel(reg, MXC_GPT_GPTCR);
-
-       /* TODO: get timer rate from clk driver */
-       v = 66500000;
-
-       __raw_writel((v / CLOCK_TICK_RATE) - 1, MXC_GPT_GPTPR);
-
-       if ((v % CLOCK_TICK_RATE) != 0) {
-               pr_info("\nWARNING: Can't generate CLOCK_TICK_RATE at %d Hz\n",
-                       CLOCK_TICK_RATE);
-       }
-       pr_info("Actual CLOCK_TICK_RATE is %d Hz\n",
-               v / ((__raw_readl(MXC_GPT_GPTPR) & 0xFFF) + 1));
-
-       reg = __raw_readl(MXC_GPT_GPTCNT);
-       reg += LATCH;
-       __raw_writel(reg, MXC_GPT_GPTOCR1);
-
-       setup_irq(MXC_INT_GPT, &timer_irq);
-
-       reg = __raw_readl(MXC_GPT_GPTCR);
-       reg =
-           GPTCR_FRR | GPTCR_CLKSRC_HIGHFREQ | GPTCR_STOPEN | GPTCR_DOZEN |
-           GPTCR_WAITEN | GPTCR_ENMOD | GPTCR_ENABLE;
-       __raw_writel(reg, MXC_GPT_GPTCR);
-
-       __raw_writel(GPTIR_OF1IE, MXC_GPT_GPTIR);
-}
-
-struct sys_timer mxc_timer = {
-       .init = mxc_init_time,
-       .offset = mxc_gettimeoffset,
-};
index c06f525..1bda8f5 100644 (file)
@@ -3,7 +3,9 @@
 #
 
 # Common support
-obj-y := io.o id.o clock.o irq.o mux.o serial.o devices.o
+obj-y := io.o id.o sram.o clock.o irq.o mux.o serial.o devices.o
+
+obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
 
 obj-$(CONFIG_OMAP_MPU_TIMER)   += time.o
 obj-$(CONFIG_OMAP_32K_TIMER)   += timer32k.o
index bcb984f..3f39e0e 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/clk.h>
@@ -202,7 +203,7 @@ static struct omap_board_config_kernel nokia770_config[] __initdata = {
 #define        AMPLIFIER_CTRL_GPIO     58
 
 static struct clk *dspxor_ck;
-static DECLARE_MUTEX(audio_pwr_sem);
+static DEFINE_MUTEX(audio_pwr_lock);
 /*
  * audio_pwr_state
  * +--+-------------------------+---------------------------------------+
@@ -218,7 +219,7 @@ static DECLARE_MUTEX(audio_pwr_sem);
 static int audio_pwr_state = -1;
 
 /*
- * audio_pwr_up / down should be called under audio_pwr_sem
+ * audio_pwr_up / down should be called under audio_pwr_lock
  */
 static void nokia770_audio_pwr_up(void)
 {
@@ -237,11 +238,11 @@ static void nokia770_audio_pwr_up(void)
 
 static void codec_delayed_power_down(struct work_struct *work)
 {
-       down(&audio_pwr_sem);
+       mutex_lock(&audio_pwr_lock);
        if (audio_pwr_state == -1)
                aic23_power_down();
        clk_disable(dspxor_ck);
-       up(&audio_pwr_sem);
+       mutex_unlock(&audio_pwr_lock);
 }
 
 static DECLARE_DELAYED_WORK(codec_power_down_work, codec_delayed_power_down);
@@ -258,19 +259,19 @@ static void nokia770_audio_pwr_down(void)
 static int
 nokia770_audio_pwr_up_request(struct dsp_kfunc_device *kdev, int stage)
 {
-       down(&audio_pwr_sem);
+       mutex_lock(&audio_pwr_lock);
        if (audio_pwr_state == -1)
                nokia770_audio_pwr_up();
        /* force audio_pwr_state = 0, even if it was 1. */
        audio_pwr_state = 0;
-       up(&audio_pwr_sem);
+       mutex_unlock(&audio_pwr_lock);
        return 0;
 }
 
 static int
 nokia770_audio_pwr_down_request(struct dsp_kfunc_device *kdev, int stage)
 {
-       down(&audio_pwr_sem);
+       mutex_lock(&audio_pwr_lock);
        switch (stage) {
        case 1:
                if (audio_pwr_state == 0)
@@ -283,7 +284,7 @@ nokia770_audio_pwr_down_request(struct dsp_kfunc_device *kdev, int stage)
                }
                break;
        }
-       up(&audio_pwr_sem);
+       mutex_unlock(&audio_pwr_lock);
        return 0;
 }
 
index a66505f..845c663 100644 (file)
@@ -267,13 +267,17 @@ static struct i2c_board_info __initdata osk_i2c_board_info[] = {
 
 static void __init osk_init_smc91x(void)
 {
+       u32 l;
+
        if ((gpio_request(0, "smc_irq")) < 0) {
                printk("Error requesting gpio 0 for smc91x irq\n");
                return;
        }
 
        /* Check EMIFS wait states to fix errors with SMC_GET_PKT_HDR */
-       EMIFS_CCS(1) |= 0x3;
+       l = omap_readl(EMIFS_CCS(1));
+       l |= 0x3;
+       omap_writel(l, EMIFS_CCS(1));
 }
 
 static void __init osk_init_cf(void)
@@ -526,20 +530,26 @@ static void __init osk_mistral_init(void) { }
 
 static void __init osk_init(void)
 {
+       u32 l;
+
        /* Workaround for wrong CS3 (NOR flash) timing
         * There are some U-Boot versions out there which configure
         * wrong CS3 memory timings. This mainly leads to CRC
         * or similar errors if you use NOR flash (e.g. with JFFS2)
         */
-       if (EMIFS_CCS(3) != EMIFS_CS3_VAL)
-               EMIFS_CCS(3) = EMIFS_CS3_VAL;
+       l = omap_readl(EMIFS_CCS(3));
+       if (l != EMIFS_CS3_VAL)
+               omap_writel(EMIFS_CS3_VAL, EMIFS_CCS(3));
 
        osk_flash_resource.end = osk_flash_resource.start = omap_cs3_phys();
        osk_flash_resource.end += SZ_32M - 1;
        platform_add_devices(osk5912_devices, ARRAY_SIZE(osk5912_devices));
        omap_board_config = osk_config;
        omap_board_config_size = ARRAY_SIZE(osk_config);
-       USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
+
+       l = omap_readl(USB_TRANSCEIVER_CTRL);
+       l |= (3 << 1);
+       omap_writel(l, USB_TRANSCEIVER_CTRL);
 
        /* irq for tps65010 chip */
        /* bootloader effectively does:  omap_cfg_reg(U19_1610_MPUIO1); */
index 30e1881..0cf62ef 100644 (file)
@@ -32,7 +32,7 @@
 
 static void fpga_mask_irq(unsigned int irq)
 {
-       irq -= OMAP1510_IH_FPGA_BASE;
+       irq -= OMAP_FPGA_IRQ_BASE;
 
        if (irq < 8)
                __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO)
@@ -65,7 +65,7 @@ static void fpga_ack_irq(unsigned int irq)
 
 static void fpga_unmask_irq(unsigned int irq)
 {
-       irq -= OMAP1510_IH_FPGA_BASE;
+       irq -= OMAP_FPGA_IRQ_BASE;
 
        if (irq < 8)
                __raw_writeb((__raw_readb(OMAP1510_FPGA_IMR_LO) | (1 << irq)),
@@ -95,8 +95,8 @@ void innovator_fpga_IRQ_demux(unsigned int irq, struct irq_desc *desc)
        if (!stat)
                return;
 
-       for (fpga_irq = OMAP1510_IH_FPGA_BASE;
-            (fpga_irq < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS)) && stat;
+       for (fpga_irq = OMAP_FPGA_IRQ_BASE;
+            (fpga_irq < OMAP_FPGA_IRQ_END) && stat;
             fpga_irq++, stat >>= 1) {
                if (stat & 1) {
                        d = irq_desc + fpga_irq;
@@ -151,7 +151,7 @@ void omap1510_fpga_init_irq(void)
        __raw_writeb(0, OMAP1510_FPGA_IMR_HI);
        __raw_writeb(0, INNOVATOR_FPGA_IMR2);
 
-       for (i = OMAP1510_IH_FPGA_BASE; i < (OMAP1510_IH_FPGA_BASE + NR_FPGA_IRQS); i++) {
+       for (i = OMAP_FPGA_IRQ_BASE; i < OMAP_FPGA_IRQ_END; i++) {
 
                if (i == OMAP1510_INT_FPGA_TS) {
                        /*
diff --git a/arch/arm/mach-omap1/mcbsp.c b/arch/arm/mach-omap1/mcbsp.c
new file mode 100644 (file)
index 0000000..2d2c252
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * linux/arch/arm/mach-omap1/mcbsp.c
+ *
+ * Copyright (C) 2008 Instituto Nokia de Tecnologia
+ * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Multichannel mode not supported.
+ */
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+#include <asm/arch/dma.h>
+#include <asm/arch/mux.h>
+#include <asm/arch/cpu.h>
+#include <asm/arch/mcbsp.h>
+#include <asm/arch/dsp_common.h>
+
+#define DPS_RSTCT2_PER_EN      (1 << 0)
+#define DSP_RSTCT2_WD_PER_EN   (1 << 1)
+
+struct mcbsp_internal_clk {
+       struct clk clk;
+       struct clk **childs;
+       int n_childs;
+};
+
+#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
+static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
+{
+       const char *clk_names[] = { "dsp_ck", "api_ck", "dspxor_ck" };
+       int i;
+
+       mclk->n_childs = ARRAY_SIZE(clk_names);
+       mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
+                               GFP_KERNEL);
+
+       for (i = 0; i < mclk->n_childs; i++) {
+               /* We fake a platform device to get correct device id */
+               struct platform_device pdev;
+
+               pdev.dev.bus = &platform_bus_type;
+               pdev.id = mclk->clk.id;
+               mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
+               if (IS_ERR(mclk->childs[i]))
+                       printk(KERN_ERR "Could not get clock %s (%d).\n",
+                               clk_names[i], mclk->clk.id);
+       }
+}
+
+static int omap_mcbsp_clk_enable(struct clk *clk)
+{
+       struct mcbsp_internal_clk *mclk = container_of(clk,
+                                       struct mcbsp_internal_clk, clk);
+       int i;
+
+       for (i = 0; i < mclk->n_childs; i++)
+               clk_enable(mclk->childs[i]);
+       return 0;
+}
+
+static void omap_mcbsp_clk_disable(struct clk *clk)
+{
+       struct mcbsp_internal_clk *mclk = container_of(clk,
+                                       struct mcbsp_internal_clk, clk);
+       int i;
+
+       for (i = 0; i < mclk->n_childs; i++)
+               clk_disable(mclk->childs[i]);
+}
+
+static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
+       {
+               .clk = {
+                       .name           = "mcbsp_clk",
+                       .id             = 1,
+                       .enable         = omap_mcbsp_clk_enable,
+                       .disable        = omap_mcbsp_clk_disable,
+               },
+       },
+       {
+               .clk = {
+                       .name           = "mcbsp_clk",
+                       .id             = 3,
+                       .enable         = omap_mcbsp_clk_enable,
+                       .disable        = omap_mcbsp_clk_disable,
+               },
+       },
+};
+
+#define omap_mcbsp_clks_size   ARRAY_SIZE(omap_mcbsp_clks)
+#else
+#define omap_mcbsp_clks_size   0
+static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
+static inline void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
+{ }
+#endif
+
+static int omap1_mcbsp_check(unsigned int id)
+{
+       /* REVISIT: Check correctly for number of registered McBSPs */
+       if (cpu_is_omap730()) {
+               if (id > OMAP_MAX_MCBSP_COUNT - 2) {
+                      printk(KERN_ERR "OMAP-McBSP: McBSP%d doesn't exist\n",
+                               id + 1);
+                      return -ENODEV;
+               }
+               return 0;
+       }
+
+       if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
+               if (id > OMAP_MAX_MCBSP_COUNT - 1) {
+                       printk(KERN_ERR "OMAP-McBSP: McBSP%d doesn't exist\n",
+                               id + 1);
+                       return -ENODEV;
+               }
+               return 0;
+       }
+
+       return -ENODEV;
+}
+
+static void omap1_mcbsp_request(unsigned int id)
+{
+       /*
+        * On 1510, 1610 and 1710, McBSP1 and McBSP3
+        * are DSP public peripherals.
+        */
+       if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
+               omap_dsp_request_mem();
+               /*
+                * DSP external peripheral reset
+                * FIXME: This should be moved to dsp code
+                */
+               __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
+                               DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
+       }
+}
+
+static void omap1_mcbsp_free(unsigned int id)
+{
+       if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3)
+               omap_dsp_release_mem();
+}
+
+static struct omap_mcbsp_ops omap1_mcbsp_ops = {
+       .check          = omap1_mcbsp_check,
+       .request        = omap1_mcbsp_request,
+       .free           = omap1_mcbsp_free,
+};
+
+#ifdef CONFIG_ARCH_OMAP730
+static struct omap_mcbsp_platform_data omap730_mcbsp_pdata[] = {
+       {
+               .virt_base      = io_p2v(OMAP730_MCBSP1_BASE),
+               .dma_rx_sync    = OMAP_DMA_MCBSP1_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP1_TX,
+               .rx_irq         = INT_730_McBSP1RX,
+               .tx_irq         = INT_730_McBSP1TX,
+               .ops            = &omap1_mcbsp_ops,
+       },
+       {
+               .virt_base      = io_p2v(OMAP730_MCBSP2_BASE),
+               .dma_rx_sync    = OMAP_DMA_MCBSP3_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP3_TX,
+               .rx_irq         = INT_730_McBSP2RX,
+               .tx_irq         = INT_730_McBSP2TX,
+               .ops            = &omap1_mcbsp_ops,
+       },
+};
+#define OMAP730_MCBSP_PDATA_SZ         ARRAY_SIZE(omap730_mcbsp_pdata)
+#else
+#define omap730_mcbsp_pdata            NULL
+#define OMAP730_MCBSP_PDATA_SZ         0
+#endif
+
+#ifdef CONFIG_ARCH_OMAP15XX
+static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
+       {
+               .virt_base      = OMAP1510_MCBSP1_BASE,
+               .dma_rx_sync    = OMAP_DMA_MCBSP1_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP1_TX,
+               .rx_irq         = INT_McBSP1RX,
+               .tx_irq         = INT_McBSP1TX,
+               .ops            = &omap1_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+               },
+       {
+               .virt_base      = io_p2v(OMAP1510_MCBSP2_BASE),
+               .dma_rx_sync    = OMAP_DMA_MCBSP2_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP2_TX,
+               .rx_irq         = INT_1510_SPI_RX,
+               .tx_irq         = INT_1510_SPI_TX,
+               .ops            = &omap1_mcbsp_ops,
+       },
+       {
+               .virt_base      = OMAP1510_MCBSP3_BASE,
+               .dma_rx_sync    = OMAP_DMA_MCBSP3_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP3_TX,
+               .rx_irq         = INT_McBSP3RX,
+               .tx_irq         = INT_McBSP3TX,
+               .ops            = &omap1_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+};
+#define OMAP15XX_MCBSP_PDATA_SZ                ARRAY_SIZE(omap15xx_mcbsp_pdata)
+#else
+#define omap15xx_mcbsp_pdata           NULL
+#define OMAP15XX_MCBSP_PDATA_SZ                0
+#endif
+
+#ifdef CONFIG_ARCH_OMAP16XX
+static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
+       {
+               .virt_base      = OMAP1610_MCBSP1_BASE,
+               .dma_rx_sync    = OMAP_DMA_MCBSP1_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP1_TX,
+               .rx_irq         = INT_McBSP1RX,
+               .tx_irq         = INT_McBSP1TX,
+               .ops            = &omap1_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+       {
+               .virt_base      = io_p2v(OMAP1610_MCBSP2_BASE),
+               .dma_rx_sync    = OMAP_DMA_MCBSP2_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP2_TX,
+               .rx_irq         = INT_1610_McBSP2_RX,
+               .tx_irq         = INT_1610_McBSP2_TX,
+               .ops            = &omap1_mcbsp_ops,
+       },
+       {
+               .virt_base      = OMAP1610_MCBSP3_BASE,
+               .dma_rx_sync    = OMAP_DMA_MCBSP3_RX,
+               .dma_tx_sync    = OMAP_DMA_MCBSP3_TX,
+               .rx_irq         = INT_McBSP3RX,
+               .tx_irq         = INT_McBSP3TX,
+               .ops            = &omap1_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+};
+#define OMAP16XX_MCBSP_PDATA_SZ                ARRAY_SIZE(omap16xx_mcbsp_pdata)
+#else
+#define omap16xx_mcbsp_pdata           NULL
+#define OMAP16XX_MCBSP_PDATA_SZ                0
+#endif
+
+int __init omap1_mcbsp_init(void)
+{
+       int i;
+
+       for (i = 0; i < omap_mcbsp_clks_size; i++) {
+               if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
+                       omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
+                       clk_register(&omap_mcbsp_clks[i].clk);
+               }
+       }
+
+       if (cpu_is_omap730())
+               omap_mcbsp_register_board_cfg(omap730_mcbsp_pdata,
+                                               OMAP730_MCBSP_PDATA_SZ);
+
+       if (cpu_is_omap15xx())
+               omap_mcbsp_register_board_cfg(omap15xx_mcbsp_pdata,
+                                               OMAP15XX_MCBSP_PDATA_SZ);
+
+       if (cpu_is_omap16xx())
+               omap_mcbsp_register_board_cfg(omap16xx_mcbsp_pdata,
+                                               OMAP16XX_MCBSP_PDATA_SZ);
+
+       return omap_mcbsp_init();
+}
+
+arch_initcall(omap1_mcbsp_init);
index e6c64e1..742f79e 100644 (file)
@@ -116,13 +116,6 @@ void omap_pm_idle(void)
                return;
        }
 
-       /*
-        * Since an interrupt may set up a timer, we don't want to
-        * reprogram the hardware timer with interrupts enabled.
-        * Re-enable interrupts only after returning from idle.
-        */
-       timer_dyn_reprogram();
-
 #ifdef CONFIG_OMAP_MPU_TIMER
 #warning Enable 32kHz OS timer in order to allow sleep states in idle
        use_idlect1 = use_idlect1 & ~(1 << 9);
diff --git a/arch/arm/mach-omap1/sram.S b/arch/arm/mach-omap1/sram.S
new file mode 100644 (file)
index 0000000..126d252
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * linux/arch/arm/plat-omap/sram-fn.S
+ *
+ * Functions that need to be run in internal SRAM
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/arch/io.h>
+#include <asm/hardware.h>
+
+       .text
+
+/*
+ * Reprograms ULPD and CKCTL.
+ */
+ENTRY(omap1_sram_reprogram_clock)
+       stmfd   sp!, {r0 - r12, lr}             @ save registers on stack
+
+       mov     r2, #IO_ADDRESS(DPLL_CTL) & 0xff000000
+       orr     r2, r2, #IO_ADDRESS(DPLL_CTL) & 0x00ff0000
+       orr     r2, r2, #IO_ADDRESS(DPLL_CTL) & 0x0000ff00
+
+       mov     r3, #IO_ADDRESS(ARM_CKCTL) & 0xff000000
+       orr     r3, r3, #IO_ADDRESS(ARM_CKCTL) & 0x00ff0000
+       orr     r3, r3, #IO_ADDRESS(ARM_CKCTL) & 0x0000ff00
+
+       tst     r0, #1 << 4                     @ want lock mode?
+       beq     newck                           @ nope
+       bic     r0, r0, #1 << 4                 @ else clear lock bit
+       strh    r0, [r2]                        @ set dpll into bypass mode
+       orr     r0, r0, #1 << 4                 @ set lock bit again
+
+newck:
+       strh    r1, [r3]                        @ write new ckctl value
+       strh    r0, [r2]                        @ write new dpll value
+
+       mov     r4, #0x0700                     @ let the clocks settle
+       orr     r4, r4, #0x00ff
+delay: sub     r4, r4, #1
+       cmp     r4, #0
+       bne     delay
+
+lock:  ldrh    r4, [r2], #0                    @ read back dpll value
+       tst     r0, #1 << 4                     @ want lock mode?
+       beq     out                             @ nope
+       tst     r4, #1 << 0                     @ dpll rate locked?
+       beq     lock                            @ try again
+
+out:
+       ldmfd   sp!, {r0 - r12, pc}             @ restore regs and return
+ENTRY(omap1_sram_reprogram_clock_sz)
+       .word   . - omap1_sram_reprogram_clock
index 2feb687..93ee990 100644 (file)
@@ -3,9 +3,15 @@
 #
 
 # Common support
-obj-y := irq.o id.o io.o sram-fn.o memory.o control.o prcm.o clock.o mux.o \
+obj-y := irq.o id.o io.o memory.o control.o prcm.o clock.o mux.o \
                devices.o serial.o gpmc.o timer-gp.o
 
+obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
+
+# Functions loaded to SRAM
+obj-$(CONFIG_ARCH_OMAP2420)            += sram242x.o
+obj-$(CONFIG_ARCH_OMAP2430)            += sram243x.o
+
 # Power Management
 obj-$(CONFIG_PM) += pm.o sleep.o
 
index ab9fc57..15675bc 100644 (file)
 
 #define MAX_CLOCK_ENABLE_WAIT          100000
 
+/* DPLL rate rounding: minimum DPLL multiplier, divider values */
+#define DPLL_MIN_MULTIPLIER            1
+#define DPLL_MIN_DIVIDER               1
+
+/* Possible error results from _dpll_test_mult */
+#define DPLL_MULT_UNDERFLOW            (1 << 0)
+
+/*
+ * Scale factor to mitigate roundoff errors in DPLL rate rounding.
+ * The higher the scale factor, the greater the risk of arithmetic overflow,
+ * but the closer the rounded rate to the target rate.  DPLL_SCALE_FACTOR
+ * must be a power of DPLL_SCALE_BASE.
+ */
+#define DPLL_SCALE_FACTOR              64
+#define DPLL_SCALE_BASE                        2
+#define DPLL_ROUNDING_VAL              ((DPLL_SCALE_BASE / 2) * \
+                                        (DPLL_SCALE_FACTOR / DPLL_SCALE_BASE))
+
 u8 cpu_mask;
 
 /*-------------------------------------------------------------------------
@@ -95,7 +113,7 @@ u32 omap2_get_dpll_rate(struct clk *clk)
 {
        long long dpll_clk;
        u32 dpll_mult, dpll_div, dpll;
-       const struct dpll_data *dd;
+       struct dpll_data *dd;
 
        dd = clk->dpll_data;
        /* REVISIT: What do we return on error? */
@@ -603,7 +621,8 @@ int omap2_clksel_set_rate(struct clk *clk, unsigned long rate)
        clk->rate = clk->parent->rate / new_div;
 
        if (clk->flags & DELAYED_APP && cpu_is_omap24xx()) {
-               __raw_writel(OMAP24XX_VALID_CONFIG, OMAP24XX_PRCM_CLKCFG_CTRL);
+               prm_write_mod_reg(OMAP24XX_VALID_CONFIG,
+                       OMAP24XX_GR_MOD, OMAP24XX_PRCM_CLKCFG_CTRL_OFFSET);
                wmb();
        }
 
@@ -723,6 +742,184 @@ int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent)
        return 0;
 }
 
+/* DPLL rate rounding code */
+
+/**
+ * omap2_dpll_set_rate_tolerance: set the error tolerance during rate rounding
+ * @clk: struct clk * of the DPLL
+ * @tolerance: maximum rate error tolerance
+ *
+ * Set the maximum DPLL rate error tolerance for the rate rounding
+ * algorithm.  The rate tolerance is an attempt to balance DPLL power
+ * saving (the least divider value "n") vs. rate fidelity (the least
+ * difference between the desired DPLL target rate and the rounded
+ * rate out of the algorithm).  So, increasing the tolerance is likely
+ * to decrease DPLL power consumption and increase DPLL rate error.
+ * Returns -EINVAL if provided a null clock ptr or a clk that is not a
+ * DPLL; or 0 upon success.
+ */
+int omap2_dpll_set_rate_tolerance(struct clk *clk, unsigned int tolerance)
+{
+       if (!clk || !clk->dpll_data)
+               return -EINVAL;
+
+       clk->dpll_data->rate_tolerance = tolerance;
+
+       return 0;
+}
+
+static unsigned long _dpll_compute_new_rate(unsigned long parent_rate, unsigned int m, unsigned int n)
+{
+       unsigned long long num;
+
+       num = (unsigned long long)parent_rate * m;
+       do_div(num, n);
+       return num;
+}
+
+/*
+ * _dpll_test_mult - test a DPLL multiplier value
+ * @m: pointer to the DPLL m (multiplier) value under test
+ * @n: current DPLL n (divider) value under test
+ * @new_rate: pointer to storage for the resulting rounded rate
+ * @target_rate: the desired DPLL rate
+ * @parent_rate: the DPLL's parent clock rate
+ *
+ * This code tests a DPLL multiplier value, ensuring that the
+ * resulting rate will not be higher than the target_rate, and that
+ * the multiplier value itself is valid for the DPLL.  Initially, the
+ * integer pointed to by the m argument should be prescaled by
+ * multiplying by DPLL_SCALE_FACTOR.  The code will replace this with
+ * a non-scaled m upon return.  This non-scaled m will result in a
+ * new_rate as close as possible to target_rate (but not greater than
+ * target_rate) given the current (parent_rate, n, prescaled m)
+ * triple. Returns DPLL_MULT_UNDERFLOW in the event that the
+ * non-scaled m attempted to underflow, which can allow the calling
+ * function to bail out early; or 0 upon success.
+ */
+static int _dpll_test_mult(int *m, int n, unsigned long *new_rate,
+                          unsigned long target_rate,
+                          unsigned long parent_rate)
+{
+       int flags = 0, carry = 0;
+
+       /* Unscale m and round if necessary */
+       if (*m % DPLL_SCALE_FACTOR >= DPLL_ROUNDING_VAL)
+               carry = 1;
+       *m = (*m / DPLL_SCALE_FACTOR) + carry;
+
+       /*
+        * The new rate must be <= the target rate to avoid programming
+        * a rate that is impossible for the hardware to handle
+        */
+       *new_rate = _dpll_compute_new_rate(parent_rate, *m, n);
+       if (*new_rate > target_rate) {
+               (*m)--;
+               *new_rate = 0;
+       }
+
+       /* Guard against m underflow */
+       if (*m < DPLL_MIN_MULTIPLIER) {
+               *m = DPLL_MIN_MULTIPLIER;
+               *new_rate = 0;
+               flags = DPLL_MULT_UNDERFLOW;
+       }
+
+       if (*new_rate == 0)
+               *new_rate = _dpll_compute_new_rate(parent_rate, *m, n);
+
+       return flags;
+}
+
+/**
+ * omap2_dpll_round_rate - round a target rate for an OMAP DPLL
+ * @clk: struct clk * for a DPLL
+ * @target_rate: desired DPLL clock rate
+ *
+ * Given a DPLL, a desired target rate, and a rate tolerance, round
+ * the target rate to a possible, programmable rate for this DPLL.
+ * Rate tolerance is assumed to be set by the caller before this
+ * function is called.  Attempts to select the minimum possible n
+ * within the tolerance to reduce power consumption.  Stores the
+ * computed (m, n) in the DPLL's dpll_data structure so set_rate()
+ * will not need to call this (expensive) function again.  Returns ~0
+ * if the target rate cannot be rounded, either because the rate is
+ * too low or because the rate tolerance is set too tightly; or the
+ * rounded rate upon success.
+ */
+long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate)
+{
+       int m, n, r, e, scaled_max_m;
+       unsigned long scaled_rt_rp, new_rate;
+       int min_e = -1, min_e_m = -1, min_e_n = -1;
+
+       if (!clk || !clk->dpll_data)
+               return ~0;
+
+       pr_debug("clock: starting DPLL round_rate for clock %s, target rate "
+                "%ld\n", clk->name, target_rate);
+
+       scaled_rt_rp = target_rate / (clk->parent->rate / DPLL_SCALE_FACTOR);
+       scaled_max_m = clk->dpll_data->max_multiplier * DPLL_SCALE_FACTOR;
+
+       clk->dpll_data->last_rounded_rate = 0;
+
+       for (n = clk->dpll_data->max_divider; n >= DPLL_MIN_DIVIDER; n--) {
+
+               /* Compute the scaled DPLL multiplier, based on the divider */
+               m = scaled_rt_rp * n;
+
+               /*
+                * Since we're counting n down, a m overflow means we can
+                * can immediately skip to the next n
+                */
+               if (m > scaled_max_m)
+                       continue;
+
+               r = _dpll_test_mult(&m, n, &new_rate, target_rate,
+                                   clk->parent->rate);
+
+               e = target_rate - new_rate;
+               pr_debug("clock: n = %d: m = %d: rate error is %d "
+                        "(new_rate = %ld)\n", n, m, e, new_rate);
+
+               if (min_e == -1 ||
+                   min_e >= (int)(abs(e) - clk->dpll_data->rate_tolerance)) {
+                       min_e = e;
+                       min_e_m = m;
+                       min_e_n = n;
+
+                       pr_debug("clock: found new least error %d\n", min_e);
+               }
+
+               /*
+                * Since we're counting n down, a m underflow means we
+                * can bail out completely (since as n decreases in
+                * the next iteration, there's no way that m can
+                * increase beyond the current m)
+                */
+               if (r & DPLL_MULT_UNDERFLOW)
+                       break;
+       }
+
+       if (min_e < 0) {
+               pr_debug("clock: error: target rate or tolerance too low\n");
+               return ~0;
+       }
+
+       clk->dpll_data->last_rounded_m = min_e_m;
+       clk->dpll_data->last_rounded_n = min_e_n;
+       clk->dpll_data->last_rounded_rate =
+               _dpll_compute_new_rate(clk->parent->rate, min_e_m,  min_e_n);
+
+       pr_debug("clock: final least error: e = %d, m = %d, n = %d\n",
+                min_e, min_e_m, min_e_n);
+       pr_debug("clock: final rate: %ld  (target rate: %ld)\n",
+                clk->dpll_data->last_rounded_rate, target_rate);
+
+       return clk->dpll_data->last_rounded_rate;
+}
+
 /*-------------------------------------------------------------------------
  * Omap2 clock reset and init functions
  *-------------------------------------------------------------------------*/
index d5980a9..3cd37cb 100644 (file)
 
 #include <asm/arch/clock.h>
 
+/* The maximum error between a target DPLL rate and the rounded rate in Hz */
+#define DEFAULT_DPLL_RATE_TOLERANCE    50000
+
 int omap2_clk_enable(struct clk *clk);
 void omap2_clk_disable(struct clk *clk);
 long omap2_clk_round_rate(struct clk *clk, unsigned long rate);
 int omap2_clk_set_rate(struct clk *clk, unsigned long rate);
 int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent);
+int omap2_dpll_rate_tolerance_set(struct clk *clk, unsigned int tolerance);
+long omap2_dpll_round_rate(struct clk *clk, unsigned long target_rate);
 
 #ifdef CONFIG_OMAP_RESET_CLOCKS
 void omap2_clk_disable_unused(struct clk *clk);
@@ -42,6 +47,7 @@ long omap2_clksel_round_rate(struct clk *clk, unsigned long target_rate);
 int omap2_clksel_set_rate(struct clk *clk, unsigned long rate);
 u32 omap2_get_dpll_rate(struct clk *clk);
 int omap2_wait_clock_ready(void __iomem *reg, u32 cval, const char *name);
+void omap2_clk_prepare_for_reboot(void);
 
 extern u8 cpu_mask;
 
index ece32d8..aa56787 100644 (file)
@@ -154,7 +154,7 @@ static void omap2_clk_fixed_disable(struct clk *clk)
  * Uses the current prcm set to tell if a rate is valid.
  * You can go slower, but not faster within a given rate set.
  */
-static u32 omap2_dpll_round_rate(unsigned long target_rate)
+long omap2_dpllcore_round_rate(unsigned long target_rate)
 {
        u32 high, low, core_clk_src;
 
@@ -183,14 +183,14 @@ static u32 omap2_dpll_round_rate(unsigned long target_rate)
 
 }
 
-static void omap2_dpll_recalc(struct clk *clk)
+static void omap2_dpllcore_recalc(struct clk *clk)
 {
        clk->rate = omap2_get_dpll_rate_24xx(clk);
 
        propagate_rate(clk);
 }
 
-static int omap2_reprogram_dpll(struct clk *clk, unsigned long rate)
+static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate)
 {
        u32 cur_rate, low, mult, div, valid_rate, done_rate;
        u32 bypass = 0;
@@ -209,7 +209,7 @@ static int omap2_reprogram_dpll(struct clk *clk, unsigned long rate)
        } else if ((rate == (cur_rate * 2)) && (mult == 1)) {
                omap2_reprogram_sdrc(CORE_CLK_SRC_DPLL_X2, 1);
        } else if (rate != cur_rate) {
-               valid_rate = omap2_dpll_round_rate(rate);
+               valid_rate = omap2_dpllcore_round_rate(rate);
                if (valid_rate != rate)
                        goto dpll_exit;
 
@@ -256,7 +256,7 @@ static int omap2_reprogram_dpll(struct clk *clk, unsigned long rate)
                omap2_init_memory_params(omap2_dll_force_needed());
                omap2_reprogram_sdrc(done_rate, 0);
        }
-       omap2_dpll_recalc(&dpll_ck);
+       omap2_dpllcore_recalc(&dpll_ck);
        ret = 0;
 
 dpll_exit:
@@ -383,7 +383,7 @@ static int omap2_select_table_rate(struct clk *clk, unsigned long rate)
 
                local_irq_restore(flags);
        }
-       omap2_dpll_recalc(&dpll_ck);
+       omap2_dpllcore_recalc(&dpll_ck);
 
        return 0;
 }
index 88081ed..be4e255 100644 (file)
@@ -30,12 +30,12 @@ static long omap2_round_to_table_rate(struct clk *clk, unsigned long rate);
 static void omap2_sys_clk_recalc(struct clk *clk);
 static void omap2_osc_clk_recalc(struct clk *clk);
 static void omap2_sys_clk_recalc(struct clk *clk);
-static void omap2_dpll_recalc(struct clk *clk);
+static void omap2_dpllcore_recalc(struct clk *clk);
 static int omap2_clk_fixed_enable(struct clk *clk);
 static void omap2_clk_fixed_disable(struct clk *clk);
 static int omap2_enable_osc_ck(struct clk *clk);
 static void omap2_disable_osc_ck(struct clk *clk);
-static int omap2_reprogram_dpll(struct clk *clk, unsigned long rate);
+static int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate);
 
 /* Key dividers which make up a PRCM set. Ratio's for a PRCM are mandated.
  * xtal_speed, dpll_speed, mpu_speed, CM_CLKSEL_MPU,CM_CLKSEL_DSP
@@ -665,20 +665,27 @@ static struct clk alt_ck = {              /* Typical 54M or 48M, may not exist */
  * deal with this
  */
 
-static const struct dpll_data dpll_dd = {
+static struct dpll_data dpll_dd = {
        .mult_div1_reg          = OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL1),
        .mult_mask              = OMAP24XX_DPLL_MULT_MASK,
        .div1_mask              = OMAP24XX_DPLL_DIV_MASK,
+       .max_multiplier         = 1024,
+       .max_divider            = 16,
+       .rate_tolerance         = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
+/*
+ * XXX Cannot add round_rate here yet, as this is still a composite clock,
+ * not just a DPLL
+ */
 static struct clk dpll_ck = {
        .name           = "dpll_ck",
        .parent         = &sys_ck,              /* Can be func_32k also */
        .dpll_data      = &dpll_dd,
        .flags          = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X |
                                RATE_PROPAGATES | ALWAYS_ENABLED,
-       .recalc         = &omap2_dpll_recalc,
-       .set_rate       = &omap2_reprogram_dpll,
+       .recalc         = &omap2_dpllcore_recalc,
+       .set_rate       = &omap2_reprogram_dpllcore,
 };
 
 static struct clk apll96_ck = {
@@ -1747,7 +1754,8 @@ static struct clk gpt12_fck = {
 };
 
 static struct clk mcbsp1_ick = {
-       .name           = "mcbsp1_ick",
+       .name           = "mcbsp_ick",
+       .id             = 1,
        .parent         = &l4_ck,
        .flags          = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
@@ -1756,7 +1764,8 @@ static struct clk mcbsp1_ick = {
 };
 
 static struct clk mcbsp1_fck = {
-       .name           = "mcbsp1_fck",
+       .name           = "mcbsp_fck",
+       .id             = 1,
        .parent         = &func_96m_ck,
        .flags          = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
@@ -1765,7 +1774,8 @@ static struct clk mcbsp1_fck = {
 };
 
 static struct clk mcbsp2_ick = {
-       .name           = "mcbsp2_ick",
+       .name           = "mcbsp_ick",
+       .id             = 2,
        .parent         = &l4_ck,
        .flags          = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
@@ -1774,7 +1784,8 @@ static struct clk mcbsp2_ick = {
 };
 
 static struct clk mcbsp2_fck = {
-       .name           = "mcbsp2_fck",
+       .name           = "mcbsp_fck",
+       .id             = 2,
        .parent         = &func_96m_ck,
        .flags          = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
@@ -1783,7 +1794,8 @@ static struct clk mcbsp2_fck = {
 };
 
 static struct clk mcbsp3_ick = {
-       .name           = "mcbsp3_ick",
+       .name           = "mcbsp_ick",
+       .id             = 3,
        .parent         = &l4_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN2),
@@ -1792,7 +1804,8 @@ static struct clk mcbsp3_ick = {
 };
 
 static struct clk mcbsp3_fck = {
-       .name           = "mcbsp3_fck",
+       .name           = "mcbsp_fck",
+       .id             = 3,
        .parent         = &func_96m_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, OMAP24XX_CM_FCLKEN2),
@@ -1801,7 +1814,8 @@ static struct clk mcbsp3_fck = {
 };
 
 static struct clk mcbsp4_ick = {
-       .name           = "mcbsp4_ick",
+       .name           = "mcbsp_ick",
+       .id             = 4,
        .parent         = &l4_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN2),
@@ -1810,7 +1824,8 @@ static struct clk mcbsp4_ick = {
 };
 
 static struct clk mcbsp4_fck = {
-       .name           = "mcbsp4_fck",
+       .name           = "mcbsp_fck",
+       .id             = 4,
        .parent         = &func_96m_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, OMAP24XX_CM_FCLKEN2),
@@ -1819,7 +1834,8 @@ static struct clk mcbsp4_fck = {
 };
 
 static struct clk mcbsp5_ick = {
-       .name           = "mcbsp5_ick",
+       .name           = "mcbsp_ick",
+       .id             = 5,
        .parent         = &l4_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN2),
@@ -1828,7 +1844,8 @@ static struct clk mcbsp5_ick = {
 };
 
 static struct clk mcbsp5_fck = {
-       .name           = "mcbsp5_fck",
+       .name           = "mcbsp_fck",
+       .id             = 5,
        .parent         = &func_96m_ck,
        .flags          = CLOCK_IN_OMAP243X,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, OMAP24XX_CM_FCLKEN2),
index b42bdd6..4263099 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * OMAP3-specific clock framework functions
  *
- * Copyright (C) 2007 Texas Instruments, Inc.
- * Copyright (C) 2007 Nokia Corporation
+ * Copyright (C) 2007-2008 Texas Instruments, Inc.
+ * Copyright (C) 2007-2008 Nokia Corporation
  *
  * Written by Paul Walmsley
+ * Testing and integration fixes by Jouni Högander
  *
  * Parts of this code are based on code written by
  * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
@@ -23,6 +24,7 @@
 #include <linux/delay.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/limits.h>
 
 #include <asm/arch/clock.h>
 #include <asm/arch/sram.h>
 #include "cm.h"
 #include "cm-regbits-34xx.h"
 
-/* CM_CLKEN_PLL*.EN* bit values */
-#define DPLL_LOCKED            0x7
+/* CM_AUTOIDLE_PLL*.AUTO_* bit values */
+#define DPLL_AUTOIDLE_DISABLE                  0x0
+#define DPLL_AUTOIDLE_LOW_POWER_STOP           0x1
+
+#define MAX_DPLL_WAIT_TRIES            1000000
 
 /**
  * omap3_dpll_recalc - recalculate DPLL rate
@@ -53,6 +58,290 @@ static void omap3_dpll_recalc(struct clk *clk)
        propagate_rate(clk);
 }
 
+/* _omap3_dpll_write_clken - write clken_bits arg to a DPLL's enable bits */
+static void _omap3_dpll_write_clken(struct clk *clk, u8 clken_bits)
+{
+       const struct dpll_data *dd;
+
+       dd = clk->dpll_data;
+
+       cm_rmw_reg_bits(dd->enable_mask, clken_bits << __ffs(dd->enable_mask),
+                       dd->control_reg);
+}
+
+/* _omap3_wait_dpll_status: wait for a DPLL to enter a specific state */
+static int _omap3_wait_dpll_status(struct clk *clk, u8 state)
+{
+       const struct dpll_data *dd;
+       int i = 0;
+       int ret = -EINVAL;
+       u32 idlest_mask;
+
+       dd = clk->dpll_data;
+
+       state <<= dd->idlest_bit;
+       idlest_mask = 1 << dd->idlest_bit;
+
+       while (((cm_read_reg(dd->idlest_reg) & idlest_mask) != state) &&
+              i < MAX_DPLL_WAIT_TRIES) {
+               i++;
+               udelay(1);
+       }
+
+       if (i == MAX_DPLL_WAIT_TRIES) {
+               printk(KERN_ERR "clock: %s failed transition to '%s'\n",
+                      clk->name, (state) ? "locked" : "bypassed");
+       } else {
+               pr_debug("clock: %s transition to '%s' in %d loops\n",
+                        clk->name, (state) ? "locked" : "bypassed", i);
+
+               ret = 0;
+       }
+
+       return ret;
+}
+
+/* Non-CORE DPLL (e.g., DPLLs that do not control SDRC) clock functions */
+
+/*
+ * _omap3_noncore_dpll_lock - instruct a DPLL to lock and wait for readiness
+ * @clk: pointer to a DPLL struct clk
+ *
+ * Instructs a non-CORE DPLL to lock.  Waits for the DPLL to report
+ * readiness before returning.  Will save and restore the DPLL's
+ * autoidle state across the enable, per the CDP code.  If the DPLL
+ * locked successfully, return 0; if the DPLL did not lock in the time
+ * allotted, or DPLL3 was passed in, return -EINVAL.
+ */
+static int _omap3_noncore_dpll_lock(struct clk *clk)
+{
+       u8 ai;
+       int r;
+
+       if (clk == &dpll3_ck)
+               return -EINVAL;
+
+       pr_debug("clock: locking DPLL %s\n", clk->name);
+
+       ai = omap3_dpll_autoidle_read(clk);
+
+       _omap3_dpll_write_clken(clk, DPLL_LOCKED);
+
+       if (ai) {
+               /*
+                * If no downstream clocks are enabled, CM_IDLEST bit
+                * may never become active, so don't wait for DPLL to lock.
+                */
+               r = 0;
+               omap3_dpll_allow_idle(clk);
+       } else {
+               r = _omap3_wait_dpll_status(clk, 1);
+               omap3_dpll_deny_idle(clk);
+       };
+
+       return r;
+}
+
+/*
+ * omap3_noncore_dpll_bypass - instruct a DPLL to bypass and wait for readiness
+ * @clk: pointer to a DPLL struct clk
+ *
+ * Instructs a non-CORE DPLL to enter low-power bypass mode.  In
+ * bypass mode, the DPLL's rate is set equal to its parent clock's
+ * rate.  Waits for the DPLL to report readiness before returning.
+ * Will save and restore the DPLL's autoidle state across the enable,
+ * per the CDP code.  If the DPLL entered bypass mode successfully,
+ * return 0; if the DPLL did not enter bypass in the time allotted, or
+ * DPLL3 was passed in, or the DPLL does not support low-power bypass,
+ * return -EINVAL.
+ */
+static int _omap3_noncore_dpll_bypass(struct clk *clk)
+{
+       int r;
+       u8 ai;
+
+       if (clk == &dpll3_ck)
+               return -EINVAL;
+
+       if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_BYPASS)))
+               return -EINVAL;
+
+       pr_debug("clock: configuring DPLL %s for low-power bypass\n",
+                clk->name);
+
+       ai = omap3_dpll_autoidle_read(clk);
+
+       _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_BYPASS);
+
+       r = _omap3_wait_dpll_status(clk, 0);
+
+       if (ai)
+               omap3_dpll_allow_idle(clk);
+       else
+               omap3_dpll_deny_idle(clk);
+
+       return r;
+}
+
+/*
+ * _omap3_noncore_dpll_stop - instruct a DPLL to stop
+ * @clk: pointer to a DPLL struct clk
+ *
+ * Instructs a non-CORE DPLL to enter low-power stop. Will save and
+ * restore the DPLL's autoidle state across the stop, per the CDP
+ * code.  If DPLL3 was passed in, or the DPLL does not support
+ * low-power stop, return -EINVAL; otherwise, return 0.
+ */
+static int _omap3_noncore_dpll_stop(struct clk *clk)
+{
+       u8 ai;
+
+       if (clk == &dpll3_ck)
+               return -EINVAL;
+
+       if (!(clk->dpll_data->modes & (1 << DPLL_LOW_POWER_STOP)))
+               return -EINVAL;
+
+       pr_debug("clock: stopping DPLL %s\n", clk->name);
+
+       ai = omap3_dpll_autoidle_read(clk);
+
+       _omap3_dpll_write_clken(clk, DPLL_LOW_POWER_STOP);
+
+       if (ai)
+               omap3_dpll_allow_idle(clk);
+       else
+               omap3_dpll_deny_idle(clk);
+
+       return 0;
+}
+
+/**
+ * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
+ * @clk: pointer to a DPLL struct clk
+ *
+ * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
+ * The choice of modes depends on the DPLL's programmed rate: if it is
+ * the same as the DPLL's parent clock, it will enter bypass;
+ * otherwise, it will enter lock.  This code will wait for the DPLL to
+ * indicate readiness before returning, unless the DPLL takes too long
+ * to enter the target state.  Intended to be used as the struct clk's
+ * enable function.  If DPLL3 was passed in, or the DPLL does not
+ * support low-power stop, or if the DPLL took too long to enter
+ * bypass or lock, return -EINVAL; otherwise, return 0.
+ */
+static int omap3_noncore_dpll_enable(struct clk *clk)
+{
+       int r;
+
+       if (clk == &dpll3_ck)
+               return -EINVAL;
+
+       if (clk->parent->rate == clk_get_rate(clk))
+               r = _omap3_noncore_dpll_bypass(clk);
+       else
+               r = _omap3_noncore_dpll_lock(clk);
+
+       return r;
+}
+
+/**
+ * omap3_noncore_dpll_enable - instruct a DPLL to enter bypass or lock mode
+ * @clk: pointer to a DPLL struct clk
+ *
+ * Instructs a non-CORE DPLL to enable, e.g., to enter bypass or lock.
+ * The choice of modes depends on the DPLL's programmed rate: if it is
+ * the same as the DPLL's parent clock, it will enter bypass;
+ * otherwise, it will enter lock.  This code will wait for the DPLL to
+ * indicate readiness before returning, unless the DPLL takes too long
+ * to enter the target state.  Intended to be used as the struct clk's
+ * enable function.  If DPLL3 was passed in, or the DPLL does not
+ * support low-power stop, or if the DPLL took too long to enter
+ * bypass or lock, return -EINVAL; otherwise, return 0.
+ */
+static void omap3_noncore_dpll_disable(struct clk *clk)
+{
+       if (clk == &dpll3_ck)
+               return;
+
+       _omap3_noncore_dpll_stop(clk);
+}
+
+/**
+ * omap3_dpll_autoidle_read - read a DPLL's autoidle bits
+ * @clk: struct clk * of the DPLL to read
+ *
+ * Return the DPLL's autoidle bits, shifted down to bit 0.  Returns
+ * -EINVAL if passed a null pointer or if the struct clk does not
+ * appear to refer to a DPLL.
+ */
+static u32 omap3_dpll_autoidle_read(struct clk *clk)
+{
+       const struct dpll_data *dd;
+       u32 v;
+
+       if (!clk || !clk->dpll_data)
+               return -EINVAL;
+
+       dd = clk->dpll_data;
+
+       v = cm_read_reg(dd->autoidle_reg);
+       v &= dd->autoidle_mask;
+       v >>= __ffs(dd->autoidle_mask);
+
+       return v;
+}
+
+/**
+ * omap3_dpll_allow_idle - enable DPLL autoidle bits
+ * @clk: struct clk * of the DPLL to operate on
+ *
+ * Enable DPLL automatic idle control.  This automatic idle mode
+ * switching takes effect only when the DPLL is locked, at least on
+ * OMAP3430.  The DPLL will enter low-power stop when its downstream
+ * clocks are gated.  No return value.
+ */
+static void omap3_dpll_allow_idle(struct clk *clk)
+{
+       const struct dpll_data *dd;
+
+       if (!clk || !clk->dpll_data)
+               return;
+
+       dd = clk->dpll_data;
+
+       /*
+        * REVISIT: CORE DPLL can optionally enter low-power bypass
+        * by writing 0x5 instead of 0x1.  Add some mechanism to
+        * optionally enter this mode.
+        */
+       cm_rmw_reg_bits(dd->autoidle_mask,
+                       DPLL_AUTOIDLE_LOW_POWER_STOP << __ffs(dd->autoidle_mask),
+                       dd->autoidle_reg);
+}
+
+/**
+ * omap3_dpll_deny_idle - prevent DPLL from automatically idling
+ * @clk: struct clk * of the DPLL to operate on
+ *
+ * Disable DPLL automatic idle control.  No return value.
+ */
+static void omap3_dpll_deny_idle(struct clk *clk)
+{
+       const struct dpll_data *dd;
+
+       if (!clk || !clk->dpll_data)
+               return;
+
+       dd = clk->dpll_data;
+
+       cm_rmw_reg_bits(dd->autoidle_mask,
+                       DPLL_AUTOIDLE_DISABLE << __ffs(dd->autoidle_mask),
+                       dd->autoidle_reg);
+}
+
+/* Clock control for DPLL outputs */
+
 /**
  * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
  * @clk: DPLL output struct clk
@@ -89,6 +378,8 @@ static void omap3_clkoutx2_recalc(struct clk *clk)
                propagate_rate(clk);
 }
 
+/* Common clock code */
+
 /*
  * As it is structured now, this will prevent an OMAP2/3 multiboot
  * kernel from compiling.  This will need further attention.
index c9c5972..05757eb 100644 (file)
@@ -1,14 +1,19 @@
 /*
  * OMAP3 clock framework
  *
- * Virtual clocks are introduced as a convenient tools.
- * They are sources for other clocks and not supposed
- * to be requested from drivers directly.
- *
  * Copyright (C) 2007-2008 Texas Instruments, Inc.
  * Copyright (C) 2007-2008 Nokia Corporation
  *
  * Written by Paul Walmsley
+ * With many device clock fixes by Kevin Hilman and Jouni Högander
+ * DPLL bypass clock support added by Roman Tereshonkov
+ *
+ */
+
+/*
+ * Virtual clocks are introduced as convenient tools.
+ * They are sources for other clocks and not supposed
+ * to be requested from drivers directly.
  */
 
 #ifndef __ARCH_ARM_MACH_OMAP2_CLOCK34XX_H
 
 static void omap3_dpll_recalc(struct clk *clk);
 static void omap3_clkoutx2_recalc(struct clk *clk);
+static void omap3_dpll_allow_idle(struct clk *clk);
+static void omap3_dpll_deny_idle(struct clk *clk);
+static u32 omap3_dpll_autoidle_read(struct clk *clk);
+static int omap3_noncore_dpll_enable(struct clk *clk);
+static void omap3_noncore_dpll_disable(struct clk *clk);
+
+/* Maximum DPLL multiplier, divider values for OMAP3 */
+#define OMAP3_MAX_DPLL_MULT            2048
+#define OMAP3_MAX_DPLL_DIV             128
 
 /*
  * DPLL1 supplies clock to the MPU.
@@ -33,6 +47,11 @@ static void omap3_clkoutx2_recalc(struct clk *clk);
  * DPLL5 supplies other peripheral clocks (USBHOST, USIM).
  */
 
+/* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
+#define DPLL_LOW_POWER_STOP            0x1
+#define DPLL_LOW_POWER_BYPASS          0x5
+#define DPLL_LOCKED                    0x7
+
 /* PRM CLOCKS */
 
 /* According to timer32k.c, this is a 32768Hz clock, not a 32000Hz clock. */
@@ -240,15 +259,23 @@ static const struct clksel_rate div16_dpll_rates[] = {
 /* DPLL1 */
 /* MPU clock source */
 /* Type: DPLL */
-static const struct dpll_data dpll1_dd = {
+static struct dpll_data dpll1_dd = {
        .mult_div1_reg  = OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKSEL1_PLL),
        .mult_mask      = OMAP3430_MPU_DPLL_MULT_MASK,
        .div1_mask      = OMAP3430_MPU_DPLL_DIV_MASK,
        .control_reg    = OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_CLKEN_PLL),
        .enable_mask    = OMAP3430_EN_MPU_DPLL_MASK,
+       .modes          = (1 << DPLL_LOW_POWER_BYPASS) | (1 << DPLL_LOCKED),
        .auto_recal_bit = OMAP3430_EN_MPU_DPLL_DRIFTGUARD_SHIFT,
        .recal_en_bit   = OMAP3430_MPU_DPLL_RECAL_EN_SHIFT,
        .recal_st_bit   = OMAP3430_MPU_DPLL_ST_SHIFT,
+       .autoidle_reg   = OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_AUTOIDLE_PLL),
+       .autoidle_mask  = OMAP3430_AUTO_MPU_DPLL_MASK,
+       .idlest_reg     = OMAP_CM_REGADDR(MPU_MOD, OMAP3430_CM_IDLEST_PLL),
+       .idlest_bit     = OMAP3430_ST_MPU_CLK_SHIFT,
+       .max_multiplier = OMAP3_MAX_DPLL_MULT,
+       .max_divider    = OMAP3_MAX_DPLL_DIV,
+       .rate_tolerance = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
 static struct clk dpll1_ck = {
@@ -256,6 +283,7 @@ static struct clk dpll1_ck = {
        .parent         = &sys_ck,
        .dpll_data      = &dpll1_dd,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES | ALWAYS_ENABLED,
+       .round_rate     = &omap2_dpll_round_rate,
        .recalc         = &omap3_dpll_recalc,
 };
 
@@ -297,22 +325,34 @@ static struct clk dpll1_x2m2_ck = {
 /* IVA2 clock source */
 /* Type: DPLL */
 
-static const struct dpll_data dpll2_dd = {
+static struct dpll_data dpll2_dd = {
        .mult_div1_reg  = OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSEL1_PLL),
        .mult_mask      = OMAP3430_IVA2_DPLL_MULT_MASK,
        .div1_mask      = OMAP3430_IVA2_DPLL_DIV_MASK,
        .control_reg    = OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKEN_PLL),
        .enable_mask    = OMAP3430_EN_IVA2_DPLL_MASK,
+       .modes          = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED) |
+                               (1 << DPLL_LOW_POWER_BYPASS),
        .auto_recal_bit = OMAP3430_EN_IVA2_DPLL_DRIFTGUARD_SHIFT,
        .recal_en_bit   = OMAP3430_PRM_IRQENABLE_MPU_IVA2_DPLL_RECAL_EN_SHIFT,
        .recal_st_bit   = OMAP3430_PRM_IRQSTATUS_MPU_IVA2_DPLL_ST_SHIFT,
+       .autoidle_reg   = OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_AUTOIDLE_PLL),
+       .autoidle_mask  = OMAP3430_AUTO_IVA2_DPLL_MASK,
+       .idlest_reg     = OMAP_CM_REGADDR(OMAP3430_IVA2_MOD, OMAP3430_CM_IDLEST_PLL),
+       .idlest_bit     = OMAP3430_ST_IVA2_CLK_SHIFT,
+       .max_multiplier = OMAP3_MAX_DPLL_MULT,
+       .max_divider    = OMAP3_MAX_DPLL_DIV,
+       .rate_tolerance = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
 static struct clk dpll2_ck = {
        .name           = "dpll2_ck",
        .parent         = &sys_ck,
        .dpll_data      = &dpll2_dd,
-       .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES | ALWAYS_ENABLED,
+       .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES,
+       .enable         = &omap3_noncore_dpll_enable,
+       .disable        = &omap3_noncore_dpll_disable,
+       .round_rate     = &omap2_dpll_round_rate,
        .recalc         = &omap3_dpll_recalc,
 };
 
@@ -338,10 +378,12 @@ static struct clk dpll2_m2_ck = {
        .recalc         = &omap2_clksel_recalc,
 };
 
-/* DPLL3 */
-/* Source clock for all interfaces and for some device fclks */
-/* Type: DPLL */
-static const struct dpll_data dpll3_dd = {
+/*
+ * DPLL3
+ * Source clock for all interfaces and for some device fclks
+ * REVISIT: Also supports fast relock bypass - not included below
+ */
+static struct dpll_data dpll3_dd = {
        .mult_div1_reg  = OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL1),
        .mult_mask      = OMAP3430_CORE_DPLL_MULT_MASK,
        .div1_mask      = OMAP3430_CORE_DPLL_DIV_MASK,
@@ -350,6 +392,11 @@ static const struct dpll_data dpll3_dd = {
        .auto_recal_bit = OMAP3430_EN_CORE_DPLL_DRIFTGUARD_SHIFT,
        .recal_en_bit   = OMAP3430_CORE_DPLL_RECAL_EN_SHIFT,
        .recal_st_bit   = OMAP3430_CORE_DPLL_ST_SHIFT,
+       .autoidle_reg   = OMAP_CM_REGADDR(PLL_MOD, CM_AUTOIDLE),
+       .autoidle_mask  = OMAP3430_AUTO_CORE_DPLL_MASK,
+       .max_multiplier = OMAP3_MAX_DPLL_MULT,
+       .max_divider    = OMAP3_MAX_DPLL_DIV,
+       .rate_tolerance = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
 static struct clk dpll3_ck = {
@@ -357,6 +404,7 @@ static struct clk dpll3_ck = {
        .parent         = &sys_ck,
        .dpll_data      = &dpll3_dd,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES | ALWAYS_ENABLED,
+       .round_rate     = &omap2_dpll_round_rate,
        .recalc         = &omap3_dpll_recalc,
 };
 
@@ -439,7 +487,7 @@ static struct clk core_ck = {
        .name           = "core_ck",
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_CORE_CLK,
+       .clksel_mask    = OMAP3430_ST_CORE_CLK_MASK,
        .clksel         = core_ck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                PARENT_CONTROLS_CLOCK,
@@ -456,7 +504,7 @@ static struct clk dpll3_m2x2_ck = {
        .name           = "dpll3_m2x2_ck",
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_CORE_CLK,
+       .clksel_mask    = OMAP3430_ST_CORE_CLK_MASK,
        .clksel         = dpll3_m2x2_ck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                PARENT_CONTROLS_CLOCK,
@@ -503,7 +551,7 @@ static struct clk emu_core_alwon_ck = {
        .parent         = &dpll3_m3x2_ck,
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_CORE_CLK,
+       .clksel_mask    = OMAP3430_ST_CORE_CLK_MASK,
        .clksel         = emu_core_alwon_ck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                PARENT_CONTROLS_CLOCK,
@@ -513,22 +561,33 @@ static struct clk emu_core_alwon_ck = {
 /* DPLL4 */
 /* Supplies 96MHz, 54Mhz TV DAC, DSS fclk, CAM sensor clock, emul trace clk */
 /* Type: DPLL */
-static const struct dpll_data dpll4_dd = {
+static struct dpll_data dpll4_dd = {
        .mult_div1_reg  = OMAP_CM_REGADDR(PLL_MOD, CM_CLKSEL2),
        .mult_mask      = OMAP3430_PERIPH_DPLL_MULT_MASK,
        .div1_mask      = OMAP3430_PERIPH_DPLL_DIV_MASK,
        .control_reg    = OMAP_CM_REGADDR(PLL_MOD, CM_CLKEN),
        .enable_mask    = OMAP3430_EN_PERIPH_DPLL_MASK,
+       .modes          = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
        .auto_recal_bit = OMAP3430_EN_PERIPH_DPLL_DRIFTGUARD_SHIFT,
        .recal_en_bit   = OMAP3430_PERIPH_DPLL_RECAL_EN_SHIFT,
        .recal_st_bit   = OMAP3430_PERIPH_DPLL_ST_SHIFT,
+       .autoidle_reg   = OMAP_CM_REGADDR(PLL_MOD, CM_AUTOIDLE),
+       .autoidle_mask  = OMAP3430_AUTO_PERIPH_DPLL_MASK,
+       .idlest_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
+       .idlest_bit     = OMAP3430_ST_PERIPH_CLK_SHIFT,
+       .max_multiplier = OMAP3_MAX_DPLL_MULT,
+       .max_divider    = OMAP3_MAX_DPLL_DIV,
+       .rate_tolerance = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
 static struct clk dpll4_ck = {
        .name           = "dpll4_ck",
        .parent         = &sys_ck,
        .dpll_data      = &dpll4_dd,
-       .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES | ALWAYS_ENABLED,
+       .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES,
+       .enable         = &omap3_noncore_dpll_enable,
+       .disable        = &omap3_noncore_dpll_disable,
+       .round_rate     = &omap2_dpll_round_rate,
        .recalc         = &omap3_dpll_recalc,
 };
 
@@ -584,7 +643,7 @@ static struct clk omap_96m_alwon_fck = {
        .parent         = &dpll4_m2x2_ck,
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_PERIPH_CLK,
+       .clksel_mask    = OMAP3430_ST_PERIPH_CLK_MASK,
        .clksel         = omap_96m_alwon_fck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                 PARENT_CONTROLS_CLOCK,
@@ -610,7 +669,7 @@ static struct clk cm_96m_fck = {
        .parent         = &dpll4_m2x2_ck,
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_PERIPH_CLK,
+       .clksel_mask    = OMAP3430_ST_PERIPH_CLK_MASK,
        .clksel         = cm_96m_fck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                PARENT_CONTROLS_CLOCK,
@@ -652,7 +711,7 @@ static struct clk virt_omap_54m_fck = {
        .parent         = &dpll4_m3x2_ck,
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_PERIPH_CLK,
+       .clksel_mask    = OMAP3430_ST_PERIPH_CLK_MASK,
        .clksel         = virt_omap_54m_fck_clksel,
        .flags          = CLOCK_IN_OMAP343X | RATE_PROPAGATES |
                                PARENT_CONTROLS_CLOCK,
@@ -804,23 +863,33 @@ static struct clk emu_per_alwon_ck = {
 /* Supplies 120MHz clock, USIM source clock */
 /* Type: DPLL */
 /* 3430ES2 only */
-static const struct dpll_data dpll5_dd = {
+static struct dpll_data dpll5_dd = {
        .mult_div1_reg  = OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKSEL4),
        .mult_mask      = OMAP3430ES2_PERIPH2_DPLL_MULT_MASK,
        .div1_mask      = OMAP3430ES2_PERIPH2_DPLL_DIV_MASK,
        .control_reg    = OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_CLKEN2),
        .enable_mask    = OMAP3430ES2_EN_PERIPH2_DPLL_MASK,
+       .modes          = (1 << DPLL_LOW_POWER_STOP) | (1 << DPLL_LOCKED),
        .auto_recal_bit = OMAP3430ES2_EN_PERIPH2_DPLL_DRIFTGUARD_SHIFT,
        .recal_en_bit   = OMAP3430ES2_SND_PERIPH_DPLL_RECAL_EN_SHIFT,
        .recal_st_bit   = OMAP3430ES2_SND_PERIPH_DPLL_ST_SHIFT,
+       .autoidle_reg   = OMAP_CM_REGADDR(PLL_MOD, OMAP3430ES2_CM_AUTOIDLE2_PLL),
+       .autoidle_mask  = OMAP3430ES2_AUTO_PERIPH2_DPLL_MASK,
+       .idlest_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST2),
+       .idlest_bit     = OMAP3430ES2_ST_PERIPH2_CLK_SHIFT,
+       .max_multiplier = OMAP3_MAX_DPLL_MULT,
+       .max_divider    = OMAP3_MAX_DPLL_DIV,
+       .rate_tolerance = DEFAULT_DPLL_RATE_TOLERANCE
 };
 
 static struct clk dpll5_ck = {
        .name           = "dpll5_ck",
        .parent         = &sys_ck,
        .dpll_data      = &dpll5_dd,
-       .flags          = CLOCK_IN_OMAP3430ES2 | RATE_PROPAGATES |
-                               ALWAYS_ENABLED,
+       .flags          = CLOCK_IN_OMAP3430ES2 | RATE_PROPAGATES,
+       .enable         = &omap3_noncore_dpll_enable,
+       .disable        = &omap3_noncore_dpll_disable,
+       .round_rate     = &omap2_dpll_round_rate,
        .recalc         = &omap3_dpll_recalc,
 };
 
@@ -1365,7 +1434,8 @@ static const struct clksel mcbsp_15_clksel[] = {
 };
 
 static struct clk mcbsp5_fck = {
-       .name           = "mcbsp5_fck",
+       .name           = "mcbsp_fck",
+       .id             = 5,
        .init           = &omap2_init_clksel_parent,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
        .enable_bit     = OMAP3430_EN_MCBSP5_SHIFT,
@@ -1377,7 +1447,8 @@ static struct clk mcbsp5_fck = {
 };
 
 static struct clk mcbsp1_fck = {
-       .name           = "mcbsp1_fck",
+       .name           = "mcbsp_fck",
+       .id             = 1,
        .init           = &omap2_init_clksel_parent,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_FCLKEN1),
        .enable_bit     = OMAP3430_EN_MCBSP1_SHIFT,
@@ -1789,7 +1860,8 @@ static struct clk gpt10_ick = {
 };
 
 static struct clk mcbsp5_ick = {
-       .name           = "mcbsp5_ick",
+       .name           = "mcbsp_ick",
+       .id             = 5,
        .parent         = &core_l4_ick,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
        .enable_bit     = OMAP3430_EN_MCBSP5_SHIFT,
@@ -1798,7 +1870,8 @@ static struct clk mcbsp5_ick = {
 };
 
 static struct clk mcbsp1_ick = {
-       .name           = "mcbsp1_ick",
+       .name           = "mcbsp_ick",
+       .id             = 1,
        .parent         = &core_l4_ick,
        .enable_reg     = OMAP_CM_REGADDR(CORE_MOD, CM_ICLKEN1),
        .enable_bit     = OMAP3430_EN_MCBSP1_SHIFT,
@@ -1935,7 +2008,7 @@ static struct clk dss1_alwon_fck = {
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_DSS_MOD, CM_FCLKEN),
        .enable_bit     = OMAP3430_EN_DSS1_SHIFT,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_PERIPH_CLK,
+       .clksel_mask    = OMAP3430_ST_PERIPH_CLK_MASK,
        .clksel         = dss1_alwon_fck_clksel,
        .flags          = CLOCK_IN_OMAP343X,
        .recalc         = &omap2_clksel_recalc,
@@ -1991,7 +2064,7 @@ static struct clk cam_mclk = {
        .parent         = &dpll4_m5x2_ck,
        .init           = &omap2_init_clksel_parent,
        .clksel_reg     = OMAP_CM_REGADDR(PLL_MOD, CM_IDLEST),
-       .clksel_mask    = OMAP3430_ST_PERIPH_CLK,
+       .clksel_mask    = OMAP3430_ST_PERIPH_CLK_MASK,
        .clksel         = cam_mclk_clksel,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_CAM_MOD, CM_FCLKEN),
        .enable_bit     = OMAP3430_EN_CAM_SHIFT,
@@ -2541,7 +2614,8 @@ static struct clk gpt2_ick = {
 };
 
 static struct clk mcbsp2_ick = {
-       .name           = "mcbsp2_ick",
+       .name           = "mcbsp_ick",
+       .id             = 2,
        .parent         = &per_l4_ick,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_ICLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP2_SHIFT,
@@ -2550,7 +2624,8 @@ static struct clk mcbsp2_ick = {
 };
 
 static struct clk mcbsp3_ick = {
-       .name           = "mcbsp3_ick",
+       .name           = "mcbsp_ick",
+       .id             = 3,
        .parent         = &per_l4_ick,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_ICLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP3_SHIFT,
@@ -2559,7 +2634,8 @@ static struct clk mcbsp3_ick = {
 };
 
 static struct clk mcbsp4_ick = {
-       .name           = "mcbsp4_ick",
+       .name           = "mcbsp_ick",
+       .id             = 4,
        .parent         = &per_l4_ick,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_ICLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP4_SHIFT,
@@ -2574,7 +2650,8 @@ static const struct clksel mcbsp_234_clksel[] = {
 };
 
 static struct clk mcbsp2_fck = {
-       .name           = "mcbsp2_fck",
+       .name           = "mcbsp_fck",
+       .id             = 2,
        .init           = &omap2_init_clksel_parent,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_FCLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP2_SHIFT,
@@ -2586,7 +2663,8 @@ static struct clk mcbsp2_fck = {
 };
 
 static struct clk mcbsp3_fck = {
-       .name           = "mcbsp3_fck",
+       .name           = "mcbsp_fck",
+       .id             = 3,
        .init           = &omap2_init_clksel_parent,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_FCLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP3_SHIFT,
@@ -2598,7 +2676,8 @@ static struct clk mcbsp3_fck = {
 };
 
 static struct clk mcbsp4_fck = {
-       .name           = "mcbsp4_fck",
+       .name           = "mcbsp_fck",
+       .id             = 4,
        .init           = &omap2_init_clksel_parent,
        .enable_reg     = OMAP_CM_REGADDR(OMAP3430_PER_MOD, CM_FCLKEN),
        .enable_bit     = OMAP3430_EN_MCBSP4_SHIFT,
index 3c38395..ee4c0ca 100644 (file)
@@ -72,7 +72,8 @@
 #define OMAP3430_ST_IVA2                               (1 << 0)
 
 /* CM_IDLEST_PLL_IVA2 */
-#define OMAP3430_ST_IVA2_CLK                           (1 << 0)
+#define OMAP3430_ST_IVA2_CLK_SHIFT                     0
+#define OMAP3430_ST_IVA2_CLK_MASK                      (1 << 0)
 
 /* CM_AUTOIDLE_PLL_IVA2 */
 #define OMAP3430_AUTO_IVA2_DPLL_SHIFT                  0
 #define OMAP3430_ST_MPU                                        (1 << 0)
 
 /* CM_IDLEST_PLL_MPU */
-#define OMAP3430_ST_MPU_CLK                            (1 << 0)
-#define OMAP3430_ST_IVA2_CLK_MASK                      (1 << 0)
-
-/* CM_IDLEST_PLL_MPU */
+#define OMAP3430_ST_MPU_CLK_SHIFT                      0
 #define OMAP3430_ST_MPU_CLK_MASK                       (1 << 0)
 
 /* CM_AUTOIDLE_PLL_MPU */
 #define OMAP3430_ST_12M_CLK                            (1 << 4)
 #define OMAP3430_ST_48M_CLK                            (1 << 3)
 #define OMAP3430_ST_96M_CLK                            (1 << 2)
-#define OMAP3430_ST_PERIPH_CLK                         (1 << 1)
-#define OMAP3430_ST_CORE_CLK                           (1 << 0)
+#define OMAP3430_ST_PERIPH_CLK_SHIFT                   1
+#define OMAP3430_ST_PERIPH_CLK_MASK                    (1 << 1)
+#define OMAP3430_ST_CORE_CLK_SHIFT                     0
+#define OMAP3430_ST_CORE_CLK_MASK                      (1 << 0)
 
 /* CM_IDLEST2_CKGEN */
 #define OMAP3430ES2_ST_120M_CLK_SHIFT                  1
 #define OMAP3430_AUTO_CORE_DPLL_SHIFT                  0
 #define OMAP3430_AUTO_CORE_DPLL_MASK                   (0x7 << 0)
 
+/* CM_AUTOIDLE2_PLL */
+#define OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT            0
+#define OMAP3430ES2_AUTO_PERIPH2_DPLL_MASK             (0x7 << 0)
+
 /* CM_CLKSEL1_PLL */
 /* Note that OMAP3430_CORE_DPLL_CLKOUT_DIV_MASK was (0x3 << 27) on 3430ES1 */
 #define OMAP3430_CORE_DPLL_CLKOUT_DIV_SHIFT            27
index 8489f30..87a44c7 100644 (file)
@@ -81,6 +81,7 @@
 #define OMAP3430ES2_CM_FCLKEN3                         0x0008
 #define OMAP3430_CM_IDLEST_PLL                         CM_IDLEST2
 #define OMAP3430_CM_AUTOIDLE_PLL                       CM_AUTOIDLE2
+#define OMAP3430ES2_CM_AUTOIDLE2_PLL                   CM_AUTOIDLE2
 #define OMAP3430_CM_CLKSEL1                            CM_CLKSEL
 #define OMAP3430_CM_CLKSEL1_PLL                                CM_CLKSEL
 #define OMAP3430_CM_CLKSEL2_PLL                                CM_CLKSEL2
 /* Clock management domain register get/set */
 
 #ifndef __ASSEMBLER__
-static inline void cm_write_mod_reg(u32 val, s16 module, s16 idx)
+
+extern u32 cm_read_mod_reg(s16 module, u16 idx);
+extern void cm_write_mod_reg(u32 val, s16 module, u16 idx);
+extern u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx);
+
+static inline u32 cm_set_mod_reg_bits(u32 bits, s16 module, s16 idx)
 {
-       __raw_writel(val, OMAP_CM_REGADDR(module, idx));
+       return cm_rmw_mod_reg_bits(bits, bits, module, idx);
 }
 
-static inline u32 cm_read_mod_reg(s16 module, s16 idx)
+static inline u32 cm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx)
 {
-       return __raw_readl(OMAP_CM_REGADDR(module, idx));
+       return cm_rmw_mod_reg_bits(bits, 0x0, module, idx);
 }
+
 #endif
 
 /* CM register bits shared between 24XX and 3430 */
index a5d86a4..51f7030 100644 (file)
 #undef DEBUG
 
 #include <linux/kernel.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
-
+#include <asm/arch/common.h>
 #include <asm/arch/control.h>
 
-static u32 omap2_ctrl_base;
+static void __iomem *omap2_ctrl_base;
 
-#define OMAP_CTRL_REGADDR(reg) (void __iomem *)IO_ADDRESS(omap2_ctrl_base \
-                                                               + (reg))
+#define OMAP_CTRL_REGADDR(reg)         (omap2_ctrl_base + (reg))
 
-void omap_ctrl_base_set(u32 base)
+void __init omap2_set_globals_control(struct omap_globals *omap2_globals)
 {
-       omap2_ctrl_base = base;
+       omap2_ctrl_base = omap2_globals->ctrl;
 }
 
-u32 omap_ctrl_base_get(void)
+void __iomem *omap_ctrl_base_get(void)
 {
        return omap2_ctrl_base;
 }
@@ -50,25 +49,16 @@ u32 omap_ctrl_readl(u16 offset)
 
 void omap_ctrl_writeb(u8 val, u16 offset)
 {
-       pr_debug("omap_ctrl_writeb: writing 0x%0x to 0x%0x\n", val,
-                (u32)OMAP_CTRL_REGADDR(offset));
-
        __raw_writeb(val, OMAP_CTRL_REGADDR(offset));
 }
 
 void omap_ctrl_writew(u16 val, u16 offset)
 {
-       pr_debug("omap_ctrl_writew: writing 0x%0x to 0x%0x\n", val,
-                (u32)OMAP_CTRL_REGADDR(offset));
-
        __raw_writew(val, OMAP_CTRL_REGADDR(offset));
 }
 
 void omap_ctrl_writel(u32 val, u16 offset)
 {
-       pr_debug("omap_ctrl_writel: writing 0x%0x to 0x%0x\n", val,
-                (u32)OMAP_CTRL_REGADDR(offset));
-
        __raw_writel(val, OMAP_CTRL_REGADDR(offset));
 }
 
index 4dfd878..dff4b16 100644 (file)
 
 #include <asm/io.h>
 
-#if defined(CONFIG_ARCH_OMAP2420)
-#define OMAP24XX_TAP_BASE      io_p2v(0x48014000)
-#endif
+#include <asm/arch/control.h>
+#include <asm/arch/cpu.h>
 
-#if defined(CONFIG_ARCH_OMAP2430)
-#define OMAP24XX_TAP_BASE      io_p2v(0x4900A000)
+#if defined(CONFIG_ARCH_OMAP2420)
+#define TAP_BASE       io_p2v(0x48014000)
+#elif defined(CONFIG_ARCH_OMAP2430)
+#define TAP_BASE       io_p2v(0x4900A000)
+#elif defined(CONFIG_ARCH_OMAP34XX)
+#define TAP_BASE       io_p2v(0x4830A000)
 #endif
 
 #define OMAP_TAP_IDCODE                0x0204
+#if defined(CONFIG_ARCH_OMAP34XX)
+#define OMAP_TAP_PROD_ID       0x0210
+#else
 #define OMAP_TAP_PROD_ID       0x0208
+#endif
 
 #define OMAP_TAP_DIE_ID_0      0x0218
 #define OMAP_TAP_DIE_ID_1      0x021C
@@ -56,9 +63,134 @@ static struct omap_id omap_ids[] __initdata = {
        { .hawkeye = 0xb68a, .dev = 0x0, .type = 0x24300000 },
 };
 
+static struct omap_chip_id omap_chip;
+
+/**
+ * omap_chip_is - test whether currently running OMAP matches a chip type
+ * @oc: omap_chip_t to test against
+ *
+ * Test whether the currently-running OMAP chip matches the supplied
+ * chip type 'oc'.  Returns 1 upon a match; 0 upon failure.
+ */
+int omap_chip_is(struct omap_chip_id oci)
+{
+       return (oci.oc & omap_chip.oc) ? 1 : 0;
+}
+EXPORT_SYMBOL(omap_chip_is);
+
 static u32 __init read_tap_reg(int reg)
 {
-       return __raw_readl(OMAP24XX_TAP_BASE + reg);
+       unsigned int regval = 0;
+       u32 cpuid;
+
+       /* Reading the IDCODE register on 3430 ES1 results in a
+        * data abort as the register is not exposed on the OCP
+        * Hence reading the Cortex Rev
+        */
+       cpuid = read_cpuid(CPUID_ID);
+
+       /* If the processor type is Cortex-A8 and the revision is 0x0
+        * it means its Cortex r0p0 which is 3430 ES1
+        */
+       if ((((cpuid >> 4) & 0xFFF) == 0xC08) && ((cpuid & 0xF) == 0x0)) {
+               switch (reg) {
+               case OMAP_TAP_IDCODE  : regval = 0x0B7AE02F; break;
+               /* Making DevType as 0xF in ES1 to differ from ES2 */
+               case OMAP_TAP_PROD_ID : regval = 0x000F00F0; break;
+               case OMAP_TAP_DIE_ID_0: regval = 0x01000000; break;
+               case OMAP_TAP_DIE_ID_1: regval = 0x1012d687; break;
+               case OMAP_TAP_DIE_ID_2: regval = 0x00000000; break;
+               case OMAP_TAP_DIE_ID_3: regval = 0x2d2c0000; break;
+               }
+       } else
+               regval = __raw_readl(TAP_BASE + reg);
+
+       return regval;
+
+}
+
+/*
+ * _set_system_rev - set the system_rev global based on current OMAP chip type
+ *
+ * Set the system_rev global.  This is primarily used by the cpu_is_omapxxxx()
+ * macros.
+ */
+static void __init _set_system_rev(u32 type, u8 rev)
+{
+       u32 i, ctrl_status;
+
+       /*
+        * system_rev encoding is as follows
+        * system_rev & 0xff000000 -> Omap Class (24xx/34xx)
+        * system_rev & 0xfff00000 -> Omap Sub Class (242x/343x)
+        * system_rev & 0xffff0000 -> Omap type (2420/2422/2423/2430/3430)
+        * system_rev & 0x0000f000 -> Silicon revision (ES1, ES2 )
+        * system_rev & 0x00000700 -> Device Type ( EMU/HS/GP/BAD )
+        * system_rev & 0x000000c0 -> IDCODE revision[6:7]
+        * system_rev & 0x0000003f -> sys_boot[0:5]
+        */
+       /* Embedding the ES revision info in type field */
+       system_rev = type;
+       /* Also add IDCODE revision info only two lower bits */
+       system_rev |= ((rev & 0x3) << 6);
+
+       /* Add in the device type and sys_boot fields (see above) */
+       if (cpu_is_omap24xx()) {
+               i = OMAP24XX_CONTROL_STATUS;
+       } else if (cpu_is_omap343x()) {
+               i = OMAP343X_CONTROL_STATUS;
+       } else {
+               printk(KERN_ERR "id: unknown CPU type\n");
+               BUG();
+       }
+       ctrl_status = omap_ctrl_readl(i);
+       system_rev |= (ctrl_status & (OMAP2_SYSBOOT_5_MASK |
+                                     OMAP2_SYSBOOT_4_MASK |
+                                     OMAP2_SYSBOOT_3_MASK |
+                                     OMAP2_SYSBOOT_2_MASK |
+                                     OMAP2_SYSBOOT_1_MASK |
+                                     OMAP2_SYSBOOT_0_MASK));
+       system_rev |= (ctrl_status & OMAP2_DEVICETYPE_MASK);
+}
+
+
+/*
+ * _set_omap_chip - set the omap_chip global based on OMAP chip type
+ *
+ * Build the omap_chip bits.  This variable is used by powerdomain and
+ * clockdomain code to indicate whether structures are applicable for
+ * the current OMAP chip type by ANDing it against a 'platform' bitfield
+ * in the structure.
+ */
+static void __init _set_omap_chip(void)
+{
+       if (cpu_is_omap343x()) {
+
+               omap_chip.oc = CHIP_IS_OMAP3430;
+               if (is_sil_rev_equal_to(OMAP3430_REV_ES1_0))
+                       omap_chip.oc |= CHIP_IS_OMAP3430ES1;
+               else if (is_sil_rev_greater_than(OMAP3430_REV_ES1_0))
+                       omap_chip.oc |= CHIP_IS_OMAP3430ES2;
+
+       } else if (cpu_is_omap243x()) {
+
+               /* Currently only supports 2430ES2.1 and 2430-all */
+               omap_chip.oc |= CHIP_IS_OMAP2430;
+
+       } else if (cpu_is_omap242x()) {
+
+               /* Currently only supports 2420ES2.1.1 and 2420-all */
+               omap_chip.oc |= CHIP_IS_OMAP2420;
+
+       } else {
+
+               /* Current CPU not supported by this code. */
+               printk(KERN_WARNING "OMAP chip type code does not yet support "
+                      "this CPU type.\n");
+               WARN_ON(1);
+
+       }
+
 }
 
 void __init omap2_check_revision(void)
@@ -76,21 +208,31 @@ void __init omap2_check_revision(void)
        rev = (idcode >> 28) & 0x0f;
        dev_type = (prod_id >> 16) & 0x0f;
 
-#ifdef DEBUG
-       printk(KERN_DEBUG "OMAP_TAP_IDCODE 0x%08x REV %i HAWKEYE 0x%04x MANF %03x\n",
-               idcode, rev, hawkeye, (idcode >> 1) & 0x7ff);
-       printk(KERN_DEBUG "OMAP_TAP_DIE_ID_0: 0x%08x\n",
-               read_tap_reg(OMAP_TAP_DIE_ID_0));
-       printk(KERN_DEBUG "OMAP_TAP_DIE_ID_1: 0x%08x DEV_REV: %i\n",
-               read_tap_reg(OMAP_TAP_DIE_ID_1),
-              (read_tap_reg(OMAP_TAP_DIE_ID_1) >> 28) & 0xf);
-       printk(KERN_DEBUG "OMAP_TAP_DIE_ID_2: 0x%08x\n",
-               read_tap_reg(OMAP_TAP_DIE_ID_2));
-       printk(KERN_DEBUG "OMAP_TAP_DIE_ID_3: 0x%08x\n",
-               read_tap_reg(OMAP_TAP_DIE_ID_3));
-       printk(KERN_DEBUG "OMAP_TAP_PROD_ID_0: 0x%08x DEV_TYPE: %i\n",
-               prod_id, dev_type);
-#endif
+       pr_debug("OMAP_TAP_IDCODE 0x%08x REV %i HAWKEYE 0x%04x MANF %03x\n",
+                idcode, rev, hawkeye, (idcode >> 1) & 0x7ff);
+       pr_debug("OMAP_TAP_DIE_ID_0: 0x%08x\n",
+                read_tap_reg(OMAP_TAP_DIE_ID_0));
+       pr_debug("OMAP_TAP_DIE_ID_1: 0x%08x DEV_REV: %i\n",
+                read_tap_reg(OMAP_TAP_DIE_ID_1),
+                (read_tap_reg(OMAP_TAP_DIE_ID_1) >> 28) & 0xf);
+       pr_debug("OMAP_TAP_DIE_ID_2: 0x%08x\n",
+                read_tap_reg(OMAP_TAP_DIE_ID_2));
+       pr_debug("OMAP_TAP_DIE_ID_3: 0x%08x\n",
+                read_tap_reg(OMAP_TAP_DIE_ID_3));
+       pr_debug("OMAP_TAP_PROD_ID_0: 0x%08x DEV_TYPE: %i\n",
+                prod_id, dev_type);
+
+       /*
+        * Detection for 34xx ES2.0 and above can be done with just
+        * hawkeye and rev. See TRM 1.5.2 Device Identification.
+        * Note that rev cannot be used directly as ES1.0 uses value 0.
+        */
+       if (hawkeye == 0xb7ae) {
+               system_rev = 0x34300000 | ((1 + rev) << 12);
+               pr_info("OMAP%04x ES2.%i\n", system_rev >> 16, rev);
+               _set_omap_chip();
+               return;
+       }
 
        /* Check hawkeye ids */
        for (i = 0; i < ARRAY_SIZE(omap_ids); i++) {
@@ -114,16 +256,15 @@ void __init omap2_check_revision(void)
                                omap_ids[i].type >> 16);
                j = i;
        }
-       system_rev = omap_ids[j].type;
 
-       system_rev |= rev << 8;
+       _set_system_rev(omap_ids[j].type, rev);
 
-       /* Add the cpu class info (24xx) */
-       system_rev |= 0x24;
+       _set_omap_chip();
 
        pr_info("OMAP%04x", system_rev >> 16);
        if ((system_rev >> 8) & 0x0f)
-               printk("%x", (system_rev >> 8) & 0x0f);
-       printk("\n");
+               pr_info("ES%x", (system_rev >> 12) & 0xf);
+       pr_info("\n");
+
 }
 
diff --git a/arch/arm/mach-omap2/mcbsp.c b/arch/arm/mach-omap2/mcbsp.c
new file mode 100644 (file)
index 0000000..17cf199
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * linux/arch/arm/mach-omap2/mcbsp.c
+ *
+ * Copyright (C) 2008 Instituto Nokia de Tecnologia
+ * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Multichannel mode not supported.
+ */
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+#include <asm/arch/dma.h>
+#include <asm/arch/mux.h>
+#include <asm/arch/cpu.h>
+#include <asm/arch/mcbsp.h>
+
+struct mcbsp_internal_clk {
+       struct clk clk;
+       struct clk **childs;
+       int n_childs;
+};
+
+#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
+static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
+{
+       const char *clk_names[] = { "mcbsp_ick", "mcbsp_fck" };
+       int i;
+
+       mclk->n_childs = ARRAY_SIZE(clk_names);
+       mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
+                               GFP_KERNEL);
+
+       for (i = 0; i < mclk->n_childs; i++) {
+               /* We fake a platform device to get correct device id */
+               struct platform_device pdev;
+
+               pdev.dev.bus = &platform_bus_type;
+               pdev.id = mclk->clk.id;
+               mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
+               if (IS_ERR(mclk->childs[i]))
+                       printk(KERN_ERR "Could not get clock %s (%d).\n",
+                               clk_names[i], mclk->clk.id);
+       }
+}
+
+static int omap_mcbsp_clk_enable(struct clk *clk)
+{
+       struct mcbsp_internal_clk *mclk = container_of(clk,
+                                       struct mcbsp_internal_clk, clk);
+       int i;
+
+       for (i = 0; i < mclk->n_childs; i++)
+               clk_enable(mclk->childs[i]);
+       return 0;
+}
+
+static void omap_mcbsp_clk_disable(struct clk *clk)
+{
+       struct mcbsp_internal_clk *mclk = container_of(clk,
+                                       struct mcbsp_internal_clk, clk);
+       int i;
+
+       for (i = 0; i < mclk->n_childs; i++)
+               clk_disable(mclk->childs[i]);
+}
+
+static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
+       {
+               .clk = {
+                       .name           = "mcbsp_clk",
+                       .id             = 1,
+                       .enable         = omap_mcbsp_clk_enable,
+                       .disable        = omap_mcbsp_clk_disable,
+               },
+       },
+       {
+               .clk = {
+                       .name           = "mcbsp_clk",
+                       .id             = 2,
+                       .enable         = omap_mcbsp_clk_enable,
+                       .disable        = omap_mcbsp_clk_disable,
+               },
+       },
+};
+
+#define omap_mcbsp_clks_size   ARRAY_SIZE(omap_mcbsp_clks)
+#else
+#define omap_mcbsp_clks_size   0
+static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
+static inline void omap_mcbsp_clk_init(struct clk *clk)
+{ }
+#endif
+
+static void omap2_mcbsp2_mux_setup(void)
+{
+       omap_cfg_reg(Y15_24XX_MCBSP2_CLKX);
+       omap_cfg_reg(R14_24XX_MCBSP2_FSX);
+       omap_cfg_reg(W15_24XX_MCBSP2_DR);
+       omap_cfg_reg(V15_24XX_MCBSP2_DX);
+       omap_cfg_reg(V14_24XX_GPIO117);
+       /*
+        * TODO: Need to add MUX settings for OMAP 2430 SDP
+        */
+}
+
+static void omap2_mcbsp_request(unsigned int id)
+{
+       if (cpu_is_omap2420() && (id == OMAP_MCBSP2))
+               omap2_mcbsp2_mux_setup();
+}
+
+static int omap2_mcbsp_check(unsigned int id)
+{
+       if (id > OMAP_MAX_MCBSP_COUNT - 1) {
+               printk(KERN_ERR "OMAP-McBSP: McBSP%d doesn't exist\n", id + 1);
+               return -ENODEV;
+       }
+       return 0;
+}
+
+static struct omap_mcbsp_ops omap2_mcbsp_ops = {
+       .request        = omap2_mcbsp_request,
+       .check          = omap2_mcbsp_check,
+};
+
+#ifdef CONFIG_ARCH_OMAP24XX
+static struct omap_mcbsp_platform_data omap24xx_mcbsp_pdata[] = {
+       {
+               .virt_base      = IO_ADDRESS(OMAP24XX_MCBSP1_BASE),
+               .dma_rx_sync    = OMAP24XX_DMA_MCBSP1_RX,
+               .dma_tx_sync    = OMAP24XX_DMA_MCBSP1_TX,
+               .rx_irq         = INT_24XX_MCBSP1_IRQ_RX,
+               .tx_irq         = INT_24XX_MCBSP1_IRQ_TX,
+               .ops            = &omap2_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+       {
+               .virt_base      = IO_ADDRESS(OMAP24XX_MCBSP2_BASE),
+               .dma_rx_sync    = OMAP24XX_DMA_MCBSP2_RX,
+               .dma_tx_sync    = OMAP24XX_DMA_MCBSP2_TX,
+               .rx_irq         = INT_24XX_MCBSP2_IRQ_RX,
+               .tx_irq         = INT_24XX_MCBSP2_IRQ_TX,
+               .ops            = &omap2_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+};
+#define OMAP24XX_MCBSP_PDATA_SZ                ARRAY_SIZE(omap24xx_mcbsp_pdata)
+#else
+#define omap24xx_mcbsp_pdata           NULL
+#define OMAP24XX_MCBSP_PDATA_SZ                0
+#endif
+
+#ifdef CONFIG_ARCH_OMAP34XX
+static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
+       {
+               .virt_base      = IO_ADDRESS(OMAP34XX_MCBSP1_BASE),
+               .dma_rx_sync    = OMAP24XX_DMA_MCBSP1_RX,
+               .dma_tx_sync    = OMAP24XX_DMA_MCBSP1_TX,
+               .rx_irq         = INT_24XX_MCBSP1_IRQ_RX,
+               .tx_irq         = INT_24XX_MCBSP1_IRQ_TX,
+               .ops            = &omap2_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+       {
+               .virt_base      = IO_ADDRESS(OMAP34XX_MCBSP2_BASE),
+               .dma_rx_sync    = OMAP24XX_DMA_MCBSP2_RX,
+               .dma_tx_sync    = OMAP24XX_DMA_MCBSP2_TX,
+               .rx_irq         = INT_24XX_MCBSP2_IRQ_RX,
+               .tx_irq         = INT_24XX_MCBSP2_IRQ_TX,
+               .ops            = &omap2_mcbsp_ops,
+               .clk_name       = "mcbsp_clk",
+       },
+};
+#define OMAP34XX_MCBSP_PDATA_SZ                ARRAY_SIZE(omap34xx_mcbsp_pdata)
+#else
+#define omap34xx_mcbsp_pdata           NULL
+#define OMAP34XX_MCBSP_PDATA_SZ                0
+#endif
+
+int __init omap2_mcbsp_init(void)
+{
+       int i;
+
+       for (i = 0; i < omap_mcbsp_clks_size; i++) {
+               /* Once we call clk_get inside init, we do not register it */
+               omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
+               clk_register(&omap_mcbsp_clks[i].clk);
+       }
+
+       if (cpu_is_omap24xx())
+               omap_mcbsp_register_board_cfg(omap24xx_mcbsp_pdata,
+                                               OMAP24XX_MCBSP_PDATA_SZ);
+
+       if (cpu_is_omap34xx())
+               omap_mcbsp_register_board_cfg(omap34xx_mcbsp_pdata,
+                                               OMAP34XX_MCBSP_PDATA_SZ);
+
+       return omap_mcbsp_init();
+}
+arch_initcall(omap2_mcbsp_init);
index 1247908..73cadb2 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <asm/io.h>
 
+#include <asm/arch/common.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/sram.h>
 
@@ -32,8 +33,8 @@
 #include "memory.h"
 #include "sdrc.h"
 
-unsigned long omap2_sdrc_base;
-unsigned long omap2_sms_base;
+void __iomem *omap2_sdrc_base;
+void __iomem *omap2_sms_base;
 
 static struct memory_timings mem_timings;
 static u32 curr_perf_level = CORE_CLK_SRC_DPLL_X2;
@@ -154,6 +155,12 @@ void omap2_init_memory_params(u32 force_lock_to_unlock_mode)
        mem_timings.slow_dll_ctrl |= ((1 << 1) | (3 << 8));
 }
 
+void __init omap2_set_globals_memory(struct omap_globals *omap2_globals)
+{
+       omap2_sdrc_base = omap2_globals->sdrc;
+       omap2_sms_base = omap2_globals->sms;
+}
+
 /* turn on smart idle modes for SDRAM scheduler and controller */
 void __init omap2_init_memory(void)
 {
index 9307700..8f98b20 100644 (file)
@@ -236,7 +236,7 @@ void __init_or_module omap2_cfg_debug(const struct pin_config *cfg, u8 reg)
        warn = (orig != reg);
        if (debug || warn)
                printk(KERN_WARNING
-                       "MUX: setup %s (0x%08x): 0x%02x -> 0x%02x\n",
+                       "MUX: setup %s (0x%p): 0x%04x -> 0x%04x\n",
                        cfg->name, omap_ctrl_base_get() + cfg->mux_reg,
                        orig, reg);
 }
index aad781d..d6c9de8 100644 (file)
@@ -57,13 +57,6 @@ void omap2_pm_idle(void)
                return;
        }
 
-       /*
-        * Since an interrupt may set up a timer, we don't want to
-        * reprogram the hardware timer with interrupts enabled.
-        * Re-enable interrupts only after returning from idle.
-        */
-       timer_dyn_reprogram();
-
        omap2_sram_idle();
        local_fiq_enable();
        local_irq_enable();
index cacb340..54c32f4 100644 (file)
@@ -32,6 +32,7 @@
 
 
 /* Chip-specific module offsets */
+#define OMAP24XX_GR_MOD                                        OCP_MOD
 #define OMAP24XX_DSP_MOD                               0x800
 
 #define OMAP2430_MDM_MOD                               0xc00
index b12f423..fd92a80 100644 (file)
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/clk.h>
+#include <linux/io.h>
 
-#include <asm/io.h>
+#include <asm/arch/common.h>
+#include <asm/arch/prcm.h>
 
+#include "clock.h"
 #include "prm.h"
 #include "prm-regbits-24xx.h"
 
-extern void omap2_clk_prepare_for_reboot(void);
+static void __iomem *prm_base;
+static void __iomem *cm_base;
 
 u32 omap_prcm_get_reset_sources(void)
 {
+       /* XXX This presumably needs modification for 34XX */
        return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f;
 }
 EXPORT_SYMBOL(omap_prcm_get_reset_sources);
@@ -33,11 +38,90 @@ EXPORT_SYMBOL(omap_prcm_get_reset_sources);
 /* Resets clock rates and reboots the system. Only called from system.h */
 void omap_prcm_arch_reset(char mode)
 {
-       u32 wkup;
+       s16 prcm_offs;
        omap2_clk_prepare_for_reboot();
 
-       if (cpu_is_omap24xx()) {
-               wkup = prm_read_mod_reg(WKUP_MOD, RM_RSTCTRL) | OMAP_RST_DPLL3;
-               prm_write_mod_reg(wkup, WKUP_MOD, RM_RSTCTRL);
-       }
+       if (cpu_is_omap24xx())
+               prcm_offs = WKUP_MOD;
+       else if (cpu_is_omap34xx())
+               prcm_offs = OMAP3430_GR_MOD;
+       else
+               WARN_ON(1);
+
+       prm_set_mod_reg_bits(OMAP_RST_DPLL3, prcm_offs, RM_RSTCTRL);
+}
+
+static inline u32 __omap_prcm_read(void __iomem *base, s16 module, u16 reg)
+{
+       BUG_ON(!base);
+       return __raw_readl(base + module + reg);
+}
+
+static inline void __omap_prcm_write(u32 value, void __iomem *base,
+                                               s16 module, u16 reg)
+{
+       BUG_ON(!base);
+       __raw_writel(value, base + module + reg);
+}
+
+/* Read a register in a PRM module */
+u32 prm_read_mod_reg(s16 module, u16 idx)
+{
+       return __omap_prcm_read(prm_base, module, idx);
+}
+EXPORT_SYMBOL(prm_read_mod_reg);
+
+/* Write into a register in a PRM module */
+void prm_write_mod_reg(u32 val, s16 module, u16 idx)
+{
+       __omap_prcm_write(val, prm_base, module, idx);
+}
+EXPORT_SYMBOL(prm_write_mod_reg);
+
+/* Read-modify-write a register in a PRM module. Caller must lock */
+u32 prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
+{
+       u32 v;
+
+       v = prm_read_mod_reg(module, idx);
+       v &= ~mask;
+       v |= bits;
+       prm_write_mod_reg(v, module, idx);
+
+       return v;
+}
+EXPORT_SYMBOL(prm_rmw_mod_reg_bits);
+
+/* Read a register in a CM module */
+u32 cm_read_mod_reg(s16 module, u16 idx)
+{
+       return __omap_prcm_read(cm_base, module, idx);
+}
+EXPORT_SYMBOL(cm_read_mod_reg);
+
+/* Write into a register in a CM module */
+void cm_write_mod_reg(u32 val, s16 module, u16 idx)
+{
+       __omap_prcm_write(val, cm_base, module, idx);
+}
+EXPORT_SYMBOL(cm_write_mod_reg);
+
+/* Read-modify-write a register in a CM module. Caller must lock */
+u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
+{
+       u32 v;
+
+       v = cm_read_mod_reg(module, idx);
+       v &= ~mask;
+       v |= bits;
+       cm_write_mod_reg(v, module, idx);
+
+       return v;
+}
+EXPORT_SYMBOL(cm_rmw_mod_reg_bits);
+
+void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
+{
+       prm_base = omap2_globals->prm;
+       cm_base = omap2_globals->cm;
 }
index 618f811..bbf41fc 100644 (file)
  *
  */
 
+/* Global 24xx registers in GR_MOD (Same as OCP_MOD for 24xx) */
+#define OMAP24XX_PRCM_VOLTCTRL_OFFSET          0x0050
+#define OMAP24XX_PRCM_CLKCFG_CTRL_OFFSET       0x0080
+
+/* 242x GR_MOD registers, use these only for assembly code */
+#define OMAP242X_PRCM_VOLTCTRL         OMAP2420_PRM_REGADDR(OMAP24XX_GR_MOD,   \
+                                               OMAP24XX_PRCM_VOLTCTRL_OFFSET)
+#define OMAP242X_PRCM_CLKCFG_CTRL      OMAP2420_PRM_REGADDR(OMAP24XX_GR_MOD,   \
+                                               OMAP24XX_PRCM_CLKCFG_CTRL_OFFSET)
+
+/* 243x GR_MOD registers, use these only for assembly code */
+#define OMAP243X_PRCM_VOLTCTRL         OMAP2430_PRM_REGADDR(OMAP24XX_GR_MOD,   \
+                                               OMAP24XX_PRCM_VOLTCTRL_OFFSET)
+#define OMAP243X_PRCM_CLKCFG_CTRL      OMAP2430_PRM_REGADDR(OMAP24XX_GR_MOD,   \
+                                               OMAP24XX_PRCM_CLKCFG_CTRL_OFFSET)
+
+/* These will disappear */
 #define OMAP24XX_PRCM_REVISION         OMAP_PRM_REGADDR(OCP_MOD, 0x0000)
 #define OMAP24XX_PRCM_SYSCONFIG                OMAP_PRM_REGADDR(OCP_MOD, 0x0010)
 
 #define OMAP24XX_PRCM_IRQSTATUS_MPU    OMAP_PRM_REGADDR(OCP_MOD, 0x0018)
 #define OMAP24XX_PRCM_IRQENABLE_MPU    OMAP_PRM_REGADDR(OCP_MOD, 0x001c)
 
-#define OMAP24XX_PRCM_VOLTCTRL         OMAP_PRM_REGADDR(OCP_MOD, 0x0050)
 #define OMAP24XX_PRCM_VOLTST           OMAP_PRM_REGADDR(OCP_MOD, 0x0054)
 #define OMAP24XX_PRCM_CLKSRC_CTRL      OMAP_PRM_REGADDR(OCP_MOD, 0x0060)
 #define OMAP24XX_PRCM_CLKOUT_CTRL      OMAP_PRM_REGADDR(OCP_MOD, 0x0070)
 #ifndef __ASSEMBLER__
 
 /* Power/reset management domain register get/set */
+extern u32 prm_read_mod_reg(s16 module, u16 idx);
+extern void prm_write_mod_reg(u32 val, s16 module, u16 idx);
+extern u32 prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx);
 
-static inline void prm_write_mod_reg(u32 val, s16 module, s16 idx)
+/* Read-modify-write bits in a PRM register (by domain) */
+static inline u32 prm_set_mod_reg_bits(u32 bits, s16 module, s16 idx)
 {
-       __raw_writel(val, OMAP_PRM_REGADDR(module, idx));
+       return prm_rmw_mod_reg_bits(bits, bits, module, idx);
 }
 
-static inline u32 prm_read_mod_reg(s16 module, s16 idx)
+static inline u32 prm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx)
 {
-       return __raw_readl(OMAP_PRM_REGADDR(module, idx));
+       return prm_rmw_mod_reg_bits(bits, 0x0, module, idx);
 }
 
 #endif
index d7f23bc..1b1fe4f 100644 (file)
 #include <asm/arch/sdrc.h>
 
 #ifndef __ASSEMBLER__
-extern unsigned long omap2_sdrc_base;
-extern unsigned long omap2_sms_base;
+extern void __iomem *omap2_sdrc_base;
+extern void __iomem *omap2_sms_base;
 
-#define OMAP_SDRC_REGADDR(reg)                                         \
-               (void __iomem *)IO_ADDRESS(omap2_sdrc_base + (reg))
-#define OMAP_SMS_REGADDR(reg)                                          \
-               (void __iomem *)IO_ADDRESS(omap2_sms_base + (reg))
+#define OMAP_SDRC_REGADDR(reg)                 (omap2_sdrc_base + (reg))
+#define OMAP_SMS_REGADDR(reg)                  (omap2_sms_base + (reg))
 
 /* SDRC global register get/set */
 
diff --git a/arch/arm/mach-omap2/sram-fn.S b/arch/arm/mach-omap2/sram-fn.S
deleted file mode 100644 (file)
index 4a9e491..0000000
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * linux/arch/arm/mach-omap2/sram-fn.S
- *
- * Omap2 specific functions that need to be run in internal SRAM
- *
- * (C) Copyright 2004
- * Texas Instruments, <www.ti.com>
- * Richard Woodruff <r-woodruff2@ti.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-#include <linux/linkage.h>
-#include <asm/assembler.h>
-#include <asm/arch/io.h>
-#include <asm/hardware.h>
-
-#include "sdrc.h"
-#include "prm.h"
-#include "cm.h"
-
-#define TIMER_32KSYNCT_CR_V    IO_ADDRESS(OMAP2420_32KSYNCT_BASE + 0x010)
-
-       .text
-
-ENTRY(sram_ddr_init)
-       stmfd   sp!, {r0 - r12, lr}     @ save registers on stack
-
-       mov     r12, r2                 @ capture CS1 vs CS0
-       mov     r8, r3                  @ capture force parameter
-
-       /* frequency shift down */
-       ldr     r2, cm_clksel2_pll      @ get address of dpllout reg
-       mov     r3, #0x1                @ value for 1x operation
-       str     r3, [r2]                @ go to L1-freq operation
-
-       /* voltage shift down */
-       mov r9, #0x1                    @ set up for L1 voltage call
-       bl voltage_shift                @ go drop voltage
-
-       /* dll lock mode */
-       ldr     r11, sdrc_dlla_ctrl     @ addr of dlla ctrl
-       ldr     r10, [r11]              @ get current val
-       cmp     r12, #0x1               @ cs1 base (2422 es2.05/1)
-       addeq   r11, r11, #0x8          @ if cs1 base, move to DLLB
-       mvn     r9, #0x4                @ mask to get clear bit2
-       and     r10, r10, r9            @ clear bit2 for lock mode.
-       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
-       orr     r10, r10, #0x2          @ 90 degree phase for all below 133Mhz
-       str     r10, [r11]              @ commit to DLLA_CTRL
-       bl      i_dll_wait              @ wait for dll to lock
-
-       /* get dll value */
-       add     r11, r11, #0x4          @ get addr of status reg
-       ldr     r10, [r11]              @ get locked value
-
-       /* voltage shift up */
-       mov r9, #0x0                    @ shift back to L0-voltage
-       bl voltage_shift                @ go raise voltage
-
-       /* frequency shift up */
-       mov     r3, #0x2                @ value for 2x operation
-       str     r3, [r2]                @ go to L0-freq operation
-
-       /* reset entry mode for dllctrl */
-       sub     r11, r11, #0x4          @ move from status to ctrl
-       cmp     r12, #0x1               @ normalize if cs1 based
-       subeq   r11, r11, #0x8          @ possibly back to DLLA
-       cmp     r8, #0x1                @ if forced unlock exit
-       orreq   r1, r1, #0x4            @ make sure exit with unlocked value
-       str     r1, [r11]               @ restore DLLA_CTRL high value
-       add     r11, r11, #0x8          @ move to DLLB_CTRL addr
-       str     r1, [r11]               @ set value DLLB_CTRL
-       bl      i_dll_wait              @ wait for possible lock
-
-       /* set up for return, DDR should be good */
-       str r10, [r0]                   @ write dll_status and return counter
-       ldmfd   sp!, {r0 - r12, pc}     @ restore regs and return
-
-       /* ensure the DLL has relocked */
-i_dll_wait:
-       mov     r4, #0x800              @ delay DLL relock, min 0x400 L3 clocks
-i_dll_delay:
-       subs    r4, r4, #0x1
-       bne     i_dll_delay
-       mov     pc, lr
-
-       /*
-        * shift up or down voltage, use R9 as input to tell level.
-        * wait for it to finish, use 32k sync counter, 1tick=31uS.
-        */
-voltage_shift:
-       ldr     r4, prcm_voltctrl       @ get addr of volt ctrl.
-       ldr     r5, [r4]                @ get value.
-       ldr     r6, prcm_mask_val       @ get value of mask
-       and     r5, r5, r6              @ apply mask to clear bits
-       orr     r5, r5, r9              @ bulld value for L0/L1-volt operation.
-       str     r5, [r4]                @ set up for change.
-       mov     r3, #0x4000             @ get val for force
-       orr     r5, r5, r3              @ build value for force
-       str     r5, [r4]                @ Force transition to L1
-
-       ldr     r3, timer_32ksynct_cr   @ get addr of counter
-       ldr     r5, [r3]                @ get value
-       add     r5, r5, #0x3            @ give it at most 93uS
-volt_delay:
-       ldr     r7, [r3]                @ get timer value
-       cmp     r5, r7                  @ time up?
-       bhi     volt_delay              @ not yet->branch
-       mov     pc, lr                  @ back to caller.
-
-/* relative load constants */
-cm_clksel2_pll:
-       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
-sdrc_dlla_ctrl:
-       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
-prcm_voltctrl:
-       .word OMAP2420_PRM_REGADDR(OCP_MOD, 0x50)
-prcm_mask_val:
-       .word 0xFFFF3FFC
-timer_32ksynct_cr:
-       .word TIMER_32KSYNCT_CR_V
-ENTRY(sram_ddr_init_sz)
-       .word   . - sram_ddr_init
-
-/*
- * Reprograms memory timings.
- * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR]
- * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0
- */
-ENTRY(sram_reprogram_sdrc)
-       stmfd   sp!, {r0 - r10, lr}     @ save registers on stack
-       mov     r3, #0x0                @ clear for mrc call
-       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier, finish ARM SDR/DDR
-       nop
-       nop
-       ldr     r6, ddr_sdrc_rfr_ctrl   @ get addr of refresh reg
-       ldr     r5, [r6]                @ get value
-       mov     r5, r5, lsr #8          @ isolate rfr field and drop burst
-
-       cmp     r0, #0x1                @ going to half speed?
-       movne   r9, #0x0                @ if up set flag up for pre up, hi volt
-
-       blne    voltage_shift_c         @ adjust voltage
-
-       cmp     r0, #0x1                @ going to half speed (post branch link)
-       moveq   r5, r5, lsr #1          @ divide by 2 if to half
-       movne   r5, r5, lsl #1          @ mult by 2 if to full
-       mov     r5, r5, lsl #8          @ put rfr field back into place
-       add     r5, r5, #0x1            @ turn on burst of 1
-       ldr     r4, ddr_cm_clksel2_pll  @ get address of out reg
-       ldr     r3, [r4]                @ get curr value
-       orr     r3, r3, #0x3
-       bic     r3, r3, #0x3            @ clear lower bits
-       orr     r3, r3, r0              @ new state value
-       str     r3, [r4]                @ set new state (pll/x, x=1 or 2)
-       nop
-       nop
-
-       moveq   r9, #0x1                @ if speed down, post down, drop volt
-       bleq    voltage_shift_c
-
-       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier
-       str     r5, [r6]                @ set new RFR_1 value
-       add     r6, r6, #0x30           @ get RFR_2 addr
-       str     r5, [r6]                @ set RFR_2
-       nop
-       cmp     r2, #0x1                @ (SDR or DDR) do we need to adjust DLL
-       bne     freq_out                @ leave if SDR, no DLL function
-
-       /* With DDR, we need to take care of the DLL for the frequency change */
-       ldr     r2, ddr_sdrc_dlla_ctrl  @ addr of dlla ctrl
-       str     r1, [r2]                @ write out new SDRC_DLLA_CTRL
-       add     r2, r2, #0x8            @ addr to SDRC_DLLB_CTRL
-       str     r1, [r2]                @ commit to SDRC_DLLB_CTRL
-       mov     r1, #0x2000             @ wait DLL relock, min 0x400 L3 clocks
-dll_wait:
-       subs    r1, r1, #0x1
-       bne     dll_wait
-freq_out:
-       ldmfd   sp!, {r0 - r10, pc}     @ restore regs and return
-
-    /*
-     * shift up or down voltage, use R9 as input to tell level.
-     * wait for it to finish, use 32k sync counter, 1tick=31uS.
-     */
-voltage_shift_c:
-       ldr     r10, ddr_prcm_voltctrl  @ get addr of volt ctrl
-       ldr     r8, [r10]               @ get value
-       ldr     r7, ddr_prcm_mask_val   @ get value of mask
-       and     r8, r8, r7              @ apply mask to clear bits
-       orr     r8, r8, r9              @ bulld value for L0/L1-volt operation.
-       str     r8, [r10]               @ set up for change.
-       mov     r7, #0x4000             @ get val for force
-       orr     r8, r8, r7              @ build value for force
-       str     r8, [r10]               @ Force transition to L1
-
-       ldr     r10, ddr_timer_32ksynct @ get addr of counter
-       ldr     r8, [r10]               @ get value
-       add     r8, r8, #0x2            @ give it at most 62uS (min 31+)
-volt_delay_c:
-       ldr     r7, [r10]               @ get timer value
-       cmp     r8, r7                  @ time up?
-       bhi     volt_delay_c            @ not yet->branch
-       mov     pc, lr                  @ back to caller
-
-ddr_cm_clksel2_pll:
-       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
-ddr_sdrc_dlla_ctrl:
-       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
-ddr_sdrc_rfr_ctrl:
-       .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
-ddr_prcm_voltctrl:
-       .word OMAP2420_PRM_REGADDR(OCP_MOD, 0x50)
-ddr_prcm_mask_val:
-       .word 0xFFFF3FFC
-ddr_timer_32ksynct:
-       .word TIMER_32KSYNCT_CR_V
-
-ENTRY(sram_reprogram_sdrc_sz)
-       .word   . - sram_reprogram_sdrc
-
-/*
- * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode.
- */
-ENTRY(sram_set_prcm)
-       stmfd   sp!, {r0-r12, lr}       @ regs to stack
-       adr     r4, pbegin              @ addr of preload start
-       adr     r8, pend                @ addr of preload end
-       mcrr    p15, 1, r8, r4, c12     @ preload into icache
-pbegin:
-       /* move into fast relock bypass */
-       ldr     r8, pll_ctl             @ get addr
-       ldr     r5, [r8]                @ get val
-       mvn     r6, #0x3                @ clear mask
-       and     r5, r5, r6              @ clear field
-       orr     r7, r5, #0x2            @ fast relock val
-       str     r7, [r8]                @ go to fast relock
-       ldr     r4, pll_stat            @ addr of stat
-block:
-       /* wait for bypass */
-       ldr     r8, [r4]                @ stat value
-       and     r8, r8, #0x3            @ mask for stat
-       cmp     r8, #0x1                @ there yet
-       bne     block                   @ loop if not
-
-       /* set new dpll dividers _after_ in bypass */
-       ldr     r4, pll_div             @ get addr
-       str     r0, [r4]                @ set dpll ctrl val
-
-       ldr     r4, set_config          @ get addr
-       mov     r8, #1                  @ valid cfg msk
-       str     r8, [r4]                @ make dividers take
-
-       mov     r4, #100                @ dead spin a bit
-wait_a_bit:
-       subs    r4, r4, #1              @ dec loop
-       bne     wait_a_bit              @ delay done?
-
-       /* check if staying in bypass */
-       cmp     r2, #0x1                @ stay in bypass?
-       beq     pend                    @ jump over dpll relock
-
-       /* relock DPLL with new vals */
-       ldr     r5, pll_stat            @ get addr
-       ldr     r4, pll_ctl             @ get addr
-       orr     r8, r7, #0x3            @ val for lock dpll
-       str     r8, [r4]                @ set val
-       mov     r0, #1000               @ dead spin a bit
-wait_more:
-       subs    r0, r0, #1              @ dec loop
-       bne     wait_more               @ delay done?
-wait_lock:
-       ldr     r8, [r5]                @ get lock val
-       and     r8, r8, #3              @ isolate field
-       cmp     r8, #2                  @ locked?
-       bne     wait_lock               @ wait if not
-pend:
-       /* update memory timings & briefly lock dll */
-       ldr     r4, sdrc_rfr            @ get addr
-       str     r1, [r4]                @ update refresh timing
-       ldr     r11, dlla_ctrl          @ get addr of DLLA ctrl
-       ldr     r10, [r11]              @ get current val
-       mvn     r9, #0x4                @ mask to get clear bit2
-       and     r10, r10, r9            @ clear bit2 for lock mode
-       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
-       str     r10, [r11]              @ commit to DLLA_CTRL
-       add     r11, r11, #0x8          @ move to dllb
-       str     r10, [r11]              @ hit DLLB also
-
-       mov     r4, #0x800              @ relock time (min 0x400 L3 clocks)
-wait_dll_lock:
-       subs    r4, r4, #0x1
-       bne     wait_dll_lock
-       nop
-       ldmfd   sp!, {r0-r12, pc}       @ restore regs and return
-
-set_config:
-       .word OMAP2420_PRM_REGADDR(OCP_MOD, 0x80)
-pll_ctl:
-       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_FCLKEN1)
-pll_stat:
-       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_IDLEST1)
-pll_div:
-       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL)
-sdrc_rfr:
-       .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
-dlla_ctrl:
-       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
-
-ENTRY(sram_set_prcm_sz)
-       .word   . - sram_set_prcm
diff --git a/arch/arm/mach-omap2/sram242x.S b/arch/arm/mach-omap2/sram242x.S
new file mode 100644 (file)
index 0000000..4c27451
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * linux/arch/arm/mach-omap2/sram242x.S
+ *
+ * Omap2 specific functions that need to be run in internal SRAM
+ *
+ * (C) Copyright 2004
+ * Texas Instruments, <www.ti.com>
+ * Richard Woodruff <r-woodruff2@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/arch/io.h>
+#include <asm/hardware.h>
+
+#include "prm.h"
+#include "cm.h"
+#include "sdrc.h"
+
+       .text
+
+ENTRY(omap242x_sram_ddr_init)
+       stmfd   sp!, {r0 - r12, lr}     @ save registers on stack
+
+       mov     r12, r2                 @ capture CS1 vs CS0
+       mov     r8, r3                  @ capture force parameter
+
+       /* frequency shift down */
+       ldr     r2, omap242x_sdi_cm_clksel2_pll @ get address of dpllout reg
+       mov     r3, #0x1                @ value for 1x operation
+       str     r3, [r2]                @ go to L1-freq operation
+
+       /* voltage shift down */
+       mov r9, #0x1                    @ set up for L1 voltage call
+       bl voltage_shift                @ go drop voltage
+
+       /* dll lock mode */
+       ldr     r11, omap242x_sdi_sdrc_dlla_ctrl        @ addr of dlla ctrl
+       ldr     r10, [r11]              @ get current val
+       cmp     r12, #0x1               @ cs1 base (2422 es2.05/1)
+       addeq   r11, r11, #0x8          @ if cs1 base, move to DLLB
+       mvn     r9, #0x4                @ mask to get clear bit2
+       and     r10, r10, r9            @ clear bit2 for lock mode.
+       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
+       orr     r10, r10, #0x2          @ 90 degree phase for all below 133Mhz
+       str     r10, [r11]              @ commit to DLLA_CTRL
+       bl      i_dll_wait              @ wait for dll to lock
+
+       /* get dll value */
+       add     r11, r11, #0x4          @ get addr of status reg
+       ldr     r10, [r11]              @ get locked value
+
+       /* voltage shift up */
+       mov r9, #0x0                    @ shift back to L0-voltage
+       bl voltage_shift                @ go raise voltage
+
+       /* frequency shift up */
+       mov     r3, #0x2                @ value for 2x operation
+       str     r3, [r2]                @ go to L0-freq operation
+
+       /* reset entry mode for dllctrl */
+       sub     r11, r11, #0x4          @ move from status to ctrl
+       cmp     r12, #0x1               @ normalize if cs1 based
+       subeq   r11, r11, #0x8          @ possibly back to DLLA
+       cmp     r8, #0x1                @ if forced unlock exit
+       orreq   r1, r1, #0x4            @ make sure exit with unlocked value
+       str     r1, [r11]               @ restore DLLA_CTRL high value
+       add     r11, r11, #0x8          @ move to DLLB_CTRL addr
+       str     r1, [r11]               @ set value DLLB_CTRL
+       bl      i_dll_wait              @ wait for possible lock
+
+       /* set up for return, DDR should be good */
+       str r10, [r0]                   @ write dll_status and return counter
+       ldmfd   sp!, {r0 - r12, pc}     @ restore regs and return
+
+       /* ensure the DLL has relocked */
+i_dll_wait:
+       mov     r4, #0x800              @ delay DLL relock, min 0x400 L3 clocks
+i_dll_delay:
+       subs    r4, r4, #0x1
+       bne     i_dll_delay
+       mov     pc, lr
+
+       /*
+        * shift up or down voltage, use R9 as input to tell level.
+        * wait for it to finish, use 32k sync counter, 1tick=31uS.
+        */
+voltage_shift:
+       ldr     r4, omap242x_sdi_prcm_voltctrl  @ get addr of volt ctrl.
+       ldr     r5, [r4]                @ get value.
+       ldr     r6, prcm_mask_val       @ get value of mask
+       and     r5, r5, r6              @ apply mask to clear bits
+       orr     r5, r5, r9              @ bulld value for L0/L1-volt operation.
+       str     r5, [r4]                @ set up for change.
+       mov     r3, #0x4000             @ get val for force
+       orr     r5, r5, r3              @ build value for force
+       str     r5, [r4]                @ Force transition to L1
+
+       ldr     r3, omap242x_sdi_timer_32ksynct_cr      @ get addr of counter
+       ldr     r5, [r3]                @ get value
+       add     r5, r5, #0x3            @ give it at most 93uS
+volt_delay:
+       ldr     r7, [r3]                @ get timer value
+       cmp     r5, r7                  @ time up?
+       bhi     volt_delay              @ not yet->branch
+       mov     pc, lr                  @ back to caller.
+
+omap242x_sdi_cm_clksel2_pll:
+       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
+omap242x_sdi_sdrc_dlla_ctrl:
+       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+omap242x_sdi_prcm_voltctrl:
+       .word OMAP242X_PRCM_VOLTCTRL
+prcm_mask_val:
+       .word 0xFFFF3FFC
+omap242x_sdi_timer_32ksynct_cr:
+       .word IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010)
+ENTRY(omap242x_sram_ddr_init_sz)
+       .word   . - omap242x_sram_ddr_init
+
+/*
+ * Reprograms memory timings.
+ * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR]
+ * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0
+ */
+ENTRY(omap242x_sram_reprogram_sdrc)
+       stmfd   sp!, {r0 - r10, lr}     @ save registers on stack
+       mov     r3, #0x0                @ clear for mrc call
+       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier, finish ARM SDR/DDR
+       nop
+       nop
+       ldr     r6, omap242x_srs_sdrc_rfr_ctrl  @ get addr of refresh reg
+       ldr     r5, [r6]                @ get value
+       mov     r5, r5, lsr #8          @ isolate rfr field and drop burst
+
+       cmp     r0, #0x1                @ going to half speed?
+       movne   r9, #0x0                @ if up set flag up for pre up, hi volt
+
+       blne    voltage_shift_c         @ adjust voltage
+
+       cmp     r0, #0x1                @ going to half speed (post branch link)
+       moveq   r5, r5, lsr #1          @ divide by 2 if to half
+       movne   r5, r5, lsl #1          @ mult by 2 if to full
+       mov     r5, r5, lsl #8          @ put rfr field back into place
+       add     r5, r5, #0x1            @ turn on burst of 1
+       ldr     r4, omap242x_srs_cm_clksel2_pll @ get address of out reg
+       ldr     r3, [r4]                @ get curr value
+       orr     r3, r3, #0x3
+       bic     r3, r3, #0x3            @ clear lower bits
+       orr     r3, r3, r0              @ new state value
+       str     r3, [r4]                @ set new state (pll/x, x=1 or 2)
+       nop
+       nop
+
+       moveq   r9, #0x1                @ if speed down, post down, drop volt
+       bleq    voltage_shift_c
+
+       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier
+       str     r5, [r6]                @ set new RFR_1 value
+       add     r6, r6, #0x30           @ get RFR_2 addr
+       str     r5, [r6]                @ set RFR_2
+       nop
+       cmp     r2, #0x1                @ (SDR or DDR) do we need to adjust DLL
+       bne     freq_out                @ leave if SDR, no DLL function
+
+       /* With DDR, we need to take care of the DLL for the frequency change */
+       ldr     r2, omap242x_srs_sdrc_dlla_ctrl @ addr of dlla ctrl
+       str     r1, [r2]                @ write out new SDRC_DLLA_CTRL
+       add     r2, r2, #0x8            @ addr to SDRC_DLLB_CTRL
+       str     r1, [r2]                @ commit to SDRC_DLLB_CTRL
+       mov     r1, #0x2000             @ wait DLL relock, min 0x400 L3 clocks
+dll_wait:
+       subs    r1, r1, #0x1
+       bne     dll_wait
+freq_out:
+       ldmfd   sp!, {r0 - r10, pc}     @ restore regs and return
+
+    /*
+     * shift up or down voltage, use R9 as input to tell level.
+     * wait for it to finish, use 32k sync counter, 1tick=31uS.
+     */
+voltage_shift_c:
+       ldr     r10, omap242x_srs_prcm_voltctrl @ get addr of volt ctrl
+       ldr     r8, [r10]               @ get value
+       ldr     r7, ddr_prcm_mask_val   @ get value of mask
+       and     r8, r8, r7              @ apply mask to clear bits
+       orr     r8, r8, r9              @ bulld value for L0/L1-volt operation.
+       str     r8, [r10]               @ set up for change.
+       mov     r7, #0x4000             @ get val for force
+       orr     r8, r8, r7              @ build value for force
+       str     r8, [r10]               @ Force transition to L1
+
+       ldr     r10, omap242x_srs_timer_32ksynct        @ get addr of counter
+       ldr     r8, [r10]               @ get value
+       add     r8, r8, #0x2            @ give it at most 62uS (min 31+)
+volt_delay_c:
+       ldr     r7, [r10]               @ get timer value
+       cmp     r8, r7                  @ time up?
+       bhi     volt_delay_c            @ not yet->branch
+       mov     pc, lr                  @ back to caller
+
+omap242x_srs_cm_clksel2_pll:
+       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
+omap242x_srs_sdrc_dlla_ctrl:
+       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+omap242x_srs_sdrc_rfr_ctrl:
+       .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
+omap242x_srs_prcm_voltctrl:
+       .word OMAP242X_PRCM_VOLTCTRL
+ddr_prcm_mask_val:
+       .word 0xFFFF3FFC
+omap242x_srs_timer_32ksynct:
+       .word IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010)
+
+ENTRY(omap242x_sram_reprogram_sdrc_sz)
+       .word   . - omap242x_sram_reprogram_sdrc
+
+/*
+ * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode.
+ */
+ENTRY(omap242x_sram_set_prcm)
+       stmfd   sp!, {r0-r12, lr}       @ regs to stack
+       adr     r4, pbegin              @ addr of preload start
+       adr     r8, pend                @ addr of preload end
+       mcrr    p15, 1, r8, r4, c12     @ preload into icache
+pbegin:
+       /* move into fast relock bypass */
+       ldr     r8, omap242x_ssp_pll_ctl        @ get addr
+       ldr     r5, [r8]                @ get val
+       mvn     r6, #0x3                @ clear mask
+       and     r5, r5, r6              @ clear field
+       orr     r7, r5, #0x2            @ fast relock val
+       str     r7, [r8]                @ go to fast relock
+       ldr     r4, omap242x_ssp_pll_stat       @ addr of stat
+block:
+       /* wait for bypass */
+       ldr     r8, [r4]                @ stat value
+       and     r8, r8, #0x3            @ mask for stat
+       cmp     r8, #0x1                @ there yet
+       bne     block                   @ loop if not
+
+       /* set new dpll dividers _after_ in bypass */
+       ldr     r4, omap242x_ssp_pll_div        @ get addr
+       str     r0, [r4]                @ set dpll ctrl val
+
+       ldr     r4, omap242x_ssp_set_config     @ get addr
+       mov     r8, #1                  @ valid cfg msk
+       str     r8, [r4]                @ make dividers take
+
+       mov     r4, #100                @ dead spin a bit
+wait_a_bit:
+       subs    r4, r4, #1              @ dec loop
+       bne     wait_a_bit              @ delay done?
+
+       /* check if staying in bypass */
+       cmp     r2, #0x1                @ stay in bypass?
+       beq     pend                    @ jump over dpll relock
+
+       /* relock DPLL with new vals */
+       ldr     r5, omap242x_ssp_pll_stat       @ get addr
+       ldr     r4, omap242x_ssp_pll_ctl        @ get addr
+       orr     r8, r7, #0x3            @ val for lock dpll
+       str     r8, [r4]                @ set val
+       mov     r0, #1000               @ dead spin a bit
+wait_more:
+       subs    r0, r0, #1              @ dec loop
+       bne     wait_more               @ delay done?
+wait_lock:
+       ldr     r8, [r5]                @ get lock val
+       and     r8, r8, #3              @ isolate field
+       cmp     r8, #2                  @ locked?
+       bne     wait_lock               @ wait if not
+pend:
+       /* update memory timings & briefly lock dll */
+       ldr     r4, omap242x_ssp_sdrc_rfr       @ get addr
+       str     r1, [r4]                @ update refresh timing
+       ldr     r11, omap242x_ssp_dlla_ctrl     @ get addr of DLLA ctrl
+       ldr     r10, [r11]              @ get current val
+       mvn     r9, #0x4                @ mask to get clear bit2
+       and     r10, r10, r9            @ clear bit2 for lock mode
+       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
+       str     r10, [r11]              @ commit to DLLA_CTRL
+       add     r11, r11, #0x8          @ move to dllb
+       str     r10, [r11]              @ hit DLLB also
+
+       mov     r4, #0x800              @ relock time (min 0x400 L3 clocks)
+wait_dll_lock:
+       subs    r4, r4, #0x1
+       bne     wait_dll_lock
+       nop
+       ldmfd   sp!, {r0-r12, pc}       @ restore regs and return
+
+omap242x_ssp_set_config:
+       .word OMAP242X_PRCM_CLKCFG_CTRL
+omap242x_ssp_pll_ctl:
+       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKEN)
+omap242x_ssp_pll_stat:
+       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_IDLEST)
+omap242x_ssp_pll_div:
+       .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
+omap242x_ssp_sdrc_rfr:
+       .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
+omap242x_ssp_dlla_ctrl:
+       .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+
+ENTRY(omap242x_sram_set_prcm_sz)
+       .word   . - omap242x_sram_set_prcm
diff --git a/arch/arm/mach-omap2/sram243x.S b/arch/arm/mach-omap2/sram243x.S
new file mode 100644 (file)
index 0000000..a3fa48d
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * linux/arch/arm/mach-omap2/sram243x.S
+ *
+ * Omap2 specific functions that need to be run in internal SRAM
+ *
+ * (C) Copyright 2004
+ * Texas Instruments, <www.ti.com>
+ * Richard Woodruff <r-woodruff2@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/arch/io.h>
+#include <asm/hardware.h>
+
+#include "prm.h"
+#include "cm.h"
+#include "sdrc.h"
+
+       .text
+
+ENTRY(omap243x_sram_ddr_init)
+       stmfd   sp!, {r0 - r12, lr}     @ save registers on stack
+
+       mov     r12, r2                 @ capture CS1 vs CS0
+       mov     r8, r3                  @ capture force parameter
+
+       /* frequency shift down */
+       ldr     r2, omap243x_sdi_cm_clksel2_pll @ get address of dpllout reg
+       mov     r3, #0x1                @ value for 1x operation
+       str     r3, [r2]                @ go to L1-freq operation
+
+       /* voltage shift down */
+       mov r9, #0x1                    @ set up for L1 voltage call
+       bl voltage_shift                @ go drop voltage
+
+       /* dll lock mode */
+       ldr     r11, omap243x_sdi_sdrc_dlla_ctrl        @ addr of dlla ctrl
+       ldr     r10, [r11]              @ get current val
+       cmp     r12, #0x1               @ cs1 base (2422 es2.05/1)
+       addeq   r11, r11, #0x8          @ if cs1 base, move to DLLB
+       mvn     r9, #0x4                @ mask to get clear bit2
+       and     r10, r10, r9            @ clear bit2 for lock mode.
+       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
+       orr     r10, r10, #0x2          @ 90 degree phase for all below 133Mhz
+       str     r10, [r11]              @ commit to DLLA_CTRL
+       bl      i_dll_wait              @ wait for dll to lock
+
+       /* get dll value */
+       add     r11, r11, #0x4          @ get addr of status reg
+       ldr     r10, [r11]              @ get locked value
+
+       /* voltage shift up */
+       mov r9, #0x0                    @ shift back to L0-voltage
+       bl voltage_shift                @ go raise voltage
+
+       /* frequency shift up */
+       mov     r3, #0x2                @ value for 2x operation
+       str     r3, [r2]                @ go to L0-freq operation
+
+       /* reset entry mode for dllctrl */
+       sub     r11, r11, #0x4          @ move from status to ctrl
+       cmp     r12, #0x1               @ normalize if cs1 based
+       subeq   r11, r11, #0x8          @ possibly back to DLLA
+       cmp     r8, #0x1                @ if forced unlock exit
+       orreq   r1, r1, #0x4            @ make sure exit with unlocked value
+       str     r1, [r11]               @ restore DLLA_CTRL high value
+       add     r11, r11, #0x8          @ move to DLLB_CTRL addr
+       str     r1, [r11]               @ set value DLLB_CTRL
+       bl      i_dll_wait              @ wait for possible lock
+
+       /* set up for return, DDR should be good */
+       str r10, [r0]                   @ write dll_status and return counter
+       ldmfd   sp!, {r0 - r12, pc}     @ restore regs and return
+
+       /* ensure the DLL has relocked */
+i_dll_wait:
+       mov     r4, #0x800              @ delay DLL relock, min 0x400 L3 clocks
+i_dll_delay:
+       subs    r4, r4, #0x1
+       bne     i_dll_delay
+       mov     pc, lr
+
+       /*
+        * shift up or down voltage, use R9 as input to tell level.
+        * wait for it to finish, use 32k sync counter, 1tick=31uS.
+        */
+voltage_shift:
+       ldr     r4, omap243x_sdi_prcm_voltctrl  @ get addr of volt ctrl.
+       ldr     r5, [r4]                @ get value.
+       ldr     r6, prcm_mask_val       @ get value of mask
+       and     r5, r5, r6              @ apply mask to clear bits
+       orr     r5, r5, r9              @ bulld value for L0/L1-volt operation.
+       str     r5, [r4]                @ set up for change.
+       mov     r3, #0x4000             @ get val for force
+       orr     r5, r5, r3              @ build value for force
+       str     r5, [r4]                @ Force transition to L1
+
+       ldr     r3, omap243x_sdi_timer_32ksynct_cr      @ get addr of counter
+       ldr     r5, [r3]                @ get value
+       add     r5, r5, #0x3            @ give it at most 93uS
+volt_delay:
+       ldr     r7, [r3]                @ get timer value
+       cmp     r5, r7                  @ time up?
+       bhi     volt_delay              @ not yet->branch
+       mov     pc, lr                  @ back to caller.
+
+omap243x_sdi_cm_clksel2_pll:
+       .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
+omap243x_sdi_sdrc_dlla_ctrl:
+       .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+omap243x_sdi_prcm_voltctrl:
+       .word OMAP243X_PRCM_VOLTCTRL
+prcm_mask_val:
+       .word 0xFFFF3FFC
+omap243x_sdi_timer_32ksynct_cr:
+       .word IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010)
+ENTRY(omap243x_sram_ddr_init_sz)
+       .word   . - omap243x_sram_ddr_init
+
+/*
+ * Reprograms memory timings.
+ * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR]
+ * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0
+ */
+ENTRY(omap243x_sram_reprogram_sdrc)
+       stmfd   sp!, {r0 - r10, lr}     @ save registers on stack
+       mov     r3, #0x0                @ clear for mrc call
+       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier, finish ARM SDR/DDR
+       nop
+       nop
+       ldr     r6, omap243x_srs_sdrc_rfr_ctrl  @ get addr of refresh reg
+       ldr     r5, [r6]                @ get value
+       mov     r5, r5, lsr #8          @ isolate rfr field and drop burst
+
+       cmp     r0, #0x1                @ going to half speed?
+       movne   r9, #0x0                @ if up set flag up for pre up, hi volt
+
+       blne    voltage_shift_c         @ adjust voltage
+
+       cmp     r0, #0x1                @ going to half speed (post branch link)
+       moveq   r5, r5, lsr #1          @ divide by 2 if to half
+       movne   r5, r5, lsl #1          @ mult by 2 if to full
+       mov     r5, r5, lsl #8          @ put rfr field back into place
+       add     r5, r5, #0x1            @ turn on burst of 1
+       ldr     r4, omap243x_srs_cm_clksel2_pll @ get address of out reg
+       ldr     r3, [r4]                @ get curr value
+       orr     r3, r3, #0x3
+       bic     r3, r3, #0x3            @ clear lower bits
+       orr     r3, r3, r0              @ new state value
+       str     r3, [r4]                @ set new state (pll/x, x=1 or 2)
+       nop
+       nop
+
+       moveq   r9, #0x1                @ if speed down, post down, drop volt
+       bleq    voltage_shift_c
+
+       mcr     p15, 0, r3, c7, c10, 4  @ memory barrier
+       str     r5, [r6]                @ set new RFR_1 value
+       add     r6, r6, #0x30           @ get RFR_2 addr
+       str     r5, [r6]                @ set RFR_2
+       nop
+       cmp     r2, #0x1                @ (SDR or DDR) do we need to adjust DLL
+       bne     freq_out                @ leave if SDR, no DLL function
+
+       /* With DDR, we need to take care of the DLL for the frequency change */
+       ldr     r2, omap243x_srs_sdrc_dlla_ctrl @ addr of dlla ctrl
+       str     r1, [r2]                @ write out new SDRC_DLLA_CTRL
+       add     r2, r2, #0x8            @ addr to SDRC_DLLB_CTRL
+       str     r1, [r2]                @ commit to SDRC_DLLB_CTRL
+       mov     r1, #0x2000             @ wait DLL relock, min 0x400 L3 clocks
+dll_wait:
+       subs    r1, r1, #0x1
+       bne     dll_wait
+freq_out:
+       ldmfd   sp!, {r0 - r10, pc}     @ restore regs and return
+
+    /*
+     * shift up or down voltage, use R9 as input to tell level.
+     * wait for it to finish, use 32k sync counter, 1tick=31uS.
+     */
+voltage_shift_c:
+       ldr     r10, omap243x_srs_prcm_voltctrl @ get addr of volt ctrl
+       ldr     r8, [r10]               @ get value
+       ldr     r7, ddr_prcm_mask_val   @ get value of mask
+       and     r8, r8, r7              @ apply mask to clear bits
+       orr     r8, r8, r9              @ bulld value for L0/L1-volt operation.
+       str     r8, [r10]               @ set up for change.
+       mov     r7, #0x4000             @ get val for force
+       orr     r8, r8, r7              @ build value for force
+       str     r8, [r10]               @ Force transition to L1
+
+       ldr     r10, omap243x_srs_timer_32ksynct        @ get addr of counter
+       ldr     r8, [r10]               @ get value
+       add     r8, r8, #0x2            @ give it at most 62uS (min 31+)
+volt_delay_c:
+       ldr     r7, [r10]               @ get timer value
+       cmp     r8, r7                  @ time up?
+       bhi     volt_delay_c            @ not yet->branch
+       mov     pc, lr                  @ back to caller
+
+omap243x_srs_cm_clksel2_pll:
+       .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
+omap243x_srs_sdrc_dlla_ctrl:
+       .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+omap243x_srs_sdrc_rfr_ctrl:
+       .word OMAP243X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
+omap243x_srs_prcm_voltctrl:
+       .word OMAP243X_PRCM_VOLTCTRL
+ddr_prcm_mask_val:
+       .word 0xFFFF3FFC
+omap243x_srs_timer_32ksynct:
+       .word IO_ADDRESS(OMAP2_32KSYNCT_BASE + 0x010)
+
+ENTRY(omap243x_sram_reprogram_sdrc_sz)
+       .word   . - omap243x_sram_reprogram_sdrc
+
+/*
+ * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode.
+ */
+ENTRY(omap243x_sram_set_prcm)
+       stmfd   sp!, {r0-r12, lr}       @ regs to stack
+       adr     r4, pbegin              @ addr of preload start
+       adr     r8, pend                @ addr of preload end
+       mcrr    p15, 1, r8, r4, c12     @ preload into icache
+pbegin:
+       /* move into fast relock bypass */
+       ldr     r8, omap243x_ssp_pll_ctl        @ get addr
+       ldr     r5, [r8]                @ get val
+       mvn     r6, #0x3                @ clear mask
+       and     r5, r5, r6              @ clear field
+       orr     r7, r5, #0x2            @ fast relock val
+       str     r7, [r8]                @ go to fast relock
+       ldr     r4, omap243x_ssp_pll_stat       @ addr of stat
+block:
+       /* wait for bypass */
+       ldr     r8, [r4]                @ stat value
+       and     r8, r8, #0x3            @ mask for stat
+       cmp     r8, #0x1                @ there yet
+       bne     block                   @ loop if not
+
+       /* set new dpll dividers _after_ in bypass */
+       ldr     r4, omap243x_ssp_pll_div        @ get addr
+       str     r0, [r4]                @ set dpll ctrl val
+
+       ldr     r4, omap243x_ssp_set_config     @ get addr
+       mov     r8, #1                  @ valid cfg msk
+       str     r8, [r4]                @ make dividers take
+
+       mov     r4, #100                @ dead spin a bit
+wait_a_bit:
+       subs    r4, r4, #1              @ dec loop
+       bne     wait_a_bit              @ delay done?
+
+       /* check if staying in bypass */
+       cmp     r2, #0x1                @ stay in bypass?
+       beq     pend                    @ jump over dpll relock
+
+       /* relock DPLL with new vals */
+       ldr     r5, omap243x_ssp_pll_stat       @ get addr
+       ldr     r4, omap243x_ssp_pll_ctl        @ get addr
+       orr     r8, r7, #0x3            @ val for lock dpll
+       str     r8, [r4]                @ set val
+       mov     r0, #1000               @ dead spin a bit
+wait_more:
+       subs    r0, r0, #1              @ dec loop
+       bne     wait_more               @ delay done?
+wait_lock:
+       ldr     r8, [r5]                @ get lock val
+       and     r8, r8, #3              @ isolate field
+       cmp     r8, #2                  @ locked?
+       bne     wait_lock               @ wait if not
+pend:
+       /* update memory timings & briefly lock dll */
+       ldr     r4, omap243x_ssp_sdrc_rfr       @ get addr
+       str     r1, [r4]                @ update refresh timing
+       ldr     r11, omap243x_ssp_dlla_ctrl     @ get addr of DLLA ctrl
+       ldr     r10, [r11]              @ get current val
+       mvn     r9, #0x4                @ mask to get clear bit2
+       and     r10, r10, r9            @ clear bit2 for lock mode
+       orr     r10, r10, #0x8          @ make sure DLL on (es2 bit pos)
+       str     r10, [r11]              @ commit to DLLA_CTRL
+       add     r11, r11, #0x8          @ move to dllb
+       str     r10, [r11]              @ hit DLLB also
+
+       mov     r4, #0x800              @ relock time (min 0x400 L3 clocks)
+wait_dll_lock:
+       subs    r4, r4, #0x1
+       bne     wait_dll_lock
+       nop
+       ldmfd   sp!, {r0-r12, pc}       @ restore regs and return
+
+omap243x_ssp_set_config:
+       .word OMAP243X_PRCM_CLKCFG_CTRL
+omap243x_ssp_pll_ctl:
+       .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKEN)
+omap243x_ssp_pll_stat:
+       .word OMAP2430_CM_REGADDR(PLL_MOD, CM_IDLEST)
+omap243x_ssp_pll_div:
+       .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
+omap243x_ssp_sdrc_rfr:
+       .word OMAP243X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
+omap243x_ssp_dlla_ctrl:
+       .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
+
+ENTRY(omap243x_sram_set_prcm_sz)
+       .word   . - omap243x_sram_set_prcm
index 78d05f2..557603f 100644 (file)
@@ -59,8 +59,7 @@ static struct irqaction omap2_gp_timer_irq = {
 static int omap2_gp_timer_set_next_event(unsigned long cycles,
                                         struct clock_event_device *evt)
 {
-       omap_dm_timer_set_load(gptimer, 0, 0xffffffff - cycles);
-       omap_dm_timer_start(gptimer);
+       omap_dm_timer_set_load_start(gptimer, 0, 0xffffffff - cycles);
 
        return 0;
 }
@@ -77,8 +76,7 @@ static void omap2_gp_timer_set_mode(enum clock_event_mode mode,
                period = clk_get_rate(omap_dm_timer_get_fclk(gptimer)) / HZ;
                period -= 1;
 
-               omap_dm_timer_set_load(gptimer, 1, 0xffffffff - period);
-               omap_dm_timer_start(gptimer);
+               omap_dm_timer_set_load_start(gptimer, 1, 0xffffffff - period);
                break;
        case CLOCK_EVT_MODE_ONESHOT:
                break;
@@ -172,8 +170,7 @@ static void __init omap2_gp_clocksource_init(void)
        tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gpt));
        tick_period = (tick_rate / HZ) - 1;
 
-       omap_dm_timer_set_load(gpt, 1, 0);
-       omap_dm_timer_start(gpt);
+       omap_dm_timer_set_load_start(gpt, 1, 0);
 
        clocksource_gpt.mult =
                clocksource_khz2mult(tick_rate/1000, clocksource_gpt.shift);
index 93debf3..ddcd41b 100644 (file)
@@ -44,6 +44,54 @@ config MACH_LINKSTATION_PRO
          Buffalo Linkstation Pro/Live platform. Both v1 and
          v2 devices are supported.
 
+config MACH_TS409
+       bool "QNAP TS-409"
+       help
+         Say 'Y' here if you want your kernel to support the
+         QNAP TS-409 platform.
+
+config MACH_WRT350N_V2
+       bool "Linksys WRT350N v2"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Linksys WRT350N v2 platform.
+
+config MACH_TS78XX
+       bool "Technologic Systems TS-78xx"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Technologic Systems TS-78xx platform.
+
+config MACH_MV2120
+       bool "HP Media Vault mv2120"
+       help
+         Say 'Y' here if you want your kernel to support the
+         HP Media Vault mv2120 or mv5100.
+
+config MACH_MSS2
+       bool "Maxtor Shared Storage II"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Maxtor Shared Storage II platform.
+
+config MACH_WNR854T
+       bool "Netgear WNR854T"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Netgear WNR854T platform.
+
+config MACH_RD88F5181L_GE
+       bool "Marvell Orion-VoIP GE Reference Design"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell Orion-VoIP GE (88F5181L) RD.
+
+config MACH_RD88F5181L_FXO
+       bool "Marvell Orion-VoIP FXO Reference Design"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell Orion-VoIP FXO (88F5181L) RD.
+
 endmenu
 
 endif
index 9301bf5..fcc48a8 100644 (file)
@@ -1,7 +1,15 @@
-obj-y                          += common.o addr-map.o pci.o gpio.o irq.o
+obj-y                          += common.o addr-map.o pci.o gpio.o irq.o mpp.o
 obj-$(CONFIG_MACH_DB88F5281)   += db88f5281-setup.o
 obj-$(CONFIG_MACH_RD88F5182)   += rd88f5182-setup.o
 obj-$(CONFIG_MACH_KUROBOX_PRO) += kurobox_pro-setup.o
 obj-$(CONFIG_MACH_LINKSTATION_PRO) += kurobox_pro-setup.o
 obj-$(CONFIG_MACH_DNS323)      += dns323-setup.o
-obj-$(CONFIG_MACH_TS209)       += ts209-setup.o
+obj-$(CONFIG_MACH_TS209)       += ts209-setup.o tsx09-common.o
+obj-$(CONFIG_MACH_TS409)       += ts409-setup.o tsx09-common.o
+obj-$(CONFIG_MACH_WRT350N_V2)  += wrt350n-v2-setup.o
+obj-$(CONFIG_MACH_TS78XX)      += ts78xx-setup.o
+obj-$(CONFIG_MACH_MV2120)      += mv2120-setup.o
+obj-$(CONFIG_MACH_MSS2)                += mss2-setup.o
+obj-$(CONFIG_MACH_WNR854T)     += wnr854t-setup.o
+obj-$(CONFIG_MACH_RD88F5181L_GE)       += rd88f5181l-ge-setup.o
+obj-$(CONFIG_MACH_RD88F5181L_FXO)      += rd88f5181l-fxo-setup.o
index e63fb05..6f0dbda 100644 (file)
@@ -70,6 +70,7 @@
 
 
 struct mbus_dram_target_info orion5x_mbus_dram_info;
+static int __initdata win_alloc_count;
 
 static int __init orion5x_cpu_win_can_remap(int win)
 {
@@ -87,16 +88,22 @@ static int __init orion5x_cpu_win_can_remap(int win)
 static void __init setup_cpu_win(int win, u32 base, u32 size,
                                 u8 target, u8 attr, int remap)
 {
-       orion5x_write(CPU_WIN_BASE(win), base & 0xffff0000);
-       orion5x_write(CPU_WIN_CTRL(win),
-               ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1);
+       if (win >= 8) {
+               printk(KERN_ERR "setup_cpu_win: trying to allocate "
+                               "window %d\n", win);
+               return;
+       }
+
+       writel(base & 0xffff0000, CPU_WIN_BASE(win));
+       writel(((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1,
+               CPU_WIN_CTRL(win));
 
        if (orion5x_cpu_win_can_remap(win)) {
                if (remap < 0)
                        remap = base;
 
-               orion5x_write(CPU_WIN_REMAP_LO(win), remap & 0xffff0000);
-               orion5x_write(CPU_WIN_REMAP_HI(win), 0);
+               writel(remap & 0xffff0000, CPU_WIN_REMAP_LO(win));
+               writel(0, CPU_WIN_REMAP_HI(win));
        }
 }
 
@@ -109,11 +116,11 @@ void __init orion5x_setup_cpu_mbus_bridge(void)
         * First, disable and clear windows.
         */
        for (i = 0; i < 8; i++) {
-               orion5x_write(CPU_WIN_BASE(i), 0);
-               orion5x_write(CPU_WIN_CTRL(i), 0);
+               writel(0, CPU_WIN_BASE(i));
+               writel(0, CPU_WIN_CTRL(i));
                if (orion5x_cpu_win_can_remap(i)) {
-                       orion5x_write(CPU_WIN_REMAP_LO(i), 0);
-                       orion5x_write(CPU_WIN_REMAP_HI(i), 0);
+                       writel(0, CPU_WIN_REMAP_LO(i));
+                       writel(0, CPU_WIN_REMAP_HI(i));
                }
        }
 
@@ -128,6 +135,7 @@ void __init orion5x_setup_cpu_mbus_bridge(void)
                TARGET_PCIE, ATTR_PCIE_MEM, -1);
        setup_cpu_win(3, ORION5X_PCI_MEM_PHYS_BASE, ORION5X_PCI_MEM_SIZE,
                TARGET_PCI, ATTR_PCI_MEM, -1);
+       win_alloc_count = 4;
 
        /*
         * Setup MBUS dram target info.
@@ -147,8 +155,8 @@ void __init orion5x_setup_cpu_mbus_bridge(void)
                        w = &orion5x_mbus_dram_info.cs[cs++];
                        w->cs_index = i;
                        w->mbus_attr = 0xf & ~(1 << i);
-                       w->base = base & 0xff000000;
-                       w->size = (size | 0x00ffffff) + 1;
+                       w->base = base & 0xffff0000;
+                       w->size = (size | 0x0000ffff) + 1;
                }
        }
        orion5x_mbus_dram_info.num_cs = cs;
@@ -156,25 +164,30 @@ void __init orion5x_setup_cpu_mbus_bridge(void)
 
 void __init orion5x_setup_dev_boot_win(u32 base, u32 size)
 {
-       setup_cpu_win(4, base, size, TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);
+       setup_cpu_win(win_alloc_count++, base, size,
+                     TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);
 }
 
 void __init orion5x_setup_dev0_win(u32 base, u32 size)
 {
-       setup_cpu_win(5, base, size, TARGET_DEV_BUS, ATTR_DEV_CS0, -1);
+       setup_cpu_win(win_alloc_count++, base, size,
+                     TARGET_DEV_BUS, ATTR_DEV_CS0, -1);
 }
 
 void __init orion5x_setup_dev1_win(u32 base, u32 size)
 {
-       setup_cpu_win(6, base, size, TARGET_DEV_BUS, ATTR_DEV_CS1, -1);
+       setup_cpu_win(win_alloc_count++, base, size,
+                     TARGET_DEV_BUS, ATTR_DEV_CS1, -1);
 }
 
 void __init orion5x_setup_dev2_win(u32 base, u32 size)
 {
-       setup_cpu_win(7, base, size, TARGET_DEV_BUS, ATTR_DEV_CS2, -1);
+       setup_cpu_win(win_alloc_count++, base, size,
+                     TARGET_DEV_BUS, ATTR_DEV_CS2, -1);
 }
 
 void __init orion5x_setup_pcie_wa_win(u32 base, u32 size)
 {
-       setup_cpu_win(7, base, size, TARGET_PCIE, ATTR_PCIE_WA, -1);
+       setup_cpu_win(win_alloc_count++, base, size,
+                     TARGET_PCIE, ATTR_PCIE_WA, -1);
 }
index 4f13fd0..faf4e32 100644 (file)
@@ -39,25 +39,22 @@ static struct map_desc orion5x_io_desc[] __initdata = {
                .virtual        = ORION5X_REGS_VIRT_BASE,
                .pfn            = __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
                .length         = ORION5X_REGS_SIZE,
-               .type           = MT_DEVICE
-       },
-       {
+               .type           = MT_DEVICE,
+       }, {
                .virtual        = ORION5X_PCIE_IO_VIRT_BASE,
                .pfn            = __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
                .length         = ORION5X_PCIE_IO_SIZE,
-               .type           = MT_DEVICE
-       },
-       {
+               .type           = MT_DEVICE,
+       }, {
                .virtual        = ORION5X_PCI_IO_VIRT_BASE,
                .pfn            = __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
                .length         = ORION5X_PCI_IO_SIZE,
-               .type           = MT_DEVICE
-       },
-       {
+               .type           = MT_DEVICE,
+       }, {
                .virtual        = ORION5X_PCIE_WA_VIRT_BASE,
                .pfn            = __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
                .length         = ORION5X_PCIE_WA_SIZE,
-               .type           = MT_DEVICE
+               .type           = MT_DEVICE,
        },
 };
 
@@ -66,101 +63,32 @@ void __init orion5x_map_io(void)
        iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
 }
 
+
 /*****************************************************************************
- * UART
+ * EHCI
  ****************************************************************************/
-
-static struct resource orion5x_uart_resources[] = {
-       {
-               .start          = UART0_PHYS_BASE,
-               .end            = UART0_PHYS_BASE + 0xff,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .start          = IRQ_ORION5X_UART0,
-               .end            = IRQ_ORION5X_UART0,
-               .flags          = IORESOURCE_IRQ,
-       },
-       {
-               .start          = UART1_PHYS_BASE,
-               .end            = UART1_PHYS_BASE + 0xff,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .start          = IRQ_ORION5X_UART1,
-               .end            = IRQ_ORION5X_UART1,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static struct plat_serial8250_port orion5x_uart_data[] = {
-       {
-               .mapbase        = UART0_PHYS_BASE,
-               .membase        = (char *)UART0_VIRT_BASE,
-               .irq            = IRQ_ORION5X_UART0,
-               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
-               .iotype         = UPIO_MEM,
-               .regshift       = 2,
-               .uartclk        = ORION5X_TCLK,
-       },
-       {
-               .mapbase        = UART1_PHYS_BASE,
-               .membase        = (char *)UART1_VIRT_BASE,
-               .irq            = IRQ_ORION5X_UART1,
-               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
-               .iotype         = UPIO_MEM,
-               .regshift       = 2,
-               .uartclk        = ORION5X_TCLK,
-       },
-       { },
+static struct orion_ehci_data orion5x_ehci_data = {
+       .dram           = &orion5x_mbus_dram_info,
 };
 
-static struct platform_device orion5x_uart = {
-       .name                   = "serial8250",
-       .id                     = PLAT8250_DEV_PLATFORM,
-       .dev                    = {
-               .platform_data  = orion5x_uart_data,
-       },
-       .resource               = orion5x_uart_resources,
-       .num_resources          = ARRAY_SIZE(orion5x_uart_resources),
-};
+static u64 ehci_dmamask = 0xffffffffUL;
 
-/*******************************************************************************
- * USB Controller - 2 interfaces
- ******************************************************************************/
 
+/*****************************************************************************
+ * EHCI0
+ ****************************************************************************/
 static struct resource orion5x_ehci0_resources[] = {
        {
                .start  = ORION5X_USB0_PHYS_BASE,
                .end    = ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
                .flags  = IORESOURCE_MEM,
-       },
-       {
+       }, {
                .start  = IRQ_ORION5X_USB0_CTRL,
                .end    = IRQ_ORION5X_USB0_CTRL,
                .flags  = IORESOURCE_IRQ,
        },
 };
 
-static struct resource orion5x_ehci1_resources[] = {
-       {
-               .start  = ORION5X_USB1_PHYS_BASE,
-               .end    = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
-               .flags  = IORESOURCE_MEM,
-       },
-       {
-               .start  = IRQ_ORION5X_USB1_CTRL,
-               .end    = IRQ_ORION5X_USB1_CTRL,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-static struct orion_ehci_data orion5x_ehci_data = {
-       .dram           = &orion5x_mbus_dram_info,
-};
-
-static u64 ehci_dmamask = 0xffffffffUL;
-
 static struct platform_device orion5x_ehci0 = {
        .name           = "orion-ehci",
        .id             = 0,
@@ -173,6 +101,27 @@ static struct platform_device orion5x_ehci0 = {
        .num_resources  = ARRAY_SIZE(orion5x_ehci0_resources),
 };
 
+void __init orion5x_ehci0_init(void)
+{
+       platform_device_register(&orion5x_ehci0);
+}
+
+
+/*****************************************************************************
+ * EHCI1
+ ****************************************************************************/
+static struct resource orion5x_ehci1_resources[] = {
+       {
+               .start  = ORION5X_USB1_PHYS_BASE,
+               .end    = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_ORION5X_USB1_CTRL,
+               .end    = IRQ_ORION5X_USB1_CTRL,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
 static struct platform_device orion5x_ehci1 = {
        .name           = "orion-ehci",
        .id             = 1,
@@ -185,11 +134,15 @@ static struct platform_device orion5x_ehci1 = {
        .num_resources  = ARRAY_SIZE(orion5x_ehci1_resources),
 };
 
+void __init orion5x_ehci1_init(void)
+{
+       platform_device_register(&orion5x_ehci1);
+}
+
+
 /*****************************************************************************
- * Gigabit Ethernet port
- * (The Orion and Discovery (MV643xx) families use the same Ethernet driver)
+ * GigE
  ****************************************************************************/
-
 struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data = {
        .dram           = &orion5x_mbus_dram_info,
        .t_clk          = ORION5X_TCLK,
@@ -219,7 +172,7 @@ static struct resource orion5x_eth_resources[] = {
                .start  = IRQ_ORION5X_ETH_SUM,
                .end    = IRQ_ORION5X_ETH_SUM,
                .flags  = IORESOURCE_IRQ,
-       }
+       },
 };
 
 static struct platform_device orion5x_eth = {
@@ -238,11 +191,10 @@ void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
        platform_device_register(&orion5x_eth);
 }
 
+
 /*****************************************************************************
- * I2C controller
- * (The Orion and Discovery (MV643xx) families share the same I2C controller)
+ * I2C
  ****************************************************************************/
-
 static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
        .freq_m         = 8, /* assumes 166 MHz TCLK */
        .freq_n         = 3,
@@ -251,16 +203,15 @@ static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
 
 static struct resource orion5x_i2c_resources[] = {
        {
-               .name   = "i2c base",
-               .start  = I2C_PHYS_BASE,
-               .end    = I2C_PHYS_BASE + 0x20 -1,
-               .flags  = IORESOURCE_MEM,
-       },
-       {
-               .name   = "i2c irq",
-               .start  = IRQ_ORION5X_I2C,
-               .end    = IRQ_ORION5X_I2C,
-               .flags  = IORESOURCE_IRQ,
+               .name   = "i2c base",
+               .start  = I2C_PHYS_BASE,
+               .end    = I2C_PHYS_BASE + 0x1f,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "i2c irq",
+               .start  = IRQ_ORION5X_I2C,
+               .end    = IRQ_ORION5X_I2C,
+               .flags  = IORESOURCE_IRQ,
        },
 };
 
@@ -270,36 +221,41 @@ static struct platform_device orion5x_i2c = {
        .num_resources  = ARRAY_SIZE(orion5x_i2c_resources),
        .resource       = orion5x_i2c_resources,
        .dev            = {
-               .platform_data = &orion5x_i2c_pdata,
+               .platform_data  = &orion5x_i2c_pdata,
        },
 };
 
+void __init orion5x_i2c_init(void)
+{
+       platform_device_register(&orion5x_i2c);
+}
+
+
 /*****************************************************************************
- * Sata port
+ * SATA
  ****************************************************************************/
 static struct resource orion5x_sata_resources[] = {
-        {
-                .name   = "sata base",
-                .start  = ORION5X_SATA_PHYS_BASE,
-                .end    = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
-                .flags  = IORESOURCE_MEM,
-        },
        {
-                .name   = "sata irq",
-                .start  = IRQ_ORION5X_SATA,
-                .end    = IRQ_ORION5X_SATA,
-                .flags  = IORESOURCE_IRQ,
-        },
+               .name   = "sata base",
+               .start  = ORION5X_SATA_PHYS_BASE,
+               .end    = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "sata irq",
+               .start  = IRQ_ORION5X_SATA,
+               .end    = IRQ_ORION5X_SATA,
+               .flags  = IORESOURCE_IRQ,
+       },
 };
 
 static struct platform_device orion5x_sata = {
-       .name           = "sata_mv",
-       .id             = 0,
+       .name           = "sata_mv",
+       .id             = 0,
        .dev            = {
                .coherent_dma_mask      = 0xffffffff,
        },
-       .num_resources  = ARRAY_SIZE(orion5x_sata_resources),
-       .resource       = orion5x_sata_resources,
+       .num_resources  = ARRAY_SIZE(orion5x_sata_resources),
+       .resource       = orion5x_sata_resources,
 };
 
 void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
@@ -309,23 +265,111 @@ void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
        platform_device_register(&orion5x_sata);
 }
 
+
 /*****************************************************************************
- * Time handling
+ * UART0
+ ****************************************************************************/
+static struct plat_serial8250_port orion5x_uart0_data[] = {
+       {
+               .mapbase        = UART0_PHYS_BASE,
+               .membase        = (char *)UART0_VIRT_BASE,
+               .irq            = IRQ_ORION5X_UART0,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = ORION5X_TCLK,
+       }, {
+       },
+};
+
+static struct resource orion5x_uart0_resources[] = {
+       {
+               .start          = UART0_PHYS_BASE,
+               .end            = UART0_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_ORION5X_UART0,
+               .end            = IRQ_ORION5X_UART0,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device orion5x_uart0 = {
+       .name                   = "serial8250",
+       .id                     = PLAT8250_DEV_PLATFORM,
+       .dev                    = {
+               .platform_data  = orion5x_uart0_data,
+       },
+       .resource               = orion5x_uart0_resources,
+       .num_resources          = ARRAY_SIZE(orion5x_uart0_resources),
+};
+
+void __init orion5x_uart0_init(void)
+{
+       platform_device_register(&orion5x_uart0);
+}
+
+
+/*****************************************************************************
+ * UART1
  ****************************************************************************/
+static struct plat_serial8250_port orion5x_uart1_data[] = {
+       {
+               .mapbase        = UART1_PHYS_BASE,
+               .membase        = (char *)UART1_VIRT_BASE,
+               .irq            = IRQ_ORION5X_UART1,
+               .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+               .iotype         = UPIO_MEM,
+               .regshift       = 2,
+               .uartclk        = ORION5X_TCLK,
+       }, {
+       },
+};
+
+static struct resource orion5x_uart1_resources[] = {
+       {
+               .start          = UART1_PHYS_BASE,
+               .end            = UART1_PHYS_BASE + 0xff,
+               .flags          = IORESOURCE_MEM,
+       }, {
+               .start          = IRQ_ORION5X_UART1,
+               .end            = IRQ_ORION5X_UART1,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device orion5x_uart1 = {
+       .name                   = "serial8250",
+       .id                     = PLAT8250_DEV_PLATFORM1,
+       .dev                    = {
+               .platform_data  = orion5x_uart1_data,
+       },
+       .resource               = orion5x_uart1_resources,
+       .num_resources          = ARRAY_SIZE(orion5x_uart1_resources),
+};
+
+void __init orion5x_uart1_init(void)
+{
+       platform_device_register(&orion5x_uart1);
+}
+
 
+/*****************************************************************************
+ * Time handling
+ ****************************************************************************/
 static void orion5x_timer_init(void)
 {
        orion_time_init(IRQ_ORION5X_BRIDGE, ORION5X_TCLK);
 }
 
 struct sys_timer orion5x_timer = {
-        .init = orion5x_timer_init,
+       .init = orion5x_timer_init,
 };
 
+
 /*****************************************************************************
  * General
  ****************************************************************************/
-
 /*
  * Identify device ID and rev from PCIe configuration header space '0'.
  */
@@ -350,8 +394,10 @@ static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
        } else if (*dev == MV88F5181_DEV_ID) {
                if (*rev == MV88F5181_REV_B1) {
                        *dev_name = "MV88F5181-Rev-B1";
+               } else if (*rev == MV88F5181L_REV_A1) {
+                       *dev_name = "MV88F5181L-Rev-A1";
                } else {
-                       *dev_name = "MV88F5181-Rev-Unsupported";
+                       *dev_name = "MV88F5181(L)-Rev-Unsupported";
                }
        } else {
                *dev_name = "Device-Unknown";
@@ -370,15 +416,6 @@ void __init orion5x_init(void)
         * Setup Orion address map
         */
        orion5x_setup_cpu_mbus_bridge();
-
-       /*
-        * Register devices.
-        */
-       platform_device_register(&orion5x_uart);
-       platform_device_register(&orion5x_ehci0);
-       if (dev == MV88F5182_DEV_ID)
-               platform_device_register(&orion5x_ehci1);
-       platform_device_register(&orion5x_i2c);
 }
 
 /*
index bd0f05d..f72cf0e 100644 (file)
@@ -1,10 +1,12 @@
 #ifndef __ARCH_ORION5X_COMMON_H
 #define __ARCH_ORION5X_COMMON_H
 
+struct mv643xx_eth_platform_data;
+struct mv_sata_platform_data;
+
 /*
  * Basic Orion init functions used early by machine-setup.
  */
-
 void orion5x_map_io(void);
 void orion5x_init_irq(void);
 void orion5x_init(void);
@@ -23,15 +25,22 @@ void orion5x_setup_dev1_win(u32 base, u32 size);
 void orion5x_setup_dev2_win(u32 base, u32 size);
 void orion5x_setup_pcie_wa_win(u32 base, u32 size);
 
+void orion5x_ehci0_init(void);
+void orion5x_ehci1_init(void);
+void orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data);
+void orion5x_i2c_init(void);
+void orion5x_sata_init(struct mv_sata_platform_data *sata_data);
+void orion5x_uart0_init(void);
+void orion5x_uart1_init(void);
+
 /*
- * Shared code used internally by other Orion core functions.
- * (/mach-orion/pci.c)
+ * PCIe/PCI functions.
  */
-
-struct pci_sys_data;
 struct pci_bus;
+struct pci_sys_data;
 
 void orion5x_pcie_id(u32 *dev, u32 *rev);
+void orion5x_pci_set_cardbus_mode(void);
 int orion5x_pci_sys_setup(int nr, struct pci_sys_data *sys);
 struct pci_bus *orion5x_pci_sys_scan_bus(int nr, struct pci_sys_data *sys);
 int orion5x_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin);
@@ -40,26 +49,9 @@ int orion5x_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin);
  * Valid GPIO pins according to MPP setup, used by machine-setup.
  * (/mach-orion/gpio.c).
  */
-
-void orion5x_gpio_set_valid_pins(u32 pins);
+void orion5x_gpio_set_valid(unsigned pin, int valid);
 void gpio_display(void);       /* debug */
 
-/*
- * Pull in Orion Ethernet platform_data, used by machine-setup
- */
-
-struct mv643xx_eth_platform_data;
-
-void orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data);
-
-/*
- * Orion Sata platform_data, used by machine-setup
- */
-
-struct mv_sata_platform_data;
-
-void orion5x_sata_init(struct mv_sata_platform_data *sata_data);
-
 struct machine_desc;
 struct meminfo;
 struct tag;
index 44c6434..88405e7 100644 (file)
@@ -27,6 +27,7 @@
 #include <asm/arch/orion5x.h>
 #include <asm/plat-orion/orion_nand.h>
 #include "common.h"
+#include "mpp.h"
 
 /*****************************************************************************
  * DB-88F5281 on board devices
@@ -86,7 +87,7 @@ static struct platform_device db88f5281_boot_flash = {
        .name           = "physmap-flash",
        .id             = 0,
        .dev            = {
-               .platform_data = &db88f5281_boot_flash_data,
+               .platform_data  = &db88f5281_boot_flash_data,
        },
        .num_resources  = 1,
        .resource       = &db88f5281_boot_flash_resource,
@@ -110,7 +111,7 @@ static struct platform_device db88f5281_nor_flash = {
        .name           = "physmap-flash",
        .id             = 1,
        .dev            = {
-               .platform_data = &db88f5281_nor_flash_data,
+               .platform_data  = &db88f5281_nor_flash_data,
        },
        .num_resources  = 1,
        .resource       = &db88f5281_nor_flash_resource,
@@ -125,18 +126,15 @@ static struct mtd_partition db88f5281_nand_parts[] = {
                .name = "kernel",
                .offset = 0,
                .size = SZ_2M,
-       },
-       {
+       }, {
                .name = "root",
                .offset = SZ_2M,
                .size = (SZ_16M - SZ_2M),
-       },
-       {
+       }, {
                .name = "user",
                .offset = SZ_16M,
                .size = SZ_8M,
-       },
-       {
+       }, {
                .name = "recovery",
                .offset = (SZ_16M + SZ_8M),
                .size = SZ_8M,
@@ -288,7 +286,6 @@ subsys_initcall(db88f5281_pci_init);
  ****************************************************************************/
 static struct mv643xx_eth_platform_data db88f5281_eth_data = {
        .phy_addr       = 8,
-       .force_phy_addr = 1,
 };
 
 /*****************************************************************************
@@ -301,11 +298,28 @@ static struct i2c_board_info __initdata db88f5281_i2c_rtc = {
 /*****************************************************************************
  * General Setup
  ****************************************************************************/
-
-static struct platform_device *db88f5281_devs[] __initdata = {
-       &db88f5281_boot_flash,
-       &db88f5281_nor_flash,
-       &db88f5281_nand_flash,
+static struct orion5x_mpp_mode db88f5281_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* USB Over Current */
+       {  1, MPP_GPIO },               /* USB Vbat input */
+       {  2, MPP_PCI_ARB },            /* PCI_REQn[2] */
+       {  3, MPP_PCI_ARB },            /* PCI_GNTn[2] */
+       {  4, MPP_PCI_ARB },            /* PCI_REQn[3] */
+       {  5, MPP_PCI_ARB },            /* PCI_GNTn[3] */
+       {  6, MPP_GPIO },               /* JP0, CON17.2 */
+       {  7, MPP_GPIO },               /* JP1, CON17.1 */
+       {  8, MPP_GPIO },               /* JP2, CON11.2 */
+       {  9, MPP_GPIO },               /* JP3, CON11.3 */
+       { 10, MPP_GPIO },               /* RTC int */
+       { 11, MPP_GPIO },               /* Baud Rate Generator */
+       { 12, MPP_GPIO },               /* PCI int 1 */
+       { 13, MPP_GPIO },               /* PCI int 2 */
+       { 14, MPP_NAND },               /* NAND_REn[2] */
+       { 15, MPP_NAND },               /* NAND_WEn[2] */
+       { 16, MPP_UART },               /* UART1_RX */
+       { 17, MPP_UART },               /* UART1_TX */
+       { 18, MPP_UART },               /* UART1_CTSn */
+       { 19, MPP_UART },               /* UART1_RTSn */
+       { -1 },
 };
 
 static void __init db88f5281_init(void)
@@ -315,39 +329,31 @@ static void __init db88f5281_init(void)
         */
        orion5x_init();
 
+       orion5x_mpp_conf(db88f5281_mpp_modes);
+       writel(0, MPP_DEV_CTRL);                /* DEV_D[31:16] */
+
        /*
-        * Setup the CPU address decode windows for our on-board devices
+        * Configure peripherals.
         */
+       orion5x_ehci0_init();
+       orion5x_eth_init(&db88f5281_eth_data);
+       orion5x_i2c_init();
+       orion5x_uart0_init();
+       orion5x_uart1_init();
+
        orion5x_setup_dev_boot_win(DB88F5281_NOR_BOOT_BASE,
                                DB88F5281_NOR_BOOT_SIZE);
+       platform_device_register(&db88f5281_boot_flash);
+
        orion5x_setup_dev0_win(DB88F5281_7SEG_BASE, DB88F5281_7SEG_SIZE);
-       orion5x_setup_dev1_win(DB88F5281_NOR_BASE, DB88F5281_NOR_SIZE);
-       orion5x_setup_dev2_win(DB88F5281_NAND_BASE, DB88F5281_NAND_SIZE);
 
-       /*
-        * Setup Multiplexing Pins:
-        * MPP0: GPIO (USB Over Current)        MPP1: GPIO (USB Vbat input)
-        * MPP2: PCI_REQn[2]                    MPP3: PCI_GNTn[2]
-        * MPP4: PCI_REQn[3]                    MPP5: PCI_GNTn[3]
-        * MPP6: GPIO (JP0, CON17.2)            MPP7: GPIO (JP1, CON17.1)
-        * MPP8: GPIO (JP2, CON11.2)            MPP9: GPIO (JP3, CON11.3)
-        * MPP10: GPIO (RTC int)                MPP11: GPIO (Baud Rate Generator)
-        * MPP12: GPIO (PCI int 1)              MPP13: GPIO (PCI int 2)
-        * MPP14: NAND_REn[2]                   MPP15: NAND_WEn[2]
-        * MPP16: UART1_RX                      MPP17: UART1_TX
-        * MPP18: UART1_CTS                     MPP19: UART1_RTS
-        * MPP-DEV: DEV_D[16:31]
-        */
-       orion5x_write(MPP_0_7_CTRL, 0x00222203);
-       orion5x_write(MPP_8_15_CTRL, 0x44000000);
-       orion5x_write(MPP_16_19_CTRL, 0);
-       orion5x_write(MPP_DEV_CTRL, 0);
+       orion5x_setup_dev1_win(DB88F5281_NOR_BASE, DB88F5281_NOR_SIZE);
+       platform_device_register(&db88f5281_nor_flash);
 
-       orion5x_gpio_set_valid_pins(0x00003fc3);
+       orion5x_setup_dev2_win(DB88F5281_NAND_BASE, DB88F5281_NAND_SIZE);
+       platform_device_register(&db88f5281_nand_flash);
 
-       platform_add_devices(db88f5281_devs, ARRAY_SIZE(db88f5281_devs));
        i2c_register_board_info(0, &db88f5281_i2c_rtc, 1);
-       orion5x_eth_init(&db88f5281_eth_data);
 }
 
 MACHINE_START(DB88F5281, "Marvell Orion-2 Development Board")
index 27ce967..3791ca6 100644 (file)
@@ -27,6 +27,7 @@
 #include <asm/mach/pci.h>
 #include <asm/arch/orion5x.h>
 #include "common.h"
+#include "mpp.h"
 
 #define DNS323_GPIO_LED_RIGHT_AMBER    1
 #define DNS323_GPIO_LED_LEFT_AMBER     2
@@ -52,8 +53,6 @@ static int __init dns323_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
        if (irq != -1)
                return irq;
 
-       pr_err("%s: requested mapping for unknown device\n", __func__);
-
        return -1;
 }
 
@@ -81,7 +80,6 @@ subsys_initcall(dns323_pci_init);
 
 static struct mv643xx_eth_platform_data dns323_eth_data = {
        .phy_addr = 8,
-       .force_phy_addr = 1,
 };
 
 /****************************************************************************
@@ -119,7 +117,7 @@ static struct mtd_partition dns323_partitions[] = {
                .name   = "u-boot",
                .size   = 0x00030000,
                .offset = 0x007d0000,
-       }
+       },
 };
 
 static struct physmap_flash_data dns323_nor_flash_data = {
@@ -137,7 +135,9 @@ static struct resource dns323_nor_flash_resource = {
 static struct platform_device dns323_nor_flash = {
        .name           = "physmap-flash",
        .id             = 0,
-       .dev            = { .platform_data = &dns323_nor_flash_data, },
+       .dev            = {
+               .platform_data  = &dns323_nor_flash_data,
+       },
        .resource       = &dns323_nor_flash_resource,
        .num_resources  = 1,
 };
@@ -170,7 +170,9 @@ static struct gpio_led_platform_data dns323_led_data = {
 static struct platform_device dns323_gpio_leds = {
        .name           = "leds-gpio",
        .id             = -1,
-       .dev            = { .platform_data = &dns323_led_data, },
+       .dev            = {
+               .platform_data  = &dns323_led_data,
+       },
 };
 
 /****************************************************************************
@@ -183,35 +185,53 @@ static struct gpio_keys_button dns323_buttons[] = {
                .gpio           = DNS323_GPIO_KEY_RESET,
                .desc           = "Reset Button",
                .active_low     = 1,
-       },
-       {
+       }, {
                .code           = KEY_POWER,
                .gpio           = DNS323_GPIO_KEY_POWER,
                .desc           = "Power Button",
                .active_low     = 1,
-       }
+       },
 };
 
 static struct gpio_keys_platform_data dns323_button_data = {
        .buttons        = dns323_buttons,
-       .nbuttons       = ARRAY_SIZE(dns323_buttons),
+       .nbuttons       = ARRAY_SIZE(dns323_buttons),
 };
 
 static struct platform_device dns323_button_device = {
        .name           = "gpio-keys",
        .id             = -1,
        .num_resources  = 0,
-       .dev            = { .platform_data  = &dns323_button_data, },
+       .dev            = {
+               .platform_data  = &dns323_button_data,
+       },
 };
 
 /****************************************************************************
  * General Setup
  */
-
-static struct platform_device *dns323_plat_devices[] __initdata = {
-       &dns323_nor_flash,
-       &dns323_gpio_leds,
-       &dns323_button_device,
+static struct orion5x_mpp_mode dns323_mpp_modes[] __initdata = {
+       {  0, MPP_PCIE_RST_OUTn },
+       {  1, MPP_GPIO },               /* right amber LED (sata ch0) */
+       {  2, MPP_GPIO },               /* left amber LED (sata ch1) */
+       {  3, MPP_UNUSED },
+       {  4, MPP_GPIO },               /* power button LED */
+       {  5, MPP_GPIO },               /* power button LED */
+       {  6, MPP_GPIO },               /* GMT G751-2f overtemp */
+       {  7, MPP_GPIO },               /* M41T80 nIRQ/OUT/SQW */
+       {  8, MPP_GPIO },               /* triggers power off */
+       {  9, MPP_GPIO },               /* power button switch */
+       { 10, MPP_GPIO },               /* reset button switch */
+       { 11, MPP_UNUSED },
+       { 12, MPP_UNUSED },
+       { 13, MPP_UNUSED },
+       { 14, MPP_UNUSED },
+       { 15, MPP_UNUSED },
+       { 16, MPP_UNUSED },
+       { 17, MPP_UNUSED },
+       { 18, MPP_UNUSED },
+       { 19, MPP_UNUSED },
+       { -1 },
 };
 
 /*
@@ -225,17 +245,15 @@ static struct platform_device *dns323_plat_devices[] __initdata = {
 static struct i2c_board_info __initdata dns323_i2c_devices[] = {
        {
                I2C_BOARD_INFO("g760a", 0x3e),
-       },
 #if 0
        /* this entry requires the new-style driver model lm75 driver,
         * for the meantime "insmod lm75.ko force_lm75=0,0x48" is needed */
-       {
+       }, {
                I2C_BOARD_INFO("g751", 0x48),
-       },
 #endif
-       {
+       }, {
                I2C_BOARD_INFO("m41t80", 0x68),
-       }
+       },
 };
 
 /* DNS-323 specific power off method */
@@ -250,62 +268,35 @@ static void __init dns323_init(void)
        /* Setup basic Orion functions. Need to be called early. */
        orion5x_init();
 
+       orion5x_mpp_conf(dns323_mpp_modes);
+       writel(0, MPP_DEV_CTRL);                /* DEV_D[31:16] */
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_eth_init(&dns323_eth_data);
+       orion5x_i2c_init();
+       orion5x_uart0_init();
+
        /* setup flash mapping
         * CS3 holds a 8 MB Spansion S29GL064M90TFIR4
         */
        orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
+       platform_device_register(&dns323_nor_flash);
 
-       /* DNS-323 has a Marvell 88X7042 SATA controller attached via PCIe
-        *
-        * Open a special address decode windows for the PCIe WA.
-        */
-       orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
-                               ORION5X_PCIE_WA_SIZE);
-
-       /* set MPP to 0 as D-Link's 2.6.12.6 kernel did */
-       orion5x_write(MPP_0_7_CTRL, 0);
-       orion5x_write(MPP_8_15_CTRL, 0);
-       orion5x_write(MPP_16_19_CTRL, 0);
-       orion5x_write(MPP_DEV_CTRL, 0);
-
-       /* Define used GPIO pins
-
-         GPIO Map:
-
-         |  0 |     | PEX_RST_OUT (not controlled by GPIO)
-         |  1 | Out | right amber LED (= sata ch0 LED)  (low-active)
-         |  2 | Out | left  amber LED (= sata ch1 LED)  (low-active)
-         |  3 | Out | //unknown//
-         |  4 | Out | power button LED (low-active, together with pin #5)
-         |  5 | Out | power button LED (low-active, together with pin #4)
-         |  6 | In  | GMT G751-2f overtemp. shutdown signal (low-active)
-         |  7 | In  | M41T80 nIRQ/OUT/SQW signal
-         |  8 | Out | triggers power off (high-active)
-         |  9 | In  | power button switch (low-active)
-         | 10 | In  | reset button switch (low-active)
-         | 11 | Out | //unknown//
-         | 12 | Out | //unknown//
-         | 13 | Out | //unknown//
-         | 14 | Out | //unknown//
-         | 15 | Out | //unknown//
-       */
-       orion5x_gpio_set_valid_pins(0x07f6);
-
-       /* register dns323 specific power-off method */
-       if ((gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0)
-           || (gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0))
-               pr_err("DNS323: failed to setup power-off GPIO\n");
-
-       pm_power_off = dns323_power_off;
+       platform_device_register(&dns323_gpio_leds);
 
-       /* register flash and other platform devices */
-       platform_add_devices(dns323_plat_devices,
-                            ARRAY_SIZE(dns323_plat_devices));
+       platform_device_register(&dns323_button_device);
 
        i2c_register_board_info(0, dns323_i2c_devices,
                                ARRAY_SIZE(dns323_i2c_devices));
 
-       orion5x_eth_init(&dns323_eth_data);
+       /* register dns323 specific power-off method */
+       if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
+           gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
+               pr_err("DNS323: failed to setup power-off GPIO\n");
+       pm_power_off = dns323_power_off;
 }
 
 /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
index 8108c31..d097979 100644 (file)
@@ -24,9 +24,12 @@ static DEFINE_SPINLOCK(gpio_lock);
 static unsigned long gpio_valid[BITS_TO_LONGS(GPIO_MAX)];
 static const char *gpio_label[GPIO_MAX];  /* non null for allocated GPIOs */
 
-void __init orion5x_gpio_set_valid_pins(u32 pins)
+void __init orion5x_gpio_set_valid(unsigned pin, int valid)
 {
-       gpio_valid[0] = pins;
+       if (valid)
+               __set_bit(pin, gpio_valid);
+       else
+               __clear_bit(pin, gpio_valid);
 }
 
 /*
@@ -93,10 +96,10 @@ int gpio_get_value(unsigned pin)
 {
        int val, mask = 1 << pin;
 
-       if (orion5x_read(GPIO_IO_CONF) & mask)
-               val = orion5x_read(GPIO_DATA_IN) ^ orion5x_read(GPIO_IN_POL);
+       if (readl(GPIO_IO_CONF) & mask)
+               val = readl(GPIO_DATA_IN) ^ readl(GPIO_IN_POL);
        else
-               val = orion5x_read(GPIO_OUT);
+               val = readl(GPIO_OUT);
 
        return val & mask;
 }
@@ -188,39 +191,39 @@ void gpio_display(void)
                        printk("GPIO, free\n");
                } else {
                        printk("GPIO, used by %s, ", gpio_label[i]);
-                       if (orion5x_read(GPIO_IO_CONF) & (1 << i)) {
+                       if (readl(GPIO_IO_CONF) & (1 << i)) {
                                printk("input, active %s, level %s, edge %s\n",
-                               ((orion5x_read(GPIO_IN_POL) >> i) & 1) ? "low" : "high",
-                               ((orion5x_read(GPIO_LEVEL_MASK) >> i) & 1) ? "enabled" : "masked",
-                               ((orion5x_read(GPIO_EDGE_MASK) >> i) & 1) ? "enabled" : "masked");
+                               ((readl(GPIO_IN_POL) >> i) & 1) ? "low" : "high",
+                               ((readl(GPIO_LEVEL_MASK) >> i) & 1) ? "enabled" : "masked",
+                               ((readl(GPIO_EDGE_MASK) >> i) & 1) ? "enabled" : "masked");
                        } else {
-                               printk("output, val=%d\n", (orion5x_read(GPIO_OUT) >> i) & 1);
+                               printk("output, val=%d\n", (readl(GPIO_OUT) >> i) & 1);
                        }
                }
        }
 
        printk(KERN_DEBUG "MPP_0_7_CTRL (0x%08x) = 0x%08x\n",
-                               MPP_0_7_CTRL, orion5x_read(MPP_0_7_CTRL));
+                               MPP_0_7_CTRL, readl(MPP_0_7_CTRL));
        printk(KERN_DEBUG "MPP_8_15_CTRL (0x%08x) = 0x%08x\n",
-                               MPP_8_15_CTRL, orion5x_read(MPP_8_15_CTRL));
+                               MPP_8_15_CTRL, readl(MPP_8_15_CTRL));
        printk(KERN_DEBUG "MPP_16_19_CTRL (0x%08x) = 0x%08x\n",
-                               MPP_16_19_CTRL, orion5x_read(MPP_16_19_CTRL));
+                               MPP_16_19_CTRL, readl(MPP_16_19_CTRL));
        printk(KERN_DEBUG "MPP_DEV_CTRL (0x%08x) = 0x%08x\n",
-                               MPP_DEV_CTRL, orion5x_read(MPP_DEV_CTRL));
+                               MPP_DEV_CTRL, readl(MPP_DEV_CTRL));
        printk(KERN_DEBUG "GPIO_OUT (0x%08x) = 0x%08x\n",
-                               GPIO_OUT, orion5x_read(GPIO_OUT));
+                               GPIO_OUT, readl(GPIO_OUT));
        printk(KERN_DEBUG "GPIO_IO_CONF (0x%08x) = 0x%08x\n",
-                               GPIO_IO_CONF, orion5x_read(GPIO_IO_CONF));
+                               GPIO_IO_CONF, readl(GPIO_IO_CONF));
        printk(KERN_DEBUG "GPIO_BLINK_EN (0x%08x) = 0x%08x\n",
-                               GPIO_BLINK_EN, orion5x_read(GPIO_BLINK_EN));
+                               GPIO_BLINK_EN, readl(GPIO_BLINK_EN));
        printk(KERN_DEBUG "GPIO_IN_POL (0x%08x) = 0x%08x\n",
-                               GPIO_IN_POL, orion5x_read(GPIO_IN_POL));
+                               GPIO_IN_POL, readl(GPIO_IN_POL));
        printk(KERN_DEBUG "GPIO_DATA_IN (0x%08x) = 0x%08x\n",
-                               GPIO_DATA_IN, orion5x_read(GPIO_DATA_IN));
+                               GPIO_DATA_IN, readl(GPIO_DATA_IN));
        printk(KERN_DEBUG "GPIO_LEVEL_MASK (0x%08x) = 0x%08x\n",
-                               GPIO_LEVEL_MASK, orion5x_read(GPIO_LEVEL_MASK));
+                               GPIO_LEVEL_MASK, readl(GPIO_LEVEL_MASK));
        printk(KERN_DEBUG "GPIO_EDGE_CAUSE (0x%08x) = 0x%08x\n",
-                               GPIO_EDGE_CAUSE, orion5x_read(GPIO_EDGE_CAUSE));
+                               GPIO_EDGE_CAUSE, readl(GPIO_EDGE_CAUSE));
        printk(KERN_DEBUG "GPIO_EDGE_MASK (0x%08x) = 0x%08x\n",
-                               GPIO_EDGE_MASK, orion5x_read(GPIO_EDGE_MASK));
+                               GPIO_EDGE_MASK, readl(GPIO_EDGE_MASK));
 }
index dd21f38..e2a0084 100644 (file)
@@ -82,7 +82,7 @@ static int orion5x_gpio_set_irq_type(u32 irq, u32 type)
        int pin = irq_to_gpio(irq);
        struct irq_desc *desc;
 
-       if ((orion5x_read(GPIO_IO_CONF) & (1 << pin)) == 0) {
+       if ((readl(GPIO_IO_CONF) & (1 << pin)) == 0) {
                printk(KERN_ERR "orion5x_gpio_set_irq_type failed "
                                "(irq %d, pin %d).\n", irq, pin);
                return -EINVAL;
@@ -117,7 +117,7 @@ static int orion5x_gpio_set_irq_type(u32 irq, u32 type)
                /*
                 * set initial polarity based on current input level
                 */
-               if ((orion5x_read(GPIO_IN_POL) ^ orion5x_read(GPIO_DATA_IN))
+               if ((readl(GPIO_IN_POL) ^ readl(GPIO_DATA_IN))
                    & (1 << pin))
                        orion5x_setbits(GPIO_IN_POL, (1 << pin)); /* falling */
                else
@@ -149,8 +149,8 @@ static void orion5x_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
 
        BUG_ON(irq < IRQ_ORION5X_GPIO_0_7 || irq > IRQ_ORION5X_GPIO_24_31);
        offs = (irq - IRQ_ORION5X_GPIO_0_7) * 8;
-       cause = (orion5x_read(GPIO_DATA_IN) & orion5x_read(GPIO_LEVEL_MASK)) |
-               (orion5x_read(GPIO_EDGE_CAUSE) & orion5x_read(GPIO_EDGE_MASK));
+       cause = (readl(GPIO_DATA_IN) & readl(GPIO_LEVEL_MASK)) |
+               (readl(GPIO_EDGE_CAUSE) & readl(GPIO_EDGE_MASK));
 
        for (pin = offs; pin < offs + 8; pin++) {
                if (cause & (1 << pin)) {
@@ -158,9 +158,9 @@ static void orion5x_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
                        desc = irq_desc + irq;
                        if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQT_BOTHEDGE) {
                                /* Swap polarity (race with GPIO line) */
-                               u32 polarity = orion5x_read(GPIO_IN_POL);
+                               u32 polarity = readl(GPIO_IN_POL);
                                polarity ^= 1 << pin;
-                               orion5x_write(GPIO_IN_POL, polarity);
+                               writel(polarity, GPIO_IN_POL);
                        }
                        desc_handle_irq(irq, desc);
                }
@@ -175,9 +175,9 @@ static void __init orion5x_init_gpio_irq(void)
        /*
         * Mask and clear GPIO IRQ interrupts
         */
-       orion5x_write(GPIO_LEVEL_MASK, 0x0);
-       orion5x_write(GPIO_EDGE_MASK, 0x0);
-       orion5x_write(GPIO_EDGE_CAUSE, 0x0);
+       writel(0x0, GPIO_LEVEL_MASK);
+       writel(0x0, GPIO_EDGE_MASK);
+       writel(0x0, GPIO_EDGE_CAUSE);
 
        /*
         * Register chained level handlers for GPIO IRQs by default.
index f5074b8..84feac4 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/pci.h>
 #include <linux/irq.h>
+#include <linux/delay.h>
 #include <linux/mtd/physmap.h>
 #include <linux/mtd/nand.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/i2c.h>
+#include <linux/serial_reg.h>
 #include <linux/ata_platform.h>
 #include <asm/mach-types.h>
 #include <asm/gpio.h>
@@ -25,6 +27,7 @@
 #include <asm/arch/orion5x.h>
 #include <asm/plat-orion/orion_nand.h>
 #include "common.h"
+#include "mpp.h"
 
 /*****************************************************************************
  * KUROBOX-PRO Info
@@ -53,13 +56,11 @@ static struct mtd_partition kurobox_pro_nand_parts[] = {
                .name   = "uImage",
                .offset = 0,
                .size   = SZ_4M,
-       },
-       {
+       }, {
                .name   = "rootfs",
                .offset = SZ_4M,
                .size   = SZ_64M,
-       },
-       {
+       }, {
                .name   = "extra",
                .offset = SZ_4M + SZ_64M,
                .size   = SZ_256M - (SZ_4M + SZ_64M),
@@ -132,8 +133,6 @@ static int __init kurobox_pro_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
        /*
         * PCI isn't used on the Kuro
         */
-       printk(KERN_ERR "kurobox_pro_pci_map_irq failed, unknown bus\n");
-
        return -1;
 }
 
@@ -161,7 +160,6 @@ subsys_initcall(kurobox_pro_pci_init);
 
 static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
        .phy_addr       = 8,
-       .force_phy_addr = 1,
 };
 
 /*****************************************************************************
@@ -175,12 +173,169 @@ static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
  * SATA
  ****************************************************************************/
 static struct mv_sata_platform_data kurobox_pro_sata_data = {
-       .n_ports        = 2,
+       .n_ports        = 2,
 };
 
+/*****************************************************************************
+ * Kurobox Pro specific power off method via UART1-attached microcontroller
+ ****************************************************************************/
+
+#define UART1_REG(x)   (UART1_VIRT_BASE + ((UART_##x) << 2))
+
+static int kurobox_pro_miconread(unsigned char *buf, int count)
+{
+       int i;
+       int timeout;
+
+       for (i = 0; i < count; i++) {
+               timeout = 10;
+
+               while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
+                       if (--timeout == 0)
+                               break;
+                       udelay(1000);
+               }
+
+               if (timeout == 0)
+                       break;
+               buf[i] = readl(UART1_REG(RX));
+       }
+
+       /* return read bytes */
+       return i;
+}
+
+static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
+{
+       int i = 0;
+
+       while (count--) {
+               while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
+                       barrier();
+               writel(buf[i++], UART1_REG(TX));
+       }
+
+       return 0;
+}
+
+static int kurobox_pro_miconsend(const unsigned char *data, int count)
+{
+       int i;
+       unsigned char checksum = 0;
+       unsigned char recv_buf[40];
+       unsigned char send_buf[40];
+       unsigned char correct_ack[3];
+       int retry = 2;
+
+       /* Generate checksum */
+       for (i = 0; i < count; i++)
+               checksum -=  data[i];
+
+       do {
+               /* Send data */
+               kurobox_pro_miconwrite(data, count);
+
+               /* send checksum */
+               kurobox_pro_miconwrite(&checksum, 1);
+
+               if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
+                       printk(KERN_ERR ">%s: receive failed.\n", __func__);
+
+                       /* send preamble to clear the receive buffer */
+                       memset(&send_buf, 0xff, sizeof(send_buf));
+                       kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
+
+                       /* make dummy reads */
+                       mdelay(100);
+                       kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
+               } else {
+                       /* Generate expected ack */
+                       correct_ack[0] = 0x01;
+                       correct_ack[1] = data[1];
+                       correct_ack[2] = 0x00;
+
+                       /* checksum Check */
+                       if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
+                            recv_buf[3]) & 0xFF) {
+                               printk(KERN_ERR ">%s: Checksum Error : "
+                                       "Received data[%02x, %02x, %02x, %02x]"
+                                       "\n", __func__, recv_buf[0],
+                                       recv_buf[1], recv_buf[2], recv_buf[3]);
+                       } else {
+                               /* Check Received Data */
+                               if (correct_ack[0] == recv_buf[0] &&
+                                   correct_ack[1] == recv_buf[1] &&
+                                   correct_ack[2] == recv_buf[2]) {
+                                       /* Interval for next command */
+                                       mdelay(10);
+
+                                       /* Receive ACK */
+                                       return 0;
+                               }
+                       }
+                       /* Received NAK or illegal Data */
+                       printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
+                                       "Received\n", __func__);
+               }
+       } while (retry--);
+
+       /* Interval for next command */
+       mdelay(10);
+
+       return -1;
+}
+
+static void kurobox_pro_power_off(void)
+{
+       const unsigned char watchdogkill[]      = {0x01, 0x35, 0x00};
+       const unsigned char shutdownwait[]      = {0x00, 0x0c};
+       const unsigned char poweroff[]          = {0x00, 0x06};
+       /* 38400 baud divisor */
+       const unsigned divisor = ((ORION5X_TCLK + (8 * 38400)) / (16 * 38400));
+
+       pr_info("%s: triggering power-off...\n", __func__);
+
+       /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
+       writel(0x83, UART1_REG(LCR));
+       writel(divisor & 0xff, UART1_REG(DLL));
+       writel((divisor >> 8) & 0xff, UART1_REG(DLM));
+       writel(0x1b, UART1_REG(LCR));
+       writel(0x00, UART1_REG(IER));
+       writel(0x07, UART1_REG(FCR));
+       writel(0x00, UART1_REG(MCR));
+
+       /* Send the commands to shutdown the Kurobox Pro */
+       kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
+       kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
+       kurobox_pro_miconsend(poweroff, sizeof(poweroff));
+}
+
 /*****************************************************************************
  * General Setup
  ****************************************************************************/
+static struct orion5x_mpp_mode kurobox_pro_mpp_modes[] __initdata = {
+       {  0, MPP_UNUSED },
+       {  1, MPP_UNUSED },
+       {  2, MPP_GPIO },               /* GPIO Micon */
+       {  3, MPP_GPIO },               /* GPIO Rtc */
+       {  4, MPP_UNUSED },
+       {  5, MPP_UNUSED },
+       {  6, MPP_NAND },               /* NAND Flash REn */
+       {  7, MPP_NAND },               /* NAND Flash WEn */
+       {  8, MPP_UNUSED },
+       {  9, MPP_UNUSED },
+       { 10, MPP_UNUSED },
+       { 11, MPP_UNUSED },
+       { 12, MPP_SATA_LED },           /* SATA 0 presence */
+       { 13, MPP_SATA_LED },           /* SATA 1 presence */
+       { 14, MPP_SATA_LED },           /* SATA 0 active */
+       { 15, MPP_SATA_LED },           /* SATA 1 active */
+       { 16, MPP_UART },               /* UART1 RXD */
+       { 17, MPP_UART },               /* UART1 TXD */
+       { 18, MPP_UART },               /* UART1 CTSn */
+       { 19, MPP_UART },               /* UART1 RTSn */
+       { -1 },
+};
 
 static void __init kurobox_pro_init(void)
 {
@@ -189,46 +344,33 @@ static void __init kurobox_pro_init(void)
         */
        orion5x_init();
 
-       /*
-        * Setup the CPU address decode windows for our devices
-        */
-       orion5x_setup_dev_boot_win(KUROBOX_PRO_NOR_BOOT_BASE,
-                               KUROBOX_PRO_NOR_BOOT_SIZE);
-       orion5x_setup_dev0_win(KUROBOX_PRO_NAND_BASE, KUROBOX_PRO_NAND_SIZE);
+       orion5x_mpp_conf(kurobox_pro_mpp_modes);
 
        /*
-        * Open a special address decode windows for the PCIe WA.
+        * Configure peripherals.
         */
-       orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
-                               ORION5X_PCIE_WA_SIZE);
-
-       /*
-        * Setup Multiplexing Pins --
-        * MPP[0-1] Not used
-        * MPP[2] GPIO Micon
-        * MPP[3] GPIO RTC
-        * MPP[4-5] Not used
-        * MPP[6] Nand Flash REn
-        * MPP[7] Nand Flash WEn
-        * MPP[8-11] Not used
-        * MPP[12] SATA 0 presence Indication
-        * MPP[13] SATA 1 presence Indication
-        * MPP[14] SATA 0 active Indication
-        * MPP[15] SATA 1 active indication
-        * MPP[16-19] Not used
-        */
-       orion5x_write(MPP_0_7_CTRL, 0x44220003);
-       orion5x_write(MPP_8_15_CTRL, 0x55550000);
-       orion5x_write(MPP_16_19_CTRL, 0x0);
-
-       orion5x_gpio_set_valid_pins(0x0000000c);
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       orion5x_eth_init(&kurobox_pro_eth_data);
+       orion5x_i2c_init();
+       orion5x_sata_init(&kurobox_pro_sata_data);
+       orion5x_uart0_init();
+       orion5x_uart1_init();
 
+       orion5x_setup_dev_boot_win(KUROBOX_PRO_NOR_BOOT_BASE,
+                                  KUROBOX_PRO_NOR_BOOT_SIZE);
        platform_device_register(&kurobox_pro_nor_flash);
-       if (machine_is_kurobox_pro())
+
+       if (machine_is_kurobox_pro()) {
+               orion5x_setup_dev0_win(KUROBOX_PRO_NAND_BASE,
+                                      KUROBOX_PRO_NAND_SIZE);
                platform_device_register(&kurobox_pro_nand_flash);
+       }
+
        i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
-       orion5x_eth_init(&kurobox_pro_eth_data);
-       orion5x_sata_init(&kurobox_pro_sata_data);
+
+       /* register Kurobox Pro specific power-off method */
+       pm_power_off = kurobox_pro_power_off;
 }
 
 #ifdef CONFIG_MACH_KUROBOX_PRO
diff --git a/arch/arm/mach-orion5x/mpp.c b/arch/arm/mach-orion5x/mpp.c
new file mode 100644 (file)
index 0000000..a48cadb
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * arch/arm/mach-orion5x/mpp.c
+ *
+ * MPP functions for Marvell Orion 5x SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/mbus.h>
+#include <asm/hardware.h>
+#include <asm/io.h>
+#include "common.h"
+#include "mpp.h"
+
+static int is_5181l(void)
+{
+       u32 dev;
+       u32 rev;
+
+       orion5x_pcie_id(&dev, &rev);
+
+       return !!(dev == MV88F5181_DEV_ID && rev >= MV88F5181L_REV_A0);
+}
+
+static int is_5182(void)
+{
+       u32 dev;
+       u32 rev;
+
+       orion5x_pcie_id(&dev, &rev);
+
+       return !!(dev == MV88F5182_DEV_ID);
+}
+
+static int is_5281(void)
+{
+       u32 dev;
+       u32 rev;
+
+       orion5x_pcie_id(&dev, &rev);
+
+       return !!(dev == MV88F5281_DEV_ID);
+}
+
+static int __init determine_type_encoding(int mpp, enum orion5x_mpp_type type)
+{
+       switch (type) {
+       case MPP_UNUSED:
+       case MPP_GPIO:
+               if (mpp == 0)
+                       return 3;
+               if (mpp >= 1 && mpp <= 15)
+                       return 0;
+               if (mpp >= 16 && mpp <= 19) {
+                       if (is_5182())
+                               return 5;
+                       if (type == MPP_UNUSED)
+                               return 0;
+               }
+               return -1;
+
+       case MPP_PCIE_RST_OUTn:
+               if (mpp == 0)
+                       return 0;
+               return -1;
+
+       case MPP_PCI_ARB:
+               if (mpp >= 0 && mpp <= 7)
+                       return 2;
+               return -1;
+
+       case MPP_PCI_PMEn:
+               if (mpp == 2)
+                       return 3;
+               return -1;
+
+       case MPP_GIGE:
+               if (mpp >= 8 && mpp <= 19)
+                       return 1;
+               return -1;
+
+       case MPP_NAND:
+               if (is_5182() || is_5281()) {
+                       if (mpp >= 4 && mpp <= 7)
+                               return 4;
+                       if (mpp >= 12 && mpp <= 17)
+                               return 4;
+               }
+               return -1;
+
+       case MPP_PCI_CLK:
+               if (is_5181l() && mpp >= 6 && mpp <= 7)
+                       return 5;
+               return -1;
+
+       case MPP_SATA_LED:
+               if (is_5182()) {
+                       if (mpp >= 4 && mpp <= 7)
+                               return 5;
+                       if (mpp >= 12 && mpp <= 15)
+                               return 5;
+               }
+               return -1;
+
+       case MPP_UART:
+               if (mpp >= 16 && mpp <= 19)
+                       return 0;
+               return -1;
+       }
+
+       printk(KERN_INFO "unknown MPP type %d\n", type);
+
+       return -1;
+}
+
+void __init orion5x_mpp_conf(struct orion5x_mpp_mode *mode)
+{
+       u32 mpp_0_7_ctrl = readl(MPP_0_7_CTRL);
+       u32 mpp_8_15_ctrl = readl(MPP_8_15_CTRL);
+       u32 mpp_16_19_ctrl = readl(MPP_16_19_CTRL);
+
+       while (mode->mpp >= 0) {
+               u32 *reg;
+               int num_type;
+               int shift;
+
+               if (mode->mpp >= 0 && mode->mpp <= 7)
+                       reg = &mpp_0_7_ctrl;
+               else if (mode->mpp >= 8 && mode->mpp <= 15)
+                       reg = &mpp_8_15_ctrl;
+               else if (mode->mpp >= 16 && mode->mpp <= 19)
+                       reg = &mpp_16_19_ctrl;
+               else {
+                       printk(KERN_ERR "orion5x_mpp_conf: invalid MPP "
+                                       "(%d)\n", mode->mpp);
+                       continue;
+               }
+
+               num_type = determine_type_encoding(mode->mpp, mode->type);
+               if (num_type < 0) {
+                       printk(KERN_ERR "orion5x_mpp_conf: invalid MPP "
+                                       "combination (%d, %d)\n", mode->mpp,
+                                       mode->type);
+                       continue;
+               }
+
+               shift = (mode->mpp & 7) << 2;
+               *reg &= ~(0xf << shift);
+               *reg |= (num_type & 0xf) << shift;
+
+               orion5x_gpio_set_valid(mode->mpp, !!(mode->type == MPP_GPIO));
+
+               mode++;
+       }
+
+       writel(mpp_0_7_ctrl, MPP_0_7_CTRL);
+       writel(mpp_8_15_ctrl, MPP_8_15_CTRL);
+       writel(mpp_16_19_ctrl, MPP_16_19_CTRL);
+}
diff --git a/arch/arm/mach-orion5x/mpp.h b/arch/arm/mach-orion5x/mpp.h
new file mode 100644 (file)
index 0000000..290e610
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef __ARCH_ORION5X_MPP_H
+#define __ARCH_ORION5X_MPP_H
+
+enum orion5x_mpp_type {
+       /*
+        * This MPP is unused.
+        */
+       MPP_UNUSED,
+
+       /*
+        * This MPP pin is used as a generic GPIO pin.  Valid for
+        * MPPs 0-15 and device bus data pins 16-31.  On 5182, also
+        * valid for MPPs 16-19.
+        */
+       MPP_GPIO,
+
+       /*
+        * This MPP is used as PCIe_RST_OUTn pin.  Valid for
+        * MPP 0 only.
+        */
+       MPP_PCIE_RST_OUTn,
+
+       /*
+        * This MPP is used as PCI arbiter pin (REQn/GNTn).
+        * Valid for MPPs 0-7 only.
+        */
+       MPP_PCI_ARB,
+
+       /*
+        * This MPP is used as PCI_PMEn pin.  Valid for MPP 2 only.
+        */
+       MPP_PCI_PMEn,
+
+       /*
+        * This MPP is used as GigE half-duplex (COL, CRS) or GMII
+        * (RXERR, CRS, TXERR, TXD[7:4], RXD[7:4]) pin.  Valid for
+        * MPPs 8-19 only.
+        */
+       MPP_GIGE,
+
+       /*
+        * This MPP is used as NAND REn/WEn pin.  Valid for MPPs
+        * 4-7 and 12-17 only, and only on the 5181l/5182/5281.
+        */
+       MPP_NAND,
+
+       /*
+        * This MPP is used as a PCI clock output pin.  Valid for
+        * MPPs 6-7 only, and only on the 5181l.
+        */
+       MPP_PCI_CLK,
+
+       /*
+        * This MPP is used as a SATA presence/activity LED.
+        * Valid for MPPs 4-7 and 12-15 only, and only on the 5182.
+        */
+       MPP_SATA_LED,
+
+       /*
+        * This MPP is used as UART1 RXD/TXD/CTSn/RTSn pin.
+        * Valid for MPPs 16-19 only.
+        */
+       MPP_UART,
+};
+
+struct orion5x_mpp_mode {
+       int                     mpp;
+       enum orion5x_mpp_type   type;
+};
+
+void orion5x_mpp_conf(struct orion5x_mpp_mode *mode);
+
+
+#endif
diff --git a/arch/arm/mach-orion5x/mss2-setup.c b/arch/arm/mach-orion5x/mss2-setup.c
new file mode 100644 (file)
index 0000000..7ce9e40
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * Maxtor Shared Storage II Board Setup
+ *
+ * Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/leds.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/i2c.h>
+#include <linux/ata_platform.h>
+#include <linux/gpio.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+#define MSS2_NOR_BOOT_BASE     0xff800000
+#define MSS2_NOR_BOOT_SIZE     SZ_256K
+
+/*****************************************************************************
+ * Maxtor Shared Storage II Info
+ ****************************************************************************/
+
+/*
+ * Maxtor Shared Storage II hardware :
+ * - Marvell 88F5182-A2 C500
+ * - Marvell 88E1111 Gigabit Ethernet PHY
+ * - RTC M41T81 (@0x68) on I2C bus
+ * - 256KB NOR flash
+ * - 64MB of RAM
+ */
+
+/*****************************************************************************
+ * 256KB NOR Flash on BOOT Device
+ ****************************************************************************/
+
+static struct physmap_flash_data mss2_nor_flash_data = {
+       .width          = 1,
+};
+
+static struct resource mss2_nor_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = MSS2_NOR_BOOT_BASE,
+       .end            = MSS2_NOR_BOOT_BASE + MSS2_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device mss2_nor_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &mss2_nor_flash_data,
+       },
+       .resource       = &mss2_nor_flash_resource,
+       .num_resources  = 1,
+};
+
+/****************************************************************************
+ * PCI setup
+ ****************************************************************************/
+static int __init mss2_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       return -1;
+}
+
+static struct hw_pci mss2_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = mss2_pci_map_irq,
+};
+
+static int __init mss2_pci_init(void)
+{
+       if (machine_is_mss2())
+               pci_common_init(&mss2_pci);
+
+       return 0;
+}
+subsys_initcall(mss2_pci_init);
+
+
+/*****************************************************************************
+ * Ethernet
+ ****************************************************************************/
+
+static struct mv643xx_eth_platform_data mss2_eth_data = {
+       .phy_addr       = 8,
+};
+
+/*****************************************************************************
+ * SATA
+ ****************************************************************************/
+
+static struct mv_sata_platform_data mss2_sata_data = {
+       .n_ports        = 2,
+};
+
+/*****************************************************************************
+ * GPIO buttons
+ ****************************************************************************/
+
+#define MSS2_GPIO_KEY_RESET    12
+#define MSS2_GPIO_KEY_POWER    11
+
+static struct gpio_keys_button mss2_buttons[] = {
+       {
+               .code           = KEY_POWER,
+               .gpio           = MSS2_GPIO_KEY_POWER,
+               .desc           = "Power",
+               .active_low     = 1,
+       }, {
+               .code           = KEY_RESTART,
+               .gpio           = MSS2_GPIO_KEY_RESET,
+               .desc           = "Reset",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data mss2_button_data = {
+       .buttons        = mss2_buttons,
+       .nbuttons       = ARRAY_SIZE(mss2_buttons),
+};
+
+static struct platform_device mss2_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &mss2_button_data,
+       },
+};
+
+/*****************************************************************************
+ * RTC m41t81 on I2C bus
+ ****************************************************************************/
+
+#define MSS2_GPIO_RTC_IRQ      3
+
+static struct i2c_board_info __initdata mss2_i2c_rtc = {
+       I2C_BOARD_INFO("m41t81", 0x68),
+};
+
+/*****************************************************************************
+ * MSS2 power off method
+ ****************************************************************************/
+/*
+ * On the Maxtor Shared Storage II, the shutdown process is the following :
+ * - Userland modifies U-boot env to tell U-boot to go idle at next boot
+ * - The board reboots
+ * - U-boot starts and go into an idle mode until the user press "power"
+ */
+static void mss2_power_off(void)
+{
+       u32 reg;
+
+       /*
+        * Enable and issue soft reset
+        */
+       reg = readl(CPU_RESET_MASK);
+       reg |= 1 << 2;
+       writel(reg, CPU_RESET_MASK);
+
+       reg = readl(CPU_SOFT_RESET);
+       reg |= 1;
+       writel(reg, CPU_SOFT_RESET);
+}
+
+/****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode mss2_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* Power LED */
+       {  1, MPP_GPIO },               /* Error LED */
+       {  2, MPP_UNUSED },
+       {  3, MPP_GPIO },               /* RTC interrupt */
+       {  4, MPP_GPIO },               /* HDD ind. (Single/Dual)*/
+       {  5, MPP_GPIO },               /* HD0 5V control */
+       {  6, MPP_GPIO },               /* HD0 12V control */
+       {  7, MPP_GPIO },               /* HD1 5V control */
+       {  8, MPP_GPIO },               /* HD1 12V control */
+       {  9, MPP_UNUSED },
+       { 10, MPP_GPIO },               /* Fan control */
+       { 11, MPP_GPIO },               /* Power button */
+       { 12, MPP_GPIO },               /* Reset button */
+       { 13, MPP_UNUSED },
+       { 14, MPP_SATA_LED },           /* SATA 0 active */
+       { 15, MPP_SATA_LED },           /* SATA 1 active */
+       { 16, MPP_UNUSED },
+       { 17, MPP_UNUSED },
+       { 18, MPP_UNUSED },
+       { 19, MPP_UNUSED },
+       { -1 },
+};
+
+static void __init mss2_init(void)
+{
+       /* Setup basic Orion functions. Need to be called early. */
+       orion5x_init();
+
+       orion5x_mpp_conf(mss2_mpp_modes);
+
+       /*
+        * MPP[20] Unused
+        * MPP[21] PCI clock
+        * MPP[22] USB 0 over current
+        * MPP[23] USB 1 over current
+        */
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       orion5x_eth_init(&mss2_eth_data);
+       orion5x_i2c_init();
+       orion5x_sata_init(&mss2_sata_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(MSS2_NOR_BOOT_BASE, MSS2_NOR_BOOT_SIZE);
+       platform_device_register(&mss2_nor_flash);
+
+       platform_device_register(&mss2_button_device);
+
+       if (gpio_request(MSS2_GPIO_RTC_IRQ, "rtc") == 0) {
+               if (gpio_direction_input(MSS2_GPIO_RTC_IRQ) == 0)
+                       mss2_i2c_rtc.irq = gpio_to_irq(MSS2_GPIO_RTC_IRQ);
+               else
+                       gpio_free(MSS2_GPIO_RTC_IRQ);
+       }
+       i2c_register_board_info(0, &mss2_i2c_rtc, 1);
+
+       /* register mss2 specific power-off method */
+       pm_power_off = mss2_power_off;
+}
+
+MACHINE_START(MSS2, "Maxtor Shared Storage II")
+       /* Maintainer: Sylver Bruneau <sylver.bruneau@googlemail.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = mss2_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32
+MACHINE_END
diff --git a/arch/arm/mach-orion5x/mv2120-setup.c b/arch/arm/mach-orion5x/mv2120-setup.c
new file mode 100644 (file)
index 0000000..55f3b0f
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
+ * Copyright (C) 2008 Martin Michlmayr <tbm@cyrius.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/leds.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/i2c.h>
+#include <linux/ata_platform.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/mach/arch.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+#define MV2120_NOR_BOOT_BASE   0xf4000000
+#define MV2120_NOR_BOOT_SIZE   SZ_512K
+
+#define MV2120_GPIO_RTC_IRQ    3
+#define MV2120_GPIO_KEY_RESET  17
+#define MV2120_GPIO_KEY_POWER  18
+#define MV2120_GPIO_POWER_OFF  19
+
+
+/*****************************************************************************
+ * Ethernet
+ ****************************************************************************/
+static struct mv643xx_eth_platform_data mv2120_eth_data = {
+       .phy_addr       = 8,
+};
+
+static struct mv_sata_platform_data mv2120_sata_data = {
+       .n_ports        = 2,
+};
+
+static struct mtd_partition mv2120_partitions[] = {
+       {
+               .name   = "firmware",
+               .size   = 0x00080000,
+               .offset = 0,
+       },
+};
+
+static struct physmap_flash_data mv2120_nor_flash_data = {
+       .width          = 1,
+       .parts          = mv2120_partitions,
+       .nr_parts       = ARRAY_SIZE(mv2120_partitions)
+};
+
+static struct resource mv2120_nor_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = MV2120_NOR_BOOT_BASE,
+       .end            = MV2120_NOR_BOOT_BASE + MV2120_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device mv2120_nor_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &mv2120_nor_flash_data,
+       },
+       .resource       = &mv2120_nor_flash_resource,
+       .num_resources  = 1,
+};
+
+static struct gpio_keys_button mv2120_buttons[] = {
+       {
+               .code           = KEY_RESTART,
+               .gpio           = MV2120_GPIO_KEY_RESET,
+               .desc           = "reset",
+               .active_low     = 1,
+       }, {
+               .code           = KEY_POWER,
+               .gpio           = MV2120_GPIO_KEY_POWER,
+               .desc           = "power",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data mv2120_button_data = {
+       .buttons        = mv2120_buttons,
+       .nbuttons       = ARRAY_SIZE(mv2120_buttons),
+};
+
+static struct platform_device mv2120_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &mv2120_button_data,
+       },
+};
+
+
+/****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode mv2120_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* Sys status LED */
+       {  1, MPP_GPIO },               /* Sys error LED */
+       {  2, MPP_GPIO },               /* OverTemp interrupt */
+       {  3, MPP_GPIO },               /* RTC interrupt */
+       {  4, MPP_GPIO },               /* V_LED 5V */
+       {  5, MPP_GPIO },               /* V_LED 3.3V */
+       {  6, MPP_UNUSED },
+       {  7, MPP_UNUSED },
+       {  8, MPP_GPIO },               /* SATA 0 fail LED */
+       {  9, MPP_GPIO },               /* SATA 1 fail LED */
+       { 10, MPP_UNUSED },
+       { 11, MPP_UNUSED },
+       { 12, MPP_SATA_LED },           /* SATA 0 presence */
+       { 13, MPP_SATA_LED },           /* SATA 1 presence */
+       { 14, MPP_SATA_LED },           /* SATA 0 active */
+       { 15, MPP_SATA_LED },           /* SATA 1 active */
+       { 16, MPP_UNUSED },
+       { 17, MPP_GPIO },               /* Reset button */
+       { 18, MPP_GPIO },               /* Power button */
+       { 19, MPP_GPIO },               /* Power off */
+       { -1 },
+};
+
+static struct i2c_board_info __initdata mv2120_i2c_rtc = {
+       I2C_BOARD_INFO("pcf8563", 0x51),
+       .irq    = 0,
+};
+
+static struct gpio_led mv2120_led_pins[] = {
+       {
+               .name                   = "mv2120:blue:health",
+               .gpio                   = 0,
+       },
+       {
+               .name                   = "mv2120:red:health",
+               .gpio                   = 1,
+       },
+       {
+               .name                   = "mv2120:led:bright",
+               .gpio                   = 4,
+               .default_trigger        = "default-on",
+       },
+       {
+               .name                   = "mv2120:led:dimmed",
+               .gpio                   = 5,
+       },
+       {
+               .name                   = "mv2120:red:sata0",
+               .gpio                   = 8,
+               .active_low             = 1,
+       },
+       {
+               .name                   = "mv2120:red:sata1",
+               .gpio                   = 9,
+               .active_low             = 1,
+       },
+
+};
+
+static struct gpio_led_platform_data mv2120_led_data = {
+       .leds           = mv2120_led_pins,
+       .num_leds       = ARRAY_SIZE(mv2120_led_pins),
+};
+
+static struct platform_device mv2120_leds = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &mv2120_led_data,
+       }
+};
+
+static void mv2120_power_off(void)
+{
+       pr_info("%s: triggering power-off...\n", __func__);
+       gpio_set_value(MV2120_GPIO_POWER_OFF, 0);
+}
+
+static void __init mv2120_init(void)
+{
+       /* Setup basic Orion functions. Need to be called early. */
+       orion5x_init();
+
+       orion5x_mpp_conf(mv2120_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       orion5x_eth_init(&mv2120_eth_data);
+       orion5x_i2c_init();
+       orion5x_sata_init(&mv2120_sata_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(MV2120_NOR_BOOT_BASE, MV2120_NOR_BOOT_SIZE);
+       platform_device_register(&mv2120_nor_flash);
+
+       platform_device_register(&mv2120_button_device);
+
+       if (gpio_request(MV2120_GPIO_RTC_IRQ, "rtc") == 0) {
+               if (gpio_direction_input(MV2120_GPIO_RTC_IRQ) == 0)
+                       mv2120_i2c_rtc.irq = gpio_to_irq(MV2120_GPIO_RTC_IRQ);
+               else
+                       gpio_free(MV2120_GPIO_RTC_IRQ);
+       }
+       i2c_register_board_info(0, &mv2120_i2c_rtc, 1);
+       platform_device_register(&mv2120_leds);
+
+       /* register mv2120 specific power-off method */
+       if (gpio_request(MV2120_GPIO_POWER_OFF, "POWEROFF") != 0 ||
+           gpio_direction_output(MV2120_GPIO_POWER_OFF, 1) != 0)
+               pr_err("mv2120: failed to setup power-off GPIO\n");
+       pm_power_off = mv2120_power_off;
+}
+
+/* Warning: HP uses a wrong mach-type (=526) in their bootloader */
+MACHINE_START(MV2120, "HP Media Vault mv2120")
+       /* Maintainer: Martin Michlmayr <tbm@cyrius.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = mv2120_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32
+MACHINE_END
index 9d5d39f..256a4f6 100644 (file)
@@ -152,6 +152,8 @@ static int __init pcie_setup(struct pci_sys_data *sys)
        if (dev == MV88F5181_DEV_ID || dev == MV88F5182_DEV_ID) {
                printk(KERN_NOTICE "Applying Orion-1/Orion-NAS PCIe config "
                                   "read transaction workaround\n");
+               orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
+                                         ORION5X_PCIE_WA_SIZE);
                pcie_ops.read = pcie_rd_conf_wa;
        }
 
@@ -240,13 +242,13 @@ static int __init pcie_setup(struct pci_sys_data *sys)
  * PCI Address Decode Windows registers
  */
 #define PCI_BAR_SIZE_DDR_CS(n) (((n) == 0) ? ORION5X_PCI_REG(0xc08) : \
-                               ((n) == 1) ? ORION5X_PCI_REG(0xd08) :  \
-                               ((n) == 2) ? ORION5X_PCI_REG(0xc0c) :  \
-                               ((n) == 3) ? ORION5X_PCI_REG(0xd0c) : 0)
-#define PCI_BAR_REMAP_DDR_CS(n)        (((n) ==0) ? ORION5X_PCI_REG(0xc48) :  \
-                               ((n) == 1) ? ORION5X_PCI_REG(0xd48) :  \
-                               ((n) == 2) ? ORION5X_PCI_REG(0xc4c) :  \
-                               ((n) == 3) ? ORION5X_PCI_REG(0xd4c) : 0)
+                                ((n) == 1) ? ORION5X_PCI_REG(0xd08) : \
+                                ((n) == 2) ? ORION5X_PCI_REG(0xc0c) : \
+                                ((n) == 3) ? ORION5X_PCI_REG(0xd0c) : 0)
+#define PCI_BAR_REMAP_DDR_CS(n)        (((n) == 0) ? ORION5X_PCI_REG(0xc48) : \
+                                ((n) == 1) ? ORION5X_PCI_REG(0xd48) : \
+                                ((n) == 2) ? ORION5X_PCI_REG(0xc4c) : \
+                                ((n) == 3) ? ORION5X_PCI_REG(0xd4c) : 0)
 #define PCI_BAR_ENABLE         ORION5X_PCI_REG(0xc3c)
 #define PCI_ADDR_DECODE_CTRL   ORION5X_PCI_REG(0xd3c)
 
@@ -264,9 +266,11 @@ static int __init pcie_setup(struct pci_sys_data *sys)
  */
 static DEFINE_SPINLOCK(orion5x_pci_lock);
 
+static int orion5x_pci_cardbus_mode;
+
 static int orion5x_pci_local_bus_nr(void)
 {
-       u32 conf = orion5x_read(PCI_P2P_CONF);
+       u32 conf = readl(PCI_P2P_CONF);
        return((conf & PCI_P2P_BUS_MASK) >> PCI_P2P_BUS_OFFS);
 }
 
@@ -276,11 +280,11 @@ static int orion5x_pci_hw_rd_conf(int bus, int dev, u32 func,
        unsigned long flags;
        spin_lock_irqsave(&orion5x_pci_lock, flags);
 
-       orion5x_write(PCI_CONF_ADDR, PCI_CONF_BUS(bus) |
-                       PCI_CONF_DEV(dev) | PCI_CONF_REG(where) |
-                       PCI_CONF_FUNC(func) | PCI_CONF_ADDR_EN);
+       writel(PCI_CONF_BUS(bus) |
+               PCI_CONF_DEV(dev) | PCI_CONF_REG(where) |
+               PCI_CONF_FUNC(func) | PCI_CONF_ADDR_EN, PCI_CONF_ADDR);
 
-       *val = orion5x_read(PCI_CONF_DATA);
+       *val = readl(PCI_CONF_DATA);
 
        if (size == 1)
                *val = (*val >> (8*(where & 0x3))) & 0xff;
@@ -300,9 +304,9 @@ static int orion5x_pci_hw_wr_conf(int bus, int dev, u32 func,
 
        spin_lock_irqsave(&orion5x_pci_lock, flags);
 
-       orion5x_write(PCI_CONF_ADDR, PCI_CONF_BUS(bus) |
-                       PCI_CONF_DEV(dev) | PCI_CONF_REG(where) |
-                       PCI_CONF_FUNC(func) | PCI_CONF_ADDR_EN);
+       writel(PCI_CONF_BUS(bus) |
+               PCI_CONF_DEV(dev) | PCI_CONF_REG(where) |
+               PCI_CONF_FUNC(func) | PCI_CONF_ADDR_EN, PCI_CONF_ADDR);
 
        if (size == 4) {
                __raw_writel(val, PCI_CONF_DATA);
@@ -319,14 +323,30 @@ static int orion5x_pci_hw_wr_conf(int bus, int dev, u32 func,
        return ret;
 }
 
+static int orion5x_pci_valid_config(int bus, u32 devfn)
+{
+       if (bus == orion5x_pci_local_bus_nr()) {
+               /*
+                * Don't go out for local device
+                */
+               if (PCI_SLOT(devfn) == 0 && PCI_FUNC(devfn) != 0)
+                       return 0;
+
+               /*
+                * When the PCI signals are directly connected to a
+                * Cardbus slot, ignore all but device IDs 0 and 1.
+                */
+               if (orion5x_pci_cardbus_mode && PCI_SLOT(devfn) > 1)
+                       return 0;
+       }
+
+       return 1;
+}
+
 static int orion5x_pci_rd_conf(struct pci_bus *bus, u32 devfn,
                                int where, int size, u32 *val)
 {
-       /*
-        * Don't go out for local device
-        */
-       if (bus->number == orion5x_pci_local_bus_nr() &&
-           PCI_SLOT(devfn) == 0 && PCI_FUNC(devfn) != 0) {
+       if (!orion5x_pci_valid_config(bus->number, devfn)) {
                *val = 0xffffffff;
                return PCIBIOS_DEVICE_NOT_FOUND;
        }
@@ -338,8 +358,7 @@ static int orion5x_pci_rd_conf(struct pci_bus *bus, u32 devfn,
 static int orion5x_pci_wr_conf(struct pci_bus *bus, u32 devfn,
                                int where, int size, u32 val)
 {
-       if (bus->number == orion5x_pci_local_bus_nr() &&
-           PCI_SLOT(devfn) == 0 && PCI_FUNC(devfn) != 0)
+       if (!orion5x_pci_valid_config(bus->number, devfn))
                return PCIBIOS_DEVICE_NOT_FOUND;
 
        return orion5x_pci_hw_wr_conf(bus->number, PCI_SLOT(devfn),
@@ -353,9 +372,9 @@ static struct pci_ops pci_ops = {
 
 static void __init orion5x_pci_set_bus_nr(int nr)
 {
-       u32 p2p = orion5x_read(PCI_P2P_CONF);
+       u32 p2p = readl(PCI_P2P_CONF);
 
-       if (orion5x_read(PCI_MODE) & PCI_MODE_PCIX) {
+       if (readl(PCI_MODE) & PCI_MODE_PCIX) {
                /*
                 * PCI-X mode
                 */
@@ -372,7 +391,7 @@ static void __init orion5x_pci_set_bus_nr(int nr)
                 */
                p2p &= ~PCI_P2P_BUS_MASK;
                p2p |= (nr << PCI_P2P_BUS_OFFS);
-               orion5x_write(PCI_P2P_CONF, p2p);
+               writel(p2p, PCI_P2P_CONF);
        }
 }
 
@@ -399,7 +418,7 @@ static void __init orion5x_setup_pci_wins(struct mbus_dram_target_info *dram)
         * First, disable windows.
         */
        win_enable = 0xffffffff;
-       orion5x_write(PCI_BAR_ENABLE, win_enable);
+       writel(win_enable, PCI_BAR_ENABLE);
 
        /*
         * Setup windows for DDR banks.
@@ -425,10 +444,10 @@ static void __init orion5x_setup_pci_wins(struct mbus_dram_target_info *dram)
                 */
                reg = PCI_CONF_REG_BAR_HI_CS(cs->cs_index);
                orion5x_pci_hw_wr_conf(bus, 0, func, reg, 4, 0);
-               orion5x_write(PCI_BAR_SIZE_DDR_CS(cs->cs_index),
-                               (cs->size - 1) & 0xfffff000);
-               orion5x_write(PCI_BAR_REMAP_DDR_CS(cs->cs_index),
-                               cs->base & 0xfffff000);
+               writel((cs->size - 1) & 0xfffff000,
+                       PCI_BAR_SIZE_DDR_CS(cs->cs_index));
+               writel(cs->base & 0xfffff000,
+                       PCI_BAR_REMAP_DDR_CS(cs->cs_index));
 
                /*
                 * Enable decode window for this chip select.
@@ -439,7 +458,7 @@ static void __init orion5x_setup_pci_wins(struct mbus_dram_target_info *dram)
        /*
         * Re-enable decode windows.
         */
-       orion5x_write(PCI_BAR_ENABLE, win_enable);
+       writel(win_enable, PCI_BAR_ENABLE);
 
        /*
         * Disable automatic update of address remaping when writing to BARs.
@@ -522,6 +541,11 @@ static void __devinit rc_pci_fixup(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
 
+void __init orion5x_pci_set_cardbus_mode(void)
+{
+       orion5x_pci_cardbus_mode = 1;
+}
+
 int __init orion5x_pci_sys_setup(int nr, struct pci_sys_data *sys)
 {
        int ret = 0;
diff --git a/arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c b/arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c
new file mode 100644 (file)
index 0000000..d50e365
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * arch/arm/mach-orion5x/rd88f5181l-fxo-setup.c
+ *
+ * Marvell Orion-VoIP FXO Reference Design Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/leds.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+/*****************************************************************************
+ * RD-88F5181L FXO Info
+ ****************************************************************************/
+/*
+ * 8M NOR flash Device bus boot chip select
+ */
+#define RD88F5181L_FXO_NOR_BOOT_BASE           0xff800000
+#define RD88F5181L_FXO_NOR_BOOT_SIZE           SZ_8M
+
+
+/*****************************************************************************
+ * 8M NOR Flash on Device bus Boot chip select
+ ****************************************************************************/
+static struct physmap_flash_data rd88f5181l_fxo_nor_boot_flash_data = {
+       .width          = 1,
+};
+
+static struct resource rd88f5181l_fxo_nor_boot_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = RD88F5181L_FXO_NOR_BOOT_BASE,
+       .end            = RD88F5181L_FXO_NOR_BOOT_BASE +
+                         RD88F5181L_FXO_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device rd88f5181l_fxo_nor_boot_flash = {
+       .name                   = "physmap-flash",
+       .id                     = 0,
+       .dev            = {
+               .platform_data  = &rd88f5181l_fxo_nor_boot_flash_data,
+       },
+       .num_resources          = 1,
+       .resource               = &rd88f5181l_fxo_nor_boot_flash_resource,
+};
+
+
+/*****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode rd88f5181l_fxo_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* LED1 CardBus LED (front panel) */
+       {  1, MPP_GPIO },               /* PCI_intA */
+       {  2, MPP_GPIO },               /* Hard Reset / Factory Init*/
+       {  3, MPP_GPIO },               /* FXS or DAA select */
+       {  4, MPP_GPIO },               /* LED6 - phone LED (front panel) */
+       {  5, MPP_GPIO },               /* LED5 - phone LED (front panel) */
+       {  6, MPP_PCI_CLK },            /* CPU PCI refclk */
+       {  7, MPP_PCI_CLK },            /* PCI/PCIe refclk */
+       {  8, MPP_GPIO },               /* CardBus reset */
+       {  9, MPP_GPIO },               /* GE_RXERR */
+       { 10, MPP_GPIO },               /* LED2 MiniPCI LED (front panel) */
+       { 11, MPP_GPIO },               /* Lifeline control */
+       { 12, MPP_GIGE },               /* GE_TXD[4] */
+       { 13, MPP_GIGE },               /* GE_TXD[5] */
+       { 14, MPP_GIGE },               /* GE_TXD[6] */
+       { 15, MPP_GIGE },               /* GE_TXD[7] */
+       { 16, MPP_GIGE },               /* GE_RXD[4] */
+       { 17, MPP_GIGE },               /* GE_RXD[5] */
+       { 18, MPP_GIGE },               /* GE_RXD[6] */
+       { 19, MPP_GIGE },               /* GE_RXD[7] */
+       { -1 },
+};
+
+static struct mv643xx_eth_platform_data rd88f5181l_fxo_eth_data = {
+       .phy_addr       = -1,
+};
+
+static void __init rd88f5181l_fxo_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       orion5x_mpp_conf(rd88f5181l_fxo_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_eth_init(&rd88f5181l_fxo_eth_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(RD88F5181L_FXO_NOR_BOOT_BASE,
+                                  RD88F5181L_FXO_NOR_BOOT_SIZE);
+       platform_device_register(&rd88f5181l_fxo_nor_boot_flash);
+}
+
+static int __init
+rd88f5181l_fxo_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       /*
+        * Mini-PCI / Cardbus slot.
+        */
+       return gpio_to_irq(1);
+}
+
+static struct hw_pci rd88f5181l_fxo_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = rd88f5181l_fxo_pci_map_irq,
+};
+
+static int __init rd88f5181l_fxo_pci_init(void)
+{
+       if (machine_is_rd88f5181l_fxo()) {
+               orion5x_pci_set_cardbus_mode();
+               pci_common_init(&rd88f5181l_fxo_pci);
+       }
+
+       return 0;
+}
+subsys_initcall(rd88f5181l_fxo_pci_init);
+
+MACHINE_START(RD88F5181L_FXO, "Marvell Orion-VoIP FXO Reference Design")
+       /* Maintainer: Nicolas Pitre <nico@marvell.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = rd88f5181l_fxo_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32,
+MACHINE_END
diff --git a/arch/arm/mach-orion5x/rd88f5181l-ge-setup.c b/arch/arm/mach-orion5x/rd88f5181l-ge-setup.c
new file mode 100644 (file)
index 0000000..b56447d
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * arch/arm/mach-orion5x/rd88f5181l-ge-setup.c
+ *
+ * Marvell Orion-VoIP GE Reference Design Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/i2c.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/leds.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+/*****************************************************************************
+ * RD-88F5181L GE Info
+ ****************************************************************************/
+/*
+ * 16M NOR flash Device bus boot chip select
+ */
+#define RD88F5181L_GE_NOR_BOOT_BASE            0xff000000
+#define RD88F5181L_GE_NOR_BOOT_SIZE            SZ_16M
+
+
+/*****************************************************************************
+ * 16M NOR Flash on Device bus Boot chip select
+ ****************************************************************************/
+static struct physmap_flash_data rd88f5181l_ge_nor_boot_flash_data = {
+       .width          = 1,
+};
+
+static struct resource rd88f5181l_ge_nor_boot_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = RD88F5181L_GE_NOR_BOOT_BASE,
+       .end            = RD88F5181L_GE_NOR_BOOT_BASE +
+                         RD88F5181L_GE_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device rd88f5181l_ge_nor_boot_flash = {
+       .name                   = "physmap-flash",
+       .id                     = 0,
+       .dev            = {
+               .platform_data  = &rd88f5181l_ge_nor_boot_flash_data,
+       },
+       .num_resources          = 1,
+       .resource               = &rd88f5181l_ge_nor_boot_flash_resource,
+};
+
+
+/*****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode rd88f5181l_ge_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* LED1 */
+       {  1, MPP_GPIO },               /* LED5 */
+       {  2, MPP_GPIO },               /* LED4 */
+       {  3, MPP_GPIO },               /* LED3 */
+       {  4, MPP_GPIO },               /* PCI_intA */
+       {  5, MPP_GPIO },               /* RTC interrupt */
+       {  6, MPP_PCI_CLK },            /* CPU PCI refclk */
+       {  7, MPP_PCI_CLK },            /* PCI/PCIe refclk */
+       {  8, MPP_GPIO },               /* 88e6131 interrupt */
+       {  9, MPP_GPIO },               /* GE_RXERR */
+       { 10, MPP_GPIO },               /* PCI_intB */
+       { 11, MPP_GPIO },               /* LED2 */
+       { 12, MPP_GIGE },               /* GE_TXD[4] */
+       { 13, MPP_GIGE },               /* GE_TXD[5] */
+       { 14, MPP_GIGE },               /* GE_TXD[6] */
+       { 15, MPP_GIGE },               /* GE_TXD[7] */
+       { 16, MPP_GIGE },               /* GE_RXD[4] */
+       { 17, MPP_GIGE },               /* GE_RXD[5] */
+       { 18, MPP_GIGE },               /* GE_RXD[6] */
+       { 19, MPP_GIGE },               /* GE_RXD[7] */
+       { -1 },
+};
+
+static struct mv643xx_eth_platform_data rd88f5181l_ge_eth_data = {
+       .phy_addr       = -1,
+};
+
+static struct i2c_board_info __initdata rd88f5181l_ge_i2c_rtc = {
+       I2C_BOARD_INFO("ds1338", 0x68),
+};
+
+static void __init rd88f5181l_ge_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       orion5x_mpp_conf(rd88f5181l_ge_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_eth_init(&rd88f5181l_ge_eth_data);
+       orion5x_i2c_init();
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(RD88F5181L_GE_NOR_BOOT_BASE,
+                                  RD88F5181L_GE_NOR_BOOT_SIZE);
+       platform_device_register(&rd88f5181l_ge_nor_boot_flash);
+
+       i2c_register_board_info(0, &rd88f5181l_ge_i2c_rtc, 1);
+}
+
+static int __init
+rd88f5181l_ge_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       /*
+        * Cardbus slot.
+        */
+       if (pin == 1)
+               return gpio_to_irq(4);
+       else
+               return gpio_to_irq(10);
+}
+
+static struct hw_pci rd88f5181l_ge_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = rd88f5181l_ge_pci_map_irq,
+};
+
+static int __init rd88f5181l_ge_pci_init(void)
+{
+       if (machine_is_rd88f5181l_ge()) {
+               orion5x_pci_set_cardbus_mode();
+               pci_common_init(&rd88f5181l_ge_pci);
+       }
+
+       return 0;
+}
+subsys_initcall(rd88f5181l_ge_pci_init);
+
+MACHINE_START(RD88F5181L_GE, "Marvell Orion-VoIP GE Reference Design")
+       /* Maintainer: Lennert Buytenhek <buytenh@marvell.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = rd88f5181l_ge_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32,
+MACHINE_END
index 81abc10..10ae628 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/mach/pci.h>
 #include <asm/arch/orion5x.h>
 #include "common.h"
+#include "mpp.h"
 
 /*****************************************************************************
  * RD-88F5182 Info
@@ -125,6 +126,7 @@ static int __init rd88f5182_dbgled_init(void)
 
                leds_event = rd88f5182_dbgled_event;
        }
+
        return 0;
 }
 
@@ -220,7 +222,6 @@ subsys_initcall(rd88f5182_pci_init);
 
 static struct mv643xx_eth_platform_data rd88f5182_eth_data = {
        .phy_addr       = 8,
-       .force_phy_addr = 1,
 };
 
 /*****************************************************************************
@@ -234,15 +235,34 @@ static struct i2c_board_info __initdata rd88f5182_i2c_rtc = {
  * Sata
  ****************************************************************************/
 static struct mv_sata_platform_data rd88f5182_sata_data = {
-       .n_ports        = 2,
+       .n_ports        = 2,
 };
 
 /*****************************************************************************
  * General Setup
  ****************************************************************************/
-
-static struct platform_device *rd88f5182_devices[] __initdata = {
-       &rd88f5182_nor_flash,
+static struct orion5x_mpp_mode rd88f5182_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* Debug Led */
+       {  1, MPP_GPIO },               /* Reset Switch */
+       {  2, MPP_UNUSED },
+       {  3, MPP_GPIO },               /* RTC Int */
+       {  4, MPP_GPIO },
+       {  5, MPP_GPIO },
+       {  6, MPP_GPIO },               /* PCI_intA */
+       {  7, MPP_GPIO },               /* PCI_intB */
+       {  8, MPP_UNUSED },
+       {  9, MPP_UNUSED },
+       { 10, MPP_UNUSED },
+       { 11, MPP_UNUSED },
+       { 12, MPP_SATA_LED },           /* SATA 0 presence */
+       { 13, MPP_SATA_LED },           /* SATA 1 presence */
+       { 14, MPP_SATA_LED },           /* SATA 0 active */
+       { 15, MPP_SATA_LED },           /* SATA 1 active */
+       { 16, MPP_UNUSED },
+       { 17, MPP_UNUSED },
+       { 18, MPP_UNUSED },
+       { 19, MPP_UNUSED },
+       { -1 },
 };
 
 static void __init rd88f5182_init(void)
@@ -252,35 +272,9 @@ static void __init rd88f5182_init(void)
         */
        orion5x_init();
 
-       /*
-        * Setup the CPU address decode windows for our devices
-        */
-       orion5x_setup_dev_boot_win(RD88F5182_NOR_BOOT_BASE,
-                               RD88F5182_NOR_BOOT_SIZE);
-       orion5x_setup_dev1_win(RD88F5182_NOR_BASE, RD88F5182_NOR_SIZE);
-
-       /*
-        * Open a special address decode windows for the PCIe WA.
-        */
-       orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
-                               ORION5X_PCIE_WA_SIZE);
+       orion5x_mpp_conf(rd88f5182_mpp_modes);
 
        /*
-        * Setup Multiplexing Pins --
-        * MPP[0] Debug Led (GPIO - Out)
-        * MPP[1] Debug Led (GPIO - Out)
-        * MPP[2] N/A
-        * MPP[3] RTC_Int (GPIO - In)
-        * MPP[4] GPIO
-        * MPP[5] GPIO
-        * MPP[6] PCI_intA (GPIO - In)
-        * MPP[7] PCI_intB (GPIO - In)
-        * MPP[8-11] N/A
-        * MPP[12] SATA 0 presence Indication
-        * MPP[13] SATA 1 presence Indication
-        * MPP[14] SATA 0 active Indication
-        * MPP[15] SATA 1 active indication
-        * MPP[16-19] Not used
         * MPP[20] PCI Clock to MV88F5182
         * MPP[21] PCI Clock to mini PCI CON11
         * MPP[22] USB 0 over current indication
@@ -289,16 +283,23 @@ static void __init rd88f5182_init(void)
         * MPP[25] USB 0 over current enable
         */
 
-       orion5x_write(MPP_0_7_CTRL, 0x00000003);
-       orion5x_write(MPP_8_15_CTRL, 0x55550000);
-       orion5x_write(MPP_16_19_CTRL, 0x5555);
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       orion5x_eth_init(&rd88f5182_eth_data);
+       orion5x_i2c_init();
+       orion5x_sata_init(&rd88f5182_sata_data);
+       orion5x_uart0_init();
 
-       orion5x_gpio_set_valid_pins(0x000000fb);
+       orion5x_setup_dev_boot_win(RD88F5182_NOR_BOOT_BASE,
+                                  RD88F5182_NOR_BOOT_SIZE);
+
+       orion5x_setup_dev1_win(RD88F5182_NOR_BASE, RD88F5182_NOR_SIZE);
+       platform_device_register(&rd88f5182_nor_flash);
 
-       platform_add_devices(rd88f5182_devices, ARRAY_SIZE(rd88f5182_devices));
        i2c_register_board_info(0, &rd88f5182_i2c_rtc, 1);
-       orion5x_eth_init(&rd88f5182_eth_data);
-       orion5x_sata_init(&rd88f5182_sata_data);
 }
 
 MACHINE_START(RD88F5182, "Marvell Orion-NAS Reference Design")
index 9afb41e..a9cef97 100644 (file)
@@ -28,6 +28,8 @@
 #include <asm/mach/pci.h>
 #include <asm/arch/orion5x.h>
 #include "common.h"
+#include "mpp.h"
+#include "tsx09-common.h"
 
 #define QNAP_TS209_NOR_BOOT_BASE 0xf4000000
 #define QNAP_TS209_NOR_BOOT_SIZE SZ_8M
  ***************************************************************************/
 static struct mtd_partition qnap_ts209_partitions[] = {
        {
-               .name       = "U-Boot",
-               .size       = 0x00080000,
-               .offset     = 0x00780000,
-               .mask_flags = MTD_WRITEABLE,
+               .name           = "U-Boot",
+               .size           = 0x00080000,
+               .offset         = 0x00780000,
+               .mask_flags     = MTD_WRITEABLE,
        }, {
-               .name   = "Kernel",
-               .size   = 0x00200000,
-               .offset = 0,
+               .name           = "Kernel",
+               .size           = 0x00200000,
+               .offset         = 0,
        }, {
-               .name   = "RootFS1",
-               .size   = 0x00400000,
-               .offset = 0x00200000,
+               .name           = "RootFS1",
+               .size           = 0x00400000,
+               .offset         = 0x00200000,
        }, {
-               .name   = "RootFS2",
-               .size   = 0x00100000,
-               .offset = 0x00600000,
+               .name           = "RootFS2",
+               .size           = 0x00100000,
+               .offset         = 0x00600000,
        }, {
-               .name   = "U-Boot Config",
-               .size   = 0x00020000,
-               .offset = 0x00760000,
+               .name           = "U-Boot Config",
+               .size           = 0x00020000,
+               .offset         = 0x00760000,
        }, {
-               .name       = "NAS Config",
-               .size       = 0x00060000,
-               .offset     = 0x00700000,
-               .mask_flags = MTD_WRITEABLE,
-       }
+               .name           = "NAS Config",
+               .size           = 0x00060000,
+               .offset         = 0x00700000,
+               .mask_flags     = MTD_WRITEABLE,
+       },
 };
 
 static struct physmap_flash_data qnap_ts209_nor_flash_data = {
-       .width    = 1,
-       .parts    = qnap_ts209_partitions,
-       .nr_parts = ARRAY_SIZE(qnap_ts209_partitions)
+       .width          = 1,
+       .parts          = qnap_ts209_partitions,
+       .nr_parts       = ARRAY_SIZE(qnap_ts209_partitions)
 };
 
 static struct resource qnap_ts209_nor_flash_resource = {
-       .flags = IORESOURCE_MEM,
-       .start = QNAP_TS209_NOR_BOOT_BASE,
-       .end   = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
+       .flags  = IORESOURCE_MEM,
+       .start  = QNAP_TS209_NOR_BOOT_BASE,
+       .end    = QNAP_TS209_NOR_BOOT_BASE + QNAP_TS209_NOR_BOOT_SIZE - 1,
 };
 
 static struct platform_device qnap_ts209_nor_flash = {
-       .name          = "physmap-flash",
-       .id            = 0,
-       .dev           = { .platform_data = &qnap_ts209_nor_flash_data, },
-       .resource      = &qnap_ts209_nor_flash_resource,
-       .num_resources = 1,
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &qnap_ts209_nor_flash_data,
+       },
+       .resource       = &qnap_ts209_nor_flash_resource,
+       .num_resources  = 1,
 };
 
 /*****************************************************************************
@@ -164,12 +168,12 @@ static int __init qnap_ts209_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
 }
 
 static struct hw_pci qnap_ts209_pci __initdata = {
-       .nr_controllers = 2,
-       .preinit        = qnap_ts209_pci_preinit,
-       .swizzle        = pci_std_swizzle,
-       .setup          = orion5x_pci_sys_setup,
-       .scan           = orion5x_pci_sys_scan_bus,
-       .map_irq        = qnap_ts209_pci_map_irq,
+       .nr_controllers = 2,
+       .preinit        = qnap_ts209_pci_preinit,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = qnap_ts209_pci_map_irq,
 };
 
 static int __init qnap_ts209_pci_init(void)
@@ -182,96 +186,6 @@ static int __init qnap_ts209_pci_init(void)
 
 subsys_initcall(qnap_ts209_pci_init);
 
-/*****************************************************************************
- * Ethernet
- ****************************************************************************/
-
-static struct mv643xx_eth_platform_data qnap_ts209_eth_data = {
-       .phy_addr       = 8,
-       .force_phy_addr = 1,
-};
-
-static int __init parse_hex_nibble(char n)
-{
-       if (n >= '0' && n <= '9')
-               return n - '0';
-
-       if (n >= 'A' && n <= 'F')
-               return n - 'A' + 10;
-
-       if (n >= 'a' && n <= 'f')
-               return n - 'a' + 10;
-
-       return -1;
-}
-
-static int __init parse_hex_byte(const char *b)
-{
-       int hi;
-       int lo;
-
-       hi = parse_hex_nibble(b[0]);
-       lo = parse_hex_nibble(b[1]);
-
-       if (hi < 0 || lo < 0)
-               return -1;
-
-       return (hi << 4) | lo;
-}
-
-static int __init check_mac_addr(const char *addr_str)
-{
-       u_int8_t addr[6];
-       int i;
-
-       for (i = 0; i < 6; i++) {
-               int byte;
-
-               /*
-                * Enforce "xx:xx:xx:xx:xx:xx\n" format.
-                */
-               if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
-                       return -1;
-
-               byte = parse_hex_byte(addr_str + (i * 3));
-               if (byte < 0)
-                       return -1;
-               addr[i] = byte;
-       }
-
-       printk(KERN_INFO "ts209: found ethernet mac address ");
-       for (i = 0; i < 6; i++)
-               printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
-
-       memcpy(qnap_ts209_eth_data.mac_addr, addr, 6);
-
-       return 0;
-}
-
-/*
- * The 'NAS Config' flash partition has an ext2 filesystem which
- * contains a file that has the ethernet MAC address in plain text
- * (format "xx:xx:xx:xx:xx:xx\n".)
- */
-static void __init ts209_find_mac_addr(void)
-{
-       unsigned long addr;
-
-       for (addr = 0x00700000; addr < 0x00760000; addr += 1024) {
-               char *nor_page;
-               int ret = 0;
-
-               nor_page = ioremap(QNAP_TS209_NOR_BOOT_BASE + addr, 1024);
-               if (nor_page != NULL) {
-                       ret = check_mac_addr(nor_page);
-                       iounmap(nor_page);
-               }
-
-               if (ret == 0)
-                       break;
-       }
-}
-
 /*****************************************************************************
  * RTC S35390A on I2C bus
  ****************************************************************************/
@@ -280,7 +194,7 @@ static void __init ts209_find_mac_addr(void)
 
 static struct i2c_board_info __initdata qnap_ts209_i2c_rtc = {
        I2C_BOARD_INFO("s35390a", 0x30),
-       .irq         = 0,
+       .irq    = 0,
 };
 
 /****************************************************************************
@@ -297,70 +211,63 @@ static struct gpio_keys_button qnap_ts209_buttons[] = {
                .gpio           = QNAP_TS209_GPIO_KEY_MEDIA,
                .desc           = "USB Copy Button",
                .active_low     = 1,
-       },
-       {
+       }, {
                .code           = KEY_POWER,
                .gpio           = QNAP_TS209_GPIO_KEY_RESET,
                .desc           = "Reset Button",
                .active_low     = 1,
-       }
+       },
 };
 
 static struct gpio_keys_platform_data qnap_ts209_button_data = {
        .buttons        = qnap_ts209_buttons,
-       .nbuttons       = ARRAY_SIZE(qnap_ts209_buttons),
+       .nbuttons       = ARRAY_SIZE(qnap_ts209_buttons),
 };
 
 static struct platform_device qnap_ts209_button_device = {
        .name           = "gpio-keys",
        .id             = -1,
        .num_resources  = 0,
-       .dev            = { .platform_data  = &qnap_ts209_button_data, },
+       .dev            = {
+               .platform_data  = &qnap_ts209_button_data,
+       },
 };
 
 /*****************************************************************************
  * SATA
  ****************************************************************************/
 static struct mv_sata_platform_data qnap_ts209_sata_data = {
-       .n_ports        = 2,
+       .n_ports        = 2,
 };
 
 /*****************************************************************************
 
  * General Setup
  ****************************************************************************/
-
-static struct platform_device *qnap_ts209_devices[] __initdata = {
-       &qnap_ts209_nor_flash,
-       &qnap_ts209_button_device,
+static struct orion5x_mpp_mode ts209_mpp_modes[] __initdata = {
+       {  0, MPP_UNUSED },
+       {  1, MPP_GPIO },               /* USB copy button */
+       {  2, MPP_GPIO },               /* Load defaults button */
+       {  3, MPP_GPIO },               /* GPIO RTC */
+       {  4, MPP_UNUSED },
+       {  5, MPP_UNUSED },
+       {  6, MPP_GPIO },               /* PCI Int A */
+       {  7, MPP_GPIO },               /* PCI Int B */
+       {  8, MPP_UNUSED },
+       {  9, MPP_UNUSED },
+       { 10, MPP_UNUSED },
+       { 11, MPP_UNUSED },
+       { 12, MPP_SATA_LED },           /* SATA 0 presence */
+       { 13, MPP_SATA_LED },           /* SATA 1 presence */
+       { 14, MPP_SATA_LED },           /* SATA 0 active */
+       { 15, MPP_SATA_LED },           /* SATA 1 active */
+       { 16, MPP_UART },               /* UART1 RXD */
+       { 17, MPP_UART },               /* UART1 TXD */
+       { 18, MPP_GPIO },               /* SW_RST */
+       { 19, MPP_UNUSED },
+       { -1 },
 };
 
-/*
- * QNAP TS-[12]09 specific power off method via UART1-attached PIC
- */
-
-#define UART1_REG(x)  (UART1_VIRT_BASE + ((UART_##x) << 2))
-
-static void qnap_ts209_power_off(void)
-{
-       /* 19200 baud divisor */
-       const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
-
-       pr_info("%s: triggering power-off...\n", __func__);
-
-       /* hijack uart1 and reset into sane state (19200,8n1) */
-       orion5x_write(UART1_REG(LCR), 0x83);
-       orion5x_write(UART1_REG(DLL), divisor & 0xff);
-       orion5x_write(UART1_REG(DLM), (divisor >> 8) & 0xff);
-       orion5x_write(UART1_REG(LCR), 0x03);
-       orion5x_write(UART1_REG(IER), 0x00);
-       orion5x_write(UART1_REG(FCR), 0x00);
-       orion5x_write(UART1_REG(MCR), 0x00);
-
-       /* send the power-off command 'A' to PIC */
-       orion5x_write(UART1_REG(TX), 'A');
-}
-
 static void __init qnap_ts209_init(void)
 {
        /*
@@ -368,51 +275,33 @@ static void __init qnap_ts209_init(void)
         */
        orion5x_init();
 
-       /*
-        * Setup flash mapping
-        */
-       orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE,
-                           QNAP_TS209_NOR_BOOT_SIZE);
-
-       /*
-        * Open a special address decode windows for the PCIe WA.
-        */
-       orion5x_setup_pcie_wa_win(ORION5X_PCIE_WA_PHYS_BASE,
-                               ORION5X_PCIE_WA_SIZE);
+       orion5x_mpp_conf(ts209_mpp_modes);
 
        /*
-        * Setup Multiplexing Pins --
-        * MPP[0] Reserved
-        * MPP[1] USB copy button (0 active)
-        * MPP[2] Load defaults button (0 active)
-        * MPP[3] GPIO RTC
-        * MPP[4-5] Reserved
-        * MPP[6] PCI Int A
-        * MPP[7] PCI Int B
-        * MPP[8-11] Reserved
-        * MPP[12] SATA 0 presence
-        * MPP[13] SATA 1 presence
-        * MPP[14] SATA 0 active
-        * MPP[15] SATA 1 active
-        * MPP[16] UART1 RXD
-        * MPP[17] UART1 TXD
-        * MPP[18] SW_RST (0 active)
-        * MPP[19] Reserved
         * MPP[20] PCI clock 0
         * MPP[21] PCI clock 1
         * MPP[22] USB 0 over current
         * MPP[23-25] Reserved
         */
-       orion5x_write(MPP_0_7_CTRL, 0x3);
-       orion5x_write(MPP_8_15_CTRL, 0x55550000);
-       orion5x_write(MPP_16_19_CTRL, 0x5500);
-       orion5x_gpio_set_valid_pins(0x3cc0fff);
 
-       /* register ts209 specific power-off method */
-       pm_power_off = qnap_ts209_power_off;
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       qnap_tsx09_find_mac_addr(QNAP_TS209_NOR_BOOT_BASE +
+                                qnap_ts209_partitions[5].offset,
+                                qnap_ts209_partitions[5].size);
+       orion5x_eth_init(&qnap_tsx09_eth_data);
+       orion5x_i2c_init();
+       orion5x_sata_init(&qnap_ts209_sata_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(QNAP_TS209_NOR_BOOT_BASE,
+                                  QNAP_TS209_NOR_BOOT_SIZE);
+       platform_device_register(&qnap_ts209_nor_flash);
 
-       platform_add_devices(qnap_ts209_devices,
-                               ARRAY_SIZE(qnap_ts209_devices));
+       platform_device_register(&qnap_ts209_button_device);
 
        /* Get RTC IRQ and register the chip */
        if (gpio_request(TS209_RTC_GPIO, "rtc") == 0) {
@@ -425,14 +314,12 @@ static void __init qnap_ts209_init(void)
                pr_warning("qnap_ts209_init: failed to get RTC IRQ\n");
        i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
 
-       ts209_find_mac_addr();
-       orion5x_eth_init(&qnap_ts209_eth_data);
-
-       orion5x_sata_init(&qnap_ts209_sata_data);
+       /* register tsx09 specific power-off method */
+       pm_power_off = qnap_tsx09_power_off;
 }
 
 MACHINE_START(TS209, "QNAP TS-109/TS-209")
-       /* Maintainer:  Byron Bradley <byron.bbradley@gmail.com> */
+       /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
        .phys_io        = ORION5X_REGS_PHYS_BASE,
        .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
        .boot_params    = 0x00000100,
diff --git a/arch/arm/mach-orion5x/ts409-setup.c b/arch/arm/mach-orion5x/ts409-setup.c
new file mode 100644 (file)
index 0000000..32f0ff0
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * QNAP TS-409 Board Setup
+ *
+ * Maintainer: Sylver Bruneau <sylver.bruneau@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/i2c.h>
+#include <linux/serial_reg.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+#include "tsx09-common.h"
+
+/*****************************************************************************
+ * QNAP TS-409 Info
+ ****************************************************************************/
+
+/*
+ * QNAP TS-409 hardware :
+ * - Marvell 88F5281-D0
+ * - Marvell 88SX7042 SATA controller (PCIe)
+ * - Marvell 88E1118 Gigabit Ethernet PHY
+ * - RTC S35390A (@0x30) on I2C bus
+ * - 8MB NOR flash
+ * - 256MB of DDR-2 RAM
+ */
+
+/*
+ * 8MB NOR flash Device bus boot chip select
+ */
+
+#define QNAP_TS409_NOR_BOOT_BASE 0xff800000
+#define QNAP_TS409_NOR_BOOT_SIZE SZ_8M
+
+/****************************************************************************
+ * 8MiB NOR flash. The struct mtd_partition is not in the same order as the
+ *     partitions on the device because we want to keep compatability with
+ *     existing QNAP firmware.
+ *
+ * Layout as used by QNAP:
+ *  [2] 0x00000000-0x00200000 : "Kernel"
+ *  [3] 0x00200000-0x00600000 : "RootFS1"
+ *  [4] 0x00600000-0x00700000 : "RootFS2"
+ *  [6] 0x00700000-0x00760000 : "NAS Config" (read-only)
+ *  [5] 0x00760000-0x00780000 : "U-Boot Config"
+ *  [1] 0x00780000-0x00800000 : "U-Boot" (read-only)
+ ***************************************************************************/
+static struct mtd_partition qnap_ts409_partitions[] = {
+       {
+               .name           = "U-Boot",
+               .size           = 0x00080000,
+               .offset         = 0x00780000,
+               .mask_flags     = MTD_WRITEABLE,
+       }, {
+               .name           = "Kernel",
+               .size           = 0x00200000,
+               .offset         = 0,
+       }, {
+               .name           = "RootFS1",
+               .size           = 0x00400000,
+               .offset         = 0x00200000,
+       }, {
+               .name           = "RootFS2",
+               .size           = 0x00100000,
+               .offset         = 0x00600000,
+       }, {
+               .name           = "U-Boot Config",
+               .size           = 0x00020000,
+               .offset         = 0x00760000,
+       }, {
+               .name           = "NAS Config",
+               .size           = 0x00060000,
+               .offset         = 0x00700000,
+               .mask_flags     = MTD_WRITEABLE,
+       },
+};
+
+static struct physmap_flash_data qnap_ts409_nor_flash_data = {
+       .width          = 1,
+       .parts          = qnap_ts409_partitions,
+       .nr_parts       = ARRAY_SIZE(qnap_ts409_partitions)
+};
+
+static struct resource qnap_ts409_nor_flash_resource = {
+       .flags  = IORESOURCE_MEM,
+       .start  = QNAP_TS409_NOR_BOOT_BASE,
+       .end    = QNAP_TS409_NOR_BOOT_BASE + QNAP_TS409_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device qnap_ts409_nor_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = { .platform_data = &qnap_ts409_nor_flash_data, },
+       .num_resources  = 1,
+       .resource       = &qnap_ts409_nor_flash_resource,
+};
+
+/*****************************************************************************
+ * PCI
+ ****************************************************************************/
+
+static int __init qnap_ts409_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       /*
+        * PCI isn't used on the TS-409
+        */
+       return -1;
+}
+
+static struct hw_pci qnap_ts409_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = qnap_ts409_pci_map_irq,
+};
+
+static int __init qnap_ts409_pci_init(void)
+{
+       if (machine_is_ts409())
+               pci_common_init(&qnap_ts409_pci);
+
+       return 0;
+}
+
+subsys_initcall(qnap_ts409_pci_init);
+
+/*****************************************************************************
+ * RTC S35390A on I2C bus
+ ****************************************************************************/
+
+#define TS409_RTC_GPIO 10
+
+static struct i2c_board_info __initdata qnap_ts409_i2c_rtc = {
+       I2C_BOARD_INFO("s35390a", 0x30),
+};
+
+/****************************************************************************
+ * GPIO Attached Keys
+ *     Power button is attached to the PIC microcontroller
+ ****************************************************************************/
+
+#define QNAP_TS409_GPIO_KEY_MEDIA      15
+
+static struct gpio_keys_button qnap_ts409_buttons[] = {
+       {
+               .code           = KEY_RESTART,
+               .gpio           = QNAP_TS409_GPIO_KEY_MEDIA,
+               .desc           = "USB Copy Button",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data qnap_ts409_button_data = {
+       .buttons        = qnap_ts409_buttons,
+       .nbuttons       = ARRAY_SIZE(qnap_ts409_buttons),
+};
+
+static struct platform_device qnap_ts409_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &qnap_ts409_button_data,
+       },
+};
+
+/*****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode ts409_mpp_modes[] __initdata = {
+       {  0, MPP_UNUSED },
+       {  1, MPP_UNUSED },
+       {  2, MPP_UNUSED },
+       {  3, MPP_UNUSED },
+       {  4, MPP_GPIO },               /* HDD 1 status */
+       {  5, MPP_GPIO },               /* HDD 2 status */
+       {  6, MPP_GPIO },               /* HDD 3 status */
+       {  7, MPP_GPIO },               /* HDD 4 status */
+       {  8, MPP_UNUSED },
+       {  9, MPP_UNUSED },
+       { 10, MPP_GPIO },               /* RTC int */
+       { 11, MPP_UNUSED },
+       { 12, MPP_UNUSED },
+       { 13, MPP_UNUSED },
+       { 14, MPP_GPIO },               /* SW_RST */
+       { 15, MPP_GPIO },               /* USB copy button */
+       { 16, MPP_UART },               /* UART1 RXD */
+       { 17, MPP_UART },               /* UART1 TXD */
+       { 18, MPP_UNUSED },
+       { 19, MPP_UNUSED },
+       { -1 },
+};
+
+static void __init qnap_ts409_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       orion5x_mpp_conf(ts409_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       qnap_tsx09_find_mac_addr(QNAP_TS409_NOR_BOOT_BASE +
+                                qnap_ts409_partitions[5].offset,
+                                qnap_ts409_partitions[5].size);
+       orion5x_eth_init(&qnap_tsx09_eth_data);
+       orion5x_i2c_init();
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(QNAP_TS409_NOR_BOOT_BASE,
+                                  QNAP_TS409_NOR_BOOT_SIZE);
+       platform_device_register(&qnap_ts409_nor_flash);
+
+       platform_device_register(&qnap_ts409_button_device);
+
+       /* Get RTC IRQ and register the chip */
+       if (gpio_request(TS409_RTC_GPIO, "rtc") == 0) {
+               if (gpio_direction_input(TS409_RTC_GPIO) == 0)
+                       qnap_ts409_i2c_rtc.irq = gpio_to_irq(TS409_RTC_GPIO);
+               else
+                       gpio_free(TS409_RTC_GPIO);
+       }
+       if (qnap_ts409_i2c_rtc.irq == 0)
+               pr_warning("qnap_ts409_init: failed to get RTC IRQ\n");
+       i2c_register_board_info(0, &qnap_ts409_i2c_rtc, 1);
+
+       /* register tsx09 specific power-off method */
+       pm_power_off = qnap_tsx09_power_off;
+}
+
+MACHINE_START(TS409, "QNAP TS-409")
+       /* Maintainer:  Sylver Bruneau <sylver.bruneau@gmail.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = qnap_ts409_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32,
+MACHINE_END
diff --git a/arch/arm/mach-orion5x/ts78xx-setup.c b/arch/arm/mach-orion5x/ts78xx-setup.c
new file mode 100644 (file)
index 0000000..77e9f35
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * arch/arm/mach-orion5x/ts78xx-setup.c
+ *
+ * Maintainer: Alexander Clouter <alex@digriz.org.uk>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/ata_platform.h>
+#include <linux/m48t86.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+/*****************************************************************************
+ * TS-78xx Info
+ ****************************************************************************/
+
+/*
+ * FPGA - lives where the PCI bus would be at ORION5X_PCI_MEM_PHYS_BASE
+ */
+#define TS78XX_FPGA_REGS_PHYS_BASE     0xe8000000
+#define TS78XX_FPGA_REGS_VIRT_BASE     0xff900000
+#define TS78XX_FPGA_REGS_SIZE          SZ_1M
+
+#define TS78XX_FPGA_REGS_SYSCON_ID     (TS78XX_FPGA_REGS_VIRT_BASE | 0x000)
+#define TS78XX_FPGA_REGS_SYSCON_LCDI   (TS78XX_FPGA_REGS_VIRT_BASE | 0x004)
+#define TS78XX_FPGA_REGS_SYSCON_LCDO   (TS78XX_FPGA_REGS_VIRT_BASE | 0x008)
+
+#define TS78XX_FPGA_REGS_RTC_CTRL      (TS78XX_FPGA_REGS_VIRT_BASE | 0x808)
+#define TS78XX_FPGA_REGS_RTC_DATA      (TS78XX_FPGA_REGS_VIRT_BASE | 0x80c)
+
+/*
+ * 512kB NOR flash Device
+ */
+#define TS78XX_NOR_BOOT_BASE           0xff800000
+#define TS78XX_NOR_BOOT_SIZE           SZ_512K
+
+/*****************************************************************************
+ * I/O Address Mapping
+ ****************************************************************************/
+static struct map_desc ts78xx_io_desc[] __initdata = {
+       {
+               .virtual        = TS78XX_FPGA_REGS_VIRT_BASE,
+               .pfn            = __phys_to_pfn(TS78XX_FPGA_REGS_PHYS_BASE),
+               .length         = TS78XX_FPGA_REGS_SIZE,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init ts78xx_map_io(void)
+{
+       orion5x_map_io();
+       iotable_init(ts78xx_io_desc, ARRAY_SIZE(ts78xx_io_desc));
+}
+
+/*****************************************************************************
+ * 512kB NOR Boot Flash - the chip is a M25P40
+ ****************************************************************************/
+static struct mtd_partition ts78xx_nor_boot_flash_resources[] = {
+       {
+               .name           = "ts-bootrom",
+               .offset         = 0,
+               /* only the first 256kB is used */
+               .size           = SZ_256K,
+               .mask_flags     = MTD_WRITEABLE,
+       },
+};
+
+static struct physmap_flash_data ts78xx_nor_boot_flash_data = {
+       .width          = 1,
+       .parts          = ts78xx_nor_boot_flash_resources,
+       .nr_parts       = ARRAY_SIZE(ts78xx_nor_boot_flash_resources),
+};
+
+static struct resource ts78xx_nor_boot_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = TS78XX_NOR_BOOT_BASE,
+       .end            = TS78XX_NOR_BOOT_BASE + TS78XX_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device ts78xx_nor_boot_flash = {
+       .name           = "physmap-flash",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &ts78xx_nor_boot_flash_data,
+       },
+       .num_resources  = 1,
+       .resource       = &ts78xx_nor_boot_flash_resource,
+};
+
+/*****************************************************************************
+ * Ethernet
+ ****************************************************************************/
+static struct mv643xx_eth_platform_data ts78xx_eth_data = {
+       .phy_addr       = 0,
+       .force_phy_addr = 1,
+};
+
+/*****************************************************************************
+ * RTC M48T86 - nicked^Wborrowed from arch/arm/mach-ep93xx/ts72xx.c
+ ****************************************************************************/
+#ifdef CONFIG_RTC_DRV_M48T86
+static unsigned char ts78xx_rtc_readbyte(unsigned long addr)
+{
+       writeb(addr, TS78XX_FPGA_REGS_RTC_CTRL);
+       return readb(TS78XX_FPGA_REGS_RTC_DATA);
+}
+
+static void ts78xx_rtc_writebyte(unsigned char value, unsigned long addr)
+{
+       writeb(addr, TS78XX_FPGA_REGS_RTC_CTRL);
+       writeb(value, TS78XX_FPGA_REGS_RTC_DATA);
+}
+
+static struct m48t86_ops ts78xx_rtc_ops = {
+       .readbyte       = ts78xx_rtc_readbyte,
+       .writebyte      = ts78xx_rtc_writebyte,
+};
+
+static struct platform_device ts78xx_rtc_device = {
+       .name           = "rtc-m48t86",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &ts78xx_rtc_ops,
+       },
+       .num_resources  = 0,
+};
+
+/*
+ * TS uses some of the user storage space on the RTC chip so see if it is
+ * present; as it's an optional feature at purchase time and not all boards
+ * will have it present
+ *
+ * I've used the method TS use in their rtc7800.c example for the detection
+ *
+ * TODO: track down a guinea pig without an RTC to see if we can work out a
+ *             better RTC detection routine
+ */
+static int __init ts78xx_rtc_init(void)
+{
+       unsigned char tmp_rtc0, tmp_rtc1;
+
+       tmp_rtc0 = ts78xx_rtc_readbyte(126);
+       tmp_rtc1 = ts78xx_rtc_readbyte(127);
+
+       ts78xx_rtc_writebyte(0x00, 126);
+       ts78xx_rtc_writebyte(0x55, 127);
+       if (ts78xx_rtc_readbyte(127) == 0x55) {
+               ts78xx_rtc_writebyte(0xaa, 127);
+               if (ts78xx_rtc_readbyte(127) == 0xaa
+                               && ts78xx_rtc_readbyte(126) == 0x00) {
+                       ts78xx_rtc_writebyte(tmp_rtc0, 126);
+                       ts78xx_rtc_writebyte(tmp_rtc1, 127);
+                       platform_device_register(&ts78xx_rtc_device);
+                       return 1;
+               }
+       }
+
+       return 0;
+};
+#else
+static int __init ts78xx_rtc_init(void)
+{
+       return 0;
+}
+#endif
+
+/*****************************************************************************
+ * SATA
+ ****************************************************************************/
+static struct mv_sata_platform_data ts78xx_sata_data = {
+       .n_ports        = 2,
+};
+
+/*****************************************************************************
+ * print some information regarding the board
+ ****************************************************************************/
+static void __init ts78xx_print_board_id(void)
+{
+       unsigned int board_info;
+
+       board_info = readl(TS78XX_FPGA_REGS_SYSCON_ID);
+       printk(KERN_INFO "TS-78xx Info: FPGA rev=%.2x, Board Magic=%.6x, ",
+                               board_info & 0xff,
+                               (board_info >> 8) & 0xffffff);
+       board_info = readl(TS78XX_FPGA_REGS_SYSCON_LCDI);
+       printk("JP1=%d, JP2=%d\n",
+                               (board_info >> 30) & 0x1,
+                               (board_info >> 31) & 0x1);
+};
+
+/*****************************************************************************
+ * General Setup
+ ****************************************************************************/
+static struct orion5x_mpp_mode ts78xx_mpp_modes[] __initdata = {
+       {  0, MPP_UNUSED },
+       {  1, MPP_GPIO },               /* JTAG Clock */
+       {  2, MPP_GPIO },               /* JTAG Data In */
+       {  3, MPP_GPIO },               /* Lat ECP2 256 FPGA - PB2B */
+       {  4, MPP_GPIO },               /* JTAG Data Out */
+       {  5, MPP_GPIO },               /* JTAG TMS */
+       {  6, MPP_GPIO },               /* Lat ECP2 256 FPGA - PB31A_CLK4+ */
+       {  7, MPP_GPIO },               /* Lat ECP2 256 FPGA - PB22B */
+       {  8, MPP_UNUSED },
+       {  9, MPP_UNUSED },
+       { 10, MPP_UNUSED },
+       { 11, MPP_UNUSED },
+       { 12, MPP_UNUSED },
+       { 13, MPP_UNUSED },
+       { 14, MPP_UNUSED },
+       { 15, MPP_UNUSED },
+       { 16, MPP_UART },
+       { 17, MPP_UART },
+       { 18, MPP_UART },
+       { 19, MPP_UART },
+       { -1 },
+};
+
+static void __init ts78xx_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       ts78xx_print_board_id();
+
+       orion5x_mpp_conf(ts78xx_mpp_modes);
+
+       /*
+        * MPP[20] PCI Clock Out 1
+        * MPP[21] PCI Clock Out 0
+        * MPP[22] Unused
+        * MPP[23] Unused
+        * MPP[24] Unused
+        * MPP[25] Unused
+        */
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_ehci1_init();
+       orion5x_eth_init(&ts78xx_eth_data);
+       orion5x_sata_init(&ts78xx_sata_data);
+       orion5x_uart0_init();
+       orion5x_uart1_init();
+
+       orion5x_setup_dev_boot_win(TS78XX_NOR_BOOT_BASE,
+                                  TS78XX_NOR_BOOT_SIZE);
+       platform_device_register(&ts78xx_nor_boot_flash);
+
+       if (!ts78xx_rtc_init())
+               printk(KERN_INFO "TS-78xx RTC not detected or enabled\n");
+}
+
+MACHINE_START(TS78XX, "Technologic Systems TS-78xx SBC")
+       /* Maintainer: Alexander Clouter <alex@digriz.org.uk> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = ts78xx_init,
+       .map_io         = ts78xx_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+MACHINE_END
diff --git a/arch/arm/mach-orion5x/tsx09-common.c b/arch/arm/mach-orion5x/tsx09-common.c
new file mode 100644 (file)
index 0000000..83feac3
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * QNAP TS-x09 Boards common functions
+ *
+ * Maintainers: Lennert Buytenhek <buytenh@marvell.com>
+ *             Byron Bradley <byron.bbradley@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/timex.h>
+#include <linux/serial_reg.h>
+#include "tsx09-common.h"
+
+/*****************************************************************************
+ * QNAP TS-x09 specific power off method via UART1-attached PIC
+ ****************************************************************************/
+
+#define UART1_REG(x)   (UART1_VIRT_BASE + ((UART_##x) << 2))
+
+void qnap_tsx09_power_off(void)
+{
+       /* 19200 baud divisor */
+       const unsigned divisor = ((ORION5X_TCLK + (8 * 19200)) / (16 * 19200));
+
+       pr_info("%s: triggering power-off...\n", __func__);
+
+       /* hijack uart1 and reset into sane state (19200,8n1) */
+       writel(0x83, UART1_REG(LCR));
+       writel(divisor & 0xff, UART1_REG(DLL));
+       writel((divisor >> 8) & 0xff, UART1_REG(DLM));
+       writel(0x03, UART1_REG(LCR));
+       writel(0x00, UART1_REG(IER));
+       writel(0x00, UART1_REG(FCR));
+       writel(0x00, UART1_REG(MCR));
+
+       /* send the power-off command 'A' to PIC */
+       writel('A', UART1_REG(TX));
+}
+
+/*****************************************************************************
+ * Ethernet
+ ****************************************************************************/
+
+struct mv643xx_eth_platform_data qnap_tsx09_eth_data = {
+       .phy_addr       = 8,
+};
+
+static int __init qnap_tsx09_parse_hex_nibble(char n)
+{
+       if (n >= '0' && n <= '9')
+               return n - '0';
+
+       if (n >= 'A' && n <= 'F')
+               return n - 'A' + 10;
+
+       if (n >= 'a' && n <= 'f')
+               return n - 'a' + 10;
+
+       return -1;
+}
+
+static int __init qnap_tsx09_parse_hex_byte(const char *b)
+{
+       int hi;
+       int lo;
+
+       hi = qnap_tsx09_parse_hex_nibble(b[0]);
+       lo = qnap_tsx09_parse_hex_nibble(b[1]);
+
+       if (hi < 0 || lo < 0)
+               return -1;
+
+       return (hi << 4) | lo;
+}
+
+static int __init qnap_tsx09_check_mac_addr(const char *addr_str)
+{
+       u_int8_t addr[6];
+       int i;
+
+       for (i = 0; i < 6; i++) {
+               int byte;
+
+               /*
+                * Enforce "xx:xx:xx:xx:xx:xx\n" format.
+                */
+               if (addr_str[(i * 3) + 2] != ((i < 5) ? ':' : '\n'))
+                       return -1;
+
+               byte = qnap_tsx09_parse_hex_byte(addr_str + (i * 3));
+               if (byte < 0)
+                       return -1;
+               addr[i] = byte;
+       }
+
+       printk(KERN_INFO "tsx09: found ethernet mac address ");
+       for (i = 0; i < 6; i++)
+               printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
+
+       memcpy(qnap_tsx09_eth_data.mac_addr, addr, 6);
+
+       return 0;
+}
+
+/*
+ * The 'NAS Config' flash partition has an ext2 filesystem which
+ * contains a file that has the ethernet MAC address in plain text
+ * (format "xx:xx:xx:xx:xx:xx\n").
+ */
+void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size)
+{
+       unsigned long addr;
+
+       for (addr = mem_base; addr < (mem_base + size); addr += 1024) {
+               char *nor_page;
+               int ret = 0;
+
+               nor_page = ioremap(addr, 1024);
+               if (nor_page != NULL) {
+                       ret = qnap_tsx09_check_mac_addr(nor_page);
+                       iounmap(nor_page);
+               }
+
+               if (ret == 0)
+                       break;
+       }
+}
diff --git a/arch/arm/mach-orion5x/tsx09-common.h b/arch/arm/mach-orion5x/tsx09-common.h
new file mode 100644 (file)
index 0000000..0984264
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __ARCH_ORION5X_TSX09_COMMON_H
+#define __ARCH_ORION5X_TSX09_COMMON_H
+
+/*
+ * QNAP TS-x09 Boards power-off function
+ */
+extern void qnap_tsx09_power_off(void);
+
+/*
+ * QNAP TS-x09 Boards function to find Ethernet MAC address in flash memory
+ */
+extern void __init qnap_tsx09_find_mac_addr(u32 mem_base, u32 size);
+
+/*
+ * QNAP TS-x09 Boards ethernet declaration
+ */
+extern struct mv643xx_eth_platform_data qnap_tsx09_eth_data;
+
+
+#endif
diff --git a/arch/arm/mach-orion5x/wnr854t-setup.c b/arch/arm/mach-orion5x/wnr854t-setup.c
new file mode 100644 (file)
index 0000000..1af093f
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * arch/arm/mach-orion5x/wnr854t-setup.c
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+static struct orion5x_mpp_mode wnr854t_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* Power LED green (0=on) */
+       {  1, MPP_GPIO },               /* Reset Button (0=off) */
+       {  2, MPP_GPIO },               /* Power LED blink (0=off) */
+       {  3, MPP_GPIO },               /* WAN Status LED amber (0=off) */
+       {  4, MPP_GPIO },               /* PCI int */
+       {  5, MPP_GPIO },               /* ??? */
+       {  6, MPP_GPIO },               /* ??? */
+       {  7, MPP_GPIO },               /* ??? */
+       {  8, MPP_UNUSED },             /* ??? */
+       {  9, MPP_GIGE },               /* GE_RXERR */
+       { 10, MPP_UNUSED },             /* ??? */
+       { 11, MPP_UNUSED },             /* ??? */
+       { 12, MPP_GIGE },               /* GE_TXD[4] */
+       { 13, MPP_GIGE },               /* GE_TXD[5] */
+       { 14, MPP_GIGE },               /* GE_TXD[6] */
+       { 15, MPP_GIGE },               /* GE_TXD[7] */
+       { 16, MPP_GIGE },               /* GE_RXD[4] */
+       { 17, MPP_GIGE },               /* GE_RXD[5] */
+       { 18, MPP_GIGE },               /* GE_RXD[6] */
+       { 19, MPP_GIGE },               /* GE_RXD[7] */
+       { -1 },
+};
+
+/*
+ * 8M NOR flash Device bus boot chip select
+ */
+#define WNR854T_NOR_BOOT_BASE  0xf4000000
+#define WNR854T_NOR_BOOT_SIZE  SZ_8M
+
+static struct mtd_partition wnr854t_nor_flash_partitions[] = {
+       {
+               .name           = "kernel",
+               .offset         = 0x00000000,
+               .size           = 0x00100000,
+       }, {
+               .name           = "rootfs",
+               .offset         = 0x00100000,
+               .size           = 0x00660000,
+       }, {
+               .name           = "uboot",
+               .offset         = 0x00760000,
+               .size           = 0x00040000,
+       },
+};
+
+static struct physmap_flash_data wnr854t_nor_flash_data = {
+       .width          = 2,
+       .parts          = wnr854t_nor_flash_partitions,
+       .nr_parts       = ARRAY_SIZE(wnr854t_nor_flash_partitions),
+};
+
+static struct resource wnr854t_nor_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = WNR854T_NOR_BOOT_BASE,
+       .end            = WNR854T_NOR_BOOT_BASE + WNR854T_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device wnr854t_nor_flash = {
+       .name                   = "physmap-flash",
+       .id                     = 0,
+       .dev            = {
+               .platform_data  = &wnr854t_nor_flash_data,
+       },
+       .num_resources          = 1,
+       .resource               = &wnr854t_nor_flash_resource,
+};
+
+static struct mv643xx_eth_platform_data wnr854t_eth_data = {
+       .phy_addr       = -1,
+};
+
+static void __init wnr854t_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       orion5x_mpp_conf(wnr854t_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_eth_init(&wnr854t_eth_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(WNR854T_NOR_BOOT_BASE,
+                                  WNR854T_NOR_BOOT_SIZE);
+       platform_device_register(&wnr854t_nor_flash);
+}
+
+static int __init wnr854t_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       /*
+        * Mini-PCI slot.
+        */
+       if (slot == 7)
+               return gpio_to_irq(4);
+
+       return -1;
+}
+
+static struct hw_pci wnr854t_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = wnr854t_pci_map_irq,
+};
+
+static int __init wnr854t_pci_init(void)
+{
+       if (machine_is_wnr854t())
+               pci_common_init(&wnr854t_pci);
+
+       return 0;
+}
+subsys_initcall(wnr854t_pci_init);
+
+MACHINE_START(WNR854T, "Netgear WNR854T")
+       /* Maintainer: Imre Kaloz <kaloz@openwrt.org> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = wnr854t_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32,
+MACHINE_END
diff --git a/arch/arm/mach-orion5x/wrt350n-v2-setup.c b/arch/arm/mach-orion5x/wrt350n-v2-setup.c
new file mode 100644 (file)
index 0000000..aeab55c
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * arch/arm/mach-orion5x/wrt350n-v2-setup.c
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/pci.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mv643xx_eth.h>
+#include <asm/mach-types.h>
+#include <asm/gpio.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/pci.h>
+#include <asm/arch/orion5x.h>
+#include "common.h"
+#include "mpp.h"
+
+static struct orion5x_mpp_mode wrt350n_v2_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* Power LED green (0=on) */
+       {  1, MPP_GPIO },               /* Security LED (0=on) */
+       {  2, MPP_GPIO },               /* Internal Button (0=on) */
+       {  3, MPP_GPIO },               /* Reset Button (0=on) */
+       {  4, MPP_GPIO },               /* PCI int */
+       {  5, MPP_GPIO },               /* Power LED orange (0=on) */
+       {  6, MPP_GPIO },               /* USB LED (0=on) */
+       {  7, MPP_GPIO },               /* Wireless LED (0=on) */
+       {  8, MPP_UNUSED },             /* ??? */
+       {  9, MPP_GIGE },               /* GE_RXERR */
+       { 10, MPP_UNUSED },             /* ??? */
+       { 11, MPP_UNUSED },             /* ??? */
+       { 12, MPP_GIGE },               /* GE_TXD[4] */
+       { 13, MPP_GIGE },               /* GE_TXD[5] */
+       { 14, MPP_GIGE },               /* GE_TXD[6] */
+       { 15, MPP_GIGE },               /* GE_TXD[7] */
+       { 16, MPP_GIGE },               /* GE_RXD[4] */
+       { 17, MPP_GIGE },               /* GE_RXD[5] */
+       { 18, MPP_GIGE },               /* GE_RXD[6] */
+       { 19, MPP_GIGE },               /* GE_RXD[7] */
+       { -1 },
+};
+
+/*
+ * 8M NOR flash Device bus boot chip select
+ */
+#define WRT350N_V2_NOR_BOOT_BASE       0xf4000000
+#define WRT350N_V2_NOR_BOOT_SIZE       SZ_8M
+
+static struct mtd_partition wrt350n_v2_nor_flash_partitions[] = {
+       {
+               .name           = "kernel",
+               .offset         = 0x00000000,
+               .size           = 0x00760000,
+       }, {
+               .name           = "rootfs",
+               .offset         = 0x001a0000,
+               .size           = 0x005c0000,
+       }, {
+               .name           = "lang",
+               .offset         = 0x00760000,
+               .size           = 0x00040000,
+       }, {
+               .name           = "nvram",
+               .offset         = 0x007a0000,
+               .size           = 0x00020000,
+       }, {
+               .name           = "u-boot",
+               .offset         = 0x007c0000,
+               .size           = 0x00040000,
+       },
+};
+
+static struct physmap_flash_data wrt350n_v2_nor_flash_data = {
+       .width          = 1,
+       .parts          = wrt350n_v2_nor_flash_partitions,
+       .nr_parts       = ARRAY_SIZE(wrt350n_v2_nor_flash_partitions),
+};
+
+static struct resource wrt350n_v2_nor_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+       .start          = WRT350N_V2_NOR_BOOT_BASE,
+       .end            = WRT350N_V2_NOR_BOOT_BASE + WRT350N_V2_NOR_BOOT_SIZE - 1,
+};
+
+static struct platform_device wrt350n_v2_nor_flash = {
+       .name                   = "physmap-flash",
+       .id                     = 0,
+       .dev            = {
+               .platform_data  = &wrt350n_v2_nor_flash_data,
+       },
+       .num_resources          = 1,
+       .resource               = &wrt350n_v2_nor_flash_resource,
+};
+
+static struct mv643xx_eth_platform_data wrt350n_v2_eth_data = {
+       .phy_addr       = -1,
+};
+
+static void __init wrt350n_v2_init(void)
+{
+       /*
+        * Setup basic Orion functions. Need to be called early.
+        */
+       orion5x_init();
+
+       orion5x_mpp_conf(wrt350n_v2_mpp_modes);
+
+       /*
+        * Configure peripherals.
+        */
+       orion5x_ehci0_init();
+       orion5x_eth_init(&wrt350n_v2_eth_data);
+       orion5x_uart0_init();
+
+       orion5x_setup_dev_boot_win(WRT350N_V2_NOR_BOOT_BASE,
+                                  WRT350N_V2_NOR_BOOT_SIZE);
+       platform_device_register(&wrt350n_v2_nor_flash);
+}
+
+static int __init wrt350n_v2_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       int irq;
+
+       /*
+        * Check for devices with hard-wired IRQs.
+        */
+       irq = orion5x_pci_map_irq(dev, slot, pin);
+       if (irq != -1)
+               return irq;
+
+       /*
+        * Mini-PCI slot.
+        */
+       if (slot == 7)
+               return gpio_to_irq(4);
+
+       return -1;
+}
+
+static struct hw_pci wrt350n_v2_pci __initdata = {
+       .nr_controllers = 2,
+       .swizzle        = pci_std_swizzle,
+       .setup          = orion5x_pci_sys_setup,
+       .scan           = orion5x_pci_sys_scan_bus,
+       .map_irq        = wrt350n_v2_pci_map_irq,
+};
+
+static int __init wrt350n_v2_pci_init(void)
+{
+       if (machine_is_wrt350n_v2())
+               pci_common_init(&wrt350n_v2_pci);
+
+       return 0;
+}
+subsys_initcall(wrt350n_v2_pci_init);
+
+MACHINE_START(WRT350N_V2, "Linksys WRT350N v2")
+       /* Maintainer: Lennert Buytenhek <buytenh@marvell.com> */
+       .phys_io        = ORION5X_REGS_PHYS_BASE,
+       .io_pg_offst    = ((ORION5X_REGS_VIRT_BASE) >> 18) & 0xFFFC,
+       .boot_params    = 0x00000100,
+       .init_machine   = wrt350n_v2_init,
+       .map_io         = orion5x_map_io,
+       .init_irq       = orion5x_init_irq,
+       .timer          = &orion5x_timer,
+       .fixup          = tag_fixup_mem32,
+MACHINE_END
index 5da7a68..914bb33 100644 (file)
@@ -20,8 +20,7 @@ endmenu
 
 endif
 
-choice
-       prompt "Select target board"
+menu "Select target boards"
 
 config ARCH_GUMSTIX
        bool "Gumstix XScale boards"
@@ -37,10 +36,12 @@ config ARCH_LUBBOCK
 config MACH_LOGICPD_PXA270
        bool "LogicPD PXA270 Card Engine Development Platform"
        select PXA27x
+       select HAVE_PWM
 
 config MACH_MAINSTONE
        bool "Intel HCDDBBVA0 Development Platform"
        select PXA27x
+       select HAVE_PWM
 
 config ARCH_PXA_IDP
        bool "Accelent Xscale IDP"
@@ -116,6 +117,7 @@ config MACH_COLIBRI
 config MACH_ZYLONITE
        bool "PXA3xx Development Platform"
        select PXA3xx
+       select HAVE_PWM
 
 config MACH_LITTLETON
        bool "PXA3xx Form Factor Platform (aka Littleton)"
@@ -138,7 +140,7 @@ config MACH_PCM027
        select PXA27x
        select IWMMXT
 
-endchoice
+endmenu
 
 choice
        prompt "Used baseboard"
@@ -146,25 +148,24 @@ choice
 
 config MACH_PCM990_BASEBOARD
        bool "PHYTEC PCM-990 development board"
+       select HAVE_PWM
 
 endchoice
 
-if PXA_SHARPSL
-
 choice
-       prompt "Select target Sharp Zaurus device range"
+       prompt "display on pcm990"
+       depends on MACH_PCM990_BASEBOARD
 
-config PXA_SHARPSL_25x
-       bool "Sharp PXA25x models (SL-5600, SL-C7xx and SL-C6000x)"
-       select PXA25x
+config PCM990_DISPLAY_SHARP
+       bool "sharp lq084v1dg21 stn display"
 
-config PXA_SHARPSL_27x
-       bool "Sharp PXA270 models (SL-Cxx00)"
-       select PXA27x
+config PCM990_DISPLAY_NEC
+       bool "nec nl6448bc20_18d tft display"
 
-endchoice
+config PCM990_DISPLAY_NONE
+       bool "no display"
 
-endif
+endchoice
 
 if ARCH_GUMSTIX
 
@@ -199,28 +200,33 @@ endmenu
 
 config MACH_POODLE
        bool "Enable Sharp SL-5600 (Poodle) Support"
-       depends on PXA_SHARPSL_25x
+       depends on PXA_SHARPSL
+       select PXA25x
        select SHARP_LOCOMO
        select PXA_SSP
 
 config MACH_CORGI
        bool "Enable Sharp SL-C700 (Corgi) Support"
-       depends on PXA_SHARPSL_25x
+       depends on PXA_SHARPSL
+       select PXA25x
        select PXA_SHARP_C7xx
 
 config MACH_SHEPHERD
        bool "Enable Sharp SL-C750 (Shepherd) Support"
-       depends on PXA_SHARPSL_25x
+       depends on PXA_SHARPSL
+       select PXA25x
        select PXA_SHARP_C7xx
 
 config MACH_HUSKY
        bool "Enable Sharp SL-C760 (Husky) Support"
-       depends on PXA_SHARPSL_25x
+       depends on PXA_SHARPSL
+       select PXA25x
        select PXA_SHARP_C7xx
 
 config MACH_AKITA
        bool "Enable Sharp SL-1000 (Akita) Support"
-       depends on PXA_SHARPSL_27x
+       depends on PXA_SHARPSL
+       select PXA27x
        select PXA_SHARP_Cxx00
        select MACH_SPITZ
        select I2C
@@ -228,17 +234,20 @@ config MACH_AKITA
 
 config MACH_SPITZ
        bool "Enable Sharp Zaurus SL-3000 (Spitz) Support"
-       depends on PXA_SHARPSL_27x
+       depends on PXA_SHARPSL
+       select PXA27x
        select PXA_SHARP_Cxx00
 
 config MACH_BORZOI
        bool "Enable Sharp Zaurus SL-3100 (Borzoi) Support"
-       depends on PXA_SHARPSL_27x
+       depends on PXA_SHARPSL
+       select PXA27x
        select PXA_SHARP_Cxx00
 
 config MACH_TOSA
        bool "Enable Sharp SL-6000x (Tosa) Support"
-       depends on PXA_SHARPSL_25x
+       depends on PXA_SHARPSL
+       select PXA25x
 
 config PXA25x
        bool
@@ -273,4 +282,10 @@ config PXA_SSP
        tristate
        help
          Enable support for PXA2xx SSP ports
+
+config PXA_PWM
+       tristate
+       default BACKLIGHT_PWM
+       help
+         Enable support for PXA2xx/PXA3xx PWM controllers
 endif
index 0e6d05b..c4dfbe8 100644 (file)
@@ -10,10 +10,11 @@ obj-$(CONFIG_CPU_FREQ)              += cpu-pxa.o
 
 # Generic drivers that other drivers may depend upon
 obj-$(CONFIG_PXA_SSP)          += ssp.o
+obj-$(CONFIG_PXA_PWM)          += pwm.o
 
 # SoC-specific code
-obj-$(CONFIG_PXA25x)           += mfp-pxa2xx.o pxa25x.o
-obj-$(CONFIG_PXA27x)           += mfp-pxa2xx.o pxa27x.o
+obj-$(CONFIG_PXA25x)           += mfp-pxa2xx.o pxa2xx.o pxa25x.o
+obj-$(CONFIG_PXA27x)           += mfp-pxa2xx.o pxa2xx.o pxa27x.o
 obj-$(CONFIG_PXA3xx)           += mfp-pxa3xx.o pxa3xx.o smemc.o
 obj-$(CONFIG_CPU_PXA300)       += pxa300.o
 obj-$(CONFIG_CPU_PXA320)       += pxa320.o
index e97dc59..b4d0495 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 
-#include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include <asm/hardware.h>
 
@@ -47,6 +47,9 @@ struct clk *clk_get(struct device *dev, const char *id)
                clk = p;
        mutex_unlock(&clocks_mutex);
 
+       if (!IS_ERR(clk) && clk->ops == NULL)
+               clk = clk->other;
+
        return clk;
 }
 EXPORT_SYMBOL(clk_get);
index bc6b77e..83cbfab 100644 (file)
@@ -15,6 +15,7 @@ struct clk {
        unsigned int            cken;
        unsigned int            delay;
        unsigned int            enabled;
+       struct clk              *other;
 };
 
 #define INIT_CKEN(_name, _cken, _rate, _delay, _dev)   \
@@ -35,6 +36,17 @@ struct clk {
                .cken   = CKEN_##_cken,                 \
        }
 
+/*
+ * This is a placeholder to alias one clock device+name pair
+ * to another struct clk.
+ */
+#define INIT_CKOTHER(_name, _other, _dev)              \
+       {                                               \
+               .name   = _name,                        \
+               .dev    = _dev,                         \
+               .other  = _other,                       \
+       }
+
 extern const struct clkops clk_cken_ops;
 
 void clk_cken_enable(struct clk *clk);
index ac7f05f..319c9ff 100644 (file)
@@ -41,18 +41,20 @@ void __init cmx270_pci_adjust_zones(int node, unsigned long *zone_size,
 {
        unsigned int sz = SZ_64M >> PAGE_SHIFT;
 
-       pr_info("Adjusting zones for CM-x270\n");
-
-       /*
-        * Only adjust if > 64M on current system
-        */
-       if (node || (zone_size[0] <= sz))
-               return;
-
-       zone_size[1] = zone_size[0] - sz;
-       zone_size[0] = sz;
-       zhole_size[1] = zhole_size[0];
-       zhole_size[0] = 0;
+       if (machine_is_armcore()) {
+               pr_info("Adjusting zones for CM-x270\n");
+
+               /*
+                * Only adjust if > 64M on current system
+                */
+               if (node || (zone_size[0] <= sz))
+                       return;
+
+               zone_size[1] = zone_size[0] - sz;
+               zone_size[0] = sz;
+               zhole_size[1] = zhole_size[0];
+               zhole_size[0] = 0;
+       }
 }
 
 static void cmx270_it8152_irq_demux(unsigned int irq, struct irq_desc *desc)
index f5851d1..01b9964 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/arch/pxa-regs.h>
 #include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
+#include <asm/arch/audio.h>
 #include <asm/arch/pxafb.h>
 #include <asm/arch/ohci.h>
 #include <asm/arch/mmc.h>
@@ -81,12 +82,6 @@ static struct platform_device cmx270_device_dm9k = {
        }
 };
 
-/* audio device */
-static struct platform_device cmx270_audio_device = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-};
-
 /* touchscreen controller */
 static struct platform_device cmx270_ts_device = {
        .name           = "ucb1400_ts",
@@ -219,7 +214,6 @@ static struct platform_device cmx270_ata = {
 /* platform devices */
 static struct platform_device *platform_devices[] __initdata = {
        &cmx270_device_dm9k,
-       &cmx270_audio_device,
        &cmx270_rtc_device,
        &cmx270_2700G,
        &cmx270_led_device,
@@ -594,6 +588,7 @@ static void __init cmx270_init(void)
 
        /* register CM-X270 platform devices */
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+       pxa_set_ac97_info(NULL);
 
        /* set MCI and OHCI platform parameters */
        pxa_set_mci_info(&cmx270_mci_platform_data);
index b757dd7..b37671b 100644 (file)
@@ -36,6 +36,7 @@
 #include <asm/mach/irq.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/mmc.h>
index 0a85f70..e91c0f2 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/arch/sharpsl.h>
 #include <asm/arch/corgi.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include "sharpsl.h"
 
@@ -204,7 +205,9 @@ static struct sharpsl_charger_machinfo corgi_pm_machinfo = {
        .read_devdata    = corgipm_read_devdata,
        .charger_wakeup  = corgi_charger_wakeup,
        .should_wakeup   = corgi_should_wakeup,
+#ifdef CONFIG_BACKLIGHT_CORGI
        .backlight_limit = corgibl_limit_intensity,
+#endif
        .charge_on_volt   = SHARPSL_CHARGE_ON_VOLT,
        .charge_on_temp   = SHARPSL_CHARGE_ON_TEMP,
        .charge_acin_high = SHARPSL_CHARGE_ON_ACIN_HIGH,
@@ -226,6 +229,10 @@ static int __devinit corgipm_init(void)
 {
        int ret;
 
+       if (!machine_is_corgi() && !machine_is_shepherd()
+                       && !machine_is_husky())
+               return -ENODEV;
+
        corgipm_device = platform_device_alloc("sharpsl-pm", -1);
        if (!corgipm_device)
                return -ENOMEM;
index d6c05b6..a6f2390 100644 (file)
 #include <asm/arch/mmc.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/i2c.h>
+#include <asm/arch/mfp-pxa27x.h>
 #include <asm/arch/ohci.h>
 #include <asm/arch/pxa27x_keypad.h>
 #include <asm/arch/camera.h>
+#include <asm/arch/audio.h>
 
 #include "devices.h"
+#include "generic.h"
 
 void __init pxa_register_device(struct platform_device *dev, void *data)
 {
@@ -91,8 +94,19 @@ static struct resource pxa2xx_udc_resources[] = {
 
 static u64 udc_dma_mask = ~(u32)0;
 
-struct platform_device pxa_device_udc = {
-       .name           = "pxa2xx-udc",
+struct platform_device pxa25x_device_udc = {
+       .name           = "pxa25x-udc",
+       .id             = -1,
+       .resource       = pxa2xx_udc_resources,
+       .num_resources  = ARRAY_SIZE(pxa2xx_udc_resources),
+       .dev            =  {
+               .platform_data  = &pxa_udc_info,
+               .dma_mask       = &udc_dma_mask,
+       }
+};
+
+struct platform_device pxa27x_device_udc = {
+       .name           = "pxa27x-udc",
        .id             = -1,
        .resource       = pxa2xx_udc_resources,
        .num_resources  = ARRAY_SIZE(pxa2xx_udc_resources),
@@ -233,8 +247,15 @@ struct platform_device pxa_device_i2c = {
        .num_resources  = ARRAY_SIZE(pxai2c_resources),
 };
 
+static unsigned long pxa27x_i2c_mfp_cfg[] = {
+       GPIO117_I2C_SCL,
+       GPIO118_I2C_SDA,
+};
+
 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
 {
+       if (cpu_is_pxa27x())
+               pxa2xx_mfp_config(ARRAY_AND_SIZE(pxa27x_i2c_mfp_cfg));
        pxa_register_device(&pxa_device_i2c, info);
 }
 
@@ -278,8 +299,69 @@ struct platform_device pxa_device_rtc = {
        .id             = -1,
 };
 
+static struct resource pxa_ac97_resources[] = {
+       [0] = {
+               .start  = 0x40500000,
+               .end    = 0x40500000 + 0xfff,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_AC97,
+               .end    = IRQ_AC97,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static u64 pxa_ac97_dmamask = 0xffffffffUL;
+
+struct platform_device pxa_device_ac97 = {
+       .name           = "pxa2xx-ac97",
+       .id             = -1,
+       .dev            = {
+               .dma_mask = &pxa_ac97_dmamask,
+               .coherent_dma_mask = 0xffffffff,
+       },
+       .num_resources  = ARRAY_SIZE(pxa_ac97_resources),
+       .resource       = pxa_ac97_resources,
+};
+
+void __init pxa_set_ac97_info(pxa2xx_audio_ops_t *ops)
+{
+       pxa_register_device(&pxa_device_ac97, ops);
+}
+
 #ifdef CONFIG_PXA25x
 
+static struct resource pxa25x_resource_pwm0[] = {
+       [0] = {
+               .start  = 0x40b00000,
+               .end    = 0x40b0000f,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device pxa25x_device_pwm0 = {
+       .name           = "pxa25x-pwm",
+       .id             = 0,
+       .resource       = pxa25x_resource_pwm0,
+       .num_resources  = ARRAY_SIZE(pxa25x_resource_pwm0),
+};
+
+static struct resource pxa25x_resource_pwm1[] = {
+       [0] = {
+               .start  = 0x40c00000,
+               .end    = 0x40c0000f,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device pxa25x_device_pwm1 = {
+       .name           = "pxa25x-pwm",
+       .id             = 1,
+       .resource       = pxa25x_resource_pwm1,
+       .num_resources  = ARRAY_SIZE(pxa25x_resource_pwm1),
+};
+
 static u64 pxa25x_ssp_dma_mask = DMA_BIT_MASK(32);
 
 static struct resource pxa25x_resource_ssp[] = {
@@ -568,6 +650,36 @@ struct platform_device pxa27x_device_ssp3 = {
        .num_resources  = ARRAY_SIZE(pxa27x_resource_ssp3),
 };
 
+static struct resource pxa27x_resource_pwm0[] = {
+       [0] = {
+               .start  = 0x40b00000,
+               .end    = 0x40b0001f,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device pxa27x_device_pwm0 = {
+       .name           = "pxa27x-pwm",
+       .id             = 0,
+       .resource       = pxa27x_resource_pwm0,
+       .num_resources  = ARRAY_SIZE(pxa27x_resource_pwm0),
+};
+
+static struct resource pxa27x_resource_pwm1[] = {
+       [0] = {
+               .start  = 0x40c00000,
+               .end    = 0x40c0001f,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device pxa27x_device_pwm1 = {
+       .name           = "pxa27x-pwm",
+       .id             = 1,
+       .resource       = pxa27x_resource_pwm1,
+       .num_resources  = ARRAY_SIZE(pxa27x_resource_pwm1),
+};
+
 static struct resource pxa27x_resource_camera[] = {
        [0] = {
                .start  = 0x50000000,
index fcab017..b852eb1 100644 (file)
@@ -1,7 +1,8 @@
 extern struct platform_device pxa_device_mci;
 extern struct platform_device pxa3xx_device_mci2;
 extern struct platform_device pxa3xx_device_mci3;
-extern struct platform_device pxa_device_udc;
+extern struct platform_device pxa25x_device_udc;
+extern struct platform_device pxa27x_device_udc;
 extern struct platform_device pxa_device_fb;
 extern struct platform_device pxa_device_ffuart;
 extern struct platform_device pxa_device_btuart;
@@ -11,6 +12,7 @@ extern struct platform_device pxa_device_i2c;
 extern struct platform_device pxa_device_i2s;
 extern struct platform_device pxa_device_ficp;
 extern struct platform_device pxa_device_rtc;
+extern struct platform_device pxa_device_ac97;
 
 extern struct platform_device pxa27x_device_i2c_power;
 extern struct platform_device pxa27x_device_ohci;
@@ -24,4 +26,9 @@ extern struct platform_device pxa27x_device_ssp2;
 extern struct platform_device pxa27x_device_ssp3;
 extern struct platform_device pxa3xx_device_ssp4;
 
+extern struct platform_device pxa25x_device_pwm0;
+extern struct platform_device pxa25x_device_pwm1;
+extern struct platform_device pxa27x_device_pwm0;
+extern struct platform_device pxa27x_device_pwm1;
+
 void __init pxa_register_device(struct platform_device *dev, void *data);
index 9c57700..1bf6807 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <asm/arch/pxa-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
+#include <asm/arch/pxa27x-udc.h>
+#include <asm/arch/audio.h>
 #include <asm/arch/pxafb.h>
 #include <asm/arch/ohci.h>
 #include <asm/arch/mmc.h>
@@ -72,12 +74,6 @@ static struct platform_device em_x270_dm9k = {
        }
 };
 
-/* audio device */
-static struct platform_device em_x270_audio = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-};
-
 /* WM9712 touchscreen controller. Hopefully the driver will make it to
  * the mainstream sometime */
 static struct platform_device em_x270_ts = {
@@ -217,7 +213,6 @@ static struct platform_device em_x270_nand = {
 /* platform devices */
 static struct platform_device *platform_devices[] __initdata = {
        &em_x270_dm9k,
-       &em_x270_audio,
        &em_x270_ts,
        &em_x270_rtc,
        &em_x270_nand,
@@ -325,6 +320,7 @@ static void __init em_x270_init(void)
 
        /* register EM-X270 platform devices */
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+       pxa_set_ac97_info(NULL);
 
        /* set MCI and OHCI platform parameters */
        pxa_set_mci_info(&em_x270_mci_platform_data);
index 4461793..ca05322 100644 (file)
@@ -59,23 +59,6 @@ unsigned int get_memclk_frequency_10khz(void)
 }
 EXPORT_SYMBOL(get_memclk_frequency_10khz);
 
-/*
- * Routine to safely enable or disable a clock in the CKEN
- */
-void __pxa_set_cken(int clock, int enable)
-{
-       unsigned long flags;
-       local_irq_save(flags);
-
-       if (enable)
-               CKEN |= (1 << clock);
-       else
-               CKEN &= ~(1 << clock);
-
-       local_irq_restore(flags);
-}
-EXPORT_SYMBOL(__pxa_set_cken);
-
 /*
  * Intel PXA2xx internal register mapping.
  *
index a9a0c3f..fbff557 100644 (file)
@@ -21,7 +21,6 @@
 #include <asm/irq.h>
 #include <asm/mach/irq.h>
 #include <asm/arch/pxa-regs.h>
-#include <asm/arch/pxa2xx-gpio.h>
 
 #include "generic.h"
 
index a20e4b1..cc1c4fa 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/ioport.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
+#include <linux/pwm_backlight.h>
 
 #include <asm/types.h>
 #include <asm/setup.h>
@@ -134,9 +135,12 @@ static struct sys_device lpd270_irq_device = {
 
 static int __init lpd270_irq_device_init(void)
 {
-       int ret = sysdev_class_register(&lpd270_irq_sysclass);
-       if (ret == 0)
-               ret = sysdev_register(&lpd270_irq_device);
+       int ret = -ENODEV;
+       if (machine_is_logicpd_pxa270()) {
+               ret = sysdev_class_register(&lpd270_irq_sysclass);
+               if (ret == 0)
+                       ret = sysdev_register(&lpd270_irq_device);
+       }
        return ret;
 }
 
@@ -164,11 +168,6 @@ static struct platform_device smc91x_device = {
        .resource       = smc91x_resources,
 };
 
-static struct platform_device lpd270_audio_device = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-};
-
 static struct resource lpd270_flash_resources[] = {
        [0] = {
                .start  = PXA_CS0_PHYS,
@@ -233,21 +232,20 @@ static struct platform_device lpd270_flash_device[2] = {
        },
 };
 
-static void lpd270_backlight_power(int on)
-{
-       if (on) {
-               pxa_gpio_mode(GPIO16_PWM0_MD);
-               pxa_set_cken(CKEN_PWM0, 1);
-               PWM_CTRL0 = 0;
-               PWM_PWDUTY0 = 0x3ff;
-               PWM_PERVAL0 = 0x3ff;
-       } else {
-               PWM_CTRL0 = 0;
-               PWM_PWDUTY0 = 0x0;
-               PWM_PERVAL0 = 0x3FF;
-               pxa_set_cken(CKEN_PWM0, 0);
-       }
-}
+static struct platform_pwm_backlight_data lpd270_backlight_data = {
+       .pwm_id         = 0,
+       .max_brightness = 1,
+       .dft_brightness = 1,
+       .pwm_period_ns  = 78770,
+};
+
+static struct platform_device lpd270_backlight_device = {
+       .name           = "pwm-backlight",
+       .dev            = {
+               .parent = &pxa27x_device_pwm0.dev,
+               .platform_data = &lpd270_backlight_data,
+       },
+};
 
 /* 5.7" TFT QVGA (LoLo display number 1) */
 static struct pxafb_mode_info sharp_lq057q3dc02_mode = {
@@ -269,7 +267,6 @@ static struct pxafb_mach_info sharp_lq057q3dc02 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 /* 12.1" TFT SVGA (LoLo display number 2) */
@@ -292,7 +289,6 @@ static struct pxafb_mach_info sharp_lq121s1dg31 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 /* 3.6" TFT QVGA (LoLo display number 3) */
@@ -315,7 +311,6 @@ static struct pxafb_mach_info sharp_lq036q1da01 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 /* 6.4" TFT VGA (LoLo display number 5) */
@@ -338,7 +333,6 @@ static struct pxafb_mach_info sharp_lq64d343 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 /* 10.4" TFT VGA (LoLo display number 7) */
@@ -361,7 +355,6 @@ static struct pxafb_mach_info sharp_lq10d368 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 /* 3.5" TFT QVGA (LoLo display number 8) */
@@ -384,7 +377,6 @@ static struct pxafb_mach_info sharp_lq035q7db02_20 = {
        .num_modes              = 1,
        .lccr0                  = 0x07800080,
        .lccr3                  = 0x00400000,
-       .pxafb_backlight_power  = lpd270_backlight_power,
 };
 
 static struct pxafb_mach_info *lpd270_lcd_to_use;
@@ -414,7 +406,7 @@ __setup("lcd=", lpd270_set_lcd);
 
 static struct platform_device *platform_devices[] __initdata = {
        &smc91x_device,
-       &lpd270_audio_device,
+       &lpd270_backlight_device,
        &lpd270_flash_device[0],
        &lpd270_flash_device[1],
 };
@@ -454,9 +446,12 @@ static void __init lpd270_init(void)
         * On LogicPD PXA270, we route AC97_SYSCLK via GPIO45.
         */
        pxa_gpio_mode(GPIO45_SYSCLK_AC97_MD);
+       pxa_gpio_mode(GPIO16_PWM0_MD);
 
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 
+       pxa_set_ac97_info(NULL);
+
        if (lpd270_lcd_to_use != NULL)
                set_pxa_fb_info(lpd270_lcd_to_use);
 
index 7b9bdd0..a3fae41 100644 (file)
@@ -43,6 +43,7 @@
 #include <asm/arch/pxa-regs.h>
 #include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/mfp-pxa25x.h>
+#include <asm/arch/audio.h>
 #include <asm/arch/lubbock.h>
 #include <asm/arch/udc.h>
 #include <asm/arch/irda.h>
@@ -196,11 +197,6 @@ static struct pxa2xx_udc_mach_info udc_info __initdata = {
        // no D+ pullup; lubbock can't connect/disconnect in software
 };
 
-static struct platform_device lub_audio_device = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-};
-
 static struct resource sa1111_resources[] = {
        [0] = {
                .start  = 0x10000000,
@@ -368,7 +364,6 @@ static struct platform_device lubbock_flash_device[2] = {
 
 static struct platform_device *devices[] __initdata = {
        &sa1111_device,
-       &lub_audio_device,
        &smc91x_device,
        &lubbock_flash_device[0],
        &lubbock_flash_device[1],
@@ -494,6 +489,7 @@ static void __init lubbock_init(void)
        set_pxa_fb_info(&sharp_lm8v31);
        pxa_set_mci_info(&lubbock_mci_platform_data);
        pxa_set_ficp_info(&lubbock_ficp_platform_data);
+       pxa_set_ac97_info(NULL);
 
        lubbock_flash_data[0].width = lubbock_flash_data[1].width =
                (BOOT_DEF & 1) ? 2 : 4;
index badba06..01b2fa7 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/mtd/map.h>
 #include <linux/mtd/physmap.h>
 #include <linux/pda_power.h>
+#include <linux/pwm_backlight.h>
 
 #include <asm/gpio.h>
 #include <asm/hardware.h>
 #include <asm/arch/magician.h>
 #include <asm/arch/mfp-pxa27x.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxafb.h>
 #include <asm/arch/i2c.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/ohci.h>
 
+#include "devices.h"
 #include "generic.h"
 
 static unsigned long magician_pin_config[] = {
@@ -348,40 +351,58 @@ static struct pxafb_mach_info samsung_info = {
  * Backlight
  */
 
-static void magician_set_bl_intensity(int intensity)
+static int magician_backlight_init(struct device *dev)
 {
-       if (intensity) {
-               PWM_CTRL0 = 1;
-               PWM_PERVAL0 = 0xc8;
-               if (intensity > 0xc7) {
-                       PWM_PWDUTY0 = intensity - 0x48;
-                       gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
-               } else {
-                       PWM_PWDUTY0 = intensity;
-                       gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
-               }
-               gpio_set_value(EGPIO_MAGICIAN_BL_POWER, 1);
-               pxa_set_cken(CKEN_PWM0, 1);
+       int ret;
+
+       ret = gpio_request(EGPIO_MAGICIAN_BL_POWER, "BL_POWER");
+       if (ret)
+               goto err;
+       ret = gpio_request(EGPIO_MAGICIAN_BL_POWER2, "BL_POWER2");
+       if (ret)
+               goto err2;
+       return 0;
+
+err2:
+       gpio_free(EGPIO_MAGICIAN_BL_POWER);
+err:
+       return ret;
+}
+
+static int magician_backlight_notify(int brightness)
+{
+       gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
+       if (brightness >= 200) {
+               gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
+               return brightness - 72;
        } else {
-               /* PWM_PWDUTY0 = intensity; */
-               gpio_set_value(EGPIO_MAGICIAN_BL_POWER, 0);
-               pxa_set_cken(CKEN_PWM0, 0);
+               gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
+               return brightness;
        }
 }
 
-static struct generic_bl_info backlight_info = {
-       .default_intensity = 0x64,
-       .limit_mask        = 0x0b,
-       .max_intensity     = 0xc7+0x48,
-       .set_bl_intensity  = magician_set_bl_intensity,
+static void magician_backlight_exit(struct device *dev)
+{
+       gpio_free(EGPIO_MAGICIAN_BL_POWER);
+       gpio_free(EGPIO_MAGICIAN_BL_POWER2);
+}
+
+static struct platform_pwm_backlight_data backlight_data = {
+       .pwm_id         = 0,
+       .max_brightness = 272,
+       .dft_brightness = 100,
+       .pwm_period_ns  = 30923,
+       .init           = magician_backlight_init,
+       .notify         = magician_backlight_notify,
+       .exit           = magician_backlight_exit,
 };
 
 static struct platform_device backlight = {
-       .name = "generic-bl",
+       .name = "pwm-backlight",
        .dev  = {
-               .platform_data = &backlight_info,
+               .parent        = &pxa27x_device_pwm0.dev,
+               .platform_data = &backlight_data,
        },
-       .id   = -1,
 };
 
 /*
index 7399fb3..f2e9e7c 100644 (file)
@@ -23,9 +23,9 @@
 #include <linux/ioport.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
-#include <linux/backlight.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
+#include <linux/pwm_backlight.h>
 
 #include <asm/types.h>
 #include <asm/setup.h>
@@ -280,12 +280,6 @@ static pxa2xx_audio_ops_t mst_audio_ops = {
        .resume         = mst_audio_resume,
 };
 
-static struct platform_device mst_audio_device = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-       .dev            = { .platform_data = &mst_audio_ops },
-};
-
 static struct resource flash_resources[] = {
        [0] = {
                .start  = PXA_CS0_PHYS,
@@ -349,56 +343,27 @@ static struct platform_device mst_flash_device[2] = {
        },
 };
 
-#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
-static int mainstone_backlight_update_status(struct backlight_device *bl)
-{
-       int brightness = bl->props.brightness;
-
-       if (bl->props.power != FB_BLANK_UNBLANK ||
-           bl->props.fb_blank != FB_BLANK_UNBLANK)
-               brightness = 0;
-
-       if (brightness != 0)
-               pxa_set_cken(CKEN_PWM0, 1);
-
-       PWM_CTRL0 = 0;
-       PWM_PWDUTY0 = brightness;
-       PWM_PERVAL0 = bl->props.max_brightness;
-
-       if (brightness == 0)
-               pxa_set_cken(CKEN_PWM0, 0);
-       return 0; /* pointless return value */
-}
-
-static int mainstone_backlight_get_brightness(struct backlight_device *bl)
-{
-       return PWM_PWDUTY0;
-}
+#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
+static struct platform_pwm_backlight_data mainstone_backlight_data = {
+       .pwm_id         = 0,
+       .max_brightness = 1023,
+       .dft_brightness = 1023,
+       .pwm_period_ns  = 78770,
+};
 
-static /*const*/ struct backlight_ops mainstone_backlight_ops = {
-       .update_status  = mainstone_backlight_update_status,
-       .get_brightness = mainstone_backlight_get_brightness,
+static struct platform_device mainstone_backlight_device = {
+       .name           = "pwm-backlight",
+       .dev            = {
+               .parent = &pxa27x_device_pwm0.dev,
+               .platform_data = &mainstone_backlight_data,
+       },
 };
 
 static void __init mainstone_backlight_register(void)
 {
-       struct backlight_device *bl;
-
-       bl = backlight_device_register("mainstone-bl", &pxa_device_fb.dev,
-                                      NULL, &mainstone_backlight_ops);
-       if (IS_ERR(bl)) {
-               printk(KERN_ERR "mainstone: unable to register backlight: %ld\n",
-                      PTR_ERR(bl));
-               return;
-       }
-
-       /*
-        * broken design - register-then-setup interfaces are
-        * utterly broken by definition.
-        */
-       bl->props.max_brightness = 1023;
-       bl->props.brightness = 1023;
-       backlight_update_status(bl);
+       int ret = platform_device_register(&mainstone_backlight_device);
+       if (ret)
+               printk(KERN_ERR "mainstone: failed to register backlight device: %d\n", ret);
 }
 #else
 #define mainstone_backlight_register() do { } while (0)
@@ -528,7 +493,6 @@ static struct platform_device mst_gpio_keys_device = {
 
 static struct platform_device *platform_devices[] __initdata = {
        &smc91x_device,
-       &mst_audio_device,
        &mst_flash_device[0],
        &mst_flash_device[1],
        &mst_gpio_keys_device,
@@ -638,6 +602,7 @@ static void __init mainstone_init(void)
        pxa_set_ficp_info(&mainstone_ficp_platform_data);
        pxa_set_ohci_info(&mainstone_ohci_platform_data);
        pxa_set_i2c_info(NULL);
+       pxa_set_ac97_info(&mst_audio_ops);
 
        mainstone_init_keypad();
 }
index 22097a1..d1cdb4e 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <asm/arch/hardware.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/mfp-pxa2xx.h>
 
 #include "generic.h"
index 49d951d..5d87c7c 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/platform_device.h>
 #include <linux/ide.h>
 #include <linux/i2c.h>
+#include <linux/pwm_backlight.h>
 
 #include <media/soc_camera.h>
 
 #include <asm/mach/map.h>
 #include <asm/arch/pxa-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
+#include <asm/arch/audio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/ohci.h>
 #include <asm/arch/pcm990_baseboard.h>
+#include <asm/arch/pxafb.h>
+
+#include "devices.h"
 
 /*
- * The PCM-990 development baseboard uses PCM-027's hardeware in the
+ * pcm990_lcd_power - control power supply to the LCD
+ * @on: 0 = switch off, 1 = switch on
+ *
+ * Called by the pxafb driver
+ */
+#ifndef CONFIG_PCM990_DISPLAY_NONE
+static void pcm990_lcd_power(int on, struct fb_var_screeninfo *var)
+{
+       if (on) {
+               /* enable LCD-Latches
+                * power on LCD
+                */
+               __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG3) =
+                       PCM990_CTRL_LCDPWR + PCM990_CTRL_LCDON;
+       } else {
+               /* disable LCD-Latches
+                * power off LCD
+                */
+               __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG3) = 0x00;
+       }
+}
+#endif
+
+#if defined(CONFIG_PCM990_DISPLAY_SHARP)
+static struct pxafb_mode_info fb_info_sharp_lq084v1dg21 = {
+       .pixclock               = 28000,
+       .xres                   = 640,
+       .yres                   = 480,
+       .bpp                    = 16,
+       .hsync_len              = 20,
+       .left_margin            = 103,
+       .right_margin           = 47,
+       .vsync_len              = 6,
+       .upper_margin           = 28,
+       .lower_margin           = 5,
+       .sync                   = 0,
+       .cmap_greyscale         = 0,
+};
+
+static struct pxafb_mach_info pcm990_fbinfo __initdata = {
+       .modes                  = &fb_info_sharp_lq084v1dg21,
+       .num_modes              = 1,
+       .lccr0                  = LCCR0_PAS,
+       .lccr3                  = LCCR3_PCP,
+       .pxafb_lcd_power        = pcm990_lcd_power,
+};
+#elif defined(CONFIG_PCM990_DISPLAY_NEC)
+struct pxafb_mode_info fb_info_nec_nl6448bc20_18d = {
+       .pixclock               = 39720,
+       .xres                   = 640,
+       .yres                   = 480,
+       .bpp                    = 16,
+       .hsync_len              = 32,
+       .left_margin            = 16,
+       .right_margin           = 48,
+       .vsync_len              = 2,
+       .upper_margin           = 12,
+       .lower_margin           = 17,
+       .sync                   = 0,
+       .cmap_greyscale         = 0,
+};
+
+static struct pxafb_mach_info pcm990_fbinfo __initdata = {
+       .modes                  = &fb_info_nec_nl6448bc20_18d,
+       .num_modes              = 1,
+       .lccr0                  = LCCR0_Act,
+       .lccr3                  = LCCR3_PixFlEdg,
+       .pxafb_lcd_power        = pcm990_lcd_power,
+};
+#endif
+
+static struct platform_pwm_backlight_data pcm990_backlight_data = {
+       .pwm_id         = 0,
+       .max_brightness = 1023,
+       .dft_brightness = 1023,
+       .pwm_period_ns  = 78770,
+};
+
+static struct platform_device pcm990_backlight_device = {
+       .name           = "pwm-backlight",
+       .dev            = {
+               .parent = &pxa27x_device_pwm0.dev,
+               .platform_data = &pcm990_backlight_data,
+       },
+};
+
+/*
+ * The PCM-990 development baseboard uses PCM-027's hardware in the
  * following way:
  *
  * - LCD support is in use
@@ -332,36 +424,6 @@ static struct i2c_board_info __initdata pcm990_i2c_devices[] = {
 };
 #endif /* CONFIG_VIDEO_PXA27x ||CONFIG_VIDEO_PXA27x_MODULE */
 
-/*
- * AC97 support
- * Note: The connected AC97 mixer also reports interrupts at PCM990_AC97_IRQ
- */
-static struct resource pxa27x_ac97_resources[] = {
-       [0] = {
-               .start  = 0x40500000,
-               .end    = 0x40500000 + 0xfff,
-               .flags  = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start  = IRQ_AC97,
-               .end    = IRQ_AC97,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-static u64 pxa_ac97_dmamask = 0xffffffffUL;
-
-static struct platform_device pxa27x_device_ac97 = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-       .dev            = {
-               .dma_mask = &pxa_ac97_dmamask,
-               .coherent_dma_mask = 0xffffffff,
-       },
-       .num_resources  = ARRAY_SIZE(pxa27x_ac97_resources),
-       .resource       = pxa27x_ac97_resources,
-};
-
 /*
  * enable generic access to the base board control CPLDs U6 and U7
  */
@@ -393,7 +455,11 @@ void __init pcm990_baseboard_init(void)
        /* register CPLD's IRQ controller */
        pcm990_init_irq();
 
-       platform_device_register(&pxa27x_device_ac97);
+#ifndef CONFIG_PCM990_DISPLAY_NONE
+       set_pxa_fb_info(&pcm990_fbinfo);
+#endif
+       pxa_gpio_mode(GPIO16_PWM0_MD);
+       platform_device_register(&pcm990_backlight_device);
 
        /* MMC */
        pxa_set_mci_info(&pcm990_mci_platform_data);
@@ -402,6 +468,7 @@ void __init pcm990_baseboard_init(void)
        pxa_set_ohci_info(&pcm990_ohci_platform_data);
 
        pxa_set_i2c_info(NULL);
+       pxa_set_ac97_info(NULL);
 
 #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
        pxa_set_camera_info(&pcm990_pxacamera_platform_data);
index 0b30f25..f81c10c 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/mach/irq.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/udc.h>
diff --git a/arch/arm/mach-pxa/pwm.c b/arch/arm/mach-pxa/pwm.c
new file mode 100644 (file)
index 0000000..ce28cd9
--- /dev/null
@@ -0,0 +1,319 @@
+/*
+ * linux/arch/arm/mach-pxa/pwm.c
+ *
+ * simple driver for PWM (Pulse Width Modulator) controller
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 2008-02-13  initial version
+ *             eric miao <eric.miao@marvell.com>
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/pwm.h>
+
+#include <asm/div64.h>
+#include <asm/arch/pxa-regs.h>
+
+/* PWM registers and bits definitions */
+#define PWMCR          (0x00)
+#define PWMDCR         (0x04)
+#define PWMPCR         (0x08)
+
+#define PWMCR_SD       (1 << 6)
+#define PWMDCR_FD      (1 << 10)
+
+struct pwm_device {
+       struct list_head        node;
+       struct platform_device *pdev;
+
+       const char      *label;
+       struct clk      *clk;
+       int             clk_enabled;
+       void __iomem    *mmio_base;
+
+       unsigned int    use_count;
+       unsigned int    pwm_id;
+};
+
+/*
+ * period_ns = 10^9 * (PRESCALE + 1) * (PV + 1) / PWM_CLK_RATE
+ * duty_ns   = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE
+ */
+int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
+{
+       unsigned long long c;
+       unsigned long period_cycles, prescale, pv, dc;
+
+       if (pwm == NULL || period_ns == 0 || duty_ns > period_ns)
+               return -EINVAL;
+
+       c = clk_get_rate(pwm->clk);
+       c = c * period_ns;
+       do_div(c, 1000000000);
+       period_cycles = c;
+
+       if (period_cycles < 0)
+               period_cycles = 1;
+       prescale = (period_cycles - 1) / 1024;
+       pv = period_cycles / (prescale + 1) - 1;
+
+       if (prescale > 63)
+               return -EINVAL;
+
+       if (duty_ns == period_ns)
+               dc = PWMDCR_FD;
+       else
+               dc = (pv + 1) * duty_ns / period_ns;
+
+       /* NOTE: the clock to PWM has to be enabled first
+        * before writing to the registers
+        */
+       clk_enable(pwm->clk);
+       __raw_writel(prescale, pwm->mmio_base + PWMCR);
+       __raw_writel(dc, pwm->mmio_base + PWMDCR);
+       __raw_writel(pv, pwm->mmio_base + PWMPCR);
+       clk_disable(pwm->clk);
+
+       return 0;
+}
+EXPORT_SYMBOL(pwm_config);
+
+int pwm_enable(struct pwm_device *pwm)
+{
+       int rc = 0;
+
+       if (!pwm->clk_enabled) {
+               rc = clk_enable(pwm->clk);
+               if (!rc)
+                       pwm->clk_enabled = 1;
+       }
+       return rc;
+}
+EXPORT_SYMBOL(pwm_enable);
+
+void pwm_disable(struct pwm_device *pwm)
+{
+       if (pwm->clk_enabled) {
+               clk_disable(pwm->clk);
+               pwm->clk_enabled = 0;
+       }
+}
+EXPORT_SYMBOL(pwm_disable);
+
+static DEFINE_MUTEX(pwm_lock);
+static LIST_HEAD(pwm_list);
+
+struct pwm_device *pwm_request(int pwm_id, const char *label)
+{
+       struct pwm_device *pwm;
+       int found = 0;
+
+       mutex_lock(&pwm_lock);
+
+       list_for_each_entry(pwm, &pwm_list, node) {
+               if (pwm->pwm_id == pwm_id) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (found) {
+               if (pwm->use_count == 0) {
+                       pwm->use_count++;
+                       pwm->label = label;
+               } else
+                       pwm = ERR_PTR(-EBUSY);
+       } else
+               pwm = ERR_PTR(-ENOENT);
+
+       mutex_unlock(&pwm_lock);
+       return pwm;
+}
+EXPORT_SYMBOL(pwm_request);
+
+void pwm_free(struct pwm_device *pwm)
+{
+       mutex_lock(&pwm_lock);
+
+       if (pwm->use_count) {
+               pwm->use_count--;
+               pwm->label = NULL;
+       } else
+               pr_warning("PWM device already freed\n");
+
+       mutex_unlock(&pwm_lock);
+}
+EXPORT_SYMBOL(pwm_free);
+
+static inline void __add_pwm(struct pwm_device *pwm)
+{
+       mutex_lock(&pwm_lock);
+       list_add_tail(&pwm->node, &pwm_list);
+       mutex_unlock(&pwm_lock);
+}
+
+static struct pwm_device *pwm_probe(struct platform_device *pdev,
+               unsigned int pwm_id, struct pwm_device *parent_pwm)
+{
+       struct pwm_device *pwm;
+       struct resource *r;
+       int ret = 0;
+
+       pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
+       if (pwm == NULL) {
+               dev_err(&pdev->dev, "failed to allocate memory\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       pwm->clk = clk_get(&pdev->dev, "PWMCLK");
+       if (IS_ERR(pwm->clk)) {
+               ret = PTR_ERR(pwm->clk);
+               goto err_free;
+       }
+       pwm->clk_enabled = 0;
+
+       pwm->use_count = 0;
+       pwm->pwm_id = pwm_id;
+       pwm->pdev = pdev;
+
+       if (parent_pwm != NULL) {
+               /* registers for the second PWM has offset of 0x10 */
+               pwm->mmio_base = parent_pwm->mmio_base + 0x10;
+               __add_pwm(pwm);
+               return pwm;
+       }
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (r == NULL) {
+               dev_err(&pdev->dev, "no memory resource defined\n");
+               ret = -ENODEV;
+               goto err_free_clk;
+       }
+
+       r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
+       if (r == NULL) {
+               dev_err(&pdev->dev, "failed to request memory resource\n");
+               ret = -EBUSY;
+               goto err_free_clk;
+       }
+
+       pwm->mmio_base = ioremap(r->start, r->end - r->start + 1);
+       if (pwm->mmio_base == NULL) {
+               dev_err(&pdev->dev, "failed to ioremap() registers\n");
+               ret = -ENODEV;
+               goto err_free_mem;
+       }
+
+       __add_pwm(pwm);
+       platform_set_drvdata(pdev, pwm);
+       return pwm;
+
+err_free_mem:
+       release_mem_region(r->start, r->end - r->start + 1);
+err_free_clk:
+       clk_put(pwm->clk);
+err_free:
+       kfree(pwm);
+       return ERR_PTR(ret);
+}
+
+static int __devinit pxa25x_pwm_probe(struct platform_device *pdev)
+{
+       struct pwm_device *pwm = pwm_probe(pdev, pdev->id, NULL);
+
+       if (IS_ERR(pwm))
+               return PTR_ERR(pwm);
+
+       return 0;
+}
+
+static int __devinit pxa27x_pwm_probe(struct platform_device *pdev)
+{
+       struct pwm_device *pwm;
+
+       pwm = pwm_probe(pdev, pdev->id, NULL);
+       if (IS_ERR(pwm))
+               return PTR_ERR(pwm);
+
+       pwm = pwm_probe(pdev, pdev->id + 2, pwm);
+       if (IS_ERR(pwm))
+               return PTR_ERR(pwm);
+
+       return 0;
+}
+
+static int __devexit pwm_remove(struct platform_device *pdev)
+{
+       struct pwm_device *pwm;
+       struct resource *r;
+
+       pwm = platform_get_drvdata(pdev);
+       if (pwm == NULL)
+               return -ENODEV;
+
+       mutex_lock(&pwm_lock);
+       list_del(&pwm->node);
+       mutex_unlock(&pwm_lock);
+
+       iounmap(pwm->mmio_base);
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       release_mem_region(r->start, r->end - r->start + 1);
+
+       clk_put(pwm->clk);
+       kfree(pwm);
+       return 0;
+}
+
+static struct platform_driver pxa25x_pwm_driver = {
+       .driver         = {
+               .name   = "pxa25x-pwm",
+       },
+       .probe          = pxa25x_pwm_probe,
+       .remove         = __devexit_p(pwm_remove),
+};
+
+static struct platform_driver pxa27x_pwm_driver = {
+       .driver         = {
+               .name   = "pxa27x-pwm",
+       },
+       .probe          = pxa27x_pwm_probe,
+       .remove         = __devexit_p(pwm_remove),
+};
+
+static int __init pwm_init(void)
+{
+       int ret = 0;
+
+       ret = platform_driver_register(&pxa25x_pwm_driver);
+       if (ret) {
+               printk(KERN_ERR "failed to register pxa25x_pwm_driver\n");
+               return ret;
+       }
+
+       ret = platform_driver_register(&pxa27x_pwm_driver);
+       if (ret) {
+               printk(KERN_ERR "failed to register pxa27x_pwm_driver\n");
+               return ret;
+       }
+
+       return ret;
+}
+arch_initcall(pwm_init);
+
+static void __exit pwm_exit(void)
+{
+       platform_driver_unregister(&pxa25x_pwm_driver);
+       platform_driver_unregister(&pxa27x_pwm_driver);
+}
+module_exit(pwm_exit);
+
+MODULE_LICENSE("GPL v2");
index e5b417d..4cd50e3 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/hardware.h>
 #include <asm/arch/irqs.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/mfp-pxa25x.h>
 #include <asm/arch/pm.h>
 #include <asm/arch/dma.h>
@@ -117,29 +118,35 @@ static struct clk pxa25x_hwuart_clk =
        INIT_CKEN("UARTCLK", HWUART, 14745600, 1, &pxa_device_hwuart.dev)
 ;
 
+/*
+ * PXA 2xx clock declarations. Order is important (see aliases below)
+ * Please be careful not to disrupt the ordering.
+ */
 static struct clk pxa25x_clks[] = {
        INIT_CK("LCDCLK", LCD, &clk_pxa25x_lcd_ops, &pxa_device_fb.dev),
        INIT_CKEN("UARTCLK", FFUART, 14745600, 1, &pxa_device_ffuart.dev),
        INIT_CKEN("UARTCLK", BTUART, 14745600, 1, &pxa_device_btuart.dev),
        INIT_CKEN("UARTCLK", STUART, 14745600, 1, NULL),
-       INIT_CKEN("UDCCLK", USB, 47923000, 5, &pxa_device_udc.dev),
+       INIT_CKEN("UDCCLK", USB, 47923000, 5, &pxa25x_device_udc.dev),
        INIT_CKEN("MMCCLK", MMC, 19169000, 0, &pxa_device_mci.dev),
        INIT_CKEN("I2CCLK", I2C, 31949000, 0, &pxa_device_i2c.dev),
 
        INIT_CKEN("SSPCLK",  SSP, 3686400, 0, &pxa25x_device_ssp.dev),
        INIT_CKEN("SSPCLK", NSSP, 3686400, 0, &pxa25x_device_nssp.dev),
        INIT_CKEN("SSPCLK", ASSP, 3686400, 0, &pxa25x_device_assp.dev),
+       INIT_CKEN("PWMCLK", PWM0, 3686400, 0, &pxa25x_device_pwm0.dev),
+       INIT_CKEN("PWMCLK", PWM1, 3686400, 0, &pxa25x_device_pwm1.dev),
 
        INIT_CKEN("AC97CLK",     AC97,     24576000, 0, NULL),
 
        /*
-       INIT_CKEN("PWMCLK",  PWM0, 3686400,  0, NULL),
-       INIT_CKEN("PWMCLK",  PWM0, 3686400,  0, NULL),
        INIT_CKEN("I2SCLK",  I2S,  14745600, 0, NULL),
        */
        INIT_CKEN("FICPCLK", FICP, 47923000, 0, NULL),
 };
 
+static struct clk gpio7_clk = INIT_CKOTHER("GPIO7_CK", &pxa25x_clks[4], NULL);
+
 #ifdef CONFIG_PM
 
 #define SAVE(x)                sleep_save[SLEEP_SAVE_##x] = x
@@ -260,7 +267,7 @@ void __init pxa25x_init_irq(void)
 }
 
 static struct platform_device *pxa25x_devices[] __initdata = {
-       &pxa_device_udc,
+       &pxa25x_device_udc,
        &pxa_device_ffuart,
        &pxa_device_btuart,
        &pxa_device_stuart,
@@ -269,6 +276,8 @@ static struct platform_device *pxa25x_devices[] __initdata = {
        &pxa25x_device_ssp,
        &pxa25x_device_nssp,
        &pxa25x_device_assp,
+       &pxa25x_device_pwm0,
+       &pxa25x_device_pwm1,
 };
 
 static struct sys_device pxa25x_sysdev[] = {
@@ -311,6 +320,8 @@ static int __init pxa25x_init(void)
        if (cpu_is_pxa25x())
                ret = platform_device_register(&pxa_device_hwuart);
 
+       clks_register(&gpio7_clk, 1);
+
        return ret;
 }
 
index 7e94583..d5d14ea 100644 (file)
@@ -146,7 +146,7 @@ static struct clk pxa27x_clks[] = {
 
        INIT_CKEN("I2SCLK",  I2S,  14682000, 0, &pxa_device_i2s.dev),
        INIT_CKEN("I2CCLK",  I2C,  32842000, 0, &pxa_device_i2c.dev),
-       INIT_CKEN("UDCCLK",  USB,  48000000, 5, &pxa_device_udc.dev),
+       INIT_CKEN("UDCCLK",  USB,  48000000, 5, &pxa27x_device_udc.dev),
        INIT_CKEN("MMCCLK",  MMC,  19500000, 0, &pxa_device_mci.dev),
        INIT_CKEN("FICPCLK", FICP, 48000000, 0, &pxa_device_ficp.dev),
 
@@ -157,12 +157,13 @@ static struct clk pxa27x_clks[] = {
        INIT_CKEN("SSPCLK", SSP1, 13000000, 0, &pxa27x_device_ssp1.dev),
        INIT_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
        INIT_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
+       INIT_CKEN("PWMCLK", PWM0, 13000000, 0, &pxa27x_device_pwm0.dev),
+       INIT_CKEN("PWMCLK", PWM1, 13000000, 0, &pxa27x_device_pwm1.dev),
 
        INIT_CKEN("AC97CLK",     AC97,     24576000, 0, NULL),
        INIT_CKEN("AC97CONFCLK", AC97CONF, 24576000, 0, NULL),
 
        /*
-       INIT_CKEN("PWMCLK",  PWM0, 13000000, 0, NULL),
        INIT_CKEN("MSLCLK",  MSL,  48000000, 0, NULL),
        INIT_CKEN("USIMCLK", USIM, 48000000, 0, NULL),
        INIT_CKEN("MSTKCLK", MEMSTK, 19500000, 0, NULL),
@@ -349,11 +350,14 @@ struct platform_device pxa27x_device_i2c_power = {
 
 void __init pxa_set_i2c_power_info(struct i2c_pxa_platform_data *info)
 {
+       local_irq_disable();
+       PCFR |= PCFR_PI2CEN;
+       local_irq_enable();
        pxa27x_device_i2c_power.dev.platform_data = info;
 }
 
 static struct platform_device *devices[] __initdata = {
-       &pxa_device_udc,
+       &pxa27x_device_udc,
        &pxa_device_ffuart,
        &pxa_device_btuart,
        &pxa_device_stuart,
@@ -363,6 +367,8 @@ static struct platform_device *devices[] __initdata = {
        &pxa27x_device_ssp1,
        &pxa27x_device_ssp2,
        &pxa27x_device_ssp3,
+       &pxa27x_device_pwm0,
+       &pxa27x_device_pwm1,
 };
 
 static struct sys_device pxa27x_sysdev[] = {
diff --git a/arch/arm/mach-pxa/pxa2xx.c b/arch/arm/mach-pxa/pxa2xx.c
new file mode 100644 (file)
index 0000000..d4f6415
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * linux/arch/arm/mach-pxa/pxa2xx.c
+ *
+ * code specific to pxa2xx
+ *
+ * Copyright (C) 2008 Dmitry Baryshkov
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+
+#include <asm/arch/mfp-pxa2xx.h>
+#include <asm/arch/mfp-pxa25x.h>
+#include <asm/arch/irda.h>
+
+static unsigned long pxa2xx_mfp_fir[] = {
+       GPIO46_FICP_RXD,
+       GPIO47_FICP_TXD,
+};
+
+static unsigned long pxa2xx_mfp_sir[] = {
+       GPIO46_STUART_RXD,
+       GPIO47_STUART_TXD,
+};
+
+static unsigned long pxa2xx_mfp_off[] = {
+       GPIO46_GPIO | MFP_LPM_DRIVE_LOW,
+       GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
+};
+
+void pxa2xx_transceiver_mode(struct device *dev, int mode)
+{
+       if (mode & IR_OFF) {
+               pxa2xx_mfp_config(pxa2xx_mfp_off, ARRAY_SIZE(pxa2xx_mfp_off));
+       } else if (mode & IR_SIRMODE) {
+               pxa2xx_mfp_config(pxa2xx_mfp_sir, ARRAY_SIZE(pxa2xx_mfp_sir));
+       } else if (mode & IR_FIRMODE) {
+               pxa2xx_mfp_config(pxa2xx_mfp_fir, ARRAY_SIZE(pxa2xx_mfp_fir));
+       } else
+               BUG();
+}
index 644550b..15685d2 100644 (file)
@@ -231,7 +231,7 @@ static struct clk pxa3xx_clks[] = {
        PXA3xx_CKEN("UARTCLK", STUART, 14857000, 1, NULL),
 
        PXA3xx_CKEN("I2CCLK", I2C,  32842000, 0, &pxa_device_i2c.dev),
-       PXA3xx_CKEN("UDCCLK", UDC,  48000000, 5, &pxa_device_udc.dev),
+       PXA3xx_CKEN("UDCCLK", UDC,  48000000, 5, &pxa27x_device_udc.dev),
        PXA3xx_CKEN("USBCLK", USBH, 48000000, 0, &pxa27x_device_ohci.dev),
        PXA3xx_CKEN("KBDCLK", KEYPAD,  32768, 0, &pxa27x_device_keypad.dev),
 
@@ -239,6 +239,8 @@ static struct clk pxa3xx_clks[] = {
        PXA3xx_CKEN("SSPCLK", SSP2, 13000000, 0, &pxa27x_device_ssp2.dev),
        PXA3xx_CKEN("SSPCLK", SSP3, 13000000, 0, &pxa27x_device_ssp3.dev),
        PXA3xx_CKEN("SSPCLK", SSP4, 13000000, 0, &pxa3xx_device_ssp4.dev),
+       PXA3xx_CKEN("PWMCLK", PWM0, 13000000, 0, &pxa27x_device_pwm0.dev),
+       PXA3xx_CKEN("PWMCLK", PWM1, 13000000, 0, &pxa27x_device_pwm1.dev),
 
        PXA3xx_CKEN("MMCCLK", MMC1, 19500000, 0, &pxa_device_mci.dev),
        PXA3xx_CKEN("MMCCLK", MMC2, 19500000, 0, &pxa3xx_device_mci2.dev),
@@ -520,7 +522,7 @@ void __init pxa3xx_init_irq(void)
  */
 
 static struct platform_device *devices[] __initdata = {
-       &pxa_device_udc,
+/*     &pxa_device_udc,        The UDC driver is PXA25x only */
        &pxa_device_ffuart,
        &pxa_device_btuart,
        &pxa_device_stuart,
@@ -530,6 +532,8 @@ static struct platform_device *devices[] __initdata = {
        &pxa27x_device_ssp2,
        &pxa27x_device_ssp3,
        &pxa3xx_device_ssp4,
+       &pxa27x_device_pwm0,
+       &pxa27x_device_pwm1,
 };
 
 static struct sys_device pxa3xx_sysdev[] = {
index 23f050f..3603540 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/arch/sharpsl.h>
 #include <asm/arch/spitz.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include "sharpsl.h"
 
@@ -207,7 +208,9 @@ struct sharpsl_charger_machinfo spitz_pm_machinfo = {
        .read_devdata     = spitzpm_read_devdata,
        .charger_wakeup   = spitz_charger_wakeup,
        .should_wakeup    = spitz_should_wakeup,
+#ifdef CONFIG_BACKLIGHT_CORGI
         .backlight_limit  = corgibl_limit_intensity,
+#endif
        .charge_on_volt   = SHARPSL_CHARGE_ON_VOLT,
        .charge_on_temp   = SHARPSL_CHARGE_ON_TEMP,
        .charge_acin_high = SHARPSL_CHARGE_ON_ACIN_HIGH,
@@ -229,6 +232,10 @@ static int __devinit spitzpm_init(void)
 {
        int ret;
 
+       if (!machine_is_spitz() && !machine_is_akita()
+                       && !machine_is_borzoi())
+               return -ENODEV;
+
        spitzpm_device = platform_device_alloc("sharpsl-pm", -1);
        if (!spitzpm_device)
                return -ENOMEM;
index 167412e..40bb70e 100644 (file)
@@ -14,6 +14,7 @@
 #include <asm/hardware.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 
                .text
 
@@ -35,20 +36,20 @@ ENTRY(pxa_cpu_standby)
 
 #ifdef CONFIG_PXA3xx
 
-#define MDCNFG         0x0000
-#define MDCNFG_DMCEN   (1 << 30)
-#define DDR_HCAL       0x0060
-#define DDR_HCAL_HCRNG 0x1f
-#define DDR_HCAL_HCPROG        (1 << 28)
-#define DDR_HCAL_HCEN  (1 << 31)
-#define DMCIER         0x0070
-#define DMCIER_EDLP    (1 << 29)
-#define DMCISR         0x0078
-#define RCOMP          0x0100
-#define RCOMP_SWEVAL   (1 << 31)
+#define PXA3_MDCNFG            0x0000
+#define PXA3_MDCNFG_DMCEN      (1 << 30)
+#define PXA3_DDR_HCAL          0x0060
+#define PXA3_DDR_HCAL_HCRNG    0x1f
+#define PXA3_DDR_HCAL_HCPROG   (1 << 28)
+#define PXA3_DDR_HCAL_HCEN     (1 << 31)
+#define PXA3_DMCIER            0x0070
+#define PXA3_DMCIER_EDLP       (1 << 29)
+#define PXA3_DMCISR            0x0078
+#define PXA3_RCOMP             0x0100
+#define PXA3_RCOMP_SWEVAL      (1 << 31)
 
 ENTRY(pm_enter_standby_start)
-       mov     r1, #0xf6000000         @ DMEMC_REG_BASE (MDCNFG)
+       mov     r1, #0xf6000000                 @ DMEMC_REG_BASE (PXA3_MDCNFG)
        add     r1, r1, #0x00100000
 
        /*
@@ -59,54 +60,54 @@ ENTRY(pm_enter_standby_start)
         * This also means that only the dynamic memory controller
         * can be reliably accessed in the code following standby.
         */
-       ldr     r2, [r1]                @ Dummy read MDCNFG
+       ldr     r2, [r1]                        @ Dummy read PXA3_MDCNFG
 
        mcr     p14, 0, r0, c7, c0, 0
        .rept   8
        nop
        .endr
 
-       ldr     r0, [r1, #DDR_HCAL]     @ Clear (and wait for) HCEN
-       bic     r0, r0, #DDR_HCAL_HCEN
-       str     r0, [r1, #DDR_HCAL]
-1:     ldr     r0, [r1, #DDR_HCAL]
-       tst     r0, #DDR_HCAL_HCEN
+       ldr     r0, [r1, #PXA3_DDR_HCAL]        @ Clear (and wait for) HCEN
+       bic     r0, r0, #PXA3_DDR_HCAL_HCEN
+       str     r0, [r1, #PXA3_DDR_HCAL]
+1:     ldr     r0, [r1, #PXA3_DDR_HCAL]
+       tst     r0, #PXA3_DDR_HCAL_HCEN
        bne     1b
 
-       ldr     r0, [r1, #RCOMP]        @ Initiate RCOMP
-       orr     r0, r0, #RCOMP_SWEVAL
-       str     r0, [r1, #RCOMP]
+       ldr     r0, [r1, #PXA3_RCOMP]           @ Initiate RCOMP
+       orr     r0, r0, #PXA3_RCOMP_SWEVAL
+       str     r0, [r1, #PXA3_RCOMP]
 
-       mov     r0, #~0                 @ Clear interrupts
-       str     r0, [r1, #DMCISR]
+       mov     r0, #~0                         @ Clear interrupts
+       str     r0, [r1, #PXA3_DMCISR]
 
-       ldr     r0, [r1, #DMCIER]       @ set DMIER[EDLP]
-       orr     r0, r0, #DMCIER_EDLP
-       str     r0, [r1, #DMCIER]
+       ldr     r0, [r1, #PXA3_DMCIER]          @ set DMIER[EDLP]
+       orr     r0, r0, #PXA3_DMCIER_EDLP
+       str     r0, [r1, #PXA3_DMCIER]
 
-       ldr     r0, [r1, #DDR_HCAL]     @ clear HCRNG, set HCPROG, HCEN
-       bic     r0, r0, #DDR_HCAL_HCRNG
-       orr     r0, r0, #DDR_HCAL_HCEN | DDR_HCAL_HCPROG
-       str     r0, [r1, #DDR_HCAL]
+       ldr     r0, [r1, #PXA3_DDR_HCAL]        @ clear HCRNG, set HCPROG, HCEN
+       bic     r0, r0, #PXA3_DDR_HCAL_HCRNG
+       orr     r0, r0, #PXA3_DDR_HCAL_HCEN | PXA3_DDR_HCAL_HCPROG
+       str     r0, [r1, #PXA3_DDR_HCAL]
 
-1:     ldr     r0, [r1, #DMCISR]
-       tst     r0, #DMCIER_EDLP
+1:     ldr     r0, [r1, #PXA3_DMCISR]
+       tst     r0, #PXA3_DMCIER_EDLP
        beq     1b
 
-       ldr     r0, [r1, #MDCNFG]       @ set MDCNFG[DMCEN]
-       orr     r0, r0, #MDCNFG_DMCEN
-       str     r0, [r1, #MDCNFG]
-1:     ldr     r0, [r1, #MDCNFG]
-       tst     r0, #MDCNFG_DMCEN
+       ldr     r0, [r1, #PXA3_MDCNFG]          @ set PXA3_MDCNFG[DMCEN]
+       orr     r0, r0, #PXA3_MDCNFG_DMCEN
+       str     r0, [r1, #PXA3_MDCNFG]
+1:     ldr     r0, [r1, #PXA3_MDCNFG]
+       tst     r0, #PXA3_MDCNFG_DMCEN
        beq     1b
 
-       ldr     r0, [r1, #DDR_HCAL]     @ set DDR_HCAL[HCRNG]
+       ldr     r0, [r1, #PXA3_DDR_HCAL]        @ set PXA3_DDR_HCAL[HCRNG]
        orr     r0, r0, #2 @ HCRNG
-       str     r0, [r1, #DDR_HCAL]
+       str     r0, [r1, #PXA3_DDR_HCAL]
 
-       ldr     r0, [r1, #DMCIER]       @ Clear the interrupt
+       ldr     r0, [r1, #PXA3_DMCIER]          @ Clear the interrupt
        bic     r0, r0, #0x20000000
-       str     r0, [r1, #DMCIER]
+       str     r0, [r1, #PXA3_DMCIER]
 
        mov     pc, lr
 ENTRY(pm_enter_standby_end)
index 931885d..61e2440 100644 (file)
@@ -41,6 +41,7 @@
 #include <asm/mach/flash.h>
 
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
 #include <asm/arch/trizeps4.h>
 #include <asm/arch/audio.h>
@@ -175,19 +176,10 @@ static struct platform_device uart_devices = {
        .resource       = NULL,
 };
 
-/********************************************************************************************
- * PXA270 ac97 sound codec
- ********************************************************************************************/
-static struct platform_device ac97_audio_device = {
-       .name           = "pxa2xx-ac97",
-       .id             = -1,
-};
-
 static struct platform_device * trizeps4_devices[] __initdata = {
        &flash_device,
        &uart_devices,
        &dm9000_device,
-       &ac97_audio_device,
 };
 
 #ifdef CONFIG_MACH_TRIZEPS4_CONXS
@@ -438,6 +430,7 @@ static void __init trizeps4_init(void)
        pxa_set_mci_info(&trizeps4_mci_platform_data);
        pxa_set_ficp_info(&trizeps4_ficp_platform_data);
        pxa_set_ohci_info(&trizeps4_ohci_platform_data);
+       pxa_set_ac97_info(NULL);
 }
 
 static void __init trizeps4_map_io(void)
@@ -487,6 +480,7 @@ static void __init trizeps4_map_io(void)
        ConXS_BCR = trizeps_conxs_bcr;
 #endif
 
+#warning FIXME - accessing PM registers directly is deprecated
        PWER  = 0x00000002;
        PFER  = 0x00000000;
        PRER  = 0x00000002;
index 4a00280..66b446c 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/pwm_backlight.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/hardware.h>
+#include <asm/arch/audio.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/pxafb.h>
 #include <asm/arch/zylonite.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/pxa27x_keypad.h>
 
+#include "devices.h"
 #include "generic.h"
 
 #define MAX_SLOTS      3
 struct platform_mmc_slot zylonite_mmc_slot[MAX_SLOTS];
 
-int gpio_backlight;
 int gpio_eth_irq;
 
 int wm9713_irq;
@@ -62,10 +64,20 @@ static struct platform_device smc91x_device = {
 };
 
 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
-static void zylonite_backlight_power(int on)
-{
-       gpio_set_value(gpio_backlight, on);
-}
+static struct platform_pwm_backlight_data zylonite_backlight_data = {
+       .pwm_id         = 3,
+       .max_brightness = 100,
+       .dft_brightness = 100,
+       .pwm_period_ns  = 10000,
+};
+
+static struct platform_device zylonite_backlight_device = {
+       .name           = "pwm-backlight",
+       .dev            = {
+               .parent = &pxa27x_device_pwm1.dev,
+               .platform_data  = &zylonite_backlight_data,
+       },
+};
 
 static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
        .pixclock               = 110000,
@@ -98,7 +110,6 @@ static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
 static struct pxafb_mach_info zylonite_toshiba_lcd_info = {
        .num_modes              = 1,
        .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
-       .pxafb_backlight_power  = zylonite_backlight_power,
 };
 
 static struct pxafb_mode_info sharp_ls037_modes[] = {
@@ -134,13 +145,11 @@ static struct pxafb_mach_info zylonite_sharp_lcd_info = {
        .modes                  = sharp_ls037_modes,
        .num_modes              = 2,
        .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
-       .pxafb_backlight_power  = zylonite_backlight_power,
 };
 
 static void __init zylonite_init_lcd(void)
 {
-       /* backlight GPIO: output, default on */
-       gpio_direction_output(gpio_backlight, 1);
+       platform_device_register(&zylonite_backlight_device);
 
        if (lcd_id & 0x20) {
                set_pxa_fb_info(&zylonite_sharp_lcd_info);
@@ -329,6 +338,7 @@ static void __init zylonite_init(void)
        smc91x_resources[1].end   = gpio_to_irq(gpio_eth_irq);
        platform_device_register(&smc91x_device);
 
+       pxa_set_ac97_info(NULL);
        zylonite_init_lcd();
        zylonite_init_mmc();
        zylonite_init_keypad();
index 324fb9d..6f7ae97 100644 (file)
@@ -50,6 +50,7 @@ static mfp_cfg_t common_mfp_cfg[] __initdata = {
        GPIO75_LCD_BIAS,
        GPIO76_LCD_VSYNC,
        GPIO127_LCD_CS_N,
+       GPIO20_PWM3_OUT,        /* backlight */
 
        /* BTUART */
        GPIO111_UART2_RTS,
@@ -200,9 +201,6 @@ void __init zylonite_pxa300_init(void)
                /* detect LCD panel */
                zylonite_detect_lcd_panel();
 
-               /* GPIO pin assignment */
-               gpio_backlight = mfp_to_gpio(MFP_PIN_GPIO20);
-
                /* MMC card detect & write protect for controller 0 */
                zylonite_mmc_slot[0].gpio_cd  = EXT_GPIO(0);
                zylonite_mmc_slot[0].gpio_wp  = EXT_GPIO(2);
index 193d079..2b4fc34 100644 (file)
@@ -49,6 +49,7 @@ static mfp_cfg_t mfp_cfg[] __initdata = {
        GPIO15_2_LCD_LCLK,
        GPIO16_2_LCD_PCLK,
        GPIO17_2_LCD_BIAS,
+       GPIO14_PWM3_OUT,        /* backlight */
 
        /* FFUART */
        GPIO41_UART1_RXD | MFP_LPM_EDGE_FALL,
@@ -187,7 +188,6 @@ void __init zylonite_pxa320_init(void)
                zylonite_detect_lcd_panel();
 
                /* GPIO pin assignment */
-               gpio_backlight  = mfp_to_gpio(MFP_PIN_GPIO14);
                gpio_eth_irq    = mfp_to_gpio(MFP_PIN_GPIO9);
 
                /* MMC card detect & write protect for controller 0 */
index cd3dc08..99fdc73 100644 (file)
@@ -37,6 +37,17 @@ config S3C2410_CLOCK
        help
          Clock code for the S3C2410, and similar processors
 
+config SIMTEC_NOR
+       bool
+       help
+         Internal node to specify machine has simtec NOR mapping
+
+config MACH_BAST_IDE
+       bool
+       select HAVE_PATA_PLATFORM
+       help
+         Internal node for machines with an BAST style IDE
+         interface
 
 menu "S3C2410 Machines"
 
@@ -61,15 +72,18 @@ config PM_H1940
          Internal node for H1940 and related PM
 
 config MACH_N30
-       bool "Acer N30"
+       bool "Acer N30 family"
        select CPU_S3C2410
        help
-         Say Y here if you are using the Acer N30
+         Say Y here if you want suppt for the Acer N30, Acer N35,
+         Navman PiN570, Yakumo AlphaX or Airis NC05 PDAs.
 
 config ARCH_BAST
        bool "Simtec Electronics BAST (EB2410ITX)"
        select CPU_S3C2410
        select PM_SIMTEC if PM
+       select SIMTEC_NOR
+       select MACH_BAST_IDE
        select ISA
        help
          Say Y here if you are using the Simtec Electronics EB2410ITX
@@ -107,6 +121,8 @@ config MACH_TCT_HAMMER
 config MACH_VR1000
        bool "Thorcom VR1000"
        select PM_SIMTEC if PM
+       select SIMTEC_NOR
+       select MACH_BAST_IDE
        select CPU_S3C2410
        help
          Say Y here if you are using the Thorcom VR1000 board.
@@ -118,4 +134,3 @@ config MACH_QT2410
           Say Y here if you are using the Armzone QT2410
 
 endmenu
-
index cabc13c..00f31f8 100644 (file)
@@ -30,3 +30,11 @@ obj-$(CONFIG_BAST_PC104_IRQ) += bast-irq.o
 obj-$(CONFIG_MACH_TCT_HAMMER)  += mach-tct_hammer.o
 obj-$(CONFIG_MACH_VR1000)      += mach-vr1000.o usb-simtec.o
 obj-$(CONFIG_MACH_QT2410)      += mach-qt2410.o
+
+# Common bits of machine support
+
+obj-$(CONFIG_SIMTEC_NOR)       += nor-simtec.o
+
+# machine additions
+
+obj-$(CONFIG_MACH_BAST_IDE)    += bast-ide.o
diff --git a/arch/arm/mach-s3c2410/bast-ide.c b/arch/arm/mach-s3c2410/bast-ide.c
new file mode 100644 (file)
index 0000000..df95fe3
--- /dev/null
@@ -0,0 +1,112 @@
+/* linux/arch/arm/mach-s3c2410/bast-ide.c
+ *
+ * Copyright 2007 Simtec Electronics
+ *     http://www.simtec.co.uk/products/EB2410ITX/
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+
+#include <linux/platform_device.h>
+#include <linux/ata_platform.h>
+
+#include <asm/mach-types.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/map.h>
+#include <asm/arch/bast-map.h>
+#include <asm/arch/bast-irq.h>
+
+/* IDE ports */
+
+static struct pata_platform_info bast_ide_platdata = {
+       .ioport_shift   = 5,
+};
+
+#define IDE_CS S3C2410_CS5
+
+static struct resource bast_ide0_resource[] = {
+       [0]     = {
+               .start  = IDE_CS + BAST_PA_IDEPRI,
+               .end    = IDE_CS + BAST_PA_IDEPRI + (8 * 0x20) - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1]     = {
+               .start  = IDE_CS + BAST_PA_IDEPRIAUX + (6 * 0x20) ,
+               .end    = IDE_CS + BAST_PA_IDEPRIAUX + (7 * 0x20) - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [2]     = {
+               .start  = IRQ_IDE0,
+               .end    = IRQ_IDE0,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bast_device_ide0 = {
+       .name           = "pata_platform",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(bast_ide0_resource),
+       .resource       = bast_ide0_resource,
+       .dev            = {
+               .platform_data = &bast_ide_platdata,
+               .coherent_dma_mask = ~0,
+       }
+
+};
+
+static struct resource bast_ide1_resource[] = {
+       [0]     = {
+               .start  = IDE_CS + BAST_PA_IDESEC,
+               .end    = IDE_CS + BAST_PA_IDESEC + (8 * 0x20) - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1]     = {
+               .start  = IDE_CS + BAST_PA_IDESECAUX + (6 * 0x20),
+               .end    = IDE_CS + BAST_PA_IDESECAUX + (7 * 0x20) - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [2]     = {
+               .start  = IRQ_IDE1,
+               .end    = IRQ_IDE1,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device bast_device_ide1 = {
+       .name           = "pata_platform",
+       .id             = 1,
+       .num_resources  = ARRAY_SIZE(bast_ide1_resource),
+       .resource       = bast_ide1_resource,
+       .dev            = {
+               .platform_data = &bast_ide_platdata,
+               .coherent_dma_mask = ~0,
+       }
+};
+
+static struct platform_device *bast_ide_devices[] __initdata = {
+       &bast_device_ide0,
+       &bast_device_ide1,
+};
+
+static __init int bast_ide_init(void)
+{
+       if (machine_is_bast() || machine_is_vr1000())
+               return platform_add_devices(bast_ide_devices,
+                                           ARRAY_SIZE(bast_ide_devices));
+
+       return 0;
+}
+
+fs_initcall(bast_ide_init);
index 27f63d5..965f271 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/mach-s3c2410/mach-bast.c
  *
- * Copyright (c) 2003-2005 Simtec Electronics
+ * Copyright (c) 2003-2005,2008 Simtec Electronics
  *   Ben Dooks <ben@simtec.co.uk>
  *
  * http://www.simtec.co.uk/products/EB2410ITX/
@@ -20,6 +20,8 @@
 #include <linux/serial_core.h>
 #include <linux/platform_device.h>
 #include <linux/dm9000.h>
+#include <linux/ata_platform.h>
+#include <linux/i2c.h>
 
 #include <net/ax88796.h>
 
@@ -56,7 +58,9 @@
 #include <asm/plat-s3c24xx/clock.h>
 #include <asm/plat-s3c24xx/devs.h>
 #include <asm/plat-s3c24xx/cpu.h>
+
 #include "usb-simtec.h"
+#include "nor-simtec.h"
 
 #define COPYRIGHT ", (c) 2004-2005 Simtec Electronics"
 
@@ -134,37 +138,21 @@ static struct map_desc bast_iodesc[] __initdata = {
   { VA_C2(BAST_VA_ISAIO),   PA_CS2(BAST_PA_ISAIO),    SZ_16M, MT_DEVICE },
   { VA_C2(BAST_VA_ISAMEM),  PA_CS2(BAST_PA_ISAMEM),   SZ_16M, MT_DEVICE },
   { VA_C2(BAST_VA_SUPERIO), PA_CS2(BAST_PA_SUPERIO),  SZ_1M,  MT_DEVICE },
-  { VA_C2(BAST_VA_IDEPRI),  PA_CS3(BAST_PA_IDEPRI),   SZ_1M,  MT_DEVICE },
-  { VA_C2(BAST_VA_IDESEC),  PA_CS3(BAST_PA_IDESEC),   SZ_1M,  MT_DEVICE },
-  { VA_C2(BAST_VA_IDEPRIAUX), PA_CS3(BAST_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C2(BAST_VA_IDESECAUX), PA_CS3(BAST_PA_IDESECAUX), SZ_1M, MT_DEVICE },
 
   /* slow, word */
   { VA_C3(BAST_VA_ISAIO),   PA_CS3(BAST_PA_ISAIO),    SZ_16M, MT_DEVICE },
   { VA_C3(BAST_VA_ISAMEM),  PA_CS3(BAST_PA_ISAMEM),   SZ_16M, MT_DEVICE },
   { VA_C3(BAST_VA_SUPERIO), PA_CS3(BAST_PA_SUPERIO),  SZ_1M,  MT_DEVICE },
-  { VA_C3(BAST_VA_IDEPRI),  PA_CS3(BAST_PA_IDEPRI),   SZ_1M,  MT_DEVICE },
-  { VA_C3(BAST_VA_IDESEC),  PA_CS3(BAST_PA_IDESEC),   SZ_1M,  MT_DEVICE },
-  { VA_C3(BAST_VA_IDEPRIAUX), PA_CS3(BAST_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C3(BAST_VA_IDESECAUX), PA_CS3(BAST_PA_IDESECAUX), SZ_1M, MT_DEVICE },
 
   /* fast, byte */
   { VA_C4(BAST_VA_ISAIO),   PA_CS4(BAST_PA_ISAIO),    SZ_16M, MT_DEVICE },
   { VA_C4(BAST_VA_ISAMEM),  PA_CS4(BAST_PA_ISAMEM),   SZ_16M, MT_DEVICE },
   { VA_C4(BAST_VA_SUPERIO), PA_CS4(BAST_PA_SUPERIO),  SZ_1M,  MT_DEVICE },
-  { VA_C4(BAST_VA_IDEPRI),  PA_CS5(BAST_PA_IDEPRI),   SZ_1M,  MT_DEVICE },
-  { VA_C4(BAST_VA_IDESEC),  PA_CS5(BAST_PA_IDESEC),   SZ_1M,  MT_DEVICE },
-  { VA_C4(BAST_VA_IDEPRIAUX), PA_CS5(BAST_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C4(BAST_VA_IDESECAUX), PA_CS5(BAST_PA_IDESECAUX), SZ_1M, MT_DEVICE },
 
   /* fast, word */
   { VA_C5(BAST_VA_ISAIO),   PA_CS5(BAST_PA_ISAIO),    SZ_16M, MT_DEVICE },
   { VA_C5(BAST_VA_ISAMEM),  PA_CS5(BAST_PA_ISAMEM),   SZ_16M, MT_DEVICE },
   { VA_C5(BAST_VA_SUPERIO), PA_CS5(BAST_PA_SUPERIO),  SZ_1M,  MT_DEVICE },
-  { VA_C5(BAST_VA_IDEPRI),  PA_CS5(BAST_PA_IDEPRI),   SZ_1M,  MT_DEVICE },
-  { VA_C5(BAST_VA_IDESEC),  PA_CS5(BAST_PA_IDESEC),   SZ_1M,  MT_DEVICE },
-  { VA_C5(BAST_VA_IDEPRIAUX), PA_CS5(BAST_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C5(BAST_VA_IDESECAUX), PA_CS5(BAST_PA_IDESECAUX), SZ_1M, MT_DEVICE },
 };
 
 #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
@@ -218,23 +206,6 @@ static struct s3c2410_uartcfg bast_uartcfgs[] __initdata = {
        }
 };
 
-/* NOR Flash on BAST board */
-
-static struct resource bast_nor_resource[] = {
-       [0] = {
-               .start = S3C2410_CS1 + 0x4000000,
-               .end   = S3C2410_CS1 + 0x4000000 + (32*1024*1024) - 1,
-               .flags = IORESOURCE_MEM,
-       }
-};
-
-static struct platform_device bast_device_nor = {
-       .name           = "bast-nor",
-       .id             = -1,
-       .num_resources  = ARRAY_SIZE(bast_nor_resource),
-       .resource       = bast_nor_resource,
-};
-
 /* NAND Flash on BAST board */
 
 #ifdef CONFIG_PM
@@ -374,7 +345,7 @@ static struct resource bast_dm9k_resource[] = {
        [2] = {
                .start = IRQ_DM9000,
                .end   = IRQ_DM9000,
-               .flags = IORESOURCE_IRQ | IRQF_TRIGGER_HIGH,
+               .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
        }
 
 };
@@ -564,6 +535,18 @@ static struct s3c2410fb_mach_info __initdata bast_fb_info = {
        .default_display = 1,
 };
 
+/* I2C devices fitted. */
+
+static struct i2c_board_info bast_i2c_devs[] __initdata = {
+       {
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       }, {
+               I2C_BOARD_INFO("simtec-pmu", 0x6b),
+       }, {
+               I2C_BOARD_INFO("ch7013", 0x75),
+       },
+};
+
 /* Standard BAST devices */
 
 static struct platform_device *bast_devices[] __initdata = {
@@ -573,7 +556,6 @@ static struct platform_device *bast_devices[] __initdata = {
        &s3c_device_i2c,
        &s3c_device_rtc,
        &s3c_device_nand,
-       &bast_device_nor,
        &bast_device_dm9k,
        &bast_device_asix,
        &bast_device_axpp,
@@ -622,6 +604,11 @@ static void __init bast_init(void)
 
        s3c24xx_fb_set_platdata(&bast_fb_info);
        platform_add_devices(bast_devices, ARRAY_SIZE(bast_devices));
+
+       i2c_register_board_info(0, bast_i2c_devs,
+                               ARRAY_SIZE(bast_i2c_devs));
+
+       nor_simtec_init();
 }
 
 MACHINE_START(BAST, "Simtec-BAST")
index 621f548..43c2e91 100644 (file)
@@ -1,9 +1,10 @@
-/* linux/arch/arm/mach-s3c2410/mach-n30.c
+/* Machine specific code for the Acer n30, Acer N35, Navman PiN 570,
+ * Yakumo AlphaX and Airis NC05 PDAs.
  *
  * Copyright (c) 2003-2005 Simtec Electronics
  *     Ben Dooks <ben@simtec.co.uk>
  *
- * Copyright (c) 2005 Christer Weinigel <christer@weinigel.se>
+ * Copyright (c) 2005-2008 Christer Weinigel <christer@weinigel.se>
  *
  * There is a wiki with more information about the n30 port at
  * http://handhelds.org/moin/moin.cgi/AcerN30Documentation .
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
-*/
+ */
 
 #include <linux/kernel.h>
 #include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/list.h>
-#include <linux/timer.h>
-#include <linux/init.h>
+
 #include <linux/delay.h>
-#include <linux/serial_core.h>
+#include <linux/gpio_keys.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
 #include <linux/platform_device.h>
-#include <linux/kthread.h>
-
-#include <asm/mach/arch.h>
-#include <asm/mach/map.h>
-#include <asm/mach/irq.h>
+#include <linux/serial_core.h>
+#include <linux/timer.h>
 
 #include <asm/hardware.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/mach-types.h>
 
-#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/fb.h>
+#include <asm/arch/leds-gpio.h>
 #include <asm/arch/regs-gpio.h>
+#include <asm/arch/regs-lcd.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/irq.h>
+#include <asm/mach/map.h>
+
 #include <asm/plat-s3c/iic.h>
+#include <asm/plat-s3c/regs-serial.h>
 
-#include <asm/plat-s3c24xx/s3c2410.h>
 #include <asm/plat-s3c24xx/clock.h>
-#include <asm/plat-s3c24xx/devs.h>
 #include <asm/plat-s3c24xx/cpu.h>
+#include <asm/plat-s3c24xx/devs.h>
+#include <asm/plat-s3c24xx/s3c2410.h>
+#include <asm/plat-s3c24xx/udc.h>
 
 static struct map_desc n30_iodesc[] __initdata = {
        /* nothing here yet */
@@ -64,7 +71,8 @@ static struct s3c2410_uartcfg n30_uartcfgs[] = {
                .ulcon       = 0x43,
                .ufcon       = 0x51,
        },
-       /* The BlueTooth controller is connected to port 2 */
+       /* On the N30 the bluetooth controller is connected here.
+        * On the N35 and variants the GPS receiver is connected here. */
        [2] = {
                .hwport      = 2,
                .flags       = 0,
@@ -74,13 +82,260 @@ static struct s3c2410_uartcfg n30_uartcfgs[] = {
        },
 };
 
+static void n30_udc_pullup(enum s3c2410_udc_cmd_e cmd)
+{
+       switch (cmd) {
+       case S3C2410_UDC_P_ENABLE :
+               s3c2410_gpio_setpin(S3C2410_GPB3, 1);
+               break;
+       case S3C2410_UDC_P_DISABLE :
+               s3c2410_gpio_setpin(S3C2410_GPB3, 0);
+               break;
+       case S3C2410_UDC_P_RESET :
+               break;
+       default:
+               break;
+       }
+}
+
+static struct s3c2410_udc_mach_info n30_udc_cfg __initdata = {
+       .udc_command            = n30_udc_pullup,
+       .vbus_pin               = S3C2410_GPG1,
+       .vbus_pin_inverted      = 0,
+};
+
+static struct gpio_keys_button n30_buttons[] = {
+       {
+               .gpio           = S3C2410_GPF0,
+               .code           = KEY_POWER,
+               .desc           = "Power",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG9,
+               .code           = KEY_UP,
+               .desc           = "Thumbwheel Up",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG8,
+               .code           = KEY_DOWN,
+               .desc           = "Thumbwheel Down",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG7,
+               .code           = KEY_ENTER,
+               .desc           = "Thumbwheel Press",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF7,
+               .code           = KEY_HOMEPAGE,
+               .desc           = "Home",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF6,
+               .code           = KEY_CALENDAR,
+               .desc           = "Calendar",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF5,
+               .code           = KEY_ADDRESSBOOK,
+               .desc           = "Contacts",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF4,
+               .code           = KEY_MAIL,
+               .desc           = "Mail",
+               .active_low     = 0,
+       },
+};
+
+static struct gpio_keys_platform_data n30_button_data = {
+       .buttons        = n30_buttons,
+       .nbuttons       = ARRAY_SIZE(n30_buttons),
+};
+
+static struct platform_device n30_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &n30_button_data,
+       }
+};
+
+static struct gpio_keys_button n35_buttons[] = {
+       {
+               .gpio           = S3C2410_GPF0,
+               .code           = KEY_POWER,
+               .desc           = "Power",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG9,
+               .code           = KEY_UP,
+               .desc           = "Joystick Up",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG8,
+               .code           = KEY_DOWN,
+               .desc           = "Joystick Down",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG6,
+               .code           = KEY_DOWN,
+               .desc           = "Joystick Left",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG5,
+               .code           = KEY_DOWN,
+               .desc           = "Joystick Right",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG7,
+               .code           = KEY_ENTER,
+               .desc           = "Joystick Press",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF7,
+               .code           = KEY_HOMEPAGE,
+               .desc           = "Home",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF6,
+               .code           = KEY_CALENDAR,
+               .desc           = "Calendar",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF5,
+               .code           = KEY_ADDRESSBOOK,
+               .desc           = "Contacts",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF4,
+               .code           = KEY_MAIL,
+               .desc           = "Mail",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPF3,
+               .code           = SW_RADIO,
+               .desc           = "GPS Antenna",
+               .active_low     = 0,
+       },
+       {
+               .gpio           = S3C2410_GPG2,
+               .code           = SW_HEADPHONE_INSERT,
+               .desc           = "Headphone",
+               .active_low     = 0,
+       },
+};
+
+static struct gpio_keys_platform_data n35_button_data = {
+       .buttons        = n35_buttons,
+       .nbuttons       = ARRAY_SIZE(n35_buttons),
+};
+
+static struct platform_device n35_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &n35_button_data,
+       }
+};
+
+/* This is the bluetooth LED on the device. */
+static struct s3c24xx_led_platdata n30_blue_led_pdata = {
+       .name           = "blue_led",
+       .gpio           = S3C2410_GPG6,
+       .def_trigger    = "",
+};
+
+/* This LED is driven by the battery microcontroller, and is blinking
+ * red, blinking green or solid green when the battery is low,
+ * charging or full respectively.  By driving GPD9 low, it's possible
+ * to force the LED to blink red, so call that warning LED.  */
+static struct s3c24xx_led_platdata n30_warning_led_pdata = {
+       .name           = "warning_led",
+       .flags          = S3C24XX_LEDF_ACTLOW,
+       .gpio           = S3C2410_GPD9,
+       .def_trigger    = "",
+};
+
+static struct platform_device n30_blue_led = {
+       .name           = "s3c24xx_led",
+       .id             = 1,
+       .dev            = {
+               .platform_data  = &n30_blue_led_pdata,
+       },
+};
+
+static struct platform_device n30_warning_led = {
+       .name           = "s3c24xx_led",
+       .id             = 2,
+       .dev            = {
+               .platform_data  = &n30_warning_led_pdata,
+       },
+};
+
+static struct s3c2410fb_display n30_display __initdata = {
+       .type           = S3C2410_LCDCON1_TFT,
+       .width          = 240,
+       .height         = 320,
+       .pixclock       = 170000,
+
+       .xres           = 240,
+       .yres           = 320,
+       .bpp            = 16,
+       .left_margin    = 3,
+       .right_margin   = 40,
+       .hsync_len      = 40,
+       .upper_margin   = 2,
+       .lower_margin   = 3,
+       .vsync_len      = 2,
+
+       .lcdcon5 = S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVFRAME,
+};
+
+static struct s3c2410fb_mach_info n30_fb_info __initdata = {
+       .displays       = &n30_display,
+       .num_displays   = 1,
+       .default_display = 0,
+       .lpcsel         = 0x06,
+};
+
 static struct platform_device *n30_devices[] __initdata = {
+       &s3c_device_lcd,
+       &s3c_device_wdt,
+       &s3c_device_i2c,
+       &s3c_device_iis,
        &s3c_device_usb,
+       &s3c_device_usbgadget,
+       &n30_button_device,
+       &n30_blue_led,
+       &n30_warning_led,
+};
+
+static struct platform_device *n35_devices[] __initdata = {
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c,
        &s3c_device_iis,
        &s3c_device_usbgadget,
+       &n35_button_device,
 };
 
 static struct s3c2410_platform_i2c n30_i2ccfg = {
@@ -90,9 +345,148 @@ static struct s3c2410_platform_i2c n30_i2ccfg = {
        .max_freq       = 10*1000,
 };
 
+/* Lots of hardcoded stuff, but it sets up the hardware in a useful
+ * state so that we can boot Linux directly from flash. */
+static void __init n30_hwinit(void)
+{
+       /* GPA0-11 special functions -- unknown what they do
+        * GPA12 N30 special function -- unknown what it does
+        *       N35/PiN output -- unknown what it does
+        *
+        * A12 is nGCS1 on the N30 and an output on the N35/PiN.  I
+        * don't think it does anything useful on the N30, so I ought
+        * to make it an output there too since it always driven to 0
+        * as far as I can tell. */
+       if (machine_is_n30())
+               __raw_writel(0x007fffff, S3C2410_GPACON);
+       if (machine_is_n35())
+               __raw_writel(0x007fefff, S3C2410_GPACON);
+       __raw_writel(0x00000000, S3C2410_GPADAT);
+
+       /* GPB0 TOUT0 backlight level
+        * GPB1 output 1=backlight on
+        * GPB2 output IrDA enable 0=transceiver enabled, 1=disabled
+        * GPB3 output USB D+ pull up 0=disabled, 1=enabled
+        * GPB4 N30 output -- unknown function
+        *      N30/PiN GPS control 0=GPS enabled, 1=GPS disabled
+        * GPB5 output -- unknown function
+        * GPB6 input -- unknown function
+        * GPB7 output -- unknown function
+        * GPB8 output -- probably LCD driver enable
+        * GPB9 output -- probably LCD VSYNC driver enable
+        * GPB10 output -- probably LCD HSYNC driver enable
+        */
+       __raw_writel(0x00154556, S3C2410_GPBCON);
+       __raw_writel(0x00000750, S3C2410_GPBDAT);
+       __raw_writel(0x00000073, S3C2410_GPBUP);
+
+       /* GPC0 input RS232 DCD/DSR/RI
+        * GPC1 LCD
+        * GPC2 output RS232 DTR?
+        * GPC3 input RS232 DCD/DSR/RI
+        * GPC4 LCD
+        * GPC5 output 0=NAND write enabled, 1=NAND write protect
+        * GPC6 input -- unknown function
+        * GPC7 input charger status 0=charger connected
+        *      this input can be triggered by power on the USB device
+        *      port too, but will go back to disconnected soon after.
+        * GPC8 N30/N35 output -- unknown function, always driven to 1
+        *      PiN input -- unknown function, always read as 1
+        *      Make it an input with a pull up for all models.
+        * GPC9-15 LCD
+        */
+       __raw_writel(0xaaa80618, S3C2410_GPCCON);
+       __raw_writel(0x0000014c, S3C2410_GPCDAT);
+       __raw_writel(0x0000fef2, S3C2410_GPCUP);
+
+       /* GPD0 input -- unknown function
+        * GPD1-D7 LCD
+        * GPD8 N30 output -- unknown function
+        *      N35/PiN output 1=GPS LED on
+        * GPD9 output 0=power led blinks red, 1=normal power led function
+        * GPD10 output -- unknown function
+        * GPD11-15 LCD drivers
+        */
+       __raw_writel(0xaa95aaa4, S3C2410_GPDCON);
+       __raw_writel(0x00000601, S3C2410_GPDDAT);
+       __raw_writel(0x0000fbfe, S3C2410_GPDUP);
+
+       /* GPE0-4 I2S audio bus
+        * GPE5-10 SD/MMC bus
+        * E11-13 outputs -- unknown function, probably power management
+        * E14-15 I2C bus connected to the battery controller
+        */
+       __raw_writel(0xa56aaaaa, S3C2410_GPECON);
+       __raw_writel(0x0000efc5, S3C2410_GPEDAT);
+       __raw_writel(0x0000f81f, S3C2410_GPEUP);
+
+       /* GPF0  input 0=power button pressed
+        * GPF1  input SD/MMC switch 0=card present
+        * GPF2  N30 1=reset button pressed (inverted compared to the rest)
+        *       N35/PiN 0=reset button pressed
+        * GPF3  N30/PiN input -- unknown function
+        *       N35 input GPS antenna position, 0=antenna closed, 1=open
+        * GPF4  input 0=button 4 pressed
+        * GPF5  input 0=button 3 pressed
+        * GPF6  input 0=button 2 pressed
+        * GPF7  input 0=button 1 pressed
+        */
+       __raw_writel(0x0000aaaa, S3C2410_GPFCON);
+       __raw_writel(0x00000000, S3C2410_GPFDAT);
+       __raw_writel(0x000000ff, S3C2410_GPFUP);
+
+       /* GPG0  input RS232 DCD/DSR/RI
+        * GPG1  input 1=USB gadget port has power from a host
+        * GPG2  N30 input -- unknown function
+        *       N35/PiN input 0=headphones plugged in, 1=not plugged in
+        * GPG3  N30 output -- unknown function
+        *       N35/PiN input with unknown function
+        * GPG4  N30 output 0=MMC enabled, 1=MMC disabled
+        * GPG5  N30 output 0=BlueTooth chip disabled, 1=enabled
+        *       N35/PiN input joystick right
+        * GPG6  N30 output 0=blue led on, 1=off
+        *       N35/PiN input joystick left
+        * GPG7  input 0=thumbwheel pressed
+        * GPG8  input 0=thumbwheel down
+        * GPG9  input 0=thumbwheel up
+        * GPG10 input SD/MMC write protect switch
+        * GPG11 N30 input -- unknown function
+        *       N35 output 0=GPS antenna powered, 1=not powered
+        *       PiN output -- unknown function
+        * GPG12-15 touch screen functions
+        *
+        * The pullups differ between the models, so enable all
+        * pullups that are enabled on any of the models.
+        */
+       if (machine_is_n30())
+               __raw_writel(0xff0a956a, S3C2410_GPGCON);
+       if (machine_is_n35())
+               __raw_writel(0xff4aa92a, S3C2410_GPGCON);
+       __raw_writel(0x0000e800, S3C2410_GPGDAT);
+       __raw_writel(0x0000f86f, S3C2410_GPGUP);
+
+       /* GPH0/1/2/3 RS232 serial port
+        * GPH4/5 IrDA serial port
+        * GPH6/7  N30 BlueTooth serial port
+        *         N35/PiN GPS receiver
+        * GPH8 input -- unknown function
+        * GPH9 CLKOUT0 HCLK -- unknown use
+        * GPH10 CLKOUT1 FCLK -- unknown use
+        *
+        * The pull ups for H6/H7 are enabled on N30 but not on the
+        * N35/PiN.  I suppose is useful for a budget model of the N30
+        * with no bluetooh.  It doesn't hurt to have the pull ups
+        * enabled on the N35, so leave them enabled for all models.
+        */
+       __raw_writel(0x0028aaaa, S3C2410_GPHCON);
+       __raw_writel(0x000005ef, S3C2410_GPHDAT);
+       __raw_writel(0x0000063f, S3C2410_GPHUP);
+}
+
 static void __init n30_map_io(void)
 {
        s3c24xx_init_io(n30_iodesc, ARRAY_SIZE(n30_iodesc));
+       n30_hwinit();
        s3c24xx_init_clocks(0);
        s3c24xx_init_uarts(n30_uartcfgs, ARRAY_SIZE(n30_uartcfgs));
 }
@@ -106,7 +500,9 @@ static void __init n30_init_irq(void)
 
 static void __init n30_init(void)
 {
+       s3c24xx_fb_set_platdata(&n30_fb_info);
        s3c_device_i2c.dev.platform_data = &n30_i2ccfg;
+       s3c24xx_udc_set_platdata(&n30_udc_cfg);
 
        /* Turn off suspend on both USB ports, and switch the
         * selectable USB port to USB device mode. */
@@ -115,7 +511,32 @@ static void __init n30_init(void)
                              S3C2410_MISCCR_USBSUSPND0 |
                              S3C2410_MISCCR_USBSUSPND1, 0x0);
 
-       platform_add_devices(n30_devices, ARRAY_SIZE(n30_devices));
+       if (machine_is_n30()) {
+               /* Turn off suspend on both USB ports, and switch the
+                * selectable USB port to USB device mode. */
+               s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
+                                     S3C2410_MISCCR_USBSUSPND0 |
+                                     S3C2410_MISCCR_USBSUSPND1, 0x0);
+
+               platform_add_devices(n30_devices, ARRAY_SIZE(n30_devices));
+       }
+
+       if (machine_is_n35()) {
+               /* Turn off suspend and switch the selectable USB port
+                * to USB device mode.  Turn on suspend for the host
+                * port since it is not connected on the N35.
+                *
+                * Actually, the host port is available at some pads
+                * on the back of the device, so it would actually be
+                * possible to add a USB device inside the N35 if you
+                * are willing to do some hardware modifications. */
+               s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
+                                     S3C2410_MISCCR_USBSUSPND0 |
+                                     S3C2410_MISCCR_USBSUSPND1,
+                                     S3C2410_MISCCR_USBSUSPND1);
+
+               platform_add_devices(n35_devices, ARRAY_SIZE(n35_devices));
+       }
 }
 
 MACHINE_START(N30, "Acer-N30")
@@ -131,9 +552,14 @@ MACHINE_START(N30, "Acer-N30")
        .map_io         = n30_map_io,
 MACHINE_END
 
-/*
-    Local variables:
-        compile-command: "make ARCH=arm CROSS_COMPILE=/usr/local/arm/3.3.2/bin/arm-linux- -k -C ../../.."
-        c-basic-offset: 8
-    End:
-*/
+MACHINE_START(N35, "Acer-N35")
+       /* Maintainer: Christer Weinigel <christer@weinigel.se>
+       */
+       .phys_io        = S3C2410_PA_UART,
+       .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
+       .boot_params    = S3C2410_SDRAM_PA + 0x100,
+       .timer          = &s3c24xx_timer,
+       .init_machine   = n30_init,
+       .init_irq       = n30_init_irq,
+       .map_io         = n30_map_io,
+MACHINE_END
index 4c4b5c4..9a0965a 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/mach-s3c2410/mach-vr1000.c
  *
- * Copyright (c) 2003-2005 Simtec Electronics
+ * Copyright (c) 2003-2005,2008 Simtec Electronics
  *   Ben Dooks <ben@simtec.co.uk>
  *
  * Machine support for Thorcom VR1000 board. Designed for Thorcom by
@@ -19,6 +19,7 @@
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/dm9000.h>
+#include <linux/i2c.h>
 
 #include <linux/serial.h>
 #include <linux/tty.h>
@@ -46,7 +47,9 @@
 #include <asm/plat-s3c24xx/clock.h>
 #include <asm/plat-s3c24xx/devs.h>
 #include <asm/plat-s3c24xx/cpu.h>
+
 #include "usb-simtec.h"
+#include "nor-simtec.h"
 
 /* macros for virtual address mods for the io space entries */
 #define VA_C5(item) ((unsigned long)(item) + BAST_VAM_CS5)
@@ -97,34 +100,6 @@ static struct map_desc vr1000_iodesc[] __initdata = {
          .length       = SZ_1M,
          .type         = MT_DEVICE,
   },
-
-  /* peripheral space... one for each of fast/slow/byte/16bit */
-  /* note, ide is only decoded in word space, even though some registers
-   * are only 8bit */
-
-  /* slow, byte */
-  { VA_C2(VR1000_VA_IDEPRI),  PA_CS3(VR1000_PA_IDEPRI),          SZ_1M,  MT_DEVICE },
-  { VA_C2(VR1000_VA_IDESEC),  PA_CS3(VR1000_PA_IDESEC),          SZ_1M,  MT_DEVICE },
-  { VA_C2(VR1000_VA_IDEPRIAUX), PA_CS3(VR1000_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C2(VR1000_VA_IDESECAUX), PA_CS3(VR1000_PA_IDESECAUX), SZ_1M, MT_DEVICE },
-
-  /* slow, word */
-  { VA_C3(VR1000_VA_IDEPRI),  PA_CS3(VR1000_PA_IDEPRI),          SZ_1M,  MT_DEVICE },
-  { VA_C3(VR1000_VA_IDESEC),  PA_CS3(VR1000_PA_IDESEC),          SZ_1M,  MT_DEVICE },
-  { VA_C3(VR1000_VA_IDEPRIAUX), PA_CS3(VR1000_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C3(VR1000_VA_IDESECAUX), PA_CS3(VR1000_PA_IDESECAUX), SZ_1M, MT_DEVICE },
-
-  /* fast, byte */
-  { VA_C4(VR1000_VA_IDEPRI),  PA_CS5(VR1000_PA_IDEPRI),          SZ_1M,  MT_DEVICE },
-  { VA_C4(VR1000_VA_IDESEC),  PA_CS5(VR1000_PA_IDESEC),          SZ_1M,  MT_DEVICE },
-  { VA_C4(VR1000_VA_IDEPRIAUX), PA_CS5(VR1000_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C4(VR1000_VA_IDESECAUX), PA_CS5(VR1000_PA_IDESECAUX), SZ_1M, MT_DEVICE },
-
-  /* fast, word */
-  { VA_C5(VR1000_VA_IDEPRI),  PA_CS5(VR1000_PA_IDEPRI),          SZ_1M,  MT_DEVICE },
-  { VA_C5(VR1000_VA_IDESEC),  PA_CS5(VR1000_PA_IDESEC),          SZ_1M,  MT_DEVICE },
-  { VA_C5(VR1000_VA_IDEPRIAUX), PA_CS5(VR1000_PA_IDEPRIAUX), SZ_1M, MT_DEVICE },
-  { VA_C5(VR1000_VA_IDESECAUX), PA_CS5(VR1000_PA_IDESECAUX), SZ_1M, MT_DEVICE },
 };
 
 #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
@@ -230,23 +205,6 @@ static struct platform_device serial_device = {
        },
 };
 
-/* MTD NOR Flash */
-
-static struct resource vr1000_nor_resource[] = {
-       [0] = {
-               .start  = S3C2410_CS1 + 0x4000000,
-               .end    = S3C2410_CS1 + 0x4000000 + SZ_16M - 1,
-               .flags  = IORESOURCE_MEM,
-       }
-};
-
-static struct platform_device vr1000_nor = {
-       .name           = "bast-nor",
-       .id             = -1,
-       .num_resources  = ARRAY_SIZE(vr1000_nor_resource),
-       .resource       = vr1000_nor_resource,
-};
-
 /* DM9000 ethernet devices */
 
 static struct resource vr1000_dm9k0_resource[] = {
@@ -263,7 +221,7 @@ static struct resource vr1000_dm9k0_resource[] = {
        [2] = {
                .start = IRQ_VR1000_DM9000A,
                .end   = IRQ_VR1000_DM9000A,
-               .flags = IORESOURCE_IRQ | IRQF_TRIGGER_HIGH,
+               .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
        }
 
 };
@@ -282,7 +240,7 @@ static struct resource vr1000_dm9k1_resource[] = {
        [2] = {
                .start = IRQ_VR1000_DM9000N,
                .end   = IRQ_VR1000_DM9000N,
-               .flags = IORESOURCE_IRQ | IRQF_TRIGGER_HIGH,
+               .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
        }
 };
 
@@ -358,6 +316,18 @@ static struct platform_device vr1000_led3 = {
        },
 };
 
+/* I2C devices. */
+
+static struct i2c_board_info vr1000_i2c_devs[] __initdata = {
+       {
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       }, {
+               I2C_BOARD_INFO("tmp101", 0x48),
+       }, {
+               I2C_BOARD_INFO("m41st87", 0x68),
+       },
+};
+
 /* devices for this board */
 
 static struct platform_device *vr1000_devices[] __initdata = {
@@ -367,7 +337,6 @@ static struct platform_device *vr1000_devices[] __initdata = {
        &s3c_device_i2c,
        &s3c_device_adc,
        &serial_device,
-       &vr1000_nor,
        &vr1000_dm9k0,
        &vr1000_dm9k1,
        &vr1000_led1,
@@ -416,6 +385,11 @@ static void __init vr1000_map_io(void)
 static void __init vr1000_init(void)
 {
        platform_add_devices(vr1000_devices, ARRAY_SIZE(vr1000_devices));
+
+       i2c_register_board_info(0, vr1000_i2c_devs,
+                               ARRAY_SIZE(vr1000_i2c_devs));
+
+       nor_simtec_init();
 }
 
 MACHINE_START(VR1000, "Thorcom-VR1000")
diff --git a/arch/arm/mach-s3c2410/nor-simtec.c b/arch/arm/mach-s3c2410/nor-simtec.c
new file mode 100644 (file)
index 0000000..f44e21b
--- /dev/null
@@ -0,0 +1,86 @@
+/* linux/arch/arm/mach-s3c2410/nor-simtec.c
+ *
+ * Copyright (c) 2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * Simtec NOR mapping
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/arch/map.h>
+#include <asm/arch/bast-map.h>
+#include <asm/arch/bast-cpld.h>
+
+
+static void simtec_nor_vpp(struct map_info *map, int vpp)
+{
+       unsigned int val;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       val = __raw_readb(BAST_VA_CTRL3);
+
+       printk(KERN_DEBUG "%s(%d)\n", __func__, vpp);
+
+       if (vpp)
+               val |= BAST_CPLD_CTRL3_ROMWEN;
+       else
+               val &= ~BAST_CPLD_CTRL3_ROMWEN;
+
+       __raw_writeb(val, BAST_VA_CTRL3);
+       local_irq_restore(flags);
+}
+
+struct physmap_flash_data simtec_nor_pdata = {
+       .width          = 2,
+       .set_vpp        = simtec_nor_vpp,
+       .nr_parts       = 0,
+};
+
+static struct resource simtec_nor_resource[] = {
+       [0] = {
+               .start = S3C2410_CS1 + 0x4000000,
+               .end   = S3C2410_CS1 + 0x4000000 + SZ_8M - 1,
+               .flags = IORESOURCE_MEM,
+       }
+};
+
+static struct platform_device simtec_device_nor = {
+       .name           = "physmap-flash",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(simtec_nor_resource),
+       .resource       = simtec_nor_resource,
+       .dev            = {
+               .platform_data = &simtec_nor_pdata,
+       },
+};
+
+void __init nor_simtec_init(void)
+{
+       int ret;
+
+       ret = platform_device_register(&simtec_device_nor);
+       if (ret < 0)
+               printk(KERN_ERR "failed to register physmap-flash device\n");
+       else
+               simtec_nor_vpp(NULL, 1);
+}
diff --git a/arch/arm/mach-s3c2410/nor-simtec.h b/arch/arm/mach-s3c2410/nor-simtec.h
new file mode 100644 (file)
index 0000000..f619c1e
--- /dev/null
@@ -0,0 +1,14 @@
+/* linux/arch/arm/mach-s3c2410/nor-simtec.h
+ *
+ * Copyright (c) 2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * Simtec NOR mapping
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+extern void nor_simtec_init(void);
index 0b43431..c59a9d2 100644 (file)
@@ -34,6 +34,16 @@ config S3C2412_PM
 
 menu "S3C2412 Machines"
 
+config MACH_JIVE
+       bool "Logitech Jive"
+       select CPU_S3C2412
+       help
+         Say Y here if you are using the Logitech Jive.
+
+config MACH_JIVE_SHOW_BOOTLOADER
+       bool "Allow access to bootloader partitions in MTD"
+       depends on MACH_JIVE && EXPERIMENTAL
+
 config MACH_SMDK2413
        bool "SMDK2413"
        select CPU_S3C2412
index 267f334..20918d5 100644 (file)
@@ -18,5 +18,6 @@ obj-$(CONFIG_S3C2412_PM)      += pm.o sleep.o
 
 # Machine support
 
+obj-$(CONFIG_MACH_JIVE)                += mach-jive.o
 obj-$(CONFIG_MACH_SMDK2413)    += mach-smdk2413.o
 obj-$(CONFIG_MACH_VSTMS)       += mach-vstms.o
index 2697a65..1157b5a 100644 (file)
@@ -631,6 +631,17 @@ static struct clk_init clks_src[] __initdata = {
                .bit    = S3C2412_CLKSRC_USBCLK_HCLK,
                .src_0  = &clk_usysclk,
                .src_1  = &clk_h,
+       /* here we assume  OM[4] select xtal */
+       }, {
+               .clk    = &clk_erefclk,
+               .bit    = S3C2412_CLKSRC_EREFCLK_EXTCLK,
+               .src_0  = &clk_xtal,
+               .src_1  = &clk_ext,
+       }, {
+               .clk    = &clk_urefclk,
+               .bit    = S3C2412_CLKSRC_UREFCLK_EXTCLK,
+               .src_0  = &clk_xtal,
+               .src_1  = &clk_ext,
        },
 };
 
@@ -666,8 +677,6 @@ static void __init s3c2412_clk_initparents(void)
 static struct clk *clks[] __initdata = {
        &clk_ext,
        &clk_usb_bus,
-       &clk_erefclk,
-       &clk_urefclk,
        &clk_mrefclk,
        &clk_armclk,
 };
diff --git a/arch/arm/mach-s3c2412/mach-jive.c b/arch/arm/mach-s3c2412/mach-jive.c
new file mode 100644 (file)
index 0000000..7f59247
--- /dev/null
@@ -0,0 +1,687 @@
+/* linux/arch/arm/mach-s3c2410/mach-jive.c
+ *
+ * Copyright 2007 Simtec Electronics
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/timer.h>
+#include <linux/init.h>
+#include <linux/sysdev.h>
+#include <linux/delay.h>
+#include <linux/serial_core.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+
+#include <video/ili9320.h>
+
+#include <linux/spi/spi.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/plat-s3c/nand.h>
+#include <asm/plat-s3c/iic.h>
+
+#include <asm/arch/regs-power.h>
+#include <asm/arch/regs-gpio.h>
+#include <asm/arch/regs-mem.h>
+#include <asm/arch/regs-lcd.h>
+#include <asm/arch/spi-gpio.h>
+#include <asm/arch/fb.h>
+
+#include <asm/mach-types.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/plat-s3c24xx/clock.h>
+#include <asm/plat-s3c24xx/devs.h>
+#include <asm/plat-s3c24xx/cpu.h>
+#include <asm/plat-s3c24xx/pm.h>
+#include <asm/plat-s3c24xx/udc.h>
+
+static struct map_desc jive_iodesc[] __initdata = {
+};
+
+#define UCON S3C2410_UCON_DEFAULT
+#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE
+#define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
+
+static struct s3c2410_uartcfg jive_uartcfgs[] = {
+       [0] = {
+               .hwport      = 0,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+       },
+       [1] = {
+               .hwport      = 1,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+       },
+       [2] = {
+               .hwport      = 2,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+       }
+};
+
+/* Jive flash assignment
+ *
+ * 0x00000000-0x00028000 : uboot
+ * 0x00028000-0x0002c000 : uboot env
+ * 0x0002c000-0x00030000 : spare
+ * 0x00030000-0x00200000 : zimage A
+ * 0x00200000-0x01600000 : cramfs A
+ * 0x01600000-0x017d0000 : zimage B
+ * 0x017d0000-0x02bd0000 : cramfs B
+ * 0x02bd0000-0x03fd0000 : yaffs
+ */
+static struct mtd_partition jive_imageA_nand_part[] = {
+
+#ifdef CONFIG_MACH_JIVE_SHOW_BOOTLOADER
+       /* Don't allow access to the bootloader from linux */
+       {
+               .name           = "uboot",
+               .offset         = 0,
+               .size           = (160 * SZ_1K),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+       },
+
+       /* spare */
+        {
+                .name           = "spare",
+                .offset         = (176 * SZ_1K),
+                .size           = (16 * SZ_1K),
+        },
+#endif
+
+       /* booted images */
+        {
+               .name           = "kernel (ro)",
+               .offset         = (192 * SZ_1K),
+               .size           = (SZ_2M) - (192 * SZ_1K),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+        }, {
+                .name           = "root (ro)",
+                .offset         = (SZ_2M),
+                .size           = (20 * SZ_1M),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+        },
+
+       /* yaffs */
+       {
+               .name           = "yaffs",
+               .offset         = (44 * SZ_1M),
+               .size           = (20 * SZ_1M),
+       },
+
+       /* bootloader environment */
+       {
+                .name          = "env",
+               .offset         = (160 * SZ_1K),
+               .size           = (16 * SZ_1K),
+       },
+
+       /* upgrade images */
+        {
+               .name           = "zimage",
+               .offset         = (22 * SZ_1M),
+               .size           = (2 * SZ_1M) - (192 * SZ_1K),
+        }, {
+               .name           = "cramfs",
+               .offset         = (24 * SZ_1M) - (192*SZ_1K),
+               .size           = (20 * SZ_1M),
+        },
+};
+
+static struct mtd_partition jive_imageB_nand_part[] = {
+
+#ifdef CONFIG_MACH_JIVE_SHOW_BOOTLOADER
+       /* Don't allow access to the bootloader from linux */
+       {
+               .name           = "uboot",
+               .offset         = 0,
+               .size           = (160 * SZ_1K),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+       },
+
+       /* spare */
+        {
+                .name           = "spare",
+                .offset         = (176 * SZ_1K),
+                .size           = (16 * SZ_1K),
+        },
+#endif
+
+       /* booted images */
+        {
+               .name           = "kernel (ro)",
+               .offset         = (22 * SZ_1M),
+               .size           = (2 * SZ_1M) - (192 * SZ_1K),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+        },
+       {
+               .name           = "root (ro)",
+               .offset         = (24 * SZ_1M) - (192 * SZ_1K),
+                .size          = (20 * SZ_1M),
+               .mask_flags     = MTD_WRITEABLE, /* force read-only */
+       },
+
+       /* yaffs */
+       {
+               .name           = "yaffs",
+               .offset         = (44 * SZ_1M),
+               .size           = (20 * SZ_1M),
+        },
+
+       /* bootloader environment */
+       {
+               .name           = "env",
+               .offset         = (160 * SZ_1K),
+               .size           = (16 * SZ_1K),
+       },
+
+       /* upgrade images */
+       {
+               .name           = "zimage",
+               .offset         = (192 * SZ_1K),
+               .size           = (2 * SZ_1M) - (192 * SZ_1K),
+        }, {
+               .name           = "cramfs",
+               .offset         = (2 * SZ_1M),
+               .size           = (20 * SZ_1M),
+        },
+};
+
+static struct s3c2410_nand_set jive_nand_sets[] = {
+       [0] = {
+               .name           = "flash",
+               .nr_chips       = 1,
+               .nr_partitions  = ARRAY_SIZE(jive_imageA_nand_part),
+               .partitions     = jive_imageA_nand_part,
+       },
+};
+
+static struct s3c2410_platform_nand jive_nand_info = {
+       /* set taken from osiris nand timings, possibly still conservative */
+       .tacls          = 30,
+       .twrph0         = 55,
+       .twrph1         = 40,
+       .sets           = jive_nand_sets,
+       .nr_sets        = ARRAY_SIZE(jive_nand_sets),
+};
+
+static int __init jive_mtdset(char *options)
+{
+       struct s3c2410_nand_set *nand = &jive_nand_sets[0];
+       unsigned long set;
+
+       if (options == NULL || options[0] == '\0')
+               return 0;
+
+       if (strict_strtoul(options, 10, &set)) {
+               printk(KERN_ERR "failed to parse mtdset=%s\n", options);
+               return 0;
+       }
+
+       switch (set) {
+       case 1:
+               nand->nr_partitions = ARRAY_SIZE(jive_imageB_nand_part);
+               nand->partitions = jive_imageB_nand_part;
+       case 0:
+               /* this is already setup in the nand info */
+               break;
+       default:
+               printk(KERN_ERR "Unknown mtd set %ld specified,"
+                      "using default.", set);
+       }
+
+       return 0;
+}
+
+/* parse the mtdset= option given to the kernel command line */
+__setup("mtdset=", jive_mtdset);
+
+/* LCD timing and setup */
+
+#define LCD_XRES        (240)
+#define LCD_YRES        (320)
+#define LCD_LEFT_MARGIN  (12)
+#define LCD_RIGHT_MARGIN (12)
+#define LCD_LOWER_MARGIN (12)
+#define LCD_UPPER_MARGIN (12)
+#define LCD_VSYNC       (2)
+#define LCD_HSYNC       (2)
+
+#define LCD_REFRESH     (60)
+
+#define LCD_HTOT (LCD_HSYNC + LCD_LEFT_MARGIN + LCD_XRES + LCD_RIGHT_MARGIN)
+#define LCD_VTOT (LCD_VSYNC + LCD_LOWER_MARGIN + LCD_YRES + LCD_UPPER_MARGIN)
+
+struct s3c2410fb_display jive_vgg2432a4_display[] = {
+       [0] = {
+               .width          = LCD_XRES,
+               .height         = LCD_YRES,
+               .xres           = LCD_XRES,
+               .yres           = LCD_YRES,
+               .left_margin    = LCD_LEFT_MARGIN,
+               .right_margin   = LCD_RIGHT_MARGIN,
+               .upper_margin   = LCD_UPPER_MARGIN,
+               .lower_margin   = LCD_LOWER_MARGIN,
+               .hsync_len      = LCD_HSYNC,
+               .vsync_len      = LCD_VSYNC,
+
+               .pixclock       = (1000000000000LL /
+                                  (LCD_REFRESH * LCD_HTOT * LCD_VTOT)),
+
+               .bpp            = 16,
+               .type           = (S3C2410_LCDCON1_TFT16BPP |
+                                  S3C2410_LCDCON1_TFT),
+
+               .lcdcon5        = (S3C2410_LCDCON5_FRM565 |
+                                  S3C2410_LCDCON5_INVVLINE |
+                                  S3C2410_LCDCON5_INVVFRAME |
+                                  S3C2410_LCDCON5_INVVDEN |
+                                  S3C2410_LCDCON5_PWREN),
+       },
+};
+
+/* todo - put into gpio header */
+
+#define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
+#define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
+
+struct s3c2410fb_mach_info jive_lcd_config = {
+       .displays        = jive_vgg2432a4_display,
+       .num_displays    = ARRAY_SIZE(jive_vgg2432a4_display),
+       .default_display = 0,
+
+       /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
+        * and disable the pull down resistors on pins we are using for LCD
+        * data. */
+
+       .gpcup          = (0xf << 1) | (0x3f << 10),
+
+       .gpccon         = (S3C2410_GPC1_VCLK   | S3C2410_GPC2_VLINE |
+                          S3C2410_GPC3_VFRAME | S3C2410_GPC4_VM |
+                          S3C2410_GPC10_VD2   | S3C2410_GPC11_VD3 |
+                          S3C2410_GPC12_VD4   | S3C2410_GPC13_VD5 |
+                          S3C2410_GPC14_VD6   | S3C2410_GPC15_VD7),
+
+       .gpccon_mask    = (S3C2410_GPCCON_MASK(1)  | S3C2410_GPCCON_MASK(2)  |
+                          S3C2410_GPCCON_MASK(3)  | S3C2410_GPCCON_MASK(4)  |
+                          S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
+                          S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
+                          S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
+
+       .gpdup          = (0x3f << 2) | (0x3f << 10),
+
+       .gpdcon         = (S3C2410_GPD2_VD10  | S3C2410_GPD3_VD11 |
+                          S3C2410_GPD4_VD12  | S3C2410_GPD5_VD13 |
+                          S3C2410_GPD6_VD14  | S3C2410_GPD7_VD15 |
+                          S3C2410_GPD10_VD18 | S3C2410_GPD11_VD19 |
+                          S3C2410_GPD12_VD20 | S3C2410_GPD13_VD21 |
+                          S3C2410_GPD14_VD22 | S3C2410_GPD15_VD23),
+
+       .gpdcon_mask    = (S3C2410_GPDCON_MASK(2)  | S3C2410_GPDCON_MASK(3) |
+                          S3C2410_GPDCON_MASK(4)  | S3C2410_GPDCON_MASK(5) |
+                          S3C2410_GPDCON_MASK(6)  | S3C2410_GPDCON_MASK(7) |
+                          S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
+                          S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
+                          S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
+};
+
+/* ILI9320 support. */
+
+static void jive_lcm_reset(unsigned int set)
+{
+       printk(KERN_DEBUG "%s(%d)\n", __func__, set);
+
+       s3c2410_gpio_setpin(S3C2410_GPG13, set);
+       s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPIO_OUTPUT);
+}
+
+#undef LCD_UPPER_MARGIN
+#define LCD_UPPER_MARGIN 2
+
+static struct ili9320_platdata jive_lcm_config = {
+       .hsize          = LCD_XRES,
+       .vsize          = LCD_YRES,
+
+       .reset          = jive_lcm_reset,
+       .suspend        = ILI9320_SUSPEND_DEEP,
+
+       .entry_mode     = ILI9320_ENTRYMODE_ID(3) | ILI9320_ENTRYMODE_BGR,
+       .display2       = (ILI9320_DISPLAY2_FP(LCD_UPPER_MARGIN) |
+                          ILI9320_DISPLAY2_BP(LCD_LOWER_MARGIN)),
+       .display3       = 0x0,
+       .display4       = 0x0,
+       .rgb_if1        = (ILI9320_RGBIF1_RIM_RGB18 |
+                          ILI9320_RGBIF1_RM | ILI9320_RGBIF1_CLK_RGBIF),
+       .rgb_if2        = ILI9320_RGBIF2_DPL,
+       .interface2     = 0x0,
+       .interface3     = 0x3,
+       .interface4     = (ILI9320_INTERFACE4_RTNE(16) |
+                          ILI9320_INTERFACE4_DIVE(1)),
+       .interface5     = 0x0,
+       .interface6     = 0x0,
+};
+
+/* LCD SPI support */
+
+static void jive_lcd_spi_chipselect(struct s3c2410_spigpio_info *spi, int cs)
+{
+       s3c2410_gpio_setpin(S3C2410_GPB7, cs ? 0 : 1);
+}
+
+static struct s3c2410_spigpio_info jive_lcd_spi = {
+       .bus_num        = 0,
+       .pin_clk        = S3C2410_GPG8,
+       .pin_mosi       = S3C2410_GPB8,
+       .chip_select    = jive_lcd_spi_chipselect,
+};
+
+static struct platform_device jive_device_lcdspi = {
+       .name           = "s3c24xx-spi-gpio",
+       .id             = 1,
+       .num_resources  = 0,
+       .dev.platform_data = &jive_lcd_spi,
+};
+
+/* WM8750 audio code SPI definition */
+
+static void jive_wm8750_chipselect(struct s3c2410_spigpio_info *spi, int cs)
+{
+       s3c2410_gpio_setpin(S3C2410_GPH10, cs ? 0 : 1);
+}
+
+static struct s3c2410_spigpio_info jive_wm8750_spi = {
+       .bus_num        = 2,
+       .pin_clk        = S3C2410_GPB4,
+       .pin_mosi       = S3C2410_GPB9,
+       .chip_select    = jive_wm8750_chipselect,
+};
+
+static struct platform_device jive_device_wm8750 = {
+       .name           = "s3c24xx-spi-gpio",
+       .id             = 2,
+       .num_resources  = 0,
+       .dev.platform_data = &jive_wm8750_spi,
+};
+
+/* JIVE SPI devices. */
+
+static struct spi_board_info __initdata jive_spi_devs[] = {
+       [0] = {
+               .modalias       = "VGG2432A4",
+               .bus_num        = 1,
+               .chip_select    = 0,
+               .mode           = SPI_MODE_3,   /* CPOL=1, CPHA=1 */
+               .max_speed_hz   = 100000,
+               .platform_data  = &jive_lcm_config,
+       }, {
+               .modalias       = "WM8750",
+               .bus_num        = 2,
+               .chip_select    = 0,
+               .mode           = SPI_MODE_0,   /* CPOL=0, CPHA=0 */
+               .max_speed_hz   = 100000,
+       },
+};
+
+/* I2C bus and device configuration. */
+
+static struct s3c2410_platform_i2c jive_i2c_cfg = {
+       .max_freq       = 80 * 1000,
+       .bus_freq       = 50 * 1000,
+       .flags          = S3C_IICFLG_FILTER,
+       .sda_delay      = 2,
+};
+
+static struct i2c_board_info jive_i2c_devs[] = {
+       [0] = {
+               I2C_BOARD_INFO("lis302dl", 0x1c),
+               .irq    = IRQ_EINT14,
+       },
+};
+
+/* The platform devices being used. */
+
+static struct platform_device *jive_devices[] __initdata = {
+       &s3c_device_usb,
+       &s3c_device_rtc,
+       &s3c_device_wdt,
+       &s3c_device_i2c,
+       &s3c_device_lcd,
+       &jive_device_lcdspi,
+       &jive_device_wm8750,
+       &s3c_device_nand,
+       &s3c_device_usbgadget,
+};
+
+static struct s3c2410_udc_mach_info jive_udc_cfg __initdata = {
+       .vbus_pin       = S3C2410_GPG1,         /* detect is on GPG1 */
+};
+
+/* Jive power management device */
+
+#ifdef CONFIG_PM
+static int jive_pm_suspend(struct sys_device *sd, pm_message_t state)
+{
+       /* Write the magic value u-boot uses to check for resume into
+        * the INFORM0 register, and ensure INFORM1 is set to the
+        * correct address to resume from. */
+
+       __raw_writel(0x2BED, S3C2412_INFORM0);
+       __raw_writel(virt_to_phys(s3c2410_cpu_resume), S3C2412_INFORM1);
+
+       return 0;
+}
+
+static int jive_pm_resume(struct sys_device *sd)
+{
+       __raw_writel(0x0, S3C2412_INFORM0);
+       return 0;
+}
+
+#else
+#define jive_pm_suspend NULL
+#define jive_pm_resume NULL
+#endif
+
+static struct sysdev_class jive_pm_sysclass = {
+       .name           = "jive-pm",
+       .suspend        = jive_pm_suspend,
+       .resume         = jive_pm_resume,
+};
+
+static struct sys_device jive_pm_sysdev = {
+       .cls            = &jive_pm_sysclass,
+};
+
+static void __init jive_map_io(void)
+{
+       s3c24xx_init_io(jive_iodesc, ARRAY_SIZE(jive_iodesc));
+       s3c24xx_init_clocks(12000000);
+       s3c24xx_init_uarts(jive_uartcfgs, ARRAY_SIZE(jive_uartcfgs));
+}
+
+static void jive_power_off(void)
+{
+       printk(KERN_INFO "powering system down...\n");
+
+       s3c2410_gpio_setpin(S3C2410_GPC5, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPC5, S3C2410_GPIO_OUTPUT);
+}
+
+static void __init jive_machine_init(void)
+{
+       /* register system devices for managing low level suspend */
+
+       sysdev_class_register(&jive_pm_sysclass);
+       sysdev_register(&jive_pm_sysdev);
+
+       /* write our sleep configurations for the IO. Pull down all unused
+        * IO, ensure that we have turned off all peripherals we do not
+        * need, and configure the ones we do need. */
+
+       /* Port B sleep */
+
+       __raw_writel(S3C2412_SLPCON_IN(0)   |
+                    S3C2412_SLPCON_PULL(1) |
+                    S3C2412_SLPCON_HIGH(2) |
+                    S3C2412_SLPCON_PULL(3) |
+                    S3C2412_SLPCON_PULL(4) |
+                    S3C2412_SLPCON_PULL(5) |
+                    S3C2412_SLPCON_PULL(6) |
+                    S3C2412_SLPCON_HIGH(7) |
+                    S3C2412_SLPCON_PULL(8) |
+                    S3C2412_SLPCON_PULL(9) |
+                    S3C2412_SLPCON_PULL(10), S3C2412_GPBSLPCON);
+
+       /* Port C sleep */
+
+       __raw_writel(S3C2412_SLPCON_PULL(0) |
+                    S3C2412_SLPCON_PULL(1) |
+                    S3C2412_SLPCON_PULL(2) |
+                    S3C2412_SLPCON_PULL(3) |
+                    S3C2412_SLPCON_PULL(4) |
+                    S3C2412_SLPCON_PULL(5) |
+                    S3C2412_SLPCON_LOW(6)  |
+                    S3C2412_SLPCON_PULL(6) |
+                    S3C2412_SLPCON_PULL(7) |
+                    S3C2412_SLPCON_PULL(8) |
+                    S3C2412_SLPCON_PULL(9) |
+                    S3C2412_SLPCON_PULL(10) |
+                    S3C2412_SLPCON_PULL(11) |
+                    S3C2412_SLPCON_PULL(12) |
+                    S3C2412_SLPCON_PULL(13) |
+                    S3C2412_SLPCON_PULL(14) |
+                    S3C2412_SLPCON_PULL(15), S3C2412_GPCSLPCON);
+
+       /* Port D sleep */
+
+       __raw_writel(S3C2412_SLPCON_ALL_PULL, S3C2412_GPDSLPCON);
+
+       /* Port F sleep */
+
+       __raw_writel(S3C2412_SLPCON_LOW(0)  |
+                    S3C2412_SLPCON_LOW(1)  |
+                    S3C2412_SLPCON_LOW(2)  |
+                    S3C2412_SLPCON_EINT(3) |
+                    S3C2412_SLPCON_EINT(4) |
+                    S3C2412_SLPCON_EINT(5) |
+                    S3C2412_SLPCON_EINT(6) |
+                    S3C2412_SLPCON_EINT(7), S3C2412_GPFSLPCON);
+
+       /* Port G sleep */
+
+       __raw_writel(S3C2412_SLPCON_IN(0)    |
+                    S3C2412_SLPCON_IN(1)    |
+                    S3C2412_SLPCON_IN(2)    |
+                    S3C2412_SLPCON_IN(3)    |
+                    S3C2412_SLPCON_IN(4)    |
+                    S3C2412_SLPCON_IN(5)    |
+                    S3C2412_SLPCON_IN(6)    |
+                    S3C2412_SLPCON_IN(7)    |
+                    S3C2412_SLPCON_PULL(8)  |
+                    S3C2412_SLPCON_PULL(9)  |
+                    S3C2412_SLPCON_IN(10)   |
+                    S3C2412_SLPCON_PULL(11) |
+                    S3C2412_SLPCON_PULL(12) |
+                    S3C2412_SLPCON_PULL(13) |
+                    S3C2412_SLPCON_IN(14)   |
+                    S3C2412_SLPCON_PULL(15), S3C2412_GPGSLPCON);
+
+       /* Port H sleep */
+
+       __raw_writel(S3C2412_SLPCON_PULL(0) |
+                    S3C2412_SLPCON_PULL(1) |
+                    S3C2412_SLPCON_PULL(2) |
+                    S3C2412_SLPCON_PULL(3) |
+                    S3C2412_SLPCON_PULL(4) |
+                    S3C2412_SLPCON_PULL(5) |
+                    S3C2412_SLPCON_PULL(6) |
+                    S3C2412_SLPCON_IN(7)   |
+                    S3C2412_SLPCON_IN(8)   |
+                    S3C2412_SLPCON_PULL(9) |
+                    S3C2412_SLPCON_IN(10), S3C2412_GPHSLPCON);
+
+       /* initialise the power management now we've setup everything. */
+
+       s3c2410_pm_init();
+
+       s3c_device_nand.dev.platform_data = &jive_nand_info;
+
+       /* initialise the spi */
+
+       s3c2410_gpio_setpin(S3C2410_GPG13, 0);
+       s3c2410_gpio_cfgpin(S3C2410_GPG13, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPB7, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPB7, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPB6, 0);
+       s3c2410_gpio_cfgpin(S3C2410_GPB6, S3C2410_GPIO_OUTPUT);
+
+       s3c2410_gpio_setpin(S3C2410_GPG8, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPG8, S3C2410_GPIO_OUTPUT);
+
+       /* initialise the WM8750 spi */
+
+       s3c2410_gpio_setpin(S3C2410_GPH10, 1);
+       s3c2410_gpio_cfgpin(S3C2410_GPH10, S3C2410_GPIO_OUTPUT);
+
+       /* Turn off suspend on both USB ports, and switch the
+        * selectable USB port to USB device mode. */
+
+       s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
+                             S3C2410_MISCCR_USBSUSPND0 |
+                             S3C2410_MISCCR_USBSUSPND1, 0x0);
+
+       s3c24xx_udc_set_platdata(&jive_udc_cfg);
+       s3c24xx_fb_set_platdata(&jive_lcd_config);
+
+       spi_register_board_info(jive_spi_devs, ARRAY_SIZE(jive_spi_devs));
+
+       s3c_device_i2c.dev.platform_data = &jive_i2c_cfg;
+       i2c_register_board_info(0, jive_i2c_devs, ARRAY_SIZE(jive_i2c_devs));
+
+       pm_power_off = jive_power_off;
+
+       platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
+}
+
+MACHINE_START(JIVE, "JIVE")
+       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       .phys_io        = S3C2410_PA_UART,
+       .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
+       .boot_params    = S3C2410_SDRAM_PA + 0x100,
+
+       .init_irq       = s3c24xx_init_irq,
+       .map_io         = jive_map_io,
+       .init_machine   = jive_machine_init,
+       .timer          = &s3c24xx_timer,
+MACHINE_END
index f1915bd..25de042 100644 (file)
@@ -29,6 +29,7 @@ config MACH_ANUBIS
        bool "Simtec Electronics ANUBIS"
        select CPU_S3C2440
        select PM_SIMTEC if PM
+       select HAVE_PATA_PLATFORM
        help
          Say Y here if you are using the Simtec Electronics ANUBIS
          development system
@@ -67,6 +68,11 @@ config SMDK2440_CPU2440
        default y if ARCH_S3C2440
        select CPU_S3C2440
 
+config MACH_AT2440EVB
+       bool "Avantech AT2440EVB development board"
+       select CPU_S3C2440
+       help
+         Say Y here if you are using the AT2440EVB development board
 
 endmenu
 
index c81ed62..0b4440e 100644 (file)
@@ -21,3 +21,4 @@ obj-$(CONFIG_MACH_OSIRIS)     += mach-osiris.o
 obj-$(CONFIG_MACH_RX3715)      += mach-rx3715.o
 obj-$(CONFIG_ARCH_S3C2440)     += mach-smdk2440.o
 obj-$(CONFIG_MACH_NEXCODER_2440) += mach-nexcoder.o
+obj-$(CONFIG_MACH_AT2440EVB) += mach-at2440evb.o
index 4725891..09af8b2 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/mach-s3c2440/mach-anubis.c
  *
- * Copyright (c) 2003-2005 Simtec Electronics
+ * Copyright (c) 2003-2005,2008 Simtec Electronics
  *     http://armlinux.simtec.co.uk/
  *     Ben Dooks <ben@simtec.co.uk>
  *
@@ -17,6 +17,8 @@
 #include <linux/init.h>
 #include <linux/serial_core.h>
 #include <linux/platform_device.h>
+#include <linux/ata_platform.h>
+#include <linux/i2c.h>
 
 #include <linux/sm501.h>
 #include <linux/sm501-regs.h>
@@ -241,14 +243,18 @@ static struct s3c2410_platform_nand anubis_nand_info = {
 
 /* IDE channels */
 
+struct pata_platform_info anubis_ide_platdata = {
+       .ioport_shift   = 5,
+};
+
 static struct resource anubis_ide0_resource[] = {
        {
                .start  = S3C2410_CS3,
                .end    = S3C2410_CS3 + (8*32) - 1,
                .flags  = IORESOURCE_MEM,
        }, {
-               .start  = S3C2410_CS3 + (1<<26),
-               .end    = S3C2410_CS3 + (1<<26) + (8*32) - 1,
+               .start  = S3C2410_CS3 + (1<<26) + (6*32),
+               .end    = S3C2410_CS3 + (1<<26) + (7*32) - 1,
                .flags  = IORESOURCE_MEM,
        }, {
                .start  = IRQ_IDE0,
@@ -258,10 +264,14 @@ static struct resource anubis_ide0_resource[] = {
 };
 
 static struct platform_device anubis_device_ide0 = {
-       .name           = "simtec-ide",
+       .name           = "pata_platform",
        .id             = 0,
        .num_resources  = ARRAY_SIZE(anubis_ide0_resource),
        .resource       = anubis_ide0_resource,
+       .dev    = {
+               .platform_data = &anubis_ide_platdata,
+               .coherent_dma_mask = ~0,
+       },
 };
 
 static struct resource anubis_ide1_resource[] = {
@@ -270,8 +280,8 @@ static struct resource anubis_ide1_resource[] = {
                .end    = S3C2410_CS4 + (8*32) - 1,
                .flags  = IORESOURCE_MEM,
        }, {
-               .start  = S3C2410_CS4 + (1<<26),
-               .end    = S3C2410_CS4 + (1<<26) + (8*32) - 1,
+               .start  = S3C2410_CS4 + (1<<26) + (6*32),
+               .end    = S3C2410_CS4 + (1<<26) + (7*32) - 1,
                .flags  = IORESOURCE_MEM,
        }, {
                .start  = IRQ_IDE0,
@@ -280,12 +290,15 @@ static struct resource anubis_ide1_resource[] = {
        },
 };
 
-
 static struct platform_device anubis_device_ide1 = {
-       .name           = "simtec-ide",
+       .name           = "pata_platform",
        .id             = 1,
        .num_resources  = ARRAY_SIZE(anubis_ide1_resource),
        .resource       = anubis_ide1_resource,
+       .dev    = {
+               .platform_data = &anubis_ide_platdata,
+               .coherent_dma_mask = ~0,
+       },
 };
 
 /* Asix AX88796 10/100 ethernet controller */
@@ -409,6 +422,15 @@ static struct clk *anubis_clocks[] = {
        &s3c24xx_uclk,
 };
 
+/* I2C devices. */
+
+static struct i2c_board_info anubis_i2c_devs[] __initdata = {
+       {
+               I2C_BOARD_INFO("tps65011", 0x48),
+               .irq    = IRQ_EINT20,
+       }
+};
+
 static void __init anubis_map_io(void)
 {
        /* initialise the clocks */
@@ -448,6 +470,9 @@ static void __init anubis_map_io(void)
 static void __init anubis_init(void)
 {
        platform_add_devices(anubis_devices, ARRAY_SIZE(anubis_devices));
+
+       i2c_register_board_info(0, anubis_i2c_devs,
+                               ARRAY_SIZE(anubis_i2c_devs));
 }
 
 
diff --git a/arch/arm/mach-s3c2440/mach-at2440evb.c b/arch/arm/mach-s3c2440/mach-at2440evb.c
new file mode 100644 (file)
index 0000000..f5e3c7f
--- /dev/null
@@ -0,0 +1,198 @@
+/* linux/arch/arm/mach-s3c2440/mach-at2440evb.c
+ *
+ * Copyright (c) 2008 Ramax Lo <ramaxlo@gmail.com>
+ *      Based on mach-anubis.c by Ben Dooks <ben@simtec.co.uk>
+ *      and modifications by SBZ <sbz@spgui.org> and
+ *      Weibing <http://weibing.blogbus.com>
+ *
+ * For product information, visit http://www.arm9e.com/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/timer.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/serial_core.h>
+#include <linux/dm9000.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+#include <asm/mach-types.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
+#include <asm/arch/regs-mem.h>
+#include <asm/arch/regs-lcd.h>
+#include <asm/plat-s3c/nand.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/partitions.h>
+
+#include <asm/plat-s3c24xx/clock.h>
+#include <asm/plat-s3c24xx/devs.h>
+#include <asm/plat-s3c24xx/cpu.h>
+
+static struct map_desc at2440evb_iodesc[] __initdata = {
+       /* Nothing here */
+};
+
+#define UCON S3C2410_UCON_DEFAULT
+#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
+#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
+
+static struct s3c24xx_uart_clksrc at2440evb_serial_clocks[] = {
+       [0] = {
+               .name           = "uclk",
+               .divisor        = 1,
+               .min_baud       = 0,
+               .max_baud       = 0,
+       },
+       [1] = {
+               .name           = "pclk",
+               .divisor        = 1,
+               .min_baud       = 0,
+               .max_baud       = 0,
+       }
+};
+
+
+static struct s3c2410_uartcfg at2440evb_uartcfgs[] __initdata = {
+       [0] = {
+               .hwport      = 0,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+               .clocks      = at2440evb_serial_clocks,
+               .clocks_size = ARRAY_SIZE(at2440evb_serial_clocks),
+       },
+       [1] = {
+               .hwport      = 1,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+               .clocks      = at2440evb_serial_clocks,
+               .clocks_size = ARRAY_SIZE(at2440evb_serial_clocks),
+       },
+};
+
+/* NAND Flash on AT2440EVB board */
+
+static struct mtd_partition at2440evb_default_nand_part[] = {
+       [0] = {
+               .name   = "Boot Agent",
+               .size   = SZ_256K,
+               .offset = 0,
+       },
+       [1] = {
+               .name   = "Kernel",
+               .size   = SZ_2M,
+               .offset = SZ_256K,
+       },
+       [2] = {
+               .name   = "Root",
+               .offset = SZ_256K + SZ_2M,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct s3c2410_nand_set at2440evb_nand_sets[] = {
+       [0] = {
+               .name           = "nand",
+               .nr_chips       = 1,
+               .nr_partitions  = ARRAY_SIZE(at2440evb_default_nand_part),
+               .partitions     = at2440evb_default_nand_part,
+       },
+};
+
+static struct s3c2410_platform_nand at2440evb_nand_info = {
+       .tacls          = 25,
+       .twrph0         = 55,
+       .twrph1         = 40,
+       .nr_sets        = ARRAY_SIZE(at2440evb_nand_sets),
+       .sets           = at2440evb_nand_sets,
+};
+
+/* DM9000AEP 10/100 ethernet controller */
+
+static struct resource at2440evb_dm9k_resource[] = {
+       [0] = {
+               .start = S3C2410_CS3,
+               .end   = S3C2410_CS3 + 3,
+               .flags = IORESOURCE_MEM
+       },
+       [1] = {
+               .start = S3C2410_CS3 + 4,
+               .end   = S3C2410_CS3 + 7,
+               .flags = IORESOURCE_MEM
+       },
+       [2] = {
+               .start = IRQ_EINT7,
+               .end   = IRQ_EINT7,
+               .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
+       }
+};
+
+static struct dm9000_plat_data at2440evb_dm9k_pdata = {
+       .flags          = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
+};
+
+static struct platform_device at2440evb_device_eth = {
+       .name           = "dm9000",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(at2440evb_dm9k_resource),
+       .resource       = at2440evb_dm9k_resource,
+       .dev            = {
+               .platform_data  = &at2440evb_dm9k_pdata,
+       },
+};
+
+static struct platform_device *at2440evb_devices[] __initdata = {
+       &s3c_device_usb,
+       &s3c_device_wdt,
+       &s3c_device_adc,
+       &s3c_device_i2c,
+       &s3c_device_rtc,
+       &s3c_device_nand,
+       &at2440evb_device_eth,
+};
+
+static void __init at2440evb_map_io(void)
+{
+       s3c_device_nand.dev.platform_data = &at2440evb_nand_info;
+
+       s3c24xx_init_io(at2440evb_iodesc, ARRAY_SIZE(at2440evb_iodesc));
+       s3c24xx_init_clocks(16934400);
+       s3c24xx_init_uarts(at2440evb_uartcfgs, ARRAY_SIZE(at2440evb_uartcfgs));
+}
+
+static void __init at2440evb_init(void)
+{
+       platform_add_devices(at2440evb_devices, ARRAY_SIZE(at2440evb_devices));
+}
+
+
+MACHINE_START(AT2440EVB, "AT2440EVB")
+       .phys_io        = S3C2410_PA_UART,
+       .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
+       .boot_params    = S3C2410_SDRAM_PA + 0x100,
+       .map_io         = at2440evb_map_io,
+       .init_machine   = at2440evb_init,
+       .init_irq       = s3c24xx_init_irq,
+       .timer          = &s3c24xx_timer,
+MACHINE_END
index 8a8acdb..af996b0 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/mach-s3c2440/mach-osiris.c
  *
- * Copyright (c) 2005 Simtec Electronics
+ * Copyright (c) 2005,2008 Simtec Electronics
  *     http://armlinux.simtec.co.uk/
  *     Ben Dooks <ben@simtec.co.uk>
  *
@@ -19,6 +19,7 @@
 #include <linux/sysdev.h>
 #include <linux/serial_core.h>
 #include <linux/clk.h>
+#include <linux/i2c.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -322,6 +323,15 @@ static struct sys_device osiris_pm_sysdev = {
        .cls            = &osiris_pm_sysclass,
 };
 
+/* I2C devices fitted. */
+
+static struct i2c_board_info osiris_i2c_devs[] __initdata = {
+       {
+               I2C_BOARD_INFO("tps65011", 0x48),
+               .irq    = IRQ_EINT20,
+       },
+};
+
 /* Standard Osiris devices */
 
 static struct platform_device *osiris_devices[] __initdata = {
@@ -388,6 +398,9 @@ static void __init osiris_init(void)
        sysdev_class_register(&osiris_pm_sysclass);
        sysdev_register(&osiris_pm_sysdev);
 
+       i2c_register_board_info(0, osiris_i2c_devs,
+                               ARRAY_SIZE(osiris_i2c_devs));
+
        platform_add_devices(osiris_devices, ARRAY_SIZE(osiris_devices));
 };
 
index b42f956..17f064f 100644 (file)
@@ -81,7 +81,7 @@ static int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
        else
                clkcon &= ~clocks;
 
-       __raw_writel(clkcon, S3C2443_HCLKCON);
+       __raw_writel(clkcon, S3C2443_PCLKCON);
 
        return 0;
 }
@@ -221,7 +221,6 @@ static struct clk clk_mdivclk = {
        .get_rate       = s3c2443_getrate_mdivclk,
 };
 
-
 static int s3c2443_setparent_msysclk(struct clk *clk, struct clk *parent)
 {
        unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
@@ -249,6 +248,46 @@ static struct clk clk_msysclk = {
        .set_parent     = s3c2443_setparent_msysclk,
 };
 
+/* armdiv
+ *
+ * this clock is sourced from msysclk and can have a number of
+ * divider values applied to it to then be fed into armclk.
+*/
+
+static struct clk clk_armdiv = {
+       .name           = "armdiv",
+       .id             = -1,
+       .parent         = &clk_msysclk,
+};
+
+/* armclk
+ *
+ * this is the clock fed into the ARM core itself, either from
+ * armdiv or from hclk.
+ */
+
+static int s3c2443_setparent_armclk(struct clk *clk, struct clk *parent)
+{
+       unsigned long clkdiv0;
+
+       clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
+
+       if (parent == &clk_armdiv)
+               clkdiv0 &= ~S3C2443_CLKDIV0_DVS;
+       else if (parent == &clk_h)
+               clkdiv0 |= S3C2443_CLKDIV0_DVS;
+       else
+               return -EINVAL;
+
+       __raw_writel(clkdiv0, S3C2443_CLKDIV0);
+       return 0;
+}
+
+static struct clk clk_arm = {
+       .name           = "armclk",
+       .id             = -1,
+       .set_parent     = s3c2443_setparent_armclk,
+};
 
 /* esysclk
  *
@@ -639,6 +678,29 @@ static struct clk clk_display = {
        .round_rate     = s3c2443_roundrate_clksrc256,
 };
 
+/* prediv
+ *
+ * this divides the msysclk down to pass to h/p/etc.
+ */
+
+static unsigned long s3c2443_prediv_getrate(struct clk *clk)
+{
+       unsigned long rate = clk_get_rate(clk->parent);
+       unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
+
+       clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
+       clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
+
+       return rate / (clkdiv0 + 1);
+}
+
+static struct clk clk_prediv = {
+       .name           = "prediv",
+       .id             = -1,
+       .parent         = &clk_msysclk,
+       .get_rate       = s3c2443_prediv_getrate,
+};
+
 /* standard clock definitions */
 
 static struct clk init_clocks_disable[] = {
@@ -887,6 +949,15 @@ static void __init s3c2443_clk_initparents(void)
        }
 
        clk_init_set_parent(&clk_msysclk, parent);
+
+       /* arm */
+
+       if (__raw_readl(S3C2443_CLKDIV0) & S3C2443_CLKDIV0_DVS)
+               parent = &clk_h;
+       else
+               parent = &clk_armdiv;
+
+       clk_init_set_parent(&clk_arm, parent);
 }
 
 /* armdiv divisor table */
@@ -909,10 +980,9 @@ static inline unsigned int s3c2443_fclk_div(unsigned long clkcon0)
        return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
 }
 
-static inline unsigned long s3c2443_get_prediv(unsigned long clkcon0)
+static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
 {
-       clkcon0 &= S3C2443_CLKDIV0_PREDIV_MASK;
-       clkcon0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
+       clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
 
        return clkcon0 + 1;
 }
@@ -936,6 +1006,9 @@ static struct clk *clks[] __initdata = {
        &clk_hsspi,
        &clk_hsmmc_div,
        &clk_hsmmc,
+       &clk_armdiv,
+       &clk_arm,
+       &clk_prediv,
 };
 
 void __init s3c2443_init_clocks(int xtal)
@@ -951,10 +1024,16 @@ void __init s3c2443_init_clocks(int xtal)
        int ret;
        int ptr;
 
+       /* s3c2443 parents h and p clocks from prediv */
+       clk_h.parent = &clk_prediv;
+       clk_p.parent = &clk_prediv;
+
        pll = s3c2443_get_mpll(mpllcon, xtal);
+       clk_msysclk.rate = pll;
 
        fclk = pll / s3c2443_fclk_div(clkdiv0);
-       hclk = fclk / s3c2443_get_prediv(clkdiv0);
+       hclk = s3c2443_prediv_getrate(&clk_prediv);
+       hclk = hclk / s3c2443_get_hdiv(clkdiv0);
        hclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_HCLK) ? 2 : 1);
        pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
 
index 33ed048..3a6c8ec 100644 (file)
@@ -180,8 +180,21 @@ config CPU_ARM925T
 # ARM926T
 config CPU_ARM926T
        bool "Support ARM926T processor"
-       depends on ARCH_INTEGRATOR || ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX || MACH_REALVIEW_EB || ARCH_PNX4008 || ARCH_NETX || CPU_S3C2412 || ARCH_AT91SAM9260 || ARCH_AT91SAM9261 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9 || ARCH_NS9XXX || ARCH_DAVINCI
-       default y if ARCH_VERSATILE_PB || MACH_VERSATILE_AB || ARCH_OMAP730 || ARCH_OMAP16XX || ARCH_PNX4008 || ARCH_NETX || CPU_S3C2412 || ARCH_AT91SAM9260 || ARCH_AT91SAM9261 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9 || ARCH_NS9XXX || ARCH_DAVINCI
+       depends on ARCH_INTEGRATOR || ARCH_VERSATILE_PB || \
+               MACH_VERSATILE_AB || ARCH_OMAP730 || \
+               ARCH_OMAP16XX || MACH_REALVIEW_EB || \
+               ARCH_PNX4008 || ARCH_NETX || CPU_S3C2412 || \
+               ARCH_AT91SAM9260 || ARCH_AT91SAM9261 || \
+               ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || \
+               ARCH_AT91SAM9G20 || ARCH_AT91CAP9 || \
+               ARCH_NS9XXX || ARCH_DAVINCI
+       default y if ARCH_VERSATILE_PB || MACH_VERSATILE_AB || \
+               ARCH_OMAP730 || ARCH_OMAP16XX || \
+               ARCH_PNX4008 || ARCH_NETX || CPU_S3C2412 || \
+               ARCH_AT91SAM9260 || ARCH_AT91SAM9261 || \
+               ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || \
+               ARCH_AT91SAM9G20 || ARCH_AT91CAP9 || \
+               ARCH_NS9XXX || ARCH_DAVINCI || ARCH_MX2
        select CPU_32v5
        select CPU_ABRT_EV5TJ
        select CPU_PABRT_NOIFAR
@@ -365,7 +378,7 @@ config CPU_XSC3
 # Feroceon
 config CPU_FEROCEON
        bool
-       depends on ARCH_ORION5X
+       depends on ARCH_ORION5X || ARCH_LOKI || ARCH_KIRKWOOD || ARCH_MV78XX0
        default y
        select CPU_32v5
        select CPU_ABRT_EV5T
@@ -373,7 +386,7 @@ config CPU_FEROCEON
        select CPU_CACHE_VIVT
        select CPU_CP15_MMU
        select CPU_COPY_FEROCEON if MMU
-       select CPU_TLB_V4WBI if MMU
+       select CPU_TLB_FEROCEON if MMU
 
 config CPU_FEROCEON_OLD_ID
        bool "Accept early Feroceon cores with an ARM926 ID"
@@ -551,6 +564,11 @@ config CPU_TLB_V4WBI
          ARM Architecture Version 4 TLB with writeback cache and invalidate
          instruction cache entry.
 
+config CPU_TLB_FEROCEON
+       bool
+       help
+         Feroceon TLB (v4wbi with non-outer-cachable page table walks).
+
 config CPU_TLB_V6
        bool
 
@@ -709,6 +727,14 @@ config OUTER_CACHE
        bool
        default n
 
+config CACHE_FEROCEON_L2
+       bool "Enable the Feroceon L2 cache controller"
+       depends on ARCH_KIRKWOOD || ARCH_MV78XX0
+       default y
+       select OUTER_CACHE
+       help
+         This option enables the Feroceon L2 cache controller.
+
 config CACHE_L2X0
        bool "Enable the L2x0 outer cache controller"
        depends on REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || MACH_REALVIEW_PB1176
index 32b2d2d..f64b925 100644 (file)
@@ -46,6 +46,7 @@ obj-$(CONFIG_CPU_TLB_V3)      += tlb-v3.o
 obj-$(CONFIG_CPU_TLB_V4WT)     += tlb-v4.o
 obj-$(CONFIG_CPU_TLB_V4WB)     += tlb-v4wb.o
 obj-$(CONFIG_CPU_TLB_V4WBI)    += tlb-v4wbi.o
+obj-$(CONFIG_CPU_TLB_FEROCEON) += tlb-v4wbi.o  # reuse v4wbi TLB functions
 obj-$(CONFIG_CPU_TLB_V6)       += tlb-v6.o
 obj-$(CONFIG_CPU_TLB_V7)       += tlb-v7.o
 
@@ -73,4 +74,5 @@ obj-$(CONFIG_CPU_FEROCEON)    += proc-feroceon.o
 obj-$(CONFIG_CPU_V6)           += proc-v6.o
 obj-$(CONFIG_CPU_V7)           += proc-v7.o
 
+obj-$(CONFIG_CACHE_FEROCEON_L2)        += cache-feroceon-l2.o
 obj-$(CONFIG_CACHE_L2X0)       += cache-l2x0.o
diff --git a/arch/arm/mm/cache-feroceon-l2.c b/arch/arm/mm/cache-feroceon-l2.c
new file mode 100644 (file)
index 0000000..20eec4b
--- /dev/null
@@ -0,0 +1,318 @@
+/*
+ * arch/arm/mm/cache-feroceon-l2.c - Feroceon L2 cache controller support
+ *
+ * Copyright (C) 2008 Marvell Semiconductor
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * References:
+ * - Unified Layer 2 Cache for Feroceon CPU Cores,
+ *   Document ID MV-S104858-00, Rev. A, October 23 2007.
+ */
+
+#include <linux/init.h>
+#include <asm/cacheflush.h>
+#include <asm/plat-orion/cache-feroceon-l2.h>
+
+
+/*
+ * Low-level cache maintenance operations.
+ *
+ * As well as the regular 'clean/invalidate/flush L2 cache line by
+ * MVA' instructions, the Feroceon L2 cache controller also features
+ * 'clean/invalidate L2 range by MVA' operations.
+ *
+ * Cache range operations are initiated by writing the start and
+ * end addresses to successive cp15 registers, and process every
+ * cache line whose first byte address lies in the inclusive range
+ * [start:end].
+ *
+ * The cache range operations stall the CPU pipeline until completion.
+ *
+ * The range operations require two successive cp15 writes, in
+ * between which we don't want to be preempted.
+ */
+static inline void l2_clean_pa(unsigned long addr)
+{
+       __asm__("mcr p15, 1, %0, c15, c9, 3" : : "r" (addr));
+}
+
+static inline void l2_clean_mva_range(unsigned long start, unsigned long end)
+{
+       unsigned long flags;
+
+       /*
+        * Make sure 'start' and 'end' reference the same page, as
+        * L2 is PIPT and range operations only do a TLB lookup on
+        * the start address.
+        */
+       BUG_ON((start ^ end) & ~(PAGE_SIZE - 1));
+
+       raw_local_irq_save(flags);
+       __asm__("mcr p15, 1, %0, c15, c9, 4" : : "r" (start));
+       __asm__("mcr p15, 1, %0, c15, c9, 5" : : "r" (end));
+       raw_local_irq_restore(flags);
+}
+
+static inline void l2_clean_pa_range(unsigned long start, unsigned long end)
+{
+       l2_clean_mva_range(__phys_to_virt(start), __phys_to_virt(end));
+}
+
+static inline void l2_clean_inv_pa(unsigned long addr)
+{
+       __asm__("mcr p15, 1, %0, c15, c10, 3" : : "r" (addr));
+}
+
+static inline void l2_inv_pa(unsigned long addr)
+{
+       __asm__("mcr p15, 1, %0, c15, c11, 3" : : "r" (addr));
+}
+
+static inline void l2_inv_mva_range(unsigned long start, unsigned long end)
+{
+       unsigned long flags;
+
+       /*
+        * Make sure 'start' and 'end' reference the same page, as
+        * L2 is PIPT and range operations only do a TLB lookup on
+        * the start address.
+        */
+       BUG_ON((start ^ end) & ~(PAGE_SIZE - 1));
+
+       raw_local_irq_save(flags);
+       __asm__("mcr p15, 1, %0, c15, c11, 4" : : "r" (start));
+       __asm__("mcr p15, 1, %0, c15, c11, 5" : : "r" (end));
+       raw_local_irq_restore(flags);
+}
+
+static inline void l2_inv_pa_range(unsigned long start, unsigned long end)
+{
+       l2_inv_mva_range(__phys_to_virt(start), __phys_to_virt(end));
+}
+
+
+/*
+ * Linux primitives.
+ *
+ * Note that the end addresses passed to Linux primitives are
+ * noninclusive, while the hardware cache range operations use
+ * inclusive start and end addresses.
+ */
+#define CACHE_LINE_SIZE                32
+#define MAX_RANGE_SIZE         1024
+
+static int l2_wt_override;
+
+static unsigned long calc_range_end(unsigned long start, unsigned long end)
+{
+       unsigned long range_end;
+
+       BUG_ON(start & (CACHE_LINE_SIZE - 1));
+       BUG_ON(end & (CACHE_LINE_SIZE - 1));
+
+       /*
+        * Try to process all cache lines between 'start' and 'end'.
+        */
+       range_end = end;
+
+       /*
+        * Limit the number of cache lines processed at once,
+        * since cache range operations stall the CPU pipeline
+        * until completion.
+        */
+       if (range_end > start + MAX_RANGE_SIZE)
+               range_end = start + MAX_RANGE_SIZE;
+
+       /*
+        * Cache range operations can't straddle a page boundary.
+        */
+       if (range_end > (start | (PAGE_SIZE - 1)) + 1)
+               range_end = (start | (PAGE_SIZE - 1)) + 1;
+
+       return range_end;
+}
+
+static void feroceon_l2_inv_range(unsigned long start, unsigned long end)
+{
+       /*
+        * Clean and invalidate partial first cache line.
+        */
+       if (start & (CACHE_LINE_SIZE - 1)) {
+               l2_clean_inv_pa(start & ~(CACHE_LINE_SIZE - 1));
+               start = (start | (CACHE_LINE_SIZE - 1)) + 1;
+       }
+
+       /*
+        * Clean and invalidate partial last cache line.
+        */
+       if (end & (CACHE_LINE_SIZE - 1)) {
+               l2_clean_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
+               end &= ~(CACHE_LINE_SIZE - 1);
+       }
+
+       /*
+        * Invalidate all full cache lines between 'start' and 'end'.
+        */
+       while (start != end) {
+               unsigned long range_end = calc_range_end(start, end);
+               l2_inv_pa_range(start, range_end - CACHE_LINE_SIZE);
+               start = range_end;
+       }
+
+       dsb();
+}
+
+static void feroceon_l2_clean_range(unsigned long start, unsigned long end)
+{
+       /*
+        * If L2 is forced to WT, the L2 will always be clean and we
+        * don't need to do anything here.
+        */
+       if (!l2_wt_override) {
+               start &= ~(CACHE_LINE_SIZE - 1);
+               end = (end + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1);
+               while (start != end) {
+                       unsigned long range_end = calc_range_end(start, end);
+                       l2_clean_pa_range(start, range_end - CACHE_LINE_SIZE);
+                       start = range_end;
+               }
+       }
+
+       dsb();
+}
+
+static void feroceon_l2_flush_range(unsigned long start, unsigned long end)
+{
+       start &= ~(CACHE_LINE_SIZE - 1);
+       end = (end + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1);
+       while (start != end) {
+               unsigned long range_end = calc_range_end(start, end);
+               if (!l2_wt_override)
+                       l2_clean_pa_range(start, range_end - CACHE_LINE_SIZE);
+               l2_inv_pa_range(start, range_end - CACHE_LINE_SIZE);
+               start = range_end;
+       }
+
+       dsb();
+}
+
+
+/*
+ * Routines to disable and re-enable the D-cache and I-cache at run
+ * time.  These are necessary because the L2 cache can only be enabled
+ * or disabled while the L1 Dcache and Icache are both disabled.
+ */
+static void __init invalidate_and_disable_dcache(void)
+{
+       u32 cr;
+
+       cr = get_cr();
+       if (cr & CR_C) {
+               unsigned long flags;
+
+               raw_local_irq_save(flags);
+               flush_cache_all();
+               set_cr(cr & ~CR_C);
+               raw_local_irq_restore(flags);
+       }
+}
+
+static void __init enable_dcache(void)
+{
+       u32 cr;
+
+       cr = get_cr();
+       if (!(cr & CR_C))
+               set_cr(cr | CR_C);
+}
+
+static void __init __invalidate_icache(void)
+{
+       int dummy;
+
+       __asm__ __volatile__("mcr p15, 0, %0, c7, c5, 0\n" : "=r" (dummy));
+}
+
+static void __init invalidate_and_disable_icache(void)
+{
+       u32 cr;
+
+       cr = get_cr();
+       if (cr & CR_I) {
+               set_cr(cr & ~CR_I);
+               __invalidate_icache();
+       }
+}
+
+static void __init enable_icache(void)
+{
+       u32 cr;
+
+       cr = get_cr();
+       if (!(cr & CR_I))
+               set_cr(cr | CR_I);
+}
+
+static inline u32 read_extra_features(void)
+{
+       u32 u;
+
+       __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (u));
+
+       return u;
+}
+
+static inline void write_extra_features(u32 u)
+{
+       __asm__("mcr p15, 1, %0, c15, c1, 0" : : "r" (u));
+}
+
+static void __init disable_l2_prefetch(void)
+{
+       u32 u;
+
+       /*
+        * Read the CPU Extra Features register and verify that the
+        * Disable L2 Prefetch bit is set.
+        */
+       u = read_extra_features();
+       if (!(u & 0x01000000)) {
+               printk(KERN_INFO "Feroceon L2: Disabling L2 prefetch.\n");
+               write_extra_features(u | 0x01000000);
+       }
+}
+
+static void __init enable_l2(void)
+{
+       u32 u;
+
+       u = read_extra_features();
+       if (!(u & 0x00400000)) {
+               printk(KERN_INFO "Feroceon L2: Enabling L2\n");
+
+               invalidate_and_disable_dcache();
+               invalidate_and_disable_icache();
+               write_extra_features(u | 0x00400000);
+               enable_icache();
+               enable_dcache();
+       }
+}
+
+void __init feroceon_l2_init(int __l2_wt_override)
+{
+       l2_wt_override = __l2_wt_override;
+
+       disable_l2_prefetch();
+
+       outer_cache.inv_range = feroceon_l2_inv_range;
+       outer_cache.clean_range = feroceon_l2_clean_range;
+       outer_cache.flush_range = feroceon_l2_flush_range;
+
+       enable_l2();
+
+       printk(KERN_INFO "Feroceon L2: Cache support initialised%s.\n",
+                        l2_wt_override ? ", in WT override mode" : "");
+}
index 44558d5..fbfa260 100644 (file)
@@ -144,13 +144,17 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
        page = pfn_to_page(pfn);
        mapping = page_mapping(page);
        if (mapping) {
+#ifndef CONFIG_SMP
                int dirty = test_and_clear_bit(PG_dcache_dirty, &page->flags);
 
                if (dirty)
                        __flush_dcache_page(mapping, page);
+#endif
 
                if (cache_is_vivt())
                        make_coherent(mapping, vma, addr, pfn);
+               else if (vma->vm_flags & VM_EXEC)
+                       __flush_icache_all();
        }
 }
 
index 9df507d..029ee65 100644 (file)
@@ -199,6 +199,8 @@ void flush_dcache_page(struct page *page)
                __flush_dcache_page(mapping, page);
                if (mapping && cache_is_vivt())
                        __flush_dcache_aliases(mapping, page);
+               else if (mapping)
+                       __flush_icache_all();
        }
 }
 EXPORT_SYMBOL(flush_dcache_page);
index a02c171..f2e5884 100644 (file)
  */
 #define CACHE_DLINESIZE        32
 
+       .bss
+       .align 3
+__cache_params_loc:
+       .space  8
+
        .text
+__cache_params:
+       .word   __cache_params_loc
+
 /*
  * cpu_feroceon_proc_init()
  */
 ENTRY(cpu_feroceon_proc_init)
+       mrc     p15, 0, r0, c0, c0, 1           @ read cache type register
+       ldr     r1, __cache_params
+       mov     r2, #(16 << 5)
+       tst     r0, #(1 << 16)                  @ get way
+       mov     r0, r0, lsr #18                 @ get cache size order
+       movne   r3, #((4 - 1) << 30)            @ 4-way
+       and     r0, r0, #0xf
+       moveq   r3, #0                          @ 1-way
+       mov     r2, r2, lsl r0                  @ actual cache size
+       movne   r2, r2, lsr #2                  @ turned into # of sets
+       sub     r2, r2, #(1 << 5)
+       stmia   r1, {r2, r3}
        mov     pc, lr
 
 /*
@@ -59,6 +79,13 @@ ENTRY(cpu_feroceon_proc_fin)
        mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
        msr     cpsr_c, ip
        bl      feroceon_flush_kern_cache_all
+
+#if defined(CONFIG_CACHE_FEROCEON_L2) && !defined(CONFIG_L2_CACHE_WRITETHROUGH)
+       mov     r0, #0
+       mcr     p15, 1, r0, c15, c9, 0          @ clean L2
+       mcr     p15, 0, r0, c7, c10, 4          @ drain WB
+#endif
+
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
@@ -117,11 +144,19 @@ ENTRY(feroceon_flush_user_cache_all)
  */
 ENTRY(feroceon_flush_kern_cache_all)
        mov     r2, #VM_EXEC
-       mov     ip, #0
+
 __flush_whole_cache:
-1:     mrc     p15, 0, r15, c7, c14, 3         @ test,clean,invalidate
-       bne     1b
+       ldr     r1, __cache_params
+       ldmia   r1, {r1, r3}
+1:     orr     ip, r1, r3
+2:     mcr     p15, 0, ip, c7, c14, 2          @ clean + invalidate D set/way
+       subs    ip, ip, #(1 << 30)              @ next way
+       bcs     2b
+       subs    r1, r1, #(1 << 5)               @ next set
+       bcs     1b
+
        tst     r2, #VM_EXEC
+       mov     ip, #0
        mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
        mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
        mov     pc, lr
@@ -138,7 +173,6 @@ __flush_whole_cache:
  */
        .align  5
 ENTRY(feroceon_flush_user_cache_range)
-       mov     ip, #0
        sub     r3, r1, r0                      @ calculate total size
        cmp     r3, #CACHE_DLIMIT
        bgt     __flush_whole_cache
@@ -152,6 +186,7 @@ ENTRY(feroceon_flush_user_cache_range)
        cmp     r0, r1
        blo     1b
        tst     r2, #VM_EXEC
+       mov     ip, #0
        mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
        mov     pc, lr
 
@@ -209,6 +244,20 @@ ENTRY(feroceon_flush_kern_dcache_page)
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
        mov     pc, lr
 
+       .align  5
+ENTRY(feroceon_range_flush_kern_dcache_page)
+       mrs     r2, cpsr
+       add     r1, r0, #PAGE_SZ - CACHE_DLINESIZE      @ top addr is inclusive
+       orr     r3, r2, #PSR_I_BIT
+       msr     cpsr_c, r3                      @ disable interrupts
+       mcr     p15, 5, r0, c15, c15, 0         @ D clean/inv range start
+       mcr     p15, 5, r1, c15, c15, 1         @ D clean/inv range top
+       msr     cpsr_c, r2                      @ restore interrupts
+       mov     r0, #0
+       mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
+       mcr     p15, 0, r0, c7, c10, 4          @ drain WB
+       mov     pc, lr
+
 /*
  *     dma_inv_range(start, end)
  *
@@ -225,10 +274,10 @@ ENTRY(feroceon_flush_kern_dcache_page)
        .align  5
 ENTRY(feroceon_dma_inv_range)
        tst     r0, #CACHE_DLINESIZE - 1
+       bic     r0, r0, #CACHE_DLINESIZE - 1
        mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
        tst     r1, #CACHE_DLINESIZE - 1
        mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
-       bic     r0, r0, #CACHE_DLINESIZE - 1
 1:     mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
        add     r0, r0, #CACHE_DLINESIZE
        cmp     r0, r1
@@ -236,6 +285,22 @@ ENTRY(feroceon_dma_inv_range)
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
        mov     pc, lr
 
+       .align  5
+ENTRY(feroceon_range_dma_inv_range)
+       mrs     r2, cpsr
+       tst     r0, #CACHE_DLINESIZE - 1
+       mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
+       tst     r1, #CACHE_DLINESIZE - 1
+       mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
+       cmp     r1, r0
+       subne   r1, r1, #1                      @ top address is inclusive
+       orr     r3, r2, #PSR_I_BIT
+       msr     cpsr_c, r3                      @ disable interrupts
+       mcr     p15, 5, r0, c15, c14, 0         @ D inv range start
+       mcr     p15, 5, r1, c15, c14, 1         @ D inv range top
+       msr     cpsr_c, r2                      @ restore interrupts
+       mov     pc, lr
+
 /*
  *     dma_clean_range(start, end)
  *
@@ -256,6 +321,19 @@ ENTRY(feroceon_dma_clean_range)
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
        mov     pc, lr
 
+       .align  5
+ENTRY(feroceon_range_dma_clean_range)
+       mrs     r2, cpsr
+       cmp     r1, r0
+       subne   r1, r1, #1                      @ top address is inclusive
+       orr     r3, r2, #PSR_I_BIT
+       msr     cpsr_c, r3                      @ disable interrupts
+       mcr     p15, 5, r0, c15, c13, 0         @ D clean range start
+       mcr     p15, 5, r1, c15, c13, 1         @ D clean range top
+       msr     cpsr_c, r2                      @ restore interrupts
+       mcr     p15, 0, r0, c7, c10, 4          @ drain WB
+       mov     pc, lr
+
 /*
  *     dma_flush_range(start, end)
  *
@@ -274,6 +352,19 @@ ENTRY(feroceon_dma_flush_range)
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
        mov     pc, lr
 
+       .align  5
+ENTRY(feroceon_range_dma_flush_range)
+       mrs     r2, cpsr
+       cmp     r1, r0
+       subne   r1, r1, #1                      @ top address is inclusive
+       orr     r3, r2, #PSR_I_BIT
+       msr     cpsr_c, r3                      @ disable interrupts
+       mcr     p15, 5, r0, c15, c15, 0         @ D clean/inv range start
+       mcr     p15, 5, r1, c15, c15, 1         @ D clean/inv range top
+       msr     cpsr_c, r2                      @ restore interrupts
+       mcr     p15, 0, r0, c7, c10, 4          @ drain WB
+       mov     pc, lr
+
 ENTRY(feroceon_cache_fns)
        .long   feroceon_flush_kern_cache_all
        .long   feroceon_flush_user_cache_all
@@ -285,12 +376,33 @@ ENTRY(feroceon_cache_fns)
        .long   feroceon_dma_clean_range
        .long   feroceon_dma_flush_range
 
+ENTRY(feroceon_range_cache_fns)
+       .long   feroceon_flush_kern_cache_all
+       .long   feroceon_flush_user_cache_all
+       .long   feroceon_flush_user_cache_range
+       .long   feroceon_coherent_kern_range
+       .long   feroceon_coherent_user_range
+       .long   feroceon_range_flush_kern_dcache_page
+       .long   feroceon_range_dma_inv_range
+       .long   feroceon_range_dma_clean_range
+       .long   feroceon_range_dma_flush_range
+
        .align  5
 ENTRY(cpu_feroceon_dcache_clean_area)
+#if defined(CONFIG_CACHE_FEROCEON_L2) && !defined(CONFIG_L2_CACHE_WRITETHROUGH)
+       mov     r2, r0
+       mov     r3, r1
+#endif
 1:     mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
        add     r0, r0, #CACHE_DLINESIZE
        subs    r1, r1, #CACHE_DLINESIZE
        bhi     1b
+#if defined(CONFIG_CACHE_FEROCEON_L2) && !defined(CONFIG_L2_CACHE_WRITETHROUGH)
+1:     mcr     p15, 1, r2, c15, c9, 1          @ clean L2 entry
+       add     r2, r2, #CACHE_DLINESIZE
+       subs    r3, r3, #CACHE_DLINESIZE
+       bhi     1b
+#endif
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
        mov     pc, lr
 
@@ -306,16 +418,25 @@ ENTRY(cpu_feroceon_dcache_clean_area)
        .align  5
 ENTRY(cpu_feroceon_switch_mm)
 #ifdef CONFIG_MMU
-       mov     ip, #0
-@ && 'Clean & Invalidate whole DCache'
-1:     mrc     p15, 0, r15, c7, c14, 3         @ test,clean,invalidate
-       bne     1b
-       mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
-       mcr     p15, 0, ip, c7, c10, 4          @ drain WB
+       /*
+        * Note: we wish to call __flush_whole_cache but we need to preserve
+        * lr to do so.  The only way without touching main memory is to
+        * use r2 which is normally used to test the VM_EXEC flag, and
+        * compensate locally for the skipped ops if it is not set.
+        */
+       mov     r2, lr                          @ abuse r2 to preserve lr
+       bl      __flush_whole_cache
+       @ if r2 contains the VM_EXEC bit then the next 2 ops are done already
+       tst     r2, #VM_EXEC
+       mcreq   p15, 0, ip, c7, c5, 0           @ invalidate I cache
+       mcreq   p15, 0, ip, c7, c10, 4          @ drain WB
+
        mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
        mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
-#endif
+       mov     pc, r2
+#else
        mov     pc, lr
+#endif
 
 /*
  * cpu_feroceon_set_pte_ext(ptep, pte, ext)
@@ -345,6 +466,9 @@ ENTRY(cpu_feroceon_set_pte_ext)
        str     r2, [r0]                        @ hardware version
        mov     r0, r0
        mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
+#if defined(CONFIG_CACHE_FEROCEON_L2) && !defined(CONFIG_L2_CACHE_WRITETHROUGH)
+       mcr     p15, 1, r0, c15, c9, 1          @ clean L2 entry
+#endif
        mcr     p15, 0, r0, c7, c10, 4          @ drain WB
 #endif
        mov     pc, lr
@@ -369,14 +493,15 @@ __feroceon_setup:
        .size   __feroceon_setup, . - __feroceon_setup
 
        /*
-        *  R
-        * .RVI ZFRS BLDP WCAM
-        * .011 0001 ..11 0101
+        *      B
+        *  R   P
+        * .RVI UFRS BLDP WCAM
+        * .011 .001 ..11 0101
         *
         */
        .type   feroceon_crval, #object
 feroceon_crval:
-       crval   clear=0x00007f3f, mmuset=0x00003135, ucset=0x00001134
+       crval   clear=0x0000773f, mmuset=0x00003135, ucset=0x00001134
 
        __INITDATA
 
@@ -414,6 +539,21 @@ cpu_feroceon_name:
        .asciz  "Feroceon"
        .size   cpu_feroceon_name, . - cpu_feroceon_name
 
+       .type   cpu_88fr531_name, #object
+cpu_88fr531_name:
+       .asciz  "Feroceon 88FR531-vd"
+       .size   cpu_88fr531_name, . - cpu_88fr531_name
+
+       .type   cpu_88fr571_name, #object
+cpu_88fr571_name:
+       .asciz  "Feroceon 88FR571-vd"
+       .size   cpu_88fr571_name, . - cpu_88fr571_name
+
+       .type   cpu_88fr131_name, #object
+cpu_88fr131_name:
+       .asciz  "Feroceon 88FR131"
+       .size   cpu_88fr131_name, . - cpu_88fr131_name
+
        .align
 
        .section ".proc.info.init", #alloc, #execinstr
@@ -421,15 +561,15 @@ cpu_feroceon_name:
 #ifdef CONFIG_CPU_FEROCEON_OLD_ID
        .type   __feroceon_old_id_proc_info,#object
 __feroceon_old_id_proc_info:
-       .long   0x41069260
-       .long   0xfffffff0
-       .long   PMD_TYPE_SECT | \
+       .long   0x41009260
+       .long   0xff00fff0
+       .long   PMD_TYPE_SECT | \
                PMD_SECT_BUFFERABLE | \
                PMD_SECT_CACHEABLE | \
                PMD_BIT4 | \
                PMD_SECT_AP_WRITE | \
                PMD_SECT_AP_READ
-       .long   PMD_TYPE_SECT | \
+       .long   PMD_TYPE_SECT | \
                PMD_BIT4 | \
                PMD_SECT_AP_WRITE | \
                PMD_SECT_AP_READ
@@ -445,17 +585,17 @@ __feroceon_old_id_proc_info:
        .size   __feroceon_old_id_proc_info, . - __feroceon_old_id_proc_info
 #endif
 
-       .type   __feroceon_proc_info,#object
-__feroceon_proc_info:
+       .type   __88fr531_proc_info,#object
+__88fr531_proc_info:
        .long   0x56055310
        .long   0xfffffff0
-       .long   PMD_TYPE_SECT | \
+       .long   PMD_TYPE_SECT | \
                PMD_SECT_BUFFERABLE | \
                PMD_SECT_CACHEABLE | \
                PMD_BIT4 | \
                PMD_SECT_AP_WRITE | \
                PMD_SECT_AP_READ
-       .long   PMD_TYPE_SECT | \
+       .long   PMD_TYPE_SECT | \
                PMD_BIT4 | \
                PMD_SECT_AP_WRITE | \
                PMD_SECT_AP_READ
@@ -463,9 +603,59 @@ __feroceon_proc_info:
        .long   cpu_arch_name
        .long   cpu_elf_name
        .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
-       .long   cpu_feroceon_name
+       .long   cpu_88fr531_name
        .long   feroceon_processor_functions
        .long   v4wbi_tlb_fns
        .long   feroceon_user_fns
        .long   feroceon_cache_fns
-       .size   __feroceon_proc_info, . - __feroceon_proc_info
+       .size   __88fr531_proc_info, . - __88fr531_proc_info
+
+       .type   __88fr571_proc_info,#object
+__88fr571_proc_info:
+       .long   0x56155710
+       .long   0xfffffff0
+       .long   PMD_TYPE_SECT | \
+               PMD_SECT_BUFFERABLE | \
+               PMD_SECT_CACHEABLE | \
+               PMD_BIT4 | \
+               PMD_SECT_AP_WRITE | \
+               PMD_SECT_AP_READ
+       .long   PMD_TYPE_SECT | \
+               PMD_BIT4 | \
+               PMD_SECT_AP_WRITE | \
+               PMD_SECT_AP_READ
+       b       __feroceon_setup
+       .long   cpu_arch_name
+       .long   cpu_elf_name
+       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+       .long   cpu_88fr571_name
+       .long   feroceon_processor_functions
+       .long   v4wbi_tlb_fns
+       .long   feroceon_user_fns
+       .long   feroceon_range_cache_fns
+       .size   __88fr571_proc_info, . - __88fr571_proc_info
+
+       .type   __88fr131_proc_info,#object
+__88fr131_proc_info:
+       .long   0x56251310
+       .long   0xfffffff0
+       .long   PMD_TYPE_SECT | \
+               PMD_SECT_BUFFERABLE | \
+               PMD_SECT_CACHEABLE | \
+               PMD_BIT4 | \
+               PMD_SECT_AP_WRITE | \
+               PMD_SECT_AP_READ
+       .long   PMD_TYPE_SECT | \
+               PMD_BIT4 | \
+               PMD_SECT_AP_WRITE | \
+               PMD_SECT_AP_READ
+       b       __feroceon_setup
+       .long   cpu_arch_name
+       .long   cpu_elf_name
+       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+       .long   cpu_88fr131_name
+       .long   feroceon_processor_functions
+       .long   v4wbi_tlb_fns
+       .long   feroceon_user_fns
+       .long   feroceon_range_cache_fns
+       .size   __88fr131_proc_info, . - __88fr131_proc_info
index eda4360..640e498 100644 (file)
  */
 
 #include <linux/device.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/gpio.h>
 #include <asm/hardware/iop3xx.h>
 
 void gpio_line_config(int line, int direction)
@@ -46,3 +50,42 @@ void gpio_line_set(int line, int value)
        local_irq_restore(flags);
 }
 EXPORT_SYMBOL(gpio_line_set);
+
+static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+       gpio_line_config(gpio, GPIO_IN);
+       return 0;
+}
+
+static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
+{
+       gpio_line_set(gpio, level);
+       gpio_line_config(gpio, GPIO_OUT);
+       return 0;
+}
+
+static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+       return gpio_line_get(gpio);
+}
+
+static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
+{
+       gpio_line_set(gpio, value);
+}
+
+static struct gpio_chip iop3xx_chip = {
+       .label                  = "iop3xx",
+       .direction_input        = iop3xx_gpio_direction_input,
+       .get                    = iop3xx_gpio_get_value,
+       .direction_output       = iop3xx_gpio_direction_output,
+       .set                    = iop3xx_gpio_set_value,
+       .base                   = 0,
+       .ngpio                  = IOP3XX_N_GPIOS,
+};
+
+static int __init iop3xx_gpio_setup(void)
+{
+       return gpiochip_add(&iop3xx_chip);
+}
+arch_initcall(iop3xx_gpio_setup);
index bb6e127..e14eaad 100644 (file)
@@ -3,9 +3,14 @@ if ARCH_MXC
 menu "Freescale MXC Implementations"
 
 choice
-       prompt "MXC/iMX System Type"
+       prompt "MXC/iMX Base Type"
        default ARCH_MX3
 
+config ARCH_MX2
+       bool "MX2-based"
+       help
+         This enables support for systems based on the Freescale i.MX2 family
+
 config ARCH_MX3
        bool "MX3-based"
        help
@@ -13,6 +18,7 @@ config ARCH_MX3
 
 endchoice
 
+source "arch/arm/mach-mx2/Kconfig"
 source "arch/arm/mach-mx3/Kconfig"
 
 endmenu
index f96dc03..db66e9a 100644 (file)
@@ -3,4 +3,6 @@
 #
 
 # Common support
-obj-y := irq.o
+obj-y := irq.o clock.o gpio.o time.o
+
+obj-$(CONFIG_ARCH_MX2) += iomux-mx1-mx2.o
diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
new file mode 100644 (file)
index 0000000..1aa86fd
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+ * Based on arch/arm/plat-omap/clock.c
+ *
+ * Copyright (C) 2004 - 2005 Nokia corporation
+ * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
+ * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
+ * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+/* #define DEBUG */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/proc_fs.h>
+#include <linux/semaphore.h>
+#include <linux/string.h>
+#include <linux/version.h>
+
+#include <asm/arch/clock.h>
+
+static LIST_HEAD(clocks);
+static DEFINE_MUTEX(clocks_mutex);
+
+/*-------------------------------------------------------------------------
+ * Standard clock functions defined in include/linux/clk.h
+ *-------------------------------------------------------------------------*/
+
+/*
+ * Retrieve a clock by name.
+ *
+ * Note that we first try to use device id on the bus
+ * and clock name. If this fails, we try to use "<name>.<id>". If this fails,
+ * we try to use clock name only.
+ * The reference count to the clock's module owner ref count is incremented.
+ */
+struct clk *clk_get(struct device *dev, const char *id)
+{
+       struct clk *p, *clk = ERR_PTR(-ENOENT);
+       int idno;
+       const char *str;
+
+       if (id == NULL)
+               return clk;
+
+       if (dev == NULL || dev->bus != &platform_bus_type)
+               idno = -1;
+       else
+               idno = to_platform_device(dev)->id;
+
+       mutex_lock(&clocks_mutex);
+
+       list_for_each_entry(p, &clocks, node) {
+               if (p->id == idno &&
+                   strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
+                       clk = p;
+                       goto found;
+               }
+       }
+
+       str = strrchr(id, '.');
+       if (str) {
+               int cnt = str - id;
+               str++;
+               idno = simple_strtol(str, NULL, 10);
+               list_for_each_entry(p, &clocks, node) {
+                       if (p->id == idno &&
+                           strlen(p->name) == cnt &&
+                           strncmp(id, p->name, cnt) == 0 &&
+                           try_module_get(p->owner)) {
+                               clk = p;
+                               goto found;
+                       }
+               }
+       }
+
+       list_for_each_entry(p, &clocks, node) {
+               if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
+                       clk = p;
+                       goto found;
+               }
+       }
+
+       printk(KERN_WARNING "clk: Unable to get requested clock: %s\n", id);
+
+found:
+       mutex_unlock(&clocks_mutex);
+
+       return clk;
+}
+EXPORT_SYMBOL(clk_get);
+
+static void __clk_disable(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return;
+
+       __clk_disable(clk->parent);
+       __clk_disable(clk->secondary);
+
+       if (!(--clk->usecount) && clk->disable)
+               clk->disable(clk);
+}
+
+static int __clk_enable(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return -EINVAL;
+
+       __clk_enable(clk->parent);
+       __clk_enable(clk->secondary);
+
+       if (clk->usecount++ == 0 && clk->enable)
+               clk->enable(clk);
+
+       return 0;
+}
+
+/* This function increments the reference count on the clock and enables the
+ * clock if not already enabled. The parent clock tree is recursively enabled
+ */
+int clk_enable(struct clk *clk)
+{
+       int ret = 0;
+
+       if (clk == NULL || IS_ERR(clk))
+               return -EINVAL;
+
+       mutex_lock(&clocks_mutex);
+       ret = __clk_enable(clk);
+       mutex_unlock(&clocks_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_enable);
+
+/* This function decrements the reference count on the clock and disables
+ * the clock when reference count is 0. The parent clock tree is
+ * recursively disabled
+ */
+void clk_disable(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return;
+
+       mutex_lock(&clocks_mutex);
+       __clk_disable(clk);
+       mutex_unlock(&clocks_mutex);
+}
+EXPORT_SYMBOL(clk_disable);
+
+/* Retrieve the *current* clock rate. If the clock itself
+ * does not provide a special calculation routine, ask
+ * its parent and so on, until one is able to return
+ * a valid clock rate
+ */
+unsigned long clk_get_rate(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return 0UL;
+
+       if (clk->get_rate)
+               return clk->get_rate(clk);
+
+       return clk_get_rate(clk->parent);
+}
+EXPORT_SYMBOL(clk_get_rate);
+
+/* Decrement the clock's module reference count */
+void clk_put(struct clk *clk)
+{
+       if (clk && !IS_ERR(clk))
+               module_put(clk->owner);
+}
+EXPORT_SYMBOL(clk_put);
+
+/* Round the requested clock rate to the nearest supported
+ * rate that is less than or equal to the requested rate.
+ * This is dependent on the clock's current parent.
+ */
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+       if (clk == NULL || IS_ERR(clk) || !clk->round_rate)
+               return 0;
+
+       return clk->round_rate(clk, rate);
+}
+EXPORT_SYMBOL(clk_round_rate);
+
+/* Set the clock to the requested clock rate. The rate must
+ * match a supported rate exactly based on what clk_round_rate returns
+ */
+int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       int ret = -EINVAL;
+
+       if (clk == NULL || IS_ERR(clk) || clk->set_rate == NULL || rate == 0)
+               return ret;
+
+       mutex_lock(&clocks_mutex);
+       ret = clk->set_rate(clk, rate);
+       mutex_unlock(&clocks_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_set_rate);
+
+/* Set the clock's parent to another clock source */
+int clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       int ret = -EINVAL;
+
+       if (clk == NULL || IS_ERR(clk) || parent == NULL ||
+           IS_ERR(parent) || clk->set_parent == NULL)
+               return ret;
+
+       mutex_lock(&clocks_mutex);
+       ret = clk->set_parent(clk, parent);
+       if (ret == 0)
+               clk->parent = parent;
+       mutex_unlock(&clocks_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_set_parent);
+
+/* Retrieve the clock's parent clock source */
+struct clk *clk_get_parent(struct clk *clk)
+{
+       struct clk *ret = NULL;
+
+       if (clk == NULL || IS_ERR(clk))
+               return ret;
+
+       return clk->parent;
+}
+EXPORT_SYMBOL(clk_get_parent);
+
+/*
+ * Add a new clock to the clock tree.
+ */
+int clk_register(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return -EINVAL;
+
+       mutex_lock(&clocks_mutex);
+       list_add(&clk->node, &clocks);
+       mutex_unlock(&clocks_mutex);
+
+       return 0;
+}
+EXPORT_SYMBOL(clk_register);
+
+/* Remove a clock from the clock tree */
+void clk_unregister(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return;
+
+       mutex_lock(&clocks_mutex);
+       list_del(&clk->node);
+       mutex_unlock(&clocks_mutex);
+}
+EXPORT_SYMBOL(clk_unregister);
+
+#ifdef CONFIG_PROC_FS
+static int mxc_clock_read_proc(char *page, char **start, off_t off,
+                               int count, int *eof, void *data)
+{
+       struct clk *clkp;
+       char *p = page;
+       int len;
+
+       list_for_each_entry(clkp, &clocks, node) {
+               p += sprintf(p, "%s-%d:\t\t%lu, %d", clkp->name, clkp->id,
+                               clk_get_rate(clkp), clkp->usecount);
+               if (clkp->parent)
+                       p += sprintf(p, ", %s-%d\n", clkp->parent->name,
+                                    clkp->parent->id);
+               else
+                       p += sprintf(p, "\n");
+       }
+
+       len = (p - page) - off;
+       if (len < 0)
+               len = 0;
+
+       *eof = (len <= count) ? 1 : 0;
+       *start = page + off;
+
+       return len;
+}
+
+static int __init mxc_setup_proc_entry(void)
+{
+       struct proc_dir_entry *res;
+
+       res = create_proc_read_entry("cpu/clocks", 0, NULL,
+                                    mxc_clock_read_proc, NULL);
+       if (!res) {
+               printk(KERN_ERR "Failed to create proc/cpu/clocks\n");
+               return -ENOMEM;
+       }
+       return 0;
+}
+
+late_initcall(mxc_setup_proc_entry);
+#endif
diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
new file mode 100644 (file)
index 0000000..4a77367
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * MXC GPIO support. (c) 2008 Daniel Mack <daniel@caiaq.de>
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * Based on code from Freescale,
+ * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <asm/hardware.h>
+#include <asm-generic/bug.h>
+
+static struct mxc_gpio_port *mxc_gpio_ports;
+static int gpio_table_size;
+
+/* Note: This driver assumes 32 GPIOs are handled in one register */
+
+static void _clear_gpio_irqstatus(struct mxc_gpio_port *port, u32 index)
+{
+       __raw_writel(1 << index, port->base + GPIO_ISR);
+}
+
+static void _set_gpio_irqenable(struct mxc_gpio_port *port, u32 index,
+                               int enable)
+{
+       u32 l;
+
+       l = __raw_readl(port->base + GPIO_IMR);
+       l = (l & (~(1 << index))) | (!!enable << index);
+       __raw_writel(l, port->base + GPIO_IMR);
+}
+
+static void gpio_ack_irq(u32 irq)
+{
+       u32 gpio = irq_to_gpio(irq);
+       _clear_gpio_irqstatus(&mxc_gpio_ports[gpio / 32], gpio & 0x1f);
+}
+
+static void gpio_mask_irq(u32 irq)
+{
+       u32 gpio = irq_to_gpio(irq);
+       _set_gpio_irqenable(&mxc_gpio_ports[gpio / 32], gpio & 0x1f, 0);
+}
+
+static void gpio_unmask_irq(u32 irq)
+{
+       u32 gpio = irq_to_gpio(irq);
+       _set_gpio_irqenable(&mxc_gpio_ports[gpio / 32], gpio & 0x1f, 1);
+}
+
+static int gpio_set_irq_type(u32 irq, u32 type)
+{
+       u32 gpio = irq_to_gpio(irq);
+       struct mxc_gpio_port *port = &mxc_gpio_ports[gpio / 32];
+       u32 bit, val;
+       int edge;
+       void __iomem *reg = port->base;
+
+       switch (type) {
+       case IRQT_RISING:
+               edge = GPIO_INT_RISE_EDGE;
+               break;
+       case IRQT_FALLING:
+               edge = GPIO_INT_FALL_EDGE;
+               break;
+       case IRQT_LOW:
+               edge = GPIO_INT_LOW_LEV;
+               break;
+       case IRQT_HIGH:
+               edge = GPIO_INT_HIGH_LEV;
+               break;
+       default:        /* this includes IRQT_BOTHEDGE */
+               return -EINVAL;
+       }
+
+       reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */
+       bit = gpio & 0xf;
+       val = __raw_readl(reg) & ~(0x3 << (bit << 1));
+       __raw_writel(val | (edge << (bit << 1)), reg);
+       _clear_gpio_irqstatus(port, gpio & 0x1f);
+
+       return 0;
+}
+
+/* handle n interrupts in one status register */
+static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
+{
+       u32 gpio_irq_no;
+
+       gpio_irq_no = port->virtual_irq_start;
+       for (; irq_stat != 0; irq_stat >>= 1, gpio_irq_no++) {
+
+               if ((irq_stat & 1) == 0)
+                       continue;
+
+               BUG_ON(!(irq_desc[gpio_irq_no].handle_irq));
+               irq_desc[gpio_irq_no].handle_irq(gpio_irq_no,
+                               &irq_desc[gpio_irq_no]);
+       }
+}
+
+#ifdef CONFIG_ARCH_MX3
+/* MX3 has one interrupt *per* gpio port */
+static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc)
+{
+       u32 irq_stat;
+       struct mxc_gpio_port *port = (struct mxc_gpio_port *)get_irq_data(irq);
+
+       irq_stat = __raw_readl(port->base + GPIO_ISR) &
+                       __raw_readl(port->base + GPIO_IMR);
+       BUG_ON(!irq_stat);
+       mxc_gpio_irq_handler(port, irq_stat);
+}
+#endif
+
+#ifdef CONFIG_ARCH_MX2
+/* MX2 has one interrupt *for all* gpio ports */
+static void mx2_gpio_irq_handler(u32 irq, struct irq_desc *desc)
+{
+       int i;
+       u32 irq_msk, irq_stat;
+       struct mxc_gpio_port *port = (struct mxc_gpio_port *)get_irq_data(irq);
+
+       /* walk through all interrupt status registers */
+       for (i = 0; i < gpio_table_size; i++) {
+               irq_msk = __raw_readl(port[i].base + GPIO_IMR);
+               if (!irq_msk)
+                       continue;
+
+               irq_stat = __raw_readl(port[i].base + GPIO_ISR) & irq_msk;
+               if (irq_stat)
+                       mxc_gpio_irq_handler(&port[i], irq_stat);
+       }
+}
+#endif
+
+static struct irq_chip gpio_irq_chip = {
+       .ack = gpio_ack_irq,
+       .mask = gpio_mask_irq,
+       .unmask = gpio_unmask_irq,
+       .set_type = gpio_set_irq_type,
+};
+
+static void _set_gpio_direction(struct gpio_chip *chip, unsigned offset,
+                               int dir)
+{
+       struct mxc_gpio_port *port =
+               container_of(chip, struct mxc_gpio_port, chip);
+       u32 l;
+
+       l = __raw_readl(port->base + GPIO_GDIR);
+       if (dir)
+               l |= 1 << offset;
+       else
+               l &= ~(1 << offset);
+       __raw_writel(l, port->base + GPIO_GDIR);
+}
+
+static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct mxc_gpio_port *port =
+               container_of(chip, struct mxc_gpio_port, chip);
+       void __iomem *reg = port->base + GPIO_DR;
+       u32 l;
+
+       l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
+       __raw_writel(l, reg);
+}
+
+static int mxc_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+       struct mxc_gpio_port *port =
+               container_of(chip, struct mxc_gpio_port, chip);
+
+       return (__raw_readl(port->base + GPIO_DR) >> offset) & 1;
+}
+
+static int mxc_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+       _set_gpio_direction(chip, offset, 0);
+       return 0;
+}
+
+static int mxc_gpio_direction_output(struct gpio_chip *chip,
+                                    unsigned offset, int value)
+{
+       _set_gpio_direction(chip, offset, 1);
+       mxc_gpio_set(chip, offset, value);
+       return 0;
+}
+
+int __init mxc_gpio_init(struct mxc_gpio_port *port, int cnt)
+{
+       int i, j;
+
+       /* save for local usage */
+       mxc_gpio_ports = port;
+       gpio_table_size = cnt;
+
+       printk(KERN_INFO "MXC GPIO hardware\n");
+
+       for (i = 0; i < cnt; i++) {
+               /* disable the interrupt and clear the status */
+               __raw_writel(0, port[i].base + GPIO_IMR);
+               __raw_writel(~0, port[i].base + GPIO_ISR);
+               for (j = port[i].virtual_irq_start;
+                       j < port[i].virtual_irq_start + 32; j++) {
+                       set_irq_chip(j, &gpio_irq_chip);
+                       set_irq_handler(j, handle_edge_irq);
+                       set_irq_flags(j, IRQF_VALID);
+               }
+
+               /* register gpio chip */
+               port[i].chip.direction_input = mxc_gpio_direction_input;
+               port[i].chip.direction_output = mxc_gpio_direction_output;
+               port[i].chip.get = mxc_gpio_get;
+               port[i].chip.set = mxc_gpio_set;
+               port[i].chip.base = i * 32;
+               port[i].chip.ngpio = 32;
+
+               /* its a serious configuration bug when it fails */
+               BUG_ON( gpiochip_add(&port[i].chip) < 0 );
+
+#ifdef CONFIG_ARCH_MX3
+               /* setup one handler for each entry */
+               set_irq_chained_handler(port[i].irq, mx3_gpio_irq_handler);
+               set_irq_data(port[i].irq, &port[i]);
+#endif
+       }
+
+#ifdef CONFIG_ARCH_MX2
+       /* setup one handler for all GPIO interrupts */
+       set_irq_chained_handler(port[0].irq, mx2_gpio_irq_handler);
+       set_irq_data(port[0].irq, port);
+#endif
+       return 0;
+}
diff --git a/arch/arm/plat-mxc/iomux-mx1-mx2.c b/arch/arm/plat-mxc/iomux-mx1-mx2.c
new file mode 100644 (file)
index 0000000..1985571
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ *  arch/arm/mach-mxc/generic.c
+ *
+ *  author: Sascha Hauer
+ *  Created: april 20th, 2004
+ *  Copyright: Synertronixx GmbH
+ *
+ *  Common code for i.MX machines
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/gpio.h>
+
+#include <asm/hardware.h>
+#include <asm/mach/map.h>
+#include <asm/arch/iomux-mx1-mx2.h>
+
+void mxc_gpio_mode(int gpio_mode)
+{
+       unsigned int pin = gpio_mode & GPIO_PIN_MASK;
+       unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
+       unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> GPIO_OCR_SHIFT;
+       unsigned int tmp;
+
+       /* Pullup enable */
+       tmp = __raw_readl(VA_GPIO_BASE + MXC_PUEN(port));
+       if (gpio_mode & GPIO_PUEN)
+               tmp |= (1 << pin);
+       else
+               tmp &= ~(1 << pin);
+       __raw_writel(tmp, VA_GPIO_BASE + MXC_PUEN(port));
+
+       /* Data direction */
+       tmp = __raw_readl(VA_GPIO_BASE + MXC_DDIR(port));
+       if (gpio_mode & GPIO_OUT)
+               tmp |= 1 << pin;
+       else
+               tmp &= ~(1 << pin);
+       __raw_writel(tmp, VA_GPIO_BASE + MXC_DDIR(port));
+
+       /* Primary / alternate function */
+       tmp = __raw_readl(VA_GPIO_BASE + MXC_GPR(port));
+       if (gpio_mode & GPIO_AF)
+               tmp |= (1 << pin);
+       else
+               tmp &= ~(1 << pin);
+       __raw_writel(tmp, VA_GPIO_BASE + MXC_GPR(port));
+
+       /* use as gpio? */
+       tmp = __raw_readl(VA_GPIO_BASE + MXC_GIUS(port));
+       if (gpio_mode & (GPIO_PF | GPIO_AF))
+               tmp &= ~(1 << pin);
+       else
+               tmp |= (1 << pin);
+       __raw_writel(tmp, VA_GPIO_BASE + MXC_GIUS(port));
+
+       if (pin < 16) {
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_OCR1(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= (ocr << (pin * 2));
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_OCR1(port));
+
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_ICONFA1(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2);
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_ICONFA1(port));
+
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_ICONFB1(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2);
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_ICONFB1(port));
+       } else {
+               pin -= 16;
+
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_OCR2(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= (ocr << (pin * 2));
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_OCR2(port));
+
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_ICONFA2(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2);
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_ICONFA2(port));
+
+               tmp = __raw_readl(VA_GPIO_BASE + MXC_ICONFB2(port));
+               tmp &= ~(3 << (pin * 2));
+               tmp |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2);
+               __raw_writel(tmp, VA_GPIO_BASE + MXC_ICONFB2(port));
+       }
+}
+EXPORT_SYMBOL(mxc_gpio_mode);
+
+int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
+                               int alloc_mode, const char *label)
+{
+       const int *p = pin_list;
+       int i;
+       unsigned gpio;
+       unsigned mode;
+
+       for (i = 0; i < count; i++) {
+               gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
+               mode = *p & ~(GPIO_PIN_MASK | GPIO_PORT_MASK);
+
+               if (gpio >= (GPIO_PORT_MAX + 1) * 32)
+                       goto setup_error;
+
+               if (alloc_mode & MXC_GPIO_ALLOC_MODE_RELEASE)
+                       gpio_free(gpio);
+               else if (!(alloc_mode & MXC_GPIO_ALLOC_MODE_NO_ALLOC))
+                       if (gpio_request(gpio, label)
+                          && !(alloc_mode & MXC_GPIO_ALLOC_MODE_TRY_ALLOC))
+                               goto setup_error;
+
+               if (!(alloc_mode & (MXC_GPIO_ALLOC_MODE_ALLOC_ONLY |
+                                   MXC_GPIO_ALLOC_MODE_RELEASE)))
+                       mxc_gpio_mode(gpio | mode);
+
+               p++;
+       }
+       return 0;
+
+setup_error:
+       if (alloc_mode & (MXC_GPIO_ALLOC_MODE_NO_ALLOC |
+           MXC_GPIO_ALLOC_MODE_TRY_ALLOC))
+               return -EINVAL;
+
+       while (p != pin_list) {
+               p--;
+               gpio = *p & (GPIO_PIN_MASK | GPIO_PORT_MASK);
+               gpio_free(gpio);
+       }
+
+       return -EINVAL;
+}
+EXPORT_SYMBOL(mxc_gpio_setup_multiple_pins);
+
index 2ad5a69..1fbe01d 100644 (file)
@@ -1,24 +1,59 @@
 /*
- *  Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
  */
 
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/init.h>
-#include <linux/device.h>
-#include <linux/errno.h>
-#include <asm/hardware.h>
+#include <linux/irq.h>
 #include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/mach/irq.h>
 #include <asm/arch/common.h>
 
+#define AVIC_BASE              IO_ADDRESS(AVIC_BASE_ADDR)
+#define AVIC_INTCNTL           (AVIC_BASE + 0x00)      /* int control reg */
+#define AVIC_NIMASK            (AVIC_BASE + 0x04)      /* int mask reg */
+#define AVIC_INTENNUM          (AVIC_BASE + 0x08)      /* int enable number reg */
+#define AVIC_INTDISNUM         (AVIC_BASE + 0x0C)      /* int disable number reg */
+#define AVIC_INTENABLEH                (AVIC_BASE + 0x10)      /* int enable reg high */
+#define AVIC_INTENABLEL                (AVIC_BASE + 0x14)      /* int enable reg low */
+#define AVIC_INTTYPEH          (AVIC_BASE + 0x18)      /* int type reg high */
+#define AVIC_INTTYPEL          (AVIC_BASE + 0x1C)      /* int type reg low */
+#define AVIC_NIPRIORITY7       (AVIC_BASE + 0x20)      /* norm int priority lvl7 */
+#define AVIC_NIPRIORITY6       (AVIC_BASE + 0x24)      /* norm int priority lvl6 */
+#define AVIC_NIPRIORITY5       (AVIC_BASE + 0x28)      /* norm int priority lvl5 */
+#define AVIC_NIPRIORITY4       (AVIC_BASE + 0x2C)      /* norm int priority lvl4 */
+#define AVIC_NIPRIORITY3       (AVIC_BASE + 0x30)      /* norm int priority lvl3 */
+#define AVIC_NIPRIORITY2       (AVIC_BASE + 0x34)      /* norm int priority lvl2 */
+#define AVIC_NIPRIORITY1       (AVIC_BASE + 0x38)      /* norm int priority lvl1 */
+#define AVIC_NIPRIORITY0       (AVIC_BASE + 0x3C)      /* norm int priority lvl0 */
+#define AVIC_NIVECSR           (AVIC_BASE + 0x40)      /* norm int vector/status */
+#define AVIC_FIVECSR           (AVIC_BASE + 0x44)      /* fast int vector/status */
+#define AVIC_INTSRCH           (AVIC_BASE + 0x48)      /* int source reg high */
+#define AVIC_INTSRCL           (AVIC_BASE + 0x4C)      /* int source reg low */
+#define AVIC_INTFRCH           (AVIC_BASE + 0x50)      /* int force reg high */
+#define AVIC_INTFRCL           (AVIC_BASE + 0x54)      /* int force reg low */
+#define AVIC_NIPNDH            (AVIC_BASE + 0x58)      /* norm int pending high */
+#define AVIC_NIPNDL            (AVIC_BASE + 0x5C)      /* norm int pending low */
+#define AVIC_FIPNDH            (AVIC_BASE + 0x60)      /* fast int pending high */
+#define AVIC_FIPNDL            (AVIC_BASE + 0x64)      /* fast int pending low */
+
+#define SYSTEM_PREV_REG                IO_ADDRESS(IIM_BASE_ADDR + 0x20)
+#define SYSTEM_SREV_REG                IO_ADDRESS(IIM_BASE_ADDR + 0x24)
+#define IIM_PROD_REV_SH                3
+#define IIM_PROD_REV_LEN       5
+
 /* Disable interrupt number "irq" in the AVIC */
 static void mxc_mask_irq(unsigned int irq)
 {
@@ -32,7 +67,7 @@ static void mxc_unmask_irq(unsigned int irq)
 }
 
 static struct irq_chip mxc_avic_chip = {
-       .mask_ack = mxc_mask_irq,
+       .ack = mxc_mask_irq,
        .mask = mxc_mask_irq,
        .unmask = mxc_unmask_irq,
 };
@@ -71,5 +106,8 @@ void __init mxc_init_irq(void)
        reg |= (0xF << 28);
        __raw_writel(reg, AVIC_NIPRIORITY6);
 
+       /* init architectures chained interrupt handler */
+       mxc_register_gpios();
+
        printk(KERN_INFO "MXC IRQ initialized\n");
 }
diff --git a/arch/arm/plat-mxc/time.c b/arch/arm/plat-mxc/time.c
new file mode 100644 (file)
index 0000000..3bf8634
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ *  linux/arch/arm/plat-mxc/time.c
+ *
+ *  Copyright (C) 2000-2001 Deep Blue Solutions
+ *  Copyright (C) 2002 Shane Nay (shane@minirl.com)
+ *  Copyright (C) 2006-2007 Pavel Pisa (ppisa@pikron.com)
+ *  Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/clockchips.h>
+#include <linux/clk.h>
+
+#include <asm/hardware.h>
+#include <asm/mach/time.h>
+#include <asm/arch/common.h>
+#include <asm/arch/mxc_timer.h>
+
+static struct clock_event_device clockevent_mxc;
+static enum clock_event_mode clockevent_mode = CLOCK_EVT_MODE_UNUSED;
+
+/* clock source for the timer */
+static struct clk *timer_clk;
+
+/* clock source */
+
+static cycle_t mxc_get_cycles(void)
+{
+       return __raw_readl(TIMER_BASE + MXC_TCN);
+}
+
+static struct clocksource clocksource_mxc = {
+       .name           = "mxc_timer1",
+       .rating         = 200,
+       .read           = mxc_get_cycles,
+       .mask           = CLOCKSOURCE_MASK(32),
+       .shift          = 20,
+       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static int __init mxc_clocksource_init(void)
+{
+       unsigned int clock;
+
+       clock = clk_get_rate(timer_clk);
+
+       clocksource_mxc.mult = clocksource_hz2mult(clock,
+                                       clocksource_mxc.shift);
+       clocksource_register(&clocksource_mxc);
+
+       return 0;
+}
+
+/* clock event */
+
+static int mxc_set_next_event(unsigned long evt,
+                             struct clock_event_device *unused)
+{
+       unsigned long tcmp;
+
+       tcmp = __raw_readl(TIMER_BASE + MXC_TCN) + evt;
+       __raw_writel(tcmp, TIMER_BASE + MXC_TCMP);
+
+       return (int)(tcmp - __raw_readl(TIMER_BASE + MXC_TCN)) < 0 ?
+                               -ETIME : 0;
+}
+
+#ifdef DEBUG
+static const char *clock_event_mode_label[] = {
+       [CLOCK_EVT_MODE_PERIODIC] = "CLOCK_EVT_MODE_PERIODIC",
+       [CLOCK_EVT_MODE_ONESHOT]  = "CLOCK_EVT_MODE_ONESHOT",
+       [CLOCK_EVT_MODE_SHUTDOWN] = "CLOCK_EVT_MODE_SHUTDOWN",
+       [CLOCK_EVT_MODE_UNUSED]   = "CLOCK_EVT_MODE_UNUSED"
+};
+#endif /* DEBUG */
+
+static void mxc_set_mode(enum clock_event_mode mode,
+                               struct clock_event_device *evt)
+{
+       unsigned long flags;
+
+       /*
+        * The timer interrupt generation is disabled at least
+        * for enough time to call mxc_set_next_event()
+        */
+       local_irq_save(flags);
+
+       /* Disable interrupt in GPT module */
+       gpt_irq_disable();
+
+       if (mode != clockevent_mode) {
+               /* Set event time into far-far future */
+               __raw_writel(__raw_readl(TIMER_BASE + MXC_TCN) - 3,
+                               TIMER_BASE + MXC_TCMP);
+               /* Clear pending interrupt */
+               gpt_irq_acknowledge();
+       }
+
+#ifdef DEBUG
+       printk(KERN_INFO "mxc_set_mode: changing mode from %s to %s\n",
+               clock_event_mode_label[clockevent_mode],
+               clock_event_mode_label[mode]);
+#endif /* DEBUG */
+
+       /* Remember timer mode */
+       clockevent_mode = mode;
+       local_irq_restore(flags);
+
+       switch (mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               printk(KERN_ERR"mxc_set_mode: Periodic mode is not "
+                               "supported for i.MX\n");
+               break;
+       case CLOCK_EVT_MODE_ONESHOT:
+       /*
+        * Do not put overhead of interrupt enable/disable into
+        * mxc_set_next_event(), the core has about 4 minutes
+        * to call mxc_set_next_event() or shutdown clock after
+        * mode switching
+        */
+               local_irq_save(flags);
+               gpt_irq_enable();
+               local_irq_restore(flags);
+               break;
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_RESUME:
+               /* Left event sources disabled, no more interrupts appear */
+               break;
+       }
+}
+
+/*
+ * IRQ handler for the timer
+ */
+static irqreturn_t mxc_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = &clockevent_mxc;
+       uint32_t tstat;
+
+       tstat = __raw_readl(TIMER_BASE + MXC_TSTAT);
+
+       gpt_irq_acknowledge();
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static struct irqaction mxc_timer_irq = {
+       .name           = "i.MX Timer Tick",
+       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+       .handler        = mxc_timer_interrupt,
+};
+
+static struct clock_event_device clockevent_mxc = {
+       .name           = "mxc_timer1",
+       .features       = CLOCK_EVT_FEAT_ONESHOT,
+       .shift          = 32,
+       .set_mode       = mxc_set_mode,
+       .set_next_event = mxc_set_next_event,
+       .rating         = 200,
+};
+
+static int __init mxc_clockevent_init(void)
+{
+       unsigned int clock;
+
+       clock = clk_get_rate(timer_clk);
+
+       clockevent_mxc.mult = div_sc(clock, NSEC_PER_SEC,
+                                       clockevent_mxc.shift);
+       clockevent_mxc.max_delta_ns =
+                       clockevent_delta2ns(0xfffffffe, &clockevent_mxc);
+       clockevent_mxc.min_delta_ns =
+                       clockevent_delta2ns(0xff, &clockevent_mxc);
+
+       clockevent_mxc.cpumask = cpumask_of_cpu(0);
+
+       clockevents_register_device(&clockevent_mxc);
+
+       return 0;
+}
+
+void __init mxc_timer_init(const char *clk_timer)
+{
+       timer_clk = clk_get(NULL, clk_timer);
+       if (!timer_clk) {
+               printk(KERN_ERR"Cannot determine timer clock. Giving up.\n");
+               return;
+       }
+
+       clk_enable(timer_clk);
+
+       /*
+        * Initialise to a known state (all timers off, and timing reset)
+        */
+       __raw_writel(0, TIMER_BASE + MXC_TCTL);
+       __raw_writel(0, TIMER_BASE + MXC_TPRER); /* see datasheet note */
+
+       __raw_writel(TCTL_FRR | /* free running */
+                    TCTL_VAL | /* set clocksource and arch specific bits */
+                    TCTL_TEN,  /* start the timer */
+                    TIMER_BASE + MXC_TCTL);
+
+       /* init and register the timer to the framework */
+       mxc_clocksource_init();
+       mxc_clockevent_init();
+
+       /* Make irqs happen */
+       setup_irq(TIMER_INTERRUPT, &mxc_timer_irq);
+}
+
index bc639a3..2c4051c 100644 (file)
@@ -3,7 +3,7 @@
 #
 
 # Common support
-obj-y := common.o sram.o sram-fn.o clock.o devices.o dma.o mux.o gpio.o \
+obj-y := common.o sram.o clock.o devices.o dma.o mux.o gpio.o \
         usb.o fb.o
 obj-m :=
 obj-n :=
index 2db5580..c2e741d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  linux/arch/arm/plat-omap/clock.c
  *
- *  Copyright (C) 2004 - 2005 Nokia corporation
+ *  Copyright (C) 2004 - 2008 Nokia corporation
  *  Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
  *
  *  Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
@@ -22,6 +22,7 @@
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/cpufreq.h>
+#include <linux/debugfs.h>
 
 #include <asm/io.h>
 
@@ -33,41 +34,6 @@ static DEFINE_SPINLOCK(clockfw_lock);
 
 static struct clk_functions *arch_clock;
 
-#ifdef CONFIG_PM_DEBUG
-
-static void print_parents(struct clk *clk)
-{
-       struct clk *p;
-       int printed = 0;
-
-       list_for_each_entry(p, &clocks, node) {
-               if (p->parent == clk && p->usecount) {
-                       if (!clk->usecount && !printed) {
-                               printk("MISMATCH: %s\n", clk->name);
-                               printed = 1;
-                       }
-                       printk("\t%-15s\n", p->name);
-               }
-       }
-}
-
-void clk_print_usecounts(void)
-{
-       unsigned long flags;
-       struct clk *p;
-
-       spin_lock_irqsave(&clockfw_lock, flags);
-       list_for_each_entry(p, &clocks, node) {
-               if (p->usecount)
-                       printk("%-15s: %d\n", p->name, p->usecount);
-               print_parents(p);
-
-       }
-       spin_unlock_irqrestore(&clockfw_lock, flags);
-}
-
-#endif
-
 /*-------------------------------------------------------------------------
  * Standard clock functions defined in include/linux/clk.h
  *-------------------------------------------------------------------------*/
@@ -446,3 +412,93 @@ int __init clk_init(struct clk_functions * custom_clocks)
        return 0;
 }
 
+#if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS)
+/*
+ *     debugfs support to trace clock tree hierarchy and attributes
+ */
+static struct dentry *clk_debugfs_root;
+
+static int clk_debugfs_register_one(struct clk *c)
+{
+       int err;
+       struct dentry *d, *child;
+       struct clk *pa = c->parent;
+       char s[255];
+       char *p = s;
+
+       p += sprintf(p, "%s", c->name);
+       if (c->id != 0)
+               sprintf(p, ":%d", c->id);
+       d = debugfs_create_dir(s, pa ? pa->dent : clk_debugfs_root);
+       if (IS_ERR(d))
+               return PTR_ERR(d);
+       c->dent = d;
+
+       d = debugfs_create_u8("usecount", S_IRUGO, c->dent, (u8 *)&c->usecount);
+       if (IS_ERR(d)) {
+               err = PTR_ERR(d);
+               goto err_out;
+       }
+       d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate);
+       if (IS_ERR(d)) {
+               err = PTR_ERR(d);
+               goto err_out;
+       }
+       d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags);
+       if (IS_ERR(d)) {
+               err = PTR_ERR(d);
+               goto err_out;
+       }
+       return 0;
+
+err_out:
+       d = c->dent;
+       list_for_each_entry(child, &d->d_subdirs, d_u.d_child)
+               debugfs_remove(child);
+       debugfs_remove(c->dent);
+       return err;
+}
+
+static int clk_debugfs_register(struct clk *c)
+{
+       int err;
+       struct clk *pa = c->parent;
+
+       if (pa && !pa->dent) {
+               err = clk_debugfs_register(pa);
+               if (err)
+                       return err;
+       }
+
+       if (!c->dent) {
+               err = clk_debugfs_register_one(c);
+               if (err)
+                       return err;
+       }
+       return 0;
+}
+
+static int __init clk_debugfs_init(void)
+{
+       struct clk *c;
+       struct dentry *d;
+       int err;
+
+       d = debugfs_create_dir("clock", NULL);
+       if (IS_ERR(d))
+               return PTR_ERR(d);
+       clk_debugfs_root = d;
+
+       list_for_each_entry(c, &clocks, node) {
+               err = clk_debugfs_register(c);
+               if (err)
+                       goto err_out;
+       }
+       return 0;
+err_out:
+       debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */
+       return err;
+}
+late_initcall(clk_debugfs_init);
+
+#endif /* defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS) */
index bd1cef2..8d04929 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/io.h>
 #include <asm/setup.h>
 
+#include <asm/arch/common.h>
 #include <asm/arch/board.h>
 #include <asm/arch/control.h>
 #include <asm/arch/mux.h>
@@ -241,30 +242,70 @@ arch_initcall(omap_init_clocksource_32k);
 
 /* Global address base setup code */
 
+#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
+
+static struct omap_globals *omap2_globals;
+
+static void __init __omap2_set_globals(void)
+{
+       omap2_set_globals_memory(omap2_globals);
+       omap2_set_globals_control(omap2_globals);
+       omap2_set_globals_prcm(omap2_globals);
+}
+
+#endif
+
 #if defined(CONFIG_ARCH_OMAP2420)
+
+static struct omap_globals omap242x_globals = {
+       .tap    = (__force void __iomem *)OMAP2_IO_ADDRESS(0x48014000),
+       .sdrc   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
+       .sms    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
+       .ctrl   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
+       .prm    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
+       .cm     = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
+};
+
 void __init omap2_set_globals_242x(void)
 {
-       omap2_sdrc_base = OMAP2420_SDRC_BASE;
-       omap2_sms_base = OMAP2420_SMS_BASE;
-       omap_ctrl_base_set(OMAP2420_CTRL_BASE);
+       omap2_globals = &omap242x_globals;
+       __omap2_set_globals();
 }
 #endif
 
 #if defined(CONFIG_ARCH_OMAP2430)
+
+static struct omap_globals omap243x_globals = {
+       .tap    = (__force void __iomem *)OMAP2_IO_ADDRESS(0x4900a000),
+       .sdrc   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
+       .sms    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
+       .ctrl   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
+       .prm    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
+       .cm     = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
+};
+
 void __init omap2_set_globals_243x(void)
 {
-       omap2_sdrc_base = OMAP243X_SDRC_BASE;
-       omap2_sms_base = OMAP243X_SMS_BASE;
-       omap_ctrl_base_set(OMAP243X_CTRL_BASE);
+       omap2_globals = &omap243x_globals;
+       __omap2_set_globals();
 }
 #endif
 
 #if defined(CONFIG_ARCH_OMAP3430)
+
+static struct omap_globals omap343x_globals = {
+       .tap    = (__force void __iomem *)OMAP2_IO_ADDRESS(0x4830A000),
+       .sdrc   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
+       .sms    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
+       .ctrl   = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
+       .prm    = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
+       .cm     = (__force void __iomem *)OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
+};
+
 void __init omap2_set_globals_343x(void)
 {
-       omap2_sdrc_base = OMAP343X_SDRC_BASE;
-       omap2_sms_base = OMAP343X_SMS_BASE;
-       omap_ctrl_base_set(OMAP343X_CTRL_BASE);
+       omap2_globals = &omap343x_globals;
+       __omap2_set_globals();
 }
 #endif
 
index 4a53f9b..81002b7 100644 (file)
@@ -24,6 +24,7 @@
 #include <asm/arch/mux.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/menelaus.h>
+#include <asm/arch/mcbsp.h>
 
 #if    defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE)
 
@@ -144,6 +145,53 @@ static void omap_init_kp(void)
 static inline void omap_init_kp(void) {}
 #endif
 
+/*-------------------------------------------------------------------------*/
+#if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE)
+
+static struct platform_device **omap_mcbsp_devices;
+
+void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
+                                       int size)
+{
+       int i;
+
+       if (size > OMAP_MAX_MCBSP_COUNT) {
+               printk(KERN_WARNING "Registered too many McBSPs platform_data."
+                       " Using maximum (%d) available.\n",
+                       OMAP_MAX_MCBSP_COUNT);
+               size = OMAP_MAX_MCBSP_COUNT;
+       }
+
+       omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
+                                    GFP_KERNEL);
+       if (!omap_mcbsp_devices) {
+               printk(KERN_ERR "Could not register McBSP devices\n");
+               return;
+       }
+
+       for (i = 0; i < size; i++) {
+               struct platform_device *new_mcbsp;
+               int ret;
+
+               new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
+               if (!new_mcbsp)
+                       continue;
+               new_mcbsp->dev.platform_data = &config[i];
+               ret = platform_device_add(new_mcbsp);
+               if (ret) {
+                       platform_device_put(new_mcbsp);
+                       continue;
+               }
+               omap_mcbsp_devices[i] = new_mcbsp;
+       }
+}
+
+#else
+void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
+                                       int size)
+{  }
+#endif
+
 /*-------------------------------------------------------------------------*/
 
 #if    defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
index 39c637b..fac8e99 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * linux/arch/arm/plat-omap/dma.c
  *
- * Copyright (C) 2003 Nokia Corporation
+ * Copyright (C) 2003 - 2008 Nokia Corporation
  * Author: Juha Yrjölä <juha.yrjola@nokia.com>
  * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
  * Graphics DMA and LCD DMA graphics tranformations
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/io.h>
 
 #include <asm/system.h>
 #include <asm/hardware.h>
 #include <asm/dma.h>
-#include <asm/io.h>
 
 #include <asm/arch/tc.h>
 
@@ -43,13 +43,13 @@ enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
 enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
 #endif
 
-#define OMAP_DMA_ACTIVE                0x01
-#define OMAP_DMA_CCR_EN                (1 << 7)
+#define OMAP_DMA_ACTIVE                        0x01
+#define OMAP_DMA_CCR_EN                        (1 << 7)
 #define OMAP2_DMA_CSR_CLEAR_MASK       0xffe
 
-#define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
+#define OMAP_FUNC_MUX_ARM_BASE         (0xfffe1000 + 0xec)
 
-static int enable_1510_mode = 0;
+static int enable_1510_mode;
 
 struct omap_dma_lch {
        int next_lch;
@@ -57,7 +57,7 @@ struct omap_dma_lch {
        u16 saved_csr;
        u16 enabled_irqs;
        const char *dev_name;
-       void (* callback)(int lch, u16 ch_status, void *data);
+       void (*callback)(int lch, u16 ch_status, void *data);
        void *data;
 
 #ifndef CONFIG_ARCH_OMAP1
@@ -72,7 +72,6 @@ struct omap_dma_lch {
        long flags;
 };
 
-#ifndef CONFIG_ARCH_OMAP1
 struct dma_link_info {
        int *linked_dmach_q;
        int no_of_lchs_linked;
@@ -86,7 +85,9 @@ struct dma_link_info {
 
 };
 
-static struct dma_link_info dma_linked_lch[OMAP_LOGICAL_DMA_CH_COUNT];
+static struct dma_link_info *dma_linked_lch;
+
+#ifndef CONFIG_ARCH_OMAP1
 
 /* Chain handling macros */
 #define OMAP_DMA_CHAIN_QINIT(chain_id)                                 \
@@ -119,12 +120,15 @@ static struct dma_link_info dma_linked_lch[OMAP_LOGICAL_DMA_CH_COUNT];
                dma_linked_lch[chain_id].q_count++; \
        } while (0)
 #endif
+
+static int dma_lch_count;
 static int dma_chan_count;
 
 static spinlock_t dma_chan_lock;
-static struct omap_dma_lch dma_chan[OMAP_LOGICAL_DMA_CH_COUNT];
+static struct omap_dma_lch *dma_chan;
+static void __iomem *omap_dma_base;
 
-static const u8 omap1_dma_irq[OMAP_LOGICAL_DMA_CH_COUNT] = {
+static const u8 omap1_dma_irq[OMAP1_LOGICAL_DMA_CH_COUNT] = {
        INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
        INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
        INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
@@ -139,6 +143,24 @@ static inline void omap_enable_channel_irq(int lch);
 #define REVISIT_24XX()         printk(KERN_ERR "FIXME: no %s on 24xx\n", \
                                                __func__);
 
+#define dma_read(reg)                                                  \
+({                                                                     \
+       u32 __val;                                                      \
+       if (cpu_class_is_omap1())                                       \
+               __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg);   \
+       else                                                            \
+               __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg);   \
+       __val;                                                          \
+})
+
+#define dma_write(val, reg)                                            \
+({                                                                     \
+       if (cpu_class_is_omap1())                                       \
+               __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
+       else                                                            \
+               __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg);   \
+})
+
 #ifdef CONFIG_ARCH_OMAP15XX
 /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
 int omap_dma_in_1510_mode(void)
@@ -173,13 +195,14 @@ static inline void set_gdma_dev(int req, int dev)
 #define set_gdma_dev(req, dev) do {} while (0)
 #endif
 
+/* Omap1 only */
 static void clear_lch_regs(int lch)
 {
        int i;
-       u32 lch_base = OMAP_DMA_BASE + lch * 0x40;
+       void __iomem *lch_base = omap_dma_base + OMAP1_DMA_CH_BASE(lch);
 
        for (i = 0; i < 0x2c; i += 2)
-               omap_writew(0, lch_base + i);
+               __raw_writew(0, lch_base + i);
 }
 
 void omap_set_dma_priority(int lch, int dst_port, int priority)
@@ -212,33 +235,49 @@ void omap_set_dma_priority(int lch, int dst_port, int priority)
        }
 
        if (cpu_class_is_omap2()) {
+               u32 ccr;
+
+               ccr = dma_read(CCR(lch));
                if (priority)
-                       OMAP_DMA_CCR_REG(lch) |= (1 << 6);
+                       ccr |= (1 << 6);
                else
-                       OMAP_DMA_CCR_REG(lch) &= ~(1 << 6);
+                       ccr &= ~(1 << 6);
+               dma_write(ccr, CCR(lch));
        }
 }
+EXPORT_SYMBOL(omap_set_dma_priority);
 
 void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
                                  int frame_count, int sync_mode,
                                  int dma_trigger, int src_or_dst_synch)
 {
-       OMAP_DMA_CSDP_REG(lch) &= ~0x03;
-       OMAP_DMA_CSDP_REG(lch) |= data_type;
+       u32 l;
+
+       l = dma_read(CSDP(lch));
+       l &= ~0x03;
+       l |= data_type;
+       dma_write(l, CSDP(lch));
 
        if (cpu_class_is_omap1()) {
-               OMAP_DMA_CCR_REG(lch) &= ~(1 << 5);
+               u16 ccr;
+
+               ccr = dma_read(CCR(lch));
+               ccr &= ~(1 << 5);
                if (sync_mode == OMAP_DMA_SYNC_FRAME)
-                       OMAP_DMA_CCR_REG(lch) |= 1 << 5;
+                       ccr |= 1 << 5;
+               dma_write(ccr, CCR(lch));
 
-               OMAP1_DMA_CCR2_REG(lch) &= ~(1 << 2);
+               ccr = dma_read(CCR2(lch));
+               ccr &= ~(1 << 2);
                if (sync_mode == OMAP_DMA_SYNC_BLOCK)
-                       OMAP1_DMA_CCR2_REG(lch) |= 1 << 2;
+                       ccr |= 1 << 2;
+               dma_write(ccr, CCR2(lch));
        }
 
        if (cpu_class_is_omap2() && dma_trigger) {
-               u32 val = OMAP_DMA_CCR_REG(lch);
+               u32 val;
 
+               val = dma_read(CCR(lch));
                val &= ~(3 << 19);
                if (dma_trigger > 63)
                        val |= 1 << 20;
@@ -263,12 +302,13 @@ void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
                else
                        val &= ~(1 << 24);      /* dest synch */
 
-               OMAP_DMA_CCR_REG(lch) = val;
+               dma_write(val, CCR(lch));
        }
 
-       OMAP_DMA_CEN_REG(lch) = elem_count;
-       OMAP_DMA_CFN_REG(lch) = frame_count;
+       dma_write(elem_count, CEN(lch));
+       dma_write(frame_count, CFN(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_transfer_params);
 
 void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
 {
@@ -281,7 +321,9 @@ void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
                return;
        }
 
-       w = OMAP1_DMA_CCR2_REG(lch) & ~0x03;
+       w = dma_read(CCR2(lch));
+       w &= ~0x03;
+
        switch (mode) {
        case OMAP_DMA_CONSTANT_FILL:
                w |= 0x01;
@@ -294,52 +336,81 @@ void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
        default:
                BUG();
        }
-       OMAP1_DMA_CCR2_REG(lch) = w;
+       dma_write(w, CCR2(lch));
 
-       w = OMAP1_DMA_LCH_CTRL_REG(lch) & ~0x0f;
+       w = dma_read(LCH_CTRL(lch));
+       w &= ~0x0f;
        /* Default is channel type 2D */
        if (mode) {
-               OMAP1_DMA_COLOR_L_REG(lch) = (u16)color;
-               OMAP1_DMA_COLOR_U_REG(lch) = (u16)(color >> 16);
+               dma_write((u16)color, COLOR_L(lch));
+               dma_write((u16)(color >> 16), COLOR_U(lch));
                w |= 1;         /* Channel type G */
        }
-       OMAP1_DMA_LCH_CTRL_REG(lch) = w;
+       dma_write(w, LCH_CTRL(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_color_mode);
 
 void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
 {
        if (cpu_class_is_omap2()) {
-               OMAP_DMA_CSDP_REG(lch) &= ~(0x3 << 16);
-               OMAP_DMA_CSDP_REG(lch) |= (mode << 16);
+               u32 csdp;
+
+               csdp = dma_read(CSDP(lch));
+               csdp &= ~(0x3 << 16);
+               csdp |= (mode << 16);
+               dma_write(csdp, CSDP(lch));
+       }
+}
+EXPORT_SYMBOL(omap_set_dma_write_mode);
+
+void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
+{
+       if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
+               u32 l;
+
+               l = dma_read(LCH_CTRL(lch));
+               l &= ~0x7;
+               l |= mode;
+               dma_write(l, LCH_CTRL(lch));
        }
 }
+EXPORT_SYMBOL(omap_set_dma_channel_mode);
 
 /* Note that src_port is only for omap1 */
 void omap_set_dma_src_params(int lch, int src_port, int src_amode,
                             unsigned long src_start,
                             int src_ei, int src_fi)
 {
+       u32 l;
+
        if (cpu_class_is_omap1()) {
-               OMAP_DMA_CSDP_REG(lch) &= ~(0x1f << 2);
-               OMAP_DMA_CSDP_REG(lch) |= src_port << 2;
+               u16 w;
+
+               w = dma_read(CSDP(lch));
+               w &= ~(0x1f << 2);
+               w |= src_port << 2;
+               dma_write(w, CSDP(lch));
        }
 
-       OMAP_DMA_CCR_REG(lch) &= ~(0x03 << 12);
-       OMAP_DMA_CCR_REG(lch) |= src_amode << 12;
+       l = dma_read(CCR(lch));
+       l &= ~(0x03 << 12);
+       l |= src_amode << 12;
+       dma_write(l, CCR(lch));
 
        if (cpu_class_is_omap1()) {
-               OMAP1_DMA_CSSA_U_REG(lch) = src_start >> 16;
-               OMAP1_DMA_CSSA_L_REG(lch) = src_start;
+               dma_write(src_start >> 16, CSSA_U(lch));
+               dma_write((u16)src_start, CSSA_L(lch));
        }
 
        if (cpu_class_is_omap2())
-               OMAP2_DMA_CSSA_REG(lch) = src_start;
+               dma_write(src_start, CSSA(lch));
 
-       OMAP_DMA_CSEI_REG(lch) = src_ei;
-       OMAP_DMA_CSFI_REG(lch) = src_fi;
+       dma_write(src_ei, CSEI(lch));
+       dma_write(src_fi, CSFI(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_src_params);
 
-void omap_set_dma_params(int lch, struct omap_dma_channel_params * params)
+void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
 {
        omap_set_dma_transfer_params(lch, params->data_type,
                                     params->elem_count, params->frame_count,
@@ -356,28 +427,37 @@ void omap_set_dma_params(int lch, struct omap_dma_channel_params * params)
                omap_dma_set_prio_lch(lch, params->read_prio,
                                      params->write_prio);
 }
+EXPORT_SYMBOL(omap_set_dma_params);
 
 void omap_set_dma_src_index(int lch, int eidx, int fidx)
 {
-       if (cpu_class_is_omap2()) {
-               REVISIT_24XX();
+       if (cpu_class_is_omap2())
                return;
-       }
-       OMAP_DMA_CSEI_REG(lch) = eidx;
-       OMAP_DMA_CSFI_REG(lch) = fidx;
+
+       dma_write(eidx, CSEI(lch));
+       dma_write(fidx, CSFI(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_src_index);
 
 void omap_set_dma_src_data_pack(int lch, int enable)
 {
-       OMAP_DMA_CSDP_REG(lch) &= ~(1 << 6);
+       u32 l;
+
+       l = dma_read(CSDP(lch));
+       l &= ~(1 << 6);
        if (enable)
-               OMAP_DMA_CSDP_REG(lch) |= (1 << 6);
+               l |= (1 << 6);
+       dma_write(l, CSDP(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_src_data_pack);
 
 void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
 {
        unsigned int burst = 0;
-       OMAP_DMA_CSDP_REG(lch) &= ~(0x03 << 7);
+       u32 l;
+
+       l = dma_read(CSDP(lch));
+       l &= ~(0x03 << 7);
 
        switch (burst_mode) {
        case OMAP_DMA_DATA_BURST_DIS:
@@ -408,55 +488,73 @@ void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
        default:
                BUG();
        }
-       OMAP_DMA_CSDP_REG(lch) |= (burst << 7);
+
+       l |= (burst << 7);
+       dma_write(l, CSDP(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
 
 /* Note that dest_port is only for OMAP1 */
 void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
                              unsigned long dest_start,
                              int dst_ei, int dst_fi)
 {
+       u32 l;
+
        if (cpu_class_is_omap1()) {
-               OMAP_DMA_CSDP_REG(lch) &= ~(0x1f << 9);
-               OMAP_DMA_CSDP_REG(lch) |= dest_port << 9;
+               l = dma_read(CSDP(lch));
+               l &= ~(0x1f << 9);
+               l |= dest_port << 9;
+               dma_write(l, CSDP(lch));
        }
 
-       OMAP_DMA_CCR_REG(lch) &= ~(0x03 << 14);
-       OMAP_DMA_CCR_REG(lch) |= dest_amode << 14;
+       l = dma_read(CCR(lch));
+       l &= ~(0x03 << 14);
+       l |= dest_amode << 14;
+       dma_write(l, CCR(lch));
 
        if (cpu_class_is_omap1()) {
-               OMAP1_DMA_CDSA_U_REG(lch) = dest_start >> 16;
-               OMAP1_DMA_CDSA_L_REG(lch) = dest_start;
+               dma_write(dest_start >> 16, CDSA_U(lch));
+               dma_write(dest_start, CDSA_L(lch));
        }
 
        if (cpu_class_is_omap2())
-               OMAP2_DMA_CDSA_REG(lch) = dest_start;
+               dma_write(dest_start, CDSA(lch));
 
-       OMAP_DMA_CDEI_REG(lch) = dst_ei;
-       OMAP_DMA_CDFI_REG(lch) = dst_fi;
+       dma_write(dst_ei, CDEI(lch));
+       dma_write(dst_fi, CDFI(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_dest_params);
 
 void omap_set_dma_dest_index(int lch, int eidx, int fidx)
 {
-       if (cpu_class_is_omap2()) {
-               REVISIT_24XX();
+       if (cpu_class_is_omap2())
                return;
-       }
-       OMAP_DMA_CDEI_REG(lch) = eidx;
-       OMAP_DMA_CDFI_REG(lch) = fidx;
+
+       dma_write(eidx, CDEI(lch));
+       dma_write(fidx, CDFI(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_dest_index);
 
 void omap_set_dma_dest_data_pack(int lch, int enable)
 {
-       OMAP_DMA_CSDP_REG(lch) &= ~(1 << 13);
+       u32 l;
+
+       l = dma_read(CSDP(lch));
+       l &= ~(1 << 13);
        if (enable)
-               OMAP_DMA_CSDP_REG(lch) |= 1 << 13;
+               l |= 1 << 13;
+       dma_write(l, CSDP(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
 
 void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
 {
        unsigned int burst = 0;
-       OMAP_DMA_CSDP_REG(lch) &= ~(0x03 << 14);
+       u32 l;
+
+       l = dma_read(CSDP(lch));
+       l &= ~(0x03 << 14);
 
        switch (burst_mode) {
        case OMAP_DMA_DATA_BURST_DIS:
@@ -486,8 +584,10 @@ void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
                BUG();
                return;
        }
-       OMAP_DMA_CSDP_REG(lch) |= (burst << 14);
+       l |= (burst << 14);
+       dma_write(l, CSDP(lch));
 }
+EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
 
 static inline void omap_enable_channel_irq(int lch)
 {
@@ -495,62 +595,74 @@ static inline void omap_enable_channel_irq(int lch)
 
        /* Clear CSR */
        if (cpu_class_is_omap1())
-               status = OMAP_DMA_CSR_REG(lch);
+               status = dma_read(CSR(lch));
        else if (cpu_class_is_omap2())
-               OMAP_DMA_CSR_REG(lch) = OMAP2_DMA_CSR_CLEAR_MASK;
+               dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
 
        /* Enable some nice interrupts. */
-       OMAP_DMA_CICR_REG(lch) = dma_chan[lch].enabled_irqs;
+       dma_write(dma_chan[lch].enabled_irqs, CICR(lch));
 }
 
 static void omap_disable_channel_irq(int lch)
 {
        if (cpu_class_is_omap2())
-               OMAP_DMA_CICR_REG(lch) = 0;
+               dma_write(0, CICR(lch));
 }
 
 void omap_enable_dma_irq(int lch, u16 bits)
 {
        dma_chan[lch].enabled_irqs |= bits;
 }
+EXPORT_SYMBOL(omap_enable_dma_irq);
 
 void omap_disable_dma_irq(int lch, u16 bits)
 {
        dma_chan[lch].enabled_irqs &= ~bits;
 }
+EXPORT_SYMBOL(omap_disable_dma_irq);
 
 static inline void enable_lnk(int lch)
 {
+       u32 l;
+
+       l = dma_read(CLNK_CTRL(lch));
+
        if (cpu_class_is_omap1())
-               OMAP_DMA_CLNK_CTRL_REG(lch) &= ~(1 << 14);
+               l &= ~(1 << 14);
 
        /* Set the ENABLE_LNK bits */
        if (dma_chan[lch].next_lch != -1)
-               OMAP_DMA_CLNK_CTRL_REG(lch) =
-                       dma_chan[lch].next_lch | (1 << 15);
+               l = dma_chan[lch].next_lch | (1 << 15);
 
 #ifndef CONFIG_ARCH_OMAP1
-       if (dma_chan[lch].next_linked_ch != -1)
-               OMAP_DMA_CLNK_CTRL_REG(lch) =
-                       dma_chan[lch].next_linked_ch | (1 << 15);
+       if (cpu_class_is_omap2())
+               if (dma_chan[lch].next_linked_ch != -1)
+                       l = dma_chan[lch].next_linked_ch | (1 << 15);
 #endif
+
+       dma_write(l, CLNK_CTRL(lch));
 }
 
 static inline void disable_lnk(int lch)
 {
+       u32 l;
+
+       l = dma_read(CLNK_CTRL(lch));
+
        /* Disable interrupts */
        if (cpu_class_is_omap1()) {
-               OMAP_DMA_CICR_REG(lch) = 0;
+               dma_write(0, CICR(lch));
                /* Set the STOP_LNK bit */
-               OMAP_DMA_CLNK_CTRL_REG(lch) |= 1 << 14;
+               l |= 1 << 14;
        }
 
        if (cpu_class_is_omap2()) {
                omap_disable_channel_irq(lch);
                /* Clear the ENABLE_LNK bit */
-               OMAP_DMA_CLNK_CTRL_REG(lch) &= ~(1 << 15);
+               l &= ~(1 << 15);
        }
 
+       dma_write(l, CLNK_CTRL(lch));
        dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
 }
 
@@ -561,13 +673,13 @@ static inline void omap2_enable_irq_lch(int lch)
        if (!cpu_class_is_omap2())
                return;
 
-       val = omap_readl(OMAP_DMA4_IRQENABLE_L0);
+       val = dma_read(IRQENABLE_L0);
        val |= 1 << lch;
-       omap_writel(val, OMAP_DMA4_IRQENABLE_L0);
+       dma_write(val, IRQENABLE_L0);
 }
 
 int omap_request_dma(int dev_id, const char *dev_name,
-                    void (* callback)(int lch, u16 ch_status, void *data),
+                    void (*callback)(int lch, u16 ch_status, void *data),
                     void *data, int *dma_ch_out)
 {
        int ch, free_ch = -1;
@@ -600,10 +712,14 @@ int omap_request_dma(int dev_id, const char *dev_name,
        chan->dev_name = dev_name;
        chan->callback = callback;
        chan->data = data;
+
 #ifndef CONFIG_ARCH_OMAP1
-       chan->chain_id = -1;
-       chan->next_linked_ch = -1;
+       if (cpu_class_is_omap2()) {
+               chan->chain_id = -1;
+               chan->next_linked_ch = -1;
+       }
 #endif
+
        chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
 
        if (cpu_class_is_omap1())
@@ -618,26 +734,28 @@ int omap_request_dma(int dev_id, const char *dev_name,
                        set_gdma_dev(free_ch + 1, dev_id);
                        dev_id = free_ch + 1;
                }
-               /* Disable the 1510 compatibility mode and set the sync device
-                * id. */
-               OMAP_DMA_CCR_REG(free_ch) = dev_id | (1 << 10);
+               /*
+                * Disable the 1510 compatibility mode and set the sync device
+                * id.
+                */
+               dma_write(dev_id | (1 << 10), CCR(free_ch));
        } else if (cpu_is_omap730() || cpu_is_omap15xx()) {
-               OMAP_DMA_CCR_REG(free_ch) = dev_id;
+               dma_write(dev_id, CCR(free_ch));
        }
 
        if (cpu_class_is_omap2()) {
                omap2_enable_irq_lch(free_ch);
-
                omap_enable_channel_irq(free_ch);
                /* Clear the CSR register and IRQ status register */
-               OMAP_DMA_CSR_REG(free_ch) = OMAP2_DMA_CSR_CLEAR_MASK;
-               omap_writel(1 << free_ch, OMAP_DMA4_IRQSTATUS_L0);
+               dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(free_ch));
+               dma_write(1 << free_ch, IRQSTATUS_L0);
        }
 
        *dma_ch_out = free_ch;
 
        return 0;
 }
+EXPORT_SYMBOL(omap_request_dma);
 
 void omap_free_dma(int lch)
 {
@@ -645,11 +763,12 @@ void omap_free_dma(int lch)
 
        spin_lock_irqsave(&dma_chan_lock, flags);
        if (dma_chan[lch].dev_id == -1) {
-               printk("omap_dma: trying to free nonallocated DMA channel %d\n",
+               pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
                       lch);
                spin_unlock_irqrestore(&dma_chan_lock, flags);
                return;
        }
+
        dma_chan[lch].dev_id = -1;
        dma_chan[lch].next_lch = -1;
        dma_chan[lch].callback = NULL;
@@ -657,30 +776,31 @@ void omap_free_dma(int lch)
 
        if (cpu_class_is_omap1()) {
                /* Disable all DMA interrupts for the channel. */
-               OMAP_DMA_CICR_REG(lch) = 0;
+               dma_write(0, CICR(lch));
                /* Make sure the DMA transfer is stopped. */
-               OMAP_DMA_CCR_REG(lch) = 0;
+               dma_write(0, CCR(lch));
        }
 
        if (cpu_class_is_omap2()) {
                u32 val;
                /* Disable interrupts */
-               val = omap_readl(OMAP_DMA4_IRQENABLE_L0);
+               val = dma_read(IRQENABLE_L0);
                val &= ~(1 << lch);
-               omap_writel(val, OMAP_DMA4_IRQENABLE_L0);
+               dma_write(val, IRQENABLE_L0);
 
                /* Clear the CSR register and IRQ status register */
-               OMAP_DMA_CSR_REG(lch) = OMAP2_DMA_CSR_CLEAR_MASK;
-               omap_writel(1 << lch, OMAP_DMA4_IRQSTATUS_L0);
+               dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
+               dma_write(1 << lch, IRQSTATUS_L0);
 
                /* Disable all DMA interrupts for the channel. */
-               OMAP_DMA_CICR_REG(lch) = 0;
+               dma_write(0, CICR(lch));
 
                /* Make sure the DMA transfer is stopped. */
-               OMAP_DMA_CCR_REG(lch) = 0;
+               dma_write(0, CCR(lch));
                omap_clear_dma(lch);
        }
 }
+EXPORT_SYMBOL(omap_free_dma);
 
 /**
  * @brief omap_dma_set_global_params : Set global priority settings for dma
@@ -708,7 +828,7 @@ omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
        reg = (arb_rate & 0xff) << 16;
        reg |= (0xff & max_fifo_depth);
 
-       omap_writel(reg, OMAP_DMA4_GCR_REG);
+       dma_write(reg, GCR);
 }
 EXPORT_SYMBOL(omap_dma_set_global_params);
 
@@ -725,20 +845,21 @@ int
 omap_dma_set_prio_lch(int lch, unsigned char read_prio,
                      unsigned char write_prio)
 {
-       u32 w;
+       u32 l;
 
-       if (unlikely((lch < 0 || lch >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((lch < 0 || lch >= dma_lch_count))) {
                printk(KERN_ERR "Invalid channel id\n");
                return -EINVAL;
        }
-       w = OMAP_DMA_CCR_REG(lch);
-       w &= ~((1 << 6) | (1 << 26));
+       l = dma_read(CCR(lch));
+       l &= ~((1 << 6) | (1 << 26));
        if (cpu_is_omap2430() || cpu_is_omap34xx())
-               w |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
+               l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
        else
-               w |= ((read_prio & 0x1) << 6);
+               l |= ((read_prio & 0x1) << 6);
+
+       dma_write(l, CCR(lch));
 
-       OMAP_DMA_CCR_REG(lch) = w;
        return 0;
 }
 EXPORT_SYMBOL(omap_dma_set_prio_lch);
@@ -754,28 +875,34 @@ void omap_clear_dma(int lch)
        local_irq_save(flags);
 
        if (cpu_class_is_omap1()) {
-               int status;
-               OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
+               u32 l;
+
+               l = dma_read(CCR(lch));
+               l &= ~OMAP_DMA_CCR_EN;
+               dma_write(l, CCR(lch));
 
                /* Clear pending interrupts */
-               status = OMAP_DMA_CSR_REG(lch);
+               l = dma_read(CSR(lch));
        }
 
        if (cpu_class_is_omap2()) {
                int i;
-               u32 lch_base = OMAP_DMA4_BASE + lch * 0x60 + 0x80;
+               void __iomem *lch_base = omap_dma_base + OMAP_DMA4_CH_BASE(lch);
                for (i = 0; i < 0x44; i += 4)
-                       omap_writel(0, lch_base + i);
+                       __raw_writel(0, lch_base + i);
        }
 
        local_irq_restore(flags);
 }
+EXPORT_SYMBOL(omap_clear_dma);
 
 void omap_start_dma(int lch)
 {
+       u32 l;
+
        if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
                int next_lch, cur_lch;
-               char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
+               char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
 
                dma_chan_link_map[lch] = 1;
                /* Set the link register of the first channel */
@@ -799,27 +926,34 @@ void omap_start_dma(int lch)
                } while (next_lch != -1);
        } else if (cpu_class_is_omap2()) {
                /* Errata: Need to write lch even if not using chaining */
-               OMAP_DMA_CLNK_CTRL_REG(lch) = lch;
+               dma_write(lch, CLNK_CTRL(lch));
        }
 
        omap_enable_channel_irq(lch);
 
-       /* Errata: On ES2.0 BUFFERING disable must be set.
-        * This will always fail on ES1.0 */
-       if (cpu_is_omap24xx()) {
-               OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
-       }
+       l = dma_read(CCR(lch));
+
+       /*
+        * Errata: On ES2.0 BUFFERING disable must be set.
+        * This will always fail on ES1.0
+        */
+       if (cpu_is_omap24xx())
+               l |= OMAP_DMA_CCR_EN;
 
-       OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
+       l |= OMAP_DMA_CCR_EN;
+       dma_write(l, CCR(lch));
 
        dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
 }
+EXPORT_SYMBOL(omap_start_dma);
 
 void omap_stop_dma(int lch)
 {
+       u32 l;
+
        if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
                int next_lch, cur_lch = lch;
-               char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
+               char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
 
                memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
                do {
@@ -840,18 +974,22 @@ void omap_stop_dma(int lch)
 
        /* Disable all interrupts on the channel */
        if (cpu_class_is_omap1())
-               OMAP_DMA_CICR_REG(lch) = 0;
+               dma_write(0, CICR(lch));
+
+       l = dma_read(CCR(lch));
+       l &= ~OMAP_DMA_CCR_EN;
+       dma_write(l, CCR(lch));
 
-       OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
        dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
 }
+EXPORT_SYMBOL(omap_stop_dma);
 
 /*
  * Allows changing the DMA callback function or data. This may be needed if
  * the driver shares a single DMA channel for multiple dma triggers.
  */
 int omap_set_dma_callback(int lch,
-                         void (* callback)(int lch, u16 ch_status, void *data),
+                         void (*callback)(int lch, u16 ch_status, void *data),
                          void *data)
 {
        unsigned long flags;
@@ -871,6 +1009,7 @@ int omap_set_dma_callback(int lch,
 
        return 0;
 }
+EXPORT_SYMBOL(omap_set_dma_callback);
 
 /*
  * Returns current physical source address for the given DMA channel.
@@ -884,15 +1023,24 @@ dma_addr_t omap_get_dma_src_pos(int lch)
 {
        dma_addr_t offset = 0;
 
-       if (cpu_class_is_omap1())
-               offset = (dma_addr_t) (OMAP1_DMA_CSSA_L_REG(lch) |
-                                      (OMAP1_DMA_CSSA_U_REG(lch) << 16));
+       if (cpu_is_omap15xx())
+               offset = dma_read(CPC(lch));
+       else
+               offset = dma_read(CSAC(lch));
 
-       if (cpu_class_is_omap2())
-               offset = OMAP_DMA_CSAC_REG(lch);
+       /*
+        * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
+        * read before the DMA controller finished disabling the channel.
+        */
+       if (!cpu_is_omap15xx() && offset == 0)
+               offset = dma_read(CSAC(lch));
+
+       if (cpu_class_is_omap1())
+               offset |= (dma_read(CSSA_U(lch)) << 16);
 
        return offset;
 }
+EXPORT_SYMBOL(omap_get_dma_src_pos);
 
 /*
  * Returns current physical destination address for the given DMA channel.
@@ -906,25 +1054,30 @@ dma_addr_t omap_get_dma_dst_pos(int lch)
 {
        dma_addr_t offset = 0;
 
-       if (cpu_class_is_omap1())
-               offset = (dma_addr_t) (OMAP1_DMA_CDSA_L_REG(lch) |
-                                      (OMAP1_DMA_CDSA_U_REG(lch) << 16));
+       if (cpu_is_omap15xx())
+               offset = dma_read(CPC(lch));
+       else
+               offset = dma_read(CDAC(lch));
 
-       if (cpu_class_is_omap2())
-               offset = OMAP_DMA_CDAC_REG(lch);
+       /*
+        * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
+        * read before the DMA controller finished disabling the channel.
+        */
+       if (!cpu_is_omap15xx() && offset == 0)
+               offset = dma_read(CDAC(lch));
+
+       if (cpu_class_is_omap1())
+               offset |= (dma_read(CDSA_U(lch)) << 16);
 
        return offset;
 }
+EXPORT_SYMBOL(omap_get_dma_dst_pos);
 
-/*
- * Returns current source transfer counting for the given DMA channel.
- * Can be used to monitor the progress of a transfer inside a block.
- * It must be called with disabled interrupts.
- */
-int omap_get_dma_src_addr_counter(int lch)
+int omap_get_dma_active_status(int lch)
 {
-       return (dma_addr_t) OMAP_DMA_CSAC_REG(lch);
+       return (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN) != 0;
 }
+EXPORT_SYMBOL(omap_get_dma_active_status);
 
 int omap_dma_running(void)
 {
@@ -936,7 +1089,7 @@ int omap_dma_running(void)
                        return 1;
 
        for (lch = 0; lch < dma_chan_count; lch++)
-               if (OMAP_DMA_CCR_REG(lch) & OMAP_DMA_CCR_EN)
+               if (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN)
                        return 1;
 
        return 0;
@@ -947,7 +1100,7 @@ int omap_dma_running(void)
  * For this DMA link to start, you still need to start (see omap_start_dma)
  * the first one. That will fire up the entire queue.
  */
-void omap_dma_link_lch (int lch_head, int lch_queue)
+void omap_dma_link_lch(int lch_head, int lch_queue)
 {
        if (omap_dma_in_1510_mode()) {
                printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
@@ -964,11 +1117,12 @@ void omap_dma_link_lch (int lch_head, int lch_queue)
 
        dma_chan[lch_head].next_lch = lch_queue;
 }
+EXPORT_SYMBOL(omap_dma_link_lch);
 
 /*
  * Once the DMA queue is stopped, we can destroy it.
  */
-void omap_dma_unlink_lch (int lch_head, int lch_queue)
+void omap_dma_unlink_lch(int lch_head, int lch_queue)
 {
        if (omap_dma_in_1510_mode()) {
                printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
@@ -983,7 +1137,6 @@ void omap_dma_unlink_lch (int lch_head, int lch_queue)
                dump_stack();
        }
 
-
        if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
            (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
                printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
@@ -993,12 +1146,15 @@ void omap_dma_unlink_lch (int lch_head, int lch_queue)
 
        dma_chan[lch_head].next_lch = -1;
 }
+EXPORT_SYMBOL(omap_dma_unlink_lch);
+
+/*----------------------------------------------------------------------------*/
 
 #ifndef CONFIG_ARCH_OMAP1
 /* Create chain of DMA channesls */
 static void create_dma_lch_chain(int lch_head, int lch_queue)
 {
-       u32 w;
+       u32 l;
 
        /* Check if this is the first link in chain */
        if (dma_chan[lch_head].next_linked_ch == -1) {
@@ -1018,15 +1174,15 @@ static void create_dma_lch_chain(int lch_head, int lch_queue)
                                        lch_queue;
        }
 
-       w = OMAP_DMA_CLNK_CTRL_REG(lch_head);
-       w &= ~(0x1f);
-       w |= lch_queue;
-       OMAP_DMA_CLNK_CTRL_REG(lch_head) = w;
+       l = dma_read(CLNK_CTRL(lch_head));
+       l &= ~(0x1f);
+       l |= lch_queue;
+       dma_write(l, CLNK_CTRL(lch_head));
 
-       w = OMAP_DMA_CLNK_CTRL_REG(lch_queue);
-       w &= ~(0x1f);
-       w |= (dma_chan[lch_queue].next_linked_ch);
-       OMAP_DMA_CLNK_CTRL_REG(lch_queue) = w;
+       l = dma_read(CLNK_CTRL(lch_queue));
+       l &= ~(0x1f);
+       l |= (dma_chan[lch_queue].next_linked_ch);
+       dma_write(l, CLNK_CTRL(lch_queue));
 }
 
 /**
@@ -1061,7 +1217,7 @@ int omap_request_dma_chain(int dev_id, const char *dev_name,
        }
 
        if (unlikely((no_of_chans < 1
-                       || no_of_chans > OMAP_LOGICAL_DMA_CH_COUNT))) {
+                       || no_of_chans > dma_lch_count))) {
                printk(KERN_ERR "Invalid Number of channels requested\n");
                return -EINVAL;
        }
@@ -1116,6 +1272,7 @@ int omap_request_dma_chain(int dev_id, const char *dev_name,
                for (i = 0; i < (no_of_chans - 1); i++)
                        create_dma_lch_chain(channels[i], channels[i + 1]);
        }
+
        return 0;
 }
 EXPORT_SYMBOL(omap_request_dma_chain);
@@ -1138,7 +1295,7 @@ int omap_modify_dma_chain_params(int chain_id,
 
        /* Check for input params */
        if (unlikely((chain_id < 0
-                       || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+                       || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1158,6 +1315,7 @@ int omap_modify_dma_chain_params(int chain_id,
                 */
                omap_set_dma_params(channels[i], &params);
        }
+
        return 0;
 }
 EXPORT_SYMBOL(omap_modify_dma_chain_params);
@@ -1176,7 +1334,7 @@ int omap_free_dma_chain(int chain_id)
        u32 i;
 
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1201,6 +1359,7 @@ int omap_free_dma_chain(int chain_id)
        dma_linked_lch[chain_id].linked_dmach_q = NULL;
        dma_linked_lch[chain_id].chain_mode = -1;
        dma_linked_lch[chain_id].chain_state = -1;
+
        return (0);
 }
 EXPORT_SYMBOL(omap_free_dma_chain);
@@ -1216,7 +1375,7 @@ EXPORT_SYMBOL(omap_free_dma_chain);
 int omap_dma_chain_status(int chain_id)
 {
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1231,6 +1390,7 @@ int omap_dma_chain_status(int chain_id)
 
        if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
                return OMAP_DMA_CHAIN_INACTIVE;
+
        return OMAP_DMA_CHAIN_ACTIVE;
 }
 EXPORT_SYMBOL(omap_dma_chain_status);
@@ -1253,11 +1413,13 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
                        int elem_count, int frame_count, void *callbk_data)
 {
        int *channels;
-       u32 w, lch;
+       u32 l, lch;
        int start_dma = 0;
 
-       /* if buffer size is less than 1 then there is
-        * no use of starting the chain */
+       /*
+        * if buffer size is less than 1 then there is
+        * no use of starting the chain
+        */
        if (elem_count < 1) {
                printk(KERN_ERR "Invalid buffer size\n");
                return -EINVAL;
@@ -1265,7 +1427,7 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
 
        /* Check for input params */
        if (unlikely((chain_id < 0
-                       || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+                       || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1294,20 +1456,24 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
 
        /* Set the params to the free channel */
        if (src_start != 0)
-               OMAP2_DMA_CSSA_REG(lch) = src_start;
+               dma_write(src_start, CSSA(lch));
        if (dest_start != 0)
-               OMAP2_DMA_CDSA_REG(lch) = dest_start;
+               dma_write(dest_start, CDSA(lch));
 
        /* Write the buffer size */
-       OMAP_DMA_CEN_REG(lch) = elem_count;
-       OMAP_DMA_CFN_REG(lch) = frame_count;
+       dma_write(elem_count, CEN(lch));
+       dma_write(frame_count, CFN(lch));
 
-       /* If the chain is dynamically linked,
-        * then we may have to start the chain if its not active */
+       /*
+        * If the chain is dynamically linked,
+        * then we may have to start the chain if its not active
+        */
        if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
 
-               /* In Dynamic chain, if the chain is not started,
-                * queue the channel */
+               /*
+                * In Dynamic chain, if the chain is not started,
+                * queue the channel
+                */
                if (dma_linked_lch[chain_id].chain_state ==
                                                DMA_CHAIN_NOTSTARTED) {
                        /* Enable the link in previous channel */
@@ -1317,8 +1483,10 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
                        dma_chan[lch].state = DMA_CH_QUEUED;
                }
 
-               /* Chain is already started, make sure its active,
-                * if not then start the chain */
+               /*
+                * Chain is already started, make sure its active,
+                * if not then start the chain
+                */
                else {
                        start_dma = 1;
 
@@ -1327,8 +1495,8 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
                                enable_lnk(dma_chan[lch].prev_linked_ch);
                                dma_chan[lch].state = DMA_CH_QUEUED;
                                start_dma = 0;
-                               if (0 == ((1 << 7) & (OMAP_DMA_CCR_REG
-                                       (dma_chan[lch].prev_linked_ch)))) {
+                               if (0 == ((1 << 7) & dma_read(
+                                       CCR(dma_chan[lch].prev_linked_ch)))) {
                                        disable_lnk(dma_chan[lch].
                                                    prev_linked_ch);
                                        pr_debug("\n prev ch is stopped\n");
@@ -1344,27 +1512,28 @@ int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
                        }
                        omap_enable_channel_irq(lch);
 
-                       w = OMAP_DMA_CCR_REG(lch);
+                       l = dma_read(CCR(lch));
 
-                       if ((0 == (w & (1 << 24))))
-                               w &= ~(1 << 25);
+                       if ((0 == (l & (1 << 24))))
+                               l &= ~(1 << 25);
                        else
-                               w |= (1 << 25);
+                               l |= (1 << 25);
                        if (start_dma == 1) {
-                               if (0 == (w & (1 << 7))) {
-                                       w |= (1 << 7);
+                               if (0 == (l & (1 << 7))) {
+                                       l |= (1 << 7);
                                        dma_chan[lch].state = DMA_CH_STARTED;
                                        pr_debug("starting %d\n", lch);
-                                       OMAP_DMA_CCR_REG(lch) = w;
+                                       dma_write(l, CCR(lch));
                                } else
                                        start_dma = 0;
                        } else {
-                               if (0 == (w & (1 << 7)))
-                                       OMAP_DMA_CCR_REG(lch) = w;
+                               if (0 == (l & (1 << 7)))
+                                       dma_write(l, CCR(lch));
                        }
                        dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
                }
        }
+
        return 0;
 }
 EXPORT_SYMBOL(omap_dma_chain_a_transfer);
@@ -1380,9 +1549,9 @@ EXPORT_SYMBOL(omap_dma_chain_a_transfer);
 int omap_start_dma_chain_transfers(int chain_id)
 {
        int *channels;
-       u32 w, i;
+       u32 l, i;
 
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1404,18 +1573,19 @@ int omap_start_dma_chain_transfers(int chain_id)
                omap_enable_channel_irq(channels[0]);
        }
 
-       w = OMAP_DMA_CCR_REG(channels[0]);
-       w |= (1 << 7);
+       l = dma_read(CCR(channels[0]));
+       l |= (1 << 7);
        dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
        dma_chan[channels[0]].state = DMA_CH_STARTED;
 
-       if ((0 == (w & (1 << 24))))
-               w &= ~(1 << 25);
+       if ((0 == (l & (1 << 24))))
+               l &= ~(1 << 25);
        else
-               w |= (1 << 25);
-       OMAP_DMA_CCR_REG(channels[0]) = w;
+               l |= (1 << 25);
+       dma_write(l, CCR(channels[0]));
 
        dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
+
        return 0;
 }
 EXPORT_SYMBOL(omap_start_dma_chain_transfers);
@@ -1431,11 +1601,11 @@ EXPORT_SYMBOL(omap_start_dma_chain_transfers);
 int omap_stop_dma_chain_transfers(int chain_id)
 {
        int *channels;
-       u32 w, i;
+       u32 l, i;
        u32 sys_cf;
 
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1447,21 +1617,22 @@ int omap_stop_dma_chain_transfers(int chain_id)
        }
        channels = dma_linked_lch[chain_id].linked_dmach_q;
 
-       /* DMA Errata:
+       /*
+        * DMA Errata:
         * Special programming model needed to disable DMA before end of block
         */
-       sys_cf = omap_readl(OMAP_DMA4_OCP_SYSCONFIG);
-       w = sys_cf;
+       sys_cf = dma_read(OCP_SYSCONFIG);
+       l = sys_cf;
        /* Middle mode reg set no Standby */
-       w &= ~((1 << 12)|(1 << 13));
-       omap_writel(w, OMAP_DMA4_OCP_SYSCONFIG);
+       l &= ~((1 << 12)|(1 << 13));
+       dma_write(l, OCP_SYSCONFIG);
 
        for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
 
                /* Stop the Channel transmission */
-               w = OMAP_DMA_CCR_REG(channels[i]);
-               w &= ~(1 << 7);
-               OMAP_DMA_CCR_REG(channels[i]) = w;
+               l = dma_read(CCR(channels[i]));
+               l &= ~(1 << 7);
+               dma_write(l, CCR(channels[i]));
 
                /* Disable the link in all the channels */
                disable_lnk(channels[i]);
@@ -1474,7 +1645,8 @@ int omap_stop_dma_chain_transfers(int chain_id)
        OMAP_DMA_CHAIN_QINIT(chain_id);
 
        /* Errata - put in the old value */
-       omap_writel(sys_cf, OMAP_DMA4_OCP_SYSCONFIG);
+       dma_write(sys_cf, OCP_SYSCONFIG);
+
        return 0;
 }
 EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
@@ -1497,7 +1669,7 @@ int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
        int *channels;
 
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1515,8 +1687,8 @@ int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
        /* Get the current channel */
        lch = channels[dma_linked_lch[chain_id].q_head];
 
-       *ei = OMAP2_DMA_CCEN_REG(lch);
-       *fi = OMAP2_DMA_CCFN_REG(lch);
+       *ei = dma_read(CCEN(lch));
+       *fi = dma_read(CCFN(lch));
 
        return 0;
 }
@@ -1537,7 +1709,7 @@ int omap_get_dma_chain_dst_pos(int chain_id)
        int *channels;
 
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1553,7 +1725,7 @@ int omap_get_dma_chain_dst_pos(int chain_id)
        /* Get the current channel */
        lch = channels[dma_linked_lch[chain_id].q_head];
 
-       return (OMAP_DMA_CDAC_REG(lch));
+       return dma_read(CDAC(lch));
 }
 EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
 
@@ -1571,7 +1743,7 @@ int omap_get_dma_chain_src_pos(int chain_id)
        int *channels;
 
        /* Check for input params */
-       if (unlikely((chain_id < 0 || chain_id >= OMAP_LOGICAL_DMA_CH_COUNT))) {
+       if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
                printk(KERN_ERR "Invalid chain id\n");
                return -EINVAL;
        }
@@ -1587,10 +1759,10 @@ int omap_get_dma_chain_src_pos(int chain_id)
        /* Get the current channel */
        lch = channels[dma_linked_lch[chain_id].q_head];
 
-       return (OMAP_DMA_CSAC_REG(lch));
+       return dma_read(CSAC(lch));
 }
 EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
-#endif
+#endif /* ifndef CONFIG_ARCH_OMAP1 */
 
 /*----------------------------------------------------------------------------*/
 
@@ -1598,13 +1770,13 @@ EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
 
 static int omap1_dma_handle_ch(int ch)
 {
-       u16 csr;
+       u32 csr;
 
        if (enable_1510_mode && ch >= 6) {
                csr = dma_chan[ch].saved_csr;
                dma_chan[ch].saved_csr = 0;
        } else
-               csr = OMAP_DMA_CSR_REG(ch);
+               csr = dma_read(CSR(ch));
        if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
                dma_chan[ch + 6].saved_csr = csr >> 7;
                csr &= 0x7f;
@@ -1626,6 +1798,7 @@ static int omap1_dma_handle_ch(int ch)
                dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
        if (likely(dma_chan[ch].callback != NULL))
                dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
+
        return 1;
 }
 
@@ -1656,12 +1829,13 @@ static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
 
 static int omap2_dma_handle_ch(int ch)
 {
-       u32 status = OMAP_DMA_CSR_REG(ch);
+       u32 status = dma_read(CSR(ch));
 
        if (!status) {
                if (printk_ratelimit())
-                       printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n", ch);
-               omap_writel(1 << ch, OMAP_DMA4_IRQSTATUS_L0);
+                       printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n",
+                               ch);
+               dma_write(1 << ch, IRQSTATUS_L0);
                return 0;
        }
        if (unlikely(dma_chan[ch].dev_id == -1)) {
@@ -1684,14 +1858,14 @@ static int omap2_dma_handle_ch(int ch)
                printk(KERN_INFO "DMA misaligned error with device %d\n",
                       dma_chan[ch].dev_id);
 
-       OMAP_DMA_CSR_REG(ch) = OMAP2_DMA_CSR_CLEAR_MASK;
-       omap_writel(1 << ch, OMAP_DMA4_IRQSTATUS_L0);
+       dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
+       dma_write(1 << ch, IRQSTATUS_L0);
 
        /* If the ch is not chained then chain_id will be -1 */
        if (dma_chan[ch].chain_id != -1) {
                int chain_id = dma_chan[ch].chain_id;
                dma_chan[ch].state = DMA_CH_NOTSTARTED;
-               if (OMAP_DMA_CLNK_CTRL_REG(ch) & (1 << 15))
+               if (dma_read(CLNK_CTRL(ch)) & (1 << 15))
                        dma_chan[dma_chan[ch].next_linked_ch].state =
                                                        DMA_CH_STARTED;
                if (dma_linked_lch[chain_id].chain_mode ==
@@ -1701,13 +1875,13 @@ static int omap2_dma_handle_ch(int ch)
                if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
                        OMAP_DMA_CHAIN_INCQHEAD(chain_id);
 
-               status = OMAP_DMA_CSR_REG(ch);
+               status = dma_read(CSR(ch));
        }
 
        if (likely(dma_chan[ch].callback != NULL))
                dma_chan[ch].callback(ch, status, dma_chan[ch].data);
 
-       OMAP_DMA_CSR_REG(ch) = status;
+       dma_write(status, CSR(ch));
 
        return 0;
 }
@@ -1718,13 +1892,13 @@ static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
        u32 val;
        int i;
 
-       val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
+       val = dma_read(IRQSTATUS_L0);
        if (val == 0) {
                if (printk_ratelimit())
                        printk(KERN_WARNING "Spurious DMA IRQ\n");
                return IRQ_HANDLED;
        }
-       for (i = 0; i < OMAP_LOGICAL_DMA_CH_COUNT && val != 0; i++) {
+       for (i = 0; i < dma_lch_count && val != 0; i++) {
                if (val & 1)
                        omap2_dma_handle_ch(i);
                val >>= 1;
@@ -1748,7 +1922,7 @@ static struct irqaction omap24xx_dma_irq;
 static struct lcd_dma_info {
        spinlock_t lock;
        int reserved;
-       void (* callback)(u16 status, void *data);
+       void (*callback)(u16 status, void *data);
        void *cb_data;
 
        int active;
@@ -1770,6 +1944,7 @@ void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
        lcd_dma.xres = fb_xres;
        lcd_dma.yres = fb_yres;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_b1);
 
 void omap_set_lcd_dma_src_port(int port)
 {
@@ -1780,12 +1955,13 @@ void omap_set_lcd_dma_ext_controller(int external)
 {
        lcd_dma.ext_ctrl = external;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
 
 void omap_set_lcd_dma_single_transfer(int single)
 {
        lcd_dma.single_transfer = single;
 }
-
+EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
 
 void omap_set_lcd_dma_b1_rotation(int rotate)
 {
@@ -1796,6 +1972,7 @@ void omap_set_lcd_dma_b1_rotation(int rotate)
        }
        lcd_dma.rotate = rotate;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
 
 void omap_set_lcd_dma_b1_mirror(int mirror)
 {
@@ -1805,6 +1982,7 @@ void omap_set_lcd_dma_b1_mirror(int mirror)
        }
        lcd_dma.mirror = mirror;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
 
 void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
 {
@@ -1815,6 +1993,7 @@ void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
        }
        lcd_dma.vxres = vxres;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
 
 void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
 {
@@ -1825,6 +2004,7 @@ void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
        lcd_dma.xscale = xscale;
        lcd_dma.yscale = yscale;
 }
+EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
 
 static void set_b1_regs(void)
 {
@@ -1855,8 +2035,11 @@ static void set_b1_regs(void)
        xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
        yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
        BUG_ON(vxres < lcd_dma.xres);
-#define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
+
+#define PIXADDR(x, y) (lcd_dma.addr +                                  \
+               ((y) * vxres * yscale + (x) * xscale) * es)
 #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
+
        switch (lcd_dma.rotate) {
        case 0:
                if (!lcd_dma.mirror) {
@@ -1865,8 +2048,8 @@ static void set_b1_regs(void)
                        /* 1510 DMA requires the bottom address to be 2 more
                         * than the actual last memory access location. */
                        if (omap_dma_in_1510_mode() &&
-                           lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
-                               bottom += 2;
+                               lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
+                                       bottom += 2;
                        ei = PIXSTEP(0, 0, 1, 0);
                        fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
                } else {
@@ -1993,7 +2176,7 @@ static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
+int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
                         void *data)
 {
        spin_lock_irq(&lcd_dma.lock);
@@ -2019,6 +2202,7 @@ int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
 
        return 0;
 }
+EXPORT_SYMBOL(omap_request_lcd_dma);
 
 void omap_free_lcd_dma(void)
 {
@@ -2035,12 +2219,14 @@ void omap_free_lcd_dma(void)
        lcd_dma.reserved = 0;
        spin_unlock(&lcd_dma.lock);
 }
+EXPORT_SYMBOL(omap_free_lcd_dma);
 
 void omap_enable_lcd_dma(void)
 {
        u16 w;
 
-       /* Set the Enable bit only if an external controller is
+       /*
+        * Set the Enable bit only if an external controller is
         * connected. Otherwise the OMAP internal controller will
         * start the transfer when it gets enabled.
         */
@@ -2057,6 +2243,7 @@ void omap_enable_lcd_dma(void)
        w |= 1 << 7;
        omap_writew(w, OMAP1610_DMA_LCD_CCR);
 }
+EXPORT_SYMBOL(omap_enable_lcd_dma);
 
 void omap_setup_lcd_dma(void)
 {
@@ -2072,16 +2259,18 @@ void omap_setup_lcd_dma(void)
                u16 w;
 
                w = omap_readw(OMAP1610_DMA_LCD_CCR);
-               /* If DMA was already active set the end_prog bit to have
+               /*
+                * If DMA was already active set the end_prog bit to have
                 * the programmed register set loaded into the active
                 * register set.
                 */
                w |= 1 << 11;           /* End_prog */
                if (!lcd_dma.single_transfer)
-                       w |= (3 << 8);  /* Auto_init, repeat */
+                       w |= (3 << 8);  /* Auto_init, repeat */
                omap_writew(w, OMAP1610_DMA_LCD_CCR);
        }
 }
+EXPORT_SYMBOL(omap_setup_lcd_dma);
 
 void omap_stop_lcd_dma(void)
 {
@@ -2099,6 +2288,7 @@ void omap_stop_lcd_dma(void)
        w &= ~(1 << 8);
        omap_writew(w, OMAP1610_DMA_LCD_CTRL);
 }
+EXPORT_SYMBOL(omap_stop_lcd_dma);
 
 /*----------------------------------------------------------------------------*/
 
@@ -2106,27 +2296,55 @@ static int __init omap_init_dma(void)
 {
        int ch, r;
 
+       if (cpu_class_is_omap1()) {
+               omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP1_DMA_BASE);
+               dma_lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
+       } else if (cpu_is_omap24xx()) {
+               omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP24XX_DMA4_BASE);
+               dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
+       } else if (cpu_is_omap34xx()) {
+               omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP34XX_DMA4_BASE);
+               dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
+       } else {
+               pr_err("DMA init failed for unsupported omap\n");
+               return -ENODEV;
+       }
+
+       dma_chan = kzalloc(sizeof(struct omap_dma_lch) * dma_lch_count,
+                               GFP_KERNEL);
+       if (!dma_chan)
+               return -ENOMEM;
+
+       if (cpu_class_is_omap2()) {
+               dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
+                                               dma_lch_count, GFP_KERNEL);
+               if (!dma_linked_lch) {
+                       kfree(dma_chan);
+                       return -ENOMEM;
+               }
+       }
+
        if (cpu_is_omap15xx()) {
                printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
                dma_chan_count = 9;
                enable_1510_mode = 1;
        } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
                printk(KERN_INFO "OMAP DMA hardware version %d\n",
-                      omap_readw(OMAP_DMA_HW_ID));
+                      dma_read(HW_ID));
                printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
-                      (omap_readw(OMAP_DMA_CAPS_0_U) << 16) |
-                      omap_readw(OMAP_DMA_CAPS_0_L),
-                      (omap_readw(OMAP_DMA_CAPS_1_U) << 16) |
-                      omap_readw(OMAP_DMA_CAPS_1_L),
-                      omap_readw(OMAP_DMA_CAPS_2), omap_readw(OMAP_DMA_CAPS_3),
-                      omap_readw(OMAP_DMA_CAPS_4));
+                      (dma_read(CAPS_0_U) << 16) |
+                      dma_read(CAPS_0_L),
+                      (dma_read(CAPS_1_U) << 16) |
+                      dma_read(CAPS_1_L),
+                      dma_read(CAPS_2), dma_read(CAPS_3),
+                      dma_read(CAPS_4));
                if (!enable_1510_mode) {
                        u16 w;
 
                        /* Disable OMAP 3.0/3.1 compatibility mode. */
-                       w = omap_readw(OMAP_DMA_GSCR);
+                       w = dma_read(GSCR);
                        w |= 1 << 3;
-                       omap_writew(w, OMAP_DMA_GSCR);
+                       dma_write(w, GSCR);
                        dma_chan_count = 16;
                } else
                        dma_chan_count = 9;
@@ -2139,19 +2357,17 @@ static int __init omap_init_dma(void)
                        omap_writew(w, OMAP1610_DMA_LCD_CTRL);
                }
        } else if (cpu_class_is_omap2()) {
-               u8 revision = omap_readb(OMAP_DMA4_REVISION);
+               u8 revision = dma_read(REVISION) & 0xff;
                printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
                       revision >> 4, revision & 0xf);
-               dma_chan_count = OMAP_LOGICAL_DMA_CH_COUNT;
+               dma_chan_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
        } else {
                dma_chan_count = 0;
                return 0;
        }
 
-       memset(&lcd_dma, 0, sizeof(lcd_dma));
        spin_lock_init(&lcd_dma.lock);
        spin_lock_init(&dma_chan_lock);
-       memset(&dma_chan, 0, sizeof(dma_chan));
 
        for (ch = 0; ch < dma_chan_count; ch++) {
                omap_clear_dma(ch);
@@ -2162,8 +2378,10 @@ static int __init omap_init_dma(void)
                        continue;
 
                if (cpu_class_is_omap1()) {
-                       /* request_irq() doesn't like dev_id (ie. ch) being
-                        * zero, so we have to kludge around this. */
+                       /*
+                        * request_irq() doesn't like dev_id (ie. ch) being
+                        * zero, so we have to kludge around this.
+                        */
                        r = request_irq(omap1_dma_irq[ch],
                                        omap1_dma_irq_handler, 0, "DMA",
                                        (void *) (ch + 1));
@@ -2208,48 +2426,4 @@ static int __init omap_init_dma(void)
 
 arch_initcall(omap_init_dma);
 
-EXPORT_SYMBOL(omap_get_dma_src_pos);
-EXPORT_SYMBOL(omap_get_dma_dst_pos);
-EXPORT_SYMBOL(omap_get_dma_src_addr_counter);
-EXPORT_SYMBOL(omap_clear_dma);
-EXPORT_SYMBOL(omap_set_dma_priority);
-EXPORT_SYMBOL(omap_request_dma);
-EXPORT_SYMBOL(omap_free_dma);
-EXPORT_SYMBOL(omap_start_dma);
-EXPORT_SYMBOL(omap_stop_dma);
-EXPORT_SYMBOL(omap_set_dma_callback);
-EXPORT_SYMBOL(omap_enable_dma_irq);
-EXPORT_SYMBOL(omap_disable_dma_irq);
-
-EXPORT_SYMBOL(omap_set_dma_transfer_params);
-EXPORT_SYMBOL(omap_set_dma_color_mode);
-EXPORT_SYMBOL(omap_set_dma_write_mode);
-
-EXPORT_SYMBOL(omap_set_dma_src_params);
-EXPORT_SYMBOL(omap_set_dma_src_index);
-EXPORT_SYMBOL(omap_set_dma_src_data_pack);
-EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
-
-EXPORT_SYMBOL(omap_set_dma_dest_params);
-EXPORT_SYMBOL(omap_set_dma_dest_index);
-EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
-EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
-
-EXPORT_SYMBOL(omap_set_dma_params);
-
-EXPORT_SYMBOL(omap_dma_link_lch);
-EXPORT_SYMBOL(omap_dma_unlink_lch);
-
-EXPORT_SYMBOL(omap_request_lcd_dma);
-EXPORT_SYMBOL(omap_free_lcd_dma);
-EXPORT_SYMBOL(omap_enable_lcd_dma);
-EXPORT_SYMBOL(omap_setup_lcd_dma);
-EXPORT_SYMBOL(omap_stop_lcd_dma);
-EXPORT_SYMBOL(omap_set_lcd_dma_b1);
-EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
-EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
-EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
-EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
-EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
-EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
 
index 302ad8d..f22506a 100644 (file)
 #include <asm/arch/irqs.h>
 
 /* register offsets */
-#define OMAP_TIMER_ID_REG              0x00
-#define OMAP_TIMER_OCP_CFG_REG         0x10
-#define OMAP_TIMER_SYS_STAT_REG                0x14
-#define OMAP_TIMER_STAT_REG            0x18
-#define OMAP_TIMER_INT_EN_REG          0x1c
-#define OMAP_TIMER_WAKEUP_EN_REG       0x20
-#define OMAP_TIMER_CTRL_REG            0x24
-#define OMAP_TIMER_COUNTER_REG         0x28
-#define OMAP_TIMER_LOAD_REG            0x2c
-#define OMAP_TIMER_TRIGGER_REG         0x30
-#define OMAP_TIMER_WRITE_PEND_REG      0x34
-#define OMAP_TIMER_MATCH_REG           0x38
-#define OMAP_TIMER_CAPTURE_REG         0x3c
-#define OMAP_TIMER_IF_CTRL_REG         0x40
-
-/* timer control reg bits */
-#define OMAP_TIMER_CTRL_GPOCFG         (1 << 14)
-#define OMAP_TIMER_CTRL_CAPTMODE       (1 << 13)
-#define OMAP_TIMER_CTRL_PT             (1 << 12)
-#define OMAP_TIMER_CTRL_TCM_LOWTOHIGH  (0x1 << 8)
-#define OMAP_TIMER_CTRL_TCM_HIGHTOLOW  (0x2 << 8)
-#define OMAP_TIMER_CTRL_TCM_BOTHEDGES  (0x3 << 8)
-#define OMAP_TIMER_CTRL_SCPWM          (1 << 7)
-#define OMAP_TIMER_CTRL_CE             (1 << 6)        /* compare enable */
-#define OMAP_TIMER_CTRL_PRE            (1 << 5)        /* prescaler enable */
-#define OMAP_TIMER_CTRL_PTV_SHIFT      2               /* how much to shift the prescaler value */
-#define OMAP_TIMER_CTRL_AR             (1 << 1)        /* auto-reload enable */
-#define OMAP_TIMER_CTRL_ST             (1 << 0)        /* start timer */
+#define _OMAP_TIMER_ID_OFFSET          0x00
+#define _OMAP_TIMER_OCP_CFG_OFFSET     0x10
+#define _OMAP_TIMER_SYS_STAT_OFFSET    0x14
+#define _OMAP_TIMER_STAT_OFFSET                0x18
+#define _OMAP_TIMER_INT_EN_OFFSET      0x1c
+#define _OMAP_TIMER_WAKEUP_EN_OFFSET   0x20
+#define _OMAP_TIMER_CTRL_OFFSET                0x24
+#define                OMAP_TIMER_CTRL_GPOCFG          (1 << 14)
+#define                OMAP_TIMER_CTRL_CAPTMODE        (1 << 13)
+#define                OMAP_TIMER_CTRL_PT              (1 << 12)
+#define                OMAP_TIMER_CTRL_TCM_LOWTOHIGH   (0x1 << 8)
+#define                OMAP_TIMER_CTRL_TCM_HIGHTOLOW   (0x2 << 8)
+#define                OMAP_TIMER_CTRL_TCM_BOTHEDGES   (0x3 << 8)
+#define                OMAP_TIMER_CTRL_SCPWM           (1 << 7)
+#define                OMAP_TIMER_CTRL_CE              (1 << 6) /* compare enable */
+#define                OMAP_TIMER_CTRL_PRE             (1 << 5) /* prescaler enable */
+#define                OMAP_TIMER_CTRL_PTV_SHIFT       2 /* prescaler value shift */
+#define                OMAP_TIMER_CTRL_POSTED          (1 << 2)
+#define                OMAP_TIMER_CTRL_AR              (1 << 1) /* auto-reload enable */
+#define                OMAP_TIMER_CTRL_ST              (1 << 0) /* start timer */
+#define _OMAP_TIMER_COUNTER_OFFSET     0x28
+#define _OMAP_TIMER_LOAD_OFFSET                0x2c
+#define _OMAP_TIMER_TRIGGER_OFFSET     0x30
+#define _OMAP_TIMER_WRITE_PEND_OFFSET  0x34
+#define                WP_NONE                 0       /* no write pending bit */
+#define                WP_TCLR                 (1 << 0)
+#define                WP_TCRR                 (1 << 1)
+#define                WP_TLDR                 (1 << 2)
+#define                WP_TTGR                 (1 << 3)
+#define                WP_TMAR                 (1 << 4)
+#define                WP_TPIR                 (1 << 5)
+#define                WP_TNIR                 (1 << 6)
+#define                WP_TCVR                 (1 << 7)
+#define                WP_TOCR                 (1 << 8)
+#define                WP_TOWR                 (1 << 9)
+#define _OMAP_TIMER_MATCH_OFFSET       0x38
+#define _OMAP_TIMER_CAPTURE_OFFSET     0x3c
+#define _OMAP_TIMER_IF_CTRL_OFFSET     0x40
+#define _OMAP_TIMER_CAPTURE2_OFFSET            0x44    /* TCAR2, 34xx only */
+#define _OMAP_TIMER_TICK_POS_OFFSET            0x48    /* TPIR, 34xx only */
+#define _OMAP_TIMER_TICK_NEG_OFFSET            0x4c    /* TNIR, 34xx only */
+#define _OMAP_TIMER_TICK_COUNT_OFFSET          0x50    /* TCVR, 34xx only */
+#define _OMAP_TIMER_TICK_INT_MASK_SET_OFFSET   0x54    /* TOCR, 34xx only */
+#define _OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET 0x58    /* TOWR, 34xx only */
+
+/* register offsets with the write pending bit encoded */
+#define        WPSHIFT                                 16
+
+#define OMAP_TIMER_ID_REG                      (_OMAP_TIMER_ID_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_OCP_CFG_REG                 (_OMAP_TIMER_OCP_CFG_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_SYS_STAT_REG                        (_OMAP_TIMER_SYS_STAT_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_STAT_REG                    (_OMAP_TIMER_STAT_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_INT_EN_REG                  (_OMAP_TIMER_INT_EN_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_WAKEUP_EN_REG               (_OMAP_TIMER_WAKEUP_EN_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_CTRL_REG                    (_OMAP_TIMER_CTRL_OFFSET \
+                                                       | (WP_TCLR << WPSHIFT))
+
+#define OMAP_TIMER_COUNTER_REG                 (_OMAP_TIMER_COUNTER_OFFSET \
+                                                       | (WP_TCRR << WPSHIFT))
+
+#define OMAP_TIMER_LOAD_REG                    (_OMAP_TIMER_LOAD_OFFSET \
+                                                       | (WP_TLDR << WPSHIFT))
+
+#define OMAP_TIMER_TRIGGER_REG                 (_OMAP_TIMER_TRIGGER_OFFSET \
+                                                       | (WP_TTGR << WPSHIFT))
+
+#define OMAP_TIMER_WRITE_PEND_REG              (_OMAP_TIMER_WRITE_PEND_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_MATCH_REG                   (_OMAP_TIMER_MATCH_OFFSET \
+                                                       | (WP_TMAR << WPSHIFT))
+
+#define OMAP_TIMER_CAPTURE_REG                 (_OMAP_TIMER_CAPTURE_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_IF_CTRL_REG                 (_OMAP_TIMER_IF_CTRL_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_CAPTURE2_REG                        (_OMAP_TIMER_CAPTURE2_OFFSET \
+                                                       | (WP_NONE << WPSHIFT))
+
+#define OMAP_TIMER_TICK_POS_REG                        (_OMAP_TIMER_TICK_POS_OFFSET \
+                                                       | (WP_TPIR << WPSHIFT))
+
+#define OMAP_TIMER_TICK_NEG_REG                        (_OMAP_TIMER_TICK_NEG_OFFSET \
+                                                       | (WP_TNIR << WPSHIFT))
+
+#define OMAP_TIMER_TICK_COUNT_REG              (_OMAP_TIMER_TICK_COUNT_OFFSET \
+                                                       | (WP_TCVR << WPSHIFT))
+
+#define OMAP_TIMER_TICK_INT_MASK_SET_REG                               \
+               (_OMAP_TIMER_TICK_INT_MASK_SET_OFFSET | (WP_TOCR << WPSHIFT))
+
+#define OMAP_TIMER_TICK_INT_MASK_COUNT_REG                             \
+               (_OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET | (WP_TOWR << WPSHIFT))
 
 struct omap_dm_timer {
        unsigned long phys_base;
@@ -76,6 +155,7 @@ struct omap_dm_timer {
        void __iomem *io_base;
        unsigned reserved:1;
        unsigned enabled:1;
+       unsigned posted:1;
 };
 
 #ifdef CONFIG_ARCH_OMAP1
@@ -181,16 +261,34 @@ static struct clk **dm_source_clocks;
 
 static spinlock_t dm_timer_lock;
 
-static inline u32 omap_dm_timer_read_reg(struct omap_dm_timer *timer, int reg)
+/*
+ * Reads timer registers in posted and non-posted mode. The posted mode bit
+ * is encoded in reg. Note that in posted mode write pending bit must be
+ * checked. Otherwise a read of a non completed write will produce an error.
+ */
+static inline u32 omap_dm_timer_read_reg(struct omap_dm_timer *timer, u32 reg)
 {
-       return readl(timer->io_base + reg);
+       if (timer->posted)
+               while (readl(timer->io_base + (OMAP_TIMER_WRITE_PEND_REG & 0xff))
+                               & (reg >> WPSHIFT))
+                       cpu_relax();
+       return readl(timer->io_base + (reg & 0xff));
 }
 
-static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, int reg, u32 value)
+/*
+ * Writes timer registers in posted and non-posted mode. The posted mode bit
+ * is encoded in reg. Note that in posted mode the write pending bit must be
+ * checked. Otherwise a write on a register which has a pending write will be
+ * lost.
+ */
+static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg,
+                                               u32 value)
 {
-       writel(value, timer->io_base + reg);
-       while (omap_dm_timer_read_reg(timer, OMAP_TIMER_WRITE_PEND_REG))
-               ;
+       if (timer->posted)
+               while (readl(timer->io_base + (OMAP_TIMER_WRITE_PEND_REG & 0xff))
+                               & (reg >> WPSHIFT))
+                       cpu_relax();
+       writel(value, timer->io_base + (reg & 0xff));
 }
 
 static void omap_dm_timer_wait_for_reset(struct omap_dm_timer *timer)
@@ -217,17 +315,23 @@ static void omap_dm_timer_reset(struct omap_dm_timer *timer)
        }
        omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ);
 
-       /* Set to smart-idle mode */
        l = omap_dm_timer_read_reg(timer, OMAP_TIMER_OCP_CFG_REG);
-       l |= 0x02 << 3;
-
-       if (cpu_class_is_omap2() && timer == &dm_timers[0]) {
-               /* Enable wake-up only for GPT1 on OMAP2 CPUs*/
+       l |= 0x02 << 3;  /* Set to smart-idle mode */
+       l |= 0x2 << 8;   /* Set clock activity to perserve f-clock on idle */
+
+       /*
+        * Enable wake-up only for GPT1 on OMAP2 CPUs.
+        * FIXME: All timers should have wake-up enabled and clear
+        * PRCM status.
+        */
+       if (cpu_class_is_omap2() && (timer == &dm_timers[0]))
                l |= 1 << 2;
-               /* Non-posted mode */
-               omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0);
-       }
        omap_dm_timer_write_reg(timer, OMAP_TIMER_OCP_CFG_REG, l);
+
+       /* Match hardware reset default of posted mode */
+       omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG,
+                       OMAP_TIMER_CTRL_POSTED);
+       timer->posted = 1;
 }
 
 static void omap_dm_timer_prepare(struct omap_dm_timer *timer)
@@ -434,9 +538,32 @@ void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload,
                l &= ~OMAP_TIMER_CTRL_AR;
        omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
        omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load);
+
+       /* REVISIT: hw feature, ttgr overtaking tldr? */
+       while (readl(timer->io_base + (OMAP_TIMER_WRITE_PEND_REG & 0xff)))
+               cpu_relax();
+
        omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0);
 }
 
+/* Optimized set_load which removes costly spin wait in timer_start */
+void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload,
+                            unsigned int load)
+{
+       u32 l;
+
+       l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
+       if (autoreload)
+               l |= OMAP_TIMER_CTRL_AR;
+       else
+               l &= ~OMAP_TIMER_CTRL_AR;
+       l |= OMAP_TIMER_CTRL_ST;
+
+       omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, load);
+       omap_dm_timer_write_reg(timer, OMAP_TIMER_LOAD_REG, load);
+       omap_dm_timer_write_reg(timer, OMAP_TIMER_CTRL_REG, l);
+}
+
 void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable,
                             unsigned int match)
 {
@@ -451,7 +578,6 @@ void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable,
        omap_dm_timer_write_reg(timer, OMAP_TIMER_MATCH_REG, match);
 }
 
-
 void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on,
                           int toggle, int trigger)
 {
index 9cf83c4..c7f7406 100644 (file)
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/wait.h>
 #include <linux/completion.h>
 #include <linux/interrupt.h>
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
-
-#include <asm/io.h>
-#include <asm/irq.h>
+#include <linux/io.h>
 
 #include <asm/arch/dma.h>
-#include <asm/arch/mux.h>
-#include <asm/arch/irqs.h>
-#include <asm/arch/dsp_common.h>
 #include <asm/arch/mcbsp.h>
 
-#ifdef CONFIG_MCBSP_DEBUG
-#define DBG(x...)      printk(x)
-#else
-#define DBG(x...)                      do { } while (0)
-#endif
-
-struct omap_mcbsp {
-       u32                          io_base;
-       u8                           id;
-       u8                           free;
-       omap_mcbsp_word_length       rx_word_length;
-       omap_mcbsp_word_length       tx_word_length;
-
-       omap_mcbsp_io_type_t         io_type; /* IRQ or poll */
-       /* IRQ based TX/RX */
-       int                          rx_irq;
-       int                          tx_irq;
-
-       /* DMA stuff */
-       u8                           dma_rx_sync;
-       short                        dma_rx_lch;
-       u8                           dma_tx_sync;
-       short                        dma_tx_lch;
-
-       /* Completion queues */
-       struct completion            tx_irq_completion;
-       struct completion            rx_irq_completion;
-       struct completion            tx_dma_completion;
-       struct completion            rx_dma_completion;
-
-       spinlock_t                   lock;
-};
-
 static struct omap_mcbsp mcbsp[OMAP_MAX_MCBSP_COUNT];
-#ifdef CONFIG_ARCH_OMAP1
-static struct clk *mcbsp_dsp_ck = 0;
-static struct clk *mcbsp_api_ck = 0;
-static struct clk *mcbsp_dspxor_ck = 0;
-#endif
-#ifdef CONFIG_ARCH_OMAP2
-static struct clk *mcbsp1_ick = 0;
-static struct clk *mcbsp1_fck = 0;
-static struct clk *mcbsp2_ick = 0;
-static struct clk *mcbsp2_fck = 0;
-#endif
+
+#define omap_mcbsp_check_valid_id(id)  (mcbsp[id].pdata && \
+                                       mcbsp[id].pdata->ops && \
+                                       mcbsp[id].pdata->ops->check && \
+                                       (mcbsp[id].pdata->ops->check(id) == 0))
 
 static void omap_mcbsp_dump_reg(u8 id)
 {
-       DBG("**** MCBSP%d regs ****\n", mcbsp[id].id);
-       DBG("DRR2:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, DRR2));
-       DBG("DRR1:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, DRR1));
-       DBG("DXR2:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, DXR2));
-       DBG("DXR1:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, DXR1));
-       DBG("SPCR2: 0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, SPCR2));
-       DBG("SPCR1: 0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, SPCR1));
-       DBG("RCR2:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, RCR2));
-       DBG("RCR1:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, RCR1));
-       DBG("XCR2:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, XCR2));
-       DBG("XCR1:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, XCR1));
-       DBG("SRGR2: 0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, SRGR2));
-       DBG("SRGR1: 0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, SRGR1));
-       DBG("PCR0:  0x%04x\n", OMAP_MCBSP_READ(mcbsp[id].io_base, PCR0));
-       DBG("***********************\n");
+       dev_dbg(mcbsp[id].dev, "**** McBSP%d regs ****\n", mcbsp[id].id);
+       dev_dbg(mcbsp[id].dev, "DRR2:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, DRR2));
+       dev_dbg(mcbsp[id].dev, "DRR1:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, DRR1));
+       dev_dbg(mcbsp[id].dev, "DXR2:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, DXR2));
+       dev_dbg(mcbsp[id].dev, "DXR1:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, DXR1));
+       dev_dbg(mcbsp[id].dev, "SPCR2: 0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, SPCR2));
+       dev_dbg(mcbsp[id].dev, "SPCR1: 0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, SPCR1));
+       dev_dbg(mcbsp[id].dev, "RCR2:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, RCR2));
+       dev_dbg(mcbsp[id].dev, "RCR1:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, RCR1));
+       dev_dbg(mcbsp[id].dev, "XCR2:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, XCR2));
+       dev_dbg(mcbsp[id].dev, "XCR1:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, XCR1));
+       dev_dbg(mcbsp[id].dev, "SRGR2: 0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, SRGR2));
+       dev_dbg(mcbsp[id].dev, "SRGR1: 0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, SRGR1));
+       dev_dbg(mcbsp[id].dev, "PCR0:  0x%04x\n",
+                       OMAP_MCBSP_READ(mcbsp[id].io_base, PCR0));
+       dev_dbg(mcbsp[id].dev, "***********************\n");
 }
 
 static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
 {
        struct omap_mcbsp *mcbsp_tx = dev_id;
 
-       DBG("TX IRQ callback : 0x%x\n",
-           OMAP_MCBSP_READ(mcbsp_tx->io_base, SPCR2));
+       dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n",
+               OMAP_MCBSP_READ(mcbsp_tx->io_base, SPCR2));
 
        complete(&mcbsp_tx->tx_irq_completion);
+
        return IRQ_HANDLED;
 }
 
@@ -111,10 +82,11 @@ static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
 {
        struct omap_mcbsp *mcbsp_rx = dev_id;
 
-       DBG("RX IRQ callback : 0x%x\n",
-           OMAP_MCBSP_READ(mcbsp_rx->io_base, SPCR2));
+       dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n",
+               OMAP_MCBSP_READ(mcbsp_rx->io_base, SPCR2));
 
        complete(&mcbsp_rx->rx_irq_completion);
+
        return IRQ_HANDLED;
 }
 
@@ -122,8 +94,8 @@ static void omap_mcbsp_tx_dma_callback(int lch, u16 ch_status, void *data)
 {
        struct omap_mcbsp *mcbsp_dma_tx = data;
 
-       DBG("TX DMA callback : 0x%x\n",
-           OMAP_MCBSP_READ(mcbsp_dma_tx->io_base, SPCR2));
+       dev_dbg(mcbsp_dma_tx->dev, "TX DMA callback : 0x%x\n",
+               OMAP_MCBSP_READ(mcbsp_dma_tx->io_base, SPCR2));
 
        /* We can free the channels */
        omap_free_dma(mcbsp_dma_tx->dma_tx_lch);
@@ -136,8 +108,8 @@ static void omap_mcbsp_rx_dma_callback(int lch, u16 ch_status, void *data)
 {
        struct omap_mcbsp *mcbsp_dma_rx = data;
 
-       DBG("RX DMA callback : 0x%x\n",
-           OMAP_MCBSP_READ(mcbsp_dma_rx->io_base, SPCR2));
+       dev_dbg(mcbsp_dma_rx->dev, "RX DMA callback : 0x%x\n",
+               OMAP_MCBSP_READ(mcbsp_dma_rx->io_base, SPCR2));
 
        /* We can free the channels */
        omap_free_dma(mcbsp_dma_rx->dma_rx_lch);
@@ -146,19 +118,24 @@ static void omap_mcbsp_rx_dma_callback(int lch, u16 ch_status, void *data)
        complete(&mcbsp_dma_rx->rx_dma_completion);
 }
 
-
 /*
  * omap_mcbsp_config simply write a config to the
  * appropriate McBSP.
  * You either call this function or set the McBSP registers
  * by yourself before calling omap_mcbsp_start().
  */
-
-void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config)
+void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config)
 {
-       u32 io_base = mcbsp[id].io_base;
+       u32 io_base;
+
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return;
+       }
 
-       DBG("OMAP-McBSP: McBSP%d  io_base: 0x%8x\n", id+1, io_base);
+       io_base = mcbsp[id].io_base;
+       dev_dbg(mcbsp[id].dev, "Configuring McBSP%d  io_base: 0x%8x\n",
+                       mcbsp[id].id, io_base);
 
        /* We write the given config */
        OMAP_MCBSP_WRITE(io_base, SPCR2, config->spcr2);
@@ -173,83 +150,7 @@ void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config
        OMAP_MCBSP_WRITE(io_base, MCR1, config->mcr1);
        OMAP_MCBSP_WRITE(io_base, PCR0, config->pcr0);
 }
-
-
-
-static int omap_mcbsp_check(unsigned int id)
-{
-       if (cpu_is_omap730()) {
-               if (id > OMAP_MAX_MCBSP_COUNT - 1) {
-                      printk(KERN_ERR "OMAP-McBSP: McBSP%d doesn't exist\n", id + 1);
-                      return -1;
-               }
-               return 0;
-       }
-
-       if (cpu_is_omap15xx() || cpu_is_omap16xx() || cpu_is_omap24xx()) {
-               if (id > OMAP_MAX_MCBSP_COUNT) {
-                       printk(KERN_ERR "OMAP-McBSP: McBSP%d doesn't exist\n", id + 1);
-                       return -1;
-               }
-               return 0;
-       }
-
-       return -1;
-}
-
-#ifdef CONFIG_ARCH_OMAP1
-static void omap_mcbsp_dsp_request(void)
-{
-       if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
-               int ret;
-
-               ret = omap_dsp_request_mem();
-               if (ret < 0) {
-                       printk(KERN_ERR "Could not get dsp memory: %i\n", ret);
-                       return;
-               }
-
-               clk_enable(mcbsp_dsp_ck);
-               clk_enable(mcbsp_api_ck);
-
-               /* enable 12MHz clock to mcbsp 1 & 3 */
-               clk_enable(mcbsp_dspxor_ck);
-
-               /*
-                * DSP external peripheral reset
-                * FIXME: This should be moved to dsp code
-                */
-               __raw_writew(__raw_readw(DSP_RSTCT2) | 1 | 1 << 1,
-                            DSP_RSTCT2);
-       }
-}
-
-static void omap_mcbsp_dsp_free(void)
-{
-       if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
-               omap_dsp_release_mem();
-               clk_disable(mcbsp_dspxor_ck);
-               clk_disable(mcbsp_dsp_ck);
-               clk_disable(mcbsp_api_ck);
-       }
-}
-#endif
-
-#ifdef CONFIG_ARCH_OMAP2
-static void omap2_mcbsp2_mux_setup(void)
-{
-       if (cpu_is_omap2420()) {
-               omap_cfg_reg(Y15_24XX_MCBSP2_CLKX);
-               omap_cfg_reg(R14_24XX_MCBSP2_FSX);
-               omap_cfg_reg(W15_24XX_MCBSP2_DR);
-               omap_cfg_reg(V15_24XX_MCBSP2_DX);
-               omap_cfg_reg(V14_24XX_GPIO117);
-       }
-       /*
-        * Need to add MUX settings for OMAP 2430 SDP
-        */
-}
-#endif
+EXPORT_SYMBOL(omap_mcbsp_config);
 
 /*
  * We can choose between IRQ based or polled IO.
@@ -257,13 +158,16 @@ static void omap2_mcbsp2_mux_setup(void)
  */
 int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type)
 {
-       if (omap_mcbsp_check(id) < 0)
-               return -EINVAL;
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
 
        spin_lock(&mcbsp[id].lock);
 
        if (!mcbsp[id].free) {
-               printk (KERN_ERR "OMAP-McBSP: McBSP%d is currently in use\n", id + 1);
+               dev_err(mcbsp[id].dev, "McBSP%d is currently in use\n",
+                       mcbsp[id].id);
                spin_unlock(&mcbsp[id].lock);
                return -EINVAL;
        }
@@ -274,38 +178,26 @@ int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type)
 
        return 0;
 }
+EXPORT_SYMBOL(omap_mcbsp_set_io_type);
 
 int omap_mcbsp_request(unsigned int id)
 {
        int err;
 
-       if (omap_mcbsp_check(id) < 0)
-               return -EINVAL;
-
-#ifdef CONFIG_ARCH_OMAP1
-       /*
-        * On 1510, 1610 and 1710, McBSP1 and McBSP3
-        * are DSP public peripherals.
-        */
-       if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3)
-               omap_mcbsp_dsp_request();
-#endif
-
-#ifdef CONFIG_ARCH_OMAP2
-       if (cpu_is_omap24xx()) {
-               if (id == OMAP_MCBSP1) {
-                       clk_enable(mcbsp1_ick);
-                       clk_enable(mcbsp1_fck);
-               } else {
-                       clk_enable(mcbsp2_ick);
-                       clk_enable(mcbsp2_fck);
-               }
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
        }
-#endif
+
+       if (mcbsp[id].pdata->ops->request)
+               mcbsp[id].pdata->ops->request(id);
+
+       clk_enable(mcbsp[id].clk);
 
        spin_lock(&mcbsp[id].lock);
        if (!mcbsp[id].free) {
-               printk (KERN_ERR "OMAP-McBSP: McBSP%d is currently in use\n", id + 1);
+               dev_err(mcbsp[id].dev, "McBSP%d is currently in use\n",
+                       mcbsp[id].id);
                spin_unlock(&mcbsp[id].lock);
                return -1;
        }
@@ -315,24 +207,23 @@ int omap_mcbsp_request(unsigned int id)
 
        if (mcbsp[id].io_type == OMAP_MCBSP_IRQ_IO) {
                /* We need to get IRQs here */
-               err = request_irq(mcbsp[id].tx_irq, omap_mcbsp_tx_irq_handler, 0,
-                                 "McBSP",
-                                 (void *) (&mcbsp[id]));
+               err = request_irq(mcbsp[id].tx_irq, omap_mcbsp_tx_irq_handler,
+                                       0, "McBSP", (void *) (&mcbsp[id]));
                if (err != 0) {
-                       printk(KERN_ERR "OMAP-McBSP: Unable to request TX IRQ %d for McBSP%d\n",
-                              mcbsp[id].tx_irq, mcbsp[id].id);
+                       dev_err(mcbsp[id].dev, "Unable to request TX IRQ %d "
+                                       "for McBSP%d\n", mcbsp[id].tx_irq,
+                                       mcbsp[id].id);
                        return err;
                }
 
                init_completion(&(mcbsp[id].tx_irq_completion));
 
-
-               err = request_irq(mcbsp[id].rx_irq, omap_mcbsp_rx_irq_handler, 0,
-                                 "McBSP",
-                                 (void *) (&mcbsp[id]));
+               err = request_irq(mcbsp[id].rx_irq, omap_mcbsp_rx_irq_handler,
+                                       0, "McBSP", (void *) (&mcbsp[id]));
                if (err != 0) {
-                       printk(KERN_ERR "OMAP-McBSP: Unable to request RX IRQ %d for McBSP%d\n",
-                              mcbsp[id].rx_irq, mcbsp[id].id);
+                       dev_err(mcbsp[id].dev, "Unable to request RX IRQ %d "
+                                       "for McBSP%d\n", mcbsp[id].rx_irq,
+                                       mcbsp[id].id);
                        free_irq(mcbsp[id].tx_irq, (void *) (&mcbsp[id]));
                        return err;
                }
@@ -341,36 +232,25 @@ int omap_mcbsp_request(unsigned int id)
        }
 
        return 0;
-
 }
+EXPORT_SYMBOL(omap_mcbsp_request);
 
 void omap_mcbsp_free(unsigned int id)
 {
-       if (omap_mcbsp_check(id) < 0)
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
                return;
-
-#ifdef CONFIG_ARCH_OMAP1
-       if (cpu_class_is_omap1()) {
-               if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3)
-                       omap_mcbsp_dsp_free();
        }
-#endif
-
-#ifdef CONFIG_ARCH_OMAP2
-       if (cpu_is_omap24xx()) {
-               if (id == OMAP_MCBSP1) {
-                       clk_disable(mcbsp1_ick);
-                       clk_disable(mcbsp1_fck);
-               } else {
-                       clk_disable(mcbsp2_ick);
-                       clk_disable(mcbsp2_fck);
-               }
-       }
-#endif
+
+       if (mcbsp[id].pdata->ops->free)
+               mcbsp[id].pdata->ops->free(id);
+
+       clk_disable(mcbsp[id].clk);
 
        spin_lock(&mcbsp[id].lock);
        if (mcbsp[id].free) {
-               printk (KERN_ERR "OMAP-McBSP: McBSP%d was not reserved\n", id + 1);
+               dev_err(mcbsp[id].dev, "McBSP%d was not reserved\n",
+                       mcbsp[id].id);
                spin_unlock(&mcbsp[id].lock);
                return;
        }
@@ -384,6 +264,7 @@ void omap_mcbsp_free(unsigned int id)
                free_irq(mcbsp[id].tx_irq, (void *) (&mcbsp[id]));
        }
 }
+EXPORT_SYMBOL(omap_mcbsp_free);
 
 /*
  * Here we start the McBSP, by enabling the sample
@@ -395,13 +276,15 @@ void omap_mcbsp_start(unsigned int id)
        u32 io_base;
        u16 w;
 
-       if (omap_mcbsp_check(id) < 0)
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
                return;
+       }
 
        io_base = mcbsp[id].io_base;
 
-       mcbsp[id].rx_word_length = ((OMAP_MCBSP_READ(io_base, RCR1) >> 5) & 0x7);
-       mcbsp[id].tx_word_length = ((OMAP_MCBSP_READ(io_base, XCR1) >> 5) & 0x7);
+       mcbsp[id].rx_word_length = (OMAP_MCBSP_READ(io_base, RCR1) >> 5) & 0x7;
+       mcbsp[id].tx_word_length = (OMAP_MCBSP_READ(io_base, XCR1) >> 5) & 0x7;
 
        /* Start the sample generator */
        w = OMAP_MCBSP_READ(io_base, SPCR2);
@@ -422,20 +305,22 @@ void omap_mcbsp_start(unsigned int id)
 
        /* Dump McBSP Regs */
        omap_mcbsp_dump_reg(id);
-
 }
+EXPORT_SYMBOL(omap_mcbsp_start);
 
 void omap_mcbsp_stop(unsigned int id)
 {
        u32 io_base;
        u16 w;
 
-       if (omap_mcbsp_check(id) < 0)
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
                return;
+       }
 
        io_base = mcbsp[id].io_base;
 
-        /* Reset transmitter */
+       /* Reset transmitter */
        w = OMAP_MCBSP_READ(io_base, SPCR2);
        OMAP_MCBSP_WRITE(io_base, SPCR2, w & ~(1));
 
@@ -447,12 +332,19 @@ void omap_mcbsp_stop(unsigned int id)
        w = OMAP_MCBSP_READ(io_base, SPCR2);
        OMAP_MCBSP_WRITE(io_base, SPCR2, w & ~(1 << 6));
 }
-
+EXPORT_SYMBOL(omap_mcbsp_stop);
 
 /* polled mcbsp i/o operations */
 int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
 {
-       u32 base = mcbsp[id].io_base;
+       u32 base;
+
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+
+       base = mcbsp[id].io_base;
        writew(buf, base + OMAP_MCBSP_REG_DXR1);
        /* if frame sync error - clear the error */
        if (readw(base + OMAP_MCBSP_REG_SPCR2) & XSYNC_ERR) {
@@ -474,18 +366,27 @@ int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
                                       (XRST),
                                       base + OMAP_MCBSP_REG_SPCR2);
                                udelay(10);
-                               printk(KERN_ERR
-                                      " Could not write to McBSP Register\n");
+                               dev_err(mcbsp[id].dev, "Could not write to"
+                                       " McBSP%d Register\n", mcbsp[id].id);
                                return -2;
                        }
                }
        }
+
        return 0;
 }
+EXPORT_SYMBOL(omap_mcbsp_pollwrite);
 
-int omap_mcbsp_pollread(unsigned int id, u16 * buf)
+int omap_mcbsp_pollread(unsigned int id, u16 *buf)
 {
-       u32 base = mcbsp[id].io_base;
+       u32 base;
+
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+
+       base = mcbsp[id].io_base;
        /* if frame sync error - clear the error */
        if (readw(base + OMAP_MCBSP_REG_SPCR1) & RSYNC_ERR) {
                /* clear error */
@@ -506,15 +407,17 @@ int omap_mcbsp_pollread(unsigned int id, u16 * buf)
                                       (RRST),
                                       base + OMAP_MCBSP_REG_SPCR1);
                                udelay(10);
-                               printk(KERN_ERR
-                                      " Could not read from McBSP Register\n");
+                               dev_err(mcbsp[id].dev, "Could not read from"
+                                       " McBSP%d Register\n", mcbsp[id].id);
                                return -2;
                        }
                }
        }
        *buf = readw(base + OMAP_MCBSP_REG_DRR1);
+
        return 0;
 }
+EXPORT_SYMBOL(omap_mcbsp_pollread);
 
 /*
  * IRQ based word transmission.
@@ -522,12 +425,15 @@ int omap_mcbsp_pollread(unsigned int id, u16 * buf)
 void omap_mcbsp_xmit_word(unsigned int id, u32 word)
 {
        u32 io_base;
-       omap_mcbsp_word_length word_length = mcbsp[id].tx_word_length;
+       omap_mcbsp_word_length word_length;
 
-       if (omap_mcbsp_check(id) < 0)
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
                return;
+       }
 
        io_base = mcbsp[id].io_base;
+       word_length = mcbsp[id].tx_word_length;
 
        wait_for_completion(&(mcbsp[id].tx_irq_completion));
 
@@ -535,16 +441,20 @@ void omap_mcbsp_xmit_word(unsigned int id, u32 word)
                OMAP_MCBSP_WRITE(io_base, DXR2, word >> 16);
        OMAP_MCBSP_WRITE(io_base, DXR1, word & 0xffff);
 }
+EXPORT_SYMBOL(omap_mcbsp_xmit_word);
 
 u32 omap_mcbsp_recv_word(unsigned int id)
 {
        u32 io_base;
        u16 word_lsb, word_msb = 0;
-       omap_mcbsp_word_length word_length = mcbsp[id].rx_word_length;
+       omap_mcbsp_word_length word_length;
 
-       if (omap_mcbsp_check(id) < 0)
-               return -EINVAL;
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
 
+       word_length = mcbsp[id].rx_word_length;
        io_base = mcbsp[id].io_base;
 
        wait_for_completion(&(mcbsp[id].rx_irq_completion));
@@ -555,15 +465,24 @@ u32 omap_mcbsp_recv_word(unsigned int id)
 
        return (word_lsb | (word_msb << 16));
 }
-
+EXPORT_SYMBOL(omap_mcbsp_recv_word);
 
 int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word)
 {
-       u32 io_base = mcbsp[id].io_base;
-       omap_mcbsp_word_length tx_word_length = mcbsp[id].tx_word_length;
-       omap_mcbsp_word_length rx_word_length = mcbsp[id].rx_word_length;
+       u32 io_base;
+       omap_mcbsp_word_length tx_word_length;
+       omap_mcbsp_word_length rx_word_length;
        u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0;
 
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+
+       io_base = mcbsp[id].io_base;
+       tx_word_length = mcbsp[id].tx_word_length;
+       rx_word_length = mcbsp[id].rx_word_length;
+
        if (tx_word_length != rx_word_length)
                return -EINVAL;
 
@@ -577,7 +496,8 @@ int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word)
                        udelay(10);
                        OMAP_MCBSP_WRITE(io_base, SPCR2, spcr2 | XRST);
                        udelay(10);
-                       printk("McBSP transmitter not ready\n");
+                       dev_err(mcbsp[id].dev, "McBSP%d transmitter not "
+                               "ready\n", mcbsp[id].id);
                        return -EAGAIN;
                }
        }
@@ -597,7 +517,8 @@ int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word)
                        udelay(10);
                        OMAP_MCBSP_WRITE(io_base, SPCR1, spcr1 | RRST);
                        udelay(10);
-                       printk("McBSP receiver not ready\n");
+                       dev_err(mcbsp[id].dev, "McBSP%d receiver not "
+                               "ready\n", mcbsp[id].id);
                        return -EAGAIN;
                }
        }
@@ -609,14 +530,24 @@ int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word)
 
        return 0;
 }
+EXPORT_SYMBOL(omap_mcbsp_spi_master_xmit_word_poll);
 
-int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word)
+int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 *word)
 {
-       u32 io_base = mcbsp[id].io_base, clock_word = 0;
-       omap_mcbsp_word_length tx_word_length = mcbsp[id].tx_word_length;
-       omap_mcbsp_word_length rx_word_length = mcbsp[id].rx_word_length;
+       u32 io_base, clock_word = 0;
+       omap_mcbsp_word_length tx_word_length;
+       omap_mcbsp_word_length rx_word_length;
        u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0;
 
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+
+       io_base = mcbsp[id].io_base;
+       tx_word_length = mcbsp[id].tx_word_length;
+       rx_word_length = mcbsp[id].rx_word_length;
+
        if (tx_word_length != rx_word_length)
                return -EINVAL;
 
@@ -630,7 +561,8 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word)
                        udelay(10);
                        OMAP_MCBSP_WRITE(io_base, SPCR2, spcr2 | XRST);
                        udelay(10);
-                       printk("McBSP transmitter not ready\n");
+                       dev_err(mcbsp[id].dev, "McBSP%d transmitter not "
+                               "ready\n", mcbsp[id].id);
                        return -EAGAIN;
                }
        }
@@ -650,7 +582,8 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word)
                        udelay(10);
                        OMAP_MCBSP_WRITE(io_base, SPCR1, spcr1 | RRST);
                        udelay(10);
-                       printk("McBSP receiver not ready\n");
+                       dev_err(mcbsp[id].dev, "McBSP%d receiver not "
+                               "ready\n", mcbsp[id].id);
                        return -EAGAIN;
                }
        }
@@ -664,7 +597,7 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word)
 
        return 0;
 }
-
+EXPORT_SYMBOL(omap_mcbsp_spi_master_recv_word_poll);
 
 /*
  * Simple DMA based buffer rx/tx routines.
@@ -673,25 +606,32 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word)
  * For anything fancier, you should use your own customized DMA
  * routines and callbacks.
  */
-int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length)
+int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer,
+                               unsigned int length)
 {
        int dma_tx_ch;
        int src_port = 0;
        int dest_port = 0;
        int sync_dev = 0;
 
-       if (omap_mcbsp_check(id) < 0)
-               return -EINVAL;
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
 
-       if (omap_request_dma(mcbsp[id].dma_tx_sync, "McBSP TX", omap_mcbsp_tx_dma_callback,
-                            &mcbsp[id],
-                            &dma_tx_ch)) {
-               printk("OMAP-McBSP: Unable to request DMA channel for McBSP%d TX. Trying IRQ based TX\n", id+1);
+       if (omap_request_dma(mcbsp[id].dma_tx_sync, "McBSP TX",
+                               omap_mcbsp_tx_dma_callback,
+                               &mcbsp[id],
+                               &dma_tx_ch)) {
+               dev_err(mcbsp[id].dev, " Unable to request DMA channel for "
+                               "McBSP%d TX. Trying IRQ based TX\n",
+                               mcbsp[id].id);
                return -EAGAIN;
        }
        mcbsp[id].dma_tx_lch = dma_tx_ch;
 
-       DBG("TX DMA on channel %d\n", dma_tx_ch);
+       dev_err(mcbsp[id].dev, "McBSP%d TX DMA on channel %d\n", mcbsp[id].id,
+               dma_tx_ch);
 
        init_completion(&(mcbsp[id].tx_dma_completion));
 
@@ -699,7 +639,7 @@ int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int leng
                src_port = OMAP_DMA_PORT_TIPB;
                dest_port = OMAP_DMA_PORT_EMIFF;
        }
-       if (cpu_is_omap24xx())
+       if (cpu_class_is_omap2())
                sync_dev = mcbsp[id].dma_tx_sync;
 
        omap_set_dma_transfer_params(mcbsp[id].dma_tx_lch,
@@ -722,29 +662,37 @@ int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int leng
 
        omap_start_dma(mcbsp[id].dma_tx_lch);
        wait_for_completion(&(mcbsp[id].tx_dma_completion));
+
        return 0;
 }
+EXPORT_SYMBOL(omap_mcbsp_xmit_buffer);
 
-
-int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length)
+int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer,
+                               unsigned int length)
 {
        int dma_rx_ch;
        int src_port = 0;
        int dest_port = 0;
        int sync_dev = 0;
 
-       if (omap_mcbsp_check(id) < 0)
-               return -EINVAL;
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
 
-       if (omap_request_dma(mcbsp[id].dma_rx_sync, "McBSP RX", omap_mcbsp_rx_dma_callback,
-                            &mcbsp[id],
-                            &dma_rx_ch)) {
-               printk("Unable to request DMA channel for McBSP%d RX. Trying IRQ based RX\n", id+1);
+       if (omap_request_dma(mcbsp[id].dma_rx_sync, "McBSP RX",
+                               omap_mcbsp_rx_dma_callback,
+                               &mcbsp[id],
+                               &dma_rx_ch)) {
+               dev_err(mcbsp[id].dev, "Unable to request DMA channel for "
+                               "McBSP%d RX. Trying IRQ based RX\n",
+                               mcbsp[id].id);
                return -EAGAIN;
        }
        mcbsp[id].dma_rx_lch = dma_rx_ch;
 
-       DBG("RX DMA on channel %d\n", dma_rx_ch);
+       dev_err(mcbsp[id].dev, "McBSP%d RX DMA on channel %d\n", mcbsp[id].id,
+               dma_rx_ch);
 
        init_completion(&(mcbsp[id].rx_dma_completion));
 
@@ -752,14 +700,14 @@ int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int leng
                src_port = OMAP_DMA_PORT_TIPB;
                dest_port = OMAP_DMA_PORT_EMIFF;
        }
-       if (cpu_is_omap24xx())
+       if (cpu_class_is_omap2())
                sync_dev = mcbsp[id].dma_rx_sync;
 
        omap_set_dma_transfer_params(mcbsp[id].dma_rx_lch,
-                                    OMAP_DMA_DATA_TYPE_S16,
-                                    length >> 1, 1,
-                                    OMAP_DMA_SYNC_ELEMENT,
-        sync_dev, 0);
+                                       OMAP_DMA_DATA_TYPE_S16,
+                                       length >> 1, 1,
+                                       OMAP_DMA_SYNC_ELEMENT,
+                                       sync_dev, 0);
 
        omap_set_dma_src_params(mcbsp[id].dma_rx_lch,
                                src_port,
@@ -768,16 +716,17 @@ int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int leng
                                0, 0);
 
        omap_set_dma_dest_params(mcbsp[id].dma_rx_lch,
-                                dest_port,
-                                OMAP_DMA_AMODE_POST_INC,
-                                buffer,
-                                0, 0);
+                                       dest_port,
+                                       OMAP_DMA_AMODE_POST_INC,
+                                       buffer,
+                                       0, 0);
 
        omap_start_dma(mcbsp[id].dma_rx_lch);
        wait_for_completion(&(mcbsp[id].rx_dma_completion));
+
        return 0;
 }
-
+EXPORT_SYMBOL(omap_mcbsp_recv_buffer);
 
 /*
  * SPI wrapper.
@@ -785,12 +734,15 @@ int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int leng
  * this wrapper just need an omap_mcbsp_spi_cfg structure as an input.
  * Once this is done, you can call omap_mcbsp_start().
  */
-void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg)
+void omap_mcbsp_set_spi_mode(unsigned int id,
+                               const struct omap_mcbsp_spi_cfg *spi_cfg)
 {
        struct omap_mcbsp_reg_cfg mcbsp_cfg;
 
-       if (omap_mcbsp_check(id) < 0)
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
                return;
+       }
 
        memset(&mcbsp_cfg, 0, sizeof(struct omap_mcbsp_reg_cfg));
 
@@ -798,7 +750,7 @@ void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg *
        mcbsp_cfg.rcr1 |= (RWDLEN1(spi_cfg->word_length) | RFRLEN1(0));
        mcbsp_cfg.xcr1 |= (XWDLEN1(spi_cfg->word_length) | XFRLEN1(0));
 
-        /* Clock stop mode */
+       /* Clock stop mode */
        if (spi_cfg->clk_stp_mode == OMAP_MCBSP_CLK_STP_MODE_NO_DELAY)
                mcbsp_cfg.spcr1 |= (1 << 12);
        else
@@ -827,13 +779,12 @@ void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg *
 
        if (spi_cfg->spi_mode == OMAP_MCBSP_SPI_MASTER) {
                mcbsp_cfg.pcr0 |= CLKXM;
-               mcbsp_cfg.srgr1 |= CLKGDV(spi_cfg->clk_div -1);
+               mcbsp_cfg.srgr1 |= CLKGDV(spi_cfg->clk_div - 1);
                mcbsp_cfg.pcr0 |= FSXM;
                mcbsp_cfg.srgr2 &= ~FSGM;
                mcbsp_cfg.xcr2 |= XDATDLY(1);
                mcbsp_cfg.rcr2 |= RDATDLY(1);
-       }
-       else {
+       } else {
                mcbsp_cfg.pcr0 &= ~CLKXM;
                mcbsp_cfg.srgr1 |= CLKGDV(1);
                mcbsp_cfg.pcr0 &= ~FSXM;
@@ -846,199 +797,99 @@ void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg *
 
        omap_mcbsp_config(id, &mcbsp_cfg);
 }
-
+EXPORT_SYMBOL(omap_mcbsp_set_spi_mode);
 
 /*
  * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
  * 730 has only 2 McBSP, and both of them are MPU peripherals.
  */
-struct omap_mcbsp_info {
-       u32 virt_base;
-       u8 dma_rx_sync, dma_tx_sync;
-       u16 rx_irq, tx_irq;
-};
+static int __init omap_mcbsp_probe(struct platform_device *pdev)
+{
+       struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data;
+       int id = pdev->id - 1;
+       int ret = 0;
 
-#ifdef CONFIG_ARCH_OMAP730
-static const struct omap_mcbsp_info mcbsp_730[] = {
-       [0] = { .virt_base = io_p2v(OMAP730_MCBSP1_BASE),
-               .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
-               .rx_irq = INT_730_McBSP1RX,
-               .tx_irq = INT_730_McBSP1TX },
-       [1] = { .virt_base = io_p2v(OMAP730_MCBSP2_BASE),
-               .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
-               .rx_irq = INT_730_McBSP2RX,
-               .tx_irq = INT_730_McBSP2TX },
-};
-#endif
-
-#ifdef CONFIG_ARCH_OMAP15XX
-static const struct omap_mcbsp_info mcbsp_1510[] = {
-       [0] = { .virt_base = OMAP1510_MCBSP1_BASE,
-               .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
-               .rx_irq = INT_McBSP1RX,
-               .tx_irq = INT_McBSP1TX },
-       [1] = { .virt_base = io_p2v(OMAP1510_MCBSP2_BASE),
-               .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
-               .rx_irq = INT_1510_SPI_RX,
-               .tx_irq = INT_1510_SPI_TX },
-       [2] = { .virt_base = OMAP1510_MCBSP3_BASE,
-               .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
-               .rx_irq = INT_McBSP3RX,
-               .tx_irq = INT_McBSP3TX },
-};
-#endif
-
-#if defined(CONFIG_ARCH_OMAP16XX)
-static const struct omap_mcbsp_info mcbsp_1610[] = {
-       [0] = { .virt_base = OMAP1610_MCBSP1_BASE,
-               .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
-               .rx_irq = INT_McBSP1RX,
-               .tx_irq = INT_McBSP1TX },
-       [1] = { .virt_base = io_p2v(OMAP1610_MCBSP2_BASE),
-               .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
-               .rx_irq = INT_1610_McBSP2_RX,
-               .tx_irq = INT_1610_McBSP2_TX },
-       [2] = { .virt_base = OMAP1610_MCBSP3_BASE,
-               .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
-               .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
-               .rx_irq = INT_McBSP3RX,
-               .tx_irq = INT_McBSP3TX },
-};
-#endif
-
-#if defined(CONFIG_ARCH_OMAP24XX)
-static const struct omap_mcbsp_info mcbsp_24xx[] = {
-       [0] = { .virt_base = IO_ADDRESS(OMAP24XX_MCBSP1_BASE),
-               .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
-               .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
-               .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
-               .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
-               },
-       [1] = { .virt_base = IO_ADDRESS(OMAP24XX_MCBSP2_BASE),
-               .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
-               .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
-               .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
-               .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
-               },
-};
-#endif
+       if (!pdata) {
+               dev_err(&pdev->dev, "McBSP device initialized without"
+                               "platform data\n");
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id);
+
+       if (id >= OMAP_MAX_MCBSP_COUNT) {
+               dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id);
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       spin_lock_init(&mcbsp[id].lock);
+       mcbsp[id].id = id + 1;
+       mcbsp[id].free = 1;
+       mcbsp[id].dma_tx_lch = -1;
+       mcbsp[id].dma_rx_lch = -1;
+
+       mcbsp[id].io_base = pdata->virt_base;
+       /* Default I/O is IRQ based */
+       mcbsp[id].io_type = OMAP_MCBSP_IRQ_IO;
+       mcbsp[id].tx_irq = pdata->tx_irq;
+       mcbsp[id].rx_irq = pdata->rx_irq;
+       mcbsp[id].dma_rx_sync = pdata->dma_rx_sync;
+       mcbsp[id].dma_tx_sync = pdata->dma_tx_sync;
+
+       if (pdata->clk_name)
+               mcbsp[id].clk = clk_get(&pdev->dev, pdata->clk_name);
+       if (IS_ERR(mcbsp[id].clk)) {
+               mcbsp[id].free = 0;
+               dev_err(&pdev->dev,
+                       "Invalid clock configuration for McBSP%d.\n",
+                       mcbsp[id].id);
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       mcbsp[id].pdata = pdata;
+       mcbsp[id].dev = &pdev->dev;
+       platform_set_drvdata(pdev, &mcbsp[id]);
+
+exit:
+       return ret;
+}
 
-static int __init omap_mcbsp_init(void)
+static int omap_mcbsp_remove(struct platform_device *pdev)
 {
-       int mcbsp_count = 0, i;
-       static const struct omap_mcbsp_info *mcbsp_info;
+       struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
 
-       printk("Initializing OMAP McBSP system\n");
+       platform_set_drvdata(pdev, NULL);
+       if (mcbsp) {
 
-#ifdef CONFIG_ARCH_OMAP1
-       mcbsp_dsp_ck = clk_get(0, "dsp_ck");
-       if (IS_ERR(mcbsp_dsp_ck)) {
-               printk(KERN_ERR "mcbsp: could not acquire dsp_ck handle.\n");
-               return PTR_ERR(mcbsp_dsp_ck);
-       }
-       mcbsp_api_ck = clk_get(0, "api_ck");
-       if (IS_ERR(mcbsp_api_ck)) {
-               printk(KERN_ERR "mcbsp: could not acquire api_ck handle.\n");
-               return PTR_ERR(mcbsp_api_ck);
-       }
-       mcbsp_dspxor_ck = clk_get(0, "dspxor_ck");
-       if (IS_ERR(mcbsp_dspxor_ck)) {
-               printk(KERN_ERR "mcbsp: could not acquire dspxor_ck handle.\n");
-               return PTR_ERR(mcbsp_dspxor_ck);
-       }
-#endif
-#ifdef CONFIG_ARCH_OMAP2
-       mcbsp1_ick = clk_get(0, "mcbsp1_ick");
-       if (IS_ERR(mcbsp1_ick)) {
-               printk(KERN_ERR "mcbsp: could not acquire mcbsp1_ick handle.\n");
-               return PTR_ERR(mcbsp1_ick);
-       }
-       mcbsp1_fck = clk_get(0, "mcbsp1_fck");
-       if (IS_ERR(mcbsp1_fck)) {
-               printk(KERN_ERR "mcbsp: could not acquire mcbsp1_fck handle.\n");
-               return PTR_ERR(mcbsp1_fck);
-       }
-       mcbsp2_ick = clk_get(0, "mcbsp2_ick");
-       if (IS_ERR(mcbsp2_ick)) {
-               printk(KERN_ERR "mcbsp: could not acquire mcbsp2_ick handle.\n");
-               return PTR_ERR(mcbsp2_ick);
-       }
-       mcbsp2_fck = clk_get(0, "mcbsp2_fck");
-       if (IS_ERR(mcbsp2_fck)) {
-               printk(KERN_ERR "mcbsp: could not acquire mcbsp2_fck handle.\n");
-               return PTR_ERR(mcbsp2_fck);
-       }
-#endif
+               if (mcbsp->pdata && mcbsp->pdata->ops &&
+                               mcbsp->pdata->ops->free)
+                       mcbsp->pdata->ops->free(mcbsp->id);
 
-#ifdef CONFIG_ARCH_OMAP730
-       if (cpu_is_omap730()) {
-               mcbsp_info = mcbsp_730;
-               mcbsp_count = ARRAY_SIZE(mcbsp_730);
-       }
-#endif
-#ifdef CONFIG_ARCH_OMAP15XX
-       if (cpu_is_omap15xx()) {
-               mcbsp_info = mcbsp_1510;
-               mcbsp_count = ARRAY_SIZE(mcbsp_1510);
-       }
-#endif
-#if defined(CONFIG_ARCH_OMAP16XX)
-       if (cpu_is_omap16xx()) {
-               mcbsp_info = mcbsp_1610;
-               mcbsp_count = ARRAY_SIZE(mcbsp_1610);
-       }
-#endif
-#if defined(CONFIG_ARCH_OMAP24XX)
-       if (cpu_is_omap24xx()) {
-               mcbsp_info = mcbsp_24xx;
-               mcbsp_count = ARRAY_SIZE(mcbsp_24xx);
-               omap2_mcbsp2_mux_setup();
-       }
-#endif
-       for (i = 0; i < OMAP_MAX_MCBSP_COUNT ; i++) {
-               if (i >= mcbsp_count) {
-                       mcbsp[i].io_base = 0;
-                       mcbsp[i].free = 0;
-                        continue;
-               }
-               mcbsp[i].id = i + 1;
-               mcbsp[i].free = 1;
-               mcbsp[i].dma_tx_lch = -1;
-               mcbsp[i].dma_rx_lch = -1;
-
-               mcbsp[i].io_base = mcbsp_info[i].virt_base;
-               mcbsp[i].io_type = OMAP_MCBSP_IRQ_IO; /* Default I/O is IRQ based */
-               mcbsp[i].tx_irq = mcbsp_info[i].tx_irq;
-               mcbsp[i].rx_irq = mcbsp_info[i].rx_irq;
-               mcbsp[i].dma_rx_sync = mcbsp_info[i].dma_rx_sync;
-               mcbsp[i].dma_tx_sync = mcbsp_info[i].dma_tx_sync;
-               spin_lock_init(&mcbsp[i].lock);
+               clk_disable(mcbsp->clk);
+               clk_put(mcbsp->clk);
+
+               mcbsp->clk = NULL;
+               mcbsp->free = 0;
+               mcbsp->dev = NULL;
        }
 
        return 0;
 }
 
-arch_initcall(omap_mcbsp_init);
+static struct platform_driver omap_mcbsp_driver = {
+       .probe          = omap_mcbsp_probe,
+       .remove         = omap_mcbsp_remove,
+       .driver         = {
+               .name   = "omap-mcbsp",
+       },
+};
+
+int __init omap_mcbsp_init(void)
+{
+       /* Register the McBSP driver */
+       return platform_driver_register(&omap_mcbsp_driver);
+}
 
-EXPORT_SYMBOL(omap_mcbsp_config);
-EXPORT_SYMBOL(omap_mcbsp_request);
-EXPORT_SYMBOL(omap_mcbsp_set_io_type);
-EXPORT_SYMBOL(omap_mcbsp_free);
-EXPORT_SYMBOL(omap_mcbsp_start);
-EXPORT_SYMBOL(omap_mcbsp_stop);
-EXPORT_SYMBOL(omap_mcbsp_pollread);
-EXPORT_SYMBOL(omap_mcbsp_pollwrite);
-EXPORT_SYMBOL(omap_mcbsp_xmit_word);
-EXPORT_SYMBOL(omap_mcbsp_recv_word);
-EXPORT_SYMBOL(omap_mcbsp_xmit_buffer);
-EXPORT_SYMBOL(omap_mcbsp_recv_buffer);
-EXPORT_SYMBOL(omap_mcbsp_spi_master_xmit_word_poll);
-EXPORT_SYMBOL(omap_mcbsp_spi_master_recv_word_poll);
-EXPORT_SYMBOL(omap_mcbsp_set_spi_mode);
diff --git a/arch/arm/plat-omap/sram-fn.S b/arch/arm/plat-omap/sram-fn.S
deleted file mode 100644 (file)
index 9e1813c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * linux/arch/arm/plat-omap/sram-fn.S
- *
- * Functions that need to be run in internal SRAM
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/linkage.h>
-#include <asm/assembler.h>
-#include <asm/arch/io.h>
-#include <asm/hardware.h>
-
-       .text
-
-/*
- * Reprograms ULPD and CKCTL.
- */
-ENTRY(sram_reprogram_clock)
-       stmfd   sp!, {r0 - r12, lr}             @ save registers on stack
-
-       mov     r2, #IO_ADDRESS(DPLL_CTL) & 0xff000000
-       orr     r2, r2, #IO_ADDRESS(DPLL_CTL) & 0x00ff0000
-       orr     r2, r2, #IO_ADDRESS(DPLL_CTL) & 0x0000ff00
-
-       mov     r3, #IO_ADDRESS(ARM_CKCTL) & 0xff000000
-       orr     r3, r3, #IO_ADDRESS(ARM_CKCTL) & 0x00ff0000
-       orr     r3, r3, #IO_ADDRESS(ARM_CKCTL) & 0x0000ff00
-
-       tst     r0, #1 << 4                     @ want lock mode?
-       beq     newck                           @ nope
-       bic     r0, r0, #1 << 4                 @ else clear lock bit
-       strh    r0, [r2]                        @ set dpll into bypass mode
-       orr     r0, r0, #1 << 4                 @ set lock bit again
-
-newck:
-       strh    r1, [r3]                        @ write new ckctl value
-       strh    r0, [r2]                        @ write new dpll value
-
-       mov     r4, #0x0700                     @ let the clocks settle
-       orr     r4, r4, #0x00ff
-delay: sub     r4, r4, #1
-       cmp     r4, #0
-       bne     delay
-
-lock:  ldrh    r4, [r2], #0                    @ read back dpll value
-       tst     r0, #1 << 4                     @ want lock mode?
-       beq     out                             @ nope
-       tst     r4, #1 << 0                     @ dpll rate locked?
-       beq     lock                            @ try again
-
-out:
-       ldmfd   sp!, {r0 - r12, pc}             @ restore regs and return
-ENTRY(sram_reprogram_clock_sz)
-       .word   . - sram_reprogram_clock
index 1f23f04..554ee58 100644 (file)
@@ -10,6 +10,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#undef DEBUG
 
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <asm/arch/sram.h>
 #include <asm/arch/board.h>
 
+#include <asm/arch/control.h>
+
+#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
+# include "../mach-omap2/prm.h"
+# include "../mach-omap2/cm.h"
+# include "../mach-omap2/sdrc.h"
+#endif
+
 #define OMAP1_SRAM_PA          0x20000000
-#define OMAP1_SRAM_VA          0xd0000000
+#define OMAP1_SRAM_VA          VMALLOC_END
 #define OMAP2_SRAM_PA          0x40200000
 #define OMAP2_SRAM_PUB_PA      0x4020f800
-#define OMAP2_SRAM_VA          0xd0000000
-#define OMAP2_SRAM_PUB_VA      0xd0000800
-
-#if defined(CONFIG_ARCH_OMAP24XX)
+#define OMAP2_SRAM_VA          VMALLOC_END
+#define OMAP2_SRAM_PUB_VA      (VMALLOC_END + 0x800)
+#define OMAP3_SRAM_PA           0x40200000
+#define OMAP3_SRAM_VA           0xd7000000
+#define OMAP3_SRAM_PUB_PA       0x40208000
+#define OMAP3_SRAM_PUB_VA       0xd7008000
+
+#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
 #define SRAM_BOOTLOADER_SZ     0x00
 #else
 #define SRAM_BOOTLOADER_SZ     0x80
 #endif
 
-#define VA_REQINFOPERM0                IO_ADDRESS(0x68005048)
-#define VA_READPERM0           IO_ADDRESS(0x68005050)
-#define VA_WRITEPERM0          IO_ADDRESS(0x68005058)
-#define VA_CONTROL_STAT                IO_ADDRESS(0x480002F8)
+#define OMAP24XX_VA_REQINFOPERM0       IO_ADDRESS(0x68005048)
+#define OMAP24XX_VA_READPERM0          IO_ADDRESS(0x68005050)
+#define OMAP24XX_VA_WRITEPERM0         IO_ADDRESS(0x68005058)
+
+#define OMAP34XX_VA_REQINFOPERM0       IO_ADDRESS(0x68012848)
+#define OMAP34XX_VA_READPERM0          IO_ADDRESS(0x68012850)
+#define OMAP34XX_VA_WRITEPERM0         IO_ADDRESS(0x68012858)
+#define OMAP34XX_VA_ADDR_MATCH2                IO_ADDRESS(0x68012880)
+#define OMAP34XX_VA_SMS_RG_ATT0                IO_ADDRESS(0x6C000048)
+#define OMAP34XX_VA_CONTROL_STAT       IO_ADDRESS(0x480022F0)
+
 #define GP_DEVICE              0x300
-#define TYPE_MASK              0x700
 
 #define ROUND_DOWN(value,boundary)     ((value) & (~((boundary)-1)))
 
@@ -68,14 +87,21 @@ static int is_sram_locked(void)
        int type = 0;
 
        if (cpu_is_omap242x())
-               type = __raw_readl(VA_CONTROL_STAT) & TYPE_MASK;
+               type = system_rev & OMAP2_DEVICETYPE_MASK;
 
        if (type == GP_DEVICE) {
                /* RAMFW: R/W access to all initiators for all qualifier sets */
                if (cpu_is_omap242x()) {
-                       __raw_writel(0xFF, VA_REQINFOPERM0); /* all q-vects */
-                       __raw_writel(0xCFDE, VA_READPERM0);  /* all i-read */
-                       __raw_writel(0xCFDE, VA_WRITEPERM0); /* all i-write */
+                       __raw_writel(0xFF, OMAP24XX_VA_REQINFOPERM0); /* all q-vects */
+                       __raw_writel(0xCFDE, OMAP24XX_VA_READPERM0);  /* all i-read */
+                       __raw_writel(0xCFDE, OMAP24XX_VA_WRITEPERM0); /* all i-write */
+               }
+               if (cpu_is_omap34xx()) {
+                       __raw_writel(0xFFFF, OMAP34XX_VA_REQINFOPERM0); /* all q-vects */
+                       __raw_writel(0xFFFF, OMAP34XX_VA_READPERM0);  /* all i-read */
+                       __raw_writel(0xFFFF, OMAP34XX_VA_WRITEPERM0); /* all i-write */
+                       __raw_writel(0x0, OMAP34XX_VA_ADDR_MATCH2);
+                       __raw_writel(0xFFFFFFFF, OMAP34XX_VA_SMS_RG_ATT0);
                }
                return 0;
        } else
@@ -92,18 +118,30 @@ void __init omap_detect_sram(void)
 {
        unsigned long reserved;
 
-       if (cpu_is_omap24xx()) {
+       if (cpu_class_is_omap2()) {
                if (is_sram_locked()) {
-                       omap_sram_base = OMAP2_SRAM_PUB_VA;
-                       omap_sram_start = OMAP2_SRAM_PUB_PA;
-                       omap_sram_size = 0x800; /* 2K */
+                       if (cpu_is_omap34xx()) {
+                               omap_sram_base = OMAP3_SRAM_PUB_VA;
+                               omap_sram_start = OMAP3_SRAM_PUB_PA;
+                               omap_sram_size = 0x8000; /* 32K */
+                       } else {
+                               omap_sram_base = OMAP2_SRAM_PUB_VA;
+                               omap_sram_start = OMAP2_SRAM_PUB_PA;
+                               omap_sram_size = 0x800; /* 2K */
+                       }
                } else {
-                       omap_sram_base = OMAP2_SRAM_VA;
-                       omap_sram_start = OMAP2_SRAM_PA;
-                       if (cpu_is_omap242x())
-                               omap_sram_size = 0xa0000; /* 640K */
-                       else if (cpu_is_omap243x())
+                       if (cpu_is_omap34xx()) {
+                               omap_sram_base = OMAP3_SRAM_VA;
+                               omap_sram_start = OMAP3_SRAM_PA;
                                omap_sram_size = 0x10000; /* 64K */
+                       } else {
+                               omap_sram_base = OMAP2_SRAM_VA;
+                               omap_sram_start = OMAP2_SRAM_PA;
+                               if (cpu_is_omap242x())
+                                       omap_sram_size = 0xa0000; /* 640K */
+                               else if (cpu_is_omap243x())
+                                       omap_sram_size = 0x10000; /* 64K */
+                       }
                }
        } else {
                omap_sram_base = OMAP1_SRAM_VA;
@@ -157,6 +195,13 @@ void __init omap_map_sram(void)
                omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
        }
 
+       if (cpu_is_omap34xx()) {
+               omap_sram_io_desc[0].virtual = OMAP3_SRAM_VA;
+               base = OMAP3_SRAM_PA;
+               base = ROUND_DOWN(base, PAGE_SIZE);
+               omap_sram_io_desc[0].pfn = __phys_to_pfn(base);
+       }
+
        omap_sram_io_desc[0].length = 1024 * 1024;      /* Use section desc */
        iotable_init(omap_sram_io_desc, ARRAY_SIZE(omap_sram_io_desc));
 
@@ -191,6 +236,7 @@ void * omap_sram_push(void * start, unsigned long size)
        omap_sram_ceil -= size;
        omap_sram_ceil = ROUND_DOWN(omap_sram_ceil, sizeof(void *));
        memcpy((void *)omap_sram_ceil, start, size);
+       flush_icache_range((unsigned long)start, (unsigned long)(start + size));
 
        return (void *)omap_sram_ceil;
 }
@@ -214,8 +260,9 @@ void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl)
 
 int __init omap1_sram_init(void)
 {
-       _omap_sram_reprogram_clock = omap_sram_push(sram_reprogram_clock,
-                                                   sram_reprogram_clock_sz);
+       _omap_sram_reprogram_clock =
+                       omap_sram_push(omap1_sram_reprogram_clock,
+                                       omap1_sram_reprogram_clock_sz);
 
        return 0;
 }
@@ -224,7 +271,7 @@ int __init omap1_sram_init(void)
 #define omap1_sram_init()      do {} while (0)
 #endif
 
-#ifdef CONFIG_ARCH_OMAP2
+#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
 
 static void (*_omap2_sram_ddr_init)(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
                              u32 base_cs, u32 force_unlock);
@@ -259,19 +306,109 @@ u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass)
 
        return _omap2_set_prcm(dpll_ctrl_val, sdrc_rfr_val, bypass);
 }
+#endif
+
+#ifdef CONFIG_ARCH_OMAP2420
+int __init omap242x_sram_init(void)
+{
+       _omap2_sram_ddr_init = omap_sram_push(omap242x_sram_ddr_init,
+                                       omap242x_sram_ddr_init_sz);
+
+       _omap2_sram_reprogram_sdrc = omap_sram_push(omap242x_sram_reprogram_sdrc,
+                                           omap242x_sram_reprogram_sdrc_sz);
+
+       _omap2_set_prcm = omap_sram_push(omap242x_sram_set_prcm,
+                                        omap242x_sram_set_prcm_sz);
+
+       return 0;
+}
+#else
+static inline int omap242x_sram_init(void)
+{
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_ARCH_OMAP2430
+int __init omap243x_sram_init(void)
+{
+       _omap2_sram_ddr_init = omap_sram_push(omap243x_sram_ddr_init,
+                                       omap243x_sram_ddr_init_sz);
+
+       _omap2_sram_reprogram_sdrc = omap_sram_push(omap243x_sram_reprogram_sdrc,
+                                           omap243x_sram_reprogram_sdrc_sz);
+
+       _omap2_set_prcm = omap_sram_push(omap243x_sram_set_prcm,
+                                        omap243x_sram_set_prcm_sz);
+
+       return 0;
+}
+#else
+static inline int omap243x_sram_init(void)
+{
+       return 0;
+}
+#endif
+
+#ifdef CONFIG_ARCH_OMAP3
+
+static u32 (*_omap2_sram_reprogram_gpmc)(u32 perf_level);
+u32 omap2_sram_reprogram_gpmc(u32 perf_level)
+{
+       if (!_omap2_sram_reprogram_gpmc)
+               omap_sram_error();
+
+       return _omap2_sram_reprogram_gpmc(perf_level);
+}
+
+static u32 (*_omap2_sram_configure_core_dpll)(u32 m, u32 n,
+                                               u32 freqsel, u32 m2);
+u32 omap2_sram_configure_core_dpll(u32 m, u32 n, u32 freqsel, u32 m2)
+{
+       if (!_omap2_sram_configure_core_dpll)
+               omap_sram_error();
+
+       return _omap2_sram_configure_core_dpll(m, n, freqsel, m2);
+}
 
-int __init omap2_sram_init(void)
+/* REVISIT: Should this be same as omap34xx_sram_init() after off-idle? */
+void restore_sram_functions(void)
 {
-       _omap2_sram_ddr_init = omap_sram_push(sram_ddr_init, sram_ddr_init_sz);
+       omap_sram_ceil = omap_sram_base + omap_sram_size;
 
-       _omap2_sram_reprogram_sdrc = omap_sram_push(sram_reprogram_sdrc,
-                                                   sram_reprogram_sdrc_sz);
-       _omap2_set_prcm = omap_sram_push(sram_set_prcm, sram_set_prcm_sz);
+       _omap2_sram_reprogram_gpmc = omap_sram_push(omap34xx_sram_reprogram_gpmc,
+               omap34xx_sram_reprogram_gpmc_sz);
+
+       _omap2_sram_configure_core_dpll =
+                       omap_sram_push(omap34xx_sram_configure_core_dpll,
+                                       omap34xx_sram_configure_core_dpll_sz);
+}
+
+int __init omap34xx_sram_init(void)
+{
+       _omap2_sram_ddr_init = omap_sram_push(omap34xx_sram_ddr_init,
+                                       omap34xx_sram_ddr_init_sz);
+
+       _omap2_sram_reprogram_sdrc = omap_sram_push(omap34xx_sram_reprogram_sdrc,
+                                       omap34xx_sram_reprogram_sdrc_sz);
+
+       _omap2_set_prcm = omap_sram_push(omap34xx_sram_set_prcm,
+                                       omap34xx_sram_set_prcm_sz);
+
+       _omap2_sram_reprogram_gpmc = omap_sram_push(omap34xx_sram_reprogram_gpmc,
+                                       omap34xx_sram_reprogram_gpmc_sz);
+
+       _omap2_sram_configure_core_dpll =
+                               omap_sram_push(omap34xx_sram_configure_core_dpll,
+                                       omap34xx_sram_configure_core_dpll_sz);
 
        return 0;
 }
 #else
-#define omap2_sram_init()      do {} while (0)
+static inline int omap34xx_sram_init(void)
+{
+       return 0;
+}
 #endif
 
 int __init omap_sram_init(void)
@@ -279,10 +416,14 @@ int __init omap_sram_init(void)
        omap_detect_sram();
        omap_map_sram();
 
-       if (!cpu_is_omap24xx())
+       if (!(cpu_class_is_omap2()))
                omap1_sram_init();
-       else
-               omap2_sram_init();
+       else if (cpu_is_omap242x())
+               omap242x_sram_init();
+       else if (cpu_is_omap2430())
+               omap243x_sram_init();
+       else if (cpu_is_omap34xx())
+               omap34xx_sram_init();
 
        return 0;
 }
index a619475..2699c16 100644 (file)
@@ -1,4 +1,4 @@
-/*
+ /*
  * arch/arm/plat-omap/usb.c -- platform level USB initialization
  *
  * Copyright (C) 2004 Texas Instruments, Inc.
@@ -156,8 +156,12 @@ static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
 
        if (nwires == 0) {
                if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
+                       u32 l;
+
                        /* pulldown D+/D- */
-                       USB_TRANSCEIVER_CTRL_REG &= ~(3 << 1);
+                       l = omap_readl(USB_TRANSCEIVER_CTRL);
+                       l &= ~(3 << 1);
+                       omap_writel(l, USB_TRANSCEIVER_CTRL);
                }
                return 0;
        }
@@ -171,6 +175,8 @@ static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
 
        /* internal transceiver (unavailable on 17xx, 24xx) */
        if (!cpu_class_is_omap2() && nwires == 2) {
+               u32 l;
+
                // omap_cfg_reg(P9_USB_DP);
                // omap_cfg_reg(R8_USB_DM);
 
@@ -185,9 +191,11 @@ static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
                 *  - OTG support on this port not yet written
                 */
 
-               USB_TRANSCEIVER_CTRL_REG &= ~(7 << 4);
+               l = omap_readl(USB_TRANSCEIVER_CTRL);
+               l &= ~(7 << 4);
                if (!is_device)
-                       USB_TRANSCEIVER_CTRL_REG |= (3 << 1);
+                       l |= (3 << 1);
+               omap_writel(l, USB_TRANSCEIVER_CTRL);
 
                return 3 << 16;
        }
@@ -217,8 +225,13 @@ static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
         * with VBUS switching and overcurrent detection.
         */
 
-       if (cpu_class_is_omap1() && nwires != 6)
-               USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
+       if (cpu_class_is_omap1() && nwires != 6) {
+               u32 l;
+
+               l = omap_readl(USB_TRANSCEIVER_CTRL);
+               l &= ~CONF_USB2_UNI_R;
+               omap_writel(l, USB_TRANSCEIVER_CTRL);
+       }
 
        switch (nwires) {
        case 3:
@@ -238,9 +251,13 @@ static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device)
                        omap_cfg_reg(K20_24XX_USB0_VM);
                        omap2_usb_devconf_set(0, USB_UNIDIR);
                } else {
+                       u32 l;
+
                        omap_cfg_reg(AA9_USB0_VP);
                        omap_cfg_reg(R9_USB0_VM);
-                       USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
+                       l = omap_readl(USB_TRANSCEIVER_CTRL);
+                       l |= CONF_USB2_UNI_R;
+                       omap_writel(l, USB_TRANSCEIVER_CTRL);
                }
                break;
        default:
@@ -254,8 +271,13 @@ static u32 __init omap_usb1_init(unsigned nwires)
 {
        u32     syscon1 = 0;
 
-       if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
-               USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;
+       if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
+               u32 l;
+
+               l = omap_readl(USB_TRANSCEIVER_CTRL);
+               l &= ~CONF_USB1_UNI_R;
+               omap_writel(l, USB_TRANSCEIVER_CTRL);
+       }
        if (cpu_is_omap24xx())
                omap2_usb_devconf_clear(1, USB_BIDIR_TLL);
 
@@ -316,8 +338,13 @@ static u32 __init omap_usb1_init(unsigned nwires)
                syscon1 = 3;
                omap_cfg_reg(USB1_VP);
                omap_cfg_reg(USB1_VM);
-               if (!cpu_is_omap15xx())
-                       USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;
+               if (!cpu_is_omap15xx()) {
+                       u32 l;
+
+                       l = omap_readl(USB_TRANSCEIVER_CTRL);
+                       l |= CONF_USB1_UNI_R;
+                       omap_writel(l, USB_TRANSCEIVER_CTRL);
+               }
                break;
        default:
 bad:
@@ -340,8 +367,13 @@ static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
        if (alt_pingroup || nwires == 0)
                return 0;
 
-       if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6)
-               USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;
+       if (cpu_class_is_omap1() && !cpu_is_omap15xx() && nwires != 6) {
+               u32 l;
+
+               l = omap_readl(USB_TRANSCEIVER_CTRL);
+               l &= ~CONF_USB2_UNI_R;
+               omap_writel(l, USB_TRANSCEIVER_CTRL);
+       }
 
        /* external transceiver */
        if (cpu_is_omap15xx()) {
@@ -410,9 +442,13 @@ static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup)
                        omap_cfg_reg(USB2_VP);
                        omap_cfg_reg(USB2_VM);
                } else {
+                       u32 l;
+
                        omap_cfg_reg(AA9_USB2_VP);
                        omap_cfg_reg(R9_USB2_VM);
-                       USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;
+                       l = omap_readl(USB_TRANSCEIVER_CTRL);
+                       l |= CONF_USB2_UNI_R;
+                       omap_writel(l, USB_TRANSCEIVER_CTRL);
                }
                break;
        default:
@@ -531,10 +567,6 @@ static struct platform_device otg_device = {
 
 /*-------------------------------------------------------------------------*/
 
-#define ULPD_CLOCK_CTRL_REG    __REG16(ULPD_CLOCK_CTRL)
-#define ULPD_SOFT_REQ_REG      __REG16(ULPD_SOFT_REQ)
-
-
 // FIXME correct answer depends on hmc_mode,
 // as does (on omap1) any nonzero value for config->otg port number
 #ifdef CONFIG_USB_GADGET_OMAP
@@ -550,17 +582,17 @@ static struct platform_device otg_device = {
 void __init
 omap_otg_init(struct omap_usb_config *config)
 {
-       u32             syscon = OTG_SYSCON_1_REG & 0xffff;
+       u32             syscon;
        int             status;
        int             alt_pingroup = 0;
 
        /* NOTE:  no bus or clock setup (yet?) */
 
-       syscon = OTG_SYSCON_1_REG & 0xffff;
+       syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
        if (!(syscon & OTG_RESET_DONE))
                pr_debug("USB resets not complete?\n");
 
-       // OTG_IRQ_EN_REG = 0;
+       //omap_writew(0, OTG_IRQ_EN);
 
        /* pin muxing and transceiver pinouts */
        if (config->pins[0] > 2)        /* alt pingroup 2 */
@@ -568,8 +600,8 @@ omap_otg_init(struct omap_usb_config *config)
        syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));
        syscon |= omap_usb1_init(config->pins[1]);
        syscon |= omap_usb2_init(config->pins[2], alt_pingroup);
-       pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
-       OTG_SYSCON_1_REG = syscon;
+       pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
+       omap_writel(syscon, OTG_SYSCON_1);
 
        syscon = config->hmc_mode;
        syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
@@ -578,9 +610,10 @@ omap_otg_init(struct omap_usb_config *config)
                syscon |= OTG_EN;
 #endif
        if (cpu_class_is_omap1())
-               pr_debug("USB_TRANSCEIVER_CTRL_REG = %03x\n", USB_TRANSCEIVER_CTRL_REG);
-       pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);
-       OTG_SYSCON_2_REG = syscon;
+               pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
+                        omap_readl(USB_TRANSCEIVER_CTRL));
+       pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
+       omap_writel(syscon, OTG_SYSCON_2);
 
        printk("USB: hmc %d", config->hmc_mode);
        if (!alt_pingroup)
@@ -597,12 +630,19 @@ omap_otg_init(struct omap_usb_config *config)
        printk("\n");
 
        if (cpu_class_is_omap1()) {
+               u16 w;
+
                /* leave USB clocks/controllers off until needed */
-               ULPD_SOFT_REQ_REG &= ~SOFT_USB_CLK_REQ;
-               ULPD_CLOCK_CTRL_REG &= ~USB_MCLK_EN;
-               ULPD_CLOCK_CTRL_REG |= DIS_USB_PVCI_CLK;
+               w = omap_readw(ULPD_SOFT_REQ);
+               w &= ~SOFT_USB_CLK_REQ;
+               omap_writew(w, ULPD_SOFT_REQ);
+
+               w = omap_readw(ULPD_CLOCK_CTRL);
+               w &= ~USB_MCLK_EN;
+               w |= DIS_USB_PVCI_CLK;
+               omap_writew(w, ULPD_CLOCK_CTRL);
        }
-       syscon = OTG_SYSCON_1_REG;
+       syscon = omap_readl(OTG_SYSCON_1);
        syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
 
 #ifdef CONFIG_USB_GADGET_OMAP
@@ -639,8 +679,8 @@ omap_otg_init(struct omap_usb_config *config)
                        pr_debug("can't register OTG device, %d\n", status);
        }
 #endif
-       pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);
-       OTG_SYSCON_1_REG = syscon;
+       pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
+       omap_writel(syscon, OTG_SYSCON_1);
 
        status = 0;
 }
@@ -653,18 +693,19 @@ static inline void omap_otg_init(struct omap_usb_config *config) {}
 
 #ifdef CONFIG_ARCH_OMAP15XX
 
-#define ULPD_DPLL_CTRL_REG     __REG16(ULPD_DPLL_CTRL)
+/* ULPD_DPLL_CTRL */
 #define DPLL_IOB               (1 << 13)
 #define DPLL_PLL_ENABLE                (1 << 4)
 #define DPLL_LOCK              (1 << 0)
 
-#define ULPD_APLL_CTRL_REG     __REG16(ULPD_APLL_CTRL)
+/* ULPD_APLL_CTRL */
 #define APLL_NDPLL_SWITCH      (1 << 0)
 
 
 static void __init omap_1510_usb_init(struct omap_usb_config *config)
 {
        unsigned int val;
+       u16 w;
 
        omap_usb0_init(config->pins[0], is_usb0_device(config));
        omap_usb1_init(config->pins[1]);
@@ -685,12 +726,22 @@ static void __init omap_1510_usb_init(struct omap_usb_config *config)
        printk("\n");
 
        /* use DPLL for 48 MHz function clock */
-       pr_debug("APLL %04x DPLL %04x REQ %04x\n", ULPD_APLL_CTRL_REG,
-                       ULPD_DPLL_CTRL_REG, ULPD_SOFT_REQ_REG);
-       ULPD_APLL_CTRL_REG &= ~APLL_NDPLL_SWITCH;
-       ULPD_DPLL_CTRL_REG |= DPLL_IOB | DPLL_PLL_ENABLE;
-       ULPD_SOFT_REQ_REG |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
-       while (!(ULPD_DPLL_CTRL_REG & DPLL_LOCK))
+       pr_debug("APLL %04x DPLL %04x REQ %04x\n", omap_readw(ULPD_APLL_CTRL),
+                       omap_readw(ULPD_DPLL_CTRL), omap_readw(ULPD_SOFT_REQ));
+
+       w = omap_readw(ULPD_APLL_CTRL);
+       w &= ~APLL_NDPLL_SWITCH;
+       omap_writew(w, ULPD_APLL_CTRL);
+
+       w = omap_readw(ULPD_DPLL_CTRL);
+       w |= DPLL_IOB | DPLL_PLL_ENABLE;
+       omap_writew(w, ULPD_DPLL_CTRL);
+
+       w = omap_readw(ULPD_SOFT_REQ);
+       w |= SOFT_UDC_REQ | SOFT_DPLL_REQ;
+       omap_writew(w, ULPD_SOFT_REQ);
+
+       while (!(omap_readw(ULPD_DPLL_CTRL) & DPLL_LOCK))
                cpu_relax();
 
 #ifdef CONFIG_USB_GADGET_OMAP
index c5b669d..fe66a18 100644 (file)
@@ -36,8 +36,8 @@ static void orion_irq_unmask(u32 irq)
 
 static struct irq_chip orion_irq_chip = {
        .name           = "orion_irq",
-       .ack            = orion_irq_mask,
        .mask           = orion_irq_mask,
+       .mask_ack       = orion_irq_mask,
        .unmask         = orion_irq_unmask,
 };
 
@@ -59,6 +59,7 @@ void __init orion_irq_init(unsigned int irq_start, void __iomem *maskaddr)
                set_irq_chip(irq, &orion_irq_chip);
                set_irq_chip_data(irq, maskaddr);
                set_irq_handler(irq, handle_level_irq);
+               irq_desc[irq].status |= IRQ_LEVEL;
                set_irq_flags(irq, IRQF_VALID);
        }
 }
index abfda53..ca32c60 100644 (file)
@@ -39,6 +39,7 @@
 #define PCIE_CONF_DATA_OFF     0x18fc
 #define PCIE_MASK_OFF          0x1910
 #define PCIE_CTRL_OFF          0x1a00
+#define  PCIE_CTRL_X1_MODE             0x0001
 #define PCIE_STAT_OFF          0x1a04
 #define  PCIE_STAT_DEV_OFFS            20
 #define  PCIE_STAT_DEV_MASK            0x1f
@@ -62,6 +63,11 @@ int orion_pcie_link_up(void __iomem *base)
        return !(readl(base + PCIE_STAT_OFF) & PCIE_STAT_LINK_DOWN);
 }
 
+int __init orion_pcie_x4_mode(void __iomem *base)
+{
+       return !(readl(base + PCIE_CTRL_OFF) & PCIE_CTRL_X1_MODE);
+}
+
 int orion_pcie_get_local_bus_nr(void __iomem *base)
 {
        u32 stat = readl(base + PCIE_STAT_OFF);
index 28b5285..93c4ef9 100644 (file)
@@ -74,7 +74,7 @@ orion_clkevt_next_event(unsigned long delta, struct clock_event_device *dev)
        /*
         * Clear and enable clockevent timer interrupt.
         */
-       writel(~BRIDGE_INT_TIMER1, BRIDGE_CAUSE);
+       writel(BRIDGE_INT_TIMER1_CLR, BRIDGE_CAUSE);
 
        u = readl(BRIDGE_MASK);
        u |= BRIDGE_INT_TIMER1;
@@ -138,7 +138,7 @@ orion_clkevt_mode(enum clock_event_mode mode, struct clock_event_device *dev)
                /*
                 * ACK pending timer interrupt.
                 */
-               writel(~BRIDGE_INT_TIMER1, BRIDGE_CAUSE);
+               writel(BRIDGE_INT_TIMER1_CLR, BRIDGE_CAUSE);
 
        }
        local_irq_restore(flags);
@@ -159,7 +159,7 @@ static irqreturn_t orion_timer_interrupt(int irq, void *dev_id)
        /*
         * ACK timer interrupt and call event handler.
         */
-       writel(~BRIDGE_INT_TIMER1, BRIDGE_CAUSE);
+       writel(BRIDGE_INT_TIMER1_CLR, BRIDGE_CAUSE);
        orion_clkevt.event_handler(&orion_clkevt);
 
        return IRQ_HANDLED;
index b66fb3c..5e28c21 100644 (file)
@@ -9,6 +9,7 @@ config PLAT_S3C24XX
        depends on ARCH_S3C2410
        default y if ARCH_S3C2410
        select NO_IOPORT
+       select HAVE_GPIO_LIB
        help
          Base platform code for any Samsung S3C24XX device
 
@@ -20,6 +21,13 @@ config CPU_S3C244X
        help
          Support for S3C2440 and S3C2442 Samsung Mobile CPU based systems.
 
+config S3C24XX_PWM
+       bool "PWM device support"
+       select HAVE_PWM
+       help
+         Support for exporting the PWM timer blocks via the pwm device
+         system.
+
 config PM_SIMTEC
        bool
        help
index 131d202..d82767b 100644 (file)
@@ -16,8 +16,10 @@ obj-y                                += cpu.o
 obj-y                          += irq.o
 obj-y                          += devs.o
 obj-y                          += gpio.o
+obj-y                          += gpiolib.o
 obj-y                          += time.o
 obj-y                          += clock.o
+obj-y                          += pwm-clock.o
 
 # Architecture dependant builds
 
@@ -27,5 +29,6 @@ obj-$(CONFIG_CPU_S3C244X)     += s3c244x-clock.o
 obj-$(CONFIG_PM_SIMTEC)                += pm-simtec.o
 obj-$(CONFIG_PM)               += pm.o
 obj-$(CONFIG_PM)               += sleep.o
+obj-$(CONFIG_HAVE_PWM)         += pwm.o
 obj-$(CONFIG_S3C2410_DMA)      += dma.o
 obj-$(CONFIG_MACH_SMDK)                += common-smdk.o
index e546e93..eea3b32 100644 (file)
@@ -495,106 +495,6 @@ struct platform_device s3c_device_spi1 = {
 
 EXPORT_SYMBOL(s3c_device_spi1);
 
-/* pwm timer blocks */
-
-static struct resource s3c_timer0_resource[] = {
-       [0] = {
-               .start = S3C24XX_PA_TIMER + 0x0C,
-               .end   = S3C24XX_PA_TIMER + 0x0C + 0xB,
-               .flags = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start = IRQ_TIMER0,
-               .end   = IRQ_TIMER0,
-               .flags = IORESOURCE_IRQ,
-       }
-
-};
-
-struct platform_device s3c_device_timer0 = {
-       .name             = "s3c2410-timer",
-       .id               = 0,
-       .num_resources    = ARRAY_SIZE(s3c_timer0_resource),
-       .resource         = s3c_timer0_resource,
-};
-
-EXPORT_SYMBOL(s3c_device_timer0);
-
-/* timer 1 */
-
-static struct resource s3c_timer1_resource[] = {
-       [0] = {
-               .start = S3C24XX_PA_TIMER + 0x18,
-               .end   = S3C24XX_PA_TIMER + 0x23,
-               .flags = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start = IRQ_TIMER1,
-               .end   = IRQ_TIMER1,
-               .flags = IORESOURCE_IRQ,
-       }
-
-};
-
-struct platform_device s3c_device_timer1 = {
-       .name             = "s3c2410-timer",
-       .id               = 1,
-       .num_resources    = ARRAY_SIZE(s3c_timer1_resource),
-       .resource         = s3c_timer1_resource,
-};
-
-EXPORT_SYMBOL(s3c_device_timer1);
-
-/* timer 2 */
-
-static struct resource s3c_timer2_resource[] = {
-       [0] = {
-               .start = S3C24XX_PA_TIMER + 0x24,
-               .end   = S3C24XX_PA_TIMER + 0x2F,
-               .flags = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start = IRQ_TIMER2,
-               .end   = IRQ_TIMER2,
-               .flags = IORESOURCE_IRQ,
-       }
-
-};
-
-struct platform_device s3c_device_timer2 = {
-       .name             = "s3c2410-timer",
-       .id               = 2,
-       .num_resources    = ARRAY_SIZE(s3c_timer2_resource),
-       .resource         = s3c_timer2_resource,
-};
-
-EXPORT_SYMBOL(s3c_device_timer2);
-
-/* timer 3 */
-
-static struct resource s3c_timer3_resource[] = {
-       [0] = {
-               .start = S3C24XX_PA_TIMER + 0x30,
-               .end   = S3C24XX_PA_TIMER + 0x3B,
-               .flags = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start = IRQ_TIMER3,
-               .end   = IRQ_TIMER3,
-               .flags = IORESOURCE_IRQ,
-       }
-
-};
-
-struct platform_device s3c_device_timer3 = {
-       .name             = "s3c2410-timer",
-       .id               = 3,
-       .num_resources    = ARRAY_SIZE(s3c_timer3_resource),
-       .resource         = s3c_timer3_resource,
-};
-
-EXPORT_SYMBOL(s3c_device_timer3);
-
 #ifdef CONFIG_CPU_S3C2440
 
 /* Camif Controller */
diff --git a/arch/arm/plat-s3c24xx/gpiolib.c b/arch/arm/plat-s3c24xx/gpiolib.c
new file mode 100644 (file)
index 0000000..825d8d0
--- /dev/null
@@ -0,0 +1,259 @@
+/* linux/arch/arm/plat-s3c24xx/gpiolib.c
+ *
+ * Copyright (c) 2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * S3C24XX GPIOlib support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License.
+*/
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+
+#include <asm/arch/regs-gpio.h>
+
+struct s3c24xx_gpio_chip {
+       struct gpio_chip        chip;
+       void __iomem            *base;
+};
+
+static inline struct s3c24xx_gpio_chip *to_s3c_chip(struct gpio_chip *gpc)
+{
+       return container_of(gpc, struct s3c24xx_gpio_chip, chip);
+}
+
+/* these routines are exported for use by other parts of the platform
+ * and system support, but are not intended to be used directly by the
+ * drivers themsevles.
+ */
+
+int s3c24xx_gpiolib_input(struct gpio_chip *chip, unsigned offset)
+{
+       struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip);
+       void __iomem *base = ourchip->base;
+       unsigned long flags;
+       unsigned long con;
+
+       local_irq_save(flags);
+
+       con = __raw_readl(base + 0x00);
+       con &= ~(3 << (offset * 2));
+       con |= (S3C2410_GPIO_OUTPUT & 0xf) << (offset * 2);
+
+       __raw_writel(con, base + 0x00);
+
+       local_irq_restore(flags);
+       return 0;
+}
+
+int s3c24xx_gpiolib_output(struct gpio_chip *chip,
+                                 unsigned offset, int value)
+{
+       struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip);
+       void __iomem *base = ourchip->base;
+       unsigned long flags;
+       unsigned long dat;
+       unsigned long con;
+
+       local_irq_save(flags);
+
+       dat = __raw_readl(base + 0x04);
+       dat &= ~(1 << offset);
+       if (value)
+               dat |= 1 << offset;
+       __raw_writel(dat, base + 0x04);
+
+       con = __raw_readl(base + 0x00);
+       con &= ~(3 << (offset * 2));
+       con |= (S3C2410_GPIO_OUTPUT & 0xf) << (offset * 2);
+
+       __raw_writel(con, base + 0x00);
+       __raw_writel(dat, base + 0x04);
+
+       local_irq_restore(flags);
+       return 0;
+}
+
+void s3c24xx_gpiolib_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+       struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip);
+       void __iomem *base = ourchip->base;
+       unsigned long flags;
+       unsigned long dat;
+
+       local_irq_save(flags);
+
+       dat = __raw_readl(base + 0x04);
+       dat &= ~(1 << offset);
+       if (value)
+               dat |= 1 << offset;
+       __raw_writel(dat, base + 0x04);
+
+       local_irq_restore(flags);
+}
+
+int s3c24xx_gpiolib_get(struct gpio_chip *chip, unsigned offset)
+{
+       struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip);
+       unsigned long val;
+
+       val = __raw_readl(ourchip->base + 0x04);
+       val >>= offset;
+       val &= 1;
+
+       return val;
+}
+
+static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
+{
+       return -EINVAL;
+}
+
+static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
+                                       unsigned offset, int value)
+{
+       struct s3c24xx_gpio_chip *ourchip = to_s3c_chip(chip);
+       void __iomem *base = ourchip->base;
+       unsigned long flags;
+       unsigned long dat;
+       unsigned long con;
+
+       local_irq_save(flags);
+
+       con = __raw_readl(base + 0x00);
+       dat = __raw_readl(base + 0x04);
+
+       dat &= ~(1 << offset);
+       if (value)
+               dat |= 1 << offset;
+
+       __raw_writel(dat, base + 0x04);
+
+       con &= ~(1 << offset);
+
+       __raw_writel(con, base + 0x00);
+       __raw_writel(dat, base + 0x04);
+
+       local_irq_restore(flags);
+       return 0;
+}
+
+
+struct s3c24xx_gpio_chip gpios[] = {
+       [0] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPA0),
+               .chip   = {
+                       .base                   = S3C2410_GPA0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOA",
+                       .ngpio                  = 24,
+                       .direction_input        = s3c24xx_gpiolib_banka_input,
+                       .direction_output       = s3c24xx_gpiolib_banka_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [1] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPB0),
+               .chip   = {
+                       .base                   = S3C2410_GPB0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOB",
+                       .ngpio                  = 16,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [2] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPC0),
+               .chip   = {
+                       .base                   = S3C2410_GPC0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOC",
+                       .ngpio                  = 16,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [3] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPD0),
+               .chip   = {
+                       .base                   = S3C2410_GPD0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOD",
+                       .ngpio                  = 16,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [4] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPE0),
+               .chip   = {
+                       .base                   = S3C2410_GPE0,
+                       .label                  = "GPIOE",
+                       .owner                  = THIS_MODULE,
+                       .ngpio                  = 16,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [5] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPF0),
+               .chip   = {
+                       .base                   = S3C2410_GPF0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOF",
+                       .ngpio                  = 8,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+       [6] = {
+               .base   = S3C24XX_GPIO_BASE(S3C2410_GPG0),
+               .chip   = {
+                       .base                   = S3C2410_GPG0,
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOG",
+                       .ngpio                  = 10,
+                       .direction_input        = s3c24xx_gpiolib_input,
+                       .direction_output       = s3c24xx_gpiolib_output,
+                       .set                    = s3c24xx_gpiolib_set,
+                       .get                    = s3c24xx_gpiolib_get,
+               },
+       },
+};
+
+static __init int s3c24xx_gpiolib_init(void)
+{
+       struct s3c24xx_gpio_chip *chip = gpios;
+       int gpn;
+
+       for (gpn = 0; gpn < ARRAY_SIZE(gpios); gpn++, chip++)
+               gpiochip_add(&chip->chip);
+
+       return 0;
+}
+
+arch_initcall(s3c24xx_gpiolib_init);
diff --git a/arch/arm/plat-s3c24xx/pwm-clock.c b/arch/arm/plat-s3c24xx/pwm-clock.c
new file mode 100644 (file)
index 0000000..2cda3e3
--- /dev/null
@@ -0,0 +1,437 @@
+/* linux/arch/arm/plat-s3c24xx/pwm-clock.c
+ *
+ * Copyright (c) 2007 Simtec Electronics
+ * Copyright (c) 2007, 2008 Ben Dooks
+ *     Ben Dooks <ben-linux@fluff.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License.
+*/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+
+#include <asm/arch/regs-clock.h>
+#include <asm/arch/regs-gpio.h>
+
+#include <asm/plat-s3c24xx/clock.h>
+#include <asm/plat-s3c24xx/cpu.h>
+
+#include <asm/plat-s3c/regs-timer.h>
+
+/* Each of the timers 0 through 5 go through the following
+ * clock tree, with the inputs depending on the timers.
+ *
+ * pclk ---- [ prescaler 0 ] -+---> timer 0
+ *                           +---> timer 1
+ *
+ * pclk ---- [ prescaler 1 ] -+---> timer 2
+ *                           +---> timer 3
+ *                           \---> timer 4
+ *
+ * Which are fed into the timers as so:
+ *
+ * prescaled 0 ---- [ div 2,4,8,16 ] ---\
+ *                                    [mux] -> timer 0
+ * tclk 0 ------------------------------/
+ *
+ * prescaled 0 ---- [ div 2,4,8,16 ] ---\
+ *                                    [mux] -> timer 1
+ * tclk 0 ------------------------------/
+ *
+ *
+ * prescaled 1 ---- [ div 2,4,8,16 ] ---\
+ *                                    [mux] -> timer 2
+ * tclk 1 ------------------------------/
+ *
+ * prescaled 1 ---- [ div 2,4,8,16 ] ---\
+ *                                    [mux] -> timer 3
+ * tclk 1 ------------------------------/
+ *
+ * prescaled 1 ---- [ div 2,4,8, 16 ] --\
+ *                                    [mux] -> timer 4
+ * tclk 1 ------------------------------/
+ *
+ * Since the mux and the divider are tied together in the
+ * same register space, it is impossible to set the parent
+ * and the rate at the same time. To avoid this, we add an
+ * intermediate 'prescaled-and-divided' clock to select
+ * as the parent for the timer input clock called tdiv.
+ *
+ * prescaled clk --> pwm-tdiv ---\
+ *                             [ mux ] --> timer X
+ * tclk -------------------------/
+*/
+
+static unsigned long clk_pwm_scaler_getrate(struct clk *clk)
+{
+       unsigned long tcfg0 = __raw_readl(S3C2410_TCFG0);
+
+       if (clk->id == 1) {
+               tcfg0 &= S3C2410_TCFG_PRESCALER1_MASK;
+               tcfg0 >>= S3C2410_TCFG_PRESCALER1_SHIFT;
+       } else {
+               tcfg0 &= S3C2410_TCFG_PRESCALER0_MASK;
+       }
+
+       return clk_get_rate(clk->parent) / (tcfg0 + 1);
+}
+
+/* TODO - add set rate calls. */
+
+struct clk clk_timer_scaler[] = {
+       [0]     = {
+               .name           = "pwm-scaler0",
+               .id             = -1,
+               .get_rate       = clk_pwm_scaler_getrate,
+       },
+       [1]     = {
+               .name           = "pwm-scaler1",
+               .id             = -1,
+               .get_rate       = clk_pwm_scaler_getrate,
+       },
+};
+
+struct clk clk_timer_tclk[] = {
+       [0]     = {
+               .name           = "pwm-tclk0",
+               .id             = -1,
+       },
+       [1]     = {
+               .name           = "pwm-tclk1",
+               .id             = -1,
+       },
+};
+
+struct pwm_tdiv_clk {
+       struct clk      clk;
+       unsigned int    divisor;
+};
+
+static inline struct pwm_tdiv_clk *to_tdiv(struct clk *clk)
+{
+       return container_of(clk, struct pwm_tdiv_clk, clk);
+}
+
+static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
+{
+       return 1 << (1 + tcfg1);
+}
+
+static unsigned long clk_pwm_tdiv_get_rate(struct clk *clk)
+{
+       unsigned long tcfg1 = __raw_readl(S3C2410_TCFG1);
+       unsigned int divisor;
+
+       tcfg1 >>= S3C2410_TCFG1_SHIFT(clk->id);
+       tcfg1 &= S3C2410_TCFG1_MUX_MASK;
+
+       if (tcfg1 == S3C2410_TCFG1_MUX_TCLK)
+               divisor = to_tdiv(clk)->divisor;
+       else
+               divisor = tcfg_to_divisor(tcfg1);
+
+       return clk_get_rate(clk->parent) / divisor;
+}
+
+static unsigned long clk_pwm_tdiv_round_rate(struct clk *clk,
+                                            unsigned long rate)
+{
+       unsigned long parent_rate;
+       unsigned long divisor;
+
+       parent_rate = clk_get_rate(clk->parent);
+       divisor = parent_rate / rate;
+
+       if (divisor <= 2)
+               divisor = 2;
+       else if (divisor <= 4)
+               divisor = 4;
+       else if (divisor <= 8)
+               divisor = 8;
+       else
+               divisor = 16;
+
+       return parent_rate / divisor;
+}
+
+static unsigned long clk_pwm_tdiv_bits(struct pwm_tdiv_clk *divclk)
+{
+       unsigned long bits;
+
+       switch (divclk->divisor) {
+       case 2:
+               bits = S3C2410_TCFG1_MUX_DIV2;
+               break;
+       case 4:
+               bits = S3C2410_TCFG1_MUX_DIV4;
+               break;
+       case 8:
+               bits = S3C2410_TCFG1_MUX_DIV8;
+               break;
+       case 16:
+       default:
+               bits = S3C2410_TCFG1_MUX_DIV16;
+               break;
+       }
+
+       return bits;
+}
+
+static void clk_pwm_tdiv_update(struct pwm_tdiv_clk *divclk)
+{
+       unsigned long tcfg1 = __raw_readl(S3C2410_TCFG1);
+       unsigned long bits = clk_pwm_tdiv_bits(divclk);
+       unsigned long flags;
+       unsigned long shift =  S3C2410_TCFG1_SHIFT(divclk->clk.id);
+
+       local_irq_save(flags);
+
+       tcfg1 = __raw_readl(S3C2410_TCFG1);
+       tcfg1 &= ~(S3C2410_TCFG1_MUX_MASK << shift);
+       tcfg1 |= bits << shift;
+       __raw_writel(tcfg1, S3C2410_TCFG1);
+
+       local_irq_restore(flags);
+}
+
+static int clk_pwm_tdiv_set_rate(struct clk *clk, unsigned long rate)
+{
+       struct pwm_tdiv_clk *divclk = to_tdiv(clk);
+       unsigned long tcfg1 = __raw_readl(S3C2410_TCFG1);
+       unsigned long parent_rate = clk_get_rate(clk->parent);
+       unsigned long divisor;
+
+       tcfg1 >>= S3C2410_TCFG1_SHIFT(clk->id);
+       tcfg1 &= S3C2410_TCFG1_MUX_MASK;
+
+       rate = clk_round_rate(clk, rate);
+       divisor = parent_rate / rate;
+
+       if (divisor > 16)
+               return -EINVAL;
+
+       divclk->divisor = divisor;
+
+       /* Update the current MUX settings if we are currently
+        * selected as the clock source for this clock. */
+
+       if (tcfg1 != S3C2410_TCFG1_MUX_TCLK)
+               clk_pwm_tdiv_update(divclk);
+
+       return 0;
+}
+
+struct pwm_tdiv_clk clk_timer_tdiv[] = {
+       [0]     = {
+               .clk    = {
+                       .name           = "pwm-tdiv",
+                       .parent         = &clk_timer_scaler[0],
+                       .get_rate       = clk_pwm_tdiv_get_rate,
+                       .set_rate       = clk_pwm_tdiv_set_rate,
+                       .round_rate     = clk_pwm_tdiv_round_rate,
+               },
+       },
+       [1]     = {
+               .clk    = {
+                       .name           = "pwm-tdiv",
+                       .parent         = &clk_timer_scaler[0],
+                       .get_rate       = clk_pwm_tdiv_get_rate,
+                       .set_rate       = clk_pwm_tdiv_set_rate,
+                       .round_rate     = clk_pwm_tdiv_round_rate,
+               }
+       },
+       [2]     = {
+               .clk    = {
+                       .name           = "pwm-tdiv",
+                       .parent         = &clk_timer_scaler[1],
+                       .get_rate       = clk_pwm_tdiv_get_rate,
+                       .set_rate       = clk_pwm_tdiv_set_rate,
+                       .round_rate     = clk_pwm_tdiv_round_rate,
+               },
+       },
+       [3]     = {
+               .clk    = {
+                       .name           = "pwm-tdiv",
+                       .parent         = &clk_timer_scaler[1],
+                       .get_rate       = clk_pwm_tdiv_get_rate,
+                       .set_rate       = clk_pwm_tdiv_set_rate,
+                       .round_rate     = clk_pwm_tdiv_round_rate,
+               },
+       },
+       [4]     = {
+               .clk    = {
+                       .name           = "pwm-tdiv",
+                       .parent         = &clk_timer_scaler[1],
+                       .get_rate       = clk_pwm_tdiv_get_rate,
+                       .set_rate       = clk_pwm_tdiv_set_rate,
+                       .round_rate     = clk_pwm_tdiv_round_rate,
+               },
+       },
+};
+
+static int __init clk_pwm_tdiv_register(unsigned int id)
+{
+       struct pwm_tdiv_clk *divclk = &clk_timer_tdiv[id];
+       unsigned long tcfg1 = __raw_readl(S3C2410_TCFG1);
+
+       tcfg1 >>= S3C2410_TCFG1_SHIFT(id);
+       tcfg1 &= S3C2410_TCFG1_MUX_MASK;
+
+       divclk->clk.id = id;
+       divclk->divisor = tcfg_to_divisor(tcfg1);
+
+       return s3c24xx_register_clock(&divclk->clk);
+}
+
+static inline struct clk *s3c24xx_pwmclk_tclk(unsigned int id)
+{
+       return (id >= 2) ? &clk_timer_tclk[1] : &clk_timer_tclk[0];
+}
+
+static inline struct clk *s3c24xx_pwmclk_tdiv(unsigned int id)
+{
+       return &clk_timer_tdiv[id].clk;
+}
+
+static int clk_pwm_tin_set_parent(struct clk *clk, struct clk *parent)
+{
+       unsigned int id = clk->id;
+       unsigned long tcfg1;
+       unsigned long flags;
+       unsigned long bits;
+       unsigned long shift = S3C2410_TCFG1_SHIFT(id);
+
+       if (parent == s3c24xx_pwmclk_tclk(id))
+               bits = S3C2410_TCFG1_MUX_TCLK << shift;
+       else if (parent == s3c24xx_pwmclk_tdiv(id))
+               bits = clk_pwm_tdiv_bits(to_tdiv(clk)) << shift;
+       else
+               return -EINVAL;
+
+       clk->parent = parent;
+
+       local_irq_save(flags);
+
+       tcfg1 = __raw_readl(S3C2410_TCFG1);
+       tcfg1 &= ~(S3C2410_TCFG1_MUX_MASK << shift);
+       __raw_writel(tcfg1 | bits, S3C2410_TCFG1);
+
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+static struct clk clk_tin[] = {
+       [0]     = {
+               .name           = "pwm-tin",
+               .id             = 0,
+               .set_parent     = clk_pwm_tin_set_parent,
+       },
+       [1]     = {
+               .name           = "pwm-tin",
+               .id             = 1,
+               .set_parent     = clk_pwm_tin_set_parent,
+       },
+       [2]     = {
+               .name           = "pwm-tin",
+               .id             = 2,
+               .set_parent     = clk_pwm_tin_set_parent,
+       },
+       [3]     = {
+               .name           = "pwm-tin",
+               .id             = 3,
+               .set_parent     = clk_pwm_tin_set_parent,
+       },
+       [4]     = {
+               .name           = "pwm-tin",
+               .id             = 4,
+               .set_parent     = clk_pwm_tin_set_parent,
+       },
+};
+
+static __init int clk_pwm_tin_register(struct clk *pwm)
+{
+       unsigned long tcfg1 = __raw_readl(S3C2410_TCFG1);
+       unsigned int id = pwm->id;
+
+       struct clk *parent;
+       int ret;
+
+       ret = s3c24xx_register_clock(pwm);
+       if (ret < 0)
+               return ret;
+
+       tcfg1 >>= S3C2410_TCFG1_SHIFT(id);
+       tcfg1 &= S3C2410_TCFG1_MUX_MASK;
+
+       if (tcfg1 == S3C2410_TCFG1_MUX_TCLK)
+               parent = s3c24xx_pwmclk_tclk(id);
+       else
+               parent = s3c24xx_pwmclk_tdiv(id);
+
+       return clk_set_parent(pwm, parent);
+}
+
+static __init int s3c24xx_pwmclk_init(void)
+{
+       struct clk *clk_timers;
+       unsigned int clk;
+       int ret;
+
+       clk_timers = clk_get(NULL, "timers");
+       if (IS_ERR(clk_timers)) {
+               printk(KERN_ERR "%s: no parent clock\n", __func__);
+               return -EINVAL;
+       }
+
+       for (clk = 0; clk < ARRAY_SIZE(clk_timer_scaler); clk++) {
+               clk_timer_scaler[clk].parent = clk_timers;
+               ret = s3c24xx_register_clock(&clk_timer_scaler[clk]);
+               if (ret < 0) {
+                       printk(KERN_ERR "error adding pwm scaler%d clock\n", clk);
+                       goto err;
+               }
+       }
+
+       for (clk = 0; clk < ARRAY_SIZE(clk_timer_tclk); clk++) {
+               ret = s3c24xx_register_clock(&clk_timer_tclk[clk]);
+               if (ret < 0) {
+                       printk(KERN_ERR "error adding pww tclk%d\n", clk);
+                       goto err;
+               }
+       }
+
+       for (clk = 0; clk < ARRAY_SIZE(clk_timer_tdiv); clk++) {
+               ret = clk_pwm_tdiv_register(clk);
+               if (ret < 0) {
+                       printk(KERN_ERR "error adding pwm%d tdiv clock\n", clk);
+                       goto err;
+               }
+       }
+
+       for (clk = 0; clk < ARRAY_SIZE(clk_tin); clk++) {
+               ret = clk_pwm_tin_register(&clk_tin[clk]);
+               if (ret < 0) {
+                       printk(KERN_ERR "error adding pwm%d tin clock\n", clk);
+                       goto err;
+               }
+       }
+
+       return 0;
+
+ err:
+       return ret;
+}
+
+arch_initcall(s3c24xx_pwmclk_init);
diff --git a/arch/arm/plat-s3c24xx/pwm.c b/arch/arm/plat-s3c24xx/pwm.c
new file mode 100644 (file)
index 0000000..18c4bdc
--- /dev/null
@@ -0,0 +1,402 @@
+/* arch/arm/plat-s3c24xx/pwm.c
+ *
+ * Copyright (c) 2007 Ben Dooks
+ * Copyright (c) 2008 Simtec Electronics
+ *     Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
+ *
+ * S3C24XX PWM device core
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License.
+*/
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/pwm.h>
+
+#include <asm/plat-s3c/regs-timer.h>
+
+struct pwm_device {
+       struct list_head         list;
+       struct platform_device  *pdev;
+
+       struct clk              *clk_div;
+       struct clk              *clk;
+       const char              *label;
+
+       unsigned int             period_ns;
+       unsigned int             duty_ns;
+
+       unsigned char            tcon_base;
+       unsigned char            running;
+       unsigned char            use_count;
+       unsigned char            pwm_id;
+};
+
+#define pwm_dbg(_pwm, msg...) dev_info(&(_pwm)->pdev->dev, msg)
+
+static struct clk *clk_scaler[2];
+
+/* Standard setup for a timer block. */
+
+#define TIMER_RESOURCE_SIZE (1)
+
+#define TIMER_RESOURCE(_tmr, _irq)                     \
+       (struct resource [TIMER_RESOURCE_SIZE]) {       \
+               [0] = {                                 \
+                       .start  = _irq,                 \
+                       .end    = _irq,                 \
+                       .flags  = IORESOURCE_IRQ        \
+               }                                       \
+       }
+
+#define DEFINE_TIMER(_tmr_no, _irq)                    \
+       .name           = "s3c24xx-pwm",                \
+       .id             = _tmr_no,                      \
+       .num_resources  = TIMER_RESOURCE_SIZE,          \
+       .resource       = TIMER_RESOURCE(_tmr_no, _irq),        \
+
+/* since we already have an static mapping for the timer, we do not
+ * bother setting any IO resource for the base.
+ */
+
+struct platform_device s3c_device_timer[] = {
+       [0] = { DEFINE_TIMER(0, IRQ_TIMER0) },
+       [1] = { DEFINE_TIMER(1, IRQ_TIMER1) },
+       [2] = { DEFINE_TIMER(2, IRQ_TIMER2) },
+       [3] = { DEFINE_TIMER(3, IRQ_TIMER3) },
+       [4] = { DEFINE_TIMER(4, IRQ_TIMER4) },
+};
+
+static inline int pwm_is_tdiv(struct pwm_device *pwm)
+{
+       return clk_get_parent(pwm->clk) == pwm->clk_div;
+}
+
+static DEFINE_MUTEX(pwm_lock);
+static LIST_HEAD(pwm_list);
+
+struct pwm_device *pwm_request(int pwm_id, const char *label)
+{
+       struct pwm_device *pwm;
+       int found = 0;
+
+       mutex_lock(&pwm_lock);
+
+       list_for_each_entry(pwm, &pwm_list, list) {
+               if (pwm->pwm_id == pwm_id) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (found) {
+               if (pwm->use_count == 0) {
+                       pwm->use_count = 1;
+                       pwm->label = label;
+               } else
+                       pwm = ERR_PTR(-EBUSY);
+       } else
+               pwm = ERR_PTR(-ENOENT);
+
+       mutex_unlock(&pwm_lock);
+       return pwm;
+}
+
+EXPORT_SYMBOL(pwm_request);
+
+
+void pwm_free(struct pwm_device *pwm)
+{
+       mutex_lock(&pwm_lock);
+
+       if (pwm->use_count) {
+               pwm->use_count--;
+               pwm->label = NULL;
+       } else
+               printk(KERN_ERR "PWM%d device already freed\n", pwm->pwm_id);
+
+       mutex_unlock(&pwm_lock);
+}
+
+EXPORT_SYMBOL(pwm_free);
+
+#define pwm_tcon_start(pwm) (1 << (pwm->tcon_base + 0))
+#define pwm_tcon_invert(pwm) (1 << (pwm->tcon_base + 2))
+#define pwm_tcon_autoreload(pwm) (1 << (pwm->tcon_base + 3))
+#define pwm_tcon_manulupdate(pwm) (1 << (pwm->tcon_base + 1))
+
+int pwm_enable(struct pwm_device *pwm)
+{
+       unsigned long flags;
+       unsigned long tcon;
+
+       local_irq_save(flags);
+
+       tcon = __raw_readl(S3C2410_TCON);
+       tcon |= pwm_tcon_start(pwm);
+       __raw_writel(tcon, S3C2410_TCON);
+
+       local_irq_restore(flags);
+
+       pwm->running = 1;
+       return 0;
+}
+
+EXPORT_SYMBOL(pwm_enable);
+
+void pwm_disable(struct pwm_device *pwm)
+{
+       unsigned long flags;
+       unsigned long tcon;
+
+       local_irq_save(flags);
+
+       tcon = __raw_readl(S3C2410_TCON);
+       tcon &= ~pwm_tcon_start(pwm);
+       __raw_writel(tcon, S3C2410_TCON);
+
+       local_irq_restore(flags);
+
+       pwm->running = 0;
+}
+
+EXPORT_SYMBOL(pwm_disable);
+
+unsigned long pwm_calc_tin(struct pwm_device *pwm, unsigned long freq)
+{
+       unsigned long tin_parent_rate;
+       unsigned int div;
+
+       tin_parent_rate = clk_get_rate(clk_get_parent(pwm->clk_div));
+       pwm_dbg(pwm, "tin parent at %lu\n", tin_parent_rate);
+
+       for (div = 2; div <= 16; div *= 2) {
+               if ((tin_parent_rate / (div << 16)) < freq)
+                       return tin_parent_rate / div;
+       }
+
+       return tin_parent_rate / 16;
+}
+
+#define NS_IN_HZ (1000000000UL)
+
+int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
+{
+       unsigned long tin_rate;
+       unsigned long tin_ns;
+       unsigned long period;
+       unsigned long flags;
+       unsigned long tcon;
+       unsigned long tcnt;
+       long tcmp;
+
+       /* We currently avoid using 64bit arithmetic by using the
+        * fact that anything faster than 1Hz is easily representable
+        * by 32bits. */
+
+       if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ)
+               return -ERANGE;
+
+       if (duty_ns > period_ns)
+               return -EINVAL;
+
+       if (period_ns == pwm->period_ns &&
+           duty_ns == pwm->duty_ns)
+               return 0;
+
+       /* The TCMP and TCNT can be read without a lock, they're not
+        * shared between the timers. */
+
+       tcmp = __raw_readl(S3C2410_TCMPB(pwm->pwm_id));
+       tcnt = __raw_readl(S3C2410_TCNTB(pwm->pwm_id));
+
+       period = NS_IN_HZ / period_ns;
+
+       pwm_dbg(pwm, "duty_ns=%d, period_ns=%d (%lu)\n",
+               duty_ns, period_ns, period);
+
+       /* Check to see if we are changing the clock rate of the PWM */
+
+       if (pwm->period_ns != period_ns) {
+               if (pwm_is_tdiv(pwm)) {
+                       tin_rate = pwm_calc_tin(pwm, period);
+                       clk_set_rate(pwm->clk_div, tin_rate);
+               } else
+                       tin_rate = clk_get_rate(pwm->clk);
+
+               pwm->period_ns = period_ns;
+
+               pwm_dbg(pwm, "tin_rate=%lu\n", tin_rate);
+
+               tin_ns = NS_IN_HZ / tin_rate;
+               tcnt = period_ns / tin_ns;
+       } else
+               tin_ns = NS_IN_HZ / clk_get_rate(pwm->clk);
+
+       /* Note, counters count down */
+
+       tcmp = duty_ns / tin_ns;
+       tcmp = tcnt - tcmp;
+
+       pwm_dbg(pwm, "tin_ns=%lu, tcmp=%ld/%lu\n", tin_ns, tcmp, tcnt);
+
+       if (tcmp < 0)
+               tcmp = 0;
+
+       /* Update the PWM register block. */
+
+       local_irq_save(flags);
+
+       __raw_writel(tcmp, S3C2410_TCMPB(pwm->pwm_id));
+       __raw_writel(tcnt, S3C2410_TCNTB(pwm->pwm_id));
+
+       tcon = __raw_readl(S3C2410_TCON);
+       tcon |= pwm_tcon_manulupdate(pwm);
+       tcon |= pwm_tcon_autoreload(pwm);
+       __raw_writel(tcon, S3C2410_TCON);
+
+       tcon &= ~pwm_tcon_manulupdate(pwm);
+       __raw_writel(tcon, S3C2410_TCON);
+
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+EXPORT_SYMBOL(pwm_config);
+
+static int pwm_register(struct pwm_device *pwm)
+{
+       pwm->duty_ns = -1;
+       pwm->period_ns = -1;
+
+       mutex_lock(&pwm_lock);
+       list_add_tail(&pwm->list, &pwm_list);
+       mutex_unlock(&pwm_lock);
+
+       return 0;
+}
+
+static int s3c_pwm_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct pwm_device *pwm;
+       unsigned long flags;
+       unsigned long tcon;
+       unsigned int id = pdev->id;
+       int ret;
+
+       if (id == 4) {
+               dev_err(dev, "TIMER4 is currently not supported\n");
+               return -ENXIO;
+       }
+
+       pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
+       if (pwm == NULL) {
+               dev_err(dev, "failed to allocate pwm_device\n");
+               return -ENOMEM;
+       }
+
+       pwm->pdev = pdev;
+       pwm->pwm_id = id;
+
+       /* calculate base of control bits in TCON */
+       pwm->tcon_base = id == 0 ? 0 : (id * 4) + 4;
+
+       pwm->clk = clk_get(dev, "pwm-tin");
+       if (IS_ERR(pwm->clk)) {
+               dev_err(dev, "failed to get pwm tin clk\n");
+               ret = PTR_ERR(pwm->clk);
+               goto err_alloc;
+       }
+
+       pwm->clk_div = clk_get(dev, "pwm-tdiv");
+       if (IS_ERR(pwm->clk_div)) {
+               dev_err(dev, "failed to get pwm tdiv clk\n");
+               ret = PTR_ERR(pwm->clk_div);
+               goto err_clk_tin;
+       }
+
+       local_irq_save(flags);
+
+       tcon = __raw_readl(S3C2410_TCON);
+       tcon |= pwm_tcon_invert(pwm);
+       __raw_writel(tcon, S3C2410_TCON);
+
+       local_irq_restore(flags);
+
+
+       ret = pwm_register(pwm);
+       if (ret) {
+               dev_err(dev, "failed to register pwm\n");
+               goto err_clk_tdiv;
+       }
+
+       pwm_dbg(pwm, "config bits %02x\n",
+               (__raw_readl(S3C2410_TCON) >> pwm->tcon_base) & 0x0f);
+
+       dev_info(dev, "tin at %lu, tdiv at %lu, tin=%sclk, base %d\n",
+                clk_get_rate(pwm->clk),
+                clk_get_rate(pwm->clk_div),
+                pwm_is_tdiv(pwm) ? "div" : "ext", pwm->tcon_base);
+
+       platform_set_drvdata(pdev, pwm);
+       return 0;
+
+ err_clk_tdiv:
+       clk_put(pwm->clk_div);
+
+ err_clk_tin:
+       clk_put(pwm->clk);
+
+ err_alloc:
+       kfree(pwm);
+       return ret;
+}
+
+static int s3c_pwm_remove(struct platform_device *pdev)
+{
+       struct pwm_device *pwm = platform_get_drvdata(pdev);
+
+       clk_put(pwm->clk_div);
+       clk_put(pwm->clk);
+       kfree(pwm);
+
+       return 0;
+}
+
+static struct platform_driver s3c_pwm_driver = {
+       .driver         = {
+               .name   = "s3c24xx-pwm",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = s3c_pwm_probe,
+       .remove         = __devexit_p(s3c_pwm_remove),
+};
+
+static int __init pwm_init(void)
+{
+       int ret;
+
+       clk_scaler[0] = clk_get(NULL, "pwm-scaler0");
+       clk_scaler[1] = clk_get(NULL, "pwm-scaler1");
+
+       if (IS_ERR(clk_scaler[0]) || IS_ERR(clk_scaler[1])) {
+               printk(KERN_ERR "%s: failed to get scaler clocks\n", __func__);
+               return -EINVAL;
+       }
+
+       ret = platform_driver_register(&s3c_pwm_driver);
+       if (ret)
+               printk(KERN_ERR "%s: failed to add pwm driver\n", __func__);
+
+       return ret;
+}
+
+arch_initcall(pwm_init);
index 207a8b5..0be5630 100644 (file)
@@ -12,7 +12,7 @@
 #
 #   http://www.arm.linux.org.uk/developer/machines/?action=new
 #
-# Last update: Sat Apr 19 11:23:38 2008
+# Last update: Mon Jul 7 16:25:39 2008
 #
 # machine_is_xxx       CONFIG_xxxx             MACH_TYPE_xxx           number
 #
@@ -560,7 +560,6 @@ husky                       MACH_HUSKY              HUSKY                   543
 boxer                  MACH_BOXER              BOXER                   544
 shepherd               MACH_SHEPHERD           SHEPHERD                545
 aml42800aa             MACH_AML42800AA         AML42800AA              546
-ml674001               MACH_MACH_TYPE_ML674001 MACH_TYPE_ML674001      547
 lpc2294                        MACH_LPC2294            LPC2294                 548
 switchgrass            MACH_SWITCHGRASS        SWITCHGRASS             549
 ens_cmu                        MACH_ENS_CMU            ENS_CMU                 550
@@ -748,7 +747,6 @@ anubis                      MACH_ANUBIS             ANUBIS                  734
 ite8152                        MACH_ITE8152            ITE8152                 735
 lpc3xxx                        MACH_LPC3XXX            LPC3XXX                 736
 puppeteer              MACH_PUPPETEER          PUPPETEER               737
-vt001                  MACH_MACH_VADATECH      MACH_VADATECH           738
 e570                   MACH_E570               E570                    739
 x50                    MACH_X50                X50                     740
 recon                  MACH_RECON              RECON                   741
@@ -839,7 +837,7 @@ ccxp270                     MACH_CCXP               CCXP                    825
 omap_gsample           MACH_OMAP_GSAMPLE       OMAP_GSAMPLE            826
 realview_eb            MACH_REALVIEW_EB        REALVIEW_EB             827
 samoa                  MACH_SAMOA              SAMOA                   828
-t3xscale               MACH_T3XSCALE           T3XSCALE                829
+palmt3                 MACH_PALMT3             PALMT3                  829
 i878                   MACH_I878               I878                    830
 borzoi                 MACH_BORZOI             BORZOI                  831
 gecko                  MACH_GECKO              GECKO                   832
@@ -895,7 +893,7 @@ mio8390                     MACH_MIO8390            MIO8390                 881
 omi_board              MACH_OMI_BOARD          OMI_BOARD               882
 mx21civ                        MACH_MX21CIV            MX21CIV                 883
 mahi_cdac              MACH_MAHI_CDAC          MAHI_CDAC               884
-xscale_palmtx          MACH_XSCALE_PALMTX      XSCALE_PALMTX           885
+palmtx                 MACH_PALMTX             PALMTX                  885
 s3c2413                        MACH_S3C2413            S3C2413                 887
 samsys_ep0             MACH_SAMSYS_EP0         SAMSYS_EP0              888
 wg302v1                        MACH_WG302V1            WG302V1                 889
@@ -918,7 +916,7 @@ nxdb500                     MACH_NXDB500            NXDB500                 905
 apf9328                        MACH_APF9328            APF9328                 906
 omap_wipoq             MACH_OMAP_WIPOQ         OMAP_WIPOQ              907
 omap_twip              MACH_OMAP_TWIP          OMAP_TWIP               908
-xscale_treo650         MACH_XSCALE_PALMTREO650 XSCALE_PALMTREO650      909
+palmtreo650            MACH_PALMTREO650        PALMTREO650             909
 acumen                 MACH_ACUMEN             ACUMEN                  910
 xp100                  MACH_XP100              XP100                   911
 fs2410                 MACH_FS2410             FS2410                  912
@@ -926,8 +924,8 @@ pxa270_cerf         MACH_PXA270_CERF        PXA270_CERF             913
 sq2ftlpalm             MACH_SQ2FTLPALM         SQ2FTLPALM              914
 bsemserver             MACH_BSEMSERVER         BSEMSERVER              915
 netclient              MACH_NETCLIENT          NETCLIENT               916
-xscale_palmtt5         MACH_XSCALE_PALMTT5     XSCALE_PALMTT5          917
-xscale_palmtc          MACH_OMAP_PALMTC        OMAP_PALMTC             918
+palmt5                 MACH_PALMT5             PALMT5                  917
+palmtc                 MACH_PALMTC             PALMTC                  918
 omap_apollon           MACH_OMAP_APOLLON       OMAP_APOLLON            919
 mxc30030evb            MACH_MXC30030EVB        MXC30030EVB             920
 rea_2d                 MACH_REA_2D             REA_2D                  921
@@ -1220,7 +1218,6 @@ empca400          MACH_EMPCA400           EMPCA400                1211
 em7210                 MACH_EM7210             EM7210                  1212
 htchermes              MACH_HTCHERMES          HTCHERMES               1213
 eti_c1                 MACH_ETI_C1             ETI_C1                  1214
-mach_dep2410           MACH_MACH_DEP2410       MACH_DEP2410            1215
 ac100                  MACH_AC100              AC100                   1216
 sneetch                        MACH_SNEETCH            SNEETCH                 1217
 studentmate            MACH_STUDENTMATE        STUDENTMATE             1218
@@ -1421,10 +1418,10 @@ looxc550                MACH_LOOXC550           LOOXC550                1417
 cnty_titan             MACH_CNTY_TITAN         CNTY_TITAN              1418
 app3xx                 MACH_APP3XX             APP3XX                  1419
 sideoatsgrama          MACH_SIDEOATSGRAMA      SIDEOATSGRAMA           1420
-xscale_palmt700p       MACH_XSCALE_PALMT700P   XSCALE_PALMT700P        1421
-xscale_palmt700w       MACH_XSCALE_PALMT700W   XSCALE_PALMT700W        1422
-xscale_palmt750                MACH_XSCALE_PALMT750    XSCALE_PALMT750         1423
-xscale_palmt755p       MACH_XSCALE_PALMT755P   XSCALE_PALMT755P        1424
+palmtreo700p           MACH_PALMTREO700P       PALMTREO700P            1421
+palmtreo700w           MACH_PALMTREO700W       PALMTREO700W            1422
+palmtreo750            MACH_PALMTREO750        PALMTREO750             1423
+palmtreo755p           MACH_PALMTREO755P       PALMTREO755P            1424
 ezreganut9200          MACH_EZREGANUT9200      EZREGANUT9200           1425
 sarge                  MACH_SARGE              SARGE                   1426
 a696                   MACH_A696               A696                    1427
@@ -1463,7 +1460,7 @@ artemis                   MACH_ARTEMIS            ARTEMIS                 1462
 htctitan               MACH_HTCTITAN           HTCTITAN                1463
 qranium                        MACH_QRANIUM            QRANIUM                 1464
 adx_wsc2               MACH_ADX_WSC2           ADX_WSC2                1465
-adx_medcom             MACH_ADX_MEDINET        ADX_MEDINET             1466
+adx_medcom             MACH_ADX_MEDCOM         ADX_MEDCOM              1466
 bboard                 MACH_BBOARD             BBOARD                  1467
 cambria                        MACH_CAMBRIA            CAMBRIA                 1468
 mt7xxx                 MACH_MT7XXX             MT7XXX                  1469
@@ -1519,7 +1516,7 @@ wp188                     MACH_WP188              WP188                   1518
 corsica                        MACH_CORSICA            CORSICA                 1519
 bigeye                 MACH_BIGEYE             BIGEYE                  1520
 tll5000                        MACH_TLL5000            TLL5000                 1522
-hni270                 MACH_HNI_X270           HNI_X270                1523
+bebot                  MACH_BEBOT              BEBOT                   1523
 qong                   MACH_QONG               QONG                    1524
 tcompact               MACH_TCOMPACT           TCOMPACT                1525
 puma5                  MACH_PUMA5              PUMA5                   1526
@@ -1636,7 +1633,6 @@ awlug4lcu         MACH_AWLUG4LCU          AWLUG4LCU               1637
 palermoc               MACH_PALERMOC           PALERMOC                1638
 omap_ldp               MACH_OMAP_LDP           OMAP_LDP                1639
 ip500                  MACH_IP500              IP500                   1640
-mx35ads                        MACH_MACH_MX35ADS       MACH_MX35ADS            1641
 ase2                   MACH_ASE2               ASE2                    1642
 mx35evb                        MACH_MX35EVB            MX35EVB                 1643
 aml_m8050              MACH_AML_M8050          AML_M8050               1644
@@ -1647,7 +1643,7 @@ badger                    MACH_BADGER             BADGER                  1648
 trizeps4wl             MACH_TRIZEPS4WL         TRIZEPS4WL              1649
 trizeps5               MACH_TRIZEPS5           TRIZEPS5                1650
 marlin                 MACH_MARLIN             MARLIN                  1651
-ts7800                 MACH_TS7800             TS7800                  1652
+ts78xx                 MACH_TS78XX             TS78XX                  1652
 hpipaq214              MACH_HPIPAQ214          HPIPAQ214               1653
 at572d940dcm           MACH_AT572D940DCM       AT572D940DCM            1654
 ne1board               MACH_NE1BOARD           NE1BOARD                1655
@@ -1720,3 +1716,99 @@ htc_kaiser               MACH_HTC_KAISER         HTC_KAISER              1724
 lg_ks20                        MACH_LG_KS20            LG_KS20                 1725
 hhgps                  MACH_HHGPS              HHGPS                   1726
 nokia_n810_wimax       MACH_NOKIA_N810_WIMAX   NOKIA_N810_WIMAX        1727
+insight                        MACH_INSIGHT            INSIGHT                 1728
+sapphire               MACH_SAPPHIRE           SAPPHIRE                1729
+csb637xo               MACH_CSB637XO           CSB637XO                1730
+evisiong               MACH_EVISIONG           EVISIONG                1731
+stmp37xx               MACH_STMP37XX           STMP37XX                1732
+stmp378x               MACH_STMP38XX           STMP38XX                1733
+tnt                    MACH_TNT                TNT                     1734
+tbxt                   MACH_TBXT               TBXT                    1735
+playmate               MACH_PLAYMATE           PLAYMATE                1736
+pns10                  MACH_PNS10              PNS10                   1737
+eznavi                 MACH_EZNAVI             EZNAVI                  1738
+ps4000                 MACH_PS4000             PS4000                  1739
+ezx_a780               MACH_EZX_A780           EZX_A780                1740
+ezx_e680               MACH_EZX_E680           EZX_E680                1741
+ezx_a1200              MACH_EZX_A1200          EZX_A1200               1742
+ezx_e6                 MACH_EZX_E6             EZX_E6                  1743
+ezx_e2                 MACH_EZX_E2             EZX_E2                  1744
+ezx_a910               MACH_EZX_A910           EZX_A910                1745
+cwmx31                 MACH_CWMX31             CWMX31                  1746
+sl2312                 MACH_SL2312             SL2312                  1747
+blenny                 MACH_BLENNY             BLENNY                  1748
+ds107                  MACH_DS107              DS107                   1749
+dsx07                  MACH_DSX07              DSX07                   1750
+picocom1               MACH_PICOCOM1           PICOCOM1                1751
+lynx_wolverine         MACH_LYNX_WOLVERINE     LYNX_WOLVERINE          1752
+ubisys_p9_sc19         MACH_UBISYS_P9_SC19     UBISYS_P9_SC19          1753
+kratos_low             MACH_KRATOS_LOW         KRATOS_LOW              1754
+m700                   MACH_M700               M700                    1755
+edmini_v2              MACH_EDMINI_V2          EDMINI_V2               1756
+zipit2                 MACH_ZIPIT2             ZIPIT2                  1757
+hslfemtocell           MACH_HSLFEMTOCELL       HSLFEMTOCELL            1758
+daintree_at91          MACH_DAINTREE_AT91      DAINTREE_AT91           1759
+sg560usb               MACH_SG560USB           SG560USB                1760
+omap3_pandora          MACH_OMAP3_PANDORA      OMAP3_PANDORA           1761
+usr8200                        MACH_USR8200            USR8200                 1762
+s1s65k                 MACH_S1S65K             S1S65K                  1763
+s2s65a                 MACH_S2S65A             S2S65A                  1764
+icore                  MACH_ICORE              ICORE                   1765
+mss2                   MACH_MSS2               MSS2                    1766
+belmont                        MACH_BELMONT            BELMONT                 1767
+asusp525               MACH_ASUSP525           ASUSP525                1768
+lb88rc8480             MACH_LB88RC8480         LB88RC8480              1769
+hipxa                  MACH_HIPXA              HIPXA                   1770
+mx25_3ds               MACH_MX25_3DS           MX25_3DS                1771
+m800                   MACH_M800               M800                    1772
+omap3530_lv_som                MACH_OMAP3530_LV_SOM    OMAP3530_LV_SOM         1773
+prima_evb              MACH_PRIMA_EVB          PRIMA_EVB               1774
+mx31bt1                        MACH_MX31BT1            MX31BT1                 1775
+atlas4_evb             MACH_ATLAS4_EVB         ATLAS4_EVB              1776
+mx31cicada             MACH_MX31CICADA         MX31CICADA              1777
+mi424wr                        MACH_MI424WR            MI424WR                 1778
+axs_ultrax             MACH_AXS_ULTRAX         AXS_ULTRAX              1779
+at572d940deb           MACH_AT572D940DEB       AT572D940DEB            1780
+davinci_da8xx_evm      MACH_DAVINCI_DA8XX_EVM  DAVINCI_DA8XX_EVM       1781
+ep9302                 MACH_EP9302             EP9302                  1782
+at572d940hfeb          MACH_AT572D940HFEB      AT572D940HFEB           1783
+cybook3                        MACH_CYBOOK3            CYBOOK3                 1784
+wdg002                 MACH_WDG002             WDG002                  1785
+sg560adsl              MACH_SG560ADSL          SG560ADSL               1786
+nextio_n2800_ica       MACH_NEXTIO_N2800_ICA   NEXTIO_N2800_ICA        1787
+marvell_newdb          MACH_MARVELL_NEWDB      MARVELL_NEWDB           1789
+vandihud               MACH_VANDIHUD           VANDIHUD                1790
+magx_e8                        MACH_MAGX_E8            MAGX_E8                 1791
+magx_z6                        MACH_MAGX_Z6            MAGX_Z6                 1792
+magx_v8                        MACH_MAGX_V8            MAGX_V8                 1793
+magx_u9                        MACH_MAGX_U9            MAGX_U9                 1794
+toughcf08              MACH_TOUGHCF08          TOUGHCF08               1795
+zw4400                 MACH_ZW4400             ZW4400                  1796
+marat91                        MACH_MARAT91            MARAT91                 1797
+overo                  MACH_OVERO              OVERO                   1798
+at2440evb              MACH_AT2440EVB          AT2440EVB               1799
+neocore926             MACH_NEOCORE926         NEOCORE926              1800
+wnr854t                        MACH_WNR854T            WNR854T                 1801
+imx27                  MACH_IMX27              IMX27                   1802
+moose_db               MACH_MOOSE_DB           MOOSE_DB                1803
+fab4                   MACH_FAB4               FAB4                    1804
+htcdiamond             MACH_HTCDIAMOND         HTCDIAMOND              1805
+fiona                  MACH_FIONA              FIONA                   1806
+mxc30030_x             MACH_MXC30030_X         MXC30030_X              1807
+bmp1000                        MACH_BMP1000            BMP1000                 1808
+logi9200               MACH_LOGI9200           LOGI9200                1809
+tqma31                 MACH_TQMA31             TQMA31                  1810
+ccw9p9215js            MACH_CCW9P9215JS        CCW9P9215JS             1811
+rd88f5181l_ge          MACH_RD88F5181L_GE      RD88F5181L_GE           1812
+sifmain                        MACH_SIFMAIN            SIFMAIN                 1813
+sam9_l9261             MACH_SAM9_L9261         SAM9_L9261              1814
+cc9m2443js             MACH_CC9M2443JS         CC9M2443JS              1815
+xaria300               MACH_XARIA300           XARIA300                1816
+it9200                 MACH_IT9200             IT9200                  1817
+rd88f5181l_fxo         MACH_RD88F5181L_FXO     RD88F5181L_FXO          1818
+kriss_sensor           MACH_KRISS_SENSOR       KRISS_SENSOR            1819
+pilz_pmi5              MACH_PILZ_PMI5          PILZ_PMI5               1820
+jade                   MACH_JADE               JADE                    1821
+ks8695_softplc         MACH_KS8695_SOFTPLC     KS8695_SOFTPLC          1822
+gprisc4                        MACH_GPRISC4            GPRISC4                 1823
+stamp9260              MACH_STAMP9260          STAMP9260               1824
index 09ad799..45d63c9 100644 (file)
@@ -88,6 +88,7 @@ config PLATFORM_AT32AP
        select MMU
        select PERFORMANCE_COUNTERS
        select HAVE_GPIO_LIB
+       select GENERIC_ALLOCATOR
 
 #
 # CPU types
@@ -147,6 +148,9 @@ config PHYS_OFFSET
 
 source "kernel/Kconfig.preempt"
 
+config QUICKLIST
+       def_bool y
+
 config HAVE_ARCH_BOOTMEM_NODE
        def_bool n
 
@@ -201,6 +205,11 @@ endmenu
 
 menu "Power management options"
 
+source "kernel/power/Kconfig"
+
+config ARCH_SUSPEND_POSSIBLE
+       def_bool y
+
 menu "CPU Frequency scaling"
 
 source "drivers/cpufreq/Kconfig"
index a398be2..a51bb9f 100644 (file)
@@ -9,6 +9,8 @@
  */
 #include <linux/clk.h>
 #include <linux/etherdevice.h>
+#include <linux/irq.h>
+#include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 #include <linux/init.h>
 #include <linux/linkage.h>
 #include <asm/arch/init.h>
 #include <asm/arch/portmux.h>
 
+/* Oscillator frequencies. These are board-specific */
+unsigned long at32_board_osc_rates[3] = {
+       [0] = 32768,    /* 32.768 kHz on RTC osc */
+       [1] = 20000000, /* 20 MHz on osc0 */
+       [2] = 12000000, /* 12 MHz on osc1 */
+};
+
 /* Initialized by bootloader-specific startup code. */
 struct tag *bootloader_tags __initdata;
 
@@ -140,6 +149,10 @@ static struct platform_device i2c_gpio_device = {
        },
 };
 
+static struct i2c_board_info __initdata i2c_info[] = {
+       /* NOTE:  original ATtiny24 firmware is at address 0x0b */
+};
+
 static int __init atngw100_init(void)
 {
        unsigned        i;
@@ -165,12 +178,28 @@ static int __init atngw100_init(void)
        }
        platform_device_register(&ngw_gpio_leds);
 
+       /* all these i2c/smbus pins should have external pullups for
+        * open-drain sharing among all I2C devices.  SDA and SCL do;
+        * PB28/EXTINT3 doesn't; it should be SMBALERT# (for PMBus),
+        * but it's not available off-board.
+        */
+       at32_select_periph(GPIO_PIN_PB(28), 0, AT32_GPIOF_PULLUP);
        at32_select_gpio(i2c_gpio_data.sda_pin,
                AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
        at32_select_gpio(i2c_gpio_data.scl_pin,
                AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
        platform_device_register(&i2c_gpio_device);
+       i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
 
        return 0;
 }
 postcore_initcall(atngw100_init);
+
+static int __init atngw100_arch_init(void)
+{
+       /* set_irq_type() after the arch_initcall for EIC has run, and
+        * before the I2C subsystem could try using this IRQ.
+        */
+       return set_irq_type(AT32_EXTINT(3), IRQ_TYPE_EDGE_FALLING);
+}
+arch_initcall(atngw100_arch_init);
index 000eb42..86b363c 100644 (file)
 
 #include "atstk1000.h"
 
+/* Oscillator frequencies. These are board specific */
+unsigned long at32_board_osc_rates[3] = {
+       [0] = 32768,    /* 32.768 kHz on RTC osc */
+       [1] = 20000000, /* 20 MHz on osc0 */
+       [2] = 12000000, /* 12 MHz on osc1 */
+};
 
 struct eth_addr {
        u8 addr[6];
@@ -232,7 +238,7 @@ static int __init atstk1002_init(void)
        set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
 #else
        at32_add_device_lcdc(0, &atstk1000_lcdc_data,
-                            fbmem_start, fbmem_size);
+                            fbmem_start, fbmem_size, 0);
 #endif
        at32_add_device_usba(0, NULL);
 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
index a0b223d..ea109f4 100644 (file)
 
 #include "atstk1000.h"
 
+/* Oscillator frequencies. These are board specific */
+unsigned long at32_board_osc_rates[3] = {
+       [0] = 32768,    /* 32.768 kHz on RTC osc */
+       [1] = 20000000, /* 20 MHz on osc0 */
+       [2] = 12000000, /* 12 MHz on osc1 */
+};
+
 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
 static struct at73c213_board_info at73c213_data = {
        .ssc_id         = 0,
index e765a86..c7236df 100644 (file)
 
 #include "atstk1000.h"
 
+/* Oscillator frequencies. These are board specific */
+unsigned long at32_board_osc_rates[3] = {
+       [0] = 32768,    /* 32.768 kHz on RTC osc */
+       [1] = 20000000, /* 20 MHz on osc0 */
+       [2] = 12000000, /* 12 MHz on osc1 */
+};
+
 #ifdef CONFIG_BOARD_ATSTK1000_EXTDAC
 static struct at73c213_board_info at73c213_data = {
        .ssc_id         = 0,
@@ -133,7 +140,7 @@ static int __init atstk1004_init(void)
        at32_add_device_mci(0);
 #endif
        at32_add_device_lcdc(0, &atstk1000_lcdc_data,
-                            fbmem_start, fbmem_size);
+                            fbmem_start, fbmem_size, 0);
        at32_add_device_usba(0, NULL);
 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
        at32_add_device_ssc(0, ATMEL_SSC_TX);
index 5f31702..2b398ca 100644 (file)
@@ -74,50 +74,41 @@ exception_vectors:
        .align  2
        bral    do_dtlb_modified
 
-       /*
-        * r0 : PGD/PT/PTE
-        * r1 : Offending address
-        * r2 : Scratch register
-        * r3 : Cause (5, 12 or 13)
-        */
 #define        tlbmiss_save    pushm   r0-r3
 #define tlbmiss_restore        popm    r0-r3
 
-       .section .tlbx.ex.text,"ax",@progbits
+       .org    0x50
        .global itlb_miss
 itlb_miss:
        tlbmiss_save
        rjmp    tlb_miss_common
 
-       .section .tlbr.ex.text,"ax",@progbits
+       .org    0x60
 dtlb_miss_read:
        tlbmiss_save
        rjmp    tlb_miss_common
 
-       .section .tlbw.ex.text,"ax",@progbits
+       .org    0x70
 dtlb_miss_write:
        tlbmiss_save
 
        .global tlb_miss_common
+       .align  2
 tlb_miss_common:
        mfsr    r0, SYSREG_TLBEAR
        mfsr    r1, SYSREG_PTBR
 
-       /* Is it the vmalloc space? */
-       bld     r0, 31
-       brcs    handle_vmalloc_miss
-
-       /* First level lookup */
+       /*
+        * First level lookup: The PGD contains virtual pointers to
+        * the second-level page tables, but they may be NULL if not
+        * present.
+        */
 pgtbl_lookup:
        lsr     r2, r0, PGDIR_SHIFT
        ld.w    r3, r1[r2 << 2]
        bfextu  r1, r0, PAGE_SHIFT, PGDIR_SHIFT - PAGE_SHIFT
-       bld     r3, _PAGE_BIT_PRESENT
-       brcc    page_table_not_present
-
-       /* Translate to virtual address in P1. */
-       andl    r3, 0xf000
-       sbr     r3, 31
+       cp.w    r3, 0
+       breq    page_table_not_present
 
        /* Second level lookup */
        ld.w    r2, r3[r1 << 2]
@@ -148,16 +139,55 @@ pgtbl_lookup:
        tlbmiss_restore
        rete
 
-handle_vmalloc_miss:
-       /* Simply do the lookup in init's page table */
+       /* The slow path of the TLB miss handler */
+       .align  2
+page_table_not_present:
+       /* Do we need to synchronize with swapper_pg_dir? */
+       bld     r0, 31
+       brcs    sync_with_swapper_pg_dir
+
+page_not_present:
+       tlbmiss_restore
+       sub     sp, 4
+       stmts   --sp, r0-lr
+       rcall   save_full_context_ex
+       mfsr    r12, SYSREG_ECR
+       mov     r11, sp
+       rcall   do_page_fault
+       rjmp    ret_from_exception
+
+       .align  2
+sync_with_swapper_pg_dir:
+       /*
+        * If swapper_pg_dir contains a non-NULL second-level page
+        * table pointer, copy it into the current PGD. If not, we
+        * must handle it as a full-blown page fault.
+        *
+        * Jumping back to pgtbl_lookup causes an unnecessary lookup,
+        * but it is guaranteed to be a cache hit, it won't happen
+        * very often, and we absolutely do not want to sacrifice any
+        * performance in the fast path in order to improve this.
+        */
        mov     r1, lo(swapper_pg_dir)
        orh     r1, hi(swapper_pg_dir)
+       ld.w    r3, r1[r2 << 2]
+       cp.w    r3, 0
+       breq    page_not_present
+       mfsr    r1, SYSREG_PTBR
+       st.w    r1[r2 << 2], r3
        rjmp    pgtbl_lookup
 
+       /*
+        * We currently have two bytes left at this point until we
+        * crash into the system call handler...
+        *
+        * Don't worry, the assembler will let us know.
+        */
+
 
        /* ---                    System Call                    --- */
 
-       .section .scall.text,"ax",@progbits
+       .org    0x100
 system_call:
 #ifdef CONFIG_PREEMPT
        mask_interrupts
@@ -266,18 +296,6 @@ syscall_exit_work:
        brcc    syscall_exit_cont
        rjmp    enter_monitor_mode
 
-       /* The slow path of the TLB miss handler */
-page_table_not_present:
-page_not_present:
-       tlbmiss_restore
-       sub     sp, 4
-       stmts   --sp, r0-lr
-       rcall   save_full_context_ex
-       mfsr    r12, SYSREG_ECR
-       mov     r11, sp
-       rcall   do_page_fault
-       rjmp    ret_from_exception
-
        /* This function expects to find offending PC in SYSREG_RAR_EX */
        .type   save_full_context_ex, @function
        .align  2
index 5616a00..c5b11f9 100644 (file)
@@ -93,6 +93,9 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
        if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
                goto badframe;
 
+       if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
+               goto badframe;
+
        pr_debug("Context restored: pc = %08lx, lr = %08lx, sp = %08lx\n",
                 regs->pc, regs->lr, regs->sp);
 
index 00a9862..abd954f 100644 (file)
@@ -7,21 +7,13 @@
  */
 #include <linux/clk.h>
 #include <linux/clockchips.h>
-#include <linux/time.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
-#include <linux/kernel_stat.h>
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/profile.h>
-#include <linux/sysdev.h>
-#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/time.h>
 
-#include <asm/div64.h>
 #include <asm/sysreg.h>
-#include <asm/io.h>
-#include <asm/sections.h>
 
 #include <asm/arch/pm.h>
 
index 481cfd4..7910d41 100644 (file)
@@ -68,14 +68,6 @@ SECTIONS
                _evba = .;
                _text = .;
                *(.ex.text)
-               . = 0x50;
-               *(.tlbx.ex.text)
-               . = 0x60;
-               *(.tlbr.ex.text)
-               . = 0x70;
-               *(.tlbw.ex.text)
-               . = 0x100;
-               *(.scall.text)
                *(.irq.text)
                KPROBES_TEXT
                TEXT_TEXT
@@ -93,8 +85,6 @@ SECTIONS
                __stop___ex_table = .;
        }
 
-       BUG_TABLE
-
        RODATA
 
        . = ALIGN(THREAD_SIZE);
@@ -107,6 +97,10 @@ SECTIONS
                 */
                *(.data.init_task)
 
+               /* Then, the page-aligned data */
+               . = ALIGN(PAGE_SIZE);
+               *(.data.page_aligned)
+
                /* Then, the cacheline aligned data */
                . = ALIGN(L1_CACHE_BYTES);
                *(.data.cacheline_aligned)
index 2be5da7..cb2d869 100644 (file)
@@ -41,7 +41,7 @@ __raw_readsb:
 2:     sub     r10, -4
        reteq   r12
 
-3:     ld.uh   r8, r12[0]
+3:     ld.ub   r8, r12[0]
        sub     r10, 1
        st.b    r11++, r8
        brne    3b
index e890094..d5018e2 100644 (file)
@@ -1,3 +1,8 @@
-obj-y                          += at32ap.o clock.o intc.o extint.o pio.o hsmc.o
+obj-y                          += pdc.o clock.o intc.o extint.o pio.o hsmc.o
 obj-$(CONFIG_CPU_AT32AP700X)   += at32ap700x.o pm-at32ap700x.o
 obj-$(CONFIG_CPU_FREQ_AT32AP)  += cpufreq.o
+obj-$(CONFIG_PM)               += pm.o
+
+ifeq ($(CONFIG_PM_DEBUG),y)
+CFLAGS_pm.o    += -DDEBUG
+endif
diff --git a/arch/avr32/mach-at32ap/at32ap.c b/arch/avr32/mach-at32ap/at32ap.c
deleted file mode 100644 (file)
index 7c4987f..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2006 Atmel Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-
-#include <asm/arch/init.h>
-
-void __init setup_platform(void)
-{
-       at32_clock_init();
-       at32_portmux_init();
-}
-
-static int __init pdc_probe(struct platform_device *pdev)
-{
-       struct clk *pclk, *hclk;
-
-       pclk = clk_get(&pdev->dev, "pclk");
-       if (IS_ERR(pclk)) {
-               dev_err(&pdev->dev, "no pclk defined\n");
-               return PTR_ERR(pclk);
-       }
-       hclk = clk_get(&pdev->dev, "hclk");
-       if (IS_ERR(hclk)) {
-               dev_err(&pdev->dev, "no hclk defined\n");
-               clk_put(pclk);
-               return PTR_ERR(hclk);
-       }
-
-       clk_enable(pclk);
-       clk_enable(hclk);
-
-       dev_info(&pdev->dev, "Atmel Peripheral DMA Controller enabled\n");
-       return 0;
-}
-
-static struct platform_driver pdc_driver = {
-       .probe          = pdc_probe,
-       .driver         = {
-               .name   = "pdc",
-       },
-};
-
-static int __init pdc_init(void)
-{
-       return platform_driver_register(&pdc_driver);
-}
-arch_initcall(pdc_init);
index 0f24b4f..07b21b1 100644 (file)
@@ -20,6 +20,7 @@
 #include <asm/arch/at32ap700x.h>
 #include <asm/arch/board.h>
 #include <asm/arch/portmux.h>
+#include <asm/arch/sram.h>
 
 #include <video/atmel_lcdc.h>
 
@@ -93,19 +94,12 @@ static struct clk devname##_##_name = {                             \
 
 static DEFINE_SPINLOCK(pm_lock);
 
-unsigned long at32ap7000_osc_rates[3] = {
-       [0] = 32768,
-       /* FIXME: these are ATSTK1002-specific */
-       [1] = 20000000,
-       [2] = 12000000,
-};
-
 static struct clk osc0;
 static struct clk osc1;
 
 static unsigned long osc_get_rate(struct clk *clk)
 {
-       return at32ap7000_osc_rates[clk->index];
+       return at32_board_osc_rates[clk->index];
 }
 
 static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
@@ -682,6 +676,14 @@ static struct clk hramc_clk = {
        .users          = 1,
        .index          = 3,
 };
+static struct clk sdramc_clk = {
+       .name           = "sdramc_clk",
+       .parent         = &pbb_clk,
+       .mode           = pbb_clk_mode,
+       .get_rate       = pbb_clk_get_rate,
+       .users          = 1,
+       .index          = 14,
+};
 
 static struct resource smc0_resource[] = {
        PBMEM(0xfff03400),
@@ -840,6 +842,81 @@ void __init at32_add_system_devices(void)
        platform_device_register(&pio4_device);
 }
 
+/* --------------------------------------------------------------------
+ *  PSIF
+ * -------------------------------------------------------------------- */
+static struct resource atmel_psif0_resource[] __initdata = {
+       {
+               .start  = 0xffe03c00,
+               .end    = 0xffe03cff,
+               .flags  = IORESOURCE_MEM,
+       },
+       IRQ(18),
+};
+static struct clk atmel_psif0_pclk = {
+       .name           = "pclk",
+       .parent         = &pba_clk,
+       .mode           = pba_clk_mode,
+       .get_rate       = pba_clk_get_rate,
+       .index          = 15,
+};
+
+static struct resource atmel_psif1_resource[] __initdata = {
+       {
+               .start  = 0xffe03d00,
+               .end    = 0xffe03dff,
+               .flags  = IORESOURCE_MEM,
+       },
+       IRQ(18),
+};
+static struct clk atmel_psif1_pclk = {
+       .name           = "pclk",
+       .parent         = &pba_clk,
+       .mode           = pba_clk_mode,
+       .get_rate       = pba_clk_get_rate,
+       .index          = 15,
+};
+
+struct platform_device *__init at32_add_device_psif(unsigned int id)
+{
+       struct platform_device *pdev;
+
+       if (!(id == 0 || id == 1))
+               return NULL;
+
+       pdev = platform_device_alloc("atmel_psif", id);
+       if (!pdev)
+               return NULL;
+
+       switch (id) {
+       case 0:
+               if (platform_device_add_resources(pdev, atmel_psif0_resource,
+                                       ARRAY_SIZE(atmel_psif0_resource)))
+                       goto err_add_resources;
+               atmel_psif0_pclk.dev = &pdev->dev;
+               select_peripheral(PA(8), PERIPH_A, 0); /* CLOCK */
+               select_peripheral(PA(9), PERIPH_A, 0); /* DATA  */
+               break;
+       case 1:
+               if (platform_device_add_resources(pdev, atmel_psif1_resource,
+                                       ARRAY_SIZE(atmel_psif1_resource)))
+                       goto err_add_resources;
+               atmel_psif1_pclk.dev = &pdev->dev;
+               select_peripheral(PB(11), PERIPH_A, 0); /* CLOCK */
+               select_peripheral(PB(12), PERIPH_A, 0); /* DATA  */
+               break;
+       default:
+               return NULL;
+       }
+
+       platform_device_add(pdev);
+       return pdev;
+
+err_add_resources:
+       platform_device_put(pdev);
+       return NULL;
+}
+
 /* --------------------------------------------------------------------
  *  USART
  * -------------------------------------------------------------------- */
@@ -1113,7 +1190,8 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
        switch (id) {
        case 0:
                pdev = &atmel_spi0_device;
-               select_peripheral(PA(0),  PERIPH_A, 0); /* MISO  */
+               /* pullup MISO so a level is always defined */
+               select_peripheral(PA(0),  PERIPH_A, AT32_GPIOF_PULLUP);
                select_peripheral(PA(1),  PERIPH_A, 0); /* MOSI  */
                select_peripheral(PA(2),  PERIPH_A, 0); /* SCK   */
                at32_spi_setup_slaves(0, b, n, spi0_pins);
@@ -1121,7 +1199,8 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
 
        case 1:
                pdev = &atmel_spi1_device;
-               select_peripheral(PB(0),  PERIPH_B, 0); /* MISO  */
+               /* pullup MISO so a level is always defined */
+               select_peripheral(PB(0),  PERIPH_B, AT32_GPIOF_PULLUP);
                select_peripheral(PB(1),  PERIPH_B, 0); /* MOSI  */
                select_peripheral(PB(5),  PERIPH_B, 0); /* SCK   */
                at32_spi_setup_slaves(1, b, n, spi1_pins);
@@ -1264,7 +1343,8 @@ static struct clk atmel_lcdfb0_pixclk = {
 
 struct platform_device *__init
 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
-                    unsigned long fbmem_start, unsigned long fbmem_len)
+                    unsigned long fbmem_start, unsigned long fbmem_len,
+                    unsigned int pin_config)
 {
        struct platform_device *pdev;
        struct atmel_lcdfb_info *info;
@@ -1291,37 +1371,77 @@ at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
        switch (id) {
        case 0:
                pdev = &atmel_lcdfb0_device;
-               select_peripheral(PC(19), PERIPH_A, 0); /* CC     */
-               select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC  */
-               select_peripheral(PC(21), PERIPH_A, 0); /* PCLK   */
-               select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC  */
-               select_peripheral(PC(23), PERIPH_A, 0); /* DVAL   */
-               select_peripheral(PC(24), PERIPH_A, 0); /* MODE   */
-               select_peripheral(PC(25), PERIPH_A, 0); /* PWR    */
-               select_peripheral(PC(26), PERIPH_A, 0); /* DATA0  */
-               select_peripheral(PC(27), PERIPH_A, 0); /* DATA1  */
-               select_peripheral(PC(28), PERIPH_A, 0); /* DATA2  */
-               select_peripheral(PC(29), PERIPH_A, 0); /* DATA3  */
-               select_peripheral(PC(30), PERIPH_A, 0); /* DATA4  */
-               select_peripheral(PC(31), PERIPH_A, 0); /* DATA5  */
-               select_peripheral(PD(0),  PERIPH_A, 0); /* DATA6  */
-               select_peripheral(PD(1),  PERIPH_A, 0); /* DATA7  */
-               select_peripheral(PD(2),  PERIPH_A, 0); /* DATA8  */
-               select_peripheral(PD(3),  PERIPH_A, 0); /* DATA9  */
-               select_peripheral(PD(4),  PERIPH_A, 0); /* DATA10 */
-               select_peripheral(PD(5),  PERIPH_A, 0); /* DATA11 */
-               select_peripheral(PD(6),  PERIPH_A, 0); /* DATA12 */
-               select_peripheral(PD(7),  PERIPH_A, 0); /* DATA13 */
-               select_peripheral(PD(8),  PERIPH_A, 0); /* DATA14 */
-               select_peripheral(PD(9),  PERIPH_A, 0); /* DATA15 */
-               select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
-               select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
-               select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
-               select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
-               select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
-               select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
-               select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
-               select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
+
+               switch (pin_config) {
+               case 0:
+                       select_peripheral(PC(19), PERIPH_A, 0); /* CC     */
+                       select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC  */
+                       select_peripheral(PC(21), PERIPH_A, 0); /* PCLK   */
+                       select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC  */
+                       select_peripheral(PC(23), PERIPH_A, 0); /* DVAL   */
+                       select_peripheral(PC(24), PERIPH_A, 0); /* MODE   */
+                       select_peripheral(PC(25), PERIPH_A, 0); /* PWR    */
+                       select_peripheral(PC(26), PERIPH_A, 0); /* DATA0  */
+                       select_peripheral(PC(27), PERIPH_A, 0); /* DATA1  */
+                       select_peripheral(PC(28), PERIPH_A, 0); /* DATA2  */
+                       select_peripheral(PC(29), PERIPH_A, 0); /* DATA3  */
+                       select_peripheral(PC(30), PERIPH_A, 0); /* DATA4  */
+                       select_peripheral(PC(31), PERIPH_A, 0); /* DATA5  */
+                       select_peripheral(PD(0),  PERIPH_A, 0); /* DATA6  */
+                       select_peripheral(PD(1),  PERIPH_A, 0); /* DATA7  */
+                       select_peripheral(PD(2),  PERIPH_A, 0); /* DATA8  */
+                       select_peripheral(PD(3),  PERIPH_A, 0); /* DATA9  */
+                       select_peripheral(PD(4),  PERIPH_A, 0); /* DATA10 */
+                       select_peripheral(PD(5),  PERIPH_A, 0); /* DATA11 */
+                       select_peripheral(PD(6),  PERIPH_A, 0); /* DATA12 */
+                       select_peripheral(PD(7),  PERIPH_A, 0); /* DATA13 */
+                       select_peripheral(PD(8),  PERIPH_A, 0); /* DATA14 */
+                       select_peripheral(PD(9),  PERIPH_A, 0); /* DATA15 */
+                       select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
+                       select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
+                       select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
+                       select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
+                       select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
+                       select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
+                       select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
+                       select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
+                       break;
+               case 1:
+                       select_peripheral(PE(0),  PERIPH_B, 0); /* CC     */
+                       select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC  */
+                       select_peripheral(PC(21), PERIPH_A, 0); /* PCLK   */
+                       select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC  */
+                       select_peripheral(PE(1),  PERIPH_B, 0); /* DVAL   */
+                       select_peripheral(PE(2),  PERIPH_B, 0); /* MODE   */
+                       select_peripheral(PC(25), PERIPH_A, 0); /* PWR    */
+                       select_peripheral(PE(3),  PERIPH_B, 0); /* DATA0  */
+                       select_peripheral(PE(4),  PERIPH_B, 0); /* DATA1  */
+                       select_peripheral(PE(5),  PERIPH_B, 0); /* DATA2  */
+                       select_peripheral(PE(6),  PERIPH_B, 0); /* DATA3  */
+                       select_peripheral(PE(7),  PERIPH_B, 0); /* DATA4  */
+                       select_peripheral(PC(31), PERIPH_A, 0); /* DATA5  */
+                       select_peripheral(PD(0),  PERIPH_A, 0); /* DATA6  */
+                       select_peripheral(PD(1),  PERIPH_A, 0); /* DATA7  */
+                       select_peripheral(PE(8),  PERIPH_B, 0); /* DATA8  */
+                       select_peripheral(PE(9),  PERIPH_B, 0); /* DATA9  */
+                       select_peripheral(PE(10), PERIPH_B, 0); /* DATA10 */
+                       select_peripheral(PE(11), PERIPH_B, 0); /* DATA11 */
+                       select_peripheral(PE(12), PERIPH_B, 0); /* DATA12 */
+                       select_peripheral(PD(7),  PERIPH_A, 0); /* DATA13 */
+                       select_peripheral(PD(8),  PERIPH_A, 0); /* DATA14 */
+                       select_peripheral(PD(9),  PERIPH_A, 0); /* DATA15 */
+                       select_peripheral(PE(13), PERIPH_B, 0); /* DATA16 */
+                       select_peripheral(PE(14), PERIPH_B, 0); /* DATA17 */
+                       select_peripheral(PE(15), PERIPH_B, 0); /* DATA18 */
+                       select_peripheral(PE(16), PERIPH_B, 0); /* DATA19 */
+                       select_peripheral(PE(17), PERIPH_B, 0); /* DATA20 */
+                       select_peripheral(PE(18), PERIPH_B, 0); /* DATA21 */
+                       select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
+                       select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
+                       break;
+               default:
+                       goto err_invalid_id;
+               }
 
                clk_set_parent(&atmel_lcdfb0_pixclk, &pll0);
                clk_set_rate(&atmel_lcdfb0_pixclk, clk_get_rate(&pll0));
@@ -1360,7 +1480,7 @@ static struct resource atmel_pwm0_resource[] __initdata = {
        IRQ(24),
 };
 static struct clk atmel_pwm0_mck = {
-       .name           = "mck",
+       .name           = "pwm_clk",
        .parent         = &pbb_clk,
        .mode           = pbb_clk_mode,
        .get_rate       = pbb_clk_get_rate,
@@ -1887,6 +2007,7 @@ struct clk *at32_clock_list[] = {
        &hmatrix_clk,
        &ebi_clk,
        &hramc_clk,
+       &sdramc_clk,
        &smc0_pclk,
        &smc0_mck,
        &pdc_hclk,
@@ -1900,6 +2021,8 @@ struct clk *at32_clock_list[] = {
        &pio4_mck,
        &at32_tcb0_t0_clk,
        &at32_tcb1_t0_clk,
+       &atmel_psif0_pclk,
+       &atmel_psif1_pclk,
        &atmel_usart0_usart,
        &atmel_usart1_usart,
        &atmel_usart2_usart,
@@ -1935,16 +2058,7 @@ struct clk *at32_clock_list[] = {
 };
 unsigned int at32_nr_clocks = ARRAY_SIZE(at32_clock_list);
 
-void __init at32_portmux_init(void)
-{
-       at32_init_pio(&pio0_device);
-       at32_init_pio(&pio1_device);
-       at32_init_pio(&pio2_device);
-       at32_init_pio(&pio3_device);
-       at32_init_pio(&pio4_device);
-}
-
-void __init at32_clock_init(void)
+void __init setup_platform(void)
 {
        u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
        int i;
@@ -1999,4 +2113,36 @@ void __init at32_clock_init(void)
        pm_writel(HSB_MASK, hsb_mask);
        pm_writel(PBA_MASK, pba_mask);
        pm_writel(PBB_MASK, pbb_mask);
+
+       /* Initialize the port muxes */
+       at32_init_pio(&pio0_device);
+       at32_init_pio(&pio1_device);
+       at32_init_pio(&pio2_device);
+       at32_init_pio(&pio3_device);
+       at32_init_pio(&pio4_device);
+}
+
+struct gen_pool *sram_pool;
+
+static int __init sram_init(void)
+{
+       struct gen_pool *pool;
+
+       /* 1KiB granularity */
+       pool = gen_pool_create(10, -1);
+       if (!pool)
+               goto fail;
+
+       if (gen_pool_add(pool, 0x24000000, 0x8000, -1))
+               goto err_pool_add;
+
+       sram_pool = pool;
+       return 0;
+
+err_pool_add:
+       gen_pool_destroy(pool);
+fail:
+       pr_err("Failed to create SRAM pool\n");
+       return -ENOMEM;
 }
+core_initcall(sram_init);
index 097cf4e..994c454 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Atmel Corporation
+ * Copyright (C) 2006, 2008 Atmel Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/platform_device.h>
+#include <linux/sysdev.h>
 
 #include <asm/io.h>
 
 #include "intc.h"
 
 struct intc {
-       void __iomem    *regs;
-       struct irq_chip chip;
+       void __iomem            *regs;
+       struct irq_chip         chip;
+       struct sys_device       sysdev;
+#ifdef CONFIG_PM
+       unsigned long           suspend_ipr;
+       unsigned long           saved_ipr[64];
+#endif
 };
 
 extern struct platform_device at32_intc0_device;
@@ -136,6 +142,74 @@ fail:
        panic("Interrupt controller initialization failed!\n");
 }
 
+#ifdef CONFIG_PM
+void intc_set_suspend_handler(unsigned long offset)
+{
+       intc0.suspend_ipr = offset;
+}
+
+static int intc_suspend(struct sys_device *sdev, pm_message_t state)
+{
+       struct intc *intc = container_of(sdev, struct intc, sysdev);
+       int i;
+
+       if (unlikely(!irqs_disabled())) {
+               pr_err("intc_suspend: called with interrupts enabled\n");
+               return -EINVAL;
+       }
+
+       if (unlikely(!intc->suspend_ipr)) {
+               pr_err("intc_suspend: suspend_ipr not initialized\n");
+               return -EINVAL;
+       }
+
+       for (i = 0; i < 64; i++) {
+               intc->saved_ipr[i] = intc_readl(intc, INTPR0 + 4 * i);
+               intc_writel(intc, INTPR0 + 4 * i, intc->suspend_ipr);
+       }
+
+       return 0;
+}
+
+static int intc_resume(struct sys_device *sdev)
+{
+       struct intc *intc = container_of(sdev, struct intc, sysdev);
+       int i;
+
+       WARN_ON(!irqs_disabled());
+
+       for (i = 0; i < 64; i++)
+               intc_writel(intc, INTPR0 + 4 * i, intc->saved_ipr[i]);
+
+       return 0;
+}
+#else
+#define intc_suspend   NULL
+#define intc_resume    NULL
+#endif
+
+static struct sysdev_class intc_class = {
+       .name           = "intc",
+       .suspend        = intc_suspend,
+       .resume         = intc_resume,
+};
+
+static int __init intc_init_sysdev(void)
+{
+       int ret;
+
+       ret = sysdev_class_register(&intc_class);
+       if (ret)
+               return ret;
+
+       intc0.sysdev.id = 0;
+       intc0.sysdev.cls = &intc_class;
+       ret = sysdev_register(&intc0.sysdev);
+
+       return ret;
+}
+device_initcall(intc_init_sysdev);
+
 unsigned long intc_get_pending(unsigned int group)
 {
        return intc_readl(&intc0, INTREQ0 + 4 * group);
diff --git a/arch/avr32/mach-at32ap/pdc.c b/arch/avr32/mach-at32ap/pdc.c
new file mode 100644 (file)
index 0000000..1040bda
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2006 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+
+static int __init pdc_probe(struct platform_device *pdev)
+{
+       struct clk *pclk, *hclk;
+
+       pclk = clk_get(&pdev->dev, "pclk");
+       if (IS_ERR(pclk)) {
+               dev_err(&pdev->dev, "no pclk defined\n");
+               return PTR_ERR(pclk);
+       }
+       hclk = clk_get(&pdev->dev, "hclk");
+       if (IS_ERR(hclk)) {
+               dev_err(&pdev->dev, "no hclk defined\n");
+               clk_put(pclk);
+               return PTR_ERR(hclk);
+       }
+
+       clk_enable(pclk);
+       clk_enable(hclk);
+
+       dev_info(&pdev->dev, "Atmel Peripheral DMA Controller enabled\n");
+       return 0;
+}
+
+static struct platform_driver pdc_driver = {
+       .probe          = pdc_probe,
+       .driver         = {
+               .name   = "pdc",
+       },
+};
+
+static int __init pdc_init(void)
+{
+       return platform_driver_register(&pdc_driver);
+}
+arch_initcall(pdc_init);
index 38a8fa3..60da03b 100644 (file)
@@ -318,6 +318,8 @@ static void pio_bank_show(struct seq_file *s, struct gpio_chip *chip)
                const char *label;
 
                label = gpiochip_is_requested(chip, i);
+               if (!label && (imr & mask))
+                       label = "[irq]";
                if (!label)
                        continue;
 
index 7795116..9484dfc 100644 (file)
@@ -57,7 +57,7 @@
 
 /* Bitfields in IFDR */
 
-/* Bitfields in ISFR */
+/* Bitfields in IFSR */
 
 /* Bitfields in SODR */
 
index 949e248..0a53ad3 100644 (file)
 #include <asm/thread_info.h>
 #include <asm/arch/pm.h>
 
+#include "pm.h"
+#include "sdramc.h"
+
+/* Same as 0xfff00000 but fits in a 21 bit signed immediate */
+#define PM_BASE        -0x100000
+
        .section .bss, "wa", @nobits
        .global disable_idle_sleep
        .type   disable_idle_sleep, @object
@@ -64,3 +70,105 @@ cpu_idle_skip_sleep:
        unmask_interrupts
        retal   r12
        .size   cpu_idle_skip_sleep, . - cpu_idle_skip_sleep
+
+#ifdef CONFIG_PM
+       .section .init.text, "ax", @progbits
+
+       .global pm_exception
+       .type   pm_exception, @function
+pm_exception:
+       /*
+        * Exceptions are masked when we switch to this handler, so
+        * we'll only get "unrecoverable" exceptions (offset 0.)
+        */
+       sub     r12, pc, . - .Lpanic_msg
+       lddpc   pc, .Lpanic_addr
+
+       .align  2
+.Lpanic_addr:
+       .long   panic
+.Lpanic_msg:
+       .asciz  "Unrecoverable exception during suspend\n"
+       .size   pm_exception, . - pm_exception
+
+       .global pm_irq0
+       .type   pm_irq0, @function
+pm_irq0:
+       /* Disable interrupts and return after the sleep instruction */
+       mfsr    r9, SYSREG_RSR_INT0
+       mtsr    SYSREG_RAR_INT0, r8
+       sbr     r9, SYSREG_GM_OFFSET
+       mtsr    SYSREG_RSR_INT0, r9
+       rete
+
+       /*
+        * void cpu_enter_standby(unsigned long sdramc_base)
+        *
+        * Enter PM_SUSPEND_STANDBY mode. At this point, all drivers
+        * are suspended and interrupts are disabled. Interrupts
+        * marked as 'wakeup' event sources may still come along and
+        * get us out of here.
+        *
+        * The SDRAM will be put into self-refresh mode (which does
+        * not require a clock from the CPU), and the CPU will be put
+        * into "frozen" mode (HSB bus stopped). The SDRAM controller
+        * will automatically bring the SDRAM into normal mode on the
+        * first access, and the power manager will automatically
+        * start the HSB and CPU clocks upon a wakeup event.
+        *
+        * This code uses the same "skip sleep" technique as above.
+        * It is very important that we jump directly to
+        * cpu_after_sleep after the sleep instruction since that's
+        * where we'll end up if the interrupt handler decides that we
+        * need to skip the sleep instruction.
+        */
+       .global pm_standby
+       .type   pm_standby, @function
+pm_standby:
+       /*
+        * interrupts are already masked at this point, and EVBA
+        * points to pm_exception above.
+        */
+       ld.w    r10, r12[SDRAMC_LPR]
+       sub     r8, pc, . - 1f          /* return address for irq handler */
+       mov     r11, SDRAMC_LPR_LPCB_SELF_RFR
+       bfins   r10, r11, 0, 2          /* LPCB <- self Refresh */
+       sync    0                       /* flush write buffer */
+       st.w    r12[SDRAMC_LPR], r11    /* put SDRAM in self-refresh mode */
+       ld.w    r11, r12[SDRAMC_LPR]
+       unmask_interrupts
+       sleep   CPU_SLEEP_FROZEN
+1:     mask_interrupts
+       retal   r12
+       .size   pm_standby, . - pm_standby
+
+       .global pm_suspend_to_ram
+       .type   pm_suspend_to_ram, @function
+pm_suspend_to_ram:
+       /*
+        * interrupts are already masked at this point, and EVBA
+        * points to pm_exception above.
+        */
+       mov     r11, 0
+       cache   r11[2], 8               /* clean all dcache lines */
+       sync    0                       /* flush write buffer */
+       ld.w    r10, r12[SDRAMC_LPR]
+       sub     r8, pc, . - 1f          /* return address for irq handler */
+       mov     r11, SDRAMC_LPR_LPCB_SELF_RFR
+       bfins   r10, r11, 0, 2          /* LPCB <- self refresh */
+       st.w    r12[SDRAMC_LPR], r10    /* put SDRAM in self-refresh mode */
+       ld.w    r11, r12[SDRAMC_LPR]
+
+       unmask_interrupts
+       sleep   CPU_SLEEP_STOP
+1:     mask_interrupts
+
+       retal   r12
+       .size   pm_suspend_to_ram, . - pm_suspend_to_ram
+
+       .global pm_sram_end
+       .type   pm_sram_end, @function
+pm_sram_end:
+       .size   pm_sram_end, 0
+
+#endif /* CONFIG_PM */
diff --git a/arch/avr32/mach-at32ap/pm.c b/arch/avr32/mach-at32ap/pm.c
new file mode 100644 (file)
index 0000000..0b76432
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * AVR32 AP Power Management
+ *
+ * Copyright (C) 2008 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+#include <linux/io.h>
+#include <linux/suspend.h>
+#include <linux/vmalloc.h>
+
+#include <asm/cacheflush.h>
+#include <asm/sysreg.h>
+
+#include <asm/arch/pm.h>
+#include <asm/arch/sram.h>
+
+/* FIXME: This is only valid for AP7000 */
+#define SDRAMC_BASE    0xfff03800
+
+#include "sdramc.h"
+
+#define SRAM_PAGE_FLAGS        (SYSREG_BIT(TLBELO_D) | SYSREG_BF(SZ, 1)        \
+                               | SYSREG_BF(AP, 3) | SYSREG_BIT(G))
+
+
+static unsigned long   pm_sram_start;
+static size_t          pm_sram_size;
+static struct vm_struct        *pm_sram_area;
+
+static void (*avr32_pm_enter_standby)(unsigned long sdramc_base);
+static void (*avr32_pm_enter_str)(unsigned long sdramc_base);
+
+/*
+ * Must be called with interrupts disabled. Exceptions will be masked
+ * on return (i.e. all exceptions will be "unrecoverable".)
+ */
+static void *avr32_pm_map_sram(void)
+{
+       unsigned long   vaddr;
+       unsigned long   page_addr;
+       u32             tlbehi;
+       u32             mmucr;
+
+       vaddr = (unsigned long)pm_sram_area->addr;
+       page_addr = pm_sram_start & PAGE_MASK;
+
+       /*
+        * Mask exceptions and grab the first TLB entry. We won't be
+        * needing it while sleeping.
+        */
+       asm volatile("ssrf      %0" : : "i"(SYSREG_EM_OFFSET) : "memory");
+
+       mmucr = sysreg_read(MMUCR);
+       tlbehi = sysreg_read(TLBEHI);
+       sysreg_write(MMUCR, SYSREG_BFINS(DRP, 0, mmucr));
+
+       tlbehi = SYSREG_BF(ASID, SYSREG_BFEXT(ASID, tlbehi));
+       tlbehi |= vaddr & PAGE_MASK;
+       tlbehi |= SYSREG_BIT(TLBEHI_V);
+
+       sysreg_write(TLBELO, page_addr | SRAM_PAGE_FLAGS);
+       sysreg_write(TLBEHI, tlbehi);
+       __builtin_tlbw();
+
+       return (void *)(vaddr + pm_sram_start - page_addr);
+}
+
+/*
+ * Must be called with interrupts disabled. Exceptions will be
+ * unmasked on return.
+ */
+static void avr32_pm_unmap_sram(void)
+{
+       u32     mmucr;
+       u32     tlbehi;
+       u32     tlbarlo;
+
+       /* Going to update TLB entry at index 0 */
+       mmucr = sysreg_read(MMUCR);
+       tlbehi = sysreg_read(TLBEHI);
+       sysreg_write(MMUCR, SYSREG_BFINS(DRP, 0, mmucr));
+
+       /* Clear the "valid" bit */
+       tlbehi = SYSREG_BF(ASID, SYSREG_BFEXT(ASID, tlbehi));
+       sysreg_write(TLBEHI, tlbehi);
+
+       /* Mark it as "not accessed" */
+       tlbarlo = sysreg_read(TLBARLO);
+       sysreg_write(TLBARLO, tlbarlo | 0x80000000U);
+
+       /* Update the TLB */
+       __builtin_tlbw();
+
+       /* Unmask exceptions */
+       asm volatile("csrf      %0" : : "i"(SYSREG_EM_OFFSET) : "memory");
+}
+
+static int avr32_pm_valid_state(suspend_state_t state)
+{
+       switch (state) {
+       case PM_SUSPEND_ON:
+       case PM_SUSPEND_STANDBY:
+       case PM_SUSPEND_MEM:
+               return 1;
+
+       default:
+               return 0;
+       }
+}
+
+static int avr32_pm_enter(suspend_state_t state)
+{
+       u32             lpr_saved;
+       u32             evba_saved;
+       void            *sram;
+
+       switch (state) {
+       case PM_SUSPEND_STANDBY:
+               sram = avr32_pm_map_sram();
+
+               /* Switch to in-sram exception handlers */
+               evba_saved = sysreg_read(EVBA);
+               sysreg_write(EVBA, (unsigned long)sram);
+
+               /*
+                * Save the LPR register so that we can re-enable
+                * SDRAM Low Power mode on resume.
+                */
+               lpr_saved = sdramc_readl(LPR);
+               pr_debug("%s: Entering standby...\n", __func__);
+               avr32_pm_enter_standby(SDRAMC_BASE);
+               sdramc_writel(LPR, lpr_saved);
+
+               /* Switch back to regular exception handlers */
+               sysreg_write(EVBA, evba_saved);
+
+               avr32_pm_unmap_sram();
+               break;
+
+       case PM_SUSPEND_MEM:
+               sram = avr32_pm_map_sram();
+
+               /* Switch to in-sram exception handlers */
+               evba_saved = sysreg_read(EVBA);
+               sysreg_write(EVBA, (unsigned long)sram);
+
+               /*
+                * Save the LPR register so that we can re-enable
+                * SDRAM Low Power mode on resume.
+                */
+               lpr_saved = sdramc_readl(LPR);
+               pr_debug("%s: Entering suspend-to-ram...\n", __func__);
+               avr32_pm_enter_str(SDRAMC_BASE);
+               sdramc_writel(LPR, lpr_saved);
+
+               /* Switch back to regular exception handlers */
+               sysreg_write(EVBA, evba_saved);
+
+               avr32_pm_unmap_sram();
+               break;
+
+       case PM_SUSPEND_ON:
+               pr_debug("%s: Entering idle...\n", __func__);
+               cpu_enter_idle();
+               break;
+
+       default:
+               pr_debug("%s: Invalid suspend state %d\n", __func__, state);
+               goto out;
+       }
+
+       pr_debug("%s: wakeup\n", __func__);
+
+out:
+       return 0;
+}
+
+static struct platform_suspend_ops avr32_pm_ops = {
+       .valid  = avr32_pm_valid_state,
+       .enter  = avr32_pm_enter,
+};
+
+static unsigned long avr32_pm_offset(void *symbol)
+{
+       extern u8 pm_exception[];
+
+       return (unsigned long)symbol - (unsigned long)pm_exception;
+}
+
+static int __init avr32_pm_init(void)
+{
+       extern u8 pm_exception[];
+       extern u8 pm_irq0[];
+       extern u8 pm_standby[];
+       extern u8 pm_suspend_to_ram[];
+       extern u8 pm_sram_end[];
+       void *dst;
+
+       /*
+        * To keep things simple, we depend on not needing more than a
+        * single page.
+        */
+       pm_sram_size = avr32_pm_offset(pm_sram_end);
+       if (pm_sram_size > PAGE_SIZE)
+               goto err;
+
+       pm_sram_start = sram_alloc(pm_sram_size);
+       if (!pm_sram_start)
+               goto err_alloc_sram;
+
+       /* Grab a virtual area we can use later on. */
+       pm_sram_area = get_vm_area(pm_sram_size, VM_IOREMAP);
+       if (!pm_sram_area)
+               goto err_vm_area;
+       pm_sram_area->phys_addr = pm_sram_start;
+
+       local_irq_disable();
+       dst = avr32_pm_map_sram();
+       memcpy(dst, pm_exception, pm_sram_size);
+       flush_dcache_region(dst, pm_sram_size);
+       invalidate_icache_region(dst, pm_sram_size);
+       avr32_pm_unmap_sram();
+       local_irq_enable();
+
+       avr32_pm_enter_standby = dst + avr32_pm_offset(pm_standby);
+       avr32_pm_enter_str = dst + avr32_pm_offset(pm_suspend_to_ram);
+       intc_set_suspend_handler(avr32_pm_offset(pm_irq0));
+
+       suspend_set_ops(&avr32_pm_ops);
+
+       printk("AVR32 AP Power Management enabled\n");
+
+       return 0;
+
+err_vm_area:
+       sram_free(pm_sram_start, pm_sram_size);
+err_alloc_sram:
+err:
+       pr_err("AVR32 Power Management initialization failed\n");
+       return -ENOMEM;
+}
+arch_initcall(avr32_pm_init);
diff --git a/arch/avr32/mach-at32ap/sdramc.h b/arch/avr32/mach-at32ap/sdramc.h
new file mode 100644 (file)
index 0000000..66eeaed
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Register definitions for the AT32AP SDRAM Controller
+ *
+ * Copyright (C) 2008 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+/* Register offsets */
+#define SDRAMC_MR                      0x0000
+#define SDRAMC_TR                      0x0004
+#define SDRAMC_CR                      0x0008
+#define SDRAMC_HSR                     0x000c
+#define SDRAMC_LPR                     0x0010
+#define SDRAMC_IER                     0x0014
+#define SDRAMC_IDR                     0x0018
+#define SDRAMC_IMR                     0x001c
+#define SDRAMC_ISR                     0x0020
+#define SDRAMC_MDR                     0x0024
+
+/* MR - Mode Register */
+#define SDRAMC_MR_MODE_NORMAL          (  0 <<  0)
+#define SDRAMC_MR_MODE_NOP             (  1 <<  0)
+#define SDRAMC_MR_MODE_BANKS_PRECHARGE (  2 <<  0)
+#define SDRAMC_MR_MODE_LOAD_MODE       (  3 <<  0)
+#define SDRAMC_MR_MODE_AUTO_REFRESH    (  4 <<  0)
+#define SDRAMC_MR_MODE_EXT_LOAD_MODE   (  5 <<  0)
+#define SDRAMC_MR_MODE_POWER_DOWN      (  6 <<  0)
+
+/* CR - Configuration Register */
+#define SDRAMC_CR_NC_8_BITS            (  0 <<  0)
+#define SDRAMC_CR_NC_9_BITS            (  1 <<  0)
+#define SDRAMC_CR_NC_10_BITS           (  2 <<  0)
+#define SDRAMC_CR_NC_11_BITS           (  3 <<  0)
+#define SDRAMC_CR_NR_11_BITS           (  0 <<  2)
+#define SDRAMC_CR_NR_12_BITS           (  1 <<  2)
+#define SDRAMC_CR_NR_13_BITS           (  2 <<  2)
+#define SDRAMC_CR_NB_2_BANKS           (  0 <<  4)
+#define SDRAMC_CR_NB_4_BANKS           (  1 <<  4)
+#define SDRAMC_CR_CAS(x)               ((x) <<  5)
+#define SDRAMC_CR_DBW_32_BITS          (  0 <<  7)
+#define SDRAMC_CR_DBW_16_BITS          (  1 <<  7)
+#define SDRAMC_CR_TWR(x)               ((x) <<  8)
+#define SDRAMC_CR_TRC(x)               ((x) << 12)
+#define SDRAMC_CR_TRP(x)               ((x) << 16)
+#define SDRAMC_CR_TRCD(x)              ((x) << 20)
+#define SDRAMC_CR_TRAS(x)              ((x) << 24)
+#define SDRAMC_CR_TXSR(x)              ((x) << 28)
+
+/* HSR - High Speed Register */
+#define SDRAMC_HSR_DA                  (  1 <<  0)
+
+/* LPR - Low Power Register */
+#define SDRAMC_LPR_LPCB_INHIBIT                (  0 <<  0)
+#define SDRAMC_LPR_LPCB_SELF_RFR       (  1 <<  0)
+#define SDRAMC_LPR_LPCB_PDOWN          (  2 <<  0)
+#define SDRAMC_LPR_LPCB_DEEP_PDOWN     (  3 <<  0)
+#define SDRAMC_LPR_PASR(x)             ((x) <<  4)
+#define SDRAMC_LPR_TCSR(x)             ((x) <<  8)
+#define SDRAMC_LPR_DS(x)               ((x) << 10)
+#define SDRAMC_LPR_TIMEOUT(x)          ((x) << 12)
+
+/* IER/IDR/IMR/ISR - Interrupt Enable/Disable/Mask/Status Register */
+#define SDRAMC_ISR_RES                 (  1 <<  0)
+
+/* MDR - Memory Device Register */
+#define SDRAMC_MDR_MD_SDRAM            (  0 <<  0)
+#define SDRAMC_MDR_MD_LOW_PWR_SDRAM    (  1 <<  0)
+
+/* Register access macros */
+#define sdramc_readl(reg) \
+       __raw_readl((void __iomem __force *)SDRAMC_BASE + SDRAMC_##reg)
+#define sdramc_writel(reg, value) \
+       __raw_writel(value, (void __iomem __force *)SDRAMC_BASE + SDRAMC_##reg)
index 0e64ddc..3f90a87 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/swap.h>
 #include <linux/init.h>
 #include <linux/mmzone.h>
+#include <linux/module.h>
 #include <linux/bootmem.h>
 #include <linux/pagemap.h>
 #include <linux/nodemask.h>
 #include <asm/setup.h>
 #include <asm/sections.h>
 
+#define __page_aligned __attribute__((section(".data.page_aligned")))
+
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 
-pgd_t swapper_pg_dir[PTRS_PER_PGD];
+pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned;
 
 struct page *empty_zero_page;
+EXPORT_SYMBOL(empty_zero_page);
 
 /*
  * Cache of MMU context last used.
@@ -106,19 +110,9 @@ void __init paging_init(void)
        zero_page = alloc_bootmem_low_pages_node(NODE_DATA(0),
                                                 PAGE_SIZE);
 
-       {
-               pgd_t *pg_dir;
-               int i;
-
-               pg_dir = swapper_pg_dir;
-               sysreg_write(PTBR, (unsigned long)pg_dir);
-
-               for (i = 0; i < PTRS_PER_PGD; i++)
-                       pgd_val(pg_dir[i]) = 0;
-
-               enable_mmu();
-               printk ("CPU: Paging enabled\n");
-       }
+       sysreg_write(PTBR, (unsigned long)swapper_pg_dir);
+       enable_mmu();
+       printk ("CPU: Paging enabled\n");
 
        for_each_online_node(nid) {
                pg_data_t *pgdat = NODE_DATA(nid);
index cd12edb..06677be 100644 (file)
 
 #include <asm/mmu_context.h>
 
-#define _TLBEHI_I      0x100
+/* TODO: Get the correct number from the CONFIG1 system register */
+#define NR_TLB_ENTRIES 32
 
-void show_dtlb_entry(unsigned int index)
+static void show_dtlb_entry(unsigned int index)
 {
-       unsigned int tlbehi, tlbehi_save, tlbelo, mmucr, mmucr_save;
+       u32 tlbehi, tlbehi_save, tlbelo, mmucr, mmucr_save;
        unsigned long flags;
 
        local_irq_save(flags);
        mmucr_save = sysreg_read(MMUCR);
        tlbehi_save = sysreg_read(TLBEHI);
-       mmucr = mmucr_save & 0x13;
-       mmucr |= index << 14;
+       mmucr = SYSREG_BFINS(DRP, index, mmucr_save);
        sysreg_write(MMUCR, mmucr);
 
-       asm volatile("tlbr" : : : "memory");
+       __builtin_tlbr();
        cpu_sync_pipeline();
 
        tlbehi = sysreg_read(TLBEHI);
@@ -33,15 +33,17 @@ void show_dtlb_entry(unsigned int index)
 
        printk("%2u: %c %c %02x   %05x %05x %o  %o  %c %c %c %c\n",
               index,
-              (tlbehi & 0x200)?'1':'0',
-              (tlbelo & 0x100)?'1':'0',
-              (tlbehi & 0xff),
-              (tlbehi >> 12), (tlbelo >> 12),
-              (tlbelo >> 4) & 7, (tlbelo >> 2) & 3,
-              (tlbelo & 0x200)?'1':'0',
-              (tlbelo & 0x080)?'1':'0',
-              (tlbelo & 0x001)?'1':'0',
-              (tlbelo & 0x002)?'1':'0');
+              SYSREG_BFEXT(TLBEHI_V, tlbehi) ? '1' : '0',
+              SYSREG_BFEXT(G, tlbelo) ? '1' : '0',
+              SYSREG_BFEXT(ASID, tlbehi),
+              SYSREG_BFEXT(VPN, tlbehi) >> 2,
+              SYSREG_BFEXT(PFN, tlbelo) >> 2,
+              SYSREG_BFEXT(AP, tlbelo),
+              SYSREG_BFEXT(SZ, tlbelo),
+              SYSREG_BFEXT(TLBELO_C, tlbelo) ? 'C' : ' ',
+              SYSREG_BFEXT(B, tlbelo) ? 'B' : ' ',
+              SYSREG_BFEXT(W, tlbelo) ? 'W' : ' ',
+              SYSREG_BFEXT(TLBELO_D, tlbelo) ? 'D' : ' ');
 
        sysreg_write(MMUCR, mmucr_save);
        sysreg_write(TLBEHI, tlbehi_save);
@@ -54,29 +56,33 @@ void dump_dtlb(void)
        unsigned int i;
 
        printk("ID  V G ASID VPN   PFN   AP SZ C B W D\n");
-       for (i = 0; i < 32; i++)
+       for (i = 0; i < NR_TLB_ENTRIES; i++)
                show_dtlb_entry(i);
 }
 
-static unsigned long last_mmucr;
-
-static inline void set_replacement_pointer(unsigned shift)
+static void update_dtlb(unsigned long address, pte_t pte)
 {
-       unsigned long mmucr, mmucr_save;
+       u32 tlbehi;
+       u32 mmucr;
 
-       mmucr = mmucr_save = sysreg_read(MMUCR);
+       /*
+        * We're not changing the ASID here, so no need to flush the
+        * pipeline.
+        */
+       tlbehi = sysreg_read(TLBEHI);
+       tlbehi = SYSREG_BF(ASID, SYSREG_BFEXT(ASID, tlbehi));
+       tlbehi |= address & MMU_VPN_MASK;
+       tlbehi |= SYSREG_BIT(TLBEHI_V);
+       sysreg_write(TLBEHI, tlbehi);
 
        /* Does this mapping already exist? */
-       __asm__ __volatile__(
-               "       tlbs\n"
-               "       mfsr %0, %1"
-               : "=r"(mmucr)
-               : "i"(SYSREG_MMUCR));
+       __builtin_tlbs();
+       mmucr = sysreg_read(MMUCR);
 
        if (mmucr & SYSREG_BIT(MMUCR_N)) {
                /* Not found -- pick a not-recently-accessed entry */
-               unsigned long rp;
-               unsigned long tlbar = sysreg_read(TLBARLO);
+               unsigned int rp;
+               u32 tlbar = sysreg_read(TLBARLO);
 
                rp = 32 - fls(tlbar);
                if (rp == 32) {
@@ -84,30 +90,14 @@ static inline void set_replacement_pointer(unsigned shift)
                        sysreg_write(TLBARLO, -1L);
                }
 
-               mmucr &= 0x13;
-               mmucr |= (rp << shift);
-
+               mmucr = SYSREG_BFINS(DRP, rp, mmucr);
                sysreg_write(MMUCR, mmucr);
        }
 
-       last_mmucr = mmucr;
-}
-
-static void update_dtlb(unsigned long address, pte_t pte, unsigned long asid)
-{
-       unsigned long vpn;
-
-       vpn = (address & MMU_VPN_MASK) | _TLBEHI_VALID | asid;
-       sysreg_write(TLBEHI, vpn);
-       cpu_sync_pipeline();
-
-       set_replacement_pointer(14);
-
        sysreg_write(TLBELO, pte_val(pte) & _PAGE_FLAGS_HARDWARE_MASK);
 
        /* Let's go */
-       asm volatile("nop\n\ttlbw" : : : "memory");
-       cpu_sync_pipeline();
+       __builtin_tlbw();
 }
 
 void update_mmu_cache(struct vm_area_struct *vma,
@@ -120,39 +110,40 @@ void update_mmu_cache(struct vm_area_struct *vma,
                return;
 
        local_irq_save(flags);
-       update_dtlb(address, pte, get_asid());
+       update_dtlb(address, pte);
        local_irq_restore(flags);
 }
 
-void __flush_tlb_page(unsigned long asid, unsigned long page)
+static void __flush_tlb_page(unsigned long asid, unsigned long page)
 {
-       unsigned long mmucr, tlbehi;
+       u32 mmucr, tlbehi;
 
-       page |= asid;
-       sysreg_write(TLBEHI, page);
-       cpu_sync_pipeline();
-       asm volatile("tlbs");
+       /*
+        * Caller is responsible for masking out non-PFN bits in page
+        * and changing the current ASID if necessary. This means that
+        * we don't need to flush the pipeline after writing TLBEHI.
+        */
+       tlbehi = page | asid;
+       sysreg_write(TLBEHI, tlbehi);
+
+       __builtin_tlbs();
        mmucr = sysreg_read(MMUCR);
 
        if (!(mmucr & SYSREG_BIT(MMUCR_N))) {
-               unsigned long tlbarlo;
-               unsigned long entry;
+               unsigned int entry;
+               u32 tlbarlo;
 
                /* Clear the "valid" bit */
-               tlbehi = sysreg_read(TLBEHI);
-               tlbehi &= ~_TLBEHI_VALID;
                sysreg_write(TLBEHI, tlbehi);
-               cpu_sync_pipeline();
 
                /* mark the entry as "not accessed" */
-               entry = (mmucr >> 14) & 0x3f;
+               entry = SYSREG_BFEXT(DRP, mmucr);
                tlbarlo = sysreg_read(TLBARLO);
-               tlbarlo |= (0x80000000 >> entry);
+               tlbarlo |= (0x80000000UL >> entry);
                sysreg_write(TLBARLO, tlbarlo);
 
                /* update the entry with valid bit clear */
-               asm volatile("tlbw");
-               cpu_sync_pipeline();
+               __builtin_tlbw();
        }
 }
 
@@ -190,17 +181,22 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
 
                local_irq_save(flags);
                size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
+
                if (size > (MMU_DTLB_ENTRIES / 4)) { /* Too many entries to flush */
                        mm->context = NO_CONTEXT;
                        if (mm == current->mm)
                                activate_context(mm);
                } else {
-                       unsigned long asid = mm->context & MMU_CONTEXT_ASID_MASK;
-                       unsigned long saved_asid = MMU_NO_ASID;
+                       unsigned long asid;
+                       unsigned long saved_asid;
+
+                       asid = mm->context & MMU_CONTEXT_ASID_MASK;
+                       saved_asid = MMU_NO_ASID;
 
                        start &= PAGE_MASK;
                        end += (PAGE_SIZE - 1);
                        end &= PAGE_MASK;
+
                        if (mm != current->mm) {
                                saved_asid = get_asid();
                                set_asid(asid);
@@ -218,33 +214,34 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
 }
 
 /*
- * TODO: If this is only called for addresses > TASK_SIZE, we can probably
- * skip the ASID stuff and just use the Global bit...
+ * This function depends on the pages to be flushed having the G
+ * (global) bit set in their pte. This is true for all
+ * PAGE_KERNEL(_RO) pages.
  */
 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
 {
        unsigned long flags;
        int size;
 
-       local_irq_save(flags);
        size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
        if (size > (MMU_DTLB_ENTRIES / 4)) { /* Too many entries to flush */
                flush_tlb_all();
        } else {
-               unsigned long asid = init_mm.context & MMU_CONTEXT_ASID_MASK;
-               unsigned long saved_asid = get_asid();
+               unsigned long asid;
+
+               local_irq_save(flags);
+               asid = get_asid();
 
                start &= PAGE_MASK;
                end += (PAGE_SIZE - 1);
                end &= PAGE_MASK;
-               set_asid(asid);
+
                while (start < end) {
                        __flush_tlb_page(asid, start);
                        start += PAGE_SIZE;
                }
-               set_asid(saved_asid);
+               local_irq_restore(flags);
        }
-       local_irq_restore(flags);
 }
 
 void flush_tlb_mm(struct mm_struct *mm)
@@ -280,7 +277,7 @@ static void *tlb_start(struct seq_file *tlb, loff_t *pos)
 {
        static unsigned long tlb_index;
 
-       if (*pos >= 32)
+       if (*pos >= NR_TLB_ENTRIES)
                return NULL;
 
        tlb_index = 0;
@@ -291,7 +288,7 @@ static void *tlb_next(struct seq_file *tlb, void *v, loff_t *pos)
 {
        unsigned long *index = v;
 
-       if (*index >= 31)
+       if (*index >= NR_TLB_ENTRIES - 1)
                return NULL;
 
        ++*pos;
@@ -313,16 +310,16 @@ static int tlb_show(struct seq_file *tlb, void *v)
        if (*index == 0)
                seq_puts(tlb, "ID  V G ASID VPN   PFN   AP SZ C B W D\n");
 
-       BUG_ON(*index >= 32);
+       BUG_ON(*index >= NR_TLB_ENTRIES);
 
        local_irq_save(flags);
        mmucr_save = sysreg_read(MMUCR);
        tlbehi_save = sysreg_read(TLBEHI);
-       mmucr = mmucr_save & 0x13;
-       mmucr |= *index << 14;
+       mmucr = SYSREG_BFINS(DRP, *index, mmucr_save);
        sysreg_write(MMUCR, mmucr);
 
-       asm volatile("tlbr" : : : "memory");
+       /* TLBR might change the ASID */
+       __builtin_tlbr();
        cpu_sync_pipeline();
 
        tlbehi = sysreg_read(TLBEHI);
@@ -334,16 +331,18 @@ static int tlb_show(struct seq_file *tlb, void *v)
        local_irq_restore(flags);
 
        seq_printf(tlb, "%2lu: %c %c %02x   %05x %05x %o  %o  %c %c %c %c\n",
-              *index,
-              (tlbehi & 0x200)?'1':'0',
-              (tlbelo & 0x100)?'1':'0',
-              (tlbehi & 0xff),
-              (tlbehi >> 12), (tlbelo >> 12),
-              (tlbelo >> 4) & 7, (tlbelo >> 2) & 3,
-              (tlbelo & 0x200)?'1':'0',
-              (tlbelo & 0x080)?'1':'0',
-              (tlbelo & 0x001)?'1':'0',
-              (tlbelo & 0x002)?'1':'0');
+                  *index,
+                  SYSREG_BFEXT(TLBEHI_V, tlbehi) ? '1' : '0',
+                  SYSREG_BFEXT(G, tlbelo) ? '1' : '0',
+                  SYSREG_BFEXT(ASID, tlbehi),
+                  SYSREG_BFEXT(VPN, tlbehi) >> 2,
+                  SYSREG_BFEXT(PFN, tlbelo) >> 2,
+                  SYSREG_BFEXT(AP, tlbelo),
+                  SYSREG_BFEXT(SZ, tlbelo),
+                  SYSREG_BFEXT(TLBELO_C, tlbelo) ? '1' : '0',
+                  SYSREG_BFEXT(B, tlbelo) ? '1' : '0',
+                  SYSREG_BFEXT(W, tlbelo) ? '1' : '0',
+                  SYSREG_BFEXT(TLBELO_D, tlbelo) ? '1' : '0');
 
        return 0;
 }
index 1b44e9e..8598098 100644 (file)
@@ -194,6 +194,7 @@ static loff_t coreb_lseek(struct file *file, loff_t offset, int origin)
        return ret;
 }
 
+/* No BKL needed here */
 static int coreb_open(struct inode *inode, struct file *file)
 {
        spin_lock_irq(&coreb_lock);
index f1cac9d..1f2ae90 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/smp_lock.h>
 #include <linux/wait.h>
 #include <asm/uaccess.h>
 #include "i2c.h"
@@ -375,10 +376,9 @@ int __init eeprom_init(void)
 }
 
 /* Opens the device. */
-
 static int eeprom_open(struct inode * inode, struct file * file)
 {
-
+  cycle_kernel_lock();
   if(iminor(inode) != EEPROM_MINOR_NR)
      return -ENXIO;
   if(imajor(inode) != EEPROM_MAJOR_NR)
index 68a998b..86048e6 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/poll.h>
 #include <linux/init.h>
@@ -323,6 +324,7 @@ gpio_open(struct inode *inode, struct file *filp)
        if (!priv)
                return -ENOMEM;
 
+       lock_kernel();
        priv->minor = p;
 
        /* initialize the io/alarm struct */
@@ -357,6 +359,7 @@ gpio_open(struct inode *inode, struct file *filp)
        alarmlist = priv;
        spin_unlock_irqrestore(&gpio_lock, flags);
 
+       unlock_kernel();
        return 0;
 }
 
index d6d2206..2797e67 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
@@ -566,6 +567,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
 static int
 i2c_open(struct inode *inode, struct file *filp)
 {
+       cycle_kernel_lock();
        return 0;
 }
 
index 069546e..91fea62 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/poll.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 #include <linux/timer.h>
 #include <asm/irq.h>
 #include <asm/dma.h>
@@ -443,18 +444,21 @@ static int sync_serial_open(struct inode *inode, struct file *file)
        int dev = MINOR(inode->i_rdev);
        struct sync_port *port;
        int mode;
+       int err = -EBUSY;
 
+       lock_kernel();
        DEBUG(printk(KERN_DEBUG "Open sync serial port %d\n", dev));
 
        if (dev < 0 || dev >= NUMBER_OF_PORTS || !ports[dev].enabled) {
                DEBUG(printk(KERN_DEBUG "Invalid minor %d\n", dev));
-               return -ENODEV;
+               err = -ENODEV;
+               goto out;
        }
        port = &ports[dev];
        /* Allow open this device twice (assuming one reader and one writer) */
        if (port->busy == 2) {
                DEBUG(printk(KERN_DEBUG "Device is busy.. \n"));
-               return -EBUSY;
+               goto out;
        }
        if (port->init_irqs) {
                if (port->use_dma) {
@@ -465,14 +469,14 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                &ports[0])) {
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 1 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (request_irq(25, rx_interrupt, 0,
                                                "synchronous serial 1 dma rx",
                                                &ports[0])) {
                                        free_irq(24, &port[0]);
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 1 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (cris_request_dma(8,
                                                "synchronous serial 1 dma tr",
                                                DMA_VERBOSE_ON_ERROR,
@@ -482,7 +486,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 1 "
                                                "TX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (cris_request_dma(9,
                                                "synchronous serial 1 dma rec",
                                                DMA_VERBOSE_ON_ERROR,
@@ -493,7 +497,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 1 "
                                                "RX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                }
 #endif
                                RESET_DMA(8); WAIT_DMA(8);
@@ -520,14 +524,14 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                &ports[1])) {
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 3 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (request_irq(21, rx_interrupt, 0,
                                                "synchronous serial 3 dma rx",
                                                &ports[1])) {
                                        free_irq(20, &ports[1]);
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 3 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (cris_request_dma(4,
                                                "synchronous serial 3 dma tr",
                                                DMA_VERBOSE_ON_ERROR,
@@ -537,7 +541,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 3 "
                                                "TX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (cris_request_dma(5,
                                                "synchronous serial 3 dma rec",
                                                DMA_VERBOSE_ON_ERROR,
@@ -548,7 +552,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial port 3 "
                                                "RX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                }
 #endif
                                RESET_DMA(4); WAIT_DMA(4);
@@ -581,7 +585,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                &ports[0])) {
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial manual irq");
-                                       return -EBUSY;
+                                       goto out;
                                }
                        } else if (port == &ports[1]) {
                                if (request_irq(8,
@@ -591,7 +595,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                &ports[1])) {
                                        printk(KERN_CRIT "Can't alloc "
                                                "sync serial manual irq");
-                                       return -EBUSY;
+                                       goto out;
                                }
                        }
                        port->init_irqs = 0;
@@ -620,7 +624,11 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                        *R_IRQ_MASK1_SET = 1 << port->data_avail_bit;
                DEBUG(printk(KERN_DEBUG "sser%d rec started\n", dev));
        }
-       return 0;
+       ret = 0;
+       
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int sync_serial_release(struct inode *inode, struct file *file)
index 9fb5820..67c61ea 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/string.h>
 #include <linux/fs.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/stddef.h>
 
@@ -2302,11 +2303,11 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
        return 0;
 }
 
-
 static int cryptocop_open(struct inode *inode, struct file *filp)
 {
        int p = iminor(inode);
 
+       cycle_kernel_lock();
        if (p != CRYPTOCOP_MINOR) return -EINVAL;
 
        filp->private_data = NULL;
index c2fb7a5..179e7b8 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/fs.h>
 #include <linux/string.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 
 #include <asm/etraxi2c.h>
 
@@ -636,6 +637,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
 static int
 i2c_open(struct inode *inode, struct file *filp)
 {
+       cycle_kernel_lock();
        return 0;
 }
 
index de107da..ef98608 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 
 #include <asm/etraxgpio.h>
 #include <hwregs/reg_map.h>
@@ -390,6 +391,8 @@ static int gpio_open(struct inode *inode, struct file *filp)
 
        if (!priv)
                return -ENOMEM;
+
+       lock_kernel();
        memset(priv, 0, sizeof(*priv));
 
        priv->minor = p;
@@ -412,6 +415,7 @@ static int gpio_open(struct inode *inode, struct file *filp)
                spin_unlock_irq(&gpio_lock);
        }
 
+       unlock_kernel();
        return 0;
 }
 
index 7863fd4..fe1fde8 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 
 #include <asm/etraxgpio.h>
 #include <hwregs/reg_map.h>
@@ -426,9 +427,10 @@ gpio_open(struct inode *inode, struct file *filp)
                return -EINVAL;
 
        priv = kmalloc(sizeof(struct gpio_private), GFP_KERNEL);
-
        if (!priv)
                return -ENOMEM;
+
+       lock_kernel();
        memset(priv, 0, sizeof(*priv));
 
        priv->minor = p;
@@ -449,6 +451,7 @@ gpio_open(struct inode *inode, struct file *filp)
        alarmlist = priv;
        spin_unlock_irq(&alarm_lock);
 
+       unlock_kernel();
        return 0;
 }
 
index 47c377d..d2a0fbf 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/major.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/interrupt.h>
 #include <linux/poll.h>
 #include <linux/init.h>
@@ -429,23 +430,26 @@ static inline int sync_data_avail_to_end(struct sync_port *port)
 static int sync_serial_open(struct inode *inode, struct file *file)
 {
        int dev = iminor(inode);
+       int ret = -EBUSY;
        sync_port *port;
        reg_dma_rw_cfg cfg = {.en = regk_dma_yes};
        reg_dma_rw_intr_mask intr_mask = {.data = regk_dma_yes};
 
+       lock_kernel();
        DEBUG(printk(KERN_DEBUG "Open sync serial port %d\n", dev));
 
        if (dev < 0 || dev >= NBR_PORTS || !ports[dev].enabled)
        {
                DEBUG(printk(KERN_DEBUG "Invalid minor %d\n", dev));
-               return -ENODEV;
+               ret = -ENODEV;
+               goto out;
        }
        port = &ports[dev];
        /* Allow open this device twice (assuming one reader and one writer) */
        if (port->busy == 2)
        {
                DEBUG(printk(KERN_DEBUG "Device is busy.. \n"));
-               return -EBUSY;
+               goto out;
        }
 
 
@@ -459,7 +463,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                "synchronous serial 0 dma tr",
                                                &ports[0])) {
                                        printk(KERN_CRIT "Can't allocate sync serial port 0 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (request_irq(DMA_IN_INTR_VECT,
                                                rx_interrupt,
                                                0,
@@ -467,7 +471,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                &ports[0])) {
                                        free_irq(DMA_OUT_INTR_VECT, &port[0]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 0 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (crisv32_request_dma(OUT_DMA_NBR,
                                                "synchronous serial 0 dma tr",
                                                DMA_VERBOSE_ON_ERROR,
@@ -476,7 +480,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        free_irq(DMA_OUT_INTR_VECT, &port[0]);
                                        free_irq(DMA_IN_INTR_VECT, &port[0]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 0 TX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (crisv32_request_dma(IN_DMA_NBR,
                                                "synchronous serial 0 dma rec",
                                                DMA_VERBOSE_ON_ERROR,
@@ -486,7 +490,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        free_irq(DMA_OUT_INTR_VECT, &port[0]);
                                        free_irq(DMA_IN_INTR_VECT, &port[0]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 1 RX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                }
 #endif
                        }
@@ -499,7 +503,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                "synchronous serial 1 dma tr",
                                                &ports[1])) {
                                        printk(KERN_CRIT "Can't allocate sync serial port 1 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (request_irq(DMA7_INTR_VECT,
                                                       rx_interrupt,
                                                       0,
@@ -507,7 +511,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                       &ports[1])) {
                                        free_irq(DMA6_INTR_VECT, &ports[1]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 3 IRQ");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (crisv32_request_dma(
                                                SYNC_SER1_TX_DMA_NBR,
                                                "synchronous serial 1 dma tr",
@@ -517,7 +521,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        free_irq(DMA6_INTR_VECT, &ports[1]);
                                        free_irq(DMA7_INTR_VECT, &ports[1]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 3 TX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                } else if (crisv32_request_dma(
                                                SYNC_SER1_RX_DMA_NBR,
                                                "synchronous serial 3 dma rec",
@@ -528,7 +532,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                        free_irq(DMA6_INTR_VECT, &ports[1]);
                                        free_irq(DMA7_INTR_VECT, &ports[1]);
                                        printk(KERN_CRIT "Can't allocate sync serial port 3 RX DMA channel");
-                                       return -EBUSY;
+                                       goto out;
                                }
 #endif
                        }
@@ -554,7 +558,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                "synchronous serial manual irq",
                                                &ports[0])) {
                                        printk("Can't allocate sync serial manual irq");
-                                       return -EBUSY;
+                                       goto out;
                                }
                        }
 #ifdef CONFIG_ETRAXFS
@@ -565,7 +569,7 @@ static int sync_serial_open(struct inode *inode, struct file *file)
                                                "synchronous serial manual irq",
                                                &ports[1])) {
                                        printk(KERN_CRIT "Can't allocate sync serial manual irq");
-                                       return -EBUSY;
+                                       goto out;
                                }
                        }
 #endif
@@ -578,7 +582,10 @@ static int sync_serial_open(struct inode *inode, struct file *file)
        } /* port->init_irqs */
 
        port->busy++;
-       return 0;
+       ret = 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int sync_serial_release(struct inode *inode, struct file *file)
index a812d03..e8ac3f7 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/ioport.h>
 #include <linux/capability.h>
 #include <linux/fcntl.h>
@@ -140,10 +141,14 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 
 static int rtc_open(struct inode *inode, struct file *file)
 {
-       if(rtc_status)
+       lock_kernel();
+       if(rtc_status) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
        rtc_status = 1;
+       unlock_kernel();
        return 0;
 }
 
index e341387..432a9f1 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/ioport.h>
 #include <linux/capability.h>
 #include <linux/fcntl.h>
@@ -127,11 +128,14 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 
 static int rtc_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        if( !atomic_dec_and_test(&rtc_ready) )
        {
                atomic_inc( &rtc_ready );
+               unlock_kernel();
                return -EBUSY;
        }
+       unlock_kernel();
 
        return 0;
 }
index 476d20e..a1e3526 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/miscdevice.h>
+#include <linux/smp_lock.h>
 
 #include "excite_iodev.h"
 
@@ -110,8 +111,14 @@ static int __exit iodev_remove(struct device *dev)
 
 static int iodev_open(struct inode *i, struct file *f)
 {
-       return request_irq(iodev_irq, iodev_irqhdl, IRQF_DISABLED,
+       int ret;
+
+       lock_kernel();
+       ret = request_irq(iodev_irq, iodev_irqhdl, IRQF_DISABLED,
                           iodev_name, &miscdev);
+       unlock_kernel();
+
+       return ret;
 }
 
 static int iodev_release(struct inode *i, struct file *f)
index b88f1c1..b556419 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/vmalloc.h>
 #include <linux/elf.h>
 #include <linux/seq_file.h>
+#include <linux/smp_lock.h>
 #include <linux/syscalls.h>
 #include <linux/moduleloader.h>
 #include <linux/interrupt.h>
@@ -392,8 +393,12 @@ out:
 static int file_open(struct inode *inode, struct file *filp)
 {
        int minor = iminor(inode);
+       int err;
 
-       return rtlx_open(minor, (filp->f_flags & O_NONBLOCK) ? 0 : 1);
+       lock_kernel();
+       err = rtlx_open(minor, (filp->f_flags & O_NONBLOCK) ? 0 : 1);
+       unlock_kernel();
+       return err;
 }
 
 static int file_release(struct inode *inode, struct file *filp)
index 2794501..972b2d2 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/vmalloc.h>
 #include <linux/elf.h>
 #include <linux/seq_file.h>
+#include <linux/smp_lock.h>
 #include <linux/syscalls.h>
 #include <linux/moduleloader.h>
 #include <linux/interrupt.h>
@@ -1050,17 +1051,20 @@ static int vpe_open(struct inode *inode, struct file *filp)
        enum vpe_state state;
        struct vpe_notifications *not;
        struct vpe *v;
-       int ret;
+       int ret, err = 0;
 
+       lock_kernel();
        if (minor != iminor(inode)) {
                /* assume only 1 device at the moment. */
                printk(KERN_WARNING "VPE loader: only vpe1 is supported\n");
-               return -ENODEV;
+               err = -ENODEV;
+               goto out;
        }
 
        if ((v = get_vpe(tclimit)) == NULL) {
                printk(KERN_WARNING "VPE loader: unable to get vpe\n");
-               return -ENODEV;
+               err = -ENODEV;
+               goto out;
        }
 
        state = xchg(&v->state, VPE_STATE_INUSE);
@@ -1100,6 +1104,8 @@ static int vpe_open(struct inode *inode, struct file *filp)
        v->shared_ptr = NULL;
        v->__start = 0;
 
+out:
+       unlock_kernel();
        return 0;
 }
 
index 63b444e..28b012a 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/vmalloc.h>
 #include <linux/fs.h>
 #include <linux/errno.h>
@@ -402,18 +403,26 @@ static int sbprof_zbprof_stop(void)
 static int sbprof_tb_open(struct inode *inode, struct file *filp)
 {
        int minor;
+       int err = 0;
 
+       lock_kernel();
        minor = iminor(inode);
-       if (minor != 0)
-               return -ENODEV;
+       if (minor != 0) {
+               err = -ENODEV;
+               goto out;
+       }
 
-       if (xchg(&sbp.open, SB_OPENING) != SB_CLOSED)
-               return -EBUSY;
+       if (xchg(&sbp.open, SB_OPENING) != SB_CLOSED) {
+               err = -EBUSY;
+               goto out;
+       }
 
        memset(&sbp, 0, sizeof(struct sbprof_tb));
        sbp.sbprof_tbbuf = vmalloc(MAX_TBSAMPLE_BYTES);
-       if (!sbp.sbprof_tbbuf)
-               return -ENOMEM;
+       if (!sbp.sbprof_tbbuf) {
+               err = -ENOMEM;
+               goto out;
+       }
        memset(sbp.sbprof_tbbuf, 0, MAX_TBSAMPLE_BYTES);
        init_waitqueue_head(&sbp.tb_sync);
        init_waitqueue_head(&sbp.tb_read);
@@ -421,7 +430,9 @@ static int sbprof_tb_open(struct inode *inode, struct file *filp)
 
        sbp.open = SB_OPEN;
 
-       return 0;
+  out:
+       unlock_kernel();
+       return err;
 }
 
 static int sbprof_tb_release(struct inode *inode, struct file *filp)
index 89d6d5a..f696f57 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/miscdevice.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 
 #include <asm/uaccess.h>
@@ -260,13 +261,16 @@ printk("Preparing to start counters\n");
  */
 static int perf_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock(&perf_lock);
        if (perf_enabled) {
                spin_unlock(&perf_lock);
+               unlock_kernel();
                return -EBUSY;
        }
        perf_enabled = 1;
        spin_unlock(&perf_lock);
+       unlock_kernel();
 
        return 0;
 }
index 2e516b8..1a3b6cc 100644 (file)
@@ -67,7 +67,6 @@ SECTIONS
        _etext = .;
 
        RODATA
-       BUG_TABLE
 
        /* writeable */
        /* Make sure this is page aligned so
index 06b7277..1530a41 100644 (file)
@@ -108,12 +108,14 @@ config ARCH_NO_VIRT_TO_BUS
 config PPC
        bool
        default y
+       select HAVE_DYNAMIC_FTRACE
+       select HAVE_FTRACE
        select HAVE_IDE
-       select HAVE_OPROFILE
        select HAVE_KPROBES
        select HAVE_KRETPROBES
        select HAVE_LMB
        select HAVE_DMA_ATTRS if PPC64
+       select HAVE_OPROFILE
 
 config EARLY_PRINTK
        bool
index 9ebeb24..bf0b1fd 100644 (file)
@@ -12,6 +12,18 @@ CFLAGS_prom_init.o      += -fPIC
 CFLAGS_btext.o         += -fPIC
 endif
 
+ifdef CONFIG_FTRACE
+# Do not trace early boot code
+CFLAGS_REMOVE_cputable.o = -pg
+CFLAGS_REMOVE_prom_init.o = -pg
+
+ifdef CONFIG_DYNAMIC_FTRACE
+# dynamic ftrace setup.
+CFLAGS_REMOVE_ftrace.o = -pg
+endif
+
+endif
+
 obj-y                          := cputable.o ptrace.o syscalls.o \
                                   irq.o align.o signal_32.o pmc.o vdso.o \
                                   init_task.o process.o systbl.o idle.o \
@@ -79,6 +91,8 @@ obj-$(CONFIG_KEXEC)           += machine_kexec.o crash.o \
 obj-$(CONFIG_AUDIT)            += audit.o
 obj64-$(CONFIG_AUDIT)          += compat_audit.o
 
+obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
+
 obj-$(CONFIG_8XX_MINIMAL_FPEMU) += softemu8xx.o
 
 ifneq ($(CONFIG_PPC_INDIRECT_IO),y)
index ab2d62f..da52269 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/ppc_asm.h>
 #include <asm/asm-offsets.h>
 #include <asm/unistd.h>
+#include <asm/ftrace.h>
 
 #undef SHOW_SYSCALLS
 #undef SHOW_SYSCALLS_TASK
@@ -1151,3 +1152,129 @@ machine_check_in_rtas:
        /* XXX load up BATs and panic */
 
 #endif /* CONFIG_PPC_RTAS */
+
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+_GLOBAL(mcount)
+_GLOBAL(_mcount)
+       stwu    r1,-48(r1)
+       stw     r3, 12(r1)
+       stw     r4, 16(r1)
+       stw     r5, 20(r1)
+       stw     r6, 24(r1)
+       mflr    r3
+       stw     r7, 28(r1)
+       mfcr    r5
+       stw     r8, 32(r1)
+       stw     r9, 36(r1)
+       stw     r10,40(r1)
+       stw     r3, 44(r1)
+       stw     r5, 8(r1)
+       subi    r3, r3, MCOUNT_INSN_SIZE
+       .globl mcount_call
+mcount_call:
+       bl      ftrace_stub
+       nop
+       lwz     r6, 8(r1)
+       lwz     r0, 44(r1)
+       lwz     r3, 12(r1)
+       mtctr   r0
+       lwz     r4, 16(r1)
+       mtcr    r6
+       lwz     r5, 20(r1)
+       lwz     r6, 24(r1)
+       lwz     r0, 52(r1)
+       lwz     r7, 28(r1)
+       lwz     r8, 32(r1)
+       mtlr    r0
+       lwz     r9, 36(r1)
+       lwz     r10,40(r1)
+       addi    r1, r1, 48
+       bctr
+
+_GLOBAL(ftrace_caller)
+       /* Based off of objdump optput from glibc */
+       stwu    r1,-48(r1)
+       stw     r3, 12(r1)
+       stw     r4, 16(r1)
+       stw     r5, 20(r1)
+       stw     r6, 24(r1)
+       mflr    r3
+       lwz     r4, 52(r1)
+       mfcr    r5
+       stw     r7, 28(r1)
+       stw     r8, 32(r1)
+       stw     r9, 36(r1)
+       stw     r10,40(r1)
+       stw     r3, 44(r1)
+       stw     r5, 8(r1)
+       subi    r3, r3, MCOUNT_INSN_SIZE
+.globl ftrace_call
+ftrace_call:
+       bl      ftrace_stub
+       nop
+       lwz     r6, 8(r1)
+       lwz     r0, 44(r1)
+       lwz     r3, 12(r1)
+       mtctr   r0
+       lwz     r4, 16(r1)
+       mtcr    r6
+       lwz     r5, 20(r1)
+       lwz     r6, 24(r1)
+       lwz     r0, 52(r1)
+       lwz     r7, 28(r1)
+       lwz     r8, 32(r1)
+       mtlr    r0
+       lwz     r9, 36(r1)
+       lwz     r10,40(r1)
+       addi    r1, r1, 48
+       bctr
+#else
+_GLOBAL(mcount)
+_GLOBAL(_mcount)
+       stwu    r1,-48(r1)
+       stw     r3, 12(r1)
+       stw     r4, 16(r1)
+       stw     r5, 20(r1)
+       stw     r6, 24(r1)
+       mflr    r3
+       lwz     r4, 52(r1)
+       mfcr    r5
+       stw     r7, 28(r1)
+       stw     r8, 32(r1)
+       stw     r9, 36(r1)
+       stw     r10,40(r1)
+       stw     r3, 44(r1)
+       stw     r5, 8(r1)
+
+       subi    r3, r3, MCOUNT_INSN_SIZE
+       LOAD_REG_ADDR(r5, ftrace_trace_function)
+       lwz     r5,0(r5)
+
+       mtctr   r5
+       bctrl
+
+       nop
+
+       lwz     r6, 8(r1)
+       lwz     r0, 44(r1)
+       lwz     r3, 12(r1)
+       mtctr   r0
+       lwz     r4, 16(r1)
+       mtcr    r6
+       lwz     r5, 20(r1)
+       lwz     r6, 24(r1)
+       lwz     r0, 52(r1)
+       lwz     r7, 28(r1)
+       lwz     r8, 32(r1)
+       mtlr    r0
+       lwz     r9, 36(r1)
+       lwz     r10,40(r1)
+       addi    r1, r1, 48
+       bctr
+#endif
+
+_GLOBAL(ftrace_stub)
+       blr
+
+#endif /* CONFIG_MCOUNT */
index 12eb95a..d736924 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/bug.h>
 #include <asm/ptrace.h>
 #include <asm/irqflags.h>
+#include <asm/ftrace.h>
 
 /*
  * System calls.
@@ -875,3 +876,67 @@ _GLOBAL(enter_prom)
        ld      r0,16(r1)
        mtlr    r0
         blr
+
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+_GLOBAL(mcount)
+_GLOBAL(_mcount)
+       /* Taken from output of objdump from lib64/glibc */
+       mflr    r3
+       stdu    r1, -112(r1)
+       std     r3, 128(r1)
+       subi    r3, r3, MCOUNT_INSN_SIZE
+       .globl mcount_call
+mcount_call:
+       bl      ftrace_stub
+       nop
+       ld      r0, 128(r1)
+       mtlr    r0
+       addi    r1, r1, 112
+       blr
+
+_GLOBAL(ftrace_caller)
+       /* Taken from output of objdump from lib64/glibc */
+       mflr    r3
+       ld      r11, 0(r1)
+       stdu    r1, -112(r1)
+       std     r3, 128(r1)
+       ld      r4, 16(r11)
+       subi    r3, r3, MCOUNT_INSN_SIZE
+.globl ftrace_call
+ftrace_call:
+       bl      ftrace_stub
+       nop
+       ld      r0, 128(r1)
+       mtlr    r0
+       addi    r1, r1, 112
+_GLOBAL(ftrace_stub)
+       blr
+#else
+_GLOBAL(mcount)
+       blr
+
+_GLOBAL(_mcount)
+       /* Taken from output of objdump from lib64/glibc */
+       mflr    r3
+       ld      r11, 0(r1)
+       stdu    r1, -112(r1)
+       std     r3, 128(r1)
+       ld      r4, 16(r11)
+
+       subi    r3, r3, MCOUNT_INSN_SIZE
+       LOAD_REG_ADDR(r5,ftrace_trace_function)
+       ld      r5,0(r5)
+       ld      r5,0(r5)
+       mtctr   r5
+       bctrl
+
+       nop
+       ld      r0, 128(r1)
+       mtlr    r0
+       addi    r1, r1, 112
+_GLOBAL(ftrace_stub)
+       blr
+
+#endif
+#endif
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
new file mode 100644 (file)
index 0000000..3855ceb
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Code for replacing ftrace calls with jumps.
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ *
+ * Thanks goes out to P.A. Semi, Inc for supplying me with a PPC64 box.
+ *
+ */
+
+#include <linux/spinlock.h>
+#include <linux/hardirq.h>
+#include <linux/ftrace.h>
+#include <linux/percpu.h>
+#include <linux/init.h>
+#include <linux/list.h>
+
+#include <asm/cacheflush.h>
+#include <asm/ftrace.h>
+
+
+static unsigned int ftrace_nop = 0x60000000;
+
+#ifdef CONFIG_PPC32
+# define GET_ADDR(addr) addr
+#else
+/* PowerPC64's functions are data that points to the functions */
+# define GET_ADDR(addr) *(unsigned long *)addr
+#endif
+
+
+static unsigned int notrace ftrace_calc_offset(long ip, long addr)
+{
+       return (int)(addr - ip);
+}
+
+notrace unsigned char *ftrace_nop_replace(void)
+{
+       return (char *)&ftrace_nop;
+}
+
+notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
+{
+       static unsigned int op;
+
+       /*
+        * It would be nice to just use create_function_call, but that will
+        * update the code itself. Here we need to just return the
+        * instruction that is going to be modified, without modifying the
+        * code.
+        */
+       addr = GET_ADDR(addr);
+
+       /* Set to "bl addr" */
+       op = 0x48000001 | (ftrace_calc_offset(ip, addr) & 0x03fffffc);
+
+       /*
+        * No locking needed, this must be called via kstop_machine
+        * which in essence is like running on a uniprocessor machine.
+        */
+       return (unsigned char *)&op;
+}
+
+#ifdef CONFIG_PPC64
+# define _ASM_ALIGN    " .align 3 "
+# define _ASM_PTR      " .llong "
+#else
+# define _ASM_ALIGN    " .align 2 "
+# define _ASM_PTR      " .long "
+#endif
+
+notrace int
+ftrace_modify_code(unsigned long ip, unsigned char *old_code,
+                  unsigned char *new_code)
+{
+       unsigned replaced;
+       unsigned old = *(unsigned *)old_code;
+       unsigned new = *(unsigned *)new_code;
+       int faulted = 0;
+
+       /*
+        * Note: Due to modules and __init, code can
+        *  disappear and change, we need to protect against faulting
+        *  as well as code changing.
+        *
+        * No real locking needed, this code is run through
+        * kstop_machine.
+        */
+       asm volatile (
+               "1: lwz         %1, 0(%2)\n"
+               "   cmpw        %1, %5\n"
+               "   bne         2f\n"
+               "   stwu        %3, 0(%2)\n"
+               "2:\n"
+               ".section .fixup, \"ax\"\n"
+               "3:     li %0, 1\n"
+               "       b 2b\n"
+               ".previous\n"
+               ".section __ex_table,\"a\"\n"
+               _ASM_ALIGN "\n"
+               _ASM_PTR "1b, 3b\n"
+               ".previous"
+               : "=r"(faulted), "=r"(replaced)
+               : "r"(ip), "r"(new),
+                 "0"(faulted), "r"(old)
+               : "memory");
+
+       if (replaced != old && replaced != new)
+               faulted = 2;
+
+       if (!faulted)
+               flush_icache_range(ip, ip + 8);
+
+       return faulted;
+}
+
+notrace int ftrace_update_ftrace_func(ftrace_func_t func)
+{
+       unsigned long ip = (unsigned long)(&ftrace_call);
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+       int ret;
+
+       memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, (unsigned long)func);
+       ret = ftrace_modify_code(ip, old, new);
+
+       return ret;
+}
+
+notrace int ftrace_mcount_set(unsigned long *data)
+{
+       unsigned long ip = (long)(&mcount_call);
+       unsigned long *addr = data;
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+
+       /*
+        * Replace the mcount stub with a pointer to the
+        * ip recorder function.
+        */
+       memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, *addr);
+       *addr = ftrace_modify_code(ip, old, new);
+
+       return 0;
+}
+
+int __init ftrace_dyn_arch_init(void *data)
+{
+       /* This is running in kstop_machine */
+
+       ftrace_mcount_set(data);
+
+       return 0;
+}
+
index e31aca9..1882bf4 100644 (file)
@@ -120,7 +120,8 @@ EXPORT_SYMBOL(_outsl_ns);
 
 #define IO_CHECK_ALIGN(v,a) ((((unsigned long)(v)) & ((a) - 1)) == 0)
 
-void _memset_io(volatile void __iomem *addr, int c, unsigned long n)
+notrace void
+_memset_io(volatile void __iomem *addr, int c, unsigned long n)
 {
        void *p = (void __force *)addr;
        u32 lc = c;
index d6df018..6ac8612 100644 (file)
@@ -98,7 +98,7 @@ EXPORT_SYMBOL(irq_desc);
 
 int distribute_irqs = 1;
 
-static inline unsigned long get_hard_enabled(void)
+static inline notrace unsigned long get_hard_enabled(void)
 {
        unsigned long enabled;
 
@@ -108,13 +108,13 @@ static inline unsigned long get_hard_enabled(void)
        return enabled;
 }
 
-static inline void set_soft_enabled(unsigned long enable)
+static inline notrace void set_soft_enabled(unsigned long enable)
 {
        __asm__ __volatile__("stb %0,%1(13)"
        : : "r" (enable), "i" (offsetof(struct paca_struct, soft_enabled)));
 }
 
-void raw_local_irq_restore(unsigned long en)
+notrace void raw_local_irq_restore(unsigned long en)
 {
        /*
         * get_paca()->soft_enabled = en;
index 958ecb9..e1ea4fe 100644 (file)
@@ -42,6 +42,7 @@
 #include <asm/div64.h>
 #include <asm/signal.h>
 #include <asm/dcr.h>
+#include <asm/ftrace.h>
 
 #ifdef CONFIG_PPC32
 extern void transfer_to_handler(void);
@@ -67,6 +68,10 @@ EXPORT_SYMBOL(single_step_exception);
 EXPORT_SYMBOL(sys_sigreturn);
 #endif
 
+#ifdef CONFIG_FTRACE
+EXPORT_SYMBOL(_mcount);
+#endif
+
 EXPORT_SYMBOL(strcpy);
 EXPORT_SYMBOL(strncpy);
 EXPORT_SYMBOL(strcat);
index 0109e7f..4efebe8 100644 (file)
@@ -81,7 +81,7 @@ int ucache_bsize;
  * from the address that it was linked at, so we must use RELOC/PTRRELOC
  * to access static data (including strings).  -- paulus
  */
-unsigned long __init early_init(unsigned long dt_ptr)
+notrace unsigned long __init early_init(unsigned long dt_ptr)
 {
        unsigned long offset = reloc_offset();
        struct cpu_spec *spec;
@@ -115,7 +115,7 @@ unsigned long __init early_init(unsigned long dt_ptr)
  * This is called very early on the boot process, after a minimal
  * MMU environment has been set up but before MMU_init is called.
  */
-void __init machine_init(unsigned long dt_ptr, unsigned long phys)
+notrace void __init machine_init(unsigned long dt_ptr, unsigned long phys)
 {
        /* Enable early debugging if any specified (see udbg.h) */
        udbg_early_init();
@@ -142,7 +142,7 @@ void __init machine_init(unsigned long dt_ptr, unsigned long phys)
 
 #ifdef CONFIG_BOOKE_WDT
 /* Checks wdt=x and wdt_period=xx command-line option */
-int __init early_parse_wdt(char *p)
+notrace int __init early_parse_wdt(char *p)
 {
        if (p && strncmp(p, "0", 1) != 0)
               booke_wdt_enabled = 1;
index 6856f6c..87a72c6 100644 (file)
@@ -64,8 +64,6 @@ SECTIONS
 
        NOTES
 
-       BUG_TABLE
-
 /*
  * Init sections discarded at runtime
  */
index 4d72c8f..8977417 100644 (file)
@@ -1,5 +1,10 @@
 CFLAGS_bootx_init.o            += -fPIC
 
+ifdef CONFIG_FTRACE
+# Do not trace early boot code
+CFLAGS_REMOVE_bootx_init.o = -pg
+endif
+
 obj-y                          += pic.o setup.o time.o feature.o pci.o \
                                   sleep.o low_i2c.o cache.o pfunc_core.o \
                                   pfunc_base.o
index 107e492..5dc8f80 100644 (file)
@@ -146,6 +146,7 @@ config MATHEMU
 config COMPAT
        bool "Kernel support for 31 bit emulation"
        depends on 64BIT
+       select COMPAT_BINFMT_ELF
        help
          Select this option if you want to enable your system kernel to
          handle system-calls from ELF binaries for 31 bit ESA.  This option
@@ -312,6 +313,10 @@ config ARCH_SPARSEMEM_DEFAULT
 config ARCH_SELECT_MEMORY_MODEL
        def_bool y
 
+config ARCH_ENABLE_MEMORY_HOTPLUG
+       def_bool y
+       depends on SPARSEMEM
+
 source "mm/Kconfig"
 
 comment "I/O subsystem configuration"
@@ -344,6 +349,22 @@ config QDIO_DEBUG
 
          If unsure, say N.
 
+config CHSC_SCH
+       tristate "Support for CHSC subchannels"
+       help
+         This driver allows usage of CHSC subchannels. A CHSC subchannel
+         is usually present on LPAR only.
+         The driver creates a device /dev/chsc, which may be used to
+         obtain I/O configuration information about the machine and
+         to issue asynchronous chsc commands (DANGEROUS).
+         You will usually only want to use this interface on a special
+         LPAR designated for system management.
+
+         To compile this driver as a module, choose M here: the
+         module will be called chsc_sch.
+
+         If unsure, say N.
+
 comment "Misc"
 
 config IPL
index db3ae85..17a2636 100644 (file)
@@ -3,13 +3,11 @@
  *
  * Definitions and interface for Linux - z/VM Monitor Stream.
  *
- * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
+ * Copyright IBM Corp. 2003, 2008
  *
  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  */
 
-//#define APPLDATA_DEBUG                       /* Debug messages on/off */
-
 #define APPLDATA_MAX_REC_SIZE    4024  /* Maximum size of the */
                                        /* data buffer */
 #define APPLDATA_MAX_PROCS 100
 #define P_ERROR(x...)  printk(KERN_ERR MY_PRINT_NAME " error: " x)
 #define P_WARNING(x...)        printk(KERN_WARNING MY_PRINT_NAME " status: " x)
 
-#ifdef APPLDATA_DEBUG
-#define P_DEBUG(x...)   printk(KERN_DEBUG MY_PRINT_NAME " debug: " x)
-#else
-#define P_DEBUG(x...)   do {} while (0)
-#endif
-
 struct appldata_ops {
        struct list_head list;
        struct ctl_table_header *sysctl_header;
index ad40729..9cb3d92 100644 (file)
@@ -5,7 +5,7 @@
  * Exports appldata_register_ops() and appldata_unregister_ops() for the
  * data gathering modules.
  *
- * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
+ * Copyright IBM Corp. 2003, 2008
  *
  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  */
@@ -108,9 +108,6 @@ static LIST_HEAD(appldata_ops_list);
  */
 static void appldata_timer_function(unsigned long data)
 {
-       P_DEBUG("   -= Timer =-\n");
-       P_DEBUG("CPU: %i, expire_count: %i\n", smp_processor_id(),
-               atomic_read(&appldata_expire_count));
        if (atomic_dec_and_test(&appldata_expire_count)) {
                atomic_set(&appldata_expire_count, num_online_cpus());
                queue_work(appldata_wq, (struct work_struct *) data);
@@ -128,14 +125,11 @@ static void appldata_work_fn(struct work_struct *work)
        struct appldata_ops *ops;
        int i;
 
-       P_DEBUG("  -= Work Queue =-\n");
        i = 0;
        get_online_cpus();
        spin_lock(&appldata_ops_lock);
        list_for_each(lh, &appldata_ops_list) {
                ops = list_entry(lh, struct appldata_ops, list);
-               P_DEBUG("list_for_each loop: %i) active = %u, name = %s\n",
-                       ++i, ops->active, ops->name);
                if (ops->active == 1) {
                        ops->callback(ops->data);
                }
@@ -212,7 +206,6 @@ __appldata_vtimer_setup(int cmd)
                                                 0, 1);
                }
                appldata_timer_active = 1;
-               P_INFO("Monitoring timer started.\n");
                break;
        case APPLDATA_DEL_TIMER:
                for_each_online_cpu(i)
@@ -221,7 +214,6 @@ __appldata_vtimer_setup(int cmd)
                        break;
                appldata_timer_active = 0;
                atomic_set(&appldata_expire_count, num_online_cpus());
-               P_INFO("Monitoring timer stopped.\n");
                break;
        case APPLDATA_MOD_TIMER:
                per_cpu_interval = (u64) (appldata_interval*1000 /
@@ -313,10 +305,8 @@ appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
        }
        interval = 0;
        sscanf(buf, "%i", &interval);
-       if (interval <= 0) {
-               P_ERROR("Timer CPU interval has to be > 0!\n");
+       if (interval <= 0)
                return -EINVAL;
-       }
 
        get_online_cpus();
        spin_lock(&appldata_timer_lock);
@@ -324,9 +314,6 @@ appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
        __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
        spin_unlock(&appldata_timer_lock);
        put_online_cpus();
-
-       P_INFO("Monitoring CPU interval set to %u milliseconds.\n",
-                interval);
 out:
        *lenp = len;
        *ppos += len;
@@ -406,23 +393,16 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
                        P_ERROR("START DIAG 0xDC for %s failed, "
                                "return code: %d\n", ops->name, rc);
                        module_put(ops->owner);
-               } else {
-                       P_INFO("Monitoring %s data enabled, "
-                               "DIAG 0xDC started.\n", ops->name);
+               } else
                        ops->active = 1;
-               }
        } else if ((buf[0] == '0') && (ops->active == 1)) {
                ops->active = 0;
                rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
                                (unsigned long) ops->data, ops->size,
                                ops->mod_lvl);
-               if (rc != 0) {
+               if (rc != 0)
                        P_ERROR("STOP DIAG 0xDC for %s failed, "
                                "return code: %d\n", ops->name, rc);
-               } else {
-                       P_INFO("Monitoring %s data disabled, "
-                               "DIAG 0xDC stopped.\n", ops->name);
-               }
                module_put(ops->owner);
        }
        spin_unlock(&appldata_ops_lock);
@@ -468,7 +448,6 @@ int appldata_register_ops(struct appldata_ops *ops)
        ops->sysctl_header = register_sysctl_table(ops->ctl_table);
        if (!ops->sysctl_header)
                goto out;
-       P_INFO("%s-ops registered!\n", ops->name);
        return 0;
 out:
        spin_lock(&appldata_ops_lock);
@@ -490,7 +469,6 @@ void appldata_unregister_ops(struct appldata_ops *ops)
        spin_unlock(&appldata_ops_lock);
        unregister_sysctl_table(ops->sysctl_header);
        kfree(ops->ctl_table);
-       P_INFO("%s-ops unregistered!\n", ops->name);
 }
 /********************** module-ops management <END> **************************/
 
@@ -553,14 +531,9 @@ static int __init appldata_init(void)
 {
        int i;
 
-       P_DEBUG("sizeof(parameter_list) = %lu\n",
-               sizeof(struct appldata_parameter_list));
-
        appldata_wq = create_singlethread_workqueue("appldata");
-       if (!appldata_wq) {
-               P_ERROR("Could not create work queue\n");
+       if (!appldata_wq)
                return -ENOMEM;
-       }
 
        get_online_cpus();
        for_each_online_cpu(i)
@@ -571,8 +544,6 @@ static int __init appldata_init(void)
        register_hotcpu_notifier(&appldata_nb);
 
        appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
-
-       P_DEBUG("Base interface initialized.\n");
        return 0;
 }
 
@@ -584,7 +555,9 @@ EXPORT_SYMBOL_GPL(appldata_register_ops);
 EXPORT_SYMBOL_GPL(appldata_unregister_ops);
 EXPORT_SYMBOL_GPL(appldata_diag);
 
+#ifdef CONFIG_SWAP
 EXPORT_SYMBOL_GPL(si_swapinfo);
+#endif
 EXPORT_SYMBOL_GPL(nr_threads);
 EXPORT_SYMBOL_GPL(nr_running);
 EXPORT_SYMBOL_GPL(nr_iowait);
index 51181cc..3ed56b7 100644 (file)
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/kernel_stat.h>
-#include <asm/io.h>
 #include <linux/pagemap.h>
 #include <linux/swap.h>
+#include <asm/io.h>
 
 #include "appldata.h"
 
 
-#define MY_PRINT_NAME "appldata_mem"           /* for debug messages, etc. */
 #define P2K(x) ((x) << (PAGE_SHIFT - 10))      /* Converts #Pages to KB */
 
 /*
@@ -70,30 +69,6 @@ static struct appldata_mem_data {
 } __attribute__((packed)) appldata_mem_data;
 
 
-static inline void appldata_debug_print(struct appldata_mem_data *mem_data)
-{
-       P_DEBUG("--- MEM - RECORD ---\n");
-       P_DEBUG("pgpgin     = %8lu KB\n", mem_data->pgpgin);
-       P_DEBUG("pgpgout    = %8lu KB\n", mem_data->pgpgout);
-       P_DEBUG("pswpin     = %8lu Pages\n", mem_data->pswpin);
-       P_DEBUG("pswpout    = %8lu Pages\n", mem_data->pswpout);
-       P_DEBUG("pgalloc    = %8lu \n", mem_data->pgalloc);
-       P_DEBUG("pgfault    = %8lu \n", mem_data->pgfault);
-       P_DEBUG("pgmajfault = %8lu \n", mem_data->pgmajfault);
-       P_DEBUG("sharedram  = %8lu KB\n", mem_data->sharedram);
-       P_DEBUG("totalram   = %8lu KB\n", mem_data->totalram);
-       P_DEBUG("freeram    = %8lu KB\n", mem_data->freeram);
-       P_DEBUG("totalhigh  = %8lu KB\n", mem_data->totalhigh);
-       P_DEBUG("freehigh   = %8lu KB\n", mem_data->freehigh);
-       P_DEBUG("bufferram  = %8lu KB\n", mem_data->bufferram);
-       P_DEBUG("cached     = %8lu KB\n", mem_data->cached);
-       P_DEBUG("totalswap  = %8lu KB\n", mem_data->totalswap);
-       P_DEBUG("freeswap   = %8lu KB\n", mem_data->freeswap);
-       P_DEBUG("sync_count_1 = %u\n", mem_data->sync_count_1);
-       P_DEBUG("sync_count_2 = %u\n", mem_data->sync_count_2);
-       P_DEBUG("timestamp    = %lX\n", mem_data->timestamp);
-}
-
 /*
  * appldata_get_mem_data()
  *
@@ -140,9 +115,6 @@ static void appldata_get_mem_data(void *data)
 
        mem_data->timestamp = get_clock();
        mem_data->sync_count_2++;
-#ifdef APPLDATA_DEBUG
-       appldata_debug_print(mem_data);
-#endif
 }
 
 
@@ -164,17 +136,7 @@ static struct appldata_ops ops = {
  */
 static int __init appldata_mem_init(void)
 {
-       int rc;
-
-       P_DEBUG("sizeof(mem) = %lu\n", sizeof(struct appldata_mem_data));
-
-       rc = appldata_register_ops(&ops);
-       if (rc != 0) {
-               P_ERROR("Error registering ops, rc = %i\n", rc);
-       } else {
-               P_DEBUG("%s-ops registered!\n", ops.name);
-       }
-       return rc;
+       return appldata_register_ops(&ops);
 }
 
 /*
@@ -185,7 +147,6 @@ static int __init appldata_mem_init(void)
 static void __exit appldata_mem_exit(void)
 {
        appldata_unregister_ops(&ops);
-       P_DEBUG("%s-ops unregistered!\n", ops.name);
 }
 
 
index 4d83443..3b74655 100644 (file)
@@ -21,9 +21,6 @@
 #include "appldata.h"
 
 
-#define MY_PRINT_NAME  "appldata_net_sum"      /* for debug messages, etc. */
-
-
 /*
  * Network data
  *
@@ -60,26 +57,6 @@ static struct appldata_net_sum_data {
 } __attribute__((packed)) appldata_net_sum_data;
 
 
-static inline void appldata_print_debug(struct appldata_net_sum_data *net_data)
-{
-       P_DEBUG("--- NET - RECORD ---\n");
-
-       P_DEBUG("nr_interfaces = %u\n", net_data->nr_interfaces);
-       P_DEBUG("rx_packets    = %8lu\n", net_data->rx_packets);
-       P_DEBUG("tx_packets    = %8lu\n", net_data->tx_packets);
-       P_DEBUG("rx_bytes      = %8lu\n", net_data->rx_bytes);
-       P_DEBUG("tx_bytes      = %8lu\n", net_data->tx_bytes);
-       P_DEBUG("rx_errors     = %8lu\n", net_data->rx_errors);
-       P_DEBUG("tx_errors     = %8lu\n", net_data->tx_errors);
-       P_DEBUG("rx_dropped    = %8lu\n", net_data->rx_dropped);
-       P_DEBUG("tx_dropped    = %8lu\n", net_data->tx_dropped);
-       P_DEBUG("collisions    = %8lu\n", net_data->collisions);
-
-       P_DEBUG("sync_count_1 = %u\n", net_data->sync_count_1);
-       P_DEBUG("sync_count_2 = %u\n", net_data->sync_count_2);
-       P_DEBUG("timestamp    = %lX\n", net_data->timestamp);
-}
-
 /*
  * appldata_get_net_sum_data()
  *
@@ -135,9 +112,6 @@ static void appldata_get_net_sum_data(void *data)
 
        net_data->timestamp = get_clock();
        net_data->sync_count_2++;
-#ifdef APPLDATA_DEBUG
-       appldata_print_debug(net_data);
-#endif
 }
 
 
@@ -159,17 +133,7 @@ static struct appldata_ops ops = {
  */
 static int __init appldata_net_init(void)
 {
-       int rc;
-
-       P_DEBUG("sizeof(net) = %lu\n", sizeof(struct appldata_net_sum_data));
-
-       rc = appldata_register_ops(&ops);
-       if (rc != 0) {
-               P_ERROR("Error registering ops, rc = %i\n", rc);
-       } else {
-               P_DEBUG("%s-ops registered!\n", ops.name);
-       }
-       return rc;
+       return appldata_register_ops(&ops);
 }
 
 /*
@@ -180,7 +144,6 @@ static int __init appldata_net_init(void)
 static void __exit appldata_net_exit(void)
 {
        appldata_unregister_ops(&ops);
-       P_DEBUG("%s-ops unregistered!\n", ops.name);
 }
 
 
index 6b3eafe..eb44f9f 100644 (file)
@@ -89,44 +89,6 @@ static struct appldata_ops ops = {
 };
 
 
-static inline void appldata_print_debug(struct appldata_os_data *os_data)
-{
-       int a0, a1, a2, i;
-
-       P_DEBUG("--- OS - RECORD ---\n");
-       P_DEBUG("nr_threads   = %u\n", os_data->nr_threads);
-       P_DEBUG("nr_running   = %u\n", os_data->nr_running);
-       P_DEBUG("nr_iowait    = %u\n", os_data->nr_iowait);
-       P_DEBUG("avenrun(int) = %8x / %8x / %8x\n", os_data->avenrun[0],
-               os_data->avenrun[1], os_data->avenrun[2]);
-       a0 = os_data->avenrun[0];
-       a1 = os_data->avenrun[1];
-       a2 = os_data->avenrun[2];
-       P_DEBUG("avenrun(float) = %d.%02d / %d.%02d / %d.%02d\n",
-               LOAD_INT(a0), LOAD_FRAC(a0), LOAD_INT(a1), LOAD_FRAC(a1),
-               LOAD_INT(a2), LOAD_FRAC(a2));
-
-       P_DEBUG("nr_cpus = %u\n", os_data->nr_cpus);
-       for (i = 0; i < os_data->nr_cpus; i++) {
-               P_DEBUG("cpu%u : user = %u, nice = %u, system = %u, "
-                       "idle = %u, irq = %u, softirq = %u, iowait = %u, "
-                       "steal = %u\n",
-                               os_data->os_cpu[i].cpu_id,
-                               os_data->os_cpu[i].per_cpu_user,
-                               os_data->os_cpu[i].per_cpu_nice,
-                               os_data->os_cpu[i].per_cpu_system,
-                               os_data->os_cpu[i].per_cpu_idle,
-                               os_data->os_cpu[i].per_cpu_irq,
-                               os_data->os_cpu[i].per_cpu_softirq,
-                               os_data->os_cpu[i].per_cpu_iowait,
-                               os_data->os_cpu[i].per_cpu_steal);
-       }
-
-       P_DEBUG("sync_count_1 = %u\n", os_data->sync_count_1);
-       P_DEBUG("sync_count_2 = %u\n", os_data->sync_count_2);
-       P_DEBUG("timestamp    = %lX\n", os_data->timestamp);
-}
-
 /*
  * appldata_get_os_data()
  *
@@ -180,13 +142,10 @@ static void appldata_get_os_data(void *data)
                                           APPLDATA_START_INTERVAL_REC,
                                           (unsigned long) ops.data, new_size,
                                           ops.mod_lvl);
-                       if (rc != 0) {
+                       if (rc != 0)
                                P_ERROR("os: START NEW DIAG 0xDC failed, "
                                        "return code: %d, new size = %i\n", rc,
                                        new_size);
-                               P_INFO("os: stopping old record now\n");
-                       } else
-                               P_INFO("os: new record size = %i\n", new_size);
 
                        rc = appldata_diag(APPLDATA_RECORD_OS_ID,
                                           APPLDATA_STOP_REC,
@@ -204,9 +163,6 @@ static void appldata_get_os_data(void *data)
        }
        os_data->timestamp = get_clock();
        os_data->sync_count_2++;
-#ifdef APPLDATA_DEBUG
-       appldata_print_debug(os_data);
-#endif
 }
 
 
@@ -227,12 +183,9 @@ static int __init appldata_os_init(void)
                rc = -ENOMEM;
                goto out;
        }
-       P_DEBUG("max. sizeof(os) = %i, sizeof(os_cpu) = %lu\n", max_size,
-               sizeof(struct appldata_os_per_cpu));
 
        appldata_os_data = kzalloc(max_size, GFP_DMA);
        if (appldata_os_data == NULL) {
-               P_ERROR("No memory for %s!\n", ops.name);
                rc = -ENOMEM;
                goto out;
        }
@@ -240,17 +193,12 @@ static int __init appldata_os_init(void)
        appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu);
        appldata_os_data->cpu_offset   = offsetof(struct appldata_os_data,
                                                        os_cpu);
-       P_DEBUG("cpu offset = %u\n", appldata_os_data->cpu_offset);
 
        ops.data = appldata_os_data;
        ops.callback  = &appldata_get_os_data;
        rc = appldata_register_ops(&ops);
-       if (rc != 0) {
-               P_ERROR("Error registering ops, rc = %i\n", rc);
+       if (rc != 0)
                kfree(appldata_os_data);
-       } else {
-               P_DEBUG("%s-ops registered!\n", ops.name);
-       }
 out:
        return rc;
 }
@@ -264,7 +212,6 @@ static void __exit appldata_os_exit(void)
 {
        appldata_unregister_ops(&ops);
        kfree(appldata_os_data);
-       P_DEBUG("%s-ops unregistered!\n", ops.name);
 }
 
 
index 9992f95..0ef9829 100644 (file)
@@ -296,6 +296,10 @@ static inline int crypt_s390_func_available(int func)
        unsigned char status[16];
        int ret;
 
+       /* check if CPACF facility (bit 17) is available */
+       if (!(stfl() & 1ULL << (31 - 17)))
+               return 0;
+
        switch (func & CRYPT_S390_OP_MASK) {
        case CRYPT_S390_KM:
                ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0);
index 0cfefdd..eca724d 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/smp_lock.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
@@ -48,6 +49,7 @@ static unsigned char parm_block[32] = {
 
 static int prng_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        return nonseekable_open(inode, file);
 }
 
@@ -185,11 +187,8 @@ static int __init prng_init(void)
        prng_seed(16);
 
        ret = misc_register(&prng_dev);
-       if (ret) {
-               printk(KERN_WARNING
-                      "Could not register misc device for PRNG.\n");
+       if (ret)
                goto out_buf;
-       }
        return 0;
 
 out_buf:
index 4b010ff..7383781 100644 (file)
@@ -150,33 +150,24 @@ static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
                              unsigned long nr_segs, loff_t offset)
 {
        char *data;
-       size_t len;
+       ssize_t ret;
        struct file *filp = iocb->ki_filp;
        /* XXX: temporary */
        char __user *buf = iov[0].iov_base;
        size_t count = iov[0].iov_len;
 
-       if (nr_segs != 1) {
-               count = -EINVAL;
-               goto out;
-       }
+       if (nr_segs != 1)
+               return -EINVAL;
 
        data = filp->private_data;
-       len = strlen(data);
-       if (offset > len) {
-               count = 0;
-               goto out;
-       }
-       if (count > len - offset)
-               count = len - offset;
-       if (copy_to_user(buf, data + offset, count)) {
-               count = -EFAULT;
-               goto out;
-       }
-       iocb->ki_pos += count;
+       ret = simple_read_from_buffer(buf, count, &offset, data, strlen(data));
+       if (ret <= 0)
+               return ret;
+
+       iocb->ki_pos += ret;
        file_accessed(filp);
-out:
-       return count;
+
+       return ret;
 }
 static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
                              unsigned long nr_segs, loff_t offset)
index 6302f50..50f657e 100644 (file)
@@ -7,9 +7,14 @@
 #
 CFLAGS_smp.o   := -Wno-nonnull
 
+#
+# Pass UTS_MACHINE for user_regset definition
+#
+CFLAGS_ptrace.o                += -DUTS_MACHINE='"$(UTS_MACHINE)"'
+
 obj-y  :=  bitmap.o traps.o time.o process.o base.o early.o \
             setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \
-           s390_ext.o debug.o irq.o ipl.o dis.o diag.o
+           s390_ext.o debug.o irq.o ipl.o dis.o diag.o mem_detect.o
 
 obj-y  += $(if $(CONFIG_64BIT),entry64.o,entry.o)
 obj-y  += $(if $(CONFIG_64BIT),reipl64.o,reipl.o)
@@ -23,7 +28,7 @@ obj-$(CONFIG_AUDIT)           += audit.o
 compat-obj-$(CONFIG_AUDIT)     += compat_audit.o
 obj-$(CONFIG_COMPAT)           += compat_linux.o compat_signal.o \
                                        compat_wrapper.o compat_exec_domain.o \
-                                       binfmt_elf32.o $(compat-obj-y)
+                                       $(compat-obj-y)
 
 obj-$(CONFIG_VIRT_TIMER)       += vtime.o
 obj-$(CONFIG_STACKTRACE)       += stacktrace.o
diff --git a/arch/s390/kernel/binfmt_elf32.c b/arch/s390/kernel/binfmt_elf32.c
deleted file mode 100644 (file)
index 3e1c315..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Support for 32-bit Linux for S390 ELF binaries.
- *
- * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
- * Author(s): Gerhard Tonn (ton@de.ibm.com)
- *
- * Heavily inspired by the 32-bit Sparc compat code which is
- * Copyright (C) 1995, 1996, 1997, 1998 David S. Miller (davem@redhat.com)
- * Copyright (C) 1995, 1996, 1997, 1998 Jakub Jelinek   (jj@ultra.linux.cz)
- */
-
-#define __ASMS390_ELF_H
-
-#include <linux/time.h>
-
-/*
- * These are used to set parameters in the core dumps.
- */
-#define ELF_CLASS      ELFCLASS32
-#define ELF_DATA       ELFDATA2MSB
-#define ELF_ARCH       EM_S390
-
-/*
- * This is used to ensure we don't load something for the wrong architecture.
- */
-#define elf_check_arch(x) \
-       (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
-         && (x)->e_ident[EI_CLASS] == ELF_CLASS)
-
-/* ELF register definitions */
-#define NUM_GPRS      16
-#define NUM_FPRS      16
-#define NUM_ACRS      16    
-
-/* For SVR4/S390 the function pointer to be registered with `atexit` is
-   passed in R14. */
-#define ELF_PLAT_INIT(_r, load_addr) \
-       do { \
-               _r->gprs[14] = 0; \
-       } while(0)
-
-#define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
-
-/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
-   use of this is to invoke "./ld.so someprog" to test out a new version of
-   the loader.  We need to make sure that it is out of the way of the program
-   that it will "exec", and that there is sufficient room for the brk.  */
-
-#define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
-
-/* Wow, the "main" arch needs arch dependent functions too.. :) */
-
-/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
-   now struct_user_regs, they are different) */
-
-#define ELF_CORE_COPY_REGS(pr_reg, regs) dump_regs32(regs, &pr_reg);
-
-#define ELF_CORE_COPY_TASK_REGS(tsk, regs) dump_task_regs32(tsk, regs)
-
-#define ELF_CORE_COPY_FPREGS(tsk, fpregs) dump_task_fpu(tsk, fpregs)
-
-/* This yields a mask that user programs can use to figure out what
-   instruction set this CPU supports. */
-
-#define ELF_HWCAP (0)
-
-/* This yields a string that ld.so will use to load implementation
-   specific libraries for optimization.  This is more specific in
-   intent than poking at uname or /proc/cpuinfo.
-
-   For the moment, we have only optimizations for the Intel generations,
-   but that could change... */
-
-#define ELF_PLATFORM (NULL)
-
-#define SET_PERSONALITY(ex, ibcs2)                     \
-do {                                                   \
-       if (ibcs2)                                      \
-               set_personality(PER_SVR4);              \
-       else if (current->personality != PER_LINUX32)   \
-               set_personality(PER_LINUX);             \
-       set_thread_flag(TIF_31BIT);                     \
-} while (0)
-
-#include "compat_linux.h"
-
-typedef _s390_fp_regs32 elf_fpregset_t;
-
-typedef struct
-{
-       
-       _psw_t32        psw;
-       __u32           gprs[__NUM_GPRS]; 
-       __u32           acrs[__NUM_ACRS]; 
-       __u32           orig_gpr2;
-} s390_regs32;
-typedef s390_regs32 elf_gregset_t;
-
-static inline int dump_regs32(struct pt_regs *ptregs, elf_gregset_t *regs)
-{
-       int i;
-
-       memcpy(&regs->psw.mask, &ptregs->psw.mask, 4);
-       memcpy(&regs->psw.addr, (char *)&ptregs->psw.addr + 4, 4);
-       for (i = 0; i < NUM_GPRS; i++)
-               regs->gprs[i] = ptregs->gprs[i];
-       save_access_regs(regs->acrs);
-       regs->orig_gpr2 = ptregs->orig_gpr2;
-       return 1;
-}
-
-static inline int dump_task_regs32(struct task_struct *tsk, elf_gregset_t *regs)
-{
-       struct pt_regs *ptregs = task_pt_regs(tsk);
-       int i;
-
-       memcpy(&regs->psw.mask, &ptregs->psw.mask, 4);
-       memcpy(&regs->psw.addr, (char *)&ptregs->psw.addr + 4, 4);
-       for (i = 0; i < NUM_GPRS; i++)
-               regs->gprs[i] = ptregs->gprs[i];
-       memcpy(regs->acrs, tsk->thread.acrs, sizeof(regs->acrs));
-       regs->orig_gpr2 = ptregs->orig_gpr2;
-       return 1;
-}
-
-static inline int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
-{
-       if (tsk == current)
-               save_fp_regs((s390_fp_regs *) fpregs);
-       else
-               memcpy(fpregs, &tsk->thread.fp_regs, sizeof(elf_fpregset_t));
-       return 1;
-}
-
-#include <asm/processor.h>
-#include <asm/pgalloc.h>
-#include <linux/module.h>
-#include <linux/elfcore.h>
-#include <linux/binfmts.h>
-#include <linux/compat.h>
-
-#define elf_prstatus elf_prstatus32
-struct elf_prstatus32
-{
-       struct elf_siginfo pr_info;     /* Info associated with signal */
-       short   pr_cursig;              /* Current signal */
-       u32     pr_sigpend;     /* Set of pending signals */
-       u32     pr_sighold;     /* Set of held signals */
-       pid_t   pr_pid;
-       pid_t   pr_ppid;
-       pid_t   pr_pgrp;
-       pid_t   pr_sid;
-       struct compat_timeval pr_utime; /* User time */
-       struct compat_timeval pr_stime; /* System time */
-       struct compat_timeval pr_cutime;        /* Cumulative user time */
-       struct compat_timeval pr_cstime;        /* Cumulative system time */
-       elf_gregset_t pr_reg;   /* GP registers */
-       int pr_fpvalid;         /* True if math co-processor being used.  */
-};
-
-#define elf_prpsinfo elf_prpsinfo32
-struct elf_prpsinfo32
-{
-       char    pr_state;       /* numeric process state */
-       char    pr_sname;       /* char for pr_state */
-       char    pr_zomb;        /* zombie */
-       char    pr_nice;        /* nice val */
-       u32     pr_flag;        /* flags */
-       u16     pr_uid;
-       u16     pr_gid;
-       pid_t   pr_pid, pr_ppid, pr_pgrp, pr_sid;
-       /* Lots missing */
-       char    pr_fname[16];   /* filename of executable */
-       char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
-};
-
-#include <linux/highuid.h>
-
-/*
-#define init_elf_binfmt init_elf32_binfmt
-*/
-
-#undef start_thread
-#define start_thread                    start_thread31 
-
-static inline void start_thread31(struct pt_regs *regs, unsigned long new_psw,
-                                 unsigned long new_stackp)
-{
-       set_fs(USER_DS);
-       regs->psw.mask  = psw_user32_bits;
-       regs->psw.addr  = new_psw;
-       regs->gprs[15]  = new_stackp;
-       crst_table_downgrade(current->mm, 1UL << 31);
-}
-
-MODULE_DESCRIPTION("Binary format loader for compatibility with 32bit Linux for S390 binaries,"
-                   " Copyright 2000 IBM Corporation"); 
-MODULE_AUTHOR("Gerhard Tonn <ton@de.ibm.com>");
-
-#undef MODULE_DESCRIPTION
-#undef MODULE_AUTHOR
-
-#undef cputime_to_timeval
-#define cputime_to_timeval cputime_to_compat_timeval
-static inline void
-cputime_to_compat_timeval(const cputime_t cputime, struct compat_timeval *value)
-{
-       value->tv_usec = cputime % 1000000;
-       value->tv_sec = cputime / 1000000;
-}
-
-#include "../../../fs/binfmt_elf.c"
-
index 419aef9..cde81fa 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _PTRACE32_H
 #define _PTRACE32_H
 
-#include "compat_linux.h"  /* needed for _psw_t32 */
+#include "compat_linux.h"  /* needed for psw_compat_t */
 
 typedef struct {
        __u32 cr[3];
@@ -38,7 +38,7 @@ typedef struct {
 
 struct user_regs_struct32
 {
-       _psw_t32 psw;
+       psw_compat_t psw;
        u32 gprs[NUM_GPRS];
        u32 acrs[NUM_ACRS];
        u32 orig_gpr2;
index c93d129..d80fcd4 100644 (file)
@@ -1079,7 +1079,6 @@ __init debug_init(void)
        s390dbf_sysctl_header = register_sysctl_table(s390dbf_dir_table);
        mutex_lock(&debug_mutex);
        debug_debugfs_root_entry = debugfs_create_dir(DEBUG_DIR_ROOT,NULL);
-       printk(KERN_INFO "debug: Initialization complete\n");
        initialized = 1;
        mutex_unlock(&debug_mutex);
 
@@ -1193,7 +1192,6 @@ debug_get_uint(char *buf)
        for(; isspace(*buf); buf++);
        rc = simple_strtoul(buf, &buf, 10);
        if(*buf){
-               printk("debug: no integer specified!\n");
                rc = -EINVAL;
        }
        return rc;
@@ -1340,19 +1338,12 @@ static void debug_flush(debug_info_t* id, int area)
                                memset(id->areas[i][j], 0, PAGE_SIZE);
                        }
                }
-                printk(KERN_INFO "debug: %s: all areas flushed\n",id->name);
         } else if(area >= 0 && area < id->nr_areas) {
                 id->active_entries[area] = 0;
                id->active_pages[area] = 0;
                for(i = 0; i < id->pages_per_area; i++) {
                        memset(id->areas[area][i],0,PAGE_SIZE);
                }
-                printk(KERN_INFO "debug: %s: area %i has been flushed\n",
-                        id->name, area);
-        } else {
-                printk(KERN_INFO
-                      "debug: %s: area %i cannot be flushed (range: %i - %i)\n",
-                        id->name, area, 0, id->nr_areas-1);
         }
         spin_unlock_irqrestore(&id->lock,flags);
 }
index d0e0968..2a2ca26 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/pfn.h>
 #include <linux/uaccess.h>
+#include <asm/ebcdic.h>
 #include <asm/ipl.h>
 #include <asm/lowcore.h>
 #include <asm/processor.h>
 /*
  * Create a Kernel NSS if the SAVESYS= parameter is defined
  */
-#define DEFSYS_CMD_SIZE                96
+#define DEFSYS_CMD_SIZE                128
 #define SAVESYS_CMD_SIZE       32
 
 char kernel_nss_name[NSS_NAME_SIZE + 1];
 
+static void __init setup_boot_command_line(void);
+
+
 #ifdef CONFIG_SHARED_KERNEL
+int __init savesys_ipl_nss(char *cmd, const int cmdlen);
+
+asm(
+       "       .section .init.text,\"ax\",@progbits\n"
+       "       .align  4\n"
+       "       .type   savesys_ipl_nss, @function\n"
+       "savesys_ipl_nss:\n"
+#ifdef CONFIG_64BIT
+       "       stmg    6,15,48(15)\n"
+       "       lgr     14,3\n"
+       "       sam31\n"
+       "       diag    2,14,0x8\n"
+       "       sam64\n"
+       "       lgr     2,14\n"
+       "       lmg     6,15,48(15)\n"
+#else
+       "       stm     6,15,24(15)\n"
+       "       lr      14,3\n"
+       "       diag    2,14,0x8\n"
+       "       lr      2,14\n"
+       "       lm      6,15,24(15)\n"
+#endif
+       "       br      14\n"
+       "       .size   savesys_ipl_nss, .-savesys_ipl_nss\n");
+
 static noinline __init void create_kernel_nss(void)
 {
        unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
@@ -39,6 +68,7 @@ static noinline __init void create_kernel_nss(void)
        unsigned int sinitrd_pfn, einitrd_pfn;
 #endif
        int response;
+       size_t len;
        char *savesys_ptr;
        char upper_command_line[COMMAND_LINE_SIZE];
        char defsys_cmd[DEFSYS_CMD_SIZE];
@@ -49,8 +79,8 @@ static noinline __init void create_kernel_nss(void)
                return;
 
        /* Convert COMMAND_LINE to upper case */
-       for (i = 0; i < strlen(COMMAND_LINE); i++)
-               upper_command_line[i] = toupper(COMMAND_LINE[i]);
+       for (i = 0; i < strlen(boot_command_line); i++)
+               upper_command_line[i] = toupper(boot_command_line[i]);
 
        savesys_ptr = strstr(upper_command_line, "SAVESYS=");
 
@@ -83,7 +113,8 @@ static noinline __init void create_kernel_nss(void)
        }
 #endif
 
-       sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK", defsys_cmd, min_size);
+       sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK PARMREGS=0-13",
+               defsys_cmd, min_size);
        sprintf(savesys_cmd, "SAVESYS %s \n IPL %s",
                kernel_nss_name, kernel_nss_name);
 
@@ -94,13 +125,24 @@ static noinline __init void create_kernel_nss(void)
                return;
        }
 
-       __cpcmd(savesys_cmd, NULL, 0, &response);
+       len = strlen(savesys_cmd);
+       ASCEBC(savesys_cmd, len);
+       response = savesys_ipl_nss(savesys_cmd, len);
 
-       if (response != strlen(savesys_cmd)) {
+       /* On success: response is equal to the command size,
+        *             max SAVESYS_CMD_SIZE
+        * On error: response contains the numeric portion of cp error message.
+        *           for SAVESYS it will be >= 263
+        */
+       if (response > SAVESYS_CMD_SIZE) {
                kernel_nss_name[0] = '\0';
                return;
        }
 
+       /* re-setup boot command line with new ipl vm parms */
+       ipl_update_parameters();
+       setup_boot_command_line();
+
        ipl_flags = IPL_NSS_VALID;
 }
 
@@ -141,109 +183,11 @@ static noinline __init void detect_machine_type(void)
        if (cpuinfo->cpu_id.version == 0xff)
                machine_flags |= MACHINE_FLAG_VM;
 
-       /* Running on a P/390 ? */
-       if (cpuinfo->cpu_id.machine == 0x7490)
-               machine_flags |= MACHINE_FLAG_P390;
-
        /* Running under KVM ? */
        if (cpuinfo->cpu_id.version == 0xfe)
                machine_flags |= MACHINE_FLAG_KVM;
 }
 
-#ifdef CONFIG_64BIT
-static noinline __init int memory_fast_detect(void)
-{
-       unsigned long val0 = 0;
-       unsigned long val1 = 0xc;
-       int ret = -ENOSYS;
-
-       if (ipl_flags & IPL_NSS_VALID)
-               return -ENOSYS;
-
-       asm volatile(
-               "       diag    %1,%2,0x260\n"
-               "0:     lhi     %0,0\n"
-               "1:\n"
-               EX_TABLE(0b,1b)
-               : "+d" (ret), "+d" (val0), "+d" (val1) : : "cc");
-
-       if (ret || val0 != val1)
-               return -ENOSYS;
-
-       memory_chunk[0].size = val0 + 1;
-       return 0;
-}
-#else
-static inline int memory_fast_detect(void)
-{
-       return -ENOSYS;
-}
-#endif
-
-static inline __init unsigned long __tprot(unsigned long addr)
-{
-       int cc = -1;
-
-       asm volatile(
-               "       tprot   0(%1),0\n"
-               "0:     ipm     %0\n"
-               "       srl     %0,28\n"
-               "1:\n"
-               EX_TABLE(0b,1b)
-               : "+d" (cc) : "a" (addr) : "cc");
-       return (unsigned long)cc;
-}
-
-/* Checking memory in 128KB increments. */
-#define CHUNK_INCR     (1UL << 17)
-#define ADDR2G         (1UL << 31)
-
-static noinline __init void find_memory_chunks(unsigned long memsize)
-{
-       unsigned long addr = 0, old_addr = 0;
-       unsigned long old_cc = CHUNK_READ_WRITE;
-       unsigned long cc;
-       int chunk = 0;
-
-       while (chunk < MEMORY_CHUNKS) {
-               cc = __tprot(addr);
-               while (cc == old_cc) {
-                       addr += CHUNK_INCR;
-                       if (memsize && addr >= memsize)
-                               break;
-#ifndef CONFIG_64BIT
-                       if (addr == ADDR2G)
-                               break;
-#endif
-                       cc = __tprot(addr);
-               }
-
-               if (old_addr != addr &&
-                   (old_cc == CHUNK_READ_WRITE || old_cc == CHUNK_READ_ONLY)) {
-                       memory_chunk[chunk].addr = old_addr;
-                       memory_chunk[chunk].size = addr - old_addr;
-                       memory_chunk[chunk].type = old_cc;
-                       chunk++;
-               }
-
-               old_addr = addr;
-               old_cc = cc;
-
-#ifndef CONFIG_64BIT
-               if (addr == ADDR2G)
-                       break;
-#endif
-               /*
-                * Finish memory detection at the first hole
-                * if storage size is unknown.
-                */
-               if (cc == -1UL && !memsize)
-                       break;
-               if (memsize && addr >= memsize)
-                       break;
-       }
-}
-
 static __init void early_pgm_check_handler(void)
 {
        unsigned long addr;
@@ -380,23 +324,61 @@ static __init void detect_machine_facilities(void)
 #endif
 }
 
+static __init void rescue_initrd(void)
+{
+#ifdef CONFIG_BLK_DEV_INITRD
+       /*
+        * Move the initrd right behind the bss section in case it starts
+        * within the bss section. So we don't overwrite it when the bss
+        * section gets cleared.
+        */
+       if (!INITRD_START || !INITRD_SIZE)
+               return;
+       if (INITRD_START >= (unsigned long) __bss_stop)
+               return;
+       memmove(__bss_stop, (void *) INITRD_START, INITRD_SIZE);
+       INITRD_START = (unsigned long) __bss_stop;
+#endif
+}
+
+/* Set up boot command line */
+static void __init setup_boot_command_line(void)
+{
+       char *parm = NULL;
+
+       /* copy arch command line */
+       strlcpy(boot_command_line, COMMAND_LINE, ARCH_COMMAND_LINE_SIZE);
+       boot_command_line[ARCH_COMMAND_LINE_SIZE - 1] = 0;
+
+       /* append IPL PARM data to the boot command line */
+       if (MACHINE_IS_VM) {
+               parm = boot_command_line + strlen(boot_command_line);
+               *parm++ = ' ';
+               get_ipl_vmparm(parm);
+               if (parm[0] == '=')
+                       memmove(boot_command_line, parm + 1, strlen(parm));
+       }
+}
+
+
 /*
  * Save ipl parameters, clear bss memory, initialize storage keys
  * and create a kernel NSS at startup if the SAVESYS= parm is defined
  */
 void __init startup_init(void)
 {
-       unsigned long long memsize;
-
        ipl_save_parameters();
+       rescue_initrd();
        clear_bss_section();
        init_kernel_storage_key();
        lockdep_init();
        lockdep_off();
-       detect_machine_type();
-       create_kernel_nss();
        sort_main_extable();
        setup_lowcore_early();
+       detect_machine_type();
+       ipl_update_parameters();
+       setup_boot_command_line();
+       create_kernel_nss();
        detect_mvpg();
        detect_ieee();
        detect_csp();
@@ -404,18 +386,7 @@ void __init startup_init(void)
        detect_diag44();
        detect_machine_facilities();
        setup_hpage();
-       sclp_read_info_early();
        sclp_facilities_detect();
-       memsize = sclp_memory_detect();
-#ifndef CONFIG_64BIT
-       /*
-        * Can't deal with more than 2G in 31 bit addressing mode, so
-        * limit the value in order to avoid strange side effects.
-        */
-       if (memsize > ADDR2G)
-               memsize = ADDR2G;
-#endif
-       if (memory_fast_detect() < 0)
-               find_memory_chunks((unsigned long) memsize);
+       detect_memory_layout(memory_chunk);
        lockdep_on();
 }
index 5325424..54b2779 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/ctype.h>
+#include <linux/fs.h>
 #include <asm/ipl.h>
 #include <asm/smp.h>
 #include <asm/setup.h>
@@ -22,6 +23,7 @@
 #include <asm/ebcdic.h>
 #include <asm/reset.h>
 #include <asm/sclp.h>
+#include <asm/setup.h>
 
 #define IPL_PARM_BLOCK_VERSION 0
 
@@ -121,6 +123,7 @@ enum ipl_method {
        REIPL_METHOD_FCP_RO_VM,
        REIPL_METHOD_FCP_DUMP,
        REIPL_METHOD_NSS,
+       REIPL_METHOD_NSS_DIAG,
        REIPL_METHOD_DEFAULT,
 };
 
@@ -134,14 +137,15 @@ enum dump_method {
 
 static int diag308_set_works = 0;
 
+static struct ipl_parameter_block ipl_block;
+
 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
 
 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
 static struct ipl_parameter_block *reipl_block_fcp;
 static struct ipl_parameter_block *reipl_block_ccw;
-
-static char reipl_nss_name[NSS_NAME_SIZE + 1];
+static struct ipl_parameter_block *reipl_block_nss;
 
 static int dump_capabilities = DUMP_TYPE_NONE;
 static enum dump_type dump_type = DUMP_TYPE_NONE;
@@ -263,6 +267,56 @@ static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
 
 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
 
+/* VM IPL PARM routines */
+static void reipl_get_ascii_vmparm(char *dest,
+                                  const struct ipl_parameter_block *ipb)
+{
+       int i;
+       int len = 0;
+       char has_lowercase = 0;
+
+       if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
+           (ipb->ipl_info.ccw.vm_parm_len > 0)) {
+
+               len = ipb->ipl_info.ccw.vm_parm_len;
+               memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
+               /* If at least one character is lowercase, we assume mixed
+                * case; otherwise we convert everything to lowercase.
+                */
+               for (i = 0; i < len; i++)
+                       if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
+                           (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
+                           (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
+                               has_lowercase = 1;
+                               break;
+                       }
+               if (!has_lowercase)
+                       EBC_TOLOWER(dest, len);
+               EBCASC(dest, len);
+       }
+       dest[len] = 0;
+}
+
+void get_ipl_vmparm(char *dest)
+{
+       if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
+               reipl_get_ascii_vmparm(dest, &ipl_block);
+       else
+               dest[0] = 0;
+}
+
+static ssize_t ipl_vm_parm_show(struct kobject *kobj,
+                               struct kobj_attribute *attr, char *page)
+{
+       char parm[DIAG308_VMPARM_SIZE + 1] = {};
+
+       get_ipl_vmparm(parm);
+       return sprintf(page, "%s\n", parm);
+}
+
+static struct kobj_attribute sys_ipl_vm_parm_attr =
+       __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
+
 static ssize_t sys_ipl_device_show(struct kobject *kobj,
                                   struct kobj_attribute *attr, char *page)
 {
@@ -285,14 +339,8 @@ static struct kobj_attribute sys_ipl_device_attr =
 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
                                  char *buf, loff_t off, size_t count)
 {
-       unsigned int size = IPL_PARMBLOCK_SIZE;
-
-       if (off > size)
-               return 0;
-       if (off + count > size)
-               count = size - off;
-       memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
-       return count;
+       return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
+                                       IPL_PARMBLOCK_SIZE);
 }
 
 static struct bin_attribute ipl_parameter_attr = {
@@ -310,12 +358,7 @@ static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *att
        unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
        void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
 
-       if (off > size)
-               return 0;
-       if (off + count > size)
-               count = size - off;
-       memcpy(buf, scp_data + off, count);
-       return count;
+       return memory_read_from_buffer(buf, count, &off, scp_data, size);
 }
 
 static struct bin_attribute ipl_scp_data_attr = {
@@ -370,15 +413,27 @@ static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
        __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
 
-static struct attribute *ipl_ccw_attrs[] = {
+static struct attribute *ipl_ccw_attrs_vm[] = {
        &sys_ipl_type_attr.attr,
        &sys_ipl_device_attr.attr,
        &sys_ipl_ccw_loadparm_attr.attr,
+       &sys_ipl_vm_parm_attr.attr,
        NULL,
 };
 
-static struct attribute_group ipl_ccw_attr_group = {
-       .attrs = ipl_ccw_attrs,
+static struct attribute *ipl_ccw_attrs_lpar[] = {
+       &sys_ipl_type_attr.attr,
+       &sys_ipl_device_attr.attr,
+       &sys_ipl_ccw_loadparm_attr.attr,
+       NULL,
+};
+
+static struct attribute_group ipl_ccw_attr_group_vm = {
+       .attrs = ipl_ccw_attrs_vm,
+};
+
+static struct attribute_group ipl_ccw_attr_group_lpar = {
+       .attrs = ipl_ccw_attrs_lpar
 };
 
 /* NSS ipl device attributes */
@@ -388,6 +443,8 @@ DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
 static struct attribute *ipl_nss_attrs[] = {
        &sys_ipl_type_attr.attr,
        &sys_ipl_nss_name_attr.attr,
+       &sys_ipl_ccw_loadparm_attr.attr,
+       &sys_ipl_vm_parm_attr.attr,
        NULL,
 };
 
@@ -450,7 +507,12 @@ static int __init ipl_init(void)
        }
        switch (ipl_info.type) {
        case IPL_TYPE_CCW:
-               rc = sysfs_create_group(&ipl_kset->kobj, &ipl_ccw_attr_group);
+               if (MACHINE_IS_VM)
+                       rc = sysfs_create_group(&ipl_kset->kobj,
+                                               &ipl_ccw_attr_group_vm);
+               else
+                       rc = sysfs_create_group(&ipl_kset->kobj,
+                                               &ipl_ccw_attr_group_lpar);
                break;
        case IPL_TYPE_FCP:
        case IPL_TYPE_FCP_DUMP:
@@ -481,6 +543,83 @@ static struct shutdown_action __refdata ipl_action = {
  * reipl shutdown action: Reboot Linux on shutdown.
  */
 
+/* VM IPL PARM attributes */
+static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
+                                         char *page)
+{
+       char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
+
+       reipl_get_ascii_vmparm(vmparm, ipb);
+       return sprintf(page, "%s\n", vmparm);
+}
+
+static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
+                                         size_t vmparm_max,
+                                         const char *buf, size_t len)
+{
+       int i, ip_len;
+
+       /* ignore trailing newline */
+       ip_len = len;
+       if ((len > 0) && (buf[len - 1] == '\n'))
+               ip_len--;
+
+       if (ip_len > vmparm_max)
+               return -EINVAL;
+
+       /* parm is used to store kernel options, check for common chars */
+       for (i = 0; i < ip_len; i++)
+               if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
+                       return -EINVAL;
+
+       memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
+       ipb->ipl_info.ccw.vm_parm_len = ip_len;
+       if (ip_len > 0) {
+               ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
+               memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
+               ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
+       } else {
+               ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
+       }
+
+       return len;
+}
+
+/* NSS wrapper */
+static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
+                                    struct kobj_attribute *attr, char *page)
+{
+       return reipl_generic_vmparm_show(reipl_block_nss, page);
+}
+
+static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
+                                     struct kobj_attribute *attr,
+                                     const char *buf, size_t len)
+{
+       return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
+}
+
+/* CCW wrapper */
+static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
+                                    struct kobj_attribute *attr, char *page)
+{
+       return reipl_generic_vmparm_show(reipl_block_ccw, page);
+}
+
+static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
+                                     struct kobj_attribute *attr,
+                                     const char *buf, size_t len)
+{
+       return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
+}
+
+static struct kobj_attribute sys_reipl_nss_vmparm_attr =
+       __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
+                                       reipl_nss_vmparm_store);
+static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
+       __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
+                                       reipl_ccw_vmparm_store);
+
 /* FCP reipl device attributes */
 
 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
@@ -513,27 +652,26 @@ static struct attribute_group reipl_fcp_attr_group = {
 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
        reipl_block_ccw->ipl_info.ccw.devno);
 
-static void reipl_get_ascii_loadparm(char *loadparm)
+static void reipl_get_ascii_loadparm(char *loadparm,
+                                    struct ipl_parameter_block *ibp)
 {
-       memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
-              LOADPARM_LEN);
+       memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
        EBCASC(loadparm, LOADPARM_LEN);
        loadparm[LOADPARM_LEN] = 0;
        strstrip(loadparm);
 }
 
-static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
-                                      struct kobj_attribute *attr, char *page)
+static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
+                                          char *page)
 {
        char buf[LOADPARM_LEN + 1];
 
-       reipl_get_ascii_loadparm(buf);
+       reipl_get_ascii_loadparm(buf, ipb);
        return sprintf(page, "%s\n", buf);
 }
 
-static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
-                                       struct kobj_attribute *attr,
-                                       const char *buf, size_t len)
+static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
+                                           const char *buf, size_t len)
 {
        int i, lp_len;
 
@@ -552,35 +690,128 @@ static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
                return -EINVAL;
        }
        /* initialize loadparm with blanks */
-       memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
+       memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
        /* copy and convert to ebcdic */
-       memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
-       ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
+       memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
+       ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
        return len;
 }
 
+/* NSS wrapper */
+static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
+                                      struct kobj_attribute *attr, char *page)
+{
+       return reipl_generic_loadparm_show(reipl_block_nss, page);
+}
+
+static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
+                                       struct kobj_attribute *attr,
+                                       const char *buf, size_t len)
+{
+       return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
+}
+
+/* CCW wrapper */
+static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
+                                      struct kobj_attribute *attr, char *page)
+{
+       return reipl_generic_loadparm_show(reipl_block_ccw, page);
+}
+
+static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
+                                       struct kobj_attribute *attr,
+                                       const char *buf, size_t len)
+{
+       return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
+}
+
 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
-       __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
-              reipl_ccw_loadparm_store);
+       __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
+                                           reipl_ccw_loadparm_store);
 
-static struct attribute *reipl_ccw_attrs[] = {
+static struct attribute *reipl_ccw_attrs_vm[] = {
        &sys_reipl_ccw_device_attr.attr,
        &sys_reipl_ccw_loadparm_attr.attr,
+       &sys_reipl_ccw_vmparm_attr.attr,
        NULL,
 };
 
-static struct attribute_group reipl_ccw_attr_group = {
+static struct attribute *reipl_ccw_attrs_lpar[] = {
+       &sys_reipl_ccw_device_attr.attr,
+       &sys_reipl_ccw_loadparm_attr.attr,
+       NULL,
+};
+
+static struct attribute_group reipl_ccw_attr_group_vm = {
+       .name  = IPL_CCW_STR,
+       .attrs = reipl_ccw_attrs_vm,
+};
+
+static struct attribute_group reipl_ccw_attr_group_lpar = {
        .name  = IPL_CCW_STR,
-       .attrs = reipl_ccw_attrs,
+       .attrs = reipl_ccw_attrs_lpar,
 };
 
 
 /* NSS reipl device attributes */
+static void reipl_get_ascii_nss_name(char *dst,
+                                    struct ipl_parameter_block *ipb)
+{
+       memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
+       EBCASC(dst, NSS_NAME_SIZE);
+       dst[NSS_NAME_SIZE] = 0;
+}
+
+static ssize_t reipl_nss_name_show(struct kobject *kobj,
+                                  struct kobj_attribute *attr, char *page)
+{
+       char nss_name[NSS_NAME_SIZE + 1] = {};
 
-DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
+       reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
+       return sprintf(page, "%s\n", nss_name);
+}
+
+static ssize_t reipl_nss_name_store(struct kobject *kobj,
+                                   struct kobj_attribute *attr,
+                                   const char *buf, size_t len)
+{
+       int nss_len;
+
+       /* ignore trailing newline */
+       nss_len = len;
+       if ((len > 0) && (buf[len - 1] == '\n'))
+               nss_len--;
+
+       if (nss_len > NSS_NAME_SIZE)
+               return -EINVAL;
+
+       memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
+       if (nss_len > 0) {
+               reipl_block_nss->ipl_info.ccw.vm_flags |=
+                       DIAG308_VM_FLAGS_NSS_VALID;
+               memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
+               ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
+               EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
+       } else {
+               reipl_block_nss->ipl_info.ccw.vm_flags &=
+                       ~DIAG308_VM_FLAGS_NSS_VALID;
+       }
+
+       return len;
+}
+
+static struct kobj_attribute sys_reipl_nss_name_attr =
+       __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
+                                       reipl_nss_name_store);
+
+static struct kobj_attribute sys_reipl_nss_loadparm_attr =
+       __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
+                                           reipl_nss_loadparm_store);
 
 static struct attribute *reipl_nss_attrs[] = {
        &sys_reipl_nss_name_attr.attr,
+       &sys_reipl_nss_loadparm_attr.attr,
+       &sys_reipl_nss_vmparm_attr.attr,
        NULL,
 };
 
@@ -617,7 +848,10 @@ static int reipl_set_type(enum ipl_type type)
                reipl_method = REIPL_METHOD_FCP_DUMP;
                break;
        case IPL_TYPE_NSS:
-               reipl_method = REIPL_METHOD_NSS;
+               if (diag308_set_works)
+                       reipl_method = REIPL_METHOD_NSS_DIAG;
+               else
+                       reipl_method = REIPL_METHOD_NSS;
                break;
        case IPL_TYPE_UNKNOWN:
                reipl_method = REIPL_METHOD_DEFAULT;
@@ -655,11 +889,38 @@ static struct kobj_attribute reipl_type_attr =
 
 static struct kset *reipl_kset;
 
+static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
+                          const enum ipl_method m)
+{
+       char loadparm[LOADPARM_LEN + 1] = {};
+       char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
+       char nss_name[NSS_NAME_SIZE + 1] = {};
+       size_t pos = 0;
+
+       reipl_get_ascii_loadparm(loadparm, ipb);
+       reipl_get_ascii_nss_name(nss_name, ipb);
+       reipl_get_ascii_vmparm(vmparm, ipb);
+
+       switch (m) {
+       case REIPL_METHOD_CCW_VM:
+               pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
+               break;
+       case REIPL_METHOD_NSS:
+               pos = sprintf(dst, "IPL %s", nss_name);
+               break;
+       default:
+               break;
+       }
+       if (strlen(loadparm) > 0)
+               pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
+       if (strlen(vmparm) > 0)
+               sprintf(dst + pos, " PARM %s", vmparm);
+}
+
 static void reipl_run(struct shutdown_trigger *trigger)
 {
        struct ccw_dev_id devid;
-       static char buf[100];
-       char loadparm[LOADPARM_LEN + 1];
+       static char buf[128];
 
        switch (reipl_method) {
        case REIPL_METHOD_CCW_CIO:
@@ -668,13 +929,7 @@ static void reipl_run(struct shutdown_trigger *trigger)
                reipl_ccw_dev(&devid);
                break;
        case REIPL_METHOD_CCW_VM:
-               reipl_get_ascii_loadparm(loadparm);
-               if (strlen(loadparm) == 0)
-                       sprintf(buf, "IPL %X CLEAR",
-                               reipl_block_ccw->ipl_info.ccw.devno);
-               else
-                       sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
-                               reipl_block_ccw->ipl_info.ccw.devno, loadparm);
+               get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
                __cpcmd(buf, NULL, 0, NULL);
                break;
        case REIPL_METHOD_CCW_DIAG:
@@ -691,8 +946,12 @@ static void reipl_run(struct shutdown_trigger *trigger)
        case REIPL_METHOD_FCP_RO_VM:
                __cpcmd("IPL", NULL, 0, NULL);
                break;
+       case REIPL_METHOD_NSS_DIAG:
+               diag308(DIAG308_SET, reipl_block_nss);
+               diag308(DIAG308_IPL, NULL);
+               break;
        case REIPL_METHOD_NSS:
-               sprintf(buf, "IPL %s", reipl_nss_name);
+               get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
                __cpcmd(buf, NULL, 0, NULL);
                break;
        case REIPL_METHOD_DEFAULT:
@@ -707,16 +966,36 @@ static void reipl_run(struct shutdown_trigger *trigger)
        disabled_wait((unsigned long) __builtin_return_address(0));
 }
 
-static void __init reipl_probe(void)
+static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
 {
-       void *buffer;
+       ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
+       ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
+       ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
+       ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
+}
 
-       buffer = (void *) get_zeroed_page(GFP_KERNEL);
-       if (!buffer)
-               return;
-       if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
-               diag308_set_works = 1;
-       free_page((unsigned long)buffer);
+static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
+{
+       /* LOADPARM */
+       /* check if read scp info worked and set loadparm */
+       if (sclp_ipl_info.is_valid)
+               memcpy(ipb->ipl_info.ccw.load_parm,
+                               &sclp_ipl_info.loadparm, LOADPARM_LEN);
+       else
+               /* read scp info failed: set empty loadparm (EBCDIC blanks) */
+               memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
+       ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
+
+       /* VM PARM */
+       if (MACHINE_IS_VM && diag308_set_works &&
+           (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
+
+               ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
+               ipb->ipl_info.ccw.vm_parm_len =
+                                       ipl_block.ipl_info.ccw.vm_parm_len;
+               memcpy(ipb->ipl_info.ccw.vm_parm,
+                      ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
+       }
 }
 
 static int __init reipl_nss_init(void)
@@ -725,10 +1004,31 @@ static int __init reipl_nss_init(void)
 
        if (!MACHINE_IS_VM)
                return 0;
+
+       reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
+       if (!reipl_block_nss)
+               return -ENOMEM;
+
+       if (!diag308_set_works)
+               sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
+
        rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
        if (rc)
                return rc;
-       strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
+
+       reipl_block_ccw_init(reipl_block_nss);
+       if (ipl_info.type == IPL_TYPE_NSS) {
+               memset(reipl_block_nss->ipl_info.ccw.nss_name,
+                       ' ', NSS_NAME_SIZE);
+               memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
+                       kernel_nss_name, strlen(kernel_nss_name));
+               ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
+               reipl_block_nss->ipl_info.ccw.vm_flags |=
+                       DIAG308_VM_FLAGS_NSS_VALID;
+
+               reipl_block_ccw_fill_parms(reipl_block_nss);
+       }
+
        reipl_capabilities |= IPL_TYPE_NSS;
        return 0;
 }
@@ -740,28 +1040,27 @@ static int __init reipl_ccw_init(void)
        reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
        if (!reipl_block_ccw)
                return -ENOMEM;
-       rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
-       if (rc) {
-               free_page((unsigned long)reipl_block_ccw);
-               return rc;
+
+       if (MACHINE_IS_VM) {
+               if (!diag308_set_works)
+                       sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
+               rc = sysfs_create_group(&reipl_kset->kobj,
+                                       &reipl_ccw_attr_group_vm);
+       } else {
+               if(!diag308_set_works)
+                       sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
+               rc = sysfs_create_group(&reipl_kset->kobj,
+                                       &reipl_ccw_attr_group_lpar);
        }
-       reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
-       reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
-       reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
-       reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
-       reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID;
-       /* check if read scp info worked and set loadparm */
-       if (sclp_ipl_info.is_valid)
-               memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
-                      &sclp_ipl_info.loadparm, LOADPARM_LEN);
-       else
-               /* read scp info failed: set empty loadparm (EBCDIC blanks) */
-               memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
-                      LOADPARM_LEN);
-       if (!MACHINE_IS_VM && !diag308_set_works)
-               sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
-       if (ipl_info.type == IPL_TYPE_CCW)
+       if (rc)
+               return rc;
+
+       reipl_block_ccw_init(reipl_block_ccw);
+       if (ipl_info.type == IPL_TYPE_CCW) {
                reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
+               reipl_block_ccw_fill_parms(reipl_block_ccw);
+       }
+
        reipl_capabilities |= IPL_TYPE_CCW;
        return 0;
 }
@@ -1298,7 +1597,6 @@ static void __init shutdown_actions_init(void)
 
 static int __init s390_ipl_init(void)
 {
-       reipl_probe();
        sclp_get_ipl_info(&sclp_ipl_info);
        shutdown_actions_init();
        shutdown_triggers_init();
@@ -1405,6 +1703,12 @@ void __init setup_ipl(void)
        atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
 }
 
+void __init ipl_update_parameters(void)
+{
+       if (diag308(DIAG308_STORE, &ipl_block) == DIAG308_RC_OK)
+               diag308_set_works = 1;
+}
+
 void __init ipl_save_parameters(void)
 {
        struct cio_iplinfo iplinfo;
index ed04d13..288ad49 100644 (file)
@@ -41,10 +41,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
        if (is_prohibited_opcode((kprobe_opcode_t *) p->addr))
                return -EINVAL;
 
-       if ((unsigned long)p->addr & 0x01) {
-               printk("Attempt to register kprobe at an unaligned address\n");
+       if ((unsigned long)p->addr & 0x01)
                return -EINVAL;
-               }
 
        /* Use the get_insn_slot() facility for correctness */
        if (!(p->ainsn.insn = get_insn_slot()))
index 3c77dd3..131d7ee 100644 (file)
@@ -52,7 +52,6 @@ void machine_kexec_cleanup(struct kimage *image)
 
 void machine_shutdown(void)
 {
-       printk(KERN_INFO "kexec: machine_shutdown called\n");
 }
 
 void machine_kexec(struct kimage *image)
diff --git a/arch/s390/kernel/mem_detect.c b/arch/s390/kernel/mem_detect.c
new file mode 100644 (file)
index 0000000..18ed7ab
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <asm/ipl.h>
+#include <asm/sclp.h>
+#include <asm/setup.h>
+
+static int memory_fast_detect(struct mem_chunk *chunk)
+{
+       unsigned long val0 = 0;
+       unsigned long val1 = 0xc;
+       int rc = -EOPNOTSUPP;
+
+       if (ipl_flags & IPL_NSS_VALID)
+               return -EOPNOTSUPP;
+       asm volatile(
+               "       diag    %1,%2,0x260\n"
+               "0:     lhi     %0,0\n"
+               "1:\n"
+               EX_TABLE(0b,1b)
+               : "+d" (rc), "+d" (val0), "+d" (val1) : : "cc");
+
+       if (rc || val0 != val1)
+               return -EOPNOTSUPP;
+       chunk->size = val0 + 1;
+       return 0;
+}
+
+static inline int tprot(unsigned long addr)
+{
+       int rc = -EFAULT;
+
+       asm volatile(
+               "       tprot   0(%1),0\n"
+               "0:     ipm     %0\n"
+               "       srl     %0,28\n"
+               "1:\n"
+               EX_TABLE(0b,1b)
+               : "+d" (rc) : "a" (addr) : "cc");
+       return rc;
+}
+
+#define ADDR2G (1ULL << 31)
+
+static void find_memory_chunks(struct mem_chunk chunk[])
+{
+       unsigned long long memsize, rnmax, rzm;
+       unsigned long addr = 0, size;
+       int i = 0, type;
+
+       rzm = sclp_get_rzm();
+       rnmax = sclp_get_rnmax();
+       memsize = rzm * rnmax;
+       if (!rzm)
+               rzm = 1ULL << 17;
+       if (sizeof(long) == 4) {
+               rzm = min(ADDR2G, rzm);
+               memsize = memsize ? min(ADDR2G, memsize) : ADDR2G;
+       }
+       do {
+               size = 0;
+               type = tprot(addr);
+               do {
+                       size += rzm;
+                       if (memsize && addr + size >= memsize)
+                               break;
+               } while (type == tprot(addr + size));
+               if (type == CHUNK_READ_WRITE || type == CHUNK_READ_ONLY) {
+                       chunk[i].addr = addr;
+                       chunk[i].size = size;
+                       chunk[i].type = type;
+                       i++;
+               }
+               addr += size;
+       } while (addr < memsize && i < MEMORY_CHUNKS);
+}
+
+void detect_memory_layout(struct mem_chunk chunk[])
+{
+       unsigned long flags, cr0;
+
+       memset(chunk, 0, MEMORY_CHUNKS * sizeof(struct mem_chunk));
+       if (memory_fast_detect(&chunk[0]) == 0)
+               return;
+       /* Disable IRQs, DAT and low address protection so tprot does the
+        * right thing and we don't get scheduled away with low address
+        * protection disabled.
+        */
+       flags = __raw_local_irq_stnsm(0xf8);
+       __ctl_store(cr0, 0, 0);
+       __ctl_clear_bit(0, 28);
+       find_memory_chunks(chunk);
+       __ctl_load(cr0, 0, 0);
+       __raw_local_irq_ssm(flags);
+}
+EXPORT_SYMBOL(detect_memory_layout);
index 7920861..85defd0 100644 (file)
@@ -75,46 +75,19 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return sf->gprs[8];
 }
 
-/*
- * Need to know about CPUs going idle?
- */
-static ATOMIC_NOTIFIER_HEAD(idle_chain);
 DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
 
-int register_idle_notifier(struct notifier_block *nb)
-{
-       return atomic_notifier_chain_register(&idle_chain, nb);
-}
-EXPORT_SYMBOL(register_idle_notifier);
-
-int unregister_idle_notifier(struct notifier_block *nb)
-{
-       return atomic_notifier_chain_unregister(&idle_chain, nb);
-}
-EXPORT_SYMBOL(unregister_idle_notifier);
-
 static int s390_idle_enter(void)
 {
        struct s390_idle_data *idle;
-       int nr_calls = 0;
-       void *hcpu;
-       int rc;
 
-       hcpu = (void *)(long)smp_processor_id();
-       rc = __atomic_notifier_call_chain(&idle_chain, S390_CPU_IDLE, hcpu, -1,
-                                         &nr_calls);
-       if (rc == NOTIFY_BAD) {
-               nr_calls--;
-               __atomic_notifier_call_chain(&idle_chain, S390_CPU_NOT_IDLE,
-                                            hcpu, nr_calls, NULL);
-               return rc;
-       }
        idle = &__get_cpu_var(s390_idle);
        spin_lock(&idle->lock);
        idle->idle_count++;
        idle->in_idle = 1;
        idle->idle_enter = get_clock();
        spin_unlock(&idle->lock);
+       vtime_stop_cpu_timer();
        return NOTIFY_OK;
 }
 
@@ -122,13 +95,12 @@ void s390_idle_leave(void)
 {
        struct s390_idle_data *idle;
 
+       vtime_start_cpu_timer();
        idle = &__get_cpu_var(s390_idle);
        spin_lock(&idle->lock);
        idle->idle_time += get_clock() - idle->idle_enter;
        idle->in_idle = 0;
        spin_unlock(&idle->lock);
-       atomic_notifier_call_chain(&idle_chain, S390_CPU_NOT_IDLE,
-                                  (void *)(long) smp_processor_id());
 }
 
 extern void s390_handle_mcck(void);
index 35827b9..2815bfe 100644 (file)
@@ -33,6 +33,8 @@
 #include <linux/security.h>
 #include <linux/audit.h>
 #include <linux/signal.h>
+#include <linux/elf.h>
+#include <linux/regset.h>
 
 #include <asm/segment.h>
 #include <asm/page.h>
 #include "compat_ptrace.h"
 #endif
 
+enum s390_regset {
+       REGSET_GENERAL,
+       REGSET_FP,
+};
+
 static void
 FixPerRegisters(struct task_struct *task)
 {
@@ -126,24 +133,10 @@ ptrace_disable(struct task_struct *child)
  * struct user contain pad bytes that should be read as zeroes.
  * Lovely...
  */
-static int
-peek_user(struct task_struct *child, addr_t addr, addr_t data)
+static unsigned long __peek_user(struct task_struct *child, addr_t addr)
 {
        struct user *dummy = NULL;
-       addr_t offset, tmp, mask;
-
-       /*
-        * Stupid gdb peeks/pokes the access registers in 64 bit with
-        * an alignment of 4. Programmers from hell...
-        */
-       mask = __ADDR_MASK;
-#ifdef CONFIG_64BIT
-       if (addr >= (addr_t) &dummy->regs.acrs &&
-           addr < (addr_t) &dummy->regs.orig_gpr2)
-               mask = 3;
-#endif
-       if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
-               return -EIO;
+       addr_t offset, tmp;
 
        if (addr < (addr_t) &dummy->regs.acrs) {
                /*
@@ -197,24 +190,18 @@ peek_user(struct task_struct *child, addr_t addr, addr_t data)
        } else
                tmp = 0;
 
-       return put_user(tmp, (addr_t __user *) data);
+       return tmp;
 }
 
-/*
- * Write a word to the user area of a process at location addr. This
- * operation does have an additional problem compared to peek_user.
- * Stores to the program status word and on the floating point
- * control register needs to get checked for validity.
- */
 static int
-poke_user(struct task_struct *child, addr_t addr, addr_t data)
+peek_user(struct task_struct *child, addr_t addr, addr_t data)
 {
        struct user *dummy = NULL;
-       addr_t offset, mask;
+       addr_t tmp, mask;
 
        /*
         * Stupid gdb peeks/pokes the access registers in 64 bit with
-        * an alignment of 4. Programmers from hell indeed...
+        * an alignment of 4. Programmers from hell...
         */
        mask = __ADDR_MASK;
 #ifdef CONFIG_64BIT
@@ -225,6 +212,21 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
        if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
                return -EIO;
 
+       tmp = __peek_user(child, addr);
+       return put_user(tmp, (addr_t __user *) data);
+}
+
+/*
+ * Write a word to the user area of a process at location addr. This
+ * operation does have an additional problem compared to peek_user.
+ * Stores to the program status word and on the floating point
+ * control register needs to get checked for validity.
+ */
+static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
+{
+       struct user *dummy = NULL;
+       addr_t offset;
+
        if (addr < (addr_t) &dummy->regs.acrs) {
                /*
                 * psw and gprs are stored on the stack
@@ -292,6 +294,28 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
        return 0;
 }
 
+static int
+poke_user(struct task_struct *child, addr_t addr, addr_t data)
+{
+       struct user *dummy = NULL;
+       addr_t mask;
+
+       /*
+        * Stupid gdb peeks/pokes the access registers in 64 bit with
+        * an alignment of 4. Programmers from hell indeed...
+        */
+       mask = __ADDR_MASK;
+#ifdef CONFIG_64BIT
+       if (addr >= (addr_t) &dummy->regs.acrs &&
+           addr < (addr_t) &dummy->regs.orig_gpr2)
+               mask = 3;
+#endif
+       if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
+               return -EIO;
+
+       return __poke_user(child, addr, data);
+}
+
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
        ptrace_area parea; 
@@ -367,18 +391,13 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 /*
  * Same as peek_user but for a 31 bit program.
  */
-static int
-peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
+static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
 {
        struct user32 *dummy32 = NULL;
        per_struct32 *dummy_per32 = NULL;
        addr_t offset;
        __u32 tmp;
 
-       if (!test_thread_flag(TIF_31BIT) ||
-           (addr & 3) || addr > sizeof(struct user) - 3)
-               return -EIO;
-
        if (addr < (addr_t) &dummy32->regs.acrs) {
                /*
                 * psw and gprs are stored on the stack
@@ -435,25 +454,32 @@ peek_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
        } else
                tmp = 0;
 
+       return tmp;
+}
+
+static int peek_user_compat(struct task_struct *child,
+                           addr_t addr, addr_t data)
+{
+       __u32 tmp;
+
+       if (!test_thread_flag(TIF_31BIT) ||
+           (addr & 3) || addr > sizeof(struct user) - 3)
+               return -EIO;
+
+       tmp = __peek_user_compat(child, addr);
        return put_user(tmp, (__u32 __user *) data);
 }
 
 /*
  * Same as poke_user but for a 31 bit program.
  */
-static int
-poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
+static int __poke_user_compat(struct task_struct *child,
+                             addr_t addr, addr_t data)
 {
        struct user32 *dummy32 = NULL;
        per_struct32 *dummy_per32 = NULL;
+       __u32 tmp = (__u32) data;
        addr_t offset;
-       __u32 tmp;
-
-       if (!test_thread_flag(TIF_31BIT) ||
-           (addr & 3) || addr > sizeof(struct user32) - 3)
-               return -EIO;
-
-       tmp = (__u32) data;
 
        if (addr < (addr_t) &dummy32->regs.acrs) {
                /*
@@ -528,6 +554,16 @@ poke_user_emu31(struct task_struct *child, addr_t addr, addr_t data)
        return 0;
 }
 
+static int poke_user_compat(struct task_struct *child,
+                           addr_t addr, addr_t data)
+{
+       if (!test_thread_flag(TIF_31BIT) ||
+           (addr & 3) || addr > sizeof(struct user32) - 3)
+               return -EIO;
+
+       return __poke_user_compat(child, addr, data);
+}
+
 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
                        compat_ulong_t caddr, compat_ulong_t cdata)
 {
@@ -539,11 +575,11 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
        switch (request) {
        case PTRACE_PEEKUSR:
                /* read the word at location addr in the USER area. */
-               return peek_user_emu31(child, addr, data);
+               return peek_user_compat(child, addr, data);
 
        case PTRACE_POKEUSR:
                /* write the word at location addr in the USER area */
-               return poke_user_emu31(child, addr, data);
+               return poke_user_compat(child, addr, data);
 
        case PTRACE_PEEKUSR_AREA:
        case PTRACE_POKEUSR_AREA:
@@ -555,13 +591,13 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
                copied = 0;
                while (copied < parea.len) {
                        if (request == PTRACE_PEEKUSR_AREA)
-                               ret = peek_user_emu31(child, addr, data);
+                               ret = peek_user_compat(child, addr, data);
                        else {
                                __u32 utmp;
                                if (get_user(utmp,
                                             (__u32 __force __user *) data))
                                        return -EFAULT;
-                               ret = poke_user_emu31(child, addr, utmp);
+                               ret = poke_user_compat(child, addr, utmp);
                        }
                        if (ret)
                                return ret;
@@ -610,3 +646,240 @@ syscall_trace(struct pt_regs *regs, int entryexit)
                                    regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
                                    regs->gprs[4], regs->gprs[5]);
 }
+
+/*
+ * user_regset definitions.
+ */
+
+static int s390_regs_get(struct task_struct *target,
+                        const struct user_regset *regset,
+                        unsigned int pos, unsigned int count,
+                        void *kbuf, void __user *ubuf)
+{
+       if (target == current)
+               save_access_regs(target->thread.acrs);
+
+       if (kbuf) {
+               unsigned long *k = kbuf;
+               while (count > 0) {
+                       *k++ = __peek_user(target, pos);
+                       count -= sizeof(*k);
+                       pos += sizeof(*k);
+               }
+       } else {
+               unsigned long __user *u = ubuf;
+               while (count > 0) {
+                       if (__put_user(__peek_user(target, pos), u++))
+                               return -EFAULT;
+                       count -= sizeof(*u);
+                       pos += sizeof(*u);
+               }
+       }
+       return 0;
+}
+
+static int s390_regs_set(struct task_struct *target,
+                        const struct user_regset *regset,
+                        unsigned int pos, unsigned int count,
+                        const void *kbuf, const void __user *ubuf)
+{
+       int rc = 0;
+
+       if (target == current)
+               save_access_regs(target->thread.acrs);
+
+       if (kbuf) {
+               const unsigned long *k = kbuf;
+               while (count > 0 && !rc) {
+                       rc = __poke_user(target, pos, *k++);
+                       count -= sizeof(*k);
+                       pos += sizeof(*k);
+               }
+       } else {
+               const unsigned long  __user *u = ubuf;
+               while (count > 0 && !rc) {
+                       unsigned long word;
+                       rc = __get_user(word, u++);
+                       if (rc)
+                               break;
+                       rc = __poke_user(target, pos, word);
+                       count -= sizeof(*u);
+                       pos += sizeof(*u);
+               }
+       }
+
+       if (rc == 0 && target == current)
+               restore_access_regs(target->thread.acrs);
+
+       return rc;
+}
+
+static int s390_fpregs_get(struct task_struct *target,
+                          const struct user_regset *regset, unsigned int pos,
+                          unsigned int count, void *kbuf, void __user *ubuf)
+{
+       if (target == current)
+               save_fp_regs(&target->thread.fp_regs);
+
+       return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                  &target->thread.fp_regs, 0, -1);
+}
+
+static int s390_fpregs_set(struct task_struct *target,
+                          const struct user_regset *regset, unsigned int pos,
+                          unsigned int count, const void *kbuf,
+                          const void __user *ubuf)
+{
+       int rc = 0;
+
+       if (target == current)
+               save_fp_regs(&target->thread.fp_regs);
+
+       /* If setting FPC, must validate it first. */
+       if (count > 0 && pos < offsetof(s390_fp_regs, fprs)) {
+               u32 fpc[2] = { target->thread.fp_regs.fpc, 0 };
+               rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &fpc,
+                                       0, offsetof(s390_fp_regs, fprs));
+               if (rc)
+                       return rc;
+               if ((fpc[0] & ~FPC_VALID_MASK) != 0 || fpc[1] != 0)
+                       return -EINVAL;
+               target->thread.fp_regs.fpc = fpc[0];
+       }
+
+       if (rc == 0 && count > 0)
+               rc = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                       target->thread.fp_regs.fprs,
+                                       offsetof(s390_fp_regs, fprs), -1);
+
+       if (rc == 0 && target == current)
+               restore_fp_regs(&target->thread.fp_regs);
+
+       return rc;
+}
+
+static const struct user_regset s390_regsets[] = {
+       [REGSET_GENERAL] = {
+               .core_note_type = NT_PRSTATUS,
+               .n = sizeof(s390_regs) / sizeof(long),
+               .size = sizeof(long),
+               .align = sizeof(long),
+               .get = s390_regs_get,
+               .set = s390_regs_set,
+       },
+       [REGSET_FP] = {
+               .core_note_type = NT_PRFPREG,
+               .n = sizeof(s390_fp_regs) / sizeof(long),
+               .size = sizeof(long),
+               .align = sizeof(long),
+               .get = s390_fpregs_get,
+               .set = s390_fpregs_set,
+       },
+};
+
+static const struct user_regset_view user_s390_view = {
+       .name = UTS_MACHINE,
+       .e_machine = EM_S390,
+       .regsets = s390_regsets,
+       .n = ARRAY_SIZE(s390_regsets)
+};
+
+#ifdef CONFIG_COMPAT
+static int s390_compat_regs_get(struct task_struct *target,
+                               const struct user_regset *regset,
+                               unsigned int pos, unsigned int count,
+                               void *kbuf, void __user *ubuf)
+{
+       if (target == current)
+               save_access_regs(target->thread.acrs);
+
+       if (kbuf) {
+               compat_ulong_t *k = kbuf;
+               while (count > 0) {
+                       *k++ = __peek_user_compat(target, pos);
+                       count -= sizeof(*k);
+                       pos += sizeof(*k);
+               }
+       } else {
+               compat_ulong_t __user *u = ubuf;
+               while (count > 0) {
+                       if (__put_user(__peek_user_compat(target, pos), u++))
+                               return -EFAULT;
+                       count -= sizeof(*u);
+                       pos += sizeof(*u);
+               }
+       }
+       return 0;
+}
+
+static int s390_compat_regs_set(struct task_struct *target,
+                               const struct user_regset *regset,
+                               unsigned int pos, unsigned int count,
+                               const void *kbuf, const void __user *ubuf)
+{
+       int rc = 0;
+
+       if (target == current)
+               save_access_regs(target->thread.acrs);
+
+       if (kbuf) {
+               const compat_ulong_t *k = kbuf;
+               while (count > 0 && !rc) {
+                       rc = __poke_user_compat(target, pos, *k++);
+                       count -= sizeof(*k);
+                       pos += sizeof(*k);
+               }
+       } else {
+               const compat_ulong_t  __user *u = ubuf;
+               while (count > 0 && !rc) {
+                       compat_ulong_t word;
+                       rc = __get_user(word, u++);
+                       if (rc)
+                               break;
+                       rc = __poke_user_compat(target, pos, word);
+                       count -= sizeof(*u);
+                       pos += sizeof(*u);
+               }
+       }
+
+       if (rc == 0 && target == current)
+               restore_access_regs(target->thread.acrs);
+
+       return rc;
+}
+
+static const struct user_regset s390_compat_regsets[] = {
+       [REGSET_GENERAL] = {
+               .core_note_type = NT_PRSTATUS,
+               .n = sizeof(s390_compat_regs) / sizeof(compat_long_t),
+               .size = sizeof(compat_long_t),
+               .align = sizeof(compat_long_t),
+               .get = s390_compat_regs_get,
+               .set = s390_compat_regs_set,
+       },
+       [REGSET_FP] = {
+               .core_note_type = NT_PRFPREG,
+               .n = sizeof(s390_fp_regs) / sizeof(compat_long_t),
+               .size = sizeof(compat_long_t),
+               .align = sizeof(compat_long_t),
+               .get = s390_fpregs_get,
+               .set = s390_fpregs_set,
+       },
+};
+
+static const struct user_regset_view user_s390_compat_view = {
+       .name = "s390",
+       .e_machine = EM_S390,
+       .regsets = s390_compat_regsets,
+       .n = ARRAY_SIZE(s390_compat_regsets)
+};
+#endif
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_COMPAT
+       if (test_tsk_thread_flag(task, TIF_31BIT))
+               return &user_s390_compat_view;
+#endif
+       return &user_s390_view;
+}
index 2bc70b6..b358e18 100644 (file)
@@ -77,7 +77,7 @@ unsigned long machine_flags;
 unsigned long elf_hwcap = 0;
 char elf_platform[ELF_PLATFORM_SIZE];
 
-struct mem_chunk __meminitdata memory_chunk[MEMORY_CHUNKS];
+struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
 static unsigned long __initdata memory_end;
 
@@ -205,12 +205,6 @@ static void __init conmode_default(void)
                        SET_CONSOLE_SCLP;
 #endif
                }
-        } else if (MACHINE_IS_P390) {
-#if defined(CONFIG_TN3215_CONSOLE)
-               SET_CONSOLE_3215;
-#elif defined(CONFIG_TN3270_CONSOLE)
-               SET_CONSOLE_3270;
-#endif
        } else {
 #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
                SET_CONSOLE_SCLP;
@@ -221,18 +215,17 @@ static void __init conmode_default(void)
 #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
 static void __init setup_zfcpdump(unsigned int console_devno)
 {
-       static char str[64];
+       static char str[41];
 
        if (ipl_info.type != IPL_TYPE_FCP_DUMP)
                return;
        if (console_devno != -1)
-               sprintf(str, "cio_ignore=all,!0.0.%04x,!0.0.%04x",
+               sprintf(str, " cio_ignore=all,!0.0.%04x,!0.0.%04x",
                        ipl_info.data.fcp.dev_id.devno, console_devno);
        else
-               sprintf(str, "cio_ignore=all,!0.0.%04x",
+               sprintf(str, " cio_ignore=all,!0.0.%04x",
                        ipl_info.data.fcp.dev_id.devno);
-       strcat(COMMAND_LINE, " ");
-       strcat(COMMAND_LINE, str);
+       strcat(boot_command_line, str);
        console_loglevel = 2;
 }
 #else
@@ -289,32 +282,6 @@ static int __init early_parse_mem(char *p)
 }
 early_param("mem", early_parse_mem);
 
-/*
- * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
- */
-static int __init early_parse_ipldelay(char *p)
-{
-       unsigned long delay = 0;
-
-       delay = simple_strtoul(p, &p, 0);
-
-       switch (*p) {
-       case 's':
-       case 'S':
-               delay *= 1000000;
-               break;
-       case 'm':
-       case 'M':
-               delay *= 60 * 1000000;
-       }
-
-       /* now wait for the requested amount of time */
-       udelay(delay);
-
-       return 0;
-}
-early_param("ipldelay", early_parse_ipldelay);
-
 #ifdef CONFIG_S390_SWITCH_AMODE
 #ifdef CONFIG_PGSTE
 unsigned int switch_amode = 1;
@@ -804,11 +771,9 @@ setup_arch(char **cmdline_p)
                printk("We are running native (64 bit mode)\n");
 #endif /* CONFIG_64BIT */
 
-       /* Save unparsed command line copy for /proc/cmdline */
-       strlcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
-
-       *cmdline_p = COMMAND_LINE;
-       *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
+       /* Have one command line that is parsed and saved in /proc/cmdline */
+       /* boot_command_line has been already set up in early.c */
+       *cmdline_p = boot_command_line;
 
         ROOT_DEV = Root_RAM0;
 
index 7aec676..7418beb 100644 (file)
@@ -3,7 +3,7 @@
  *    Time of day based timer functions.
  *
  *  S390 version
- *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ *    Copyright IBM Corp. 1999, 2008
  *    Author(s): Hartmut Penner (hp@de.ibm.com),
  *               Martin Schwidefsky (schwidefsky@de.ibm.com),
  *               Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
@@ -31,6 +31,7 @@
 #include <linux/notifier.h>
 #include <linux/clocksource.h>
 #include <linux/clockchips.h>
+#include <linux/bootmem.h>
 #include <asm/uaccess.h>
 #include <asm/delay.h>
 #include <asm/s390_ext.h>
@@ -162,7 +163,7 @@ void init_cpu_timer(void)
        /* Enable clock comparator timer interrupt. */
        __ctl_set_bit(0,11);
 
-       /* Always allow ETR external interrupts, even without an ETR. */
+       /* Always allow the timing alert external interrupt. */
        __ctl_set_bit(0, 4);
 }
 
@@ -170,8 +171,21 @@ static void clock_comparator_interrupt(__u16 code)
 {
 }
 
+static void etr_timing_alert(struct etr_irq_parm *);
+static void stp_timing_alert(struct stp_irq_parm *);
+
+static void timing_alert_interrupt(__u16 code)
+{
+       if (S390_lowcore.ext_params & 0x00c40000)
+               etr_timing_alert((struct etr_irq_parm *)
+                                &S390_lowcore.ext_params);
+       if (S390_lowcore.ext_params & 0x00038000)
+               stp_timing_alert((struct stp_irq_parm *)
+                                &S390_lowcore.ext_params);
+}
+
 static void etr_reset(void);
-static void etr_ext_handler(__u16);
+static void stp_reset(void);
 
 /*
  * Get the TOD clock running.
@@ -181,6 +195,7 @@ static u64 __init reset_tod_clock(void)
        u64 time;
 
        etr_reset();
+       stp_reset();
        if (store_clock(&time) == 0)
                return time;
        /* TOD clock not running. Set the clock to Unix Epoch. */
@@ -231,8 +246,9 @@ void __init time_init(void)
        if (clocksource_register(&clocksource_tod) != 0)
                panic("Could not register TOD clock source");
 
-       /* request the etr external interrupt */
-       if (register_early_external_interrupt(0x1406, etr_ext_handler,
+       /* request the timing alert external interrupt */
+       if (register_early_external_interrupt(0x1406,
+                                             timing_alert_interrupt,
                                              &ext_int_etr_cc) != 0)
                panic("Couldn't request external interrupt 0x1406");
 
@@ -244,11 +260,113 @@ void __init time_init(void)
 #endif
 }
 
+/*
+ * The time is "clock". old is what we think the time is.
+ * Adjust the value by a multiple of jiffies and add the delta to ntp.
+ * "delay" is an approximation how long the synchronization took. If
+ * the time correction is positive, then "delay" is subtracted from
+ * the time difference and only the remaining part is passed to ntp.
+ */
+static unsigned long long adjust_time(unsigned long long old,
+                                     unsigned long long clock,
+                                     unsigned long long delay)
+{
+       unsigned long long delta, ticks;
+       struct timex adjust;
+
+       if (clock > old) {
+               /* It is later than we thought. */
+               delta = ticks = clock - old;
+               delta = ticks = (delta < delay) ? 0 : delta - delay;
+               delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
+               adjust.offset = ticks * (1000000 / HZ);
+       } else {
+               /* It is earlier than we thought. */
+               delta = ticks = old - clock;
+               delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
+               delta = -delta;
+               adjust.offset = -ticks * (1000000 / HZ);
+       }
+       jiffies_timer_cc += delta;
+       if (adjust.offset != 0) {
+               printk(KERN_NOTICE "etr: time adjusted by %li micro-seconds\n",
+                      adjust.offset);
+               adjust.modes = ADJ_OFFSET_SINGLESHOT;
+               do_adjtimex(&adjust);
+       }
+       return delta;
+}
+
+static DEFINE_PER_CPU(atomic_t, clock_sync_word);
+static unsigned long clock_sync_flags;
+
+#define CLOCK_SYNC_HAS_ETR     0
+#define CLOCK_SYNC_HAS_STP     1
+#define CLOCK_SYNC_ETR         2
+#define CLOCK_SYNC_STP         3
+
+/*
+ * The synchronous get_clock function. It will write the current clock
+ * value to the clock pointer and return 0 if the clock is in sync with
+ * the external time source. If the clock mode is local it will return
+ * -ENOSYS and -EAGAIN if the clock is not in sync with the external
+ * reference.
+ */
+int get_sync_clock(unsigned long long *clock)
+{
+       atomic_t *sw_ptr;
+       unsigned int sw0, sw1;
+
+       sw_ptr = &get_cpu_var(clock_sync_word);
+       sw0 = atomic_read(sw_ptr);
+       *clock = get_clock();
+       sw1 = atomic_read(sw_ptr);
+       put_cpu_var(clock_sync_sync);
+       if (sw0 == sw1 && (sw0 & 0x80000000U))
+               /* Success: time is in sync. */
+               return 0;
+       if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags) &&
+           !test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
+               return -ENOSYS;
+       if (!test_bit(CLOCK_SYNC_ETR, &clock_sync_flags) &&
+           !test_bit(CLOCK_SYNC_STP, &clock_sync_flags))
+               return -EACCES;
+       return -EAGAIN;
+}
+EXPORT_SYMBOL(get_sync_clock);
+
+/*
+ * Make get_sync_clock return -EAGAIN.
+ */
+static void disable_sync_clock(void *dummy)
+{
+       atomic_t *sw_ptr = &__get_cpu_var(clock_sync_word);
+       /*
+        * Clear the in-sync bit 2^31. All get_sync_clock calls will
+        * fail until the sync bit is turned back on. In addition
+        * increase the "sequence" counter to avoid the race of an
+        * etr event and the complete recovery against get_sync_clock.
+        */
+       atomic_clear_mask(0x80000000, sw_ptr);
+       atomic_inc(sw_ptr);
+}
+
+/*
+ * Make get_sync_clock return 0 again.
+ * Needs to be called from a context disabled for preemption.
+ */
+static void enable_sync_clock(void)
+{
+       atomic_t *sw_ptr = &__get_cpu_var(clock_sync_word);
+       atomic_set_mask(0x80000000, sw_ptr);
+}
+
 /*
  * External Time Reference (ETR) code.
  */
 static int etr_port0_online;
 static int etr_port1_online;
+static int etr_steai_available;
 
 static int __init early_parse_etr(char *p)
 {
@@ -273,12 +391,6 @@ enum etr_event {
        ETR_EVENT_UPDATE,
 };
 
-enum etr_flags {
-       ETR_FLAG_ENOSYS,
-       ETR_FLAG_EACCES,
-       ETR_FLAG_STEAI,
-};
-
 /*
  * Valid bit combinations of the eacr register are (x = don't care):
  * e0 e1 dp p0 p1 ea es sl
@@ -305,73 +417,17 @@ enum etr_flags {
  */
 static struct etr_eacr etr_eacr;
 static u64 etr_tolec;                  /* time of last eacr update */
-static unsigned long etr_flags;
 static struct etr_aib etr_port0;
 static int etr_port0_uptodate;
 static struct etr_aib etr_port1;
 static int etr_port1_uptodate;
 static unsigned long etr_events;
 static struct timer_list etr_timer;
-static DEFINE_PER_CPU(atomic_t, etr_sync_word);
 
 static void etr_timeout(unsigned long dummy);
 static void etr_work_fn(struct work_struct *work);
 static DECLARE_WORK(etr_work, etr_work_fn);
 
-/*
- * The etr get_clock function. It will write the current clock value
- * to the clock pointer and return 0 if the clock is in sync with the
- * external time source. If the clock mode is local it will return
- * -ENOSYS and -EAGAIN if the clock is not in sync with the external
- * reference. This function is what ETR is all about..
- */
-int get_sync_clock(unsigned long long *clock)
-{
-       atomic_t *sw_ptr;
-       unsigned int sw0, sw1;
-
-       sw_ptr = &get_cpu_var(etr_sync_word);
-       sw0 = atomic_read(sw_ptr);
-       *clock = get_clock();
-       sw1 = atomic_read(sw_ptr);
-       put_cpu_var(etr_sync_sync);
-       if (sw0 == sw1 && (sw0 & 0x80000000U))
-               /* Success: time is in sync. */
-               return 0;
-       if (test_bit(ETR_FLAG_ENOSYS, &etr_flags))
-               return -ENOSYS;
-       if (test_bit(ETR_FLAG_EACCES, &etr_flags))
-               return -EACCES;
-       return -EAGAIN;
-}
-EXPORT_SYMBOL(get_sync_clock);
-
-/*
- * Make get_sync_clock return -EAGAIN.
- */
-static void etr_disable_sync_clock(void *dummy)
-{
-       atomic_t *sw_ptr = &__get_cpu_var(etr_sync_word);
-       /*
-        * Clear the in-sync bit 2^31. All get_sync_clock calls will
-        * fail until the sync bit is turned back on. In addition
-        * increase the "sequence" counter to avoid the race of an
-        * etr event and the complete recovery against get_sync_clock.
-        */
-       atomic_clear_mask(0x80000000, sw_ptr);
-       atomic_inc(sw_ptr);
-}
-
-/*
- * Make get_sync_clock return 0 again.
- * Needs to be called from a context disabled for preemption.
- */
-static void etr_enable_sync_clock(void)
-{
-       atomic_t *sw_ptr = &__get_cpu_var(etr_sync_word);
-       atomic_set_mask(0x80000000, sw_ptr);
-}
-
 /*
  * Reset ETR attachment.
  */
@@ -381,15 +437,13 @@ static void etr_reset(void)
                .e0 = 0, .e1 = 0, ._pad0 = 4, .dp = 0,
                .p0 = 0, .p1 = 0, ._pad1 = 0, .ea = 0,
                .es = 0, .sl = 0 };
-       if (etr_setr(&etr_eacr) == 0)
+       if (etr_setr(&etr_eacr) == 0) {
                etr_tolec = get_clock();
-       else {
-               set_bit(ETR_FLAG_ENOSYS, &etr_flags);
-               if (etr_port0_online || etr_port1_online) {
-                       printk(KERN_WARNING "Running on non ETR capable "
-                              "machine, only local mode available.\n");
-                       etr_port0_online = etr_port1_online = 0;
-               }
+               set_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags);
+       } else if (etr_port0_online || etr_port1_online) {
+               printk(KERN_WARNING "Running on non ETR capable "
+                      "machine, only local mode available.\n");
+               etr_port0_online = etr_port1_online = 0;
        }
 }
 
@@ -397,14 +451,12 @@ static int __init etr_init(void)
 {
        struct etr_aib aib;
 
-       if (test_bit(ETR_FLAG_ENOSYS, &etr_flags))
+       if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags))
                return 0;
        /* Check if this machine has the steai instruction. */
        if (etr_steai(&aib, ETR_STEAI_STEPPING_PORT) == 0)
-               set_bit(ETR_FLAG_STEAI, &etr_flags);
+               etr_steai_available = 1;
        setup_timer(&etr_timer, etr_timeout, 0UL);
-       if (!etr_port0_online && !etr_port1_online)
-               set_bit(ETR_FLAG_EACCES, &etr_flags);
        if (etr_port0_online) {
                set_bit(ETR_EVENT_PORT0_CHANGE, &etr_events);
                schedule_work(&etr_work);
@@ -435,7 +487,8 @@ void etr_switch_to_local(void)
 {
        if (!etr_eacr.sl)
                return;
-       etr_disable_sync_clock(NULL);
+       if (test_bit(CLOCK_SYNC_ETR, &clock_sync_flags))
+               disable_sync_clock(NULL);
        set_bit(ETR_EVENT_SWITCH_LOCAL, &etr_events);
        schedule_work(&etr_work);
 }
@@ -450,23 +503,21 @@ void etr_sync_check(void)
 {
        if (!etr_eacr.es)
                return;
-       etr_disable_sync_clock(NULL);
+       if (test_bit(CLOCK_SYNC_ETR, &clock_sync_flags))
+               disable_sync_clock(NULL);
        set_bit(ETR_EVENT_SYNC_CHECK, &etr_events);
        schedule_work(&etr_work);
 }
 
 /*
- * ETR external interrupt. There are two causes:
+ * ETR timing alert. There are two causes:
  * 1) port state change, check the usability of the port
  * 2) port alert, one of the ETR-data-validity bits (v1-v2 bits of the
  *    sldr-status word) or ETR-data word 1 (edf1) or ETR-data word 3 (edf3)
  *    or ETR-data word 4 (edf4) has changed.
  */
-static void etr_ext_handler(__u16 code)
+static void etr_timing_alert(struct etr_irq_parm *intparm)
 {
-       struct etr_interruption_parameter *intparm =
-               (struct etr_interruption_parameter *) &S390_lowcore.ext_params;
-
        if (intparm->pc0)
                /* ETR port 0 state change. */
                set_bit(ETR_EVENT_PORT0_CHANGE, &etr_events);
@@ -591,58 +642,23 @@ static int etr_aib_follows(struct etr_aib *a1, struct etr_aib *a2, int p)
        return 1;
 }
 
-/*
- * The time is "clock". old is what we think the time is.
- * Adjust the value by a multiple of jiffies and add the delta to ntp.
- * "delay" is an approximation how long the synchronization took. If
- * the time correction is positive, then "delay" is subtracted from
- * the time difference and only the remaining part is passed to ntp.
- */
-static unsigned long long etr_adjust_time(unsigned long long old,
-                                         unsigned long long clock,
-                                         unsigned long long delay)
-{
-       unsigned long long delta, ticks;
-       struct timex adjust;
-
-       if (clock > old) {
-               /* It is later than we thought. */
-               delta = ticks = clock - old;
-               delta = ticks = (delta < delay) ? 0 : delta - delay;
-               delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
-               adjust.offset = ticks * (1000000 / HZ);
-       } else {
-               /* It is earlier than we thought. */
-               delta = ticks = old - clock;
-               delta -= do_div(ticks, CLK_TICKS_PER_JIFFY);
-               delta = -delta;
-               adjust.offset = -ticks * (1000000 / HZ);
-       }
-       jiffies_timer_cc += delta;
-       if (adjust.offset != 0) {
-               printk(KERN_NOTICE "etr: time adjusted by %li micro-seconds\n",
-                      adjust.offset);
-               adjust.modes = ADJ_OFFSET_SINGLESHOT;
-               do_adjtimex(&adjust);
-       }
-       return delta;
-}
-
-static struct {
+struct clock_sync_data {
        int in_sync;
        unsigned long long fixup_cc;
-} etr_sync;
+};
 
-static void etr_sync_cpu_start(void *dummy)
+static void clock_sync_cpu_start(void *dummy)
 {
-       etr_enable_sync_clock();
+       struct clock_sync_data *sync = dummy;
+
+       enable_sync_clock();
        /*
         * This looks like a busy wait loop but it isn't. etr_sync_cpus
         * is called on all other cpus while the TOD clocks is stopped.
         * __udelay will stop the cpu on an enabled wait psw until the
         * TOD is running again.
         */
-       while (etr_sync.in_sync == 0) {
+       while (sync->in_sync == 0) {
                __udelay(1);
                /*
                 * A different cpu changes *in_sync. Therefore use
@@ -650,17 +666,17 @@ static void etr_sync_cpu_start(void *dummy)
                 */
                barrier();
        }
-       if (etr_sync.in_sync != 1)
+       if (sync->in_sync != 1)
                /* Didn't work. Clear per-cpu in sync bit again. */
-               etr_disable_sync_clock(NULL);
+               disable_sync_clock(NULL);
        /*
         * This round of TOD syncing is done. Set the clock comparator
         * to the next tick and let the processor continue.
         */
-       fixup_clock_comparator(etr_sync.fixup_cc);
+       fixup_clock_comparator(sync->fixup_cc);
 }
 
-static void etr_sync_cpu_end(void *dummy)
+static void clock_sync_cpu_end(void *dummy)
 {
 }
 
@@ -672,6 +688,7 @@ static void etr_sync_cpu_end(void *dummy)
 static int etr_sync_clock(struct etr_aib *aib, int port)
 {
        struct etr_aib *sync_port;
+       struct clock_sync_data etr_sync;
        unsigned long long clock, old_clock, delay, delta;
        int follows;
        int rc;
@@ -690,9 +707,9 @@ static int etr_sync_clock(struct etr_aib *aib, int port)
         */
        memset(&etr_sync, 0, sizeof(etr_sync));
        preempt_disable();
-       smp_call_function(etr_sync_cpu_start, NULL, 0, 0);
+       smp_call_function(clock_sync_cpu_start, &etr_sync, 0, 0);
        local_irq_disable();
-       etr_enable_sync_clock();
+       enable_sync_clock();
 
        /* Set clock to next OTE. */
        __ctl_set_bit(14, 21);
@@ -707,13 +724,13 @@ static int etr_sync_clock(struct etr_aib *aib, int port)
                /* Adjust Linux timing variables. */
                delay = (unsigned long long)
                        (aib->edf2.etv - sync_port->edf2.etv) << 32;
-               delta = etr_adjust_time(old_clock, clock, delay);
+               delta = adjust_time(old_clock, clock, delay);
                etr_sync.fixup_cc = delta;
                fixup_clock_comparator(delta);
                /* Verify that the clock is properly set. */
                if (!etr_aib_follows(sync_port, aib, port)) {
                        /* Didn't work. */
-                       etr_disable_sync_clock(NULL);
+                       disable_sync_clock(NULL);
                        etr_sync.in_sync = -EAGAIN;
                        rc = -EAGAIN;
                } else {
@@ -724,12 +741,12 @@ static int etr_sync_clock(struct etr_aib *aib, int port)
                /* Could not set the clock ?!? */
                __ctl_clear_bit(0, 29);
                __ctl_clear_bit(14, 21);
-               etr_disable_sync_clock(NULL);
+               disable_sync_clock(NULL);
                etr_sync.in_sync = -EAGAIN;
                rc = -EAGAIN;
        }
        local_irq_enable();
-       smp_call_function(etr_sync_cpu_end,NULL,0,0);
+       smp_call_function(clock_sync_cpu_end, NULL, 0, 0);
        preempt_enable();
        return rc;
 }
@@ -832,7 +849,7 @@ static struct etr_eacr etr_handle_update(struct etr_aib *aib,
         * Do not try to get the alternate port aib if the clock
         * is not in sync yet.
         */
-       if (!eacr.es)
+       if (!test_bit(CLOCK_SYNC_STP, &clock_sync_flags) && !eacr.es)
                return eacr;
 
        /*
@@ -840,7 +857,7 @@ static struct etr_eacr etr_handle_update(struct etr_aib *aib,
         * the other port immediately. If only stetr is available the
         * data-port bit toggle has to be used.
         */
-       if (test_bit(ETR_FLAG_STEAI, &etr_flags)) {
+       if (etr_steai_available) {
                if (eacr.p0 && !etr_port0_uptodate) {
                        etr_steai_cv(&etr_port0, ETR_STEAI_PORT_0);
                        etr_port0_uptodate = 1;
@@ -909,10 +926,10 @@ static void etr_work_fn(struct work_struct *work)
        if (!eacr.ea) {
                /* Both ports offline. Reset everything. */
                eacr.dp = eacr.es = eacr.sl = 0;
-               on_each_cpu(etr_disable_sync_clock, NULL, 0, 1);
+               on_each_cpu(disable_sync_clock, NULL, 0, 1);
                del_timer_sync(&etr_timer);
                etr_update_eacr(eacr);
-               set_bit(ETR_FLAG_EACCES, &etr_flags);
+               clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
                return;
        }
 
@@ -953,7 +970,6 @@ static void etr_work_fn(struct work_struct *work)
                        eacr.e1 = 1;
                sync_port = (etr_port0_uptodate &&
                             etr_port_valid(&etr_port0, 0)) ? 0 : -1;
-               clear_bit(ETR_FLAG_EACCES, &etr_flags);
        } else if (eacr.p1 && aib.esw.psc1 == etr_lpsc_pps_mode) {
                eacr.sl = 0;
                eacr.e0 = 0;
@@ -962,7 +978,6 @@ static void etr_work_fn(struct work_struct *work)
                        eacr.es = 0;
                sync_port = (etr_port1_uptodate &&
                             etr_port_valid(&etr_port1, 1)) ? 1 : -1;
-               clear_bit(ETR_FLAG_EACCES, &etr_flags);
        } else if (eacr.p0 && aib.esw.psc0 == etr_lpsc_operational_step) {
                eacr.sl = 1;
                eacr.e0 = 1;
@@ -976,7 +991,6 @@ static void etr_work_fn(struct work_struct *work)
                        eacr.e1 = 1;
                sync_port = (etr_port0_uptodate &&
                             etr_port_valid(&etr_port0, 0)) ? 0 : -1;
-               clear_bit(ETR_FLAG_EACCES, &etr_flags);
        } else if (eacr.p1 && aib.esw.psc1 == etr_lpsc_operational_step) {
                eacr.sl = 1;
                eacr.e0 = 0;
@@ -985,19 +999,22 @@ static void etr_work_fn(struct work_struct *work)
                        eacr.es = 0;
                sync_port = (etr_port1_uptodate &&
                             etr_port_valid(&etr_port1, 1)) ? 1 : -1;
-               clear_bit(ETR_FLAG_EACCES, &etr_flags);
        } else {
                /* Both ports not usable. */
                eacr.es = eacr.sl = 0;
                sync_port = -1;
-               set_bit(ETR_FLAG_EACCES, &etr_flags);
+               clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
        }
 
+       if (!test_bit(CLOCK_SYNC_ETR, &clock_sync_flags))
+               eacr.es = 0;
+
        /*
         * If the clock is in sync just update the eacr and return.
         * If there is no valid sync port wait for a port update.
         */
-       if (eacr.es || sync_port < 0) {
+       if (test_bit(CLOCK_SYNC_STP, &clock_sync_flags) ||
+           eacr.es || sync_port < 0) {
                etr_update_eacr(eacr);
                etr_set_tolec_timeout(now);
                return;
@@ -1018,11 +1035,13 @@ static void etr_work_fn(struct work_struct *work)
         * and set up a timer to try again after 0.5 seconds
         */
        etr_update_eacr(eacr);
+       set_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
        if (now < etr_tolec + (1600000 << 12) ||
            etr_sync_clock(&aib, sync_port) != 0) {
                /* Sync failed. Try again in 1/2 second. */
                eacr.es = 0;
                etr_update_eacr(eacr);
+               clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags);
                etr_set_sync_timeout();
        } else
                etr_set_tolec_timeout(now);
@@ -1097,8 +1116,8 @@ static ssize_t etr_online_store(struct sys_device *dev,
        value = simple_strtoul(buf, NULL, 0);
        if (value != 0 && value != 1)
                return -EINVAL;
-       if (test_bit(ETR_FLAG_ENOSYS, &etr_flags))
-               return -ENOSYS;
+       if (!test_bit(CLOCK_SYNC_HAS_ETR, &clock_sync_flags))
+               return -EOPNOTSUPP;
        if (dev == &etr_port0_dev) {
                if (etr_port0_online == value)
                        return count;   /* Nothing to do. */
@@ -1292,3 +1311,318 @@ out:
 }
 
 device_initcall(etr_init_sysfs);
+
+/*
+ * Server Time Protocol (STP) code.
+ */
+static int stp_online;
+static struct stp_sstpi stp_info;
+static void *stp_page;
+
+static void stp_work_fn(struct work_struct *work);
+static DECLARE_WORK(stp_work, stp_work_fn);
+
+static int __init early_parse_stp(char *p)
+{
+       if (strncmp(p, "off", 3) == 0)
+               stp_online = 0;
+       else if (strncmp(p, "on", 2) == 0)
+               stp_online = 1;
+       return 0;
+}
+early_param("stp", early_parse_stp);
+
+/*
+ * Reset STP attachment.
+ */
+static void stp_reset(void)
+{
+       int rc;
+
+       stp_page = alloc_bootmem_pages(PAGE_SIZE);
+       rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000);
+       if (rc == 1)
+               set_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags);
+       else if (stp_online) {
+               printk(KERN_WARNING "Running on non STP capable machine.\n");
+               free_bootmem((unsigned long) stp_page, PAGE_SIZE);
+               stp_page = NULL;
+               stp_online = 0;
+       }
+}
+
+static int __init stp_init(void)
+{
+       if (test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags) && stp_online)
+               schedule_work(&stp_work);
+       return 0;
+}
+
+arch_initcall(stp_init);
+
+/*
+ * STP timing alert. There are three causes:
+ * 1) timing status change
+ * 2) link availability change
+ * 3) time control parameter change
+ * In all three cases we are only interested in the clock source state.
+ * If a STP clock source is now available use it.
+ */
+static void stp_timing_alert(struct stp_irq_parm *intparm)
+{
+       if (intparm->tsc || intparm->lac || intparm->tcpc)
+               schedule_work(&stp_work);
+}
+
+/*
+ * STP sync check machine check. This is called when the timing state
+ * changes from the synchronized state to the unsynchronized state.
+ * After a STP sync check the clock is not in sync. The machine check
+ * is broadcasted to all cpus at the same time.
+ */
+void stp_sync_check(void)
+{
+       if (!test_bit(CLOCK_SYNC_STP, &clock_sync_flags))
+               return;
+       disable_sync_clock(NULL);
+       schedule_work(&stp_work);
+}
+
+/*
+ * STP island condition machine check. This is called when an attached
+ * server  attempts to communicate over an STP link and the servers
+ * have matching CTN ids and have a valid stratum-1 configuration
+ * but the configurations do not match.
+ */
+void stp_island_check(void)
+{
+       if (!test_bit(CLOCK_SYNC_STP, &clock_sync_flags))
+               return;
+       disable_sync_clock(NULL);
+       schedule_work(&stp_work);
+}
+
+/*
+ * STP tasklet. Check for the STP state and take over the clock
+ * synchronization if the STP clock source is usable.
+ */
+static void stp_work_fn(struct work_struct *work)
+{
+       struct clock_sync_data stp_sync;
+       unsigned long long old_clock, delta;
+       int rc;
+
+       if (!stp_online) {
+               chsc_sstpc(stp_page, STP_OP_CTRL, 0x0000);
+               return;
+       }
+
+       rc = chsc_sstpc(stp_page, STP_OP_CTRL, 0xb0e0);
+       if (rc)
+               return;
+
+       rc = chsc_sstpi(stp_page, &stp_info, sizeof(struct stp_sstpi));
+       if (rc || stp_info.c == 0)
+               return;
+
+       /*
+        * Catch all other cpus and make them wait until we have
+        * successfully synced the clock. smp_call_function will
+        * return after all other cpus are in clock_sync_cpu_start.
+        */
+       memset(&stp_sync, 0, sizeof(stp_sync));
+       preempt_disable();
+       smp_call_function(clock_sync_cpu_start, &stp_sync, 0, 0);
+       local_irq_disable();
+       enable_sync_clock();
+
+       set_bit(CLOCK_SYNC_STP, &clock_sync_flags);
+       if (test_and_clear_bit(CLOCK_SYNC_ETR, &clock_sync_flags))
+               schedule_work(&etr_work);
+
+       rc = 0;
+       if (stp_info.todoff[0] || stp_info.todoff[1] ||
+           stp_info.todoff[2] || stp_info.todoff[3] ||
+           stp_info.tmd != 2) {
+               old_clock = get_clock();
+               rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0);
+               if (rc == 0) {
+                       delta = adjust_time(old_clock, get_clock(), 0);
+                       fixup_clock_comparator(delta);
+                       rc = chsc_sstpi(stp_page, &stp_info,
+                                       sizeof(struct stp_sstpi));
+                       if (rc == 0 && stp_info.tmd != 2)
+                               rc = -EAGAIN;
+               }
+       }
+       if (rc) {
+               disable_sync_clock(NULL);
+               stp_sync.in_sync = -EAGAIN;
+               clear_bit(CLOCK_SYNC_STP, &clock_sync_flags);
+               if (etr_port0_online || etr_port1_online)
+                       schedule_work(&etr_work);
+       } else
+               stp_sync.in_sync = 1;
+
+       local_irq_enable();
+       smp_call_function(clock_sync_cpu_end, NULL, 0, 0);
+       preempt_enable();
+}
+
+/*
+ * STP class sysfs interface functions
+ */
+static struct sysdev_class stp_sysclass = {
+       .name   = "stp",
+};
+
+static ssize_t stp_ctn_id_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online)
+               return -ENODATA;
+       return sprintf(buf, "%016llx\n",
+                      *(unsigned long long *) stp_info.ctnid);
+}
+
+static SYSDEV_CLASS_ATTR(ctn_id, 0400, stp_ctn_id_show, NULL);
+
+static ssize_t stp_ctn_type_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online)
+               return -ENODATA;
+       return sprintf(buf, "%i\n", stp_info.ctn);
+}
+
+static SYSDEV_CLASS_ATTR(ctn_type, 0400, stp_ctn_type_show, NULL);
+
+static ssize_t stp_dst_offset_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online || !(stp_info.vbits & 0x2000))
+               return -ENODATA;
+       return sprintf(buf, "%i\n", (int)(s16) stp_info.dsto);
+}
+
+static SYSDEV_CLASS_ATTR(dst_offset, 0400, stp_dst_offset_show, NULL);
+
+static ssize_t stp_leap_seconds_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online || !(stp_info.vbits & 0x8000))
+               return -ENODATA;
+       return sprintf(buf, "%i\n", (int)(s16) stp_info.leaps);
+}
+
+static SYSDEV_CLASS_ATTR(leap_seconds, 0400, stp_leap_seconds_show, NULL);
+
+static ssize_t stp_stratum_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online)
+               return -ENODATA;
+       return sprintf(buf, "%i\n", (int)(s16) stp_info.stratum);
+}
+
+static SYSDEV_CLASS_ATTR(stratum, 0400, stp_stratum_show, NULL);
+
+static ssize_t stp_time_offset_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online || !(stp_info.vbits & 0x0800))
+               return -ENODATA;
+       return sprintf(buf, "%i\n", (int) stp_info.tto);
+}
+
+static SYSDEV_CLASS_ATTR(time_offset, 0400, stp_time_offset_show, NULL);
+
+static ssize_t stp_time_zone_offset_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online || !(stp_info.vbits & 0x4000))
+               return -ENODATA;
+       return sprintf(buf, "%i\n", (int)(s16) stp_info.tzo);
+}
+
+static SYSDEV_CLASS_ATTR(time_zone_offset, 0400,
+                        stp_time_zone_offset_show, NULL);
+
+static ssize_t stp_timing_mode_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online)
+               return -ENODATA;
+       return sprintf(buf, "%i\n", stp_info.tmd);
+}
+
+static SYSDEV_CLASS_ATTR(timing_mode, 0400, stp_timing_mode_show, NULL);
+
+static ssize_t stp_timing_state_show(struct sysdev_class *class, char *buf)
+{
+       if (!stp_online)
+               return -ENODATA;
+       return sprintf(buf, "%i\n", stp_info.tst);
+}
+
+static SYSDEV_CLASS_ATTR(timing_state, 0400, stp_timing_state_show, NULL);
+
+static ssize_t stp_online_show(struct sysdev_class *class, char *buf)
+{
+       return sprintf(buf, "%i\n", stp_online);
+}
+
+static ssize_t stp_online_store(struct sysdev_class *class,
+                               const char *buf, size_t count)
+{
+       unsigned int value;
+
+       value = simple_strtoul(buf, NULL, 0);
+       if (value != 0 && value != 1)
+               return -EINVAL;
+       if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
+               return -EOPNOTSUPP;
+       stp_online = value;
+       schedule_work(&stp_work);
+       return count;
+}
+
+/*
+ * Can't use SYSDEV_CLASS_ATTR because the attribute should be named
+ * stp/online but attr_online already exists in this file ..
+ */
+static struct sysdev_class_attribute attr_stp_online = {
+       .attr = { .name = "online", .mode = 0600 },
+       .show   = stp_online_show,
+       .store  = stp_online_store,
+};
+
+static struct sysdev_class_attribute *stp_attributes[] = {
+       &attr_ctn_id,
+       &attr_ctn_type,
+       &attr_dst_offset,
+       &attr_leap_seconds,
+       &attr_stp_online,
+       &attr_stratum,
+       &attr_time_offset,
+       &attr_time_zone_offset,
+       &attr_timing_mode,
+       &attr_timing_state,
+       NULL
+};
+
+static int __init stp_init_sysfs(void)
+{
+       struct sysdev_class_attribute **attr;
+       int rc;
+
+       rc = sysdev_class_register(&stp_sysclass);
+       if (rc)
+               goto out;
+       for (attr = stp_attributes; *attr; attr++) {
+               rc = sysdev_class_create_file(&stp_sysclass, *attr);
+               if (rc)
+                       goto out_unreg;
+       }
+       return 0;
+out_unreg:
+       for (; attr >= stp_attributes; attr--)
+               sysdev_class_remove_file(&stp_sysclass, *attr);
+       sysdev_class_unregister(&stp_sysclass);
+out:
+       return rc;
+}
+
+device_initcall(stp_init_sysfs);
index 661a072..212d618 100644 (file)
@@ -313,8 +313,6 @@ void __init s390_init_cpu_topology(void)
                machine_has_topology_irq = 1;
 
        tl_info = alloc_bootmem_pages(PAGE_SIZE);
-       if (!tl_info)
-               goto error;
        info = tl_info;
        stsi(info, 15, 1, 2);
 
index b460715..76c1e60 100644 (file)
@@ -40,7 +40,6 @@ SECTIONS
        _etext = .;             /* End of text section */
 
        NOTES :text :note
-       BUG_TABLE :text
 
        RODATA
 
index ca90ee3..0fa5dc5 100644 (file)
@@ -136,7 +136,7 @@ static inline void set_vtimer(__u64 expires)
 }
 #endif
 
-static void start_cpu_timer(void)
+void vtime_start_cpu_timer(void)
 {
        struct vtimer_queue *vt_list;
 
@@ -150,7 +150,7 @@ static void start_cpu_timer(void)
                set_vtimer(vt_list->idle);
 }
 
-static void stop_cpu_timer(void)
+void vtime_stop_cpu_timer(void)
 {
        struct vtimer_queue *vt_list;
 
@@ -318,8 +318,7 @@ static void internal_add_vtimer(struct vtimer_list *timer)
        vt_list = &per_cpu(virt_cpu_timer, timer->cpu);
        spin_lock_irqsave(&vt_list->lock, flags);
 
-       if (timer->cpu != smp_processor_id())
-               printk("internal_add_vtimer: BUG, running on wrong CPU");
+       BUG_ON(timer->cpu != smp_processor_id());
 
        /* if list is empty we only have to set the timer */
        if (list_empty(&vt_list->list)) {
@@ -353,25 +352,12 @@ static void internal_add_vtimer(struct vtimer_list *timer)
        put_cpu();
 }
 
-static inline int prepare_vtimer(struct vtimer_list *timer)
+static inline void prepare_vtimer(struct vtimer_list *timer)
 {
-       if (!timer->function) {
-               printk("add_virt_timer: uninitialized timer\n");
-               return -EINVAL;
-       }
-
-       if (!timer->expires || timer->expires > VTIMER_MAX_SLICE) {
-               printk("add_virt_timer: invalid timer expire value!\n");
-               return -EINVAL;
-       }
-
-       if (vtimer_pending(timer)) {
-               printk("add_virt_timer: timer pending\n");
-               return -EBUSY;
-       }
-
+       BUG_ON(!timer->function);
+       BUG_ON(!timer->expires || timer->expires > VTIMER_MAX_SLICE);
+       BUG_ON(vtimer_pending(timer));
        timer->cpu = get_cpu();
-       return 0;
 }
 
 /*
@@ -382,10 +368,7 @@ void add_virt_timer(void *new)
        struct vtimer_list *timer;
 
        timer = (struct vtimer_list *)new;
-
-       if (prepare_vtimer(timer) < 0)
-               return;
-
+       prepare_vtimer(timer);
        timer->interval = 0;
        internal_add_vtimer(timer);
 }
@@ -399,10 +382,7 @@ void add_virt_timer_periodic(void *new)
        struct vtimer_list *timer;
 
        timer = (struct vtimer_list *)new;
-
-       if (prepare_vtimer(timer) < 0)
-               return;
-
+       prepare_vtimer(timer);
        timer->interval = timer->expires;
        internal_add_vtimer(timer);
 }
@@ -423,15 +403,8 @@ int mod_virt_timer(struct vtimer_list *timer, __u64 expires)
        unsigned long flags;
        int cpu;
 
-       if (!timer->function) {
-               printk("mod_virt_timer: uninitialized timer\n");
-               return  -EINVAL;
-       }
-
-       if (!expires || expires > VTIMER_MAX_SLICE) {
-               printk("mod_virt_timer: invalid expire range\n");
-               return -EINVAL;
-       }
+       BUG_ON(!timer->function);
+       BUG_ON(!expires || expires > VTIMER_MAX_SLICE);
 
        /*
         * This is a common optimization triggered by the
@@ -444,6 +417,9 @@ int mod_virt_timer(struct vtimer_list *timer, __u64 expires)
        cpu = get_cpu();
        vt_list = &per_cpu(virt_cpu_timer, cpu);
 
+       /* check if we run on the right CPU */
+       BUG_ON(timer->cpu != cpu);
+
        /* disable interrupts before test if timer is pending */
        spin_lock_irqsave(&vt_list->lock, flags);
 
@@ -458,14 +434,6 @@ int mod_virt_timer(struct vtimer_list *timer, __u64 expires)
                return 0;
        }
 
-       /* check if we run on the right CPU */
-       if (timer->cpu != cpu) {
-               printk("mod_virt_timer: running on wrong CPU, check your code\n");
-               spin_unlock_irqrestore(&vt_list->lock, flags);
-               put_cpu();
-               return -EINVAL;
-       }
-
        list_del_init(&timer->entry);
        timer->expires = expires;
 
@@ -536,24 +504,6 @@ void init_cpu_vtimer(void)
 
 }
 
-static int vtimer_idle_notify(struct notifier_block *self,
-                             unsigned long action, void *hcpu)
-{
-       switch (action) {
-       case S390_CPU_IDLE:
-               stop_cpu_timer();
-               break;
-       case S390_CPU_NOT_IDLE:
-               start_cpu_timer();
-               break;
-       }
-       return NOTIFY_OK;
-}
-
-static struct notifier_block vtimer_idle_nb = {
-       .notifier_call = vtimer_idle_notify,
-};
-
 void __init vtime_init(void)
 {
        /* request the cpu timer external interrupt */
@@ -561,9 +511,6 @@ void __init vtime_init(void)
                                              &ext_int_info_timer) != 0)
                panic("Couldn't request external interrupt 0x1005");
 
-       if (register_idle_notifier(&vtimer_idle_nb))
-               panic("Couldn't register idle notifier");
-
        /* Enable cpu timer interrupts on the boot cpu. */
        init_cpu_vtimer();
 }
index 0559864..388cc74 100644 (file)
@@ -202,3 +202,22 @@ void free_initrd_mem(unsigned long start, unsigned long end)
         }
 }
 #endif
+
+#ifdef CONFIG_MEMORY_HOTPLUG
+int arch_add_memory(int nid, u64 start, u64 size)
+{
+       struct pglist_data *pgdat;
+       struct zone *zone;
+       int rc;
+
+       pgdat = NODE_DATA(nid);
+       zone = pgdat->node_zones + ZONE_NORMAL;
+       rc = vmem_add_mapping(start, size);
+       if (rc)
+               return rc;
+       rc = __add_pages(zone, PFN_DOWN(start), PFN_DOWN(size));
+       if (rc)
+               vmem_remove_mapping(start, size);
+       return rc;
+}
+#endif /* CONFIG_MEMORY_HOTPLUG */
index 1702508..0c15b0a 100644 (file)
@@ -14,6 +14,7 @@
  */
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 #include <linux/kdev_t.h>
 #include <linux/cdev.h>
 #include <linux/fs.h>
@@ -32,17 +33,20 @@ static int openCnt;
 static int gio_open(struct inode *inode, struct file *filp)
 {
        int minor;
+       int ret = -ENOENT;
 
+       lock_kernel();
        minor = MINOR(inode->i_rdev);
        if (minor < DEVCOUNT) {
                if (openCnt > 0) {
-                       return -EALREADY;
+                       ret = -EALREADY;
                } else {
                        openCnt++;
-                       return 0;
+                       ret = 0;
                }
        }
-       return -ENOENT;
+       unlock_kernel();
+       return ret;
 }
 
 static int gio_close(struct inode *inode, struct file *filp)
index f52db12..38f934a 100644 (file)
@@ -226,7 +226,6 @@ CONFIG_CPU_HAS_PTEA=y
 #
 CONFIG_SH_TMU=y
 CONFIG_SH_TIMER_IRQ=16
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_SH_PCLK_FREQ=33333333
 
 #
index 9fa66d9..b68b6cd 100644 (file)
@@ -231,7 +231,6 @@ CONFIG_CPU_HAS_PTEA=y
 #
 CONFIG_SH_TMU=y
 CONFIG_SH_TIMER_IRQ=16
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_SH_PCLK_FREQ=40000000
 
 #
index 84717d8..490dcbc 100644 (file)
@@ -239,7 +239,6 @@ CONFIG_CPU_HAS_SR_RB=y
 #
 CONFIG_SH_TMU=y
 CONFIG_SH_TIMER_IRQ=16
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_SH_PCLK_FREQ=33333333
 
 #
index 240a1ce..2dd83af 100644 (file)
@@ -236,7 +236,6 @@ CONFIG_CPU_HAS_SR_RB=y
 #
 CONFIG_SH_TMU=y
 CONFIG_SH_TIMER_IRQ=16
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_SH_PCLK_FREQ=66666666
 
 #
index c60b6fd..167786f 100644 (file)
@@ -235,7 +235,6 @@ CONFIG_CPU_HAS_PTEA=y
 #
 CONFIG_SH_TMU=y
 CONFIG_SH_TIMER_IRQ=16
-# CONFIG_NO_IDLE_HZ is not set
 CONFIG_SH_PCLK_FREQ=33333333
 
 #
index c711378..7b4b82b 100644 (file)
@@ -44,7 +44,6 @@ SECTIONS
 
        _etext = .;                     /* End of text section */
 
-       BUG_TABLE
        NOTES
        RO_DATA(PAGE_SIZE)
 
index d1e1770..33fa464 100644 (file)
@@ -65,7 +65,6 @@ SECTIONS
 
        _etext = .;                     /* End of text section */
 
-       BUG_TABLE
        NOTES 
        RO_DATA(PAGE_SIZE)
 
index d06a405..6707422 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/miscdevice.h>
+#include <linux/smp_lock.h>
 #include <linux/pm.h>
 
 #include <asm/io.h>
@@ -75,6 +76,7 @@ static inline void apc_free(void)
 
 static int apc_open(struct inode *inode, struct file *f)
 {
+       cycle_kernel_lock();
        return 0;
 }
 
index eb36f3b..fca9246 100644 (file)
@@ -11,6 +11,8 @@ config SPARC
 config SPARC64
        bool
        default y
+       select HAVE_DYNAMIC_FTRACE
+       select HAVE_FTRACE
        select HAVE_IDE
        select HAVE_LMB
        select HAVE_ARCH_KGDB
index 6a4d28a..d6d32d1 100644 (file)
@@ -33,7 +33,7 @@ config DEBUG_PAGEALLOC
 
 config MCOUNT
        bool
-       depends on STACK_DEBUG
+       depends on STACK_DEBUG || FTRACE
        default y
 
 config FRAME_POINTER
index ec4f5eb..418b578 100644 (file)
@@ -14,6 +14,7 @@ obj-y         := process.o setup.o cpu.o idprom.o \
                   power.o sbus.o sparc64_ksyms.o chmc.o \
                   visemul.o prom.o of_device.o hvapi.o sstate.o mdesc.o
 
+obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
 obj-$(CONFIG_PCI)       += ebus.o pci_common.o \
                            pci_psycho.o pci_sabre.o pci_schizo.o \
diff --git a/arch/sparc64/kernel/ftrace.c b/arch/sparc64/kernel/ftrace.c
new file mode 100644 (file)
index 0000000..4298d0a
--- /dev/null
@@ -0,0 +1,94 @@
+#include <linux/spinlock.h>
+#include <linux/hardirq.h>
+#include <linux/ftrace.h>
+#include <linux/percpu.h>
+#include <linux/init.h>
+#include <linux/list.h>
+
+#include <asm/ftrace.h>
+
+static const u32 ftrace_nop = 0x01000000;
+
+notrace unsigned char *ftrace_nop_replace(void)
+{
+       return (char *)&ftrace_nop;
+}
+
+notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
+{
+       static u32 call;
+       s32 off;
+
+       off = ((s32)addr - (s32)ip);
+       call = 0x40000000 | ((u32)off >> 2);
+
+       return (unsigned char *) &call;
+}
+
+notrace int
+ftrace_modify_code(unsigned long ip, unsigned char *old_code,
+                  unsigned char *new_code)
+{
+       u32 old = *(u32 *)old_code;
+       u32 new = *(u32 *)new_code;
+       u32 replaced;
+       int faulted;
+
+       __asm__ __volatile__(
+       "1:     cas     [%[ip]], %[old], %[new]\n"
+       "       flush   %[ip]\n"
+       "       mov     0, %[faulted]\n"
+       "2:\n"
+       "       .section .fixup,#alloc,#execinstr\n"
+       "       .align  4\n"
+       "3:     sethi   %%hi(2b), %[faulted]\n"
+       "       jmpl    %[faulted] + %%lo(2b), %%g0\n"
+       "        mov    1, %[faulted]\n"
+       "       .previous\n"
+       "       .section __ex_table,\"a\"\n"
+       "       .align  4\n"
+       "       .word   1b, 3b\n"
+       "       .previous\n"
+       : "=r" (replaced), [faulted] "=r" (faulted)
+       : [new] "0" (new), [old] "r" (old), [ip] "r" (ip)
+       : "memory");
+
+       if (replaced != old && replaced != new)
+               faulted = 2;
+
+       return faulted;
+}
+
+notrace int ftrace_update_ftrace_func(ftrace_func_t func)
+{
+       unsigned long ip = (unsigned long)(&ftrace_call);
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+
+       memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, (unsigned long)func);
+       return ftrace_modify_code(ip, old, new);
+}
+
+notrace int ftrace_mcount_set(unsigned long *data)
+{
+       unsigned long ip = (long)(&mcount_call);
+       unsigned long *addr = data;
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+
+       /*
+        * Replace the mcount stub with a pointer to the
+        * ip recorder function.
+        */
+       memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, *addr);
+       *addr = ftrace_modify_code(ip, old, new);
+
+       return 0;
+}
+
+
+int __init ftrace_dyn_arch_init(void *data)
+{
+       ftrace_mcount_set(data);
+       return 0;
+}
index 8ac0b99..49d3ea5 100644 (file)
@@ -53,6 +53,7 @@
 #include <asm/ns87303.h>
 #include <asm/timer.h>
 #include <asm/cpudata.h>
+#include <asm/ftrace.h>
 
 struct poll {
        int fd;
@@ -111,8 +112,7 @@ EXPORT_SYMBOL(__write_trylock);
 EXPORT_SYMBOL(smp_call_function);
 #endif /* CONFIG_SMP */
 
-#if defined(CONFIG_MCOUNT)
-extern void _mcount(void);
+#ifdef CONFIG_MCOUNT
 EXPORT_SYMBOL(_mcount);
 #endif
 
index e5d2389..bedc4c1 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/kernel.h>
 #include <linux/param.h>
 #include <linux/string.h>
@@ -1659,10 +1660,14 @@ static int mini_rtc_ioctl(struct inode *inode, struct file *file,
 
 static int mini_rtc_open(struct inode *inode, struct file *file)
 {
-       if (mini_rtc_status & RTC_IS_OPEN)
+       lock_kernel();
+       if (mini_rtc_status & RTC_IS_OPEN) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
        mini_rtc_status |= RTC_IS_OPEN;
+       unlock_kernel();
 
        return 0;
 }
index 9e4534b..7735a7a 100644 (file)
@@ -28,10 +28,13 @@ ovstack:
        .skip           OVSTACKSIZE
 #endif
        .text
-       .align 32
-       .globl mcount, _mcount
-mcount:
+       .align          32
+       .globl          _mcount
+       .type           _mcount,#function
+       .globl          mcount
+       .type           mcount,#function
 _mcount:
+mcount:
 #ifdef CONFIG_STACK_DEBUG
        /*
         * Check whether %sp is dangerously low.
@@ -55,6 +58,53 @@ _mcount:
         or             %g3, %lo(panicstring), %o0
        call            prom_halt
         nop
+1:
+#endif
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+       mov             %o7, %o0
+       .globl          mcount_call
+mcount_call:
+       call            ftrace_stub
+        mov            %o0, %o7
+#else
+       sethi           %hi(ftrace_trace_function), %g1
+       sethi           %hi(ftrace_stub), %g2
+       ldx             [%g1 + %lo(ftrace_trace_function)], %g1
+       or              %g2, %lo(ftrace_stub), %g2
+       cmp             %g1, %g2
+       be,pn           %icc, 1f
+        mov            %i7, %o1
+       jmpl            %g1, %g0
+        mov            %o7, %o0
+       /* not reached */
+1:
 #endif
-1:     retl
+#endif
+       retl
         nop
+       .size           _mcount,.-_mcount
+       .size           mcount,.-mcount
+
+#ifdef CONFIG_FTRACE
+       .globl          ftrace_stub
+       .type           ftrace_stub,#function
+ftrace_stub:
+       retl
+        nop
+       .size           ftrace_stub,.-ftrace_stub
+#ifdef CONFIG_DYNAMIC_FTRACE
+       .globl          ftrace_caller
+       .type           ftrace_caller,#function
+ftrace_caller:
+       mov             %i7, %o1
+       mov             %o7, %o0
+       .globl          ftrace_call
+ftrace_call:
+       call            ftrace_stub
+        mov            %o0, %o7
+       retl
+        nop
+       .size           ftrace_caller,.-ftrace_caller
+#endif
+#endif
index a9ad4bd..d332503 100644 (file)
@@ -66,6 +66,7 @@ static int harddog_open(struct inode *inode, struct file *file)
        int err = -EBUSY;
        char *sock = NULL;
 
+       lock_kernel();
        spin_lock(&lock);
        if(timer_alive)
                goto err;
@@ -82,9 +83,11 @@ static int harddog_open(struct inode *inode, struct file *file)
 
        timer_alive = 1;
        spin_unlock(&lock);
+       unlock_kernel();
        return nonseekable_open(inode, file);
 err:
        spin_unlock(&lock);
+       unlock_kernel();
        return err;
 }
 
index 67b2f55..eb24032 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include "mem_user.h"
 
@@ -77,6 +78,7 @@ out:
 
 static int mmapper_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        return 0;
 }
 
index 4949044..6eabb70 100644 (file)
@@ -7,6 +7,7 @@
  * of the GNU General Public License, incorporated herein by reference.
  */
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
@@ -33,6 +34,8 @@ static DECLARE_WAIT_QUEUE_HEAD(host_read_wait);
 
 static int rng_dev_open (struct inode *inode, struct file *filp)
 {
+       cycle_kernel_lock();
+
        /* enforce read-only access to this chrdev */
        if ((filp->f_mode & FMODE_READ) == 0)
                return -EINVAL;
index bf07b6f..6958d6b 100644 (file)
@@ -23,6 +23,8 @@ config X86
        select HAVE_OPROFILE
        select HAVE_KPROBES
        select HAVE_KRETPROBES
+       select HAVE_DYNAMIC_FTRACE
+       select HAVE_FTRACE
        select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
        select HAVE_ARCH_KGDB if !X86_VOYAGER
 
@@ -121,7 +123,7 @@ config ARCH_HAS_CACHE_LINE_SIZE
        def_bool y
 
 config HAVE_SETUP_PER_CPU_AREA
-       def_bool X86_64 || (X86_SMP && !X86_VOYAGER)
+       def_bool X86_64_SMP || (X86_SMP && !X86_VOYAGER)
 
 config HAVE_CPUMASK_OF_CPU_MAP
        def_bool X86_64_SMP
@@ -181,12 +183,12 @@ config X86_64_SMP
 config X86_HT
        bool
        depends on SMP
-       depends on (X86_32 && !(X86_VISWS || X86_VOYAGER)) || X86_64
+       depends on (X86_32 && !X86_VOYAGER) || X86_64
        default y
 
 config X86_BIOS_REBOOT
        bool
-       depends on !X86_VISWS && !X86_VOYAGER
+       depends on !X86_VOYAGER
        default y
 
 config X86_TRAMPOLINE
@@ -230,6 +232,26 @@ config SMP
 
          If you don't know what to do here, say N.
 
+config X86_FIND_SMP_CONFIG
+       def_bool y
+       depends on X86_MPPARSE || X86_VOYAGER
+
+if ACPI
+config X86_MPPARSE
+       def_bool y
+       bool "Enable MPS table"
+       depends on X86_LOCAL_APIC
+       help
+         For old smp systems that do not have proper acpi support. Newer systems
+         (esp with 64bit cpus) with acpi support, MADT and DSDT will override it
+endif
+
+if !ACPI
+config X86_MPPARSE
+       def_bool y
+       depends on X86_LOCAL_APIC
+endif
+
 choice
        prompt "Subarchitecture Type"
        default X86_PC
@@ -251,7 +273,7 @@ config X86_ELAN
 
 config X86_VOYAGER
        bool "Voyager (NCR)"
-       depends on X86_32 && (SMP || BROKEN)
+       depends on X86_32 && (SMP || BROKEN) && !PCI
        help
          Voyager is an MCA-based 32-way capable SMP architecture proprietary
          to NCR Corp.  Machine classes 345x/35xx/4100/51xx are Voyager-based.
@@ -261,16 +283,27 @@ config X86_VOYAGER
          If you do not specifically know you have a Voyager based machine,
          say N here, otherwise the kernel you build will not be bootable.
 
+config X86_GENERICARCH
+       bool "Generic architecture"
+       depends on X86_32
+       help
+          This option compiles in the NUMAQ, Summit, bigsmp, ES7000, default
+         subarchitectures.  It is intended for a generic binary kernel.
+         if you select them all, kernel will probe it one by one. and will
+         fallback to default.
+
+if X86_GENERICARCH
+
 config X86_NUMAQ
        bool "NUMAQ (IBM/Sequent)"
-       depends on SMP && X86_32
+       depends on SMP && X86_32 && PCI && X86_MPPARSE
        select NUMA
        help
-         This option is used for getting Linux to run on a (IBM/Sequent) NUMA
-         multiquad box. This changes the way that processors are bootstrapped,
-         and uses Clustered Logical APIC addressing mode instead of Flat Logical.
-         You will need a new lynxer.elf file to flash your firmware with - send
-         email to <Martin.Bligh@us.ibm.com>.
+         This option is used for getting Linux to run on a NUMAQ (IBM/Sequent)
+         NUMA multiquad box. This changes the way that processors are
+         bootstrapped, and uses Clustered Logical APIC addressing mode instead
+         of Flat Logical.  You will need a new lynxer.elf file to flash your
+         firmware with - send email to <Martin.Bligh@us.ibm.com>.
 
 config X86_SUMMIT
        bool "Summit/EXA (IBM x440)"
@@ -279,46 +312,21 @@ config X86_SUMMIT
          This option is needed for IBM systems that use the Summit/EXA chipset.
          In particular, it is needed for the x440.
 
-         If you don't have one of these computers, you should say N here.
-         If you want to build a NUMA kernel, you must select ACPI.
+config X86_ES7000
+       bool "Support for Unisys ES7000 IA32 series"
+       depends on X86_32 && SMP
+       help
+         Support for Unisys ES7000 systems.  Say 'Y' here if this kernel is
+         supposed to run on an IA32-based Unisys ES7000 system.
 
 config X86_BIGSMP
-       bool "Support for other sub-arch SMP systems with more than 8 CPUs"
+       bool "Support for big SMP systems with more than 8 CPUs"
        depends on X86_32 && SMP
        help
          This option is needed for the systems that have more than 8 CPUs
          and if the system is not of any sub-arch type above.
 
-         If you don't have such a system, you should say N here.
-
-config X86_VISWS
-       bool "SGI 320/540 (Visual Workstation)"
-       depends on X86_32
-       help
-         The SGI Visual Workstation series is an IA32-based workstation
-         based on SGI systems chips with some legacy PC hardware attached.
-
-         Say Y here to create a kernel to run on the SGI 320 or 540.
-
-         A kernel compiled for the Visual Workstation will not run on PCs
-         and vice versa. See <file:Documentation/sgi-visws.txt> for details.
-
-config X86_GENERICARCH
-       bool "Generic architecture (Summit, bigsmp, ES7000, default)"
-       depends on X86_32
-       help
-          This option compiles in the Summit, bigsmp, ES7000, default subarchitectures.
-         It is intended for a generic binary kernel.
-         If you want a NUMA kernel, select ACPI.   We need SRAT for NUMA.
-
-config X86_ES7000
-       bool "Support for Unisys ES7000 IA32 series"
-       depends on X86_32 && SMP
-       help
-         Support for Unisys ES7000 systems.  Say 'Y' here if this kernel is
-         supposed to run on an IA32-based Unisys ES7000 system.
-         Only choose this option if you have such a system, otherwise you
-         should say N here.
+endif
 
 config X86_RDC321X
        bool "RDC R-321x SoC"
@@ -337,7 +345,7 @@ config X86_RDC321X
 config X86_VSMP
        bool "Support for ScaleMP vSMP"
        select PARAVIRT
-       depends on X86_64
+       depends on X86_64 && PCI
        help
          Support for ScaleMP vSMP systems.  Say 'Y' here if this kernel is
          supposed to run on these EM64T-based machines.  Only choose this option
@@ -345,6 +353,18 @@ config X86_VSMP
 
 endchoice
 
+config X86_VISWS
+       bool "SGI 320/540 (Visual Workstation)"
+       depends on X86_32 && PCI && !X86_VOYAGER && X86_MPPARSE && PCI_GODIRECT
+       help
+         The SGI Visual Workstation series is an IA32-based workstation
+         based on SGI systems chips with some legacy PC hardware attached.
+
+         Say Y here to create a kernel to run on the SGI 320 or 540.
+
+         A kernel compiled for the Visual Workstation will run on general
+         PCs as well. See <file:Documentation/sgi-visws.txt> for details.
+
 config SCHED_NO_NO_OMIT_FRAME_POINTER
        def_bool y
        prompt "Single-depth WCHAN output"
@@ -373,7 +393,7 @@ config VMI
        bool "VMI Guest support"
        select PARAVIRT
        depends on X86_32
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          VMI provides a paravirtualized interface to the VMware ESX server
          (it could be used by other hypervisors in theory too, but is not
@@ -384,7 +404,7 @@ config KVM_CLOCK
        bool "KVM paravirtualized clock"
        select PARAVIRT
        select PARAVIRT_CLOCK
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          Turning on this option will allow you to run a paravirtualized clock
          when running over the KVM hypervisor. Instead of relying on a PIT
@@ -395,7 +415,7 @@ config KVM_CLOCK
 config KVM_GUEST
        bool "KVM Guest support"
        select PARAVIRT
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
         This option enables various optimizations for running under the KVM
         hypervisor.
@@ -404,7 +424,7 @@ source "arch/x86/lguest/Kconfig"
 
 config PARAVIRT
        bool "Enable paravirtualization code"
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          This changes the kernel so it can modify itself when it is run
          under a hypervisor, potentially improving performance significantly
@@ -417,51 +437,33 @@ config PARAVIRT_CLOCK
 
 endif
 
-config MEMTEST_BOOTPARAM
-       bool "Memtest boot parameter"
+config PARAVIRT_DEBUG
+       bool "paravirt-ops debugging"
+       depends on PARAVIRT && DEBUG_KERNEL
+       help
+         Enable to debug paravirt_ops internals.  Specifically, BUG if
+        a paravirt_op is missing when it is called.
+
+config MEMTEST
+       bool "Memtest"
        depends on X86_64
        default y
        help
          This option adds a kernel parameter 'memtest', which allows memtest
-         to be disabled at boot.  If this option is selected, memtest
-         functionality can be disabled with memtest=0 on the kernel
-         command line.  The purpose of this option is to allow a single
-         kernel image to be distributed with memtest built in, but not
-         necessarily enabled.
-
+         to be set.
+               memtest=0, mean disabled; -- default
+               memtest=1, mean do 1 test pattern;
+               ...
+               memtest=4, mean do 4 test patterns.
          If you are unsure how to answer this question, answer Y.
 
-config MEMTEST_BOOTPARAM_VALUE
-       int "Memtest boot parameter default value (0-4)"
-       depends on MEMTEST_BOOTPARAM
-       range 0 4
-       default 0
-       help
-         This option sets the default value for the kernel parameter
-         'memtest', which allows memtest to be disabled at boot.  If this
-         option is set to 0 (zero), the memtest kernel parameter will
-         default to 0, disabling memtest at bootup.  If this option is
-         set to 4, the memtest kernel parameter will default to 4,
-         enabling memtest at bootup, and use that as pattern number.
-
-         If you are unsure how to answer this question, answer 0.
-
-config ACPI_SRAT
-       def_bool y
-       depends on X86_32 && ACPI && NUMA && (X86_SUMMIT || X86_GENERICARCH)
-       select ACPI_NUMA
-
-config HAVE_ARCH_PARSE_SRAT
-       def_bool y
-       depends on ACPI_SRAT
-
 config X86_SUMMIT_NUMA
        def_bool y
-       depends on X86_32 && NUMA && (X86_SUMMIT || X86_GENERICARCH)
+       depends on X86_32 && NUMA && X86_GENERICARCH
 
 config X86_CYCLONE_TIMER
        def_bool y
-       depends on X86_32 && X86_SUMMIT || X86_GENERICARCH
+       depends on X86_GENERICARCH
 
 config ES7000_CLUSTERED_APIC
        def_bool y
@@ -549,6 +551,21 @@ config CALGARY_IOMMU_ENABLED_BY_DEFAULT
          Calgary anyway, pass 'iommu=calgary' on the kernel command line.
          If unsure, say Y.
 
+config AMD_IOMMU
+       bool "AMD IOMMU support"
+       select SWIOTLB
+       depends on X86_64 && PCI && ACPI
+       help
+         With this option you can enable support for AMD IOMMU hardware in
+         your system. An IOMMU is a hardware component which provides
+         remapping of DMA memory accesses from devices. With an AMD IOMMU you
+         can isolate the the DMA memory of different devices and protect the
+         system from misbehaving device drivers or hardware.
+
+         You can find out if your system has an AMD IOMMU if you look into
+         your BIOS for an option to enable it or if you have an IVRS ACPI
+         table.
+
 # need this always selected by IOMMU for the VIA workaround
 config SWIOTLB
        bool
@@ -560,21 +577,36 @@ config SWIOTLB
          3 GB of memory. If unsure, say Y.
 
 config IOMMU_HELPER
-       def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB)
+       def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB || AMD_IOMMU)
+config MAXSMP
+       bool "Configure Maximum number of SMP Processors and NUMA Nodes"
+       depends on X86_64 && SMP
+       default n
+       help
+         Configure maximum number of CPUS and NUMA Nodes for this architecture.
+         If unsure, say N.
 
+if MAXSMP
 config NR_CPUS
-       int "Maximum number of CPUs (2-255)"
-       range 2 255
+       int
+       default "4096"
+endif
+
+if !MAXSMP
+config NR_CPUS
+       int "Maximum number of CPUs (2-4096)"
+       range 2 4096
        depends on SMP
        default "32" if X86_NUMAQ || X86_SUMMIT || X86_BIGSMP || X86_ES7000
        default "8"
        help
          This allows you to specify the maximum number of CPUs which this
-         kernel will support.  The maximum supported value is 255 and the
+         kernel will support.  The maximum supported value is 4096 and the
          minimum value which makes sense is 2.
 
          This is purely to save memory - each supported CPU adds
          approximately eight kilobytes to the kernel image.
+endif
 
 config SCHED_SMT
        bool "SMT (Hyperthreading) scheduler support"
@@ -598,7 +630,7 @@ source "kernel/Kconfig.preempt"
 
 config X86_UP_APIC
        bool "Local APIC support on uniprocessors"
-       depends on X86_32 && !SMP && !(X86_VISWS || X86_VOYAGER || X86_GENERICARCH)
+       depends on X86_32 && !SMP && !(X86_VOYAGER || X86_GENERICARCH)
        help
          A local APIC (Advanced Programmable Interrupt Controller) is an
          integrated interrupt controller in the CPU. If you have a single-CPU
@@ -623,11 +655,11 @@ config X86_UP_IOAPIC
 
 config X86_LOCAL_APIC
        def_bool y
-       depends on X86_64 || (X86_32 && (X86_UP_APIC || ((X86_VISWS || SMP) && !X86_VOYAGER) || X86_GENERICARCH))
+       depends on X86_64 || (X86_32 && (X86_UP_APIC || (SMP && !X86_VOYAGER) || X86_GENERICARCH))
 
 config X86_IO_APIC
        def_bool y
-       depends on X86_64 || (X86_32 && (X86_UP_IOAPIC || (SMP && !(X86_VISWS || X86_VOYAGER)) || X86_GENERICARCH))
+       depends on X86_64 || (X86_32 && (X86_UP_IOAPIC || (SMP && !X86_VOYAGER) || X86_GENERICARCH))
 
 config X86_VISWS_APIC
        def_bool y
@@ -681,7 +713,7 @@ config X86_MCE_NONFATAL
 
 config X86_MCE_P4THERMAL
        bool "check for P4 thermal throttling interrupt."
-       depends on X86_32 && X86_MCE && (X86_UP_APIC || SMP) && !X86_VISWS
+       depends on X86_32 && X86_MCE && (X86_UP_APIC || SMP)
        help
          Enabling this feature will cause a message to be printed when the P4
          enters thermal throttling.
@@ -911,9 +943,9 @@ config X86_PAE
 config NUMA
        bool "Numa Memory Allocation and Scheduler Support (EXPERIMENTAL)"
        depends on SMP
-       depends on X86_64 || (X86_32 && HIGHMEM64G && (X86_NUMAQ || (X86_SUMMIT || X86_GENERICARCH) && ACPI) && EXPERIMENTAL)
+       depends on X86_64 || (X86_32 && HIGHMEM64G && (X86_NUMAQ || X86_BIGSMP || X86_SUMMIT && ACPI) && EXPERIMENTAL)
        default n if X86_PC
-       default y if (X86_NUMAQ || X86_SUMMIT)
+       default y if (X86_NUMAQ || X86_SUMMIT || X86_BIGSMP)
        help
          Enable NUMA (Non Uniform Memory Access) support.
          The kernel will try to allocate memory used by a CPU on the
@@ -965,13 +997,25 @@ config NUMA_EMU
          into virtual nodes when booted with "numa=fake=N", where N is the
          number of nodes. This is only useful for debugging.
 
+if MAXSMP
+
+config NODES_SHIFT
+       int
+       default "9"
+endif
+
+if !MAXSMP
 config NODES_SHIFT
-       int "Max num nodes shift(1-9)"
-       range 1 9  if X86_64
+       int "Maximum NUMA Nodes (as a power of 2)"
+       range 1 9   if X86_64
        default "6" if X86_64
        default "4" if X86_NUMAQ
        default "3"
        depends on NEED_MULTIPLE_NODES
+       help
+         Specify the maximum number of NUMA Nodes available on the target
+         system.  Increases memory reserved to accomodate various tables.
+endif
 
 config HAVE_ARCH_BOOTMEM_NODE
        def_bool y
@@ -1090,6 +1134,40 @@ config MTRR
 
          See <file:Documentation/mtrr.txt> for more information.
 
+config MTRR_SANITIZER
+       def_bool y
+       prompt "MTRR cleanup support"
+       depends on MTRR
+       help
+         Convert MTRR layout from continuous to discrete, so some X driver
+         could add WB entries.
+
+         Say N here if you see bootup problems (boot crash, boot hang,
+         spontaneous reboots).
+
+         Could be disabled with disable_mtrr_cleanup. Also mtrr_chunk_size
+         could be used to send largest mtrr entry size for continuous block
+         to hold holes (aka. UC entries)
+
+         If unsure, say Y.
+
+config MTRR_SANITIZER_ENABLE_DEFAULT
+       int "MTRR cleanup enable value (0-1)"
+       range 0 1
+       default "0"
+       depends on MTRR_SANITIZER
+       help
+         Enable mtrr cleanup default value
+
+config MTRR_SANITIZER_SPARE_REG_NR_DEFAULT
+       int "MTRR cleanup spare reg num (0-7)"
+       range 0 7
+       default "1"
+       depends on MTRR_SANITIZER
+       help
+         mtrr cleanup spare entries default, it can be changed via
+         mtrr_spare_reg_nr=
+
 config X86_PAT
        bool
        prompt "x86 PAT support"
@@ -1190,7 +1268,6 @@ config KEXEC
 
 config CRASH_DUMP
        bool "kernel crash dumps (EXPERIMENTAL)"
-       depends on EXPERIMENTAL
        depends on X86_64 || (X86_32 && HIGHMEM)
        help
          Generate crash dump after being started by kexec.
@@ -1339,7 +1416,7 @@ config X86_APM_BOOT
 
 menuconfig APM
        tristate "APM (Advanced Power Management) BIOS support"
-       depends on X86_32 && PM_SLEEP && !X86_VISWS
+       depends on X86_32 && PM_SLEEP
        ---help---
          APM is a BIOS specification for saving power using several different
          techniques. This is mostly useful for battery powered laptops with
@@ -1475,8 +1552,7 @@ endmenu
 menu "Bus options (PCI etc.)"
 
 config PCI
-       bool "PCI support" if !X86_VISWS && !X86_VSMP
-       depends on !X86_VOYAGER
+       bool "PCI support"
        default y
        select ARCH_SUPPORTS_MSI if (X86_LOCAL_APIC && X86_IO_APIC)
        help
@@ -1487,7 +1563,7 @@ config PCI
 
 choice
        prompt "PCI access mode"
-       depends on X86_32 && PCI && !X86_VISWS
+       depends on X86_32 && PCI
        default PCI_GOANY
        ---help---
          On PCI systems, the BIOS can be used to detect the PCI devices and
@@ -1524,12 +1600,12 @@ endchoice
 
 config PCI_BIOS
        def_bool y
-       depends on X86_32 && !X86_VISWS && PCI && (PCI_GOBIOS || PCI_GOANY)
+       depends on X86_32 && PCI && (PCI_GOBIOS || PCI_GOANY)
 
 # x86-64 doesn't support PCI BIOS access from long mode so always go direct.
 config PCI_DIRECT
        def_bool y
-       depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC) || X86_VISWS)
+       depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC))
 
 config PCI_MMCONFIG
        def_bool y
@@ -1589,7 +1665,7 @@ if X86_32
 
 config ISA
        bool "ISA support"
-       depends on !(X86_VOYAGER || X86_VISWS)
+       depends on !X86_VOYAGER
        help
          Find out whether you have ISA slots on your motherboard.  ISA is the
          name of a bus system, i.e. the way the CPU talks to the other stuff
@@ -1616,7 +1692,7 @@ config EISA
 source "drivers/eisa/Kconfig"
 
 config MCA
-       bool "MCA support" if !(X86_VISWS || X86_VOYAGER)
+       bool "MCA support" if !X86_VOYAGER
        default y if X86_VOYAGER
        help
          MicroChannel Architecture is found in some IBM PS/2 machines and
index 2ad6301..abff1b8 100644 (file)
@@ -344,7 +344,7 @@ config X86_F00F_BUG
 
 config X86_WP_WORKS_OK
        def_bool y
-       depends on X86_32 && !M386
+       depends on !M386
 
 config X86_INVLPG
        def_bool y
@@ -399,6 +399,10 @@ config X86_TSC
        def_bool y
        depends on ((MWINCHIP3D || MWINCHIP2 || MCRUSOE || MEFFICEON || MCYRIXIII || MK7 || MK6 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || MK8 || MVIAC3_2 || MVIAC7 || MGEODEGX1 || MGEODE_LX || MCORE2) && !X86_NUMAQ) || X86_64
 
+config X86_CMPXCHG64
+       def_bool y
+       depends on X86_PAE || X86_64
+
 # this should be set for all -march=.. options where the compiler
 # generates cmov.
 config X86_CMOV
index 1836337..ae36bfa 100644 (file)
@@ -20,6 +20,14 @@ config NONPROMISC_DEVMEM
 
          If in doubt, say Y.
 
+config X86_VERBOSE_BOOTUP
+       bool "Enable verbose x86 bootup info messages"
+       default y
+       help
+         Enables the informational output from the decompression stage
+         (e.g. bzImage) of the boot. If you disable this you will still
+         see errors. Disable this if you want silent bootup.
+
 config EARLY_PRINTK
        bool "Early printk" if EMBEDDED
        default y
@@ -60,7 +68,7 @@ config DEBUG_PAGEALLOC
 config DEBUG_PER_CPU_MAPS
        bool "Debug access to per_cpu maps"
        depends on DEBUG_KERNEL
-       depends on X86_64_SMP
+       depends on X86_SMP
        default n
        help
          Say Y to verify that the per_cpu map being accessed has
@@ -129,15 +137,6 @@ config 4KSTACKS
          on the VM subsystem for higher order allocations. This option
          will also use IRQ stacks to compensate for the reduced stackspace.
 
-config X86_FIND_SMP_CONFIG
-       def_bool y
-       depends on X86_LOCAL_APIC || X86_VOYAGER
-       depends on X86_32
-
-config X86_MPPARSE
-       def_bool y
-       depends on (X86_32 && (X86_LOCAL_APIC && !X86_VISWS)) || X86_64
-
 config DOUBLEFAULT
        default y
        bool "Enable doublefault exception handler" if EMBEDDED
@@ -172,6 +171,33 @@ config IOMMU_LEAK
          Add a simple leak tracer to the IOMMU code. This is useful when you
          are debugging a buggy device driver that leaks IOMMU mappings.
 
+config MMIOTRACE_HOOKS
+       bool
+
+config MMIOTRACE
+       bool "Memory mapped IO tracing"
+       depends on DEBUG_KERNEL && PCI
+       select TRACING
+       select MMIOTRACE_HOOKS
+       help
+         Mmiotrace traces Memory Mapped I/O access and is meant for
+         debugging and reverse engineering. It is called from the ioremap
+         implementation and works via page faults. Tracing is disabled by
+         default and can be enabled at run-time.
+
+         See Documentation/tracers/mmiotrace.txt.
+         If you are not helping to develop drivers, say N.
+
+config MMIOTRACE_TEST
+       tristate "Test module for mmiotrace"
+       depends on MMIOTRACE && m
+       help
+         This is a dumb module for testing mmiotrace. It is very dangerous
+         as it will write garbage to IO memory starting at a given address.
+         However, it should be safe to use on e.g. unused portion of VRAM.
+
+         Say N, unless you absolutely know what you are doing.
+
 #
 # IO delay types:
 #
index 3cff3c8..919ce21 100644 (file)
@@ -113,33 +113,11 @@ mcore-y  := arch/x86/mach-default/
 mflags-$(CONFIG_X86_VOYAGER)   := -Iinclude/asm-x86/mach-voyager
 mcore-$(CONFIG_X86_VOYAGER)    := arch/x86/mach-voyager/
 
-# VISWS subarch support
-mflags-$(CONFIG_X86_VISWS)     := -Iinclude/asm-x86/mach-visws
-mcore-$(CONFIG_X86_VISWS)      := arch/x86/mach-visws/
-
-# NUMAQ subarch support
-mflags-$(CONFIG_X86_NUMAQ)     := -Iinclude/asm-x86/mach-numaq
-mcore-$(CONFIG_X86_NUMAQ)      := arch/x86/mach-default/
-
-# BIGSMP subarch support
-mflags-$(CONFIG_X86_BIGSMP)    := -Iinclude/asm-x86/mach-bigsmp
-mcore-$(CONFIG_X86_BIGSMP)     := arch/x86/mach-default/
-
-#Summit subarch support
-mflags-$(CONFIG_X86_SUMMIT)    := -Iinclude/asm-x86/mach-summit
-mcore-$(CONFIG_X86_SUMMIT)     := arch/x86/mach-default/
-
 # generic subarchitecture
 mflags-$(CONFIG_X86_GENERICARCH):= -Iinclude/asm-x86/mach-generic
 fcore-$(CONFIG_X86_GENERICARCH)        += arch/x86/mach-generic/
 mcore-$(CONFIG_X86_GENERICARCH)        := arch/x86/mach-default/
 
-
-# ES7000 subarch support
-mflags-$(CONFIG_X86_ES7000)    := -Iinclude/asm-x86/mach-es7000
-fcore-$(CONFIG_X86_ES7000)     := arch/x86/mach-es7000/
-mcore-$(CONFIG_X86_ES7000)     := arch/x86/mach-default/
-
 # RDC R-321x subarch support
 mflags-$(CONFIG_X86_RDC321X)   := -Iinclude/asm-x86/mach-rdc321x
 mcore-$(CONFIG_X86_RDC321X)    := arch/x86/mach-default/
@@ -160,6 +138,7 @@ KBUILD_AFLAGS += $(mflags-y)
 
 head-y := arch/x86/kernel/head_$(BITS).o
 head-y += arch/x86/kernel/head$(BITS).o
+head-y += arch/x86/kernel/head.o
 head-y += arch/x86/kernel/init_task.o
 
 libs-y  += arch/x86/lib/
@@ -210,12 +189,12 @@ all: bzImage
 
 # KBUILD_IMAGE specify target image being built
                     KBUILD_IMAGE := $(boot)/bzImage
-zImage zlilo zdisk: KBUILD_IMAGE := arch/x86/boot/zImage
+zImage zlilo zdisk: KBUILD_IMAGE := $(boot)/zImage
 
 zImage bzImage: vmlinux
        $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
        $(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
-       $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/bzImage
+       $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
 
 compressed: zImage
 
index e01aafd..4063d63 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- linux-c -*- ------------------------------------------------------- *
  *
  *   Copyright (C) 1991, 1992 Linus Torvalds
- *   Copyright 2007 rPath, Inc. - All Rights Reserved
+ *   Copyright 2007-2008 rPath, Inc. - All Rights Reserved
  *
  *   This file is part of the Linux kernel, and is made available under
  *   the terms of the GNU General Public License version 2.
@@ -95,6 +95,9 @@ static void enable_a20_kbc(void)
 
        outb(0xdf, 0x60);       /* A20 on */
        empty_8042();
+
+       outb(0xff, 0x64);       /* Null command, but UHCI wants it */
+       empty_8042();
 }
 
 static void enable_a20_fast(void)
index d8819ef..1d5dff4 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/page.h>
 #include <asm/boot.h>
 #include <asm/msr.h>
+#include <asm/processor-flags.h>
 #include <asm/asm-offsets.h>
 
 .section ".text.head"
@@ -109,7 +110,7 @@ startup_32:
 
        /* Enable PAE mode */
        xorl    %eax, %eax
-       orl     $(1 << 5), %eax
+       orl     $(X86_CR4_PAE), %eax
        movl    %eax, %cr4
 
  /*
@@ -170,7 +171,7 @@ startup_32:
        pushl   %eax
 
        /* Enter paged protected Mode, activating Long Mode */
-       movl    $0x80000001, %eax /* Enable Paging and Protected mode */
+       movl    $(X86_CR0_PG | X86_CR0_PE), %eax /* Enable Paging and Protected mode */
        movl    %eax, %cr0
 
        /* Jump from 32bit compatibility mode into 64bit mode. */
index 90456ce..bc5553b 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/io.h>
 #include <asm/page.h>
 #include <asm/boot.h>
+#include <asm/bootparam.h>
 
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated dynamically
@@ -187,13 +188,8 @@ static void gzip_release(void **);
 /*
  * This is set up by the setup-routine at boot-time
  */
-static unsigned char *real_mode; /* Pointer to real-mode data */
-
-#define RM_EXT_MEM_K   (*(unsigned short *)(real_mode + 0x2))
-#ifndef STANDARD_MEMORY_BIOS_CALL
-#define RM_ALT_MEM_K   (*(unsigned long *)(real_mode + 0x1e0))
-#endif
-#define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))
+static struct boot_params *real_mode;          /* Pointer to real-mode data */
+static int quiet;
 
 extern unsigned char input_data[];
 extern int input_len;
@@ -206,7 +202,8 @@ static void free(void *where);
 static void *memset(void *s, int c, unsigned n);
 static void *memcpy(void *dest, const void *src, unsigned n);
 
-static void putstr(const char *);
+static void __putstr(int, const char *);
+#define putstr(__x)  __putstr(0, __x)
 
 #ifdef CONFIG_X86_64
 #define memptr long
@@ -221,10 +218,6 @@ static char *vidmem;
 static int vidport;
 static int lines, cols;
 
-#ifdef CONFIG_X86_NUMAQ
-void *xquad_portio;
-#endif
-
 #include "../../../../lib/inflate.c"
 
 static void *malloc(int size)
@@ -270,18 +263,24 @@ static void scroll(void)
                vidmem[i] = ' ';
 }
 
-static void putstr(const char *s)
+static void __putstr(int error, const char *s)
 {
        int x, y, pos;
        char c;
 
+#ifndef CONFIG_X86_VERBOSE_BOOTUP
+       if (!error)
+               return;
+#endif
+
 #ifdef CONFIG_X86_32
-       if (RM_SCREEN_INFO.orig_video_mode == 0 && lines == 0 && cols == 0)
+       if (real_mode->screen_info.orig_video_mode == 0 &&
+           lines == 0 && cols == 0)
                return;
 #endif
 
-       x = RM_SCREEN_INFO.orig_x;
-       y = RM_SCREEN_INFO.orig_y;
+       x = real_mode->screen_info.orig_x;
+       y = real_mode->screen_info.orig_y;
 
        while ((c = *s++) != '\0') {
                if (c == '\n') {
@@ -302,8 +301,8 @@ static void putstr(const char *s)
                }
        }
 
-       RM_SCREEN_INFO.orig_x = x;
-       RM_SCREEN_INFO.orig_y = y;
+       real_mode->screen_info.orig_x = x;
+       real_mode->screen_info.orig_y = y;
 
        pos = (x + cols * y) * 2;       /* Update cursor position */
        outb(14, vidport);
@@ -366,9 +365,9 @@ static void flush_window(void)
 
 static void error(char *x)
 {
-       putstr("\n\n");
-       putstr(x);
-       putstr("\n\n -- System halted");
+       __putstr(1, "\n\n");
+       __putstr(1, x);
+       __putstr(1, "\n\n -- System halted");
 
        while (1)
                asm("hlt");
@@ -395,7 +394,8 @@ static void parse_elf(void *output)
                return;
        }
 
-       putstr("Parsing ELF... ");
+       if (!quiet)
+               putstr("Parsing ELF... ");
 
        phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum);
        if (!phdrs)
@@ -430,7 +430,10 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
 {
        real_mode = rmode;
 
-       if (RM_SCREEN_INFO.orig_video_mode == 7) {
+       if (real_mode->hdr.loadflags & QUIET_FLAG)
+               quiet = 1;
+
+       if (real_mode->screen_info.orig_video_mode == 7) {
                vidmem = (char *) 0xb0000;
                vidport = 0x3b4;
        } else {
@@ -438,8 +441,8 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
                vidport = 0x3d4;
        }
 
-       lines = RM_SCREEN_INFO.orig_video_lines;
-       cols = RM_SCREEN_INFO.orig_video_cols;
+       lines = real_mode->screen_info.orig_video_lines;
+       cols = real_mode->screen_info.orig_video_cols;
 
        window = output;                /* Output buffer (Normally at 1M) */
        free_mem_ptr     = heap;        /* Heap */
@@ -465,9 +468,11 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
 #endif
 
        makecrc();
-       putstr("\nDecompressing Linux... ");
+       if (!quiet)
+               putstr("\nDecompressing Linux... ");
        gunzip();
        parse_elf(output);
-       putstr("done.\nBooting the kernel.\n");
+       if (!quiet)
+               putstr("done.\nBooting the kernel.\n");
        return;
 }
index edaadea..a1310c5 100644 (file)
 #define USE_BSD
 #include <endian.h>
 
-#define MAX_SHDRS 100
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 static Elf32_Ehdr ehdr;
-static Elf32_Shdr shdr[MAX_SHDRS];
-static Elf32_Sym  *symtab[MAX_SHDRS];
-static Elf32_Rel  *reltab[MAX_SHDRS];
-static char *strtab[MAX_SHDRS];
 static unsigned long reloc_count, reloc_idx;
 static unsigned long *relocs;
 
+struct section {
+       Elf32_Shdr     shdr;
+       struct section *link;
+       Elf32_Sym      *symtab;
+       Elf32_Rel      *reltab;
+       char           *strtab;
+};
+static struct section *secs;
+
 /*
  * Following symbols have been audited. There values are constant and do
  * not change if bzImage is loaded at a different physical address than
@@ -35,7 +39,7 @@ static int is_safe_abs_reloc(const char* sym_name)
 {
        int i;
 
-       for(i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
+       for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
                if (!strcmp(sym_name, safe_abs_relocs[i]))
                        /* Match found */
                        return 1;
@@ -137,10 +141,10 @@ static const char *sec_name(unsigned shndx)
 {
        const char *sec_strtab;
        const char *name;
-       sec_strtab = strtab[ehdr.e_shstrndx];
+       sec_strtab = secs[ehdr.e_shstrndx].strtab;
        name = "<noname>";
        if (shndx < ehdr.e_shnum) {
-               name = sec_strtab + shdr[shndx].sh_name;
+               name = sec_strtab + secs[shndx].shdr.sh_name;
        }
        else if (shndx == SHN_ABS) {
                name = "ABSOLUTE";
@@ -159,7 +163,7 @@ static const char *sym_name(const char *sym_strtab, Elf32_Sym *sym)
                name = sym_strtab + sym->st_name;
        }
        else {
-               name = sec_name(shdr[sym->st_shndx].sh_name);
+               name = sec_name(secs[sym->st_shndx].shdr.sh_name);
        }
        return name;
 }
@@ -244,29 +248,34 @@ static void read_ehdr(FILE *fp)
 static void read_shdrs(FILE *fp)
 {
        int i;
-       if (ehdr.e_shnum > MAX_SHDRS) {
-               die("%d section headers supported: %d\n",
-                       ehdr.e_shnum, MAX_SHDRS);
+       Elf32_Shdr shdr;
+
+       secs = calloc(ehdr.e_shnum, sizeof(struct section));
+       if (!secs) {
+               die("Unable to allocate %d section headers\n",
+                   ehdr.e_shnum);
        }
        if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) {
                die("Seek to %d failed: %s\n",
                        ehdr.e_shoff, strerror(errno));
        }
-       if (fread(&shdr, sizeof(shdr[0]), ehdr.e_shnum, fp) != ehdr.e_shnum) {
-               die("Cannot read ELF section headers: %s\n",
-                       strerror(errno));
-       }
-       for(i = 0; i < ehdr.e_shnum; i++) {
-               shdr[i].sh_name      = elf32_to_cpu(shdr[i].sh_name);
-               shdr[i].sh_type      = elf32_to_cpu(shdr[i].sh_type);
-               shdr[i].sh_flags     = elf32_to_cpu(shdr[i].sh_flags);
-               shdr[i].sh_addr      = elf32_to_cpu(shdr[i].sh_addr);
-               shdr[i].sh_offset    = elf32_to_cpu(shdr[i].sh_offset);
-               shdr[i].sh_size      = elf32_to_cpu(shdr[i].sh_size);
-               shdr[i].sh_link      = elf32_to_cpu(shdr[i].sh_link);
-               shdr[i].sh_info      = elf32_to_cpu(shdr[i].sh_info);
-               shdr[i].sh_addralign = elf32_to_cpu(shdr[i].sh_addralign);
-               shdr[i].sh_entsize   = elf32_to_cpu(shdr[i].sh_entsize);
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
+               if (fread(&shdr, sizeof shdr, 1, fp) != 1)
+                       die("Cannot read ELF section headers %d/%d: %s\n",
+                           i, ehdr.e_shnum, strerror(errno));
+               sec->shdr.sh_name      = elf32_to_cpu(shdr.sh_name);
+               sec->shdr.sh_type      = elf32_to_cpu(shdr.sh_type);
+               sec->shdr.sh_flags     = elf32_to_cpu(shdr.sh_flags);
+               sec->shdr.sh_addr      = elf32_to_cpu(shdr.sh_addr);
+               sec->shdr.sh_offset    = elf32_to_cpu(shdr.sh_offset);
+               sec->shdr.sh_size      = elf32_to_cpu(shdr.sh_size);
+               sec->shdr.sh_link      = elf32_to_cpu(shdr.sh_link);
+               sec->shdr.sh_info      = elf32_to_cpu(shdr.sh_info);
+               sec->shdr.sh_addralign = elf32_to_cpu(shdr.sh_addralign);
+               sec->shdr.sh_entsize   = elf32_to_cpu(shdr.sh_entsize);
+               if (sec->shdr.sh_link < ehdr.e_shnum)
+                       sec->link = &secs[sec->shdr.sh_link];
        }
 
 }
@@ -274,20 +283,22 @@ static void read_shdrs(FILE *fp)
 static void read_strtabs(FILE *fp)
 {
        int i;
-       for(i = 0; i < ehdr.e_shnum; i++) {
-               if (shdr[i].sh_type != SHT_STRTAB) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
+               if (sec->shdr.sh_type != SHT_STRTAB) {
                        continue;
                }
-               strtab[i] = malloc(shdr[i].sh_size);
-               if (!strtab[i]) {
+               sec->strtab = malloc(sec->shdr.sh_size);
+               if (!sec->strtab) {
                        die("malloc of %d bytes for strtab failed\n",
-                               shdr[i].sh_size);
+                               sec->shdr.sh_size);
                }
-               if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
+               if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
                        die("Seek to %d failed: %s\n",
-                               shdr[i].sh_offset, strerror(errno));
+                               sec->shdr.sh_offset, strerror(errno));
                }
-               if (fread(strtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
+               if (fread(sec->strtab, 1, sec->shdr.sh_size, fp)
+                   != sec->shdr.sh_size) {
                        die("Cannot read symbol table: %s\n",
                                strerror(errno));
                }
@@ -297,28 +308,31 @@ static void read_strtabs(FILE *fp)
 static void read_symtabs(FILE *fp)
 {
        int i,j;
-       for(i = 0; i < ehdr.e_shnum; i++) {
-               if (shdr[i].sh_type != SHT_SYMTAB) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
+               if (sec->shdr.sh_type != SHT_SYMTAB) {
                        continue;
                }
-               symtab[i] = malloc(shdr[i].sh_size);
-               if (!symtab[i]) {
+               sec->symtab = malloc(sec->shdr.sh_size);
+               if (!sec->symtab) {
                        die("malloc of %d bytes for symtab failed\n",
-                               shdr[i].sh_size);
+                               sec->shdr.sh_size);
                }
-               if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
+               if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
                        die("Seek to %d failed: %s\n",
-                               shdr[i].sh_offset, strerror(errno));
+                               sec->shdr.sh_offset, strerror(errno));
                }
-               if (fread(symtab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
+               if (fread(sec->symtab, 1, sec->shdr.sh_size, fp)
+                   != sec->shdr.sh_size) {
                        die("Cannot read symbol table: %s\n",
                                strerror(errno));
                }
-               for(j = 0; j < shdr[i].sh_size/sizeof(symtab[i][0]); j++) {
-                       symtab[i][j].st_name  = elf32_to_cpu(symtab[i][j].st_name);
-                       symtab[i][j].st_value = elf32_to_cpu(symtab[i][j].st_value);
-                       symtab[i][j].st_size  = elf32_to_cpu(symtab[i][j].st_size);
-                       symtab[i][j].st_shndx = elf16_to_cpu(symtab[i][j].st_shndx);
+               for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) {
+                       Elf32_Sym *sym = &sec->symtab[j];
+                       sym->st_name  = elf32_to_cpu(sym->st_name);
+                       sym->st_value = elf32_to_cpu(sym->st_value);
+                       sym->st_size  = elf32_to_cpu(sym->st_size);
+                       sym->st_shndx = elf16_to_cpu(sym->st_shndx);
                }
        }
 }
@@ -327,26 +341,29 @@ static void read_symtabs(FILE *fp)
 static void read_relocs(FILE *fp)
 {
        int i,j;
-       for(i = 0; i < ehdr.e_shnum; i++) {
-               if (shdr[i].sh_type != SHT_REL) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
+               if (sec->shdr.sh_type != SHT_REL) {
                        continue;
                }
-               reltab[i] = malloc(shdr[i].sh_size);
-               if (!reltab[i]) {
+               sec->reltab = malloc(sec->shdr.sh_size);
+               if (!sec->reltab) {
                        die("malloc of %d bytes for relocs failed\n",
-                               shdr[i].sh_size);
+                               sec->shdr.sh_size);
                }
-               if (fseek(fp, shdr[i].sh_offset, SEEK_SET) < 0) {
+               if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) {
                        die("Seek to %d failed: %s\n",
-                               shdr[i].sh_offset, strerror(errno));
+                               sec->shdr.sh_offset, strerror(errno));
                }
-               if (fread(reltab[i], 1, shdr[i].sh_size, fp) != shdr[i].sh_size) {
+               if (fread(sec->reltab, 1, sec->shdr.sh_size, fp)
+                   != sec->shdr.sh_size) {
                        die("Cannot read symbol table: %s\n",
                                strerror(errno));
                }
-               for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
-                       reltab[i][j].r_offset = elf32_to_cpu(reltab[i][j].r_offset);
-                       reltab[i][j].r_info   = elf32_to_cpu(reltab[i][j].r_info);
+               for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
+                       Elf32_Rel *rel = &sec->reltab[j];
+                       rel->r_offset = elf32_to_cpu(rel->r_offset);
+                       rel->r_info   = elf32_to_cpu(rel->r_info);
                }
        }
 }
@@ -357,19 +374,21 @@ static void print_absolute_symbols(void)
        int i;
        printf("Absolute symbols\n");
        printf(" Num:    Value Size  Type       Bind        Visibility  Name\n");
-       for(i = 0; i < ehdr.e_shnum; i++) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
                char *sym_strtab;
                Elf32_Sym *sh_symtab;
                int j;
-               if (shdr[i].sh_type != SHT_SYMTAB) {
+
+               if (sec->shdr.sh_type != SHT_SYMTAB) {
                        continue;
                }
-               sh_symtab = symtab[i];
-               sym_strtab = strtab[shdr[i].sh_link];
-               for(j = 0; j < shdr[i].sh_size/sizeof(symtab[0][0]); j++) {
+               sh_symtab = sec->symtab;
+               sym_strtab = sec->link->strtab;
+               for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Sym); j++) {
                        Elf32_Sym *sym;
                        const char *name;
-                       sym = &symtab[i][j];
+                       sym = &sec->symtab[j];
                        name = sym_name(sym_strtab, sym);
                        if (sym->st_shndx != SHN_ABS) {
                                continue;
@@ -389,26 +408,27 @@ static void print_absolute_relocs(void)
 {
        int i, printed = 0;
 
-       for(i = 0; i < ehdr.e_shnum; i++) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
+               struct section *sec = &secs[i];
+               struct section *sec_applies, *sec_symtab;
                char *sym_strtab;
                Elf32_Sym *sh_symtab;
-               unsigned sec_applies, sec_symtab;
                int j;
-               if (shdr[i].sh_type != SHT_REL) {
+               if (sec->shdr.sh_type != SHT_REL) {
                        continue;
                }
-               sec_symtab  = shdr[i].sh_link;
-               sec_applies = shdr[i].sh_info;
-               if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
+               sec_symtab  = sec->link;
+               sec_applies = &secs[sec->shdr.sh_info];
+               if (!(sec_applies->shdr.sh_flags & SHF_ALLOC)) {
                        continue;
                }
-               sh_symtab = symtab[sec_symtab];
-               sym_strtab = strtab[shdr[sec_symtab].sh_link];
-               for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
+               sh_symtab  = sec_symtab->symtab;
+               sym_strtab = sec_symtab->link->strtab;
+               for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
                        Elf32_Rel *rel;
                        Elf32_Sym *sym;
                        const char *name;
-                       rel = &reltab[i][j];
+                       rel = &sec->reltab[j];
                        sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
                        name = sym_name(sym_strtab, sym);
                        if (sym->st_shndx != SHN_ABS) {
@@ -456,26 +476,28 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
 {
        int i;
        /* Walk through the relocations */
-       for(i = 0; i < ehdr.e_shnum; i++) {
+       for (i = 0; i < ehdr.e_shnum; i++) {
                char *sym_strtab;
                Elf32_Sym *sh_symtab;
-               unsigned sec_applies, sec_symtab;
+               struct section *sec_applies, *sec_symtab;
                int j;
-               if (shdr[i].sh_type != SHT_REL) {
+               struct section *sec = &secs[i];
+
+               if (sec->shdr.sh_type != SHT_REL) {
                        continue;
                }
-               sec_symtab  = shdr[i].sh_link;
-               sec_applies = shdr[i].sh_info;
-               if (!(shdr[sec_applies].sh_flags & SHF_ALLOC)) {
+               sec_symtab  = sec->link;
+               sec_applies = &secs[sec->shdr.sh_info];
+               if (!(sec_applies->shdr.sh_flags & SHF_ALLOC)) {
                        continue;
                }
-               sh_symtab = symtab[sec_symtab];
-               sym_strtab = strtab[shdr[sec_symtab].sh_link];
-               for(j = 0; j < shdr[i].sh_size/sizeof(reltab[0][0]); j++) {
+               sh_symtab = sec_symtab->symtab;
+               sym_strtab = sec->link->strtab;
+               for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
                        Elf32_Rel *rel;
                        Elf32_Sym *sym;
                        unsigned r_type;
-                       rel = &reltab[i][j];
+                       rel = &sec->reltab[j];
                        sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
                        r_type = ELF32_R_TYPE(rel->r_info);
                        /* Don't visit relocations to absolute symbols */
@@ -539,7 +561,7 @@ static void emit_relocs(int as_text)
                 */
                printf(".section \".data.reloc\",\"a\"\n");
                printf(".balign 4\n");
-               for(i = 0; i < reloc_count; i++) {
+               for (i = 0; i < reloc_count; i++) {
                        printf("\t .long 0x%08lx\n", relocs[i]);
                }
                printf("\n");
@@ -550,7 +572,7 @@ static void emit_relocs(int as_text)
                /* Print a stop */
                printf("%c%c%c%c", buf[0], buf[1], buf[2], buf[3]);
                /* Now print each relocation */
-               for(i = 0; i < reloc_count; i++) {
+               for (i = 0; i < reloc_count; i++) {
                        buf[0] = (relocs[i] >>  0) & 0xff;
                        buf[1] = (relocs[i] >>  8) & 0xff;
                        buf[2] = (relocs[i] >> 16) & 0xff;
@@ -577,7 +599,7 @@ int main(int argc, char **argv)
        show_absolute_relocs = 0;
        as_text = 0;
        fname = NULL;
-       for(i = 1; i < argc; i++) {
+       for (i = 1; i < argc; i++) {
                char *arg = argv[i];
                if (*arg == '-') {
                        if (strcmp(argv[1], "--abs-syms") == 0) {
index 00e19ed..92d6fd7 100644 (file)
@@ -28,6 +28,8 @@ static char *cpu_name(int level)
        if (level == 64) {
                return "x86-64";
        } else {
+               if (level == 15)
+                       level = 6;
                sprintf(buf, "i%d86", level);
                return buf;
        }
index 77569a4..2296164 100644 (file)
@@ -165,6 +165,10 @@ void main(void)
        /* Set the video mode */
        set_video();
 
+       /* Parse command line for 'quiet' and pass it to decompressor. */
+       if (cmdline_find_option_bool("quiet"))
+               boot_params.hdr.loadflags |= QUIET_FLAG;
+
        /* Do the last things and invoke protected mode */
        go_to_protected_mode();
 }
index acad32e..53165c9 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include "boot.h"
+#include <linux/kernel.h>
 
 #define SMAP   0x534d4150      /* ASCII "SMAP" */
 
@@ -53,7 +54,7 @@ static int detect_memory_e820(void)
 
                count++;
                desc++;
-       } while (next && count < E820MAX);
+       } while (next && count < ARRAY_SIZE(boot_params.e820_map));
 
        return boot_params.e820_entries = count;
 }
index ab049d4..141b6e2 100644 (file)
@@ -33,6 +33,8 @@ protected_mode_jump:
        movw    %cs, %bx
        shll    $4, %ebx
        addl    %ebx, 2f
+       jmp     1f                      # Short jump to serialize on 386/486
+1:
 
        movw    $__BOOT_DS, %cx
        movw    $__BOOT_TSS, %di
@@ -40,8 +42,6 @@ protected_mode_jump:
        movl    %cr0, %edx
        orb     $X86_CR0_PE, %dl        # Protected mode
        movl    %edx, %cr0
-       jmp     1f                      # Short jump to serialize on 386/486
-1:
 
        # Transition to 32-bit mode
        .byte   0x66, 0xea              # ljmpl opcode
index 40ecb8d..b939cb4 100644 (file)
@@ -259,8 +259,7 @@ static int vga_probe(void)
        return mode_count[adapter];
 }
 
-__videocard video_vga =
-{
+__videocard video_vga = {
        .card_name      = "VGA",
        .probe          = vga_probe,
        .set_mode       = vga_set_mode,
index ad7ddaa..9bc34e2 100644 (file)
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.22-git14
-# Fri Jul 20 09:53:15 2007
+# Linux kernel version: 2.6.26-rc1
+# Sun May  4 19:59:02 2008
 #
+# CONFIG_64BIT is not set
 CONFIG_X86_32=y
+# CONFIG_X86_64 is not set
+CONFIG_X86=y
+CONFIG_DEFCONFIG_LIST="arch/x86/configs/i386_defconfig"
+# CONFIG_GENERIC_LOCKBREAK is not set
 CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CMOS_UPDATE=y
 CONFIG_CLOCKSOURCE_WATCHDOG=y
 CONFIG_GENERIC_CLOCKEVENTS=y
 CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
 CONFIG_LOCKDEP_SUPPORT=y
 CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_SEMAPHORE_SLEEPERS=y
-CONFIG_X86=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_FAST_CMPXCHG_LOCAL=y
 CONFIG_MMU=y
 CONFIG_ZONE_DMA=y
-CONFIG_QUICKLIST=y
 CONFIG_GENERIC_ISA_DMA=y
 CONFIG_GENERIC_IOMAP=y
 CONFIG_GENERIC_BUG=y
 CONFIG_GENERIC_HWEIGHT=y
+# CONFIG_GENERIC_GPIO is not set
 CONFIG_ARCH_MAY_HAVE_PC_FDC=y
-CONFIG_DMI=y
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+# CONFIG_RWSEM_GENERIC_SPINLOCK is not set
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+# CONFIG_ARCH_HAS_ILOG2_U32 is not set
+# CONFIG_ARCH_HAS_ILOG2_U64 is not set
+CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+# CONFIG_GENERIC_TIME_VSYSCALL is not set
+CONFIG_ARCH_HAS_CPU_RELAX=y
+CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
+CONFIG_HAVE_SETUP_PER_CPU_AREA=y
+# CONFIG_HAVE_CPUMASK_OF_CPU_MAP is not set
+CONFIG_ARCH_HIBERNATION_POSSIBLE=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_ZONE_DMA32 is not set
+CONFIG_ARCH_POPULATES_NODE_MAP=y
+# CONFIG_AUDIT_ARCH is not set
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_GENERIC_PENDING_IRQ=y
+CONFIG_X86_SMP=y
+CONFIG_X86_32_SMP=y
+CONFIG_X86_HT=y
+CONFIG_X86_BIOS_REBOOT=y
+CONFIG_X86_TRAMPOLINE=y
+CONFIG_KTIME_SCALAR=y
 
 #
-# Code maturity level options
+# General setup
 #
 CONFIG_EXPERIMENTAL=y
 CONFIG_LOCK_KERNEL=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
 CONFIG_LOCALVERSION=""
-CONFIG_LOCALVERSION_AUTO=y
+# CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_POSIX_MQUEUE=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_USER_NS is not set
-# CONFIG_AUDIT is not set
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=18
-# CONFIG_CPUSETS is not set
-CONFIG_SYSFS_DEPRECATED=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+CONFIG_TASKSTATS=y
+CONFIG_TASK_DELAY_ACCT=y
+CONFIG_TASK_XACCT=y
+CONFIG_TASK_IO_ACCOUNTING=y
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_AUDIT_TREE=y
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+CONFIG_CGROUPS=y
+# CONFIG_CGROUP_DEBUG is not set
+CONFIG_CGROUP_NS=y
+# CONFIG_CGROUP_DEVICE is not set
+CONFIG_CPUSETS=y
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+# CONFIG_USER_SCHED is not set
+CONFIG_CGROUP_SCHED=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_RESOURCE_COUNTERS=y
+# CONFIG_CGROUP_MEM_RES_CTLR is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+CONFIG_PROC_PID_CPUSET=y
 CONFIG_RELAY=y
+CONFIG_NAMESPACES=y
+CONFIG_UTS_NS=y
+CONFIG_IPC_NS=y
+CONFIG_USER_NS=y
+CONFIG_PID_NS=y
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
@@ -56,13 +105,15 @@ CONFIG_SYSCTL=y
 # CONFIG_EMBEDDED is not set
 CONFIG_UID16=y
 CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_KALLSYMS=y
 CONFIG_KALLSYMS_ALL=y
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
 CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
 CONFIG_BUG=y
 CONFIG_ELF_CORE=y
+# CONFIG_COMPAT_BRK is not set
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
 CONFIG_ANON_INODES=y
@@ -76,6 +127,17 @@ CONFIG_SLUB_DEBUG=y
 # CONFIG_SLAB is not set
 CONFIG_SLUB=y
 # CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_MARKERS=y
+# CONFIG_OPROFILE is not set
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
@@ -87,10 +149,10 @@ CONFIG_MODULE_FORCE_UNLOAD=y
 # CONFIG_KMOD is not set
 CONFIG_STOP_MACHINE=y
 CONFIG_BLOCK=y
-CONFIG_LBD=y
-# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_LBD is not set
+CONFIG_BLK_DEV_IO_TRACE=y
 # CONFIG_LSF is not set
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_BLK_DEV_BSG=y
 
 #
 # IO Schedulers
@@ -103,7 +165,8 @@ CONFIG_IOSCHED_CFQ=y
 # CONFIG_DEFAULT_DEADLINE is not set
 CONFIG_DEFAULT_CFQ=y
 # CONFIG_DEFAULT_NOOP is not set
-CONFIG_DEFAULT_IOSCHED="anticipatory"
+CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
 
 #
 # Processor type and features
@@ -111,18 +174,21 @@ CONFIG_DEFAULT_IOSCHED="anticipatory"
 CONFIG_TICK_ONESHOT=y
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
 CONFIG_SMP=y
-# CONFIG_X86_PC is not set
+CONFIG_X86_PC=y
 # CONFIG_X86_ELAN is not set
 # CONFIG_X86_VOYAGER is not set
 # CONFIG_X86_NUMAQ is not set
 # CONFIG_X86_SUMMIT is not set
 # CONFIG_X86_BIGSMP is not set
 # CONFIG_X86_VISWS is not set
-CONFIG_X86_GENERICARCH=y
+# CONFIG_X86_GENERICARCH is not set
 # CONFIG_X86_ES7000 is not set
-# CONFIG_PARAVIRT is not set
-CONFIG_X86_CYCLONE_TIMER=y
+# CONFIG_X86_RDC321X is not set
+# CONFIG_X86_VSMP is not set
+CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
+# CONFIG_PARAVIRT_GUEST is not set
 # CONFIG_M386 is not set
 # CONFIG_M486 is not set
 # CONFIG_M586 is not set
@@ -130,9 +196,8 @@ CONFIG_X86_CYCLONE_TIMER=y
 # CONFIG_M586MMX is not set
 # CONFIG_M686 is not set
 # CONFIG_MPENTIUMII is not set
-CONFIG_MPENTIUMIII=y
+# CONFIG_MPENTIUMIII is not set
 # CONFIG_MPENTIUMM is not set
-# CONFIG_MCORE2 is not set
 # CONFIG_MPENTIUM4 is not set
 # CONFIG_MK6 is not set
 # CONFIG_MK7 is not set
@@ -147,14 +212,14 @@ CONFIG_MPENTIUMIII=y
 # CONFIG_MCYRIXIII is not set
 # CONFIG_MVIAC3_2 is not set
 # CONFIG_MVIAC7 is not set
-CONFIG_X86_GENERIC=y
+# CONFIG_MPSC is not set
+CONFIG_MCORE2=y
+# CONFIG_GENERIC_CPU is not set
+# CONFIG_X86_GENERIC is not set
+CONFIG_X86_CPU=y
 CONFIG_X86_CMPXCHG=y
-CONFIG_X86_L1_CACHE_SHIFT=7
+CONFIG_X86_L1_CACHE_SHIFT=6
 CONFIG_X86_XADD=y
-CONFIG_RWSEM_XCHGADD_ALGORITHM=y
-# CONFIG_ARCH_HAS_ILOG2_U32 is not set
-# CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_GENERIC_CALIBRATE_DELAY=y
 CONFIG_X86_WP_WORKS_OK=y
 CONFIG_X86_INVLPG=y
 CONFIG_X86_BSWAP=y
@@ -162,106 +227,120 @@ CONFIG_X86_POPAD_OK=y
 CONFIG_X86_GOOD_APIC=y
 CONFIG_X86_INTEL_USERCOPY=y
 CONFIG_X86_USE_PPRO_CHECKSUM=y
+CONFIG_X86_P6_NOP=y
 CONFIG_X86_TSC=y
-CONFIG_X86_CMOV=y
-CONFIG_X86_MINIMUM_CPU_FAMILY=4
+CONFIG_X86_MINIMUM_CPU_FAMILY=6
+CONFIG_X86_DEBUGCTLMSR=y
 CONFIG_HPET_TIMER=y
 CONFIG_HPET_EMULATE_RTC=y
-CONFIG_NR_CPUS=32
-CONFIG_SCHED_SMT=y
+CONFIG_DMI=y
+# CONFIG_IOMMU_HELPER is not set
+CONFIG_NR_CPUS=4
+# CONFIG_SCHED_SMT is not set
 CONFIG_SCHED_MC=y
 # CONFIG_PREEMPT_NONE is not set
 CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
-CONFIG_PREEMPT_BKL=y
 CONFIG_X86_LOCAL_APIC=y
 CONFIG_X86_IO_APIC=y
-CONFIG_X86_MCE=y
-CONFIG_X86_MCE_NONFATAL=y
-CONFIG_X86_MCE_P4THERMAL=y
+# CONFIG_X86_MCE is not set
 CONFIG_VM86=y
 # CONFIG_TOSHIBA is not set
 # CONFIG_I8K is not set
 # CONFIG_X86_REBOOTFIXUPS is not set
-CONFIG_MICROCODE=y
-CONFIG_MICROCODE_OLD_INTERFACE=y
+# CONFIG_MICROCODE is not set
 CONFIG_X86_MSR=y
 CONFIG_X86_CPUID=y
-
-#
-# Firmware Drivers
-#
-# CONFIG_EDD is not set
-# CONFIG_DELL_RBU is not set
-# CONFIG_DCDBAS is not set
-CONFIG_DMIID=y
 # CONFIG_NOHIGHMEM is not set
 CONFIG_HIGHMEM4G=y
 # CONFIG_HIGHMEM64G is not set
 CONFIG_PAGE_OFFSET=0xC0000000
 CONFIG_HIGHMEM=y
-CONFIG_ARCH_POPULATES_NODE_MAP=y
+CONFIG_NEED_NODE_MEMMAP_SIZE=y
+CONFIG_ARCH_FLATMEM_ENABLE=y
+CONFIG_ARCH_SPARSEMEM_ENABLE=y
+CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_SELECT_MEMORY_MODEL=y
-CONFIG_FLATMEM_MANUAL=y
+# CONFIG_FLATMEM_MANUAL is not set
 # CONFIG_DISCONTIGMEM_MANUAL is not set
-# CONFIG_SPARSEMEM_MANUAL is not set
-CONFIG_FLATMEM=y
-CONFIG_FLAT_NODE_MEM_MAP=y
-# CONFIG_SPARSEMEM_STATIC is not set
+CONFIG_SPARSEMEM_MANUAL=y
+CONFIG_SPARSEMEM=y
+CONFIG_HAVE_MEMORY_PRESENT=y
+CONFIG_SPARSEMEM_STATIC=y
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+
+#
+# Memory hotplug is currently incompatible with Software Suspend
+#
+CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_RESOURCES_64BIT=y
 CONFIG_ZONE_DMA_FLAG=1
 CONFIG_BOUNCE=y
-CONFIG_NR_QUICK=1
 CONFIG_VIRT_TO_BUS=y
 # CONFIG_HIGHPTE is not set
 # CONFIG_MATH_EMULATION is not set
 CONFIG_MTRR=y
-# CONFIG_EFI is not set
+# CONFIG_X86_PAT is not set
+CONFIG_EFI=y
 # CONFIG_IRQBALANCE is not set
 CONFIG_SECCOMP=y
 # CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
+# CONFIG_HZ_250 is not set
 # CONFIG_HZ_300 is not set
-# CONFIG_HZ_1000 is not set
-CONFIG_HZ=250
-# CONFIG_KEXEC is not set
-# CONFIG_CRASH_DUMP is not set
-CONFIG_PHYSICAL_START=0x100000
-# CONFIG_RELOCATABLE is not set
-CONFIG_PHYSICAL_ALIGN=0x100000
-# CONFIG_HOTPLUG_CPU is not set
-CONFIG_COMPAT_VDSO=y
+CONFIG_HZ_1000=y
+CONFIG_HZ=1000
+CONFIG_SCHED_HRTICK=y
+CONFIG_KEXEC=y
+CONFIG_CRASH_DUMP=y
+CONFIG_PHYSICAL_START=0x1000000
+CONFIG_RELOCATABLE=y
+CONFIG_PHYSICAL_ALIGN=0x200000
+CONFIG_HOTPLUG_CPU=y
+# CONFIG_COMPAT_VDSO is not set
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 
 #
-# Power management options (ACPI, APM)
+# Power management options
 #
 CONFIG_PM=y
-CONFIG_PM_LEGACY=y
-# CONFIG_PM_DEBUG is not set
-
-#
-# ACPI (Advanced Configuration and Power Interface) Support
-#
+CONFIG_PM_DEBUG=y
+# CONFIG_PM_VERBOSE is not set
+CONFIG_CAN_PM_TRACE=y
+CONFIG_PM_TRACE=y
+CONFIG_PM_TRACE_RTC=y
+CONFIG_PM_SLEEP_SMP=y
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND=y
+CONFIG_SUSPEND_FREEZER=y
+CONFIG_HIBERNATION=y
+CONFIG_PM_STD_PARTITION=""
 CONFIG_ACPI=y
+CONFIG_ACPI_SLEEP=y
 CONFIG_ACPI_PROCFS=y
+CONFIG_ACPI_PROCFS_POWER=y
+CONFIG_ACPI_SYSFS_POWER=y
+CONFIG_ACPI_PROC_EVENT=y
 CONFIG_ACPI_AC=y
 CONFIG_ACPI_BATTERY=y
 CONFIG_ACPI_BUTTON=y
 CONFIG_ACPI_FAN=y
-# CONFIG_ACPI_DOCK is not set
+CONFIG_ACPI_DOCK=y
+# CONFIG_ACPI_BAY is not set
 CONFIG_ACPI_PROCESSOR=y
+CONFIG_ACPI_HOTPLUG_CPU=y
 CONFIG_ACPI_THERMAL=y
+# CONFIG_ACPI_WMI is not set
 # CONFIG_ACPI_ASUS is not set
 # CONFIG_ACPI_TOSHIBA is not set
-CONFIG_ACPI_BLACKLIST_YEAR=2001
-CONFIG_ACPI_DEBUG=y
+# CONFIG_ACPI_CUSTOM_DSDT is not set
+CONFIG_ACPI_BLACKLIST_YEAR=0
+# CONFIG_ACPI_DEBUG is not set
 CONFIG_ACPI_EC=y
 CONFIG_ACPI_POWER=y
 CONFIG_ACPI_SYSTEM=y
 CONFIG_X86_PM_TIMER=y
-# CONFIG_ACPI_CONTAINER is not set
+CONFIG_ACPI_CONTAINER=y
 # CONFIG_ACPI_SBS is not set
 # CONFIG_APM is not set
 
@@ -271,15 +350,17 @@ CONFIG_X86_PM_TIMER=y
 CONFIG_CPU_FREQ=y
 CONFIG_CPU_FREQ_TABLE=y
 CONFIG_CPU_FREQ_DEBUG=y
-CONFIG_CPU_FREQ_STAT=y
-# CONFIG_CPU_FREQ_STAT_DETAILS is not set
-CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
-# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
+# CONFIG_CPU_FREQ_STAT is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
+CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
+# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
 CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
 # CONFIG_CPU_FREQ_GOV_POWERSAVE is not set
 CONFIG_CPU_FREQ_GOV_USERSPACE=y
 CONFIG_CPU_FREQ_GOV_ONDEMAND=y
-CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
+# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
 
 #
 # CPUFreq processor drivers
@@ -287,8 +368,7 @@ CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
 CONFIG_X86_ACPI_CPUFREQ=y
 # CONFIG_X86_POWERNOW_K6 is not set
 # CONFIG_X86_POWERNOW_K7 is not set
-CONFIG_X86_POWERNOW_K8=y
-CONFIG_X86_POWERNOW_K8_ACPI=y
+# CONFIG_X86_POWERNOW_K8 is not set
 # CONFIG_X86_GX_SUSPMOD is not set
 # CONFIG_X86_SPEEDSTEP_CENTRINO is not set
 # CONFIG_X86_SPEEDSTEP_ICH is not set
@@ -302,43 +382,72 @@ CONFIG_X86_POWERNOW_K8_ACPI=y
 #
 # shared options
 #
-CONFIG_X86_ACPI_CPUFREQ_PROC_INTF=y
+# CONFIG_X86_ACPI_CPUFREQ_PROC_INTF is not set
 # CONFIG_X86_SPEEDSTEP_LIB is not set
+CONFIG_CPU_IDLE=y
+CONFIG_CPU_IDLE_GOV_LADDER=y
+CONFIG_CPU_IDLE_GOV_MENU=y
 
 #
-# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
+# Bus options (PCI etc.)
 #
 CONFIG_PCI=y
 # CONFIG_PCI_GOBIOS is not set
 # CONFIG_PCI_GOMMCONFIG is not set
 # CONFIG_PCI_GODIRECT is not set
 CONFIG_PCI_GOANY=y
+# CONFIG_PCI_GOOLPC is not set
 CONFIG_PCI_BIOS=y
 CONFIG_PCI_DIRECT=y
 CONFIG_PCI_MMCONFIG=y
-# CONFIG_PCIEPORTBUS is not set
+CONFIG_PCI_DOMAINS=y
+CONFIG_PCIEPORTBUS=y
+# CONFIG_HOTPLUG_PCI_PCIE is not set
+CONFIG_PCIEAER=y
+# CONFIG_PCIEASPM is not set
 CONFIG_ARCH_SUPPORTS_MSI=y
 CONFIG_PCI_MSI=y
+# CONFIG_PCI_LEGACY is not set
 # CONFIG_PCI_DEBUG is not set
-# CONFIG_HT_IRQ is not set
+CONFIG_HT_IRQ=y
 CONFIG_ISA_DMA_API=y
 # CONFIG_ISA is not set
 # CONFIG_MCA is not set
 # CONFIG_SCx200 is not set
+# CONFIG_OLPC is not set
 CONFIG_K8_NB=y
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
-# CONFIG_PCCARD is not set
-# CONFIG_HOTPLUG_PCI is not set
-
-#
-# Executable file formats
+CONFIG_PCCARD=y
+# CONFIG_PCMCIA_DEBUG is not set
+CONFIG_PCMCIA=y
+CONFIG_PCMCIA_LOAD_CIS=y
+CONFIG_PCMCIA_IOCTL=y
+CONFIG_CARDBUS=y
+
+#
+# PC-card bridges
+#
+CONFIG_YENTA=y
+CONFIG_YENTA_O2=y
+CONFIG_YENTA_RICOH=y
+CONFIG_YENTA_TI=y
+CONFIG_YENTA_ENE_TUNE=y
+CONFIG_YENTA_TOSHIBA=y
+# CONFIG_PD6729 is not set
+# CONFIG_I82092 is not set
+CONFIG_PCCARD_NONSTATIC=y
+CONFIG_HOTPLUG_PCI=y
+# CONFIG_HOTPLUG_PCI_FAKE is not set
+# CONFIG_HOTPLUG_PCI_IBM is not set
+# CONFIG_HOTPLUG_PCI_ACPI is not set
+# CONFIG_HOTPLUG_PCI_CPCI is not set
+# CONFIG_HOTPLUG_PCI_SHPC is not set
+
+#
+# Executable file formats / Emulations
 #
 CONFIG_BINFMT_ELF=y
 # CONFIG_BINFMT_AOUT is not set
-# CONFIG_BINFMT_MISC is not set
+CONFIG_BINFMT_MISC=y
 
 #
 # Networking
@@ -349,59 +458,142 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
+CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
-# CONFIG_XFRM_USER is not set
+CONFIG_XFRM_USER=y
 # CONFIG_XFRM_SUB_POLICY is not set
 # CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_ASK_IP_FIB_HASH=y
+# CONFIG_IP_FIB_TRIE is not set
 CONFIG_IP_FIB_HASH=y
-CONFIG_IP_PNP=y
-CONFIG_IP_PNP_DHCP=y
-# CONFIG_IP_PNP_BOOTP is not set
-# CONFIG_IP_PNP_RARP is not set
+CONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_ROUTE_MULTIPATH=y
+CONFIG_IP_ROUTE_VERBOSE=y
+# CONFIG_IP_PNP is not set
 # CONFIG_NET_IPIP is not set
 # CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
 # CONFIG_ARPD is not set
-# CONFIG_SYN_COOKIES is not set
+CONFIG_SYN_COOKIES=y
 # CONFIG_INET_AH is not set
 # CONFIG_INET_ESP is not set
 # CONFIG_INET_IPCOMP is not set
 # CONFIG_INET_XFRM_TUNNEL is not set
 CONFIG_INET_TUNNEL=y
-CONFIG_INET_XFRM_MODE_TRANSPORT=y
-CONFIG_INET_XFRM_MODE_TUNNEL=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
 # CONFIG_INET_XFRM_MODE_BEET is not set
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_INET_LRO=y
+# CONFIG_INET_DIAG is not set
+CONFIG_TCP_CONG_ADVANCED=y
+# CONFIG_TCP_CONG_BIC is not set
 CONFIG_TCP_CONG_CUBIC=y
+# CONFIG_TCP_CONG_WESTWOOD is not set
+# CONFIG_TCP_CONG_HTCP is not set
+# CONFIG_TCP_CONG_HSTCP is not set
+# CONFIG_TCP_CONG_HYBLA is not set
+# CONFIG_TCP_CONG_VEGAS is not set
+# CONFIG_TCP_CONG_SCALABLE is not set
+# CONFIG_TCP_CONG_LP is not set
+# CONFIG_TCP_CONG_VENO is not set
+# CONFIG_TCP_CONG_YEAH is not set
+# CONFIG_TCP_CONG_ILLINOIS is not set
+# CONFIG_DEFAULT_BIC is not set
+CONFIG_DEFAULT_CUBIC=y
+# CONFIG_DEFAULT_HTCP is not set
+# CONFIG_DEFAULT_VEGAS is not set
+# CONFIG_DEFAULT_WESTWOOD is not set
+# CONFIG_DEFAULT_RENO is not set
 CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
+CONFIG_TCP_MD5SIG=y
+# CONFIG_IP_VS is not set
 CONFIG_IPV6=y
 # CONFIG_IPV6_PRIVACY is not set
 # CONFIG_IPV6_ROUTER_PREF is not set
 # CONFIG_IPV6_OPTIMISTIC_DAD is not set
-# CONFIG_INET6_AH is not set
-# CONFIG_INET6_ESP is not set
+CONFIG_INET6_AH=y
+CONFIG_INET6_ESP=y
 # CONFIG_INET6_IPCOMP is not set
 # CONFIG_IPV6_MIP6 is not set
 # CONFIG_INET6_XFRM_TUNNEL is not set
 # CONFIG_INET6_TUNNEL is not set
 CONFIG_INET6_XFRM_MODE_TRANSPORT=y
 CONFIG_INET6_XFRM_MODE_TUNNEL=y
-# CONFIG_INET6_XFRM_MODE_BEET is not set
+CONFIG_INET6_XFRM_MODE_BEET=y
 # CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
 CONFIG_IPV6_SIT=y
+CONFIG_IPV6_NDISC_NODETYPE=y
 # CONFIG_IPV6_TUNNEL is not set
 # CONFIG_IPV6_MULTIPLE_TABLES is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETFILTER is not set
+# CONFIG_IPV6_MROUTE is not set
+CONFIG_NETLABEL=y
+CONFIG_NETWORK_SECMARK=y
+CONFIG_NETFILTER=y
+# CONFIG_NETFILTER_DEBUG is not set
+# CONFIG_NETFILTER_ADVANCED is not set
+
+#
+# Core Netfilter Configuration
+#
+CONFIG_NETFILTER_NETLINK=y
+CONFIG_NETFILTER_NETLINK_LOG=y
+CONFIG_NF_CONNTRACK=y
+CONFIG_NF_CONNTRACK_SECMARK=y
+CONFIG_NF_CONNTRACK_FTP=y
+CONFIG_NF_CONNTRACK_IRC=y
+CONFIG_NF_CONNTRACK_SIP=y
+CONFIG_NF_CT_NETLINK=y
+CONFIG_NETFILTER_XTABLES=y
+CONFIG_NETFILTER_XT_TARGET_MARK=y
+CONFIG_NETFILTER_XT_TARGET_NFLOG=y
+CONFIG_NETFILTER_XT_TARGET_SECMARK=y
+CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y
+CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
+CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
+CONFIG_NETFILTER_XT_MATCH_MARK=y
+CONFIG_NETFILTER_XT_MATCH_POLICY=y
+CONFIG_NETFILTER_XT_MATCH_STATE=y
+
+#
+# IP: Netfilter Configuration
+#
+CONFIG_NF_CONNTRACK_IPV4=y
+CONFIG_NF_CONNTRACK_PROC_COMPAT=y
+CONFIG_IP_NF_IPTABLES=y
+CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_TARGET_REJECT=y
+CONFIG_IP_NF_TARGET_LOG=y
+CONFIG_IP_NF_TARGET_ULOG=y
+CONFIG_NF_NAT=y
+CONFIG_NF_NAT_NEEDED=y
+CONFIG_IP_NF_TARGET_MASQUERADE=y
+CONFIG_NF_NAT_FTP=y
+CONFIG_NF_NAT_IRC=y
+# CONFIG_NF_NAT_TFTP is not set
+# CONFIG_NF_NAT_AMANDA is not set
+# CONFIG_NF_NAT_PPTP is not set
+# CONFIG_NF_NAT_H323 is not set
+CONFIG_NF_NAT_SIP=y
+CONFIG_IP_NF_MANGLE=y
+
+#
+# IPv6: Netfilter Configuration
+#
+CONFIG_NF_CONNTRACK_IPV6=y
+CONFIG_IP6_NF_IPTABLES=y
+CONFIG_IP6_NF_MATCH_IPV6HEADER=y
+CONFIG_IP6_NF_FILTER=y
+CONFIG_IP6_NF_TARGET_LOG=y
+CONFIG_IP6_NF_TARGET_REJECT=y
+CONFIG_IP6_NF_MANGLE=y
 # CONFIG_IP_DCCP is not set
 # CONFIG_IP_SCTP is not set
 # CONFIG_TIPC is not set
@@ -409,6 +601,7 @@ CONFIG_IPV6_SIT=y
 # CONFIG_BRIDGE is not set
 # CONFIG_VLAN_8021Q is not set
 # CONFIG_DECNET is not set
+CONFIG_LLC=y
 # CONFIG_LLC2 is not set
 # CONFIG_IPX is not set
 # CONFIG_ATALK is not set
@@ -416,28 +609,99 @@ CONFIG_IPV6_SIT=y
 # CONFIG_LAPB is not set
 # CONFIG_ECONET is not set
 # CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
+CONFIG_NET_SCHED=y
+
+#
+# Queueing/Scheduling
+#
+# CONFIG_NET_SCH_CBQ is not set
+# CONFIG_NET_SCH_HTB is not set
+# CONFIG_NET_SCH_HFSC is not set
+# CONFIG_NET_SCH_PRIO is not set
+# CONFIG_NET_SCH_RR is not set
+# CONFIG_NET_SCH_RED is not set
+# CONFIG_NET_SCH_SFQ is not set
+# CONFIG_NET_SCH_TEQL is not set
+# CONFIG_NET_SCH_TBF is not set
+# CONFIG_NET_SCH_GRED is not set
+# CONFIG_NET_SCH_DSMARK is not set
+# CONFIG_NET_SCH_NETEM is not set
+# CONFIG_NET_SCH_INGRESS is not set
+
+#
+# Classification
+#
+CONFIG_NET_CLS=y
+# CONFIG_NET_CLS_BASIC is not set
+# CONFIG_NET_CLS_TCINDEX is not set
+# CONFIG_NET_CLS_ROUTE4 is not set
+# CONFIG_NET_CLS_FW is not set
+# CONFIG_NET_CLS_U32 is not set
+# CONFIG_NET_CLS_RSVP is not set
+# CONFIG_NET_CLS_RSVP6 is not set
+# CONFIG_NET_CLS_FLOW is not set
+CONFIG_NET_EMATCH=y
+CONFIG_NET_EMATCH_STACK=32
+# CONFIG_NET_EMATCH_CMP is not set
+# CONFIG_NET_EMATCH_NBYTE is not set
+# CONFIG_NET_EMATCH_U32 is not set
+# CONFIG_NET_EMATCH_META is not set
+# CONFIG_NET_EMATCH_TEXT is not set
+CONFIG_NET_CLS_ACT=y
+# CONFIG_NET_ACT_POLICE is not set
+# CONFIG_NET_ACT_GACT is not set
+# CONFIG_NET_ACT_MIRRED is not set
+# CONFIG_NET_ACT_IPT is not set
+# CONFIG_NET_ACT_NAT is not set
+# CONFIG_NET_ACT_PEDIT is not set
+# CONFIG_NET_ACT_SIMP is not set
+CONFIG_NET_SCH_FIFO=y
 
 #
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_NET_TCPPROBE is not set
-# CONFIG_HAMRADIO is not set
+CONFIG_HAMRADIO=y
+
+#
+# Packet Radio protocols
+#
+# CONFIG_AX25 is not set
+# CONFIG_CAN is not set
 # CONFIG_IRDA is not set
 # CONFIG_BT is not set
 # CONFIG_AF_RXRPC is not set
+CONFIG_FIB_RULES=y
 
 #
 # Wireless
 #
-# CONFIG_CFG80211 is not set
-# CONFIG_WIRELESS_EXT is not set
-# CONFIG_MAC80211 is not set
+CONFIG_CFG80211=y
+CONFIG_NL80211=y
+CONFIG_WIRELESS_EXT=y
+CONFIG_MAC80211=y
+
+#
+# Rate control algorithm selection
+#
+CONFIG_MAC80211_RC_DEFAULT_PID=y
+# CONFIG_MAC80211_RC_DEFAULT_NONE is not set
+
+#
+# Selecting 'y' for an algorithm will
+#
+
+#
+# build the algorithm into mac80211.
+#
+CONFIG_MAC80211_RC_DEFAULT="pid"
+CONFIG_MAC80211_RC_PID=y
+# CONFIG_MAC80211_MESH is not set
+CONFIG_MAC80211_LEDS=y
+# CONFIG_MAC80211_DEBUGFS is not set
+# CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT is not set
+# CONFIG_MAC80211_DEBUG is not set
 # CONFIG_IEEE80211 is not set
 # CONFIG_RFKILL is not set
 # CONFIG_NET_9P is not set
@@ -449,13 +713,15 @@ CONFIG_IPV6_SIT=y
 #
 # Generic Driver Options
 #
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
 CONFIG_FW_LOADER=y
 # CONFIG_DEBUG_DRIVER is not set
-# CONFIG_DEBUG_DEVRES is not set
+CONFIG_DEBUG_DEVRES=y
 # CONFIG_SYS_HYPERVISOR is not set
-# CONFIG_CONNECTOR is not set
+CONFIG_CONNECTOR=y
+CONFIG_PROC_EVENTS=y
 # CONFIG_MTD is not set
 # CONFIG_PARPORT is not set
 CONFIG_PNP=y
@@ -466,7 +732,7 @@ CONFIG_PNP=y
 #
 CONFIG_PNPACPI=y
 CONFIG_BLK_DEV=y
-CONFIG_BLK_DEV_FD=y
+# CONFIG_BLK_DEV_FD is not set
 # CONFIG_BLK_CPQ_DA is not set
 # CONFIG_BLK_CPQ_CISS_DA is not set
 # CONFIG_BLK_DEV_DAC960 is not set
@@ -479,8 +745,8 @@ CONFIG_BLK_DEV_LOOP=y
 # CONFIG_BLK_DEV_UB is not set
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_COUNT=16
-CONFIG_BLK_DEV_RAM_SIZE=4096
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 CONFIG_MISC_DEVICES=y
@@ -489,73 +755,17 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_EEPROM_93CX6 is not set
 # CONFIG_SGI_IOC4 is not set
 # CONFIG_TIFM_CORE is not set
+# CONFIG_ACER_WMI is not set
+# CONFIG_ASUS_LAPTOP is not set
+# CONFIG_FUJITSU_LAPTOP is not set
+# CONFIG_TC1100_WMI is not set
+# CONFIG_MSI_LAPTOP is not set
 # CONFIG_SONY_LAPTOP is not set
 # CONFIG_THINKPAD_ACPI is not set
-CONFIG_IDE=y
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_IDE_SATA is not set
-# CONFIG_BLK_DEV_HD_IDE is not set
-CONFIG_BLK_DEV_IDEDISK=y
-CONFIG_IDEDISK_MULTI_MODE=y
-CONFIG_BLK_DEV_IDECD=y
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-CONFIG_BLK_DEV_IDEACPI=y
-# CONFIG_IDE_TASK_IOCTL is not set
-CONFIG_IDE_PROC_FS=y
-
-#
-# IDE chipset support/bugfixes
-#
-CONFIG_IDE_GENERIC=y
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_IDEPNP is not set
-CONFIG_BLK_DEV_IDEPCI=y
-# CONFIG_IDEPCI_SHARE_IRQ is not set
-CONFIG_IDEPCI_PCIBUS_ORDER=y
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_BLK_DEV_GENERIC is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-CONFIG_BLK_DEV_IDEDMA_PCI=y
-# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
-# CONFIG_IDEDMA_ONLYDISK is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-CONFIG_BLK_DEV_AMD74XX=y
-# CONFIG_BLK_DEV_ATIIXP is not set
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_TRIFLEX is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_CS5520 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_CS5535 is not set
-# CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_BLK_DEV_HPT366 is not set
-# CONFIG_BLK_DEV_JMICRON is not set
-# CONFIG_BLK_DEV_SC1200 is not set
-CONFIG_BLK_DEV_PIIX=y
-# CONFIG_BLK_DEV_IT8213 is not set
-# CONFIG_BLK_DEV_IT821X is not set
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_PDC202XX_OLD is not set
-# CONFIG_BLK_DEV_PDC202XX_NEW is not set
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SIIMAGE is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_SLC90E66 is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_VIA82CXXX is not set
-# CONFIG_BLK_DEV_TC86C001 is not set
-# CONFIG_IDE_ARM is not set
-CONFIG_BLK_DEV_IDEDMA=y
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_BLK_DEV_HD is not set
+# CONFIG_INTEL_MENLOW is not set
+# CONFIG_ENCLOSURE_SERVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
 
 #
 # SCSI device support
@@ -564,8 +774,8 @@ CONFIG_BLK_DEV_IDEDMA=y
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
 # CONFIG_SCSI_TGT is not set
-CONFIG_SCSI_NETLINK=y
-# CONFIG_SCSI_PROC_FS is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
 
 #
 # SCSI support type (disk, tape, CD-ROM)
@@ -574,7 +784,7 @@ CONFIG_BLK_DEV_SD=y
 # CONFIG_CHR_DEV_ST is not set
 # CONFIG_CHR_DEV_OSST is not set
 CONFIG_BLK_DEV_SR=y
-# CONFIG_BLK_DEV_SR_VENDOR is not set
+CONFIG_BLK_DEV_SR_VENDOR=y
 CONFIG_CHR_DEV_SG=y
 # CONFIG_CHR_DEV_SCH is not set
 
@@ -582,7 +792,7 @@ CONFIG_CHR_DEV_SG=y
 # Some SCSI devices (e.g. CD jukebox) support multiple LUNs
 #
 # CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
+CONFIG_SCSI_CONSTANTS=y
 # CONFIG_SCSI_LOGGING is not set
 # CONFIG_SCSI_SCAN_ASYNC is not set
 CONFIG_SCSI_WAIT_SCAN=m
@@ -591,81 +801,37 @@ CONFIG_SCSI_WAIT_SCAN=m
 # SCSI Transports
 #
 CONFIG_SCSI_SPI_ATTRS=y
-CONFIG_SCSI_FC_ATTRS=y
+# CONFIG_SCSI_FC_ATTRS is not set
 # CONFIG_SCSI_ISCSI_ATTRS is not set
 # CONFIG_SCSI_SAS_ATTRS is not set
 # CONFIG_SCSI_SAS_LIBSAS is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_ISCSI_TCP is not set
-CONFIG_BLK_DEV_3W_XXXX_RAID=y
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AACRAID is not set
-CONFIG_SCSI_AIC7XXX=y
-CONFIG_AIC7XXX_CMDS_PER_DEVICE=32
-CONFIG_AIC7XXX_RESET_DELAY_MS=5000
-CONFIG_AIC7XXX_DEBUG_ENABLE=y
-CONFIG_AIC7XXX_DEBUG_MASK=0
-CONFIG_AIC7XXX_REG_PRETTY_PRINT=y
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-CONFIG_SCSI_AIC79XX=y
-CONFIG_AIC79XX_CMDS_PER_DEVICE=32
-CONFIG_AIC79XX_RESET_DELAY_MS=4000
-# CONFIG_AIC79XX_DEBUG_ENABLE is not set
-CONFIG_AIC79XX_DEBUG_MASK=0
-# CONFIG_AIC79XX_REG_PRETTY_PRINT is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_DPT_I2O is not set
-# CONFIG_SCSI_ADVANSYS is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_IPR is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_LPFC is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_NSP32 is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_SCSI_SRP is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+# CONFIG_SCSI_LOWLEVEL is not set
+# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
 CONFIG_ATA=y
 # CONFIG_ATA_NONSTANDARD is not set
 CONFIG_ATA_ACPI=y
+CONFIG_SATA_PMP=y
 CONFIG_SATA_AHCI=y
-CONFIG_SATA_SVW=y
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
+# CONFIG_SATA_SVW is not set
 CONFIG_ATA_PIIX=y
 # CONFIG_SATA_MV is not set
-CONFIG_SATA_NV=y
+# CONFIG_SATA_NV is not set
 # CONFIG_PDC_ADMA is not set
 # CONFIG_SATA_QSTOR is not set
 # CONFIG_SATA_PROMISE is not set
 # CONFIG_SATA_SX4 is not set
-CONFIG_SATA_SIL=y
-# CONFIG_SATA_SIL24 is not set
+# CONFIG_SATA_SIL is not set
 # CONFIG_SATA_SIS is not set
 # CONFIG_SATA_ULI is not set
-CONFIG_SATA_VIA=y
+# CONFIG_SATA_VIA is not set
 # CONFIG_SATA_VITESSE is not set
 # CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ACPI is not set
 # CONFIG_PATA_ALI is not set
-# CONFIG_PATA_AMD is not set
+CONFIG_PATA_AMD=y
 # CONFIG_PATA_ARTOP is not set
 # CONFIG_PATA_ATIIXP is not set
 # CONFIG_PATA_CMD640_PCI is not set
@@ -673,6 +839,7 @@ CONFIG_SATA_VIA=y
 # CONFIG_PATA_CS5520 is not set
 # CONFIG_PATA_CS5530 is not set
 # CONFIG_PATA_CS5535 is not set
+# CONFIG_PATA_CS5536 is not set
 # CONFIG_PATA_CYPRESS is not set
 # CONFIG_PATA_EFAR is not set
 # CONFIG_ATA_GENERIC is not set
@@ -686,11 +853,14 @@ CONFIG_SATA_VIA=y
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
-# CONFIG_PATA_OLDPIIX is not set
+CONFIG_PATA_OLDPIIX=y
 # CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NINJA32 is not set
 # CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
 # CONFIG_PATA_OPTI is not set
 # CONFIG_PATA_OPTIDMA is not set
+# CONFIG_PATA_PCMCIA is not set
 # CONFIG_PATA_PDC_OLD is not set
 # CONFIG_PATA_RADISYS is not set
 # CONFIG_PATA_RZ1000 is not set
@@ -702,65 +872,42 @@ CONFIG_SATA_VIA=y
 # CONFIG_PATA_VIA is not set
 # CONFIG_PATA_WINBOND is not set
 CONFIG_MD=y
-# CONFIG_BLK_DEV_MD is not set
+CONFIG_BLK_DEV_MD=y
+# CONFIG_MD_LINEAR is not set
+# CONFIG_MD_RAID0 is not set
+# CONFIG_MD_RAID1 is not set
+# CONFIG_MD_RAID10 is not set
+# CONFIG_MD_RAID456 is not set
+# CONFIG_MD_MULTIPATH is not set
+# CONFIG_MD_FAULTY is not set
 CONFIG_BLK_DEV_DM=y
 # CONFIG_DM_DEBUG is not set
 # CONFIG_DM_CRYPT is not set
 # CONFIG_DM_SNAPSHOT is not set
-# CONFIG_DM_MIRROR is not set
-# CONFIG_DM_ZERO is not set
+CONFIG_DM_MIRROR=y
+CONFIG_DM_ZERO=y
 # CONFIG_DM_MULTIPATH is not set
 # CONFIG_DM_DELAY is not set
-
-#
-# Fusion MPT device support
-#
-CONFIG_FUSION=y
-CONFIG_FUSION_SPI=y
-# CONFIG_FUSION_FC is not set
-# CONFIG_FUSION_SAS is not set
-CONFIG_FUSION_MAX_SGE=128
-# CONFIG_FUSION_CTL is not set
+# CONFIG_DM_UEVENT is not set
+# CONFIG_FUSION is not set
 
 #
 # IEEE 1394 (FireWire) support
 #
 # CONFIG_FIREWIRE is not set
-CONFIG_IEEE1394=y
-
-#
-# Subsystem Options
-#
-# CONFIG_IEEE1394_VERBOSEDEBUG is not set
-
-#
-# Controllers
-#
-
-#
-# Texas Instruments PCILynx requires I2C
-#
-CONFIG_IEEE1394_OHCI1394=y
-
-#
-# Protocols
-#
-# CONFIG_IEEE1394_VIDEO1394 is not set
-# CONFIG_IEEE1394_SBP2 is not set
-# CONFIG_IEEE1394_ETH1394_ROM_ENTRY is not set
-# CONFIG_IEEE1394_ETH1394 is not set
-# CONFIG_IEEE1394_DV1394 is not set
-CONFIG_IEEE1394_RAWIO=y
+# CONFIG_IEEE1394 is not set
 # CONFIG_I2O is not set
 CONFIG_MACINTOSH_DRIVERS=y
-# CONFIG_MAC_EMUMOUSEBTN is not set
+CONFIG_MAC_EMUMOUSEBTN=y
 CONFIG_NETDEVICES=y
-CONFIG_NETDEVICES_MULTIQUEUE=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_IFB is not set
 # CONFIG_DUMMY is not set
 # CONFIG_BONDING is not set
 # CONFIG_MACVLAN is not set
 # CONFIG_EQUALIZER is not set
 # CONFIG_TUN is not set
+# CONFIG_VETH is not set
 # CONFIG_NET_SB1000 is not set
 # CONFIG_ARCNET is not set
 # CONFIG_PHYLIB is not set
@@ -770,38 +917,40 @@ CONFIG_MII=y
 # CONFIG_SUNGEM is not set
 # CONFIG_CASSINI is not set
 CONFIG_NET_VENDOR_3COM=y
-CONFIG_VORTEX=y
+# CONFIG_VORTEX is not set
 # CONFIG_TYPHOON is not set
 CONFIG_NET_TULIP=y
 # CONFIG_DE2104X is not set
-CONFIG_TULIP=y
-# CONFIG_TULIP_MWI is not set
-# CONFIG_TULIP_MMIO is not set
-# CONFIG_TULIP_NAPI is not set
+# CONFIG_TULIP is not set
 # CONFIG_DE4X5 is not set
 # CONFIG_WINBOND_840 is not set
 # CONFIG_DM9102 is not set
 # CONFIG_ULI526X is not set
+# CONFIG_PCMCIA_XIRCOM is not set
 # CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
 CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
-CONFIG_B44=y
+# CONFIG_B44 is not set
 CONFIG_FORCEDETH=y
 # CONFIG_FORCEDETH_NAPI is not set
-# CONFIG_DGRS is not set
 # CONFIG_EEPRO100 is not set
 CONFIG_E100=y
 # CONFIG_FEALNX is not set
 # CONFIG_NATSEMI is not set
 # CONFIG_NE2K_PCI is not set
-CONFIG_8139CP=y
+# CONFIG_8139CP is not set
 CONFIG_8139TOO=y
-# CONFIG_8139TOO_PIO is not set
+CONFIG_8139TOO_PIO=y
 # CONFIG_8139TOO_TUNE_TWISTER is not set
 # CONFIG_8139TOO_8129 is not set
 # CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_R6040 is not set
 # CONFIG_SIS900 is not set
 # CONFIG_EPIC100 is not set
 # CONFIG_SUNDANCE is not set
@@ -814,34 +963,75 @@ CONFIG_NETDEV_1000=y
 CONFIG_E1000=y
 # CONFIG_E1000_NAPI is not set
 # CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
+# CONFIG_E1000E is not set
+# CONFIG_E1000E_ENABLED is not set
+# CONFIG_IP1000 is not set
+# CONFIG_IGB is not set
 # CONFIG_NS83820 is not set
 # CONFIG_HAMACHI is not set
 # CONFIG_YELLOWFIN is not set
-CONFIG_R8169=y
-# CONFIG_R8169_NAPI is not set
+# CONFIG_R8169 is not set
 # CONFIG_SIS190 is not set
 # CONFIG_SKGE is not set
 CONFIG_SKY2=y
+# CONFIG_SKY2_DEBUG is not set
 # CONFIG_VIA_VELOCITY is not set
 CONFIG_TIGON3=y
-CONFIG_BNX2=y
+# CONFIG_BNX2 is not set
 # CONFIG_QLA3XXX is not set
 # CONFIG_ATL1 is not set
 CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 # CONFIG_CHELSIO_T3 is not set
+# CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
 # CONFIG_S2IO is not set
 # CONFIG_MYRI10GE is not set
 # CONFIG_NETXEN_NIC is not set
+# CONFIG_NIU is not set
 # CONFIG_MLX4_CORE is not set
-# CONFIG_TR is not set
+# CONFIG_TEHUTI is not set
+# CONFIG_BNX2X is not set
+# CONFIG_SFC is not set
+CONFIG_TR=y
+# CONFIG_IBMOL is not set
+# CONFIG_IBMLS is not set
+# CONFIG_3C359 is not set
+# CONFIG_TMS380TR is not set
 
 #
 # Wireless LAN
 #
 # CONFIG_WLAN_PRE80211 is not set
-# CONFIG_WLAN_80211 is not set
+CONFIG_WLAN_80211=y
+# CONFIG_PCMCIA_RAYCS is not set
+# CONFIG_IPW2100 is not set
+# CONFIG_IPW2200 is not set
+# CONFIG_LIBERTAS is not set
+# CONFIG_AIRO is not set
+# CONFIG_HERMES is not set
+# CONFIG_ATMEL is not set
+# CONFIG_AIRO_CS is not set
+# CONFIG_PCMCIA_WL3501 is not set
+# CONFIG_PRISM54 is not set
+# CONFIG_USB_ZD1201 is not set
+# CONFIG_USB_NET_RNDIS_WLAN is not set
+# CONFIG_RTL8180 is not set
+# CONFIG_RTL8187 is not set
+# CONFIG_ADM8211 is not set
+# CONFIG_P54_COMMON is not set
+CONFIG_ATH5K=y
+# CONFIG_ATH5K_DEBUG is not set
+# CONFIG_IWLWIFI is not set
+# CONFIG_IWLCORE is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_IWL4965 is not set
+# CONFIG_IWL3945 is not set
+# CONFIG_HOSTAP is not set
+# CONFIG_B43 is not set
+# CONFIG_B43LEGACY is not set
+# CONFIG_ZD1211RW is not set
+# CONFIG_RT2X00 is not set
 
 #
 # USB Network Adapters
@@ -850,16 +1040,27 @@ CONFIG_NETDEV_10000=y
 # CONFIG_USB_KAWETH is not set
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_USBNET_MII is not set
 # CONFIG_USB_USBNET is not set
+CONFIG_NET_PCMCIA=y
+# CONFIG_PCMCIA_3C589 is not set
+# CONFIG_PCMCIA_3C574 is not set
+# CONFIG_PCMCIA_FMVJ18X is not set
+# CONFIG_PCMCIA_PCNET is not set
+# CONFIG_PCMCIA_NMCLAN is not set
+# CONFIG_PCMCIA_SMC91C92 is not set
+# CONFIG_PCMCIA_XIRC2PS is not set
+# CONFIG_PCMCIA_AXNET is not set
+# CONFIG_PCMCIA_IBMTR is not set
 # CONFIG_WAN is not set
-# CONFIG_FDDI is not set
+CONFIG_FDDI=y
+# CONFIG_DEFXX is not set
+# CONFIG_SKFP is not set
 # CONFIG_HIPPI is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
 # CONFIG_NET_FC is not set
-# CONFIG_SHAPER is not set
 CONFIG_NETCONSOLE=y
+# CONFIG_NETCONSOLE_DYNAMIC is not set
 CONFIG_NETPOLL=y
 # CONFIG_NETPOLL_TRAP is not set
 CONFIG_NET_POLL_CONTROLLER=y
@@ -870,18 +1071,17 @@ CONFIG_NET_POLL_CONTROLLER=y
 # Input device support
 #
 CONFIG_INPUT=y
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_POLLDEV is not set
+CONFIG_INPUT_FF_MEMLESS=y
+CONFIG_INPUT_POLLDEV=y
 
 #
 # Userland interfaces
 #
 CONFIG_INPUT_MOUSEDEV=y
-CONFIG_INPUT_MOUSEDEV_PSAUX=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
 CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
 CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 # CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
 CONFIG_INPUT_EVDEV=y
 # CONFIG_INPUT_EVBUG is not set
 
@@ -906,17 +1106,63 @@ CONFIG_MOUSE_PS2_TRACKPOINT=y
 # CONFIG_MOUSE_SERIAL is not set
 # CONFIG_MOUSE_APPLETOUCH is not set
 # CONFIG_MOUSE_VSXXXAA is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_TABLET is not set
-# CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_INPUT_MISC is not set
+CONFIG_INPUT_JOYSTICK=y
+# CONFIG_JOYSTICK_ANALOG is not set
+# CONFIG_JOYSTICK_A3D is not set
+# CONFIG_JOYSTICK_ADI is not set
+# CONFIG_JOYSTICK_COBRA is not set
+# CONFIG_JOYSTICK_GF2K is not set
+# CONFIG_JOYSTICK_GRIP is not set
+# CONFIG_JOYSTICK_GRIP_MP is not set
+# CONFIG_JOYSTICK_GUILLEMOT is not set
+# CONFIG_JOYSTICK_INTERACT is not set
+# CONFIG_JOYSTICK_SIDEWINDER is not set
+# CONFIG_JOYSTICK_TMDC is not set
+# CONFIG_JOYSTICK_IFORCE is not set
+# CONFIG_JOYSTICK_WARRIOR is not set
+# CONFIG_JOYSTICK_MAGELLAN is not set
+# CONFIG_JOYSTICK_SPACEORB is not set
+# CONFIG_JOYSTICK_SPACEBALL is not set
+# CONFIG_JOYSTICK_STINGER is not set
+# CONFIG_JOYSTICK_TWIDJOY is not set
+# CONFIG_JOYSTICK_ZHENHUA is not set
+# CONFIG_JOYSTICK_JOYDUMP is not set
+# CONFIG_JOYSTICK_XPAD is not set
+CONFIG_INPUT_TABLET=y
+# CONFIG_TABLET_USB_ACECAD is not set
+# CONFIG_TABLET_USB_AIPTEK is not set
+# CONFIG_TABLET_USB_GTCO is not set
+# CONFIG_TABLET_USB_KBTAB is not set
+# CONFIG_TABLET_USB_WACOM is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
+# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
+CONFIG_INPUT_MISC=y
+# CONFIG_INPUT_PCSPKR is not set
+# CONFIG_INPUT_APANEL is not set
+# CONFIG_INPUT_WISTRON_BTNS is not set
+# CONFIG_INPUT_ATLAS_BTNS is not set
+# CONFIG_INPUT_ATI_REMOTE is not set
+# CONFIG_INPUT_ATI_REMOTE2 is not set
+# CONFIG_INPUT_KEYSPAN_REMOTE is not set
+# CONFIG_INPUT_POWERMATE is not set
+# CONFIG_INPUT_YEALINK is not set
+# CONFIG_INPUT_UINPUT is not set
 
 #
 # Hardware I/O ports
 #
 CONFIG_SERIO=y
 CONFIG_SERIO_I8042=y
-# CONFIG_SERIO_SERPORT is not set
+CONFIG_SERIO_SERPORT=y
 # CONFIG_SERIO_CT82C710 is not set
 # CONFIG_SERIO_PCIPS2 is not set
 CONFIG_SERIO_LIBPS2=y
@@ -929,8 +1175,26 @@ CONFIG_SERIO_LIBPS2=y
 CONFIG_VT=y
 CONFIG_VT_CONSOLE=y
 CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
+CONFIG_VT_HW_CONSOLE_BINDING=y
+CONFIG_DEVKMEM=y
+CONFIG_SERIAL_NONSTANDARD=y
+# CONFIG_COMPUTONE is not set
+# CONFIG_ROCKETPORT is not set
+# CONFIG_CYCLADES is not set
+# CONFIG_DIGIEPCA is not set
+# CONFIG_MOXA_INTELLIO is not set
+# CONFIG_MOXA_SMARTIO is not set
+# CONFIG_ISI is not set
+# CONFIG_SYNCLINK is not set
+# CONFIG_SYNCLINKMP is not set
+# CONFIG_SYNCLINK_GT is not set
+# CONFIG_N_HDLC is not set
+# CONFIG_RISCOM8 is not set
+# CONFIG_SPECIALIX is not set
+# CONFIG_SX is not set
+# CONFIG_RIO is not set
+# CONFIG_STALDRV is not set
+# CONFIG_NOZOMI is not set
 
 #
 # Serial drivers
@@ -940,9 +1204,14 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_FIX_EARLYCON_MEM=y
 CONFIG_SERIAL_8250_PCI=y
 CONFIG_SERIAL_8250_PNP=y
-CONFIG_SERIAL_8250_NR_UARTS=4
+# CONFIG_SERIAL_8250_CS is not set
+CONFIG_SERIAL_8250_NR_UARTS=32
 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
-# CONFIG_SERIAL_8250_EXTENDED is not set
+CONFIG_SERIAL_8250_EXTENDED=y
+CONFIG_SERIAL_8250_MANY_PORTS=y
+CONFIG_SERIAL_8250_SHARE_IRQ=y
+CONFIG_SERIAL_8250_DETECT_IRQ=y
+CONFIG_SERIAL_8250_RSA=y
 
 #
 # Non-8250 serial port support
@@ -951,89 +1220,275 @@ CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
 CONFIG_UNIX98_PTYS=y
-CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
-# CONFIG_WATCHDOG is not set
 CONFIG_HW_RANDOM=y
-CONFIG_HW_RANDOM_INTEL=y
-CONFIG_HW_RANDOM_AMD=y
+# CONFIG_HW_RANDOM_INTEL is not set
+# CONFIG_HW_RANDOM_AMD is not set
 CONFIG_HW_RANDOM_GEODE=y
 CONFIG_HW_RANDOM_VIA=y
-# CONFIG_NVRAM is not set
-CONFIG_RTC=y
+CONFIG_NVRAM=y
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
 # CONFIG_SONYPI is not set
-CONFIG_AGP=y
-# CONFIG_AGP_ALI is not set
-# CONFIG_AGP_ATI is not set
-# CONFIG_AGP_AMD is not set
-CONFIG_AGP_AMD64=y
-CONFIG_AGP_INTEL=y
-# CONFIG_AGP_NVIDIA is not set
-# CONFIG_AGP_SIS is not set
-# CONFIG_AGP_SWORKS is not set
-# CONFIG_AGP_VIA is not set
-# CONFIG_AGP_EFFICEON is not set
-# CONFIG_DRM is not set
+
+#
+# PCMCIA character devices
+#
+# CONFIG_SYNCLINK_CS is not set
+# CONFIG_CARDMAN_4000 is not set
+# CONFIG_CARDMAN_4040 is not set
+# CONFIG_IPWIRELESS is not set
 # CONFIG_MWAVE is not set
 # CONFIG_PC8736x_GPIO is not set
 # CONFIG_NSC_GPIO is not set
 # CONFIG_CS5535_GPIO is not set
-CONFIG_RAW_DRIVER=y
-CONFIG_MAX_RAW_DEVS=256
+# CONFIG_RAW_DRIVER is not set
 CONFIG_HPET=y
 # CONFIG_HPET_RTC_IRQ is not set
-CONFIG_HPET_MMAP=y
+# CONFIG_HPET_MMAP is not set
 # CONFIG_HANGCHECK_TIMER is not set
 # CONFIG_TCG_TPM is not set
 # CONFIG_TELCLOCK is not set
 CONFIG_DEVPORT=y
-# CONFIG_I2C is not set
-
-#
-# SPI support
-#
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+# CONFIG_I2C_CHARDEV is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+CONFIG_I2C_I801=y
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_SCx200_ACB is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+# CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
 # CONFIG_W1 is not set
-# CONFIG_POWER_SUPPLY is not set
+CONFIG_POWER_SUPPLY=y
+# CONFIG_POWER_SUPPLY_DEBUG is not set
+# CONFIG_PDA_POWER is not set
+# CONFIG_BATTERY_DS2760 is not set
 # CONFIG_HWMON is not set
+CONFIG_THERMAL=y
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+# CONFIG_ACQUIRE_WDT is not set
+# CONFIG_ADVANTECH_WDT is not set
+# CONFIG_ALIM1535_WDT is not set
+# CONFIG_ALIM7101_WDT is not set
+# CONFIG_SC520_WDT is not set
+# CONFIG_EUROTECH_WDT is not set
+# CONFIG_IB700_WDT is not set
+# CONFIG_IBMASR is not set
+# CONFIG_WAFER_WDT is not set
+# CONFIG_I6300ESB_WDT is not set
+# CONFIG_ITCO_WDT is not set
+# CONFIG_IT8712F_WDT is not set
+# CONFIG_HP_WATCHDOG is not set
+# CONFIG_SC1200_WDT is not set
+# CONFIG_PC87413_WDT is not set
+# CONFIG_60XX_WDT is not set
+# CONFIG_SBC8360_WDT is not set
+# CONFIG_SBC7240_WDT is not set
+# CONFIG_CPU5_WDT is not set
+# CONFIG_SMSC37B787_WDT is not set
+# CONFIG_W83627HF_WDT is not set
+# CONFIG_W83697HF_WDT is not set
+# CONFIG_W83877F_WDT is not set
+# CONFIG_W83977F_WDT is not set
+# CONFIG_MACHZ_WDT is not set
+# CONFIG_SBC_EPX_C3_WATCHDOG is not set
+
+#
+# PCI-based Watchdog Cards
+#
+# CONFIG_PCIPCWATCHDOG is not set
+# CONFIG_WDTPCI is not set
+
+#
+# USB-based Watchdog Cards
+#
+# CONFIG_USBPCWATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
 
 #
 # Multifunction device drivers
 #
 # CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
 
 #
 # Multimedia devices
 #
+
+#
+# Multimedia core support
+#
 # CONFIG_VIDEO_DEV is not set
 # CONFIG_DVB_CORE is not set
+
+#
+# Multimedia drivers
+#
 CONFIG_DAB=y
 # CONFIG_USB_DABUSB is not set
 
 #
 # Graphics support
 #
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+CONFIG_AGP=y
+# CONFIG_AGP_ALI is not set
+# CONFIG_AGP_ATI is not set
+# CONFIG_AGP_AMD is not set
+CONFIG_AGP_AMD64=y
+CONFIG_AGP_INTEL=y
+# CONFIG_AGP_NVIDIA is not set
+# CONFIG_AGP_SIS is not set
+# CONFIG_AGP_SWORKS is not set
+# CONFIG_AGP_VIA is not set
+# CONFIG_AGP_EFFICEON is not set
+CONFIG_DRM=y
+# CONFIG_DRM_TDFX is not set
+# CONFIG_DRM_R128 is not set
+# CONFIG_DRM_RADEON is not set
+# CONFIG_DRM_I810 is not set
+# CONFIG_DRM_I830 is not set
+CONFIG_DRM_I915=y
+# CONFIG_DRM_MGA is not set
+# CONFIG_DRM_SIS is not set
+# CONFIG_DRM_VIA is not set
+# CONFIG_DRM_SAVAGE is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+CONFIG_FB_CFB_FILLRECT=y
+CONFIG_FB_CFB_COPYAREA=y
+CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+CONFIG_FB_DEFERRED_IO=y
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+CONFIG_FB_MODE_HELPERS=y
+CONFIG_FB_TILEBLITTING=y
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_CIRRUS is not set
+# CONFIG_FB_PM2 is not set
+# CONFIG_FB_CYBER2000 is not set
+# CONFIG_FB_ARC is not set
+# CONFIG_FB_ASILIANT is not set
+# CONFIG_FB_IMSTT is not set
+# CONFIG_FB_VGA16 is not set
+# CONFIG_FB_UVESA is not set
+# CONFIG_FB_VESA is not set
+CONFIG_FB_EFI=y
+# CONFIG_FB_IMAC is not set
+# CONFIG_FB_N411 is not set
+# CONFIG_FB_HGA is not set
+# CONFIG_FB_S1D13XXX is not set
+# CONFIG_FB_NVIDIA is not set
+# CONFIG_FB_RIVA is not set
+# CONFIG_FB_I810 is not set
+# CONFIG_FB_LE80578 is not set
+# CONFIG_FB_INTEL is not set
+# CONFIG_FB_MATROX is not set
+# CONFIG_FB_RADEON is not set
+# CONFIG_FB_ATY128 is not set
+# CONFIG_FB_ATY is not set
+# CONFIG_FB_S3 is not set
+# CONFIG_FB_SAVAGE is not set
+# CONFIG_FB_SIS is not set
+# CONFIG_FB_NEOMAGIC is not set
+# CONFIG_FB_KYRO is not set
+# CONFIG_FB_3DFX is not set
+# CONFIG_FB_VOODOO1 is not set
+# CONFIG_FB_VT8623 is not set
+# CONFIG_FB_CYBLA is not set
+# CONFIG_FB_TRIDENT is not set
+# CONFIG_FB_ARK is not set
+# CONFIG_FB_PM3 is not set
+# CONFIG_FB_GEODE is not set
+# CONFIG_FB_VIRTUAL is not set
+CONFIG_BACKLIGHT_LCD_SUPPORT=y
+# CONFIG_LCD_CLASS_DEVICE is not set
+CONFIG_BACKLIGHT_CLASS_DEVICE=y
+# CONFIG_BACKLIGHT_CORGI is not set
+# CONFIG_BACKLIGHT_PROGEAR is not set
 
 #
 # Display device support
 #
 # CONFIG_DISPLAY_SUPPORT is not set
-# CONFIG_VGASTATE is not set
-# CONFIG_FB is not set
 
 #
 # Console display driver support
 #
 CONFIG_VGA_CONSOLE=y
 CONFIG_VGACON_SOFT_SCROLLBACK=y
-CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=128
+CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64
 CONFIG_VIDEO_SELECT=y
 CONFIG_DUMMY_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE is not set
+CONFIG_LOGO=y
+# CONFIG_LOGO_LINUX_MONO is not set
+# CONFIG_LOGO_LINUX_VGA16 is not set
+CONFIG_LOGO_LINUX_CLUT224=y
 
 #
 # Sound
@@ -1043,33 +1498,167 @@ CONFIG_SOUND=y
 #
 # Advanced Linux Sound Architecture
 #
-# CONFIG_SND is not set
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+CONFIG_SND_HWDEP=y
+CONFIG_SND_SEQUENCER=y
+CONFIG_SND_SEQ_DUMMY=y
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=y
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_PCM_OSS_PLUGINS=y
+CONFIG_SND_SEQUENCER_OSS=y
+CONFIG_SND_DYNAMIC_MINORS=y
+CONFIG_SND_SUPPORT_OLD_API=y
+CONFIG_SND_VERBOSE_PROCFS=y
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+CONFIG_SND_VMASTER=y
+
+#
+# Generic devices
+#
+# CONFIG_SND_PCSP is not set
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_VIRMIDI is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# PCI devices
+#
+# CONFIG_SND_AD1889 is not set
+# CONFIG_SND_ALS300 is not set
+# CONFIG_SND_ALS4000 is not set
+# CONFIG_SND_ALI5451 is not set
+# CONFIG_SND_ATIIXP is not set
+# CONFIG_SND_ATIIXP_MODEM is not set
+# CONFIG_SND_AU8810 is not set
+# CONFIG_SND_AU8820 is not set
+# CONFIG_SND_AU8830 is not set
+# CONFIG_SND_AW2 is not set
+# CONFIG_SND_AZT3328 is not set
+# CONFIG_SND_BT87X is not set
+# CONFIG_SND_CA0106 is not set
+# CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_OXYGEN is not set
+# CONFIG_SND_CS4281 is not set
+# CONFIG_SND_CS46XX is not set
+# CONFIG_SND_CS5530 is not set
+# CONFIG_SND_CS5535AUDIO is not set
+# CONFIG_SND_DARLA20 is not set
+# CONFIG_SND_GINA20 is not set
+# CONFIG_SND_LAYLA20 is not set
+# CONFIG_SND_DARLA24 is not set
+# CONFIG_SND_GINA24 is not set
+# CONFIG_SND_LAYLA24 is not set
+# CONFIG_SND_MONA is not set
+# CONFIG_SND_MIA is not set
+# CONFIG_SND_ECHO3G is not set
+# CONFIG_SND_INDIGO is not set
+# CONFIG_SND_INDIGOIO is not set
+# CONFIG_SND_INDIGODJ is not set
+# CONFIG_SND_EMU10K1 is not set
+# CONFIG_SND_EMU10K1X is not set
+# CONFIG_SND_ENS1370 is not set
+# CONFIG_SND_ENS1371 is not set
+# CONFIG_SND_ES1938 is not set
+# CONFIG_SND_ES1968 is not set
+# CONFIG_SND_FM801 is not set
+CONFIG_SND_HDA_INTEL=y
+CONFIG_SND_HDA_HWDEP=y
+CONFIG_SND_HDA_CODEC_REALTEK=y
+CONFIG_SND_HDA_CODEC_ANALOG=y
+CONFIG_SND_HDA_CODEC_SIGMATEL=y
+CONFIG_SND_HDA_CODEC_VIA=y
+CONFIG_SND_HDA_CODEC_ATIHDMI=y
+CONFIG_SND_HDA_CODEC_CONEXANT=y
+CONFIG_SND_HDA_CODEC_CMEDIA=y
+CONFIG_SND_HDA_CODEC_SI3054=y
+CONFIG_SND_HDA_GENERIC=y
+# CONFIG_SND_HDA_POWER_SAVE is not set
+# CONFIG_SND_HDSP is not set
+# CONFIG_SND_HDSPM is not set
+# CONFIG_SND_HIFIER is not set
+# CONFIG_SND_ICE1712 is not set
+# CONFIG_SND_ICE1724 is not set
+# CONFIG_SND_INTEL8X0 is not set
+# CONFIG_SND_INTEL8X0M is not set
+# CONFIG_SND_KORG1212 is not set
+# CONFIG_SND_MAESTRO3 is not set
+# CONFIG_SND_MIXART is not set
+# CONFIG_SND_NM256 is not set
+# CONFIG_SND_PCXHR is not set
+# CONFIG_SND_RIPTIDE is not set
+# CONFIG_SND_RME32 is not set
+# CONFIG_SND_RME96 is not set
+# CONFIG_SND_RME9652 is not set
+# CONFIG_SND_SIS7019 is not set
+# CONFIG_SND_SONICVIBES is not set
+# CONFIG_SND_TRIDENT is not set
+# CONFIG_SND_VIA82XX is not set
+# CONFIG_SND_VIA82XX_MODEM is not set
+# CONFIG_SND_VIRTUOSO is not set
+# CONFIG_SND_VX222 is not set
+# CONFIG_SND_YMFPCI is not set
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_USX2Y is not set
+# CONFIG_SND_USB_CAIAQ is not set
+
+#
+# PCMCIA devices
+#
+# CONFIG_SND_VXPOCKET is not set
+# CONFIG_SND_PDAUDIOCF is not set
+
+#
+# System on Chip audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
+# ALSA SoC audio for Freescale SOCs
+#
+
+#
+# SoC Audio for the Texas Instruments OMAP
+#
 
 #
 # Open Sound System
 #
-CONFIG_SOUND_PRIME=y
-# CONFIG_SOUND_TRIDENT is not set
-# CONFIG_SOUND_MSNDCLAS is not set
-# CONFIG_SOUND_MSNDPIN is not set
-# CONFIG_SOUND_OSS is not set
+# CONFIG_SOUND_PRIME is not set
 CONFIG_HID_SUPPORT=y
 CONFIG_HID=y
-# CONFIG_HID_DEBUG is not set
+CONFIG_HID_DEBUG=y
+CONFIG_HIDRAW=y
 
 #
 # USB Input Devices
 #
 CONFIG_USB_HID=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_HID_FF is not set
-# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_HIDINPUT_POWERBOOK=y
+CONFIG_HID_FF=y
+CONFIG_HID_PID=y
+CONFIG_LOGITECH_FF=y
+# CONFIG_LOGIRUMBLEPAD2_FF is not set
+CONFIG_PANTHERLORD_FF=y
+CONFIG_THRUSTMASTER_FF=y
+CONFIG_ZEROPLUS_FF=y
+CONFIG_USB_HIDDEV=y
 CONFIG_USB_SUPPORT=y
 CONFIG_USB_ARCH_HAS_HCD=y
 CONFIG_USB_ARCH_HAS_OHCI=y
 CONFIG_USB_ARCH_HAS_EHCI=y
 CONFIG_USB=y
-# CONFIG_USB_DEBUG is not set
+CONFIG_USB_DEBUG=y
+CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
 
 #
 # Miscellaneous USB options
@@ -1077,18 +1666,18 @@ CONFIG_USB=y
 CONFIG_USB_DEVICEFS=y
 # CONFIG_USB_DEVICE_CLASS is not set
 # CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
-# CONFIG_USB_PERSIST is not set
+CONFIG_USB_SUSPEND=y
 # CONFIG_USB_OTG is not set
 
 #
 # USB Host Controller Drivers
 #
+# CONFIG_USB_C67X00_HCD is not set
 CONFIG_USB_EHCI_HCD=y
-# CONFIG_USB_EHCI_SPLIT_ISO is not set
 # CONFIG_USB_EHCI_ROOT_HUB_TT is not set
 # CONFIG_USB_EHCI_TT_NEWSCHED is not set
 # CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
 CONFIG_USB_OHCI_HCD=y
 # CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
 # CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
@@ -1121,8 +1710,10 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_STORAGE_SDDR55 is not set
 # CONFIG_USB_STORAGE_JUMPSHOT is not set
 # CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
 # CONFIG_USB_STORAGE_KARMA is not set
-# CONFIG_USB_LIBUSUAL is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+CONFIG_USB_LIBUSUAL=y
 
 #
 # USB Imaging devices
@@ -1134,10 +1725,6 @@ CONFIG_USB_MON=y
 #
 # USB port drivers
 #
-
-#
-# USB Serial Converter support
-#
 # CONFIG_USB_SERIAL is not set
 
 #
@@ -1163,90 +1750,125 @@ CONFIG_USB_MON=y
 # CONFIG_USB_TRANCEVIBRATOR is not set
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
 
 #
-# USB DSL modem support
+# LED drivers
 #
+# CONFIG_LEDS_CLEVO_MAIL is not set
 
 #
-# USB Gadget Support
+# LED Triggers
 #
-# CONFIG_USB_GADGET is not set
-# CONFIG_MMC is not set
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+# CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
+# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
+# CONFIG_ACCESSIBILITY is not set
+# CONFIG_INFINIBAND is not set
+CONFIG_EDAC=y
 
 #
-# LED devices
+# Reporting subsystems
 #
-# CONFIG_NEW_LEDS is not set
+# CONFIG_EDAC_DEBUG is not set
+# CONFIG_EDAC_MM_EDAC is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+# CONFIG_RTC_DEBUG is not set
 
 #
-# LED drivers
+# RTC interfaces
 #
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
 
 #
-# LED Triggers
+# I2C RTC drivers
 #
-# CONFIG_INFINIBAND is not set
-# CONFIG_EDAC is not set
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
 
 #
-# Real Time Clock
+# SPI RTC drivers
 #
-# CONFIG_RTC_CLASS is not set
 
 #
-# DMA Engine support
+# Platform RTC drivers
 #
-# CONFIG_DMA_ENGINE is not set
+CONFIG_RTC_DRV_CMOS=y
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
 
 #
-# DMA Clients
+# on-CPU RTC drivers
 #
+CONFIG_DMADEVICES=y
 
 #
 # DMA Devices
 #
-CONFIG_VIRTUALIZATION=y
-# CONFIG_KVM is not set
+# CONFIG_INTEL_IOATDMA is not set
+# CONFIG_UIO is not set
 
 #
-# Userspace I/O
+# Firmware Drivers
 #
-# CONFIG_UIO is not set
+# CONFIG_EDD is not set
+CONFIG_EFI_VARS=y
+# CONFIG_DELL_RBU is not set
+# CONFIG_DCDBAS is not set
+CONFIG_DMIID=y
+# CONFIG_ISCSI_IBFT_FIND is not set
 
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-CONFIG_EXT2_FS_POSIX_ACL=y
-# CONFIG_EXT2_FS_SECURITY is not set
-# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT2_FS is not set
 CONFIG_EXT3_FS=y
 CONFIG_EXT3_FS_XATTR=y
 CONFIG_EXT3_FS_POSIX_ACL=y
-# CONFIG_EXT3_FS_SECURITY is not set
+CONFIG_EXT3_FS_SECURITY=y
 # CONFIG_EXT4DEV_FS is not set
 CONFIG_JBD=y
 # CONFIG_JBD_DEBUG is not set
 CONFIG_FS_MBCACHE=y
-CONFIG_REISERFS_FS=y
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_REISERFS_PROC_INFO is not set
-CONFIG_REISERFS_FS_XATTR=y
-CONFIG_REISERFS_FS_POSIX_ACL=y
-# CONFIG_REISERFS_FS_SECURITY is not set
+# CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 CONFIG_FS_POSIX_ACL=y
 # CONFIG_XFS_FS is not set
-# CONFIG_GFS2_FS is not set
 # CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
+CONFIG_DNOTIFY=y
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
-# CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
+CONFIG_QUOTA=y
+CONFIG_QUOTA_NETLINK_INTERFACE=y
+# CONFIG_PRINT_QUOTA_WARNING is not set
+# CONFIG_QFMT_V1 is not set
+CONFIG_QFMT_V2=y
+CONFIG_QUOTACTL=y
 # CONFIG_AUTOFS_FS is not set
 CONFIG_AUTOFS4_FS=y
 # CONFIG_FUSE_FS is not set
@@ -1256,8 +1878,8 @@ CONFIG_GENERIC_ACL=y
 # CD-ROM/DVD Filesystems
 #
 CONFIG_ISO9660_FS=y
-# CONFIG_JOLIET is not set
-# CONFIG_ZISOFS is not set
+CONFIG_JOLIET=y
+CONFIG_ZISOFS=y
 # CONFIG_UDF_FS is not set
 
 #
@@ -1275,13 +1897,13 @@ CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
 #
 CONFIG_PROC_FS=y
 CONFIG_PROC_KCORE=y
+CONFIG_PROC_VMCORE=y
 CONFIG_PROC_SYSCTL=y
 CONFIG_SYSFS=y
 CONFIG_TMPFS=y
 CONFIG_TMPFS_POSIX_ACL=y
 CONFIG_HUGETLBFS=y
 CONFIG_HUGETLB_PAGE=y
-CONFIG_RAMFS=y
 # CONFIG_CONFIGFS_FS is not set
 
 #
@@ -1289,6 +1911,7 @@ CONFIG_RAMFS=y
 #
 # CONFIG_ADFS_FS is not set
 # CONFIG_AFFS_FS is not set
+# CONFIG_ECRYPT_FS is not set
 # CONFIG_HFS_FS is not set
 # CONFIG_HFSPLUS_FS is not set
 # CONFIG_BEFS_FS is not set
@@ -1296,33 +1919,15 @@ CONFIG_RAMFS=y
 # CONFIG_EFS_FS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
 # CONFIG_HPFS_FS is not set
 # CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-# CONFIG_NFSD_V3_ACL is not set
-# CONFIG_NFSD_V4 is not set
-CONFIG_NFSD_TCP=y
-CONFIG_ROOT_NFS=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-CONFIG_EXPORTFS=y
-CONFIG_NFS_COMMON=y
-CONFIG_SUNRPC=y
-# CONFIG_SUNRPC_BIND34 is not set
-# CONFIG_RPCSEC_GSS_KRB5 is not set
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+# CONFIG_NFS_FS is not set
+# CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
@@ -1332,14 +1937,26 @@ CONFIG_SUNRPC=y
 #
 # Partition Types
 #
-# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+CONFIG_OSF_PARTITION=y
+CONFIG_AMIGA_PARTITION=y
+# CONFIG_ATARI_PARTITION is not set
+CONFIG_MAC_PARTITION=y
 CONFIG_MSDOS_PARTITION=y
-
-#
-# Native Language Support
-#
+CONFIG_BSD_DISKLABEL=y
+CONFIG_MINIX_SUBPARTITION=y
+CONFIG_SOLARIS_X86_PARTITION=y
+CONFIG_UNIXWARE_DISKLABEL=y
+# CONFIG_LDM_PARTITION is not set
+CONFIG_SGI_PARTITION=y
+# CONFIG_ULTRIX_PARTITION is not set
+CONFIG_SUN_PARTITION=y
+CONFIG_KARMA_PARTITION=y
+CONFIG_EFI_PARTITION=y
+# CONFIG_SYSV68_PARTITION is not set
 CONFIG_NLS=y
-CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_DEFAULT="utf8"
 CONFIG_NLS_CODEPAGE_437=y
 # CONFIG_NLS_CODEPAGE_737 is not set
 # CONFIG_NLS_CODEPAGE_775 is not set
@@ -1374,37 +1991,33 @@ CONFIG_NLS_ISO8859_1=y
 # CONFIG_NLS_ISO8859_9 is not set
 # CONFIG_NLS_ISO8859_13 is not set
 # CONFIG_NLS_ISO8859_14 is not set
-CONFIG_NLS_ISO8859_15=y
+# CONFIG_NLS_ISO8859_15 is not set
 # CONFIG_NLS_KOI8_R is not set
 # CONFIG_NLS_KOI8_U is not set
 CONFIG_NLS_UTF8=y
-
-#
-# Distributed Lock Manager
-#
 # CONFIG_DLM is not set
-CONFIG_INSTRUMENTATION=y
-CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_KPROBES=y
 
 #
 # Kernel hacking
 #
 CONFIG_TRACE_IRQFLAGS_SUPPORT=y
 # CONFIG_PRINTK_TIME is not set
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
 # CONFIG_ENABLE_MUST_CHECK is not set
+CONFIG_FRAME_WARN=2048
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_UNUSED_SYMBOLS=y
-# CONFIG_DEBUG_FS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SHIRQ is not set
-CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_DETECT_SOFTLOCKUP is not set
 # CONFIG_SCHED_DEBUG is not set
-# CONFIG_SCHEDSTATS is not set
+CONFIG_SCHEDSTATS=y
 CONFIG_TIMER_STATS=y
+# CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1419,48 +2032,174 @@ CONFIG_TIMER_STATS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
 # CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
 # CONFIG_DEBUG_LIST is not set
-# CONFIG_FRAME_POINTER is not set
-CONFIG_OPTIMIZE_INLINING=y
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
 # CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+CONFIG_PROVIDE_OHCI1394_DMA_INIT=y
+# CONFIG_SAMPLES is not set
+# CONFIG_KGDB is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_NONPROMISC_DEVMEM is not set
 CONFIG_EARLY_PRINTK=y
 CONFIG_DEBUG_STACKOVERFLOW=y
-# CONFIG_DEBUG_STACK_USAGE is not set
-# CONFIG_DEBUG_RODATA is not set
+CONFIG_DEBUG_STACK_USAGE=y
+# CONFIG_DEBUG_PAGEALLOC is not set
+# CONFIG_X86_PTDUMP is not set
+CONFIG_DEBUG_RODATA=y
+# CONFIG_DEBUG_RODATA_TEST is not set
+CONFIG_DEBUG_NX_TEST=m
 # CONFIG_4KSTACKS is not set
 CONFIG_X86_FIND_SMP_CONFIG=y
 CONFIG_X86_MPPARSE=y
 CONFIG_DOUBLEFAULT=y
+CONFIG_IO_DELAY_TYPE_0X80=0
+CONFIG_IO_DELAY_TYPE_0XED=1
+CONFIG_IO_DELAY_TYPE_UDELAY=2
+CONFIG_IO_DELAY_TYPE_NONE=3
+CONFIG_IO_DELAY_0X80=y
+# CONFIG_IO_DELAY_0XED is not set
+# CONFIG_IO_DELAY_UDELAY is not set
+# CONFIG_IO_DELAY_NONE is not set
+CONFIG_DEFAULT_IO_DELAY_TYPE=0
+CONFIG_DEBUG_BOOT_PARAMS=y
+# CONFIG_CPA_DEBUG is not set
 
 #
 # Security options
 #
-# CONFIG_KEYS is not set
-# CONFIG_SECURITY is not set
-# CONFIG_CRYPTO is not set
+CONFIG_KEYS=y
+CONFIG_KEYS_DEBUG_PROC_KEYS=y
+CONFIG_SECURITY=y
+CONFIG_SECURITY_NETWORK=y
+# CONFIG_SECURITY_NETWORK_XFRM is not set
+CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_FILE_CAPABILITIES=y
+# CONFIG_SECURITY_ROOTPLUG is not set
+CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR=65536
+CONFIG_SECURITY_SELINUX=y
+CONFIG_SECURITY_SELINUX_BOOTPARAM=y
+CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
+CONFIG_SECURITY_SELINUX_DISABLE=y
+CONFIG_SECURITY_SELINUX_DEVELOP=y
+CONFIG_SECURITY_SELINUX_AVC_STATS=y
+CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1
+# CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT is not set
+# CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX is not set
+# CONFIG_SECURITY_SMACK is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_AEAD=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_HASH=y
+CONFIG_CRYPTO_MANAGER=y
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_AUTHENC=y
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=y
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=y
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+CONFIG_CRYPTO_HMAC=y
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+CONFIG_CRYPTO_SHA1=y
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+CONFIG_CRYPTO_AES=y
+# CONFIG_CRYPTO_AES_586 is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+CONFIG_CRYPTO_ARC4=y
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SALSA20_586 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+# CONFIG_CRYPTO_TWOFISH_586 is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+# CONFIG_CRYPTO_DEV_PADLOCK is not set
+# CONFIG_CRYPTO_DEV_GEODE is not set
+# CONFIG_CRYPTO_DEV_HIFN_795X is not set
+CONFIG_HAVE_KVM=y
+CONFIG_VIRTUALIZATION=y
+# CONFIG_KVM is not set
+# CONFIG_LGUEST is not set
+# CONFIG_VIRTIO_PCI is not set
+# CONFIG_VIRTIO_BALLOON is not set
 
 #
 # Library routines
 #
 CONFIG_BITREVERSE=y
+CONFIG_GENERIC_FIND_FIRST_BIT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
 # CONFIG_CRC_CCITT is not set
 # CONFIG_CRC16 is not set
 # CONFIG_CRC_ITU_T is not set
 CONFIG_CRC32=y
 # CONFIG_CRC7 is not set
 # CONFIG_LIBCRC32C is not set
+CONFIG_AUDIT_GENERIC=y
 CONFIG_ZLIB_INFLATE=y
 CONFIG_PLIST=y
 CONFIG_HAS_IOMEM=y
 CONFIG_HAS_IOPORT=y
 CONFIG_HAS_DMA=y
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_GENERIC_PENDING_IRQ=y
-CONFIG_X86_SMP=y
-CONFIG_X86_HT=y
-CONFIG_X86_BIOS_REBOOT=y
-CONFIG_X86_TRAMPOLINE=y
-CONFIG_KTIME_SCALAR=y
index 2d6f5b2..ae5124e 100644 (file)
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.22-git14
-# Fri Jul 20 09:53:15 2007
+# Linux kernel version: 2.6.26-rc1
+# Sun May  4 19:59:57 2008
 #
-CONFIG_X86_64=y
 CONFIG_64BIT=y
+# CONFIG_X86_32 is not set
+CONFIG_X86_64=y
 CONFIG_X86=y
+CONFIG_DEFCONFIG_LIST="arch/x86/configs/x86_64_defconfig"
+# CONFIG_GENERIC_LOCKBREAK is not set
 CONFIG_GENERIC_TIME=y
-CONFIG_GENERIC_TIME_VSYSCALL=y
 CONFIG_GENERIC_CMOS_UPDATE=y
-CONFIG_ZONE_DMA32=y
+CONFIG_CLOCKSOURCE_WATCHDOG=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
 CONFIG_LOCKDEP_SUPPORT=y
 CONFIG_STACKTRACE_SUPPORT=y
-CONFIG_SEMAPHORE_SLEEPERS=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_FAST_CMPXCHG_LOCAL=y
 CONFIG_MMU=y
 CONFIG_ZONE_DMA=y
-CONFIG_QUICKLIST=y
-CONFIG_NR_QUICK=2
-CONFIG_RWSEM_GENERIC_SPINLOCK=y
-CONFIG_GENERIC_HWEIGHT=y
-CONFIG_GENERIC_CALIBRATE_DELAY=y
-CONFIG_X86_CMPXCHG=y
-CONFIG_EARLY_PRINTK=y
 CONFIG_GENERIC_ISA_DMA=y
 CONFIG_GENERIC_IOMAP=y
-CONFIG_ARCH_MAY_HAVE_PC_FDC=y
-CONFIG_ARCH_POPULATES_NODE_MAP=y
-CONFIG_DMI=y
-CONFIG_AUDIT_ARCH=y
 CONFIG_GENERIC_BUG=y
+CONFIG_GENERIC_HWEIGHT=y
+# CONFIG_GENERIC_GPIO is not set
+CONFIG_ARCH_MAY_HAVE_PC_FDC=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
 # CONFIG_ARCH_HAS_ILOG2_U32 is not set
 # CONFIG_ARCH_HAS_ILOG2_U64 is not set
-CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_TIME_VSYSCALL=y
+CONFIG_ARCH_HAS_CPU_RELAX=y
+CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
+CONFIG_HAVE_SETUP_PER_CPU_AREA=y
+CONFIG_HAVE_CPUMASK_OF_CPU_MAP=y
+CONFIG_ARCH_HIBERNATION_POSSIBLE=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+CONFIG_ZONE_DMA32=y
+CONFIG_ARCH_POPULATES_NODE_MAP=y
+CONFIG_AUDIT_ARCH=y
+CONFIG_ARCH_SUPPORTS_AOUT=y
+CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_GENERIC_PENDING_IRQ=y
+CONFIG_X86_SMP=y
+CONFIG_X86_64_SMP=y
+CONFIG_X86_HT=y
+CONFIG_X86_BIOS_REBOOT=y
+CONFIG_X86_TRAMPOLINE=y
+# CONFIG_KTIME_SCALAR is not set
 
 #
-# Code maturity level options
+# General setup
 #
 CONFIG_EXPERIMENTAL=y
 CONFIG_LOCK_KERNEL=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
-
-#
-# General setup
-#
 CONFIG_LOCALVERSION=""
-CONFIG_LOCALVERSION_AUTO=y
+# CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_POSIX_MQUEUE=y
-# CONFIG_BSD_PROCESS_ACCT is not set
-# CONFIG_TASKSTATS is not set
-# CONFIG_USER_NS is not set
-# CONFIG_AUDIT is not set
-CONFIG_IKCONFIG=y
-CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=18
-# CONFIG_CPUSETS is not set
-CONFIG_SYSFS_DEPRECATED=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+CONFIG_TASKSTATS=y
+CONFIG_TASK_DELAY_ACCT=y
+CONFIG_TASK_XACCT=y
+CONFIG_TASK_IO_ACCOUNTING=y
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_AUDIT_TREE=y
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+CONFIG_CGROUPS=y
+# CONFIG_CGROUP_DEBUG is not set
+CONFIG_CGROUP_NS=y
+# CONFIG_CGROUP_DEVICE is not set
+CONFIG_CPUSETS=y
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+# CONFIG_USER_SCHED is not set
+CONFIG_CGROUP_SCHED=y
+CONFIG_CGROUP_CPUACCT=y
+CONFIG_RESOURCE_COUNTERS=y
+# CONFIG_CGROUP_MEM_RES_CTLR is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+CONFIG_PROC_PID_CPUSET=y
 CONFIG_RELAY=y
+CONFIG_NAMESPACES=y
+CONFIG_UTS_NS=y
+CONFIG_IPC_NS=y
+CONFIG_USER_NS=y
+CONFIG_PID_NS=y
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_INITRAMFS_SOURCE=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
@@ -66,13 +105,15 @@ CONFIG_SYSCTL=y
 # CONFIG_EMBEDDED is not set
 CONFIG_UID16=y
 CONFIG_SYSCTL_SYSCALL=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_KALLSYMS=y
 CONFIG_KALLSYMS_ALL=y
-# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
 CONFIG_HOTPLUG=y
 CONFIG_PRINTK=y
 CONFIG_BUG=y
 CONFIG_ELF_CORE=y
+# CONFIG_COMPAT_BRK is not set
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
 CONFIG_ANON_INODES=y
@@ -82,9 +123,21 @@ CONFIG_TIMERFD=y
 CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
 CONFIG_VM_EVENT_COUNTERS=y
-CONFIG_SLAB=y
-# CONFIG_SLUB is not set
+CONFIG_SLUB_DEBUG=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
 # CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_MARKERS=y
+# CONFIG_OPROFILE is not set
+CONFIG_HAVE_OPROFILE=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_DMA_ATTRS is not set
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
 # CONFIG_TINY_SHMEM is not set
 CONFIG_BASE_SMALL=0
@@ -96,14 +149,15 @@ CONFIG_MODULE_FORCE_UNLOAD=y
 # CONFIG_KMOD is not set
 CONFIG_STOP_MACHINE=y
 CONFIG_BLOCK=y
-# CONFIG_BLK_DEV_IO_TRACE is not set
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_BLK_DEV_IO_TRACE=y
+CONFIG_BLK_DEV_BSG=y
+CONFIG_BLOCK_COMPAT=y
 
 #
 # IO Schedulers
 #
 CONFIG_IOSCHED_NOOP=y
-# CONFIG_IOSCHED_AS is not set
+CONFIG_IOSCHED_AS=y
 CONFIG_IOSCHED_DEADLINE=y
 CONFIG_IOSCHED_CFQ=y
 # CONFIG_DEFAULT_AS is not set
@@ -111,107 +165,177 @@ CONFIG_IOSCHED_CFQ=y
 CONFIG_DEFAULT_CFQ=y
 # CONFIG_DEFAULT_NOOP is not set
 CONFIG_DEFAULT_IOSCHED="cfq"
+CONFIG_CLASSIC_RCU=y
 
 #
 # Processor type and features
 #
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_SMP=y
 CONFIG_X86_PC=y
+# CONFIG_X86_ELAN is not set
+# CONFIG_X86_VOYAGER is not set
+# CONFIG_X86_NUMAQ is not set
+# CONFIG_X86_SUMMIT is not set
+# CONFIG_X86_BIGSMP is not set
+# CONFIG_X86_VISWS is not set
+# CONFIG_X86_GENERICARCH is not set
+# CONFIG_X86_ES7000 is not set
+# CONFIG_X86_RDC321X is not set
 # CONFIG_X86_VSMP is not set
+# CONFIG_PARAVIRT_GUEST is not set
+CONFIG_MEMTEST_BOOTPARAM=y
+CONFIG_MEMTEST_BOOTPARAM_VALUE=0
+# CONFIG_M386 is not set
+# CONFIG_M486 is not set
+# CONFIG_M586 is not set
+# CONFIG_M586TSC is not set
+# CONFIG_M586MMX is not set
+# CONFIG_M686 is not set
+# CONFIG_MPENTIUMII is not set
+# CONFIG_MPENTIUMIII is not set
+# CONFIG_MPENTIUMM is not set
+# CONFIG_MPENTIUM4 is not set
+# CONFIG_MK6 is not set
+# CONFIG_MK7 is not set
 # CONFIG_MK8 is not set
+# CONFIG_MCRUSOE is not set
+# CONFIG_MEFFICEON is not set
+# CONFIG_MWINCHIPC6 is not set
+# CONFIG_MWINCHIP2 is not set
+# CONFIG_MWINCHIP3D is not set
+# CONFIG_MGEODEGX1 is not set
+# CONFIG_MGEODE_LX is not set
+# CONFIG_MCYRIXIII is not set
+# CONFIG_MVIAC3_2 is not set
+# CONFIG_MVIAC7 is not set
 # CONFIG_MPSC is not set
-# CONFIG_MCORE2 is not set
-CONFIG_GENERIC_CPU=y
-CONFIG_X86_L1_CACHE_BYTES=128
-CONFIG_X86_L1_CACHE_SHIFT=7
-CONFIG_X86_INTERNODE_CACHE_BYTES=128
-CONFIG_X86_TSC=y
+CONFIG_MCORE2=y
+# CONFIG_GENERIC_CPU is not set
+CONFIG_X86_CPU=y
+CONFIG_X86_L1_CACHE_BYTES=64
+CONFIG_X86_INTERNODE_CACHE_BYTES=64
+CONFIG_X86_CMPXCHG=y
+CONFIG_X86_L1_CACHE_SHIFT=6
 CONFIG_X86_GOOD_APIC=y
-# CONFIG_MICROCODE is not set
-CONFIG_X86_MSR=y
-CONFIG_X86_CPUID=y
-CONFIG_X86_HT=y
-CONFIG_X86_IO_APIC=y
-CONFIG_X86_LOCAL_APIC=y
-CONFIG_MTRR=y
-CONFIG_SMP=y
-CONFIG_SCHED_SMT=y
+CONFIG_X86_INTEL_USERCOPY=y
+CONFIG_X86_USE_PPRO_CHECKSUM=y
+CONFIG_X86_P6_NOP=y
+CONFIG_X86_TSC=y
+CONFIG_X86_CMOV=y
+CONFIG_X86_MINIMUM_CPU_FAMILY=64
+CONFIG_X86_DEBUGCTLMSR=y
+CONFIG_HPET_TIMER=y
+CONFIG_HPET_EMULATE_RTC=y
+CONFIG_DMI=y
+CONFIG_GART_IOMMU=y
+CONFIG_CALGARY_IOMMU=y
+CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT=y
+CONFIG_SWIOTLB=y
+CONFIG_IOMMU_HELPER=y
+CONFIG_NR_CPUS=4
+# CONFIG_SCHED_SMT is not set
 CONFIG_SCHED_MC=y
 # CONFIG_PREEMPT_NONE is not set
 CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
-CONFIG_PREEMPT_BKL=y
+CONFIG_X86_LOCAL_APIC=y
+CONFIG_X86_IO_APIC=y
+# CONFIG_X86_MCE is not set
+# CONFIG_I8K is not set
+# CONFIG_MICROCODE is not set
+CONFIG_X86_MSR=y
+CONFIG_X86_CPUID=y
 CONFIG_NUMA=y
 CONFIG_K8_NUMA=y
-CONFIG_NODES_SHIFT=6
 CONFIG_X86_64_ACPI_NUMA=y
-CONFIG_NUMA_EMU=y
+CONFIG_NODES_SPAN_OTHER_NODES=y
+# CONFIG_NUMA_EMU is not set
+CONFIG_NODES_SHIFT=6
+CONFIG_ARCH_SPARSEMEM_DEFAULT=y
+CONFIG_ARCH_SPARSEMEM_ENABLE=y
+CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_SELECT_MEMORY_MODEL=y
+# CONFIG_FLATMEM_MANUAL is not set
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+CONFIG_SPARSEMEM_MANUAL=y
+CONFIG_SPARSEMEM=y
 CONFIG_NEED_MULTIPLE_NODES=y
+CONFIG_HAVE_MEMORY_PRESENT=y
 # CONFIG_SPARSEMEM_STATIC is not set
+CONFIG_SPARSEMEM_EXTREME=y
+CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
+CONFIG_SPARSEMEM_VMEMMAP=y
+
+#
+# Memory hotplug is currently incompatible with Software Suspend
+#
+CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 CONFIG_RESOURCES_64BIT=y
 CONFIG_ZONE_DMA_FLAG=1
 CONFIG_BOUNCE=y
 CONFIG_VIRT_TO_BUS=y
-CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y
-CONFIG_OUT_OF_LINE_PFN_TO_PAGE=y
-CONFIG_NR_CPUS=32
-CONFIG_PHYSICAL_ALIGN=0x200000
-CONFIG_HOTPLUG_CPU=y
-CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
-CONFIG_HPET_TIMER=y
-CONFIG_HPET_EMULATE_RTC=y
-CONFIG_GART_IOMMU=y
-# CONFIG_CALGARY_IOMMU is not set
-CONFIG_SWIOTLB=y
-CONFIG_X86_MCE=y
-CONFIG_X86_MCE_INTEL=y
-CONFIG_X86_MCE_AMD=y
-# CONFIG_KEXEC is not set
-# CONFIG_CRASH_DUMP is not set
-# CONFIG_RELOCATABLE is not set
-CONFIG_PHYSICAL_START=0x200000
+CONFIG_MTRR=y
+# CONFIG_X86_PAT is not set
+CONFIG_EFI=y
 CONFIG_SECCOMP=y
-# CONFIG_CC_STACKPROTECTOR is not set
 # CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
+# CONFIG_HZ_250 is not set
 # CONFIG_HZ_300 is not set
-# CONFIG_HZ_1000 is not set
-CONFIG_HZ=250
-CONFIG_K8_NB=y
-CONFIG_GENERIC_HARDIRQS=y
-CONFIG_GENERIC_IRQ_PROBE=y
-CONFIG_ISA_DMA_API=y
-CONFIG_GENERIC_PENDING_IRQ=y
+CONFIG_HZ_1000=y
+CONFIG_HZ=1000
+CONFIG_SCHED_HRTICK=y
+CONFIG_KEXEC=y
+CONFIG_CRASH_DUMP=y
+CONFIG_PHYSICAL_START=0x1000000
+CONFIG_RELOCATABLE=y
+CONFIG_PHYSICAL_ALIGN=0x200000
+CONFIG_HOTPLUG_CPU=y
+# CONFIG_COMPAT_VDSO is not set
+CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
+CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID=y
 
 #
 # Power management options
 #
+CONFIG_ARCH_HIBERNATION_HEADER=y
 CONFIG_PM=y
-# CONFIG_PM_LEGACY is not set
-# CONFIG_PM_DEBUG is not set
+CONFIG_PM_DEBUG=y
+# CONFIG_PM_VERBOSE is not set
+CONFIG_CAN_PM_TRACE=y
+CONFIG_PM_TRACE=y
+CONFIG_PM_TRACE_RTC=y
+CONFIG_PM_SLEEP_SMP=y
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND=y
+CONFIG_SUSPEND_FREEZER=y
 CONFIG_HIBERNATION=y
 CONFIG_PM_STD_PARTITION=""
-
-#
-# ACPI (Advanced Configuration and Power Interface) Support
-#
 CONFIG_ACPI=y
 CONFIG_ACPI_SLEEP=y
-CONFIG_ACPI_SLEEP_PROC_FS=y
-CONFIG_ACPI_SLEEP_PROC_SLEEP=y
 CONFIG_ACPI_PROCFS=y
+CONFIG_ACPI_PROCFS_POWER=y
+CONFIG_ACPI_SYSFS_POWER=y
+CONFIG_ACPI_PROC_EVENT=y
 CONFIG_ACPI_AC=y
 CONFIG_ACPI_BATTERY=y
 CONFIG_ACPI_BUTTON=y
 CONFIG_ACPI_FAN=y
-# CONFIG_ACPI_DOCK is not set
+CONFIG_ACPI_DOCK=y
+# CONFIG_ACPI_BAY is not set
 CONFIG_ACPI_PROCESSOR=y
 CONFIG_ACPI_HOTPLUG_CPU=y
 CONFIG_ACPI_THERMAL=y
 CONFIG_ACPI_NUMA=y
+# CONFIG_ACPI_WMI is not set
 # CONFIG_ACPI_ASUS is not set
 # CONFIG_ACPI_TOSHIBA is not set
+# CONFIG_ACPI_CUSTOM_DSDT is not set
 CONFIG_ACPI_BLACKLIST_YEAR=0
 # CONFIG_ACPI_DEBUG is not set
 CONFIG_ACPI_EC=y
@@ -227,29 +351,34 @@ CONFIG_ACPI_CONTAINER=y
 CONFIG_CPU_FREQ=y
 CONFIG_CPU_FREQ_TABLE=y
 CONFIG_CPU_FREQ_DEBUG=y
-CONFIG_CPU_FREQ_STAT=y
-# CONFIG_CPU_FREQ_STAT_DETAILS is not set
-CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
-# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
+# CONFIG_CPU_FREQ_STAT is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
+CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
+# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
+# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
 CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
 # CONFIG_CPU_FREQ_GOV_POWERSAVE is not set
 CONFIG_CPU_FREQ_GOV_USERSPACE=y
 CONFIG_CPU_FREQ_GOV_ONDEMAND=y
-CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
+# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
 
 #
 # CPUFreq processor drivers
 #
-CONFIG_X86_POWERNOW_K8=y
-CONFIG_X86_POWERNOW_K8_ACPI=y
-# CONFIG_X86_SPEEDSTEP_CENTRINO is not set
 CONFIG_X86_ACPI_CPUFREQ=y
+# CONFIG_X86_POWERNOW_K8 is not set
+# CONFIG_X86_SPEEDSTEP_CENTRINO is not set
+# CONFIG_X86_P4_CLOCKMOD is not set
 
 #
 # shared options
 #
-CONFIG_X86_ACPI_CPUFREQ_PROC_INTF=y
+# CONFIG_X86_ACPI_CPUFREQ_PROC_INTF is not set
 # CONFIG_X86_SPEEDSTEP_LIB is not set
+CONFIG_CPU_IDLE=y
+CONFIG_CPU_IDLE_GOV_LADDER=y
+CONFIG_CPU_IDLE_GOV_MENU=y
 
 #
 # Bus options (PCI etc.)
@@ -257,27 +386,56 @@ CONFIG_X86_ACPI_CPUFREQ_PROC_INTF=y
 CONFIG_PCI=y
 CONFIG_PCI_DIRECT=y
 CONFIG_PCI_MMCONFIG=y
+CONFIG_PCI_DOMAINS=y
+CONFIG_DMAR=y
+CONFIG_DMAR_GFX_WA=y
+CONFIG_DMAR_FLOPPY_WA=y
 CONFIG_PCIEPORTBUS=y
+# CONFIG_HOTPLUG_PCI_PCIE is not set
 CONFIG_PCIEAER=y
+# CONFIG_PCIEASPM is not set
 CONFIG_ARCH_SUPPORTS_MSI=y
 CONFIG_PCI_MSI=y
+# CONFIG_PCI_LEGACY is not set
 # CONFIG_PCI_DEBUG is not set
-# CONFIG_HT_IRQ is not set
-
-#
-# PCCARD (PCMCIA/CardBus) support
-#
-# CONFIG_PCCARD is not set
-# CONFIG_HOTPLUG_PCI is not set
+CONFIG_HT_IRQ=y
+CONFIG_ISA_DMA_API=y
+CONFIG_K8_NB=y
+CONFIG_PCCARD=y
+# CONFIG_PCMCIA_DEBUG is not set
+CONFIG_PCMCIA=y
+CONFIG_PCMCIA_LOAD_CIS=y
+CONFIG_PCMCIA_IOCTL=y
+CONFIG_CARDBUS=y
+
+#
+# PC-card bridges
+#
+CONFIG_YENTA=y
+CONFIG_YENTA_O2=y
+CONFIG_YENTA_RICOH=y
+CONFIG_YENTA_TI=y
+CONFIG_YENTA_ENE_TUNE=y
+CONFIG_YENTA_TOSHIBA=y
+# CONFIG_PD6729 is not set
+# CONFIG_I82092 is not set
+CONFIG_PCCARD_NONSTATIC=y
+CONFIG_HOTPLUG_PCI=y
+# CONFIG_HOTPLUG_PCI_FAKE is not set
+# CONFIG_HOTPLUG_PCI_ACPI is not set
+# CONFIG_HOTPLUG_PCI_CPCI is not set
+# CONFIG_HOTPLUG_PCI_SHPC is not set
 
 #
 # Executable file formats / Emulations
 #
 CONFIG_BINFMT_ELF=y
-# CONFIG_BINFMT_MISC is not set
+CONFIG_COMPAT_BINFMT_ELF=y
+CONFIG_BINFMT_MISC=y
 CONFIG_IA32_EMULATION=y
-CONFIG_IA32_AOUT=y
+# CONFIG_IA32_AOUT is not set
 CONFIG_COMPAT=y
+CONFIG_COMPAT_FOR_U64_ALIGNMENT=y
 CONFIG_SYSVIPC_COMPAT=y
 
 #
@@ -289,22 +447,31 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
+CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
+CONFIG_XFRM=y
+CONFIG_XFRM_USER=y
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
 CONFIG_IP_MULTICAST=y
-# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_ASK_IP_FIB_HASH=y
+# CONFIG_IP_FIB_TRIE is not set
 CONFIG_IP_FIB_HASH=y
-CONFIG_IP_PNP=y
-CONFIG_IP_PNP_DHCP=y
-# CONFIG_IP_PNP_BOOTP is not set
-# CONFIG_IP_PNP_RARP is not set
+CONFIG_IP_MULTIPLE_TABLES=y
+CONFIG_IP_ROUTE_MULTIPATH=y
+CONFIG_IP_ROUTE_VERBOSE=y
+# CONFIG_IP_PNP is not set
 # CONFIG_NET_IPIP is not set
 # CONFIG_NET_IPGRE is not set
-# CONFIG_IP_MROUTE is not set
+CONFIG_IP_MROUTE=y
+CONFIG_IP_PIMSM_V1=y
+CONFIG_IP_PIMSM_V2=y
 # CONFIG_ARPD is not set
-# CONFIG_SYN_COOKIES is not set
+CONFIG_SYN_COOKIES=y
 # CONFIG_INET_AH is not set
 # CONFIG_INET_ESP is not set
 # CONFIG_INET_IPCOMP is not set
@@ -313,31 +480,109 @@ CONFIG_INET_TUNNEL=y
 # CONFIG_INET_XFRM_MODE_TRANSPORT is not set
 # CONFIG_INET_XFRM_MODE_TUNNEL is not set
 # CONFIG_INET_XFRM_MODE_BEET is not set
-CONFIG_INET_DIAG=y
-CONFIG_INET_TCP_DIAG=y
-# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_INET_LRO=y
+# CONFIG_INET_DIAG is not set
+CONFIG_TCP_CONG_ADVANCED=y
+# CONFIG_TCP_CONG_BIC is not set
 CONFIG_TCP_CONG_CUBIC=y
+# CONFIG_TCP_CONG_WESTWOOD is not set
+# CONFIG_TCP_CONG_HTCP is not set
+# CONFIG_TCP_CONG_HSTCP is not set
+# CONFIG_TCP_CONG_HYBLA is not set
+# CONFIG_TCP_CONG_VEGAS is not set
+# CONFIG_TCP_CONG_SCALABLE is not set
+# CONFIG_TCP_CONG_LP is not set
+# CONFIG_TCP_CONG_VENO is not set
+# CONFIG_TCP_CONG_YEAH is not set
+# CONFIG_TCP_CONG_ILLINOIS is not set
+# CONFIG_DEFAULT_BIC is not set
+CONFIG_DEFAULT_CUBIC=y
+# CONFIG_DEFAULT_HTCP is not set
+# CONFIG_DEFAULT_VEGAS is not set
+# CONFIG_DEFAULT_WESTWOOD is not set
+# CONFIG_DEFAULT_RENO is not set
 CONFIG_DEFAULT_TCP_CONG="cubic"
-# CONFIG_TCP_MD5SIG is not set
+CONFIG_TCP_MD5SIG=y
+# CONFIG_IP_VS is not set
 CONFIG_IPV6=y
 # CONFIG_IPV6_PRIVACY is not set
 # CONFIG_IPV6_ROUTER_PREF is not set
 # CONFIG_IPV6_OPTIMISTIC_DAD is not set
-# CONFIG_INET6_AH is not set
-# CONFIG_INET6_ESP is not set
+CONFIG_INET6_AH=y
+CONFIG_INET6_ESP=y
 # CONFIG_INET6_IPCOMP is not set
 # CONFIG_IPV6_MIP6 is not set
 # CONFIG_INET6_XFRM_TUNNEL is not set
 # CONFIG_INET6_TUNNEL is not set
-# CONFIG_INET6_XFRM_MODE_TRANSPORT is not set
-# CONFIG_INET6_XFRM_MODE_TUNNEL is not set
-# CONFIG_INET6_XFRM_MODE_BEET is not set
+CONFIG_INET6_XFRM_MODE_TRANSPORT=y
+CONFIG_INET6_XFRM_MODE_TUNNEL=y
+CONFIG_INET6_XFRM_MODE_BEET=y
 # CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
 CONFIG_IPV6_SIT=y
+CONFIG_IPV6_NDISC_NODETYPE=y
 # CONFIG_IPV6_TUNNEL is not set
 # CONFIG_IPV6_MULTIPLE_TABLES is not set
-# CONFIG_NETWORK_SECMARK is not set
-# CONFIG_NETFILTER is not set
+# CONFIG_IPV6_MROUTE is not set
+CONFIG_NETLABEL=y
+CONFIG_NETWORK_SECMARK=y
+CONFIG_NETFILTER=y
+# CONFIG_NETFILTER_DEBUG is not set
+# CONFIG_NETFILTER_ADVANCED is not set
+
+#
+# Core Netfilter Configuration
+#
+CONFIG_NETFILTER_NETLINK=y
+CONFIG_NETFILTER_NETLINK_LOG=y
+CONFIG_NF_CONNTRACK=y
+CONFIG_NF_CONNTRACK_SECMARK=y
+CONFIG_NF_CONNTRACK_FTP=y
+CONFIG_NF_CONNTRACK_IRC=y
+CONFIG_NF_CONNTRACK_SIP=y
+CONFIG_NF_CT_NETLINK=y
+CONFIG_NETFILTER_XTABLES=y
+CONFIG_NETFILTER_XT_TARGET_MARK=y
+CONFIG_NETFILTER_XT_TARGET_NFLOG=y
+CONFIG_NETFILTER_XT_TARGET_SECMARK=y
+CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y
+CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
+CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
+CONFIG_NETFILTER_XT_MATCH_MARK=y
+CONFIG_NETFILTER_XT_MATCH_POLICY=y
+CONFIG_NETFILTER_XT_MATCH_STATE=y
+
+#
+# IP: Netfilter Configuration
+#
+CONFIG_NF_CONNTRACK_IPV4=y
+CONFIG_NF_CONNTRACK_PROC_COMPAT=y
+CONFIG_IP_NF_IPTABLES=y
+CONFIG_IP_NF_FILTER=y
+CONFIG_IP_NF_TARGET_REJECT=y
+CONFIG_IP_NF_TARGET_LOG=y
+CONFIG_IP_NF_TARGET_ULOG=y
+CONFIG_NF_NAT=y
+CONFIG_NF_NAT_NEEDED=y
+CONFIG_IP_NF_TARGET_MASQUERADE=y
+CONFIG_NF_NAT_FTP=y
+CONFIG_NF_NAT_IRC=y
+# CONFIG_NF_NAT_TFTP is not set
+# CONFIG_NF_NAT_AMANDA is not set
+# CONFIG_NF_NAT_PPTP is not set
+# CONFIG_NF_NAT_H323 is not set
+CONFIG_NF_NAT_SIP=y
+CONFIG_IP_NF_MANGLE=y
+
+#
+# IPv6: Netfilter Configuration
+#
+CONFIG_NF_CONNTRACK_IPV6=y
+CONFIG_IP6_NF_IPTABLES=y
+CONFIG_IP6_NF_MATCH_IPV6HEADER=y
+CONFIG_IP6_NF_FILTER=y
+CONFIG_IP6_NF_TARGET_LOG=y
+CONFIG_IP6_NF_TARGET_REJECT=y
+CONFIG_IP6_NF_MANGLE=y
 # CONFIG_IP_DCCP is not set
 # CONFIG_IP_SCTP is not set
 # CONFIG_TIPC is not set
@@ -345,6 +590,7 @@ CONFIG_IPV6_SIT=y
 # CONFIG_BRIDGE is not set
 # CONFIG_VLAN_8021Q is not set
 # CONFIG_DECNET is not set
+CONFIG_LLC=y
 # CONFIG_LLC2 is not set
 # CONFIG_IPX is not set
 # CONFIG_ATALK is not set
@@ -352,28 +598,99 @@ CONFIG_IPV6_SIT=y
 # CONFIG_LAPB is not set
 # CONFIG_ECONET is not set
 # CONFIG_WAN_ROUTER is not set
-
-#
-# QoS and/or fair queueing
-#
-# CONFIG_NET_SCHED is not set
+CONFIG_NET_SCHED=y
+
+#
+# Queueing/Scheduling
+#
+# CONFIG_NET_SCH_CBQ is not set
+# CONFIG_NET_SCH_HTB is not set
+# CONFIG_NET_SCH_HFSC is not set
+# CONFIG_NET_SCH_PRIO is not set
+# CONFIG_NET_SCH_RR is not set
+# CONFIG_NET_SCH_RED is not set
+# CONFIG_NET_SCH_SFQ is not set
+# CONFIG_NET_SCH_TEQL is not set
+# CONFIG_NET_SCH_TBF is not set
+# CONFIG_NET_SCH_GRED is not set
+# CONFIG_NET_SCH_DSMARK is not set
+# CONFIG_NET_SCH_NETEM is not set
+# CONFIG_NET_SCH_INGRESS is not set
+
+#
+# Classification
+#
+CONFIG_NET_CLS=y
+# CONFIG_NET_CLS_BASIC is not set
+# CONFIG_NET_CLS_TCINDEX is not set
+# CONFIG_NET_CLS_ROUTE4 is not set
+# CONFIG_NET_CLS_FW is not set
+# CONFIG_NET_CLS_U32 is not set
+# CONFIG_NET_CLS_RSVP is not set
+# CONFIG_NET_CLS_RSVP6 is not set
+# CONFIG_NET_CLS_FLOW is not set
+CONFIG_NET_EMATCH=y
+CONFIG_NET_EMATCH_STACK=32
+# CONFIG_NET_EMATCH_CMP is not set
+# CONFIG_NET_EMATCH_NBYTE is not set
+# CONFIG_NET_EMATCH_U32 is not set
+# CONFIG_NET_EMATCH_META is not set
+# CONFIG_NET_EMATCH_TEXT is not set
+CONFIG_NET_CLS_ACT=y
+# CONFIG_NET_ACT_POLICE is not set
+# CONFIG_NET_ACT_GACT is not set
+# CONFIG_NET_ACT_MIRRED is not set
+# CONFIG_NET_ACT_IPT is not set
+# CONFIG_NET_ACT_NAT is not set
+# CONFIG_NET_ACT_PEDIT is not set
+# CONFIG_NET_ACT_SIMP is not set
+CONFIG_NET_SCH_FIFO=y
 
 #
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_NET_TCPPROBE is not set
-# CONFIG_HAMRADIO is not set
+CONFIG_HAMRADIO=y
+
+#
+# Packet Radio protocols
+#
+# CONFIG_AX25 is not set
+# CONFIG_CAN is not set
 # CONFIG_IRDA is not set
 # CONFIG_BT is not set
 # CONFIG_AF_RXRPC is not set
+CONFIG_FIB_RULES=y
 
 #
 # Wireless
 #
-# CONFIG_CFG80211 is not set
-# CONFIG_WIRELESS_EXT is not set
-# CONFIG_MAC80211 is not set
+CONFIG_CFG80211=y
+CONFIG_NL80211=y
+CONFIG_WIRELESS_EXT=y
+CONFIG_MAC80211=y
+
+#
+# Rate control algorithm selection
+#
+CONFIG_MAC80211_RC_DEFAULT_PID=y
+# CONFIG_MAC80211_RC_DEFAULT_NONE is not set
+
+#
+# Selecting 'y' for an algorithm will
+#
+
+#
+# build the algorithm into mac80211.
+#
+CONFIG_MAC80211_RC_DEFAULT="pid"
+CONFIG_MAC80211_RC_PID=y
+# CONFIG_MAC80211_MESH is not set
+CONFIG_MAC80211_LEDS=y
+# CONFIG_MAC80211_DEBUGFS is not set
+# CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT is not set
+# CONFIG_MAC80211_DEBUG is not set
 # CONFIG_IEEE80211 is not set
 # CONFIG_RFKILL is not set
 # CONFIG_NET_9P is not set
@@ -385,13 +702,15 @@ CONFIG_IPV6_SIT=y
 #
 # Generic Driver Options
 #
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
 CONFIG_STANDALONE=y
 CONFIG_PREVENT_FIRMWARE_BUILD=y
 CONFIG_FW_LOADER=y
 # CONFIG_DEBUG_DRIVER is not set
-# CONFIG_DEBUG_DEVRES is not set
+CONFIG_DEBUG_DEVRES=y
 # CONFIG_SYS_HYPERVISOR is not set
-# CONFIG_CONNECTOR is not set
+CONFIG_CONNECTOR=y
+CONFIG_PROC_EVENTS=y
 # CONFIG_MTD is not set
 # CONFIG_PARPORT is not set
 CONFIG_PNP=y
@@ -402,7 +721,7 @@ CONFIG_PNP=y
 #
 CONFIG_PNPACPI=y
 CONFIG_BLK_DEV=y
-CONFIG_BLK_DEV_FD=y
+# CONFIG_BLK_DEV_FD is not set
 # CONFIG_BLK_CPQ_DA is not set
 # CONFIG_BLK_CPQ_CISS_DA is not set
 # CONFIG_BLK_DEV_DAC960 is not set
@@ -415,8 +734,8 @@ CONFIG_BLK_DEV_LOOP=y
 # CONFIG_BLK_DEV_UB is not set
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_COUNT=16
-CONFIG_BLK_DEV_RAM_SIZE=4096
-CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 CONFIG_MISC_DEVICES=y
@@ -425,72 +744,16 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_EEPROM_93CX6 is not set
 # CONFIG_SGI_IOC4 is not set
 # CONFIG_TIFM_CORE is not set
+# CONFIG_ACER_WMI is not set
+# CONFIG_ASUS_LAPTOP is not set
+# CONFIG_FUJITSU_LAPTOP is not set
+# CONFIG_MSI_LAPTOP is not set
 # CONFIG_SONY_LAPTOP is not set
 # CONFIG_THINKPAD_ACPI is not set
-CONFIG_IDE=y
-CONFIG_BLK_DEV_IDE=y
-
-#
-# Please see Documentation/ide.txt for help/info on IDE drives
-#
-# CONFIG_BLK_DEV_IDE_SATA is not set
-# CONFIG_BLK_DEV_HD_IDE is not set
-CONFIG_BLK_DEV_IDEDISK=y
-CONFIG_IDEDISK_MULTI_MODE=y
-CONFIG_BLK_DEV_IDECD=y
-# CONFIG_BLK_DEV_IDETAPE is not set
-# CONFIG_BLK_DEV_IDEFLOPPY is not set
-# CONFIG_BLK_DEV_IDESCSI is not set
-CONFIG_BLK_DEV_IDEACPI=y
-# CONFIG_IDE_TASK_IOCTL is not set
-CONFIG_IDE_PROC_FS=y
-
-#
-# IDE chipset support/bugfixes
-#
-CONFIG_IDE_GENERIC=y
-# CONFIG_BLK_DEV_CMD640 is not set
-# CONFIG_BLK_DEV_IDEPNP is not set
-CONFIG_BLK_DEV_IDEPCI=y
-# CONFIG_IDEPCI_SHARE_IRQ is not set
-CONFIG_IDEPCI_PCIBUS_ORDER=y
-# CONFIG_BLK_DEV_OFFBOARD is not set
-# CONFIG_BLK_DEV_GENERIC is not set
-# CONFIG_BLK_DEV_OPTI621 is not set
-# CONFIG_BLK_DEV_RZ1000 is not set
-CONFIG_BLK_DEV_IDEDMA_PCI=y
-# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
-# CONFIG_IDEDMA_ONLYDISK is not set
-# CONFIG_BLK_DEV_AEC62XX is not set
-# CONFIG_BLK_DEV_ALI15X3 is not set
-CONFIG_BLK_DEV_AMD74XX=y
-CONFIG_BLK_DEV_ATIIXP=y
-# CONFIG_BLK_DEV_CMD64X is not set
-# CONFIG_BLK_DEV_TRIFLEX is not set
-# CONFIG_BLK_DEV_CY82C693 is not set
-# CONFIG_BLK_DEV_CS5520 is not set
-# CONFIG_BLK_DEV_CS5530 is not set
-# CONFIG_BLK_DEV_HPT34X is not set
-# CONFIG_BLK_DEV_HPT366 is not set
-# CONFIG_BLK_DEV_JMICRON is not set
-# CONFIG_BLK_DEV_SC1200 is not set
-CONFIG_BLK_DEV_PIIX=y
-# CONFIG_BLK_DEV_IT8213 is not set
-# CONFIG_BLK_DEV_IT821X is not set
-# CONFIG_BLK_DEV_NS87415 is not set
-# CONFIG_BLK_DEV_PDC202XX_OLD is not set
-CONFIG_BLK_DEV_PDC202XX_NEW=y
-# CONFIG_BLK_DEV_SVWKS is not set
-# CONFIG_BLK_DEV_SIIMAGE is not set
-# CONFIG_BLK_DEV_SIS5513 is not set
-# CONFIG_BLK_DEV_SLC90E66 is not set
-# CONFIG_BLK_DEV_TRM290 is not set
-# CONFIG_BLK_DEV_VIA82CXXX is not set
-# CONFIG_BLK_DEV_TC86C001 is not set
-# CONFIG_IDE_ARM is not set
-CONFIG_BLK_DEV_IDEDMA=y
-# CONFIG_IDEDMA_IVB is not set
-# CONFIG_BLK_DEV_HD is not set
+# CONFIG_INTEL_MENLOW is not set
+# CONFIG_ENCLOSURE_SERVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
 
 #
 # SCSI device support
@@ -499,8 +762,8 @@ CONFIG_BLK_DEV_IDEDMA=y
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
 # CONFIG_SCSI_TGT is not set
-CONFIG_SCSI_NETLINK=y
-# CONFIG_SCSI_PROC_FS is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
 
 #
 # SCSI support type (disk, tape, CD-ROM)
@@ -509,7 +772,7 @@ CONFIG_BLK_DEV_SD=y
 # CONFIG_CHR_DEV_ST is not set
 # CONFIG_CHR_DEV_OSST is not set
 CONFIG_BLK_DEV_SR=y
-# CONFIG_BLK_DEV_SR_VENDOR is not set
+CONFIG_BLK_DEV_SR_VENDOR=y
 CONFIG_CHR_DEV_SG=y
 # CONFIG_CHR_DEV_SCH is not set
 
@@ -526,73 +789,37 @@ CONFIG_SCSI_WAIT_SCAN=m
 # SCSI Transports
 #
 CONFIG_SCSI_SPI_ATTRS=y
-CONFIG_SCSI_FC_ATTRS=y
+# CONFIG_SCSI_FC_ATTRS is not set
 # CONFIG_SCSI_ISCSI_ATTRS is not set
-CONFIG_SCSI_SAS_ATTRS=y
+# CONFIG_SCSI_SAS_ATTRS is not set
 # CONFIG_SCSI_SAS_LIBSAS is not set
-
-#
-# SCSI low-level drivers
-#
-# CONFIG_ISCSI_TCP is not set
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AACRAID is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-CONFIG_SCSI_AIC79XX=y
-CONFIG_AIC79XX_CMDS_PER_DEVICE=32
-CONFIG_AIC79XX_RESET_DELAY_MS=4000
-# CONFIG_AIC79XX_DEBUG_ENABLE is not set
-CONFIG_AIC79XX_DEBUG_MASK=0
-# CONFIG_AIC79XX_REG_PRETTY_PRINT is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_SCSI_BUSLOGIC is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_EATA is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_GDTH is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_IPR is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_LPFC is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_SCSI_SRP is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+# CONFIG_SCSI_LOWLEVEL is not set
+# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
 CONFIG_ATA=y
 # CONFIG_ATA_NONSTANDARD is not set
 CONFIG_ATA_ACPI=y
+CONFIG_SATA_PMP=y
 CONFIG_SATA_AHCI=y
-CONFIG_SATA_SVW=y
+# CONFIG_SATA_SIL24 is not set
+CONFIG_ATA_SFF=y
+# CONFIG_SATA_SVW is not set
 CONFIG_ATA_PIIX=y
 # CONFIG_SATA_MV is not set
-CONFIG_SATA_NV=y
+# CONFIG_SATA_NV is not set
 # CONFIG_PDC_ADMA is not set
 # CONFIG_SATA_QSTOR is not set
 # CONFIG_SATA_PROMISE is not set
 # CONFIG_SATA_SX4 is not set
-CONFIG_SATA_SIL=y
-# CONFIG_SATA_SIL24 is not set
+# CONFIG_SATA_SIL is not set
 # CONFIG_SATA_SIS is not set
 # CONFIG_SATA_ULI is not set
-CONFIG_SATA_VIA=y
+# CONFIG_SATA_VIA is not set
 # CONFIG_SATA_VITESSE is not set
 # CONFIG_SATA_INIC162X is not set
+# CONFIG_PATA_ACPI is not set
 # CONFIG_PATA_ALI is not set
-# CONFIG_PATA_AMD is not set
+CONFIG_PATA_AMD=y
 # CONFIG_PATA_ARTOP is not set
 # CONFIG_PATA_ATIIXP is not set
 # CONFIG_PATA_CMD640_PCI is not set
@@ -612,11 +839,14 @@ CONFIG_SATA_VIA=y
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
-# CONFIG_PATA_OLDPIIX is not set
+CONFIG_PATA_OLDPIIX=y
 # CONFIG_PATA_NETCELL is not set
+# CONFIG_PATA_NINJA32 is not set
 # CONFIG_PATA_NS87410 is not set
+# CONFIG_PATA_NS87415 is not set
 # CONFIG_PATA_OPTI is not set
 # CONFIG_PATA_OPTIDMA is not set
+# CONFIG_PATA_PCMCIA is not set
 # CONFIG_PATA_PDC_OLD is not set
 # CONFIG_PATA_RADISYS is not set
 # CONFIG_PATA_RZ1000 is not set
@@ -628,65 +858,42 @@ CONFIG_SATA_VIA=y
 # CONFIG_PATA_VIA is not set
 # CONFIG_PATA_WINBOND is not set
 CONFIG_MD=y
-# CONFIG_BLK_DEV_MD is not set
+CONFIG_BLK_DEV_MD=y
+# CONFIG_MD_LINEAR is not set
+# CONFIG_MD_RAID0 is not set
+# CONFIG_MD_RAID1 is not set
+# CONFIG_MD_RAID10 is not set
+# CONFIG_MD_RAID456 is not set
+# CONFIG_MD_MULTIPATH is not set
+# CONFIG_MD_FAULTY is not set
 CONFIG_BLK_DEV_DM=y
 # CONFIG_DM_DEBUG is not set
 # CONFIG_DM_CRYPT is not set
 # CONFIG_DM_SNAPSHOT is not set
-# CONFIG_DM_MIRROR is not set
-# CONFIG_DM_ZERO is not set
+CONFIG_DM_MIRROR=y
+CONFIG_DM_ZERO=y
 # CONFIG_DM_MULTIPATH is not set
 # CONFIG_DM_DELAY is not set
-
-#
-# Fusion MPT device support
-#
-CONFIG_FUSION=y
-CONFIG_FUSION_SPI=y
-# CONFIG_FUSION_FC is not set
-# CONFIG_FUSION_SAS is not set
-CONFIG_FUSION_MAX_SGE=128
-# CONFIG_FUSION_CTL is not set
+# CONFIG_DM_UEVENT is not set
+# CONFIG_FUSION is not set
 
 #
 # IEEE 1394 (FireWire) support
 #
 # CONFIG_FIREWIRE is not set
-CONFIG_IEEE1394=y
-
-#
-# Subsystem Options
-#
-# CONFIG_IEEE1394_VERBOSEDEBUG is not set
-
-#
-# Controllers
-#
-
-#
-# Texas Instruments PCILynx requires I2C
-#
-CONFIG_IEEE1394_OHCI1394=y
-
-#
-# Protocols
-#
-# CONFIG_IEEE1394_VIDEO1394 is not set
-# CONFIG_IEEE1394_SBP2 is not set
-# CONFIG_IEEE1394_ETH1394_ROM_ENTRY is not set
-# CONFIG_IEEE1394_ETH1394 is not set
-# CONFIG_IEEE1394_DV1394 is not set
-CONFIG_IEEE1394_RAWIO=y
+# CONFIG_IEEE1394 is not set
 # CONFIG_I2O is not set
 CONFIG_MACINTOSH_DRIVERS=y
-# CONFIG_MAC_EMUMOUSEBTN is not set
+CONFIG_MAC_EMUMOUSEBTN=y
 CONFIG_NETDEVICES=y
-CONFIG_NETDEVICES_MULTIQUEUE=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_IFB is not set
 # CONFIG_DUMMY is not set
 # CONFIG_BONDING is not set
 # CONFIG_MACVLAN is not set
 # CONFIG_EQUALIZER is not set
-CONFIG_TUN=y
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
 # CONFIG_NET_SB1000 is not set
 # CONFIG_ARCNET is not set
 # CONFIG_PHYLIB is not set
@@ -696,39 +903,40 @@ CONFIG_MII=y
 # CONFIG_SUNGEM is not set
 # CONFIG_CASSINI is not set
 CONFIG_NET_VENDOR_3COM=y
-CONFIG_VORTEX=y
+# CONFIG_VORTEX is not set
 # CONFIG_TYPHOON is not set
 CONFIG_NET_TULIP=y
 # CONFIG_DE2104X is not set
-CONFIG_TULIP=y
-# CONFIG_TULIP_MWI is not set
-# CONFIG_TULIP_MMIO is not set
-# CONFIG_TULIP_NAPI is not set
+# CONFIG_TULIP is not set
 # CONFIG_DE4X5 is not set
 # CONFIG_WINBOND_840 is not set
 # CONFIG_DM9102 is not set
 # CONFIG_ULI526X is not set
+# CONFIG_PCMCIA_XIRCOM is not set
 # CONFIG_HP100 is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
 CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
-CONFIG_AMD8111_ETH=y
-# CONFIG_AMD8111E_NAPI is not set
+# CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
-CONFIG_B44=y
+# CONFIG_B44 is not set
 CONFIG_FORCEDETH=y
 # CONFIG_FORCEDETH_NAPI is not set
-# CONFIG_DGRS is not set
 # CONFIG_EEPRO100 is not set
 CONFIG_E100=y
 # CONFIG_FEALNX is not set
 # CONFIG_NATSEMI is not set
 # CONFIG_NE2K_PCI is not set
-CONFIG_8139CP=y
+# CONFIG_8139CP is not set
 CONFIG_8139TOO=y
-# CONFIG_8139TOO_PIO is not set
+CONFIG_8139TOO_PIO=y
 # CONFIG_8139TOO_TUNE_TWISTER is not set
 # CONFIG_8139TOO_8129 is not set
 # CONFIG_8139_OLD_RX_RESET is not set
+# CONFIG_R6040 is not set
 # CONFIG_SIS900 is not set
 # CONFIG_EPIC100 is not set
 # CONFIG_SUNDANCE is not set
@@ -740,34 +948,74 @@ CONFIG_NETDEV_1000=y
 CONFIG_E1000=y
 # CONFIG_E1000_NAPI is not set
 # CONFIG_E1000_DISABLE_PACKET_SPLIT is not set
+# CONFIG_E1000E is not set
+# CONFIG_E1000E_ENABLED is not set
+# CONFIG_IP1000 is not set
+# CONFIG_IGB is not set
 # CONFIG_NS83820 is not set
 # CONFIG_HAMACHI is not set
 # CONFIG_YELLOWFIN is not set
 # CONFIG_R8169 is not set
 # CONFIG_SIS190 is not set
 # CONFIG_SKGE is not set
-# CONFIG_SKY2 is not set
+CONFIG_SKY2=y
+# CONFIG_SKY2_DEBUG is not set
 # CONFIG_VIA_VELOCITY is not set
 CONFIG_TIGON3=y
-CONFIG_BNX2=y
+# CONFIG_BNX2 is not set
 # CONFIG_QLA3XXX is not set
 # CONFIG_ATL1 is not set
 CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 # CONFIG_CHELSIO_T3 is not set
+# CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
-CONFIG_S2IO=m
-# CONFIG_S2IO_NAPI is not set
+# CONFIG_S2IO is not set
 # CONFIG_MYRI10GE is not set
 # CONFIG_NETXEN_NIC is not set
+# CONFIG_NIU is not set
 # CONFIG_MLX4_CORE is not set
-# CONFIG_TR is not set
+# CONFIG_TEHUTI is not set
+# CONFIG_BNX2X is not set
+# CONFIG_SFC is not set
+CONFIG_TR=y
+# CONFIG_IBMOL is not set
+# CONFIG_3C359 is not set
+# CONFIG_TMS380TR is not set
 
 #
 # Wireless LAN
 #
 # CONFIG_WLAN_PRE80211 is not set
-# CONFIG_WLAN_80211 is not set
+CONFIG_WLAN_80211=y
+# CONFIG_PCMCIA_RAYCS is not set
+# CONFIG_IPW2100 is not set
+# CONFIG_IPW2200 is not set
+# CONFIG_LIBERTAS is not set
+# CONFIG_AIRO is not set
+# CONFIG_HERMES is not set
+# CONFIG_ATMEL is not set
+# CONFIG_AIRO_CS is not set
+# CONFIG_PCMCIA_WL3501 is not set
+# CONFIG_PRISM54 is not set
+# CONFIG_USB_ZD1201 is not set
+# CONFIG_USB_NET_RNDIS_WLAN is not set
+# CONFIG_RTL8180 is not set
+# CONFIG_RTL8187 is not set
+# CONFIG_ADM8211 is not set
+# CONFIG_P54_COMMON is not set
+CONFIG_ATH5K=y
+# CONFIG_ATH5K_DEBUG is not set
+# CONFIG_IWLWIFI is not set
+# CONFIG_IWLCORE is not set
+# CONFIG_IWLWIFI_LEDS is not set
+# CONFIG_IWL4965 is not set
+# CONFIG_IWL3945 is not set
+# CONFIG_HOSTAP is not set
+# CONFIG_B43 is not set
+# CONFIG_B43LEGACY is not set
+# CONFIG_ZD1211RW is not set
+# CONFIG_RT2X00 is not set
 
 #
 # USB Network Adapters
@@ -776,16 +1024,26 @@ CONFIG_S2IO=m
 # CONFIG_USB_KAWETH is not set
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
-# CONFIG_USB_USBNET_MII is not set
 # CONFIG_USB_USBNET is not set
+CONFIG_NET_PCMCIA=y
+# CONFIG_PCMCIA_3C589 is not set
+# CONFIG_PCMCIA_3C574 is not set
+# CONFIG_PCMCIA_FMVJ18X is not set
+# CONFIG_PCMCIA_PCNET is not set
+# CONFIG_PCMCIA_NMCLAN is not set
+# CONFIG_PCMCIA_SMC91C92 is not set
+# CONFIG_PCMCIA_XIRC2PS is not set
+# CONFIG_PCMCIA_AXNET is not set
 # CONFIG_WAN is not set
-# CONFIG_FDDI is not set
+CONFIG_FDDI=y
+# CONFIG_DEFXX is not set
+# CONFIG_SKFP is not set
 # CONFIG_HIPPI is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
 # CONFIG_NET_FC is not set
-# CONFIG_SHAPER is not set
 CONFIG_NETCONSOLE=y
+# CONFIG_NETCONSOLE_DYNAMIC is not set
 CONFIG_NETPOLL=y
 # CONFIG_NETPOLL_TRAP is not set
 CONFIG_NET_POLL_CONTROLLER=y
@@ -796,18 +1054,17 @@ CONFIG_NET_POLL_CONTROLLER=y
 # Input device support
 #
 CONFIG_INPUT=y
-# CONFIG_INPUT_FF_MEMLESS is not set
-# CONFIG_INPUT_POLLDEV is not set
+CONFIG_INPUT_FF_MEMLESS=y
+CONFIG_INPUT_POLLDEV=y
 
 #
 # Userland interfaces
 #
 CONFIG_INPUT_MOUSEDEV=y
-CONFIG_INPUT_MOUSEDEV_PSAUX=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
 CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
 CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
 # CONFIG_INPUT_JOYDEV is not set
-# CONFIG_INPUT_TSDEV is not set
 CONFIG_INPUT_EVDEV=y
 # CONFIG_INPUT_EVBUG is not set
 
@@ -832,17 +1089,62 @@ CONFIG_MOUSE_PS2_TRACKPOINT=y
 # CONFIG_MOUSE_SERIAL is not set
 # CONFIG_MOUSE_APPLETOUCH is not set
 # CONFIG_MOUSE_VSXXXAA is not set
-# CONFIG_INPUT_JOYSTICK is not set
-# CONFIG_INPUT_TABLET is not set
-# CONFIG_INPUT_TOUCHSCREEN is not set
-# CONFIG_INPUT_MISC is not set
+CONFIG_INPUT_JOYSTICK=y
+# CONFIG_JOYSTICK_ANALOG is not set
+# CONFIG_JOYSTICK_A3D is not set
+# CONFIG_JOYSTICK_ADI is not set
+# CONFIG_JOYSTICK_COBRA is not set
+# CONFIG_JOYSTICK_GF2K is not set
+# CONFIG_JOYSTICK_GRIP is not set
+# CONFIG_JOYSTICK_GRIP_MP is not set
+# CONFIG_JOYSTICK_GUILLEMOT is not set
+# CONFIG_JOYSTICK_INTERACT is not set
+# CONFIG_JOYSTICK_SIDEWINDER is not set
+# CONFIG_JOYSTICK_TMDC is not set
+# CONFIG_JOYSTICK_IFORCE is not set
+# CONFIG_JOYSTICK_WARRIOR is not set
+# CONFIG_JOYSTICK_MAGELLAN is not set
+# CONFIG_JOYSTICK_SPACEORB is not set
+# CONFIG_JOYSTICK_SPACEBALL is not set
+# CONFIG_JOYSTICK_STINGER is not set
+# CONFIG_JOYSTICK_TWIDJOY is not set
+# CONFIG_JOYSTICK_ZHENHUA is not set
+# CONFIG_JOYSTICK_JOYDUMP is not set
+# CONFIG_JOYSTICK_XPAD is not set
+CONFIG_INPUT_TABLET=y
+# CONFIG_TABLET_USB_ACECAD is not set
+# CONFIG_TABLET_USB_AIPTEK is not set
+# CONFIG_TABLET_USB_GTCO is not set
+# CONFIG_TABLET_USB_KBTAB is not set
+# CONFIG_TABLET_USB_WACOM is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_UCB1400 is not set
+# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
+CONFIG_INPUT_MISC=y
+# CONFIG_INPUT_PCSPKR is not set
+# CONFIG_INPUT_APANEL is not set
+# CONFIG_INPUT_ATLAS_BTNS is not set
+# CONFIG_INPUT_ATI_REMOTE is not set
+# CONFIG_INPUT_ATI_REMOTE2 is not set
+# CONFIG_INPUT_KEYSPAN_REMOTE is not set
+# CONFIG_INPUT_POWERMATE is not set
+# CONFIG_INPUT_YEALINK is not set
+# CONFIG_INPUT_UINPUT is not set
 
 #
 # Hardware I/O ports
 #
 CONFIG_SERIO=y
 CONFIG_SERIO_I8042=y
-# CONFIG_SERIO_SERPORT is not set
+CONFIG_SERIO_SERPORT=y
 # CONFIG_SERIO_CT82C710 is not set
 # CONFIG_SERIO_PCIPS2 is not set
 CONFIG_SERIO_LIBPS2=y
@@ -855,8 +1157,26 @@ CONFIG_SERIO_LIBPS2=y
 CONFIG_VT=y
 CONFIG_VT_CONSOLE=y
 CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
-# CONFIG_SERIAL_NONSTANDARD is not set
+CONFIG_VT_HW_CONSOLE_BINDING=y
+CONFIG_DEVKMEM=y
+CONFIG_SERIAL_NONSTANDARD=y
+# CONFIG_COMPUTONE is not set
+# CONFIG_ROCKETPORT is not set
+# CONFIG_CYCLADES is not set
+# CONFIG_DIGIEPCA is not set
+# CONFIG_MOXA_INTELLIO is not set
+# CONFIG_MOXA_SMARTIO is not set
+# CONFIG_ISI is not set
+# CONFIG_SYNCLINK is not set
+# CONFIG_SYNCLINKMP is not set
+# CONFIG_SYNCLINK_GT is not set
+# CONFIG_N_HDLC is not set
+# CONFIG_RISCOM8 is not set
+# CONFIG_SPECIALIX is not set
+# CONFIG_SX is not set
+# CONFIG_RIO is not set
+# CONFIG_STALDRV is not set
+# CONFIG_NOZOMI is not set
 
 #
 # Serial drivers
@@ -866,9 +1186,14 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_FIX_EARLYCON_MEM=y
 CONFIG_SERIAL_8250_PCI=y
 CONFIG_SERIAL_8250_PNP=y
-CONFIG_SERIAL_8250_NR_UARTS=4
+# CONFIG_SERIAL_8250_CS is not set
+CONFIG_SERIAL_8250_NR_UARTS=32
 CONFIG_SERIAL_8250_RUNTIME_UARTS=4
-# CONFIG_SERIAL_8250_EXTENDED is not set
+CONFIG_SERIAL_8250_EXTENDED=y
+CONFIG_SERIAL_8250_MANY_PORTS=y
+CONFIG_SERIAL_8250_SHARE_IRQ=y
+CONFIG_SERIAL_8250_DETECT_IRQ=y
+CONFIG_SERIAL_8250_RSA=y
 
 #
 # Non-8250 serial port support
@@ -877,78 +1202,260 @@ CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
 CONFIG_UNIX98_PTYS=y
-CONFIG_LEGACY_PTYS=y
-CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
-# CONFIG_WATCHDOG is not set
 CONFIG_HW_RANDOM=y
-CONFIG_HW_RANDOM_INTEL=y
-CONFIG_HW_RANDOM_AMD=y
-# CONFIG_NVRAM is not set
-CONFIG_RTC=y
+# CONFIG_HW_RANDOM_INTEL is not set
+# CONFIG_HW_RANDOM_AMD is not set
+CONFIG_NVRAM=y
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
-CONFIG_AGP=y
-CONFIG_AGP_AMD64=y
-CONFIG_AGP_INTEL=y
-# CONFIG_AGP_SIS is not set
-# CONFIG_AGP_VIA is not set
-# CONFIG_DRM is not set
+
+#
+# PCMCIA character devices
+#
+# CONFIG_SYNCLINK_CS is not set
+# CONFIG_CARDMAN_4000 is not set
+# CONFIG_CARDMAN_4040 is not set
+# CONFIG_IPWIRELESS is not set
 # CONFIG_MWAVE is not set
 # CONFIG_PC8736x_GPIO is not set
-CONFIG_RAW_DRIVER=y
-CONFIG_MAX_RAW_DEVS=256
+# CONFIG_RAW_DRIVER is not set
 CONFIG_HPET=y
 # CONFIG_HPET_RTC_IRQ is not set
-CONFIG_HPET_MMAP=y
+# CONFIG_HPET_MMAP is not set
 # CONFIG_HANGCHECK_TIMER is not set
 # CONFIG_TCG_TPM is not set
 # CONFIG_TELCLOCK is not set
 CONFIG_DEVPORT=y
-# CONFIG_I2C is not set
-
-#
-# SPI support
-#
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+# CONFIG_I2C_CHARDEV is not set
+
+#
+# I2C Hardware Bus support
+#
+# CONFIG_I2C_ALI1535 is not set
+# CONFIG_I2C_ALI1563 is not set
+# CONFIG_I2C_ALI15X3 is not set
+# CONFIG_I2C_AMD756 is not set
+# CONFIG_I2C_AMD8111 is not set
+CONFIG_I2C_I801=y
+# CONFIG_I2C_I810 is not set
+# CONFIG_I2C_PIIX4 is not set
+# CONFIG_I2C_NFORCE2 is not set
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_PROSAVAGE is not set
+# CONFIG_I2C_SAVAGE4 is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_SIS5595 is not set
+# CONFIG_I2C_SIS630 is not set
+# CONFIG_I2C_SIS96X is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_STUB is not set
+# CONFIG_I2C_TINY_USB is not set
+# CONFIG_I2C_VIA is not set
+# CONFIG_I2C_VIAPRO is not set
+# CONFIG_I2C_VOODOO3 is not set
+# CONFIG_I2C_PCA_PLATFORM is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_DS1682 is not set
+# CONFIG_SENSORS_EEPROM is not set
+# CONFIG_SENSORS_PCF8574 is not set
+# CONFIG_PCF8575 is not set
+# CONFIG_SENSORS_PCF8591 is not set
+# CONFIG_SENSORS_MAX6875 is not set
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
-# CONFIG_SPI_MASTER is not set
 # CONFIG_W1 is not set
-# CONFIG_POWER_SUPPLY is not set
+CONFIG_POWER_SUPPLY=y
+# CONFIG_POWER_SUPPLY_DEBUG is not set
+# CONFIG_PDA_POWER is not set
+# CONFIG_BATTERY_DS2760 is not set
 # CONFIG_HWMON is not set
+CONFIG_THERMAL=y
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+# CONFIG_ACQUIRE_WDT is not set
+# CONFIG_ADVANTECH_WDT is not set
+# CONFIG_ALIM1535_WDT is not set
+# CONFIG_ALIM7101_WDT is not set
+# CONFIG_SC520_WDT is not set
+# CONFIG_EUROTECH_WDT is not set
+# CONFIG_IB700_WDT is not set
+# CONFIG_IBMASR is not set
+# CONFIG_WAFER_WDT is not set
+# CONFIG_I6300ESB_WDT is not set
+# CONFIG_ITCO_WDT is not set
+# CONFIG_IT8712F_WDT is not set
+# CONFIG_HP_WATCHDOG is not set
+# CONFIG_SC1200_WDT is not set
+# CONFIG_PC87413_WDT is not set
+# CONFIG_60XX_WDT is not set
+# CONFIG_SBC8360_WDT is not set
+# CONFIG_CPU5_WDT is not set
+# CONFIG_SMSC37B787_WDT is not set
+# CONFIG_W83627HF_WDT is not set
+# CONFIG_W83697HF_WDT is not set
+# CONFIG_W83877F_WDT is not set
+# CONFIG_W83977F_WDT is not set
+# CONFIG_MACHZ_WDT is not set
+# CONFIG_SBC_EPX_C3_WATCHDOG is not set
+
+#
+# PCI-based Watchdog Cards
+#
+# CONFIG_PCIPCWATCHDOG is not set
+# CONFIG_WDTPCI is not set
+
+#
+# USB-based Watchdog Cards
+#
+# CONFIG_USBPCWATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
 
 #
 # Multifunction device drivers
 #
 # CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
 
 #
 # Multimedia devices
 #
+
+#
+# Multimedia core support
+#
 # CONFIG_VIDEO_DEV is not set
 # CONFIG_DVB_CORE is not set
+
+#
+# Multimedia drivers
+#
 CONFIG_DAB=y
 # CONFIG_USB_DABUSB is not set
 
 #
 # Graphics support
 #
-# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+CONFIG_AGP=y
+CONFIG_AGP_AMD64=y
+CONFIG_AGP_INTEL=y
+# CONFIG_AGP_SIS is not set
+# CONFIG_AGP_VIA is not set
+CONFIG_DRM=y
+# CONFIG_DRM_TDFX is not set
+# CONFIG_DRM_R128 is not set
+# CONFIG_DRM_RADEON is not set
+# CONFIG_DRM_I810 is not set
+# CONFIG_DRM_I830 is not set
+CONFIG_DRM_I915=y
+# CONFIG_DRM_MGA is not set
+# CONFIG_DRM_SIS is not set
+# CONFIG_DRM_VIA is not set
+# CONFIG_DRM_SAVAGE is not set
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+CONFIG_FB_CFB_FILLRECT=y
+CONFIG_FB_CFB_COPYAREA=y
+CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+CONFIG_FB_DEFERRED_IO=y
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+CONFIG_FB_MODE_HELPERS=y
+CONFIG_FB_TILEBLITTING=y
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_CIRRUS is not set
+# CONFIG_FB_PM2 is not set
+# CONFIG_FB_CYBER2000 is not set
+# CONFIG_FB_ARC is not set
+# CONFIG_FB_ASILIANT is not set
+# CONFIG_FB_IMSTT is not set
+# CONFIG_FB_VGA16 is not set
+# CONFIG_FB_UVESA is not set
+# CONFIG_FB_VESA is not set
+CONFIG_FB_EFI=y
+# CONFIG_FB_IMAC is not set
+# CONFIG_FB_N411 is not set
+# CONFIG_FB_HGA is not set
+# CONFIG_FB_S1D13XXX is not set
+# CONFIG_FB_NVIDIA is not set
+# CONFIG_FB_RIVA is not set
+# CONFIG_FB_LE80578 is not set
+# CONFIG_FB_INTEL is not set
+# CONFIG_FB_MATROX is not set
+# CONFIG_FB_RADEON is not set
+# CONFIG_FB_ATY128 is not set
+# CONFIG_FB_ATY is not set
+# CONFIG_FB_S3 is not set
+# CONFIG_FB_SAVAGE is not set
+# CONFIG_FB_SIS is not set
+# CONFIG_FB_NEOMAGIC is not set
+# CONFIG_FB_KYRO is not set
+# CONFIG_FB_3DFX is not set
+# CONFIG_FB_VOODOO1 is not set
+# CONFIG_FB_VT8623 is not set
+# CONFIG_FB_TRIDENT is not set
+# CONFIG_FB_ARK is not set
+# CONFIG_FB_PM3 is not set
+# CONFIG_FB_GEODE is not set
+# CONFIG_FB_VIRTUAL is not set
+CONFIG_BACKLIGHT_LCD_SUPPORT=y
+# CONFIG_LCD_CLASS_DEVICE is not set
+CONFIG_BACKLIGHT_CLASS_DEVICE=y
+# CONFIG_BACKLIGHT_CORGI is not set
+# CONFIG_BACKLIGHT_PROGEAR is not set
 
 #
 # Display device support
 #
 # CONFIG_DISPLAY_SUPPORT is not set
-# CONFIG_VGASTATE is not set
-# CONFIG_FB is not set
 
 #
 # Console display driver support
 #
 CONFIG_VGA_CONSOLE=y
 CONFIG_VGACON_SOFT_SCROLLBACK=y
-CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=256
+CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64
 CONFIG_VIDEO_SELECT=y
 CONFIG_DUMMY_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE is not set
+CONFIG_LOGO=y
+# CONFIG_LOGO_LINUX_MONO is not set
+# CONFIG_LOGO_LINUX_VGA16 is not set
+CONFIG_LOGO_LINUX_CLUT224=y
 
 #
 # Sound
@@ -958,33 +1465,165 @@ CONFIG_SOUND=y
 #
 # Advanced Linux Sound Architecture
 #
-# CONFIG_SND is not set
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+CONFIG_SND_HWDEP=y
+CONFIG_SND_SEQUENCER=y
+CONFIG_SND_SEQ_DUMMY=y
+CONFIG_SND_OSSEMUL=y
+CONFIG_SND_MIXER_OSS=y
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_PCM_OSS_PLUGINS=y
+CONFIG_SND_SEQUENCER_OSS=y
+CONFIG_SND_DYNAMIC_MINORS=y
+CONFIG_SND_SUPPORT_OLD_API=y
+CONFIG_SND_VERBOSE_PROCFS=y
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+CONFIG_SND_VMASTER=y
+
+#
+# Generic devices
+#
+# CONFIG_SND_PCSP is not set
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_VIRMIDI is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# PCI devices
+#
+# CONFIG_SND_AD1889 is not set
+# CONFIG_SND_ALS300 is not set
+# CONFIG_SND_ALS4000 is not set
+# CONFIG_SND_ALI5451 is not set
+# CONFIG_SND_ATIIXP is not set
+# CONFIG_SND_ATIIXP_MODEM is not set
+# CONFIG_SND_AU8810 is not set
+# CONFIG_SND_AU8820 is not set
+# CONFIG_SND_AU8830 is not set
+# CONFIG_SND_AW2 is not set
+# CONFIG_SND_AZT3328 is not set
+# CONFIG_SND_BT87X is not set
+# CONFIG_SND_CA0106 is not set
+# CONFIG_SND_CMIPCI is not set
+# CONFIG_SND_OXYGEN is not set
+# CONFIG_SND_CS4281 is not set
+# CONFIG_SND_CS46XX is not set
+# CONFIG_SND_CS5530 is not set
+# CONFIG_SND_DARLA20 is not set
+# CONFIG_SND_GINA20 is not set
+# CONFIG_SND_LAYLA20 is not set
+# CONFIG_SND_DARLA24 is not set
+# CONFIG_SND_GINA24 is not set
+# CONFIG_SND_LAYLA24 is not set
+# CONFIG_SND_MONA is not set
+# CONFIG_SND_MIA is not set
+# CONFIG_SND_ECHO3G is not set
+# CONFIG_SND_INDIGO is not set
+# CONFIG_SND_INDIGOIO is not set
+# CONFIG_SND_INDIGODJ is not set
+# CONFIG_SND_EMU10K1 is not set
+# CONFIG_SND_EMU10K1X is not set
+# CONFIG_SND_ENS1370 is not set
+# CONFIG_SND_ENS1371 is not set
+# CONFIG_SND_ES1938 is not set
+# CONFIG_SND_ES1968 is not set
+# CONFIG_SND_FM801 is not set
+CONFIG_SND_HDA_INTEL=y
+CONFIG_SND_HDA_HWDEP=y
+CONFIG_SND_HDA_CODEC_REALTEK=y
+CONFIG_SND_HDA_CODEC_ANALOG=y
+CONFIG_SND_HDA_CODEC_SIGMATEL=y
+CONFIG_SND_HDA_CODEC_VIA=y
+CONFIG_SND_HDA_CODEC_ATIHDMI=y
+CONFIG_SND_HDA_CODEC_CONEXANT=y
+CONFIG_SND_HDA_CODEC_CMEDIA=y
+CONFIG_SND_HDA_CODEC_SI3054=y
+CONFIG_SND_HDA_GENERIC=y
+# CONFIG_SND_HDA_POWER_SAVE is not set
+# CONFIG_SND_HDSP is not set
+# CONFIG_SND_HDSPM is not set
+# CONFIG_SND_HIFIER is not set
+# CONFIG_SND_ICE1712 is not set
+# CONFIG_SND_ICE1724 is not set
+# CONFIG_SND_INTEL8X0 is not set
+# CONFIG_SND_INTEL8X0M is not set
+# CONFIG_SND_KORG1212 is not set
+# CONFIG_SND_MAESTRO3 is not set
+# CONFIG_SND_MIXART is not set
+# CONFIG_SND_NM256 is not set
+# CONFIG_SND_PCXHR is not set
+# CONFIG_SND_RIPTIDE is not set
+# CONFIG_SND_RME32 is not set
+# CONFIG_SND_RME96 is not set
+# CONFIG_SND_RME9652 is not set
+# CONFIG_SND_SONICVIBES is not set
+# CONFIG_SND_TRIDENT is not set
+# CONFIG_SND_VIA82XX is not set
+# CONFIG_SND_VIA82XX_MODEM is not set
+# CONFIG_SND_VIRTUOSO is not set
+# CONFIG_SND_VX222 is not set
+# CONFIG_SND_YMFPCI is not set
+
+#
+# USB devices
+#
+# CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_USX2Y is not set
+# CONFIG_SND_USB_CAIAQ is not set
+
+#
+# PCMCIA devices
+#
+# CONFIG_SND_VXPOCKET is not set
+# CONFIG_SND_PDAUDIOCF is not set
+
+#
+# System on Chip audio support
+#
+# CONFIG_SND_SOC is not set
+
+#
+# ALSA SoC audio for Freescale SOCs
+#
+
+#
+# SoC Audio for the Texas Instruments OMAP
+#
 
 #
 # Open Sound System
 #
-CONFIG_SOUND_PRIME=y
-# CONFIG_SOUND_TRIDENT is not set
-# CONFIG_SOUND_MSNDCLAS is not set
-# CONFIG_SOUND_MSNDPIN is not set
-# CONFIG_SOUND_OSS is not set
+# CONFIG_SOUND_PRIME is not set
 CONFIG_HID_SUPPORT=y
 CONFIG_HID=y
-# CONFIG_HID_DEBUG is not set
+CONFIG_HID_DEBUG=y
+CONFIG_HIDRAW=y
 
 #
 # USB Input Devices
 #
 CONFIG_USB_HID=y
-# CONFIG_USB_HIDINPUT_POWERBOOK is not set
-# CONFIG_HID_FF is not set
-# CONFIG_USB_HIDDEV is not set
+CONFIG_USB_HIDINPUT_POWERBOOK=y
+CONFIG_HID_FF=y
+CONFIG_HID_PID=y
+CONFIG_LOGITECH_FF=y
+# CONFIG_LOGIRUMBLEPAD2_FF is not set
+CONFIG_PANTHERLORD_FF=y
+CONFIG_THRUSTMASTER_FF=y
+CONFIG_ZEROPLUS_FF=y
+CONFIG_USB_HIDDEV=y
 CONFIG_USB_SUPPORT=y
 CONFIG_USB_ARCH_HAS_HCD=y
 CONFIG_USB_ARCH_HAS_OHCI=y
 CONFIG_USB_ARCH_HAS_EHCI=y
 CONFIG_USB=y
-# CONFIG_USB_DEBUG is not set
+CONFIG_USB_DEBUG=y
+CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
 
 #
 # Miscellaneous USB options
@@ -992,18 +1631,18 @@ CONFIG_USB=y
 CONFIG_USB_DEVICEFS=y
 # CONFIG_USB_DEVICE_CLASS is not set
 # CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
-# CONFIG_USB_PERSIST is not set
+CONFIG_USB_SUSPEND=y
 # CONFIG_USB_OTG is not set
 
 #
 # USB Host Controller Drivers
 #
+# CONFIG_USB_C67X00_HCD is not set
 CONFIG_USB_EHCI_HCD=y
-# CONFIG_USB_EHCI_SPLIT_ISO is not set
 # CONFIG_USB_EHCI_ROOT_HUB_TT is not set
 # CONFIG_USB_EHCI_TT_NEWSCHED is not set
 # CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
 CONFIG_USB_OHCI_HCD=y
 # CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
 # CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
@@ -1036,8 +1675,10 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_STORAGE_SDDR55 is not set
 # CONFIG_USB_STORAGE_JUMPSHOT is not set
 # CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
 # CONFIG_USB_STORAGE_KARMA is not set
-# CONFIG_USB_LIBUSUAL is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+CONFIG_USB_LIBUSUAL=y
 
 #
 # USB Imaging devices
@@ -1049,10 +1690,6 @@ CONFIG_USB_MON=y
 #
 # USB port drivers
 #
-
-#
-# USB Serial Converter support
-#
 # CONFIG_USB_SERIAL is not set
 
 #
@@ -1078,98 +1715,126 @@ CONFIG_USB_MON=y
 # CONFIG_USB_TRANCEVIBRATOR is not set
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
+# CONFIG_USB_GADGET is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
 
 #
-# USB DSL modem support
+# LED drivers
 #
+# CONFIG_LEDS_CLEVO_MAIL is not set
 
 #
-# USB Gadget Support
+# LED Triggers
 #
-# CONFIG_USB_GADGET is not set
-# CONFIG_MMC is not set
+CONFIG_LEDS_TRIGGERS=y
+# CONFIG_LEDS_TRIGGER_TIMER is not set
+# CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
+# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
+# CONFIG_ACCESSIBILITY is not set
+# CONFIG_INFINIBAND is not set
+CONFIG_EDAC=y
 
 #
-# LED devices
+# Reporting subsystems
 #
-# CONFIG_NEW_LEDS is not set
+# CONFIG_EDAC_DEBUG is not set
+# CONFIG_EDAC_MM_EDAC is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+# CONFIG_RTC_DEBUG is not set
 
 #
-# LED drivers
+# RTC interfaces
 #
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
 
 #
-# LED Triggers
+# I2C RTC drivers
 #
-# CONFIG_INFINIBAND is not set
-# CONFIG_EDAC is not set
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_S35390A is not set
 
 #
-# Real Time Clock
+# SPI RTC drivers
 #
-# CONFIG_RTC_CLASS is not set
 
 #
-# DMA Engine support
+# Platform RTC drivers
 #
-# CONFIG_DMA_ENGINE is not set
+CONFIG_RTC_DRV_CMOS=y
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_V3020 is not set
 
 #
-# DMA Clients
+# on-CPU RTC drivers
 #
+CONFIG_DMADEVICES=y
 
 #
 # DMA Devices
 #
-CONFIG_VIRTUALIZATION=y
-# CONFIG_KVM is not set
-
-#
-# Userspace I/O
-#
+# CONFIG_INTEL_IOATDMA is not set
 # CONFIG_UIO is not set
 
 #
 # Firmware Drivers
 #
 # CONFIG_EDD is not set
+CONFIG_EFI_VARS=y
 # CONFIG_DELL_RBU is not set
 # CONFIG_DCDBAS is not set
 CONFIG_DMIID=y
+# CONFIG_ISCSI_IBFT_FIND is not set
 
 #
 # File systems
 #
-CONFIG_EXT2_FS=y
-CONFIG_EXT2_FS_XATTR=y
-CONFIG_EXT2_FS_POSIX_ACL=y
-# CONFIG_EXT2_FS_SECURITY is not set
-# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT2_FS is not set
 CONFIG_EXT3_FS=y
 CONFIG_EXT3_FS_XATTR=y
 CONFIG_EXT3_FS_POSIX_ACL=y
-# CONFIG_EXT3_FS_SECURITY is not set
+CONFIG_EXT3_FS_SECURITY=y
 # CONFIG_EXT4DEV_FS is not set
 CONFIG_JBD=y
 # CONFIG_JBD_DEBUG is not set
 CONFIG_FS_MBCACHE=y
-CONFIG_REISERFS_FS=y
-# CONFIG_REISERFS_CHECK is not set
-# CONFIG_REISERFS_PROC_INFO is not set
-CONFIG_REISERFS_FS_XATTR=y
-CONFIG_REISERFS_FS_POSIX_ACL=y
-# CONFIG_REISERFS_FS_SECURITY is not set
+# CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 CONFIG_FS_POSIX_ACL=y
 # CONFIG_XFS_FS is not set
 # CONFIG_GFS2_FS is not set
 # CONFIG_OCFS2_FS is not set
-# CONFIG_MINIX_FS is not set
-# CONFIG_ROMFS_FS is not set
+CONFIG_DNOTIFY=y
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
-# CONFIG_QUOTA is not set
-CONFIG_DNOTIFY=y
+CONFIG_QUOTA=y
+CONFIG_QUOTA_NETLINK_INTERFACE=y
+# CONFIG_PRINT_QUOTA_WARNING is not set
+# CONFIG_QFMT_V1 is not set
+CONFIG_QFMT_V2=y
+CONFIG_QUOTACTL=y
 # CONFIG_AUTOFS_FS is not set
 CONFIG_AUTOFS4_FS=y
 # CONFIG_FUSE_FS is not set
@@ -1180,7 +1845,7 @@ CONFIG_GENERIC_ACL=y
 #
 CONFIG_ISO9660_FS=y
 CONFIG_JOLIET=y
-# CONFIG_ZISOFS is not set
+CONFIG_ZISOFS=y
 # CONFIG_UDF_FS is not set
 
 #
@@ -1198,13 +1863,13 @@ CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
 #
 CONFIG_PROC_FS=y
 CONFIG_PROC_KCORE=y
+CONFIG_PROC_VMCORE=y
 CONFIG_PROC_SYSCTL=y
 CONFIG_SYSFS=y
 CONFIG_TMPFS=y
 CONFIG_TMPFS_POSIX_ACL=y
 CONFIG_HUGETLBFS=y
 CONFIG_HUGETLB_PAGE=y
-CONFIG_RAMFS=y
 # CONFIG_CONFIGFS_FS is not set
 
 #
@@ -1212,6 +1877,7 @@ CONFIG_RAMFS=y
 #
 # CONFIG_ADFS_FS is not set
 # CONFIG_AFFS_FS is not set
+# CONFIG_ECRYPT_FS is not set
 # CONFIG_HFS_FS is not set
 # CONFIG_HFSPLUS_FS is not set
 # CONFIG_BEFS_FS is not set
@@ -1219,33 +1885,15 @@ CONFIG_RAMFS=y
 # CONFIG_EFS_FS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
 # CONFIG_HPFS_FS is not set
 # CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
-
-#
-# Network File Systems
-#
-CONFIG_NFS_FS=y
-CONFIG_NFS_V3=y
-# CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
-# CONFIG_NFS_DIRECTIO is not set
-CONFIG_NFSD=y
-CONFIG_NFSD_V3=y
-# CONFIG_NFSD_V3_ACL is not set
-# CONFIG_NFSD_V4 is not set
-CONFIG_NFSD_TCP=y
-CONFIG_ROOT_NFS=y
-CONFIG_LOCKD=y
-CONFIG_LOCKD_V4=y
-CONFIG_EXPORTFS=y
-CONFIG_NFS_COMMON=y
-CONFIG_SUNRPC=y
-# CONFIG_SUNRPC_BIND34 is not set
-# CONFIG_RPCSEC_GSS_KRB5 is not set
-# CONFIG_RPCSEC_GSS_SPKM3 is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+# CONFIG_NFS_FS is not set
+# CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
@@ -1255,14 +1903,26 @@ CONFIG_SUNRPC=y
 #
 # Partition Types
 #
-# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+CONFIG_OSF_PARTITION=y
+CONFIG_AMIGA_PARTITION=y
+# CONFIG_ATARI_PARTITION is not set
+CONFIG_MAC_PARTITION=y
 CONFIG_MSDOS_PARTITION=y
-
-#
-# Native Language Support
-#
+CONFIG_BSD_DISKLABEL=y
+CONFIG_MINIX_SUBPARTITION=y
+CONFIG_SOLARIS_X86_PARTITION=y
+CONFIG_UNIXWARE_DISKLABEL=y
+# CONFIG_LDM_PARTITION is not set
+CONFIG_SGI_PARTITION=y
+# CONFIG_ULTRIX_PARTITION is not set
+CONFIG_SUN_PARTITION=y
+CONFIG_KARMA_PARTITION=y
+CONFIG_EFI_PARTITION=y
+# CONFIG_SYSV68_PARTITION is not set
 CONFIG_NLS=y
-CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_DEFAULT="utf8"
 CONFIG_NLS_CODEPAGE_437=y
 # CONFIG_NLS_CODEPAGE_737 is not set
 # CONFIG_NLS_CODEPAGE_775 is not set
@@ -1297,40 +1957,33 @@ CONFIG_NLS_ISO8859_1=y
 # CONFIG_NLS_ISO8859_9 is not set
 # CONFIG_NLS_ISO8859_13 is not set
 # CONFIG_NLS_ISO8859_14 is not set
-CONFIG_NLS_ISO8859_15=y
+# CONFIG_NLS_ISO8859_15 is not set
 # CONFIG_NLS_KOI8_R is not set
 # CONFIG_NLS_KOI8_U is not set
 CONFIG_NLS_UTF8=y
-
-#
-# Distributed Lock Manager
-#
 # CONFIG_DLM is not set
 
-#
-# Instrumentation Support
-#
-CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_KPROBES=y
-
 #
 # Kernel hacking
 #
 CONFIG_TRACE_IRQFLAGS_SUPPORT=y
 # CONFIG_PRINTK_TIME is not set
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
 # CONFIG_ENABLE_MUST_CHECK is not set
+CONFIG_FRAME_WARN=2048
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_UNUSED_SYMBOLS=y
+# CONFIG_UNUSED_SYMBOLS is not set
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SHIRQ is not set
-CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_DETECT_SOFTLOCKUP is not set
 # CONFIG_SCHED_DEBUG is not set
-# CONFIG_SCHEDSTATS is not set
+CONFIG_SCHEDSTATS=y
 CONFIG_TIMER_STATS=y
-# CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1344,28 +1997,162 @@ CONFIG_TIMER_STATS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
 # CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
 # CONFIG_DEBUG_LIST is not set
-# CONFIG_FRAME_POINTER is not set
-CONFIG_OPTIMIZE_INLINING=y
+# CONFIG_DEBUG_SG is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
 # CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
-# CONFIG_DEBUG_RODATA is not set
-# CONFIG_IOMMU_DEBUG is not set
+# CONFIG_LATENCYTOP is not set
+CONFIG_PROVIDE_OHCI1394_DMA_INIT=y
+# CONFIG_SAMPLES is not set
+# CONFIG_KGDB is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_NONPROMISC_DEVMEM is not set
+CONFIG_EARLY_PRINTK=y
 CONFIG_DEBUG_STACKOVERFLOW=y
-# CONFIG_DEBUG_STACK_USAGE is not set
+CONFIG_DEBUG_STACK_USAGE=y
+# CONFIG_DEBUG_PAGEALLOC is not set
+# CONFIG_DEBUG_PER_CPU_MAPS is not set
+# CONFIG_X86_PTDUMP is not set
+CONFIG_DEBUG_RODATA=y
+# CONFIG_DIRECT_GBPAGES is not set
+# CONFIG_DEBUG_RODATA_TEST is not set
+CONFIG_DEBUG_NX_TEST=m
+CONFIG_X86_MPPARSE=y
+# CONFIG_IOMMU_DEBUG is not set
+CONFIG_IO_DELAY_TYPE_0X80=0
+CONFIG_IO_DELAY_TYPE_0XED=1
+CONFIG_IO_DELAY_TYPE_UDELAY=2
+CONFIG_IO_DELAY_TYPE_NONE=3
+CONFIG_IO_DELAY_0X80=y
+# CONFIG_IO_DELAY_0XED is not set
+# CONFIG_IO_DELAY_UDELAY is not set
+# CONFIG_IO_DELAY_NONE is not set
+CONFIG_DEFAULT_IO_DELAY_TYPE=0
+CONFIG_DEBUG_BOOT_PARAMS=y
+# CONFIG_CPA_DEBUG is not set
 
 #
 # Security options
 #
-# CONFIG_KEYS is not set
-# CONFIG_SECURITY is not set
-# CONFIG_CRYPTO is not set
+CONFIG_KEYS=y
+CONFIG_KEYS_DEBUG_PROC_KEYS=y
+CONFIG_SECURITY=y
+CONFIG_SECURITY_NETWORK=y
+# CONFIG_SECURITY_NETWORK_XFRM is not set
+CONFIG_SECURITY_CAPABILITIES=y
+CONFIG_SECURITY_FILE_CAPABILITIES=y
+# CONFIG_SECURITY_ROOTPLUG is not set
+CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR=65536
+CONFIG_SECURITY_SELINUX=y
+CONFIG_SECURITY_SELINUX_BOOTPARAM=y
+CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
+CONFIG_SECURITY_SELINUX_DISABLE=y
+CONFIG_SECURITY_SELINUX_DEVELOP=y
+CONFIG_SECURITY_SELINUX_AVC_STATS=y
+CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1
+# CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT is not set
+# CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX is not set
+# CONFIG_SECURITY_SMACK is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_AEAD=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_HASH=y
+CONFIG_CRYPTO_MANAGER=y
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+CONFIG_CRYPTO_AUTHENC=y
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+CONFIG_CRYPTO_CBC=y
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+CONFIG_CRYPTO_ECB=y
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+CONFIG_CRYPTO_HMAC=y
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+CONFIG_CRYPTO_MD5=y
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+CONFIG_CRYPTO_SHA1=y
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+CONFIG_CRYPTO_AES=y
+# CONFIG_CRYPTO_AES_X86_64 is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+CONFIG_CRYPTO_ARC4=y
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SALSA20_X86_64 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+# CONFIG_CRYPTO_TWOFISH_X86_64 is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_HW=y
+# CONFIG_CRYPTO_DEV_HIFN_795X is not set
+CONFIG_HAVE_KVM=y
+CONFIG_VIRTUALIZATION=y
+# CONFIG_KVM is not set
+# CONFIG_VIRTIO_PCI is not set
+# CONFIG_VIRTIO_BALLOON is not set
 
 #
 # Library routines
 #
 CONFIG_BITREVERSE=y
+CONFIG_GENERIC_FIND_FIRST_BIT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
 # CONFIG_CRC_CCITT is not set
 # CONFIG_CRC16 is not set
 # CONFIG_CRC_ITU_T is not set
index b5e329d..20371d0 100644 (file)
        CFI_UNDEFINED   r15
        .endm
 
+#ifdef CONFIG_PARAVIRT
+ENTRY(native_usergs_sysret32)
+       swapgs
+       sysretl
+ENDPROC(native_usergs_sysret32)
+
+ENTRY(native_irq_enable_sysexit)
+       swapgs
+       sti
+       sysexit
+ENDPROC(native_irq_enable_sysexit)
+#endif
+
 /*
  * 32bit SYSENTER instruction entry.
  *
@@ -85,14 +98,14 @@ ENTRY(ia32_sysenter_target)
        CFI_SIGNAL_FRAME
        CFI_DEF_CFA     rsp,0
        CFI_REGISTER    rsp,rbp
-       swapgs
+       SWAPGS_UNSAFE_STACK
        movq    %gs:pda_kernelstack, %rsp
        addq    $(PDA_STACKOFFSET),%rsp 
        /*
         * No need to follow this irqs on/off section: the syscall
         * disabled irqs, here we enable it straight after entry:
         */
-       sti     
+       ENABLE_INTERRUPTS(CLBR_NONE)
        movl    %ebp,%ebp               /* zero extension */
        pushq   $__USER32_DS
        CFI_ADJUST_CFA_OFFSET 8
@@ -103,7 +116,7 @@ ENTRY(ia32_sysenter_target)
        pushfq
        CFI_ADJUST_CFA_OFFSET 8
        /*CFI_REL_OFFSET rflags,0*/
-       movl    8*3-THREAD_SIZE+threadinfo_sysenter_return(%rsp), %r10d
+       movl    8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
        CFI_REGISTER rip,r10
        pushq   $__USER32_CS
        CFI_ADJUST_CFA_OFFSET 8
@@ -123,8 +136,9 @@ ENTRY(ia32_sysenter_target)
        .quad 1b,ia32_badarg
        .previous       
        GET_THREAD_INFO(%r10)
-       orl    $TS_COMPAT,threadinfo_status(%r10)
-       testl  $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
+       orl    $TS_COMPAT,TI_status(%r10)
+       testl  $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
+                TI_flags(%r10)
        CFI_REMEMBER_STATE
        jnz  sysenter_tracesys
 sysenter_do_call:      
@@ -134,11 +148,11 @@ sysenter_do_call:
        call    *ia32_sys_call_table(,%rax,8)
        movq    %rax,RAX-ARGOFFSET(%rsp)
        GET_THREAD_INFO(%r10)
-       cli
+       DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
-       testl   $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
+       testl   $_TIF_ALLWORK_MASK,TI_flags(%r10)
        jnz     int_ret_from_sys_call
-       andl    $~TS_COMPAT,threadinfo_status(%r10)
+       andl    $~TS_COMPAT,TI_status(%r10)
        /* clear IF, that popfq doesn't enable interrupts early */
        andl  $~0x200,EFLAGS-R11(%rsp) 
        movl    RIP-R11(%rsp),%edx              /* User %eip */
@@ -151,10 +165,7 @@ sysenter_do_call:
        CFI_ADJUST_CFA_OFFSET -8
        CFI_REGISTER rsp,rcx
        TRACE_IRQS_ON
-       swapgs
-       sti             /* sti only takes effect after the next instruction */
-       /* sysexit */
-       .byte   0xf, 0x35
+       ENABLE_INTERRUPTS_SYSEXIT32
 
 sysenter_tracesys:
        CFI_RESTORE_STATE
@@ -200,7 +211,7 @@ ENTRY(ia32_cstar_target)
        CFI_DEF_CFA     rsp,PDA_STACKOFFSET
        CFI_REGISTER    rip,rcx
        /*CFI_REGISTER  rflags,r11*/
-       swapgs
+       SWAPGS_UNSAFE_STACK
        movl    %esp,%r8d
        CFI_REGISTER    rsp,r8
        movq    %gs:pda_kernelstack,%rsp
@@ -208,7 +219,7 @@ ENTRY(ia32_cstar_target)
         * No need to follow this irqs on/off section: the syscall
         * disabled irqs and here we enable it straight after entry:
         */
-       sti
+       ENABLE_INTERRUPTS(CLBR_NONE)
        SAVE_ARGS 8,1,1
        movl    %eax,%eax       /* zero extension */
        movq    %rax,ORIG_RAX-ARGOFFSET(%rsp)
@@ -230,8 +241,9 @@ ENTRY(ia32_cstar_target)
        .quad 1b,ia32_badarg
        .previous       
        GET_THREAD_INFO(%r10)
-       orl   $TS_COMPAT,threadinfo_status(%r10)
-       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
+       orl   $TS_COMPAT,TI_status(%r10)
+       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
+               TI_flags(%r10)
        CFI_REMEMBER_STATE
        jnz   cstar_tracesys
 cstar_do_call: 
@@ -241,11 +253,11 @@ cstar_do_call:
        call *ia32_sys_call_table(,%rax,8)
        movq %rax,RAX-ARGOFFSET(%rsp)
        GET_THREAD_INFO(%r10)
-       cli
+       DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
-       testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
+       testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
        jnz  int_ret_from_sys_call
-       andl $~TS_COMPAT,threadinfo_status(%r10)
+       andl $~TS_COMPAT,TI_status(%r10)
        RESTORE_ARGS 1,-ARG_SKIP,1,1,1
        movl RIP-ARGOFFSET(%rsp),%ecx
        CFI_REGISTER rip,rcx
@@ -254,8 +266,7 @@ cstar_do_call:
        TRACE_IRQS_ON
        movl RSP-ARGOFFSET(%rsp),%esp
        CFI_RESTORE rsp
-       swapgs
-       sysretl
+       USERGS_SYSRET32
        
 cstar_tracesys:        
        CFI_RESTORE_STATE
@@ -310,12 +321,12 @@ ENTRY(ia32_syscall)
        /*CFI_REL_OFFSET        rflags,EFLAGS-RIP*/
        /*CFI_REL_OFFSET        cs,CS-RIP*/
        CFI_REL_OFFSET  rip,RIP-RIP
-       swapgs
+       SWAPGS
        /*
         * No need to follow this irqs on/off section: the syscall
         * disabled irqs and here we enable it straight after entry:
         */
-       sti
+       ENABLE_INTERRUPTS(CLBR_NONE)
        movl %eax,%eax
        pushq %rax
        CFI_ADJUST_CFA_OFFSET 8
@@ -324,8 +335,9 @@ ENTRY(ia32_syscall)
           this could be a problem. */
        SAVE_ARGS 0,0,1
        GET_THREAD_INFO(%r10)
-       orl   $TS_COMPAT,threadinfo_status(%r10)
-       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
+       orl   $TS_COMPAT,TI_status(%r10)
+       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
+               TI_flags(%r10)
        jnz ia32_tracesys
 ia32_do_syscall:       
        cmpl $(IA32_NR_syscalls-1),%eax
@@ -370,13 +382,11 @@ quiet_ni_syscall:
        PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
        PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
        PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
-       PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx
        PTREGSCALL stub32_execve, sys32_execve, %rcx
        PTREGSCALL stub32_fork, sys_fork, %rdi
        PTREGSCALL stub32_clone, sys32_clone, %rdx
        PTREGSCALL stub32_vfork, sys_vfork, %rdi
        PTREGSCALL stub32_iopl, sys_iopl, %rsi
-       PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
 
 ENTRY(ia32_ptregs_common)
        popq %r11
@@ -476,7 +486,7 @@ ia32_sys_call_table:
        .quad sys_ssetmask
        .quad sys_setreuid16    /* 70 */
        .quad sys_setregid16
-       .quad stub32_sigsuspend
+       .quad sys32_sigsuspend
        .quad compat_sys_sigpending
        .quad sys_sethostname
        .quad compat_sys_setrlimit      /* 75 */
@@ -583,7 +593,7 @@ ia32_sys_call_table:
        .quad sys32_rt_sigpending
        .quad compat_sys_rt_sigtimedwait
        .quad sys32_rt_sigqueueinfo
-       .quad stub32_rt_sigsuspend
+       .quad sys_rt_sigsuspend
        .quad sys32_pread               /* 180 */
        .quad sys32_pwrite
        .quad sys_chown16
index 77807d4..5112c84 100644 (file)
@@ -2,10 +2,17 @@
 # Makefile for the linux kernel.
 #
 
-extra-y                := head_$(BITS).o head$(BITS).o init_task.o vmlinux.lds
+extra-y                := head_$(BITS).o head$(BITS).o head.o init_task.o vmlinux.lds
 
 CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)
 
+ifdef CONFIG_FTRACE
+# Do not profile debug utilities
+CFLAGS_REMOVE_tsc_64.o = -pg
+CFLAGS_REMOVE_tsc_32.o = -pg
+CFLAGS_REMOVE_rtc.o = -pg
+endif
+
 #
 # vsyscalls (which work on the user stack) should have
 # no stack-protector checks:
@@ -13,20 +20,21 @@ CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)
 nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_vsyscall_64.o   := $(PROFILING) -g0 $(nostackp)
 CFLAGS_hpet.o          := $(nostackp)
-CFLAGS_tsc_64.o                := $(nostackp)
+CFLAGS_tsc.o           := $(nostackp)
 
 obj-y                  := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o
 obj-y                  += traps_$(BITS).o irq_$(BITS).o
 obj-y                  += time_$(BITS).o ioport.o ldt.o
-obj-y                  += setup_$(BITS).o i8259_$(BITS).o setup.o
+obj-y                  += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o
+obj-$(CONFIG_X86_VISWS)        += visws_quirks.o
+obj-$(CONFIG_X86_32)   += probe_roms_32.o
 obj-$(CONFIG_X86_32)   += sys_i386_32.o i386_ksyms_32.o
 obj-$(CONFIG_X86_64)   += sys_x86_64.o x8664_ksyms_64.o
-obj-$(CONFIG_X86_64)   += syscall_64.o vsyscall_64.o setup64.o
-obj-y                  += bootflag.o e820_$(BITS).o
+obj-$(CONFIG_X86_64)   += syscall_64.o vsyscall_64.o
+obj-y                  += bootflag.o e820.o
 obj-y                  += pci-dma.o quirks.o i8237.o topology.o kdebugfs.o
 obj-y                  += alternative.o i8253.o pci-nommu.o
-obj-$(CONFIG_X86_64)   += bugs_64.o
-obj-y                  += tsc_$(BITS).o io_delay.o rtc.o
+obj-y                  += tsc.o io_delay.o rtc.o
 
 obj-$(CONFIG_X86_TRAMPOLINE)   += trampoline.o
 obj-y                          += process.o
@@ -53,9 +61,10 @@ obj-$(CONFIG_X86_32_SMP)     += smpcommon.o
 obj-$(CONFIG_X86_64_SMP)       += tsc_sync.o smpcommon.o
 obj-$(CONFIG_X86_TRAMPOLINE)   += trampoline_$(BITS).o
 obj-$(CONFIG_X86_MPPARSE)      += mpparse.o
-obj-$(CONFIG_X86_LOCAL_APIC)   += apic_$(BITS).o nmi_$(BITS).o
+obj-$(CONFIG_X86_LOCAL_APIC)   += apic_$(BITS).o nmi.o
 obj-$(CONFIG_X86_IO_APIC)      += io_apic_$(BITS).o
 obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
+obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
 obj-$(CONFIG_KEXEC)            += machine_kexec_$(BITS).o
 obj-$(CONFIG_KEXEC)            += relocate_kernel_$(BITS).o crash.o
 obj-$(CONFIG_CRASH_DUMP)       += crash_dump_$(BITS).o
@@ -64,7 +73,6 @@ obj-$(CONFIG_X86_SUMMIT_NUMA) += summit_32.o
 obj-y                          += vsmp_64.o
 obj-$(CONFIG_KPROBES)          += kprobes.o
 obj-$(CONFIG_MODULES)          += module_$(BITS).o
-obj-$(CONFIG_ACPI_SRAT)        += srat_32.o
 obj-$(CONFIG_EFI)              += efi.o efi_$(BITS).o efi_stub_$(BITS).o
 obj-$(CONFIG_DOUBLEFAULT)      += doublefault_32.o
 obj-$(CONFIG_KGDB)             += kgdb.o
@@ -94,12 +102,13 @@ obj-$(CONFIG_OLPC)         += olpc.o
 ###
 # 64 bit specific files
 ifeq ($(CONFIG_X86_64),y)
-        obj-y                          += genapic_64.o genapic_flat_64.o genx2apic_uv_x.o
+        obj-y                          += genapic_64.o genapic_flat_64.o genx2apic_uv_x.o tlb_uv.o
         obj-$(CONFIG_X86_PM_TIMER)     += pmtimer_64.o
         obj-$(CONFIG_AUDIT)            += audit_64.o
 
         obj-$(CONFIG_GART_IOMMU)       += pci-gart_64.o aperture_64.o
         obj-$(CONFIG_CALGARY_IOMMU)    += pci-calgary_64.o tce_64.o
+        obj-$(CONFIG_AMD_IOMMU)                += amd_iommu_init.o amd_iommu.o
         obj-$(CONFIG_SWIOTLB)          += pci-swiotlb_64.o
 
         obj-$(CONFIG_PCI_MMCONFIG)     += mmconf-fam10h_64.o
index 33c5216..f489d7a 100644 (file)
@@ -37,6 +37,7 @@
 #include <asm/pgtable.h>
 #include <asm/io_apic.h>
 #include <asm/apic.h>
+#include <asm/genapic.h>
 #include <asm/io.h>
 #include <asm/mpspec.h>
 #include <asm/smp.h>
@@ -106,21 +107,6 @@ static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  */
 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
 
-#ifdef CONFIG_X86_64
-
-/* rely on all ACPI tables being in the direct mapping */
-char *__init __acpi_map_table(unsigned long phys_addr, unsigned long size)
-{
-       if (!phys_addr || !size)
-               return NULL;
-
-       if (phys_addr+size <= (max_pfn_mapped << PAGE_SHIFT) + PAGE_SIZE)
-               return __va(phys_addr);
-
-       return NULL;
-}
-
-#else
 
 /*
  * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
@@ -139,11 +125,15 @@ char *__init __acpi_map_table(unsigned long phys, unsigned long size)
        unsigned long base, offset, mapped_size;
        int idx;
 
-       if (phys + size < 8 * 1024 * 1024)
+       if (!phys || !size)
+               return NULL;
+
+       if (phys+size <= (max_low_pfn_mapped << PAGE_SHIFT))
                return __va(phys);
 
        offset = phys & (PAGE_SIZE - 1);
        mapped_size = PAGE_SIZE - offset;
+       clear_fixmap(FIX_ACPI_END);
        set_fixmap(FIX_ACPI_END, phys);
        base = fix_to_virt(FIX_ACPI_END);
 
@@ -155,13 +145,13 @@ char *__init __acpi_map_table(unsigned long phys, unsigned long size)
                if (--idx < FIX_ACPI_BEGIN)
                        return NULL;    /* cannot handle this */
                phys += PAGE_SIZE;
+               clear_fixmap(idx);
                set_fixmap(idx, phys);
                mapped_size += PAGE_SIZE;
        }
 
        return ((unsigned char *)base + offset);
 }
-#endif
 
 #ifdef CONFIG_PCI_MMCONFIG
 /* The physical address of the MMCONFIG aperture.  Set from ACPI tables. */
@@ -338,8 +328,6 @@ acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long e
 
 #ifdef CONFIG_X86_IO_APIC
 
-struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
-
 static int __init
 acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
 {
@@ -514,8 +502,6 @@ int acpi_register_gsi(u32 gsi, int triggering, int polarity)
         * Make sure all (legacy) PCI IRQs are set as level-triggered.
         */
        if (acpi_irq_model == ACPI_IRQ_MODEL_PIC) {
-               extern void eisa_set_level_irq(unsigned int irq);
-
                if (triggering == ACPI_LEVEL_SENSITIVE)
                        eisa_set_level_irq(gsi);
        }
@@ -860,6 +846,364 @@ static int __init acpi_parse_madt_lapic_entries(void)
 #endif                         /* CONFIG_X86_LOCAL_APIC */
 
 #ifdef CONFIG_X86_IO_APIC
+#define MP_ISA_BUS             0
+
+#ifdef CONFIG_X86_ES7000
+extern int es7000_plat;
+#endif
+
+static struct {
+       int apic_id;
+       int gsi_base;
+       int gsi_end;
+       DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
+} mp_ioapic_routing[MAX_IO_APICS];
+
+static int mp_find_ioapic(int gsi)
+{
+       int i = 0;
+
+       /* Find the IOAPIC that manages this GSI. */
+       for (i = 0; i < nr_ioapics; i++) {
+               if ((gsi >= mp_ioapic_routing[i].gsi_base)
+                   && (gsi <= mp_ioapic_routing[i].gsi_end))
+                       return i;
+       }
+
+       printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
+       return -1;
+}
+
+static u8 __init uniq_ioapic_id(u8 id)
+{
+#ifdef CONFIG_X86_32
+       if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
+           !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
+               return io_apic_get_unique_id(nr_ioapics, id);
+       else
+               return id;
+#else
+       int i;
+       DECLARE_BITMAP(used, 256);
+       bitmap_zero(used, 256);
+       for (i = 0; i < nr_ioapics; i++) {
+               struct mp_config_ioapic *ia = &mp_ioapics[i];
+               __set_bit(ia->mp_apicid, used);
+       }
+       if (!test_bit(id, used))
+               return id;
+       return find_first_zero_bit(used, 256);
+#endif
+}
+
+static int bad_ioapic(unsigned long address)
+{
+       if (nr_ioapics >= MAX_IO_APICS) {
+               printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
+                      "(found %d)\n", MAX_IO_APICS, nr_ioapics);
+               panic("Recompile kernel with bigger MAX_IO_APICS!\n");
+       }
+       if (!address) {
+               printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
+                      " found in table, skipping!\n");
+               return 1;
+       }
+       return 0;
+}
+
+void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
+{
+       int idx = 0;
+
+       if (bad_ioapic(address))
+               return;
+
+       idx = nr_ioapics;
+
+       mp_ioapics[idx].mp_type = MP_IOAPIC;
+       mp_ioapics[idx].mp_flags = MPC_APIC_USABLE;
+       mp_ioapics[idx].mp_apicaddr = address;
+
+       set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
+       mp_ioapics[idx].mp_apicid = uniq_ioapic_id(id);
+#ifdef CONFIG_X86_32
+       mp_ioapics[idx].mp_apicver = io_apic_get_version(idx);
+#else
+       mp_ioapics[idx].mp_apicver = 0;
+#endif
+       /*
+        * Build basic GSI lookup table to facilitate gsi->io_apic lookups
+        * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
+        */
+       mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mp_apicid;
+       mp_ioapic_routing[idx].gsi_base = gsi_base;
+       mp_ioapic_routing[idx].gsi_end = gsi_base +
+           io_apic_get_redir_entries(idx);
+
+       printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%lx, "
+              "GSI %d-%d\n", idx, mp_ioapics[idx].mp_apicid,
+              mp_ioapics[idx].mp_apicver, mp_ioapics[idx].mp_apicaddr,
+              mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
+
+       nr_ioapics++;
+}
+
+static void assign_to_mp_irq(struct mp_config_intsrc *m,
+                                   struct mp_config_intsrc *mp_irq)
+{
+       memcpy(mp_irq, m, sizeof(struct mp_config_intsrc));
+}
+
+static int mp_irq_cmp(struct mp_config_intsrc *mp_irq,
+                               struct mp_config_intsrc *m)
+{
+       return memcmp(mp_irq, m, sizeof(struct mp_config_intsrc));
+}
+
+static void save_mp_irq(struct mp_config_intsrc *m)
+{
+       int i;
+
+       for (i = 0; i < mp_irq_entries; i++) {
+               if (!mp_irq_cmp(&mp_irqs[i], m))
+                       return;
+       }
+
+       assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
+       if (++mp_irq_entries == MAX_IRQ_SOURCES)
+               panic("Max # of irq sources exceeded!!\n");
+}
+
+void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
+{
+       int ioapic;
+       int pin;
+       struct mp_config_intsrc mp_irq;
+
+       /*
+        * Convert 'gsi' to 'ioapic.pin'.
+        */
+       ioapic = mp_find_ioapic(gsi);
+       if (ioapic < 0)
+               return;
+       pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
+
+       /*
+        * TBD: This check is for faulty timer entries, where the override
+        *      erroneously sets the trigger to level, resulting in a HUGE
+        *      increase of timer interrupts!
+        */
+       if ((bus_irq == 0) && (trigger == 3))
+               trigger = 1;
+
+       mp_irq.mp_type = MP_INTSRC;
+       mp_irq.mp_irqtype = mp_INT;
+       mp_irq.mp_irqflag = (trigger << 2) | polarity;
+       mp_irq.mp_srcbus = MP_ISA_BUS;
+       mp_irq.mp_srcbusirq = bus_irq;  /* IRQ */
+       mp_irq.mp_dstapic = mp_ioapics[ioapic].mp_apicid; /* APIC ID */
+       mp_irq.mp_dstirq = pin; /* INTIN# */
+
+       save_mp_irq(&mp_irq);
+}
+
+void __init mp_config_acpi_legacy_irqs(void)
+{
+       int i;
+       int ioapic;
+       unsigned int dstapic;
+       struct mp_config_intsrc mp_irq;
+
+#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
+       /*
+        * Fabricate the legacy ISA bus (bus #31).
+        */
+       mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
+#endif
+       set_bit(MP_ISA_BUS, mp_bus_not_pci);
+       Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
+
+#ifdef CONFIG_X86_ES7000
+       /*
+        * Older generations of ES7000 have no legacy identity mappings
+        */
+       if (es7000_plat == 1)
+               return;
+#endif
+
+       /*
+        * Locate the IOAPIC that manages the ISA IRQs (0-15).
+        */
+       ioapic = mp_find_ioapic(0);
+       if (ioapic < 0)
+               return;
+       dstapic = mp_ioapics[ioapic].mp_apicid;
+
+       /*
+        * Use the default configuration for the IRQs 0-15.  Unless
+        * overridden by (MADT) interrupt source override entries.
+        */
+       for (i = 0; i < 16; i++) {
+               int idx;
+
+               for (idx = 0; idx < mp_irq_entries; idx++) {
+                       struct mp_config_intsrc *irq = mp_irqs + idx;
+
+                       /* Do we already have a mapping for this ISA IRQ? */
+                       if (irq->mp_srcbus == MP_ISA_BUS
+                           && irq->mp_srcbusirq == i)
+                               break;
+
+                       /* Do we already have a mapping for this IOAPIC pin */
+                       if (irq->mp_dstapic == dstapic &&
+                           irq->mp_dstirq == i)
+                               break;
+               }
+
+               if (idx != mp_irq_entries) {
+                       printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
+                       continue;       /* IRQ already used */
+               }
+
+               mp_irq.mp_type = MP_INTSRC;
+               mp_irq.mp_irqflag = 0;  /* Conforming */
+               mp_irq.mp_srcbus = MP_ISA_BUS;
+               mp_irq.mp_dstapic = dstapic;
+               mp_irq.mp_irqtype = mp_INT;
+               mp_irq.mp_srcbusirq = i; /* Identity mapped */
+               mp_irq.mp_dstirq = i;
+
+               save_mp_irq(&mp_irq);
+       }
+}
+
+int mp_register_gsi(u32 gsi, int triggering, int polarity)
+{
+       int ioapic;
+       int ioapic_pin;
+#ifdef CONFIG_X86_32
+#define MAX_GSI_NUM    4096
+#define IRQ_COMPRESSION_START  64
+
+       static int pci_irq = IRQ_COMPRESSION_START;
+       /*
+        * Mapping between Global System Interrupts, which
+        * represent all possible interrupts, and IRQs
+        * assigned to actual devices.
+        */
+       static int gsi_to_irq[MAX_GSI_NUM];
+#else
+
+       if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
+               return gsi;
+#endif
+
+       /* Don't set up the ACPI SCI because it's already set up */
+       if (acpi_gbl_FADT.sci_interrupt == gsi)
+               return gsi;
+
+       ioapic = mp_find_ioapic(gsi);
+       if (ioapic < 0) {
+               printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
+               return gsi;
+       }
+
+       ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
+
+#ifdef CONFIG_X86_32
+       if (ioapic_renumber_irq)
+               gsi = ioapic_renumber_irq(ioapic, gsi);
+#endif
+
+       /*
+        * Avoid pin reprogramming.  PRTs typically include entries
+        * with redundant pin->gsi mappings (but unique PCI devices);
+        * we only program the IOAPIC on the first.
+        */
+       if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
+               printk(KERN_ERR "Invalid reference to IOAPIC pin "
+                      "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
+                      ioapic_pin);
+               return gsi;
+       }
+       if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
+               Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
+                       mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
+#ifdef CONFIG_X86_32
+               return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
+#else
+               return gsi;
+#endif
+       }
+
+       set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
+#ifdef CONFIG_X86_32
+       /*
+        * For GSI >= 64, use IRQ compression
+        */
+       if ((gsi >= IRQ_COMPRESSION_START)
+           && (triggering == ACPI_LEVEL_SENSITIVE)) {
+               /*
+                * For PCI devices assign IRQs in order, avoiding gaps
+                * due to unused I/O APIC pins.
+                */
+               int irq = gsi;
+               if (gsi < MAX_GSI_NUM) {
+                       /*
+                        * Retain the VIA chipset work-around (gsi > 15), but
+                        * avoid a problem where the 8254 timer (IRQ0) is setup
+                        * via an override (so it's not on pin 0 of the ioapic),
+                        * and at the same time, the pin 0 interrupt is a PCI
+                        * type.  The gsi > 15 test could cause these two pins
+                        * to be shared as IRQ0, and they are not shareable.
+                        * So test for this condition, and if necessary, avoid
+                        * the pin collision.
+                        */
+                       gsi = pci_irq++;
+                       /*
+                        * Don't assign IRQ used by ACPI SCI
+                        */
+                       if (gsi == acpi_gbl_FADT.sci_interrupt)
+                               gsi = pci_irq++;
+                       gsi_to_irq[irq] = gsi;
+               } else {
+                       printk(KERN_ERR "GSI %u is too high\n", gsi);
+                       return gsi;
+               }
+       }
+#endif
+       io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
+                               triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
+                               polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
+       return gsi;
+}
+
+int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
+                       u32 gsi, int triggering, int polarity)
+{
+#ifdef CONFIG_X86_MPPARSE
+       struct mp_config_intsrc mp_irq;
+       int ioapic;
+
+       if (!acpi_ioapic)
+               return 0;
+
+       /* print the entry should happen on mptable identically */
+       mp_irq.mp_type = MP_INTSRC;
+       mp_irq.mp_irqtype = mp_INT;
+       mp_irq.mp_irqflag = (triggering == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
+                               (polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
+       mp_irq.mp_srcbus = number;
+       mp_irq.mp_srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
+       ioapic = mp_find_ioapic(gsi);
+       mp_irq.mp_dstapic = mp_ioapic_routing[ioapic].apic_id;
+       mp_irq.mp_dstirq = gsi - mp_ioapic_routing[ioapic].gsi_base;
+
+       save_mp_irq(&mp_irq);
+#endif
+       return 0;
+}
+
 /*
  * Parse IOAPIC related entries in MADT
  * returns 0 on success, < 0 on error
@@ -1009,8 +1353,6 @@ static void __init acpi_process_madt(void)
        return;
 }
 
-#ifdef __i386__
-
 static int __init disable_acpi_irq(const struct dmi_system_id *d)
 {
        if (!acpi_force) {
@@ -1060,6 +1402,16 @@ static int __init force_acpi_ht(const struct dmi_system_id *d)
        return 0;
 }
 
+/*
+ * Force ignoring BIOS IRQ0 pin2 override
+ */
+static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
+{
+       pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n", d->ident);
+       acpi_skip_timer_override = 1;
+       return 0;
+}
+
 /*
  * If your system is blacklisted here, but you find that acpi=force
  * works for you, please contact acpi-devel@sourceforge.net
@@ -1227,11 +1579,35 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
                     DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
                     },
         },
+       /*
+        * HP laptops which use a DSDT reporting as HP/SB400/10000,
+        * which includes some code which overrides all temperature
+        * trip points to 16C if the INTIN2 input of the I/O APIC
+        * is enabled.  This input is incorrectly designated the
+        * ISA IRQ 0 via an interrupt source override even though
+        * it is wired to the output of the master 8259A and INTIN0
+        * is not connected at all.  Force ignoring BIOS IRQ0 pin2
+        * override in that cases.
+        */
+       {
+        .callback = dmi_ignore_irq0_timer_override,
+        .ident = "HP NX6125 laptop",
+        .matches = {
+                    DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+                    DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
+                    },
+        },
+       {
+        .callback = dmi_ignore_irq0_timer_override,
+        .ident = "HP NX6325 laptop",
+        .matches = {
+                    DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
+                    DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
+                    },
+        },
        {}
 };
 
-#endif                         /* __i386__ */
-
 /*
  * acpi_boot_table_init() and acpi_boot_init()
  *  called from setup_arch(), always.
@@ -1259,9 +1635,7 @@ int __init acpi_boot_table_init(void)
 {
        int error;
 
-#ifdef __i386__
        dmi_check_system(acpi_dmi_table);
-#endif
 
        /*
         * If acpi_disabled, bail out
@@ -1386,6 +1760,20 @@ static int __init parse_pci(char *arg)
 }
 early_param("pci", parse_pci);
 
+int __init acpi_mps_check(void)
+{
+#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
+/* mptable code is not built-in*/
+       if (acpi_disabled || acpi_noirq) {
+               printk(KERN_WARNING "MPS support code is not built-in.\n"
+                      "Using acpi=off or acpi=noirq or pci=noacpi "
+                      "may have problem\n");
+               return 1;
+       }
+#endif
+       return 0;
+}
+
 #ifdef CONFIG_X86_IO_APIC
 static int __init parse_acpi_skip_timer_override(char *arg)
 {
index 36af01f..e6a4b56 100644 (file)
@@ -86,7 +86,9 @@ int acpi_save_state_mem(void)
        saved_magic = 0x12345678;
 #else /* CONFIG_64BIT */
        header->trampoline_segment = setup_trampoline() >> 4;
-       init_rsp = (unsigned long)temp_stack + 4096;
+#ifdef CONFIG_SMP
+       stack_start.sp = temp_stack + 4096;
+#endif
        initial_code = (unsigned long)wakeup_long64;
        saved_magic = 0x123456789abcdef0;
 #endif /* CONFIG_64BIT */
index 65c7857..2763cb3 100644 (file)
@@ -1,6 +1,6 @@
 #include <linux/module.h>
 #include <linux/sched.h>
-#include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/kprobes.h>
 #include <linux/mm.h>
@@ -143,7 +143,7 @@ static const unsigned char *const p6_nops[ASM_NOP_MAX+1] = {
 #ifdef CONFIG_X86_64
 
 extern char __vsyscall_0;
-static inline const unsigned char*const * find_nop_table(void)
+const unsigned char *const *find_nop_table(void)
 {
        return boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
               boot_cpu_data.x86 < 6 ? k8_nops : p6_nops;
@@ -162,7 +162,7 @@ static const struct nop {
        { -1, NULL }
 };
 
-static const unsigned char*const * find_nop_table(void)
+const unsigned char *const *find_nop_table(void)
 {
        const unsigned char *const *noptable = intel_nops;
        int i;
@@ -279,7 +279,7 @@ struct smp_alt_module {
        struct list_head next;
 };
 static LIST_HEAD(smp_alt_modules);
-static DEFINE_SPINLOCK(smp_alt);
+static DEFINE_MUTEX(smp_alt);
 static int smp_mode = 1;       /* protected by smp_alt */
 
 void alternatives_smp_module_add(struct module *mod, char *name,
@@ -312,12 +312,12 @@ void alternatives_smp_module_add(struct module *mod, char *name,
                __func__, smp->locks, smp->locks_end,
                smp->text, smp->text_end, smp->name);
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
        list_add_tail(&smp->next, &smp_alt_modules);
        if (boot_cpu_has(X86_FEATURE_UP))
                alternatives_smp_unlock(smp->locks, smp->locks_end,
                                        smp->text, smp->text_end);
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 void alternatives_smp_module_del(struct module *mod)
@@ -327,17 +327,17 @@ void alternatives_smp_module_del(struct module *mod)
        if (smp_alt_once || noreplace_smp)
                return;
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
        list_for_each_entry(item, &smp_alt_modules, next) {
                if (mod != item->mod)
                        continue;
                list_del(&item->next);
-               spin_unlock(&smp_alt);
+               mutex_unlock(&smp_alt);
                DPRINTK("%s: %s\n", __func__, item->name);
                kfree(item);
                return;
        }
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 void alternatives_smp_switch(int smp)
@@ -359,7 +359,7 @@ void alternatives_smp_switch(int smp)
                return;
        BUG_ON(!smp && (num_online_cpus() > 1));
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
 
        /*
         * Avoid unnecessary switches because it forces JIT based VMs to
@@ -383,7 +383,7 @@ void alternatives_smp_switch(int smp)
                                                mod->text, mod->text_end);
        }
        smp_mode = smp;
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 #endif
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
new file mode 100644 (file)
index 0000000..f2766d8
--- /dev/null
@@ -0,0 +1,962 @@
+/*
+ * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
+ * Author: Joerg Roedel <joerg.roedel@amd.com>
+ *         Leo Duran <leo.duran@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/pci.h>
+#include <linux/gfp.h>
+#include <linux/bitops.h>
+#include <linux/scatterlist.h>
+#include <linux/iommu-helper.h>
+#include <asm/proto.h>
+#include <asm/gart.h>
+#include <asm/amd_iommu_types.h>
+#include <asm/amd_iommu.h>
+
+#define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28))
+
+#define to_pages(addr, size) \
+        (round_up(((addr) & ~PAGE_MASK) + (size), PAGE_SIZE) >> PAGE_SHIFT)
+
+static DEFINE_RWLOCK(amd_iommu_devtable_lock);
+
+struct command {
+       u32 data[4];
+};
+
+static int dma_ops_unity_map(struct dma_ops_domain *dma_dom,
+                            struct unity_map_entry *e);
+
+static int iommu_has_npcache(struct amd_iommu *iommu)
+{
+       return iommu->cap & IOMMU_CAP_NPCACHE;
+}
+
+static int __iommu_queue_command(struct amd_iommu *iommu, struct command *cmd)
+{
+       u32 tail, head;
+       u8 *target;
+
+       tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
+       target = (iommu->cmd_buf + tail);
+       memcpy_toio(target, cmd, sizeof(*cmd));
+       tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size;
+       head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET);
+       if (tail == head)
+               return -ENOMEM;
+       writel(tail, iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
+
+       return 0;
+}
+
+static int iommu_queue_command(struct amd_iommu *iommu, struct command *cmd)
+{
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&iommu->lock, flags);
+       ret = __iommu_queue_command(iommu, cmd);
+       spin_unlock_irqrestore(&iommu->lock, flags);
+
+       return ret;
+}
+
+static int iommu_completion_wait(struct amd_iommu *iommu)
+{
+       int ret;
+       struct command cmd;
+       volatile u64 ready = 0;
+       unsigned long ready_phys = virt_to_phys(&ready);
+
+       memset(&cmd, 0, sizeof(cmd));
+       cmd.data[0] = LOW_U32(ready_phys) | CMD_COMPL_WAIT_STORE_MASK;
+       cmd.data[1] = HIGH_U32(ready_phys);
+       cmd.data[2] = 1; /* value written to 'ready' */
+       CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT);
+
+       iommu->need_sync = 0;
+
+       ret = iommu_queue_command(iommu, &cmd);
+
+       if (ret)
+               return ret;
+
+       while (!ready)
+               cpu_relax();
+
+       return 0;
+}
+
+static int iommu_queue_inv_dev_entry(struct amd_iommu *iommu, u16 devid)
+{
+       struct command cmd;
+
+       BUG_ON(iommu == NULL);
+
+       memset(&cmd, 0, sizeof(cmd));
+       CMD_SET_TYPE(&cmd, CMD_INV_DEV_ENTRY);
+       cmd.data[0] = devid;
+
+       iommu->need_sync = 1;
+
+       return iommu_queue_command(iommu, &cmd);
+}
+
+static int iommu_queue_inv_iommu_pages(struct amd_iommu *iommu,
+               u64 address, u16 domid, int pde, int s)
+{
+       struct command cmd;
+
+       memset(&cmd, 0, sizeof(cmd));
+       address &= PAGE_MASK;
+       CMD_SET_TYPE(&cmd, CMD_INV_IOMMU_PAGES);
+       cmd.data[1] |= domid;
+       cmd.data[2] = LOW_U32(address);
+       cmd.data[3] = HIGH_U32(address);
+       if (s)
+               cmd.data[2] |= CMD_INV_IOMMU_PAGES_SIZE_MASK;
+       if (pde)
+               cmd.data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK;
+
+       iommu->need_sync = 1;
+
+       return iommu_queue_command(iommu, &cmd);
+}
+
+static int iommu_flush_pages(struct amd_iommu *iommu, u16 domid,
+               u64 address, size_t size)
+{
+       int s = 0;
+       unsigned pages = to_pages(address, size);
+
+       address &= PAGE_MASK;
+
+       if (pages > 1) {
+               /*
+                * If we have to flush more than one page, flush all
+                * TLB entries for this domain
+                */
+               address = CMD_INV_IOMMU_ALL_PAGES_ADDRESS;
+               s = 1;
+       }
+
+       iommu_queue_inv_iommu_pages(iommu, address, domid, 0, s);
+
+       return 0;
+}
+
+static int iommu_map(struct protection_domain *dom,
+                    unsigned long bus_addr,
+                    unsigned long phys_addr,
+                    int prot)
+{
+       u64 __pte, *pte, *page;
+
+       bus_addr  = PAGE_ALIGN(bus_addr);
+       phys_addr = PAGE_ALIGN(bus_addr);
+
+       /* only support 512GB address spaces for now */
+       if (bus_addr > IOMMU_MAP_SIZE_L3 || !(prot & IOMMU_PROT_MASK))
+               return -EINVAL;
+
+       pte = &dom->pt_root[IOMMU_PTE_L2_INDEX(bus_addr)];
+
+       if (!IOMMU_PTE_PRESENT(*pte)) {
+               page = (u64 *)get_zeroed_page(GFP_KERNEL);
+               if (!page)
+                       return -ENOMEM;
+               *pte = IOMMU_L2_PDE(virt_to_phys(page));
+       }
+
+       pte = IOMMU_PTE_PAGE(*pte);
+       pte = &pte[IOMMU_PTE_L1_INDEX(bus_addr)];
+
+       if (!IOMMU_PTE_PRESENT(*pte)) {
+               page = (u64 *)get_zeroed_page(GFP_KERNEL);
+               if (!page)
+                       return -ENOMEM;
+               *pte = IOMMU_L1_PDE(virt_to_phys(page));
+       }
+
+       pte = IOMMU_PTE_PAGE(*pte);
+       pte = &pte[IOMMU_PTE_L0_INDEX(bus_addr)];
+
+       if (IOMMU_PTE_PRESENT(*pte))
+               return -EBUSY;
+
+       __pte = phys_addr | IOMMU_PTE_P;
+       if (prot & IOMMU_PROT_IR)
+               __pte |= IOMMU_PTE_IR;
+       if (prot & IOMMU_PROT_IW)
+               __pte |= IOMMU_PTE_IW;
+
+       *pte = __pte;
+
+       return 0;
+}
+
+static int iommu_for_unity_map(struct amd_iommu *iommu,
+                              struct unity_map_entry *entry)
+{
+       u16 bdf, i;
+
+       for (i = entry->devid_start; i <= entry->devid_end; ++i) {
+               bdf = amd_iommu_alias_table[i];
+               if (amd_iommu_rlookup_table[bdf] == iommu)
+                       return 1;
+       }
+
+       return 0;
+}
+
+static int iommu_init_unity_mappings(struct amd_iommu *iommu)
+{
+       struct unity_map_entry *entry;
+       int ret;
+
+       list_for_each_entry(entry, &amd_iommu_unity_map, list) {
+               if (!iommu_for_unity_map(iommu, entry))
+                       continue;
+               ret = dma_ops_unity_map(iommu->default_dom, entry);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int dma_ops_unity_map(struct dma_ops_domain *dma_dom,
+                            struct unity_map_entry *e)
+{
+       u64 addr;
+       int ret;
+
+       for (addr = e->address_start; addr < e->address_end;
+            addr += PAGE_SIZE) {
+               ret = iommu_map(&dma_dom->domain, addr, addr, e->prot);
+               if (ret)
+                       return ret;
+               /*
+                * if unity mapping is in aperture range mark the page
+                * as allocated in the aperture
+                */
+               if (addr < dma_dom->aperture_size)
+                       __set_bit(addr >> PAGE_SHIFT, dma_dom->bitmap);
+       }
+
+       return 0;
+}
+
+static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom,
+                                         u16 devid)
+{
+       struct unity_map_entry *e;
+       int ret;
+
+       list_for_each_entry(e, &amd_iommu_unity_map, list) {
+               if (!(devid >= e->devid_start && devid <= e->devid_end))
+                       continue;
+               ret = dma_ops_unity_map(dma_dom, e);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static unsigned long dma_mask_to_pages(unsigned long mask)
+{
+       return (mask >> PAGE_SHIFT) +
+               (PAGE_ALIGN(mask & ~PAGE_MASK) >> PAGE_SHIFT);
+}
+
+static unsigned long dma_ops_alloc_addresses(struct device *dev,
+                                            struct dma_ops_domain *dom,
+                                            unsigned int pages)
+{
+       unsigned long limit = dma_mask_to_pages(*dev->dma_mask);
+       unsigned long address;
+       unsigned long size = dom->aperture_size >> PAGE_SHIFT;
+       unsigned long boundary_size;
+
+       boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                       PAGE_SIZE) >> PAGE_SHIFT;
+       limit = limit < size ? limit : size;
+
+       if (dom->next_bit >= limit)
+               dom->next_bit = 0;
+
+       address = iommu_area_alloc(dom->bitmap, limit, dom->next_bit, pages,
+                       0 , boundary_size, 0);
+       if (address == -1)
+               address = iommu_area_alloc(dom->bitmap, limit, 0, pages,
+                               0, boundary_size, 0);
+
+       if (likely(address != -1)) {
+               dom->next_bit = address + pages;
+               address <<= PAGE_SHIFT;
+       } else
+               address = bad_dma_address;
+
+       WARN_ON((address + (PAGE_SIZE*pages)) > dom->aperture_size);
+
+       return address;
+}
+
+static void dma_ops_free_addresses(struct dma_ops_domain *dom,
+                                  unsigned long address,
+                                  unsigned int pages)
+{
+       address >>= PAGE_SHIFT;
+       iommu_area_free(dom->bitmap, address, pages);
+}
+
+static u16 domain_id_alloc(void)
+{
+       unsigned long flags;
+       int id;
+
+       write_lock_irqsave(&amd_iommu_devtable_lock, flags);
+       id = find_first_zero_bit(amd_iommu_pd_alloc_bitmap, MAX_DOMAIN_ID);
+       BUG_ON(id == 0);
+       if (id > 0 && id < MAX_DOMAIN_ID)
+               __set_bit(id, amd_iommu_pd_alloc_bitmap);
+       else
+               id = 0;
+       write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
+
+       return id;
+}
+
+static void dma_ops_reserve_addresses(struct dma_ops_domain *dom,
+                                     unsigned long start_page,
+                                     unsigned int pages)
+{
+       unsigned int last_page = dom->aperture_size >> PAGE_SHIFT;
+
+       if (start_page + pages > last_page)
+               pages = last_page - start_page;
+
+       set_bit_string(dom->bitmap, start_page, pages);
+}
+
+static void dma_ops_free_pagetable(struct dma_ops_domain *dma_dom)
+{
+       int i, j;
+       u64 *p1, *p2, *p3;
+
+       p1 = dma_dom->domain.pt_root;
+
+       if (!p1)
+               return;
+
+       for (i = 0; i < 512; ++i) {
+               if (!IOMMU_PTE_PRESENT(p1[i]))
+                       continue;
+
+               p2 = IOMMU_PTE_PAGE(p1[i]);
+               for (j = 0; j < 512; ++i) {
+                       if (!IOMMU_PTE_PRESENT(p2[j]))
+                               continue;
+                       p3 = IOMMU_PTE_PAGE(p2[j]);
+                       free_page((unsigned long)p3);
+               }
+
+               free_page((unsigned long)p2);
+       }
+
+       free_page((unsigned long)p1);
+}
+
+static void dma_ops_domain_free(struct dma_ops_domain *dom)
+{
+       if (!dom)
+               return;
+
+       dma_ops_free_pagetable(dom);
+
+       kfree(dom->pte_pages);
+
+       kfree(dom->bitmap);
+
+       kfree(dom);
+}
+
+static struct dma_ops_domain *dma_ops_domain_alloc(struct amd_iommu *iommu,
+                                                  unsigned order)
+{
+       struct dma_ops_domain *dma_dom;
+       unsigned i, num_pte_pages;
+       u64 *l2_pde;
+       u64 address;
+
+       /*
+        * Currently the DMA aperture must be between 32 MB and 1GB in size
+        */
+       if ((order < 25) || (order > 30))
+               return NULL;
+
+       dma_dom = kzalloc(sizeof(struct dma_ops_domain), GFP_KERNEL);
+       if (!dma_dom)
+               return NULL;
+
+       spin_lock_init(&dma_dom->domain.lock);
+
+       dma_dom->domain.id = domain_id_alloc();
+       if (dma_dom->domain.id == 0)
+               goto free_dma_dom;
+       dma_dom->domain.mode = PAGE_MODE_3_LEVEL;
+       dma_dom->domain.pt_root = (void *)get_zeroed_page(GFP_KERNEL);
+       dma_dom->domain.priv = dma_dom;
+       if (!dma_dom->domain.pt_root)
+               goto free_dma_dom;
+       dma_dom->aperture_size = (1ULL << order);
+       dma_dom->bitmap = kzalloc(dma_dom->aperture_size / (PAGE_SIZE * 8),
+                                 GFP_KERNEL);
+       if (!dma_dom->bitmap)
+               goto free_dma_dom;
+       /*
+        * mark the first page as allocated so we never return 0 as
+        * a valid dma-address. So we can use 0 as error value
+        */
+       dma_dom->bitmap[0] = 1;
+       dma_dom->next_bit = 0;
+
+       if (iommu->exclusion_start &&
+           iommu->exclusion_start < dma_dom->aperture_size) {
+               unsigned long startpage = iommu->exclusion_start >> PAGE_SHIFT;
+               int pages = to_pages(iommu->exclusion_start,
+                               iommu->exclusion_length);
+               dma_ops_reserve_addresses(dma_dom, startpage, pages);
+       }
+
+       num_pte_pages = dma_dom->aperture_size / (PAGE_SIZE * 512);
+       dma_dom->pte_pages = kzalloc(num_pte_pages * sizeof(void *),
+                       GFP_KERNEL);
+       if (!dma_dom->pte_pages)
+               goto free_dma_dom;
+
+       l2_pde = (u64 *)get_zeroed_page(GFP_KERNEL);
+       if (l2_pde == NULL)
+               goto free_dma_dom;
+
+       dma_dom->domain.pt_root[0] = IOMMU_L2_PDE(virt_to_phys(l2_pde));
+
+       for (i = 0; i < num_pte_pages; ++i) {
+               dma_dom->pte_pages[i] = (u64 *)get_zeroed_page(GFP_KERNEL);
+               if (!dma_dom->pte_pages[i])
+                       goto free_dma_dom;
+               address = virt_to_phys(dma_dom->pte_pages[i]);
+               l2_pde[i] = IOMMU_L1_PDE(address);
+       }
+
+       return dma_dom;
+
+free_dma_dom:
+       dma_ops_domain_free(dma_dom);
+
+       return NULL;
+}
+
+static struct protection_domain *domain_for_device(u16 devid)
+{
+       struct protection_domain *dom;
+       unsigned long flags;
+
+       read_lock_irqsave(&amd_iommu_devtable_lock, flags);
+       dom = amd_iommu_pd_table[devid];
+       read_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
+
+       return dom;
+}
+
+static void set_device_domain(struct amd_iommu *iommu,
+                             struct protection_domain *domain,
+                             u16 devid)
+{
+       unsigned long flags;
+
+       u64 pte_root = virt_to_phys(domain->pt_root);
+
+       pte_root |= (domain->mode & 0x07) << 9;
+       pte_root |= IOMMU_PTE_IR | IOMMU_PTE_IW | IOMMU_PTE_P | 2;
+
+       write_lock_irqsave(&amd_iommu_devtable_lock, flags);
+       amd_iommu_dev_table[devid].data[0] = pte_root;
+       amd_iommu_dev_table[devid].data[1] = pte_root >> 32;
+       amd_iommu_dev_table[devid].data[2] = domain->id;
+
+       amd_iommu_pd_table[devid] = domain;
+       write_unlock_irqrestore(&amd_iommu_devtable_lock, flags);
+
+       iommu_queue_inv_dev_entry(iommu, devid);
+
+       iommu->need_sync = 1;
+}
+
+static int get_device_resources(struct device *dev,
+                               struct amd_iommu **iommu,
+                               struct protection_domain **domain,
+                               u16 *bdf)
+{
+       struct dma_ops_domain *dma_dom;
+       struct pci_dev *pcidev;
+       u16 _bdf;
+
+       BUG_ON(!dev || dev->bus != &pci_bus_type || !dev->dma_mask);
+
+       pcidev = to_pci_dev(dev);
+       _bdf = (pcidev->bus->number << 8) | pcidev->devfn;
+
+       if (_bdf >= amd_iommu_last_bdf) {
+               *iommu = NULL;
+               *domain = NULL;
+               *bdf = 0xffff;
+               return 0;
+       }
+
+       *bdf = amd_iommu_alias_table[_bdf];
+
+       *iommu = amd_iommu_rlookup_table[*bdf];
+       if (*iommu == NULL)
+               return 0;
+       dma_dom = (*iommu)->default_dom;
+       *domain = domain_for_device(*bdf);
+       if (*domain == NULL) {
+               *domain = &dma_dom->domain;
+               set_device_domain(*iommu, *domain, *bdf);
+               printk(KERN_INFO "AMD IOMMU: Using protection domain %d for "
+                               "device ", (*domain)->id);
+               print_devid(_bdf, 1);
+       }
+
+       return 1;
+}
+
+static dma_addr_t dma_ops_domain_map(struct amd_iommu *iommu,
+                                    struct dma_ops_domain *dom,
+                                    unsigned long address,
+                                    phys_addr_t paddr,
+                                    int direction)
+{
+       u64 *pte, __pte;
+
+       WARN_ON(address > dom->aperture_size);
+
+       paddr &= PAGE_MASK;
+
+       pte  = dom->pte_pages[IOMMU_PTE_L1_INDEX(address)];
+       pte += IOMMU_PTE_L0_INDEX(address);
+
+       __pte = paddr | IOMMU_PTE_P | IOMMU_PTE_FC;
+
+       if (direction == DMA_TO_DEVICE)
+               __pte |= IOMMU_PTE_IR;
+       else if (direction == DMA_FROM_DEVICE)
+               __pte |= IOMMU_PTE_IW;
+       else if (direction == DMA_BIDIRECTIONAL)
+               __pte |= IOMMU_PTE_IR | IOMMU_PTE_IW;
+
+       WARN_ON(*pte);
+
+       *pte = __pte;
+
+       return (dma_addr_t)address;
+}
+
+static void dma_ops_domain_unmap(struct amd_iommu *iommu,
+                                struct dma_ops_domain *dom,
+                                unsigned long address)
+{
+       u64 *pte;
+
+       if (address >= dom->aperture_size)
+               return;
+
+       WARN_ON(address & 0xfffULL || address > dom->aperture_size);
+
+       pte  = dom->pte_pages[IOMMU_PTE_L1_INDEX(address)];
+       pte += IOMMU_PTE_L0_INDEX(address);
+
+       WARN_ON(!*pte);
+
+       *pte = 0ULL;
+}
+
+static dma_addr_t __map_single(struct device *dev,
+                              struct amd_iommu *iommu,
+                              struct dma_ops_domain *dma_dom,
+                              phys_addr_t paddr,
+                              size_t size,
+                              int dir)
+{
+       dma_addr_t offset = paddr & ~PAGE_MASK;
+       dma_addr_t address, start;
+       unsigned int pages;
+       int i;
+
+       pages = to_pages(paddr, size);
+       paddr &= PAGE_MASK;
+
+       address = dma_ops_alloc_addresses(dev, dma_dom, pages);
+       if (unlikely(address == bad_dma_address))
+               goto out;
+
+       start = address;
+       for (i = 0; i < pages; ++i) {
+               dma_ops_domain_map(iommu, dma_dom, start, paddr, dir);
+               paddr += PAGE_SIZE;
+               start += PAGE_SIZE;
+       }
+       address += offset;
+
+out:
+       return address;
+}
+
+static void __unmap_single(struct amd_iommu *iommu,
+                          struct dma_ops_domain *dma_dom,
+                          dma_addr_t dma_addr,
+                          size_t size,
+                          int dir)
+{
+       dma_addr_t i, start;
+       unsigned int pages;
+
+       if ((dma_addr == 0) || (dma_addr + size > dma_dom->aperture_size))
+               return;
+
+       pages = to_pages(dma_addr, size);
+       dma_addr &= PAGE_MASK;
+       start = dma_addr;
+
+       for (i = 0; i < pages; ++i) {
+               dma_ops_domain_unmap(iommu, dma_dom, start);
+               start += PAGE_SIZE;
+       }
+
+       dma_ops_free_addresses(dma_dom, dma_addr, pages);
+}
+
+static dma_addr_t map_single(struct device *dev, phys_addr_t paddr,
+                            size_t size, int dir)
+{
+       unsigned long flags;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       u16 devid;
+       dma_addr_t addr;
+
+       get_device_resources(dev, &iommu, &domain, &devid);
+
+       if (iommu == NULL || domain == NULL)
+               return (dma_addr_t)paddr;
+
+       spin_lock_irqsave(&domain->lock, flags);
+       addr = __map_single(dev, iommu, domain->priv, paddr, size, dir);
+       if (addr == bad_dma_address)
+               goto out;
+
+       if (iommu_has_npcache(iommu))
+               iommu_flush_pages(iommu, domain->id, addr, size);
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+out:
+       spin_unlock_irqrestore(&domain->lock, flags);
+
+       return addr;
+}
+
+static void unmap_single(struct device *dev, dma_addr_t dma_addr,
+                        size_t size, int dir)
+{
+       unsigned long flags;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       u16 devid;
+
+       if (!get_device_resources(dev, &iommu, &domain, &devid))
+               return;
+
+       spin_lock_irqsave(&domain->lock, flags);
+
+       __unmap_single(iommu, domain->priv, dma_addr, size, dir);
+
+       iommu_flush_pages(iommu, domain->id, dma_addr, size);
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+       spin_unlock_irqrestore(&domain->lock, flags);
+}
+
+static int map_sg_no_iommu(struct device *dev, struct scatterlist *sglist,
+                          int nelems, int dir)
+{
+       struct scatterlist *s;
+       int i;
+
+       for_each_sg(sglist, s, nelems, i) {
+               s->dma_address = (dma_addr_t)sg_phys(s);
+               s->dma_length  = s->length;
+       }
+
+       return nelems;
+}
+
+static int map_sg(struct device *dev, struct scatterlist *sglist,
+                 int nelems, int dir)
+{
+       unsigned long flags;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       u16 devid;
+       int i;
+       struct scatterlist *s;
+       phys_addr_t paddr;
+       int mapped_elems = 0;
+
+       get_device_resources(dev, &iommu, &domain, &devid);
+
+       if (!iommu || !domain)
+               return map_sg_no_iommu(dev, sglist, nelems, dir);
+
+       spin_lock_irqsave(&domain->lock, flags);
+
+       for_each_sg(sglist, s, nelems, i) {
+               paddr = sg_phys(s);
+
+               s->dma_address = __map_single(dev, iommu, domain->priv,
+                                             paddr, s->length, dir);
+
+               if (s->dma_address) {
+                       s->dma_length = s->length;
+                       mapped_elems++;
+               } else
+                       goto unmap;
+               if (iommu_has_npcache(iommu))
+                       iommu_flush_pages(iommu, domain->id, s->dma_address,
+                                         s->dma_length);
+       }
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+out:
+       spin_unlock_irqrestore(&domain->lock, flags);
+
+       return mapped_elems;
+unmap:
+       for_each_sg(sglist, s, mapped_elems, i) {
+               if (s->dma_address)
+                       __unmap_single(iommu, domain->priv, s->dma_address,
+                                      s->dma_length, dir);
+               s->dma_address = s->dma_length = 0;
+       }
+
+       mapped_elems = 0;
+
+       goto out;
+}
+
+static void unmap_sg(struct device *dev, struct scatterlist *sglist,
+                    int nelems, int dir)
+{
+       unsigned long flags;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       struct scatterlist *s;
+       u16 devid;
+       int i;
+
+       if (!get_device_resources(dev, &iommu, &domain, &devid))
+               return;
+
+       spin_lock_irqsave(&domain->lock, flags);
+
+       for_each_sg(sglist, s, nelems, i) {
+               __unmap_single(iommu, domain->priv, s->dma_address,
+                              s->dma_length, dir);
+               iommu_flush_pages(iommu, domain->id, s->dma_address,
+                                 s->dma_length);
+               s->dma_address = s->dma_length = 0;
+       }
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+       spin_unlock_irqrestore(&domain->lock, flags);
+}
+
+static void *alloc_coherent(struct device *dev, size_t size,
+                           dma_addr_t *dma_addr, gfp_t flag)
+{
+       unsigned long flags;
+       void *virt_addr;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       u16 devid;
+       phys_addr_t paddr;
+
+       virt_addr = (void *)__get_free_pages(flag, get_order(size));
+       if (!virt_addr)
+               return 0;
+
+       memset(virt_addr, 0, size);
+       paddr = virt_to_phys(virt_addr);
+
+       get_device_resources(dev, &iommu, &domain, &devid);
+
+       if (!iommu || !domain) {
+               *dma_addr = (dma_addr_t)paddr;
+               return virt_addr;
+       }
+
+       spin_lock_irqsave(&domain->lock, flags);
+
+       *dma_addr = __map_single(dev, iommu, domain->priv, paddr,
+                                size, DMA_BIDIRECTIONAL);
+
+       if (*dma_addr == bad_dma_address) {
+               free_pages((unsigned long)virt_addr, get_order(size));
+               virt_addr = NULL;
+               goto out;
+       }
+
+       if (iommu_has_npcache(iommu))
+               iommu_flush_pages(iommu, domain->id, *dma_addr, size);
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+out:
+       spin_unlock_irqrestore(&domain->lock, flags);
+
+       return virt_addr;
+}
+
+static void free_coherent(struct device *dev, size_t size,
+                         void *virt_addr, dma_addr_t dma_addr)
+{
+       unsigned long flags;
+       struct amd_iommu *iommu;
+       struct protection_domain *domain;
+       u16 devid;
+
+       get_device_resources(dev, &iommu, &domain, &devid);
+
+       if (!iommu || !domain)
+               goto free_mem;
+
+       spin_lock_irqsave(&domain->lock, flags);
+
+       __unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL);
+       iommu_flush_pages(iommu, domain->id, dma_addr, size);
+
+       if (iommu->need_sync)
+               iommu_completion_wait(iommu);
+
+       spin_unlock_irqrestore(&domain->lock, flags);
+
+free_mem:
+       free_pages((unsigned long)virt_addr, get_order(size));
+}
+
+/*
+ * If the driver core informs the DMA layer if a driver grabs a device
+ * we don't need to preallocate the protection domains anymore.
+ * For now we have to.
+ */
+void prealloc_protection_domains(void)
+{
+       struct pci_dev *dev = NULL;
+       struct dma_ops_domain *dma_dom;
+       struct amd_iommu *iommu;
+       int order = amd_iommu_aperture_order;
+       u16 devid;
+
+       while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
+               devid = (dev->bus->number << 8) | dev->devfn;
+               if (devid >= amd_iommu_last_bdf)
+                       continue;
+               devid = amd_iommu_alias_table[devid];
+               if (domain_for_device(devid))
+                       continue;
+               iommu = amd_iommu_rlookup_table[devid];
+               if (!iommu)
+                       continue;
+               dma_dom = dma_ops_domain_alloc(iommu, order);
+               if (!dma_dom)
+                       continue;
+               init_unity_mappings_for_device(dma_dom, devid);
+               set_device_domain(iommu, &dma_dom->domain, devid);
+               printk(KERN_INFO "AMD IOMMU: Allocated domain %d for device ",
+                      dma_dom->domain.id);
+               print_devid(devid, 1);
+       }
+}
+
+static struct dma_mapping_ops amd_iommu_dma_ops = {
+       .alloc_coherent = alloc_coherent,
+       .free_coherent = free_coherent,
+       .map_single = map_single,
+       .unmap_single = unmap_single,
+       .map_sg = map_sg,
+       .unmap_sg = unmap_sg,
+};
+
+int __init amd_iommu_init_dma_ops(void)
+{
+       struct amd_iommu *iommu;
+       int order = amd_iommu_aperture_order;
+       int ret;
+
+       list_for_each_entry(iommu, &amd_iommu_list, list) {
+               iommu->default_dom = dma_ops_domain_alloc(iommu, order);
+               if (iommu->default_dom == NULL)
+                       return -ENOMEM;
+               ret = iommu_init_unity_mappings(iommu);
+               if (ret)
+                       goto free_domains;
+       }
+
+       if (amd_iommu_isolate)
+               prealloc_protection_domains();
+
+       iommu_detected = 1;
+       force_iommu = 1;
+       bad_dma_address = 0;
+#ifdef CONFIG_GART_IOMMU
+       gart_iommu_aperture_disabled = 1;
+       gart_iommu_aperture = 0;
+#endif
+
+       dma_ops = &amd_iommu_dma_ops;
+
+       return 0;
+
+free_domains:
+
+       list_for_each_entry(iommu, &amd_iommu_list, list) {
+               if (iommu->default_dom)
+                       dma_ops_domain_free(iommu->default_dom);
+       }
+
+       return ret;
+}
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c
new file mode 100644 (file)
index 0000000..2a13e43
--- /dev/null
@@ -0,0 +1,875 @@
+/*
+ * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
+ * Author: Joerg Roedel <joerg.roedel@amd.com>
+ *         Leo Duran <leo.duran@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/pci.h>
+#include <linux/acpi.h>
+#include <linux/gfp.h>
+#include <linux/list.h>
+#include <linux/sysdev.h>
+#include <asm/pci-direct.h>
+#include <asm/amd_iommu_types.h>
+#include <asm/amd_iommu.h>
+#include <asm/gart.h>
+
+/*
+ * definitions for the ACPI scanning code
+ */
+#define UPDATE_LAST_BDF(x) do {\
+       if ((x) > amd_iommu_last_bdf) \
+               amd_iommu_last_bdf = (x); \
+       } while (0);
+
+#define DEVID(bus, devfn) (((bus) << 8) | (devfn))
+#define PCI_BUS(x) (((x) >> 8) & 0xff)
+#define IVRS_HEADER_LENGTH 48
+#define TBL_SIZE(x) (1 << (PAGE_SHIFT + get_order(amd_iommu_last_bdf * (x))))
+
+#define ACPI_IVHD_TYPE                  0x10
+#define ACPI_IVMD_TYPE_ALL              0x20
+#define ACPI_IVMD_TYPE                  0x21
+#define ACPI_IVMD_TYPE_RANGE            0x22
+
+#define IVHD_DEV_ALL                    0x01
+#define IVHD_DEV_SELECT                 0x02
+#define IVHD_DEV_SELECT_RANGE_START     0x03
+#define IVHD_DEV_RANGE_END              0x04
+#define IVHD_DEV_ALIAS                  0x42
+#define IVHD_DEV_ALIAS_RANGE            0x43
+#define IVHD_DEV_EXT_SELECT             0x46
+#define IVHD_DEV_EXT_SELECT_RANGE       0x47
+
+#define IVHD_FLAG_HT_TUN_EN             0x00
+#define IVHD_FLAG_PASSPW_EN             0x01
+#define IVHD_FLAG_RESPASSPW_EN          0x02
+#define IVHD_FLAG_ISOC_EN               0x03
+
+#define IVMD_FLAG_EXCL_RANGE            0x08
+#define IVMD_FLAG_UNITY_MAP             0x01
+
+#define ACPI_DEVFLAG_INITPASS           0x01
+#define ACPI_DEVFLAG_EXTINT             0x02
+#define ACPI_DEVFLAG_NMI                0x04
+#define ACPI_DEVFLAG_SYSMGT1            0x10
+#define ACPI_DEVFLAG_SYSMGT2            0x20
+#define ACPI_DEVFLAG_LINT0              0x40
+#define ACPI_DEVFLAG_LINT1              0x80
+#define ACPI_DEVFLAG_ATSDIS             0x10000000
+
+struct ivhd_header {
+       u8 type;
+       u8 flags;
+       u16 length;
+       u16 devid;
+       u16 cap_ptr;
+       u64 mmio_phys;
+       u16 pci_seg;
+       u16 info;
+       u32 reserved;
+} __attribute__((packed));
+
+struct ivhd_entry {
+       u8 type;
+       u16 devid;
+       u8 flags;
+       u32 ext;
+} __attribute__((packed));
+
+struct ivmd_header {
+       u8 type;
+       u8 flags;
+       u16 length;
+       u16 devid;
+       u16 aux;
+       u64 resv;
+       u64 range_start;
+       u64 range_length;
+} __attribute__((packed));
+
+static int __initdata amd_iommu_detected;
+
+u16 amd_iommu_last_bdf;
+struct list_head amd_iommu_unity_map;
+unsigned amd_iommu_aperture_order = 26;
+int amd_iommu_isolate;
+
+struct list_head amd_iommu_list;
+struct dev_table_entry *amd_iommu_dev_table;
+u16 *amd_iommu_alias_table;
+struct amd_iommu **amd_iommu_rlookup_table;
+struct protection_domain **amd_iommu_pd_table;
+unsigned long *amd_iommu_pd_alloc_bitmap;
+
+static u32 dev_table_size;
+static u32 alias_table_size;
+static u32 rlookup_table_size;
+
+static void __init iommu_set_exclusion_range(struct amd_iommu *iommu)
+{
+       u64 start = iommu->exclusion_start & PAGE_MASK;
+       u64 limit = (start + iommu->exclusion_length) & PAGE_MASK;
+       u64 entry;
+
+       if (!iommu->exclusion_start)
+               return;
+
+       entry = start | MMIO_EXCL_ENABLE_MASK;
+       memcpy_toio(iommu->mmio_base + MMIO_EXCL_BASE_OFFSET,
+                       &entry, sizeof(entry));
+
+       entry = limit;
+       memcpy_toio(iommu->mmio_base + MMIO_EXCL_LIMIT_OFFSET,
+                       &entry, sizeof(entry));
+}
+
+static void __init iommu_set_device_table(struct amd_iommu *iommu)
+{
+       u32 entry;
+
+       BUG_ON(iommu->mmio_base == NULL);
+
+       entry = virt_to_phys(amd_iommu_dev_table);
+       entry |= (dev_table_size >> 12) - 1;
+       memcpy_toio(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET,
+                       &entry, sizeof(entry));
+}
+
+static void __init iommu_feature_enable(struct amd_iommu *iommu, u8 bit)
+{
+       u32 ctrl;
+
+       ctrl = readl(iommu->mmio_base + MMIO_CONTROL_OFFSET);
+       ctrl |= (1 << bit);
+       writel(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
+}
+
+static void __init iommu_feature_disable(struct amd_iommu *iommu, u8 bit)
+{
+       u32 ctrl;
+
+       ctrl = (u64)readl(iommu->mmio_base + MMIO_CONTROL_OFFSET);
+       ctrl &= ~(1 << bit);
+       writel(ctrl, iommu->mmio_base + MMIO_CONTROL_OFFSET);
+}
+
+void __init iommu_enable(struct amd_iommu *iommu)
+{
+       printk(KERN_INFO "AMD IOMMU: Enabling IOMMU at ");
+       print_devid(iommu->devid, 0);
+       printk(" cap 0x%hx\n", iommu->cap_ptr);
+
+       iommu_feature_enable(iommu, CONTROL_IOMMU_EN);
+}
+
+static u8 * __init iommu_map_mmio_space(u64 address)
+{
+       u8 *ret;
+
+       if (!request_mem_region(address, MMIO_REGION_LENGTH, "amd_iommu"))
+               return NULL;
+
+       ret = ioremap_nocache(address, MMIO_REGION_LENGTH);
+       if (ret != NULL)
+               return ret;
+
+       release_mem_region(address, MMIO_REGION_LENGTH);
+
+       return NULL;
+}
+
+static void __init iommu_unmap_mmio_space(struct amd_iommu *iommu)
+{
+       if (iommu->mmio_base)
+               iounmap(iommu->mmio_base);
+       release_mem_region(iommu->mmio_phys, MMIO_REGION_LENGTH);
+}
+
+static int __init find_last_devid_on_pci(int bus, int dev, int fn, int cap_ptr)
+{
+       u32 cap;
+
+       cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET);
+       UPDATE_LAST_BDF(DEVID(MMIO_GET_BUS(cap), MMIO_GET_LD(cap)));
+
+       return 0;
+}
+
+static int __init find_last_devid_from_ivhd(struct ivhd_header *h)
+{
+       u8 *p = (void *)h, *end = (void *)h;
+       struct ivhd_entry *dev;
+
+       p += sizeof(*h);
+       end += h->length;
+
+       find_last_devid_on_pci(PCI_BUS(h->devid),
+                       PCI_SLOT(h->devid),
+                       PCI_FUNC(h->devid),
+                       h->cap_ptr);
+
+       while (p < end) {
+               dev = (struct ivhd_entry *)p;
+               switch (dev->type) {
+               case IVHD_DEV_SELECT:
+               case IVHD_DEV_RANGE_END:
+               case IVHD_DEV_ALIAS:
+               case IVHD_DEV_EXT_SELECT:
+                       UPDATE_LAST_BDF(dev->devid);
+                       break;
+               default:
+                       break;
+               }
+               p += 0x04 << (*p >> 6);
+       }
+
+       WARN_ON(p != end);
+
+       return 0;
+}
+
+static int __init find_last_devid_acpi(struct acpi_table_header *table)
+{
+       int i;
+       u8 checksum = 0, *p = (u8 *)table, *end = (u8 *)table;
+       struct ivhd_header *h;
+
+       /*
+        * Validate checksum here so we don't need to do it when
+        * we actually parse the table
+        */
+       for (i = 0; i < table->length; ++i)
+               checksum += p[i];
+       if (checksum != 0)
+               /* ACPI table corrupt */
+               return -ENODEV;
+
+       p += IVRS_HEADER_LENGTH;
+
+       end += table->length;
+       while (p < end) {
+               h = (struct ivhd_header *)p;
+               switch (h->type) {
+               case ACPI_IVHD_TYPE:
+                       find_last_devid_from_ivhd(h);
+                       break;
+               default:
+                       break;
+               }
+               p += h->length;
+       }
+       WARN_ON(p != end);
+
+       return 0;
+}
+
+static u8 * __init alloc_command_buffer(struct amd_iommu *iommu)
+{
+       u8 *cmd_buf = (u8 *)__get_free_pages(GFP_KERNEL,
+                       get_order(CMD_BUFFER_SIZE));
+       u64 entry = 0;
+
+       if (cmd_buf == NULL)
+               return NULL;
+
+       iommu->cmd_buf_size = CMD_BUFFER_SIZE;
+
+       memset(cmd_buf, 0, CMD_BUFFER_SIZE);
+
+       entry = (u64)virt_to_phys(cmd_buf);
+       entry |= MMIO_CMD_SIZE_512;
+       memcpy_toio(iommu->mmio_base + MMIO_CMD_BUF_OFFSET,
+                       &entry, sizeof(entry));
+
+       iommu_feature_enable(iommu, CONTROL_CMDBUF_EN);
+
+       return cmd_buf;
+}
+
+static void __init free_command_buffer(struct amd_iommu *iommu)
+{
+       if (iommu->cmd_buf)
+               free_pages((unsigned long)iommu->cmd_buf,
+                               get_order(CMD_BUFFER_SIZE));
+}
+
+static void set_dev_entry_bit(u16 devid, u8 bit)
+{
+       int i = (bit >> 5) & 0x07;
+       int _bit = bit & 0x1f;
+
+       amd_iommu_dev_table[devid].data[i] |= (1 << _bit);
+}
+
+static void __init set_dev_entry_from_acpi(u16 devid, u32 flags, u32 ext_flags)
+{
+       if (flags & ACPI_DEVFLAG_INITPASS)
+               set_dev_entry_bit(devid, DEV_ENTRY_INIT_PASS);
+       if (flags & ACPI_DEVFLAG_EXTINT)
+               set_dev_entry_bit(devid, DEV_ENTRY_EINT_PASS);
+       if (flags & ACPI_DEVFLAG_NMI)
+               set_dev_entry_bit(devid, DEV_ENTRY_NMI_PASS);
+       if (flags & ACPI_DEVFLAG_SYSMGT1)
+               set_dev_entry_bit(devid, DEV_ENTRY_SYSMGT1);
+       if (flags & ACPI_DEVFLAG_SYSMGT2)
+               set_dev_entry_bit(devid, DEV_ENTRY_SYSMGT2);
+       if (flags & ACPI_DEVFLAG_LINT0)
+               set_dev_entry_bit(devid, DEV_ENTRY_LINT0_PASS);
+       if (flags & ACPI_DEVFLAG_LINT1)
+               set_dev_entry_bit(devid, DEV_ENTRY_LINT1_PASS);
+}
+
+static void __init set_iommu_for_device(struct amd_iommu *iommu, u16 devid)
+{
+       amd_iommu_rlookup_table[devid] = iommu;
+}
+
+static void __init set_device_exclusion_range(u16 devid, struct ivmd_header *m)
+{
+       struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
+
+       if (!(m->flags & IVMD_FLAG_EXCL_RANGE))
+               return;
+
+       if (iommu) {
+               set_dev_entry_bit(m->devid, DEV_ENTRY_EX);
+               iommu->exclusion_start = m->range_start;
+               iommu->exclusion_length = m->range_length;
+       }
+}
+
+static void __init init_iommu_from_pci(struct amd_iommu *iommu)
+{
+       int bus = PCI_BUS(iommu->devid);
+       int dev = PCI_SLOT(iommu->devid);
+       int fn  = PCI_FUNC(iommu->devid);
+       int cap_ptr = iommu->cap_ptr;
+       u32 range;
+
+       iommu->cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_CAP_HDR_OFFSET);
+
+       range = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET);
+       iommu->first_device = DEVID(MMIO_GET_BUS(range), MMIO_GET_FD(range));
+       iommu->last_device = DEVID(MMIO_GET_BUS(range), MMIO_GET_LD(range));
+}
+
+static void __init init_iommu_from_acpi(struct amd_iommu *iommu,
+                                       struct ivhd_header *h)
+{
+       u8 *p = (u8 *)h;
+       u8 *end = p, flags = 0;
+       u16 dev_i, devid = 0, devid_start = 0, devid_to = 0;
+       u32 ext_flags = 0;
+       bool alias = 0;
+       struct ivhd_entry *e;
+
+       /*
+        * First set the recommended feature enable bits from ACPI
+        * into the IOMMU control registers
+        */
+       h->flags & IVHD_FLAG_HT_TUN_EN ?
+               iommu_feature_enable(iommu, CONTROL_HT_TUN_EN) :
+               iommu_feature_disable(iommu, CONTROL_HT_TUN_EN);
+
+       h->flags & IVHD_FLAG_PASSPW_EN ?
+               iommu_feature_enable(iommu, CONTROL_PASSPW_EN) :
+               iommu_feature_disable(iommu, CONTROL_PASSPW_EN);
+
+       h->flags & IVHD_FLAG_RESPASSPW_EN ?
+               iommu_feature_enable(iommu, CONTROL_RESPASSPW_EN) :
+               iommu_feature_disable(iommu, CONTROL_RESPASSPW_EN);
+
+       h->flags & IVHD_FLAG_ISOC_EN ?
+               iommu_feature_enable(iommu, CONTROL_ISOC_EN) :
+               iommu_feature_disable(iommu, CONTROL_ISOC_EN);
+
+       /*
+        * make IOMMU memory accesses cache coherent
+        */
+       iommu_feature_enable(iommu, CONTROL_COHERENT_EN);
+
+       /*
+        * Done. Now parse the device entries
+        */
+       p += sizeof(struct ivhd_header);
+       end += h->length;
+
+       while (p < end) {
+               e = (struct ivhd_entry *)p;
+               switch (e->type) {
+               case IVHD_DEV_ALL:
+                       for (dev_i = iommu->first_device;
+                                       dev_i <= iommu->last_device; ++dev_i)
+                               set_dev_entry_from_acpi(dev_i, e->flags, 0);
+                       break;
+               case IVHD_DEV_SELECT:
+                       devid = e->devid;
+                       set_dev_entry_from_acpi(devid, e->flags, 0);
+                       break;
+               case IVHD_DEV_SELECT_RANGE_START:
+                       devid_start = e->devid;
+                       flags = e->flags;
+                       ext_flags = 0;
+                       alias = 0;
+                       break;
+               case IVHD_DEV_ALIAS:
+                       devid = e->devid;
+                       devid_to = e->ext >> 8;
+                       set_dev_entry_from_acpi(devid, e->flags, 0);
+                       amd_iommu_alias_table[devid] = devid_to;
+                       break;
+               case IVHD_DEV_ALIAS_RANGE:
+                       devid_start = e->devid;
+                       flags = e->flags;
+                       devid_to = e->ext >> 8;
+                       ext_flags = 0;
+                       alias = 1;
+                       break;
+               case IVHD_DEV_EXT_SELECT:
+                       devid = e->devid;
+                       set_dev_entry_from_acpi(devid, e->flags, e->ext);
+                       break;
+               case IVHD_DEV_EXT_SELECT_RANGE:
+                       devid_start = e->devid;
+                       flags = e->flags;
+                       ext_flags = e->ext;
+                       alias = 0;
+                       break;
+               case IVHD_DEV_RANGE_END:
+                       devid = e->devid;
+                       for (dev_i = devid_start; dev_i <= devid; ++dev_i) {
+                               if (alias)
+                                       amd_iommu_alias_table[dev_i] = devid_to;
+                               set_dev_entry_from_acpi(
+                                               amd_iommu_alias_table[dev_i],
+                                               flags, ext_flags);
+                       }
+                       break;
+               default:
+                       break;
+               }
+
+               p += 0x04 << (e->type >> 6);
+       }
+}
+
+static int __init init_iommu_devices(struct amd_iommu *iommu)
+{
+       u16 i;
+
+       for (i = iommu->first_device; i <= iommu->last_device; ++i)
+               set_iommu_for_device(iommu, i);
+
+       return 0;
+}
+
+static void __init free_iommu_one(struct amd_iommu *iommu)
+{
+       free_command_buffer(iommu);
+       iommu_unmap_mmio_space(iommu);
+}
+
+static void __init free_iommu_all(void)
+{
+       struct amd_iommu *iommu, *next;
+
+       list_for_each_entry_safe(iommu, next, &amd_iommu_list, list) {
+               list_del(&iommu->list);
+               free_iommu_one(iommu);
+               kfree(iommu);
+       }
+}
+
+static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
+{
+       spin_lock_init(&iommu->lock);
+       list_add_tail(&iommu->list, &amd_iommu_list);
+
+       /*
+        * Copy data from ACPI table entry to the iommu struct
+        */
+       iommu->devid = h->devid;
+       iommu->cap_ptr = h->cap_ptr;
+       iommu->mmio_phys = h->mmio_phys;
+       iommu->mmio_base = iommu_map_mmio_space(h->mmio_phys);
+       if (!iommu->mmio_base)
+               return -ENOMEM;
+
+       iommu_set_device_table(iommu);
+       iommu->cmd_buf = alloc_command_buffer(iommu);
+       if (!iommu->cmd_buf)
+               return -ENOMEM;
+
+       init_iommu_from_pci(iommu);
+       init_iommu_from_acpi(iommu, h);
+       init_iommu_devices(iommu);
+
+       return 0;
+}
+
+static int __init init_iommu_all(struct acpi_table_header *table)
+{
+       u8 *p = (u8 *)table, *end = (u8 *)table;
+       struct ivhd_header *h;
+       struct amd_iommu *iommu;
+       int ret;
+
+       INIT_LIST_HEAD(&amd_iommu_list);
+
+       end += table->length;
+       p += IVRS_HEADER_LENGTH;
+
+       while (p < end) {
+               h = (struct ivhd_header *)p;
+               switch (*p) {
+               case ACPI_IVHD_TYPE:
+                       iommu = kzalloc(sizeof(struct amd_iommu), GFP_KERNEL);
+                       if (iommu == NULL)
+                               return -ENOMEM;
+                       ret = init_iommu_one(iommu, h);
+                       if (ret)
+                               return ret;
+                       break;
+               default:
+                       break;
+               }
+               p += h->length;
+
+       }
+       WARN_ON(p != end);
+
+       return 0;
+}
+
+static void __init free_unity_maps(void)
+{
+       struct unity_map_entry *entry, *next;
+
+       list_for_each_entry_safe(entry, next, &amd_iommu_unity_map, list) {
+               list_del(&entry->list);
+               kfree(entry);
+       }
+}
+
+static int __init init_exclusion_range(struct ivmd_header *m)
+{
+       int i;
+
+       switch (m->type) {
+       case ACPI_IVMD_TYPE:
+               set_device_exclusion_range(m->devid, m);
+               break;
+       case ACPI_IVMD_TYPE_ALL:
+               for (i = 0; i < amd_iommu_last_bdf; ++i)
+                       set_device_exclusion_range(i, m);
+               break;
+       case ACPI_IVMD_TYPE_RANGE:
+               for (i = m->devid; i <= m->aux; ++i)
+                       set_device_exclusion_range(i, m);
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static int __init init_unity_map_range(struct ivmd_header *m)
+{
+       struct unity_map_entry *e = 0;
+
+       e = kzalloc(sizeof(*e), GFP_KERNEL);
+       if (e == NULL)
+               return -ENOMEM;
+
+       switch (m->type) {
+       default:
+       case ACPI_IVMD_TYPE:
+               e->devid_start = e->devid_end = m->devid;
+               break;
+       case ACPI_IVMD_TYPE_ALL:
+               e->devid_start = 0;
+               e->devid_end = amd_iommu_last_bdf;
+               break;
+       case ACPI_IVMD_TYPE_RANGE:
+               e->devid_start = m->devid;
+               e->devid_end = m->aux;
+               break;
+       }
+       e->address_start = PAGE_ALIGN(m->range_start);
+       e->address_end = e->address_start + PAGE_ALIGN(m->range_length);
+       e->prot = m->flags >> 1;
+
+       list_add_tail(&e->list, &amd_iommu_unity_map);
+
+       return 0;
+}
+
+static int __init init_memory_definitions(struct acpi_table_header *table)
+{
+       u8 *p = (u8 *)table, *end = (u8 *)table;
+       struct ivmd_header *m;
+
+       INIT_LIST_HEAD(&amd_iommu_unity_map);
+
+       end += table->length;
+       p += IVRS_HEADER_LENGTH;
+
+       while (p < end) {
+               m = (struct ivmd_header *)p;
+               if (m->flags & IVMD_FLAG_EXCL_RANGE)
+                       init_exclusion_range(m);
+               else if (m->flags & IVMD_FLAG_UNITY_MAP)
+                       init_unity_map_range(m);
+
+               p += m->length;
+       }
+
+       return 0;
+}
+
+static void __init enable_iommus(void)
+{
+       struct amd_iommu *iommu;
+
+       list_for_each_entry(iommu, &amd_iommu_list, list) {
+               iommu_set_exclusion_range(iommu);
+               iommu_enable(iommu);
+       }
+}
+
+/*
+ * Suspend/Resume support
+ * disable suspend until real resume implemented
+ */
+
+static int amd_iommu_resume(struct sys_device *dev)
+{
+       return 0;
+}
+
+static int amd_iommu_suspend(struct sys_device *dev, pm_message_t state)
+{
+       return -EINVAL;
+}
+
+static struct sysdev_class amd_iommu_sysdev_class = {
+       .name = "amd_iommu",
+       .suspend = amd_iommu_suspend,
+       .resume = amd_iommu_resume,
+};
+
+static struct sys_device device_amd_iommu = {
+       .id = 0,
+       .cls = &amd_iommu_sysdev_class,
+};
+
+int __init amd_iommu_init(void)
+{
+       int i, ret = 0;
+
+
+       if (no_iommu) {
+               printk(KERN_INFO "AMD IOMMU disabled by kernel command line\n");
+               return 0;
+       }
+
+       if (!amd_iommu_detected)
+               return -ENODEV;
+
+       /*
+        * First parse ACPI tables to find the largest Bus/Dev/Func
+        * we need to handle. Upon this information the shared data
+        * structures for the IOMMUs in the system will be allocated
+        */
+       if (acpi_table_parse("IVRS", find_last_devid_acpi) != 0)
+               return -ENODEV;
+
+       dev_table_size     = TBL_SIZE(DEV_TABLE_ENTRY_SIZE);
+       alias_table_size   = TBL_SIZE(ALIAS_TABLE_ENTRY_SIZE);
+       rlookup_table_size = TBL_SIZE(RLOOKUP_TABLE_ENTRY_SIZE);
+
+       ret = -ENOMEM;
+
+       /* Device table - directly used by all IOMMUs */
+       amd_iommu_dev_table = (void *)__get_free_pages(GFP_KERNEL,
+                                     get_order(dev_table_size));
+       if (amd_iommu_dev_table == NULL)
+               goto out;
+
+       /*
+        * Alias table - map PCI Bus/Dev/Func to Bus/Dev/Func the
+        * IOMMU see for that device
+        */
+       amd_iommu_alias_table = (void *)__get_free_pages(GFP_KERNEL,
+                       get_order(alias_table_size));
+       if (amd_iommu_alias_table == NULL)
+               goto free;
+
+       /* IOMMU rlookup table - find the IOMMU for a specific device */
+       amd_iommu_rlookup_table = (void *)__get_free_pages(GFP_KERNEL,
+                       get_order(rlookup_table_size));
+       if (amd_iommu_rlookup_table == NULL)
+               goto free;
+
+       /*
+        * Protection Domain table - maps devices to protection domains
+        * This table has the same size as the rlookup_table
+        */
+       amd_iommu_pd_table = (void *)__get_free_pages(GFP_KERNEL,
+                                    get_order(rlookup_table_size));
+       if (amd_iommu_pd_table == NULL)
+               goto free;
+
+       amd_iommu_pd_alloc_bitmap = (void *)__get_free_pages(GFP_KERNEL,
+                                           get_order(MAX_DOMAIN_ID/8));
+       if (amd_iommu_pd_alloc_bitmap == NULL)
+               goto free;
+
+       /*
+        * memory is allocated now; initialize the device table with all zeroes
+        * and let all alias entries point to itself
+        */
+       memset(amd_iommu_dev_table, 0, dev_table_size);
+       for (i = 0; i < amd_iommu_last_bdf; ++i)
+               amd_iommu_alias_table[i] = i;
+
+       memset(amd_iommu_pd_table, 0, rlookup_table_size);
+       memset(amd_iommu_pd_alloc_bitmap, 0, MAX_DOMAIN_ID / 8);
+
+       /*
+        * never allocate domain 0 because its used as the non-allocated and
+        * error value placeholder
+        */
+       amd_iommu_pd_alloc_bitmap[0] = 1;
+
+       /*
+        * now the data structures are allocated and basically initialized
+        * start the real acpi table scan
+        */
+       ret = -ENODEV;
+       if (acpi_table_parse("IVRS", init_iommu_all) != 0)
+               goto free;
+
+       if (acpi_table_parse("IVRS", init_memory_definitions) != 0)
+               goto free;
+
+       ret = amd_iommu_init_dma_ops();
+       if (ret)
+               goto free;
+
+       ret = sysdev_class_register(&amd_iommu_sysdev_class);
+       if (ret)
+               goto free;
+
+       ret = sysdev_register(&device_amd_iommu);
+       if (ret)
+               goto free;
+
+       enable_iommus();
+
+       printk(KERN_INFO "AMD IOMMU: aperture size is %d MB\n",
+                       (1 << (amd_iommu_aperture_order-20)));
+
+       printk(KERN_INFO "AMD IOMMU: device isolation ");
+       if (amd_iommu_isolate)
+               printk("enabled\n");
+       else
+               printk("disabled\n");
+
+out:
+       return ret;
+
+free:
+       if (amd_iommu_pd_alloc_bitmap)
+               free_pages((unsigned long)amd_iommu_pd_alloc_bitmap, 1);
+
+       if (amd_iommu_pd_table)
+               free_pages((unsigned long)amd_iommu_pd_table,
+                               get_order(rlookup_table_size));
+
+       if (amd_iommu_rlookup_table)
+               free_pages((unsigned long)amd_iommu_rlookup_table,
+                               get_order(rlookup_table_size));
+
+       if (amd_iommu_alias_table)
+               free_pages((unsigned long)amd_iommu_alias_table,
+                               get_order(alias_table_size));
+
+       if (amd_iommu_dev_table)
+               free_pages((unsigned long)amd_iommu_dev_table,
+                               get_order(dev_table_size));
+
+       free_iommu_all();
+
+       free_unity_maps();
+
+       goto out;
+}
+
+static int __init early_amd_iommu_detect(struct acpi_table_header *table)
+{
+       return 0;
+}
+
+void __init amd_iommu_detect(void)
+{
+       if (swiotlb || no_iommu || iommu_detected)
+               return;
+
+       if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) {
+               iommu_detected = 1;
+               amd_iommu_detected = 1;
+#ifdef CONFIG_GART_IOMMU
+               gart_iommu_aperture_disabled = 1;
+               gart_iommu_aperture = 0;
+#endif
+       }
+}
+
+static int __init parse_amd_iommu_options(char *str)
+{
+       for (; *str; ++str) {
+               if (strcmp(str, "isolate") == 0)
+                       amd_iommu_isolate = 1;
+       }
+
+       return 1;
+}
+
+static int __init parse_amd_iommu_size_options(char *str)
+{
+       for (; *str; ++str) {
+               if (strcmp(str, "32M") == 0)
+                       amd_iommu_aperture_order = 25;
+               if (strcmp(str, "64M") == 0)
+                       amd_iommu_aperture_order = 26;
+               if (strcmp(str, "128M") == 0)
+                       amd_iommu_aperture_order = 27;
+               if (strcmp(str, "256M") == 0)
+                       amd_iommu_aperture_order = 28;
+               if (strcmp(str, "512M") == 0)
+                       amd_iommu_aperture_order = 29;
+               if (strcmp(str, "1G") == 0)
+                       amd_iommu_aperture_order = 30;
+       }
+
+       return 1;
+}
+
+__setup("amd_iommu=", parse_amd_iommu_options);
+__setup("amd_iommu_size=", parse_amd_iommu_size_options);
index 479926d..9f90780 100644 (file)
@@ -35,6 +35,18 @@ int fallback_aper_force __initdata;
 
 int fix_aperture __initdata = 1;
 
+struct bus_dev_range {
+       int bus;
+       int dev_base;
+       int dev_limit;
+};
+
+static struct bus_dev_range bus_dev_ranges[] __initdata = {
+       { 0x00, 0x18, 0x20},
+       { 0xff, 0x00, 0x20},
+       { 0xfe, 0x00, 0x20}
+};
+
 static struct resource gart_resource = {
        .name   = "GART",
        .flags  = IORESOURCE_MEM,
@@ -55,8 +67,9 @@ static u32 __init allocate_aperture(void)
        u32 aper_size;
        void *p;
 
-       if (fallback_aper_order > 7)
-               fallback_aper_order = 7;
+       /* aper_size should <= 1G */
+       if (fallback_aper_order > 5)
+               fallback_aper_order = 5;
        aper_size = (32 * 1024 * 1024) << fallback_aper_order;
 
        /*
@@ -65,7 +78,20 @@ static u32 __init allocate_aperture(void)
         * memory. Unfortunately we cannot move it up because that would
         * make the IOMMU useless.
         */
-       p = __alloc_bootmem_nopanic(aper_size, aper_size, 0);
+       /*
+        * using 512M as goal, in case kexec will load kernel_big
+        * that will do the on position decompress, and  could overlap with
+        * that positon with gart that is used.
+        * sequende:
+        * kernel_small
+        * ==> kexec (with kdump trigger path or previous doesn't shutdown gart)
+        * ==> kernel_small(gart area become e820_reserved)
+        * ==> kexec (with kdump trigger path or previous doesn't shutdown gart)
+        * ==> kerne_big (uncompressed size will be big than 64M or 128M)
+        * so don't use 512M below as gart iommu, leave the space for kernel
+        * code for safe
+        */
+       p = __alloc_bootmem_nopanic(aper_size, aper_size, 512ULL<<20);
        if (!p || __pa(p)+aper_size > 0xffffffff) {
                printk(KERN_ERR
                        "Cannot allocate aperture memory hole (%p,%uK)\n",
@@ -83,69 +109,53 @@ static u32 __init allocate_aperture(void)
        return (u32)__pa(p);
 }
 
-static int __init aperture_valid(u64 aper_base, u32 aper_size)
-{
-       if (!aper_base)
-               return 0;
-
-       if (aper_base + aper_size > 0x100000000UL) {
-               printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n");
-               return 0;
-       }
-       if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
-               printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n");
-               return 0;
-       }
-       if (aper_size < 64*1024*1024) {
-               printk(KERN_ERR "Aperture too small (%d MB)\n", aper_size>>20);
-               return 0;
-       }
-
-       return 1;
-}
 
 /* Find a PCI capability */
-static __u32 __init find_cap(int num, int slot, int func, int cap)
+static u32 __init find_cap(int bus, int slot, int func, int cap)
 {
        int bytes;
        u8 pos;
 
-       if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
+       if (!(read_pci_config_16(bus, slot, func, PCI_STATUS) &
                                                PCI_STATUS_CAP_LIST))
                return 0;
 
-       pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST);
+       pos = read_pci_config_byte(bus, slot, func, PCI_CAPABILITY_LIST);
        for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
                u8 id;
 
                pos &= ~3;
-               id = read_pci_config_byte(num, slot, func, pos+PCI_CAP_LIST_ID);
+               id = read_pci_config_byte(bus, slot, func, pos+PCI_CAP_LIST_ID);
                if (id == 0xff)
                        break;
                if (id == cap)
                        return pos;
-               pos = read_pci_config_byte(num, slot, func,
+               pos = read_pci_config_byte(bus, slot, func,
                                                pos+PCI_CAP_LIST_NEXT);
        }
        return 0;
 }
 
 /* Read a standard AGPv3 bridge header */
-static __u32 __init read_agp(int num, int slot, int func, int cap, u32 *order)
+static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order)
 {
        u32 apsize;
        u32 apsizereg;
        int nbits;
        u32 aper_low, aper_hi;
        u64 aper;
+       u32 old_order;
 
-       printk(KERN_INFO "AGP bridge at %02x:%02x:%02x\n", num, slot, func);
-       apsizereg = read_pci_config_16(num, slot, func, cap + 0x14);
+       printk(KERN_INFO "AGP bridge at %02x:%02x:%02x\n", bus, slot, func);
+       apsizereg = read_pci_config_16(bus, slot, func, cap + 0x14);
        if (apsizereg == 0xffffffff) {
                printk(KERN_ERR "APSIZE in AGP bridge unreadable\n");
                return 0;
        }
 
+       /* old_order could be the value from NB gart setting */
+       old_order = *order;
+
        apsize = apsizereg & 0xfff;
        /* Some BIOS use weird encodings not in the AGPv3 table. */
        if (apsize & 0xff)
@@ -155,14 +165,26 @@ static __u32 __init read_agp(int num, int slot, int func, int cap, u32 *order)
        if ((int)*order < 0) /* < 32MB */
                *order = 0;
 
-       aper_low = read_pci_config(num, slot, func, 0x10);
-       aper_hi = read_pci_config(num, slot, func, 0x14);
+       aper_low = read_pci_config(bus, slot, func, 0x10);
+       aper_hi = read_pci_config(bus, slot, func, 0x14);
        aper = (aper_low & ~((1<<22)-1)) | ((u64)aper_hi << 32);
 
+       /*
+        * On some sick chips, APSIZE is 0. It means it wants 4G
+        * so let double check that order, and lets trust AMD NB settings:
+        */
+       printk(KERN_INFO "Aperture from AGP @ %Lx old size %u MB\n",
+                       aper, 32 << old_order);
+       if (aper + (32ULL<<(20 + *order)) > 0x100000000ULL) {
+               printk(KERN_INFO "Aperture size %u MB (APSIZE %x) is not right, using settings from NB\n",
+                               32 << *order, apsizereg);
+               *order = old_order;
+       }
+
        printk(KERN_INFO "Aperture from AGP @ %Lx size %u MB (APSIZE %x)\n",
                        aper, 32 << *order, apsizereg);
 
-       if (!aperture_valid(aper, (32*1024*1024) << *order))
+       if (!aperture_valid(aper, (32*1024*1024) << *order, 32<<20))
                return 0;
        return (u32)aper;
 }
@@ -180,17 +202,17 @@ static __u32 __init read_agp(int num, int slot, int func, int cap, u32 *order)
  * the AGP bridges should be always an own bus on the HT hierarchy,
  * but do it here for future safety.
  */
-static __u32 __init search_agp_bridge(u32 *order, int *valid_agp)
+static u32 __init search_agp_bridge(u32 *order, int *valid_agp)
 {
-       int num, slot, func;
+       int bus, slot, func;
 
        /* Poor man's PCI discovery */
-       for (num = 0; num < 256; num++) {
+       for (bus = 0; bus < 256; bus++) {
                for (slot = 0; slot < 32; slot++) {
                        for (func = 0; func < 8; func++) {
                                u32 class, cap;
                                u8 type;
-                               class = read_pci_config(num, slot, func,
+                               class = read_pci_config(bus, slot, func,
                                                        PCI_CLASS_REVISION);
                                if (class == 0xffffffff)
                                        break;
@@ -199,17 +221,17 @@ static __u32 __init search_agp_bridge(u32 *order, int *valid_agp)
                                case PCI_CLASS_BRIDGE_HOST:
                                case PCI_CLASS_BRIDGE_OTHER: /* needed? */
                                        /* AGP bridge? */
-                                       cap = find_cap(num, slot, func,
+                                       cap = find_cap(bus, slot, func,
                                                        PCI_CAP_ID_AGP);
                                        if (!cap)
                                                break;
                                        *valid_agp = 1;
-                                       return read_agp(num, slot, func, cap,
+                                       return read_agp(bus, slot, func, cap,
                                                        order);
                                }
 
                                /* No multi-function device? */
-                               type = read_pci_config_byte(num, slot, func,
+                               type = read_pci_config_byte(bus, slot, func,
                                                               PCI_HEADER_TYPE);
                                if (!(type & 0x80))
                                        break;
@@ -249,36 +271,50 @@ void __init early_gart_iommu_check(void)
         * or BIOS forget to put that in reserved.
         * try to update e820 to make that region as reserved.
         */
-       int fix, num;
+       int i, fix, slot;
        u32 ctl;
        u32 aper_size = 0, aper_order = 0, last_aper_order = 0;
        u64 aper_base = 0, last_aper_base = 0;
-       int aper_enabled = 0, last_aper_enabled = 0;
+       int aper_enabled = 0, last_aper_enabled = 0, last_valid = 0;
 
        if (!early_pci_allowed())
                return;
 
+       /* This is mostly duplicate of iommu_hole_init */
        fix = 0;
-       for (num = 24; num < 32; num++) {
-               if (!early_is_k8_nb(read_pci_config(0, num, 3, 0x00)))
-                       continue;
-
-               ctl = read_pci_config(0, num, 3, 0x90);
-               aper_enabled = ctl & 1;
-               aper_order = (ctl >> 1) & 7;
-               aper_size = (32 * 1024 * 1024) << aper_order;
-               aper_base = read_pci_config(0, num, 3, 0x94) & 0x7fff;
-               aper_base <<= 25;
-
-               if ((last_aper_order && aper_order != last_aper_order) ||
-                   (last_aper_base && aper_base != last_aper_base) ||
-                   (last_aper_enabled && aper_enabled != last_aper_enabled)) {
-                       fix = 1;
-                       break;
+       for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
+               int bus;
+               int dev_base, dev_limit;
+
+               bus = bus_dev_ranges[i].bus;
+               dev_base = bus_dev_ranges[i].dev_base;
+               dev_limit = bus_dev_ranges[i].dev_limit;
+
+               for (slot = dev_base; slot < dev_limit; slot++) {
+                       if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
+                               continue;
+
+                       ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
+                       aper_enabled = ctl & AMD64_GARTEN;
+                       aper_order = (ctl >> 1) & 7;
+                       aper_size = (32 * 1024 * 1024) << aper_order;
+                       aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff;
+                       aper_base <<= 25;
+
+                       if (last_valid) {
+                               if ((aper_order != last_aper_order) ||
+                                   (aper_base != last_aper_base) ||
+                                   (aper_enabled != last_aper_enabled)) {
+                                       fix = 1;
+                                       break;
+                               }
+                       }
+
+                       last_aper_order = aper_order;
+                       last_aper_base = aper_base;
+                       last_aper_enabled = aper_enabled;
+                       last_valid = 1;
                }
-               last_aper_order = aper_order;
-               last_aper_base = aper_base;
-               last_aper_enabled = aper_enabled;
        }
 
        if (!fix && !aper_enabled)
@@ -290,32 +326,46 @@ void __init early_gart_iommu_check(void)
        if (gart_fix_e820 && !fix && aper_enabled) {
                if (e820_any_mapped(aper_base, aper_base + aper_size,
                                    E820_RAM)) {
-                       /* reserved it, so we can resuse it in second kernel */
+                       /* reserve it, so we can reuse it in second kernel */
                        printk(KERN_INFO "update e820 for GART\n");
-                       add_memory_region(aper_base, aper_size, E820_RESERVED);
+                       e820_add_region(aper_base, aper_size, E820_RESERVED);
                        update_e820();
                }
-               return;
        }
 
+       if (!fix)
+               return;
+
        /* different nodes have different setting, disable them all at first*/
-       for (num = 24; num < 32; num++) {
-               if (!early_is_k8_nb(read_pci_config(0, num, 3, 0x00)))
-                       continue;
+       for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
+               int bus;
+               int dev_base, dev_limit;
+
+               bus = bus_dev_ranges[i].bus;
+               dev_base = bus_dev_ranges[i].dev_base;
+               dev_limit = bus_dev_ranges[i].dev_limit;
+
+               for (slot = dev_base; slot < dev_limit; slot++) {
+                       if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
+                               continue;
 
-               ctl = read_pci_config(0, num, 3, 0x90);
-               ctl &= ~1;
-               write_pci_config(0, num, 3, 0x90, ctl);
+                       ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL);
+                       ctl &= ~AMD64_GARTEN;
+                       write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl);
+               }
        }
 
 }
 
+static int __initdata printed_gart_size_msg;
+
 void __init gart_iommu_hole_init(void)
 {
+       u32 agp_aper_base = 0, agp_aper_order = 0;
        u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0;
        u64 aper_base, last_aper_base = 0;
-       int fix, num, valid_agp = 0;
-       int node;
+       int fix, slot, valid_agp = 0;
+       int i, node;
 
        if (gart_iommu_aperture_disabled || !fix_aperture ||
            !early_pci_allowed())
@@ -323,38 +373,65 @@ void __init gart_iommu_hole_init(void)
 
        printk(KERN_INFO  "Checking aperture...\n");
 
+       if (!fallback_aper_force)
+               agp_aper_base = search_agp_bridge(&agp_aper_order, &valid_agp);
+
        fix = 0;
        node = 0;
-       for (num = 24; num < 32; num++) {
-               if (!early_is_k8_nb(read_pci_config(0, num, 3, 0x00)))
-                       continue;
-
-               iommu_detected = 1;
-               gart_iommu_aperture = 1;
-
-               aper_order = (read_pci_config(0, num, 3, 0x90) >> 1) & 7;
-               aper_size = (32 * 1024 * 1024) << aper_order;
-               aper_base = read_pci_config(0, num, 3, 0x94) & 0x7fff;
-               aper_base <<= 25;
-
-               printk(KERN_INFO "Node %d: aperture @ %Lx size %u MB\n",
-                               node, aper_base, aper_size >> 20);
-               node++;
-
-               if (!aperture_valid(aper_base, aper_size)) {
-                       fix = 1;
-                       break;
-               }
+       for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
+               int bus;
+               int dev_base, dev_limit;
+
+               bus = bus_dev_ranges[i].bus;
+               dev_base = bus_dev_ranges[i].dev_base;
+               dev_limit = bus_dev_ranges[i].dev_limit;
+
+               for (slot = dev_base; slot < dev_limit; slot++) {
+                       if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
+                               continue;
+
+                       iommu_detected = 1;
+                       gart_iommu_aperture = 1;
+
+                       aper_order = (read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL) >> 1) & 7;
+                       aper_size = (32 * 1024 * 1024) << aper_order;
+                       aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff;
+                       aper_base <<= 25;
+
+                       printk(KERN_INFO "Node %d: aperture @ %Lx size %u MB\n",
+                                       node, aper_base, aper_size >> 20);
+                       node++;
+
+                       if (!aperture_valid(aper_base, aper_size, 64<<20)) {
+                               if (valid_agp && agp_aper_base &&
+                                   agp_aper_base == aper_base &&
+                                   agp_aper_order == aper_order) {
+                                       /* the same between two setting from NB and agp */
+                                       if (!no_iommu &&
+                                           max_pfn > MAX_DMA32_PFN &&
+                                           !printed_gart_size_msg) {
+                                               printk(KERN_ERR "you are using iommu with agp, but GART size is less than 64M\n");
+                                               printk(KERN_ERR "please increase GART size in your BIOS setup\n");
+                                               printk(KERN_ERR "if BIOS doesn't have that option, contact your HW vendor!\n");
+                                               printed_gart_size_msg = 1;
+                                       }
+                               } else {
+                                       fix = 1;
+                                       goto out;
+                               }
+                       }
 
-               if ((last_aper_order && aper_order != last_aper_order) ||
-                   (last_aper_base && aper_base != last_aper_base)) {
-                       fix = 1;
-                       break;
+                       if ((last_aper_order && aper_order != last_aper_order) ||
+                           (last_aper_base && aper_base != last_aper_base)) {
+                               fix = 1;
+                               goto out;
+                       }
+                       last_aper_order = aper_order;
+                       last_aper_base = aper_base;
                }
-               last_aper_order = aper_order;
-               last_aper_base = aper_base;
        }
 
+out:
        if (!fix && !fallback_aper_force) {
                if (last_aper_base) {
                        unsigned long n = (32 * 1024 * 1024) << last_aper_order;
@@ -364,14 +441,16 @@ void __init gart_iommu_hole_init(void)
                return;
        }
 
-       if (!fallback_aper_force)
-               aper_alloc = search_agp_bridge(&aper_order, &valid_agp);
+       if (!fallback_aper_force) {
+               aper_alloc = agp_aper_base;
+               aper_order = agp_aper_order;
+       }
 
        if (aper_alloc) {
                /* Got the aperture from the AGP bridge */
        } else if (swiotlb && !valid_agp) {
                /* Do nothing */
-       } else if ((!no_iommu && end_pfn > MAX_DMA32_PFN) ||
+       } else if ((!no_iommu && max_pfn > MAX_DMA32_PFN) ||
                   force_iommu ||
                   valid_agp ||
                   fallback_aper_force) {
@@ -401,16 +480,24 @@ void __init gart_iommu_hole_init(void)
        }
 
        /* Fix up the north bridges */
-       for (num = 24; num < 32; num++) {
-               if (!early_is_k8_nb(read_pci_config(0, num, 3, 0x00)))
-                       continue;
-
-               /*
-                * Don't enable translation yet. That is done later.
-                * Assume this BIOS didn't initialise the GART so
-                * just overwrite all previous bits
-                */
-               write_pci_config(0, num, 3, 0x90, aper_order<<1);
-               write_pci_config(0, num, 3, 0x94, aper_alloc>>25);
+       for (i = 0; i < ARRAY_SIZE(bus_dev_ranges); i++) {
+               int bus;
+               int dev_base, dev_limit;
+
+               bus = bus_dev_ranges[i].bus;
+               dev_base = bus_dev_ranges[i].dev_base;
+               dev_limit = bus_dev_ranges[i].dev_limit;
+               for (slot = dev_base; slot < dev_limit; slot++) {
+                       if (!early_is_k8_nb(read_pci_config(bus, slot, 3, 0x00)))
+                               continue;
+
+                       /* Don't enable translation yet. That is done later.
+                          Assume this BIOS didn't initialise the GART so
+                          just overwrite all previous bits */
+                       write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, aper_order << 1);
+                       write_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE, aper_alloc >> 25);
+               }
        }
+
+       set_up_gart_resume(aper_order, aper_alloc);
 }
index 4b99b1b..3e58b67 100644 (file)
 
 unsigned long mp_lapic_addr;
 
-DEFINE_PER_CPU(u16, x86_bios_cpu_apicid) = BAD_APICID;
-EXPORT_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
-
 /*
  * Knob to control our willingness to enable the local APIC.
  *
- * -1=force-disable, +1=force-enable
+ * +1=force-enable
  */
-static int enable_local_apic __initdata;
+static int force_enable_local_apic;
+int disable_apic;
 
 /* Local APIC timer verification ok */
 static int local_apic_timer_verify_ok;
-/* Disable local APIC timer from the kernel commandline or via dmi quirk
-   or using CPU MSR check */
-int local_apic_timer_disabled;
+/* Disable local APIC timer from the kernel commandline or via dmi quirk */
+static int local_apic_timer_disabled;
 /* Local APIC timer works in C2 */
 int local_apic_timer_c2_ok;
 EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
 
+int first_system_vector = 0xfe;
+
+char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE};
+
 /*
  * Debug level, exported for io_apic.c
  */
 int apic_verbosity;
 
+int pic_mode;
+
+/* Have we found an MP table */
+int smp_found_config;
+
+static struct resource lapic_resource = {
+       .name = "Local APIC",
+       .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
+};
+
 static unsigned int calibration_result;
 
 static int lapic_next_event(unsigned long delta,
@@ -545,7 +556,7 @@ void __init setup_boot_APIC_clock(void)
                        lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
                else
                        printk(KERN_WARNING "APIC timer registered as dummy,"
-                              " due to nmi_watchdog=1!\n");
+                               " due to nmi_watchdog=%d!\n", nmi_watchdog);
        }
 
        /* Setup the lapic or request the broadcast */
@@ -963,7 +974,7 @@ void __cpuinit setup_local_APIC(void)
         * Double-check whether this APIC is really registered.
         */
        if (!apic_id_registered())
-               BUG();
+               WARN_ON_ONCE(1);
 
        /*
         * Intel recommends to set DFR, LDR and TPR before enabling
@@ -1094,7 +1105,7 @@ static int __init detect_init_APIC(void)
        u32 h, l, features;
 
        /* Disabled by kernel option? */
-       if (enable_local_apic < 0)
+       if (disable_apic)
                return -1;
 
        switch (boot_cpu_data.x86_vendor) {
@@ -1117,7 +1128,7 @@ static int __init detect_init_APIC(void)
                 * Over-ride BIOS and try to enable the local APIC only if
                 * "lapic" specified.
                 */
-               if (enable_local_apic <= 0) {
+               if (!force_enable_local_apic) {
                        printk(KERN_INFO "Local APIC disabled by BIOS -- "
                               "you can enable it with \"lapic\"\n");
                        return -1;
@@ -1154,9 +1165,6 @@ static int __init detect_init_APIC(void)
        if (l & MSR_IA32_APICBASE_ENABLE)
                mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
 
-       if (nmi_watchdog != NMI_NONE && nmi_watchdog != NMI_DISABLED)
-               nmi_watchdog = NMI_LOCAL_APIC;
-
        printk(KERN_INFO "Found and enabled local APIC!\n");
 
        apic_pm_activate();
@@ -1195,36 +1203,6 @@ void __init init_apic_mappings(void)
        if (boot_cpu_physical_apicid == -1U)
                boot_cpu_physical_apicid = GET_APIC_ID(read_apic_id());
 
-#ifdef CONFIG_X86_IO_APIC
-       {
-               unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
-               int i;
-
-               for (i = 0; i < nr_ioapics; i++) {
-                       if (smp_found_config) {
-                               ioapic_phys = mp_ioapics[i].mpc_apicaddr;
-                               if (!ioapic_phys) {
-                                       printk(KERN_ERR
-                                              "WARNING: bogus zero IO-APIC "
-                                              "address found in MPTABLE, "
-                                              "disabling IO/APIC support!\n");
-                                       smp_found_config = 0;
-                                       skip_ioapic_setup = 1;
-                                       goto fake_ioapic_page;
-                               }
-                       } else {
-fake_ioapic_page:
-                               ioapic_phys = (unsigned long)
-                                             alloc_bootmem_pages(PAGE_SIZE);
-                               ioapic_phys = __pa(ioapic_phys);
-                       }
-                       set_fixmap_nocache(idx, ioapic_phys);
-                       printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
-                              __fix_to_virt(idx), ioapic_phys);
-                       idx++;
-               }
-       }
-#endif
 }
 
 /*
@@ -1236,7 +1214,7 @@ int apic_version[MAX_APICS];
 
 int __init APIC_init_uniprocessor(void)
 {
-       if (enable_local_apic < 0)
+       if (disable_apic)
                clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
 
        if (!smp_found_config && !cpu_has_apic)
@@ -1265,10 +1243,14 @@ int __init APIC_init_uniprocessor(void)
 #ifdef CONFIG_CRASH_DUMP
        boot_cpu_physical_apicid = GET_APIC_ID(read_apic_id());
 #endif
-       phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
+       physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
 
        setup_local_APIC();
 
+#ifdef CONFIG_X86_IO_APIC
+       if (!smp_found_config || skip_ioapic_setup || !nr_ioapics)
+#endif
+               localise_nmi_watchdog();
        end_local_APIC_setup();
 #ifdef CONFIG_X86_IO_APIC
        if (smp_found_config)
@@ -1351,13 +1333,13 @@ void __init smp_intr_init(void)
         * The reschedule interrupt is a CPU-to-CPU reschedule-helper
         * IPI, driven by wakeup.
         */
-       set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
+       alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
 
        /* IPI for invalidation */
-       set_intr_gate(INVALIDATE_TLB_VECTOR, invalidate_interrupt);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR, invalidate_interrupt);
 
        /* IPI for generic function call */
-       set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
+       alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
 }
 #endif
 
@@ -1370,15 +1352,15 @@ void __init apic_intr_init(void)
        smp_intr_init();
 #endif
        /* self generated IPI for local APIC timer */
-       set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
+       alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
 
        /* IPI vectors for APIC spurious and error interrupts */
-       set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
-       set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
+       alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
+       alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
 
        /* thermal monitor LVT interrupt */
 #ifdef CONFIG_X86_MCE_P4THERMAL
-       set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
+       alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
 #endif
 }
 
@@ -1513,6 +1495,9 @@ void __cpuinit generic_processor_info(int apicid, int version)
                 */
                cpu = 0;
 
+       if (apicid > max_physical_apicid)
+               max_physical_apicid = apicid;
+
        /*
         * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
         * but we need to work other dependencies like SMP_SUSPEND etc
@@ -1520,7 +1505,7 @@ void __cpuinit generic_processor_info(int apicid, int version)
         * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
         *       - Ashok Raj <ashok.raj@intel.com>
         */
-       if (num_processors > 8) {
+       if (max_physical_apicid >= 8) {
                switch (boot_cpu_data.x86_vendor) {
                case X86_VENDOR_INTEL:
                        if (!APIC_XAPIC(version)) {
@@ -1534,9 +1519,9 @@ void __cpuinit generic_processor_info(int apicid, int version)
        }
 #ifdef CONFIG_SMP
        /* are we being called early in kernel startup? */
-       if (x86_cpu_to_apicid_early_ptr) {
-               u16 *cpu_to_apicid = x86_cpu_to_apicid_early_ptr;
-               u16 *bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
+       if (early_per_cpu_ptr(x86_cpu_to_apicid)) {
+               u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
+               u16 *bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
 
                cpu_to_apicid[cpu] = apicid;
                bios_cpu_apicid[cpu] = apicid;
@@ -1703,14 +1688,14 @@ static void apic_pm_activate(void) { }
  */
 static int __init parse_lapic(char *arg)
 {
-       enable_local_apic = 1;
+       force_enable_local_apic = 1;
        return 0;
 }
 early_param("lapic", parse_lapic);
 
 static int __init parse_nolapic(char *arg)
 {
-       enable_local_apic = -1;
+       disable_apic = 1;
        clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
        return 0;
 }
@@ -1740,3 +1725,21 @@ static int __init apic_set_verbosity(char *str)
 }
 __setup("apic=", apic_set_verbosity);
 
+static int __init lapic_insert_resource(void)
+{
+       if (!apic_phys)
+               return -1;
+
+       /* Put local APIC into the resource map. */
+       lapic_resource.start = apic_phys;
+       lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
+       insert_resource(&iomem_resource, &lapic_resource);
+
+       return 0;
+}
+
+/*
+ * need call insert after e820_reserve_resources()
+ * that is using request_resource
+ */
+late_initcall(lapic_insert_resource);
index 0633cfd..1e3d32e 100644 (file)
@@ -43,7 +43,7 @@
 #include <mach_ipi.h>
 #include <mach_apic.h>
 
-int disable_apic_timer __cpuinitdata;
+static int disable_apic_timer __cpuinitdata;
 static int apic_calibrate_pmtmr __initdata;
 int disable_apic;
 
@@ -56,6 +56,9 @@ EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
  */
 int apic_verbosity;
 
+/* Have we found an MP table */
+int smp_found_config;
+
 static struct resource lapic_resource = {
        .name = "Local APIC",
        .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
@@ -87,9 +90,6 @@ static unsigned long apic_phys;
 
 unsigned long mp_lapic_addr;
 
-DEFINE_PER_CPU(u16, x86_bios_cpu_apicid) = BAD_APICID;
-EXPORT_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
-
 unsigned int __cpuinitdata maxcpus = NR_CPUS;
 /*
  * Get the LAPIC version
@@ -417,37 +417,13 @@ void __init setup_boot_APIC_clock(void)
                lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
        else
                printk(KERN_WARNING "APIC timer registered as dummy,"
-                      " due to nmi_watchdog=1!\n");
+                       " due to nmi_watchdog=%d!\n", nmi_watchdog);
 
        setup_APIC_timer();
 }
 
-/*
- * AMD C1E enabled CPUs have a real nasty problem: Some BIOSes set the
- * C1E flag only in the secondary CPU, so when we detect the wreckage
- * we already have enabled the boot CPU local apic timer. Check, if
- * disable_apic_timer is set and the DUMMY flag is cleared. If yes,
- * set the DUMMY flag again and force the broadcast mode in the
- * clockevents layer.
- */
-static void __cpuinit check_boot_apic_timer_broadcast(void)
-{
-       if (!disable_apic_timer ||
-           (lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
-               return;
-
-       printk(KERN_INFO "AMD C1E detected late. Force timer broadcast.\n");
-       lapic_clockevent.features |= CLOCK_EVT_FEAT_DUMMY;
-
-       local_irq_enable();
-       clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
-                          &boot_cpu_physical_apicid);
-       local_irq_disable();
-}
-
 void __cpuinit setup_secondary_APIC_clock(void)
 {
-       check_boot_apic_timer_broadcast();
        setup_APIC_timer();
 }
 
@@ -850,7 +826,6 @@ static void __cpuinit lapic_setup_esr(void)
 void __cpuinit end_local_APIC_setup(void)
 {
        lapic_setup_esr();
-       nmi_watchdog_default();
        setup_apic_nmi_watchdog(NULL);
        apic_pm_activate();
 }
@@ -875,7 +850,7 @@ static int __init detect_init_APIC(void)
 
 void __init early_init_lapic_mapping(void)
 {
-       unsigned long apic_phys;
+       unsigned long phys_addr;
 
        /*
         * If no local APIC can be found then go out
@@ -884,11 +859,11 @@ void __init early_init_lapic_mapping(void)
        if (!smp_found_config)
                return;
 
-       apic_phys = mp_lapic_addr;
+       phys_addr = mp_lapic_addr;
 
-       set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
+       set_fixmap_nocache(FIX_APIC_BASE, phys_addr);
        apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
-                                APIC_BASE, apic_phys);
+                   APIC_BASE, phys_addr);
 
        /*
         * Fetch the APIC ID of the BSP in case we have a
@@ -942,7 +917,9 @@ int __init APIC_init_uniprocessor(void)
 
        verify_local_APIC();
 
-       phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
+       connect_bsp_APIC();
+
+       physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
        apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid));
 
        setup_local_APIC();
@@ -954,6 +931,8 @@ int __init APIC_init_uniprocessor(void)
        if (!skip_ioapic_setup && nr_ioapics)
                enable_IO_APIC();
 
+       if (!smp_found_config || skip_ioapic_setup || !nr_ioapics)
+               localise_nmi_watchdog();
        end_local_APIC_setup();
 
        if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
@@ -1021,6 +1000,14 @@ asmlinkage void smp_error_interrupt(void)
        irq_exit();
 }
 
+/**
+ *  * connect_bsp_APIC - attach the APIC to the interrupt system
+ *   */
+void __init connect_bsp_APIC(void)
+{
+       enable_apic_mode();
+}
+
 void disconnect_bsp_APIC(int virt_wire_setup)
 {
        /* Go back to Virtual Wire compatibility mode */
@@ -1090,10 +1077,13 @@ void __cpuinit generic_processor_info(int apicid, int version)
                 */
                cpu = 0;
        }
+       if (apicid > max_physical_apicid)
+               max_physical_apicid = apicid;
+
        /* are we being called early in kernel startup? */
-       if (x86_cpu_to_apicid_early_ptr) {
-               u16 *cpu_to_apicid = x86_cpu_to_apicid_early_ptr;
-               u16 *bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
+       if (early_per_cpu_ptr(x86_cpu_to_apicid)) {
+               u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
+               u16 *bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
 
                cpu_to_apicid[cpu] = apicid;
                bios_cpu_apicid[cpu] = apicid;
@@ -1269,7 +1259,7 @@ __cpuinit int apic_is_clustered_box(void)
        if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && !is_vsmp_box())
                return 0;
 
-       bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
+       bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
        bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
 
        for (i = 0; i < NR_CPUS; i++) {
index bf9290e..75cb5da 100644 (file)
 #include <linux/module.h>
 
 #include <linux/poll.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <linux/timer.h>
 #include <linux/suspend.h>
 #include <linux/kthread.h>
 #include <linux/jiffies.h>
+#include <linux/smp_lock.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -1149,7 +1151,7 @@ static void queue_event(apm_event_t event, struct apm_user *sender)
                                as->event_tail = 0;
                }
                as->events[as->event_head] = event;
-               if ((!as->suser) || (!as->writer))
+               if (!as->suser || !as->writer)
                        continue;
                switch (event) {
                case APM_SYS_SUSPEND:
@@ -1396,7 +1398,7 @@ static void apm_mainloop(void)
 
 static int check_apm_user(struct apm_user *as, const char *func)
 {
-       if ((as == NULL) || (as->magic != APM_BIOS_MAGIC)) {
+       if (as == NULL || as->magic != APM_BIOS_MAGIC) {
                printk(KERN_ERR "apm: %s passed bad filp\n", func);
                return 1;
        }
@@ -1459,18 +1461,19 @@ static unsigned int do_poll(struct file *fp, poll_table *wait)
        return 0;
 }
 
-static int do_ioctl(struct inode *inode, struct file *filp,
-                   u_int cmd, u_long arg)
+static long do_ioctl(struct file *filp, u_int cmd, u_long arg)
 {
        struct apm_user *as;
+       int ret;
 
        as = filp->private_data;
        if (check_apm_user(as, "ioctl"))
                return -EIO;
-       if ((!as->suser) || (!as->writer))
+       if (!as->suser || !as->writer)
                return -EPERM;
        switch (cmd) {
        case APM_IOC_STANDBY:
+               lock_kernel();
                if (as->standbys_read > 0) {
                        as->standbys_read--;
                        as->standbys_pending--;
@@ -1479,8 +1482,10 @@ static int do_ioctl(struct inode *inode, struct file *filp,
                        queue_event(APM_USER_STANDBY, as);
                if (standbys_pending <= 0)
                        standby();
+               unlock_kernel();
                break;
        case APM_IOC_SUSPEND:
+               lock_kernel();
                if (as->suspends_read > 0) {
                        as->suspends_read--;
                        as->suspends_pending--;
@@ -1488,16 +1493,17 @@ static int do_ioctl(struct inode *inode, struct file *filp,
                } else
                        queue_event(APM_USER_SUSPEND, as);
                if (suspends_pending <= 0) {
-                       return suspend(1);
+                       ret = suspend(1);
                } else {
                        as->suspend_wait = 1;
                        wait_event_interruptible(apm_suspend_waitqueue,
                                        as->suspend_wait == 0);
-                       return as->suspend_result;
+                       ret = as->suspend_result;
                }
-               break;
+               unlock_kernel();
+               return ret;
        default:
-               return -EINVAL;
+               return -ENOTTY;
        }
        return 0;
 }
@@ -1544,10 +1550,12 @@ static int do_open(struct inode *inode, struct file *filp)
 {
        struct apm_user *as;
 
+       lock_kernel();
        as = kmalloc(sizeof(*as), GFP_KERNEL);
        if (as == NULL) {
                printk(KERN_ERR "apm: cannot allocate struct of size %d bytes\n",
                       sizeof(*as));
+                      unlock_kernel();
                return -ENOMEM;
        }
        as->magic = APM_BIOS_MAGIC;
@@ -1569,6 +1577,7 @@ static int do_open(struct inode *inode, struct file *filp)
        user_list = as;
        spin_unlock(&user_list_lock);
        filp->private_data = as;
+       unlock_kernel();
        return 0;
 }
 
@@ -1860,7 +1869,7 @@ static const struct file_operations apm_bios_fops = {
        .owner          = THIS_MODULE,
        .read           = do_read,
        .poll           = do_poll,
-       .ioctl          = do_ioctl,
+       .unlocked_ioctl = do_ioctl,
        .open           = do_open,
        .release        = do_release,
 };
index 9258808..6649d09 100644 (file)
@@ -111,7 +111,7 @@ void foo(void)
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
-       OFFSET(PV_CPU_irq_enable_syscall_ret, pv_cpu_ops, irq_enable_syscall_ret);
+       OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
        OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
 #endif
 
index f126c05..bacf5de 100644 (file)
@@ -34,7 +34,7 @@ int main(void)
        ENTRY(pid);
        BLANK();
 #undef ENTRY
-#define ENTRY(entry) DEFINE(threadinfo_ ## entry, offsetof(struct thread_info, entry))
+#define ENTRY(entry) DEFINE(TI_ ## entry, offsetof(struct thread_info, entry))
        ENTRY(flags);
        ENTRY(addr_limit);
        ENTRY(preempt_count);
@@ -61,8 +61,11 @@ int main(void)
        OFFSET(PARAVIRT_PATCH_pv_irq_ops, paravirt_patch_template, pv_irq_ops);
        OFFSET(PV_IRQ_irq_disable, pv_irq_ops, irq_disable);
        OFFSET(PV_IRQ_irq_enable, pv_irq_ops, irq_enable);
+       OFFSET(PV_IRQ_adjust_exception_frame, pv_irq_ops, adjust_exception_frame);
        OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
-       OFFSET(PV_CPU_irq_enable_syscall_ret, pv_cpu_ops, irq_enable_syscall_ret);
+       OFFSET(PV_CPU_usergs_sysret32, pv_cpu_ops, usergs_sysret32);
+       OFFSET(PV_CPU_usergs_sysret64, pv_cpu_ops, usergs_sysret64);
+       OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
        OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
        OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
 #endif
diff --git a/arch/x86/kernel/bugs_64.c b/arch/x86/kernel/bugs_64.c
deleted file mode 100644 (file)
index 9a3ed06..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Copyright (C) 1994  Linus Torvalds
- *  Copyright (C) 2000  SuSE
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <asm/alternative.h>
-#include <asm/bugs.h>
-#include <asm/processor.h>
-#include <asm/mtrr.h>
-#include <asm/cacheflush.h>
-
-void __init check_bugs(void)
-{
-       identify_boot_cpu();
-#if !defined(CONFIG_SMP)
-       printk("CPU: ");
-       print_cpu_info(&boot_cpu_data);
-#endif
-       alternative_instructions();
-
-       /*
-        * Make sure the first 2MB area is not mapped by huge pages
-        * There are typically fixed size MTRRs in there and overlapping
-        * MTRRs into large pages causes slow downs.
-        *
-        * Right now we don't do that with gbpages because there seems
-        * very little benefit for that case.
-        */
-       if (!direct_gbpages)
-               set_memory_4k((unsigned long)__va(0), 1);
-}
index a0c6f81..ee76eaa 100644 (file)
@@ -6,11 +6,15 @@ obj-y                 := intel_cacheinfo.o addon_cpuid_features.o
 obj-y                  += proc.o feature_names.o
 
 obj-$(CONFIG_X86_32)   += common.o bugs.o
+obj-$(CONFIG_X86_64)   += common_64.o bugs_64.o
 obj-$(CONFIG_X86_32)   += amd.o
+obj-$(CONFIG_X86_64)   += amd_64.o
 obj-$(CONFIG_X86_32)   += cyrix.o
 obj-$(CONFIG_X86_32)   += centaur.o
+obj-$(CONFIG_X86_64)   += centaur_64.o
 obj-$(CONFIG_X86_32)   += transmeta.o
 obj-$(CONFIG_X86_32)   += intel.o
+obj-$(CONFIG_X86_64)   += intel_64.o
 obj-$(CONFIG_X86_32)   += umc.o
 
 obj-$(CONFIG_X86_MCE)  += mcheck/
index c2e1ce3..84a8220 100644 (file)
@@ -1,9 +1,7 @@
-
 /*
  *     Routines to indentify additional cpu features that are scattered in
  *     cpuid space.
  */
-
 #include <linux/cpu.h>
 
 #include <asm/pat.h>
@@ -53,19 +51,20 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_PAT
 void __cpuinit validate_pat_support(struct cpuinfo_x86 *c)
 {
+       if (!cpu_has_pat)
+               pat_disable("PAT not supported by CPU.");
+
        switch (c->x86_vendor) {
-       case X86_VENDOR_AMD:
-               if (c->x86 >= 0xf && c->x86 <= 0x11)
-                       return;
-               break;
        case X86_VENDOR_INTEL:
                if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
                        return;
                break;
+       case X86_VENDOR_AMD:
+       case X86_VENDOR_CENTAUR:
+       case X86_VENDOR_TRANSMETA:
+               return;
        }
 
-       pat_disable(cpu_has_pat ?
-                   "PAT disabled. Not yet verified on this CPU type." :
-                   "PAT not supported by CPU.");
+       pat_disable("PAT disabled. Not yet verified on this CPU type.");
 }
 #endif
index 2458668..81a07ca 100644 (file)
 extern void vide(void);
 __asm__(".align 4\nvide: ret");
 
-#ifdef CONFIG_X86_LOCAL_APIC
-#define ENABLE_C1E_MASK         0x18000000
-#define CPUID_PROCESSOR_SIGNATURE       1
-#define CPUID_XFAM              0x0ff00000
-#define CPUID_XFAM_K8           0x00000000
-#define CPUID_XFAM_10H          0x00100000
-#define CPUID_XFAM_11H          0x00200000
-#define CPUID_XMOD              0x000f0000
-#define CPUID_XMOD_REV_F        0x00040000
-
-/* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
-static __cpuinit int amd_apic_timer_broken(void)
-{
-       u32 lo, hi;
-       u32 eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
-       switch (eax & CPUID_XFAM) {
-       case CPUID_XFAM_K8:
-               if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
-                       break;
-       case CPUID_XFAM_10H:
-       case CPUID_XFAM_11H:
-               rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
-               if (lo & ENABLE_C1E_MASK) {
-                       if (smp_processor_id() != boot_cpu_physical_apicid)
-                               printk(KERN_INFO "AMD C1E detected late. "
-                                      "        Force timer broadcast.\n");
-                       return 1;
-               }
-               break;
-       default:
-               /* err on the side of caution */
-               return 1;
-       }
-       return 0;
-}
-#endif
-
 int force_mwait __cpuinitdata;
 
 static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
@@ -297,11 +260,6 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c)
                        num_cache_leaves = 3;
        }
 
-#ifdef CONFIG_X86_LOCAL_APIC
-       if (amd_apic_timer_broken())
-               local_apic_timer_disabled = 1;
-#endif
-
        /* K6s reports MCEs but don't actually have all the MSRs */
        if (c->x86 < 6)
                clear_cpu_cap(c, X86_FEATURE_MCE);
diff --git a/arch/x86/kernel/cpu/amd_64.c b/arch/x86/kernel/cpu/amd_64.c
new file mode 100644 (file)
index 0000000..7c36fb8
--- /dev/null
@@ -0,0 +1,222 @@
+#include <linux/init.h>
+#include <linux/mm.h>
+
+#include <asm/numa_64.h>
+#include <asm/mmconfig.h>
+#include <asm/cacheflush.h>
+
+#include <mach_apic.h>
+
+#include "cpu.h"
+
+int force_mwait __cpuinitdata;
+
+#ifdef CONFIG_NUMA
+static int __cpuinit nearby_node(int apicid)
+{
+       int i, node;
+
+       for (i = apicid - 1; i >= 0; i--) {
+               node = apicid_to_node[i];
+               if (node != NUMA_NO_NODE && node_online(node))
+                       return node;
+       }
+       for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
+               node = apicid_to_node[i];
+               if (node != NUMA_NO_NODE && node_online(node))
+                       return node;
+       }
+       return first_node(node_online_map); /* Shouldn't happen */
+}
+#endif
+
+/*
+ * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
+ * Assumes number of cores is a power of two.
+ */
+static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
+{
+#ifdef CONFIG_SMP
+       unsigned bits;
+#ifdef CONFIG_NUMA
+       int cpu = smp_processor_id();
+       int node = 0;
+       unsigned apicid = hard_smp_processor_id();
+#endif
+       bits = c->x86_coreid_bits;
+
+       /* Low order bits define the core id (index of core in socket) */
+       c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
+       /* Convert the initial APIC ID into the socket ID */
+       c->phys_proc_id = c->initial_apicid >> bits;
+
+#ifdef CONFIG_NUMA
+       node = c->phys_proc_id;
+       if (apicid_to_node[apicid] != NUMA_NO_NODE)
+               node = apicid_to_node[apicid];
+       if (!node_online(node)) {
+               /* Two possibilities here:
+                  - The CPU is missing memory and no node was created.
+                  In that case try picking one from a nearby CPU
+                  - The APIC IDs differ from the HyperTransport node IDs
+                  which the K8 northbridge parsing fills in.
+                  Assume they are all increased by a constant offset,
+                  but in the same order as the HT nodeids.
+                  If that doesn't result in a usable node fall back to the
+                  path for the previous case.  */
+
+               int ht_nodeid = c->initial_apicid;
+
+               if (ht_nodeid >= 0 &&
+                   apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
+                       node = apicid_to_node[ht_nodeid];
+               /* Pick a nearby node */
+               if (!node_online(node))
+                       node = nearby_node(apicid);
+       }
+       numa_set_node(cpu, node);
+
+       printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
+#endif
+#endif
+}
+
+static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
+{
+#ifdef CONFIG_SMP
+       unsigned bits, ecx;
+
+       /* Multi core CPU? */
+       if (c->extended_cpuid_level < 0x80000008)
+               return;
+
+       ecx = cpuid_ecx(0x80000008);
+
+       c->x86_max_cores = (ecx & 0xff) + 1;
+
+       /* CPU telling us the core id bits shift? */
+       bits = (ecx >> 12) & 0xF;
+
+       /* Otherwise recompute */
+       if (bits == 0) {
+               while ((1 << bits) < c->x86_max_cores)
+                       bits++;
+       }
+
+       c->x86_coreid_bits = bits;
+
+#endif
+}
+
+static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
+{
+       early_init_amd_mc(c);
+
+       /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
+       if (c->x86_power & (1<<8))
+               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+}
+
+static void __cpuinit init_amd(struct cpuinfo_x86 *c)
+{
+       unsigned level;
+
+#ifdef CONFIG_SMP
+       unsigned long value;
+
+       /*
+        * Disable TLB flush filter by setting HWCR.FFDIS on K8
+        * bit 6 of msr C001_0015
+        *
+        * Errata 63 for SH-B3 steppings
+        * Errata 122 for all steppings (F+ have it disabled by default)
+        */
+       if (c->x86 == 0xf) {
+               rdmsrl(MSR_K8_HWCR, value);
+               value |= 1 << 6;
+               wrmsrl(MSR_K8_HWCR, value);
+       }
+#endif
+
+       /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
+          3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
+       clear_cpu_cap(c, 0*32+31);
+
+       /* On C+ stepping K8 rep microcode works well for copy/memset */
+       if (c->x86 == 0xf) {
+               level = cpuid_eax(1);
+               if((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
+                       set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+       }
+       if (c->x86 == 0x10 || c->x86 == 0x11)
+               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+
+       /* Enable workaround for FXSAVE leak */
+       if (c->x86 >= 6)
+               set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
+
+       level = get_model_name(c);
+       if (!level) {
+               switch (c->x86) {
+               case 0xf:
+                       /* Should distinguish Models here, but this is only
+                          a fallback anyways. */
+                       strcpy(c->x86_model_id, "Hammer");
+                       break;
+               }
+       }
+       display_cacheinfo(c);
+
+       /* Multi core CPU? */
+       if (c->extended_cpuid_level >= 0x80000008)
+               amd_detect_cmp(c);
+
+       if (c->extended_cpuid_level >= 0x80000006 &&
+               (cpuid_edx(0x80000006) & 0xf000))
+               num_cache_leaves = 4;
+       else
+               num_cache_leaves = 3;
+
+       if (c->x86 >= 0xf && c->x86 <= 0x11)
+               set_cpu_cap(c, X86_FEATURE_K8);
+
+       /* MFENCE stops RDTSC speculation */
+       set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
+
+       if (c->x86 == 0x10) {
+               /* do this for boot cpu */
+               if (c == &boot_cpu_data)
+                       check_enable_amd_mmconf_dmi();
+
+               fam10h_check_enable_mmcfg();
+       }
+
+       if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
+               unsigned long long tseg;
+
+               /*
+                * Split up direct mapping around the TSEG SMM area.
+                * Don't do it for gbpages because there seems very little
+                * benefit in doing so.
+                */
+               if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg)) {
+                   printk(KERN_DEBUG "tseg: %010llx\n", tseg);
+                   if ((tseg>>PMD_SHIFT) <
+                               (max_low_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) ||
+                       ((tseg>>PMD_SHIFT) <
+                               (max_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) &&
+                        (tseg>>PMD_SHIFT) >= (1ULL<<(32 - PMD_SHIFT))))
+                       set_memory_4k((unsigned long)__va(tseg), 1);
+               }
+       }
+}
+
+static struct cpu_dev amd_cpu_dev __cpuinitdata = {
+       .c_vendor       = "AMD",
+       .c_ident        = { "AuthenticAMD" },
+       .c_early_init   = early_init_amd,
+       .c_init         = init_amd,
+};
+
+cpu_vendor_dev_register(X86_VENDOR_AMD, &amd_cpu_dev);
+
index 170d2f5..1b1c56b 100644 (file)
@@ -59,8 +59,12 @@ static void __init check_fpu(void)
                return;
        }
 
-/* trap_init() enabled FXSR and company _before_ testing for FP problems here. */
-       /* Test for the divl bug.. */
+       /*
+        * trap_init() enabled FXSR and company _before_ testing for FP
+        * problems here.
+        *
+        * Test for the divl bug..
+        */
        __asm__("fninit\n\t"
                "fldl %1\n\t"
                "fdivl %2\n\t"
@@ -108,10 +112,15 @@ static void __init check_popad(void)
          "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
          : "=&a" (res)
          : "d" (inp)
-         : "ecx", "edi" );
-       /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
-       if (res != 12345678) printk( "Buggy.\n" );
-                       else printk( "OK.\n" );
+         : "ecx", "edi");
+       /*
+        * If this fails, it means that any user program may lock the
+        * CPU hard. Too bad.
+        */
+       if (res != 12345678)
+               printk("Buggy.\n");
+       else
+               printk("OK.\n");
 #endif
 }
 
@@ -137,7 +146,8 @@ static void __init check_config(void)
  * i486+ only features! (WP works in supervisor mode and the
  * new "invlpg" and "bswap" instructions)
  */
-#if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || defined(CONFIG_X86_BSWAP)
+#if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
+       defined(CONFIG_X86_BSWAP)
        if (boot_cpu_data.x86 == 3)
                panic("Kernel requires i486+ for 'invlpg' and other features");
 #endif
@@ -170,6 +180,7 @@ void __init check_bugs(void)
        check_fpu();
        check_hlt();
        check_popad();
-       init_utsname()->machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
+       init_utsname()->machine[1] =
+               '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
        alternative_instructions();
 }
diff --git a/arch/x86/kernel/cpu/bugs_64.c b/arch/x86/kernel/cpu/bugs_64.c
new file mode 100644 (file)
index 0000000..9a3ed06
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  Copyright (C) 1994  Linus Torvalds
+ *  Copyright (C) 2000  SuSE
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <asm/alternative.h>
+#include <asm/bugs.h>
+#include <asm/processor.h>
+#include <asm/mtrr.h>
+#include <asm/cacheflush.h>
+
+void __init check_bugs(void)
+{
+       identify_boot_cpu();
+#if !defined(CONFIG_SMP)
+       printk("CPU: ");
+       print_cpu_info(&boot_cpu_data);
+#endif
+       alternative_instructions();
+
+       /*
+        * Make sure the first 2MB area is not mapped by huge pages
+        * There are typically fixed size MTRRs in there and overlapping
+        * MTRRs into large pages causes slow downs.
+        *
+        * Right now we don't do that with gbpages because there seems
+        * very little benefit for that case.
+        */
+       if (!direct_gbpages)
+               set_memory_4k((unsigned long)__va(0), 1);
+}
diff --git a/arch/x86/kernel/cpu/centaur_64.c b/arch/x86/kernel/cpu/centaur_64.c
new file mode 100644 (file)
index 0000000..1d181c4
--- /dev/null
@@ -0,0 +1,35 @@
+#include <linux/init.h>
+#include <linux/smp.h>
+
+#include <asm/cpufeature.h>
+#include <asm/processor.h>
+
+#include "cpu.h"
+
+static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
+{
+       if (c->x86 == 0x6 && c->x86_model >= 0xf)
+               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+
+       set_cpu_cap(c, X86_FEATURE_SYSENTER32);
+}
+
+static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
+{
+       if (c->x86 == 0x6 && c->x86_model >= 0xf) {
+               c->x86_cache_alignment = c->x86_clflush_size * 2;
+               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+       }
+       set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
+}
+
+static struct cpu_dev centaur_cpu_dev __cpuinitdata = {
+       .c_vendor       = "Centaur",
+       .c_ident        = { "CentaurHauls" },
+       .c_early_init   = early_init_centaur,
+       .c_init         = init_centaur,
+};
+
+cpu_vendor_dev_register(X86_VENDOR_CENTAUR, &centaur_cpu_dev);
+
index d0463a9..80ab20d 100644 (file)
@@ -427,7 +427,7 @@ __setup("serialnumber", x86_serial_nr_setup);
 /*
  * This does the hard work of actually picking apart the CPU stuff...
  */
-void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
+static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
 {
        int i;
 
diff --git a/arch/x86/kernel/cpu/common_64.c b/arch/x86/kernel/cpu/common_64.c
new file mode 100644 (file)
index 0000000..7b8cc72
--- /dev/null
@@ -0,0 +1,681 @@
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/bootmem.h>
+#include <linux/bitops.h>
+#include <linux/module.h>
+#include <linux/kgdb.h>
+#include <linux/topology.h>
+#include <linux/string.h>
+#include <linux/delay.h>
+#include <linux/smp.h>
+#include <linux/module.h>
+#include <linux/percpu.h>
+#include <asm/processor.h>
+#include <asm/i387.h>
+#include <asm/msr.h>
+#include <asm/io.h>
+#include <asm/mmu_context.h>
+#include <asm/mtrr.h>
+#include <asm/mce.h>
+#include <asm/pat.h>
+#include <asm/numa.h>
+#ifdef CONFIG_X86_LOCAL_APIC
+#include <asm/mpspec.h>
+#include <asm/apic.h>
+#include <mach_apic.h>
+#endif
+#include <asm/pda.h>
+#include <asm/pgtable.h>
+#include <asm/processor.h>
+#include <asm/desc.h>
+#include <asm/atomic.h>
+#include <asm/proto.h>
+#include <asm/sections.h>
+#include <asm/setup.h>
+#include <asm/genapic.h>
+
+#include "cpu.h"
+
+/* We need valid kernel segments for data and code in long mode too
+ * IRET will check the segment types  kkeil 2000/10/28
+ * Also sysret mandates a special GDT layout
+ */
+/* The TLS descriptors are currently at a different place compared to i386.
+   Hopefully nobody expects them at a fixed place (Wine?) */
+DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
+       [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
+       [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
+       [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
+       [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
+       [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
+       [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
+} };
+EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
+
+__u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
+
+/* Current gdt points %fs at the "master" per-cpu area: after this,
+ * it's on the real one. */
+void switch_to_new_gdt(void)
+{
+       struct desc_ptr gdt_descr;
+
+       gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
+       gdt_descr.size = GDT_SIZE - 1;
+       load_gdt(&gdt_descr);
+}
+
+struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
+
+static void __cpuinit default_init(struct cpuinfo_x86 *c)
+{
+       display_cacheinfo(c);
+}
+
+static struct cpu_dev __cpuinitdata default_cpu = {
+       .c_init = default_init,
+       .c_vendor = "Unknown",
+};
+static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
+
+int __cpuinit get_model_name(struct cpuinfo_x86 *c)
+{
+       unsigned int *v;
+
+       if (c->extended_cpuid_level < 0x80000004)
+               return 0;
+
+       v = (unsigned int *) c->x86_model_id;
+       cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
+       cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
+       cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
+       c->x86_model_id[48] = 0;
+       return 1;
+}
+
+
+void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
+{
+       unsigned int n, dummy, ebx, ecx, edx;
+
+       n = c->extended_cpuid_level;
+
+       if (n >= 0x80000005) {
+               cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
+               printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
+                      "D cache %dK (%d bytes/line)\n",
+                      edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
+               c->x86_cache_size = (ecx>>24) + (edx>>24);
+               /* On K8 L1 TLB is inclusive, so don't count it */
+               c->x86_tlbsize = 0;
+       }
+
+       if (n >= 0x80000006) {
+               cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
+               ecx = cpuid_ecx(0x80000006);
+               c->x86_cache_size = ecx >> 16;
+               c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
+
+               printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
+               c->x86_cache_size, ecx & 0xFF);
+       }
+}
+
+void __cpuinit detect_ht(struct cpuinfo_x86 *c)
+{
+#ifdef CONFIG_SMP
+       u32 eax, ebx, ecx, edx;
+       int index_msb, core_bits;
+
+       cpuid(1, &eax, &ebx, &ecx, &edx);
+
+
+       if (!cpu_has(c, X86_FEATURE_HT))
+               return;
+       if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
+               goto out;
+
+       smp_num_siblings = (ebx & 0xff0000) >> 16;
+
+       if (smp_num_siblings == 1) {
+               printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
+       } else if (smp_num_siblings > 1) {
+
+               if (smp_num_siblings > NR_CPUS) {
+                       printk(KERN_WARNING "CPU: Unsupported number of "
+                              "siblings %d", smp_num_siblings);
+                       smp_num_siblings = 1;
+                       return;
+               }
+
+               index_msb = get_count_order(smp_num_siblings);
+               c->phys_proc_id = phys_pkg_id(index_msb);
+
+               smp_num_siblings = smp_num_siblings / c->x86_max_cores;
+
+               index_msb = get_count_order(smp_num_siblings);
+
+               core_bits = get_count_order(c->x86_max_cores);
+
+               c->cpu_core_id = phys_pkg_id(index_msb) &
+                                              ((1 << core_bits) - 1);
+       }
+out:
+       if ((c->x86_max_cores * smp_num_siblings) > 1) {
+               printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
+                      c->phys_proc_id);
+               printk(KERN_INFO  "CPU: Processor Core ID: %d\n",
+                      c->cpu_core_id);
+       }
+
+#endif
+}
+
+static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
+{
+       char *v = c->x86_vendor_id;
+       int i;
+       static int printed;
+
+       for (i = 0; i < X86_VENDOR_NUM; i++) {
+               if (cpu_devs[i]) {
+                       if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
+                           (cpu_devs[i]->c_ident[1] &&
+                           !strcmp(v, cpu_devs[i]->c_ident[1]))) {
+                               c->x86_vendor = i;
+                               this_cpu = cpu_devs[i];
+                               return;
+                       }
+               }
+       }
+       if (!printed) {
+               printed++;
+               printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
+               printk(KERN_ERR "CPU: Your system may be unstable.\n");
+       }
+       c->x86_vendor = X86_VENDOR_UNKNOWN;
+}
+
+static void __init early_cpu_support_print(void)
+{
+       int i,j;
+       struct cpu_dev *cpu_devx;
+
+       printk("KERNEL supported cpus:\n");
+       for (i = 0; i < X86_VENDOR_NUM; i++) {
+               cpu_devx = cpu_devs[i];
+               if (!cpu_devx)
+                       continue;
+               for (j = 0; j < 2; j++) {
+                       if (!cpu_devx->c_ident[j])
+                               continue;
+                       printk("  %s %s\n", cpu_devx->c_vendor,
+                               cpu_devx->c_ident[j]);
+               }
+       }
+}
+
+static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
+
+void __init early_cpu_init(void)
+{
+        struct cpu_vendor_dev *cvdev;
+
+        for (cvdev = __x86cpuvendor_start ;
+             cvdev < __x86cpuvendor_end   ;
+             cvdev++)
+                cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
+       early_cpu_support_print();
+       early_identify_cpu(&boot_cpu_data);
+}
+
+/* Do some early cpuid on the boot CPU to get some parameter that are
+   needed before check_bugs. Everything advanced is in identify_cpu
+   below. */
+static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
+{
+       u32 tfms, xlvl;
+
+       c->loops_per_jiffy = loops_per_jiffy;
+       c->x86_cache_size = -1;
+       c->x86_vendor = X86_VENDOR_UNKNOWN;
+       c->x86_model = c->x86_mask = 0; /* So far unknown... */
+       c->x86_vendor_id[0] = '\0'; /* Unset */
+       c->x86_model_id[0] = '\0';  /* Unset */
+       c->x86_clflush_size = 64;
+       c->x86_cache_alignment = c->x86_clflush_size;
+       c->x86_max_cores = 1;
+       c->x86_coreid_bits = 0;
+       c->extended_cpuid_level = 0;
+       memset(&c->x86_capability, 0, sizeof c->x86_capability);
+
+       /* Get vendor name */
+       cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
+             (unsigned int *)&c->x86_vendor_id[0],
+             (unsigned int *)&c->x86_vendor_id[8],
+             (unsigned int *)&c->x86_vendor_id[4]);
+
+       get_cpu_vendor(c);
+
+       /* Initialize the standard set of capabilities */
+       /* Note that the vendor-specific code below might override */
+
+       /* Intel-defined flags: level 0x00000001 */
+       if (c->cpuid_level >= 0x00000001) {
+               __u32 misc;
+               cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
+                     &c->x86_capability[0]);
+               c->x86 = (tfms >> 8) & 0xf;
+               c->x86_model = (tfms >> 4) & 0xf;
+               c->x86_mask = tfms & 0xf;
+               if (c->x86 == 0xf)
+                       c->x86 += (tfms >> 20) & 0xff;
+               if (c->x86 >= 0x6)
+                       c->x86_model += ((tfms >> 16) & 0xF) << 4;
+               if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
+                       c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
+       } else {
+               /* Have CPUID level 0 only - unheard of */
+               c->x86 = 4;
+       }
+
+       c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
+#ifdef CONFIG_SMP
+       c->phys_proc_id = c->initial_apicid;
+#endif
+       /* AMD-defined flags: level 0x80000001 */
+       xlvl = cpuid_eax(0x80000000);
+       c->extended_cpuid_level = xlvl;
+       if ((xlvl & 0xffff0000) == 0x80000000) {
+               if (xlvl >= 0x80000001) {
+                       c->x86_capability[1] = cpuid_edx(0x80000001);
+                       c->x86_capability[6] = cpuid_ecx(0x80000001);
+               }
+               if (xlvl >= 0x80000004)
+                       get_model_name(c); /* Default name */
+       }
+
+       /* Transmeta-defined flags: level 0x80860001 */
+       xlvl = cpuid_eax(0x80860000);
+       if ((xlvl & 0xffff0000) == 0x80860000) {
+               /* Don't set x86_cpuid_level here for now to not confuse. */
+               if (xlvl >= 0x80860001)
+                       c->x86_capability[2] = cpuid_edx(0x80860001);
+       }
+
+       c->extended_cpuid_level = cpuid_eax(0x80000000);
+       if (c->extended_cpuid_level >= 0x80000007)
+               c->x86_power = cpuid_edx(0x80000007);
+
+       if (c->extended_cpuid_level >= 0x80000008) {
+               u32 eax = cpuid_eax(0x80000008);
+
+               c->x86_virt_bits = (eax >> 8) & 0xff;
+               c->x86_phys_bits = eax & 0xff;
+       }
+
+       /* Assume all 64-bit CPUs support 32-bit syscall */
+       set_cpu_cap(c, X86_FEATURE_SYSCALL32);
+
+       if (c->x86_vendor != X86_VENDOR_UNKNOWN &&
+           cpu_devs[c->x86_vendor]->c_early_init)
+               cpu_devs[c->x86_vendor]->c_early_init(c);
+
+       validate_pat_support(c);
+
+       /* early_param could clear that, but recall get it set again */
+       if (disable_apic)
+               clear_cpu_cap(c, X86_FEATURE_APIC);
+}
+
+/*
+ * This does the hard work of actually picking apart the CPU stuff...
+ */
+static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
+{
+       int i;
+
+       early_identify_cpu(c);
+
+       init_scattered_cpuid_features(c);
+
+       c->apicid = phys_pkg_id(0);
+
+       /*
+        * Vendor-specific initialization.  In this section we
+        * canonicalize the feature flags, meaning if there are
+        * features a certain CPU supports which CPUID doesn't
+        * tell us, CPUID claiming incorrect flags, or other bugs,
+        * we handle them here.
+        *
+        * At the end of this section, c->x86_capability better
+        * indicate the features this CPU genuinely supports!
+        */
+       if (this_cpu->c_init)
+               this_cpu->c_init(c);
+
+       detect_ht(c);
+
+       /*
+        * On SMP, boot_cpu_data holds the common feature set between
+        * all CPUs; so make sure that we indicate which features are
+        * common between the CPUs.  The first time this routine gets
+        * executed, c == &boot_cpu_data.
+        */
+       if (c != &boot_cpu_data) {
+               /* AND the already accumulated flags with these */
+               for (i = 0; i < NCAPINTS; i++)
+                       boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
+       }
+
+       /* Clear all flags overriden by options */
+       for (i = 0; i < NCAPINTS; i++)
+               c->x86_capability[i] &= ~cleared_cpu_caps[i];
+
+#ifdef CONFIG_X86_MCE
+       mcheck_init(c);
+#endif
+       select_idle_routine(c);
+
+#ifdef CONFIG_NUMA
+       numa_add_cpu(smp_processor_id());
+#endif
+
+}
+
+void __cpuinit identify_boot_cpu(void)
+{
+       identify_cpu(&boot_cpu_data);
+}
+
+void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
+{
+       BUG_ON(c == &boot_cpu_data);
+       identify_cpu(c);
+       mtrr_ap_init();
+}
+
+static __init int setup_noclflush(char *arg)
+{
+       setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
+       return 1;
+}
+__setup("noclflush", setup_noclflush);
+
+void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
+{
+       if (c->x86_model_id[0])
+               printk(KERN_CONT "%s", c->x86_model_id);
+
+       if (c->x86_mask || c->cpuid_level >= 0)
+               printk(KERN_CONT " stepping %02x\n", c->x86_mask);
+       else
+               printk(KERN_CONT "\n");
+}
+
+static __init int setup_disablecpuid(char *arg)
+{
+       int bit;
+       if (get_option(&arg, &bit) && bit < NCAPINTS*32)
+               setup_clear_cpu_cap(bit);
+       else
+               return 0;
+       return 1;
+}
+__setup("clearcpuid=", setup_disablecpuid);
+
+cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
+
+struct x8664_pda **_cpu_pda __read_mostly;
+EXPORT_SYMBOL(_cpu_pda);
+
+struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
+
+char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
+
+unsigned long __supported_pte_mask __read_mostly = ~0UL;
+EXPORT_SYMBOL_GPL(__supported_pte_mask);
+
+static int do_not_nx __cpuinitdata;
+
+/* noexec=on|off
+Control non executable mappings for 64bit processes.
+
+on     Enable(default)
+off    Disable
+*/
+static int __init nonx_setup(char *str)
+{
+       if (!str)
+               return -EINVAL;
+       if (!strncmp(str, "on", 2)) {
+               __supported_pte_mask |= _PAGE_NX;
+               do_not_nx = 0;
+       } else if (!strncmp(str, "off", 3)) {
+               do_not_nx = 1;
+               __supported_pte_mask &= ~_PAGE_NX;
+       }
+       return 0;
+}
+early_param("noexec", nonx_setup);
+
+int force_personality32;
+
+/* noexec32=on|off
+Control non executable heap for 32bit processes.
+To control the stack too use noexec=off
+
+on     PROT_READ does not imply PROT_EXEC for 32bit processes (default)
+off    PROT_READ implies PROT_EXEC
+*/
+static int __init nonx32_setup(char *str)
+{
+       if (!strcmp(str, "on"))
+               force_personality32 &= ~READ_IMPLIES_EXEC;
+       else if (!strcmp(str, "off"))
+               force_personality32 |= READ_IMPLIES_EXEC;
+       return 1;
+}
+__setup("noexec32=", nonx32_setup);
+
+void pda_init(int cpu)
+{
+       struct x8664_pda *pda = cpu_pda(cpu);
+
+       /* Setup up data that may be needed in __get_free_pages early */
+       loadsegment(fs, 0);
+       loadsegment(gs, 0);
+       /* Memory clobbers used to order PDA accessed */
+       mb();
+       wrmsrl(MSR_GS_BASE, pda);
+       mb();
+
+       pda->cpunumber = cpu;
+       pda->irqcount = -1;
+       pda->kernelstack = (unsigned long)stack_thread_info() -
+                                PDA_STACKOFFSET + THREAD_SIZE;
+       pda->active_mm = &init_mm;
+       pda->mmu_state = 0;
+
+       if (cpu == 0) {
+               /* others are initialized in smpboot.c */
+               pda->pcurrent = &init_task;
+               pda->irqstackptr = boot_cpu_stack;
+       } else {
+               pda->irqstackptr = (char *)
+                       __get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER);
+               if (!pda->irqstackptr)
+                       panic("cannot allocate irqstack for cpu %d", cpu);
+
+               if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE)
+                       pda->nodenumber = cpu_to_node(cpu);
+       }
+
+       pda->irqstackptr += IRQSTACKSIZE-64;
+}
+
+char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ +
+                          DEBUG_STKSZ]
+__attribute__((section(".bss.page_aligned")));
+
+extern asmlinkage void ignore_sysret(void);
+
+/* May not be marked __init: used by software suspend */
+void syscall_init(void)
+{
+       /*
+        * LSTAR and STAR live in a bit strange symbiosis.
+        * They both write to the same internal register. STAR allows to
+        * set CS/DS but only a 32bit target. LSTAR sets the 64bit rip.
+        */
+       wrmsrl(MSR_STAR,  ((u64)__USER32_CS)<<48  | ((u64)__KERNEL_CS)<<32);
+       wrmsrl(MSR_LSTAR, system_call);
+       wrmsrl(MSR_CSTAR, ignore_sysret);
+
+#ifdef CONFIG_IA32_EMULATION
+       syscall32_cpu_init();
+#endif
+
+       /* Flags to clear on syscall */
+       wrmsrl(MSR_SYSCALL_MASK,
+              X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
+}
+
+void __cpuinit check_efer(void)
+{
+       unsigned long efer;
+
+       rdmsrl(MSR_EFER, efer);
+       if (!(efer & EFER_NX) || do_not_nx)
+               __supported_pte_mask &= ~_PAGE_NX;
+}
+
+unsigned long kernel_eflags;
+
+/*
+ * Copies of the original ist values from the tss are only accessed during
+ * debugging, no special alignment required.
+ */
+DEFINE_PER_CPU(struct orig_ist, orig_ist);
+
+/*
+ * cpu_init() initializes state that is per-CPU. Some data is already
+ * initialized (naturally) in the bootstrap process, such as the GDT
+ * and IDT. We reload them nevertheless, this function acts as a
+ * 'CPU state barrier', nothing should get across.
+ * A lot of state is already set up in PDA init.
+ */
+void __cpuinit cpu_init(void)
+{
+       int cpu = stack_smp_processor_id();
+       struct tss_struct *t = &per_cpu(init_tss, cpu);
+       struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
+       unsigned long v;
+       char *estacks = NULL;
+       struct task_struct *me;
+       int i;
+
+       /* CPU 0 is initialised in head64.c */
+       if (cpu != 0)
+               pda_init(cpu);
+       else
+               estacks = boot_exception_stacks;
+
+       me = current;
+
+       if (cpu_test_and_set(cpu, cpu_initialized))
+               panic("CPU#%d already initialized!\n", cpu);
+
+       printk(KERN_INFO "Initializing CPU#%d\n", cpu);
+
+       clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
+
+       /*
+        * Initialize the per-CPU GDT with the boot GDT,
+        * and set up the GDT descriptor:
+        */
+
+       switch_to_new_gdt();
+       load_idt((const struct desc_ptr *)&idt_descr);
+
+       memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
+       syscall_init();
+
+       wrmsrl(MSR_FS_BASE, 0);
+       wrmsrl(MSR_KERNEL_GS_BASE, 0);
+       barrier();
+
+       check_efer();
+
+       /*
+        * set up and load the per-CPU TSS
+        */
+       for (v = 0; v < N_EXCEPTION_STACKS; v++) {
+               static const unsigned int order[N_EXCEPTION_STACKS] = {
+                       [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
+                       [DEBUG_STACK - 1] = DEBUG_STACK_ORDER
+               };
+               if (cpu) {
+                       estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
+                       if (!estacks)
+                               panic("Cannot allocate exception stack %ld %d\n",
+                                     v, cpu);
+               }
+               estacks += PAGE_SIZE << order[v];
+               orig_ist->ist[v] = t->x86_tss.ist[v] = (unsigned long)estacks;
+       }
+
+       t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
+       /*
+        * <= is required because the CPU will access up to
+        * 8 bits beyond the end of the IO permission bitmap.
+        */
+       for (i = 0; i <= IO_BITMAP_LONGS; i++)
+               t->io_bitmap[i] = ~0UL;
+
+       atomic_inc(&init_mm.mm_count);
+       me->active_mm = &init_mm;
+       if (me->mm)
+               BUG();
+       enter_lazy_tlb(&init_mm, me);
+
+       load_sp0(t, &current->thread);
+       set_tss_desc(cpu, t);
+       load_TR_desc();
+       load_LDT(&init_mm.context);
+
+#ifdef CONFIG_KGDB
+       /*
+        * If the kgdb is connected no debug regs should be altered.  This
+        * is only applicable when KGDB and a KGDB I/O module are built
+        * into the kernel and you are using early debugging with
+        * kgdbwait. KGDB will control the kernel HW breakpoint registers.
+        */
+       if (kgdb_connected && arch_kgdb_ops.correct_hw_break)
+               arch_kgdb_ops.correct_hw_break();
+       else {
+#endif
+       /*
+        * Clear all 6 debug registers:
+        */
+
+       set_debugreg(0UL, 0);
+       set_debugreg(0UL, 1);
+       set_debugreg(0UL, 2);
+       set_debugreg(0UL, 3);
+       set_debugreg(0UL, 6);
+       set_debugreg(0UL, 7);
+#ifdef CONFIG_KGDB
+       /* If the kgdb is connected no debug regs should be altered. */
+       }
+#endif
+
+       fpu_init();
+
+       raw_local_save_flags(kernel_eflags);
+
+       if (is_uv_system())
+               uv_cpu_init();
+}
index 783691b..4d894e8 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef ARCH_X86_CPU_H
+
+#define ARCH_X86_CPU_H
 
 struct cpu_model_info {
        int vendor;
@@ -36,3 +39,5 @@ extern struct cpu_vendor_dev __x86cpuvendor_start[], __x86cpuvendor_end[];
 
 extern int get_model_name(struct cpuinfo_x86 *c);
 extern void display_cacheinfo(struct cpuinfo_x86 *c);
+
+#endif
index f03e915..965ea52 100644 (file)
 #define NFORCE2_SAFE_DISTANCE 50
 
 /* Delay in ms between FSB changes */
-//#define NFORCE2_DELAY 10
+/* #define NFORCE2_DELAY 10 */
 
-/* nforce2_chipset:
+/*
+ * nforce2_chipset:
  * FSB is changed using the chipset
  */
 static struct pci_dev *nforce2_chipset_dev;
@@ -36,13 +37,13 @@ static struct pci_dev *nforce2_chipset_dev;
 /* fid:
  * multiplier * 10
  */
-static int fid = 0;
+static int fid;
 
 /* min_fsb, max_fsb:
  * minimum and maximum FSB (= FSB at boot time)
  */
-static int min_fsb = 0;
-static int max_fsb = 0;
+static int min_fsb;
+static int max_fsb;
 
 MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
 MODULE_DESCRIPTION("nForce2 FSB changing cpufreq driver");
@@ -53,7 +54,7 @@ module_param(min_fsb, int, 0444);
 
 MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)");
 MODULE_PARM_DESC(min_fsb,
-                 "Minimum FSB to use, if not defined: current FSB - 50");
+               "Minimum FSB to use, if not defined: current FSB - 50");
 
 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "cpufreq-nforce2", msg)
 
@@ -139,7 +140,7 @@ static unsigned int nforce2_fsb_read(int bootfsb)
 
        /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */
        nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
-                                               0x01EF,PCI_ANY_ID,PCI_ANY_ID,NULL);
+                                               0x01EF, PCI_ANY_ID, PCI_ANY_ID, NULL);
        if (!nforce2_sub5)
                return 0;
 
@@ -147,13 +148,13 @@ static unsigned int nforce2_fsb_read(int bootfsb)
        fsb /= 1000000;
 
        /* Check if PLL register is already set */
-       pci_read_config_byte(nforce2_chipset_dev,NFORCE2_PLLENABLE, (u8 *)&temp);
+       pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
 
-       if(bootfsb || !temp)
+       if (bootfsb || !temp)
                return fsb;
-               
+
        /* Use PLL register FSB value */
-       pci_read_config_dword(nforce2_chipset_dev,NFORCE2_PLLREG, &temp);
+       pci_read_config_dword(nforce2_chipset_dev, NFORCE2_PLLREG, &temp);
        fsb = nforce2_calc_fsb(temp);
 
        return fsb;
@@ -184,7 +185,7 @@ static int nforce2_set_fsb(unsigned int fsb)
        }
 
        /* First write? Then set actual value */
-       pci_read_config_byte(nforce2_chipset_dev,NFORCE2_PLLENABLE, (u8 *)&temp);
+       pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
        if (!temp) {
                pll = nforce2_calc_pll(tfsb);
 
@@ -210,7 +211,8 @@ static int nforce2_set_fsb(unsigned int fsb)
                        tfsb--;
 
                /* Calculate the PLL reg. value */
-               if ((pll = nforce2_calc_pll(tfsb)) == -1)
+               pll = nforce2_calc_pll(tfsb);
+               if (pll == -1)
                        return -EINVAL;
 
                nforce2_write_pll(pll);
@@ -249,7 +251,7 @@ static unsigned int nforce2_get(unsigned int cpu)
 static int nforce2_target(struct cpufreq_policy *policy,
                          unsigned int target_freq, unsigned int relation)
 {
-//        unsigned long         flags;
+/*        unsigned long         flags; */
        struct cpufreq_freqs freqs;
        unsigned int target_fsb;
 
@@ -271,17 +273,17 @@ static int nforce2_target(struct cpufreq_policy *policy,
        cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
 
        /* Disable IRQs */
-       //local_irq_save(flags);
+       /* local_irq_save(flags); */
 
        if (nforce2_set_fsb(target_fsb) < 0)
                printk(KERN_ERR "cpufreq: Changing FSB to %d failed\n",
-                       target_fsb);
+                       target_fsb);
        else
                dprintk("Changed FSB successfully to %d\n",
-                       target_fsb);
+                       target_fsb);
 
        /* Enable IRQs */
-       //local_irq_restore(flags);
+       /* local_irq_restore(flags); */
 
        cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
 
@@ -302,8 +304,8 @@ static int nforce2_verify(struct cpufreq_policy *policy)
                policy->max = (fsb_pol_max + 1) * fid * 100;
 
        cpufreq_verify_within_limits(policy,
-                                     policy->cpuinfo.min_freq,
-                                     policy->cpuinfo.max_freq);
+                                    policy->cpuinfo.min_freq,
+                                    policy->cpuinfo.max_freq);
        return 0;
 }
 
@@ -347,7 +349,7 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
        /* Set maximum FSB to FSB at boot time */
        max_fsb = nforce2_fsb_read(1);
 
-       if(!max_fsb)
+       if (!max_fsb)
                return -EIO;
 
        if (!min_fsb)
index fe9224c..70609ef 100644 (file)
@@ -226,6 +226,10 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
 
        if (cpu_has_bts)
                ds_init_intel(c);
+
+#ifdef CONFIG_X86_NUMAQ
+       numaq_tsc_disable();
+#endif
 }
 
 static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
diff --git a/arch/x86/kernel/cpu/intel_64.c b/arch/x86/kernel/cpu/intel_64.c
new file mode 100644 (file)
index 0000000..1019c58
--- /dev/null
@@ -0,0 +1,95 @@
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <asm/processor.h>
+#include <asm/ptrace.h>
+#include <asm/topology.h>
+#include <asm/numa_64.h>
+
+#include "cpu.h"
+
+static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
+{
+       if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
+           (c->x86 == 0x6 && c->x86_model >= 0x0e))
+               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
+
+       set_cpu_cap(c, X86_FEATURE_SYSENTER32);
+}
+
+/*
+ * find out the number of processor cores on the die
+ */
+static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
+{
+       unsigned int eax, t;
+
+       if (c->cpuid_level < 4)
+               return 1;
+
+       cpuid_count(4, 0, &eax, &t, &t, &t);
+
+       if (eax & 0x1f)
+               return ((eax >> 26) + 1);
+       else
+               return 1;
+}
+
+static void __cpuinit srat_detect_node(void)
+{
+#ifdef CONFIG_NUMA
+       unsigned node;
+       int cpu = smp_processor_id();
+       int apicid = hard_smp_processor_id();
+
+       /* Don't do the funky fallback heuristics the AMD version employs
+          for now. */
+       node = apicid_to_node[apicid];
+       if (node == NUMA_NO_NODE || !node_online(node))
+               node = first_node(node_online_map);
+       numa_set_node(cpu, node);
+
+       printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
+#endif
+}
+
+static void __cpuinit init_intel(struct cpuinfo_x86 *c)
+{
+       init_intel_cacheinfo(c);
+       if (c->cpuid_level > 9) {
+               unsigned eax = cpuid_eax(10);
+               /* Check for version and the number of counters */
+               if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
+                       set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
+       }
+
+       if (cpu_has_ds) {
+               unsigned int l1, l2;
+               rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
+               if (!(l1 & (1<<11)))
+                       set_cpu_cap(c, X86_FEATURE_BTS);
+               if (!(l1 & (1<<12)))
+                       set_cpu_cap(c, X86_FEATURE_PEBS);
+       }
+
+
+       if (cpu_has_bts)
+               ds_init_intel(c);
+
+       if (c->x86 == 15)
+               c->x86_cache_alignment = c->x86_clflush_size * 2;
+       if (c->x86 == 6)
+               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+       set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
+       c->x86_max_cores = intel_num_cpu_cores(c);
+
+       srat_detect_node();
+}
+
+static struct cpu_dev intel_cpu_dev __cpuinitdata = {
+       .c_vendor       = "Intel",
+       .c_ident        = { "GenuineIntel" },
+       .c_early_init   = early_init_intel,
+       .c_init         = init_intel,
+};
+cpu_vendor_dev_register(X86_VENDOR_INTEL, &intel_cpu_dev);
+
index 26d615d..2c8afaf 100644 (file)
@@ -62,6 +62,7 @@ static struct _cache_table cache_table[] __cpuinitdata =
        { 0x4b, LVL_3,      8192 },     /* 16-way set assoc, 64 byte line size */
        { 0x4c, LVL_3,     12288 },     /* 12-way set assoc, 64 byte line size */
        { 0x4d, LVL_3,     16384 },     /* 16-way set assoc, 64 byte line size */
+       { 0x4e, LVL_2,      6144 },     /* 24-way set assoc, 64 byte line size */
        { 0x60, LVL_1_DATA, 16 },       /* 8-way set assoc, sectored cache, 64 byte line size */
        { 0x66, LVL_1_DATA, 8 },        /* 4-way set assoc, sectored cache, 64 byte line size */
        { 0x67, LVL_1_DATA, 16 },       /* 4-way set assoc, sectored cache, 64 byte line size */
index e633c9c..f390c9f 100644 (file)
@@ -9,23 +9,23 @@
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 
-#include <asm/processor.h> 
+#include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/msr.h>
 
 #include "mce.h"
 
 /* Machine Check Handler For AMD Athlon/Duron */
-static void k7_machine_check(struct pt_regs * regs, long error_code)
+static void k7_machine_check(struct pt_regs *regs, long error_code)
 {
-       int recover=1;
+       int recover = 1;
        u32 alow, ahigh, high, low;
        u32 mcgstl, mcgsth;
        int i;
 
-       rdmsr (MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
+       rdmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
        if (mcgstl & (1<<0))    /* Recoverable ? */
-               recover=0;
+               recover = 0;
 
        printk(KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
                smp_processor_id(), mcgsth, mcgstl);
@@ -60,12 +60,12 @@ static void k7_machine_check(struct pt_regs * regs, long error_code)
        }
 
        if (recover&2)
-               panic ("CPU context corrupt");
+               panic("CPU context corrupt");
        if (recover&1)
-               panic ("Unable to continue");
-       printk (KERN_EMERG "Attempting to continue.\n");
+               panic("Unable to continue");
+       printk(KERN_EMERG "Attempting to continue.\n");
        mcgstl &= ~(1<<2);
-       wrmsr (MSR_IA32_MCG_STATUS,mcgstl, mcgsth);
+       wrmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
 }
 
 
@@ -81,25 +81,25 @@ void amd_mcheck_init(struct cpuinfo_x86 *c)
        machine_check_vector = k7_machine_check;
        wmb();
 
-       printk (KERN_INFO "Intel machine check architecture supported.\n");
-       rdmsr (MSR_IA32_MCG_CAP, l, h);
+       printk(KERN_INFO "Intel machine check architecture supported.\n");
+       rdmsr(MSR_IA32_MCG_CAP, l, h);
        if (l & (1<<8)) /* Control register present ? */
-               wrmsr (MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
+               wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
        nr_mce_banks = l & 0xff;
 
        /* Clear status for MC index 0 separately, we don't touch CTL,
         * as some K7 Athlons cause spurious MCEs when its enabled. */
        if (boot_cpu_data.x86 == 6) {
-               wrmsr (MSR_IA32_MC0_STATUS, 0x0, 0x0);
+               wrmsr(MSR_IA32_MC0_STATUS, 0x0, 0x0);
                i = 1;
        } else
                i = 0;
-       for (; i<nr_mce_banks; i++) {
-               wrmsr (MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
-               wrmsr (MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
+       for (; i < nr_mce_banks; i++) {
+               wrmsr(MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
+               wrmsr(MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
        }
 
-       set_in_cr4 (X86_CR4_MCE);
-       printk (KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
+       set_in_cr4(X86_CR4_MCE);
+       printk(KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
                smp_processor_id());
 }
index e07e8c0..9874107 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/rcupdate.h>
 #include <linux/kallsyms.h>
@@ -31,7 +32,7 @@
 #include <asm/idle.h>
 
 #define MISC_MCELOG_MINOR 227
-#define NR_BANKS 6
+#define NR_SYSFS_BANKS 6
 
 atomic_t mce_entry;
 
@@ -46,7 +47,7 @@ static int mce_dont_init;
  */
 static int tolerant = 1;
 static int banks;
-static unsigned long bank[NR_BANKS] = { [0 ... NR_BANKS-1] = ~0UL };
+static unsigned long bank[NR_SYSFS_BANKS] = { [0 ... NR_SYSFS_BANKS-1] = ~0UL };
 static unsigned long notify_user;
 static int rip_msr;
 static int mce_bootlog = -1;
@@ -209,7 +210,7 @@ void do_machine_check(struct pt_regs * regs, long error_code)
        barrier();
 
        for (i = 0; i < banks; i++) {
-               if (!bank[i])
+               if (i < NR_SYSFS_BANKS && !bank[i])
                        continue;
 
                m.misc = 0;
@@ -444,9 +445,10 @@ static void mce_init(void *dummy)
 
        rdmsrl(MSR_IA32_MCG_CAP, cap);
        banks = cap & 0xff;
-       if (banks > NR_BANKS) {
-               printk(KERN_INFO "MCE: warning: using only %d banks\n", banks);
-               banks = NR_BANKS;
+       if (banks > MCE_EXTENDED_BANK) {
+               banks = MCE_EXTENDED_BANK;
+               printk(KERN_INFO "MCE: warning: using only %d banks\n",
+                      MCE_EXTENDED_BANK);
        }
        /* Use accurate RIP reporting if available. */
        if ((cap & (1<<9)) && ((cap >> 16) & 0xff) >= 9)
@@ -462,7 +464,11 @@ static void mce_init(void *dummy)
                wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
 
        for (i = 0; i < banks; i++) {
-               wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
+               if (i < NR_SYSFS_BANKS)
+                       wrmsrl(MSR_IA32_MC0_CTL+4*i, bank[i]);
+               else
+                       wrmsrl(MSR_IA32_MC0_CTL+4*i, ~0UL);
+
                wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
        }
 }
@@ -527,10 +533,12 @@ static int open_exclu;    /* already open exclusive? */
 
 static int mce_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock(&mce_state_lock);
 
        if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
                spin_unlock(&mce_state_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -539,6 +547,7 @@ static int mce_open(struct inode *inode, struct file *file)
        open_count++;
 
        spin_unlock(&mce_state_lock);
+       unlock_kernel();
 
        return nonseekable_open(inode, file);
 }
@@ -766,7 +775,10 @@ DEFINE_PER_CPU(struct sys_device, device_mce);
        }                                                               \
        static SYSDEV_ATTR(name, 0644, show_ ## name, set_ ## name);
 
-/* TBD should generate these dynamically based on number of available banks */
+/*
+ * TBD should generate these dynamically based on number of available banks.
+ * Have only 6 contol banks in /sysfs until then.
+ */
 ACCESSOR(bank0ctl,bank[0],mce_restart())
 ACCESSOR(bank1ctl,bank[1],mce_restart())
 ACCESSOR(bank2ctl,bank[2],mce_restart())
index cb03345..eef001a 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 
-#include <asm/processor.h> 
+#include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/msr.h>
 #include <asm/apic.h>
@@ -32,12 +32,12 @@ struct intel_mce_extended_msrs {
        /* u32 *reserved[]; */
 };
 
-static int mce_num_extended_msrs = 0;
+static int mce_num_extended_msrs;
 
 
 #ifdef CONFIG_X86_MCE_P4THERMAL
 static void unexpected_thermal_interrupt(struct pt_regs *regs)
-{      
+{
        printk(KERN_ERR "CPU%d: Unexpected LVT TMR interrupt!\n",
                        smp_processor_id());
        add_taint(TAINT_MACHINE_CHECK);
@@ -83,7 +83,7 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)
         * be some SMM goo which handles it, so we can't even put a handler
         * since it might be delivered via SMI already -zwanem.
         */
-       rdmsr (MSR_IA32_MISC_ENABLE, l, h);
+       rdmsr(MSR_IA32_MISC_ENABLE, l, h);
        h = apic_read(APIC_LVTTHMR);
        if ((l & (1<<3)) && (h & APIC_DM_SMI)) {
                printk(KERN_DEBUG "CPU%d: Thermal monitoring handled by SMI\n",
@@ -91,7 +91,7 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)
                return; /* -EBUSY */
        }
 
-       /* check whether a vector already exists, temporarily masked? */        
+       /* check whether a vector already exists, temporarily masked? */
        if (h & APIC_VECTOR_MASK) {
                printk(KERN_DEBUG "CPU%d: Thermal LVT vector (%#x) already "
                                "installed\n",
@@ -104,18 +104,18 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)
        h |= (APIC_DM_FIXED | APIC_LVT_MASKED); /* we'll mask till we're ready */
        apic_write_around(APIC_LVTTHMR, h);
 
-       rdmsr (MSR_IA32_THERM_INTERRUPT, l, h);
-       wrmsr (MSR_IA32_THERM_INTERRUPT, l | 0x03 , h);
+       rdmsr(MSR_IA32_THERM_INTERRUPT, l, h);
+       wrmsr(MSR_IA32_THERM_INTERRUPT, l | 0x03 , h);
 
        /* ok we're good to go... */
        vendor_thermal_interrupt = intel_thermal_interrupt;
-       
-       rdmsr (MSR_IA32_MISC_ENABLE, l, h);
-       wrmsr (MSR_IA32_MISC_ENABLE, l | (1<<3), h);
 
-       l = apic_read (APIC_LVTTHMR);
-       apic_write_around (APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
-       printk (KERN_INFO "CPU%d: Thermal monitoring enabled\n", cpu);
+       rdmsr(MSR_IA32_MISC_ENABLE, l, h);
+       wrmsr(MSR_IA32_MISC_ENABLE, l | (1<<3), h);
+
+       l = apic_read(APIC_LVTTHMR);
+       apic_write_around(APIC_LVTTHMR, l & ~APIC_LVT_MASKED);
+       printk(KERN_INFO "CPU%d: Thermal monitoring enabled\n", cpu);
 
        /* enable thermal throttle processing */
        atomic_set(&therm_throt_en, 1);
@@ -129,28 +129,28 @@ static inline void intel_get_extended_msrs(struct intel_mce_extended_msrs *r)
 {
        u32 h;
 
-       rdmsr (MSR_IA32_MCG_EAX, r->eax, h);
-       rdmsr (MSR_IA32_MCG_EBX, r->ebx, h);
-       rdmsr (MSR_IA32_MCG_ECX, r->ecx, h);
-       rdmsr (MSR_IA32_MCG_EDX, r->edx, h);
-       rdmsr (MSR_IA32_MCG_ESI, r->esi, h);
-       rdmsr (MSR_IA32_MCG_EDI, r->edi, h);
-       rdmsr (MSR_IA32_MCG_EBP, r->ebp, h);
-       rdmsr (MSR_IA32_MCG_ESP, r->esp, h);
-       rdmsr (MSR_IA32_MCG_EFLAGS, r->eflags, h);
-       rdmsr (MSR_IA32_MCG_EIP, r->eip, h);
+       rdmsr(MSR_IA32_MCG_EAX, r->eax, h);
+       rdmsr(MSR_IA32_MCG_EBX, r->ebx, h);
+       rdmsr(MSR_IA32_MCG_ECX, r->ecx, h);
+       rdmsr(MSR_IA32_MCG_EDX, r->edx, h);
+       rdmsr(MSR_IA32_MCG_ESI, r->esi, h);
+       rdmsr(MSR_IA32_MCG_EDI, r->edi, h);
+       rdmsr(MSR_IA32_MCG_EBP, r->ebp, h);
+       rdmsr(MSR_IA32_MCG_ESP, r->esp, h);
+       rdmsr(MSR_IA32_MCG_EFLAGS, r->eflags, h);
+       rdmsr(MSR_IA32_MCG_EIP, r->eip, h);
 }
 
-static void intel_machine_check(struct pt_regs * regs, long error_code)
+static void intel_machine_check(struct pt_regs *regs, long error_code)
 {
-       int recover=1;
+       int recover = 1;
        u32 alow, ahigh, high, low;
        u32 mcgstl, mcgsth;
        int i;
 
-       rdmsr (MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
+       rdmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
        if (mcgstl & (1<<0))    /* Recoverable ? */
-               recover=0;
+               recover = 0;
 
        printk(KERN_EMERG "CPU %d: Machine Check Exception: %08x%08x\n",
                smp_processor_id(), mcgsth, mcgstl);
@@ -191,20 +191,20 @@ static void intel_machine_check(struct pt_regs * regs, long error_code)
        }
 
        if (recover & 2)
-               panic ("CPU context corrupt");
+               panic("CPU context corrupt");
        if (recover & 1)
-               panic ("Unable to continue");
+               panic("Unable to continue");
 
        printk(KERN_EMERG "Attempting to continue.\n");
-       /* 
-        * Do not clear the MSR_IA32_MCi_STATUS if the error is not 
+       /*
+        * Do not clear the MSR_IA32_MCi_STATUS if the error is not
         * recoverable/continuable.This will allow BIOS to look at the MSRs
         * for errors if the OS could not log the error.
         */
-       for (i=0; i<nr_mce_banks; i++) {
+       for (i = 0; i < nr_mce_banks; i++) {
                u32 msr;
                msr = MSR_IA32_MC0_STATUS+i*4;
-               rdmsr (msr, low, high);
+               rdmsr(msr, low, high);
                if (high&(1<<31)) {
                        /* Clear it */
                        wrmsr(msr, 0UL, 0UL);
@@ -214,7 +214,7 @@ static void intel_machine_check(struct pt_regs * regs, long error_code)
                }
        }
        mcgstl &= ~(1<<2);
-       wrmsr (MSR_IA32_MCG_STATUS,mcgstl, mcgsth);
+       wrmsr(MSR_IA32_MCG_STATUS, mcgstl, mcgsth);
 }
 
 
@@ -222,30 +222,30 @@ void intel_p4_mcheck_init(struct cpuinfo_x86 *c)
 {
        u32 l, h;
        int i;
-       
+
        machine_check_vector = intel_machine_check;
        wmb();
 
-       printk (KERN_INFO "Intel machine check architecture supported.\n");
-       rdmsr (MSR_IA32_MCG_CAP, l, h);
+       printk(KERN_INFO "Intel machine check architecture supported.\n");
+       rdmsr(MSR_IA32_MCG_CAP, l, h);
        if (l & (1<<8)) /* Control register present ? */
-               wrmsr (MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
+               wrmsr(MSR_IA32_MCG_CTL, 0xffffffff, 0xffffffff);
        nr_mce_banks = l & 0xff;
 
-       for (i=0; i<nr_mce_banks; i++) {
-               wrmsr (MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
-               wrmsr (MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
+       for (i = 0; i < nr_mce_banks; i++) {
+               wrmsr(MSR_IA32_MC0_CTL+4*i, 0xffffffff, 0xffffffff);
+               wrmsr(MSR_IA32_MC0_STATUS+4*i, 0x0, 0x0);
        }
 
-       set_in_cr4 (X86_CR4_MCE);
-       printk (KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
+       set_in_cr4(X86_CR4_MCE);
+       printk(KERN_INFO "Intel machine check reporting enabled on CPU#%d.\n",
                smp_processor_id());
 
        /* Check for P4/Xeon extended MCE MSRs */
-       rdmsr (MSR_IA32_MCG_CAP, l, h);
+       rdmsr(MSR_IA32_MCG_CAP, l, h);
        if (l & (1<<9)) {/* MCG_EXT_P */
                mce_num_extended_msrs = (l >> 16) & 0xff;
-               printk (KERN_INFO "CPU%d: Intel P4/Xeon Extended MCE MSRs (%d)"
+               printk(KERN_INFO "CPU%d: Intel P4/Xeon Extended MCE MSRs (%d)"
                                " available\n",
                        smp_processor_id(), mce_num_extended_msrs);
 
index 5d241ce..509bd3d 100644 (file)
@@ -37,7 +37,7 @@ static struct fixed_range_block fixed_range_blocks[] = {
 static unsigned long smp_changes_mask;
 static struct mtrr_state mtrr_state = {};
 static int mtrr_state_set;
-static u64 tom2;
+u64 mtrr_tom2;
 
 #undef MODULE_PARAM_PREFIX
 #define MODULE_PARAM_PREFIX "mtrr."
@@ -139,8 +139,8 @@ u8 mtrr_type_lookup(u64 start, u64 end)
                }
        }
 
-       if (tom2) {
-               if (start >= (1ULL<<32) && (end < tom2))
+       if (mtrr_tom2) {
+               if (start >= (1ULL<<32) && (end < mtrr_tom2))
                        return MTRR_TYPE_WRBACK;
        }
 
@@ -158,6 +158,20 @@ get_mtrr_var_range(unsigned int index, struct mtrr_var_range *vr)
        rdmsr(MTRRphysMask_MSR(index), vr->mask_lo, vr->mask_hi);
 }
 
+/*  fill the MSR pair relating to a var range  */
+void fill_mtrr_var_range(unsigned int index,
+               u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi)
+{
+       struct mtrr_var_range *vr;
+
+       vr = mtrr_state.var_ranges;
+
+       vr[index].base_lo = base_lo;
+       vr[index].base_hi = base_hi;
+       vr[index].mask_lo = mask_lo;
+       vr[index].mask_hi = mask_hi;
+}
+
 static void
 get_fixed_ranges(mtrr_type * frs)
 {
@@ -213,13 +227,13 @@ void __init get_mtrr_state(void)
        mtrr_state.enabled = (lo & 0xc00) >> 10;
 
        if (amd_special_default_mtrr()) {
-               unsigned lo, hi;
+               unsigned low, high;
                /* TOP_MEM2 */
-               rdmsr(MSR_K8_TOP_MEM2, lo, hi);
-               tom2 = hi;
-               tom2 <<= 32;
-               tom2 |= lo;
-               tom2 &= 0xffffff8000000ULL;
+               rdmsr(MSR_K8_TOP_MEM2, low, high);
+               mtrr_tom2 = high;
+               mtrr_tom2 <<= 32;
+               mtrr_tom2 |= low;
+               mtrr_tom2 &= 0xffffff800000ULL;
        }
        if (mtrr_show) {
                int high_width;
@@ -251,9 +265,9 @@ void __init get_mtrr_state(void)
                        else
                                printk(KERN_INFO "MTRR %u disabled\n", i);
                }
-               if (tom2) {
+               if (mtrr_tom2) {
                        printk(KERN_INFO "TOM2: %016llx aka %lldM\n",
-                                         tom2, tom2>>20);
+                                         mtrr_tom2, mtrr_tom2>>20);
                }
        }
        mtrr_state_set = 1;
@@ -328,7 +342,7 @@ static void set_fixed_range(int msr, bool *changed, unsigned int *msrwords)
 
        if (lo != msrwords[0] || hi != msrwords[1]) {
                if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
-                   boot_cpu_data.x86 == 15 &&
+                   (boot_cpu_data.x86 >= 0x0f && boot_cpu_data.x86 <= 0x11) &&
                    ((msrwords[0] | msrwords[1]) & K8_MTRR_RDMEM_WRMEM_MASK))
                        k8_enable_fixed_iorrs();
                mtrr_wrmsr(msr, msrwords[0], msrwords[1]);
index 6a1e278..105afe1 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/smp.h>
 #include <linux/cpu.h>
 #include <linux/mutex.h>
+#include <linux/sort.h>
 
 #include <asm/e820.h>
 #include <asm/mtrr.h>
@@ -609,6 +610,787 @@ static struct sysdev_driver mtrr_sysdev_driver = {
        .resume         = mtrr_restore,
 };
 
+/* should be related to MTRR_VAR_RANGES nums */
+#define RANGE_NUM 256
+
+struct res_range {
+       unsigned long start;
+       unsigned long end;
+};
+
+static int __init
+add_range(struct res_range *range, int nr_range, unsigned long start,
+                             unsigned long end)
+{
+       /* out of slots */
+       if (nr_range >= RANGE_NUM)
+               return nr_range;
+
+       range[nr_range].start = start;
+       range[nr_range].end = end;
+
+       nr_range++;
+
+       return nr_range;
+}
+
+static int __init
+add_range_with_merge(struct res_range *range, int nr_range, unsigned long start,
+                             unsigned long end)
+{
+       int i;
+
+       /* try to merge it with old one */
+       for (i = 0; i < nr_range; i++) {
+               unsigned long final_start, final_end;
+               unsigned long common_start, common_end;
+
+               if (!range[i].end)
+                       continue;
+
+               common_start = max(range[i].start, start);
+               common_end = min(range[i].end, end);
+               if (common_start > common_end + 1)
+                       continue;
+
+               final_start = min(range[i].start, start);
+               final_end = max(range[i].end, end);
+
+               range[i].start = final_start;
+               range[i].end =  final_end;
+               return nr_range;
+       }
+
+       /* need to add that */
+       return add_range(range, nr_range, start, end);
+}
+
+static void __init
+subtract_range(struct res_range *range, unsigned long start, unsigned long end)
+{
+       int i, j;
+
+       for (j = 0; j < RANGE_NUM; j++) {
+               if (!range[j].end)
+                       continue;
+
+               if (start <= range[j].start && end >= range[j].end) {
+                       range[j].start = 0;
+                       range[j].end = 0;
+                       continue;
+               }
+
+               if (start <= range[j].start && end < range[j].end &&
+                   range[j].start < end + 1) {
+                       range[j].start = end + 1;
+                       continue;
+               }
+
+
+               if (start > range[j].start && end >= range[j].end &&
+                   range[j].end > start - 1) {
+                       range[j].end = start - 1;
+                       continue;
+               }
+
+               if (start > range[j].start && end < range[j].end) {
+                       /* find the new spare */
+                       for (i = 0; i < RANGE_NUM; i++) {
+                               if (range[i].end == 0)
+                                       break;
+                       }
+                       if (i < RANGE_NUM) {
+                               range[i].end = range[j].end;
+                               range[i].start = end + 1;
+                       } else {
+                               printk(KERN_ERR "run of slot in ranges\n");
+                       }
+                       range[j].end = start - 1;
+                       continue;
+               }
+       }
+}
+
+static int __init cmp_range(const void *x1, const void *x2)
+{
+       const struct res_range *r1 = x1;
+       const struct res_range *r2 = x2;
+       long start1, start2;
+
+       start1 = r1->start;
+       start2 = r2->start;
+
+       return start1 - start2;
+}
+
+struct var_mtrr_range_state {
+       unsigned long base_pfn;
+       unsigned long size_pfn;
+       mtrr_type type;
+};
+
+struct var_mtrr_range_state __initdata range_state[RANGE_NUM];
+static int __initdata debug_print;
+
+static int __init
+x86_get_mtrr_mem_range(struct res_range *range, int nr_range,
+                      unsigned long extra_remove_base,
+                      unsigned long extra_remove_size)
+{
+       unsigned long i, base, size;
+       mtrr_type type;
+
+       for (i = 0; i < num_var_ranges; i++) {
+               type = range_state[i].type;
+               if (type != MTRR_TYPE_WRBACK)
+                       continue;
+               base = range_state[i].base_pfn;
+               size = range_state[i].size_pfn;
+               nr_range = add_range_with_merge(range, nr_range, base,
+                                               base + size - 1);
+       }
+       if (debug_print) {
+               printk(KERN_DEBUG "After WB checking\n");
+               for (i = 0; i < nr_range; i++)
+                       printk(KERN_DEBUG "MTRR MAP PFN: %016lx - %016lx\n",
+                                range[i].start, range[i].end + 1);
+       }
+
+       /* take out UC ranges */
+       for (i = 0; i < num_var_ranges; i++) {
+               type = range_state[i].type;
+               if (type != MTRR_TYPE_UNCACHABLE)
+                       continue;
+               size = range_state[i].size_pfn;
+               if (!size)
+                       continue;
+               base = range_state[i].base_pfn;
+               subtract_range(range, base, base + size - 1);
+       }
+       if (extra_remove_size)
+               subtract_range(range, extra_remove_base,
+                                extra_remove_base + extra_remove_size  - 1);
+
+       /* get new range num */
+       nr_range = 0;
+       for (i = 0; i < RANGE_NUM; i++) {
+               if (!range[i].end)
+                       continue;
+               nr_range++;
+       }
+       if  (debug_print) {
+               printk(KERN_DEBUG "After UC checking\n");
+               for (i = 0; i < nr_range; i++)
+                       printk(KERN_DEBUG "MTRR MAP PFN: %016lx - %016lx\n",
+                                range[i].start, range[i].end + 1);
+       }
+
+       /* sort the ranges */
+       sort(range, nr_range, sizeof(struct res_range), cmp_range, NULL);
+       if  (debug_print) {
+               printk(KERN_DEBUG "After sorting\n");
+               for (i = 0; i < nr_range; i++)
+                       printk(KERN_DEBUG "MTRR MAP PFN: %016lx - %016lx\n",
+                                range[i].start, range[i].end + 1);
+       }
+
+       /* clear those is not used */
+       for (i = nr_range; i < RANGE_NUM; i++)
+               memset(&range[i], 0, sizeof(range[i]));
+
+       return nr_range;
+}
+
+static struct res_range __initdata range[RANGE_NUM];
+
+#ifdef CONFIG_MTRR_SANITIZER
+
+static unsigned long __init sum_ranges(struct res_range *range, int nr_range)
+{
+       unsigned long sum;
+       int i;
+
+       sum = 0;
+       for (i = 0; i < nr_range; i++)
+               sum += range[i].end + 1 - range[i].start;
+
+       return sum;
+}
+
+static int enable_mtrr_cleanup __initdata =
+       CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT;
+
+static int __init disable_mtrr_cleanup_setup(char *str)
+{
+       if (enable_mtrr_cleanup != -1)
+               enable_mtrr_cleanup = 0;
+       return 0;
+}
+early_param("disable_mtrr_cleanup", disable_mtrr_cleanup_setup);
+
+static int __init enable_mtrr_cleanup_setup(char *str)
+{
+       if (enable_mtrr_cleanup != -1)
+               enable_mtrr_cleanup = 1;
+       return 0;
+}
+early_param("enble_mtrr_cleanup", enable_mtrr_cleanup_setup);
+
+struct var_mtrr_state {
+       unsigned long   range_startk;
+       unsigned long   range_sizek;
+       unsigned long   chunk_sizek;
+       unsigned long   gran_sizek;
+       unsigned int    reg;
+};
+
+static void __init
+set_var_mtrr(unsigned int reg, unsigned long basek, unsigned long sizek,
+               unsigned char type, unsigned int address_bits)
+{
+       u32 base_lo, base_hi, mask_lo, mask_hi;
+       u64 base, mask;
+
+       if (!sizek) {
+               fill_mtrr_var_range(reg, 0, 0, 0, 0);
+               return;
+       }
+
+       mask = (1ULL << address_bits) - 1;
+       mask &= ~((((u64)sizek) << 10) - 1);
+
+       base  = ((u64)basek) << 10;
+
+       base |= type;
+       mask |= 0x800;
+
+       base_lo = base & ((1ULL<<32) - 1);
+       base_hi = base >> 32;
+
+       mask_lo = mask & ((1ULL<<32) - 1);
+       mask_hi = mask >> 32;
+
+       fill_mtrr_var_range(reg, base_lo, base_hi, mask_lo, mask_hi);
+}
+
+static void __init
+save_var_mtrr(unsigned int reg, unsigned long basek, unsigned long sizek,
+               unsigned char type)
+{
+       range_state[reg].base_pfn = basek >> (PAGE_SHIFT - 10);
+       range_state[reg].size_pfn = sizek >> (PAGE_SHIFT - 10);
+       range_state[reg].type = type;
+}
+
+static void __init
+set_var_mtrr_all(unsigned int address_bits)
+{
+       unsigned long basek, sizek;
+       unsigned char type;
+       unsigned int reg;
+
+       for (reg = 0; reg < num_var_ranges; reg++) {
+               basek = range_state[reg].base_pfn << (PAGE_SHIFT - 10);
+               sizek = range_state[reg].size_pfn << (PAGE_SHIFT - 10);
+               type = range_state[reg].type;
+
+               set_var_mtrr(reg, basek, sizek, type, address_bits);
+       }
+}
+
+static unsigned int __init
+range_to_mtrr(unsigned int reg, unsigned long range_startk,
+             unsigned long range_sizek, unsigned char type)
+{
+       if (!range_sizek || (reg >= num_var_ranges))
+               return reg;
+
+       while (range_sizek) {
+               unsigned long max_align, align;
+               unsigned long sizek;
+
+               /* Compute the maximum size I can make a range */
+               if (range_startk)
+                       max_align = ffs(range_startk) - 1;
+               else
+                       max_align = 32;
+               align = fls(range_sizek) - 1;
+               if (align > max_align)
+                       align = max_align;
+
+               sizek = 1 << align;
+               if (debug_print)
+                       printk(KERN_DEBUG "Setting variable MTRR %d, "
+                               "base: %ldMB, range: %ldMB, type %s\n",
+                               reg, range_startk >> 10, sizek >> 10,
+                               (type == MTRR_TYPE_UNCACHABLE)?"UC":
+                                   ((type == MTRR_TYPE_WRBACK)?"WB":"Other")
+                               );
+               save_var_mtrr(reg++, range_startk, sizek, type);
+               range_startk += sizek;
+               range_sizek -= sizek;
+               if (reg >= num_var_ranges)
+                       break;
+       }
+       return reg;
+}
+
+static unsigned __init
+range_to_mtrr_with_hole(struct var_mtrr_state *state, unsigned long basek,
+                       unsigned long sizek)
+{
+       unsigned long hole_basek, hole_sizek;
+       unsigned long second_basek, second_sizek;
+       unsigned long range0_basek, range0_sizek;
+       unsigned long range_basek, range_sizek;
+       unsigned long chunk_sizek;
+       unsigned long gran_sizek;
+
+       hole_basek = 0;
+       hole_sizek = 0;
+       second_basek = 0;
+       second_sizek = 0;
+       chunk_sizek = state->chunk_sizek;
+       gran_sizek = state->gran_sizek;
+
+       /* align with gran size, prevent small block used up MTRRs */
+       range_basek = ALIGN(state->range_startk, gran_sizek);
+       if ((range_basek > basek) && basek)
+               return second_sizek;
+       state->range_sizek -= (range_basek - state->range_startk);
+       range_sizek = ALIGN(state->range_sizek, gran_sizek);
+
+       while (range_sizek > state->range_sizek) {
+               range_sizek -= gran_sizek;
+               if (!range_sizek)
+                       return 0;
+       }
+       state->range_sizek = range_sizek;
+
+       /* try to append some small hole */
+       range0_basek = state->range_startk;
+       range0_sizek = ALIGN(state->range_sizek, chunk_sizek);
+       if (range0_sizek == state->range_sizek) {
+               if (debug_print)
+                       printk(KERN_DEBUG "rangeX: %016lx - %016lx\n",
+                               range0_basek<<10,
+                               (range0_basek + state->range_sizek)<<10);
+               state->reg = range_to_mtrr(state->reg, range0_basek,
+                               state->range_sizek, MTRR_TYPE_WRBACK);
+               return 0;
+       }
+
+       range0_sizek -= chunk_sizek;
+       if (range0_sizek && sizek) {
+           while (range0_basek + range0_sizek > (basek + sizek)) {
+               range0_sizek -= chunk_sizek;
+               if (!range0_sizek)
+                       break;
+           }
+       }
+
+       if (range0_sizek) {
+               if (debug_print)
+                       printk(KERN_DEBUG "range0: %016lx - %016lx\n",
+                               range0_basek<<10,
+                               (range0_basek + range0_sizek)<<10);
+               state->reg = range_to_mtrr(state->reg, range0_basek,
+                               range0_sizek, MTRR_TYPE_WRBACK);
+
+       }
+
+       range_basek = range0_basek + range0_sizek;
+       range_sizek = chunk_sizek;
+
+       if (range_basek + range_sizek > basek &&
+           range_basek + range_sizek <= (basek + sizek)) {
+               /* one hole */
+               second_basek = basek;
+               second_sizek = range_basek + range_sizek - basek;
+       }
+
+       /* if last piece, only could one hole near end */
+       if ((second_basek || !basek) &&
+           range_sizek - (state->range_sizek - range0_sizek) - second_sizek <
+           (chunk_sizek >> 1)) {
+               /*
+                * one hole in middle (second_sizek is 0) or at end
+                * (second_sizek is 0 )
+                */
+               hole_sizek = range_sizek - (state->range_sizek - range0_sizek)
+                                - second_sizek;
+               hole_basek = range_basek + range_sizek - hole_sizek
+                                - second_sizek;
+       } else {
+               /* fallback for big hole, or several holes */
+               range_sizek = state->range_sizek - range0_sizek;
+               second_basek = 0;
+               second_sizek = 0;
+       }
+
+       if (debug_print)
+               printk(KERN_DEBUG "range: %016lx - %016lx\n", range_basek<<10,
+                        (range_basek + range_sizek)<<10);
+       state->reg = range_to_mtrr(state->reg, range_basek, range_sizek,
+                                        MTRR_TYPE_WRBACK);
+       if (hole_sizek) {
+               if (debug_print)
+                       printk(KERN_DEBUG "hole: %016lx - %016lx\n",
+                                hole_basek<<10, (hole_basek + hole_sizek)<<10);
+               state->reg = range_to_mtrr(state->reg, hole_basek, hole_sizek,
+                                                MTRR_TYPE_UNCACHABLE);
+
+       }
+
+       return second_sizek;
+}
+
+static void __init
+set_var_mtrr_range(struct var_mtrr_state *state, unsigned long base_pfn,
+                  unsigned long size_pfn)
+{
+       unsigned long basek, sizek;
+       unsigned long second_sizek = 0;
+
+       if (state->reg >= num_var_ranges)
+               return;
+
+       basek = base_pfn << (PAGE_SHIFT - 10);
+       sizek = size_pfn << (PAGE_SHIFT - 10);
+
+       /* See if I can merge with the last range */
+       if ((basek <= 1024) ||
+           (state->range_startk + state->range_sizek == basek)) {
+               unsigned long endk = basek + sizek;
+               state->range_sizek = endk - state->range_startk;
+               return;
+       }
+       /* Write the range mtrrs */
+       if (state->range_sizek != 0)
+               second_sizek = range_to_mtrr_with_hole(state, basek, sizek);
+
+       /* Allocate an msr */
+       state->range_startk = basek + second_sizek;
+       state->range_sizek  = sizek - second_sizek;
+}
+
+/* mininum size of mtrr block that can take hole */
+static u64 mtrr_chunk_size __initdata = (256ULL<<20);
+
+static int __init parse_mtrr_chunk_size_opt(char *p)
+{
+       if (!p)
+               return -EINVAL;
+       mtrr_chunk_size = memparse(p, &p);
+       return 0;
+}
+early_param("mtrr_chunk_size", parse_mtrr_chunk_size_opt);
+
+/* granity of mtrr of block */
+static u64 mtrr_gran_size __initdata;
+
+static int __init parse_mtrr_gran_size_opt(char *p)
+{
+       if (!p)
+               return -EINVAL;
+       mtrr_gran_size = memparse(p, &p);
+       return 0;
+}
+early_param("mtrr_gran_size", parse_mtrr_gran_size_opt);
+
+static int nr_mtrr_spare_reg __initdata =
+                                CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT;
+
+static int __init parse_mtrr_spare_reg(char *arg)
+{
+       if (arg)
+               nr_mtrr_spare_reg = simple_strtoul(arg, NULL, 0);
+       return 0;
+}
+
+early_param("mtrr_spare_reg_nr", parse_mtrr_spare_reg);
+
+static int __init
+x86_setup_var_mtrrs(struct res_range *range, int nr_range,
+                   u64 chunk_size, u64 gran_size)
+{
+       struct var_mtrr_state var_state;
+       int i;
+       int num_reg;
+
+       var_state.range_startk  = 0;
+       var_state.range_sizek   = 0;
+       var_state.reg           = 0;
+       var_state.chunk_sizek   = chunk_size >> 10;
+       var_state.gran_sizek    = gran_size >> 10;
+
+       memset(range_state, 0, sizeof(range_state));
+
+       /* Write the range etc */
+       for (i = 0; i < nr_range; i++)
+               set_var_mtrr_range(&var_state, range[i].start,
+                                  range[i].end - range[i].start + 1);
+
+       /* Write the last range */
+       if (var_state.range_sizek != 0)
+               range_to_mtrr_with_hole(&var_state, 0, 0);
+
+       num_reg = var_state.reg;
+       /* Clear out the extra MTRR's */
+       while (var_state.reg < num_var_ranges) {
+               save_var_mtrr(var_state.reg, 0, 0, 0);
+               var_state.reg++;
+       }
+
+       return num_reg;
+}
+
+struct mtrr_cleanup_result {
+       unsigned long gran_sizek;
+       unsigned long chunk_sizek;
+       unsigned long lose_cover_sizek;
+       unsigned int num_reg;
+       int bad;
+};
+
+/*
+ * gran_size: 1M, 2M, ..., 2G
+ * chunk size: gran_size, ..., 4G
+ * so we need (2+13)*6
+ */
+#define NUM_RESULT     90
+#define PSHIFT         (PAGE_SHIFT - 10)
+
+static struct mtrr_cleanup_result __initdata result[NUM_RESULT];
+static struct res_range __initdata range_new[RANGE_NUM];
+static unsigned long __initdata min_loss_pfn[RANGE_NUM];
+
+static int __init mtrr_cleanup(unsigned address_bits)
+{
+       unsigned long extra_remove_base, extra_remove_size;
+       unsigned long i, base, size, def, dummy;
+       mtrr_type type;
+       int nr_range, nr_range_new;
+       u64 chunk_size, gran_size;
+       unsigned long range_sums, range_sums_new;
+       int index_good;
+       int num_reg_good;
+
+       /* extra one for all 0 */
+       int num[MTRR_NUM_TYPES + 1];
+
+       if (!is_cpu(INTEL) || enable_mtrr_cleanup < 1)
+               return 0;
+       rdmsr(MTRRdefType_MSR, def, dummy);
+       def &= 0xff;
+       if (def != MTRR_TYPE_UNCACHABLE)
+               return 0;
+
+       /* get it and store it aside */
+       memset(range_state, 0, sizeof(range_state));
+       for (i = 0; i < num_var_ranges; i++) {
+               mtrr_if->get(i, &base, &size, &type);
+               range_state[i].base_pfn = base;
+               range_state[i].size_pfn = size;
+               range_state[i].type = type;
+       }
+
+       /* check entries number */
+       memset(num, 0, sizeof(num));
+       for (i = 0; i < num_var_ranges; i++) {
+               type = range_state[i].type;
+               size = range_state[i].size_pfn;
+               if (type >= MTRR_NUM_TYPES)
+                       continue;
+               if (!size)
+                       type = MTRR_NUM_TYPES;
+               num[type]++;
+       }
+
+       /* check if we got UC entries */
+       if (!num[MTRR_TYPE_UNCACHABLE])
+               return 0;
+
+       /* check if we only had WB and UC */
+       if (num[MTRR_TYPE_WRBACK] + num[MTRR_TYPE_UNCACHABLE] !=
+               num_var_ranges - num[MTRR_NUM_TYPES])
+               return 0;
+
+       memset(range, 0, sizeof(range));
+       extra_remove_size = 0;
+       if (mtrr_tom2) {
+               extra_remove_base = 1 << (32 - PAGE_SHIFT);
+               extra_remove_size =
+                       (mtrr_tom2 >> PAGE_SHIFT) - extra_remove_base;
+       }
+       nr_range = x86_get_mtrr_mem_range(range, 0, extra_remove_base,
+                                         extra_remove_size);
+       range_sums = sum_ranges(range, nr_range);
+       printk(KERN_INFO "total RAM coverred: %ldM\n",
+              range_sums >> (20 - PAGE_SHIFT));
+
+       if (mtrr_chunk_size && mtrr_gran_size) {
+               int num_reg;
+
+               debug_print = 1;
+               /* convert ranges to var ranges state */
+               num_reg = x86_setup_var_mtrrs(range, nr_range, mtrr_chunk_size,
+                                             mtrr_gran_size);
+
+               /* we got new setting in range_state, check it */
+               memset(range_new, 0, sizeof(range_new));
+               nr_range_new = x86_get_mtrr_mem_range(range_new, 0,
+                                                     extra_remove_base,
+                                                     extra_remove_size);
+               range_sums_new = sum_ranges(range_new, nr_range_new);
+
+               i = 0;
+               result[i].chunk_sizek = mtrr_chunk_size >> 10;
+               result[i].gran_sizek = mtrr_gran_size >> 10;
+               result[i].num_reg = num_reg;
+               if (range_sums < range_sums_new) {
+                       result[i].lose_cover_sizek =
+                               (range_sums_new - range_sums) << PSHIFT;
+                       result[i].bad = 1;
+               } else
+                       result[i].lose_cover_sizek =
+                               (range_sums - range_sums_new) << PSHIFT;
+
+               printk(KERN_INFO "%sgran_size: %ldM \tchunk_size: %ldM \t",
+                        result[i].bad?"*BAD*":" ", result[i].gran_sizek >> 10,
+                        result[i].chunk_sizek >> 10);
+               printk(KERN_CONT "num_reg: %d  \tlose cover RAM: %s%ldM \n",
+                        result[i].num_reg, result[i].bad?"-":"",
+                        result[i].lose_cover_sizek >> 10);
+               if (!result[i].bad) {
+                       set_var_mtrr_all(address_bits);
+                       return 1;
+               }
+               printk(KERN_INFO "invalid mtrr_gran_size or mtrr_chunk_size, "
+                      "will find optimal one\n");
+               debug_print = 0;
+               memset(result, 0, sizeof(result[0]));
+       }
+
+       i = 0;
+       memset(min_loss_pfn, 0xff, sizeof(min_loss_pfn));
+       memset(result, 0, sizeof(result));
+       for (gran_size = (1ULL<<20); gran_size < (1ULL<<32); gran_size <<= 1) {
+               for (chunk_size = gran_size; chunk_size < (1ULL<<33);
+                    chunk_size <<= 1) {
+                       int num_reg;
+
+                       if (debug_print)
+                               printk(KERN_INFO
+                              "\ngran_size: %lldM   chunk_size_size: %lldM\n",
+                                      gran_size >> 20, chunk_size >> 20);
+                       if (i >= NUM_RESULT)
+                               continue;
+
+                       /* convert ranges to var ranges state */
+                       num_reg = x86_setup_var_mtrrs(range, nr_range,
+                                                        chunk_size, gran_size);
+
+                       /* we got new setting in range_state, check it */
+                       memset(range_new, 0, sizeof(range_new));
+                       nr_range_new = x86_get_mtrr_mem_range(range_new, 0,
+                                        extra_remove_base, extra_remove_size);
+                       range_sums_new = sum_ranges(range_new, nr_range_new);
+
+                       result[i].chunk_sizek = chunk_size >> 10;
+                       result[i].gran_sizek = gran_size >> 10;
+                       result[i].num_reg = num_reg;
+                       if (range_sums < range_sums_new) {
+                               result[i].lose_cover_sizek =
+                                       (range_sums_new - range_sums) << PSHIFT;
+                               result[i].bad = 1;
+                       } else
+                               result[i].lose_cover_sizek =
+                                       (range_sums - range_sums_new) << PSHIFT;
+
+                       /* double check it */
+                       if (!result[i].bad && !result[i].lose_cover_sizek) {
+                               if (nr_range_new != nr_range ||
+                                       memcmp(range, range_new, sizeof(range)))
+                                               result[i].bad = 1;
+                       }
+
+                       if (!result[i].bad && (range_sums - range_sums_new <
+                                              min_loss_pfn[num_reg])) {
+                               min_loss_pfn[num_reg] =
+                                       range_sums - range_sums_new;
+                       }
+                       i++;
+               }
+       }
+
+       /* print out all */
+       for (i = 0; i < NUM_RESULT; i++) {
+               printk(KERN_INFO "%sgran_size: %ldM \tchunk_size: %ldM \t",
+                      result[i].bad?"*BAD* ":" ", result[i].gran_sizek >> 10,
+                      result[i].chunk_sizek >> 10);
+               printk(KERN_CONT "num_reg: %d \tlose RAM: %s%ldM\n",
+                      result[i].num_reg, result[i].bad?"-":"",
+                      result[i].lose_cover_sizek >> 10);
+       }
+
+       /* try to find the optimal index */
+       if (nr_mtrr_spare_reg >= num_var_ranges)
+               nr_mtrr_spare_reg = num_var_ranges - 1;
+       num_reg_good = -1;
+       for (i = num_var_ranges - nr_mtrr_spare_reg; i > 0; i--) {
+               if (!min_loss_pfn[i]) {
+                       num_reg_good = i;
+                       break;
+               }
+       }
+
+       index_good = -1;
+       if (num_reg_good != -1) {
+               for (i = 0; i < NUM_RESULT; i++) {
+                       if (!result[i].bad &&
+                           result[i].num_reg == num_reg_good &&
+                           !result[i].lose_cover_sizek) {
+                               index_good = i;
+                               break;
+                       }
+               }
+       }
+
+       if (index_good != -1) {
+               printk(KERN_INFO "Found optimal setting for mtrr clean up\n");
+               i = index_good;
+               printk(KERN_INFO "gran_size: %ldM \tchunk_size: %ldM \t",
+                               result[i].gran_sizek >> 10,
+                               result[i].chunk_sizek >> 10);
+               printk(KERN_CONT "num_reg: %d \tlose RAM: %ldM\n",
+                               result[i].num_reg,
+                               result[i].lose_cover_sizek >> 10);
+               /* convert ranges to var ranges state */
+               chunk_size = result[i].chunk_sizek;
+               chunk_size <<= 10;
+               gran_size = result[i].gran_sizek;
+               gran_size <<= 10;
+               debug_print = 1;
+               x86_setup_var_mtrrs(range, nr_range, chunk_size, gran_size);
+               set_var_mtrr_all(address_bits);
+               return 1;
+       }
+
+       printk(KERN_INFO "mtrr_cleanup: can not find optimal value\n");
+       printk(KERN_INFO "please specify mtrr_gran_size/mtrr_chunk_size\n");
+
+       return 0;
+}
+#else
+static int __init mtrr_cleanup(unsigned address_bits)
+{
+       return 0;
+}
+#endif
+
+static int __initdata changed_by_mtrr_cleanup;
+
 static int disable_mtrr_trim;
 
 static int __init disable_mtrr_trim_setup(char *str)
@@ -648,6 +1430,19 @@ int __init amd_special_default_mtrr(void)
        return 0;
 }
 
+static u64 __init real_trim_memory(unsigned long start_pfn,
+                                  unsigned long limit_pfn)
+{
+       u64 trim_start, trim_size;
+       trim_start = start_pfn;
+       trim_start <<= PAGE_SHIFT;
+       trim_size = limit_pfn;
+       trim_size <<= PAGE_SHIFT;
+       trim_size -= trim_start;
+
+       return e820_update_range(trim_start, trim_size, E820_RAM,
+                               E820_RESERVED);
+}
 /**
  * mtrr_trim_uncached_memory - trim RAM not covered by MTRRs
  * @end_pfn: ending page frame number
@@ -663,8 +1458,11 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 {
        unsigned long i, base, size, highest_pfn = 0, def, dummy;
        mtrr_type type;
-       u64 trim_start, trim_size;
+       int nr_range;
+       u64 total_trim_size;
 
+       /* extra one for all 0 */
+       int num[MTRR_NUM_TYPES + 1];
        /*
         * Make sure we only trim uncachable memory on machines that
         * support the Intel MTRR architecture:
@@ -676,14 +1474,22 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
        if (def != MTRR_TYPE_UNCACHABLE)
                return 0;
 
-       if (amd_special_default_mtrr())
-               return 0;
+       /* get it and store it aside */
+       memset(range_state, 0, sizeof(range_state));
+       for (i = 0; i < num_var_ranges; i++) {
+               mtrr_if->get(i, &base, &size, &type);
+               range_state[i].base_pfn = base;
+               range_state[i].size_pfn = size;
+               range_state[i].type = type;
+       }
 
        /* Find highest cached pfn */
        for (i = 0; i < num_var_ranges; i++) {
-               mtrr_if->get(i, &base, &size, &type);
+               type = range_state[i].type;
                if (type != MTRR_TYPE_WRBACK)
                        continue;
+               base = range_state[i].base_pfn;
+               size = range_state[i].size_pfn;
                if (highest_pfn < base + size)
                        highest_pfn = base + size;
        }
@@ -698,22 +1504,65 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
                return 0;
        }
 
-       if (highest_pfn < end_pfn) {
+       /* check entries number */
+       memset(num, 0, sizeof(num));
+       for (i = 0; i < num_var_ranges; i++) {
+               type = range_state[i].type;
+               if (type >= MTRR_NUM_TYPES)
+                       continue;
+               size = range_state[i].size_pfn;
+               if (!size)
+                       type = MTRR_NUM_TYPES;
+               num[type]++;
+       }
+
+       /* no entry for WB? */
+       if (!num[MTRR_TYPE_WRBACK])
+               return 0;
+
+       /* check if we only had WB and UC */
+       if (num[MTRR_TYPE_WRBACK] + num[MTRR_TYPE_UNCACHABLE] !=
+               num_var_ranges - num[MTRR_NUM_TYPES])
+               return 0;
+
+       memset(range, 0, sizeof(range));
+       nr_range = 0;
+       if (mtrr_tom2) {
+               range[nr_range].start = (1ULL<<(32 - PAGE_SHIFT));
+               range[nr_range].end = (mtrr_tom2 >> PAGE_SHIFT) - 1;
+               if (highest_pfn < range[nr_range].end + 1)
+                       highest_pfn = range[nr_range].end + 1;
+               nr_range++;
+       }
+       nr_range = x86_get_mtrr_mem_range(range, nr_range, 0, 0);
+
+       total_trim_size = 0;
+       /* check the head */
+       if (range[0].start)
+               total_trim_size += real_trim_memory(0, range[0].start);
+       /* check the holes */
+       for (i = 0; i < nr_range - 1; i++) {
+               if (range[i].end + 1 < range[i+1].start)
+                       total_trim_size += real_trim_memory(range[i].end + 1,
+                                                           range[i+1].start);
+       }
+       /* check the top */
+       i = nr_range - 1;
+       if (range[i].end + 1 < end_pfn)
+               total_trim_size += real_trim_memory(range[i].end + 1,
+                                                        end_pfn);
+
+       if (total_trim_size) {
                printk(KERN_WARNING "WARNING: BIOS bug: CPU MTRRs don't cover"
-                       " all of memory, losing %luMB of RAM.\n",
-                       (end_pfn - highest_pfn) >> (20 - PAGE_SHIFT));
+                       " all of memory, losing %lluMB of RAM.\n",
+                       total_trim_size >> 20);
 
-               WARN_ON(1);
+               if (!changed_by_mtrr_cleanup)
+                       WARN_ON(1);
 
                printk(KERN_INFO "update e820 for mtrr\n");
-               trim_start = highest_pfn;
-               trim_start <<= PAGE_SHIFT;
-               trim_size = end_pfn;
-               trim_size <<= PAGE_SHIFT;
-               trim_size -= trim_start;
-               update_memory_range(trim_start, trim_size, E820_RAM,
-                                       E820_RESERVED);
                update_e820();
+
                return 1;
        }
 
@@ -729,18 +1578,21 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
  */
 void __init mtrr_bp_init(void)
 {
+       u32 phys_addr;
        init_ifs();
 
+       phys_addr = 32;
+
        if (cpu_has_mtrr) {
                mtrr_if = &generic_mtrr_ops;
                size_or_mask = 0xff000000;      /* 36 bits */
                size_and_mask = 0x00f00000;
+               phys_addr = 36;
 
                /* This is an AMD specific MSR, but we assume(hope?) that
                   Intel will implement it to when they extend the address
                   bus of the Xeon. */
                if (cpuid_eax(0x80000000) >= 0x80000008) {
-                       u32 phys_addr;
                        phys_addr = cpuid_eax(0x80000008) & 0xff;
                        /* CPUID workaround for Intel 0F33/0F34 CPU */
                        if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
@@ -758,6 +1610,7 @@ void __init mtrr_bp_init(void)
                           don't support PAE */
                        size_or_mask = 0xfff00000;      /* 32 bits */
                        size_and_mask = 0;
+                       phys_addr = 32;
                }
        } else {
                switch (boot_cpu_data.x86_vendor) {
@@ -791,8 +1644,15 @@ void __init mtrr_bp_init(void)
        if (mtrr_if) {
                set_num_var_ranges();
                init_table();
-               if (use_intel())
+               if (use_intel()) {
                        get_mtrr_state();
+
+                       if (mtrr_cleanup(phys_addr)) {
+                               changed_by_mtrr_cleanup = 1;
+                               mtrr_if->set_all();
+                       }
+
+               }
        }
 }
 
@@ -829,9 +1689,10 @@ static int __init mtrr_init_finialize(void)
 {
        if (!mtrr_if)
                return 0;
-       if (use_intel())
-               mtrr_state_warn();
-       else {
+       if (use_intel()) {
+               if (!changed_by_mtrr_cleanup)
+                       mtrr_state_warn();
+       } else {
                /* The CPUs haven't MTRR and seem to not support SMP. They have
                 * specific drivers, we use a tricky method to support
                 * suspend/resume for them.
index 2cc77eb..2dc4ec6 100644 (file)
@@ -81,6 +81,8 @@ void set_mtrr_done(struct set_mtrr_context *ctxt);
 void set_mtrr_cache_disable(struct set_mtrr_context *ctxt);
 void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
 
+void fill_mtrr_var_range(unsigned int index,
+               u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
 void get_mtrr_state(void);
 
 extern void set_mtrr_ops(struct mtrr_ops * ops);
@@ -92,6 +94,7 @@ extern struct mtrr_ops * mtrr_if;
 #define use_intel()    (mtrr_if && mtrr_if->use_intel_if == 1)
 
 extern unsigned int num_var_ranges;
+extern u64 mtrr_tom2;
 
 void mtrr_state_warn(void);
 const char *mtrr_attrib_to_str(int x);
index f9ae93a..2e9bef6 100644 (file)
@@ -1,11 +1,15 @@
-/* local apic based NMI watchdog for various CPUs.
-   This file also handles reservation of performance counters for coordination
-   with other users (like oprofile).
-
-   Note that these events normally don't tick when the CPU idles. This means
-   the frequency varies with CPU load.
-
-   Original code for K7/P6 written by Keith Owens */
+/*
+ * local apic based NMI watchdog for various CPUs.
+ *
+ * This file also handles reservation of performance counters for coordination
+ * with other users (like oprofile).
+ *
+ * Note that these events normally don't tick when the CPU idles. This means
+ * the frequency varies with CPU load.
+ *
+ * Original code for K7/P6 written by Keith Owens
+ *
+ */
 
 #include <linux/percpu.h>
 #include <linux/module.h>
@@ -36,12 +40,16 @@ struct wd_ops {
 
 static const struct wd_ops *wd_ops;
 
-/* this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's
- * offset from MSR_P4_BSU_ESCR0.  It will be the max for all platforms (for now)
+/*
+ * this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's
+ * offset from MSR_P4_BSU_ESCR0.
+ *
+ * It will be the max for all platforms (for now)
  */
 #define NMI_MAX_COUNTER_BITS 66
 
-/* perfctr_nmi_owner tracks the ownership of the perfctr registers:
+/*
+ * perfctr_nmi_owner tracks the ownership of the perfctr registers:
  * evtsel_nmi_owner tracks the ownership of the event selection
  * - different performance counters/ event selection may be reserved for
  *   different subsystems this reservation system just tries to coordinate
@@ -73,8 +81,10 @@ static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr)
        return 0;
 }
 
-/* converts an msr to an appropriate reservation bit */
-/* returns the bit offset of the event selection register */
+/*
+ * converts an msr to an appropriate reservation bit
+ * returns the bit offset of the event selection register
+ */
 static inline unsigned int nmi_evntsel_msr_to_bit(unsigned int msr)
 {
        /* returns the bit offset of the event selection register */
@@ -114,6 +124,7 @@ int avail_to_resrv_perfctr_nmi(unsigned int msr)
 
        return (!test_bit(counter, perfctr_nmi_owner));
 }
+EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi_bit);
 
 int reserve_perfctr_nmi(unsigned int msr)
 {
@@ -128,6 +139,7 @@ int reserve_perfctr_nmi(unsigned int msr)
                return 1;
        return 0;
 }
+EXPORT_SYMBOL(reserve_perfctr_nmi);
 
 void release_perfctr_nmi(unsigned int msr)
 {
@@ -140,6 +152,7 @@ void release_perfctr_nmi(unsigned int msr)
 
        clear_bit(counter, perfctr_nmi_owner);
 }
+EXPORT_SYMBOL(release_perfctr_nmi);
 
 int reserve_evntsel_nmi(unsigned int msr)
 {
@@ -154,6 +167,7 @@ int reserve_evntsel_nmi(unsigned int msr)
                return 1;
        return 0;
 }
+EXPORT_SYMBOL(reserve_evntsel_nmi);
 
 void release_evntsel_nmi(unsigned int msr)
 {
@@ -166,11 +180,6 @@ void release_evntsel_nmi(unsigned int msr)
 
        clear_bit(counter, evntsel_nmi_owner);
 }
-
-EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi_bit);
-EXPORT_SYMBOL(reserve_perfctr_nmi);
-EXPORT_SYMBOL(release_perfctr_nmi);
-EXPORT_SYMBOL(reserve_evntsel_nmi);
 EXPORT_SYMBOL(release_evntsel_nmi);
 
 void disable_lapic_nmi_watchdog(void)
@@ -181,7 +190,9 @@ void disable_lapic_nmi_watchdog(void)
                return;
 
        on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1);
-       wd_ops->unreserve();
+
+       if (wd_ops)
+               wd_ops->unreserve();
 
        BUG_ON(atomic_read(&nmi_active) != 0);
 }
@@ -232,8 +243,8 @@ static unsigned int adjust_for_32bit_ctr(unsigned int hz)
        return retval;
 }
 
-static void
-write_watchdog_counter(unsigned int perfctr_msr, const char *descr, unsigned nmi_hz)
+static void write_watchdog_counter(unsigned int perfctr_msr,
+                               const char *descr, unsigned nmi_hz)
 {
        u64 count = (u64)cpu_khz * 1000;
 
@@ -244,7 +255,7 @@ write_watchdog_counter(unsigned int perfctr_msr, const char *descr, unsigned nmi
 }
 
 static void write_watchdog_counter32(unsigned int perfctr_msr,
-               const char *descr, unsigned nmi_hz)
+                               const char *descr, unsigned nmi_hz)
 {
        u64 count = (u64)cpu_khz * 1000;
 
@@ -254,9 +265,10 @@ static void write_watchdog_counter32(unsigned int perfctr_msr,
        wrmsr(perfctr_msr, (u32)(-count), 0);
 }
 
-/* AMD K7/K8/Family10h/Family11h support. AMD keeps this interface
-   nicely stable so there is not much variety */
-
+/*
+ * AMD K7/K8/Family10h/Family11h support.
+ * AMD keeps this interface nicely stable so there is not much variety
+ */
 #define K7_EVNTSEL_ENABLE      (1 << 22)
 #define K7_EVNTSEL_INT         (1 << 20)
 #define K7_EVNTSEL_OS          (1 << 17)
@@ -289,7 +301,7 @@ static int setup_k7_watchdog(unsigned nmi_hz)
 
        wd->perfctr_msr = perfctr_msr;
        wd->evntsel_msr = evntsel_msr;
-       wd->cccr_msr = 0;  //unused
+       wd->cccr_msr = 0;  /* unused */
        return 1;
 }
 
@@ -325,18 +337,19 @@ static void single_msr_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz)
 }
 
 static const struct wd_ops k7_wd_ops = {
-       .reserve = single_msr_reserve,
-       .unreserve = single_msr_unreserve,
-       .setup = setup_k7_watchdog,
-       .rearm = single_msr_rearm,
-       .stop = single_msr_stop_watchdog,
-       .perfctr = MSR_K7_PERFCTR0,
-       .evntsel = MSR_K7_EVNTSEL0,
-       .checkbit = 1ULL<<47,
+       .reserve        = single_msr_reserve,
+       .unreserve      = single_msr_unreserve,
+       .setup          = setup_k7_watchdog,
+       .rearm          = single_msr_rearm,
+       .stop           = single_msr_stop_watchdog,
+       .perfctr        = MSR_K7_PERFCTR0,
+       .evntsel        = MSR_K7_EVNTSEL0,
+       .checkbit       = 1ULL << 47,
 };
 
-/* Intel Model 6 (PPro+,P2,P3,P-M,Core1) */
-
+/*
+ * Intel Model 6 (PPro+,P2,P3,P-M,Core1)
+ */
 #define P6_EVNTSEL0_ENABLE     (1 << 22)
 #define P6_EVNTSEL_INT         (1 << 20)
 #define P6_EVNTSEL_OS          (1 << 17)
@@ -372,52 +385,58 @@ static int setup_p6_watchdog(unsigned nmi_hz)
 
        wd->perfctr_msr = perfctr_msr;
        wd->evntsel_msr = evntsel_msr;
-       wd->cccr_msr = 0;  //unused
+       wd->cccr_msr = 0;  /* unused */
        return 1;
 }
 
 static void p6_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz)
 {
-       /* P6 based Pentium M need to re-unmask
+       /*
+        * P6 based Pentium M need to re-unmask
         * the apic vector but it doesn't hurt
         * other P6 variant.
-        * ArchPerfom/Core Duo also needs this */
+        * ArchPerfom/Core Duo also needs this
+        */
        apic_write(APIC_LVTPC, APIC_DM_NMI);
+
        /* P6/ARCH_PERFMON has 32 bit counter write */
        write_watchdog_counter32(wd->perfctr_msr, NULL,nmi_hz);
 }
 
 static const struct wd_ops p6_wd_ops = {
-       .reserve = single_msr_reserve,
-       .unreserve = single_msr_unreserve,
-       .setup = setup_p6_watchdog,
-       .rearm = p6_rearm,
-       .stop = single_msr_stop_watchdog,
-       .perfctr = MSR_P6_PERFCTR0,
-       .evntsel = MSR_P6_EVNTSEL0,
-       .checkbit = 1ULL<<39,
+       .reserve        = single_msr_reserve,
+       .unreserve      = single_msr_unreserve,
+       .setup          = setup_p6_watchdog,
+       .rearm          = p6_rearm,
+       .stop           = single_msr_stop_watchdog,
+       .perfctr        = MSR_P6_PERFCTR0,
+       .evntsel        = MSR_P6_EVNTSEL0,
+       .checkbit       = 1ULL << 39,
 };
 
-/* Intel P4 performance counters. By far the most complicated of all. */
-
-#define MSR_P4_MISC_ENABLE_PERF_AVAIL  (1<<7)
-#define P4_ESCR_EVENT_SELECT(N)        ((N)<<25)
-#define P4_ESCR_OS             (1<<3)
-#define P4_ESCR_USR            (1<<2)
-#define P4_CCCR_OVF_PMI0       (1<<26)
-#define P4_CCCR_OVF_PMI1       (1<<27)
-#define P4_CCCR_THRESHOLD(N)   ((N)<<20)
-#define P4_CCCR_COMPLEMENT     (1<<19)
-#define P4_CCCR_COMPARE                (1<<18)
-#define P4_CCCR_REQUIRED       (3<<16)
-#define P4_CCCR_ESCR_SELECT(N) ((N)<<13)
-#define P4_CCCR_ENABLE         (1<<12)
-#define P4_CCCR_OVF            (1<<31)
-
-/* Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter
-   CRU_ESCR0 (with any non-null event selector) through a complemented
-   max threshold. [IA32-Vol3, Section 14.9.9] */
+/*
+ * Intel P4 performance counters.
+ * By far the most complicated of all.
+ */
+#define MSR_P4_MISC_ENABLE_PERF_AVAIL  (1 << 7)
+#define P4_ESCR_EVENT_SELECT(N)        ((N) << 25)
+#define P4_ESCR_OS             (1 << 3)
+#define P4_ESCR_USR            (1 << 2)
+#define P4_CCCR_OVF_PMI0       (1 << 26)
+#define P4_CCCR_OVF_PMI1       (1 << 27)
+#define P4_CCCR_THRESHOLD(N)   ((N) << 20)
+#define P4_CCCR_COMPLEMENT     (1 << 19)
+#define P4_CCCR_COMPARE                (1 << 18)
+#define P4_CCCR_REQUIRED       (3 << 16)
+#define P4_CCCR_ESCR_SELECT(N) ((N) << 13)
+#define P4_CCCR_ENABLE         (1 << 12)
+#define P4_CCCR_OVF            (1 << 31)
 
+/*
+ * Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter
+ * CRU_ESCR0 (with any non-null event selector) through a complemented
+ * max threshold. [IA32-Vol3, Section 14.9.9]
+ */
 static int setup_p4_watchdog(unsigned nmi_hz)
 {
        unsigned int perfctr_msr, evntsel_msr, cccr_msr;
@@ -442,7 +461,8 @@ static int setup_p4_watchdog(unsigned nmi_hz)
 #endif
                ht_num = 0;
 
-       /* performance counters are shared resources
+       /*
+        * performance counters are shared resources
         * assign each hyperthread its own set
         * (re-use the ESCR0 register, seems safe
         * and keeps the cccr_val the same)
@@ -540,20 +560,21 @@ static void p4_rearm(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz)
 }
 
 static const struct wd_ops p4_wd_ops = {
-       .reserve = p4_reserve,
-       .unreserve = p4_unreserve,
-       .setup = setup_p4_watchdog,
-       .rearm = p4_rearm,
-       .stop = stop_p4_watchdog,
+       .reserve        = p4_reserve,
+       .unreserve      = p4_unreserve,
+       .setup          = setup_p4_watchdog,
+       .rearm          = p4_rearm,
+       .stop           = stop_p4_watchdog,
        /* RED-PEN this is wrong for the other sibling */
-       .perfctr = MSR_P4_BPU_PERFCTR0,
-       .evntsel = MSR_P4_BSU_ESCR0,
-       .checkbit = 1ULL<<39,
+       .perfctr        = MSR_P4_BPU_PERFCTR0,
+       .evntsel        = MSR_P4_BSU_ESCR0,
+       .checkbit       = 1ULL << 39,
 };
 
-/* Watchdog using the Intel architected PerfMon. Used for Core2 and hopefully
-   all future Intel CPUs. */
-
+/*
+ * Watchdog using the Intel architected PerfMon.
+ * Used for Core2 and hopefully all future Intel CPUs.
+ */
 #define ARCH_PERFMON_NMI_EVENT_SEL     ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
 #define ARCH_PERFMON_NMI_EVENT_UMASK   ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
 
@@ -599,19 +620,19 @@ static int setup_intel_arch_watchdog(unsigned nmi_hz)
 
        wd->perfctr_msr = perfctr_msr;
        wd->evntsel_msr = evntsel_msr;
-       wd->cccr_msr = 0;  //unused
+       wd->cccr_msr = 0;  /* unused */
        intel_arch_wd_ops.checkbit = 1ULL << (eax.split.bit_width - 1);
        return 1;
 }
 
 static struct wd_ops intel_arch_wd_ops __read_mostly = {
-       .reserve = single_msr_reserve,
-       .unreserve = single_msr_unreserve,
-       .setup = setup_intel_arch_watchdog,
-       .rearm = p6_rearm,
-       .stop = single_msr_stop_watchdog,
-       .perfctr = MSR_ARCH_PERFMON_PERFCTR1,
-       .evntsel = MSR_ARCH_PERFMON_EVENTSEL1,
+       .reserve        = single_msr_reserve,
+       .unreserve      = single_msr_unreserve,
+       .setup          = setup_intel_arch_watchdog,
+       .rearm          = p6_rearm,
+       .stop           = single_msr_stop_watchdog,
+       .perfctr        = MSR_ARCH_PERFMON_PERFCTR1,
+       .evntsel        = MSR_ARCH_PERFMON_EVENTSEL1,
 };
 
 static void probe_nmi_watchdog(void)
@@ -624,8 +645,10 @@ static void probe_nmi_watchdog(void)
                wd_ops = &k7_wd_ops;
                break;
        case X86_VENDOR_INTEL:
-               /* Work around Core Duo (Yonah) errata AE49 where perfctr1
-                  doesn't have a working enable bit. */
+               /*
+                * Work around Core Duo (Yonah) errata AE49 where perfctr1
+                * doesn't have a working enable bit.
+                */
                if (boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 14) {
                        intel_arch_wd_ops.perfctr = MSR_ARCH_PERFMON_PERFCTR0;
                        intel_arch_wd_ops.evntsel = MSR_ARCH_PERFMON_EVENTSEL0;
@@ -636,7 +659,7 @@ static void probe_nmi_watchdog(void)
                }
                switch (boot_cpu_data.x86) {
                case 6:
-                       if (boot_cpu_data.x86_model > 0xd)
+                       if (boot_cpu_data.x86_model > 13)
                                return;
 
                        wd_ops = &p6_wd_ops;
@@ -697,10 +720,11 @@ int lapic_wd_event(unsigned nmi_hz)
 {
        struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
        u64 ctr;
+
        rdmsrl(wd->perfctr_msr, ctr);
-       if (ctr & wd_ops->checkbit) /* perfctr still running? */
+       if (ctr & wd_ops->checkbit) /* perfctr still running? */
                return 0;
-       }
+
        wd_ops->rearm(wd, nmi_hz);
        return 1;
 }
index daff52a..71f1c26 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/init.h>
 #include <linux/poll.h>
 #include <linux/smp.h>
+#include <linux/smp_lock.h>
 #include <linux/major.h>
 #include <linux/fs.h>
 #include <linux/smp_lock.h>
@@ -107,15 +108,23 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
 
 static int cpuid_open(struct inode *inode, struct file *file)
 {
-       unsigned int cpu = iminor(file->f_path.dentry->d_inode);
-       struct cpuinfo_x86 *c = &cpu_data(cpu);
-
-       if (cpu >= NR_CPUS || !cpu_online(cpu))
-               return -ENXIO;  /* No such CPU */
+       unsigned int cpu;
+       struct cpuinfo_x86 *c;
+       int ret = 0;
+       
+       lock_kernel();
+
+       cpu = iminor(file->f_path.dentry->d_inode);
+       if (cpu >= NR_CPUS || !cpu_online(cpu)) {
+               ret = -ENXIO;   /* No such CPU */
+               goto out;
+       }
+       c = &cpu_data(cpu);
        if (c->cpuid_level < 0)
-               return -EIO;    /* CPUID not supported */
-
-       return 0;
+               ret = -EIO;     /* CPUID not supported */
+out:
+       unlock_kernel();
+       return ret;
 }
 
 /*
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
new file mode 100644 (file)
index 0000000..28c2918
--- /dev/null
@@ -0,0 +1,1390 @@
+/*
+ * Handle the memory map.
+ * The functions here do the job until bootmem takes over.
+ *
+ *  Getting sanitize_e820_map() in sync with i386 version by applying change:
+ *  -  Provisions for empty E820 memory regions (reported by certain BIOSes).
+ *     Alex Achenbach <xela@slit.de>, December 2002.
+ *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/ioport.h>
+#include <linux/string.h>
+#include <linux/kexec.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/pfn.h>
+#include <linux/suspend.h>
+#include <linux/firmware-map.h>
+
+#include <asm/pgtable.h>
+#include <asm/page.h>
+#include <asm/e820.h>
+#include <asm/proto.h>
+#include <asm/setup.h>
+#include <asm/trampoline.h>
+
+/*
+ * The e820 map is the map that gets modified e.g. with command line parameters
+ * and that is also registered with modifications in the kernel resource tree
+ * with the iomem_resource as parent.
+ *
+ * The e820_saved is directly saved after the BIOS-provided memory map is
+ * copied. It doesn't get modified afterwards. It's registered for the
+ * /sys/firmware/memmap interface.
+ *
+ * That memory map is not modified and is used as base for kexec. The kexec'd
+ * kernel should get the same memory map as the firmware provides. Then the
+ * user can e.g. boot the original kernel with mem=1G while still booting the
+ * next kernel with full memory.
+ */
+struct e820map e820;
+struct e820map e820_saved;
+
+/* For PCI or other memory-mapped resources */
+unsigned long pci_mem_start = 0xaeedbabe;
+#ifdef CONFIG_PCI
+EXPORT_SYMBOL(pci_mem_start);
+#endif
+
+/*
+ * This function checks if any part of the range <start,end> is mapped
+ * with type.
+ */
+int
+e820_any_mapped(u64 start, u64 end, unsigned type)
+{
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+
+               if (type && ei->type != type)
+                       continue;
+               if (ei->addr >= end || ei->addr + ei->size <= start)
+                       continue;
+               return 1;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(e820_any_mapped);
+
+/*
+ * This function checks if the entire range <start,end> is mapped with type.
+ *
+ * Note: this function only works correct if the e820 table is sorted and
+ * not-overlapping, which is the case
+ */
+int __init e820_all_mapped(u64 start, u64 end, unsigned type)
+{
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+
+               if (type && ei->type != type)
+                       continue;
+               /* is the region (part) in overlap with the current region ?*/
+               if (ei->addr >= end || ei->addr + ei->size <= start)
+                       continue;
+
+               /* if the region is at the beginning of <start,end> we move
+                * start to the end of the region since it's ok until there
+                */
+               if (ei->addr <= start)
+                       start = ei->addr + ei->size;
+               /*
+                * if start is now at or beyond end, we're done, full
+                * coverage
+                */
+               if (start >= end)
+                       return 1;
+       }
+       return 0;
+}
+
+/*
+ * Add a memory region to the kernel e820 map.
+ */
+void __init e820_add_region(u64 start, u64 size, int type)
+{
+       int x = e820.nr_map;
+
+       if (x == ARRAY_SIZE(e820.map)) {
+               printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
+               return;
+       }
+
+       e820.map[x].addr = start;
+       e820.map[x].size = size;
+       e820.map[x].type = type;
+       e820.nr_map++;
+}
+
+void __init e820_print_map(char *who)
+{
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
+                      (unsigned long long) e820.map[i].addr,
+                      (unsigned long long)
+                      (e820.map[i].addr + e820.map[i].size));
+               switch (e820.map[i].type) {
+               case E820_RAM:
+               case E820_RESERVED_KERN:
+                       printk(KERN_CONT "(usable)\n");
+                       break;
+               case E820_RESERVED:
+                       printk(KERN_CONT "(reserved)\n");
+                       break;
+               case E820_ACPI:
+                       printk(KERN_CONT "(ACPI data)\n");
+                       break;
+               case E820_NVS:
+                       printk(KERN_CONT "(ACPI NVS)\n");
+                       break;
+               default:
+                       printk(KERN_CONT "type %u\n", e820.map[i].type);
+                       break;
+               }
+       }
+}
+
+/*
+ * Sanitize the BIOS e820 map.
+ *
+ * Some e820 responses include overlapping entries. The following
+ * replaces the original e820 map with a new one, removing overlaps,
+ * and resolving conflicting memory types in favor of highest
+ * numbered type.
+ *
+ * The input parameter biosmap points to an array of 'struct
+ * e820entry' which on entry has elements in the range [0, *pnr_map)
+ * valid, and which has space for up to max_nr_map entries.
+ * On return, the resulting sanitized e820 map entries will be in
+ * overwritten in the same location, starting at biosmap.
+ *
+ * The integer pointed to by pnr_map must be valid on entry (the
+ * current number of valid entries located at biosmap) and will
+ * be updated on return, with the new number of valid entries
+ * (something no more than max_nr_map.)
+ *
+ * The return value from sanitize_e820_map() is zero if it
+ * successfully 'sanitized' the map entries passed in, and is -1
+ * if it did nothing, which can happen if either of (1) it was
+ * only passed one map entry, or (2) any of the input map entries
+ * were invalid (start + size < start, meaning that the size was
+ * so big the described memory range wrapped around through zero.)
+ *
+ *     Visually we're performing the following
+ *     (1,2,3,4 = memory types)...
+ *
+ *     Sample memory map (w/overlaps):
+ *        ____22__________________
+ *        ______________________4_
+ *        ____1111________________
+ *        _44_____________________
+ *        11111111________________
+ *        ____________________33__
+ *        ___________44___________
+ *        __________33333_________
+ *        ______________22________
+ *        ___________________2222_
+ *        _________111111111______
+ *        _____________________11_
+ *        _________________4______
+ *
+ *     Sanitized equivalent (no overlap):
+ *        1_______________________
+ *        _44_____________________
+ *        ___1____________________
+ *        ____22__________________
+ *        ______11________________
+ *        _________1______________
+ *        __________3_____________
+ *        ___________44___________
+ *        _____________33_________
+ *        _______________2________
+ *        ________________1_______
+ *        _________________4______
+ *        ___________________2____
+ *        ____________________33__
+ *        ______________________4_
+ */
+
+int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
+                               int *pnr_map)
+{
+       struct change_member {
+               struct e820entry *pbios; /* pointer to original bios entry */
+               unsigned long long addr; /* address for this change point */
+       };
+       static struct change_member change_point_list[2*E820_X_MAX] __initdata;
+       static struct change_member *change_point[2*E820_X_MAX] __initdata;
+       static struct e820entry *overlap_list[E820_X_MAX] __initdata;
+       static struct e820entry new_bios[E820_X_MAX] __initdata;
+       struct change_member *change_tmp;
+       unsigned long current_type, last_type;
+       unsigned long long last_addr;
+       int chgidx, still_changing;
+       int overlap_entries;
+       int new_bios_entry;
+       int old_nr, new_nr, chg_nr;
+       int i;
+
+       /* if there's only one memory region, don't bother */
+       if (*pnr_map < 2)
+               return -1;
+
+       old_nr = *pnr_map;
+       BUG_ON(old_nr > max_nr_map);
+
+       /* bail out if we find any unreasonable addresses in bios map */
+       for (i = 0; i < old_nr; i++)
+               if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
+                       return -1;
+
+       /* create pointers for initial change-point information (for sorting) */
+       for (i = 0; i < 2 * old_nr; i++)
+               change_point[i] = &change_point_list[i];
+
+       /* record all known change-points (starting and ending addresses),
+          omitting those that are for empty memory regions */
+       chgidx = 0;
+       for (i = 0; i < old_nr; i++)    {
+               if (biosmap[i].size != 0) {
+                       change_point[chgidx]->addr = biosmap[i].addr;
+                       change_point[chgidx++]->pbios = &biosmap[i];
+                       change_point[chgidx]->addr = biosmap[i].addr +
+                               biosmap[i].size;
+                       change_point[chgidx++]->pbios = &biosmap[i];
+               }
+       }
+       chg_nr = chgidx;
+
+       /* sort change-point list by memory addresses (low -> high) */
+       still_changing = 1;
+       while (still_changing)  {
+               still_changing = 0;
+               for (i = 1; i < chg_nr; i++)  {
+                       unsigned long long curaddr, lastaddr;
+                       unsigned long long curpbaddr, lastpbaddr;
+
+                       curaddr = change_point[i]->addr;
+                       lastaddr = change_point[i - 1]->addr;
+                       curpbaddr = change_point[i]->pbios->addr;
+                       lastpbaddr = change_point[i - 1]->pbios->addr;
+
+                       /*
+                        * swap entries, when:
+                        *
+                        * curaddr > lastaddr or
+                        * curaddr == lastaddr and curaddr == curpbaddr and
+                        * lastaddr != lastpbaddr
+                        */
+                       if (curaddr < lastaddr ||
+                           (curaddr == lastaddr && curaddr == curpbaddr &&
+                            lastaddr != lastpbaddr)) {
+                               change_tmp = change_point[i];
+                               change_point[i] = change_point[i-1];
+                               change_point[i-1] = change_tmp;
+                               still_changing = 1;
+                       }
+               }
+       }
+
+       /* create a new bios memory map, removing overlaps */
+       overlap_entries = 0;     /* number of entries in the overlap table */
+       new_bios_entry = 0;      /* index for creating new bios map entries */
+       last_type = 0;           /* start with undefined memory type */
+       last_addr = 0;           /* start with 0 as last starting address */
+
+       /* loop through change-points, determining affect on the new bios map */
+       for (chgidx = 0; chgidx < chg_nr; chgidx++) {
+               /* keep track of all overlapping bios entries */
+               if (change_point[chgidx]->addr ==
+                   change_point[chgidx]->pbios->addr) {
+                       /*
+                        * add map entry to overlap list (> 1 entry
+                        * implies an overlap)
+                        */
+                       overlap_list[overlap_entries++] =
+                               change_point[chgidx]->pbios;
+               } else {
+                       /*
+                        * remove entry from list (order independent,
+                        * so swap with last)
+                        */
+                       for (i = 0; i < overlap_entries; i++) {
+                               if (overlap_list[i] ==
+                                   change_point[chgidx]->pbios)
+                                       overlap_list[i] =
+                                               overlap_list[overlap_entries-1];
+                       }
+                       overlap_entries--;
+               }
+               /*
+                * if there are overlapping entries, decide which
+                * "type" to use (larger value takes precedence --
+                * 1=usable, 2,3,4,4+=unusable)
+                */
+               current_type = 0;
+               for (i = 0; i < overlap_entries; i++)
+                       if (overlap_list[i]->type > current_type)
+                               current_type = overlap_list[i]->type;
+               /*
+                * continue building up new bios map based on this
+                * information
+                */
+               if (current_type != last_type)  {
+                       if (last_type != 0)      {
+                               new_bios[new_bios_entry].size =
+                                       change_point[chgidx]->addr - last_addr;
+                               /*
+                                * move forward only if the new size
+                                * was non-zero
+                                */
+                               if (new_bios[new_bios_entry].size != 0)
+                                       /*
+                                        * no more space left for new
+                                        * bios entries ?
+                                        */
+                                       if (++new_bios_entry >= max_nr_map)
+                                               break;
+                       }
+                       if (current_type != 0)  {
+                               new_bios[new_bios_entry].addr =
+                                       change_point[chgidx]->addr;
+                               new_bios[new_bios_entry].type = current_type;
+                               last_addr = change_point[chgidx]->addr;
+                       }
+                       last_type = current_type;
+               }
+       }
+       /* retain count for new bios entries */
+       new_nr = new_bios_entry;
+
+       /* copy new bios mapping into original location */
+       memcpy(biosmap, new_bios, new_nr * sizeof(struct e820entry));
+       *pnr_map = new_nr;
+
+       return 0;
+}
+
+static int __init __append_e820_map(struct e820entry *biosmap, int nr_map)
+{
+       while (nr_map) {
+               u64 start = biosmap->addr;
+               u64 size = biosmap->size;
+               u64 end = start + size;
+               u32 type = biosmap->type;
+
+               /* Overflow in 64 bits? Ignore the memory map. */
+               if (start > end)
+                       return -1;
+
+               e820_add_region(start, size, type);
+
+               biosmap++;
+               nr_map--;
+       }
+       return 0;
+}
+
+/*
+ * Copy the BIOS e820 map into a safe place.
+ *
+ * Sanity-check it while we're at it..
+ *
+ * If we're lucky and live on a modern system, the setup code
+ * will have given us a memory map that we can use to properly
+ * set up memory.  If we aren't, we'll fake a memory map.
+ */
+static int __init append_e820_map(struct e820entry *biosmap, int nr_map)
+{
+       /* Only one memory region (or negative)? Ignore it */
+       if (nr_map < 2)
+               return -1;
+
+       return __append_e820_map(biosmap, nr_map);
+}
+
+static u64 __init e820_update_range_map(struct e820map *e820x, u64 start,
+                                       u64 size, unsigned old_type,
+                                       unsigned new_type)
+{
+       int i;
+       u64 real_updated_size = 0;
+
+       BUG_ON(old_type == new_type);
+
+       if (size > (ULLONG_MAX - start))
+               size = ULLONG_MAX - start;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820x->map[i];
+               u64 final_start, final_end;
+               if (ei->type != old_type)
+                       continue;
+               /* totally covered? */
+               if (ei->addr >= start &&
+                   (ei->addr + ei->size) <= (start + size)) {
+                       ei->type = new_type;
+                       real_updated_size += ei->size;
+                       continue;
+               }
+               /* partially covered */
+               final_start = max(start, ei->addr);
+               final_end = min(start + size, ei->addr + ei->size);
+               if (final_start >= final_end)
+                       continue;
+               e820_add_region(final_start, final_end - final_start,
+                                        new_type);
+               real_updated_size += final_end - final_start;
+
+               ei->size -= final_end - final_start;
+               if (ei->addr < final_start)
+                       continue;
+               ei->addr = final_end;
+       }
+       return real_updated_size;
+}
+
+u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
+                            unsigned new_type)
+{
+       return e820_update_range_map(&e820, start, size, old_type, new_type);
+}
+
+static u64 __init e820_update_range_saved(u64 start, u64 size,
+                                         unsigned old_type, unsigned new_type)
+{
+       return e820_update_range_map(&e820_saved, start, size, old_type,
+                                    new_type);
+}
+
+/* make e820 not cover the range */
+u64 __init e820_remove_range(u64 start, u64 size, unsigned old_type,
+                            int checktype)
+{
+       int i;
+       u64 real_removed_size = 0;
+
+       if (size > (ULLONG_MAX - start))
+               size = ULLONG_MAX - start;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+               u64 final_start, final_end;
+
+               if (checktype && ei->type != old_type)
+                       continue;
+               /* totally covered? */
+               if (ei->addr >= start &&
+                   (ei->addr + ei->size) <= (start + size)) {
+                       real_removed_size += ei->size;
+                       memset(ei, 0, sizeof(struct e820entry));
+                       continue;
+               }
+               /* partially covered */
+               final_start = max(start, ei->addr);
+               final_end = min(start + size, ei->addr + ei->size);
+               if (final_start >= final_end)
+                       continue;
+               real_removed_size += final_end - final_start;
+
+               ei->size -= final_end - final_start;
+               if (ei->addr < final_start)
+                       continue;
+               ei->addr = final_end;
+       }
+       return real_removed_size;
+}
+
+void __init update_e820(void)
+{
+       int nr_map;
+
+       nr_map = e820.nr_map;
+       if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
+               return;
+       e820.nr_map = nr_map;
+       printk(KERN_INFO "modified physical RAM map:\n");
+       e820_print_map("modified");
+}
+static void __init update_e820_saved(void)
+{
+       int nr_map;
+
+       nr_map = e820_saved.nr_map;
+       if (sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
+               return;
+       e820_saved.nr_map = nr_map;
+}
+#define MAX_GAP_END 0x100000000ull
+/*
+ * Search for a gap in the e820 memory space from start_addr to end_addr.
+ */
+__init int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+               unsigned long start_addr, unsigned long long end_addr)
+{
+       unsigned long long last;
+       int i = e820.nr_map;
+       int found = 0;
+
+       last = (end_addr && end_addr < MAX_GAP_END) ? end_addr : MAX_GAP_END;
+
+       while (--i >= 0) {
+               unsigned long long start = e820.map[i].addr;
+               unsigned long long end = start + e820.map[i].size;
+
+               if (end < start_addr)
+                       continue;
+
+               /*
+                * Since "last" is at most 4GB, we know we'll
+                * fit in 32 bits if this condition is true
+                */
+               if (last > end) {
+                       unsigned long gap = last - end;
+
+                       if (gap >= *gapsize) {
+                               *gapsize = gap;
+                               *gapstart = end;
+                               found = 1;
+                       }
+               }
+               if (start < last)
+                       last = start;
+       }
+       return found;
+}
+
+/*
+ * Search for the biggest gap in the low 32 bits of the e820
+ * memory space.  We pass this space to PCI to assign MMIO resources
+ * for hotplug or unconfigured devices in.
+ * Hopefully the BIOS let enough space left.
+ */
+__init void e820_setup_gap(void)
+{
+       unsigned long gapstart, gapsize, round;
+       int found;
+
+       gapstart = 0x10000000;
+       gapsize = 0x400000;
+       found  = e820_search_gap(&gapstart, &gapsize, 0, MAX_GAP_END);
+
+#ifdef CONFIG_X86_64
+       if (!found) {
+               gapstart = (max_pfn << PAGE_SHIFT) + 1024*1024;
+               printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
+                      "address range\n"
+                      KERN_ERR "PCI: Unassigned devices with 32bit resource "
+                      "registers may break!\n");
+       }
+#endif
+
+       /*
+        * See how much we want to round up: start off with
+        * rounding to the next 1MB area.
+        */
+       round = 0x100000;
+       while ((gapsize >> 4) > round)
+               round += round;
+       /* Fun with two's complement */
+       pci_mem_start = (gapstart + round) & -round;
+
+       printk(KERN_INFO
+              "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
+              pci_mem_start, gapstart, gapsize);
+}
+
+/**
+ * Because of the size limitation of struct boot_params, only first
+ * 128 E820 memory entries are passed to kernel via
+ * boot_params.e820_map, others are passed via SETUP_E820_EXT node of
+ * linked list of struct setup_data, which is parsed here.
+ */
+void __init parse_e820_ext(struct setup_data *sdata, unsigned long pa_data)
+{
+       u32 map_len;
+       int entries;
+       struct e820entry *extmap;
+
+       entries = sdata->len / sizeof(struct e820entry);
+       map_len = sdata->len + sizeof(struct setup_data);
+       if (map_len > PAGE_SIZE)
+               sdata = early_ioremap(pa_data, map_len);
+       extmap = (struct e820entry *)(sdata->data);
+       __append_e820_map(extmap, entries);
+       sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+       if (map_len > PAGE_SIZE)
+               early_iounmap(sdata, map_len);
+       printk(KERN_INFO "extended physical RAM map:\n");
+       e820_print_map("extended");
+}
+
+#if defined(CONFIG_X86_64) || \
+       (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
+/**
+ * Find the ranges of physical addresses that do not correspond to
+ * e820 RAM areas and mark the corresponding pages as nosave for
+ * hibernation (32 bit) or software suspend and suspend to RAM (64 bit).
+ *
+ * This function requires the e820 map to be sorted and without any
+ * overlapping entries and assumes the first e820 area to be RAM.
+ */
+void __init e820_mark_nosave_regions(unsigned long limit_pfn)
+{
+       int i;
+       unsigned long pfn;
+
+       pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
+       for (i = 1; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+
+               if (pfn < PFN_UP(ei->addr))
+                       register_nosave_region(pfn, PFN_UP(ei->addr));
+
+               pfn = PFN_DOWN(ei->addr + ei->size);
+               if (ei->type != E820_RAM && ei->type != E820_RESERVED_KERN)
+                       register_nosave_region(PFN_UP(ei->addr), pfn);
+
+               if (pfn >= limit_pfn)
+                       break;
+       }
+}
+#endif
+
+/*
+ * Early reserved memory areas.
+ */
+#define MAX_EARLY_RES 20
+
+struct early_res {
+       u64 start, end;
+       char name[16];
+       char overlap_ok;
+};
+static struct early_res early_res[MAX_EARLY_RES] __initdata = {
+       { 0, PAGE_SIZE, "BIOS data page" },     /* BIOS data page */
+#if defined(CONFIG_X86_64) && defined(CONFIG_X86_TRAMPOLINE)
+       { TRAMPOLINE_BASE, TRAMPOLINE_BASE + 2 * PAGE_SIZE, "TRAMPOLINE" },
+#endif
+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
+       /*
+        * But first pinch a few for the stack/trampoline stuff
+        * FIXME: Don't need the extra page at 4K, but need to fix
+        * trampoline before removing it. (see the GDT stuff)
+        */
+       { PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE" },
+       /*
+        * Has to be in very low memory so we can execute
+        * real-mode AP code.
+        */
+       { TRAMPOLINE_BASE, TRAMPOLINE_BASE + PAGE_SIZE, "TRAMPOLINE" },
+#endif
+       {}
+};
+
+static int __init find_overlapped_early(u64 start, u64 end)
+{
+       int i;
+       struct early_res *r;
+
+       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
+               r = &early_res[i];
+               if (end > r->start && start < r->end)
+                       break;
+       }
+
+       return i;
+}
+
+/*
+ * Drop the i-th range from the early reservation map,
+ * by copying any higher ranges down one over it, and
+ * clearing what had been the last slot.
+ */
+static void __init drop_range(int i)
+{
+       int j;
+
+       for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
+               ;
+
+       memmove(&early_res[i], &early_res[i + 1],
+              (j - 1 - i) * sizeof(struct early_res));
+
+       early_res[j - 1].end = 0;
+}
+
+/*
+ * Split any existing ranges that:
+ *  1) are marked 'overlap_ok', and
+ *  2) overlap with the stated range [start, end)
+ * into whatever portion (if any) of the existing range is entirely
+ * below or entirely above the stated range.  Drop the portion
+ * of the existing range that overlaps with the stated range,
+ * which will allow the caller of this routine to then add that
+ * stated range without conflicting with any existing range.
+ */
+static void __init drop_overlaps_that_are_ok(u64 start, u64 end)
+{
+       int i;
+       struct early_res *r;
+       u64 lower_start, lower_end;
+       u64 upper_start, upper_end;
+       char name[16];
+
+       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
+               r = &early_res[i];
+
+               /* Continue past non-overlapping ranges */
+               if (end <= r->start || start >= r->end)
+                       continue;
+
+               /*
+                * Leave non-ok overlaps as is; let caller
+                * panic "Overlapping early reservations"
+                * when it hits this overlap.
+                */
+               if (!r->overlap_ok)
+                       return;
+
+               /*
+                * We have an ok overlap.  We will drop it from the early
+                * reservation map, and add back in any non-overlapping
+                * portions (lower or upper) as separate, overlap_ok,
+                * non-overlapping ranges.
+                */
+
+               /* 1. Note any non-overlapping (lower or upper) ranges. */
+               strncpy(name, r->name, sizeof(name) - 1);
+
+               lower_start = lower_end = 0;
+               upper_start = upper_end = 0;
+               if (r->start < start) {
+                       lower_start = r->start;
+                       lower_end = start;
+               }
+               if (r->end > end) {
+                       upper_start = end;
+                       upper_end = r->end;
+               }
+
+               /* 2. Drop the original ok overlapping range */
+               drop_range(i);
+
+               i--;            /* resume for-loop on copied down entry */
+
+               /* 3. Add back in any non-overlapping ranges. */
+               if (lower_end)
+                       reserve_early_overlap_ok(lower_start, lower_end, name);
+               if (upper_end)
+                       reserve_early_overlap_ok(upper_start, upper_end, name);
+       }
+}
+
+static void __init __reserve_early(u64 start, u64 end, char *name,
+                                               int overlap_ok)
+{
+       int i;
+       struct early_res *r;
+
+       i = find_overlapped_early(start, end);
+       if (i >= MAX_EARLY_RES)
+               panic("Too many early reservations");
+       r = &early_res[i];
+       if (r->end)
+               panic("Overlapping early reservations "
+                     "%llx-%llx %s to %llx-%llx %s\n",
+                     start, end - 1, name?name:"", r->start,
+                     r->end - 1, r->name);
+       r->start = start;
+       r->end = end;
+       r->overlap_ok = overlap_ok;
+       if (name)
+               strncpy(r->name, name, sizeof(r->name) - 1);
+}
+
+/*
+ * A few early reservtations come here.
+ *
+ * The 'overlap_ok' in the name of this routine does -not- mean it
+ * is ok for these reservations to overlap an earlier reservation.
+ * Rather it means that it is ok for subsequent reservations to
+ * overlap this one.
+ *
+ * Use this entry point to reserve early ranges when you are doing
+ * so out of "Paranoia", reserving perhaps more memory than you need,
+ * just in case, and don't mind a subsequent overlapping reservation
+ * that is known to be needed.
+ *
+ * The drop_overlaps_that_are_ok() call here isn't really needed.
+ * It would be needed if we had two colliding 'overlap_ok'
+ * reservations, so that the second such would not panic on the
+ * overlap with the first.  We don't have any such as of this
+ * writing, but might as well tolerate such if it happens in
+ * the future.
+ */
+void __init reserve_early_overlap_ok(u64 start, u64 end, char *name)
+{
+       drop_overlaps_that_are_ok(start, end);
+       __reserve_early(start, end, name, 1);
+}
+
+/*
+ * Most early reservations come here.
+ *
+ * We first have drop_overlaps_that_are_ok() drop any pre-existing
+ * 'overlap_ok' ranges, so that we can then reserve this memory
+ * range without risk of panic'ing on an overlapping overlap_ok
+ * early reservation.
+ */
+void __init reserve_early(u64 start, u64 end, char *name)
+{
+       drop_overlaps_that_are_ok(start, end);
+       __reserve_early(start, end, name, 0);
+}
+
+void __init free_early(u64 start, u64 end)
+{
+       struct early_res *r;
+       int i;
+
+       i = find_overlapped_early(start, end);
+       r = &early_res[i];
+       if (i >= MAX_EARLY_RES || r->end != end || r->start != start)
+               panic("free_early on not reserved area: %llx-%llx!",
+                        start, end - 1);
+
+       drop_range(i);
+}
+
+void __init early_res_to_bootmem(u64 start, u64 end)
+{
+       int i, count;
+       u64 final_start, final_end;
+
+       count  = 0;
+       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++)
+               count++;
+
+       printk(KERN_INFO "(%d early reservations) ==> bootmem\n", count);
+       for (i = 0; i < count; i++) {
+               struct early_res *r = &early_res[i];
+               printk(KERN_INFO "  #%d [%010llx - %010llx] %16s", i,
+                       r->start, r->end, r->name);
+               final_start = max(start, r->start);
+               final_end = min(end, r->end);
+               if (final_start >= final_end) {
+                       printk(KERN_CONT "\n");
+                       continue;
+               }
+               printk(KERN_CONT " ==> [%010llx - %010llx]\n",
+                       final_start, final_end);
+               reserve_bootmem_generic(final_start, final_end - final_start,
+                               BOOTMEM_DEFAULT);
+       }
+}
+
+/* Check for already reserved areas */
+static inline int __init bad_addr(u64 *addrp, u64 size, u64 align)
+{
+       int i;
+       u64 addr = *addrp;
+       int changed = 0;
+       struct early_res *r;
+again:
+       i = find_overlapped_early(addr, addr + size);
+       r = &early_res[i];
+       if (i < MAX_EARLY_RES && r->end) {
+               *addrp = addr = round_up(r->end, align);
+               changed = 1;
+               goto again;
+       }
+       return changed;
+}
+
+/* Check for already reserved areas */
+static inline int __init bad_addr_size(u64 *addrp, u64 *sizep, u64 align)
+{
+       int i;
+       u64 addr = *addrp, last;
+       u64 size = *sizep;
+       int changed = 0;
+again:
+       last = addr + size;
+       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
+               struct early_res *r = &early_res[i];
+               if (last > r->start && addr < r->start) {
+                       size = r->start - addr;
+                       changed = 1;
+                       goto again;
+               }
+               if (last > r->end && addr < r->end) {
+                       addr = round_up(r->end, align);
+                       size = last - addr;
+                       changed = 1;
+                       goto again;
+               }
+               if (last <= r->end && addr >= r->start) {
+                       (*sizep)++;
+                       return 0;
+               }
+       }
+       if (changed) {
+               *addrp = addr;
+               *sizep = size;
+       }
+       return changed;
+}
+
+/*
+ * Find a free area with specified alignment in a specific range.
+ */
+u64 __init find_e820_area(u64 start, u64 end, u64 size, u64 align)
+{
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+               u64 addr, last;
+               u64 ei_last;
+
+               if (ei->type != E820_RAM)
+                       continue;
+               addr = round_up(ei->addr, align);
+               ei_last = ei->addr + ei->size;
+               if (addr < start)
+                       addr = round_up(start, align);
+               if (addr >= ei_last)
+                       continue;
+               while (bad_addr(&addr, size, align) && addr+size <= ei_last)
+                       ;
+               last = addr + size;
+               if (last > ei_last)
+                       continue;
+               if (last > end)
+                       continue;
+               return addr;
+       }
+       return -1ULL;
+}
+
+/*
+ * Find next free range after *start
+ */
+u64 __init find_e820_area_size(u64 start, u64 *sizep, u64 align)
+{
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+               u64 addr, last;
+               u64 ei_last;
+
+               if (ei->type != E820_RAM)
+                       continue;
+               addr = round_up(ei->addr, align);
+               ei_last = ei->addr + ei->size;
+               if (addr < start)
+                       addr = round_up(start, align);
+               if (addr >= ei_last)
+                       continue;
+               *sizep = ei_last - addr;
+               while (bad_addr_size(&addr, sizep, align) &&
+                       addr + *sizep <= ei_last)
+                       ;
+               last = addr + *sizep;
+               if (last > ei_last)
+                       continue;
+               return addr;
+       }
+       return -1UL;
+
+}
+
+/*
+ * pre allocated 4k and reserved it in e820
+ */
+u64 __init early_reserve_e820(u64 startt, u64 sizet, u64 align)
+{
+       u64 size = 0;
+       u64 addr;
+       u64 start;
+
+       start = startt;
+       while (size < sizet)
+               start = find_e820_area_size(start, &size, align);
+
+       if (size < sizet)
+               return 0;
+
+       addr = round_down(start + size - sizet, align);
+       e820_update_range(addr, sizet, E820_RAM, E820_RESERVED);
+       e820_update_range_saved(addr, sizet, E820_RAM, E820_RESERVED);
+       printk(KERN_INFO "update e820 for early_reserve_e820\n");
+       update_e820();
+       update_e820_saved();
+
+       return addr;
+}
+
+#ifdef CONFIG_X86_32
+# ifdef CONFIG_X86_PAE
+#  define MAX_ARCH_PFN         (1ULL<<(36-PAGE_SHIFT))
+# else
+#  define MAX_ARCH_PFN         (1ULL<<(32-PAGE_SHIFT))
+# endif
+#else /* CONFIG_X86_32 */
+# define MAX_ARCH_PFN MAXMEM>>PAGE_SHIFT
+#endif
+
+/*
+ * Find the highest page frame number we have available
+ */
+static unsigned long __init e820_end_pfn(unsigned long limit_pfn, unsigned type)
+{
+       int i;
+       unsigned long last_pfn = 0;
+       unsigned long max_arch_pfn = MAX_ARCH_PFN;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               struct e820entry *ei = &e820.map[i];
+               unsigned long start_pfn;
+               unsigned long end_pfn;
+
+               if (ei->type != type)
+                       continue;
+
+               start_pfn = ei->addr >> PAGE_SHIFT;
+               end_pfn = (ei->addr + ei->size) >> PAGE_SHIFT;
+
+               if (start_pfn >= limit_pfn)
+                       continue;
+               if (end_pfn > limit_pfn) {
+                       last_pfn = limit_pfn;
+                       break;
+               }
+               if (end_pfn > last_pfn)
+                       last_pfn = end_pfn;
+       }
+
+       if (last_pfn > max_arch_pfn)
+               last_pfn = max_arch_pfn;
+
+       printk(KERN_INFO "last_pfn = %#lx max_arch_pfn = %#lx\n",
+                        last_pfn, max_arch_pfn);
+       return last_pfn;
+}
+unsigned long __init e820_end_of_ram_pfn(void)
+{
+       return e820_end_pfn(MAX_ARCH_PFN, E820_RAM);
+}
+
+unsigned long __init e820_end_of_low_ram_pfn(void)
+{
+       return e820_end_pfn(1UL<<(32 - PAGE_SHIFT), E820_RAM);
+}
+/*
+ * Finds an active region in the address range from start_pfn to last_pfn and
+ * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
+ */
+int __init e820_find_active_region(const struct e820entry *ei,
+                                 unsigned long start_pfn,
+                                 unsigned long last_pfn,
+                                 unsigned long *ei_startpfn,
+                                 unsigned long *ei_endpfn)
+{
+       u64 align = PAGE_SIZE;
+
+       *ei_startpfn = round_up(ei->addr, align) >> PAGE_SHIFT;
+       *ei_endpfn = round_down(ei->addr + ei->size, align) >> PAGE_SHIFT;
+
+       /* Skip map entries smaller than a page */
+       if (*ei_startpfn >= *ei_endpfn)
+               return 0;
+
+       /* Skip if map is outside the node */
+       if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
+                                   *ei_startpfn >= last_pfn)
+               return 0;
+
+       /* Check for overlaps */
+       if (*ei_startpfn < start_pfn)
+               *ei_startpfn = start_pfn;
+       if (*ei_endpfn > last_pfn)
+               *ei_endpfn = last_pfn;
+
+       return 1;
+}
+
+/* Walk the e820 map and register active regions within a node */
+void __init e820_register_active_regions(int nid, unsigned long start_pfn,
+                                        unsigned long last_pfn)
+{
+       unsigned long ei_startpfn;
+       unsigned long ei_endpfn;
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++)
+               if (e820_find_active_region(&e820.map[i],
+                                           start_pfn, last_pfn,
+                                           &ei_startpfn, &ei_endpfn))
+                       add_active_range(nid, ei_startpfn, ei_endpfn);
+}
+
+/*
+ * Find the hole size (in bytes) in the memory range.
+ * @start: starting address of the memory range to scan
+ * @end: ending address of the memory range to scan
+ */
+u64 __init e820_hole_size(u64 start, u64 end)
+{
+       unsigned long start_pfn = start >> PAGE_SHIFT;
+       unsigned long last_pfn = end >> PAGE_SHIFT;
+       unsigned long ei_startpfn, ei_endpfn, ram = 0;
+       int i;
+
+       for (i = 0; i < e820.nr_map; i++) {
+               if (e820_find_active_region(&e820.map[i],
+                                           start_pfn, last_pfn,
+                                           &ei_startpfn, &ei_endpfn))
+                       ram += ei_endpfn - ei_startpfn;
+       }
+       return end - start - ((u64)ram << PAGE_SHIFT);
+}
+
+static void early_panic(char *msg)
+{
+       early_printk(msg);
+       panic(msg);
+}
+
+static int userdef __initdata;
+
+/* "mem=nopentium" disables the 4MB page tables. */
+static int __init parse_memopt(char *p)
+{
+       u64 mem_size;
+
+       if (!p)
+               return -EINVAL;
+
+#ifdef CONFIG_X86_32
+       if (!strcmp(p, "nopentium")) {
+               setup_clear_cpu_cap(X86_FEATURE_PSE);
+               return 0;
+       }
+#endif
+
+       userdef = 1;
+       mem_size = memparse(p, &p);
+       e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+
+       return 0;
+}
+early_param("mem", parse_memopt);
+
+static int __init parse_memmap_opt(char *p)
+{
+       char *oldp;
+       u64 start_at, mem_size;
+
+       if (!p)
+               return -EINVAL;
+
+       if (!strcmp(p, "exactmap")) {
+#ifdef CONFIG_CRASH_DUMP
+               /*
+                * If we are doing a crash dump, we still need to know
+                * the real mem size before original memory map is
+                * reset.
+                */
+               saved_max_pfn = e820_end_of_ram_pfn();
+#endif
+               e820.nr_map = 0;
+               userdef = 1;
+               return 0;
+       }
+
+       oldp = p;
+       mem_size = memparse(p, &p);
+       if (p == oldp)
+               return -EINVAL;
+
+       userdef = 1;
+       if (*p == '@') {
+               start_at = memparse(p+1, &p);
+               e820_add_region(start_at, mem_size, E820_RAM);
+       } else if (*p == '#') {
+               start_at = memparse(p+1, &p);
+               e820_add_region(start_at, mem_size, E820_ACPI);
+       } else if (*p == '$') {
+               start_at = memparse(p+1, &p);
+               e820_add_region(start_at, mem_size, E820_RESERVED);
+       } else
+               e820_remove_range(mem_size, ULLONG_MAX - mem_size, E820_RAM, 1);
+
+       return *p == '\0' ? 0 : -EINVAL;
+}
+early_param("memmap", parse_memmap_opt);
+
+void __init finish_e820_parsing(void)
+{
+       if (userdef) {
+               int nr = e820.nr_map;
+
+               if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
+                       early_panic("Invalid user supplied memory map");
+               e820.nr_map = nr;
+
+               printk(KERN_INFO "user-defined physical RAM map:\n");
+               e820_print_map("user");
+       }
+}
+
+static inline const char *e820_type_to_string(int e820_type)
+{
+       switch (e820_type) {
+       case E820_RESERVED_KERN:
+       case E820_RAM:  return "System RAM";
+       case E820_ACPI: return "ACPI Tables";
+       case E820_NVS:  return "ACPI Non-volatile Storage";
+       default:        return "reserved";
+       }
+}
+
+/*
+ * Mark e820 reserved areas as busy for the resource manager.
+ */
+void __init e820_reserve_resources(void)
+{
+       int i;
+       struct resource *res;
+       u64 end;
+
+       res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
+       for (i = 0; i < e820.nr_map; i++) {
+               end = e820.map[i].addr + e820.map[i].size - 1;
+#ifndef CONFIG_RESOURCES_64BIT
+               if (end > 0x100000000ULL) {
+                       res++;
+                       continue;
+               }
+#endif
+               res->name = e820_type_to_string(e820.map[i].type);
+               res->start = e820.map[i].addr;
+               res->end = end;
+
+               res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+               insert_resource(&iomem_resource, res);
+               res++;
+       }
+
+       for (i = 0; i < e820_saved.nr_map; i++) {
+               struct e820entry *entry = &e820_saved.map[i];
+               firmware_map_add_early(entry->addr,
+                       entry->addr + entry->size - 1,
+                       e820_type_to_string(entry->type));
+       }
+}
+
+/*
+ * Non-standard memory setup can be specified via this quirk:
+ */
+char * (*arch_memory_setup_quirk)(void);
+
+char *__init default_machine_specific_memory_setup(void)
+{
+       char *who = "BIOS-e820";
+       int new_nr;
+       /*
+        * Try to copy the BIOS-supplied E820-map.
+        *
+        * Otherwise fake a memory map; one section from 0k->640k,
+        * the next section from 1mb->appropriate_mem_k
+        */
+       new_nr = boot_params.e820_entries;
+       sanitize_e820_map(boot_params.e820_map,
+                       ARRAY_SIZE(boot_params.e820_map),
+                       &new_nr);
+       boot_params.e820_entries = new_nr;
+       if (append_e820_map(boot_params.e820_map, boot_params.e820_entries)
+         < 0) {
+               u64 mem_size;
+
+               /* compare results from other methods and take the greater */
+               if (boot_params.alt_mem_k
+                   < boot_params.screen_info.ext_mem_k) {
+                       mem_size = boot_params.screen_info.ext_mem_k;
+                       who = "BIOS-88";
+               } else {
+                       mem_size = boot_params.alt_mem_k;
+                       who = "BIOS-e801";
+               }
+
+               e820.nr_map = 0;
+               e820_add_region(0, LOWMEMSIZE(), E820_RAM);
+               e820_add_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
+       }
+
+       /* In case someone cares... */
+       return who;
+}
+
+char *__init __attribute__((weak)) machine_specific_memory_setup(void)
+{
+       if (arch_memory_setup_quirk) {
+               char *who = arch_memory_setup_quirk();
+
+               if (who)
+                       return who;
+       }
+       return default_machine_specific_memory_setup();
+}
+
+/* Overridden in paravirt.c if CONFIG_PARAVIRT */
+char * __init __attribute__((weak)) memory_setup(void)
+{
+       return machine_specific_memory_setup();
+}
+
+void __init setup_memory_map(void)
+{
+       char *who;
+
+       who = memory_setup();
+       memcpy(&e820_saved, &e820, sizeof(struct e820map));
+       printk(KERN_INFO "BIOS-provided physical RAM map:\n");
+       e820_print_map(who);
+}
+
+#ifdef CONFIG_X86_64
+int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
+{
+       int i;
+
+       if (slot < 0 || slot >= e820.nr_map)
+               return -1;
+       for (i = slot; i < e820.nr_map; i++) {
+               if (e820.map[i].type != E820_RAM)
+                       continue;
+               break;
+       }
+       if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
+               return -1;
+       *addr = e820.map[i].addr;
+       *size = min_t(u64, e820.map[i].size + e820.map[i].addr,
+               max_pfn << PAGE_SHIFT) - *addr;
+       return i + 1;
+}
+#endif
diff --git a/arch/x86/kernel/e820_32.c b/arch/x86/kernel/e820_32.c
deleted file mode 100644 (file)
index ed733e7..0000000
+++ /dev/null
@@ -1,775 +0,0 @@
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <linux/init.h>
-#include <linux/bootmem.h>
-#include <linux/ioport.h>
-#include <linux/string.h>
-#include <linux/kexec.h>
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/pfn.h>
-#include <linux/uaccess.h>
-#include <linux/suspend.h>
-
-#include <asm/pgtable.h>
-#include <asm/page.h>
-#include <asm/e820.h>
-#include <asm/setup.h>
-
-struct e820map e820;
-struct change_member {
-       struct e820entry *pbios; /* pointer to original bios entry */
-       unsigned long long addr; /* address for this change point */
-};
-static struct change_member change_point_list[2*E820MAX] __initdata;
-static struct change_member *change_point[2*E820MAX] __initdata;
-static struct e820entry *overlap_list[E820MAX] __initdata;
-static struct e820entry new_bios[E820MAX] __initdata;
-/* For PCI or other memory-mapped resources */
-unsigned long pci_mem_start = 0x10000000;
-#ifdef CONFIG_PCI
-EXPORT_SYMBOL(pci_mem_start);
-#endif
-extern int user_defined_memmap;
-
-static struct resource system_rom_resource = {
-       .name   = "System ROM",
-       .start  = 0xf0000,
-       .end    = 0xfffff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-static struct resource extension_rom_resource = {
-       .name   = "Extension ROM",
-       .start  = 0xe0000,
-       .end    = 0xeffff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-static struct resource adapter_rom_resources[] = { {
-       .name   = "Adapter ROM",
-       .start  = 0xc8000,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-} };
-
-static struct resource video_rom_resource = {
-       .name   = "Video ROM",
-       .start  = 0xc0000,
-       .end    = 0xc7fff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-#define ROMSIGNATURE 0xaa55
-
-static int __init romsignature(const unsigned char *rom)
-{
-       const unsigned short * const ptr = (const unsigned short *)rom;
-       unsigned short sig;
-
-       return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
-}
-
-static int __init romchecksum(const unsigned char *rom, unsigned long length)
-{
-       unsigned char sum, c;
-
-       for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
-               sum += c;
-       return !length && !sum;
-}
-
-static void __init probe_roms(void)
-{
-       const unsigned char *rom;
-       unsigned long start, length, upper;
-       unsigned char c;
-       int i;
-
-       /* video rom */
-       upper = adapter_rom_resources[0].start;
-       for (start = video_rom_resource.start; start < upper; start += 2048) {
-               rom = isa_bus_to_virt(start);
-               if (!romsignature(rom))
-                       continue;
-
-               video_rom_resource.start = start;
-
-               if (probe_kernel_address(rom + 2, c) != 0)
-                       continue;
-
-               /* 0 < length <= 0x7f * 512, historically */
-               length = c * 512;
-
-               /* if checksum okay, trust length byte */
-               if (length && romchecksum(rom, length))
-                       video_rom_resource.end = start + length - 1;
-
-               request_resource(&iomem_resource, &video_rom_resource);
-               break;
-       }
-
-       start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
-       if (start < upper)
-               start = upper;
-
-       /* system rom */
-       request_resource(&iomem_resource, &system_rom_resource);
-       upper = system_rom_resource.start;
-
-       /* check for extension rom (ignore length byte!) */
-       rom = isa_bus_to_virt(extension_rom_resource.start);
-       if (romsignature(rom)) {
-               length = extension_rom_resource.end - extension_rom_resource.start + 1;
-               if (romchecksum(rom, length)) {
-                       request_resource(&iomem_resource, &extension_rom_resource);
-                       upper = extension_rom_resource.start;
-               }
-       }
-
-       /* check for adapter roms on 2k boundaries */
-       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
-               rom = isa_bus_to_virt(start);
-               if (!romsignature(rom))
-                       continue;
-
-               if (probe_kernel_address(rom + 2, c) != 0)
-                       continue;
-
-               /* 0 < length <= 0x7f * 512, historically */
-               length = c * 512;
-
-               /* but accept any length that fits if checksum okay */
-               if (!length || start + length > upper || !romchecksum(rom, length))
-                       continue;
-
-               adapter_rom_resources[i].start = start;
-               adapter_rom_resources[i].end = start + length - 1;
-               request_resource(&iomem_resource, &adapter_rom_resources[i]);
-
-               start = adapter_rom_resources[i++].end & ~2047UL;
-       }
-}
-
-/*
- * Request address space for all standard RAM and ROM resources
- * and also for regions reported as reserved by the e820.
- */
-void __init init_iomem_resources(struct resource *code_resource,
-               struct resource *data_resource,
-               struct resource *bss_resource)
-{
-       int i;
-
-       probe_roms();
-       for (i = 0; i < e820.nr_map; i++) {
-               struct resource *res;
-#ifndef CONFIG_RESOURCES_64BIT
-               if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
-                       continue;
-#endif
-               res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
-               switch (e820.map[i].type) {
-               case E820_RAM:  res->name = "System RAM"; break;
-               case E820_ACPI: res->name = "ACPI Tables"; break;
-               case E820_NVS:  res->name = "ACPI Non-volatile Storage"; break;
-               default:        res->name = "reserved";
-               }
-               res->start = e820.map[i].addr;
-               res->end = res->start + e820.map[i].size - 1;
-               res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-               if (request_resource(&iomem_resource, res)) {
-                       kfree(res);
-                       continue;
-               }
-               if (e820.map[i].type == E820_RAM) {
-                       /*
-                        *  We don't know which RAM region contains kernel data,
-                        *  so we try it repeatedly and let the resource manager
-                        *  test it.
-                        */
-                       request_resource(res, code_resource);
-                       request_resource(res, data_resource);
-                       request_resource(res, bss_resource);
-#ifdef CONFIG_KEXEC
-                       if (crashk_res.start != crashk_res.end)
-                               request_resource(res, &crashk_res);
-#endif
-               }
-       }
-}
-
-#if defined(CONFIG_PM) && defined(CONFIG_HIBERNATION)
-/**
- * e820_mark_nosave_regions - Find the ranges of physical addresses that do not
- * correspond to e820 RAM areas and mark the corresponding pages as nosave for
- * hibernation.
- *
- * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
- */
-void __init e820_mark_nosave_regions(void)
-{
-       int i;
-       unsigned long pfn;
-
-       pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
-       for (i = 1; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-
-               if (pfn < PFN_UP(ei->addr))
-                       register_nosave_region(pfn, PFN_UP(ei->addr));
-
-               pfn = PFN_DOWN(ei->addr + ei->size);
-               if (ei->type != E820_RAM)
-                       register_nosave_region(PFN_UP(ei->addr), pfn);
-
-               if (pfn >= max_low_pfn)
-                       break;
-       }
-}
-#endif
-
-void __init add_memory_region(unsigned long long start,
-                             unsigned long long size, int type)
-{
-       int x;
-
-       x = e820.nr_map;
-
-       if (x == E820MAX) {
-               printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
-               return;
-       }
-
-       e820.map[x].addr = start;
-       e820.map[x].size = size;
-       e820.map[x].type = type;
-       e820.nr_map++;
-} /* add_memory_region */
-
-/*
- * Sanitize the BIOS e820 map.
- *
- * Some e820 responses include overlapping entries.  The following
- * replaces the original e820 map with a new one, removing overlaps.
- *
- */
-int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
-{
-       struct change_member *change_tmp;
-       unsigned long current_type, last_type;
-       unsigned long long last_addr;
-       int chgidx, still_changing;
-       int overlap_entries;
-       int new_bios_entry;
-       int old_nr, new_nr, chg_nr;
-       int i;
-
-       /*
-               Visually we're performing the following (1,2,3,4 = memory types)...
-
-               Sample memory map (w/overlaps):
-                  ____22__________________
-                  ______________________4_
-                  ____1111________________
-                  _44_____________________
-                  11111111________________
-                  ____________________33__
-                  ___________44___________
-                  __________33333_________
-                  ______________22________
-                  ___________________2222_
-                  _________111111111______
-                  _____________________11_
-                  _________________4______
-
-               Sanitized equivalent (no overlap):
-                  1_______________________
-                  _44_____________________
-                  ___1____________________
-                  ____22__________________
-                  ______11________________
-                  _________1______________
-                  __________3_____________
-                  ___________44___________
-                  _____________33_________
-                  _______________2________
-                  ________________1_______
-                  _________________4______
-                  ___________________2____
-                  ____________________33__
-                  ______________________4_
-       */
-       /* if there's only one memory region, don't bother */
-       if (*pnr_map < 2) {
-               return -1;
-       }
-
-       old_nr = *pnr_map;
-
-       /* bail out if we find any unreasonable addresses in bios map */
-       for (i=0; i<old_nr; i++)
-               if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr) {
-                       return -1;
-               }
-
-       /* create pointers for initial change-point information (for sorting) */
-       for (i=0; i < 2*old_nr; i++)
-               change_point[i] = &change_point_list[i];
-
-       /* record all known change-points (starting and ending addresses),
-          omitting those that are for empty memory regions */
-       chgidx = 0;
-       for (i=0; i < old_nr; i++)      {
-               if (biosmap[i].size != 0) {
-                       change_point[chgidx]->addr = biosmap[i].addr;
-                       change_point[chgidx++]->pbios = &biosmap[i];
-                       change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
-                       change_point[chgidx++]->pbios = &biosmap[i];
-               }
-       }
-       chg_nr = chgidx;        /* true number of change-points */
-
-       /* sort change-point list by memory addresses (low -> high) */
-       still_changing = 1;
-       while (still_changing)  {
-               still_changing = 0;
-               for (i=1; i < chg_nr; i++)  {
-                       /* if <current_addr> > <last_addr>, swap */
-                       /* or, if current=<start_addr> & last=<end_addr>, swap */
-                       if ((change_point[i]->addr < change_point[i-1]->addr) ||
-                               ((change_point[i]->addr == change_point[i-1]->addr) &&
-                                (change_point[i]->addr == change_point[i]->pbios->addr) &&
-                                (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
-                          )
-                       {
-                               change_tmp = change_point[i];
-                               change_point[i] = change_point[i-1];
-                               change_point[i-1] = change_tmp;
-                               still_changing=1;
-                       }
-               }
-       }
-
-       /* create a new bios memory map, removing overlaps */
-       overlap_entries=0;       /* number of entries in the overlap table */
-       new_bios_entry=0;        /* index for creating new bios map entries */
-       last_type = 0;           /* start with undefined memory type */
-       last_addr = 0;           /* start with 0 as last starting address */
-       /* loop through change-points, determining affect on the new bios map */
-       for (chgidx=0; chgidx < chg_nr; chgidx++)
-       {
-               /* keep track of all overlapping bios entries */
-               if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
-               {
-                       /* add map entry to overlap list (> 1 entry implies an overlap) */
-                       overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
-               }
-               else
-               {
-                       /* remove entry from list (order independent, so swap with last) */
-                       for (i=0; i<overlap_entries; i++)
-                       {
-                               if (overlap_list[i] == change_point[chgidx]->pbios)
-                                       overlap_list[i] = overlap_list[overlap_entries-1];
-                       }
-                       overlap_entries--;
-               }
-               /* if there are overlapping entries, decide which "type" to use */
-               /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
-               current_type = 0;
-               for (i=0; i<overlap_entries; i++)
-                       if (overlap_list[i]->type > current_type)
-                               current_type = overlap_list[i]->type;
-               /* continue building up new bios map based on this information */
-               if (current_type != last_type)  {
-                       if (last_type != 0)      {
-                               new_bios[new_bios_entry].size =
-                                       change_point[chgidx]->addr - last_addr;
-                               /* move forward only if the new size was non-zero */
-                               if (new_bios[new_bios_entry].size != 0)
-                                       if (++new_bios_entry >= E820MAX)
-                                               break;  /* no more space left for new bios entries */
-                       }
-                       if (current_type != 0)  {
-                               new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
-                               new_bios[new_bios_entry].type = current_type;
-                               last_addr=change_point[chgidx]->addr;
-                       }
-                       last_type = current_type;
-               }
-       }
-       new_nr = new_bios_entry;   /* retain count for new bios entries */
-
-       /* copy new bios mapping into original location */
-       memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
-       *pnr_map = new_nr;
-
-       return 0;
-}
-
-/*
- * Copy the BIOS e820 map into a safe place.
- *
- * Sanity-check it while we're at it..
- *
- * If we're lucky and live on a modern system, the setup code
- * will have given us a memory map that we can use to properly
- * set up memory.  If we aren't, we'll fake a memory map.
- *
- * We check to see that the memory map contains at least 2 elements
- * before we'll use it, because the detection code in setup.S may
- * not be perfect and most every PC known to man has two memory
- * regions: one from 0 to 640k, and one from 1mb up.  (The IBM
- * thinkpad 560x, for example, does not cooperate with the memory
- * detection code.)
- */
-int __init copy_e820_map(struct e820entry *biosmap, int nr_map)
-{
-       /* Only one memory region (or negative)? Ignore it */
-       if (nr_map < 2)
-               return -1;
-
-       do {
-               u64 start = biosmap->addr;
-               u64 size = biosmap->size;
-               u64 end = start + size;
-               u32 type = biosmap->type;
-
-               /* Overflow in 64 bits? Ignore the memory map. */
-               if (start > end)
-                       return -1;
-
-               add_memory_region(start, size, type);
-       } while (biosmap++, --nr_map);
-
-       return 0;
-}
-
-/*
- * Find the highest page frame number we have available
- */
-void __init propagate_e820_map(void)
-{
-       int i;
-
-       max_pfn = 0;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               unsigned long start, end;
-               /* RAM? */
-               if (e820.map[i].type != E820_RAM)
-                       continue;
-               start = PFN_UP(e820.map[i].addr);
-               end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
-               if (start >= end)
-                       continue;
-               if (end > max_pfn)
-                       max_pfn = end;
-               memory_present(0, start, end);
-       }
-}
-
-/*
- * Register fully available low RAM pages with the bootmem allocator.
- */
-void __init register_bootmem_low_pages(unsigned long max_low_pfn)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               unsigned long curr_pfn, last_pfn, size;
-               /*
-                * Reserve usable low memory
-                */
-               if (e820.map[i].type != E820_RAM)
-                       continue;
-               /*
-                * We are rounding up the start address of usable memory:
-                */
-               curr_pfn = PFN_UP(e820.map[i].addr);
-               if (curr_pfn >= max_low_pfn)
-                       continue;
-               /*
-                * ... and at the end of the usable range downwards:
-                */
-               last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
-
-               if (last_pfn > max_low_pfn)
-                       last_pfn = max_low_pfn;
-
-               /*
-                * .. finally, did all the rounding and playing
-                * around just make the area go away?
-                */
-               if (last_pfn <= curr_pfn)
-                       continue;
-
-               size = last_pfn - curr_pfn;
-               free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
-       }
-}
-
-void __init e820_register_memory(void)
-{
-       unsigned long gapstart, gapsize, round;
-       unsigned long long last;
-       int i;
-
-       /*
-        * Search for the biggest gap in the low 32 bits of the e820
-        * memory space.
-        */
-       last = 0x100000000ull;
-       gapstart = 0x10000000;
-       gapsize = 0x400000;
-       i = e820.nr_map;
-       while (--i >= 0) {
-               unsigned long long start = e820.map[i].addr;
-               unsigned long long end = start + e820.map[i].size;
-
-               /*
-                * Since "last" is at most 4GB, we know we'll
-                * fit in 32 bits if this condition is true
-                */
-               if (last > end) {
-                       unsigned long gap = last - end;
-
-                       if (gap > gapsize) {
-                               gapsize = gap;
-                               gapstart = end;
-                       }
-               }
-               if (start < last)
-                       last = start;
-       }
-
-       /*
-        * See how much we want to round up: start off with
-        * rounding to the next 1MB area.
-        */
-       round = 0x100000;
-       while ((gapsize >> 4) > round)
-               round += round;
-       /* Fun with two's complement */
-       pci_mem_start = (gapstart + round) & -round;
-
-       printk("Allocating PCI resources starting at %08lx (gap: %08lx:%08lx)\n",
-               pci_mem_start, gapstart, gapsize);
-}
-
-void __init print_memory_map(char *who)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               printk(" %s: %016Lx - %016Lx ", who,
-                       e820.map[i].addr,
-                       e820.map[i].addr + e820.map[i].size);
-               switch (e820.map[i].type) {
-               case E820_RAM:  printk("(usable)\n");
-                               break;
-               case E820_RESERVED:
-                               printk("(reserved)\n");
-                               break;
-               case E820_ACPI:
-                               printk("(ACPI data)\n");
-                               break;
-               case E820_NVS:
-                               printk("(ACPI NVS)\n");
-                               break;
-               default:        printk("type %u\n", e820.map[i].type);
-                               break;
-               }
-       }
-}
-
-void __init limit_regions(unsigned long long size)
-{
-       unsigned long long current_addr;
-       int i;
-
-       print_memory_map("limit_regions start");
-       for (i = 0; i < e820.nr_map; i++) {
-               current_addr = e820.map[i].addr + e820.map[i].size;
-               if (current_addr < size)
-                       continue;
-
-               if (e820.map[i].type != E820_RAM)
-                       continue;
-
-               if (e820.map[i].addr >= size) {
-                       /*
-                        * This region starts past the end of the
-                        * requested size, skip it completely.
-                        */
-                       e820.nr_map = i;
-               } else {
-                       e820.nr_map = i + 1;
-                       e820.map[i].size -= current_addr - size;
-               }
-               print_memory_map("limit_regions endfor");
-               return;
-       }
-       print_memory_map("limit_regions endfunc");
-}
-
-/*
- * This function checks if any part of the range <start,end> is mapped
- * with type.
- */
-int
-e820_any_mapped(u64 start, u64 end, unsigned type)
-{
-       int i;
-       for (i = 0; i < e820.nr_map; i++) {
-               const struct e820entry *ei = &e820.map[i];
-               if (type && ei->type != type)
-                       continue;
-               if (ei->addr >= end || ei->addr + ei->size <= start)
-                       continue;
-               return 1;
-       }
-       return 0;
-}
-EXPORT_SYMBOL_GPL(e820_any_mapped);
-
- /*
-  * This function checks if the entire range <start,end> is mapped with type.
-  *
-  * Note: this function only works correct if the e820 table is sorted and
-  * not-overlapping, which is the case
-  */
-int __init
-e820_all_mapped(unsigned long s, unsigned long e, unsigned type)
-{
-       u64 start = s;
-       u64 end = e;
-       int i;
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-               if (type && ei->type != type)
-                       continue;
-               /* is the region (part) in overlap with the current region ?*/
-               if (ei->addr >= end || ei->addr + ei->size <= start)
-                       continue;
-               /* if the region is at the beginning of <start,end> we move
-                * start to the end of the region since it's ok until there
-                */
-               if (ei->addr <= start)
-                       start = ei->addr + ei->size;
-               /* if start is now at or beyond end, we're done, full
-                * coverage */
-               if (start >= end)
-                       return 1; /* we're done */
-       }
-       return 0;
-}
-
-static int __init parse_memmap(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-
-       if (strcmp(arg, "exactmap") == 0) {
-#ifdef CONFIG_CRASH_DUMP
-               /* If we are doing a crash dump, we
-                * still need to know the real mem
-                * size before original memory map is
-                * reset.
-                */
-               propagate_e820_map();
-               saved_max_pfn = max_pfn;
-#endif
-               e820.nr_map = 0;
-               user_defined_memmap = 1;
-       } else {
-               /* If the user specifies memory size, we
-                * limit the BIOS-provided memory map to
-                * that size. exactmap can be used to specify
-                * the exact map. mem=number can be used to
-                * trim the existing memory map.
-                */
-               unsigned long long start_at, mem_size;
-
-               mem_size = memparse(arg, &arg);
-               if (*arg == '@') {
-                       start_at = memparse(arg+1, &arg);
-                       add_memory_region(start_at, mem_size, E820_RAM);
-               } else if (*arg == '#') {
-                       start_at = memparse(arg+1, &arg);
-                       add_memory_region(start_at, mem_size, E820_ACPI);
-               } else if (*arg == '$') {
-                       start_at = memparse(arg+1, &arg);
-                       add_memory_region(start_at, mem_size, E820_RESERVED);
-               } else {
-                       limit_regions(mem_size);
-                       user_defined_memmap = 1;
-               }
-       }
-       return 0;
-}
-early_param("memmap", parse_memmap);
-void __init update_memory_range(u64 start, u64 size, unsigned old_type,
-                               unsigned new_type)
-{
-       int i;
-
-       BUG_ON(old_type == new_type);
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-               u64 final_start, final_end;
-               if (ei->type != old_type)
-                       continue;
-               /* totally covered? */
-               if (ei->addr >= start && ei->size <= size) {
-                       ei->type = new_type;
-                       continue;
-               }
-               /* partially covered */
-               final_start = max(start, ei->addr);
-               final_end = min(start + size, ei->addr + ei->size);
-               if (final_start >= final_end)
-                       continue;
-               add_memory_region(final_start, final_end - final_start,
-                                        new_type);
-       }
-}
-void __init update_e820(void)
-{
-       u8 nr_map;
-
-       nr_map = e820.nr_map;
-       if (sanitize_e820_map(e820.map, &nr_map))
-               return;
-       e820.nr_map = nr_map;
-       printk(KERN_INFO "modified physical RAM map:\n");
-       print_memory_map("modified");
-}
diff --git a/arch/x86/kernel/e820_64.c b/arch/x86/kernel/e820_64.c
deleted file mode 100644 (file)
index 124480c..0000000
+++ /dev/null
@@ -1,952 +0,0 @@
-/*
- * Handle the memory map.
- * The functions here do the job until bootmem takes over.
- *
- *  Getting sanitize_e820_map() in sync with i386 version by applying change:
- *  -  Provisions for empty E820 memory regions (reported by certain BIOSes).
- *     Alex Achenbach <xela@slit.de>, December 2002.
- *  Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
- *
- */
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <linux/init.h>
-#include <linux/bootmem.h>
-#include <linux/ioport.h>
-#include <linux/string.h>
-#include <linux/kexec.h>
-#include <linux/module.h>
-#include <linux/mm.h>
-#include <linux/suspend.h>
-#include <linux/pfn.h>
-
-#include <asm/pgtable.h>
-#include <asm/page.h>
-#include <asm/e820.h>
-#include <asm/proto.h>
-#include <asm/setup.h>
-#include <asm/sections.h>
-#include <asm/kdebug.h>
-#include <asm/trampoline.h>
-
-struct e820map e820;
-
-/*
- * PFN of last memory page.
- */
-unsigned long end_pfn;
-
-/*
- * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
- * The direct mapping extends to max_pfn_mapped, so that we can directly access
- * apertures, ACPI and other tables without having to play with fixmaps.
- */
-unsigned long max_pfn_mapped;
-
-/*
- * Last pfn which the user wants to use.
- */
-static unsigned long __initdata end_user_pfn = MAXMEM>>PAGE_SHIFT;
-
-/*
- * Early reserved memory areas.
- */
-#define MAX_EARLY_RES 20
-
-struct early_res {
-       unsigned long start, end;
-       char name[16];
-};
-static struct early_res early_res[MAX_EARLY_RES] __initdata = {
-       { 0, PAGE_SIZE, "BIOS data page" },                     /* BIOS data page */
-#ifdef CONFIG_X86_TRAMPOLINE
-       { TRAMPOLINE_BASE, TRAMPOLINE_BASE + 2 * PAGE_SIZE, "TRAMPOLINE" },
-#endif
-       {}
-};
-
-void __init reserve_early(unsigned long start, unsigned long end, char *name)
-{
-       int i;
-       struct early_res *r;
-       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
-               r = &early_res[i];
-               if (end > r->start && start < r->end)
-                       panic("Overlapping early reservations %lx-%lx %s to %lx-%lx %s\n",
-                             start, end - 1, name?name:"", r->start, r->end - 1, r->name);
-       }
-       if (i >= MAX_EARLY_RES)
-               panic("Too many early reservations");
-       r = &early_res[i];
-       r->start = start;
-       r->end = end;
-       if (name)
-               strncpy(r->name, name, sizeof(r->name) - 1);
-}
-
-void __init free_early(unsigned long start, unsigned long end)
-{
-       struct early_res *r;
-       int i, j;
-
-       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
-               r = &early_res[i];
-               if (start == r->start && end == r->end)
-                       break;
-       }
-       if (i >= MAX_EARLY_RES || !early_res[i].end)
-               panic("free_early on not reserved area: %lx-%lx!", start, end);
-
-       for (j = i + 1; j < MAX_EARLY_RES && early_res[j].end; j++)
-               ;
-
-       memmove(&early_res[i], &early_res[i + 1],
-              (j - 1 - i) * sizeof(struct early_res));
-
-       early_res[j - 1].end = 0;
-}
-
-void __init early_res_to_bootmem(unsigned long start, unsigned long end)
-{
-       int i;
-       unsigned long final_start, final_end;
-       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
-               struct early_res *r = &early_res[i];
-               final_start = max(start, r->start);
-               final_end = min(end, r->end);
-               if (final_start >= final_end)
-                       continue;
-               printk(KERN_INFO "  early res: %d [%lx-%lx] %s\n", i,
-                       final_start, final_end - 1, r->name);
-               reserve_bootmem_generic(final_start, final_end - final_start);
-       }
-}
-
-/* Check for already reserved areas */
-static inline int __init
-bad_addr(unsigned long *addrp, unsigned long size, unsigned long align)
-{
-       int i;
-       unsigned long addr = *addrp, last;
-       int changed = 0;
-again:
-       last = addr + size;
-       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
-               struct early_res *r = &early_res[i];
-               if (last >= r->start && addr < r->end) {
-                       *addrp = addr = round_up(r->end, align);
-                       changed = 1;
-                       goto again;
-               }
-       }
-       return changed;
-}
-
-/* Check for already reserved areas */
-static inline int __init
-bad_addr_size(unsigned long *addrp, unsigned long *sizep, unsigned long align)
-{
-       int i;
-       unsigned long addr = *addrp, last;
-       unsigned long size = *sizep;
-       int changed = 0;
-again:
-       last = addr + size;
-       for (i = 0; i < MAX_EARLY_RES && early_res[i].end; i++) {
-               struct early_res *r = &early_res[i];
-               if (last > r->start && addr < r->start) {
-                       size = r->start - addr;
-                       changed = 1;
-                       goto again;
-               }
-               if (last > r->end && addr < r->end) {
-                       addr = round_up(r->end, align);
-                       size = last - addr;
-                       changed = 1;
-                       goto again;
-               }
-               if (last <= r->end && addr >= r->start) {
-                       (*sizep)++;
-                       return 0;
-               }
-       }
-       if (changed) {
-               *addrp = addr;
-               *sizep = size;
-       }
-       return changed;
-}
-/*
- * This function checks if any part of the range <start,end> is mapped
- * with type.
- */
-int
-e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-
-               if (type && ei->type != type)
-                       continue;
-               if (ei->addr >= end || ei->addr + ei->size <= start)
-                       continue;
-               return 1;
-       }
-       return 0;
-}
-EXPORT_SYMBOL_GPL(e820_any_mapped);
-
-/*
- * This function checks if the entire range <start,end> is mapped with type.
- *
- * Note: this function only works correct if the e820 table is sorted and
- * not-overlapping, which is the case
- */
-int __init e820_all_mapped(unsigned long start, unsigned long end,
-                          unsigned type)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-
-               if (type && ei->type != type)
-                       continue;
-               /* is the region (part) in overlap with the current region ?*/
-               if (ei->addr >= end || ei->addr + ei->size <= start)
-                       continue;
-
-               /* if the region is at the beginning of <start,end> we move
-                * start to the end of the region since it's ok until there
-                */
-               if (ei->addr <= start)
-                       start = ei->addr + ei->size;
-               /*
-                * if start is now at or beyond end, we're done, full
-                * coverage
-                */
-               if (start >= end)
-                       return 1;
-       }
-       return 0;
-}
-
-/*
- * Find a free area with specified alignment in a specific range.
- */
-unsigned long __init find_e820_area(unsigned long start, unsigned long end,
-                                   unsigned long size, unsigned long align)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-               unsigned long addr, last;
-               unsigned long ei_last;
-
-               if (ei->type != E820_RAM)
-                       continue;
-               addr = round_up(ei->addr, align);
-               ei_last = ei->addr + ei->size;
-               if (addr < start)
-                       addr = round_up(start, align);
-               if (addr >= ei_last)
-                       continue;
-               while (bad_addr(&addr, size, align) && addr+size <= ei_last)
-                       ;
-               last = addr + size;
-               if (last > ei_last)
-                       continue;
-               if (last > end)
-                       continue;
-               return addr;
-       }
-       return -1UL;
-}
-
-/*
- * Find next free range after *start
- */
-unsigned long __init find_e820_area_size(unsigned long start,
-                                        unsigned long *sizep,
-                                        unsigned long align)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-               unsigned long addr, last;
-               unsigned long ei_last;
-
-               if (ei->type != E820_RAM)
-                       continue;
-               addr = round_up(ei->addr, align);
-               ei_last = ei->addr + ei->size;
-               if (addr < start)
-                       addr = round_up(start, align);
-               if (addr >= ei_last)
-                       continue;
-               *sizep = ei_last - addr;
-               while (bad_addr_size(&addr, sizep, align) &&
-                       addr + *sizep <= ei_last)
-                       ;
-               last = addr + *sizep;
-               if (last > ei_last)
-                       continue;
-               return addr;
-       }
-       return -1UL;
-
-}
-/*
- * Find the highest page frame number we have available
- */
-unsigned long __init e820_end_of_ram(void)
-{
-       unsigned long end_pfn;
-
-       end_pfn = find_max_pfn_with_active_regions();
-
-       if (end_pfn > max_pfn_mapped)
-               max_pfn_mapped = end_pfn;
-       if (max_pfn_mapped > MAXMEM>>PAGE_SHIFT)
-               max_pfn_mapped = MAXMEM>>PAGE_SHIFT;
-       if (end_pfn > end_user_pfn)
-               end_pfn = end_user_pfn;
-       if (end_pfn > max_pfn_mapped)
-               end_pfn = max_pfn_mapped;
-
-       printk(KERN_INFO "max_pfn_mapped = %lu\n", max_pfn_mapped);
-       return end_pfn;
-}
-
-/*
- * Mark e820 reserved areas as busy for the resource manager.
- */
-void __init e820_reserve_resources(void)
-{
-       int i;
-       struct resource *res;
-
-       res = alloc_bootmem_low(sizeof(struct resource) * e820.nr_map);
-       for (i = 0; i < e820.nr_map; i++) {
-               switch (e820.map[i].type) {
-               case E820_RAM:  res->name = "System RAM"; break;
-               case E820_ACPI: res->name = "ACPI Tables"; break;
-               case E820_NVS:  res->name = "ACPI Non-volatile Storage"; break;
-               default:        res->name = "reserved";
-               }
-               res->start = e820.map[i].addr;
-               res->end = res->start + e820.map[i].size - 1;
-               res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-               insert_resource(&iomem_resource, res);
-               res++;
-       }
-}
-
-/*
- * Find the ranges of physical addresses that do not correspond to
- * e820 RAM areas and mark the corresponding pages as nosave for software
- * suspend and suspend to RAM.
- *
- * This function requires the e820 map to be sorted and without any
- * overlapping entries and assumes the first e820 area to be RAM.
- */
-void __init e820_mark_nosave_regions(void)
-{
-       int i;
-       unsigned long paddr;
-
-       paddr = round_down(e820.map[0].addr + e820.map[0].size, PAGE_SIZE);
-       for (i = 1; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-
-               if (paddr < ei->addr)
-                       register_nosave_region(PFN_DOWN(paddr),
-                                               PFN_UP(ei->addr));
-
-               paddr = round_down(ei->addr + ei->size, PAGE_SIZE);
-               if (ei->type != E820_RAM)
-                       register_nosave_region(PFN_UP(ei->addr),
-                                               PFN_DOWN(paddr));
-
-               if (paddr >= (end_pfn << PAGE_SHIFT))
-                       break;
-       }
-}
-
-/*
- * Finds an active region in the address range from start_pfn to end_pfn and
- * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
- */
-static int __init e820_find_active_region(const struct e820entry *ei,
-                                         unsigned long start_pfn,
-                                         unsigned long end_pfn,
-                                         unsigned long *ei_startpfn,
-                                         unsigned long *ei_endpfn)
-{
-       *ei_startpfn = round_up(ei->addr, PAGE_SIZE) >> PAGE_SHIFT;
-       *ei_endpfn = round_down(ei->addr + ei->size, PAGE_SIZE) >> PAGE_SHIFT;
-
-       /* Skip map entries smaller than a page */
-       if (*ei_startpfn >= *ei_endpfn)
-               return 0;
-
-       /* Check if max_pfn_mapped should be updated */
-       if (ei->type != E820_RAM && *ei_endpfn > max_pfn_mapped)
-               max_pfn_mapped = *ei_endpfn;
-
-       /* Skip if map is outside the node */
-       if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
-                                   *ei_startpfn >= end_pfn)
-               return 0;
-
-       /* Check for overlaps */
-       if (*ei_startpfn < start_pfn)
-               *ei_startpfn = start_pfn;
-       if (*ei_endpfn > end_pfn)
-               *ei_endpfn = end_pfn;
-
-       /* Obey end_user_pfn to save on memmap */
-       if (*ei_startpfn >= end_user_pfn)
-               return 0;
-       if (*ei_endpfn > end_user_pfn)
-               *ei_endpfn = end_user_pfn;
-
-       return 1;
-}
-
-/* Walk the e820 map and register active regions within a node */
-void __init
-e820_register_active_regions(int nid, unsigned long start_pfn,
-                                                       unsigned long end_pfn)
-{
-       unsigned long ei_startpfn;
-       unsigned long ei_endpfn;
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++)
-               if (e820_find_active_region(&e820.map[i],
-                                           start_pfn, end_pfn,
-                                           &ei_startpfn, &ei_endpfn))
-                       add_active_range(nid, ei_startpfn, ei_endpfn);
-}
-
-/*
- * Add a memory region to the kernel e820 map.
- */
-void __init add_memory_region(unsigned long start, unsigned long size, int type)
-{
-       int x = e820.nr_map;
-
-       if (x == E820MAX) {
-               printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
-               return;
-       }
-
-       e820.map[x].addr = start;
-       e820.map[x].size = size;
-       e820.map[x].type = type;
-       e820.nr_map++;
-}
-
-/*
- * Find the hole size (in bytes) in the memory range.
- * @start: starting address of the memory range to scan
- * @end: ending address of the memory range to scan
- */
-unsigned long __init e820_hole_size(unsigned long start, unsigned long end)
-{
-       unsigned long start_pfn = start >> PAGE_SHIFT;
-       unsigned long end_pfn = end >> PAGE_SHIFT;
-       unsigned long ei_startpfn, ei_endpfn, ram = 0;
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               if (e820_find_active_region(&e820.map[i],
-                                           start_pfn, end_pfn,
-                                           &ei_startpfn, &ei_endpfn))
-                       ram += ei_endpfn - ei_startpfn;
-       }
-       return end - start - (ram << PAGE_SHIFT);
-}
-
-static void __init e820_print_map(char *who)
-{
-       int i;
-
-       for (i = 0; i < e820.nr_map; i++) {
-               printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
-                      (unsigned long long) e820.map[i].addr,
-                      (unsigned long long)
-                      (e820.map[i].addr + e820.map[i].size));
-               switch (e820.map[i].type) {
-               case E820_RAM:
-                       printk(KERN_CONT "(usable)\n");
-                       break;
-               case E820_RESERVED:
-                       printk(KERN_CONT "(reserved)\n");
-                       break;
-               case E820_ACPI:
-                       printk(KERN_CONT "(ACPI data)\n");
-                       break;
-               case E820_NVS:
-                       printk(KERN_CONT "(ACPI NVS)\n");
-                       break;
-               default:
-                       printk(KERN_CONT "type %u\n", e820.map[i].type);
-                       break;
-               }
-       }
-}
-
-/*
- * Sanitize the BIOS e820 map.
- *
- * Some e820 responses include overlapping entries. The following
- * replaces the original e820 map with a new one, removing overlaps.
- *
- */
-static int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map)
-{
-       struct change_member {
-               struct e820entry *pbios; /* pointer to original bios entry */
-               unsigned long long addr; /* address for this change point */
-       };
-       static struct change_member change_point_list[2*E820MAX] __initdata;
-       static struct change_member *change_point[2*E820MAX] __initdata;
-       static struct e820entry *overlap_list[E820MAX] __initdata;
-       static struct e820entry new_bios[E820MAX] __initdata;
-       struct change_member *change_tmp;
-       unsigned long current_type, last_type;
-       unsigned long long last_addr;
-       int chgidx, still_changing;
-       int overlap_entries;
-       int new_bios_entry;
-       int old_nr, new_nr, chg_nr;
-       int i;
-
-       /*
-               Visually we're performing the following
-               (1,2,3,4 = memory types)...
-
-               Sample memory map (w/overlaps):
-                  ____22__________________
-                  ______________________4_
-                  ____1111________________
-                  _44_____________________
-                  11111111________________
-                  ____________________33__
-                  ___________44___________
-                  __________33333_________
-                  ______________22________
-                  ___________________2222_
-                  _________111111111______
-                  _____________________11_
-                  _________________4______
-
-               Sanitized equivalent (no overlap):
-                  1_______________________
-                  _44_____________________
-                  ___1____________________
-                  ____22__________________
-                  ______11________________
-                  _________1______________
-                  __________3_____________
-                  ___________44___________
-                  _____________33_________
-                  _______________2________
-                  ________________1_______
-                  _________________4______
-                  ___________________2____
-                  ____________________33__
-                  ______________________4_
-       */
-
-       /* if there's only one memory region, don't bother */
-       if (*pnr_map < 2)
-               return -1;
-
-       old_nr = *pnr_map;
-
-       /* bail out if we find any unreasonable addresses in bios map */
-       for (i = 0; i < old_nr; i++)
-               if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
-                       return -1;
-
-       /* create pointers for initial change-point information (for sorting) */
-       for (i = 0; i < 2 * old_nr; i++)
-               change_point[i] = &change_point_list[i];
-
-       /* record all known change-points (starting and ending addresses),
-          omitting those that are for empty memory regions */
-       chgidx = 0;
-       for (i = 0; i < old_nr; i++)    {
-               if (biosmap[i].size != 0) {
-                       change_point[chgidx]->addr = biosmap[i].addr;
-                       change_point[chgidx++]->pbios = &biosmap[i];
-                       change_point[chgidx]->addr = biosmap[i].addr +
-                               biosmap[i].size;
-                       change_point[chgidx++]->pbios = &biosmap[i];
-               }
-       }
-       chg_nr = chgidx;
-
-       /* sort change-point list by memory addresses (low -> high) */
-       still_changing = 1;
-       while (still_changing)  {
-               still_changing = 0;
-               for (i = 1; i < chg_nr; i++)  {
-                       unsigned long long curaddr, lastaddr;
-                       unsigned long long curpbaddr, lastpbaddr;
-
-                       curaddr = change_point[i]->addr;
-                       lastaddr = change_point[i - 1]->addr;
-                       curpbaddr = change_point[i]->pbios->addr;
-                       lastpbaddr = change_point[i - 1]->pbios->addr;
-
-                       /*
-                        * swap entries, when:
-                        *
-                        * curaddr > lastaddr or
-                        * curaddr == lastaddr and curaddr == curpbaddr and
-                        * lastaddr != lastpbaddr
-                        */
-                       if (curaddr < lastaddr ||
-                           (curaddr == lastaddr && curaddr == curpbaddr &&
-                            lastaddr != lastpbaddr)) {
-                               change_tmp = change_point[i];
-                               change_point[i] = change_point[i-1];
-                               change_point[i-1] = change_tmp;
-                               still_changing = 1;
-                       }
-               }
-       }
-
-       /* create a new bios memory map, removing overlaps */
-       overlap_entries = 0;     /* number of entries in the overlap table */
-       new_bios_entry = 0;      /* index for creating new bios map entries */
-       last_type = 0;           /* start with undefined memory type */
-       last_addr = 0;           /* start with 0 as last starting address */
-
-       /* loop through change-points, determining affect on the new bios map */
-       for (chgidx = 0; chgidx < chg_nr; chgidx++) {
-               /* keep track of all overlapping bios entries */
-               if (change_point[chgidx]->addr ==
-                   change_point[chgidx]->pbios->addr) {
-                       /*
-                        * add map entry to overlap list (> 1 entry
-                        * implies an overlap)
-                        */
-                       overlap_list[overlap_entries++] =
-                               change_point[chgidx]->pbios;
-               } else {
-                       /*
-                        * remove entry from list (order independent,
-                        * so swap with last)
-                        */
-                       for (i = 0; i < overlap_entries; i++) {
-                               if (overlap_list[i] ==
-                                   change_point[chgidx]->pbios)
-                                       overlap_list[i] =
-                                               overlap_list[overlap_entries-1];
-                       }
-                       overlap_entries--;
-               }
-               /*
-                * if there are overlapping entries, decide which
-                * "type" to use (larger value takes precedence --
-                * 1=usable, 2,3,4,4+=unusable)
-                */
-               current_type = 0;
-               for (i = 0; i < overlap_entries; i++)
-                       if (overlap_list[i]->type > current_type)
-                               current_type = overlap_list[i]->type;
-               /*
-                * continue building up new bios map based on this
-                * information
-                */
-               if (current_type != last_type)  {
-                       if (last_type != 0)      {
-                               new_bios[new_bios_entry].size =
-                                       change_point[chgidx]->addr - last_addr;
-                               /*
-                                * move forward only if the new size
-                                * was non-zero
-                                */
-                               if (new_bios[new_bios_entry].size != 0)
-                                       /*
-                                        * no more space left for new
-                                        * bios entries ?
-                                        */
-                                       if (++new_bios_entry >= E820MAX)
-                                               break;
-                       }
-                       if (current_type != 0)  {
-                               new_bios[new_bios_entry].addr =
-                                       change_point[chgidx]->addr;
-                               new_bios[new_bios_entry].type = current_type;
-                               last_addr = change_point[chgidx]->addr;
-                       }
-                       last_type = current_type;
-               }
-       }
-       /* retain count for new bios entries */
-       new_nr = new_bios_entry;
-
-       /* copy new bios mapping into original location */
-       memcpy(biosmap, new_bios, new_nr * sizeof(struct e820entry));
-       *pnr_map = new_nr;
-
-       return 0;
-}
-
-/*
- * Copy the BIOS e820 map into a safe place.
- *
- * Sanity-check it while we're at it..
- *
- * If we're lucky and live on a modern system, the setup code
- * will have given us a memory map that we can use to properly
- * set up memory.  If we aren't, we'll fake a memory map.
- */
-static int __init copy_e820_map(struct e820entry *biosmap, int nr_map)
-{
-       /* Only one memory region (or negative)? Ignore it */
-       if (nr_map < 2)
-               return -1;
-
-       do {
-               u64 start = biosmap->addr;
-               u64 size = biosmap->size;
-               u64 end = start + size;
-               u32 type = biosmap->type;
-
-               /* Overflow in 64 bits? Ignore the memory map. */
-               if (start > end)
-                       return -1;
-
-               add_memory_region(start, size, type);
-       } while (biosmap++, --nr_map);
-       return 0;
-}
-
-static void early_panic(char *msg)
-{
-       early_printk(msg);
-       panic(msg);
-}
-
-/* We're not void only for x86 32-bit compat */
-char * __init machine_specific_memory_setup(void)
-{
-       char *who = "BIOS-e820";
-       /*
-        * Try to copy the BIOS-supplied E820-map.
-        *
-        * Otherwise fake a memory map; one section from 0k->640k,
-        * the next section from 1mb->appropriate_mem_k
-        */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
-       if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries) < 0)
-               early_panic("Cannot find a valid memory map");
-       printk(KERN_INFO "BIOS-provided physical RAM map:\n");
-       e820_print_map(who);
-
-       /* In case someone cares... */
-       return who;
-}
-
-static int __init parse_memopt(char *p)
-{
-       if (!p)
-               return -EINVAL;
-       end_user_pfn = memparse(p, &p);
-       end_user_pfn >>= PAGE_SHIFT;
-       return 0;
-}
-early_param("mem", parse_memopt);
-
-static int userdef __initdata;
-
-static int __init parse_memmap_opt(char *p)
-{
-       char *oldp;
-       unsigned long long start_at, mem_size;
-
-       if (!strcmp(p, "exactmap")) {
-#ifdef CONFIG_CRASH_DUMP
-               /*
-                * If we are doing a crash dump, we still need to know
-                * the real mem size before original memory map is
-                * reset.
-                */
-               e820_register_active_regions(0, 0, -1UL);
-               saved_max_pfn = e820_end_of_ram();
-               remove_all_active_ranges();
-#endif
-               max_pfn_mapped = 0;
-               e820.nr_map = 0;
-               userdef = 1;
-               return 0;
-       }
-
-       oldp = p;
-       mem_size = memparse(p, &p);
-       if (p == oldp)
-               return -EINVAL;
-
-       userdef = 1;
-       if (*p == '@') {
-               start_at = memparse(p+1, &p);
-               add_memory_region(start_at, mem_size, E820_RAM);
-       } else if (*p == '#') {
-               start_at = memparse(p+1, &p);
-               add_memory_region(start_at, mem_size, E820_ACPI);
-       } else if (*p == '$') {
-               start_at = memparse(p+1, &p);
-               add_memory_region(start_at, mem_size, E820_RESERVED);
-       } else {
-               end_user_pfn = (mem_size >> PAGE_SHIFT);
-       }
-       return *p == '\0' ? 0 : -EINVAL;
-}
-early_param("memmap", parse_memmap_opt);
-
-void __init finish_e820_parsing(void)
-{
-       if (userdef) {
-               char nr = e820.nr_map;
-
-               if (sanitize_e820_map(e820.map, &nr) < 0)
-                       early_panic("Invalid user supplied memory map");
-               e820.nr_map = nr;
-
-               printk(KERN_INFO "user-defined physical RAM map:\n");
-               e820_print_map("user");
-       }
-}
-
-void __init update_memory_range(u64 start, u64 size, unsigned old_type,
-                               unsigned new_type)
-{
-       int i;
-
-       BUG_ON(old_type == new_type);
-
-       for (i = 0; i < e820.nr_map; i++) {
-               struct e820entry *ei = &e820.map[i];
-               u64 final_start, final_end;
-               if (ei->type != old_type)
-                       continue;
-               /* totally covered? */
-               if (ei->addr >= start && ei->size <= size) {
-                       ei->type = new_type;
-                       continue;
-               }
-               /* partially covered */
-               final_start = max(start, ei->addr);
-               final_end = min(start + size, ei->addr + ei->size);
-               if (final_start >= final_end)
-                       continue;
-               add_memory_region(final_start, final_end - final_start,
-                                        new_type);
-       }
-}
-
-void __init update_e820(void)
-{
-       u8 nr_map;
-
-       nr_map = e820.nr_map;
-       if (sanitize_e820_map(e820.map, &nr_map))
-               return;
-       e820.nr_map = nr_map;
-       printk(KERN_INFO "modified physical RAM map:\n");
-       e820_print_map("modified");
-}
-
-unsigned long pci_mem_start = 0xaeedbabe;
-EXPORT_SYMBOL(pci_mem_start);
-
-/*
- * Search for the biggest gap in the low 32 bits of the e820
- * memory space.  We pass this space to PCI to assign MMIO resources
- * for hotplug or unconfigured devices in.
- * Hopefully the BIOS let enough space left.
- */
-__init void e820_setup_gap(void)
-{
-       unsigned long gapstart, gapsize, round;
-       unsigned long last;
-       int i;
-       int found = 0;
-
-       last = 0x100000000ull;
-       gapstart = 0x10000000;
-       gapsize = 0x400000;
-       i = e820.nr_map;
-       while (--i >= 0) {
-               unsigned long long start = e820.map[i].addr;
-               unsigned long long end = start + e820.map[i].size;
-
-               /*
-                * Since "last" is at most 4GB, we know we'll
-                * fit in 32 bits if this condition is true
-                */
-               if (last > end) {
-                       unsigned long gap = last - end;
-
-                       if (gap > gapsize) {
-                               gapsize = gap;
-                               gapstart = end;
-                               found = 1;
-                       }
-               }
-               if (start < last)
-                       last = start;
-       }
-
-       if (!found) {
-               gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
-               printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
-                      "address range\n"
-                      KERN_ERR "PCI: Unassigned devices with 32bit resource "
-                      "registers may break!\n");
-       }
-
-       /*
-        * See how much we want to round up: start off with
-        * rounding to the next 1MB area.
-        */
-       round = 0x100000;
-       while ((gapsize >> 4) > round)
-               round += round;
-       /* Fun with two's complement */
-       pci_mem_start = (gapstart + round) & -round;
-
-       printk(KERN_INFO
-              "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
-              pci_mem_start, gapstart, gapsize);
-}
-
-int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
-{
-       int i;
-
-       if (slot < 0 || slot >= e820.nr_map)
-               return -1;
-       for (i = slot; i < e820.nr_map; i++) {
-               if (e820.map[i].type != E820_RAM)
-                       continue;
-               break;
-       }
-       if (i == e820.nr_map || e820.map[i].addr > (max_pfn << PAGE_SHIFT))
-               return -1;
-       *addr = e820.map[i].addr;
-       *size = min_t(u64, e820.map[i].size + e820.map[i].addr,
-               max_pfn << PAGE_SHIFT) - *addr;
-       return i + 1;
-}
index 9f51e1e..a4665f3 100644 (file)
@@ -50,7 +50,7 @@ static void __init fix_hypertransport_config(int num, int slot, int func)
 static void __init via_bugs(int  num, int slot, int func)
 {
 #ifdef CONFIG_GART_IOMMU
-       if ((end_pfn > MAX_DMA32_PFN ||  force_iommu) &&
+       if ((max_pfn > MAX_DMA32_PFN ||  force_iommu) &&
            !gart_iommu_aperture_allowed) {
                printk(KERN_INFO
                       "Looks like a VIA chipset. Disabling IOMMU."
@@ -98,17 +98,6 @@ static void __init nvidia_bugs(int num, int slot, int func)
 
 }
 
-static void __init ati_bugs(int num, int slot, int func)
-{
-#ifdef CONFIG_X86_IO_APIC
-       if (timer_over_8254 == 1) {
-               timer_over_8254 = 0;
-               printk(KERN_INFO
-               "ATI board detected. Disabling timer routing over 8254.\n");
-       }
-#endif
-}
-
 #define QFLAG_APPLY_ONCE       0x1
 #define QFLAG_APPLIED          0x2
 #define QFLAG_DONE             (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
@@ -126,8 +115,6 @@ static struct chipset early_qrk[] __initdata = {
          PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
        { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
          PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
-       { PCI_VENDOR_ID_ATI, PCI_ANY_ID,
-         PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, ati_bugs },
        { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
          PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
        {}
index 643fd86..ff9e735 100644 (file)
@@ -196,7 +196,7 @@ static struct console simnow_console = {
 static struct console *early_console = &early_vga_console;
 static int early_console_initialized;
 
-void early_printk(const char *fmt, ...)
+asmlinkage void early_printk(const char *fmt, ...)
 {
        char buf[512];
        int n;
index 77d424c..06cc8d4 100644 (file)
@@ -64,6 +64,17 @@ static int __init setup_noefi(char *arg)
 }
 early_param("noefi", setup_noefi);
 
+int add_efi_memmap;
+EXPORT_SYMBOL(add_efi_memmap);
+
+static int __init setup_add_efi_memmap(char *arg)
+{
+       add_efi_memmap = 1;
+       return 0;
+}
+early_param("add_efi_memmap", setup_add_efi_memmap);
+
+
 static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
 {
        return efi_call_virt2(get_time, tm, tc);
@@ -213,6 +224,50 @@ unsigned long efi_get_time(void)
                      eft.minute, eft.second);
 }
 
+/*
+ * Tell the kernel about the EFI memory map.  This might include
+ * more than the max 128 entries that can fit in the e820 legacy
+ * (zeropage) memory map.
+ */
+
+static void __init do_add_efi_memmap(void)
+{
+       void *p;
+
+       for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
+               efi_memory_desc_t *md = p;
+               unsigned long long start = md->phys_addr;
+               unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
+               int e820_type;
+
+               if (md->attribute & EFI_MEMORY_WB)
+                       e820_type = E820_RAM;
+               else
+                       e820_type = E820_RESERVED;
+               e820_add_region(start, size, e820_type);
+       }
+       sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+}
+
+void __init efi_reserve_early(void)
+{
+       unsigned long pmap;
+
+#ifdef CONFIG_X86_32
+       pmap = boot_params.efi_info.efi_memmap;
+#else
+       pmap = (boot_params.efi_info.efi_memmap |
+               ((__u64)boot_params.efi_info.efi_memmap_hi<<32));
+#endif
+       memmap.phys_map = (void *)pmap;
+       memmap.nr_map = boot_params.efi_info.efi_memmap_size /
+               boot_params.efi_info.efi_memdesc_size;
+       memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
+       memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
+       reserve_early(pmap, pmap + memmap.nr_map * memmap.desc_size,
+                     "EFI memmap");
+}
+
 #if EFI_DEBUG
 static void __init print_efi_memmap(void)
 {
@@ -244,19 +299,11 @@ void __init efi_init(void)
 
 #ifdef CONFIG_X86_32
        efi_phys.systab = (efi_system_table_t *)boot_params.efi_info.efi_systab;
-       memmap.phys_map = (void *)boot_params.efi_info.efi_memmap;
 #else
        efi_phys.systab = (efi_system_table_t *)
                (boot_params.efi_info.efi_systab |
                 ((__u64)boot_params.efi_info.efi_systab_hi<<32));
-       memmap.phys_map = (void *)
-               (boot_params.efi_info.efi_memmap |
-                ((__u64)boot_params.efi_info.efi_memmap_hi<<32));
 #endif
-       memmap.nr_map = boot_params.efi_info.efi_memmap_size /
-               boot_params.efi_info.efi_memdesc_size;
-       memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
-       memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
 
        efi.systab = early_ioremap((unsigned long)efi_phys.systab,
                                   sizeof(efi_system_table_t));
@@ -370,6 +417,8 @@ void __init efi_init(void)
        if (memmap.desc_size != sizeof(efi_memory_desc_t))
                printk(KERN_WARNING "Kernel-defined memdesc"
                       "doesn't match the one from EFI!\n");
+       if (add_efi_memmap)
+               do_add_efi_memmap();
 
        /* Setup for EFI runtime service */
        reboot_type = BOOT_EFI;
@@ -424,7 +473,7 @@ void __init efi_enter_virtual_mode(void)
                size = md->num_pages << EFI_PAGE_SHIFT;
                end = md->phys_addr + size;
 
-               if (PFN_UP(end) <= max_pfn_mapped)
+               if (PFN_UP(end) <= max_low_pfn_mapped)
                        va = __va(md->phys_addr);
                else
                        va = efi_ioremap(md->phys_addr, size);
index d0060fd..652c528 100644 (file)
@@ -97,13 +97,7 @@ void __init efi_call_phys_epilog(void)
        early_runtime_code_mapping_set_exec(0);
 }
 
-void __init efi_reserve_bootmem(void)
-{
-       reserve_bootmem_generic((unsigned long)memmap.phys_map,
-                               memmap.nr_map * memmap.desc_size);
-}
-
-void __iomem * __init efi_ioremap(unsigned long phys_addr, unsigned long size)
+void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size)
 {
        static unsigned pages_mapped __initdata;
        unsigned i, pages;
index c778e4f..6bc07f0 100644 (file)
 #include <asm/percpu.h>
 #include <asm/dwarf2.h>
 #include <asm/processor-flags.h>
-#include "irq_vectors.h"
+#include <asm/ftrace.h>
+#include <asm/irq_vectors.h>
 
 /*
  * We use macros for low-level operations which need to be overridden
  * for paravirtualization.  The following will never clobber any registers:
  *   INTERRUPT_RETURN (aka. "iret")
  *   GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
- *   ENABLE_INTERRUPTS_SYSCALL_RET (aka "sti; sysexit").
+ *   ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
  *
  * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
  * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
@@ -349,7 +350,7 @@ sysenter_past_esp:
        xorl %ebp,%ebp
        TRACE_IRQS_ON
 1:     mov  PT_FS(%esp), %fs
-       ENABLE_INTERRUPTS_SYSCALL_RET
+       ENABLE_INTERRUPTS_SYSEXIT
        CFI_ENDPROC
 .pushsection .fixup,"ax"
 2:     movl $0,PT_FS(%esp)
@@ -874,10 +875,10 @@ ENTRY(native_iret)
 .previous
 END(native_iret)
 
-ENTRY(native_irq_enable_syscall_ret)
+ENTRY(native_irq_enable_sysexit)
        sti
        sysexit
-END(native_irq_enable_syscall_ret)
+END(native_irq_enable_sysexit)
 #endif
 
 KPROBE_ENTRY(int3)
@@ -1024,6 +1025,7 @@ ENTRY(xen_sysenter_target)
        RING0_INT_FRAME
        addl $5*4, %esp         /* remove xen-provided frame */
        jmp sysenter_past_esp
+       CFI_ENDPROC
 
 ENTRY(xen_hypervisor_callback)
        CFI_STARTPROC
@@ -1110,6 +1112,77 @@ ENDPROC(xen_failsafe_callback)
 
 #endif /* CONFIG_XEN */
 
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+
+ENTRY(mcount)
+       pushl %eax
+       pushl %ecx
+       pushl %edx
+       movl 0xc(%esp), %eax
+       subl $MCOUNT_INSN_SIZE, %eax
+
+.globl mcount_call
+mcount_call:
+       call ftrace_stub
+
+       popl %edx
+       popl %ecx
+       popl %eax
+
+       ret
+END(mcount)
+
+ENTRY(ftrace_caller)
+       pushl %eax
+       pushl %ecx
+       pushl %edx
+       movl 0xc(%esp), %eax
+       movl 0x4(%ebp), %edx
+       subl $MCOUNT_INSN_SIZE, %eax
+
+.globl ftrace_call
+ftrace_call:
+       call ftrace_stub
+
+       popl %edx
+       popl %ecx
+       popl %eax
+
+.globl ftrace_stub
+ftrace_stub:
+       ret
+END(ftrace_caller)
+
+#else /* ! CONFIG_DYNAMIC_FTRACE */
+
+ENTRY(mcount)
+       cmpl $ftrace_stub, ftrace_trace_function
+       jnz trace
+.globl ftrace_stub
+ftrace_stub:
+       ret
+
+       /* taken from glibc */
+trace:
+       pushl %eax
+       pushl %ecx
+       pushl %edx
+       movl 0xc(%esp), %eax
+       movl 0x4(%ebp), %edx
+       subl $MCOUNT_INSN_SIZE, %eax
+
+       call *ftrace_trace_function
+
+       popl %edx
+       popl %ecx
+       popl %eax
+
+       jmp ftrace_stub
+END(mcount)
+#endif /* CONFIG_DYNAMIC_FTRACE */
+#endif /* CONFIG_FTRACE */
+
 .section .rodata,"a"
 #include "syscall_table_32.S"
 
index 556a8df..ba41bf4 100644 (file)
 #include <asm/page.h>
 #include <asm/irqflags.h>
 #include <asm/paravirt.h>
+#include <asm/ftrace.h>
 
        .code64
 
+#ifdef CONFIG_FTRACE
+#ifdef CONFIG_DYNAMIC_FTRACE
+ENTRY(mcount)
+
+       subq $0x38, %rsp
+       movq %rax, (%rsp)
+       movq %rcx, 8(%rsp)
+       movq %rdx, 16(%rsp)
+       movq %rsi, 24(%rsp)
+       movq %rdi, 32(%rsp)
+       movq %r8, 40(%rsp)
+       movq %r9, 48(%rsp)
+
+       movq 0x38(%rsp), %rdi
+       subq $MCOUNT_INSN_SIZE, %rdi
+
+.globl mcount_call
+mcount_call:
+       call ftrace_stub
+
+       movq 48(%rsp), %r9
+       movq 40(%rsp), %r8
+       movq 32(%rsp), %rdi
+       movq 24(%rsp), %rsi
+       movq 16(%rsp), %rdx
+       movq 8(%rsp), %rcx
+       movq (%rsp), %rax
+       addq $0x38, %rsp
+
+       retq
+END(mcount)
+
+ENTRY(ftrace_caller)
+
+       /* taken from glibc */
+       subq $0x38, %rsp
+       movq %rax, (%rsp)
+       movq %rcx, 8(%rsp)
+       movq %rdx, 16(%rsp)
+       movq %rsi, 24(%rsp)
+       movq %rdi, 32(%rsp)
+       movq %r8, 40(%rsp)
+       movq %r9, 48(%rsp)
+
+       movq 0x38(%rsp), %rdi
+       movq 8(%rbp), %rsi
+       subq $MCOUNT_INSN_SIZE, %rdi
+
+.globl ftrace_call
+ftrace_call:
+       call ftrace_stub
+
+       movq 48(%rsp), %r9
+       movq 40(%rsp), %r8
+       movq 32(%rsp), %rdi
+       movq 24(%rsp), %rsi
+       movq 16(%rsp), %rdx
+       movq 8(%rsp), %rcx
+       movq (%rsp), %rax
+       addq $0x38, %rsp
+
+.globl ftrace_stub
+ftrace_stub:
+       retq
+END(ftrace_caller)
+
+#else /* ! CONFIG_DYNAMIC_FTRACE */
+ENTRY(mcount)
+       cmpq $ftrace_stub, ftrace_trace_function
+       jnz trace
+.globl ftrace_stub
+ftrace_stub:
+       retq
+
+trace:
+       /* taken from glibc */
+       subq $0x38, %rsp
+       movq %rax, (%rsp)
+       movq %rcx, 8(%rsp)
+       movq %rdx, 16(%rsp)
+       movq %rsi, 24(%rsp)
+       movq %rdi, 32(%rsp)
+       movq %r8, 40(%rsp)
+       movq %r9, 48(%rsp)
+
+       movq 0x38(%rsp), %rdi
+       movq 8(%rbp), %rsi
+       subq $MCOUNT_INSN_SIZE, %rdi
+
+       call   *ftrace_trace_function
+
+       movq 48(%rsp), %r9
+       movq 40(%rsp), %r8
+       movq 32(%rsp), %rdi
+       movq 24(%rsp), %rsi
+       movq 16(%rsp), %rdx
+       movq 8(%rsp), %rcx
+       movq (%rsp), %rax
+       addq $0x38, %rsp
+
+       jmp ftrace_stub
+END(mcount)
+#endif /* CONFIG_DYNAMIC_FTRACE */
+#endif /* CONFIG_FTRACE */
+
 #ifndef CONFIG_PREEMPT
 #define retint_kernel retint_restore_args
 #endif 
 
 #ifdef CONFIG_PARAVIRT
-ENTRY(native_irq_enable_syscall_ret)
-       movq    %gs:pda_oldrsp,%rsp
+ENTRY(native_usergs_sysret64)
        swapgs
        sysretq
 #endif /* CONFIG_PARAVIRT */
@@ -104,7 +209,7 @@ ENTRY(native_irq_enable_syscall_ret)
        .macro FAKE_STACK_FRAME child_rip
        /* push in order ss, rsp, eflags, cs, rip */
        xorl %eax, %eax
-       pushq %rax /* ss */
+       pushq $__KERNEL_DS /* ss */
        CFI_ADJUST_CFA_OFFSET   8
        /*CFI_REL_OFFSET        ss,0*/
        pushq %rax /* rsp */
@@ -169,13 +274,13 @@ ENTRY(ret_from_fork)
        CFI_ADJUST_CFA_OFFSET -4
        call schedule_tail
        GET_THREAD_INFO(%rcx)
-       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%rcx)
+       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
        jnz rff_trace
 rff_action:    
        RESTORE_REST
        testl $3,CS-ARGOFFSET(%rsp)     # from kernel_thread?
        je   int_ret_from_sys_call
-       testl $_TIF_IA32,threadinfo_flags(%rcx)
+       testl $_TIF_IA32,TI_flags(%rcx)
        jnz  int_ret_from_sys_call
        RESTORE_TOP_OF_STACK %rdi,ARGOFFSET
        jmp ret_from_sys_call
@@ -244,7 +349,8 @@ ENTRY(system_call_after_swapgs)
        movq  %rcx,RIP-ARGOFFSET(%rsp)
        CFI_REL_OFFSET rip,RIP-ARGOFFSET
        GET_THREAD_INFO(%rcx)
-       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx)
+       testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
+               TI_flags(%rcx)
        jnz tracesys
        cmpq $__NR_syscall_max,%rax
        ja badsys
@@ -263,7 +369,7 @@ sysret_check:
        GET_THREAD_INFO(%rcx)
        DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
-       movl threadinfo_flags(%rcx),%edx
+       movl TI_flags(%rcx),%edx
        andl %edi,%edx
        jnz  sysret_careful 
        CFI_REMEMBER_STATE
@@ -275,7 +381,8 @@ sysret_check:
        CFI_REGISTER    rip,rcx
        RESTORE_ARGS 0,-ARG_SKIP,1
        /*CFI_REGISTER  rflags,r11*/
-       ENABLE_INTERRUPTS_SYSCALL_RET
+       movq    %gs:pda_oldrsp, %rsp
+       USERGS_SYSRET64
 
        CFI_RESTORE_STATE
        /* Handle reschedules */
@@ -305,7 +412,7 @@ sysret_signal:
        leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
        xorl %esi,%esi # oldset -> arg2
        call ptregscall_common
-1:     movl $_TIF_NEED_RESCHED,%edi
+1:     movl $_TIF_WORK_MASK,%edi
        /* Use IRET because user could have changed frame. This
           works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
        DISABLE_INTERRUPTS(CLBR_NONE)
@@ -347,10 +454,10 @@ int_ret_from_sys_call:
 int_with_check:
        LOCKDEP_SYS_EXIT_IRQ
        GET_THREAD_INFO(%rcx)
-       movl threadinfo_flags(%rcx),%edx
+       movl TI_flags(%rcx),%edx
        andl %edi,%edx
        jnz   int_careful
-       andl    $~TS_COMPAT,threadinfo_status(%rcx)
+       andl    $~TS_COMPAT,TI_status(%rcx)
        jmp   retint_swapgs
 
        /* Either reschedule or signal or syscall exit tracking needed. */
@@ -393,7 +500,7 @@ int_signal:
        movq %rsp,%rdi          # &ptregs -> arg1
        xorl %esi,%esi          # oldset -> arg2
        call do_notify_resume
-1:     movl $_TIF_NEED_RESCHED,%edi    
+1:     movl $_TIF_WORK_MASK,%edi
 int_restore_rest:
        RESTORE_REST
        DISABLE_INTERRUPTS(CLBR_NONE)
@@ -420,7 +527,6 @@ END(\label)
        PTREGSCALL stub_clone, sys_clone, %r8
        PTREGSCALL stub_fork, sys_fork, %rdi
        PTREGSCALL stub_vfork, sys_vfork, %rdi
-       PTREGSCALL stub_rt_sigsuspend, sys_rt_sigsuspend, %rdx
        PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
        PTREGSCALL stub_iopl, sys_iopl, %rsi
 
@@ -559,7 +665,7 @@ retint_with_reschedule:
        movl $_TIF_WORK_MASK,%edi
 retint_check:
        LOCKDEP_SYS_EXIT_IRQ
-       movl threadinfo_flags(%rcx),%edx
+       movl TI_flags(%rcx),%edx
        andl %edi,%edx
        CFI_REMEMBER_STATE
        jnz  retint_careful
@@ -647,17 +753,16 @@ retint_signal:
        RESTORE_REST
        DISABLE_INTERRUPTS(CLBR_NONE)
        TRACE_IRQS_OFF
-       movl $_TIF_NEED_RESCHED,%edi
        GET_THREAD_INFO(%rcx)
-       jmp retint_check
+       jmp retint_with_reschedule
 
 #ifdef CONFIG_PREEMPT
        /* Returning to kernel space. Check if we need preemption */
        /* rcx:  threadinfo. interrupts off. */
 ENTRY(retint_kernel)
-       cmpl $0,threadinfo_preempt_count(%rcx)
+       cmpl $0,TI_preempt_count(%rcx)
        jnz  retint_restore_args
-       bt  $TIF_NEED_RESCHED,threadinfo_flags(%rcx)
+       bt  $TIF_NEED_RESCHED,TI_flags(%rcx)
        jnc  retint_restore_args
        bt   $9,EFLAGS-ARGOFFSET(%rsp)  /* interrupts off? */
        jnc  retint_restore_args
@@ -720,6 +825,10 @@ ENTRY(apic_timer_interrupt)
        apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt
 END(apic_timer_interrupt)
 
+ENTRY(uv_bau_message_intr1)
+       apicinterrupt 220,uv_bau_message_interrupt
+END(uv_bau_message_intr1)
+
 ENTRY(error_interrupt)
        apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt
 END(error_interrupt)
@@ -733,6 +842,7 @@ END(spurious_interrupt)
  */            
        .macro zeroentry sym
        INTR_FRAME
+       PARAVIRT_ADJUST_EXCEPTION_FRAME
        pushq $0        /* push error code/oldrax */ 
        CFI_ADJUST_CFA_OFFSET 8
        pushq %rax      /* push real oldrax to the rdi slot */ 
@@ -745,6 +855,7 @@ END(spurious_interrupt)
 
        .macro errorentry sym
        XCPT_FRAME
+       PARAVIRT_ADJUST_EXCEPTION_FRAME
        pushq %rax
        CFI_ADJUST_CFA_OFFSET 8
        CFI_REL_OFFSET rax,0
@@ -814,7 +925,7 @@ paranoid_restore\trace:
        jmp irq_return
 paranoid_userspace\trace:
        GET_THREAD_INFO(%rcx)
-       movl threadinfo_flags(%rcx),%ebx
+       movl TI_flags(%rcx),%ebx
        andl $_TIF_WORK_MASK,%ebx
        jz paranoid_swapgs\trace
        movq %rsp,%rdi                  /* &pt_regs */
@@ -912,7 +1023,7 @@ error_exit:
        testl %eax,%eax
        jne  retint_kernel
        LOCKDEP_SYS_EXIT_IRQ
-       movl  threadinfo_flags(%rcx),%edx
+       movl  TI_flags(%rcx),%edx
        movl  $_TIF_WORK_MASK,%edi
        andl  %edi,%edx
        jnz  retint_careful
@@ -926,11 +1037,11 @@ error_kernelspace:
           iret run with kernel gs again, so don't set the user space flag.
           B stepping K8s sometimes report an truncated RIP for IRET 
           exceptions returning to compat mode. Check for these here too. */
-       leaq irq_return(%rip),%rbp
-       cmpq %rbp,RIP(%rsp) 
+       leaq irq_return(%rip),%rcx
+       cmpq %rcx,RIP(%rsp)
        je   error_swapgs
-       movl %ebp,%ebp  /* zero extend */
-       cmpq %rbp,RIP(%rsp) 
+       movl %ecx,%ecx  /* zero extend */
+       cmpq %rcx,RIP(%rsp)
        je   error_swapgs
        cmpq $gs_change,RIP(%rsp)
         je   error_swapgs
@@ -939,7 +1050,7 @@ KPROBE_END(error_entry)
        
        /* Reload gs selector with exception handling */
        /* edi:  new selector */ 
-ENTRY(load_gs_index)
+ENTRY(native_load_gs_index)
        CFI_STARTPROC
        pushf
        CFI_ADJUST_CFA_OFFSET 8
@@ -953,7 +1064,7 @@ gs_change:
        CFI_ADJUST_CFA_OFFSET -8
         ret
        CFI_ENDPROC
-ENDPROC(load_gs_index)
+ENDPROC(native_load_gs_index)
        
         .section __ex_table,"a"
         .align 8
@@ -1120,10 +1231,6 @@ ENTRY(coprocessor_segment_overrun)
        zeroentry do_coprocessor_segment_overrun
 END(coprocessor_segment_overrun)
 
-ENTRY(reserved)
-       zeroentry do_reserved
-END(reserved)
-
        /* runs on exception stack */
 ENTRY(double_fault)
        XCPT_FRAME
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
new file mode 100644 (file)
index 0000000..ab115cd
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Code for replacing ftrace calls with jumps.
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ *
+ * Thanks goes to Ingo Molnar, for suggesting the idea.
+ * Mathieu Desnoyers, for suggesting postponing the modifications.
+ * Arjan van de Ven, for keeping me straight, and explaining to me
+ * the dangers of modifying code on the run.
+ */
+
+#include <linux/spinlock.h>
+#include <linux/hardirq.h>
+#include <linux/ftrace.h>
+#include <linux/percpu.h>
+#include <linux/init.h>
+#include <linux/list.h>
+
+#include <asm/alternative.h>
+#include <asm/ftrace.h>
+
+
+/* Long is fine, even if it is only 4 bytes ;-) */
+static long *ftrace_nop;
+
+union ftrace_code_union {
+       char code[MCOUNT_INSN_SIZE];
+       struct {
+               char e8;
+               int offset;
+       } __attribute__((packed));
+};
+
+
+static int notrace ftrace_calc_offset(long ip, long addr)
+{
+       return (int)(addr - ip);
+}
+
+notrace unsigned char *ftrace_nop_replace(void)
+{
+       return (char *)ftrace_nop;
+}
+
+notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
+{
+       static union ftrace_code_union calc;
+
+       calc.e8         = 0xe8;
+       calc.offset     = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
+
+       /*
+        * No locking needed, this must be called via kstop_machine
+        * which in essence is like running on a uniprocessor machine.
+        */
+       return calc.code;
+}
+
+notrace int
+ftrace_modify_code(unsigned long ip, unsigned char *old_code,
+                  unsigned char *new_code)
+{
+       unsigned replaced;
+       unsigned old = *(unsigned *)old_code; /* 4 bytes */
+       unsigned new = *(unsigned *)new_code; /* 4 bytes */
+       unsigned char newch = new_code[4];
+       int faulted = 0;
+
+       /*
+        * Note: Due to modules and __init, code can
+        *  disappear and change, we need to protect against faulting
+        *  as well as code changing.
+        *
+        * No real locking needed, this code is run through
+        * kstop_machine.
+        */
+       asm volatile (
+               "1: lock\n"
+               "   cmpxchg %3, (%2)\n"
+               "   jnz 2f\n"
+               "   movb %b4, 4(%2)\n"
+               "2:\n"
+               ".section .fixup, \"ax\"\n"
+               "3:     movl $1, %0\n"
+               "       jmp 2b\n"
+               ".previous\n"
+               _ASM_EXTABLE(1b, 3b)
+               : "=r"(faulted), "=a"(replaced)
+               : "r"(ip), "r"(new), "c"(newch),
+                 "0"(faulted), "a"(old)
+               : "memory");
+       sync_core();
+
+       if (replaced != old && replaced != new)
+               faulted = 2;
+
+       return faulted;
+}
+
+notrace int ftrace_update_ftrace_func(ftrace_func_t func)
+{
+       unsigned long ip = (unsigned long)(&ftrace_call);
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+       int ret;
+
+       memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, (unsigned long)func);
+       ret = ftrace_modify_code(ip, old, new);
+
+       return ret;
+}
+
+notrace int ftrace_mcount_set(unsigned long *data)
+{
+       unsigned long ip = (long)(&mcount_call);
+       unsigned long *addr = data;
+       unsigned char old[MCOUNT_INSN_SIZE], *new;
+
+       /*
+        * Replace the mcount stub with a pointer to the
+        * ip recorder function.
+        */
+       memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
+       new = ftrace_call_replace(ip, *addr);
+       *addr = ftrace_modify_code(ip, old, new);
+
+       return 0;
+}
+
+int __init ftrace_dyn_arch_init(void *data)
+{
+       const unsigned char *const *noptable = find_nop_table();
+
+       /* This is running in kstop_machine */
+
+       ftrace_mcount_set(data);
+
+       ftrace_nop = (unsigned long *)noptable[MCOUNT_INSN_SIZE];
+
+       return 0;
+}
index cbaaf69..1fa8be5 100644 (file)
@@ -51,7 +51,7 @@ void __init setup_apic_routing(void)
        else
 #endif
 
-       if (num_possible_cpus() <= 8)
+       if (max_physical_apicid < 8)
                genapic = &apic_flat;
        else
                genapic = &apic_physflat;
index ebf1390..711f11c 100644 (file)
@@ -5,9 +5,10 @@
  *
  * SGI UV APIC functions (note: not an Intel compatible APIC)
  *
- * Copyright (C) 2007 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved.
  */
 
+#include <linux/kernel.h>
 #include <linux/threads.h>
 #include <linux/cpumask.h>
 #include <linux/string.h>
@@ -20,6 +21,7 @@
 #include <asm/smp.h>
 #include <asm/ipi.h>
 #include <asm/genapic.h>
+#include <asm/pgtable.h>
 #include <asm/uv/uv_mmrs.h>
 #include <asm/uv/uv_hub.h>
 
@@ -55,37 +57,37 @@ static cpumask_t uv_vector_allocation_domain(int cpu)
 int uv_wakeup_secondary(int phys_apicid, unsigned int start_rip)
 {
        unsigned long val;
-       int nasid;
+       int pnode;
 
-       nasid = uv_apicid_to_nasid(phys_apicid);
+       pnode = uv_apicid_to_pnode(phys_apicid);
        val = (1UL << UVH_IPI_INT_SEND_SHFT) |
            (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
            (((long)start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
            APIC_DM_INIT;
-       uv_write_global_mmr64(nasid, UVH_IPI_INT, val);
+       uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
        mdelay(10);
 
        val = (1UL << UVH_IPI_INT_SEND_SHFT) |
            (phys_apicid << UVH_IPI_INT_APIC_ID_SHFT) |
            (((long)start_rip << UVH_IPI_INT_VECTOR_SHFT) >> 12) |
            APIC_DM_STARTUP;
-       uv_write_global_mmr64(nasid, UVH_IPI_INT, val);
+       uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
        return 0;
 }
 
 static void uv_send_IPI_one(int cpu, int vector)
 {
        unsigned long val, apicid, lapicid;
-       int nasid;
+       int pnode;
 
        apicid = per_cpu(x86_cpu_to_apicid, cpu); /* ZZZ - cache node-local ? */
        lapicid = apicid & 0x3f;                /* ZZZ macro needed */
-       nasid = uv_apicid_to_nasid(apicid);
+       pnode = uv_apicid_to_pnode(apicid);
        val =
            (1UL << UVH_IPI_INT_SEND_SHFT) | (lapicid <<
                                              UVH_IPI_INT_APIC_ID_SHFT) |
            (vector << UVH_IPI_INT_VECTOR_SHFT);
-       uv_write_global_mmr64(nasid, UVH_IPI_INT, val);
+       uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
 }
 
 static void uv_send_IPI_mask(cpumask_t mask, int vector)
@@ -159,39 +161,146 @@ struct genapic apic_x2apic_uv_x = {
        .phys_pkg_id = phys_pkg_id,     /* Fixme ZZZ */
 };
 
-static __cpuinit void set_x2apic_extra_bits(int nasid)
+static __cpuinit void set_x2apic_extra_bits(int pnode)
 {
-       __get_cpu_var(x2apic_extra_bits) = ((nasid >> 1) << 6);
+       __get_cpu_var(x2apic_extra_bits) = (pnode << 6);
 }
 
 /*
  * Called on boot cpu.
  */
+static __init int boot_pnode_to_blade(int pnode)
+{
+       int blade;
+
+       for (blade = 0; blade < uv_num_possible_blades(); blade++)
+               if (pnode == uv_blade_info[blade].pnode)
+                       return blade;
+       BUG();
+}
+
+struct redir_addr {
+       unsigned long redirect;
+       unsigned long alias;
+};
+
+#define DEST_SHIFT UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT
+
+static __initdata struct redir_addr redir_addrs[] = {
+       {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR, UVH_SI_ALIAS0_OVERLAY_CONFIG},
+       {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR, UVH_SI_ALIAS1_OVERLAY_CONFIG},
+       {UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR, UVH_SI_ALIAS2_OVERLAY_CONFIG},
+};
+
+static __init void get_lowmem_redirect(unsigned long *base, unsigned long *size)
+{
+       union uvh_si_alias0_overlay_config_u alias;
+       union uvh_rh_gam_alias210_redirect_config_2_mmr_u redirect;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(redir_addrs); i++) {
+               alias.v = uv_read_local_mmr(redir_addrs[i].alias);
+               if (alias.s.base == 0) {
+                       *size = (1UL << alias.s.m_alias);
+                       redirect.v = uv_read_local_mmr(redir_addrs[i].redirect);
+                       *base = (unsigned long)redirect.s.dest_base << DEST_SHIFT;
+                       return;
+               }
+       }
+       BUG();
+}
+
+static __init void map_low_mmrs(void)
+{
+       init_extra_mapping_uc(UV_GLOBAL_MMR32_BASE, UV_GLOBAL_MMR32_SIZE);
+       init_extra_mapping_uc(UV_LOCAL_MMR_BASE, UV_LOCAL_MMR_SIZE);
+}
+
+enum map_type {map_wb, map_uc};
+
+static void map_high(char *id, unsigned long base, int shift, enum map_type map_type)
+{
+       unsigned long bytes, paddr;
+
+       paddr = base << shift;
+       bytes = (1UL << shift);
+       printk(KERN_INFO "UV: Map %s_HI 0x%lx - 0x%lx\n", id, paddr,
+                                               paddr + bytes);
+       if (map_type == map_uc)
+               init_extra_mapping_uc(paddr, bytes);
+       else
+               init_extra_mapping_wb(paddr, bytes);
+
+}
+static __init void map_gru_high(int max_pnode)
+{
+       union uvh_rh_gam_gru_overlay_config_mmr_u gru;
+       int shift = UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT;
+
+       gru.v = uv_read_local_mmr(UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR);
+       if (gru.s.enable)
+               map_high("GRU", gru.s.base, shift, map_wb);
+}
+
+static __init void map_config_high(int max_pnode)
+{
+       union uvh_rh_gam_cfg_overlay_config_mmr_u cfg;
+       int shift = UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_SHFT;
+
+       cfg.v = uv_read_local_mmr(UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR);
+       if (cfg.s.enable)
+               map_high("CONFIG", cfg.s.base, shift, map_uc);
+}
+
+static __init void map_mmr_high(int max_pnode)
+{
+       union uvh_rh_gam_mmr_overlay_config_mmr_u mmr;
+       int shift = UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR_BASE_SHFT;
+
+       mmr.v = uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR);
+       if (mmr.s.enable)
+               map_high("MMR", mmr.s.base, shift, map_uc);
+}
+
+static __init void map_mmioh_high(int max_pnode)
+{
+       union uvh_rh_gam_mmioh_overlay_config_mmr_u mmioh;
+       int shift = UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT;
+
+       mmioh.v = uv_read_local_mmr(UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR);
+       if (mmioh.s.enable)
+               map_high("MMIOH", mmioh.s.base, shift, map_uc);
+}
+
 static __init void uv_system_init(void)
 {
        union uvh_si_addr_map_config_u m_n_config;
-       int bytes, nid, cpu, lcpu, nasid, last_nasid, blade;
-       unsigned long mmr_base;
+       union uvh_node_id_u node_id;
+       unsigned long gnode_upper, lowmem_redir_base, lowmem_redir_size;
+       int bytes, nid, cpu, lcpu, pnode, blade, i, j, m_val, n_val;
+       int max_pnode = 0;
+       unsigned long mmr_base, present;
+
+       map_low_mmrs();
 
        m_n_config.v = uv_read_local_mmr(UVH_SI_ADDR_MAP_CONFIG);
+       m_val = m_n_config.s.m_skt;
+       n_val = m_n_config.s.n_skt;
        mmr_base =
            uv_read_local_mmr(UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR) &
            ~UV_MMR_ENABLE;
        printk(KERN_DEBUG "UV: global MMR base 0x%lx\n", mmr_base);
 
-       last_nasid = -1;
-       for_each_possible_cpu(cpu) {
-               nid = cpu_to_node(cpu);
-               nasid = uv_apicid_to_nasid(per_cpu(x86_cpu_to_apicid, cpu));
-               if (nasid != last_nasid)
-                       uv_possible_blades++;
-               last_nasid = nasid;
-       }
+       for(i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++)
+               uv_possible_blades +=
+                 hweight64(uv_read_local_mmr( UVH_NODE_PRESENT_TABLE + i * 8));
        printk(KERN_DEBUG "UV: Found %d blades\n", uv_num_possible_blades());
 
        bytes = sizeof(struct uv_blade_info) * uv_num_possible_blades();
        uv_blade_info = alloc_bootmem_pages(bytes);
 
+       get_lowmem_redirect(&lowmem_redir_base, &lowmem_redir_size);
+
        bytes = sizeof(uv_node_to_blade[0]) * num_possible_nodes();
        uv_node_to_blade = alloc_bootmem_pages(bytes);
        memset(uv_node_to_blade, 255, bytes);
@@ -200,43 +309,62 @@ static __init void uv_system_init(void)
        uv_cpu_to_blade = alloc_bootmem_pages(bytes);
        memset(uv_cpu_to_blade, 255, bytes);
 
-       last_nasid = -1;
-       blade = -1;
-       lcpu = -1;
-       for_each_possible_cpu(cpu) {
-               nid = cpu_to_node(cpu);
-               nasid = uv_apicid_to_nasid(per_cpu(x86_cpu_to_apicid, cpu));
-               if (nasid != last_nasid) {
-                       blade++;
-                       lcpu = -1;
-                       uv_blade_info[blade].nr_posible_cpus = 0;
+       blade = 0;
+       for (i = 0; i < UVH_NODE_PRESENT_TABLE_DEPTH; i++) {
+               present = uv_read_local_mmr(UVH_NODE_PRESENT_TABLE + i * 8);
+               for (j = 0; j < 64; j++) {
+                       if (!test_bit(j, &present))
+                               continue;
+                       uv_blade_info[blade].pnode = (i * 64 + j);
+                       uv_blade_info[blade].nr_possible_cpus = 0;
                        uv_blade_info[blade].nr_online_cpus = 0;
+                       blade++;
                }
-               last_nasid = nasid;
-               lcpu++;
+       }
 
-               uv_cpu_hub_info(cpu)->m_val = m_n_config.s.m_skt;
-               uv_cpu_hub_info(cpu)->n_val = m_n_config.s.n_skt;
+       node_id.v = uv_read_local_mmr(UVH_NODE_ID);
+       gnode_upper = (((unsigned long)node_id.s.node_id) &
+                      ~((1 << n_val) - 1)) << m_val;
+
+       for_each_present_cpu(cpu) {
+               nid = cpu_to_node(cpu);
+               pnode = uv_apicid_to_pnode(per_cpu(x86_cpu_to_apicid, cpu));
+               blade = boot_pnode_to_blade(pnode);
+               lcpu = uv_blade_info[blade].nr_possible_cpus;
+               uv_blade_info[blade].nr_possible_cpus++;
+
+               uv_cpu_hub_info(cpu)->lowmem_remap_base = lowmem_redir_base;
+               uv_cpu_hub_info(cpu)->lowmem_remap_top =
+                                       lowmem_redir_base + lowmem_redir_size;
+               uv_cpu_hub_info(cpu)->m_val = m_val;
+               uv_cpu_hub_info(cpu)->n_val = m_val;
                uv_cpu_hub_info(cpu)->numa_blade_id = blade;
                uv_cpu_hub_info(cpu)->blade_processor_id = lcpu;
-               uv_cpu_hub_info(cpu)->local_nasid = nasid;
-               uv_cpu_hub_info(cpu)->gnode_upper =
-                   nasid & ~((1 << uv_hub_info->n_val) - 1);
+               uv_cpu_hub_info(cpu)->pnode = pnode;
+               uv_cpu_hub_info(cpu)->pnode_mask = (1 << n_val) - 1;
+               uv_cpu_hub_info(cpu)->gpa_mask = (1 << (m_val + n_val)) - 1;
+               uv_cpu_hub_info(cpu)->gnode_upper = gnode_upper;
                uv_cpu_hub_info(cpu)->global_mmr_base = mmr_base;
                uv_cpu_hub_info(cpu)->coherency_domain_number = 0;/* ZZZ */
-               uv_blade_info[blade].nasid = nasid;
-               uv_blade_info[blade].nr_posible_cpus++;
                uv_node_to_blade[nid] = blade;
                uv_cpu_to_blade[cpu] = blade;
+               max_pnode = max(pnode, max_pnode);
 
-               printk(KERN_DEBUG "UV cpu %d, apicid 0x%x, nasid %d, nid %d\n",
-                      cpu, per_cpu(x86_cpu_to_apicid, cpu), nasid, nid);
-               printk(KERN_DEBUG "UV   lcpu %d, blade %d\n", lcpu, blade);
+               printk(KERN_DEBUG "UV: cpu %d, apicid 0x%x, pnode %d, nid %d, "
+                       "lcpu %d, blade %d\n",
+                       cpu, per_cpu(x86_cpu_to_apicid, cpu), pnode, nid,
+                       lcpu, blade);
        }
+
+       map_gru_high(max_pnode);
+       map_mmr_high(max_pnode);
+       map_config_high(max_pnode);
+       map_mmioh_high(max_pnode);
 }
 
 /*
  * Called on each cpu to initialize the per_cpu UV data area.
+ *     ZZZ hotplug not supported yet
  */
 void __cpuinit uv_cpu_init(void)
 {
@@ -246,5 +374,5 @@ void __cpuinit uv_cpu_init(void)
        uv_blade_info[uv_numa_blade_id()].nr_online_cpus++;
 
        if (get_uv_system_type() == UV_NON_UNIQUE_APIC)
-               set_x2apic_extra_bits(uv_hub_info->local_nasid);
+               set_x2apic_extra_bits(uv_hub_info->pnode);
 }
diff --git a/arch/x86/kernel/head.c b/arch/x86/kernel/head.c
new file mode 100644 (file)
index 0000000..3e66bd3
--- /dev/null
@@ -0,0 +1,55 @@
+#include <linux/kernel.h>
+#include <linux/init.h>
+
+#include <asm/setup.h>
+#include <asm/bios_ebda.h>
+
+#define BIOS_LOWMEM_KILOBYTES 0x413
+
+/*
+ * The BIOS places the EBDA/XBDA at the top of conventional
+ * memory, and usually decreases the reported amount of
+ * conventional memory (int 0x12) too. This also contains a
+ * workaround for Dell systems that neglect to reserve EBDA.
+ * The same workaround also avoids a problem with the AMD768MPX
+ * chipset: reserve a page before VGA to prevent PCI prefetch
+ * into it (errata #56). Usually the page is reserved anyways,
+ * unless you have no PS/2 mouse plugged in.
+ */
+void __init reserve_ebda_region(void)
+{
+       unsigned int lowmem, ebda_addr;
+
+       /* To determine the position of the EBDA and the */
+       /* end of conventional memory, we need to look at */
+       /* the BIOS data area. In a paravirtual environment */
+       /* that area is absent. We'll just have to assume */
+       /* that the paravirt case can handle memory setup */
+       /* correctly, without our help. */
+       if (paravirt_enabled())
+               return;
+
+       /* end of low (conventional) memory */
+       lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
+       lowmem <<= 10;
+
+       /* start of EBDA area */
+       ebda_addr = get_bios_ebda();
+
+       /* Fixup: bios puts an EBDA in the top 64K segment */
+       /* of conventional memory, but does not adjust lowmem. */
+       if ((lowmem - ebda_addr) <= 0x10000)
+               lowmem = ebda_addr;
+
+       /* Fixup: bios does not report an EBDA at all. */
+       /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
+       if ((ebda_addr == 0) && (lowmem >= 0x9f000))
+               lowmem = 0x9f000;
+
+       /* Paranoia: should never happen, but... */
+       if ((lowmem == 0) || (lowmem >= 0x100000))
+               lowmem = 0x9f000;
+
+       /* reserve all memory between lowmem and the 1MB mark */
+       reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
+}
index 3db0590..fa1d25d 100644 (file)
@@ -8,7 +8,34 @@
 #include <linux/init.h>
 #include <linux/start_kernel.h>
 
+#include <asm/setup.h>
+#include <asm/sections.h>
+#include <asm/e820.h>
+#include <asm/bios_ebda.h>
+
 void __init i386_start_kernel(void)
 {
+       reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
+
+#ifdef CONFIG_BLK_DEV_INITRD
+       /* Reserve INITRD */
+       if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
+               u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+               u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
+               u64 ramdisk_end   = ramdisk_image + ramdisk_size;
+               reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
+       }
+#endif
+       reserve_early(init_pg_tables_start, init_pg_tables_end,
+                       "INIT_PG_TABLE");
+
+       reserve_ebda_region();
+
+       /*
+        * At this point everything still needed from the boot loader
+        * or BIOS or kernel text should be early reserved or marked not
+        * RAM in e820. All other memory is free game.
+        */
+
        start_kernel();
 }
index e25c57b..c978198 100644 (file)
 #include <asm/e820.h>
 #include <asm/bios_ebda.h>
 
+/* boot cpu pda */
+static struct x8664_pda _boot_cpu_pda __read_mostly;
+
+#ifdef CONFIG_SMP
+/*
+ * We install an empty cpu_pda pointer table to indicate to early users
+ * (numa_set_node) that the cpu_pda pointer table for cpus other than
+ * the boot cpu is not yet setup.
+ */
+static struct x8664_pda *__cpu_pda[NR_CPUS] __initdata;
+#else
+static struct x8664_pda *__cpu_pda[NR_CPUS] __read_mostly;
+#endif
+
 static void __init zap_identity_mappings(void)
 {
        pgd_t *pgd = pgd_offset_k(0UL);
@@ -51,74 +65,6 @@ static void __init copy_bootdata(char *real_mode_data)
        }
 }
 
-#define BIOS_LOWMEM_KILOBYTES 0x413
-
-/*
- * The BIOS places the EBDA/XBDA at the top of conventional
- * memory, and usually decreases the reported amount of
- * conventional memory (int 0x12) too. This also contains a
- * workaround for Dell systems that neglect to reserve EBDA.
- * The same workaround also avoids a problem with the AMD768MPX
- * chipset: reserve a page before VGA to prevent PCI prefetch
- * into it (errata #56). Usually the page is reserved anyways,
- * unless you have no PS/2 mouse plugged in.
- */
-static void __init reserve_ebda_region(void)
-{
-       unsigned int lowmem, ebda_addr;
-
-       /* To determine the position of the EBDA and the */
-       /* end of conventional memory, we need to look at */
-       /* the BIOS data area. In a paravirtual environment */
-       /* that area is absent. We'll just have to assume */
-       /* that the paravirt case can handle memory setup */
-       /* correctly, without our help. */
-       if (paravirt_enabled())
-               return;
-
-       /* end of low (conventional) memory */
-       lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
-       lowmem <<= 10;
-
-       /* start of EBDA area */
-       ebda_addr = get_bios_ebda();
-
-       /* Fixup: bios puts an EBDA in the top 64K segment */
-       /* of conventional memory, but does not adjust lowmem. */
-       if ((lowmem - ebda_addr) <= 0x10000)
-               lowmem = ebda_addr;
-
-       /* Fixup: bios does not report an EBDA at all. */
-       /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
-       if ((ebda_addr == 0) && (lowmem >= 0x9f000))
-               lowmem = 0x9f000;
-
-       /* Paranoia: should never happen, but... */
-       if ((lowmem == 0) || (lowmem >= 0x100000))
-               lowmem = 0x9f000;
-
-       /* reserve all memory between lowmem and the 1MB mark */
-       reserve_early(lowmem, 0x100000, "BIOS reserved");
-}
-
-static void __init reserve_setup_data(void)
-{
-       struct setup_data *data;
-       unsigned long pa_data;
-       char buf[32];
-
-       if (boot_params.hdr.version < 0x0209)
-               return;
-       pa_data = boot_params.hdr.setup_data;
-       while (pa_data) {
-               data = early_ioremap(pa_data, sizeof(*data));
-               sprintf(buf, "setup data %x", data->type);
-               reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
-               pa_data = data->next;
-               early_iounmap(data, sizeof(*data));
-       }
-}
-
 void __init x86_64_start_kernel(char * real_mode_data)
 {
        int i;
@@ -156,10 +102,17 @@ void __init x86_64_start_kernel(char * real_mode_data)
 
        early_printk("Kernel alive\n");
 
-       for (i = 0; i < NR_CPUS; i++)
-               cpu_pda(i) = &boot_cpu_pda[i];
-
+       _cpu_pda = __cpu_pda;
+       cpu_pda(0) = &_boot_cpu_pda;
        pda_init(0);
+
+       early_printk("Kernel really alive\n");
+
+       x86_64_start_reservations(real_mode_data);
+}
+
+void __init x86_64_start_reservations(char *real_mode_data)
+{
        copy_bootdata(__va(real_mode_data));
 
        reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
@@ -175,7 +128,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
 #endif
 
        reserve_ebda_region();
-       reserve_setup_data();
 
        /*
         * At this point everything still needed from the boot loader
index f7357cc..f67e934 100644 (file)
@@ -194,6 +194,7 @@ default_entry:
        xorl %ebx,%ebx                          /* %ebx is kept at zero */
 
        movl $pa(pg0), %edi
+       movl %edi, pa(init_pg_tables_start)
        movl $pa(swapper_pg_pmd), %edx
        movl $PTE_ATTR, %eax
 10:
@@ -219,6 +220,8 @@ default_entry:
        jb 10b
 1:
        movl %edi,pa(init_pg_tables_end)
+       shrl $12, %eax
+       movl %eax, pa(max_pfn_mapped)
 
        /* Do early initialization of the fixmap area */
        movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
@@ -228,6 +231,7 @@ default_entry:
 page_pde_offset = (__PAGE_OFFSET >> 20);
 
        movl $pa(pg0), %edi
+       movl %edi, pa(init_pg_tables_start)
        movl $pa(swapper_pg_dir), %edx
        movl $PTE_ATTR, %eax
 10:
@@ -249,6 +253,8 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
        cmpl %ebp,%eax
        jb 10b
        movl %edi,pa(init_pg_tables_end)
+       shrl $12, %eax
+       movl %eax, pa(max_pfn_mapped)
 
        /* Do early initialization of the fixmap area */
        movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
@@ -446,10 +452,13 @@ is386:    movl $2,%ecx            # set MP
        je   1f
        movl $(__KERNEL_PERCPU), %eax
        movl %eax,%fs           # set this cpu's percpu
-       jmp initialize_secondary # all other CPUs call initialize_secondary
+       movl (stack_start), %esp
 1:
 #endif /* CONFIG_SMP */
-       jmp i386_start_kernel
+       jmp *(initial_code)
+.align 4
+ENTRY(initial_code)
+       .long i386_start_kernel
 
 /*
  * We depend on ET to be correct. This checks for 287/387.
index b817974..b07ac7b 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/page.h>
 #include <asm/msr.h>
 #include <asm/cache.h>
+#include <asm/processor-flags.h>
 
 #ifdef CONFIG_PARAVIRT
 #include <asm/asm-offsets.h>
  *
  */
 
+#define pud_index(x)   (((x) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
+
+L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
+L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
+L4_START_KERNEL = pgd_index(__START_KERNEL_map)
+L3_START_KERNEL = pud_index(__START_KERNEL_map)
+
        .text
        .section .text.head
        .code64
@@ -76,8 +84,8 @@ startup_64:
        /* Fixup the physical addresses in the page table
         */
        addq    %rbp, init_level4_pgt + 0(%rip)
-       addq    %rbp, init_level4_pgt + (258*8)(%rip)
-       addq    %rbp, init_level4_pgt + (511*8)(%rip)
+       addq    %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
+       addq    %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
 
        addq    %rbp, level3_ident_pgt + 0(%rip)
 
@@ -154,9 +162,7 @@ ENTRY(secondary_startup_64)
         */
 
        /* Enable PAE mode and PGE */
-       xorq    %rax, %rax
-       btsq    $5, %rax
-       btsq    $7, %rax
+       movl    $(X86_CR4_PAE | X86_CR4_PGE), %eax
        movq    %rax, %cr4
 
        /* Setup early boot stage 4 level pagetables. */
@@ -184,19 +190,15 @@ ENTRY(secondary_startup_64)
 1:     wrmsr                           /* Make changes effective */
 
        /* Setup cr0 */
-#define CR0_PM                         1               /* protected mode */
-#define CR0_MP                         (1<<1)
-#define CR0_ET                         (1<<4)
-#define CR0_NE                         (1<<5)
-#define CR0_WP                         (1<<16)
-#define CR0_AM                         (1<<18)
-#define CR0_PAGING                     (1<<31)
-       movl $CR0_PM|CR0_MP|CR0_ET|CR0_NE|CR0_WP|CR0_AM|CR0_PAGING,%eax
+#define CR0_STATE      (X86_CR0_PE | X86_CR0_MP | X86_CR0_ET | \
+                        X86_CR0_NE | X86_CR0_WP | X86_CR0_AM | \
+                        X86_CR0_PG)
+       movl    $CR0_STATE, %eax
        /* Make changes effective */
        movq    %rax, %cr0
 
        /* Setup a boot time stack */
-       movq init_rsp(%rip),%rsp
+       movq stack_start(%rip),%rsp
 
        /* zero EFLAGS after setting rsp */
        pushq $0
@@ -208,7 +210,7 @@ ENTRY(secondary_startup_64)
         * addresses where we're currently running on. We have to do that here
         * because in 32bit we couldn't load a 64bit linear address.
         */
-       lgdt    cpu_gdt_descr(%rip)
+       lgdt    early_gdt_descr(%rip)
 
        /* set up data segments. actually 0 would do too */
        movl $__KERNEL_DS,%eax
@@ -257,8 +259,9 @@ ENTRY(secondary_startup_64)
        .quad   x86_64_start_kernel
        __FINITDATA
 
-       ENTRY(init_rsp)
+       ENTRY(stack_start)
        .quad  init_thread_union+THREAD_SIZE-8
+       .word  0
 
 bad_address:
        jmp bad_address
@@ -327,11 +330,11 @@ early_idt_ripmsg:
 ENTRY(name)
 
 /* Automate the creation of 1 to 1 mapping pmd entries */
-#define PMDS(START, PERM, COUNT)               \
-       i = 0 ;                                 \
-       .rept (COUNT) ;                         \
-       .quad   (START) + (i << 21) + (PERM) ;  \
-       i = i + 1 ;                             \
+#define PMDS(START, PERM, COUNT)                       \
+       i = 0 ;                                         \
+       .rept (COUNT) ;                                 \
+       .quad   (START) + (i << PMD_SHIFT) + (PERM) ;   \
+       i = i + 1 ;                                     \
        .endr
 
        /*
@@ -342,9 +345,9 @@ ENTRY(name)
         */
 NEXT_PAGE(init_level4_pgt)
        .quad   level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
-       .fill   257,8,0
+       .org    init_level4_pgt + L4_PAGE_OFFSET*8, 0
        .quad   level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
-       .fill   252,8,0
+       .org    init_level4_pgt + L4_START_KERNEL*8, 0
        /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
        .quad   level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
 
@@ -353,7 +356,7 @@ NEXT_PAGE(level3_ident_pgt)
        .fill   511,8,0
 
 NEXT_PAGE(level3_kernel_pgt)
-       .fill   510,8,0
+       .fill   L3_START_KERNEL,8,0
        /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
        .quad   level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
        .quad   level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
@@ -384,7 +387,7 @@ NEXT_PAGE(level2_kernel_pgt)
         *  If you want to increase this then increase MODULES_VADDR
         *  too.)
         */
-       PMDS(0, __PAGE_KERNEL_LARGE_EXEC|_PAGE_GLOBAL,
+       PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
                KERNEL_IMAGE_SIZE/PMD_SIZE)
 
 NEXT_PAGE(level2_spare_pgt)
@@ -395,54 +398,16 @@ NEXT_PAGE(level2_spare_pgt)
 
        .data
        .align 16
-       .globl cpu_gdt_descr
-cpu_gdt_descr:
-       .word   gdt_end-cpu_gdt_table-1
-gdt:
-       .quad   cpu_gdt_table
-#ifdef CONFIG_SMP
-       .rept   NR_CPUS-1
-       .word   0
-       .quad   0
-       .endr
-#endif
+       .globl early_gdt_descr
+early_gdt_descr:
+       .word   GDT_ENTRIES*8-1
+       .quad   per_cpu__gdt_page
 
 ENTRY(phys_base)
        /* This must match the first entry in level2_kernel_pgt */
        .quad   0x0000000000000000
 
-/* We need valid kernel segments for data and code in long mode too
- * IRET will check the segment types  kkeil 2000/10/28
- * Also sysret mandates a special GDT layout 
- */
-                               
-       .section .data.page_aligned, "aw"
-       .align PAGE_SIZE
-
-/* The TLS descriptors are currently at a different place compared to i386.
-   Hopefully nobody expects them at a fixed place (Wine?) */
        
-ENTRY(cpu_gdt_table)
-       .quad   0x0000000000000000      /* NULL descriptor */
-       .quad   0x00cf9b000000ffff      /* __KERNEL32_CS */
-       .quad   0x00af9b000000ffff      /* __KERNEL_CS */
-       .quad   0x00cf93000000ffff      /* __KERNEL_DS */
-       .quad   0x00cffb000000ffff      /* __USER32_CS */
-       .quad   0x00cff3000000ffff      /* __USER_DS, __USER32_DS  */
-       .quad   0x00affb000000ffff      /* __USER_CS */
-       .quad   0x0                     /* unused */
-       .quad   0,0                     /* TSS */
-       .quad   0,0                     /* LDT */
-       .quad   0,0,0                   /* three TLS descriptors */ 
-       .quad   0x0000f40000000000      /* node/CPU stored in limit */
-gdt_end:       
-       /* asm/segment.h:GDT_ENTRIES must match this */ 
-       /* This should be a multiple of the cache line size */
-       /* GDTs of other CPUs are now dynamically allocated */
-
-       /* zero the remaining page */
-       .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
-
        .section .bss, "aw", @nobits
        .align L1_CACHE_BYTES
 ENTRY(idt_table)
index 9b5cfcd..0ea6a19 100644 (file)
@@ -17,7 +17,7 @@
 
 /* FSEC = 10^-15
    NSEC = 10^-9 */
-#define FSEC_PER_NSEC  1000000
+#define FSEC_PER_NSEC  1000000L
 
 /*
  * HPET address is set in acpi/boot.c, when an ACPI entry exists
@@ -36,26 +36,15 @@ static inline void hpet_writel(unsigned long d, unsigned long a)
 }
 
 #ifdef CONFIG_X86_64
-
 #include <asm/pgtable.h>
-
-static inline void hpet_set_mapping(void)
-{
-       set_fixmap_nocache(FIX_HPET_BASE, hpet_address);
-       __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
-       hpet_virt_address = (void __iomem *)fix_to_virt(FIX_HPET_BASE);
-}
-
-static inline void hpet_clear_mapping(void)
-{
-       hpet_virt_address = NULL;
-}
-
-#else
+#endif
 
 static inline void hpet_set_mapping(void)
 {
        hpet_virt_address = ioremap_nocache(hpet_address, HPET_MMAP_SIZE);
+#ifdef CONFIG_X86_64
+       __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL_NOCACHE);
+#endif
 }
 
 static inline void hpet_clear_mapping(void)
@@ -63,7 +52,6 @@ static inline void hpet_clear_mapping(void)
        iounmap(hpet_virt_address);
        hpet_virt_address = NULL;
 }
-#endif
 
 /*
  * HPET command line enable / disable
@@ -206,20 +194,19 @@ static void hpet_enable_legacy_int(void)
 
 static void hpet_legacy_clockevent_register(void)
 {
-       uint64_t hpet_freq;
-
        /* Start HPET legacy interrupts */
        hpet_enable_legacy_int();
 
        /*
-        * The period is a femto seconds value. We need to calculate the
-        * scaled math multiplication factor for nanosecond to hpet tick
-        * conversion.
+        * The mult factor is defined as (include/linux/clockchips.h)
+        *  mult/2^shift = cyc/ns (in contrast to ns/cyc in clocksource.h)
+        * hpet_period is in units of femtoseconds (per cycle), so
+        *  mult/2^shift = cyc/ns = 10^6/hpet_period
+        *  mult = (10^6 * 2^shift)/hpet_period
+        *  mult = (FSEC_PER_NSEC << hpet_clockevent.shift)/hpet_period
         */
-       hpet_freq = 1000000000000000ULL;
-       do_div(hpet_freq, hpet_period);
-       hpet_clockevent.mult = div_sc((unsigned long) hpet_freq,
-                                     NSEC_PER_SEC, hpet_clockevent.shift);
+       hpet_clockevent.mult = div_sc((unsigned long) FSEC_PER_NSEC,
+                                     hpet_period, hpet_clockevent.shift);
        /* Calculate the min / max delta */
        hpet_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFFFF,
                                                           &hpet_clockevent);
@@ -324,7 +311,7 @@ static struct clocksource clocksource_hpet = {
 
 static int hpet_clocksource_register(void)
 {
-       u64 tmp, start, now;
+       u64 start, now;
        cycle_t t1;
 
        /* Start the counter */
@@ -351,21 +338,15 @@ static int hpet_clocksource_register(void)
                return -ENODEV;
        }
 
-       /* Initialize and register HPET clocksource
-        *
-        * hpet period is in femto seconds per cycle
-        * so we need to convert this to ns/cyc units
-        * approximated by mult/2^shift
-        *
-        *  fsec/cyc * 1nsec/1000000fsec = nsec/cyc = mult/2^shift
-        *  fsec/cyc * 1ns/1000000fsec * 2^shift = mult
-        *  fsec/cyc * 2^shift * 1nsec/1000000fsec = mult
-        *  (fsec/cyc << shift)/1000000 = mult
-        *  (hpet_period << shift)/FSEC_PER_NSEC = mult
+       /*
+        * The definition of mult is (include/linux/clocksource.h)
+        * mult/2^shift = ns/cyc and hpet_period is in units of fsec/cyc
+        * so we first need to convert hpet_period to ns/cyc units:
+        *  mult/2^shift = ns/cyc = hpet_period/10^6
+        *  mult = (hpet_period * 2^shift)/10^6
+        *  mult = (hpet_period << shift)/FSEC_PER_NSEC
         */
-       tmp = (u64)hpet_period << HPET_SHIFT;
-       do_div(tmp, FSEC_PER_NSEC);
-       clocksource_hpet.mult = (u32)tmp;
+       clocksource_hpet.mult = div_sc(hpet_period, FSEC_PER_NSEC, HPET_SHIFT);
 
        clocksource_register(&clocksource_hpet);
 
index deb4378..dd7ebee 100644 (file)
@@ -1,7 +1,14 @@
 #include <linux/module.h>
+
 #include <asm/checksum.h>
-#include <asm/desc.h>
 #include <asm/pgtable.h>
+#include <asm/desc.h>
+#include <asm/ftrace.h>
+
+#ifdef CONFIG_FTRACE
+/* mcount is defined in assembly */
+EXPORT_SYMBOL(mcount);
+#endif
 
 /* Networking helper routines. */
 EXPORT_SYMBOL(csum_partial_copy_generic);
index 95e80e5..eb9ddd8 100644 (file)
@@ -162,7 +162,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
        int ret;
 
        if (!cpu_has_fxsr)
-               return -EIO;
+               return -ENODEV;
 
        ret = init_fpu(target);
        if (ret)
@@ -179,7 +179,7 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
        int ret;
 
        if (!cpu_has_fxsr)
-               return -EIO;
+               return -ENODEV;
 
        ret = init_fpu(target);
        if (ret)
diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
new file mode 100644 (file)
index 0000000..dc92b49
--- /dev/null
@@ -0,0 +1,337 @@
+#include <linux/linkage.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/timex.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/init.h>
+#include <linux/kernel_stat.h>
+#include <linux/sysdev.h>
+#include <linux/bitops.h>
+
+#include <asm/acpi.h>
+#include <asm/atomic.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/timer.h>
+#include <asm/hw_irq.h>
+#include <asm/pgtable.h>
+#include <asm/delay.h>
+#include <asm/desc.h>
+#include <asm/apic.h>
+#include <asm/arch_hooks.h>
+#include <asm/i8259.h>
+
+/*
+ * This is the 'legacy' 8259A Programmable Interrupt Controller,
+ * present in the majority of PC/AT boxes.
+ * plus some generic x86 specific things if generic specifics makes
+ * any sense at all.
+ */
+
+static int i8259A_auto_eoi;
+DEFINE_SPINLOCK(i8259A_lock);
+static void mask_and_ack_8259A(unsigned int);
+
+struct irq_chip i8259A_chip = {
+       .name           = "XT-PIC",
+       .mask           = disable_8259A_irq,
+       .disable        = disable_8259A_irq,
+       .unmask         = enable_8259A_irq,
+       .mask_ack       = mask_and_ack_8259A,
+};
+
+/*
+ * 8259A PIC functions to handle ISA devices:
+ */
+
+/*
+ * This contains the irq mask for both 8259A irq controllers,
+ */
+unsigned int cached_irq_mask = 0xffff;
+
+/*
+ * Not all IRQs can be routed through the IO-APIC, eg. on certain (older)
+ * boards the timer interrupt is not really connected to any IO-APIC pin,
+ * it's fed to the master 8259A's IR0 line only.
+ *
+ * Any '1' bit in this mask means the IRQ is routed through the IO-APIC.
+ * this 'mixed mode' IRQ handling costs nothing because it's only used
+ * at IRQ setup time.
+ */
+unsigned long io_apic_irqs;
+
+void disable_8259A_irq(unsigned int irq)
+{
+       unsigned int mask = 1 << irq;
+       unsigned long flags;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+       cached_irq_mask |= mask;
+       if (irq & 8)
+               outb(cached_slave_mask, PIC_SLAVE_IMR);
+       else
+               outb(cached_master_mask, PIC_MASTER_IMR);
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+}
+
+void enable_8259A_irq(unsigned int irq)
+{
+       unsigned int mask = ~(1 << irq);
+       unsigned long flags;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+       cached_irq_mask &= mask;
+       if (irq & 8)
+               outb(cached_slave_mask, PIC_SLAVE_IMR);
+       else
+               outb(cached_master_mask, PIC_MASTER_IMR);
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+}
+
+int i8259A_irq_pending(unsigned int irq)
+{
+       unsigned int mask = 1<<irq;
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+       if (irq < 8)
+               ret = inb(PIC_MASTER_CMD) & mask;
+       else
+               ret = inb(PIC_SLAVE_CMD) & (mask >> 8);
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+
+       return ret;
+}
+
+void make_8259A_irq(unsigned int irq)
+{
+       disable_irq_nosync(irq);
+       io_apic_irqs &= ~(1<<irq);
+       set_irq_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
+                                     "XT");
+       enable_irq(irq);
+}
+
+/*
+ * This function assumes to be called rarely. Switching between
+ * 8259A registers is slow.
+ * This has to be protected by the irq controller spinlock
+ * before being called.
+ */
+static inline int i8259A_irq_real(unsigned int irq)
+{
+       int value;
+       int irqmask = 1<<irq;
+
+       if (irq < 8) {
+               outb(0x0B, PIC_MASTER_CMD);     /* ISR register */
+               value = inb(PIC_MASTER_CMD) & irqmask;
+               outb(0x0A, PIC_MASTER_CMD);     /* back to the IRR register */
+               return value;
+       }
+       outb(0x0B, PIC_SLAVE_CMD);      /* ISR register */
+       value = inb(PIC_SLAVE_CMD) & (irqmask >> 8);
+       outb(0x0A, PIC_SLAVE_CMD);      /* back to the IRR register */
+       return value;
+}
+
+/*
+ * Careful! The 8259A is a fragile beast, it pretty
+ * much _has_ to be done exactly like this (mask it
+ * first, _then_ send the EOI, and the order of EOI
+ * to the two 8259s is important!
+ */
+static void mask_and_ack_8259A(unsigned int irq)
+{
+       unsigned int irqmask = 1 << irq;
+       unsigned long flags;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+       /*
+        * Lightweight spurious IRQ detection. We do not want
+        * to overdo spurious IRQ handling - it's usually a sign
+        * of hardware problems, so we only do the checks we can
+        * do without slowing down good hardware unnecessarily.
+        *
+        * Note that IRQ7 and IRQ15 (the two spurious IRQs
+        * usually resulting from the 8259A-1|2 PICs) occur
+        * even if the IRQ is masked in the 8259A. Thus we
+        * can check spurious 8259A IRQs without doing the
+        * quite slow i8259A_irq_real() call for every IRQ.
+        * This does not cover 100% of spurious interrupts,
+        * but should be enough to warn the user that there
+        * is something bad going on ...
+        */
+       if (cached_irq_mask & irqmask)
+               goto spurious_8259A_irq;
+       cached_irq_mask |= irqmask;
+
+handle_real_irq:
+       if (irq & 8) {
+               inb(PIC_SLAVE_IMR);     /* DUMMY - (do we need this?) */
+               outb(cached_slave_mask, PIC_SLAVE_IMR);
+               /* 'Specific EOI' to slave */
+               outb(0x60+(irq&7), PIC_SLAVE_CMD);
+                /* 'Specific EOI' to master-IRQ2 */
+               outb(0x60+PIC_CASCADE_IR, PIC_MASTER_CMD);
+       } else {
+               inb(PIC_MASTER_IMR);    /* DUMMY - (do we need this?) */
+               outb(cached_master_mask, PIC_MASTER_IMR);
+               outb(0x60+irq, PIC_MASTER_CMD); /* 'Specific EOI to master */
+       }
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+       return;
+
+spurious_8259A_irq:
+       /*
+        * this is the slow path - should happen rarely.
+        */
+       if (i8259A_irq_real(irq))
+               /*
+                * oops, the IRQ _is_ in service according to the
+                * 8259A - not spurious, go handle it.
+                */
+               goto handle_real_irq;
+
+       {
+               static int spurious_irq_mask;
+               /*
+                * At this point we can be sure the IRQ is spurious,
+                * lets ACK and report it. [once per IRQ]
+                */
+               if (!(spurious_irq_mask & irqmask)) {
+                       printk(KERN_DEBUG
+                              "spurious 8259A interrupt: IRQ%d.\n", irq);
+                       spurious_irq_mask |= irqmask;
+               }
+               atomic_inc(&irq_err_count);
+               /*
+                * Theoretically we do not have to handle this IRQ,
+                * but in Linux this does not cause problems and is
+                * simpler for us.
+                */
+               goto handle_real_irq;
+       }
+}
+
+static char irq_trigger[2];
+/**
+ * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
+ */
+static void restore_ELCR(char *trigger)
+{
+       outb(trigger[0], 0x4d0);
+       outb(trigger[1], 0x4d1);
+}
+
+static void save_ELCR(char *trigger)
+{
+       /* IRQ 0,1,2,8,13 are marked as reserved */
+       trigger[0] = inb(0x4d0) & 0xF8;
+       trigger[1] = inb(0x4d1) & 0xDE;
+}
+
+static int i8259A_resume(struct sys_device *dev)
+{
+       init_8259A(i8259A_auto_eoi);
+       restore_ELCR(irq_trigger);
+       return 0;
+}
+
+static int i8259A_suspend(struct sys_device *dev, pm_message_t state)
+{
+       save_ELCR(irq_trigger);
+       return 0;
+}
+
+static int i8259A_shutdown(struct sys_device *dev)
+{
+       /* Put the i8259A into a quiescent state that
+        * the kernel initialization code can get it
+        * out of.
+        */
+       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
+       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-1 */
+       return 0;
+}
+
+static struct sysdev_class i8259_sysdev_class = {
+       .name = "i8259",
+       .suspend = i8259A_suspend,
+       .resume = i8259A_resume,
+       .shutdown = i8259A_shutdown,
+};
+
+static struct sys_device device_i8259A = {
+       .id     = 0,
+       .cls    = &i8259_sysdev_class,
+};
+
+static int __init i8259A_init_sysfs(void)
+{
+       int error = sysdev_class_register(&i8259_sysdev_class);
+       if (!error)
+               error = sysdev_register(&device_i8259A);
+       return error;
+}
+
+device_initcall(i8259A_init_sysfs);
+
+void init_8259A(int auto_eoi)
+{
+       unsigned long flags;
+
+       i8259A_auto_eoi = auto_eoi;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+
+       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
+       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-2 */
+
+       /*
+        * outb_pic - this has to work on a wide range of PC hardware.
+        */
+       outb_pic(0x11, PIC_MASTER_CMD); /* ICW1: select 8259A-1 init */
+
+       /* ICW2: 8259A-1 IR0-7 mapped to 0x30-0x37 on x86-64,
+                              to 0x20-0x27 on i386 */
+       outb_pic(IRQ0_VECTOR, PIC_MASTER_IMR);
+
+       /* 8259A-1 (the master) has a slave on IR2 */
+       outb_pic(1U << PIC_CASCADE_IR, PIC_MASTER_IMR);
+
+       if (auto_eoi)   /* master does Auto EOI */
+               outb_pic(MASTER_ICW4_DEFAULT | PIC_ICW4_AEOI, PIC_MASTER_IMR);
+       else            /* master expects normal EOI */
+               outb_pic(MASTER_ICW4_DEFAULT, PIC_MASTER_IMR);
+
+       outb_pic(0x11, PIC_SLAVE_CMD);  /* ICW1: select 8259A-2 init */
+
+       /* ICW2: 8259A-2 IR0-7 mapped to IRQ8_VECTOR */
+       outb_pic(IRQ8_VECTOR, PIC_SLAVE_IMR);
+       /* 8259A-2 is a slave on master's IR2 */
+       outb_pic(PIC_CASCADE_IR, PIC_SLAVE_IMR);
+       /* (slave's support for AEOI in flat mode is to be investigated) */
+       outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
+
+       if (auto_eoi)
+               /*
+                * In AEOI mode we just have to mask the interrupt
+                * when acking.
+                */
+               i8259A_chip.mask_ack = disable_8259A_irq;
+       else
+               i8259A_chip.mask_ack = mask_and_ack_8259A;
+
+       udelay(100);            /* wait for 8259A to initialize */
+
+       outb(cached_master_mask, PIC_MASTER_IMR); /* restore master IRQ mask */
+       outb(cached_slave_mask, PIC_SLAVE_IMR);   /* restore slave IRQ mask */
+
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+}
diff --git a/arch/x86/kernel/i8259_32.c b/arch/x86/kernel/i8259_32.c
deleted file mode 100644 (file)
index fe63196..0000000
+++ /dev/null
@@ -1,409 +0,0 @@
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/ioport.h>
-#include <linux/interrupt.h>
-#include <linux/slab.h>
-#include <linux/random.h>
-#include <linux/init.h>
-#include <linux/kernel_stat.h>
-#include <linux/sysdev.h>
-#include <linux/bitops.h>
-
-#include <asm/atomic.h>
-#include <asm/system.h>
-#include <asm/io.h>
-#include <asm/timer.h>
-#include <asm/pgtable.h>
-#include <asm/delay.h>
-#include <asm/desc.h>
-#include <asm/apic.h>
-#include <asm/arch_hooks.h>
-#include <asm/i8259.h>
-
-/*
- * This is the 'legacy' 8259A Programmable Interrupt Controller,
- * present in the majority of PC/AT boxes.
- * plus some generic x86 specific things if generic specifics makes
- * any sense at all.
- */
-
-static int i8259A_auto_eoi;
-DEFINE_SPINLOCK(i8259A_lock);
-static void mask_and_ack_8259A(unsigned int);
-
-static struct irq_chip i8259A_chip = {
-       .name           = "XT-PIC",
-       .mask           = disable_8259A_irq,
-       .disable        = disable_8259A_irq,
-       .unmask         = enable_8259A_irq,
-       .mask_ack       = mask_and_ack_8259A,
-};
-
-/*
- * 8259A PIC functions to handle ISA devices:
- */
-
-/*
- * This contains the irq mask for both 8259A irq controllers,
- */
-unsigned int cached_irq_mask = 0xffff;
-
-/*
- * Not all IRQs can be routed through the IO-APIC, eg. on certain (older)
- * boards the timer interrupt is not really connected to any IO-APIC pin,
- * it's fed to the master 8259A's IR0 line only.
- *
- * Any '1' bit in this mask means the IRQ is routed through the IO-APIC.
- * this 'mixed mode' IRQ handling costs nothing because it's only used
- * at IRQ setup time.
- */
-unsigned long io_apic_irqs;
-
-void disable_8259A_irq(unsigned int irq)
-{
-       unsigned int mask = 1 << irq;
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       cached_irq_mask |= mask;
-       if (irq & 8)
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-       else
-               outb(cached_master_mask, PIC_MASTER_IMR);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-void enable_8259A_irq(unsigned int irq)
-{
-       unsigned int mask = ~(1 << irq);
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       cached_irq_mask &= mask;
-       if (irq & 8)
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-       else
-               outb(cached_master_mask, PIC_MASTER_IMR);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-int i8259A_irq_pending(unsigned int irq)
-{
-       unsigned int mask = 1<<irq;
-       unsigned long flags;
-       int ret;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       if (irq < 8)
-               ret = inb(PIC_MASTER_CMD) & mask;
-       else
-               ret = inb(PIC_SLAVE_CMD) & (mask >> 8);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-
-       return ret;
-}
-
-void make_8259A_irq(unsigned int irq)
-{
-       disable_irq_nosync(irq);
-       io_apic_irqs &= ~(1<<irq);
-       set_irq_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
-                                     "XT");
-       enable_irq(irq);
-}
-
-/*
- * This function assumes to be called rarely. Switching between
- * 8259A registers is slow.
- * This has to be protected by the irq controller spinlock
- * before being called.
- */
-static inline int i8259A_irq_real(unsigned int irq)
-{
-       int value;
-       int irqmask = 1<<irq;
-
-       if (irq < 8) {
-               outb(0x0B,PIC_MASTER_CMD);      /* ISR register */
-               value = inb(PIC_MASTER_CMD) & irqmask;
-               outb(0x0A,PIC_MASTER_CMD);      /* back to the IRR register */
-               return value;
-       }
-       outb(0x0B,PIC_SLAVE_CMD);       /* ISR register */
-       value = inb(PIC_SLAVE_CMD) & (irqmask >> 8);
-       outb(0x0A,PIC_SLAVE_CMD);       /* back to the IRR register */
-       return value;
-}
-
-/*
- * Careful! The 8259A is a fragile beast, it pretty
- * much _has_ to be done exactly like this (mask it
- * first, _then_ send the EOI, and the order of EOI
- * to the two 8259s is important!
- */
-static void mask_and_ack_8259A(unsigned int irq)
-{
-       unsigned int irqmask = 1 << irq;
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       /*
-        * Lightweight spurious IRQ detection. We do not want
-        * to overdo spurious IRQ handling - it's usually a sign
-        * of hardware problems, so we only do the checks we can
-        * do without slowing down good hardware unnecessarily.
-        *
-        * Note that IRQ7 and IRQ15 (the two spurious IRQs
-        * usually resulting from the 8259A-1|2 PICs) occur
-        * even if the IRQ is masked in the 8259A. Thus we
-        * can check spurious 8259A IRQs without doing the
-        * quite slow i8259A_irq_real() call for every IRQ.
-        * This does not cover 100% of spurious interrupts,
-        * but should be enough to warn the user that there
-        * is something bad going on ...
-        */
-       if (cached_irq_mask & irqmask)
-               goto spurious_8259A_irq;
-       cached_irq_mask |= irqmask;
-
-handle_real_irq:
-       if (irq & 8) {
-               inb(PIC_SLAVE_IMR);     /* DUMMY - (do we need this?) */
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-               outb(0x60+(irq&7),PIC_SLAVE_CMD);/* 'Specific EOI' to slave */
-               outb(0x60+PIC_CASCADE_IR,PIC_MASTER_CMD); /* 'Specific EOI' to master-IRQ2 */
-       } else {
-               inb(PIC_MASTER_IMR);    /* DUMMY - (do we need this?) */
-               outb(cached_master_mask, PIC_MASTER_IMR);
-               outb(0x60+irq,PIC_MASTER_CMD);  /* 'Specific EOI to master */
-       }
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-       return;
-
-spurious_8259A_irq:
-       /*
-        * this is the slow path - should happen rarely.
-        */
-       if (i8259A_irq_real(irq))
-               /*
-                * oops, the IRQ _is_ in service according to the
-                * 8259A - not spurious, go handle it.
-                */
-               goto handle_real_irq;
-
-       {
-               static int spurious_irq_mask;
-               /*
-                * At this point we can be sure the IRQ is spurious,
-                * lets ACK and report it. [once per IRQ]
-                */
-               if (!(spurious_irq_mask & irqmask)) {
-                       printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
-                       spurious_irq_mask |= irqmask;
-               }
-               atomic_inc(&irq_err_count);
-               /*
-                * Theoretically we do not have to handle this IRQ,
-                * but in Linux this does not cause problems and is
-                * simpler for us.
-                */
-               goto handle_real_irq;
-       }
-}
-
-static char irq_trigger[2];
-/**
- * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
- */
-static void restore_ELCR(char *trigger)
-{
-       outb(trigger[0], 0x4d0);
-       outb(trigger[1], 0x4d1);
-}
-
-static void save_ELCR(char *trigger)
-{
-       /* IRQ 0,1,2,8,13 are marked as reserved */
-       trigger[0] = inb(0x4d0) & 0xF8;
-       trigger[1] = inb(0x4d1) & 0xDE;
-}
-
-static int i8259A_resume(struct sys_device *dev)
-{
-       init_8259A(i8259A_auto_eoi);
-       restore_ELCR(irq_trigger);
-       return 0;
-}
-
-static int i8259A_suspend(struct sys_device *dev, pm_message_t state)
-{
-       save_ELCR(irq_trigger);
-       return 0;
-}
-
-static int i8259A_shutdown(struct sys_device *dev)
-{
-       /* Put the i8259A into a quiescent state that
-        * the kernel initialization code can get it
-        * out of.
-        */
-       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
-       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-1 */
-       return 0;
-}
-
-static struct sysdev_class i8259_sysdev_class = {
-       .name = "i8259",
-       .suspend = i8259A_suspend,
-       .resume = i8259A_resume,
-       .shutdown = i8259A_shutdown,
-};
-
-static struct sys_device device_i8259A = {
-       .id     = 0,
-       .cls    = &i8259_sysdev_class,
-};
-
-static int __init i8259A_init_sysfs(void)
-{
-       int error = sysdev_class_register(&i8259_sysdev_class);
-       if (!error)
-               error = sysdev_register(&device_i8259A);
-       return error;
-}
-
-device_initcall(i8259A_init_sysfs);
-
-void init_8259A(int auto_eoi)
-{
-       unsigned long flags;
-
-       i8259A_auto_eoi = auto_eoi;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-
-       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
-       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-2 */
-
-       /*
-        * outb_pic - this has to work on a wide range of PC hardware.
-        */
-       outb_pic(0x11, PIC_MASTER_CMD); /* ICW1: select 8259A-1 init */
-       outb_pic(0x20 + 0, PIC_MASTER_IMR);     /* ICW2: 8259A-1 IR0-7 mapped to 0x20-0x27 */
-       outb_pic(1U << PIC_CASCADE_IR, PIC_MASTER_IMR); /* 8259A-1 (the master) has a slave on IR2 */
-       if (auto_eoi)   /* master does Auto EOI */
-               outb_pic(MASTER_ICW4_DEFAULT | PIC_ICW4_AEOI, PIC_MASTER_IMR);
-       else            /* master expects normal EOI */
-               outb_pic(MASTER_ICW4_DEFAULT, PIC_MASTER_IMR);
-
-       outb_pic(0x11, PIC_SLAVE_CMD);  /* ICW1: select 8259A-2 init */
-       outb_pic(0x20 + 8, PIC_SLAVE_IMR);      /* ICW2: 8259A-2 IR0-7 mapped to 0x28-0x2f */
-       outb_pic(PIC_CASCADE_IR, PIC_SLAVE_IMR);        /* 8259A-2 is a slave on master's IR2 */
-       outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR); /* (slave's support for AEOI in flat mode is to be investigated) */
-       if (auto_eoi)
-               /*
-                * In AEOI mode we just have to mask the interrupt
-                * when acking.
-                */
-               i8259A_chip.mask_ack = disable_8259A_irq;
-       else
-               i8259A_chip.mask_ack = mask_and_ack_8259A;
-
-       udelay(100);            /* wait for 8259A to initialize */
-
-       outb(cached_master_mask, PIC_MASTER_IMR); /* restore master IRQ mask */
-       outb(cached_slave_mask, PIC_SLAVE_IMR);   /* restore slave IRQ mask */
-
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-/*
- * Note that on a 486, we don't want to do a SIGFPE on an irq13
- * as the irq is unreliable, and exception 16 works correctly
- * (ie as explained in the intel literature). On a 386, you
- * can't use exception 16 due to bad IBM design, so we have to
- * rely on the less exact irq13.
- *
- * Careful.. Not only is IRQ13 unreliable, but it is also
- * leads to races. IBM designers who came up with it should
- * be shot.
- */
-
-static irqreturn_t math_error_irq(int cpl, void *dev_id)
-{
-       extern void math_error(void __user *);
-       outb(0,0xF0);
-       if (ignore_fpu_irq || !boot_cpu_data.hard_math)
-               return IRQ_NONE;
-       math_error((void __user *)get_irq_regs()->ip);
-       return IRQ_HANDLED;
-}
-
-/*
- * New motherboards sometimes make IRQ 13 be a PCI interrupt,
- * so allow interrupt sharing.
- */
-static struct irqaction fpu_irq = {
-       .handler = math_error_irq,
-       .mask = CPU_MASK_NONE,
-       .name = "fpu",
-};
-
-void __init init_ISA_irqs (void)
-{
-       int i;
-
-#ifdef CONFIG_X86_LOCAL_APIC
-       init_bsp_APIC();
-#endif
-       init_8259A(0);
-
-       /*
-        * 16 old-style INTA-cycle interrupts:
-        */
-       for (i = 0; i < 16; i++) {
-               set_irq_chip_and_handler_name(i, &i8259A_chip,
-                                             handle_level_irq, "XT");
-       }
-}
-
-/* Overridden in paravirt.c */
-void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
-
-void __init native_init_IRQ(void)
-{
-       int i;
-
-       /* all the set up before the call gates are initialised */
-       pre_intr_init_hook();
-
-       /*
-        * Cover the whole vector space, no vector can escape
-        * us. (some of these will be overridden and become
-        * 'special' SMP interrupts)
-        */
-       for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) {
-               int vector = FIRST_EXTERNAL_VECTOR + i;
-               if (i >= NR_IRQS)
-                       break;
-               /* SYSCALL_VECTOR was reserved in trap_init. */
-               if (!test_bit(vector, used_vectors))
-                       set_intr_gate(vector, interrupt[i]);
-       }
-
-       /* setup after call gates are initialised (usually add in
-        * the architecture specific gates)
-        */
-       intr_init_hook();
-
-       /*
-        * External FPU? Set up irq13 if so, for
-        * original braindamaged IBM FERR coupling.
-        */
-       if (boot_cpu_data.hard_math && !cpu_has_fpu)
-               setup_irq(FPU_IRQ, &fpu_irq);
-
-       irq_ctx_init(smp_processor_id());
-}
diff --git a/arch/x86/kernel/i8259_64.c b/arch/x86/kernel/i8259_64.c
deleted file mode 100644 (file)
index fa57a15..0000000
+++ /dev/null
@@ -1,512 +0,0 @@
-#include <linux/linkage.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/ioport.h>
-#include <linux/interrupt.h>
-#include <linux/timex.h>
-#include <linux/slab.h>
-#include <linux/random.h>
-#include <linux/init.h>
-#include <linux/kernel_stat.h>
-#include <linux/sysdev.h>
-#include <linux/bitops.h>
-
-#include <asm/acpi.h>
-#include <asm/atomic.h>
-#include <asm/system.h>
-#include <asm/io.h>
-#include <asm/hw_irq.h>
-#include <asm/pgtable.h>
-#include <asm/delay.h>
-#include <asm/desc.h>
-#include <asm/apic.h>
-#include <asm/i8259.h>
-
-/*
- * Common place to define all x86 IRQ vectors
- *
- * This builds up the IRQ handler stubs using some ugly macros in irq.h
- *
- * These macros create the low-level assembly IRQ routines that save
- * register context and call do_IRQ(). do_IRQ() then does all the
- * operations that are needed to keep the AT (or SMP IOAPIC)
- * interrupt-controller happy.
- */
-
-#define BI(x,y) \
-       BUILD_IRQ(x##y)
-
-#define BUILD_16_IRQS(x) \
-       BI(x,0) BI(x,1) BI(x,2) BI(x,3) \
-       BI(x,4) BI(x,5) BI(x,6) BI(x,7) \
-       BI(x,8) BI(x,9) BI(x,a) BI(x,b) \
-       BI(x,c) BI(x,d) BI(x,e) BI(x,f)
-
-/*
- * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
- * (these are usually mapped to vectors 0x30-0x3f)
- */
-
-/*
- * The IO-APIC gives us many more interrupt sources. Most of these
- * are unused but an SMP system is supposed to have enough memory ...
- * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
- * across the spectrum, so we really want to be prepared to get all
- * of these. Plus, more powerful systems might have more than 64
- * IO-APIC registers.
- *
- * (these are usually mapped into the 0x30-0xff vector range)
- */
-                                     BUILD_16_IRQS(0x2) BUILD_16_IRQS(0x3)
-BUILD_16_IRQS(0x4) BUILD_16_IRQS(0x5) BUILD_16_IRQS(0x6) BUILD_16_IRQS(0x7)
-BUILD_16_IRQS(0x8) BUILD_16_IRQS(0x9) BUILD_16_IRQS(0xa) BUILD_16_IRQS(0xb)
-BUILD_16_IRQS(0xc) BUILD_16_IRQS(0xd) BUILD_16_IRQS(0xe) BUILD_16_IRQS(0xf)
-
-#undef BUILD_16_IRQS
-#undef BI
-
-
-#define IRQ(x,y) \
-       IRQ##x##y##_interrupt
-
-#define IRQLIST_16(x) \
-       IRQ(x,0), IRQ(x,1), IRQ(x,2), IRQ(x,3), \
-       IRQ(x,4), IRQ(x,5), IRQ(x,6), IRQ(x,7), \
-       IRQ(x,8), IRQ(x,9), IRQ(x,a), IRQ(x,b), \
-       IRQ(x,c), IRQ(x,d), IRQ(x,e), IRQ(x,f)
-
-/* for the irq vectors */
-static void (*__initdata interrupt[NR_VECTORS - FIRST_EXTERNAL_VECTOR])(void) = {
-                                         IRQLIST_16(0x2), IRQLIST_16(0x3),
-       IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7),
-       IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb),
-       IRQLIST_16(0xc), IRQLIST_16(0xd), IRQLIST_16(0xe), IRQLIST_16(0xf)
-};
-
-#undef IRQ
-#undef IRQLIST_16
-
-/*
- * This is the 'legacy' 8259A Programmable Interrupt Controller,
- * present in the majority of PC/AT boxes.
- * plus some generic x86 specific things if generic specifics makes
- * any sense at all.
- * this file should become arch/i386/kernel/irq.c when the old irq.c
- * moves to arch independent land
- */
-
-static int i8259A_auto_eoi;
-DEFINE_SPINLOCK(i8259A_lock);
-static void mask_and_ack_8259A(unsigned int);
-
-static struct irq_chip i8259A_chip = {
-       .name           = "XT-PIC",
-       .mask           = disable_8259A_irq,
-       .disable        = disable_8259A_irq,
-       .unmask         = enable_8259A_irq,
-       .mask_ack       = mask_and_ack_8259A,
-};
-
-/*
- * 8259A PIC functions to handle ISA devices:
- */
-
-/*
- * This contains the irq mask for both 8259A irq controllers,
- */
-unsigned int cached_irq_mask = 0xffff;
-
-/*
- * Not all IRQs can be routed through the IO-APIC, eg. on certain (older)
- * boards the timer interrupt is not really connected to any IO-APIC pin,
- * it's fed to the master 8259A's IR0 line only.
- *
- * Any '1' bit in this mask means the IRQ is routed through the IO-APIC.
- * this 'mixed mode' IRQ handling costs nothing because it's only used
- * at IRQ setup time.
- */
-unsigned long io_apic_irqs;
-
-void disable_8259A_irq(unsigned int irq)
-{
-       unsigned int mask = 1 << irq;
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       cached_irq_mask |= mask;
-       if (irq & 8)
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-       else
-               outb(cached_master_mask, PIC_MASTER_IMR);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-void enable_8259A_irq(unsigned int irq)
-{
-       unsigned int mask = ~(1 << irq);
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       cached_irq_mask &= mask;
-       if (irq & 8)
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-       else
-               outb(cached_master_mask, PIC_MASTER_IMR);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-int i8259A_irq_pending(unsigned int irq)
-{
-       unsigned int mask = 1<<irq;
-       unsigned long flags;
-       int ret;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       if (irq < 8)
-               ret = inb(PIC_MASTER_CMD) & mask;
-       else
-               ret = inb(PIC_SLAVE_CMD) & (mask >> 8);
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-
-       return ret;
-}
-
-void make_8259A_irq(unsigned int irq)
-{
-       disable_irq_nosync(irq);
-       io_apic_irqs &= ~(1<<irq);
-       set_irq_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
-                                     "XT");
-       enable_irq(irq);
-}
-
-/*
- * This function assumes to be called rarely. Switching between
- * 8259A registers is slow.
- * This has to be protected by the irq controller spinlock
- * before being called.
- */
-static inline int i8259A_irq_real(unsigned int irq)
-{
-       int value;
-       int irqmask = 1<<irq;
-
-       if (irq < 8) {
-               outb(0x0B,PIC_MASTER_CMD);      /* ISR register */
-               value = inb(PIC_MASTER_CMD) & irqmask;
-               outb(0x0A,PIC_MASTER_CMD);      /* back to the IRR register */
-               return value;
-       }
-       outb(0x0B,PIC_SLAVE_CMD);       /* ISR register */
-       value = inb(PIC_SLAVE_CMD) & (irqmask >> 8);
-       outb(0x0A,PIC_SLAVE_CMD);       /* back to the IRR register */
-       return value;
-}
-
-/*
- * Careful! The 8259A is a fragile beast, it pretty
- * much _has_ to be done exactly like this (mask it
- * first, _then_ send the EOI, and the order of EOI
- * to the two 8259s is important!
- */
-static void mask_and_ack_8259A(unsigned int irq)
-{
-       unsigned int irqmask = 1 << irq;
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-       /*
-        * Lightweight spurious IRQ detection. We do not want
-        * to overdo spurious IRQ handling - it's usually a sign
-        * of hardware problems, so we only do the checks we can
-        * do without slowing down good hardware unnecessarily.
-        *
-        * Note that IRQ7 and IRQ15 (the two spurious IRQs
-        * usually resulting from the 8259A-1|2 PICs) occur
-        * even if the IRQ is masked in the 8259A. Thus we
-        * can check spurious 8259A IRQs without doing the
-        * quite slow i8259A_irq_real() call for every IRQ.
-        * This does not cover 100% of spurious interrupts,
-        * but should be enough to warn the user that there
-        * is something bad going on ...
-        */
-       if (cached_irq_mask & irqmask)
-               goto spurious_8259A_irq;
-       cached_irq_mask |= irqmask;
-
-handle_real_irq:
-       if (irq & 8) {
-               inb(PIC_SLAVE_IMR);     /* DUMMY - (do we need this?) */
-               outb(cached_slave_mask, PIC_SLAVE_IMR);
-               /* 'Specific EOI' to slave */
-               outb(0x60+(irq&7),PIC_SLAVE_CMD);
-                /* 'Specific EOI' to master-IRQ2 */
-               outb(0x60+PIC_CASCADE_IR,PIC_MASTER_CMD);
-       } else {
-               inb(PIC_MASTER_IMR);    /* DUMMY - (do we need this?) */
-               outb(cached_master_mask, PIC_MASTER_IMR);
-               /* 'Specific EOI' to master */
-               outb(0x60+irq,PIC_MASTER_CMD);
-       }
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-       return;
-
-spurious_8259A_irq:
-       /*
-        * this is the slow path - should happen rarely.
-        */
-       if (i8259A_irq_real(irq))
-               /*
-                * oops, the IRQ _is_ in service according to the
-                * 8259A - not spurious, go handle it.
-                */
-               goto handle_real_irq;
-
-       {
-               static int spurious_irq_mask;
-               /*
-                * At this point we can be sure the IRQ is spurious,
-                * lets ACK and report it. [once per IRQ]
-                */
-               if (!(spurious_irq_mask & irqmask)) {
-                       printk(KERN_DEBUG
-                              "spurious 8259A interrupt: IRQ%d.\n", irq);
-                       spurious_irq_mask |= irqmask;
-               }
-               atomic_inc(&irq_err_count);
-               /*
-                * Theoretically we do not have to handle this IRQ,
-                * but in Linux this does not cause problems and is
-                * simpler for us.
-                */
-               goto handle_real_irq;
-       }
-}
-
-static char irq_trigger[2];
-/**
- * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
- */
-static void restore_ELCR(char *trigger)
-{
-       outb(trigger[0], 0x4d0);
-       outb(trigger[1], 0x4d1);
-}
-
-static void save_ELCR(char *trigger)
-{
-       /* IRQ 0,1,2,8,13 are marked as reserved */
-       trigger[0] = inb(0x4d0) & 0xF8;
-       trigger[1] = inb(0x4d1) & 0xDE;
-}
-
-static int i8259A_resume(struct sys_device *dev)
-{
-       init_8259A(i8259A_auto_eoi);
-       restore_ELCR(irq_trigger);
-       return 0;
-}
-
-static int i8259A_suspend(struct sys_device *dev, pm_message_t state)
-{
-       save_ELCR(irq_trigger);
-       return 0;
-}
-
-static int i8259A_shutdown(struct sys_device *dev)
-{
-       /* Put the i8259A into a quiescent state that
-        * the kernel initialization code can get it
-        * out of.
-        */
-       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
-       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-1 */
-       return 0;
-}
-
-static struct sysdev_class i8259_sysdev_class = {
-       .name = "i8259",
-       .suspend = i8259A_suspend,
-       .resume = i8259A_resume,
-       .shutdown = i8259A_shutdown,
-};
-
-static struct sys_device device_i8259A = {
-       .id     = 0,
-       .cls    = &i8259_sysdev_class,
-};
-
-static int __init i8259A_init_sysfs(void)
-{
-       int error = sysdev_class_register(&i8259_sysdev_class);
-       if (!error)
-               error = sysdev_register(&device_i8259A);
-       return error;
-}
-
-device_initcall(i8259A_init_sysfs);
-
-void init_8259A(int auto_eoi)
-{
-       unsigned long flags;
-
-       i8259A_auto_eoi = auto_eoi;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-
-       outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
-       outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-2 */
-
-       /*
-        * outb_pic - this has to work on a wide range of PC hardware.
-        */
-       outb_pic(0x11, PIC_MASTER_CMD); /* ICW1: select 8259A-1 init */
-       /* ICW2: 8259A-1 IR0-7 mapped to 0x30-0x37 */
-       outb_pic(IRQ0_VECTOR, PIC_MASTER_IMR);
-       /* 8259A-1 (the master) has a slave on IR2 */
-       outb_pic(0x04, PIC_MASTER_IMR);
-       if (auto_eoi)   /* master does Auto EOI */
-               outb_pic(MASTER_ICW4_DEFAULT | PIC_ICW4_AEOI, PIC_MASTER_IMR);
-       else            /* master expects normal EOI */
-               outb_pic(MASTER_ICW4_DEFAULT, PIC_MASTER_IMR);
-
-       outb_pic(0x11, PIC_SLAVE_CMD);  /* ICW1: select 8259A-2 init */
-       /* ICW2: 8259A-2 IR0-7 mapped to 0x38-0x3f */
-       outb_pic(IRQ8_VECTOR, PIC_SLAVE_IMR);
-       /* 8259A-2 is a slave on master's IR2 */
-       outb_pic(PIC_CASCADE_IR, PIC_SLAVE_IMR);
-       /* (slave's support for AEOI in flat mode is to be investigated) */
-       outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
-
-       if (auto_eoi)
-               /*
-                * In AEOI mode we just have to mask the interrupt
-                * when acking.
-                */
-               i8259A_chip.mask_ack = disable_8259A_irq;
-       else
-               i8259A_chip.mask_ack = mask_and_ack_8259A;
-
-       udelay(100);            /* wait for 8259A to initialize */
-
-       outb(cached_master_mask, PIC_MASTER_IMR); /* restore master IRQ mask */
-       outb(cached_slave_mask, PIC_SLAVE_IMR);   /* restore slave IRQ mask */
-
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-}
-
-
-
-
-/*
- * IRQ2 is cascade interrupt to second interrupt controller
- */
-
-static struct irqaction irq2 = {
-       .handler = no_action,
-       .mask = CPU_MASK_NONE,
-       .name = "cascade",
-};
-DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
-       [0 ... IRQ0_VECTOR - 1] = -1,
-       [IRQ0_VECTOR] = 0,
-       [IRQ1_VECTOR] = 1,
-       [IRQ2_VECTOR] = 2,
-       [IRQ3_VECTOR] = 3,
-       [IRQ4_VECTOR] = 4,
-       [IRQ5_VECTOR] = 5,
-       [IRQ6_VECTOR] = 6,
-       [IRQ7_VECTOR] = 7,
-       [IRQ8_VECTOR] = 8,
-       [IRQ9_VECTOR] = 9,
-       [IRQ10_VECTOR] = 10,
-       [IRQ11_VECTOR] = 11,
-       [IRQ12_VECTOR] = 12,
-       [IRQ13_VECTOR] = 13,
-       [IRQ14_VECTOR] = 14,
-       [IRQ15_VECTOR] = 15,
-       [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1
-};
-
-void __init init_ISA_irqs (void)
-{
-       int i;
-
-       init_bsp_APIC();
-       init_8259A(0);
-
-       for (i = 0; i < NR_IRQS; i++) {
-               irq_desc[i].status = IRQ_DISABLED;
-               irq_desc[i].action = NULL;
-               irq_desc[i].depth = 1;
-
-               if (i < 16) {
-                       /*
-                        * 16 old-style INTA-cycle interrupts:
-                        */
-                       set_irq_chip_and_handler_name(i, &i8259A_chip,
-                                                     handle_level_irq, "XT");
-               } else {
-                       /*
-                        * 'high' PCI IRQs filled in on demand
-                        */
-                       irq_desc[i].chip = &no_irq_chip;
-               }
-       }
-}
-
-void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
-
-void __init native_init_IRQ(void)
-{
-       int i;
-
-       init_ISA_irqs();
-       /*
-        * Cover the whole vector space, no vector can escape
-        * us. (some of these will be overridden and become
-        * 'special' SMP interrupts)
-        */
-       for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) {
-               int vector = FIRST_EXTERNAL_VECTOR + i;
-               if (vector != IA32_SYSCALL_VECTOR)
-                       set_intr_gate(vector, interrupt[i]);
-       }
-
-#ifdef CONFIG_SMP
-       /*
-        * The reschedule interrupt is a CPU-to-CPU reschedule-helper
-        * IPI, driven by wakeup.
-        */
-       set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
-
-       /* IPIs for invalidation */
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
-       set_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
-
-       /* IPI for generic function call */
-       set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
-
-       /* Low priority IPI to cleanup after moving an irq */
-       set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
-#endif
-       set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
-       set_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt);
-
-       /* self generated IPI for local APIC timer */
-       set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
-
-       /* IPI vectors for APIC spurious and error interrupts */
-       set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
-       set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
-
-       if (!acpi_ioapic)
-               setup_irq(2, &irq2);
-}
index 4dc8600..603261a 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/sched.h>
+#include <linux/bootmem.h>
 #include <linux/mc146818rtc.h>
 #include <linux/compiler.h>
 #include <linux/acpi.h>
@@ -58,7 +59,7 @@ static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
 static DEFINE_SPINLOCK(ioapic_lock);
 static DEFINE_SPINLOCK(vector_lock);
 
-int timer_over_8254 __initdata = 1;
+int timer_through_8259 __initdata;
 
 /*
  *     Is the SiS APIC rmw bug present ?
@@ -72,15 +73,21 @@ int sis_apic_bug = -1;
 int nr_ioapic_registers[MAX_IO_APICS];
 
 /* I/O APIC entries */
-struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
+struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
 int nr_ioapics;
 
 /* MP IRQ source entries */
-struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
+struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
 
 /* # of MP IRQ source entries */
 int mp_irq_entries;
 
+#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
+int mp_bus_id_to_type[MAX_MP_BUSSES];
+#endif
+
+DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
+
 static int disable_timer_pin_1 __initdata;
 
 /*
@@ -110,7 +117,7 @@ struct io_apic {
 static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
 {
        return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
-               + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK);
+               + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK);
 }
 
 static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
@@ -239,7 +246,7 @@ static void __init replace_pin_at_irq(unsigned int irq,
        }
 }
 
-static void __modify_IO_APIC_irq (unsigned int irq, unsigned long enable, unsigned long disable)
+static void __modify_IO_APIC_irq(unsigned int irq, unsigned long enable, unsigned long disable)
 {
        struct irq_pin_list *entry = irq_2_pin + irq;
        unsigned int pin, reg;
@@ -259,30 +266,32 @@ static void __modify_IO_APIC_irq (unsigned int irq, unsigned long enable, unsign
 }
 
 /* mask = 1 */
-static void __mask_IO_APIC_irq (unsigned int irq)
+static void __mask_IO_APIC_irq(unsigned int irq)
 {
-       __modify_IO_APIC_irq(irq, 0x00010000, 0);
+       __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, 0);
 }
 
 /* mask = 0 */
-static void __unmask_IO_APIC_irq (unsigned int irq)
+static void __unmask_IO_APIC_irq(unsigned int irq)
 {
-       __modify_IO_APIC_irq(irq, 0, 0x00010000);
+       __modify_IO_APIC_irq(irq, 0, IO_APIC_REDIR_MASKED);
 }
 
 /* mask = 1, trigger = 0 */
-static void __mask_and_edge_IO_APIC_irq (unsigned int irq)
+static void __mask_and_edge_IO_APIC_irq(unsigned int irq)
 {
-       __modify_IO_APIC_irq(irq, 0x00010000, 0x00008000);
+       __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED,
+                               IO_APIC_REDIR_LEVEL_TRIGGER);
 }
 
 /* mask = 0, trigger = 1 */
-static void __unmask_and_level_IO_APIC_irq (unsigned int irq)
+static void __unmask_and_level_IO_APIC_irq(unsigned int irq)
 {
-       __modify_IO_APIC_irq(irq, 0x00008000, 0x00010000);
+       __modify_IO_APIC_irq(irq, IO_APIC_REDIR_LEVEL_TRIGGER,
+                               IO_APIC_REDIR_MASKED);
 }
 
-static void mask_IO_APIC_irq (unsigned int irq)
+static void mask_IO_APIC_irq(unsigned int irq)
 {
        unsigned long flags;
 
@@ -291,7 +300,7 @@ static void mask_IO_APIC_irq (unsigned int irq)
        spin_unlock_irqrestore(&ioapic_lock, flags);
 }
 
-static void unmask_IO_APIC_irq (unsigned int irq)
+static void unmask_IO_APIC_irq(unsigned int irq)
 {
        unsigned long flags;
 
@@ -303,7 +312,7 @@ static void unmask_IO_APIC_irq (unsigned int irq)
 static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
 {
        struct IO_APIC_route_entry entry;
-       
+
        /* Check delivery_mode to be sure we're not clearing an SMI pin */
        entry = ioapic_read_entry(apic, pin);
        if (entry.delivery_mode == dest_SMI)
@@ -315,7 +324,7 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
        ioapic_mask_entry(apic, pin);
 }
 
-static void clear_IO_APIC (void)
+static void clear_IO_APIC(void)
 {
        int apic, pin;
 
@@ -332,7 +341,7 @@ static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask)
        struct irq_pin_list *entry = irq_2_pin + irq;
        unsigned int apicid_value;
        cpumask_t tmp;
-       
+
        cpus_and(tmp, cpumask, cpu_online_map);
        if (cpus_empty(tmp))
                tmp = TARGET_CPUS;
@@ -361,7 +370,7 @@ static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask)
 # include <linux/kernel_stat.h>        /* kstat */
 # include <linux/slab.h>               /* kmalloc() */
 # include <linux/timer.h>
+
 #define IRQBALANCE_CHECK_ARCH -999
 #define MAX_BALANCED_IRQ_INTERVAL      (5*HZ)
 #define MIN_BALANCED_IRQ_INTERVAL      (HZ/2)
@@ -373,14 +382,14 @@ static int physical_balance __read_mostly;
 static long balanced_irq_interval __read_mostly = MAX_BALANCED_IRQ_INTERVAL;
 
 static struct irq_cpu_info {
-       unsigned long * last_irq;
-       unsigned long * irq_delta;
+       unsigned long *last_irq;
+       unsigned long *irq_delta;
        unsigned long irq;
 } irq_cpu_data[NR_CPUS];
 
 #define CPU_IRQ(cpu)           (irq_cpu_data[cpu].irq)
-#define LAST_CPU_IRQ(cpu,irq)   (irq_cpu_data[cpu].last_irq[irq])
-#define IRQ_DELTA(cpu,irq)     (irq_cpu_data[cpu].irq_delta[irq])
+#define LAST_CPU_IRQ(cpu, irq)   (irq_cpu_data[cpu].last_irq[irq])
+#define IRQ_DELTA(cpu, irq)    (irq_cpu_data[cpu].irq_delta[irq])
 
 #define IDLE_ENOUGH(cpu,now) \
        (idle_cpu(cpu) && ((now) - per_cpu(irq_stat, (cpu)).idle_timestamp > 1))
@@ -419,8 +428,8 @@ inside:
                        if (cpu == -1)
                                cpu = NR_CPUS-1;
                }
-       } while (!cpu_online(cpu) || !IRQ_ALLOWED(cpu,allowed_mask) ||
-                       (search_idle && !IDLE_ENOUGH(cpu,now)));
+       } while (!cpu_online(cpu) || !IRQ_ALLOWED(cpu, allowed_mask) ||
+                       (search_idle && !IDLE_ENOUGH(cpu, now)));
 
        return cpu;
 }
@@ -430,15 +439,14 @@ static inline void balance_irq(int cpu, int irq)
        unsigned long now = jiffies;
        cpumask_t allowed_mask;
        unsigned int new_cpu;
-               
+
        if (irqbalance_disabled)
-               return; 
+               return;
 
        cpus_and(allowed_mask, cpu_online_map, balance_irq_affinity[irq]);
        new_cpu = move(cpu, allowed_mask, now, 1);
-       if (cpu != new_cpu) {
+       if (cpu != new_cpu)
                set_pending_irq(irq, cpumask_of_cpu(new_cpu));
-       }
 }
 
 static inline void rotate_irqs_among_cpus(unsigned long useful_load_threshold)
@@ -450,14 +458,14 @@ static inline void rotate_irqs_among_cpus(unsigned long useful_load_threshold)
                        if (!irq_desc[j].action)
                                continue;
                        /* Is it a significant load ?  */
-                       if (IRQ_DELTA(CPU_TO_PACKAGEINDEX(i),j) <
+                       if (IRQ_DELTA(CPU_TO_PACKAGEINDEX(i), j) <
                                                useful_load_threshold)
                                continue;
                        balance_irq(i, j);
                }
        }
        balanced_irq_interval = max((long)MIN_BALANCED_IRQ_INTERVAL,
-               balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);       
+               balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);
        return;
 }
 
@@ -486,22 +494,22 @@ static void do_irq_balance(void)
                        /* Is this an active IRQ or balancing disabled ? */
                        if (!irq_desc[j].action || irq_balancing_disabled(j))
                                continue;
-                       if ( package_index == i )
-                               IRQ_DELTA(package_index,j) = 0;
+                       if (package_index == i)
+                               IRQ_DELTA(package_index, j) = 0;
                        /* Determine the total count per processor per IRQ */
                        value_now = (unsigned long) kstat_cpu(i).irqs[j];
 
                        /* Determine the activity per processor per IRQ */
-                       delta = value_now - LAST_CPU_IRQ(i,j);
+                       delta = value_now - LAST_CPU_IRQ(i, j);
 
                        /* Update last_cpu_irq[][] for the next time */
-                       LAST_CPU_IRQ(i,j) = value_now;
+                       LAST_CPU_IRQ(i, j) = value_now;
 
                        /* Ignore IRQs whose rate is less than the clock */
                        if (delta < useful_load_threshold)
                                continue;
                        /* update the load for the processor or package total */
-                       IRQ_DELTA(package_index,j) += delta;
+                       IRQ_DELTA(package_index, j) += delta;
 
                        /* Keep track of the higher numbered sibling as well */
                        if (i != package_index)
@@ -527,7 +535,8 @@ static void do_irq_balance(void)
        max_cpu_irq = ULONG_MAX;
 
 tryanothercpu:
-       /* Look for heaviest loaded processor.
+       /*
+        * Look for heaviest loaded processor.
         * We may come back to get the next heaviest loaded processor.
         * Skip processors with trivial loads.
         */
@@ -536,7 +545,7 @@ tryanothercpu:
        for_each_online_cpu(i) {
                if (i != CPU_TO_PACKAGEINDEX(i))
                        continue;
-               if (max_cpu_irq <= CPU_IRQ(i)) 
+               if (max_cpu_irq <= CPU_IRQ(i))
                        continue;
                if (tmp_cpu_irq < CPU_IRQ(i)) {
                        tmp_cpu_irq = CPU_IRQ(i);
@@ -545,8 +554,9 @@ tryanothercpu:
        }
 
        if (tmp_loaded == -1) {
-        /* In the case of small number of heavy interrupt sources, 
-         * loading some of the cpus too much. We use Ingo's original 
+        /*
+         * In the case of small number of heavy interrupt sources,
+         * loading some of the cpus too much. We use Ingo's original
          * approach to rotate them around.
          */
                if (!first_attempt && imbalance >= useful_load_threshold) {
@@ -555,13 +565,14 @@ tryanothercpu:
                }
                goto not_worth_the_effort;
        }
-       
+
        first_attempt = 0;              /* heaviest search */
        max_cpu_irq = tmp_cpu_irq;      /* load */
        max_loaded = tmp_loaded;        /* processor */
        imbalance = (max_cpu_irq - min_cpu_irq) / 2;
-       
-       /* if imbalance is less than approx 10% of max load, then
+
+       /*
+        * if imbalance is less than approx 10% of max load, then
         * observe diminishing returns action. - quit
         */
        if (imbalance < (max_cpu_irq >> 3))
@@ -577,26 +588,25 @@ tryanotherirq:
                /* Is this an active IRQ? */
                if (!irq_desc[j].action)
                        continue;
-               if (imbalance <= IRQ_DELTA(max_loaded,j))
+               if (imbalance <= IRQ_DELTA(max_loaded, j))
                        continue;
                /* Try to find the IRQ that is closest to the imbalance
                 * without going over.
                 */
-               if (move_this_load < IRQ_DELTA(max_loaded,j)) {
-                       move_this_load = IRQ_DELTA(max_loaded,j);
+               if (move_this_load < IRQ_DELTA(max_loaded, j)) {
+                       move_this_load = IRQ_DELTA(max_loaded, j);
                        selected_irq = j;
                }
        }
-       if (selected_irq == -1) {
+       if (selected_irq == -1)
                goto tryanothercpu;
-       }
 
        imbalance = move_this_load;
-       
+
        /* For physical_balance case, we accumulated both load
         * values in the one of the siblings cpu_irq[],
         * to use the same code for physical and logical processors
-        * as much as possible. 
+        * as much as possible.
         *
         * NOTE: the cpu_irq[] array holds the sum of the load for
         * sibling A and sibling B in the slot for the lowest numbered
@@ -625,11 +635,11 @@ tryanotherirq:
                /* mark for change destination */
                set_pending_irq(selected_irq, cpumask_of_cpu(min_loaded));
 
-               /* Since we made a change, come back sooner to 
+               /* Since we made a change, come back sooner to
                 * check for more variation.
                 */
                balanced_irq_interval = max((long)MIN_BALANCED_IRQ_INTERVAL,
-                       balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);       
+                       balanced_irq_interval - BALANCED_IRQ_LESS_DELTA);
                return;
        }
        goto tryanotherirq;
@@ -640,7 +650,7 @@ not_worth_the_effort:
         * upward
         */
        balanced_irq_interval = min((long)MAX_BALANCED_IRQ_INTERVAL,
-               balanced_irq_interval + BALANCED_IRQ_MORE_DELTA);       
+               balanced_irq_interval + BALANCED_IRQ_MORE_DELTA);
        return;
 }
 
@@ -679,13 +689,13 @@ static int __init balanced_irq_init(void)
        cpumask_t tmp;
 
        cpus_shift_right(tmp, cpu_online_map, 2);
-        c = &boot_cpu_data;
+       c = &boot_cpu_data;
        /* When not overwritten by the command line ask subarchitecture. */
        if (irqbalance_disabled == IRQBALANCE_CHECK_ARCH)
                irqbalance_disabled = NO_BALANCE_IRQ;
        if (irqbalance_disabled)
                return 0;
-       
+
         /* disable irqbalance completely if there is only one processor online */
        if (num_online_cpus() < 2) {
                irqbalance_disabled = 1;
@@ -699,16 +709,14 @@ static int __init balanced_irq_init(void)
                physical_balance = 1;
 
        for_each_online_cpu(i) {
-               irq_cpu_data[i].irq_delta = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
-               irq_cpu_data[i].last_irq = kmalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
+               irq_cpu_data[i].irq_delta = kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
+               irq_cpu_data[i].last_irq = kzalloc(sizeof(unsigned long) * NR_IRQS, GFP_KERNEL);
                if (irq_cpu_data[i].irq_delta == NULL || irq_cpu_data[i].last_irq == NULL) {
                        printk(KERN_ERR "balanced_irq_init: out of memory");
                        goto failed;
                }
-               memset(irq_cpu_data[i].irq_delta,0,sizeof(unsigned long) * NR_IRQS);
-               memset(irq_cpu_data[i].last_irq,0,sizeof(unsigned long) * NR_IRQS);
        }
-       
+
        printk(KERN_INFO "Starting balanced_irq\n");
        if (!IS_ERR(kthread_run(balanced_irq, NULL, "kirqd")))
                return 0;
@@ -801,10 +809,10 @@ static int find_irq_entry(int apic, int pin, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++)
-               if (mp_irqs[i].mpc_irqtype == type &&
-                   (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid ||
-                    mp_irqs[i].mpc_dstapic == MP_APIC_ALL) &&
-                   mp_irqs[i].mpc_dstirq == pin)
+               if (mp_irqs[i].mp_irqtype == type &&
+                   (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid ||
+                    mp_irqs[i].mp_dstapic == MP_APIC_ALL) &&
+                   mp_irqs[i].mp_dstirq == pin)
                        return i;
 
        return -1;
@@ -818,13 +826,13 @@ static int __init find_isa_irq_pin(int irq, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                if (test_bit(lbus, mp_bus_not_pci) &&
-                   (mp_irqs[i].mpc_irqtype == type) &&
-                   (mp_irqs[i].mpc_srcbusirq == irq))
+                   (mp_irqs[i].mp_irqtype == type) &&
+                   (mp_irqs[i].mp_srcbusirq == irq))
 
-                       return mp_irqs[i].mpc_dstirq;
+                       return mp_irqs[i].mp_dstirq;
        }
        return -1;
 }
@@ -834,17 +842,17 @@ static int __init find_isa_irq_apic(int irq, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                if (test_bit(lbus, mp_bus_not_pci) &&
-                   (mp_irqs[i].mpc_irqtype == type) &&
-                   (mp_irqs[i].mpc_srcbusirq == irq))
+                   (mp_irqs[i].mp_irqtype == type) &&
+                   (mp_irqs[i].mp_srcbusirq == irq))
                        break;
        }
        if (i < mp_irq_entries) {
                int apic;
-               for(apic = 0; apic < nr_ioapics; apic++) {
-                       if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic)
+               for (apic = 0; apic < nr_ioapics; apic++) {
+                       if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic)
                                return apic;
                }
        }
@@ -864,28 +872,28 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
 
        apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, "
                "slot:%d, pin:%d.\n", bus, slot, pin);
-       if (mp_bus_id_to_pci_bus[bus] == -1) {
+       if (test_bit(bus, mp_bus_not_pci)) {
                printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
                return -1;
        }
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                for (apic = 0; apic < nr_ioapics; apic++)
-                       if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic ||
-                           mp_irqs[i].mpc_dstapic == MP_APIC_ALL)
+                       if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic ||
+                           mp_irqs[i].mp_dstapic == MP_APIC_ALL)
                                break;
 
                if (!test_bit(lbus, mp_bus_not_pci) &&
-                   !mp_irqs[i].mpc_irqtype &&
+                   !mp_irqs[i].mp_irqtype &&
                    (bus == lbus) &&
-                   (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) {
-                       int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq);
+                   (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) {
+                       int irq = pin_2_irq(i, apic, mp_irqs[i].mp_dstirq);
 
                        if (!(apic || IO_APIC_IRQ(irq)))
                                continue;
 
-                       if (pin == (mp_irqs[i].mpc_srcbusirq & 3))
+                       if (pin == (mp_irqs[i].mp_srcbusirq & 3))
                                return irq;
                        /*
                         * Use the first all-but-pin matching entry as a
@@ -900,7 +908,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
 
 /*
- * This function currently is only a helper for the i386 smp boot process where 
+ * This function currently is only a helper for the i386 smp boot process where
  * we need to reprogram the ioredtbls to cater for the cpus which have come online
  * so mask in all cases should simply be TARGET_CPUS
  */
@@ -952,7 +960,7 @@ static int EISA_ELCR(unsigned int irq)
  * EISA conforming in the MP table, that means its trigger type must
  * be read in from the ELCR */
 
-#define default_EISA_trigger(idx)      (EISA_ELCR(mp_irqs[idx].mpc_srcbusirq))
+#define default_EISA_trigger(idx)      (EISA_ELCR(mp_irqs[idx].mp_srcbusirq))
 #define default_EISA_polarity(idx)     default_ISA_polarity(idx)
 
 /* PCI interrupts are always polarity one level triggered,
@@ -969,118 +977,115 @@ static int EISA_ELCR(unsigned int irq)
 
 static int MPBIOS_polarity(int idx)
 {
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
        int polarity;
 
        /*
         * Determine IRQ line polarity (high active or low active):
         */
-       switch (mp_irqs[idx].mpc_irqflag & 3)
+       switch (mp_irqs[idx].mp_irqflag & 3) {
+       case 0: /* conforms, ie. bus-type dependent polarity */
        {
-               case 0: /* conforms, ie. bus-type dependent polarity */
-               {
-                       polarity = test_bit(bus, mp_bus_not_pci)?
-                               default_ISA_polarity(idx):
-                               default_PCI_polarity(idx);
-                       break;
-               }
-               case 1: /* high active */
-               {
-                       polarity = 0;
-                       break;
-               }
-               case 2: /* reserved */
-               {
-                       printk(KERN_WARNING "broken BIOS!!\n");
-                       polarity = 1;
-                       break;
-               }
-               case 3: /* low active */
-               {
-                       polarity = 1;
-                       break;
-               }
-               default: /* invalid */
-               {
-                       printk(KERN_WARNING "broken BIOS!!\n");
-                       polarity = 1;
-                       break;
-               }
+               polarity = test_bit(bus, mp_bus_not_pci)?
+                       default_ISA_polarity(idx):
+                       default_PCI_polarity(idx);
+               break;
+       }
+       case 1: /* high active */
+       {
+               polarity = 0;
+               break;
+       }
+       case 2: /* reserved */
+       {
+               printk(KERN_WARNING "broken BIOS!!\n");
+               polarity = 1;
+               break;
+       }
+       case 3: /* low active */
+       {
+               polarity = 1;
+               break;
+       }
+       default: /* invalid */
+       {
+               printk(KERN_WARNING "broken BIOS!!\n");
+               polarity = 1;
+               break;
+       }
        }
        return polarity;
 }
 
 static int MPBIOS_trigger(int idx)
 {
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
        int trigger;
 
        /*
         * Determine IRQ trigger mode (edge or level sensitive):
         */
-       switch ((mp_irqs[idx].mpc_irqflag>>2) & 3)
+       switch ((mp_irqs[idx].mp_irqflag>>2) & 3) {
+       case 0: /* conforms, ie. bus-type dependent */
        {
-               case 0: /* conforms, ie. bus-type dependent */
-               {
-                       trigger = test_bit(bus, mp_bus_not_pci)?
-                                       default_ISA_trigger(idx):
-                                       default_PCI_trigger(idx);
+               trigger = test_bit(bus, mp_bus_not_pci)?
+                               default_ISA_trigger(idx):
+                               default_PCI_trigger(idx);
 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
-                       switch (mp_bus_id_to_type[bus])
-                       {
-                               case MP_BUS_ISA: /* ISA pin */
-                               {
-                                       /* set before the switch */
-                                       break;
-                               }
-                               case MP_BUS_EISA: /* EISA pin */
-                               {
-                                       trigger = default_EISA_trigger(idx);
-                                       break;
-                               }
-                               case MP_BUS_PCI: /* PCI pin */
-                               {
-                                       /* set before the switch */
-                                       break;
-                               }
-                               case MP_BUS_MCA: /* MCA pin */
-                               {
-                                       trigger = default_MCA_trigger(idx);
-                                       break;
-                               }
-                               default:
-                               {
-                                       printk(KERN_WARNING "broken BIOS!!\n");
-                                       trigger = 1;
-                                       break;
-                               }
-                       }
-#endif
+               switch (mp_bus_id_to_type[bus]) {
+               case MP_BUS_ISA: /* ISA pin */
+               {
+                       /* set before the switch */
                        break;
                }
-               case 1: /* edge */
+               case MP_BUS_EISA: /* EISA pin */
                {
-                       trigger = 0;
+                       trigger = default_EISA_trigger(idx);
                        break;
                }
-               case 2: /* reserved */
+               case MP_BUS_PCI: /* PCI pin */
                {
-                       printk(KERN_WARNING "broken BIOS!!\n");
-                       trigger = 1;
+                       /* set before the switch */
                        break;
                }
-               case 3: /* level */
+               case MP_BUS_MCA: /* MCA pin */
                {
-                       trigger = 1;
+                       trigger = default_MCA_trigger(idx);
                        break;
                }
-               default: /* invalid */
+               default:
                {
                        printk(KERN_WARNING "broken BIOS!!\n");
-                       trigger = 0;
+                       trigger = 1;
                        break;
                }
        }
+#endif
+               break;
+       }
+       case 1: /* edge */
+       {
+               trigger = 0;
+               break;
+       }
+       case 2: /* reserved */
+       {
+               printk(KERN_WARNING "broken BIOS!!\n");
+               trigger = 1;
+               break;
+       }
+       case 3: /* level */
+       {
+               trigger = 1;
+               break;
+       }
+       default: /* invalid */
+       {
+               printk(KERN_WARNING "broken BIOS!!\n");
+               trigger = 0;
+               break;
+       }
+       }
        return trigger;
 }
 
@@ -1097,16 +1102,16 @@ static inline int irq_trigger(int idx)
 static int pin_2_irq(int idx, int apic, int pin)
 {
        int irq, i;
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
 
        /*
         * Debugging check, we are in big trouble if this message pops up!
         */
-       if (mp_irqs[idx].mpc_dstirq != pin)
+       if (mp_irqs[idx].mp_dstirq != pin)
                printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
 
        if (test_bit(bus, mp_bus_not_pci))
-               irq = mp_irqs[idx].mpc_srcbusirq;
+               irq = mp_irqs[idx].mp_srcbusirq;
        else {
                /*
                 * PCI IRQs are mapped in order
@@ -1148,8 +1153,8 @@ static inline int IO_APIC_irq_trigger(int irq)
 
        for (apic = 0; apic < nr_ioapics; apic++) {
                for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
-                       idx = find_irq_entry(apic,pin,mp_INT);
-                       if ((idx != -1) && (irq == pin_2_irq(idx,apic,pin)))
+                       idx = find_irq_entry(apic, pin, mp_INT);
+                       if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
                                return irq_trigger(idx);
                }
        }
@@ -1164,7 +1169,7 @@ static u8 irq_vector[NR_IRQ_VECTORS] __read_mostly = { FIRST_DEVICE_VECTOR , 0 }
 
 static int __assign_irq_vector(int irq)
 {
-       static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
+       static int current_vector = FIRST_DEVICE_VECTOR, current_offset;
        int vector, offset;
 
        BUG_ON((unsigned)irq >= NR_IRQ_VECTORS);
@@ -1176,7 +1181,7 @@ static int __assign_irq_vector(int irq)
        offset = current_offset;
 next:
        vector += 8;
-       if (vector >= FIRST_SYSTEM_VECTOR) {
+       if (vector >= first_system_vector) {
                offset = (offset + 1) % 8;
                vector = FIRST_DEVICE_VECTOR + offset;
        }
@@ -1203,6 +1208,11 @@ static int assign_irq_vector(int irq)
 
        return vector;
 }
+
+void setup_vector_irq(int cpu)
+{
+}
+
 static struct irq_chip ioapic_chip;
 
 #define IOAPIC_AUTO    -1
@@ -1237,25 +1247,25 @@ static void __init setup_IO_APIC_irqs(void)
                /*
                 * add it to the IO-APIC irq-routing table:
                 */
-               memset(&entry,0,sizeof(entry));
+               memset(&entry, 0, sizeof(entry));
 
                entry.delivery_mode = INT_DELIVERY_MODE;
                entry.dest_mode = INT_DEST_MODE;
                entry.mask = 0;                         /* enable IRQ */
-               entry.dest.logical.logical_dest = 
+               entry.dest.logical.logical_dest =
                                        cpu_mask_to_apicid(TARGET_CPUS);
 
-               idx = find_irq_entry(apic,pin,mp_INT);
+               idx = find_irq_entry(apic, pin, mp_INT);
                if (idx == -1) {
                        if (first_notcon) {
                                apic_printk(APIC_VERBOSE, KERN_DEBUG
                                                " IO-APIC (apicid-pin) %d-%d",
-                                               mp_ioapics[apic].mpc_apicid,
+                                               mp_ioapics[apic].mp_apicid,
                                                pin);
                                first_notcon = 0;
                        } else
                                apic_printk(APIC_VERBOSE, ", %d-%d",
-                                       mp_ioapics[apic].mpc_apicid, pin);
+                                       mp_ioapics[apic].mp_apicid, pin);
                        continue;
                }
 
@@ -1289,7 +1299,7 @@ static void __init setup_IO_APIC_irqs(void)
                        vector = assign_irq_vector(irq);
                        entry.vector = vector;
                        ioapic_register_intr(irq, vector, IOAPIC_AUTO);
-               
+
                        if (!apic && (irq < 16))
                                disable_8259A_irq(irq);
                }
@@ -1302,25 +1312,21 @@ static void __init setup_IO_APIC_irqs(void)
 }
 
 /*
- * Set up the 8259A-master output pin:
+ * Set up the timer pin, possibly with the 8259A-master behind.
  */
-static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector)
+static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin,
+                                       int vector)
 {
        struct IO_APIC_route_entry entry;
 
-       memset(&entry,0,sizeof(entry));
-
-       disable_8259A_irq(0);
-
-       /* mask LVT0 */
-       apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
+       memset(&entry, 0, sizeof(entry));
 
        /*
         * We use logical delivery to get the timer IRQ
         * to the first CPU.
         */
        entry.dest_mode = INT_DEST_MODE;
-       entry.mask = 0;                                 /* unmask IRQ now */
+       entry.mask = 1;                                 /* mask IRQ now */
        entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
        entry.delivery_mode = INT_DELIVERY_MODE;
        entry.polarity = 0;
@@ -1329,17 +1335,14 @@ static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, in
 
        /*
         * The timer IRQ doesn't have to know that behind the
-        * scene we have a 8259A-master in AEOI mode ...
+        * scene we may have a 8259A-master in AEOI mode ...
         */
-       irq_desc[0].chip = &ioapic_chip;
-       set_irq_handler(0, handle_edge_irq);
+       ioapic_register_intr(0, vector, IOAPIC_EDGE);
 
        /*
         * Add it to the IO-APIC irq-routing table:
         */
        ioapic_write_entry(apic, pin, entry);
-
-       enable_8259A_irq(0);
 }
 
 void __init print_IO_APIC(void)
@@ -1354,10 +1357,10 @@ void __init print_IO_APIC(void)
        if (apic_verbosity == APIC_QUIET)
                return;
 
-       printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
+       printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
        for (i = 0; i < nr_ioapics; i++)
                printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
-                      mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]);
+                      mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]);
 
        /*
         * We are a bit conservative about what we expect.  We have to
@@ -1376,7 +1379,7 @@ void __init print_IO_APIC(void)
                reg_03.raw = io_apic_read(apic, 3);
        spin_unlock_irqrestore(&ioapic_lock, flags);
 
-       printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid);
+       printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid);
        printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
        printk(KERN_DEBUG ".......    : physical APIC id: %02X\n", reg_00.bits.ID);
        printk(KERN_DEBUG ".......    : Delivery Type: %X\n", reg_00.bits.delivery_type);
@@ -1459,7 +1462,7 @@ void __init print_IO_APIC(void)
 
 #if 0
 
-static void print_APIC_bitfield (int base)
+static void print_APIC_bitfield(int base)
 {
        unsigned int v;
        int i, j;
@@ -1480,7 +1483,7 @@ static void print_APIC_bitfield (int base)
        }
 }
 
-void /*__init*/ print_local_APIC(void * dummy)
+void /*__init*/ print_local_APIC(void *dummy)
 {
        unsigned int v, ver, maxlvt;
 
@@ -1489,6 +1492,7 @@ void /*__init*/ print_local_APIC(void * dummy)
 
        printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
                smp_processor_id(), hard_smp_processor_id());
+       v = apic_read(APIC_ID);
        printk(KERN_INFO "... APIC ID:      %08x (%01x)\n", v,
                        GET_APIC_ID(read_apic_id()));
        v = apic_read(APIC_LVR);
@@ -1563,7 +1567,7 @@ void /*__init*/ print_local_APIC(void * dummy)
        printk("\n");
 }
 
-void print_all_local_APICs (void)
+void print_all_local_APICs(void)
 {
        on_each_cpu(print_local_APIC, NULL, 1, 1);
 }
@@ -1586,11 +1590,11 @@ void /*__init*/ print_PIC(void)
        v = inb(0xa0) << 8 | inb(0x20);
        printk(KERN_DEBUG "... PIC  IRR: %04x\n", v);
 
-       outb(0x0b,0xa0);
-       outb(0x0b,0x20);
+       outb(0x0b, 0xa0);
+       outb(0x0b, 0x20);
        v = inb(0xa0) << 8 | inb(0x20);
-       outb(0x0a,0xa0);
-       outb(0x0a,0x20);
+       outb(0x0a, 0xa0);
+       outb(0x0a, 0x20);
 
        spin_unlock_irqrestore(&i8259A_lock, flags);
 
@@ -1626,7 +1630,7 @@ static void __init enable_IO_APIC(void)
                spin_unlock_irqrestore(&ioapic_lock, flags);
                nr_ioapic_registers[apic] = reg_01.bits.entries+1;
        }
-       for(apic = 0; apic < nr_ioapics; apic++) {
+       for (apic = 0; apic < nr_ioapics; apic++) {
                int pin;
                /* See if any of the pins is in ExtINT mode */
                for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
@@ -1716,7 +1720,6 @@ void disable_IO_APIC(void)
  * by Matt Domsch <Matt_Domsch@dell.com>  Tue Dec 21 12:25:05 CST 1999
  */
 
-#ifndef CONFIG_X86_NUMAQ
 static void __init setup_ioapic_ids_from_mpc(void)
 {
        union IO_APIC_reg_00 reg_00;
@@ -1726,6 +1729,11 @@ static void __init setup_ioapic_ids_from_mpc(void)
        unsigned char old_id;
        unsigned long flags;
 
+#ifdef CONFIG_X86_NUMAQ
+       if (found_numaq)
+               return;
+#endif
+
        /*
         * Don't check I/O APIC IDs for xAPIC systems.  They have
         * no meaning without the serial APIC bus.
@@ -1748,15 +1756,15 @@ static void __init setup_ioapic_ids_from_mpc(void)
                spin_lock_irqsave(&ioapic_lock, flags);
                reg_00.raw = io_apic_read(apic, 0);
                spin_unlock_irqrestore(&ioapic_lock, flags);
-               
-               old_id = mp_ioapics[apic].mpc_apicid;
 
-               if (mp_ioapics[apic].mpc_apicid >= get_physical_broadcast()) {
+               old_id = mp_ioapics[apic].mp_apicid;
+
+               if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) {
                        printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
-                               apic, mp_ioapics[apic].mpc_apicid);
+                               apic, mp_ioapics[apic].mp_apicid);
                        printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
                                reg_00.bits.ID);
-                       mp_ioapics[apic].mpc_apicid = reg_00.bits.ID;
+                       mp_ioapics[apic].mp_apicid = reg_00.bits.ID;
                }
 
                /*
@@ -1765,9 +1773,9 @@ static void __init setup_ioapic_ids_from_mpc(void)
                 * 'stuck on smp_invalidate_needed IPI wait' messages.
                 */
                if (check_apicid_used(phys_id_present_map,
-                                       mp_ioapics[apic].mpc_apicid)) {
+                                       mp_ioapics[apic].mp_apicid)) {
                        printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
-                               apic, mp_ioapics[apic].mpc_apicid);
+                               apic, mp_ioapics[apic].mp_apicid);
                        for (i = 0; i < get_physical_broadcast(); i++)
                                if (!physid_isset(i, phys_id_present_map))
                                        break;
@@ -1776,13 +1784,13 @@ static void __init setup_ioapic_ids_from_mpc(void)
                        printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
                                i);
                        physid_set(i, phys_id_present_map);
-                       mp_ioapics[apic].mpc_apicid = i;
+                       mp_ioapics[apic].mp_apicid = i;
                } else {
                        physid_mask_t tmp;
-                       tmp = apicid_to_cpu_present(mp_ioapics[apic].mpc_apicid);
+                       tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid);
                        apic_printk(APIC_VERBOSE, "Setting %d in the "
                                        "phys_id_present_map\n",
-                                       mp_ioapics[apic].mpc_apicid);
+                                       mp_ioapics[apic].mp_apicid);
                        physids_or(phys_id_present_map, phys_id_present_map, tmp);
                }
 
@@ -1791,21 +1799,21 @@ static void __init setup_ioapic_ids_from_mpc(void)
                 * We need to adjust the IRQ routing table
                 * if the ID changed.
                 */
-               if (old_id != mp_ioapics[apic].mpc_apicid)
+               if (old_id != mp_ioapics[apic].mp_apicid)
                        for (i = 0; i < mp_irq_entries; i++)
-                               if (mp_irqs[i].mpc_dstapic == old_id)
-                                       mp_irqs[i].mpc_dstapic
-                                               = mp_ioapics[apic].mpc_apicid;
+                               if (mp_irqs[i].mp_dstapic == old_id)
+                                       mp_irqs[i].mp_dstapic
+                                               = mp_ioapics[apic].mp_apicid;
 
                /*
                 * Read the right value from the MPC table and
                 * write it into the ID register.
-                */
+                */
                apic_printk(APIC_VERBOSE, KERN_INFO
                        "...changing IO-APIC physical APIC ID to %d ...",
-                       mp_ioapics[apic].mpc_apicid);
+                       mp_ioapics[apic].mp_apicid);
 
-               reg_00.bits.ID = mp_ioapics[apic].mpc_apicid;
+               reg_00.bits.ID = mp_ioapics[apic].mp_apicid;
                spin_lock_irqsave(&ioapic_lock, flags);
                io_apic_write(apic, 0, reg_00.raw);
                spin_unlock_irqrestore(&ioapic_lock, flags);
@@ -1816,15 +1824,12 @@ static void __init setup_ioapic_ids_from_mpc(void)
                spin_lock_irqsave(&ioapic_lock, flags);
                reg_00.raw = io_apic_read(apic, 0);
                spin_unlock_irqrestore(&ioapic_lock, flags);
-               if (reg_00.bits.ID != mp_ioapics[apic].mpc_apicid)
+               if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid)
                        printk("could not set ID!\n");
                else
                        apic_printk(APIC_VERBOSE, " ok.\n");
        }
 }
-#else
-static void __init setup_ioapic_ids_from_mpc(void) { }
-#endif
 
 int no_timer_check __initdata;
 
@@ -2015,12 +2020,12 @@ static inline void init_IO_APIC_traps(void)
  * The local APIC irq-chip implementation:
  */
 
-static void ack_apic(unsigned int irq)
+static void ack_lapic_irq(unsigned int irq)
 {
        ack_APIC_irq();
 }
 
-static void mask_lapic_irq (unsigned int irq)
+static void mask_lapic_irq(unsigned int irq)
 {
        unsigned long v;
 
@@ -2028,7 +2033,7 @@ static void mask_lapic_irq (unsigned int irq)
        apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
 }
 
-static void unmask_lapic_irq (unsigned int irq)
+static void unmask_lapic_irq(unsigned int irq)
 {
        unsigned long v;
 
@@ -2037,23 +2042,31 @@ static void unmask_lapic_irq (unsigned int irq)
 }
 
 static struct irq_chip lapic_chip __read_mostly = {
-       .name           = "local-APIC-edge",
+       .name           = "local-APIC",
        .mask           = mask_lapic_irq,
        .unmask         = unmask_lapic_irq,
-       .eoi            = ack_apic,
+       .ack            = ack_lapic_irq,
 };
 
+static void lapic_register_intr(int irq, int vector)
+{
+       irq_desc[irq].status &= ~IRQ_LEVEL;
+       set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
+                                     "edge");
+       set_intr_gate(vector, interrupt[irq]);
+}
+
 static void __init setup_nmi(void)
 {
        /*
-        * Dirty trick to enable the NMI watchdog ...
+        * Dirty trick to enable the NMI watchdog ...
         * We put the 8259A master into AEOI mode and
         * unmask on all local APICs LVT0 as NMI.
         *
         * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
         * is from Maciej W. Rozycki - so we do not have to EOI from
         * the NMI handler or the timer interrupt.
-        */ 
+        */
        apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
 
        enable_NMI_through_LVT0();
@@ -2129,11 +2142,16 @@ static inline void __init unlock_ExtINT_logic(void)
 static inline void __init check_timer(void)
 {
        int apic1, pin1, apic2, pin2;
+       int no_pin1 = 0;
        int vector;
+       unsigned int ver;
        unsigned long flags;
 
        local_irq_save(flags);
 
+       ver = apic_read(APIC_LVR);
+       ver = GET_APIC_VERSION(ver);
+
        /*
         * get/set the timer IRQ vector:
         */
@@ -2142,17 +2160,17 @@ static inline void __init check_timer(void)
        set_intr_gate(vector, interrupt[0]);
 
        /*
-        * Subtle, code in do_timer_interrupt() expects an AEOI
-        * mode for the 8259A whenever interrupts are routed
-        * through I/O APICs.  Also IRQ0 has to be enabled in
-        * the 8259A which implies the virtual wire has to be
-        * disabled in the local APIC.
+        * As IRQ0 is to be enabled in the 8259A, the virtual
+        * wire has to be disabled in the local APIC.  Also
+        * timer interrupts need to be acknowledged manually in
+        * the 8259A for the i82489DX when using the NMI
+        * watchdog as that APIC treats NMIs as level-triggered.
+        * The AEOI mode will finish them in the 8259A
+        * automatically.
         */
        apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
        init_8259A(1);
-       timer_ack = 1;
-       if (timer_over_8254 > 0)
-               enable_8259A_irq(0);
+       timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
 
        pin1  = find_isa_irq_pin(0, mp_INT);
        apic1 = find_isa_irq_apic(0, mp_INT);
@@ -2162,14 +2180,33 @@ static inline void __init check_timer(void)
        printk(KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",
                vector, apic1, pin1, apic2, pin2);
 
+       /*
+        * Some BIOS writers are clueless and report the ExtINTA
+        * I/O APIC input from the cascaded 8259A as the timer
+        * interrupt input.  So just in case, if only one pin
+        * was found above, try it both directly and through the
+        * 8259A.
+        */
+       if (pin1 == -1) {
+               pin1 = pin2;
+               apic1 = apic2;
+               no_pin1 = 1;
+       } else if (pin2 == -1) {
+               pin2 = pin1;
+               apic2 = apic1;
+       }
+
        if (pin1 != -1) {
                /*
                 * Ok, does IRQ0 through the IOAPIC work?
                 */
+               if (no_pin1) {
+                       add_pin_to_irq(0, apic1, pin1);
+                       setup_timer_IRQ0_pin(apic1, pin1, vector);
+               }
                unmask_IO_APIC_irq(0);
                if (timer_irq_works()) {
                        if (nmi_watchdog == NMI_IO_APIC) {
-                               disable_8259A_irq(0);
                                setup_nmi();
                                enable_8259A_irq(0);
                        }
@@ -2178,45 +2215,47 @@ static inline void __init check_timer(void)
                        goto out;
                }
                clear_IO_APIC_pin(apic1, pin1);
-               printk(KERN_ERR "..MP-BIOS bug: 8254 timer not connected to "
-                               "IO-APIC\n");
-       }
+               if (!no_pin1)
+                       printk(KERN_ERR "..MP-BIOS bug: "
+                              "8254 timer not connected to IO-APIC\n");
 
-       printk(KERN_INFO "...trying to set up timer (IRQ0) through the 8259A ... ");
-       if (pin2 != -1) {
+               printk(KERN_INFO "...trying to set up timer (IRQ0) "
+                      "through the 8259A ... ");
                printk("\n..... (found pin %d) ...", pin2);
                /*
                 * legacy devices should be connected to IO APIC #0
                 */
-               setup_ExtINT_IRQ0_pin(apic2, pin2, vector);
+               replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
+               setup_timer_IRQ0_pin(apic2, pin2, vector);
+               unmask_IO_APIC_irq(0);
+               enable_8259A_irq(0);
                if (timer_irq_works()) {
                        printk("works.\n");
-                       if (pin1 != -1)
-                               replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
-                       else
-                               add_pin_to_irq(0, apic2, pin2);
+                       timer_through_8259 = 1;
                        if (nmi_watchdog == NMI_IO_APIC) {
+                               disable_8259A_irq(0);
                                setup_nmi();
+                               enable_8259A_irq(0);
                        }
                        goto out;
                }
                /*
                 * Cleanup, just in case ...
                 */
+               disable_8259A_irq(0);
                clear_IO_APIC_pin(apic2, pin2);
+               printk(" failed.\n");
        }
-       printk(" failed.\n");
 
        if (nmi_watchdog == NMI_IO_APIC) {
                printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");
-               nmi_watchdog = 0;
+               nmi_watchdog = NMI_NONE;
        }
+       timer_ack = 0;
 
        printk(KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");
 
-       disable_8259A_irq(0);
-       set_irq_chip_and_handler_name(0, &lapic_chip, handle_fasteoi_irq,
-                                     "fasteoi");
+       lapic_register_intr(0, vector);
        apic_write_around(APIC_LVT0, APIC_DM_FIXED | vector);   /* Fixed mode */
        enable_8259A_irq(0);
 
@@ -2224,12 +2263,12 @@ static inline void __init check_timer(void)
                printk(" works.\n");
                goto out;
        }
+       disable_8259A_irq(0);
        apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
        printk(" failed.\n");
 
        printk(KERN_INFO "...trying to set up timer as ExtINT IRQ...");
 
-       timer_ack = 0;
        init_8259A(0);
        make_8259A_irq(0);
        apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
@@ -2248,11 +2287,21 @@ out:
 }
 
 /*
- *
- * IRQ's that are handled by the PIC in the MPS IOAPIC case.
- * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ.
- *   Linux doesn't really care, as it's not actually used
- *   for any interrupt handling anyway.
+ * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
+ * to devices.  However there may be an I/O APIC pin available for
+ * this interrupt regardless.  The pin may be left unconnected, but
+ * typically it will be reused as an ExtINT cascade interrupt for
+ * the master 8259A.  In the MPS case such a pin will normally be
+ * reported as an ExtINT interrupt in the MP table.  With ACPI
+ * there is no provision for ExtINT interrupts, and in the absence
+ * of an override it would be treated as an ordinary ISA I/O APIC
+ * interrupt, that is edge-triggered and unmasked by default.  We
+ * used to do this, but it caused problems on some systems because
+ * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
+ * the same ExtINT cascade interrupt to drive the local APIC of the
+ * bootstrap processor.  Therefore we refrain from routing IRQ2 to
+ * the I/O APIC in all cases now.  No actual device should request
+ * it anyway.  --macro
  */
 #define PIC_IRQS       (1 << PIC_CASCADE_IR)
 
@@ -2261,15 +2310,12 @@ void __init setup_IO_APIC(void)
        int i;
 
        /* Reserve all the system vectors. */
-       for (i = FIRST_SYSTEM_VECTOR; i < NR_VECTORS; i++)
+       for (i = first_system_vector; i < NR_VECTORS; i++)
                set_bit(i, used_vectors);
 
        enable_IO_APIC();
 
-       if (acpi_ioapic)
-               io_apic_irqs = ~0;      /* all IRQs go through IOAPIC */
-       else
-               io_apic_irqs = ~PIC_IRQS;
+       io_apic_irqs = ~PIC_IRQS;
 
        printk("ENABLING IO-APIC IRQs\n");
 
@@ -2286,28 +2332,14 @@ void __init setup_IO_APIC(void)
                print_IO_APIC();
 }
 
-static int __init setup_disable_8254_timer(char *s)
-{
-       timer_over_8254 = -1;
-       return 1;
-}
-static int __init setup_enable_8254_timer(char *s)
-{
-       timer_over_8254 = 2;
-       return 1;
-}
-
-__setup("disable_8254_timer", setup_disable_8254_timer);
-__setup("enable_8254_timer", setup_enable_8254_timer);
-
 /*
  *     Called after all the initialization is done. If we didnt find any
  *     APIC bugs then we can allow the modify fast path
  */
+
 static int __init io_apic_bug_finalize(void)
 {
-       if(sis_apic_bug == -1)
+       if (sis_apic_bug == -1)
                sis_apic_bug = 0;
        return 0;
 }
@@ -2318,17 +2350,17 @@ struct sysfs_ioapic_data {
        struct sys_device dev;
        struct IO_APIC_route_entry entry[0];
 };
-static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
+static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS];
 
 static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
 {
        struct IO_APIC_route_entry *entry;
        struct sysfs_ioapic_data *data;
        int i;
-       
+
        data = container_of(dev, struct sysfs_ioapic_data, dev);
        entry = data->entry;
-       for (i = 0; i < nr_ioapic_registers[dev->id]; i ++)
+       for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
                entry[i] = ioapic_read_entry(dev->id, i);
 
        return 0;
@@ -2341,18 +2373,18 @@ static int ioapic_resume(struct sys_device *dev)
        unsigned long flags;
        union IO_APIC_reg_00 reg_00;
        int i;
-       
+
        data = container_of(dev, struct sysfs_ioapic_data, dev);
        entry = data->entry;
 
        spin_lock_irqsave(&ioapic_lock, flags);
        reg_00.raw = io_apic_read(dev->id, 0);
-       if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {
-               reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;
+       if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
+               reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
                io_apic_write(dev->id, 0, reg_00.raw);
        }
        spin_unlock_irqrestore(&ioapic_lock, flags);
-       for (i = 0; i < nr_ioapic_registers[dev->id]; i ++)
+       for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
                ioapic_write_entry(dev->id, i, entry[i]);
 
        return 0;
@@ -2366,24 +2398,23 @@ static struct sysdev_class ioapic_sysdev_class = {
 
 static int __init ioapic_init_sysfs(void)
 {
-       struct sys_device * dev;
+       struct sys_device *dev;
        int i, size, error = 0;
 
        error = sysdev_class_register(&ioapic_sysdev_class);
        if (error)
                return error;
 
-       for (i = 0; i < nr_ioapics; i++ ) {
-               size = sizeof(struct sys_device) + nr_ioapic_registers[i] 
+       for (i = 0; i < nr_ioapics; i++) {
+               size = sizeof(struct sys_device) + nr_ioapic_registers[i]
                        * sizeof(struct IO_APIC_route_entry);
-               mp_ioapic_data[i] = kmalloc(size, GFP_KERNEL);
+               mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
                if (!mp_ioapic_data[i]) {
                        printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
                        continue;
                }
-               memset(mp_ioapic_data[i], 0, size);
                dev = &mp_ioapic_data[i]->dev;
-               dev->id = i; 
+               dev->id = i;
                dev->cls = &ioapic_sysdev_class;
                error = sysdev_register(dev);
                if (error) {
@@ -2458,7 +2489,7 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms
                msg->address_lo =
                        MSI_ADDR_BASE_LO |
                        ((INT_DEST_MODE == 0) ?
-                               MSI_ADDR_DEST_MODE_PHYSICAL:
+MSI_ADDR_DEST_MODE_PHYSICAL:
                                MSI_ADDR_DEST_MODE_LOGICAL) |
                        ((INT_DELIVERY_MODE != dest_LowestPrio) ?
                                MSI_ADDR_REDIRECTION_CPU:
@@ -2469,7 +2500,7 @@ static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_ms
                        MSI_DATA_TRIGGER_EDGE |
                        MSI_DATA_LEVEL_ASSERT |
                        ((INT_DELIVERY_MODE != dest_LowestPrio) ?
-                               MSI_DATA_DELIVERY_FIXED:
+MSI_DATA_DELIVERY_FIXED:
                                MSI_DATA_DELIVERY_LOWPRI) |
                        MSI_DATA_VECTOR(vector);
        }
@@ -2640,12 +2671,12 @@ int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
 #endif /* CONFIG_HT_IRQ */
 
 /* --------------------------------------------------------------------------
-                          ACPI-based IOAPIC Configuration
+                       ACPI-based IOAPIC Configuration
    -------------------------------------------------------------------------- */
 
 #ifdef CONFIG_ACPI
 
-int __init io_apic_get_unique_id (int ioapic, int apic_id)
+int __init io_apic_get_unique_id(int ioapic, int apic_id)
 {
        union IO_APIC_reg_00 reg_00;
        static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
@@ -2654,10 +2685,10 @@ int __init io_apic_get_unique_id (int ioapic, int apic_id)
        int i = 0;
 
        /*
-        * The P4 platform supports up to 256 APIC IDs on two separate APIC 
-        * buses (one for LAPICs, one for IOAPICs), where predecessors only 
+        * The P4 platform supports up to 256 APIC IDs on two separate APIC
+        * buses (one for LAPICs, one for IOAPICs), where predecessors only
         * supports up to 16 on one shared APIC bus.
-        * 
+        *
         * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
         *      advantage of new APIC bus architecture.
         */
@@ -2676,7 +2707,7 @@ int __init io_apic_get_unique_id (int ioapic, int apic_id)
        }
 
        /*
-        * Every APIC in a system must have a unique ID or we get lots of nice 
+        * Every APIC in a system must have a unique ID or we get lots of nice
         * 'stuck on smp_invalidate_needed IPI wait' messages.
         */
        if (check_apicid_used(apic_id_map, apic_id)) {
@@ -2693,7 +2724,7 @@ int __init io_apic_get_unique_id (int ioapic, int apic_id)
                        "trying %d\n", ioapic, apic_id, i);
 
                apic_id = i;
-       } 
+       }
 
        tmp = apicid_to_cpu_present(apic_id);
        physids_or(apic_id_map, apic_id_map, tmp);
@@ -2720,7 +2751,7 @@ int __init io_apic_get_unique_id (int ioapic, int apic_id)
 }
 
 
-int __init io_apic_get_version (int ioapic)
+int __init io_apic_get_version(int ioapic)
 {
        union IO_APIC_reg_01    reg_01;
        unsigned long flags;
@@ -2733,7 +2764,7 @@ int __init io_apic_get_version (int ioapic)
 }
 
 
-int __init io_apic_get_redir_entries (int ioapic)
+int __init io_apic_get_redir_entries(int ioapic)
 {
        union IO_APIC_reg_01    reg_01;
        unsigned long flags;
@@ -2746,7 +2777,7 @@ int __init io_apic_get_redir_entries (int ioapic)
 }
 
 
-int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int active_high_low)
+int io_apic_set_pci_routing(int ioapic, int pin, int irq, int edge_level, int active_high_low)
 {
        struct IO_APIC_route_entry entry;
 
@@ -2762,7 +2793,7 @@ int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int a
         * corresponding device driver registers for this IRQ.
         */
 
-       memset(&entry,0,sizeof(entry));
+       memset(&entry, 0, sizeof(entry));
 
        entry.delivery_mode = INT_DELIVERY_MODE;
        entry.dest_mode = INT_DEST_MODE;
@@ -2781,7 +2812,7 @@ int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int a
 
        apic_printk(APIC_DEBUG, KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry "
                "(%d-%d -> 0x%x -> IRQ %d Mode:%i Active:%i)\n", ioapic,
-               mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq,
+               mp_ioapics[ioapic].mp_apicid, pin, entry.vector, irq,
                edge_level, active_high_low);
 
        ioapic_register_intr(irq, entry.vector, edge_level);
@@ -2802,8 +2833,8 @@ int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
                return -1;
 
        for (i = 0; i < mp_irq_entries; i++)
-               if (mp_irqs[i].mpc_irqtype == mp_INT &&
-                   mp_irqs[i].mpc_srcbusirq == bus_irq)
+               if (mp_irqs[i].mp_irqtype == mp_INT &&
+                   mp_irqs[i].mp_srcbusirq == bus_irq)
                        break;
        if (i >= mp_irq_entries)
                return -1;
@@ -2836,3 +2867,34 @@ static int __init parse_noapic(char *arg)
        return 0;
 }
 early_param("noapic", parse_noapic);
+
+void __init ioapic_init_mappings(void)
+{
+       unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
+       int i;
+
+       for (i = 0; i < nr_ioapics; i++) {
+               if (smp_found_config) {
+                       ioapic_phys = mp_ioapics[i].mp_apicaddr;
+                       if (!ioapic_phys) {
+                               printk(KERN_ERR
+                                      "WARNING: bogus zero IO-APIC "
+                                      "address found in MPTABLE, "
+                                      "disabling IO/APIC support!\n");
+                               smp_found_config = 0;
+                               skip_ioapic_setup = 1;
+                               goto fake_ioapic_page;
+                       }
+               } else {
+fake_ioapic_page:
+                       ioapic_phys = (unsigned long)
+                                     alloc_bootmem_pages(PAGE_SIZE);
+                       ioapic_phys = __pa(ioapic_phys);
+               }
+               set_fixmap_nocache(idx, ioapic_phys);
+               printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
+                      __fix_to_virt(idx), ioapic_phys);
+               idx++;
+       }
+}
+
index ef1a8df..b16ef02 100644 (file)
@@ -61,7 +61,7 @@ struct irq_cfg {
 };
 
 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
-struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = {
+static struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = {
        [0]  = { .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR,  },
        [1]  = { .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR,  },
        [2]  = { .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR,  },
@@ -82,6 +82,10 @@ struct irq_cfg irq_cfg[NR_IRQS] __read_mostly = {
 
 static int assign_irq_vector(int irq, cpumask_t mask);
 
+int first_system_vector = 0xfe;
+
+char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE};
+
 #define __apicdebuginit  __init
 
 int sis_apic_bug; /* not actually supported, dummy for compile */
@@ -90,7 +94,7 @@ static int no_timer_check;
 
 static int disable_timer_pin_1 __initdata;
 
-int timer_over_8254 __initdata = 1;
+int timer_through_8259 __initdata;
 
 /* Where if anywhere is the i8259 connect in external int mode */
 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
@@ -104,15 +108,17 @@ DEFINE_SPINLOCK(vector_lock);
 int nr_ioapic_registers[MAX_IO_APICS];
 
 /* I/O APIC entries */
-struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
+struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
 int nr_ioapics;
 
 /* MP IRQ source entries */
-struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
+struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
 
 /* # of MP IRQ source entries */
 int mp_irq_entries;
 
+DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
+
 /*
  * Rough estimation of how many shared IRQs there are, can
  * be changed anytime.
@@ -140,7 +146,7 @@ struct io_apic {
 static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
 {
        return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
-               + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK);
+               + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK);
 }
 
 static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
@@ -183,7 +189,7 @@ static bool io_apic_level_ack_pending(unsigned int irq)
                        break;
                reg = io_apic_read(entry->apic, 0x10 + pin*2);
                /* Is the remote IRR bit set? */
-               if ((reg >> 14) & 1) {
+               if (reg & IO_APIC_REDIR_REMOTE_IRR) {
                        spin_unlock_irqrestore(&ioapic_lock, flags);
                        return true;
                }
@@ -298,7 +304,7 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector)
                        break;
                io_apic_write(apic, 0x11 + pin*2, dest);
                reg = io_apic_read(apic, 0x10 + pin*2);
-               reg &= ~0x000000ff;
+               reg &= ~IO_APIC_REDIR_VECTOR_MASK;
                reg |= vector;
                io_apic_modify(apic, reg);
                if (!entry->next)
@@ -360,16 +366,37 @@ static void add_pin_to_irq(unsigned int irq, int apic, int pin)
        entry->pin = pin;
 }
 
+/*
+ * Reroute an IRQ to a different pin.
+ */
+static void __init replace_pin_at_irq(unsigned int irq,
+                                     int oldapic, int oldpin,
+                                     int newapic, int newpin)
+{
+       struct irq_pin_list *entry = irq_2_pin + irq;
+
+       while (1) {
+               if (entry->apic == oldapic && entry->pin == oldpin) {
+                       entry->apic = newapic;
+                       entry->pin = newpin;
+               }
+               if (!entry->next)
+                       break;
+               entry = irq_2_pin + entry->next;
+       }
+}
+
 
 #define DO_ACTION(name,R,ACTION, FINAL)                                        \
                                                                        \
        static void name##_IO_APIC_irq (unsigned int irq)               \
        __DO_ACTION(R, ACTION, FINAL)
 
-DO_ACTION( __mask,             0, |= 0x00010000, io_apic_sync(entry->apic) )
-                                               /* mask = 1 */
-DO_ACTION( __unmask,           0, &= 0xfffeffff, )
-                                               /* mask = 0 */
+/* mask = 1 */
+DO_ACTION(__mask,      0, |= IO_APIC_REDIR_MASKED, io_apic_sync(entry->apic))
+
+/* mask = 0 */
+DO_ACTION(__unmask,    0, &= ~IO_APIC_REDIR_MASKED, )
 
 static void mask_IO_APIC_irq (unsigned int irq)
 {
@@ -430,20 +457,6 @@ static int __init disable_timer_pin_setup(char *arg)
 }
 __setup("disable_timer_pin_1", disable_timer_pin_setup);
 
-static int __init setup_disable_8254_timer(char *s)
-{
-       timer_over_8254 = -1;
-       return 1;
-}
-static int __init setup_enable_8254_timer(char *s)
-{
-       timer_over_8254 = 2;
-       return 1;
-}
-
-__setup("disable_8254_timer", setup_disable_8254_timer);
-__setup("enable_8254_timer", setup_enable_8254_timer);
-
 
 /*
  * Find the IRQ entry number of a certain pin.
@@ -453,10 +466,10 @@ static int find_irq_entry(int apic, int pin, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++)
-               if (mp_irqs[i].mpc_irqtype == type &&
-                   (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid ||
-                    mp_irqs[i].mpc_dstapic == MP_APIC_ALL) &&
-                   mp_irqs[i].mpc_dstirq == pin)
+               if (mp_irqs[i].mp_irqtype == type &&
+                   (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid ||
+                    mp_irqs[i].mp_dstapic == MP_APIC_ALL) &&
+                   mp_irqs[i].mp_dstirq == pin)
                        return i;
 
        return -1;
@@ -470,13 +483,13 @@ static int __init find_isa_irq_pin(int irq, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                if (test_bit(lbus, mp_bus_not_pci) &&
-                   (mp_irqs[i].mpc_irqtype == type) &&
-                   (mp_irqs[i].mpc_srcbusirq == irq))
+                   (mp_irqs[i].mp_irqtype == type) &&
+                   (mp_irqs[i].mp_srcbusirq == irq))
 
-                       return mp_irqs[i].mpc_dstirq;
+                       return mp_irqs[i].mp_dstirq;
        }
        return -1;
 }
@@ -486,17 +499,17 @@ static int __init find_isa_irq_apic(int irq, int type)
        int i;
 
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                if (test_bit(lbus, mp_bus_not_pci) &&
-                   (mp_irqs[i].mpc_irqtype == type) &&
-                   (mp_irqs[i].mpc_srcbusirq == irq))
+                   (mp_irqs[i].mp_irqtype == type) &&
+                   (mp_irqs[i].mp_srcbusirq == irq))
                        break;
        }
        if (i < mp_irq_entries) {
                int apic;
                for(apic = 0; apic < nr_ioapics; apic++) {
-                       if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic)
+                       if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic)
                                return apic;
                }
        }
@@ -516,28 +529,28 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
 
        apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
                bus, slot, pin);
-       if (mp_bus_id_to_pci_bus[bus] == -1) {
+       if (test_bit(bus, mp_bus_not_pci)) {
                apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
                return -1;
        }
        for (i = 0; i < mp_irq_entries; i++) {
-               int lbus = mp_irqs[i].mpc_srcbus;
+               int lbus = mp_irqs[i].mp_srcbus;
 
                for (apic = 0; apic < nr_ioapics; apic++)
-                       if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic ||
-                           mp_irqs[i].mpc_dstapic == MP_APIC_ALL)
+                       if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic ||
+                           mp_irqs[i].mp_dstapic == MP_APIC_ALL)
                                break;
 
                if (!test_bit(lbus, mp_bus_not_pci) &&
-                   !mp_irqs[i].mpc_irqtype &&
+                   !mp_irqs[i].mp_irqtype &&
                    (bus == lbus) &&
-                   (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) {
-                       int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq);
+                   (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) {
+                       int irq = pin_2_irq(i,apic,mp_irqs[i].mp_dstirq);
 
                        if (!(apic || IO_APIC_IRQ(irq)))
                                continue;
 
-                       if (pin == (mp_irqs[i].mpc_srcbusirq & 3))
+                       if (pin == (mp_irqs[i].mp_srcbusirq & 3))
                                return irq;
                        /*
                         * Use the first all-but-pin matching entry as a
@@ -565,13 +578,13 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
 
 static int MPBIOS_polarity(int idx)
 {
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
        int polarity;
 
        /*
         * Determine IRQ line polarity (high active or low active):
         */
-       switch (mp_irqs[idx].mpc_irqflag & 3)
+       switch (mp_irqs[idx].mp_irqflag & 3)
        {
                case 0: /* conforms, ie. bus-type dependent polarity */
                        if (test_bit(bus, mp_bus_not_pci))
@@ -607,13 +620,13 @@ static int MPBIOS_polarity(int idx)
 
 static int MPBIOS_trigger(int idx)
 {
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
        int trigger;
 
        /*
         * Determine IRQ trigger mode (edge or level sensitive):
         */
-       switch ((mp_irqs[idx].mpc_irqflag>>2) & 3)
+       switch ((mp_irqs[idx].mp_irqflag>>2) & 3)
        {
                case 0: /* conforms, ie. bus-type dependent */
                        if (test_bit(bus, mp_bus_not_pci))
@@ -660,16 +673,16 @@ static inline int irq_trigger(int idx)
 static int pin_2_irq(int idx, int apic, int pin)
 {
        int irq, i;
-       int bus = mp_irqs[idx].mpc_srcbus;
+       int bus = mp_irqs[idx].mp_srcbus;
 
        /*
         * Debugging check, we are in big trouble if this message pops up!
         */
-       if (mp_irqs[idx].mpc_dstirq != pin)
+       if (mp_irqs[idx].mp_dstirq != pin)
                printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
 
        if (test_bit(bus, mp_bus_not_pci)) {
-               irq = mp_irqs[idx].mpc_srcbusirq;
+               irq = mp_irqs[idx].mp_srcbusirq;
        } else {
                /*
                 * PCI IRQs are mapped in order
@@ -730,7 +743,7 @@ static int __assign_irq_vector(int irq, cpumask_t mask)
                offset = current_offset;
 next:
                vector += 8;
-               if (vector >= FIRST_SYSTEM_VECTOR) {
+               if (vector >= first_system_vector) {
                        /* If we run out of vectors on large boxen, must share them. */
                        offset = (offset + 1) % 8;
                        vector = FIRST_DEVICE_VECTOR + offset;
@@ -788,7 +801,7 @@ static void __clear_irq_vector(int irq)
        cpus_clear(cfg->domain);
 }
 
-void __setup_vector_irq(int cpu)
+static void __setup_vector_irq(int cpu)
 {
        /* Initialize vector_irq on a new cpu */
        /* This function must be called with vector_lock held */
@@ -811,6 +824,13 @@ void __setup_vector_irq(int cpu)
        }
 }
 
+void setup_vector_irq(int cpu)
+{
+       spin_lock(&vector_lock);
+       __setup_vector_irq(smp_processor_id());
+       spin_unlock(&vector_lock);
+}
+
 
 static struct irq_chip ioapic_chip;
 
@@ -846,7 +866,7 @@ static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq,
        apic_printk(APIC_VERBOSE,KERN_DEBUG
                    "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
                    "IRQ %d Mode:%i Active:%i)\n",
-                   apic, mp_ioapics[apic].mpc_apicid, pin, cfg->vector,
+                   apic, mp_ioapics[apic].mp_apicid, pin, cfg->vector,
                    irq, trigger, polarity);
 
        /*
@@ -887,10 +907,10 @@ static void __init setup_IO_APIC_irqs(void)
                idx = find_irq_entry(apic,pin,mp_INT);
                if (idx == -1) {
                        if (first_notcon) {
-                               apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mpc_apicid, pin);
+                               apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mp_apicid, pin);
                                first_notcon = 0;
                        } else
-                               apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mpc_apicid, pin);
+                               apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mp_apicid, pin);
                        continue;
                }
                if (!first_notcon) {
@@ -911,26 +931,21 @@ static void __init setup_IO_APIC_irqs(void)
 }
 
 /*
- * Set up the 8259A-master output pin as broadcast to all
- * CPUs.
+ * Set up the timer pin, possibly with the 8259A-master behind.
  */
-static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector)
+static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin,
+                                       int vector)
 {
        struct IO_APIC_route_entry entry;
 
        memset(&entry, 0, sizeof(entry));
 
-       disable_8259A_irq(0);
-
-       /* mask LVT0 */
-       apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
-
        /*
         * We use logical delivery to get the timer IRQ
         * to the first CPU.
         */
        entry.dest_mode = INT_DEST_MODE;
-       entry.mask = 0;                                 /* unmask IRQ now */
+       entry.mask = 1;                                 /* mask IRQ now */
        entry.dest = cpu_mask_to_apicid(TARGET_CPUS);
        entry.delivery_mode = INT_DELIVERY_MODE;
        entry.polarity = 0;
@@ -939,7 +954,7 @@ static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, in
 
        /*
         * The timer IRQ doesn't have to know that behind the
-        * scene we have a 8259A-master in AEOI mode ...
+        * scene we may have a 8259A-master in AEOI mode ...
         */
        set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
 
@@ -947,8 +962,6 @@ static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, in
         * Add it to the IO-APIC irq-routing table:
         */
        ioapic_write_entry(apic, pin, entry);
-
-       enable_8259A_irq(0);
 }
 
 void __apicdebuginit print_IO_APIC(void)
@@ -965,7 +978,7 @@ void __apicdebuginit print_IO_APIC(void)
        printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
        for (i = 0; i < nr_ioapics; i++)
                printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
-                      mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]);
+                      mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]);
 
        /*
         * We are a bit conservative about what we expect.  We have to
@@ -983,7 +996,7 @@ void __apicdebuginit print_IO_APIC(void)
        spin_unlock_irqrestore(&ioapic_lock, flags);
 
        printk("\n");
-       printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid);
+       printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid);
        printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
        printk(KERN_DEBUG ".......    : physical APIC id: %02X\n", reg_00.bits.ID);
 
@@ -1077,6 +1090,7 @@ void __apicdebuginit print_local_APIC(void * dummy)
 
        printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
                smp_processor_id(), hard_smp_processor_id());
+       v = apic_read(APIC_ID);
        printk(KERN_INFO "... APIC ID:      %08x (%01x)\n", v, GET_APIC_ID(read_apic_id()));
        v = apic_read(APIC_LVR);
        printk(KERN_INFO "... APIC VERSION: %08x\n", v);
@@ -1540,7 +1554,7 @@ static inline void init_IO_APIC_traps(void)
        }
 }
 
-static void enable_lapic_irq (unsigned int irq)
+static void unmask_lapic_irq(unsigned int irq)
 {
        unsigned long v;
 
@@ -1548,7 +1562,7 @@ static void enable_lapic_irq (unsigned int irq)
        apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
 }
 
-static void disable_lapic_irq (unsigned int irq)
+static void mask_lapic_irq(unsigned int irq)
 {
        unsigned long v;
 
@@ -1561,19 +1575,20 @@ static void ack_lapic_irq (unsigned int irq)
        ack_APIC_irq();
 }
 
-static void end_lapic_irq (unsigned int i) { /* nothing */ }
-
-static struct hw_interrupt_type lapic_irq_type __read_mostly = {
-       .name = "local-APIC",
-       .typename = "local-APIC-edge",
-       .startup = NULL, /* startup_irq() not used for IRQ0 */
-       .shutdown = NULL, /* shutdown_irq() not used for IRQ0 */
-       .enable = enable_lapic_irq,
-       .disable = disable_lapic_irq,
-       .ack = ack_lapic_irq,
-       .end = end_lapic_irq,
+static struct irq_chip lapic_chip __read_mostly = {
+       .name           = "local-APIC",
+       .mask           = mask_lapic_irq,
+       .unmask         = unmask_lapic_irq,
+       .ack            = ack_lapic_irq,
 };
 
+static void lapic_register_intr(int irq)
+{
+       irq_desc[irq].status &= ~IRQ_LEVEL;
+       set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
+                                     "edge");
+}
+
 static void __init setup_nmi(void)
 {
        /*
@@ -1659,6 +1674,7 @@ static inline void __init check_timer(void)
        struct irq_cfg *cfg = irq_cfg + 0;
        int apic1, pin1, apic2, pin2;
        unsigned long flags;
+       int no_pin1 = 0;
 
        local_irq_save(flags);
 
@@ -1669,16 +1685,11 @@ static inline void __init check_timer(void)
        assign_irq_vector(0, TARGET_CPUS);
 
        /*
-        * Subtle, code in do_timer_interrupt() expects an AEOI
-        * mode for the 8259A whenever interrupts are routed
-        * through I/O APICs.  Also IRQ0 has to be enabled in
-        * the 8259A which implies the virtual wire has to be
-        * disabled in the local APIC.
+        * As IRQ0 is to be enabled in the 8259A, the virtual
+        * wire has to be disabled in the local APIC.
         */
        apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
        init_8259A(1);
-       if (timer_over_8254 > 0)
-               enable_8259A_irq(0);
 
        pin1  = find_isa_irq_pin(0, mp_INT);
        apic1 = find_isa_irq_apic(0, mp_INT);
@@ -1688,15 +1699,33 @@ static inline void __init check_timer(void)
        apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",
                cfg->vector, apic1, pin1, apic2, pin2);
 
+       /*
+        * Some BIOS writers are clueless and report the ExtINTA
+        * I/O APIC input from the cascaded 8259A as the timer
+        * interrupt input.  So just in case, if only one pin
+        * was found above, try it both directly and through the
+        * 8259A.
+        */
+       if (pin1 == -1) {
+               pin1 = pin2;
+               apic1 = apic2;
+               no_pin1 = 1;
+       } else if (pin2 == -1) {
+               pin2 = pin1;
+               apic2 = apic1;
+       }
+
        if (pin1 != -1) {
                /*
                 * Ok, does IRQ0 through the IOAPIC work?
                 */
+               if (no_pin1) {
+                       add_pin_to_irq(0, apic1, pin1);
+                       setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
+               }
                unmask_IO_APIC_irq(0);
                if (!no_timer_check && timer_irq_works()) {
-                       nmi_watchdog_default();
                        if (nmi_watchdog == NMI_IO_APIC) {
-                               disable_8259A_irq(0);
                                setup_nmi();
                                enable_8259A_irq(0);
                        }
@@ -1705,43 +1734,48 @@ static inline void __init check_timer(void)
                        goto out;
                }
                clear_IO_APIC_pin(apic1, pin1);
-               apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not "
-                               "connected to IO-APIC\n");
-       }
+               if (!no_pin1)
+                       apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: "
+                                   "8254 timer not connected to IO-APIC\n");
 
-       apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) "
-                               "through the 8259A ... ");
-       if (pin2 != -1) {
+               apic_printk(APIC_VERBOSE,KERN_INFO
+                       "...trying to set up timer (IRQ0) "
+                       "through the 8259A ... ");
                apic_printk(APIC_VERBOSE,"\n..... (found apic %d pin %d) ...",
                        apic2, pin2);
                /*
                 * legacy devices should be connected to IO APIC #0
                 */
-               setup_ExtINT_IRQ0_pin(apic2, pin2, cfg->vector);
+               replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
+               setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
+               unmask_IO_APIC_irq(0);
+               enable_8259A_irq(0);
                if (timer_irq_works()) {
                        apic_printk(APIC_VERBOSE," works.\n");
-                       nmi_watchdog_default();
+                       timer_through_8259 = 1;
                        if (nmi_watchdog == NMI_IO_APIC) {
+                               disable_8259A_irq(0);
                                setup_nmi();
+                               enable_8259A_irq(0);
                        }
                        goto out;
                }
                /*
                 * Cleanup, just in case ...
                 */
+               disable_8259A_irq(0);
                clear_IO_APIC_pin(apic2, pin2);
+               apic_printk(APIC_VERBOSE," failed.\n");
        }
-       apic_printk(APIC_VERBOSE," failed.\n");
 
        if (nmi_watchdog == NMI_IO_APIC) {
                printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");
-               nmi_watchdog = 0;
+               nmi_watchdog = NMI_NONE;
        }
 
        apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");
 
-       disable_8259A_irq(0);
-       irq_desc[0].chip = &lapic_irq_type;
+       lapic_register_intr(0);
        apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector);     /* Fixed mode */
        enable_8259A_irq(0);
 
@@ -1749,6 +1783,7 @@ static inline void __init check_timer(void)
                apic_printk(APIC_VERBOSE," works.\n");
                goto out;
        }
+       disable_8259A_irq(0);
        apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
        apic_printk(APIC_VERBOSE," failed.\n");
 
@@ -1778,11 +1813,21 @@ static int __init notimercheck(char *s)
 __setup("no_timer_check", notimercheck);
 
 /*
- *
- * IRQs that are handled by the PIC in the MPS IOAPIC case.
- * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ.
- *   Linux doesn't really care, as it's not actually used
- *   for any interrupt handling anyway.
+ * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
+ * to devices.  However there may be an I/O APIC pin available for
+ * this interrupt regardless.  The pin may be left unconnected, but
+ * typically it will be reused as an ExtINT cascade interrupt for
+ * the master 8259A.  In the MPS case such a pin will normally be
+ * reported as an ExtINT interrupt in the MP table.  With ACPI
+ * there is no provision for ExtINT interrupts, and in the absence
+ * of an override it would be treated as an ordinary ISA I/O APIC
+ * interrupt, that is edge-triggered and unmasked by default.  We
+ * used to do this, but it caused problems on some systems because
+ * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
+ * the same ExtINT cascade interrupt to drive the local APIC of the
+ * bootstrap processor.  Therefore we refrain from routing IRQ2 to
+ * the I/O APIC in all cases now.  No actual device should request
+ * it anyway.  --macro
  */
 #define PIC_IRQS       (1<<2)
 
@@ -1793,10 +1838,7 @@ void __init setup_IO_APIC(void)
         * calling enable_IO_APIC() is moved to setup_local_APIC for BP
         */
 
-       if (acpi_ioapic)
-               io_apic_irqs = ~0;      /* all IRQs go through IOAPIC */
-       else
-               io_apic_irqs = ~PIC_IRQS;
+       io_apic_irqs = ~PIC_IRQS;
 
        apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
 
@@ -1841,8 +1883,8 @@ static int ioapic_resume(struct sys_device *dev)
 
        spin_lock_irqsave(&ioapic_lock, flags);
        reg_00.raw = io_apic_read(dev->id, 0);
-       if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {
-               reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;
+       if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
+               reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
                io_apic_write(dev->id, 0, reg_00.raw);
        }
        spin_unlock_irqrestore(&ioapic_lock, flags);
@@ -2242,8 +2284,8 @@ int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
                return -1;
 
        for (i = 0; i < mp_irq_entries; i++)
-               if (mp_irqs[i].mpc_irqtype == mp_INT &&
-                   mp_irqs[i].mpc_srcbusirq == bus_irq)
+               if (mp_irqs[i].mp_irqtype == mp_INT &&
+                   mp_irqs[i].mp_srcbusirq == bus_irq)
                        break;
        if (i >= mp_irq_entries)
                return -1;
@@ -2336,7 +2378,7 @@ void __init ioapic_init_mappings(void)
        ioapic_res = ioapic_setup_resources();
        for (i = 0; i < nr_ioapics; i++) {
                if (smp_found_config) {
-                       ioapic_phys = mp_ioapics[i].mpc_apicaddr;
+                       ioapic_phys = mp_ioapics[i].mp_apicaddr;
                } else {
                        ioapic_phys = (unsigned long)
                                alloc_bootmem_pages(PAGE_SIZE);
index c0df7b8..9d98cda 100644 (file)
@@ -8,7 +8,6 @@
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
 #include <linux/cache.h>
-#include <linux/interrupt.h>
 #include <linux/cpu.h>
 #include <linux/module.h>
 
index 147352d..47a6f6f 100644 (file)
@@ -48,6 +48,29 @@ void ack_bad_irq(unsigned int irq)
 #endif
 }
 
+#ifdef CONFIG_DEBUG_STACKOVERFLOW
+/* Debugging check for stack overflow: is there less than 1KB free? */
+static int check_stack_overflow(void)
+{
+       long sp;
+
+       __asm__ __volatile__("andl %%esp,%0" :
+                            "=r" (sp) : "0" (THREAD_SIZE - 1));
+
+       return sp < (sizeof(struct thread_info) + STACK_WARN);
+}
+
+static void print_stack_overflow(void)
+{
+       printk(KERN_WARNING "low stack detected by irq handler\n");
+       dump_stack();
+}
+
+#else
+static inline int check_stack_overflow(void) { return 0; }
+static inline void print_stack_overflow(void) { }
+#endif
+
 #ifdef CONFIG_4KSTACKS
 /*
  * per-CPU IRQ handling contexts (thread information and stack)
@@ -59,48 +82,29 @@ union irq_ctx {
 
 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
-#endif
 
-/*
- * do_IRQ handles all normal device IRQ's (the special
- * SMP cross-CPU interrupts have their own specific
- * handlers).
- */
-unsigned int do_IRQ(struct pt_regs *regs)
-{      
-       struct pt_regs *old_regs;
-       /* high bit used in ret_from_ code */
-       int irq = ~regs->orig_ax;
-       struct irq_desc *desc = irq_desc + irq;
-#ifdef CONFIG_4KSTACKS
-       union irq_ctx *curctx, *irqctx;
-       u32 *isp;
-#endif
+static char softirq_stack[NR_CPUS * THREAD_SIZE]
+               __attribute__((__section__(".bss.page_aligned")));
 
-       if (unlikely((unsigned)irq >= NR_IRQS)) {
-               printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
-                                       __func__, irq);
-               BUG();
-       }
+static char hardirq_stack[NR_CPUS * THREAD_SIZE]
+               __attribute__((__section__(".bss.page_aligned")));
 
-       old_regs = set_irq_regs(regs);
-       irq_enter();
-#ifdef CONFIG_DEBUG_STACKOVERFLOW
-       /* Debugging check for stack overflow: is there less than 1KB free? */
-       {
-               long sp;
-
-               __asm__ __volatile__("andl %%esp,%0" :
-                                       "=r" (sp) : "0" (THREAD_SIZE - 1));
-               if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
-                       printk("do_IRQ: stack overflow: %ld\n",
-                               sp - sizeof(struct thread_info));
-                       dump_stack();
-               }
-       }
-#endif
+static void call_on_stack(void *func, void *stack)
+{
+       asm volatile("xchgl     %%ebx,%%esp     \n"
+                    "call      *%%edi          \n"
+                    "movl      %%ebx,%%esp     \n"
+                    : "=b" (stack)
+                    : "0" (stack),
+                      "D"(func)
+                    : "memory", "cc", "edx", "ecx", "eax");
+}
 
-#ifdef CONFIG_4KSTACKS
+static inline int
+execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
+{
+       union irq_ctx *curctx, *irqctx;
+       u32 *isp, arg1, arg2;
 
        curctx = (union irq_ctx *) current_thread_info();
        irqctx = hardirq_ctx[smp_processor_id()];
@@ -111,52 +115,39 @@ unsigned int do_IRQ(struct pt_regs *regs)
         * handler) we can't do that and just have to keep using the
         * current stack (which is the irq stack already after all)
         */
-       if (curctx != irqctx) {
-               int arg1, arg2, bx;
-
-               /* build the stack frame on the IRQ stack */
-               isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
-               irqctx->tinfo.task = curctx->tinfo.task;
-               irqctx->tinfo.previous_esp = current_stack_pointer;
+       if (unlikely(curctx == irqctx))
+               return 0;
 
-               /*
-                * Copy the softirq bits in preempt_count so that the
-                * softirq checks work in the hardirq context.
-                */
-               irqctx->tinfo.preempt_count =
-                       (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
-                       (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
-
-               asm volatile(
-                       "       xchgl  %%ebx,%%esp    \n"
-                       "       call   *%%edi         \n"
-                       "       movl   %%ebx,%%esp    \n"
-                       : "=a" (arg1), "=d" (arg2), "=b" (bx)
-                       :  "0" (irq),   "1" (desc),  "2" (isp),
-                          "D" (desc->handle_irq)
-                       : "memory", "cc", "ecx"
-               );
-       } else
-#endif
-               desc->handle_irq(irq, desc);
+       /* build the stack frame on the IRQ stack */
+       isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
+       irqctx->tinfo.task = curctx->tinfo.task;
+       irqctx->tinfo.previous_esp = current_stack_pointer;
 
-       irq_exit();
-       set_irq_regs(old_regs);
+       /*
+        * Copy the softirq bits in preempt_count so that the
+        * softirq checks work in the hardirq context.
+        */
+       irqctx->tinfo.preempt_count =
+               (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
+               (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
+
+       if (unlikely(overflow))
+               call_on_stack(print_stack_overflow, isp);
+
+       asm volatile("xchgl     %%ebx,%%esp     \n"
+                    "call      *%%edi          \n"
+                    "movl      %%ebx,%%esp     \n"
+                    : "=a" (arg1), "=d" (arg2), "=b" (isp)
+                    :  "0" (irq),   "1" (desc),  "2" (isp),
+                       "D" (desc->handle_irq)
+                    : "memory", "cc", "ecx");
        return 1;
 }
 
-#ifdef CONFIG_4KSTACKS
-
-static char softirq_stack[NR_CPUS * THREAD_SIZE]
-               __attribute__((__section__(".bss.page_aligned")));
-
-static char hardirq_stack[NR_CPUS * THREAD_SIZE]
-               __attribute__((__section__(".bss.page_aligned")));
-
 /*
  * allocate per-cpu stacks for hardirq and for softirq processing
  */
-void irq_ctx_init(int cpu)
+void __cpuinit irq_ctx_init(int cpu)
 {
        union irq_ctx *irqctx;
 
@@ -164,25 +155,25 @@ void irq_ctx_init(int cpu)
                return;
 
        irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
-       irqctx->tinfo.task              = NULL;
-       irqctx->tinfo.exec_domain       = NULL;
-       irqctx->tinfo.cpu               = cpu;
-       irqctx->tinfo.preempt_count     = HARDIRQ_OFFSET;
-       irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
+       irqctx->tinfo.task              = NULL;
+       irqctx->tinfo.exec_domain       = NULL;
+       irqctx->tinfo.cpu               = cpu;
+       irqctx->tinfo.preempt_count     = HARDIRQ_OFFSET;
+       irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
 
        hardirq_ctx[cpu] = irqctx;
 
        irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
-       irqctx->tinfo.task              = NULL;
-       irqctx->tinfo.exec_domain       = NULL;
-       irqctx->tinfo.cpu               = cpu;
-       irqctx->tinfo.preempt_count     = 0;
-       irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
+       irqctx->tinfo.task              = NULL;
+       irqctx->tinfo.exec_domain       = NULL;
+       irqctx->tinfo.cpu               = cpu;
+       irqctx->tinfo.preempt_count     = 0;
+       irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
 
        softirq_ctx[cpu] = irqctx;
 
-       printk("CPU %u irqstacks, hard=%p soft=%p\n",
-               cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
+       printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
+              cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
 }
 
 void irq_ctx_exit(int cpu)
@@ -211,24 +202,55 @@ asmlinkage void do_softirq(void)
                /* build the stack frame on the softirq stack */
                isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
 
-               asm volatile(
-                       "       xchgl   %%ebx,%%esp     \n"
-                       "       call    __do_softirq    \n"
-                       "       movl    %%ebx,%%esp     \n"
-                       : "=b"(isp)
-                       : "0"(isp)
-                       : "memory", "cc", "edx", "ecx", "eax"
-               );
+               call_on_stack(__do_softirq, isp);
                /*
                 * Shouldnt happen, we returned above if in_interrupt():
-                */
+                */
                WARN_ON_ONCE(softirq_count());
        }
 
        local_irq_restore(flags);
 }
+
+#else
+static inline int
+execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq) { return 0; }
 #endif
 
+/*
+ * do_IRQ handles all normal device IRQ's (the special
+ * SMP cross-CPU interrupts have their own specific
+ * handlers).
+ */
+unsigned int do_IRQ(struct pt_regs *regs)
+{
+       struct pt_regs *old_regs;
+       /* high bit used in ret_from_ code */
+       int overflow, irq = ~regs->orig_ax;
+       struct irq_desc *desc = irq_desc + irq;
+
+       if (unlikely((unsigned)irq >= NR_IRQS)) {
+               printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
+                                       __func__, irq);
+               BUG();
+       }
+
+       old_regs = set_irq_regs(regs);
+       irq_enter();
+
+       overflow = check_stack_overflow();
+
+       if (!execute_on_irq_stack(overflow, desc, irq)) {
+               if (unlikely(overflow))
+                       print_stack_overflow();
+               desc->handle_irq(irq, desc);
+       }
+
+       irq_exit();
+       set_irq_regs(old_regs);
+       return 1;
+}
+
 /*
  * Interrupt statistics:
  */
@@ -313,16 +335,20 @@ skip:
                                per_cpu(irq_stat,j).irq_tlb_count);
                seq_printf(p, "  TLB shootdowns\n");
 #endif
+#ifdef CONFIG_X86_MCE
                seq_printf(p, "TRM: ");
                for_each_online_cpu(j)
                        seq_printf(p, "%10u ",
                                per_cpu(irq_stat,j).irq_thermal_count);
                seq_printf(p, "  Thermal event interrupts\n");
+#endif
+#ifdef CONFIG_X86_LOCAL_APIC
                seq_printf(p, "SPU: ");
                for_each_online_cpu(j)
                        seq_printf(p, "%10u ",
                                per_cpu(irq_stat,j).irq_spurious_count);
                seq_printf(p, "  Spurious interrupts\n");
+#endif
                seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
 #if defined(CONFIG_X86_IO_APIC)
                seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
@@ -331,6 +357,40 @@ skip:
        return 0;
 }
 
+/*
+ * /proc/stat helpers
+ */
+u64 arch_irq_stat_cpu(unsigned int cpu)
+{
+       u64 sum = nmi_count(cpu);
+
+#ifdef CONFIG_X86_LOCAL_APIC
+       sum += per_cpu(irq_stat, cpu).apic_timer_irqs;
+#endif
+#ifdef CONFIG_SMP
+       sum += per_cpu(irq_stat, cpu).irq_resched_count;
+       sum += per_cpu(irq_stat, cpu).irq_call_count;
+       sum += per_cpu(irq_stat, cpu).irq_tlb_count;
+#endif
+#ifdef CONFIG_X86_MCE
+       sum += per_cpu(irq_stat, cpu).irq_thermal_count;
+#endif
+#ifdef CONFIG_X86_LOCAL_APIC
+       sum += per_cpu(irq_stat, cpu).irq_spurious_count;
+#endif
+       return sum;
+}
+
+u64 arch_irq_stat(void)
+{
+       u64 sum = atomic_read(&irq_err_count);
+
+#ifdef CONFIG_X86_IO_APIC
+       sum += atomic_read(&irq_mis_count);
+#endif
+       return sum;
+}
+
 #ifdef CONFIG_HOTPLUG_CPU
 #include <mach_apic.h>
 
index 3aac154..1f78b23 100644 (file)
@@ -135,6 +135,7 @@ skip:
                        seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
                seq_printf(p, "  TLB shootdowns\n");
 #endif
+#ifdef CONFIG_X86_MCE
                seq_printf(p, "TRM: ");
                for_each_online_cpu(j)
                        seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
@@ -143,6 +144,7 @@ skip:
                for_each_online_cpu(j)
                        seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
                seq_printf(p, "  Threshold APIC interrupts\n");
+#endif
                seq_printf(p, "SPU: ");
                for_each_online_cpu(j)
                        seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
@@ -152,6 +154,32 @@ skip:
        return 0;
 }
 
+/*
+ * /proc/stat helpers
+ */
+u64 arch_irq_stat_cpu(unsigned int cpu)
+{
+       u64 sum = cpu_pda(cpu)->__nmi_count;
+
+       sum += cpu_pda(cpu)->apic_timer_irqs;
+#ifdef CONFIG_SMP
+       sum += cpu_pda(cpu)->irq_resched_count;
+       sum += cpu_pda(cpu)->irq_call_count;
+       sum += cpu_pda(cpu)->irq_tlb_count;
+#endif
+#ifdef CONFIG_X86_MCE
+       sum += cpu_pda(cpu)->irq_thermal_count;
+       sum += cpu_pda(cpu)->irq_threshold_count;
+#endif
+       sum += cpu_pda(cpu)->irq_spurious_count;
+       return sum;
+}
+
+u64 arch_irq_stat(void)
+{
+       return atomic_read(&irq_err_count);
+}
+
 /*
  * do_IRQ handles all normal device IRQ's (the special
  * SMP cross-CPU interrupts have their own specific
diff --git a/arch/x86/kernel/irqinit_32.c b/arch/x86/kernel/irqinit_32.c
new file mode 100644 (file)
index 0000000..d669142
--- /dev/null
@@ -0,0 +1,114 @@
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/init.h>
+#include <linux/kernel_stat.h>
+#include <linux/sysdev.h>
+#include <linux/bitops.h>
+
+#include <asm/atomic.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/timer.h>
+#include <asm/pgtable.h>
+#include <asm/delay.h>
+#include <asm/desc.h>
+#include <asm/apic.h>
+#include <asm/arch_hooks.h>
+#include <asm/i8259.h>
+
+
+
+/*
+ * Note that on a 486, we don't want to do a SIGFPE on an irq13
+ * as the irq is unreliable, and exception 16 works correctly
+ * (ie as explained in the intel literature). On a 386, you
+ * can't use exception 16 due to bad IBM design, so we have to
+ * rely on the less exact irq13.
+ *
+ * Careful.. Not only is IRQ13 unreliable, but it is also
+ * leads to races. IBM designers who came up with it should
+ * be shot.
+ */
+
+static irqreturn_t math_error_irq(int cpl, void *dev_id)
+{
+       extern void math_error(void __user *);
+       outb(0,0xF0);
+       if (ignore_fpu_irq || !boot_cpu_data.hard_math)
+               return IRQ_NONE;
+       math_error((void __user *)get_irq_regs()->ip);
+       return IRQ_HANDLED;
+}
+
+/*
+ * New motherboards sometimes make IRQ 13 be a PCI interrupt,
+ * so allow interrupt sharing.
+ */
+static struct irqaction fpu_irq = {
+       .handler = math_error_irq,
+       .mask = CPU_MASK_NONE,
+       .name = "fpu",
+};
+
+void __init init_ISA_irqs (void)
+{
+       int i;
+
+#ifdef CONFIG_X86_LOCAL_APIC
+       init_bsp_APIC();
+#endif
+       init_8259A(0);
+
+       /*
+        * 16 old-style INTA-cycle interrupts:
+        */
+       for (i = 0; i < 16; i++) {
+               set_irq_chip_and_handler_name(i, &i8259A_chip,
+                                             handle_level_irq, "XT");
+       }
+}
+
+/* Overridden in paravirt.c */
+void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
+
+void __init native_init_IRQ(void)
+{
+       int i;
+
+       /* all the set up before the call gates are initialised */
+       pre_intr_init_hook();
+
+       /*
+        * Cover the whole vector space, no vector can escape
+        * us. (some of these will be overridden and become
+        * 'special' SMP interrupts)
+        */
+       for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) {
+               int vector = FIRST_EXTERNAL_VECTOR + i;
+               if (i >= NR_IRQS)
+                       break;
+               /* SYSCALL_VECTOR was reserved in trap_init. */
+               if (!test_bit(vector, used_vectors))
+                       set_intr_gate(vector, interrupt[i]);
+       }
+
+       /* setup after call gates are initialised (usually add in
+        * the architecture specific gates)
+        */
+       intr_init_hook();
+
+       /*
+        * External FPU? Set up irq13 if so, for
+        * original braindamaged IBM FERR coupling.
+        */
+       if (boot_cpu_data.hard_math && !cpu_has_fpu)
+               setup_irq(FPU_IRQ, &fpu_irq);
+
+       irq_ctx_init(smp_processor_id());
+}
diff --git a/arch/x86/kernel/irqinit_64.c b/arch/x86/kernel/irqinit_64.c
new file mode 100644 (file)
index 0000000..31f49e8
--- /dev/null
@@ -0,0 +1,217 @@
+#include <linux/linkage.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/timex.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/init.h>
+#include <linux/kernel_stat.h>
+#include <linux/sysdev.h>
+#include <linux/bitops.h>
+
+#include <asm/acpi.h>
+#include <asm/atomic.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/hw_irq.h>
+#include <asm/pgtable.h>
+#include <asm/delay.h>
+#include <asm/desc.h>
+#include <asm/apic.h>
+#include <asm/i8259.h>
+
+/*
+ * Common place to define all x86 IRQ vectors
+ *
+ * This builds up the IRQ handler stubs using some ugly macros in irq.h
+ *
+ * These macros create the low-level assembly IRQ routines that save
+ * register context and call do_IRQ(). do_IRQ() then does all the
+ * operations that are needed to keep the AT (or SMP IOAPIC)
+ * interrupt-controller happy.
+ */
+
+#define IRQ_NAME2(nr) nr##_interrupt(void)
+#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
+
+/*
+ *     SMP has a few special interrupts for IPI messages
+ */
+
+#define BUILD_IRQ(nr)                          \
+       asmlinkage void IRQ_NAME(nr);           \
+       asm("\n.p2align\n"                      \
+           "IRQ" #nr "_interrupt:\n\t"         \
+           "push $~(" #nr ") ; "               \
+           "jmp common_interrupt");
+
+#define BI(x,y) \
+       BUILD_IRQ(x##y)
+
+#define BUILD_16_IRQS(x) \
+       BI(x,0) BI(x,1) BI(x,2) BI(x,3) \
+       BI(x,4) BI(x,5) BI(x,6) BI(x,7) \
+       BI(x,8) BI(x,9) BI(x,a) BI(x,b) \
+       BI(x,c) BI(x,d) BI(x,e) BI(x,f)
+
+/*
+ * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
+ * (these are usually mapped to vectors 0x30-0x3f)
+ */
+
+/*
+ * The IO-APIC gives us many more interrupt sources. Most of these
+ * are unused but an SMP system is supposed to have enough memory ...
+ * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
+ * across the spectrum, so we really want to be prepared to get all
+ * of these. Plus, more powerful systems might have more than 64
+ * IO-APIC registers.
+ *
+ * (these are usually mapped into the 0x30-0xff vector range)
+ */
+                                     BUILD_16_IRQS(0x2) BUILD_16_IRQS(0x3)
+BUILD_16_IRQS(0x4) BUILD_16_IRQS(0x5) BUILD_16_IRQS(0x6) BUILD_16_IRQS(0x7)
+BUILD_16_IRQS(0x8) BUILD_16_IRQS(0x9) BUILD_16_IRQS(0xa) BUILD_16_IRQS(0xb)
+BUILD_16_IRQS(0xc) BUILD_16_IRQS(0xd) BUILD_16_IRQS(0xe) BUILD_16_IRQS(0xf)
+
+#undef BUILD_16_IRQS
+#undef BI
+
+
+#define IRQ(x,y) \
+       IRQ##x##y##_interrupt
+
+#define IRQLIST_16(x) \
+       IRQ(x,0), IRQ(x,1), IRQ(x,2), IRQ(x,3), \
+       IRQ(x,4), IRQ(x,5), IRQ(x,6), IRQ(x,7), \
+       IRQ(x,8), IRQ(x,9), IRQ(x,a), IRQ(x,b), \
+       IRQ(x,c), IRQ(x,d), IRQ(x,e), IRQ(x,f)
+
+/* for the irq vectors */
+static void (*__initdata interrupt[NR_VECTORS - FIRST_EXTERNAL_VECTOR])(void) = {
+                                         IRQLIST_16(0x2), IRQLIST_16(0x3),
+       IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7),
+       IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb),
+       IRQLIST_16(0xc), IRQLIST_16(0xd), IRQLIST_16(0xe), IRQLIST_16(0xf)
+};
+
+#undef IRQ
+#undef IRQLIST_16
+
+
+
+
+/*
+ * IRQ2 is cascade interrupt to second interrupt controller
+ */
+
+static struct irqaction irq2 = {
+       .handler = no_action,
+       .mask = CPU_MASK_NONE,
+       .name = "cascade",
+};
+DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
+       [0 ... IRQ0_VECTOR - 1] = -1,
+       [IRQ0_VECTOR] = 0,
+       [IRQ1_VECTOR] = 1,
+       [IRQ2_VECTOR] = 2,
+       [IRQ3_VECTOR] = 3,
+       [IRQ4_VECTOR] = 4,
+       [IRQ5_VECTOR] = 5,
+       [IRQ6_VECTOR] = 6,
+       [IRQ7_VECTOR] = 7,
+       [IRQ8_VECTOR] = 8,
+       [IRQ9_VECTOR] = 9,
+       [IRQ10_VECTOR] = 10,
+       [IRQ11_VECTOR] = 11,
+       [IRQ12_VECTOR] = 12,
+       [IRQ13_VECTOR] = 13,
+       [IRQ14_VECTOR] = 14,
+       [IRQ15_VECTOR] = 15,
+       [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1
+};
+
+static void __init init_ISA_irqs (void)
+{
+       int i;
+
+       init_bsp_APIC();
+       init_8259A(0);
+
+       for (i = 0; i < NR_IRQS; i++) {
+               irq_desc[i].status = IRQ_DISABLED;
+               irq_desc[i].action = NULL;
+               irq_desc[i].depth = 1;
+
+               if (i < 16) {
+                       /*
+                        * 16 old-style INTA-cycle interrupts:
+                        */
+                       set_irq_chip_and_handler_name(i, &i8259A_chip,
+                                                     handle_level_irq, "XT");
+               } else {
+                       /*
+                        * 'high' PCI IRQs filled in on demand
+                        */
+                       irq_desc[i].chip = &no_irq_chip;
+               }
+       }
+}
+
+void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
+
+void __init native_init_IRQ(void)
+{
+       int i;
+
+       init_ISA_irqs();
+       /*
+        * Cover the whole vector space, no vector can escape
+        * us. (some of these will be overridden and become
+        * 'special' SMP interrupts)
+        */
+       for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) {
+               int vector = FIRST_EXTERNAL_VECTOR + i;
+               if (vector != IA32_SYSCALL_VECTOR)
+                       set_intr_gate(vector, interrupt[i]);
+       }
+
+#ifdef CONFIG_SMP
+       /*
+        * The reschedule interrupt is a CPU-to-CPU reschedule-helper
+        * IPI, driven by wakeup.
+        */
+       alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
+
+       /* IPIs for invalidation */
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
+       alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
+
+       /* IPI for generic function call */
+       alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
+
+       /* Low priority IPI to cleanup after moving an irq */
+       set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
+#endif
+       alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
+       alloc_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt);
+
+       /* self generated IPI for local APIC timer */
+       alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
+
+       /* IPI vectors for APIC spurious and error interrupts */
+       alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
+       alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
+
+       if (!acpi_ioapic)
+               setup_irq(2, &irq2);
+}
index 0224c36..21f2bae 100644 (file)
@@ -20,9 +20,9 @@
 #include <asm/mmu_context.h>
 
 #ifdef CONFIG_SMP
-static void flush_ldt(void *null)
+static void flush_ldt(void *current_mm)
 {
-       if (current->active_mm)
+       if (current->active_mm == current_mm)
                load_LDT(&current->active_mm->context);
 }
 #endif
@@ -68,7 +68,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
                load_LDT(pc);
                mask = cpumask_of_cpu(smp_processor_id());
                if (!cpus_equal(current->mm->cpu_vm_mask, mask))
-                       smp_call_function(flush_ldt, NULL, 1, 1);
+                       smp_call_function(flush_ldt, current->mm, 1, 1);
                preempt_enable();
 #else
                load_LDT(pc);
index d0b234c..8864230 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/numa.h>
+#include <linux/ftrace.h>
+
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
@@ -39,7 +41,7 @@ static void set_idt(void *newidt, __u16 limit)
        curidt.address = (unsigned long)newidt;
 
        load_idt(&curidt);
-};
+}
 
 
 static void set_gdt(void *newgdt, __u16 limit)
@@ -51,7 +53,7 @@ static void set_gdt(void *newgdt, __u16 limit)
        curgdt.address = (unsigned long)newgdt;
 
        load_gdt(&curgdt);
-};
+}
 
 static void load_segments(void)
 {
@@ -107,6 +109,8 @@ NORET_TYPE void machine_kexec(struct kimage *image)
        unsigned long page_list[PAGES_NR];
        void *control_page;
 
+       tracer_disable();
+
        /* Interrupts aren't acceptable while we reboot */
        local_irq_disable();
 
index 576a03d..9dd9262 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/string.h>
 #include <linux/reboot.h>
 #include <linux/numa.h>
+#include <linux/ftrace.h>
+
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
 #include <asm/mmu_context.h>
@@ -110,7 +112,7 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable)
 {
        pgd_t *level4p;
        level4p = (pgd_t *)__va(start_pgtable);
-       return init_level4_page(image, level4p, 0, end_pfn << PAGE_SHIFT);
+       return init_level4_page(image, level4p, 0, max_pfn << PAGE_SHIFT);
 }
 
 static void set_idt(void *newidt, u16 limit)
@@ -184,6 +186,8 @@ NORET_TYPE void machine_kexec(struct kimage *image)
        unsigned long page_list[PAGES_NR];
        void *control_page;
 
+       tracer_disable();
+
        /* Interrupts aren't acceptable while we reboot */
        local_irq_disable();
 
index 69729e3..f47ba81 100644 (file)
@@ -5,13 +5,14 @@
  *                   2006      Shaohua Li <shaohua.li@intel.com>
  *
  *     This driver allows to upgrade microcode on Intel processors
- *     belonging to IA-32 family - PentiumPro, Pentium II, 
+ *     belonging to IA-32 family - PentiumPro, Pentium II,
  *     Pentium III, Xeon, Pentium 4, etc.
  *
- *     Reference: Section 8.10 of Volume III, Intel Pentium 4 Manual, 
- *     Order Number 245472 or free download from:
- *             
- *     http://developer.intel.com/design/pentium4/manuals/245472.htm
+ *     Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
+ *     Software Developer's Manual
+ *     Order Number 253668 or free download from:
+ *
+ *     http://developer.intel.com/design/pentium4/manuals/253668.htm
  *
  *     For more information, go to http://www.urbanmyth.org/microcode
  *
  *             nature of implementation.
  *     1.11    22 Mar 2002 Tigran Aivazian <tigran@veritas.com>
  *             Fix the panic when writing zero-length microcode chunk.
- *     1.12    29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>, 
+ *     1.12    29 Sep 2003 Nitin Kamble <nitin.a.kamble@intel.com>,
  *             Jun Nakajima <jun.nakajima@intel.com>
  *             Support for the microcode updates in the new format.
  *     1.13    10 Oct 2003 Tigran Aivazian <tigran@veritas.com>
  *             Removed ->read() method and obsoleted MICROCODE_IOCFREE ioctl
- *             because we no longer hold a copy of applied microcode 
+ *             because we no longer hold a copy of applied microcode
  *             in kernel memory.
  *     1.14    25 Jun 2004 Tigran Aivazian <tigran@veritas.com>
  *             Fix sigmatch() macro to handle old CPUs with pf == 0.
@@ -75,6 +76,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/cpumask.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -320,11 +322,11 @@ static void apply_microcode(int cpu)
                return;
 
        /* serialize access to the physical write to MSR 0x79 */
-       spin_lock_irqsave(&microcode_update_lock, flags);          
+       spin_lock_irqsave(&microcode_update_lock, flags);
 
        /* write microcode via MSR 0x79 */
        wrmsr(MSR_IA32_UCODE_WRITE,
-               (unsigned long) uci->mc->bits, 
+               (unsigned long) uci->mc->bits,
                (unsigned long) uci->mc->bits >> 16 >> 16);
        wrmsr(MSR_IA32_UCODE_REV, 0, 0);
 
@@ -341,7 +343,7 @@ static void apply_microcode(int cpu)
                return;
        }
        printk(KERN_INFO "microcode: CPU%d updated from revision "
-              "0x%x to 0x%x, date = %08x \n", 
+              "0x%x to 0x%x, date = %08x \n",
               cpu_num, uci->rev, val[1], uci->mc->hdr.date);
        uci->rev = val[1];
 }
@@ -422,6 +424,7 @@ out:
 
 static int microcode_open (struct inode *unused1, struct file *unused2)
 {
+       cycle_kernel_lock();
        return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
@@ -534,7 +537,7 @@ static int cpu_request_microcode(int cpu)
                c->x86, c->x86_model, c->x86_mask);
        error = request_firmware(&firmware, name, &microcode_pdev->dev);
        if (error) {
-               pr_debug("microcode: ucode data file %s load failed\n", name);
+               pr_debug("microcode: data file %s load failed\n", name);
                return error;
        }
        buf = firmware->data;
@@ -805,6 +808,9 @@ static int __init microcode_init (void)
 {
        int error;
 
+       printk(KERN_INFO
+               "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
+
        error = microcode_dev_init();
        if (error)
                return error;
@@ -825,9 +831,6 @@ static int __init microcode_init (void)
        }
 
        register_hotcpu_notifier(&mc_cpu_notifier);
-
-       printk(KERN_INFO 
-               "IA-32 Microcode Update Driver: v" MICROCODE_VERSION " <tigran@aivazian.fsnet.co.uk>\n");
        return 0;
 }
 
index edc5fbf..fdfdc55 100644 (file)
@@ -12,6 +12,7 @@
 #include <asm/io.h>
 #include <asm/msr.h>
 #include <asm/acpi.h>
+#include <asm/mmconfig.h>
 
 #include "../pci/pci.h"
 
index 404683b..3b25e49 100644 (file)
@@ -25,6 +25,8 @@
 #include <asm/proto.h>
 #include <asm/acpi.h>
 #include <asm/bios_ebda.h>
+#include <asm/e820.h>
+#include <asm/trampoline.h>
 
 #include <mach_apic.h>
 #ifdef CONFIG_X86_32
 #include <mach_mpparse.h>
 #endif
 
-/* Have we found an MP table */
-int smp_found_config;
-
-/*
- * Various Linux-internal data structures created from the
- * MP-table.
- */
-#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
-int mp_bus_id_to_type[MAX_MP_BUSSES];
-#endif
-
-DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
-int mp_bus_id_to_pci_bus[MAX_MP_BUSSES] = {[0 ... MAX_MP_BUSSES - 1] = -1 };
-
-static int mp_current_pci_id;
-
-int pic_mode;
-
-/*
- * Intel MP BIOS table parsing routines:
- */
-
 /*
  * Checksum an MP configuration block.
  */
@@ -69,15 +49,73 @@ static int __init mpf_checksum(unsigned char *mp, int len)
 }
 
 #ifdef CONFIG_X86_NUMAQ
+int found_numaq;
 /*
  * Have to match translation table entries to main table entries by counter
  * hence the mpc_record variable .... can't see a less disgusting way of
  * doing this ....
  */
+struct mpc_config_translation {
+       unsigned char mpc_type;
+       unsigned char trans_len;
+       unsigned char trans_type;
+       unsigned char trans_quad;
+       unsigned char trans_global;
+       unsigned char trans_local;
+       unsigned short trans_reserved;
+};
+
 
 static int mpc_record;
 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
     __cpuinitdata;
+
+static inline int generate_logical_apicid(int quad, int phys_apicid)
+{
+       return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
+}
+
+
+static inline int mpc_apic_id(struct mpc_config_processor *m,
+                       struct mpc_config_translation *translation_record)
+{
+       int quad = translation_record->trans_quad;
+       int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
+
+       printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
+              m->mpc_apicid,
+              (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
+              (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
+              m->mpc_apicver, quad, logical_apicid);
+       return logical_apicid;
+}
+
+int mp_bus_id_to_node[MAX_MP_BUSSES];
+
+int mp_bus_id_to_local[MAX_MP_BUSSES];
+
+static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
+       struct mpc_config_translation *translation)
+{
+       int quad = translation->trans_quad;
+       int local = translation->trans_local;
+
+       mp_bus_id_to_node[m->mpc_busid] = quad;
+       mp_bus_id_to_local[m->mpc_busid] = local;
+       printk(KERN_INFO "Bus #%d is %s (node %d)\n",
+              m->mpc_busid, name, quad);
+}
+
+int quad_local_to_mp_bus_id [NR_CPUS/4][4];
+static void mpc_oem_pci_bus(struct mpc_config_bus *m,
+       struct mpc_config_translation *translation)
+{
+       int quad = translation->trans_quad;
+       int local = translation->trans_local;
+
+       quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
+}
+
 #endif
 
 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
@@ -90,7 +128,10 @@ static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
                return;
        }
 #ifdef CONFIG_X86_NUMAQ
-       apicid = mpc_apic_id(m, translation_table[mpc_record]);
+       if (found_numaq)
+               apicid = mpc_apic_id(m, translation_table[mpc_record]);
+       else
+               apicid = m->mpc_apicid;
 #else
        apicid = m->mpc_apicid;
 #endif
@@ -103,17 +144,18 @@ static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
        generic_processor_info(apicid, m->mpc_apicver);
 }
 
+#ifdef CONFIG_X86_IO_APIC
 static void __init MP_bus_info(struct mpc_config_bus *m)
 {
        char str[7];
-
        memcpy(str, m->mpc_bustype, 6);
        str[6] = 0;
 
 #ifdef CONFIG_X86_NUMAQ
-       mpc_oem_bus_info(m, str, translation_table[mpc_record]);
+       if (found_numaq)
+               mpc_oem_bus_info(m, str, translation_table[mpc_record]);
 #else
-       Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
+       printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
 #endif
 
 #if MAX_MP_BUSSES < 256
@@ -132,11 +174,10 @@ static void __init MP_bus_info(struct mpc_config_bus *m)
 #endif
        } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
 #ifdef CONFIG_X86_NUMAQ
-               mpc_oem_pci_bus(m, translation_table[mpc_record]);
+               if (found_numaq)
+                       mpc_oem_pci_bus(m, translation_table[mpc_record]);
 #endif
                clear_bit(m->mpc_busid, mp_bus_not_pci);
-               mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
-               mp_current_pci_id++;
 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
                mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
        } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
@@ -147,6 +188,7 @@ static void __init MP_bus_info(struct mpc_config_bus *m)
        } else
                printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
 }
+#endif
 
 #ifdef CONFIG_X86_IO_APIC
 
@@ -176,18 +218,89 @@ static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
        if (bad_ioapic(m->mpc_apicaddr))
                return;
 
-       mp_ioapics[nr_ioapics] = *m;
+       mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
+       mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
+       mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
+       mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
+       mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
        nr_ioapics++;
 }
 
-static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
+static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
 {
-       mp_irqs[mp_irq_entries] = *m;
-       Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
+       printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
                " IRQ %02x, APIC ID %x, APIC INT %02x\n",
                m->mpc_irqtype, m->mpc_irqflag & 3,
                (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
                m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
+}
+
+static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
+{
+       printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
+               " IRQ %02x, APIC ID %x, APIC INT %02x\n",
+               mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
+               (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
+               mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
+}
+
+static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
+                                   struct mp_config_intsrc *mp_irq)
+{
+       mp_irq->mp_dstapic = m->mpc_dstapic;
+       mp_irq->mp_type = m->mpc_type;
+       mp_irq->mp_irqtype = m->mpc_irqtype;
+       mp_irq->mp_irqflag = m->mpc_irqflag;
+       mp_irq->mp_srcbus = m->mpc_srcbus;
+       mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
+       mp_irq->mp_dstirq = m->mpc_dstirq;
+}
+
+static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
+                                       struct mpc_config_intsrc *m)
+{
+       m->mpc_dstapic = mp_irq->mp_dstapic;
+       m->mpc_type = mp_irq->mp_type;
+       m->mpc_irqtype = mp_irq->mp_irqtype;
+       m->mpc_irqflag = mp_irq->mp_irqflag;
+       m->mpc_srcbus = mp_irq->mp_srcbus;
+       m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
+       m->mpc_dstirq = mp_irq->mp_dstirq;
+}
+
+static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
+                                       struct mpc_config_intsrc *m)
+{
+       if (mp_irq->mp_dstapic != m->mpc_dstapic)
+               return 1;
+       if (mp_irq->mp_type != m->mpc_type)
+               return 2;
+       if (mp_irq->mp_irqtype != m->mpc_irqtype)
+               return 3;
+       if (mp_irq->mp_irqflag != m->mpc_irqflag)
+               return 4;
+       if (mp_irq->mp_srcbus != m->mpc_srcbus)
+               return 5;
+       if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
+               return 6;
+       if (mp_irq->mp_dstirq != m->mpc_dstirq)
+               return 7;
+
+       return 0;
+}
+
+static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
+{
+       int i;
+
+       print_MP_intsrc_info(m);
+
+       for (i = 0; i < mp_irq_entries; i++) {
+               if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
+                       return;
+       }
+
+       assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
        if (++mp_irq_entries == MAX_IRQ_SOURCES)
                panic("Max # of irq sources exceeded!!\n");
 }
@@ -196,7 +309,7 @@ static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
 
 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
 {
-       Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
+       printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
                " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
                m->mpc_irqtype, m->mpc_irqflag & 3,
                (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
@@ -266,11 +379,14 @@ static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
        }
 }
 
-static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
+void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
                                 char *productid)
 {
        if (strncmp(oem, "IBM NUMA", 8))
-               printk("Warning!  May not be a NUMA-Q system!\n");
+               printk("Warning!  Not a NUMA-Q system!\n");
+       else
+               found_numaq = 1;
+
        if (mpc->mpc_oemptr)
                smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
                                 mpc->mpc_oemsize);
@@ -281,12 +397,9 @@ static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
  * Read/parse the MPC
  */
 
-static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
+static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
+                               char *str)
 {
-       char str[16];
-       char oem[10];
-       int count = sizeof(*mpc);
-       unsigned char *mpt = ((unsigned char *)mpc) + count;
 
        if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
                printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
@@ -309,19 +422,42 @@ static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
        }
        memcpy(oem, mpc->mpc_oem, 8);
        oem[8] = 0;
-       printk(KERN_INFO "MPTABLE: OEM ID: %s ", oem);
+       printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
 
        memcpy(str, mpc->mpc_productid, 12);
        str[12] = 0;
-       printk("Product ID: %s ", str);
 
-#ifdef CONFIG_X86_32
-       mps_oem_check(mpc, oem, str);
-#endif
-       printk(KERN_INFO "MPTABLE: Product ID: %s ", str);
+       printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
 
        printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
 
+       return 1;
+}
+
+static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
+{
+       char str[16];
+       char oem[10];
+
+       int count = sizeof(*mpc);
+       unsigned char *mpt = ((unsigned char *)mpc) + count;
+
+       if (!smp_check_mpc(mpc, oem, str))
+               return 0;
+
+#ifdef CONFIG_X86_32
+       /*
+        * need to make sure summit and es7000's mps_oem_check is safe to be
+        * called early via genericarch 's mps_oem_check
+        */
+       if (early) {
+#ifdef CONFIG_X86_NUMAQ
+               numaq_mps_oem_check(mpc, oem, str);
+#endif
+       } else
+               mps_oem_check(mpc, oem, str);
+#endif
+
        /* save the local APIC address, it might be non-default */
        if (!acpi_lapic)
                mp_lapic_addr = mpc->mpc_lapic;
@@ -352,7 +488,9 @@ static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
                        {
                                struct mpc_config_bus *m =
                                    (struct mpc_config_bus *)mpt;
+#ifdef CONFIG_X86_IO_APIC
                                MP_bus_info(m);
+#endif
                                mpt += sizeof(*m);
                                count += sizeof(*m);
                                break;
@@ -402,6 +540,11 @@ static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
                ++mpc_record;
 #endif
        }
+
+#ifdef CONFIG_X86_GENERICARCH
+       generic_bigsmp_probe();
+#endif
+
        setup_apic_routing();
        if (!num_processors)
                printk(KERN_ERR "MPTABLE: no processors registered!\n");
@@ -427,7 +570,7 @@ static void __init construct_default_ioirq_mptable(int mpc_default_type)
        intsrc.mpc_type = MP_INTSRC;
        intsrc.mpc_irqflag = 0; /* conforming */
        intsrc.mpc_srcbus = 0;
-       intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
+       intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
 
        intsrc.mpc_irqtype = mp_INT;
 
@@ -488,40 +631,11 @@ static void __init construct_default_ioirq_mptable(int mpc_default_type)
        MP_intsrc_info(&intsrc);
 }
 
-#endif
 
-static inline void __init construct_default_ISA_mptable(int mpc_default_type)
+static void construct_ioapic_table(int mpc_default_type)
 {
-       struct mpc_config_processor processor;
-       struct mpc_config_bus bus;
-#ifdef CONFIG_X86_IO_APIC
        struct mpc_config_ioapic ioapic;
-#endif
-       struct mpc_config_lintsrc lintsrc;
-       int linttypes[2] = { mp_ExtINT, mp_NMI };
-       int i;
-
-       /*
-        * local APIC has default address
-        */
-       mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
-
-       /*
-        * 2 CPUs, numbered 0 & 1.
-        */
-       processor.mpc_type = MP_PROCESSOR;
-       /* Either an integrated APIC or a discrete 82489DX. */
-       processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
-       processor.mpc_cpuflag = CPU_ENABLED;
-       processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
-           (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
-       processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
-       processor.mpc_reserved[0] = 0;
-       processor.mpc_reserved[1] = 0;
-       for (i = 0; i < 2; i++) {
-               processor.mpc_apicid = i;
-               MP_processor_info(&processor);
-       }
+       struct mpc_config_bus bus;
 
        bus.mpc_type = MP_BUS;
        bus.mpc_busid = 0;
@@ -550,7 +664,6 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
                MP_bus_info(&bus);
        }
 
-#ifdef CONFIG_X86_IO_APIC
        ioapic.mpc_type = MP_IOAPIC;
        ioapic.mpc_apicid = 2;
        ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
@@ -562,7 +675,42 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
         * We set up most of the low 16 IO-APIC pins according to MPS rules.
         */
        construct_default_ioirq_mptable(mpc_default_type);
+}
+#else
+static inline void construct_ioapic_table(int mpc_default_type) { }
 #endif
+
+static inline void __init construct_default_ISA_mptable(int mpc_default_type)
+{
+       struct mpc_config_processor processor;
+       struct mpc_config_lintsrc lintsrc;
+       int linttypes[2] = { mp_ExtINT, mp_NMI };
+       int i;
+
+       /*
+        * local APIC has default address
+        */
+       mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+
+       /*
+        * 2 CPUs, numbered 0 & 1.
+        */
+       processor.mpc_type = MP_PROCESSOR;
+       /* Either an integrated APIC or a discrete 82489DX. */
+       processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
+       processor.mpc_cpuflag = CPU_ENABLED;
+       processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
+           (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
+       processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
+       processor.mpc_reserved[0] = 0;
+       processor.mpc_reserved[1] = 0;
+       for (i = 0; i < 2; i++) {
+               processor.mpc_apicid = i;
+               MP_processor_info(&processor);
+       }
+
+       construct_ioapic_table(mpc_default_type);
+
        lintsrc.mpc_type = MP_LINTSRC;
        lintsrc.mpc_irqflag = 0;        /* conforming */
        lintsrc.mpc_srcbusid = 0;
@@ -577,13 +725,23 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 
 static struct intel_mp_floating *mpf_found;
 
+/*
+ * Machine specific quirk for finding the SMP config before other setup
+ * activities destroy the table:
+ */
+int (*mach_get_smp_config_quirk)(unsigned int early);
+
 /*
  * Scan the memory blocks for an SMP configuration block.
  */
-static void __init __get_smp_config(unsigned early)
+static void __init __get_smp_config(unsigned int early)
 {
        struct intel_mp_floating *mpf = mpf_found;
 
+       if (mach_get_smp_config_quirk) {
+               if (mach_get_smp_config_quirk(early))
+                       return;
+       }
        if (acpi_lapic && early)
                return;
        /*
@@ -600,7 +758,7 @@ static void __init __get_smp_config(unsigned early)
 
        printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
               mpf->mpf_specification);
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
        if (mpf->mpf_feature2 & (1 << 7)) {
                printk(KERN_INFO "    IMCR and PIC compatibility mode.\n");
                pic_mode = 1;
@@ -632,7 +790,9 @@ static void __init __get_smp_config(unsigned early)
                 * override the defaults.
                 */
                if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
+#ifdef CONFIG_X86_LOCAL_APIC
                        smp_found_config = 0;
+#endif
                        printk(KERN_ERR
                               "BIOS bug, MP table errors detected!...\n");
                        printk(KERN_ERR "... disabling SMP support. "
@@ -689,7 +849,7 @@ static int __init smp_scan_config(unsigned long base, unsigned long length,
        unsigned int *bp = phys_to_virt(base);
        struct intel_mp_floating *mpf;
 
-       Dprintk("Scan SMP from %p for %ld bytes.\n", bp, length);
+       printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
        BUILD_BUG_ON(sizeof(*mpf) != 16);
 
        while (length > 0) {
@@ -699,15 +859,21 @@ static int __init smp_scan_config(unsigned long base, unsigned long length,
                    !mpf_checksum((unsigned char *)bp, 16) &&
                    ((mpf->mpf_specification == 1)
                     || (mpf->mpf_specification == 4))) {
-
+#ifdef CONFIG_X86_LOCAL_APIC
                        smp_found_config = 1;
+#endif
                        mpf_found = mpf;
-#ifdef CONFIG_X86_32
+
                        printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
                               mpf, virt_to_phys(mpf));
-                       reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
+
+                       if (!reserve)
+                               return 1;
+                       reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
                                        BOOTMEM_DEFAULT);
                        if (mpf->mpf_physptr) {
+                               unsigned long size = PAGE_SIZE;
+#ifdef CONFIG_X86_32
                                /*
                                 * We cannot access to MPC table to compute
                                 * table size yet, as only few megabytes from
@@ -717,24 +883,15 @@ static int __init smp_scan_config(unsigned long base, unsigned long length,
                                 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
                                 * in reserve_bootmem.
                                 */
-                               unsigned long size = PAGE_SIZE;
                                unsigned long end = max_low_pfn * PAGE_SIZE;
                                if (mpf->mpf_physptr + size > end)
                                        size = end - mpf->mpf_physptr;
-                               reserve_bootmem(mpf->mpf_physptr, size,
+#endif
+                               reserve_bootmem_generic(mpf->mpf_physptr, size,
                                                BOOTMEM_DEFAULT);
                        }
 
-#else
-                       if (!reserve)
-                               return 1;
-
-                       reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
-                       if (mpf->mpf_physptr)
-                               reserve_bootmem_generic(mpf->mpf_physptr,
-                                                       PAGE_SIZE);
-#endif
-               return 1;
+                       return 1;
                }
                bp += 4;
                length -= 16;
@@ -742,10 +899,16 @@ static int __init smp_scan_config(unsigned long base, unsigned long length,
        return 0;
 }
 
-static void __init __find_smp_config(unsigned reserve)
+int (*mach_find_smp_config_quirk)(unsigned int reserve);
+
+static void __init __find_smp_config(unsigned int reserve)
 {
        unsigned int address;
 
+       if (mach_find_smp_config_quirk) {
+               if (mach_find_smp_config_quirk(reserve))
+                       return;
+       }
        /*
         * FIXME: Linux assumes you have 640K of base ram..
         * this continues the error...
@@ -790,298 +953,294 @@ void __init find_smp_config(void)
        __find_smp_config(1);
 }
 
-/* --------------------------------------------------------------------------
-                            ACPI-based MP Configuration
-   -------------------------------------------------------------------------- */
+#ifdef CONFIG_X86_IO_APIC
+static u8 __initdata irq_used[MAX_IRQ_SOURCES];
 
-/*
- * Keep this outside and initialized to 0, for !CONFIG_ACPI builds:
- */
-int es7000_plat;
+static int  __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
+{
+       int i;
 
-#ifdef CONFIG_ACPI
+       if (m->mpc_irqtype != mp_INT)
+               return 0;
 
-#ifdef CONFIG_X86_IO_APIC
+       if (m->mpc_irqflag != 0x0f)
+               return 0;
 
-#define MP_ISA_BUS             0
+       /* not legacy */
 
-extern struct mp_ioapic_routing mp_ioapic_routing[MAX_IO_APICS];
+       for (i = 0; i < mp_irq_entries; i++) {
+               if (mp_irqs[i].mp_irqtype != mp_INT)
+                       continue;
 
-static int mp_find_ioapic(int gsi)
-{
-       int i = 0;
+               if (mp_irqs[i].mp_irqflag != 0x0f)
+                       continue;
 
-       /* Find the IOAPIC that manages this GSI. */
-       for (i = 0; i < nr_ioapics; i++) {
-               if ((gsi >= mp_ioapic_routing[i].gsi_base)
-                   && (gsi <= mp_ioapic_routing[i].gsi_end))
-                       return i;
+               if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
+                       continue;
+               if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
+                       continue;
+               if (irq_used[i]) {
+                       /* already claimed */
+                       return -2;
+               }
+               irq_used[i] = 1;
+               return i;
        }
 
-       printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
+       /* not found */
        return -1;
 }
 
-static u8 __init uniq_ioapic_id(u8 id)
-{
-#ifdef CONFIG_X86_32
-       if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
-           !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
-               return io_apic_get_unique_id(nr_ioapics, id);
-       else
-               return id;
-#else
-       int i;
-       DECLARE_BITMAP(used, 256);
-       bitmap_zero(used, 256);
-       for (i = 0; i < nr_ioapics; i++) {
-               struct mpc_config_ioapic *ia = &mp_ioapics[i];
-               __set_bit(ia->mpc_apicid, used);
-       }
-       if (!test_bit(id, used))
-               return id;
-       return find_first_zero_bit(used, 256);
+#define SPARE_SLOT_NUM 20
+
+static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
 #endif
-}
 
-void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
+static int  __init replace_intsrc_all(struct mp_config_table *mpc,
+                                       unsigned long mpc_new_phys,
+                                       unsigned long mpc_new_length)
 {
-       int idx = 0;
-
-       if (bad_ioapic(address))
-               return;
+#ifdef CONFIG_X86_IO_APIC
+       int i;
+       int nr_m_spare = 0;
+#endif
 
-       idx = nr_ioapics;
+       int count = sizeof(*mpc);
+       unsigned char *mpt = ((unsigned char *)mpc) + count;
 
-       mp_ioapics[idx].mpc_type = MP_IOAPIC;
-       mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
-       mp_ioapics[idx].mpc_apicaddr = address;
+       printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
+       while (count < mpc->mpc_length) {
+               switch (*mpt) {
+               case MP_PROCESSOR:
+                       {
+                               struct mpc_config_processor *m =
+                                   (struct mpc_config_processor *)mpt;
+                               mpt += sizeof(*m);
+                               count += sizeof(*m);
+                               break;
+                       }
+               case MP_BUS:
+                       {
+                               struct mpc_config_bus *m =
+                                   (struct mpc_config_bus *)mpt;
+                               mpt += sizeof(*m);
+                               count += sizeof(*m);
+                               break;
+                       }
+               case MP_IOAPIC:
+                       {
+                               mpt += sizeof(struct mpc_config_ioapic);
+                               count += sizeof(struct mpc_config_ioapic);
+                               break;
+                       }
+               case MP_INTSRC:
+                       {
+#ifdef CONFIG_X86_IO_APIC
+                               struct mpc_config_intsrc *m =
+                                   (struct mpc_config_intsrc *)mpt;
 
-       set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
-       mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
-#ifdef CONFIG_X86_32
-       mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
-#else
-       mp_ioapics[idx].mpc_apicver = 0;
+                               printk(KERN_INFO "OLD ");
+                               print_MP_intsrc_info(m);
+                               i = get_MP_intsrc_index(m);
+                               if (i > 0) {
+                                       assign_to_mpc_intsrc(&mp_irqs[i], m);
+                                       printk(KERN_INFO "NEW ");
+                                       print_mp_irq_info(&mp_irqs[i]);
+                               } else if (!i) {
+                                       /* legacy, do nothing */
+                               } else if (nr_m_spare < SPARE_SLOT_NUM) {
+                                       /*
+                                        * not found (-1), or duplicated (-2)
+                                        * are invalid entries,
+                                        * we need to use the slot  later
+                                        */
+                                       m_spare[nr_m_spare] = m;
+                                       nr_m_spare++;
+                               }
 #endif
-       /*
-        * Build basic GSI lookup table to facilitate gsi->io_apic lookups
-        * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
-        */
-       mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
-       mp_ioapic_routing[idx].gsi_base = gsi_base;
-       mp_ioapic_routing[idx].gsi_end = gsi_base +
-           io_apic_get_redir_entries(idx);
-
-       printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
-              "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
-              mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
-              mp_ioapic_routing[idx].gsi_base, mp_ioapic_routing[idx].gsi_end);
-
-       nr_ioapics++;
-}
+                               mpt += sizeof(struct mpc_config_intsrc);
+                               count += sizeof(struct mpc_config_intsrc);
+                               break;
+                       }
+               case MP_LINTSRC:
+                       {
+                               struct mpc_config_lintsrc *m =
+                                   (struct mpc_config_lintsrc *)mpt;
+                               mpt += sizeof(*m);
+                               count += sizeof(*m);
+                               break;
+                       }
+               default:
+                       /* wrong mptable */
+                       printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
+                       printk(KERN_ERR "type %x\n", *mpt);
+                       print_hex_dump(KERN_ERR, "  ", DUMP_PREFIX_ADDRESS, 16,
+                                       1, mpc, mpc->mpc_length, 1);
+                       goto out;
+               }
+       }
 
-void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
-{
-       struct mpc_config_intsrc intsrc;
-       int ioapic = -1;
-       int pin = -1;
+#ifdef CONFIG_X86_IO_APIC
+       for (i = 0; i < mp_irq_entries; i++) {
+               if (irq_used[i])
+                       continue;
 
-       /*
-        * Convert 'gsi' to 'ioapic.pin'.
-        */
-       ioapic = mp_find_ioapic(gsi);
-       if (ioapic < 0)
-               return;
-       pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
+               if (mp_irqs[i].mp_irqtype != mp_INT)
+                       continue;
 
-       /*
-        * TBD: This check is for faulty timer entries, where the override
-        *      erroneously sets the trigger to level, resulting in a HUGE
-        *      increase of timer interrupts!
-        */
-       if ((bus_irq == 0) && (trigger == 3))
-               trigger = 1;
+               if (mp_irqs[i].mp_irqflag != 0x0f)
+                       continue;
 
-       intsrc.mpc_type = MP_INTSRC;
-       intsrc.mpc_irqtype = mp_INT;
-       intsrc.mpc_irqflag = (trigger << 2) | polarity;
-       intsrc.mpc_srcbus = MP_ISA_BUS;
-       intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
-       intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;     /* APIC ID */
-       intsrc.mpc_dstirq = pin;        /* INTIN# */
+               if (nr_m_spare > 0) {
+                       printk(KERN_INFO "*NEW* found ");
+                       nr_m_spare--;
+                       assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
+                       m_spare[nr_m_spare] = NULL;
+               } else {
+                       struct mpc_config_intsrc *m =
+                           (struct mpc_config_intsrc *)mpt;
+                       count += sizeof(struct mpc_config_intsrc);
+                       if (!mpc_new_phys) {
+                               printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
+                       } else {
+                               if (count <= mpc_new_length)
+                                       printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
+                               else {
+                                       printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
+                                       goto out;
+                               }
+                       }
+                       assign_to_mpc_intsrc(&mp_irqs[i], m);
+                       mpc->mpc_length = count;
+                       mpt += sizeof(struct mpc_config_intsrc);
+               }
+               print_mp_irq_info(&mp_irqs[i]);
+       }
+#endif
+out:
+       /* update checksum */
+       mpc->mpc_checksum = 0;
+       mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
+                                          mpc->mpc_length);
 
-       MP_intsrc_info(&intsrc);
+       return 0;
 }
 
-void __init mp_config_acpi_legacy_irqs(void)
-{
-       struct mpc_config_intsrc intsrc;
-       int i = 0;
-       int ioapic = -1;
+static int __initdata enable_update_mptable;
 
-#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
-       /*
-        * Fabricate the legacy ISA bus (bus #31).
-        */
-       mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
-#endif
-       set_bit(MP_ISA_BUS, mp_bus_not_pci);
-       Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
+static int __init update_mptable_setup(char *str)
+{
+       enable_update_mptable = 1;
+       return 0;
+}
+early_param("update_mptable", update_mptable_setup);
 
-       /*
-        * Older generations of ES7000 have no legacy identity mappings
-        */
-       if (es7000_plat == 1)
-               return;
+static unsigned long __initdata mpc_new_phys;
+static unsigned long mpc_new_length __initdata = 4096;
 
-       /*
-        * Locate the IOAPIC that manages the ISA IRQs (0-15).
-        */
-       ioapic = mp_find_ioapic(0);
-       if (ioapic < 0)
-               return;
+/* alloc_mptable or alloc_mptable=4k */
+static int __initdata alloc_mptable;
+static int __init parse_alloc_mptable_opt(char *p)
+{
+       enable_update_mptable = 1;
+       alloc_mptable = 1;
+       if (!p)
+               return 0;
+       mpc_new_length = memparse(p, &p);
+       return 0;
+}
+early_param("alloc_mptable", parse_alloc_mptable_opt);
 
-       intsrc.mpc_type = MP_INTSRC;
-       intsrc.mpc_irqflag = 0; /* Conforming */
-       intsrc.mpc_srcbus = MP_ISA_BUS;
-#ifdef CONFIG_X86_IO_APIC
-       intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
+void __init early_reserve_e820_mpc_new(void)
+{
+       if (enable_update_mptable && alloc_mptable) {
+               u64 startt = 0;
+#ifdef CONFIG_X86_TRAMPOLINE
+               startt = TRAMPOLINE_BASE;
 #endif
-       /*
-        * Use the default configuration for the IRQs 0-15.  Unless
-        * overridden by (MADT) interrupt source override entries.
-        */
-       for (i = 0; i < 16; i++) {
-               int idx;
-
-               for (idx = 0; idx < mp_irq_entries; idx++) {
-                       struct mpc_config_intsrc *irq = mp_irqs + idx;
-
-                       /* Do we already have a mapping for this ISA IRQ? */
-                       if (irq->mpc_srcbus == MP_ISA_BUS
-                           && irq->mpc_srcbusirq == i)
-                               break;
-
-                       /* Do we already have a mapping for this IOAPIC pin */
-                       if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
-                           (irq->mpc_dstirq == i))
-                               break;
-               }
-
-               if (idx != mp_irq_entries) {
-                       printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
-                       continue;       /* IRQ already used */
-               }
-
-               intsrc.mpc_irqtype = mp_INT;
-               intsrc.mpc_srcbusirq = i;       /* Identity mapped */
-               intsrc.mpc_dstirq = i;
-
-               MP_intsrc_info(&intsrc);
+               mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
        }
 }
 
-int mp_register_gsi(u32 gsi, int triggering, int polarity)
+static int __init update_mp_table(void)
 {
-       int ioapic;
-       int ioapic_pin;
-#ifdef CONFIG_X86_32
-#define MAX_GSI_NUM    4096
-#define IRQ_COMPRESSION_START  64
+       char str[16];
+       char oem[10];
+       struct intel_mp_floating *mpf;
+       struct mp_config_table *mpc;
+       struct mp_config_table *mpc_new;
+
+       if (!enable_update_mptable)
+               return 0;
+
+       mpf = mpf_found;
+       if (!mpf)
+               return 0;
 
-       static int pci_irq = IRQ_COMPRESSION_START;
        /*
-        * Mapping between Global System Interrupts, which
-        * represent all possible interrupts, and IRQs
-        * assigned to actual devices.
+        * Now see if we need to go further.
         */
-       static int gsi_to_irq[MAX_GSI_NUM];
-#else
-
-       if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
-               return gsi;
-#endif
+       if (mpf->mpf_feature1 != 0)
+               return 0;
 
-       /* Don't set up the ACPI SCI because it's already set up */
-       if (acpi_gbl_FADT.sci_interrupt == gsi)
-               return gsi;
+       if (!mpf->mpf_physptr)
+               return 0;
 
-       ioapic = mp_find_ioapic(gsi);
-       if (ioapic < 0) {
-               printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
-               return gsi;
-       }
+       mpc = phys_to_virt(mpf->mpf_physptr);
 
-       ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_base;
+       if (!smp_check_mpc(mpc, oem, str))
+               return 0;
 
-#ifdef CONFIG_X86_32
-       if (ioapic_renumber_irq)
-               gsi = ioapic_renumber_irq(ioapic, gsi);
-#endif
+       printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
+       printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
 
-       /*
-        * Avoid pin reprogramming.  PRTs typically include entries
-        * with redundant pin->gsi mappings (but unique PCI devices);
-        * we only program the IOAPIC on the first.
-        */
-       if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
-               printk(KERN_ERR "Invalid reference to IOAPIC pin "
-                      "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
-                      ioapic_pin);
-               return gsi;
+       if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
+               mpc_new_phys = 0;
+               printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
+                        mpc_new_length);
        }
-       if (test_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {
-               Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
-                       mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
-#ifdef CONFIG_X86_32
-               return (gsi < IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]);
-#else
-               return gsi;
-#endif
+
+       if (!mpc_new_phys) {
+               unsigned char old, new;
+               /* check if we can change the postion */
+               mpc->mpc_checksum = 0;
+               old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
+               mpc->mpc_checksum = 0xff;
+               new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
+               if (old == new) {
+                       printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
+                       return 0;
+               }
+               printk(KERN_INFO "use in-positon replacing\n");
+       } else {
+               mpf->mpf_physptr = mpc_new_phys;
+               mpc_new = phys_to_virt(mpc_new_phys);
+               memcpy(mpc_new, mpc, mpc->mpc_length);
+               mpc = mpc_new;
+               /* check if we can modify that */
+               if (mpc_new_phys - mpf->mpf_physptr) {
+                       struct intel_mp_floating *mpf_new;
+                       /* steal 16 bytes from [0, 1k) */
+                       printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
+                       mpf_new = phys_to_virt(0x400 - 16);
+                       memcpy(mpf_new, mpf, 16);
+                       mpf = mpf_new;
+                       mpf->mpf_physptr = mpc_new_phys;
+               }
+               mpf->mpf_checksum = 0;
+               mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
+               printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
        }
 
-       set_bit(ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);
-#ifdef CONFIG_X86_32
        /*
-        * For GSI >= 64, use IRQ compression
+        * only replace the one with mp_INT and
+        *       MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
+        * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
+        * may need pci=routeirq for all coverage
         */
-       if ((gsi >= IRQ_COMPRESSION_START)
-           && (triggering == ACPI_LEVEL_SENSITIVE)) {
-               /*
-                * For PCI devices assign IRQs in order, avoiding gaps
-                * due to unused I/O APIC pins.
-                */
-               int irq = gsi;
-               if (gsi < MAX_GSI_NUM) {
-                       /*
-                        * Retain the VIA chipset work-around (gsi > 15), but
-                        * avoid a problem where the 8254 timer (IRQ0) is setup
-                        * via an override (so it's not on pin 0 of the ioapic),
-                        * and at the same time, the pin 0 interrupt is a PCI
-                        * type.  The gsi > 15 test could cause these two pins
-                        * to be shared as IRQ0, and they are not shareable.
-                        * So test for this condition, and if necessary, avoid
-                        * the pin collision.
-                        */
-                       gsi = pci_irq++;
-                       /*
-                        * Don't assign IRQ used by ACPI SCI
-                        */
-                       if (gsi == acpi_gbl_FADT.sci_interrupt)
-                               gsi = pci_irq++;
-                       gsi_to_irq[irq] = gsi;
-               } else {
-                       printk(KERN_ERR "GSI %u is too high\n", gsi);
-                       return gsi;
-               }
-       }
-#endif
-       io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
-                               triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
-                               polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
-       return gsi;
+       replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
+
+       return 0;
 }
 
-#endif /* CONFIG_X86_IO_APIC */
-#endif /* CONFIG_ACPI */
+late_initcall(update_mp_table);
index 1f3abe0..a153b39 100644 (file)
@@ -117,12 +117,20 @@ static int msr_open(struct inode *inode, struct file *file)
 {
        unsigned int cpu = iminor(file->f_path.dentry->d_inode);
        struct cpuinfo_x86 *c = &cpu_data(cpu);
+       int ret = 0;
 
-       if (cpu >= NR_CPUS || !cpu_online(cpu))
-               return -ENXIO;  /* No such CPU */
-       if (!cpu_has(c, X86_FEATURE_MSR))
-               return -EIO;    /* MSR not supported */
+       lock_kernel();
+       cpu = iminor(file->f_path.dentry->d_inode);
 
+       if (cpu >= NR_CPUS || !cpu_online(cpu)) {
+               ret = -ENXIO;   /* No such CPU */
+               goto out;
+       }
+       c = &cpu_data(cpu);
+       if (!cpu_has(c, X86_FEATURE_MSR))
+               ret = -EIO;     /* MSR not supported */
+out:
+       unlock_kernel();
        return 0;
 }
 
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
new file mode 100644 (file)
index 0000000..716b892
--- /dev/null
@@ -0,0 +1,516 @@
+/*
+ *  NMI watchdog support on APIC systems
+ *
+ *  Started by Ingo Molnar <mingo@redhat.com>
+ *
+ *  Fixes:
+ *  Mikael Pettersson  : AMD K7 support for local APIC NMI watchdog.
+ *  Mikael Pettersson  : Power Management for local APIC NMI watchdog.
+ *  Mikael Pettersson  : Pentium 4 support for local APIC NMI watchdog.
+ *  Pavel Machek and
+ *  Mikael Pettersson  : PM converted to driver model. Disable/enable API.
+ */
+
+#include <asm/apic.h>
+
+#include <linux/nmi.h>
+#include <linux/mm.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/sysdev.h>
+#include <linux/sysctl.h>
+#include <linux/percpu.h>
+#include <linux/kprobes.h>
+#include <linux/cpumask.h>
+#include <linux/kernel_stat.h>
+#include <linux/kdebug.h>
+#include <linux/smp.h>
+
+#include <asm/i8259.h>
+#include <asm/io_apic.h>
+#include <asm/smp.h>
+#include <asm/nmi.h>
+#include <asm/proto.h>
+#include <asm/timer.h>
+
+#include <asm/mce.h>
+
+#include <mach_traps.h>
+
+int unknown_nmi_panic;
+int nmi_watchdog_enabled;
+
+static cpumask_t backtrace_mask = CPU_MASK_NONE;
+
+/* nmi_active:
+ * >0: the lapic NMI watchdog is active, but can be disabled
+ * <0: the lapic NMI watchdog has not been set up, and cannot
+ *     be enabled
+ *  0: the lapic NMI watchdog is disabled, but can be enabled
+ */
+atomic_t nmi_active = ATOMIC_INIT(0);          /* oprofile uses this */
+EXPORT_SYMBOL(nmi_active);
+
+unsigned int nmi_watchdog = NMI_NONE;
+EXPORT_SYMBOL(nmi_watchdog);
+
+static int panic_on_timeout;
+
+static unsigned int nmi_hz = HZ;
+static DEFINE_PER_CPU(short, wd_enabled);
+static int endflag __initdata;
+
+static inline unsigned int get_nmi_count(int cpu)
+{
+#ifdef CONFIG_X86_64
+       return cpu_pda(cpu)->__nmi_count;
+#else
+       return nmi_count(cpu);
+#endif
+}
+
+static inline int mce_in_progress(void)
+{
+#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
+       return atomic_read(&mce_entry) > 0;
+#endif
+       return 0;
+}
+
+/*
+ * Take the local apic timer and PIT/HPET into account. We don't
+ * know which one is active, when we have highres/dyntick on
+ */
+static inline unsigned int get_timer_irqs(int cpu)
+{
+#ifdef CONFIG_X86_64
+       return read_pda(apic_timer_irqs) + read_pda(irq0_irqs);
+#else
+       return per_cpu(irq_stat, cpu).apic_timer_irqs +
+               per_cpu(irq_stat, cpu).irq0_irqs;
+#endif
+}
+
+#ifdef CONFIG_SMP
+/*
+ * The performance counters used by NMI_LOCAL_APIC don't trigger when
+ * the CPU is idle. To make sure the NMI watchdog really ticks on all
+ * CPUs during the test make them busy.
+ */
+static __init void nmi_cpu_busy(void *data)
+{
+       local_irq_enable_in_hardirq();
+       /*
+        * Intentionally don't use cpu_relax here. This is
+        * to make sure that the performance counter really ticks,
+        * even if there is a simulator or similar that catches the
+        * pause instruction. On a real HT machine this is fine because
+        * all other CPUs are busy with "useless" delay loops and don't
+        * care if they get somewhat less cycles.
+        */
+       while (endflag == 0)
+               mb();
+}
+#endif
+
+int __init check_nmi_watchdog(void)
+{
+       unsigned int *prev_nmi_count;
+       int cpu;
+
+       if (!nmi_watchdog_active() || !atomic_read(&nmi_active))
+               return 0;
+
+       prev_nmi_count = kmalloc(nr_cpu_ids * sizeof(int), GFP_KERNEL);
+       if (!prev_nmi_count)
+               goto error;
+
+       printk(KERN_INFO "Testing NMI watchdog ... ");
+
+#ifdef CONFIG_SMP
+       if (nmi_watchdog == NMI_LOCAL_APIC)
+               smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
+#endif
+
+       for_each_possible_cpu(cpu)
+               prev_nmi_count[cpu] = get_nmi_count(cpu);
+       local_irq_enable();
+       mdelay((20 * 1000) / nmi_hz); /* wait 20 ticks */
+
+       for_each_online_cpu(cpu) {
+               if (!per_cpu(wd_enabled, cpu))
+                       continue;
+               if (get_nmi_count(cpu) - prev_nmi_count[cpu] <= 5) {
+                       printk(KERN_WARNING "WARNING: CPU#%d: NMI "
+                               "appears to be stuck (%d->%d)!\n",
+                               cpu,
+                               prev_nmi_count[cpu],
+                               get_nmi_count(cpu));
+                       per_cpu(wd_enabled, cpu) = 0;
+                       atomic_dec(&nmi_active);
+               }
+       }
+       endflag = 1;
+       if (!atomic_read(&nmi_active)) {
+               kfree(prev_nmi_count);
+               atomic_set(&nmi_active, -1);
+               goto error;
+       }
+       printk("OK.\n");
+
+       /*
+        * now that we know it works we can reduce NMI frequency to
+        * something more reasonable; makes a difference in some configs
+        */
+       if (nmi_watchdog == NMI_LOCAL_APIC)
+               nmi_hz = lapic_adjust_nmi_hz(1);
+
+       kfree(prev_nmi_count);
+       return 0;
+error:
+       if (nmi_watchdog == NMI_IO_APIC && !timer_through_8259)
+               disable_8259A_irq(0);
+#ifdef CONFIG_X86_32
+       timer_ack = 0;
+#endif
+       return -1;
+}
+
+static int __init setup_nmi_watchdog(char *str)
+{
+       unsigned int nmi;
+
+       if (!strncmp(str, "panic", 5)) {
+               panic_on_timeout = 1;
+               str = strchr(str, ',');
+               if (!str)
+                       return 1;
+               ++str;
+       }
+
+       get_option(&str, &nmi);
+
+       if (nmi >= NMI_INVALID)
+               return 0;
+
+       nmi_watchdog = nmi;
+       return 1;
+}
+__setup("nmi_watchdog=", setup_nmi_watchdog);
+
+/*
+ * Suspend/resume support
+ */
+#ifdef CONFIG_PM
+
+static int nmi_pm_active; /* nmi_active before suspend */
+
+static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
+{
+       /* only CPU0 goes here, other CPUs should be offline */
+       nmi_pm_active = atomic_read(&nmi_active);
+       stop_apic_nmi_watchdog(NULL);
+       BUG_ON(atomic_read(&nmi_active) != 0);
+       return 0;
+}
+
+static int lapic_nmi_resume(struct sys_device *dev)
+{
+       /* only CPU0 goes here, other CPUs should be offline */
+       if (nmi_pm_active > 0) {
+               setup_apic_nmi_watchdog(NULL);
+               touch_nmi_watchdog();
+       }
+       return 0;
+}
+
+static struct sysdev_class nmi_sysclass = {
+       .name           = "lapic_nmi",
+       .resume         = lapic_nmi_resume,
+       .suspend        = lapic_nmi_suspend,
+};
+
+static struct sys_device device_lapic_nmi = {
+       .id     = 0,
+       .cls    = &nmi_sysclass,
+};
+
+static int __init init_lapic_nmi_sysfs(void)
+{
+       int error;
+
+       /*
+        * should really be a BUG_ON but b/c this is an
+        * init call, it just doesn't work.  -dcz
+        */
+       if (nmi_watchdog != NMI_LOCAL_APIC)
+               return 0;
+
+       if (atomic_read(&nmi_active) < 0)
+               return 0;
+
+       error = sysdev_class_register(&nmi_sysclass);
+       if (!error)
+               error = sysdev_register(&device_lapic_nmi);
+       return error;
+}
+
+/* must come after the local APIC's device_initcall() */
+late_initcall(init_lapic_nmi_sysfs);
+
+#endif /* CONFIG_PM */
+
+static void __acpi_nmi_enable(void *__unused)
+{
+       apic_write_around(APIC_LVT0, APIC_DM_NMI);
+}
+
+/*
+ * Enable timer based NMIs on all CPUs:
+ */
+void acpi_nmi_enable(void)
+{
+       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
+               on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
+}
+
+static void __acpi_nmi_disable(void *__unused)
+{
+       apic_write_around(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
+}
+
+/*
+ * Disable timer based NMIs on all CPUs:
+ */
+void acpi_nmi_disable(void)
+{
+       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
+               on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
+}
+
+void setup_apic_nmi_watchdog(void *unused)
+{
+       if (__get_cpu_var(wd_enabled))
+               return;
+
+       /* cheap hack to support suspend/resume */
+       /* if cpu0 is not active neither should the other cpus */
+       if (smp_processor_id() != 0 && atomic_read(&nmi_active) <= 0)
+               return;
+
+       switch (nmi_watchdog) {
+       case NMI_LOCAL_APIC:
+                /* enable it before to avoid race with handler */
+               __get_cpu_var(wd_enabled) = 1;
+               if (lapic_watchdog_init(nmi_hz) < 0) {
+                       __get_cpu_var(wd_enabled) = 0;
+                       return;
+               }
+               /* FALL THROUGH */
+       case NMI_IO_APIC:
+               __get_cpu_var(wd_enabled) = 1;
+               atomic_inc(&nmi_active);
+       }
+}
+
+void stop_apic_nmi_watchdog(void *unused)
+{
+       /* only support LOCAL and IO APICs for now */
+       if (!nmi_watchdog_active())
+               return;
+       if (__get_cpu_var(wd_enabled) == 0)
+               return;
+       if (nmi_watchdog == NMI_LOCAL_APIC)
+               lapic_watchdog_stop();
+       __get_cpu_var(wd_enabled) = 0;
+       atomic_dec(&nmi_active);
+}
+
+/*
+ * the best way to detect whether a CPU has a 'hard lockup' problem
+ * is to check it's local APIC timer IRQ counts. If they are not
+ * changing then that CPU has some problem.
+ *
+ * as these watchdog NMI IRQs are generated on every CPU, we only
+ * have to check the current processor.
+ *
+ * since NMIs don't listen to _any_ locks, we have to be extremely
+ * careful not to rely on unsafe variables. The printk might lock
+ * up though, so we have to break up any console locks first ...
+ * [when there will be more tty-related locks, break them up here too!]
+ */
+
+static DEFINE_PER_CPU(unsigned, last_irq_sum);
+static DEFINE_PER_CPU(local_t, alert_counter);
+static DEFINE_PER_CPU(int, nmi_touch);
+
+void touch_nmi_watchdog(void)
+{
+       if (nmi_watchdog_active()) {
+               unsigned cpu;
+
+               /*
+                * Tell other CPUs to reset their alert counters. We cannot
+                * do it ourselves because the alert count increase is not
+                * atomic.
+                */
+               for_each_present_cpu(cpu) {
+                       if (per_cpu(nmi_touch, cpu) != 1)
+                               per_cpu(nmi_touch, cpu) = 1;
+               }
+       }
+
+       /*
+        * Tickle the softlockup detector too:
+        */
+       touch_softlockup_watchdog();
+}
+EXPORT_SYMBOL(touch_nmi_watchdog);
+
+notrace __kprobes int
+nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
+{
+       /*
+        * Since current_thread_info()-> is always on the stack, and we
+        * always switch the stack NMI-atomically, it's safe to use
+        * smp_processor_id().
+        */
+       unsigned int sum;
+       int touched = 0;
+       int cpu = smp_processor_id();
+       int rc = 0;
+
+       /* check for other users first */
+       if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
+                       == NOTIFY_STOP) {
+               rc = 1;
+               touched = 1;
+       }
+
+       sum = get_timer_irqs(cpu);
+
+       if (__get_cpu_var(nmi_touch)) {
+               __get_cpu_var(nmi_touch) = 0;
+               touched = 1;
+       }
+
+       if (cpu_isset(cpu, backtrace_mask)) {
+               static DEFINE_SPINLOCK(lock);   /* Serialise the printks */
+
+               spin_lock(&lock);
+               printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
+               dump_stack();
+               spin_unlock(&lock);
+               cpu_clear(cpu, backtrace_mask);
+       }
+
+       /* Could check oops_in_progress here too, but it's safer not to */
+       if (mce_in_progress())
+               touched = 1;
+
+       /* if the none of the timers isn't firing, this cpu isn't doing much */
+       if (!touched && __get_cpu_var(last_irq_sum) == sum) {
+               /*
+                * Ayiee, looks like this CPU is stuck ...
+                * wait a few IRQs (5 seconds) before doing the oops ...
+                */
+               local_inc(&__get_cpu_var(alert_counter));
+               if (local_read(&__get_cpu_var(alert_counter)) == 5 * nmi_hz)
+                       /*
+                        * die_nmi will return ONLY if NOTIFY_STOP happens..
+                        */
+                       die_nmi("BUG: NMI Watchdog detected LOCKUP",
+                               regs, panic_on_timeout);
+       } else {
+               __get_cpu_var(last_irq_sum) = sum;
+               local_set(&__get_cpu_var(alert_counter), 0);
+       }
+
+       /* see if the nmi watchdog went off */
+       if (!__get_cpu_var(wd_enabled))
+               return rc;
+       switch (nmi_watchdog) {
+       case NMI_LOCAL_APIC:
+               rc |= lapic_wd_event(nmi_hz);
+               break;
+       case NMI_IO_APIC:
+               /*
+                * don't know how to accurately check for this.
+                * just assume it was a watchdog timer interrupt
+                * This matches the old behaviour.
+                */
+               rc = 1;
+               break;
+       }
+       return rc;
+}
+
+#ifdef CONFIG_SYSCTL
+
+static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
+{
+       unsigned char reason = get_nmi_reason();
+       char buf[64];
+
+       sprintf(buf, "NMI received for unknown reason %02x\n", reason);
+       die_nmi(buf, regs, 1); /* Always panic here */
+       return 0;
+}
+
+/*
+ * proc handler for /proc/sys/kernel/nmi
+ */
+int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
+                       void __user *buffer, size_t *length, loff_t *ppos)
+{
+       int old_state;
+
+       nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
+       old_state = nmi_watchdog_enabled;
+       proc_dointvec(table, write, file, buffer, length, ppos);
+       if (!!old_state == !!nmi_watchdog_enabled)
+               return 0;
+
+       if (atomic_read(&nmi_active) < 0 || !nmi_watchdog_active()) {
+               printk(KERN_WARNING
+                       "NMI watchdog is permanently disabled\n");
+               return -EIO;
+       }
+
+       if (nmi_watchdog == NMI_LOCAL_APIC) {
+               if (nmi_watchdog_enabled)
+                       enable_lapic_nmi_watchdog();
+               else
+                       disable_lapic_nmi_watchdog();
+       } else {
+               printk(KERN_WARNING
+                       "NMI watchdog doesn't know what hardware to touch\n");
+               return -EIO;
+       }
+       return 0;
+}
+
+#endif /* CONFIG_SYSCTL */
+
+int do_nmi_callback(struct pt_regs *regs, int cpu)
+{
+#ifdef CONFIG_SYSCTL
+       if (unknown_nmi_panic)
+               return unknown_nmi_panic_callback(regs, cpu);
+#endif
+       return 0;
+}
+
+void __trigger_all_cpu_backtrace(void)
+{
+       int i;
+
+       backtrace_mask = cpu_online_map;
+       /* Wait for up to 10 seconds for all CPUs to do the backtrace */
+       for (i = 0; i < 10 * 1000; i++) {
+               if (cpus_empty(backtrace_mask))
+                       break;
+               mdelay(1);
+       }
+}
diff --git a/arch/x86/kernel/nmi_32.c b/arch/x86/kernel/nmi_32.c
deleted file mode 100644 (file)
index 84160f7..0000000
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- *  NMI watchdog support on APIC systems
- *
- *  Started by Ingo Molnar <mingo@redhat.com>
- *
- *  Fixes:
- *  Mikael Pettersson  : AMD K7 support for local APIC NMI watchdog.
- *  Mikael Pettersson  : Power Management for local APIC NMI watchdog.
- *  Mikael Pettersson  : Pentium 4 support for local APIC NMI watchdog.
- *  Pavel Machek and
- *  Mikael Pettersson  : PM converted to driver model. Disable/enable API.
- */
-
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/module.h>
-#include <linux/nmi.h>
-#include <linux/sysdev.h>
-#include <linux/sysctl.h>
-#include <linux/percpu.h>
-#include <linux/kprobes.h>
-#include <linux/cpumask.h>
-#include <linux/kernel_stat.h>
-#include <linux/kdebug.h>
-#include <linux/slab.h>
-
-#include <asm/smp.h>
-#include <asm/nmi.h>
-
-#include "mach_traps.h"
-
-int unknown_nmi_panic;
-int nmi_watchdog_enabled;
-
-static cpumask_t backtrace_mask = CPU_MASK_NONE;
-
-/* nmi_active:
- * >0: the lapic NMI watchdog is active, but can be disabled
- * <0: the lapic NMI watchdog has not been set up, and cannot
- *     be enabled
- *  0: the lapic NMI watchdog is disabled, but can be enabled
- */
-atomic_t nmi_active = ATOMIC_INIT(0);          /* oprofile uses this */
-
-unsigned int nmi_watchdog = NMI_DEFAULT;
-static unsigned int nmi_hz = HZ;
-
-static DEFINE_PER_CPU(short, wd_enabled);
-
-static int endflag __initdata = 0;
-
-#ifdef CONFIG_SMP
-/* The performance counters used by NMI_LOCAL_APIC don't trigger when
- * the CPU is idle. To make sure the NMI watchdog really ticks on all
- * CPUs during the test make them busy.
- */
-static __init void nmi_cpu_busy(void *data)
-{
-       local_irq_enable_in_hardirq();
-       /* Intentionally don't use cpu_relax here. This is
-          to make sure that the performance counter really ticks,
-          even if there is a simulator or similar that catches the
-          pause instruction. On a real HT machine this is fine because
-          all other CPUs are busy with "useless" delay loops and don't
-          care if they get somewhat less cycles. */
-       while (endflag == 0)
-               mb();
-}
-#endif
-
-int __init check_nmi_watchdog(void)
-{
-       unsigned int *prev_nmi_count;
-       int cpu;
-
-       if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DISABLED))
-               return 0;
-
-       if (!atomic_read(&nmi_active))
-               return 0;
-
-       prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
-       if (!prev_nmi_count)
-               return -1;
-
-       printk(KERN_INFO "Testing NMI watchdog ... ");
-
-#ifdef CONFIG_SMP
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
-#endif
-
-       for_each_possible_cpu(cpu)
-               prev_nmi_count[cpu] = nmi_count(cpu);
-       local_irq_enable();
-       mdelay((20*1000)/nmi_hz); // wait 20 ticks
-
-       for_each_possible_cpu(cpu) {
-#ifdef CONFIG_SMP
-               /* Check cpu_callin_map here because that is set
-                  after the timer is started. */
-               if (!cpu_isset(cpu, cpu_callin_map))
-                       continue;
-#endif
-               if (!per_cpu(wd_enabled, cpu))
-                       continue;
-               if (nmi_count(cpu) - prev_nmi_count[cpu] <= 5) {
-                       printk(KERN_WARNING "WARNING: CPU#%d: NMI "
-                               "appears to be stuck (%d->%d)!\n",
-                               cpu,
-                               prev_nmi_count[cpu],
-                               nmi_count(cpu));
-                       per_cpu(wd_enabled, cpu) = 0;
-                       atomic_dec(&nmi_active);
-               }
-       }
-       endflag = 1;
-       if (!atomic_read(&nmi_active)) {
-               kfree(prev_nmi_count);
-               atomic_set(&nmi_active, -1);
-               return -1;
-       }
-       printk("OK.\n");
-
-       /* now that we know it works we can reduce NMI frequency to
-          something more reasonable; makes a difference in some configs */
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               nmi_hz = lapic_adjust_nmi_hz(1);
-
-       kfree(prev_nmi_count);
-       return 0;
-}
-
-static int __init setup_nmi_watchdog(char *str)
-{
-       int nmi;
-
-       get_option(&str, &nmi);
-
-       if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE))
-               return 0;
-
-       nmi_watchdog = nmi;
-       return 1;
-}
-
-__setup("nmi_watchdog=", setup_nmi_watchdog);
-
-
-/* Suspend/resume support */
-
-#ifdef CONFIG_PM
-
-static int nmi_pm_active; /* nmi_active before suspend */
-
-static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
-{
-       /* only CPU0 goes here, other CPUs should be offline */
-       nmi_pm_active = atomic_read(&nmi_active);
-       stop_apic_nmi_watchdog(NULL);
-       BUG_ON(atomic_read(&nmi_active) != 0);
-       return 0;
-}
-
-static int lapic_nmi_resume(struct sys_device *dev)
-{
-       /* only CPU0 goes here, other CPUs should be offline */
-       if (nmi_pm_active > 0) {
-               setup_apic_nmi_watchdog(NULL);
-               touch_nmi_watchdog();
-       }
-       return 0;
-}
-
-
-static struct sysdev_class nmi_sysclass = {
-       .name           = "lapic_nmi",
-       .resume         = lapic_nmi_resume,
-       .suspend        = lapic_nmi_suspend,
-};
-
-static struct sys_device device_lapic_nmi = {
-       .id     = 0,
-       .cls    = &nmi_sysclass,
-};
-
-static int __init init_lapic_nmi_sysfs(void)
-{
-       int error;
-
-       /* should really be a BUG_ON but b/c this is an
-        * init call, it just doesn't work.  -dcz
-        */
-       if (nmi_watchdog != NMI_LOCAL_APIC)
-               return 0;
-
-       if (atomic_read(&nmi_active) < 0)
-               return 0;
-
-       error = sysdev_class_register(&nmi_sysclass);
-       if (!error)
-               error = sysdev_register(&device_lapic_nmi);
-       return error;
-}
-/* must come after the local APIC's device_initcall() */
-late_initcall(init_lapic_nmi_sysfs);
-
-#endif /* CONFIG_PM */
-
-static void __acpi_nmi_enable(void *__unused)
-{
-       apic_write_around(APIC_LVT0, APIC_DM_NMI);
-}
-
-/*
- * Enable timer based NMIs on all CPUs:
- */
-void acpi_nmi_enable(void)
-{
-       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
-               on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
-}
-
-static void __acpi_nmi_disable(void *__unused)
-{
-       apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
-}
-
-/*
- * Disable timer based NMIs on all CPUs:
- */
-void acpi_nmi_disable(void)
-{
-       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
-               on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
-}
-
-void setup_apic_nmi_watchdog(void *unused)
-{
-       if (__get_cpu_var(wd_enabled))
-               return;
-
-       /* cheap hack to support suspend/resume */
-       /* if cpu0 is not active neither should the other cpus */
-       if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0))
-               return;
-
-       switch (nmi_watchdog) {
-       case NMI_LOCAL_APIC:
-               __get_cpu_var(wd_enabled) = 1; /* enable it before to avoid race with handler */
-               if (lapic_watchdog_init(nmi_hz) < 0) {
-                       __get_cpu_var(wd_enabled) = 0;
-                       return;
-               }
-               /* FALL THROUGH */
-       case NMI_IO_APIC:
-               __get_cpu_var(wd_enabled) = 1;
-               atomic_inc(&nmi_active);
-       }
-}
-
-void stop_apic_nmi_watchdog(void *unused)
-{
-       /* only support LOCAL and IO APICs for now */
-       if ((nmi_watchdog != NMI_LOCAL_APIC) &&
-           (nmi_watchdog != NMI_IO_APIC))
-               return;
-       if (__get_cpu_var(wd_enabled) == 0)
-               return;
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               lapic_watchdog_stop();
-       __get_cpu_var(wd_enabled) = 0;
-       atomic_dec(&nmi_active);
-}
-
-/*
- * the best way to detect whether a CPU has a 'hard lockup' problem
- * is to check it's local APIC timer IRQ counts. If they are not
- * changing then that CPU has some problem.
- *
- * as these watchdog NMI IRQs are generated on every CPU, we only
- * have to check the current processor.
- *
- * since NMIs don't listen to _any_ locks, we have to be extremely
- * careful not to rely on unsafe variables. The printk might lock
- * up though, so we have to break up any console locks first ...
- * [when there will be more tty-related locks, break them up
- *  here too!]
- */
-
-static unsigned int
-       last_irq_sums [NR_CPUS],
-       alert_counter [NR_CPUS];
-
-void touch_nmi_watchdog(void)
-{
-       if (nmi_watchdog > 0) {
-               unsigned cpu;
-
-               /*
-                * Just reset the alert counters, (other CPUs might be
-                * spinning on locks we hold):
-                */
-               for_each_present_cpu(cpu) {
-                       if (alert_counter[cpu])
-                               alert_counter[cpu] = 0;
-               }
-       }
-
-       /*
-        * Tickle the softlockup detector too:
-        */
-       touch_softlockup_watchdog();
-}
-EXPORT_SYMBOL(touch_nmi_watchdog);
-
-extern void die_nmi(struct pt_regs *, const char *msg);
-
-notrace __kprobes int
-nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
-{
-
-       /*
-        * Since current_thread_info()-> is always on the stack, and we
-        * always switch the stack NMI-atomically, it's safe to use
-        * smp_processor_id().
-        */
-       unsigned int sum;
-       int touched = 0;
-       int cpu = smp_processor_id();
-       int rc = 0;
-
-       /* check for other users first */
-       if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-                       == NOTIFY_STOP) {
-               rc = 1;
-               touched = 1;
-       }
-
-       if (cpu_isset(cpu, backtrace_mask)) {
-               static DEFINE_SPINLOCK(lock);   /* Serialise the printks */
-
-               spin_lock(&lock);
-               printk("NMI backtrace for cpu %d\n", cpu);
-               dump_stack();
-               spin_unlock(&lock);
-               cpu_clear(cpu, backtrace_mask);
-       }
-
-       /*
-        * Take the local apic timer and PIT/HPET into account. We don't
-        * know which one is active, when we have highres/dyntick on
-        */
-       sum = per_cpu(irq_stat, cpu).apic_timer_irqs +
-               per_cpu(irq_stat, cpu).irq0_irqs;
-
-       /* if the none of the timers isn't firing, this cpu isn't doing much */
-       if (!touched && last_irq_sums[cpu] == sum) {
-               /*
-                * Ayiee, looks like this CPU is stuck ...
-                * wait a few IRQs (5 seconds) before doing the oops ...
-                */
-               alert_counter[cpu]++;
-               if (alert_counter[cpu] == 5*nmi_hz)
-                       /*
-                        * die_nmi will return ONLY if NOTIFY_STOP happens..
-                        */
-                       die_nmi(regs, "BUG: NMI Watchdog detected LOCKUP");
-       } else {
-               last_irq_sums[cpu] = sum;
-               alert_counter[cpu] = 0;
-       }
-       /* see if the nmi watchdog went off */
-       if (!__get_cpu_var(wd_enabled))
-               return rc;
-       switch (nmi_watchdog) {
-       case NMI_LOCAL_APIC:
-               rc |= lapic_wd_event(nmi_hz);
-               break;
-       case NMI_IO_APIC:
-               /* don't know how to accurately check for this.
-                * just assume it was a watchdog timer interrupt
-                * This matches the old behaviour.
-                */
-               rc = 1;
-               break;
-       }
-       return rc;
-}
-
-#ifdef CONFIG_SYSCTL
-
-static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
-{
-       unsigned char reason = get_nmi_reason();
-       char buf[64];
-
-       sprintf(buf, "NMI received for unknown reason %02x\n", reason);
-       die_nmi(regs, buf);
-       return 0;
-}
-
-/*
- * proc handler for /proc/sys/kernel/nmi
- */
-int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
-                       void __user *buffer, size_t *length, loff_t *ppos)
-{
-       int old_state;
-
-       nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
-       old_state = nmi_watchdog_enabled;
-       proc_dointvec(table, write, file, buffer, length, ppos);
-       if (!!old_state == !!nmi_watchdog_enabled)
-               return 0;
-
-       if (atomic_read(&nmi_active) < 0 || nmi_watchdog == NMI_DISABLED) {
-               printk( KERN_WARNING "NMI watchdog is permanently disabled\n");
-               return -EIO;
-       }
-
-       if (nmi_watchdog == NMI_DEFAULT) {
-               if (lapic_watchdog_ok())
-                       nmi_watchdog = NMI_LOCAL_APIC;
-               else
-                       nmi_watchdog = NMI_IO_APIC;
-       }
-
-       if (nmi_watchdog == NMI_LOCAL_APIC) {
-               if (nmi_watchdog_enabled)
-                       enable_lapic_nmi_watchdog();
-               else
-                       disable_lapic_nmi_watchdog();
-       } else {
-               printk( KERN_WARNING
-                       "NMI watchdog doesn't know what hardware to touch\n");
-               return -EIO;
-       }
-       return 0;
-}
-
-#endif
-
-int do_nmi_callback(struct pt_regs *regs, int cpu)
-{
-#ifdef CONFIG_SYSCTL
-       if (unknown_nmi_panic)
-               return unknown_nmi_panic_callback(regs, cpu);
-#endif
-       return 0;
-}
-
-void __trigger_all_cpu_backtrace(void)
-{
-       int i;
-
-       backtrace_mask = cpu_online_map;
-       /* Wait for up to 10 seconds for all CPUs to do the backtrace */
-       for (i = 0; i < 10 * 1000; i++) {
-               if (cpus_empty(backtrace_mask))
-                       break;
-               mdelay(1);
-       }
-}
-
-EXPORT_SYMBOL(nmi_active);
-EXPORT_SYMBOL(nmi_watchdog);
diff --git a/arch/x86/kernel/nmi_64.c b/arch/x86/kernel/nmi_64.c
deleted file mode 100644 (file)
index 5a29ded..0000000
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- *  NMI watchdog support on APIC systems
- *
- *  Started by Ingo Molnar <mingo@redhat.com>
- *
- *  Fixes:
- *  Mikael Pettersson  : AMD K7 support for local APIC NMI watchdog.
- *  Mikael Pettersson  : Power Management for local APIC NMI watchdog.
- *  Pavel Machek and
- *  Mikael Pettersson  : PM converted to driver model. Disable/enable API.
- */
-
-#include <linux/nmi.h>
-#include <linux/mm.h>
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/module.h>
-#include <linux/sysdev.h>
-#include <linux/sysctl.h>
-#include <linux/kprobes.h>
-#include <linux/cpumask.h>
-#include <linux/kdebug.h>
-
-#include <asm/smp.h>
-#include <asm/nmi.h>
-#include <asm/proto.h>
-#include <asm/mce.h>
-
-#include <mach_traps.h>
-
-int unknown_nmi_panic;
-int nmi_watchdog_enabled;
-int panic_on_unrecovered_nmi;
-
-static cpumask_t backtrace_mask = CPU_MASK_NONE;
-
-/* nmi_active:
- * >0: the lapic NMI watchdog is active, but can be disabled
- * <0: the lapic NMI watchdog has not been set up, and cannot
- *     be enabled
- *  0: the lapic NMI watchdog is disabled, but can be enabled
- */
-atomic_t nmi_active = ATOMIC_INIT(0);          /* oprofile uses this */
-static int panic_on_timeout;
-
-unsigned int nmi_watchdog = NMI_DEFAULT;
-static unsigned int nmi_hz = HZ;
-
-static DEFINE_PER_CPU(short, wd_enabled);
-
-/* Run after command line and cpu_init init, but before all other checks */
-void nmi_watchdog_default(void)
-{
-       if (nmi_watchdog != NMI_DEFAULT)
-               return;
-       nmi_watchdog = NMI_NONE;
-}
-
-static int endflag __initdata = 0;
-
-#ifdef CONFIG_SMP
-/* The performance counters used by NMI_LOCAL_APIC don't trigger when
- * the CPU is idle. To make sure the NMI watchdog really ticks on all
- * CPUs during the test make them busy.
- */
-static __init void nmi_cpu_busy(void *data)
-{
-       local_irq_enable_in_hardirq();
-       /* Intentionally don't use cpu_relax here. This is
-          to make sure that the performance counter really ticks,
-          even if there is a simulator or similar that catches the
-          pause instruction. On a real HT machine this is fine because
-          all other CPUs are busy with "useless" delay loops and don't
-          care if they get somewhat less cycles. */
-       while (endflag == 0)
-               mb();
-}
-#endif
-
-int __init check_nmi_watchdog(void)
-{
-       int *prev_nmi_count;
-       int cpu;
-
-       if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DISABLED))
-               return 0;
-
-       if (!atomic_read(&nmi_active))
-               return 0;
-
-       prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
-       if (!prev_nmi_count)
-               return -1;
-
-       printk(KERN_INFO "Testing NMI watchdog ... ");
-
-#ifdef CONFIG_SMP
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
-#endif
-
-       for (cpu = 0; cpu < NR_CPUS; cpu++)
-               prev_nmi_count[cpu] = cpu_pda(cpu)->__nmi_count;
-       local_irq_enable();
-       mdelay((20*1000)/nmi_hz); // wait 20 ticks
-
-       for_each_online_cpu(cpu) {
-               if (!per_cpu(wd_enabled, cpu))
-                       continue;
-               if (cpu_pda(cpu)->__nmi_count - prev_nmi_count[cpu] <= 5) {
-                       printk(KERN_WARNING "WARNING: CPU#%d: NMI "
-                              "appears to be stuck (%d->%d)!\n",
-                               cpu,
-                               prev_nmi_count[cpu],
-                               cpu_pda(cpu)->__nmi_count);
-                       per_cpu(wd_enabled, cpu) = 0;
-                       atomic_dec(&nmi_active);
-               }
-       }
-       endflag = 1;
-       if (!atomic_read(&nmi_active)) {
-               kfree(prev_nmi_count);
-               atomic_set(&nmi_active, -1);
-               return -1;
-       }
-       printk("OK.\n");
-
-       /* now that we know it works we can reduce NMI frequency to
-          something more reasonable; makes a difference in some configs */
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               nmi_hz = lapic_adjust_nmi_hz(1);
-
-       kfree(prev_nmi_count);
-       return 0;
-}
-
-static int __init setup_nmi_watchdog(char *str)
-{
-       int nmi;
-
-       if (!strncmp(str,"panic",5)) {
-               panic_on_timeout = 1;
-               str = strchr(str, ',');
-               if (!str)
-                       return 1;
-               ++str;
-       }
-
-       get_option(&str, &nmi);
-
-       if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE))
-               return 0;
-
-       nmi_watchdog = nmi;
-       return 1;
-}
-
-__setup("nmi_watchdog=", setup_nmi_watchdog);
-
-#ifdef CONFIG_PM
-
-static int nmi_pm_active; /* nmi_active before suspend */
-
-static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
-{
-       /* only CPU0 goes here, other CPUs should be offline */
-       nmi_pm_active = atomic_read(&nmi_active);
-       stop_apic_nmi_watchdog(NULL);
-       BUG_ON(atomic_read(&nmi_active) != 0);
-       return 0;
-}
-
-static int lapic_nmi_resume(struct sys_device *dev)
-{
-       /* only CPU0 goes here, other CPUs should be offline */
-       if (nmi_pm_active > 0) {
-               setup_apic_nmi_watchdog(NULL);
-               touch_nmi_watchdog();
-       }
-       return 0;
-}
-
-static struct sysdev_class nmi_sysclass = {
-       .name           = "lapic_nmi",
-       .resume         = lapic_nmi_resume,
-       .suspend        = lapic_nmi_suspend,
-};
-
-static struct sys_device device_lapic_nmi = {
-       .id     = 0,
-       .cls    = &nmi_sysclass,
-};
-
-static int __init init_lapic_nmi_sysfs(void)
-{
-       int error;
-
-       /* should really be a BUG_ON but b/c this is an
-        * init call, it just doesn't work.  -dcz
-        */
-       if (nmi_watchdog != NMI_LOCAL_APIC)
-               return 0;
-
-       if (atomic_read(&nmi_active) < 0)
-               return 0;
-
-       error = sysdev_class_register(&nmi_sysclass);
-       if (!error)
-               error = sysdev_register(&device_lapic_nmi);
-       return error;
-}
-/* must come after the local APIC's device_initcall() */
-late_initcall(init_lapic_nmi_sysfs);
-
-#endif /* CONFIG_PM */
-
-static void __acpi_nmi_enable(void *__unused)
-{
-       apic_write(APIC_LVT0, APIC_DM_NMI);
-}
-
-/*
- * Enable timer based NMIs on all CPUs:
- */
-void acpi_nmi_enable(void)
-{
-       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
-               on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
-}
-
-static void __acpi_nmi_disable(void *__unused)
-{
-       apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
-}
-
-/*
- * Disable timer based NMIs on all CPUs:
- */
-void acpi_nmi_disable(void)
-{
-       if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
-               on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
-}
-
-void setup_apic_nmi_watchdog(void *unused)
-{
-       if (__get_cpu_var(wd_enabled))
-               return;
-
-       /* cheap hack to support suspend/resume */
-       /* if cpu0 is not active neither should the other cpus */
-       if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0))
-               return;
-
-       switch (nmi_watchdog) {
-       case NMI_LOCAL_APIC:
-               __get_cpu_var(wd_enabled) = 1;
-               if (lapic_watchdog_init(nmi_hz) < 0) {
-                       __get_cpu_var(wd_enabled) = 0;
-                       return;
-               }
-               /* FALL THROUGH */
-       case NMI_IO_APIC:
-               __get_cpu_var(wd_enabled) = 1;
-               atomic_inc(&nmi_active);
-       }
-}
-
-void stop_apic_nmi_watchdog(void *unused)
-{
-       /* only support LOCAL and IO APICs for now */
-       if ((nmi_watchdog != NMI_LOCAL_APIC) &&
-           (nmi_watchdog != NMI_IO_APIC))
-               return;
-       if (__get_cpu_var(wd_enabled) == 0)
-               return;
-       if (nmi_watchdog == NMI_LOCAL_APIC)
-               lapic_watchdog_stop();
-       __get_cpu_var(wd_enabled) = 0;
-       atomic_dec(&nmi_active);
-}
-
-/*
- * the best way to detect whether a CPU has a 'hard lockup' problem
- * is to check it's local APIC timer IRQ counts. If they are not
- * changing then that CPU has some problem.
- *
- * as these watchdog NMI IRQs are generated on every CPU, we only
- * have to check the current processor.
- */
-
-static DEFINE_PER_CPU(unsigned, last_irq_sum);
-static DEFINE_PER_CPU(local_t, alert_counter);
-static DEFINE_PER_CPU(int, nmi_touch);
-
-void touch_nmi_watchdog(void)
-{
-       if (nmi_watchdog > 0) {
-               unsigned cpu;
-
-               /*
-                * Tell other CPUs to reset their alert counters. We cannot
-                * do it ourselves because the alert count increase is not
-                * atomic.
-                */
-               for_each_present_cpu(cpu) {
-                       if (per_cpu(nmi_touch, cpu) != 1)
-                               per_cpu(nmi_touch, cpu) = 1;
-               }
-       }
-
-       touch_softlockup_watchdog();
-}
-EXPORT_SYMBOL(touch_nmi_watchdog);
-
-notrace __kprobes int
-nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
-{
-       int sum;
-       int touched = 0;
-       int cpu = smp_processor_id();
-       int rc = 0;
-
-       /* check for other users first */
-       if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
-                       == NOTIFY_STOP) {
-               rc = 1;
-               touched = 1;
-       }
-
-       sum = read_pda(apic_timer_irqs) + read_pda(irq0_irqs);
-       if (__get_cpu_var(nmi_touch)) {
-               __get_cpu_var(nmi_touch) = 0;
-               touched = 1;
-       }
-
-       if (cpu_isset(cpu, backtrace_mask)) {
-               static DEFINE_SPINLOCK(lock);   /* Serialise the printks */
-
-               spin_lock(&lock);
-               printk("NMI backtrace for cpu %d\n", cpu);
-               dump_stack();
-               spin_unlock(&lock);
-               cpu_clear(cpu, backtrace_mask);
-       }
-
-#ifdef CONFIG_X86_MCE
-       /* Could check oops_in_progress here too, but it's safer
-          not too */
-       if (atomic_read(&mce_entry) > 0)
-               touched = 1;
-#endif
-       /* if the apic timer isn't firing, this cpu isn't doing much */
-       if (!touched && __get_cpu_var(last_irq_sum) == sum) {
-               /*
-                * Ayiee, looks like this CPU is stuck ...
-                * wait a few IRQs (5 seconds) before doing the oops ...
-                */
-               local_inc(&__get_cpu_var(alert_counter));
-               if (local_read(&__get_cpu_var(alert_counter)) == 5*nmi_hz)
-                       die_nmi("NMI Watchdog detected LOCKUP on CPU %d\n", regs,
-                               panic_on_timeout);
-       } else {
-               __get_cpu_var(last_irq_sum) = sum;
-               local_set(&__get_cpu_var(alert_counter), 0);
-       }
-
-       /* see if the nmi watchdog went off */
-       if (!__get_cpu_var(wd_enabled))
-               return rc;
-       switch (nmi_watchdog) {
-       case NMI_LOCAL_APIC:
-               rc |= lapic_wd_event(nmi_hz);
-               break;
-       case NMI_IO_APIC:
-               /* don't know how to accurately check for this.
-                * just assume it was a watchdog timer interrupt
-                * This matches the old behaviour.
-                */
-               rc = 1;
-               break;
-       }
-       return rc;
-}
-
-static unsigned ignore_nmis;
-
-asmlinkage notrace __kprobes void
-do_nmi(struct pt_regs *regs, long error_code)
-{
-       nmi_enter();
-       add_pda(__nmi_count,1);
-       if (!ignore_nmis)
-               default_do_nmi(regs);
-       nmi_exit();
-}
-
-void stop_nmi(void)
-{
-       acpi_nmi_disable();
-       ignore_nmis++;
-}
-
-void restart_nmi(void)
-{
-       ignore_nmis--;
-       acpi_nmi_enable();
-}
-
-#ifdef CONFIG_SYSCTL
-
-static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
-{
-       unsigned char reason = get_nmi_reason();
-       char buf[64];
-
-       sprintf(buf, "NMI received for unknown reason %02x\n", reason);
-       die_nmi(buf, regs, 1);  /* Always panic here */
-       return 0;
-}
-
-/*
- * proc handler for /proc/sys/kernel/nmi
- */
-int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
-                       void __user *buffer, size_t *length, loff_t *ppos)
-{
-       int old_state;
-
-       nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
-       old_state = nmi_watchdog_enabled;
-       proc_dointvec(table, write, file, buffer, length, ppos);
-       if (!!old_state == !!nmi_watchdog_enabled)
-               return 0;
-
-       if (atomic_read(&nmi_active) < 0 || nmi_watchdog == NMI_DISABLED) {
-               printk( KERN_WARNING "NMI watchdog is permanently disabled\n");
-               return -EIO;
-       }
-
-       /* if nmi_watchdog is not set yet, then set it */
-       nmi_watchdog_default();
-
-       if (nmi_watchdog == NMI_LOCAL_APIC) {
-               if (nmi_watchdog_enabled)
-                       enable_lapic_nmi_watchdog();
-               else
-                       disable_lapic_nmi_watchdog();
-       } else {
-               printk( KERN_WARNING
-                       "NMI watchdog doesn't know what hardware to touch\n");
-               return -EIO;
-       }
-       return 0;
-}
-
-#endif
-
-int do_nmi_callback(struct pt_regs *regs, int cpu)
-{
-#ifdef CONFIG_SYSCTL
-       if (unknown_nmi_panic)
-               return unknown_nmi_panic_callback(regs, cpu);
-#endif
-       return 0;
-}
-
-void __trigger_all_cpu_backtrace(void)
-{
-       int i;
-
-       backtrace_mask = cpu_online_map;
-       /* Wait for up to 10 seconds for all CPUs to do the backtrace */
-       for (i = 0; i < 10 * 1000; i++) {
-               if (cpus_empty(backtrace_mask))
-                       break;
-               mdelay(1);
-       }
-}
-
-EXPORT_SYMBOL(nmi_active);
-EXPORT_SYMBOL(nmi_watchdog);
index e65281b..5b20a5e 100644 (file)
@@ -31,6 +31,8 @@
 #include <asm/numaq.h>
 #include <asm/topology.h>
 #include <asm/processor.h>
+#include <asm/mpspec.h>
+#include <asm/e820.h>
 
 #define        MB_TO_PAGES(addr) ((addr) << (20 - PAGE_SHIFT))
 
@@ -58,6 +60,8 @@ static void __init smp_dump_qct(void)
                        node_end_pfn[node] = MB_TO_PAGES(
                                eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
 
+                       e820_register_active_regions(node, node_start_pfn[node],
+                                                       node_end_pfn[node]);
                        memory_present(node,
                                node_start_pfn[node], node_end_pfn[node]);
                        node_remap_size[node] = node_memmap_size_bytes(node,
@@ -67,23 +71,35 @@ static void __init smp_dump_qct(void)
        }
 }
 
-/*
- * Unlike Summit, we don't really care to let the NUMA-Q
- * fall back to flat mode.  Don't compile for NUMA-Q
- * unless you really need it!
- */
+static __init void early_check_numaq(void)
+{
+       /*
+        * Find possible boot-time SMP configuration:
+        */
+       early_find_smp_config();
+       /*
+        * get boot-time SMP configuration:
+        */
+       if (smp_found_config)
+               early_get_smp_config();
+}
+
 int __init get_memcfg_numaq(void)
 {
+       early_check_numaq();
+       if (!found_numaq)
+               return 0;
        smp_dump_qct();
        return 1;
 }
 
-static int __init numaq_tsc_disable(void)
+void __init numaq_tsc_disable(void)
 {
+       if (!found_numaq)
+               return -1;
+
        if (num_online_nodes() > 1) {
                printk(KERN_DEBUG "NUMAQ: disabling TSC\n");
                setup_clear_cpu_cap(X86_FEATURE_TSC);
        }
-       return 0;
 }
-arch_initcall(numaq_tsc_disable);
index 74f0c5e..e0f571d 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/setup.h>
 #include <asm/arch_hooks.h>
 #include <asm/time.h>
+#include <asm/pgalloc.h>
 #include <asm/irq.h>
 #include <asm/delay.h>
 #include <asm/fixmap.h>
@@ -139,7 +140,9 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
                /* If the operation is a nop, then nop the callsite */
                ret = paravirt_patch_nop();
        else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
-                type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_syscall_ret))
+                type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
+                type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret32) ||
+                type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
                /* If operation requires a jmp, then jmp */
                ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
        else
@@ -190,7 +193,9 @@ static void native_flush_tlb_single(unsigned long addr)
 
 /* These are in entry.S */
 extern void native_iret(void);
-extern void native_irq_enable_syscall_ret(void);
+extern void native_irq_enable_sysexit(void);
+extern void native_usergs_sysret32(void);
+extern void native_usergs_sysret64(void);
 
 static int __init print_banner(void)
 {
@@ -280,7 +285,7 @@ struct pv_time_ops pv_time_ops = {
        .get_wallclock = native_get_wallclock,
        .set_wallclock = native_set_wallclock,
        .sched_clock = native_sched_clock,
-       .get_cpu_khz = native_calculate_cpu_khz,
+       .get_tsc_khz = native_calibrate_tsc,
 };
 
 struct pv_irq_ops pv_irq_ops = {
@@ -291,6 +296,9 @@ struct pv_irq_ops pv_irq_ops = {
        .irq_enable = native_irq_enable,
        .safe_halt = native_safe_halt,
        .halt = native_halt,
+#ifdef CONFIG_X86_64
+       .adjust_exception_frame = paravirt_nop,
+#endif
 };
 
 struct pv_cpu_ops pv_cpu_ops = {
@@ -321,12 +329,23 @@ struct pv_cpu_ops pv_cpu_ops = {
        .store_idt = native_store_idt,
        .store_tr = native_store_tr,
        .load_tls = native_load_tls,
+#ifdef CONFIG_X86_64
+       .load_gs_index = native_load_gs_index,
+#endif
        .write_ldt_entry = native_write_ldt_entry,
        .write_gdt_entry = native_write_gdt_entry,
        .write_idt_entry = native_write_idt_entry,
        .load_sp0 = native_load_sp0,
 
-       .irq_enable_syscall_ret = native_irq_enable_syscall_ret,
+#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
+       .irq_enable_sysexit = native_irq_enable_sysexit,
+#endif
+#ifdef CONFIG_X86_64
+#ifdef CONFIG_IA32_EMULATION
+       .usergs_sysret32 = native_usergs_sysret32,
+#endif
+       .usergs_sysret64 = native_usergs_sysret64,
+#endif
        .iret = native_iret,
        .swapgs = native_swapgs,
 
@@ -366,6 +385,9 @@ struct pv_mmu_ops pv_mmu_ops = {
        .flush_tlb_single = native_flush_tlb_single,
        .flush_tlb_others = native_flush_tlb_others,
 
+       .pgd_alloc = __paravirt_pgd_alloc,
+       .pgd_free = paravirt_nop,
+
        .alloc_pte = paravirt_nop,
        .alloc_pmd = paravirt_nop,
        .alloc_pmd_clone = paravirt_nop,
@@ -380,6 +402,9 @@ struct pv_mmu_ops pv_mmu_ops = {
        .pte_update = paravirt_nop,
        .pte_update_defer = paravirt_nop,
 
+       .ptep_modify_prot_start = __ptep_modify_prot_start,
+       .ptep_modify_prot_commit = __ptep_modify_prot_commit,
+
 #ifdef CONFIG_HIGHPTE
        .kmap_atomic_pte = kmap_atomic,
 #endif
@@ -403,6 +428,7 @@ struct pv_mmu_ops pv_mmu_ops = {
 #endif /* PAGETABLE_LEVELS >= 3 */
 
        .pte_val = native_pte_val,
+       .pte_flags = native_pte_val,
        .pgd_val = native_pgd_val,
 
        .make_pte = native_make_pte,
@@ -416,6 +442,8 @@ struct pv_mmu_ops pv_mmu_ops = {
                .enter = paravirt_nop,
                .leave = paravirt_nop,
        },
+
+       .set_fixmap = native_set_fixmap,
 };
 
 EXPORT_SYMBOL_GPL(pv_time_ops);
index 82fc5fc..5826221 100644 (file)
@@ -5,7 +5,7 @@ DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
 DEF_NATIVE(pv_irq_ops, restore_fl, "push %eax; popf");
 DEF_NATIVE(pv_irq_ops, save_fl, "pushf; pop %eax");
 DEF_NATIVE(pv_cpu_ops, iret, "iret");
-DEF_NATIVE(pv_cpu_ops, irq_enable_syscall_ret, "sti; sysexit");
+DEF_NATIVE(pv_cpu_ops, irq_enable_sysexit, "sti; sysexit");
 DEF_NATIVE(pv_mmu_ops, read_cr2, "mov %cr2, %eax");
 DEF_NATIVE(pv_mmu_ops, write_cr3, "mov %eax, %cr3");
 DEF_NATIVE(pv_mmu_ops, read_cr3, "mov %cr3, %eax");
@@ -29,7 +29,7 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, restore_fl);
                PATCH_SITE(pv_irq_ops, save_fl);
                PATCH_SITE(pv_cpu_ops, iret);
-               PATCH_SITE(pv_cpu_ops, irq_enable_syscall_ret);
+               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
                PATCH_SITE(pv_mmu_ops, read_cr2);
                PATCH_SITE(pv_mmu_ops, read_cr3);
                PATCH_SITE(pv_mmu_ops, write_cr3);
index 7d904e1..061d01d 100644 (file)
@@ -14,8 +14,9 @@ DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
 DEF_NATIVE(pv_cpu_ops, clts, "clts");
 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
 
-/* the three commands give us more control to how to return from a syscall */
-DEF_NATIVE(pv_cpu_ops, irq_enable_syscall_ret, "movq %gs:" __stringify(pda_oldrsp) ", %rsp; swapgs; sysretq;");
+DEF_NATIVE(pv_cpu_ops, irq_enable_sysexit, "swapgs; sti; sysexit");
+DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq");
+DEF_NATIVE(pv_cpu_ops, usergs_sysret32, "swapgs; sysretl");
 DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
 
 unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
@@ -35,7 +36,9 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
                PATCH_SITE(pv_irq_ops, irq_enable);
                PATCH_SITE(pv_irq_ops, irq_disable);
                PATCH_SITE(pv_cpu_ops, iret);
-               PATCH_SITE(pv_cpu_ops, irq_enable_syscall_ret);
+               PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
+               PATCH_SITE(pv_cpu_ops, usergs_sysret32);
+               PATCH_SITE(pv_cpu_ops, usergs_sysret64);
                PATCH_SITE(pv_cpu_ops, swapgs);
                PATCH_SITE(pv_mmu_ops, read_cr2);
                PATCH_SITE(pv_mmu_ops, read_cr3);
index e28ec49..6959b5c 100644 (file)
@@ -1394,7 +1394,7 @@ void __init detect_calgary(void)
                return;
        }
 
-       specified_table_size = determine_tce_table_size(end_pfn * PAGE_SIZE);
+       specified_table_size = determine_tce_table_size(max_pfn * PAGE_SIZE);
 
        for (bus = 0; bus < MAX_PHB_BUS_NUM; bus++) {
                struct calgary_bus_info *info = &bus_info[bus];
@@ -1459,7 +1459,7 @@ int __init calgary_iommu_init(void)
        if (ret) {
                printk(KERN_ERR "PCI-DMA: Calgary init failed %d, "
                       "falling back to no_iommu\n", ret);
-               if (end_pfn > MAX_DMA32_PFN)
+               if (max_pfn > MAX_DMA32_PFN)
                        printk(KERN_ERR "WARNING more than 4GB of memory, "
                                        "32bit PCI may malfunction.\n");
                return ret;
index dc00a13..8467ec2 100644 (file)
@@ -7,6 +7,7 @@
 #include <asm/dma.h>
 #include <asm/gart.h>
 #include <asm/calgary.h>
+#include <asm/amd_iommu.h>
 
 int forbid_dac __read_mostly;
 EXPORT_SYMBOL(forbid_dac);
@@ -74,13 +75,17 @@ early_param("dma32_size", parse_dma32_size_opt);
 void __init dma32_reserve_bootmem(void)
 {
        unsigned long size, align;
-       if (end_pfn <= MAX_DMA32_PFN)
+       if (max_pfn <= MAX_DMA32_PFN)
                return;
 
+       /*
+        * check aperture_64.c allocate_aperture() for reason about
+        * using 512M as goal
+        */
        align = 64ULL<<20;
        size = round_up(dma32_bootmem_size, align);
        dma32_bootmem_ptr = __alloc_bootmem_nopanic(size, align,
-                                __pa(MAX_DMA_ADDRESS));
+                                512ULL<<20);
        if (dma32_bootmem_ptr)
                dma32_bootmem_size = size;
        else
@@ -88,17 +93,14 @@ void __init dma32_reserve_bootmem(void)
 }
 static void __init dma32_free_bootmem(void)
 {
-       int node;
 
-       if (end_pfn <= MAX_DMA32_PFN)
+       if (max_pfn <= MAX_DMA32_PFN)
                return;
 
        if (!dma32_bootmem_ptr)
                return;
 
-       for_each_online_node(node)
-               free_bootmem_node(NODE_DATA(node), __pa(dma32_bootmem_ptr),
-                                 dma32_bootmem_size);
+       free_bootmem(__pa(dma32_bootmem_ptr), dma32_bootmem_size);
 
        dma32_bootmem_ptr = NULL;
        dma32_bootmem_size = 0;
@@ -122,6 +124,8 @@ void __init pci_iommu_alloc(void)
 
        detect_intel_iommu();
 
+       amd_iommu_detect();
+
 #ifdef CONFIG_SWIOTLB
        pci_swiotlb_init();
 #endif
@@ -357,7 +361,7 @@ int dma_supported(struct device *dev, u64 mask)
 EXPORT_SYMBOL(dma_supported);
 
 /* Allocate DMA memory on node near device */
-noinline struct page *
+static noinline struct page *
 dma_alloc_pages(struct device *dev, gfp_t gfp, unsigned order)
 {
        int node;
@@ -502,6 +506,8 @@ static int __init pci_iommu_init(void)
 
        intel_iommu_init();
 
+       amd_iommu_init();
+
 #ifdef CONFIG_GART_IOMMU
        gart_iommu_init();
 #endif
index aa8ec92..c3fe784 100644 (file)
@@ -104,7 +104,6 @@ static unsigned long alloc_iommu(struct device *dev, int size)
                                          size, base_index, boundary_size, 0);
        }
        if (offset != -1) {
-               set_bit_string(iommu_gart_bitmap, offset, size);
                next_bit = offset+size;
                if (next_bit >= iommu_pages) {
                        next_bit = 0;
@@ -534,8 +533,8 @@ static __init unsigned read_aperture(struct pci_dev *dev, u32 *size)
        unsigned aper_size = 0, aper_base_32, aper_order;
        u64 aper_base;
 
-       pci_read_config_dword(dev, 0x94, &aper_base_32);
-       pci_read_config_dword(dev, 0x90, &aper_order);
+       pci_read_config_dword(dev, AMD64_GARTAPERTUREBASE, &aper_base_32);
+       pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &aper_order);
        aper_order = (aper_order >> 1) & 7;
 
        aper_base = aper_base_32 & 0x7fff;
@@ -549,14 +548,63 @@ static __init unsigned read_aperture(struct pci_dev *dev, u32 *size)
        return aper_base;
 }
 
+static void enable_gart_translations(void)
+{
+       int i;
+
+       for (i = 0; i < num_k8_northbridges; i++) {
+               struct pci_dev *dev = k8_northbridges[i];
+
+               enable_gart_translation(dev, __pa(agp_gatt_table));
+       }
+}
+
+/*
+ * If fix_up_north_bridges is set, the north bridges have to be fixed up on
+ * resume in the same way as they are handled in gart_iommu_hole_init().
+ */
+static bool fix_up_north_bridges;
+static u32 aperture_order;
+static u32 aperture_alloc;
+
+void set_up_gart_resume(u32 aper_order, u32 aper_alloc)
+{
+       fix_up_north_bridges = true;
+       aperture_order = aper_order;
+       aperture_alloc = aper_alloc;
+}
+
 static int gart_resume(struct sys_device *dev)
 {
+       printk(KERN_INFO "PCI-DMA: Resuming GART IOMMU\n");
+
+       if (fix_up_north_bridges) {
+               int i;
+
+               printk(KERN_INFO "PCI-DMA: Restoring GART aperture settings\n");
+
+               for (i = 0; i < num_k8_northbridges; i++) {
+                       struct pci_dev *dev = k8_northbridges[i];
+
+                       /*
+                        * Don't enable translations just yet.  That is the next
+                        * step.  Restore the pre-suspend aperture settings.
+                        */
+                       pci_write_config_dword(dev, AMD64_GARTAPERTURECTL,
+                                               aperture_order << 1);
+                       pci_write_config_dword(dev, AMD64_GARTAPERTUREBASE,
+                                               aperture_alloc >> 25);
+               }
+       }
+
+       enable_gart_translations();
+
        return 0;
 }
 
 static int gart_suspend(struct sys_device *dev, pm_message_t state)
 {
-       return -EINVAL;
+       return 0;
 }
 
 static struct sysdev_class gart_sysdev_class = {
@@ -582,6 +630,7 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
        struct pci_dev *dev;
        void *gatt;
        int i, error;
+       unsigned long start_pfn, end_pfn;
 
        printk(KERN_INFO "PCI-DMA: Disabling AGP.\n");
        aper_size = aper_base = info->aper_size = 0;
@@ -614,31 +663,25 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
        memset(gatt, 0, gatt_size);
        agp_gatt_table = gatt;
 
-       for (i = 0; i < num_k8_northbridges; i++) {
-               u32 gatt_reg;
-               u32 ctl;
-
-               dev = k8_northbridges[i];
-               gatt_reg = __pa(gatt) >> 12;
-               gatt_reg <<= 4;
-               pci_write_config_dword(dev, 0x98, gatt_reg);
-               pci_read_config_dword(dev, 0x90, &ctl);
-
-               ctl |= 1;
-               ctl &= ~((1<<4) | (1<<5));
-
-               pci_write_config_dword(dev, 0x90, ctl);
-       }
+       enable_gart_translations();
 
        error = sysdev_class_register(&gart_sysdev_class);
        if (!error)
                error = sysdev_register(&device_gart);
        if (error)
                panic("Could not register gart_sysdev -- would corrupt data on next suspend");
+
        flush_gart();
 
        printk(KERN_INFO "PCI-DMA: aperture base @ %x size %u KB\n",
               aper_base, aper_size>>10);
+
+       /* need to map that range */
+       end_pfn = (aper_base>>PAGE_SHIFT) + (aper_size>>PAGE_SHIFT);
+       if (end_pfn > max_low_pfn_mapped) {
+               start_pfn = (aper_base>>PAGE_SHIFT);
+               init_memory_mapping(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
+       }
        return 0;
 
  nommu:
@@ -677,11 +720,11 @@ void gart_iommu_shutdown(void)
                u32 ctl;
 
                dev = k8_northbridges[i];
-               pci_read_config_dword(dev, 0x90, &ctl);
+               pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl);
 
-               ctl &= ~1;
+               ctl &= ~GARTEN;
 
-               pci_write_config_dword(dev, 0x90, ctl);
+               pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
        }
 }
 
@@ -716,10 +759,10 @@ void __init gart_iommu_init(void)
                return;
 
        if (no_iommu ||
-           (!force_iommu && end_pfn <= MAX_DMA32_PFN) ||
+           (!force_iommu && max_pfn <= MAX_DMA32_PFN) ||
            !gart_iommu_aperture ||
            (no_agp && init_k8_gatt(&info) < 0)) {
-               if (end_pfn > MAX_DMA32_PFN) {
+               if (max_pfn > MAX_DMA32_PFN) {
                        printk(KERN_WARNING "More than 4GB of memory "
                                          "but GART IOMMU not available.\n"
                               KERN_WARNING "falling back to iommu=soft.\n");
@@ -788,10 +831,10 @@ void __init gart_iommu_init(void)
        wbinvd();
 
        /*
-        * Try to workaround a bug (thanks to BenH)
+        * Try to workaround a bug (thanks to BenH):
         * Set unmapped entries to a scratch page instead of 0.
         * Any prefetches that hit unmapped entries won't get an bus abort
-        * then.
+        * then. (P2P bridge may be prefetching on DMA reads).
         */
        scratch = get_zeroed_page(GFP_KERNEL);
        if (!scratch)
index 490da7f..82299cd 100644 (file)
@@ -38,7 +38,7 @@ const struct dma_mapping_ops swiotlb_dma_ops = {
 void __init pci_swiotlb_init(void)
 {
        /* don't initialize swiotlb if iommu=off (no_iommu=1) */
-       if (!iommu_detected && !no_iommu && end_pfn > MAX_DMA32_PFN)
+       if (!iommu_detected && !no_iommu && max_pfn > MAX_DMA32_PFN)
               swiotlb = 1;
        if (swiotlb_force)
                swiotlb = 1;
diff --git a/arch/x86/kernel/probe_roms_32.c b/arch/x86/kernel/probe_roms_32.c
new file mode 100644 (file)
index 0000000..675a48c
--- /dev/null
@@ -0,0 +1,166 @@
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/uaccess.h>
+#include <linux/mmzone.h>
+#include <linux/ioport.h>
+#include <linux/seq_file.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/edd.h>
+#include <linux/dmi.h>
+#include <linux/pfn.h>
+#include <linux/pci.h>
+#include <asm/pci-direct.h>
+
+
+#include <asm/e820.h>
+#include <asm/mmzone.h>
+#include <asm/setup.h>
+#include <asm/sections.h>
+#include <asm/io.h>
+#include <setup_arch.h>
+
+static struct resource system_rom_resource = {
+       .name   = "System ROM",
+       .start  = 0xf0000,
+       .end    = 0xfffff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+static struct resource extension_rom_resource = {
+       .name   = "Extension ROM",
+       .start  = 0xe0000,
+       .end    = 0xeffff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+static struct resource adapter_rom_resources[] = { {
+       .name   = "Adapter ROM",
+       .start  = 0xc8000,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+} };
+
+static struct resource video_rom_resource = {
+       .name   = "Video ROM",
+       .start  = 0xc0000,
+       .end    = 0xc7fff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+#define ROMSIGNATURE 0xaa55
+
+static int __init romsignature(const unsigned char *rom)
+{
+       const unsigned short * const ptr = (const unsigned short *)rom;
+       unsigned short sig;
+
+       return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
+}
+
+static int __init romchecksum(const unsigned char *rom, unsigned long length)
+{
+       unsigned char sum, c;
+
+       for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
+               sum += c;
+       return !length && !sum;
+}
+
+void __init probe_roms(void)
+{
+       const unsigned char *rom;
+       unsigned long start, length, upper;
+       unsigned char c;
+       int i;
+
+       /* video rom */
+       upper = adapter_rom_resources[0].start;
+       for (start = video_rom_resource.start; start < upper; start += 2048) {
+               rom = isa_bus_to_virt(start);
+               if (!romsignature(rom))
+                       continue;
+
+               video_rom_resource.start = start;
+
+               if (probe_kernel_address(rom + 2, c) != 0)
+                       continue;
+
+               /* 0 < length <= 0x7f * 512, historically */
+               length = c * 512;
+
+               /* if checksum okay, trust length byte */
+               if (length && romchecksum(rom, length))
+                       video_rom_resource.end = start + length - 1;
+
+               request_resource(&iomem_resource, &video_rom_resource);
+               break;
+       }
+
+       start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
+       if (start < upper)
+               start = upper;
+
+       /* system rom */
+       request_resource(&iomem_resource, &system_rom_resource);
+       upper = system_rom_resource.start;
+
+       /* check for extension rom (ignore length byte!) */
+       rom = isa_bus_to_virt(extension_rom_resource.start);
+       if (romsignature(rom)) {
+               length = extension_rom_resource.end - extension_rom_resource.start + 1;
+               if (romchecksum(rom, length)) {
+                       request_resource(&iomem_resource, &extension_rom_resource);
+                       upper = extension_rom_resource.start;
+               }
+       }
+
+       /* check for adapter roms on 2k boundaries */
+       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
+               rom = isa_bus_to_virt(start);
+               if (!romsignature(rom))
+                       continue;
+
+               if (probe_kernel_address(rom + 2, c) != 0)
+                       continue;
+
+               /* 0 < length <= 0x7f * 512, historically */
+               length = c * 512;
+
+               /* but accept any length that fits if checksum okay */
+               if (!length || start + length > upper || !romchecksum(rom, length))
+                       continue;
+
+               adapter_rom_resources[i].start = start;
+               adapter_rom_resources[i].end = start + length - 1;
+               request_resource(&iomem_resource, &adapter_rom_resources[i]);
+
+               start = adapter_rom_resources[i++].end & ~2047UL;
+       }
+}
+
index ba370dc..4061d63 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/pm.h>
+#include <linux/clockchips.h>
 
 struct kmem_cache *task_xstate_cachep;
 
@@ -45,6 +46,76 @@ void arch_task_cache_init(void)
                                  SLAB_PANIC, NULL);
 }
 
+/*
+ * Idle related variables and functions
+ */
+unsigned long boot_option_idle_override = 0;
+EXPORT_SYMBOL(boot_option_idle_override);
+
+/*
+ * Powermanagement idle function, if any..
+ */
+void (*pm_idle)(void);
+EXPORT_SYMBOL(pm_idle);
+
+#ifdef CONFIG_X86_32
+/*
+ * This halt magic was a workaround for ancient floppy DMA
+ * wreckage. It should be safe to remove.
+ */
+static int hlt_counter;
+void disable_hlt(void)
+{
+       hlt_counter++;
+}
+EXPORT_SYMBOL(disable_hlt);
+
+void enable_hlt(void)
+{
+       hlt_counter--;
+}
+EXPORT_SYMBOL(enable_hlt);
+
+static inline int hlt_use_halt(void)
+{
+       return (!hlt_counter && boot_cpu_data.hlt_works_ok);
+}
+#else
+static inline int hlt_use_halt(void)
+{
+       return 1;
+}
+#endif
+
+/*
+ * We use this if we don't have any better
+ * idle routine..
+ */
+void default_idle(void)
+{
+       if (hlt_use_halt()) {
+               current_thread_info()->status &= ~TS_POLLING;
+               /*
+                * TS_POLLING-cleared state must be visible before we
+                * test NEED_RESCHED:
+                */
+               smp_mb();
+
+               if (!need_resched())
+                       safe_halt();    /* enables interrupts racelessly */
+               else
+                       local_irq_enable();
+               current_thread_info()->status |= TS_POLLING;
+       } else {
+               local_irq_enable();
+               /* loop is done by the caller */
+               cpu_relax();
+       }
+}
+#ifdef CONFIG_APM_MODULE
+EXPORT_SYMBOL(default_idle);
+#endif
+
 static void do_nothing(void *unused)
 {
 }
@@ -122,44 +193,129 @@ static void poll_idle(void)
  *
  * idle=mwait overrides this decision and forces the usage of mwait.
  */
+
+#define MWAIT_INFO                     0x05
+#define MWAIT_ECX_EXTENDED_INFO                0x01
+#define MWAIT_EDX_C1                   0xf0
+
 static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
 {
+       u32 eax, ebx, ecx, edx;
+
        if (force_mwait)
                return 1;
 
-       if (c->x86_vendor == X86_VENDOR_AMD) {
-               switch(c->x86) {
-               case 0x10:
-               case 0x11:
-                       return 0;
-               }
-       }
+       if (c->cpuid_level < MWAIT_INFO)
+               return 0;
+
+       cpuid(MWAIT_INFO, &eax, &ebx, &ecx, &edx);
+       /* Check, whether EDX has extended info about MWAIT */
+       if (!(ecx & MWAIT_ECX_EXTENDED_INFO))
+               return 1;
+
+       /*
+        * edx enumeratios MONITOR/MWAIT extensions. Check, whether
+        * C1  supports MWAIT
+        */
+       return (edx & MWAIT_EDX_C1);
+}
+
+/*
+ * Check for AMD CPUs, which have potentially C1E support
+ */
+static int __cpuinit check_c1e_idle(const struct cpuinfo_x86 *c)
+{
+       if (c->x86_vendor != X86_VENDOR_AMD)
+               return 0;
+
+       if (c->x86 < 0x0F)
+               return 0;
+
+       /* Family 0x0f models < rev F do not have C1E */
+       if (c->x86 == 0x0f && c->x86_model < 0x40)
+               return 0;
+
        return 1;
 }
 
-void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
+/*
+ * C1E aware idle routine. We check for C1E active in the interrupt
+ * pending message MSR. If we detect C1E, then we handle it the same
+ * way as C3 power states (local apic timer and TSC stop)
+ */
+static void c1e_idle(void)
 {
-       static int selected;
+       static cpumask_t c1e_mask = CPU_MASK_NONE;
+       static int c1e_detected;
 
-       if (selected)
+       if (need_resched())
                return;
+
+       if (!c1e_detected) {
+               u32 lo, hi;
+
+               rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi);
+               if (lo & K8_INTP_C1E_ACTIVE_MASK) {
+                       c1e_detected = 1;
+                       mark_tsc_unstable("TSC halt in C1E");
+                       printk(KERN_INFO "System has C1E enabled\n");
+               }
+       }
+
+       if (c1e_detected) {
+               int cpu = smp_processor_id();
+
+               if (!cpu_isset(cpu, c1e_mask)) {
+                       cpu_set(cpu, c1e_mask);
+                       /*
+                        * Force broadcast so ACPI can not interfere. Needs
+                        * to run with interrupts enabled as it uses
+                        * smp_function_call.
+                        */
+                       local_irq_enable();
+                       clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
+                                          &cpu);
+                       printk(KERN_INFO "Switch to broadcast mode on CPU%d\n",
+                              cpu);
+                       local_irq_disable();
+               }
+               clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+
+               default_idle();
+
+               /*
+                * The switch back from broadcast mode needs to be
+                * called with interrupts disabled.
+                */
+                local_irq_disable();
+                clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+                local_irq_enable();
+       } else
+               default_idle();
+}
+
+void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
+{
 #ifdef CONFIG_X86_SMP
        if (pm_idle == poll_idle && smp_num_siblings > 1) {
                printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
                        " performance may degrade.\n");
        }
 #endif
+       if (pm_idle)
+               return;
+
        if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
                /*
-                * Skip, if setup has overridden idle.
                 * One CPU supports mwait => All CPUs supports mwait
                 */
-               if (!pm_idle) {
-                       printk(KERN_INFO "using mwait in idle threads.\n");
-                       pm_idle = mwait_idle;
-               }
-       }
-       selected = 1;
+               printk(KERN_INFO "using mwait in idle threads.\n");
+               pm_idle = mwait_idle;
+       } else if (check_c1e_idle(c)) {
+               printk(KERN_INFO "using C1E aware idle routine\n");
+               pm_idle = c1e_idle;
+       } else
+               pm_idle = default_idle;
 }
 
 static int __init idle_setup(char *str)
index e2db9ac..0c3927a 100644 (file)
 
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
 
-static int hlt_counter;
-
-unsigned long boot_option_idle_override = 0;
-EXPORT_SYMBOL(boot_option_idle_override);
-
 DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
 EXPORT_PER_CPU_SYMBOL(current_task);
 
@@ -77,57 +72,24 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return ((unsigned long *)tsk->thread.sp)[3];
 }
 
-/*
- * Powermanagement idle function, if any..
- */
-void (*pm_idle)(void);
-EXPORT_SYMBOL(pm_idle);
+#ifdef CONFIG_HOTPLUG_CPU
+#include <asm/nmi.h>
 
-void disable_hlt(void)
+static void cpu_exit_clear(void)
 {
-       hlt_counter++;
-}
+       int cpu = raw_smp_processor_id();
 
-EXPORT_SYMBOL(disable_hlt);
+       idle_task_exit();
 
-void enable_hlt(void)
-{
-       hlt_counter--;
-}
+       cpu_uninit();
+       irq_ctx_exit(cpu);
 
-EXPORT_SYMBOL(enable_hlt);
-
-/*
- * We use this if we don't have any better
- * idle routine..
- */
-void default_idle(void)
-{
-       if (!hlt_counter && boot_cpu_data.hlt_works_ok) {
-               current_thread_info()->status &= ~TS_POLLING;
-               /*
-                * TS_POLLING-cleared state must be visible before we
-                * test NEED_RESCHED:
-                */
-               smp_mb();
+       cpu_clear(cpu, cpu_callout_map);
+       cpu_clear(cpu, cpu_callin_map);
 
-               if (!need_resched())
-                       safe_halt();    /* enables interrupts racelessly */
-               else
-                       local_irq_enable();
-               current_thread_info()->status |= TS_POLLING;
-       } else {
-               local_irq_enable();
-               /* loop is done by the caller */
-               cpu_relax();
-       }
+       numa_remove_cpu(cpu);
 }
-#ifdef CONFIG_APM_MODULE
-EXPORT_SYMBOL(default_idle);
-#endif
 
-#ifdef CONFIG_HOTPLUG_CPU
-#include <asm/nmi.h>
 /* We don't actually take CPU down, just spin without interrupts. */
 static inline void play_dead(void)
 {
@@ -168,24 +130,22 @@ void cpu_idle(void)
        while (1) {
                tick_nohz_stop_sched_tick();
                while (!need_resched()) {
-                       void (*idle)(void);
 
                        check_pgt_cache();
                        rmb();
-                       idle = pm_idle;
 
                        if (rcu_pending(cpu))
                                rcu_check_callbacks(cpu, 0);
 
-                       if (!idle)
-                               idle = default_idle;
-
                        if (cpu_is_offline(cpu))
                                play_dead();
 
                        local_irq_disable();
                        __get_cpu_var(irq_stat).idle_timestamp = jiffies;
-                       idle();
+                       /* Don't trace irqs off for idle */
+                       stop_critical_timings();
+                       pm_idle();
+                       start_critical_timings();
                }
                tick_nohz_restart_sched_tick();
                preempt_enable_no_resched();
index c6eb5c9..a8e5362 100644 (file)
@@ -56,15 +56,6 @@ asmlinkage extern void ret_from_fork(void);
 
 unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
 
-unsigned long boot_option_idle_override = 0;
-EXPORT_SYMBOL(boot_option_idle_override);
-
-/*
- * Powermanagement idle function, if any..
- */
-void (*pm_idle)(void);
-EXPORT_SYMBOL(pm_idle);
-
 static ATOMIC_NOTIFIER_HEAD(idle_notifier);
 
 void idle_notifier_register(struct notifier_block *n)
@@ -94,25 +85,6 @@ void exit_idle(void)
        __exit_idle();
 }
 
-/*
- * We use this if we don't have any better
- * idle routine..
- */
-void default_idle(void)
-{
-       current_thread_info()->status &= ~TS_POLLING;
-       /*
-        * TS_POLLING-cleared state must be visible before we
-        * test NEED_RESCHED:
-        */
-       smp_mb();
-       if (!need_resched())
-               safe_halt();    /* enables interrupts racelessly */
-       else
-               local_irq_enable();
-       current_thread_info()->status |= TS_POLLING;
-}
-
 #ifdef CONFIG_HOTPLUG_CPU
 DECLARE_PER_CPU(int, cpu_state);
 
@@ -150,12 +122,9 @@ void cpu_idle(void)
        while (1) {
                tick_nohz_stop_sched_tick();
                while (!need_resched()) {
-                       void (*idle)(void);
 
                        rmb();
-                       idle = pm_idle;
-                       if (!idle)
-                               idle = default_idle;
+
                        if (cpu_is_offline(smp_processor_id()))
                                play_dead();
                        /*
@@ -165,7 +134,10 @@ void cpu_idle(void)
                         */
                        local_irq_disable();
                        enter_idle();
-                       idle();
+                       /* Don't trace irqs off for idle */
+                       stop_critical_timings();
+                       pm_idle();
+                       start_critical_timings();
                        /* In many cases the interrupt that ended idle
                           has already called exit_idle. But some idle
                           loops can be woken up without interrupt. */
@@ -366,10 +338,10 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
        p->thread.fs = me->thread.fs;
        p->thread.gs = me->thread.gs;
 
-       asm("mov %%gs,%0" : "=m" (p->thread.gsindex));
-       asm("mov %%fs,%0" : "=m" (p->thread.fsindex));
-       asm("mov %%es,%0" : "=m" (p->thread.es));
-       asm("mov %%ds,%0" : "=m" (p->thread.ds));
+       savesegment(gs, p->thread.gsindex);
+       savesegment(fs, p->thread.fsindex);
+       savesegment(es, p->thread.es);
+       savesegment(ds, p->thread.ds);
 
        if (unlikely(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
                p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
@@ -408,7 +380,9 @@ out:
 void
 start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
 {
-       asm volatile("movl %0, %%fs; movl %0, %%es; movl %0, %%ds" :: "r"(0));
+       loadsegment(fs, 0);
+       loadsegment(es, 0);
+       loadsegment(ds, 0);
        load_gs_index(0);
        regs->ip                = new_ip;
        regs->sp                = new_sp;
@@ -567,6 +541,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
                                 *next = &next_p->thread;
        int cpu = smp_processor_id();
        struct tss_struct *tss = &per_cpu(init_tss, cpu);
+       unsigned fsindex, gsindex;
 
        /* we're going to use this soon, after a few expensive things */
        if (next_p->fpu_counter>5)
@@ -581,22 +556,38 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
         * Switch DS and ES.
         * This won't pick up thread selector changes, but I guess that is ok.
         */
-       asm volatile("mov %%es,%0" : "=m" (prev->es));
+       savesegment(es, prev->es);
        if (unlikely(next->es | prev->es))
                loadsegment(es, next->es); 
-       
-       asm volatile ("mov %%ds,%0" : "=m" (prev->ds));
+
+       savesegment(ds, prev->ds);
        if (unlikely(next->ds | prev->ds))
                loadsegment(ds, next->ds);
 
+
+       /* We must save %fs and %gs before load_TLS() because
+        * %fs and %gs may be cleared by load_TLS().
+        *
+        * (e.g. xen_load_tls())
+        */
+       savesegment(fs, fsindex);
+       savesegment(gs, gsindex);
+
        load_TLS(next, cpu);
 
+       /*
+        * Leave lazy mode, flushing any hypercalls made here.
+        * This must be done before restoring TLS segments so
+        * the GDT and LDT are properly updated, and must be
+        * done before math_state_restore, so the TS bit is up
+        * to date.
+        */
+       arch_leave_lazy_cpu_mode();
+
        /* 
         * Switch FS and GS.
         */
        { 
-               unsigned fsindex;
-               asm volatile("movl %%fs,%0" : "=r" (fsindex)); 
                /* segment register != 0 always requires a reload. 
                   also reload when it has changed. 
                   when prev process used 64bit base always reload
@@ -614,10 +605,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
                if (next->fs) 
                        wrmsrl(MSR_FS_BASE, next->fs); 
                prev->fsindex = fsindex;
-       }
-       { 
-               unsigned gsindex;
-               asm volatile("movl %%gs,%0" : "=r" (gsindex)); 
+
                if (unlikely(gsindex | next->gsindex | prev->gs)) {
                        load_gs_index(next->gsindex);
                        if (gsindex)
@@ -798,7 +786,7 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
                        set_32bit_tls(task, FS_TLS, addr);
                        if (doit) {
                                load_TLS(&task->thread, cpu);
-                               asm volatile("movl %0,%%fs" :: "r"(FS_TLS_SEL));
+                               loadsegment(fs, FS_TLS_SEL);
                        }
                        task->thread.fsindex = FS_TLS_SEL;
                        task->thread.fs = 0;
@@ -808,7 +796,7 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
                        if (doit) {
                                /* set the selector to 0 to not confuse
                                   __switch_to */
-                               asm volatile("movl %0,%%fs" :: "r" (0));
+                               loadsegment(fs, 0);
                                ret = checking_wrmsrl(MSR_FS_BASE, addr);
                        }
                }
@@ -831,7 +819,7 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
                if (task->thread.gsindex == GS_TLS_SEL)
                        base = read_32bit_tls(task, GS_TLS);
                else if (doit) {
-                       asm("movl %%gs,%0" : "=r" (gsindex));
+                       savesegment(gs, gsindex);
                        if (gsindex)
                                rdmsrl(MSR_KERNEL_GS_BASE, base);
                        else
index a7835f2..77040b6 100644 (file)
@@ -943,13 +943,13 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                return copy_regset_to_user(child, &user_x86_32_view,
                                           REGSET_XFP,
                                           0, sizeof(struct user_fxsr_struct),
-                                          datap);
+                                          datap) ? -EIO : 0;
 
        case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
                return copy_regset_from_user(child, &user_x86_32_view,
                                             REGSET_XFP,
                                             0, sizeof(struct user_fxsr_struct),
-                                            datap);
+                                            datap) ? -EIO : 0;
 #endif
 
 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
index d89a648..79bdcd1 100644 (file)
@@ -65,6 +65,7 @@ static enum {
        ICH_FORCE_HPET_RESUME,
        VT8237_FORCE_HPET_RESUME,
        NVIDIA_FORCE_HPET_RESUME,
+       ATI_FORCE_HPET_RESUME,
 } force_hpet_resume_type;
 
 static void __iomem *rcba_base;
@@ -158,6 +159,8 @@ static void ich_force_enable_hpet(struct pci_dev *dev)
 
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
                         ich_force_enable_hpet);
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0,
+                        ich_force_enable_hpet);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
                         ich_force_enable_hpet);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
@@ -174,6 +177,12 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7,
 
 static struct pci_dev *cached_dev;
 
+static void hpet_print_force_info(void)
+{
+       printk(KERN_INFO "HPET not enabled in BIOS. "
+              "You might try hpet=force boot option\n");
+}
+
 static void old_ich_force_hpet_resume(void)
 {
        u32 val;
@@ -253,6 +262,8 @@ static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
 {
        if (hpet_force_user)
                old_ich_force_enable_hpet(dev);
+       else
+               hpet_print_force_info();
 }
 
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
@@ -290,8 +301,13 @@ static void vt8237_force_enable_hpet(struct pci_dev *dev)
 {
        u32 uninitialized_var(val);
 
-       if (!hpet_force_user || hpet_address || force_hpet_address)
+       if (hpet_address || force_hpet_address)
+               return;
+
+       if (!hpet_force_user) {
+               hpet_print_force_info();
                return;
+       }
 
        pci_read_config_dword(dev, 0x68, &val);
        /*
@@ -330,6 +346,36 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
                         vt8237_force_enable_hpet);
 
+static void ati_force_hpet_resume(void)
+{
+       pci_write_config_dword(cached_dev, 0x14, 0xfed00000);
+       printk(KERN_DEBUG "Force enabled HPET at resume\n");
+}
+
+static void ati_force_enable_hpet(struct pci_dev *dev)
+{
+       u32 uninitialized_var(val);
+
+       if (hpet_address || force_hpet_address)
+               return;
+
+       if (!hpet_force_user) {
+               hpet_print_force_info();
+               return;
+       }
+
+       pci_write_config_dword(dev, 0x14, 0xfed00000);
+       pci_read_config_dword(dev, 0x14, &val);
+       force_hpet_address = val;
+       force_hpet_resume_type = ATI_FORCE_HPET_RESUME;
+       dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
+                  force_hpet_address);
+       cached_dev = dev;
+       return;
+}
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
+                        ati_force_enable_hpet);
+
 /*
  * Undocumented chipset feature taken from LinuxBIOS.
  */
@@ -343,8 +389,13 @@ static void nvidia_force_enable_hpet(struct pci_dev *dev)
 {
        u32 uninitialized_var(val);
 
-       if (!hpet_force_user || hpet_address || force_hpet_address)
+       if (hpet_address || force_hpet_address)
+               return;
+
+       if (!hpet_force_user) {
+               hpet_print_force_info();
                return;
+       }
 
        pci_write_config_dword(dev, 0x44, 0xfed00001);
        pci_read_config_dword(dev, 0x44, &val);
@@ -397,6 +448,9 @@ void force_hpet_resume(void)
        case NVIDIA_FORCE_HPET_RESUME:
                nvidia_force_hpet_resume();
                return;
+       case ATI_FORCE_HPET_RESUME:
+               ati_force_hpet_resume();
+               return;
        default:
                break;
        }
index f6be7d5..f8a6216 100644 (file)
@@ -27,7 +27,7 @@
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
-static long no_idt[3];
+static const struct desc_ptr no_idt = {};
 static int reboot_mode;
 enum reboot_type reboot_type = BOOT_KBD;
 int reboot_force;
@@ -201,15 +201,15 @@ core_initcall(reboot_init);
    controller to pulse the CPU reset line, which is more thorough, but
    doesn't work with at least one type of 486 motherboard.  It is easy
    to stop this code working; hence the copious comments. */
-static unsigned long long
+static const unsigned long long
 real_mode_gdt_entries [3] =
 {
        0x0000000000000000ULL,  /* Null descriptor */
-       0x00009a000000ffffULL,  /* 16-bit real-mode 64k code at 0x00000000 */
-       0x000092000100ffffULL   /* 16-bit real-mode 64k data at 0x00000100 */
+       0x00009b000000ffffULL,  /* 16-bit real-mode 64k code at 0x00000000 */
+       0x000093000100ffffULL   /* 16-bit real-mode 64k data at 0x00000100 */
 };
 
-static struct desc_ptr
+static const struct desc_ptr
 real_mode_gdt = { sizeof (real_mode_gdt_entries) - 1, (long)real_mode_gdt_entries },
 real_mode_idt = { 0x3ff, 0 };
 
@@ -231,7 +231,7 @@ real_mode_idt = { 0x3ff, 0 };
 
    More could be done here to set up the registers as if a CPU reset had
    occurred; hopefully real BIOSs don't assume much. */
-static unsigned char real_mode_switch [] =
+static const unsigned char real_mode_switch [] =
 {
        0x66, 0x0f, 0x20, 0xc0,                 /*    movl  %cr0,%eax        */
        0x66, 0x83, 0xe0, 0x11,                 /*    andl  $0x00000011,%eax */
@@ -245,7 +245,7 @@ static unsigned char real_mode_switch [] =
        0x24, 0x10,                             /* f: andb  $0x10,al         */
        0x66, 0x0f, 0x22, 0xc0                  /*    movl  %eax,%cr0        */
 };
-static unsigned char jump_to_bios [] =
+static const unsigned char jump_to_bios [] =
 {
        0xea, 0x00, 0x00, 0xff, 0xff            /*    ljmp  $0xffff,$0x0000  */
 };
@@ -255,7 +255,7 @@ static unsigned char jump_to_bios [] =
  * specified by the code and length parameters.
  * We assume that length will aways be less that 100!
  */
-void machine_real_restart(unsigned char *code, int length)
+void machine_real_restart(const unsigned char *code, int length)
 {
        local_irq_disable();
 
@@ -368,7 +368,7 @@ static void native_machine_emergency_restart(void)
                        }
 
                case BOOT_TRIPLE:
-                       load_idt((const struct desc_ptr *)&no_idt);
+                       load_idt(&no_idt);
                        __asm__ __volatile__("int3");
 
                        reboot_type = BOOT_KBD;
index dec0b5e..61a8377 100644 (file)
@@ -49,7 +49,7 @@ struct device_fixup {
        void (*reboot_fixup)(struct pci_dev *);
 };
 
-static struct device_fixup fixups_table[] = {
+static const struct device_fixup fixups_table[] = {
 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY, cs5530a_warm_reset },
 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, cs5536_warm_reset },
 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE, cs5530a_warm_reset },
@@ -64,7 +64,7 @@ static struct device_fixup fixups_table[] = {
  */
 void mach_reboot_fixups(void)
 {
-       struct device_fixup *cur;
+       const struct device_fixup *cur;
        struct pci_dev *dev;
        int i;
 
index 6f80b85..36c540d 100644 (file)
-#include <linux/kernel.h>
+/*
+ *  Copyright (C) 1995  Linus Torvalds
+ *
+ *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
+ *
+ *  Memory region support
+ *     David Parsons <orc@pell.chi.il.us>, July-August 1999
+ *
+ *  Added E820 sanitization routine (removes overlapping memory regions);
+ *  Brian Moyle <bmoyle@mvista.com>, February 2001
+ *
+ * Moved CPU detection code to cpu/${cpu}.c
+ *    Patrick Mochel <mochel@osdl.org>, March 2002
+ *
+ *  Provisions for empty E820 memory regions (reported by certain BIOSes).
+ *  Alex Achenbach <xela@slit.de>, December 2002.
+ *
+ */
+
+/*
+ * This file handles the architecture-dependent parts of initialization
+ */
+
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/screen_info.h>
+#include <linux/ioport.h>
+#include <linux/acpi.h>
+#include <linux/apm_bios.h>
+#include <linux/initrd.h>
+#include <linux/bootmem.h>
+#include <linux/seq_file.h>
+#include <linux/console.h>
+#include <linux/mca.h>
+#include <linux/root_dev.h>
+#include <linux/highmem.h>
 #include <linux/module.h>
+#include <linux/efi.h>
 #include <linux/init.h>
-#include <linux/bootmem.h>
+#include <linux/edd.h>
+#include <linux/iscsi_ibft.h>
+#include <linux/nodemask.h>
+#include <linux/kexec.h>
+#include <linux/dmi.h>
+#include <linux/pfn.h>
+#include <linux/pci.h>
+#include <asm/pci-direct.h>
+#include <linux/init_ohci1394_dma.h>
+#include <linux/kvm_para.h>
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/stddef.h>
+#include <linux/unistd.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/user.h>
+#include <linux/delay.h>
+#include <linux/highmem.h>
+
+#include <linux/kallsyms.h>
+#include <linux/edd.h>
+#include <linux/iscsi_ibft.h>
+#include <linux/kexec.h>
+#include <linux/cpufreq.h>
+#include <linux/dma-mapping.h>
+#include <linux/ctype.h>
+#include <linux/uaccess.h>
+
 #include <linux/percpu.h>
+#include <linux/crash_dump.h>
+
+#include <video/edid.h>
+
+#include <asm/mtrr.h>
+#include <asm/apic.h>
+#include <asm/e820.h>
+#include <asm/mpspec.h>
+#include <asm/setup.h>
+#include <asm/arch_hooks.h>
+#include <asm/efi.h>
+#include <asm/sections.h>
+#include <asm/dmi.h>
+#include <asm/io_apic.h>
+#include <asm/ist.h>
+#include <asm/vmi.h>
+#include <setup_arch.h>
+#include <asm/bios_ebda.h>
+#include <asm/cacheflush.h>
+#include <asm/processor.h>
+#include <asm/bugs.h>
+
+#include <asm/system.h>
+#include <asm/vsyscall.h>
 #include <asm/smp.h>
+#include <asm/desc.h>
+#include <asm/dma.h>
+#include <asm/gart.h>
+#include <asm/mmu_context.h>
+#include <asm/proto.h>
+
+#include <mach_apic.h>
+#include <asm/paravirt.h>
+
 #include <asm/percpu.h>
 #include <asm/sections.h>
-#include <asm/processor.h>
-#include <asm/setup.h>
 #include <asm/topology.h>
-#include <asm/mpspec.h>
 #include <asm/apicdef.h>
+#ifdef CONFIG_X86_64
+#include <asm/numa_64.h>
+#endif
 
-#ifdef CONFIG_X86_LOCAL_APIC
-unsigned int num_processors;
-unsigned disabled_cpus __cpuinitdata;
-/* Processor that is doing the boot up */
-unsigned int boot_cpu_physical_apicid = -1U;
-EXPORT_SYMBOL(boot_cpu_physical_apicid);
+#ifndef ARCH_SETUP
+#define ARCH_SETUP
+#endif
+
+#ifndef CONFIG_DEBUG_BOOT_PARAMS
+struct boot_params __initdata boot_params;
+#else
+struct boot_params boot_params;
+#endif
+
+/*
+ * Machine setup..
+ */
+static struct resource data_resource = {
+       .name   = "Kernel data",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource code_resource = {
+       .name   = "Kernel code",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+static struct resource bss_resource = {
+       .name   = "Kernel bss",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+
+#ifdef CONFIG_X86_32
+/* This value is set up by the early boot code to point to the value
+   immediately after the boot time page tables.  It contains a *physical*
+   address, and must not be in the .bss segment! */
+unsigned long init_pg_tables_start __initdata = ~0UL;
+unsigned long init_pg_tables_end __initdata = ~0UL;
+
+static struct resource video_ram_resource = {
+       .name   = "Video RAM area",
+       .start  = 0xa0000,
+       .end    = 0xbffff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
+};
+
+/* cpu data as detected by the assembly code in head.S */
+struct cpuinfo_x86 new_cpu_data __cpuinitdata = {0, 0, 0, 0, -1, 1, 0, 0, -1};
+/* common cpu data for all cpus */
+struct cpuinfo_x86 boot_cpu_data __read_mostly = {0, 0, 0, 0, -1, 1, 0, 0, -1};
+EXPORT_SYMBOL(boot_cpu_data);
+static void set_mca_bus(int x)
+{
+#ifdef CONFIG_MCA
+       MCA_bus = x;
+#endif
+}
+
+unsigned int def_to_bigsmp;
+
+/* for MCA, but anyone else can use it if they want */
+unsigned int machine_id;
+unsigned int machine_submodel_id;
+unsigned int BIOS_revision;
+
+struct apm_info apm_info;
+EXPORT_SYMBOL(apm_info);
+
+#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
+       defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
+struct ist_info ist_info;
+EXPORT_SYMBOL(ist_info);
+#else
+struct ist_info ist_info;
+#endif
+
+#else
+struct cpuinfo_x86 boot_cpu_data __read_mostly;
+EXPORT_SYMBOL(boot_cpu_data);
+#endif
 
-DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
-EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
 
-/* Bitmask of physically existing CPUs */
-physid_mask_t phys_cpu_present_map;
+#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
+unsigned long mmu_cr4_features;
+#else
+unsigned long mmu_cr4_features = X86_CR4_PAE;
 #endif
 
-#if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_X86_SMP)
+/* Boot loader ID as an integer, for the benefit of proc_dointvec */
+int bootloader_type;
+
 /*
- * Copy data used in early init routines from the initial arrays to the
- * per cpu data areas.  These arrays then become expendable and the
- * *_early_ptr's are zeroed indicating that the static arrays are gone.
+ * Early DMI memory
  */
-static void __init setup_per_cpu_maps(void)
+int dmi_alloc_index;
+char dmi_alloc_data[DMI_MAX_DATA];
+
+/*
+ * Setup options
+ */
+struct screen_info screen_info;
+EXPORT_SYMBOL(screen_info);
+struct edid_info edid_info;
+EXPORT_SYMBOL_GPL(edid_info);
+
+extern int root_mountflags;
+
+unsigned long saved_video_mode;
+
+#define RAMDISK_IMAGE_START_MASK       0x07FF
+#define RAMDISK_PROMPT_FLAG            0x8000
+#define RAMDISK_LOAD_FLAG              0x4000
+
+static char __initdata command_line[COMMAND_LINE_SIZE];
+
+#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
+struct edd edd;
+#ifdef CONFIG_EDD_MODULE
+EXPORT_SYMBOL(edd);
+#endif
+/**
+ * copy_edd() - Copy the BIOS EDD information
+ *              from boot_params into a safe place.
+ *
+ */
+static inline void copy_edd(void)
+{
+     memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
+           sizeof(edd.mbr_signature));
+     memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
+     edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
+     edd.edd_info_nr = boot_params.eddbuf_entries;
+}
+#else
+static inline void copy_edd(void)
+{
+}
+#endif
+
+#ifdef CONFIG_BLK_DEV_INITRD
+
+#ifdef CONFIG_X86_32
+
+#define MAX_MAP_CHUNK  (NR_FIX_BTMAPS << PAGE_SHIFT)
+static void __init relocate_initrd(void)
 {
-       int cpu;
 
-       for_each_possible_cpu(cpu) {
-               per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu];
-               per_cpu(x86_bios_cpu_apicid, cpu) =
-                                               x86_bios_cpu_apicid_init[cpu];
-#ifdef CONFIG_NUMA
-               per_cpu(x86_cpu_to_node_map, cpu) =
-                                               x86_cpu_to_node_map_init[cpu];
+       u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+       u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
+       u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
+       u64 ramdisk_here;
+       unsigned long slop, clen, mapaddr;
+       char *p, *q;
+
+       /* We need to move the initrd down into lowmem */
+       ramdisk_here = find_e820_area(0, end_of_lowmem, ramdisk_size,
+                                        PAGE_SIZE);
+
+       if (ramdisk_here == -1ULL)
+               panic("Cannot find place for new RAMDISK of size %lld\n",
+                        ramdisk_size);
+
+       /* Note: this includes all the lowmem currently occupied by
+          the initrd, we rely on that fact to keep the data intact. */
+       reserve_early(ramdisk_here, ramdisk_here + ramdisk_size,
+                        "NEW RAMDISK");
+       initrd_start = ramdisk_here + PAGE_OFFSET;
+       initrd_end   = initrd_start + ramdisk_size;
+       printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
+                        ramdisk_here, ramdisk_here + ramdisk_size);
+
+       q = (char *)initrd_start;
+
+       /* Copy any lowmem portion of the initrd */
+       if (ramdisk_image < end_of_lowmem) {
+               clen = end_of_lowmem - ramdisk_image;
+               p = (char *)__va(ramdisk_image);
+               memcpy(q, p, clen);
+               q += clen;
+               ramdisk_image += clen;
+               ramdisk_size  -= clen;
+       }
+
+       /* Copy the highmem portion of the initrd */
+       while (ramdisk_size) {
+               slop = ramdisk_image & ~PAGE_MASK;
+               clen = ramdisk_size;
+               if (clen > MAX_MAP_CHUNK-slop)
+                       clen = MAX_MAP_CHUNK-slop;
+               mapaddr = ramdisk_image & PAGE_MASK;
+               p = early_ioremap(mapaddr, clen+slop);
+               memcpy(q, p+slop, clen);
+               early_iounmap(p, clen+slop);
+               q += clen;
+               ramdisk_image += clen;
+               ramdisk_size  -= clen;
+       }
+       /* high pages is not converted by early_res_to_bootmem */
+       ramdisk_image = boot_params.hdr.ramdisk_image;
+       ramdisk_size  = boot_params.hdr.ramdisk_size;
+       printk(KERN_INFO "Move RAMDISK from %016llx - %016llx to"
+               " %08llx - %08llx\n",
+               ramdisk_image, ramdisk_image + ramdisk_size - 1,
+               ramdisk_here, ramdisk_here + ramdisk_size - 1);
+}
 #endif
+
+static void __init reserve_initrd(void)
+{
+       u64 ramdisk_image = boot_params.hdr.ramdisk_image;
+       u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
+       u64 ramdisk_end   = ramdisk_image + ramdisk_size;
+       u64 end_of_lowmem = max_low_pfn << PAGE_SHIFT;
+
+       if (!boot_params.hdr.type_of_loader ||
+           !ramdisk_image || !ramdisk_size)
+               return;         /* No initrd provided by bootloader */
+
+       initrd_start = 0;
+
+       if (ramdisk_size >= (end_of_lowmem>>1)) {
+               free_early(ramdisk_image, ramdisk_end);
+               printk(KERN_ERR "initrd too large to handle, "
+                      "disabling initrd\n");
+               return;
+       }
+
+       printk(KERN_INFO "RAMDISK: %08llx - %08llx\n", ramdisk_image,
+                       ramdisk_end);
+
+
+       if (ramdisk_end <= end_of_lowmem) {
+               /* All in lowmem, easy case */
+               /*
+                * don't need to reserve again, already reserved early
+                * in i386_start_kernel
+                */
+               initrd_start = ramdisk_image + PAGE_OFFSET;
+               initrd_end = initrd_start + ramdisk_size;
+               return;
        }
 
-       /* indicate the early static arrays will soon be gone */
-       x86_cpu_to_apicid_early_ptr = NULL;
-       x86_bios_cpu_apicid_early_ptr = NULL;
-#ifdef CONFIG_NUMA
-       x86_cpu_to_node_map_early_ptr = NULL;
+#ifdef CONFIG_X86_32
+       relocate_initrd();
+#else
+       printk(KERN_ERR "initrd extends beyond end of memory "
+              "(0x%08llx > 0x%08llx)\ndisabling initrd\n",
+              ramdisk_end, end_of_lowmem);
+       initrd_start = 0;
 #endif
+       free_early(ramdisk_image, ramdisk_end);
 }
+#else
+static void __init reserve_initrd(void)
+{
+}
+#endif /* CONFIG_BLK_DEV_INITRD */
+
+static void __init parse_setup_data(void)
+{
+       struct setup_data *data;
+       u64 pa_data;
+
+       if (boot_params.hdr.version < 0x0209)
+               return;
+       pa_data = boot_params.hdr.setup_data;
+       while (pa_data) {
+               data = early_ioremap(pa_data, PAGE_SIZE);
+               switch (data->type) {
+               case SETUP_E820_EXT:
+                       parse_e820_ext(data, pa_data);
+                       break;
+               default:
+                       break;
+               }
+               pa_data = data->next;
+               early_iounmap(data, PAGE_SIZE);
+       }
+}
+
+static void __init e820_reserve_setup_data(void)
+{
+       struct setup_data *data;
+       u64 pa_data;
+       int found = 0;
+
+       if (boot_params.hdr.version < 0x0209)
+               return;
+       pa_data = boot_params.hdr.setup_data;
+       while (pa_data) {
+               data = early_ioremap(pa_data, sizeof(*data));
+               e820_update_range(pa_data, sizeof(*data)+data->len,
+                        E820_RAM, E820_RESERVED_KERN);
+               found = 1;
+               pa_data = data->next;
+               early_iounmap(data, sizeof(*data));
+       }
+       if (!found)
+               return;
 
-#ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP
-cpumask_t *cpumask_of_cpu_map __read_mostly;
-EXPORT_SYMBOL(cpumask_of_cpu_map);
+       sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+       memcpy(&e820_saved, &e820, sizeof(struct e820map));
+       printk(KERN_INFO "extended physical RAM map:\n");
+       e820_print_map("reserve setup_data");
+}
 
-/* requires nr_cpu_ids to be initialized */
-static void __init setup_cpumask_of_cpu(void)
+static void __init reserve_early_setup_data(void)
 {
-       int i;
+       struct setup_data *data;
+       u64 pa_data;
+       char buf[32];
+
+       if (boot_params.hdr.version < 0x0209)
+               return;
+       pa_data = boot_params.hdr.setup_data;
+       while (pa_data) {
+               data = early_ioremap(pa_data, sizeof(*data));
+               sprintf(buf, "setup data %x", data->type);
+               reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
+               pa_data = data->next;
+               early_iounmap(data, sizeof(*data));
+       }
+}
+
+/*
+ * --------- Crashkernel reservation ------------------------------
+ */
+
+#ifdef CONFIG_KEXEC
+
+/**
+ * Reserve @size bytes of crashkernel memory at any suitable offset.
+ *
+ * @size: Size of the crashkernel memory to reserve.
+ * Returns the base address on success, and -1ULL on failure.
+ */
+unsigned long long find_and_reserve_crashkernel(unsigned long long size)
+{
+       const unsigned long long alignment = 16<<20;    /* 16M */
+       unsigned long long start = 0LL;
+
+       while (1) {
+               int ret;
+
+               start = find_e820_area(start, ULONG_MAX, size, alignment);
+               if (start == -1ULL)
+                       return start;
+
+               /* try to reserve it */
+               ret = reserve_bootmem_generic(start, size, BOOTMEM_EXCLUSIVE);
+               if (ret >= 0)
+                       return start;
+
+               start += alignment;
+       }
+}
 
-       /* alloc_bootmem zeroes memory */
-       cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids);
-       for (i = 0; i < nr_cpu_ids; i++)
-               cpu_set(i, cpumask_of_cpu_map[i]);
+static inline unsigned long long get_total_mem(void)
+{
+       unsigned long long total;
+
+       total = max_low_pfn - min_low_pfn;
+#ifdef CONFIG_HIGHMEM
+       total += highend_pfn - highstart_pfn;
+#endif
+
+       return total << PAGE_SHIFT;
+}
+
+static void __init reserve_crashkernel(void)
+{
+       unsigned long long total_mem;
+       unsigned long long crash_size, crash_base;
+       int ret;
+
+       total_mem = get_total_mem();
+
+       ret = parse_crashkernel(boot_command_line, total_mem,
+                       &crash_size, &crash_base);
+       if (ret != 0 || crash_size <= 0)
+               return;
+
+       /* 0 means: find the address automatically */
+       if (crash_base <= 0) {
+               crash_base = find_and_reserve_crashkernel(crash_size);
+               if (crash_base == -1ULL) {
+                       pr_info("crashkernel reservation failed. "
+                               "No suitable area found.\n");
+                       return;
+               }
+       } else {
+               ret = reserve_bootmem_generic(crash_base, crash_size,
+                                       BOOTMEM_EXCLUSIVE);
+               if (ret < 0) {
+                       pr_info("crashkernel reservation failed - "
+                               "memory is in use\n");
+                       return;
+               }
+       }
+
+       printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
+                       "for crashkernel (System RAM: %ldMB)\n",
+                       (unsigned long)(crash_size >> 20),
+                       (unsigned long)(crash_base >> 20),
+                       (unsigned long)(total_mem >> 20));
+
+       crashk_res.start = crash_base;
+       crashk_res.end   = crash_base + crash_size - 1;
+       insert_resource(&iomem_resource, &crashk_res);
 }
 #else
-static inline void setup_cpumask_of_cpu(void) { }
+static void __init reserve_crashkernel(void)
+{
+}
 #endif
 
-#ifdef CONFIG_X86_32
-/*
- * Great future not-so-futuristic plan: make i386 and x86_64 do it
- * the same way
+static struct resource standard_io_resources[] = {
+       { .name = "dma1", .start = 0x00, .end = 0x1f,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "pic1", .start = 0x20, .end = 0x21,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "timer0", .start = 0x40, .end = 0x43,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "timer1", .start = 0x50, .end = 0x53,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "keyboard", .start = 0x60, .end = 0x60,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "keyboard", .start = 0x64, .end = 0x64,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "dma page reg", .start = 0x80, .end = 0x8f,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "pic2", .start = 0xa0, .end = 0xa1,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "dma2", .start = 0xc0, .end = 0xdf,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
+       { .name = "fpu", .start = 0xf0, .end = 0xff,
+               .flags = IORESOURCE_BUSY | IORESOURCE_IO }
+};
+
+static void __init reserve_standard_io_resources(void)
+{
+       int i;
+
+       /* request I/O space for devices used on all i[345]86 PCs */
+       for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
+               request_resource(&ioport_resource, &standard_io_resources[i]);
+
+}
+
+#ifdef CONFIG_PROC_VMCORE
+/* elfcorehdr= specifies the location of elf core header
+ * stored by the crashed kernel. This option will be passed
+ * by kexec loader to the capture kernel.
  */
-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
-EXPORT_SYMBOL(__per_cpu_offset);
+static int __init setup_elfcorehdr(char *arg)
+{
+       char *end;
+       if (!arg)
+               return -EINVAL;
+       elfcorehdr_addr = memparse(arg, &end);
+       return end > arg ? 0 : -EINVAL;
+}
+early_param("elfcorehdr", setup_elfcorehdr);
 #endif
 
 /*
- * Great future plan:
- * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
- * Always point %gs to its beginning
+ * Determine if we were loaded by an EFI loader.  If so, then we have also been
+ * passed the efi memmap, systab, etc., so we should use these data structures
+ * for initialization.  Note, the efi init code path is determined by the
+ * global efi_enabled. This allows the same kernel image to be used on existing
+ * systems (with a traditional BIOS) as well as on EFI systems.
  */
-void __init setup_per_cpu_areas(void)
+/*
+ * setup_arch - architecture-specific boot-time initializations
+ *
+ * Note: On x86_64, fixmaps are ready for use even before this is called.
+ */
+
+void __init setup_arch(char **cmdline_p)
 {
-       int i, highest_cpu = 0;
-       unsigned long size;
+#ifdef CONFIG_X86_32
+       memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
+       visws_early_detect();
+       pre_setup_arch_hook();
+       early_cpu_init();
+#else
+       printk(KERN_INFO "Command line: %s\n", boot_command_line);
+#endif
 
-#ifdef CONFIG_HOTPLUG_CPU
-       prefill_possible_map();
+       early_ioremap_init();
+
+       ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
+       screen_info = boot_params.screen_info;
+       edid_info = boot_params.edid_info;
+#ifdef CONFIG_X86_32
+       apm_info.bios = boot_params.apm_bios_info;
+       ist_info = boot_params.ist_info;
+       if (boot_params.sys_desc_table.length != 0) {
+               set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
+               machine_id = boot_params.sys_desc_table.table[0];
+               machine_submodel_id = boot_params.sys_desc_table.table[1];
+               BIOS_revision = boot_params.sys_desc_table.table[2];
+       }
+#endif
+       saved_video_mode = boot_params.hdr.vid_mode;
+       bootloader_type = boot_params.hdr.type_of_loader;
+
+#ifdef CONFIG_BLK_DEV_RAM
+       rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
+       rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
+       rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
 #endif
+#ifdef CONFIG_EFI
+       if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
+#ifdef CONFIG_X86_32
+                    "EL32",
+#else
+                    "EL64",
+#endif
+        4)) {
+               efi_enabled = 1;
+               efi_reserve_early();
+       }
+#endif
+
+       ARCH_SETUP
 
-       /* Copy section for each CPU (we discard the original) */
-       size = PERCPU_ENOUGH_ROOM;
-       printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
-                         size);
+       setup_memory_map();
+       parse_setup_data();
+       /* update the e820_saved too */
+       e820_reserve_setup_data();
 
-       for_each_possible_cpu(i) {
-               char *ptr;
-#ifndef CONFIG_NEED_MULTIPLE_NODES
-               ptr = alloc_bootmem_pages(size);
+       copy_edd();
+
+       if (!boot_params.hdr.root_flags)
+               root_mountflags &= ~MS_RDONLY;
+       init_mm.start_code = (unsigned long) _text;
+       init_mm.end_code = (unsigned long) _etext;
+       init_mm.end_data = (unsigned long) _edata;
+#ifdef CONFIG_X86_32
+       init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
 #else
-               int node = early_cpu_to_node(i);
-               if (!node_online(node) || !NODE_DATA(node)) {
-                       ptr = alloc_bootmem_pages(size);
-                       printk(KERN_INFO
-                              "cpu %d has no node or node-local memory\n", i);
-               }
-               else
-                       ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
+       init_mm.brk = (unsigned long) &_end;
 #endif
-               if (!ptr)
-                       panic("Cannot allocate cpu data for CPU %d\n", i);
+
+       code_resource.start = virt_to_phys(_text);
+       code_resource.end = virt_to_phys(_etext)-1;
+       data_resource.start = virt_to_phys(_etext);
+       data_resource.end = virt_to_phys(_edata)-1;
+       bss_resource.start = virt_to_phys(&__bss_start);
+       bss_resource.end = virt_to_phys(&__bss_stop)-1;
+
 #ifdef CONFIG_X86_64
-               cpu_pda(i)->data_offset = ptr - __per_cpu_start;
+       early_cpu_init();
+#endif
+       strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+       *cmdline_p = command_line;
+
+       parse_early_param();
+
+       /* after early param, so could get panic from serial */
+       reserve_early_setup_data();
+
+       if (acpi_mps_check()) {
+#ifdef CONFIG_X86_LOCAL_APIC
+               disable_apic = 1;
+#endif
+               clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
+       }
+
+       finish_e820_parsing();
+
+#ifdef CONFIG_X86_32
+       probe_roms();
+#endif
+
+       /* after parse_early_param, so could debug it */
+       insert_resource(&iomem_resource, &code_resource);
+       insert_resource(&iomem_resource, &data_resource);
+       insert_resource(&iomem_resource, &bss_resource);
+
+       if (efi_enabled)
+               efi_init();
+
+#ifdef CONFIG_X86_32
+       if (ppro_with_ram_bug()) {
+               e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
+                                 E820_RESERVED);
+               sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+               printk(KERN_INFO "fixed physical RAM map:\n");
+               e820_print_map("bad_ppro");
+       }
+#else
+       early_gart_iommu_check();
+#endif
+
+       /*
+        * partially used pages are not usable - thus
+        * we are rounding upwards:
+        */
+       max_pfn = e820_end_of_ram_pfn();
+
+       /* preallocate 4k for mptable mpc */
+       early_reserve_e820_mpc_new();
+       /* update e820 for memory not covered by WB MTRRs */
+       mtrr_bp_init();
+       if (mtrr_trim_uncached_memory(max_pfn))
+               max_pfn = e820_end_of_ram_pfn();
+
+#ifdef CONFIG_X86_32
+       /* max_low_pfn get updated here */
+       find_low_pfn_range();
 #else
-               __per_cpu_offset[i] = ptr - __per_cpu_start;
+       num_physpages = max_pfn;
+
+       check_efer();
+
+       /* How many end-of-memory variables you have, grandma! */
+       /* need this before calling reserve_initrd */
+       if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
+               max_low_pfn = e820_end_of_low_ram_pfn();
+       else
+               max_low_pfn = max_pfn;
+
+       high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
 #endif
-               memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
 
-               highest_cpu = i;
+       /* max_pfn_mapped is updated here */
+       max_low_pfn_mapped = init_memory_mapping(0, max_low_pfn<<PAGE_SHIFT);
+       max_pfn_mapped = max_low_pfn_mapped;
+
+#ifdef CONFIG_X86_64
+       if (max_pfn > max_low_pfn) {
+               max_pfn_mapped = init_memory_mapping(1UL<<32,
+                                                    max_pfn<<PAGE_SHIFT);
+               /* can we preseve max_low_pfn ?*/
+               max_low_pfn = max_pfn;
        }
+#endif
+
+       /*
+        * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
+        */
 
-       nr_cpu_ids = highest_cpu + 1;
-       printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d\n", NR_CPUS, nr_cpu_ids);
+#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
+       if (init_ohci1394_dma_early)
+               init_ohci1394_dma_on_all_controllers();
+#endif
 
-       /* Setup percpu data maps */
-       setup_per_cpu_maps();
+       reserve_initrd();
 
-       /* Setup cpumask_of_cpu map */
-       setup_cpumask_of_cpu();
-}
+#ifdef CONFIG_X86_64
+       vsmp_init();
+#endif
+
+       dmi_scan_machine();
+
+       io_delay_init();
+
+       /*
+        * Parse the ACPI tables for possible boot-time SMP configuration.
+        */
+       acpi_boot_table_init();
+
+#ifdef CONFIG_ACPI_NUMA
+       /*
+        * Parse SRAT to discover nodes.
+        */
+       acpi_numa_init();
+#endif
+
+       initmem_init(0, max_pfn);
+
+#ifdef CONFIG_X86_64
+       dma32_reserve_bootmem();
+#endif
 
+#ifdef CONFIG_ACPI_SLEEP
+       /*
+        * Reserve low memory region for sleep support.
+        */
+       acpi_reserve_bootmem();
+#endif
+#ifdef CONFIG_X86_FIND_SMP_CONFIG
+       /*
+        * Find and reserve possible boot-time SMP configuration:
+        */
+       find_smp_config();
 #endif
+       reserve_crashkernel();
+
+       reserve_ibft_region();
+
+#ifdef CONFIG_KVM_CLOCK
+       kvmclock_init();
+#endif
+
+#if defined(CONFIG_VMI) && defined(CONFIG_X86_32)
+       /*
+        * Must be after max_low_pfn is determined, and before kernel
+        * pagetables are setup.
+        */
+       vmi_init();
+#endif
+
+       paging_init();
+
+#ifdef CONFIG_X86_64
+       map_vsyscall();
+#endif
+
+#ifdef CONFIG_X86_GENERICARCH
+       generic_apic_probe();
+#endif
+
+       early_quirks();
+
+       /*
+        * Read APIC and some other early information from ACPI tables.
+        */
+       acpi_boot_init();
+
+#if defined(CONFIG_X86_MPPARSE) || defined(CONFIG_X86_VISWS)
+       /*
+        * get boot-time SMP configuration:
+        */
+       if (smp_found_config)
+               get_smp_config();
+#endif
+
+       prefill_possible_map();
+#ifdef CONFIG_X86_64
+       init_cpu_to_node();
+#endif
+
+#ifdef CONFIG_X86_NUMAQ
+       /*
+        * need to check online nodes num, call it
+        * here before time_init/tsc_init
+        */
+       numaq_tsc_disable();
+#endif
+
+       init_apic_mappings();
+       ioapic_init_mappings();
+
+#if defined(CONFIG_SMP) && defined(CONFIG_X86_PC) && defined(CONFIG_X86_32)
+       if (def_to_bigsmp)
+               printk(KERN_WARNING "More than 8 CPUs detected and "
+                       "CONFIG_X86_PC cannot handle it.\nUse "
+                       "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
+#endif
+       kvm_guest_init();
+
+       e820_reserve_resources();
+       e820_mark_nosave_regions(max_low_pfn);
+
+#ifdef CONFIG_X86_32
+       request_resource(&iomem_resource, &video_ram_resource);
+#endif
+       reserve_standard_io_resources();
+
+       e820_setup_gap();
+
+#ifdef CONFIG_VT
+#if defined(CONFIG_VGA_CONSOLE)
+       if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
+               conswitchp = &vga_con;
+#elif defined(CONFIG_DUMMY_CONSOLE)
+       conswitchp = &dummy_con;
+#endif
+#endif
+}
diff --git a/arch/x86/kernel/setup64.c b/arch/x86/kernel/setup64.c
deleted file mode 100644 (file)
index aee0e82..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-/* 
- * X86-64 specific CPU setup.
- * Copyright (C) 1995  Linus Torvalds
- * Copyright 2001, 2002, 2003 SuSE Labs / Andi Kleen.
- * See setup.c for older changelog.
- */ 
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/string.h>
-#include <linux/bootmem.h>
-#include <linux/bitops.h>
-#include <linux/module.h>
-#include <linux/kgdb.h>
-#include <asm/pda.h>
-#include <asm/pgtable.h>
-#include <asm/processor.h>
-#include <asm/desc.h>
-#include <asm/atomic.h>
-#include <asm/mmu_context.h>
-#include <asm/smp.h>
-#include <asm/i387.h>
-#include <asm/percpu.h>
-#include <asm/proto.h>
-#include <asm/sections.h>
-#include <asm/setup.h>
-#include <asm/genapic.h>
-
-#ifndef CONFIG_DEBUG_BOOT_PARAMS
-struct boot_params __initdata boot_params;
-#else
-struct boot_params boot_params;
-#endif
-
-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
-
-struct x8664_pda *_cpu_pda[NR_CPUS] __read_mostly;
-EXPORT_SYMBOL(_cpu_pda);
-struct x8664_pda boot_cpu_pda[NR_CPUS] __cacheline_aligned;
-
-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
-
-char boot_cpu_stack[IRQSTACKSIZE] __attribute__((section(".bss.page_aligned")));
-
-unsigned long __supported_pte_mask __read_mostly = ~0UL;
-EXPORT_SYMBOL_GPL(__supported_pte_mask);
-
-static int do_not_nx __cpuinitdata = 0;
-
-/* noexec=on|off
-Control non executable mappings for 64bit processes.
-
-on     Enable(default)
-off    Disable
-*/ 
-static int __init nonx_setup(char *str)
-{
-       if (!str)
-               return -EINVAL;
-       if (!strncmp(str, "on", 2)) {
-                __supported_pte_mask |= _PAGE_NX; 
-               do_not_nx = 0; 
-       } else if (!strncmp(str, "off", 3)) {
-               do_not_nx = 1;
-               __supported_pte_mask &= ~_PAGE_NX;
-        }
-       return 0;
-} 
-early_param("noexec", nonx_setup);
-
-int force_personality32 = 0; 
-
-/* noexec32=on|off
-Control non executable heap for 32bit processes.
-To control the stack too use noexec=off
-
-on     PROT_READ does not imply PROT_EXEC for 32bit processes (default)
-off    PROT_READ implies PROT_EXEC
-*/
-static int __init nonx32_setup(char *str)
-{
-       if (!strcmp(str, "on"))
-               force_personality32 &= ~READ_IMPLIES_EXEC;
-       else if (!strcmp(str, "off"))
-               force_personality32 |= READ_IMPLIES_EXEC;
-       return 1;
-}
-__setup("noexec32=", nonx32_setup);
-
-void pda_init(int cpu)
-{ 
-       struct x8664_pda *pda = cpu_pda(cpu);
-
-       /* Setup up data that may be needed in __get_free_pages early */
-       asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0)); 
-       /* Memory clobbers used to order PDA accessed */
-       mb();
-       wrmsrl(MSR_GS_BASE, pda);
-       mb();
-
-       pda->cpunumber = cpu; 
-       pda->irqcount = -1;
-       pda->kernelstack = 
-               (unsigned long)stack_thread_info() - PDA_STACKOFFSET + THREAD_SIZE; 
-       pda->active_mm = &init_mm;
-       pda->mmu_state = 0;
-
-       if (cpu == 0) {
-               /* others are initialized in smpboot.c */
-               pda->pcurrent = &init_task;
-               pda->irqstackptr = boot_cpu_stack; 
-       } else {
-               pda->irqstackptr = (char *)
-                       __get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER);
-               if (!pda->irqstackptr)
-                       panic("cannot allocate irqstack for cpu %d", cpu); 
-       }
-
-
-       pda->irqstackptr += IRQSTACKSIZE-64;
-} 
-
-char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]
-__attribute__((section(".bss.page_aligned")));
-
-extern asmlinkage void ignore_sysret(void);
-
-/* May not be marked __init: used by software suspend */
-void syscall_init(void)
-{
-       /* 
-        * LSTAR and STAR live in a bit strange symbiosis.
-        * They both write to the same internal register. STAR allows to set CS/DS
-        * but only a 32bit target. LSTAR sets the 64bit rip.    
-        */ 
-       wrmsrl(MSR_STAR,  ((u64)__USER32_CS)<<48  | ((u64)__KERNEL_CS)<<32); 
-       wrmsrl(MSR_LSTAR, system_call); 
-       wrmsrl(MSR_CSTAR, ignore_sysret);
-
-#ifdef CONFIG_IA32_EMULATION                   
-       syscall32_cpu_init ();
-#endif
-
-       /* Flags to clear on syscall */
-       wrmsrl(MSR_SYSCALL_MASK,
-              X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
-}
-
-void __cpuinit check_efer(void)
-{
-       unsigned long efer;
-
-       rdmsrl(MSR_EFER, efer); 
-        if (!(efer & EFER_NX) || do_not_nx) { 
-                __supported_pte_mask &= ~_PAGE_NX; 
-        }       
-}
-
-unsigned long kernel_eflags;
-
-/*
- * Copies of the original ist values from the tss are only accessed during
- * debugging, no special alignment required.
- */
-DEFINE_PER_CPU(struct orig_ist, orig_ist);
-
-/*
- * cpu_init() initializes state that is per-CPU. Some data is already
- * initialized (naturally) in the bootstrap process, such as the GDT
- * and IDT. We reload them nevertheless, this function acts as a
- * 'CPU state barrier', nothing should get across.
- * A lot of state is already set up in PDA init.
- */
-void __cpuinit cpu_init (void)
-{
-       int cpu = stack_smp_processor_id();
-       struct tss_struct *t = &per_cpu(init_tss, cpu);
-       struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
-       unsigned long v; 
-       char *estacks = NULL; 
-       struct task_struct *me;
-       int i;
-
-       /* CPU 0 is initialised in head64.c */
-       if (cpu != 0) {
-               pda_init(cpu);
-       } else 
-               estacks = boot_exception_stacks; 
-
-       me = current;
-
-       if (cpu_test_and_set(cpu, cpu_initialized))
-               panic("CPU#%d already initialized!\n", cpu);
-
-       printk("Initializing CPU#%d\n", cpu);
-
-       clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
-
-       /*
-        * Initialize the per-CPU GDT with the boot GDT,
-        * and set up the GDT descriptor:
-        */
-       if (cpu)
-               memcpy(get_cpu_gdt_table(cpu), cpu_gdt_table, GDT_SIZE);
-
-       cpu_gdt_descr[cpu].size = GDT_SIZE;
-       load_gdt((const struct desc_ptr *)&cpu_gdt_descr[cpu]);
-       load_idt((const struct desc_ptr *)&idt_descr);
-
-       memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
-       syscall_init();
-
-       wrmsrl(MSR_FS_BASE, 0);
-       wrmsrl(MSR_KERNEL_GS_BASE, 0);
-       barrier(); 
-
-       check_efer();
-
-       /*
-        * set up and load the per-CPU TSS
-        */
-       for (v = 0; v < N_EXCEPTION_STACKS; v++) {
-               static const unsigned int order[N_EXCEPTION_STACKS] = {
-                       [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
-                       [DEBUG_STACK - 1] = DEBUG_STACK_ORDER
-               };
-               if (cpu) {
-                       estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
-                       if (!estacks)
-                               panic("Cannot allocate exception stack %ld %d\n",
-                                     v, cpu); 
-               }
-               estacks += PAGE_SIZE << order[v];
-               orig_ist->ist[v] = t->x86_tss.ist[v] = (unsigned long)estacks;
-       }
-
-       t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
-       /*
-        * <= is required because the CPU will access up to
-        * 8 bits beyond the end of the IO permission bitmap.
-        */
-       for (i = 0; i <= IO_BITMAP_LONGS; i++)
-               t->io_bitmap[i] = ~0UL;
-
-       atomic_inc(&init_mm.mm_count);
-       me->active_mm = &init_mm;
-       if (me->mm)
-               BUG();
-       enter_lazy_tlb(&init_mm, me);
-
-       set_tss_desc(cpu, t);
-       load_TR_desc();
-       load_LDT(&init_mm.context);
-
-#ifdef CONFIG_KGDB
-       /*
-        * If the kgdb is connected no debug regs should be altered.  This
-        * is only applicable when KGDB and a KGDB I/O module are built
-        * into the kernel and you are using early debugging with
-        * kgdbwait. KGDB will control the kernel HW breakpoint registers.
-        */
-       if (kgdb_connected && arch_kgdb_ops.correct_hw_break)
-               arch_kgdb_ops.correct_hw_break();
-       else {
-#endif
-       /*
-        * Clear all 6 debug registers:
-        */
-
-       set_debugreg(0UL, 0);
-       set_debugreg(0UL, 1);
-       set_debugreg(0UL, 2);
-       set_debugreg(0UL, 3);
-       set_debugreg(0UL, 6);
-       set_debugreg(0UL, 7);
-#ifdef CONFIG_KGDB
-       /* If the kgdb is connected no debug regs should be altered. */
-       }
-#endif
-
-       fpu_init(); 
-
-       raw_local_save_flags(kernel_eflags);
-
-       if (is_uv_system())
-               uv_cpu_init();
-}
diff --git a/arch/x86/kernel/setup_32.c b/arch/x86/kernel/setup_32.c
deleted file mode 100644 (file)
index 5a2f8e0..0000000
+++ /dev/null
@@ -1,964 +0,0 @@
-/*
- *  Copyright (C) 1995  Linus Torvalds
- *
- *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
- *
- *  Memory region support
- *     David Parsons <orc@pell.chi.il.us>, July-August 1999
- *
- *  Added E820 sanitization routine (removes overlapping memory regions);
- *  Brian Moyle <bmoyle@mvista.com>, February 2001
- *
- * Moved CPU detection code to cpu/${cpu}.c
- *    Patrick Mochel <mochel@osdl.org>, March 2002
- *
- *  Provisions for empty E820 memory regions (reported by certain BIOSes).
- *  Alex Achenbach <xela@slit.de>, December 2002.
- *
- */
-
-/*
- * This file handles the architecture-dependent parts of initialization
- */
-
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/mmzone.h>
-#include <linux/screen_info.h>
-#include <linux/ioport.h>
-#include <linux/acpi.h>
-#include <linux/apm_bios.h>
-#include <linux/initrd.h>
-#include <linux/bootmem.h>
-#include <linux/seq_file.h>
-#include <linux/console.h>
-#include <linux/mca.h>
-#include <linux/root_dev.h>
-#include <linux/highmem.h>
-#include <linux/module.h>
-#include <linux/efi.h>
-#include <linux/init.h>
-#include <linux/edd.h>
-#include <linux/iscsi_ibft.h>
-#include <linux/nodemask.h>
-#include <linux/kexec.h>
-#include <linux/crash_dump.h>
-#include <linux/dmi.h>
-#include <linux/pfn.h>
-#include <linux/pci.h>
-#include <linux/init_ohci1394_dma.h>
-#include <linux/kvm_para.h>
-
-#include <video/edid.h>
-
-#include <asm/mtrr.h>
-#include <asm/apic.h>
-#include <asm/e820.h>
-#include <asm/mpspec.h>
-#include <asm/mmzone.h>
-#include <asm/setup.h>
-#include <asm/arch_hooks.h>
-#include <asm/sections.h>
-#include <asm/io_apic.h>
-#include <asm/ist.h>
-#include <asm/io.h>
-#include <asm/vmi.h>
-#include <setup_arch.h>
-#include <asm/bios_ebda.h>
-#include <asm/cacheflush.h>
-#include <asm/processor.h>
-
-/* This value is set up by the early boot code to point to the value
-   immediately after the boot time page tables.  It contains a *physical*
-   address, and must not be in the .bss segment! */
-unsigned long init_pg_tables_end __initdata = ~0UL;
-
-/*
- * Machine setup..
- */
-static struct resource data_resource = {
-       .name   = "Kernel data",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-static struct resource code_resource = {
-       .name   = "Kernel code",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-static struct resource bss_resource = {
-       .name   = "Kernel bss",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-static struct resource video_ram_resource = {
-       .name   = "Video RAM area",
-       .start  = 0xa0000,
-       .end    = 0xbffff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_MEM
-};
-
-static struct resource standard_io_resources[] = { {
-       .name   = "dma1",
-       .start  = 0x0000,
-       .end    = 0x001f,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "pic1",
-       .start  = 0x0020,
-       .end    = 0x0021,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "timer0",
-       .start  = 0x0040,
-       .end    = 0x0043,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "timer1",
-       .start  = 0x0050,
-       .end    = 0x0053,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "keyboard",
-       .start  = 0x0060,
-       .end    = 0x0060,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "keyboard",
-       .start  = 0x0064,
-       .end    = 0x0064,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "dma page reg",
-       .start  = 0x0080,
-       .end    = 0x008f,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "pic2",
-       .start  = 0x00a0,
-       .end    = 0x00a1,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "dma2",
-       .start  = 0x00c0,
-       .end    = 0x00df,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-}, {
-       .name   = "fpu",
-       .start  = 0x00f0,
-       .end    = 0x00ff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_IO
-} };
-
-/* cpu data as detected by the assembly code in head.S */
-struct cpuinfo_x86 new_cpu_data __cpuinitdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
-/* common cpu data for all cpus */
-struct cpuinfo_x86 boot_cpu_data __read_mostly = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
-EXPORT_SYMBOL(boot_cpu_data);
-
-unsigned int def_to_bigsmp;
-
-#ifndef CONFIG_X86_PAE
-unsigned long mmu_cr4_features;
-#else
-unsigned long mmu_cr4_features = X86_CR4_PAE;
-#endif
-
-/* for MCA, but anyone else can use it if they want */
-unsigned int machine_id;
-unsigned int machine_submodel_id;
-unsigned int BIOS_revision;
-
-/* Boot loader ID as an integer, for the benefit of proc_dointvec */
-int bootloader_type;
-
-/* user-defined highmem size */
-static unsigned int highmem_pages = -1;
-
-/*
- * Setup options
- */
-struct screen_info screen_info;
-EXPORT_SYMBOL(screen_info);
-struct apm_info apm_info;
-EXPORT_SYMBOL(apm_info);
-struct edid_info edid_info;
-EXPORT_SYMBOL_GPL(edid_info);
-struct ist_info ist_info;
-#if defined(CONFIG_X86_SPEEDSTEP_SMI) || \
-       defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
-EXPORT_SYMBOL(ist_info);
-#endif
-
-extern void early_cpu_init(void);
-extern int root_mountflags;
-
-unsigned long saved_video_mode;
-
-#define RAMDISK_IMAGE_START_MASK       0x07FF
-#define RAMDISK_PROMPT_FLAG            0x8000
-#define RAMDISK_LOAD_FLAG              0x4000
-
-static char __initdata command_line[COMMAND_LINE_SIZE];
-
-#ifndef CONFIG_DEBUG_BOOT_PARAMS
-struct boot_params __initdata boot_params;
-#else
-struct boot_params boot_params;
-#endif
-
-#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
-struct edd edd;
-#ifdef CONFIG_EDD_MODULE
-EXPORT_SYMBOL(edd);
-#endif
-/**
- * copy_edd() - Copy the BIOS EDD information
- *              from boot_params into a safe place.
- *
- */
-static inline void copy_edd(void)
-{
-     memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
-           sizeof(edd.mbr_signature));
-     memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
-     edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
-     edd.edd_info_nr = boot_params.eddbuf_entries;
-}
-#else
-static inline void copy_edd(void)
-{
-}
-#endif
-
-int __initdata user_defined_memmap;
-
-/*
- * "mem=nopentium" disables the 4MB page tables.
- * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
- * to <mem>, overriding the bios size.
- * "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
- * <start> to <start>+<mem>, overriding the bios size.
- *
- * HPA tells me bootloaders need to parse mem=, so no new
- * option should be mem=  [also see Documentation/i386/boot.txt]
- */
-static int __init parse_mem(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-
-       if (strcmp(arg, "nopentium") == 0) {
-               setup_clear_cpu_cap(X86_FEATURE_PSE);
-       } else {
-               /* If the user specifies memory size, we
-                * limit the BIOS-provided memory map to
-                * that size. exactmap can be used to specify
-                * the exact map. mem=number can be used to
-                * trim the existing memory map.
-                */
-               unsigned long long mem_size;
-
-               mem_size = memparse(arg, &arg);
-               limit_regions(mem_size);
-               user_defined_memmap = 1;
-       }
-       return 0;
-}
-early_param("mem", parse_mem);
-
-#ifdef CONFIG_PROC_VMCORE
-/* elfcorehdr= specifies the location of elf core header
- * stored by the crashed kernel.
- */
-static int __init parse_elfcorehdr(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-
-       elfcorehdr_addr = memparse(arg, &arg);
-       return 0;
-}
-early_param("elfcorehdr", parse_elfcorehdr);
-#endif /* CONFIG_PROC_VMCORE */
-
-/*
- * highmem=size forces highmem to be exactly 'size' bytes.
- * This works even on boxes that have no highmem otherwise.
- * This also works to reduce highmem size on bigger boxes.
- */
-static int __init parse_highmem(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-
-       highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
-       return 0;
-}
-early_param("highmem", parse_highmem);
-
-/*
- * vmalloc=size forces the vmalloc area to be exactly 'size'
- * bytes. This can be used to increase (or decrease) the
- * vmalloc area - the default is 128m.
- */
-static int __init parse_vmalloc(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-
-       __VMALLOC_RESERVE = memparse(arg, &arg);
-       return 0;
-}
-early_param("vmalloc", parse_vmalloc);
-
-/*
- * reservetop=size reserves a hole at the top of the kernel address space which
- * a hypervisor can load into later.  Needed for dynamically loaded hypervisors,
- * so relocating the fixmap can be done before paging initialization.
- */
-static int __init parse_reservetop(char *arg)
-{
-       unsigned long address;
-
-       if (!arg)
-               return -EINVAL;
-
-       address = memparse(arg, &arg);
-       reserve_top_address(address);
-       return 0;
-}
-early_param("reservetop", parse_reservetop);
-
-/*
- * Determine low and high memory ranges:
- */
-unsigned long __init find_max_low_pfn(void)
-{
-       unsigned long max_low_pfn;
-
-       max_low_pfn = max_pfn;
-       if (max_low_pfn > MAXMEM_PFN) {
-               if (highmem_pages == -1)
-                       highmem_pages = max_pfn - MAXMEM_PFN;
-               if (highmem_pages + MAXMEM_PFN < max_pfn)
-                       max_pfn = MAXMEM_PFN + highmem_pages;
-               if (highmem_pages + MAXMEM_PFN > max_pfn) {
-                       printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
-                       highmem_pages = 0;
-               }
-               max_low_pfn = MAXMEM_PFN;
-#ifndef CONFIG_HIGHMEM
-               /* Maximum memory usable is what is directly addressable */
-               printk(KERN_WARNING "Warning only %ldMB will be used.\n",
-                                       MAXMEM>>20);
-               if (max_pfn > MAX_NONPAE_PFN)
-                       printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
-               else
-                       printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
-               max_pfn = MAXMEM_PFN;
-#else /* !CONFIG_HIGHMEM */
-#ifndef CONFIG_HIGHMEM64G
-               if (max_pfn > MAX_NONPAE_PFN) {
-                       max_pfn = MAX_NONPAE_PFN;
-                       printk(KERN_WARNING "Warning only 4GB will be used.\n");
-                       printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
-               }
-#endif /* !CONFIG_HIGHMEM64G */
-#endif /* !CONFIG_HIGHMEM */
-       } else {
-               if (highmem_pages == -1)
-                       highmem_pages = 0;
-#ifdef CONFIG_HIGHMEM
-               if (highmem_pages >= max_pfn) {
-                       printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
-                       highmem_pages = 0;
-               }
-               if (highmem_pages) {
-                       if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
-                               printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
-                               highmem_pages = 0;
-                       }
-                       max_low_pfn -= highmem_pages;
-               }
-#else
-               if (highmem_pages)
-                       printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
-#endif
-       }
-       return max_low_pfn;
-}
-
-#define BIOS_LOWMEM_KILOBYTES 0x413
-
-/*
- * The BIOS places the EBDA/XBDA at the top of conventional
- * memory, and usually decreases the reported amount of
- * conventional memory (int 0x12) too. This also contains a
- * workaround for Dell systems that neglect to reserve EBDA.
- * The same workaround also avoids a problem with the AMD768MPX
- * chipset: reserve a page before VGA to prevent PCI prefetch
- * into it (errata #56). Usually the page is reserved anyways,
- * unless you have no PS/2 mouse plugged in.
- */
-static void __init reserve_ebda_region(void)
-{
-       unsigned int lowmem, ebda_addr;
-
-       /* To determine the position of the EBDA and the */
-       /* end of conventional memory, we need to look at */
-       /* the BIOS data area. In a paravirtual environment */
-       /* that area is absent. We'll just have to assume */
-       /* that the paravirt case can handle memory setup */
-       /* correctly, without our help. */
-       if (paravirt_enabled())
-               return;
-
-       /* end of low (conventional) memory */
-       lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
-       lowmem <<= 10;
-
-       /* start of EBDA area */
-       ebda_addr = get_bios_ebda();
-
-       /* Fixup: bios puts an EBDA in the top 64K segment */
-       /* of conventional memory, but does not adjust lowmem. */
-       if ((lowmem - ebda_addr) <= 0x10000)
-               lowmem = ebda_addr;
-
-       /* Fixup: bios does not report an EBDA at all. */
-       /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
-       if ((ebda_addr == 0) && (lowmem >= 0x9f000))
-               lowmem = 0x9f000;
-
-       /* Paranoia: should never happen, but... */
-       if ((lowmem == 0) || (lowmem >= 0x100000))
-               lowmem = 0x9f000;
-
-       /* reserve all memory between lowmem and the 1MB mark */
-       reserve_bootmem(lowmem, 0x100000 - lowmem, BOOTMEM_DEFAULT);
-}
-
-#ifndef CONFIG_NEED_MULTIPLE_NODES
-static void __init setup_bootmem_allocator(void);
-static unsigned long __init setup_memory(void)
-{
-       /*
-        * partially used pages are not usable - thus
-        * we are rounding upwards:
-        */
-       min_low_pfn = PFN_UP(init_pg_tables_end);
-
-       max_low_pfn = find_max_low_pfn();
-
-#ifdef CONFIG_HIGHMEM
-       highstart_pfn = highend_pfn = max_pfn;
-       if (max_pfn > max_low_pfn) {
-               highstart_pfn = max_low_pfn;
-       }
-       printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
-               pages_to_mb(highend_pfn - highstart_pfn));
-       num_physpages = highend_pfn;
-       high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
-#else
-       num_physpages = max_low_pfn;
-       high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
-#endif
-#ifdef CONFIG_FLATMEM
-       max_mapnr = num_physpages;
-#endif
-       printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
-                       pages_to_mb(max_low_pfn));
-
-       setup_bootmem_allocator();
-
-       return max_low_pfn;
-}
-
-static void __init zone_sizes_init(void)
-{
-       unsigned long max_zone_pfns[MAX_NR_ZONES];
-       memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
-       max_zone_pfns[ZONE_DMA] =
-               virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
-       max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
-#ifdef CONFIG_HIGHMEM
-       max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
-       add_active_range(0, 0, highend_pfn);
-#else
-       add_active_range(0, 0, max_low_pfn);
-#endif
-
-       free_area_init_nodes(max_zone_pfns);
-}
-#else
-extern unsigned long __init setup_memory(void);
-extern void zone_sizes_init(void);
-#endif /* !CONFIG_NEED_MULTIPLE_NODES */
-
-static inline unsigned long long get_total_mem(void)
-{
-       unsigned long long total;
-
-       total = max_low_pfn - min_low_pfn;
-#ifdef CONFIG_HIGHMEM
-       total += highend_pfn - highstart_pfn;
-#endif
-
-       return total << PAGE_SHIFT;
-}
-
-#ifdef CONFIG_KEXEC
-static void __init reserve_crashkernel(void)
-{
-       unsigned long long total_mem;
-       unsigned long long crash_size, crash_base;
-       int ret;
-
-       total_mem = get_total_mem();
-
-       ret = parse_crashkernel(boot_command_line, total_mem,
-                       &crash_size, &crash_base);
-       if (ret == 0 && crash_size > 0) {
-               if (crash_base > 0) {
-                       printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
-                                       "for crashkernel (System RAM: %ldMB)\n",
-                                       (unsigned long)(crash_size >> 20),
-                                       (unsigned long)(crash_base >> 20),
-                                       (unsigned long)(total_mem >> 20));
-
-                       if (reserve_bootmem(crash_base, crash_size,
-                                       BOOTMEM_EXCLUSIVE) < 0) {
-                               printk(KERN_INFO "crashkernel reservation "
-                                       "failed - memory is in use\n");
-                               return;
-                       }
-
-                       crashk_res.start = crash_base;
-                       crashk_res.end   = crash_base + crash_size - 1;
-               } else
-                       printk(KERN_INFO "crashkernel reservation failed - "
-                                       "you have to specify a base address\n");
-       }
-}
-#else
-static inline void __init reserve_crashkernel(void)
-{}
-#endif
-
-#ifdef CONFIG_BLK_DEV_INITRD
-
-static bool do_relocate_initrd = false;
-
-static void __init reserve_initrd(void)
-{
-       unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
-       unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
-       unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
-       unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
-       unsigned long ramdisk_here;
-
-       initrd_start = 0;
-
-       if (!boot_params.hdr.type_of_loader ||
-           !ramdisk_image || !ramdisk_size)
-               return;         /* No initrd provided by bootloader */
-
-       if (ramdisk_end < ramdisk_image) {
-               printk(KERN_ERR "initrd wraps around end of memory, "
-                      "disabling initrd\n");
-               return;
-       }
-       if (ramdisk_size >= end_of_lowmem/2) {
-               printk(KERN_ERR "initrd too large to handle, "
-                      "disabling initrd\n");
-               return;
-       }
-       if (ramdisk_end <= end_of_lowmem) {
-               /* All in lowmem, easy case */
-               reserve_bootmem(ramdisk_image, ramdisk_size, BOOTMEM_DEFAULT);
-               initrd_start = ramdisk_image + PAGE_OFFSET;
-               initrd_end = initrd_start+ramdisk_size;
-               return;
-       }
-
-       /* We need to move the initrd down into lowmem */
-       ramdisk_here = (end_of_lowmem - ramdisk_size) & PAGE_MASK;
-
-       /* Note: this includes all the lowmem currently occupied by
-          the initrd, we rely on that fact to keep the data intact. */
-       reserve_bootmem(ramdisk_here, ramdisk_size, BOOTMEM_DEFAULT);
-       initrd_start = ramdisk_here + PAGE_OFFSET;
-       initrd_end   = initrd_start + ramdisk_size;
-
-       do_relocate_initrd = true;
-}
-
-#define MAX_MAP_CHUNK  (NR_FIX_BTMAPS << PAGE_SHIFT)
-
-static void __init relocate_initrd(void)
-{
-       unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
-       unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
-       unsigned long end_of_lowmem = max_low_pfn << PAGE_SHIFT;
-       unsigned long ramdisk_here;
-       unsigned long slop, clen, mapaddr;
-       char *p, *q;
-
-       if (!do_relocate_initrd)
-               return;
-
-       ramdisk_here = initrd_start - PAGE_OFFSET;
-
-       q = (char *)initrd_start;
-
-       /* Copy any lowmem portion of the initrd */
-       if (ramdisk_image < end_of_lowmem) {
-               clen = end_of_lowmem - ramdisk_image;
-               p = (char *)__va(ramdisk_image);
-               memcpy(q, p, clen);
-               q += clen;
-               ramdisk_image += clen;
-               ramdisk_size  -= clen;
-       }
-
-       /* Copy the highmem portion of the initrd */
-       while (ramdisk_size) {
-               slop = ramdisk_image & ~PAGE_MASK;
-               clen = ramdisk_size;
-               if (clen > MAX_MAP_CHUNK-slop)
-                       clen = MAX_MAP_CHUNK-slop;
-               mapaddr = ramdisk_image & PAGE_MASK;
-               p = early_ioremap(mapaddr, clen+slop);
-               memcpy(q, p+slop, clen);
-               early_iounmap(p, clen+slop);
-               q += clen;
-               ramdisk_image += clen;
-               ramdisk_size  -= clen;
-       }
-}
-
-#endif /* CONFIG_BLK_DEV_INITRD */
-
-void __init setup_bootmem_allocator(void)
-{
-       unsigned long bootmap_size;
-       /*
-        * Initialize the boot-time allocator (with low memory only):
-        */
-       bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
-
-       register_bootmem_low_pages(max_low_pfn);
-
-       /*
-        * Reserve the bootmem bitmap itself as well. We do this in two
-        * steps (first step was init_bootmem()) because this catches
-        * the (very unlikely) case of us accidentally initializing the
-        * bootmem allocator with an invalid RAM area.
-        */
-       reserve_bootmem(__pa_symbol(_text), (PFN_PHYS(min_low_pfn) +
-                        bootmap_size + PAGE_SIZE-1) - __pa_symbol(_text),
-                        BOOTMEM_DEFAULT);
-
-       /*
-        * reserve physical page 0 - it's a special BIOS page on many boxes,
-        * enabling clean reboots, SMP operation, laptop functions.
-        */
-       reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
-
-       /* reserve EBDA region */
-       reserve_ebda_region();
-
-#ifdef CONFIG_SMP
-       /*
-        * But first pinch a few for the stack/trampoline stuff
-        * FIXME: Don't need the extra page at 4K, but need to fix
-        * trampoline before removing it. (see the GDT stuff)
-        */
-       reserve_bootmem(PAGE_SIZE, PAGE_SIZE, BOOTMEM_DEFAULT);
-#endif
-#ifdef CONFIG_ACPI_SLEEP
-       /*
-        * Reserve low memory region for sleep support.
-        */
-       acpi_reserve_bootmem();
-#endif
-#ifdef CONFIG_X86_FIND_SMP_CONFIG
-       /*
-        * Find and reserve possible boot-time SMP configuration:
-        */
-       find_smp_config();
-#endif
-#ifdef CONFIG_BLK_DEV_INITRD
-       reserve_initrd();
-#endif
-       numa_kva_reserve();
-       reserve_crashkernel();
-
-       reserve_ibft_region();
-}
-
-/*
- * The node 0 pgdat is initialized before all of these because
- * it's needed for bootmem.  node>0 pgdats have their virtual
- * space allocated before the pagetables are in place to access
- * them, so they can't be cleared then.
- *
- * This should all compile down to nothing when NUMA is off.
- */
-static void __init remapped_pgdat_init(void)
-{
-       int nid;
-
-       for_each_online_node(nid) {
-               if (nid != 0)
-                       memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
-       }
-}
-
-#ifdef CONFIG_MCA
-static void set_mca_bus(int x)
-{
-       MCA_bus = x;
-}
-#else
-static void set_mca_bus(int x) { }
-#endif
-
-/* Overridden in paravirt.c if CONFIG_PARAVIRT */
-char * __init __attribute__((weak)) memory_setup(void)
-{
-       return machine_specific_memory_setup();
-}
-
-#ifdef CONFIG_NUMA
-/*
- * In the golden day, when everything among i386 and x86_64 will be
- * integrated, this will not live here
- */
-void *x86_cpu_to_node_map_early_ptr;
-int x86_cpu_to_node_map_init[NR_CPUS] = {
-       [0 ... NR_CPUS-1] = NUMA_NO_NODE
-};
-DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
-#endif
-
-/*
- * Determine if we were loaded by an EFI loader.  If so, then we have also been
- * passed the efi memmap, systab, etc., so we should use these data structures
- * for initialization.  Note, the efi init code path is determined by the
- * global efi_enabled. This allows the same kernel image to be used on existing
- * systems (with a traditional BIOS) as well as on EFI systems.
- */
-void __init setup_arch(char **cmdline_p)
-{
-       unsigned long max_low_pfn;
-
-       memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
-       pre_setup_arch_hook();
-       early_cpu_init();
-       early_ioremap_init();
-
-#ifdef CONFIG_EFI
-       if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
-                    "EL32", 4))
-               efi_enabled = 1;
-#endif
-
-       ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
-       screen_info = boot_params.screen_info;
-       edid_info = boot_params.edid_info;
-       apm_info.bios = boot_params.apm_bios_info;
-       ist_info = boot_params.ist_info;
-       saved_video_mode = boot_params.hdr.vid_mode;
-       if( boot_params.sys_desc_table.length != 0 ) {
-               set_mca_bus(boot_params.sys_desc_table.table[3] & 0x2);
-               machine_id = boot_params.sys_desc_table.table[0];
-               machine_submodel_id = boot_params.sys_desc_table.table[1];
-               BIOS_revision = boot_params.sys_desc_table.table[2];
-       }
-       bootloader_type = boot_params.hdr.type_of_loader;
-
-#ifdef CONFIG_BLK_DEV_RAM
-       rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
-       rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
-       rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
-#endif
-       ARCH_SETUP
-
-       printk(KERN_INFO "BIOS-provided physical RAM map:\n");
-       print_memory_map(memory_setup());
-
-       copy_edd();
-
-       if (!boot_params.hdr.root_flags)
-               root_mountflags &= ~MS_RDONLY;
-       init_mm.start_code = (unsigned long) _text;
-       init_mm.end_code = (unsigned long) _etext;
-       init_mm.end_data = (unsigned long) _edata;
-       init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
-
-       code_resource.start = virt_to_phys(_text);
-       code_resource.end = virt_to_phys(_etext)-1;
-       data_resource.start = virt_to_phys(_etext);
-       data_resource.end = virt_to_phys(_edata)-1;
-       bss_resource.start = virt_to_phys(&__bss_start);
-       bss_resource.end = virt_to_phys(&__bss_stop)-1;
-
-       parse_early_param();
-
-       if (user_defined_memmap) {
-               printk(KERN_INFO "user-defined physical RAM map:\n");
-               print_memory_map("user");
-       }
-
-       strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
-       *cmdline_p = command_line;
-
-       if (efi_enabled)
-               efi_init();
-
-       /* update e820 for memory not covered by WB MTRRs */
-       propagate_e820_map();
-       mtrr_bp_init();
-       if (mtrr_trim_uncached_memory(max_pfn))
-               propagate_e820_map();
-
-       max_low_pfn = setup_memory();
-
-#ifdef CONFIG_KVM_CLOCK
-       kvmclock_init();
-#endif
-
-#ifdef CONFIG_VMI
-       /*
-        * Must be after max_low_pfn is determined, and before kernel
-        * pagetables are setup.
-        */
-       vmi_init();
-#endif
-       kvm_guest_init();
-
-       /*
-        * NOTE: before this point _nobody_ is allowed to allocate
-        * any memory using the bootmem allocator.  Although the
-        * allocator is now initialised only the first 8Mb of the kernel
-        * virtual address space has been mapped.  All allocations before
-        * paging_init() has completed must use the alloc_bootmem_low_pages()
-        * variant (which allocates DMA'able memory) and care must be taken
-        * not to exceed the 8Mb limit.
-        */
-
-#ifdef CONFIG_SMP
-       smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
-#endif
-       paging_init();
-
-       /*
-        * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
-        */
-
-#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
-       if (init_ohci1394_dma_early)
-               init_ohci1394_dma_on_all_controllers();
-#endif
-
-       remapped_pgdat_init();
-       sparse_init();
-       zone_sizes_init();
-
-       /*
-        * NOTE: at this point the bootmem allocator is fully available.
-        */
-
-#ifdef CONFIG_BLK_DEV_INITRD
-       relocate_initrd();
-#endif
-
-       paravirt_post_allocator_init();
-
-       dmi_scan_machine();
-
-       io_delay_init();
-
-#ifdef CONFIG_X86_SMP
-       /*
-        * setup to use the early static init tables during kernel startup
-        * X86_SMP will exclude sub-arches that don't deal well with it.
-        */
-       x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
-       x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
-#ifdef CONFIG_NUMA
-       x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
-#endif
-#endif
-
-#ifdef CONFIG_X86_GENERICARCH
-       generic_apic_probe();
-#endif
-
-#ifdef CONFIG_ACPI
-       /*
-        * Parse the ACPI tables for possible boot-time SMP configuration.
-        */
-       acpi_boot_table_init();
-#endif
-
-       early_quirks();
-
-#ifdef CONFIG_ACPI
-       acpi_boot_init();
-
-#if defined(CONFIG_SMP) && defined(CONFIG_X86_PC)
-       if (def_to_bigsmp)
-               printk(KERN_WARNING "More than 8 CPUs detected and "
-                       "CONFIG_X86_PC cannot handle it.\nUse "
-                       "CONFIG_X86_GENERICARCH or CONFIG_X86_BIGSMP.\n");
-#endif
-#endif
-#ifdef CONFIG_X86_LOCAL_APIC
-       if (smp_found_config)
-               get_smp_config();
-#endif
-
-       e820_register_memory();
-       e820_mark_nosave_regions();
-
-#ifdef CONFIG_VT
-#if defined(CONFIG_VGA_CONSOLE)
-       if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
-               conswitchp = &vga_con;
-#elif defined(CONFIG_DUMMY_CONSOLE)
-       conswitchp = &dummy_con;
-#endif
-#endif
-}
-
-/*
- * Request address space for all standard resources
- *
- * This is called just before pcibios_init(), which is also a
- * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
- */
-static int __init request_standard_resources(void)
-{
-       int i;
-
-       printk(KERN_INFO "Setting up standard PCI resources\n");
-       init_iomem_resources(&code_resource, &data_resource, &bss_resource);
-
-       request_resource(&iomem_resource, &video_ram_resource);
-
-       /* request I/O space for devices used on all i[345]86 PCs */
-       for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
-               request_resource(&ioport_resource, &standard_io_resources[i]);
-       return 0;
-}
-
-subsys_initcall(request_standard_resources);
diff --git a/arch/x86/kernel/setup_64.c b/arch/x86/kernel/setup_64.c
deleted file mode 100644 (file)
index 6dff128..0000000
+++ /dev/null
@@ -1,1194 +0,0 @@
-/*
- *  Copyright (C) 1995  Linus Torvalds
- */
-
-/*
- * This file handles the architecture-dependent parts of initialization
- */
-
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/stddef.h>
-#include <linux/unistd.h>
-#include <linux/ptrace.h>
-#include <linux/slab.h>
-#include <linux/user.h>
-#include <linux/screen_info.h>
-#include <linux/ioport.h>
-#include <linux/delay.h>
-#include <linux/init.h>
-#include <linux/initrd.h>
-#include <linux/highmem.h>
-#include <linux/bootmem.h>
-#include <linux/module.h>
-#include <asm/processor.h>
-#include <linux/console.h>
-#include <linux/seq_file.h>
-#include <linux/crash_dump.h>
-#include <linux/root_dev.h>
-#include <linux/pci.h>
-#include <asm/pci-direct.h>
-#include <linux/efi.h>
-#include <linux/acpi.h>
-#include <linux/kallsyms.h>
-#include <linux/edd.h>
-#include <linux/iscsi_ibft.h>
-#include <linux/mmzone.h>
-#include <linux/kexec.h>
-#include <linux/cpufreq.h>
-#include <linux/dmi.h>
-#include <linux/dma-mapping.h>
-#include <linux/ctype.h>
-#include <linux/sort.h>
-#include <linux/uaccess.h>
-#include <linux/init_ohci1394_dma.h>
-#include <linux/kvm_para.h>
-
-#include <asm/mtrr.h>
-#include <asm/uaccess.h>
-#include <asm/system.h>
-#include <asm/vsyscall.h>
-#include <asm/io.h>
-#include <asm/smp.h>
-#include <asm/msr.h>
-#include <asm/desc.h>
-#include <video/edid.h>
-#include <asm/e820.h>
-#include <asm/dma.h>
-#include <asm/gart.h>
-#include <asm/mpspec.h>
-#include <asm/mmu_context.h>
-#include <asm/proto.h>
-#include <asm/setup.h>
-#include <asm/numa.h>
-#include <asm/sections.h>
-#include <asm/dmi.h>
-#include <asm/cacheflush.h>
-#include <asm/mce.h>
-#include <asm/ds.h>
-#include <asm/topology.h>
-#include <asm/trampoline.h>
-#include <asm/pat.h>
-
-#include <mach_apic.h>
-#ifdef CONFIG_PARAVIRT
-#include <asm/paravirt.h>
-#else
-#define ARCH_SETUP
-#endif
-
-/*
- * Machine setup..
- */
-
-struct cpuinfo_x86 boot_cpu_data __read_mostly;
-EXPORT_SYMBOL(boot_cpu_data);
-
-__u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
-
-unsigned long mmu_cr4_features;
-
-/* Boot loader ID as an integer, for the benefit of proc_dointvec */
-int bootloader_type;
-
-unsigned long saved_video_mode;
-
-int force_mwait __cpuinitdata;
-
-/*
- * Early DMI memory
- */
-int dmi_alloc_index;
-char dmi_alloc_data[DMI_MAX_DATA];
-
-/*
- * Setup options
- */
-struct screen_info screen_info;
-EXPORT_SYMBOL(screen_info);
-struct sys_desc_table_struct {
-       unsigned short length;
-       unsigned char table[0];
-};
-
-struct edid_info edid_info;
-EXPORT_SYMBOL_GPL(edid_info);
-
-extern int root_mountflags;
-
-char __initdata command_line[COMMAND_LINE_SIZE];
-
-static struct resource standard_io_resources[] = {
-       { .name = "dma1", .start = 0x00, .end = 0x1f,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "pic1", .start = 0x20, .end = 0x21,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "timer0", .start = 0x40, .end = 0x43,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "timer1", .start = 0x50, .end = 0x53,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "keyboard", .start = 0x60, .end = 0x60,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "keyboard", .start = 0x64, .end = 0x64,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "dma page reg", .start = 0x80, .end = 0x8f,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "pic2", .start = 0xa0, .end = 0xa1,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "dma2", .start = 0xc0, .end = 0xdf,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO },
-       { .name = "fpu", .start = 0xf0, .end = 0xff,
-               .flags = IORESOURCE_BUSY | IORESOURCE_IO }
-};
-
-#define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
-
-static struct resource data_resource = {
-       .name = "Kernel data",
-       .start = 0,
-       .end = 0,
-       .flags = IORESOURCE_RAM,
-};
-static struct resource code_resource = {
-       .name = "Kernel code",
-       .start = 0,
-       .end = 0,
-       .flags = IORESOURCE_RAM,
-};
-static struct resource bss_resource = {
-       .name = "Kernel bss",
-       .start = 0,
-       .end = 0,
-       .flags = IORESOURCE_RAM,
-};
-
-static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
-
-#ifdef CONFIG_PROC_VMCORE
-/* elfcorehdr= specifies the location of elf core header
- * stored by the crashed kernel. This option will be passed
- * by kexec loader to the capture kernel.
- */
-static int __init setup_elfcorehdr(char *arg)
-{
-       char *end;
-       if (!arg)
-               return -EINVAL;
-       elfcorehdr_addr = memparse(arg, &end);
-       return end > arg ? 0 : -EINVAL;
-}
-early_param("elfcorehdr", setup_elfcorehdr);
-#endif
-
-#ifndef CONFIG_NUMA
-static void __init
-contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
-{
-       unsigned long bootmap_size, bootmap;
-
-       bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
-       bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
-                                PAGE_SIZE);
-       if (bootmap == -1L)
-               panic("Cannot find bootmem map of size %ld\n", bootmap_size);
-       bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
-       e820_register_active_regions(0, start_pfn, end_pfn);
-       free_bootmem_with_active_regions(0, end_pfn);
-       early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
-       reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
-}
-#endif
-
-#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
-struct edd edd;
-#ifdef CONFIG_EDD_MODULE
-EXPORT_SYMBOL(edd);
-#endif
-/**
- * copy_edd() - Copy the BIOS EDD information
- *              from boot_params into a safe place.
- *
- */
-static inline void copy_edd(void)
-{
-     memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
-           sizeof(edd.mbr_signature));
-     memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
-     edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
-     edd.edd_info_nr = boot_params.eddbuf_entries;
-}
-#else
-static inline void copy_edd(void)
-{
-}
-#endif
-
-#ifdef CONFIG_KEXEC
-static void __init reserve_crashkernel(void)
-{
-       unsigned long long total_mem;
-       unsigned long long crash_size, crash_base;
-       int ret;
-
-       total_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
-
-       ret = parse_crashkernel(boot_command_line, total_mem,
-                       &crash_size, &crash_base);
-       if (ret == 0 && crash_size) {
-               if (crash_base <= 0) {
-                       printk(KERN_INFO "crashkernel reservation failed - "
-                                       "you have to specify a base address\n");
-                       return;
-               }
-
-               if (reserve_bootmem(crash_base, crash_size,
-                                       BOOTMEM_EXCLUSIVE) < 0) {
-                       printk(KERN_INFO "crashkernel reservation failed - "
-                                       "memory is in use\n");
-                       return;
-               }
-
-               printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
-                               "for crashkernel (System RAM: %ldMB)\n",
-                               (unsigned long)(crash_size >> 20),
-                               (unsigned long)(crash_base >> 20),
-                               (unsigned long)(total_mem >> 20));
-               crashk_res.start = crash_base;
-               crashk_res.end   = crash_base + crash_size - 1;
-               insert_resource(&iomem_resource, &crashk_res);
-       }
-}
-#else
-static inline void __init reserve_crashkernel(void)
-{}
-#endif
-
-/* Overridden in paravirt.c if CONFIG_PARAVIRT */
-void __attribute__((weak)) __init memory_setup(void)
-{
-       machine_specific_memory_setup();
-}
-
-static void __init parse_setup_data(void)
-{
-       struct setup_data *data;
-       unsigned long pa_data;
-
-       if (boot_params.hdr.version < 0x0209)
-               return;
-       pa_data = boot_params.hdr.setup_data;
-       while (pa_data) {
-               data = early_ioremap(pa_data, PAGE_SIZE);
-               switch (data->type) {
-               default:
-                       break;
-               }
-#ifndef CONFIG_DEBUG_BOOT_PARAMS
-               free_early(pa_data, pa_data+sizeof(*data)+data->len);
-#endif
-               pa_data = data->next;
-               early_iounmap(data, PAGE_SIZE);
-       }
-}
-
-#ifdef CONFIG_PCI_MMCONFIG
-extern void __cpuinit fam10h_check_enable_mmcfg(void);
-extern void __init check_enable_amd_mmconf_dmi(void);
-#else
-void __cpuinit fam10h_check_enable_mmcfg(void)
-{
-}
-void __init check_enable_amd_mmconf_dmi(void)
-{
-}
-#endif
-
-/*
- * setup_arch - architecture-specific boot-time initializations
- *
- * Note: On x86_64, fixmaps are ready for use even before this is called.
- */
-void __init setup_arch(char **cmdline_p)
-{
-       unsigned i;
-
-       printk(KERN_INFO "Command line: %s\n", boot_command_line);
-
-       ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
-       screen_info = boot_params.screen_info;
-       edid_info = boot_params.edid_info;
-       saved_video_mode = boot_params.hdr.vid_mode;
-       bootloader_type = boot_params.hdr.type_of_loader;
-
-#ifdef CONFIG_BLK_DEV_RAM
-       rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
-       rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
-       rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
-#endif
-#ifdef CONFIG_EFI
-       if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
-                    "EL64", 4))
-               efi_enabled = 1;
-#endif
-
-       ARCH_SETUP
-
-       memory_setup();
-       copy_edd();
-
-       if (!boot_params.hdr.root_flags)
-               root_mountflags &= ~MS_RDONLY;
-       init_mm.start_code = (unsigned long) &_text;
-       init_mm.end_code = (unsigned long) &_etext;
-       init_mm.end_data = (unsigned long) &_edata;
-       init_mm.brk = (unsigned long) &_end;
-
-       code_resource.start = virt_to_phys(&_text);
-       code_resource.end = virt_to_phys(&_etext)-1;
-       data_resource.start = virt_to_phys(&_etext);
-       data_resource.end = virt_to_phys(&_edata)-1;
-       bss_resource.start = virt_to_phys(&__bss_start);
-       bss_resource.end = virt_to_phys(&__bss_stop)-1;
-
-       early_identify_cpu(&boot_cpu_data);
-
-       strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
-       *cmdline_p = command_line;
-
-       parse_setup_data();
-
-       parse_early_param();
-
-#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
-       if (init_ohci1394_dma_early)
-               init_ohci1394_dma_on_all_controllers();
-#endif
-
-       finish_e820_parsing();
-
-       /* after parse_early_param, so could debug it */
-       insert_resource(&iomem_resource, &code_resource);
-       insert_resource(&iomem_resource, &data_resource);
-       insert_resource(&iomem_resource, &bss_resource);
-
-       early_gart_iommu_check();
-
-       e820_register_active_regions(0, 0, -1UL);
-       /*
-        * partially used pages are not usable - thus
-        * we are rounding upwards:
-        */
-       end_pfn = e820_end_of_ram();
-       /* update e820 for memory not covered by WB MTRRs */
-       mtrr_bp_init();
-       if (mtrr_trim_uncached_memory(end_pfn)) {
-               e820_register_active_regions(0, 0, -1UL);
-               end_pfn = e820_end_of_ram();
-       }
-
-       num_physpages = end_pfn;
-
-       check_efer();
-
-       max_pfn_mapped = init_memory_mapping(0, (max_pfn_mapped << PAGE_SHIFT));
-       if (efi_enabled)
-               efi_init();
-
-       vsmp_init();
-
-       dmi_scan_machine();
-
-       io_delay_init();
-
-#ifdef CONFIG_KVM_CLOCK
-       kvmclock_init();
-#endif
-
-#ifdef CONFIG_SMP
-       /* setup to use the early static init tables during kernel startup */
-       x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
-       x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
-#ifdef CONFIG_NUMA
-       x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
-#endif
-#endif
-
-#ifdef CONFIG_ACPI
-       /*
-        * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
-        * Call this early for SRAT node setup.
-        */
-       acpi_boot_table_init();
-#endif
-
-       /* How many end-of-memory variables you have, grandma! */
-       max_low_pfn = end_pfn;
-       max_pfn = end_pfn;
-       high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
-
-       /* Remove active ranges so rediscovery with NUMA-awareness happens */
-       remove_all_active_ranges();
-
-#ifdef CONFIG_ACPI_NUMA
-       /*
-        * Parse SRAT to discover nodes.
-        */
-       acpi_numa_init();
-#endif
-
-#ifdef CONFIG_NUMA
-       numa_initmem_init(0, end_pfn);
-#else
-       contig_initmem_init(0, end_pfn);
-#endif
-
-       dma32_reserve_bootmem();
-
-#ifdef CONFIG_ACPI_SLEEP
-       /*
-        * Reserve low memory region for sleep support.
-        */
-       acpi_reserve_bootmem();
-#endif
-
-       if (efi_enabled)
-               efi_reserve_bootmem();
-
-       /*
-       * Find and reserve possible boot-time SMP configuration:
-       */
-       find_smp_config();
-#ifdef CONFIG_BLK_DEV_INITRD
-       if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
-               unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
-               unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
-               unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
-               unsigned long end_of_mem    = end_pfn << PAGE_SHIFT;
-
-               if (ramdisk_end <= end_of_mem) {
-                       /*
-                        * don't need to reserve again, already reserved early
-                        * in x86_64_start_kernel, and early_res_to_bootmem
-                        * convert that to reserved in bootmem
-                        */
-                       initrd_start = ramdisk_image + PAGE_OFFSET;
-                       initrd_end = initrd_start+ramdisk_size;
-               } else {
-                       free_bootmem(ramdisk_image, ramdisk_size);
-                       printk(KERN_ERR "initrd extends beyond end of memory "
-                              "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
-                              ramdisk_end, end_of_mem);
-                       initrd_start = 0;
-               }
-       }
-#endif
-       reserve_crashkernel();
-
-       reserve_ibft_region();
-
-       paging_init();
-       map_vsyscall();
-
-       early_quirks();
-
-#ifdef CONFIG_ACPI
-       /*
-        * Read APIC and some other early information from ACPI tables.
-        */
-       acpi_boot_init();
-#endif
-
-       init_cpu_to_node();
-
-       /*
-        * get boot-time SMP configuration:
-        */
-       if (smp_found_config)
-               get_smp_config();
-       init_apic_mappings();
-       ioapic_init_mappings();
-
-       kvm_guest_init();
-
-       /*
-        * We trust e820 completely. No explicit ROM probing in memory.
-        */
-       e820_reserve_resources();
-       e820_mark_nosave_regions();
-
-       /* request I/O space for devices used on all i[345]86 PCs */
-       for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
-               request_resource(&ioport_resource, &standard_io_resources[i]);
-
-       e820_setup_gap();
-
-#ifdef CONFIG_VT
-#if defined(CONFIG_VGA_CONSOLE)
-       if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
-               conswitchp = &vga_con;
-#elif defined(CONFIG_DUMMY_CONSOLE)
-       conswitchp = &dummy_con;
-#endif
-#endif
-
-       /* do this before identify_cpu for boot cpu */
-       check_enable_amd_mmconf_dmi();
-}
-
-static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
-{
-       unsigned int *v;
-
-       if (c->extended_cpuid_level < 0x80000004)
-               return 0;
-
-       v = (unsigned int *) c->x86_model_id;
-       cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
-       cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
-       cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
-       c->x86_model_id[48] = 0;
-       return 1;
-}
-
-
-static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
-{
-       unsigned int n, dummy, eax, ebx, ecx, edx;
-
-       n = c->extended_cpuid_level;
-
-       if (n >= 0x80000005) {
-               cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
-               printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
-                      "D cache %dK (%d bytes/line)\n",
-                      edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
-               c->x86_cache_size = (ecx>>24) + (edx>>24);
-               /* On K8 L1 TLB is inclusive, so don't count it */
-               c->x86_tlbsize = 0;
-       }
-
-       if (n >= 0x80000006) {
-               cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
-               ecx = cpuid_ecx(0x80000006);
-               c->x86_cache_size = ecx >> 16;
-               c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
-
-               printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
-               c->x86_cache_size, ecx & 0xFF);
-       }
-       if (n >= 0x80000008) {
-               cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
-               c->x86_virt_bits = (eax >> 8) & 0xff;
-               c->x86_phys_bits = eax & 0xff;
-       }
-}
-
-#ifdef CONFIG_NUMA
-static int __cpuinit nearby_node(int apicid)
-{
-       int i, node;
-
-       for (i = apicid - 1; i >= 0; i--) {
-               node = apicid_to_node[i];
-               if (node != NUMA_NO_NODE && node_online(node))
-                       return node;
-       }
-       for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
-               node = apicid_to_node[i];
-               if (node != NUMA_NO_NODE && node_online(node))
-                       return node;
-       }
-       return first_node(node_online_map); /* Shouldn't happen */
-}
-#endif
-
-/*
- * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
- * Assumes number of cores is a power of two.
- */
-static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
-{
-#ifdef CONFIG_SMP
-       unsigned bits;
-#ifdef CONFIG_NUMA
-       int cpu = smp_processor_id();
-       int node = 0;
-       unsigned apicid = hard_smp_processor_id();
-#endif
-       bits = c->x86_coreid_bits;
-
-       /* Low order bits define the core id (index of core in socket) */
-       c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
-       /* Convert the initial APIC ID into the socket ID */
-       c->phys_proc_id = c->initial_apicid >> bits;
-
-#ifdef CONFIG_NUMA
-       node = c->phys_proc_id;
-       if (apicid_to_node[apicid] != NUMA_NO_NODE)
-               node = apicid_to_node[apicid];
-       if (!node_online(node)) {
-               /* Two possibilities here:
-                  - The CPU is missing memory and no node was created.
-                  In that case try picking one from a nearby CPU
-                  - The APIC IDs differ from the HyperTransport node IDs
-                  which the K8 northbridge parsing fills in.
-                  Assume they are all increased by a constant offset,
-                  but in the same order as the HT nodeids.
-                  If that doesn't result in a usable node fall back to the
-                  path for the previous case.  */
-
-               int ht_nodeid = c->initial_apicid;
-
-               if (ht_nodeid >= 0 &&
-                   apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
-                       node = apicid_to_node[ht_nodeid];
-               /* Pick a nearby node */
-               if (!node_online(node))
-                       node = nearby_node(apicid);
-       }
-       numa_set_node(cpu, node);
-
-       printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
-#endif
-#endif
-}
-
-static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
-{
-#ifdef CONFIG_SMP
-       unsigned bits, ecx;
-
-       /* Multi core CPU? */
-       if (c->extended_cpuid_level < 0x80000008)
-               return;
-
-       ecx = cpuid_ecx(0x80000008);
-
-       c->x86_max_cores = (ecx & 0xff) + 1;
-
-       /* CPU telling us the core id bits shift? */
-       bits = (ecx >> 12) & 0xF;
-
-       /* Otherwise recompute */
-       if (bits == 0) {
-               while ((1 << bits) < c->x86_max_cores)
-                       bits++;
-       }
-
-       c->x86_coreid_bits = bits;
-
-#endif
-}
-
-#define ENABLE_C1E_MASK                0x18000000
-#define CPUID_PROCESSOR_SIGNATURE      1
-#define CPUID_XFAM             0x0ff00000
-#define CPUID_XFAM_K8          0x00000000
-#define CPUID_XFAM_10H         0x00100000
-#define CPUID_XFAM_11H         0x00200000
-#define CPUID_XMOD             0x000f0000
-#define CPUID_XMOD_REV_F       0x00040000
-
-/* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
-static __cpuinit int amd_apic_timer_broken(void)
-{
-       u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
-
-       switch (eax & CPUID_XFAM) {
-       case CPUID_XFAM_K8:
-               if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
-                       break;
-       case CPUID_XFAM_10H:
-       case CPUID_XFAM_11H:
-               rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
-               if (lo & ENABLE_C1E_MASK)
-                       return 1;
-               break;
-       default:
-               /* err on the side of caution */
-               return 1;
-       }
-       return 0;
-}
-
-static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
-{
-       early_init_amd_mc(c);
-
-       /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
-       if (c->x86_power & (1<<8))
-               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
-}
-
-static void __cpuinit init_amd(struct cpuinfo_x86 *c)
-{
-       unsigned level;
-
-#ifdef CONFIG_SMP
-       unsigned long value;
-
-       /*
-        * Disable TLB flush filter by setting HWCR.FFDIS on K8
-        * bit 6 of msr C001_0015
-        *
-        * Errata 63 for SH-B3 steppings
-        * Errata 122 for all steppings (F+ have it disabled by default)
-        */
-       if (c->x86 == 15) {
-               rdmsrl(MSR_K8_HWCR, value);
-               value |= 1 << 6;
-               wrmsrl(MSR_K8_HWCR, value);
-       }
-#endif
-
-       /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
-          3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
-       clear_cpu_cap(c, 0*32+31);
-
-       /* On C+ stepping K8 rep microcode works well for copy/memset */
-       level = cpuid_eax(1);
-       if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
-                            level >= 0x0f58))
-               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-       if (c->x86 == 0x10 || c->x86 == 0x11)
-               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-
-       /* Enable workaround for FXSAVE leak */
-       if (c->x86 >= 6)
-               set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
-
-       level = get_model_name(c);
-       if (!level) {
-               switch (c->x86) {
-               case 15:
-                       /* Should distinguish Models here, but this is only
-                          a fallback anyways. */
-                       strcpy(c->x86_model_id, "Hammer");
-                       break;
-               }
-       }
-       display_cacheinfo(c);
-
-       /* Multi core CPU? */
-       if (c->extended_cpuid_level >= 0x80000008)
-               amd_detect_cmp(c);
-
-       if (c->extended_cpuid_level >= 0x80000006 &&
-               (cpuid_edx(0x80000006) & 0xf000))
-               num_cache_leaves = 4;
-       else
-               num_cache_leaves = 3;
-
-       if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
-               set_cpu_cap(c, X86_FEATURE_K8);
-
-       /* MFENCE stops RDTSC speculation */
-       set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
-
-       if (c->x86 == 0x10)
-               fam10h_check_enable_mmcfg();
-
-       if (amd_apic_timer_broken())
-               disable_apic_timer = 1;
-
-       if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
-               unsigned long long tseg;
-
-               /*
-                * Split up direct mapping around the TSEG SMM area.
-                * Don't do it for gbpages because there seems very little
-                * benefit in doing so.
-                */
-               if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
-               (tseg >> PMD_SHIFT) < (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
-                       set_memory_4k((unsigned long)__va(tseg), 1);
-       }
-}
-
-void __cpuinit detect_ht(struct cpuinfo_x86 *c)
-{
-#ifdef CONFIG_SMP
-       u32 eax, ebx, ecx, edx;
-       int index_msb, core_bits;
-
-       cpuid(1, &eax, &ebx, &ecx, &edx);
-
-
-       if (!cpu_has(c, X86_FEATURE_HT))
-               return;
-       if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
-               goto out;
-
-       smp_num_siblings = (ebx & 0xff0000) >> 16;
-
-       if (smp_num_siblings == 1) {
-               printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
-       } else if (smp_num_siblings > 1) {
-
-               if (smp_num_siblings > NR_CPUS) {
-                       printk(KERN_WARNING "CPU: Unsupported number of "
-                              "siblings %d", smp_num_siblings);
-                       smp_num_siblings = 1;
-                       return;
-               }
-
-               index_msb = get_count_order(smp_num_siblings);
-               c->phys_proc_id = phys_pkg_id(index_msb);
-
-               smp_num_siblings = smp_num_siblings / c->x86_max_cores;
-
-               index_msb = get_count_order(smp_num_siblings);
-
-               core_bits = get_count_order(c->x86_max_cores);
-
-               c->cpu_core_id = phys_pkg_id(index_msb) &
-                                              ((1 << core_bits) - 1);
-       }
-out:
-       if ((c->x86_max_cores * smp_num_siblings) > 1) {
-               printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
-                      c->phys_proc_id);
-               printk(KERN_INFO  "CPU: Processor Core ID: %d\n",
-                      c->cpu_core_id);
-       }
-
-#endif
-}
-
-/*
- * find out the number of processor cores on the die
- */
-static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
-{
-       unsigned int eax, t;
-
-       if (c->cpuid_level < 4)
-               return 1;
-
-       cpuid_count(4, 0, &eax, &t, &t, &t);
-
-       if (eax & 0x1f)
-               return ((eax >> 26) + 1);
-       else
-               return 1;
-}
-
-static void __cpuinit srat_detect_node(void)
-{
-#ifdef CONFIG_NUMA
-       unsigned node;
-       int cpu = smp_processor_id();
-       int apicid = hard_smp_processor_id();
-
-       /* Don't do the funky fallback heuristics the AMD version employs
-          for now. */
-       node = apicid_to_node[apicid];
-       if (node == NUMA_NO_NODE || !node_online(node))
-               node = first_node(node_online_map);
-       numa_set_node(cpu, node);
-
-       printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
-#endif
-}
-
-static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
-{
-       if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
-           (c->x86 == 0x6 && c->x86_model >= 0x0e))
-               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
-}
-
-static void __cpuinit init_intel(struct cpuinfo_x86 *c)
-{
-       /* Cache sizes */
-       unsigned n;
-
-       init_intel_cacheinfo(c);
-       if (c->cpuid_level > 9) {
-               unsigned eax = cpuid_eax(10);
-               /* Check for version and the number of counters */
-               if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
-                       set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
-       }
-
-       if (cpu_has_ds) {
-               unsigned int l1, l2;
-               rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
-               if (!(l1 & (1<<11)))
-                       set_cpu_cap(c, X86_FEATURE_BTS);
-               if (!(l1 & (1<<12)))
-                       set_cpu_cap(c, X86_FEATURE_PEBS);
-       }
-
-
-       if (cpu_has_bts)
-               ds_init_intel(c);
-
-       n = c->extended_cpuid_level;
-       if (n >= 0x80000008) {
-               unsigned eax = cpuid_eax(0x80000008);
-               c->x86_virt_bits = (eax >> 8) & 0xff;
-               c->x86_phys_bits = eax & 0xff;
-               /* CPUID workaround for Intel 0F34 CPU */
-               if (c->x86_vendor == X86_VENDOR_INTEL &&
-                   c->x86 == 0xF && c->x86_model == 0x3 &&
-                   c->x86_mask == 0x4)
-                       c->x86_phys_bits = 36;
-       }
-
-       if (c->x86 == 15)
-               c->x86_cache_alignment = c->x86_clflush_size * 2;
-       if (c->x86 == 6)
-               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-       set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
-       c->x86_max_cores = intel_num_cpu_cores(c);
-
-       srat_detect_node();
-}
-
-static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
-{
-       if (c->x86 == 0x6 && c->x86_model >= 0xf)
-               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
-}
-
-static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
-{
-       /* Cache sizes */
-       unsigned n;
-
-       n = c->extended_cpuid_level;
-       if (n >= 0x80000008) {
-               unsigned eax = cpuid_eax(0x80000008);
-               c->x86_virt_bits = (eax >> 8) & 0xff;
-               c->x86_phys_bits = eax & 0xff;
-       }
-
-       if (c->x86 == 0x6 && c->x86_model >= 0xf) {
-               c->x86_cache_alignment = c->x86_clflush_size * 2;
-               set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
-               set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-       }
-       set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
-}
-
-static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
-{
-       char *v = c->x86_vendor_id;
-
-       if (!strcmp(v, "AuthenticAMD"))
-               c->x86_vendor = X86_VENDOR_AMD;
-       else if (!strcmp(v, "GenuineIntel"))
-               c->x86_vendor = X86_VENDOR_INTEL;
-       else if (!strcmp(v, "CentaurHauls"))
-               c->x86_vendor = X86_VENDOR_CENTAUR;
-       else
-               c->x86_vendor = X86_VENDOR_UNKNOWN;
-}
-
-/* Do some early cpuid on the boot CPU to get some parameter that are
-   needed before check_bugs. Everything advanced is in identify_cpu
-   below. */
-static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
-{
-       u32 tfms, xlvl;
-
-       c->loops_per_jiffy = loops_per_jiffy;
-       c->x86_cache_size = -1;
-       c->x86_vendor = X86_VENDOR_UNKNOWN;
-       c->x86_model = c->x86_mask = 0; /* So far unknown... */
-       c->x86_vendor_id[0] = '\0'; /* Unset */
-       c->x86_model_id[0] = '\0';  /* Unset */
-       c->x86_clflush_size = 64;
-       c->x86_cache_alignment = c->x86_clflush_size;
-       c->x86_max_cores = 1;
-       c->x86_coreid_bits = 0;
-       c->extended_cpuid_level = 0;
-       memset(&c->x86_capability, 0, sizeof c->x86_capability);
-
-       /* Get vendor name */
-       cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
-             (unsigned int *)&c->x86_vendor_id[0],
-             (unsigned int *)&c->x86_vendor_id[8],
-             (unsigned int *)&c->x86_vendor_id[4]);
-
-       get_cpu_vendor(c);
-
-       /* Initialize the standard set of capabilities */
-       /* Note that the vendor-specific code below might override */
-
-       /* Intel-defined flags: level 0x00000001 */
-       if (c->cpuid_level >= 0x00000001) {
-               __u32 misc;
-               cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
-                     &c->x86_capability[0]);
-               c->x86 = (tfms >> 8) & 0xf;
-               c->x86_model = (tfms >> 4) & 0xf;
-               c->x86_mask = tfms & 0xf;
-               if (c->x86 == 0xf)
-                       c->x86 += (tfms >> 20) & 0xff;
-               if (c->x86 >= 0x6)
-                       c->x86_model += ((tfms >> 16) & 0xF) << 4;
-               if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
-                       c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
-       } else {
-               /* Have CPUID level 0 only - unheard of */
-               c->x86 = 4;
-       }
-
-       c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
-#ifdef CONFIG_SMP
-       c->phys_proc_id = c->initial_apicid;
-#endif
-       /* AMD-defined flags: level 0x80000001 */
-       xlvl = cpuid_eax(0x80000000);
-       c->extended_cpuid_level = xlvl;
-       if ((xlvl & 0xffff0000) == 0x80000000) {
-               if (xlvl >= 0x80000001) {
-                       c->x86_capability[1] = cpuid_edx(0x80000001);
-                       c->x86_capability[6] = cpuid_ecx(0x80000001);
-               }
-               if (xlvl >= 0x80000004)
-                       get_model_name(c); /* Default name */
-       }
-
-       /* Transmeta-defined flags: level 0x80860001 */
-       xlvl = cpuid_eax(0x80860000);
-       if ((xlvl & 0xffff0000) == 0x80860000) {
-               /* Don't set x86_cpuid_level here for now to not confuse. */
-               if (xlvl >= 0x80860001)
-                       c->x86_capability[2] = cpuid_edx(0x80860001);
-       }
-
-       c->extended_cpuid_level = cpuid_eax(0x80000000);
-       if (c->extended_cpuid_level >= 0x80000007)
-               c->x86_power = cpuid_edx(0x80000007);
-
-       switch (c->x86_vendor) {
-       case X86_VENDOR_AMD:
-               early_init_amd(c);
-               break;
-       case X86_VENDOR_INTEL:
-               early_init_intel(c);
-               break;
-       case X86_VENDOR_CENTAUR:
-               early_init_centaur(c);
-               break;
-       }
-
-       validate_pat_support(c);
-}
-
-/*
- * This does the hard work of actually picking apart the CPU stuff...
- */
-void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
-{
-       int i;
-
-       early_identify_cpu(c);
-
-       init_scattered_cpuid_features(c);
-
-       c->apicid = phys_pkg_id(0);
-
-       /*
-        * Vendor-specific initialization.  In this section we
-        * canonicalize the feature flags, meaning if there are
-        * features a certain CPU supports which CPUID doesn't
-        * tell us, CPUID claiming incorrect flags, or other bugs,
-        * we handle them here.
-        *
-        * At the end of this section, c->x86_capability better
-        * indicate the features this CPU genuinely supports!
-        */
-       switch (c->x86_vendor) {
-       case X86_VENDOR_AMD:
-               init_amd(c);
-               break;
-
-       case X86_VENDOR_INTEL:
-               init_intel(c);
-               break;
-
-       case X86_VENDOR_CENTAUR:
-               init_centaur(c);
-               break;
-
-       case X86_VENDOR_UNKNOWN:
-       default:
-               display_cacheinfo(c);
-               break;
-       }
-
-       detect_ht(c);
-
-       /*
-        * On SMP, boot_cpu_data holds the common feature set between
-        * all CPUs; so make sure that we indicate which features are
-        * common between the CPUs.  The first time this routine gets
-        * executed, c == &boot_cpu_data.
-        */
-       if (c != &boot_cpu_data) {
-               /* AND the already accumulated flags with these */
-               for (i = 0; i < NCAPINTS; i++)
-                       boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
-       }
-
-       /* Clear all flags overriden by options */
-       for (i = 0; i < NCAPINTS; i++)
-               c->x86_capability[i] &= ~cleared_cpu_caps[i];
-
-#ifdef CONFIG_X86_MCE
-       mcheck_init(c);
-#endif
-       select_idle_routine(c);
-
-#ifdef CONFIG_NUMA
-       numa_add_cpu(smp_processor_id());
-#endif
-
-}
-
-void __cpuinit identify_boot_cpu(void)
-{
-       identify_cpu(&boot_cpu_data);
-}
-
-void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
-{
-       BUG_ON(c == &boot_cpu_data);
-       identify_cpu(c);
-       mtrr_ap_init();
-}
-
-static __init int setup_noclflush(char *arg)
-{
-       setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
-       return 1;
-}
-__setup("noclflush", setup_noclflush);
-
-void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
-{
-       if (c->x86_model_id[0])
-               printk(KERN_CONT "%s", c->x86_model_id);
-
-       if (c->x86_mask || c->cpuid_level >= 0)
-               printk(KERN_CONT " stepping %02x\n", c->x86_mask);
-       else
-               printk(KERN_CONT "\n");
-}
-
-static __init int setup_disablecpuid(char *arg)
-{
-       int bit;
-       if (get_option(&arg, &bit) && bit < NCAPINTS*32)
-               setup_clear_cpu_cap(bit);
-       else
-               return 0;
-       return 1;
-}
-__setup("clearcpuid=", setup_disablecpuid);
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
new file mode 100644 (file)
index 0000000..cac6843
--- /dev/null
@@ -0,0 +1,399 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/percpu.h>
+#include <linux/kexec.h>
+#include <linux/crash_dump.h>
+#include <asm/smp.h>
+#include <asm/percpu.h>
+#include <asm/sections.h>
+#include <asm/processor.h>
+#include <asm/setup.h>
+#include <asm/topology.h>
+#include <asm/mpspec.h>
+#include <asm/apicdef.h>
+#include <asm/highmem.h>
+
+#ifdef CONFIG_X86_LOCAL_APIC
+unsigned int num_processors;
+unsigned disabled_cpus __cpuinitdata;
+/* Processor that is doing the boot up */
+unsigned int boot_cpu_physical_apicid = -1U;
+unsigned int max_physical_apicid;
+EXPORT_SYMBOL(boot_cpu_physical_apicid);
+
+/* Bitmask of physically existing CPUs */
+physid_mask_t phys_cpu_present_map;
+#endif
+
+/* map cpu index to physical APIC ID */
+DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID);
+DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID);
+EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
+EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
+
+#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
+#define        X86_64_NUMA     1
+
+/* map cpu index to node index */
+DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE);
+EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map);
+
+/* which logical CPUs are on which nodes */
+cpumask_t *node_to_cpumask_map;
+EXPORT_SYMBOL(node_to_cpumask_map);
+
+/* setup node_to_cpumask_map */
+static void __init setup_node_to_cpumask_map(void);
+
+#else
+static inline void setup_node_to_cpumask_map(void) { }
+#endif
+
+#if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_X86_SMP)
+/*
+ * Copy data used in early init routines from the initial arrays to the
+ * per cpu data areas.  These arrays then become expendable and the
+ * *_early_ptr's are zeroed indicating that the static arrays are gone.
+ */
+static void __init setup_per_cpu_maps(void)
+{
+       int cpu;
+
+       for_each_possible_cpu(cpu) {
+               per_cpu(x86_cpu_to_apicid, cpu) =
+                               early_per_cpu_map(x86_cpu_to_apicid, cpu);
+               per_cpu(x86_bios_cpu_apicid, cpu) =
+                               early_per_cpu_map(x86_bios_cpu_apicid, cpu);
+#ifdef X86_64_NUMA
+               per_cpu(x86_cpu_to_node_map, cpu) =
+                               early_per_cpu_map(x86_cpu_to_node_map, cpu);
+#endif
+       }
+
+       /* indicate the early static arrays will soon be gone */
+       early_per_cpu_ptr(x86_cpu_to_apicid) = NULL;
+       early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL;
+#ifdef X86_64_NUMA
+       early_per_cpu_ptr(x86_cpu_to_node_map) = NULL;
+#endif
+}
+
+#ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP
+cpumask_t *cpumask_of_cpu_map __read_mostly;
+EXPORT_SYMBOL(cpumask_of_cpu_map);
+
+/* requires nr_cpu_ids to be initialized */
+static void __init setup_cpumask_of_cpu(void)
+{
+       int i;
+
+       /* alloc_bootmem zeroes memory */
+       cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids);
+       for (i = 0; i < nr_cpu_ids; i++)
+               cpu_set(i, cpumask_of_cpu_map[i]);
+}
+#else
+static inline void setup_cpumask_of_cpu(void) { }
+#endif
+
+#ifdef CONFIG_X86_32
+/*
+ * Great future not-so-futuristic plan: make i386 and x86_64 do it
+ * the same way
+ */
+unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
+EXPORT_SYMBOL(__per_cpu_offset);
+static inline void setup_cpu_pda_map(void) { }
+
+#elif !defined(CONFIG_SMP)
+static inline void setup_cpu_pda_map(void) { }
+
+#else /* CONFIG_SMP && CONFIG_X86_64 */
+
+/*
+ * Allocate cpu_pda pointer table and array via alloc_bootmem.
+ */
+static void __init setup_cpu_pda_map(void)
+{
+       char *pda;
+       struct x8664_pda **new_cpu_pda;
+       unsigned long size;
+       int cpu;
+
+       size = roundup(sizeof(struct x8664_pda), cache_line_size());
+
+       /* allocate cpu_pda array and pointer table */
+       {
+               unsigned long tsize = nr_cpu_ids * sizeof(void *);
+               unsigned long asize = size * (nr_cpu_ids - 1);
+
+               tsize = roundup(tsize, cache_line_size());
+               new_cpu_pda = alloc_bootmem(tsize + asize);
+               pda = (char *)new_cpu_pda + tsize;
+       }
+
+       /* initialize pointer table to static pda's */
+       for_each_possible_cpu(cpu) {
+               if (cpu == 0) {
+                       /* leave boot cpu pda in place */
+                       new_cpu_pda[0] = cpu_pda(0);
+                       continue;
+               }
+               new_cpu_pda[cpu] = (struct x8664_pda *)pda;
+               new_cpu_pda[cpu]->in_bootmem = 1;
+               pda += size;
+       }
+
+       /* point to new pointer table */
+       _cpu_pda = new_cpu_pda;
+}
+#endif
+
+/*
+ * Great future plan:
+ * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
+ * Always point %gs to its beginning
+ */
+void __init setup_per_cpu_areas(void)
+{
+       ssize_t size = PERCPU_ENOUGH_ROOM;
+       char *ptr;
+       int cpu;
+
+       /* Setup cpu_pda map */
+       setup_cpu_pda_map();
+
+       /* Copy section for each CPU (we discard the original) */
+       size = PERCPU_ENOUGH_ROOM;
+       printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n",
+                         size);
+
+       for_each_possible_cpu(cpu) {
+#ifndef CONFIG_NEED_MULTIPLE_NODES
+               ptr = alloc_bootmem_pages(size);
+#else
+               int node = early_cpu_to_node(cpu);
+               if (!node_online(node) || !NODE_DATA(node)) {
+                       ptr = alloc_bootmem_pages(size);
+                       printk(KERN_INFO
+                              "cpu %d has no node %d or node-local memory\n",
+                               cpu, node);
+               }
+               else
+                       ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
+#endif
+               per_cpu_offset(cpu) = ptr - __per_cpu_start;
+               memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
+
+       }
+
+       printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d, nr_node_ids %d\n",
+               NR_CPUS, nr_cpu_ids, nr_node_ids);
+
+       /* Setup percpu data maps */
+       setup_per_cpu_maps();
+
+       /* Setup node to cpumask map */
+       setup_node_to_cpumask_map();
+
+       /* Setup cpumask_of_cpu map */
+       setup_cpumask_of_cpu();
+}
+
+#endif
+
+#ifdef X86_64_NUMA
+
+/*
+ * Allocate node_to_cpumask_map based on number of available nodes
+ * Requires node_possible_map to be valid.
+ *
+ * Note: node_to_cpumask() is not valid until after this is done.
+ */
+static void __init setup_node_to_cpumask_map(void)
+{
+       unsigned int node, num = 0;
+       cpumask_t *map;
+
+       /* setup nr_node_ids if not done yet */
+       if (nr_node_ids == MAX_NUMNODES) {
+               for_each_node_mask(node, node_possible_map)
+                       num = node;
+               nr_node_ids = num + 1;
+       }
+
+       /* allocate the map */
+       map = alloc_bootmem_low(nr_node_ids * sizeof(cpumask_t));
+
+       Dprintk(KERN_DEBUG "Node to cpumask map at %p for %d nodes\n",
+               map, nr_node_ids);
+
+       /* node_to_cpumask() will now work */
+       node_to_cpumask_map = map;
+}
+
+void __cpuinit numa_set_node(int cpu, int node)
+{
+       int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
+
+       if (cpu_pda(cpu) && node != NUMA_NO_NODE)
+               cpu_pda(cpu)->nodenumber = node;
+
+       if (cpu_to_node_map)
+               cpu_to_node_map[cpu] = node;
+
+       else if (per_cpu_offset(cpu))
+               per_cpu(x86_cpu_to_node_map, cpu) = node;
+
+       else
+               Dprintk(KERN_INFO "Setting node for non-present cpu %d\n", cpu);
+}
+
+void __cpuinit numa_clear_node(int cpu)
+{
+       numa_set_node(cpu, NUMA_NO_NODE);
+}
+
+#ifndef CONFIG_DEBUG_PER_CPU_MAPS
+
+void __cpuinit numa_add_cpu(int cpu)
+{
+       cpu_set(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]);
+}
+
+void __cpuinit numa_remove_cpu(int cpu)
+{
+       cpu_clear(cpu, node_to_cpumask_map[cpu_to_node(cpu)]);
+}
+
+#else /* CONFIG_DEBUG_PER_CPU_MAPS */
+
+/*
+ * --------- debug versions of the numa functions ---------
+ */
+static void __cpuinit numa_set_cpumask(int cpu, int enable)
+{
+       int node = cpu_to_node(cpu);
+       cpumask_t *mask;
+       char buf[64];
+
+       if (node_to_cpumask_map == NULL) {
+               printk(KERN_ERR "node_to_cpumask_map NULL\n");
+               dump_stack();
+               return;
+       }
+
+       mask = &node_to_cpumask_map[node];
+       if (enable)
+               cpu_set(cpu, *mask);
+       else
+               cpu_clear(cpu, *mask);
+
+       cpulist_scnprintf(buf, sizeof(buf), *mask);
+       printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n",
+               enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf);
+ }
+
+void __cpuinit numa_add_cpu(int cpu)
+{
+       numa_set_cpumask(cpu, 1);
+}
+
+void __cpuinit numa_remove_cpu(int cpu)
+{
+       numa_set_cpumask(cpu, 0);
+}
+
+int cpu_to_node(int cpu)
+{
+       if (early_per_cpu_ptr(x86_cpu_to_node_map)) {
+               printk(KERN_WARNING
+                       "cpu_to_node(%d): usage too early!\n", cpu);
+               dump_stack();
+               return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
+       }
+       return per_cpu(x86_cpu_to_node_map, cpu);
+}
+EXPORT_SYMBOL(cpu_to_node);
+
+/*
+ * Same function as cpu_to_node() but used if called before the
+ * per_cpu areas are setup.
+ */
+int early_cpu_to_node(int cpu)
+{
+       if (early_per_cpu_ptr(x86_cpu_to_node_map))
+               return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
+
+       if (!per_cpu_offset(cpu)) {
+               printk(KERN_WARNING
+                       "early_cpu_to_node(%d): no per_cpu area!\n", cpu);
+               dump_stack();
+               return NUMA_NO_NODE;
+       }
+       return per_cpu(x86_cpu_to_node_map, cpu);
+}
+
+
+/* empty cpumask */
+static const cpumask_t cpu_mask_none;
+
+/*
+ * Returns a pointer to the bitmask of CPUs on Node 'node'.
+ */
+const cpumask_t *_node_to_cpumask_ptr(int node)
+{
+       if (node_to_cpumask_map == NULL) {
+               printk(KERN_WARNING
+                       "_node_to_cpumask_ptr(%d): no node_to_cpumask_map!\n",
+                       node);
+               dump_stack();
+               return (const cpumask_t *)&cpu_online_map;
+       }
+       if (node >= nr_node_ids) {
+               printk(KERN_WARNING
+                       "_node_to_cpumask_ptr(%d): node > nr_node_ids(%d)\n",
+                       node, nr_node_ids);
+               dump_stack();
+               return &cpu_mask_none;
+       }
+       return &node_to_cpumask_map[node];
+}
+EXPORT_SYMBOL(_node_to_cpumask_ptr);
+
+/*
+ * Returns a bitmask of CPUs on Node 'node'.
+ *
+ * Side note: this function creates the returned cpumask on the stack
+ * so with a high NR_CPUS count, excessive stack space is used.  The
+ * node_to_cpumask_ptr function should be used whenever possible.
+ */
+cpumask_t node_to_cpumask(int node)
+{
+       if (node_to_cpumask_map == NULL) {
+               printk(KERN_WARNING
+                       "node_to_cpumask(%d): no node_to_cpumask_map!\n", node);
+               dump_stack();
+               return cpu_online_map;
+       }
+       if (node >= nr_node_ids) {
+               printk(KERN_WARNING
+                       "node_to_cpumask(%d): node > nr_node_ids(%d)\n",
+                       node, nr_node_ids);
+               dump_stack();
+               return cpu_mask_none;
+       }
+       return node_to_cpumask_map[node];
+}
+EXPORT_SYMBOL(node_to_cpumask);
+
+/*
+ * --------- end of debug versions of the numa functions ---------
+ */
+
+#endif /* CONFIG_DEBUG_PER_CPU_MAPS */
+
+#endif /* X86_64_NUMA */
+
index 3e1cece..f35c2d8 100644 (file)
@@ -59,7 +59,6 @@
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
 #include <asm/mtrr.h>
-#include <asm/nmi.h>
 #include <asm/vmi.h>
 #include <asm/genapic.h>
 #include <linux/mc146818rtc.h>
 #include <mach_wakecpu.h>
 #include <smpboot_hooks.h>
 
-/*
- * FIXME: For x86_64, those are defined in other files. But moving them here,
- * would make the setup areas dependent on smp, which is a loss. When we
- * integrate apic between arches, we can probably do a better job, but
- * right now, they'll stay here -- glommer
- */
-
-/* which logical CPU number maps to which CPU (physical APIC ID) */
-u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata =
-                       { [0 ... NR_CPUS-1] = BAD_APICID };
-void *x86_cpu_to_apicid_early_ptr;
-
-u16 x86_bios_cpu_apicid_init[NR_CPUS] __initdata
-                               = { [0 ... NR_CPUS-1] = BAD_APICID };
-void *x86_bios_cpu_apicid_early_ptr;
-
 #ifdef CONFIG_X86_32
 u8 apicid_2_node[MAX_APICID];
 static int low_mappings;
@@ -198,13 +181,12 @@ static void map_cpu_to_logical_apicid(void)
        map_cpu_to_node(cpu, node);
 }
 
-static void unmap_cpu_to_logical_apicid(int cpu)
+void numa_remove_cpu(int cpu)
 {
        cpu_2_logical_apicid[cpu] = BAD_APICID;
        unmap_cpu_to_node(cpu);
 }
 #else
-#define unmap_cpu_to_logical_apicid(cpu) do {} while (0)
 #define map_cpu_to_logical_apicid()  do {} while (0)
 #endif
 
@@ -346,15 +328,8 @@ static void __cpuinit start_secondary(void *unused)
         * smp_call_function().
         */
        lock_ipi_call_lock();
-#ifdef CONFIG_X86_64
-       spin_lock(&vector_lock);
-
-       /* Setup the per cpu irq handling data structures */
-       __setup_vector_irq(smp_processor_id());
-       /*
-        * Allow the master to continue.
-        */
-       spin_unlock(&vector_lock);
+#ifdef CONFIG_X86_IO_APIC
+       setup_vector_irq(smp_processor_id());
 #endif
        cpu_set(smp_processor_id(), cpu_online_map);
        unlock_ipi_call_lock();
@@ -366,31 +341,8 @@ static void __cpuinit start_secondary(void *unused)
        cpu_idle();
 }
 
-#ifdef CONFIG_X86_32
-/*
- * Everything has been set up for the secondary
- * CPUs - they just need to reload everything
- * from the task structure
- * This function must not return.
- */
-void __devinit initialize_secondary(void)
-{
-       /*
-        * We don't actually need to load the full TSS,
-        * basically just the stack pointer and the ip.
-        */
-
-       asm volatile(
-               "movl %0,%%esp\n\t"
-               "jmp *%1"
-               :
-               :"m" (current->thread.sp), "m" (current->thread.ip));
-}
-#endif
-
 static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c)
 {
-#ifdef CONFIG_X86_32
        /*
         * Mask B, Pentium, but not Pentium MMX
         */
@@ -440,7 +392,6 @@ static void __cpuinit smp_apply_quirks(struct cpuinfo_x86 *c)
 
 valid_k7:
        ;
-#endif
 }
 
 static void __cpuinit smp_checks(void)
@@ -555,23 +506,6 @@ cpumask_t cpu_coregroup_map(int cpu)
                return c->llc_shared_map;
 }
 
-#ifdef CONFIG_X86_32
-/*
- * We are called very early to get the low memory for the
- * SMP bootup trampoline page.
- */
-void __init smp_alloc_memory(void)
-{
-       trampoline_base = alloc_bootmem_low_pages(PAGE_SIZE);
-       /*
-        * Has to be in very low memory so we can execute
-        * real-mode AP code.
-        */
-       if (__pa(trampoline_base) >= 0x9F000)
-               BUG();
-}
-#endif
-
 static void impress_friends(void)
 {
        int cpu;
@@ -748,11 +682,7 @@ wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
         * target processor state.
         */
        startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
-#ifdef CONFIG_X86_64
-                        (unsigned long)init_rsp);
-#else
                         (unsigned long)stack_start.sp);
-#endif
 
        /*
         * Run STARTUP IPI loop.
@@ -832,6 +762,45 @@ static void __cpuinit do_fork_idle(struct work_struct *work)
        complete(&c_idle->done);
 }
 
+#ifdef CONFIG_X86_64
+/*
+ * Allocate node local memory for the AP pda.
+ *
+ * Must be called after the _cpu_pda pointer table is initialized.
+ */
+static int __cpuinit get_local_pda(int cpu)
+{
+       struct x8664_pda *oldpda, *newpda;
+       unsigned long size = sizeof(struct x8664_pda);
+       int node = cpu_to_node(cpu);
+
+       if (cpu_pda(cpu) && !cpu_pda(cpu)->in_bootmem)
+               return 0;
+
+       oldpda = cpu_pda(cpu);
+       newpda = kmalloc_node(size, GFP_ATOMIC, node);
+       if (!newpda) {
+               printk(KERN_ERR "Could not allocate node local PDA "
+                       "for CPU %d on node %d\n", cpu, node);
+
+               if (oldpda)
+                       return 0;       /* have a usable pda */
+               else
+                       return -1;
+       }
+
+       if (oldpda) {
+               memcpy(newpda, oldpda, size);
+               if (!after_bootmem)
+                       free_bootmem((unsigned long)oldpda, size);
+       }
+
+       newpda->in_bootmem = 0;
+       cpu_pda(cpu) = newpda;
+       return 0;
+}
+#endif /* CONFIG_X86_64 */
+
 static int __cpuinit do_boot_cpu(int apicid, int cpu)
 /*
  * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
@@ -848,28 +817,14 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
                .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
        };
        INIT_WORK(&c_idle.work, do_fork_idle);
-#ifdef CONFIG_X86_64
-       /* allocate memory for gdts of secondary cpus. Hotplug is considered */
-       if (!cpu_gdt_descr[cpu].address &&
-               !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
-               printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu);
-               return -1;
-       }
 
+#ifdef CONFIG_X86_64
        /* Allocate node local memory for AP pdas */
-       if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) {
-               struct x8664_pda *newpda, *pda;
-               int node = cpu_to_node(cpu);
-               pda = cpu_pda(cpu);
-               newpda = kmalloc_node(sizeof(struct x8664_pda), GFP_ATOMIC,
-                                     node);
-               if (newpda) {
-                       memcpy(newpda, pda, sizeof(struct x8664_pda));
-                       cpu_pda(cpu) = newpda;
-               } else
-                       printk(KERN_ERR
-               "Could not allocate node local PDA for CPU %d on node %d\n",
-                               cpu, node);
+       if (cpu > 0) {
+               boot_error = get_local_pda(cpu);
+               if (boot_error)
+                       goto restore_state;
+                       /* if can't get pda memory, can't start cpu */
        }
 #endif
 
@@ -905,18 +860,15 @@ do_rest:
 #ifdef CONFIG_X86_32
        per_cpu(current_task, cpu) = c_idle.idle;
        init_gdt(cpu);
-       early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
-       c_idle.idle->thread.ip = (unsigned long) start_secondary;
        /* Stack for startup_32 can be just as for start_secondary onwards */
-       stack_start.sp = (void *) c_idle.idle->thread.sp;
        irq_ctx_init(cpu);
 #else
        cpu_pda(cpu)->pcurrent = c_idle.idle;
-       init_rsp = c_idle.idle->thread.sp;
-       load_sp0(&per_cpu(init_tss, cpu), &c_idle.idle->thread);
-       initial_code = (unsigned long)start_secondary;
        clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
 #endif
+       early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
+       initial_code = (unsigned long)start_secondary;
+       stack_start.sp = (void *) c_idle.idle->thread.sp;
 
        /* start_ip had better be page-aligned! */
        start_ip = setup_trampoline();
@@ -987,13 +939,12 @@ do_rest:
                                inquire_remote_apic(apicid);
                }
        }
-
-       if (boot_error) {
-               /* Try to put things back the way they were before ... */
-               unmap_cpu_to_logical_apicid(cpu);
 #ifdef CONFIG_X86_64
-               clear_node_cpumask(cpu); /* was set by numa_add_cpu */
+restore_state:
 #endif
+       if (boot_error) {
+               /* Try to put things back the way they were before ... */
+               numa_remove_cpu(cpu); /* was set by numa_add_cpu */
                cpu_clear(cpu, cpu_callout_map); /* was set by do_boot_cpu() */
                cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
                cpu_clear(cpu, cpu_present_map);
@@ -1087,14 +1038,12 @@ static __init void disable_smp(void)
 {
        cpu_present_map = cpumask_of_cpu(0);
        cpu_possible_map = cpumask_of_cpu(0);
-#ifdef CONFIG_X86_32
        smpboot_clear_io_apic_irqs();
-#endif
+
        if (smp_found_config)
-               phys_cpu_present_map =
-                               physid_mask_of_physid(boot_cpu_physical_apicid);
+               physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
        else
-               phys_cpu_present_map = physid_mask_of_physid(0);
+               physid_set_mask_of_physid(0, &phys_cpu_present_map);
        map_cpu_to_logical_apicid();
        cpu_set(0, per_cpu(cpu_sibling_map, 0));
        cpu_set(0, per_cpu(cpu_core_map, 0));
@@ -1157,12 +1106,12 @@ static int __init smp_sanity_check(unsigned max_cpus)
         * If SMP should be disabled, then really disable it!
         */
        if (!max_cpus) {
-               printk(KERN_INFO "SMP mode deactivated,"
-                                "forcing use of dummy APIC emulation.\n");
+               printk(KERN_INFO "SMP mode deactivated.\n");
                smpboot_clear_io_apic();
-#ifdef CONFIG_X86_32
+
+               localise_nmi_watchdog();
+
                connect_bsp_APIC();
-#endif
                setup_local_APIC();
                end_local_APIC_setup();
                return -1;
@@ -1190,7 +1139,6 @@ static void __init smp_cpu_index_default(void)
 void __init native_smp_prepare_cpus(unsigned int max_cpus)
 {
        preempt_disable();
-       nmi_watchdog_default();
        smp_cpu_index_default();
        current_cpu_data = boot_cpu_data;
        cpu_callin_map = cpumask_of_cpu(0);
@@ -1217,9 +1165,8 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
        }
        preempt_enable();
 
-#ifdef CONFIG_X86_32
        connect_bsp_APIC();
-#endif
+
        /*
         * Switch from PIC to APIC mode.
         */
@@ -1257,8 +1204,8 @@ void __init native_smp_prepare_boot_cpu(void)
        int me = smp_processor_id();
 #ifdef CONFIG_X86_32
        init_gdt(me);
-       switch_to_new_gdt();
 #endif
+       switch_to_new_gdt();
        /* already set me in cpu_online_map in boot_cpu_init() */
        cpu_set(me, cpu_callout_map);
        per_cpu(cpu_state, me) = CPU_ONLINE;
@@ -1278,23 +1225,6 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
 
 #ifdef CONFIG_HOTPLUG_CPU
 
-#  ifdef CONFIG_X86_32
-void cpu_exit_clear(void)
-{
-       int cpu = raw_smp_processor_id();
-
-       idle_task_exit();
-
-       cpu_uninit();
-       irq_ctx_exit(cpu);
-
-       cpu_clear(cpu, cpu_callout_map);
-       cpu_clear(cpu, cpu_callin_map);
-
-       unmap_cpu_to_logical_apicid(cpu);
-}
-#  endif /* CONFIG_X86_32 */
-
 static void remove_siblinginfo(int cpu)
 {
        int sibling;
@@ -1348,12 +1278,20 @@ __init void prefill_possible_map(void)
        int i;
        int possible;
 
+       /* no processor from mptable or madt */
+       if (!num_processors)
+               num_processors = 1;
+
+#ifdef CONFIG_HOTPLUG_CPU
        if (additional_cpus == -1) {
                if (disabled_cpus > 0)
                        additional_cpus = disabled_cpus;
                else
                        additional_cpus = 0;
        }
+#else
+       additional_cpus = 0;
+#endif
        possible = num_processors + additional_cpus;
        if (possible > NR_CPUS)
                possible = NR_CPUS;
@@ -1363,18 +1301,18 @@ __init void prefill_possible_map(void)
 
        for (i = 0; i < possible; i++)
                cpu_set(i, cpu_possible_map);
+
+       nr_cpu_ids = possible;
 }
 
 static void __ref remove_cpu_from_maps(int cpu)
 {
        cpu_clear(cpu, cpu_online_map);
-#ifdef CONFIG_X86_64
        cpu_clear(cpu, cpu_callout_map);
        cpu_clear(cpu, cpu_callin_map);
        /* was set by cpu_init() */
        clear_bit(cpu, (unsigned long *)&cpu_initialized);
-       clear_node_cpumask(cpu);
-#endif
+       numa_remove_cpu(cpu);
 }
 
 int __cpu_disable(void)
diff --git a/arch/x86/kernel/srat_32.c b/arch/x86/kernel/srat_32.c
deleted file mode 100644 (file)
index 70e4a37..0000000
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Some of the code in this file has been gleaned from the 64 bit 
- * discontigmem support code base.
- *
- * Copyright (C) 2002, IBM Corp.
- *
- * All rights reserved.          
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
- * NON INFRINGEMENT.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Send feedback to Pat Gaughen <gone@us.ibm.com>
- */
-#include <linux/mm.h>
-#include <linux/bootmem.h>
-#include <linux/mmzone.h>
-#include <linux/acpi.h>
-#include <linux/nodemask.h>
-#include <asm/srat.h>
-#include <asm/topology.h>
-#include <asm/smp.h>
-
-/*
- * proximity macros and definitions
- */
-#define NODE_ARRAY_INDEX(x)    ((x) / 8)       /* 8 bits/char */
-#define NODE_ARRAY_OFFSET(x)   ((x) % 8)       /* 8 bits/char */
-#define BMAP_SET(bmap, bit)    ((bmap)[NODE_ARRAY_INDEX(bit)] |= 1 << NODE_ARRAY_OFFSET(bit))
-#define BMAP_TEST(bmap, bit)   ((bmap)[NODE_ARRAY_INDEX(bit)] & (1 << NODE_ARRAY_OFFSET(bit)))
-/* bitmap length; _PXM is at most 255 */
-#define PXM_BITMAP_LEN (MAX_PXM_DOMAINS / 8) 
-static u8 pxm_bitmap[PXM_BITMAP_LEN];  /* bitmap of proximity domains */
-
-#define MAX_CHUNKS_PER_NODE    3
-#define MAXCHUNKS              (MAX_CHUNKS_PER_NODE * MAX_NUMNODES)
-struct node_memory_chunk_s {
-       unsigned long   start_pfn;
-       unsigned long   end_pfn;
-       u8      pxm;            // proximity domain of node
-       u8      nid;            // which cnode contains this chunk?
-       u8      bank;           // which mem bank on this node
-};
-static struct node_memory_chunk_s node_memory_chunk[MAXCHUNKS];
-
-static int num_memory_chunks;          /* total number of memory chunks */
-static u8 __initdata apicid_to_pxm[MAX_APICID];
-
-/* Identify CPU proximity domains */
-static void __init parse_cpu_affinity_structure(char *p)
-{
-       struct acpi_srat_cpu_affinity *cpu_affinity =
-                               (struct acpi_srat_cpu_affinity *) p;
-
-       if ((cpu_affinity->flags & ACPI_SRAT_CPU_ENABLED) == 0)
-               return;         /* empty entry */
-
-       /* mark this node as "seen" in node bitmap */
-       BMAP_SET(pxm_bitmap, cpu_affinity->proximity_domain_lo);
-
-       apicid_to_pxm[cpu_affinity->apic_id] = cpu_affinity->proximity_domain_lo;
-
-       printk("CPU 0x%02X in proximity domain 0x%02X\n",
-               cpu_affinity->apic_id, cpu_affinity->proximity_domain_lo);
-}
-
-/*
- * Identify memory proximity domains and hot-remove capabilities.
- * Fill node memory chunk list structure.
- */
-static void __init parse_memory_affinity_structure (char *sratp)
-{
-       unsigned long long paddr, size;
-       unsigned long start_pfn, end_pfn;
-       u8 pxm;
-       struct node_memory_chunk_s *p, *q, *pend;
-       struct acpi_srat_mem_affinity *memory_affinity =
-                       (struct acpi_srat_mem_affinity *) sratp;
-
-       if ((memory_affinity->flags & ACPI_SRAT_MEM_ENABLED) == 0)
-               return;         /* empty entry */
-
-       pxm = memory_affinity->proximity_domain & 0xff;
-
-       /* mark this node as "seen" in node bitmap */
-       BMAP_SET(pxm_bitmap, pxm);
-
-       /* calculate info for memory chunk structure */
-       paddr = memory_affinity->base_address;
-       size = memory_affinity->length;
-
-       start_pfn = paddr >> PAGE_SHIFT;
-       end_pfn = (paddr + size) >> PAGE_SHIFT;
-
-
-       if (num_memory_chunks >= MAXCHUNKS) {
-               printk("Too many mem chunks in SRAT. Ignoring %lld MBytes at %llx\n",
-                       size/(1024*1024), paddr);
-               return;
-       }
-
-       /* Insertion sort based on base address */
-       pend = &node_memory_chunk[num_memory_chunks];
-       for (p = &node_memory_chunk[0]; p < pend; p++) {
-               if (start_pfn < p->start_pfn)
-                       break;
-       }
-       if (p < pend) {
-               for (q = pend; q >= p; q--)
-                       *(q + 1) = *q;
-       }
-       p->start_pfn = start_pfn;
-       p->end_pfn = end_pfn;
-       p->pxm = pxm;
-
-       num_memory_chunks++;
-
-       printk("Memory range 0x%lX to 0x%lX (type 0x%X) in proximity domain 0x%02X %s\n",
-               start_pfn, end_pfn,
-               memory_affinity->memory_type,
-               pxm,
-               ((memory_affinity->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ?
-                "enabled and removable" : "enabled" ) );
-}
-
-/*
- * The SRAT table always lists ascending addresses, so can always
- * assume that the first "start" address that you see is the real
- * start of the node, and that the current "end" address is after
- * the previous one.
- */
-static __init void node_read_chunk(int nid, struct node_memory_chunk_s *memory_chunk)
-{
-       /*
-        * Only add present memory as told by the e820.
-        * There is no guarantee from the SRAT that the memory it
-        * enumerates is present at boot time because it represents
-        * *possible* memory hotplug areas the same as normal RAM.
-        */
-       if (memory_chunk->start_pfn >= max_pfn) {
-               printk (KERN_INFO "Ignoring SRAT pfns: 0x%08lx -> %08lx\n",
-                       memory_chunk->start_pfn, memory_chunk->end_pfn);
-               return;
-       }
-       if (memory_chunk->nid != nid)
-               return;
-
-       if (!node_has_online_mem(nid))
-               node_start_pfn[nid] = memory_chunk->start_pfn;
-
-       if (node_start_pfn[nid] > memory_chunk->start_pfn)
-               node_start_pfn[nid] = memory_chunk->start_pfn;
-
-       if (node_end_pfn[nid] < memory_chunk->end_pfn)
-               node_end_pfn[nid] = memory_chunk->end_pfn;
-}
-
-/* Parse the ACPI Static Resource Affinity Table */
-static int __init acpi20_parse_srat(struct acpi_table_srat *sratp)
-{
-       u8 *start, *end, *p;
-       int i, j, nid;
-
-       start = (u8 *)(&(sratp->reserved) + 1); /* skip header */
-       p = start;
-       end = (u8 *)sratp + sratp->header.length;
-
-       memset(pxm_bitmap, 0, sizeof(pxm_bitmap));      /* init proximity domain bitmap */
-       memset(node_memory_chunk, 0, sizeof(node_memory_chunk));
-
-       num_memory_chunks = 0;
-       while (p < end) {
-               switch (*p) {
-               case ACPI_SRAT_TYPE_CPU_AFFINITY:
-                       parse_cpu_affinity_structure(p);
-                       break;
-               case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
-                       parse_memory_affinity_structure(p);
-                       break;
-               default:
-                       printk("ACPI 2.0 SRAT: unknown entry skipped: type=0x%02X, len=%d\n", p[0], p[1]);
-                       break;
-               }
-               p += p[1];
-               if (p[1] == 0) {
-                       printk("acpi20_parse_srat: Entry length value is zero;"
-                               " can't parse any further!\n");
-                       break;
-               }
-       }
-
-       if (num_memory_chunks == 0) {
-               printk("could not finy any ACPI SRAT memory areas.\n");
-               goto out_fail;
-       }
-
-       /* Calculate total number of nodes in system from PXM bitmap and create
-        * a set of sequential node IDs starting at zero.  (ACPI doesn't seem
-        * to specify the range of _PXM values.)
-        */
-       /*
-        * MCD - we no longer HAVE to number nodes sequentially.  PXM domain
-        * numbers could go as high as 256, and MAX_NUMNODES for i386 is typically
-        * 32, so we will continue numbering them in this manner until MAX_NUMNODES
-        * approaches MAX_PXM_DOMAINS for i386.
-        */
-       nodes_clear(node_online_map);
-       for (i = 0; i < MAX_PXM_DOMAINS; i++) {
-               if (BMAP_TEST(pxm_bitmap, i)) {
-                       int nid = acpi_map_pxm_to_node(i);
-                       node_set_online(nid);
-               }
-       }
-       BUG_ON(num_online_nodes() == 0);
-
-       /* set cnode id in memory chunk structure */
-       for (i = 0; i < num_memory_chunks; i++)
-               node_memory_chunk[i].nid = pxm_to_node(node_memory_chunk[i].pxm);
-
-       printk("pxm bitmap: ");
-       for (i = 0; i < sizeof(pxm_bitmap); i++) {
-               printk("%02X ", pxm_bitmap[i]);
-       }
-       printk("\n");
-       printk("Number of logical nodes in system = %d\n", num_online_nodes());
-       printk("Number of memory chunks in system = %d\n", num_memory_chunks);
-
-       for (i = 0; i < MAX_APICID; i++)
-               apicid_2_node[i] = pxm_to_node(apicid_to_pxm[i]);
-
-       for (j = 0; j < num_memory_chunks; j++){
-               struct node_memory_chunk_s * chunk = &node_memory_chunk[j];
-               printk("chunk %d nid %d start_pfn %08lx end_pfn %08lx\n",
-                      j, chunk->nid, chunk->start_pfn, chunk->end_pfn);
-               node_read_chunk(chunk->nid, chunk);
-               add_active_range(chunk->nid, chunk->start_pfn, chunk->end_pfn);
-       }
-       for_each_online_node(nid) {
-               unsigned long start = node_start_pfn[nid];
-               unsigned long end = node_end_pfn[nid];
-
-               memory_present(nid, start, end);
-               node_remap_size[nid] = node_memmap_size_bytes(nid, start, end);
-       }
-       return 1;
-out_fail:
-       return 0;
-}
-
-struct acpi_static_rsdt {
-       struct acpi_table_rsdt table;
-       u32 padding[7]; /* Allow for 7 more table entries */
-};
-
-int __init get_memcfg_from_srat(void)
-{
-       struct acpi_table_header *header = NULL;
-       struct acpi_table_rsdp *rsdp = NULL;
-       struct acpi_table_rsdt *rsdt = NULL;
-       acpi_native_uint rsdp_address = 0;
-       struct acpi_static_rsdt saved_rsdt;
-       int tables = 0;
-       int i = 0;
-
-       rsdp_address = acpi_os_get_root_pointer();
-       if (!rsdp_address) {
-               printk("%s: System description tables not found\n",
-                      __func__);
-               goto out_err;
-       }
-
-       printk("%s: assigning address to rsdp\n", __func__);
-       rsdp = (struct acpi_table_rsdp *)(u32)rsdp_address;
-       if (!rsdp) {
-               printk("%s: Didn't find ACPI root!\n", __func__);
-               goto out_err;
-       }
-
-       printk(KERN_INFO "%.8s v%d [%.6s]\n", rsdp->signature, rsdp->revision,
-               rsdp->oem_id);
-
-       if (strncmp(rsdp->signature, ACPI_SIG_RSDP,strlen(ACPI_SIG_RSDP))) {
-               printk(KERN_WARNING "%s: RSDP table signature incorrect\n", __func__);
-               goto out_err;
-       }
-
-       rsdt = (struct acpi_table_rsdt *)
-           early_ioremap(rsdp->rsdt_physical_address, sizeof(struct acpi_table_rsdt));
-
-       if (!rsdt) {
-               printk(KERN_WARNING
-                      "%s: ACPI: Invalid root system description tables (RSDT)\n",
-                      __func__);
-               goto out_err;
-       }
-
-       header = &rsdt->header;
-
-       if (strncmp(header->signature, ACPI_SIG_RSDT, strlen(ACPI_SIG_RSDT))) {
-               printk(KERN_WARNING "ACPI: RSDT signature incorrect\n");
-               goto out_err;
-       }
-
-       /* 
-        * The number of tables is computed by taking the 
-        * size of all entries (header size minus total 
-        * size of RSDT) divided by the size of each entry
-        * (4-byte table pointers).
-        */
-       tables = (header->length - sizeof(struct acpi_table_header)) / 4;
-
-       if (!tables)
-               goto out_err;
-
-       memcpy(&saved_rsdt, rsdt, sizeof(saved_rsdt));
-
-       if (saved_rsdt.table.header.length > sizeof(saved_rsdt)) {
-               printk(KERN_WARNING "ACPI: Too big length in RSDT: %d\n",
-                      saved_rsdt.table.header.length);
-               goto out_err;
-       }
-
-       printk("Begin SRAT table scan....\n");
-
-       for (i = 0; i < tables; i++) {
-               /* Map in header, then map in full table length. */
-               header = (struct acpi_table_header *)
-                       early_ioremap(saved_rsdt.table.table_offset_entry[i], sizeof(struct acpi_table_header));
-               if (!header)
-                       break;
-               header = (struct acpi_table_header *)
-                       early_ioremap(saved_rsdt.table.table_offset_entry[i], header->length);
-               if (!header)
-                       break;
-
-               if (strncmp((char *) &header->signature, ACPI_SIG_SRAT, 4))
-                       continue;
-
-               /* we've found the srat table. don't need to look at any more tables */
-               return acpi20_parse_srat((struct acpi_table_srat *)header);
-       }
-out_err:
-       remove_all_active_ranges();
-       printk("failed to get NUMA memory information from SRAT table\n");
-       return 0;
-}
index ae75109..d67ce5f 100644 (file)
@@ -36,7 +36,9 @@ static struct rio_table_hdr *rio_table_hdr __initdata;
 static struct scal_detail   *scal_devs[MAX_NUMNODES] __initdata;
 static struct rio_detail    *rio_devs[MAX_NUMNODES*4] __initdata;
 
+#ifndef CONFIG_X86_NUMAQ
 static int mp_bus_id_to_node[MAX_MP_BUSSES] __initdata;
+#endif
 
 static int __init setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
 {
index d2ab52c..7066cb8 100644 (file)
@@ -19,8 +19,8 @@
 #include <linux/utsname.h>
 #include <linux/ipc.h>
 
-#include <asm/uaccess.h>
-#include <asm/unistd.h>
+#include <linux/uaccess.h>
+#include <linux/unistd.h>
 
 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
                          unsigned long prot, unsigned long flags,
@@ -103,7 +103,7 @@ asmlinkage int old_select(struct sel_arg_struct __user *arg)
  *
  * This is really horribly ugly.
  */
-asmlinkage int sys_ipc (uint call, int first, int second,
+asmlinkage int sys_ipc(uint call, int first, int second,
                        int third, void __user *ptr, long fifth)
 {
        int version, ret;
@@ -113,24 +113,24 @@ asmlinkage int sys_ipc (uint call, int first, int second,
 
        switch (call) {
        case SEMOP:
-               return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
+               return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
        case SEMTIMEDOP:
                return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
                                        (const struct timespec __user *)fifth);
 
        case SEMGET:
-               return sys_semget (first, second, third);
+               return sys_semget(first, second, third);
        case SEMCTL: {
                union semun fourth;
                if (!ptr)
                        return -EINVAL;
                if (get_user(fourth.__pad, (void __user * __user *) ptr))
                        return -EFAULT;
-               return sys_semctl (first, second, third, fourth);
+               return sys_semctl(first, second, third, fourth);
        }
 
        case MSGSND:
-               return sys_msgsnd (first, (struct msgbuf __user *) ptr, 
+               return sys_msgsnd(first, (struct msgbuf __user *) ptr,
                                   second, third);
        case MSGRCV:
                switch (version) {
@@ -138,45 +138,45 @@ asmlinkage int sys_ipc (uint call, int first, int second,
                        struct ipc_kludge tmp;
                        if (!ptr)
                                return -EINVAL;
-                       
+
                        if (copy_from_user(&tmp,
-                                          (struct ipc_kludge __user *) ptr, 
-                                          sizeof (tmp)))
+                                          (struct ipc_kludge __user *) ptr,
+                                          sizeof(tmp)))
                                return -EFAULT;
-                       return sys_msgrcv (first, tmp.msgp, second,
+                       return sys_msgrcv(first, tmp.msgp, second,
                                           tmp.msgtyp, third);
                }
                default:
-                       return sys_msgrcv (first,
+                       return sys_msgrcv(first,
                                           (struct msgbuf __user *) ptr,
                                           second, fifth, third);
                }
        case MSGGET:
-               return sys_msgget ((key_t) first, second);
+               return sys_msgget((key_t) first, second);
        case MSGCTL:
-               return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
+               return sys_msgctl(first, second, (struct msqid_ds __user *) ptr);
 
        case SHMAT:
                switch (version) {
                default: {
                        ulong raddr;
-                       ret = do_shmat (first, (char __user *) ptr, second, &raddr);
+                       ret = do_shmat(first, (char __user *) ptr, second, &raddr);
                        if (ret)
                                return ret;
-                       return put_user (raddr, (ulong __user *) third);
+                       return put_user(raddr, (ulong __user *) third);
                }
                case 1: /* iBCS2 emulator entry point */
                        if (!segment_eq(get_fs(), get_ds()))
                                return -EINVAL;
                        /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
-                       return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
+                       return do_shmat(first, (char __user *) ptr, second, (ulong *) third);
                }
-       case SHMDT: 
-               return sys_shmdt ((char __user *)ptr);
+       case SHMDT:
+               return sys_shmdt((char __user *)ptr);
        case SHMGET:
-               return sys_shmget (first, second, third);
+               return sys_shmget(first, second, third);
        case SHMCTL:
-               return sys_shmctl (first, second,
+               return sys_shmctl(first, second,
                                   (struct shmid_ds __user *) ptr);
        default:
                return -ENOSYS;
@@ -186,28 +186,28 @@ asmlinkage int sys_ipc (uint call, int first, int second,
 /*
  * Old cruft
  */
-asmlinkage int sys_uname(struct old_utsname __user * name)
+asmlinkage int sys_uname(struct old_utsname __user *name)
 {
        int err;
        if (!name)
                return -EFAULT;
        down_read(&uts_sem);
-       err = copy_to_user(name, utsname(), sizeof (*name));
+       err = copy_to_user(name, utsname(), sizeof(*name));
        up_read(&uts_sem);
-       return err?-EFAULT:0;
+       return err? -EFAULT:0;
 }
 
-asmlinkage int sys_olduname(struct oldold_utsname __user * name)
+asmlinkage int sys_olduname(struct oldold_utsname __user *name)
 {
        int error;
 
        if (!name)
                return -EFAULT;
-       if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
+       if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
                return -EFAULT;
-  
-       down_read(&uts_sem);
-       
+
+       down_read(&uts_sem);
+
        error = __copy_to_user(&name->sysname, &utsname()->sysname,
                               __OLD_UTS_LEN);
        error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
@@ -223,9 +223,9 @@ asmlinkage int sys_olduname(struct oldold_utsname __user * name)
        error |= __copy_to_user(&name->machine, &utsname()->machine,
                                __OLD_UTS_LEN);
        error |= __put_user(0, name->machine + __OLD_UTS_LEN);
-       
+
        up_read(&uts_sem);
-       
+
        error = error ? -EFAULT : 0;
 
        return error;
@@ -241,6 +241,6 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
        long __res;
        asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
        : "=a" (__res)
-       : "0" (__NR_execve),"ri" (filename),"c" (argv), "d" (envp) : "memory");
+       : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
        return __res;
 }
index 2ff21f3..059ca6e 100644 (file)
@@ -39,9 +39,6 @@
 
 #include "do_timer.h"
 
-unsigned int cpu_khz;  /* Detected as we calibrate the TSC */
-EXPORT_SYMBOL(cpu_khz);
-
 int timer_ack;
 
 unsigned long profile_pc(struct pt_regs *regs)
@@ -84,8 +81,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id)
        if (timer_ack) {
                /*
                 * Subtle, when I/O APICs are used we have to ack timer IRQ
-                * manually to reset the IRR bit for do_slow_gettimeoffset().
-                * This will also deassert NMI lines for the watchdog if run
+                * manually to deassert NMI lines for the watchdog if run
                 * on an 82489DX-based system.
                 */
                spin_lock(&i8259A_lock);
index c737849..e3d49c5 100644 (file)
@@ -56,7 +56,7 @@ static irqreturn_t timer_event_interrupt(int irq, void *dev_id)
 /* calibrate_cpu is used on systems with fixed rate TSCs to determine
  * processor frequency */
 #define TICK_COUNT 100000000
-unsigned long __init native_calculate_cpu_khz(void)
+unsigned long __init calibrate_cpu(void)
 {
        int tsc_start, tsc_now;
        int i, no_ctr_free;
@@ -116,23 +116,11 @@ void __init hpet_time_init(void)
 
 void __init time_init(void)
 {
-       tsc_calibrate();
-
-       cpu_khz = tsc_khz;
-       if (cpu_has(&boot_cpu_data, X86_FEATURE_CONSTANT_TSC) &&
-               (boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
-               cpu_khz = calculate_cpu_khz();
-
-       if (unsynchronized_tsc())
-               mark_tsc_unstable("TSCs unsynchronized");
-
+       tsc_init();
        if (cpu_has(&boot_cpu_data, X86_FEATURE_RDTSCP))
                vgetcpu_mode = VGETCPU_RDTSCP;
        else
                vgetcpu_mode = VGETCPU_LSL;
 
-       printk(KERN_INFO "time.c: Detected %d.%03d MHz processor.\n",
-               cpu_khz / 1000, cpu_khz % 1000);
-       init_tsc_clocksource();
        late_time_init = choose_time_init();
 }
index a1f07d7..5039d0f 100644 (file)
@@ -15,6 +15,8 @@
 #include <asm/proto.h>
 #include <asm/apicdef.h>
 #include <asm/idle.h>
+#include <asm/uv/uv_hub.h>
+#include <asm/uv/uv_bau.h>
 
 #include <mach_ipi.h>
 /*
@@ -162,6 +164,9 @@ void native_flush_tlb_others(const cpumask_t *cpumaskp, struct mm_struct *mm,
        union smp_flush_state *f;
        cpumask_t cpumask = *cpumaskp;
 
+       if (is_uv_system() && uv_flush_tlb_others(&cpumask, mm, va))
+               return;
+
        /* Caller has disabled preemption */
        sender = smp_processor_id() % NUM_INVALIDATE_TLB_VECTORS;
        f = &per_cpu(flush_state, sender);
diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c
new file mode 100644 (file)
index 0000000..d0fbb77
--- /dev/null
@@ -0,0 +1,792 @@
+/*
+ *     SGI UltraViolet TLB flush routines.
+ *
+ *     (c) 2008 Cliff Wickman <cpw@sgi.com>, SGI.
+ *
+ *     This code is released under the GNU General Public License version 2 or
+ *     later.
+ */
+#include <linux/mc146818rtc.h>
+#include <linux/proc_fs.h>
+#include <linux/kernel.h>
+
+#include <asm/mmu_context.h>
+#include <asm/uv/uv_mmrs.h>
+#include <asm/uv/uv_hub.h>
+#include <asm/uv/uv_bau.h>
+#include <asm/genapic.h>
+#include <asm/idle.h>
+#include <asm/tsc.h>
+
+#include <mach_apic.h>
+
+static struct bau_control      **uv_bau_table_bases __read_mostly;
+static int                     uv_bau_retry_limit __read_mostly;
+
+/* position of pnode (which is nasid>>1): */
+static int                     uv_nshift __read_mostly;
+
+static unsigned long           uv_mmask __read_mostly;
+
+static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
+static DEFINE_PER_CPU(struct bau_control, bau_control);
+
+/*
+ * Free a software acknowledge hardware resource by clearing its Pending
+ * bit. This will return a reply to the sender.
+ * If the message has timed out, a reply has already been sent by the
+ * hardware but the resource has not been released. In that case our
+ * clear of the Timeout bit (as well) will free the resource. No reply will
+ * be sent (the hardware will only do one reply per message).
+ */
+static void uv_reply_to_message(int resource,
+                               struct bau_payload_queue_entry *msg,
+                               struct bau_msg_status *msp)
+{
+       unsigned long dw;
+
+       dw = (1 << (resource + UV_SW_ACK_NPENDING)) | (1 << resource);
+       msg->replied_to = 1;
+       msg->sw_ack_vector = 0;
+       if (msp)
+               msp->seen_by.bits = 0;
+       uv_write_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
+}
+
+/*
+ * Do all the things a cpu should do for a TLB shootdown message.
+ * Other cpu's may come here at the same time for this message.
+ */
+static void uv_bau_process_message(struct bau_payload_queue_entry *msg,
+                                  int msg_slot, int sw_ack_slot)
+{
+       unsigned long this_cpu_mask;
+       struct bau_msg_status *msp;
+       int cpu;
+
+       msp = __get_cpu_var(bau_control).msg_statuses + msg_slot;
+       cpu = uv_blade_processor_id();
+       msg->number_of_cpus =
+           uv_blade_nr_online_cpus(uv_node_to_blade_id(numa_node_id()));
+       this_cpu_mask = 1UL << cpu;
+       if (msp->seen_by.bits & this_cpu_mask)
+               return;
+       atomic_or_long(&msp->seen_by.bits, this_cpu_mask);
+
+       if (msg->replied_to == 1)
+               return;
+
+       if (msg->address == TLB_FLUSH_ALL) {
+               local_flush_tlb();
+               __get_cpu_var(ptcstats).alltlb++;
+       } else {
+               __flush_tlb_one(msg->address);
+               __get_cpu_var(ptcstats).onetlb++;
+       }
+
+       __get_cpu_var(ptcstats).requestee++;
+
+       atomic_inc_short(&msg->acknowledge_count);
+       if (msg->number_of_cpus == msg->acknowledge_count)
+               uv_reply_to_message(sw_ack_slot, msg, msp);
+}
+
+/*
+ * Examine the payload queue on one distribution node to see
+ * which messages have not been seen, and which cpu(s) have not seen them.
+ *
+ * Returns the number of cpu's that have not responded.
+ */
+static int uv_examine_destination(struct bau_control *bau_tablesp, int sender)
+{
+       struct bau_payload_queue_entry *msg;
+       struct bau_msg_status *msp;
+       int count = 0;
+       int i;
+       int j;
+
+       for (msg = bau_tablesp->va_queue_first, i = 0; i < DEST_Q_SIZE;
+            msg++, i++) {
+               if ((msg->sending_cpu == sender) && (!msg->replied_to)) {
+                       msp = bau_tablesp->msg_statuses + i;
+                       printk(KERN_DEBUG
+                              "blade %d: address:%#lx %d of %d, not cpu(s): ",
+                              i, msg->address, msg->acknowledge_count,
+                              msg->number_of_cpus);
+                       for (j = 0; j < msg->number_of_cpus; j++) {
+                               if (!((1L << j) & msp->seen_by.bits)) {
+                                       count++;
+                                       printk("%d ", j);
+                               }
+                       }
+                       printk("\n");
+               }
+       }
+       return count;
+}
+
+/*
+ * Examine the payload queue on all the distribution nodes to see
+ * which messages have not been seen, and which cpu(s) have not seen them.
+ *
+ * Returns the number of cpu's that have not responded.
+ */
+static int uv_examine_destinations(struct bau_target_nodemask *distribution)
+{
+       int sender;
+       int i;
+       int count = 0;
+
+       sender = smp_processor_id();
+       for (i = 0; i < sizeof(struct bau_target_nodemask) * BITSPERBYTE; i++) {
+               if (!bau_node_isset(i, distribution))
+                       continue;
+               count += uv_examine_destination(uv_bau_table_bases[i], sender);
+       }
+       return count;
+}
+
+/*
+ * wait for completion of a broadcast message
+ *
+ * return COMPLETE, RETRY or GIVEUP
+ */
+static int uv_wait_completion(struct bau_desc *bau_desc,
+                             unsigned long mmr_offset, int right_shift)
+{
+       int exams = 0;
+       long destination_timeouts = 0;
+       long source_timeouts = 0;
+       unsigned long descriptor_status;
+
+       while ((descriptor_status = (((unsigned long)
+               uv_read_local_mmr(mmr_offset) >>
+                       right_shift) & UV_ACT_STATUS_MASK)) !=
+                       DESC_STATUS_IDLE) {
+               if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
+                       source_timeouts++;
+                       if (source_timeouts > SOURCE_TIMEOUT_LIMIT)
+                               source_timeouts = 0;
+                       __get_cpu_var(ptcstats).s_retry++;
+                       return FLUSH_RETRY;
+               }
+               /*
+                * spin here looking for progress at the destinations
+                */
+               if (descriptor_status == DESC_STATUS_DESTINATION_TIMEOUT) {
+                       destination_timeouts++;
+                       if (destination_timeouts > DESTINATION_TIMEOUT_LIMIT) {
+                               /*
+                                * returns number of cpus not responding
+                                */
+                               if (uv_examine_destinations
+                                   (&bau_desc->distribution) == 0) {
+                                       __get_cpu_var(ptcstats).d_retry++;
+                                       return FLUSH_RETRY;
+                               }
+                               exams++;
+                               if (exams >= uv_bau_retry_limit) {
+                                       printk(KERN_DEBUG
+                                              "uv_flush_tlb_others");
+                                       printk("giving up on cpu %d\n",
+                                              smp_processor_id());
+                                       return FLUSH_GIVEUP;
+                               }
+                               /*
+                                * delays can hang the simulator
+                                  udelay(1000);
+                                */
+                               destination_timeouts = 0;
+                       }
+               }
+       }
+       return FLUSH_COMPLETE;
+}
+
+/**
+ * uv_flush_send_and_wait
+ *
+ * Send a broadcast and wait for a broadcast message to complete.
+ *
+ * The cpumaskp mask contains the cpus the broadcast was sent to.
+ *
+ * Returns 1 if all remote flushing was done. The mask is zeroed.
+ * Returns 0 if some remote flushing remains to be done. The mask is left
+ * unchanged.
+ */
+int uv_flush_send_and_wait(int cpu, int this_blade, struct bau_desc *bau_desc,
+                          cpumask_t *cpumaskp)
+{
+       int completion_status = 0;
+       int right_shift;
+       int tries = 0;
+       int blade;
+       int bit;
+       unsigned long mmr_offset;
+       unsigned long index;
+       cycles_t time1;
+       cycles_t time2;
+
+       if (cpu < UV_CPUS_PER_ACT_STATUS) {
+               mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
+               right_shift = cpu * UV_ACT_STATUS_SIZE;
+       } else {
+               mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_1;
+               right_shift =
+                   ((cpu - UV_CPUS_PER_ACT_STATUS) * UV_ACT_STATUS_SIZE);
+       }
+       time1 = get_cycles();
+       do {
+               tries++;
+               index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
+                       cpu;
+               uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
+               completion_status = uv_wait_completion(bau_desc, mmr_offset,
+                                       right_shift);
+       } while (completion_status == FLUSH_RETRY);
+       time2 = get_cycles();
+       __get_cpu_var(ptcstats).sflush += (time2 - time1);
+       if (tries > 1)
+               __get_cpu_var(ptcstats).retriesok++;
+
+       if (completion_status == FLUSH_GIVEUP) {
+               /*
+                * Cause the caller to do an IPI-style TLB shootdown on
+                * the cpu's, all of which are still in the mask.
+                */
+               __get_cpu_var(ptcstats).ptc_i++;
+               return 0;
+       }
+
+       /*
+        * Success, so clear the remote cpu's from the mask so we don't
+        * use the IPI method of shootdown on them.
+        */
+       for_each_cpu_mask(bit, *cpumaskp) {
+               blade = uv_cpu_to_blade_id(bit);
+               if (blade == this_blade)
+                       continue;
+               cpu_clear(bit, *cpumaskp);
+       }
+       if (!cpus_empty(*cpumaskp))
+               return 0;
+       return 1;
+}
+
+/**
+ * uv_flush_tlb_others - globally purge translation cache of a virtual
+ * address or all TLB's
+ * @cpumaskp: mask of all cpu's in which the address is to be removed
+ * @mm: mm_struct containing virtual address range
+ * @va: virtual address to be removed (or TLB_FLUSH_ALL for all TLB's on cpu)
+ *
+ * This is the entry point for initiating any UV global TLB shootdown.
+ *
+ * Purges the translation caches of all specified processors of the given
+ * virtual address, or purges all TLB's on specified processors.
+ *
+ * The caller has derived the cpumaskp from the mm_struct and has subtracted
+ * the local cpu from the mask.  This function is called only if there
+ * are bits set in the mask. (e.g. flush_tlb_page())
+ *
+ * The cpumaskp is converted into a nodemask of the nodes containing
+ * the cpus.
+ *
+ * Returns 1 if all remote flushing was done.
+ * Returns 0 if some remote flushing remains to be done.
+ */
+int uv_flush_tlb_others(cpumask_t *cpumaskp, struct mm_struct *mm,
+                       unsigned long va)
+{
+       int i;
+       int bit;
+       int blade;
+       int cpu;
+       int this_blade;
+       int locals = 0;
+       struct bau_desc *bau_desc;
+
+       cpu = uv_blade_processor_id();
+       this_blade = uv_numa_blade_id();
+       bau_desc = __get_cpu_var(bau_control).descriptor_base;
+       bau_desc += UV_ITEMS_PER_DESCRIPTOR * cpu;
+
+       bau_nodes_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
+
+       i = 0;
+       for_each_cpu_mask(bit, *cpumaskp) {
+               blade = uv_cpu_to_blade_id(bit);
+               BUG_ON(blade > (UV_DISTRIBUTION_SIZE - 1));
+               if (blade == this_blade) {
+                       locals++;
+                       continue;
+               }
+               bau_node_set(blade, &bau_desc->distribution);
+               i++;
+       }
+       if (i == 0) {
+               /*
+                * no off_node flushing; return status for local node
+                */
+               if (locals)
+                       return 0;
+               else
+                       return 1;
+       }
+       __get_cpu_var(ptcstats).requestor++;
+       __get_cpu_var(ptcstats).ntargeted += i;
+
+       bau_desc->payload.address = va;
+       bau_desc->payload.sending_cpu = smp_processor_id();
+
+       return uv_flush_send_and_wait(cpu, this_blade, bau_desc, cpumaskp);
+}
+
+/*
+ * The BAU message interrupt comes here. (registered by set_intr_gate)
+ * See entry_64.S
+ *
+ * We received a broadcast assist message.
+ *
+ * Interrupts may have been disabled; this interrupt could represent
+ * the receipt of several messages.
+ *
+ * All cores/threads on this node get this interrupt.
+ * The last one to see it does the s/w ack.
+ * (the resource will not be freed until noninterruptable cpus see this
+ *  interrupt; hardware will timeout the s/w ack and reply ERROR)
+ */
+void uv_bau_message_interrupt(struct pt_regs *regs)
+{
+       struct bau_payload_queue_entry *va_queue_first;
+       struct bau_payload_queue_entry *va_queue_last;
+       struct bau_payload_queue_entry *msg;
+       struct pt_regs *old_regs = set_irq_regs(regs);
+       cycles_t time1;
+       cycles_t time2;
+       int msg_slot;
+       int sw_ack_slot;
+       int fw;
+       int count = 0;
+       unsigned long local_pnode;
+
+       ack_APIC_irq();
+       exit_idle();
+       irq_enter();
+
+       time1 = get_cycles();
+
+       local_pnode = uv_blade_to_pnode(uv_numa_blade_id());
+
+       va_queue_first = __get_cpu_var(bau_control).va_queue_first;
+       va_queue_last = __get_cpu_var(bau_control).va_queue_last;
+
+       msg = __get_cpu_var(bau_control).bau_msg_head;
+       while (msg->sw_ack_vector) {
+               count++;
+               fw = msg->sw_ack_vector;
+               msg_slot = msg - va_queue_first;
+               sw_ack_slot = ffs(fw) - 1;
+
+               uv_bau_process_message(msg, msg_slot, sw_ack_slot);
+
+               msg++;
+               if (msg > va_queue_last)
+                       msg = va_queue_first;
+               __get_cpu_var(bau_control).bau_msg_head = msg;
+       }
+       if (!count)
+               __get_cpu_var(ptcstats).nomsg++;
+       else if (count > 1)
+               __get_cpu_var(ptcstats).multmsg++;
+
+       time2 = get_cycles();
+       __get_cpu_var(ptcstats).dflush += (time2 - time1);
+
+       irq_exit();
+       set_irq_regs(old_regs);
+}
+
+static void uv_enable_timeouts(void)
+{
+       int i;
+       int blade;
+       int last_blade;
+       int pnode;
+       int cur_cpu = 0;
+       unsigned long apicid;
+
+       last_blade = -1;
+       for_each_online_node(i) {
+               blade = uv_node_to_blade_id(i);
+               if (blade == last_blade)
+                       continue;
+               last_blade = blade;
+               apicid = per_cpu(x86_cpu_to_apicid, cur_cpu);
+               pnode = uv_blade_to_pnode(blade);
+               cur_cpu += uv_blade_nr_possible_cpus(i);
+       }
+}
+
+static void *uv_ptc_seq_start(struct seq_file *file, loff_t *offset)
+{
+       if (*offset < num_possible_cpus())
+               return offset;
+       return NULL;
+}
+
+static void *uv_ptc_seq_next(struct seq_file *file, void *data, loff_t *offset)
+{
+       (*offset)++;
+       if (*offset < num_possible_cpus())
+               return offset;
+       return NULL;
+}
+
+static void uv_ptc_seq_stop(struct seq_file *file, void *data)
+{
+}
+
+/*
+ * Display the statistics thru /proc
+ * data points to the cpu number
+ */
+static int uv_ptc_seq_show(struct seq_file *file, void *data)
+{
+       struct ptc_stats *stat;
+       int cpu;
+
+       cpu = *(loff_t *)data;
+
+       if (!cpu) {
+               seq_printf(file,
+               "# cpu requestor requestee one all sretry dretry ptc_i ");
+               seq_printf(file,
+               "sw_ack sflush dflush sok dnomsg dmult starget\n");
+       }
+       if (cpu < num_possible_cpus() && cpu_online(cpu)) {
+               stat = &per_cpu(ptcstats, cpu);
+               seq_printf(file, "cpu %d %ld %ld %ld %ld %ld %ld %ld ",
+                          cpu, stat->requestor,
+                          stat->requestee, stat->onetlb, stat->alltlb,
+                          stat->s_retry, stat->d_retry, stat->ptc_i);
+               seq_printf(file, "%lx %ld %ld %ld %ld %ld %ld\n",
+                          uv_read_global_mmr64(uv_blade_to_pnode
+                                       (uv_cpu_to_blade_id(cpu)),
+                                       UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
+                          stat->sflush, stat->dflush,
+                          stat->retriesok, stat->nomsg,
+                          stat->multmsg, stat->ntargeted);
+       }
+
+       return 0;
+}
+
+/*
+ *  0: display meaning of the statistics
+ * >0: retry limit
+ */
+static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
+                                size_t count, loff_t *data)
+{
+       long newmode;
+       char optstr[64];
+
+       if (count == 0 || count > sizeof(optstr))
+               return -EINVAL;
+       if (copy_from_user(optstr, user, count))
+               return -EFAULT;
+       optstr[count - 1] = '\0';
+       if (strict_strtoul(optstr, 10, &newmode) < 0) {
+               printk(KERN_DEBUG "%s is invalid\n", optstr);
+               return -EINVAL;
+       }
+
+       if (newmode == 0) {
+               printk(KERN_DEBUG "# cpu:      cpu number\n");
+               printk(KERN_DEBUG
+               "requestor:  times this cpu was the flush requestor\n");
+               printk(KERN_DEBUG
+               "requestee:  times this cpu was requested to flush its TLBs\n");
+               printk(KERN_DEBUG
+               "one:        times requested to flush a single address\n");
+               printk(KERN_DEBUG
+               "all:        times requested to flush all TLB's\n");
+               printk(KERN_DEBUG
+               "sretry:     number of retries of source-side timeouts\n");
+               printk(KERN_DEBUG
+               "dretry:     number of retries of destination-side timeouts\n");
+               printk(KERN_DEBUG
+               "ptc_i:      times UV fell through to IPI-style flushes\n");
+               printk(KERN_DEBUG
+               "sw_ack:     image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
+               printk(KERN_DEBUG
+               "sflush_us:  cycles spent in uv_flush_tlb_others()\n");
+               printk(KERN_DEBUG
+               "dflush_us:  cycles spent in handling flush requests\n");
+               printk(KERN_DEBUG "sok:        successes on retry\n");
+               printk(KERN_DEBUG "dnomsg:     interrupts with no message\n");
+               printk(KERN_DEBUG
+               "dmult:      interrupts with multiple messages\n");
+               printk(KERN_DEBUG "starget:    nodes targeted\n");
+       } else {
+               uv_bau_retry_limit = newmode;
+               printk(KERN_DEBUG "timeout retry limit:%d\n",
+                      uv_bau_retry_limit);
+       }
+
+       return count;
+}
+
+static const struct seq_operations uv_ptc_seq_ops = {
+       .start          = uv_ptc_seq_start,
+       .next           = uv_ptc_seq_next,
+       .stop           = uv_ptc_seq_stop,
+       .show           = uv_ptc_seq_show
+};
+
+static int uv_ptc_proc_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &uv_ptc_seq_ops);
+}
+
+static const struct file_operations proc_uv_ptc_operations = {
+       .open           = uv_ptc_proc_open,
+       .read           = seq_read,
+       .write          = uv_ptc_proc_write,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+
+static int __init uv_ptc_init(void)
+{
+       struct proc_dir_entry *proc_uv_ptc;
+
+       if (!is_uv_system())
+               return 0;
+
+       if (!proc_mkdir("sgi_uv", NULL))
+               return -EINVAL;
+
+       proc_uv_ptc = create_proc_entry(UV_PTC_BASENAME, 0444, NULL);
+       if (!proc_uv_ptc) {
+               printk(KERN_ERR "unable to create %s proc entry\n",
+                      UV_PTC_BASENAME);
+               remove_proc_entry("sgi_uv", NULL);
+               return -EINVAL;
+       }
+       proc_uv_ptc->proc_fops = &proc_uv_ptc_operations;
+       return 0;
+}
+
+/*
+ * begin the initialization of the per-blade control structures
+ */
+static struct bau_control * __init uv_table_bases_init(int blade, int node)
+{
+       int i;
+       int *ip;
+       struct bau_msg_status *msp;
+       struct bau_control *bau_tabp;
+
+       bau_tabp =
+           kmalloc_node(sizeof(struct bau_control), GFP_KERNEL, node);
+       BUG_ON(!bau_tabp);
+
+       bau_tabp->msg_statuses =
+           kmalloc_node(sizeof(struct bau_msg_status) *
+                        DEST_Q_SIZE, GFP_KERNEL, node);
+       BUG_ON(!bau_tabp->msg_statuses);
+
+       for (i = 0, msp = bau_tabp->msg_statuses; i < DEST_Q_SIZE; i++, msp++)
+               bau_cpubits_clear(&msp->seen_by, (int)
+                                 uv_blade_nr_possible_cpus(blade));
+
+       bau_tabp->watching =
+           kmalloc_node(sizeof(int) * DEST_NUM_RESOURCES, GFP_KERNEL, node);
+       BUG_ON(!bau_tabp->watching);
+
+       for (i = 0, ip = bau_tabp->watching; i < DEST_Q_SIZE; i++, ip++)
+               *ip = 0;
+
+       uv_bau_table_bases[blade] = bau_tabp;
+
+       return bau_tabp;
+}
+
+/*
+ * finish the initialization of the per-blade control structures
+ */
+static void __init
+uv_table_bases_finish(int blade, int node, int cur_cpu,
+                     struct bau_control *bau_tablesp,
+                     struct bau_desc *adp)
+{
+       struct bau_control *bcp;
+       int i;
+
+       for (i = cur_cpu; i < cur_cpu + uv_blade_nr_possible_cpus(blade); i++) {
+               bcp = (struct bau_control *)&per_cpu(bau_control, i);
+
+               bcp->bau_msg_head       = bau_tablesp->va_queue_first;
+               bcp->va_queue_first     = bau_tablesp->va_queue_first;
+               bcp->va_queue_last      = bau_tablesp->va_queue_last;
+               bcp->watching           = bau_tablesp->watching;
+               bcp->msg_statuses       = bau_tablesp->msg_statuses;
+               bcp->descriptor_base    = adp;
+       }
+}
+
+/*
+ * initialize the sending side's sending buffers
+ */
+static struct bau_desc * __init
+uv_activation_descriptor_init(int node, int pnode)
+{
+       int i;
+       unsigned long pa;
+       unsigned long m;
+       unsigned long n;
+       unsigned long mmr_image;
+       struct bau_desc *adp;
+       struct bau_desc *ad2;
+
+       adp = (struct bau_desc *)
+           kmalloc_node(16384, GFP_KERNEL, node);
+       BUG_ON(!adp);
+
+       pa = __pa((unsigned long)adp);
+       n = pa >> uv_nshift;
+       m = pa & uv_mmask;
+
+       mmr_image = uv_read_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE);
+       if (mmr_image) {
+               uv_write_global_mmr64(pnode, (unsigned long)
+                                     UVH_LB_BAU_SB_DESCRIPTOR_BASE,
+                                     (n << UV_DESC_BASE_PNODE_SHIFT | m));
+       }
+
+       for (i = 0, ad2 = adp; i < UV_ACTIVATION_DESCRIPTOR_SIZE; i++, ad2++) {
+               memset(ad2, 0, sizeof(struct bau_desc));
+               ad2->header.sw_ack_flag = 1;
+               ad2->header.base_dest_nodeid =
+                   uv_blade_to_pnode(uv_cpu_to_blade_id(0));
+               ad2->header.command = UV_NET_ENDPOINT_INTD;
+               ad2->header.int_both = 1;
+               /*
+                * all others need to be set to zero:
+                *   fairness chaining multilevel count replied_to
+                */
+       }
+       return adp;
+}
+
+/*
+ * initialize the destination side's receiving buffers
+ */
+static struct bau_payload_queue_entry * __init
+uv_payload_queue_init(int node, int pnode, struct bau_control *bau_tablesp)
+{
+       struct bau_payload_queue_entry *pqp;
+       char *cp;
+
+       pqp = (struct bau_payload_queue_entry *) kmalloc_node(
+               (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
+               GFP_KERNEL, node);
+       BUG_ON(!pqp);
+
+       cp = (char *)pqp + 31;
+       pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
+       bau_tablesp->va_queue_first = pqp;
+       uv_write_global_mmr64(pnode,
+                             UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
+                             ((unsigned long)pnode <<
+                              UV_PAYLOADQ_PNODE_SHIFT) |
+                             uv_physnodeaddr(pqp));
+       uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
+                             uv_physnodeaddr(pqp));
+       bau_tablesp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
+       uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
+                             (unsigned long)
+                             uv_physnodeaddr(bau_tablesp->va_queue_last));
+       memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
+
+       return pqp;
+}
+
+/*
+ * Initialization of each UV blade's structures
+ */
+static int __init uv_init_blade(int blade, int node, int cur_cpu)
+{
+       int pnode;
+       unsigned long pa;
+       unsigned long apicid;
+       struct bau_desc *adp;
+       struct bau_payload_queue_entry *pqp;
+       struct bau_control *bau_tablesp;
+
+       bau_tablesp = uv_table_bases_init(blade, node);
+       pnode = uv_blade_to_pnode(blade);
+       adp = uv_activation_descriptor_init(node, pnode);
+       pqp = uv_payload_queue_init(node, pnode, bau_tablesp);
+       uv_table_bases_finish(blade, node, cur_cpu, bau_tablesp, adp);
+       /*
+        * the below initialization can't be in firmware because the
+        * messaging IRQ will be determined by the OS
+        */
+       apicid = per_cpu(x86_cpu_to_apicid, cur_cpu);
+       pa = uv_read_global_mmr64(pnode, UVH_BAU_DATA_CONFIG);
+       if ((pa & 0xff) != UV_BAU_MESSAGE) {
+               uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
+                                     ((apicid << 32) | UV_BAU_MESSAGE));
+       }
+       return 0;
+}
+
+/*
+ * Initialization of BAU-related structures
+ */
+static int __init uv_bau_init(void)
+{
+       int blade;
+       int node;
+       int nblades;
+       int last_blade;
+       int cur_cpu = 0;
+
+       if (!is_uv_system())
+               return 0;
+
+       uv_bau_retry_limit = 1;
+       uv_nshift = uv_hub_info->n_val;
+       uv_mmask = (1UL << uv_hub_info->n_val) - 1;
+       nblades = 0;
+       last_blade = -1;
+       for_each_online_node(node) {
+               blade = uv_node_to_blade_id(node);
+               if (blade == last_blade)
+                       continue;
+               last_blade = blade;
+               nblades++;
+       }
+       uv_bau_table_bases = (struct bau_control **)
+           kmalloc(nblades * sizeof(struct bau_control *), GFP_KERNEL);
+       BUG_ON(!uv_bau_table_bases);
+
+       last_blade = -1;
+       for_each_online_node(node) {
+               blade = uv_node_to_blade_id(node);
+               if (blade == last_blade)
+                       continue;
+               last_blade = blade;
+               uv_init_blade(blade, node, cur_cpu);
+               cur_cpu += uv_blade_nr_possible_cpus(blade);
+       }
+       set_intr_gate(UV_BAU_MESSAGE, uv_bau_message_intr1);
+       uv_enable_timeouts();
+
+       return 0;
+}
+__initcall(uv_bau_init);
+__initcall(uv_ptc_init);
index abbf199..1106fac 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <asm/trampoline.h>
 
-/* ready for x86_64, no harm for x86, since it will overwrite after alloc */
+/* ready for x86_64 and x86 */
 unsigned char *trampoline_base = __va(TRAMPOLINE_BASE);
 
 /*
index 08d752d..8a76897 100644 (file)
@@ -1,5 +1,6 @@
 /*
  *  Copyright (C) 1991, 1992  Linus Torvalds
+ *  Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
  *
  *  Pentium III FXSR, SSE support
  *     Gareth Hughes <gareth@valinux.com>, May 2000
@@ -60,8 +61,6 @@
 
 #include "mach_traps.h"
 
-int panic_on_unrecovered_nmi;
-
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
 
@@ -98,19 +97,22 @@ asmlinkage void alignment_check(void);
 asmlinkage void spurious_interrupt_bug(void);
 asmlinkage void machine_check(void);
 
+int panic_on_unrecovered_nmi;
 int kstack_depth_to_print = 24;
 static unsigned int code_bytes = 64;
+static int ignore_nmis;
+static int die_counter;
 
 void printk_address(unsigned long address, int reliable)
 {
 #ifdef CONFIG_KALLSYMS
-       char namebuf[KSYM_NAME_LEN];
        unsigned long offset = 0;
        unsigned long symsize;
        const char *symname;
-       char reliab[4] = "";
-       char *delim = ":";
        char *modname;
+       char *delim = ":";
+       char namebuf[KSYM_NAME_LEN];
+       char reliab[4] = "";
 
        symname = kallsyms_lookup(address, &symsize, &offset,
                                        &modname, namebuf);
@@ -130,22 +132,23 @@ void printk_address(unsigned long address, int reliable)
 #endif
 }
 
-static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned size)
+static inline int valid_stack_ptr(struct thread_info *tinfo,
+                       void *p, unsigned int size)
 {
-       return  p > (void *)tinfo &&
-               p <= (void *)tinfo + THREAD_SIZE - size;
+       void *t = tinfo;
+       return  p > t && p <= t + THREAD_SIZE - size;
 }
 
 /* The form of the top of the frame on the stack */
 struct stack_frame {
-       struct stack_frame      *next_frame;
-       unsigned long           return_address;
+       struct stack_frame *next_frame;
+       unsigned long return_address;
 };
 
 static inline unsigned long
 print_context_stack(struct thread_info *tinfo,
-                   unsigned long *stack, unsigned long bp,
-                   const struct stacktrace_ops *ops, void *data)
+               unsigned long *stack, unsigned long bp,
+               const struct stacktrace_ops *ops, void *data)
 {
        struct stack_frame *frame = (struct stack_frame *)bp;
 
@@ -167,8 +170,6 @@ print_context_stack(struct thread_info *tinfo,
        return bp;
 }
 
-#define MSG(msg)               ops->warning(data, msg)
-
 void dump_trace(struct task_struct *task, struct pt_regs *regs,
                unsigned long *stack, unsigned long bp,
                const struct stacktrace_ops *ops, void *data)
@@ -178,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
 
        if (!stack) {
                unsigned long dummy;
-
                stack = &dummy;
                if (task != current)
                        stack = (unsigned long *)task->thread.sp;
@@ -196,7 +196,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
        }
 #endif
 
-       while (1) {
+       for (;;) {
                struct thread_info *context;
 
                context = (struct thread_info *)
@@ -248,10 +248,10 @@ static void print_trace_address(void *data, unsigned long addr, int reliable)
 }
 
 static const struct stacktrace_ops print_trace_ops = {
-       .warning                = print_trace_warning,
-       .warning_symbol         = print_trace_warning_symbol,
-       .stack                  = print_trace_stack,
-       .address                = print_trace_address,
+       .warning = print_trace_warning,
+       .warning_symbol = print_trace_warning_symbol,
+       .stack = print_trace_stack,
+       .address = print_trace_address,
 };
 
 static void
@@ -351,15 +351,14 @@ void show_registers(struct pt_regs *regs)
                printk(KERN_EMERG "Code: ");
 
                ip = (u8 *)regs->ip - code_prologue;
-               if (ip < (u8 *)PAGE_OFFSET ||
-                       probe_kernel_address(ip, c)) {
+               if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
                        /* try starting at EIP */
                        ip = (u8 *)regs->ip;
                        code_len = code_len - code_prologue + 1;
                }
                for (i = 0; i < code_len; i++, ip++) {
                        if (ip < (u8 *)PAGE_OFFSET ||
-                               probe_kernel_address(ip, c)) {
+                                       probe_kernel_address(ip, c)) {
                                printk(" Bad EIP value.");
                                break;
                        }
@@ -384,8 +383,6 @@ int is_valid_bugaddr(unsigned long ip)
        return ud2 == 0x0b0f;
 }
 
-static int die_counter;
-
 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
 {
        unsigned short ss;
@@ -402,26 +399,22 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
        printk("DEBUG_PAGEALLOC");
 #endif
        printk("\n");
-
        if (notify_die(DIE_OOPS, str, regs, err,
-                       current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) {
-
-               show_registers(regs);
-               /* Executive summary in case the oops scrolled away */
-               sp = (unsigned long) (&regs->sp);
-               savesegment(ss, ss);
-               if (user_mode(regs)) {
-                       sp = regs->sp;
-                       ss = regs->ss & 0xffff;
-               }
-               printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip);
-               print_symbol("%s", regs->ip);
-               printk(" SS:ESP %04x:%08lx\n", ss, sp);
+                       current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
+               return 1;
 
-               return 0;
+       show_registers(regs);
+       /* Executive summary in case the oops scrolled away */
+       sp = (unsigned long) (&regs->sp);
+       savesegment(ss, ss);
+       if (user_mode(regs)) {
+               sp = regs->sp;
+               ss = regs->ss & 0xffff;
        }
-
-       return 1;
+       printk(KERN_EMERG "EIP: [<%08lx>] ", regs->ip);
+       print_symbol("%s", regs->ip);
+       printk(" SS:ESP %04x:%08lx\n", ss, sp);
+       return 0;
 }
 
 /*
@@ -546,7 +539,7 @@ void do_##name(struct pt_regs *regs, long error_code)                       \
 {                                                                      \
        trace_hardirqs_fixup();                                         \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
-                                               == NOTIFY_STOP)         \
+                                                       == NOTIFY_STOP) \
                return;                                                 \
        do_trap(trapnr, signr, str, 0, regs, error_code, NULL);         \
 }
@@ -562,7 +555,7 @@ void do_##name(struct pt_regs *regs, long error_code)                       \
        info.si_code = sicode;                                          \
        info.si_addr = (void __user *)siaddr;                           \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
-                                               == NOTIFY_STOP)         \
+                                                       == NOTIFY_STOP) \
                return;                                                 \
        do_trap(trapnr, signr, str, 0, regs, error_code, &info);        \
 }
@@ -571,7 +564,7 @@ void do_##name(struct pt_regs *regs, long error_code)                       \
 void do_##name(struct pt_regs *regs, long error_code)                  \
 {                                                                      \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
-                                               == NOTIFY_STOP)         \
+                                                       == NOTIFY_STOP) \
                return;                                                 \
        do_trap(trapnr, signr, str, 1, regs, error_code, NULL);         \
 }
@@ -586,27 +579,29 @@ void do_##name(struct pt_regs *regs, long error_code)                     \
        info.si_addr = (void __user *)siaddr;                           \
        trace_hardirqs_fixup();                                         \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
-                                               == NOTIFY_STOP)         \
+                                                       == NOTIFY_STOP) \
                return;                                                 \
        do_trap(trapnr, signr, str, 1, regs, error_code, &info);        \
 }
 
-DO_VM86_ERROR_INFO(0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->ip)
+DO_VM86_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
 #ifndef CONFIG_KPROBES
 DO_VM86_ERROR(3, SIGTRAP, "int3", int3)
 #endif
 DO_VM86_ERROR(4, SIGSEGV, "overflow", overflow)
 DO_VM86_ERROR(5, SIGSEGV, "bounds", bounds)
-DO_ERROR_INFO(6, SIGILL,  "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
-DO_ERROR(9, SIGFPE,  "coprocessor segment overrun", coprocessor_segment_overrun)
+DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip, 0)
+DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
-DO_ERROR(11, SIGBUS,  "segment not present", segment_not_present)
-DO_ERROR(12, SIGBUS,  "stack segment", stack_segment)
+DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
+DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
 DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0)
 DO_ERROR_INFO(32, SIGILL, "iret exception", iret_error, ILL_BADSTK, 0, 1)
 
-void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
+void __kprobes
+do_general_protection(struct pt_regs *regs, long error_code)
 {
+       struct task_struct *tsk;
        struct thread_struct *thread;
        struct tss_struct *tss;
        int cpu;
@@ -647,23 +642,24 @@ void __kprobes do_general_protection(struct pt_regs *regs, long error_code)
        if (regs->flags & X86_VM_MASK)
                goto gp_in_vm86;
 
+       tsk = current;
        if (!user_mode(regs))
                goto gp_in_kernel;
 
-       current->thread.error_code = error_code;
-       current->thread.trap_no = 13;
+       tsk->thread.error_code = error_code;
+       tsk->thread.trap_no = 13;
 
-       if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) &&
-           printk_ratelimit()) {
+       if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
+                       printk_ratelimit()) {
                printk(KERN_INFO
-                   "%s[%d] general protection ip:%lx sp:%lx error:%lx",
-                   current->comm, task_pid_nr(current),
-                   regs->ip, regs->sp, error_code);
+                       "%s[%d] general protection ip:%lx sp:%lx error:%lx",
+                       tsk->comm, task_pid_nr(tsk),
+                       regs->ip, regs->sp, error_code);
                print_vma_addr(" in ", regs->ip);
                printk("\n");
        }
 
-       force_sig(SIGSEGV, current);
+       force_sig(SIGSEGV, tsk);
        return;
 
 gp_in_vm86:
@@ -672,14 +668,15 @@ gp_in_vm86:
        return;
 
 gp_in_kernel:
-       if (!fixup_exception(regs)) {
-               current->thread.error_code = error_code;
-               current->thread.trap_no = 13;
-               if (notify_die(DIE_GPF, "general protection fault", regs,
+       if (fixup_exception(regs))
+               return;
+
+       tsk->thread.error_code = error_code;
+       tsk->thread.trap_no = 13;
+       if (notify_die(DIE_GPF, "general protection fault", regs,
                                error_code, 13, SIGSEGV) == NOTIFY_STOP)
-                       return;
-               die("general protection fault", regs, error_code);
-       }
+               return;
+       die("general protection fault", regs, error_code);
 }
 
 static notrace __kprobes void
@@ -756,9 +753,9 @@ unknown_nmi_error(unsigned char reason, struct pt_regs *regs)
 
 static DEFINE_SPINLOCK(nmi_print_lock);
 
-void notrace __kprobes die_nmi(struct pt_regs *regs, const char *msg)
+void notrace __kprobes die_nmi(char *str, struct pt_regs *regs, int do_panic)
 {
-       if (notify_die(DIE_NMIWATCHDOG, msg, regs, 0, 2, SIGINT) == NOTIFY_STOP)
+       if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
                return;
 
        spin_lock(&nmi_print_lock);
@@ -767,10 +764,12 @@ void notrace __kprobes die_nmi(struct pt_regs *regs, const char *msg)
        * to get a message out:
        */
        bust_spinlocks(1);
-       printk(KERN_EMERG "%s", msg);
+       printk(KERN_EMERG "%s", str);
        printk(" on CPU%d, ip %08lx, registers:\n",
                smp_processor_id(), regs->ip);
        show_registers(regs);
+       if (do_panic)
+               panic("Non maskable interrupt");
        console_silent();
        spin_unlock(&nmi_print_lock);
        bust_spinlocks(0);
@@ -790,14 +789,17 @@ void notrace __kprobes die_nmi(struct pt_regs *regs, const char *msg)
 static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 {
        unsigned char reason = 0;
+       int cpu;
+
+       cpu = smp_processor_id();
 
-       /* Only the BSP gets external NMIs from the system: */
-       if (!smp_processor_id())
+       /* Only the BSP gets external NMIs from the system. */
+       if (!cpu)
                reason = get_nmi_reason();
 
        if (!(reason & 0xc0)) {
                if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
-                                                       == NOTIFY_STOP)
+                                                               == NOTIFY_STOP)
                        return;
 #ifdef CONFIG_X86_LOCAL_APIC
                /*
@@ -806,7 +808,7 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
                 */
                if (nmi_watchdog_tick(regs, reason))
                        return;
-               if (!do_nmi_callback(regs, smp_processor_id()))
+               if (!do_nmi_callback(regs, cpu))
                        unknown_nmi_error(reason, regs);
 #else
                unknown_nmi_error(reason, regs);
@@ -816,6 +818,8 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
        }
        if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
                return;
+
+       /* AK: following checks seem to be broken on modern chipsets. FIXME */
        if (reason & 0x80)
                mem_parity_error(reason, regs);
        if (reason & 0x40)
@@ -827,8 +831,6 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
        reassert_nmi();
 }
 
-static int ignore_nmis;
-
 notrace __kprobes void do_nmi(struct pt_regs *regs, long error_code)
 {
        int cpu;
@@ -913,7 +915,7 @@ void __kprobes do_debug(struct pt_regs *regs, long error_code)
        tsk->thread.debugctlmsr = 0;
 
        if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
-                                       SIGTRAP) == NOTIFY_STOP)
+                                               SIGTRAP) == NOTIFY_STOP)
                return;
        /* It's safe to allow irq's after DR6 has been saved */
        if (regs->flags & X86_EFLAGS_IF)
@@ -974,9 +976,8 @@ clear_TF_reenable:
 void math_error(void __user *ip)
 {
        struct task_struct *task;
-       unsigned short cwd;
-       unsigned short swd;
        siginfo_t info;
+       unsigned short cwd, swd;
 
        /*
         * Save the info for the exception handler and clear the error.
@@ -995,7 +996,7 @@ void math_error(void __user *ip)
         * C1 reg you need in case of a stack fault, 0x040 is the stack
         * fault bit.  We should only be taking one exception at a time,
         * so if this combination doesn't produce any single exception,
-        * then we have a bad program that isn't syncronizing its FPU usage
+        * then we have a bad program that isn't synchronizing its FPU usage
         * and it will suffer the consequences since we won't be able to
         * fully reproduce the context of the exception
         */
@@ -1004,7 +1005,7 @@ void math_error(void __user *ip)
        switch (swd & ~cwd & 0x3f) {
        case 0x000: /* No unmasked exception */
                return;
-       default:    /* Multiple exceptions */
+       default: /* Multiple exceptions */
                break;
        case 0x001: /* Invalid Op */
                /*
@@ -1040,8 +1041,8 @@ void do_coprocessor_error(struct pt_regs *regs, long error_code)
 static void simd_math_error(void __user *ip)
 {
        struct task_struct *task;
-       unsigned short mxcsr;
        siginfo_t info;
+       unsigned short mxcsr;
 
        /*
         * Save the info for the exception handler and clear the error.
@@ -1117,7 +1118,7 @@ void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
 
 unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
 {
-       struct desc_struct *gdt = __get_cpu_var(gdt_page).gdt;
+       struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
        unsigned long base = (kesp - uesp) & -THREAD_SIZE;
        unsigned long new_kesp = kesp - base;
        unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
@@ -1196,19 +1197,16 @@ void __init trap_init(void)
        early_iounmap(p, 4);
 #endif
 
-#ifdef CONFIG_X86_LOCAL_APIC
-       init_apic_mappings();
-#endif
-       set_trap_gate(0,  &divide_error);
-       set_intr_gate(1,  &debug);
-       set_intr_gate(2,  &nmi);
-       set_system_intr_gate(3, &int3); /* int3/4 can be called from all */
-       set_system_gate(4, &overflow);
-       set_trap_gate(5,  &bounds);
-       set_trap_gate(6,  &invalid_op);
-       set_trap_gate(7,  &device_not_available);
-       set_task_gate(8,  GDT_ENTRY_DOUBLEFAULT_TSS);
-       set_trap_gate(9,  &coprocessor_segment_overrun);
+       set_trap_gate(0, &divide_error);
+       set_intr_gate(1, &debug);
+       set_intr_gate(2, &nmi);
+       set_system_intr_gate(3, &int3); /* int3 can be called from all */
+       set_system_gate(4, &overflow); /* int4 can be called from all */
+       set_trap_gate(5, &bounds);
+       set_trap_gate(6, &invalid_op);
+       set_trap_gate(7, &device_not_available);
+       set_task_gate(8, GDT_ENTRY_DOUBLEFAULT_TSS);
+       set_trap_gate(9, &coprocessor_segment_overrun);
        set_trap_gate(10, &invalid_TSS);
        set_trap_gate(11, &segment_not_present);
        set_trap_gate(12, &stack_segment);
index adff76e..2696a68 100644 (file)
  * 'Traps.c' handles hardware traps and faults after we have saved some
  * state in 'entry.S'.
  */
-#include <linux/sched.h>
+#include <linux/moduleparam.h>
+#include <linux/interrupt.h>
+#include <linux/kallsyms.h>
+#include <linux/spinlock.h>
+#include <linux/kprobes.h>
+#include <linux/uaccess.h>
+#include <linux/utsname.h>
+#include <linux/kdebug.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/ptrace.h>
 #include <linux/string.h>
+#include <linux/unwind.h>
+#include <linux/delay.h>
 #include <linux/errno.h>
-#include <linux/ptrace.h>
+#include <linux/kexec.h>
+#include <linux/sched.h>
 #include <linux/timer.h>
-#include <linux/mm.h>
 #include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/spinlock.h>
-#include <linux/interrupt.h>
-#include <linux/kallsyms.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/nmi.h>
-#include <linux/kprobes.h>
-#include <linux/kexec.h>
-#include <linux/unwind.h>
-#include <linux/uaccess.h>
 #include <linux/bug.h>
-#include <linux/kdebug.h>
-#include <linux/utsname.h>
-
-#include <mach_traps.h>
+#include <linux/nmi.h>
+#include <linux/mm.h>
 
 #if defined(CONFIG_EDAC)
 #include <linux/edac.h>
 #endif
 
-#include <asm/system.h>
-#include <asm/io.h>
-#include <asm/atomic.h>
+#include <asm/stacktrace.h>
+#include <asm/processor.h>
 #include <asm/debugreg.h>
+#include <asm/atomic.h>
+#include <asm/system.h>
+#include <asm/unwind.h>
 #include <asm/desc.h>
 #include <asm/i387.h>
-#include <asm/processor.h>
-#include <asm/unwind.h>
+#include <asm/nmi.h>
 #include <asm/smp.h>
+#include <asm/io.h>
 #include <asm/pgalloc.h>
-#include <asm/pda.h>
 #include <asm/proto.h>
-#include <asm/nmi.h>
-#include <asm/stacktrace.h>
+#include <asm/pda.h>
+
+#include <mach_traps.h>
 
 asmlinkage void divide_error(void);
 asmlinkage void debug(void);
@@ -71,12 +71,15 @@ asmlinkage void general_protection(void);
 asmlinkage void page_fault(void);
 asmlinkage void coprocessor_error(void);
 asmlinkage void simd_coprocessor_error(void);
-asmlinkage void reserved(void);
 asmlinkage void alignment_check(void);
-asmlinkage void machine_check(void);
 asmlinkage void spurious_interrupt_bug(void);
+asmlinkage void machine_check(void);
 
+int panic_on_unrecovered_nmi;
+int kstack_depth_to_print = 12;
 static unsigned int code_bytes = 64;
+static int ignore_nmis;
+static int die_counter;
 
 static inline void conditional_sti(struct pt_regs *regs)
 {
@@ -100,34 +103,9 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
        dec_preempt_count();
 }
 
-int kstack_depth_to_print = 12;
-
 void printk_address(unsigned long address, int reliable)
 {
-#ifdef CONFIG_KALLSYMS
-       unsigned long offset = 0, symsize;
-       const char *symname;
-       char *modname;
-       char *delim = ":";
-       char namebuf[KSYM_NAME_LEN];
-       char reliab[4] = "";
-
-       symname = kallsyms_lookup(address, &symsize, &offset,
-                                       &modname, namebuf);
-       if (!symname) {
-               printk(" [<%016lx>]\n", address);
-               return;
-       }
-       if (!reliable)
-               strcpy(reliab, "? ");
-
-       if (!modname)
-               modname = delim = "";
-       printk(" [<%016lx>] %s%s%s%s%s+0x%lx/0x%lx\n",
-               address, reliab, delim, modname, delim, symname, offset, symsize);
-#else
-       printk(" [<%016lx>]\n", address);
-#endif
+       printk(" [<%016lx>] %s%pS\n", address, reliable ? "": "? ", (void *) address);
 }
 
 static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
@@ -204,8 +182,6 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
        return NULL;
 }
 
-#define MSG(txt) ops->warning(data, txt)
-
 /*
  * x86-64 can have up to three kernel stacks: 
  * process stack
@@ -232,11 +208,11 @@ struct stack_frame {
        unsigned long return_address;
 };
 
-
-static inline unsigned long print_context_stack(struct thread_info *tinfo,
-                               unsigned long *stack, unsigned long bp,
-                               const struct stacktrace_ops *ops, void *data,
-                               unsigned long *end)
+static inline unsigned long
+print_context_stack(struct thread_info *tinfo,
+               unsigned long *stack, unsigned long bp,
+               const struct stacktrace_ops *ops, void *data,
+               unsigned long *end)
 {
        struct stack_frame *frame = (struct stack_frame *)bp;
 
@@ -258,7 +234,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
        return bp;
 }
 
-void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
+void dump_trace(struct task_struct *task, struct pt_regs *regs,
                unsigned long *stack, unsigned long bp,
                const struct stacktrace_ops *ops, void *data)
 {
@@ -267,36 +243,34 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
        unsigned used = 0;
        struct thread_info *tinfo;
 
-       if (!tsk)
-               tsk = current;
-       tinfo = task_thread_info(tsk);
+       if (!task)
+               task = current;
 
        if (!stack) {
                unsigned long dummy;
                stack = &dummy;
-               if (tsk && tsk != current)
-                       stack = (unsigned long *)tsk->thread.sp;
+               if (task && task != current)
+                       stack = (unsigned long *)task->thread.sp;
        }
 
 #ifdef CONFIG_FRAME_POINTER
        if (!bp) {
-               if (tsk == current) {
+               if (task == current) {
                        /* Grab bp right from our regs */
-                       asm("movq %%rbp, %0" : "=r" (bp):);
+                       asm("movq %%rbp, %0" : "=r" (bp) :);
                } else {
                        /* bp is the last reg pushed by switch_to */
-                       bp = *(unsigned long *) tsk->thread.sp;
+                       bp = *(unsigned long *) task->thread.sp;
                }
        }
 #endif
 
-
-
        /*
         * Print function call entries in all stacks, starting at the
         * current stack address. If the stacks consist of nested
         * exceptions
         */
+       tinfo = task_thread_info(task);
        for (;;) {
                char *id;
                unsigned long *estack_end;
@@ -381,18 +355,17 @@ static const struct stacktrace_ops print_trace_ops = {
        .address = print_trace_address,
 };
 
-void
-show_trace(struct task_struct *tsk, struct pt_regs *regs, unsigned long *stack,
-               unsigned long bp)
+void show_trace(struct task_struct *task, struct pt_regs *regs,
+               unsigned long *stack, unsigned long bp)
 {
        printk("\nCall Trace:\n");
-       dump_trace(tsk, regs, stack, bp, &print_trace_ops, NULL);
+       dump_trace(task, regs, stack, bp, &print_trace_ops, NULL);
        printk("\n");
 }
 
 static void
-_show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp,
-                                                       unsigned long bp)
+_show_stack(struct task_struct *task, struct pt_regs *regs,
+               unsigned long *sp, unsigned long bp)
 {
        unsigned long *stack;
        int i;
@@ -404,14 +377,14 @@ _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp,
        // back trace for this cpu.
 
        if (sp == NULL) {
-               if (tsk)
-                       sp = (unsigned long *)tsk->thread.sp;
+               if (task)
+                       sp = (unsigned long *)task->thread.sp;
                else
                        sp = (unsigned long *)&sp;
        }
 
        stack = sp;
-       for(i=0; i < kstack_depth_to_print; i++) {
+       for (i = 0; i < kstack_depth_to_print; i++) {
                if (stack >= irqstack && stack <= irqstack_end) {
                        if (stack == irqstack_end) {
                                stack = (unsigned long *) (irqstack_end[-1]);
@@ -426,12 +399,12 @@ _show_stack(struct task_struct *tsk, struct pt_regs *regs, unsigned long *sp,
                printk(" %016lx", *stack++);
                touch_nmi_watchdog();
        }
-       show_trace(tsk, regs, sp, bp);
+       show_trace(task, regs, sp, bp);
 }
 
-void show_stack(struct task_struct *tsk, unsigned long * sp)
+void show_stack(struct task_struct *task, unsigned long *sp)
 {
-       _show_stack(tsk, NULL, sp, 0);
+       _show_stack(task, NULL, sp, 0);
 }
 
 /*
@@ -439,8 +412,8 @@ void show_stack(struct task_struct *tsk, unsigned long * sp)
  */
 void dump_stack(void)
 {
-       unsigned long dummy;
        unsigned long bp = 0;
+       unsigned long stack;
 
 #ifdef CONFIG_FRAME_POINTER
        if (!bp)
@@ -452,7 +425,7 @@ void dump_stack(void)
                init_utsname()->release,
                (int)strcspn(init_utsname()->version, " "),
                init_utsname()->version);
-       show_trace(NULL, NULL, &dummy, bp);
+       show_trace(NULL, NULL, &stack, bp);
 }
 
 EXPORT_SYMBOL(dump_stack);
@@ -463,12 +436,8 @@ void show_registers(struct pt_regs *regs)
        unsigned long sp;
        const int cpu = smp_processor_id();
        struct task_struct *cur = cpu_pda(cpu)->pcurrent;
-       u8 *ip;
-       unsigned int code_prologue = code_bytes * 43 / 64;
-       unsigned int code_len = code_bytes;
 
        sp = regs->sp;
-       ip = (u8 *) regs->ip - code_prologue;
        printk("CPU %d ", cpu);
        __show_regs(regs);
        printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
@@ -479,15 +448,21 @@ void show_registers(struct pt_regs *regs)
         * time of the fault..
         */
        if (!user_mode(regs)) {
+               unsigned int code_prologue = code_bytes * 43 / 64;
+               unsigned int code_len = code_bytes;
                unsigned char c;
+               u8 *ip;
+
                printk("Stack: ");
                _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
                printk("\n");
 
                printk(KERN_EMERG "Code: ");
+
+               ip = (u8 *)regs->ip - code_prologue;
                if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
                        /* try starting at RIP */
-                       ip = (u8 *) regs->ip;
+                       ip = (u8 *)regs->ip;
                        code_len = code_len - code_prologue + 1;
                }
                for (i = 0; i < code_len; i++, ip++) {
@@ -503,7 +478,7 @@ void show_registers(struct pt_regs *regs)
                }
        }
        printk("\n");
-}      
+}
 
 int is_valid_bugaddr(unsigned long ip)
 {
@@ -561,10 +536,9 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
        do_exit(signr);
 }
 
-int __kprobes __die(const char * str, struct pt_regs * regs, long err)
+int __kprobes __die(const char *str, struct pt_regs *regs, long err)
 {
-       static int die_counter;
-       printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff,++die_counter);
+       printk(KERN_EMERG "%s: %04lx [%u] ", str, err & 0xffff, ++die_counter);
 #ifdef CONFIG_PREEMPT
        printk("PREEMPT ");
 #endif
@@ -575,8 +549,10 @@ int __kprobes __die(const char * str, struct pt_regs * regs, long err)
        printk("DEBUG_PAGEALLOC");
 #endif
        printk("\n");
-       if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
+       if (notify_die(DIE_OOPS, str, regs, err,
+                       current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
                return 1;
+
        show_registers(regs);
        add_taint(TAINT_DIE);
        /* Executive summary in case the oops scrolled away */
@@ -588,7 +564,7 @@ int __kprobes __die(const char * str, struct pt_regs * regs, long err)
        return 0;
 }
 
-void die(const char * str, struct pt_regs * regs, long err)
+void die(const char *str, struct pt_regs *regs, long err)
 {
        unsigned long flags = oops_begin();
 
@@ -605,8 +581,7 @@ die_nmi(char *str, struct pt_regs *regs, int do_panic)
 {
        unsigned long flags;
 
-       if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) ==
-           NOTIFY_STOP)
+       if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, 2, SIGINT) == NOTIFY_STOP)
                return;
 
        flags = oops_begin();
@@ -614,7 +589,9 @@ die_nmi(char *str, struct pt_regs *regs, int do_panic)
         * We are in trouble anyway, lets at least try
         * to get a message out.
         */
-       printk(str, smp_processor_id());
+       printk(KERN_EMERG "%s", str);
+       printk(" on CPU%d, ip %08lx, registers:\n",
+               smp_processor_id(), regs->ip);
        show_registers(regs);
        if (kexec_should_crash(current))
                crash_kexec(regs);
@@ -626,44 +603,44 @@ die_nmi(char *str, struct pt_regs *regs, int do_panic)
        do_exit(SIGBUS);
 }
 
-static void __kprobes do_trap(int trapnr, int signr, char *str,
-                             struct pt_regs * regs, long error_code,
-                             siginfo_t *info)
+static void __kprobes
+do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
+       long error_code, siginfo_t *info)
 {
        struct task_struct *tsk = current;
 
-       if (user_mode(regs)) {
-               /*
-                * We want error_code and trap_no set for userspace
-                * faults and kernelspace faults which result in
-                * die(), but not kernelspace faults which are fixed
-                * up.  die() gives the process no chance to handle
-                * the signal and notice the kernel fault information,
-                * so that won't result in polluting the information
-                * about previously queued, but not yet delivered,
-                * faults.  See also do_general_protection below.
-                */
-               tsk->thread.error_code = error_code;
-               tsk->thread.trap_no = trapnr;
-
-               if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
-                   printk_ratelimit()) {
-                       printk(KERN_INFO
-                              "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
-                              tsk->comm, tsk->pid, str,
-                              regs->ip, regs->sp, error_code);
-                       print_vma_addr(" in ", regs->ip);
-                       printk("\n");
-               }
+       if (!user_mode(regs))
+               goto kernel_trap;
 
-               if (info)
-                       force_sig_info(signr, info, tsk);
-               else
-                       force_sig(signr, tsk);
-               return;
+       /*
+        * We want error_code and trap_no set for userspace faults and
+        * kernelspace faults which result in die(), but not
+        * kernelspace faults which are fixed up.  die() gives the
+        * process no chance to handle the signal and notice the
+        * kernel fault information, so that won't result in polluting
+        * the information about previously queued, but not yet
+        * delivered, faults.  See also do_general_protection below.
+        */
+       tsk->thread.error_code = error_code;
+       tsk->thread.trap_no = trapnr;
+
+       if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
+           printk_ratelimit()) {
+               printk(KERN_INFO
+                      "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
+                      tsk->comm, tsk->pid, str,
+                      regs->ip, regs->sp, error_code);
+               print_vma_addr(" in ", regs->ip);
+               printk("\n");
        }
 
+       if (info)
+               force_sig_info(signr, info, tsk);
+       else
+               force_sig(signr, tsk);
+       return;
 
+kernel_trap:
        if (!fixup_exception(regs)) {
                tsk->thread.error_code = error_code;
                tsk->thread.trap_no = trapnr;
@@ -673,41 +650,39 @@ static void __kprobes do_trap(int trapnr, int signr, char *str,
 }
 
 #define DO_ERROR(trapnr, signr, str, name) \
-asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
-{ \
-       if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
-                                                       == NOTIFY_STOP) \
-               return; \
+asmlinkage void do_##name(struct pt_regs * regs, long error_code)      \
+{                                                                      \
+       if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
+                                                       == NOTIFY_STOP) \
+               return;                                                 \
        conditional_sti(regs);                                          \
-       do_trap(trapnr, signr, str, regs, error_code, NULL); \
+       do_trap(trapnr, signr, str, regs, error_code, NULL);            \
 }
 
-#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
-asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
-{ \
-       siginfo_t info; \
-       info.si_signo = signr; \
-       info.si_errno = 0; \
-       info.si_code = sicode; \
-       info.si_addr = (void __user *)siaddr; \
-       trace_hardirqs_fixup(); \
-       if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
-                                                       == NOTIFY_STOP) \
-               return; \
+#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr)                \
+asmlinkage void do_##name(struct pt_regs * regs, long error_code)      \
+{                                                                      \
+       siginfo_t info;                                                 \
+       info.si_signo = signr;                                          \
+       info.si_errno = 0;                                              \
+       info.si_code = sicode;                                          \
+       info.si_addr = (void __user *)siaddr;                           \
+       trace_hardirqs_fixup();                                         \
+       if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr)  \
+                                                       == NOTIFY_STOP) \
+               return;                                                 \
        conditional_sti(regs);                                          \
-       do_trap(trapnr, signr, str, regs, error_code, &info); \
+       do_trap(trapnr, signr, str, regs, error_code, &info);           \
 }
 
-DO_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->ip)
-DO_ERROR( 4, SIGSEGV, "overflow", overflow)
-DO_ERROR( 5, SIGSEGV, "bounds", bounds)
-DO_ERROR_INFO( 6, SIGILL,  "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
-DO_ERROR( 7, SIGSEGV, "device not available", device_not_available)
-DO_ERROR( 9, SIGFPE,  "coprocessor segment overrun", coprocessor_segment_overrun)
+DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
+DO_ERROR(4, SIGSEGV, "overflow", overflow)
+DO_ERROR(5, SIGSEGV, "bounds", bounds)
+DO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
+DO_ERROR(9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun)
 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS)
-DO_ERROR(11, SIGBUS,  "segment not present", segment_not_present)
+DO_ERROR(11, SIGBUS, "segment not present", segment_not_present)
 DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
-DO_ERROR(18, SIGSEGV, "reserved", reserved)
 
 /* Runs on IST stack */
 asmlinkage void do_stack_segment(struct pt_regs *regs, long error_code)
@@ -737,31 +712,34 @@ asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
                die(str, regs, error_code);
 }
 
-asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
-                                               long error_code)
+asmlinkage void __kprobes
+do_general_protection(struct pt_regs *regs, long error_code)
 {
-       struct task_struct *tsk = current;
+       struct task_struct *tsk;
 
        conditional_sti(regs);
 
-       if (user_mode(regs)) {
-               tsk->thread.error_code = error_code;
-               tsk->thread.trap_no = 13;
-
-               if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
-                   printk_ratelimit()) {
-                       printk(KERN_INFO
-                      "%s[%d] general protection ip:%lx sp:%lx error:%lx",
-                              tsk->comm, tsk->pid,
-                              regs->ip, regs->sp, error_code);
-                       print_vma_addr(" in ", regs->ip);
-                       printk("\n");
-               }
+       tsk = current;
+       if (!user_mode(regs))
+               goto gp_in_kernel;
 
-               force_sig(SIGSEGV, tsk);
-               return;
-       } 
+       tsk->thread.error_code = error_code;
+       tsk->thread.trap_no = 13;
+
+       if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
+                       printk_ratelimit()) {
+               printk(KERN_INFO
+                       "%s[%d] general protection ip:%lx sp:%lx error:%lx",
+                       tsk->comm, tsk->pid,
+                       regs->ip, regs->sp, error_code);
+               print_vma_addr(" in ", regs->ip);
+               printk("\n");
+       }
 
+       force_sig(SIGSEGV, tsk);
+       return;
+
+gp_in_kernel:
        if (fixup_exception(regs))
                return;
 
@@ -774,14 +752,14 @@ asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
 }
 
 static notrace __kprobes void
-mem_parity_error(unsigned char reason, struct pt_regs * regs)
+mem_parity_error(unsigned char reason, struct pt_regs *regs)
 {
        printk(KERN_EMERG "Uhhuh. NMI received for unknown reason %02x.\n",
                reason);
        printk(KERN_EMERG "You have some hardware problem, likely on the PCI bus.\n");
 
 #if defined(CONFIG_EDAC)
-       if(edac_handler_set()) {
+       if (edac_handler_set()) {
                edac_atomic_assert_error();
                return;
        }
@@ -798,7 +776,7 @@ mem_parity_error(unsigned char reason, struct pt_regs * regs)
 }
 
 static notrace __kprobes void
-io_check_error(unsigned char reason, struct pt_regs * regs)
+io_check_error(unsigned char reason, struct pt_regs *regs)
 {
        printk("NMI: IOCK error (debug interrupt?)\n");
        show_registers(regs);
@@ -828,14 +806,14 @@ unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
 
 /* Runs on IST stack. This code must keep interrupts off all the time.
    Nested NMIs are prevented by the CPU. */
-asmlinkage notrace  __kprobes void default_do_nmi(struct pt_regs *regs)
+asmlinkage notrace __kprobes void default_do_nmi(struct pt_regs *regs)
 {
        unsigned char reason = 0;
        int cpu;
 
        cpu = smp_processor_id();
 
-       /* Only the BSP gets external NMIs from the system.  */
+       /* Only the BSP gets external NMIs from the system. */
        if (!cpu)
                reason = get_nmi_reason();
 
@@ -847,32 +825,57 @@ asmlinkage notrace  __kprobes void default_do_nmi(struct pt_regs *regs)
                 * Ok, so this is none of the documented NMI sources,
                 * so it must be the NMI watchdog.
                 */
-               if (nmi_watchdog_tick(regs,reason))
+               if (nmi_watchdog_tick(regs, reason))
                        return;
-               if (!do_nmi_callback(regs,cpu))
+               if (!do_nmi_callback(regs, cpu))
                        unknown_nmi_error(reason, regs);
 
                return;
        }
        if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) == NOTIFY_STOP)
-               return; 
+               return;
 
        /* AK: following checks seem to be broken on modern chipsets. FIXME */
-
        if (reason & 0x80)
                mem_parity_error(reason, regs);
        if (reason & 0x40)
                io_check_error(reason, regs);
 }
 
+asmlinkage notrace __kprobes void
+do_nmi(struct pt_regs *regs, long error_code)
+{
+       nmi_enter();
+
+       add_pda(__nmi_count, 1);
+
+       if (!ignore_nmis)
+               default_do_nmi(regs);
+
+       nmi_exit();
+}
+
+void stop_nmi(void)
+{
+       acpi_nmi_disable();
+       ignore_nmis++;
+}
+
+void restart_nmi(void)
+{
+       ignore_nmis--;
+       acpi_nmi_enable();
+}
+
 /* runs on IST stack. */
-asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code)
+asmlinkage void __kprobes do_int3(struct pt_regs *regs, long error_code)
 {
        trace_hardirqs_fixup();
 
-       if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) {
+       if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
+                       == NOTIFY_STOP)
                return;
-       }
+
        preempt_conditional_sti(regs);
        do_trap(3, SIGTRAP, "int3", regs, error_code, NULL);
        preempt_conditional_cli(regs);
@@ -903,8 +906,8 @@ asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *eregs)
 asmlinkage void __kprobes do_debug(struct pt_regs * regs,
                                   unsigned long error_code)
 {
-       unsigned long condition;
        struct task_struct *tsk = current;
+       unsigned long condition;
        siginfo_t info;
 
        trace_hardirqs_fixup();
@@ -925,21 +928,19 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
 
        /* Mask out spurious debug traps due to lazy DR7 setting */
        if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
-               if (!tsk->thread.debugreg7) { 
+               if (!tsk->thread.debugreg7)
                        goto clear_dr7;
-               }
        }
 
        tsk->thread.debugreg6 = condition;
 
-
        /*
         * Single-stepping through TF: make sure we ignore any events in
         * kernel space (but re-enable TF when returning to user mode).
         */
        if (condition & DR_STEP) {
-                if (!user_mode(regs))
-                       goto clear_TF_reenable;
+               if (!user_mode(regs))
+                       goto clear_TF_reenable;
        }
 
        /* Ok, finally something we can handle */
@@ -952,7 +953,7 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
        force_sig_info(SIGTRAP, &info, tsk);
 
 clear_dr7:
-       set_debugreg(0UL, 7);
+       set_debugreg(0, 7);
        preempt_conditional_cli(regs);
        return;
 
@@ -960,6 +961,7 @@ clear_TF_reenable:
        set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
        regs->flags &= ~X86_EFLAGS_TF;
        preempt_conditional_cli(regs);
+       return;
 }
 
 static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
@@ -982,7 +984,7 @@ static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
 asmlinkage void do_coprocessor_error(struct pt_regs *regs)
 {
        void __user *ip = (void __user *)(regs->ip);
-       struct task_struct * task;
+       struct task_struct *task;
        siginfo_t info;
        unsigned short cwd, swd;
 
@@ -1015,30 +1017,30 @@ asmlinkage void do_coprocessor_error(struct pt_regs *regs)
        cwd = get_fpu_cwd(task);
        swd = get_fpu_swd(task);
        switch (swd & ~cwd & 0x3f) {
-               case 0x000:
-               default:
-                       break;
-               case 0x001: /* Invalid Op */
-                       /*
-                        * swd & 0x240 == 0x040: Stack Underflow
-                        * swd & 0x240 == 0x240: Stack Overflow
-                        * User must clear the SF bit (0x40) if set
-                        */
-                       info.si_code = FPE_FLTINV;
-                       break;
-               case 0x002: /* Denormalize */
-               case 0x010: /* Underflow */
-                       info.si_code = FPE_FLTUND;
-                       break;
-               case 0x004: /* Zero Divide */
-                       info.si_code = FPE_FLTDIV;
-                       break;
-               case 0x008: /* Overflow */
-                       info.si_code = FPE_FLTOVF;
-                       break;
-               case 0x020: /* Precision */
-                       info.si_code = FPE_FLTRES;
-                       break;
+       case 0x000: /* No unmasked exception */
+       default: /* Multiple exceptions */
+               break;
+       case 0x001: /* Invalid Op */
+               /*
+                * swd & 0x240 == 0x040: Stack Underflow
+                * swd & 0x240 == 0x240: Stack Overflow
+                * User must clear the SF bit (0x40) if set
+                */
+               info.si_code = FPE_FLTINV;
+               break;
+       case 0x002: /* Denormalize */
+       case 0x010: /* Underflow */
+               info.si_code = FPE_FLTUND;
+               break;
+       case 0x004: /* Zero Divide */
+               info.si_code = FPE_FLTDIV;
+               break;
+       case 0x008: /* Overflow */
+               info.si_code = FPE_FLTOVF;
+               break;
+       case 0x020: /* Precision */
+               info.si_code = FPE_FLTRES;
+               break;
        }
        force_sig_info(SIGFPE, &info, task);
 }
@@ -1051,7 +1053,7 @@ asmlinkage void bad_intr(void)
 asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
 {
        void __user *ip = (void __user *)(regs->ip);
-       struct task_struct * task;
+       struct task_struct *task;
        siginfo_t info;
        unsigned short mxcsr;
 
@@ -1079,25 +1081,25 @@ asmlinkage void do_simd_coprocessor_error(struct pt_regs *regs)
         */
        mxcsr = get_fpu_mxcsr(task);
        switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
-               case 0x000:
-               default:
-                       break;
-               case 0x001: /* Invalid Op */
-                       info.si_code = FPE_FLTINV;
-                       break;
-               case 0x002: /* Denormalize */
-               case 0x010: /* Underflow */
-                       info.si_code = FPE_FLTUND;
-                       break;
-               case 0x004: /* Zero Divide */
-                       info.si_code = FPE_FLTDIV;
-                       break;
-               case 0x008: /* Overflow */
-                       info.si_code = FPE_FLTOVF;
-                       break;
-               case 0x020: /* Precision */
-                       info.si_code = FPE_FLTRES;
-                       break;
+       case 0x000:
+       default:
+               break;
+       case 0x001: /* Invalid Op */
+               info.si_code = FPE_FLTINV;
+               break;
+       case 0x002: /* Denormalize */
+       case 0x010: /* Underflow */
+               info.si_code = FPE_FLTUND;
+               break;
+       case 0x004: /* Zero Divide */
+               info.si_code = FPE_FLTDIV;
+               break;
+       case 0x008: /* Overflow */
+               info.si_code = FPE_FLTOVF;
+               break;
+       case 0x020: /* Precision */
+               info.si_code = FPE_FLTRES;
+               break;
        }
        force_sig_info(SIGFPE, &info, task);
 }
@@ -1115,7 +1117,7 @@ asmlinkage void __attribute__((weak)) mce_threshold_interrupt(void)
 }
 
 /*
- *  'math_state_restore()' saves the current math information in the
+ * 'math_state_restore()' saves the current math information in the
  * old math state array, and gets the new ones from the current task
  *
  * Careful.. There are problems with IBM-designed IRQ13 behaviour.
@@ -1140,7 +1142,7 @@ asmlinkage void math_state_restore(void)
                local_irq_disable();
        }
 
-       clts();                 /* Allow maths ops (or we recurse) */
+       clts();                         /* Allow maths ops (or we recurse) */
        restore_fpu_checking(&me->thread.xstate->fxsave);
        task_thread_info(me)->status |= TS_USEDFPU;
        me->fpu_counter++;
@@ -1149,64 +1151,61 @@ EXPORT_SYMBOL_GPL(math_state_restore);
 
 void __init trap_init(void)
 {
-       set_intr_gate(0,&divide_error);
-       set_intr_gate_ist(1,&debug,DEBUG_STACK);
-       set_intr_gate_ist(2,&nmi,NMI_STACK);
-       set_system_gate_ist(3,&int3,DEBUG_STACK); /* int3 can be called from all */
-       set_system_gate(4,&overflow);   /* int4 can be called from all */
-       set_intr_gate(5,&bounds);
-       set_intr_gate(6,&invalid_op);
-       set_intr_gate(7,&device_not_available);
-       set_intr_gate_ist(8,&double_fault, DOUBLEFAULT_STACK);
-       set_intr_gate(9,&coprocessor_segment_overrun);
-       set_intr_gate(10,&invalid_TSS);
-       set_intr_gate(11,&segment_not_present);
-       set_intr_gate_ist(12,&stack_segment,STACKFAULT_STACK);
-       set_intr_gate(13,&general_protection);
-       set_intr_gate(14,&page_fault);
-       set_intr_gate(15,&spurious_interrupt_bug);
-       set_intr_gate(16,&coprocessor_error);
-       set_intr_gate(17,&alignment_check);
+       set_intr_gate(0, &divide_error);
+       set_intr_gate_ist(1, &debug, DEBUG_STACK);
+       set_intr_gate_ist(2, &nmi, NMI_STACK);
+       set_system_gate_ist(3, &int3, DEBUG_STACK); /* int3 can be called from all */
+       set_system_gate(4, &overflow); /* int4 can be called from all */
+       set_intr_gate(5, &bounds);
+       set_intr_gate(6, &invalid_op);
+       set_intr_gate(7, &device_not_available);
+       set_intr_gate_ist(8, &double_fault, DOUBLEFAULT_STACK);
+       set_intr_gate(9, &coprocessor_segment_overrun);
+       set_intr_gate(10, &invalid_TSS);
+       set_intr_gate(11, &segment_not_present);
+       set_intr_gate_ist(12, &stack_segment, STACKFAULT_STACK);
+       set_intr_gate(13, &general_protection);
+       set_intr_gate(14, &page_fault);
+       set_intr_gate(15, &spurious_interrupt_bug);
+       set_intr_gate(16, &coprocessor_error);
+       set_intr_gate(17, &alignment_check);
 #ifdef CONFIG_X86_MCE
-       set_intr_gate_ist(18,&machine_check, MCE_STACK); 
+       set_intr_gate_ist(18, &machine_check, MCE_STACK);
 #endif
-       set_intr_gate(19,&simd_coprocessor_error);
+       set_intr_gate(19, &simd_coprocessor_error);
 
 #ifdef CONFIG_IA32_EMULATION
        set_system_gate(IA32_SYSCALL_VECTOR, ia32_syscall);
 #endif
-       
        /*
         * initialize the per thread extended state:
         */
-        init_thread_xstate();
+       init_thread_xstate();
        /*
-        * Should be a barrier for any external CPU state.
+        * Should be a barrier for any external CPU state:
         */
        cpu_init();
 }
 
-
 static int __init oops_setup(char *s)
-{ 
+{
        if (!s)
                return -EINVAL;
        if (!strcmp(s, "panic"))
                panic_on_oops = 1;
        return 0;
-} 
+}
 early_param("oops", oops_setup);
 
 static int __init kstack_setup(char *s)
 {
        if (!s)
                return -EINVAL;
-       kstack_depth_to_print = simple_strtoul(s,NULL,0);
+       kstack_depth_to_print = simple_strtoul(s, NULL, 0);
        return 0;
 }
 early_param("kstack", kstack_setup);
 
-
 static int __init code_bytes_setup(char *s)
 {
        code_bytes = simple_strtoul(s, NULL, 0);
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
new file mode 100644 (file)
index 0000000..3c36f92
--- /dev/null
@@ -0,0 +1,533 @@
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/acpi_pmtmr.h>
+#include <linux/cpufreq.h>
+#include <linux/dmi.h>
+#include <linux/delay.h>
+#include <linux/clocksource.h>
+#include <linux/percpu.h>
+
+#include <asm/hpet.h>
+#include <asm/timer.h>
+#include <asm/vgtod.h>
+#include <asm/time.h>
+#include <asm/delay.h>
+
+unsigned int cpu_khz;           /* TSC clocks / usec, not used here */
+EXPORT_SYMBOL(cpu_khz);
+unsigned int tsc_khz;
+EXPORT_SYMBOL(tsc_khz);
+
+/*
+ * TSC can be unstable due to cpufreq or due to unsynced TSCs
+ */
+static int tsc_unstable;
+
+/* native_sched_clock() is called before tsc_init(), so
+   we must start with the TSC soft disabled to prevent
+   erroneous rdtsc usage on !cpu_has_tsc processors */
+static int tsc_disabled = -1;
+
+/*
+ * Scheduler clock - returns current time in nanosec units.
+ */
+u64 native_sched_clock(void)
+{
+       u64 this_offset;
+
+       /*
+        * Fall back to jiffies if there's no TSC available:
+        * ( But note that we still use it if the TSC is marked
+        *   unstable. We do this because unlike Time Of Day,
+        *   the scheduler clock tolerates small errors and it's
+        *   very important for it to be as fast as the platform
+        *   can achive it. )
+        */
+       if (unlikely(tsc_disabled)) {
+               /* No locking but a rare wrong value is not a big deal: */
+               return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ);
+       }
+
+       /* read the Time Stamp Counter: */
+       rdtscll(this_offset);
+
+       /* return the value in ns */
+       return cycles_2_ns(this_offset);
+}
+
+/* We need to define a real function for sched_clock, to override the
+   weak default version */
+#ifdef CONFIG_PARAVIRT
+unsigned long long sched_clock(void)
+{
+       return paravirt_sched_clock();
+}
+#else
+unsigned long long
+sched_clock(void) __attribute__((alias("native_sched_clock")));
+#endif
+
+int check_tsc_unstable(void)
+{
+       return tsc_unstable;
+}
+EXPORT_SYMBOL_GPL(check_tsc_unstable);
+
+#ifdef CONFIG_X86_TSC
+int __init notsc_setup(char *str)
+{
+       printk(KERN_WARNING "notsc: Kernel compiled with CONFIG_X86_TSC, "
+                       "cannot disable TSC completely.\n");
+       tsc_disabled = 1;
+       return 1;
+}
+#else
+/*
+ * disable flag for tsc. Takes effect by clearing the TSC cpu flag
+ * in cpu/common.c
+ */
+int __init notsc_setup(char *str)
+{
+       setup_clear_cpu_cap(X86_FEATURE_TSC);
+       return 1;
+}
+#endif
+
+__setup("notsc", notsc_setup);
+
+#define MAX_RETRIES     5
+#define SMI_TRESHOLD    50000
+
+/*
+ * Read TSC and the reference counters. Take care of SMI disturbance
+ */
+static u64 __init tsc_read_refs(u64 *pm, u64 *hpet)
+{
+       u64 t1, t2;
+       int i;
+
+       for (i = 0; i < MAX_RETRIES; i++) {
+               t1 = get_cycles();
+               if (hpet)
+                       *hpet = hpet_readl(HPET_COUNTER) & 0xFFFFFFFF;
+               else
+                       *pm = acpi_pm_read_early();
+               t2 = get_cycles();
+               if ((t2 - t1) < SMI_TRESHOLD)
+                       return t2;
+       }
+       return ULLONG_MAX;
+}
+
+/**
+ * native_calibrate_tsc - calibrate the tsc on boot
+ */
+unsigned long native_calibrate_tsc(void)
+{
+       unsigned long flags;
+       u64 tsc1, tsc2, tr1, tr2, delta, pm1, pm2, hpet1, hpet2;
+       int hpet = is_hpet_enabled();
+       unsigned int tsc_khz_val = 0;
+
+       local_irq_save(flags);
+
+       tsc1 = tsc_read_refs(&pm1, hpet ? &hpet1 : NULL);
+
+       outb((inb(0x61) & ~0x02) | 0x01, 0x61);
+
+       outb(0xb0, 0x43);
+       outb((CLOCK_TICK_RATE / (1000 / 50)) & 0xff, 0x42);
+       outb((CLOCK_TICK_RATE / (1000 / 50)) >> 8, 0x42);
+       tr1 = get_cycles();
+       while ((inb(0x61) & 0x20) == 0);
+       tr2 = get_cycles();
+
+       tsc2 = tsc_read_refs(&pm2, hpet ? &hpet2 : NULL);
+
+       local_irq_restore(flags);
+
+       /*
+        * Preset the result with the raw and inaccurate PIT
+        * calibration value
+        */
+       delta = (tr2 - tr1);
+       do_div(delta, 50);
+       tsc_khz_val = delta;
+
+       /* hpet or pmtimer available ? */
+       if (!hpet && !pm1 && !pm2) {
+               printk(KERN_INFO "TSC calibrated against PIT\n");
+               goto out;
+       }
+
+       /* Check, whether the sampling was disturbed by an SMI */
+       if (tsc1 == ULLONG_MAX || tsc2 == ULLONG_MAX) {
+               printk(KERN_WARNING "TSC calibration disturbed by SMI, "
+                               "using PIT calibration result\n");
+               goto out;
+       }
+
+       tsc2 = (tsc2 - tsc1) * 1000000LL;
+
+       if (hpet) {
+               printk(KERN_INFO "TSC calibrated against HPET\n");
+               if (hpet2 < hpet1)
+                       hpet2 += 0x100000000ULL;
+               hpet2 -= hpet1;
+               tsc1 = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
+               do_div(tsc1, 1000000);
+       } else {
+               printk(KERN_INFO "TSC calibrated against PM_TIMER\n");
+               if (pm2 < pm1)
+                       pm2 += (u64)ACPI_PM_OVRRUN;
+               pm2 -= pm1;
+               tsc1 = pm2 * 1000000000LL;
+               do_div(tsc1, PMTMR_TICKS_PER_SEC);
+       }
+
+       do_div(tsc2, tsc1);
+       tsc_khz_val = tsc2;
+
+out:
+       return tsc_khz_val;
+}
+
+
+#ifdef CONFIG_X86_32
+/* Only called from the Powernow K7 cpu freq driver */
+int recalibrate_cpu_khz(void)
+{
+#ifndef CONFIG_SMP
+       unsigned long cpu_khz_old = cpu_khz;
+
+       if (cpu_has_tsc) {
+               tsc_khz = calibrate_tsc();
+               cpu_khz = tsc_khz;
+               cpu_data(0).loops_per_jiffy =
+                       cpufreq_scale(cpu_data(0).loops_per_jiffy,
+                                       cpu_khz_old, cpu_khz);
+               return 0;
+       } else
+               return -ENODEV;
+#else
+       return -ENODEV;
+#endif
+}
+
+EXPORT_SYMBOL(recalibrate_cpu_khz);
+
+#endif /* CONFIG_X86_32 */
+
+/* Accelerators for sched_clock()
+ * convert from cycles(64bits) => nanoseconds (64bits)
+ *  basic equation:
+ *              ns = cycles / (freq / ns_per_sec)
+ *              ns = cycles * (ns_per_sec / freq)
+ *              ns = cycles * (10^9 / (cpu_khz * 10^3))
+ *              ns = cycles * (10^6 / cpu_khz)
+ *
+ *      Then we use scaling math (suggested by george@mvista.com) to get:
+ *              ns = cycles * (10^6 * SC / cpu_khz) / SC
+ *              ns = cycles * cyc2ns_scale / SC
+ *
+ *      And since SC is a constant power of two, we can convert the div
+ *  into a shift.
+ *
+ *  We can use khz divisor instead of mhz to keep a better precision, since
+ *  cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
+ *  (mathieu.desnoyers@polymtl.ca)
+ *
+ *                      -johnstul@us.ibm.com "math is hard, lets go shopping!"
+ */
+
+DEFINE_PER_CPU(unsigned long, cyc2ns);
+
+static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
+{
+       unsigned long long tsc_now, ns_now;
+       unsigned long flags, *scale;
+
+       local_irq_save(flags);
+       sched_clock_idle_sleep_event();
+
+       scale = &per_cpu(cyc2ns, cpu);
+
+       rdtscll(tsc_now);
+       ns_now = __cycles_2_ns(tsc_now);
+
+       if (cpu_khz)
+               *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz;
+
+       sched_clock_idle_wakeup_event(0);
+       local_irq_restore(flags);
+}
+
+#ifdef CONFIG_CPU_FREQ
+
+/* Frequency scaling support. Adjust the TSC based timer when the cpu frequency
+ * changes.
+ *
+ * RED-PEN: On SMP we assume all CPUs run with the same frequency.  It's
+ * not that important because current Opteron setups do not support
+ * scaling on SMP anyroads.
+ *
+ * Should fix up last_tsc too. Currently gettimeofday in the
+ * first tick after the change will be slightly wrong.
+ */
+
+static unsigned int  ref_freq;
+static unsigned long loops_per_jiffy_ref;
+static unsigned long tsc_khz_ref;
+
+static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
+                               void *data)
+{
+       struct cpufreq_freqs *freq = data;
+       unsigned long *lpj, dummy;
+
+       if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
+               return 0;
+
+       lpj = &dummy;
+       if (!(freq->flags & CPUFREQ_CONST_LOOPS))
+#ifdef CONFIG_SMP
+               lpj = &cpu_data(freq->cpu).loops_per_jiffy;
+#else
+       lpj = &boot_cpu_data.loops_per_jiffy;
+#endif
+
+       if (!ref_freq) {
+               ref_freq = freq->old;
+               loops_per_jiffy_ref = *lpj;
+               tsc_khz_ref = tsc_khz;
+       }
+       if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
+                       (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
+                       (val == CPUFREQ_RESUMECHANGE)) {
+               *lpj =  cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
+
+               tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new);
+               if (!(freq->flags & CPUFREQ_CONST_LOOPS))
+                       mark_tsc_unstable("cpufreq changes");
+       }
+
+       set_cyc2ns_scale(tsc_khz_ref, freq->cpu);
+
+       return 0;
+}
+
+static struct notifier_block time_cpufreq_notifier_block = {
+       .notifier_call  = time_cpufreq_notifier
+};
+
+static int __init cpufreq_tsc(void)
+{
+       cpufreq_register_notifier(&time_cpufreq_notifier_block,
+                               CPUFREQ_TRANSITION_NOTIFIER);
+       return 0;
+}
+
+core_initcall(cpufreq_tsc);
+
+#endif /* CONFIG_CPU_FREQ */
+
+/* clocksource code */
+
+static struct clocksource clocksource_tsc;
+
+/*
+ * We compare the TSC to the cycle_last value in the clocksource
+ * structure to avoid a nasty time-warp. This can be observed in a
+ * very small window right after one CPU updated cycle_last under
+ * xtime/vsyscall_gtod lock and the other CPU reads a TSC value which
+ * is smaller than the cycle_last reference value due to a TSC which
+ * is slighty behind. This delta is nowhere else observable, but in
+ * that case it results in a forward time jump in the range of hours
+ * due to the unsigned delta calculation of the time keeping core
+ * code, which is necessary to support wrapping clocksources like pm
+ * timer.
+ */
+static cycle_t read_tsc(void)
+{
+       cycle_t ret = (cycle_t)get_cycles();
+
+       return ret >= clocksource_tsc.cycle_last ?
+               ret : clocksource_tsc.cycle_last;
+}
+
+static cycle_t __vsyscall_fn vread_tsc(void)
+{
+       cycle_t ret = (cycle_t)vget_cycles();
+
+       return ret >= __vsyscall_gtod_data.clock.cycle_last ?
+               ret : __vsyscall_gtod_data.clock.cycle_last;
+}
+
+static struct clocksource clocksource_tsc = {
+       .name                   = "tsc",
+       .rating                 = 300,
+       .read                   = read_tsc,
+       .mask                   = CLOCKSOURCE_MASK(64),
+       .shift                  = 22,
+       .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
+                                 CLOCK_SOURCE_MUST_VERIFY,
+#ifdef CONFIG_X86_64
+       .vread                  = vread_tsc,
+#endif
+};
+
+void mark_tsc_unstable(char *reason)
+{
+       if (!tsc_unstable) {
+               tsc_unstable = 1;
+               printk("Marking TSC unstable due to %s\n", reason);
+               /* Change only the rating, when not registered */
+               if (clocksource_tsc.mult)
+                       clocksource_change_rating(&clocksource_tsc, 0);
+               else
+                       clocksource_tsc.rating = 0;
+       }
+}
+
+EXPORT_SYMBOL_GPL(mark_tsc_unstable);
+
+static int __init dmi_mark_tsc_unstable(const struct dmi_system_id *d)
+{
+       printk(KERN_NOTICE "%s detected: marking TSC unstable.\n",
+                       d->ident);
+       tsc_unstable = 1;
+       return 0;
+}
+
+/* List of systems that have known TSC problems */
+static struct dmi_system_id __initdata bad_tsc_dmi_table[] = {
+       {
+               .callback = dmi_mark_tsc_unstable,
+               .ident = "IBM Thinkpad 380XD",
+               .matches = {
+                       DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
+                       DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
+               },
+       },
+       {}
+};
+
+/*
+ * Geode_LX - the OLPC CPU has a possibly a very reliable TSC
+ */
+#ifdef CONFIG_MGEODE_LX
+/* RTSC counts during suspend */
+#define RTSC_SUSP 0x100
+
+static void __init check_geode_tsc_reliable(void)
+{
+       unsigned long res_low, res_high;
+
+       rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high);
+       if (res_low & RTSC_SUSP)
+               clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
+}
+#else
+static inline void check_geode_tsc_reliable(void) { }
+#endif
+
+/*
+ * Make an educated guess if the TSC is trustworthy and synchronized
+ * over all CPUs.
+ */
+__cpuinit int unsynchronized_tsc(void)
+{
+       if (!cpu_has_tsc || tsc_unstable)
+               return 1;
+
+#ifdef CONFIG_SMP
+       if (apic_is_clustered_box())
+               return 1;
+#endif
+
+       if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
+               return 0;
+       /*
+        * Intel systems are normally all synchronized.
+        * Exceptions must mark TSC as unstable:
+        */
+       if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
+               /* assume multi socket systems are not synchronized: */
+               if (num_possible_cpus() > 1)
+                       tsc_unstable = 1;
+       }
+
+       return tsc_unstable;
+}
+
+static void __init init_tsc_clocksource(void)
+{
+       clocksource_tsc.mult = clocksource_khz2mult(tsc_khz,
+                       clocksource_tsc.shift);
+       /* lower the rating if we already know its unstable: */
+       if (check_tsc_unstable()) {
+               clocksource_tsc.rating = 0;
+               clocksource_tsc.flags &= ~CLOCK_SOURCE_IS_CONTINUOUS;
+       }
+       clocksource_register(&clocksource_tsc);
+}
+
+void __init tsc_init(void)
+{
+       u64 lpj;
+       int cpu;
+
+       if (!cpu_has_tsc)
+               return;
+
+       tsc_khz = calibrate_tsc();
+       cpu_khz = tsc_khz;
+
+       if (!tsc_khz) {
+               mark_tsc_unstable("could not calculate TSC khz");
+               return;
+       }
+
+#ifdef CONFIG_X86_64
+       if (cpu_has(&boot_cpu_data, X86_FEATURE_CONSTANT_TSC) &&
+                       (boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
+               cpu_khz = calibrate_cpu();
+#endif
+
+       lpj = ((u64)tsc_khz * 1000);
+       do_div(lpj, HZ);
+       lpj_fine = lpj;
+
+       printk("Detected %lu.%03lu MHz processor.\n",
+                       (unsigned long)cpu_khz / 1000,
+                       (unsigned long)cpu_khz % 1000);
+
+       /*
+        * Secondary CPUs do not run through tsc_init(), so set up
+        * all the scale factors for all CPUs, assuming the same
+        * speed as the bootup CPU. (cpufreq notifiers will fix this
+        * up if their speed diverges)
+        */
+       for_each_possible_cpu(cpu)
+               set_cyc2ns_scale(cpu_khz, cpu);
+
+       if (tsc_disabled > 0)
+               return;
+
+       /* now allow native_sched_clock() to use rdtsc */
+       tsc_disabled = 0;
+
+       use_tsc_delay();
+       /* Check and install the TSC clocksource */
+       dmi_check_system(bad_tsc_dmi_table);
+
+       if (unsynchronized_tsc())
+               mark_tsc_unstable("TSCs unsynchronized");
+
+       check_geode_tsc_reliable();
+       init_tsc_clocksource();
+}
+
diff --git a/arch/x86/kernel/tsc_32.c b/arch/x86/kernel/tsc_32.c
deleted file mode 100644 (file)
index 65b7063..0000000
+++ /dev/null
@@ -1,451 +0,0 @@
-#include <linux/sched.h>
-#include <linux/clocksource.h>
-#include <linux/workqueue.h>
-#include <linux/cpufreq.h>
-#include <linux/jiffies.h>
-#include <linux/init.h>
-#include <linux/dmi.h>
-#include <linux/percpu.h>
-
-#include <asm/delay.h>
-#include <asm/tsc.h>
-#include <asm/io.h>
-#include <asm/timer.h>
-
-#include "mach_timer.h"
-
-/* native_sched_clock() is called before tsc_init(), so
-   we must start with the TSC soft disabled to prevent
-   erroneous rdtsc usage on !cpu_has_tsc processors */
-static int tsc_disabled = -1;
-
-/*
- * On some systems the TSC frequency does not
- * change with the cpu frequency. So we need
- * an extra value to store the TSC freq
- */
-unsigned int tsc_khz;
-EXPORT_SYMBOL_GPL(tsc_khz);
-
-#ifdef CONFIG_X86_TSC
-static int __init tsc_setup(char *str)
-{
-       printk(KERN_WARNING "notsc: Kernel compiled with CONFIG_X86_TSC, "
-              "cannot disable TSC completely.\n");
-       tsc_disabled = 1;
-       return 1;
-}
-#else
-/*
- * disable flag for tsc. Takes effect by clearing the TSC cpu flag
- * in cpu/common.c
- */
-static int __init tsc_setup(char *str)
-{
-       setup_clear_cpu_cap(X86_FEATURE_TSC);
-       return 1;
-}
-#endif
-
-__setup("notsc", tsc_setup);
-
-/*
- * code to mark and check if the TSC is unstable
- * due to cpufreq or due to unsynced TSCs
- */
-static int tsc_unstable;
-
-int check_tsc_unstable(void)
-{
-       return tsc_unstable;
-}
-EXPORT_SYMBOL_GPL(check_tsc_unstable);
-
-/* Accelerators for sched_clock()
- * convert from cycles(64bits) => nanoseconds (64bits)
- *  basic equation:
- *             ns = cycles / (freq / ns_per_sec)
- *             ns = cycles * (ns_per_sec / freq)
- *             ns = cycles * (10^9 / (cpu_khz * 10^3))
- *             ns = cycles * (10^6 / cpu_khz)
- *
- *     Then we use scaling math (suggested by george@mvista.com) to get:
- *             ns = cycles * (10^6 * SC / cpu_khz) / SC
- *             ns = cycles * cyc2ns_scale / SC
- *
- *     And since SC is a constant power of two, we can convert the div
- *  into a shift.
- *
- *  We can use khz divisor instead of mhz to keep a better precision, since
- *  cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
- *  (mathieu.desnoyers@polymtl.ca)
- *
- *                     -johnstul@us.ibm.com "math is hard, lets go shopping!"
- */
-
-DEFINE_PER_CPU(unsigned long, cyc2ns);
-
-static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
-{
-       unsigned long long tsc_now, ns_now;
-       unsigned long flags, *scale;
-
-       local_irq_save(flags);
-       sched_clock_idle_sleep_event();
-
-       scale = &per_cpu(cyc2ns, cpu);
-
-       rdtscll(tsc_now);
-       ns_now = __cycles_2_ns(tsc_now);
-
-       if (cpu_khz)
-               *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz;
-
-       /*
-        * Start smoothly with the new frequency:
-        */
-       sched_clock_idle_wakeup_event(0);
-       local_irq_restore(flags);
-}
-
-/*
- * Scheduler clock - returns current time in nanosec units.
- */
-unsigned long long native_sched_clock(void)
-{
-       unsigned long long this_offset;
-
-       /*
-        * Fall back to jiffies if there's no TSC available:
-        * ( But note that we still use it if the TSC is marked
-        *   unstable. We do this because unlike Time Of Day,
-        *   the scheduler clock tolerates small errors and it's
-        *   very important for it to be as fast as the platform
-        *   can achive it. )
-        */
-       if (unlikely(tsc_disabled))
-               /* No locking but a rare wrong value is not a big deal: */
-               return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ);
-
-       /* read the Time Stamp Counter: */
-       rdtscll(this_offset);
-
-       /* return the value in ns */
-       return cycles_2_ns(this_offset);
-}
-
-/* We need to define a real function for sched_clock, to override the
-   weak default version */
-#ifdef CONFIG_PARAVIRT
-unsigned long long sched_clock(void)
-{
-       return paravirt_sched_clock();
-}
-#else
-unsigned long long sched_clock(void)
-       __attribute__((alias("native_sched_clock")));
-#endif
-
-unsigned long native_calculate_cpu_khz(void)
-{
-       unsigned long long start, end;
-       unsigned long count;
-       u64 delta64 = (u64)ULLONG_MAX;
-       int i;
-       unsigned long flags;
-
-       local_irq_save(flags);
-
-       /* run 3 times to ensure the cache is warm and to get an accurate reading */
-       for (i = 0; i < 3; i++) {
-               mach_prepare_counter();
-               rdtscll(start);
-               mach_countup(&count);
-               rdtscll(end);
-
-               /*
-                * Error: ECTCNEVERSET
-                * The CTC wasn't reliable: we got a hit on the very first read,
-                * or the CPU was so fast/slow that the quotient wouldn't fit in
-                * 32 bits..
-                */
-               if (count <= 1)
-                       continue;
-
-               /* cpu freq too slow: */
-               if ((end - start) <= CALIBRATE_TIME_MSEC)
-                       continue;
-
-               /*
-                * We want the minimum time of all runs in case one of them
-                * is inaccurate due to SMI or other delay
-                */
-               delta64 = min(delta64, (end - start));
-       }
-
-       /* cpu freq too fast (or every run was bad): */
-       if (delta64 > (1ULL<<32))
-               goto err;
-
-       delta64 += CALIBRATE_TIME_MSEC/2; /* round for do_div */
-       do_div(delta64,CALIBRATE_TIME_MSEC);
-
-       local_irq_restore(flags);
-       return (unsigned long)delta64;
-err:
-       local_irq_restore(flags);
-       return 0;
-}
-
-int recalibrate_cpu_khz(void)
-{
-#ifndef CONFIG_SMP
-       unsigned long cpu_khz_old = cpu_khz;
-
-       if (cpu_has_tsc) {
-               cpu_khz = calculate_cpu_khz();
-               tsc_khz = cpu_khz;
-               cpu_data(0).loops_per_jiffy =
-                       cpufreq_scale(cpu_data(0).loops_per_jiffy,
-                                       cpu_khz_old, cpu_khz);
-               return 0;
-       } else
-               return -ENODEV;
-#else
-       return -ENODEV;
-#endif
-}
-
-EXPORT_SYMBOL(recalibrate_cpu_khz);
-
-#ifdef CONFIG_CPU_FREQ
-
-/*
- * if the CPU frequency is scaled, TSC-based delays will need a different
- * loops_per_jiffy value to function properly.
- */
-static unsigned int ref_freq;
-static unsigned long loops_per_jiffy_ref;
-static unsigned long cpu_khz_ref;
-
-static int
-time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
-{
-       struct cpufreq_freqs *freq = data;
-
-       if (!ref_freq) {
-               if (!freq->old){
-                       ref_freq = freq->new;
-                       return 0;
-               }
-               ref_freq = freq->old;
-               loops_per_jiffy_ref = cpu_data(freq->cpu).loops_per_jiffy;
-               cpu_khz_ref = cpu_khz;
-       }
-
-       if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
-           (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
-           (val == CPUFREQ_RESUMECHANGE)) {
-               if (!(freq->flags & CPUFREQ_CONST_LOOPS))
-                       cpu_data(freq->cpu).loops_per_jiffy =
-                               cpufreq_scale(loops_per_jiffy_ref,
-                                               ref_freq, freq->new);
-
-               if (cpu_khz) {
-
-                       if (num_online_cpus() == 1)
-                               cpu_khz = cpufreq_scale(cpu_khz_ref,
-                                               ref_freq, freq->new);
-                       if (!(freq->flags & CPUFREQ_CONST_LOOPS)) {
-                               tsc_khz = cpu_khz;
-                               set_cyc2ns_scale(cpu_khz, freq->cpu);
-                               /*
-                                * TSC based sched_clock turns
-                                * to junk w/ cpufreq
-                                */
-                               mark_tsc_unstable("cpufreq changes");
-                       }
-               }
-       }
-
-       return 0;
-}
-
-static struct notifier_block time_cpufreq_notifier_block = {
-       .notifier_call  = time_cpufreq_notifier
-};
-
-static int __init cpufreq_tsc(void)
-{
-       return cpufreq_register_notifier(&time_cpufreq_notifier_block,
-                                        CPUFREQ_TRANSITION_NOTIFIER);
-}
-core_initcall(cpufreq_tsc);
-
-#endif
-
-/* clock source code */
-
-static unsigned long current_tsc_khz;
-static struct clocksource clocksource_tsc;
-
-/*
- * We compare the TSC to the cycle_last value in the clocksource
- * structure to avoid a nasty time-warp issue. This can be observed in
- * a very small window right after one CPU updated cycle_last under
- * xtime lock and the other CPU reads a TSC value which is smaller
- * than the cycle_last reference value due to a TSC which is slighty
- * behind. This delta is nowhere else observable, but in that case it
- * results in a forward time jump in the range of hours due to the
- * unsigned delta calculation of the time keeping core code, which is
- * necessary to support wrapping clocksources like pm timer.
- */
-static cycle_t read_tsc(void)
-{
-       cycle_t ret;
-
-       rdtscll(ret);
-
-       return ret >= clocksource_tsc.cycle_last ?
-               ret : clocksource_tsc.cycle_last;
-}
-
-static struct clocksource clocksource_tsc = {
-       .name                   = "tsc",
-       .rating                 = 300,
-       .read                   = read_tsc,
-       .mask                   = CLOCKSOURCE_MASK(64),
-       .mult                   = 0, /* to be set */
-       .shift                  = 22,
-       .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
-                                 CLOCK_SOURCE_MUST_VERIFY,
-};
-
-void mark_tsc_unstable(char *reason)
-{
-       if (!tsc_unstable) {
-               tsc_unstable = 1;
-               printk("Marking TSC unstable due to: %s.\n", reason);
-               /* Can be called before registration */
-               if (clocksource_tsc.mult)
-                       clocksource_change_rating(&clocksource_tsc, 0);
-               else
-                       clocksource_tsc.rating = 0;
-       }
-}
-EXPORT_SYMBOL_GPL(mark_tsc_unstable);
-
-static int __init dmi_mark_tsc_unstable(const struct dmi_system_id *d)
-{
-       printk(KERN_NOTICE "%s detected: marking TSC unstable.\n",
-              d->ident);
-       tsc_unstable = 1;
-       return 0;
-}
-
-/* List of systems that have known TSC problems */
-static struct dmi_system_id __initdata bad_tsc_dmi_table[] = {
-       {
-        .callback = dmi_mark_tsc_unstable,
-        .ident = "IBM Thinkpad 380XD",
-        .matches = {
-                    DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
-                    DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
-                    },
-        },
-        {}
-};
-
-/*
- * Make an educated guess if the TSC is trustworthy and synchronized
- * over all CPUs.
- */
-__cpuinit int unsynchronized_tsc(void)
-{
-       if (!cpu_has_tsc || tsc_unstable)
-               return 1;
-
-       /* Anything with constant TSC should be synchronized */
-       if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
-               return 0;
-
-       /*
-        * Intel systems are normally all synchronized.
-        * Exceptions must mark TSC as unstable:
-        */
-       if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
-               /* assume multi socket systems are not synchronized: */
-               if (num_possible_cpus() > 1)
-                       tsc_unstable = 1;
-       }
-       return tsc_unstable;
-}
-
-/*
- * Geode_LX - the OLPC CPU has a possibly a very reliable TSC
- */
-#ifdef CONFIG_MGEODE_LX
-/* RTSC counts during suspend */
-#define RTSC_SUSP 0x100
-
-static void __init check_geode_tsc_reliable(void)
-{
-       unsigned long res_low, res_high;
-
-       rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high);
-       if (res_low & RTSC_SUSP)
-               clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
-}
-#else
-static inline void check_geode_tsc_reliable(void) { }
-#endif
-
-
-void __init tsc_init(void)
-{
-       int cpu;
-
-       if (!cpu_has_tsc || tsc_disabled > 0)
-               return;
-
-       cpu_khz = calculate_cpu_khz();
-       tsc_khz = cpu_khz;
-
-       if (!cpu_khz) {
-               mark_tsc_unstable("could not calculate TSC khz");
-               return;
-       }
-
-       /* now allow native_sched_clock() to use rdtsc */
-       tsc_disabled = 0;
-
-       printk("Detected %lu.%03lu MHz processor.\n",
-                               (unsigned long)cpu_khz / 1000,
-                               (unsigned long)cpu_khz % 1000);
-
-       /*
-        * Secondary CPUs do not run through tsc_init(), so set up
-        * all the scale factors for all CPUs, assuming the same
-        * speed as the bootup CPU. (cpufreq notifiers will fix this
-        * up if their speed diverges)
-        */
-       for_each_possible_cpu(cpu)
-               set_cyc2ns_scale(cpu_khz, cpu);
-
-       use_tsc_delay();
-
-       /* Check and install the TSC clocksource */
-       dmi_check_system(bad_tsc_dmi_table);
-
-       unsynchronized_tsc();
-       check_geode_tsc_reliable();
-       current_tsc_khz = tsc_khz;
-       clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
-                                                       clocksource_tsc.shift);
-       /* lower the rating if we already know its unstable: */
-       if (check_tsc_unstable()) {
-               clocksource_tsc.rating = 0;
-               clocksource_tsc.flags &= ~CLOCK_SOURCE_IS_CONTINUOUS;
-       }
-       clocksource_register(&clocksource_tsc);
-}
diff --git a/arch/x86/kernel/tsc_64.c b/arch/x86/kernel/tsc_64.c
deleted file mode 100644 (file)
index 1784b80..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
-#include <linux/clocksource.h>
-#include <linux/time.h>
-#include <linux/acpi.h>
-#include <linux/cpufreq.h>
-#include <linux/acpi_pmtmr.h>
-
-#include <asm/hpet.h>
-#include <asm/timex.h>
-#include <asm/timer.h>
-#include <asm/vgtod.h>
-
-static int notsc __initdata = 0;
-
-unsigned int cpu_khz;          /* TSC clocks / usec, not used here */
-EXPORT_SYMBOL(cpu_khz);
-unsigned int tsc_khz;
-EXPORT_SYMBOL(tsc_khz);
-
-/* Accelerators for sched_clock()
- * convert from cycles(64bits) => nanoseconds (64bits)
- *  basic equation:
- *             ns = cycles / (freq / ns_per_sec)
- *             ns = cycles * (ns_per_sec / freq)
- *             ns = cycles * (10^9 / (cpu_khz * 10^3))
- *             ns = cycles * (10^6 / cpu_khz)
- *
- *     Then we use scaling math (suggested by george@mvista.com) to get:
- *             ns = cycles * (10^6 * SC / cpu_khz) / SC
- *             ns = cycles * cyc2ns_scale / SC
- *
- *     And since SC is a constant power of two, we can convert the div
- *  into a shift.
- *
- *  We can use khz divisor instead of mhz to keep a better precision, since
- *  cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
- *  (mathieu.desnoyers@polymtl.ca)
- *
- *                     -johnstul@us.ibm.com "math is hard, lets go shopping!"
- */
-DEFINE_PER_CPU(unsigned long, cyc2ns);
-
-static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
-{
-       unsigned long long tsc_now, ns_now;
-       unsigned long flags, *scale;
-
-       local_irq_save(flags);
-       sched_clock_idle_sleep_event();
-
-       scale = &per_cpu(cyc2ns, cpu);
-
-       rdtscll(tsc_now);
-       ns_now = __cycles_2_ns(tsc_now);
-
-       if (cpu_khz)
-               *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz;
-
-       sched_clock_idle_wakeup_event(0);
-       local_irq_restore(flags);
-}
-
-unsigned long long native_sched_clock(void)
-{
-       unsigned long a = 0;
-
-       /* Could do CPU core sync here. Opteron can execute rdtsc speculatively,
-        * which means it is not completely exact and may not be monotonous
-        * between CPUs. But the errors should be too small to matter for
-        * scheduling purposes.
-        */
-
-       rdtscll(a);
-       return cycles_2_ns(a);
-}
-
-/* We need to define a real function for sched_clock, to override the
-   weak default version */
-#ifdef CONFIG_PARAVIRT
-unsigned long long sched_clock(void)
-{
-       return paravirt_sched_clock();
-}
-#else
-unsigned long long
-sched_clock(void) __attribute__((alias("native_sched_clock")));
-#endif
-
-
-static int tsc_unstable;
-
-int check_tsc_unstable(void)
-{
-       return tsc_unstable;
-}
-EXPORT_SYMBOL_GPL(check_tsc_unstable);
-
-#ifdef CONFIG_CPU_FREQ
-
-/* Frequency scaling support. Adjust the TSC based timer when the cpu frequency
- * changes.
- *
- * RED-PEN: On SMP we assume all CPUs run with the same frequency.  It's
- * not that important because current Opteron setups do not support
- * scaling on SMP anyroads.
- *
- * Should fix up last_tsc too. Currently gettimeofday in the
- * first tick after the change will be slightly wrong.
- */
-
-static unsigned int  ref_freq;
-static unsigned long loops_per_jiffy_ref;
-static unsigned long tsc_khz_ref;
-
-static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
-                                void *data)
-{
-       struct cpufreq_freqs *freq = data;
-       unsigned long *lpj, dummy;
-
-       if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
-               return 0;
-
-       lpj = &dummy;
-       if (!(freq->flags & CPUFREQ_CONST_LOOPS))
-#ifdef CONFIG_SMP
-               lpj = &cpu_data(freq->cpu).loops_per_jiffy;
-#else
-               lpj = &boot_cpu_data.loops_per_jiffy;
-#endif
-
-       if (!ref_freq) {
-               ref_freq = freq->old;
-               loops_per_jiffy_ref = *lpj;
-               tsc_khz_ref = tsc_khz;
-       }
-       if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
-               (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
-               (val == CPUFREQ_RESUMECHANGE)) {
-               *lpj =
-               cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
-
-               tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new);
-               if (!(freq->flags & CPUFREQ_CONST_LOOPS))
-                       mark_tsc_unstable("cpufreq changes");
-       }
-
-       set_cyc2ns_scale(tsc_khz_ref, freq->cpu);
-
-       return 0;
-}
-
-static struct notifier_block time_cpufreq_notifier_block = {
-       .notifier_call  = time_cpufreq_notifier
-};
-
-static int __init cpufreq_tsc(void)
-{
-       cpufreq_register_notifier(&time_cpufreq_notifier_block,
-                                 CPUFREQ_TRANSITION_NOTIFIER);
-       return 0;
-}
-
-core_initcall(cpufreq_tsc);
-
-#endif
-
-#define MAX_RETRIES    5
-#define SMI_TRESHOLD   50000
-
-/*
- * Read TSC and the reference counters. Take care of SMI disturbance
- */
-static unsigned long __init tsc_read_refs(unsigned long *pm,
-                                         unsigned long *hpet)
-{
-       unsigned long t1, t2;
-       int i;
-
-       for (i = 0; i < MAX_RETRIES; i++) {
-               t1 = get_cycles();
-               if (hpet)
-                       *hpet = hpet_readl(HPET_COUNTER) & 0xFFFFFFFF;
-               else
-                       *pm = acpi_pm_read_early();
-               t2 = get_cycles();
-               if ((t2 - t1) < SMI_TRESHOLD)
-                       return t2;
-       }
-       return ULONG_MAX;
-}
-
-/**
- * tsc_calibrate - calibrate the tsc on boot
- */
-void __init tsc_calibrate(void)
-{
-       unsigned long flags, tsc1, tsc2, tr1, tr2, pm1, pm2, hpet1, hpet2;
-       int hpet = is_hpet_enabled(), cpu;
-
-       local_irq_save(flags);
-
-       tsc1 = tsc_read_refs(&pm1, hpet ? &hpet1 : NULL);
-
-       outb((inb(0x61) & ~0x02) | 0x01, 0x61);
-
-       outb(0xb0, 0x43);
-       outb((CLOCK_TICK_RATE / (1000 / 50)) & 0xff, 0x42);
-       outb((CLOCK_TICK_RATE / (1000 / 50)) >> 8, 0x42);
-       tr1 = get_cycles();
-       while ((inb(0x61) & 0x20) == 0);
-       tr2 = get_cycles();
-
-       tsc2 = tsc_read_refs(&pm2, hpet ? &hpet2 : NULL);
-
-       local_irq_restore(flags);
-
-       /*
-        * Preset the result with the raw and inaccurate PIT
-        * calibration value
-        */
-       tsc_khz = (tr2 - tr1) / 50;
-
-       /* hpet or pmtimer available ? */
-       if (!hpet && !pm1 && !pm2) {
-               printk(KERN_INFO "TSC calibrated against PIT\n");
-               goto out;
-       }
-
-       /* Check, whether the sampling was disturbed by an SMI */
-       if (tsc1 == ULONG_MAX || tsc2 == ULONG_MAX) {
-               printk(KERN_WARNING "TSC calibration disturbed by SMI, "
-                      "using PIT calibration result\n");
-               goto out;
-       }
-
-       tsc2 = (tsc2 - tsc1) * 1000000L;
-
-       if (hpet) {
-               printk(KERN_INFO "TSC calibrated against HPET\n");
-               if (hpet2 < hpet1)
-                       hpet2 += 0x100000000;
-               hpet2 -= hpet1;
-               tsc1 = (hpet2 * hpet_readl(HPET_PERIOD)) / 1000000;
-       } else {
-               printk(KERN_INFO "TSC calibrated against PM_TIMER\n");
-               if (pm2 < pm1)
-                       pm2 += ACPI_PM_OVRRUN;
-               pm2 -= pm1;
-               tsc1 = (pm2 * 1000000000) / PMTMR_TICKS_PER_SEC;
-       }
-
-       tsc_khz = tsc2 / tsc1;
-
-out:
-       for_each_possible_cpu(cpu)
-               set_cyc2ns_scale(tsc_khz, cpu);
-}
-
-/*
- * Make an educated guess if the TSC is trustworthy and synchronized
- * over all CPUs.
- */
-__cpuinit int unsynchronized_tsc(void)
-{
-       if (tsc_unstable)
-               return 1;
-
-#ifdef CONFIG_SMP
-       if (apic_is_clustered_box())
-               return 1;
-#endif
-
-       if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
-               return 0;
-
-       /* Assume multi socket systems are not synchronized */
-       return num_present_cpus() > 1;
-}
-
-int __init notsc_setup(char *s)
-{
-       notsc = 1;
-       return 1;
-}
-
-__setup("notsc", notsc_setup);
-
-static struct clocksource clocksource_tsc;
-
-/*
- * We compare the TSC to the cycle_last value in the clocksource
- * structure to avoid a nasty time-warp. This can be observed in a
- * very small window right after one CPU updated cycle_last under
- * xtime/vsyscall_gtod lock and the other CPU reads a TSC value which
- * is smaller than the cycle_last reference value due to a TSC which
- * is slighty behind. This delta is nowhere else observable, but in
- * that case it results in a forward time jump in the range of hours
- * due to the unsigned delta calculation of the time keeping core
- * code, which is necessary to support wrapping clocksources like pm
- * timer.
- */
-static cycle_t read_tsc(void)
-{
-       cycle_t ret = (cycle_t)get_cycles();
-
-       return ret >= clocksource_tsc.cycle_last ?
-               ret : clocksource_tsc.cycle_last;
-}
-
-static cycle_t __vsyscall_fn vread_tsc(void)
-{
-       cycle_t ret = (cycle_t)vget_cycles();
-
-       return ret >= __vsyscall_gtod_data.clock.cycle_last ?
-               ret : __vsyscall_gtod_data.clock.cycle_last;
-}
-
-static struct clocksource clocksource_tsc = {
-       .name                   = "tsc",
-       .rating                 = 300,
-       .read                   = read_tsc,
-       .mask                   = CLOCKSOURCE_MASK(64),
-       .shift                  = 22,
-       .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
-                                 CLOCK_SOURCE_MUST_VERIFY,
-       .vread                  = vread_tsc,
-};
-
-void mark_tsc_unstable(char *reason)
-{
-       if (!tsc_unstable) {
-               tsc_unstable = 1;
-               printk("Marking TSC unstable due to %s\n", reason);
-               /* Change only the rating, when not registered */
-               if (clocksource_tsc.mult)
-                       clocksource_change_rating(&clocksource_tsc, 0);
-               else
-                       clocksource_tsc.rating = 0;
-       }
-}
-EXPORT_SYMBOL_GPL(mark_tsc_unstable);
-
-void __init init_tsc_clocksource(void)
-{
-       if (!notsc) {
-               clocksource_tsc.mult = clocksource_khz2mult(tsc_khz,
-                                                       clocksource_tsc.shift);
-               if (check_tsc_unstable())
-                       clocksource_tsc.rating = 0;
-
-               clocksource_register(&clocksource_tsc);
-       }
-}
diff --git a/arch/x86/kernel/visws_quirks.c b/arch/x86/kernel/visws_quirks.c
new file mode 100644 (file)
index 0000000..e94bdb6
--- /dev/null
@@ -0,0 +1,709 @@
+/*
+ *  SGI Visual Workstation support and quirks, unmaintained.
+ *
+ *  Split out from setup.c by davej@suse.de
+ *
+ *     Copyright (C) 1999 Bent Hagemark, Ingo Molnar
+ *
+ *  SGI Visual Workstation interrupt controller
+ *
+ *  The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
+ *  which serves as the main interrupt controller in the system.  Non-legacy
+ *  hardware in the system uses this controller directly.  Legacy devices
+ *  are connected to the PIIX4 which in turn has its 8259(s) connected to
+ *  a of the Cobalt APIC entry.
+ *
+ *  09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
+ *
+ *  25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
+ */
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/smp.h>
+
+#include <asm/visws/cobalt.h>
+#include <asm/visws/piix4.h>
+#include <asm/arch_hooks.h>
+#include <asm/fixmap.h>
+#include <asm/reboot.h>
+#include <asm/setup.h>
+#include <asm/e820.h>
+#include <asm/smp.h>
+#include <asm/io.h>
+
+#include <mach_ipi.h>
+
+#include "mach_apic.h"
+
+#include <linux/init.h>
+#include <linux/smp.h>
+
+#include <linux/kernel_stat.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/apic.h>
+#include <asm/i8259.h>
+#include <asm/irq_vectors.h>
+#include <asm/visws/cobalt.h>
+#include <asm/visws/lithium.h>
+#include <asm/visws/piix4.h>
+
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/pci_ids.h>
+
+extern int no_broadcast;
+
+#include <asm/io.h>
+#include <asm/apic.h>
+#include <asm/arch_hooks.h>
+#include <asm/visws/cobalt.h>
+#include <asm/visws/lithium.h>
+
+char visws_board_type  = -1;
+char visws_board_rev   = -1;
+
+int is_visws_box(void)
+{
+       return visws_board_type >= 0;
+}
+
+static int __init visws_time_init_quirk(void)
+{
+       printk(KERN_INFO "Starting Cobalt Timer system clock\n");
+
+       /* Set the countdown value */
+       co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
+
+       /* Start the timer */
+       co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
+
+       /* Enable (unmask) the timer interrupt */
+       co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
+
+       /*
+        * Zero return means the generic timer setup code will set up
+        * the standard vector:
+        */
+       return 0;
+}
+
+static int __init visws_pre_intr_init_quirk(void)
+{
+       init_VISWS_APIC_irqs();
+
+       /*
+        * We dont want ISA irqs to be set up by the generic code:
+        */
+       return 1;
+}
+
+/* Quirk for machine specific memory setup. */
+
+#define MB (1024 * 1024)
+
+unsigned long sgivwfb_mem_phys;
+unsigned long sgivwfb_mem_size;
+EXPORT_SYMBOL(sgivwfb_mem_phys);
+EXPORT_SYMBOL(sgivwfb_mem_size);
+
+long long mem_size __initdata = 0;
+
+static char * __init visws_memory_setup_quirk(void)
+{
+       long long gfx_mem_size = 8 * MB;
+
+       mem_size = boot_params.alt_mem_k;
+
+       if (!mem_size) {
+               printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
+               mem_size = 128 * MB;
+       }
+
+       /*
+        * this hardcodes the graphics memory to 8 MB
+        * it really should be sized dynamically (or at least
+        * set as a boot param)
+        */
+       if (!sgivwfb_mem_size) {
+               printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
+               sgivwfb_mem_size = 8 * MB;
+       }
+
+       /*
+        * Trim to nearest MB
+        */
+       sgivwfb_mem_size &= ~((1 << 20) - 1);
+       sgivwfb_mem_phys = mem_size - gfx_mem_size;
+
+       e820_add_region(0, LOWMEMSIZE(), E820_RAM);
+       e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
+       e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
+
+       return "PROM";
+}
+
+static void visws_machine_emergency_restart(void)
+{
+       /*
+        * Visual Workstations restart after this
+        * register is poked on the PIIX4
+        */
+       outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
+}
+
+static void visws_machine_power_off(void)
+{
+       unsigned short pm_status;
+/*     extern unsigned int pci_bus0; */
+
+       while ((pm_status = inw(PMSTS_PORT)) & 0x100)
+               outw(pm_status, PMSTS_PORT);
+
+       outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
+
+       mdelay(10);
+
+#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
+       (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
+
+/*     outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
+       outl(PIIX_SPECIAL_STOP, 0xCFC);
+}
+
+static int __init visws_get_smp_config_quirk(unsigned int early)
+{
+       /*
+        * Prevent MP-table parsing by the generic code:
+        */
+       return 1;
+}
+
+extern unsigned int __cpuinitdata maxcpus;
+
+/*
+ * The Visual Workstation is Intel MP compliant in the hardware
+ * sense, but it doesn't have a BIOS(-configuration table).
+ * No problem for Linux.
+ */
+
+static void __init MP_processor_info (struct mpc_config_processor *m)
+{
+       int ver, logical_apicid;
+       physid_mask_t apic_cpus;
+
+       if (!(m->mpc_cpuflag & CPU_ENABLED))
+               return;
+
+       logical_apicid = m->mpc_apicid;
+       printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
+              m->mpc_cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
+              m->mpc_apicid,
+              (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
+              (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
+              m->mpc_apicver);
+
+       if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
+               boot_cpu_physical_apicid = m->mpc_apicid;
+
+       ver = m->mpc_apicver;
+       if ((ver >= 0x14 && m->mpc_apicid >= 0xff) || m->mpc_apicid >= 0xf) {
+               printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
+                       m->mpc_apicid, MAX_APICS);
+               return;
+       }
+
+       apic_cpus = apicid_to_cpu_present(m->mpc_apicid);
+       physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
+       /*
+        * Validate version
+        */
+       if (ver == 0x0) {
+               printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
+                       "fixing up to 0x10. (tell your hw vendor)\n",
+                       m->mpc_apicid);
+               ver = 0x10;
+       }
+       apic_version[m->mpc_apicid] = ver;
+}
+
+int __init visws_find_smp_config_quirk(unsigned int reserve)
+{
+       struct mpc_config_processor *mp = phys_to_virt(CO_CPU_TAB_PHYS);
+       unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
+
+       if (ncpus > CO_CPU_MAX) {
+               printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
+                       ncpus, mp);
+
+               ncpus = CO_CPU_MAX;
+       }
+
+       if (ncpus > maxcpus)
+               ncpus = maxcpus;
+
+#ifdef CONFIG_X86_LOCAL_APIC
+       smp_found_config = 1;
+#endif
+       while (ncpus--)
+               MP_processor_info(mp++);
+
+       mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+
+       return 1;
+}
+
+extern int visws_trap_init_quirk(void);
+
+void __init visws_early_detect(void)
+{
+       int raw;
+
+       visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
+                                                        >> PIIX_GPI_BD_SHIFT;
+
+       if (visws_board_type < 0)
+               return;
+
+       /*
+        * Install special quirks for timer, interrupt and memory setup:
+        */
+       arch_time_init_quirk            = visws_time_init_quirk;
+       arch_pre_intr_init_quirk        = visws_pre_intr_init_quirk;
+       arch_memory_setup_quirk         = visws_memory_setup_quirk;
+
+       /*
+        * Fall back to generic behavior for traps:
+        */
+       arch_intr_init_quirk            = NULL;
+       arch_trap_init_quirk            = visws_trap_init_quirk;
+
+       /*
+        * Install reboot quirks:
+        */
+       pm_power_off                    = visws_machine_power_off;
+       machine_ops.emergency_restart   = visws_machine_emergency_restart;
+
+       /*
+        * Do not use broadcast IPIs:
+        */
+       no_broadcast = 0;
+
+       /*
+        * Override generic MP-table parsing:
+        */
+       mach_get_smp_config_quirk       = visws_get_smp_config_quirk;
+       mach_find_smp_config_quirk      = visws_find_smp_config_quirk;
+
+#ifdef CONFIG_X86_IO_APIC
+       /*
+        * Turn off IO-APIC detection and initialization:
+        */
+       skip_ioapic_setup               = 1;
+#endif
+
+       /*
+        * Get Board rev.
+        * First, we have to initialize the 307 part to allow us access
+        * to the GPIO registers.  Let's map them at 0x0fc0 which is right
+        * after the PIIX4 PM section.
+        */
+       outb_p(SIO_DEV_SEL, SIO_INDEX);
+       outb_p(SIO_GP_DEV, SIO_DATA);   /* Talk to GPIO regs. */
+
+       outb_p(SIO_DEV_MSB, SIO_INDEX);
+       outb_p(SIO_GP_MSB, SIO_DATA);   /* MSB of GPIO base address */
+
+       outb_p(SIO_DEV_LSB, SIO_INDEX);
+       outb_p(SIO_GP_LSB, SIO_DATA);   /* LSB of GPIO base address */
+
+       outb_p(SIO_DEV_ENB, SIO_INDEX);
+       outb_p(1, SIO_DATA);            /* Enable GPIO registers. */
+
+       /*
+        * Now, we have to map the power management section to write
+        * a bit which enables access to the GPIO registers.
+        * What lunatic came up with this shit?
+        */
+       outb_p(SIO_DEV_SEL, SIO_INDEX);
+       outb_p(SIO_PM_DEV, SIO_DATA);   /* Talk to GPIO regs. */
+
+       outb_p(SIO_DEV_MSB, SIO_INDEX);
+       outb_p(SIO_PM_MSB, SIO_DATA);   /* MSB of PM base address */
+
+       outb_p(SIO_DEV_LSB, SIO_INDEX);
+       outb_p(SIO_PM_LSB, SIO_DATA);   /* LSB of PM base address */
+
+       outb_p(SIO_DEV_ENB, SIO_INDEX);
+       outb_p(1, SIO_DATA);            /* Enable PM registers. */
+
+       /*
+        * Now, write the PM register which enables the GPIO registers.
+        */
+       outb_p(SIO_PM_FER2, SIO_PM_INDEX);
+       outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
+
+       /*
+        * Now, initialize the GPIO registers.
+        * We want them all to be inputs which is the
+        * power on default, so let's leave them alone.
+        * So, let's just read the board rev!
+        */
+       raw = inb_p(SIO_GP_DATA1);
+       raw &= 0x7f;    /* 7 bits of valid board revision ID. */
+
+       if (visws_board_type == VISWS_320) {
+               if (raw < 0x6) {
+                       visws_board_rev = 4;
+               } else if (raw < 0xc) {
+                       visws_board_rev = 5;
+               } else {
+                       visws_board_rev = 6;
+               }
+       } else if (visws_board_type == VISWS_540) {
+                       visws_board_rev = 2;
+               } else {
+                       visws_board_rev = raw;
+               }
+
+       printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
+              (visws_board_type == VISWS_320 ? "320" :
+              (visws_board_type == VISWS_540 ? "540" :
+               "unknown")), visws_board_rev);
+}
+
+#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
+#define BCD (LI_INTB | LI_INTC | LI_INTD)
+#define ALLDEVS (A01234 | BCD)
+
+static __init void lithium_init(void)
+{
+       set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
+       set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
+
+       if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
+           (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
+               printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
+/*             panic("This machine is not SGI Visual Workstation 320/540"); */
+       }
+
+       if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
+           (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
+               printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
+/*             panic("This machine is not SGI Visual Workstation 320/540"); */
+       }
+
+       li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
+       li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
+}
+
+static __init void cobalt_init(void)
+{
+       /*
+        * On normal SMP PC this is used only with SMP, but we have to
+        * use it and set it up here to start the Cobalt clock
+        */
+       set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
+       setup_local_APIC();
+       printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
+               (unsigned int)apic_read(APIC_LVR),
+               (unsigned int)apic_read(APIC_ID));
+
+       set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
+       set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
+       printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
+               co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
+
+       /* Enable Cobalt APIC being careful to NOT change the ID! */
+       co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
+
+       printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
+               co_apic_read(CO_APIC_ID));
+}
+
+int __init visws_trap_init_quirk(void)
+{
+       lithium_init();
+       cobalt_init();
+
+       return 1;
+}
+
+/*
+ * IRQ controller / APIC support:
+ */
+
+static DEFINE_SPINLOCK(cobalt_lock);
+
+/*
+ * Set the given Cobalt APIC Redirection Table entry to point
+ * to the given IDT vector/index.
+ */
+static inline void co_apic_set(int entry, int irq)
+{
+       co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
+       co_apic_write(CO_APIC_HI(entry), 0);
+}
+
+/*
+ * Cobalt (IO)-APIC functions to handle PCI devices.
+ */
+static inline int co_apic_ide0_hack(void)
+{
+       extern char visws_board_type;
+       extern char visws_board_rev;
+
+       if (visws_board_type == VISWS_320 && visws_board_rev == 5)
+               return 5;
+       return CO_APIC_IDE0;
+}
+
+static int is_co_apic(unsigned int irq)
+{
+       if (IS_CO_APIC(irq))
+               return CO_APIC(irq);
+
+       switch (irq) {
+               case 0: return CO_APIC_CPU;
+               case CO_IRQ_IDE0: return co_apic_ide0_hack();
+               case CO_IRQ_IDE1: return CO_APIC_IDE1;
+               default: return -1;
+       }
+}
+
+
+/*
+ * This is the SGI Cobalt (IO-)APIC:
+ */
+
+static void enable_cobalt_irq(unsigned int irq)
+{
+       co_apic_set(is_co_apic(irq), irq);
+}
+
+static void disable_cobalt_irq(unsigned int irq)
+{
+       int entry = is_co_apic(irq);
+
+       co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
+       co_apic_read(CO_APIC_LO(entry));
+}
+
+/*
+ * "irq" really just serves to identify the device.  Here is where we
+ * map this to the Cobalt APIC entry where it's physically wired.
+ * This is called via request_irq -> setup_irq -> irq_desc->startup()
+ */
+static unsigned int startup_cobalt_irq(unsigned int irq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&cobalt_lock, flags);
+       if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
+               irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
+       enable_cobalt_irq(irq);
+       spin_unlock_irqrestore(&cobalt_lock, flags);
+       return 0;
+}
+
+static void ack_cobalt_irq(unsigned int irq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&cobalt_lock, flags);
+       disable_cobalt_irq(irq);
+       apic_write(APIC_EOI, APIC_EIO_ACK);
+       spin_unlock_irqrestore(&cobalt_lock, flags);
+}
+
+static void end_cobalt_irq(unsigned int irq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&cobalt_lock, flags);
+       if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
+               enable_cobalt_irq(irq);
+       spin_unlock_irqrestore(&cobalt_lock, flags);
+}
+
+static struct irq_chip cobalt_irq_type = {
+       .typename =     "Cobalt-APIC",
+       .startup =      startup_cobalt_irq,
+       .shutdown =     disable_cobalt_irq,
+       .enable =       enable_cobalt_irq,
+       .disable =      disable_cobalt_irq,
+       .ack =          ack_cobalt_irq,
+       .end =          end_cobalt_irq,
+};
+
+
+/*
+ * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
+ * -- not the manner expected by the code in i8259.c.
+ *
+ * there is a 'master' physical interrupt source that gets sent to
+ * the CPU. But in the chipset there are various 'virtual' interrupts
+ * waiting to be handled. We represent this to Linux through a 'master'
+ * interrupt controller type, and through a special virtual interrupt-
+ * controller. Device drivers only see the virtual interrupt sources.
+ */
+static unsigned int startup_piix4_master_irq(unsigned int irq)
+{
+       init_8259A(0);
+
+       return startup_cobalt_irq(irq);
+}
+
+static void end_piix4_master_irq(unsigned int irq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&cobalt_lock, flags);
+       enable_cobalt_irq(irq);
+       spin_unlock_irqrestore(&cobalt_lock, flags);
+}
+
+static struct irq_chip piix4_master_irq_type = {
+       .typename =     "PIIX4-master",
+       .startup =      startup_piix4_master_irq,
+       .ack =          ack_cobalt_irq,
+       .end =          end_piix4_master_irq,
+};
+
+
+static struct irq_chip piix4_virtual_irq_type = {
+       .typename =     "PIIX4-virtual",
+       .shutdown =     disable_8259A_irq,
+       .enable =       enable_8259A_irq,
+       .disable =      disable_8259A_irq,
+};
+
+
+/*
+ * PIIX4-8259 master/virtual functions to handle interrupt requests
+ * from legacy devices: floppy, parallel, serial, rtc.
+ *
+ * None of these get Cobalt APIC entries, neither do they have IDT
+ * entries. These interrupts are purely virtual and distributed from
+ * the 'master' interrupt source: CO_IRQ_8259.
+ *
+ * When the 8259 interrupts its handler figures out which of these
+ * devices is interrupting and dispatches to its handler.
+ *
+ * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
+ * enable_irq gets the right irq. This 'master' irq is never directly
+ * manipulated by any driver.
+ */
+static irqreturn_t piix4_master_intr(int irq, void *dev_id)
+{
+       int realirq;
+       irq_desc_t *desc;
+       unsigned long flags;
+
+       spin_lock_irqsave(&i8259A_lock, flags);
+
+       /* Find out what's interrupting in the PIIX4 master 8259 */
+       outb(0x0c, 0x20);               /* OCW3 Poll command */
+       realirq = inb(0x20);
+
+       /*
+        * Bit 7 == 0 means invalid/spurious
+        */
+       if (unlikely(!(realirq & 0x80)))
+               goto out_unlock;
+
+       realirq &= 7;
+
+       if (unlikely(realirq == 2)) {
+               outb(0x0c, 0xa0);
+               realirq = inb(0xa0);
+
+               if (unlikely(!(realirq & 0x80)))
+                       goto out_unlock;
+
+               realirq = (realirq & 7) + 8;
+       }
+
+       /* mask and ack interrupt */
+       cached_irq_mask |= 1 << realirq;
+       if (unlikely(realirq > 7)) {
+               inb(0xa1);
+               outb(cached_slave_mask, 0xa1);
+               outb(0x60 + (realirq & 7), 0xa0);
+               outb(0x60 + 2, 0x20);
+       } else {
+               inb(0x21);
+               outb(cached_master_mask, 0x21);
+               outb(0x60 + realirq, 0x20);
+       }
+
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+
+       desc = irq_desc + realirq;
+
+       /*
+        * handle this 'virtual interrupt' as a Cobalt one now.
+        */
+       kstat_cpu(smp_processor_id()).irqs[realirq]++;
+
+       if (likely(desc->action != NULL))
+               handle_IRQ_event(realirq, desc->action);
+
+       if (!(desc->status & IRQ_DISABLED))
+               enable_8259A_irq(realirq);
+
+       return IRQ_HANDLED;
+
+out_unlock:
+       spin_unlock_irqrestore(&i8259A_lock, flags);
+       return IRQ_NONE;
+}
+
+static struct irqaction master_action = {
+       .handler =      piix4_master_intr,
+       .name =         "PIIX4-8259",
+};
+
+static struct irqaction cascade_action = {
+       .handler =      no_action,
+       .name =         "cascade",
+};
+
+
+void init_VISWS_APIC_irqs(void)
+{
+       int i;
+
+       for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
+               irq_desc[i].status = IRQ_DISABLED;
+               irq_desc[i].action = 0;
+               irq_desc[i].depth = 1;
+
+               if (i == 0) {
+                       irq_desc[i].chip = &cobalt_irq_type;
+               }
+               else if (i == CO_IRQ_IDE0) {
+                       irq_desc[i].chip = &cobalt_irq_type;
+               }
+               else if (i == CO_IRQ_IDE1) {
+                       irq_desc[i].chip = &cobalt_irq_type;
+               }
+               else if (i == CO_IRQ_8259) {
+                       irq_desc[i].chip = &piix4_master_irq_type;
+               }
+               else if (i < CO_IRQ_APIC0) {
+                       irq_desc[i].chip = &piix4_virtual_irq_type;
+               }
+               else if (IS_CO_APIC(i)) {
+                       irq_desc[i].chip = &cobalt_irq_type;
+               }
+       }
+
+       setup_irq(CO_IRQ_8259, &master_action);
+       setup_irq(2, &cascade_action);
+}
index 956f389..b153460 100644 (file)
@@ -151,7 +151,7 @@ static unsigned vmi_patch(u8 type, u16 clobbers, void *insns,
                                              insns, ip);
                case PARAVIRT_PATCH(pv_cpu_ops.iret):
                        return patch_internal(VMI_CALL_IRET, len, insns, ip);
-               case PARAVIRT_PATCH(pv_cpu_ops.irq_enable_syscall_ret):
+               case PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit):
                        return patch_internal(VMI_CALL_SYSEXIT, len, insns, ip);
                default:
                        break;
@@ -896,7 +896,7 @@ static inline int __init activate_vmi(void)
         * the backend.  They are performance critical anyway, so requiring
         * a patch is not a big problem.
         */
-       pv_cpu_ops.irq_enable_syscall_ret = (void *)0xfeedbab0;
+       pv_cpu_ops.irq_enable_sysexit = (void *)0xfeedbab0;
        pv_cpu_ops.iret = (void *)0xbadbab0;
 
 #ifdef CONFIG_SMP
@@ -932,7 +932,7 @@ static inline int __init activate_vmi(void)
                pv_apic_ops.setup_secondary_clock = vmi_time_ap_init;
 #endif
                pv_time_ops.sched_clock = vmi_sched_clock;
-               pv_time_ops.get_cpu_khz = vmi_cpu_khz;
+               pv_time_ops.get_tsc_khz = vmi_tsc_khz;
 
                /* We have true wallclock functions; disable CMOS clock sync */
                no_sync_cmos_clock = 1;
index a2b0307..6953859 100644 (file)
@@ -33,8 +33,7 @@
 #include <asm/apic.h>
 #include <asm/timer.h>
 #include <asm/i8253.h>
-
-#include <irq_vectors.h>
+#include <asm/irq_vectors.h>
 
 #define VMI_ONESHOT  (VMI_ALARM_IS_ONESHOT  | VMI_CYCLES_REAL | vmi_get_alarm_wiring())
 #define VMI_PERIODIC (VMI_ALARM_IS_PERIODIC | VMI_CYCLES_REAL | vmi_get_alarm_wiring())
@@ -70,8 +69,8 @@ unsigned long long vmi_sched_clock(void)
        return cycles_2_ns(vmi_timer_ops.get_cycle_counter(VMI_CYCLES_AVAILABLE));
 }
 
-/* paravirt_ops.get_cpu_khz = vmi_cpu_khz */
-unsigned long vmi_cpu_khz(void)
+/* paravirt_ops.get_tsc_khz = vmi_tsc_khz */
+unsigned long vmi_tsc_khz(void)
 {
        unsigned long long khz;
        khz = vmi_timer_ops.get_cycle_frequency();
index ce5ed08..cdb2363 100644 (file)
@@ -49,23 +49,14 @@ SECTIONS
        _etext = .;                     /* End of text section */
   } :text = 0x9090
 
+  NOTES :text :note
+
   . = ALIGN(16);               /* Exception table */
   __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
        __start___ex_table = .;
         *(__ex_table)
        __stop___ex_table = .;
-  }
-
-  NOTES :text :note
-
-  BUG_TABLE :text
-
-  . = ALIGN(4);
-  .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {
-       __tracedata_start = .;
-       *(.tracedata)
-       __tracedata_end = .;
-  }
+  } :text = 0x9090
 
   RODATA
 
index fad3674..63e5c1a 100644 (file)
@@ -19,7 +19,7 @@ PHDRS {
        data PT_LOAD FLAGS(7);  /* RWE */
        user PT_LOAD FLAGS(7);  /* RWE */
        data.init PT_LOAD FLAGS(7);     /* RWE */
-       note PT_NOTE FLAGS(4);  /* R__ */
+       note PT_NOTE FLAGS(0);  /* ___ */
 }
 SECTIONS
 {
@@ -40,26 +40,17 @@ SECTIONS
        _etext = .;             /* End of text section */
   } :text = 0x9090
 
+  NOTES :text :note
+
   . = ALIGN(16);               /* Exception table */
   __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
        __start___ex_table = .;
         *(__ex_table)
        __stop___ex_table = .;
-  }
-
-  NOTES :text :note
-
-  BUG_TABLE :text
+  } :text = 0x9090
 
   RODATA
 
-  . = ALIGN(4);
-  .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {
-       __tracedata_start = .;
-       *(.tracedata)
-       __tracedata_end = .;
-  }
-
   . = ALIGN(PAGE_SIZE);                /* Align data segment to page size boundary */
                                /* Data */
   .data : AT(ADDR(.data) - LOAD_OFFSET) {
@@ -177,6 +168,7 @@ SECTIONS
        *(.con_initcall.init)
   }
   __con_initcall_end = .;
+  . = ALIGN(16);
   __x86cpuvendor_start = .;
   .x86cpuvendor.init : AT(ADDR(.x86cpuvendor.init) - LOAD_OFFSET) {
        *(.x86cpuvendor.init)
index ba8c0b7..0c029e8 100644 (file)
 #include <linux/init.h>
 #include <linux/pci_ids.h>
 #include <linux/pci_regs.h>
+
+#include <asm/apic.h>
 #include <asm/pci-direct.h>
 #include <asm/io.h>
 #include <asm/paravirt.h>
+#include <asm/setup.h>
 
 #if defined CONFIG_PCI && defined CONFIG_PARAVIRT
 /*
index 61efa2f..e50740d 100644 (file)
@@ -42,7 +42,8 @@
 #include <asm/topology.h>
 #include <asm/vgtod.h>
 
-#define __vsyscall(nr) __attribute__ ((unused,__section__(".vsyscall_" #nr)))
+#define __vsyscall(nr) \
+               __attribute__ ((unused, __section__(".vsyscall_" #nr))) notrace
 #define __syscall_clobber "r11","cx","memory"
 
 /*
@@ -249,7 +250,7 @@ static ctl_table kernel_root_table2[] = {
    doesn't violate that. We'll find out if it does. */
 static void __cpuinit vsyscall_set_cpu(int cpu)
 {
-       unsigned long *d;
+       unsigned long d;
        unsigned long node = 0;
 #ifdef CONFIG_NUMA
        node = cpu_to_node(cpu);
@@ -260,11 +261,11 @@ static void __cpuinit vsyscall_set_cpu(int cpu)
        /* Store cpu number in limit so that it can be loaded quickly
           in user space in vgetcpu.
           12 bits for the CPU and 8 bits for the node. */
-       d = (unsigned long *)(get_cpu_gdt_table(cpu) + GDT_ENTRY_PER_CPU);
-       *d = 0x0f40000000000ULL;
-       *d |= cpu;
-       *d |= (node & 0xf) << 12;
-       *d |= (node >> 4) << 48;
+       d = 0x0f40000000000ULL;
+       d |= cpu;
+       d |= (node & 0xf) << 12;
+       d |= (node >> 4) << 48;
+       write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_PER_CPU, &d, DESCTYPE_S);
 }
 
 static void __cpuinit cpu_vsyscall_init(void *arg)
index f6c05d0..b545f37 100644 (file)
@@ -2,13 +2,20 @@
    All C exports should go in the respective C files. */
 
 #include <linux/module.h>
-#include <net/checksum.h>
 #include <linux/smp.h>
 
+#include <net/checksum.h>
+
 #include <asm/processor.h>
-#include <asm/uaccess.h>
 #include <asm/pgtable.h>
+#include <asm/uaccess.h>
 #include <asm/desc.h>
+#include <asm/ftrace.h>
+
+#ifdef CONFIG_FTRACE
+/* mcount is defined in assembly */
+EXPORT_SYMBOL(mcount);
+#endif
 
 EXPORT_SYMBOL(kernel_thread);
 
@@ -53,8 +60,3 @@ EXPORT_SYMBOL(init_level4_pgt);
 EXPORT_SYMBOL(load_gs_index);
 
 EXPORT_SYMBOL(_proxy_pda);
-
-#ifdef CONFIG_PARAVIRT
-/* Virtualized guests may want to use it */
-EXPORT_SYMBOL_GPL(cpu_gdt_descr);
-#endif
index 964dfa3..c70e12b 100644 (file)
@@ -3,7 +3,7 @@ config LGUEST_GUEST
        select PARAVIRT
        depends on X86_32
        depends on !X86_PAE
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        select VIRTIO
        select VIRTIO_RING
        select VIRTIO_CONSOLE
index 5c7e2fd..50dad44 100644 (file)
@@ -607,7 +607,7 @@ static unsigned long lguest_get_wallclock(void)
  * what speed it runs at, or 0 if it's unusable as a reliable clock source.
  * This matches what we want here: if we return 0 from this function, the x86
  * TSC clock will give up and not register itself. */
-static unsigned long lguest_cpu_khz(void)
+static unsigned long lguest_tsc_khz(void)
 {
        return lguest_data.tsc_khz;
 }
@@ -835,7 +835,7 @@ static __init char *lguest_memory_setup(void)
 
        /* The Linux bootloader header contains an "e820" memory map: the
         * Launcher populated the first entry with our memory limit. */
-       add_memory_region(boot_params.e820_map[0].addr,
+       e820_add_region(boot_params.e820_map[0].addr,
                          boot_params.e820_map[0].size,
                          boot_params.e820_map[0].type);
 
@@ -998,7 +998,7 @@ __init void lguest_init(void)
        /* time operations */
        pv_time_ops.get_wallclock = lguest_get_wallclock;
        pv_time_ops.time_init = lguest_time_init;
-       pv_time_ops.get_cpu_khz = lguest_cpu_khz;
+       pv_time_ops.get_tsc_khz = lguest_tsc_khz;
 
        /* Now is a good time to look at the implementations of these functions
         * before returning to the rest of lguest_init(). */
@@ -1012,6 +1012,7 @@ __init void lguest_init(void)
         * clobbered.  The Launcher places our initial pagetables somewhere at
         * the top of our physical memory, so we don't need extra space: set
         * init_pg_tables_end to the end of the kernel. */
+       init_pg_tables_start = __pa(pg0);
        init_pg_tables_end = __pa(pg0);
 
        /* Load the %fs segment register (the per-cpu segment register) with
@@ -1065,9 +1066,9 @@ __init void lguest_init(void)
        pm_power_off = lguest_power_off;
        machine_ops.restart = lguest_restart;
 
-       /* Now we're set up, call start_kernel() in init/main.c and we proceed
+       /* Now we're set up, call i386_start_kernel() in head32.c and we proceed
         * to boot as normal.  It never returns. */
-       start_kernel();
+       i386_start_kernel();
 }
 /*
  * This marks the end of stage II of our journey, The Guest.
index 76f60f5..aa3fa41 100644 (file)
@@ -4,8 +4,9 @@
 
 obj-$(CONFIG_SMP) := msr-on-cpu.o
 
-lib-y := delay_$(BITS).o
-lib-y += usercopy_$(BITS).o getuser_$(BITS).o putuser_$(BITS).o
+lib-y := delay.o
+lib-y += thunk_$(BITS).o
+lib-y += usercopy_$(BITS).o getuser.o putuser.o
 lib-y += memcpy_$(BITS).o
 
 ifeq ($(CONFIG_X86_32),y)
index ee1c3f6..dfdf428 100644 (file)
@@ -1,8 +1,10 @@
-/* Copyright 2002 Andi Kleen, SuSE Labs.
+/*
+ * Copyright 2008 Vitaly Mayatskikh <vmayatsk@redhat.com>
+ * Copyright 2002 Andi Kleen, SuSE Labs.
  * Subject to the GNU Public License v2.
- * 
- * Functions to copy from and to user space.           
- */             
+ *
+ * Functions to copy from and to user space.
+ */
 
 #include <linux/linkage.h>
 #include <asm/dwarf2.h>
        .long \orig-1f  /* by default jump to orig */
 1:
        .section .altinstr_replacement,"ax"
-2:     .byte 0xe9                   /* near jump with 32bit immediate */
+2:     .byte 0xe9                      /* near jump with 32bit immediate */
        .long \alt-1b /* offset */   /* or alternatively to alt */
        .previous
        .section .altinstructions,"a"
        .align 8
        .quad  0b
        .quad  2b
-       .byte  \feature              /* when feature is set */
+       .byte  \feature                 /* when feature is set */
        .byte  5
        .byte  5
        .previous
        .endm
 
-/* Standard copy_to_user with segment limit checking */                
+       .macro ALIGN_DESTINATION
+#ifdef FIX_ALIGNMENT
+       /* check for bad alignment of destination */
+       movl %edi,%ecx
+       andl $7,%ecx
+       jz 102f                         /* already aligned */
+       subl $8,%ecx
+       negl %ecx
+       subl %ecx,%edx
+100:   movb (%rsi),%al
+101:   movb %al,(%rdi)
+       incq %rsi
+       incq %rdi
+       decl %ecx
+       jnz 100b
+102:
+       .section .fixup,"ax"
+103:   addl %r8d,%edx                  /* ecx is zerorest also */
+       jmp copy_user_handle_tail
+       .previous
+
+       .section __ex_table,"a"
+       .align 8
+       .quad 100b,103b
+       .quad 101b,103b
+       .previous
+#endif
+       .endm
+
+/* Standard copy_to_user with segment limit checking */
 ENTRY(copy_to_user)
        CFI_STARTPROC
        GET_THREAD_INFO(%rax)
        movq %rdi,%rcx
        addq %rdx,%rcx
-       jc  bad_to_user
-       cmpq threadinfo_addr_limit(%rax),%rcx
+       jc bad_to_user
+       cmpq TI_addr_limit(%rax),%rcx
        jae bad_to_user
-       xorl %eax,%eax  /* clear zero flag */
        ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
        CFI_ENDPROC
 
-ENTRY(copy_user_generic)
+/* Standard copy_from_user with segment limit checking */
+ENTRY(copy_from_user)
        CFI_STARTPROC
-       movl $1,%ecx    /* set zero flag */
+       GET_THREAD_INFO(%rax)
+       movq %rsi,%rcx
+       addq %rdx,%rcx
+       jc bad_from_user
+       cmpq TI_addr_limit(%rax),%rcx
+       jae bad_from_user
        ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
        CFI_ENDPROC
+ENDPROC(copy_from_user)
 
-ENTRY(__copy_from_user_inatomic)
+ENTRY(copy_user_generic)
        CFI_STARTPROC
-       xorl %ecx,%ecx  /* clear zero flag */
        ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
        CFI_ENDPROC
+ENDPROC(copy_user_generic)
 
-/* Standard copy_from_user with segment limit checking */      
-ENTRY(copy_from_user)
+ENTRY(__copy_from_user_inatomic)
        CFI_STARTPROC
-       GET_THREAD_INFO(%rax)
-       movq %rsi,%rcx
-       addq %rdx,%rcx
-       jc  bad_from_user
-       cmpq threadinfo_addr_limit(%rax),%rcx
-       jae  bad_from_user
-       movl $1,%ecx    /* set zero flag */
        ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
        CFI_ENDPROC
-ENDPROC(copy_from_user)
-       
+ENDPROC(__copy_from_user_inatomic)
+
        .section .fixup,"ax"
        /* must zero dest */
+ENTRY(bad_from_user)
 bad_from_user:
        CFI_STARTPROC
        movl %edx,%ecx
@@ -81,271 +111,158 @@ bad_from_user:
        rep
        stosb
 bad_to_user:
-       movl    %edx,%eax
+       movl %edx,%eax
        ret
        CFI_ENDPROC
-END(bad_from_user)
+ENDPROC(bad_from_user)
        .previous
-       
-               
+
 /*
  * copy_user_generic_unrolled - memory copy with exception handling.
- * This version is for CPUs like P4 that don't have efficient micro code for rep movsq
- *     
- * Input:      
+ * This version is for CPUs like P4 that don't have efficient micro
+ * code for rep movsq
+ *
+ * Input:
  * rdi destination
  * rsi source
  * rdx count
- * ecx zero flag -- if true zero destination on error
  *
- * Output:             
- * eax uncopied bytes or 0 if successful.
+ * Output:
+ * eax uncopied bytes or 0 if successfull.
  */
 ENTRY(copy_user_generic_unrolled)
        CFI_STARTPROC
-       pushq %rbx
-       CFI_ADJUST_CFA_OFFSET 8
-       CFI_REL_OFFSET rbx, 0
-       pushq %rcx
-       CFI_ADJUST_CFA_OFFSET 8
-       CFI_REL_OFFSET rcx, 0
-       xorl %eax,%eax          /*zero for the exception handler */
-
-#ifdef FIX_ALIGNMENT
-       /* check for bad alignment of destination */
-       movl %edi,%ecx
-       andl $7,%ecx
-       jnz  .Lbad_alignment
-.Lafter_bad_alignment:
-#endif
-
-       movq %rdx,%rcx
-
-       movl $64,%ebx
-       shrq $6,%rdx
-       decq %rdx
-       js   .Lhandle_tail
-
-       .p2align 4
-.Lloop:
-.Ls1:  movq (%rsi),%r11
-.Ls2:  movq 1*8(%rsi),%r8
-.Ls3:  movq 2*8(%rsi),%r9
-.Ls4:  movq 3*8(%rsi),%r10
-.Ld1:  movq %r11,(%rdi)
-.Ld2:  movq %r8,1*8(%rdi)
-.Ld3:  movq %r9,2*8(%rdi)
-.Ld4:  movq %r10,3*8(%rdi)
-
-.Ls5:  movq 4*8(%rsi),%r11
-.Ls6:  movq 5*8(%rsi),%r8
-.Ls7:  movq 6*8(%rsi),%r9
-.Ls8:  movq 7*8(%rsi),%r10
-.Ld5:  movq %r11,4*8(%rdi)
-.Ld6:  movq %r8,5*8(%rdi)
-.Ld7:  movq %r9,6*8(%rdi)
-.Ld8:  movq %r10,7*8(%rdi)
-
-       decq %rdx
-
+       cmpl $8,%edx
+       jb 20f          /* less then 8 bytes, go to byte copy loop */
+       ALIGN_DESTINATION
+       movl %edx,%ecx
+       andl $63,%edx
+       shrl $6,%ecx
+       jz 17f
+1:     movq (%rsi),%r8
+2:     movq 1*8(%rsi),%r9
+3:     movq 2*8(%rsi),%r10
+4:     movq 3*8(%rsi),%r11
+5:     movq %r8,(%rdi)
+6:     movq %r9,1*8(%rdi)
+7:     movq %r10,2*8(%rdi)
+8:     movq %r11,3*8(%rdi)
+9:     movq 4*8(%rsi),%r8
+10:    movq 5*8(%rsi),%r9
+11:    movq 6*8(%rsi),%r10
+12:    movq 7*8(%rsi),%r11
+13:    movq %r8,4*8(%rdi)
+14:    movq %r9,5*8(%rdi)
+15:    movq %r10,6*8(%rdi)
+16:    movq %r11,7*8(%rdi)
        leaq 64(%rsi),%rsi
        leaq 64(%rdi),%rdi
-
-       jns  .Lloop
-
-       .p2align 4
-.Lhandle_tail:
-       movl %ecx,%edx
-       andl $63,%ecx
-       shrl $3,%ecx
-       jz   .Lhandle_7
-       movl $8,%ebx
-       .p2align 4
-.Lloop_8:
-.Ls9:  movq (%rsi),%r8
-.Ld9:  movq %r8,(%rdi)
        decl %ecx
-       leaq 8(%rdi),%rdi
+       jnz 1b
+17:    movl %edx,%ecx
+       andl $7,%edx
+       shrl $3,%ecx
+       jz 20f
+18:    movq (%rsi),%r8
+19:    movq %r8,(%rdi)
        leaq 8(%rsi),%rsi
-       jnz .Lloop_8
-
-.Lhandle_7:
+       leaq 8(%rdi),%rdi
+       decl %ecx
+       jnz 18b
+20:    andl %edx,%edx
+       jz 23f
        movl %edx,%ecx
-       andl $7,%ecx
-       jz   .Lende
-       .p2align 4
-.Lloop_1:
-.Ls10: movb (%rsi),%bl
-.Ld10: movb %bl,(%rdi)
-       incq %rdi
+21:    movb (%rsi),%al
+22:    movb %al,(%rdi)
        incq %rsi
+       incq %rdi
        decl %ecx
-       jnz .Lloop_1
-
-       CFI_REMEMBER_STATE
-.Lende:
-       popq %rcx
-       CFI_ADJUST_CFA_OFFSET -8
-       CFI_RESTORE rcx
-       popq %rbx
-       CFI_ADJUST_CFA_OFFSET -8
-       CFI_RESTORE rbx
+       jnz 21b
+23:    xor %eax,%eax
        ret
-       CFI_RESTORE_STATE
 
-#ifdef FIX_ALIGNMENT
-       /* align destination */
-       .p2align 4
-.Lbad_alignment:
-       movl $8,%r9d
-       subl %ecx,%r9d
-       movl %r9d,%ecx
-       cmpq %r9,%rdx
-       jz   .Lhandle_7
-       js   .Lhandle_7
-.Lalign_1:
-.Ls11: movb (%rsi),%bl
-.Ld11: movb %bl,(%rdi)
-       incq %rsi
-       incq %rdi
-       decl %ecx
-       jnz .Lalign_1
-       subq %r9,%rdx
-       jmp .Lafter_bad_alignment
-#endif
+       .section .fixup,"ax"
+30:    shll $6,%ecx
+       addl %ecx,%edx
+       jmp 60f
+40:    lea (%rdx,%rcx,8),%rdx
+       jmp 60f
+50:    movl %ecx,%edx
+60:    jmp copy_user_handle_tail /* ecx is zerorest also */
+       .previous
 
-       /* table sorted by exception address */
        .section __ex_table,"a"
        .align 8
-       .quad .Ls1,.Ls1e        /* Ls1-Ls4 have copied zero bytes */
-       .quad .Ls2,.Ls1e
-       .quad .Ls3,.Ls1e
-       .quad .Ls4,.Ls1e
-       .quad .Ld1,.Ls1e        /* Ld1-Ld4 have copied 0-24 bytes */
-       .quad .Ld2,.Ls2e
-       .quad .Ld3,.Ls3e
-       .quad .Ld4,.Ls4e
-       .quad .Ls5,.Ls5e        /* Ls5-Ls8 have copied 32 bytes */
-       .quad .Ls6,.Ls5e
-       .quad .Ls7,.Ls5e
-       .quad .Ls8,.Ls5e
-       .quad .Ld5,.Ls5e        /* Ld5-Ld8 have copied 32-56 bytes */
-       .quad .Ld6,.Ls6e
-       .quad .Ld7,.Ls7e
-       .quad .Ld8,.Ls8e
-       .quad .Ls9,.Le_quad
-       .quad .Ld9,.Le_quad
-       .quad .Ls10,.Le_byte
-       .quad .Ld10,.Le_byte
-#ifdef FIX_ALIGNMENT
-       .quad .Ls11,.Lzero_rest
-       .quad .Ld11,.Lzero_rest
-#endif
-       .quad .Le5,.Le_zero
+       .quad 1b,30b
+       .quad 2b,30b
+       .quad 3b,30b
+       .quad 4b,30b
+       .quad 5b,30b
+       .quad 6b,30b
+       .quad 7b,30b
+       .quad 8b,30b
+       .quad 9b,30b
+       .quad 10b,30b
+       .quad 11b,30b
+       .quad 12b,30b
+       .quad 13b,30b
+       .quad 14b,30b
+       .quad 15b,30b
+       .quad 16b,30b
+       .quad 18b,40b
+       .quad 19b,40b
+       .quad 21b,50b
+       .quad 22b,50b
        .previous
-
-       /* eax: zero, ebx: 64 */
-.Ls1e:         addl $8,%eax            /* eax is bytes left uncopied within the loop (Ls1e: 64 .. Ls8e: 8) */
-.Ls2e:         addl $8,%eax
-.Ls3e:         addl $8,%eax
-.Ls4e:         addl $8,%eax
-.Ls5e:         addl $8,%eax
-.Ls6e:         addl $8,%eax
-.Ls7e:         addl $8,%eax
-.Ls8e:         addl $8,%eax
-       addq %rbx,%rdi  /* +64 */
-       subq %rax,%rdi  /* correct destination with computed offset */
-
-       shlq $6,%rdx    /* loop counter * 64 (stride length) */
-       addq %rax,%rdx  /* add offset to loopcnt */
-       andl $63,%ecx   /* remaining bytes */
-       addq %rcx,%rdx  /* add them */
-       jmp .Lzero_rest
-
-       /* exception on quad word loop in tail handling */
-       /* ecx: loopcnt/8, %edx: length, rdi: correct */
-.Le_quad:
-       shll $3,%ecx
-       andl $7,%edx
-       addl %ecx,%edx
-       /* edx: bytes to zero, rdi: dest, eax:zero */
-.Lzero_rest:
-       cmpl $0,(%rsp)
-       jz   .Le_zero
-       movq %rdx,%rcx
-.Le_byte:
-       xorl %eax,%eax
-.Le5:  rep
-       stosb
-       /* when there is another exception while zeroing the rest just return */
-.Le_zero:
-       movq %rdx,%rax
-       jmp .Lende
        CFI_ENDPROC
-ENDPROC(copy_user_generic)
+ENDPROC(copy_user_generic_unrolled)
 
-
-       /* Some CPUs run faster using the string copy instructions.
-          This is also a lot simpler. Use them when possible.
-          Patch in jmps to this code instead of copying it fully
-          to avoid unwanted aliasing in the exception tables. */
-
- /* rdi        destination
-  * rsi source
-  * rdx count
-  * ecx zero flag
-  *
-  * Output:
-  * eax uncopied bytes or 0 if successfull.
-  *
-  * Only 4GB of copy is supported. This shouldn't be a problem
-  * because the kernel normally only writes from/to page sized chunks
-  * even if user space passed a longer buffer.
-  * And more would be dangerous because both Intel and AMD have
-  * errata with rep movsq > 4GB. If someone feels the need to fix
-  * this please consider this.
-  */
+/* Some CPUs run faster using the string copy instructions.
+ * This is also a lot simpler. Use them when possible.
+ *
+ * Only 4GB of copy is supported. This shouldn't be a problem
+ * because the kernel normally only writes from/to page sized chunks
+ * even if user space passed a longer buffer.
+ * And more would be dangerous because both Intel and AMD have
+ * errata with rep movsq > 4GB. If someone feels the need to fix
+ * this please consider this.
+ *
+ * Input:
+ * rdi destination
+ * rsi source
+ * rdx count
+ *
+ * Output:
+ * eax uncopied bytes or 0 if successful.
+ */
 ENTRY(copy_user_generic_string)
        CFI_STARTPROC
-       movl %ecx,%r8d          /* save zero flag */
+       andl %edx,%edx
+       jz 4f
+       cmpl $8,%edx
+       jb 2f           /* less than 8 bytes, go to byte copy loop */
+       ALIGN_DESTINATION
        movl %edx,%ecx
        shrl $3,%ecx
-       andl $7,%edx    
-       jz   10f
-1:     rep 
-       movsq 
-       movl %edx,%ecx
-2:     rep
-       movsb
-9:     movl %ecx,%eax
-       ret
-
-       /* multiple of 8 byte */
-10:    rep
+       andl $7,%edx
+1:     rep
        movsq
-       xor %eax,%eax
+2:     movl %edx,%ecx
+3:     rep
+       movsb
+4:     xorl %eax,%eax
        ret
 
-       /* exception handling */
-3:      lea (%rdx,%rcx,8),%rax /* exception on quad loop */
-       jmp 6f
-5:     movl %ecx,%eax          /* exception on byte loop */
-       /* eax: left over bytes */
-6:     testl %r8d,%r8d         /* zero flag set? */
-       jz 7f
-       movl %eax,%ecx          /* initialize x86 loop counter */
-       push %rax
-       xorl %eax,%eax
-8:     rep
-       stosb                   /* zero the rest */
-11:    pop %rax
-7:     ret
-       CFI_ENDPROC
-END(copy_user_generic_c)
+       .section .fixup,"ax"
+11:    lea (%rdx,%rcx,8),%rcx
+12:    movl %ecx,%edx          /* ecx is zerorest also */
+       jmp copy_user_handle_tail
+       .previous
 
        .section __ex_table,"a"
-       .quad 1b,3b
-       .quad 2b,5b
-       .quad 8b,11b
-       .quad 10b,3b
+       .align 8
+       .quad 1b,11b
+       .quad 3b,12b
        .previous
+       CFI_ENDPROC
+ENDPROC(copy_user_generic_string)
index 9d3d1ab..40e0e30 100644 (file)
@@ -1,4 +1,6 @@
-/* Copyright 2002 Andi Kleen, SuSE Labs.
+/*
+ * Copyright 2008 Vitaly Mayatskikh <vmayatsk@redhat.com>
+ * Copyright 2002 Andi Kleen, SuSE Labs.
  * Subject to the GNU Public License v2.
  *
  * Functions to copy from and to user space.
 #include <asm/current.h>
 #include <asm/asm-offsets.h>
 #include <asm/thread_info.h>
-#include <asm/cpufeature.h>
-
-/*
- * copy_user_nocache - Uncached memory copy with exception handling
- * This will force destination/source out of cache for more performance.
- *
- * Input:
- * rdi destination
- * rsi source
- * rdx count
- * rcx zero flag       when 1 zero on exception
- *
- * Output:
- * eax uncopied bytes or 0 if successful.
- */
-ENTRY(__copy_user_nocache)
-       CFI_STARTPROC
-       pushq %rbx
-       CFI_ADJUST_CFA_OFFSET 8
-       CFI_REL_OFFSET rbx, 0
-       pushq %rcx              /* save zero flag */
-       CFI_ADJUST_CFA_OFFSET 8
-       CFI_REL_OFFSET rcx, 0
-
-       xorl %eax,%eax          /* zero for the exception handler */
 
+       .macro ALIGN_DESTINATION
 #ifdef FIX_ALIGNMENT
        /* check for bad alignment of destination */
        movl %edi,%ecx
        andl $7,%ecx
-       jnz  .Lbad_alignment
-.Lafter_bad_alignment:
-#endif
-
-       movq %rdx,%rcx
-
-       movl $64,%ebx
-       shrq $6,%rdx
-       decq %rdx
-       js   .Lhandle_tail
-
-       .p2align 4
-.Lloop:
-.Ls1:  movq (%rsi),%r11
-.Ls2:  movq 1*8(%rsi),%r8
-.Ls3:  movq 2*8(%rsi),%r9
-.Ls4:  movq 3*8(%rsi),%r10
-.Ld1:  movnti %r11,(%rdi)
-.Ld2:  movnti %r8,1*8(%rdi)
-.Ld3:  movnti %r9,2*8(%rdi)
-.Ld4:  movnti %r10,3*8(%rdi)
-
-.Ls5:  movq 4*8(%rsi),%r11
-.Ls6:  movq 5*8(%rsi),%r8
-.Ls7:  movq 6*8(%rsi),%r9
-.Ls8:  movq 7*8(%rsi),%r10
-.Ld5:  movnti %r11,4*8(%rdi)
-.Ld6:  movnti %r8,5*8(%rdi)
-.Ld7:  movnti %r9,6*8(%rdi)
-.Ld8:  movnti %r10,7*8(%rdi)
+       jz 102f                         /* already aligned */
+       subl $8,%ecx
+       negl %ecx
+       subl %ecx,%edx
+100:   movb (%rsi),%al
+101:   movb %al,(%rdi)
+       incq %rsi
+       incq %rdi
+       decl %ecx
+       jnz 100b
+102:
+       .section .fixup,"ax"
+103:   addl %r8d,%edx                  /* ecx is zerorest also */
+       jmp copy_user_handle_tail
+       .previous
 
-       dec  %rdx
+       .section __ex_table,"a"
+       .align 8
+       .quad 100b,103b
+       .quad 101b,103b
+       .previous
+#endif
+       .endm
 
+/*
+ * copy_user_nocache - Uncached memory copy with exception handling
+ * This will force destination/source out of cache for more performance.
+ */
+ENTRY(__copy_user_nocache)
+       CFI_STARTPROC
+       cmpl $8,%edx
+       jb 20f          /* less then 8 bytes, go to byte copy loop */
+       ALIGN_DESTINATION
+       movl %edx,%ecx
+       andl $63,%edx
+       shrl $6,%ecx
+       jz 17f
+1:     movq (%rsi),%r8
+2:     movq 1*8(%rsi),%r9
+3:     movq 2*8(%rsi),%r10
+4:     movq 3*8(%rsi),%r11
+5:     movnti %r8,(%rdi)
+6:     movnti %r9,1*8(%rdi)
+7:     movnti %r10,2*8(%rdi)
+8:     movnti %r11,3*8(%rdi)
+9:     movq 4*8(%rsi),%r8
+10:    movq 5*8(%rsi),%r9
+11:    movq 6*8(%rsi),%r10
+12:    movq 7*8(%rsi),%r11
+13:    movnti %r8,4*8(%rdi)
+14:    movnti %r9,5*8(%rdi)
+15:    movnti %r10,6*8(%rdi)
+16:    movnti %r11,7*8(%rdi)
        leaq 64(%rsi),%rsi
        leaq 64(%rdi),%rdi
-
-       jns  .Lloop
-
-       .p2align 4
-.Lhandle_tail:
-       movl %ecx,%edx
-       andl $63,%ecx
-       shrl $3,%ecx
-       jz   .Lhandle_7
-       movl $8,%ebx
-       .p2align 4
-.Lloop_8:
-.Ls9:  movq (%rsi),%r8
-.Ld9:  movnti %r8,(%rdi)
        decl %ecx
-       leaq 8(%rdi),%rdi
+       jnz 1b
+17:    movl %edx,%ecx
+       andl $7,%edx
+       shrl $3,%ecx
+       jz 20f
+18:    movq (%rsi),%r8
+19:    movnti %r8,(%rdi)
        leaq 8(%rsi),%rsi
-       jnz .Lloop_8
-
-.Lhandle_7:
+       leaq 8(%rdi),%rdi
+       decl %ecx
+       jnz 18b
+20:    andl %edx,%edx
+       jz 23f
        movl %edx,%ecx
-       andl $7,%ecx
-       jz   .Lende
-       .p2align 4
-.Lloop_1:
-.Ls10: movb (%rsi),%bl
-.Ld10: movb %bl,(%rdi)
-       incq %rdi
+21:    movb (%rsi),%al
+22:    movb %al,(%rdi)
        incq %rsi
+       incq %rdi
        decl %ecx
-       jnz .Lloop_1
-
-       CFI_REMEMBER_STATE
-.Lende:
-       popq %rcx
-       CFI_ADJUST_CFA_OFFSET -8
-       CFI_RESTORE %rcx
-       popq %rbx
-       CFI_ADJUST_CFA_OFFSET -8
-       CFI_RESTORE rbx
+       jnz 21b
+23:    xorl %eax,%eax
        sfence
        ret
-       CFI_RESTORE_STATE
 
-#ifdef FIX_ALIGNMENT
-       /* align destination */
-       .p2align 4
-.Lbad_alignment:
-       movl $8,%r9d
-       subl %ecx,%r9d
-       movl %r9d,%ecx
-       cmpq %r9,%rdx
-       jz   .Lhandle_7
-       js   .Lhandle_7
-.Lalign_1:
-.Ls11: movb (%rsi),%bl
-.Ld11: movb %bl,(%rdi)
-       incq %rsi
-       incq %rdi
-       decl %ecx
-       jnz .Lalign_1
-       subq %r9,%rdx
-       jmp .Lafter_bad_alignment
-#endif
+       .section .fixup,"ax"
+30:    shll $6,%ecx
+       addl %ecx,%edx
+       jmp 60f
+40:    lea (%rdx,%rcx,8),%rdx
+       jmp 60f
+50:    movl %ecx,%edx
+60:    sfence
+       movl %r8d,%ecx
+       jmp copy_user_handle_tail
+       .previous
 
-       /* table sorted by exception address */
        .section __ex_table,"a"
-       .align 8
-       .quad .Ls1,.Ls1e        /* .Ls[1-4] - 0 bytes copied */
-       .quad .Ls2,.Ls1e
-       .quad .Ls3,.Ls1e
-       .quad .Ls4,.Ls1e
-       .quad .Ld1,.Ls1e        /* .Ld[1-4] - 0..24 bytes coped */
-       .quad .Ld2,.Ls2e
-       .quad .Ld3,.Ls3e
-       .quad .Ld4,.Ls4e
-       .quad .Ls5,.Ls5e        /* .Ls[5-8] - 32 bytes copied */
-       .quad .Ls6,.Ls5e
-       .quad .Ls7,.Ls5e
-       .quad .Ls8,.Ls5e
-       .quad .Ld5,.Ls5e        /* .Ld[5-8] - 32..56 bytes copied */
-       .quad .Ld6,.Ls6e
-       .quad .Ld7,.Ls7e
-       .quad .Ld8,.Ls8e
-       .quad .Ls9,.Le_quad
-       .quad .Ld9,.Le_quad
-       .quad .Ls10,.Le_byte
-       .quad .Ld10,.Le_byte
-#ifdef FIX_ALIGNMENT
-       .quad .Ls11,.Lzero_rest
-       .quad .Ld11,.Lzero_rest
-#endif
-       .quad .Le5,.Le_zero
+       .quad 1b,30b
+       .quad 2b,30b
+       .quad 3b,30b
+       .quad 4b,30b
+       .quad 5b,30b
+       .quad 6b,30b
+       .quad 7b,30b
+       .quad 8b,30b
+       .quad 9b,30b
+       .quad 10b,30b
+       .quad 11b,30b
+       .quad 12b,30b
+       .quad 13b,30b
+       .quad 14b,30b
+       .quad 15b,30b
+       .quad 16b,30b
+       .quad 18b,40b
+       .quad 19b,40b
+       .quad 21b,50b
+       .quad 22b,50b
        .previous
-
-       /* eax: zero, ebx: 64 */
-.Ls1e:         addl $8,%eax    /* eax: bytes left uncopied: Ls1e: 64 .. Ls8e: 8 */
-.Ls2e:         addl $8,%eax
-.Ls3e:         addl $8,%eax
-.Ls4e:         addl $8,%eax
-.Ls5e:         addl $8,%eax
-.Ls6e:         addl $8,%eax
-.Ls7e:         addl $8,%eax
-.Ls8e:         addl $8,%eax
-       addq %rbx,%rdi  /* +64 */
-       subq %rax,%rdi  /* correct destination with computed offset */
-
-       shlq $6,%rdx    /* loop counter * 64 (stride length) */
-       addq %rax,%rdx  /* add offset to loopcnt */
-       andl $63,%ecx   /* remaining bytes */
-       addq %rcx,%rdx  /* add them */
-       jmp .Lzero_rest
-
-       /* exception on quad word loop in tail handling */
-       /* ecx: loopcnt/8, %edx: length, rdi: correct */
-.Le_quad:
-       shll $3,%ecx
-       andl $7,%edx
-       addl %ecx,%edx
-       /* edx: bytes to zero, rdi: dest, eax:zero */
-.Lzero_rest:
-       cmpl $0,(%rsp)  /* zero flag set? */
-       jz   .Le_zero
-       movq %rdx,%rcx
-.Le_byte:
-       xorl %eax,%eax
-.Le5:  rep
-       stosb
-       /* when there is another exception while zeroing the rest just return */
-.Le_zero:
-       movq %rdx,%rax
-       jmp .Lende
        CFI_ENDPROC
 ENDPROC(__copy_user_nocache)
-
-
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
new file mode 100644 (file)
index 0000000..f456860
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ *     Precise Delay Loops for i386
+ *
+ *     Copyright (C) 1993 Linus Torvalds
+ *     Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *     Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
+ *
+ *     The __delay function must _NOT_ be inlined as its execution time
+ *     depends wildly on alignment on many x86 processors. The additional
+ *     jump magic is needed to get the timing stable on all the CPU's
+ *     we have to worry about.
+ */
+
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/timex.h>
+#include <linux/preempt.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+
+#include <asm/processor.h>
+#include <asm/delay.h>
+#include <asm/timer.h>
+
+#ifdef CONFIG_SMP
+# include <asm/smp.h>
+#endif
+
+/* simple loop based delay: */
+static void delay_loop(unsigned long loops)
+{
+       asm volatile(
+               "       test %0,%0      \n"
+               "       jz 3f           \n"
+               "       jmp 1f          \n"
+
+               ".align 16              \n"
+               "1:     jmp 2f          \n"
+
+               ".align 16              \n"
+               "2:     dec %0          \n"
+               "       jnz 2b          \n"
+               "3:     dec %0          \n"
+
+               : /* we don't need output */
+               :"a" (loops)
+       );
+}
+
+/* TSC based delay: */
+static void delay_tsc(unsigned long loops)
+{
+       unsigned long bclock, now;
+       int cpu;
+
+       preempt_disable();
+       cpu = smp_processor_id();
+       rdtscl(bclock);
+       for (;;) {
+               rdtscl(now);
+               if ((now - bclock) >= loops)
+                       break;
+
+               /* Allow RT tasks to run */
+               preempt_enable();
+               rep_nop();
+               preempt_disable();
+
+               /*
+                * It is possible that we moved to another CPU, and
+                * since TSC's are per-cpu we need to calculate
+                * that. The delay must guarantee that we wait "at
+                * least" the amount of time. Being moved to another
+                * CPU could make the wait longer but we just need to
+                * make sure we waited long enough. Rebalance the
+                * counter for this CPU.
+                */
+               if (unlikely(cpu != smp_processor_id())) {
+                       loops -= (now - bclock);
+                       cpu = smp_processor_id();
+                       rdtscl(bclock);
+               }
+       }
+       preempt_enable();
+}
+
+/*
+ * Since we calibrate only once at boot, this
+ * function should be set once at boot and not changed
+ */
+static void (*delay_fn)(unsigned long) = delay_loop;
+
+void use_tsc_delay(void)
+{
+       delay_fn = delay_tsc;
+}
+
+int __devinit read_current_timer(unsigned long *timer_val)
+{
+       if (delay_fn == delay_tsc) {
+               rdtscll(*timer_val);
+               return 0;
+       }
+       return -1;
+}
+
+void __delay(unsigned long loops)
+{
+       delay_fn(loops);
+}
+EXPORT_SYMBOL(__delay);
+
+inline void __const_udelay(unsigned long xloops)
+{
+       int d0;
+
+       xloops *= 4;
+       asm("mull %%edx"
+               :"=d" (xloops), "=&a" (d0)
+               :"1" (xloops), "0"
+               (cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
+
+       __delay(++xloops);
+}
+EXPORT_SYMBOL(__const_udelay);
+
+void __udelay(unsigned long usecs)
+{
+       __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
+}
+EXPORT_SYMBOL(__udelay);
+
+void __ndelay(unsigned long nsecs)
+{
+       __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
+}
+EXPORT_SYMBOL(__ndelay);
diff --git a/arch/x86/lib/delay_32.c b/arch/x86/lib/delay_32.c
deleted file mode 100644 (file)
index d710f2d..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- *     Precise Delay Loops for i386
- *
- *     Copyright (C) 1993 Linus Torvalds
- *     Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
- *
- *     The __delay function must _NOT_ be inlined as its execution time
- *     depends wildly on alignment on many x86 processors. The additional
- *     jump magic is needed to get the timing stable on all the CPU's
- *     we have to worry about.
- */
-
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/timex.h>
-#include <linux/preempt.h>
-#include <linux/delay.h>
-#include <linux/init.h>
-
-#include <asm/processor.h>
-#include <asm/delay.h>
-#include <asm/timer.h>
-
-#ifdef CONFIG_SMP
-# include <asm/smp.h>
-#endif
-
-/* simple loop based delay: */
-static void delay_loop(unsigned long loops)
-{
-       int d0;
-
-       __asm__ __volatile__(
-               "\tjmp 1f\n"
-               ".align 16\n"
-               "1:\tjmp 2f\n"
-               ".align 16\n"
-               "2:\tdecl %0\n\tjns 2b"
-               :"=&a" (d0)
-               :"0" (loops));
-}
-
-/* TSC based delay: */
-static void delay_tsc(unsigned long loops)
-{
-       unsigned long bclock, now;
-       int cpu;
-
-       preempt_disable();
-       cpu = smp_processor_id();
-       rdtscl(bclock);
-       for (;;) {
-               rdtscl(now);
-               if ((now - bclock) >= loops)
-                       break;
-
-               /* Allow RT tasks to run */
-               preempt_enable();
-               rep_nop();
-               preempt_disable();
-
-               /*
-                * It is possible that we moved to another CPU, and
-                * since TSC's are per-cpu we need to calculate
-                * that. The delay must guarantee that we wait "at
-                * least" the amount of time. Being moved to another
-                * CPU could make the wait longer but we just need to
-                * make sure we waited long enough. Rebalance the
-                * counter for this CPU.
-                */
-               if (unlikely(cpu != smp_processor_id())) {
-                       loops -= (now - bclock);
-                       cpu = smp_processor_id();
-                       rdtscl(bclock);
-               }
-       }
-       preempt_enable();
-}
-
-/*
- * Since we calibrate only once at boot, this
- * function should be set once at boot and not changed
- */
-static void (*delay_fn)(unsigned long) = delay_loop;
-
-void use_tsc_delay(void)
-{
-       delay_fn = delay_tsc;
-}
-
-int __devinit read_current_timer(unsigned long *timer_val)
-{
-       if (delay_fn == delay_tsc) {
-               rdtscl(*timer_val);
-               return 0;
-       }
-       return -1;
-}
-
-void __delay(unsigned long loops)
-{
-       delay_fn(loops);
-}
-
-inline void __const_udelay(unsigned long xloops)
-{
-       int d0;
-
-       xloops *= 4;
-       __asm__("mull %0"
-               :"=d" (xloops), "=&a" (d0)
-               :"1" (xloops), "0"
-               (cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
-
-       __delay(++xloops);
-}
-
-void __udelay(unsigned long usecs)
-{
-       __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
-}
-
-void __ndelay(unsigned long nsecs)
-{
-       __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
-}
-
-EXPORT_SYMBOL(__delay);
-EXPORT_SYMBOL(__const_udelay);
-EXPORT_SYMBOL(__udelay);
-EXPORT_SYMBOL(__ndelay);
diff --git a/arch/x86/lib/delay_64.c b/arch/x86/lib/delay_64.c
deleted file mode 100644 (file)
index 4c441be..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- *     Precise Delay Loops for x86-64
- *
- *     Copyright (C) 1993 Linus Torvalds
- *     Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
- *
- *     The __delay function must _NOT_ be inlined as its execution time
- *     depends wildly on alignment on many x86 processors. 
- */
-
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/timex.h>
-#include <linux/preempt.h>
-#include <linux/delay.h>
-#include <linux/init.h>
-
-#include <asm/delay.h>
-#include <asm/msr.h>
-
-#ifdef CONFIG_SMP
-#include <asm/smp.h>
-#endif
-
-int __devinit read_current_timer(unsigned long *timer_value)
-{
-       rdtscll(*timer_value);
-       return 0;
-}
-
-void __delay(unsigned long loops)
-{
-       unsigned bclock, now;
-       int cpu;
-
-       preempt_disable();
-       cpu = smp_processor_id();
-       rdtscl(bclock);
-       for (;;) {
-               rdtscl(now);
-               if ((now - bclock) >= loops)
-                       break;
-
-               /* Allow RT tasks to run */
-               preempt_enable();
-               rep_nop();
-               preempt_disable();
-
-               /*
-                * It is possible that we moved to another CPU, and
-                * since TSC's are per-cpu we need to calculate
-                * that. The delay must guarantee that we wait "at
-                * least" the amount of time. Being moved to another
-                * CPU could make the wait longer but we just need to
-                * make sure we waited long enough. Rebalance the
-                * counter for this CPU.
-                */
-               if (unlikely(cpu != smp_processor_id())) {
-                       loops -= (now - bclock);
-                       cpu = smp_processor_id();
-                       rdtscl(bclock);
-               }
-       }
-       preempt_enable();
-}
-EXPORT_SYMBOL(__delay);
-
-inline void __const_udelay(unsigned long xloops)
-{
-       __delay(((xloops * HZ *
-               cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1);
-}
-EXPORT_SYMBOL(__const_udelay);
-
-void __udelay(unsigned long usecs)
-{
-       __const_udelay(usecs * 0x000010c7);  /* 2**32 / 1000000 (rounded up) */
-}
-EXPORT_SYMBOL(__udelay);
-
-void __ndelay(unsigned long nsecs)
-{
-       __const_udelay(nsecs * 0x00005);  /* 2**32 / 1000000000 (rounded up) */
-}
-EXPORT_SYMBOL(__ndelay);
diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
new file mode 100644 (file)
index 0000000..ad37400
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * __get_user functions.
+ *
+ * (C) Copyright 1998 Linus Torvalds
+ * (C) Copyright 2005 Andi Kleen
+ * (C) Copyright 2008 Glauber Costa
+ *
+ * These functions have a non-standard call interface
+ * to make them more efficient, especially as they
+ * return an error value in addition to the "real"
+ * return value.
+ */
+
+/*
+ * __get_user_X
+ *
+ * Inputs:     %[r|e]ax contains the address.
+ *             The register is modified, but all changes are undone
+ *             before returning because the C code doesn't know about it.
+ *
+ * Outputs:    %[r|e]ax is error code (0 or -EFAULT)
+ *             %[r|e]dx contains zero-extended value
+ *
+ *
+ * These functions should not modify any other registers,
+ * as they get called from within inline assembly.
+ */
+
+#include <linux/linkage.h>
+#include <asm/dwarf2.h>
+#include <asm/page.h>
+#include <asm/errno.h>
+#include <asm/asm-offsets.h>
+#include <asm/thread_info.h>
+#include <asm/asm.h>
+
+       .text
+ENTRY(__get_user_1)
+       CFI_STARTPROC
+       GET_THREAD_INFO(%_ASM_DX)
+       cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
+       jae bad_get_user
+1:     movzb (%_ASM_AX),%edx
+       xor %eax,%eax
+       ret
+       CFI_ENDPROC
+ENDPROC(__get_user_1)
+
+ENTRY(__get_user_2)
+       CFI_STARTPROC
+       add $1,%_ASM_AX
+       jc bad_get_user
+       GET_THREAD_INFO(%_ASM_DX)
+       cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
+       jae bad_get_user
+2:     movzwl -1(%_ASM_AX),%edx
+       xor %eax,%eax
+       ret
+       CFI_ENDPROC
+ENDPROC(__get_user_2)
+
+ENTRY(__get_user_4)
+       CFI_STARTPROC
+       add $3,%_ASM_AX
+       jc bad_get_user
+       GET_THREAD_INFO(%_ASM_DX)
+       cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
+       jae bad_get_user
+3:     mov -3(%_ASM_AX),%edx
+       xor %eax,%eax
+       ret
+       CFI_ENDPROC
+ENDPROC(__get_user_4)
+
+#ifdef CONFIG_X86_64
+ENTRY(__get_user_8)
+       CFI_STARTPROC
+       add $7,%_ASM_AX
+       jc bad_get_user
+       GET_THREAD_INFO(%_ASM_DX)
+       cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
+       jae     bad_get_user
+4:     movq -7(%_ASM_AX),%_ASM_DX
+       xor %eax,%eax
+       ret
+       CFI_ENDPROC
+ENDPROC(__get_user_8)
+#endif
+
+bad_get_user:
+       CFI_STARTPROC
+       xor %edx,%edx
+       mov $(-EFAULT),%_ASM_AX
+       ret
+       CFI_ENDPROC
+END(bad_get_user)
+
+.section __ex_table,"a"
+       _ASM_PTR 1b,bad_get_user
+       _ASM_PTR 2b,bad_get_user
+       _ASM_PTR 3b,bad_get_user
+#ifdef CONFIG_X86_64
+       _ASM_PTR 4b,bad_get_user
+#endif
diff --git a/arch/x86/lib/getuser_32.S b/arch/x86/lib/getuser_32.S
deleted file mode 100644 (file)
index 6d84b53..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * __get_user functions.
- *
- * (C) Copyright 1998 Linus Torvalds
- *
- * These functions have a non-standard call interface
- * to make them more efficient, especially as they
- * return an error value in addition to the "real"
- * return value.
- */
-#include <linux/linkage.h>
-#include <asm/dwarf2.h>
-#include <asm/thread_info.h>
-
-
-/*
- * __get_user_X
- *
- * Inputs:     %eax contains the address
- *
- * Outputs:    %eax is error code (0 or -EFAULT)
- *             %edx contains zero-extended value
- *
- * These functions should not modify any other registers,
- * as they get called from within inline assembly.
- */
-
-.text
-ENTRY(__get_user_1)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%edx)
-       cmpl TI_addr_limit(%edx),%eax
-       jae bad_get_user
-1:     movzbl (%eax),%edx
-       xorl %eax,%eax
-       ret
-       CFI_ENDPROC
-ENDPROC(__get_user_1)
-
-ENTRY(__get_user_2)
-       CFI_STARTPROC
-       addl $1,%eax
-       jc bad_get_user
-       GET_THREAD_INFO(%edx)
-       cmpl TI_addr_limit(%edx),%eax
-       jae bad_get_user
-2:     movzwl -1(%eax),%edx
-       xorl %eax,%eax
-       ret
-       CFI_ENDPROC
-ENDPROC(__get_user_2)
-
-ENTRY(__get_user_4)
-       CFI_STARTPROC
-       addl $3,%eax
-       jc bad_get_user
-       GET_THREAD_INFO(%edx)
-       cmpl TI_addr_limit(%edx),%eax
-       jae bad_get_user
-3:     movl -3(%eax),%edx
-       xorl %eax,%eax
-       ret
-       CFI_ENDPROC
-ENDPROC(__get_user_4)
-
-bad_get_user:
-       CFI_STARTPROC
-       xorl %edx,%edx
-       movl $-14,%eax
-       ret
-       CFI_ENDPROC
-END(bad_get_user)
-
-.section __ex_table,"a"
-       .long 1b,bad_get_user
-       .long 2b,bad_get_user
-       .long 3b,bad_get_user
-.previous
diff --git a/arch/x86/lib/getuser_64.S b/arch/x86/lib/getuser_64.S
deleted file mode 100644 (file)
index 5448876..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * __get_user functions.
- *
- * (C) Copyright 1998 Linus Torvalds
- * (C) Copyright 2005 Andi Kleen
- *
- * These functions have a non-standard call interface
- * to make them more efficient, especially as they
- * return an error value in addition to the "real"
- * return value.
- */
-
-/*
- * __get_user_X
- *
- * Inputs:     %rcx contains the address.
- *             The register is modified, but all changes are undone
- *             before returning because the C code doesn't know about it.
- *
- * Outputs:    %rax is error code (0 or -EFAULT)
- *             %rdx contains zero-extended value
- * 
- * %r8 is destroyed.
- *
- * These functions should not modify any other registers,
- * as they get called from within inline assembly.
- */
-
-#include <linux/linkage.h>
-#include <asm/dwarf2.h>
-#include <asm/page.h>
-#include <asm/errno.h>
-#include <asm/asm-offsets.h>
-#include <asm/thread_info.h>
-
-       .text
-ENTRY(__get_user_1)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae bad_get_user
-1:     movzb (%rcx),%edx
-       xorl %eax,%eax
-       ret
-       CFI_ENDPROC
-ENDPROC(__get_user_1)
-
-ENTRY(__get_user_2)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $1,%rcx
-       jc 20f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae 20f
-       decq   %rcx
-2:     movzwl (%rcx),%edx
-       xorl %eax,%eax
-       ret
-20:    decq    %rcx
-       jmp     bad_get_user
-       CFI_ENDPROC
-ENDPROC(__get_user_2)
-
-ENTRY(__get_user_4)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $3,%rcx
-       jc 30f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae 30f
-       subq $3,%rcx
-3:     movl (%rcx),%edx
-       xorl %eax,%eax
-       ret
-30:    subq $3,%rcx
-       jmp bad_get_user
-       CFI_ENDPROC
-ENDPROC(__get_user_4)
-
-ENTRY(__get_user_8)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $7,%rcx
-       jc 40f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae     40f
-       subq    $7,%rcx
-4:     movq (%rcx),%rdx
-       xorl %eax,%eax
-       ret
-40:    subq $7,%rcx
-       jmp bad_get_user
-       CFI_ENDPROC
-ENDPROC(__get_user_8)
-
-bad_get_user:
-       CFI_STARTPROC
-       xorl %edx,%edx
-       movq $(-EFAULT),%rax
-       ret
-       CFI_ENDPROC
-END(bad_get_user)
-
-.section __ex_table,"a"
-       .quad 1b,bad_get_user
-       .quad 2b,bad_get_user
-       .quad 3b,bad_get_user
-       .quad 4b,bad_get_user
-.previous
diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
new file mode 100644 (file)
index 0000000..36b0d15
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * __put_user functions.
+ *
+ * (C) Copyright 2005 Linus Torvalds
+ * (C) Copyright 2005 Andi Kleen
+ * (C) Copyright 2008 Glauber Costa
+ *
+ * These functions have a non-standard call interface
+ * to make them more efficient, especially as they
+ * return an error value in addition to the "real"
+ * return value.
+ */
+#include <linux/linkage.h>
+#include <asm/dwarf2.h>
+#include <asm/thread_info.h>
+#include <asm/errno.h>
+#include <asm/asm.h>
+
+
+/*
+ * __put_user_X
+ *
+ * Inputs:     %eax[:%edx] contains the data
+ *             %ecx contains the address
+ *
+ * Outputs:    %eax is error code (0 or -EFAULT)
+ *
+ * These functions should not modify any other registers,
+ * as they get called from within inline assembly.
+ */
+
+#define ENTER  CFI_STARTPROC ; \
+               GET_THREAD_INFO(%_ASM_BX)
+#define EXIT   ret ; \
+               CFI_ENDPROC
+
+.text
+ENTRY(__put_user_1)
+       ENTER
+       cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
+       jae bad_put_user
+1:     movb %al,(%_ASM_CX)
+       xor %eax,%eax
+       EXIT
+ENDPROC(__put_user_1)
+
+ENTRY(__put_user_2)
+       ENTER
+       mov TI_addr_limit(%_ASM_BX),%_ASM_BX
+       sub $1,%_ASM_BX
+       cmp %_ASM_BX,%_ASM_CX
+       jae bad_put_user
+2:     movw %ax,(%_ASM_CX)
+       xor %eax,%eax
+       EXIT
+ENDPROC(__put_user_2)
+
+ENTRY(__put_user_4)
+       ENTER
+       mov TI_addr_limit(%_ASM_BX),%_ASM_BX
+       sub $3,%_ASM_BX
+       cmp %_ASM_BX,%_ASM_CX
+       jae bad_put_user
+3:     movl %eax,(%_ASM_CX)
+       xor %eax,%eax
+       EXIT
+ENDPROC(__put_user_4)
+
+ENTRY(__put_user_8)
+       ENTER
+       mov TI_addr_limit(%_ASM_BX),%_ASM_BX
+       sub $7,%_ASM_BX
+       cmp %_ASM_BX,%_ASM_CX
+       jae bad_put_user
+4:     mov %_ASM_AX,(%_ASM_CX)
+#ifdef CONFIG_X86_32
+5:     movl %edx,4(%_ASM_CX)
+#endif
+       xor %eax,%eax
+       EXIT
+ENDPROC(__put_user_8)
+
+bad_put_user:
+       CFI_STARTPROC
+       movl $-EFAULT,%eax
+       EXIT
+END(bad_put_user)
+
+.section __ex_table,"a"
+       _ASM_PTR 1b,bad_put_user
+       _ASM_PTR 2b,bad_put_user
+       _ASM_PTR 3b,bad_put_user
+       _ASM_PTR 4b,bad_put_user
+#ifdef CONFIG_X86_32
+       _ASM_PTR 5b,bad_put_user
+#endif
+.previous
diff --git a/arch/x86/lib/putuser_32.S b/arch/x86/lib/putuser_32.S
deleted file mode 100644 (file)
index f58fba1..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * __put_user functions.
- *
- * (C) Copyright 2005 Linus Torvalds
- *
- * These functions have a non-standard call interface
- * to make them more efficient, especially as they
- * return an error value in addition to the "real"
- * return value.
- */
-#include <linux/linkage.h>
-#include <asm/dwarf2.h>
-#include <asm/thread_info.h>
-
-
-/*
- * __put_user_X
- *
- * Inputs:     %eax[:%edx] contains the data
- *             %ecx contains the address
- *
- * Outputs:    %eax is error code (0 or -EFAULT)
- *
- * These functions should not modify any other registers,
- * as they get called from within inline assembly.
- */
-
-#define ENTER  CFI_STARTPROC ; \
-               pushl %ebx ; \
-               CFI_ADJUST_CFA_OFFSET 4 ; \
-               CFI_REL_OFFSET ebx, 0 ; \
-               GET_THREAD_INFO(%ebx)
-#define EXIT   popl %ebx ; \
-               CFI_ADJUST_CFA_OFFSET -4 ; \
-               CFI_RESTORE ebx ; \
-               ret ; \
-               CFI_ENDPROC
-
-.text
-ENTRY(__put_user_1)
-       ENTER
-       cmpl TI_addr_limit(%ebx),%ecx
-       jae bad_put_user
-1:     movb %al,(%ecx)
-       xorl %eax,%eax
-       EXIT
-ENDPROC(__put_user_1)
-
-ENTRY(__put_user_2)
-       ENTER
-       movl TI_addr_limit(%ebx),%ebx
-       subl $1,%ebx
-       cmpl %ebx,%ecx
-       jae bad_put_user
-2:     movw %ax,(%ecx)
-       xorl %eax,%eax
-       EXIT
-ENDPROC(__put_user_2)
-
-ENTRY(__put_user_4)
-       ENTER
-       movl TI_addr_limit(%ebx),%ebx
-       subl $3,%ebx
-       cmpl %ebx,%ecx
-       jae bad_put_user
-3:     movl %eax,(%ecx)
-       xorl %eax,%eax
-       EXIT
-ENDPROC(__put_user_4)
-
-ENTRY(__put_user_8)
-       ENTER
-       movl TI_addr_limit(%ebx),%ebx
-       subl $7,%ebx
-       cmpl %ebx,%ecx
-       jae bad_put_user
-4:     movl %eax,(%ecx)
-5:     movl %edx,4(%ecx)
-       xorl %eax,%eax
-       EXIT
-ENDPROC(__put_user_8)
-
-bad_put_user:
-       CFI_STARTPROC simple
-       CFI_DEF_CFA esp, 2*4
-       CFI_OFFSET eip, -1*4
-       CFI_OFFSET ebx, -2*4
-       movl $-14,%eax
-       EXIT
-END(bad_put_user)
-
-.section __ex_table,"a"
-       .long 1b,bad_put_user
-       .long 2b,bad_put_user
-       .long 3b,bad_put_user
-       .long 4b,bad_put_user
-       .long 5b,bad_put_user
-.previous
diff --git a/arch/x86/lib/putuser_64.S b/arch/x86/lib/putuser_64.S
deleted file mode 100644 (file)
index 4989f5a..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * __put_user functions.
- *
- * (C) Copyright 1998 Linus Torvalds
- * (C) Copyright 2005 Andi Kleen
- *
- * These functions have a non-standard call interface
- * to make them more efficient, especially as they
- * return an error value in addition to the "real"
- * return value.
- */
-
-/*
- * __put_user_X
- *
- * Inputs:     %rcx contains the address
- *             %rdx contains new value
- *
- * Outputs:    %rax is error code (0 or -EFAULT)
- *
- * %r8 is destroyed.
- *
- * These functions should not modify any other registers,
- * as they get called from within inline assembly.
- */
-
-#include <linux/linkage.h>
-#include <asm/dwarf2.h>
-#include <asm/page.h>
-#include <asm/errno.h>
-#include <asm/asm-offsets.h>
-#include <asm/thread_info.h>
-
-       .text
-ENTRY(__put_user_1)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae bad_put_user
-1:     movb %dl,(%rcx)
-       xorl %eax,%eax
-       ret
-       CFI_ENDPROC
-ENDPROC(__put_user_1)
-
-ENTRY(__put_user_2)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $1,%rcx
-       jc 20f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae 20f
-       decq %rcx
-2:     movw %dx,(%rcx)
-       xorl %eax,%eax
-       ret
-20:    decq %rcx
-       jmp bad_put_user
-       CFI_ENDPROC
-ENDPROC(__put_user_2)
-
-ENTRY(__put_user_4)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $3,%rcx
-       jc 30f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae 30f
-       subq $3,%rcx
-3:     movl %edx,(%rcx)
-       xorl %eax,%eax
-       ret
-30:    subq $3,%rcx
-       jmp bad_put_user
-       CFI_ENDPROC
-ENDPROC(__put_user_4)
-
-ENTRY(__put_user_8)
-       CFI_STARTPROC
-       GET_THREAD_INFO(%r8)
-       addq $7,%rcx
-       jc 40f
-       cmpq threadinfo_addr_limit(%r8),%rcx
-       jae 40f
-       subq $7,%rcx
-4:     movq %rdx,(%rcx)
-       xorl %eax,%eax
-       ret
-40:    subq $7,%rcx
-       jmp bad_put_user
-       CFI_ENDPROC
-ENDPROC(__put_user_8)
-
-bad_put_user:
-       CFI_STARTPROC
-       movq $(-EFAULT),%rax
-       ret
-       CFI_ENDPROC
-END(bad_put_user)
-
-.section __ex_table,"a"
-       .quad 1b,bad_put_user
-       .quad 2b,bad_put_user
-       .quad 3b,bad_put_user
-       .quad 4b,bad_put_user
-.previous
diff --git a/arch/x86/lib/thunk_32.S b/arch/x86/lib/thunk_32.S
new file mode 100644 (file)
index 0000000..650b11e
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Trampoline to trace irqs off. (otherwise CALLER_ADDR1 might crash)
+ * Copyright 2008 by Steven Rostedt, Red Hat, Inc
+ *  (inspired by Andi Kleen's thunk_64.S)
+ * Subject to the GNU public license, v.2. No warranty of any kind.
+ */
+
+       #include <linux/linkage.h>
+
+#define ARCH_TRACE_IRQS_ON                     \
+       pushl %eax;                             \
+       pushl %ecx;                             \
+       pushl %edx;                             \
+       call trace_hardirqs_on;                 \
+       popl %edx;                              \
+       popl %ecx;                              \
+       popl %eax;
+
+#define ARCH_TRACE_IRQS_OFF                    \
+       pushl %eax;                             \
+       pushl %ecx;                             \
+       pushl %edx;                             \
+       call trace_hardirqs_off;                \
+       popl %edx;                              \
+       popl %ecx;                              \
+       popl %eax;
+
+#ifdef CONFIG_TRACE_IRQFLAGS
+       /* put return address in eax (arg1) */
+       .macro thunk_ra name,func
+       .globl \name
+\name:
+       pushl %eax
+       pushl %ecx
+       pushl %edx
+       /* Place EIP in the arg1 */
+       movl 3*4(%esp), %eax
+       call \func
+       popl %edx
+       popl %ecx
+       popl %eax
+       ret
+       .endm
+
+       thunk_ra trace_hardirqs_on_thunk,trace_hardirqs_on_caller
+       thunk_ra trace_hardirqs_off_thunk,trace_hardirqs_off_caller
+#endif
index e009251..bf9a7d5 100644 (file)
@@ -2,6 +2,7 @@
  * Save registers before calling assembly functions. This avoids
  * disturbance of register allocation in some inline assembly constructs.
  * Copyright 2001,2002 by Andi Kleen, SuSE Labs.
+ * Added trace_hardirqs callers - Copyright 2007 Steven Rostedt, Red Hat, Inc.
  * Subject to the GNU public license, v.2. No warranty of any kind.
  */
 
 #endif 
        
 #ifdef CONFIG_TRACE_IRQFLAGS
-       thunk trace_hardirqs_on_thunk,trace_hardirqs_on
-       thunk trace_hardirqs_off_thunk,trace_hardirqs_off
+       /* put return address in rdi (arg1) */
+       .macro thunk_ra name,func
+       .globl \name
+\name:
+       CFI_STARTPROC
+       SAVE_ARGS
+       /* SAVE_ARGS pushs 9 elements */
+       /* the next element would be the rip */
+       movq 9*8(%rsp), %rdi
+       call \func
+       jmp  restore
+       CFI_ENDPROC
+       .endm
+
+       thunk_ra trace_hardirqs_on_thunk,trace_hardirqs_on_caller
+       thunk_ra trace_hardirqs_off_thunk,trace_hardirqs_off_caller
 #endif
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
index 0c89d1b..f4df6e7 100644 (file)
@@ -158,3 +158,26 @@ unsigned long copy_in_user(void __user *to, const void __user *from, unsigned le
 }
 EXPORT_SYMBOL(copy_in_user);
 
+/*
+ * Try to copy last bytes and clear the rest if needed.
+ * Since protection fault in copy_from/to_user is not a normal situation,
+ * it is not necessary to optimize tail handling.
+ */
+unsigned long
+copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
+{
+       char c;
+       unsigned zero_len;
+
+       for (; len; --len) {
+               if (__get_user_nocheck(c, from++, sizeof(char)))
+                       break;
+               if (__put_user_nocheck(c, to++, sizeof(char)))
+                       break;
+       }
+
+       for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
+               if (__put_user_nocheck(c, to++, sizeof(char)))
+                       break;
+       return len;
+}
index 0c28a07..48278fa 100644 (file)
 #include <asm/e820.h>
 #include <asm/setup.h>
 
+/*
+ * Any quirks to be performed to initialize timers/irqs/etc?
+ */
+int (*arch_time_init_quirk)(void);
+int (*arch_pre_intr_init_quirk)(void);
+int (*arch_intr_init_quirk)(void);
+int (*arch_trap_init_quirk)(void);
+
 #ifdef CONFIG_HOTPLUG_CPU
 #define DEFAULT_SEND_IPI       (1)
 #else
@@ -29,6 +37,10 @@ int no_broadcast=DEFAULT_SEND_IPI;
  **/
 void __init pre_intr_init_hook(void)
 {
+       if (arch_pre_intr_init_quirk) {
+               if (arch_pre_intr_init_quirk())
+                       return;
+       }
        init_ISA_irqs();
 }
 
@@ -52,6 +64,10 @@ static struct irqaction irq2 = {
  **/
 void __init intr_init_hook(void)
 {
+       if (arch_intr_init_quirk) {
+               if (arch_intr_init_quirk())
+                       return;
+       }
 #ifdef CONFIG_X86_LOCAL_APIC
        apic_intr_init();
 #endif
@@ -65,7 +81,7 @@ void __init intr_init_hook(void)
  *
  * Description:
  *     generally used to activate any machine specific identification
- *     routines that may be needed before setup_arch() runs.  On VISWS
+ *     routines that may be needed before setup_arch() runs.  On Voyager
  *     this is used to get the board revision and type.
  **/
 void __init pre_setup_arch_hook(void)
@@ -81,6 +97,10 @@ void __init pre_setup_arch_hook(void)
  **/
 void __init trap_init_hook(void)
 {
+       if (arch_trap_init_quirk) {
+               if (arch_trap_init_quirk())
+                       return;
+       }
 }
 
 static struct irqaction irq0  = {
@@ -99,6 +119,16 @@ static struct irqaction irq0  = {
  **/
 void __init time_init_hook(void)
 {
+       if (arch_time_init_quirk) {
+               /*
+                * A nonzero return code does not mean failure, it means
+                * that the architecture quirk does not want any
+                * generic (timer) setup to be performed after this:
+                */
+               if (arch_time_init_quirk())
+                       return;
+       }
+
        irq0.mask = cpumask_of_cpu(0);
        setup_irq(0, &irq0);
 }
@@ -142,45 +172,3 @@ static int __init print_ipi_mode(void)
 
 late_initcall(print_ipi_mode);
 
-/**
- * machine_specific_memory_setup - Hook for machine specific memory setup.
- *
- * Description:
- *     This is included late in kernel/setup.c so that it can make
- *     use of all of the static functions.
- **/
-
-char * __init machine_specific_memory_setup(void)
-{
-       char *who;
-
-
-       who = "BIOS-e820";
-
-       /*
-        * Try to copy the BIOS-supplied E820-map.
-        *
-        * Otherwise fake a memory map; one section from 0k->640k,
-        * the next section from 1mb->appropriate_mem_k
-        */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
-       if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries)
-           < 0) {
-               unsigned long mem_size;
-
-               /* compare results from other methods and take the greater */
-               if (boot_params.alt_mem_k
-                   < boot_params.screen_info.ext_mem_k) {
-                       mem_size = boot_params.screen_info.ext_mem_k;
-                       who = "BIOS-88";
-               } else {
-                       mem_size = boot_params.alt_mem_k;
-                       who = "BIOS-e801";
-               }
-
-               e820.nr_map = 0;
-               add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-               add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
-       }
-       return who;
-}
index 69dd4da..3ef8b43 100644 (file)
@@ -3,4 +3,3 @@
 #
 
 obj-$(CONFIG_X86_ES7000)       := es7000plat.o
-obj-$(CONFIG_X86_GENERICARCH)  := es7000plat.o
index f5d6f7d..4354ce8 100644 (file)
@@ -52,6 +52,8 @@ static struct mip_reg         *host_reg;
 static int                     mip_port;
 static unsigned long           mip_addr, host_addr;
 
+int es7000_plat;
+
 /*
  * GSI override for ES7000 platforms.
  */
@@ -175,53 +177,6 @@ find_unisys_acpi_oem_table(unsigned long *oem_addr)
 }
 #endif
 
-/*
- * This file also gets compiled if CONFIG_X86_GENERICARCH is set. Generic
- * arch already has got following function definitions (asm-generic/es7000.c)
- * hence no need to define these for that case.
- */
-#ifndef CONFIG_X86_GENERICARCH
-void es7000_sw_apic(void);
-void __init enable_apic_mode(void)
-{
-       es7000_sw_apic();
-       return;
-}
-
-__init int mps_oem_check(struct mp_config_table *mpc, char *oem,
-               char *productid)
-{
-       if (mpc->mpc_oemptr) {
-               struct mp_config_oemtable *oem_table =
-                       (struct mp_config_oemtable *)mpc->mpc_oemptr;
-               if (!strncmp(oem, "UNISYS", 6))
-                       return parse_unisys_oem((char *)oem_table);
-       }
-       return 0;
-}
-#ifdef CONFIG_ACPI
-/* Hook from generic ACPI tables.c */
-int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
-{
-       unsigned long oem_addr;
-       if (!find_unisys_acpi_oem_table(&oem_addr)) {
-               if (es7000_check_dsdt())
-                       return parse_unisys_oem((char *)oem_addr);
-               else {
-                       setup_unisys();
-                       return 1;
-               }
-       }
-       return 0;
-}
-#else
-int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
-{
-       return 0;
-}
-#endif
-#endif /* COFIG_X86_GENERICARCH */
-
 static void
 es7000_spin(int n)
 {
index 19d6d40..0dbd780 100644 (file)
@@ -2,7 +2,11 @@
 # Makefile for the generic architecture
 #
 
-EXTRA_CFLAGS   := -Iarch/x86/kernel
+EXTRA_CFLAGS                   := -Iarch/x86/kernel
 
-obj-y          := probe.o summit.o bigsmp.o es7000.o default.o 
-obj-y          += ../../x86/mach-es7000/
+obj-y                          := probe.o default.o
+obj-$(CONFIG_X86_NUMAQ)                += numaq.o
+obj-$(CONFIG_X86_SUMMIT)       += summit.o
+obj-$(CONFIG_X86_BIGSMP)       += bigsmp.o
+obj-$(CONFIG_X86_ES7000)       += es7000.o
+obj-$(CONFIG_X86_ES7000)       += ../../x86/mach-es7000/
index 95fc463..59d7717 100644 (file)
@@ -23,10 +23,8 @@ static int dmi_bigsmp; /* can be set by dmi scanners */
 
 static int hp_ht_bigsmp(const struct dmi_system_id *d)
 {
-#ifdef CONFIG_X86_GENERICARCH
        printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
        dmi_bigsmp = 1;
-#endif
        return 0;
 }
 
@@ -48,7 +46,7 @@ static const struct dmi_system_id bigsmp_dmi_table[] = {
 static int probe_bigsmp(void)
 {
        if (def_to_bigsmp)
-       dmi_bigsmp = 1;
+               dmi_bigsmp = 1;
        else
                dmi_check_system(bigsmp_dmi_table);
        return dmi_bigsmp;
diff --git a/arch/x86/mach-generic/numaq.c b/arch/x86/mach-generic/numaq.c
new file mode 100644 (file)
index 0000000..8091e68
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * APIC driver for the IBM NUMAQ chipset.
+ */
+#define APIC_DEFINITION 1
+#include <linux/threads.h>
+#include <linux/cpumask.h>
+#include <linux/smp.h>
+#include <asm/mpspec.h>
+#include <asm/genapic.h>
+#include <asm/fixmap.h>
+#include <asm/apicdef.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/init.h>
+#include <asm/mach-numaq/mach_apic.h>
+#include <asm/mach-numaq/mach_apicdef.h>
+#include <asm/mach-numaq/mach_ipi.h>
+#include <asm/mach-numaq/mach_mpparse.h>
+#include <asm/mach-numaq/mach_wakecpu.h>
+#include <asm/numaq.h>
+
+static int mps_oem_check(struct mp_config_table *mpc, char *oem,
+               char *productid)
+{
+       numaq_mps_oem_check(mpc, oem, productid);
+       return found_numaq;
+}
+
+static int probe_numaq(void)
+{
+       /* already know from get_memcfg_numaq() */
+       return found_numaq;
+}
+
+/* Hook from generic ACPI tables.c */
+static int acpi_madt_oem_check(char *oem_id, char *oem_table_id)
+{
+       return 0;
+}
+
+struct genapic apic_numaq = APIC_INIT("NUMAQ", probe_numaq);
index c5ae751..5a7e461 100644 (file)
@@ -16,6 +16,7 @@
 #include <asm/apicdef.h>
 #include <asm/genapic.h>
 
+extern struct genapic apic_numaq;
 extern struct genapic apic_summit;
 extern struct genapic apic_bigsmp;
 extern struct genapic apic_es7000;
@@ -24,9 +25,18 @@ extern struct genapic apic_default;
 struct genapic *genapic = &apic_default;
 
 static struct genapic *apic_probe[] __initdata = {
+#ifdef CONFIG_X86_NUMAQ
+       &apic_numaq,
+#endif
+#ifdef CONFIG_X86_SUMMIT
        &apic_summit,
+#endif
+#ifdef CONFIG_X86_BIGSMP
        &apic_bigsmp,
+#endif
+#ifdef CONFIG_X86_ES7000
        &apic_es7000,
+#endif
        &apic_default,  /* must be last */
        NULL,
 };
@@ -54,6 +64,7 @@ early_param("apic", parse_apic);
 
 void __init generic_bigsmp_probe(void)
 {
+#ifdef CONFIG_X86_BIGSMP
        /*
         * This routine is used to switch to bigsmp mode when
         * - There is no apic= option specified by the user
@@ -67,6 +78,7 @@ void __init generic_bigsmp_probe(void)
                        printk(KERN_INFO "Overriding APIC driver with %s\n",
                               genapic->name);
                }
+#endif
 }
 
 void __init generic_apic_probe(void)
@@ -88,7 +100,8 @@ void __init generic_apic_probe(void)
 
 /* These functions can switch the APIC even after the initial ->probe() */
 
-int __init mps_oem_check(struct mp_config_table *mpc, char *oem, char *productid)
+int __init mps_oem_check(struct mp_config_table *mpc, char *oem,
+                                char *productid)
 {
        int i;
        for (i = 0; apic_probe[i]; ++i) {
diff --git a/arch/x86/mach-visws/Makefile b/arch/x86/mach-visws/Makefile
deleted file mode 100644 (file)
index 835fd96..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-obj-y                          := setup.o traps.o reboot.o
-
-obj-$(CONFIG_X86_VISWS_APIC)   += visws_apic.o
-obj-$(CONFIG_X86_LOCAL_APIC)   += mpparse.o
diff --git a/arch/x86/mach-visws/mpparse.c b/arch/x86/mach-visws/mpparse.c
deleted file mode 100644 (file)
index 57484e9..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-
-#include <linux/init.h>
-#include <linux/smp.h>
-
-#include <asm/smp.h>
-#include <asm/io.h>
-
-#include "cobalt.h"
-#include "mach_apic.h"
-
-/* Have we found an MP table */
-int smp_found_config;
-
-int pic_mode;
-
-extern unsigned int __cpuinitdata maxcpus;
-
-/*
- * The Visual Workstation is Intel MP compliant in the hardware
- * sense, but it doesn't have a BIOS(-configuration table).
- * No problem for Linux.
- */
-
-static void __init MP_processor_info (struct mpc_config_processor *m)
-{
-       int ver, logical_apicid;
-       physid_mask_t apic_cpus;
-
-       if (!(m->mpc_cpuflag & CPU_ENABLED))
-               return;
-
-       logical_apicid = m->mpc_apicid;
-       printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
-              m->mpc_cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
-              m->mpc_apicid,
-              (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
-              (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
-              m->mpc_apicver);
-
-       if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
-               boot_cpu_physical_apicid = m->mpc_apicid;
-
-       ver = m->mpc_apicver;
-       if ((ver >= 0x14 && m->mpc_apicid >= 0xff) || m->mpc_apicid >= 0xf) {
-               printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
-                       m->mpc_apicid, MAX_APICS);
-               return;
-       }
-
-       apic_cpus = apicid_to_cpu_present(m->mpc_apicid);
-       physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
-       /*
-        * Validate version
-        */
-       if (ver == 0x0) {
-               printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
-                       "fixing up to 0x10. (tell your hw vendor)\n",
-                       m->mpc_apicid);
-               ver = 0x10;
-       }
-       apic_version[m->mpc_apicid] = ver;
-}
-
-void __init find_smp_config(void)
-{
-       struct mpc_config_processor *mp = phys_to_virt(CO_CPU_TAB_PHYS);
-       unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
-
-       if (ncpus > CO_CPU_MAX) {
-               printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
-                       ncpus, mp);
-
-               ncpus = CO_CPU_MAX;
-       }
-
-       if (ncpus > maxcpus)
-               ncpus = maxcpus;
-
-       smp_found_config = 1;
-       while (ncpus--)
-               MP_processor_info(mp++);
-
-       mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
-}
-
-void __init get_smp_config (void)
-{
-}
diff --git a/arch/x86/mach-visws/reboot.c b/arch/x86/mach-visws/reboot.c
deleted file mode 100644 (file)
index 99332ab..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#include <linux/module.h>
-#include <linux/smp.h>
-#include <linux/delay.h>
-
-#include <asm/io.h>
-#include "piix4.h"
-
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-void machine_shutdown(void)
-{
-#ifdef CONFIG_SMP
-       smp_send_stop();
-#endif
-}
-
-void machine_emergency_restart(void)
-{
-       /*
-        * Visual Workstations restart after this
-        * register is poked on the PIIX4
-        */
-       outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
-}
-
-void machine_restart(char * __unused)
-{
-       machine_shutdown();
-       machine_emergency_restart();
-}
-
-void machine_power_off(void)
-{
-       unsigned short pm_status;
-       extern unsigned int pci_bus0;
-
-       while ((pm_status = inw(PMSTS_PORT)) & 0x100)
-               outw(pm_status, PMSTS_PORT);
-
-       outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
-
-       mdelay(10);
-
-#define PCI_CONF1_ADDRESS(bus, devfn, reg) \
-       (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
-
-       outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8);
-       outl(PIIX_SPECIAL_STOP, 0xCFC);
-}
-
-void machine_halt(void)
-{
-}
-
diff --git a/arch/x86/mach-visws/setup.c b/arch/x86/mach-visws/setup.c
deleted file mode 100644 (file)
index de4c9db..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- *  Unmaintained SGI Visual Workstation support.
- *  Split out from setup.c by davej@suse.de
- */
-
-#include <linux/smp.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/module.h>
-
-#include <asm/fixmap.h>
-#include <asm/arch_hooks.h>
-#include <asm/io.h>
-#include <asm/e820.h>
-#include <asm/setup.h>
-#include "cobalt.h"
-#include "piix4.h"
-
-int no_broadcast;
-
-char visws_board_type = -1;
-char visws_board_rev = -1;
-
-void __init visws_get_board_type_and_rev(void)
-{
-       int raw;
-
-       visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
-                                                        >> PIIX_GPI_BD_SHIFT;
-       /*
-        * Get Board rev.
-        * First, we have to initialize the 307 part to allow us access
-        * to the GPIO registers.  Let's map them at 0x0fc0 which is right
-        * after the PIIX4 PM section.
-        */
-       outb_p(SIO_DEV_SEL, SIO_INDEX);
-       outb_p(SIO_GP_DEV, SIO_DATA);   /* Talk to GPIO regs. */
-
-       outb_p(SIO_DEV_MSB, SIO_INDEX);
-       outb_p(SIO_GP_MSB, SIO_DATA);   /* MSB of GPIO base address */
-
-       outb_p(SIO_DEV_LSB, SIO_INDEX);
-       outb_p(SIO_GP_LSB, SIO_DATA);   /* LSB of GPIO base address */
-
-       outb_p(SIO_DEV_ENB, SIO_INDEX);
-       outb_p(1, SIO_DATA);            /* Enable GPIO registers. */
-
-       /*
-        * Now, we have to map the power management section to write
-        * a bit which enables access to the GPIO registers.
-        * What lunatic came up with this shit?
-        */
-       outb_p(SIO_DEV_SEL, SIO_INDEX);
-       outb_p(SIO_PM_DEV, SIO_DATA);   /* Talk to GPIO regs. */
-
-       outb_p(SIO_DEV_MSB, SIO_INDEX);
-       outb_p(SIO_PM_MSB, SIO_DATA);   /* MSB of PM base address */
-
-       outb_p(SIO_DEV_LSB, SIO_INDEX);
-       outb_p(SIO_PM_LSB, SIO_DATA);   /* LSB of PM base address */
-
-       outb_p(SIO_DEV_ENB, SIO_INDEX);
-       outb_p(1, SIO_DATA);            /* Enable PM registers. */
-
-       /*
-        * Now, write the PM register which enables the GPIO registers.
-        */
-       outb_p(SIO_PM_FER2, SIO_PM_INDEX);
-       outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
-
-       /*
-        * Now, initialize the GPIO registers.
-        * We want them all to be inputs which is the
-        * power on default, so let's leave them alone.
-        * So, let's just read the board rev!
-        */
-       raw = inb_p(SIO_GP_DATA1);
-       raw &= 0x7f;    /* 7 bits of valid board revision ID. */
-
-       if (visws_board_type == VISWS_320) {
-               if (raw < 0x6) {
-                       visws_board_rev = 4;
-               } else if (raw < 0xc) {
-                       visws_board_rev = 5;
-               } else {
-                       visws_board_rev = 6;
-               }
-       } else if (visws_board_type == VISWS_540) {
-                       visws_board_rev = 2;
-               } else {
-                       visws_board_rev = raw;
-               }
-
-       printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
-              (visws_board_type == VISWS_320 ? "320" :
-              (visws_board_type == VISWS_540 ? "540" :
-               "unknown")), visws_board_rev);
-}
-
-void __init pre_intr_init_hook(void)
-{
-       init_VISWS_APIC_irqs();
-}
-
-void __init intr_init_hook(void)
-{
-#ifdef CONFIG_X86_LOCAL_APIC
-       apic_intr_init();
-#endif
-}
-
-void __init pre_setup_arch_hook()
-{
-       visws_get_board_type_and_rev();
-}
-
-static struct irqaction irq0 = {
-       .handler =      timer_interrupt,
-       .flags =        IRQF_DISABLED | IRQF_IRQPOLL,
-       .name =         "timer",
-};
-
-void __init time_init_hook(void)
-{
-       printk(KERN_INFO "Starting Cobalt Timer system clock\n");
-
-       /* Set the countdown value */
-       co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
-
-       /* Start the timer */
-       co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
-
-       /* Enable (unmask) the timer interrupt */
-       co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
-
-       /* Wire cpu IDT entry to s/w handler (and Cobalt APIC to IDT) */
-       setup_irq(0, &irq0);
-}
-
-/* Hook for machine specific memory setup. */
-
-#define MB (1024 * 1024)
-
-unsigned long sgivwfb_mem_phys;
-unsigned long sgivwfb_mem_size;
-EXPORT_SYMBOL(sgivwfb_mem_phys);
-EXPORT_SYMBOL(sgivwfb_mem_size);
-
-long long mem_size __initdata = 0;
-
-char * __init machine_specific_memory_setup(void)
-{
-       long long gfx_mem_size = 8 * MB;
-
-       mem_size = boot_params.alt_mem_k;
-
-       if (!mem_size) {
-               printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
-               mem_size = 128 * MB;
-       }
-
-       /*
-        * this hardcodes the graphics memory to 8 MB
-        * it really should be sized dynamically (or at least
-        * set as a boot param)
-        */
-       if (!sgivwfb_mem_size) {
-               printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
-               sgivwfb_mem_size = 8 * MB;
-       }
-
-       /*
-        * Trim to nearest MB
-        */
-       sgivwfb_mem_size &= ~((1 << 20) - 1);
-       sgivwfb_mem_phys = mem_size - gfx_mem_size;
-
-       add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-       add_memory_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
-       add_memory_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
-
-       return "PROM";
-}
diff --git a/arch/x86/mach-visws/traps.c b/arch/x86/mach-visws/traps.c
deleted file mode 100644 (file)
index bfac6ba..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* VISWS traps */
-
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/pci.h>
-#include <linux/pci_ids.h>
-
-#include <asm/io.h>
-#include <asm/arch_hooks.h>
-#include <asm/apic.h>
-#include "cobalt.h"
-#include "lithium.h"
-
-
-#define A01234 (LI_INTA_0 | LI_INTA_1 | LI_INTA_2 | LI_INTA_3 | LI_INTA_4)
-#define BCD (LI_INTB | LI_INTC | LI_INTD)
-#define ALLDEVS (A01234 | BCD)
-
-static __init void lithium_init(void)
-{
-       set_fixmap(FIX_LI_PCIA, LI_PCI_A_PHYS);
-       set_fixmap(FIX_LI_PCIB, LI_PCI_B_PHYS);
-
-       if ((li_pcia_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
-           (li_pcia_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
-               printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'A');
-               panic("This machine is not SGI Visual Workstation 320/540");
-       }
-
-       if ((li_pcib_read16(PCI_VENDOR_ID) != PCI_VENDOR_ID_SGI) ||
-           (li_pcib_read16(PCI_DEVICE_ID) != PCI_DEVICE_ID_SGI_LITHIUM)) {
-               printk(KERN_EMERG "Lithium hostbridge %c not found\n", 'B');
-               panic("This machine is not SGI Visual Workstation 320/540");
-       }
-
-       li_pcia_write16(LI_PCI_INTEN, ALLDEVS);
-       li_pcib_write16(LI_PCI_INTEN, ALLDEVS);
-}
-
-static __init void cobalt_init(void)
-{
-       /*
-        * On normal SMP PC this is used only with SMP, but we have to
-        * use it and set it up here to start the Cobalt clock
-        */
-       set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
-       setup_local_APIC();
-       printk(KERN_INFO "Local APIC Version %#x, ID %#x\n",
-               (unsigned int)apic_read(APIC_LVR),
-               (unsigned int)apic_read(APIC_ID));
-
-       set_fixmap(FIX_CO_CPU, CO_CPU_PHYS);
-       set_fixmap(FIX_CO_APIC, CO_APIC_PHYS);
-       printk(KERN_INFO "Cobalt Revision %#lx, APIC ID %#lx\n",
-               co_cpu_read(CO_CPU_REV), co_apic_read(CO_APIC_ID));
-
-       /* Enable Cobalt APIC being careful to NOT change the ID! */
-       co_apic_write(CO_APIC_ID, co_apic_read(CO_APIC_ID) | CO_APIC_ENABLE);
-
-       printk(KERN_INFO "Cobalt APIC enabled: ID reg %#lx\n",
-               co_apic_read(CO_APIC_ID));
-}
-
-void __init trap_init_hook(void)
-{
-       lithium_init();
-       cobalt_init();
-}
diff --git a/arch/x86/mach-visws/visws_apic.c b/arch/x86/mach-visws/visws_apic.c
deleted file mode 100644 (file)
index cef9cb1..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- *     Copyright (C) 1999 Bent Hagemark, Ingo Molnar
- *
- *  SGI Visual Workstation interrupt controller
- *
- *  The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
- *  which serves as the main interrupt controller in the system.  Non-legacy
- *  hardware in the system uses this controller directly.  Legacy devices
- *  are connected to the PIIX4 which in turn has its 8259(s) connected to
- *  a of the Cobalt APIC entry.
- *
- *  09/02/2000 - Updated for 2.4 by jbarnes@sgi.com
- *
- *  25/11/2002 - Updated for 2.5 by Andrey Panin <pazke@orbita1.ru>
- */
-
-#include <linux/kernel_stat.h>
-#include <linux/interrupt.h>
-#include <linux/init.h>
-
-#include <asm/io.h>
-#include <asm/apic.h>
-#include <asm/i8259.h>
-
-#include "cobalt.h"
-#include "irq_vectors.h"
-
-
-static DEFINE_SPINLOCK(cobalt_lock);
-
-/*
- * Set the given Cobalt APIC Redirection Table entry to point
- * to the given IDT vector/index.
- */
-static inline void co_apic_set(int entry, int irq)
-{
-       co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (irq + FIRST_EXTERNAL_VECTOR));
-       co_apic_write(CO_APIC_HI(entry), 0);
-}
-
-/*
- * Cobalt (IO)-APIC functions to handle PCI devices.
- */
-static inline int co_apic_ide0_hack(void)
-{
-       extern char visws_board_type;
-       extern char visws_board_rev;
-
-       if (visws_board_type == VISWS_320 && visws_board_rev == 5)
-               return 5;
-       return CO_APIC_IDE0;
-}
-
-static int is_co_apic(unsigned int irq)
-{
-       if (IS_CO_APIC(irq))
-               return CO_APIC(irq);
-
-       switch (irq) {
-               case 0: return CO_APIC_CPU;
-               case CO_IRQ_IDE0: return co_apic_ide0_hack();
-               case CO_IRQ_IDE1: return CO_APIC_IDE1;
-               default: return -1;
-       }
-}
-
-
-/*
- * This is the SGI Cobalt (IO-)APIC:
- */
-
-static void enable_cobalt_irq(unsigned int irq)
-{
-       co_apic_set(is_co_apic(irq), irq);
-}
-
-static void disable_cobalt_irq(unsigned int irq)
-{
-       int entry = is_co_apic(irq);
-
-       co_apic_write(CO_APIC_LO(entry), CO_APIC_MASK);
-       co_apic_read(CO_APIC_LO(entry));
-}
-
-/*
- * "irq" really just serves to identify the device.  Here is where we
- * map this to the Cobalt APIC entry where it's physically wired.
- * This is called via request_irq -> setup_irq -> irq_desc->startup()
- */
-static unsigned int startup_cobalt_irq(unsigned int irq)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&cobalt_lock, flags);
-       if ((irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING)))
-               irq_desc[irq].status &= ~(IRQ_DISABLED | IRQ_INPROGRESS | IRQ_WAITING);
-       enable_cobalt_irq(irq);
-       spin_unlock_irqrestore(&cobalt_lock, flags);
-       return 0;
-}
-
-static void ack_cobalt_irq(unsigned int irq)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&cobalt_lock, flags);
-       disable_cobalt_irq(irq);
-       apic_write(APIC_EOI, APIC_EIO_ACK);
-       spin_unlock_irqrestore(&cobalt_lock, flags);
-}
-
-static void end_cobalt_irq(unsigned int irq)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&cobalt_lock, flags);
-       if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
-               enable_cobalt_irq(irq);
-       spin_unlock_irqrestore(&cobalt_lock, flags);
-}
-
-static struct irq_chip cobalt_irq_type = {
-       .typename =     "Cobalt-APIC",
-       .startup =      startup_cobalt_irq,
-       .shutdown =     disable_cobalt_irq,
-       .enable =       enable_cobalt_irq,
-       .disable =      disable_cobalt_irq,
-       .ack =          ack_cobalt_irq,
-       .end =          end_cobalt_irq,
-};
-
-
-/*
- * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
- * -- not the manner expected by the code in i8259.c.
- *
- * there is a 'master' physical interrupt source that gets sent to
- * the CPU. But in the chipset there are various 'virtual' interrupts
- * waiting to be handled. We represent this to Linux through a 'master'
- * interrupt controller type, and through a special virtual interrupt-
- * controller. Device drivers only see the virtual interrupt sources.
- */
-static unsigned int startup_piix4_master_irq(unsigned int irq)
-{
-       init_8259A(0);
-
-       return startup_cobalt_irq(irq);
-}
-
-static void end_piix4_master_irq(unsigned int irq)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&cobalt_lock, flags);
-       enable_cobalt_irq(irq);
-       spin_unlock_irqrestore(&cobalt_lock, flags);
-}
-
-static struct irq_chip piix4_master_irq_type = {
-       .typename =     "PIIX4-master",
-       .startup =      startup_piix4_master_irq,
-       .ack =          ack_cobalt_irq,
-       .end =          end_piix4_master_irq,
-};
-
-
-static struct irq_chip piix4_virtual_irq_type = {
-       .typename =     "PIIX4-virtual",
-       .shutdown =     disable_8259A_irq,
-       .enable =       enable_8259A_irq,
-       .disable =      disable_8259A_irq,
-};
-
-
-/*
- * PIIX4-8259 master/virtual functions to handle interrupt requests
- * from legacy devices: floppy, parallel, serial, rtc.
- *
- * None of these get Cobalt APIC entries, neither do they have IDT
- * entries. These interrupts are purely virtual and distributed from
- * the 'master' interrupt source: CO_IRQ_8259.
- *
- * When the 8259 interrupts its handler figures out which of these
- * devices is interrupting and dispatches to its handler.
- *
- * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
- * enable_irq gets the right irq. This 'master' irq is never directly
- * manipulated by any driver.
- */
-static irqreturn_t piix4_master_intr(int irq, void *dev_id)
-{
-       int realirq;
-       irq_desc_t *desc;
-       unsigned long flags;
-
-       spin_lock_irqsave(&i8259A_lock, flags);
-
-       /* Find out what's interrupting in the PIIX4 master 8259 */
-       outb(0x0c, 0x20);               /* OCW3 Poll command */
-       realirq = inb(0x20);
-
-       /*
-        * Bit 7 == 0 means invalid/spurious
-        */
-       if (unlikely(!(realirq & 0x80)))
-               goto out_unlock;
-
-       realirq &= 7;
-
-       if (unlikely(realirq == 2)) {
-               outb(0x0c, 0xa0);
-               realirq = inb(0xa0);
-
-               if (unlikely(!(realirq & 0x80)))
-                       goto out_unlock;
-
-               realirq = (realirq & 7) + 8;
-       }
-
-       /* mask and ack interrupt */
-       cached_irq_mask |= 1 << realirq;
-       if (unlikely(realirq > 7)) {
-               inb(0xa1);
-               outb(cached_slave_mask, 0xa1);
-               outb(0x60 + (realirq & 7), 0xa0);
-               outb(0x60 + 2, 0x20);
-       } else {
-               inb(0x21);
-               outb(cached_master_mask, 0x21);
-               outb(0x60 + realirq, 0x20);
-       }
-
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-
-       desc = irq_desc + realirq;
-
-       /*
-        * handle this 'virtual interrupt' as a Cobalt one now.
-        */
-       kstat_cpu(smp_processor_id()).irqs[realirq]++;
-
-       if (likely(desc->action != NULL))
-               handle_IRQ_event(realirq, desc->action);
-
-       if (!(desc->status & IRQ_DISABLED))
-               enable_8259A_irq(realirq);
-
-       return IRQ_HANDLED;
-
-out_unlock:
-       spin_unlock_irqrestore(&i8259A_lock, flags);
-       return IRQ_NONE;
-}
-
-static struct irqaction master_action = {
-       .handler =      piix4_master_intr,
-       .name =         "PIIX4-8259",
-};
-
-static struct irqaction cascade_action = {
-       .handler =      no_action,
-       .name =         "cascade",
-};
-
-
-void init_VISWS_APIC_irqs(void)
-{
-       int i;
-
-       for (i = 0; i < CO_IRQ_APIC0 + CO_APIC_LAST + 1; i++) {
-               irq_desc[i].status = IRQ_DISABLED;
-               irq_desc[i].action = 0;
-               irq_desc[i].depth = 1;
-
-               if (i == 0) {
-                       irq_desc[i].chip = &cobalt_irq_type;
-               }
-               else if (i == CO_IRQ_IDE0) {
-                       irq_desc[i].chip = &cobalt_irq_type;
-               }
-               else if (i == CO_IRQ_IDE1) {
-                       irq_desc[i].chip = &cobalt_irq_type;
-               }
-               else if (i == CO_IRQ_8259) {
-                       irq_desc[i].chip = &piix4_master_irq_type;
-               }
-               else if (i < CO_IRQ_APIC0) {
-                       irq_desc[i].chip = &piix4_virtual_irq_type;
-               }
-               else if (IS_CO_APIC(i)) {
-                       irq_desc[i].chip = &cobalt_irq_type;
-               }
-       }
-
-       setup_irq(CO_IRQ_8259, &master_action);
-       setup_irq(2, &cascade_action);
-}
index 5ae5466..6bbdd63 100644 (file)
@@ -62,6 +62,7 @@ void __init time_init_hook(void)
 char *__init machine_specific_memory_setup(void)
 {
        char *who;
+       int new_nr;
 
        who = "NOT VOYAGER";
 
@@ -73,7 +74,7 @@ char *__init machine_specific_memory_setup(void)
 
                e820.nr_map = 0;
                for (i = 0; voyager_memory_detect(i, &addr, &length); i++) {
-                       add_memory_region(addr, length, E820_RAM);
+                       e820_add_region(addr, length, E820_RAM);
                }
                return who;
        } else if (voyager_level == 4) {
@@ -91,43 +92,17 @@ char *__init machine_specific_memory_setup(void)
                        tom = (boot_params.screen_info.ext_mem_k) << 10;
                }
                who = "Voyager-TOM";
-               add_memory_region(0, 0x9f000, E820_RAM);
+               e820_add_region(0, 0x9f000, E820_RAM);
                /* map from 1M to top of memory */
-               add_memory_region(1 * 1024 * 1024, tom - 1 * 1024 * 1024,
+               e820_add_region(1 * 1024 * 1024, tom - 1 * 1024 * 1024,
                                  E820_RAM);
                /* FIXME: Should check the ASICs to see if I need to
                 * take out the 8M window.  Just do it at the moment
                 * */
-               add_memory_region(8 * 1024 * 1024, 8 * 1024 * 1024,
+               e820_add_region(8 * 1024 * 1024, 8 * 1024 * 1024,
                                  E820_RESERVED);
                return who;
        }
 
-       who = "BIOS-e820";
-
-       /*
-        * Try to copy the BIOS-supplied E820-map.
-        *
-        * Otherwise fake a memory map; one section from 0k->640k,
-        * the next section from 1mb->appropriate_mem_k
-        */
-       sanitize_e820_map(boot_params.e820_map, &boot_params.e820_entries);
-       if (copy_e820_map(boot_params.e820_map, boot_params.e820_entries)
-           < 0) {
-               unsigned long mem_size;
-
-               /* compare results from other methods and take the greater */
-               if (boot_params.alt_mem_k < boot_params.screen_info.ext_mem_k) {
-                       mem_size = boot_params.screen_info.ext_mem_k;
-                       who = "BIOS-88";
-               } else {
-                       mem_size = boot_params.alt_mem_k;
-                       who = "BIOS-e801";
-               }
-
-               e820.nr_map = 0;
-               add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-               add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
-       }
-       return who;
+       return default_machine_specific_memory_setup();
 }
index 8acbf0c..8dedd01 100644 (file)
@@ -59,11 +59,6 @@ __u32 voyager_quad_processors = 0;
  * activity count.  Finally exported by i386_ksyms.c */
 static int voyager_extended_cpus = 1;
 
-/* Have we found an SMP box - used by time.c to do the profiling
-   interrupt for timeslicing; do not set to 1 until the per CPU timer
-   interrupt is active */
-int smp_found_config = 0;
-
 /* Used for the invalidate map that's also checked in the spinlock */
 static volatile unsigned long smp_invalidate_needed;
 
@@ -1137,15 +1132,6 @@ void flush_tlb_all(void)
        on_each_cpu(do_flush_tlb_all, 0, 1, 1);
 }
 
-/* used to set up the trampoline for other CPUs when the memory manager
- * is sorted out */
-void __init smp_alloc_memory(void)
-{
-       trampoline_base = alloc_bootmem_low_pages(PAGE_SIZE);
-       if (__pa(trampoline_base) >= 0x93000)
-               BUG();
-}
-
 /* send a reschedule CPI to one CPU by physical CPU number*/
 static void voyager_smp_send_reschedule(int cpu)
 {
index 04869e6..0054835 100644 (file)
@@ -16,8 +16,8 @@
 #include "reg_constant.h"
 #include "control_w.h"
 
-#define MAKE_REG(s,e,l,h) { l, h, \
-                            ((EXTENDED_Ebias+(e)) | ((SIGN_##s != 0)*0x8000)) }
+#define MAKE_REG(s, e, l, h) { l, h, \
+               ((EXTENDED_Ebias+(e)) | ((SIGN_##s != 0)*0x8000)) }
 
 FPU_REG const CONST_1 = MAKE_REG(POS, 0, 0x00000000, 0x80000000);
 #if 0
@@ -40,7 +40,7 @@ FPU_REG const CONST_PI2extra = MAKE_REG(NEG, -66,
 FPU_REG const CONST_Z = MAKE_REG(POS, EXP_UNDER, 0x0, 0x0);
 
 /* Only the sign and significand (and tag) are used in internal NaNs */
-/* The 80486 never generates one of these 
+/* The 80486 never generates one of these
 FPU_REG const CONST_SNAN = MAKE_REG(POS, EXP_OVER, 0x00000001, 0x80000000);
  */
 /* This is the real indefinite QNaN */
@@ -49,7 +49,7 @@ FPU_REG const CONST_QNaN = MAKE_REG(NEG, EXP_OVER, 0x00000000, 0xC0000000);
 /* Only the sign (and tag) is used in internal infinities */
 FPU_REG const CONST_INF = MAKE_REG(POS, EXP_OVER, 0x00000000, 0x80000000);
 
-static void fld_const(FPU_REG const *c, int adj, u_char tag)
+static void fld_const(FPU_REG const * c, int adj, u_char tag)
 {
        FPU_REG *st_new_ptr;
 
index b7b3e4c..9873716 100644 (file)
@@ -8,10 +8,16 @@ obj-$(CONFIG_X86_PTDUMP)      += dump_pagetables.o
 
 obj-$(CONFIG_HIGHMEM)          += highmem_32.o
 
+obj-$(CONFIG_MMIOTRACE_HOOKS)  += kmmio.o
+obj-$(CONFIG_MMIOTRACE)                += mmiotrace.o
+mmiotrace-y                    := pf_in.o mmio-mod.o
+obj-$(CONFIG_MMIOTRACE_TEST)   += testmmiotrace.o
+
 ifeq ($(CONFIG_X86_32),y)
 obj-$(CONFIG_NUMA)             += discontig_32.o
 else
 obj-$(CONFIG_NUMA)             += numa_64.o
 obj-$(CONFIG_K8_NUMA)          += k8topology_64.o
-obj-$(CONFIG_ACPI_NUMA)                += srat_64.o
 endif
+obj-$(CONFIG_ACPI_NUMA)                += srat_$(BITS).o
+
index 914ccf9..5dfef9f 100644 (file)
@@ -38,6 +38,7 @@
 #include <asm/setup.h>
 #include <asm/mmzone.h>
 #include <asm/bios_ebda.h>
+#include <asm/proto.h>
 
 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
 EXPORT_SYMBOL(node_data);
@@ -59,14 +60,14 @@ unsigned long node_end_pfn[MAX_NUMNODES] __read_mostly;
 /*
  * 4) physnode_map     - the mapping between a pfn and owning node
  * physnode_map keeps track of the physical memory layout of a generic
- * numa node on a 256Mb break (each element of the array will
- * represent 256Mb of memory and will be marked by the node id.  so,
+ * numa node on a 64Mb break (each element of the array will
+ * represent 64Mb of memory and will be marked by the node id.  so,
  * if the first gig is on node 0, and the second gig is on node 1
  * physnode_map will contain:
  *
- *     physnode_map[0-3] = 0;
- *     physnode_map[4-7] = 1;
- *     physnode_map[8- ] = -1;
+ *     physnode_map[0-15] = 0;
+ *     physnode_map[16-31] = 1;
+ *     physnode_map[32- ] = -1;
  */
 s8 physnode_map[MAX_ELEMENTS] __read_mostly = { [0 ... (MAX_ELEMENTS - 1)] = -1};
 EXPORT_SYMBOL(physnode_map);
@@ -75,15 +76,15 @@ void memory_present(int nid, unsigned long start, unsigned long end)
 {
        unsigned long pfn;
 
-       printk(KERN_INFO "Node: %d, start_pfn: %ld, end_pfn: %ld\n",
+       printk(KERN_INFO "Node: %d, start_pfn: %lx, end_pfn: %lx\n",
                        nid, start, end);
        printk(KERN_DEBUG "  Setting physnode_map array to node %d for pfns:\n", nid);
        printk(KERN_DEBUG "  ");
        for (pfn = start; pfn < end; pfn += PAGES_PER_ELEMENT) {
                physnode_map[pfn / PAGES_PER_ELEMENT] = nid;
-               printk("%ld ", pfn);
+               printk(KERN_CONT "%lx ", pfn);
        }
-       printk("\n");
+       printk(KERN_CONT "\n");
 }
 
 unsigned long node_memmap_size_bytes(int nid, unsigned long start_pfn,
@@ -99,7 +100,6 @@ unsigned long node_memmap_size_bytes(int nid, unsigned long start_pfn,
 #endif
 
 extern unsigned long find_max_low_pfn(void);
-extern void add_one_highpage_init(struct page *, int, int);
 extern unsigned long highend_pfn, highstart_pfn;
 
 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
@@ -117,13 +117,13 @@ static unsigned long kva_pages;
  */
 int __init get_memcfg_numa_flat(void)
 {
-       printk("NUMA - single node, flat memory mode\n");
+       printk(KERN_DEBUG "NUMA - single node, flat memory mode\n");
 
-       /* Run the memory configuration and find the top of memory. */
-       propagate_e820_map();
        node_start_pfn[0] = 0;
        node_end_pfn[0] = max_pfn;
+       e820_register_active_regions(0, 0, max_pfn);
        memory_present(0, 0, max_pfn);
+       node_remap_size[0] = node_memmap_size_bytes(0, 0, max_pfn);
 
         /* Indicate there is one node available. */
        nodes_clear(node_online_map);
@@ -156,24 +156,32 @@ static void __init propagate_e820_map_node(int nid)
  */
 static void __init allocate_pgdat(int nid)
 {
-       if (nid && node_has_online_mem(nid))
+       char buf[16];
+
+       if (node_has_online_mem(nid) && node_remap_start_vaddr[nid])
                NODE_DATA(nid) = (pg_data_t *)node_remap_start_vaddr[nid];
        else {
-               NODE_DATA(nid) = (pg_data_t *)(pfn_to_kaddr(min_low_pfn));
-               min_low_pfn += PFN_UP(sizeof(pg_data_t));
+               unsigned long pgdat_phys;
+               pgdat_phys = find_e820_area(min_low_pfn<<PAGE_SHIFT,
+                                max_pfn_mapped<<PAGE_SHIFT,
+                                sizeof(pg_data_t),
+                                PAGE_SIZE);
+               NODE_DATA(nid) = (pg_data_t *)(pfn_to_kaddr(pgdat_phys>>PAGE_SHIFT));
+               memset(buf, 0, sizeof(buf));
+               sprintf(buf, "NODE_DATA %d",  nid);
+               reserve_early(pgdat_phys, pgdat_phys + sizeof(pg_data_t), buf);
        }
+       printk(KERN_DEBUG "allocate_pgdat: node %d NODE_DATA %08lx\n",
+               nid, (unsigned long)NODE_DATA(nid));
 }
 
-#ifdef CONFIG_DISCONTIGMEM
 /*
- * In the discontig memory model, a portion of the kernel virtual area (KVA)
- * is reserved and portions of nodes are mapped using it. This is to allow
- * node-local memory to be allocated for structures that would normally require
- * ZONE_NORMAL. The memory is allocated with alloc_remap() and callers
- * should be prepared to allocate from the bootmem allocator instead. This KVA
- * mechanism is incompatible with SPARSEMEM as it makes assumptions about the
- * layout of memory that are broken if alloc_remap() succeeds for some of the
- * map and fails for others
+ * In the DISCONTIGMEM and SPARSEMEM memory model, a portion of the kernel
+ * virtual address space (KVA) is reserved and portions of nodes are mapped
+ * using it. This is to allow node-local memory to be allocated for
+ * structures that would normally require ZONE_NORMAL. The memory is
+ * allocated with alloc_remap() and callers should be prepared to allocate
+ * from the bootmem allocator instead.
  */
 static unsigned long node_remap_start_pfn[MAX_NUMNODES];
 static void *node_remap_end_vaddr[MAX_NUMNODES];
@@ -195,15 +203,19 @@ void *alloc_remap(int nid, unsigned long size)
        return allocation;
 }
 
-void __init remap_numa_kva(void)
+static void __init remap_numa_kva(void)
 {
        void *vaddr;
        unsigned long pfn;
        int node;
 
        for_each_online_node(node) {
+               printk(KERN_DEBUG "remap_numa_kva: node %d\n", node);
                for (pfn=0; pfn < node_remap_size[node]; pfn += PTRS_PER_PTE) {
                        vaddr = node_remap_start_vaddr[node]+(pfn<<PAGE_SHIFT);
+                       printk(KERN_DEBUG "remap_numa_kva: %08lx to pfn %08lx\n",
+                               (unsigned long)vaddr,
+                               node_remap_start_pfn[node] + pfn);
                        set_pmd_pfn((ulong) vaddr, 
                                node_remap_start_pfn[node] + pfn, 
                                PAGE_KERNEL_LARGE);
@@ -215,17 +227,21 @@ static unsigned long calculate_numa_remap_pages(void)
 {
        int nid;
        unsigned long size, reserve_pages = 0;
-       unsigned long pfn;
 
        for_each_online_node(nid) {
-               unsigned old_end_pfn = node_end_pfn[nid];
+               u64 node_kva_target;
+               u64 node_kva_final;
 
                /*
                 * The acpi/srat node info can show hot-add memroy zones
                 * where memory could be added but not currently present.
                 */
+               printk(KERN_DEBUG "node %d pfn: [%lx - %lx]\n",
+                       nid, node_start_pfn[nid], node_end_pfn[nid]);
                if (node_start_pfn[nid] > max_pfn)
                        continue;
+               if (!node_end_pfn[nid])
+                       continue;
                if (node_end_pfn[nid] > max_pfn)
                        node_end_pfn[nid] = max_pfn;
 
@@ -237,41 +253,48 @@ static unsigned long calculate_numa_remap_pages(void)
                /* now the roundup is correct, convert to PAGE_SIZE pages */
                size = size * PTRS_PER_PTE;
 
-               /*
-                * Validate the region we are allocating only contains valid
-                * pages.
-                */
-               for (pfn = node_end_pfn[nid] - size;
-                    pfn < node_end_pfn[nid]; pfn++)
-                       if (!page_is_ram(pfn))
-                               break;
-
-               if (pfn != node_end_pfn[nid])
-                       size = 0;
+               node_kva_target = round_down(node_end_pfn[nid] - size,
+                                                PTRS_PER_PTE);
+               node_kva_target <<= PAGE_SHIFT;
+               do {
+                       node_kva_final = find_e820_area(node_kva_target,
+                                       ((u64)node_end_pfn[nid])<<PAGE_SHIFT,
+                                               ((u64)size)<<PAGE_SHIFT,
+                                               LARGE_PAGE_BYTES);
+                       node_kva_target -= LARGE_PAGE_BYTES;
+               } while (node_kva_final == -1ULL &&
+                        (node_kva_target>>PAGE_SHIFT) > (node_start_pfn[nid]));
+
+               if (node_kva_final == -1ULL)
+                       panic("Can not get kva ram\n");
 
-               printk("Reserving %ld pages of KVA for lmem_map of node %d\n",
-                               size, nid);
                node_remap_size[nid] = size;
                node_remap_offset[nid] = reserve_pages;
                reserve_pages += size;
-               printk("Shrinking node %d from %ld pages to %ld pages\n",
-                       nid, node_end_pfn[nid], node_end_pfn[nid] - size);
-
-               if (node_end_pfn[nid] & (PTRS_PER_PTE-1)) {
-                       /*
-                        * Align node_end_pfn[] and node_remap_start_pfn[] to
-                        * pmd boundary. remap_numa_kva will barf otherwise.
-                        */
-                       printk("Shrinking node %d further by %ld pages for proper alignment\n",
-                               nid, node_end_pfn[nid] & (PTRS_PER_PTE-1));
-                       size +=  node_end_pfn[nid] & (PTRS_PER_PTE-1);
-               }
+               printk(KERN_DEBUG "Reserving %ld pages of KVA for lmem_map of"
+                                 " node %d at %llx\n",
+                               size, nid, node_kva_final>>PAGE_SHIFT);
+
+               /*
+                *  prevent kva address below max_low_pfn want it on system
+                *  with less memory later.
+                *  layout will be: KVA address , KVA RAM
+                *
+                *  we are supposed to only record the one less then max_low_pfn
+                *  but we could have some hole in high memory, and it will only
+                *  check page_is_ram(pfn) && !page_is_reserved_early(pfn) to decide
+                *  to use it as free.
+                *  So reserve_early here, hope we don't run out of that array
+                */
+               reserve_early(node_kva_final,
+                             node_kva_final+(((u64)size)<<PAGE_SHIFT),
+                             "KVA RAM");
 
-               node_end_pfn[nid] -= size;
-               node_remap_start_pfn[nid] = node_end_pfn[nid];
-               shrink_active_range(nid, old_end_pfn, node_end_pfn[nid]);
+               node_remap_start_pfn[nid] = node_kva_final>>PAGE_SHIFT;
+               remove_active_range(nid, node_remap_start_pfn[nid],
+                                        node_remap_start_pfn[nid] + size);
        }
-       printk("Reserving total of %ld pages for numa KVA remap\n",
+       printk(KERN_INFO "Reserving total of %lx pages for numa KVA remap\n",
                        reserve_pages);
        return reserve_pages;
 }
@@ -285,37 +308,16 @@ static void init_remap_allocator(int nid)
        node_remap_alloc_vaddr[nid] = node_remap_start_vaddr[nid] +
                ALIGN(sizeof(pg_data_t), PAGE_SIZE);
 
-       printk ("node %d will remap to vaddr %08lx - %08lx\n", nid,
+       printk(KERN_DEBUG "node %d will remap to vaddr %08lx - %08lx\n", nid,
                (ulong) node_remap_start_vaddr[nid],
-               (ulong) pfn_to_kaddr(highstart_pfn
-                  + node_remap_offset[nid] + node_remap_size[nid]));
-}
-#else
-void *alloc_remap(int nid, unsigned long size)
-{
-       return NULL;
-}
-
-static unsigned long calculate_numa_remap_pages(void)
-{
-       return 0;
-}
-
-static void init_remap_allocator(int nid)
-{
-}
-
-void __init remap_numa_kva(void)
-{
+               (ulong) node_remap_end_vaddr[nid]);
 }
-#endif /* CONFIG_DISCONTIGMEM */
 
-extern void setup_bootmem_allocator(void);
-unsigned long __init setup_memory(void)
+void __init initmem_init(unsigned long start_pfn,
+                                 unsigned long end_pfn)
 {
        int nid;
-       unsigned long system_start_pfn, system_max_low_pfn;
-       unsigned long wasted_pages;
+       long kva_target_pfn;
 
        /*
         * When mapping a NUMA machine we allocate the node_mem_map arrays
@@ -324,109 +326,77 @@ unsigned long __init setup_memory(void)
         * this space and use it to adjust the boundary between ZONE_NORMAL
         * and ZONE_HIGHMEM.
         */
-       get_memcfg_numa();
 
-       kva_pages = calculate_numa_remap_pages();
+       get_memcfg_numa();
 
-       /* partially used pages are not usable - thus round upwards */
-       system_start_pfn = min_low_pfn = PFN_UP(init_pg_tables_end);
+       kva_pages = round_up(calculate_numa_remap_pages(), PTRS_PER_PTE);
 
-       kva_start_pfn = find_max_low_pfn() - kva_pages;
+       kva_target_pfn = round_down(max_low_pfn - kva_pages, PTRS_PER_PTE);
+       do {
+               kva_start_pfn = find_e820_area(kva_target_pfn<<PAGE_SHIFT,
+                                       max_low_pfn<<PAGE_SHIFT,
+                                       kva_pages<<PAGE_SHIFT,
+                                       PTRS_PER_PTE<<PAGE_SHIFT) >> PAGE_SHIFT;
+               kva_target_pfn -= PTRS_PER_PTE;
+       } while (kva_start_pfn == -1UL && kva_target_pfn > min_low_pfn);
 
-#ifdef CONFIG_BLK_DEV_INITRD
-       /* Numa kva area is below the initrd */
-       if (initrd_start)
-               kva_start_pfn = PFN_DOWN(initrd_start - PAGE_OFFSET)
-                       - kva_pages;
-#endif
+       if (kva_start_pfn == -1UL)
+               panic("Can not get kva space\n");
 
-       /*
-        * We waste pages past at the end of the KVA for no good reason other
-        * than how it is located. This is bad.
-        */
-       wasted_pages = kva_start_pfn & (PTRS_PER_PTE-1);
-       kva_start_pfn -= wasted_pages;
-       kva_pages += wasted_pages;
-
-       system_max_low_pfn = max_low_pfn = find_max_low_pfn();
-       printk("kva_start_pfn ~ %ld find_max_low_pfn() ~ %ld\n",
+       printk(KERN_INFO "kva_start_pfn ~ %lx max_low_pfn ~ %lx\n",
                kva_start_pfn, max_low_pfn);
-       printk("max_pfn = %ld\n", max_pfn);
+       printk(KERN_INFO "max_pfn = %lx\n", max_pfn);
+
+       /* avoid clash with initrd */
+       reserve_early(kva_start_pfn<<PAGE_SHIFT,
+                     (kva_start_pfn + kva_pages)<<PAGE_SHIFT,
+                    "KVA PG");
 #ifdef CONFIG_HIGHMEM
        highstart_pfn = highend_pfn = max_pfn;
-       if (max_pfn > system_max_low_pfn)
-               highstart_pfn = system_max_low_pfn;
+       if (max_pfn > max_low_pfn)
+               highstart_pfn = max_low_pfn;
        printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
               pages_to_mb(highend_pfn - highstart_pfn));
        num_physpages = highend_pfn;
        high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
 #else
-       num_physpages = system_max_low_pfn;
-       high_memory = (void *) __va(system_max_low_pfn * PAGE_SIZE - 1) + 1;
+       num_physpages = max_low_pfn;
+       high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
 #endif
        printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
-                       pages_to_mb(system_max_low_pfn));
-       printk("min_low_pfn = %ld, max_low_pfn = %ld, highstart_pfn = %ld\n", 
-                       min_low_pfn, max_low_pfn, highstart_pfn);
+                       pages_to_mb(max_low_pfn));
+       printk(KERN_DEBUG "max_low_pfn = %lx, highstart_pfn = %lx\n",
+                       max_low_pfn, highstart_pfn);
 
-       printk("Low memory ends at vaddr %08lx\n",
+       printk(KERN_DEBUG "Low memory ends at vaddr %08lx\n",
                        (ulong) pfn_to_kaddr(max_low_pfn));
        for_each_online_node(nid) {
                init_remap_allocator(nid);
 
                allocate_pgdat(nid);
        }
-       printk("High memory starts at vaddr %08lx\n",
+       remap_numa_kva();
+
+       printk(KERN_DEBUG "High memory starts at vaddr %08lx\n",
                        (ulong) pfn_to_kaddr(highstart_pfn));
        for_each_online_node(nid)
                propagate_e820_map_node(nid);
 
-       memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
+       for_each_online_node(nid)
+               memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
+
        NODE_DATA(0)->bdata = &node0_bdata;
        setup_bootmem_allocator();
-       return max_low_pfn;
-}
-
-void __init numa_kva_reserve(void)
-{
-       if (kva_pages)
-               reserve_bootmem(PFN_PHYS(kva_start_pfn), PFN_PHYS(kva_pages),
-                               BOOTMEM_DEFAULT);
 }
 
-void __init zone_sizes_init(void)
-{
-       int nid;
-       unsigned long max_zone_pfns[MAX_NR_ZONES];
-       memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
-       max_zone_pfns[ZONE_DMA] =
-               virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
-       max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
-#ifdef CONFIG_HIGHMEM
-       max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
-#endif
-
-       /* If SRAT has not registered memory, register it now */
-       if (find_max_pfn_with_active_regions() == 0) {
-               for_each_online_node(nid) {
-                       if (node_has_online_mem(nid))
-                               add_active_range(nid, node_start_pfn[nid],
-                                                       node_end_pfn[nid]);
-               }
-       }
-
-       free_area_init_nodes(max_zone_pfns);
-       return;
-}
-
-void __init set_highmem_pages_init(int bad_ppro) 
+void __init set_highmem_pages_init(void)
 {
 #ifdef CONFIG_HIGHMEM
        struct zone *zone;
-       struct page *page;
+       int nid;
 
        for_each_zone(zone) {
-               unsigned long node_pfn, zone_start_pfn, zone_end_pfn;
+               unsigned long zone_start_pfn, zone_end_pfn;
 
                if (!is_highmem(zone))
                        continue;
@@ -434,16 +404,12 @@ void __init set_highmem_pages_init(int bad_ppro)
                zone_start_pfn = zone->zone_start_pfn;
                zone_end_pfn = zone_start_pfn + zone->spanned_pages;
 
-               printk("Initializing %s for node %d (%08lx:%08lx)\n",
-                               zone->name, zone_to_nid(zone),
-                               zone_start_pfn, zone_end_pfn);
+               nid = zone_to_nid(zone);
+               printk(KERN_INFO "Initializing %s for node %d (%08lx:%08lx)\n",
+                               zone->name, nid, zone_start_pfn, zone_end_pfn);
 
-               for (node_pfn = zone_start_pfn; node_pfn < zone_end_pfn; node_pfn++) {
-                       if (!pfn_valid(node_pfn))
-                               continue;
-                       page = pfn_to_page(node_pfn);
-                       add_one_highpage_init(page, node_pfn, bad_ppro);
-               }
+               add_highpages_with_active_regions(nid, zone_start_pfn,
+                                zone_end_pfn);
        }
        totalram_pages += totalhigh_pages;
 #endif
@@ -476,3 +442,4 @@ int memory_add_physaddr_to_nid(u64 addr)
 
 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
 #endif
+
index 2c24bea..0bb0cae 100644 (file)
@@ -42,7 +42,7 @@ static struct addr_marker address_markers[] = {
        { 0, "User Space" },
 #ifdef CONFIG_X86_64
        { 0x8000000000000000UL, "Kernel Space" },
-       { 0xffff810000000000UL, "Low Kernel Mapping" },
+       { PAGE_OFFSET,          "Low Kernel Mapping" },
        { VMALLOC_START,        "vmalloc() Area" },
        { VMEMMAP_START,        "Vmemmap" },
        { __START_KERNEL_map,   "High Kernel Mapping" },
index 8bcb6f4..455f3fe 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/ptrace.h>
+#include <linux/mmiotrace.h>
 #include <linux/mman.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
 #define PF_RSVD                (1<<3)
 #define PF_INSTR       (1<<4)
 
+static inline int kmmio_fault(struct pt_regs *regs, unsigned long addr)
+{
+#ifdef CONFIG_MMIOTRACE_HOOKS
+       if (unlikely(is_kmmio_active()))
+               if (kmmio_handler(regs, addr) == 1)
+                       return -1;
+#endif
+       return 0;
+}
+
 static inline int notify_page_fault(struct pt_regs *regs)
 {
 #ifdef CONFIG_KPROBES
        int ret = 0;
 
        /* kprobe_running() needs smp_processor_id() */
-#ifdef CONFIG_X86_32
        if (!user_mode_vm(regs)) {
-#else
-       if (!user_mode(regs)) {
-#endif
                preempt_disable();
                if (kprobe_running() && kprobe_fault_handler(regs, 14))
                        ret = 1;
@@ -396,11 +403,7 @@ static void show_fault_oops(struct pt_regs *regs, unsigned long error_code,
                printk(KERN_CONT "NULL pointer dereference");
        else
                printk(KERN_CONT "paging request");
-#ifdef CONFIG_X86_32
-       printk(KERN_CONT " at %08lx\n", address);
-#else
-       printk(KERN_CONT " at %016lx\n", address);
-#endif
+       printk(KERN_CONT " at %p\n", (void *) address);
        printk(KERN_ALERT "IP:");
        printk_address(regs->ip, 1);
        dump_pagetable(address);
@@ -606,6 +609,8 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
 
        if (notify_page_fault(regs))
                return;
+       if (unlikely(kmmio_fault(regs, address)))
+               return;
 
        /*
         * We fault-in kernel-space virtual memory on-demand. The
@@ -800,14 +805,10 @@ bad_area_nosemaphore:
                if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
                    printk_ratelimit()) {
                        printk(
-#ifdef CONFIG_X86_32
-                       "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
-#else
-                       "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
-#endif
+                       "%s%s[%d]: segfault at %lx ip %p sp %p error %lx",
                        task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
-                       tsk->comm, task_pid_nr(tsk), address, regs->ip,
-                       regs->sp, error_code);
+                       tsk->comm, task_pid_nr(tsk), address,
+                       (void *) regs->ip, (void *) regs->sp, error_code);
                        print_vma_addr(" in ", regs->ip);
                        printk("\n");
                }
@@ -915,14 +916,7 @@ LIST_HEAD(pgd_list);
 void vmalloc_sync_all(void)
 {
 #ifdef CONFIG_X86_32
-       /*
-        * Note that races in the updates of insync and start aren't
-        * problematic: insync can only get set bits added, and updates to
-        * start are only improving performance (without affecting correctness
-        * if undone).
-        */
-       static DECLARE_BITMAP(insync, PTRS_PER_PGD);
-       static unsigned long start = TASK_SIZE;
+       unsigned long start = VMALLOC_START & PGDIR_MASK;
        unsigned long address;
 
        if (SHARED_KERNEL_PMD)
@@ -930,56 +924,38 @@ void vmalloc_sync_all(void)
 
        BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
        for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
-               if (!test_bit(pgd_index(address), insync)) {
-                       unsigned long flags;
-                       struct page *page;
-
-                       spin_lock_irqsave(&pgd_lock, flags);
-                       list_for_each_entry(page, &pgd_list, lru) {
-                               if (!vmalloc_sync_one(page_address(page),
-                                                     address))
-                                       break;
-                       }
-                       spin_unlock_irqrestore(&pgd_lock, flags);
-                       if (!page)
-                               set_bit(pgd_index(address), insync);
+               unsigned long flags;
+               struct page *page;
+
+               spin_lock_irqsave(&pgd_lock, flags);
+               list_for_each_entry(page, &pgd_list, lru) {
+                       if (!vmalloc_sync_one(page_address(page),
+                                             address))
+                               break;
                }
-               if (address == start && test_bit(pgd_index(address), insync))
-                       start = address + PGDIR_SIZE;
+               spin_unlock_irqrestore(&pgd_lock, flags);
        }
 #else /* CONFIG_X86_64 */
-       /*
-        * Note that races in the updates of insync and start aren't
-        * problematic: insync can only get set bits added, and updates to
-        * start are only improving performance (without affecting correctness
-        * if undone).
-        */
-       static DECLARE_BITMAP(insync, PTRS_PER_PGD);
-       static unsigned long start = VMALLOC_START & PGDIR_MASK;
+       unsigned long start = VMALLOC_START & PGDIR_MASK;
        unsigned long address;
 
        for (address = start; address <= VMALLOC_END; address += PGDIR_SIZE) {
-               if (!test_bit(pgd_index(address), insync)) {
-                       const pgd_t *pgd_ref = pgd_offset_k(address);
-                       unsigned long flags;
-                       struct page *page;
-
-                       if (pgd_none(*pgd_ref))
-                               continue;
-                       spin_lock_irqsave(&pgd_lock, flags);
-                       list_for_each_entry(page, &pgd_list, lru) {
-                               pgd_t *pgd;
-                               pgd = (pgd_t *)page_address(page) + pgd_index(address);
-                               if (pgd_none(*pgd))
-                                       set_pgd(pgd, *pgd_ref);
-                               else
-                                       BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
-                       }
-                       spin_unlock_irqrestore(&pgd_lock, flags);
-                       set_bit(pgd_index(address), insync);
+               const pgd_t *pgd_ref = pgd_offset_k(address);
+               unsigned long flags;
+               struct page *page;
+
+               if (pgd_none(*pgd_ref))
+                       continue;
+               spin_lock_irqsave(&pgd_lock, flags);
+               list_for_each_entry(page, &pgd_list, lru) {
+                       pgd_t *pgd;
+                       pgd = (pgd_t *)page_address(page) + pgd_index(address);
+                       if (pgd_none(*pgd))
+                               set_pgd(pgd, *pgd_ref);
+                       else
+                               BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
                }
-               if (address == start)
-                       start = address + PGDIR_SIZE;
+               spin_unlock_irqrestore(&pgd_lock, flags);
        }
 #endif
 }
index ec30d10..9689a51 100644 (file)
@@ -50,6 +50,7 @@
 
 unsigned int __VMALLOC_RESERVE = 128 << 20;
 
+unsigned long max_low_pfn_mapped;
 unsigned long max_pfn_mapped;
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
@@ -57,6 +58,27 @@ unsigned long highstart_pfn, highend_pfn;
 
 static noinline int do_test_wp_bit(void);
 
+
+static unsigned long __initdata table_start;
+static unsigned long __meminitdata table_end;
+static unsigned long __meminitdata table_top;
+
+static int __initdata after_init_bootmem;
+
+static __init void *alloc_low_page(unsigned long *phys)
+{
+       unsigned long pfn = table_end++;
+       void *adr;
+
+       if (pfn >= table_top)
+               panic("alloc_low_page: ran out of memory");
+
+       adr = __va(pfn * PAGE_SIZE);
+       memset(adr, 0, PAGE_SIZE);
+       *phys  = pfn * PAGE_SIZE;
+       return adr;
+}
+
 /*
  * Creates a middle page table and puts a pointer to it in the
  * given global directory entry. This only returns the gd entry
@@ -68,9 +90,12 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
        pmd_t *pmd_table;
 
 #ifdef CONFIG_X86_PAE
+       unsigned long phys;
        if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-               pmd_table = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE);
-
+               if (after_init_bootmem)
+                       pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
+               else
+                       pmd_table = (pmd_t *)alloc_low_page(&phys);
                paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
                set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
                pud = pud_offset(pgd, 0);
@@ -92,12 +117,16 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
        if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
                pte_t *page_table = NULL;
 
+               if (after_init_bootmem) {
 #ifdef CONFIG_DEBUG_PAGEALLOC
-               page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
+                       page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
-               if (!page_table) {
-                       page_table =
+                       if (!page_table)
+                               page_table =
                                (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
+               } else {
+                       unsigned long phys;
+                       page_table = (pte_t *)alloc_low_page(&phys);
                }
 
                paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
@@ -155,38 +184,44 @@ static inline int is_kernel_text(unsigned long addr)
  * of max_low_pfn pages, by creating page tables starting from address
  * PAGE_OFFSET:
  */
-static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
+static void __init kernel_physical_mapping_init(pgd_t *pgd_base,
+                                               unsigned long start_pfn,
+                                               unsigned long end_pfn,
+                                               int use_pse)
 {
        int pgd_idx, pmd_idx, pte_ofs;
        unsigned long pfn;
        pgd_t *pgd;
        pmd_t *pmd;
        pte_t *pte;
+       unsigned pages_2m = 0, pages_4k = 0;
 
-       pgd_idx = pgd_index(PAGE_OFFSET);
-       pgd = pgd_base + pgd_idx;
-       pfn = 0;
+       if (!cpu_has_pse)
+               use_pse = 0;
 
+       pfn = start_pfn;
+       pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
+       pgd = pgd_base + pgd_idx;
        for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
                pmd = one_md_table_init(pgd);
-               if (pfn >= max_low_pfn)
-                       continue;
 
-               for (pmd_idx = 0;
-                    pmd_idx < PTRS_PER_PMD && pfn < max_low_pfn;
+               if (pfn >= end_pfn)
+                       continue;
+#ifdef CONFIG_X86_PAE
+               pmd_idx = pmd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
+               pmd += pmd_idx;
+#else
+               pmd_idx = 0;
+#endif
+               for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
                     pmd++, pmd_idx++) {
                        unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
 
                        /*
                         * Map with big pages if possible, otherwise
                         * create normal page tables:
-                        *
-                        * Don't use a large page for the first 2/4MB of memory
-                        * because there are often fixed size MTRRs in there
-                        * and overlapping MTRRs into large pages can cause
-                        * slowdowns.
                         */
-                       if (cpu_has_pse && !(pgd_idx == 0 && pmd_idx == 0)) {
+                       if (use_pse) {
                                unsigned int addr2;
                                pgprot_t prot = PAGE_KERNEL_LARGE;
 
@@ -197,34 +232,30 @@ static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
                                    is_kernel_text(addr2))
                                        prot = PAGE_KERNEL_LARGE_EXEC;
 
+                               pages_2m++;
                                set_pmd(pmd, pfn_pmd(pfn, prot));
 
                                pfn += PTRS_PER_PTE;
-                               max_pfn_mapped = pfn;
                                continue;
                        }
                        pte = one_page_table_init(pmd);
 
-                       for (pte_ofs = 0;
-                            pte_ofs < PTRS_PER_PTE && pfn < max_low_pfn;
+                       pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
+                       pte += pte_ofs;
+                       for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
                             pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
                                pgprot_t prot = PAGE_KERNEL;
 
                                if (is_kernel_text(addr))
                                        prot = PAGE_KERNEL_EXEC;
 
+                               pages_4k++;
                                set_pte(pte, pfn_pte(pfn, prot));
                        }
-                       max_pfn_mapped = pfn;
                }
        }
-}
-
-static inline int page_kills_ppro(unsigned long pagenr)
-{
-       if (pagenr >= 0x70000 && pagenr <= 0x7003F)
-               return 1;
-       return 0;
+       update_page_count(PG_LEVEL_2M, pages_2m);
+       update_page_count(PG_LEVEL_4K, pages_4k);
 }
 
 /*
@@ -287,29 +318,62 @@ static void __init permanent_kmaps_init(pgd_t *pgd_base)
        pkmap_page_table = pte;
 }
 
-void __init add_one_highpage_init(struct page *page, int pfn, int bad_ppro)
+static void __init add_one_highpage_init(struct page *page, int pfn)
 {
-       if (page_is_ram(pfn) && !(bad_ppro && page_kills_ppro(pfn))) {
-               ClearPageReserved(page);
-               init_page_count(page);
-               __free_page(page);
-               totalhigh_pages++;
-       } else
-               SetPageReserved(page);
+       ClearPageReserved(page);
+       init_page_count(page);
+       __free_page(page);
+       totalhigh_pages++;
 }
 
-#ifndef CONFIG_NUMA
-static void __init set_highmem_pages_init(int bad_ppro)
+struct add_highpages_data {
+       unsigned long start_pfn;
+       unsigned long end_pfn;
+};
+
+static int __init add_highpages_work_fn(unsigned long start_pfn,
+                                        unsigned long end_pfn, void *datax)
 {
-       int pfn;
+       int node_pfn;
+       struct page *page;
+       unsigned long final_start_pfn, final_end_pfn;
+       struct add_highpages_data *data;
 
-       for (pfn = highstart_pfn; pfn < highend_pfn; pfn++) {
-               /*
-                * Holes under sparsemem might not have no mem_map[]:
-                */
-               if (pfn_valid(pfn))
-                       add_one_highpage_init(pfn_to_page(pfn), pfn, bad_ppro);
+       data = (struct add_highpages_data *)datax;
+
+       final_start_pfn = max(start_pfn, data->start_pfn);
+       final_end_pfn = min(end_pfn, data->end_pfn);
+       if (final_start_pfn >= final_end_pfn)
+               return 0;
+
+       for (node_pfn = final_start_pfn; node_pfn < final_end_pfn;
+            node_pfn++) {
+               if (!pfn_valid(node_pfn))
+                       continue;
+               page = pfn_to_page(node_pfn);
+               add_one_highpage_init(page, node_pfn);
        }
+
+       return 0;
+
+}
+
+void __init add_highpages_with_active_regions(int nid, unsigned long start_pfn,
+                                             unsigned long end_pfn)
+{
+       struct add_highpages_data data;
+
+       data.start_pfn = start_pfn;
+       data.end_pfn = end_pfn;
+
+       work_with_active_regions(nid, add_highpages_work_fn, &data);
+}
+
+#ifndef CONFIG_NUMA
+static void __init set_highmem_pages_init(void)
+{
+       add_highpages_with_active_regions(0, highstart_pfn, highend_pfn);
+
        totalram_pages += totalhigh_pages;
 }
 #endif /* !CONFIG_NUMA */
@@ -317,14 +381,9 @@ static void __init set_highmem_pages_init(int bad_ppro)
 #else
 # define kmap_init()                           do { } while (0)
 # define permanent_kmaps_init(pgd_base)                do { } while (0)
-# define set_highmem_pages_init(bad_ppro)      do { } while (0)
+# define set_highmem_pages_init()      do { } while (0)
 #endif /* CONFIG_HIGHMEM */
 
-pteval_t __PAGE_KERNEL = _PAGE_KERNEL;
-EXPORT_SYMBOL(__PAGE_KERNEL);
-
-pteval_t __PAGE_KERNEL_EXEC = _PAGE_KERNEL_EXEC;
-
 void __init native_pagetable_setup_start(pgd_t *base)
 {
        unsigned long pfn, va;
@@ -380,27 +439,10 @@ void __init native_pagetable_setup_done(pgd_t *base)
  * be partially populated, and so it avoids stomping on any existing
  * mappings.
  */
-static void __init pagetable_init(void)
+static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base)
 {
-       pgd_t *pgd_base = swapper_pg_dir;
        unsigned long vaddr, end;
 
-       paravirt_pagetable_setup_start(pgd_base);
-
-       /* Enable PSE if available */
-       if (cpu_has_pse)
-               set_in_cr4(X86_CR4_PSE);
-
-       /* Enable PGE if available */
-       if (cpu_has_pge) {
-               set_in_cr4(X86_CR4_PGE);
-               __PAGE_KERNEL |= _PAGE_GLOBAL;
-               __PAGE_KERNEL_EXEC |= _PAGE_GLOBAL;
-       }
-
-       kernel_physical_mapping_init(pgd_base);
-       remap_numa_kva();
-
        /*
         * Fixed mappings, only the page table structure has to be
         * created - mappings will be set by set_fixmap():
@@ -410,6 +452,13 @@ static void __init pagetable_init(void)
        end = (FIXADDR_TOP + PMD_SIZE - 1) & PMD_MASK;
        page_table_range_init(vaddr, end, pgd_base);
        early_ioremap_reset();
+}
+
+static void __init pagetable_init(void)
+{
+       pgd_t *pgd_base = swapper_pg_dir;
+
+       paravirt_pagetable_setup_start(pgd_base);
 
        permanent_kmaps_init(pgd_base);
 
@@ -456,7 +505,7 @@ void zap_low_mappings(void)
 
 int nx_enabled;
 
-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_NX;
+pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
 EXPORT_SYMBOL_GPL(__supported_pte_mask);
 
 #ifdef CONFIG_X86_PAE
@@ -509,27 +558,318 @@ static void __init set_nx(void)
 }
 #endif
 
+/* user-defined highmem size */
+static unsigned int highmem_pages = -1;
+
 /*
- * paging_init() sets up the page tables - note that the first 8MB are
- * already mapped by head.S.
- *
- * This routines also unmaps the page at virtual kernel address 0, so
- * that we can trap those pesky NULL-reference errors in the kernel.
+ * highmem=size forces highmem to be exactly 'size' bytes.
+ * This works even on boxes that have no highmem otherwise.
+ * This also works to reduce highmem size on bigger boxes.
  */
-void __init paging_init(void)
+static int __init parse_highmem(char *arg)
+{
+       if (!arg)
+               return -EINVAL;
+
+       highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
+       return 0;
+}
+early_param("highmem", parse_highmem);
+
+/*
+ * Determine low and high memory ranges:
+ */
+void __init find_low_pfn_range(void)
+{
+       /* it could update max_pfn */
+
+       /* max_low_pfn is 0, we already have early_res support */
+
+       max_low_pfn = max_pfn;
+       if (max_low_pfn > MAXMEM_PFN) {
+               if (highmem_pages == -1)
+                       highmem_pages = max_pfn - MAXMEM_PFN;
+               if (highmem_pages + MAXMEM_PFN < max_pfn)
+                       max_pfn = MAXMEM_PFN + highmem_pages;
+               if (highmem_pages + MAXMEM_PFN > max_pfn) {
+                       printk(KERN_WARNING "only %luMB highmem pages "
+                               "available, ignoring highmem size of %uMB.\n",
+                               pages_to_mb(max_pfn - MAXMEM_PFN),
+                               pages_to_mb(highmem_pages));
+                       highmem_pages = 0;
+               }
+               max_low_pfn = MAXMEM_PFN;
+#ifndef CONFIG_HIGHMEM
+               /* Maximum memory usable is what is directly addressable */
+               printk(KERN_WARNING "Warning only %ldMB will be used.\n",
+                                       MAXMEM>>20);
+               if (max_pfn > MAX_NONPAE_PFN)
+                       printk(KERN_WARNING
+                                "Use a HIGHMEM64G enabled kernel.\n");
+               else
+                       printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
+               max_pfn = MAXMEM_PFN;
+#else /* !CONFIG_HIGHMEM */
+#ifndef CONFIG_HIGHMEM64G
+               if (max_pfn > MAX_NONPAE_PFN) {
+                       max_pfn = MAX_NONPAE_PFN;
+                       printk(KERN_WARNING "Warning only 4GB will be used."
+                               "Use a HIGHMEM64G enabled kernel.\n");
+               }
+#endif /* !CONFIG_HIGHMEM64G */
+#endif /* !CONFIG_HIGHMEM */
+       } else {
+               if (highmem_pages == -1)
+                       highmem_pages = 0;
+#ifdef CONFIG_HIGHMEM
+               if (highmem_pages >= max_pfn) {
+                       printk(KERN_ERR "highmem size specified (%uMB) is "
+                               "bigger than pages available (%luMB)!.\n",
+                               pages_to_mb(highmem_pages),
+                               pages_to_mb(max_pfn));
+                       highmem_pages = 0;
+               }
+               if (highmem_pages) {
+                       if (max_low_pfn - highmem_pages <
+                           64*1024*1024/PAGE_SIZE){
+                               printk(KERN_ERR "highmem size %uMB results in "
+                               "smaller than 64MB lowmem, ignoring it.\n"
+                                       , pages_to_mb(highmem_pages));
+                               highmem_pages = 0;
+                       }
+                       max_low_pfn -= highmem_pages;
+               }
+#else
+               if (highmem_pages)
+                       printk(KERN_ERR "ignoring highmem size on non-highmem"
+                                       " kernel!\n");
+#endif
+       }
+}
+
+#ifndef CONFIG_NEED_MULTIPLE_NODES
+void __init initmem_init(unsigned long start_pfn,
+                                 unsigned long end_pfn)
 {
+#ifdef CONFIG_HIGHMEM
+       highstart_pfn = highend_pfn = max_pfn;
+       if (max_pfn > max_low_pfn)
+               highstart_pfn = max_low_pfn;
+       memory_present(0, 0, highend_pfn);
+       e820_register_active_regions(0, 0, highend_pfn);
+       printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
+               pages_to_mb(highend_pfn - highstart_pfn));
+       num_physpages = highend_pfn;
+       high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
+#else
+       memory_present(0, 0, max_low_pfn);
+       e820_register_active_regions(0, 0, max_low_pfn);
+       num_physpages = max_low_pfn;
+       high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
+#endif
+#ifdef CONFIG_FLATMEM
+       max_mapnr = num_physpages;
+#endif
+       printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
+                       pages_to_mb(max_low_pfn));
+
+       setup_bootmem_allocator();
+}
+#endif /* !CONFIG_NEED_MULTIPLE_NODES */
+
+static void __init zone_sizes_init(void)
+{
+       unsigned long max_zone_pfns[MAX_NR_ZONES];
+       memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
+       max_zone_pfns[ZONE_DMA] =
+               virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
+       max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
+#ifdef CONFIG_HIGHMEM
+       max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
+#endif
+
+       free_area_init_nodes(max_zone_pfns);
+}
+
+void __init setup_bootmem_allocator(void)
+{
+       int i;
+       unsigned long bootmap_size, bootmap;
+       /*
+        * Initialize the boot-time allocator (with low memory only):
+        */
+       bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
+       bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
+                                max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
+                                PAGE_SIZE);
+       if (bootmap == -1L)
+               panic("Cannot find bootmem map of size %ld\n", bootmap_size);
+       reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
+
+       /* don't touch min_low_pfn */
+       bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap >> PAGE_SHIFT,
+                                        min_low_pfn, max_low_pfn);
+       printk(KERN_INFO "  mapped low ram: 0 - %08lx\n",
+                max_pfn_mapped<<PAGE_SHIFT);
+       printk(KERN_INFO "  low ram: %08lx - %08lx\n",
+                min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
+       printk(KERN_INFO "  bootmap %08lx - %08lx\n",
+                bootmap, bootmap + bootmap_size);
+       for_each_online_node(i)
+               free_bootmem_with_active_regions(i, max_low_pfn);
+       early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
+
+       after_init_bootmem = 1;
+}
+
+static void __init find_early_table_space(unsigned long end)
+{
+       unsigned long puds, pmds, ptes, tables, start;
+
+       puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
+       tables = PAGE_ALIGN(puds * sizeof(pud_t));
+
+       pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
+       tables += PAGE_ALIGN(pmds * sizeof(pmd_t));
+
+       if (cpu_has_pse) {
+               unsigned long extra;
+
+               extra = end - ((end>>PMD_SHIFT) << PMD_SHIFT);
+               extra += PMD_SIZE;
+               ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       } else
+               ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
+
+       tables += PAGE_ALIGN(ptes * sizeof(pte_t));
+
+       /* for fixmap */
+       tables += PAGE_SIZE * 2;
+
+       /*
+        * RED-PEN putting page tables only on node 0 could
+        * cause a hotspot and fill up ZONE_DMA. The page tables
+        * need roughly 0.5KB per GB.
+        */
+       start = 0x7000;
+       table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
+                                       tables, PAGE_SIZE);
+       if (table_start == -1UL)
+               panic("Cannot find space for the kernel page tables");
+
+       table_start >>= PAGE_SHIFT;
+       table_end = table_start;
+       table_top = table_start + (tables>>PAGE_SHIFT);
+
+       printk(KERN_DEBUG "kernel direct mapping tables up to %lx @ %lx-%lx\n",
+               end, table_start << PAGE_SHIFT,
+               (table_start << PAGE_SHIFT) + tables);
+}
+
+unsigned long __init_refok init_memory_mapping(unsigned long start,
+                                               unsigned long end)
+{
+       pgd_t *pgd_base = swapper_pg_dir;
+       unsigned long start_pfn, end_pfn;
+       unsigned long big_page_start;
+
+       /*
+        * Find space for the kernel direct mapping tables.
+        */
+       if (!after_init_bootmem)
+               find_early_table_space(end);
+
 #ifdef CONFIG_X86_PAE
        set_nx();
        if (nx_enabled)
                printk(KERN_INFO "NX (Execute Disable) protection: active\n");
 #endif
-       pagetable_init();
+
+       /* Enable PSE if available */
+       if (cpu_has_pse)
+               set_in_cr4(X86_CR4_PSE);
+
+       /* Enable PGE if available */
+       if (cpu_has_pge) {
+               set_in_cr4(X86_CR4_PGE);
+               __supported_pte_mask |= _PAGE_GLOBAL;
+       }
+
+       /*
+        * Don't use a large page for the first 2/4MB of memory
+        * because there are often fixed size MTRRs in there
+        * and overlapping MTRRs into large pages can cause
+        * slowdowns.
+        */
+       big_page_start = PMD_SIZE;
+
+       if (start < big_page_start) {
+               start_pfn = start >> PAGE_SHIFT;
+               end_pfn = min(big_page_start>>PAGE_SHIFT, end>>PAGE_SHIFT);
+       } else {
+               /* head is not big page alignment ? */
+               start_pfn = start >> PAGE_SHIFT;
+               end_pfn = ((start + (PMD_SIZE - 1))>>PMD_SHIFT)
+                                << (PMD_SHIFT - PAGE_SHIFT);
+       }
+       if (start_pfn < end_pfn)
+               kernel_physical_mapping_init(pgd_base, start_pfn, end_pfn, 0);
+
+       /* big page range */
+       start_pfn = ((start + (PMD_SIZE - 1))>>PMD_SHIFT)
+                        << (PMD_SHIFT - PAGE_SHIFT);
+       if (start_pfn < (big_page_start >> PAGE_SHIFT))
+               start_pfn =  big_page_start >> PAGE_SHIFT;
+       end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
+       if (start_pfn < end_pfn)
+               kernel_physical_mapping_init(pgd_base, start_pfn, end_pfn,
+                                               cpu_has_pse);
+
+       /* tail is not big page alignment ? */
+       start_pfn = end_pfn;
+       if (start_pfn > (big_page_start>>PAGE_SHIFT)) {
+               end_pfn = end >> PAGE_SHIFT;
+               if (start_pfn < end_pfn)
+                       kernel_physical_mapping_init(pgd_base, start_pfn,
+                                                        end_pfn, 0);
+       }
+
+       early_ioremap_page_table_range_init(pgd_base);
 
        load_cr3(swapper_pg_dir);
 
        __flush_tlb_all();
 
+       if (!after_init_bootmem)
+               reserve_early(table_start << PAGE_SHIFT,
+                                table_end << PAGE_SHIFT, "PGTABLE");
+
+       return end >> PAGE_SHIFT;
+}
+
+
+/*
+ * paging_init() sets up the page tables - note that the first 8MB are
+ * already mapped by head.S.
+ *
+ * This routines also unmaps the page at virtual kernel address 0, so
+ * that we can trap those pesky NULL-reference errors in the kernel.
+ */
+void __init paging_init(void)
+{
+       pagetable_init();
+
+       __flush_tlb_all();
+
        kmap_init();
+
+       /*
+        * NOTE: at this point the bootmem allocator is fully available.
+        */
+       sparse_init();
+       zone_sizes_init();
+
+       paravirt_post_allocator_init();
 }
 
 /*
@@ -564,23 +904,10 @@ static struct kcore_list kcore_mem, kcore_vmalloc;
 void __init mem_init(void)
 {
        int codesize, reservedpages, datasize, initsize;
-       int tmp, bad_ppro;
+       int tmp;
 
 #ifdef CONFIG_FLATMEM
        BUG_ON(!mem_map);
-#endif
-       bad_ppro = ppro_with_ram_bug();
-
-#ifdef CONFIG_HIGHMEM
-       /* check that fixmap and pkmap do not overlap */
-       if (PKMAP_BASE + LAST_PKMAP*PAGE_SIZE >= FIXADDR_START) {
-               printk(KERN_ERR
-                       "fixmap and kmap areas overlap - this will crash\n");
-               printk(KERN_ERR "pkstart: %lxh pkend: %lxh fixstart %lxh\n",
-                               PKMAP_BASE, PKMAP_BASE + LAST_PKMAP*PAGE_SIZE,
-                               FIXADDR_START);
-               BUG();
-       }
 #endif
        /* this will put all low memory onto the freelists */
        totalram_pages += free_all_bootmem();
@@ -593,7 +920,7 @@ void __init mem_init(void)
                if (page_is_ram(tmp) && PageReserved(pfn_to_page(tmp)))
                        reservedpages++;
 
-       set_highmem_pages_init(bad_ppro);
+       set_highmem_pages_init();
 
        codesize =  (unsigned long) &_etext - (unsigned long) &_text;
        datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
@@ -614,7 +941,6 @@ void __init mem_init(void)
                (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10))
               );
 
-#if 1 /* double-sanity-check paranoia */
        printk(KERN_INFO "virtual kernel memory layout:\n"
                "    fixmap  : 0x%08lx - 0x%08lx   (%4ld kB)\n"
 #ifdef CONFIG_HIGHMEM
@@ -655,7 +981,6 @@ void __init mem_init(void)
 #endif
        BUG_ON(VMALLOC_START                            > VMALLOC_END);
        BUG_ON((unsigned long)high_memory               > VMALLOC_START);
-#endif /* double-sanity-check paranoia */
 
        if (boot_cpu_data.wp_works_ok < 0)
                test_wp_bit();
@@ -710,6 +1035,8 @@ void mark_rodata_ro(void)
        unsigned long start = PFN_ALIGN(_text);
        unsigned long size = PFN_ALIGN(_etext) - start;
 
+#ifndef CONFIG_DYNAMIC_FTRACE
+       /* Dynamic tracing modifies the kernel text section */
        set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
        printk(KERN_INFO "Write protecting the kernel text: %luk\n",
                size >> 10);
@@ -722,6 +1049,8 @@ void mark_rodata_ro(void)
        printk(KERN_INFO "Testing CPA: write protecting again\n");
        set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
 #endif
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
        start += size;
        size = (unsigned long)__end_rodata - start;
        set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
@@ -784,3 +1113,9 @@ void free_initrd_mem(unsigned long start, unsigned long end)
        free_init_pages("initrd memory", start, end);
 }
 #endif
+
+int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
+                                  int flags)
+{
+       return reserve_bootmem(phys, len, flags);
+}
index 819dad9..27de243 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/swap.h>
 #include <linux/smp.h>
 #include <linux/init.h>
+#include <linux/initrd.h>
 #include <linux/pagemap.h>
 #include <linux/bootmem.h>
 #include <linux/proc_fs.h>
 #include <asm/numa.h>
 #include <asm/cacheflush.h>
 
+/*
+ * end_pfn only includes RAM, while max_pfn_mapped includes all e820 entries.
+ * The direct mapping extends to max_pfn_mapped, so that we can directly access
+ * apertures, ACPI and other tables without having to play with fixmaps.
+ */
+unsigned long max_low_pfn_mapped;
+unsigned long max_pfn_mapped;
+
 static unsigned long dma_reserve __initdata;
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
@@ -135,26 +144,17 @@ static __init void *spp_getpage(void)
        return ptr;
 }
 
-static __init void
-set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
+void
+set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
 {
-       pgd_t *pgd;
        pud_t *pud;
        pmd_t *pmd;
-       pte_t *pte, new_pte;
-
-       pr_debug("set_pte_phys %lx to %lx\n", vaddr, phys);
+       pte_t *pte;
 
-       pgd = pgd_offset_k(vaddr);
-       if (pgd_none(*pgd)) {
-               printk(KERN_ERR
-                       "PGD FIXMAP MISSING, it should be setup in head.S!\n");
-               return;
-       }
-       pud = pud_offset(pgd, vaddr);
+       pud = pud_page + pud_index(vaddr);
        if (pud_none(*pud)) {
                pmd = (pmd_t *) spp_getpage();
-               set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER));
+               pud_populate(&init_mm, pud, pmd);
                if (pmd != pmd_offset(pud, 0)) {
                        printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
                                pmd, pmd_offset(pud, 0));
@@ -164,13 +164,12 @@ set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
        pmd = pmd_offset(pud, vaddr);
        if (pmd_none(*pmd)) {
                pte = (pte_t *) spp_getpage();
-               set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE | _PAGE_USER));
+               pmd_populate_kernel(&init_mm, pmd, pte);
                if (pte != pte_offset_kernel(pmd, 0)) {
                        printk(KERN_ERR "PAGETABLE BUG #02!\n");
                        return;
                }
        }
-       new_pte = pfn_pte(phys >> PAGE_SHIFT, prot);
 
        pte = pte_offset_kernel(pmd, vaddr);
        if (!pte_none(*pte) && pte_val(new_pte) &&
@@ -185,6 +184,64 @@ set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
        __flush_tlb_one(vaddr);
 }
 
+void
+set_pte_vaddr(unsigned long vaddr, pte_t pteval)
+{
+       pgd_t *pgd;
+       pud_t *pud_page;
+
+       pr_debug("set_pte_vaddr %lx to %lx\n", vaddr, native_pte_val(pteval));
+
+       pgd = pgd_offset_k(vaddr);
+       if (pgd_none(*pgd)) {
+               printk(KERN_ERR
+                       "PGD FIXMAP MISSING, it should be setup in head.S!\n");
+               return;
+       }
+       pud_page = (pud_t*)pgd_page_vaddr(*pgd);
+       set_pte_vaddr_pud(pud_page, vaddr, pteval);
+}
+
+/*
+ * Create large page table mappings for a range of physical addresses.
+ */
+static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
+                                               pgprot_t prot)
+{
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+
+       BUG_ON((phys & ~PMD_MASK) || (size & ~PMD_MASK));
+       for (; size; phys += PMD_SIZE, size -= PMD_SIZE) {
+               pgd = pgd_offset_k((unsigned long)__va(phys));
+               if (pgd_none(*pgd)) {
+                       pud = (pud_t *) spp_getpage();
+                       set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
+                                               _PAGE_USER));
+               }
+               pud = pud_offset(pgd, (unsigned long)__va(phys));
+               if (pud_none(*pud)) {
+                       pmd = (pmd_t *) spp_getpage();
+                       set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
+                                               _PAGE_USER));
+               }
+               pmd = pmd_offset(pud, phys);
+               BUG_ON(!pmd_none(*pmd));
+               set_pmd(pmd, __pmd(phys | pgprot_val(prot)));
+       }
+}
+
+void __init init_extra_mapping_wb(unsigned long phys, unsigned long size)
+{
+       __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE);
+}
+
+void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
+{
+       __init_extra_mapping(phys, size, PAGE_KERNEL_LARGE_NOCACHE);
+}
+
 /*
  * The head.S code sets up the kernel high mapping:
  *
@@ -213,20 +270,9 @@ void __init cleanup_highmap(void)
        }
 }
 
-/* NOTE: this is meant to be run only at boot */
-void __init __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
-{
-       unsigned long address = __fix_to_virt(idx);
-
-       if (idx >= __end_of_fixed_addresses) {
-               printk(KERN_ERR "Invalid __set_fixmap\n");
-               return;
-       }
-       set_pte_phys(address, phys, prot);
-}
-
 static unsigned long __initdata table_start;
 static unsigned long __meminitdata table_end;
+static unsigned long __meminitdata table_top;
 
 static __meminit void *alloc_low_page(unsigned long *phys)
 {
@@ -240,7 +286,7 @@ static __meminit void *alloc_low_page(unsigned long *phys)
                return adr;
        }
 
-       if (pfn >= end_pfn)
+       if (pfn >= table_top)
                panic("alloc_low_page: ran out of memory");
 
        adr = early_ioremap(pfn * PAGE_SIZE, PAGE_SIZE);
@@ -257,65 +303,61 @@ static __meminit void unmap_low_page(void *adr)
        early_iounmap(adr, PAGE_SIZE);
 }
 
-/* Must run before zap_low_mappings */
-__meminit void *early_ioremap(unsigned long addr, unsigned long size)
+static unsigned long __meminit
+phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end)
 {
-       pmd_t *pmd, *last_pmd;
-       unsigned long vaddr;
-       int i, pmds;
+       unsigned pages = 0;
+       unsigned long last_map_addr = end;
+       int i;
+
+       pte_t *pte = pte_page + pte_index(addr);
 
-       pmds = ((addr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE;
-       vaddr = __START_KERNEL_map;
-       pmd = level2_kernel_pgt;
-       last_pmd = level2_kernel_pgt + PTRS_PER_PMD - 1;
+       for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
 
-       for (; pmd <= last_pmd; pmd++, vaddr += PMD_SIZE) {
-               for (i = 0; i < pmds; i++) {
-                       if (pmd_present(pmd[i]))
-                               goto continue_outer_loop;
+               if (addr >= end) {
+                       if (!after_bootmem) {
+                               for(; i < PTRS_PER_PTE; i++, pte++)
+                                       set_pte(pte, __pte(0));
+                       }
+                       break;
                }
-               vaddr += addr & ~PMD_MASK;
-               addr &= PMD_MASK;
 
-               for (i = 0; i < pmds; i++, addr += PMD_SIZE)
-                       set_pmd(pmd+i, __pmd(addr | __PAGE_KERNEL_LARGE_EXEC));
-               __flush_tlb_all();
+               if (pte_val(*pte))
+                       continue;
 
-               return (void *)vaddr;
-continue_outer_loop:
-               ;
+               if (0)
+                       printk("   pte=%p addr=%lx pte=%016lx\n",
+                              pte, addr, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL).pte);
+               set_pte(pte, pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL));
+               last_map_addr = (addr & PAGE_MASK) + PAGE_SIZE;
+               pages++;
        }
-       printk(KERN_ERR "early_ioremap(0x%lx, %lu) failed\n", addr, size);
+       update_page_count(PG_LEVEL_4K, pages);
 
-       return NULL;
+       return last_map_addr;
 }
 
-/*
- * To avoid virtual aliases later:
- */
-__meminit void early_iounmap(void *addr, unsigned long size)
+static unsigned long __meminit
+phys_pte_update(pmd_t *pmd, unsigned long address, unsigned long end)
 {
-       unsigned long vaddr;
-       pmd_t *pmd;
-       int i, pmds;
-
-       vaddr = (unsigned long)addr;
-       pmds = ((vaddr & ~PMD_MASK) + size + ~PMD_MASK) / PMD_SIZE;
-       pmd = level2_kernel_pgt + pmd_index(vaddr);
-
-       for (i = 0; i < pmds; i++)
-               pmd_clear(pmd + i);
+       pte_t *pte = (pte_t *)pmd_page_vaddr(*pmd);
 
-       __flush_tlb_all();
+       return phys_pte_init(pte, address, end);
 }
 
 static unsigned long __meminit
-phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
+phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
+                        unsigned long page_size_mask)
 {
+       unsigned long pages = 0;
+       unsigned long last_map_addr = end;
+
        int i = pmd_index(address);
 
        for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
+               unsigned long pte_phys;
                pmd_t *pmd = pmd_page + pmd_index(address);
+               pte_t *pte;
 
                if (address >= end) {
                        if (!after_bootmem) {
@@ -325,31 +367,50 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
                        break;
                }
 
-               if (pmd_val(*pmd))
+               if (pmd_val(*pmd)) {
+                       if (!pmd_large(*pmd))
+                               last_map_addr = phys_pte_update(pmd, address,
+                                                                end);
+                       continue;
+               }
+
+               if (page_size_mask & (1<<PG_LEVEL_2M)) {
+                       pages++;
+                       set_pte((pte_t *)pmd,
+                               pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
+                       last_map_addr = (address & PMD_MASK) + PMD_SIZE;
                        continue;
+               }
+
+               pte = alloc_low_page(&pte_phys);
+               last_map_addr = phys_pte_init(pte, address, end);
+               unmap_low_page(pte);
 
-               set_pte((pte_t *)pmd,
-                       pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
+               pmd_populate_kernel(&init_mm, pmd, __va(pte_phys));
        }
-       return address;
+       update_page_count(PG_LEVEL_2M, pages);
+       return last_map_addr;
 }
 
 static unsigned long __meminit
-phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end)
+phys_pmd_update(pud_t *pud, unsigned long address, unsigned long end,
+                        unsigned long page_size_mask)
 {
        pmd_t *pmd = pmd_offset(pud, 0);
        unsigned long last_map_addr;
 
        spin_lock(&init_mm.page_table_lock);
-       last_map_addr = phys_pmd_init(pmd, address, end);
+       last_map_addr = phys_pmd_init(pmd, address, end, page_size_mask);
        spin_unlock(&init_mm.page_table_lock);
        __flush_tlb_all();
        return last_map_addr;
 }
 
 static unsigned long __meminit
-phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end)
+phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
+                        unsigned long page_size_mask)
 {
+       unsigned long pages = 0;
        unsigned long last_map_addr = end;
        int i = pud_index(addr);
 
@@ -369,11 +430,13 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end)
 
                if (pud_val(*pud)) {
                        if (!pud_large(*pud))
-                               last_map_addr = phys_pmd_update(pud, addr, end);
+                               last_map_addr = phys_pmd_update(pud, addr, end,
+                                                        page_size_mask);
                        continue;
                }
 
-               if (direct_gbpages) {
+               if (page_size_mask & (1<<PG_LEVEL_1G)) {
+                       pages++;
                        set_pte((pte_t *)pud,
                                pfn_pte(addr >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
                        last_map_addr = (addr & PUD_MASK) + PUD_SIZE;
@@ -383,27 +446,50 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end)
                pmd = alloc_low_page(&pmd_phys);
 
                spin_lock(&init_mm.page_table_lock);
-               set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE));
-               last_map_addr = phys_pmd_init(pmd, addr, end);
+               last_map_addr = phys_pmd_init(pmd, addr, end, page_size_mask);
+               unmap_low_page(pmd);
+               pud_populate(&init_mm, pud, __va(pmd_phys));
                spin_unlock(&init_mm.page_table_lock);
 
-               unmap_low_page(pmd);
        }
        __flush_tlb_all();
+       update_page_count(PG_LEVEL_1G, pages);
 
-       return last_map_addr >> PAGE_SHIFT;
+       return last_map_addr;
+}
+
+static unsigned long __meminit
+phys_pud_update(pgd_t *pgd, unsigned long addr, unsigned long end,
+                unsigned long page_size_mask)
+{
+       pud_t *pud;
+
+       pud = (pud_t *)pgd_page_vaddr(*pgd);
+
+       return phys_pud_init(pud, addr, end, page_size_mask);
 }
 
 static void __init find_early_table_space(unsigned long end)
 {
-       unsigned long puds, pmds, tables, start;
+       unsigned long puds, pmds, ptes, tables, start;
 
        puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
        tables = round_up(puds * sizeof(pud_t), PAGE_SIZE);
-       if (!direct_gbpages) {
+       if (direct_gbpages) {
+               unsigned long extra;
+               extra = end - ((end>>PUD_SHIFT) << PUD_SHIFT);
+               pmds = (extra + PMD_SIZE - 1) >> PMD_SHIFT;
+       } else
                pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
-               tables += round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
-       }
+       tables += round_up(pmds * sizeof(pmd_t), PAGE_SIZE);
+
+       if (cpu_has_pse) {
+               unsigned long extra;
+               extra = end - ((end>>PMD_SHIFT) << PMD_SHIFT);
+               ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       } else
+               ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       tables += round_up(ptes * sizeof(pte_t), PAGE_SIZE);
 
        /*
         * RED-PEN putting page tables only on node 0 could
@@ -417,10 +503,10 @@ static void __init find_early_table_space(unsigned long end)
 
        table_start >>= PAGE_SHIFT;
        table_end = table_start;
+       table_top = table_start + (tables >> PAGE_SHIFT);
 
-       early_printk("kernel direct mapping tables up to %lx @ %lx-%lx\n",
-               end, table_start << PAGE_SHIFT,
-               (table_start << PAGE_SHIFT) + tables);
+       printk(KERN_DEBUG "kernel direct mapping tables up to %lx @ %lx-%lx\n",
+               end, table_start << PAGE_SHIFT, table_top << PAGE_SHIFT);
 }
 
 static void __init init_gbpages(void)
@@ -431,7 +517,7 @@ static void __init init_gbpages(void)
                direct_gbpages = 0;
 }
 
-#ifdef CONFIG_MEMTEST_BOOTPARAM
+#ifdef CONFIG_MEMTEST
 
 static void __init memtest(unsigned long start_phys, unsigned long size,
                                 unsigned pattern)
@@ -493,7 +579,8 @@ static void __init memtest(unsigned long start_phys, unsigned long size,
 
 }
 
-static int memtest_pattern __initdata = CONFIG_MEMTEST_BOOTPARAM_VALUE;
+/* default is disabled */
+static int memtest_pattern __initdata;
 
 static int __init parse_memtest(char *arg)
 {
@@ -542,15 +629,85 @@ static void __init early_memtest(unsigned long start, unsigned long end)
 }
 #endif
 
+static unsigned long __init kernel_physical_mapping_init(unsigned long start,
+                                               unsigned long end,
+                                               unsigned long page_size_mask)
+{
+
+       unsigned long next, last_map_addr = end;
+
+       start = (unsigned long)__va(start);
+       end = (unsigned long)__va(end);
+
+       for (; start < end; start = next) {
+               pgd_t *pgd = pgd_offset_k(start);
+               unsigned long pud_phys;
+               pud_t *pud;
+
+               next = start + PGDIR_SIZE;
+               if (next > end)
+                       next = end;
+
+               if (pgd_val(*pgd)) {
+                       last_map_addr = phys_pud_update(pgd, __pa(start),
+                                                __pa(end), page_size_mask);
+                       continue;
+               }
+
+               if (after_bootmem)
+                       pud = pud_offset(pgd, start & PGDIR_MASK);
+               else
+                       pud = alloc_low_page(&pud_phys);
+
+               last_map_addr = phys_pud_init(pud, __pa(start), __pa(next),
+                                                page_size_mask);
+               unmap_low_page(pud);
+               pgd_populate(&init_mm, pgd_offset_k(start),
+                            __va(pud_phys));
+       }
+
+       return last_map_addr;
+}
+
+struct map_range {
+       unsigned long start;
+       unsigned long end;
+       unsigned page_size_mask;
+};
+
+#define NR_RANGE_MR 5
+
+static int save_mr(struct map_range *mr, int nr_range,
+                  unsigned long start_pfn, unsigned long end_pfn,
+                  unsigned long page_size_mask)
+{
+
+       if (start_pfn < end_pfn) {
+               if (nr_range >= NR_RANGE_MR)
+                       panic("run out of range for init_memory_mapping\n");
+               mr[nr_range].start = start_pfn<<PAGE_SHIFT;
+               mr[nr_range].end   = end_pfn<<PAGE_SHIFT;
+               mr[nr_range].page_size_mask = page_size_mask;
+               nr_range++;
+       }
+
+       return nr_range;
+}
+
 /*
  * Setup the direct mapping of the physical memory at PAGE_OFFSET.
  * This runs before bootmem is initialized and gets pages directly from
  * the physical memory. To access them they are temporarily mapped.
  */
-unsigned long __init_refok init_memory_mapping(unsigned long start, unsigned long end)
+unsigned long __init_refok init_memory_mapping(unsigned long start,
+                                              unsigned long end)
 {
-       unsigned long next, last_map_addr = end;
-       unsigned long start_phys = start, end_phys = end;
+       unsigned long last_map_addr = 0;
+       unsigned long page_size_mask = 0;
+       unsigned long start_pfn, end_pfn;
+
+       struct map_range mr[NR_RANGE_MR];
+       int nr_range, i;
 
        printk(KERN_INFO "init_memory_mapping\n");
 
@@ -561,48 +718,115 @@ unsigned long __init_refok init_memory_mapping(unsigned long start, unsigned lon
         * memory mapped. Unfortunately this is done currently before the
         * nodes are discovered.
         */
-       if (!after_bootmem) {
+       if (!after_bootmem)
                init_gbpages();
-               find_early_table_space(end);
-       }
 
-       start = (unsigned long)__va(start);
-       end = (unsigned long)__va(end);
+       if (direct_gbpages)
+               page_size_mask |= 1 << PG_LEVEL_1G;
+       if (cpu_has_pse)
+               page_size_mask |= 1 << PG_LEVEL_2M;
+
+       memset(mr, 0, sizeof(mr));
+       nr_range = 0;
+
+       /* head if not big page alignment ?*/
+       start_pfn = start >> PAGE_SHIFT;
+       end_pfn = ((start + (PMD_SIZE - 1)) >> PMD_SHIFT)
+                       << (PMD_SHIFT - PAGE_SHIFT);
+       nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, 0);
+
+       /* big page (2M) range*/
+       start_pfn = ((start + (PMD_SIZE - 1))>>PMD_SHIFT)
+                        << (PMD_SHIFT - PAGE_SHIFT);
+       end_pfn = ((start + (PUD_SIZE - 1))>>PUD_SHIFT)
+                        << (PUD_SHIFT - PAGE_SHIFT);
+       if (end_pfn > ((end>>PUD_SHIFT)<<(PUD_SHIFT - PAGE_SHIFT)))
+               end_pfn = ((end>>PUD_SHIFT)<<(PUD_SHIFT - PAGE_SHIFT));
+       nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
+                       page_size_mask & (1<<PG_LEVEL_2M));
+
+       /* big page (1G) range */
+       start_pfn = end_pfn;
+       end_pfn = (end>>PUD_SHIFT) << (PUD_SHIFT - PAGE_SHIFT);
+       nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
+                               page_size_mask &
+                                ((1<<PG_LEVEL_2M)|(1<<PG_LEVEL_1G)));
+
+       /* tail is not big page (1G) alignment */
+       start_pfn = end_pfn;
+       end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
+       nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
+                       page_size_mask & (1<<PG_LEVEL_2M));
+
+       /* tail is not big page (2M) alignment */
+       start_pfn = end_pfn;
+       end_pfn = end>>PAGE_SHIFT;
+       nr_range = save_mr(mr, nr_range, start_pfn, end_pfn, 0);
+
+       /* try to merge same page size and continuous */
+       for (i = 0; nr_range > 1 && i < nr_range - 1; i++) {
+               unsigned long old_start;
+               if (mr[i].end != mr[i+1].start ||
+                   mr[i].page_size_mask != mr[i+1].page_size_mask)
+                       continue;
+               /* move it */
+               old_start = mr[i].start;
+               memmove(&mr[i], &mr[i+1],
+                        (nr_range - 1 - i) * sizeof (struct map_range));
+               mr[i].start = old_start;
+               nr_range--;
+       }
 
-       for (; start < end; start = next) {
-               pgd_t *pgd = pgd_offset_k(start);
-               unsigned long pud_phys;
-               pud_t *pud;
+       for (i = 0; i < nr_range; i++)
+               printk(KERN_DEBUG " %010lx - %010lx page %s\n",
+                               mr[i].start, mr[i].end,
+                       (mr[i].page_size_mask & (1<<PG_LEVEL_1G))?"1G":(
+                        (mr[i].page_size_mask & (1<<PG_LEVEL_2M))?"2M":"4k"));
 
-               if (after_bootmem)
-                       pud = pud_offset(pgd, start & PGDIR_MASK);
-               else
-                       pud = alloc_low_page(&pud_phys);
+       if (!after_bootmem)
+               find_early_table_space(end);
 
-               next = start + PGDIR_SIZE;
-               if (next > end)
-                       next = end;
-               last_map_addr = phys_pud_init(pud, __pa(start), __pa(next));
-               if (!after_bootmem)
-                       set_pgd(pgd_offset_k(start), mk_kernel_pgd(pud_phys));
-               unmap_low_page(pud);
-       }
+       for (i = 0; i < nr_range; i++)
+               last_map_addr = kernel_physical_mapping_init(
+                                       mr[i].start, mr[i].end,
+                                       mr[i].page_size_mask);
 
        if (!after_bootmem)
                mmu_cr4_features = read_cr4();
        __flush_tlb_all();
 
-       if (!after_bootmem)
+       if (!after_bootmem && table_end > table_start)
                reserve_early(table_start << PAGE_SHIFT,
                                 table_end << PAGE_SHIFT, "PGTABLE");
 
+       printk(KERN_INFO "last_map_addr: %lx end: %lx\n",
+                        last_map_addr, end);
+
        if (!after_bootmem)
-               early_memtest(start_phys, end_phys);
+               early_memtest(start, end);
 
-       return last_map_addr;
+       return last_map_addr >> PAGE_SHIFT;
 }
 
 #ifndef CONFIG_NUMA
+void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn)
+{
+       unsigned long bootmap_size, bootmap;
+
+       bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
+       bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
+                                PAGE_SIZE);
+       if (bootmap == -1L)
+               panic("Cannot find bootmem map of size %ld\n", bootmap_size);
+       /* don't touch min_low_pfn */
+       bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap >> PAGE_SHIFT,
+                                        0, end_pfn);
+       e820_register_active_regions(0, start_pfn, end_pfn);
+       free_bootmem_with_active_regions(0, end_pfn);
+       early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
+       reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
+}
+
 void __init paging_init(void)
 {
        unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -610,9 +834,9 @@ void __init paging_init(void)
        memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
        max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
        max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
-       max_zone_pfns[ZONE_NORMAL] = end_pfn;
+       max_zone_pfns[ZONE_NORMAL] = max_pfn;
 
-       memory_present(0, 0, end_pfn);
+       memory_present(0, 0, max_pfn);
        sparse_init();
        free_area_init_nodes(max_zone_pfns);
 }
@@ -694,8 +918,8 @@ void __init mem_init(void)
 #else
        totalram_pages = free_all_bootmem();
 #endif
-       reservedpages = end_pfn - totalram_pages -
-                                       absent_pages_in_range(0, end_pfn);
+       reservedpages = max_pfn - totalram_pages -
+                                       absent_pages_in_range(0, max_pfn);
        after_bootmem = 1;
 
        codesize =  (unsigned long) &_etext - (unsigned long) &_text;
@@ -714,7 +938,7 @@ void __init mem_init(void)
        printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
                                "%ldk reserved, %ldk data, %ldk init)\n",
                (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
-               end_pfn << (PAGE_SHIFT-10),
+               max_pfn << (PAGE_SHIFT-10),
                codesize >> 10,
                reservedpages << (PAGE_SHIFT-10),
                datasize >> 10,
@@ -767,6 +991,13 @@ EXPORT_SYMBOL_GPL(rodata_test_data);
 void mark_rodata_ro(void)
 {
        unsigned long start = PFN_ALIGN(_stext), end = PFN_ALIGN(__end_rodata);
+       unsigned long rodata_start =
+               ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+       /* Dynamic tracing modifies the kernel text section */
+       start = rodata_start;
+#endif
 
        printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
               (end - start) >> 10);
@@ -776,8 +1007,7 @@ void mark_rodata_ro(void)
         * The rodata section (but not the kernel text!) should also be
         * not-executable.
         */
-       start = ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
-       set_memory_nx(start, (end - start) >> PAGE_SHIFT);
+       set_memory_nx(rodata_start, (end - rodata_start) >> PAGE_SHIFT);
 
        rodata_test();
 
@@ -799,24 +1029,26 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 }
 #endif
 
-void __init reserve_bootmem_generic(unsigned long phys, unsigned len)
+int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
+                                  int flags)
 {
 #ifdef CONFIG_NUMA
        int nid, next_nid;
+       int ret;
 #endif
        unsigned long pfn = phys >> PAGE_SHIFT;
 
-       if (pfn >= end_pfn) {
+       if (pfn >= max_pfn) {
                /*
                 * This can happen with kdump kernels when accessing
                 * firmware tables:
                 */
                if (pfn < max_pfn_mapped)
-                       return;
+                       return -EFAULT;
 
-               printk(KERN_ERR "reserve_bootmem: illegal reserve %lx %u\n",
+               printk(KERN_ERR "reserve_bootmem: illegal reserve %lx %lu\n",
                                phys, len);
-               return;
+               return -EFAULT;
        }
 
        /* Should check here against the e820 map to avoid double free */
@@ -824,9 +1056,13 @@ void __init reserve_bootmem_generic(unsigned long phys, unsigned len)
        nid = phys_to_nid(phys);
        next_nid = phys_to_nid(phys + len - 1);
        if (nid == next_nid)
-               reserve_bootmem_node(NODE_DATA(nid), phys, len, BOOTMEM_DEFAULT);
+               ret = reserve_bootmem_node(NODE_DATA(nid), phys, len, flags);
        else
-               reserve_bootmem(phys, len, BOOTMEM_DEFAULT);
+               ret = reserve_bootmem(phys, len, flags);
+
+       if (ret != 0)
+               return ret;
+
 #else
        reserve_bootmem(phys, len, BOOTMEM_DEFAULT);
 #endif
@@ -835,6 +1071,8 @@ void __init reserve_bootmem_generic(unsigned long phys, unsigned len)
                dma_reserve += len / PAGE_SIZE;
                set_dma_reserve(dma_reserve);
        }
+
+       return 0;
 }
 
 int kern_addr_valid(unsigned long addr)
@@ -939,7 +1177,7 @@ vmemmap_populate(struct page *start_page, unsigned long size, int node)
        pmd_t *pmd;
 
        for (; addr < end; addr = next) {
-               next = pmd_addr_end(addr, end);
+               void *p = NULL;
 
                pgd = vmemmap_pgd_populate(addr, node);
                if (!pgd)
@@ -949,33 +1187,51 @@ vmemmap_populate(struct page *start_page, unsigned long size, int node)
                if (!pud)
                        return -ENOMEM;
 
-               pmd = pmd_offset(pud, addr);
-               if (pmd_none(*pmd)) {
-                       pte_t entry;
-                       void *p;
+               if (!cpu_has_pse) {
+                       next = (addr + PAGE_SIZE) & PAGE_MASK;
+                       pmd = vmemmap_pmd_populate(pud, addr, node);
+
+                       if (!pmd)
+                               return -ENOMEM;
+
+                       p = vmemmap_pte_populate(pmd, addr, node);
 
-                       p = vmemmap_alloc_block(PMD_SIZE, node);
                        if (!p)
                                return -ENOMEM;
 
-                       entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
-                                                       PAGE_KERNEL_LARGE);
-                       set_pmd(pmd, __pmd(pte_val(entry)));
-
-                       /* check to see if we have contiguous blocks */
-                       if (p_end != p || node_start != node) {
-                               if (p_start)
-                                       printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
-                                               addr_start, addr_end-1, p_start, p_end-1, node_start);
-                               addr_start = addr;
-                               node_start = node;
-                               p_start = p;
-                       }
-                       addr_end = addr + PMD_SIZE;
-                       p_end = p + PMD_SIZE;
+                       addr_end = addr + PAGE_SIZE;
+                       p_end = p + PAGE_SIZE;
                } else {
-                       vmemmap_verify((pte_t *)pmd, node, addr, next);
+                       next = pmd_addr_end(addr, end);
+
+                       pmd = pmd_offset(pud, addr);
+                       if (pmd_none(*pmd)) {
+                               pte_t entry;
+
+                               p = vmemmap_alloc_block(PMD_SIZE, node);
+                               if (!p)
+                                       return -ENOMEM;
+
+                               entry = pfn_pte(__pa(p) >> PAGE_SHIFT,
+                                               PAGE_KERNEL_LARGE);
+                               set_pmd(pmd, __pmd(pte_val(entry)));
+
+                               /* check to see if we have contiguous blocks */
+                               if (p_end != p || node_start != node) {
+                                       if (p_start)
+                                               printk(KERN_DEBUG " [%lx-%lx] PMD -> [%p-%p] on node %d\n",
+                                                      addr_start, addr_end-1, p_start, p_end-1, node_start);
+                                       addr_start = addr;
+                                       node_start = node;
+                                       p_start = p;
+                               }
+
+                               addr_end = addr + PMD_SIZE;
+                               p_end = p + PMD_SIZE;
+                       } else
+                               vmemmap_verify((pte_t *)pmd, node, addr, next);
                }
+
        }
        return 0;
 }
index d1b8671..24c1d3c 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/mmiotrace.h>
 
 #include <asm/cacheflush.h>
 #include <asm/e820.h>
@@ -122,10 +123,13 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
 {
        unsigned long pfn, offset, vaddr;
        resource_size_t last_addr;
+       const resource_size_t unaligned_phys_addr = phys_addr;
+       const unsigned long unaligned_size = size;
        struct vm_struct *area;
        unsigned long new_prot_val;
        pgprot_t prot;
        int retval;
+       void __iomem *ret_addr;
 
        /* Don't allow wraparound or zero size */
        last_addr = phys_addr + size - 1;
@@ -142,7 +146,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
        /*
         * Don't remap the low PCI/ISA area, it's always mapped..
         */
-       if (phys_addr >= ISA_START_ADDRESS && last_addr < ISA_END_ADDRESS)
+       if (is_ISA_range(phys_addr, last_addr))
                return (__force void __iomem *)phys_to_virt(phys_addr);
 
        /*
@@ -233,7 +237,10 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
                return NULL;
        }
 
-       return (void __iomem *) (vaddr + offset);
+       ret_addr = (void __iomem *) (vaddr + offset);
+       mmiotrace_ioremap(unaligned_phys_addr, unaligned_size, ret_addr);
+
+       return ret_addr;
 }
 
 /**
@@ -261,7 +268,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)
 {
        /*
         * Ideally, this should be:
-        *      pat_wc_enabled ? _PAGE_CACHE_UC : _PAGE_CACHE_UC_MINUS;
+        *      pat_enabled ? _PAGE_CACHE_UC : _PAGE_CACHE_UC_MINUS;
         *
         * Till we fix all X drivers to use ioremap_wc(), we will use
         * UC MINUS.
@@ -285,7 +292,7 @@ EXPORT_SYMBOL(ioremap_nocache);
  */
 void __iomem *ioremap_wc(unsigned long phys_addr, unsigned long size)
 {
-       if (pat_wc_enabled)
+       if (pat_enabled)
                return __ioremap_caller(phys_addr, size, _PAGE_CACHE_WC,
                                        __builtin_return_address(0));
        else
@@ -341,13 +348,15 @@ void iounmap(volatile void __iomem *addr)
         * vm_area and by simply returning an address into the kernel mapping
         * of ISA space.   So handle that here.
         */
-       if (addr >= phys_to_virt(ISA_START_ADDRESS) &&
-           addr < phys_to_virt(ISA_END_ADDRESS))
+       if ((void __force *)addr >= phys_to_virt(ISA_START_ADDRESS) &&
+           (void __force *)addr < phys_to_virt(ISA_END_ADDRESS))
                return;
 
        addr = (volatile void __iomem *)
                (PAGE_MASK & (unsigned long __force)addr);
 
+       mmiotrace_iounmap(addr);
+
        /* Use the vm area unlocked, assuming the caller
           ensures there isn't another iounmap for the same address
           in parallel. Reuse of the virtual address is prevented by
@@ -355,7 +364,7 @@ void iounmap(volatile void __iomem *addr)
           cpa takes care of the direct mappings. */
        read_lock(&vmlist_lock);
        for (p = vmlist; p; p = p->next) {
-               if (p->addr == addr)
+               if (p->addr == (void __force *)addr)
                        break;
        }
        read_unlock(&vmlist_lock);
@@ -369,7 +378,7 @@ void iounmap(volatile void __iomem *addr)
        free_memtype(p->phys_addr, p->phys_addr + get_vm_area_size(p));
 
        /* Finally remove it */
-       o = remove_vm_area((void *)addr);
+       o = remove_vm_area((void __force *)addr);
        BUG_ON(p != o || o == NULL);
        kfree(p);
 }
@@ -388,7 +397,7 @@ void *xlate_dev_mem_ptr(unsigned long phys)
        if (page_is_ram(start >> PAGE_SHIFT))
                return __va(phys);
 
-       addr = (void *)ioremap_default(start, PAGE_SIZE);
+       addr = (void __force *)ioremap_default(start, PAGE_SIZE);
        if (addr)
                addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
 
@@ -404,8 +413,6 @@ void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
        return;
 }
 
-#ifdef CONFIG_X86_32
-
 int __initdata early_ioremap_debug;
 
 static int __init early_ioremap_debug_setup(char *str)
@@ -417,8 +424,7 @@ static int __init early_ioremap_debug_setup(char *str)
 early_param("early_ioremap_debug", early_ioremap_debug_setup);
 
 static __initdata int after_paging_init;
-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)]
-               __section(.bss.page_aligned);
+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
 
 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
 {
@@ -507,10 +513,11 @@ static void __init __early_set_fixmap(enum fixed_addresses idx,
                return;
        }
        pte = early_ioremap_pte(addr);
+
        if (pgprot_val(flags))
                set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
        else
-               pte_clear(NULL, addr, pte);
+               pte_clear(&init_mm, addr, pte);
        __flush_tlb_one(addr);
 }
 
@@ -648,5 +655,3 @@ void __this_fixmap_does_not_exist(void)
 {
        WARN_ON(1);
 }
-
-#endif /* CONFIG_X86_32 */
index 1f476e4..41f1b5c 100644 (file)
@@ -22,6 +22,7 @@
 #include <asm/numa.h>
 #include <asm/mpspec.h>
 #include <asm/apic.h>
+#include <asm/k8.h>
 
 static __init int find_northbridge(void)
 {
@@ -56,34 +57,33 @@ static __init void early_get_boot_cpu_id(void)
        /*
         * Find possible boot-time SMP configuration:
         */
+#ifdef CONFIG_X86_MPPARSE
        early_find_smp_config();
+#endif
 #ifdef CONFIG_ACPI
        /*
         * Read APIC information from ACPI tables.
         */
        early_acpi_boot_init();
 #endif
+#ifdef CONFIG_X86_MPPARSE
        /*
         * get boot-time SMP configuration:
         */
        if (smp_found_config)
                early_get_smp_config();
+#endif
        early_init_lapic_mapping();
 }
 
 int __init k8_scan_nodes(unsigned long start, unsigned long end)
 {
+       unsigned numnodes, cores, bits, apicid_base;
        unsigned long prevbase;
        struct bootnode nodes[8];
-       int nodeid, i, nb;
        unsigned char nodeids[8];
-       int found = 0;
-       u32 reg;
-       unsigned numnodes;
-       unsigned cores;
-       unsigned bits;
-       int j;
-       unsigned apicid_base;
+       int i, j, nb, found = 0;
+       u32 nodeid, reg;
 
        if (!early_pci_allowed())
                return -1;
@@ -105,7 +105,6 @@ int __init k8_scan_nodes(unsigned long start, unsigned long end)
        prevbase = 0;
        for (i = 0; i < 8; i++) {
                unsigned long base, limit;
-               u32 nodeid;
 
                base = read_pci_config(0, nb, 1, 0x40 + i*8);
                limit = read_pci_config(0, nb, 1, 0x44 + i*8);
@@ -144,8 +143,8 @@ int __init k8_scan_nodes(unsigned long start, unsigned long end)
                limit |= (1<<24)-1;
                limit++;
 
-               if (limit > end_pfn << PAGE_SHIFT)
-                       limit = end_pfn << PAGE_SHIFT;
+               if (limit > max_pfn << PAGE_SHIFT)
+                       limit = max_pfn << PAGE_SHIFT;
                if (limit <= base)
                        continue;
 
diff --git a/arch/x86/mm/kmmio.c b/arch/x86/mm/kmmio.c
new file mode 100644 (file)
index 0000000..93d8203
--- /dev/null
@@ -0,0 +1,510 @@
+/* Support for MMIO probes.
+ * Benfit many code from kprobes
+ * (C) 2002 Louis Zhuang <louis.zhuang@intel.com>.
+ *     2007 Alexander Eichner
+ *     2008 Pekka Paalanen <pq@iki.fi>
+ */
+
+#include <linux/list.h>
+#include <linux/rculist.h>
+#include <linux/spinlock.h>
+#include <linux/hash.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/uaccess.h>
+#include <linux/ptrace.h>
+#include <linux/preempt.h>
+#include <linux/percpu.h>
+#include <linux/kdebug.h>
+#include <linux/mutex.h>
+#include <linux/io.h>
+#include <asm/cacheflush.h>
+#include <asm/tlbflush.h>
+#include <linux/errno.h>
+#include <asm/debugreg.h>
+#include <linux/mmiotrace.h>
+
+#define KMMIO_PAGE_HASH_BITS 4
+#define KMMIO_PAGE_TABLE_SIZE (1 << KMMIO_PAGE_HASH_BITS)
+
+struct kmmio_fault_page {
+       struct list_head list;
+       struct kmmio_fault_page *release_next;
+       unsigned long page; /* location of the fault page */
+
+       /*
+        * Number of times this page has been registered as a part
+        * of a probe. If zero, page is disarmed and this may be freed.
+        * Used only by writers (RCU).
+        */
+       int count;
+};
+
+struct kmmio_delayed_release {
+       struct rcu_head rcu;
+       struct kmmio_fault_page *release_list;
+};
+
+struct kmmio_context {
+       struct kmmio_fault_page *fpage;
+       struct kmmio_probe *probe;
+       unsigned long saved_flags;
+       unsigned long addr;
+       int active;
+};
+
+static DEFINE_SPINLOCK(kmmio_lock);
+
+/* Protected by kmmio_lock */
+unsigned int kmmio_count;
+
+/* Read-protected by RCU, write-protected by kmmio_lock. */
+static struct list_head kmmio_page_table[KMMIO_PAGE_TABLE_SIZE];
+static LIST_HEAD(kmmio_probes);
+
+static struct list_head *kmmio_page_list(unsigned long page)
+{
+       return &kmmio_page_table[hash_long(page, KMMIO_PAGE_HASH_BITS)];
+}
+
+/* Accessed per-cpu */
+static DEFINE_PER_CPU(struct kmmio_context, kmmio_ctx);
+
+/*
+ * this is basically a dynamic stabbing problem:
+ * Could use the existing prio tree code or
+ * Possible better implementations:
+ * The Interval Skip List: A Data Structure for Finding All Intervals That
+ * Overlap a Point (might be simple)
+ * Space Efficient Dynamic Stabbing with Fast Queries - Mikkel Thorup
+ */
+/* Get the kmmio at this addr (if any). You must be holding RCU read lock. */
+static struct kmmio_probe *get_kmmio_probe(unsigned long addr)
+{
+       struct kmmio_probe *p;
+       list_for_each_entry_rcu(p, &kmmio_probes, list) {
+               if (addr >= p->addr && addr <= (p->addr + p->len))
+                       return p;
+       }
+       return NULL;
+}
+
+/* You must be holding RCU read lock. */
+static struct kmmio_fault_page *get_kmmio_fault_page(unsigned long page)
+{
+       struct list_head *head;
+       struct kmmio_fault_page *p;
+
+       page &= PAGE_MASK;
+       head = kmmio_page_list(page);
+       list_for_each_entry_rcu(p, head, list) {
+               if (p->page == page)
+                       return p;
+       }
+       return NULL;
+}
+
+static void set_page_present(unsigned long addr, bool present,
+                                                       unsigned int *pglevel)
+{
+       pteval_t pteval;
+       pmdval_t pmdval;
+       unsigned int level;
+       pmd_t *pmd;
+       pte_t *pte = lookup_address(addr, &level);
+
+       if (!pte) {
+               pr_err("kmmio: no pte for page 0x%08lx\n", addr);
+               return;
+       }
+
+       if (pglevel)
+               *pglevel = level;
+
+       switch (level) {
+       case PG_LEVEL_2M:
+               pmd = (pmd_t *)pte;
+               pmdval = pmd_val(*pmd) & ~_PAGE_PRESENT;
+               if (present)
+                       pmdval |= _PAGE_PRESENT;
+               set_pmd(pmd, __pmd(pmdval));
+               break;
+
+       case PG_LEVEL_4K:
+               pteval = pte_val(*pte) & ~_PAGE_PRESENT;
+               if (present)
+                       pteval |= _PAGE_PRESENT;
+               set_pte_atomic(pte, __pte(pteval));
+               break;
+
+       default:
+               pr_err("kmmio: unexpected page level 0x%x.\n", level);
+               return;
+       }
+
+       __flush_tlb_one(addr);
+}
+
+/** Mark the given page as not present. Access to it will trigger a fault. */
+static void arm_kmmio_fault_page(unsigned long page, unsigned int *pglevel)
+{
+       set_page_present(page & PAGE_MASK, false, pglevel);
+}
+
+/** Mark the given page as present. */
+static void disarm_kmmio_fault_page(unsigned long page, unsigned int *pglevel)
+{
+       set_page_present(page & PAGE_MASK, true, pglevel);
+}
+
+/*
+ * This is being called from do_page_fault().
+ *
+ * We may be in an interrupt or a critical section. Also prefecthing may
+ * trigger a page fault. We may be in the middle of process switch.
+ * We cannot take any locks, because we could be executing especially
+ * within a kmmio critical section.
+ *
+ * Local interrupts are disabled, so preemption cannot happen.
+ * Do not enable interrupts, do not sleep, and watch out for other CPUs.
+ */
+/*
+ * Interrupts are disabled on entry as trap3 is an interrupt gate
+ * and they remain disabled thorough out this function.
+ */
+int kmmio_handler(struct pt_regs *regs, unsigned long addr)
+{
+       struct kmmio_context *ctx;
+       struct kmmio_fault_page *faultpage;
+       int ret = 0; /* default to fault not handled */
+
+       /*
+        * Preemption is now disabled to prevent process switch during
+        * single stepping. We can only handle one active kmmio trace
+        * per cpu, so ensure that we finish it before something else
+        * gets to run. We also hold the RCU read lock over single
+        * stepping to avoid looking up the probe and kmmio_fault_page
+        * again.
+        */
+       preempt_disable();
+       rcu_read_lock();
+
+       faultpage = get_kmmio_fault_page(addr);
+       if (!faultpage) {
+               /*
+                * Either this page fault is not caused by kmmio, or
+                * another CPU just pulled the kmmio probe from under
+                * our feet. The latter case should not be possible.
+                */
+               goto no_kmmio;
+       }
+
+       ctx = &get_cpu_var(kmmio_ctx);
+       if (ctx->active) {
+               disarm_kmmio_fault_page(faultpage->page, NULL);
+               if (addr == ctx->addr) {
+                       /*
+                        * On SMP we sometimes get recursive probe hits on the
+                        * same address. Context is already saved, fall out.
+                        */
+                       pr_debug("kmmio: duplicate probe hit on CPU %d, for "
+                                               "address 0x%08lx.\n",
+                                               smp_processor_id(), addr);
+                       ret = 1;
+                       goto no_kmmio_ctx;
+               }
+               /*
+                * Prevent overwriting already in-flight context.
+                * This should not happen, let's hope disarming at least
+                * prevents a panic.
+                */
+               pr_emerg("kmmio: recursive probe hit on CPU %d, "
+                                       "for address 0x%08lx. Ignoring.\n",
+                                       smp_processor_id(), addr);
+               pr_emerg("kmmio: previous hit was at 0x%08lx.\n",
+                                       ctx->addr);
+               goto no_kmmio_ctx;
+       }
+       ctx->active++;
+
+       ctx->fpage = faultpage;
+       ctx->probe = get_kmmio_probe(addr);
+       ctx->saved_flags = (regs->flags & (X86_EFLAGS_TF | X86_EFLAGS_IF));
+       ctx->addr = addr;
+
+       if (ctx->probe && ctx->probe->pre_handler)
+               ctx->probe->pre_handler(ctx->probe, regs, addr);
+
+       /*
+        * Enable single-stepping and disable interrupts for the faulting
+        * context. Local interrupts must not get enabled during stepping.
+        */
+       regs->flags |= X86_EFLAGS_TF;
+       regs->flags &= ~X86_EFLAGS_IF;
+
+       /* Now we set present bit in PTE and single step. */
+       disarm_kmmio_fault_page(ctx->fpage->page, NULL);
+
+       /*
+        * If another cpu accesses the same page while we are stepping,
+        * the access will not be caught. It will simply succeed and the
+        * only downside is we lose the event. If this becomes a problem,
+        * the user should drop to single cpu before tracing.
+        */
+
+       put_cpu_var(kmmio_ctx);
+       return 1; /* fault handled */
+
+no_kmmio_ctx:
+       put_cpu_var(kmmio_ctx);
+no_kmmio:
+       rcu_read_unlock();
+       preempt_enable_no_resched();
+       return ret;
+}
+
+/*
+ * Interrupts are disabled on entry as trap1 is an interrupt gate
+ * and they remain disabled thorough out this function.
+ * This must always get called as the pair to kmmio_handler().
+ */
+static int post_kmmio_handler(unsigned long condition, struct pt_regs *regs)
+{
+       int ret = 0;
+       struct kmmio_context *ctx = &get_cpu_var(kmmio_ctx);
+
+       if (!ctx->active) {
+               pr_debug("kmmio: spurious debug trap on CPU %d.\n",
+                                                       smp_processor_id());
+               goto out;
+       }
+
+       if (ctx->probe && ctx->probe->post_handler)
+               ctx->probe->post_handler(ctx->probe, condition, regs);
+
+       arm_kmmio_fault_page(ctx->fpage->page, NULL);
+
+       regs->flags &= ~X86_EFLAGS_TF;
+       regs->flags |= ctx->saved_flags;
+
+       /* These were acquired in kmmio_handler(). */
+       ctx->active--;
+       BUG_ON(ctx->active);
+       rcu_read_unlock();
+       preempt_enable_no_resched();
+
+       /*
+        * if somebody else is singlestepping across a probe point, flags
+        * will have TF set, in which case, continue the remaining processing
+        * of do_debug, as if this is not a probe hit.
+        */
+       if (!(regs->flags & X86_EFLAGS_TF))
+               ret = 1;
+out:
+       put_cpu_var(kmmio_ctx);
+       return ret;
+}
+
+/* You must be holding kmmio_lock. */
+static int add_kmmio_fault_page(unsigned long page)
+{
+       struct kmmio_fault_page *f;
+
+       page &= PAGE_MASK;
+       f = get_kmmio_fault_page(page);
+       if (f) {
+               if (!f->count)
+                       arm_kmmio_fault_page(f->page, NULL);
+               f->count++;
+               return 0;
+       }
+
+       f = kmalloc(sizeof(*f), GFP_ATOMIC);
+       if (!f)
+               return -1;
+
+       f->count = 1;
+       f->page = page;
+       list_add_rcu(&f->list, kmmio_page_list(f->page));
+
+       arm_kmmio_fault_page(f->page, NULL);
+
+       return 0;
+}
+
+/* You must be holding kmmio_lock. */
+static void release_kmmio_fault_page(unsigned long page,
+                               struct kmmio_fault_page **release_list)
+{
+       struct kmmio_fault_page *f;
+
+       page &= PAGE_MASK;
+       f = get_kmmio_fault_page(page);
+       if (!f)
+               return;
+
+       f->count--;
+       BUG_ON(f->count < 0);
+       if (!f->count) {
+               disarm_kmmio_fault_page(f->page, NULL);
+               f->release_next = *release_list;
+               *release_list = f;
+       }
+}
+
+/*
+ * With page-unaligned ioremaps, one or two armed pages may contain
+ * addresses from outside the intended mapping. Events for these addresses
+ * are currently silently dropped. The events may result only from programming
+ * mistakes by accessing addresses before the beginning or past the end of a
+ * mapping.
+ */
+int register_kmmio_probe(struct kmmio_probe *p)
+{
+       unsigned long flags;
+       int ret = 0;
+       unsigned long size = 0;
+       const unsigned long size_lim = p->len + (p->addr & ~PAGE_MASK);
+
+       spin_lock_irqsave(&kmmio_lock, flags);
+       if (get_kmmio_probe(p->addr)) {
+               ret = -EEXIST;
+               goto out;
+       }
+       kmmio_count++;
+       list_add_rcu(&p->list, &kmmio_probes);
+       while (size < size_lim) {
+               if (add_kmmio_fault_page(p->addr + size))
+                       pr_err("kmmio: Unable to set page fault.\n");
+               size += PAGE_SIZE;
+       }
+out:
+       spin_unlock_irqrestore(&kmmio_lock, flags);
+       /*
+        * XXX: What should I do here?
+        * Here was a call to global_flush_tlb(), but it does not exist
+        * anymore. It seems it's not needed after all.
+        */
+       return ret;
+}
+EXPORT_SYMBOL(register_kmmio_probe);
+
+static void rcu_free_kmmio_fault_pages(struct rcu_head *head)
+{
+       struct kmmio_delayed_release *dr = container_of(
+                                               head,
+                                               struct kmmio_delayed_release,
+                                               rcu);
+       struct kmmio_fault_page *p = dr->release_list;
+       while (p) {
+               struct kmmio_fault_page *next = p->release_next;
+               BUG_ON(p->count);
+               kfree(p);
+               p = next;
+       }
+       kfree(dr);
+}
+
+static void remove_kmmio_fault_pages(struct rcu_head *head)
+{
+       struct kmmio_delayed_release *dr = container_of(
+                                               head,
+                                               struct kmmio_delayed_release,
+                                               rcu);
+       struct kmmio_fault_page *p = dr->release_list;
+       struct kmmio_fault_page **prevp = &dr->release_list;
+       unsigned long flags;
+       spin_lock_irqsave(&kmmio_lock, flags);
+       while (p) {
+               if (!p->count)
+                       list_del_rcu(&p->list);
+               else
+                       *prevp = p->release_next;
+               prevp = &p->release_next;
+               p = p->release_next;
+       }
+       spin_unlock_irqrestore(&kmmio_lock, flags);
+       /* This is the real RCU destroy call. */
+       call_rcu(&dr->rcu, rcu_free_kmmio_fault_pages);
+}
+
+/*
+ * Remove a kmmio probe. You have to synchronize_rcu() before you can be
+ * sure that the callbacks will not be called anymore. Only after that
+ * you may actually release your struct kmmio_probe.
+ *
+ * Unregistering a kmmio fault page has three steps:
+ * 1. release_kmmio_fault_page()
+ *    Disarm the page, wait a grace period to let all faults finish.
+ * 2. remove_kmmio_fault_pages()
+ *    Remove the pages from kmmio_page_table.
+ * 3. rcu_free_kmmio_fault_pages()
+ *    Actally free the kmmio_fault_page structs as with RCU.
+ */
+void unregister_kmmio_probe(struct kmmio_probe *p)
+{
+       unsigned long flags;
+       unsigned long size = 0;
+       const unsigned long size_lim = p->len + (p->addr & ~PAGE_MASK);
+       struct kmmio_fault_page *release_list = NULL;
+       struct kmmio_delayed_release *drelease;
+
+       spin_lock_irqsave(&kmmio_lock, flags);
+       while (size < size_lim) {
+               release_kmmio_fault_page(p->addr + size, &release_list);
+               size += PAGE_SIZE;
+       }
+       list_del_rcu(&p->list);
+       kmmio_count--;
+       spin_unlock_irqrestore(&kmmio_lock, flags);
+
+       drelease = kmalloc(sizeof(*drelease), GFP_ATOMIC);
+       if (!drelease) {
+               pr_crit("kmmio: leaking kmmio_fault_page objects.\n");
+               return;
+       }
+       drelease->release_list = release_list;
+
+       /*
+        * This is not really RCU here. We have just disarmed a set of
+        * pages so that they cannot trigger page faults anymore. However,
+        * we cannot remove the pages from kmmio_page_table,
+        * because a probe hit might be in flight on another CPU. The
+        * pages are collected into a list, and they will be removed from
+        * kmmio_page_table when it is certain that no probe hit related to
+        * these pages can be in flight. RCU grace period sounds like a
+        * good choice.
+        *
+        * If we removed the pages too early, kmmio page fault handler might
+        * not find the respective kmmio_fault_page and determine it's not
+        * a kmmio fault, when it actually is. This would lead to madness.
+        */
+       call_rcu(&drelease->rcu, remove_kmmio_fault_pages);
+}
+EXPORT_SYMBOL(unregister_kmmio_probe);
+
+static int kmmio_die_notifier(struct notifier_block *nb, unsigned long val,
+                                                               void *args)
+{
+       struct die_args *arg = args;
+
+       if (val == DIE_DEBUG && (arg->err & DR_STEP))
+               if (post_kmmio_handler(arg->err, arg->regs) == 1)
+                       return NOTIFY_STOP;
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block nb_die = {
+       .notifier_call = kmmio_die_notifier
+};
+
+static int __init init_kmmio(void)
+{
+       int i;
+       for (i = 0; i < KMMIO_PAGE_TABLE_SIZE; i++)
+               INIT_LIST_HEAD(&kmmio_page_table[i]);
+       return register_die_notifier(&nb_die);
+}
+fs_initcall(init_kmmio); /* should be before device_initcall() */
diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
new file mode 100644 (file)
index 0000000..e7397e1
--- /dev/null
@@ -0,0 +1,515 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2005
+ *               Jeff Muizelaar, 2006, 2007
+ *               Pekka Paalanen, 2008 <pq@iki.fi>
+ *
+ * Derived from the read-mod example from relay-examples by Tom Zanussi.
+ */
+#define DEBUG 1
+
+#include <linux/module.h>
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+#include <linux/version.h>
+#include <linux/kallsyms.h>
+#include <asm/pgtable.h>
+#include <linux/mmiotrace.h>
+#include <asm/e820.h> /* for ISA_START_ADDRESS */
+#include <asm/atomic.h>
+#include <linux/percpu.h>
+#include <linux/cpu.h>
+
+#include "pf_in.h"
+
+#define NAME "mmiotrace: "
+
+struct trap_reason {
+       unsigned long addr;
+       unsigned long ip;
+       enum reason_type type;
+       int active_traces;
+};
+
+struct remap_trace {
+       struct list_head list;
+       struct kmmio_probe probe;
+       resource_size_t phys;
+       unsigned long id;
+};
+
+/* Accessed per-cpu. */
+static DEFINE_PER_CPU(struct trap_reason, pf_reason);
+static DEFINE_PER_CPU(struct mmiotrace_rw, cpu_trace);
+
+#if 0 /* XXX: no way gather this info anymore */
+/* Access to this is not per-cpu. */
+static DEFINE_PER_CPU(atomic_t, dropped);
+#endif
+
+static struct dentry *marker_file;
+
+static DEFINE_MUTEX(mmiotrace_mutex);
+static DEFINE_SPINLOCK(trace_lock);
+static atomic_t mmiotrace_enabled;
+static LIST_HEAD(trace_list);          /* struct remap_trace */
+
+/*
+ * Locking in this file:
+ * - mmiotrace_mutex enforces enable/disable_mmiotrace() critical sections.
+ * - mmiotrace_enabled may be modified only when holding mmiotrace_mutex
+ *   and trace_lock.
+ * - Routines depending on is_enabled() must take trace_lock.
+ * - trace_list users must hold trace_lock.
+ * - is_enabled() guarantees that mmio_trace_record is allowed.
+ * - pre/post callbacks assume the effect of is_enabled() being true.
+ */
+
+/* module parameters */
+static unsigned long   filter_offset;
+static int             nommiotrace;
+static int             trace_pc;
+
+module_param(filter_offset, ulong, 0);
+module_param(nommiotrace, bool, 0);
+module_param(trace_pc, bool, 0);
+
+MODULE_PARM_DESC(filter_offset, "Start address of traced mappings.");
+MODULE_PARM_DESC(nommiotrace, "Disable actual MMIO tracing.");
+MODULE_PARM_DESC(trace_pc, "Record address of faulting instructions.");
+
+static bool is_enabled(void)
+{
+       return atomic_read(&mmiotrace_enabled);
+}
+
+#if 0 /* XXX: needs rewrite */
+/*
+ * Write callback for the debugfs entry:
+ * Read a marker and write it to the mmio trace log
+ */
+static ssize_t write_marker(struct file *file, const char __user *buffer,
+                                               size_t count, loff_t *ppos)
+{
+       char *event = NULL;
+       struct mm_io_header *headp;
+       ssize_t len = (count > 65535) ? 65535 : count;
+
+       event = kzalloc(sizeof(*headp) + len, GFP_KERNEL);
+       if (!event)
+               return -ENOMEM;
+
+       headp = (struct mm_io_header *)event;
+       headp->type = MMIO_MAGIC | (MMIO_MARKER << MMIO_OPCODE_SHIFT);
+       headp->data_len = len;
+
+       if (copy_from_user(event + sizeof(*headp), buffer, len)) {
+               kfree(event);
+               return -EFAULT;
+       }
+
+       spin_lock_irq(&trace_lock);
+#if 0 /* XXX: convert this to use tracing */
+       if (is_enabled())
+               relay_write(chan, event, sizeof(*headp) + len);
+       else
+#endif
+               len = -EINVAL;
+       spin_unlock_irq(&trace_lock);
+       kfree(event);
+       return len;
+}
+#endif
+
+static void print_pte(unsigned long address)
+{
+       unsigned int level;
+       pte_t *pte = lookup_address(address, &level);
+
+       if (!pte) {
+               pr_err(NAME "Error in %s: no pte for page 0x%08lx\n",
+                                                       __func__, address);
+               return;
+       }
+
+       if (level == PG_LEVEL_2M) {
+               pr_emerg(NAME "4MB pages are not currently supported: "
+                                                       "0x%08lx\n", address);
+               BUG();
+       }
+       pr_info(NAME "pte for 0x%lx: 0x%llx 0x%llx\n", address,
+               (unsigned long long)pte_val(*pte),
+               (unsigned long long)pte_val(*pte) & _PAGE_PRESENT);
+}
+
+/*
+ * For some reason the pre/post pairs have been called in an
+ * unmatched order. Report and die.
+ */
+static void die_kmmio_nesting_error(struct pt_regs *regs, unsigned long addr)
+{
+       const struct trap_reason *my_reason = &get_cpu_var(pf_reason);
+       pr_emerg(NAME "unexpected fault for address: 0x%08lx, "
+                                       "last fault for address: 0x%08lx\n",
+                                       addr, my_reason->addr);
+       print_pte(addr);
+       print_symbol(KERN_EMERG "faulting IP is at %s\n", regs->ip);
+       print_symbol(KERN_EMERG "last faulting IP was at %s\n", my_reason->ip);
+#ifdef __i386__
+       pr_emerg("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
+                       regs->ax, regs->bx, regs->cx, regs->dx);
+       pr_emerg("esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",
+                       regs->si, regs->di, regs->bp, regs->sp);
+#else
+       pr_emerg("rax: %016lx   rcx: %016lx   rdx: %016lx\n",
+                                       regs->ax, regs->cx, regs->dx);
+       pr_emerg("rsi: %016lx   rdi: %016lx   rbp: %016lx   rsp: %016lx\n",
+                               regs->si, regs->di, regs->bp, regs->sp);
+#endif
+       put_cpu_var(pf_reason);
+       BUG();
+}
+
+static void pre(struct kmmio_probe *p, struct pt_regs *regs,
+                                               unsigned long addr)
+{
+       struct trap_reason *my_reason = &get_cpu_var(pf_reason);
+       struct mmiotrace_rw *my_trace = &get_cpu_var(cpu_trace);
+       const unsigned long instptr = instruction_pointer(regs);
+       const enum reason_type type = get_ins_type(instptr);
+       struct remap_trace *trace = p->private;
+
+       /* it doesn't make sense to have more than one active trace per cpu */
+       if (my_reason->active_traces)
+               die_kmmio_nesting_error(regs, addr);
+       else
+               my_reason->active_traces++;
+
+       my_reason->type = type;
+       my_reason->addr = addr;
+       my_reason->ip = instptr;
+
+       my_trace->phys = addr - trace->probe.addr + trace->phys;
+       my_trace->map_id = trace->id;
+
+       /*
+        * Only record the program counter when requested.
+        * It may taint clean-room reverse engineering.
+        */
+       if (trace_pc)
+               my_trace->pc = instptr;
+       else
+               my_trace->pc = 0;
+
+       /*
+        * XXX: the timestamp recorded will be *after* the tracing has been
+        * done, not at the time we hit the instruction. SMP implications
+        * on event ordering?
+        */
+
+       switch (type) {
+       case REG_READ:
+               my_trace->opcode = MMIO_READ;
+               my_trace->width = get_ins_mem_width(instptr);
+               break;
+       case REG_WRITE:
+               my_trace->opcode = MMIO_WRITE;
+               my_trace->width = get_ins_mem_width(instptr);
+               my_trace->value = get_ins_reg_val(instptr, regs);
+               break;
+       case IMM_WRITE:
+               my_trace->opcode = MMIO_WRITE;
+               my_trace->width = get_ins_mem_width(instptr);
+               my_trace->value = get_ins_imm_val(instptr);
+               break;
+       default:
+               {
+                       unsigned char *ip = (unsigned char *)instptr;
+                       my_trace->opcode = MMIO_UNKNOWN_OP;
+                       my_trace->width = 0;
+                       my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
+                                                               *(ip + 2);
+               }
+       }
+       put_cpu_var(cpu_trace);
+       put_cpu_var(pf_reason);
+}
+
+static void post(struct kmmio_probe *p, unsigned long condition,
+                                                       struct pt_regs *regs)
+{
+       struct trap_reason *my_reason = &get_cpu_var(pf_reason);
+       struct mmiotrace_rw *my_trace = &get_cpu_var(cpu_trace);
+
+       /* this should always return the active_trace count to 0 */
+       my_reason->active_traces--;
+       if (my_reason->active_traces) {
+               pr_emerg(NAME "unexpected post handler");
+               BUG();
+       }
+
+       switch (my_reason->type) {
+       case REG_READ:
+               my_trace->value = get_ins_reg_val(my_reason->ip, regs);
+               break;
+       default:
+               break;
+       }
+
+       mmio_trace_rw(my_trace);
+       put_cpu_var(cpu_trace);
+       put_cpu_var(pf_reason);
+}
+
+static void ioremap_trace_core(resource_size_t offset, unsigned long size,
+                                                       void __iomem *addr)
+{
+       static atomic_t next_id;
+       struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
+       /* These are page-unaligned. */
+       struct mmiotrace_map map = {
+               .phys = offset,
+               .virt = (unsigned long)addr,
+               .len = size,
+               .opcode = MMIO_PROBE
+       };
+
+       if (!trace) {
+               pr_err(NAME "kmalloc failed in ioremap\n");
+               return;
+       }
+
+       *trace = (struct remap_trace) {
+               .probe = {
+                       .addr = (unsigned long)addr,
+                       .len = size,
+                       .pre_handler = pre,
+                       .post_handler = post,
+                       .private = trace
+               },
+               .phys = offset,
+               .id = atomic_inc_return(&next_id)
+       };
+       map.map_id = trace->id;
+
+       spin_lock_irq(&trace_lock);
+       if (!is_enabled())
+               goto not_enabled;
+
+       mmio_trace_mapping(&map);
+       list_add_tail(&trace->list, &trace_list);
+       if (!nommiotrace)
+               register_kmmio_probe(&trace->probe);
+
+not_enabled:
+       spin_unlock_irq(&trace_lock);
+}
+
+void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
+                                               void __iomem *addr)
+{
+       if (!is_enabled()) /* recheck and proper locking in *_core() */
+               return;
+
+       pr_debug(NAME "ioremap_*(0x%llx, 0x%lx) = %p\n",
+                               (unsigned long long)offset, size, addr);
+       if ((filter_offset) && (offset != filter_offset))
+               return;
+       ioremap_trace_core(offset, size, addr);
+}
+
+static void iounmap_trace_core(volatile void __iomem *addr)
+{
+       struct mmiotrace_map map = {
+               .phys = 0,
+               .virt = (unsigned long)addr,
+               .len = 0,
+               .opcode = MMIO_UNPROBE
+       };
+       struct remap_trace *trace;
+       struct remap_trace *tmp;
+       struct remap_trace *found_trace = NULL;
+
+       pr_debug(NAME "Unmapping %p.\n", addr);
+
+       spin_lock_irq(&trace_lock);
+       if (!is_enabled())
+               goto not_enabled;
+
+       list_for_each_entry_safe(trace, tmp, &trace_list, list) {
+               if ((unsigned long)addr == trace->probe.addr) {
+                       if (!nommiotrace)
+                               unregister_kmmio_probe(&trace->probe);
+                       list_del(&trace->list);
+                       found_trace = trace;
+                       break;
+               }
+       }
+       map.map_id = (found_trace) ? found_trace->id : -1;
+       mmio_trace_mapping(&map);
+
+not_enabled:
+       spin_unlock_irq(&trace_lock);
+       if (found_trace) {
+               synchronize_rcu(); /* unregister_kmmio_probe() requirement */
+               kfree(found_trace);
+       }
+}
+
+void mmiotrace_iounmap(volatile void __iomem *addr)
+{
+       might_sleep();
+       if (is_enabled()) /* recheck and proper locking in *_core() */
+               iounmap_trace_core(addr);
+}
+
+static void clear_trace_list(void)
+{
+       struct remap_trace *trace;
+       struct remap_trace *tmp;
+
+       /*
+        * No locking required, because the caller ensures we are in a
+        * critical section via mutex, and is_enabled() is false,
+        * i.e. nothing can traverse or modify this list.
+        * Caller also ensures is_enabled() cannot change.
+        */
+       list_for_each_entry(trace, &trace_list, list) {
+               pr_notice(NAME "purging non-iounmapped "
+                                       "trace @0x%08lx, size 0x%lx.\n",
+                                       trace->probe.addr, trace->probe.len);
+               if (!nommiotrace)
+                       unregister_kmmio_probe(&trace->probe);
+       }
+       synchronize_rcu(); /* unregister_kmmio_probe() requirement */
+
+       list_for_each_entry_safe(trace, tmp, &trace_list, list) {
+               list_del(&trace->list);
+               kfree(trace);
+       }
+}
+
+#ifdef CONFIG_HOTPLUG_CPU
+static cpumask_t downed_cpus;
+
+static void enter_uniprocessor(void)
+{
+       int cpu;
+       int err;
+
+       get_online_cpus();
+       downed_cpus = cpu_online_map;
+       cpu_clear(first_cpu(cpu_online_map), downed_cpus);
+       if (num_online_cpus() > 1)
+               pr_notice(NAME "Disabling non-boot CPUs...\n");
+       put_online_cpus();
+
+       for_each_cpu_mask(cpu, downed_cpus) {
+               err = cpu_down(cpu);
+               if (!err)
+                       pr_info(NAME "CPU%d is down.\n", cpu);
+               else
+                       pr_err(NAME "Error taking CPU%d down: %d\n", cpu, err);
+       }
+       if (num_online_cpus() > 1)
+               pr_warning(NAME "multiple CPUs still online, "
+                                               "may miss events.\n");
+}
+
+static void leave_uniprocessor(void)
+{
+       int cpu;
+       int err;
+
+       if (cpus_weight(downed_cpus) == 0)
+               return;
+       pr_notice(NAME "Re-enabling CPUs...\n");
+       for_each_cpu_mask(cpu, downed_cpus) {
+               err = cpu_up(cpu);
+               if (!err)
+                       pr_info(NAME "enabled CPU%d.\n", cpu);
+               else
+                       pr_err(NAME "cannot re-enable CPU%d: %d\n", cpu, err);
+       }
+}
+
+#else /* !CONFIG_HOTPLUG_CPU */
+static void enter_uniprocessor(void)
+{
+       if (num_online_cpus() > 1)
+               pr_warning(NAME "multiple CPUs are online, may miss events. "
+                       "Suggest booting with maxcpus=1 kernel argument.\n");
+}
+
+static void leave_uniprocessor(void)
+{
+}
+#endif
+
+#if 0 /* XXX: out of order */
+static struct file_operations fops_marker = {
+       .owner =        THIS_MODULE,
+       .write =        write_marker
+};
+#endif
+
+void enable_mmiotrace(void)
+{
+       mutex_lock(&mmiotrace_mutex);
+       if (is_enabled())
+               goto out;
+
+#if 0 /* XXX: tracing does not support text entries */
+       marker_file = debugfs_create_file("marker", 0660, dir, NULL,
+                                                               &fops_marker);
+       if (!marker_file)
+               pr_err(NAME "marker file creation failed.\n");
+#endif
+
+       if (nommiotrace)
+               pr_info(NAME "MMIO tracing disabled.\n");
+       enter_uniprocessor();
+       spin_lock_irq(&trace_lock);
+       atomic_inc(&mmiotrace_enabled);
+       spin_unlock_irq(&trace_lock);
+       pr_info(NAME "enabled.\n");
+out:
+       mutex_unlock(&mmiotrace_mutex);
+}
+
+void disable_mmiotrace(void)
+{
+       mutex_lock(&mmiotrace_mutex);
+       if (!is_enabled())
+               goto out;
+
+       spin_lock_irq(&trace_lock);
+       atomic_dec(&mmiotrace_enabled);
+       BUG_ON(is_enabled());
+       spin_unlock_irq(&trace_lock);
+
+       clear_trace_list(); /* guarantees: no more kmmio callbacks */
+       leave_uniprocessor();
+       if (marker_file) {
+               debugfs_remove(marker_file);
+               marker_file = NULL;
+       }
+
+       pr_info(NAME "disabled.\n");
+out:
+       mutex_unlock(&mmiotrace_mutex);
+}
index c5066d5..b432d57 100644 (file)
 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
 EXPORT_SYMBOL(node_data);
 
-bootmem_data_t plat_node_bdata[MAX_NUMNODES];
+static bootmem_data_t plat_node_bdata[MAX_NUMNODES];
 
 struct memnode memnode;
 
-#ifdef CONFIG_SMP
-int x86_cpu_to_node_map_init[NR_CPUS] = {
-       [0 ... NR_CPUS-1] = NUMA_NO_NODE
-};
-void *x86_cpu_to_node_map_early_ptr;
-EXPORT_SYMBOL(x86_cpu_to_node_map_early_ptr);
-#endif
-DEFINE_PER_CPU(int, x86_cpu_to_node_map) = NUMA_NO_NODE;
-EXPORT_PER_CPU_SYMBOL(x86_cpu_to_node_map);
-
 s16 apicid_to_node[MAX_LOCAL_APIC] __cpuinitdata = {
        [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
 };
 
-cpumask_t node_to_cpumask_map[MAX_NUMNODES] __read_mostly;
-EXPORT_SYMBOL(node_to_cpumask_map);
-
 int numa_off __initdata;
-unsigned long __initdata nodemap_addr;
-unsigned long __initdata nodemap_size;
+static unsigned long __initdata nodemap_addr;
+static unsigned long __initdata nodemap_size;
 
 /*
  * Given a shift value, try to populate memnodemap[]
@@ -99,7 +86,7 @@ static int __init allocate_cachealigned_memnodemap(void)
 
        addr = 0x8000;
        nodemap_size = round_up(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
-       nodemap_addr = find_e820_area(addr, end_pfn<<PAGE_SHIFT,
+       nodemap_addr = find_e820_area(addr, max_pfn<<PAGE_SHIFT,
                                      nodemap_size, L1_CACHE_BYTES);
        if (nodemap_addr == -1UL) {
                printk(KERN_ERR
@@ -192,7 +179,7 @@ static void * __init early_node_mem(int nodeid, unsigned long start,
 void __init setup_node_bootmem(int nodeid, unsigned long start,
                               unsigned long end)
 {
-       unsigned long start_pfn, end_pfn, bootmap_pages, bootmap_size;
+       unsigned long start_pfn, last_pfn, bootmap_pages, bootmap_size;
        unsigned long bootmap_start, nodedata_phys;
        void *bootmap;
        const int pgdat_size = round_up(sizeof(pg_data_t), PAGE_SIZE);
@@ -204,7 +191,7 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
               start, end);
 
        start_pfn = start >> PAGE_SHIFT;
-       end_pfn = end >> PAGE_SHIFT;
+       last_pfn = end >> PAGE_SHIFT;
 
        node_data[nodeid] = early_node_mem(nodeid, start, end, pgdat_size,
                                           SMP_CACHE_BYTES);
@@ -217,7 +204,7 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
        memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
        NODE_DATA(nodeid)->bdata = &plat_node_bdata[nodeid];
        NODE_DATA(nodeid)->node_start_pfn = start_pfn;
-       NODE_DATA(nodeid)->node_spanned_pages = end_pfn - start_pfn;
+       NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
 
        /*
         * Find a place for the bootmem map
@@ -226,14 +213,14 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
         * early_node_mem will get that with find_e820_area instead
         * of alloc_bootmem, that could clash with reserved range
         */
-       bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
+       bootmap_pages = bootmem_bootmap_pages(last_pfn - start_pfn);
        nid = phys_to_nid(nodedata_phys);
        if (nid == nodeid)
                bootmap_start = round_up(nodedata_phys + pgdat_size, PAGE_SIZE);
        else
                bootmap_start = round_up(start, PAGE_SIZE);
        /*
-        * SMP_CAHCE_BYTES could be enough, but init_bootmem_node like
+        * SMP_CACHE_BYTES could be enough, but init_bootmem_node like
         * to use that to align to PAGE_SIZE
         */
        bootmap = early_node_mem(nodeid, bootmap_start, end,
@@ -248,7 +235,7 @@ void __init setup_node_bootmem(int nodeid, unsigned long start,
 
        bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
                                         bootmap_start >> PAGE_SHIFT,
-                                        start_pfn, end_pfn);
+                                        start_pfn, last_pfn);
 
        printk(KERN_INFO "  bootmap [%016lx -  %016lx] pages %lx\n",
                 bootmap_start, bootmap_start + bootmap_size - 1,
@@ -309,7 +296,7 @@ void __init numa_init_array(void)
 
 #ifdef CONFIG_NUMA_EMU
 /* Numa emulation */
-char *cmdline __initdata;
+static char *cmdline __initdata;
 
 /*
  * Setups up nid to range from addr to addr + size.  If the end
@@ -413,15 +400,15 @@ static int __init split_nodes_by_size(struct bootnode *nodes, u64 *addr,
 }
 
 /*
- * Sets up the system RAM area from start_pfn to end_pfn according to the
+ * Sets up the system RAM area from start_pfn to last_pfn according to the
  * numa=fake command-line option.
  */
 static struct bootnode nodes[MAX_NUMNODES] __initdata;
 
-static int __init numa_emulation(unsigned long start_pfn, unsigned long end_pfn)
+static int __init numa_emulation(unsigned long start_pfn, unsigned long last_pfn)
 {
        u64 size, addr = start_pfn << PAGE_SHIFT;
-       u64 max_addr = end_pfn << PAGE_SHIFT;
+       u64 max_addr = last_pfn << PAGE_SHIFT;
        int num_nodes = 0, num = 0, coeff_flag, coeff = -1, i;
 
        memset(&nodes, 0, sizeof(nodes));
@@ -527,7 +514,7 @@ out:
 }
 #endif /* CONFIG_NUMA_EMU */
 
-void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
+void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn)
 {
        int i;
 
@@ -535,7 +522,7 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
        nodes_clear(node_online_map);
 
 #ifdef CONFIG_NUMA_EMU
-       if (cmdline && !numa_emulation(start_pfn, end_pfn))
+       if (cmdline && !numa_emulation(start_pfn, last_pfn))
                return;
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
@@ -543,7 +530,7 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
 
 #ifdef CONFIG_ACPI_NUMA
        if (!numa_off && !acpi_scan_nodes(start_pfn << PAGE_SHIFT,
-                                         end_pfn << PAGE_SHIFT))
+                                         last_pfn << PAGE_SHIFT))
                return;
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
@@ -551,7 +538,7 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
 
 #ifdef CONFIG_K8_NUMA
        if (!numa_off && !k8_scan_nodes(start_pfn<<PAGE_SHIFT,
-                                       end_pfn<<PAGE_SHIFT))
+                                       last_pfn<<PAGE_SHIFT))
                return;
        nodes_clear(node_possible_map);
        nodes_clear(node_online_map);
@@ -561,7 +548,7 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
 
        printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
               start_pfn << PAGE_SHIFT,
-              end_pfn << PAGE_SHIFT);
+              last_pfn << PAGE_SHIFT);
        /* setup dummy node covering all memory */
        memnode_shift = 63;
        memnodemap = memnode.embedded_map;
@@ -570,29 +557,8 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
        node_set(0, node_possible_map);
        for (i = 0; i < NR_CPUS; i++)
                numa_set_node(i, 0);
-       /* cpumask_of_cpu() may not be available during early startup */
-       memset(&node_to_cpumask_map[0], 0, sizeof(node_to_cpumask_map[0]));
-       cpu_set(0, node_to_cpumask_map[0]);
-       e820_register_active_regions(0, start_pfn, end_pfn);
-       setup_node_bootmem(0, start_pfn << PAGE_SHIFT, end_pfn << PAGE_SHIFT);
-}
-
-__cpuinit void numa_add_cpu(int cpu)
-{
-       set_bit(cpu,
-               (unsigned long *)&node_to_cpumask_map[early_cpu_to_node(cpu)]);
-}
-
-void __cpuinit numa_set_node(int cpu, int node)
-{
-       int *cpu_to_node_map = x86_cpu_to_node_map_early_ptr;
-
-       if(cpu_to_node_map)
-               cpu_to_node_map[cpu] = node;
-       else if(per_cpu_offset(cpu))
-               per_cpu(x86_cpu_to_node_map, cpu) = node;
-       else
-               Dprintk(KERN_INFO "Setting node for non-present cpu %d\n", cpu);
+       e820_register_active_regions(0, start_pfn, last_pfn);
+       setup_node_bootmem(0, start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT);
 }
 
 unsigned long __init numa_free_all_bootmem(void)
@@ -613,7 +579,7 @@ void __init paging_init(void)
        memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
        max_zone_pfns[ZONE_DMA] = MAX_DMA_PFN;
        max_zone_pfns[ZONE_DMA32] = MAX_DMA32_PFN;
-       max_zone_pfns[ZONE_NORMAL] = end_pfn;
+       max_zone_pfns[ZONE_NORMAL] = max_pfn;
 
        sparse_memory_present_with_active_regions(MAX_NUMNODES);
        sparse_init();
@@ -641,6 +607,7 @@ static __init int numa_setup(char *opt)
 }
 early_param("numa", numa_setup);
 
+#ifdef CONFIG_NUMA
 /*
  * Setup early cpu_to_node.
  *
@@ -652,14 +619,19 @@ early_param("numa", numa_setup);
  * is already initialized in a round robin manner at numa_init_array,
  * prior to this call, and this initialization is good enough
  * for the fake NUMA cases.
+ *
+ * Called before the per_cpu areas are setup.
  */
 void __init init_cpu_to_node(void)
 {
-       int i;
+       int cpu;
+       u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
 
-       for (i = 0; i < NR_CPUS; i++) {
+       BUG_ON(cpu_to_apicid == NULL);
+
+       for_each_possible_cpu(cpu) {
                int node;
-               u16 apicid = x86_cpu_to_apicid_init[i];
+               u16 apicid = cpu_to_apicid[cpu];
 
                if (apicid == BAD_APICID)
                        continue;
@@ -668,8 +640,9 @@ void __init init_cpu_to_node(void)
                        continue;
                if (!node_online(node))
                        continue;
-               numa_set_node(i, node);
+               numa_set_node(cpu, node);
        }
 }
+#endif
 
 
index 75f1b10..0dcd42e 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * self test for change_page_attr.
  *
- * Clears the global bit on random pages in the direct mapping, then reverts
- * and compares page tables forwards and afterwards.
+ * Clears the a test pte bit on random pages in the direct mapping,
+ * then reverts and compares page tables forwards and afterwards.
  */
 #include <linux/bootmem.h>
 #include <linux/kthread.h>
@@ -32,6 +32,13 @@ enum {
        GPS                     = (1<<30)
 };
 
+#define PAGE_TESTBIT   __pgprot(_PAGE_UNUSED1)
+
+static int pte_testbit(pte_t pte)
+{
+       return pte_flags(pte) & _PAGE_UNUSED1;
+}
+
 struct split_state {
        long lpg, gpg, spg, exec;
        long min_exec, max_exec;
@@ -165,15 +172,14 @@ static int pageattr_test(void)
                        continue;
                }
 
-               err = change_page_attr_clear(addr[i], len[i],
-                                              __pgprot(_PAGE_GLOBAL));
+               err = change_page_attr_set(addr[i], len[i], PAGE_TESTBIT);
                if (err < 0) {
                        printk(KERN_ERR "CPA %d failed %d\n", i, err);
                        failed++;
                }
 
                pte = lookup_address(addr[i], &level);
-               if (!pte || pte_global(*pte) || pte_huge(*pte)) {
+               if (!pte || !pte_testbit(*pte) || pte_huge(*pte)) {
                        printk(KERN_ERR "CPA %lx: bad pte %Lx\n", addr[i],
                                pte ? (u64)pte_val(*pte) : 0ULL);
                        failed++;
@@ -198,14 +204,13 @@ static int pageattr_test(void)
                        failed++;
                        continue;
                }
-               err = change_page_attr_set(addr[i], len[i],
-                                            __pgprot(_PAGE_GLOBAL));
+               err = change_page_attr_clear(addr[i], len[i], PAGE_TESTBIT);
                if (err < 0) {
                        printk(KERN_ERR "CPA reverting failed: %d\n", err);
                        failed++;
                }
                pte = lookup_address(addr[i], &level);
-               if (!pte || !pte_global(*pte)) {
+               if (!pte || pte_testbit(*pte)) {
                        printk(KERN_ERR "CPA %lx: bad pte after revert %Lx\n",
                                addr[i], pte ? (u64)pte_val(*pte) : 0ULL);
                        failed++;
index 60bcb5b..47f4e2e 100644 (file)
@@ -34,6 +34,41 @@ struct cpa_data {
        unsigned        force_split : 1;
 };
 
+#ifdef CONFIG_PROC_FS
+static unsigned long direct_pages_count[PG_LEVEL_NUM];
+
+void update_page_count(int level, unsigned long pages)
+{
+       unsigned long flags;
+
+       /* Protect against CPA */
+       spin_lock_irqsave(&pgd_lock, flags);
+       direct_pages_count[level] += pages;
+       spin_unlock_irqrestore(&pgd_lock, flags);
+}
+
+static void split_page_count(int level)
+{
+       direct_pages_count[level]--;
+       direct_pages_count[level - 1] += PTRS_PER_PTE;
+}
+
+int arch_report_meminfo(char *page)
+{
+       int n = sprintf(page, "DirectMap4k:  %8lu\n"
+                       "DirectMap2M:  %8lu\n",
+                       direct_pages_count[PG_LEVEL_4K],
+                       direct_pages_count[PG_LEVEL_2M]);
+#ifdef CONFIG_X86_64
+       n += sprintf(page + n, "DirectMap1G:  %8lu\n",
+                    direct_pages_count[PG_LEVEL_1G]);
+#endif
+       return n;
+}
+#else
+static inline void split_page_count(int level) { }
+#endif
+
 #ifdef CONFIG_X86_64
 
 static inline unsigned long highmap_start_pfn(void)
@@ -227,6 +262,7 @@ pte_t *lookup_address(unsigned long address, unsigned int *level)
 
        return pte_offset_kernel(pmd, address);
 }
+EXPORT_SYMBOL_GPL(lookup_address);
 
 /*
  * Set the new pmd in all the pgds we know about:
@@ -500,6 +536,16 @@ static int split_large_page(pte_t *kpte, unsigned long address)
        for (i = 0; i < PTRS_PER_PTE; i++, pfn += pfninc)
                set_pte(&pbase[i], pfn_pte(pfn, ref_prot));
 
+       if (address >= (unsigned long)__va(0) &&
+               address < (unsigned long)__va(max_low_pfn_mapped << PAGE_SHIFT))
+               split_page_count(level);
+
+#ifdef CONFIG_X86_64
+       if (address >= (unsigned long)__va(1UL<<32) &&
+               address < (unsigned long)__va(max_pfn_mapped << PAGE_SHIFT))
+               split_page_count(level);
+#endif
+
        /*
         * Install the new, split up pagetable. Important details here:
         *
@@ -613,15 +659,24 @@ static int cpa_process_alias(struct cpa_data *cpa)
        struct cpa_data alias_cpa;
        int ret = 0;
 
-       if (cpa->pfn > max_pfn_mapped)
+       if (cpa->pfn >= max_pfn_mapped)
                return 0;
 
+#ifdef CONFIG_X86_64
+       if (cpa->pfn >= max_low_pfn_mapped && cpa->pfn < (1UL<<(32-PAGE_SHIFT)))
+               return 0;
+#endif
        /*
         * No need to redo, when the primary call touched the direct
         * mapping already:
         */
-       if (!within(cpa->vaddr, PAGE_OFFSET,
-                   PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT))) {
+       if (!(within(cpa->vaddr, PAGE_OFFSET,
+                   PAGE_OFFSET + (max_low_pfn_mapped << PAGE_SHIFT))
+#ifdef CONFIG_X86_64
+               || within(cpa->vaddr, PAGE_OFFSET + (1UL<<32),
+                   PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT))
+#endif
+       )) {
 
                alias_cpa = *cpa;
                alias_cpa.vaddr = (unsigned long) __va(cpa->pfn << PAGE_SHIFT);
@@ -805,7 +860,7 @@ int _set_memory_wc(unsigned long addr, int numpages)
 
 int set_memory_wc(unsigned long addr, int numpages)
 {
-       if (!pat_wc_enabled)
+       if (!pat_enabled)
                return set_memory_uc(addr, numpages);
 
        if (reserve_memtype(addr, addr + numpages * PAGE_SIZE,
index 06b7a1c..d458507 100644 (file)
 #include <asm/io.h>
 
 #ifdef CONFIG_X86_PAT
-int __read_mostly pat_wc_enabled = 1;
+int __read_mostly pat_enabled = 1;
 
 void __cpuinit pat_disable(char *reason)
 {
-       pat_wc_enabled = 0;
+       pat_enabled = 0;
        printk(KERN_INFO "%s\n", reason);
 }
 
@@ -42,6 +42,19 @@ static int __init nopat(char *str)
 early_param("nopat", nopat);
 #endif
 
+
+static int debug_enable;
+static int __init pat_debug_setup(char *str)
+{
+       debug_enable = 1;
+       return 0;
+}
+__setup("debugpat", pat_debug_setup);
+
+#define dprintk(fmt, arg...) \
+       do { if (debug_enable) printk(KERN_INFO fmt, ##arg); } while (0)
+
+
 static u64 __read_mostly boot_pat_state;
 
 enum {
@@ -53,24 +66,25 @@ enum {
        PAT_UC_MINUS = 7,       /* UC, but can be overriden by MTRR */
 };
 
-#define PAT(x,y)       ((u64)PAT_ ## y << ((x)*8))
+#define PAT(x, y)      ((u64)PAT_ ## y << ((x)*8))
 
 void pat_init(void)
 {
        u64 pat;
 
-       if (!pat_wc_enabled)
+       if (!pat_enabled)
                return;
 
        /* Paranoia check. */
-       if (!cpu_has_pat) {
-               printk(KERN_ERR "PAT enabled, but CPU feature cleared\n");
+       if (!cpu_has_pat && boot_pat_state) {
                /*
-                * Panic if this happens on the secondary CPU, and we
+                * If this happens we are on a secondary CPU, but
                 * switched to PAT on the boot CPU. We have no way to
                 * undo PAT.
-               */
-               BUG_ON(boot_pat_state);
+                */
+               printk(KERN_ERR "PAT enabled, "
+                      "but not supported by secondary CPU\n");
+               BUG();
        }
 
        /* Set PWT to Write-Combining. All other bits stay the same */
@@ -86,8 +100,8 @@ void pat_init(void)
         *      011 UC          _PAGE_CACHE_UC
         * PAT bit unused
         */
-       pat = PAT(0,WB) | PAT(1,WC) | PAT(2,UC_MINUS) | PAT(3,UC) |
-             PAT(4,WB) | PAT(5,WC) | PAT(6,UC_MINUS) | PAT(7,UC);
+       pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) |
+             PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, UC);
 
        /* Boot CPU check */
        if (!boot_pat_state)
@@ -103,11 +117,11 @@ void pat_init(void)
 static char *cattr_name(unsigned long flags)
 {
        switch (flags & _PAGE_CACHE_MASK) {
-               case _PAGE_CACHE_UC:            return "uncached";
-               case _PAGE_CACHE_UC_MINUS:      return "uncached-minus";
-               case _PAGE_CACHE_WB:            return "write-back";
-               case _PAGE_CACHE_WC:            return "write-combining";
-               default:                        return "broken";
+       case _PAGE_CACHE_UC:            return "uncached";
+       case _PAGE_CACHE_UC_MINUS:      return "uncached-minus";
+       case _PAGE_CACHE_WB:            return "write-back";
+       case _PAGE_CACHE_WC:            return "write-combining";
+       default:                        return "broken";
        }
 }
 
@@ -145,47 +159,50 @@ static DEFINE_SPINLOCK(memtype_lock);     /* protects memtype list */
  * The intersection is based on "Effective Memory Type" tables in IA-32
  * SDM vol 3a
  */
-static int pat_x_mtrr_type(u64 start, u64 end, unsigned long prot,
-                               unsigned long *ret_prot)
+static unsigned long pat_x_mtrr_type(u64 start, u64 end, unsigned long req_type)
 {
-       unsigned long pat_type;
-       u8 mtrr_type;
-
-       pat_type = prot & _PAGE_CACHE_MASK;
-       prot &= (~_PAGE_CACHE_MASK);
-
-       /*
-        * We return the PAT request directly for types where PAT takes
-        * precedence with respect to MTRR and for UC_MINUS.
-        * Consistency checks with other PAT requests is done later
-        * while going through memtype list.
-        */
-       if (pat_type == _PAGE_CACHE_WC) {
-               *ret_prot = prot | _PAGE_CACHE_WC;
-               return 0;
-       } else if (pat_type == _PAGE_CACHE_UC_MINUS) {
-               *ret_prot = prot | _PAGE_CACHE_UC_MINUS;
-               return 0;
-       } else if (pat_type == _PAGE_CACHE_UC) {
-               *ret_prot = prot | _PAGE_CACHE_UC;
-               return 0;
-       }
-
        /*
         * Look for MTRR hint to get the effective type in case where PAT
         * request is for WB.
         */
-       mtrr_type = mtrr_type_lookup(start, end);
+       if (req_type == _PAGE_CACHE_WB) {
+               u8 mtrr_type;
+
+               mtrr_type = mtrr_type_lookup(start, end);
+               if (mtrr_type == MTRR_TYPE_UNCACHABLE)
+                       return _PAGE_CACHE_UC;
+               if (mtrr_type == MTRR_TYPE_WRCOMB)
+                       return _PAGE_CACHE_WC;
+       }
 
-       if (mtrr_type == MTRR_TYPE_UNCACHABLE) {
-               *ret_prot = prot | _PAGE_CACHE_UC;
-       } else if (mtrr_type == MTRR_TYPE_WRCOMB) {
-               *ret_prot = prot | _PAGE_CACHE_WC;
-       } else {
-               *ret_prot = prot | _PAGE_CACHE_WB;
+       return req_type;
+}
+
+static int chk_conflict(struct memtype *new, struct memtype *entry,
+                       unsigned long *type)
+{
+       if (new->type != entry->type) {
+               if (type) {
+                       new->type = entry->type;
+                       *type = entry->type;
+               } else
+                       goto conflict;
        }
 
+        /* check overlaps with more than one entry in the list */
+       list_for_each_entry_continue(entry, &memtype_list, nd) {
+               if (new->end <= entry->start)
+                       break;
+               else if (new->type != entry->type)
+                       goto conflict;
+       }
        return 0;
+
+ conflict:
+       printk(KERN_INFO "%s:%d conflicting memory types "
+              "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
+              new->end, cattr_name(new->type), cattr_name(entry->type));
+       return -EBUSY;
 }
 
 /*
@@ -198,37 +215,36 @@ static int pat_x_mtrr_type(u64 start, u64 end, unsigned long prot,
  * req_type will have a special case value '-1', when requester want to inherit
  * the memory type from mtrr (if WB), existing PAT, defaulting to UC_MINUS.
  *
- * If ret_type is NULL, function will return an error if it cannot reserve the
- * region with req_type. If ret_type is non-null, function will return
- * available type in ret_type in case of no error. In case of any error
+ * If new_type is NULL, function will return an error if it cannot reserve the
+ * region with req_type. If new_type is non-NULL, function will return
+ * available type in new_type in case of no error. In case of any error
  * it will return a negative return value.
  */
 int reserve_memtype(u64 start, u64 end, unsigned long req_type,
-                       unsigned long *ret_type)
+                       unsigned long *new_type)
 {
-       struct memtype *new_entry = NULL;
-       struct memtype *parse;
+       struct memtype *new, *entry;
        unsigned long actual_type;
+       struct list_head *where;
        int err = 0;
 
-       /* Only track when pat_wc_enabled */
-       if (!pat_wc_enabled) {
+       BUG_ON(start >= end); /* end is exclusive */
+
+       if (!pat_enabled) {
                /* This is identical to page table setting without PAT */
-               if (ret_type) {
-                       if (req_type == -1) {
-                               *ret_type = _PAGE_CACHE_WB;
-                       } else {
-                               *ret_type = req_type;
-                       }
+               if (new_type) {
+                       if (req_type == -1)
+                               *new_type = _PAGE_CACHE_WB;
+                       else
+                               *new_type = req_type & _PAGE_CACHE_MASK;
                }
                return 0;
        }
 
        /* Low ISA region is always mapped WB in page table. No need to track */
-       if (start >= ISA_START_ADDRESS && (end - 1) <= ISA_END_ADDRESS) {
-               if (ret_type)
-                       *ret_type = _PAGE_CACHE_WB;
-
+       if (is_ISA_range(start, end - 1)) {
+               if (new_type)
+                       *new_type = _PAGE_CACHE_WB;
                return 0;
        }
 
@@ -241,206 +257,92 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
                 */
                u8 mtrr_type = mtrr_type_lookup(start, end);
 
-               if (mtrr_type == MTRR_TYPE_WRBACK) {
-                       req_type = _PAGE_CACHE_WB;
+               if (mtrr_type == MTRR_TYPE_WRBACK)
                        actual_type = _PAGE_CACHE_WB;
-               } else {
-                       req_type = _PAGE_CACHE_UC_MINUS;
+               else
                        actual_type = _PAGE_CACHE_UC_MINUS;
-               }
-       } else {
-               req_type &= _PAGE_CACHE_MASK;
-               err = pat_x_mtrr_type(start, end, req_type, &actual_type);
-       }
-
-       if (err) {
-               if (ret_type)
-                       *ret_type = actual_type;
-
-               return -EINVAL;
-       }
+       } else
+               actual_type = pat_x_mtrr_type(start, end,
+                                             req_type & _PAGE_CACHE_MASK);
 
-       new_entry  = kmalloc(sizeof(struct memtype), GFP_KERNEL);
-       if (!new_entry)
+       new  = kmalloc(sizeof(struct memtype), GFP_KERNEL);
+       if (!new)
                return -ENOMEM;
 
-       new_entry->start = start;
-       new_entry->end = end;
-       new_entry->type = actual_type;
+       new->start = start;
+       new->end = end;
+       new->type = actual_type;
 
-       if (ret_type)
-               *ret_type = actual_type;
+       if (new_type)
+               *new_type = actual_type;
 
        spin_lock(&memtype_lock);
 
        /* Search for existing mapping that overlaps the current range */
-       list_for_each_entry(parse, &memtype_list, nd) {
-               struct memtype *saved_ptr;
-
-               if (parse->start >= end) {
-                       pr_debug("New Entry\n");
-                       list_add(&new_entry->nd, parse->nd.prev);
-                       new_entry = NULL;
+       where = NULL;
+       list_for_each_entry(entry, &memtype_list, nd) {
+               if (end <= entry->start) {
+                       where = entry->nd.prev;
                        break;
-               }
-
-               if (start <= parse->start && end >= parse->start) {
-                       if (actual_type != parse->type && ret_type) {
-                               actual_type = parse->type;
-                               *ret_type = actual_type;
-                               new_entry->type = actual_type;
-                       }
-
-                       if (actual_type != parse->type) {
-                               printk(
-               KERN_INFO "%s:%d conflicting memory types %Lx-%Lx %s<->%s\n",
-                                       current->comm, current->pid,
-                                       start, end,
-                                       cattr_name(actual_type),
-                                       cattr_name(parse->type));
-                               err = -EBUSY;
-                               break;
+               } else if (start <= entry->start) { /* end > entry->start */
+                       err = chk_conflict(new, entry, new_type);
+                       if (!err) {
+                               dprintk("Overlap at 0x%Lx-0x%Lx\n",
+                                       entry->start, entry->end);
+                               where = entry->nd.prev;
                        }
-
-                       saved_ptr = parse;
-                       /*
-                        * Check to see whether the request overlaps more
-                        * than one entry in the list
-                        */
-                       list_for_each_entry_continue(parse, &memtype_list, nd) {
-                               if (end <= parse->start) {
-                                       break;
-                               }
-
-                               if (actual_type != parse->type) {
-                                       printk(
-               KERN_INFO "%s:%d conflicting memory types %Lx-%Lx %s<->%s\n",
-                                               current->comm, current->pid,
-                                               start, end,
-                                               cattr_name(actual_type),
-                                               cattr_name(parse->type));
-                                       err = -EBUSY;
-                                       break;
-                               }
-                       }
-
-                       if (err) {
-                               break;
-                       }
-
-                       pr_debug("Overlap at 0x%Lx-0x%Lx\n",
-                              saved_ptr->start, saved_ptr->end);
-                       /* No conflict. Go ahead and add this new entry */
-                       list_add(&new_entry->nd, saved_ptr->nd.prev);
-                       new_entry = NULL;
                        break;
-               }
-
-               if (start < parse->end) {
-                       if (actual_type != parse->type && ret_type) {
-                               actual_type = parse->type;
-                               *ret_type = actual_type;
-                               new_entry->type = actual_type;
-                       }
-
-                       if (actual_type != parse->type) {
-                               printk(
-               KERN_INFO "%s:%d conflicting memory types %Lx-%Lx %s<->%s\n",
-                                       current->comm, current->pid,
-                                       start, end,
-                                       cattr_name(actual_type),
-                                       cattr_name(parse->type));
-                               err = -EBUSY;
-                               break;
-                       }
-
-                       saved_ptr = parse;
-                       /*
-                        * Check to see whether the request overlaps more
-                        * than one entry in the list
-                        */
-                       list_for_each_entry_continue(parse, &memtype_list, nd) {
-                               if (end <= parse->start) {
-                                       break;
-                               }
-
-                               if (actual_type != parse->type) {
-                                       printk(
-               KERN_INFO "%s:%d conflicting memory types %Lx-%Lx %s<->%s\n",
-                                               current->comm, current->pid,
-                                               start, end,
-                                               cattr_name(actual_type),
-                                               cattr_name(parse->type));
-                                       err = -EBUSY;
-                                       break;
-                               }
-                       }
-
-                       if (err) {
-                               break;
+               } else if (start < entry->end) { /* start > entry->start */
+                       err = chk_conflict(new, entry, new_type);
+                       if (!err) {
+                               dprintk("Overlap at 0x%Lx-0x%Lx\n",
+                                       entry->start, entry->end);
+                               where = &entry->nd;
                        }
-
-                       pr_debug(KERN_INFO "Overlap at 0x%Lx-0x%Lx\n",
-                                saved_ptr->start, saved_ptr->end);
-                       /* No conflict. Go ahead and add this new entry */
-                       list_add(&new_entry->nd, &saved_ptr->nd);
-                       new_entry = NULL;
                        break;
                }
        }
 
        if (err) {
-               printk(KERN_INFO
-       "reserve_memtype failed 0x%Lx-0x%Lx, track %s, req %s\n",
-                       start, end, cattr_name(new_entry->type),
-                       cattr_name(req_type));
-               kfree(new_entry);
+               printk(KERN_INFO "reserve_memtype failed 0x%Lx-0x%Lx, "
+                      "track %s, req %s\n",
+                      start, end, cattr_name(new->type), cattr_name(req_type));
+               kfree(new);
                spin_unlock(&memtype_lock);
                return err;
        }
 
-       if (new_entry) {
-               /* No conflict. Not yet added to the list. Add to the tail */
-               list_add_tail(&new_entry->nd, &memtype_list);
-               pr_debug("New Entry\n");
-       }
-
-       if (ret_type) {
-               pr_debug(
-       "reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n",
-                       start, end, cattr_name(actual_type),
-                       cattr_name(req_type), cattr_name(*ret_type));
-       } else {
-               pr_debug(
-       "reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s\n",
-                       start, end, cattr_name(actual_type),
-                       cattr_name(req_type));
-       }
+       if (where)
+               list_add(&new->nd, where);
+       else
+               list_add_tail(&new->nd, &memtype_list);
 
        spin_unlock(&memtype_lock);
+
+       dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n",
+               start, end, cattr_name(new->type), cattr_name(req_type),
+               new_type ? cattr_name(*new_type) : "-");
+
        return err;
 }
 
 int free_memtype(u64 start, u64 end)
 {
-       struct memtype *ml;
+       struct memtype *entry;
        int err = -EINVAL;
 
-       /* Only track when pat_wc_enabled */
-       if (!pat_wc_enabled) {
+       if (!pat_enabled)
                return 0;
-       }
 
        /* Low ISA region is always mapped WB. No need to track */
-       if (start >= ISA_START_ADDRESS && end <= ISA_END_ADDRESS) {
+       if (is_ISA_range(start, end - 1))
                return 0;
-       }
 
        spin_lock(&memtype_lock);
-       list_for_each_entry(ml, &memtype_list, nd) {
-               if (ml->start == start && ml->end == end) {
-                       list_del(&ml->nd);
-                       kfree(ml);
+       list_for_each_entry(entry, &memtype_list, nd) {
+               if (entry->start == start && entry->end == end) {
+                       list_del(&entry->nd);
+                       kfree(entry);
                        err = 0;
                        break;
                }
@@ -452,7 +354,7 @@ int free_memtype(u64 start, u64 end)
                        current->comm, current->pid, start, end);
        }
 
-       pr_debug("free_memtype request 0x%Lx-0x%Lx\n", start, end);
+       dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
        return err;
 }
 
@@ -521,12 +423,12 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
         * caching for the high addresses through the KEN pin, but
         * we maintain the tradition of paranoia in this code.
         */
-       if (!pat_wc_enabled &&
-           ! ( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) ||
-               test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) ||
-               test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) ||
-               test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability)) &&
-          (pfn << PAGE_SHIFT) >= __pa(high_memory)) {
+       if (!pat_enabled &&
+           !(boot_cpu_has(X86_FEATURE_MTRR) ||
+             boot_cpu_has(X86_FEATURE_K6_MTRR) ||
+             boot_cpu_has(X86_FEATURE_CYRIX_ARR) ||
+             boot_cpu_has(X86_FEATURE_CENTAUR_MCR)) &&
+           (pfn << PAGE_SHIFT) >= __pa(high_memory)) {
                flags = _PAGE_CACHE_UC;
        }
 #endif
@@ -547,8 +449,9 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
        if (retval < 0)
                return 0;
 
-       if (pfn <= max_pfn_mapped &&
-            ioremap_change_attr((unsigned long)__va(offset), size, flags) < 0) {
+       if (((pfn < max_low_pfn_mapped) ||
+            (pfn >= (1UL<<(32 - PAGE_SHIFT)) && pfn < max_pfn_mapped)) &&
+           ioremap_change_attr((unsigned long)__va(offset), size, flags) < 0) {
                free_memtype(offset, offset + size);
                printk(KERN_INFO
                "%s:%d /dev/mem ioremap_change_attr failed %s for %Lx-%Lx\n",
@@ -586,4 +489,3 @@ void unmap_devmem(unsigned long pfn, unsigned long size, pgprot_t vma_prot)
 
        free_memtype(addr, addr + size);
 }
-
diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
new file mode 100644 (file)
index 0000000..efa1911
--- /dev/null
@@ -0,0 +1,489 @@
+/*
+ *  Fault Injection Test harness (FI)
+ *  Copyright (C) Intel Crop.
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ *
+ */
+
+/*  Id: pf_in.c,v 1.1.1.1 2002/11/12 05:56:32 brlock Exp
+ *  Copyright by Intel Crop., 2002
+ *  Louis Zhuang (louis.zhuang@intel.com)
+ *
+ *  Bjorn Steinbrink (B.Steinbrink@gmx.de), 2007
+ */
+
+#include <linux/module.h>
+#include <linux/ptrace.h> /* struct pt_regs */
+#include "pf_in.h"
+
+#ifdef __i386__
+/* IA32 Manual 3, 2-1 */
+static unsigned char prefix_codes[] = {
+       0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64,
+       0x65, 0x2E, 0x3E, 0x66, 0x67
+};
+/* IA32 Manual 3, 3-432*/
+static unsigned int reg_rop[] = {
+       0x8A, 0x8B, 0xB60F, 0xB70F, 0xBE0F, 0xBF0F
+};
+static unsigned int reg_wop[] = { 0x88, 0x89 };
+static unsigned int imm_wop[] = { 0xC6, 0xC7 };
+/* IA32 Manual 3, 3-432*/
+static unsigned int rw8[] = { 0x88, 0x8A, 0xC6 };
+static unsigned int rw32[] = {
+       0x89, 0x8B, 0xC7, 0xB60F, 0xB70F, 0xBE0F, 0xBF0F
+};
+static unsigned int mw8[] = { 0x88, 0x8A, 0xC6, 0xB60F, 0xBE0F };
+static unsigned int mw16[] = { 0xB70F, 0xBF0F };
+static unsigned int mw32[] = { 0x89, 0x8B, 0xC7 };
+static unsigned int mw64[] = {};
+#else /* not __i386__ */
+static unsigned char prefix_codes[] = {
+       0x66, 0x67, 0x2E, 0x3E, 0x26, 0x64, 0x65, 0x36,
+       0xF0, 0xF3, 0xF2,
+       /* REX Prefixes */
+       0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+       0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
+};
+/* AMD64 Manual 3, Appendix A*/
+static unsigned int reg_rop[] = {
+       0x8A, 0x8B, 0xB60F, 0xB70F, 0xBE0F, 0xBF0F
+};
+static unsigned int reg_wop[] = { 0x88, 0x89 };
+static unsigned int imm_wop[] = { 0xC6, 0xC7 };
+static unsigned int rw8[] = { 0xC6, 0x88, 0x8A };
+static unsigned int rw32[] = {
+       0xC7, 0x89, 0x8B, 0xB60F, 0xB70F, 0xBE0F, 0xBF0F
+};
+/* 8 bit only */
+static unsigned int mw8[] = { 0xC6, 0x88, 0x8A, 0xB60F, 0xBE0F };
+/* 16 bit only */
+static unsigned int mw16[] = { 0xB70F, 0xBF0F };
+/* 16 or 32 bit */
+static unsigned int mw32[] = { 0xC7 };
+/* 16, 32 or 64 bit */
+static unsigned int mw64[] = { 0x89, 0x8B };
+#endif /* not __i386__ */
+
+static int skip_prefix(unsigned char *addr, int *shorted, int *enlarged,
+                                                               int *rexr)
+{
+       int i;
+       unsigned char *p = addr;
+       *shorted = 0;
+       *enlarged = 0;
+       *rexr = 0;
+
+restart:
+       for (i = 0; i < ARRAY_SIZE(prefix_codes); i++) {
+               if (*p == prefix_codes[i]) {
+                       if (*p == 0x66)
+                               *shorted = 1;
+#ifdef __amd64__
+                       if ((*p & 0xf8) == 0x48)
+                               *enlarged = 1;
+                       if ((*p & 0xf4) == 0x44)
+                               *rexr = 1;
+#endif
+                       p++;
+                       goto restart;
+               }
+       }
+
+       return (p - addr);
+}
+
+static int get_opcode(unsigned char *addr, unsigned int *opcode)
+{
+       int len;
+
+       if (*addr == 0x0F) {
+               /* 0x0F is extension instruction */
+               *opcode = *(unsigned short *)addr;
+               len = 2;
+       } else {
+               *opcode = *addr;
+               len = 1;
+       }
+
+       return len;
+}
+
+#define CHECK_OP_TYPE(opcode, array, type) \
+       for (i = 0; i < ARRAY_SIZE(array); i++) { \
+               if (array[i] == opcode) { \
+                       rv = type; \
+                       goto exit; \
+               } \
+       }
+
+enum reason_type get_ins_type(unsigned long ins_addr)
+{
+       unsigned int opcode;
+       unsigned char *p;
+       int shorted, enlarged, rexr;
+       int i;
+       enum reason_type rv = OTHERS;
+
+       p = (unsigned char *)ins_addr;
+       p += skip_prefix(p, &shorted, &enlarged, &rexr);
+       p += get_opcode(p, &opcode);
+
+       CHECK_OP_TYPE(opcode, reg_rop, REG_READ);
+       CHECK_OP_TYPE(opcode, reg_wop, REG_WRITE);
+       CHECK_OP_TYPE(opcode, imm_wop, IMM_WRITE);
+
+exit:
+       return rv;
+}
+#undef CHECK_OP_TYPE
+
+static unsigned int get_ins_reg_width(unsigned long ins_addr)
+{
+       unsigned int opcode;
+       unsigned char *p;
+       int i, shorted, enlarged, rexr;
+
+       p = (unsigned char *)ins_addr;
+       p += skip_prefix(p, &shorted, &enlarged, &rexr);
+       p += get_opcode(p, &opcode);
+
+       for (i = 0; i < ARRAY_SIZE(rw8); i++)
+               if (rw8[i] == opcode)
+                       return 1;
+
+       for (i = 0; i < ARRAY_SIZE(rw32); i++)
+               if (rw32[i] == opcode)
+                       return (shorted ? 2 : (enlarged ? 8 : 4));
+
+       printk(KERN_ERR "mmiotrace: Unknown opcode 0x%02x\n", opcode);
+       return 0;
+}
+
+unsigned int get_ins_mem_width(unsigned long ins_addr)
+{
+       unsigned int opcode;
+       unsigned char *p;
+       int i, shorted, enlarged, rexr;
+
+       p = (unsigned char *)ins_addr;
+       p += skip_prefix(p, &shorted, &enlarged, &rexr);
+       p += get_opcode(p, &opcode);
+
+       for (i = 0; i < ARRAY_SIZE(mw8); i++)
+               if (mw8[i] == opcode)
+                       return 1;
+
+       for (i = 0; i < ARRAY_SIZE(mw16); i++)
+               if (mw16[i] == opcode)
+                       return 2;
+
+       for (i = 0; i < ARRAY_SIZE(mw32); i++)
+               if (mw32[i] == opcode)
+                       return shorted ? 2 : 4;
+
+       for (i = 0; i < ARRAY_SIZE(mw64); i++)
+               if (mw64[i] == opcode)
+                       return shorted ? 2 : (enlarged ? 8 : 4);
+
+       printk(KERN_ERR "mmiotrace: Unknown opcode 0x%02x\n", opcode);
+       return 0;
+}
+
+/*
+ * Define register ident in mod/rm byte.
+ * Note: these are NOT the same as in ptrace-abi.h.
+ */
+enum {
+       arg_AL = 0,
+       arg_CL = 1,
+       arg_DL = 2,
+       arg_BL = 3,
+       arg_AH = 4,
+       arg_CH = 5,
+       arg_DH = 6,
+       arg_BH = 7,
+
+       arg_AX = 0,
+       arg_CX = 1,
+       arg_DX = 2,
+       arg_BX = 3,
+       arg_SP = 4,
+       arg_BP = 5,
+       arg_SI = 6,
+       arg_DI = 7,
+#ifdef __amd64__
+       arg_R8  = 8,
+       arg_R9  = 9,
+       arg_R10 = 10,
+       arg_R11 = 11,
+       arg_R12 = 12,
+       arg_R13 = 13,
+       arg_R14 = 14,
+       arg_R15 = 15
+#endif
+};
+
+static unsigned char *get_reg_w8(int no, struct pt_regs *regs)
+{
+       unsigned char *rv = NULL;
+
+       switch (no) {
+       case arg_AL:
+               rv = (unsigned char *)&regs->ax;
+               break;
+       case arg_BL:
+               rv = (unsigned char *)&regs->bx;
+               break;
+       case arg_CL:
+               rv = (unsigned char *)&regs->cx;
+               break;
+       case arg_DL:
+               rv = (unsigned char *)&regs->dx;
+               break;
+       case arg_AH:
+               rv = 1 + (unsigned char *)&regs->ax;
+               break;
+       case arg_BH:
+               rv = 1 + (unsigned char *)&regs->bx;
+               break;
+       case arg_CH:
+               rv = 1 + (unsigned char *)&regs->cx;
+               break;
+       case arg_DH:
+               rv = 1 + (unsigned char *)&regs->dx;
+               break;
+#ifdef __amd64__
+       case arg_R8:
+               rv = (unsigned char *)&regs->r8;
+               break;
+       case arg_R9:
+               rv = (unsigned char *)&regs->r9;
+               break;
+       case arg_R10:
+               rv = (unsigned char *)&regs->r10;
+               break;
+       case arg_R11:
+               rv = (unsigned char *)&regs->r11;
+               break;
+       case arg_R12:
+               rv = (unsigned char *)&regs->r12;
+               break;
+       case arg_R13:
+               rv = (unsigned char *)&regs->r13;
+               break;
+       case arg_R14:
+               rv = (unsigned char *)&regs->r14;
+               break;
+       case arg_R15:
+               rv = (unsigned char *)&regs->r15;
+               break;
+#endif
+       default:
+               printk(KERN_ERR "mmiotrace: Error reg no# %d\n", no);
+               break;
+       }
+       return rv;
+}
+
+static unsigned long *get_reg_w32(int no, struct pt_regs *regs)
+{
+       unsigned long *rv = NULL;
+
+       switch (no) {
+       case arg_AX:
+               rv = &regs->ax;
+               break;
+       case arg_BX:
+               rv = &regs->bx;
+               break;
+       case arg_CX:
+               rv = &regs->cx;
+               break;
+       case arg_DX:
+               rv = &regs->dx;
+               break;
+       case arg_SP:
+               rv = &regs->sp;
+               break;
+       case arg_BP:
+               rv = &regs->bp;
+               break;
+       case arg_SI:
+               rv = &regs->si;
+               break;
+       case arg_DI:
+               rv = &regs->di;
+               break;
+#ifdef __amd64__
+       case arg_R8:
+               rv = &regs->r8;
+               break;
+       case arg_R9:
+               rv = &regs->r9;
+               break;
+       case arg_R10:
+               rv = &regs->r10;
+               break;
+       case arg_R11:
+               rv = &regs->r11;
+               break;
+       case arg_R12:
+               rv = &regs->r12;
+               break;
+       case arg_R13:
+               rv = &regs->r13;
+               break;
+       case arg_R14:
+               rv = &regs->r14;
+               break;
+       case arg_R15:
+               rv = &regs->r15;
+               break;
+#endif
+       default:
+               printk(KERN_ERR "mmiotrace: Error reg no# %d\n", no);
+       }
+
+       return rv;
+}
+
+unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
+{
+       unsigned int opcode;
+       unsigned char mod_rm;
+       int reg;
+       unsigned char *p;
+       int i, shorted, enlarged, rexr;
+       unsigned long rv;
+
+       p = (unsigned char *)ins_addr;
+       p += skip_prefix(p, &shorted, &enlarged, &rexr);
+       p += get_opcode(p, &opcode);
+       for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
+               if (reg_rop[i] == opcode) {
+                       rv = REG_READ;
+                       goto do_work;
+               }
+
+       for (i = 0; i < ARRAY_SIZE(reg_wop); i++)
+               if (reg_wop[i] == opcode) {
+                       rv = REG_WRITE;
+                       goto do_work;
+               }
+
+       printk(KERN_ERR "mmiotrace: Not a register instruction, opcode "
+                                                       "0x%02x\n", opcode);
+       goto err;
+
+do_work:
+       mod_rm = *p;
+       reg = ((mod_rm >> 3) & 0x7) | (rexr << 3);
+       switch (get_ins_reg_width(ins_addr)) {
+       case 1:
+               return *get_reg_w8(reg, regs);
+
+       case 2:
+               return *(unsigned short *)get_reg_w32(reg, regs);
+
+       case 4:
+               return *(unsigned int *)get_reg_w32(reg, regs);
+
+#ifdef __amd64__
+       case 8:
+               return *(unsigned long *)get_reg_w32(reg, regs);
+#endif
+
+       default:
+               printk(KERN_ERR "mmiotrace: Error width# %d\n", reg);
+       }
+
+err:
+       return 0;
+}
+
+unsigned long get_ins_imm_val(unsigned long ins_addr)
+{
+       unsigned int opcode;
+       unsigned char mod_rm;
+       unsigned char mod;
+       unsigned char *p;
+       int i, shorted, enlarged, rexr;
+       unsigned long rv;
+
+       p = (unsigned char *)ins_addr;
+       p += skip_prefix(p, &shorted, &enlarged, &rexr);
+       p += get_opcode(p, &opcode);
+       for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
+               if (imm_wop[i] == opcode) {
+                       rv = IMM_WRITE;
+                       goto do_work;
+               }
+
+       printk(KERN_ERR "mmiotrace: Not an immediate instruction, opcode "
+                                                       "0x%02x\n", opcode);
+       goto err;
+
+do_work:
+       mod_rm = *p;
+       mod = mod_rm >> 6;
+       p++;
+       switch (mod) {
+       case 0:
+               /* if r/m is 5 we have a 32 disp (IA32 Manual 3, Table 2-2)  */
+               /* AMD64: XXX Check for address size prefix? */
+               if ((mod_rm & 0x7) == 0x5)
+                       p += 4;
+               break;
+
+       case 1:
+               p += 1;
+               break;
+
+       case 2:
+               p += 4;
+               break;
+
+       case 3:
+       default:
+               printk(KERN_ERR "mmiotrace: not a memory access instruction "
+                                               "at 0x%lx, rm_mod=0x%02x\n",
+                                               ins_addr, mod_rm);
+       }
+
+       switch (get_ins_reg_width(ins_addr)) {
+       case 1:
+               return *(unsigned char *)p;
+
+       case 2:
+               return *(unsigned short *)p;
+
+       case 4:
+               return *(unsigned int *)p;
+
+#ifdef __amd64__
+       case 8:
+               return *(unsigned long *)p;
+#endif
+
+       default:
+               printk(KERN_ERR "mmiotrace: Error: width.\n");
+       }
+
+err:
+       return 0;
+}
diff --git a/arch/x86/mm/pf_in.h b/arch/x86/mm/pf_in.h
new file mode 100644 (file)
index 0000000..e05341a
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  Fault Injection Test harness (FI)
+ *  Copyright (C) Intel Crop.
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ *
+ */
+
+#ifndef __PF_H_
+#define __PF_H_
+
+enum reason_type {
+       NOT_ME, /* page fault is not in regions */
+       NOTHING,        /* access others point in regions */
+       REG_READ,       /* read from addr to reg */
+       REG_WRITE,      /* write from reg to addr */
+       IMM_WRITE,      /* write from imm to addr */
+       OTHERS  /* Other instructions can not intercept */
+};
+
+enum reason_type get_ins_type(unsigned long ins_addr);
+unsigned int get_ins_mem_width(unsigned long ins_addr);
+unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs);
+unsigned long get_ins_imm_val(unsigned long ins_addr);
+
+#endif /* __PF_H_ */
index 5015976..557b2ab 100644 (file)
@@ -2,6 +2,7 @@
 #include <asm/pgalloc.h>
 #include <asm/pgtable.h>
 #include <asm/tlb.h>
+#include <asm/fixmap.h>
 
 pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
 {
@@ -65,12 +66,6 @@ static inline void pgd_list_del(pgd_t *pgd)
 static void pgd_ctor(void *p)
 {
        pgd_t *pgd = p;
-       unsigned long flags;
-
-       /* Clear usermode parts of PGD */
-       memset(pgd, 0, KERNEL_PGD_BOUNDARY*sizeof(pgd_t));
-
-       spin_lock_irqsave(&pgd_lock, flags);
 
        /* If the pgd points to a shared pagetable level (either the
           ptes in non-PAE, or shared PMD in PAE), then just copy the
@@ -90,8 +85,6 @@ static void pgd_ctor(void *p)
        /* list required to sync kernel mapping updates */
        if (!SHARED_KERNEL_PMD)
                pgd_list_add(pgd);
-
-       spin_unlock_irqrestore(&pgd_lock, flags);
 }
 
 static void pgd_dtor(void *pgd)
@@ -118,6 +111,72 @@ static void pgd_dtor(void *pgd)
  */
 
 #ifdef CONFIG_X86_PAE
+/*
+ * In PAE mode, we need to do a cr3 reload (=tlb flush) when
+ * updating the top-level pagetable entries to guarantee the
+ * processor notices the update.  Since this is expensive, and
+ * all 4 top-level entries are used almost immediately in a
+ * new process's life, we just pre-populate them here.
+ *
+ * Also, if we're in a paravirt environment where the kernel pmd is
+ * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
+ * and initialize the kernel pmds here.
+ */
+#define PREALLOCATED_PMDS      UNSHARED_PTRS_PER_PGD
+
+void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
+{
+       paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
+
+       /* Note: almost everything apart from _PAGE_PRESENT is
+          reserved at the pmd (PDPT) level. */
+       set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
+
+       /*
+        * According to Intel App note "TLBs, Paging-Structure Caches,
+        * and Their Invalidation", April 2007, document 317080-001,
+        * section 8.1: in PAE mode we explicitly have to flush the
+        * TLB via cr3 if the top-level pgd is changed...
+        */
+       if (mm == current->active_mm)
+               write_cr3(read_cr3());
+}
+#else  /* !CONFIG_X86_PAE */
+
+/* No need to prepopulate any pagetable entries in non-PAE modes. */
+#define PREALLOCATED_PMDS      0
+
+#endif /* CONFIG_X86_PAE */
+
+static void free_pmds(pmd_t *pmds[])
+{
+       int i;
+
+       for(i = 0; i < PREALLOCATED_PMDS; i++)
+               if (pmds[i])
+                       free_page((unsigned long)pmds[i]);
+}
+
+static int preallocate_pmds(pmd_t *pmds[])
+{
+       int i;
+       bool failed = false;
+
+       for(i = 0; i < PREALLOCATED_PMDS; i++) {
+               pmd_t *pmd = (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
+               if (pmd == NULL)
+                       failed = true;
+               pmds[i] = pmd;
+       }
+
+       if (failed) {
+               free_pmds(pmds);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
 /*
  * Mop up any pmd pages which may still be attached to the pgd.
  * Normally they will be freed by munmap/exit_mmap, but any pmd we
@@ -128,7 +187,7 @@ static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
 {
        int i;
 
-       for(i = 0; i < UNSHARED_PTRS_PER_PGD; i++) {
+       for(i = 0; i < PREALLOCATED_PMDS; i++) {
                pgd_t pgd = pgdp[i];
 
                if (pgd_val(pgd) != 0) {
@@ -142,32 +201,17 @@ static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
        }
 }
 
-/*
- * In PAE mode, we need to do a cr3 reload (=tlb flush) when
- * updating the top-level pagetable entries to guarantee the
- * processor notices the update.  Since this is expensive, and
- * all 4 top-level entries are used almost immediately in a
- * new process's life, we just pre-populate them here.
- *
- * Also, if we're in a paravirt environment where the kernel pmd is
- * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
- * and initialize the kernel pmds here.
- */
-static int pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd)
+static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
 {
        pud_t *pud;
        unsigned long addr;
        int i;
 
        pud = pud_offset(pgd, 0);
-       for (addr = i = 0; i < UNSHARED_PTRS_PER_PGD;
-            i++, pud++, addr += PUD_SIZE) {
-               pmd_t *pmd = pmd_alloc_one(mm, addr);
 
-               if (!pmd) {
-                       pgd_mop_up_pmds(mm, pgd);
-                       return 0;
-               }
+       for (addr = i = 0; i < PREALLOCATED_PMDS;
+            i++, pud++, addr += PUD_SIZE) {
+               pmd_t *pmd = pmds[i];
 
                if (i >= KERNEL_PGD_BOUNDARY)
                        memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
@@ -175,61 +219,54 @@ static int pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd)
 
                pud_populate(mm, pud, pmd);
        }
-
-       return 1;
 }
 
-void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
+pgd_t *pgd_alloc(struct mm_struct *mm)
 {
-       paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
+       pgd_t *pgd;
+       pmd_t *pmds[PREALLOCATED_PMDS];
+       unsigned long flags;
 
-       /* Note: almost everything apart from _PAGE_PRESENT is
-          reserved at the pmd (PDPT) level. */
-       set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
+       pgd = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
 
-       /*
-        * According to Intel App note "TLBs, Paging-Structure Caches,
-        * and Their Invalidation", April 2007, document 317080-001,
-        * section 8.1: in PAE mode we explicitly have to flush the
-        * TLB via cr3 if the top-level pgd is changed...
-        */
-       if (mm == current->active_mm)
-               write_cr3(read_cr3());
-}
-#else  /* !CONFIG_X86_PAE */
-/* No need to prepopulate any pagetable entries in non-PAE modes. */
-static int pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd)
-{
-       return 1;
-}
+       if (pgd == NULL)
+               goto out;
 
-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgd)
-{
-}
-#endif /* CONFIG_X86_PAE */
+       mm->pgd = pgd;
 
-pgd_t *pgd_alloc(struct mm_struct *mm)
-{
-       pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
+       if (preallocate_pmds(pmds) != 0)
+               goto out_free_pgd;
 
-       /* so that alloc_pmd can use it */
-       mm->pgd = pgd;
-       if (pgd)
-               pgd_ctor(pgd);
+       if (paravirt_pgd_alloc(mm) != 0)
+               goto out_free_pmds;
 
-       if (pgd && !pgd_prepopulate_pmd(mm, pgd)) {
-               pgd_dtor(pgd);
-               free_page((unsigned long)pgd);
-               pgd = NULL;
-       }
+       /*
+        * Make sure that pre-populating the pmds is atomic with
+        * respect to anything walking the pgd_list, so that they
+        * never see a partially populated pgd.
+        */
+       spin_lock_irqsave(&pgd_lock, flags);
+
+       pgd_ctor(pgd);
+       pgd_prepopulate_pmd(mm, pgd, pmds);
+
+       spin_unlock_irqrestore(&pgd_lock, flags);
 
        return pgd;
+
+out_free_pmds:
+       free_pmds(pmds);
+out_free_pgd:
+       free_page((unsigned long)pgd);
+out:
+       return NULL;
 }
 
 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
        pgd_mop_up_pmds(mm, pgd);
        pgd_dtor(pgd);
+       paravirt_pgd_free(mm, pgd);
        free_page((unsigned long)pgd);
 }
 
@@ -255,7 +292,7 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
 
        if (pte_young(*ptep))
                ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
-                                        &ptep->pte);
+                                        (unsigned long *) &ptep->pte);
 
        if (ret)
                pte_update(vma->vm_mm, addr, ptep);
@@ -274,3 +311,22 @@ int ptep_clear_flush_young(struct vm_area_struct *vma,
 
        return young;
 }
+
+int fixmaps_set;
+
+void __native_set_fixmap(enum fixed_addresses idx, pte_t pte)
+{
+       unsigned long address = __fix_to_virt(idx);
+
+       if (idx >= __end_of_fixed_addresses) {
+               BUG();
+               return;
+       }
+       set_pte_vaddr(address, pte);
+       fixmaps_set++;
+}
+
+void native_set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
+{
+       __native_set_fixmap(idx, pfn_pte(phys >> PAGE_SHIFT, flags));
+}
index 369cf06..b4becbf 100644 (file)
@@ -71,7 +71,7 @@ void show_mem(void)
  * Associate a virtual page frame with a given physical page frame 
  * and protection flags for that frame.
  */ 
-static void set_pte_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
+void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
 {
        pgd_t *pgd;
        pud_t *pud;
@@ -94,8 +94,8 @@ static void set_pte_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
                return;
        }
        pte = pte_offset_kernel(pmd, vaddr);
-       if (pgprot_val(flags))
-               set_pte_present(&init_mm, vaddr, pte, pfn_pte(pfn, flags));
+       if (pte_val(pteval))
+               set_pte_present(&init_mm, vaddr, pte, pteval);
        else
                pte_clear(&init_mm, vaddr, pte);
 
@@ -141,22 +141,9 @@ void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
        __flush_tlb_one(vaddr);
 }
 
-static int fixmaps;
 unsigned long __FIXADDR_TOP = 0xfffff000;
 EXPORT_SYMBOL(__FIXADDR_TOP);
 
-void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
-{
-       unsigned long address = __fix_to_virt(idx);
-
-       if (idx >= __end_of_fixed_addresses) {
-               BUG();
-               return;
-       }
-       set_pte_pfn(address, phys >> PAGE_SHIFT, flags);
-       fixmaps++;
-}
-
 /**
  * reserve_top_address - reserves a hole in the top of kernel address space
  * @reserve - size of hole to reserve
@@ -164,11 +151,44 @@ void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags)
  * Can be used to relocate the fixmap area and poke a hole in the top
  * of kernel address space to make room for a hypervisor.
  */
-void reserve_top_address(unsigned long reserve)
+void __init reserve_top_address(unsigned long reserve)
 {
-       BUG_ON(fixmaps > 0);
+       BUG_ON(fixmaps_set > 0);
        printk(KERN_INFO "Reserving virtual address space above 0x%08x\n",
               (int)-reserve);
        __FIXADDR_TOP = -reserve - PAGE_SIZE;
        __VMALLOC_RESERVE += reserve;
 }
+
+/*
+ * vmalloc=size forces the vmalloc area to be exactly 'size'
+ * bytes. This can be used to increase (or decrease) the
+ * vmalloc area - the default is 128m.
+ */
+static int __init parse_vmalloc(char *arg)
+{
+       if (!arg)
+               return -EINVAL;
+
+       __VMALLOC_RESERVE = memparse(arg, &arg);
+       return 0;
+}
+early_param("vmalloc", parse_vmalloc);
+
+/*
+ * reservetop=size reserves a hole at the top of the kernel address space which
+ * a hypervisor can load into later.  Needed for dynamically loaded hypervisors,
+ * so relocating the fixmap can be done before paging initialization.
+ */
+static int __init parse_reservetop(char *arg)
+{
+       unsigned long address;
+
+       if (!arg)
+               return -EINVAL;
+
+       address = memparse(arg, &arg);
+       reserve_top_address(address);
+       return 0;
+}
+early_param("reservetop", parse_reservetop);
diff --git a/arch/x86/mm/srat_32.c b/arch/x86/mm/srat_32.c
new file mode 100644 (file)
index 0000000..f41d67f
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * Some of the code in this file has been gleaned from the 64 bit 
+ * discontigmem support code base.
+ *
+ * Copyright (C) 2002, IBM Corp.
+ *
+ * All rights reserved.          
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to Pat Gaughen <gone@us.ibm.com>
+ */
+#include <linux/mm.h>
+#include <linux/bootmem.h>
+#include <linux/mmzone.h>
+#include <linux/acpi.h>
+#include <linux/nodemask.h>
+#include <asm/srat.h>
+#include <asm/topology.h>
+#include <asm/smp.h>
+#include <asm/e820.h>
+
+/*
+ * proximity macros and definitions
+ */
+#define NODE_ARRAY_INDEX(x)    ((x) / 8)       /* 8 bits/char */
+#define NODE_ARRAY_OFFSET(x)   ((x) % 8)       /* 8 bits/char */
+#define BMAP_SET(bmap, bit)    ((bmap)[NODE_ARRAY_INDEX(bit)] |= 1 << NODE_ARRAY_OFFSET(bit))
+#define BMAP_TEST(bmap, bit)   ((bmap)[NODE_ARRAY_INDEX(bit)] & (1 << NODE_ARRAY_OFFSET(bit)))
+/* bitmap length; _PXM is at most 255 */
+#define PXM_BITMAP_LEN (MAX_PXM_DOMAINS / 8) 
+static u8 __initdata pxm_bitmap[PXM_BITMAP_LEN];       /* bitmap of proximity domains */
+
+#define MAX_CHUNKS_PER_NODE    3
+#define MAXCHUNKS              (MAX_CHUNKS_PER_NODE * MAX_NUMNODES)
+struct node_memory_chunk_s {
+       unsigned long   start_pfn;
+       unsigned long   end_pfn;
+       u8      pxm;            // proximity domain of node
+       u8      nid;            // which cnode contains this chunk?
+       u8      bank;           // which mem bank on this node
+};
+static struct node_memory_chunk_s __initdata node_memory_chunk[MAXCHUNKS];
+
+static int __initdata num_memory_chunks; /* total number of memory chunks */
+static u8 __initdata apicid_to_pxm[MAX_APICID];
+
+int numa_off __initdata;
+int acpi_numa __initdata;
+
+static __init void bad_srat(void)
+{
+        printk(KERN_ERR "SRAT: SRAT not used.\n");
+        acpi_numa = -1;
+       num_memory_chunks = 0;
+}
+
+static __init inline int srat_disabled(void)
+{
+       return numa_off || acpi_numa < 0;
+}
+
+/* Identify CPU proximity domains */
+void __init
+acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *cpu_affinity)
+{
+       if (srat_disabled())
+               return;
+       if (cpu_affinity->header.length !=
+            sizeof(struct acpi_srat_cpu_affinity)) {
+               bad_srat();
+               return;
+       }
+
+       if ((cpu_affinity->flags & ACPI_SRAT_CPU_ENABLED) == 0)
+               return;         /* empty entry */
+
+       /* mark this node as "seen" in node bitmap */
+       BMAP_SET(pxm_bitmap, cpu_affinity->proximity_domain_lo);
+
+       apicid_to_pxm[cpu_affinity->apic_id] = cpu_affinity->proximity_domain_lo;
+
+       printk(KERN_DEBUG "CPU %02x in proximity domain %02x\n",
+               cpu_affinity->apic_id, cpu_affinity->proximity_domain_lo);
+}
+
+/*
+ * Identify memory proximity domains and hot-remove capabilities.
+ * Fill node memory chunk list structure.
+ */
+void __init
+acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *memory_affinity)
+{
+       unsigned long long paddr, size;
+       unsigned long start_pfn, end_pfn;
+       u8 pxm;
+       struct node_memory_chunk_s *p, *q, *pend;
+
+       if (srat_disabled())
+               return;
+       if (memory_affinity->header.length !=
+            sizeof(struct acpi_srat_mem_affinity)) {
+               bad_srat();
+               return;
+       }
+
+       if ((memory_affinity->flags & ACPI_SRAT_MEM_ENABLED) == 0)
+               return;         /* empty entry */
+
+       pxm = memory_affinity->proximity_domain & 0xff;
+
+       /* mark this node as "seen" in node bitmap */
+       BMAP_SET(pxm_bitmap, pxm);
+
+       /* calculate info for memory chunk structure */
+       paddr = memory_affinity->base_address;
+       size = memory_affinity->length;
+
+       start_pfn = paddr >> PAGE_SHIFT;
+       end_pfn = (paddr + size) >> PAGE_SHIFT;
+
+
+       if (num_memory_chunks >= MAXCHUNKS) {
+               printk(KERN_WARNING "Too many mem chunks in SRAT."
+                       " Ignoring %lld MBytes at %llx\n",
+                       size/(1024*1024), paddr);
+               return;
+       }
+
+       /* Insertion sort based on base address */
+       pend = &node_memory_chunk[num_memory_chunks];
+       for (p = &node_memory_chunk[0]; p < pend; p++) {
+               if (start_pfn < p->start_pfn)
+                       break;
+       }
+       if (p < pend) {
+               for (q = pend; q >= p; q--)
+                       *(q + 1) = *q;
+       }
+       p->start_pfn = start_pfn;
+       p->end_pfn = end_pfn;
+       p->pxm = pxm;
+
+       num_memory_chunks++;
+
+       printk(KERN_DEBUG "Memory range %08lx to %08lx (type %x)"
+                         " in proximity domain %02x %s\n",
+               start_pfn, end_pfn,
+               memory_affinity->memory_type,
+               pxm,
+               ((memory_affinity->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) ?
+                "enabled and removable" : "enabled" ) );
+}
+
+/* Callback for SLIT parsing */
+void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
+{
+}
+
+void acpi_numa_arch_fixup(void)
+{
+}
+/*
+ * The SRAT table always lists ascending addresses, so can always
+ * assume that the first "start" address that you see is the real
+ * start of the node, and that the current "end" address is after
+ * the previous one.
+ */
+static __init void node_read_chunk(int nid, struct node_memory_chunk_s *memory_chunk)
+{
+       /*
+        * Only add present memory as told by the e820.
+        * There is no guarantee from the SRAT that the memory it
+        * enumerates is present at boot time because it represents
+        * *possible* memory hotplug areas the same as normal RAM.
+        */
+       if (memory_chunk->start_pfn >= max_pfn) {
+               printk(KERN_INFO "Ignoring SRAT pfns: %08lx - %08lx\n",
+                       memory_chunk->start_pfn, memory_chunk->end_pfn);
+               return;
+       }
+       if (memory_chunk->nid != nid)
+               return;
+
+       if (!node_has_online_mem(nid))
+               node_start_pfn[nid] = memory_chunk->start_pfn;
+
+       if (node_start_pfn[nid] > memory_chunk->start_pfn)
+               node_start_pfn[nid] = memory_chunk->start_pfn;
+
+       if (node_end_pfn[nid] < memory_chunk->end_pfn)
+               node_end_pfn[nid] = memory_chunk->end_pfn;
+}
+
+int __init get_memcfg_from_srat(void)
+{
+       int i, j, nid;
+
+
+       if (srat_disabled())
+               goto out_fail;
+
+       if (num_memory_chunks == 0) {
+               printk(KERN_WARNING
+                        "could not finy any ACPI SRAT memory areas.\n");
+               goto out_fail;
+       }
+
+       /* Calculate total number of nodes in system from PXM bitmap and create
+        * a set of sequential node IDs starting at zero.  (ACPI doesn't seem
+        * to specify the range of _PXM values.)
+        */
+       /*
+        * MCD - we no longer HAVE to number nodes sequentially.  PXM domain
+        * numbers could go as high as 256, and MAX_NUMNODES for i386 is typically
+        * 32, so we will continue numbering them in this manner until MAX_NUMNODES
+        * approaches MAX_PXM_DOMAINS for i386.
+        */
+       nodes_clear(node_online_map);
+       for (i = 0; i < MAX_PXM_DOMAINS; i++) {
+               if (BMAP_TEST(pxm_bitmap, i)) {
+                       int nid = acpi_map_pxm_to_node(i);
+                       node_set_online(nid);
+               }
+       }
+       BUG_ON(num_online_nodes() == 0);
+
+       /* set cnode id in memory chunk structure */
+       for (i = 0; i < num_memory_chunks; i++)
+               node_memory_chunk[i].nid = pxm_to_node(node_memory_chunk[i].pxm);
+
+       printk(KERN_DEBUG "pxm bitmap: ");
+       for (i = 0; i < sizeof(pxm_bitmap); i++) {
+               printk(KERN_CONT "%02x ", pxm_bitmap[i]);
+       }
+       printk(KERN_CONT "\n");
+       printk(KERN_DEBUG "Number of logical nodes in system = %d\n",
+                        num_online_nodes());
+       printk(KERN_DEBUG "Number of memory chunks in system = %d\n",
+                        num_memory_chunks);
+
+       for (i = 0; i < MAX_APICID; i++)
+               apicid_2_node[i] = pxm_to_node(apicid_to_pxm[i]);
+
+       for (j = 0; j < num_memory_chunks; j++){
+               struct node_memory_chunk_s * chunk = &node_memory_chunk[j];
+               printk(KERN_DEBUG
+                       "chunk %d nid %d start_pfn %08lx end_pfn %08lx\n",
+                      j, chunk->nid, chunk->start_pfn, chunk->end_pfn);
+               node_read_chunk(chunk->nid, chunk);
+               e820_register_active_regions(chunk->nid, chunk->start_pfn,
+                                            min(chunk->end_pfn, max_pfn));
+       }
+
+       for_each_online_node(nid) {
+               unsigned long start = node_start_pfn[nid];
+               unsigned long end = min(node_end_pfn[nid], max_pfn);
+
+               memory_present(nid, start, end);
+               node_remap_size[nid] = node_memmap_size_bytes(nid, start, end);
+       }
+       return 1;
+out_fail:
+       printk(KERN_ERR "failed to get NUMA memory information from SRAT"
+                       " table\n");
+       return 0;
+}
index 99649dc..1b4763e 100644 (file)
@@ -100,7 +100,19 @@ static __init inline int srat_disabled(void)
 /* Callback for SLIT parsing */
 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 {
-       acpi_slit = slit;
+       unsigned length;
+       unsigned long phys;
+
+       length = slit->header.length;
+       phys = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, length,
+                PAGE_SIZE);
+
+       if (phys == -1L)
+               panic(" Can not save slit!\n");
+
+       acpi_slit = __va(phys);
+       memcpy(acpi_slit, slit, length);
+       reserve_early(phys, phys + length, "ACPI SLIT");
 }
 
 /* Callback for Proximity Domain -> LAPIC mapping */
@@ -299,7 +311,7 @@ static int __init nodes_cover_memory(const struct bootnode *nodes)
                        pxmram = 0;
        }
 
-       e820ram = end_pfn - absent_pages_in_range(0, end_pfn);
+       e820ram = max_pfn - absent_pages_in_range(0, max_pfn);
        /* We seem to lose 3 pages somewhere. Allow a bit of slack. */
        if ((long)(e820ram - pxmram) >= 1*1024*1024) {
                printk(KERN_ERR
@@ -376,7 +388,7 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
                if (node == NUMA_NO_NODE)
                        continue;
                if (!node_isset(node, node_possible_map))
-                       numa_set_node(i, NUMA_NO_NODE);
+                       numa_clear_node(i);
        }
        numa_init_array();
        return 0;
@@ -495,6 +507,7 @@ int __node_distance(int a, int b)
 
 EXPORT_SYMBOL(__node_distance);
 
+#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || defined(CONFIG_ACPI_HOTPLUG_MEMORY)
 int memory_add_physaddr_to_nid(u64 start)
 {
        int i, ret = 0;
@@ -506,4 +519,4 @@ int memory_add_physaddr_to_nid(u64 start)
        return ret;
 }
 EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
-
+#endif
diff --git a/arch/x86/mm/testmmiotrace.c b/arch/x86/mm/testmmiotrace.c
new file mode 100644 (file)
index 0000000..d877c5b
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Written by Pekka Paalanen, 2008 <pq@iki.fi>
+ */
+#include <linux/module.h>
+#include <linux/io.h>
+
+#define MODULE_NAME "testmmiotrace"
+
+static unsigned long mmio_address;
+module_param(mmio_address, ulong, 0);
+MODULE_PARM_DESC(mmio_address, "Start address of the mapping of 16 kB.");
+
+static void do_write_test(void __iomem *p)
+{
+       unsigned int i;
+       for (i = 0; i < 256; i++)
+               iowrite8(i, p + i);
+       for (i = 1024; i < (5 * 1024); i += 2)
+               iowrite16(i * 12 + 7, p + i);
+       for (i = (5 * 1024); i < (16 * 1024); i += 4)
+               iowrite32(i * 212371 + 13, p + i);
+}
+
+static void do_read_test(void __iomem *p)
+{
+       unsigned int i;
+       for (i = 0; i < 256; i++)
+               ioread8(p + i);
+       for (i = 1024; i < (5 * 1024); i += 2)
+               ioread16(p + i);
+       for (i = (5 * 1024); i < (16 * 1024); i += 4)
+               ioread32(p + i);
+}
+
+static void do_test(void)
+{
+       void __iomem *p = ioremap_nocache(mmio_address, 0x4000);
+       if (!p) {
+               pr_err(MODULE_NAME ": could not ioremap, aborting.\n");
+               return;
+       }
+       do_write_test(p);
+       do_read_test(p);
+       iounmap(p);
+}
+
+static int __init init(void)
+{
+       if (mmio_address == 0) {
+               pr_err(MODULE_NAME ": you have to use the module argument "
+                                                       "mmio_address.\n");
+               pr_err(MODULE_NAME ": DO NOT LOAD THIS MODULE UNLESS"
+                               " YOU REALLY KNOW WHAT YOU ARE DOING!\n");
+               return -ENXIO;
+       }
+
+       pr_warning(MODULE_NAME ": WARNING: mapping 16 kB @ 0x%08lx "
+                                       "in PCI address space, and writing "
+                                       "rubbish in there.\n", mmio_address);
+       do_test();
+       return 0;
+}
+
+static void __exit cleanup(void)
+{
+       pr_debug(MODULE_NAME ": unloaded.\n");
+}
+
+module_init(init);
+module_exit(cleanup);
+MODULE_LICENSE("GPL");
index cc48d3f..2b6ad5b 100644 (file)
@@ -269,12 +269,13 @@ static void nmi_cpu_shutdown(void *dummy)
 
 static void nmi_shutdown(void)
 {
-       struct op_msrs *msrs = &__get_cpu_var(cpu_msrs);
+       struct op_msrs *msrs = &get_cpu_var(cpu_msrs);
        nmi_enabled = 0;
        on_each_cpu(nmi_cpu_shutdown, NULL, 0, 1);
        unregister_die_notifier(&profile_exceptions_nb);
        model->shutdown(msrs);
        free_msrs();
+       put_cpu_var(cpu_msrs);
 }
 
 static void nmi_cpu_start(void *dummy)
index c5c8e48..e515e8d 100644 (file)
@@ -1,5 +1,17 @@
-ifeq ($(CONFIG_X86_32),y)
-include ${srctree}/arch/x86/pci/Makefile_32
-else
-include ${srctree}/arch/x86/pci/Makefile_64
-endif
+obj-y                          := i386.o init.o
+
+obj-$(CONFIG_PCI_BIOS)         += pcbios.o
+obj-$(CONFIG_PCI_MMCONFIG)     += mmconfig_$(BITS).o direct.o mmconfig-shared.o
+obj-$(CONFIG_PCI_DIRECT)       += direct.o
+obj-$(CONFIG_PCI_OLPC)         += olpc.o
+
+pci-y                          := fixup.o
+pci-$(CONFIG_ACPI)             += acpi.o
+pci-y                          += legacy.o irq.o
+
+pci-$(CONFIG_X86_VISWS)                += visws.o
+
+pci-$(CONFIG_X86_NUMAQ)                += numa.o
+
+obj-y                          += $(pci-y) common.o early.o
+obj-y                          += amd_bus.o
diff --git a/arch/x86/pci/Makefile_32 b/arch/x86/pci/Makefile_32
deleted file mode 100644 (file)
index 89ec35d..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-obj-y                          := i386.o init.o
-
-obj-$(CONFIG_PCI_BIOS)         += pcbios.o
-obj-$(CONFIG_PCI_MMCONFIG)     += mmconfig_32.o direct.o mmconfig-shared.o
-obj-$(CONFIG_PCI_DIRECT)       += direct.o
-obj-$(CONFIG_PCI_OLPC)         += olpc.o
-
-pci-y                          := fixup.o
-
-# Do not change the ordering here. There is a nasty init function
-# ordering dependency which breaks when you move acpi.o below
-# legacy/irq.o
-pci-$(CONFIG_ACPI)             += acpi.o
-pci-y                          += legacy.o irq.o
-
-# Careful: VISWS and NUMAQ overrule the pci-y above. The colons are
-# therefor correct. This needs a proper fix by distangling the code.
-pci-$(CONFIG_X86_VISWS)                := visws.o fixup.o
-pci-$(CONFIG_X86_NUMAQ)                := numa.o irq.o
-
-# Necessary for NUMAQ as well
-pci-$(CONFIG_NUMA)             += mp_bus_to_node.o
-
-obj-y                          += $(pci-y) common.o early.o
diff --git a/arch/x86/pci/Makefile_64 b/arch/x86/pci/Makefile_64
deleted file mode 100644 (file)
index 8fbd198..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# Makefile for X86_64 specific PCI routines
-#
-# Reuse the i386 PCI subsystem
-#
-EXTRA_CFLAGS += -Iarch/x86/pci
-
-obj-y          := i386.o
-obj-$(CONFIG_PCI_DIRECT)+= direct.o
-obj-y          += fixup.o init.o
-obj-$(CONFIG_ACPI)     += acpi.o
-obj-y                  += legacy.o irq.o common.o early.o
-# mmconfig has a 64bit special
-obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_64.o direct.o mmconfig-shared.o
-
-obj-y          += k8-bus_64.o
-
index d95de2f..19af069 100644 (file)
@@ -171,8 +171,11 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do
        if (node != -1)
                set_mp_bus_to_node(busnum, node);
        else
-               node = get_mp_bus_to_node(busnum);
 #endif
+               node = get_mp_bus_to_node(busnum);
+
+       if (node != -1 && !node_online(node))
+               node = -1;
 
        /* Allocate per-root-bus (not per bus) arch-specific data.
         * TODO: leak; this memory is never freed.
@@ -204,22 +207,23 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do
        if (!bus)
                kfree(sd);
 
+       if (bus && node != -1) {
 #ifdef CONFIG_ACPI_NUMA
-       if (bus) {
-               if (pxm >= 0) {
+               if (pxm >= 0)
                        printk(KERN_DEBUG "bus %02x -> pxm %d -> node %d\n",
-                               busnum, pxm, pxm_to_node(pxm));
-               }
-       }
+                               busnum, pxm, node);
+#else
+               printk(KERN_DEBUG "bus %02x -> node %d\n",
+                       busnum, node);
 #endif
+       }
 
        if (bus && (pci_probe & PCI_USE__CRS))
                get_current_resources(device, busnum, domain, bus);
        return bus;
 }
 
-extern int pci_routeirq;
-static int __init pci_acpi_init(void)
+int __init pci_acpi_init(void)
 {
        struct pci_dev *dev = NULL;
 
@@ -253,4 +257,3 @@ static int __init pci_acpi_init(void)
 
        return 0;
 }
-subsys_initcall(pci_acpi_init);
diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
new file mode 100644 (file)
index 0000000..a18141a
--- /dev/null
@@ -0,0 +1,586 @@
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/topology.h>
+#include "pci.h"
+
+#ifdef CONFIG_X86_64
+#include <asm/pci-direct.h>
+#include <asm/mpspec.h>
+#include <linux/cpumask.h>
+#endif
+
+/*
+ * This discovers the pcibus <-> node mapping on AMD K8.
+ * also get peer root bus resource for io,mmio
+ */
+
+#ifdef CONFIG_NUMA
+
+#define BUS_NR 256
+
+#ifdef CONFIG_X86_64
+
+static int mp_bus_to_node[BUS_NR];
+
+void set_mp_bus_to_node(int busnum, int node)
+{
+       if (busnum >= 0 &&  busnum < BUS_NR)
+               mp_bus_to_node[busnum] = node;
+}
+
+int get_mp_bus_to_node(int busnum)
+{
+       int node = -1;
+
+       if (busnum < 0 || busnum > (BUS_NR - 1))
+               return node;
+
+       node = mp_bus_to_node[busnum];
+
+       /*
+        * let numa_node_id to decide it later in dma_alloc_pages
+        * if there is no ram on that node
+        */
+       if (node != -1 && !node_online(node))
+               node = -1;
+
+       return node;
+}
+
+#else /* CONFIG_X86_32 */
+
+static unsigned char mp_bus_to_node[BUS_NR];
+
+void set_mp_bus_to_node(int busnum, int node)
+{
+       if (busnum >= 0 &&  busnum < BUS_NR)
+       mp_bus_to_node[busnum] = (unsigned char) node;
+}
+
+int get_mp_bus_to_node(int busnum)
+{
+       int node;
+
+       if (busnum < 0 || busnum > (BUS_NR - 1))
+               return 0;
+       node = mp_bus_to_node[busnum];
+       return node;
+}
+
+#endif /* CONFIG_X86_32 */
+
+#endif /* CONFIG_NUMA */
+
+#ifdef CONFIG_X86_64
+
+/*
+ * sub bus (transparent) will use entres from 3 to store extra from root,
+ * so need to make sure have enought slot there, increase PCI_BUS_NUM_RESOURCES?
+ */
+#define RES_NUM 16
+struct pci_root_info {
+       char name[12];
+       unsigned int res_num;
+       struct resource res[RES_NUM];
+       int bus_min;
+       int bus_max;
+       int node;
+       int link;
+};
+
+/* 4 at this time, it may become to 32 */
+#define PCI_ROOT_NR 4
+static int pci_root_num;
+static struct pci_root_info pci_root_info[PCI_ROOT_NR];
+
+void set_pci_bus_resources_arch_default(struct pci_bus *b)
+{
+       int i;
+       int j;
+       struct pci_root_info *info;
+
+       /* if only one root bus, don't need to anything */
+       if (pci_root_num < 2)
+               return;
+
+       for (i = 0; i < pci_root_num; i++) {
+               if (pci_root_info[i].bus_min == b->number)
+                       break;
+       }
+
+       if (i == pci_root_num)
+               return;
+
+       info = &pci_root_info[i];
+       for (j = 0; j < info->res_num; j++) {
+               struct resource *res;
+               struct resource *root;
+
+               res = &info->res[j];
+               b->resource[j] = res;
+               if (res->flags & IORESOURCE_IO)
+                       root = &ioport_resource;
+               else
+                       root = &iomem_resource;
+               insert_resource(root, res);
+       }
+}
+
+#define RANGE_NUM 16
+
+struct res_range {
+       size_t start;
+       size_t end;
+};
+
+static void __init update_range(struct res_range *range, size_t start,
+                               size_t end)
+{
+       int i;
+       int j;
+
+       for (j = 0; j < RANGE_NUM; j++) {
+               if (!range[j].end)
+                       continue;
+
+               if (start <= range[j].start && end >= range[j].end) {
+                       range[j].start = 0;
+                       range[j].end = 0;
+                       continue;
+               }
+
+               if (start <= range[j].start && end < range[j].end && range[j].start < end + 1) {
+                       range[j].start = end + 1;
+                       continue;
+               }
+
+
+               if (start > range[j].start && end >= range[j].end && range[j].end > start - 1) {
+                       range[j].end = start - 1;
+                       continue;
+               }
+
+               if (start > range[j].start && end < range[j].end) {
+                       /* find the new spare */
+                       for (i = 0; i < RANGE_NUM; i++) {
+                               if (range[i].end == 0)
+                                       break;
+                       }
+                       if (i < RANGE_NUM) {
+                               range[i].end = range[j].end;
+                               range[i].start = end + 1;
+                       } else {
+                               printk(KERN_ERR "run of slot in ranges\n");
+                       }
+                       range[j].end = start - 1;
+                       continue;
+               }
+       }
+}
+
+static void __init update_res(struct pci_root_info *info, size_t start,
+                             size_t end, unsigned long flags, int merge)
+{
+       int i;
+       struct resource *res;
+
+       if (!merge)
+               goto addit;
+
+       /* try to merge it with old one */
+       for (i = 0; i < info->res_num; i++) {
+               size_t final_start, final_end;
+               size_t common_start, common_end;
+
+               res = &info->res[i];
+               if (res->flags != flags)
+                       continue;
+
+               common_start = max((size_t)res->start, start);
+               common_end = min((size_t)res->end, end);
+               if (common_start > common_end + 1)
+                       continue;
+
+               final_start = min((size_t)res->start, start);
+               final_end = max((size_t)res->end, end);
+
+               res->start = final_start;
+               res->end = final_end;
+               return;
+       }
+
+addit:
+
+       /* need to add that */
+       if (info->res_num >= RES_NUM)
+               return;
+
+       res = &info->res[info->res_num];
+       res->name = info->name;
+       res->flags = flags;
+       res->start = start;
+       res->end = end;
+       res->child = NULL;
+       info->res_num++;
+}
+
+struct pci_hostbridge_probe {
+       u32 bus;
+       u32 slot;
+       u32 vendor;
+       u32 device;
+};
+
+static struct pci_hostbridge_probe pci_probes[] __initdata = {
+       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1100 },
+       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 },
+       { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 },
+       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1300 },
+};
+
+static u64 __initdata fam10h_mmconf_start;
+static u64 __initdata fam10h_mmconf_end;
+static void __init get_pci_mmcfg_amd_fam10h_range(void)
+{
+       u32 address;
+       u64 base, msr;
+       unsigned segn_busn_bits;
+
+       /* assume all cpus from fam10h have mmconf */
+        if (boot_cpu_data.x86 < 0x10)
+               return;
+
+       address = MSR_FAM10H_MMIO_CONF_BASE;
+       rdmsrl(address, msr);
+
+       /* mmconfig is not enable */
+       if (!(msr & FAM10H_MMIO_CONF_ENABLE))
+               return;
+
+       base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT);
+
+       segn_busn_bits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
+                        FAM10H_MMIO_CONF_BUSRANGE_MASK;
+
+       fam10h_mmconf_start = base;
+       fam10h_mmconf_end = base + (1ULL<<(segn_busn_bits + 20)) - 1;
+}
+
+/**
+ * early_fill_mp_bus_to_node()
+ * called before pcibios_scan_root and pci_scan_bus
+ * fills the mp_bus_to_cpumask array based according to the LDT Bus Number
+ * Registers found in the K8 northbridge
+ */
+static int __init early_fill_mp_bus_info(void)
+{
+       int i;
+       int j;
+       unsigned bus;
+       unsigned slot;
+       int found;
+       int node;
+       int link;
+       int def_node;
+       int def_link;
+       struct pci_root_info *info;
+       u32 reg;
+       struct resource *res;
+       size_t start;
+       size_t end;
+       struct res_range range[RANGE_NUM];
+       u64 val;
+       u32 address;
+
+#ifdef CONFIG_NUMA
+       for (i = 0; i < BUS_NR; i++)
+               mp_bus_to_node[i] = -1;
+#endif
+
+       if (!early_pci_allowed())
+               return -1;
+
+       found = 0;
+       for (i = 0; i < ARRAY_SIZE(pci_probes); i++) {
+               u32 id;
+               u16 device;
+               u16 vendor;
+
+               bus = pci_probes[i].bus;
+               slot = pci_probes[i].slot;
+               id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
+
+               vendor = id & 0xffff;
+               device = (id>>16) & 0xffff;
+               if (pci_probes[i].vendor == vendor &&
+                   pci_probes[i].device == device) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found)
+               return 0;
+
+       pci_root_num = 0;
+       for (i = 0; i < 4; i++) {
+               int min_bus;
+               int max_bus;
+               reg = read_pci_config(bus, slot, 1, 0xe0 + (i << 2));
+
+               /* Check if that register is enabled for bus range */
+               if ((reg & 7) != 3)
+                       continue;
+
+               min_bus = (reg >> 16) & 0xff;
+               max_bus = (reg >> 24) & 0xff;
+               node = (reg >> 4) & 0x07;
+#ifdef CONFIG_NUMA
+               for (j = min_bus; j <= max_bus; j++)
+                       mp_bus_to_node[j] = (unsigned char) node;
+#endif
+               link = (reg >> 8) & 0x03;
+
+               info = &pci_root_info[pci_root_num];
+               info->bus_min = min_bus;
+               info->bus_max = max_bus;
+               info->node = node;
+               info->link = link;
+               sprintf(info->name, "PCI Bus #%02x", min_bus);
+               pci_root_num++;
+       }
+
+       /* get the default node and link for left over res */
+       reg = read_pci_config(bus, slot, 0, 0x60);
+       def_node = (reg >> 8) & 0x07;
+       reg = read_pci_config(bus, slot, 0, 0x64);
+       def_link = (reg >> 8) & 0x03;
+
+       memset(range, 0, sizeof(range));
+       range[0].end = 0xffff;
+       /* io port resource */
+       for (i = 0; i < 4; i++) {
+               reg = read_pci_config(bus, slot, 1, 0xc0 + (i << 3));
+               if (!(reg & 3))
+                       continue;
+
+               start = reg & 0xfff000;
+               reg = read_pci_config(bus, slot, 1, 0xc4 + (i << 3));
+               node = reg & 0x07;
+               link = (reg >> 4) & 0x03;
+               end = (reg & 0xfff000) | 0xfff;
+
+               /* find the position */
+               for (j = 0; j < pci_root_num; j++) {
+                       info = &pci_root_info[j];
+                       if (info->node == node && info->link == link)
+                               break;
+               }
+               if (j == pci_root_num)
+                       continue; /* not found */
+
+               info = &pci_root_info[j];
+               printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n",
+                      node, link, (u64)start, (u64)end);
+
+               /* kernel only handle 16 bit only */
+               if (end > 0xffff)
+                       end = 0xffff;
+               update_res(info, start, end, IORESOURCE_IO, 1);
+               update_range(range, start, end);
+       }
+       /* add left over io port range to def node/link, [0, 0xffff] */
+       /* find the position */
+       for (j = 0; j < pci_root_num; j++) {
+               info = &pci_root_info[j];
+               if (info->node == def_node && info->link == def_link)
+                       break;
+       }
+       if (j < pci_root_num) {
+               info = &pci_root_info[j];
+               for (i = 0; i < RANGE_NUM; i++) {
+                       if (!range[i].end)
+                               continue;
+
+                       update_res(info, range[i].start, range[i].end,
+                                  IORESOURCE_IO, 1);
+               }
+       }
+
+       memset(range, 0, sizeof(range));
+       /* 0xfd00000000-0xffffffffff for HT */
+       range[0].end = (0xfdULL<<32) - 1;
+
+       /* need to take out [0, TOM) for RAM*/
+       address = MSR_K8_TOP_MEM1;
+       rdmsrl(address, val);
+       end = (val & 0xffffff800000ULL);
+       printk(KERN_INFO "TOM: %016lx aka %ldM\n", end, end>>20);
+       if (end < (1ULL<<32))
+               update_range(range, 0, end - 1);
+
+       /* get mmconfig */
+       get_pci_mmcfg_amd_fam10h_range();
+       /* need to take out mmconf range */
+       if (fam10h_mmconf_end) {
+               printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end);
+               update_range(range, fam10h_mmconf_start, fam10h_mmconf_end);
+       }
+
+       /* mmio resource */
+       for (i = 0; i < 8; i++) {
+               reg = read_pci_config(bus, slot, 1, 0x80 + (i << 3));
+               if (!(reg & 3))
+                       continue;
+
+               start = reg & 0xffffff00; /* 39:16 on 31:8*/
+               start <<= 8;
+               reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3));
+               node = reg & 0x07;
+               link = (reg >> 4) & 0x03;
+               end = (reg & 0xffffff00);
+               end <<= 8;
+               end |= 0xffff;
+
+               /* find the position */
+               for (j = 0; j < pci_root_num; j++) {
+                       info = &pci_root_info[j];
+                       if (info->node == node && info->link == link)
+                               break;
+               }
+               if (j == pci_root_num)
+                       continue; /* not found */
+
+               info = &pci_root_info[j];
+
+               printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]",
+                      node, link, (u64)start, (u64)end);
+               /*
+                * some sick allocation would have range overlap with fam10h
+                * mmconf range, so need to update start and end.
+                */
+               if (fam10h_mmconf_end) {
+                       int changed = 0;
+                       u64 endx = 0;
+                       if (start >= fam10h_mmconf_start &&
+                           start <= fam10h_mmconf_end) {
+                               start = fam10h_mmconf_end + 1;
+                               changed = 1;
+                       }
+
+                       if (end >= fam10h_mmconf_start &&
+                           end <= fam10h_mmconf_end) {
+                               end = fam10h_mmconf_start - 1;
+                               changed = 1;
+                       }
+
+                       if (start < fam10h_mmconf_start &&
+                           end > fam10h_mmconf_end) {
+                               /* we got a hole */
+                               endx = fam10h_mmconf_start - 1;
+                               update_res(info, start, endx, IORESOURCE_MEM, 0);
+                               update_range(range, start, endx);
+                               printk(KERN_CONT " ==> [%llx, %llx]", (u64)start, endx);
+                               start = fam10h_mmconf_end + 1;
+                               changed = 1;
+                       }
+                       if (changed) {
+                               if (start <= end) {
+                                       printk(KERN_CONT " %s [%llx, %llx]", endx?"and":"==>", (u64)start, (u64)end);
+                               } else {
+                                       printk(KERN_CONT "%s\n", endx?"":" ==> none");
+                                       continue;
+                               }
+                       }
+               }
+
+               update_res(info, start, end, IORESOURCE_MEM, 1);
+               update_range(range, start, end);
+               printk(KERN_CONT "\n");
+       }
+
+       /* need to take out [4G, TOM2) for RAM*/
+       /* SYS_CFG */
+       address = MSR_K8_SYSCFG;
+       rdmsrl(address, val);
+       /* TOP_MEM2 is enabled? */
+       if (val & (1<<21)) {
+               /* TOP_MEM2 */
+               address = MSR_K8_TOP_MEM2;
+               rdmsrl(address, val);
+               end = (val & 0xffffff800000ULL);
+               printk(KERN_INFO "TOM2: %016lx aka %ldM\n", end, end>>20);
+               update_range(range, 1ULL<<32, end - 1);
+       }
+
+       /*
+        * add left over mmio range to def node/link ?
+        * that is tricky, just record range in from start_min to 4G
+        */
+       for (j = 0; j < pci_root_num; j++) {
+               info = &pci_root_info[j];
+               if (info->node == def_node && info->link == def_link)
+                       break;
+       }
+       if (j < pci_root_num) {
+               info = &pci_root_info[j];
+
+               for (i = 0; i < RANGE_NUM; i++) {
+                       if (!range[i].end)
+                               continue;
+
+                       update_res(info, range[i].start, range[i].end,
+                                  IORESOURCE_MEM, 1);
+               }
+       }
+
+       for (i = 0; i < pci_root_num; i++) {
+               int res_num;
+               int busnum;
+
+               info = &pci_root_info[i];
+               res_num = info->res_num;
+               busnum = info->bus_min;
+               printk(KERN_DEBUG "bus: [%02x,%02x] on node %x link %x\n",
+                      info->bus_min, info->bus_max, info->node, info->link);
+               for (j = 0; j < res_num; j++) {
+                       res = &info->res[j];
+                       printk(KERN_DEBUG "bus: %02x index %x %s: [%llx, %llx]\n",
+                              busnum, j,
+                              (res->flags & IORESOURCE_IO)?"io port":"mmio",
+                              res->start, res->end);
+               }
+       }
+
+       return 0;
+}
+
+postcore_initcall(early_fill_mp_bus_info);
+
+#endif
+
+/* common 32/64 bit code */
+
+#define ENABLE_CF8_EXT_CFG      (1ULL << 46)
+
+static void enable_pci_io_ecs_per_cpu(void *unused)
+{
+       u64 reg;
+       rdmsrl(MSR_AMD64_NB_CFG, reg);
+       if (!(reg & ENABLE_CF8_EXT_CFG)) {
+               reg |= ENABLE_CF8_EXT_CFG;
+               wrmsrl(MSR_AMD64_NB_CFG, reg);
+       }
+}
+
+static int __init enable_pci_io_ecs(void)
+{
+       /* assume all cpus from fam10h have IO ECS */
+        if (boot_cpu_data.x86 < 0x10)
+               return 0;
+       on_each_cpu(enable_pci_io_ecs_per_cpu, NULL, 1, 1);
+       pci_probe |= PCI_HAS_IO_ECS;
+       return 0;
+}
+
+postcore_initcall(enable_pci_io_ecs);
index 6e64aaf..20b9f59 100644 (file)
@@ -384,7 +384,7 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)
 
 extern u8 pci_cache_line_size;
 
-static int __init pcibios_init(void)
+int __init pcibios_init(void)
 {
        struct cpuinfo_x86 *c = &boot_cpu_data;
 
@@ -411,8 +411,6 @@ static int __init pcibios_init(void)
        return 0;
 }
 
-subsys_initcall(pcibios_init);
-
 char * __devinit  pcibios_setup(char *str)
 {
        if (!strcmp(str, "off")) {
index 21d1e0e..9915293 100644 (file)
@@ -8,18 +8,21 @@
 #include "pci.h"
 
 /*
- * Functions for accessing PCI configuration space with type 1 accesses
+ * Functions for accessing PCI base (first 256 bytes) and extended
+ * (4096 bytes per PCI function) configuration space with type 1
+ * accesses.
  */
 
 #define PCI_CONF1_ADDRESS(bus, devfn, reg) \
-       (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
+       (0x80000000 | ((reg & 0xF00) << 16) | (bus << 16) \
+       | (devfn << 8) | (reg & 0xFC))
 
 static int pci_conf1_read(unsigned int seg, unsigned int bus,
                          unsigned int devfn, int reg, int len, u32 *value)
 {
        unsigned long flags;
 
-       if ((bus > 255) || (devfn > 255) || (reg > 255)) {
+       if ((bus > 255) || (devfn > 255) || (reg > 4095)) {
                *value = -1;
                return -EINVAL;
        }
@@ -50,7 +53,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
 {
        unsigned long flags;
 
-       if ((bus > 255) || (devfn > 255) || (reg > 255)) 
+       if ((bus > 255) || (devfn > 255) || (reg > 4095))
                return -EINVAL;
 
        spin_lock_irqsave(&pci_config_lock, flags);
@@ -260,10 +263,18 @@ void __init pci_direct_init(int type)
                return;
        printk(KERN_INFO "PCI: Using configuration type %d for base access\n",
                 type);
-       if (type == 1)
+       if (type == 1) {
                raw_pci_ops = &pci_direct_conf1;
-       else
-               raw_pci_ops = &pci_direct_conf2;
+               if (raw_pci_ext_ops)
+                       return;
+               if (!(pci_probe & PCI_HAS_IO_ECS))
+                       return;
+               printk(KERN_INFO "PCI: Using configuration type 1 "
+                      "for extended access\n");
+               raw_pci_ext_ops = &pci_direct_conf1;
+               return;
+       }
+       raw_pci_ops = &pci_direct_conf2;
 }
 
 int __init pci_direct_probe(void)
index 10fb308..2aafb67 100644 (file)
@@ -299,9 +299,9 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
                return -EINVAL;
 
        prot = pgprot_val(vma->vm_page_prot);
-       if (pat_wc_enabled && write_combine)
+       if (pat_enabled && write_combine)
                prot |= _PAGE_CACHE_WC;
-       else if (pat_wc_enabled || boot_cpu_data.x86 > 3)
+       else if (pat_enabled || boot_cpu_data.x86 > 3)
                /*
                 * ioremap() and ioremap_nocache() defaults to UC MINUS for now.
                 * To avoid attribute conflicts, request UC MINUS here
@@ -334,7 +334,9 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
                flags = new_flags;
        }
 
-       if (vma->vm_pgoff <= max_pfn_mapped &&
+       if (((vma->vm_pgoff < max_low_pfn_mapped) ||
+            (vma->vm_pgoff >= (1UL<<(32 - PAGE_SHIFT)) &&
+             vma->vm_pgoff < max_pfn_mapped)) &&
            ioremap_change_attr((unsigned long)__va(addr), len, flags)) {
                free_memtype(addr, addr + len);
                return -EINVAL;
index b821f44..d6c950f 100644 (file)
@@ -4,7 +4,7 @@
 
 /* arch_initcall has too random ordering, so call the initializers
    in the right sequence from here. */
-static __init int pci_access_init(void)
+static __init int pci_arch_init(void)
 {
 #ifdef CONFIG_PCI_DIRECT
        int type = 0;
@@ -40,4 +40,4 @@ static __init int pci_access_init(void)
 
        return 0;
 }
-arch_initcall(pci_access_init);
+arch_initcall(pci_arch_init);
index ca8df9c..dc568c6 100644 (file)
@@ -11,8 +11,8 @@
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/dmi.h>
-#include <asm/io.h>
-#include <asm/smp.h>
+#include <linux/io.h>
+#include <linux/smp.h>
 #include <asm/io_apic.h>
 #include <linux/irq.h>
 #include <linux/acpi.h>
@@ -61,7 +61,7 @@ void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
  *  and perform checksum verification.
  */
 
-static inline struct irq_routing_table * pirq_check_routing_table(u8 *addr)
+static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr)
 {
        struct irq_routing_table *rt;
        int i;
@@ -74,7 +74,7 @@ static inline struct irq_routing_table * pirq_check_routing_table(u8 *addr)
            rt->size < sizeof(struct irq_routing_table))
                return NULL;
        sum = 0;
-       for (i=0; i < rt->size; i++)
+       for (i = 0; i < rt->size; i++)
                sum += addr[i];
        if (!sum) {
                DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n", rt);
@@ -100,7 +100,7 @@ static struct irq_routing_table * __init pirq_find_routing_table(void)
                        return rt;
                printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n");
        }
-       for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {
+       for (addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {
                rt = pirq_check_routing_table(addr);
                if (rt)
                        return rt;
@@ -122,20 +122,20 @@ static void __init pirq_peer_trick(void)
        struct irq_info *e;
 
        memset(busmap, 0, sizeof(busmap));
-       for(i=0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
+       for (i = 0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
                e = &rt->slots[i];
 #ifdef DEBUG
                {
                        int j;
                        DBG(KERN_DEBUG "%02x:%02x slot=%02x", e->bus, e->devfn/8, e->slot);
-                       for(j=0; j<4; j++)
+                       for (j = 0; j < 4; j++)
                                DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);
                        DBG("\n");
                }
 #endif
                busmap[e->bus] = 1;
        }
-       for(i = 1; i < 256; i++) {
+       for (i = 1; i < 256; i++) {
                int node;
                if (!busmap[i] || pci_find_bus(0, i))
                        continue;
@@ -285,7 +285,7 @@ static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
        static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
 
        WARN_ON_ONCE(pirq > 4);
-       return read_config_nybble(router,0x43, pirqmap[pirq-1]);
+       return read_config_nybble(router, 0x43, pirqmap[pirq-1]);
 }
 
 static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
@@ -314,7 +314,7 @@ static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
 
 /*
  * Cyrix: nibble offset 0x5C
- * 0x5C bits 7:4 is INTB bits 3:0 is INTA 
+ * 0x5C bits 7:4 is INTB bits 3:0 is INTA
  * 0x5D bits 7:4 is INTD bits 3:0 is INTC
  */
 static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
@@ -350,7 +350,7 @@ static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  *     Apparently there are systems implementing PCI routing table using
  *     link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D.
  *     We try our best to handle both link mappings.
- *     
+ *
  *     Currently (2003-05-21) it appears most SiS chipsets follow the
  *     definition of routing registers from the SiS-5595 southbridge.
  *     According to the SiS 5595 datasheets the revision id's of the
@@ -370,7 +370,7 @@ static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq,
  *
  *     0x62:   USBIRQ:
  *             bit 6 OHCI function disabled (0), enabled (1)
- *     
+ *
  *     0x6a:   ACPI/SCI IRQ: bits 4-6 reserved
  *
  *     0x7e:   Data Acq. Module IRQ - bits 4-6 reserved
@@ -487,9 +487,7 @@ static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq
        u8 irq;
        irq = 0;
        if (pirq <= 4)
-       {
                irq = read_config_nybble(router, 0x56, pirq - 1);
-       }
        printk(KERN_INFO "AMD756: dev %04x:%04x, router pirq : %d get irq : %2d\n",
                dev->vendor, dev->device, pirq, irq);
        return irq;
@@ -497,12 +495,10 @@ static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq
 
 static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
 {
-       printk(KERN_INFO "AMD756: dev %04x:%04x, router pirq : %d SET irq : %2d\n", 
+       printk(KERN_INFO "AMD756: dev %04x:%04x, router pirq : %d SET irq : %2d\n",
                dev->vendor, dev->device, pirq, irq);
        if (pirq <= 4)
-       {
                write_config_nybble(router, 0x56, pirq - 1, irq);
-       }
        return 1;
 }
 
@@ -549,50 +545,49 @@ static __init int intel_router_probe(struct irq_router *r, struct pci_dev *route
        if (pci_dev_present(pirq_440gx))
                return 0;
 
-       switch(device)
-       {
-               case PCI_DEVICE_ID_INTEL_82371FB_0:
-               case PCI_DEVICE_ID_INTEL_82371SB_0:
-               case PCI_DEVICE_ID_INTEL_82371AB_0:
-               case PCI_DEVICE_ID_INTEL_82371MX:
-               case PCI_DEVICE_ID_INTEL_82443MX_0:
-               case PCI_DEVICE_ID_INTEL_82801AA_0:
-               case PCI_DEVICE_ID_INTEL_82801AB_0:
-               case PCI_DEVICE_ID_INTEL_82801BA_0:
-               case PCI_DEVICE_ID_INTEL_82801BA_10:
-               case PCI_DEVICE_ID_INTEL_82801CA_0:
-               case PCI_DEVICE_ID_INTEL_82801CA_12:
-               case PCI_DEVICE_ID_INTEL_82801DB_0:
-               case PCI_DEVICE_ID_INTEL_82801E_0:
-               case PCI_DEVICE_ID_INTEL_82801EB_0:
-               case PCI_DEVICE_ID_INTEL_ESB_1:
-               case PCI_DEVICE_ID_INTEL_ICH6_0:
-               case PCI_DEVICE_ID_INTEL_ICH6_1:
-               case PCI_DEVICE_ID_INTEL_ICH7_0:
-               case PCI_DEVICE_ID_INTEL_ICH7_1:
-               case PCI_DEVICE_ID_INTEL_ICH7_30:
-               case PCI_DEVICE_ID_INTEL_ICH7_31:
-               case PCI_DEVICE_ID_INTEL_ESB2_0:
-               case PCI_DEVICE_ID_INTEL_ICH8_0:
-               case PCI_DEVICE_ID_INTEL_ICH8_1:
-               case PCI_DEVICE_ID_INTEL_ICH8_2:
-               case PCI_DEVICE_ID_INTEL_ICH8_3:
-               case PCI_DEVICE_ID_INTEL_ICH8_4:
-               case PCI_DEVICE_ID_INTEL_ICH9_0:
-               case PCI_DEVICE_ID_INTEL_ICH9_1:
-               case PCI_DEVICE_ID_INTEL_ICH9_2:
-               case PCI_DEVICE_ID_INTEL_ICH9_3:
-               case PCI_DEVICE_ID_INTEL_ICH9_4:
-               case PCI_DEVICE_ID_INTEL_ICH9_5:
-               case PCI_DEVICE_ID_INTEL_TOLAPAI_0:
-               case PCI_DEVICE_ID_INTEL_ICH10_0:
-               case PCI_DEVICE_ID_INTEL_ICH10_1:
-               case PCI_DEVICE_ID_INTEL_ICH10_2:
-               case PCI_DEVICE_ID_INTEL_ICH10_3:
-                       r->name = "PIIX/ICH";
-                       r->get = pirq_piix_get;
-                       r->set = pirq_piix_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_INTEL_82371FB_0:
+       case PCI_DEVICE_ID_INTEL_82371SB_0:
+       case PCI_DEVICE_ID_INTEL_82371AB_0:
+       case PCI_DEVICE_ID_INTEL_82371MX:
+       case PCI_DEVICE_ID_INTEL_82443MX_0:
+       case PCI_DEVICE_ID_INTEL_82801AA_0:
+       case PCI_DEVICE_ID_INTEL_82801AB_0:
+       case PCI_DEVICE_ID_INTEL_82801BA_0:
+       case PCI_DEVICE_ID_INTEL_82801BA_10:
+       case PCI_DEVICE_ID_INTEL_82801CA_0:
+       case PCI_DEVICE_ID_INTEL_82801CA_12:
+       case PCI_DEVICE_ID_INTEL_82801DB_0:
+       case PCI_DEVICE_ID_INTEL_82801E_0:
+       case PCI_DEVICE_ID_INTEL_82801EB_0:
+       case PCI_DEVICE_ID_INTEL_ESB_1:
+       case PCI_DEVICE_ID_INTEL_ICH6_0:
+       case PCI_DEVICE_ID_INTEL_ICH6_1:
+       case PCI_DEVICE_ID_INTEL_ICH7_0:
+       case PCI_DEVICE_ID_INTEL_ICH7_1:
+       case PCI_DEVICE_ID_INTEL_ICH7_30:
+       case PCI_DEVICE_ID_INTEL_ICH7_31:
+       case PCI_DEVICE_ID_INTEL_ESB2_0:
+       case PCI_DEVICE_ID_INTEL_ICH8_0:
+       case PCI_DEVICE_ID_INTEL_ICH8_1:
+       case PCI_DEVICE_ID_INTEL_ICH8_2:
+       case PCI_DEVICE_ID_INTEL_ICH8_3:
+       case PCI_DEVICE_ID_INTEL_ICH8_4:
+       case PCI_DEVICE_ID_INTEL_ICH9_0:
+       case PCI_DEVICE_ID_INTEL_ICH9_1:
+       case PCI_DEVICE_ID_INTEL_ICH9_2:
+       case PCI_DEVICE_ID_INTEL_ICH9_3:
+       case PCI_DEVICE_ID_INTEL_ICH9_4:
+       case PCI_DEVICE_ID_INTEL_ICH9_5:
+       case PCI_DEVICE_ID_INTEL_TOLAPAI_0:
+       case PCI_DEVICE_ID_INTEL_ICH10_0:
+       case PCI_DEVICE_ID_INTEL_ICH10_1:
+       case PCI_DEVICE_ID_INTEL_ICH10_2:
+       case PCI_DEVICE_ID_INTEL_ICH10_3:
+               r->name = "PIIX/ICH";
+               r->get = pirq_piix_get;
+               r->set = pirq_piix_set;
+               return 1;
        }
        return 0;
 }
@@ -606,7 +601,7 @@ static __init int via_router_probe(struct irq_router *r,
         * workarounds for some buggy BIOSes
         */
        if (device == PCI_DEVICE_ID_VIA_82C586_0) {
-               switch(router->device) {
+               switch (router->device) {
                case PCI_DEVICE_ID_VIA_82C686:
                        /*
                         * Asus k7m bios wrongly reports 82C686A
@@ -631,7 +626,7 @@ static __init int via_router_probe(struct irq_router *r,
                }
        }
 
-       switch(device) {
+       switch (device) {
        case PCI_DEVICE_ID_VIA_82C586_0:
                r->name = "VIA";
                r->get = pirq_via586_get;
@@ -654,13 +649,12 @@ static __init int via_router_probe(struct irq_router *r,
 
 static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_VLSI_82C534:
-                       r->name = "VLSI 82C534";
-                       r->get = pirq_vlsi_get;
-                       r->set = pirq_vlsi_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_VLSI_82C534:
+               r->name = "VLSI 82C534";
+               r->get = pirq_vlsi_get;
+               r->set = pirq_vlsi_set;
+               return 1;
        }
        return 0;
 }
@@ -668,14 +662,13 @@ static __init int vlsi_router_probe(struct irq_router *r, struct pci_dev *router
 
 static __init int serverworks_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_SERVERWORKS_OSB4:
-               case PCI_DEVICE_ID_SERVERWORKS_CSB5:
-                       r->name = "ServerWorks";
-                       r->get = pirq_serverworks_get;
-                       r->set = pirq_serverworks_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_SERVERWORKS_OSB4:
+       case PCI_DEVICE_ID_SERVERWORKS_CSB5:
+               r->name = "ServerWorks";
+               r->get = pirq_serverworks_get;
+               r->set = pirq_serverworks_set;
+               return 1;
        }
        return 0;
 }
@@ -684,7 +677,7 @@ static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router,
 {
        if (device != PCI_DEVICE_ID_SI_503)
                return 0;
-               
+
        r->name = "SIS";
        r->get = pirq_sis_get;
        r->set = pirq_sis_set;
@@ -693,47 +686,43 @@ static __init int sis_router_probe(struct irq_router *r, struct pci_dev *router,
 
 static __init int cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_CYRIX_5520:
-                       r->name = "NatSemi";
-                       r->get = pirq_cyrix_get;
-                       r->set = pirq_cyrix_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_CYRIX_5520:
+               r->name = "NatSemi";
+               r->get = pirq_cyrix_get;
+               r->set = pirq_cyrix_set;
+               return 1;
        }
        return 0;
 }
 
 static __init int opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_OPTI_82C700:
-                       r->name = "OPTI";
-                       r->get = pirq_opti_get;
-                       r->set = pirq_opti_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_OPTI_82C700:
+               r->name = "OPTI";
+               r->get = pirq_opti_get;
+               r->set = pirq_opti_set;
+               return 1;
        }
        return 0;
 }
 
 static __init int ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_ITE_IT8330G_0:
-                       r->name = "ITE";
-                       r->get = pirq_ite_get;
-                       r->set = pirq_ite_set;
-                       return 1;
+       switch (device) {
+       case PCI_DEVICE_ID_ITE_IT8330G_0:
+               r->name = "ITE";
+               r->get = pirq_ite_get;
+               r->set = pirq_ite_set;
+               return 1;
        }
        return 0;
 }
 
 static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
+       switch (device) {
        case PCI_DEVICE_ID_AL_M1533:
        case PCI_DEVICE_ID_AL_M1563:
                printk(KERN_DEBUG "PCI: Using ALI IRQ Router\n");
@@ -747,25 +736,24 @@ static __init int ali_router_probe(struct irq_router *r, struct pci_dev *router,
 
 static __init int amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
-       switch(device)
-       {
-               case PCI_DEVICE_ID_AMD_VIPER_740B:
-                       r->name = "AMD756";
-                       break;
-               case PCI_DEVICE_ID_AMD_VIPER_7413:
-                       r->name = "AMD766";
-                       break;
-               case PCI_DEVICE_ID_AMD_VIPER_7443:
-                       r->name = "AMD768";
-                       break;
-               default:
-                       return 0;
+       switch (device) {
+       case PCI_DEVICE_ID_AMD_VIPER_740B:
+               r->name = "AMD756";
+               break;
+       case PCI_DEVICE_ID_AMD_VIPER_7413:
+               r->name = "AMD766";
+               break;
+       case PCI_DEVICE_ID_AMD_VIPER_7443:
+               r->name = "AMD768";
+               break;
+       default:
+               return 0;
        }
        r->get = pirq_amd756_get;
        r->set = pirq_amd756_set;
        return 1;
 }
-               
+
 static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device)
 {
        switch (device) {
@@ -807,7 +795,7 @@ static struct pci_dev *pirq_router_dev;
  *     FIXME: should we have an option to say "generic for
  *     chipset" ?
  */
+
 static void __init pirq_find_router(struct irq_router *r)
 {
        struct irq_routing_table *rt = pirq_table;
@@ -826,7 +814,7 @@ static void __init pirq_find_router(struct irq_router *r)
        r->name = "default";
        r->get = NULL;
        r->set = NULL;
-       
+
        DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for %04x:%04x\n",
            rt->rtr_vendor, rt->rtr_device);
 
@@ -837,7 +825,7 @@ static void __init pirq_find_router(struct irq_router *r)
                return;
        }
 
-       forh = pirq_routers; h->vendor; h++) {
+       for (h = pirq_routers; h->vendor; h++) {
                /* First look for a router match */
                if (rt->rtr_vendor == h->vendor && h->probe(r, pirq_router_dev, rt->rtr_device))
                        break;
@@ -889,7 +877,7 @@ static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
 
        if (!pirq_table)
                return 0;
-       
+
        DBG(KERN_DEBUG "IRQ for %s[%c]", pci_name(dev), 'A' + pin);
        info = pirq_get_info(dev);
        if (!info) {
@@ -928,8 +916,10 @@ static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
         */
        newirq = dev->irq;
        if (newirq && !((1 << newirq) & mask)) {
-               if ( pci_probe & PCI_USE_PIRQ_MASK) newirq = 0;
-               else printk("\n" KERN_WARNING
+               if (pci_probe & PCI_USE_PIRQ_MASK)
+                       newirq = 0;
+               else
+                       printk("\n" KERN_WARNING
                        "PCI: IRQ %i for device %s doesn't match PIRQ mask "
                        "- try pci=usepirqmask\n" KERN_DEBUG, newirq,
                        pci_name(dev));
@@ -949,8 +939,8 @@ static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
                irq = pirq & 0xf;
                DBG(" -> hardcoded IRQ %d\n", irq);
                msg = "Hardcoded";
-       } else if ( r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
-       ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask)) ) {
+       } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
+       ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) {
                DBG(" -> got IRQ %d\n", irq);
                msg = "Found";
                eisa_set_level_irq(irq);
@@ -985,15 +975,15 @@ static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
                        continue;
                if (info->irq[pin].link == pirq) {
                        /* We refuse to override the dev->irq information. Give a warning! */
-                       if ( dev2->irq && dev2->irq != irq && \
+                       if (dev2->irq && dev2->irq != irq && \
                        (!(pci_probe & PCI_USE_PIRQ_MASK) || \
-                       ((1 << dev2->irq) & mask)) ) {
+                       ((1 << dev2->irq) & mask))) {
 #ifndef CONFIG_PCI_MSI
-                               printk(KERN_INFO "IRQ routing conflict for %s, have irq %d, want irq %d\n",
+                               printk(KERN_INFO "IRQ routing conflict for %s, have irq %d, want irq %d\n",
                                       pci_name(dev2), dev2->irq, irq);
 #endif
-                               continue;
-                       }
+                               continue;
+                       }
                        dev2->irq = irq;
                        pirq_penalty[irq]++;
                        if (dev != dev2)
@@ -1031,8 +1021,7 @@ static void __init pcibios_fixup_irqs(void)
                /*
                 * Recalculate IRQ numbers if we use the I/O APIC.
                 */
-               if (io_apic_assign_pci_irqs)
-               {
+               if (io_apic_assign_pci_irqs) {
                        int irq;
 
                        if (pin) {
@@ -1045,10 +1034,10 @@ static void __init pcibios_fixup_irqs(void)
         * busses itself so we should get into this branch reliably.
         */
                                if (irq < 0 && dev->bus->parent) { /* go back to the bridge */
-                                       struct pci_dev * bridge = dev->bus->self;
+                                       struct pci_dev *bridge = dev->bus->self;
 
                                        pin = (pin + PCI_SLOT(dev->devfn)) % 4;
-                                       irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, 
+                                       irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
                                                        PCI_SLOT(bridge->devfn), pin);
                                        if (irq >= 0)
                                                printk(KERN_WARNING "PCI: using PPB %s[%c] to get irq %d\n",
@@ -1118,7 +1107,7 @@ static struct dmi_system_id __initdata pciirq_dmi_table[] = {
        { }
 };
 
-static int __init pcibios_irq_init(void)
+int __init pcibios_irq_init(void)
 {
        DBG(KERN_DEBUG "PCI: IRQ init\n");
 
@@ -1138,7 +1127,7 @@ static int __init pcibios_irq_init(void)
                pirq_find_router(&pirq_router);
                if (pirq_table->exclusive_irqs) {
                        int i;
-                       for (i=0; i<16; i++)
+                       for (i = 0; i < 16; i++)
                                if (!(pirq_table->exclusive_irqs & (1 << i)))
                                        pirq_penalty[i] += 100;
                }
@@ -1153,9 +1142,6 @@ static int __init pcibios_irq_init(void)
        return 0;
 }
 
-subsys_initcall(pcibios_irq_init);
-
-
 static void pirq_penalize_isa_irq(int irq, int active)
 {
        /*
@@ -1203,10 +1189,10 @@ static int pirq_enable_irq(struct pci_dev *dev)
                         */
                        temp_dev = dev;
                        while (irq < 0 && dev->bus->parent) { /* go back to the bridge */
-                               struct pci_dev * bridge = dev->bus->self;
+                               struct pci_dev *bridge = dev->bus->self;
 
                                pin = (pin + PCI_SLOT(dev->devfn)) % 4;
-                               irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, 
+                               irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number,
                                                PCI_SLOT(bridge->devfn), pin);
                                if (irq >= 0)
                                        printk(KERN_WARNING "PCI: using PPB %s[%c] to get irq %d\n",
diff --git a/arch/x86/pci/k8-bus_64.c b/arch/x86/pci/k8-bus_64.c
deleted file mode 100644 (file)
index 5c2799c..0000000
+++ /dev/null
@@ -1,528 +0,0 @@
-#include <linux/init.h>
-#include <linux/pci.h>
-#include <asm/pci-direct.h>
-#include <asm/mpspec.h>
-#include <linux/cpumask.h>
-#include <linux/topology.h>
-
-/*
- * This discovers the pcibus <-> node mapping on AMD K8.
- * also get peer root bus resource for io,mmio
- */
-
-
-/*
- * sub bus (transparent) will use entres from 3 to store extra from root,
- * so need to make sure have enought slot there, increase PCI_BUS_NUM_RESOURCES?
- */
-#define RES_NUM 16
-struct pci_root_info {
-       char name[12];
-       unsigned int res_num;
-       struct resource res[RES_NUM];
-       int bus_min;
-       int bus_max;
-       int node;
-       int link;
-};
-
-/* 4 at this time, it may become to 32 */
-#define PCI_ROOT_NR 4
-static int pci_root_num;
-static struct pci_root_info pci_root_info[PCI_ROOT_NR];
-
-#ifdef CONFIG_NUMA
-
-#define BUS_NR 256
-
-static int mp_bus_to_node[BUS_NR];
-
-void set_mp_bus_to_node(int busnum, int node)
-{
-       if (busnum >= 0 &&  busnum < BUS_NR)
-               mp_bus_to_node[busnum] = node;
-}
-
-int get_mp_bus_to_node(int busnum)
-{
-       int node = -1;
-
-       if (busnum < 0 || busnum > (BUS_NR - 1))
-               return node;
-
-       node = mp_bus_to_node[busnum];
-
-       /*
-        * let numa_node_id to decide it later in dma_alloc_pages
-        * if there is no ram on that node
-        */
-       if (node != -1 && !node_online(node))
-               node = -1;
-
-       return node;
-}
-#endif
-
-void set_pci_bus_resources_arch_default(struct pci_bus *b)
-{
-       int i;
-       int j;
-       struct pci_root_info *info;
-
-       /* if only one root bus, don't need to anything */
-       if (pci_root_num < 2)
-               return;
-
-       for (i = 0; i < pci_root_num; i++) {
-               if (pci_root_info[i].bus_min == b->number)
-                       break;
-       }
-
-       if (i == pci_root_num)
-               return;
-
-       info = &pci_root_info[i];
-       for (j = 0; j < info->res_num; j++) {
-               struct resource *res;
-               struct resource *root;
-
-               res = &info->res[j];
-               b->resource[j] = res;
-               if (res->flags & IORESOURCE_IO)
-                       root = &ioport_resource;
-               else
-                       root = &iomem_resource;
-               insert_resource(root, res);
-       }
-}
-
-#define RANGE_NUM 16
-
-struct res_range {
-       size_t start;
-       size_t end;
-};
-
-static void __init update_range(struct res_range *range, size_t start,
-                               size_t end)
-{
-       int i;
-       int j;
-
-       for (j = 0; j < RANGE_NUM; j++) {
-               if (!range[j].end)
-                       continue;
-
-               if (start <= range[j].start && end >= range[j].end) {
-                       range[j].start = 0;
-                       range[j].end = 0;
-                       continue;
-               }
-
-               if (start <= range[j].start && end < range[j].end && range[j].start < end + 1) {
-                       range[j].start = end + 1;
-                       continue;
-               }
-
-
-               if (start > range[j].start && end >= range[j].end && range[j].end > start - 1) {
-                       range[j].end = start - 1;
-                       continue;
-               }
-
-               if (start > range[j].start && end < range[j].end) {
-                       /* find the new spare */
-                       for (i = 0; i < RANGE_NUM; i++) {
-                               if (range[i].end == 0)
-                                       break;
-                       }
-                       if (i < RANGE_NUM) {
-                               range[i].end = range[j].end;
-                               range[i].start = end + 1;
-                       } else {
-                               printk(KERN_ERR "run of slot in ranges\n");
-                       }
-                       range[j].end = start - 1;
-                       continue;
-               }
-       }
-}
-
-static void __init update_res(struct pci_root_info *info, size_t start,
-                             size_t end, unsigned long flags, int merge)
-{
-       int i;
-       struct resource *res;
-
-       if (!merge)
-               goto addit;
-
-       /* try to merge it with old one */
-       for (i = 0; i < info->res_num; i++) {
-               size_t final_start, final_end;
-               size_t common_start, common_end;
-
-               res = &info->res[i];
-               if (res->flags != flags)
-                       continue;
-
-               common_start = max((size_t)res->start, start);
-               common_end = min((size_t)res->end, end);
-               if (common_start > common_end + 1)
-                       continue;
-
-               final_start = min((size_t)res->start, start);
-               final_end = max((size_t)res->end, end);
-
-               res->start = final_start;
-               res->end = final_end;
-               return;
-       }
-
-addit:
-
-       /* need to add that */
-       if (info->res_num >= RES_NUM)
-               return;
-
-       res = &info->res[info->res_num];
-       res->name = info->name;
-       res->flags = flags;
-       res->start = start;
-       res->end = end;
-       res->child = NULL;
-       info->res_num++;
-}
-
-struct pci_hostbridge_probe {
-       u32 bus;
-       u32 slot;
-       u32 vendor;
-       u32 device;
-};
-
-static struct pci_hostbridge_probe pci_probes[] __initdata = {
-       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1100 },
-       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 },
-       { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 },
-       { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1300 },
-};
-
-static u64 __initdata fam10h_mmconf_start;
-static u64 __initdata fam10h_mmconf_end;
-static void __init get_pci_mmcfg_amd_fam10h_range(void)
-{
-       u32 address;
-       u64 base, msr;
-       unsigned segn_busn_bits;
-
-       /* assume all cpus from fam10h have mmconf */
-        if (boot_cpu_data.x86 < 0x10)
-               return;
-
-       address = MSR_FAM10H_MMIO_CONF_BASE;
-       rdmsrl(address, msr);
-
-       /* mmconfig is not enable */
-       if (!(msr & FAM10H_MMIO_CONF_ENABLE))
-               return;
-
-       base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT);
-
-       segn_busn_bits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
-                        FAM10H_MMIO_CONF_BUSRANGE_MASK;
-
-       fam10h_mmconf_start = base;
-       fam10h_mmconf_end = base + (1ULL<<(segn_busn_bits + 20)) - 1;
-}
-
-/**
- * early_fill_mp_bus_to_node()
- * called before pcibios_scan_root and pci_scan_bus
- * fills the mp_bus_to_cpumask array based according to the LDT Bus Number
- * Registers found in the K8 northbridge
- */
-static int __init early_fill_mp_bus_info(void)
-{
-       int i;
-       int j;
-       unsigned bus;
-       unsigned slot;
-       int found;
-       int node;
-       int link;
-       int def_node;
-       int def_link;
-       struct pci_root_info *info;
-       u32 reg;
-       struct resource *res;
-       size_t start;
-       size_t end;
-       struct res_range range[RANGE_NUM];
-       u64 val;
-       u32 address;
-
-#ifdef CONFIG_NUMA
-       for (i = 0; i < BUS_NR; i++)
-               mp_bus_to_node[i] = -1;
-#endif
-
-       if (!early_pci_allowed())
-               return -1;
-
-       found = 0;
-       for (i = 0; i < ARRAY_SIZE(pci_probes); i++) {
-               u32 id;
-               u16 device;
-               u16 vendor;
-
-               bus = pci_probes[i].bus;
-               slot = pci_probes[i].slot;
-               id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
-
-               vendor = id & 0xffff;
-               device = (id>>16) & 0xffff;
-               if (pci_probes[i].vendor == vendor &&
-                   pci_probes[i].device == device) {
-                       found = 1;
-                       break;
-               }
-       }
-
-       if (!found)
-               return 0;
-
-       pci_root_num = 0;
-       for (i = 0; i < 4; i++) {
-               int min_bus;
-               int max_bus;
-               reg = read_pci_config(bus, slot, 1, 0xe0 + (i << 2));
-
-               /* Check if that register is enabled for bus range */
-               if ((reg & 7) != 3)
-                       continue;
-
-               min_bus = (reg >> 16) & 0xff;
-               max_bus = (reg >> 24) & 0xff;
-               node = (reg >> 4) & 0x07;
-#ifdef CONFIG_NUMA
-               for (j = min_bus; j <= max_bus; j++)
-                       mp_bus_to_node[j] = (unsigned char) node;
-#endif
-               link = (reg >> 8) & 0x03;
-
-               info = &pci_root_info[pci_root_num];
-               info->bus_min = min_bus;
-               info->bus_max = max_bus;
-               info->node = node;
-               info->link = link;
-               sprintf(info->name, "PCI Bus #%02x", min_bus);
-               pci_root_num++;
-       }
-
-       /* get the default node and link for left over res */
-       reg = read_pci_config(bus, slot, 0, 0x60);
-       def_node = (reg >> 8) & 0x07;
-       reg = read_pci_config(bus, slot, 0, 0x64);
-       def_link = (reg >> 8) & 0x03;
-
-       memset(range, 0, sizeof(range));
-       range[0].end = 0xffff;
-       /* io port resource */
-       for (i = 0; i < 4; i++) {
-               reg = read_pci_config(bus, slot, 1, 0xc0 + (i << 3));
-               if (!(reg & 3))
-                       continue;
-
-               start = reg & 0xfff000;
-               reg = read_pci_config(bus, slot, 1, 0xc4 + (i << 3));
-               node = reg & 0x07;
-               link = (reg >> 4) & 0x03;
-               end = (reg & 0xfff000) | 0xfff;
-
-               /* find the position */
-               for (j = 0; j < pci_root_num; j++) {
-                       info = &pci_root_info[j];
-                       if (info->node == node && info->link == link)
-                               break;
-               }
-               if (j == pci_root_num)
-                       continue; /* not found */
-
-               info = &pci_root_info[j];
-               printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n",
-                      node, link, (u64)start, (u64)end);
-
-               /* kernel only handle 16 bit only */
-               if (end > 0xffff)
-                       end = 0xffff;
-               update_res(info, start, end, IORESOURCE_IO, 1);
-               update_range(range, start, end);
-       }
-       /* add left over io port range to def node/link, [0, 0xffff] */
-       /* find the position */
-       for (j = 0; j < pci_root_num; j++) {
-               info = &pci_root_info[j];
-               if (info->node == def_node && info->link == def_link)
-                       break;
-       }
-       if (j < pci_root_num) {
-               info = &pci_root_info[j];
-               for (i = 0; i < RANGE_NUM; i++) {
-                       if (!range[i].end)
-                               continue;
-
-                       update_res(info, range[i].start, range[i].end,
-                                  IORESOURCE_IO, 1);
-               }
-       }
-
-       memset(range, 0, sizeof(range));
-       /* 0xfd00000000-0xffffffffff for HT */
-       range[0].end = (0xfdULL<<32) - 1;
-
-       /* need to take out [0, TOM) for RAM*/
-       address = MSR_K8_TOP_MEM1;
-       rdmsrl(address, val);
-       end = (val & 0xffffff8000000ULL);
-       printk(KERN_INFO "TOM: %016lx aka %ldM\n", end, end>>20);
-       if (end < (1ULL<<32))
-               update_range(range, 0, end - 1);
-
-       /* get mmconfig */
-       get_pci_mmcfg_amd_fam10h_range();
-       /* need to take out mmconf range */
-       if (fam10h_mmconf_end) {
-               printk(KERN_DEBUG "Fam 10h mmconf [%llx, %llx]\n", fam10h_mmconf_start, fam10h_mmconf_end);
-               update_range(range, fam10h_mmconf_start, fam10h_mmconf_end);
-       }
-
-       /* mmio resource */
-       for (i = 0; i < 8; i++) {
-               reg = read_pci_config(bus, slot, 1, 0x80 + (i << 3));
-               if (!(reg & 3))
-                       continue;
-
-               start = reg & 0xffffff00; /* 39:16 on 31:8*/
-               start <<= 8;
-               reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3));
-               node = reg & 0x07;
-               link = (reg >> 4) & 0x03;
-               end = (reg & 0xffffff00);
-               end <<= 8;
-               end |= 0xffff;
-
-               /* find the position */
-               for (j = 0; j < pci_root_num; j++) {
-                       info = &pci_root_info[j];
-                       if (info->node == node && info->link == link)
-                               break;
-               }
-               if (j == pci_root_num)
-                       continue; /* not found */
-
-               info = &pci_root_info[j];
-
-               printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]",
-                      node, link, (u64)start, (u64)end);
-               /*
-                * some sick allocation would have range overlap with fam10h
-                * mmconf range, so need to update start and end.
-                */
-               if (fam10h_mmconf_end) {
-                       int changed = 0;
-                       u64 endx = 0;
-                       if (start >= fam10h_mmconf_start &&
-                           start <= fam10h_mmconf_end) {
-                               start = fam10h_mmconf_end + 1;
-                               changed = 1;
-                       }
-
-                       if (end >= fam10h_mmconf_start &&
-                           end <= fam10h_mmconf_end) {
-                               end = fam10h_mmconf_start - 1;
-                               changed = 1;
-                       }
-
-                       if (start < fam10h_mmconf_start &&
-                           end > fam10h_mmconf_end) {
-                               /* we got a hole */
-                               endx = fam10h_mmconf_start - 1;
-                               update_res(info, start, endx, IORESOURCE_MEM, 0);
-                               update_range(range, start, endx);
-                               printk(KERN_CONT " ==> [%llx, %llx]", (u64)start, endx);
-                               start = fam10h_mmconf_end + 1;
-                               changed = 1;
-                       }
-                       if (changed) {
-                               if (start <= end) {
-                                       printk(KERN_CONT " %s [%llx, %llx]", endx?"and":"==>", (u64)start, (u64)end);
-                               } else {
-                                       printk(KERN_CONT "%s\n", endx?"":" ==> none");
-                                       continue;
-                               }
-                       }
-               }
-
-               update_res(info, start, end, IORESOURCE_MEM, 1);
-               update_range(range, start, end);
-               printk(KERN_CONT "\n");
-       }
-
-       /* need to take out [4G, TOM2) for RAM*/
-       /* SYS_CFG */
-       address = MSR_K8_SYSCFG;
-       rdmsrl(address, val);
-       /* TOP_MEM2 is enabled? */
-       if (val & (1<<21)) {
-               /* TOP_MEM2 */
-               address = MSR_K8_TOP_MEM2;
-               rdmsrl(address, val);
-               end = (val & 0xffffff8000000ULL);
-               printk(KERN_INFO "TOM2: %016lx aka %ldM\n", end, end>>20);
-               update_range(range, 1ULL<<32, end - 1);
-       }
-
-       /*
-        * add left over mmio range to def node/link ?
-        * that is tricky, just record range in from start_min to 4G
-        */
-       for (j = 0; j < pci_root_num; j++) {
-               info = &pci_root_info[j];
-               if (info->node == def_node && info->link == def_link)
-                       break;
-       }
-       if (j < pci_root_num) {
-               info = &pci_root_info[j];
-
-               for (i = 0; i < RANGE_NUM; i++) {
-                       if (!range[i].end)
-                               continue;
-
-                       update_res(info, range[i].start, range[i].end,
-                                  IORESOURCE_MEM, 1);
-               }
-       }
-
-       for (i = 0; i < pci_root_num; i++) {
-               int res_num;
-               int busnum;
-
-               info = &pci_root_info[i];
-               res_num = info->res_num;
-               busnum = info->bus_min;
-               printk(KERN_DEBUG "bus: [%02x,%02x] on node %x link %x\n",
-                      info->bus_min, info->bus_max, info->node, info->link);
-               for (j = 0; j < res_num; j++) {
-                       res = &info->res[j];
-                       printk(KERN_DEBUG "bus: %02x index %x %s: [%llx, %llx]\n",
-                              busnum, j,
-                              (res->flags & IORESOURCE_IO)?"io port":"mmio",
-                              res->start, res->end);
-               }
-       }
-
-       return 0;
-}
-
-postcore_initcall(early_fill_mp_bus_info);
index a67921c..132876c 100644 (file)
@@ -55,4 +55,18 @@ static int __init pci_legacy_init(void)
        return 0;
 }
 
-subsys_initcall(pci_legacy_init);
+int __init pci_subsys_init(void)
+{
+#ifdef CONFIG_ACPI
+       pci_acpi_init();
+#endif
+       pci_legacy_init();
+       pcibios_irq_init();
+#ifdef CONFIG_X86_NUMAQ
+       pci_numa_init();
+#endif
+       pcibios_init();
+
+       return 0;
+}
+subsys_initcall(pci_subsys_init);
index 0cfebec..23faaa8 100644 (file)
@@ -374,7 +374,7 @@ reject:
 
 static int __initdata known_bridge;
 
-void __init __pci_mmcfg_init(int early)
+static void __init __pci_mmcfg_init(int early)
 {
        /* MMCONFIG disabled */
        if ((pci_probe & PCI_PROBE_MMCONF) == 0)
diff --git a/arch/x86/pci/mp_bus_to_node.c b/arch/x86/pci/mp_bus_to_node.c
deleted file mode 100644 (file)
index 0229439..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <linux/pci.h>
-#include <linux/init.h>
-#include <linux/topology.h>
-
-#define BUS_NR 256
-
-static unsigned char mp_bus_to_node[BUS_NR];
-
-void set_mp_bus_to_node(int busnum, int node)
-{
-       if (busnum >= 0 &&  busnum < BUS_NR)
-       mp_bus_to_node[busnum] = (unsigned char) node;
-}
-
-int get_mp_bus_to_node(int busnum)
-{
-       int node;
-
-       if (busnum < 0 || busnum > (BUS_NR - 1))
-               return 0;
-       node = mp_bus_to_node[busnum];
-       return node;
-}
index d9afbae..8b5ca19 100644 (file)
@@ -6,45 +6,21 @@
 #include <linux/init.h>
 #include <linux/nodemask.h>
 #include <mach_apic.h>
+#include <asm/mpspec.h>
 #include "pci.h"
 
 #define XQUAD_PORTIO_BASE 0xfe400000
 #define XQUAD_PORTIO_QUAD 0x40000  /* 256k per quad. */
 
-int mp_bus_id_to_node[MAX_MP_BUSSES];
 #define BUS2QUAD(global) (mp_bus_id_to_node[global])
 
-int mp_bus_id_to_local[MAX_MP_BUSSES];
 #define BUS2LOCAL(global) (mp_bus_id_to_local[global])
 
-void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
-       struct mpc_config_translation *translation)
-{
-       int quad = translation->trans_quad;
-       int local = translation->trans_local;
-
-       mp_bus_id_to_node[m->mpc_busid] = quad;
-       mp_bus_id_to_local[m->mpc_busid] = local;
-       printk(KERN_INFO "Bus #%d is %s (node %d)\n",
-              m->mpc_busid, name, quad);
-}
-
-int quad_local_to_mp_bus_id [NR_CPUS/4][4];
 #define QUADLOCAL2BUS(quad,local) (quad_local_to_mp_bus_id[quad][local])
-void mpc_oem_pci_bus(struct mpc_config_bus *m,
-       struct mpc_config_translation *translation)
-{
-       int quad = translation->trans_quad;
-       int local = translation->trans_local;
-
-       quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
-}
 
 /* Where the IO area was mapped on multiquad, always 0 otherwise */
 void *xquad_portio;
-#ifdef CONFIG_X86_NUMAQ
 EXPORT_SYMBOL(xquad_portio);
-#endif
 
 #define XQUAD_PORT_ADDR(port, quad) (xquad_portio + (XQUAD_PORTIO_QUAD*quad) + port)
 
@@ -175,10 +151,13 @@ static void __devinit pci_fixup_i450nx(struct pci_dev *d)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, pci_fixup_i450nx);
 
-static int __init pci_numa_init(void)
+int __init pci_numa_init(void)
 {
        int quad;
 
+       if (!found_numaq)
+               return 0;
+
        raw_pci_ops = &pci_direct_conf1_mq;
 
        if (pcibios_scanned++)
@@ -197,5 +176,3 @@ static int __init pci_numa_init(void)
                }
        return 0;
 }
-
-subsys_initcall(pci_numa_init);
index 720c4c5..b2270a5 100644 (file)
@@ -27,6 +27,7 @@
 #define PCI_CAN_SKIP_ISA_ALIGN 0x8000
 #define PCI_USE__CRS           0x10000
 #define PCI_CHECK_ENABLE_AMD_MMCONF    0x20000
+#define PCI_HAS_IO_ECS         0x40000
 
 extern unsigned int pci_probe;
 extern unsigned long pirq_table_addr;
@@ -38,9 +39,6 @@ enum pci_bf_sort_state {
        pci_dmi_bf,
 };
 
-extern void __init dmi_check_pciprobe(void);
-extern void __init dmi_check_skip_isa_align(void);
-
 /* pci-i386.c */
 
 extern unsigned int pcibios_max_latency;
@@ -98,10 +96,19 @@ extern struct pci_raw_ops *raw_pci_ext_ops;
 
 extern struct pci_raw_ops pci_direct_conf1;
 
+/* arch_initcall level */
 extern int pci_direct_probe(void);
 extern void pci_direct_init(int type);
 extern void pci_pcbios_init(void);
 extern int pci_olpc_init(void);
+extern void __init dmi_check_pciprobe(void);
+extern void __init dmi_check_skip_isa_align(void);
+
+/* some common used subsys_initcalls */
+extern int __init pci_acpi_init(void);
+extern int __init pcibios_irq_init(void);
+extern int __init pci_numa_init(void);
+extern int __init pcibios_init(void);
 
 /* pci-mmconfig.c */
 
index c2df4e9..1a7bed4 100644 (file)
@@ -8,18 +8,19 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 
-#include "cobalt.h"
-#include "lithium.h"
+#include <asm/setup.h>
+#include <asm/visws/cobalt.h>
+#include <asm/visws/lithium.h>
 
 #include "pci.h"
 
 static int pci_visws_enable_irq(struct pci_dev *dev) { return 0; }
 static void pci_visws_disable_irq(struct pci_dev *dev) { }
 
-int (*pcibios_enable_irq)(struct pci_dev *dev) = &pci_visws_enable_irq;
-void (*pcibios_disable_irq)(struct pci_dev *dev) = &pci_visws_disable_irq;
+/* int (*pcibios_enable_irq)(struct pci_dev *dev) = &pci_visws_enable_irq; */
+/* void (*pcibios_disable_irq)(struct pci_dev *dev) = &pci_visws_disable_irq; */
 
-void __init pcibios_penalize_isa_irq(int irq, int active) {}
+/* void __init pcibios_penalize_isa_irq(int irq, int active) {} */
 
 
 unsigned int pci_bus0, pci_bus1;
@@ -85,7 +86,7 @@ void __init pcibios_update_irq(struct pci_dev *dev, int irq)
        pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
 }
 
-static int __init pcibios_init(void)
+static int __init pci_visws_init(void)
 {
        /* The VISWS supports configuration access type 1 only */
        pci_probe = (pci_probe | PCI_PROBE_CONF1) &
@@ -105,4 +106,17 @@ static int __init pcibios_init(void)
        return 0;
 }
 
-subsys_initcall(pcibios_init);
+static __init int pci_subsys_init(void)
+{
+       if (!is_visws_box())
+               return -1;
+
+       pcibios_enable_irq = &pci_visws_enable_irq;
+       pcibios_disable_irq = &pci_visws_disable_irq;
+
+       pci_visws_init();
+       pcibios_init();
+
+       return 0;
+}
+subsys_initcall(pci_subsys_init);
index b542355..6dd000d 100644 (file)
@@ -83,7 +83,7 @@ static int set_up_temporary_mappings(void)
 
        /* Set up the direct mapping from scratch */
        start = (unsigned long)pfn_to_kaddr(0);
-       end = (unsigned long)pfn_to_kaddr(end_pfn);
+       end = (unsigned long)pfn_to_kaddr(max_pfn);
 
        for (; start < end; start = next) {
                pud_t *pud = (pud_t *)get_safe_page(GFP_ATOMIC);
index efa2ba7..1ef0f90 100644 (file)
@@ -23,7 +23,7 @@
 
 #define gtod vdso_vsyscall_gtod_data
 
-static long vdso_fallback_gettime(long clock, struct timespec *ts)
+notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
 {
        long ret;
        asm("syscall" : "=a" (ret) :
@@ -31,7 +31,7 @@ static long vdso_fallback_gettime(long clock, struct timespec *ts)
        return ret;
 }
 
-static inline long vgetns(void)
+notrace static inline long vgetns(void)
 {
        long v;
        cycles_t (*vread)(void);
@@ -40,7 +40,7 @@ static inline long vgetns(void)
        return (v * gtod->clock.mult) >> gtod->clock.shift;
 }
 
-static noinline int do_realtime(struct timespec *ts)
+notrace static noinline int do_realtime(struct timespec *ts)
 {
        unsigned long seq, ns;
        do {
@@ -54,7 +54,8 @@ static noinline int do_realtime(struct timespec *ts)
 }
 
 /* Copy of the version in kernel/time.c which we cannot directly access */
-static void vset_normalized_timespec(struct timespec *ts, long sec, long nsec)
+notrace static void
+vset_normalized_timespec(struct timespec *ts, long sec, long nsec)
 {
        while (nsec >= NSEC_PER_SEC) {
                nsec -= NSEC_PER_SEC;
@@ -68,7 +69,7 @@ static void vset_normalized_timespec(struct timespec *ts, long sec, long nsec)
        ts->tv_nsec = nsec;
 }
 
-static noinline int do_monotonic(struct timespec *ts)
+notrace static noinline int do_monotonic(struct timespec *ts)
 {
        unsigned long seq, ns, secs;
        do {
@@ -82,7 +83,7 @@ static noinline int do_monotonic(struct timespec *ts)
        return 0;
 }
 
-int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
+notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
 {
        if (likely(gtod->sysctl_enabled && gtod->clock.vread))
                switch (clock) {
@@ -96,7 +97,7 @@ int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
 int clock_gettime(clockid_t, struct timespec *)
        __attribute__((weak, alias("__vdso_clock_gettime")));
 
-int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
 {
        long ret;
        if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
index cf058fe..0bce542 100644 (file)
@@ -203,20 +203,11 @@ static struct page *vdso32_pages[1];
 
 #ifdef CONFIG_X86_64
 
-static int use_sysenter __read_mostly = -1;
-
-#define        vdso32_sysenter()       (use_sysenter > 0)
+#define        vdso32_sysenter()       (boot_cpu_has(X86_FEATURE_SYSENTER32))
 
 /* May not be __init: called during resume */
 void syscall32_cpu_init(void)
 {
-       if (use_sysenter < 0) {
-               if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
-                       use_sysenter = 1;
-               if (boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR)
-                       use_sysenter = 1;
-       }
-
        /* Load these always in case some future AMD CPU supports
           SYSENTER from compat mode too. */
        checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
index c8097f1..9fbc6b2 100644 (file)
@@ -13,7 +13,8 @@
 #include <asm/vgtod.h>
 #include "vextern.h"
 
-long __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
+notrace long
+__vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
 {
        unsigned int p;
 
index 3fdd514..19a6cfa 100644 (file)
@@ -16,7 +16,7 @@
 #include "vextern.h"           /* Just for VMAGIC.  */
 #undef VEXTERN
 
-int vdso_enabled = 1;
+unsigned int __read_mostly vdso_enabled = 1;
 
 extern char vdso_start[], vdso_end[];
 extern unsigned short vdso_sync_cpuid;
index 6c388e5..c2cc995 100644 (file)
@@ -12,3 +12,13 @@ config XEN
          This is the Linux Xen port.  Enabling this will allow the
          kernel to boot in a paravirtualized environment under the
          Xen hypervisor.
+
+config XEN_MAX_DOMAIN_MEMORY
+       int "Maximum allowed size of a domain in gigabytes"
+       default 8
+       depends on XEN
+       help
+         The pseudo-physical to machine address array is sized
+         according to the maximum possible memory size of a Xen
+         domain.  This array uses 1 page per gigabyte, so there's no
+         need to be too stingy here.
\ No newline at end of file
index 3d8df98..2ba2d16 100644 (file)
@@ -1,4 +1,4 @@
 obj-y          := enlighten.o setup.o multicalls.o mmu.o \
-                       time.o manage.o xen-asm.o grant-table.o
+                       time.o xen-asm.o grant-table.o suspend.o
 
 obj-$(CONFIG_SMP)      += smp.o
index f09c1c6..dcd4e51 100644 (file)
@@ -45,6 +45,7 @@
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
 #include <asm/reboot.h>
+#include <asm/pgalloc.h>
 
 #include "xen-ops.h"
 #include "mmu.h"
@@ -75,13 +76,13 @@ DEFINE_PER_CPU(unsigned long, xen_current_cr3);      /* actual vcpu cr3 */
 struct start_info *xen_start_info;
 EXPORT_SYMBOL_GPL(xen_start_info);
 
-static /* __initdata */ struct shared_info dummy_shared_info;
+struct shared_info xen_dummy_shared_info;
 
 /*
  * Point at some empty memory to start with. We map the real shared_info
  * page as soon as fixmap is up and running.
  */
-struct shared_info *HYPERVISOR_shared_info = (void *)&dummy_shared_info;
+struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
 
 /*
  * Flag to determine whether vcpu info placement is available on all
@@ -98,13 +99,13 @@ struct shared_info *HYPERVISOR_shared_info = (void *)&dummy_shared_info;
  */
 static int have_vcpu_info_placement = 1;
 
-static void __init xen_vcpu_setup(int cpu)
+static void xen_vcpu_setup(int cpu)
 {
        struct vcpu_register_vcpu_info info;
        int err;
        struct vcpu_info *vcpup;
 
-       BUG_ON(HYPERVISOR_shared_info == &dummy_shared_info);
+       BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
        per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
 
        if (!have_vcpu_info_placement)
@@ -136,11 +137,41 @@ static void __init xen_vcpu_setup(int cpu)
        }
 }
 
+/*
+ * On restore, set the vcpu placement up again.
+ * If it fails, then we're in a bad state, since
+ * we can't back out from using it...
+ */
+void xen_vcpu_restore(void)
+{
+       if (have_vcpu_info_placement) {
+               int cpu;
+
+               for_each_online_cpu(cpu) {
+                       bool other_cpu = (cpu != smp_processor_id());
+
+                       if (other_cpu &&
+                           HYPERVISOR_vcpu_op(VCPUOP_down, cpu, NULL))
+                               BUG();
+
+                       xen_vcpu_setup(cpu);
+
+                       if (other_cpu &&
+                           HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL))
+                               BUG();
+               }
+
+               BUG_ON(!have_vcpu_info_placement);
+       }
+}
+
 static void __init xen_banner(void)
 {
        printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
               pv_info.name);
-       printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
+       printk(KERN_INFO "Hypervisor signature: %s%s\n",
+              xen_start_info->magic,
+              xen_feature(XENFEAT_mmu_pt_update_preserve_ad) ? " (preserve-AD)" : "");
 }
 
 static void xen_cpuid(unsigned int *ax, unsigned int *bx,
@@ -235,13 +266,13 @@ static void xen_irq_enable(void)
 {
        struct vcpu_info *vcpu;
 
-       /* There's a one instruction preempt window here.  We need to
-          make sure we're don't switch CPUs between getting the vcpu
-          pointer and updating the mask. */
-       preempt_disable();
+       /* We don't need to worry about being preempted here, since
+          either a) interrupts are disabled, so no preemption, or b)
+          the caller is confused and is trying to re-enable interrupts
+          on an indeterminate processor. */
+
        vcpu = x86_read_percpu(xen_vcpu);
        vcpu->evtchn_upcall_mask = 0;
-       preempt_enable_no_resched();
 
        /* Doesn't matter if we get preempted here, because any
           pending event will get dealt with anyway. */
@@ -254,7 +285,7 @@ static void xen_irq_enable(void)
 static void xen_safe_halt(void)
 {
        /* Blocking includes an implicit local_irq_enable(). */
-       if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
+       if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
                BUG();
 }
 
@@ -607,6 +638,30 @@ static void xen_flush_tlb_others(const cpumask_t *cpus, struct mm_struct *mm,
        xen_mc_issue(PARAVIRT_LAZY_MMU);
 }
 
+static void xen_clts(void)
+{
+       struct multicall_space mcs;
+
+       mcs = xen_mc_entry(0);
+
+       MULTI_fpu_taskswitch(mcs.mc, 0);
+
+       xen_mc_issue(PARAVIRT_LAZY_CPU);
+}
+
+static void xen_write_cr0(unsigned long cr0)
+{
+       struct multicall_space mcs;
+
+       /* Only pay attention to cr0.TS; everything else is
+          ignored. */
+       mcs = xen_mc_entry(0);
+
+       MULTI_fpu_taskswitch(mcs.mc, (cr0 & X86_CR0_TS) != 0);
+
+       xen_mc_issue(PARAVIRT_LAZY_CPU);
+}
+
 static void xen_write_cr2(unsigned long cr2)
 {
        x86_read_percpu(xen_vcpu)->arch.cr2 = cr2;
@@ -624,8 +679,10 @@ static unsigned long xen_read_cr2_direct(void)
 
 static void xen_write_cr4(unsigned long cr4)
 {
-       /* Just ignore cr4 changes; Xen doesn't allow us to do
-          anything anyway. */
+       cr4 &= ~X86_CR4_PGE;
+       cr4 &= ~X86_CR4_PSE;
+
+       native_write_cr4(cr4);
 }
 
 static unsigned long xen_read_cr3(void)
@@ -831,7 +888,7 @@ static __init void xen_pagetable_setup_start(pgd_t *base)
                          PFN_DOWN(__pa(xen_start_info->pt_base)));
 }
 
-static __init void setup_shared_info(void)
+void xen_setup_shared_info(void)
 {
        if (!xen_feature(XENFEAT_auto_translated_physmap)) {
                unsigned long addr = fix_to_virt(FIX_PARAVIRT_BOOTMAP);
@@ -854,6 +911,8 @@ static __init void setup_shared_info(void)
        /* In UP this is as good a place as any to set up shared info */
        xen_setup_vcpu_info_placement();
 #endif
+
+       xen_setup_mfn_list_list();
 }
 
 static __init void xen_pagetable_setup_done(pgd_t *base)
@@ -866,15 +925,23 @@ static __init void xen_pagetable_setup_done(pgd_t *base)
        pv_mmu_ops.release_pmd = xen_release_pmd;
        pv_mmu_ops.set_pte = xen_set_pte;
 
-       setup_shared_info();
+       xen_setup_shared_info();
 
        /* Actually pin the pagetable down, but we can't set PG_pinned
           yet because the page structures don't exist yet. */
        pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(base)));
 }
 
+static __init void xen_post_allocator_init(void)
+{
+       pv_mmu_ops.set_pmd = xen_set_pmd;
+       pv_mmu_ops.set_pud = xen_set_pud;
+
+       xen_mark_init_mm_pinned();
+}
+
 /* This is called once we have the cpu_possible_map */
-void __init xen_setup_vcpu_info_placement(void)
+void xen_setup_vcpu_info_placement(void)
 {
        int cpu;
 
@@ -947,6 +1014,33 @@ static unsigned xen_patch(u8 type, u16 clobbers, void *insnbuf,
        return ret;
 }
 
+static void xen_set_fixmap(unsigned idx, unsigned long phys, pgprot_t prot)
+{
+       pte_t pte;
+
+       phys >>= PAGE_SHIFT;
+
+       switch (idx) {
+       case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
+#ifdef CONFIG_X86_F00F_BUG
+       case FIX_F00F_IDT:
+#endif
+       case FIX_WP_TEST:
+       case FIX_VDSO:
+#ifdef CONFIG_X86_LOCAL_APIC
+       case FIX_APIC_BASE:     /* maps dummy local APIC */
+#endif
+               pte = pfn_pte(phys, prot);
+               break;
+
+       default:
+               pte = mfn_pte(phys, prot);
+               break;
+       }
+
+       __native_set_fixmap(idx, pte);
+}
+
 static const struct pv_info xen_info __initdata = {
        .paravirt_enabled = 1,
        .shared_kernel_pmd = 0,
@@ -960,7 +1054,7 @@ static const struct pv_init_ops xen_init_ops __initdata = {
        .banner = xen_banner,
        .memory_setup = xen_memory_setup,
        .arch_setup = xen_arch_setup,
-       .post_allocator_init = xen_mark_init_mm_pinned,
+       .post_allocator_init = xen_post_allocator_init,
 };
 
 static const struct pv_time_ops xen_time_ops __initdata = {
@@ -968,7 +1062,7 @@ static const struct pv_time_ops xen_time_ops __initdata = {
 
        .set_wallclock = xen_set_wallclock,
        .get_wallclock = xen_get_wallclock,
-       .get_cpu_khz = xen_cpu_khz,
+       .get_tsc_khz = xen_tsc_khz,
        .sched_clock = xen_sched_clock,
 };
 
@@ -978,10 +1072,10 @@ static const struct pv_cpu_ops xen_cpu_ops __initdata = {
        .set_debugreg = xen_set_debugreg,
        .get_debugreg = xen_get_debugreg,
 
-       .clts = native_clts,
+       .clts = xen_clts,
 
        .read_cr0 = native_read_cr0,
-       .write_cr0 = native_write_cr0,
+       .write_cr0 = xen_write_cr0,
 
        .read_cr4 = native_read_cr4,
        .read_cr4_safe = native_read_cr4_safe,
@@ -995,7 +1089,7 @@ static const struct pv_cpu_ops xen_cpu_ops __initdata = {
        .read_pmc = native_read_pmc,
 
        .iret = xen_iret,
-       .irq_enable_syscall_ret = xen_sysexit,
+       .irq_enable_sysexit = xen_sysexit,
 
        .load_tr_desc = paravirt_nop,
        .set_ldt = xen_set_ldt,
@@ -1029,6 +1123,9 @@ static const struct pv_irq_ops xen_irq_ops __initdata = {
        .irq_enable = xen_irq_enable,
        .safe_halt = xen_safe_halt,
        .halt = xen_halt,
+#ifdef CONFIG_X86_64
+       .adjust_exception_frame = paravirt_nop,
+#endif
 };
 
 static const struct pv_apic_ops xen_apic_ops __initdata = {
@@ -1060,6 +1157,9 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
        .pte_update = paravirt_nop,
        .pte_update_defer = paravirt_nop,
 
+       .pgd_alloc = __paravirt_pgd_alloc,
+       .pgd_free = paravirt_nop,
+
        .alloc_pte = xen_alloc_pte_init,
        .release_pte = xen_release_pte_init,
        .alloc_pmd = xen_alloc_pte_init,
@@ -1072,9 +1172,13 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
 
        .set_pte = NULL,        /* see xen_pagetable_setup_* */
        .set_pte_at = xen_set_pte_at,
-       .set_pmd = xen_set_pmd,
+       .set_pmd = xen_set_pmd_hyper,
+
+       .ptep_modify_prot_start = __ptep_modify_prot_start,
+       .ptep_modify_prot_commit = __ptep_modify_prot_commit,
 
        .pte_val = xen_pte_val,
+       .pte_flags = native_pte_val,
        .pgd_val = xen_pgd_val,
 
        .make_pte = xen_make_pte,
@@ -1082,7 +1186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
 
        .set_pte_atomic = xen_set_pte_atomic,
        .set_pte_present = xen_set_pte_at,
-       .set_pud = xen_set_pud,
+       .set_pud = xen_set_pud_hyper,
        .pte_clear = xen_pte_clear,
        .pmd_clear = xen_pmd_clear,
 
@@ -1097,6 +1201,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
                .enter = paravirt_enter_lazy_mmu,
                .leave = xen_leave_lazy,
        },
+
+       .set_fixmap = xen_set_fixmap,
 };
 
 #ifdef CONFIG_SMP
@@ -1114,11 +1220,13 @@ static const struct smp_ops xen_smp_ops __initdata = {
 
 static void xen_reboot(int reason)
 {
+       struct sched_shutdown r = { .reason = reason };
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
 
-       if (HYPERVISOR_sched_op(SCHEDOP_shutdown, reason))
+       if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
                BUG();
 }
 
@@ -1173,6 +1281,8 @@ asmlinkage void __init xen_start_kernel(void)
 
        BUG_ON(memcmp(xen_start_info->magic, "xen-3", 5) != 0);
 
+       xen_setup_features();
+
        /* Install Xen paravirt ops */
        pv_info = xen_info;
        pv_init_ops = xen_init_ops;
@@ -1182,21 +1292,26 @@ asmlinkage void __init xen_start_kernel(void)
        pv_apic_ops = xen_apic_ops;
        pv_mmu_ops = xen_mmu_ops;
 
+       if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
+               pv_mmu_ops.ptep_modify_prot_start = xen_ptep_modify_prot_start;
+               pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
+       }
+
        machine_ops = xen_machine_ops;
 
 #ifdef CONFIG_SMP
        smp_ops = xen_smp_ops;
 #endif
 
-       xen_setup_features();
-
        /* Get mfn list */
        if (!xen_feature(XENFEAT_auto_translated_physmap))
-               phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
+               xen_build_dynamic_phys_to_machine();
 
        pgd = (pgd_t *)xen_start_info->pt_base;
 
+       init_pg_tables_start = __pa(pgd);
        init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
+       max_pfn_mapped = (init_pg_tables_end + 512*1024) >> PAGE_SHIFT;
 
        init_mm.pgd = pgd; /* use the Xen pagetables to start */
 
@@ -1232,9 +1347,12 @@ asmlinkage void __init xen_start_kernel(void)
                ? __pa(xen_start_info->mod_start) : 0;
        boot_params.hdr.ramdisk_size = xen_start_info->mod_len;
 
-       if (!is_initial_xendomain())
+       if (!is_initial_xendomain()) {
+               add_preferred_console("xenboot", 0, NULL);
+               add_preferred_console("tty", 0, NULL);
                add_preferred_console("hvc", 0, NULL);
+       }
 
        /* Start the world */
-       start_kernel();
+       i386_start_kernel();
 }
diff --git a/arch/x86/xen/manage.c b/arch/x86/xen/manage.c
deleted file mode 100644 (file)
index aa7af9e..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Handle extern requests for shutdown, reboot and sysrq
- */
-#include <linux/kernel.h>
-#include <linux/err.h>
-#include <linux/reboot.h>
-#include <linux/sysrq.h>
-
-#include <xen/xenbus.h>
-
-#define SHUTDOWN_INVALID  -1
-#define SHUTDOWN_POWEROFF  0
-#define SHUTDOWN_SUSPEND   2
-/* Code 3 is SHUTDOWN_CRASH, which we don't use because the domain can only
- * report a crash, not be instructed to crash!
- * HALT is the same as POWEROFF, as far as we're concerned.  The tools use
- * the distinction when we return the reason code to them.
- */
-#define SHUTDOWN_HALT      4
-
-/* Ignore multiple shutdown requests. */
-static int shutting_down = SHUTDOWN_INVALID;
-
-static void shutdown_handler(struct xenbus_watch *watch,
-                            const char **vec, unsigned int len)
-{
-       char *str;
-       struct xenbus_transaction xbt;
-       int err;
-
-       if (shutting_down != SHUTDOWN_INVALID)
-               return;
-
- again:
-       err = xenbus_transaction_start(&xbt);
-       if (err)
-               return;
-
-       str = (char *)xenbus_read(xbt, "control", "shutdown", NULL);
-       /* Ignore read errors and empty reads. */
-       if (XENBUS_IS_ERR_READ(str)) {
-               xenbus_transaction_end(xbt, 1);
-               return;
-       }
-
-       xenbus_write(xbt, "control", "shutdown", "");
-
-       err = xenbus_transaction_end(xbt, 0);
-       if (err == -EAGAIN) {
-               kfree(str);
-               goto again;
-       }
-
-       if (strcmp(str, "poweroff") == 0 ||
-           strcmp(str, "halt") == 0)
-               orderly_poweroff(false);
-       else if (strcmp(str, "reboot") == 0)
-               ctrl_alt_del();
-       else {
-               printk(KERN_INFO "Ignoring shutdown request: %s\n", str);
-               shutting_down = SHUTDOWN_INVALID;
-       }
-
-       kfree(str);
-}
-
-static void sysrq_handler(struct xenbus_watch *watch, const char **vec,
-                         unsigned int len)
-{
-       char sysrq_key = '\0';
-       struct xenbus_transaction xbt;
-       int err;
-
- again:
-       err = xenbus_transaction_start(&xbt);
-       if (err)
-               return;
-       if (!xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key)) {
-               printk(KERN_ERR "Unable to read sysrq code in "
-                      "control/sysrq\n");
-               xenbus_transaction_end(xbt, 1);
-               return;
-       }
-
-       if (sysrq_key != '\0')
-               xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
-
-       err = xenbus_transaction_end(xbt, 0);
-       if (err == -EAGAIN)
-               goto again;
-
-       if (sysrq_key != '\0')
-               handle_sysrq(sysrq_key, NULL);
-}
-
-static struct xenbus_watch shutdown_watch = {
-       .node = "control/shutdown",
-       .callback = shutdown_handler
-};
-
-static struct xenbus_watch sysrq_watch = {
-       .node = "control/sysrq",
-       .callback = sysrq_handler
-};
-
-static int setup_shutdown_watcher(void)
-{
-       int err;
-
-       err = register_xenbus_watch(&shutdown_watch);
-       if (err) {
-               printk(KERN_ERR "Failed to set shutdown watcher\n");
-               return err;
-       }
-
-       err = register_xenbus_watch(&sysrq_watch);
-       if (err) {
-               printk(KERN_ERR "Failed to set sysrq watcher\n");
-               return err;
-       }
-
-       return 0;
-}
-
-static int shutdown_event(struct notifier_block *notifier,
-                         unsigned long event,
-                         void *data)
-{
-       setup_shutdown_watcher();
-       return NOTIFY_DONE;
-}
-
-static int __init setup_shutdown_event(void)
-{
-       static struct notifier_block xenstore_notifier = {
-               .notifier_call = shutdown_event
-       };
-       register_xenstore_notifier(&xenstore_notifier);
-
-       return 0;
-}
-
-subsys_initcall(setup_shutdown_event);
index 4e527e7..42b3b9e 100644 (file)
 #include "multicalls.h"
 #include "mmu.h"
 
+#define P2M_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof(unsigned long))
+#define TOP_ENTRIES            (MAX_DOMAIN_PAGES / P2M_ENTRIES_PER_PAGE)
+
+/* Placeholder for holes in the address space */
+static unsigned long p2m_missing[P2M_ENTRIES_PER_PAGE]
+       __attribute__((section(".data.page_aligned"))) =
+               { [ 0 ... P2M_ENTRIES_PER_PAGE-1 ] = ~0UL };
+
+ /* Array of pointers to pages containing p2m entries */
+static unsigned long *p2m_top[TOP_ENTRIES]
+       __attribute__((section(".data.page_aligned"))) =
+               { [ 0 ... TOP_ENTRIES - 1] = &p2m_missing[0] };
+
+/* Arrays of p2m arrays expressed in mfns used for save/restore */
+static unsigned long p2m_top_mfn[TOP_ENTRIES]
+       __attribute__((section(".bss.page_aligned")));
+
+static unsigned long p2m_top_mfn_list[
+                       PAGE_ALIGN(TOP_ENTRIES / P2M_ENTRIES_PER_PAGE)]
+       __attribute__((section(".bss.page_aligned")));
+
+static inline unsigned p2m_top_index(unsigned long pfn)
+{
+       BUG_ON(pfn >= MAX_DOMAIN_PAGES);
+       return pfn / P2M_ENTRIES_PER_PAGE;
+}
+
+static inline unsigned p2m_index(unsigned long pfn)
+{
+       return pfn % P2M_ENTRIES_PER_PAGE;
+}
+
+/* Build the parallel p2m_top_mfn structures */
+void xen_setup_mfn_list_list(void)
+{
+       unsigned pfn, idx;
+
+       for(pfn = 0; pfn < MAX_DOMAIN_PAGES; pfn += P2M_ENTRIES_PER_PAGE) {
+               unsigned topidx = p2m_top_index(pfn);
+
+               p2m_top_mfn[topidx] = virt_to_mfn(p2m_top[topidx]);
+       }
+
+       for(idx = 0; idx < ARRAY_SIZE(p2m_top_mfn_list); idx++) {
+               unsigned topidx = idx * P2M_ENTRIES_PER_PAGE;
+               p2m_top_mfn_list[idx] = virt_to_mfn(&p2m_top_mfn[topidx]);
+       }
+
+       BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
+
+       HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
+               virt_to_mfn(p2m_top_mfn_list);
+       HYPERVISOR_shared_info->arch.max_pfn = xen_start_info->nr_pages;
+}
+
+/* Set up p2m_top to point to the domain-builder provided p2m pages */
+void __init xen_build_dynamic_phys_to_machine(void)
+{
+       unsigned long *mfn_list = (unsigned long *)xen_start_info->mfn_list;
+       unsigned long max_pfn = min(MAX_DOMAIN_PAGES, xen_start_info->nr_pages);
+       unsigned pfn;
+
+       for(pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES_PER_PAGE) {
+               unsigned topidx = p2m_top_index(pfn);
+
+               p2m_top[topidx] = &mfn_list[pfn];
+       }
+}
+
+unsigned long get_phys_to_machine(unsigned long pfn)
+{
+       unsigned topidx, idx;
+
+       if (unlikely(pfn >= MAX_DOMAIN_PAGES))
+               return INVALID_P2M_ENTRY;
+
+       topidx = p2m_top_index(pfn);
+       idx = p2m_index(pfn);
+       return p2m_top[topidx][idx];
+}
+EXPORT_SYMBOL_GPL(get_phys_to_machine);
+
+static void alloc_p2m(unsigned long **pp, unsigned long *mfnp)
+{
+       unsigned long *p;
+       unsigned i;
+
+       p = (void *)__get_free_page(GFP_KERNEL | __GFP_NOFAIL);
+       BUG_ON(p == NULL);
+
+       for(i = 0; i < P2M_ENTRIES_PER_PAGE; i++)
+               p[i] = INVALID_P2M_ENTRY;
+
+       if (cmpxchg(pp, p2m_missing, p) != p2m_missing)
+               free_page((unsigned long)p);
+       else
+               *mfnp = virt_to_mfn(p);
+}
+
+void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
+{
+       unsigned topidx, idx;
+
+       if (unlikely(xen_feature(XENFEAT_auto_translated_physmap))) {
+               BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
+               return;
+       }
+
+       if (unlikely(pfn >= MAX_DOMAIN_PAGES)) {
+               BUG_ON(mfn != INVALID_P2M_ENTRY);
+               return;
+       }
+
+       topidx = p2m_top_index(pfn);
+       if (p2m_top[topidx] == p2m_missing) {
+               /* no need to allocate a page to store an invalid entry */
+               if (mfn == INVALID_P2M_ENTRY)
+                       return;
+               alloc_p2m(&p2m_top[topidx], &p2m_top_mfn[topidx]);
+       }
+
+       idx = p2m_index(pfn);
+       p2m_top[topidx][idx] = mfn;
+}
+
 xmaddr_t arbitrary_virt_to_machine(unsigned long address)
 {
        unsigned int level;
@@ -98,24 +223,60 @@ void make_lowmem_page_readwrite(void *vaddr)
 }
 
 
-void xen_set_pmd(pmd_t *ptr, pmd_t val)
+static bool page_pinned(void *ptr)
+{
+       struct page *page = virt_to_page(ptr);
+
+       return PagePinned(page);
+}
+
+static void extend_mmu_update(const struct mmu_update *update)
 {
        struct multicall_space mcs;
        struct mmu_update *u;
 
-       preempt_disable();
+       mcs = xen_mc_extend_args(__HYPERVISOR_mmu_update, sizeof(*u));
+
+       if (mcs.mc != NULL)
+               mcs.mc->args[1]++;
+       else {
+               mcs = __xen_mc_entry(sizeof(*u));
+               MULTI_mmu_update(mcs.mc, mcs.args, 1, NULL, DOMID_SELF);
+       }
 
-       mcs = xen_mc_entry(sizeof(*u));
        u = mcs.args;
-       u->ptr = virt_to_machine(ptr).maddr;
-       u->val = pmd_val_ma(val);
-       MULTI_mmu_update(mcs.mc, u, 1, NULL, DOMID_SELF);
+       *u = *update;
+}
+
+void xen_set_pmd_hyper(pmd_t *ptr, pmd_t val)
+{
+       struct mmu_update u;
+
+       preempt_disable();
+
+       xen_mc_batch();
+
+       u.ptr = virt_to_machine(ptr).maddr;
+       u.val = pmd_val_ma(val);
+       extend_mmu_update(&u);
 
        xen_mc_issue(PARAVIRT_LAZY_MMU);
 
        preempt_enable();
 }
 
+void xen_set_pmd(pmd_t *ptr, pmd_t val)
+{
+       /* If page is not pinned, we can just update the entry
+          directly */
+       if (!page_pinned(ptr)) {
+               *ptr = val;
+               return;
+       }
+
+       xen_set_pmd_hyper(ptr, val);
+}
+
 /*
  * Associate a virtual page frame with a given physical page frame
  * and protection flags for that frame.
@@ -179,6 +340,26 @@ out:
                preempt_enable();
 }
 
+pte_t xen_ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
+{
+       /* Just return the pte as-is.  We preserve the bits on commit */
+       return *ptep;
+}
+
+void xen_ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
+                                pte_t *ptep, pte_t pte)
+{
+       struct mmu_update u;
+
+       xen_mc_batch();
+
+       u.ptr = virt_to_machine(ptep).maddr | MMU_PT_UPDATE_PRESERVE_AD;
+       u.val = pte_val_ma(pte);
+       extend_mmu_update(&u);
+
+       xen_mc_issue(PARAVIRT_LAZY_MMU);
+}
+
 /* Assume pteval_t is equivalent to all the other *val_t types. */
 static pteval_t pte_mfn_to_pfn(pteval_t val)
 {
@@ -229,24 +410,35 @@ pmdval_t xen_pmd_val(pmd_t pmd)
        return pte_mfn_to_pfn(pmd.pmd);
 }
 
-void xen_set_pud(pud_t *ptr, pud_t val)
+void xen_set_pud_hyper(pud_t *ptr, pud_t val)
 {
-       struct multicall_space mcs;
-       struct mmu_update *u;
+       struct mmu_update u;
 
        preempt_disable();
 
-       mcs = xen_mc_entry(sizeof(*u));
-       u = mcs.args;
-       u->ptr = virt_to_machine(ptr).maddr;
-       u->val = pud_val_ma(val);
-       MULTI_mmu_update(mcs.mc, u, 1, NULL, DOMID_SELF);
+       xen_mc_batch();
+
+       u.ptr = virt_to_machine(ptr).maddr;
+       u.val = pud_val_ma(val);
+       extend_mmu_update(&u);
 
        xen_mc_issue(PARAVIRT_LAZY_MMU);
 
        preempt_enable();
 }
 
+void xen_set_pud(pud_t *ptr, pud_t val)
+{
+       /* If page is not pinned, we can just update the entry
+          directly */
+       if (!page_pinned(ptr)) {
+               *ptr = val;
+               return;
+       }
+
+       xen_set_pud_hyper(ptr, val);
+}
+
 void xen_set_pte(pte_t *ptep, pte_t pte)
 {
        ptep->pte_high = pte.pte_high;
@@ -268,7 +460,7 @@ void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 
 void xen_pmd_clear(pmd_t *pmdp)
 {
-       xen_set_pmd(pmdp, __pmd(0));
+       set_pmd(pmdp, __pmd(0));
 }
 
 pmd_t xen_make_pmd(pmdval_t pmd)
@@ -441,6 +633,29 @@ void xen_pgd_pin(pgd_t *pgd)
        xen_mc_issue(0);
 }
 
+/*
+ * On save, we need to pin all pagetables to make sure they get their
+ * mfns turned into pfns.  Search the list for any unpinned pgds and pin
+ * them (unpinned pgds are not currently in use, probably because the
+ * process is under construction or destruction).
+ */
+void xen_mm_pin_all(void)
+{
+       unsigned long flags;
+       struct page *page;
+
+       spin_lock_irqsave(&pgd_lock, flags);
+
+       list_for_each_entry(page, &pgd_list, lru) {
+               if (!PagePinned(page)) {
+                       xen_pgd_pin((pgd_t *)page_address(page));
+                       SetPageSavePinned(page);
+               }
+       }
+
+       spin_unlock_irqrestore(&pgd_lock, flags);
+}
+
 /* The init_mm pagetable is really pinned as soon as its created, but
    that's before we have page structures to store the bits.  So do all
    the book-keeping now. */
@@ -498,6 +713,29 @@ static void xen_pgd_unpin(pgd_t *pgd)
        xen_mc_issue(0);
 }
 
+/*
+ * On resume, undo any pinning done at save, so that the rest of the
+ * kernel doesn't see any unexpected pinned pagetables.
+ */
+void xen_mm_unpin_all(void)
+{
+       unsigned long flags;
+       struct page *page;
+
+       spin_lock_irqsave(&pgd_lock, flags);
+
+       list_for_each_entry(page, &pgd_list, lru) {
+               if (PageSavePinned(page)) {
+                       BUG_ON(!PagePinned(page));
+                       printk("unpinning pinned %p\n", page_address(page));
+                       xen_pgd_unpin((pgd_t *)page_address(page));
+                       ClearPageSavePinned(page);
+               }
+       }
+
+       spin_unlock_irqrestore(&pgd_lock, flags);
+}
+
 void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next)
 {
        spin_lock(&next->page_table_lock);
@@ -591,7 +829,7 @@ void xen_exit_mmap(struct mm_struct *mm)
        spin_lock(&mm->page_table_lock);
 
        /* pgd may not be pinned in the error exit path of execve */
-       if (PagePinned(virt_to_page(mm->pgd)))
+       if (page_pinned(mm->pgd))
                xen_pgd_unpin(mm->pgd);
 
        spin_unlock(&mm->page_table_lock);
index 5fe961c..297bf9f 100644 (file)
@@ -25,10 +25,6 @@ enum pt_level {
 
 void set_pte_mfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags);
 
-void xen_set_pte(pte_t *ptep, pte_t pteval);
-void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
-                   pte_t *ptep, pte_t pteval);
-void xen_set_pmd(pmd_t *pmdp, pmd_t pmdval);
 
 void xen_activate_mm(struct mm_struct *prev, struct mm_struct *next);
 void xen_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm);
@@ -45,11 +41,19 @@ pte_t xen_make_pte(pteval_t);
 pmd_t xen_make_pmd(pmdval_t);
 pgd_t xen_make_pgd(pgdval_t);
 
+void xen_set_pte(pte_t *ptep, pte_t pteval);
 void xen_set_pte_at(struct mm_struct *mm, unsigned long addr,
                    pte_t *ptep, pte_t pteval);
 void xen_set_pte_atomic(pte_t *ptep, pte_t pte);
+void xen_set_pmd(pmd_t *pmdp, pmd_t pmdval);
 void xen_set_pud(pud_t *ptr, pud_t val);
+void xen_set_pmd_hyper(pmd_t *pmdp, pmd_t pmdval);
+void xen_set_pud_hyper(pud_t *ptr, pud_t val);
 void xen_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
 void xen_pmd_clear(pmd_t *pmdp);
 
+pte_t xen_ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
+void  xen_ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
+                                 pte_t *ptep, pte_t pte);
+
 #endif /* _XEN_MMU_H */
index 5791eb2..3c63c4d 100644 (file)
 #define MC_DEBUG       1
 
 #define MC_BATCH       32
-#define MC_ARGS                (MC_BATCH * 16 / sizeof(u64))
+#define MC_ARGS                (MC_BATCH * 16)
 
 struct mc_buffer {
        struct multicall_entry entries[MC_BATCH];
 #if MC_DEBUG
        struct multicall_entry debug[MC_BATCH];
 #endif
-       u64 args[MC_ARGS];
+       unsigned char args[MC_ARGS];
        struct callback {
                void (*fn)(void *);
                void *data;
@@ -107,20 +107,48 @@ struct multicall_space __xen_mc_entry(size_t args)
 {
        struct mc_buffer *b = &__get_cpu_var(mc_buffer);
        struct multicall_space ret;
-       unsigned argspace = (args + sizeof(u64) - 1) / sizeof(u64);
+       unsigned argidx = roundup(b->argidx, sizeof(u64));
 
        BUG_ON(preemptible());
-       BUG_ON(argspace > MC_ARGS);
+       BUG_ON(b->argidx > MC_ARGS);
 
        if (b->mcidx == MC_BATCH ||
-           (b->argidx + argspace) > MC_ARGS)
+           (argidx + args) > MC_ARGS) {
                xen_mc_flush();
+               argidx = roundup(b->argidx, sizeof(u64));
+       }
 
        ret.mc = &b->entries[b->mcidx];
        b->mcidx++;
+       ret.args = &b->args[argidx];
+       b->argidx = argidx + args;
+
+       BUG_ON(b->argidx > MC_ARGS);
+       return ret;
+}
+
+struct multicall_space xen_mc_extend_args(unsigned long op, size_t size)
+{
+       struct mc_buffer *b = &__get_cpu_var(mc_buffer);
+       struct multicall_space ret = { NULL, NULL };
+
+       BUG_ON(preemptible());
+       BUG_ON(b->argidx > MC_ARGS);
+
+       if (b->mcidx == 0)
+               return ret;
+
+       if (b->entries[b->mcidx - 1].op != op)
+               return ret;
+
+       if ((b->argidx + size) > MC_ARGS)
+               return ret;
+
+       ret.mc = &b->entries[b->mcidx - 1];
        ret.args = &b->args[b->argidx];
-       b->argidx += argspace;
+       b->argidx += size;
 
+       BUG_ON(b->argidx > MC_ARGS);
        return ret;
 }
 
index 8bae996..8589382 100644 (file)
@@ -45,4 +45,16 @@ static inline void xen_mc_issue(unsigned mode)
 /* Set up a callback to be called when the current batch is flushed */
 void xen_mc_callback(void (*fn)(void *), void *data);
 
+/*
+ * Try to extend the arguments of the previous multicall command.  The
+ * previous command's op must match.  If it does, then it attempts to
+ * extend the argument space allocated to the multicall entry by
+ * arg_size bytes.
+ *
+ * The returned multicall_space will return with mc pointing to the
+ * command on success, or NULL on failure, and args pointing to the
+ * newly allocated space.
+ */
+struct multicall_space xen_mc_extend_args(unsigned long op, size_t arg_size);
+
 #endif /* _XEN_MULTICALLS_H */
index 82517e4..e0a3959 100644 (file)
 #include <asm/vdso.h>
 #include <asm/e820.h>
 #include <asm/setup.h>
+#include <asm/acpi.h>
 #include <asm/xen/hypervisor.h>
 #include <asm/xen/hypercall.h>
 
+#include <xen/page.h>
 #include <xen/interface/callback.h>
 #include <xen/interface/physdev.h>
 #include <xen/features.h>
@@ -27,8 +29,6 @@
 extern const char xen_hypervisor_callback[];
 extern const char xen_failsafe_callback[];
 
-unsigned long *phys_to_machine_mapping;
-EXPORT_SYMBOL(phys_to_machine_mapping);
 
 /**
  * machine_specific_memory_setup - Hook for machine specific memory setup.
@@ -38,9 +38,31 @@ char * __init xen_memory_setup(void)
 {
        unsigned long max_pfn = xen_start_info->nr_pages;
 
+       max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
+
        e820.nr_map = 0;
-       add_memory_region(0, LOWMEMSIZE(), E820_RAM);
-       add_memory_region(HIGH_MEMORY, PFN_PHYS(max_pfn)-HIGH_MEMORY, E820_RAM);
+
+       e820_add_region(0, PFN_PHYS(max_pfn), E820_RAM);
+
+       /*
+        * Even though this is normal, usable memory under Xen, reserve
+        * ISA memory anyway because too many things think they can poke
+        * about in there.
+        */
+       e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS,
+                       E820_RESERVED);
+
+       /*
+        * Reserve Xen bits:
+        *  - mfn_list
+        *  - xen_start_info
+        * See comment above "struct start_info" in <xen/interface/xen.h>
+        */
+       e820_add_region(__pa(xen_start_info->mfn_list),
+                       xen_start_info->pt_base - xen_start_info->mfn_list,
+                       E820_RESERVED);
+
+       sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
 
        return "Xen";
 }
index 94e6900..d2e3c20 100644 (file)
@@ -35,7 +35,7 @@
 #include "xen-ops.h"
 #include "mmu.h"
 
-static cpumask_t xen_cpu_initialized_map;
+cpumask_t xen_cpu_initialized_map;
 static DEFINE_PER_CPU(int, resched_irq) = -1;
 static DEFINE_PER_CPU(int, callfunc_irq) = -1;
 static DEFINE_PER_CPU(int, debug_irq) = -1;
@@ -65,6 +65,12 @@ static struct call_data_struct *call_data;
  */
 static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
 {
+#ifdef CONFIG_X86_32
+       __get_cpu_var(irq_stat).irq_resched_count++;
+#else
+       add_pda(irq_resched_count, 1);
+#endif
+
        return IRQ_HANDLED;
 }
 
diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c
new file mode 100644 (file)
index 0000000..251669a
--- /dev/null
@@ -0,0 +1,45 @@
+#include <linux/types.h>
+
+#include <xen/interface/xen.h>
+#include <xen/grant_table.h>
+#include <xen/events.h>
+
+#include <asm/xen/hypercall.h>
+#include <asm/xen/page.h>
+
+#include "xen-ops.h"
+#include "mmu.h"
+
+void xen_pre_suspend(void)
+{
+       xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
+       xen_start_info->console.domU.mfn =
+               mfn_to_pfn(xen_start_info->console.domU.mfn);
+
+       BUG_ON(!irqs_disabled());
+
+       HYPERVISOR_shared_info = &xen_dummy_shared_info;
+       if (HYPERVISOR_update_va_mapping(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
+                                        __pte_ma(0), 0))
+               BUG();
+}
+
+void xen_post_suspend(int suspend_cancelled)
+{
+       xen_setup_shared_info();
+
+       if (suspend_cancelled) {
+               xen_start_info->store_mfn =
+                       pfn_to_mfn(xen_start_info->store_mfn);
+               xen_start_info->console.domU.mfn =
+                       pfn_to_mfn(xen_start_info->console.domU.mfn);
+       } else {
+#ifdef CONFIG_SMP
+               xen_cpu_initialized_map = cpu_online_map;
+#endif
+               xen_vcpu_restore();
+               xen_timer_resume();
+       }
+
+}
+
index 41e2175..685b774 100644 (file)
@@ -197,8 +197,8 @@ unsigned long long xen_sched_clock(void)
 }
 
 
-/* Get the CPU speed from Xen */
-unsigned long xen_cpu_khz(void)
+/* Get the TSC speed from Xen */
+unsigned long xen_tsc_khz(void)
 {
        u64 xen_khz = 1000000ULL << 32;
        const struct pvclock_vcpu_time_info *info =
@@ -459,6 +459,19 @@ void xen_setup_cpu_clockevents(void)
        clockevents_register_device(&__get_cpu_var(xen_clock_events));
 }
 
+void xen_timer_resume(void)
+{
+       int cpu;
+
+       if (xen_clockevent != &xen_vcpuop_clockevent)
+               return;
+
+       for_each_online_cpu(cpu) {
+               if (HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer, cpu, NULL))
+                       BUG();
+       }
+}
+
 __init void xen_time_init(void)
 {
        int cpu = smp_processor_id();
index 6ec3b4f..7c0cf63 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/init.h>
 #include <asm/boot.h>
 #include <xen/interface/elfnote.h>
+#include <asm/xen/interface.h>
 
        __INIT
 ENTRY(startup_xen)
@@ -32,5 +33,9 @@ ENTRY(hypercall_page)
        ELFNOTE(Xen, XEN_ELFNOTE_FEATURES,       .asciz "!writable_page_tables|pae_pgdir_above_4gb")
        ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE,       .asciz "yes")
        ELFNOTE(Xen, XEN_ELFNOTE_LOADER,         .asciz "generic")
+       ELFNOTE(Xen, XEN_ELFNOTE_L1_MFN_VALID,
+               .quad _PAGE_PRESENT; .quad _PAGE_PRESENT)
+       ELFNOTE(Xen, XEN_ELFNOTE_SUSPEND_CANCEL, .long 1)
+       ELFNOTE(Xen, XEN_ELFNOTE_HV_START_LOW,   .long __HYPERVISOR_VIRT_START)
 
 #endif /*CONFIG_XEN */
index f1063ae..d852ddb 100644 (file)
@@ -9,26 +9,35 @@
 extern const char xen_hypervisor_callback[];
 extern const char xen_failsafe_callback[];
 
+struct trap_info;
 void xen_copy_trap_info(struct trap_info *traps);
 
 DECLARE_PER_CPU(unsigned long, xen_cr3);
 DECLARE_PER_CPU(unsigned long, xen_current_cr3);
 
 extern struct start_info *xen_start_info;
+extern struct shared_info xen_dummy_shared_info;
 extern struct shared_info *HYPERVISOR_shared_info;
 
+void xen_setup_mfn_list_list(void);
+void xen_setup_shared_info(void);
+
 char * __init xen_memory_setup(void);
 void __init xen_arch_setup(void);
 void __init xen_init_IRQ(void);
 void xen_enable_sysenter(void);
+void xen_vcpu_restore(void);
+
+void __init xen_build_dynamic_phys_to_machine(void);
 
 void xen_setup_timer(int cpu);
 void xen_setup_cpu_clockevents(void);
-unsigned long xen_cpu_khz(void);
+unsigned long xen_tsc_khz(void);
 void __init xen_time_init(void);
 unsigned long xen_get_wallclock(void);
 int xen_set_wallclock(unsigned long time);
 unsigned long long xen_sched_clock(void);
+void xen_timer_resume(void);
 
 irqreturn_t xen_debug_interrupt(int irq, void *dev_id);
 
@@ -54,6 +63,8 @@ int xen_smp_call_function_single(int cpu, void (*func) (void *info), void *info,
 int xen_smp_call_function_mask(cpumask_t mask, void (*func)(void *),
                               void *info, int wait);
 
+extern cpumask_t xen_cpu_initialized_map;
+
 
 /* Declare an asm function, along with symbols needed to make it
    inlineable */
index 3e97f2b..1ab7c15 100644 (file)
@@ -81,6 +81,18 @@ config BLK_DEV_BSG
 
          If unsure, say N.
 
+config BLK_DEV_INTEGRITY
+       bool "Block layer data integrity support"
+       ---help---
+       Some storage devices allow extra information to be
+       stored/retrieved to help protect the data.  The block layer
+       data integrity option provides hooks which can be used by
+       filesystems to ensure better data integrity.
+
+       Say yes here if you have a storage device that provides the
+       T10/SCSI Data Integrity Field or the T13/ATA External Path
+       Protection.  If in doubt, say N.
+
 endif # BLOCK
 
 config BLOCK_COMPAT
index 5a43c7d..208000b 100644 (file)
@@ -4,7 +4,8 @@
 
 obj-$(CONFIG_BLOCK) := elevator.o blk-core.o blk-tag.o blk-sysfs.o \
                        blk-barrier.o blk-settings.o blk-ioc.o blk-map.o \
-                       blk-exec.o blk-merge.o ioctl.o genhd.o scsi_ioctl.o
+                       blk-exec.o blk-merge.o ioctl.o genhd.o scsi_ioctl.o \
+                       cmd-filter.o
 
 obj-$(CONFIG_BLK_DEV_BSG)      += bsg.o
 obj-$(CONFIG_IOSCHED_NOOP)     += noop-iosched.o
@@ -14,3 +15,4 @@ obj-$(CONFIG_IOSCHED_CFQ)     += cfq-iosched.o
 
 obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
 obj-$(CONFIG_BLOCK_COMPAT)     += compat_ioctl.o
+obj-$(CONFIG_BLK_DEV_INTEGRITY)        += blk-integrity.o
index 743f33a..9735acb 100644 (file)
@@ -151,6 +151,7 @@ enum arq_state {
 
 static DEFINE_PER_CPU(unsigned long, ioc_count);
 static struct completion *ioc_gone;
+static DEFINE_SPINLOCK(ioc_gone_lock);
 
 static void as_move_to_dispatch(struct as_data *ad, struct request *rq);
 static void as_antic_stop(struct as_data *ad);
@@ -164,8 +165,19 @@ static void free_as_io_context(struct as_io_context *aic)
 {
        kfree(aic);
        elv_ioc_count_dec(ioc_count);
-       if (ioc_gone && !elv_ioc_count_read(ioc_count))
-               complete(ioc_gone);
+       if (ioc_gone) {
+               /*
+                * AS scheduler is exiting, grab exit lock and check
+                * the pending io context count. If it hits zero,
+                * complete ioc_gone and set it back to NULL.
+                */
+               spin_lock(&ioc_gone_lock);
+               if (ioc_gone && !elv_ioc_count_read(ioc_count)) {
+                       complete(ioc_gone);
+                       ioc_gone = NULL;
+               }
+               spin_unlock(&ioc_gone_lock);
+       }
 }
 
 static void as_trim(struct io_context *ioc)
@@ -1493,7 +1505,7 @@ static void __exit as_exit(void)
        /* ioc_gone's update must be visible before reading ioc_count */
        smp_wmb();
        if (elv_ioc_count_read(ioc_count))
-               wait_for_completion(ioc_gone);
+               wait_for_completion(&all_gone);
        synchronize_rcu();
 }
 
index 1905aab..c6e5365 100644 (file)
@@ -143,6 +143,10 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
 
                bio->bi_size -= nbytes;
                bio->bi_sector += (nbytes >> 9);
+
+               if (bio_integrity(bio))
+                       bio_integrity_advance(bio, nbytes);
+
                if (bio->bi_size == 0)
                        bio_endio(bio, error);
        } else {
@@ -201,8 +205,7 @@ void blk_plug_device(struct request_queue *q)
        if (blk_queue_stopped(q))
                return;
 
-       if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
-               __set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags);
+       if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) {
                mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
                blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
        }
@@ -217,10 +220,9 @@ int blk_remove_plug(struct request_queue *q)
 {
        WARN_ON(!irqs_disabled());
 
-       if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
+       if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q))
                return 0;
 
-       queue_flag_clear(QUEUE_FLAG_PLUGGED, q);
        del_timer(&q->unplug_timer);
        return 1;
 }
@@ -324,8 +326,7 @@ void blk_start_queue(struct request_queue *q)
         * one level of recursion is ok and is much faster than kicking
         * the unplug handling
         */
-       if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
-               queue_flag_set(QUEUE_FLAG_REENTER, q);
+       if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
                q->request_fn(q);
                queue_flag_clear(QUEUE_FLAG_REENTER, q);
        } else {
@@ -390,8 +391,7 @@ void __blk_run_queue(struct request_queue *q)
         * handling reinvoke the handler shortly if we already got there.
         */
        if (!elv_queue_empty(q)) {
-               if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
-                       queue_flag_set(QUEUE_FLAG_REENTER, q);
+               if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
                        q->request_fn(q);
                        queue_flag_clear(QUEUE_FLAG_REENTER, q);
                } else {
@@ -1381,6 +1381,9 @@ end_io:
                 */
                blk_partition_remap(bio);
 
+               if (bio_integrity_enabled(bio) && bio_integrity_prep(bio))
+                       goto end_io;
+
                if (old_sector != -1)
                        blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
                                            old_sector);
@@ -2045,7 +2048,7 @@ int __init blk_dev_init(void)
        for_each_possible_cpu(i)
                INIT_LIST_HEAD(&per_cpu(blk_cpu_done, i));
 
-       open_softirq(BLOCK_SOFTIRQ, blk_done_softirq, NULL);
+       open_softirq(BLOCK_SOFTIRQ, blk_done_softirq);
        register_hotcpu_notifier(&blk_cpu_notifier);
 
        return 0;
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
new file mode 100644 (file)
index 0000000..3f1a847
--- /dev/null
@@ -0,0 +1,381 @@
+/*
+ * blk-integrity.c - Block layer data integrity extensions
+ *
+ * Copyright (C) 2007, 2008 Oracle Corporation
+ * Written by: Martin K. Petersen <martin.petersen@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
+ * USA.
+ *
+ */
+
+#include <linux/blkdev.h>
+#include <linux/mempool.h>
+#include <linux/bio.h>
+#include <linux/scatterlist.h>
+
+#include "blk.h"
+
+static struct kmem_cache *integrity_cachep;
+
+/**
+ * blk_rq_count_integrity_sg - Count number of integrity scatterlist elements
+ * @rq:                request with integrity metadata attached
+ *
+ * Description: Returns the number of elements required in a
+ * scatterlist corresponding to the integrity metadata in a request.
+ */
+int blk_rq_count_integrity_sg(struct request *rq)
+{
+       struct bio_vec *iv, *ivprv;
+       struct req_iterator iter;
+       unsigned int segments;
+
+       ivprv = NULL;
+       segments = 0;
+
+       rq_for_each_integrity_segment(iv, rq, iter) {
+
+               if (!ivprv || !BIOVEC_PHYS_MERGEABLE(ivprv, iv))
+                       segments++;
+
+               ivprv = iv;
+       }
+
+       return segments;
+}
+EXPORT_SYMBOL(blk_rq_count_integrity_sg);
+
+/**
+ * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist
+ * @rq:                request with integrity metadata attached
+ * @sglist:    target scatterlist
+ *
+ * Description: Map the integrity vectors in request into a
+ * scatterlist.  The scatterlist must be big enough to hold all
+ * elements.  I.e. sized using blk_rq_count_integrity_sg().
+ */
+int blk_rq_map_integrity_sg(struct request *rq, struct scatterlist *sglist)
+{
+       struct bio_vec *iv, *ivprv;
+       struct req_iterator iter;
+       struct scatterlist *sg;
+       unsigned int segments;
+
+       ivprv = NULL;
+       sg = NULL;
+       segments = 0;
+
+       rq_for_each_integrity_segment(iv, rq, iter) {
+
+               if (ivprv) {
+                       if (!BIOVEC_PHYS_MERGEABLE(ivprv, iv))
+                               goto new_segment;
+
+                       sg->length += iv->bv_len;
+               } else {
+new_segment:
+                       if (!sg)
+                               sg = sglist;
+                       else {
+                               sg->page_link &= ~0x02;
+                               sg = sg_next(sg);
+                       }
+
+                       sg_set_page(sg, iv->bv_page, iv->bv_len, iv->bv_offset);
+                       segments++;
+               }
+
+               ivprv = iv;
+       }
+
+       if (sg)
+               sg_mark_end(sg);
+
+       return segments;
+}
+EXPORT_SYMBOL(blk_rq_map_integrity_sg);
+
+/**
+ * blk_integrity_compare - Compare integrity profile of two block devices
+ * @b1:                Device to compare
+ * @b2:                Device to compare
+ *
+ * Description: Meta-devices like DM and MD need to verify that all
+ * sub-devices use the same integrity format before advertising to
+ * upper layers that they can send/receive integrity metadata.  This
+ * function can be used to check whether two block devices have
+ * compatible integrity formats.
+ */
+int blk_integrity_compare(struct block_device *bd1, struct block_device *bd2)
+{
+       struct blk_integrity *b1 = bd1->bd_disk->integrity;
+       struct blk_integrity *b2 = bd2->bd_disk->integrity;
+
+       BUG_ON(bd1->bd_disk == NULL);
+       BUG_ON(bd2->bd_disk == NULL);
+
+       if (!b1 || !b2)
+               return 0;
+
+       if (b1->sector_size != b2->sector_size) {
+               printk(KERN_ERR "%s: %s/%s sector sz %u != %u\n", __func__,
+                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      b1->sector_size, b2->sector_size);
+               return -1;
+       }
+
+       if (b1->tuple_size != b2->tuple_size) {
+               printk(KERN_ERR "%s: %s/%s tuple sz %u != %u\n", __func__,
+                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      b1->tuple_size, b2->tuple_size);
+               return -1;
+       }
+
+       if (b1->tag_size && b2->tag_size && (b1->tag_size != b2->tag_size)) {
+               printk(KERN_ERR "%s: %s/%s tag sz %u != %u\n", __func__,
+                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      b1->tag_size, b2->tag_size);
+               return -1;
+       }
+
+       if (strcmp(b1->name, b2->name)) {
+               printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__,
+                      bd1->bd_disk->disk_name, bd2->bd_disk->disk_name,
+                      b1->name, b2->name);
+               return -1;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(blk_integrity_compare);
+
+struct integrity_sysfs_entry {
+       struct attribute attr;
+       ssize_t (*show)(struct blk_integrity *, char *);
+       ssize_t (*store)(struct blk_integrity *, const char *, size_t);
+};
+
+static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr,
+                                  char *page)
+{
+       struct blk_integrity *bi =
+               container_of(kobj, struct blk_integrity, kobj);
+       struct integrity_sysfs_entry *entry =
+               container_of(attr, struct integrity_sysfs_entry, attr);
+
+       return entry->show(bi, page);
+}
+
+static ssize_t integrity_attr_store(struct kobject *kobj,
+                                   struct attribute *attr, const char *page,
+                                   size_t count)
+{
+       struct blk_integrity *bi =
+               container_of(kobj, struct blk_integrity, kobj);
+       struct integrity_sysfs_entry *entry =
+               container_of(attr, struct integrity_sysfs_entry, attr);
+       ssize_t ret = 0;
+
+       if (entry->store)
+               ret = entry->store(bi, page, count);
+
+       return ret;
+}
+
+static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
+{
+       if (bi != NULL && bi->name != NULL)
+               return sprintf(page, "%s\n", bi->name);
+       else
+               return sprintf(page, "none\n");
+}
+
+static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page)
+{
+       if (bi != NULL)
+               return sprintf(page, "%u\n", bi->tag_size);
+       else
+               return sprintf(page, "0\n");
+}
+
+static ssize_t integrity_read_store(struct blk_integrity *bi,
+                                   const char *page, size_t count)
+{
+       char *p = (char *) page;
+       unsigned long val = simple_strtoul(p, &p, 10);
+
+       if (val)
+               bi->flags |= INTEGRITY_FLAG_READ;
+       else
+               bi->flags &= ~INTEGRITY_FLAG_READ;
+
+       return count;
+}
+
+static ssize_t integrity_read_show(struct blk_integrity *bi, char *page)
+{
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_READ) != 0);
+}
+
+static ssize_t integrity_write_store(struct blk_integrity *bi,
+                                    const char *page, size_t count)
+{
+       char *p = (char *) page;
+       unsigned long val = simple_strtoul(p, &p, 10);
+
+       if (val)
+               bi->flags |= INTEGRITY_FLAG_WRITE;
+       else
+               bi->flags &= ~INTEGRITY_FLAG_WRITE;
+
+       return count;
+}
+
+static ssize_t integrity_write_show(struct blk_integrity *bi, char *page)
+{
+       return sprintf(page, "%d\n", (bi->flags & INTEGRITY_FLAG_WRITE) != 0);
+}
+
+static struct integrity_sysfs_entry integrity_format_entry = {
+       .attr = { .name = "format", .mode = S_IRUGO },
+       .show = integrity_format_show,
+};
+
+static struct integrity_sysfs_entry integrity_tag_size_entry = {
+       .attr = { .name = "tag_size", .mode = S_IRUGO },
+       .show = integrity_tag_size_show,
+};
+
+static struct integrity_sysfs_entry integrity_read_entry = {
+       .attr = { .name = "read_verify", .mode = S_IRUGO | S_IWUSR },
+       .show = integrity_read_show,
+       .store = integrity_read_store,
+};
+
+static struct integrity_sysfs_entry integrity_write_entry = {
+       .attr = { .name = "write_generate", .mode = S_IRUGO | S_IWUSR },
+       .show = integrity_write_show,
+       .store = integrity_write_store,
+};
+
+static struct attribute *integrity_attrs[] = {
+       &integrity_format_entry.attr,
+       &integrity_tag_size_entry.attr,
+       &integrity_read_entry.attr,
+       &integrity_write_entry.attr,
+       NULL,
+};
+
+static struct sysfs_ops integrity_ops = {
+       .show   = &integrity_attr_show,
+       .store  = &integrity_attr_store,
+};
+
+static int __init blk_dev_integrity_init(void)
+{
+       integrity_cachep = kmem_cache_create("blkdev_integrity",
+                                            sizeof(struct blk_integrity),
+                                            0, SLAB_PANIC, NULL);
+       return 0;
+}
+subsys_initcall(blk_dev_integrity_init);
+
+static void blk_integrity_release(struct kobject *kobj)
+{
+       struct blk_integrity *bi =
+               container_of(kobj, struct blk_integrity, kobj);
+
+       kmem_cache_free(integrity_cachep, bi);
+}
+
+static struct kobj_type integrity_ktype = {
+       .default_attrs  = integrity_attrs,
+       .sysfs_ops      = &integrity_ops,
+       .release        = blk_integrity_release,
+};
+
+/**
+ * blk_integrity_register - Register a gendisk as being integrity-capable
+ * @disk:      struct gendisk pointer to make integrity-aware
+ * @template:  integrity profile
+ *
+ * Description: When a device needs to advertise itself as being able
+ * to send/receive integrity metadata it must use this function to
+ * register the capability with the block layer.  The template is a
+ * blk_integrity struct with values appropriate for the underlying
+ * hardware.  See Documentation/block/data-integrity.txt.
+ */
+int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
+{
+       struct blk_integrity *bi;
+
+       BUG_ON(disk == NULL);
+       BUG_ON(template == NULL);
+
+       if (disk->integrity == NULL) {
+               bi = kmem_cache_alloc(integrity_cachep,
+                                               GFP_KERNEL | __GFP_ZERO);
+               if (!bi)
+                       return -1;
+
+               if (kobject_init_and_add(&bi->kobj, &integrity_ktype,
+                                        &disk->dev.kobj, "%s", "integrity")) {
+                       kmem_cache_free(integrity_cachep, bi);
+                       return -1;
+               }
+
+               kobject_uevent(&bi->kobj, KOBJ_ADD);
+
+               bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
+               bi->sector_size = disk->queue->hardsect_size;
+               disk->integrity = bi;
+       } else
+               bi = disk->integrity;
+
+       /* Use the provided profile as template */
+       bi->name = template->name;
+       bi->generate_fn = template->generate_fn;
+       bi->verify_fn = template->verify_fn;
+       bi->tuple_size = template->tuple_size;
+       bi->set_tag_fn = template->set_tag_fn;
+       bi->get_tag_fn = template->get_tag_fn;
+       bi->tag_size = template->tag_size;
+
+       return 0;
+}
+EXPORT_SYMBOL(blk_integrity_register);
+
+/**
+ * blk_integrity_unregister - Remove block integrity profile
+ * @disk:      disk whose integrity profile to deallocate
+ *
+ * Description: This function frees all memory used by the block
+ * integrity profile.  To be called at device teardown.
+ */
+void blk_integrity_unregister(struct gendisk *disk)
+{
+       struct blk_integrity *bi;
+
+       if (!disk || !disk->integrity)
+               return;
+
+       bi = disk->integrity;
+
+       kobject_uevent(&bi->kobj, KOBJ_REMOVE);
+       kobject_del(&bi->kobj);
+       kobject_put(&disk->dev.kobj);
+       kmem_cache_free(integrity_cachep, bi);
+}
+EXPORT_SYMBOL(blk_integrity_unregister);
index 0b1af5a..ddd96fb 100644 (file)
@@ -210,6 +210,7 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
        if (!bio_flagged(bio, BIO_USER_MAPPED))
                rq->cmd_flags |= REQ_COPY_USER;
 
+       blk_queue_bounce(q, &bio);
        bio_get(bio);
        blk_rq_bio_prep(q, rq, bio);
        rq->buffer = rq->data = NULL;
@@ -268,6 +269,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
        int reading = rq_data_dir(rq) == READ;
        int do_copy = 0;
        struct bio *bio;
+       unsigned long stack_mask = ~(THREAD_SIZE - 1);
 
        if (len > (q->max_hw_sectors << 9))
                return -EINVAL;
@@ -278,6 +280,10 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
        alignment = queue_dma_alignment(q) | q->dma_pad_mask;
        do_copy = ((kaddr & alignment) || (len & alignment));
 
+       if (!((kaddr & stack_mask) ^
+             ((unsigned long)current->stack & stack_mask)))
+               do_copy = 1;
+
        if (do_copy)
                bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
        else
index 651136a..5efc9e7 100644 (file)
@@ -441,6 +441,9 @@ static int attempt_merge(struct request_queue *q, struct request *req,
            || next->special)
                return 0;
 
+       if (blk_integrity_rq(req) != blk_integrity_rq(next))
+               return 0;
+
        /*
         * If we are allowed to merge, then append bio list
         * from next to rq and release next. merge_requests_fn
index 8dd8641..dfc7701 100644 (file)
@@ -302,11 +302,10 @@ EXPORT_SYMBOL(blk_queue_stack_limits);
  * @q:     the request queue for the device
  * @mask:  pad mask
  *
- * Set pad mask.  Direct IO requests are padded to the mask specified.
+ * Set dma pad mask.
  *
- * Appending pad buffer to a request modifies ->data_len such that it
- * includes the pad buffer.  The original requested data length can be
- * obtained using blk_rq_raw_data_len().
+ * Appending pad buffer to a request modifies the last entry of a
+ * scatter list such that it includes the pad buffer.
  **/
 void blk_queue_dma_pad(struct request_queue *q, unsigned int mask)
 {
@@ -314,6 +313,23 @@ void blk_queue_dma_pad(struct request_queue *q, unsigned int mask)
 }
 EXPORT_SYMBOL(blk_queue_dma_pad);
 
+/**
+ * blk_queue_update_dma_pad - update pad mask
+ * @q:     the request queue for the device
+ * @mask:  pad mask
+ *
+ * Update dma pad mask.
+ *
+ * Appending pad buffer to a request modifies the last entry of a
+ * scatter list such that it includes the pad buffer.
+ **/
+void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
+{
+       if (mask > q->dma_pad_mask)
+               q->dma_pad_mask = mask;
+}
+EXPORT_SYMBOL(blk_queue_update_dma_pad);
+
 /**
  * blk_queue_dma_drain - Set up a drain buffer for excess dma.
  * @q:  the request queue for the device
index 59776ab..c79f30e 100644 (file)
@@ -51,4 +51,12 @@ static inline int queue_congestion_off_threshold(struct request_queue *q)
        return q->nr_congestion_off;
 }
 
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+
+#define rq_for_each_integrity_segment(bvl, _rq, _iter)         \
+       __rq_for_each_bio(_iter.bio, _rq)                       \
+               bip_for_each_vec(bvl, _iter.bio->bi_integrity, _iter.i)
+
+#endif /* BLK_DEV_INTEGRITY */
+
 #endif
index 8d3a277..eb9651c 100644 (file)
@@ -244,6 +244,7 @@ err:
 static void blk_trace_cleanup(struct blk_trace *bt)
 {
        relay_close(bt->rchan);
+       debugfs_remove(bt->msg_file);
        debugfs_remove(bt->dropped_file);
        blk_remove_tree(bt->dir);
        free_percpu(bt->sequence);
@@ -291,6 +292,44 @@ static const struct file_operations blk_dropped_fops = {
        .read =         blk_dropped_read,
 };
 
+static int blk_msg_open(struct inode *inode, struct file *filp)
+{
+       filp->private_data = inode->i_private;
+
+       return 0;
+}
+
+static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
+                               size_t count, loff_t *ppos)
+{
+       char *msg;
+       struct blk_trace *bt;
+
+       if (count > BLK_TN_MAX_MSG)
+               return -EINVAL;
+
+       msg = kmalloc(count, GFP_KERNEL);
+       if (msg == NULL)
+               return -ENOMEM;
+
+       if (copy_from_user(msg, buffer, count)) {
+               kfree(msg);
+               return -EFAULT;
+       }
+
+       bt = filp->private_data;
+       __trace_note_message(bt, "%s", msg);
+       kfree(msg);
+
+       return count;
+}
+
+static const struct file_operations blk_msg_fops = {
+       .owner =        THIS_MODULE,
+       .open =         blk_msg_open,
+       .write =        blk_msg_write,
+};
+
 /*
  * Keep track of how many times we encountered a full subbuffer, to aid
  * the user space app in telling how many lost events there were.
@@ -380,6 +419,10 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
        if (!bt->dropped_file)
                goto err;
 
+       bt->msg_file = debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
+       if (!bt->msg_file)
+               goto err;
+
        bt->rchan = relay_open("trace", dir, buts->buf_size,
                                buts->buf_nr, &blk_relay_callbacks, bt);
        if (!bt->rchan)
@@ -409,6 +452,8 @@ err:
        if (dir)
                blk_remove_tree(dir);
        if (bt) {
+               if (bt->msg_file)
+                       debugfs_remove(bt->msg_file);
                if (bt->dropped_file)
                        debugfs_remove(bt->dropped_file);
                free_percpu(bt->sequence);
index 54d617f..0b3b282 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/uio.h>
 #include <linux/idr.h>
 #include <linux/bsg.h>
+#include <linux/smp_lock.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_ioctl.h>
@@ -44,11 +45,12 @@ struct bsg_device {
        char name[BUS_ID_SIZE];
        int max_queue;
        unsigned long flags;
+       struct blk_scsi_cmd_filter *cmd_filter;
+       mode_t *f_mode;
 };
 
 enum {
        BSG_F_BLOCK             = 1,
-       BSG_F_WRITE_PERM        = 2,
 };
 
 #define BSG_DEFAULT_CMDS       64
@@ -172,7 +174,7 @@ unlock:
 }
 
 static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
-                               struct sg_io_v4 *hdr, int has_write_perm)
+                               struct sg_io_v4 *hdr, struct bsg_device *bd)
 {
        if (hdr->request_len > BLK_MAX_CDB) {
                rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
@@ -185,7 +187,8 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
                return -EFAULT;
 
        if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
-               if (blk_verify_command(rq->cmd, has_write_perm))
+               if (blk_cmd_filter_verify_command(bd->cmd_filter, rq->cmd,
+                                                bd->f_mode))
                        return -EPERM;
        } else if (!capable(CAP_SYS_RAWIO))
                return -EPERM;
@@ -263,8 +266,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr)
        rq = blk_get_request(q, rw, GFP_KERNEL);
        if (!rq)
                return ERR_PTR(-ENOMEM);
-       ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, test_bit(BSG_F_WRITE_PERM,
-                                                      &bd->flags));
+       ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd);
        if (ret)
                goto out;
 
@@ -566,12 +568,23 @@ static inline void bsg_set_block(struct bsg_device *bd, struct file *file)
                set_bit(BSG_F_BLOCK, &bd->flags);
 }
 
-static inline void bsg_set_write_perm(struct bsg_device *bd, struct file *file)
+static void bsg_set_cmd_filter(struct bsg_device *bd,
+                          struct file *file)
 {
-       if (file->f_mode & FMODE_WRITE)
-               set_bit(BSG_F_WRITE_PERM, &bd->flags);
-       else
-               clear_bit(BSG_F_WRITE_PERM, &bd->flags);
+       struct inode *inode;
+       struct gendisk *disk;
+
+       if (!file)
+               return;
+
+       inode = file->f_dentry->d_inode;
+       if (!inode)
+               return;
+
+       disk = inode->i_bdev->bd_disk;
+
+       bd->cmd_filter = &disk->cmd_filter;
+       bd->f_mode = &file->f_mode;
 }
 
 /*
@@ -595,6 +608,8 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        dprintk("%s: read %Zd bytes\n", bd->name, count);
 
        bsg_set_block(bd, file);
+       bsg_set_cmd_filter(bd, file);
+
        bytes_read = 0;
        ret = __bsg_read(buf, count, bd, NULL, &bytes_read);
        *ppos = bytes_read;
@@ -668,7 +683,7 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
        dprintk("%s: write %Zd bytes\n", bd->name, count);
 
        bsg_set_block(bd, file);
-       bsg_set_write_perm(bd, file);
+       bsg_set_cmd_filter(bd, file);
 
        bytes_written = 0;
        ret = __bsg_write(bd, buf, count, &bytes_written);
@@ -772,7 +787,9 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
        }
 
        bd->queue = rq;
+
        bsg_set_block(bd, file);
+       bsg_set_cmd_filter(bd, file);
 
        atomic_set(&bd->ref_count, 1);
        mutex_lock(&bsg_mutex);
@@ -835,7 +852,11 @@ static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file)
 
 static int bsg_open(struct inode *inode, struct file *file)
 {
-       struct bsg_device *bd = bsg_get_device(inode, file);
+       struct bsg_device *bd;
+
+       lock_kernel();
+       bd = bsg_get_device(inode, file);
+       unlock_kernel();
 
        if (IS_ERR(bd))
                return PTR_ERR(bd);
index d01b411..1e2aff8 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/elevator.h>
 #include <linux/rbtree.h>
 #include <linux/ioprio.h>
+#include <linux/blktrace_api.h>
 
 /*
  * tunables
@@ -41,13 +42,14 @@ static int cfq_slice_idle = HZ / 125;
 
 #define RQ_CIC(rq)             \
        ((struct cfq_io_context *) (rq)->elevator_private)
-#define RQ_CFQQ(rq)            ((rq)->elevator_private2)
+#define RQ_CFQQ(rq)            (struct cfq_queue *) ((rq)->elevator_private2)
 
 static struct kmem_cache *cfq_pool;
 static struct kmem_cache *cfq_ioc_pool;
 
 static DEFINE_PER_CPU(unsigned long, ioc_count);
 static struct completion *ioc_gone;
+static DEFINE_SPINLOCK(ioc_gone_lock);
 
 #define CFQ_PRIO_LISTS         IOPRIO_BE_NR
 #define cfq_class_idle(cfqq)   ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
@@ -155,6 +157,7 @@ struct cfq_queue {
        unsigned short ioprio, org_ioprio;
        unsigned short ioprio_class, org_ioprio_class;
 
+       pid_t pid;
 };
 
 enum cfqq_state_flags {
@@ -198,6 +201,11 @@ CFQ_CFQQ_FNS(slice_new);
 CFQ_CFQQ_FNS(sync);
 #undef CFQ_CFQQ_FNS
 
+#define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
+       blk_add_trace_msg((cfqd)->queue, "cfq%d " fmt, (cfqq)->pid, ##args)
+#define cfq_log(cfqd, fmt, args...)    \
+       blk_add_trace_msg((cfqd)->queue, "cfq " fmt, ##args)
+
 static void cfq_dispatch_insert(struct request_queue *, struct request *);
 static struct cfq_queue *cfq_get_queue(struct cfq_data *, int,
                                       struct io_context *, gfp_t);
@@ -234,8 +242,10 @@ static inline int cfq_bio_sync(struct bio *bio)
  */
 static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
 {
-       if (cfqd->busy_queues)
+       if (cfqd->busy_queues) {
+               cfq_log(cfqd, "schedule dispatch");
                kblockd_schedule_work(&cfqd->unplug_work);
+       }
 }
 
 static int cfq_queue_empty(struct request_queue *q)
@@ -270,6 +280,7 @@ static inline void
 cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
        cfqq->slice_end = cfq_prio_to_slice(cfqd, cfqq) + jiffies;
+       cfq_log_cfqq(cfqd, cfqq, "set_slice=%lu", cfqq->slice_end - jiffies);
 }
 
 /*
@@ -539,6 +550,7 @@ static void cfq_resort_rr_list(struct cfq_data *cfqd, struct cfq_queue *cfqq)
  */
 static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
+       cfq_log_cfqq(cfqd, cfqq, "add_to_rr");
        BUG_ON(cfq_cfqq_on_rr(cfqq));
        cfq_mark_cfqq_on_rr(cfqq);
        cfqd->busy_queues++;
@@ -552,6 +564,7 @@ static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
  */
 static void cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
+       cfq_log_cfqq(cfqd, cfqq, "del_from_rr");
        BUG_ON(!cfq_cfqq_on_rr(cfqq));
        cfq_clear_cfqq_on_rr(cfqq);
 
@@ -638,6 +651,8 @@ static void cfq_activate_request(struct request_queue *q, struct request *rq)
        struct cfq_data *cfqd = q->elevator->elevator_data;
 
        cfqd->rq_in_driver++;
+       cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
+                                               cfqd->rq_in_driver);
 
        /*
         * If the depth is larger 1, it really could be queueing. But lets
@@ -657,6 +672,8 @@ static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
 
        WARN_ON(!cfqd->rq_in_driver);
        cfqd->rq_in_driver--;
+       cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d",
+                                               cfqd->rq_in_driver);
 }
 
 static void cfq_remove_request(struct request *rq)
@@ -746,6 +763,7 @@ static void __cfq_set_active_queue(struct cfq_data *cfqd,
                                   struct cfq_queue *cfqq)
 {
        if (cfqq) {
+               cfq_log_cfqq(cfqd, cfqq, "set_active");
                cfqq->slice_end = 0;
                cfq_clear_cfqq_must_alloc_slice(cfqq);
                cfq_clear_cfqq_fifo_expire(cfqq);
@@ -763,6 +781,8 @@ static void
 __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
                    int timed_out)
 {
+       cfq_log_cfqq(cfqd, cfqq, "slice expired t=%d", timed_out);
+
        if (cfq_cfqq_wait_request(cfqq))
                del_timer(&cfqd->idle_slice_timer);
 
@@ -772,8 +792,10 @@ __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
        /*
         * store what was left of this slice, if the queue idled/timed out
         */
-       if (timed_out && !cfq_cfqq_slice_new(cfqq))
+       if (timed_out && !cfq_cfqq_slice_new(cfqq)) {
                cfqq->slice_resid = cfqq->slice_end - jiffies;
+               cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid);
+       }
 
        cfq_resort_rr_list(cfqd, cfqq);
 
@@ -865,6 +887,12 @@ static void cfq_arm_slice_timer(struct cfq_data *cfqd)
        if (!cfqd->cfq_slice_idle || !cfq_cfqq_idle_window(cfqq))
                return;
 
+       /*
+        * still requests with the driver, don't idle
+        */
+       if (cfqd->rq_in_driver)
+               return;
+
        /*
         * task has exited, don't wait
         */
@@ -892,6 +920,7 @@ static void cfq_arm_slice_timer(struct cfq_data *cfqd)
                sl = min(sl, msecs_to_jiffies(CFQ_MIN_TT));
 
        mod_timer(&cfqd->idle_slice_timer, jiffies + sl);
+       cfq_log(cfqd, "arm_idle: %lu", sl);
 }
 
 /*
@@ -902,6 +931,8 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)
        struct cfq_data *cfqd = q->elevator->elevator_data;
        struct cfq_queue *cfqq = RQ_CFQQ(rq);
 
+       cfq_log_cfqq(cfqd, cfqq, "dispatch_insert");
+
        cfq_remove_request(rq);
        cfqq->dispatched++;
        elv_dispatch_sort(q, rq);
@@ -931,8 +962,9 @@ static struct request *cfq_check_fifo(struct cfq_queue *cfqq)
        rq = rq_entry_fifo(cfqq->fifo.next);
 
        if (time_before(jiffies, rq->start_time + cfqd->cfq_fifo_expire[fifo]))
-               return NULL;
+               rq = NULL;
 
+       cfq_log_cfqq(cfqd, cfqq, "fifo=%p", rq);
        return rq;
 }
 
@@ -1072,6 +1104,7 @@ static int cfq_forced_dispatch(struct cfq_data *cfqd)
 
        BUG_ON(cfqd->busy_queues);
 
+       cfq_log(cfqd, "forced_dispatch=%d\n", dispatched);
        return dispatched;
 }
 
@@ -1112,6 +1145,7 @@ static int cfq_dispatch_requests(struct request_queue *q, int force)
                dispatched += __cfq_dispatch_requests(cfqd, cfqq, max_dispatch);
        }
 
+       cfq_log(cfqd, "dispatched=%d", dispatched);
        return dispatched;
 }
 
@@ -1130,6 +1164,7 @@ static void cfq_put_queue(struct cfq_queue *cfqq)
        if (!atomic_dec_and_test(&cfqq->ref))
                return;
 
+       cfq_log_cfqq(cfqd, cfqq, "put_queue");
        BUG_ON(rb_first(&cfqq->sort_list));
        BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
        BUG_ON(cfq_cfqq_on_rr(cfqq));
@@ -1177,8 +1212,19 @@ static void cfq_cic_free_rcu(struct rcu_head *head)
        kmem_cache_free(cfq_ioc_pool, cic);
        elv_ioc_count_dec(ioc_count);
 
-       if (ioc_gone && !elv_ioc_count_read(ioc_count))
-               complete(ioc_gone);
+       if (ioc_gone) {
+               /*
+                * CFQ scheduler is exiting, grab exit lock and check
+                * the pending io context count. If it hits zero,
+                * complete ioc_gone and set it back to NULL
+                */
+               spin_lock(&ioc_gone_lock);
+               if (ioc_gone && !elv_ioc_count_read(ioc_count)) {
+                       complete(ioc_gone);
+                       ioc_gone = NULL;
+               }
+               spin_unlock(&ioc_gone_lock);
+       }
 }
 
 static void cfq_cic_free(struct cfq_io_context *cic)
@@ -1427,6 +1473,8 @@ retry:
                                cfq_mark_cfqq_idle_window(cfqq);
                        cfq_mark_cfqq_sync(cfqq);
                }
+               cfqq->pid = current->pid;
+               cfq_log_cfqq(cfqd, cfqq, "alloced");
        }
 
        if (new_cfqq)
@@ -1675,7 +1723,7 @@ static void
 cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
                       struct cfq_io_context *cic)
 {
-       int enable_idle;
+       int old_idle, enable_idle;
 
        /*
         * Don't idle for async or idle io prio class
@@ -1683,7 +1731,7 @@ cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
        if (!cfq_cfqq_sync(cfqq) || cfq_class_idle(cfqq))
                return;
 
-       enable_idle = cfq_cfqq_idle_window(cfqq);
+       enable_idle = old_idle = cfq_cfqq_idle_window(cfqq);
 
        if (!atomic_read(&cic->ioc->nr_tasks) || !cfqd->cfq_slice_idle ||
            (cfqd->hw_tag && CIC_SEEKY(cic)))
@@ -1695,10 +1743,13 @@ cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
                        enable_idle = 1;
        }
 
-       if (enable_idle)
-               cfq_mark_cfqq_idle_window(cfqq);
-       else
-               cfq_clear_cfqq_idle_window(cfqq);
+       if (old_idle != enable_idle) {
+               cfq_log_cfqq(cfqd, cfqq, "idle=%d", enable_idle);
+               if (enable_idle)
+                       cfq_mark_cfqq_idle_window(cfqq);
+               else
+                       cfq_clear_cfqq_idle_window(cfqq);
+       }
 }
 
 /*
@@ -1757,6 +1808,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
  */
 static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
+       cfq_log_cfqq(cfqd, cfqq, "preempt");
        cfq_slice_expired(cfqd, 1);
 
        /*
@@ -1818,6 +1870,7 @@ static void cfq_insert_request(struct request_queue *q, struct request *rq)
        struct cfq_data *cfqd = q->elevator->elevator_data;
        struct cfq_queue *cfqq = RQ_CFQQ(rq);
 
+       cfq_log_cfqq(cfqd, cfqq, "insert_request");
        cfq_init_prio_data(cfqq, RQ_CIC(rq)->ioc);
 
        cfq_add_rq_rb(rq);
@@ -1835,6 +1888,7 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
        unsigned long now;
 
        now = jiffies;
+       cfq_log_cfqq(cfqd, cfqq, "complete");
 
        WARN_ON(!cfqd->rq_in_driver);
        WARN_ON(!cfqq->dispatched);
@@ -2004,6 +2058,7 @@ queue_fail:
 
        cfq_schedule_dispatch(cfqd);
        spin_unlock_irqrestore(q->queue_lock, flags);
+       cfq_log(cfqd, "set_request fail");
        return 1;
 }
 
@@ -2029,6 +2084,8 @@ static void cfq_idle_slice_timer(unsigned long data)
        unsigned long flags;
        int timed_out = 1;
 
+       cfq_log(cfqd, "idle timer fired");
+
        spin_lock_irqsave(cfqd->queue->queue_lock, flags);
 
        cfqq = cfqd->active_queue;
@@ -2317,7 +2374,7 @@ static void __exit cfq_exit(void)
         * pending RCU callbacks
         */
        if (elv_ioc_count_read(ioc_count))
-               wait_for_completion(ioc_gone);
+               wait_for_completion(&all_gone);
        cfq_slab_kill();
 }
 
diff --git a/block/cmd-filter.c b/block/cmd-filter.c
new file mode 100644 (file)
index 0000000..eec4404
--- /dev/null
@@ -0,0 +1,334 @@
+/*
+ * Copyright 2004 Peter M. Jones <pjones@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public Licens
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-
+ *
+ */
+
+#include <linux/list.h>
+#include <linux/genhd.h>
+#include <linux/spinlock.h>
+#include <linux/parser.h>
+#include <linux/capability.h>
+#include <linux/bitops.h>
+
+#include <scsi/scsi.h>
+#include <linux/cdrom.h>
+
+int blk_cmd_filter_verify_command(struct blk_scsi_cmd_filter *filter,
+                                 unsigned char *cmd, mode_t *f_mode)
+{
+       /* root can do any command. */
+       if (capable(CAP_SYS_RAWIO))
+               return 0;
+
+       /* if there's no filter set, assume we're filtering everything out */
+       if (!filter)
+               return -EPERM;
+
+       /* Anybody who can open the device can do a read-safe command */
+       if (test_bit(cmd[0], filter->read_ok))
+               return 0;
+
+       /* Write-safe commands require a writable open */
+       if (test_bit(cmd[0], filter->write_ok) && (*f_mode & FMODE_WRITE))
+               return 0;
+
+       return -EPERM;
+}
+EXPORT_SYMBOL(blk_cmd_filter_verify_command);
+
+int blk_verify_command(struct file *file, unsigned char *cmd)
+{
+       struct gendisk *disk;
+       struct inode *inode;
+
+       if (!file)
+               return -EINVAL;
+
+       inode = file->f_dentry->d_inode;
+       if (!inode)
+               return -EINVAL;
+
+       disk = inode->i_bdev->bd_disk;
+
+       return blk_cmd_filter_verify_command(&disk->cmd_filter,
+                                                cmd, &file->f_mode);
+}
+EXPORT_SYMBOL(blk_verify_command);
+
+/* and now, the sysfs stuff */
+static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page,
+                            int rw)
+{
+       char *npage = page;
+       unsigned long *okbits;
+       int i;
+
+       if (rw == READ)
+               okbits = filter->read_ok;
+       else
+               okbits = filter->write_ok;
+
+       for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) {
+               if (test_bit(i, okbits)) {
+                       sprintf(npage, "%02x", i);
+                       npage += 2;
+                       if (i < BLK_SCSI_MAX_CMDS - 1)
+                               sprintf(npage++, " ");
+               }
+       }
+
+       if (npage != page)
+               npage += sprintf(npage, "\n");
+
+       return npage - page;
+}
+
+static ssize_t rcf_readcmds_show(struct blk_scsi_cmd_filter *filter, char *page)
+{
+       return rcf_cmds_show(filter, page, READ);
+}
+
+static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter,
+                                char *page)
+{
+       return rcf_cmds_show(filter, page, WRITE);
+}
+
+static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter,
+                             const char *page, size_t count, int rw)
+{
+       ssize_t ret = 0;
+       unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
+       int cmd, status, len;
+       substring_t ss;
+
+       memset(&okbits, 0, sizeof(okbits));
+
+       for (len = strlen(page); len > 0; len -= 3) {
+               if (len < 2)
+                       break;
+               ss.from = (char *) page + ret;
+               ss.to = (char *) page + ret + 2;
+               ret += 3;
+               status = match_hex(&ss, &cmd);
+               /* either of these cases means invalid input, so do nothing. */
+               if (status || cmd >= BLK_SCSI_MAX_CMDS)
+                       return -EINVAL;
+
+               __set_bit(cmd, okbits);
+       }
+
+       if (rw == READ)
+               target_okbits = filter->read_ok;
+       else
+               target_okbits = filter->write_ok;
+
+       memmove(target_okbits, okbits, sizeof(okbits));
+       return count;
+}
+
+static ssize_t rcf_readcmds_store(struct blk_scsi_cmd_filter *filter,
+                                 const char *page, size_t count)
+{
+       return rcf_cmds_store(filter, page, count, READ);
+}
+
+static ssize_t rcf_writecmds_store(struct blk_scsi_cmd_filter *filter,
+                                  const char *page, size_t count)
+{
+       return rcf_cmds_store(filter, page, count, WRITE);
+}
+
+struct rcf_sysfs_entry {
+       struct attribute attr;
+       ssize_t (*show)(struct blk_scsi_cmd_filter *, char *);
+       ssize_t (*store)(struct blk_scsi_cmd_filter *, const char *, size_t);
+};
+
+static struct rcf_sysfs_entry rcf_readcmds_entry = {
+       .attr = { .name = "read_table", .mode = S_IRUGO | S_IWUSR },
+       .show = rcf_readcmds_show,
+       .store = rcf_readcmds_store,
+};
+
+static struct rcf_sysfs_entry rcf_writecmds_entry = {
+       .attr = {.name = "write_table", .mode = S_IRUGO | S_IWUSR },
+       .show = rcf_writecmds_show,
+       .store = rcf_writecmds_store,
+};
+
+static struct attribute *default_attrs[] = {
+       &rcf_readcmds_entry.attr,
+       &rcf_writecmds_entry.attr,
+       NULL,
+};
+
+#define to_rcf(atr) container_of((atr), struct rcf_sysfs_entry, attr)
+
+static ssize_t
+rcf_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
+{
+       struct rcf_sysfs_entry *entry = to_rcf(attr);
+       struct blk_scsi_cmd_filter *filter;
+
+       filter = container_of(kobj, struct blk_scsi_cmd_filter, kobj);
+       if (entry->show)
+               return entry->show(filter, page);
+
+       return 0;
+}
+
+static ssize_t
+rcf_attr_store(struct kobject *kobj, struct attribute *attr,
+                       const char *page, size_t length)
+{
+       struct rcf_sysfs_entry *entry = to_rcf(attr);
+       struct blk_scsi_cmd_filter *filter;
+
+       if (!capable(CAP_SYS_RAWIO))
+               return -EPERM;
+
+       if (!entry->store)
+               return -EINVAL;
+
+       filter = container_of(kobj, struct blk_scsi_cmd_filter, kobj);
+       return entry->store(filter, page, length);
+}
+
+static struct sysfs_ops rcf_sysfs_ops = {
+       .show = rcf_attr_show,
+       .store = rcf_attr_store,
+};
+
+static struct kobj_type rcf_ktype = {
+       .sysfs_ops = &rcf_sysfs_ops,
+       .default_attrs = default_attrs,
+};
+
+#ifndef MAINTENANCE_IN_CMD
+#define MAINTENANCE_IN_CMD 0xa3
+#endif
+
+static void rcf_set_defaults(struct blk_scsi_cmd_filter *filter)
+{
+       /* Basic read-only commands */
+       __set_bit(TEST_UNIT_READY, filter->read_ok);
+       __set_bit(REQUEST_SENSE, filter->read_ok);
+       __set_bit(READ_6, filter->read_ok);
+       __set_bit(READ_10, filter->read_ok);
+       __set_bit(READ_12, filter->read_ok);
+       __set_bit(READ_16, filter->read_ok);
+       __set_bit(READ_BUFFER, filter->read_ok);
+       __set_bit(READ_DEFECT_DATA, filter->read_ok);
+       __set_bit(READ_CAPACITY, filter->read_ok);
+       __set_bit(READ_LONG, filter->read_ok);
+       __set_bit(INQUIRY, filter->read_ok);
+       __set_bit(MODE_SENSE, filter->read_ok);
+       __set_bit(MODE_SENSE_10, filter->read_ok);
+       __set_bit(LOG_SENSE, filter->read_ok);
+       __set_bit(START_STOP, filter->read_ok);
+       __set_bit(GPCMD_VERIFY_10, filter->read_ok);
+       __set_bit(VERIFY_16, filter->read_ok);
+       __set_bit(REPORT_LUNS, filter->read_ok);
+       __set_bit(SERVICE_ACTION_IN, filter->read_ok);
+       __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok);
+       __set_bit(MAINTENANCE_IN_CMD, filter->read_ok);
+       __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok);
+
+       /* Audio CD commands */
+       __set_bit(GPCMD_PLAY_CD, filter->read_ok);
+       __set_bit(GPCMD_PLAY_AUDIO_10, filter->read_ok);
+       __set_bit(GPCMD_PLAY_AUDIO_MSF, filter->read_ok);
+       __set_bit(GPCMD_PLAY_AUDIO_TI, filter->read_ok);
+       __set_bit(GPCMD_PAUSE_RESUME, filter->read_ok);
+
+       /* CD/DVD data reading */
+       __set_bit(GPCMD_READ_CD, filter->read_ok);
+       __set_bit(GPCMD_READ_CD_MSF, filter->read_ok);
+       __set_bit(GPCMD_READ_DISC_INFO, filter->read_ok);
+       __set_bit(GPCMD_READ_CDVD_CAPACITY, filter->read_ok);
+       __set_bit(GPCMD_READ_DVD_STRUCTURE, filter->read_ok);
+       __set_bit(GPCMD_READ_HEADER, filter->read_ok);
+       __set_bit(GPCMD_READ_TRACK_RZONE_INFO, filter->read_ok);
+       __set_bit(GPCMD_READ_SUBCHANNEL, filter->read_ok);
+       __set_bit(GPCMD_READ_TOC_PMA_ATIP, filter->read_ok);
+       __set_bit(GPCMD_REPORT_KEY, filter->read_ok);
+       __set_bit(GPCMD_SCAN, filter->read_ok);
+       __set_bit(GPCMD_GET_CONFIGURATION, filter->read_ok);
+       __set_bit(GPCMD_READ_FORMAT_CAPACITIES, filter->read_ok);
+       __set_bit(GPCMD_GET_EVENT_STATUS_NOTIFICATION, filter->read_ok);
+       __set_bit(GPCMD_GET_PERFORMANCE, filter->read_ok);
+       __set_bit(GPCMD_SEEK, filter->read_ok);
+       __set_bit(GPCMD_STOP_PLAY_SCAN, filter->read_ok);
+
+       /* Basic writing commands */
+       __set_bit(WRITE_6, filter->write_ok);
+       __set_bit(WRITE_10, filter->write_ok);
+       __set_bit(WRITE_VERIFY, filter->write_ok);
+       __set_bit(WRITE_12, filter->write_ok);
+       __set_bit(WRITE_VERIFY_12, filter->write_ok);
+       __set_bit(WRITE_16, filter->write_ok);
+       __set_bit(WRITE_LONG, filter->write_ok);
+       __set_bit(WRITE_LONG_2, filter->write_ok);
+       __set_bit(ERASE, filter->write_ok);
+       __set_bit(GPCMD_MODE_SELECT_10, filter->write_ok);
+       __set_bit(MODE_SELECT, filter->write_ok);
+       __set_bit(LOG_SELECT, filter->write_ok);
+       __set_bit(GPCMD_BLANK, filter->write_ok);
+       __set_bit(GPCMD_CLOSE_TRACK, filter->write_ok);
+       __set_bit(GPCMD_FLUSH_CACHE, filter->write_ok);
+       __set_bit(GPCMD_FORMAT_UNIT, filter->write_ok);
+       __set_bit(GPCMD_REPAIR_RZONE_TRACK, filter->write_ok);
+       __set_bit(GPCMD_RESERVE_RZONE_TRACK, filter->write_ok);
+       __set_bit(GPCMD_SEND_DVD_STRUCTURE, filter->write_ok);
+       __set_bit(GPCMD_SEND_EVENT, filter->write_ok);
+       __set_bit(GPCMD_SEND_KEY, filter->write_ok);
+       __set_bit(GPCMD_SEND_OPC, filter->write_ok);
+       __set_bit(GPCMD_SEND_CUE_SHEET, filter->write_ok);
+       __set_bit(GPCMD_SET_SPEED, filter->write_ok);
+       __set_bit(GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, filter->write_ok);
+       __set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok);
+       __set_bit(GPCMD_SET_STREAMING, filter->write_ok);
+}
+
+int blk_register_filter(struct gendisk *disk)
+{
+       int ret;
+       struct blk_scsi_cmd_filter *filter = &disk->cmd_filter;
+       struct kobject *parent = kobject_get(disk->holder_dir->parent);
+
+       if (!parent)
+               return -ENODEV;
+
+       ret = kobject_init_and_add(&filter->kobj, &rcf_ktype, parent,
+                                "%s", "cmd_filter");
+
+       if (ret < 0)
+               return ret;
+
+       rcf_set_defaults(filter);
+       return 0;
+}
+
+void blk_unregister_filter(struct gendisk *disk)
+{
+       struct blk_scsi_cmd_filter *filter = &disk->cmd_filter;
+
+       kobject_put(&filter->kobj);
+       kobject_put(disk->holder_dir->parent);
+}
+
index 902dd13..ed6f8f3 100644 (file)
@@ -86,6 +86,12 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
        if (rq->rq_disk != bio->bi_bdev->bd_disk || rq->special)
                return 0;
 
+       /*
+        * only merge integrity protected bio into ditto rq
+        */
+       if (bio_integrity(bio) != blk_integrity_rq(rq))
+               return 0;
+
        if (!elv_iosched_allow_merge(rq, bio))
                return 0;
 
@@ -144,7 +150,7 @@ static struct elevator_type *elevator_get(const char *name)
                else
                        sprintf(elv, "%s-iosched", name);
 
-               request_module(elv);
+               request_module("%s", elv);
                spin_lock(&elv_list_lock);
                e = elevator_find(name);
        }
index b922d48..9074f38 100644 (file)
@@ -189,6 +189,7 @@ void add_disk(struct gendisk *disk)
                            disk->minors, NULL, exact_match, exact_lock, disk);
        register_disk(disk);
        blk_register_queue(disk);
+       blk_register_filter(disk);
 
        bdi = &disk->queue->backing_dev_info;
        bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor));
@@ -200,6 +201,7 @@ EXPORT_SYMBOL(del_gendisk); /* in partitions/check.c */
 
 void unlink_gendisk(struct gendisk *disk)
 {
+       blk_unregister_filter(disk);
        sysfs_remove_link(&disk->dev.kobj, "bdi");
        bdi_unregister(&disk->queue->backing_dev_info);
        blk_unregister_queue(disk);
@@ -400,6 +402,14 @@ static ssize_t disk_removable_show(struct device *dev,
                       (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
 }
 
+static ssize_t disk_ro_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%d\n", disk->policy ? 1 : 0);
+}
+
 static ssize_t disk_size_show(struct device *dev,
                              struct device_attribute *attr, char *buf)
 {
@@ -472,6 +482,7 @@ static ssize_t disk_fail_store(struct device *dev,
 
 static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
 static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
+static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
 static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL);
 static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
 static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);
@@ -483,6 +494,7 @@ static struct device_attribute dev_attr_fail =
 static struct attribute *disk_attrs[] = {
        &dev_attr_range.attr,
        &dev_attr_removable.attr,
+       &dev_attr_ro.attr,
        &dev_attr_size.attr,
        &dev_attr_capability.attr,
        &dev_attr_stat.attr,
index 78199c0..c5b9bcf 100644 (file)
@@ -105,120 +105,12 @@ static int sg_emulated_host(struct request_queue *q, int __user *p)
        return put_user(1, p);
 }
 
-#define CMD_READ_SAFE  0x01
-#define CMD_WRITE_SAFE 0x02
-#define CMD_WARNED     0x04
-#define safe_for_read(cmd)     [cmd] = CMD_READ_SAFE
-#define safe_for_write(cmd)    [cmd] = CMD_WRITE_SAFE
-
-int blk_verify_command(unsigned char *cmd, int has_write_perm)
-{
-       static unsigned char cmd_type[256] = {
-
-               /* Basic read-only commands */
-               safe_for_read(TEST_UNIT_READY),
-               safe_for_read(REQUEST_SENSE),
-               safe_for_read(READ_6),
-               safe_for_read(READ_10),
-               safe_for_read(READ_12),
-               safe_for_read(READ_16),
-               safe_for_read(READ_BUFFER),
-               safe_for_read(READ_DEFECT_DATA),
-               safe_for_read(READ_LONG),
-               safe_for_read(INQUIRY),
-               safe_for_read(MODE_SENSE),
-               safe_for_read(MODE_SENSE_10),
-               safe_for_read(LOG_SENSE),
-               safe_for_read(START_STOP),
-               safe_for_read(GPCMD_VERIFY_10),
-               safe_for_read(VERIFY_16),
-
-               /* Audio CD commands */
-               safe_for_read(GPCMD_PLAY_CD),
-               safe_for_read(GPCMD_PLAY_AUDIO_10),
-               safe_for_read(GPCMD_PLAY_AUDIO_MSF),
-               safe_for_read(GPCMD_PLAY_AUDIO_TI),
-               safe_for_read(GPCMD_PAUSE_RESUME),
-
-               /* CD/DVD data reading */
-               safe_for_read(GPCMD_READ_BUFFER_CAPACITY),
-               safe_for_read(GPCMD_READ_CD),
-               safe_for_read(GPCMD_READ_CD_MSF),
-               safe_for_read(GPCMD_READ_DISC_INFO),
-               safe_for_read(GPCMD_READ_CDVD_CAPACITY),
-               safe_for_read(GPCMD_READ_DVD_STRUCTURE),
-               safe_for_read(GPCMD_READ_HEADER),
-               safe_for_read(GPCMD_READ_TRACK_RZONE_INFO),
-               safe_for_read(GPCMD_READ_SUBCHANNEL),
-               safe_for_read(GPCMD_READ_TOC_PMA_ATIP),
-               safe_for_read(GPCMD_REPORT_KEY),
-               safe_for_read(GPCMD_SCAN),
-               safe_for_read(GPCMD_GET_CONFIGURATION),
-               safe_for_read(GPCMD_READ_FORMAT_CAPACITIES),
-               safe_for_read(GPCMD_GET_EVENT_STATUS_NOTIFICATION),
-               safe_for_read(GPCMD_GET_PERFORMANCE),
-               safe_for_read(GPCMD_SEEK),
-               safe_for_read(GPCMD_STOP_PLAY_SCAN),
-
-               /* Basic writing commands */
-               safe_for_write(WRITE_6),
-               safe_for_write(WRITE_10),
-               safe_for_write(WRITE_VERIFY),
-               safe_for_write(WRITE_12),
-               safe_for_write(WRITE_VERIFY_12),
-               safe_for_write(WRITE_16),
-               safe_for_write(WRITE_LONG),
-               safe_for_write(WRITE_LONG_2),
-               safe_for_write(ERASE),
-               safe_for_write(GPCMD_MODE_SELECT_10),
-               safe_for_write(MODE_SELECT),
-               safe_for_write(LOG_SELECT),
-               safe_for_write(GPCMD_BLANK),
-               safe_for_write(GPCMD_CLOSE_TRACK),
-               safe_for_write(GPCMD_FLUSH_CACHE),
-               safe_for_write(GPCMD_FORMAT_UNIT),
-               safe_for_write(GPCMD_REPAIR_RZONE_TRACK),
-               safe_for_write(GPCMD_RESERVE_RZONE_TRACK),
-               safe_for_write(GPCMD_SEND_DVD_STRUCTURE),
-               safe_for_write(GPCMD_SEND_EVENT),
-               safe_for_write(GPCMD_SEND_KEY),
-               safe_for_write(GPCMD_SEND_OPC),
-               safe_for_write(GPCMD_SEND_CUE_SHEET),
-               safe_for_write(GPCMD_SET_SPEED),
-               safe_for_write(GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL),
-               safe_for_write(GPCMD_LOAD_UNLOAD),
-               safe_for_write(GPCMD_SET_STREAMING),
-       };
-       unsigned char type = cmd_type[cmd[0]];
-
-       /* Anybody who can open the device can do a read-safe command */
-       if (type & CMD_READ_SAFE)
-               return 0;
-
-       /* Write-safe commands just require a writable open.. */
-       if ((type & CMD_WRITE_SAFE) && has_write_perm)
-               return 0;
-
-       /* And root can do any command.. */
-       if (capable(CAP_SYS_RAWIO))
-               return 0;
-
-       if (!type) {
-               cmd_type[cmd[0]] = CMD_WARNED;
-               printk(KERN_WARNING "scsi: unknown opcode 0x%02x\n", cmd[0]);
-       }
-
-       /* Otherwise fail it with an "Operation not permitted" */
-       return -EPERM;
-}
-EXPORT_SYMBOL_GPL(blk_verify_command);
-
 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
-                            struct sg_io_hdr *hdr, int has_write_perm)
+                            struct sg_io_hdr *hdr, struct file *file)
 {
        if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
                return -EFAULT;
-       if (blk_verify_command(rq->cmd, has_write_perm))
+       if (blk_verify_command(file, rq->cmd))
                return -EPERM;
 
        /*
@@ -287,7 +179,7 @@ static int sg_io(struct file *file, struct request_queue *q,
                struct gendisk *bd_disk, struct sg_io_hdr *hdr)
 {
        unsigned long start_time;
-       int writing = 0, ret = 0, has_write_perm = 0;
+       int writing = 0, ret = 0;
        struct request *rq;
        char sense[SCSI_SENSE_BUFFERSIZE];
        struct bio *bio;
@@ -316,10 +208,7 @@ static int sg_io(struct file *file, struct request_queue *q,
        if (!rq)
                return -ENOMEM;
 
-       if (file)
-               has_write_perm = file->f_mode & FMODE_WRITE;
-
-       if (blk_fill_sghdr_rq(q, rq, hdr, has_write_perm)) {
+       if (blk_fill_sghdr_rq(q, rq, hdr, file)) {
                blk_put_request(rq);
                return -EFAULT;
        }
@@ -451,7 +340,7 @@ int sg_scsi_ioctl(struct file *file, struct request_queue *q,
        if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
                goto error;
 
-       err = blk_verify_command(rq->cmd, file->f_mode & FMODE_WRITE);
+       err = blk_verify_command(file, rq->cmd);
        if (err)
                goto error;
 
index 864456c..ea50357 100644 (file)
@@ -65,6 +65,7 @@ config CRYPTO_NULL
 config CRYPTO_CRYPTD
        tristate "Software async crypto daemon"
        select CRYPTO_BLKCIPHER
+       select CRYPTO_HASH
        select CRYPTO_MANAGER
        help
          This is a generic software asynchronous crypto daemon that
@@ -212,7 +213,7 @@ comment "Digest"
 
 config CRYPTO_CRC32C
        tristate "CRC32c CRC algorithm"
-       select CRYPTO_ALGAPI
+       select CRYPTO_HASH
        select LIBCRC32C
        help
          Castagnoli, et al Cyclic Redundancy-Check Algorithm.  Used
@@ -241,6 +242,57 @@ config CRYPTO_MICHAEL_MIC
          should not be used for other purposes because of the weakness
          of the algorithm.
 
+config CRYPTO_RMD128
+  tristate "RIPEMD-128 digest algorithm"
+  select CRYPTO_ALGAPI
+  help
+    RIPEMD-128 (ISO/IEC 10118-3:2004).
+
+    RIPEMD-128 is a 128-bit cryptographic hash function. It should only
+    to be used as a secure replacement for RIPEMD. For other use cases
+    RIPEMD-160 should be used.
+
+    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+
+config CRYPTO_RMD160
+  tristate "RIPEMD-160 digest algorithm"
+  select CRYPTO_ALGAPI
+  help
+    RIPEMD-160 (ISO/IEC 10118-3:2004).
+
+    RIPEMD-160 is a 160-bit cryptographic hash function. It is intended
+    to be used as a secure replacement for the 128-bit hash functions
+    MD4, MD5 and it's predecessor RIPEMD (not to be confused with RIPEMD-128).
+
+    It's speed is comparable to SHA1 and there are no known attacks against
+    RIPEMD-160.
+
+    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+
+config CRYPTO_RMD256
+  tristate "RIPEMD-256 digest algorithm"
+  select CRYPTO_ALGAPI
+  help
+    RIPEMD-256 is an optional extension of RIPEMD-128 with a 256 bit hash.
+    It is intended for applications that require longer hash-results, without
+    needing a larger security level (than RIPEMD-128).
+
+    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+
+config CRYPTO_RMD320
+  tristate "RIPEMD-320 digest algorithm"
+  select CRYPTO_ALGAPI
+  help
+    RIPEMD-320 is an optional extension of RIPEMD-160 with a 320 bit hash.
+    It is intended for applications that require longer hash-results, without
+    needing a larger security level (than RIPEMD-160).
+
+    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+
 config CRYPTO_SHA1
        tristate "SHA1 digest algorithm"
        select CRYPTO_ALGAPI
@@ -614,6 +666,15 @@ config CRYPTO_LZO
        help
          This is the LZO algorithm.
 
+comment "Random Number Generation"
+
+config CRYPTO_PRNG
+       tristate "Pseudo Random Number Generation for Cryptographic modules"
+       help
+         This option enables the generic pseudo random number generator
+         for cryptographic modules.  Uses the Algorithm specified in
+         ANSI X9.31 A.2.4
+
 source "drivers/crypto/Kconfig"
 
 endif  # if CRYPTO
index ca02441..ef61b3b 100644 (file)
@@ -19,6 +19,7 @@ obj-$(CONFIG_CRYPTO_BLKCIPHER) += crypto_blkcipher.o
 obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
 
 crypto_hash-objs := hash.o
+crypto_hash-objs += ahash.o
 obj-$(CONFIG_CRYPTO_HASH) += crypto_hash.o
 
 obj-$(CONFIG_CRYPTO_MANAGER) += cryptomgr.o
@@ -27,6 +28,10 @@ obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
 obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o
 obj-$(CONFIG_CRYPTO_MD4) += md4.o
 obj-$(CONFIG_CRYPTO_MD5) += md5.o
+obj-$(CONFIG_CRYPTO_RMD128) += rmd128.o
+obj-$(CONFIG_CRYPTO_RMD160) += rmd160.o
+obj-$(CONFIG_CRYPTO_RMD256) += rmd256.o
+obj-$(CONFIG_CRYPTO_RMD320) += rmd320.o
 obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o
 obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o
 obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o
@@ -64,7 +69,7 @@ obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
 obj-$(CONFIG_CRYPTO_LZO) += lzo.o
-
+obj-$(CONFIG_CRYPTO_PRNG) += prng.o
 obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
 
 #
diff --git a/crypto/ahash.c b/crypto/ahash.c
new file mode 100644 (file)
index 0000000..27128f2
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Asynchronous Cryptographic Hash operations.
+ *
+ * This is the asynchronous version of hash.c with notification of
+ * completion via a callback.
+ *
+ * Copyright (c) 2008 Loc Ho <lho@amcc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+#include <crypto/internal/hash.h>
+#include <crypto/scatterwalk.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/seq_file.h>
+
+#include "internal.h"
+
+static int hash_walk_next(struct crypto_hash_walk *walk)
+{
+       unsigned int alignmask = walk->alignmask;
+       unsigned int offset = walk->offset;
+       unsigned int nbytes = min(walk->entrylen,
+                                 ((unsigned int)(PAGE_SIZE)) - offset);
+
+       walk->data = crypto_kmap(walk->pg, 0);
+       walk->data += offset;
+
+       if (offset & alignmask)
+               nbytes = alignmask + 1 - (offset & alignmask);
+
+       walk->entrylen -= nbytes;
+       return nbytes;
+}
+
+static int hash_walk_new_entry(struct crypto_hash_walk *walk)
+{
+       struct scatterlist *sg;
+
+       sg = walk->sg;
+       walk->pg = sg_page(sg);
+       walk->offset = sg->offset;
+       walk->entrylen = sg->length;
+
+       if (walk->entrylen > walk->total)
+               walk->entrylen = walk->total;
+       walk->total -= walk->entrylen;
+
+       return hash_walk_next(walk);
+}
+
+int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
+{
+       unsigned int alignmask = walk->alignmask;
+       unsigned int nbytes = walk->entrylen;
+
+       walk->data -= walk->offset;
+
+       if (nbytes && walk->offset & alignmask && !err) {
+               walk->offset += alignmask - 1;
+               walk->offset = ALIGN(walk->offset, alignmask + 1);
+               walk->data += walk->offset;
+
+               nbytes = min(nbytes,
+                            ((unsigned int)(PAGE_SIZE)) - walk->offset);
+               walk->entrylen -= nbytes;
+
+               return nbytes;
+       }
+
+       crypto_kunmap(walk->data, 0);
+       crypto_yield(walk->flags);
+
+       if (err)
+               return err;
+
+       walk->offset = 0;
+
+       if (nbytes)
+               return hash_walk_next(walk);
+
+       if (!walk->total)
+               return 0;
+
+       walk->sg = scatterwalk_sg_next(walk->sg);
+
+       return hash_walk_new_entry(walk);
+}
+EXPORT_SYMBOL_GPL(crypto_hash_walk_done);
+
+int crypto_hash_walk_first(struct ahash_request *req,
+                          struct crypto_hash_walk *walk)
+{
+       walk->total = req->nbytes;
+
+       if (!walk->total)
+               return 0;
+
+       walk->alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
+       walk->sg = req->src;
+       walk->flags = req->base.flags;
+
+       return hash_walk_new_entry(walk);
+}
+EXPORT_SYMBOL_GPL(crypto_hash_walk_first);
+
+static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
+                               unsigned int keylen)
+{
+       struct ahash_alg *ahash = crypto_ahash_alg(tfm);
+       unsigned long alignmask = crypto_ahash_alignmask(tfm);
+       int ret;
+       u8 *buffer, *alignbuffer;
+       unsigned long absize;
+
+       absize = keylen + alignmask;
+       buffer = kmalloc(absize, GFP_ATOMIC);
+       if (!buffer)
+               return -ENOMEM;
+
+       alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
+       memcpy(alignbuffer, key, keylen);
+       ret = ahash->setkey(tfm, alignbuffer, keylen);
+       memset(alignbuffer, 0, keylen);
+       kfree(buffer);
+       return ret;
+}
+
+static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
+                       unsigned int keylen)
+{
+       struct ahash_alg *ahash = crypto_ahash_alg(tfm);
+       unsigned long alignmask = crypto_ahash_alignmask(tfm);
+
+       if ((unsigned long)key & alignmask)
+               return ahash_setkey_unaligned(tfm, key, keylen);
+
+       return ahash->setkey(tfm, key, keylen);
+}
+
+static unsigned int crypto_ahash_ctxsize(struct crypto_alg *alg, u32 type,
+                                       u32 mask)
+{
+       return alg->cra_ctxsize;
+}
+
+static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+       struct ahash_alg *alg = &tfm->__crt_alg->cra_ahash;
+       struct ahash_tfm *crt   = &tfm->crt_ahash;
+
+       if (alg->digestsize > PAGE_SIZE / 8)
+               return -EINVAL;
+
+       crt->init = alg->init;
+       crt->update = alg->update;
+       crt->final  = alg->final;
+       crt->digest = alg->digest;
+       crt->setkey = ahash_setkey;
+       crt->digestsize = alg->digestsize;
+
+       return 0;
+}
+
+static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
+       __attribute__ ((unused));
+static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
+{
+       seq_printf(m, "type         : ahash\n");
+       seq_printf(m, "async        : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
+                                            "yes" : "no");
+       seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
+       seq_printf(m, "digestsize   : %u\n", alg->cra_hash.digestsize);
+}
+
+const struct crypto_type crypto_ahash_type = {
+       .ctxsize = crypto_ahash_ctxsize,
+       .init = crypto_init_ahash_ops,
+#ifdef CONFIG_PROC_FS
+       .show = crypto_ahash_show,
+#endif
+};
+EXPORT_SYMBOL_GPL(crypto_ahash_type);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Asynchronous cryptographic hash type");
index 0a0f41e..d06e332 100644 (file)
@@ -235,8 +235,12 @@ static int crypto_init_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
                return crypto_init_cipher_ops(tfm);
                
        case CRYPTO_ALG_TYPE_DIGEST:
-               return crypto_init_digest_ops(tfm);
-               
+               if ((mask & CRYPTO_ALG_TYPE_HASH_MASK) !=
+                   CRYPTO_ALG_TYPE_HASH_MASK)
+                       return crypto_init_digest_ops_async(tfm);
+               else
+                       return crypto_init_digest_ops(tfm);
+
        case CRYPTO_ALG_TYPE_COMPRESS:
                return crypto_init_compress_ops(tfm);
        
index 493fee7..b1cc4de 100644 (file)
@@ -35,6 +35,8 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/bitops.h>
+#include <asm/unaligned.h>
 
 static const u32 camellia_sp1110[256] = {
        0x70707000,0x82828200,0x2c2c2c00,0xececec00,
@@ -335,20 +337,6 @@ static const u32 camellia_sp4404[256] = {
 /*
  *  macros
  */
-#define GETU32(v, pt) \
-    do { \
-       /* latest breed of gcc is clever enough to use move */ \
-       memcpy(&(v), (pt), 4); \
-       (v) = be32_to_cpu(v); \
-    } while(0)
-
-/* rotation right shift 1byte */
-#define ROR8(x) (((x) >> 8) + ((x) << 24))
-/* rotation left shift 1bit */
-#define ROL1(x) (((x) << 1) + ((x) >> 31))
-/* rotation left shift 1byte */
-#define ROL8(x) (((x) << 8) + ((x) >> 24))
-
 #define ROLDQ(ll, lr, rl, rr, w0, w1, bits)            \
     do {                                               \
        w0 = ll;                                        \
@@ -383,7 +371,7 @@ static const u32 camellia_sp4404[256] = {
           ^ camellia_sp3033[(u8)(il >> 8)]                     \
           ^ camellia_sp4404[(u8)(il     )];                    \
        yl ^= yr;                                               \
-       yr = ROR8(yr);                                          \
+       yr = ror32(yr, 8);                                      \
        yr ^= yl;                                               \
     } while(0)
 
@@ -405,7 +393,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        subL[7] ^= subL[1]; subR[7] ^= subR[1];
        subL[1] ^= subR[1] & ~subR[9];
        dw = subL[1] & subL[9],
-               subR[1] ^= ROL1(dw); /* modified for FLinv(kl2) */
+               subR[1] ^= rol32(dw, 1); /* modified for FLinv(kl2) */
        /* round 8 */
        subL[11] ^= subL[1]; subR[11] ^= subR[1];
        /* round 10 */
@@ -414,7 +402,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        subL[15] ^= subL[1]; subR[15] ^= subR[1];
        subL[1] ^= subR[1] & ~subR[17];
        dw = subL[1] & subL[17],
-               subR[1] ^= ROL1(dw); /* modified for FLinv(kl4) */
+               subR[1] ^= rol32(dw, 1); /* modified for FLinv(kl4) */
        /* round 14 */
        subL[19] ^= subL[1]; subR[19] ^= subR[1];
        /* round 16 */
@@ -430,7 +418,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        } else {
                subL[1] ^= subR[1] & ~subR[25];
                dw = subL[1] & subL[25],
-                       subR[1] ^= ROL1(dw); /* modified for FLinv(kl6) */
+                       subR[1] ^= rol32(dw, 1); /* modified for FLinv(kl6) */
                /* round 20 */
                subL[27] ^= subL[1]; subR[27] ^= subR[1];
                /* round 22 */
@@ -450,7 +438,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
                subL[26] ^= kw4l; subR[26] ^= kw4r;
                kw4l ^= kw4r & ~subR[24];
                dw = kw4l & subL[24],
-                       kw4r ^= ROL1(dw); /* modified for FL(kl5) */
+                       kw4r ^= rol32(dw, 1); /* modified for FL(kl5) */
        }
        /* round 17 */
        subL[22] ^= kw4l; subR[22] ^= kw4r;
@@ -460,7 +448,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        subL[18] ^= kw4l; subR[18] ^= kw4r;
        kw4l ^= kw4r & ~subR[16];
        dw = kw4l & subL[16],
-               kw4r ^= ROL1(dw); /* modified for FL(kl3) */
+               kw4r ^= rol32(dw, 1); /* modified for FL(kl3) */
        /* round 11 */
        subL[14] ^= kw4l; subR[14] ^= kw4r;
        /* round 9 */
@@ -469,7 +457,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        subL[10] ^= kw4l; subR[10] ^= kw4r;
        kw4l ^= kw4r & ~subR[8];
        dw = kw4l & subL[8],
-               kw4r ^= ROL1(dw); /* modified for FL(kl1) */
+               kw4r ^= rol32(dw, 1); /* modified for FL(kl1) */
        /* round 5 */
        subL[6] ^= kw4l; subR[6] ^= kw4r;
        /* round 3 */
@@ -494,7 +482,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        SUBKEY_R(6) = subR[5] ^ subR[7];
        tl = subL[10] ^ (subR[10] & ~subR[8]);
        dw = tl & subL[8],  /* FL(kl1) */
-               tr = subR[10] ^ ROL1(dw);
+               tr = subR[10] ^ rol32(dw, 1);
        SUBKEY_L(7) = subL[6] ^ tl; /* round 6 */
        SUBKEY_R(7) = subR[6] ^ tr;
        SUBKEY_L(8) = subL[8];       /* FL(kl1) */
@@ -503,7 +491,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        SUBKEY_R(9) = subR[9];
        tl = subL[7] ^ (subR[7] & ~subR[9]);
        dw = tl & subL[9],  /* FLinv(kl2) */
-               tr = subR[7] ^ ROL1(dw);
+               tr = subR[7] ^ rol32(dw, 1);
        SUBKEY_L(10) = tl ^ subL[11]; /* round 7 */
        SUBKEY_R(10) = tr ^ subR[11];
        SUBKEY_L(11) = subL[10] ^ subL[12]; /* round 8 */
@@ -516,7 +504,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        SUBKEY_R(14) = subR[13] ^ subR[15];
        tl = subL[18] ^ (subR[18] & ~subR[16]);
        dw = tl & subL[16], /* FL(kl3) */
-               tr = subR[18] ^ ROL1(dw);
+               tr = subR[18] ^ rol32(dw, 1);
        SUBKEY_L(15) = subL[14] ^ tl; /* round 12 */
        SUBKEY_R(15) = subR[14] ^ tr;
        SUBKEY_L(16) = subL[16];     /* FL(kl3) */
@@ -525,7 +513,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        SUBKEY_R(17) = subR[17];
        tl = subL[15] ^ (subR[15] & ~subR[17]);
        dw = tl & subL[17], /* FLinv(kl4) */
-               tr = subR[15] ^ ROL1(dw);
+               tr = subR[15] ^ rol32(dw, 1);
        SUBKEY_L(18) = tl ^ subL[19]; /* round 13 */
        SUBKEY_R(18) = tr ^ subR[19];
        SUBKEY_L(19) = subL[18] ^ subL[20]; /* round 14 */
@@ -544,7 +532,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        } else {
                tl = subL[26] ^ (subR[26] & ~subR[24]);
                dw = tl & subL[24], /* FL(kl5) */
-                       tr = subR[26] ^ ROL1(dw);
+                       tr = subR[26] ^ rol32(dw, 1);
                SUBKEY_L(23) = subL[22] ^ tl; /* round 18 */
                SUBKEY_R(23) = subR[22] ^ tr;
                SUBKEY_L(24) = subL[24];     /* FL(kl5) */
@@ -553,7 +541,7 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
                SUBKEY_R(25) = subR[25];
                tl = subL[23] ^ (subR[23] & ~subR[25]);
                dw = tl & subL[25], /* FLinv(kl6) */
-                       tr = subR[23] ^ ROL1(dw);
+                       tr = subR[23] ^ rol32(dw, 1);
                SUBKEY_L(26) = tl ^ subL[27]; /* round 19 */
                SUBKEY_R(26) = tr ^ subR[27];
                SUBKEY_L(27) = subL[26] ^ subL[28]; /* round 20 */
@@ -573,17 +561,17 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
        /* apply the inverse of the last half of P-function */
        i = 2;
        do {
-               dw = SUBKEY_L(i + 0) ^ SUBKEY_R(i + 0); dw = ROL8(dw);/* round 1 */
+               dw = SUBKEY_L(i + 0) ^ SUBKEY_R(i + 0); dw = rol32(dw, 8);/* round 1 */
                SUBKEY_R(i + 0) = SUBKEY_L(i + 0) ^ dw; SUBKEY_L(i + 0) = dw;
-               dw = SUBKEY_L(i + 1) ^ SUBKEY_R(i + 1); dw = ROL8(dw);/* round 2 */
+               dw = SUBKEY_L(i + 1) ^ SUBKEY_R(i + 1); dw = rol32(dw, 8);/* round 2 */
                SUBKEY_R(i + 1) = SUBKEY_L(i + 1) ^ dw; SUBKEY_L(i + 1) = dw;
-               dw = SUBKEY_L(i + 2) ^ SUBKEY_R(i + 2); dw = ROL8(dw);/* round 3 */
+               dw = SUBKEY_L(i + 2) ^ SUBKEY_R(i + 2); dw = rol32(dw, 8);/* round 3 */
                SUBKEY_R(i + 2) = SUBKEY_L(i + 2) ^ dw; SUBKEY_L(i + 2) = dw;
-               dw = SUBKEY_L(i + 3) ^ SUBKEY_R(i + 3); dw = ROL8(dw);/* round 4 */
+               dw = SUBKEY_L(i + 3) ^ SUBKEY_R(i + 3); dw = rol32(dw, 8);/* round 4 */
                SUBKEY_R(i + 3) = SUBKEY_L(i + 3) ^ dw; SUBKEY_L(i + 3) = dw;
-               dw = SUBKEY_L(i + 4) ^ SUBKEY_R(i + 4); dw = ROL8(dw);/* round 5 */
+               dw = SUBKEY_L(i + 4) ^ SUBKEY_R(i + 4); dw = rol32(dw, 9);/* round 5 */
                SUBKEY_R(i + 4) = SUBKEY_L(i + 4) ^ dw; SUBKEY_L(i + 4) = dw;
-               dw = SUBKEY_L(i + 5) ^ SUBKEY_R(i + 5); dw = ROL8(dw);/* round 6 */
+               dw = SUBKEY_L(i + 5) ^ SUBKEY_R(i + 5); dw = rol32(dw, 8);/* round 6 */
                SUBKEY_R(i + 5) = SUBKEY_L(i + 5) ^ dw; SUBKEY_L(i + 5) = dw;
                i += 8;
        } while (i < max);
@@ -599,10 +587,10 @@ static void camellia_setup128(const unsigned char *key, u32 *subkey)
        /**
         *  k == kll || klr || krl || krr (|| is concatenation)
         */
-       GETU32(kll, key     );
-       GETU32(klr, key +  4);
-       GETU32(krl, key +  8);
-       GETU32(krr, key + 12);
+       kll = get_unaligned_be32(key);
+       klr = get_unaligned_be32(key + 4);
+       krl = get_unaligned_be32(key + 8);
+       krr = get_unaligned_be32(key + 12);
 
        /* generate KL dependent subkeys */
        /* kw1 */
@@ -707,14 +695,14 @@ static void camellia_setup256(const unsigned char *key, u32 *subkey)
         *  key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
         *  (|| is concatenation)
         */
-       GETU32(kll,  key     );
-       GETU32(klr,  key +  4);
-       GETU32(krl,  key +  8);
-       GETU32(krr,  key + 12);
-       GETU32(krll, key + 16);
-       GETU32(krlr, key + 20);
-       GETU32(krrl, key + 24);
-       GETU32(krrr, key + 28);
+       kll = get_unaligned_be32(key);
+       klr = get_unaligned_be32(key + 4);
+       krl = get_unaligned_be32(key + 8);
+       krr = get_unaligned_be32(key + 12);
+       krll = get_unaligned_be32(key + 16);
+       krlr = get_unaligned_be32(key + 20);
+       krrl = get_unaligned_be32(key + 24);
+       krrr = get_unaligned_be32(key + 28);
 
        /* generate KL dependent subkeys */
        /* kw1 */
@@ -870,13 +858,13 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey)
        t0 &= ll;                                                       \
        t2 |= rr;                                                       \
        rl ^= t2;                                                       \
-       lr ^= ROL1(t0);                                                 \
+       lr ^= rol32(t0, 1);                                             \
        t3 = krl;                                                       \
        t1 = klr;                                                       \
        t3 &= rl;                                                       \
        t1 |= lr;                                                       \
        ll ^= t1;                                                       \
-       rr ^= ROL1(t3);                                                 \
+       rr ^= rol32(t3, 1);                                             \
     } while(0)
 
 #define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir)               \
@@ -892,7 +880,7 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey)
        il ^= kl;                                                       \
        ir ^= il ^ kr;                                                  \
        yl ^= ir;                                                       \
-       yr ^= ROR8(il) ^ ir;                                            \
+       yr ^= ror32(il, 8) ^ ir;                                                \
     } while(0)
 
 /* max = 24: 128bit encrypt, max = 32: 256bit encrypt */
index 0dcf64a..a882d9e 100644 (file)
@@ -5,20 +5,23 @@
  *
  * This module file is a wrapper to invoke the lib/crc32c routines.
  *
+ * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
  * Software Foundation; either version 2 of the License, or (at your option) 
  * any later version.
  *
  */
+
+#include <crypto/internal/hash.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/string.h>
-#include <linux/crypto.h>
 #include <linux/crc32c.h>
 #include <linux/kernel.h>
 
-#define CHKSUM_BLOCK_SIZE      32
+#define CHKSUM_BLOCK_SIZE      1
 #define CHKSUM_DIGEST_SIZE     4
 
 struct chksum_ctx {
@@ -71,7 +74,7 @@ static void chksum_final(struct crypto_tfm *tfm, u8 *out)
        *(__le32 *)out = ~cpu_to_le32(mctx->crc);
 }
 
-static int crc32c_cra_init(struct crypto_tfm *tfm)
+static int crc32c_cra_init_old(struct crypto_tfm *tfm)
 {
        struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
 
@@ -79,14 +82,14 @@ static int crc32c_cra_init(struct crypto_tfm *tfm)
        return 0;
 }
 
-static struct crypto_alg alg = {
+static struct crypto_alg old_alg = {
        .cra_name       =       "crc32c",
        .cra_flags      =       CRYPTO_ALG_TYPE_DIGEST,
        .cra_blocksize  =       CHKSUM_BLOCK_SIZE,
        .cra_ctxsize    =       sizeof(struct chksum_ctx),
        .cra_module     =       THIS_MODULE,
-       .cra_list       =       LIST_HEAD_INIT(alg.cra_list),
-       .cra_init       =       crc32c_cra_init,
+       .cra_list       =       LIST_HEAD_INIT(old_alg.cra_list),
+       .cra_init       =       crc32c_cra_init_old,
        .cra_u          =       {
                .digest = {
                         .dia_digestsize=       CHKSUM_DIGEST_SIZE,
@@ -98,14 +101,125 @@ static struct crypto_alg alg = {
        }
 };
 
+/*
+ * Setting the seed allows arbitrary accumulators and flexible XOR policy
+ * If your algorithm starts with ~0, then XOR with ~0 before you set
+ * the seed.
+ */
+static int crc32c_setkey(struct crypto_ahash *hash, const u8 *key,
+                        unsigned int keylen)
+{
+       u32 *mctx = crypto_ahash_ctx(hash);
+
+       if (keylen != sizeof(u32)) {
+               crypto_ahash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
+               return -EINVAL;
+       }
+       *mctx = le32_to_cpup((__le32 *)key);
+       return 0;
+}
+
+static int crc32c_init(struct ahash_request *req)
+{
+       u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
+       u32 *crcp = ahash_request_ctx(req);
+
+       *crcp = *mctx;
+       return 0;
+}
+
+static int crc32c_update(struct ahash_request *req)
+{
+       struct crypto_hash_walk walk;
+       u32 *crcp = ahash_request_ctx(req);
+       u32 crc = *crcp;
+       int nbytes;
+
+       for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
+            nbytes = crypto_hash_walk_done(&walk, 0))
+               crc = crc32c(crc, walk.data, nbytes);
+
+       *crcp = crc;
+       return 0;
+}
+
+static int crc32c_final(struct ahash_request *req)
+{
+       u32 *crcp = ahash_request_ctx(req);
+       
+       *(__le32 *)req->result = ~cpu_to_le32p(crcp);
+       return 0;
+}
+
+static int crc32c_digest(struct ahash_request *req)
+{
+       struct crypto_hash_walk walk;
+       u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
+       u32 crc = *mctx;
+       int nbytes;
+
+       for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
+            nbytes = crypto_hash_walk_done(&walk, 0))
+               crc = crc32c(crc, walk.data, nbytes);
+
+       *(__le32 *)req->result = ~cpu_to_le32(crc);
+       return 0;
+}
+
+static int crc32c_cra_init(struct crypto_tfm *tfm)
+{
+       u32 *key = crypto_tfm_ctx(tfm);
+
+       *key = ~0;
+
+       tfm->crt_ahash.reqsize = sizeof(u32);
+
+       return 0;
+}
+
+static struct crypto_alg alg = {
+       .cra_name               =       "crc32c",
+       .cra_driver_name        =       "crc32c-generic",
+       .cra_priority           =       100,
+       .cra_flags              =       CRYPTO_ALG_TYPE_AHASH,
+       .cra_blocksize          =       CHKSUM_BLOCK_SIZE,
+       .cra_alignmask          =       3,
+       .cra_ctxsize            =       sizeof(u32),
+       .cra_module             =       THIS_MODULE,
+       .cra_list               =       LIST_HEAD_INIT(alg.cra_list),
+       .cra_init               =       crc32c_cra_init,
+       .cra_type               =       &crypto_ahash_type,
+       .cra_u                  =       {
+               .ahash = {
+                        .digestsize    =       CHKSUM_DIGEST_SIZE,
+                        .setkey        =       crc32c_setkey,
+                        .init          =       crc32c_init,
+                        .update        =       crc32c_update,
+                        .final         =       crc32c_final,
+                        .digest        =       crc32c_digest,
+                }
+       }
+};
+
 static int __init crc32c_mod_init(void)
 {
-       return crypto_register_alg(&alg);
+       int err;
+
+       err = crypto_register_alg(&old_alg);
+       if (err)
+               return err;
+
+       err = crypto_register_alg(&alg);
+       if (err)
+               crypto_unregister_alg(&old_alg);
+
+       return err;
 }
 
 static void __exit crc32c_mod_fini(void)
 {
        crypto_unregister_alg(&alg);
+       crypto_unregister_alg(&old_alg);
 }
 
 module_init(crc32c_mod_init);
index b150de5..d29e06b 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <crypto/algapi.h>
+#include <crypto/internal/hash.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -45,6 +46,13 @@ struct cryptd_blkcipher_request_ctx {
        crypto_completion_t complete;
 };
 
+struct cryptd_hash_ctx {
+       struct crypto_hash *child;
+};
+
+struct cryptd_hash_request_ctx {
+       crypto_completion_t complete;
+};
 
 static inline struct cryptd_state *cryptd_get_state(struct crypto_tfm *tfm)
 {
@@ -82,10 +90,8 @@ static void cryptd_blkcipher_crypt(struct ablkcipher_request *req,
 
        rctx = ablkcipher_request_ctx(req);
 
-       if (unlikely(err == -EINPROGRESS)) {
-               rctx->complete(&req->base, err);
-               return;
-       }
+       if (unlikely(err == -EINPROGRESS))
+               goto out;
 
        desc.tfm = child;
        desc.info = req->info;
@@ -95,8 +101,9 @@ static void cryptd_blkcipher_crypt(struct ablkcipher_request *req,
 
        req->base.complete = rctx->complete;
 
+out:
        local_bh_disable();
-       req->base.complete(&req->base, err);
+       rctx->complete(&req->base, err);
        local_bh_enable();
 }
 
@@ -261,6 +268,240 @@ out_put_alg:
        return inst;
 }
 
+static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
+{
+       struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
+       struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst);
+       struct crypto_spawn *spawn = &ictx->spawn;
+       struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct crypto_hash *cipher;
+
+       cipher = crypto_spawn_hash(spawn);
+       if (IS_ERR(cipher))
+               return PTR_ERR(cipher);
+
+       ctx->child = cipher;
+       tfm->crt_ahash.reqsize =
+               sizeof(struct cryptd_hash_request_ctx);
+       return 0;
+}
+
+static void cryptd_hash_exit_tfm(struct crypto_tfm *tfm)
+{
+       struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct cryptd_state *state = cryptd_get_state(tfm);
+       int active;
+
+       mutex_lock(&state->mutex);
+       active = ahash_tfm_in_queue(&state->queue,
+                               __crypto_ahash_cast(tfm));
+       mutex_unlock(&state->mutex);
+
+       BUG_ON(active);
+
+       crypto_free_hash(ctx->child);
+}
+
+static int cryptd_hash_setkey(struct crypto_ahash *parent,
+                                  const u8 *key, unsigned int keylen)
+{
+       struct cryptd_hash_ctx *ctx   = crypto_ahash_ctx(parent);
+       struct crypto_hash     *child = ctx->child;
+       int err;
+
+       crypto_hash_clear_flags(child, CRYPTO_TFM_REQ_MASK);
+       crypto_hash_set_flags(child, crypto_ahash_get_flags(parent) &
+                                         CRYPTO_TFM_REQ_MASK);
+       err = crypto_hash_setkey(child, key, keylen);
+       crypto_ahash_set_flags(parent, crypto_hash_get_flags(child) &
+                                           CRYPTO_TFM_RES_MASK);
+       return err;
+}
+
+static int cryptd_hash_enqueue(struct ahash_request *req,
+                               crypto_completion_t complete)
+{
+       struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
+       struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+       struct cryptd_state *state =
+               cryptd_get_state(crypto_ahash_tfm(tfm));
+       int err;
+
+       rctx->complete = req->base.complete;
+       req->base.complete = complete;
+
+       spin_lock_bh(&state->lock);
+       err = ahash_enqueue_request(&state->queue, req);
+       spin_unlock_bh(&state->lock);
+
+       wake_up_process(state->task);
+       return err;
+}
+
+static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
+{
+       struct cryptd_hash_ctx *ctx   = crypto_tfm_ctx(req_async->tfm);
+       struct crypto_hash     *child = ctx->child;
+       struct ahash_request    *req = ahash_request_cast(req_async);
+       struct cryptd_hash_request_ctx *rctx;
+       struct hash_desc desc;
+
+       rctx = ahash_request_ctx(req);
+
+       if (unlikely(err == -EINPROGRESS))
+               goto out;
+
+       desc.tfm = child;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_crt(child)->init(&desc);
+
+       req->base.complete = rctx->complete;
+
+out:
+       local_bh_disable();
+       rctx->complete(&req->base, err);
+       local_bh_enable();
+}
+
+static int cryptd_hash_init_enqueue(struct ahash_request *req)
+{
+       return cryptd_hash_enqueue(req, cryptd_hash_init);
+}
+
+static void cryptd_hash_update(struct crypto_async_request *req_async, int err)
+{
+       struct cryptd_hash_ctx *ctx   = crypto_tfm_ctx(req_async->tfm);
+       struct crypto_hash     *child = ctx->child;
+       struct ahash_request    *req = ahash_request_cast(req_async);
+       struct cryptd_hash_request_ctx *rctx;
+       struct hash_desc desc;
+
+       rctx = ahash_request_ctx(req);
+
+       if (unlikely(err == -EINPROGRESS))
+               goto out;
+
+       desc.tfm = child;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_crt(child)->update(&desc,
+                                               req->src,
+                                               req->nbytes);
+
+       req->base.complete = rctx->complete;
+
+out:
+       local_bh_disable();
+       rctx->complete(&req->base, err);
+       local_bh_enable();
+}
+
+static int cryptd_hash_update_enqueue(struct ahash_request *req)
+{
+       return cryptd_hash_enqueue(req, cryptd_hash_update);
+}
+
+static void cryptd_hash_final(struct crypto_async_request *req_async, int err)
+{
+       struct cryptd_hash_ctx *ctx   = crypto_tfm_ctx(req_async->tfm);
+       struct crypto_hash     *child = ctx->child;
+       struct ahash_request    *req = ahash_request_cast(req_async);
+       struct cryptd_hash_request_ctx *rctx;
+       struct hash_desc desc;
+
+       rctx = ahash_request_ctx(req);
+
+       if (unlikely(err == -EINPROGRESS))
+               goto out;
+
+       desc.tfm = child;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_crt(child)->final(&desc, req->result);
+
+       req->base.complete = rctx->complete;
+
+out:
+       local_bh_disable();
+       rctx->complete(&req->base, err);
+       local_bh_enable();
+}
+
+static int cryptd_hash_final_enqueue(struct ahash_request *req)
+{
+       return cryptd_hash_enqueue(req, cryptd_hash_final);
+}
+
+static void cryptd_hash_digest(struct crypto_async_request *req_async, int err)
+{
+       struct cryptd_hash_ctx *ctx   = crypto_tfm_ctx(req_async->tfm);
+       struct crypto_hash     *child = ctx->child;
+       struct ahash_request    *req = ahash_request_cast(req_async);
+       struct cryptd_hash_request_ctx *rctx;
+       struct hash_desc desc;
+
+       rctx = ahash_request_ctx(req);
+
+       if (unlikely(err == -EINPROGRESS))
+               goto out;
+
+       desc.tfm = child;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_crt(child)->digest(&desc,
+                                               req->src,
+                                               req->nbytes,
+                                               req->result);
+
+       req->base.complete = rctx->complete;
+
+out:
+       local_bh_disable();
+       rctx->complete(&req->base, err);
+       local_bh_enable();
+}
+
+static int cryptd_hash_digest_enqueue(struct ahash_request *req)
+{
+       return cryptd_hash_enqueue(req, cryptd_hash_digest);
+}
+
+static struct crypto_instance *cryptd_alloc_hash(
+       struct rtattr **tb, struct cryptd_state *state)
+{
+       struct crypto_instance *inst;
+       struct crypto_alg *alg;
+
+       alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_HASH,
+                                 CRYPTO_ALG_TYPE_HASH_MASK);
+       if (IS_ERR(alg))
+               return ERR_PTR(PTR_ERR(alg));
+
+       inst = cryptd_alloc_instance(alg, state);
+       if (IS_ERR(inst))
+               goto out_put_alg;
+
+       inst->alg.cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC;
+       inst->alg.cra_type = &crypto_ahash_type;
+
+       inst->alg.cra_ahash.digestsize = alg->cra_hash.digestsize;
+       inst->alg.cra_ctxsize = sizeof(struct cryptd_hash_ctx);
+
+       inst->alg.cra_init = cryptd_hash_init_tfm;
+       inst->alg.cra_exit = cryptd_hash_exit_tfm;
+
+       inst->alg.cra_ahash.init   = cryptd_hash_init_enqueue;
+       inst->alg.cra_ahash.update = cryptd_hash_update_enqueue;
+       inst->alg.cra_ahash.final  = cryptd_hash_final_enqueue;
+       inst->alg.cra_ahash.setkey = cryptd_hash_setkey;
+       inst->alg.cra_ahash.digest = cryptd_hash_digest_enqueue;
+
+out_put_alg:
+       crypto_mod_put(alg);
+       return inst;
+}
+
 static struct cryptd_state state;
 
 static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
@@ -274,6 +515,8 @@ static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
        switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
        case CRYPTO_ALG_TYPE_BLKCIPHER:
                return cryptd_alloc_blkcipher(tb, &state);
+       case CRYPTO_ALG_TYPE_DIGEST:
+               return cryptd_alloc_hash(tb, &state);
        }
 
        return ERR_PTR(-EINVAL);
index b526cc3..ac09194 100644 (file)
@@ -12,6 +12,7 @@
  *
  */
 
+#include <crypto/internal/hash.h>
 #include <crypto/scatterwalk.h>
 #include <linux/mm.h>
 #include <linux/errno.h>
@@ -141,7 +142,7 @@ int crypto_init_digest_ops(struct crypto_tfm *tfm)
        struct hash_tfm *ops = &tfm->crt_hash;
        struct digest_alg *dalg = &tfm->__crt_alg->cra_digest;
 
-       if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm))
+       if (dalg->dia_digestsize > PAGE_SIZE / 8)
                return -EINVAL;
        
        ops->init       = init;
@@ -157,3 +158,83 @@ int crypto_init_digest_ops(struct crypto_tfm *tfm)
 void crypto_exit_digest_ops(struct crypto_tfm *tfm)
 {
 }
+
+static int digest_async_nosetkey(struct crypto_ahash *tfm_async, const u8 *key,
+                       unsigned int keylen)
+{
+       crypto_ahash_clear_flags(tfm_async, CRYPTO_TFM_RES_MASK);
+       return -ENOSYS;
+}
+
+static int digest_async_setkey(struct crypto_ahash *tfm_async, const u8 *key,
+                       unsigned int keylen)
+{
+       struct crypto_tfm    *tfm        = crypto_ahash_tfm(tfm_async);
+       struct digest_alg    *dalg       = &tfm->__crt_alg->cra_digest;
+
+       crypto_ahash_clear_flags(tfm_async, CRYPTO_TFM_RES_MASK);
+       return dalg->dia_setkey(tfm, key, keylen);
+}
+
+static int digest_async_init(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm  = req->base.tfm;
+       struct digest_alg *dalg = &tfm->__crt_alg->cra_digest;
+
+       dalg->dia_init(tfm);
+       return 0;
+}
+
+static int digest_async_update(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm = req->base.tfm;
+       struct hash_desc  desc = {
+               .tfm   = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       update(&desc, req->src, req->nbytes);
+       return 0;
+}
+
+static int digest_async_final(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm  = req->base.tfm;
+       struct hash_desc  desc = {
+               .tfm   = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       final(&desc, req->result);
+       return 0;
+}
+
+static int digest_async_digest(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm  = req->base.tfm;
+       struct hash_desc  desc = {
+               .tfm   = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       return digest(&desc, req->src, req->nbytes, req->result);
+}
+
+int crypto_init_digest_ops_async(struct crypto_tfm *tfm)
+{
+       struct ahash_tfm  *crt  = &tfm->crt_ahash;
+       struct digest_alg *dalg = &tfm->__crt_alg->cra_digest;
+
+       if (dalg->dia_digestsize > crypto_tfm_alg_blocksize(tfm))
+               return -EINVAL;
+
+       crt->init       = digest_async_init;
+       crt->update     = digest_async_update;
+       crt->final      = digest_async_final;
+       crt->digest     = digest_async_digest;
+       crt->setkey     = dalg->dia_setkey ? digest_async_setkey :
+                                               digest_async_nosetkey;
+       crt->digestsize = dalg->dia_digestsize;
+
+       return 0;
+}
index 7dcff67..cb86b19 100644 (file)
@@ -9,6 +9,7 @@
  * any later version.
  */
 
+#include <crypto/internal/hash.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -59,24 +60,107 @@ static int hash_setkey(struct crypto_hash *crt, const u8 *key,
        return alg->setkey(crt, key, keylen);
 }
 
-static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
+static int hash_async_setkey(struct crypto_ahash *tfm_async, const u8 *key,
+                       unsigned int keylen)
+{
+       struct crypto_tfm  *tfm      = crypto_ahash_tfm(tfm_async);
+       struct crypto_hash *tfm_hash = __crypto_hash_cast(tfm);
+       struct hash_alg    *alg      = &tfm->__crt_alg->cra_hash;
+
+       return alg->setkey(tfm_hash, key, keylen);
+}
+
+static int hash_async_init(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm = req->base.tfm;
+       struct hash_alg   *alg = &tfm->__crt_alg->cra_hash;
+       struct hash_desc  desc = {
+               .tfm = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       return alg->init(&desc);
+}
+
+static int hash_async_update(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm = req->base.tfm;
+       struct hash_alg   *alg = &tfm->__crt_alg->cra_hash;
+       struct hash_desc  desc = {
+               .tfm = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       return alg->update(&desc, req->src, req->nbytes);
+}
+
+static int hash_async_final(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm = req->base.tfm;
+       struct hash_alg   *alg = &tfm->__crt_alg->cra_hash;
+       struct hash_desc  desc = {
+               .tfm = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       return alg->final(&desc, req->result);
+}
+
+static int hash_async_digest(struct ahash_request *req)
+{
+       struct crypto_tfm *tfm = req->base.tfm;
+       struct hash_alg   *alg = &tfm->__crt_alg->cra_hash;
+       struct hash_desc  desc = {
+               .tfm = __crypto_hash_cast(tfm),
+               .flags = req->base.flags,
+       };
+
+       return alg->digest(&desc, req->src, req->nbytes, req->result);
+}
+
+static int crypto_init_hash_ops_async(struct crypto_tfm *tfm)
+{
+       struct ahash_tfm *crt = &tfm->crt_ahash;
+       struct hash_alg  *alg = &tfm->__crt_alg->cra_hash;
+
+       crt->init       = hash_async_init;
+       crt->update     = hash_async_update;
+       crt->final      = hash_async_final;
+       crt->digest     = hash_async_digest;
+       crt->setkey     = hash_async_setkey;
+       crt->digestsize = alg->digestsize;
+
+       return 0;
+}
+
+static int crypto_init_hash_ops_sync(struct crypto_tfm *tfm)
 {
        struct hash_tfm *crt = &tfm->crt_hash;
        struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
 
-       if (alg->digestsize > crypto_tfm_alg_blocksize(tfm))
-               return -EINVAL;
-
-       crt->init = alg->init;
-       crt->update = alg->update;
-       crt->final = alg->final;
-       crt->digest = alg->digest;
-       crt->setkey = hash_setkey;
+       crt->init       = alg->init;
+       crt->update     = alg->update;
+       crt->final      = alg->final;
+       crt->digest     = alg->digest;
+       crt->setkey     = hash_setkey;
        crt->digestsize = alg->digestsize;
 
        return 0;
 }
 
+static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+       struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
+
+       if (alg->digestsize > PAGE_SIZE / 8)
+               return -EINVAL;
+
+       if ((mask & CRYPTO_ALG_TYPE_HASH_MASK) != CRYPTO_ALG_TYPE_HASH_MASK)
+               return crypto_init_hash_ops_async(tfm);
+       else
+               return crypto_init_hash_ops_sync(tfm);
+}
+
 static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
        __attribute__ ((unused));
 static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
index 14c6351..7ff2d6a 100644 (file)
@@ -226,6 +226,7 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb)
        struct crypto_instance *inst;
        struct crypto_alg *alg;
        int err;
+       int ds;
 
        err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH);
        if (err)
@@ -236,6 +237,13 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb)
        if (IS_ERR(alg))
                return ERR_CAST(alg);
 
+       inst = ERR_PTR(-EINVAL);
+       ds = (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
+            CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize :
+                                   alg->cra_digest.dia_digestsize;
+       if (ds > alg->cra_blocksize)
+               goto out_put_alg;
+
        inst = crypto_alloc_instance("hmac", alg);
        if (IS_ERR(inst))
                goto out_put_alg;
@@ -246,14 +254,10 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb)
        inst->alg.cra_alignmask = alg->cra_alignmask;
        inst->alg.cra_type = &crypto_hash_type;
 
-       inst->alg.cra_hash.digestsize =
-               (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
-               CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize :
-                                      alg->cra_digest.dia_digestsize;
+       inst->alg.cra_hash.digestsize = ds;
 
        inst->alg.cra_ctxsize = sizeof(struct hmac_ctx) +
-                               ALIGN(inst->alg.cra_blocksize * 2 +
-                                     inst->alg.cra_hash.digestsize,
+                               ALIGN(inst->alg.cra_blocksize * 2 + ds,
                                      sizeof(void *));
 
        inst->alg.cra_init = hmac_init_tfm;
index 32f4c21..683fcb2 100644 (file)
@@ -86,6 +86,7 @@ struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask);
 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
 
 int crypto_init_digest_ops(struct crypto_tfm *tfm);
+int crypto_init_digest_ops_async(struct crypto_tfm *tfm);
 int crypto_init_cipher_ops(struct crypto_tfm *tfm);
 int crypto_init_compress_ops(struct crypto_tfm *tfm);
 
diff --git a/crypto/prng.c b/crypto/prng.c
new file mode 100644 (file)
index 0000000..24e4f32
--- /dev/null
@@ -0,0 +1,410 @@
+/*
+ * PRNG: Pseudo Random Number Generator
+ *       Based on NIST Recommended PRNG From ANSI X9.31 Appendix A.2.4 using
+ *       AES 128 cipher in RFC3686 ctr mode
+ *
+ *  (C) Neil Horman <nhorman@tuxdriver.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or (at your
+ *  any later version.
+ *
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/scatterlist.h>
+#include <linux/string.h>
+#include <linux/crypto.h>
+#include <linux/highmem.h>
+#include <linux/moduleparam.h>
+#include <linux/jiffies.h>
+#include <linux/timex.h>
+#include <linux/interrupt.h>
+#include <linux/miscdevice.h>
+#include "prng.h"
+
+#define TEST_PRNG_ON_START 0
+
+#define DEFAULT_PRNG_KEY "0123456789abcdef1011"
+#define DEFAULT_PRNG_KSZ 20
+#define DEFAULT_PRNG_IV "defaultv"
+#define DEFAULT_PRNG_IVSZ 8
+#define DEFAULT_BLK_SZ 16
+#define DEFAULT_V_SEED "zaybxcwdveuftgsh"
+
+/*
+ * Flags for the prng_context flags field
+ */
+
+#define PRNG_FIXED_SIZE 0x1
+#define PRNG_NEED_RESET 0x2
+
+/*
+ * Note: DT is our counter value
+ *      I is our intermediate value
+ *      V is our seed vector
+ * See http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
+ * for implementation details
+ */
+
+
+struct prng_context {
+       char *prng_key;
+       char *prng_iv;
+       spinlock_t prng_lock;
+       unsigned char rand_data[DEFAULT_BLK_SZ];
+       unsigned char last_rand_data[DEFAULT_BLK_SZ];
+       unsigned char DT[DEFAULT_BLK_SZ];
+       unsigned char I[DEFAULT_BLK_SZ];
+       unsigned char V[DEFAULT_BLK_SZ];
+       u32 rand_data_valid;
+       struct crypto_blkcipher *tfm;
+       u32 flags;
+};
+
+static int dbg;
+
+static void hexdump(char *note, unsigned char *buf, unsigned int len)
+{
+       if (dbg) {
+               printk(KERN_CRIT "%s", note);
+               print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+                               16, 1,
+                               buf, len, false);
+       }
+}
+
+#define dbgprint(format, args...) do {if(dbg) printk(format, ##args);} while(0)
+
+static void xor_vectors(unsigned char *in1, unsigned char *in2,
+                       unsigned char *out, unsigned int size)
+{
+       int i;
+
+       for (i=0;i<size;i++)
+               out[i] = in1[i] ^ in2[i];
+
+}
+/*
+ * Returns DEFAULT_BLK_SZ bytes of random data per call
+ * returns 0 if generation succeded, <0 if something went wrong
+ */
+static int _get_more_prng_bytes(struct prng_context *ctx)
+{
+       int i;
+       struct blkcipher_desc desc;
+       struct scatterlist sg_in, sg_out;
+       int ret;
+       unsigned char tmp[DEFAULT_BLK_SZ];
+
+       desc.tfm = ctx->tfm;
+       desc.flags = 0;
+
+
+       dbgprint(KERN_CRIT "Calling _get_more_prng_bytes for context %p\n",ctx);
+
+       hexdump("Input DT: ", ctx->DT, DEFAULT_BLK_SZ);
+       hexdump("Input I: ", ctx->I, DEFAULT_BLK_SZ);
+       hexdump("Input V: ", ctx->V, DEFAULT_BLK_SZ);
+
+       /*
+        * This algorithm is a 3 stage state machine
+        */
+       for (i=0;i<3;i++) {
+
+               desc.tfm = ctx->tfm;
+               desc.flags = 0;
+               switch (i) {
+                       case 0:
+                               /*
+                                * Start by encrypting the counter value
+                                * This gives us an intermediate value I
+                                */
+                               memcpy(tmp, ctx->DT, DEFAULT_BLK_SZ);
+                               sg_init_one(&sg_out, &ctx->I[0], DEFAULT_BLK_SZ);
+                               hexdump("tmp stage 0: ", tmp, DEFAULT_BLK_SZ);
+                               break;
+                       case 1:
+
+                               /*
+                                * Next xor I with our secret vector V
+                                * encrypt that result to obtain our
+                                * pseudo random data which we output
+                                */
+                               xor_vectors(ctx->I, ctx->V, tmp, DEFAULT_BLK_SZ);
+                               sg_init_one(&sg_out, &ctx->rand_data[0], DEFAULT_BLK_SZ);
+                               hexdump("tmp stage 1: ", tmp, DEFAULT_BLK_SZ);
+                               break;
+                       case 2:
+                               /*
+                                * First check that we didn't produce the same random data
+                                * that we did last time around through this
+                                */
+                               if (!memcmp(ctx->rand_data, ctx->last_rand_data, DEFAULT_BLK_SZ)) {
+                                       printk(KERN_ERR "ctx %p Failed repetition check!\n",
+                                               ctx);
+                                       ctx->flags |= PRNG_NEED_RESET;
+                                       return -1;
+                               }
+                               memcpy(ctx->last_rand_data, ctx->rand_data, DEFAULT_BLK_SZ);
+
+                               /*
+                                * Lastly xor the random data with I
+                                * and encrypt that to obtain a new secret vector V
+                                */
+                               xor_vectors(ctx->rand_data, ctx->I, tmp, DEFAULT_BLK_SZ);
+                               sg_init_one(&sg_out, &ctx->V[0], DEFAULT_BLK_SZ);
+                               hexdump("tmp stage 2: ", tmp, DEFAULT_BLK_SZ);
+                               break;
+               }
+
+               /* Initialize our input buffer */
+               sg_init_one(&sg_in, &tmp[0], DEFAULT_BLK_SZ);
+
+               /* do the encryption */
+               ret = crypto_blkcipher_encrypt(&desc, &sg_out, &sg_in, DEFAULT_BLK_SZ);
+
+               /* And check the result */
+               if (ret) {
+                       dbgprint(KERN_CRIT "Encryption of new block failed for context %p\n",ctx);
+                       ctx->rand_data_valid = DEFAULT_BLK_SZ;
+                       return -1;
+               }
+
+       }
+
+       /*
+        * Now update our DT value
+        */
+       for (i=DEFAULT_BLK_SZ-1;i>0;i--) {
+               ctx->DT[i] = ctx->DT[i-1];
+       }
+       ctx->DT[0] += 1;
+
+       dbgprint("Returning new block for context %p\n",ctx);
+       ctx->rand_data_valid = 0;
+
+       hexdump("Output DT: ", ctx->DT, DEFAULT_BLK_SZ);
+       hexdump("Output I: ", ctx->I, DEFAULT_BLK_SZ);
+       hexdump("Output V: ", ctx->V, DEFAULT_BLK_SZ);
+       hexdump("New Random Data: ", ctx->rand_data, DEFAULT_BLK_SZ);
+
+       return 0;
+}
+
+/* Our exported functions */
+int get_prng_bytes(char *buf, int nbytes, struct prng_context *ctx)
+{
+       unsigned long flags;
+       unsigned char *ptr = buf;
+       unsigned int byte_count = (unsigned int)nbytes;
+       int err;
+
+
+       if (nbytes < 0)
+               return -EINVAL;
+
+       spin_lock_irqsave(&ctx->prng_lock, flags);
+
+       err = -EFAULT;
+       if (ctx->flags & PRNG_NEED_RESET)
+               goto done;
+
+       /*
+        * If the FIXED_SIZE flag is on, only return whole blocks of
+        * pseudo random data
+        */
+       err = -EINVAL;
+       if (ctx->flags & PRNG_FIXED_SIZE) {
+               if (nbytes < DEFAULT_BLK_SZ)
+                       goto done;
+               byte_count = DEFAULT_BLK_SZ;
+       }
+
+       err = byte_count;
+
+       dbgprint(KERN_CRIT "getting %d random bytes for context %p\n",byte_count, ctx);
+
+
+remainder:
+       if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
+               if (_get_more_prng_bytes(ctx) < 0) {
+                       memset(buf, 0, nbytes);
+                       err = -EFAULT;
+                       goto done;
+               }
+       }
+
+       /*
+        * Copy up to the next whole block size
+        */
+       if (byte_count < DEFAULT_BLK_SZ) {
+               for (;ctx->rand_data_valid < DEFAULT_BLK_SZ; ctx->rand_data_valid++) {
+                       *ptr = ctx->rand_data[ctx->rand_data_valid];
+                       ptr++;
+                       byte_count--;
+                       if (byte_count == 0)
+                               goto done;
+               }
+       }
+
+       /*
+        * Now copy whole blocks
+        */
+       for(;byte_count >= DEFAULT_BLK_SZ; byte_count -= DEFAULT_BLK_SZ) {
+               if (_get_more_prng_bytes(ctx) < 0) {
+                       memset(buf, 0, nbytes);
+                       err = -1;
+                       goto done;
+               }
+               memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ);
+               ctx->rand_data_valid += DEFAULT_BLK_SZ;
+               ptr += DEFAULT_BLK_SZ;
+       }
+
+       /*
+        * Now copy any extra partial data
+        */
+       if (byte_count)
+               goto remainder;
+
+done:
+       spin_unlock_irqrestore(&ctx->prng_lock, flags);
+       dbgprint(KERN_CRIT "returning %d from get_prng_bytes in context %p\n",err, ctx);
+       return err;
+}
+EXPORT_SYMBOL_GPL(get_prng_bytes);
+
+struct prng_context *alloc_prng_context(void)
+{
+       struct prng_context *ctx=kzalloc(sizeof(struct prng_context), GFP_KERNEL);
+
+       spin_lock_init(&ctx->prng_lock);
+
+       if (reset_prng_context(ctx, NULL, NULL, NULL, NULL)) {
+               kfree(ctx);
+               ctx = NULL;
+       }
+
+       dbgprint(KERN_CRIT "returning context %p\n",ctx);
+       return ctx;
+}
+
+EXPORT_SYMBOL_GPL(alloc_prng_context);
+
+void free_prng_context(struct prng_context *ctx)
+{
+       crypto_free_blkcipher(ctx->tfm);
+       kfree(ctx);
+}
+EXPORT_SYMBOL_GPL(free_prng_context);
+
+int reset_prng_context(struct prng_context *ctx,
+                      unsigned char *key, unsigned char *iv,
+                      unsigned char *V, unsigned char *DT)
+{
+       int ret;
+       int iv_len;
+       int rc = -EFAULT;
+
+       spin_lock(&ctx->prng_lock);
+       ctx->flags |= PRNG_NEED_RESET;
+
+       if (key)
+               memcpy(ctx->prng_key,key,strlen(ctx->prng_key));
+       else
+               ctx->prng_key = DEFAULT_PRNG_KEY;
+
+       if (iv)
+               memcpy(ctx->prng_iv,iv, strlen(ctx->prng_iv));
+       else
+               ctx->prng_iv = DEFAULT_PRNG_IV;
+
+       if (V)
+               memcpy(ctx->V,V,DEFAULT_BLK_SZ);
+       else
+               memcpy(ctx->V,DEFAULT_V_SEED,DEFAULT_BLK_SZ);
+
+       if (DT)
+               memcpy(ctx->DT, DT, DEFAULT_BLK_SZ);
+       else
+               memset(ctx->DT, 0, DEFAULT_BLK_SZ);
+
+       memset(ctx->rand_data,0,DEFAULT_BLK_SZ);
+       memset(ctx->last_rand_data,0,DEFAULT_BLK_SZ);
+
+       if (ctx->tfm)
+               crypto_free_blkcipher(ctx->tfm);
+
+       ctx->tfm = crypto_alloc_blkcipher("rfc3686(ctr(aes))",0,0);
+       if (!ctx->tfm) {
+               dbgprint(KERN_CRIT "Failed to alloc crypto tfm for context %p\n",ctx->tfm);
+               goto out;
+       }
+
+       ctx->rand_data_valid = DEFAULT_BLK_SZ;
+
+       ret = crypto_blkcipher_setkey(ctx->tfm, ctx->prng_key, strlen(ctx->prng_key));
+       if (ret) {
+               dbgprint(KERN_CRIT "PRNG: setkey() failed flags=%x\n",
+                       crypto_blkcipher_get_flags(ctx->tfm));
+               crypto_free_blkcipher(ctx->tfm);
+               goto out;
+       }
+
+       iv_len = crypto_blkcipher_ivsize(ctx->tfm);
+       if (iv_len) {
+               crypto_blkcipher_set_iv(ctx->tfm, ctx->prng_iv, iv_len);
+       }
+       rc = 0;
+       ctx->flags &= ~PRNG_NEED_RESET;
+out:
+       spin_unlock(&ctx->prng_lock);
+
+       return rc;
+
+}
+EXPORT_SYMBOL_GPL(reset_prng_context);
+
+/* Module initalization */
+static int __init prng_mod_init(void)
+{
+
+#ifdef TEST_PRNG_ON_START
+       int i;
+       unsigned char tmpbuf[DEFAULT_BLK_SZ];
+
+       struct prng_context *ctx = alloc_prng_context();
+       if (ctx == NULL)
+               return -EFAULT;
+       for (i=0;i<16;i++) {
+               if (get_prng_bytes(tmpbuf, DEFAULT_BLK_SZ, ctx) < 0) {
+                       free_prng_context(ctx);
+                       return -EFAULT;
+               }
+       }
+       free_prng_context(ctx);
+#endif
+
+       return 0;
+}
+
+static void __exit prng_mod_fini(void)
+{
+       return;
+}
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Software Pseudo Random Number Generator");
+MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
+module_param(dbg, int, 0);
+MODULE_PARM_DESC(dbg, "Boolean to enable debugging (0/1 == off/on)");
+module_init(prng_mod_init);
+module_exit(prng_mod_fini);
diff --git a/crypto/prng.h b/crypto/prng.h
new file mode 100644 (file)
index 0000000..1ac9be5
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * PRNG: Pseudo Random Number Generator
+ *
+ *  (C) Neil Horman <nhorman@tuxdriver.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or (at your
+ *  any later version.
+ *
+ *
+ */
+
+#ifndef _PRNG_H_
+#define _PRNG_H_
+struct prng_context;
+
+int get_prng_bytes(char *buf, int nbytes, struct prng_context *ctx);
+struct prng_context *alloc_prng_context(void);
+int reset_prng_context(struct prng_context *ctx,
+                       unsigned char *key, unsigned char *iv,
+                       unsigned char *V,
+                       unsigned char *DT);
+void free_prng_context(struct prng_context *ctx);
+
+#endif
+
diff --git a/crypto/ripemd.h b/crypto/ripemd.h
new file mode 100644 (file)
index 0000000..c57a2d4
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Common values for RIPEMD algorithms
+ */
+
+#ifndef _CRYPTO_RMD_H
+#define _CRYPTO_RMD_H
+
+#define RMD128_DIGEST_SIZE      16
+#define RMD128_BLOCK_SIZE       64
+
+#define RMD160_DIGEST_SIZE      20
+#define RMD160_BLOCK_SIZE       64
+
+#define RMD256_DIGEST_SIZE      32
+#define RMD256_BLOCK_SIZE       64
+
+#define RMD320_DIGEST_SIZE      40
+#define RMD320_BLOCK_SIZE       64
+
+/* initial values  */
+#define RMD_H0  0x67452301UL
+#define RMD_H1  0xefcdab89UL
+#define RMD_H2  0x98badcfeUL
+#define RMD_H3  0x10325476UL
+#define RMD_H4  0xc3d2e1f0UL
+#define RMD_H5  0x76543210UL
+#define RMD_H6  0xfedcba98UL
+#define RMD_H7  0x89abcdefUL
+#define RMD_H8  0x01234567UL
+#define RMD_H9  0x3c2d1e0fUL
+
+/* constants */
+#define RMD_K1  0x00000000UL
+#define RMD_K2  0x5a827999UL
+#define RMD_K3  0x6ed9eba1UL
+#define RMD_K4  0x8f1bbcdcUL
+#define RMD_K5  0xa953fd4eUL
+#define RMD_K6  0x50a28be6UL
+#define RMD_K7  0x5c4dd124UL
+#define RMD_K8  0x6d703ef3UL
+#define RMD_K9  0x7a6d76e9UL
+
+#endif
diff --git a/crypto/rmd128.c b/crypto/rmd128.c
new file mode 100644 (file)
index 0000000..5de6fa2
--- /dev/null
@@ -0,0 +1,325 @@
+/*
+ * Cryptographic API.
+ *
+ * RIPEMD-128 - RACE Integrity Primitives Evaluation Message Digest.
+ *
+ * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
+ *
+ * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/crypto.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#include "ripemd.h"
+
+struct rmd128_ctx {
+       u64 byte_count;
+       u32 state[4];
+       __le32 buffer[16];
+};
+
+#define K1  RMD_K1
+#define K2  RMD_K2
+#define K3  RMD_K3
+#define K4  RMD_K4
+#define KK1 RMD_K6
+#define KK2 RMD_K7
+#define KK3 RMD_K8
+#define KK4 RMD_K1
+
+#define F1(x, y, z) (x ^ y ^ z)                /* XOR */
+#define F2(x, y, z) (z ^ (x & (y ^ z)))        /* x ? y : z */
+#define F3(x, y, z) ((x | ~y) ^ z)
+#define F4(x, y, z) (y ^ (z & (x ^ y)))        /* z ? x : y */
+
+#define ROUND(a, b, c, d, f, k, x, s)  { \
+       (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k);     \
+       (a) = rol32((a), (s)); \
+}
+
+static void rmd128_transform(u32 *state, const __le32 *in)
+{
+       u32 aa, bb, cc, dd, aaa, bbb, ccc, ddd;
+
+       /* Initialize left lane */
+       aa = state[0];
+       bb = state[1];
+       cc = state[2];
+       dd = state[3];
+
+       /* Initialize right lane */
+       aaa = state[0];
+       bbb = state[1];
+       ccc = state[2];
+       ddd = state[3];
+
+       /* round 1: left lane */
+       ROUND(aa, bb, cc, dd, F1, K1, in[0],  11);
+       ROUND(dd, aa, bb, cc, F1, K1, in[1],  14);
+       ROUND(cc, dd, aa, bb, F1, K1, in[2],  15);
+       ROUND(bb, cc, dd, aa, F1, K1, in[3],  12);
+       ROUND(aa, bb, cc, dd, F1, K1, in[4],   5);
+       ROUND(dd, aa, bb, cc, F1, K1, in[5],   8);
+       ROUND(cc, dd, aa, bb, F1, K1, in[6],   7);
+       ROUND(bb, cc, dd, aa, F1, K1, in[7],   9);
+       ROUND(aa, bb, cc, dd, F1, K1, in[8],  11);
+       ROUND(dd, aa, bb, cc, F1, K1, in[9],  13);
+       ROUND(cc, dd, aa, bb, F1, K1, in[10], 14);
+       ROUND(bb, cc, dd, aa, F1, K1, in[11], 15);
+       ROUND(aa, bb, cc, dd, F1, K1, in[12],  6);
+       ROUND(dd, aa, bb, cc, F1, K1, in[13],  7);
+       ROUND(cc, dd, aa, bb, F1, K1, in[14],  9);
+       ROUND(bb, cc, dd, aa, F1, K1, in[15],  8);
+
+       /* round 2: left lane */
+       ROUND(aa, bb, cc, dd, F2, K2, in[7],   7);
+       ROUND(dd, aa, bb, cc, F2, K2, in[4],   6);
+       ROUND(cc, dd, aa, bb, F2, K2, in[13],  8);
+       ROUND(bb, cc, dd, aa, F2, K2, in[1],  13);
+       ROUND(aa, bb, cc, dd, F2, K2, in[10], 11);
+       ROUND(dd, aa, bb, cc, F2, K2, in[6],   9);
+       ROUND(cc, dd, aa, bb, F2, K2, in[15],  7);
+       ROUND(bb, cc, dd, aa, F2, K2, in[3],  15);
+       ROUND(aa, bb, cc, dd, F2, K2, in[12],  7);
+       ROUND(dd, aa, bb, cc, F2, K2, in[0],  12);
+       ROUND(cc, dd, aa, bb, F2, K2, in[9],  15);
+       ROUND(bb, cc, dd, aa, F2, K2, in[5],   9);
+       ROUND(aa, bb, cc, dd, F2, K2, in[2],  11);
+       ROUND(dd, aa, bb, cc, F2, K2, in[14],  7);
+       ROUND(cc, dd, aa, bb, F2, K2, in[11], 13);
+       ROUND(bb, cc, dd, aa, F2, K2, in[8],  12);
+
+       /* round 3: left lane */
+       ROUND(aa, bb, cc, dd, F3, K3, in[3],  11);
+       ROUND(dd, aa, bb, cc, F3, K3, in[10], 13);
+       ROUND(cc, dd, aa, bb, F3, K3, in[14],  6);
+       ROUND(bb, cc, dd, aa, F3, K3, in[4],   7);
+       ROUND(aa, bb, cc, dd, F3, K3, in[9],  14);
+       ROUND(dd, aa, bb, cc, F3, K3, in[15],  9);
+       ROUND(cc, dd, aa, bb, F3, K3, in[8],  13);
+       ROUND(bb, cc, dd, aa, F3, K3, in[1],  15);
+       ROUND(aa, bb, cc, dd, F3, K3, in[2],  14);
+       ROUND(dd, aa, bb, cc, F3, K3, in[7],   8);
+       ROUND(cc, dd, aa, bb, F3, K3, in[0],  13);
+       ROUND(bb, cc, dd, aa, F3, K3, in[6],   6);
+       ROUND(aa, bb, cc, dd, F3, K3, in[13],  5);
+       ROUND(dd, aa, bb, cc, F3, K3, in[11], 12);
+       ROUND(cc, dd, aa, bb, F3, K3, in[5],   7);
+       ROUND(bb, cc, dd, aa, F3, K3, in[12],  5);
+
+       /* round 4: left lane */
+       ROUND(aa, bb, cc, dd, F4, K4, in[1],  11);
+       ROUND(dd, aa, bb, cc, F4, K4, in[9],  12);
+       ROUND(cc, dd, aa, bb, F4, K4, in[11], 14);
+       ROUND(bb, cc, dd, aa, F4, K4, in[10], 15);
+       ROUND(aa, bb, cc, dd, F4, K4, in[0],  14);
+       ROUND(dd, aa, bb, cc, F4, K4, in[8],  15);
+       ROUND(cc, dd, aa, bb, F4, K4, in[12],  9);
+       ROUND(bb, cc, dd, aa, F4, K4, in[4],   8);
+       ROUND(aa, bb, cc, dd, F4, K4, in[13],  9);
+       ROUND(dd, aa, bb, cc, F4, K4, in[3],  14);
+       ROUND(cc, dd, aa, bb, F4, K4, in[7],   5);
+       ROUND(bb, cc, dd, aa, F4, K4, in[15],  6);
+       ROUND(aa, bb, cc, dd, F4, K4, in[14],  8);
+       ROUND(dd, aa, bb, cc, F4, K4, in[5],   6);
+       ROUND(cc, dd, aa, bb, F4, K4, in[6],   5);
+       ROUND(bb, cc, dd, aa, F4, K4, in[2],  12);
+
+       /* round 1: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[5],   8);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[14],  9);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[7],   9);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[0],  11);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[9],  13);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[2],  15);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[11], 15);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[4],   5);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[13],  7);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[6],   7);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[15],  8);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[8],  11);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[1],  14);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[10], 14);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[3],  12);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[12],  6);
+
+       /* round 2: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[6],   9);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[11], 13);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[3],  15);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[7],   7);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[0],  12);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[13],  8);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[5],   9);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[10], 11);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[14],  7);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[15],  7);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[8],  12);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[12],  7);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[4],   6);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[9],  15);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[1],  13);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[2],  11);
+
+       /* round 3: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[15],  9);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[5],   7);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[1],  15);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[3],  11);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[7],   8);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[14],  6);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[6],   6);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[9],  14);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[11], 12);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[8],  13);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[12],  5);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[2],  14);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[10], 13);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[0],  13);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[4],   7);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[13],  5);
+
+       /* round 4: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[8],  15);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[6],   5);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[4],   8);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[1],  11);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[3],  14);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[11], 14);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[15],  6);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[0],  14);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[5],   6);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[12],  9);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[2],  12);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[13],  9);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[9],  12);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[7],   5);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[10], 15);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[14],  8);
+
+       /* combine results */
+       ddd += cc + state[1];           /* final result for state[0] */
+       state[1] = state[2] + dd + aaa;
+       state[2] = state[3] + aa + bbb;
+       state[3] = state[0] + bb + ccc;
+       state[0] = ddd;
+
+       return;
+}
+
+static void rmd128_init(struct crypto_tfm *tfm)
+{
+       struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm);
+
+       rctx->byte_count = 0;
+
+       rctx->state[0] = RMD_H0;
+       rctx->state[1] = RMD_H1;
+       rctx->state[2] = RMD_H2;
+       rctx->state[3] = RMD_H3;
+
+       memset(rctx->buffer, 0, sizeof(rctx->buffer));
+}
+
+static void rmd128_update(struct crypto_tfm *tfm, const u8 *data,
+                         unsigned int len)
+{
+       struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm);
+       const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
+
+       rctx->byte_count += len;
+
+       /* Enough space in buffer? If so copy and we're done */
+       if (avail > len) {
+               memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+                      data, len);
+               return;
+       }
+
+       memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+              data, avail);
+
+       rmd128_transform(rctx->state, rctx->buffer);
+       data += avail;
+       len -= avail;
+
+       while (len >= sizeof(rctx->buffer)) {
+               memcpy(rctx->buffer, data, sizeof(rctx->buffer));
+               rmd128_transform(rctx->state, rctx->buffer);
+               data += sizeof(rctx->buffer);
+               len -= sizeof(rctx->buffer);
+       }
+
+       memcpy(rctx->buffer, data, len);
+}
+
+/* Add padding and return the message digest. */
+static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
+{
+       struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm);
+       u32 i, index, padlen;
+       __le64 bits;
+       __le32 *dst = (__le32 *)out;
+       static const u8 padding[64] = { 0x80, };
+
+       bits = cpu_to_le64(rctx->byte_count << 3);
+
+       /* Pad out to 56 mod 64 */
+       index = rctx->byte_count & 0x3f;
+       padlen = (index < 56) ? (56 - index) : ((64+56) - index);
+       rmd128_update(tfm, padding, padlen);
+
+       /* Append length */
+       rmd128_update(tfm, (const u8 *)&bits, sizeof(bits));
+
+       /* Store state in digest */
+       for (i = 0; i < 4; i++)
+               dst[i] = cpu_to_le32p(&rctx->state[i]);
+
+       /* Wipe context */
+       memset(rctx, 0, sizeof(*rctx));
+}
+
+static struct crypto_alg alg = {
+       .cra_name        =      "rmd128",
+       .cra_driver_name =      "rmd128",
+       .cra_flags       =      CRYPTO_ALG_TYPE_DIGEST,
+       .cra_blocksize   =      RMD128_BLOCK_SIZE,
+       .cra_ctxsize     =      sizeof(struct rmd128_ctx),
+       .cra_module      =      THIS_MODULE,
+       .cra_list        =      LIST_HEAD_INIT(alg.cra_list),
+       .cra_u           =      { .digest = {
+       .dia_digestsize  =      RMD128_DIGEST_SIZE,
+       .dia_init        =      rmd128_init,
+       .dia_update      =      rmd128_update,
+       .dia_final       =      rmd128_final } }
+};
+
+static int __init rmd128_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit rmd128_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(rmd128_mod_init);
+module_exit(rmd128_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("RIPEMD-128 Message Digest");
+
+MODULE_ALIAS("rmd128");
diff --git a/crypto/rmd160.c b/crypto/rmd160.c
new file mode 100644 (file)
index 0000000..f001ec7
--- /dev/null
@@ -0,0 +1,369 @@
+/*
+ * Cryptographic API.
+ *
+ * RIPEMD-160 - RACE Integrity Primitives Evaluation Message Digest.
+ *
+ * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
+ *
+ * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/crypto.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#include "ripemd.h"
+
+struct rmd160_ctx {
+       u64 byte_count;
+       u32 state[5];
+       __le32 buffer[16];
+};
+
+#define K1  RMD_K1
+#define K2  RMD_K2
+#define K3  RMD_K3
+#define K4  RMD_K4
+#define K5  RMD_K5
+#define KK1 RMD_K6
+#define KK2 RMD_K7
+#define KK3 RMD_K8
+#define KK4 RMD_K9
+#define KK5 RMD_K1
+
+#define F1(x, y, z) (x ^ y ^ z)                /* XOR */
+#define F2(x, y, z) (z ^ (x & (y ^ z)))        /* x ? y : z */
+#define F3(x, y, z) ((x | ~y) ^ z)
+#define F4(x, y, z) (y ^ (z & (x ^ y)))        /* z ? x : y */
+#define F5(x, y, z) (x ^ (y | ~z))
+
+#define ROUND(a, b, c, d, e, f, k, x, s)  { \
+       (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
+       (a) = rol32((a), (s)) + (e); \
+       (c) = rol32((c), 10); \
+}
+
+static void rmd160_transform(u32 *state, const __le32 *in)
+{
+       u32 aa, bb, cc, dd, ee, aaa, bbb, ccc, ddd, eee;
+
+       /* Initialize left lane */
+       aa = state[0];
+       bb = state[1];
+       cc = state[2];
+       dd = state[3];
+       ee = state[4];
+
+       /* Initialize right lane */
+       aaa = state[0];
+       bbb = state[1];
+       ccc = state[2];
+       ddd = state[3];
+       eee = state[4];
+
+       /* round 1: left lane */
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[0],  11);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[1],  14);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[2],  15);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[3],  12);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[4],   5);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[5],   8);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[6],   7);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[7],   9);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[8],  11);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[9],  13);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[10], 14);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[11], 15);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[12],  6);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[13],  7);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[14],  9);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[15],  8);
+
+       /* round 2: left lane" */
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[7],   7);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[4],   6);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[13],  8);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[1],  13);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[10], 11);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[6],   9);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[15],  7);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[3],  15);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[12],  7);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[0],  12);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[9],  15);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[5],   9);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[2],  11);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[14],  7);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[11], 13);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[8],  12);
+
+       /* round 3: left lane" */
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[3],  11);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[10], 13);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[14],  6);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[4],   7);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[9],  14);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[15],  9);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[8],  13);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[1],  15);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[2],  14);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[7],   8);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[0],  13);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[6],   6);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[13],  5);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[11], 12);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[5],   7);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[12],  5);
+
+       /* round 4: left lane" */
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[1],  11);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[9],  12);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[11], 14);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[10], 15);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[0],  14);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[8],  15);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[12],  9);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[4],   8);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[13],  9);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[3],  14);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[7],   5);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[15],  6);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[14],  8);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[5],   6);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[6],   5);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[2],  12);
+
+       /* round 5: left lane" */
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[4],   9);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[0],  15);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[5],   5);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[9],  11);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[7],   6);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[12],  8);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[2],  13);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[10], 12);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[14],  5);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[1],  12);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[3],  13);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[8],  14);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[11], 11);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[6],   8);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[15],  5);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[13],  6);
+
+       /* round 1: right lane */
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[5],   8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[14],  9);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[7],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[0],  11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[9],  13);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[2],  15);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[11], 15);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[4],   5);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[13],  7);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[6],   7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[15],  8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[8],  11);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[1],  14);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[10], 14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[3],  12);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[12],  6);
+
+       /* round 2: right lane */
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[6],   9);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[11], 13);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[3],  15);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[7],   7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[0],  12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[13],  8);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[5],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[10], 11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[14],  7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[15],  7);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[8],  12);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[12],  7);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[4],   6);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[9],  15);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[1],  13);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[2],  11);
+
+       /* round 3: right lane */
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[15],  9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[5],   7);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[1],  15);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[3],  11);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[7],   8);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[14],  6);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[6],   6);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[9],  14);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[11], 12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[8],  13);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[12],  5);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[2],  14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[10], 13);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[0],  13);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[4],   7);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[13],  5);
+
+       /* round 4: right lane */
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[8],  15);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[6],   5);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[4],   8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[1],  11);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[3],  14);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[11], 14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[15],  6);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[0],  14);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[5],   6);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[12],  9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[2],  12);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[13],  9);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[9],  12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[7],   5);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[10], 15);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[14],  8);
+
+       /* round 5: right lane */
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[12],  8);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[15],  5);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[10], 12);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[4],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[1],  12);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[5],   5);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[8],  14);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[7],   6);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[6],   8);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[2],  13);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[13],  6);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[14],  5);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[0],  15);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[3],  13);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[9],  11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[11], 11);
+
+       /* combine results */
+       ddd += cc + state[1];           /* final result for state[0] */
+       state[1] = state[2] + dd + eee;
+       state[2] = state[3] + ee + aaa;
+       state[3] = state[4] + aa + bbb;
+       state[4] = state[0] + bb + ccc;
+       state[0] = ddd;
+
+       return;
+}
+
+static void rmd160_init(struct crypto_tfm *tfm)
+{
+       struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm);
+
+       rctx->byte_count = 0;
+
+       rctx->state[0] = RMD_H0;
+       rctx->state[1] = RMD_H1;
+       rctx->state[2] = RMD_H2;
+       rctx->state[3] = RMD_H3;
+       rctx->state[4] = RMD_H4;
+
+       memset(rctx->buffer, 0, sizeof(rctx->buffer));
+}
+
+static void rmd160_update(struct crypto_tfm *tfm, const u8 *data,
+                         unsigned int len)
+{
+       struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm);
+       const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
+
+       rctx->byte_count += len;
+
+       /* Enough space in buffer? If so copy and we're done */
+       if (avail > len) {
+               memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+                      data, len);
+               return;
+       }
+
+       memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+              data, avail);
+
+       rmd160_transform(rctx->state, rctx->buffer);
+       data += avail;
+       len -= avail;
+
+       while (len >= sizeof(rctx->buffer)) {
+               memcpy(rctx->buffer, data, sizeof(rctx->buffer));
+               rmd160_transform(rctx->state, rctx->buffer);
+               data += sizeof(rctx->buffer);
+               len -= sizeof(rctx->buffer);
+       }
+
+       memcpy(rctx->buffer, data, len);
+}
+
+/* Add padding and return the message digest. */
+static void rmd160_final(struct crypto_tfm *tfm, u8 *out)
+{
+       struct rmd160_ctx *rctx = crypto_tfm_ctx(tfm);
+       u32 i, index, padlen;
+       __le64 bits;
+       __le32 *dst = (__le32 *)out;
+       static const u8 padding[64] = { 0x80, };
+
+       bits = cpu_to_le64(rctx->byte_count << 3);
+
+       /* Pad out to 56 mod 64 */
+       index = rctx->byte_count & 0x3f;
+       padlen = (index < 56) ? (56 - index) : ((64+56) - index);
+       rmd160_update(tfm, padding, padlen);
+
+       /* Append length */
+       rmd160_update(tfm, (const u8 *)&bits, sizeof(bits));
+
+       /* Store state in digest */
+       for (i = 0; i < 5; i++)
+               dst[i] = cpu_to_le32p(&rctx->state[i]);
+
+       /* Wipe context */
+       memset(rctx, 0, sizeof(*rctx));
+}
+
+static struct crypto_alg alg = {
+       .cra_name        =      "rmd160",
+       .cra_driver_name =      "rmd160",
+       .cra_flags       =      CRYPTO_ALG_TYPE_DIGEST,
+       .cra_blocksize   =      RMD160_BLOCK_SIZE,
+       .cra_ctxsize     =      sizeof(struct rmd160_ctx),
+       .cra_module      =      THIS_MODULE,
+       .cra_list        =      LIST_HEAD_INIT(alg.cra_list),
+       .cra_u           =      { .digest = {
+       .dia_digestsize  =      RMD160_DIGEST_SIZE,
+       .dia_init        =      rmd160_init,
+       .dia_update      =      rmd160_update,
+       .dia_final       =      rmd160_final } }
+};
+
+static int __init rmd160_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit rmd160_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(rmd160_mod_init);
+module_exit(rmd160_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("RIPEMD-160 Message Digest");
+
+MODULE_ALIAS("rmd160");
diff --git a/crypto/rmd256.c b/crypto/rmd256.c
new file mode 100644 (file)
index 0000000..e3de5b4
--- /dev/null
@@ -0,0 +1,344 @@
+/*
+ * Cryptographic API.
+ *
+ * RIPEMD-256 - RACE Integrity Primitives Evaluation Message Digest.
+ *
+ * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
+ *
+ * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/crypto.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#include "ripemd.h"
+
+struct rmd256_ctx {
+       u64 byte_count;
+       u32 state[8];
+       __le32 buffer[16];
+};
+
+#define K1  RMD_K1
+#define K2  RMD_K2
+#define K3  RMD_K3
+#define K4  RMD_K4
+#define KK1 RMD_K6
+#define KK2 RMD_K7
+#define KK3 RMD_K8
+#define KK4 RMD_K1
+
+#define F1(x, y, z) (x ^ y ^ z)                /* XOR */
+#define F2(x, y, z) (z ^ (x & (y ^ z)))        /* x ? y : z */
+#define F3(x, y, z) ((x | ~y) ^ z)
+#define F4(x, y, z) (y ^ (z & (x ^ y)))        /* z ? x : y */
+
+#define ROUND(a, b, c, d, f, k, x, s)  { \
+       (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
+       (a) = rol32((a), (s)); \
+}
+
+static void rmd256_transform(u32 *state, const __le32 *in)
+{
+       u32 aa, bb, cc, dd, aaa, bbb, ccc, ddd, tmp;
+
+       /* Initialize left lane */
+       aa = state[0];
+       bb = state[1];
+       cc = state[2];
+       dd = state[3];
+
+       /* Initialize right lane */
+       aaa = state[4];
+       bbb = state[5];
+       ccc = state[6];
+       ddd = state[7];
+
+       /* round 1: left lane */
+       ROUND(aa, bb, cc, dd, F1, K1, in[0],  11);
+       ROUND(dd, aa, bb, cc, F1, K1, in[1],  14);
+       ROUND(cc, dd, aa, bb, F1, K1, in[2],  15);
+       ROUND(bb, cc, dd, aa, F1, K1, in[3],  12);
+       ROUND(aa, bb, cc, dd, F1, K1, in[4],   5);
+       ROUND(dd, aa, bb, cc, F1, K1, in[5],   8);
+       ROUND(cc, dd, aa, bb, F1, K1, in[6],   7);
+       ROUND(bb, cc, dd, aa, F1, K1, in[7],   9);
+       ROUND(aa, bb, cc, dd, F1, K1, in[8],  11);
+       ROUND(dd, aa, bb, cc, F1, K1, in[9],  13);
+       ROUND(cc, dd, aa, bb, F1, K1, in[10], 14);
+       ROUND(bb, cc, dd, aa, F1, K1, in[11], 15);
+       ROUND(aa, bb, cc, dd, F1, K1, in[12],  6);
+       ROUND(dd, aa, bb, cc, F1, K1, in[13],  7);
+       ROUND(cc, dd, aa, bb, F1, K1, in[14],  9);
+       ROUND(bb, cc, dd, aa, F1, K1, in[15],  8);
+
+       /* round 1: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[5],   8);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[14],  9);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[7],   9);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[0],  11);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[9],  13);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[2],  15);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[11], 15);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[4],   5);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[13],  7);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[6],   7);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[15],  8);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[8],  11);
+       ROUND(aaa, bbb, ccc, ddd, F4, KK1, in[1],  14);
+       ROUND(ddd, aaa, bbb, ccc, F4, KK1, in[10], 14);
+       ROUND(ccc, ddd, aaa, bbb, F4, KK1, in[3],  12);
+       ROUND(bbb, ccc, ddd, aaa, F4, KK1, in[12],  6);
+
+       /* Swap contents of "a" registers */
+       tmp = aa; aa = aaa; aaa = tmp;
+
+       /* round 2: left lane */
+       ROUND(aa, bb, cc, dd, F2, K2, in[7],   7);
+       ROUND(dd, aa, bb, cc, F2, K2, in[4],   6);
+       ROUND(cc, dd, aa, bb, F2, K2, in[13],  8);
+       ROUND(bb, cc, dd, aa, F2, K2, in[1],  13);
+       ROUND(aa, bb, cc, dd, F2, K2, in[10], 11);
+       ROUND(dd, aa, bb, cc, F2, K2, in[6],   9);
+       ROUND(cc, dd, aa, bb, F2, K2, in[15],  7);
+       ROUND(bb, cc, dd, aa, F2, K2, in[3],  15);
+       ROUND(aa, bb, cc, dd, F2, K2, in[12],  7);
+       ROUND(dd, aa, bb, cc, F2, K2, in[0],  12);
+       ROUND(cc, dd, aa, bb, F2, K2, in[9],  15);
+       ROUND(bb, cc, dd, aa, F2, K2, in[5],   9);
+       ROUND(aa, bb, cc, dd, F2, K2, in[2],  11);
+       ROUND(dd, aa, bb, cc, F2, K2, in[14],  7);
+       ROUND(cc, dd, aa, bb, F2, K2, in[11], 13);
+       ROUND(bb, cc, dd, aa, F2, K2, in[8],  12);
+
+       /* round 2: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[6],   9);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[11], 13);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[3],  15);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[7],   7);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[0],  12);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[13],  8);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[5],   9);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[10], 11);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[14],  7);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[15],  7);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[8],  12);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[12],  7);
+       ROUND(aaa, bbb, ccc, ddd, F3, KK2, in[4],   6);
+       ROUND(ddd, aaa, bbb, ccc, F3, KK2, in[9],  15);
+       ROUND(ccc, ddd, aaa, bbb, F3, KK2, in[1],  13);
+       ROUND(bbb, ccc, ddd, aaa, F3, KK2, in[2],  11);
+
+       /* Swap contents of "b" registers */
+       tmp = bb; bb = bbb; bbb = tmp;
+
+       /* round 3: left lane */
+       ROUND(aa, bb, cc, dd, F3, K3, in[3],  11);
+       ROUND(dd, aa, bb, cc, F3, K3, in[10], 13);
+       ROUND(cc, dd, aa, bb, F3, K3, in[14],  6);
+       ROUND(bb, cc, dd, aa, F3, K3, in[4],   7);
+       ROUND(aa, bb, cc, dd, F3, K3, in[9],  14);
+       ROUND(dd, aa, bb, cc, F3, K3, in[15],  9);
+       ROUND(cc, dd, aa, bb, F3, K3, in[8],  13);
+       ROUND(bb, cc, dd, aa, F3, K3, in[1],  15);
+       ROUND(aa, bb, cc, dd, F3, K3, in[2],  14);
+       ROUND(dd, aa, bb, cc, F3, K3, in[7],   8);
+       ROUND(cc, dd, aa, bb, F3, K3, in[0],  13);
+       ROUND(bb, cc, dd, aa, F3, K3, in[6],   6);
+       ROUND(aa, bb, cc, dd, F3, K3, in[13],  5);
+       ROUND(dd, aa, bb, cc, F3, K3, in[11], 12);
+       ROUND(cc, dd, aa, bb, F3, K3, in[5],   7);
+       ROUND(bb, cc, dd, aa, F3, K3, in[12],  5);
+
+       /* round 3: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[15],  9);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[5],   7);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[1],  15);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[3],  11);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[7],   8);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[14],  6);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[6],   6);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[9],  14);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[11], 12);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[8],  13);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[12],  5);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[2],  14);
+       ROUND(aaa, bbb, ccc, ddd, F2, KK3, in[10], 13);
+       ROUND(ddd, aaa, bbb, ccc, F2, KK3, in[0],  13);
+       ROUND(ccc, ddd, aaa, bbb, F2, KK3, in[4],   7);
+       ROUND(bbb, ccc, ddd, aaa, F2, KK3, in[13],  5);
+
+       /* Swap contents of "c" registers */
+       tmp = cc; cc = ccc; ccc = tmp;
+
+       /* round 4: left lane */
+       ROUND(aa, bb, cc, dd, F4, K4, in[1],  11);
+       ROUND(dd, aa, bb, cc, F4, K4, in[9],  12);
+       ROUND(cc, dd, aa, bb, F4, K4, in[11], 14);
+       ROUND(bb, cc, dd, aa, F4, K4, in[10], 15);
+       ROUND(aa, bb, cc, dd, F4, K4, in[0],  14);
+       ROUND(dd, aa, bb, cc, F4, K4, in[8],  15);
+       ROUND(cc, dd, aa, bb, F4, K4, in[12],  9);
+       ROUND(bb, cc, dd, aa, F4, K4, in[4],   8);
+       ROUND(aa, bb, cc, dd, F4, K4, in[13],  9);
+       ROUND(dd, aa, bb, cc, F4, K4, in[3],  14);
+       ROUND(cc, dd, aa, bb, F4, K4, in[7],   5);
+       ROUND(bb, cc, dd, aa, F4, K4, in[15],  6);
+       ROUND(aa, bb, cc, dd, F4, K4, in[14],  8);
+       ROUND(dd, aa, bb, cc, F4, K4, in[5],   6);
+       ROUND(cc, dd, aa, bb, F4, K4, in[6],   5);
+       ROUND(bb, cc, dd, aa, F4, K4, in[2],  12);
+
+       /* round 4: right lane */
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[8],  15);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[6],   5);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[4],   8);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[1],  11);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[3],  14);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[11], 14);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[15],  6);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[0],  14);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[5],   6);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[12],  9);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[2],  12);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[13],  9);
+       ROUND(aaa, bbb, ccc, ddd, F1, KK4, in[9],  12);
+       ROUND(ddd, aaa, bbb, ccc, F1, KK4, in[7],   5);
+       ROUND(ccc, ddd, aaa, bbb, F1, KK4, in[10], 15);
+       ROUND(bbb, ccc, ddd, aaa, F1, KK4, in[14],  8);
+
+       /* Swap contents of "d" registers */
+       tmp = dd; dd = ddd; ddd = tmp;
+
+       /* combine results */
+       state[0] += aa;
+       state[1] += bb;
+       state[2] += cc;
+       state[3] += dd;
+       state[4] += aaa;
+       state[5] += bbb;
+       state[6] += ccc;
+       state[7] += ddd;
+
+       return;
+}
+
+static void rmd256_init(struct crypto_tfm *tfm)
+{
+       struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm);
+
+       rctx->byte_count = 0;
+
+       rctx->state[0] = RMD_H0;
+       rctx->state[1] = RMD_H1;
+       rctx->state[2] = RMD_H2;
+       rctx->state[3] = RMD_H3;
+       rctx->state[4] = RMD_H5;
+       rctx->state[5] = RMD_H6;
+       rctx->state[6] = RMD_H7;
+       rctx->state[7] = RMD_H8;
+
+       memset(rctx->buffer, 0, sizeof(rctx->buffer));
+}
+
+static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
+                         unsigned int len)
+{
+       struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm);
+       const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
+
+       rctx->byte_count += len;
+
+       /* Enough space in buffer? If so copy and we're done */
+       if (avail > len) {
+               memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+                      data, len);
+               return;
+       }
+
+       memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+              data, avail);
+
+       rmd256_transform(rctx->state, rctx->buffer);
+       data += avail;
+       len -= avail;
+
+       while (len >= sizeof(rctx->buffer)) {
+               memcpy(rctx->buffer, data, sizeof(rctx->buffer));
+               rmd256_transform(rctx->state, rctx->buffer);
+               data += sizeof(rctx->buffer);
+               len -= sizeof(rctx->buffer);
+       }
+
+       memcpy(rctx->buffer, data, len);
+}
+
+/* Add padding and return the message digest. */
+static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
+{
+       struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm);
+       u32 i, index, padlen;
+       __le64 bits;
+       __le32 *dst = (__le32 *)out;
+       static const u8 padding[64] = { 0x80, };
+
+       bits = cpu_to_le64(rctx->byte_count << 3);
+
+       /* Pad out to 56 mod 64 */
+       index = rctx->byte_count & 0x3f;
+       padlen = (index < 56) ? (56 - index) : ((64+56) - index);
+       rmd256_update(tfm, padding, padlen);
+
+       /* Append length */
+       rmd256_update(tfm, (const u8 *)&bits, sizeof(bits));
+
+       /* Store state in digest */
+       for (i = 0; i < 8; i++)
+               dst[i] = cpu_to_le32p(&rctx->state[i]);
+
+       /* Wipe context */
+       memset(rctx, 0, sizeof(*rctx));
+}
+
+static struct crypto_alg alg = {
+       .cra_name        =      "rmd256",
+       .cra_driver_name =      "rmd256",
+       .cra_flags       =      CRYPTO_ALG_TYPE_DIGEST,
+       .cra_blocksize   =      RMD256_BLOCK_SIZE,
+       .cra_ctxsize     =      sizeof(struct rmd256_ctx),
+       .cra_module      =      THIS_MODULE,
+       .cra_list        =      LIST_HEAD_INIT(alg.cra_list),
+       .cra_u           =      { .digest = {
+       .dia_digestsize  =      RMD256_DIGEST_SIZE,
+       .dia_init        =      rmd256_init,
+       .dia_update      =      rmd256_update,
+       .dia_final       =      rmd256_final } }
+};
+
+static int __init rmd256_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit rmd256_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(rmd256_mod_init);
+module_exit(rmd256_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("RIPEMD-256 Message Digest");
+
+MODULE_ALIAS("rmd256");
diff --git a/crypto/rmd320.c b/crypto/rmd320.c
new file mode 100644 (file)
index 0000000..b143d66
--- /dev/null
@@ -0,0 +1,393 @@
+/*
+ * Cryptographic API.
+ *
+ * RIPEMD-320 - RACE Integrity Primitives Evaluation Message Digest.
+ *
+ * Based on the reference implementation by Antoon Bosselaers, ESAT-COSIC
+ *
+ * Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger (at) swiss-it.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/crypto.h>
+#include <linux/cryptohash.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+
+#include "ripemd.h"
+
+struct rmd320_ctx {
+       u64 byte_count;
+       u32 state[10];
+       __le32 buffer[16];
+};
+
+#define K1  RMD_K1
+#define K2  RMD_K2
+#define K3  RMD_K3
+#define K4  RMD_K4
+#define K5  RMD_K5
+#define KK1 RMD_K6
+#define KK2 RMD_K7
+#define KK3 RMD_K8
+#define KK4 RMD_K9
+#define KK5 RMD_K1
+
+#define F1(x, y, z) (x ^ y ^ z)                /* XOR */
+#define F2(x, y, z) (z ^ (x & (y ^ z)))        /* x ? y : z */
+#define F3(x, y, z) ((x | ~y) ^ z)
+#define F4(x, y, z) (y ^ (z & (x ^ y)))        /* z ? x : y */
+#define F5(x, y, z) (x ^ (y | ~z))
+
+#define ROUND(a, b, c, d, e, f, k, x, s)  { \
+       (a) += f((b), (c), (d)) + le32_to_cpup(&(x)) + (k); \
+       (a) = rol32((a), (s)) + (e); \
+       (c) = rol32((c), 10); \
+}
+
+static void rmd320_transform(u32 *state, const __le32 *in)
+{
+       u32 aa, bb, cc, dd, ee, aaa, bbb, ccc, ddd, eee, tmp;
+
+       /* Initialize left lane */
+       aa = state[0];
+       bb = state[1];
+       cc = state[2];
+       dd = state[3];
+       ee = state[4];
+
+       /* Initialize right lane */
+       aaa = state[5];
+       bbb = state[6];
+       ccc = state[7];
+       ddd = state[8];
+       eee = state[9];
+
+       /* round 1: left lane */
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[0],  11);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[1],  14);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[2],  15);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[3],  12);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[4],   5);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[5],   8);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[6],   7);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[7],   9);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[8],  11);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[9],  13);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[10], 14);
+       ROUND(ee, aa, bb, cc, dd, F1, K1, in[11], 15);
+       ROUND(dd, ee, aa, bb, cc, F1, K1, in[12],  6);
+       ROUND(cc, dd, ee, aa, bb, F1, K1, in[13],  7);
+       ROUND(bb, cc, dd, ee, aa, F1, K1, in[14],  9);
+       ROUND(aa, bb, cc, dd, ee, F1, K1, in[15],  8);
+
+       /* round 1: right lane */
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[5],   8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[14],  9);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[7],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[0],  11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[9],  13);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[2],  15);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[11], 15);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[4],   5);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[13],  7);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[6],   7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[15],  8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F5, KK1, in[8],  11);
+       ROUND(ddd, eee, aaa, bbb, ccc, F5, KK1, in[1],  14);
+       ROUND(ccc, ddd, eee, aaa, bbb, F5, KK1, in[10], 14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F5, KK1, in[3],  12);
+       ROUND(aaa, bbb, ccc, ddd, eee, F5, KK1, in[12],  6);
+
+       /* Swap contents of "a" registers */
+       tmp = aa; aa = aaa; aaa = tmp;
+
+       /* round 2: left lane" */
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[7],   7);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[4],   6);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[13],  8);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[1],  13);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[10], 11);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[6],   9);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[15],  7);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[3],  15);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[12],  7);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[0],  12);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[9],  15);
+       ROUND(dd, ee, aa, bb, cc, F2, K2, in[5],   9);
+       ROUND(cc, dd, ee, aa, bb, F2, K2, in[2],  11);
+       ROUND(bb, cc, dd, ee, aa, F2, K2, in[14],  7);
+       ROUND(aa, bb, cc, dd, ee, F2, K2, in[11], 13);
+       ROUND(ee, aa, bb, cc, dd, F2, K2, in[8],  12);
+
+       /* round 2: right lane */
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[6],   9);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[11], 13);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[3],  15);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[7],   7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[0],  12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[13],  8);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[5],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[10], 11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[14],  7);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[15],  7);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[8],  12);
+       ROUND(ddd, eee, aaa, bbb, ccc, F4, KK2, in[12],  7);
+       ROUND(ccc, ddd, eee, aaa, bbb, F4, KK2, in[4],   6);
+       ROUND(bbb, ccc, ddd, eee, aaa, F4, KK2, in[9],  15);
+       ROUND(aaa, bbb, ccc, ddd, eee, F4, KK2, in[1],  13);
+       ROUND(eee, aaa, bbb, ccc, ddd, F4, KK2, in[2],  11);
+
+       /* Swap contents of "b" registers */
+       tmp = bb; bb = bbb; bbb = tmp;
+
+       /* round 3: left lane" */
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[3],  11);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[10], 13);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[14],  6);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[4],   7);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[9],  14);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[15],  9);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[8],  13);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[1],  15);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[2],  14);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[7],   8);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[0],  13);
+       ROUND(cc, dd, ee, aa, bb, F3, K3, in[6],   6);
+       ROUND(bb, cc, dd, ee, aa, F3, K3, in[13],  5);
+       ROUND(aa, bb, cc, dd, ee, F3, K3, in[11], 12);
+       ROUND(ee, aa, bb, cc, dd, F3, K3, in[5],   7);
+       ROUND(dd, ee, aa, bb, cc, F3, K3, in[12],  5);
+
+       /* round 3: right lane */
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[15],  9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[5],   7);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[1],  15);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[3],  11);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[7],   8);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[14],  6);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[6],   6);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[9],  14);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[11], 12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[8],  13);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[12],  5);
+       ROUND(ccc, ddd, eee, aaa, bbb, F3, KK3, in[2],  14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F3, KK3, in[10], 13);
+       ROUND(aaa, bbb, ccc, ddd, eee, F3, KK3, in[0],  13);
+       ROUND(eee, aaa, bbb, ccc, ddd, F3, KK3, in[4],   7);
+       ROUND(ddd, eee, aaa, bbb, ccc, F3, KK3, in[13],  5);
+
+       /* Swap contents of "c" registers */
+       tmp = cc; cc = ccc; ccc = tmp;
+
+       /* round 4: left lane" */
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[1],  11);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[9],  12);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[11], 14);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[10], 15);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[0],  14);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[8],  15);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[12],  9);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[4],   8);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[13],  9);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[3],  14);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[7],   5);
+       ROUND(bb, cc, dd, ee, aa, F4, K4, in[15],  6);
+       ROUND(aa, bb, cc, dd, ee, F4, K4, in[14],  8);
+       ROUND(ee, aa, bb, cc, dd, F4, K4, in[5],   6);
+       ROUND(dd, ee, aa, bb, cc, F4, K4, in[6],   5);
+       ROUND(cc, dd, ee, aa, bb, F4, K4, in[2],  12);
+
+       /* round 4: right lane */
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[8],  15);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[6],   5);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[4],   8);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[1],  11);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[3],  14);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[11], 14);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[15],  6);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[0],  14);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[5],   6);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[12],  9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[2],  12);
+       ROUND(bbb, ccc, ddd, eee, aaa, F2, KK4, in[13],  9);
+       ROUND(aaa, bbb, ccc, ddd, eee, F2, KK4, in[9],  12);
+       ROUND(eee, aaa, bbb, ccc, ddd, F2, KK4, in[7],   5);
+       ROUND(ddd, eee, aaa, bbb, ccc, F2, KK4, in[10], 15);
+       ROUND(ccc, ddd, eee, aaa, bbb, F2, KK4, in[14],  8);
+
+       /* Swap contents of "d" registers */
+       tmp = dd; dd = ddd; ddd = tmp;
+
+       /* round 5: left lane" */
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[4],   9);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[0],  15);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[5],   5);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[9],  11);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[7],   6);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[12],  8);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[2],  13);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[10], 12);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[14],  5);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[1],  12);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[3],  13);
+       ROUND(aa, bb, cc, dd, ee, F5, K5, in[8],  14);
+       ROUND(ee, aa, bb, cc, dd, F5, K5, in[11], 11);
+       ROUND(dd, ee, aa, bb, cc, F5, K5, in[6],   8);
+       ROUND(cc, dd, ee, aa, bb, F5, K5, in[15],  5);
+       ROUND(bb, cc, dd, ee, aa, F5, K5, in[13],  6);
+
+       /* round 5: right lane */
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[12],  8);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[15],  5);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[10], 12);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[4],   9);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[1],  12);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[5],   5);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[8],  14);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[7],   6);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[6],   8);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[2],  13);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[13],  6);
+       ROUND(aaa, bbb, ccc, ddd, eee, F1, KK5, in[14],  5);
+       ROUND(eee, aaa, bbb, ccc, ddd, F1, KK5, in[0],  15);
+       ROUND(ddd, eee, aaa, bbb, ccc, F1, KK5, in[3],  13);
+       ROUND(ccc, ddd, eee, aaa, bbb, F1, KK5, in[9],  11);
+       ROUND(bbb, ccc, ddd, eee, aaa, F1, KK5, in[11], 11);
+
+       /* Swap contents of "e" registers */
+       tmp = ee; ee = eee; eee = tmp;
+
+       /* combine results */
+       state[0] += aa;
+       state[1] += bb;
+       state[2] += cc;
+       state[3] += dd;
+       state[4] += ee;
+       state[5] += aaa;
+       state[6] += bbb;
+       state[7] += ccc;
+       state[8] += ddd;
+       state[9] += eee;
+
+       return;
+}
+
+static void rmd320_init(struct crypto_tfm *tfm)
+{
+       struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm);
+
+       rctx->byte_count = 0;
+
+       rctx->state[0] = RMD_H0;
+       rctx->state[1] = RMD_H1;
+       rctx->state[2] = RMD_H2;
+       rctx->state[3] = RMD_H3;
+       rctx->state[4] = RMD_H4;
+       rctx->state[5] = RMD_H5;
+       rctx->state[6] = RMD_H6;
+       rctx->state[7] = RMD_H7;
+       rctx->state[8] = RMD_H8;
+       rctx->state[9] = RMD_H9;
+
+       memset(rctx->buffer, 0, sizeof(rctx->buffer));
+}
+
+static void rmd320_update(struct crypto_tfm *tfm, const u8 *data,
+                         unsigned int len)
+{
+       struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm);
+       const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
+
+       rctx->byte_count += len;
+
+       /* Enough space in buffer? If so copy and we're done */
+       if (avail > len) {
+               memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+                      data, len);
+               return;
+       }
+
+       memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
+              data, avail);
+
+       rmd320_transform(rctx->state, rctx->buffer);
+       data += avail;
+       len -= avail;
+
+       while (len >= sizeof(rctx->buffer)) {
+               memcpy(rctx->buffer, data, sizeof(rctx->buffer));
+               rmd320_transform(rctx->state, rctx->buffer);
+               data += sizeof(rctx->buffer);
+               len -= sizeof(rctx->buffer);
+       }
+
+       memcpy(rctx->buffer, data, len);
+}
+
+/* Add padding and return the message digest. */
+static void rmd320_final(struct crypto_tfm *tfm, u8 *out)
+{
+       struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm);
+       u32 i, index, padlen;
+       __le64 bits;
+       __le32 *dst = (__le32 *)out;
+       static const u8 padding[64] = { 0x80, };
+
+       bits = cpu_to_le64(rctx->byte_count << 3);
+
+       /* Pad out to 56 mod 64 */
+       index = rctx->byte_count & 0x3f;
+       padlen = (index < 56) ? (56 - index) : ((64+56) - index);
+       rmd320_update(tfm, padding, padlen);
+
+       /* Append length */
+       rmd320_update(tfm, (const u8 *)&bits, sizeof(bits));
+
+       /* Store state in digest */
+       for (i = 0; i < 10; i++)
+               dst[i] = cpu_to_le32p(&rctx->state[i]);
+
+       /* Wipe context */
+       memset(rctx, 0, sizeof(*rctx));
+}
+
+static struct crypto_alg alg = {
+       .cra_name        =      "rmd320",
+       .cra_driver_name =      "rmd320",
+       .cra_flags       =      CRYPTO_ALG_TYPE_DIGEST,
+       .cra_blocksize   =      RMD320_BLOCK_SIZE,
+       .cra_ctxsize     =      sizeof(struct rmd320_ctx),
+       .cra_module      =      THIS_MODULE,
+       .cra_list        =      LIST_HEAD_INIT(alg.cra_list),
+       .cra_u           =      { .digest = {
+       .dia_digestsize  =      RMD320_DIGEST_SIZE,
+       .dia_init        =      rmd320_init,
+       .dia_update      =      rmd320_update,
+       .dia_final       =      rmd320_final } }
+};
+
+static int __init rmd320_mod_init(void)
+{
+       return crypto_register_alg(&alg);
+}
+
+static void __exit rmd320_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(rmd320_mod_init);
+module_exit(rmd320_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("RIPEMD-320 Message Digest");
+
+MODULE_ALIAS("rmd320");
index e47f6e0..59821a2 100644 (file)
  * Software Foundation; either version 2 of the License, or (at your option)
  * any later version.
  *
- * 2007-11-13 Added GCM tests
- * 2007-11-13 Added AEAD support
- * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
- * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
- * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
- * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
- *
  */
 
+#include <crypto/hash.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -30,7 +24,6 @@
 #include <linux/scatterlist.h>
 #include <linux/string.h>
 #include <linux/crypto.h>
-#include <linux/highmem.h>
 #include <linux/moduleparam.h>
 #include <linux/jiffies.h>
 #include <linux/timex.h>
@@ -38,7 +31,7 @@
 #include "tcrypt.h"
 
 /*
- * Need to kmalloc() memory for testing kmap().
+ * Need to kmalloc() memory for testing.
  */
 #define TVMEMSIZE      16384
 #define XBUFSIZE       32768
@@ -46,7 +39,7 @@
 /*
  * Indexes into the xbuf to simulate cross-page access.
  */
-#define IDX1           37
+#define IDX1           32
 #define IDX2           32400
 #define IDX3           1
 #define IDX4           8193
@@ -83,7 +76,8 @@ static char *check[] = {
        "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
        "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
        "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
-       "camellia", "seed", "salsa20", "lzo", "cts", NULL
+       "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
+       "lzo", "cts", NULL
 };
 
 static void hexdump(unsigned char *buf, unsigned int len)
@@ -110,22 +104,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
        unsigned int i, j, k, temp;
        struct scatterlist sg[8];
        char result[64];
-       struct crypto_hash *tfm;
-       struct hash_desc desc;
+       struct crypto_ahash *tfm;
+       struct ahash_request *req;
+       struct tcrypt_result tresult;
        int ret;
        void *hash_buff;
 
        printk("\ntesting %s\n", algo);
 
-       tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
+       init_completion(&tresult.completion);
+
+       tfm = crypto_alloc_ahash(algo, 0, 0);
        if (IS_ERR(tfm)) {
                printk("failed to load transform for %s: %ld\n", algo,
                       PTR_ERR(tfm));
                return;
        }
 
-       desc.tfm = tfm;
-       desc.flags = 0;
+       req = ahash_request_alloc(tfm, GFP_KERNEL);
+       if (!req) {
+               printk(KERN_ERR "failed to allocate request for %s\n", algo);
+               goto out_noreq;
+       }
+       ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
+                                  tcrypt_complete, &tresult);
 
        for (i = 0; i < tcount; i++) {
                printk("test %u:\n", i + 1);
@@ -139,8 +141,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
                sg_init_one(&sg[0], hash_buff, template[i].psize);
 
                if (template[i].ksize) {
-                       ret = crypto_hash_setkey(tfm, template[i].key,
-                                                template[i].ksize);
+                       crypto_ahash_clear_flags(tfm, ~0);
+                       ret = crypto_ahash_setkey(tfm, template[i].key,
+                                                 template[i].ksize);
                        if (ret) {
                                printk("setkey() failed ret=%d\n", ret);
                                kfree(hash_buff);
@@ -148,17 +151,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
                        }
                }
 
-               ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
-               if (ret) {
+               ahash_request_set_crypt(req, sg, result, template[i].psize);
+               ret = crypto_ahash_digest(req);
+               switch (ret) {
+               case 0:
+                       break;
+               case -EINPROGRESS:
+               case -EBUSY:
+                       ret = wait_for_completion_interruptible(
+                               &tresult.completion);
+                       if (!ret && !(ret = tresult.err)) {
+                               INIT_COMPLETION(tresult.completion);
+                               break;
+                       }
+                       /* fall through */
+               default:
                        printk("digest () failed ret=%d\n", ret);
                        kfree(hash_buff);
                        goto out;
                }
 
-               hexdump(result, crypto_hash_digestsize(tfm));
+               hexdump(result, crypto_ahash_digestsize(tfm));
                printk("%s\n",
                       memcmp(result, template[i].digest,
-                             crypto_hash_digestsize(tfm)) ?
+                             crypto_ahash_digestsize(tfm)) ?
                       "fail" : "pass");
                kfree(hash_buff);
        }
@@ -187,8 +203,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
                        }
 
                        if (template[i].ksize) {
-                               ret = crypto_hash_setkey(tfm, template[i].key,
-                                                        template[i].ksize);
+                               crypto_ahash_clear_flags(tfm, ~0);
+                               ret = crypto_ahash_setkey(tfm, template[i].key,
+                                                         template[i].ksize);
 
                                if (ret) {
                                        printk("setkey() failed ret=%d\n", ret);
@@ -196,29 +213,44 @@ static void test_hash(char *algo, struct hash_testvec *template,
                                }
                        }
 
-                       ret = crypto_hash_digest(&desc, sg, template[i].psize,
-                                                result);
-                       if (ret) {
+                       ahash_request_set_crypt(req, sg, result,
+                                               template[i].psize);
+                       ret = crypto_ahash_digest(req);
+                       switch (ret) {
+                       case 0:
+                               break;
+                       case -EINPROGRESS:
+                       case -EBUSY:
+                               ret = wait_for_completion_interruptible(
+                                       &tresult.completion);
+                               if (!ret && !(ret = tresult.err)) {
+                                       INIT_COMPLETION(tresult.completion);
+                                       break;
+                               }
+                               /* fall through */
+                       default:
                                printk("digest () failed ret=%d\n", ret);
                                goto out;
                        }
 
-                       hexdump(result, crypto_hash_digestsize(tfm));
+                       hexdump(result, crypto_ahash_digestsize(tfm));
                        printk("%s\n",
                               memcmp(result, template[i].digest,
-                                     crypto_hash_digestsize(tfm)) ?
+                                     crypto_ahash_digestsize(tfm)) ?
                               "fail" : "pass");
                }
        }
 
 out:
-       crypto_free_hash(tfm);
+       ahash_request_free(req);
+out_noreq:
+       crypto_free_ahash(tfm);
 }
 
 static void test_aead(char *algo, int enc, struct aead_testvec *template,
                      unsigned int tcount)
 {
-       unsigned int ret, i, j, k, temp;
+       unsigned int ret, i, j, k, n, temp;
        char *q;
        struct crypto_aead *tfm;
        char *key;
@@ -344,13 +376,12 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template,
                                goto next_one;
                        }
 
-                       q = kmap(sg_page(&sg[0])) + sg[0].offset;
+                       q = input;
                        hexdump(q, template[i].rlen);
 
                        printk(KERN_INFO "enc/dec: %s\n",
                               memcmp(q, template[i].result,
                                      template[i].rlen) ? "fail" : "pass");
-                       kunmap(sg_page(&sg[0]));
 next_one:
                        if (!template[i].key)
                                kfree(key);
@@ -360,7 +391,6 @@ next_one:
        }
 
        printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
-       memset(xbuf, 0, XBUFSIZE);
        memset(axbuf, 0, XBUFSIZE);
 
        for (i = 0, j = 0; i < tcount; i++) {
@@ -388,6 +418,7 @@ next_one:
                                        goto out;
                        }
 
+                       memset(xbuf, 0, XBUFSIZE);
                        sg_init_table(sg, template[i].np);
                        for (k = 0, temp = 0; k < template[i].np; k++) {
                                memcpy(&xbuf[IDX[k]],
@@ -450,7 +481,7 @@ next_one:
 
                        for (k = 0, temp = 0; k < template[i].np; k++) {
                                printk(KERN_INFO "page %u\n", k);
-                               q = kmap(sg_page(&sg[k])) + sg[k].offset;
+                               q = &axbuf[IDX[k]];
                                hexdump(q, template[i].tap[k]);
                                printk(KERN_INFO "%s\n",
                                       memcmp(q, template[i].result + temp,
@@ -459,8 +490,15 @@ next_one:
                                               0 : authsize)) ?
                                       "fail" : "pass");
 
+                               for (n = 0; q[template[i].tap[k] + n]; n++)
+                                       ;
+                               if (n) {
+                                       printk("Result buffer corruption %u "
+                                              "bytes:\n", n);
+                                       hexdump(&q[template[i].tap[k]], n);
+                               }
+
                                temp += template[i].tap[k];
-                               kunmap(sg_page(&sg[k]));
                        }
                }
        }
@@ -473,7 +511,7 @@ out:
 static void test_cipher(char *algo, int enc,
                        struct cipher_testvec *template, unsigned int tcount)
 {
-       unsigned int ret, i, j, k, temp;
+       unsigned int ret, i, j, k, n, temp;
        char *q;
        struct crypto_ablkcipher *tfm;
        struct ablkcipher_request *req;
@@ -569,19 +607,17 @@ static void test_cipher(char *algo, int enc,
                                goto out;
                        }
 
-                       q = kmap(sg_page(&sg[0])) + sg[0].offset;
+                       q = data;
                        hexdump(q, template[i].rlen);
 
                        printk("%s\n",
                               memcmp(q, template[i].result,
                                      template[i].rlen) ? "fail" : "pass");
-                       kunmap(sg_page(&sg[0]));
                }
                kfree(data);
        }
 
        printk("\ntesting %s %s across pages (chunking)\n", algo, e);
-       memset(xbuf, 0, XBUFSIZE);
 
        j = 0;
        for (i = 0; i < tcount; i++) {
@@ -596,6 +632,7 @@ static void test_cipher(char *algo, int enc,
                        printk("test %u (%d bit key):\n",
                        j, template[i].klen * 8);
 
+                       memset(xbuf, 0, XBUFSIZE);
                        crypto_ablkcipher_clear_flags(tfm, ~0);
                        if (template[i].wk)
                                crypto_ablkcipher_set_flags(
@@ -649,14 +686,21 @@ static void test_cipher(char *algo, int enc,
                        temp = 0;
                        for (k = 0; k < template[i].np; k++) {
                                printk("page %u\n", k);
-                               q = kmap(sg_page(&sg[k])) + sg[k].offset;
+                               q = &xbuf[IDX[k]];
                                hexdump(q, template[i].tap[k]);
                                printk("%s\n",
                                        memcmp(q, template[i].result + temp,
                                                template[i].tap[k]) ? "fail" :
                                        "pass");
+
+                               for (n = 0; q[template[i].tap[k] + n]; n++)
+                                       ;
+                               if (n) {
+                                       printk("Result buffer corruption %u "
+                                              "bytes:\n", n);
+                                       hexdump(&q[template[i].tap[k]], n);
+                               }
                                temp += template[i].tap[k];
-                               kunmap(sg_page(&sg[k]));
                        }
                }
        }
@@ -1172,6 +1216,14 @@ static void do_test(void)
                test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
                            DES3_EDE_DEC_TEST_VECTORS);
 
+               test_cipher("cbc(des3_ede)", ENCRYPT,
+                           des3_ede_cbc_enc_tv_template,
+                           DES3_EDE_CBC_ENC_TEST_VECTORS);
+
+               test_cipher("cbc(des3_ede)", DECRYPT,
+                           des3_ede_cbc_dec_tv_template,
+                           DES3_EDE_CBC_DEC_TEST_VECTORS);
+
                test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
 
                test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
@@ -1382,6 +1434,14 @@ static void do_test(void)
                            DES3_EDE_ENC_TEST_VECTORS);
                test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
                            DES3_EDE_DEC_TEST_VECTORS);
+
+               test_cipher("cbc(des3_ede)", ENCRYPT,
+                           des3_ede_cbc_enc_tv_template,
+                           DES3_EDE_CBC_ENC_TEST_VECTORS);
+
+               test_cipher("cbc(des3_ede)", DECRYPT,
+                           des3_ede_cbc_dec_tv_template,
+                           DES3_EDE_CBC_DEC_TEST_VECTORS);
                break;
 
        case 5:
@@ -1550,7 +1610,7 @@ static void do_test(void)
        case 29:
                test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
                break;
-               
+
        case 30:
                test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
                            XETA_ENC_TEST_VECTORS);
@@ -1615,6 +1675,22 @@ static void do_test(void)
                            CTS_MODE_DEC_TEST_VECTORS);
                break;
 
+        case 39:
+               test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
+               break;
+
+        case 40:
+               test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
+               break;
+
+       case 41:
+               test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
+               break;
+
+       case 42:
+               test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
+               break;
+
        case 100:
                test_hash("hmac(md5)", hmac_md5_tv_template,
                          HMAC_MD5_TEST_VECTORS);
@@ -1650,6 +1726,16 @@ static void do_test(void)
                          XCBC_AES_TEST_VECTORS);
                break;
 
+       case 107:
+               test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
+                         HMAC_RMD128_TEST_VECTORS);
+               break;
+
+       case 108:
+               test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
+                         HMAC_RMD160_TEST_VECTORS);
+               break;
+
        case 200:
                test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
                                speed_template_16_24_32);
@@ -1788,6 +1874,22 @@ static void do_test(void)
                test_hash_speed("sha224", sec, generic_hash_speed_template);
                if (mode > 300 && mode < 400) break;
 
+       case 314:
+               test_hash_speed("rmd128", sec, generic_hash_speed_template);
+               if (mode > 300 && mode < 400) break;
+
+       case 315:
+               test_hash_speed("rmd160", sec, generic_hash_speed_template);
+               if (mode > 300 && mode < 400) break;
+
+       case 316:
+               test_hash_speed("rmd256", sec, generic_hash_speed_template);
+               if (mode > 300 && mode < 400) break;
+
+       case 317:
+               test_hash_speed("rmd320", sec, generic_hash_speed_template);
+               if (mode > 300 && mode < 400) break;
+
        case 399:
                break;
 
index 47bc0ec..801e0c2 100644 (file)
  * Software Foundation; either version 2 of the License, or (at your option)
  * any later version.
  *
- * 2007-11-13 Added GCM tests
- * 2007-11-13 Added AEAD support
- * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
- * 2004-08-09 Cipher speed tests by Reyk Floeter <reyk@vantronix.net>
- * 2003-09-14 Changes by Kartikey Mahendra Bhatt
- *
  */
 #ifndef _CRYPTO_TCRYPT_H
 #define _CRYPTO_TCRYPT_H
@@ -168,6 +162,271 @@ static struct hash_testvec md5_tv_template[] = {
                .digest = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
                          "\xac\x49\xda\x2e\x21\x07\xb6\x7a",
        }
+
+};
+
+/*
+ * RIPEMD-128 test vectors from ISO/IEC 10118-3:2004(E)
+ */
+#define RMD128_TEST_VECTORS     10
+
+static struct hash_testvec rmd128_tv_template[] = {
+       {
+               .digest = "\xcd\xf2\x62\x13\xa1\x50\xdc\x3e"
+                         "\xcb\x61\x0f\x18\xf6\xb3\x8b\x46",
+       }, {
+               .plaintext = "a",
+               .psize  = 1,
+               .digest = "\x86\xbe\x7a\xfa\x33\x9d\x0f\xc7"
+                         "\xcf\xc7\x85\xe7\x2f\x57\x8d\x33",
+       }, {
+               .plaintext = "abc",
+               .psize  = 3,
+               .digest = "\xc1\x4a\x12\x19\x9c\x66\xe4\xba"
+                         "\x84\x63\x6b\x0f\x69\x14\x4c\x77",
+       }, {
+               .plaintext = "message digest",
+               .psize  = 14,
+               .digest = "\x9e\x32\x7b\x3d\x6e\x52\x30\x62"
+                         "\xaf\xc1\x13\x2d\x7d\xf9\xd1\xb8",
+       }, {
+               .plaintext = "abcdefghijklmnopqrstuvwxyz",
+               .psize  = 26,
+               .digest = "\xfd\x2a\xa6\x07\xf7\x1d\xc8\xf5"
+                         "\x10\x71\x49\x22\xb3\x71\x83\x4e",
+       }, {
+               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
+                            "fghijklmnopqrstuvwxyz0123456789",
+               .psize  = 62,
+               .digest = "\xd1\xe9\x59\xeb\x17\x9c\x91\x1f"
+                         "\xae\xa4\x62\x4c\x60\xc5\xc7\x02",
+       }, {
+               .plaintext = "1234567890123456789012345678901234567890"
+                            "1234567890123456789012345678901234567890",
+               .psize  = 80,
+               .digest = "\x3f\x45\xef\x19\x47\x32\xc2\xdb"
+                         "\xb2\xc4\xa2\xc7\x69\x79\x5f\xa3",
+        }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighij"
+                            "hijkijkljklmklmnlmnomnopnopq",
+               .psize  = 56,
+               .digest = "\xa1\xaa\x06\x89\xd0\xfa\xfa\x2d"
+                         "\xdc\x22\xe8\x8b\x49\x13\x3a\x06",
+               .np     = 2,
+               .tap    = { 28, 28 },
+       }, {
+               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
+                            "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqr"
+                            "lmnopqrsmnopqrstnopqrstu",
+               .psize  = 112,
+               .digest = "\xd4\xec\xc9\x13\xe1\xdf\x77\x6b"
+                         "\xf4\x8d\xe9\xd5\x5b\x1f\x25\x46",
+       }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
+               .psize  = 32,
+               .digest = "\x13\xfc\x13\xe8\xef\xff\x34\x7d"
+                         "\xe1\x93\xff\x46\xdb\xac\xcf\xd4",
+       }
+};
+
+/*
+ * RIPEMD-160 test vectors from ISO/IEC 10118-3:2004(E)
+ */
+#define RMD160_TEST_VECTORS     10
+
+static struct hash_testvec rmd160_tv_template[] = {
+       {
+               .digest = "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28"
+                         "\x08\x97\x7e\xe8\xf5\x48\xb2\x25\x8d\x31",
+       }, {
+               .plaintext = "a",
+               .psize  = 1,
+               .digest = "\x0b\xdc\x9d\x2d\x25\x6b\x3e\xe9\xda\xae"
+                         "\x34\x7b\xe6\xf4\xdc\x83\x5a\x46\x7f\xfe",
+       }, {
+               .plaintext = "abc",
+               .psize  = 3,
+               .digest = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04"
+                         "\x4a\x8e\x98\xc6\xb0\x87\xf1\x5a\x0b\xfc",
+       }, {
+               .plaintext = "message digest",
+               .psize  = 14,
+               .digest = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8"
+                         "\x81\xb1\x23\xa8\x5f\xfa\x21\x59\x5f\x36",
+       }, {
+               .plaintext = "abcdefghijklmnopqrstuvwxyz",
+               .psize  = 26,
+               .digest = "\xf7\x1c\x27\x10\x9c\x69\x2c\x1b\x56\xbb"
+                         "\xdc\xeb\x5b\x9d\x28\x65\xb3\x70\x8d\xbc",
+       }, {
+               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
+                            "fghijklmnopqrstuvwxyz0123456789",
+               .psize  = 62,
+               .digest = "\xb0\xe2\x0b\x6e\x31\x16\x64\x02\x86\xed"
+                         "\x3a\x87\xa5\x71\x30\x79\xb2\x1f\x51\x89",
+       }, {
+               .plaintext = "1234567890123456789012345678901234567890"
+                            "1234567890123456789012345678901234567890",
+               .psize  = 80,
+               .digest = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb"
+                         "\xd3\x32\x3c\xab\x82\xbf\x63\x32\x6b\xfb",
+        }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighij"
+                            "hijkijkljklmklmnlmnomnopnopq",
+               .psize  = 56,
+               .digest = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05"
+                         "\xa0\x6c\x27\xdc\xf4\x9a\xda\x62\xeb\x2b",
+               .np     = 2,
+               .tap    = { 28, 28 },
+       }, {
+               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
+                            "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqr"
+                            "lmnopqrsmnopqrstnopqrstu",
+               .psize  = 112,
+               .digest = "\x6f\x3f\xa3\x9b\x6b\x50\x3c\x38\x4f\x91"
+                         "\x9a\x49\xa7\xaa\x5c\x2c\x08\xbd\xfb\x45",
+       }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
+               .psize  = 32,
+               .digest = "\x94\xc2\x64\x11\x54\x04\xe6\x33\x79\x0d"
+                         "\xfc\xc8\x7b\x58\x7d\x36\x77\x06\x7d\x9f",
+       }
+};
+
+/*
+ * RIPEMD-256 test vectors
+ */
+#define RMD256_TEST_VECTORS     8
+
+static struct hash_testvec rmd256_tv_template[] = {
+       {
+               .digest = "\x02\xba\x4c\x4e\x5f\x8e\xcd\x18"
+                         "\x77\xfc\x52\xd6\x4d\x30\xe3\x7a"
+                         "\x2d\x97\x74\xfb\x1e\x5d\x02\x63"
+                         "\x80\xae\x01\x68\xe3\xc5\x52\x2d",
+       }, {
+               .plaintext = "a",
+               .psize  = 1,
+               .digest = "\xf9\x33\x3e\x45\xd8\x57\xf5\xd9"
+                         "\x0a\x91\xba\xb7\x0a\x1e\xba\x0c"
+                         "\xfb\x1b\xe4\xb0\x78\x3c\x9a\xcf"
+                         "\xcd\x88\x3a\x91\x34\x69\x29\x25",
+       }, {
+               .plaintext = "abc",
+               .psize  = 3,
+               .digest = "\xaf\xbd\x6e\x22\x8b\x9d\x8c\xbb"
+                         "\xce\xf5\xca\x2d\x03\xe6\xdb\xa1"
+                         "\x0a\xc0\xbc\x7d\xcb\xe4\x68\x0e"
+                         "\x1e\x42\xd2\xe9\x75\x45\x9b\x65",
+       }, {
+               .plaintext = "message digest",
+               .psize  = 14,
+               .digest = "\x87\xe9\x71\x75\x9a\x1c\xe4\x7a"
+                         "\x51\x4d\x5c\x91\x4c\x39\x2c\x90"
+                         "\x18\xc7\xc4\x6b\xc1\x44\x65\x55"
+                         "\x4a\xfc\xdf\x54\xa5\x07\x0c\x0e",
+       }, {
+               .plaintext = "abcdefghijklmnopqrstuvwxyz",
+               .psize  = 26,
+               .digest = "\x64\x9d\x30\x34\x75\x1e\xa2\x16"
+                         "\x77\x6b\xf9\xa1\x8a\xcc\x81\xbc"
+                         "\x78\x96\x11\x8a\x51\x97\x96\x87"
+                         "\x82\xdd\x1f\xd9\x7d\x8d\x51\x33",
+       }, {
+               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
+                            "fghijklmnopqrstuvwxyz0123456789",
+               .psize  = 62,
+               .digest = "\x57\x40\xa4\x08\xac\x16\xb7\x20"
+                         "\xb8\x44\x24\xae\x93\x1c\xbb\x1f"
+                         "\xe3\x63\xd1\xd0\xbf\x40\x17\xf1"
+                         "\xa8\x9f\x7e\xa6\xde\x77\xa0\xb8",
+       }, {
+               .plaintext = "1234567890123456789012345678901234567890"
+                            "1234567890123456789012345678901234567890",
+               .psize  = 80,
+               .digest = "\x06\xfd\xcc\x7a\x40\x95\x48\xaa"
+                         "\xf9\x13\x68\xc0\x6a\x62\x75\xb5"
+                         "\x53\xe3\xf0\x99\xbf\x0e\xa4\xed"
+                         "\xfd\x67\x78\xdf\x89\xa8\x90\xdd",
+        }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighij"
+                            "hijkijkljklmklmnlmnomnopnopq",
+               .psize  = 56,
+               .digest = "\x38\x43\x04\x55\x83\xaa\xc6\xc8"
+                         "\xc8\xd9\x12\x85\x73\xe7\xa9\x80"
+                         "\x9a\xfb\x2a\x0f\x34\xcc\xc3\x6e"
+                         "\xa9\xe7\x2f\x16\xf6\x36\x8e\x3f",
+               .np     = 2,
+               .tap    = { 28, 28 },
+       }
+};
+
+/*
+ * RIPEMD-320 test vectors
+ */
+#define RMD320_TEST_VECTORS     8
+
+static struct hash_testvec rmd320_tv_template[] = {
+       {
+               .digest = "\x22\xd6\x5d\x56\x61\x53\x6c\xdc\x75\xc1"
+                         "\xfd\xf5\xc6\xde\x7b\x41\xb9\xf2\x73\x25"
+                         "\xeb\xc6\x1e\x85\x57\x17\x7d\x70\x5a\x0e"
+                         "\xc8\x80\x15\x1c\x3a\x32\xa0\x08\x99\xb8",
+       }, {
+               .plaintext = "a",
+               .psize  = 1,
+               .digest = "\xce\x78\x85\x06\x38\xf9\x26\x58\xa5\xa5"
+                         "\x85\x09\x75\x79\x92\x6d\xda\x66\x7a\x57"
+                         "\x16\x56\x2c\xfc\xf6\xfb\xe7\x7f\x63\x54"
+                         "\x2f\x99\xb0\x47\x05\xd6\x97\x0d\xff\x5d",
+       }, {
+               .plaintext = "abc",
+               .psize  = 3,
+               .digest = "\xde\x4c\x01\xb3\x05\x4f\x89\x30\xa7\x9d"
+                         "\x09\xae\x73\x8e\x92\x30\x1e\x5a\x17\x08"
+                         "\x5b\xef\xfd\xc1\xb8\xd1\x16\x71\x3e\x74"
+                         "\xf8\x2f\xa9\x42\xd6\x4c\xdb\xc4\x68\x2d",
+       }, {
+               .plaintext = "message digest",
+               .psize  = 14,
+               .digest = "\x3a\x8e\x28\x50\x2e\xd4\x5d\x42\x2f\x68"
+                         "\x84\x4f\x9d\xd3\x16\xe7\xb9\x85\x33\xfa"
+                         "\x3f\x2a\x91\xd2\x9f\x84\xd4\x25\xc8\x8d"
+                         "\x6b\x4e\xff\x72\x7d\xf6\x6a\x7c\x01\x97",
+       }, {
+               .plaintext = "abcdefghijklmnopqrstuvwxyz",
+               .psize  = 26,
+               .digest = "\xca\xbd\xb1\x81\x0b\x92\x47\x0a\x20\x93"
+                         "\xaa\x6b\xce\x05\x95\x2c\x28\x34\x8c\xf4"
+                         "\x3f\xf6\x08\x41\x97\x51\x66\xbb\x40\xed"
+                         "\x23\x40\x04\xb8\x82\x44\x63\xe6\xb0\x09",
+       }, {
+               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
+                            "fghijklmnopqrstuvwxyz0123456789",
+               .psize  = 62,
+               .digest = "\xed\x54\x49\x40\xc8\x6d\x67\xf2\x50\xd2"
+                         "\x32\xc3\x0b\x7b\x3e\x57\x70\xe0\xc6\x0c"
+                         "\x8c\xb9\xa4\xca\xfe\x3b\x11\x38\x8a\xf9"
+                         "\x92\x0e\x1b\x99\x23\x0b\x84\x3c\x86\xa4",
+       }, {
+               .plaintext = "1234567890123456789012345678901234567890"
+                            "1234567890123456789012345678901234567890",
+               .psize  = 80,
+               .digest = "\x55\x78\x88\xaf\x5f\x6d\x8e\xd6\x2a\xb6"
+                         "\x69\x45\xc6\xd2\xa0\xa4\x7e\xcd\x53\x41"
+                         "\xe9\x15\xeb\x8f\xea\x1d\x05\x24\x95\x5f"
+                         "\x82\x5d\xc7\x17\xe4\xa0\x08\xab\x2d\x42",
+        }, {
+               .plaintext = "abcdbcdecdefdefgefghfghighij"
+                            "hijkijkljklmklmnlmnomnopnopq",
+               .psize  = 56,
+               .digest = "\xd0\x34\xa7\x95\x0c\xf7\x22\x02\x1b\xa4"
+                         "\xb8\x4d\xf7\x69\xa5\xde\x20\x60\xe2\x59"
+                         "\xdf\x4c\x9b\xb4\xa4\x26\x8c\x0e\x93\x5b"
+                         "\xbc\x74\x70\xa9\x69\xc9\xd0\x72\xa1\xac",
+               .np     = 2,
+               .tap    = { 28, 28 },
+       }
 };
 
 /*
@@ -816,6 +1075,168 @@ static struct hash_testvec hmac_md5_tv_template[] =
        },
 };
 
+/*
+ * HMAC-RIPEMD128 test vectors from RFC2286
+ */
+#define HMAC_RMD128_TEST_VECTORS       7
+
+static struct hash_testvec hmac_rmd128_tv_template[] = {
+       {
+               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+               .ksize  = 16,
+               .plaintext = "Hi There",
+               .psize  = 8,
+               .digest = "\xfb\xf6\x1f\x94\x92\xaa\x4b\xbf"
+                         "\x81\xc1\x72\xe8\x4e\x07\x34\xdb",
+       }, {
+               .key    = "Jefe",
+               .ksize  = 4,
+               .plaintext = "what do ya want for nothing?",
+               .psize  = 28,
+               .digest = "\x87\x5f\x82\x88\x62\xb6\xb3\x34"
+                         "\xb4\x27\xc5\x5f\x9f\x7f\xf0\x9b",
+               .np     = 2,
+               .tap    = { 14, 14 },
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
+               .ksize  = 16,
+               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
+               .psize  = 50,
+               .digest = "\x09\xf0\xb2\x84\x6d\x2f\x54\x3d"
+                         "\xa3\x63\xcb\xec\x8d\x62\xa3\x8d",
+       }, {
+               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
+                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
+                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+               .ksize  = 25,
+               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
+               .psize  = 50,
+               .digest = "\xbd\xbb\xd7\xcf\x03\xe4\x4b\x5a"
+                         "\xa6\x0a\xf8\x15\xbe\x4d\x22\x94",
+       }, {
+               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
+               .ksize  = 16,
+               .plaintext = "Test With Truncation",
+               .psize  = 20,
+               .digest = "\xe7\x98\x08\xf2\x4b\x25\xfd\x03"
+                         "\x1c\x15\x5f\x0d\x55\x1d\x9a\x3a",
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa",
+               .ksize  = 80,
+               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
+               .psize  = 54,
+               .digest = "\xdc\x73\x29\x28\xde\x98\x10\x4a"
+                         "\x1f\x59\xd3\x73\xc1\x50\xac\xbb",
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa",
+               .ksize  = 80,
+               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
+                          "Block-Size Data",
+               .psize  = 73,
+               .digest = "\x5c\x6b\xec\x96\x79\x3e\x16\xd4"
+                         "\x06\x90\xc2\x37\x63\x5f\x30\xc5",
+       },
+};
+
+/*
+ * HMAC-RIPEMD160 test vectors from RFC2286
+ */
+#define HMAC_RMD160_TEST_VECTORS       7
+
+static struct hash_testvec hmac_rmd160_tv_template[] = {
+       {
+               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+               .ksize  = 20,
+               .plaintext = "Hi There",
+               .psize  = 8,
+               .digest = "\x24\xcb\x4b\xd6\x7d\x20\xfc\x1a\x5d\x2e"
+                         "\xd7\x73\x2d\xcc\x39\x37\x7f\x0a\x56\x68",
+       }, {
+               .key    = "Jefe",
+               .ksize  = 4,
+               .plaintext = "what do ya want for nothing?",
+               .psize  = 28,
+               .digest = "\xdd\xa6\xc0\x21\x3a\x48\x5a\x9e\x24\xf4"
+                         "\x74\x20\x64\xa7\xf0\x33\xb4\x3c\x40\x69",
+               .np     = 2,
+               .tap    = { 14, 14 },
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
+               .ksize  = 20,
+               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
+                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
+               .psize  = 50,
+               .digest = "\xb0\xb1\x05\x36\x0d\xe7\x59\x96\x0a\xb4"
+                         "\xf3\x52\x98\xe1\x16\xe2\x95\xd8\xe7\xc1",
+       }, {
+               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
+                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
+                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
+               .ksize  = 25,
+               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
+                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
+               .psize  = 50,
+               .digest = "\xd5\xca\x86\x2f\x4d\x21\xd5\xe6\x10\xe1"
+                         "\x8b\x4c\xf1\xbe\xb9\x7a\x43\x65\xec\xf4",
+       }, {
+               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
+               .ksize  = 20,
+               .plaintext = "Test With Truncation",
+               .psize  = 20,
+               .digest = "\x76\x19\x69\x39\x78\xf9\x1d\x90\x53\x9a"
+                         "\xe7\x86\x50\x0f\xf3\xd8\xe0\x51\x8e\x39",
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa",
+               .ksize  = 80,
+               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
+               .psize  = 54,
+               .digest = "\x64\x66\xca\x07\xac\x5e\xac\x29\xe1\xbd"
+                         "\x52\x3e\x5a\xda\x76\x05\xb7\x91\xfd\x8b",
+       }, {
+               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
+                       "\xaa\xaa",
+               .ksize  = 80,
+               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
+                          "Block-Size Data",
+               .psize  = 73,
+               .digest = "\x69\xea\x60\x79\x8d\x71\x61\x6c\xce\x5f"
+                         "\xd0\x87\x1e\x23\x75\x4c\xd7\x5d\x5a\x0a",
+       },
+};
+
 /*
  * HMAC-SHA1 test vectors from RFC2202
  */
@@ -1442,6 +1863,8 @@ static struct hash_testvec hmac_sha512_tv_template[] = {
 #define DES_CBC_DEC_TEST_VECTORS       4
 #define DES3_EDE_ENC_TEST_VECTORS      3
 #define DES3_EDE_DEC_TEST_VECTORS      3
+#define DES3_EDE_CBC_ENC_TEST_VECTORS  1
+#define DES3_EDE_CBC_DEC_TEST_VECTORS  1
 
 static struct cipher_testvec des_enc_tv_template[] = {
        { /* From Applied Cryptography */
@@ -1680,9 +2103,6 @@ static struct cipher_testvec des_cbc_dec_tv_template[] = {
        },
 };
 
-/*
- * We really need some more test vectors, especially for DES3 CBC.
- */
 static struct cipher_testvec des3_ede_enc_tv_template[] = {
        { /* These are from openssl */
                .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
@@ -1745,6 +2165,94 @@ static struct cipher_testvec des3_ede_dec_tv_template[] = {
        },
 };
 
+static struct cipher_testvec des3_ede_cbc_enc_tv_template[] = {
+       { /* Generated from openssl */
+               .key    = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
+                         "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
+                         "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
+               .klen   = 24,
+               .iv     = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
+               .input  = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
+                         "\x53\x20\x63\x65\x65\x72\x73\x74"
+                         "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
+                         "\x20\x79\x65\x53\x72\x63\x74\x65"
+                         "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
+                         "\x79\x6e\x53\x20\x63\x65\x65\x72"
+                         "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
+                         "\x6e\x61\x20\x79\x65\x53\x72\x63"
+                         "\x74\x65\x20\x73\x6f\x54\x20\x6f"
+                         "\x61\x4d\x79\x6e\x53\x20\x63\x65"
+                         "\x65\x72\x73\x74\x54\x20\x6f\x6f"
+                         "\x4d\x20\x6e\x61\x20\x79\x65\x53"
+                         "\x72\x63\x74\x65\x20\x73\x6f\x54"
+                         "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
+                         "\x63\x65\x65\x72\x73\x74\x54\x20"
+                         "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
+               .ilen   = 128,
+               .result = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
+                         "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
+                         "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
+                         "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
+                         "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
+                         "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
+                         "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
+                         "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
+                         "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
+                         "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
+                         "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
+                         "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
+                         "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
+                         "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
+                         "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
+                         "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
+               .rlen   = 128,
+       },
+};
+
+static struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
+       { /* Generated from openssl */
+               .key    = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
+                         "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
+                         "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
+               .klen   = 24,
+               .iv     = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
+               .input  = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
+                         "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
+                         "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
+                         "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
+                         "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
+                         "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
+                         "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
+                         "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
+                         "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
+                         "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
+                         "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
+                         "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
+                         "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
+                         "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
+                         "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
+                         "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
+               .ilen   = 128,
+               .result = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
+                         "\x53\x20\x63\x65\x65\x72\x73\x74"
+                         "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
+                         "\x20\x79\x65\x53\x72\x63\x74\x65"
+                         "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
+                         "\x79\x6e\x53\x20\x63\x65\x65\x72"
+                         "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
+                         "\x6e\x61\x20\x79\x65\x53\x72\x63"
+                         "\x74\x65\x20\x73\x6f\x54\x20\x6f"
+                         "\x61\x4d\x79\x6e\x53\x20\x63\x65"
+                         "\x65\x72\x73\x74\x54\x20\x6f\x6f"
+                         "\x4d\x20\x6e\x61\x20\x79\x65\x53"
+                         "\x72\x63\x74\x65\x20\x73\x6f\x54"
+                         "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
+                         "\x63\x65\x65\x72\x73\x74\x54\x20"
+                         "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
+               .rlen   = 128,
+       },
+};
+
 /*
  * Blowfish test vectors.
  */
index f65deda..fda4467 100644 (file)
@@ -10,6 +10,7 @@ obj-$(CONFIG_PCI)             += pci/
 obj-$(CONFIG_PARISC)           += parisc/
 obj-$(CONFIG_RAPIDIO)          += rapidio/
 obj-y                          += video/
+obj-y                          += gpu/
 obj-$(CONFIG_ACPI)             += acpi/
 # PnP must come after ACPI since it will eventually need to check if acpi
 # was used and do nothing if so
diff --git a/drivers/acorn/char/Makefile b/drivers/acorn/char/Makefile
deleted file mode 100644 (file)
index d006c9f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Makefile for the acorn character device drivers.
-#
-
-obj-$(CONFIG_L7200_KEYB)       += defkeymap-l7200.o keyb_l7200.o
diff --git a/drivers/acorn/char/defkeymap-l7200.c b/drivers/acorn/char/defkeymap-l7200.c
deleted file mode 100644 (file)
index 93d80a1..0000000
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * linux/drivers/acorn/char/defkeymap-l7200.c
- *
- * Default keyboard maps for LinkUp Systems L7200 board
- *
- * Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *   08-04-2000 SJH     Created file
- */
-
-#include <linux/types.h>
-#include <linux/keyboard.h>
-#include <linux/kd.h>
-
-/* Normal (maps 1:1 with no processing) */
-#define KTn    0xF0
-/* Function keys */
-#define KTf    0xF1
-/* Special (Performs special house-keeping funcs) */
-#define KTs    0xF2
-#define KIGNORE                K(KTs, 0)       /* Ignore */
-#define KENTER         K(KTs, 1)       /* Enter */
-#define KREGS          K(KTs, 2)       /* Regs */
-#define KMEM           K(KTs, 3)       /* Mem */
-#define KSTAT          K(KTs, 4)       /* State */
-#define KINTR          K(KTs, 5)       /* Intr */
-#define Ksl    6       /* Last console */
-#define KCAPSLK                K(KTs, 7)       /* Caps lock */
-#define KNUMLK         K(KTs, 8)       /* Num-lock */
-#define KSCRLLK                K(KTs, 9)       /* Scroll-lock */
-#define KSCRLFOR       K(KTs,10)       /* Scroll forward */
-#define KSCRLBAK       K(KTs,11)       /* Scroll back */
-#define KREBOOT                K(KTs,12)       /* Reboot */
-#define KCAPSON                K(KTs,13)       /* Caps on */
-#define KCOMPOSE       K(KTs,14)       /* Compose */
-#define KSAK           K(KTs,15)       /* SAK */
-#define CONS_DEC       K(KTs,16)       /* Dec console */
-#define CONS_INC       K(KTs,17)       /* Incr console */
-#define KFLOPPY                K(KTs,18)       /* Floppy */
-/* Key pad (0-9 = digits, 10=+, 11=-, 12=*, 13=/, 14=enter, 16=., 17=# */
-#define KTp    0xF3
-#define KPAD_0         K(KTp, 0 )
-#define KPAD_1         K(KTp, 1 )
-#define KPAD_2         K(KTp, 2 )
-#define KPAD_3         K(KTp, 3 )
-#define KPAD_4         K(KTp, 4 )
-#define KPAD_5         K(KTp, 5 )
-#define KPAD_6         K(KTp, 6 )
-#define KPAD_7         K(KTp, 7 )
-#define KPAD_8         K(KTp, 8 )
-#define KPAD_9         K(KTp, 9 )
-#define KPAD_PL                K(KTp,10 )
-#define KPAD_MI                K(KTp,11 )
-#define KPAD_ML                K(KTp,12 )
-#define KPAD_DV                K(KTp,13 )
-#define KPAD_EN                K(KTp,14 )
-#define KPAD_DT                K(KTp,16 )
-#define KPAD_HS                K(KTp,20 )
-/* Console switching */
-#define KCn    0xF5
-/* Cursor */
-#define KTc    0xF6
-#define Kcd    0       /* Cursor down */
-#define Kcl    1       /* Cursor left */
-#define Kcr    2       /* Cursor right */
-#define Kcu    3       /* Cursor up */
-/* Shift/alt modifiers etc */
-#define KMd    0xF7
-#define KSHIFT         K(KMd, 0 )
-#define KALTGR         K(KMd, 1 )
-#define KCTRL          K(KMd, 2 )
-#define KALT           K(KMd, 3 )
-/* Meta */
-#define KMt    0xF8
-#define KAs    0xF9
-#define KPADA_0                K(KAs, 0 )
-#define KPADA_1                K(KAs, 1 )
-#define KPADA_2                K(KAs, 2 )
-#define KPADA_3                K(KAs, 3 )
-#define KPADA_4                K(KAs, 4 )
-#define KPADA_5                K(KAs, 5 )
-#define KPADA_6                K(KAs, 6 )
-#define KPADA_7                K(KAs, 7 )
-#define KPADA_8                K(KAs, 8 )
-#define KPADA_9                K(KAs, 9 )
-#define KPADB_0                K(KAs,10 )
-#define KPADB_1                K(KAs,11 )
-#define KPADB_2                K(KAs,12 )
-#define KPADB_3                K(KAs,13 )
-#define KPADB_4                K(KAs,14 )
-#define KPADB_5                K(KAs,15 )
-#define KPADB_6                K(KAs,16 )
-#define KPADB_7                K(KAs,17 )
-#define KPADB_8                K(KAs,18 )
-#define KPADB_9                K(KAs,19 )
-/* Locking keys */
-#define KLk    0xFA
-/* Letters */
-#define KTl    0xFB
-
-/*
- * Here is the layout of the keys for the Fujitsu QWERTY
- * style keyboard:
- *
- *     static char Fujitsu_Key_Table[] =
- *     {
- *        KALT, '`' , KNUL, KCTL, KFUN, KESC, '1' , '2' ,
- *       '9' , '0' , '-' , '=' , KNUL, KBSP, KNUL, KNUL,
- *       KNUL, KBSL, KSHF, KNUL, KNUL, KDEL, KNUL, 't' ,
- *       'y' , 'u' , 'i' , KRET, KSHF, KPGD, KNUL, KNUL,
- *       KNUL, KTAB, KNUL, KNUL, KNUL, 'q' , 'w' , 'e' ,
- *       'r' , 'o' , 'p' , '[' , KNUL, ']' , KNUL, KNUL,
- *       KNUL, 'z' , KNUL, KNUL, KNUL, KSHL, KNUL, KNUL,
- *       'k' , 'l' , ';' , KSQT, KNUL, KPGU, KNUL, KNUL,
- *       KNUL, 'a' , KNUL, KNUL, KNUL, 's' , 'd' , 'f' ,
- *       'g' , 'h' , 'j' , '/' , KNUL, KHME, KNUL, KNUL,
- *       KNUL, 'x' , KNUL, KNUL, KNUL, 'c' , 'v' , 'b' ,
- *       'n' , 'm' , ',' , '.' , KNUL, ' ' , KNUL, KNUL,
- *       KNUL, KNUL, KNUL, KNUL, KNUL, '3' , '4' , '5' ,
- *       '6' , '7' , '8' , KNUL, KPRG, KNUL, KEND, KNUL,
- *     };
- */
-
-u_short plain_map[NR_KEYS]=
-{
-       0xf703, 0xf060, 0xf200, 0xf702, 0xf200, 0xf01b, 0xf031, 0xf032,
-       0xf039, 0xf030, 0xf02d, 0xf03d, 0xf200, 0xf07f, 0xf200, 0xf200,
-       0xf200, 0xf05c, 0xf700, 0xf200, 0xf200, 0xf116, 0xf000, 0xfb74,
-       0xfb79, 0xfb75, 0xfb69, 0xf201, 0xf700, 0xf600, 0xf200, 0xf200,
-       0xf200, 0xf009, 0xf200, 0xf200, 0xf200, 0xfb71, 0xfb77, 0xfb65,
-       0xfb72, 0xfb6f, 0xfb70, 0xf05b, 0xf200, 0xf05d, 0xf200, 0xf200,
-       0xf200, 0xfb7a, 0xf200, 0xf200, 0xf200, 0xf207, 0xf200, 0xf200,
-       0xfb6b, 0xfb6c, 0xf03b, 0xf027, 0xf200, 0xf603, 0xf200, 0xf200,
-       0xf200, 0xfb61, 0xf200, 0xf200, 0xf200, 0xfb73, 0xfb64, 0xfb66,
-       0xfb67, 0xfb68, 0xfb6a, 0xf02f, 0xf200, 0xf601, 0xf200, 0xf200,
-       0xf200, 0xfb78, 0xf200, 0xf200, 0xf200, 0xfb63, 0xfb76, 0xfb62,
-       0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf200, 0xf020, 0xf200, 0xf200,
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf033, 0xf034, 0xf035, 
-       0xf036, 0xf037, 0xf038, 0xf200, 0xf200, 0xf200, 0xf602, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 
-};
-
-u_short shift_map[NR_KEYS]=
-{
-       0xf703, 0xf07e, 0xf200, 0xf702, 0xf200, 0xf01b, 0xf021, 0xf040,
-       0xf028, 0xf029, 0xf05f, 0xf02b, 0xf200, 0xf07f, 0xf200, 0xf200,
-       0xf200, 0xf07c, 0xf700, 0xf200, 0xf200, 0xf116, 0xf000, 0xfb54,
-       0xfb59, 0xfb55, 0xfb49, 0xf201, 0xf700, 0xf600, 0xf200, 0xf200,
-       0xf200, 0xf009, 0xf200, 0xf200, 0xf200, 0xfb51, 0xfb57, 0xfb45,
-       0xfb52, 0xfb4f, 0xfb50, 0xf07b, 0xf200, 0xf07d, 0xf200, 0xf200,
-       0xf200, 0xfb5a, 0xf200, 0xf200, 0xf200, 0xf207, 0xf200, 0xf200,
-       0xfb4b, 0xfb4c, 0xf03a, 0xf022, 0xf200, 0xf603, 0xf200, 0xf200,
-       0xf200, 0xfb41, 0xf200, 0xf200, 0xf200, 0xfb53, 0xfb44, 0xfb46,
-       0xfb47, 0xfb48, 0xfb4a, 0xf03f, 0xf200, 0xf601, 0xf200, 0xf200,
-       0xf200, 0xfb58, 0xf200, 0xf200, 0xf200, 0xfb43, 0xfb56, 0xfb42,
-       0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf200, 0xf020, 0xf200, 0xf200,
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf023, 0xf024, 0xf025, 
-       0xf05e, 0xf026, 0xf02a, 0xf200, 0xf200, 0xf200, 0xf602, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 
-};
-
-u_short altgr_map[NR_KEYS]=
-{
-  KIGNORE   ,K(KCn,12 ),K(KCn,13 ),K(KCn,14  ),K(KCn,15 ),K(KCn,16 ),K(KCn,17  ),K(KCn, 18),
-  K(KCn, 19),K(KCn,20 ),K(KCn,21 ),K(KCn,22  ),K(KCn,23 ),KIGNORE   ,KREGS      ,KINTR     ,
-  KIGNORE   ,KIGNORE   ,K(KTn,'@'),KIGNORE    ,K(KTn,'$'),KIGNORE   ,KIGNORE    ,K(KTn,'{'),
-  K(KTn,'['),K(KTn,']'),K(KTn,'}'),K(KTn,'\\'),KIGNORE   ,KIGNORE   ,KIGNORE    ,K(KTf,21 ),
-  K(KTf,20 ),K(KTf,24 ),KNUMLK    ,KPAD_DV    ,KPAD_ML   ,KPAD_HS   ,KIGNORE    ,K(KTl,'q'),
-  K(KTl,'w'),K(KTl,'e'),K(KTl,'r'),K(KTl,'t' ),K(KTl,'y'),K(KTl,'u'),K(KTl,'i' ),K(KTl,'o'),
-  K(KTl,'p'),KIGNORE   ,K(KTn,'~'),KIGNORE    ,K(KTf,22 ),K(KTf,23 ),K(KTf,25  ),KPADB_7   ,
-  KPADB_8   ,KPADB_9   ,KPAD_MI   ,KCTRL      ,K(KAs,20 ),K(KTl,'s'),K(KAs,23  ),K(KAs,25 ),
-  K(KTl,'g'),K(KTl,'h'),K(KTl,'j'),K(KTl,'k' ),K(KTl,'l'),KIGNORE   ,KIGNORE    ,KENTER    ,
-  KPADB_4   ,KPADB_5   ,KPADB_6   ,KPAD_PL    ,KSHIFT    ,KIGNORE   ,K(KTl,'z' ),K(KTl,'x'),
-  K(KAs,22 ),K(KTl,'v'),K(KTl,21 ),K(KTl,'n' ),K(KTl,'m'),KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KSHIFT    ,K(KTc,Kcu),KPADB_1   ,KPADB_2    ,KPADB_3   ,KCAPSLK   ,KALT       ,KIGNORE   ,
-  KALTGR    ,KCTRL     ,K(KTc,Kcl),K(KTc,Kcd ),K(KTc,Kcr),KPADB_0   ,KPAD_DT    ,KPAD_EN   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-};
-
-u_short ctrl_map[NR_KEYS]=
-{
-       0xf703, 0xf200, 0xf200, 0xf702, 0xf200, 0xf200, 0xf001, 0xf002,
-       0xf009, 0xf000, 0xf031, 0xf200, 0xf200, 0xf07f, 0xf200, 0xf200,
-       0xf200, 0xf01c, 0xf700, 0xf200, 0xf200, 0xf116, 0xf000, 0xf020,
-       0xf019, 0xf015, 0xf009, 0xf201, 0xf700, 0xf600, 0xf200, 0xf200,
-       0xf200, 0xf009, 0xf200, 0xf200, 0xf200, 0xf011, 0xf017, 0xf005,
-       0xf012, 0xf00f, 0xf010, 0xf01b, 0xf200, 0xf01d, 0xf200, 0xf200,
-       0xf200, 0xf01a, 0xf200, 0xf200, 0xf200, 0xf207, 0xf200, 0xf200,
-       0xf00b, 0xf00c, 0xf200, 0xf007, 0xf200, 0xf603, 0xf200, 0xf200,
-       0xf200, 0xf001, 0xf200, 0xf200, 0xf200, 0xf001, 0xf013, 0xf006,
-       0xf007, 0xf008, 0xf00a, 0xf07f, 0xf200, 0xf601, 0xf200, 0xf200,
-       0xf200, 0xf018, 0xf200, 0xf200, 0xf200, 0xf003, 0xf016, 0xf002,
-       0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf000, 0xf200, 0xf200,
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b, 0xf01c, 0xf01d, 
-       0xf036, 0xf037, 0xf038, 0xf200, 0xf200, 0xf200, 0xf602, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 
-       0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf602, 0xf200, 
-};
-
-u_short shift_ctrl_map[NR_KEYS]=
-{
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KFLOPPY    ,KINTR     ,
-  KIGNORE   ,KIGNORE   ,K(KTn, 0 ),KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,K(KTn,31  ),KIGNORE   ,KIGNORE   ,KIGNORE    ,K(KTf,21 ),
-  K(KTf,20 ),K(KTf,24 ),KNUMLK    ,KPAD_DV    ,KPAD_ML   ,KPAD_HS   ,KIGNORE    ,K(KTn,17 ),
-  K(KTn,23 ),K(KTn, 5 ),K(KTn,18 ),K(KTn,20  ),K(KTn,25 ),K(KTn,21 ),K(KTn, 9  ),K(KTn,15 ),
-  K(KTn,16 ),KIGNORE   ,KIGNORE   ,KIGNORE    ,K(KTf,22 ),K(KTf,23 ),K(KTf,25  ),KPAD_7    ,
-  KPAD_8    ,KPAD_9    ,KPAD_MI   ,KCTRL      ,K(KTn, 1 ),K(KTn,19 ),K(KTn, 4  ),K(KTn, 6 ),
-  K(KTn, 7 ),K(KTn, 8 ),K(KTn,10 ),K(KTn,11  ),K(KTn,12 ),KIGNORE   ,K(KTn, 7  ),KENTER    ,
-  KPAD_4    ,KPAD_5    ,KPAD_6    ,KPAD_PL    ,KSHIFT    ,KIGNORE   ,K(KTn,26  ),K(KTn,24 ),
-  K(KTn, 3 ),K(KTn,22 ),K(KTn, 2 ),K(KTn,14  ),K(KTn,13 ),KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KSHIFT    ,K(KTc,Kcu),KPAD_1    ,KPAD_2     ,KPAD_3    ,KCAPSLK   ,KALT       ,K(KTn, 0 ),
-  KALTGR    ,KCTRL     ,K(KTc,Kcl),K(KTc,Kcd ),K(KTc,Kcr),KPAD_0    ,KPAD_DT    ,KPAD_EN   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-};
-
-u_short alt_map[NR_KEYS]=
-{
-  K(KMt,27 ),K(KCn, 0 ),K(KCn, 1 ),K(KCn, 2  ),K(KCn, 3 ),K(KCn, 4 ),K(KCn, 5  ),K(KCn, 6 ),
-  K(KCn, 7 ),K(KCn, 8 ),K(KCn, 9 ),K(KCn,10  ),K(KCn,11 ),KIGNORE   ,KSCRLLK    ,KINTR     ,
-  K(KMt,'`'),K(KMt,'1'),K(KMt,'2'),K(KMt,'3' ),K(KMt,'4'),K(KMt,'5'),K(KMt,'6' ),K(KMt,'7'),
-  K(KMt,'8'),K(KMt,'9'),K(KMt,'0'),K(KMt,'-' ),K(KMt,'='),K(KMt,'£'),K(KMt,127 ),K(KTf,21 ),
-  K(KTf,20 ),K(KTf,24 ),KNUMLK    ,KPAD_DV    ,KPAD_ML   ,KPAD_HS   ,K(KMt, 9  ),K(KMt,'q'),
-  K(KMt,'w'),K(KMt,'e'),K(KMt,'r'),K(KMt,'t' ),K(KMt,'y'),K(KMt,'u'),K(KMt,'i' ),K(KMt,'o'),
-  K(KMt,'p'),K(KMt,'['),K(KMt,']'),K(KMt,'\\'),K(KTf,22 ),K(KTf,23 ),K(KTf,25  ),KPADA_7   ,
-  KPADA_8   ,KPADA_9   ,KPAD_MI   ,KCTRL      ,K(KMt,'a'),K(KMt,'s'),K(KMt,'d' ),K(KMt,'f'),
-  K(KMt,'g'),K(KMt,'h'),K(KMt,'j'),K(KMt,'k' ),K(KMt,'l'),K(KMt,';'),K(KMt,'\''),K(KMt,13 ),
-  KPADA_4   ,KPADA_5   ,KPADA_6   ,KPAD_PL    ,KSHIFT    ,KIGNORE   ,K(KMt,'z' ),K(KMt,'x'),
-  K(KMt,'c'),K(KMt,'v'),K(KMt,'b'),K(KMt,'n' ),K(KMt,'m'),K(KMt,','),K(KMt,'.' ),KIGNORE   ,
-  KSHIFT    ,K(KTc,Kcu),KPADA_1   ,KPADA_2    ,KPADA_3   ,KCAPSLK   ,KALT       ,K(KMt,' '),
-  KALTGR    ,KCTRL     ,CONS_DEC  ,K(KTc,Kcd ),CONS_INC  ,KPADA_0   ,KPAD_DT    ,KPAD_EN   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-};
-
-u_short ctrl_alt_map[NR_KEYS]=
-{
-  KIGNORE   ,K(KCn, 0 ),K(KCn, 1 ),K(KCn, 2  ),K(KCn, 3 ),K(KCn, 4 ),K(KCn, 5  ),K(KCn, 6 ),
-  K(KCn, 7 ),K(KCn, 8 ),K(KCn, 9 ),K(KCn,10  ),K(KCn,11 ),KIGNORE   ,KIGNORE    ,KINTR     ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,K(KTf,21 ),
-  K(KTf,20 ),K(KTf,24 ),KNUMLK    ,KPAD_DV    ,KPAD_ML   ,KPAD_HS   ,KIGNORE    ,K(KMt,17 ),
-  K(KMt,23 ),K(KMt, 5 ),K(KMt,18 ),K(KMt,20  ),K(KMt,25 ),K(KMt,21 ),K(KMt, 9  ),K(KMt,15 ),
-  K(KMt,16 ),KIGNORE   ,KIGNORE   ,KIGNORE    ,KREBOOT   ,K(KTf,23 ),K(KTf,25  ),KPAD_7    ,
-  KPAD_8    ,KPAD_9    ,KPAD_MI   ,KCTRL      ,K(KMt, 1 ),K(KMt,19 ),K(KMt, 4  ),K(KMt, 6 ),
-  K(KMt, 7 ),K(KMt, 8 ),K(KMt,10 ),K(KMt,11  ),K(KMt,12 ),KIGNORE   ,KIGNORE    ,KENTER    ,
-  KPAD_4    ,KPAD_5    ,KPAD_6    ,KPAD_PL    ,KSHIFT    ,KIGNORE   ,K(KMt,26  ),K(KMt,24 ),
-  K(KMt, 3 ),K(KMt,22 ),K(KMt, 2 ),K(KMt,14  ),K(KMt,13 ),KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KSHIFT    ,K(KTc,Kcu),KPAD_1    ,KPAD_2     ,KPAD_3    ,KCAPSLK   ,KALT       ,KIGNORE   ,
-  KALTGR    ,KCTRL     ,K(KTc,Kcl),K(KTc,Kcd ),K(KTc,Kcr),KPAD_0    ,KREBOOT    ,KPAD_EN   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-  KIGNORE   ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,KIGNORE   ,KIGNORE    ,KIGNORE   ,
-};
-
-ushort *key_maps[MAX_NR_KEYMAPS] = {
-       plain_map, shift_map, altgr_map, 0,
-       ctrl_map, shift_ctrl_map, 0, 0,
-       alt_map, 0, 0, 0,
-       ctrl_alt_map,   0
-};
-
-unsigned int keymap_count = 7;
-
-/*
- * Philosophy: most people do not define more strings, but they who do
- * often want quite a lot of string space. So, we statically allocate
- * the default and allocate dynamically in chunks of 512 bytes.
- */
-
-char func_buf[] = {
-       '\033', '[', '[', 'A', 0,
-       '\033', '[', '[', 'B', 0,
-       '\033', '[', '[', 'C', 0,
-       '\033', '[', '[', 'D', 0,
-       '\033', '[', '[', 'E', 0,
-       '\033', '[', '1', '7', '~', 0,
-       '\033', '[', '1', '8', '~', 0,
-       '\033', '[', '1', '9', '~', 0,
-       '\033', '[', '2', '0', '~', 0,
-       '\033', '[', '2', '1', '~', 0,
-       '\033', '[', '2', '3', '~', 0,
-       '\033', '[', '2', '4', '~', 0,
-       '\033', '[', '2', '5', '~', 0,
-       '\033', '[', '2', '6', '~', 0,
-       '\033', '[', '2', '8', '~', 0,
-       '\033', '[', '2', '9', '~', 0,
-       '\033', '[', '3', '1', '~', 0,
-       '\033', '[', '3', '2', '~', 0,
-       '\033', '[', '3', '3', '~', 0,
-       '\033', '[', '3', '4', '~', 0,
-       '\033', '[', '1', '~', 0,
-       '\033', '[', '2', '~', 0,
-       '\033', '[', '3', '~', 0,
-       '\033', '[', '4', '~', 0,
-       '\033', '[', '5', '~', 0,
-       '\033', '[', '6', '~', 0,
-       '\033', '[', 'M', 0,
-       '\033', '[', 'P', 0,
-};
-
-char *funcbufptr = func_buf;
-int funcbufsize = sizeof(func_buf);
-int funcbufleft = 0;          /* space left */
-
-char *func_table[MAX_NR_FUNC] = {
-       func_buf + 0,
-       func_buf + 5,
-       func_buf + 10,
-       func_buf + 15,
-       func_buf + 20,
-       func_buf + 25,
-       func_buf + 31,
-       func_buf + 37,
-       func_buf + 43,
-       func_buf + 49,
-       func_buf + 55,
-       func_buf + 61,
-       func_buf + 67,
-       func_buf + 73,
-       func_buf + 79,
-       func_buf + 85,
-       func_buf + 91,
-       func_buf + 97,
-       func_buf + 103,
-       func_buf + 109,
-       func_buf + 115,
-       func_buf + 120,
-       func_buf + 125,
-       func_buf + 130,
-       func_buf + 135,
-       func_buf + 140,
-       func_buf + 145,
-       0,
-       0,
-       func_buf + 149,
-       0,
-};
-
-struct kbdiacruc accent_table[MAX_DIACR] = {
-       {'`', 'A', 0300},       {'`', 'a', 0340},
-       {'\'', 'A', 0301},      {'\'', 'a', 0341},
-       {'^', 'A', 0302},       {'^', 'a', 0342},
-       {'~', 'A', 0303},       {'~', 'a', 0343},
-       {'"', 'A', 0304},       {'"', 'a', 0344},
-       {'O', 'A', 0305},       {'o', 'a', 0345},
-       {'0', 'A', 0305},       {'0', 'a', 0345},
-       {'A', 'A', 0305},       {'a', 'a', 0345},
-       {'A', 'E', 0306},       {'a', 'e', 0346},
-       {',', 'C', 0307},       {',', 'c', 0347},
-       {'`', 'E', 0310},       {'`', 'e', 0350},
-       {'\'', 'E', 0311},      {'\'', 'e', 0351},
-       {'^', 'E', 0312},       {'^', 'e', 0352},
-       {'"', 'E', 0313},       {'"', 'e', 0353},
-       {'`', 'I', 0314},       {'`', 'i', 0354},
-       {'\'', 'I', 0315},      {'\'', 'i', 0355},
-       {'^', 'I', 0316},       {'^', 'i', 0356},
-       {'"', 'I', 0317},       {'"', 'i', 0357},
-       {'-', 'D', 0320},       {'-', 'd', 0360},
-       {'~', 'N', 0321},       {'~', 'n', 0361},
-       {'`', 'O', 0322},       {'`', 'o', 0362},
-       {'\'', 'O', 0323},      {'\'', 'o', 0363},
-       {'^', 'O', 0324},       {'^', 'o', 0364},
-       {'~', 'O', 0325},       {'~', 'o', 0365},
-       {'"', 'O', 0326},       {'"', 'o', 0366},
-       {'/', 'O', 0330},       {'/', 'o', 0370},
-       {'`', 'U', 0331},       {'`', 'u', 0371},
-       {'\'', 'U', 0332},      {'\'', 'u', 0372},
-       {'^', 'U', 0333},       {'^', 'u', 0373},
-       {'"', 'U', 0334},       {'"', 'u', 0374},
-       {'\'', 'Y', 0335},      {'\'', 'y', 0375},
-       {'T', 'H', 0336},       {'t', 'h', 0376},
-       {'s', 's', 0337},       {'"', 'y', 0377},
-       {'s', 'z', 0337},       {'i', 'j', 0377},
-};
-
-unsigned int accent_table_size = 68;
index c52fca8..bba8673 100644 (file)
@@ -4,8 +4,6 @@
 
 menuconfig ACPI
        bool "ACPI (Advanced Configuration and Power Interface) Support"
-       depends on !X86_NUMAQ
-       depends on !X86_VISWS
        depends on !IA64_HP_SIM
        depends on IA64 || X86
        depends on PCI
index 57a4364..499ccc6 100644 (file)
@@ -885,7 +885,8 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
                /* set the min alignment and padding */
                blk_queue_update_dma_alignment(sdev->request_queue,
                                               ATA_DMA_PAD_SZ - 1);
-               blk_queue_dma_pad(sdev->request_queue, ATA_DMA_PAD_SZ - 1);
+               blk_queue_update_dma_pad(sdev->request_queue,
+                                        ATA_DMA_PAD_SZ - 1);
 
                /* configure draining */
                buf = kmalloc(ATAPI_MAX_DRAIN, q->bounce_gfp | GFP_KERNEL);
index 2b4b392..87a7f1d 100644 (file)
@@ -153,7 +153,7 @@ EXPORT_SYMBOL(set_trace_device);
  * it's not any guarantee, but it's a high _likelihood_ that
  * the match is valid).
  */
-void generate_resume_trace(void *tracedata, unsigned int user)
+void generate_resume_trace(const void *tracedata, unsigned int user)
 {
        unsigned short lineno = *(unsigned short *)tracedata;
        const char *file = *(const char **)(tracedata + 2);
index fdf4044..1efe162 100644 (file)
@@ -40,6 +40,7 @@ static ssize_t show_##name(struct sys_device *dev, char *buf) \
        return sprintf(buf, "%d\n", topology_##name(cpu));      \
 }
 
+#if defined(topology_thread_siblings) || defined(topology_core_siblings)
 static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
 {
        ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
@@ -54,21 +55,41 @@ static ssize_t show_cpumap(int type, cpumask_t *mask, char *buf)
        }
        return n;
 }
+#endif
 
+#ifdef arch_provides_topology_pointers
 #define define_siblings_show_map(name)                                 \
-static inline ssize_t show_##name(struct sys_device *dev, char *buf)   \
+static ssize_t show_##name(struct sys_device *dev, char *buf)  \
 {                                                                      \
        unsigned int cpu = dev->id;                                     \
        return show_cpumap(0, &(topology_##name(cpu)), buf);            \
 }
 
 #define define_siblings_show_list(name)                                        \
-static inline ssize_t show_##name##_list(struct sys_device *dev, char *buf) \
+static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \
 {                                                                      \
        unsigned int cpu = dev->id;                                     \
        return show_cpumap(1, &(topology_##name(cpu)), buf);            \
 }
 
+#else
+#define define_siblings_show_map(name)                                 \
+static ssize_t show_##name(struct sys_device *dev, char *buf)  \
+{                                                                      \
+       unsigned int cpu = dev->id;                                     \
+       cpumask_t mask = topology_##name(cpu);                          \
+       return show_cpumap(0, &mask, buf);                              \
+}
+
+#define define_siblings_show_list(name)                                        \
+static ssize_t show_##name##_list(struct sys_device *dev, char *buf) \
+{                                                                      \
+       unsigned int cpu = dev->id;                                     \
+       cpumask_t mask = topology_##name(cpu);                          \
+       return show_cpumap(1, &mask, buf);                              \
+}
+#endif
+
 #define define_siblings_show_func(name)                \
        define_siblings_show_map(name); define_siblings_show_list(name)
 
index cd03473..a002a38 100644 (file)
@@ -6628,15 +6628,18 @@ static void DAC960_DestroyProcEntries(DAC960_Controller_T *Controller)
  * DAC960_gam_ioctl is the ioctl function for performing RAID operations.
 */
 
-static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
-                           unsigned int Request, unsigned long Argument)
+static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
+                                               unsigned long Argument)
 {
-  int ErrorCode = 0;
+  long ErrorCode = 0;
   if (!capable(CAP_SYS_ADMIN)) return -EACCES;
+
+  lock_kernel();
   switch (Request)
     {
     case DAC960_IOCTL_GET_CONTROLLER_COUNT:
-      return DAC960_ControllerCount;
+      ErrorCode = DAC960_ControllerCount;
+      break;
     case DAC960_IOCTL_GET_CONTROLLER_INFO:
       {
        DAC960_ControllerInfo_T __user *UserSpaceControllerInfo =
@@ -6644,15 +6647,20 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        DAC960_ControllerInfo_T ControllerInfo;
        DAC960_Controller_T *Controller;
        int ControllerNumber;
-       if (UserSpaceControllerInfo == NULL) return -EINVAL;
-       ErrorCode = get_user(ControllerNumber,
+       if (UserSpaceControllerInfo == NULL)
+               ErrorCode = -EINVAL;
+       else ErrorCode = get_user(ControllerNumber,
                             &UserSpaceControllerInfo->ControllerNumber);
-       if (ErrorCode != 0) return ErrorCode;
+       if (ErrorCode != 0)
+               break;;
+       ErrorCode = -ENXIO;
        if (ControllerNumber < 0 ||
-           ControllerNumber > DAC960_ControllerCount - 1)
-         return -ENXIO;
+           ControllerNumber > DAC960_ControllerCount - 1) {
+         break;
+       }
        Controller = DAC960_Controllers[ControllerNumber];
-       if (Controller == NULL) return -ENXIO;
+       if (Controller == NULL)
+               break;;
        memset(&ControllerInfo, 0, sizeof(DAC960_ControllerInfo_T));
        ControllerInfo.ControllerNumber = ControllerNumber;
        ControllerInfo.FirmwareType = Controller->FirmwareType;
@@ -6665,8 +6673,9 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        ControllerInfo.PCI_Address = Controller->PCI_Address;
        strcpy(ControllerInfo.ModelName, Controller->ModelName);
        strcpy(ControllerInfo.FirmwareVersion, Controller->FirmwareVersion);
-       return (copy_to_user(UserSpaceControllerInfo, &ControllerInfo,
+       ErrorCode = (copy_to_user(UserSpaceControllerInfo, &ControllerInfo,
                             sizeof(DAC960_ControllerInfo_T)) ? -EFAULT : 0);
+       break;
       }
     case DAC960_IOCTL_V1_EXECUTE_COMMAND:
       {
@@ -6684,30 +6693,39 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        int ControllerNumber, DataTransferLength;
        unsigned char *DataTransferBuffer = NULL;
        dma_addr_t DataTransferBufferDMA;
-       if (UserSpaceUserCommand == NULL) return -EINVAL;
+       if (UserSpaceUserCommand == NULL) {
+               ErrorCode = -EINVAL;
+               break;
+       }
        if (copy_from_user(&UserCommand, UserSpaceUserCommand,
                                   sizeof(DAC960_V1_UserCommand_T))) {
                ErrorCode = -EFAULT;
-               goto Failure1a;
+               break;
        }
        ControllerNumber = UserCommand.ControllerNumber;
+       ErrorCode = -ENXIO;
        if (ControllerNumber < 0 ||
            ControllerNumber > DAC960_ControllerCount - 1)
-         return -ENXIO;
+               break;
        Controller = DAC960_Controllers[ControllerNumber];
-       if (Controller == NULL) return -ENXIO;
-       if (Controller->FirmwareType != DAC960_V1_Controller) return -EINVAL;
+       if (Controller == NULL)
+               break;
+       ErrorCode = -EINVAL;
+       if (Controller->FirmwareType != DAC960_V1_Controller)
+               break;
        CommandOpcode = UserCommand.CommandMailbox.Common.CommandOpcode;
        DataTransferLength = UserCommand.DataTransferLength;
-       if (CommandOpcode & 0x80) return -EINVAL;
+       if (CommandOpcode & 0x80)
+               break;
        if (CommandOpcode == DAC960_V1_DCDB)
          {
            if (copy_from_user(&DCDB, UserCommand.DCDB,
                               sizeof(DAC960_V1_DCDB_T))) {
                ErrorCode = -EFAULT;
-               goto Failure1a;
+               break;
            }
-           if (DCDB.Channel >= DAC960_V1_MaxChannels) return -EINVAL;
+           if (DCDB.Channel >= DAC960_V1_MaxChannels)
+                       break;
            if (!((DataTransferLength == 0 &&
                   DCDB.Direction
                   == DAC960_V1_DCDB_NoDataTransfer) ||
@@ -6717,38 +6735,37 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
                  (DataTransferLength < 0 &&
                   DCDB.Direction
                   == DAC960_V1_DCDB_DataTransferSystemToDevice)))
-             return -EINVAL;
+                       break;
            if (((DCDB.TransferLengthHigh4 << 16) | DCDB.TransferLength)
                != abs(DataTransferLength))
-             return -EINVAL;
+                       break;
            DCDB_IOBUF = pci_alloc_consistent(Controller->PCIDevice,
                        sizeof(DAC960_V1_DCDB_T), &DCDB_IOBUFDMA);
-           if (DCDB_IOBUF == NULL)
-                       return -ENOMEM;
+           if (DCDB_IOBUF == NULL) {
+                       ErrorCode = -ENOMEM;
+                       break;
+               }
          }
+       ErrorCode = -ENOMEM;
        if (DataTransferLength > 0)
          {
            DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
                                DataTransferLength, &DataTransferBufferDMA);
-           if (DataTransferBuffer == NULL) {
-               ErrorCode = -ENOMEM;
-               goto Failure1;
-           }
+           if (DataTransferBuffer == NULL)
+               break;
            memset(DataTransferBuffer, 0, DataTransferLength);
          }
        else if (DataTransferLength < 0)
          {
            DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
                                -DataTransferLength, &DataTransferBufferDMA);
-           if (DataTransferBuffer == NULL) {
-               ErrorCode = -ENOMEM;
-               goto Failure1;
-           }
+           if (DataTransferBuffer == NULL)
+               break;
            if (copy_from_user(DataTransferBuffer,
                               UserCommand.DataTransferBuffer,
                               -DataTransferLength)) {
                ErrorCode = -EFAULT;
-               goto Failure1;
+               break;
            }
          }
        if (CommandOpcode == DAC960_V1_DCDB)
@@ -6825,8 +6842,7 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        if (DCDB_IOBUF != NULL)
          pci_free_consistent(Controller->PCIDevice, sizeof(DAC960_V1_DCDB_T),
                        DCDB_IOBUF, DCDB_IOBUFDMA);
-      Failure1a:
-       return ErrorCode;
+       break;
       }
     case DAC960_IOCTL_V2_EXECUTE_COMMAND:
       {
@@ -6844,32 +6860,43 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        dma_addr_t DataTransferBufferDMA;
        unsigned char *RequestSenseBuffer = NULL;
        dma_addr_t RequestSenseBufferDMA;
-       if (UserSpaceUserCommand == NULL) return -EINVAL;
+
+       ErrorCode = -EINVAL;
+       if (UserSpaceUserCommand == NULL)
+               break;
        if (copy_from_user(&UserCommand, UserSpaceUserCommand,
                           sizeof(DAC960_V2_UserCommand_T))) {
                ErrorCode = -EFAULT;
-               goto Failure2a;
+               break;
        }
+       ErrorCode = -ENXIO;
        ControllerNumber = UserCommand.ControllerNumber;
        if (ControllerNumber < 0 ||
            ControllerNumber > DAC960_ControllerCount - 1)
-         return -ENXIO;
+               break;
        Controller = DAC960_Controllers[ControllerNumber];
-       if (Controller == NULL) return -ENXIO;
-       if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
+       if (Controller == NULL)
+               break;
+       if (Controller->FirmwareType != DAC960_V2_Controller){
+               ErrorCode = -EINVAL;
+               break;
+       }
        DataTransferLength = UserCommand.DataTransferLength;
+       ErrorCode = -ENOMEM;
        if (DataTransferLength > 0)
          {
            DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
                                DataTransferLength, &DataTransferBufferDMA);
-           if (DataTransferBuffer == NULL) return -ENOMEM;
+           if (DataTransferBuffer == NULL)
+               break;
            memset(DataTransferBuffer, 0, DataTransferLength);
          }
        else if (DataTransferLength < 0)
          {
            DataTransferBuffer = pci_alloc_consistent(Controller->PCIDevice,
                                -DataTransferLength, &DataTransferBufferDMA);
-           if (DataTransferBuffer == NULL) return -ENOMEM;
+           if (DataTransferBuffer == NULL)
+               break;
            if (copy_from_user(DataTransferBuffer,
                               UserCommand.DataTransferBuffer,
                               -DataTransferLength)) {
@@ -6979,8 +7006,7 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        if (RequestSenseBuffer != NULL)
          pci_free_consistent(Controller->PCIDevice, RequestSenseLength,
                RequestSenseBuffer, RequestSenseBufferDMA);
-      Failure2a:
-       return ErrorCode;
+        break;
       }
     case DAC960_IOCTL_V2_GET_HEALTH_STATUS:
       {
@@ -6990,21 +7016,33 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
        DAC960_V2_HealthStatusBuffer_T HealthStatusBuffer;
        DAC960_Controller_T *Controller;
        int ControllerNumber;
-       if (UserSpaceGetHealthStatus == NULL) return -EINVAL;
+       if (UserSpaceGetHealthStatus == NULL) {
+               ErrorCode = -EINVAL;
+               break;
+       }
        if (copy_from_user(&GetHealthStatus, UserSpaceGetHealthStatus,
-                          sizeof(DAC960_V2_GetHealthStatus_T)))
-               return -EFAULT;
+                          sizeof(DAC960_V2_GetHealthStatus_T))) {
+               ErrorCode = -EFAULT;
+               break;
+       }
+       ErrorCode = -ENXIO;
        ControllerNumber = GetHealthStatus.ControllerNumber;
        if (ControllerNumber < 0 ||
            ControllerNumber > DAC960_ControllerCount - 1)
-         return -ENXIO;
+                   break;
        Controller = DAC960_Controllers[ControllerNumber];
-       if (Controller == NULL) return -ENXIO;
-       if (Controller->FirmwareType != DAC960_V2_Controller) return -EINVAL;
+       if (Controller == NULL)
+               break;
+       if (Controller->FirmwareType != DAC960_V2_Controller) {
+               ErrorCode = -EINVAL;
+               break;
+       }
        if (copy_from_user(&HealthStatusBuffer,
                           GetHealthStatus.HealthStatusBuffer,
-                          sizeof(DAC960_V2_HealthStatusBuffer_T)))
-               return -EFAULT;
+                          sizeof(DAC960_V2_HealthStatusBuffer_T))) {
+               ErrorCode = -EFAULT;
+               break;
+       }
        while (Controller->V2.HealthStatusBuffer->StatusChangeCounter
               == HealthStatusBuffer.StatusChangeCounter &&
               Controller->V2.HealthStatusBuffer->NextEventSequenceNumber
@@ -7012,21 +7050,28 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
          {
            interruptible_sleep_on_timeout(&Controller->HealthStatusWaitQueue,
                                           DAC960_MonitoringTimerInterval);
-           if (signal_pending(current)) return -EINTR;
+           if (signal_pending(current)) {
+               ErrorCode = -EINTR;
+               break;
+           }
          }
        if (copy_to_user(GetHealthStatus.HealthStatusBuffer,
                         Controller->V2.HealthStatusBuffer,
                         sizeof(DAC960_V2_HealthStatusBuffer_T)))
-               return -EFAULT;
-       return 0;
+               ErrorCode = -EFAULT;
+       else
+               ErrorCode =  0;
       }
+      default:
+       ErrorCode = -ENOTTY;
     }
-  return -EINVAL;
+  unlock_kernel();
+  return ErrorCode;
 }
 
 static const struct file_operations DAC960_gam_fops = {
        .owner          = THIS_MODULE,
-       .ioctl          = DAC960_gam_ioctl
+       .unlocked_ioctl = DAC960_gam_ioctl
 };
 
 static struct miscdevice DAC960_gam_dev = {
index e8e60e7..d1de68a 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/hdreg.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
+#include <linux/smp_lock.h>
 #include "aoe.h"
 
 enum {
@@ -174,12 +175,16 @@ aoechr_open(struct inode *inode, struct file *filp)
 {
        int n, i;
 
+       lock_kernel();
        n = iminor(inode);
        filp->private_data = (void *) (unsigned long) n;
 
        for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
-               if (chardevs[i].minor == n)
+               if (chardevs[i].minor == n) {
+                       unlock_kernel();
                        return 0;
+               }
+       unlock_kernel();
        return -EINVAL;
 }
 
index 41f818b..2f17462 100644 (file)
@@ -1003,7 +1003,7 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
         * Enough people have their dip switches set backwards to
         * warrant a loud message for this special case.
         */
-       aoemajor = be16_to_cpu(get_unaligned(&h->major));
+       aoemajor = get_unaligned_be16(&h->major);
        if (aoemajor == 0xfff) {
                printk(KERN_ERR "aoe: Warning: shelf address is all ones.  "
                        "Check shelf dip switches.\n");
index ab86e23..9d92636 100644 (file)
@@ -162,6 +162,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
 #include <linux/pg.h>
 #include <linux/device.h>
 #include <linux/sched.h>       /* current, TASK_* */
+#include <linux/smp_lock.h>
 #include <linux/jiffies.h>
 
 #include <asm/uaccess.h>
@@ -515,12 +516,18 @@ static int pg_open(struct inode *inode, struct file *file)
 {
        int unit = iminor(inode) & 0x7f;
        struct pg *dev = &devices[unit];
+       int ret = 0;
 
-       if ((unit >= PG_UNITS) || (!dev->present))
-               return -ENODEV;
+       lock_kernel();
+       if ((unit >= PG_UNITS) || (!dev->present)) {
+               ret = -ENODEV;
+               goto out;
+       }
 
-       if (test_and_set_bit(0, &dev->access))
-               return -EBUSY;
+       if (test_and_set_bit(0, &dev->access)) {
+               ret = -EBUSY;
+               goto out;
+       }
 
        if (dev->busy) {
                pg_reset(dev);
@@ -533,12 +540,15 @@ static int pg_open(struct inode *inode, struct file *file)
        if (dev->bufptr == NULL) {
                clear_bit(0, &dev->access);
                printk("%s: buffer allocation failed\n", dev->name);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
 
        file->private_data = dev;
 
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int pg_release(struct inode *inode, struct file *file)
index 8b9549a..5c74c35 100644 (file)
@@ -146,6 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
 #include <linux/mtio.h>
 #include <linux/device.h>
 #include <linux/sched.h>       /* current, TASK_*, schedule_timeout() */
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -189,8 +190,7 @@ module_param_array(drive3, int, NULL, 0);
 #define ATAPI_LOG_SENSE                0x4d
 
 static int pt_open(struct inode *inode, struct file *file);
-static int pt_ioctl(struct inode *inode, struct file *file,
-                   unsigned int cmd, unsigned long arg);
+static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 static int pt_release(struct inode *inode, struct file *file);
 static ssize_t pt_read(struct file *filp, char __user *buf,
                       size_t count, loff_t * ppos);
@@ -236,7 +236,7 @@ static const struct file_operations pt_fops = {
        .owner = THIS_MODULE,
        .read = pt_read,
        .write = pt_write,
-       .ioctl = pt_ioctl,
+       .unlocked_ioctl = pt_ioctl,
        .open = pt_open,
        .release = pt_release,
 };
@@ -650,8 +650,11 @@ static int pt_open(struct inode *inode, struct file *file)
        struct pt_unit *tape = pt + unit;
        int err;
 
-       if (unit >= PT_UNITS || (!tape->present))
+       lock_kernel();
+       if (unit >= PT_UNITS || (!tape->present)) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        err = -EBUSY;
        if (!atomic_dec_and_test(&tape->available))
@@ -678,15 +681,16 @@ static int pt_open(struct inode *inode, struct file *file)
        }
 
        file->private_data = tape;
+       unlock_kernel();
        return 0;
 
 out:
        atomic_inc(&tape->available);
+       unlock_kernel();
        return err;
 }
 
-static int pt_ioctl(struct inode *inode, struct file *file,
-        unsigned int cmd, unsigned long arg)
+static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct pt_unit *tape = file->private_data;
        struct mtop __user *p = (void __user *)arg;
@@ -700,23 +704,26 @@ static int pt_ioctl(struct inode *inode, struct file *file,
                switch (mtop.mt_op) {
 
                case MTREW:
+                       lock_kernel();
                        pt_rewind(tape);
+                       unlock_kernel();
                        return 0;
 
                case MTWEOF:
+                       lock_kernel();
                        pt_write_fm(tape);
+                       unlock_kernel();
                        return 0;
 
                default:
-                       printk("%s: Unimplemented mt_op %d\n", tape->name,
+                       /* FIXME: rate limit ?? */
+                       printk(KERN_DEBUG "%s: Unimplemented mt_op %d\n", tape->name,
                               mtop.mt_op);
                        return -EINVAL;
                }
 
        default:
-               printk("%s: Unimplemented ioctl 0x%x\n", tape->name, cmd);
-               return -EINVAL;
-
+               return -ENOTTY;
        }
 }
 
index 3ba1df9..45bee91 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/kthread.h>
+#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/spinlock.h>
 #include <linux/file.h>
@@ -2079,7 +2080,6 @@ static noinline_for_stack int pkt_write_caching(struct pktcdvd_device *pd,
        unsigned char buf[64];
        int ret;
 
-       memset(buf, 0, sizeof(buf));
        init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);
        cgc.sense = &sense;
        cgc.buflen = pd->mode_offset + 12;
@@ -2126,7 +2126,6 @@ static noinline_for_stack int pkt_get_max_speed(struct pktcdvd_device *pd,
        unsigned char *cap_buf;
        int ret, offset;
 
-       memset(buf, 0, sizeof(buf));
        cap_buf = &buf[sizeof(struct mode_page_header) + pd->mode_offset];
        init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_UNKNOWN);
        cgc.sense = &sense;
@@ -2633,11 +2632,12 @@ end_io:
 
 
 
-static int pkt_merge_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *bvec)
+static int pkt_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd,
+                         struct bio_vec *bvec)
 {
        struct pktcdvd_device *pd = q->queuedata;
-       sector_t zone = ZONE(bio->bi_sector, pd);
-       int used = ((bio->bi_sector - zone) << 9) + bio->bi_size;
+       sector_t zone = ZONE(bmd->bi_sector, pd);
+       int used = ((bmd->bi_sector - zone) << 9) + bmd->bi_size;
        int remaining = (pd->settings.size << 9) - used;
        int remaining2;
 
@@ -2645,7 +2645,7 @@ static int pkt_merge_bvec(struct request_queue *q, struct bio *bio, struct bio_v
         * A bio <= PAGE_SIZE must be allowed. If it crosses a packet
         * boundary, pkt_make_request() will split the bio.
         */
-       remaining2 = PAGE_SIZE - bio->bi_size;
+       remaining2 = PAGE_SIZE - bmd->bi_size;
        remaining = max(remaining, remaining2);
 
        BUG_ON(remaining < 0);
@@ -2796,9 +2796,14 @@ out_mem:
        return ret;
 }
 
-static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static long pkt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data;
+       struct inode *inode = file->f_path.dentry->d_inode;
+       struct pktcdvd_device *pd;
+       long ret;
+
+       lock_kernel();
+       pd = inode->i_bdev->bd_disk->private_data;
 
        VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, imajor(inode), iminor(inode));
 
@@ -2811,7 +2816,8 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
        case CDROM_LAST_WRITTEN:
        case CDROM_SEND_PACKET:
        case SCSI_IOCTL_SEND_COMMAND:
-               return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
+               ret = blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
+               break;
 
        case CDROMEJECT:
                /*
@@ -2820,14 +2826,15 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
                 */
                if (pd->refcnt == 1)
                        pkt_lock_door(pd, 0);
-               return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
+               ret = blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
+               break;
 
        default:
                VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
-               return -ENOTTY;
+               ret = -ENOTTY;
        }
-
-       return 0;
+       unlock_kernel();
+       return ret;
 }
 
 static int pkt_media_changed(struct gendisk *disk)
@@ -2849,7 +2856,7 @@ static struct block_device_operations pktcdvd_ops = {
        .owner =                THIS_MODULE,
        .open =                 pkt_open,
        .release =              pkt_close,
-       .ioctl =                pkt_ioctl,
+       .unlocked_ioctl =       pkt_ioctl,
        .media_changed =        pkt_media_changed,
 };
 
@@ -3014,7 +3021,8 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
        mutex_unlock(&ctl_mutex);
 }
 
-static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static long pkt_ctl_ioctl(struct file *file, unsigned int cmd,
+                                               unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
        struct pkt_ctrl_command ctrl_cmd;
@@ -3031,16 +3039,22 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
        case PKT_CTRL_CMD_SETUP:
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
+               lock_kernel();
                ret = pkt_setup_dev(new_decode_dev(ctrl_cmd.dev), &pkt_dev);
                ctrl_cmd.pkt_dev = new_encode_dev(pkt_dev);
+               unlock_kernel();
                break;
        case PKT_CTRL_CMD_TEARDOWN:
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
+               lock_kernel();
                ret = pkt_remove_dev(new_decode_dev(ctrl_cmd.pkt_dev));
+               unlock_kernel();
                break;
        case PKT_CTRL_CMD_STATUS:
+               lock_kernel();
                pkt_get_status(&ctrl_cmd);
+               unlock_kernel();
                break;
        default:
                return -ENOTTY;
@@ -3053,7 +3067,7 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
 
 
 static const struct file_operations pkt_ctl_fops = {
-       .ioctl   = pkt_ctl_ioctl,
+       .unlocked_ioctl  = pkt_ctl_ioctl,
        .owner   = THIS_MODULE,
 };
 
index f2fff57..9ae05c5 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/hdreg.h>
+#include <linux/cdrom.h>
 #include <linux/module.h>
 
 #include <xen/xenbus.h>
@@ -153,6 +154,40 @@ static int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg)
        return 0;
 }
 
+int blkif_ioctl(struct inode *inode, struct file *filep,
+               unsigned command, unsigned long argument)
+{
+       struct blkfront_info *info =
+               inode->i_bdev->bd_disk->private_data;
+       int i;
+
+       dev_dbg(&info->xbdev->dev, "command: 0x%x, argument: 0x%lx\n",
+               command, (long)argument);
+
+       switch (command) {
+       case CDROMMULTISESSION:
+               dev_dbg(&info->xbdev->dev, "FIXME: support multisession CDs later\n");
+               for (i = 0; i < sizeof(struct cdrom_multisession); i++)
+                       if (put_user(0, (char __user *)(argument + i)))
+                               return -EFAULT;
+               return 0;
+
+       case CDROM_GET_CAPABILITY: {
+               struct gendisk *gd = info->gd;
+               if (gd->flags & GENHD_FL_CD)
+                       return 0;
+               return -EINVAL;
+       }
+
+       default:
+               /*printk(KERN_ALERT "ioctl %08x not supported by Xen blkdev\n",
+                 command);*/
+               return -EINVAL; /* same return as native Linux */
+       }
+
+       return 0;
+}
+
 /*
  * blkif_queue_request
  *
@@ -324,6 +359,9 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
        /* Make sure buffer addresses are sector-aligned. */
        blk_queue_dma_alignment(rq, 511);
 
+       /* Make sure we don't use bounce buffers. */
+       blk_queue_bounce_limit(rq, BLK_BOUNCE_ANY);
+
        gd->queue = rq;
 
        return 0;
@@ -546,7 +584,7 @@ static int setup_blkring(struct xenbus_device *dev,
 
        info->ring_ref = GRANT_INVALID_REF;
 
-       sring = (struct blkif_sring *)__get_free_page(GFP_KERNEL);
+       sring = (struct blkif_sring *)__get_free_page(GFP_NOIO | __GFP_HIGH);
        if (!sring) {
                xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
                return -ENOMEM;
@@ -703,7 +741,8 @@ static int blkif_recover(struct blkfront_info *info)
        int j;
 
        /* Stage 1: Make a safe copy of the shadow state. */
-       copy = kmalloc(sizeof(info->shadow), GFP_KERNEL);
+       copy = kmalloc(sizeof(info->shadow),
+                      GFP_NOIO | __GFP_REPEAT | __GFP_HIGH);
        if (!copy)
                return -ENOMEM;
        memcpy(copy, info->shadow, sizeof(info->shadow));
@@ -959,7 +998,7 @@ static int blkif_release(struct inode *inode, struct file *filep)
                struct xenbus_device *dev = info->xbdev;
                enum xenbus_state state = xenbus_read_driver_state(dev->otherend);
 
-               if (state == XenbusStateClosing)
+               if (state == XenbusStateClosing && info->is_ready)
                        blkfront_closing(dev);
        }
        return 0;
@@ -971,6 +1010,7 @@ static struct block_device_operations xlvbd_block_fops =
        .open = blkif_open,
        .release = blkif_release,
        .getgeo = blkif_getgeo,
+       .ioctl = blkif_ioctl,
 };
 
 
@@ -1006,7 +1046,7 @@ static int __init xlblk_init(void)
 module_init(xlblk_init);
 
 
-static void xlblk_exit(void)
+static void __exit xlblk_exit(void)
 {
        return xenbus_unregister_driver(&blkfront);
 }
index 0638730..d97700a 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
@@ -263,9 +264,11 @@ static int vhci_open(struct inode *inode, struct file *file)
        skb_queue_head_init(&data->readq);
        init_waitqueue_head(&data->read_wait);
 
+       lock_kernel();
        hdev = hci_alloc_dev();
        if (!hdev) {
                kfree(data);
+               unlock_kernel();
                return -ENOMEM;
        }
 
@@ -286,10 +289,12 @@ static int vhci_open(struct inode *inode, struct file *file)
                BT_ERR("Can't register HCI device");
                kfree(data);
                hci_free_dev(hdev);
+               unlock_kernel();
                return -EBUSY;
        }
 
        file->private_data = data;
+       unlock_kernel();
 
        return nonseekable_open(inode, file);
 }
@@ -313,18 +318,21 @@ static int vhci_release(struct inode *inode, struct file *file)
 static int vhci_fasync(int fd, struct file *file, int on)
 {
        struct vhci_data *data = file->private_data;
-       int err;
+       int err = 0;
 
+       lock_kernel();
        err = fasync_helper(fd, file, on, &data->fasync);
        if (err < 0)
-               return err;
+               goto out;
 
        if (on)
                data->flags |= VHCI_FASYNC;
        else
                data->flags &= ~VHCI_FASYNC;
 
-       return 0;
+out:
+       unlock_kernel();
+       return err;
 }
 
 static const struct file_operations vhci_fops = {
index 69f26eb..a5da356 100644 (file)
@@ -461,37 +461,27 @@ int cdrom_get_media_event(struct cdrom_device_info *cdi,
                          struct media_event_desc *med)
 {
        struct packet_command cgc;
-       unsigned char *buffer;
-       struct event_header *eh;
-       int ret = 1;
-
-       buffer = kmalloc(8, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
+       unsigned char buffer[8];
+       struct event_header *eh = (struct event_header *) buffer;
 
-       eh = (struct event_header *)buffer;
-
-       init_cdrom_command(&cgc, buffer, 8, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
        cgc.cmd[0] = GPCMD_GET_EVENT_STATUS_NOTIFICATION;
        cgc.cmd[1] = 1;         /* IMMED */
        cgc.cmd[4] = 1 << 4;    /* media event */
-       cgc.cmd[8] = 8;
+       cgc.cmd[8] = sizeof(buffer);
        cgc.quiet = 1;
 
        if (cdi->ops->generic_packet(cdi, &cgc))
-               goto err;
+               return 1;
 
        if (be16_to_cpu(eh->data_len) < sizeof(*med))
-               goto err;
+               return 1;
 
        if (eh->nea || eh->notification_class != 0x4)
-               goto err;
+               return 1;
 
-       memcpy(med, buffer + sizeof(*eh), sizeof(*med));
-       ret = 0;
-err:
-       kfree(buffer);
-       return ret;
+       memcpy(med, &buffer[sizeof(*eh)], sizeof(*med));
+       return 0;
 }
 
 /*
@@ -501,82 +491,68 @@ err:
 static int cdrom_mrw_probe_pc(struct cdrom_device_info *cdi)
 {
        struct packet_command cgc;
-       char *buffer;
-       int ret = 1;
-
-       buffer = kmalloc(16, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
+       char buffer[16];
 
-       init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
        cgc.timeout = HZ;
        cgc.quiet = 1;
 
        if (!cdrom_mode_sense(cdi, &cgc, MRW_MODE_PC, 0)) {
                cdi->mrw_mode_page = MRW_MODE_PC;
-               ret = 0;
+               return 0;
        } else if (!cdrom_mode_sense(cdi, &cgc, MRW_MODE_PC_PRE1, 0)) {
                cdi->mrw_mode_page = MRW_MODE_PC_PRE1;
-               ret = 0;
+               return 0;
        }
-       kfree(buffer);
-       return ret;
+
+       return 1;
 }
 
 static int cdrom_is_mrw(struct cdrom_device_info *cdi, int *write)
 {
        struct packet_command cgc;
        struct mrw_feature_desc *mfd;
-       unsigned char *buffer;
+       unsigned char buffer[16];
        int ret;
 
        *write = 0;
-       buffer = kmalloc(16, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
 
-       init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
        cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
        cgc.cmd[3] = CDF_MRW;
-       cgc.cmd[8] = 16;
+       cgc.cmd[8] = sizeof(buffer);
        cgc.quiet = 1;
 
        if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        mfd = (struct mrw_feature_desc *)&buffer[sizeof(struct feature_header)];
-       if (be16_to_cpu(mfd->feature_code) != CDF_MRW) {
-               ret = 1;
-               goto err;
-       }
+       if (be16_to_cpu(mfd->feature_code) != CDF_MRW)
+               return 1;
        *write = mfd->write;
 
        if ((ret = cdrom_mrw_probe_pc(cdi))) {
                *write = 0;
+               return ret;
        }
-err:
-       kfree(buffer);
-       return ret;
+
+       return 0;
 }
 
 static int cdrom_mrw_bgformat(struct cdrom_device_info *cdi, int cont)
 {
        struct packet_command cgc;
-       unsigned char *buffer;
+       unsigned char buffer[12];
        int ret;
 
        printk(KERN_INFO "cdrom: %sstarting format\n", cont ? "Re" : "");
 
-       buffer = kmalloc(12, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
-
        /*
         * FmtData bit set (bit 4), format type is 1
         */
-       init_cdrom_command(&cgc, buffer, 12, CGC_DATA_WRITE);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_WRITE);
        cgc.cmd[0] = GPCMD_FORMAT_UNIT;
        cgc.cmd[1] = (1 << 4) | 1;
 
@@ -603,7 +579,6 @@ static int cdrom_mrw_bgformat(struct cdrom_device_info *cdi, int cont)
        if (ret)
                printk(KERN_INFO "cdrom: bgformat failed\n");
 
-       kfree(buffer);
        return ret;
 }
 
@@ -663,17 +638,16 @@ static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space)
 {
        struct packet_command cgc;
        struct mode_page_header *mph;
-       char *buffer;
+       char buffer[16];
        int ret, offset, size;
 
-       buffer = kmalloc(16, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
-       init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
+       cgc.buffer = buffer;
+       cgc.buflen = sizeof(buffer);
 
        if ((ret = cdrom_mode_sense(cdi, &cgc, cdi->mrw_mode_page, 0)))
-               goto err;
+               return ret;
 
        mph = (struct mode_page_header *) buffer;
        offset = be16_to_cpu(mph->desc_length);
@@ -683,70 +657,55 @@ static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space)
        cgc.buflen = size;
 
        if ((ret = cdrom_mode_select(cdi, &cgc)))
-               goto err;
+               return ret;
 
        printk(KERN_INFO "cdrom: %s: mrw address space %s selected\n", cdi->name, mrw_address_space[space]);
-       ret = 0;
-err:
-       kfree(buffer);
-       return ret;
+       return 0;
 }
 
 static int cdrom_get_random_writable(struct cdrom_device_info *cdi,
                              struct rwrt_feature_desc *rfd)
 {
        struct packet_command cgc;
-       char *buffer;
+       char buffer[24];
        int ret;
 
-       buffer = kmalloc(24, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buffer, 24, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
        cgc.cmd[0] = GPCMD_GET_CONFIGURATION;   /* often 0x46 */
        cgc.cmd[3] = CDF_RWRT;                  /* often 0x0020 */
-       cgc.cmd[8] = 24;                        /* often 0x18 */
+       cgc.cmd[8] = sizeof(buffer);            /* often 0x18 */
        cgc.quiet = 1;
 
        if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        memcpy(rfd, &buffer[sizeof(struct feature_header)], sizeof (*rfd));
-       ret = 0;
-err:
-       kfree(buffer);
-       return ret;
+       return 0;
 }
 
 static int cdrom_has_defect_mgt(struct cdrom_device_info *cdi)
 {
        struct packet_command cgc;
-       char *buffer;
+       char buffer[16];
        __be16 *feature_code;
        int ret;
 
-       buffer = kmalloc(16, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
        cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
        cgc.cmd[3] = CDF_HWDM;
-       cgc.cmd[8] = 16;
+       cgc.cmd[8] = sizeof(buffer);
        cgc.quiet = 1;
 
        if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        feature_code = (__be16 *) &buffer[sizeof(struct feature_header)];
        if (be16_to_cpu(*feature_code) == CDF_HWDM)
-               ret = 0;
-err:
-       kfree(buffer);
-       return ret;
+               return 0;
+
+       return 1;
 }
 
 
@@ -837,14 +796,10 @@ static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
 static int mo_open_write(struct cdrom_device_info *cdi)
 {
        struct packet_command cgc;
-       char *buffer;
+       char buffer[255];
        int ret;
 
-       buffer = kmalloc(255, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buffer, 4, CGC_DATA_READ);
+       init_cdrom_command(&cgc, &buffer, 4, CGC_DATA_READ);
        cgc.quiet = 1;
 
        /*
@@ -861,15 +816,10 @@ static int mo_open_write(struct cdrom_device_info *cdi)
        }
 
        /* drive gave us no info, let the user go ahead */
-       if (ret) {
-               ret = 0;
-               goto err;
-       }
+       if (ret)
+               return 0;
 
-       ret = buffer[3] & 0x80;
-err:
-       kfree(buffer);
-       return ret;
+       return buffer[3] & 0x80;
 }
 
 static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
@@ -892,19 +842,15 @@ static int cdrom_ram_open_write(struct cdrom_device_info *cdi)
 static void cdrom_mmc3_profile(struct cdrom_device_info *cdi)
 {
        struct packet_command cgc;
-       char *buffer;
+       char buffer[32];
        int ret, mmc3_profile;
 
-       buffer = kmalloc(32, GFP_KERNEL);
-       if (!buffer)
-               return;
-
-       init_cdrom_command(&cgc, buffer, 32, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_READ);
 
        cgc.cmd[0] = GPCMD_GET_CONFIGURATION;
        cgc.cmd[1] = 0;
        cgc.cmd[2] = cgc.cmd[3] = 0;            /* Starting Feature Number */
-       cgc.cmd[8] = 32;                        /* Allocation Length */
+       cgc.cmd[8] = sizeof(buffer);            /* Allocation Length */
        cgc.quiet = 1;
 
        if ((ret = cdi->ops->generic_packet(cdi, &cgc)))
@@ -913,7 +859,6 @@ static void cdrom_mmc3_profile(struct cdrom_device_info *cdi)
                mmc3_profile = (buffer[6] << 8) | buffer[7];
 
        cdi->mmc3_profile = mmc3_profile;
-       kfree(buffer);
 }
 
 static int cdrom_is_dvd_rw(struct cdrom_device_info *cdi)
@@ -1628,15 +1573,12 @@ static void setup_send_key(struct packet_command *cgc, unsigned agid, unsigned t
 static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
 {
        int ret;
-       u_char *buf;
+       u_char buf[20];
        struct packet_command cgc;
        struct cdrom_device_ops *cdo = cdi->ops;
-       rpc_state_t *rpc_state;
-
-       buf = kzalloc(20, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
+       rpc_state_t rpc_state;
 
+       memset(buf, 0, sizeof(buf));
        init_cdrom_command(&cgc, buf, 0, CGC_DATA_READ);
 
        switch (ai->type) {
@@ -1647,7 +1589,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                setup_report_key(&cgc, ai->lsa.agid, 0);
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                ai->lsa.agid = buf[7] >> 6;
                /* Returning data, let host change state */
@@ -1658,7 +1600,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                setup_report_key(&cgc, ai->lsk.agid, 2);
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                copy_key(ai->lsk.key, &buf[4]);
                /* Returning data, let host change state */
@@ -1669,7 +1611,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                setup_report_key(&cgc, ai->lsc.agid, 1);
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                copy_chal(ai->lsc.chal, &buf[4]);
                /* Returning data, let host change state */
@@ -1686,7 +1628,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                cgc.cmd[2] = ai->lstk.lba >> 24;
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                ai->lstk.cpm = (buf[4] >> 7) & 1;
                ai->lstk.cp_sec = (buf[4] >> 6) & 1;
@@ -1700,7 +1642,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                setup_report_key(&cgc, ai->lsasf.agid, 5);
                
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                ai->lsasf.asf = buf[7] & 1;
                break;
@@ -1713,7 +1655,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                copy_chal(&buf[4], ai->hsc.chal);
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
                ai->type = DVD_LU_SEND_KEY1;
                break;
@@ -1726,7 +1668,7 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
 
                if ((ret = cdo->generic_packet(cdi, &cgc))) {
                        ai->type = DVD_AUTH_FAILURE;
-                       goto err;
+                       return ret;
                }
                ai->type = DVD_AUTH_ESTABLISHED;
                break;
@@ -1737,23 +1679,24 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                cdinfo(CD_DVD, "entering DVD_INVALIDATE_AGID\n"); 
                setup_report_key(&cgc, ai->lsa.agid, 0x3f);
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
                break;
 
        /* Get region settings */
        case DVD_LU_SEND_RPC_STATE:
                cdinfo(CD_DVD, "entering DVD_LU_SEND_RPC_STATE\n");
                setup_report_key(&cgc, 0, 8);
+               memset(&rpc_state, 0, sizeof(rpc_state_t));
+               cgc.buffer = (char *) &rpc_state;
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
 
-               rpc_state = (rpc_state_t *)buf;
-               ai->lrpcs.type = rpc_state->type_code;
-               ai->lrpcs.vra = rpc_state->vra;
-               ai->lrpcs.ucca = rpc_state->ucca;
-               ai->lrpcs.region_mask = rpc_state->region_mask;
-               ai->lrpcs.rpc_scheme = rpc_state->rpc_scheme;
+               ai->lrpcs.type = rpc_state.type_code;
+               ai->lrpcs.vra = rpc_state.vra;
+               ai->lrpcs.ucca = rpc_state.ucca;
+               ai->lrpcs.region_mask = rpc_state.region_mask;
+               ai->lrpcs.rpc_scheme = rpc_state.rpc_scheme;
                break;
 
        /* Set region settings */
@@ -1764,23 +1707,20 @@ static int dvd_do_auth(struct cdrom_device_info *cdi, dvd_authinfo *ai)
                buf[4] = ai->hrpcs.pdrc;
 
                if ((ret = cdo->generic_packet(cdi, &cgc)))
-                       goto err;
+                       return ret;
                break;
 
        default:
                cdinfo(CD_WARNING, "Invalid DVD key ioctl (%d)\n", ai->type);
-               ret = -ENOTTY;
-               goto err;
+               return -ENOTTY;
        }
-       ret = 0;
-err:
-       kfree(buf);
-       return ret;
+
+       return 0;
 }
 
 static int dvd_read_physical(struct cdrom_device_info *cdi, dvd_struct *s)
 {
-       unsigned char *buf, *base;
+       unsigned char buf[21], *base;
        struct dvd_layer *layer;
        struct packet_command cgc;
        struct cdrom_device_ops *cdo = cdi->ops;
@@ -1789,11 +1729,7 @@ static int dvd_read_physical(struct cdrom_device_info *cdi, dvd_struct *s)
        if (layer_num >= DVD_LAYERS)
                return -EINVAL;
 
-       buf = kmalloc(21, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buf, 21, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);
        cgc.cmd[0] = GPCMD_READ_DVD_STRUCTURE;
        cgc.cmd[6] = layer_num;
        cgc.cmd[7] = s->type;
@@ -1805,7 +1741,7 @@ static int dvd_read_physical(struct cdrom_device_info *cdi, dvd_struct *s)
        cgc.quiet = 1;
 
        if ((ret = cdo->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        base = &buf[4];
        layer = &s->physical.layer[layer_num];
@@ -1829,24 +1765,17 @@ static int dvd_read_physical(struct cdrom_device_info *cdi, dvd_struct *s)
        layer->end_sector_l0 = base[13] << 16 | base[14] << 8 | base[15];
        layer->bca = base[16] >> 7;
 
-       ret = 0;
-err:
-       kfree(buf);
-       return ret;
+       return 0;
 }
 
 static int dvd_read_copyright(struct cdrom_device_info *cdi, dvd_struct *s)
 {
        int ret;
-       u_char *buf;
+       u_char buf[8];
        struct packet_command cgc;
        struct cdrom_device_ops *cdo = cdi->ops;
 
-       buf = kmalloc(8, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buf, 8, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);
        cgc.cmd[0] = GPCMD_READ_DVD_STRUCTURE;
        cgc.cmd[6] = s->copyright.layer_num;
        cgc.cmd[7] = s->type;
@@ -1854,15 +1783,12 @@ static int dvd_read_copyright(struct cdrom_device_info *cdi, dvd_struct *s)
        cgc.cmd[9] = cgc.buflen & 0xff;
 
        if ((ret = cdo->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        s->copyright.cpst = buf[4];
        s->copyright.rmi = buf[5];
 
-       ret = 0;
-err:
-       kfree(buf);
-       return ret;
+       return 0;
 }
 
 static int dvd_read_disckey(struct cdrom_device_info *cdi, dvd_struct *s)
@@ -1894,33 +1820,26 @@ static int dvd_read_disckey(struct cdrom_device_info *cdi, dvd_struct *s)
 static int dvd_read_bca(struct cdrom_device_info *cdi, dvd_struct *s)
 {
        int ret;
-       u_char *buf;
+       u_char buf[4 + 188];
        struct packet_command cgc;
        struct cdrom_device_ops *cdo = cdi->ops;
 
-       buf = kmalloc(4 + 188, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       init_cdrom_command(&cgc, buf, 4 + 188, CGC_DATA_READ);
+       init_cdrom_command(&cgc, buf, sizeof(buf), CGC_DATA_READ);
        cgc.cmd[0] = GPCMD_READ_DVD_STRUCTURE;
        cgc.cmd[7] = s->type;
        cgc.cmd[9] = cgc.buflen & 0xff;
 
        if ((ret = cdo->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        s->bca.len = buf[0] << 8 | buf[1];
        if (s->bca.len < 12 || s->bca.len > 188) {
                cdinfo(CD_WARNING, "Received invalid BCA length (%d)\n", s->bca.len);
-               ret = -EIO;
-               goto err;
+               return -EIO;
        }
        memcpy(s->bca.value, &buf[4], s->bca.len);
-       ret = 0;
-err:
-       kfree(buf);
-       return ret;
+
+       return 0;
 }
 
 static int dvd_read_manufact(struct cdrom_device_info *cdi, dvd_struct *s)
@@ -2020,13 +1939,9 @@ static int cdrom_read_subchannel(struct cdrom_device_info *cdi,
 {
        struct cdrom_device_ops *cdo = cdi->ops;
        struct packet_command cgc;
-       char *buffer;
+       char buffer[32];
        int ret;
 
-       buffer = kmalloc(32, GFP_KERNEL);
-       if (!buffer)
-               return -ENOMEM;
-
        init_cdrom_command(&cgc, buffer, 16, CGC_DATA_READ);
        cgc.cmd[0] = GPCMD_READ_SUBCHANNEL;
        cgc.cmd[1] = 2;     /* MSF addressing */
@@ -2035,7 +1950,7 @@ static int cdrom_read_subchannel(struct cdrom_device_info *cdi,
        cgc.cmd[8] = 16;
 
        if ((ret = cdo->generic_packet(cdi, &cgc)))
-               goto err;
+               return ret;
 
        subchnl->cdsc_audiostatus = cgc.buffer[1];
        subchnl->cdsc_format = CDROM_MSF;
@@ -2050,10 +1965,7 @@ static int cdrom_read_subchannel(struct cdrom_device_info *cdi,
        subchnl->cdsc_absaddr.msf.second = cgc.buffer[10];
        subchnl->cdsc_absaddr.msf.frame = cgc.buffer[11];
 
-       ret = 0;
-err:
-       kfree(buffer);
-       return ret;
+       return 0;
 }
 
 /*
index d38ac50..0e0d12a 100644 (file)
@@ -102,7 +102,6 @@ obj-$(CONFIG_TELCLOCK)              += tlclk.o
 
 obj-$(CONFIG_MWAVE)            += mwave/
 obj-$(CONFIG_AGP)              += agp/
-obj-$(CONFIG_DRM)              += drm/
 obj-$(CONFIG_PCMCIA)           += pcmcia/
 obj-$(CONFIG_IPMI_HANDLER)     += ipmi/
 
index 13665db..481ffe8 100644 (file)
 #include <asm/page.h>          /* PAGE_SIZE */
 #include <asm/e820.h>
 #include <asm/k8.h>
+#include <asm/gart.h>
 #include "agp.h"
 
-/* PTE bits. */
-#define GPTE_VALID     1
-#define GPTE_COHERENT  2
-
-/* Aperture control register bits. */
-#define GARTEN         (1<<0)
-#define DISGARTCPU     (1<<4)
-#define DISGARTIO      (1<<5)
-
-/* GART cache control register bits. */
-#define INVGART                (1<<0)
-#define GARTPTEERR     (1<<1)
-
-/* K8 On-cpu GART registers */
-#define AMD64_GARTAPERTURECTL  0x90
-#define AMD64_GARTAPERTUREBASE 0x94
-#define AMD64_GARTTABLEBASE    0x98
-#define AMD64_GARTCACHECTL     0x9c
-#define AMD64_GARTEN           (1<<0)
-
 /* NVIDIA K8 registers */
 #define NVIDIA_X86_64_0_APBASE         0x10
 #define NVIDIA_X86_64_1_APBASE1                0x50
@@ -165,29 +146,18 @@ static int amd64_fetch_size(void)
  * In a multiprocessor x86-64 system, this function gets
  * called once for each CPU.
  */
-static u64 amd64_configure (struct pci_dev *hammer, u64 gatt_table)
+static u64 amd64_configure(struct pci_dev *hammer, u64 gatt_table)
 {
        u64 aperturebase;
        u32 tmp;
-       u64 addr, aper_base;
+       u64 aper_base;
 
        /* Address to map to */
-       pci_read_config_dword (hammer, AMD64_GARTAPERTUREBASE, &tmp);
+       pci_read_config_dword(hammer, AMD64_GARTAPERTUREBASE, &tmp);
        aperturebase = tmp << 25;
        aper_base = (aperturebase & PCI_BASE_ADDRESS_MEM_MASK);
 
-       /* address of the mappings table */
-       addr = (u64) gatt_table;
-       addr >>= 12;
-       tmp = (u32) addr<<4;
-       tmp &= ~0xf;
-       pci_write_config_dword (hammer, AMD64_GARTTABLEBASE, tmp);
-
-       /* Enable GART translation for this hammer. */
-       pci_read_config_dword(hammer, AMD64_GARTAPERTURECTL, &tmp);
-       tmp |= GARTEN;
-       tmp &= ~(DISGARTCPU | DISGARTIO);
-       pci_write_config_dword(hammer, AMD64_GARTAPERTURECTL, tmp);
+       enable_gart_translation(hammer, gatt_table);
 
        return aper_base;
 }
@@ -226,9 +196,9 @@ static void amd64_cleanup(void)
         for (i = 0; i < num_k8_northbridges; i++) {
                struct pci_dev *dev = k8_northbridges[i];
                /* disable gart translation */
-               pci_read_config_dword (dev, AMD64_GARTAPERTURECTL, &tmp);
+               pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &tmp);
                tmp &= ~AMD64_GARTEN;
-               pci_write_config_dword (dev, AMD64_GARTAPERTURECTL, tmp);
+               pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, tmp);
        }
 }
 
@@ -258,24 +228,10 @@ static const struct agp_bridge_driver amd_8151_driver = {
 };
 
 /* Some basic sanity checks for the aperture. */
-static int __devinit aperture_valid(u64 aper, u32 size)
+static int __devinit agp_aperture_valid(u64 aper, u32 size)
 {
-       if (aper == 0) {
-               printk(KERN_ERR PFX "No aperture\n");
-               return 0;
-       }
-       if (size < 32*1024*1024) {
-               printk(KERN_ERR PFX "Aperture too small (%d MB)\n", size>>20);
-               return 0;
-       }
-       if ((u64)aper + size > 0x100000000ULL) {
-               printk(KERN_ERR PFX "Aperture out of bounds\n");
+       if (!aperture_valid(aper, size, 32*1024*1024))
                return 0;
-       }
-       if (e820_any_mapped(aper, aper + size, E820_RAM)) {
-               printk(KERN_ERR PFX "Aperture pointing to RAM\n");
-               return 0;
-       }
 
        /* Request the Aperture. This catches cases when someone else
           already put a mapping in there - happens with some very broken BIOS
@@ -308,11 +264,11 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp,
        u32 nb_order, nb_base;
        u16 apsize;
 
-       pci_read_config_dword(nb, 0x90, &nb_order);
+       pci_read_config_dword(nb, AMD64_GARTAPERTURECTL, &nb_order);
        nb_order = (nb_order >> 1) & 7;
-       pci_read_config_dword(nb, 0x94, &nb_base);
+       pci_read_config_dword(nb, AMD64_GARTAPERTUREBASE, &nb_base);
        nb_aper = nb_base << 25;
-       if (aperture_valid(nb_aper, (32*1024*1024)<<nb_order)) {
+       if (agp_aperture_valid(nb_aper, (32*1024*1024)<<nb_order)) {
                return 0;
        }
 
@@ -331,12 +287,23 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp,
        pci_read_config_dword(agp, 0x10, &aper_low);
        pci_read_config_dword(agp, 0x14, &aper_hi);
        aper = (aper_low & ~((1<<22)-1)) | ((u64)aper_hi << 32);
+
+       /*
+        * On some sick chips APSIZE is 0. This means it wants 4G
+        * so let double check that order, and lets trust the AMD NB settings
+        */
+       if (order >=0 && aper + (32ULL<<(20 + order)) > 0x100000000ULL) {
+               printk(KERN_INFO "Aperture size %u MB is not right, using settings from NB\n",
+                                 32 << order);
+               order = nb_order;
+       }
+
        printk(KERN_INFO PFX "Aperture from AGP @ %Lx size %u MB\n", aper, 32 << order);
-       if (order < 0 || !aperture_valid(aper, (32*1024*1024)<<order))
+       if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order))
                return -1;
 
-       pci_write_config_dword(nb, 0x90, order << 1);
-       pci_write_config_dword(nb, 0x94, aper >> 25);
+       pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1);
+       pci_write_config_dword(nb, AMD64_GARTAPERTUREBASE, aper >> 25);
 
        return 0;
 }
index e6cb1ab..a96f319 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/mm.h>
 #include <linux/fs.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 #include "agp.h"
@@ -677,6 +678,7 @@ static int agp_open(struct inode *inode, struct file *file)
        struct agp_client *client;
        int rc = -ENXIO;
 
+       lock_kernel();
        mutex_lock(&(agp_fe.agp_mutex));
 
        if (minor != AGPGART_MINOR)
@@ -703,12 +705,14 @@ static int agp_open(struct inode *inode, struct file *file)
        agp_insert_file_private(priv);
        DBG("private=%p, client=%p", priv, client);
        mutex_unlock(&(agp_fe.agp_mutex));
+       unlock_kernel();
        return 0;
 
 err_out_nomem:
        rc = -ENOMEM;
 err_out:
        mutex_unlock(&(agp_fe.agp_mutex));
+       unlock_kernel();
        return rc;
 }
 
index cdd876d..da8a165 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/miscdevice.h>
@@ -416,6 +417,7 @@ static int apm_open(struct inode * inode, struct file * filp)
 {
        struct apm_user *as;
 
+       lock_kernel();
        as = kzalloc(sizeof(*as), GFP_KERNEL);
        if (as) {
                /*
@@ -435,6 +437,7 @@ static int apm_open(struct inode * inode, struct file * filp)
 
                filp->private_data = as;
        }
+       unlock_kernel();
 
        return as ? 0 : -ENOMEM;
 }
index b6f2639..d8cff90 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/module.h>
 
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/tty.h>
@@ -67,11 +68,15 @@ static void set_led(char state)
 
 static int briq_panel_open(struct inode *ino, struct file *filep)
 {
-       /* enforce single access */
-       if (vfd_is_open)
+       lock_kernel();
+       /* enforce single access, vfd_is_open is protected by BKL */
+       if (vfd_is_open) {
+               unlock_kernel();
                return -EBUSY;
+       }
        vfd_is_open = 1;
 
+       unlock_kernel();
        return 0;
 }
 
index c0a4a0b..04ba906 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/cdev.h>
 #include <linux/ioport.h>
 #include <linux/pci.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -157,6 +158,7 @@ static int cs5535_gpio_open(struct inode *inode, struct file *file)
 {
        u32 m = iminor(inode);
 
+       cycle_kernel_lock();
        /* the mask says which pins are usable by this driver */
        if ((mask & (1 << m)) == 0)
                return -EINVAL;
diff --git a/drivers/char/drm/Kconfig b/drivers/char/drm/Kconfig
deleted file mode 100644 (file)
index 610d6fd..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#
-# Drm device configuration
-#
-# This driver provides support for the
-# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
-#
-menuconfig DRM
-       tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
-       depends on (AGP || AGP=n) && PCI && !EMULATED_CMPXCHG
-       help
-         Kernel-level support for the Direct Rendering Infrastructure (DRI)
-         introduced in XFree86 4.0. If you say Y here, you need to select
-         the module that's right for your graphics card from the list below.
-         These modules provide support for synchronization, security, and
-         DMA transfers. Please see <http://dri.sourceforge.net/> for more
-         details.  You should also select and configure AGP
-         (/dev/agpgart) support.
-
-config DRM_TDFX
-       tristate "3dfx Banshee/Voodoo3+"
-       depends on DRM && PCI
-       help
-         Choose this option if you have a 3dfx Banshee or Voodoo3 (or later),
-         graphics card.  If M is selected, the module will be called tdfx.
-
-config DRM_R128
-       tristate "ATI Rage 128"
-       depends on DRM && PCI
-       help
-         Choose this option if you have an ATI Rage 128 graphics card.  If M
-         is selected, the module will be called r128.  AGP support for
-         this card is strongly suggested (unless you have a PCI version).
-
-config DRM_RADEON
-       tristate "ATI Radeon"
-       depends on DRM && PCI
-       help
-         Choose this option if you have an ATI Radeon graphics card.  There
-         are both PCI and AGP versions.  You don't need to choose this to
-         run the Radeon in plain VGA mode.
-
-         If M is selected, the module will be called radeon.
-
-config DRM_I810
-       tristate "Intel I810"
-       depends on DRM && AGP && AGP_INTEL
-       help
-         Choose this option if you have an Intel I810 graphics card.  If M is
-         selected, the module will be called i810.  AGP support is required
-         for this driver to work.
-
-choice
-       prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-       depends on DRM && AGP && AGP_INTEL
-       optional
-
-config DRM_I830
-       tristate "i830 driver"
-       help
-         Choose this option if you have a system that has Intel 830M, 845G,
-         852GM, 855GM or 865G integrated graphics.  If M is selected, the
-         module will be called i830.  AGP support is required for this driver
-         to work. This driver is used by the older X releases X.org 6.7 and
-         XFree86 4.3. If unsure, build this and i915 as modules and the X server
-         will load the correct one.
-
-config DRM_I915
-       tristate "i915 driver"
-       help
-         Choose this option if you have a system that has Intel 830M, 845G,
-         852GM, 855GM 865G or 915G integrated graphics.  If M is selected, the
-         module will be called i915.  AGP support is required for this driver
-         to work. This driver is used by the Intel driver in X.org 6.8 and
-         XFree86 4.4 and above. If unsure, build this and i830 as modules and
-         the X server will load the correct one.
-
-endchoice
-
-config DRM_MGA
-       tristate "Matrox g200/g400"
-       depends on DRM
-       help
-         Choose this option if you have a Matrox G200, G400 or G450 graphics
-         card.  If M is selected, the module will be called mga.  AGP
-         support is required for this driver to work.
-
-config DRM_SIS
-       tristate "SiS video cards"
-       depends on DRM && AGP
-       help
-         Choose this option if you have a SiS 630 or compatible video
-          chipset. If M is selected the module will be called sis. AGP
-          support is required for this driver to work.
-
-config DRM_VIA
-       tristate "Via unichrome video cards"
-       depends on DRM
-       help
-         Choose this option if you have a Via unichrome or compatible video
-         chipset. If M is selected the module will be called via.
-
-config DRM_SAVAGE
-       tristate "Savage video cards"
-       depends on DRM
-       help
-         Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
-         chipset. If M is selected the module will be called savage.
diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile
deleted file mode 100644 (file)
index 1283ded..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# Makefile for the drm device driver.  This driver provides support for the
-# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
-
-drm-objs    := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
-               drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
-               drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
-               drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
-               drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o
-
-tdfx-objs   := tdfx_drv.o
-r128-objs   := r128_drv.o r128_cce.o r128_state.o r128_irq.o
-mga-objs    := mga_drv.o mga_dma.o mga_state.o mga_warp.o mga_irq.o
-i810-objs   := i810_drv.o i810_dma.o
-i830-objs   := i830_drv.o i830_dma.o i830_irq.o
-i915-objs   := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
-radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o
-sis-objs    := sis_drv.o sis_mm.o
-savage-objs := savage_drv.o savage_bci.o savage_state.o
-via-objs    := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o
-
-ifeq ($(CONFIG_COMPAT),y)
-drm-objs    += drm_ioc32.o
-radeon-objs += radeon_ioc32.o
-mga-objs    += mga_ioc32.o
-r128-objs   += r128_ioc32.o
-i915-objs   += i915_ioc32.o
-endif
-
-obj-$(CONFIG_DRM)      += drm.o
-obj-$(CONFIG_DRM_TDFX) += tdfx.o
-obj-$(CONFIG_DRM_R128) += r128.o
-obj-$(CONFIG_DRM_RADEON)+= radeon.o
-obj-$(CONFIG_DRM_MGA)  += mga.o
-obj-$(CONFIG_DRM_I810) += i810.o
-obj-$(CONFIG_DRM_I830) += i830.o
-obj-$(CONFIG_DRM_I915)  += i915.o
-obj-$(CONFIG_DRM_SIS)   += sis.o
-obj-$(CONFIG_DRM_SAVAGE)+= savage.o
-obj-$(CONFIG_DRM_VIA)  +=via.o
diff --git a/drivers/char/drm/README.drm b/drivers/char/drm/README.drm
deleted file mode 100644 (file)
index b5b3327..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-************************************************************
-* For the very latest on DRI development, please see:      *
-*     http://dri.freedesktop.org/                          *
-************************************************************
-
-The Direct Rendering Manager (drm) is a device-independent kernel-level
-device driver that provides support for the XFree86 Direct Rendering
-Infrastructure (DRI).
-
-The DRM supports the Direct Rendering Infrastructure (DRI) in four major
-ways:
-
-    1. The DRM provides synchronized access to the graphics hardware via
-       the use of an optimized two-tiered lock.
-
-    2. The DRM enforces the DRI security policy for access to the graphics
-       hardware by only allowing authenticated X11 clients access to
-       restricted regions of memory.
-
-    3. The DRM provides a generic DMA engine, complete with multiple
-       queues and the ability to detect the need for an OpenGL context
-       switch.
-
-    4. The DRM is extensible via the use of small device-specific modules
-       that rely extensively on the API exported by the DRM module.
-
-
-Documentation on the DRI is available from:
-    http://dri.freedesktop.org/wiki/Documentation
-    http://sourceforge.net/project/showfiles.php?group_id=387
-    http://dri.sourceforge.net/doc/
-
-For specific information about kernel-level support, see:
-
-    The Direct Rendering Manager, Kernel Support for the Direct Rendering
-    Infrastructure
-    http://dri.sourceforge.net/doc/drm_low_level.html
-
-    Hardware Locking for the Direct Rendering Infrastructure
-    http://dri.sourceforge.net/doc/hardware_locking_low_level.html
-
-    A Security Analysis of the Direct Rendering Infrastructure
-    http://dri.sourceforge.net/doc/security_low_level.html
diff --git a/drivers/char/drm/ati_pcigart.c b/drivers/char/drm/ati_pcigart.c
deleted file mode 100644 (file)
index c533d0c..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * \file ati_pcigart.c
- * ATI PCI GART support
- *
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
- *
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-# define ATI_PCIGART_PAGE_SIZE         4096    /**< PCI GART page size */
-
-static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
-                                      struct drm_ati_pcigart_info *gart_info)
-{
-       gart_info->table_handle = drm_pci_alloc(dev, gart_info->table_size,
-                                               PAGE_SIZE,
-                                               gart_info->table_mask);
-       if (gart_info->table_handle == NULL)
-               return -ENOMEM;
-
-       return 0;
-}
-
-static void drm_ati_free_pcigart_table(struct drm_device *dev,
-                                      struct drm_ati_pcigart_info *gart_info)
-{
-       drm_pci_free(dev, gart_info->table_handle);
-       gart_info->table_handle = NULL;
-}
-
-int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
-{
-       struct drm_sg_mem *entry = dev->sg;
-       unsigned long pages;
-       int i;
-       int max_pages;
-
-       /* we need to support large memory configurations */
-       if (!entry) {
-               DRM_ERROR("no scatter/gather memory!\n");
-               return 0;
-       }
-
-       if (gart_info->bus_addr) {
-
-               max_pages = (gart_info->table_size / sizeof(u32));
-               pages = (entry->pages <= max_pages)
-                 ? entry->pages : max_pages;
-
-               for (i = 0; i < pages; i++) {
-                       if (!entry->busaddr[i])
-                               break;
-                       pci_unmap_page(dev->pdev, entry->busaddr[i],
-                                        PAGE_SIZE, PCI_DMA_TODEVICE);
-               }
-
-               if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
-                       gart_info->bus_addr = 0;
-       }
-
-       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN &&
-           gart_info->table_handle) {
-               drm_ati_free_pcigart_table(dev, gart_info);
-       }
-
-       return 1;
-}
-EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
-
-int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
-{
-       struct drm_sg_mem *entry = dev->sg;
-       void *address = NULL;
-       unsigned long pages;
-       u32 *pci_gart, page_base;
-       dma_addr_t bus_address = 0;
-       int i, j, ret = 0;
-       int max_pages;
-
-       if (!entry) {
-               DRM_ERROR("no scatter/gather memory!\n");
-               goto done;
-       }
-
-       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
-               DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
-
-               ret = drm_ati_alloc_pcigart_table(dev, gart_info);
-               if (ret) {
-                       DRM_ERROR("cannot allocate PCI GART page!\n");
-                       goto done;
-               }
-
-               address = gart_info->table_handle->vaddr;
-               bus_address = gart_info->table_handle->busaddr;
-       } else {
-               address = gart_info->addr;
-               bus_address = gart_info->bus_addr;
-               DRM_DEBUG("PCI: Gart Table: VRAM %08LX mapped at %08lX\n",
-                         (unsigned long long)bus_address,
-                         (unsigned long)address);
-       }
-
-       pci_gart = (u32 *) address;
-
-       max_pages = (gart_info->table_size / sizeof(u32));
-       pages = (entry->pages <= max_pages)
-           ? entry->pages : max_pages;
-
-       memset(pci_gart, 0, max_pages * sizeof(u32));
-
-       for (i = 0; i < pages; i++) {
-               /* we need to support large memory configurations */
-               entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i],
-                                                0, PAGE_SIZE, PCI_DMA_TODEVICE);
-               if (entry->busaddr[i] == 0) {
-                       DRM_ERROR("unable to map PCIGART pages!\n");
-                       drm_ati_pcigart_cleanup(dev, gart_info);
-                       address = NULL;
-                       bus_address = 0;
-                       goto done;
-               }
-               page_base = (u32) entry->busaddr[i];
-
-               for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
-                       switch(gart_info->gart_reg_if) {
-                       case DRM_ATI_GART_IGP:
-                               *pci_gart = cpu_to_le32((page_base) | 0xc);
-                               break;
-                       case DRM_ATI_GART_PCIE:
-                               *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
-                               break;
-                       default:
-                       case DRM_ATI_GART_PCI:
-                               *pci_gart = cpu_to_le32(page_base);
-                               break;
-                       }
-                       pci_gart++;
-                       page_base += ATI_PCIGART_PAGE_SIZE;
-               }
-       }
-       ret = 1;
-
-#if defined(__i386__) || defined(__x86_64__)
-       wbinvd();
-#else
-       mb();
-#endif
-
-      done:
-       gart_info->addr = address;
-       gart_info->bus_addr = bus_address;
-       return ret;
-}
-EXPORT_SYMBOL(drm_ati_pcigart_init);
diff --git a/drivers/char/drm/drm.h b/drivers/char/drm/drm.h
deleted file mode 100644 (file)
index 38d3c6b..0000000
+++ /dev/null
@@ -1,694 +0,0 @@
-/**
- * \file drm.h
- * Header for the Direct Rendering Manager
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- *
- * \par Acknowledgments:
- * Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic \c cmpxchg.
- */
-
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _DRM_H_
-#define _DRM_H_
-
-#if defined(__linux__)
-#if defined(__KERNEL__)
-#endif
-#include <asm/ioctl.h>         /* For _IO* macros */
-#define DRM_IOCTL_NR(n)                _IOC_NR(n)
-#define DRM_IOC_VOID           _IOC_NONE
-#define DRM_IOC_READ           _IOC_READ
-#define DRM_IOC_WRITE          _IOC_WRITE
-#define DRM_IOC_READWRITE      _IOC_READ|_IOC_WRITE
-#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
-#if defined(__FreeBSD__) && defined(IN_MODULE)
-/* Prevent name collision when including sys/ioccom.h */
-#undef ioctl
-#include <sys/ioccom.h>
-#define ioctl(a,b,c)           xf86ioctl(a,b,c)
-#else
-#include <sys/ioccom.h>
-#endif                         /* __FreeBSD__ && xf86ioctl */
-#define DRM_IOCTL_NR(n)                ((n) & 0xff)
-#define DRM_IOC_VOID           IOC_VOID
-#define DRM_IOC_READ           IOC_OUT
-#define DRM_IOC_WRITE          IOC_IN
-#define DRM_IOC_READWRITE      IOC_INOUT
-#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
-#endif
-
-#define DRM_MAJOR       226
-#define DRM_MAX_MINOR   15
-
-#define DRM_NAME       "drm"     /**< Name in kernel, /dev, and /proc */
-#define DRM_MIN_ORDER  5         /**< At least 2^5 bytes = 32 bytes */
-#define DRM_MAX_ORDER  22        /**< Up to 2^22 bytes = 4MB */
-#define DRM_RAM_PERCENT 10       /**< How much system ram can we lock? */
-
-#define _DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
-#define _DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
-#define _DRM_LOCK_IS_HELD(lock)           ((lock) & _DRM_LOCK_HELD)
-#define _DRM_LOCK_IS_CONT(lock)           ((lock) & _DRM_LOCK_CONT)
-#define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
-
-typedef unsigned int drm_handle_t;
-typedef unsigned int drm_context_t;
-typedef unsigned int drm_drawable_t;
-typedef unsigned int drm_magic_t;
-
-/**
- * Cliprect.
- *
- * \warning: If you change this structure, make sure you change
- * XF86DRIClipRectRec in the server as well
- *
- * \note KW: Actually it's illegal to change either for
- * backwards-compatibility reasons.
- */
-struct drm_clip_rect {
-       unsigned short x1;
-       unsigned short y1;
-       unsigned short x2;
-       unsigned short y2;
-};
-
-/**
- * Drawable information.
- */
-struct drm_drawable_info {
-       unsigned int num_rects;
-       struct drm_clip_rect *rects;
-};
-
-/**
- * Texture region,
- */
-struct drm_tex_region {
-       unsigned char next;
-       unsigned char prev;
-       unsigned char in_use;
-       unsigned char padding;
-       unsigned int age;
-};
-
-/**
- * Hardware lock.
- *
- * The lock structure is a simple cache-line aligned integer.  To avoid
- * processor bus contention on a multiprocessor system, there should not be any
- * other data stored in the same cache line.
- */
-struct drm_hw_lock {
-       __volatile__ unsigned int lock;         /**< lock variable */
-       char padding[60];                       /**< Pad to cache line */
-};
-
-/**
- * DRM_IOCTL_VERSION ioctl argument type.
- *
- * \sa drmGetVersion().
- */
-struct drm_version {
-       int version_major;        /**< Major version */
-       int version_minor;        /**< Minor version */
-       int version_patchlevel;   /**< Patch level */
-       size_t name_len;          /**< Length of name buffer */
-       char __user *name;        /**< Name of driver */
-       size_t date_len;          /**< Length of date buffer */
-       char __user *date;        /**< User-space buffer to hold date */
-       size_t desc_len;          /**< Length of desc buffer */
-       char __user *desc;        /**< User-space buffer to hold desc */
-};
-
-/**
- * DRM_IOCTL_GET_UNIQUE ioctl argument type.
- *
- * \sa drmGetBusid() and drmSetBusId().
- */
-struct drm_unique {
-       size_t unique_len;        /**< Length of unique */
-       char __user *unique;      /**< Unique name for driver instantiation */
-};
-
-struct drm_list {
-       int count;                /**< Length of user-space structures */
-       struct drm_version __user *version;
-};
-
-struct drm_block {
-       int unused;
-};
-
-/**
- * DRM_IOCTL_CONTROL ioctl argument type.
- *
- * \sa drmCtlInstHandler() and drmCtlUninstHandler().
- */
-struct drm_control {
-       enum {
-               DRM_ADD_COMMAND,
-               DRM_RM_COMMAND,
-               DRM_INST_HANDLER,
-               DRM_UNINST_HANDLER
-       } func;
-       int irq;
-};
-
-/**
- * Type of memory to map.
- */
-enum drm_map_type {
-       _DRM_FRAME_BUFFER = 0,    /**< WC (no caching), no core dump */
-       _DRM_REGISTERS = 1,       /**< no caching, no core dump */
-       _DRM_SHM = 2,             /**< shared, cached */
-       _DRM_AGP = 3,             /**< AGP/GART */
-       _DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
-       _DRM_CONSISTENT = 5,      /**< Consistent memory for PCI DMA */
-};
-
-/**
- * Memory mapping flags.
- */
-enum drm_map_flags {
-       _DRM_RESTRICTED = 0x01,      /**< Cannot be mapped to user-virtual */
-       _DRM_READ_ONLY = 0x02,
-       _DRM_LOCKED = 0x04,          /**< shared, cached, locked */
-       _DRM_KERNEL = 0x08,          /**< kernel requires access */
-       _DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
-       _DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
-       _DRM_REMOVABLE = 0x40,       /**< Removable mapping */
-       _DRM_DRIVER = 0x80           /**< Managed by driver */
-};
-
-struct drm_ctx_priv_map {
-       unsigned int ctx_id;     /**< Context requesting private mapping */
-       void *handle;            /**< Handle of map */
-};
-
-/**
- * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
- * argument type.
- *
- * \sa drmAddMap().
- */
-struct drm_map {
-       unsigned long offset;    /**< Requested physical address (0 for SAREA)*/
-       unsigned long size;      /**< Requested physical size (bytes) */
-       enum drm_map_type type;  /**< Type of memory to map */
-       enum drm_map_flags flags;        /**< Flags */
-       void *handle;            /**< User-space: "Handle" to pass to mmap() */
-                                /**< Kernel-space: kernel-virtual address */
-       int mtrr;                /**< MTRR slot used */
-       /*   Private data */
-};
-
-/**
- * DRM_IOCTL_GET_CLIENT ioctl argument type.
- */
-struct drm_client {
-       int idx;                /**< Which client desired? */
-       int auth;               /**< Is client authenticated? */
-       unsigned long pid;      /**< Process ID */
-       unsigned long uid;      /**< User ID */
-       unsigned long magic;    /**< Magic */
-       unsigned long iocs;     /**< Ioctl count */
-};
-
-enum drm_stat_type {
-       _DRM_STAT_LOCK,
-       _DRM_STAT_OPENS,
-       _DRM_STAT_CLOSES,
-       _DRM_STAT_IOCTLS,
-       _DRM_STAT_LOCKS,
-       _DRM_STAT_UNLOCKS,
-       _DRM_STAT_VALUE,        /**< Generic value */
-       _DRM_STAT_BYTE,         /**< Generic byte counter (1024bytes/K) */
-       _DRM_STAT_COUNT,        /**< Generic non-byte counter (1000/k) */
-
-       _DRM_STAT_IRQ,          /**< IRQ */
-       _DRM_STAT_PRIMARY,      /**< Primary DMA bytes */
-       _DRM_STAT_SECONDARY,    /**< Secondary DMA bytes */
-       _DRM_STAT_DMA,          /**< DMA */
-       _DRM_STAT_SPECIAL,      /**< Special DMA (e.g., priority or polled) */
-       _DRM_STAT_MISSED        /**< Missed DMA opportunity */
-           /* Add to the *END* of the list */
-};
-
-/**
- * DRM_IOCTL_GET_STATS ioctl argument type.
- */
-struct drm_stats {
-       unsigned long count;
-       struct {
-               unsigned long value;
-               enum drm_stat_type type;
-       } data[15];
-};
-
-/**
- * Hardware locking flags.
- */
-enum drm_lock_flags {
-       _DRM_LOCK_READY = 0x01,      /**< Wait until hardware is ready for DMA */
-       _DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
-       _DRM_LOCK_FLUSH = 0x04,      /**< Flush this context's DMA queue first */
-       _DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
-       /* These *HALT* flags aren't supported yet
-          -- they will be used to support the
-          full-screen DGA-like mode. */
-       _DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
-       _DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
-};
-
-/**
- * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
- *
- * \sa drmGetLock() and drmUnlock().
- */
-struct drm_lock {
-       int context;
-       enum drm_lock_flags flags;
-};
-
-/**
- * DMA flags
- *
- * \warning
- * These values \e must match xf86drm.h.
- *
- * \sa drm_dma.
- */
-enum drm_dma_flags {
-       /* Flags for DMA buffer dispatch */
-       _DRM_DMA_BLOCK = 0x01,        /**<
-                                      * Block until buffer dispatched.
-                                      *
-                                      * \note The buffer may not yet have
-                                      * been processed by the hardware --
-                                      * getting a hardware lock with the
-                                      * hardware quiescent will ensure
-                                      * that the buffer has been
-                                      * processed.
-                                      */
-       _DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
-       _DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
-
-       /* Flags for DMA buffer request */
-       _DRM_DMA_WAIT = 0x10,         /**< Wait for free buffers */
-       _DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
-       _DRM_DMA_LARGER_OK = 0x40     /**< Larger-than-requested buffers OK */
-};
-
-/**
- * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
- *
- * \sa drmAddBufs().
- */
-struct drm_buf_desc {
-       int count;               /**< Number of buffers of this size */
-       int size;                /**< Size in bytes */
-       int low_mark;            /**< Low water mark */
-       int high_mark;           /**< High water mark */
-       enum {
-               _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
-               _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
-               _DRM_SG_BUFFER = 0x04,  /**< Scatter/gather memory buffer */
-               _DRM_FB_BUFFER = 0x08,  /**< Buffer is in frame buffer */
-               _DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
-       } flags;
-       unsigned long agp_start; /**<
-                                 * Start address of where the AGP buffers are
-                                 * in the AGP aperture
-                                 */
-};
-
-/**
- * DRM_IOCTL_INFO_BUFS ioctl argument type.
- */
-struct drm_buf_info {
-       int count;              /**< Entries in list */
-       struct drm_buf_desc __user *list;
-};
-
-/**
- * DRM_IOCTL_FREE_BUFS ioctl argument type.
- */
-struct drm_buf_free {
-       int count;
-       int __user *list;
-};
-
-/**
- * Buffer information
- *
- * \sa drm_buf_map.
- */
-struct drm_buf_pub {
-       int idx;                       /**< Index into the master buffer list */
-       int total;                     /**< Buffer size */
-       int used;                      /**< Amount of buffer in use (for DMA) */
-       void __user *address;          /**< Address of buffer */
-};
-
-/**
- * DRM_IOCTL_MAP_BUFS ioctl argument type.
- */
-struct drm_buf_map {
-       int count;              /**< Length of the buffer list */
-       void __user *virtual;           /**< Mmap'd area in user-virtual */
-       struct drm_buf_pub __user *list;        /**< Buffer information */
-};
-
-/**
- * DRM_IOCTL_DMA ioctl argument type.
- *
- * Indices here refer to the offset into the buffer list in drm_buf_get.
- *
- * \sa drmDMA().
- */
-struct drm_dma {
-       int context;                      /**< Context handle */
-       int send_count;                   /**< Number of buffers to send */
-       int __user *send_indices;         /**< List of handles to buffers */
-       int __user *send_sizes;           /**< Lengths of data to send */
-       enum drm_dma_flags flags;         /**< Flags */
-       int request_count;                /**< Number of buffers requested */
-       int request_size;                 /**< Desired size for buffers */
-       int __user *request_indices;      /**< Buffer information */
-       int __user *request_sizes;
-       int granted_count;                /**< Number of buffers granted */
-};
-
-enum drm_ctx_flags {
-       _DRM_CONTEXT_PRESERVED = 0x01,
-       _DRM_CONTEXT_2DONLY = 0x02
-};
-
-/**
- * DRM_IOCTL_ADD_CTX ioctl argument type.
- *
- * \sa drmCreateContext() and drmDestroyContext().
- */
-struct drm_ctx {
-       drm_context_t handle;
-       enum drm_ctx_flags flags;
-};
-
-/**
- * DRM_IOCTL_RES_CTX ioctl argument type.
- */
-struct drm_ctx_res {
-       int count;
-       struct drm_ctx __user *contexts;
-};
-
-/**
- * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
- */
-struct drm_draw {
-       drm_drawable_t handle;
-};
-
-/**
- * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
- */
-typedef enum {
-       DRM_DRAWABLE_CLIPRECTS,
-} drm_drawable_info_type_t;
-
-struct drm_update_draw {
-       drm_drawable_t handle;
-       unsigned int type;
-       unsigned int num;
-       unsigned long long data;
-};
-
-/**
- * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
- */
-struct drm_auth {
-       drm_magic_t magic;
-};
-
-/**
- * DRM_IOCTL_IRQ_BUSID ioctl argument type.
- *
- * \sa drmGetInterruptFromBusID().
- */
-struct drm_irq_busid {
-       int irq;        /**< IRQ number */
-       int busnum;     /**< bus number */
-       int devnum;     /**< device number */
-       int funcnum;    /**< function number */
-};
-
-enum drm_vblank_seq_type {
-       _DRM_VBLANK_ABSOLUTE = 0x0,     /**< Wait for specific vblank sequence number */
-       _DRM_VBLANK_RELATIVE = 0x1,     /**< Wait for given number of vblanks */
-       _DRM_VBLANK_NEXTONMISS = 0x10000000,    /**< If missed, wait for next vblank */
-       _DRM_VBLANK_SECONDARY = 0x20000000,     /**< Secondary display controller */
-       _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */
-};
-
-#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
-#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \
-                               _DRM_VBLANK_NEXTONMISS)
-
-struct drm_wait_vblank_request {
-       enum drm_vblank_seq_type type;
-       unsigned int sequence;
-       unsigned long signal;
-};
-
-struct drm_wait_vblank_reply {
-       enum drm_vblank_seq_type type;
-       unsigned int sequence;
-       long tval_sec;
-       long tval_usec;
-};
-
-/**
- * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
- *
- * \sa drmWaitVBlank().
- */
-union drm_wait_vblank {
-       struct drm_wait_vblank_request request;
-       struct drm_wait_vblank_reply reply;
-};
-
-/**
- * DRM_IOCTL_AGP_ENABLE ioctl argument type.
- *
- * \sa drmAgpEnable().
- */
-struct drm_agp_mode {
-       unsigned long mode;     /**< AGP mode */
-};
-
-/**
- * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
- *
- * \sa drmAgpAlloc() and drmAgpFree().
- */
-struct drm_agp_buffer {
-       unsigned long size;     /**< In bytes -- will round to page boundary */
-       unsigned long handle;   /**< Used for binding / unbinding */
-       unsigned long type;     /**< Type of memory to allocate */
-       unsigned long physical; /**< Physical used by i810 */
-};
-
-/**
- * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
- *
- * \sa drmAgpBind() and drmAgpUnbind().
- */
-struct drm_agp_binding {
-       unsigned long handle;   /**< From drm_agp_buffer */
-       unsigned long offset;   /**< In bytes -- will round to page boundary */
-};
-
-/**
- * DRM_IOCTL_AGP_INFO ioctl argument type.
- *
- * \sa drmAgpVersionMajor(), drmAgpVersionMinor(), drmAgpGetMode(),
- * drmAgpBase(), drmAgpSize(), drmAgpMemoryUsed(), drmAgpMemoryAvail(),
- * drmAgpVendorId() and drmAgpDeviceId().
- */
-struct drm_agp_info {
-       int agp_version_major;
-       int agp_version_minor;
-       unsigned long mode;
-       unsigned long aperture_base;    /* physical address */
-       unsigned long aperture_size;    /* bytes */
-       unsigned long memory_allowed;   /* bytes */
-       unsigned long memory_used;
-
-       /* PCI information */
-       unsigned short id_vendor;
-       unsigned short id_device;
-};
-
-/**
- * DRM_IOCTL_SG_ALLOC ioctl argument type.
- */
-struct drm_scatter_gather {
-       unsigned long size;     /**< In bytes -- will round to page boundary */
-       unsigned long handle;   /**< Used for mapping / unmapping */
-};
-
-/**
- * DRM_IOCTL_SET_VERSION ioctl argument type.
- */
-struct drm_set_version {
-       int drm_di_major;
-       int drm_di_minor;
-       int drm_dd_major;
-       int drm_dd_minor;
-};
-
-#define DRM_IOCTL_BASE                 'd'
-#define DRM_IO(nr)                     _IO(DRM_IOCTL_BASE,nr)
-#define DRM_IOR(nr,type)               _IOR(DRM_IOCTL_BASE,nr,type)
-#define DRM_IOW(nr,type)               _IOW(DRM_IOCTL_BASE,nr,type)
-#define DRM_IOWR(nr,type)              _IOWR(DRM_IOCTL_BASE,nr,type)
-
-#define DRM_IOCTL_VERSION              DRM_IOWR(0x00, struct drm_version)
-#define DRM_IOCTL_GET_UNIQUE           DRM_IOWR(0x01, struct drm_unique)
-#define DRM_IOCTL_GET_MAGIC            DRM_IOR( 0x02, struct drm_auth)
-#define DRM_IOCTL_IRQ_BUSID            DRM_IOWR(0x03, struct drm_irq_busid)
-#define DRM_IOCTL_GET_MAP               DRM_IOWR(0x04, struct drm_map)
-#define DRM_IOCTL_GET_CLIENT            DRM_IOWR(0x05, struct drm_client)
-#define DRM_IOCTL_GET_STATS             DRM_IOR( 0x06, struct drm_stats)
-#define DRM_IOCTL_SET_VERSION          DRM_IOWR(0x07, struct drm_set_version)
-
-#define DRM_IOCTL_SET_UNIQUE           DRM_IOW( 0x10, struct drm_unique)
-#define DRM_IOCTL_AUTH_MAGIC           DRM_IOW( 0x11, struct drm_auth)
-#define DRM_IOCTL_BLOCK                        DRM_IOWR(0x12, struct drm_block)
-#define DRM_IOCTL_UNBLOCK              DRM_IOWR(0x13, struct drm_block)
-#define DRM_IOCTL_CONTROL              DRM_IOW( 0x14, struct drm_control)
-#define DRM_IOCTL_ADD_MAP              DRM_IOWR(0x15, struct drm_map)
-#define DRM_IOCTL_ADD_BUFS             DRM_IOWR(0x16, struct drm_buf_desc)
-#define DRM_IOCTL_MARK_BUFS            DRM_IOW( 0x17, struct drm_buf_desc)
-#define DRM_IOCTL_INFO_BUFS            DRM_IOWR(0x18, struct drm_buf_info)
-#define DRM_IOCTL_MAP_BUFS             DRM_IOWR(0x19, struct drm_buf_map)
-#define DRM_IOCTL_FREE_BUFS            DRM_IOW( 0x1a, struct drm_buf_free)
-
-#define DRM_IOCTL_RM_MAP               DRM_IOW( 0x1b, struct drm_map)
-
-#define DRM_IOCTL_SET_SAREA_CTX                DRM_IOW( 0x1c, struct drm_ctx_priv_map)
-#define DRM_IOCTL_GET_SAREA_CTX        DRM_IOWR(0x1d, struct drm_ctx_priv_map)
-
-#define DRM_IOCTL_ADD_CTX              DRM_IOWR(0x20, struct drm_ctx)
-#define DRM_IOCTL_RM_CTX               DRM_IOWR(0x21, struct drm_ctx)
-#define DRM_IOCTL_MOD_CTX              DRM_IOW( 0x22, struct drm_ctx)
-#define DRM_IOCTL_GET_CTX              DRM_IOWR(0x23, struct drm_ctx)
-#define DRM_IOCTL_SWITCH_CTX           DRM_IOW( 0x24, struct drm_ctx)
-#define DRM_IOCTL_NEW_CTX              DRM_IOW( 0x25, struct drm_ctx)
-#define DRM_IOCTL_RES_CTX              DRM_IOWR(0x26, struct drm_ctx_res)
-#define DRM_IOCTL_ADD_DRAW             DRM_IOWR(0x27, struct drm_draw)
-#define DRM_IOCTL_RM_DRAW              DRM_IOWR(0x28, struct drm_draw)
-#define DRM_IOCTL_DMA                  DRM_IOWR(0x29, struct drm_dma)
-#define DRM_IOCTL_LOCK                 DRM_IOW( 0x2a, struct drm_lock)
-#define DRM_IOCTL_UNLOCK               DRM_IOW( 0x2b, struct drm_lock)
-#define DRM_IOCTL_FINISH               DRM_IOW( 0x2c, struct drm_lock)
-
-#define DRM_IOCTL_AGP_ACQUIRE          DRM_IO(  0x30)
-#define DRM_IOCTL_AGP_RELEASE          DRM_IO(  0x31)
-#define DRM_IOCTL_AGP_ENABLE           DRM_IOW( 0x32, struct drm_agp_mode)
-#define DRM_IOCTL_AGP_INFO             DRM_IOR( 0x33, struct drm_agp_info)
-#define DRM_IOCTL_AGP_ALLOC            DRM_IOWR(0x34, struct drm_agp_buffer)
-#define DRM_IOCTL_AGP_FREE             DRM_IOW( 0x35, struct drm_agp_buffer)
-#define DRM_IOCTL_AGP_BIND             DRM_IOW( 0x36, struct drm_agp_binding)
-#define DRM_IOCTL_AGP_UNBIND           DRM_IOW( 0x37, struct drm_agp_binding)
-
-#define DRM_IOCTL_SG_ALLOC             DRM_IOWR(0x38, struct drm_scatter_gather)
-#define DRM_IOCTL_SG_FREE              DRM_IOW( 0x39, struct drm_scatter_gather)
-
-#define DRM_IOCTL_WAIT_VBLANK          DRM_IOWR(0x3a, union drm_wait_vblank)
-
-#define DRM_IOCTL_UPDATE_DRAW          DRM_IOW(0x3f, struct drm_update_draw)
-
-/**
- * Device specific ioctls should only be in their respective headers
- * The device specific ioctl range is from 0x40 to 0x99.
- * Generic IOCTLS restart at 0xA0.
- *
- * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
- * drmCommandReadWrite().
- */
-#define DRM_COMMAND_BASE                0x40
-#define DRM_COMMAND_END                        0xA0
-
-/* typedef area */
-#ifndef __KERNEL__
-typedef struct drm_clip_rect drm_clip_rect_t;
-typedef struct drm_drawable_info drm_drawable_info_t;
-typedef struct drm_tex_region drm_tex_region_t;
-typedef struct drm_hw_lock drm_hw_lock_t;
-typedef struct drm_version drm_version_t;
-typedef struct drm_unique drm_unique_t;
-typedef struct drm_list drm_list_t;
-typedef struct drm_block drm_block_t;
-typedef struct drm_control drm_control_t;
-typedef enum drm_map_type drm_map_type_t;
-typedef enum drm_map_flags drm_map_flags_t;
-typedef struct drm_ctx_priv_map drm_ctx_priv_map_t;
-typedef struct drm_map drm_map_t;
-typedef struct drm_client drm_client_t;
-typedef enum drm_stat_type drm_stat_type_t;
-typedef struct drm_stats drm_stats_t;
-typedef enum drm_lock_flags drm_lock_flags_t;
-typedef struct drm_lock drm_lock_t;
-typedef enum drm_dma_flags drm_dma_flags_t;
-typedef struct drm_buf_desc drm_buf_desc_t;
-typedef struct drm_buf_info drm_buf_info_t;
-typedef struct drm_buf_free drm_buf_free_t;
-typedef struct drm_buf_pub drm_buf_pub_t;
-typedef struct drm_buf_map drm_buf_map_t;
-typedef struct drm_dma drm_dma_t;
-typedef union drm_wait_vblank drm_wait_vblank_t;
-typedef struct drm_agp_mode drm_agp_mode_t;
-typedef enum drm_ctx_flags drm_ctx_flags_t;
-typedef struct drm_ctx drm_ctx_t;
-typedef struct drm_ctx_res drm_ctx_res_t;
-typedef struct drm_draw drm_draw_t;
-typedef struct drm_update_draw drm_update_draw_t;
-typedef struct drm_auth drm_auth_t;
-typedef struct drm_irq_busid drm_irq_busid_t;
-typedef enum drm_vblank_seq_type drm_vblank_seq_type_t;
-
-typedef struct drm_agp_buffer drm_agp_buffer_t;
-typedef struct drm_agp_binding drm_agp_binding_t;
-typedef struct drm_agp_info drm_agp_info_t;
-typedef struct drm_scatter_gather drm_scatter_gather_t;
-typedef struct drm_set_version drm_set_version_t;
-#endif
-
-#endif
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
deleted file mode 100644 (file)
index 0764b66..0000000
+++ /dev/null
@@ -1,1153 +0,0 @@
-/**
- * \file drmP.h
- * Private header for Direct Rendering Manager
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _DRM_P_H_
-#define _DRM_P_H_
-
-/* If you want the memory alloc debug functionality, change define below */
-/* #define DEBUG_MEMORY */
-
-#ifdef __KERNEL__
-#ifdef __alpha__
-/* add include of current.h so that "current" is defined
- * before static inline funcs in wait.h. Doing this so we
- * can build the DRM (part of PI DRI). 4/21/2000 S + B */
-#include <asm/current.h>
-#endif                         /* __alpha__ */
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/miscdevice.h>
-#include <linux/fs.h>
-#include <linux/proc_fs.h>
-#include <linux/init.h>
-#include <linux/file.h>
-#include <linux/pci.h>
-#include <linux/jiffies.h>
-#include <linux/smp_lock.h>    /* For (un)lock_kernel */
-#include <linux/dma-mapping.h>
-#include <linux/mm.h>
-#include <linux/cdev.h>
-#include <linux/mutex.h>
-#if defined(__alpha__) || defined(__powerpc__)
-#include <asm/pgtable.h>       /* For pte_wrprotect */
-#endif
-#include <asm/io.h>
-#include <asm/mman.h>
-#include <asm/uaccess.h>
-#ifdef CONFIG_MTRR
-#include <asm/mtrr.h>
-#endif
-#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
-#include <linux/types.h>
-#include <linux/agp_backend.h>
-#endif
-#include <linux/workqueue.h>
-#include <linux/poll.h>
-#include <asm/pgalloc.h>
-#include "drm.h"
-
-#include <linux/idr.h>
-
-#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
-#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
-
-struct drm_file;
-struct drm_device;
-
-#include "drm_os_linux.h"
-#include "drm_hashtab.h"
-
-/***********************************************************************/
-/** \name DRM template customization defaults */
-/*@{*/
-
-/* driver capabilities and requirements mask */
-#define DRIVER_USE_AGP     0x1
-#define DRIVER_REQUIRE_AGP 0x2
-#define DRIVER_USE_MTRR    0x4
-#define DRIVER_PCI_DMA     0x8
-#define DRIVER_SG          0x10
-#define DRIVER_HAVE_DMA    0x20
-#define DRIVER_HAVE_IRQ    0x40
-#define DRIVER_IRQ_SHARED  0x80
-#define DRIVER_IRQ_VBL     0x100
-#define DRIVER_DMA_QUEUE   0x200
-#define DRIVER_FB_DMA      0x400
-#define DRIVER_IRQ_VBL2    0x800
-
-/***********************************************************************/
-/** \name Begin the DRM... */
-/*@{*/
-
-#define DRM_DEBUG_CODE 2         /**< Include debugging code if > 1, then
-                                    also include looping detection. */
-
-#define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
-#define DRM_KERNEL_CONTEXT    0         /**< Change drm_resctx if changed */
-#define DRM_RESERVED_CONTEXTS 1         /**< Change drm_resctx if changed */
-#define DRM_LOOPING_LIMIT     5000000
-#define DRM_TIME_SLICE       (HZ/20)  /**< Time slice for GLXContexts */
-#define DRM_LOCK_SLICE       1 /**< Time slice for lock, in jiffies */
-
-#define DRM_FLAG_DEBUG   0x01
-
-#define DRM_MEM_DMA       0
-#define DRM_MEM_SAREA     1
-#define DRM_MEM_DRIVER    2
-#define DRM_MEM_MAGIC     3
-#define DRM_MEM_IOCTLS    4
-#define DRM_MEM_MAPS      5
-#define DRM_MEM_VMAS      6
-#define DRM_MEM_BUFS      7
-#define DRM_MEM_SEGS      8
-#define DRM_MEM_PAGES     9
-#define DRM_MEM_FILES    10
-#define DRM_MEM_QUEUES   11
-#define DRM_MEM_CMDS     12
-#define DRM_MEM_MAPPINGS  13
-#define DRM_MEM_BUFLISTS  14
-#define DRM_MEM_AGPLISTS  15
-#define DRM_MEM_TOTALAGP  16
-#define DRM_MEM_BOUNDAGP  17
-#define DRM_MEM_CTXBITMAP 18
-#define DRM_MEM_STUB      19
-#define DRM_MEM_SGLISTS   20
-#define DRM_MEM_CTXLIST   21
-#define DRM_MEM_MM        22
-#define DRM_MEM_HASHTAB   23
-
-#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
-#define DRM_MAP_HASH_OFFSET 0x10000000
-
-/*@}*/
-
-/***********************************************************************/
-/** \name Macros to make printk easier */
-/*@{*/
-
-/**
- * Error output.
- *
- * \param fmt printf() like format string.
- * \param arg arguments
- */
-#define DRM_ERROR(fmt, arg...) \
-       printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
-
-/**
- * Memory error output.
- *
- * \param area memory area where the error occurred.
- * \param fmt printf() like format string.
- * \param arg arguments
- */
-#define DRM_MEM_ERROR(area, fmt, arg...) \
-       printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
-              drm_mem_stats[area].name , ##arg)
-
-#define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
-
-/**
- * Debug output.
- *
- * \param fmt printf() like format string.
- * \param arg arguments
- */
-#if DRM_DEBUG_CODE
-#define DRM_DEBUG(fmt, arg...)                                         \
-       do {                                                            \
-               if ( drm_debug )                        \
-                       printk(KERN_DEBUG                               \
-                              "[" DRM_NAME ":%s] " fmt ,       \
-                              __func__ , ##arg);                       \
-       } while (0)
-#else
-#define DRM_DEBUG(fmt, arg...)          do { } while (0)
-#endif
-
-#define DRM_PROC_LIMIT (PAGE_SIZE-80)
-
-#define DRM_PROC_PRINT(fmt, arg...)                                    \
-   len += sprintf(&buf[len], fmt , ##arg);                             \
-   if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
-
-#define DRM_PROC_PRINT_RET(ret, fmt, arg...)                           \
-   len += sprintf(&buf[len], fmt , ##arg);                             \
-   if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
-
-/*@}*/
-
-/***********************************************************************/
-/** \name Internal types and structures */
-/*@{*/
-
-#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
-
-#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
-#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
-#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
-
-#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
-/**
- * Get the private SAREA mapping.
- *
- * \param _dev DRM device.
- * \param _ctx context number.
- * \param _map output mapping.
- */
-#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {      \
-       (_map) = (_dev)->context_sareas[_ctx];          \
-} while(0)
-
-/**
- * Test that the hardware lock is held by the caller, returning otherwise.
- *
- * \param dev DRM device.
- * \param filp file pointer of the caller.
- */
-#define LOCK_TEST_WITH_RETURN( dev, file_priv )                                \
-do {                                                                   \
-       if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||           \
-            dev->lock.file_priv != file_priv ) {                       \
-               DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
-                          __func__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
-                          dev->lock.file_priv, file_priv );            \
-               return -EINVAL;                                         \
-       }                                                               \
-} while (0)
-
-/**
- * Copy and IOCTL return string to user space
- */
-#define DRM_COPY( name, value )                                                \
-       len = strlen( value );                                          \
-       if ( len > name##_len ) len = name##_len;                       \
-       name##_len = strlen( value );                                   \
-       if ( len && name ) {                                            \
-               if ( copy_to_user( name, value, len ) )                 \
-                       return -EFAULT;                                 \
-       }
-
-/**
- * Ioctl function type.
- *
- * \param inode device inode.
- * \param file_priv DRM file private pointer.
- * \param cmd command.
- * \param arg argument.
- */
-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-
-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
-                              unsigned long arg);
-
-#define DRM_AUTH       0x1
-#define        DRM_MASTER      0x2
-#define DRM_ROOT_ONLY  0x4
-
-struct drm_ioctl_desc {
-       unsigned int cmd;
-       drm_ioctl_t *func;
-       int flags;
-};
-
-/**
- * Creates a driver or general drm_ioctl_desc array entry for the given
- * ioctl, for use by drm_ioctl().
- */
-#define DRM_IOCTL_DEF(ioctl, func, flags) \
-       [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
-
-struct drm_magic_entry {
-       struct list_head head;
-       struct drm_hash_item hash_item;
-       struct drm_file *priv;
-};
-
-struct drm_vma_entry {
-       struct list_head head;
-       struct vm_area_struct *vma;
-       pid_t pid;
-};
-
-/**
- * DMA buffer.
- */
-struct drm_buf {
-       int idx;                       /**< Index into master buflist */
-       int total;                     /**< Buffer size */
-       int order;                     /**< log-base-2(total) */
-       int used;                      /**< Amount of buffer in use (for DMA) */
-       unsigned long offset;          /**< Byte offset (used internally) */
-       void *address;                 /**< Address of buffer */
-       unsigned long bus_address;     /**< Bus address of buffer */
-       struct drm_buf *next;          /**< Kernel-only: used for free list */
-       __volatile__ int waiting;      /**< On kernel DMA queue */
-       __volatile__ int pending;      /**< On hardware DMA queue */
-       wait_queue_head_t dma_wait;    /**< Processes waiting */
-       struct drm_file *file_priv;    /**< Private of holding file descr */
-       int context;                   /**< Kernel queue for this buffer */
-       int while_locked;              /**< Dispatch this buffer while locked */
-       enum {
-               DRM_LIST_NONE = 0,
-               DRM_LIST_FREE = 1,
-               DRM_LIST_WAIT = 2,
-               DRM_LIST_PEND = 3,
-               DRM_LIST_PRIO = 4,
-               DRM_LIST_RECLAIM = 5
-       } list;                        /**< Which list we're on */
-
-       int dev_priv_size;               /**< Size of buffer private storage */
-       void *dev_private;               /**< Per-buffer private storage */
-};
-
-/** bufs is one longer than it has to be */
-struct drm_waitlist {
-       int count;                      /**< Number of possible buffers */
-       struct drm_buf **bufs;          /**< List of pointers to buffers */
-       struct drm_buf **rp;                    /**< Read pointer */
-       struct drm_buf **wp;                    /**< Write pointer */
-       struct drm_buf **end;           /**< End pointer */
-       spinlock_t read_lock;
-       spinlock_t write_lock;
-};
-
-struct drm_freelist {
-       int initialized;               /**< Freelist in use */
-       atomic_t count;                /**< Number of free buffers */
-       struct drm_buf *next;          /**< End pointer */
-
-       wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
-       int low_mark;                  /**< Low water mark */
-       int high_mark;                 /**< High water mark */
-       atomic_t wfh;                  /**< If waiting for high mark */
-       spinlock_t lock;
-};
-
-typedef struct drm_dma_handle {
-       dma_addr_t busaddr;
-       void *vaddr;
-       size_t size;
-} drm_dma_handle_t;
-
-/**
- * Buffer entry.  There is one of this for each buffer size order.
- */
-struct drm_buf_entry {
-       int buf_size;                   /**< size */
-       int buf_count;                  /**< number of buffers */
-       struct drm_buf *buflist;                /**< buffer list */
-       int seg_count;
-       int page_order;
-       struct drm_dma_handle **seglist;
-
-       struct drm_freelist freelist;
-};
-
-/** File private data */
-struct drm_file {
-       int authenticated;
-       int master;
-       pid_t pid;
-       uid_t uid;
-       drm_magic_t magic;
-       unsigned long ioctl_count;
-       struct list_head lhead;
-       struct drm_minor *minor;
-       int remove_auth_on_close;
-       unsigned long lock_count;
-       struct file *filp;
-       void *driver_priv;
-};
-
-/** Wait queue */
-struct drm_queue {
-       atomic_t use_count;             /**< Outstanding uses (+1) */
-       atomic_t finalization;          /**< Finalization in progress */
-       atomic_t block_count;           /**< Count of processes waiting */
-       atomic_t block_read;            /**< Queue blocked for reads */
-       wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
-       atomic_t block_write;           /**< Queue blocked for writes */
-       wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
-       atomic_t total_queued;          /**< Total queued statistic */
-       atomic_t total_flushed;         /**< Total flushes statistic */
-       atomic_t total_locks;           /**< Total locks statistics */
-       enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
-       struct drm_waitlist waitlist;   /**< Pending buffers */
-       wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
-};
-
-/**
- * Lock data.
- */
-struct drm_lock_data {
-       struct drm_hw_lock *hw_lock;    /**< Hardware lock */
-       /** Private of lock holder's file (NULL=kernel) */
-       struct drm_file *file_priv;
-       wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
-       unsigned long lock_time;        /**< Time of last lock in jiffies */
-       spinlock_t spinlock;
-       uint32_t kernel_waiters;
-       uint32_t user_waiters;
-       int idle_has_lock;
-};
-
-/**
- * DMA data.
- */
-struct drm_device_dma {
-
-       struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
-       int buf_count;                  /**< total number of buffers */
-       struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
-       int seg_count;
-       int page_count;                 /**< number of pages */
-       unsigned long *pagelist;        /**< page list */
-       unsigned long byte_count;
-       enum {
-               _DRM_DMA_USE_AGP = 0x01,
-               _DRM_DMA_USE_SG = 0x02,
-               _DRM_DMA_USE_FB = 0x04,
-               _DRM_DMA_USE_PCI_RO = 0x08
-       } flags;
-
-};
-
-/**
- * AGP memory entry.  Stored as a doubly linked list.
- */
-struct drm_agp_mem {
-       unsigned long handle;           /**< handle */
-       DRM_AGP_MEM *memory;
-       unsigned long bound;            /**< address */
-       int pages;
-       struct list_head head;
-};
-
-/**
- * AGP data.
- *
- * \sa drm_agp_init() and drm_device::agp.
- */
-struct drm_agp_head {
-       DRM_AGP_KERN agp_info;          /**< AGP device information */
-       struct list_head memory;
-       unsigned long mode;             /**< AGP mode */
-       struct agp_bridge_data *bridge;
-       int enabled;                    /**< whether the AGP bus as been enabled */
-       int acquired;                   /**< whether the AGP device has been acquired */
-       unsigned long base;
-       int agp_mtrr;
-       int cant_use_aperture;
-       unsigned long page_mask;
-};
-
-/**
- * Scatter-gather memory.
- */
-struct drm_sg_mem {
-       unsigned long handle;
-       void *virtual;
-       int pages;
-       struct page **pagelist;
-       dma_addr_t *busaddr;
-};
-
-struct drm_sigdata {
-       int context;
-       struct drm_hw_lock *lock;
-};
-
-
-/*
- * Generic memory manager structs
- */
-
-struct drm_mm_node {
-       struct list_head fl_entry;
-       struct list_head ml_entry;
-       int free;
-       unsigned long start;
-       unsigned long size;
-       struct drm_mm *mm;
-       void *private;
-};
-
-struct drm_mm {
-       struct list_head fl_entry;
-       struct list_head ml_entry;
-};
-
-
-/**
- * Mappings list
- */
-struct drm_map_list {
-       struct list_head head;          /**< list head */
-       struct drm_hash_item hash;
-       struct drm_map *map;                    /**< mapping */
-       uint64_t user_token;
-};
-
-typedef struct drm_map drm_local_map_t;
-
-/**
- * Context handle list
- */
-struct drm_ctx_list {
-       struct list_head head;          /**< list head */
-       drm_context_t handle;           /**< context handle */
-       struct drm_file *tag;           /**< associated fd private data */
-};
-
-struct drm_vbl_sig {
-       struct list_head head;
-       unsigned int sequence;
-       struct siginfo info;
-       struct task_struct *task;
-};
-
-/* location of GART table */
-#define DRM_ATI_GART_MAIN 1
-#define DRM_ATI_GART_FB   2
-
-#define DRM_ATI_GART_PCI 1
-#define DRM_ATI_GART_PCIE 2
-#define DRM_ATI_GART_IGP 3
-
-struct drm_ati_pcigart_info {
-       int gart_table_location;
-       int gart_reg_if;
-       void *addr;
-       dma_addr_t bus_addr;
-       dma_addr_t table_mask;
-       struct drm_dma_handle *table_handle;
-       drm_local_map_t mapping;
-       int table_size;
-};
-
-/**
- * DRM driver structure. This structure represent the common code for
- * a family of cards. There will one drm_device for each card present
- * in this family
- */
-struct drm_driver {
-       int (*load) (struct drm_device *, unsigned long flags);
-       int (*firstopen) (struct drm_device *);
-       int (*open) (struct drm_device *, struct drm_file *);
-       void (*preclose) (struct drm_device *, struct drm_file *file_priv);
-       void (*postclose) (struct drm_device *, struct drm_file *);
-       void (*lastclose) (struct drm_device *);
-       int (*unload) (struct drm_device *);
-       int (*suspend) (struct drm_device *, pm_message_t state);
-       int (*resume) (struct drm_device *);
-       int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
-       void (*dma_ready) (struct drm_device *);
-       int (*dma_quiescent) (struct drm_device *);
-       int (*context_ctor) (struct drm_device *dev, int context);
-       int (*context_dtor) (struct drm_device *dev, int context);
-       int (*kernel_context_switch) (struct drm_device *dev, int old,
-                                     int new);
-       void (*kernel_context_switch_unlock) (struct drm_device *dev);
-       int (*vblank_wait) (struct drm_device *dev, unsigned int *sequence);
-       int (*vblank_wait2) (struct drm_device *dev, unsigned int *sequence);
-       int (*dri_library_name) (struct drm_device *dev, char *buf);
-
-       /**
-        * Called by \c drm_device_is_agp.  Typically used to determine if a
-        * card is really attached to AGP or not.
-        *
-        * \param dev  DRM device handle
-        *
-        * \returns
-        * One of three values is returned depending on whether or not the
-        * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
-        * (return of 1), or may or may not be AGP (return of 2).
-        */
-       int (*device_is_agp) (struct drm_device *dev);
-
-       /* these have to be filled in */
-
-       irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
-       void (*irq_preinstall) (struct drm_device *dev);
-       void (*irq_postinstall) (struct drm_device *dev);
-       void (*irq_uninstall) (struct drm_device *dev);
-       void (*reclaim_buffers) (struct drm_device *dev,
-                                struct drm_file * file_priv);
-       void (*reclaim_buffers_locked) (struct drm_device *dev,
-                                       struct drm_file *file_priv);
-       void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
-                                           struct drm_file *file_priv);
-       unsigned long (*get_map_ofs) (struct drm_map * map);
-       unsigned long (*get_reg_ofs) (struct drm_device *dev);
-       void (*set_version) (struct drm_device *dev,
-                            struct drm_set_version *sv);
-
-       int major;
-       int minor;
-       int patchlevel;
-       char *name;
-       char *desc;
-       char *date;
-
-       u32 driver_features;
-       int dev_priv_size;
-       struct drm_ioctl_desc *ioctls;
-       int num_ioctls;
-       struct file_operations fops;
-       struct pci_driver pci_driver;
-};
-
-#define DRM_MINOR_UNASSIGNED 0
-#define DRM_MINOR_LEGACY 1
-
-/**
- * DRM minor structure. This structure represents a drm minor number.
- */
-struct drm_minor {
-       int index;                      /**< Minor device number */
-       int type;                       /**< Control or render */
-       dev_t device;                   /**< Device number for mknod */
-       struct device kdev;             /**< Linux device */
-       struct drm_device *dev;
-       struct proc_dir_entry *dev_root;  /**< proc directory entry */
-};
-
-/**
- * DRM device structure. This structure represent a complete card that
- * may contain multiple heads.
- */
-struct drm_device {
-       char *unique;                   /**< Unique identifier: e.g., busid */
-       int unique_len;                 /**< Length of unique field */
-       char *devname;                  /**< For /proc/interrupts */
-       int if_version;                 /**< Highest interface version set */
-
-       int blocked;                    /**< Blocked due to VC switch? */
-
-       /** \name Locks */
-       /*@{ */
-       spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
-       struct mutex struct_mutex;      /**< For others */
-       /*@} */
-
-       /** \name Usage Counters */
-       /*@{ */
-       int open_count;                 /**< Outstanding files open */
-       atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
-       atomic_t vma_count;             /**< Outstanding vma areas open */
-       int buf_use;                    /**< Buffers in use -- cannot alloc */
-       atomic_t buf_alloc;             /**< Buffer allocation in progress */
-       /*@} */
-
-       /** \name Performance counters */
-       /*@{ */
-       unsigned long counters;
-       enum drm_stat_type types[15];
-       atomic_t counts[15];
-       /*@} */
-
-       /** \name Authentication */
-       /*@{ */
-       struct list_head filelist;
-       struct drm_open_hash magiclist; /**< magic hash table */
-       struct list_head magicfree;
-       /*@} */
-
-       /** \name Memory management */
-       /*@{ */
-       struct list_head maplist;       /**< Linked list of regions */
-       int map_count;                  /**< Number of mappable regions */
-       struct drm_open_hash map_hash;  /**< User token hash table for maps */
-
-       /** \name Context handle management */
-       /*@{ */
-       struct list_head ctxlist;       /**< Linked list of context handles */
-       int ctx_count;                  /**< Number of context handles */
-       struct mutex ctxlist_mutex;     /**< For ctxlist */
-
-       struct idr ctx_idr;
-
-       struct list_head vmalist;       /**< List of vmas (for debugging) */
-       struct drm_lock_data lock;      /**< Information on hardware lock */
-       /*@} */
-
-       /** \name DMA queues (contexts) */
-       /*@{ */
-       int queue_count;                /**< Number of active DMA queues */
-       int queue_reserved;               /**< Number of reserved DMA queues */
-       int queue_slots;                /**< Actual length of queuelist */
-       struct drm_queue **queuelist;   /**< Vector of pointers to DMA queues */
-       struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
-       /*@} */
-
-       /** \name Context support */
-       /*@{ */
-       int irq;                        /**< Interrupt used by board */
-       int irq_enabled;                /**< True if irq handler is enabled */
-       __volatile__ long context_flag; /**< Context swapping flag */
-       __volatile__ long interrupt_flag; /**< Interruption handler flag */
-       __volatile__ long dma_flag;     /**< DMA dispatch flag */
-       struct timer_list timer;        /**< Timer for delaying ctx switch */
-       wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
-       int last_checked;               /**< Last context checked for DMA */
-       int last_context;               /**< Last current context */
-       unsigned long last_switch;      /**< jiffies at last context switch */
-       /*@} */
-
-       struct work_struct work;
-       /** \name VBLANK IRQ support */
-       /*@{ */
-
-       wait_queue_head_t vbl_queue;    /**< VBLANK wait queue */
-       atomic_t vbl_received;
-       atomic_t vbl_received2;         /**< number of secondary VBLANK interrupts */
-       spinlock_t vbl_lock;
-       struct list_head vbl_sigs;              /**< signal list to send on VBLANK */
-       struct list_head vbl_sigs2;     /**< signals to send on secondary VBLANK */
-       unsigned int vbl_pending;
-       spinlock_t tasklet_lock;        /**< For drm_locked_tasklet */
-       void (*locked_tasklet_func)(struct drm_device *dev);
-
-       /*@} */
-       cycles_t ctx_start;
-       cycles_t lck_start;
-
-       struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
-       wait_queue_head_t buf_readers;  /**< Processes waiting to read */
-       wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
-
-       struct drm_agp_head *agp;       /**< AGP data */
-
-       struct pci_dev *pdev;           /**< PCI device structure */
-       int pci_vendor;                 /**< PCI vendor id */
-       int pci_device;                 /**< PCI device id */
-#ifdef __alpha__
-       struct pci_controller *hose;
-#endif
-       struct drm_sg_mem *sg;  /**< Scatter gather memory */
-       void *dev_private;              /**< device private data */
-       struct drm_sigdata sigdata;        /**< For block_all_signals */
-       sigset_t sigmask;
-
-       struct drm_driver *driver;
-       drm_local_map_t *agp_buffer_map;
-       unsigned int agp_buffer_token;
-       struct drm_minor *primary;              /**< render type primary screen head */
-
-       /** \name Drawable information */
-       /*@{ */
-       spinlock_t drw_lock;
-       struct idr drw_idr;
-       /*@} */
-};
-
-static __inline__ int drm_core_check_feature(struct drm_device *dev,
-                                            int feature)
-{
-       return ((dev->driver->driver_features & feature) ? 1 : 0);
-}
-
-#ifdef __alpha__
-#define drm_get_pci_domain(dev) dev->hose->index
-#else
-#define drm_get_pci_domain(dev) 0
-#endif
-
-#if __OS_HAS_AGP
-static inline int drm_core_has_AGP(struct drm_device *dev)
-{
-       return drm_core_check_feature(dev, DRIVER_USE_AGP);
-}
-#else
-#define drm_core_has_AGP(dev) (0)
-#endif
-
-#if __OS_HAS_MTRR
-static inline int drm_core_has_MTRR(struct drm_device *dev)
-{
-       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
-}
-
-#define DRM_MTRR_WC            MTRR_TYPE_WRCOMB
-
-static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
-                              unsigned int flags)
-{
-       return mtrr_add(offset, size, flags, 1);
-}
-
-static inline int drm_mtrr_del(int handle, unsigned long offset,
-                              unsigned long size, unsigned int flags)
-{
-       return mtrr_del(handle, offset, size);
-}
-
-#else
-#define drm_core_has_MTRR(dev) (0)
-
-#define DRM_MTRR_WC            0
-
-static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
-                              unsigned int flags)
-{
-       return 0;
-}
-
-static inline int drm_mtrr_del(int handle, unsigned long offset,
-                              unsigned long size, unsigned int flags)
-{
-       return 0;
-}
-#endif
-
-/******************************************************************/
-/** \name Internal function definitions */
-/*@{*/
-
-                               /* Driver support (drm_drv.h) */
-extern int drm_init(struct drm_driver *driver);
-extern void drm_exit(struct drm_driver *driver);
-extern int drm_ioctl(struct inode *inode, struct file *filp,
-                    unsigned int cmd, unsigned long arg);
-extern long drm_compat_ioctl(struct file *filp,
-                            unsigned int cmd, unsigned long arg);
-extern int drm_lastclose(struct drm_device *dev);
-
-                               /* Device support (drm_fops.h) */
-extern int drm_open(struct inode *inode, struct file *filp);
-extern int drm_stub_open(struct inode *inode, struct file *filp);
-extern int drm_fasync(int fd, struct file *filp, int on);
-extern int drm_release(struct inode *inode, struct file *filp);
-
-                               /* Mapping support (drm_vm.h) */
-extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
-extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
-extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
-extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
-
-                               /* Memory management support (drm_memory.h) */
-#include "drm_memory.h"
-extern void drm_mem_init(void);
-extern int drm_mem_info(char *buf, char **start, off_t offset,
-                       int request, int *eof, void *data);
-extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
-
-extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
-extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
-extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
-extern int drm_unbind_agp(DRM_AGP_MEM * handle);
-
-                               /* Misc. IOCTL support (drm_ioctl.h) */
-extern int drm_irq_by_busid(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv);
-extern int drm_getunique(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int drm_setunique(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int drm_getmap(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_getclient(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int drm_getstats(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_setversion(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv);
-extern int drm_noop(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv);
-
-                               /* Context IOCTL support (drm_context.h) */
-extern int drm_resctx(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_addctx(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_modctx(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_getctx(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_switchctx(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int drm_newctx(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_rmctx(struct drm_device *dev, void *data,
-                    struct drm_file *file_priv);
-
-extern int drm_ctxbitmap_init(struct drm_device *dev);
-extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
-extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
-
-extern int drm_setsareactx(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv);
-extern int drm_getsareactx(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv);
-
-                               /* Drawable IOCTL support (drm_drawable.h) */
-extern int drm_adddraw(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-extern int drm_rmdraw(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_update_drawable_info(struct drm_device *dev, void *data,
-                                   struct drm_file *file_priv);
-extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
-                                                 drm_drawable_t id);
-extern void drm_drawable_free_all(struct drm_device *dev);
-
-                               /* Authentication IOCTL support (drm_auth.h) */
-extern int drm_getmagic(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_authmagic(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-
-                               /* Locking IOCTL support (drm_lock.h) */
-extern int drm_lock(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv);
-extern int drm_unlock(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv);
-extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
-extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
-extern void drm_idlelock_take(struct drm_lock_data *lock_data);
-extern void drm_idlelock_release(struct drm_lock_data *lock_data);
-
-/*
- * These are exported to drivers so that they can implement fencing using
- * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
- */
-
-extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
-
-                               /* Buffer management support (drm_bufs.h) */
-extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
-extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
-extern int drm_addmap(struct drm_device *dev, unsigned int offset,
-                     unsigned int size, enum drm_map_type type,
-                     enum drm_map_flags flags, drm_local_map_t ** map_ptr);
-extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv);
-extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
-extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
-extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv);
-extern int drm_addbufs(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-extern int drm_infobufs(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_markbufs(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_freebufs(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_mapbufs(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-extern int drm_order(unsigned long size);
-extern unsigned long drm_get_resource_start(struct drm_device *dev,
-                                           unsigned int resource);
-extern unsigned long drm_get_resource_len(struct drm_device *dev,
-                                         unsigned int resource);
-
-                               /* DMA support (drm_dma.h) */
-extern int drm_dma_setup(struct drm_device *dev);
-extern void drm_dma_takedown(struct drm_device *dev);
-extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
-extern void drm_core_reclaim_buffers(struct drm_device *dev,
-                                    struct drm_file *filp);
-
-                               /* IRQ support (drm_irq.h) */
-extern int drm_control(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
-extern int drm_irq_uninstall(struct drm_device *dev);
-extern void drm_driver_irq_preinstall(struct drm_device *dev);
-extern void drm_driver_irq_postinstall(struct drm_device *dev);
-extern void drm_driver_irq_uninstall(struct drm_device *dev);
-
-extern int drm_wait_vblank(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv);
-extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
-extern void drm_vbl_send_signals(struct drm_device *dev);
-extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
-
-                               /* AGP/GART support (drm_agpsupport.h) */
-extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
-extern int drm_agp_acquire(struct drm_device *dev);
-extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
-                                struct drm_file *file_priv);
-extern int drm_agp_release(struct drm_device *dev);
-extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
-                                struct drm_file *file_priv);
-extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
-extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
-                               struct drm_file *file_priv);
-extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
-extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
-extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
-extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
-extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv);
-extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
-extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
-extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
-extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
-extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
-
-                               /* Stub support (drm_stub.h) */
-extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
-                      struct drm_driver *driver);
-extern int drm_put_dev(struct drm_device *dev);
-extern int drm_put_minor(struct drm_minor **minor);
-extern unsigned int drm_debug;
-
-extern struct class *drm_class;
-extern struct proc_dir_entry *drm_proc_root;
-
-extern struct idr drm_minors_idr;
-
-extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
-
-                               /* Proc support (drm_proc.h) */
-extern int drm_proc_init(struct drm_minor *minor, int minor_id,
-                        struct proc_dir_entry *root);
-extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
-
-                               /* Scatter Gather Support (drm_scatter.h) */
-extern void drm_sg_cleanup(struct drm_sg_mem * entry);
-extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
-extern int drm_sg_free(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-
-                              /* ATI PCIGART support (ati_pcigart.h) */
-extern int drm_ati_pcigart_init(struct drm_device *dev,
-                               struct drm_ati_pcigart_info * gart_info);
-extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
-                                  struct drm_ati_pcigart_info * gart_info);
-
-extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
-                                      size_t align, dma_addr_t maxaddr);
-extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
-extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
-
-                              /* sysfs support (drm_sysfs.c) */
-struct drm_sysfs_class;
-extern struct class *drm_sysfs_create(struct module *owner, char *name);
-extern void drm_sysfs_destroy(void);
-extern int drm_sysfs_device_add(struct drm_minor *minor);
-extern void drm_sysfs_device_remove(struct drm_minor *minor);
-
-/*
- * Basic memory manager support (drm_mm.c)
- */
-extern struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
-                                      unsigned long size,
-                                      unsigned alignment);
-extern void drm_mm_put_block(struct drm_mm_node * cur);
-extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
-                                        unsigned alignment, int best_match);
-extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
-extern void drm_mm_takedown(struct drm_mm *mm);
-extern int drm_mm_clean(struct drm_mm *mm);
-extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
-extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
-extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
-
-extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
-extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
-
-static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
-                                                  unsigned int token)
-{
-       struct drm_map_list *_entry;
-       list_for_each_entry(_entry, &dev->maplist, head)
-           if (_entry->user_token == token)
-               return _entry->map;
-       return NULL;
-}
-
-static __inline__ int drm_device_is_agp(struct drm_device *dev)
-{
-       if (dev->driver->device_is_agp != NULL) {
-               int err = (*dev->driver->device_is_agp) (dev);
-
-               if (err != 2) {
-                       return err;
-               }
-       }
-
-       return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
-}
-
-static __inline__ int drm_device_is_pcie(struct drm_device *dev)
-{
-       return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
-}
-
-static __inline__ void drm_core_dropmap(struct drm_map *map)
-{
-}
-
-#ifndef DEBUG_MEMORY
-/** Wrapper around kmalloc() */
-static __inline__ void *drm_alloc(size_t size, int area)
-{
-       return kmalloc(size, GFP_KERNEL);
-}
-
-/** Wrapper around kfree() */
-static __inline__ void drm_free(void *pt, size_t size, int area)
-{
-       kfree(pt);
-}
-
-/** Wrapper around kcalloc() */
-static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
-{
-       return kcalloc(nmemb, size, GFP_KERNEL);
-}
-#else
-extern void *drm_alloc(size_t size, int area);
-extern void drm_free(void *pt, size_t size, int area);
-extern void *drm_calloc(size_t nmemb, size_t size, int area);
-#endif
-
-/*@}*/
-
-#endif                         /* __KERNEL__ */
-#endif
diff --git a/drivers/char/drm/drm_agpsupport.c b/drivers/char/drm/drm_agpsupport.c
deleted file mode 100644 (file)
index aefa5ac..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-/**
- * \file drm_agpsupport.c
- * DRM support for AGP/GART backend
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include <linux/module.h>
-
-#if __OS_HAS_AGP
-
-/**
- * Get AGP information.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a (output) drm_agp_info structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device has been initialized and acquired and fills in the
- * drm_agp_info structure with the information in drm_agp_head::agp_info.
- */
-int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info)
-{
-       DRM_AGP_KERN *kern;
-
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-
-       kern = &dev->agp->agp_info;
-       info->agp_version_major = kern->version.major;
-       info->agp_version_minor = kern->version.minor;
-       info->mode = kern->mode;
-       info->aperture_base = kern->aper_base;
-       info->aperture_size = kern->aper_size * 1024 * 1024;
-       info->memory_allowed = kern->max_memory << PAGE_SHIFT;
-       info->memory_used = kern->current_memory << PAGE_SHIFT;
-       info->id_vendor = kern->device->vendor;
-       info->id_device = kern->device->device;
-
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_agp_info);
-
-int drm_agp_info_ioctl(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_agp_info *info = data;
-       int err;
-
-       err = drm_agp_info(dev, info);
-       if (err)
-               return err;
-
-       return 0;
-}
-
-/**
- * Acquire the AGP device.
- *
- * \param dev DRM device that is to acquire AGP.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device hasn't been acquired before and calls
- * \c agp_backend_acquire.
- */
-int drm_agp_acquire(struct drm_device * dev)
-{
-       if (!dev->agp)
-               return -ENODEV;
-       if (dev->agp->acquired)
-               return -EBUSY;
-       if (!(dev->agp->bridge = agp_backend_acquire(dev->pdev)))
-               return -ENODEV;
-       dev->agp->acquired = 1;
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_agp_acquire);
-
-/**
- * Acquire the AGP device (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device hasn't been acquired before and calls
- * \c agp_backend_acquire.
- */
-int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       return drm_agp_acquire((struct drm_device *) file_priv->minor->dev);
-}
-
-/**
- * Release the AGP device.
- *
- * \param dev DRM device that is to release AGP.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device has been acquired and calls \c agp_backend_release.
- */
-int drm_agp_release(struct drm_device * dev)
-{
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-       agp_backend_release(dev->agp->bridge);
-       dev->agp->acquired = 0;
-       return 0;
-}
-EXPORT_SYMBOL(drm_agp_release);
-
-int drm_agp_release_ioctl(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       return drm_agp_release(dev);
-}
-
-/**
- * Enable the AGP bus.
- *
- * \param dev DRM device that has previously acquired AGP.
- * \param mode Requested AGP mode.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device has been acquired but not enabled, and calls
- * \c agp_enable.
- */
-int drm_agp_enable(struct drm_device * dev, struct drm_agp_mode mode)
-{
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-
-       dev->agp->mode = mode.mode;
-       agp_enable(dev->agp->bridge, mode.mode);
-       dev->agp->enabled = 1;
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_agp_enable);
-
-int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       struct drm_agp_mode *mode = data;
-
-       return drm_agp_enable(dev, *mode);
-}
-
-/**
- * Allocate AGP memory.
- *
- * \param inode device inode.
- * \param file_priv file private pointer.
- * \param cmd command.
- * \param arg pointer to a drm_agp_buffer structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device is present and has been acquired, allocates the
- * memory via alloc_agp() and creates a drm_agp_mem entry for it.
- */
-int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
-{
-       struct drm_agp_mem *entry;
-       DRM_AGP_MEM *memory;
-       unsigned long pages;
-       u32 type;
-
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-       if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
-               return -ENOMEM;
-
-       memset(entry, 0, sizeof(*entry));
-
-       pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
-       type = (u32) request->type;
-       if (!(memory = drm_alloc_agp(dev, pages, type))) {
-               drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
-               return -ENOMEM;
-       }
-
-       entry->handle = (unsigned long)memory->key + 1;
-       entry->memory = memory;
-       entry->bound = 0;
-       entry->pages = pages;
-       list_add(&entry->head, &dev->agp->memory);
-
-       request->handle = entry->handle;
-       request->physical = memory->physical;
-
-       return 0;
-}
-EXPORT_SYMBOL(drm_agp_alloc);
-
-
-int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       struct drm_agp_buffer *request = data;
-
-       return drm_agp_alloc(dev, request);
-}
-
-/**
- * Search for the AGP memory entry associated with a handle.
- *
- * \param dev DRM device structure.
- * \param handle AGP memory handle.
- * \return pointer to the drm_agp_mem structure associated with \p handle.
- *
- * Walks through drm_agp_head::memory until finding a matching handle.
- */
-static struct drm_agp_mem *drm_agp_lookup_entry(struct drm_device * dev,
-                                          unsigned long handle)
-{
-       struct drm_agp_mem *entry;
-
-       list_for_each_entry(entry, &dev->agp->memory, head) {
-               if (entry->handle == handle)
-                       return entry;
-       }
-       return NULL;
-}
-
-/**
- * Unbind AGP memory from the GATT (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_agp_binding structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device is present and acquired, looks-up the AGP memory
- * entry and passes it to the unbind_agp() function.
- */
-int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
-{
-       struct drm_agp_mem *entry;
-       int ret;
-
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
-               return -EINVAL;
-       if (!entry->bound)
-               return -EINVAL;
-       ret = drm_unbind_agp(entry->memory);
-       if (ret == 0)
-               entry->bound = 0;
-       return ret;
-}
-EXPORT_SYMBOL(drm_agp_unbind);
-
-
-int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       struct drm_agp_binding *request = data;
-
-       return drm_agp_unbind(dev, request);
-}
-
-/**
- * Bind AGP memory into the GATT (ioctl)
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_agp_binding structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device is present and has been acquired and that no memory
- * is currently bound into the GATT. Looks-up the AGP memory entry and passes
- * it to bind_agp() function.
- */
-int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
-{
-       struct drm_agp_mem *entry;
-       int retcode;
-       int page;
-
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
-               return -EINVAL;
-       if (entry->bound)
-               return -EINVAL;
-       page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
-       if ((retcode = drm_bind_agp(entry->memory, page)))
-               return retcode;
-       entry->bound = dev->agp->base + (page << PAGE_SHIFT);
-       DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
-                 dev->agp->base, entry->bound);
-       return 0;
-}
-EXPORT_SYMBOL(drm_agp_bind);
-
-
-int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_agp_binding *request = data;
-
-       return drm_agp_bind(dev, request);
-}
-
-/**
- * Free AGP memory (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_agp_buffer structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the AGP device is present and has been acquired and looks up the
- * AGP memory entry. If the memory it's currently bound, unbind it via
- * unbind_agp(). Frees it via free_agp() as well as the entry itself
- * and unlinks from the doubly linked list it's inserted in.
- */
-int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
-{
-       struct drm_agp_mem *entry;
-
-       if (!dev->agp || !dev->agp->acquired)
-               return -EINVAL;
-       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
-               return -EINVAL;
-       if (entry->bound)
-               drm_unbind_agp(entry->memory);
-
-       list_del(&entry->head);
-
-       drm_free_agp(entry->memory, entry->pages);
-       drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
-       return 0;
-}
-EXPORT_SYMBOL(drm_agp_free);
-
-
-
-int drm_agp_free_ioctl(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_agp_buffer *request = data;
-
-       return drm_agp_free(dev, request);
-}
-
-/**
- * Initialize the AGP resources.
- *
- * \return pointer to a drm_agp_head structure.
- *
- * Gets the drm_agp_t structure which is made available by the agpgart module
- * via the inter_module_* functions. Creates and initializes a drm_agp_head
- * structure.
- */
-struct drm_agp_head *drm_agp_init(struct drm_device *dev)
-{
-       struct drm_agp_head *head = NULL;
-
-       if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
-               return NULL;
-       memset((void *)head, 0, sizeof(*head));
-       head->bridge = agp_find_bridge(dev->pdev);
-       if (!head->bridge) {
-               if (!(head->bridge = agp_backend_acquire(dev->pdev))) {
-                       drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
-                       return NULL;
-               }
-               agp_copy_info(head->bridge, &head->agp_info);
-               agp_backend_release(head->bridge);
-       } else {
-               agp_copy_info(head->bridge, &head->agp_info);
-       }
-       if (head->agp_info.chipset == NOT_SUPPORTED) {
-               drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
-               return NULL;
-       }
-       INIT_LIST_HEAD(&head->memory);
-       head->cant_use_aperture = head->agp_info.cant_use_aperture;
-       head->page_mask = head->agp_info.page_mask;
-       head->base = head->agp_info.aper_base;
-       return head;
-}
-
-/** Calls agp_allocate_memory() */
-DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
-                                    size_t pages, u32 type)
-{
-       return agp_allocate_memory(bridge, pages, type);
-}
-
-/** Calls agp_free_memory() */
-int drm_agp_free_memory(DRM_AGP_MEM * handle)
-{
-       if (!handle)
-               return 0;
-       agp_free_memory(handle);
-       return 1;
-}
-
-/** Calls agp_bind_memory() */
-int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
-{
-       if (!handle)
-               return -EINVAL;
-       return agp_bind_memory(handle, start);
-}
-
-/** Calls agp_unbind_memory() */
-int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
-{
-       if (!handle)
-               return -EINVAL;
-       return agp_unbind_memory(handle);
-}
-
-#endif                         /* __OS_HAS_AGP */
diff --git a/drivers/char/drm/drm_auth.c b/drivers/char/drm/drm_auth.c
deleted file mode 100644 (file)
index a734627..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * \file drm_auth.c
- * IOCTLs for authentication
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-/**
- * Find the file with the given magic number.
- *
- * \param dev DRM device.
- * \param magic magic number.
- *
- * Searches in drm_device::magiclist within all files with the same hash key
- * the one with matching magic number, while holding the drm_device::struct_mutex
- * lock.
- */
-static struct drm_file *drm_find_file(struct drm_device * dev, drm_magic_t magic)
-{
-       struct drm_file *retval = NULL;
-       struct drm_magic_entry *pt;
-       struct drm_hash_item *hash;
-
-       mutex_lock(&dev->struct_mutex);
-       if (!drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
-               pt = drm_hash_entry(hash, struct drm_magic_entry, hash_item);
-               retval = pt->priv;
-       }
-       mutex_unlock(&dev->struct_mutex);
-       return retval;
-}
-
-/**
- * Adds a magic number.
- *
- * \param dev DRM device.
- * \param priv file private data.
- * \param magic magic number.
- *
- * Creates a drm_magic_entry structure and appends to the linked list
- * associated the magic number hash key in drm_device::magiclist, while holding
- * the drm_device::struct_mutex lock.
- */
-static int drm_add_magic(struct drm_device * dev, struct drm_file * priv,
-                        drm_magic_t magic)
-{
-       struct drm_magic_entry *entry;
-
-       DRM_DEBUG("%d\n", magic);
-
-       entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
-       if (!entry)
-               return -ENOMEM;
-       memset(entry, 0, sizeof(*entry));
-       entry->priv = priv;
-
-       entry->hash_item.key = (unsigned long)magic;
-       mutex_lock(&dev->struct_mutex);
-       drm_ht_insert_item(&dev->magiclist, &entry->hash_item);
-       list_add_tail(&entry->head, &dev->magicfree);
-       mutex_unlock(&dev->struct_mutex);
-
-       return 0;
-}
-
-/**
- * Remove a magic number.
- *
- * \param dev DRM device.
- * \param magic magic number.
- *
- * Searches and unlinks the entry in drm_device::magiclist with the magic
- * number hash key, while holding the drm_device::struct_mutex lock.
- */
-static int drm_remove_magic(struct drm_device * dev, drm_magic_t magic)
-{
-       struct drm_magic_entry *pt;
-       struct drm_hash_item *hash;
-
-       DRM_DEBUG("%d\n", magic);
-
-       mutex_lock(&dev->struct_mutex);
-       if (drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-       pt = drm_hash_entry(hash, struct drm_magic_entry, hash_item);
-       drm_ht_remove_item(&dev->magiclist, hash);
-       list_del(&pt->head);
-       mutex_unlock(&dev->struct_mutex);
-
-       drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
-
-       return 0;
-}
-
-/**
- * Get a unique magic number (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a resulting drm_auth structure.
- * \return zero on success, or a negative number on failure.
- *
- * If there is a magic number in drm_file::magic then use it, otherwise
- * searches an unique non-zero magic number and add it associating it with \p
- * file_priv.
- */
-int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       static drm_magic_t sequence = 0;
-       static DEFINE_SPINLOCK(lock);
-       struct drm_auth *auth = data;
-
-       /* Find unique magic */
-       if (file_priv->magic) {
-               auth->magic = file_priv->magic;
-       } else {
-               do {
-                       spin_lock(&lock);
-                       if (!sequence)
-                               ++sequence;     /* reserve 0 */
-                       auth->magic = sequence++;
-                       spin_unlock(&lock);
-               } while (drm_find_file(dev, auth->magic));
-               file_priv->magic = auth->magic;
-               drm_add_magic(dev, file_priv, auth->magic);
-       }
-
-       DRM_DEBUG("%u\n", auth->magic);
-
-       return 0;
-}
-
-/**
- * Authenticate with a magic.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_auth structure.
- * \return zero if authentication successed, or a negative number otherwise.
- *
- * Checks if \p file_priv is associated with the magic number passed in \arg.
- */
-int drm_authmagic(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       struct drm_auth *auth = data;
-       struct drm_file *file;
-
-       DRM_DEBUG("%u\n", auth->magic);
-       if ((file = drm_find_file(dev, auth->magic))) {
-               file->authenticated = 1;
-               drm_remove_magic(dev, auth->magic);
-               return 0;
-       }
-       return -EINVAL;
-}
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
deleted file mode 100644 (file)
index bde64b8..0000000
+++ /dev/null
@@ -1,1601 +0,0 @@
-/**
- * \file drm_bufs.c
- * Generic buffer template
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
- *
- * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/vmalloc.h>
-#include "drmP.h"
-
-unsigned long drm_get_resource_start(struct drm_device *dev, unsigned int resource)
-{
-       return pci_resource_start(dev->pdev, resource);
-}
-EXPORT_SYMBOL(drm_get_resource_start);
-
-unsigned long drm_get_resource_len(struct drm_device *dev, unsigned int resource)
-{
-       return pci_resource_len(dev->pdev, resource);
-}
-
-EXPORT_SYMBOL(drm_get_resource_len);
-
-static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
-                                            drm_local_map_t *map)
-{
-       struct drm_map_list *entry;
-       list_for_each_entry(entry, &dev->maplist, head) {
-               if (entry->map && map->type == entry->map->type &&
-                   ((entry->map->offset == map->offset) ||
-                    (map->type == _DRM_SHM && map->flags==_DRM_CONTAINS_LOCK))) {
-                       return entry;
-               }
-       }
-
-       return NULL;
-}
-
-static int drm_map_handle(struct drm_device *dev, struct drm_hash_item *hash,
-                         unsigned long user_token, int hashed_handle)
-{
-       int use_hashed_handle;
-#if (BITS_PER_LONG == 64)
-       use_hashed_handle = ((user_token & 0xFFFFFFFF00000000UL) || hashed_handle);
-#elif (BITS_PER_LONG == 32)
-       use_hashed_handle = hashed_handle;
-#else
-#error Unsupported long size. Neither 64 nor 32 bits.
-#endif
-
-       if (!use_hashed_handle) {
-               int ret;
-               hash->key = user_token >> PAGE_SHIFT;
-               ret = drm_ht_insert_item(&dev->map_hash, hash);
-               if (ret != -EINVAL)
-                       return ret;
-       }
-       return drm_ht_just_insert_please(&dev->map_hash, hash,
-                                        user_token, 32 - PAGE_SHIFT - 3,
-                                        0, DRM_MAP_HASH_OFFSET >> PAGE_SHIFT);
-}
-
-/**
- * Ioctl to specify a range of memory that is available for mapping by a non-root process.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_map structure.
- * \return zero on success or a negative value on error.
- *
- * Adjusts the memory offset to its absolute value according to the mapping
- * type.  Adds the map to the map list drm_device::maplist. Adds MTRR's where
- * applicable and if supported by the kernel.
- */
-static int drm_addmap_core(struct drm_device * dev, unsigned int offset,
-                          unsigned int size, enum drm_map_type type,
-                          enum drm_map_flags flags,
-                          struct drm_map_list ** maplist)
-{
-       struct drm_map *map;
-       struct drm_map_list *list;
-       drm_dma_handle_t *dmah;
-       unsigned long user_token;
-       int ret;
-
-       map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
-       if (!map)
-               return -ENOMEM;
-
-       map->offset = offset;
-       map->size = size;
-       map->flags = flags;
-       map->type = type;
-
-       /* Only allow shared memory to be removable since we only keep enough
-        * book keeping information about shared memory to allow for removal
-        * when processes fork.
-        */
-       if ((map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM) {
-               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               return -EINVAL;
-       }
-       DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
-                 map->offset, map->size, map->type);
-       if ((map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK))) {
-               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               return -EINVAL;
-       }
-       map->mtrr = -1;
-       map->handle = NULL;
-
-       switch (map->type) {
-       case _DRM_REGISTERS:
-       case _DRM_FRAME_BUFFER:
-#if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && !defined(__powerpc64__) && !defined(__x86_64__)
-               if (map->offset + (map->size-1) < map->offset ||
-                   map->offset < virt_to_phys(high_memory)) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -EINVAL;
-               }
-#endif
-#ifdef __alpha__
-               map->offset += dev->hose->mem_space->start;
-#endif
-               /* Some drivers preinitialize some maps, without the X Server
-                * needing to be aware of it.  Therefore, we just return success
-                * when the server tries to create a duplicate map.
-                */
-               list = drm_find_matching_map(dev, map);
-               if (list != NULL) {
-                       if (list->map->size != map->size) {
-                               DRM_DEBUG("Matching maps of type %d with "
-                                         "mismatched sizes, (%ld vs %ld)\n",
-                                         map->type, map->size,
-                                         list->map->size);
-                               list->map->size = map->size;
-                       }
-
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       *maplist = list;
-                       return 0;
-               }
-
-               if (drm_core_has_MTRR(dev)) {
-                       if (map->type == _DRM_FRAME_BUFFER ||
-                           (map->flags & _DRM_WRITE_COMBINING)) {
-                               map->mtrr = mtrr_add(map->offset, map->size,
-                                                    MTRR_TYPE_WRCOMB, 1);
-                       }
-               }
-               if (map->type == _DRM_REGISTERS) {
-                       map->handle = ioremap(map->offset, map->size);
-                       if (!map->handle) {
-                               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                               return -ENOMEM;
-                       }
-               }
-
-               break;
-       case _DRM_SHM:
-               list = drm_find_matching_map(dev, map);
-               if (list != NULL) {
-                       if(list->map->size != map->size) {
-                               DRM_DEBUG("Matching maps of type %d with "
-                                         "mismatched sizes, (%ld vs %ld)\n",
-                                         map->type, map->size, list->map->size);
-                               list->map->size = map->size;
-                       }
-
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       *maplist = list;
-                       return 0;
-               }
-               map->handle = vmalloc_user(map->size);
-               DRM_DEBUG("%lu %d %p\n",
-                         map->size, drm_order(map->size), map->handle);
-               if (!map->handle) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -ENOMEM;
-               }
-               map->offset = (unsigned long)map->handle;
-               if (map->flags & _DRM_CONTAINS_LOCK) {
-                       /* Prevent a 2nd X Server from creating a 2nd lock */
-                       if (dev->lock.hw_lock != NULL) {
-                               vfree(map->handle);
-                               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                               return -EBUSY;
-                       }
-                       dev->sigdata.lock = dev->lock.hw_lock = map->handle;    /* Pointer to lock */
-               }
-               break;
-       case _DRM_AGP: {
-               struct drm_agp_mem *entry;
-               int valid = 0;
-
-               if (!drm_core_has_AGP(dev)) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -EINVAL;
-               }
-#ifdef __alpha__
-               map->offset += dev->hose->mem_space->start;
-#endif
-               /* In some cases (i810 driver), user space may have already
-                * added the AGP base itself, because dev->agp->base previously
-                * only got set during AGP enable.  So, only add the base
-                * address if the map's offset isn't already within the
-                * aperture.
-                */
-               if (map->offset < dev->agp->base ||
-                   map->offset > dev->agp->base +
-                   dev->agp->agp_info.aper_size * 1024 * 1024 - 1) {
-                       map->offset += dev->agp->base;
-               }
-               map->mtrr = dev->agp->agp_mtrr; /* for getmap */
-
-               /* This assumes the DRM is in total control of AGP space.
-                * It's not always the case as AGP can be in the control
-                * of user space (i.e. i810 driver). So this loop will get
-                * skipped and we double check that dev->agp->memory is
-                * actually set as well as being invalid before EPERM'ing
-                */
-               list_for_each_entry(entry, &dev->agp->memory, head) {
-                       if ((map->offset >= entry->bound) &&
-                           (map->offset + map->size <= entry->bound + entry->pages * PAGE_SIZE)) {
-                               valid = 1;
-                               break;
-                       }
-               }
-               if (!list_empty(&dev->agp->memory) && !valid) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -EPERM;
-               }
-               DRM_DEBUG("AGP offset = 0x%08lx, size = 0x%08lx\n", map->offset, map->size);
-
-               break;
-       }
-       case _DRM_SCATTER_GATHER:
-               if (!dev->sg) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -EINVAL;
-               }
-               map->offset += (unsigned long)dev->sg->virtual;
-               break;
-       case _DRM_CONSISTENT:
-               /* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
-                * As we're limiting the address to 2^32-1 (or less),
-                * casting it down to 32 bits is no problem, but we
-                * need to point to a 64bit variable first. */
-               dmah = drm_pci_alloc(dev, map->size, map->size, 0xffffffffUL);
-               if (!dmah) {
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-                       return -ENOMEM;
-               }
-               map->handle = dmah->vaddr;
-               map->offset = (unsigned long)dmah->busaddr;
-               kfree(dmah);
-               break;
-       default:
-               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               return -EINVAL;
-       }
-
-       list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
-       if (!list) {
-               if (map->type == _DRM_REGISTERS)
-                       iounmap(map->handle);
-               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               return -EINVAL;
-       }
-       memset(list, 0, sizeof(*list));
-       list->map = map;
-
-       mutex_lock(&dev->struct_mutex);
-       list_add(&list->head, &dev->maplist);
-
-       /* Assign a 32-bit handle */
-       /* We do it here so that dev->struct_mutex protects the increment */
-       user_token = (map->type == _DRM_SHM) ? (unsigned long)map->handle :
-               map->offset;
-       ret = drm_map_handle(dev, &list->hash, user_token, 0);
-       if (ret) {
-               if (map->type == _DRM_REGISTERS)
-                       iounmap(map->handle);
-               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               drm_free(list, sizeof(*list), DRM_MEM_MAPS);
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       list->user_token = list->hash.key << PAGE_SHIFT;
-       mutex_unlock(&dev->struct_mutex);
-
-       *maplist = list;
-       return 0;
-       }
-
-int drm_addmap(struct drm_device * dev, unsigned int offset,
-              unsigned int size, enum drm_map_type type,
-              enum drm_map_flags flags, drm_local_map_t ** map_ptr)
-{
-       struct drm_map_list *list;
-       int rc;
-
-       rc = drm_addmap_core(dev, offset, size, type, flags, &list);
-       if (!rc)
-               *map_ptr = list->map;
-       return rc;
-}
-
-EXPORT_SYMBOL(drm_addmap);
-
-int drm_addmap_ioctl(struct drm_device *dev, void *data,
-                    struct drm_file *file_priv)
-{
-       struct drm_map *map = data;
-       struct drm_map_list *maplist;
-       int err;
-
-       if (!(capable(CAP_SYS_ADMIN) || map->type == _DRM_AGP))
-               return -EPERM;
-
-       err = drm_addmap_core(dev, map->offset, map->size, map->type,
-                             map->flags, &maplist);
-
-       if (err)
-               return err;
-
-       /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
-       map->handle = (void *)(unsigned long)maplist->user_token;
-       return 0;
-}
-
-/**
- * Remove a map private from list and deallocate resources if the mapping
- * isn't in use.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a struct drm_map structure.
- * \return zero on success or a negative value on error.
- *
- * Searches the map on drm_device::maplist, removes it from the list, see if
- * its being used, and free any associate resource (such as MTRR's) if it's not
- * being on use.
- *
- * \sa drm_addmap
- */
-int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map)
-{
-       struct drm_map_list *r_list = NULL, *list_t;
-       drm_dma_handle_t dmah;
-       int found = 0;
-
-       /* Find the list entry for the map and remove it */
-       list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) {
-               if (r_list->map == map) {
-                       list_del(&r_list->head);
-                       drm_ht_remove_key(&dev->map_hash,
-                                         r_list->user_token >> PAGE_SHIFT);
-                       drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS);
-                       found = 1;
-                       break;
-               }
-       }
-
-       if (!found)
-               return -EINVAL;
-
-       switch (map->type) {
-       case _DRM_REGISTERS:
-               iounmap(map->handle);
-               /* FALLTHROUGH */
-       case _DRM_FRAME_BUFFER:
-               if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
-                       int retcode;
-                       retcode = mtrr_del(map->mtrr, map->offset, map->size);
-                       DRM_DEBUG("mtrr_del=%d\n", retcode);
-               }
-               break;
-       case _DRM_SHM:
-               vfree(map->handle);
-               break;
-       case _DRM_AGP:
-       case _DRM_SCATTER_GATHER:
-               break;
-       case _DRM_CONSISTENT:
-               dmah.vaddr = map->handle;
-               dmah.busaddr = map->offset;
-               dmah.size = map->size;
-               __drm_pci_free(dev, &dmah);
-               break;
-       }
-       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-
-       return 0;
-}
-
-int drm_rmmap(struct drm_device *dev, drm_local_map_t *map)
-{
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_rmmap_locked(dev, map);
-       mutex_unlock(&dev->struct_mutex);
-
-       return ret;
-}
-EXPORT_SYMBOL(drm_rmmap);
-
-/* The rmmap ioctl appears to be unnecessary.  All mappings are torn down on
- * the last close of the device, and this is necessary for cleanup when things
- * exit uncleanly.  Therefore, having userland manually remove mappings seems
- * like a pointless exercise since they're going away anyway.
- *
- * One use case might be after addmap is allowed for normal users for SHM and
- * gets used by drivers that the server doesn't need to care about.  This seems
- * unlikely.
- */
-int drm_rmmap_ioctl(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv)
-{
-       struct drm_map *request = data;
-       drm_local_map_t *map = NULL;
-       struct drm_map_list *r_list;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               if (r_list->map &&
-                   r_list->user_token == (unsigned long)request->handle &&
-                   r_list->map->flags & _DRM_REMOVABLE) {
-                       map = r_list->map;
-                       break;
-               }
-       }
-
-       /* List has wrapped around to the head pointer, or its empty we didn't
-        * find anything.
-        */
-       if (list_empty(&dev->maplist) || !map) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       /* Register and framebuffer maps are permanent */
-       if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) {
-               mutex_unlock(&dev->struct_mutex);
-               return 0;
-       }
-
-       ret = drm_rmmap_locked(dev, map);
-
-       mutex_unlock(&dev->struct_mutex);
-
-       return ret;
-}
-
-/**
- * Cleanup after an error on one of the addbufs() functions.
- *
- * \param dev DRM device.
- * \param entry buffer entry where the error occurred.
- *
- * Frees any pages and buffers associated with the given entry.
- */
-static void drm_cleanup_buf_error(struct drm_device * dev,
-                                 struct drm_buf_entry * entry)
-{
-       int i;
-
-       if (entry->seg_count) {
-               for (i = 0; i < entry->seg_count; i++) {
-                       if (entry->seglist[i]) {
-                               drm_pci_free(dev, entry->seglist[i]);
-                       }
-               }
-               drm_free(entry->seglist,
-                        entry->seg_count *
-                        sizeof(*entry->seglist), DRM_MEM_SEGS);
-
-               entry->seg_count = 0;
-       }
-
-       if (entry->buf_count) {
-               for (i = 0; i < entry->buf_count; i++) {
-                       if (entry->buflist[i].dev_private) {
-                               drm_free(entry->buflist[i].dev_private,
-                                        entry->buflist[i].dev_priv_size,
-                                        DRM_MEM_BUFS);
-                       }
-               }
-               drm_free(entry->buflist,
-                        entry->buf_count *
-                        sizeof(*entry->buflist), DRM_MEM_BUFS);
-
-               entry->buf_count = 0;
-       }
-}
-
-#if __OS_HAS_AGP
-/**
- * Add AGP buffers for DMA transfers.
- *
- * \param dev struct drm_device to which the buffers are to be added.
- * \param request pointer to a struct drm_buf_desc describing the request.
- * \return zero on success or a negative number on failure.
- *
- * After some sanity checks creates a drm_buf structure for each buffer and
- * reallocates the buffer list of the same size order to accommodate the new
- * buffers.
- */
-int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_entry *entry;
-       struct drm_agp_mem *agp_entry;
-       struct drm_buf *buf;
-       unsigned long offset;
-       unsigned long agp_offset;
-       int count;
-       int order;
-       int size;
-       int alignment;
-       int page_order;
-       int total;
-       int byte_count;
-       int i, valid;
-       struct drm_buf **temp_buflist;
-
-       if (!dma)
-               return -EINVAL;
-
-       count = request->count;
-       order = drm_order(request->size);
-       size = 1 << order;
-
-       alignment = (request->flags & _DRM_PAGE_ALIGN)
-           ? PAGE_ALIGN(size) : size;
-       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
-       total = PAGE_SIZE << page_order;
-
-       byte_count = 0;
-       agp_offset = dev->agp->base + request->agp_start;
-
-       DRM_DEBUG("count:      %d\n", count);
-       DRM_DEBUG("order:      %d\n", order);
-       DRM_DEBUG("size:       %d\n", size);
-       DRM_DEBUG("agp_offset: %lx\n", agp_offset);
-       DRM_DEBUG("alignment:  %d\n", alignment);
-       DRM_DEBUG("page_order: %d\n", page_order);
-       DRM_DEBUG("total:      %d\n", total);
-
-       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-               return -EINVAL;
-       if (dev->queue_count)
-               return -EBUSY;  /* Not while in use */
-
-       /* Make sure buffers are located in AGP memory that we own */
-       valid = 0;
-       list_for_each_entry(agp_entry, &dev->agp->memory, head) {
-               if ((agp_offset >= agp_entry->bound) &&
-                   (agp_offset + total * count <= agp_entry->bound + agp_entry->pages * PAGE_SIZE)) {
-                       valid = 1;
-                       break;
-               }
-       }
-       if (!list_empty(&dev->agp->memory) && !valid) {
-               DRM_DEBUG("zone invalid\n");
-               return -EINVAL;
-       }
-       spin_lock(&dev->count_lock);
-       if (dev->buf_use) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       atomic_inc(&dev->buf_alloc);
-       spin_unlock(&dev->count_lock);
-
-       mutex_lock(&dev->struct_mutex);
-       entry = &dma->bufs[order];
-       if (entry->buf_count) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM; /* May only call once for each order */
-       }
-
-       if (count < 0 || count > 4096) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -EINVAL;
-       }
-
-       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
-                                  DRM_MEM_BUFS);
-       if (!entry->buflist) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
-
-       entry->buf_size = size;
-       entry->page_order = page_order;
-
-       offset = 0;
-
-       while (entry->buf_count < count) {
-               buf = &entry->buflist[entry->buf_count];
-               buf->idx = dma->buf_count + entry->buf_count;
-               buf->total = alignment;
-               buf->order = order;
-               buf->used = 0;
-
-               buf->offset = (dma->byte_count + offset);
-               buf->bus_address = agp_offset + offset;
-               buf->address = (void *)(agp_offset + offset);
-               buf->next = NULL;
-               buf->waiting = 0;
-               buf->pending = 0;
-               init_waitqueue_head(&buf->dma_wait);
-               buf->file_priv = NULL;
-
-               buf->dev_priv_size = dev->driver->dev_priv_size;
-               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
-               if (!buf->dev_private) {
-                       /* Set count correctly so we free the proper amount. */
-                       entry->buf_count = count;
-                       drm_cleanup_buf_error(dev, entry);
-                       mutex_unlock(&dev->struct_mutex);
-                       atomic_dec(&dev->buf_alloc);
-                       return -ENOMEM;
-               }
-               memset(buf->dev_private, 0, buf->dev_priv_size);
-
-               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
-
-               offset += alignment;
-               entry->buf_count++;
-               byte_count += PAGE_SIZE << page_order;
-       }
-
-       DRM_DEBUG("byte_count: %d\n", byte_count);
-
-       temp_buflist = drm_realloc(dma->buflist,
-                                  dma->buf_count * sizeof(*dma->buflist),
-                                  (dma->buf_count + entry->buf_count)
-                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
-       if (!temp_buflist) {
-               /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev, entry);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       dma->buflist = temp_buflist;
-
-       for (i = 0; i < entry->buf_count; i++) {
-               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
-       }
-
-       dma->buf_count += entry->buf_count;
-       dma->seg_count += entry->seg_count;
-       dma->page_count += byte_count >> PAGE_SHIFT;
-       dma->byte_count += byte_count;
-
-       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
-       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
-
-       mutex_unlock(&dev->struct_mutex);
-
-       request->count = entry->buf_count;
-       request->size = size;
-
-       dma->flags = _DRM_DMA_USE_AGP;
-
-       atomic_dec(&dev->buf_alloc);
-       return 0;
-}
-EXPORT_SYMBOL(drm_addbufs_agp);
-#endif                         /* __OS_HAS_AGP */
-
-int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int count;
-       int order;
-       int size;
-       int total;
-       int page_order;
-       struct drm_buf_entry *entry;
-       drm_dma_handle_t *dmah;
-       struct drm_buf *buf;
-       int alignment;
-       unsigned long offset;
-       int i;
-       int byte_count;
-       int page_count;
-       unsigned long *temp_pagelist;
-       struct drm_buf **temp_buflist;
-
-       if (!drm_core_check_feature(dev, DRIVER_PCI_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       if (!capable(CAP_SYS_ADMIN))
-               return -EPERM;
-
-       count = request->count;
-       order = drm_order(request->size);
-       size = 1 << order;
-
-       DRM_DEBUG("count=%d, size=%d (%d), order=%d, queue_count=%d\n",
-                 request->count, request->size, size, order, dev->queue_count);
-
-       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-               return -EINVAL;
-       if (dev->queue_count)
-               return -EBUSY;  /* Not while in use */
-
-       alignment = (request->flags & _DRM_PAGE_ALIGN)
-           ? PAGE_ALIGN(size) : size;
-       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
-       total = PAGE_SIZE << page_order;
-
-       spin_lock(&dev->count_lock);
-       if (dev->buf_use) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       atomic_inc(&dev->buf_alloc);
-       spin_unlock(&dev->count_lock);
-
-       mutex_lock(&dev->struct_mutex);
-       entry = &dma->bufs[order];
-       if (entry->buf_count) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM; /* May only call once for each order */
-       }
-
-       if (count < 0 || count > 4096) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -EINVAL;
-       }
-
-       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
-                                  DRM_MEM_BUFS);
-       if (!entry->buflist) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
-
-       entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
-                                  DRM_MEM_SEGS);
-       if (!entry->seglist) {
-               drm_free(entry->buflist,
-                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memset(entry->seglist, 0, count * sizeof(*entry->seglist));
-
-       /* Keep the original pagelist until we know all the allocations
-        * have succeeded
-        */
-       temp_pagelist = drm_alloc((dma->page_count + (count << page_order))
-                                 * sizeof(*dma->pagelist), DRM_MEM_PAGES);
-       if (!temp_pagelist) {
-               drm_free(entry->buflist,
-                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
-               drm_free(entry->seglist,
-                        count * sizeof(*entry->seglist), DRM_MEM_SEGS);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memcpy(temp_pagelist,
-              dma->pagelist, dma->page_count * sizeof(*dma->pagelist));
-       DRM_DEBUG("pagelist: %d entries\n",
-                 dma->page_count + (count << page_order));
-
-       entry->buf_size = size;
-       entry->page_order = page_order;
-       byte_count = 0;
-       page_count = 0;
-
-       while (entry->buf_count < count) {
-
-               dmah = drm_pci_alloc(dev, PAGE_SIZE << page_order, 0x1000, 0xfffffffful);
-
-               if (!dmah) {
-                       /* Set count correctly so we free the proper amount. */
-                       entry->buf_count = count;
-                       entry->seg_count = count;
-                       drm_cleanup_buf_error(dev, entry);
-                       drm_free(temp_pagelist,
-                                (dma->page_count + (count << page_order))
-                                * sizeof(*dma->pagelist), DRM_MEM_PAGES);
-                       mutex_unlock(&dev->struct_mutex);
-                       atomic_dec(&dev->buf_alloc);
-                       return -ENOMEM;
-               }
-               entry->seglist[entry->seg_count++] = dmah;
-               for (i = 0; i < (1 << page_order); i++) {
-                       DRM_DEBUG("page %d @ 0x%08lx\n",
-                                 dma->page_count + page_count,
-                                 (unsigned long)dmah->vaddr + PAGE_SIZE * i);
-                       temp_pagelist[dma->page_count + page_count++]
-                               = (unsigned long)dmah->vaddr + PAGE_SIZE * i;
-               }
-               for (offset = 0;
-                    offset + size <= total && entry->buf_count < count;
-                    offset += alignment, ++entry->buf_count) {
-                       buf = &entry->buflist[entry->buf_count];
-                       buf->idx = dma->buf_count + entry->buf_count;
-                       buf->total = alignment;
-                       buf->order = order;
-                       buf->used = 0;
-                       buf->offset = (dma->byte_count + byte_count + offset);
-                       buf->address = (void *)(dmah->vaddr + offset);
-                       buf->bus_address = dmah->busaddr + offset;
-                       buf->next = NULL;
-                       buf->waiting = 0;
-                       buf->pending = 0;
-                       init_waitqueue_head(&buf->dma_wait);
-                       buf->file_priv = NULL;
-
-                       buf->dev_priv_size = dev->driver->dev_priv_size;
-                       buf->dev_private = drm_alloc(buf->dev_priv_size,
-                                                    DRM_MEM_BUFS);
-                       if (!buf->dev_private) {
-                               /* Set count correctly so we free the proper amount. */
-                               entry->buf_count = count;
-                               entry->seg_count = count;
-                               drm_cleanup_buf_error(dev, entry);
-                               drm_free(temp_pagelist,
-                                        (dma->page_count +
-                                         (count << page_order))
-                                        * sizeof(*dma->pagelist),
-                                        DRM_MEM_PAGES);
-                               mutex_unlock(&dev->struct_mutex);
-                               atomic_dec(&dev->buf_alloc);
-                               return -ENOMEM;
-                       }
-                       memset(buf->dev_private, 0, buf->dev_priv_size);
-
-                       DRM_DEBUG("buffer %d @ %p\n",
-                                 entry->buf_count, buf->address);
-               }
-               byte_count += PAGE_SIZE << page_order;
-       }
-
-       temp_buflist = drm_realloc(dma->buflist,
-                                  dma->buf_count * sizeof(*dma->buflist),
-                                  (dma->buf_count + entry->buf_count)
-                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
-       if (!temp_buflist) {
-               /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev, entry);
-               drm_free(temp_pagelist,
-                        (dma->page_count + (count << page_order))
-                        * sizeof(*dma->pagelist), DRM_MEM_PAGES);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       dma->buflist = temp_buflist;
-
-       for (i = 0; i < entry->buf_count; i++) {
-               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
-       }
-
-       /* No allocations failed, so now we can replace the orginal pagelist
-        * with the new one.
-        */
-       if (dma->page_count) {
-               drm_free(dma->pagelist,
-                        dma->page_count * sizeof(*dma->pagelist),
-                        DRM_MEM_PAGES);
-       }
-       dma->pagelist = temp_pagelist;
-
-       dma->buf_count += entry->buf_count;
-       dma->seg_count += entry->seg_count;
-       dma->page_count += entry->seg_count << page_order;
-       dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
-
-       mutex_unlock(&dev->struct_mutex);
-
-       request->count = entry->buf_count;
-       request->size = size;
-
-       if (request->flags & _DRM_PCI_BUFFER_RO)
-               dma->flags = _DRM_DMA_USE_PCI_RO;
-
-       atomic_dec(&dev->buf_alloc);
-       return 0;
-
-}
-EXPORT_SYMBOL(drm_addbufs_pci);
-
-static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_entry *entry;
-       struct drm_buf *buf;
-       unsigned long offset;
-       unsigned long agp_offset;
-       int count;
-       int order;
-       int size;
-       int alignment;
-       int page_order;
-       int total;
-       int byte_count;
-       int i;
-       struct drm_buf **temp_buflist;
-
-       if (!drm_core_check_feature(dev, DRIVER_SG))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       if (!capable(CAP_SYS_ADMIN))
-               return -EPERM;
-
-       count = request->count;
-       order = drm_order(request->size);
-       size = 1 << order;
-
-       alignment = (request->flags & _DRM_PAGE_ALIGN)
-           ? PAGE_ALIGN(size) : size;
-       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
-       total = PAGE_SIZE << page_order;
-
-       byte_count = 0;
-       agp_offset = request->agp_start;
-
-       DRM_DEBUG("count:      %d\n", count);
-       DRM_DEBUG("order:      %d\n", order);
-       DRM_DEBUG("size:       %d\n", size);
-       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
-       DRM_DEBUG("alignment:  %d\n", alignment);
-       DRM_DEBUG("page_order: %d\n", page_order);
-       DRM_DEBUG("total:      %d\n", total);
-
-       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-               return -EINVAL;
-       if (dev->queue_count)
-               return -EBUSY;  /* Not while in use */
-
-       spin_lock(&dev->count_lock);
-       if (dev->buf_use) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       atomic_inc(&dev->buf_alloc);
-       spin_unlock(&dev->count_lock);
-
-       mutex_lock(&dev->struct_mutex);
-       entry = &dma->bufs[order];
-       if (entry->buf_count) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM; /* May only call once for each order */
-       }
-
-       if (count < 0 || count > 4096) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -EINVAL;
-       }
-
-       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
-                                  DRM_MEM_BUFS);
-       if (!entry->buflist) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
-
-       entry->buf_size = size;
-       entry->page_order = page_order;
-
-       offset = 0;
-
-       while (entry->buf_count < count) {
-               buf = &entry->buflist[entry->buf_count];
-               buf->idx = dma->buf_count + entry->buf_count;
-               buf->total = alignment;
-               buf->order = order;
-               buf->used = 0;
-
-               buf->offset = (dma->byte_count + offset);
-               buf->bus_address = agp_offset + offset;
-               buf->address = (void *)(agp_offset + offset
-                                       + (unsigned long)dev->sg->virtual);
-               buf->next = NULL;
-               buf->waiting = 0;
-               buf->pending = 0;
-               init_waitqueue_head(&buf->dma_wait);
-               buf->file_priv = NULL;
-
-               buf->dev_priv_size = dev->driver->dev_priv_size;
-               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
-               if (!buf->dev_private) {
-                       /* Set count correctly so we free the proper amount. */
-                       entry->buf_count = count;
-                       drm_cleanup_buf_error(dev, entry);
-                       mutex_unlock(&dev->struct_mutex);
-                       atomic_dec(&dev->buf_alloc);
-                       return -ENOMEM;
-               }
-
-               memset(buf->dev_private, 0, buf->dev_priv_size);
-
-               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
-
-               offset += alignment;
-               entry->buf_count++;
-               byte_count += PAGE_SIZE << page_order;
-       }
-
-       DRM_DEBUG("byte_count: %d\n", byte_count);
-
-       temp_buflist = drm_realloc(dma->buflist,
-                                  dma->buf_count * sizeof(*dma->buflist),
-                                  (dma->buf_count + entry->buf_count)
-                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
-       if (!temp_buflist) {
-               /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev, entry);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       dma->buflist = temp_buflist;
-
-       for (i = 0; i < entry->buf_count; i++) {
-               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
-       }
-
-       dma->buf_count += entry->buf_count;
-       dma->seg_count += entry->seg_count;
-       dma->page_count += byte_count >> PAGE_SHIFT;
-       dma->byte_count += byte_count;
-
-       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
-       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
-
-       mutex_unlock(&dev->struct_mutex);
-
-       request->count = entry->buf_count;
-       request->size = size;
-
-       dma->flags = _DRM_DMA_USE_SG;
-
-       atomic_dec(&dev->buf_alloc);
-       return 0;
-}
-
-static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_entry *entry;
-       struct drm_buf *buf;
-       unsigned long offset;
-       unsigned long agp_offset;
-       int count;
-       int order;
-       int size;
-       int alignment;
-       int page_order;
-       int total;
-       int byte_count;
-       int i;
-       struct drm_buf **temp_buflist;
-
-       if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       if (!capable(CAP_SYS_ADMIN))
-               return -EPERM;
-
-       count = request->count;
-       order = drm_order(request->size);
-       size = 1 << order;
-
-       alignment = (request->flags & _DRM_PAGE_ALIGN)
-           ? PAGE_ALIGN(size) : size;
-       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
-       total = PAGE_SIZE << page_order;
-
-       byte_count = 0;
-       agp_offset = request->agp_start;
-
-       DRM_DEBUG("count:      %d\n", count);
-       DRM_DEBUG("order:      %d\n", order);
-       DRM_DEBUG("size:       %d\n", size);
-       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
-       DRM_DEBUG("alignment:  %d\n", alignment);
-       DRM_DEBUG("page_order: %d\n", page_order);
-       DRM_DEBUG("total:      %d\n", total);
-
-       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-               return -EINVAL;
-       if (dev->queue_count)
-               return -EBUSY;  /* Not while in use */
-
-       spin_lock(&dev->count_lock);
-       if (dev->buf_use) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       atomic_inc(&dev->buf_alloc);
-       spin_unlock(&dev->count_lock);
-
-       mutex_lock(&dev->struct_mutex);
-       entry = &dma->bufs[order];
-       if (entry->buf_count) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM; /* May only call once for each order */
-       }
-
-       if (count < 0 || count > 4096) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -EINVAL;
-       }
-
-       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
-                                  DRM_MEM_BUFS);
-       if (!entry->buflist) {
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
-
-       entry->buf_size = size;
-       entry->page_order = page_order;
-
-       offset = 0;
-
-       while (entry->buf_count < count) {
-               buf = &entry->buflist[entry->buf_count];
-               buf->idx = dma->buf_count + entry->buf_count;
-               buf->total = alignment;
-               buf->order = order;
-               buf->used = 0;
-
-               buf->offset = (dma->byte_count + offset);
-               buf->bus_address = agp_offset + offset;
-               buf->address = (void *)(agp_offset + offset);
-               buf->next = NULL;
-               buf->waiting = 0;
-               buf->pending = 0;
-               init_waitqueue_head(&buf->dma_wait);
-               buf->file_priv = NULL;
-
-               buf->dev_priv_size = dev->driver->dev_priv_size;
-               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
-               if (!buf->dev_private) {
-                       /* Set count correctly so we free the proper amount. */
-                       entry->buf_count = count;
-                       drm_cleanup_buf_error(dev, entry);
-                       mutex_unlock(&dev->struct_mutex);
-                       atomic_dec(&dev->buf_alloc);
-                       return -ENOMEM;
-               }
-               memset(buf->dev_private, 0, buf->dev_priv_size);
-
-               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
-
-               offset += alignment;
-               entry->buf_count++;
-               byte_count += PAGE_SIZE << page_order;
-       }
-
-       DRM_DEBUG("byte_count: %d\n", byte_count);
-
-       temp_buflist = drm_realloc(dma->buflist,
-                                  dma->buf_count * sizeof(*dma->buflist),
-                                  (dma->buf_count + entry->buf_count)
-                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
-       if (!temp_buflist) {
-               /* Free the entry because it isn't valid */
-               drm_cleanup_buf_error(dev, entry);
-               mutex_unlock(&dev->struct_mutex);
-               atomic_dec(&dev->buf_alloc);
-               return -ENOMEM;
-       }
-       dma->buflist = temp_buflist;
-
-       for (i = 0; i < entry->buf_count; i++) {
-               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
-       }
-
-       dma->buf_count += entry->buf_count;
-       dma->seg_count += entry->seg_count;
-       dma->page_count += byte_count >> PAGE_SHIFT;
-       dma->byte_count += byte_count;
-
-       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
-       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
-
-       mutex_unlock(&dev->struct_mutex);
-
-       request->count = entry->buf_count;
-       request->size = size;
-
-       dma->flags = _DRM_DMA_USE_FB;
-
-       atomic_dec(&dev->buf_alloc);
-       return 0;
-}
-
-
-/**
- * Add buffers for DMA transfers (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a struct drm_buf_desc request.
- * \return zero on success or a negative number on failure.
- *
- * According with the memory type specified in drm_buf_desc::flags and the
- * build options, it dispatches the call either to addbufs_agp(),
- * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
- * PCI memory respectively.
- */
-int drm_addbufs(struct drm_device *dev, void *data,
-               struct drm_file *file_priv)
-{
-       struct drm_buf_desc *request = data;
-       int ret;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               return -EINVAL;
-
-#if __OS_HAS_AGP
-       if (request->flags & _DRM_AGP_BUFFER)
-               ret = drm_addbufs_agp(dev, request);
-       else
-#endif
-       if (request->flags & _DRM_SG_BUFFER)
-               ret = drm_addbufs_sg(dev, request);
-       else if (request->flags & _DRM_FB_BUFFER)
-               ret = drm_addbufs_fb(dev, request);
-       else
-               ret = drm_addbufs_pci(dev, request);
-
-       return ret;
-}
-
-/**
- * Get information about the buffer mappings.
- *
- * This was originally mean for debugging purposes, or by a sophisticated
- * client library to determine how best to use the available buffers (e.g.,
- * large buffers can be used for image transfer).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_buf_info structure.
- * \return zero on success or a negative number on failure.
- *
- * Increments drm_device::buf_use while holding the drm_device::count_lock
- * lock, preventing of allocating more buffers after this call. Information
- * about each requested buffer is then copied into user space.
- */
-int drm_infobufs(struct drm_device *dev, void *data,
-                struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_info *request = data;
-       int i;
-       int count;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       spin_lock(&dev->count_lock);
-       if (atomic_read(&dev->buf_alloc)) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       ++dev->buf_use;         /* Can't allocate more after this call */
-       spin_unlock(&dev->count_lock);
-
-       for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
-               if (dma->bufs[i].buf_count)
-                       ++count;
-       }
-
-       DRM_DEBUG("count = %d\n", count);
-
-       if (request->count >= count) {
-               for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
-                       if (dma->bufs[i].buf_count) {
-                               struct drm_buf_desc __user *to =
-                                   &request->list[count];
-                               struct drm_buf_entry *from = &dma->bufs[i];
-                               struct drm_freelist *list = &dma->bufs[i].freelist;
-                               if (copy_to_user(&to->count,
-                                                &from->buf_count,
-                                                sizeof(from->buf_count)) ||
-                                   copy_to_user(&to->size,
-                                                &from->buf_size,
-                                                sizeof(from->buf_size)) ||
-                                   copy_to_user(&to->low_mark,
-                                                &list->low_mark,
-                                                sizeof(list->low_mark)) ||
-                                   copy_to_user(&to->high_mark,
-                                                &list->high_mark,
-                                                sizeof(list->high_mark)))
-                                       return -EFAULT;
-
-                               DRM_DEBUG("%d %d %d %d %d\n",
-                                         i,
-                                         dma->bufs[i].buf_count,
-                                         dma->bufs[i].buf_size,
-                                         dma->bufs[i].freelist.low_mark,
-                                         dma->bufs[i].freelist.high_mark);
-                               ++count;
-                       }
-               }
-       }
-       request->count = count;
-
-       return 0;
-}
-
-/**
- * Specifies a low and high water mark for buffer allocation
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg a pointer to a drm_buf_desc structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies that the size order is bounded between the admissible orders and
- * updates the respective drm_device_dma::bufs entry low and high water mark.
- *
- * \note This ioctl is deprecated and mostly never used.
- */
-int drm_markbufs(struct drm_device *dev, void *data,
-                struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_desc *request = data;
-       int order;
-       struct drm_buf_entry *entry;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       DRM_DEBUG("%d, %d, %d\n",
-                 request->size, request->low_mark, request->high_mark);
-       order = drm_order(request->size);
-       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
-               return -EINVAL;
-       entry = &dma->bufs[order];
-
-       if (request->low_mark < 0 || request->low_mark > entry->buf_count)
-               return -EINVAL;
-       if (request->high_mark < 0 || request->high_mark > entry->buf_count)
-               return -EINVAL;
-
-       entry->freelist.low_mark = request->low_mark;
-       entry->freelist.high_mark = request->high_mark;
-
-       return 0;
-}
-
-/**
- * Unreserve the buffers in list, previously reserved using drmDMA.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_buf_free structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls free_buffer() for each used buffer.
- * This function is primarily used for debugging.
- */
-int drm_freebufs(struct drm_device *dev, void *data,
-                struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf_free *request = data;
-       int i;
-       int idx;
-       struct drm_buf *buf;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       DRM_DEBUG("%d\n", request->count);
-       for (i = 0; i < request->count; i++) {
-               if (copy_from_user(&idx, &request->list[i], sizeof(idx)))
-                       return -EFAULT;
-               if (idx < 0 || idx >= dma->buf_count) {
-                       DRM_ERROR("Index %d (of %d max)\n",
-                                 idx, dma->buf_count - 1);
-                       return -EINVAL;
-               }
-               buf = dma->buflist[idx];
-               if (buf->file_priv != file_priv) {
-                       DRM_ERROR("Process %d freeing buffer not owned\n",
-                                 task_pid_nr(current));
-                       return -EINVAL;
-               }
-               drm_free_buffer(dev, buf);
-       }
-
-       return 0;
-}
-
-/**
- * Maps all of the DMA buffers into client-virtual space (ioctl).
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg pointer to a drm_buf_map structure.
- * \return zero on success or a negative number on failure.
- *
- * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information
- * about each buffer into user space. For PCI buffers, it calls do_mmap() with
- * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
- * drm_mmap_dma().
- */
-int drm_mapbufs(struct drm_device *dev, void *data,
-               struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int retcode = 0;
-       const int zero = 0;
-       unsigned long virtual;
-       unsigned long address;
-       struct drm_buf_map *request = data;
-       int i;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               return -EINVAL;
-
-       if (!dma)
-               return -EINVAL;
-
-       spin_lock(&dev->count_lock);
-       if (atomic_read(&dev->buf_alloc)) {
-               spin_unlock(&dev->count_lock);
-               return -EBUSY;
-       }
-       dev->buf_use++;         /* Can't allocate more after this call */
-       spin_unlock(&dev->count_lock);
-
-       if (request->count >= dma->buf_count) {
-               if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
-                   || (drm_core_check_feature(dev, DRIVER_SG)
-                       && (dma->flags & _DRM_DMA_USE_SG))
-                   || (drm_core_check_feature(dev, DRIVER_FB_DMA)
-                       && (dma->flags & _DRM_DMA_USE_FB))) {
-                       struct drm_map *map = dev->agp_buffer_map;
-                       unsigned long token = dev->agp_buffer_token;
-
-                       if (!map) {
-                               retcode = -EINVAL;
-                               goto done;
-                       }
-                       down_write(&current->mm->mmap_sem);
-                       virtual = do_mmap(file_priv->filp, 0, map->size,
-                                         PROT_READ | PROT_WRITE,
-                                         MAP_SHARED,
-                                         token);
-                       up_write(&current->mm->mmap_sem);
-               } else {
-                       down_write(&current->mm->mmap_sem);
-                       virtual = do_mmap(file_priv->filp, 0, dma->byte_count,
-                                         PROT_READ | PROT_WRITE,
-                                         MAP_SHARED, 0);
-                       up_write(&current->mm->mmap_sem);
-               }
-               if (virtual > -1024UL) {
-                       /* Real error */
-                       retcode = (signed long)virtual;
-                       goto done;
-               }
-               request->virtual = (void __user *)virtual;
-
-               for (i = 0; i < dma->buf_count; i++) {
-                       if (copy_to_user(&request->list[i].idx,
-                                        &dma->buflist[i]->idx,
-                                        sizeof(request->list[0].idx))) {
-                               retcode = -EFAULT;
-                               goto done;
-                       }
-                       if (copy_to_user(&request->list[i].total,
-                                        &dma->buflist[i]->total,
-                                        sizeof(request->list[0].total))) {
-                               retcode = -EFAULT;
-                               goto done;
-                       }
-                       if (copy_to_user(&request->list[i].used,
-                                        &zero, sizeof(zero))) {
-                               retcode = -EFAULT;
-                               goto done;
-                       }
-                       address = virtual + dma->buflist[i]->offset;    /* *** */
-                       if (copy_to_user(&request->list[i].address,
-                                        &address, sizeof(address))) {
-                               retcode = -EFAULT;
-                               goto done;
-                       }
-               }
-       }
-      done:
-       request->count = dma->buf_count;
-       DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
-
-       return retcode;
-}
-
-/**
- * Compute size order.  Returns the exponent of the smaller power of two which
- * is greater or equal to given number.
- *
- * \param size size.
- * \return order.
- *
- * \todo Can be made faster.
- */
-int drm_order(unsigned long size)
-{
-       int order;
-       unsigned long tmp;
-
-       for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ;
-
-       if (size & (size - 1))
-               ++order;
-
-       return order;
-}
-EXPORT_SYMBOL(drm_order);
diff --git a/drivers/char/drm/drm_context.c b/drivers/char/drm/drm_context.c
deleted file mode 100644 (file)
index d505f69..0000000
+++ /dev/null
@@ -1,471 +0,0 @@
-/**
- * \file drm_context.c
- * IOCTLs for generic contexts
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
- *
- * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * ChangeLog:
- *  2001-11-16 Torsten Duwe <duwe@caldera.de>
- *             added context constructor/destructor hooks,
- *             needed by SiS driver's memory management.
- */
-
-#include "drmP.h"
-
-/******************************************************************/
-/** \name Context bitmap support */
-/*@{*/
-
-/**
- * Free a handle from the context bitmap.
- *
- * \param dev DRM device.
- * \param ctx_handle context handle.
- *
- * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the entry
- * in drm_device::ctx_idr, while holding the drm_device::struct_mutex
- * lock.
- */
-void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
-{
-       mutex_lock(&dev->struct_mutex);
-       idr_remove(&dev->ctx_idr, ctx_handle);
-       mutex_unlock(&dev->struct_mutex);
-}
-
-/**
- * Context bitmap allocation.
- *
- * \param dev DRM device.
- * \return (non-negative) context handle on success or a negative number on failure.
- *
- * Allocate a new idr from drm_device::ctx_idr while holding the
- * drm_device::struct_mutex lock.
- */
-static int drm_ctxbitmap_next(struct drm_device * dev)
-{
-       int new_id;
-       int ret;
-
-again:
-       if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) {
-               DRM_ERROR("Out of memory expanding drawable idr\n");
-               return -ENOMEM;
-       }
-       mutex_lock(&dev->struct_mutex);
-       ret = idr_get_new_above(&dev->ctx_idr, NULL,
-                               DRM_RESERVED_CONTEXTS, &new_id);
-       if (ret == -EAGAIN) {
-               mutex_unlock(&dev->struct_mutex);
-               goto again;
-       }
-       mutex_unlock(&dev->struct_mutex);
-       return new_id;
-}
-
-/**
- * Context bitmap initialization.
- *
- * \param dev DRM device.
- *
- * Initialise the drm_device::ctx_idr
- */
-int drm_ctxbitmap_init(struct drm_device * dev)
-{
-       idr_init(&dev->ctx_idr);
-       return 0;
-}
-
-/**
- * Context bitmap cleanup.
- *
- * \param dev DRM device.
- *
- * Free all idr members using drm_ctx_sarea_free helper function
- * while holding the drm_device::struct_mutex lock.
- */
-void drm_ctxbitmap_cleanup(struct drm_device * dev)
-{
-       mutex_lock(&dev->struct_mutex);
-       idr_remove_all(&dev->ctx_idr);
-       mutex_unlock(&dev->struct_mutex);
-}
-
-/*@}*/
-
-/******************************************************************/
-/** \name Per Context SAREA Support */
-/*@{*/
-
-/**
- * Get per-context SAREA.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx_priv_map structure.
- * \return zero on success or a negative number on failure.
- *
- * Gets the map from drm_device::ctx_idr with the handle specified and
- * returns its handle.
- */
-int drm_getsareactx(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv)
-{
-       struct drm_ctx_priv_map *request = data;
-       struct drm_map *map;
-       struct drm_map_list *_entry;
-
-       mutex_lock(&dev->struct_mutex);
-
-       map = idr_find(&dev->ctx_idr, request->ctx_id);
-       if (!map) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       mutex_unlock(&dev->struct_mutex);
-
-       request->handle = NULL;
-       list_for_each_entry(_entry, &dev->maplist, head) {
-               if (_entry->map == map) {
-                       request->handle =
-                           (void *)(unsigned long)_entry->user_token;
-                       break;
-               }
-       }
-       if (request->handle == NULL)
-               return -EINVAL;
-
-       return 0;
-}
-
-/**
- * Set per-context SAREA.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx_priv_map structure.
- * \return zero on success or a negative number on failure.
- *
- * Searches the mapping specified in \p arg and update the entry in
- * drm_device::ctx_idr with it.
- */
-int drm_setsareactx(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv)
-{
-       struct drm_ctx_priv_map *request = data;
-       struct drm_map *map = NULL;
-       struct drm_map_list *r_list = NULL;
-
-       mutex_lock(&dev->struct_mutex);
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               if (r_list->map
-                   && r_list->user_token == (unsigned long) request->handle)
-                       goto found;
-       }
-      bad:
-       mutex_unlock(&dev->struct_mutex);
-       return -EINVAL;
-
-      found:
-       map = r_list->map;
-       if (!map)
-               goto bad;
-
-       if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id)))
-               goto bad;
-
-       mutex_unlock(&dev->struct_mutex);
-
-       return 0;
-}
-
-/*@}*/
-
-/******************************************************************/
-/** \name The actual DRM context handling routines */
-/*@{*/
-
-/**
- * Switch context.
- *
- * \param dev DRM device.
- * \param old old context handle.
- * \param new new context handle.
- * \return zero on success or a negative number on failure.
- *
- * Attempt to set drm_device::context_flag.
- */
-static int drm_context_switch(struct drm_device * dev, int old, int new)
-{
-       if (test_and_set_bit(0, &dev->context_flag)) {
-               DRM_ERROR("Reentering -- FIXME\n");
-               return -EBUSY;
-       }
-
-       DRM_DEBUG("Context switch from %d to %d\n", old, new);
-
-       if (new == dev->last_context) {
-               clear_bit(0, &dev->context_flag);
-               return 0;
-       }
-
-       return 0;
-}
-
-/**
- * Complete context switch.
- *
- * \param dev DRM device.
- * \param new new context handle.
- * \return zero on success or a negative number on failure.
- *
- * Updates drm_device::last_context and drm_device::last_switch. Verifies the
- * hardware lock is held, clears the drm_device::context_flag and wakes up
- * drm_device::context_wait.
- */
-static int drm_context_switch_complete(struct drm_device * dev, int new)
-{
-       dev->last_context = new;        /* PRE/POST: This is the _only_ writer. */
-       dev->last_switch = jiffies;
-
-       if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
-               DRM_ERROR("Lock isn't held after context switch\n");
-       }
-
-       /* If a context switch is ever initiated
-          when the kernel holds the lock, release
-          that lock here. */
-       clear_bit(0, &dev->context_flag);
-       wake_up(&dev->context_wait);
-
-       return 0;
-}
-
-/**
- * Reserve contexts.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx_res structure.
- * \return zero on success or a negative number on failure.
- */
-int drm_resctx(struct drm_device *dev, void *data,
-              struct drm_file *file_priv)
-{
-       struct drm_ctx_res *res = data;
-       struct drm_ctx ctx;
-       int i;
-
-       if (res->count >= DRM_RESERVED_CONTEXTS) {
-               memset(&ctx, 0, sizeof(ctx));
-               for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
-                       ctx.handle = i;
-                       if (copy_to_user(&res->contexts[i], &ctx, sizeof(ctx)))
-                               return -EFAULT;
-               }
-       }
-       res->count = DRM_RESERVED_CONTEXTS;
-
-       return 0;
-}
-
-/**
- * Add context.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx structure.
- * \return zero on success or a negative number on failure.
- *
- * Get a new handle for the context and copy to userspace.
- */
-int drm_addctx(struct drm_device *dev, void *data,
-              struct drm_file *file_priv)
-{
-       struct drm_ctx_list *ctx_entry;
-       struct drm_ctx *ctx = data;
-
-       ctx->handle = drm_ctxbitmap_next(dev);
-       if (ctx->handle == DRM_KERNEL_CONTEXT) {
-               /* Skip kernel's context and get a new one. */
-               ctx->handle = drm_ctxbitmap_next(dev);
-       }
-       DRM_DEBUG("%d\n", ctx->handle);
-       if (ctx->handle == -1) {
-               DRM_DEBUG("Not enough free contexts.\n");
-               /* Should this return -EBUSY instead? */
-               return -ENOMEM;
-       }
-
-       if (ctx->handle != DRM_KERNEL_CONTEXT) {
-               if (dev->driver->context_ctor)
-                       if (!dev->driver->context_ctor(dev, ctx->handle)) {
-                               DRM_DEBUG("Running out of ctxs or memory.\n");
-                               return -ENOMEM;
-                       }
-       }
-
-       ctx_entry = drm_alloc(sizeof(*ctx_entry), DRM_MEM_CTXLIST);
-       if (!ctx_entry) {
-               DRM_DEBUG("out of memory\n");
-               return -ENOMEM;
-       }
-
-       INIT_LIST_HEAD(&ctx_entry->head);
-       ctx_entry->handle = ctx->handle;
-       ctx_entry->tag = file_priv;
-
-       mutex_lock(&dev->ctxlist_mutex);
-       list_add(&ctx_entry->head, &dev->ctxlist);
-       ++dev->ctx_count;
-       mutex_unlock(&dev->ctxlist_mutex);
-
-       return 0;
-}
-
-int drm_modctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       /* This does nothing */
-       return 0;
-}
-
-/**
- * Get context.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx structure.
- * \return zero on success or a negative number on failure.
- */
-int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_ctx *ctx = data;
-
-       /* This is 0, because we don't handle any context flags */
-       ctx->flags = 0;
-
-       return 0;
-}
-
-/**
- * Switch context.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls context_switch().
- */
-int drm_switchctx(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       struct drm_ctx *ctx = data;
-
-       DRM_DEBUG("%d\n", ctx->handle);
-       return drm_context_switch(dev, dev->last_context, ctx->handle);
-}
-
-/**
- * New context.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls context_switch_complete().
- */
-int drm_newctx(struct drm_device *dev, void *data,
-              struct drm_file *file_priv)
-{
-       struct drm_ctx *ctx = data;
-
-       DRM_DEBUG("%d\n", ctx->handle);
-       drm_context_switch_complete(dev, ctx->handle);
-
-       return 0;
-}
-
-/**
- * Remove context.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument pointing to a drm_ctx structure.
- * \return zero on success or a negative number on failure.
- *
- * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
- */
-int drm_rmctx(struct drm_device *dev, void *data,
-             struct drm_file *file_priv)
-{
-       struct drm_ctx *ctx = data;
-
-       DRM_DEBUG("%d\n", ctx->handle);
-       if (ctx->handle == DRM_KERNEL_CONTEXT + 1) {
-               file_priv->remove_auth_on_close = 1;
-       }
-       if (ctx->handle != DRM_KERNEL_CONTEXT) {
-               if (dev->driver->context_dtor)
-                       dev->driver->context_dtor(dev, ctx->handle);
-               drm_ctxbitmap_free(dev, ctx->handle);
-       }
-
-       mutex_lock(&dev->ctxlist_mutex);
-       if (!list_empty(&dev->ctxlist)) {
-               struct drm_ctx_list *pos, *n;
-
-               list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
-                       if (pos->handle == ctx->handle) {
-                               list_del(&pos->head);
-                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
-                               --dev->ctx_count;
-                       }
-               }
-       }
-       mutex_unlock(&dev->ctxlist_mutex);
-
-       return 0;
-}
-
-/*@}*/
diff --git a/drivers/char/drm/drm_core.h b/drivers/char/drm/drm_core.h
deleted file mode 100644 (file)
index 3167390..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2004 Jon Smirl <jonsmirl@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#define CORE_AUTHOR            "Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl"
-
-#define CORE_NAME              "drm"
-#define CORE_DESC              "DRM shared core routines"
-#define CORE_DATE              "20060810"
-
-#define DRM_IF_MAJOR   1
-#define DRM_IF_MINOR   3
-
-#define CORE_MAJOR     1
-#define CORE_MINOR     1
-#define CORE_PATCHLEVEL 0
diff --git a/drivers/char/drm/drm_dma.c b/drivers/char/drm/drm_dma.c
deleted file mode 100644 (file)
index 7a8e2fb..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/**
- * \file drm_dma.c
- * DMA IOCTL and function support
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
- *
- * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-/**
- * Initialize the DMA data.
- *
- * \param dev DRM device.
- * \return zero on success or a negative value on failure.
- *
- * Allocate and initialize a drm_device_dma structure.
- */
-int drm_dma_setup(struct drm_device *dev)
-{
-       int i;
-
-       dev->dma = drm_alloc(sizeof(*dev->dma), DRM_MEM_DRIVER);
-       if (!dev->dma)
-               return -ENOMEM;
-
-       memset(dev->dma, 0, sizeof(*dev->dma));
-
-       for (i = 0; i <= DRM_MAX_ORDER; i++)
-               memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
-
-       return 0;
-}
-
-/**
- * Cleanup the DMA resources.
- *
- * \param dev DRM device.
- *
- * Free all pages associated with DMA buffers, the buffers and pages lists, and
- * finally the drm_device::dma structure itself.
- */
-void drm_dma_takedown(struct drm_device *dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i, j;
-
-       if (!dma)
-               return;
-
-       /* Clear dma buffers */
-       for (i = 0; i <= DRM_MAX_ORDER; i++) {
-               if (dma->bufs[i].seg_count) {
-                       DRM_DEBUG("order %d: buf_count = %d,"
-                                 " seg_count = %d\n",
-                                 i,
-                                 dma->bufs[i].buf_count,
-                                 dma->bufs[i].seg_count);
-                       for (j = 0; j < dma->bufs[i].seg_count; j++) {
-                               if (dma->bufs[i].seglist[j]) {
-                                       drm_pci_free(dev, dma->bufs[i].seglist[j]);
-                               }
-                       }
-                       drm_free(dma->bufs[i].seglist,
-                                dma->bufs[i].seg_count
-                                * sizeof(*dma->bufs[0].seglist), DRM_MEM_SEGS);
-               }
-               if (dma->bufs[i].buf_count) {
-                       for (j = 0; j < dma->bufs[i].buf_count; j++) {
-                               if (dma->bufs[i].buflist[j].dev_private) {
-                                       drm_free(dma->bufs[i].buflist[j].
-                                                dev_private,
-                                                dma->bufs[i].buflist[j].
-                                                dev_priv_size, DRM_MEM_BUFS);
-                               }
-                       }
-                       drm_free(dma->bufs[i].buflist,
-                                dma->bufs[i].buf_count *
-                                sizeof(*dma->bufs[0].buflist), DRM_MEM_BUFS);
-               }
-       }
-
-       if (dma->buflist) {
-               drm_free(dma->buflist,
-                        dma->buf_count * sizeof(*dma->buflist), DRM_MEM_BUFS);
-       }
-
-       if (dma->pagelist) {
-               drm_free(dma->pagelist,
-                        dma->page_count * sizeof(*dma->pagelist),
-                        DRM_MEM_PAGES);
-       }
-       drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
-       dev->dma = NULL;
-}
-
-/**
- * Free a buffer.
- *
- * \param dev DRM device.
- * \param buf buffer to free.
- *
- * Resets the fields of \p buf.
- */
-void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf)
-{
-       if (!buf)
-               return;
-
-       buf->waiting = 0;
-       buf->pending = 0;
-       buf->file_priv = NULL;
-       buf->used = 0;
-
-       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE)
-           && waitqueue_active(&buf->dma_wait)) {
-               wake_up_interruptible(&buf->dma_wait);
-       }
-}
-
-/**
- * Reclaim the buffers.
- *
- * \param file_priv DRM file private.
- *
- * Frees each buffer associated with \p file_priv not already on the hardware.
- */
-void drm_core_reclaim_buffers(struct drm_device *dev,
-                             struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-
-       if (!dma)
-               return;
-       for (i = 0; i < dma->buf_count; i++) {
-               if (dma->buflist[i]->file_priv == file_priv) {
-                       switch (dma->buflist[i]->list) {
-                       case DRM_LIST_NONE:
-                               drm_free_buffer(dev, dma->buflist[i]);
-                               break;
-                       case DRM_LIST_WAIT:
-                               dma->buflist[i]->list = DRM_LIST_RECLAIM;
-                               break;
-                       default:
-                               /* Buffer already on hardware. */
-                               break;
-                       }
-               }
-       }
-}
-
-EXPORT_SYMBOL(drm_core_reclaim_buffers);
diff --git a/drivers/char/drm/drm_drawable.c b/drivers/char/drm/drm_drawable.c
deleted file mode 100644 (file)
index 1839c57..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * \file drm_drawable.c
- * IOCTLs for drawables
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- * \author Michel Dänzer <michel@tungstengraphics.com>
- */
-
-/*
- * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-/**
- * Allocate drawable ID and memory to store information about it.
- */
-int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       unsigned long irqflags;
-       struct drm_draw *draw = data;
-       int new_id = 0;
-       int ret;
-
-again:
-       if (idr_pre_get(&dev->drw_idr, GFP_KERNEL) == 0) {
-               DRM_ERROR("Out of memory expanding drawable idr\n");
-               return -ENOMEM;
-       }
-
-       spin_lock_irqsave(&dev->drw_lock, irqflags);
-       ret = idr_get_new_above(&dev->drw_idr, NULL, 1, &new_id);
-       if (ret == -EAGAIN) {
-               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-               goto again;
-       }
-
-       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-
-       draw->handle = new_id;
-
-       DRM_DEBUG("%d\n", draw->handle);
-
-       return 0;
-}
-
-/**
- * Free drawable ID and memory to store information about it.
- */
-int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_draw *draw = data;
-       unsigned long irqflags;
-
-       spin_lock_irqsave(&dev->drw_lock, irqflags);
-
-       drm_free(drm_get_drawable_info(dev, draw->handle),
-                sizeof(struct drm_drawable_info), DRM_MEM_BUFS);
-
-       idr_remove(&dev->drw_idr, draw->handle);
-
-       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-       DRM_DEBUG("%d\n", draw->handle);
-       return 0;
-}
-
-int drm_update_drawable_info(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_update_draw *update = data;
-       unsigned long irqflags;
-       struct drm_clip_rect *rects;
-       struct drm_drawable_info *info;
-       int err;
-
-       info = idr_find(&dev->drw_idr, update->handle);
-       if (!info) {
-               info = drm_calloc(1, sizeof(*info), DRM_MEM_BUFS);
-               if (!info)
-                       return -ENOMEM;
-               if (IS_ERR(idr_replace(&dev->drw_idr, info, update->handle))) {
-                       DRM_ERROR("No such drawable %d\n", update->handle);
-                       drm_free(info, sizeof(*info), DRM_MEM_BUFS);
-                       return -EINVAL;
-               }
-       }
-
-       switch (update->type) {
-       case DRM_DRAWABLE_CLIPRECTS:
-               if (update->num != info->num_rects) {
-                       rects = drm_alloc(update->num * sizeof(struct drm_clip_rect),
-                                        DRM_MEM_BUFS);
-               } else
-                       rects = info->rects;
-
-               if (update->num && !rects) {
-                       DRM_ERROR("Failed to allocate cliprect memory\n");
-                       err = -ENOMEM;
-                       goto error;
-               }
-
-               if (update->num && DRM_COPY_FROM_USER(rects,
-                                                    (struct drm_clip_rect __user *)
-                                                    (unsigned long)update->data,
-                                                    update->num *
-                                                    sizeof(*rects))) {
-                       DRM_ERROR("Failed to copy cliprects from userspace\n");
-                       err = -EFAULT;
-                       goto error;
-               }
-
-               spin_lock_irqsave(&dev->drw_lock, irqflags);
-
-               if (rects != info->rects) {
-                       drm_free(info->rects, info->num_rects *
-                                sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
-               }
-
-               info->rects = rects;
-               info->num_rects = update->num;
-
-               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-
-               DRM_DEBUG("Updated %d cliprects for drawable %d\n",
-                         info->num_rects, update->handle);
-               break;
-       default:
-               DRM_ERROR("Invalid update type %d\n", update->type);
-               return -EINVAL;
-       }
-
-       return 0;
-
-error:
-       if (rects != info->rects)
-               drm_free(rects, update->num * sizeof(struct drm_clip_rect),
-                        DRM_MEM_BUFS);
-
-       return err;
-}
-
-/**
- * Caller must hold the drawable spinlock!
- */
-struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id)
-{
-       return idr_find(&dev->drw_idr, id);
-}
-EXPORT_SYMBOL(drm_get_drawable_info);
-
-static int drm_drawable_free(int idr, void *p, void *data)
-{
-       struct drm_drawable_info *info = p;
-
-       if (info) {
-               drm_free(info->rects, info->num_rects *
-                        sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
-               drm_free(info, sizeof(*info), DRM_MEM_BUFS);
-       }
-
-       return 0;
-}
-
-void drm_drawable_free_all(struct drm_device *dev)
-{
-       idr_for_each(&dev->drw_idr, drm_drawable_free, NULL);
-       idr_remove_all(&dev->drw_idr);
-}
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
deleted file mode 100644 (file)
index 5641387..0000000
+++ /dev/null
@@ -1,540 +0,0 @@
-/**
- * \file drm_drv.c
- * Generic driver template
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- *
- * To use this template, you must at least define the following (samples
- * given for the MGA driver):
- *
- * \code
- * #define DRIVER_AUTHOR       "VA Linux Systems, Inc."
- *
- * #define DRIVER_NAME         "mga"
- * #define DRIVER_DESC         "Matrox G200/G400"
- * #define DRIVER_DATE         "20001127"
- *
- * #define drm_x               mga_##x
- * \endcode
- */
-
-/*
- * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
- *
- * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "drm_core.h"
-
-static int drm_version(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv);
-
-/** Ioctl table */
-static struct drm_ioctl_desc drm_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_getmap, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, 0),
-       DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER|DRM_ROOT_ONLY),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_rmmap_ioctl, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_getctx, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_resctx, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_adddraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_rmdraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_LOCK, drm_lock, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_unlock, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
-       DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
-#if __OS_HAS_AGP
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-#endif
-
-       DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0),
-
-       DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-};
-
-#define DRM_CORE_IOCTL_COUNT   ARRAY_SIZE( drm_ioctls )
-
-/**
- * Take down the DRM device.
- *
- * \param dev DRM device structure.
- *
- * Frees every resource in \p dev.
- *
- * \sa drm_device
- */
-int drm_lastclose(struct drm_device * dev)
-{
-       struct drm_magic_entry *pt, *next;
-       struct drm_map_list *r_list, *list_t;
-       struct drm_vma_entry *vma, *vma_temp;
-       int i;
-
-       DRM_DEBUG("\n");
-
-       if (dev->driver->lastclose)
-               dev->driver->lastclose(dev);
-       DRM_DEBUG("driver lastclose completed\n");
-
-       if (dev->unique) {
-               drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
-               dev->unique = NULL;
-               dev->unique_len = 0;
-       }
-
-       if (dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-       mutex_lock(&dev->struct_mutex);
-
-       /* Free drawable information memory */
-       drm_drawable_free_all(dev);
-       del_timer(&dev->timer);
-
-       /* Clear pid list */
-       if (dev->magicfree.next) {
-               list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
-                       list_del(&pt->head);
-                       drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
-                       drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
-               }
-               drm_ht_remove(&dev->magiclist);
-       }
-
-       /* Clear AGP information */
-       if (drm_core_has_AGP(dev) && dev->agp) {
-               struct drm_agp_mem *entry, *tempe;
-
-               /* Remove AGP resources, but leave dev->agp
-                  intact until drv_cleanup is called. */
-               list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
-                       if (entry->bound)
-                               drm_unbind_agp(entry->memory);
-                       drm_free_agp(entry->memory, entry->pages);
-                       drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
-               }
-               INIT_LIST_HEAD(&dev->agp->memory);
-
-               if (dev->agp->acquired)
-                       drm_agp_release(dev);
-
-               dev->agp->acquired = 0;
-               dev->agp->enabled = 0;
-       }
-       if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
-               drm_sg_cleanup(dev->sg);
-               dev->sg = NULL;
-       }
-
-       /* Clear vma list (only built for debugging) */
-       list_for_each_entry_safe(vma, vma_temp, &dev->vmalist, head) {
-               list_del(&vma->head);
-               drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
-       }
-
-       list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) {
-               if (!(r_list->map->flags & _DRM_DRIVER)) {
-                       drm_rmmap_locked(dev, r_list->map);
-                       r_list = NULL;
-               }
-       }
-
-       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
-               for (i = 0; i < dev->queue_count; i++) {
-                       if (dev->queuelist[i]) {
-                               drm_free(dev->queuelist[i],
-                                        sizeof(*dev->queuelist[0]),
-                                        DRM_MEM_QUEUES);
-                               dev->queuelist[i] = NULL;
-                       }
-               }
-               drm_free(dev->queuelist,
-                        dev->queue_slots * sizeof(*dev->queuelist),
-                        DRM_MEM_QUEUES);
-               dev->queuelist = NULL;
-       }
-       dev->queue_count = 0;
-
-       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
-               drm_dma_takedown(dev);
-
-       if (dev->lock.hw_lock) {
-               dev->sigdata.lock = dev->lock.hw_lock = NULL;   /* SHM removed */
-               dev->lock.file_priv = NULL;
-               wake_up_interruptible(&dev->lock.lock_queue);
-       }
-       mutex_unlock(&dev->struct_mutex);
-
-       DRM_DEBUG("lastclose completed\n");
-       return 0;
-}
-
-/**
- * Module initialization. Called via init_module at module load time, or via
- * linux/init/main.c (this is not currently supported).
- *
- * \return zero on success or a negative number on failure.
- *
- * Initializes an array of drm_device structures, and attempts to
- * initialize all available devices, using consecutive minors, registering the
- * stubs and initializing the AGP device.
- *
- * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
- * after the initialization for driver customization.
- */
-int drm_init(struct drm_driver *driver)
-{
-       struct pci_dev *pdev = NULL;
-       struct pci_device_id *pid;
-       int i;
-
-       DRM_DEBUG("\n");
-
-       for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
-               pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
-
-               pdev = NULL;
-               /* pass back in pdev to account for multiple identical cards */
-               while ((pdev =
-                       pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
-                                      pid->subdevice, pdev)) != NULL) {
-                       /* stealth mode requires a manual probe */
-                       pci_dev_get(pdev);
-                       drm_get_dev(pdev, pid, driver);
-               }
-       }
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_init);
-
-/**
- * Called via cleanup_module() at module unload time.
- *
- * Cleans up all DRM device, calling drm_lastclose().
- *
- * \sa drm_init
- */
-static void drm_cleanup(struct drm_device * dev)
-{
-       DRM_DEBUG("\n");
-
-       if (!dev) {
-               DRM_ERROR("cleanup called no dev\n");
-               return;
-       }
-
-       drm_lastclose(dev);
-
-       if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
-           dev->agp && dev->agp->agp_mtrr >= 0) {
-               int retval;
-               retval = mtrr_del(dev->agp->agp_mtrr,
-                                 dev->agp->agp_info.aper_base,
-                                 dev->agp->agp_info.aper_size * 1024 * 1024);
-               DRM_DEBUG("mtrr_del=%d\n", retval);
-       }
-
-       if (drm_core_has_AGP(dev) && dev->agp) {
-               drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
-               dev->agp = NULL;
-       }
-
-       if (dev->driver->unload)
-               dev->driver->unload(dev);
-
-       drm_ht_remove(&dev->map_hash);
-       drm_ctxbitmap_cleanup(dev);
-
-       drm_put_minor(&dev->primary);
-       if (drm_put_dev(dev))
-               DRM_ERROR("Cannot unload module\n");
-}
-
-int drm_minors_cleanup(int id, void *ptr, void *data)
-{
-       struct drm_minor *minor = ptr;
-       struct drm_device *dev;
-       struct drm_driver *driver = data;
-
-       dev = minor->dev;
-       if (minor->dev->driver != driver)
-               return 0;
-
-       if (minor->type != DRM_MINOR_LEGACY)
-               return 0;
-
-       if (dev)
-               pci_dev_put(dev->pdev);
-       drm_cleanup(dev);
-       return 1;
-}
-
-void drm_exit(struct drm_driver *driver)
-{
-       DRM_DEBUG("\n");
-
-       idr_for_each(&drm_minors_idr, &drm_minors_cleanup, driver);
-
-       DRM_INFO("Module unloaded\n");
-}
-
-EXPORT_SYMBOL(drm_exit);
-
-/** File operations structure */
-static const struct file_operations drm_stub_fops = {
-       .owner = THIS_MODULE,
-       .open = drm_stub_open
-};
-
-static int __init drm_core_init(void)
-{
-       int ret = -ENOMEM;
-
-       idr_init(&drm_minors_idr);
-
-       if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
-               goto err_p1;
-
-       drm_class = drm_sysfs_create(THIS_MODULE, "drm");
-       if (IS_ERR(drm_class)) {
-               printk(KERN_ERR "DRM: Error creating drm class.\n");
-               ret = PTR_ERR(drm_class);
-               goto err_p2;
-       }
-
-       drm_proc_root = proc_mkdir("dri", NULL);
-       if (!drm_proc_root) {
-               DRM_ERROR("Cannot create /proc/dri\n");
-               ret = -1;
-               goto err_p3;
-       }
-
-       drm_mem_init();
-
-       DRM_INFO("Initialized %s %d.%d.%d %s\n",
-                CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
-       return 0;
-err_p3:
-       drm_sysfs_destroy();
-err_p2:
-       unregister_chrdev(DRM_MAJOR, "drm");
-
-       idr_destroy(&drm_minors_idr);
-err_p1:
-       return ret;
-}
-
-static void __exit drm_core_exit(void)
-{
-       remove_proc_entry("dri", NULL);
-       drm_sysfs_destroy();
-
-       unregister_chrdev(DRM_MAJOR, "drm");
-
-       idr_destroy(&drm_minors_idr);
-}
-
-module_init(drm_core_init);
-module_exit(drm_core_exit);
-
-/**
- * Get version information
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_version structure.
- * \return zero on success or negative number on failure.
- *
- * Fills in the version information in \p arg.
- */
-static int drm_version(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_version *version = data;
-       int len;
-
-       version->version_major = dev->driver->major;
-       version->version_minor = dev->driver->minor;
-       version->version_patchlevel = dev->driver->patchlevel;
-       DRM_COPY(version->name, dev->driver->name);
-       DRM_COPY(version->date, dev->driver->date);
-       DRM_COPY(version->desc, dev->driver->desc);
-
-       return 0;
-}
-
-/**
- * Called whenever a process performs an ioctl on /dev/drm.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- *
- * Looks up the ioctl function in the ::ioctls table, checking for root
- * previleges if so required, and dispatches to the respective function.
- */
-int drm_ioctl(struct inode *inode, struct file *filp,
-             unsigned int cmd, unsigned long arg)
-{
-       struct drm_file *file_priv = filp->private_data;
-       struct drm_device *dev = file_priv->minor->dev;
-       struct drm_ioctl_desc *ioctl;
-       drm_ioctl_t *func;
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       int retcode = -EINVAL;
-       char *kdata = NULL;
-
-       atomic_inc(&dev->ioctl_count);
-       atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
-       ++file_priv->ioctl_count;
-
-       DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
-                 task_pid_nr(current), cmd, nr,
-                 (long)old_encode_dev(file_priv->minor->device),
-                 file_priv->authenticated);
-
-       if ((nr >= DRM_CORE_IOCTL_COUNT) &&
-           ((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END)))
-               goto err_i1;
-       if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) &&
-           (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
-               ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
-       else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) {
-               ioctl = &drm_ioctls[nr];
-               cmd = ioctl->cmd;
-       } else
-               goto err_i1;
-
-       /* Do not trust userspace, use our own definition */
-       func = ioctl->func;
-       /* is there a local override? */
-       if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
-               func = dev->driver->dma_ioctl;
-
-       if (!func) {
-               DRM_DEBUG("no function\n");
-               retcode = -EINVAL;
-       } else if (((ioctl->flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
-                  ((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
-                  ((ioctl->flags & DRM_MASTER) && !file_priv->master)) {
-               retcode = -EACCES;
-       } else {
-               if (cmd & (IOC_IN | IOC_OUT)) {
-                       kdata = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
-                       if (!kdata) {
-                               retcode = -ENOMEM;
-                               goto err_i1;
-                       }
-               }
-
-               if (cmd & IOC_IN) {
-                       if (copy_from_user(kdata, (void __user *)arg,
-                                          _IOC_SIZE(cmd)) != 0) {
-                               retcode = -EFAULT;
-                               goto err_i1;
-                       }
-               }
-               retcode = func(dev, kdata, file_priv);
-
-               if ((retcode == 0) && (cmd & IOC_OUT)) {
-                       if (copy_to_user((void __user *)arg, kdata,
-                                        _IOC_SIZE(cmd)) != 0)
-                               retcode = -EFAULT;
-               }
-       }
-
-      err_i1:
-       if (kdata)
-               kfree(kdata);
-       atomic_dec(&dev->ioctl_count);
-       if (retcode)
-               DRM_DEBUG("ret = %x\n", retcode);
-       return retcode;
-}
-
-EXPORT_SYMBOL(drm_ioctl);
-
-drm_local_map_t *drm_getsarea(struct drm_device *dev)
-{
-       struct drm_map_list *entry;
-
-       list_for_each_entry(entry, &dev->maplist, head) {
-               if (entry->map && entry->map->type == _DRM_SHM &&
-                   (entry->map->flags & _DRM_CONTAINS_LOCK)) {
-                       return entry->map;
-               }
-       }
-       return NULL;
-}
-EXPORT_SYMBOL(drm_getsarea);
diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c
deleted file mode 100644 (file)
index d2e6da8..0000000
+++ /dev/null
@@ -1,466 +0,0 @@
-/**
- * \file drm_fops.c
- * File operations for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Daryll Strauss <daryll@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "drm_sarea.h"
-#include <linux/poll.h>
-
-static int drm_open_helper(struct inode *inode, struct file *filp,
-                          struct drm_device * dev);
-
-static int drm_setup(struct drm_device * dev)
-{
-       drm_local_map_t *map;
-       int i;
-       int ret;
-       u32 sareapage;
-
-       if (dev->driver->firstopen) {
-               ret = dev->driver->firstopen(dev);
-               if (ret != 0)
-                       return ret;
-       }
-
-       dev->magicfree.next = NULL;
-
-       /* prebuild the SAREA */
-       sareapage = max_t(unsigned, SAREA_MAX, PAGE_SIZE);
-       i = drm_addmap(dev, 0, sareapage, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
-       if (i != 0)
-               return i;
-
-       atomic_set(&dev->ioctl_count, 0);
-       atomic_set(&dev->vma_count, 0);
-       dev->buf_use = 0;
-       atomic_set(&dev->buf_alloc, 0);
-
-       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
-               i = drm_dma_setup(dev);
-               if (i < 0)
-                       return i;
-       }
-
-       for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
-               atomic_set(&dev->counts[i], 0);
-
-       drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
-       INIT_LIST_HEAD(&dev->magicfree);
-
-       dev->sigdata.lock = NULL;
-       init_waitqueue_head(&dev->lock.lock_queue);
-       dev->queue_count = 0;
-       dev->queue_reserved = 0;
-       dev->queue_slots = 0;
-       dev->queuelist = NULL;
-       dev->irq_enabled = 0;
-       dev->context_flag = 0;
-       dev->interrupt_flag = 0;
-       dev->dma_flag = 0;
-       dev->last_context = 0;
-       dev->last_switch = 0;
-       dev->last_checked = 0;
-       init_waitqueue_head(&dev->context_wait);
-       dev->if_version = 0;
-
-       dev->ctx_start = 0;
-       dev->lck_start = 0;
-
-       dev->buf_async = NULL;
-       init_waitqueue_head(&dev->buf_readers);
-       init_waitqueue_head(&dev->buf_writers);
-
-       DRM_DEBUG("\n");
-
-       /*
-        * The kernel's context could be created here, but is now created
-        * in drm_dma_enqueue.  This is more resource-efficient for
-        * hardware that does not do DMA, but may mean that
-        * drm_select_queue fails between the time the interrupt is
-        * initialized and the time the queues are initialized.
-        */
-
-       return 0;
-}
-
-/**
- * Open file.
- *
- * \param inode device inode
- * \param filp file pointer.
- * \return zero on success or a negative number on failure.
- *
- * Searches the DRM device with the same minor number, calls open_helper(), and
- * increments the device open count. If the open count was previous at zero,
- * i.e., it's the first that the device is open, then calls setup().
- */
-int drm_open(struct inode *inode, struct file *filp)
-{
-       struct drm_device *dev = NULL;
-       int minor_id = iminor(inode);
-       struct drm_minor *minor;
-       int retcode = 0;
-
-       minor = idr_find(&drm_minors_idr, minor_id);
-       if (!minor)
-               return -ENODEV;
-
-       if (!(dev = minor->dev))
-               return -ENODEV;
-
-       retcode = drm_open_helper(inode, filp, dev);
-       if (!retcode) {
-               atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
-               spin_lock(&dev->count_lock);
-               if (!dev->open_count++) {
-                       spin_unlock(&dev->count_lock);
-                       return drm_setup(dev);
-               }
-               spin_unlock(&dev->count_lock);
-       }
-
-       return retcode;
-}
-EXPORT_SYMBOL(drm_open);
-
-/**
- * File \c open operation.
- *
- * \param inode device inode.
- * \param filp file pointer.
- *
- * Puts the dev->fops corresponding to the device minor number into
- * \p filp, call the \c open method, and restore the file operations.
- */
-int drm_stub_open(struct inode *inode, struct file *filp)
-{
-       struct drm_device *dev = NULL;
-       struct drm_minor *minor;
-       int minor_id = iminor(inode);
-       int err = -ENODEV;
-       const struct file_operations *old_fops;
-
-       DRM_DEBUG("\n");
-
-       minor = idr_find(&drm_minors_idr, minor_id);
-       if (!minor)
-               return -ENODEV;
-
-       if (!(dev = minor->dev))
-               return -ENODEV;
-
-       old_fops = filp->f_op;
-       filp->f_op = fops_get(&dev->driver->fops);
-       if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
-               fops_put(filp->f_op);
-               filp->f_op = fops_get(old_fops);
-       }
-       fops_put(old_fops);
-
-       return err;
-}
-
-/**
- * Check whether DRI will run on this CPU.
- *
- * \return non-zero if the DRI will run on this CPU, or zero otherwise.
- */
-static int drm_cpu_valid(void)
-{
-#if defined(__i386__)
-       if (boot_cpu_data.x86 == 3)
-               return 0;       /* No cmpxchg on a 386 */
-#endif
-#if defined(__sparc__) && !defined(__sparc_v9__)
-       return 0;               /* No cmpxchg before v9 sparc. */
-#endif
-       return 1;
-}
-
-/**
- * Called whenever a process opens /dev/drm.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param dev device.
- * \return zero on success or a negative number on failure.
- *
- * Creates and initializes a drm_file structure for the file private data in \p
- * filp and add it into the double linked list in \p dev.
- */
-static int drm_open_helper(struct inode *inode, struct file *filp,
-                          struct drm_device * dev)
-{
-       int minor_id = iminor(inode);
-       struct drm_file *priv;
-       int ret;
-
-       if (filp->f_flags & O_EXCL)
-               return -EBUSY;  /* No exclusive opens */
-       if (!drm_cpu_valid())
-               return -EINVAL;
-
-       DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
-
-       priv = drm_alloc(sizeof(*priv), DRM_MEM_FILES);
-       if (!priv)
-               return -ENOMEM;
-
-       memset(priv, 0, sizeof(*priv));
-       filp->private_data = priv;
-       priv->filp = filp;
-       priv->uid = current->euid;
-       priv->pid = task_pid_nr(current);
-       priv->minor = idr_find(&drm_minors_idr, minor_id);
-       priv->ioctl_count = 0;
-       /* for compatibility root is always authenticated */
-       priv->authenticated = capable(CAP_SYS_ADMIN);
-       priv->lock_count = 0;
-
-       INIT_LIST_HEAD(&priv->lhead);
-
-       if (dev->driver->open) {
-               ret = dev->driver->open(dev, priv);
-               if (ret < 0)
-                       goto out_free;
-       }
-
-       mutex_lock(&dev->struct_mutex);
-       if (list_empty(&dev->filelist))
-               priv->master = 1;
-
-       list_add(&priv->lhead, &dev->filelist);
-       mutex_unlock(&dev->struct_mutex);
-
-#ifdef __alpha__
-       /*
-        * Default the hose
-        */
-       if (!dev->hose) {
-               struct pci_dev *pci_dev;
-               pci_dev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
-               if (pci_dev) {
-                       dev->hose = pci_dev->sysdata;
-                       pci_dev_put(pci_dev);
-               }
-               if (!dev->hose) {
-                       struct pci_bus *b = pci_bus_b(pci_root_buses.next);
-                       if (b)
-                               dev->hose = b->sysdata;
-               }
-       }
-#endif
-
-       return 0;
-      out_free:
-       drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
-       filp->private_data = NULL;
-       return ret;
-}
-
-/** No-op. */
-int drm_fasync(int fd, struct file *filp, int on)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       int retcode;
-
-       DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
-                 (long)old_encode_dev(priv->minor->device));
-       retcode = fasync_helper(fd, filp, on, &dev->buf_async);
-       if (retcode < 0)
-               return retcode;
-       return 0;
-}
-EXPORT_SYMBOL(drm_fasync);
-
-/**
- * Release file.
- *
- * \param inode device inode
- * \param file_priv DRM file private.
- * \return zero on success or a negative number on failure.
- *
- * If the hardware lock is held then free it, and take it again for the kernel
- * context since it's necessary to reclaim buffers. Unlink the file private
- * data from its list and free it. Decreases the open count and if it reaches
- * zero calls drm_lastclose().
- */
-int drm_release(struct inode *inode, struct file *filp)
-{
-       struct drm_file *file_priv = filp->private_data;
-       struct drm_device *dev = file_priv->minor->dev;
-       int retcode = 0;
-
-       lock_kernel();
-
-       DRM_DEBUG("open_count = %d\n", dev->open_count);
-
-       if (dev->driver->preclose)
-               dev->driver->preclose(dev, file_priv);
-
-       /* ========================================================
-        * Begin inline drm_release
-        */
-
-       DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
-                 task_pid_nr(current),
-                 (long)old_encode_dev(file_priv->minor->device),
-                 dev->open_count);
-
-       if (dev->driver->reclaim_buffers_locked && dev->lock.hw_lock) {
-               if (drm_i_have_hw_lock(dev, file_priv)) {
-                       dev->driver->reclaim_buffers_locked(dev, file_priv);
-               } else {
-                       unsigned long endtime = jiffies + 3 * DRM_HZ;
-                       int locked = 0;
-
-                       drm_idlelock_take(&dev->lock);
-
-                       /*
-                        * Wait for a while.
-                        */
-
-                       do{
-                               spin_lock_bh(&dev->lock.spinlock);
-                               locked = dev->lock.idle_has_lock;
-                               spin_unlock_bh(&dev->lock.spinlock);
-                               if (locked)
-                                       break;
-                               schedule();
-                       } while (!time_after_eq(jiffies, endtime));
-
-                       if (!locked) {
-                               DRM_ERROR("reclaim_buffers_locked() deadlock. Please rework this\n"
-                                         "\tdriver to use reclaim_buffers_idlelocked() instead.\n"
-                                         "\tI will go on reclaiming the buffers anyway.\n");
-                       }
-
-                       dev->driver->reclaim_buffers_locked(dev, file_priv);
-                       drm_idlelock_release(&dev->lock);
-               }
-       }
-
-       if (dev->driver->reclaim_buffers_idlelocked && dev->lock.hw_lock) {
-
-               drm_idlelock_take(&dev->lock);
-               dev->driver->reclaim_buffers_idlelocked(dev, file_priv);
-               drm_idlelock_release(&dev->lock);
-
-       }
-
-       if (drm_i_have_hw_lock(dev, file_priv)) {
-               DRM_DEBUG("File %p released, freeing lock for context %d\n",
-                         filp, _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
-
-               drm_lock_free(&dev->lock,
-                             _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
-       }
-
-
-       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
-           !dev->driver->reclaim_buffers_locked) {
-               dev->driver->reclaim_buffers(dev, file_priv);
-       }
-
-       drm_fasync(-1, filp, 0);
-
-       mutex_lock(&dev->ctxlist_mutex);
-       if (!list_empty(&dev->ctxlist)) {
-               struct drm_ctx_list *pos, *n;
-
-               list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
-                       if (pos->tag == file_priv &&
-                           pos->handle != DRM_KERNEL_CONTEXT) {
-                               if (dev->driver->context_dtor)
-                                       dev->driver->context_dtor(dev,
-                                                                 pos->handle);
-
-                               drm_ctxbitmap_free(dev, pos->handle);
-
-                               list_del(&pos->head);
-                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
-                               --dev->ctx_count;
-                       }
-               }
-       }
-       mutex_unlock(&dev->ctxlist_mutex);
-
-       mutex_lock(&dev->struct_mutex);
-       if (file_priv->remove_auth_on_close == 1) {
-               struct drm_file *temp;
-
-               list_for_each_entry(temp, &dev->filelist, lhead)
-                       temp->authenticated = 0;
-       }
-       list_del(&file_priv->lhead);
-       mutex_unlock(&dev->struct_mutex);
-
-       if (dev->driver->postclose)
-               dev->driver->postclose(dev, file_priv);
-       drm_free(file_priv, sizeof(*file_priv), DRM_MEM_FILES);
-
-       /* ========================================================
-        * End inline drm_release
-        */
-
-       atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
-       spin_lock(&dev->count_lock);
-       if (!--dev->open_count) {
-               if (atomic_read(&dev->ioctl_count) || dev->blocked) {
-                       DRM_ERROR("Device busy: %d %d\n",
-                                 atomic_read(&dev->ioctl_count), dev->blocked);
-                       spin_unlock(&dev->count_lock);
-                       unlock_kernel();
-                       return -EBUSY;
-               }
-               spin_unlock(&dev->count_lock);
-               unlock_kernel();
-               return drm_lastclose(dev);
-       }
-       spin_unlock(&dev->count_lock);
-
-       unlock_kernel();
-
-       return retcode;
-}
-EXPORT_SYMBOL(drm_release);
-
-/** No-op. */
-unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
-{
-       return 0;
-}
-EXPORT_SYMBOL(drm_poll);
diff --git a/drivers/char/drm/drm_hashtab.c b/drivers/char/drm/drm_hashtab.c
deleted file mode 100644 (file)
index 3316067..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- **************************************************************************/
-/*
- * Simple open hash tab implementation.
- *
- * Authors:
- * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include "drm_hashtab.h"
-#include <linux/hash.h>
-
-int drm_ht_create(struct drm_open_hash *ht, unsigned int order)
-{
-       unsigned int i;
-
-       ht->size = 1 << order;
-       ht->order = order;
-       ht->fill = 0;
-       ht->table = NULL;
-       ht->use_vmalloc = ((ht->size * sizeof(*ht->table)) > PAGE_SIZE);
-       if (!ht->use_vmalloc) {
-               ht->table = drm_calloc(ht->size, sizeof(*ht->table),
-                                      DRM_MEM_HASHTAB);
-       }
-       if (!ht->table) {
-               ht->use_vmalloc = 1;
-               ht->table = vmalloc(ht->size*sizeof(*ht->table));
-       }
-       if (!ht->table) {
-               DRM_ERROR("Out of memory for hash table\n");
-               return -ENOMEM;
-       }
-       for (i=0; i< ht->size; ++i) {
-               INIT_HLIST_HEAD(&ht->table[i]);
-       }
-       return 0;
-}
-
-void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
-{
-       struct drm_hash_item *entry;
-       struct hlist_head *h_list;
-       struct hlist_node *list;
-       unsigned int hashed_key;
-       int count = 0;
-
-       hashed_key = hash_long(key, ht->order);
-       DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
-       h_list = &ht->table[hashed_key];
-       hlist_for_each(list, h_list) {
-               entry = hlist_entry(list, struct drm_hash_item, head);
-               DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
-       }
-}
-
-static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
-                                         unsigned long key)
-{
-       struct drm_hash_item *entry;
-       struct hlist_head *h_list;
-       struct hlist_node *list;
-       unsigned int hashed_key;
-
-       hashed_key = hash_long(key, ht->order);
-       h_list = &ht->table[hashed_key];
-       hlist_for_each(list, h_list) {
-               entry = hlist_entry(list, struct drm_hash_item, head);
-               if (entry->key == key)
-                       return list;
-               if (entry->key > key)
-                       break;
-       }
-       return NULL;
-}
-
-
-int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
-{
-       struct drm_hash_item *entry;
-       struct hlist_head *h_list;
-       struct hlist_node *list, *parent;
-       unsigned int hashed_key;
-       unsigned long key = item->key;
-
-       hashed_key = hash_long(key, ht->order);
-       h_list = &ht->table[hashed_key];
-       parent = NULL;
-       hlist_for_each(list, h_list) {
-               entry = hlist_entry(list, struct drm_hash_item, head);
-               if (entry->key == key)
-                       return -EINVAL;
-               if (entry->key > key)
-                       break;
-               parent = list;
-       }
-       if (parent) {
-               hlist_add_after(parent, &item->head);
-       } else {
-               hlist_add_head(&item->head, h_list);
-       }
-       return 0;
-}
-
-/*
- * Just insert an item and return any "bits" bit key that hasn't been
- * used before.
- */
-int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
-                             unsigned long seed, int bits, int shift,
-                             unsigned long add)
-{
-       int ret;
-       unsigned long mask = (1 << bits) - 1;
-       unsigned long first, unshifted_key;
-
-       unshifted_key = hash_long(seed, bits);
-       first = unshifted_key;
-       do {
-               item->key = (unshifted_key << shift) + add;
-               ret = drm_ht_insert_item(ht, item);
-               if (ret)
-                       unshifted_key = (unshifted_key + 1) & mask;
-       } while(ret && (unshifted_key != first));
-
-       if (ret) {
-               DRM_ERROR("Available key bit space exhausted\n");
-               return -EINVAL;
-       }
-       return 0;
-}
-
-int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key,
-                    struct drm_hash_item **item)
-{
-       struct hlist_node *list;
-
-       list = drm_ht_find_key(ht, key);
-       if (!list)
-               return -EINVAL;
-
-       *item = hlist_entry(list, struct drm_hash_item, head);
-       return 0;
-}
-
-int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key)
-{
-       struct hlist_node *list;
-
-       list = drm_ht_find_key(ht, key);
-       if (list) {
-               hlist_del_init(list);
-               ht->fill--;
-               return 0;
-       }
-       return -EINVAL;
-}
-
-int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item)
-{
-       hlist_del_init(&item->head);
-       ht->fill--;
-       return 0;
-}
-
-void drm_ht_remove(struct drm_open_hash *ht)
-{
-       if (ht->table) {
-               if (ht->use_vmalloc)
-                       vfree(ht->table);
-               else
-                       drm_free(ht->table, ht->size * sizeof(*ht->table),
-                                DRM_MEM_HASHTAB);
-               ht->table = NULL;
-       }
-}
diff --git a/drivers/char/drm/drm_hashtab.h b/drivers/char/drm/drm_hashtab.h
deleted file mode 100644 (file)
index cd2b189..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- **************************************************************************/
-/*
- * Simple open hash tab implementation.
- *
- * Authors:
- * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#ifndef DRM_HASHTAB_H
-#define DRM_HASHTAB_H
-
-#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
-
-struct drm_hash_item {
-       struct hlist_node head;
-       unsigned long key;
-};
-
-struct drm_open_hash {
-       unsigned int size;
-       unsigned int order;
-       unsigned int fill;
-       struct hlist_head *table;
-       int use_vmalloc;
-};
-
-
-extern int drm_ht_create(struct drm_open_hash *ht, unsigned int order);
-extern int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
-extern int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
-                                    unsigned long seed, int bits, int shift,
-                                    unsigned long add);
-extern int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
-
-extern void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
-extern int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
-extern int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
-extern void drm_ht_remove(struct drm_open_hash *ht);
-
-
-#endif
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
deleted file mode 100644 (file)
index 90f5a8d..0000000
+++ /dev/null
@@ -1,1073 +0,0 @@
-/**
- * \file drm_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the DRM.
- *
- * \author Paul Mackerras <paulus@samba.org>
- *
- * Copyright (C) Paul Mackerras 2005.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include "drmP.h"
-#include "drm_core.h"
-
-#define DRM_IOCTL_VERSION32            DRM_IOWR(0x00, drm_version32_t)
-#define DRM_IOCTL_GET_UNIQUE32         DRM_IOWR(0x01, drm_unique32_t)
-#define DRM_IOCTL_GET_MAP32            DRM_IOWR(0x04, drm_map32_t)
-#define DRM_IOCTL_GET_CLIENT32         DRM_IOWR(0x05, drm_client32_t)
-#define DRM_IOCTL_GET_STATS32          DRM_IOR( 0x06, drm_stats32_t)
-
-#define DRM_IOCTL_SET_UNIQUE32         DRM_IOW( 0x10, drm_unique32_t)
-#define DRM_IOCTL_ADD_MAP32            DRM_IOWR(0x15, drm_map32_t)
-#define DRM_IOCTL_ADD_BUFS32           DRM_IOWR(0x16, drm_buf_desc32_t)
-#define DRM_IOCTL_MARK_BUFS32          DRM_IOW( 0x17, drm_buf_desc32_t)
-#define DRM_IOCTL_INFO_BUFS32          DRM_IOWR(0x18, drm_buf_info32_t)
-#define DRM_IOCTL_MAP_BUFS32           DRM_IOWR(0x19, drm_buf_map32_t)
-#define DRM_IOCTL_FREE_BUFS32          DRM_IOW( 0x1a, drm_buf_free32_t)
-
-#define DRM_IOCTL_RM_MAP32             DRM_IOW( 0x1b, drm_map32_t)
-
-#define DRM_IOCTL_SET_SAREA_CTX32      DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
-#define DRM_IOCTL_GET_SAREA_CTX32      DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
-
-#define DRM_IOCTL_RES_CTX32            DRM_IOWR(0x26, drm_ctx_res32_t)
-#define DRM_IOCTL_DMA32                        DRM_IOWR(0x29, drm_dma32_t)
-
-#define DRM_IOCTL_AGP_ENABLE32         DRM_IOW( 0x32, drm_agp_mode32_t)
-#define DRM_IOCTL_AGP_INFO32           DRM_IOR( 0x33, drm_agp_info32_t)
-#define DRM_IOCTL_AGP_ALLOC32          DRM_IOWR(0x34, drm_agp_buffer32_t)
-#define DRM_IOCTL_AGP_FREE32           DRM_IOW( 0x35, drm_agp_buffer32_t)
-#define DRM_IOCTL_AGP_BIND32           DRM_IOW( 0x36, drm_agp_binding32_t)
-#define DRM_IOCTL_AGP_UNBIND32         DRM_IOW( 0x37, drm_agp_binding32_t)
-
-#define DRM_IOCTL_SG_ALLOC32           DRM_IOW( 0x38, drm_scatter_gather32_t)
-#define DRM_IOCTL_SG_FREE32            DRM_IOW( 0x39, drm_scatter_gather32_t)
-
-#define DRM_IOCTL_WAIT_VBLANK32                DRM_IOWR(0x3a, drm_wait_vblank32_t)
-
-typedef struct drm_version_32 {
-       int version_major;        /**< Major version */
-       int version_minor;        /**< Minor version */
-       int version_patchlevel;    /**< Patch level */
-       u32 name_len;             /**< Length of name buffer */
-       u32 name;                 /**< Name of driver */
-       u32 date_len;             /**< Length of date buffer */
-       u32 date;                 /**< User-space buffer to hold date */
-       u32 desc_len;             /**< Length of desc buffer */
-       u32 desc;                 /**< User-space buffer to hold desc */
-} drm_version32_t;
-
-static int compat_drm_version(struct file *file, unsigned int cmd,
-                             unsigned long arg)
-{
-       drm_version32_t v32;
-       struct drm_version __user *version;
-       int err;
-
-       if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
-               return -EFAULT;
-
-       version = compat_alloc_user_space(sizeof(*version));
-       if (!access_ok(VERIFY_WRITE, version, sizeof(*version)))
-               return -EFAULT;
-       if (__put_user(v32.name_len, &version->name_len)
-           || __put_user((void __user *)(unsigned long)v32.name,
-                         &version->name)
-           || __put_user(v32.date_len, &version->date_len)
-           || __put_user((void __user *)(unsigned long)v32.date,
-                         &version->date)
-           || __put_user(v32.desc_len, &version->desc_len)
-           || __put_user((void __user *)(unsigned long)v32.desc,
-                         &version->desc))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_VERSION, (unsigned long)version);
-       if (err)
-               return err;
-
-       if (__get_user(v32.version_major, &version->version_major)
-           || __get_user(v32.version_minor, &version->version_minor)
-           || __get_user(v32.version_patchlevel, &version->version_patchlevel)
-           || __get_user(v32.name_len, &version->name_len)
-           || __get_user(v32.date_len, &version->date_len)
-           || __get_user(v32.desc_len, &version->desc_len))
-               return -EFAULT;
-
-       if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
-               return -EFAULT;
-       return 0;
-}
-
-typedef struct drm_unique32 {
-       u32 unique_len; /**< Length of unique */
-       u32 unique;     /**< Unique name for driver instantiation */
-} drm_unique32_t;
-
-static int compat_drm_getunique(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_unique32_t uq32;
-       struct drm_unique __user *u;
-       int err;
-
-       if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
-               return -EFAULT;
-
-       u = compat_alloc_user_space(sizeof(*u));
-       if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
-               return -EFAULT;
-       if (__put_user(uq32.unique_len, &u->unique_len)
-           || __put_user((void __user *)(unsigned long)uq32.unique,
-                         &u->unique))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
-       if (err)
-               return err;
-
-       if (__get_user(uq32.unique_len, &u->unique_len))
-               return -EFAULT;
-       if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
-               return -EFAULT;
-       return 0;
-}
-
-static int compat_drm_setunique(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_unique32_t uq32;
-       struct drm_unique __user *u;
-
-       if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
-               return -EFAULT;
-
-       u = compat_alloc_user_space(sizeof(*u));
-       if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
-               return -EFAULT;
-       if (__put_user(uq32.unique_len, &u->unique_len)
-           || __put_user((void __user *)(unsigned long)uq32.unique,
-                         &u->unique))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
-}
-
-typedef struct drm_map32 {
-       u32 offset;             /**< Requested physical address (0 for SAREA)*/
-       u32 size;               /**< Requested physical size (bytes) */
-       enum drm_map_type type; /**< Type of memory to map */
-       enum drm_map_flags flags;       /**< Flags */
-       u32 handle;             /**< User-space: "Handle" to pass to mmap() */
-       int mtrr;               /**< MTRR slot used */
-} drm_map32_t;
-
-static int compat_drm_getmap(struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       drm_map32_t __user *argp = (void __user *)arg;
-       drm_map32_t m32;
-       struct drm_map __user *map;
-       int idx, err;
-       void *handle;
-
-       if (get_user(idx, &argp->offset))
-               return -EFAULT;
-
-       map = compat_alloc_user_space(sizeof(*map));
-       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
-               return -EFAULT;
-       if (__put_user(idx, &map->offset))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_GET_MAP, (unsigned long)map);
-       if (err)
-               return err;
-
-       if (__get_user(m32.offset, &map->offset)
-           || __get_user(m32.size, &map->size)
-           || __get_user(m32.type, &map->type)
-           || __get_user(m32.flags, &map->flags)
-           || __get_user(handle, &map->handle)
-           || __get_user(m32.mtrr, &map->mtrr))
-               return -EFAULT;
-
-       m32.handle = (unsigned long)handle;
-       if (copy_to_user(argp, &m32, sizeof(m32)))
-               return -EFAULT;
-       return 0;
-
-}
-
-static int compat_drm_addmap(struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       drm_map32_t __user *argp = (void __user *)arg;
-       drm_map32_t m32;
-       struct drm_map __user *map;
-       int err;
-       void *handle;
-
-       if (copy_from_user(&m32, argp, sizeof(m32)))
-               return -EFAULT;
-
-       map = compat_alloc_user_space(sizeof(*map));
-       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
-               return -EFAULT;
-       if (__put_user(m32.offset, &map->offset)
-           || __put_user(m32.size, &map->size)
-           || __put_user(m32.type, &map->type)
-           || __put_user(m32.flags, &map->flags))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_ADD_MAP, (unsigned long)map);
-       if (err)
-               return err;
-
-       if (__get_user(m32.offset, &map->offset)
-           || __get_user(m32.mtrr, &map->mtrr)
-           || __get_user(handle, &map->handle))
-               return -EFAULT;
-
-       m32.handle = (unsigned long)handle;
-       if (m32.handle != (unsigned long)handle && printk_ratelimit())
-               printk(KERN_ERR "compat_drm_addmap truncated handle"
-                      " %p for type %d offset %x\n",
-                      handle, m32.type, m32.offset);
-
-       if (copy_to_user(argp, &m32, sizeof(m32)))
-               return -EFAULT;
-
-       return 0;
-}
-
-static int compat_drm_rmmap(struct file *file, unsigned int cmd,
-                           unsigned long arg)
-{
-       drm_map32_t __user *argp = (void __user *)arg;
-       struct drm_map __user *map;
-       u32 handle;
-
-       if (get_user(handle, &argp->handle))
-               return -EFAULT;
-
-       map = compat_alloc_user_space(sizeof(*map));
-       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
-               return -EFAULT;
-       if (__put_user((void *)(unsigned long)handle, &map->handle))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RM_MAP, (unsigned long)map);
-}
-
-typedef struct drm_client32 {
-       int idx;        /**< Which client desired? */
-       int auth;       /**< Is client authenticated? */
-       u32 pid;        /**< Process ID */
-       u32 uid;        /**< User ID */
-       u32 magic;      /**< Magic */
-       u32 iocs;       /**< Ioctl count */
-} drm_client32_t;
-
-static int compat_drm_getclient(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_client32_t c32;
-       drm_client32_t __user *argp = (void __user *)arg;
-       struct drm_client __user *client;
-       int idx, err;
-
-       if (get_user(idx, &argp->idx))
-               return -EFAULT;
-
-       client = compat_alloc_user_space(sizeof(*client));
-       if (!access_ok(VERIFY_WRITE, client, sizeof(*client)))
-               return -EFAULT;
-       if (__put_user(idx, &client->idx))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_GET_CLIENT, (unsigned long)client);
-       if (err)
-               return err;
-
-       if (__get_user(c32.auth, &client->auth)
-           || __get_user(c32.pid, &client->pid)
-           || __get_user(c32.uid, &client->uid)
-           || __get_user(c32.magic, &client->magic)
-           || __get_user(c32.iocs, &client->iocs))
-               return -EFAULT;
-
-       if (copy_to_user(argp, &c32, sizeof(c32)))
-               return -EFAULT;
-       return 0;
-}
-
-typedef struct drm_stats32 {
-       u32 count;
-       struct {
-               u32 value;
-               enum drm_stat_type type;
-       } data[15];
-} drm_stats32_t;
-
-static int compat_drm_getstats(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_stats32_t s32;
-       drm_stats32_t __user *argp = (void __user *)arg;
-       struct drm_stats __user *stats;
-       int i, err;
-
-       stats = compat_alloc_user_space(sizeof(*stats));
-       if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_GET_STATS, (unsigned long)stats);
-       if (err)
-               return err;
-
-       if (__get_user(s32.count, &stats->count))
-               return -EFAULT;
-       for (i = 0; i < 15; ++i)
-               if (__get_user(s32.data[i].value, &stats->data[i].value)
-                   || __get_user(s32.data[i].type, &stats->data[i].type))
-                       return -EFAULT;
-
-       if (copy_to_user(argp, &s32, sizeof(s32)))
-               return -EFAULT;
-       return 0;
-}
-
-typedef struct drm_buf_desc32 {
-       int count;               /**< Number of buffers of this size */
-       int size;                /**< Size in bytes */
-       int low_mark;            /**< Low water mark */
-       int high_mark;           /**< High water mark */
-       int flags;
-       u32 agp_start;           /**< Start address in the AGP aperture */
-} drm_buf_desc32_t;
-
-static int compat_drm_addbufs(struct file *file, unsigned int cmd,
-                             unsigned long arg)
-{
-       drm_buf_desc32_t __user *argp = (void __user *)arg;
-       struct drm_buf_desc __user *buf;
-       int err;
-       unsigned long agp_start;
-
-       buf = compat_alloc_user_space(sizeof(*buf));
-       if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf))
-           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)))
-               return -EFAULT;
-
-       if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start))
-           || __get_user(agp_start, &argp->agp_start)
-           || __put_user(agp_start, &buf->agp_start))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
-       if (err)
-               return err;
-
-       if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start))
-           || __get_user(agp_start, &buf->agp_start)
-           || __put_user(agp_start, &argp->agp_start))
-               return -EFAULT;
-
-       return 0;
-}
-
-static int compat_drm_markbufs(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_buf_desc32_t b32;
-       drm_buf_desc32_t __user *argp = (void __user *)arg;
-       struct drm_buf_desc __user *buf;
-
-       if (copy_from_user(&b32, argp, sizeof(b32)))
-               return -EFAULT;
-
-       buf = compat_alloc_user_space(sizeof(*buf));
-       if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))
-               return -EFAULT;
-
-       if (__put_user(b32.size, &buf->size)
-           || __put_user(b32.low_mark, &buf->low_mark)
-           || __put_user(b32.high_mark, &buf->high_mark))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
-}
-
-typedef struct drm_buf_info32 {
-       int count;              /**< Entries in list */
-       u32 list;
-} drm_buf_info32_t;
-
-static int compat_drm_infobufs(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_buf_info32_t req32;
-       drm_buf_info32_t __user *argp = (void __user *)arg;
-       drm_buf_desc32_t __user *to;
-       struct drm_buf_info __user *request;
-       struct drm_buf_desc __user *list;
-       size_t nbytes;
-       int i, err;
-       int count, actual;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       count = req32.count;
-       to = (drm_buf_desc32_t __user *) (unsigned long)req32.list;
-       if (count < 0)
-               count = 0;
-       if (count > 0
-           && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t)))
-               return -EFAULT;
-
-       nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc);
-       request = compat_alloc_user_space(nbytes);
-       if (!access_ok(VERIFY_WRITE, request, nbytes))
-               return -EFAULT;
-       list = (struct drm_buf_desc *) (request + 1);
-
-       if (__put_user(count, &request->count)
-           || __put_user(list, &request->list))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_INFO_BUFS, (unsigned long)request);
-       if (err)
-               return err;
-
-       if (__get_user(actual, &request->count))
-               return -EFAULT;
-       if (count >= actual)
-               for (i = 0; i < actual; ++i)
-                       if (__copy_in_user(&to[i], &list[i],
-                                          offsetof(struct drm_buf_desc, flags)))
-                               return -EFAULT;
-
-       if (__put_user(actual, &argp->count))
-               return -EFAULT;
-
-       return 0;
-}
-
-typedef struct drm_buf_pub32 {
-       int idx;                /**< Index into the master buffer list */
-       int total;              /**< Buffer size */
-       int used;               /**< Amount of buffer in use (for DMA) */
-       u32 address;            /**< Address of buffer */
-} drm_buf_pub32_t;
-
-typedef struct drm_buf_map32 {
-       int count;              /**< Length of the buffer list */
-       u32 virtual;            /**< Mmap'd area in user-virtual */
-       u32 list;               /**< Buffer information */
-} drm_buf_map32_t;
-
-static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
-                             unsigned long arg)
-{
-       drm_buf_map32_t __user *argp = (void __user *)arg;
-       drm_buf_map32_t req32;
-       drm_buf_pub32_t __user *list32;
-       struct drm_buf_map __user *request;
-       struct drm_buf_pub __user *list;
-       int i, err;
-       int count, actual;
-       size_t nbytes;
-       void __user *addr;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-       count = req32.count;
-       list32 = (void __user *)(unsigned long)req32.list;
-
-       if (count < 0)
-               return -EINVAL;
-       nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
-       request = compat_alloc_user_space(nbytes);
-       if (!access_ok(VERIFY_WRITE, request, nbytes))
-               return -EFAULT;
-       list = (struct drm_buf_pub *) (request + 1);
-
-       if (__put_user(count, &request->count)
-           || __put_user(list, &request->list))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_MAP_BUFS, (unsigned long)request);
-       if (err)
-               return err;
-
-       if (__get_user(actual, &request->count))
-               return -EFAULT;
-       if (count >= actual)
-               for (i = 0; i < actual; ++i)
-                       if (__copy_in_user(&list32[i], &list[i],
-                                          offsetof(struct drm_buf_pub, address))
-                           || __get_user(addr, &list[i].address)
-                           || __put_user((unsigned long)addr,
-                                         &list32[i].address))
-                               return -EFAULT;
-
-       if (__put_user(actual, &argp->count)
-           || __get_user(addr, &request->virtual)
-           || __put_user((unsigned long)addr, &argp->virtual))
-               return -EFAULT;
-
-       return 0;
-}
-
-typedef struct drm_buf_free32 {
-       int count;
-       u32 list;
-} drm_buf_free32_t;
-
-static int compat_drm_freebufs(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_buf_free32_t req32;
-       struct drm_buf_free __user *request;
-       drm_buf_free32_t __user *argp = (void __user *)arg;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
-               return -EFAULT;
-       if (__put_user(req32.count, &request->count)
-           || __put_user((int __user *)(unsigned long)req32.list,
-                         &request->list))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_FREE_BUFS, (unsigned long)request);
-}
-
-typedef struct drm_ctx_priv_map32 {
-       unsigned int ctx_id;     /**< Context requesting private mapping */
-       u32 handle;             /**< Handle of map */
-} drm_ctx_priv_map32_t;
-
-static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
-                                 unsigned long arg)
-{
-       drm_ctx_priv_map32_t req32;
-       struct drm_ctx_priv_map __user *request;
-       drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
-               return -EFAULT;
-       if (__put_user(req32.ctx_id, &request->ctx_id)
-           || __put_user((void *)(unsigned long)req32.handle,
-                         &request->handle))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
-}
-
-static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
-                                 unsigned long arg)
-{
-       struct drm_ctx_priv_map __user *request;
-       drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
-       int err;
-       unsigned int ctx_id;
-       void *handle;
-
-       if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp))
-           || __get_user(ctx_id, &argp->ctx_id))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
-               return -EFAULT;
-       if (__put_user(ctx_id, &request->ctx_id))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
-       if (err)
-               return err;
-
-       if (__get_user(handle, &request->handle)
-           || __put_user((unsigned long)handle, &argp->handle))
-               return -EFAULT;
-
-       return 0;
-}
-
-typedef struct drm_ctx_res32 {
-       int count;
-       u32 contexts;
-} drm_ctx_res32_t;
-
-static int compat_drm_resctx(struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       drm_ctx_res32_t __user *argp = (void __user *)arg;
-       drm_ctx_res32_t res32;
-       struct drm_ctx_res __user *res;
-       int err;
-
-       if (copy_from_user(&res32, argp, sizeof(res32)))
-               return -EFAULT;
-
-       res = compat_alloc_user_space(sizeof(*res));
-       if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
-               return -EFAULT;
-       if (__put_user(res32.count, &res->count)
-           || __put_user((struct drm_ctx __user *) (unsigned long)res32.contexts,
-                         &res->contexts))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_RES_CTX, (unsigned long)res);
-       if (err)
-               return err;
-
-       if (__get_user(res32.count, &res->count)
-           || __put_user(res32.count, &argp->count))
-               return -EFAULT;
-
-       return 0;
-}
-
-typedef struct drm_dma32 {
-       int context;              /**< Context handle */
-       int send_count;           /**< Number of buffers to send */
-       u32 send_indices;         /**< List of handles to buffers */
-       u32 send_sizes;           /**< Lengths of data to send */
-       enum drm_dma_flags flags;                 /**< Flags */
-       int request_count;        /**< Number of buffers requested */
-       int request_size;         /**< Desired size for buffers */
-       u32 request_indices;      /**< Buffer information */
-       u32 request_sizes;
-       int granted_count;        /**< Number of buffers granted */
-} drm_dma32_t;
-
-static int compat_drm_dma(struct file *file, unsigned int cmd,
-                         unsigned long arg)
-{
-       drm_dma32_t d32;
-       drm_dma32_t __user *argp = (void __user *)arg;
-       struct drm_dma __user *d;
-       int err;
-
-       if (copy_from_user(&d32, argp, sizeof(d32)))
-               return -EFAULT;
-
-       d = compat_alloc_user_space(sizeof(*d));
-       if (!access_ok(VERIFY_WRITE, d, sizeof(*d)))
-               return -EFAULT;
-
-       if (__put_user(d32.context, &d->context)
-           || __put_user(d32.send_count, &d->send_count)
-           || __put_user((int __user *)(unsigned long)d32.send_indices,
-                         &d->send_indices)
-           || __put_user((int __user *)(unsigned long)d32.send_sizes,
-                         &d->send_sizes)
-           || __put_user(d32.flags, &d->flags)
-           || __put_user(d32.request_count, &d->request_count)
-           || __put_user((int __user *)(unsigned long)d32.request_indices,
-                         &d->request_indices)
-           || __put_user((int __user *)(unsigned long)d32.request_sizes,
-                         &d->request_sizes))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_DMA, (unsigned long)d);
-       if (err)
-               return err;
-
-       if (__get_user(d32.request_size, &d->request_size)
-           || __get_user(d32.granted_count, &d->granted_count)
-           || __put_user(d32.request_size, &argp->request_size)
-           || __put_user(d32.granted_count, &argp->granted_count))
-               return -EFAULT;
-
-       return 0;
-}
-
-#if __OS_HAS_AGP
-typedef struct drm_agp_mode32 {
-       u32 mode;       /**< AGP mode */
-} drm_agp_mode32_t;
-
-static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
-                                unsigned long arg)
-{
-       drm_agp_mode32_t __user *argp = (void __user *)arg;
-       drm_agp_mode32_t m32;
-       struct drm_agp_mode __user *mode;
-
-       if (get_user(m32.mode, &argp->mode))
-               return -EFAULT;
-
-       mode = compat_alloc_user_space(sizeof(*mode));
-       if (put_user(m32.mode, &mode->mode))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
-}
-
-typedef struct drm_agp_info32 {
-       int agp_version_major;
-       int agp_version_minor;
-       u32 mode;
-       u32 aperture_base;      /* physical address */
-       u32 aperture_size;      /* bytes */
-       u32 memory_allowed;     /* bytes */
-       u32 memory_used;
-
-       /* PCI information */
-       unsigned short id_vendor;
-       unsigned short id_device;
-} drm_agp_info32_t;
-
-static int compat_drm_agp_info(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_agp_info32_t __user *argp = (void __user *)arg;
-       drm_agp_info32_t i32;
-       struct drm_agp_info __user *info;
-       int err;
-
-       info = compat_alloc_user_space(sizeof(*info));
-       if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_AGP_INFO, (unsigned long)info);
-       if (err)
-               return err;
-
-       if (__get_user(i32.agp_version_major, &info->agp_version_major)
-           || __get_user(i32.agp_version_minor, &info->agp_version_minor)
-           || __get_user(i32.mode, &info->mode)
-           || __get_user(i32.aperture_base, &info->aperture_base)
-           || __get_user(i32.aperture_size, &info->aperture_size)
-           || __get_user(i32.memory_allowed, &info->memory_allowed)
-           || __get_user(i32.memory_used, &info->memory_used)
-           || __get_user(i32.id_vendor, &info->id_vendor)
-           || __get_user(i32.id_device, &info->id_device))
-               return -EFAULT;
-
-       if (copy_to_user(argp, &i32, sizeof(i32)))
-               return -EFAULT;
-
-       return 0;
-}
-
-typedef struct drm_agp_buffer32 {
-       u32 size;       /**< In bytes -- will round to page boundary */
-       u32 handle;     /**< Used for binding / unbinding */
-       u32 type;       /**< Type of memory to allocate */
-       u32 physical;   /**< Physical used by i810 */
-} drm_agp_buffer32_t;
-
-static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_agp_buffer32_t __user *argp = (void __user *)arg;
-       drm_agp_buffer32_t req32;
-       struct drm_agp_buffer __user *request;
-       int err;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.size, &request->size)
-           || __put_user(req32.type, &request->type))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
-       if (err)
-               return err;
-
-       if (__get_user(req32.handle, &request->handle)
-           || __get_user(req32.physical, &request->physical)
-           || copy_to_user(argp, &req32, sizeof(req32))) {
-               drm_ioctl(file->f_path.dentry->d_inode, file,
-                         DRM_IOCTL_AGP_FREE, (unsigned long)request);
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-static int compat_drm_agp_free(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_agp_buffer32_t __user *argp = (void __user *)arg;
-       struct drm_agp_buffer __user *request;
-       u32 handle;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || get_user(handle, &argp->handle)
-           || __put_user(handle, &request->handle))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_AGP_FREE, (unsigned long)request);
-}
-
-typedef struct drm_agp_binding32 {
-       u32 handle;     /**< From drm_agp_buffer */
-       u32 offset;     /**< In bytes -- will round to page boundary */
-} drm_agp_binding32_t;
-
-static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_agp_binding32_t __user *argp = (void __user *)arg;
-       drm_agp_binding32_t req32;
-       struct drm_agp_binding __user *request;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.handle, &request->handle)
-           || __put_user(req32.offset, &request->offset))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_AGP_BIND, (unsigned long)request);
-}
-
-static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
-                                unsigned long arg)
-{
-       drm_agp_binding32_t __user *argp = (void __user *)arg;
-       struct drm_agp_binding __user *request;
-       u32 handle;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || get_user(handle, &argp->handle)
-           || __put_user(handle, &request->handle))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
-}
-#endif                         /* __OS_HAS_AGP */
-
-typedef struct drm_scatter_gather32 {
-       u32 size;       /**< In bytes -- will round to page boundary */
-       u32 handle;     /**< Used for mapping / unmapping */
-} drm_scatter_gather32_t;
-
-static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_scatter_gather32_t __user *argp = (void __user *)arg;
-       struct drm_scatter_gather __user *request;
-       int err;
-       unsigned long x;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
-           || __get_user(x, &argp->size)
-           || __put_user(x, &request->size))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_SG_ALLOC, (unsigned long)request);
-       if (err)
-               return err;
-
-       /* XXX not sure about the handle conversion here... */
-       if (__get_user(x, &request->handle)
-           || __put_user(x >> PAGE_SHIFT, &argp->handle))
-               return -EFAULT;
-
-       return 0;
-}
-
-static int compat_drm_sg_free(struct file *file, unsigned int cmd,
-                             unsigned long arg)
-{
-       drm_scatter_gather32_t __user *argp = (void __user *)arg;
-       struct drm_scatter_gather __user *request;
-       unsigned long x;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
-           || __get_user(x, &argp->handle)
-           || __put_user(x << PAGE_SHIFT, &request->handle))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_SG_FREE, (unsigned long)request);
-}
-
-struct drm_wait_vblank_request32 {
-       enum drm_vblank_seq_type type;
-       unsigned int sequence;
-       u32 signal;
-};
-
-struct drm_wait_vblank_reply32 {
-       enum drm_vblank_seq_type type;
-       unsigned int sequence;
-       s32 tval_sec;
-       s32 tval_usec;
-};
-
-typedef union drm_wait_vblank32 {
-       struct drm_wait_vblank_request32 request;
-       struct drm_wait_vblank_reply32 reply;
-} drm_wait_vblank32_t;
-
-static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
-                                 unsigned long arg)
-{
-       drm_wait_vblank32_t __user *argp = (void __user *)arg;
-       drm_wait_vblank32_t req32;
-       union drm_wait_vblank __user *request;
-       int err;
-
-       if (copy_from_user(&req32, argp, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.request.type, &request->request.type)
-           || __put_user(req32.request.sequence, &request->request.sequence)
-           || __put_user(req32.request.signal, &request->request.signal))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
-       if (err)
-               return err;
-
-       if (__get_user(req32.reply.type, &request->reply.type)
-           || __get_user(req32.reply.sequence, &request->reply.sequence)
-           || __get_user(req32.reply.tval_sec, &request->reply.tval_sec)
-           || __get_user(req32.reply.tval_usec, &request->reply.tval_usec))
-               return -EFAULT;
-
-       if (copy_to_user(argp, &req32, sizeof(req32)))
-               return -EFAULT;
-
-       return 0;
-}
-
-drm_ioctl_compat_t *drm_compat_ioctls[] = {
-       [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient,
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats,
-       [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique,
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap,
-       [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs,
-       [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs,
-       [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs,
-       [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs,
-       [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs,
-       [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap,
-       [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx,
-       [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx,
-       [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx,
-       [DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma,
-#if __OS_HAS_AGP
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable,
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info,
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc,
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free,
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind,
-       [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind,
-#endif
-       [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
-       [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
-       [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
-};
-
-/**
- * Called whenever a 32-bit process running under a 64-bit kernel
- * performs an ioctl on /dev/drm.
- *
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- */
-long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       drm_ioctl_compat_t *fn;
-       int ret;
-
-       /* Assume that ioctls without an explicit compat routine will just
-        * work.  This may not always be a good assumption, but it's better
-        * than always failing.
-        */
-       if (nr >= ARRAY_SIZE(drm_compat_ioctls))
-               return drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
-
-       fn = drm_compat_ioctls[nr];
-
-       lock_kernel();          /* XXX for now */
-       if (fn != NULL)
-               ret = (*fn) (filp, cmd, arg);
-       else
-               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
-       unlock_kernel();
-
-       return ret;
-}
-
-EXPORT_SYMBOL(drm_compat_ioctl);
diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c
deleted file mode 100644 (file)
index 16829fb..0000000
+++ /dev/null
@@ -1,352 +0,0 @@
-/**
- * \file drm_ioctl.c
- * IOCTL processing for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Fri Jan  8 09:01:26 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "drm_core.h"
-
-#include "linux/pci.h"
-
-/**
- * Get the bus id.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_unique structure.
- * \return zero on success or a negative number on failure.
- *
- * Copies the bus id from drm_device::unique into user space.
- */
-int drm_getunique(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       struct drm_unique *u = data;
-
-       if (u->unique_len >= dev->unique_len) {
-               if (copy_to_user(u->unique, dev->unique, dev->unique_len))
-                       return -EFAULT;
-       }
-       u->unique_len = dev->unique_len;
-
-       return 0;
-}
-
-/**
- * Set the bus id.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_unique structure.
- * \return zero on success or a negative number on failure.
- *
- * Copies the bus id from userspace into drm_device::unique, and verifies that
- * it matches the device this DRM is attached to (EINVAL otherwise).  Deprecated
- * in interface version 1.1 and will return EBUSY when setversion has requested
- * version 1.1 or greater.
- */
-int drm_setunique(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       struct drm_unique *u = data;
-       int domain, bus, slot, func, ret;
-
-       if (dev->unique_len || dev->unique)
-               return -EBUSY;
-
-       if (!u->unique_len || u->unique_len > 1024)
-               return -EINVAL;
-
-       dev->unique_len = u->unique_len;
-       dev->unique = drm_alloc(u->unique_len + 1, DRM_MEM_DRIVER);
-       if (!dev->unique)
-               return -ENOMEM;
-       if (copy_from_user(dev->unique, u->unique, dev->unique_len))
-               return -EFAULT;
-
-       dev->unique[dev->unique_len] = '\0';
-
-       dev->devname =
-           drm_alloc(strlen(dev->driver->pci_driver.name) +
-                     strlen(dev->unique) + 2, DRM_MEM_DRIVER);
-       if (!dev->devname)
-               return -ENOMEM;
-
-       sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
-               dev->unique);
-
-       /* Return error if the busid submitted doesn't match the device's actual
-        * busid.
-        */
-       ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
-       if (ret != 3)
-               return -EINVAL;
-       domain = bus >> 8;
-       bus &= 0xff;
-
-       if ((domain != drm_get_pci_domain(dev)) ||
-           (bus != dev->pdev->bus->number) ||
-           (slot != PCI_SLOT(dev->pdev->devfn)) ||
-           (func != PCI_FUNC(dev->pdev->devfn)))
-               return -EINVAL;
-
-       return 0;
-}
-
-static int drm_set_busid(struct drm_device * dev)
-{
-       int len;
-
-       if (dev->unique != NULL)
-               return 0;
-
-       dev->unique_len = 40;
-       dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
-       if (dev->unique == NULL)
-               return -ENOMEM;
-
-       len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
-                      drm_get_pci_domain(dev), dev->pdev->bus->number,
-                      PCI_SLOT(dev->pdev->devfn),
-                      PCI_FUNC(dev->pdev->devfn));
-
-       if (len > dev->unique_len)
-               DRM_ERROR("Unique buffer overflowed\n");
-
-       dev->devname =
-           drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
-                     2, DRM_MEM_DRIVER);
-       if (dev->devname == NULL)
-               return -ENOMEM;
-
-       sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
-               dev->unique);
-
-       return 0;
-}
-
-/**
- * Get a mapping information.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_map structure.
- *
- * \return zero on success or a negative number on failure.
- *
- * Searches for the mapping with the specified offset and copies its information
- * into userspace
- */
-int drm_getmap(struct drm_device *dev, void *data,
-              struct drm_file *file_priv)
-{
-       struct drm_map *map = data;
-       struct drm_map_list *r_list = NULL;
-       struct list_head *list;
-       int idx;
-       int i;
-
-       idx = map->offset;
-
-       mutex_lock(&dev->struct_mutex);
-       if (idx < 0) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       i = 0;
-       list_for_each(list, &dev->maplist) {
-               if (i == idx) {
-                       r_list = list_entry(list, struct drm_map_list, head);
-                       break;
-               }
-               i++;
-       }
-       if (!r_list || !r_list->map) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       map->offset = r_list->map->offset;
-       map->size = r_list->map->size;
-       map->type = r_list->map->type;
-       map->flags = r_list->map->flags;
-       map->handle = (void *)(unsigned long) r_list->user_token;
-       map->mtrr = r_list->map->mtrr;
-       mutex_unlock(&dev->struct_mutex);
-
-       return 0;
-}
-
-/**
- * Get client information.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_client structure.
- *
- * \return zero on success or a negative number on failure.
- *
- * Searches for the client with the specified index and copies its information
- * into userspace
- */
-int drm_getclient(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       struct drm_client *client = data;
-       struct drm_file *pt;
-       int idx;
-       int i;
-
-       idx = client->idx;
-       mutex_lock(&dev->struct_mutex);
-
-       i = 0;
-       list_for_each_entry(pt, &dev->filelist, lhead) {
-               if (i++ >= idx) {
-                       client->auth = pt->authenticated;
-                       client->pid = pt->pid;
-                       client->uid = pt->uid;
-                       client->magic = pt->magic;
-                       client->iocs = pt->ioctl_count;
-                       mutex_unlock(&dev->struct_mutex);
-
-                       return 0;
-               }
-       }
-       mutex_unlock(&dev->struct_mutex);
-
-       return -EINVAL;
-}
-
-/**
- * Get statistics information.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_stats structure.
- *
- * \return zero on success or a negative number on failure.
- */
-int drm_getstats(struct drm_device *dev, void *data,
-                struct drm_file *file_priv)
-{
-       struct drm_stats *stats = data;
-       int i;
-
-       memset(stats, 0, sizeof(*stats));
-
-       mutex_lock(&dev->struct_mutex);
-
-       for (i = 0; i < dev->counters; i++) {
-               if (dev->types[i] == _DRM_STAT_LOCK)
-                       stats->data[i].value =
-                           (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
-               else
-                       stats->data[i].value = atomic_read(&dev->counts[i]);
-               stats->data[i].type = dev->types[i];
-       }
-
-       stats->count = dev->counters;
-
-       mutex_unlock(&dev->struct_mutex);
-
-       return 0;
-}
-
-/**
- * Setversion ioctl.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_lock structure.
- * \return zero on success or negative number on failure.
- *
- * Sets the requested interface version
- */
-int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_set_version *sv = data;
-       int if_version, retcode = 0;
-
-       if (sv->drm_di_major != -1) {
-               if (sv->drm_di_major != DRM_IF_MAJOR ||
-                   sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) {
-                       retcode = -EINVAL;
-                       goto done;
-               }
-               if_version = DRM_IF_VERSION(sv->drm_di_major,
-                                           sv->drm_di_minor);
-               dev->if_version = max(if_version, dev->if_version);
-               if (sv->drm_di_minor >= 1) {
-                       /*
-                        * Version 1.1 includes tying of DRM to specific device
-                        */
-                       drm_set_busid(dev);
-               }
-       }
-
-       if (sv->drm_dd_major != -1) {
-               if (sv->drm_dd_major != dev->driver->major ||
-                   sv->drm_dd_minor < 0 || sv->drm_dd_minor >
-                   dev->driver->minor) {
-                       retcode = -EINVAL;
-                       goto done;
-               }
-
-               if (dev->driver->set_version)
-                       dev->driver->set_version(dev, sv);
-       }
-
-done:
-       sv->drm_di_major = DRM_IF_MAJOR;
-       sv->drm_di_minor = DRM_IF_MINOR;
-       sv->drm_dd_major = dev->driver->major;
-       sv->drm_dd_minor = dev->driver->minor;
-
-       return retcode;
-}
-
-/** No-op ioctl. */
-int drm_noop(struct drm_device *dev, void *data,
-            struct drm_file *file_priv)
-{
-       DRM_DEBUG("\n");
-       return 0;
-}
diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c
deleted file mode 100644 (file)
index 089c015..0000000
+++ /dev/null
@@ -1,462 +0,0 @@
-/**
- * \file drm_irq.c
- * IRQ support
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
- *
- * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-#include <linux/interrupt.h>   /* For task queue support */
-
-/**
- * Get interrupt from bus id.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_irq_busid structure.
- * \return zero on success or a negative number on failure.
- *
- * Finds the PCI device with the specified bus id and gets its IRQ number.
- * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
- * to that of the device that this DRM instance attached to.
- */
-int drm_irq_by_busid(struct drm_device *dev, void *data,
-                    struct drm_file *file_priv)
-{
-       struct drm_irq_busid *p = data;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
-               return -EINVAL;
-
-       if ((p->busnum >> 8) != drm_get_pci_domain(dev) ||
-           (p->busnum & 0xff) != dev->pdev->bus->number ||
-           p->devnum != PCI_SLOT(dev->pdev->devfn) || p->funcnum != PCI_FUNC(dev->pdev->devfn))
-               return -EINVAL;
-
-       p->irq = dev->irq;
-
-       DRM_DEBUG("%d:%d:%d => IRQ %d\n", p->busnum, p->devnum, p->funcnum,
-                 p->irq);
-
-       return 0;
-}
-
-/**
- * Install IRQ handler.
- *
- * \param dev DRM device.
- * \param irq IRQ number.
- *
- * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
- * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
- * before and after the installation.
- */
-static int drm_irq_install(struct drm_device * dev)
-{
-       int ret;
-       unsigned long sh_flags = 0;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
-               return -EINVAL;
-
-       if (dev->irq == 0)
-               return -EINVAL;
-
-       mutex_lock(&dev->struct_mutex);
-
-       /* Driver must have been initialized */
-       if (!dev->dev_private) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       if (dev->irq_enabled) {
-               mutex_unlock(&dev->struct_mutex);
-               return -EBUSY;
-       }
-       dev->irq_enabled = 1;
-       mutex_unlock(&dev->struct_mutex);
-
-       DRM_DEBUG("irq=%d\n", dev->irq);
-
-       if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) {
-               init_waitqueue_head(&dev->vbl_queue);
-
-               spin_lock_init(&dev->vbl_lock);
-
-               INIT_LIST_HEAD(&dev->vbl_sigs);
-               INIT_LIST_HEAD(&dev->vbl_sigs2);
-
-               dev->vbl_pending = 0;
-       }
-
-       /* Before installing handler */
-       dev->driver->irq_preinstall(dev);
-
-       /* Install handler */
-       if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
-               sh_flags = IRQF_SHARED;
-
-       ret = request_irq(dev->irq, dev->driver->irq_handler,
-                         sh_flags, dev->devname, dev);
-       if (ret < 0) {
-               mutex_lock(&dev->struct_mutex);
-               dev->irq_enabled = 0;
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       /* After installing handler */
-       dev->driver->irq_postinstall(dev);
-
-       return 0;
-}
-
-/**
- * Uninstall the IRQ handler.
- *
- * \param dev DRM device.
- *
- * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq.
- */
-int drm_irq_uninstall(struct drm_device * dev)
-{
-       int irq_enabled;
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
-               return -EINVAL;
-
-       mutex_lock(&dev->struct_mutex);
-       irq_enabled = dev->irq_enabled;
-       dev->irq_enabled = 0;
-       mutex_unlock(&dev->struct_mutex);
-
-       if (!irq_enabled)
-               return -EINVAL;
-
-       DRM_DEBUG("irq=%d\n", dev->irq);
-
-       dev->driver->irq_uninstall(dev);
-
-       free_irq(dev->irq, dev);
-
-       dev->locked_tasklet_func = NULL;
-
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_irq_uninstall);
-
-/**
- * IRQ control ioctl.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_control structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls irq_install() or irq_uninstall() according to \p arg.
- */
-int drm_control(struct drm_device *dev, void *data,
-               struct drm_file *file_priv)
-{
-       struct drm_control *ctl = data;
-
-       /* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */
-
-
-       switch (ctl->func) {
-       case DRM_INST_HANDLER:
-               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
-                       return 0;
-               if (dev->if_version < DRM_IF_VERSION(1, 2) &&
-                   ctl->irq != dev->irq)
-                       return -EINVAL;
-               return drm_irq_install(dev);
-       case DRM_UNINST_HANDLER:
-               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
-                       return 0;
-               return drm_irq_uninstall(dev);
-       default:
-               return -EINVAL;
-       }
-}
-
-/**
- * Wait for VBLANK.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param data user argument, pointing to a drm_wait_vblank structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the IRQ is installed.
- *
- * If a signal is requested checks if this task has already scheduled the same signal
- * for the same vblank sequence number - nothing to be done in
- * that case. If the number of tasks waiting for the interrupt exceeds 100 the
- * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
- * task.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       union drm_wait_vblank *vblwait = data;
-       struct timeval now;
-       int ret = 0;
-       unsigned int flags, seq;
-
-       if ((!dev->irq) || (!dev->irq_enabled))
-               return -EINVAL;
-
-       if (vblwait->request.type &
-           ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) {
-               DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n",
-                         vblwait->request.type,
-                         (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK));
-               return -EINVAL;
-       }
-
-       flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK;
-
-       if (!drm_core_check_feature(dev, (flags & _DRM_VBLANK_SECONDARY) ?
-                                   DRIVER_IRQ_VBL2 : DRIVER_IRQ_VBL))
-               return -EINVAL;
-
-       seq = atomic_read((flags & _DRM_VBLANK_SECONDARY) ? &dev->vbl_received2
-                         : &dev->vbl_received);
-
-       switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
-       case _DRM_VBLANK_RELATIVE:
-               vblwait->request.sequence += seq;
-               vblwait->request.type &= ~_DRM_VBLANK_RELATIVE;
-       case _DRM_VBLANK_ABSOLUTE:
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if ((flags & _DRM_VBLANK_NEXTONMISS) &&
-           (seq - vblwait->request.sequence) <= (1<<23)) {
-               vblwait->request.sequence = seq + 1;
-       }
-
-       if (flags & _DRM_VBLANK_SIGNAL) {
-               unsigned long irqflags;
-               struct list_head *vbl_sigs = (flags & _DRM_VBLANK_SECONDARY)
-                                     ? &dev->vbl_sigs2 : &dev->vbl_sigs;
-               struct drm_vbl_sig *vbl_sig;
-
-               spin_lock_irqsave(&dev->vbl_lock, irqflags);
-
-               /* Check if this task has already scheduled the same signal
-                * for the same vblank sequence number; nothing to be done in
-                * that case
-                */
-               list_for_each_entry(vbl_sig, vbl_sigs, head) {
-                       if (vbl_sig->sequence == vblwait->request.sequence
-                           && vbl_sig->info.si_signo ==
-                           vblwait->request.signal
-                           && vbl_sig->task == current) {
-                               spin_unlock_irqrestore(&dev->vbl_lock,
-                                                      irqflags);
-                               vblwait->reply.sequence = seq;
-                               goto done;
-                       }
-               }
-
-               if (dev->vbl_pending >= 100) {
-                       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
-                       return -EBUSY;
-               }
-
-               dev->vbl_pending++;
-
-               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
-
-               if (!
-                   (vbl_sig =
-                    drm_alloc(sizeof(struct drm_vbl_sig), DRM_MEM_DRIVER))) {
-                       return -ENOMEM;
-               }
-
-               memset((void *)vbl_sig, 0, sizeof(*vbl_sig));
-
-               vbl_sig->sequence = vblwait->request.sequence;
-               vbl_sig->info.si_signo = vblwait->request.signal;
-               vbl_sig->task = current;
-
-               spin_lock_irqsave(&dev->vbl_lock, irqflags);
-
-               list_add_tail(&vbl_sig->head, vbl_sigs);
-
-               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
-
-               vblwait->reply.sequence = seq;
-       } else {
-               if (flags & _DRM_VBLANK_SECONDARY) {
-                       if (dev->driver->vblank_wait2)
-                               ret = dev->driver->vblank_wait2(dev, &vblwait->request.sequence);
-               } else if (dev->driver->vblank_wait)
-                       ret =
-                           dev->driver->vblank_wait(dev,
-                                                    &vblwait->request.sequence);
-
-               do_gettimeofday(&now);
-               vblwait->reply.tval_sec = now.tv_sec;
-               vblwait->reply.tval_usec = now.tv_usec;
-       }
-
-      done:
-       return ret;
-}
-
-/**
- * Send the VBLANK signals.
- *
- * \param dev DRM device.
- *
- * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-void drm_vbl_send_signals(struct drm_device * dev)
-{
-       unsigned long flags;
-       int i;
-
-       spin_lock_irqsave(&dev->vbl_lock, flags);
-
-       for (i = 0; i < 2; i++) {
-               struct drm_vbl_sig *vbl_sig, *tmp;
-               struct list_head *vbl_sigs = i ? &dev->vbl_sigs2 : &dev->vbl_sigs;
-               unsigned int vbl_seq = atomic_read(i ? &dev->vbl_received2 :
-                                                  &dev->vbl_received);
-
-               list_for_each_entry_safe(vbl_sig, tmp, vbl_sigs, head) {
-                       if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
-                               vbl_sig->info.si_code = vbl_seq;
-                               send_sig_info(vbl_sig->info.si_signo,
-                                             &vbl_sig->info, vbl_sig->task);
-
-                               list_del(&vbl_sig->head);
-
-                               drm_free(vbl_sig, sizeof(*vbl_sig),
-                                        DRM_MEM_DRIVER);
-
-                               dev->vbl_pending--;
-                       }
-               }
-       }
-
-       spin_unlock_irqrestore(&dev->vbl_lock, flags);
-}
-
-EXPORT_SYMBOL(drm_vbl_send_signals);
-
-/**
- * Tasklet wrapper function.
- *
- * \param data DRM device in disguise.
- *
- * Attempts to grab the HW lock and calls the driver callback on success. On
- * failure, leave the lock marked as contended so the callback can be called
- * from drm_unlock().
- */
-static void drm_locked_tasklet_func(unsigned long data)
-{
-       struct drm_device *dev = (struct drm_device *)data;
-       unsigned long irqflags;
-
-       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
-
-       if (!dev->locked_tasklet_func ||
-           !drm_lock_take(&dev->lock,
-                          DRM_KERNEL_CONTEXT)) {
-               spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
-               return;
-       }
-
-       dev->lock.lock_time = jiffies;
-       atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
-
-       dev->locked_tasklet_func(dev);
-
-       drm_lock_free(&dev->lock,
-                     DRM_KERNEL_CONTEXT);
-
-       dev->locked_tasklet_func = NULL;
-
-       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
-}
-
-/**
- * Schedule a tasklet to call back a driver hook with the HW lock held.
- *
- * \param dev DRM device.
- * \param func Driver callback.
- *
- * This is intended for triggering actions that require the HW lock from an
- * interrupt handler. The lock will be grabbed ASAP after the interrupt handler
- * completes. Note that the callback may be called from interrupt or process
- * context, it must not make any assumptions about this. Also, the HW lock will
- * be held with the kernel context or any client context.
- */
-void drm_locked_tasklet(struct drm_device *dev, void (*func)(struct drm_device *))
-{
-       unsigned long irqflags;
-       static DECLARE_TASKLET(drm_tasklet, drm_locked_tasklet_func, 0);
-
-       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ) ||
-           test_bit(TASKLET_STATE_SCHED, &drm_tasklet.state))
-               return;
-
-       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
-
-       if (dev->locked_tasklet_func) {
-               spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
-               return;
-       }
-
-       dev->locked_tasklet_func = func;
-
-       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
-
-       drm_tasklet.data = (unsigned long)dev;
-
-       tasklet_hi_schedule(&drm_tasklet);
-}
-EXPORT_SYMBOL(drm_locked_tasklet);
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
deleted file mode 100644 (file)
index 0998723..0000000
+++ /dev/null
@@ -1,391 +0,0 @@
-/**
- * \file drm_lock.c
- * IOCTLs for locking
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-static int drm_notifier(void *priv);
-
-/**
- * Lock ioctl.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_lock structure.
- * \return zero on success or negative number on failure.
- *
- * Add the current task to the lock wait queue, and attempt to take to lock.
- */
-int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       DECLARE_WAITQUEUE(entry, current);
-       struct drm_lock *lock = data;
-       int ret = 0;
-
-       ++file_priv->lock_count;
-
-       if (lock->context == DRM_KERNEL_CONTEXT) {
-               DRM_ERROR("Process %d using kernel context %d\n",
-                         task_pid_nr(current), lock->context);
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
-                 lock->context, task_pid_nr(current),
-                 dev->lock.hw_lock->lock, lock->flags);
-
-       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE))
-               if (lock->context < 0)
-                       return -EINVAL;
-
-       add_wait_queue(&dev->lock.lock_queue, &entry);
-       spin_lock_bh(&dev->lock.spinlock);
-       dev->lock.user_waiters++;
-       spin_unlock_bh(&dev->lock.spinlock);
-       for (;;) {
-               __set_current_state(TASK_INTERRUPTIBLE);
-               if (!dev->lock.hw_lock) {
-                       /* Device has been unregistered */
-                       ret = -EINTR;
-                       break;
-               }
-               if (drm_lock_take(&dev->lock, lock->context)) {
-                       dev->lock.file_priv = file_priv;
-                       dev->lock.lock_time = jiffies;
-                       atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
-                       break;  /* Got lock */
-               }
-
-               /* Contention */
-               schedule();
-               if (signal_pending(current)) {
-                       ret = -ERESTARTSYS;
-                       break;
-               }
-       }
-       spin_lock_bh(&dev->lock.spinlock);
-       dev->lock.user_waiters--;
-       spin_unlock_bh(&dev->lock.spinlock);
-       __set_current_state(TASK_RUNNING);
-       remove_wait_queue(&dev->lock.lock_queue, &entry);
-
-       DRM_DEBUG("%d %s\n", lock->context,
-                 ret ? "interrupted" : "has lock");
-       if (ret) return ret;
-
-       sigemptyset(&dev->sigmask);
-       sigaddset(&dev->sigmask, SIGSTOP);
-       sigaddset(&dev->sigmask, SIGTSTP);
-       sigaddset(&dev->sigmask, SIGTTIN);
-       sigaddset(&dev->sigmask, SIGTTOU);
-       dev->sigdata.context = lock->context;
-       dev->sigdata.lock = dev->lock.hw_lock;
-       block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
-
-       if (dev->driver->dma_ready && (lock->flags & _DRM_LOCK_READY))
-               dev->driver->dma_ready(dev);
-
-       if (dev->driver->dma_quiescent && (lock->flags & _DRM_LOCK_QUIESCENT))
-       {
-               if (dev->driver->dma_quiescent(dev)) {
-                       DRM_DEBUG("%d waiting for DMA quiescent\n",
-                                 lock->context);
-                       return -EBUSY;
-               }
-       }
-
-       if (dev->driver->kernel_context_switch &&
-           dev->last_context != lock->context) {
-               dev->driver->kernel_context_switch(dev, dev->last_context,
-                                                  lock->context);
-       }
-
-       return 0;
-}
-
-/**
- * Unlock ioctl.
- *
- * \param inode device inode.
- * \param file_priv DRM file private.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_lock structure.
- * \return zero on success or negative number on failure.
- *
- * Transfer and free the lock.
- */
-int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_lock *lock = data;
-       unsigned long irqflags;
-
-       if (lock->context == DRM_KERNEL_CONTEXT) {
-               DRM_ERROR("Process %d using kernel context %d\n",
-                         task_pid_nr(current), lock->context);
-               return -EINVAL;
-       }
-
-       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
-
-       if (dev->locked_tasklet_func) {
-               dev->locked_tasklet_func(dev);
-
-               dev->locked_tasklet_func = NULL;
-       }
-
-       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
-
-       atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
-
-       /* kernel_context_switch isn't used by any of the x86 drm
-        * modules but is required by the Sparc driver.
-        */
-       if (dev->driver->kernel_context_switch_unlock)
-               dev->driver->kernel_context_switch_unlock(dev);
-       else {
-               if (drm_lock_free(&dev->lock,lock->context)) {
-                       /* FIXME: Should really bail out here. */
-               }
-       }
-
-       unblock_all_signals();
-       return 0;
-}
-
-/**
- * Take the heavyweight lock.
- *
- * \param lock lock pointer.
- * \param context locking context.
- * \return one if the lock is held, or zero otherwise.
- *
- * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
- */
-int drm_lock_take(struct drm_lock_data *lock_data,
-                 unsigned int context)
-{
-       unsigned int old, new, prev;
-       volatile unsigned int *lock = &lock_data->hw_lock->lock;
-
-       spin_lock_bh(&lock_data->spinlock);
-       do {
-               old = *lock;
-               if (old & _DRM_LOCK_HELD)
-                       new = old | _DRM_LOCK_CONT;
-               else {
-                       new = context | _DRM_LOCK_HELD |
-                               ((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
-                                _DRM_LOCK_CONT : 0);
-               }
-               prev = cmpxchg(lock, old, new);
-       } while (prev != old);
-       spin_unlock_bh(&lock_data->spinlock);
-
-       if (_DRM_LOCKING_CONTEXT(old) == context) {
-               if (old & _DRM_LOCK_HELD) {
-                       if (context != DRM_KERNEL_CONTEXT) {
-                               DRM_ERROR("%d holds heavyweight lock\n",
-                                         context);
-                       }
-                       return 0;
-               }
-       }
-
-       if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
-               /* Have lock */
-               return 1;
-       }
-       return 0;
-}
-
-/**
- * This takes a lock forcibly and hands it to context. Should ONLY be used
- * inside *_unlock to give lock to kernel before calling *_dma_schedule.
- *
- * \param dev DRM device.
- * \param lock lock pointer.
- * \param context locking context.
- * \return always one.
- *
- * Resets the lock file pointer.
- * Marks the lock as held by the given context, via the \p cmpxchg instruction.
- */
-static int drm_lock_transfer(struct drm_lock_data *lock_data,
-                            unsigned int context)
-{
-       unsigned int old, new, prev;
-       volatile unsigned int *lock = &lock_data->hw_lock->lock;
-
-       lock_data->file_priv = NULL;
-       do {
-               old = *lock;
-               new = context | _DRM_LOCK_HELD;
-               prev = cmpxchg(lock, old, new);
-       } while (prev != old);
-       return 1;
-}
-
-/**
- * Free lock.
- *
- * \param dev DRM device.
- * \param lock lock.
- * \param context context.
- *
- * Resets the lock file pointer.
- * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
- * waiting on the lock queue.
- */
-int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context)
-{
-       unsigned int old, new, prev;
-       volatile unsigned int *lock = &lock_data->hw_lock->lock;
-
-       spin_lock_bh(&lock_data->spinlock);
-       if (lock_data->kernel_waiters != 0) {
-               drm_lock_transfer(lock_data, 0);
-               lock_data->idle_has_lock = 1;
-               spin_unlock_bh(&lock_data->spinlock);
-               return 1;
-       }
-       spin_unlock_bh(&lock_data->spinlock);
-
-       do {
-               old = *lock;
-               new = _DRM_LOCKING_CONTEXT(old);
-               prev = cmpxchg(lock, old, new);
-       } while (prev != old);
-
-       if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
-               DRM_ERROR("%d freed heavyweight lock held by %d\n",
-                         context, _DRM_LOCKING_CONTEXT(old));
-               return 1;
-       }
-       wake_up_interruptible(&lock_data->lock_queue);
-       return 0;
-}
-
-/**
- * If we get here, it means that the process has called DRM_IOCTL_LOCK
- * without calling DRM_IOCTL_UNLOCK.
- *
- * If the lock is not held, then let the signal proceed as usual.  If the lock
- * is held, then set the contended flag and keep the signal blocked.
- *
- * \param priv pointer to a drm_sigdata structure.
- * \return one if the signal should be delivered normally, or zero if the
- * signal should be blocked.
- */
-static int drm_notifier(void *priv)
-{
-       struct drm_sigdata *s = (struct drm_sigdata *) priv;
-       unsigned int old, new, prev;
-
-       /* Allow signal delivery if lock isn't held */
-       if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
-           || _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context)
-               return 1;
-
-       /* Otherwise, set flag to force call to
-          drmUnlock */
-       do {
-               old = s->lock->lock;
-               new = old | _DRM_LOCK_CONT;
-               prev = cmpxchg(&s->lock->lock, old, new);
-       } while (prev != old);
-       return 0;
-}
-
-/**
- * This function returns immediately and takes the hw lock
- * with the kernel context if it is free, otherwise it gets the highest priority when and if
- * it is eventually released.
- *
- * This guarantees that the kernel will _eventually_ have the lock _unless_ it is held
- * by a blocked process. (In the latter case an explicit wait for the hardware lock would cause
- * a deadlock, which is why the "idlelock" was invented).
- *
- * This should be sufficient to wait for GPU idle without
- * having to worry about starvation.
- */
-
-void drm_idlelock_take(struct drm_lock_data *lock_data)
-{
-       int ret = 0;
-
-       spin_lock_bh(&lock_data->spinlock);
-       lock_data->kernel_waiters++;
-       if (!lock_data->idle_has_lock) {
-
-               spin_unlock_bh(&lock_data->spinlock);
-               ret = drm_lock_take(lock_data, DRM_KERNEL_CONTEXT);
-               spin_lock_bh(&lock_data->spinlock);
-
-               if (ret == 1)
-                       lock_data->idle_has_lock = 1;
-       }
-       spin_unlock_bh(&lock_data->spinlock);
-}
-EXPORT_SYMBOL(drm_idlelock_take);
-
-void drm_idlelock_release(struct drm_lock_data *lock_data)
-{
-       unsigned int old, prev;
-       volatile unsigned int *lock = &lock_data->hw_lock->lock;
-
-       spin_lock_bh(&lock_data->spinlock);
-       if (--lock_data->kernel_waiters == 0) {
-               if (lock_data->idle_has_lock) {
-                       do {
-                               old = *lock;
-                               prev = cmpxchg(lock, old, DRM_KERNEL_CONTEXT);
-                       } while (prev != old);
-                       wake_up_interruptible(&lock_data->lock_queue);
-                       lock_data->idle_has_lock = 0;
-               }
-       }
-       spin_unlock_bh(&lock_data->spinlock);
-}
-EXPORT_SYMBOL(drm_idlelock_release);
-
-
-int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv)
-{
-       return (file_priv->lock_count && dev->lock.hw_lock &&
-               _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
-               dev->lock.file_priv == file_priv);
-}
-
-EXPORT_SYMBOL(drm_i_have_hw_lock);
diff --git a/drivers/char/drm/drm_memory.c b/drivers/char/drm/drm_memory.c
deleted file mode 100644 (file)
index 845081b..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * \file drm_memory.c
- * Memory management wrappers for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/highmem.h>
-#include "drmP.h"
-
-#ifdef DEBUG_MEMORY
-#include "drm_memory_debug.h"
-#else
-
-/** No-op. */
-void drm_mem_init(void)
-{
-}
-
-/**
- * Called when "/proc/dri/%dev%/mem" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param len requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- *
- * No-op.
- */
-int drm_mem_info(char *buf, char **start, off_t offset,
-                int len, int *eof, void *data)
-{
-       return 0;
-}
-
-/** Wrapper around kmalloc() and kfree() */
-void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
-{
-       void *pt;
-
-       if (!(pt = kmalloc(size, GFP_KERNEL)))
-               return NULL;
-       if (oldpt && oldsize) {
-               memcpy(pt, oldpt, oldsize);
-               kfree(oldpt);
-       }
-       return pt;
-}
-
-#if __OS_HAS_AGP
-static void *agp_remap(unsigned long offset, unsigned long size,
-                      struct drm_device * dev)
-{
-       unsigned long *phys_addr_map, i, num_pages =
-           PAGE_ALIGN(size) / PAGE_SIZE;
-       struct drm_agp_mem *agpmem;
-       struct page **page_map;
-       void *addr;
-
-       size = PAGE_ALIGN(size);
-
-#ifdef __alpha__
-       offset -= dev->hose->mem_space->start;
-#endif
-
-       list_for_each_entry(agpmem, &dev->agp->memory, head)
-               if (agpmem->bound <= offset
-                   && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
-                   (offset + size))
-                       break;
-       if (!agpmem)
-               return NULL;
-
-       /*
-        * OK, we're mapping AGP space on a chipset/platform on which memory accesses by
-        * the CPU do not get remapped by the GART.  We fix this by using the kernel's
-        * page-table instead (that's probably faster anyhow...).
-        */
-       /* note: use vmalloc() because num_pages could be large... */
-       page_map = vmalloc(num_pages * sizeof(struct page *));
-       if (!page_map)
-               return NULL;
-
-       phys_addr_map =
-           agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
-       for (i = 0; i < num_pages; ++i)
-               page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
-       addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
-       vfree(page_map);
-
-       return addr;
-}
-
-/** Wrapper around agp_allocate_memory() */
-DRM_AGP_MEM *drm_alloc_agp(struct drm_device * dev, int pages, u32 type)
-{
-       return drm_agp_allocate_memory(dev->agp->bridge, pages, type);
-}
-
-/** Wrapper around agp_free_memory() */
-int drm_free_agp(DRM_AGP_MEM * handle, int pages)
-{
-       return drm_agp_free_memory(handle) ? 0 : -EINVAL;
-}
-
-/** Wrapper around agp_bind_memory() */
-int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
-{
-       return drm_agp_bind_memory(handle, start);
-}
-
-/** Wrapper around agp_unbind_memory() */
-int drm_unbind_agp(DRM_AGP_MEM * handle)
-{
-       return drm_agp_unbind_memory(handle);
-}
-
-#else  /*  __OS_HAS_AGP  */
-static inline void *agp_remap(unsigned long offset, unsigned long size,
-                             struct drm_device * dev)
-{
-       return NULL;
-}
-
-#endif                         /* agp */
-
-#endif                         /* debug_memory */
-
-void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
-{
-       if (drm_core_has_AGP(dev) &&
-           dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
-               map->handle = agp_remap(map->offset, map->size, dev);
-       else
-               map->handle = ioremap(map->offset, map->size);
-}
-EXPORT_SYMBOL(drm_core_ioremap);
-
-void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
-{
-       if (!map->handle || !map->size)
-               return;
-
-       if (drm_core_has_AGP(dev) &&
-           dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
-               vunmap(map->handle);
-       else
-               iounmap(map->handle);
-}
-EXPORT_SYMBOL(drm_core_ioremapfree);
diff --git a/drivers/char/drm/drm_memory.h b/drivers/char/drm/drm_memory.h
deleted file mode 100644 (file)
index 63e425b..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * \file drm_memory.h
- * Memory management wrappers for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/highmem.h>
-#include <linux/vmalloc.h>
-#include "drmP.h"
-
-/**
- * Cut down version of drm_memory_debug.h, which used to be called
- * drm_memory.h.
- */
-
-#if __OS_HAS_AGP
-
-#include <linux/vmalloc.h>
-
-#ifdef HAVE_PAGE_AGP
-#include <asm/agp.h>
-#else
-# ifdef __powerpc__
-#  define PAGE_AGP     __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
-# else
-#  define PAGE_AGP     PAGE_KERNEL
-# endif
-#endif
-
-#else                          /* __OS_HAS_AGP */
-
-#endif
diff --git a/drivers/char/drm/drm_memory_debug.h b/drivers/char/drm/drm_memory_debug.h
deleted file mode 100644 (file)
index 6463271..0000000
+++ /dev/null
@@ -1,309 +0,0 @@
-/**
- * \file drm_memory_debug.h
- * Memory management wrappers for DRM.
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-typedef struct drm_mem_stats {
-       const char *name;
-       int succeed_count;
-       int free_count;
-       int fail_count;
-       unsigned long bytes_allocated;
-       unsigned long bytes_freed;
-} drm_mem_stats_t;
-
-static DEFINE_SPINLOCK(drm_mem_lock);
-static unsigned long drm_ram_available = 0;    /* In pages */
-static unsigned long drm_ram_used = 0;
-static drm_mem_stats_t drm_mem_stats[] =
-{
-       [DRM_MEM_DMA] = {"dmabufs"},
-       [DRM_MEM_SAREA] = {"sareas"},
-       [DRM_MEM_DRIVER] = {"driver"},
-       [DRM_MEM_MAGIC] = {"magic"},
-       [DRM_MEM_IOCTLS] = {"ioctltab"},
-       [DRM_MEM_MAPS] = {"maplist"},
-       [DRM_MEM_VMAS] = {"vmalist"},
-       [DRM_MEM_BUFS] = {"buflist"},
-       [DRM_MEM_SEGS] = {"seglist"},
-       [DRM_MEM_PAGES] = {"pagelist"},
-       [DRM_MEM_FILES] = {"files"},
-       [DRM_MEM_QUEUES] = {"queues"},
-       [DRM_MEM_CMDS] = {"commands"},
-       [DRM_MEM_MAPPINGS] = {"mappings"},
-       [DRM_MEM_BUFLISTS] = {"buflists"},
-       [DRM_MEM_AGPLISTS] = {"agplist"},
-       [DRM_MEM_SGLISTS] = {"sglist"},
-       [DRM_MEM_TOTALAGP] = {"totalagp"},
-       [DRM_MEM_BOUNDAGP] = {"boundagp"},
-       [DRM_MEM_CTXBITMAP] = {"ctxbitmap"},
-       [DRM_MEM_CTXLIST] = {"ctxlist"},
-       [DRM_MEM_STUB] = {"stub"},
-       {NULL, 0,}              /* Last entry must be null */
-};
-
-void drm_mem_init (void) {
-       drm_mem_stats_t *mem;
-       struct sysinfo si;
-
-       for (mem = drm_mem_stats; mem->name; ++mem) {
-               mem->succeed_count = 0;
-               mem->free_count = 0;
-               mem->fail_count = 0;
-               mem->bytes_allocated = 0;
-               mem->bytes_freed = 0;
-       }
-
-       si_meminfo(&si);
-       drm_ram_available = si.totalram;
-       drm_ram_used = 0;
-}
-
-/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
-
-static int drm__mem_info (char *buf, char **start, off_t offset,
-                          int request, int *eof, void *data) {
-       drm_mem_stats_t *pt;
-       int len = 0;
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *eof = 0;
-       *start = &buf[offset];
-
-       DRM_PROC_PRINT("                  total counts                  "
-                      " |    outstanding  \n");
-       DRM_PROC_PRINT("type       alloc freed fail     bytes      freed"
-                      " | allocs      bytes\n\n");
-       DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB         |\n",
-                      "system", 0, 0, 0,
-                      drm_ram_available << (PAGE_SHIFT - 10));
-       DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB         |\n",
-                      "locked", 0, 0, 0, drm_ram_used >> 10);
-       DRM_PROC_PRINT("\n");
-       for (pt = drm_mem_stats; pt->name; pt++) {
-               DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
-                              pt->name,
-                              pt->succeed_count,
-                              pt->free_count,
-                              pt->fail_count,
-                              pt->bytes_allocated,
-                              pt->bytes_freed,
-                              pt->succeed_count - pt->free_count,
-                              (long)pt->bytes_allocated
-                              - (long)pt->bytes_freed);
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-int drm_mem_info (char *buf, char **start, off_t offset,
-                  int len, int *eof, void *data) {
-       int ret;
-
-       spin_lock(&drm_mem_lock);
-       ret = drm__mem_info (buf, start, offset, len, eof, data);
-       spin_unlock(&drm_mem_lock);
-       return ret;
-}
-
-void *drm_alloc (size_t size, int area) {
-       void *pt;
-
-       if (!size) {
-               DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
-               return NULL;
-       }
-
-       if (!(pt = kmalloc(size, GFP_KERNEL))) {
-               spin_lock(&drm_mem_lock);
-               ++drm_mem_stats[area].fail_count;
-               spin_unlock(&drm_mem_lock);
-               return NULL;
-       }
-       spin_lock(&drm_mem_lock);
-       ++drm_mem_stats[area].succeed_count;
-       drm_mem_stats[area].bytes_allocated += size;
-       spin_unlock(&drm_mem_lock);
-       return pt;
-}
-
-void *drm_calloc (size_t nmemb, size_t size, int area) {
-       void *addr;
-
-       addr = drm_alloc (nmemb * size, area);
-       if (addr != NULL)
-               memset((void *)addr, 0, size * nmemb);
-
-       return addr;
-}
-
-void *drm_realloc (void *oldpt, size_t oldsize, size_t size, int area) {
-       void *pt;
-
-       if (!(pt = drm_alloc (size, area)))
-               return NULL;
-       if (oldpt && oldsize) {
-               memcpy(pt, oldpt, oldsize);
-               drm_free (oldpt, oldsize, area);
-       }
-       return pt;
-}
-
-void drm_free (void *pt, size_t size, int area) {
-       int alloc_count;
-       int free_count;
-
-       if (!pt)
-               DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
-       else
-               kfree(pt);
-       spin_lock(&drm_mem_lock);
-       drm_mem_stats[area].bytes_freed += size;
-       free_count = ++drm_mem_stats[area].free_count;
-       alloc_count = drm_mem_stats[area].succeed_count;
-       spin_unlock(&drm_mem_lock);
-       if (free_count > alloc_count) {
-               DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
-                             free_count, alloc_count);
-       }
-}
-
-#if __OS_HAS_AGP
-
-DRM_AGP_MEM *drm_alloc_agp (drm_device_t *dev, int pages, u32 type) {
-       DRM_AGP_MEM *handle;
-
-       if (!pages) {
-               DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
-               return NULL;
-       }
-
-       if ((handle = drm_agp_allocate_memory (pages, type))) {
-               spin_lock(&drm_mem_lock);
-               ++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
-               drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated
-                   += pages << PAGE_SHIFT;
-               spin_unlock(&drm_mem_lock);
-               return handle;
-       }
-       spin_lock(&drm_mem_lock);
-       ++drm_mem_stats[DRM_MEM_TOTALAGP].fail_count;
-       spin_unlock(&drm_mem_lock);
-       return NULL;
-}
-
-int drm_free_agp (DRM_AGP_MEM * handle, int pages) {
-       int alloc_count;
-       int free_count;
-       int retval = -EINVAL;
-
-       if (!handle) {
-               DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
-                             "Attempt to free NULL AGP handle\n");
-               return retval;
-       }
-
-       if (drm_agp_free_memory (handle)) {
-               spin_lock(&drm_mem_lock);
-               free_count = ++drm_mem_stats[DRM_MEM_TOTALAGP].free_count;
-               alloc_count = drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
-               drm_mem_stats[DRM_MEM_TOTALAGP].bytes_freed
-                   += pages << PAGE_SHIFT;
-               spin_unlock(&drm_mem_lock);
-               if (free_count > alloc_count) {
-                       DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
-                                     "Excess frees: %d frees, %d allocs\n",
-                                     free_count, alloc_count);
-               }
-               return 0;
-       }
-       return retval;
-}
-
-int drm_bind_agp (DRM_AGP_MEM * handle, unsigned int start) {
-       int retcode = -EINVAL;
-
-       if (!handle) {
-               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-                             "Attempt to bind NULL AGP handle\n");
-               return retcode;
-       }
-
-       if (!(retcode = drm_agp_bind_memory (handle, start))) {
-               spin_lock(&drm_mem_lock);
-               ++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
-               drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated
-                   += handle->page_count << PAGE_SHIFT;
-               spin_unlock(&drm_mem_lock);
-               return retcode;
-       }
-       spin_lock(&drm_mem_lock);
-       ++drm_mem_stats[DRM_MEM_BOUNDAGP].fail_count;
-       spin_unlock(&drm_mem_lock);
-       return retcode;
-}
-
-int drm_unbind_agp (DRM_AGP_MEM * handle) {
-       int alloc_count;
-       int free_count;
-       int retcode = -EINVAL;
-
-       if (!handle) {
-               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-                             "Attempt to unbind NULL AGP handle\n");
-               return retcode;
-       }
-
-       if ((retcode = drm_agp_unbind_memory (handle)))
-               return retcode;
-       spin_lock(&drm_mem_lock);
-       free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count;
-       alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
-       drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_freed
-           += handle->page_count << PAGE_SHIFT;
-       spin_unlock(&drm_mem_lock);
-       if (free_count > alloc_count) {
-               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-                             "Excess frees: %d frees, %d allocs\n",
-                             free_count, alloc_count);
-       }
-       return retcode;
-}
-#endif
diff --git a/drivers/char/drm/drm_mm.c b/drivers/char/drm/drm_mm.c
deleted file mode 100644 (file)
index dcff9e9..0000000
+++ /dev/null
@@ -1,295 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- **************************************************************************/
-
-/*
- * Generic simple memory manager implementation. Intended to be used as a base
- * class implementation for more advanced memory managers.
- *
- * Note that the algorithm used is quite simple and there might be substantial
- * performance gains if a smarter free list is implemented. Currently it is just an
- * unordered stack of free regions. This could easily be improved if an RB-tree
- * is used instead. At least if we expect heavy fragmentation.
- *
- * Aligned allocations can also see improvement.
- *
- * Authors:
- * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include <linux/slab.h>
-
-unsigned long drm_mm_tail_space(struct drm_mm *mm)
-{
-       struct list_head *tail_node;
-       struct drm_mm_node *entry;
-
-       tail_node = mm->ml_entry.prev;
-       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
-       if (!entry->free)
-               return 0;
-
-       return entry->size;
-}
-
-int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size)
-{
-       struct list_head *tail_node;
-       struct drm_mm_node *entry;
-
-       tail_node = mm->ml_entry.prev;
-       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
-       if (!entry->free)
-               return -ENOMEM;
-
-       if (entry->size <= size)
-               return -ENOMEM;
-
-       entry->size -= size;
-       return 0;
-}
-
-
-static int drm_mm_create_tail_node(struct drm_mm *mm,
-                           unsigned long start,
-                           unsigned long size)
-{
-       struct drm_mm_node *child;
-
-       child = (struct drm_mm_node *)
-               drm_alloc(sizeof(*child), DRM_MEM_MM);
-       if (!child)
-               return -ENOMEM;
-
-       child->free = 1;
-       child->size = size;
-       child->start = start;
-       child->mm = mm;
-
-       list_add_tail(&child->ml_entry, &mm->ml_entry);
-       list_add_tail(&child->fl_entry, &mm->fl_entry);
-
-       return 0;
-}
-
-
-int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size)
-{
-       struct list_head *tail_node;
-       struct drm_mm_node *entry;
-
-       tail_node = mm->ml_entry.prev;
-       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
-       if (!entry->free) {
-               return drm_mm_create_tail_node(mm, entry->start + entry->size, size);
-       }
-       entry->size += size;
-       return 0;
-}
-
-static struct drm_mm_node *drm_mm_split_at_start(struct drm_mm_node *parent,
-                                           unsigned long size)
-{
-       struct drm_mm_node *child;
-
-       child = (struct drm_mm_node *)
-               drm_alloc(sizeof(*child), DRM_MEM_MM);
-       if (!child)
-               return NULL;
-
-       INIT_LIST_HEAD(&child->fl_entry);
-
-       child->free = 0;
-       child->size = size;
-       child->start = parent->start;
-       child->mm = parent->mm;
-
-       list_add_tail(&child->ml_entry, &parent->ml_entry);
-       INIT_LIST_HEAD(&child->fl_entry);
-
-       parent->size -= size;
-       parent->start += size;
-       return child;
-}
-
-
-
-struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
-                               unsigned long size, unsigned alignment)
-{
-
-       struct drm_mm_node *align_splitoff = NULL;
-       struct drm_mm_node *child;
-       unsigned tmp = 0;
-
-       if (alignment)
-               tmp = parent->start % alignment;
-
-       if (tmp) {
-               align_splitoff = drm_mm_split_at_start(parent, alignment - tmp);
-               if (!align_splitoff)
-                       return NULL;
-       }
-
-       if (parent->size == size) {
-               list_del_init(&parent->fl_entry);
-               parent->free = 0;
-               return parent;
-       } else {
-               child = drm_mm_split_at_start(parent, size);
-       }
-
-       if (align_splitoff)
-               drm_mm_put_block(align_splitoff);
-
-       return child;
-}
-
-/*
- * Put a block. Merge with the previous and / or next block if they are free.
- * Otherwise add to the free stack.
- */
-
-void drm_mm_put_block(struct drm_mm_node * cur)
-{
-
-       struct drm_mm *mm = cur->mm;
-       struct list_head *cur_head = &cur->ml_entry;
-       struct list_head *root_head = &mm->ml_entry;
-       struct drm_mm_node *prev_node = NULL;
-       struct drm_mm_node *next_node;
-
-       int merged = 0;
-
-       if (cur_head->prev != root_head) {
-               prev_node = list_entry(cur_head->prev, struct drm_mm_node, ml_entry);
-               if (prev_node->free) {
-                       prev_node->size += cur->size;
-                       merged = 1;
-               }
-       }
-       if (cur_head->next != root_head) {
-               next_node = list_entry(cur_head->next, struct drm_mm_node, ml_entry);
-               if (next_node->free) {
-                       if (merged) {
-                               prev_node->size += next_node->size;
-                               list_del(&next_node->ml_entry);
-                               list_del(&next_node->fl_entry);
-                               drm_free(next_node, sizeof(*next_node),
-                                        DRM_MEM_MM);
-                       } else {
-                               next_node->size += cur->size;
-                               next_node->start = cur->start;
-                               merged = 1;
-                       }
-               }
-       }
-       if (!merged) {
-               cur->free = 1;
-               list_add(&cur->fl_entry, &mm->fl_entry);
-       } else {
-               list_del(&cur->ml_entry);
-               drm_free(cur, sizeof(*cur), DRM_MEM_MM);
-       }
-}
-
-struct drm_mm_node *drm_mm_search_free(const struct drm_mm * mm,
-                                 unsigned long size,
-                                 unsigned alignment, int best_match)
-{
-       struct list_head *list;
-       const struct list_head *free_stack = &mm->fl_entry;
-       struct drm_mm_node *entry;
-       struct drm_mm_node *best;
-       unsigned long best_size;
-       unsigned wasted;
-
-       best = NULL;
-       best_size = ~0UL;
-
-       list_for_each(list, free_stack) {
-               entry = list_entry(list, struct drm_mm_node, fl_entry);
-               wasted = 0;
-
-               if (entry->size < size)
-                       continue;
-
-               if (alignment) {
-                       register unsigned tmp = entry->start % alignment;
-                       if (tmp)
-                               wasted += alignment - tmp;
-               }
-
-
-               if (entry->size >= size + wasted) {
-                       if (!best_match)
-                               return entry;
-                       if (size < best_size) {
-                               best = entry;
-                               best_size = entry->size;
-                       }
-               }
-       }
-
-       return best;
-}
-
-int drm_mm_clean(struct drm_mm * mm)
-{
-       struct list_head *head = &mm->ml_entry;
-
-       return (head->next->next == head);
-}
-
-int drm_mm_init(struct drm_mm * mm, unsigned long start, unsigned long size)
-{
-       INIT_LIST_HEAD(&mm->ml_entry);
-       INIT_LIST_HEAD(&mm->fl_entry);
-
-       return drm_mm_create_tail_node(mm, start, size);
-}
-
-
-void drm_mm_takedown(struct drm_mm * mm)
-{
-       struct list_head *bnode = mm->fl_entry.next;
-       struct drm_mm_node *entry;
-
-       entry = list_entry(bnode, struct drm_mm_node, fl_entry);
-
-       if (entry->ml_entry.next != &mm->ml_entry ||
-           entry->fl_entry.next != &mm->fl_entry) {
-               DRM_ERROR("Memory manager not clean. Delaying takedown\n");
-               return;
-       }
-
-       list_del(&entry->fl_entry);
-       list_del(&entry->ml_entry);
-
-       drm_free(entry, sizeof(*entry), DRM_MEM_MM);
-}
diff --git a/drivers/char/drm/drm_os_linux.h b/drivers/char/drm/drm_os_linux.h
deleted file mode 100644 (file)
index 8dbd257..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * \file drm_os_linux.h
- * OS abstraction macros.
- */
-
-#include <linux/interrupt.h>   /* For task queue support */
-#include <linux/delay.h>
-
-/** Current process ID */
-#define DRM_CURRENTPID                 task_pid_nr(current)
-#define DRM_SUSER(p)                   capable(CAP_SYS_ADMIN)
-#define DRM_UDELAY(d)                  udelay(d)
-/** Read a byte from a MMIO region */
-#define DRM_READ8(map, offset)         readb(((void __iomem *)(map)->handle) + (offset))
-/** Read a word from a MMIO region */
-#define DRM_READ16(map, offset)         readw(((void __iomem *)(map)->handle) + (offset))
-/** Read a dword from a MMIO region */
-#define DRM_READ32(map, offset)                readl(((void __iomem *)(map)->handle) + (offset))
-/** Write a byte into a MMIO region */
-#define DRM_WRITE8(map, offset, val)   writeb(val, ((void __iomem *)(map)->handle) + (offset))
-/** Write a word into a MMIO region */
-#define DRM_WRITE16(map, offset, val)   writew(val, ((void __iomem *)(map)->handle) + (offset))
-/** Write a dword into a MMIO region */
-#define DRM_WRITE32(map, offset, val)  writel(val, ((void __iomem *)(map)->handle) + (offset))
-/** Read memory barrier */
-#define DRM_READMEMORYBARRIER()                rmb()
-/** Write memory barrier */
-#define DRM_WRITEMEMORYBARRIER()       wmb()
-/** Read/write memory barrier */
-#define DRM_MEMORYBARRIER()            mb()
-
-/** IRQ handler arguments and return type and values */
-#define DRM_IRQ_ARGS           int irq, void *arg
-
-/** AGP types */
-#if __OS_HAS_AGP
-#define DRM_AGP_MEM            struct agp_memory
-#define DRM_AGP_KERN           struct agp_kern_info
-#else
-/* define some dummy types for non AGP supporting kernels */
-struct no_agp_kern {
-       unsigned long aper_base;
-       unsigned long aper_size;
-};
-#define DRM_AGP_MEM             int
-#define DRM_AGP_KERN            struct no_agp_kern
-#endif
-
-#if !(__OS_HAS_MTRR)
-static __inline__ int mtrr_add(unsigned long base, unsigned long size,
-                              unsigned int type, char increment)
-{
-       return -ENODEV;
-}
-
-static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
-{
-       return -ENODEV;
-}
-
-#define MTRR_TYPE_WRCOMB     1
-
-#endif
-
-/** Other copying of data to kernel space */
-#define DRM_COPY_FROM_USER(arg1, arg2, arg3)           \
-       copy_from_user(arg1, arg2, arg3)
-/** Other copying of data from kernel space */
-#define DRM_COPY_TO_USER(arg1, arg2, arg3)             \
-       copy_to_user(arg1, arg2, arg3)
-/* Macros for copyfrom user, but checking readability only once */
-#define DRM_VERIFYAREA_READ( uaddr, size )             \
-       (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
-#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
-       __copy_from_user(arg1, arg2, arg3)
-#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)   \
-       __copy_to_user(arg1, arg2, arg3)
-#define DRM_GET_USER_UNCHECKED(val, uaddr)             \
-       __get_user(val, uaddr)
-
-#define DRM_HZ HZ
-
-#define DRM_WAIT_ON( ret, queue, timeout, condition )          \
-do {                                                           \
-       DECLARE_WAITQUEUE(entry, current);                      \
-       unsigned long end = jiffies + (timeout);                \
-       add_wait_queue(&(queue), &entry);                       \
-                                                               \
-       for (;;) {                                              \
-               __set_current_state(TASK_INTERRUPTIBLE);        \
-               if (condition)                                  \
-                       break;                                  \
-               if (time_after_eq(jiffies, end)) {              \
-                       ret = -EBUSY;                           \
-                       break;                                  \
-               }                                               \
-               schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
-               if (signal_pending(current)) {                  \
-                       ret = -EINTR;                           \
-                       break;                                  \
-               }                                               \
-       }                                                       \
-       __set_current_state(TASK_RUNNING);                      \
-       remove_wait_queue(&(queue), &entry);                    \
-} while (0)
-
-#define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
-#define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
diff --git a/drivers/char/drm/drm_pci.c b/drivers/char/drm/drm_pci.c
deleted file mode 100644 (file)
index b55d5bc..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/* drm_pci.h -- PCI DMA memory management wrappers for DRM -*- linux-c -*- */
-/**
- * \file drm_pci.c
- * \brief Functions and ioctls to manage PCI memory
- *
- * \warning These interfaces aren't stable yet.
- *
- * \todo Implement the remaining ioctl's for the PCI pools.
- * \todo The wrappers here are so thin that they would be better off inlined..
- *
- * \author José Fonseca <jrfonseca@tungstengraphics.com>
- * \author Leif Delgass <ldelgass@retinalburn.net>
- */
-
-/*
- * Copyright 2003 José Fonseca.
- * Copyright 2003 Leif Delgass.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
- * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/pci.h>
-#include <linux/dma-mapping.h>
-#include "drmP.h"
-
-/**********************************************************************/
-/** \name PCI memory */
-/*@{*/
-
-/**
- * \brief Allocate a PCI consistent memory block, for DMA.
- */
-drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align,
-                               dma_addr_t maxaddr)
-{
-       drm_dma_handle_t *dmah;
-#if 1
-       unsigned long addr;
-       size_t sz;
-#endif
-#ifdef DRM_DEBUG_MEMORY
-       int area = DRM_MEM_DMA;
-
-       spin_lock(&drm_mem_lock);
-       if ((drm_ram_used >> PAGE_SHIFT)
-           > (DRM_RAM_PERCENT * drm_ram_available) / 100) {
-               spin_unlock(&drm_mem_lock);
-               return 0;
-       }
-       spin_unlock(&drm_mem_lock);
-#endif
-
-       /* pci_alloc_consistent only guarantees alignment to the smallest
-        * PAGE_SIZE order which is greater than or equal to the requested size.
-        * Return NULL here for now to make sure nobody tries for larger alignment
-        */
-       if (align > size)
-               return NULL;
-
-       if (pci_set_dma_mask(dev->pdev, maxaddr) != 0) {
-               DRM_ERROR("Setting pci dma mask failed\n");
-               return NULL;
-       }
-
-       dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
-       if (!dmah)
-               return NULL;
-
-       dmah->size = size;
-       dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size, &dmah->busaddr, GFP_KERNEL | __GFP_COMP);
-
-#ifdef DRM_DEBUG_MEMORY
-       if (dmah->vaddr == NULL) {
-               spin_lock(&drm_mem_lock);
-               ++drm_mem_stats[area].fail_count;
-               spin_unlock(&drm_mem_lock);
-               kfree(dmah);
-               return NULL;
-       }
-
-       spin_lock(&drm_mem_lock);
-       ++drm_mem_stats[area].succeed_count;
-       drm_mem_stats[area].bytes_allocated += size;
-       drm_ram_used += size;
-       spin_unlock(&drm_mem_lock);
-#else
-       if (dmah->vaddr == NULL) {
-               kfree(dmah);
-               return NULL;
-       }
-#endif
-
-       memset(dmah->vaddr, 0, size);
-
-       /* XXX - Is virt_to_page() legal for consistent mem? */
-       /* Reserve */
-       for (addr = (unsigned long)dmah->vaddr, sz = size;
-            sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
-               SetPageReserved(virt_to_page(addr));
-       }
-
-       return dmah;
-}
-
-EXPORT_SYMBOL(drm_pci_alloc);
-
-/**
- * \brief Free a PCI consistent memory block without freeing its descriptor.
- *
- * This function is for internal use in the Linux-specific DRM core code.
- */
-void __drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
-{
-#if 1
-       unsigned long addr;
-       size_t sz;
-#endif
-#ifdef DRM_DEBUG_MEMORY
-       int area = DRM_MEM_DMA;
-       int alloc_count;
-       int free_count;
-#endif
-
-       if (!dmah->vaddr) {
-#ifdef DRM_DEBUG_MEMORY
-               DRM_MEM_ERROR(area, "Attempt to free address 0\n");
-#endif
-       } else {
-               /* XXX - Is virt_to_page() legal for consistent mem? */
-               /* Unreserve */
-               for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
-                    sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
-                       ClearPageReserved(virt_to_page(addr));
-               }
-               dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
-                                 dmah->busaddr);
-       }
-
-#ifdef DRM_DEBUG_MEMORY
-       spin_lock(&drm_mem_lock);
-       free_count = ++drm_mem_stats[area].free_count;
-       alloc_count = drm_mem_stats[area].succeed_count;
-       drm_mem_stats[area].bytes_freed += size;
-       drm_ram_used -= size;
-       spin_unlock(&drm_mem_lock);
-       if (free_count > alloc_count) {
-               DRM_MEM_ERROR(area,
-                             "Excess frees: %d frees, %d allocs\n",
-                             free_count, alloc_count);
-       }
-#endif
-
-}
-
-/**
- * \brief Free a PCI consistent memory block
- */
-void drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
-{
-       __drm_pci_free(dev, dmah);
-       kfree(dmah);
-}
-
-EXPORT_SYMBOL(drm_pci_free);
-
-/*@}*/
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
deleted file mode 100644 (file)
index 135bd19..0000000
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
-   This file is auto-generated from the drm_pciids.txt in the DRM CVS
-   Please contact dri-devel@lists.sf.net to add new cards to this list
-*/
-#define radeon_PCI_IDS \
-       {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \
-       {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
-       {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x414A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x414B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
-       {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
-       {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
-       {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
-       {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
-       {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
-       {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4E47, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
-       {0x1002, 0x4E48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
-       {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
-       {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
-       {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
-       {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
-       {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
-       {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
-       {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
-       {0x1002, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
-       {0x1002, 0x5158, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
-       {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
-       {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
-       {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
-       {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5657, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \
-       {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5954, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5955, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5974, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
-       {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
-       {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
-       {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
-       {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
-       {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
-       {0x1002, 0x5a61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5a62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
-       {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
-       {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x710A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x710B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x710C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x710E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x710F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7143, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x714F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x715E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x715F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7181, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7183, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7186, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7187, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7188, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x718A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x718B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x718C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x718D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x718F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7193, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7196, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x719B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x719F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71C7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71CD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71CE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71D2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71D4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71D5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71D6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x71DE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7210, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7244, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7245, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7247, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7248, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7249, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x724F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7280, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7281, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7283, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7284, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7287, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7289, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x728B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x728C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7290, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7291, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7293, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7297, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
-       {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
-       {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
-       {0, 0, 0}
-
-#define r128_PCI_IDS \
-       {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4d46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5041, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5043, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5044, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5045, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5046, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5047, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5048, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5049, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x504F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5054, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5245, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5247, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x524b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x524c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x534d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define mga_PCI_IDS \
-       {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
-       {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
-       {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
-       {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
-       {0, 0, 0}
-
-#define mach64_PCI_IDS \
-       {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4750, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4751, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4742, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4744, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c42, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x474c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x474f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4752, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4753, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x474d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x474e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define sisdrv_PCI_IDS \
-       {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1039, 0x6330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
-       {0x1039, 0x6351, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
-       {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
-       {0, 0, 0}
-
-#define tdfx_PCI_IDS \
-       {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x121a, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x121a, 0x0005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define viadrv_PCI_IDS \
-       {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x3118, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
-       {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x3344, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
-       {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
-       {0, 0, 0}
-
-#define i810_PCI_IDS \
-       {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define i830_PCI_IDS \
-       {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define gamma_PCI_IDS \
-       {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
-
-#define savage_PCI_IDS \
-       {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
-       {0x5333, 0x8a21, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
-       {0x5333, 0x8a22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE4}, \
-       {0x5333, 0x8a23, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE4}, \
-       {0x5333, 0x8c10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
-       {0x5333, 0x8c11, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
-       {0x5333, 0x8c12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
-       {0x5333, 0x8c13, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
-       {0x5333, 0x8c22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c24, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8c2f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
-       {0x5333, 0x8a25, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGE}, \
-       {0x5333, 0x8a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGE}, \
-       {0x5333, 0x8d01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
-       {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
-       {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
-       {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
-       {0, 0, 0}
-
-#define ffb_PCI_IDS \
-       {0, 0, 0}
-
-#define i915_PCI_IDS \
-       {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x258a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x27ae, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2972, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2982, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2992, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x29a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x29b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x29c2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x29d2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2a02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2a12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2a42, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
-       {0, 0, 0}
diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
deleted file mode 100644 (file)
index 93b1e04..0000000
+++ /dev/null
@@ -1,557 +0,0 @@
-/**
- * \file drm_proc.c
- * /proc support for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- *
- * \par Acknowledgements:
- *    Matthew J Sottek <matthew.j.sottek@intel.com> sent in a patch to fix
- *    the problem with the proc files not outputting all their information.
- */
-
-/*
- * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-
-static int drm_name_info(char *buf, char **start, off_t offset,
-                        int request, int *eof, void *data);
-static int drm_vm_info(char *buf, char **start, off_t offset,
-                      int request, int *eof, void *data);
-static int drm_clients_info(char *buf, char **start, off_t offset,
-                           int request, int *eof, void *data);
-static int drm_queues_info(char *buf, char **start, off_t offset,
-                          int request, int *eof, void *data);
-static int drm_bufs_info(char *buf, char **start, off_t offset,
-                        int request, int *eof, void *data);
-#if DRM_DEBUG_CODE
-static int drm_vma_info(char *buf, char **start, off_t offset,
-                       int request, int *eof, void *data);
-#endif
-
-/**
- * Proc file list.
- */
-static struct drm_proc_list {
-       const char *name;       /**< file name */
-       int (*f) (char *, char **, off_t, int, int *, void *);          /**< proc callback*/
-} drm_proc_list[] = {
-       {"name", drm_name_info},
-       {"mem", drm_mem_info},
-       {"vm", drm_vm_info},
-       {"clients", drm_clients_info},
-       {"queues", drm_queues_info},
-       {"bufs", drm_bufs_info},
-#if DRM_DEBUG_CODE
-       {"vma", drm_vma_info},
-#endif
-};
-
-#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
-
-/**
- * Initialize the DRI proc filesystem for a device.
- *
- * \param dev DRM device.
- * \param minor device minor number.
- * \param root DRI proc dir entry.
- * \param dev_root resulting DRI device proc dir entry.
- * \return root entry pointer on success, or NULL on failure.
- *
- * Create the DRI proc root entry "/proc/dri", the device proc root entry
- * "/proc/dri/%minor%/", and each entry in proc_list as
- * "/proc/dri/%minor%/%name%".
- */
-int drm_proc_init(struct drm_minor *minor, int minor_id,
-                 struct proc_dir_entry *root)
-{
-       struct proc_dir_entry *ent;
-       int i, j;
-       char name[64];
-
-       sprintf(name, "%d", minor_id);
-       minor->dev_root = proc_mkdir(name, root);
-       if (!minor->dev_root) {
-               DRM_ERROR("Cannot create /proc/dri/%s\n", name);
-               return -1;
-       }
-
-       for (i = 0; i < DRM_PROC_ENTRIES; i++) {
-               ent = create_proc_entry(drm_proc_list[i].name,
-                                       S_IFREG | S_IRUGO, minor->dev_root);
-               if (!ent) {
-                       DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
-                                 name, drm_proc_list[i].name);
-                       for (j = 0; j < i; j++)
-                               remove_proc_entry(drm_proc_list[i].name,
-                                                 minor->dev_root);
-                       remove_proc_entry(name, root);
-                       minor->dev_root = NULL;
-                       return -1;
-               }
-               ent->read_proc = drm_proc_list[i].f;
-               ent->data = minor;
-       }
-
-       return 0;
-}
-
-/**
- * Cleanup the proc filesystem resources.
- *
- * \param minor device minor number.
- * \param root DRI proc dir entry.
- * \param dev_root DRI device proc dir entry.
- * \return always zero.
- *
- * Remove all proc entries created by proc_init().
- */
-int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
-{
-       int i;
-       char name[64];
-
-       if (!root || !minor->dev_root)
-               return 0;
-
-       for (i = 0; i < DRM_PROC_ENTRIES; i++)
-               remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
-       sprintf(name, "%d", minor->index);
-       remove_proc_entry(name, root);
-
-       return 0;
-}
-
-/**
- * Called when "/proc/dri/.../name" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- *
- * Prints the device name together with the bus id if available.
- */
-static int drm_name_info(char *buf, char **start, off_t offset, int request,
-                        int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       if (dev->unique) {
-               DRM_PROC_PRINT("%s %s %s\n",
-                              dev->driver->pci_driver.name,
-                              pci_name(dev->pdev), dev->unique);
-       } else {
-               DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
-                              pci_name(dev->pdev));
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-/**
- * Called when "/proc/dri/.../vm" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- *
- * Prints information about all mappings in drm_device::maplist.
- */
-static int drm__vm_info(char *buf, char **start, off_t offset, int request,
-                       int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-       struct drm_map *map;
-       struct drm_map_list *r_list;
-
-       /* Hardcoded from _DRM_FRAME_BUFFER,
-          _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
-          _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
-       const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
-       const char *type;
-       int i;
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       DRM_PROC_PRINT("slot     offset       size type flags    "
-                      "address mtrr\n\n");
-       i = 0;
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               map = r_list->map;
-               if (!map)
-                       continue;
-               if (map->type < 0 || map->type > 5)
-                       type = "??";
-               else
-                       type = types[map->type];
-               DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s  0x%02x 0x%08lx ",
-                              i,
-                              map->offset,
-                              map->size, type, map->flags,
-                              (unsigned long) r_list->user_token);
-               if (map->mtrr < 0) {
-                       DRM_PROC_PRINT("none\n");
-               } else {
-                       DRM_PROC_PRINT("%4d\n", map->mtrr);
-               }
-               i++;
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-/**
- * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
- */
-static int drm_vm_info(char *buf, char **start, off_t offset, int request,
-                      int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm__vm_info(buf, start, offset, request, eof, data);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
-}
-
-/**
- * Called when "/proc/dri/.../queues" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- */
-static int drm__queues_info(char *buf, char **start, off_t offset,
-                           int request, int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-       int i;
-       struct drm_queue *q;
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       DRM_PROC_PRINT("  ctx/flags   use   fin"
-                      "   blk/rw/rwf  wait    flushed     queued"
-                      "      locks\n\n");
-       for (i = 0; i < dev->queue_count; i++) {
-               q = dev->queuelist[i];
-               atomic_inc(&q->use_count);
-               DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
-                                  "%5d/0x%03x %5d %5d"
-                                  " %5d/%c%c/%c%c%c %5Zd\n",
-                                  i,
-                                  q->flags,
-                                  atomic_read(&q->use_count),
-                                  atomic_read(&q->finalization),
-                                  atomic_read(&q->block_count),
-                                  atomic_read(&q->block_read) ? 'r' : '-',
-                                  atomic_read(&q->block_write) ? 'w' : '-',
-                                  waitqueue_active(&q->read_queue) ? 'r' : '-',
-                                  waitqueue_active(&q->
-                                                   write_queue) ? 'w' : '-',
-                                  waitqueue_active(&q->
-                                                   flush_queue) ? 'f' : '-',
-                                  DRM_BUFCOUNT(&q->waitlist));
-               atomic_dec(&q->use_count);
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-/**
- * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
- */
-static int drm_queues_info(char *buf, char **start, off_t offset, int request,
-                          int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm__queues_info(buf, start, offset, request, eof, data);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
-}
-
-/**
- * Called when "/proc/dri/.../bufs" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- */
-static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
-                         int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-
-       if (!dma || offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       DRM_PROC_PRINT(" o     size count  free  segs pages    kB\n\n");
-       for (i = 0; i <= DRM_MAX_ORDER; i++) {
-               if (dma->bufs[i].buf_count)
-                       DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
-                                      i,
-                                      dma->bufs[i].buf_size,
-                                      dma->bufs[i].buf_count,
-                                      atomic_read(&dma->bufs[i]
-                                                  .freelist.count),
-                                      dma->bufs[i].seg_count,
-                                      dma->bufs[i].seg_count
-                                      * (1 << dma->bufs[i].page_order),
-                                      (dma->bufs[i].seg_count
-                                       * (1 << dma->bufs[i].page_order))
-                                      * PAGE_SIZE / 1024);
-       }
-       DRM_PROC_PRINT("\n");
-       for (i = 0; i < dma->buf_count; i++) {
-               if (i && !(i % 32))
-                       DRM_PROC_PRINT("\n");
-               DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
-       }
-       DRM_PROC_PRINT("\n");
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-/**
- * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
- */
-static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
-                        int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm__bufs_info(buf, start, offset, request, eof, data);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
-}
-
-/**
- * Called when "/proc/dri/.../clients" is read.
- *
- * \param buf output buffer.
- * \param start start of output data.
- * \param offset requested start offset.
- * \param request requested number of bytes.
- * \param eof whether there is no more data to return.
- * \param data private data.
- * \return number of written bytes.
- */
-static int drm__clients_info(char *buf, char **start, off_t offset,
-                            int request, int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-       struct drm_file *priv;
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       DRM_PROC_PRINT("a dev   pid    uid      magic     ioctls\n\n");
-       list_for_each_entry(priv, &dev->filelist, lhead) {
-               DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
-                              priv->authenticated ? 'y' : 'n',
-                              priv->minor->index,
-                              priv->pid,
-                              priv->uid, priv->magic, priv->ioctl_count);
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-/**
- * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
- */
-static int drm_clients_info(char *buf, char **start, off_t offset,
-                           int request, int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm__clients_info(buf, start, offset, request, eof, data);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
-}
-
-#if DRM_DEBUG_CODE
-
-static int drm__vma_info(char *buf, char **start, off_t offset, int request,
-                        int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int len = 0;
-       struct drm_vma_entry *pt;
-       struct vm_area_struct *vma;
-#if defined(__i386__)
-       unsigned int pgprot;
-#endif
-
-       if (offset > DRM_PROC_LIMIT) {
-               *eof = 1;
-               return 0;
-       }
-
-       *start = &buf[offset];
-       *eof = 0;
-
-       DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
-                      atomic_read(&dev->vma_count),
-                      high_memory, virt_to_phys(high_memory));
-       list_for_each_entry(pt, &dev->vmalist, head) {
-               if (!(vma = pt->vma))
-                       continue;
-               DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
-                              pt->pid,
-                              vma->vm_start,
-                              vma->vm_end,
-                              vma->vm_flags & VM_READ ? 'r' : '-',
-                              vma->vm_flags & VM_WRITE ? 'w' : '-',
-                              vma->vm_flags & VM_EXEC ? 'x' : '-',
-                              vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
-                              vma->vm_flags & VM_LOCKED ? 'l' : '-',
-                              vma->vm_flags & VM_IO ? 'i' : '-',
-                              vma->vm_pgoff);
-
-#if defined(__i386__)
-               pgprot = pgprot_val(vma->vm_page_prot);
-               DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
-                              pgprot & _PAGE_PRESENT ? 'p' : '-',
-                              pgprot & _PAGE_RW ? 'w' : 'r',
-                              pgprot & _PAGE_USER ? 'u' : 's',
-                              pgprot & _PAGE_PWT ? 't' : 'b',
-                              pgprot & _PAGE_PCD ? 'u' : 'c',
-                              pgprot & _PAGE_ACCESSED ? 'a' : '-',
-                              pgprot & _PAGE_DIRTY ? 'd' : '-',
-                              pgprot & _PAGE_PSE ? 'm' : 'k',
-                              pgprot & _PAGE_GLOBAL ? 'g' : 'l');
-#endif
-               DRM_PROC_PRINT("\n");
-       }
-
-       if (len > request + offset)
-               return request;
-       *eof = 1;
-       return len - offset;
-}
-
-static int drm_vma_info(char *buf, char **start, off_t offset, int request,
-                       int *eof, void *data)
-{
-       struct drm_minor *minor = (struct drm_minor *) data;
-       struct drm_device *dev = minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm__vma_info(buf, start, offset, request, eof, data);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
-}
-#endif
diff --git a/drivers/char/drm/drm_sarea.h b/drivers/char/drm/drm_sarea.h
deleted file mode 100644 (file)
index 4800373..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * \file drm_sarea.h
- * \brief SAREA definitions
- *
- * \author Michel Dänzer <michel@daenzer.net>
- */
-
-/*
- * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _DRM_SAREA_H_
-#define _DRM_SAREA_H_
-
-#include "drm.h"
-
-/* SAREA area needs to be at least a page */
-#if defined(__alpha__)
-#define SAREA_MAX                       0x2000
-#elif defined(__ia64__)
-#define SAREA_MAX                       0x10000        /* 64kB */
-#else
-/* Intel 830M driver needs at least 8k SAREA */
-#define SAREA_MAX                       0x2000
-#endif
-
-/** Maximum number of drawables in the SAREA */
-#define SAREA_MAX_DRAWABLES            256
-
-#define SAREA_DRAWABLE_CLAIMED_ENTRY    0x80000000
-
-/** SAREA drawable */
-struct drm_sarea_drawable {
-       unsigned int stamp;
-       unsigned int flags;
-};
-
-/** SAREA frame */
-struct drm_sarea_frame {
-       unsigned int x;
-       unsigned int y;
-       unsigned int width;
-       unsigned int height;
-       unsigned int fullscreen;
-};
-
-/** SAREA */
-struct drm_sarea {
-    /** first thing is always the DRM locking structure */
-       struct drm_hw_lock lock;
-    /** \todo Use readers/writer lock for drm_sarea::drawable_lock */
-       struct drm_hw_lock drawable_lock;
-       struct drm_sarea_drawable drawableTable[SAREA_MAX_DRAWABLES];   /**< drawables */
-       struct drm_sarea_frame frame;   /**< frame */
-       drm_context_t dummy_context;
-};
-
-#ifndef __KERNEL__
-typedef struct drm_sarea_drawable drm_sarea_drawable_t;
-typedef struct drm_sarea_frame drm_sarea_frame_t;
-typedef struct drm_sarea drm_sarea_t;
-#endif
-
-#endif                         /* _DRM_SAREA_H_ */
diff --git a/drivers/char/drm/drm_scatter.c b/drivers/char/drm/drm_scatter.c
deleted file mode 100644 (file)
index b2b0f3d..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/**
- * \file drm_scatter.c
- * IOCTLs to manage scatter/gather memory
- *
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com
- *
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/vmalloc.h>
-#include "drmP.h"
-
-#define DEBUG_SCATTER 0
-
-static inline void *drm_vmalloc_dma(unsigned long size)
-{
-#if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
-       return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL | _PAGE_NO_CACHE);
-#else
-       return vmalloc_32(size);
-#endif
-}
-
-void drm_sg_cleanup(struct drm_sg_mem * entry)
-{
-       struct page *page;
-       int i;
-
-       for (i = 0; i < entry->pages; i++) {
-               page = entry->pagelist[i];
-               if (page)
-                       ClearPageReserved(page);
-       }
-
-       vfree(entry->virtual);
-
-       drm_free(entry->busaddr,
-                entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
-       drm_free(entry->pagelist,
-                entry->pages * sizeof(*entry->pagelist), DRM_MEM_PAGES);
-       drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
-}
-
-#ifdef _LP64
-# define ScatterHandle(x) (unsigned int)((x >> 32) + (x & ((1L << 32) - 1)))
-#else
-# define ScatterHandle(x) (unsigned int)(x)
-#endif
-
-int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
-{
-       struct drm_sg_mem *entry;
-       unsigned long pages, i, j;
-
-       DRM_DEBUG("\n");
-
-       if (!drm_core_check_feature(dev, DRIVER_SG))
-               return -EINVAL;
-
-       if (dev->sg)
-               return -EINVAL;
-
-       entry = drm_alloc(sizeof(*entry), DRM_MEM_SGLISTS);
-       if (!entry)
-               return -ENOMEM;
-
-       memset(entry, 0, sizeof(*entry));
-       pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
-       DRM_DEBUG("size=%ld pages=%ld\n", request->size, pages);
-
-       entry->pages = pages;
-       entry->pagelist = drm_alloc(pages * sizeof(*entry->pagelist),
-                                   DRM_MEM_PAGES);
-       if (!entry->pagelist) {
-               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
-               return -ENOMEM;
-       }
-
-       memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
-
-       entry->busaddr = drm_alloc(pages * sizeof(*entry->busaddr),
-                                  DRM_MEM_PAGES);
-       if (!entry->busaddr) {
-               drm_free(entry->pagelist,
-                        entry->pages * sizeof(*entry->pagelist),
-                        DRM_MEM_PAGES);
-               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
-               return -ENOMEM;
-       }
-       memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
-
-       entry->virtual = drm_vmalloc_dma(pages << PAGE_SHIFT);
-       if (!entry->virtual) {
-               drm_free(entry->busaddr,
-                        entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
-               drm_free(entry->pagelist,
-                        entry->pages * sizeof(*entry->pagelist),
-                        DRM_MEM_PAGES);
-               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
-               return -ENOMEM;
-       }
-
-       /* This also forces the mapping of COW pages, so our page list
-        * will be valid.  Please don't remove it...
-        */
-       memset(entry->virtual, 0, pages << PAGE_SHIFT);
-
-       entry->handle = ScatterHandle((unsigned long)entry->virtual);
-
-       DRM_DEBUG("handle  = %08lx\n", entry->handle);
-       DRM_DEBUG("virtual = %p\n", entry->virtual);
-
-       for (i = (unsigned long)entry->virtual, j = 0; j < pages;
-            i += PAGE_SIZE, j++) {
-               entry->pagelist[j] = vmalloc_to_page((void *)i);
-               if (!entry->pagelist[j])
-                       goto failed;
-               SetPageReserved(entry->pagelist[j]);
-       }
-
-       request->handle = entry->handle;
-
-       dev->sg = entry;
-
-#if DEBUG_SCATTER
-       /* Verify that each page points to its virtual address, and vice
-        * versa.
-        */
-       {
-               int error = 0;
-
-               for (i = 0; i < pages; i++) {
-                       unsigned long *tmp;
-
-                       tmp = page_address(entry->pagelist[i]);
-                       for (j = 0;
-                            j < PAGE_SIZE / sizeof(unsigned long);
-                            j++, tmp++) {
-                               *tmp = 0xcafebabe;
-                       }
-                       tmp = (unsigned long *)((u8 *) entry->virtual +
-                                               (PAGE_SIZE * i));
-                       for (j = 0;
-                            j < PAGE_SIZE / sizeof(unsigned long);
-                            j++, tmp++) {
-                               if (*tmp != 0xcafebabe && error == 0) {
-                                       error = 1;
-                                       DRM_ERROR("Scatter allocation error, "
-                                                 "pagelist does not match "
-                                                 "virtual mapping\n");
-                               }
-                       }
-                       tmp = page_address(entry->pagelist[i]);
-                       for (j = 0;
-                            j < PAGE_SIZE / sizeof(unsigned long);
-                            j++, tmp++) {
-                               *tmp = 0;
-                       }
-               }
-               if (error == 0)
-                       DRM_ERROR("Scatter allocation matches pagelist\n");
-       }
-#endif
-
-       return 0;
-
-      failed:
-       drm_sg_cleanup(entry);
-       return -ENOMEM;
-}
-EXPORT_SYMBOL(drm_sg_alloc);
-
-
-int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_scatter_gather *request = data;
-
-       return drm_sg_alloc(dev, request);
-
-}
-
-int drm_sg_free(struct drm_device *dev, void *data,
-               struct drm_file *file_priv)
-{
-       struct drm_scatter_gather *request = data;
-       struct drm_sg_mem *entry;
-
-       if (!drm_core_check_feature(dev, DRIVER_SG))
-               return -EINVAL;
-
-       entry = dev->sg;
-       dev->sg = NULL;
-
-       if (!entry || entry->handle != request->handle)
-               return -EINVAL;
-
-       DRM_DEBUG("virtual  = %p\n", entry->virtual);
-
-       drm_sg_cleanup(entry);
-
-       return 0;
-}
diff --git a/drivers/char/drm/drm_sman.c b/drivers/char/drm/drm_sman.c
deleted file mode 100644 (file)
index 926f146..0000000
+++ /dev/null
@@ -1,353 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- *
- **************************************************************************/
-/*
- * Simple memory manager interface that keeps track on allocate regions on a
- * per "owner" basis. All regions associated with an "owner" can be released
- * with a simple call. Typically if the "owner" exists. The owner is any
- * "unsigned long" identifier. Can typically be a pointer to a file private
- * struct or a context identifier.
- *
- * Authors:
- * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drm_sman.h"
-
-struct drm_owner_item {
-       struct drm_hash_item owner_hash;
-       struct list_head sman_list;
-       struct list_head mem_blocks;
-};
-
-void drm_sman_takedown(struct drm_sman * sman)
-{
-       drm_ht_remove(&sman->user_hash_tab);
-       drm_ht_remove(&sman->owner_hash_tab);
-       if (sman->mm)
-               drm_free(sman->mm, sman->num_managers * sizeof(*sman->mm),
-                        DRM_MEM_MM);
-}
-
-EXPORT_SYMBOL(drm_sman_takedown);
-
-int
-drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
-             unsigned int user_order, unsigned int owner_order)
-{
-       int ret = 0;
-
-       sman->mm = (struct drm_sman_mm *) drm_calloc(num_managers, sizeof(*sman->mm),
-                                               DRM_MEM_MM);
-       if (!sman->mm) {
-               ret = -ENOMEM;
-               goto out;
-       }
-       sman->num_managers = num_managers;
-       INIT_LIST_HEAD(&sman->owner_items);
-       ret = drm_ht_create(&sman->owner_hash_tab, owner_order);
-       if (ret)
-               goto out1;
-       ret = drm_ht_create(&sman->user_hash_tab, user_order);
-       if (!ret)
-               goto out;
-
-       drm_ht_remove(&sman->owner_hash_tab);
-out1:
-       drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
-out:
-       return ret;
-}
-
-EXPORT_SYMBOL(drm_sman_init);
-
-static void *drm_sman_mm_allocate(void *private, unsigned long size,
-                                 unsigned alignment)
-{
-       struct drm_mm *mm = (struct drm_mm *) private;
-       struct drm_mm_node *tmp;
-
-       tmp = drm_mm_search_free(mm, size, alignment, 1);
-       if (!tmp) {
-               return NULL;
-       }
-       tmp = drm_mm_get_block(tmp, size, alignment);
-       return tmp;
-}
-
-static void drm_sman_mm_free(void *private, void *ref)
-{
-       struct drm_mm_node *node = (struct drm_mm_node *) ref;
-
-       drm_mm_put_block(node);
-}
-
-static void drm_sman_mm_destroy(void *private)
-{
-       struct drm_mm *mm = (struct drm_mm *) private;
-       drm_mm_takedown(mm);
-       drm_free(mm, sizeof(*mm), DRM_MEM_MM);
-}
-
-static unsigned long drm_sman_mm_offset(void *private, void *ref)
-{
-       struct drm_mm_node *node = (struct drm_mm_node *) ref;
-       return node->start;
-}
-
-int
-drm_sman_set_range(struct drm_sman * sman, unsigned int manager,
-                  unsigned long start, unsigned long size)
-{
-       struct drm_sman_mm *sman_mm;
-       struct drm_mm *mm;
-       int ret;
-
-       BUG_ON(manager >= sman->num_managers);
-
-       sman_mm = &sman->mm[manager];
-       mm = drm_calloc(1, sizeof(*mm), DRM_MEM_MM);
-       if (!mm) {
-               return -ENOMEM;
-       }
-       sman_mm->private = mm;
-       ret = drm_mm_init(mm, start, size);
-
-       if (ret) {
-               drm_free(mm, sizeof(*mm), DRM_MEM_MM);
-               return ret;
-       }
-
-       sman_mm->allocate = drm_sman_mm_allocate;
-       sman_mm->free = drm_sman_mm_free;
-       sman_mm->destroy = drm_sman_mm_destroy;
-       sman_mm->offset = drm_sman_mm_offset;
-
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_sman_set_range);
-
-int
-drm_sman_set_manager(struct drm_sman * sman, unsigned int manager,
-                    struct drm_sman_mm * allocator)
-{
-       BUG_ON(manager >= sman->num_managers);
-       sman->mm[manager] = *allocator;
-
-       return 0;
-}
-EXPORT_SYMBOL(drm_sman_set_manager);
-
-static struct drm_owner_item *drm_sman_get_owner_item(struct drm_sman * sman,
-                                                unsigned long owner)
-{
-       int ret;
-       struct drm_hash_item *owner_hash_item;
-       struct drm_owner_item *owner_item;
-
-       ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
-       if (!ret) {
-               return drm_hash_entry(owner_hash_item, struct drm_owner_item,
-                                     owner_hash);
-       }
-
-       owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM);
-       if (!owner_item)
-               goto out;
-
-       INIT_LIST_HEAD(&owner_item->mem_blocks);
-       owner_item->owner_hash.key = owner;
-       if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash))
-               goto out1;
-
-       list_add_tail(&owner_item->sman_list, &sman->owner_items);
-       return owner_item;
-
-out1:
-       drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
-out:
-       return NULL;
-}
-
-struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int manager,
-                                   unsigned long size, unsigned alignment,
-                                   unsigned long owner)
-{
-       void *tmp;
-       struct drm_sman_mm *sman_mm;
-       struct drm_owner_item *owner_item;
-       struct drm_memblock_item *memblock;
-
-       BUG_ON(manager >= sman->num_managers);
-
-       sman_mm = &sman->mm[manager];
-       tmp = sman_mm->allocate(sman_mm->private, size, alignment);
-
-       if (!tmp) {
-               return NULL;
-       }
-
-       memblock = drm_calloc(1, sizeof(*memblock), DRM_MEM_MM);
-
-       if (!memblock)
-               goto out;
-
-       memblock->mm_info = tmp;
-       memblock->mm = sman_mm;
-       memblock->sman = sman;
-
-       if (drm_ht_just_insert_please
-           (&sman->user_hash_tab, &memblock->user_hash,
-            (unsigned long)memblock, 32, 0, 0))
-               goto out1;
-
-       owner_item = drm_sman_get_owner_item(sman, owner);
-       if (!owner_item)
-               goto out2;
-
-       list_add_tail(&memblock->owner_list, &owner_item->mem_blocks);
-
-       return memblock;
-
-out2:
-       drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
-out1:
-       drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
-out:
-       sman_mm->free(sman_mm->private, tmp);
-
-       return NULL;
-}
-
-EXPORT_SYMBOL(drm_sman_alloc);
-
-static void drm_sman_free(struct drm_memblock_item *item)
-{
-       struct drm_sman *sman = item->sman;
-
-       list_del(&item->owner_list);
-       drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash);
-       item->mm->free(item->mm->private, item->mm_info);
-       drm_free(item, sizeof(*item), DRM_MEM_MM);
-}
-
-int drm_sman_free_key(struct drm_sman *sman, unsigned int key)
-{
-       struct drm_hash_item *hash_item;
-       struct drm_memblock_item *memblock_item;
-
-       if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item))
-               return -EINVAL;
-
-       memblock_item = drm_hash_entry(hash_item, struct drm_memblock_item,
-                                      user_hash);
-       drm_sman_free(memblock_item);
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_sman_free_key);
-
-static void drm_sman_remove_owner(struct drm_sman *sman,
-                                 struct drm_owner_item *owner_item)
-{
-       list_del(&owner_item->sman_list);
-       drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
-       drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
-}
-
-int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner)
-{
-
-       struct drm_hash_item *hash_item;
-       struct drm_owner_item *owner_item;
-
-       if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
-               return -1;
-       }
-
-       owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash);
-       if (owner_item->mem_blocks.next == &owner_item->mem_blocks) {
-               drm_sman_remove_owner(sman, owner_item);
-               return -1;
-       }
-
-       return 0;
-}
-
-EXPORT_SYMBOL(drm_sman_owner_clean);
-
-static void drm_sman_do_owner_cleanup(struct drm_sman *sman,
-                                     struct drm_owner_item *owner_item)
-{
-       struct drm_memblock_item *entry, *next;
-
-       list_for_each_entry_safe(entry, next, &owner_item->mem_blocks,
-                                owner_list) {
-               drm_sman_free(entry);
-       }
-       drm_sman_remove_owner(sman, owner_item);
-}
-
-void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner)
-{
-
-       struct drm_hash_item *hash_item;
-       struct drm_owner_item *owner_item;
-
-       if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
-
-               return;
-       }
-
-       owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash);
-       drm_sman_do_owner_cleanup(sman, owner_item);
-}
-
-EXPORT_SYMBOL(drm_sman_owner_cleanup);
-
-void drm_sman_cleanup(struct drm_sman *sman)
-{
-       struct drm_owner_item *entry, *next;
-       unsigned int i;
-       struct drm_sman_mm *sman_mm;
-
-       list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) {
-               drm_sman_do_owner_cleanup(sman, entry);
-       }
-       if (sman->mm) {
-               for (i = 0; i < sman->num_managers; ++i) {
-                       sman_mm = &sman->mm[i];
-                       if (sman_mm->private) {
-                               sman_mm->destroy(sman_mm->private);
-                               sman_mm->private = NULL;
-                       }
-               }
-       }
-}
-
-EXPORT_SYMBOL(drm_sman_cleanup);
diff --git a/drivers/char/drm/drm_sman.h b/drivers/char/drm/drm_sman.h
deleted file mode 100644 (file)
index 08ecf83..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- **************************************************************************/
-/*
- * Simple memory MANager interface that keeps track on allocate regions on a
- * per "owner" basis. All regions associated with an "owner" can be released
- * with a simple call. Typically if the "owner" exists. The owner is any
- * "unsigned long" identifier. Can typically be a pointer to a file private
- * struct or a context identifier.
- *
- * Authors:
- * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#ifndef DRM_SMAN_H
-#define DRM_SMAN_H
-
-#include "drmP.h"
-#include "drm_hashtab.h"
-
-/*
- * A class that is an abstration of a simple memory allocator.
- * The sman implementation provides a default such allocator
- * using the drm_mm.c implementation. But the user can replace it.
- * See the SiS implementation, which may use the SiS FB kernel module
- * for memory management.
- */
-
-struct drm_sman_mm {
-       /* private info. If allocated, needs to be destroyed by the destroy
-          function */
-       void *private;
-
-       /* Allocate a memory block with given size and alignment.
-          Return an opaque reference to the memory block */
-
-       void *(*allocate) (void *private, unsigned long size,
-                          unsigned alignment);
-
-       /* Free a memory block. "ref" is the opaque reference that we got from
-          the "alloc" function */
-
-       void (*free) (void *private, void *ref);
-
-       /* Free all resources associated with this allocator */
-
-       void (*destroy) (void *private);
-
-       /* Return a memory offset from the opaque reference returned from the
-          "alloc" function */
-
-       unsigned long (*offset) (void *private, void *ref);
-};
-
-struct drm_memblock_item {
-       struct list_head owner_list;
-       struct drm_hash_item user_hash;
-       void *mm_info;
-       struct drm_sman_mm *mm;
-       struct drm_sman *sman;
-};
-
-struct drm_sman {
-       struct drm_sman_mm *mm;
-       int num_managers;
-       struct drm_open_hash owner_hash_tab;
-       struct drm_open_hash user_hash_tab;
-       struct list_head owner_items;
-};
-
-/*
- * Take down a memory manager. This function should only be called after a
- * successful init and after a call to drm_sman_cleanup.
- */
-
-extern void drm_sman_takedown(struct drm_sman * sman);
-
-/*
- * Allocate structures for a manager.
- * num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
- * user_order is the log2 of the number of buckets in the user hash table.
- *         set this to approximately log2 of the max number of memory regions
- *         that will be allocated for _all_ pools together.
- * owner_order is the log2 of the number of buckets in the owner hash table.
- *         set this to approximately log2 of
- *         the number of client file connections that will
- *         be using the manager.
- *
- */
-
-extern int drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
-                        unsigned int user_order, unsigned int owner_order);
-
-/*
- * Initialize a drm_mm.c allocator. Should be called only once for each
- * manager unless a customized allogator is used.
- */
-
-extern int drm_sman_set_range(struct drm_sman * sman, unsigned int manager,
-                             unsigned long start, unsigned long size);
-
-/*
- * Initialize a customized allocator for one of the managers.
- * (See the SiS module). The object pointed to by "allocator" is copied,
- * so it can be destroyed after this call.
- */
-
-extern int drm_sman_set_manager(struct drm_sman * sman, unsigned int mananger,
-                               struct drm_sman_mm * allocator);
-
-/*
- * Allocate a memory block. Aligment is not implemented yet.
- */
-
-extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman,
-                                               unsigned int manager,
-                                               unsigned long size,
-                                               unsigned alignment,
-                                               unsigned long owner);
-/*
- * Free a memory block identified by its user hash key.
- */
-
-extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key);
-
-/*
- * returns 1 iff there are no stale memory blocks associated with this owner.
- * Typically called to determine if we need to idle the hardware and call
- * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all
- * resources associated with owner.
- */
-
-extern int drm_sman_owner_clean(struct drm_sman * sman, unsigned long owner);
-
-/*
- * Frees all stale memory blocks associated with this owner. Note that this
- * requires that the hardware is finished with all blocks, so the graphics engine
- * should be idled before this call is made. This function also frees
- * any resources associated with "owner" and should be called when owner
- * is not going to be referenced anymore.
- */
-
-extern void drm_sman_owner_cleanup(struct drm_sman * sman, unsigned long owner);
-
-/*
- * Frees all stale memory blocks associated with the memory manager.
- * See idling above.
- */
-
-extern void drm_sman_cleanup(struct drm_sman * sman);
-
-#endif
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
deleted file mode 100644 (file)
index c2f584f..0000000
+++ /dev/null
@@ -1,331 +0,0 @@
-/**
- * \file drm_stub.h
- * Stub support
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- */
-
-/*
- * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
- *
- * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include "drmP.h"
-#include "drm_core.h"
-
-unsigned int drm_debug = 0;    /* 1 to enable debug output */
-EXPORT_SYMBOL(drm_debug);
-
-MODULE_AUTHOR(CORE_AUTHOR);
-MODULE_DESCRIPTION(CORE_DESC);
-MODULE_LICENSE("GPL and additional rights");
-MODULE_PARM_DESC(debug, "Enable debug output");
-
-module_param_named(debug, drm_debug, int, 0600);
-
-struct idr drm_minors_idr;
-
-struct class *drm_class;
-struct proc_dir_entry *drm_proc_root;
-
-static int drm_minor_get_id(struct drm_device *dev, int type)
-{
-       int new_id;
-       int ret;
-       int base = 0, limit = 63;
-
-again:
-       if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) {
-               DRM_ERROR("Out of memory expanding drawable idr\n");
-               return -ENOMEM;
-       }
-       mutex_lock(&dev->struct_mutex);
-       ret = idr_get_new_above(&drm_minors_idr, NULL,
-                               base, &new_id);
-       mutex_unlock(&dev->struct_mutex);
-       if (ret == -EAGAIN) {
-               goto again;
-       } else if (ret) {
-               return ret;
-       }
-
-       if (new_id >= limit) {
-               idr_remove(&drm_minors_idr, new_id);
-               return -EINVAL;
-       }
-       return new_id;
-}
-
-static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
-                          const struct pci_device_id *ent,
-                          struct drm_driver *driver)
-{
-       int retcode;
-
-       INIT_LIST_HEAD(&dev->filelist);
-       INIT_LIST_HEAD(&dev->ctxlist);
-       INIT_LIST_HEAD(&dev->vmalist);
-       INIT_LIST_HEAD(&dev->maplist);
-
-       spin_lock_init(&dev->count_lock);
-       spin_lock_init(&dev->drw_lock);
-       spin_lock_init(&dev->tasklet_lock);
-       spin_lock_init(&dev->lock.spinlock);
-       init_timer(&dev->timer);
-       mutex_init(&dev->struct_mutex);
-       mutex_init(&dev->ctxlist_mutex);
-
-       idr_init(&dev->drw_idr);
-
-       dev->pdev = pdev;
-       dev->pci_device = pdev->device;
-       dev->pci_vendor = pdev->vendor;
-
-#ifdef __alpha__
-       dev->hose = pdev->sysdata;
-#endif
-       dev->irq = pdev->irq;
-
-       if (drm_ht_create(&dev->map_hash, 12)) {
-               return -ENOMEM;
-       }
-
-       /* the DRM has 6 basic counters */
-       dev->counters = 6;
-       dev->types[0] = _DRM_STAT_LOCK;
-       dev->types[1] = _DRM_STAT_OPENS;
-       dev->types[2] = _DRM_STAT_CLOSES;
-       dev->types[3] = _DRM_STAT_IOCTLS;
-       dev->types[4] = _DRM_STAT_LOCKS;
-       dev->types[5] = _DRM_STAT_UNLOCKS;
-
-       dev->driver = driver;
-
-       if (drm_core_has_AGP(dev)) {
-               if (drm_device_is_agp(dev))
-                       dev->agp = drm_agp_init(dev);
-               if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP)
-                   && (dev->agp == NULL)) {
-                       DRM_ERROR("Cannot initialize the agpgart module.\n");
-                       retcode = -EINVAL;
-                       goto error_out_unreg;
-               }
-               if (drm_core_has_MTRR(dev)) {
-                       if (dev->agp)
-                               dev->agp->agp_mtrr =
-                                   mtrr_add(dev->agp->agp_info.aper_base,
-                                            dev->agp->agp_info.aper_size *
-                                            1024 * 1024, MTRR_TYPE_WRCOMB, 1);
-               }
-       }
-
-       if (dev->driver->load)
-               if ((retcode = dev->driver->load(dev, ent->driver_data)))
-                       goto error_out_unreg;
-
-       retcode = drm_ctxbitmap_init(dev);
-       if (retcode) {
-               DRM_ERROR("Cannot allocate memory for context bitmap.\n");
-               goto error_out_unreg;
-       }
-
-       return 0;
-
-      error_out_unreg:
-       drm_lastclose(dev);
-       return retcode;
-}
-
-
-/**
- * Get a secondary minor number.
- *
- * \param dev device data structure
- * \param sec-minor structure to hold the assigned minor
- * \return negative number on failure.
- *
- * Search an empty entry and initialize it to the given parameters, and
- * create the proc init entry via proc_init(). This routines assigns
- * minor numbers to secondary heads of multi-headed cards
- */
-static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
-{
-       struct drm_minor *new_minor;
-       int ret;
-       int minor_id;
-
-       DRM_DEBUG("\n");
-
-       minor_id = drm_minor_get_id(dev, type);
-       if (minor_id < 0)
-               return minor_id;
-
-       new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL);
-       if (!new_minor) {
-               ret = -ENOMEM;
-               goto err_idr;
-       }
-
-       new_minor->type = type;
-       new_minor->device = MKDEV(DRM_MAJOR, minor_id);
-       new_minor->dev = dev;
-       new_minor->index = minor_id;
-
-       idr_replace(&drm_minors_idr, new_minor, minor_id);
-
-       if (type == DRM_MINOR_LEGACY) {
-               ret = drm_proc_init(new_minor, minor_id, drm_proc_root);
-               if (ret) {
-                       DRM_ERROR("DRM: Failed to initialize /proc/dri.\n");
-                       goto err_mem;
-               }
-       } else
-               new_minor->dev_root = NULL;
-
-       ret = drm_sysfs_device_add(new_minor);
-       if (ret) {
-               printk(KERN_ERR
-                      "DRM: Error sysfs_device_add.\n");
-               goto err_g2;
-       }
-       *minor = new_minor;
-
-       DRM_DEBUG("new minor assigned %d\n", minor_id);
-       return 0;
-
-
-err_g2:
-       if (new_minor->type == DRM_MINOR_LEGACY)
-               drm_proc_cleanup(new_minor, drm_proc_root);
-err_mem:
-       kfree(new_minor);
-err_idr:
-       idr_remove(&drm_minors_idr, minor_id);
-       *minor = NULL;
-       return ret;
-}
-
-/**
- * Register.
- *
- * \param pdev - PCI device structure
- * \param ent entry from the PCI ID table with device type flags
- * \return zero on success or a negative number on failure.
- *
- * Attempt to gets inter module "drm" information. If we are first
- * then register the character device and inter module information.
- * Try and register, if we fail to register, backout previous work.
- */
-int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
-               struct drm_driver *driver)
-{
-       struct drm_device *dev;
-       int ret;
-
-       DRM_DEBUG("\n");
-
-       dev = drm_calloc(1, sizeof(*dev), DRM_MEM_STUB);
-       if (!dev)
-               return -ENOMEM;
-
-       ret = pci_enable_device(pdev);
-       if (ret)
-               goto err_g1;
-
-       pci_set_master(pdev);
-       if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
-               printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
-               goto err_g2;
-       }
-       if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY)))
-               goto err_g2;
-
-       DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
-                driver->name, driver->major, driver->minor, driver->patchlevel,
-                driver->date, dev->primary->index);
-
-       return 0;
-
-err_g2:
-       pci_disable_device(pdev);
-err_g1:
-       drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
-       return ret;
-}
-
-/**
- * Put a device minor number.
- *
- * \param dev device data structure
- * \return always zero
- *
- * Cleans up the proc resources. If it is the last minor then release the foreign
- * "drm" data, otherwise unregisters the "drm" data, frees the dev list and
- * unregisters the character device.
- */
-int drm_put_dev(struct drm_device * dev)
-{
-       DRM_DEBUG("release primary %s\n", dev->driver->pci_driver.name);
-
-       if (dev->unique) {
-               drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
-               dev->unique = NULL;
-               dev->unique_len = 0;
-       }
-       if (dev->devname) {
-               drm_free(dev->devname, strlen(dev->devname) + 1,
-                        DRM_MEM_DRIVER);
-               dev->devname = NULL;
-       }
-       drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
-       return 0;
-}
-
-/**
- * Put a secondary minor number.
- *
- * \param sec_minor - structure to be released
- * \return always zero
- *
- * Cleans up the proc resources. Not legal for this to be the
- * last minor released.
- *
- */
-int drm_put_minor(struct drm_minor **minor_p)
-{
-       struct drm_minor *minor = *minor_p;
-       DRM_DEBUG("release secondary minor %d\n", minor->index);
-
-       if (minor->type == DRM_MINOR_LEGACY)
-               drm_proc_cleanup(minor, drm_proc_root);
-       drm_sysfs_device_remove(minor);
-
-       idr_remove(&drm_minors_idr, minor->index);
-
-       kfree(minor);
-       *minor_p = NULL;
-       return 0;
-}
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
deleted file mode 100644 (file)
index af211a0..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-
-/*
- * drm_sysfs.c - Modifications to drm_sysfs_class.c to support
- *               extra sysfs attribute from DRM. Normal drm_sysfs_class
- *               does not allow adding attributes.
- *
- * Copyright (c) 2004 Jon Smirl <jonsmirl@gmail.com>
- * Copyright (c) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (c) 2003-2004 IBM Corp.
- *
- * This file is released under the GPLv2
- *
- */
-
-#include <linux/device.h>
-#include <linux/kdev_t.h>
-#include <linux/err.h>
-
-#include "drm_core.h"
-#include "drmP.h"
-
-#define to_drm_minor(d) container_of(d, struct drm_minor, kdev)
-
-/**
- * drm_sysfs_suspend - DRM class suspend hook
- * @dev: Linux device to suspend
- * @state: power state to enter
- *
- * Just figures out what the actual struct drm_device associated with
- * @dev is and calls its suspend hook, if present.
- */
-static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
-{
-       struct drm_minor *drm_minor = to_drm_minor(dev);
-       struct drm_device *drm_dev = drm_minor->dev;
-
-       if (drm_dev->driver->suspend)
-               return drm_dev->driver->suspend(drm_dev, state);
-
-       return 0;
-}
-
-/**
- * drm_sysfs_resume - DRM class resume hook
- * @dev: Linux device to resume
- *
- * Just figures out what the actual struct drm_device associated with
- * @dev is and calls its resume hook, if present.
- */
-static int drm_sysfs_resume(struct device *dev)
-{
-       struct drm_minor *drm_minor = to_drm_minor(dev);
-       struct drm_device *drm_dev = drm_minor->dev;
-
-       if (drm_dev->driver->resume)
-               return drm_dev->driver->resume(drm_dev);
-
-       return 0;
-}
-
-/* Display the version of drm_core. This doesn't work right in current design */
-static ssize_t version_show(struct class *dev, char *buf)
-{
-       return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
-                      CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
-}
-
-static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
-
-/**
- * drm_sysfs_create - create a struct drm_sysfs_class structure
- * @owner: pointer to the module that is to "own" this struct drm_sysfs_class
- * @name: pointer to a string for the name of this class.
- *
- * This is used to create DRM class pointer that can then be used
- * in calls to drm_sysfs_device_add().
- *
- * Note, the pointer created here is to be destroyed when finished by making a
- * call to drm_sysfs_destroy().
- */
-struct class *drm_sysfs_create(struct module *owner, char *name)
-{
-       struct class *class;
-       int err;
-
-       class = class_create(owner, name);
-       if (IS_ERR(class)) {
-               err = PTR_ERR(class);
-               goto err_out;
-       }
-
-       class->suspend = drm_sysfs_suspend;
-       class->resume = drm_sysfs_resume;
-
-       err = class_create_file(class, &class_attr_version);
-       if (err)
-               goto err_out_class;
-
-       return class;
-
-err_out_class:
-       class_destroy(class);
-err_out:
-       return ERR_PTR(err);
-}
-
-/**
- * drm_sysfs_destroy - destroys DRM class
- *
- * Destroy the DRM device class.
- */
-void drm_sysfs_destroy(void)
-{
-       if ((drm_class == NULL) || (IS_ERR(drm_class)))
-               return;
-       class_remove_file(drm_class, &class_attr_version);
-       class_destroy(drm_class);
-}
-
-static ssize_t show_dri(struct device *device, struct device_attribute *attr,
-                       char *buf)
-{
-       struct drm_minor *drm_minor = to_drm_minor(device);
-       struct drm_device *drm_dev = drm_minor->dev;
-       if (drm_dev->driver->dri_library_name)
-               return drm_dev->driver->dri_library_name(drm_dev, buf);
-       return snprintf(buf, PAGE_SIZE, "%s\n", drm_dev->driver->pci_driver.name);
-}
-
-static struct device_attribute device_attrs[] = {
-       __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
-};
-
-/**
- * drm_sysfs_device_release - do nothing
- * @dev: Linux device
- *
- * Normally, this would free the DRM device associated with @dev, along
- * with cleaning up any other stuff.  But we do that in the DRM core, so
- * this function can just return and hope that the core does its job.
- */
-static void drm_sysfs_device_release(struct device *dev)
-{
-       return;
-}
-
-/**
- * drm_sysfs_device_add - adds a class device to sysfs for a character driver
- * @dev: DRM device to be added
- * @head: DRM head in question
- *
- * Add a DRM device to the DRM's device model class.  We use @dev's PCI device
- * as the parent for the Linux device, and make sure it has a file containing
- * the driver we're using (for userspace compatibility).
- */
-int drm_sysfs_device_add(struct drm_minor *minor)
-{
-       int err;
-       int i, j;
-       char *minor_str;
-
-       minor->kdev.parent = &minor->dev->pdev->dev;
-       minor->kdev.class = drm_class;
-       minor->kdev.release = drm_sysfs_device_release;
-       minor->kdev.devt = minor->device;
-       minor_str = "card%d";
-
-       snprintf(minor->kdev.bus_id, BUS_ID_SIZE, minor_str, minor->index);
-
-       err = device_register(&minor->kdev);
-       if (err) {
-               DRM_ERROR("device add failed: %d\n", err);
-               goto err_out;
-       }
-
-       for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
-               err = device_create_file(&minor->kdev, &device_attrs[i]);
-               if (err)
-                       goto err_out_files;
-       }
-
-       return 0;
-
-err_out_files:
-       if (i > 0)
-               for (j = 0; j < i; j++)
-                       device_remove_file(&minor->kdev, &device_attrs[i]);
-       device_unregister(&minor->kdev);
-err_out:
-
-       return err;
-}
-
-/**
- * drm_sysfs_device_remove - remove DRM device
- * @dev: DRM device to remove
- *
- * This call unregisters and cleans up a class device that was created with a
- * call to drm_sysfs_device_add()
- */
-void drm_sysfs_device_remove(struct drm_minor *minor)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
-               device_remove_file(&minor->kdev, &device_attrs[i]);
-       device_unregister(&minor->kdev);
-}
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
deleted file mode 100644 (file)
index c234c6f..0000000
+++ /dev/null
@@ -1,673 +0,0 @@
-/**
- * \file drm_vm.c
- * Memory mapping for DRM
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#if defined(__ia64__)
-#include <linux/efi.h>
-#endif
-
-static void drm_vm_open(struct vm_area_struct *vma);
-static void drm_vm_close(struct vm_area_struct *vma);
-
-static pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma)
-{
-       pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
-
-#if defined(__i386__) || defined(__x86_64__)
-       if (boot_cpu_data.x86 > 3 && map_type != _DRM_AGP) {
-               pgprot_val(tmp) |= _PAGE_PCD;
-               pgprot_val(tmp) &= ~_PAGE_PWT;
-       }
-#elif defined(__powerpc__)
-       pgprot_val(tmp) |= _PAGE_NO_CACHE;
-       if (map_type == _DRM_REGISTERS)
-               pgprot_val(tmp) |= _PAGE_GUARDED;
-#elif defined(__ia64__)
-       if (efi_range_is_wc(vma->vm_start, vma->vm_end -
-                                   vma->vm_start))
-               tmp = pgprot_writecombine(tmp);
-       else
-               tmp = pgprot_noncached(tmp);
-#elif defined(__sparc__)
-       tmp = pgprot_noncached(tmp);
-#endif
-       return tmp;
-}
-
-static pgprot_t drm_dma_prot(uint32_t map_type, struct vm_area_struct *vma)
-{
-       pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
-
-#if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
-       tmp |= _PAGE_NO_CACHE;
-#endif
-       return tmp;
-}
-
-/**
- * \c fault method for AGP virtual memory.
- *
- * \param vma virtual memory area.
- * \param address access address.
- * \return pointer to the page structure.
- *
- * Find the right map and if it's AGP memory find the real physical page to
- * map, get the page, increment the use count and return it.
- */
-#if __OS_HAS_AGP
-static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_map *map = NULL;
-       struct drm_map_list *r_list;
-       struct drm_hash_item *hash;
-
-       /*
-        * Find the right map
-        */
-       if (!drm_core_has_AGP(dev))
-               goto vm_fault_error;
-
-       if (!dev->agp || !dev->agp->cant_use_aperture)
-               goto vm_fault_error;
-
-       if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
-               goto vm_fault_error;
-
-       r_list = drm_hash_entry(hash, struct drm_map_list, hash);
-       map = r_list->map;
-
-       if (map && map->type == _DRM_AGP) {
-               /*
-                * Using vm_pgoff as a selector forces us to use this unusual
-                * addressing scheme.
-                */
-               unsigned long offset = (unsigned long)vmf->virtual_address -
-                                                               vma->vm_start;
-               unsigned long baddr = map->offset + offset;
-               struct drm_agp_mem *agpmem;
-               struct page *page;
-
-#ifdef __alpha__
-               /*
-                * Adjust to a bus-relative address
-                */
-               baddr -= dev->hose->mem_space->start;
-#endif
-
-               /*
-                * It's AGP memory - find the real physical page to map
-                */
-               list_for_each_entry(agpmem, &dev->agp->memory, head) {
-                       if (agpmem->bound <= baddr &&
-                           agpmem->bound + agpmem->pages * PAGE_SIZE > baddr)
-                               break;
-               }
-
-               if (!agpmem)
-                       goto vm_fault_error;
-
-               /*
-                * Get the page, inc the use count, and return it
-                */
-               offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
-               page = virt_to_page(__va(agpmem->memory->memory[offset]));
-               get_page(page);
-               vmf->page = page;
-
-               DRM_DEBUG
-                   ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
-                    baddr, __va(agpmem->memory->memory[offset]), offset,
-                    page_count(page));
-               return 0;
-       }
-vm_fault_error:
-       return VM_FAULT_SIGBUS; /* Disallow mremap */
-}
-#else                          /* __OS_HAS_AGP */
-static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       return VM_FAULT_SIGBUS;
-}
-#endif                         /* __OS_HAS_AGP */
-
-/**
- * \c nopage method for shared virtual memory.
- *
- * \param vma virtual memory area.
- * \param address access address.
- * \return pointer to the page structure.
- *
- * Get the mapping, find the real physical page to map, get the page, and
- * return it.
- */
-static int drm_do_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct drm_map *map = (struct drm_map *) vma->vm_private_data;
-       unsigned long offset;
-       unsigned long i;
-       struct page *page;
-
-       if (!map)
-               return VM_FAULT_SIGBUS; /* Nothing allocated */
-
-       offset = (unsigned long)vmf->virtual_address - vma->vm_start;
-       i = (unsigned long)map->handle + offset;
-       page = vmalloc_to_page((void *)i);
-       if (!page)
-               return VM_FAULT_SIGBUS;
-       get_page(page);
-       vmf->page = page;
-
-       DRM_DEBUG("shm_fault 0x%lx\n", offset);
-       return 0;
-}
-
-/**
- * \c close method for shared virtual memory.
- *
- * \param vma virtual memory area.
- *
- * Deletes map information if we are the last
- * person to close a mapping and it's not in the global maplist.
- */
-static void drm_vm_shm_close(struct vm_area_struct *vma)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_vma_entry *pt, *temp;
-       struct drm_map *map;
-       struct drm_map_list *r_list;
-       int found_maps = 0;
-
-       DRM_DEBUG("0x%08lx,0x%08lx\n",
-                 vma->vm_start, vma->vm_end - vma->vm_start);
-       atomic_dec(&dev->vma_count);
-
-       map = vma->vm_private_data;
-
-       mutex_lock(&dev->struct_mutex);
-       list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
-               if (pt->vma->vm_private_data == map)
-                       found_maps++;
-               if (pt->vma == vma) {
-                       list_del(&pt->head);
-                       drm_free(pt, sizeof(*pt), DRM_MEM_VMAS);
-               }
-       }
-
-       /* We were the only map that was found */
-       if (found_maps == 1 && map->flags & _DRM_REMOVABLE) {
-               /* Check to see if we are in the maplist, if we are not, then
-                * we delete this mappings information.
-                */
-               found_maps = 0;
-               list_for_each_entry(r_list, &dev->maplist, head) {
-                       if (r_list->map == map)
-                               found_maps++;
-               }
-
-               if (!found_maps) {
-                       drm_dma_handle_t dmah;
-
-                       switch (map->type) {
-                       case _DRM_REGISTERS:
-                       case _DRM_FRAME_BUFFER:
-                               if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
-                                       int retcode;
-                                       retcode = mtrr_del(map->mtrr,
-                                                          map->offset,
-                                                          map->size);
-                                       DRM_DEBUG("mtrr_del = %d\n", retcode);
-                               }
-                               iounmap(map->handle);
-                               break;
-                       case _DRM_SHM:
-                               vfree(map->handle);
-                               break;
-                       case _DRM_AGP:
-                       case _DRM_SCATTER_GATHER:
-                               break;
-                       case _DRM_CONSISTENT:
-                               dmah.vaddr = map->handle;
-                               dmah.busaddr = map->offset;
-                               dmah.size = map->size;
-                               __drm_pci_free(dev, &dmah);
-                               break;
-                       }
-                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
-               }
-       }
-       mutex_unlock(&dev->struct_mutex);
-}
-
-/**
- * \c fault method for DMA virtual memory.
- *
- * \param vma virtual memory area.
- * \param address access address.
- * \return pointer to the page structure.
- *
- * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
- */
-static int drm_do_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_device_dma *dma = dev->dma;
-       unsigned long offset;
-       unsigned long page_nr;
-       struct page *page;
-
-       if (!dma)
-               return VM_FAULT_SIGBUS; /* Error */
-       if (!dma->pagelist)
-               return VM_FAULT_SIGBUS; /* Nothing allocated */
-
-       offset = (unsigned long)vmf->virtual_address - vma->vm_start;   /* vm_[pg]off[set] should be 0 */
-       page_nr = offset >> PAGE_SHIFT; /* page_nr could just be vmf->pgoff */
-       page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
-
-       get_page(page);
-       vmf->page = page;
-
-       DRM_DEBUG("dma_fault 0x%lx (page %lu)\n", offset, page_nr);
-       return 0;
-}
-
-/**
- * \c fault method for scatter-gather virtual memory.
- *
- * \param vma virtual memory area.
- * \param address access address.
- * \return pointer to the page structure.
- *
- * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
- */
-static int drm_do_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       struct drm_map *map = (struct drm_map *) vma->vm_private_data;
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_sg_mem *entry = dev->sg;
-       unsigned long offset;
-       unsigned long map_offset;
-       unsigned long page_offset;
-       struct page *page;
-
-       if (!entry)
-               return VM_FAULT_SIGBUS; /* Error */
-       if (!entry->pagelist)
-               return VM_FAULT_SIGBUS; /* Nothing allocated */
-
-       offset = (unsigned long)vmf->virtual_address - vma->vm_start;
-       map_offset = map->offset - (unsigned long)dev->sg->virtual;
-       page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
-       page = entry->pagelist[page_offset];
-       get_page(page);
-       vmf->page = page;
-
-       return 0;
-}
-
-static int drm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       return drm_do_vm_fault(vma, vmf);
-}
-
-static int drm_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       return drm_do_vm_shm_fault(vma, vmf);
-}
-
-static int drm_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       return drm_do_vm_dma_fault(vma, vmf);
-}
-
-static int drm_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
-{
-       return drm_do_vm_sg_fault(vma, vmf);
-}
-
-/** AGP virtual memory operations */
-static struct vm_operations_struct drm_vm_ops = {
-       .fault = drm_vm_fault,
-       .open = drm_vm_open,
-       .close = drm_vm_close,
-};
-
-/** Shared virtual memory operations */
-static struct vm_operations_struct drm_vm_shm_ops = {
-       .fault = drm_vm_shm_fault,
-       .open = drm_vm_open,
-       .close = drm_vm_shm_close,
-};
-
-/** DMA virtual memory operations */
-static struct vm_operations_struct drm_vm_dma_ops = {
-       .fault = drm_vm_dma_fault,
-       .open = drm_vm_open,
-       .close = drm_vm_close,
-};
-
-/** Scatter-gather virtual memory operations */
-static struct vm_operations_struct drm_vm_sg_ops = {
-       .fault = drm_vm_sg_fault,
-       .open = drm_vm_open,
-       .close = drm_vm_close,
-};
-
-/**
- * \c open method for shared virtual memory.
- *
- * \param vma virtual memory area.
- *
- * Create a new drm_vma_entry structure as the \p vma private data entry and
- * add it to drm_device::vmalist.
- */
-static void drm_vm_open_locked(struct vm_area_struct *vma)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_vma_entry *vma_entry;
-
-       DRM_DEBUG("0x%08lx,0x%08lx\n",
-                 vma->vm_start, vma->vm_end - vma->vm_start);
-       atomic_inc(&dev->vma_count);
-
-       vma_entry = drm_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
-       if (vma_entry) {
-               vma_entry->vma = vma;
-               vma_entry->pid = current->pid;
-               list_add(&vma_entry->head, &dev->vmalist);
-       }
-}
-
-static void drm_vm_open(struct vm_area_struct *vma)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-
-       mutex_lock(&dev->struct_mutex);
-       drm_vm_open_locked(vma);
-       mutex_unlock(&dev->struct_mutex);
-}
-
-/**
- * \c close method for all virtual memory types.
- *
- * \param vma virtual memory area.
- *
- * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
- * free it.
- */
-static void drm_vm_close(struct vm_area_struct *vma)
-{
-       struct drm_file *priv = vma->vm_file->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_vma_entry *pt, *temp;
-
-       DRM_DEBUG("0x%08lx,0x%08lx\n",
-                 vma->vm_start, vma->vm_end - vma->vm_start);
-       atomic_dec(&dev->vma_count);
-
-       mutex_lock(&dev->struct_mutex);
-       list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
-               if (pt->vma == vma) {
-                       list_del(&pt->head);
-                       drm_free(pt, sizeof(*pt), DRM_MEM_VMAS);
-                       break;
-               }
-       }
-       mutex_unlock(&dev->struct_mutex);
-}
-
-/**
- * mmap DMA memory.
- *
- * \param file_priv DRM file private.
- * \param vma virtual memory area.
- * \return zero on success or a negative number on failure.
- *
- * Sets the virtual memory area operations structure to vm_dma_ops, the file
- * pointer, and calls vm_open().
- */
-static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev;
-       struct drm_device_dma *dma;
-       unsigned long length = vma->vm_end - vma->vm_start;
-
-       dev = priv->minor->dev;
-       dma = dev->dma;
-       DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
-                 vma->vm_start, vma->vm_end, vma->vm_pgoff);
-
-       /* Length must match exact page count */
-       if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
-               return -EINVAL;
-       }
-
-       if (!capable(CAP_SYS_ADMIN) &&
-           (dma->flags & _DRM_DMA_USE_PCI_RO)) {
-               vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
-#if defined(__i386__) || defined(__x86_64__)
-               pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
-#else
-               /* Ye gads this is ugly.  With more thought
-                  we could move this up higher and use
-                  `protection_map' instead.  */
-               vma->vm_page_prot =
-                   __pgprot(pte_val
-                            (pte_wrprotect
-                             (__pte(pgprot_val(vma->vm_page_prot)))));
-#endif
-       }
-
-       vma->vm_ops = &drm_vm_dma_ops;
-
-       vma->vm_flags |= VM_RESERVED;   /* Don't swap */
-       vma->vm_flags |= VM_DONTEXPAND;
-
-       vma->vm_file = filp;    /* Needed for drm_vm_open() */
-       drm_vm_open_locked(vma);
-       return 0;
-}
-
-unsigned long drm_core_get_map_ofs(struct drm_map * map)
-{
-       return map->offset;
-}
-
-EXPORT_SYMBOL(drm_core_get_map_ofs);
-
-unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
-{
-#ifdef __alpha__
-       return dev->hose->dense_mem_base - dev->hose->mem_space->start;
-#else
-       return 0;
-#endif
-}
-
-EXPORT_SYMBOL(drm_core_get_reg_ofs);
-
-/**
- * mmap DMA memory.
- *
- * \param file_priv DRM file private.
- * \param vma virtual memory area.
- * \return zero on success or a negative number on failure.
- *
- * If the virtual memory area has no offset associated with it then it's a DMA
- * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
- * checks that the restricted flag is not set, sets the virtual memory operations
- * according to the mapping type and remaps the pages. Finally sets the file
- * pointer and calls vm_open().
- */
-static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       struct drm_map *map = NULL;
-       unsigned long offset = 0;
-       struct drm_hash_item *hash;
-
-       DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
-                 vma->vm_start, vma->vm_end, vma->vm_pgoff);
-
-       if (!priv->authenticated)
-               return -EACCES;
-
-       /* We check for "dma". On Apple's UniNorth, it's valid to have
-        * the AGP mapped at physical address 0
-        * --BenH.
-        */
-       if (!vma->vm_pgoff
-#if __OS_HAS_AGP
-           && (!dev->agp
-               || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
-#endif
-           )
-               return drm_mmap_dma(filp, vma);
-
-       if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash)) {
-               DRM_ERROR("Could not find map\n");
-               return -EINVAL;
-       }
-
-       map = drm_hash_entry(hash, struct drm_map_list, hash)->map;
-       if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
-               return -EPERM;
-
-       /* Check for valid size. */
-       if (map->size < vma->vm_end - vma->vm_start)
-               return -EINVAL;
-
-       if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
-               vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
-#if defined(__i386__) || defined(__x86_64__)
-               pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
-#else
-               /* Ye gads this is ugly.  With more thought
-                  we could move this up higher and use
-                  `protection_map' instead.  */
-               vma->vm_page_prot =
-                   __pgprot(pte_val
-                            (pte_wrprotect
-                             (__pte(pgprot_val(vma->vm_page_prot)))));
-#endif
-       }
-
-       switch (map->type) {
-       case _DRM_AGP:
-               if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
-                       /*
-                        * On some platforms we can't talk to bus dma address from the CPU, so for
-                        * memory of type DRM_AGP, we'll deal with sorting out the real physical
-                        * pages and mappings in fault()
-                        */
-#if defined(__powerpc__)
-                       pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
-#endif
-                       vma->vm_ops = &drm_vm_ops;
-                       break;
-               }
-               /* fall through to _DRM_FRAME_BUFFER... */
-       case _DRM_FRAME_BUFFER:
-       case _DRM_REGISTERS:
-               offset = dev->driver->get_reg_ofs(dev);
-               vma->vm_flags |= VM_IO; /* not in core dump */
-               vma->vm_page_prot = drm_io_prot(map->type, vma);
-               if (io_remap_pfn_range(vma, vma->vm_start,
-                                      (map->offset + offset) >> PAGE_SHIFT,
-                                      vma->vm_end - vma->vm_start,
-                                      vma->vm_page_prot))
-                       return -EAGAIN;
-               DRM_DEBUG("   Type = %d; start = 0x%lx, end = 0x%lx,"
-                         " offset = 0x%lx\n",
-                         map->type,
-                         vma->vm_start, vma->vm_end, map->offset + offset);
-               vma->vm_ops = &drm_vm_ops;
-               break;
-       case _DRM_CONSISTENT:
-               /* Consistent memory is really like shared memory. But
-                * it's allocated in a different way, so avoid fault */
-               if (remap_pfn_range(vma, vma->vm_start,
-                   page_to_pfn(virt_to_page(map->handle)),
-                   vma->vm_end - vma->vm_start, vma->vm_page_prot))
-                       return -EAGAIN;
-               vma->vm_page_prot = drm_dma_prot(map->type, vma);
-       /* fall through to _DRM_SHM */
-       case _DRM_SHM:
-               vma->vm_ops = &drm_vm_shm_ops;
-               vma->vm_private_data = (void *)map;
-               /* Don't let this area swap.  Change when
-                  DRM_KERNEL advisory is supported. */
-               vma->vm_flags |= VM_RESERVED;
-               break;
-       case _DRM_SCATTER_GATHER:
-               vma->vm_ops = &drm_vm_sg_ops;
-               vma->vm_private_data = (void *)map;
-               vma->vm_flags |= VM_RESERVED;
-               vma->vm_page_prot = drm_dma_prot(map->type, vma);
-               break;
-       default:
-               return -EINVAL; /* This should never happen. */
-       }
-       vma->vm_flags |= VM_RESERVED;   /* Don't swap */
-       vma->vm_flags |= VM_DONTEXPAND;
-
-       vma->vm_file = filp;    /* Needed for drm_vm_open() */
-       drm_vm_open_locked(vma);
-       return 0;
-}
-
-int drm_mmap(struct file *filp, struct vm_area_struct *vma)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev = priv->minor->dev;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_mmap_locked(filp, vma);
-       mutex_unlock(&dev->struct_mutex);
-
-       return ret;
-}
-EXPORT_SYMBOL(drm_mmap);
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
deleted file mode 100644 (file)
index e5de8ea..0000000
+++ /dev/null
@@ -1,1283 +0,0 @@
-/* i810_dma.c -- DMA support for the i810 -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
- *         Jeff Hartmann <jhartmann@valinux.com>
- *          Keith Whitwell <keith@tungstengraphics.com>
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i810_drm.h"
-#include "i810_drv.h"
-#include <linux/interrupt.h>   /* For task queue support */
-#include <linux/delay.h>
-#include <linux/pagemap.h>
-
-#define I810_BUF_FREE          2
-#define I810_BUF_CLIENT                1
-#define I810_BUF_HARDWARE      0
-
-#define I810_BUF_UNMAPPED 0
-#define I810_BUF_MAPPED   1
-
-static struct drm_buf *i810_freelist_get(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-       int used;
-
-       /* Linear search might not be the best solution */
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-               /* In use is already a pointer */
-               used = cmpxchg(buf_priv->in_use, I810_BUF_FREE,
-                              I810_BUF_CLIENT);
-               if (used == I810_BUF_FREE) {
-                       return buf;
-               }
-       }
-       return NULL;
-}
-
-/* This should only be called if the buffer is not sent to the hardware
- * yet, the hardware updates in use for us once its on the ring buffer.
- */
-
-static int i810_freelist_put(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-       int used;
-
-       /* In use is already a pointer */
-       used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE);
-       if (used != I810_BUF_CLIENT) {
-               DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev;
-       drm_i810_private_t *dev_priv;
-       struct drm_buf *buf;
-       drm_i810_buf_priv_t *buf_priv;
-
-       lock_kernel();
-       dev = priv->minor->dev;
-       dev_priv = dev->dev_private;
-       buf = dev_priv->mmap_buffer;
-       buf_priv = buf->dev_private;
-
-       vma->vm_flags |= (VM_IO | VM_DONTCOPY);
-       vma->vm_file = filp;
-
-       buf_priv->currently_mapped = I810_BUF_MAPPED;
-       unlock_kernel();
-
-       if (io_remap_pfn_range(vma, vma->vm_start,
-                              vma->vm_pgoff,
-                              vma->vm_end - vma->vm_start, vma->vm_page_prot))
-               return -EAGAIN;
-       return 0;
-}
-
-static const struct file_operations i810_buffer_fops = {
-       .open = drm_open,
-       .release = drm_release,
-       .ioctl = drm_ioctl,
-       .mmap = i810_mmap_buffers,
-       .fasync = drm_fasync,
-};
-
-static int i810_map_buffer(struct drm_buf * buf, struct drm_file *file_priv)
-{
-       struct drm_device *dev = file_priv->minor->dev;
-       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       const struct file_operations *old_fops;
-       int retcode = 0;
-
-       if (buf_priv->currently_mapped == I810_BUF_MAPPED)
-               return -EINVAL;
-
-       down_write(&current->mm->mmap_sem);
-       old_fops = file_priv->filp->f_op;
-       file_priv->filp->f_op = &i810_buffer_fops;
-       dev_priv->mmap_buffer = buf;
-       buf_priv->virtual = (void *)do_mmap(file_priv->filp, 0, buf->total,
-                                           PROT_READ | PROT_WRITE,
-                                           MAP_SHARED, buf->bus_address);
-       dev_priv->mmap_buffer = NULL;
-       file_priv->filp->f_op = old_fops;
-       if (IS_ERR(buf_priv->virtual)) {
-               /* Real error */
-               DRM_ERROR("mmap error\n");
-               retcode = PTR_ERR(buf_priv->virtual);
-               buf_priv->virtual = NULL;
-       }
-       up_write(&current->mm->mmap_sem);
-
-       return retcode;
-}
-
-static int i810_unmap_buffer(struct drm_buf * buf)
-{
-       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-       int retcode = 0;
-
-       if (buf_priv->currently_mapped != I810_BUF_MAPPED)
-               return -EINVAL;
-
-       down_write(&current->mm->mmap_sem);
-       retcode = do_munmap(current->mm,
-                           (unsigned long)buf_priv->virtual,
-                           (size_t) buf->total);
-       up_write(&current->mm->mmap_sem);
-
-       buf_priv->currently_mapped = I810_BUF_UNMAPPED;
-       buf_priv->virtual = NULL;
-
-       return retcode;
-}
-
-static int i810_dma_get_buffer(struct drm_device * dev, drm_i810_dma_t * d,
-                              struct drm_file *file_priv)
-{
-       struct drm_buf *buf;
-       drm_i810_buf_priv_t *buf_priv;
-       int retcode = 0;
-
-       buf = i810_freelist_get(dev);
-       if (!buf) {
-               retcode = -ENOMEM;
-               DRM_DEBUG("retcode=%d\n", retcode);
-               return retcode;
-       }
-
-       retcode = i810_map_buffer(buf, file_priv);
-       if (retcode) {
-               i810_freelist_put(dev, buf);
-               DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
-               return retcode;
-       }
-       buf->file_priv = file_priv;
-       buf_priv = buf->dev_private;
-       d->granted = 1;
-       d->request_idx = buf->idx;
-       d->request_size = buf->total;
-       d->virtual = buf_priv->virtual;
-
-       return retcode;
-}
-
-static int i810_dma_cleanup(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (drm_core_check_feature(dev, DRIVER_HAVE_IRQ) && dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-       if (dev->dev_private) {
-               int i;
-               drm_i810_private_t *dev_priv =
-                   (drm_i810_private_t *) dev->dev_private;
-
-               if (dev_priv->ring.virtual_start) {
-                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
-               }
-               if (dev_priv->hw_status_page) {
-                       pci_free_consistent(dev->pdev, PAGE_SIZE,
-                                           dev_priv->hw_status_page,
-                                           dev_priv->dma_status_page);
-                       /* Need to rewrite hardware status page */
-                       I810_WRITE(0x02080, 0x1ffff000);
-               }
-               drm_free(dev->dev_private, sizeof(drm_i810_private_t),
-                        DRM_MEM_DRIVER);
-               dev->dev_private = NULL;
-
-               for (i = 0; i < dma->buf_count; i++) {
-                       struct drm_buf *buf = dma->buflist[i];
-                       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-
-                       if (buf_priv->kernel_virtual && buf->total)
-                               drm_core_ioremapfree(&buf_priv->map, dev);
-               }
-       }
-       return 0;
-}
-
-static int i810_wait_ring(struct drm_device * dev, int n)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
-       int iters = 0;
-       unsigned long end;
-       unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-
-       end = jiffies + (HZ * 3);
-       while (ring->space < n) {
-               ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-               ring->space = ring->head - (ring->tail + 8);
-               if (ring->space < 0)
-                       ring->space += ring->Size;
-
-               if (ring->head != last_head) {
-                       end = jiffies + (HZ * 3);
-                       last_head = ring->head;
-               }
-
-               iters++;
-               if (time_before(end, jiffies)) {
-                       DRM_ERROR("space: %d wanted %d\n", ring->space, n);
-                       DRM_ERROR("lockup\n");
-                       goto out_wait_ring;
-               }
-               udelay(1);
-       }
-
-      out_wait_ring:
-       return iters;
-}
-
-static void i810_kernel_lost_context(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
-
-       ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-       ring->tail = I810_READ(LP_RING + RING_TAIL);
-       ring->space = ring->head - (ring->tail + 8);
-       if (ring->space < 0)
-               ring->space += ring->Size;
-}
-
-static int i810_freelist_init(struct drm_device * dev, drm_i810_private_t * dev_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int my_idx = 24;
-       u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
-       int i;
-
-       if (dma->buf_count > 1019) {
-               /* Not enough space in the status page for the freelist */
-               return -EINVAL;
-       }
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-
-               buf_priv->in_use = hw_status++;
-               buf_priv->my_use_idx = my_idx;
-               my_idx += 4;
-
-               *buf_priv->in_use = I810_BUF_FREE;
-
-               buf_priv->map.offset = buf->bus_address;
-               buf_priv->map.size = buf->total;
-               buf_priv->map.type = _DRM_AGP;
-               buf_priv->map.flags = 0;
-               buf_priv->map.mtrr = 0;
-
-               drm_core_ioremap(&buf_priv->map, dev);
-               buf_priv->kernel_virtual = buf_priv->map.handle;
-
-       }
-       return 0;
-}
-
-static int i810_dma_initialize(struct drm_device * dev,
-                              drm_i810_private_t * dev_priv,
-                              drm_i810_init_t * init)
-{
-       struct drm_map_list *r_list;
-       memset(dev_priv, 0, sizeof(drm_i810_private_t));
-
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               if (r_list->map &&
-                   r_list->map->type == _DRM_SHM &&
-                   r_list->map->flags & _DRM_CONTAINS_LOCK) {
-                       dev_priv->sarea_map = r_list->map;
-                       break;
-               }
-       }
-       if (!dev_priv->sarea_map) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("can not find sarea!\n");
-               return -EINVAL;
-       }
-       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
-       if (!dev_priv->mmio_map) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("can not find mmio map!\n");
-               return -EINVAL;
-       }
-       dev->agp_buffer_token = init->buffers_offset;
-       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
-       if (!dev->agp_buffer_map) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("can not find dma buffer map!\n");
-               return -EINVAL;
-       }
-
-       dev_priv->sarea_priv = (drm_i810_sarea_t *)
-           ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
-
-       dev_priv->ring.Start = init->ring_start;
-       dev_priv->ring.End = init->ring_end;
-       dev_priv->ring.Size = init->ring_size;
-
-       dev_priv->ring.map.offset = dev->agp->base + init->ring_start;
-       dev_priv->ring.map.size = init->ring_size;
-       dev_priv->ring.map.type = _DRM_AGP;
-       dev_priv->ring.map.flags = 0;
-       dev_priv->ring.map.mtrr = 0;
-
-       drm_core_ioremap(&dev_priv->ring.map, dev);
-
-       if (dev_priv->ring.map.handle == NULL) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("can not ioremap virtual address for"
-                         " ring buffer\n");
-               return -ENOMEM;
-       }
-
-       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
-
-       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
-
-       dev_priv->w = init->w;
-       dev_priv->h = init->h;
-       dev_priv->pitch = init->pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->front_offset = init->front_offset;
-
-       dev_priv->overlay_offset = init->overlay_offset;
-       dev_priv->overlay_physical = init->overlay_physical;
-
-       dev_priv->front_di1 = init->front_offset | init->pitch_bits;
-       dev_priv->back_di1 = init->back_offset | init->pitch_bits;
-       dev_priv->zi1 = init->depth_offset | init->pitch_bits;
-
-       /* Program Hardware Status Page */
-       dev_priv->hw_status_page =
-           pci_alloc_consistent(dev->pdev, PAGE_SIZE,
-                                &dev_priv->dma_status_page);
-       if (!dev_priv->hw_status_page) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("Can not allocate hardware status page\n");
-               return -ENOMEM;
-       }
-       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
-
-       I810_WRITE(0x02080, dev_priv->dma_status_page);
-       DRM_DEBUG("Enabled hardware status page\n");
-
-       /* Now we need to init our freelist */
-       if (i810_freelist_init(dev, dev_priv) != 0) {
-               dev->dev_private = (void *)dev_priv;
-               i810_dma_cleanup(dev);
-               DRM_ERROR("Not enough space in the status page for"
-                         " the freelist\n");
-               return -ENOMEM;
-       }
-       dev->dev_private = (void *)dev_priv;
-
-       return 0;
-}
-
-static int i810_dma_init(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv;
-       drm_i810_init_t *init = data;
-       int retcode = 0;
-
-       switch (init->func) {
-       case I810_INIT_DMA_1_4:
-               DRM_INFO("Using v1.4 init.\n");
-               dev_priv = drm_alloc(sizeof(drm_i810_private_t),
-                                    DRM_MEM_DRIVER);
-               if (dev_priv == NULL)
-                       return -ENOMEM;
-               retcode = i810_dma_initialize(dev, dev_priv, init);
-               break;
-
-       case I810_CLEANUP_DMA:
-               DRM_INFO("DMA Cleanup\n");
-               retcode = i810_dma_cleanup(dev);
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       return retcode;
-}
-
-/* Most efficient way to verify state for the i810 is as it is
- * emitted.  Non-conformant state is silently dropped.
- *
- * Use 'volatile' & local var tmp to force the emitted values to be
- * identical to the verified ones.
- */
-static void i810EmitContextVerified(struct drm_device * dev,
-                                   volatile unsigned int *code)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       int i, j = 0;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(I810_CTX_SETUP_SIZE);
-
-       OUT_RING(GFX_OP_COLOR_FACTOR);
-       OUT_RING(code[I810_CTXREG_CF1]);
-
-       OUT_RING(GFX_OP_STIPPLE);
-       OUT_RING(code[I810_CTXREG_ST1]);
-
-       for (i = 4; i < I810_CTX_SETUP_SIZE; i++) {
-               tmp = code[i];
-
-               if ((tmp & (7 << 29)) == (3 << 29) &&
-                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
-                       OUT_RING(tmp);
-                       j++;
-               } else
-                       printk("constext state dropped!!!\n");
-       }
-
-       if (j & 1)
-               OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-static void i810EmitTexVerified(struct drm_device * dev, volatile unsigned int *code)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       int i, j = 0;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(I810_TEX_SETUP_SIZE);
-
-       OUT_RING(GFX_OP_MAP_INFO);
-       OUT_RING(code[I810_TEXREG_MI1]);
-       OUT_RING(code[I810_TEXREG_MI2]);
-       OUT_RING(code[I810_TEXREG_MI3]);
-
-       for (i = 4; i < I810_TEX_SETUP_SIZE; i++) {
-               tmp = code[i];
-
-               if ((tmp & (7 << 29)) == (3 << 29) &&
-                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
-                       OUT_RING(tmp);
-                       j++;
-               } else
-                       printk("texture state dropped!!!\n");
-       }
-
-       if (j & 1)
-               OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-/* Need to do some additional checking when setting the dest buffer.
- */
-static void i810EmitDestVerified(struct drm_device * dev,
-                                volatile unsigned int *code)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
-
-       tmp = code[I810_DESTREG_DI1];
-       if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
-               OUT_RING(CMD_OP_DESTBUFFER_INFO);
-               OUT_RING(tmp);
-       } else
-               DRM_DEBUG("bad di1 %x (allow %x or %x)\n",
-                         tmp, dev_priv->front_di1, dev_priv->back_di1);
-
-       /* invarient:
-        */
-       OUT_RING(CMD_OP_Z_BUFFER_INFO);
-       OUT_RING(dev_priv->zi1);
-
-       OUT_RING(GFX_OP_DESTBUFFER_VARS);
-       OUT_RING(code[I810_DESTREG_DV1]);
-
-       OUT_RING(GFX_OP_DRAWRECT_INFO);
-       OUT_RING(code[I810_DESTREG_DR1]);
-       OUT_RING(code[I810_DESTREG_DR2]);
-       OUT_RING(code[I810_DESTREG_DR3]);
-       OUT_RING(code[I810_DESTREG_DR4]);
-       OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-static void i810EmitState(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-
-       DRM_DEBUG("%x\n", dirty);
-
-       if (dirty & I810_UPLOAD_BUFFERS) {
-               i810EmitDestVerified(dev, sarea_priv->BufferState);
-               sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS;
-       }
-
-       if (dirty & I810_UPLOAD_CTX) {
-               i810EmitContextVerified(dev, sarea_priv->ContextState);
-               sarea_priv->dirty &= ~I810_UPLOAD_CTX;
-       }
-
-       if (dirty & I810_UPLOAD_TEX0) {
-               i810EmitTexVerified(dev, sarea_priv->TexState[0]);
-               sarea_priv->dirty &= ~I810_UPLOAD_TEX0;
-       }
-
-       if (dirty & I810_UPLOAD_TEX1) {
-               i810EmitTexVerified(dev, sarea_priv->TexState[1]);
-               sarea_priv->dirty &= ~I810_UPLOAD_TEX1;
-       }
-}
-
-/* need to verify
- */
-static void i810_dma_dispatch_clear(struct drm_device * dev, int flags,
-                                   unsigned int clear_color,
-                                   unsigned int clear_zval)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int pitch = dev_priv->pitch;
-       int cpp = 2;
-       int i;
-       RING_LOCALS;
-
-       if (dev_priv->current_page == 1) {
-               unsigned int tmp = flags;
-
-               flags &= ~(I810_FRONT | I810_BACK);
-               if (tmp & I810_FRONT)
-                       flags |= I810_BACK;
-               if (tmp & I810_BACK)
-                       flags |= I810_FRONT;
-       }
-
-       i810_kernel_lost_context(dev);
-
-       if (nbox > I810_NR_SAREA_CLIPRECTS)
-               nbox = I810_NR_SAREA_CLIPRECTS;
-
-       for (i = 0; i < nbox; i++, pbox++) {
-               unsigned int x = pbox->x1;
-               unsigned int y = pbox->y1;
-               unsigned int width = (pbox->x2 - x) * cpp;
-               unsigned int height = pbox->y2 - y;
-               unsigned int start = y * pitch + x * cpp;
-
-               if (pbox->x1 > pbox->x2 ||
-                   pbox->y1 > pbox->y2 ||
-                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
-                       continue;
-
-               if (flags & I810_FRONT) {
-                       BEGIN_LP_RING(6);
-                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
-                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
-                       OUT_RING((height << 16) | width);
-                       OUT_RING(start);
-                       OUT_RING(clear_color);
-                       OUT_RING(0);
-                       ADVANCE_LP_RING();
-               }
-
-               if (flags & I810_BACK) {
-                       BEGIN_LP_RING(6);
-                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
-                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
-                       OUT_RING((height << 16) | width);
-                       OUT_RING(dev_priv->back_offset + start);
-                       OUT_RING(clear_color);
-                       OUT_RING(0);
-                       ADVANCE_LP_RING();
-               }
-
-               if (flags & I810_DEPTH) {
-                       BEGIN_LP_RING(6);
-                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
-                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
-                       OUT_RING((height << 16) | width);
-                       OUT_RING(dev_priv->depth_offset + start);
-                       OUT_RING(clear_zval);
-                       OUT_RING(0);
-                       ADVANCE_LP_RING();
-               }
-       }
-}
-
-static void i810_dma_dispatch_swap(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int pitch = dev_priv->pitch;
-       int cpp = 2;
-       int i;
-       RING_LOCALS;
-
-       DRM_DEBUG("swapbuffers\n");
-
-       i810_kernel_lost_context(dev);
-
-       if (nbox > I810_NR_SAREA_CLIPRECTS)
-               nbox = I810_NR_SAREA_CLIPRECTS;
-
-       for (i = 0; i < nbox; i++, pbox++) {
-               unsigned int w = pbox->x2 - pbox->x1;
-               unsigned int h = pbox->y2 - pbox->y1;
-               unsigned int dst = pbox->x1 * cpp + pbox->y1 * pitch;
-               unsigned int start = dst;
-
-               if (pbox->x1 > pbox->x2 ||
-                   pbox->y1 > pbox->y2 ||
-                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
-                       continue;
-
-               BEGIN_LP_RING(6);
-               OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4);
-               OUT_RING(pitch | (0xCC << 16));
-               OUT_RING((h << 16) | (w * cpp));
-               if (dev_priv->current_page == 0)
-                       OUT_RING(dev_priv->front_offset + start);
-               else
-                       OUT_RING(dev_priv->back_offset + start);
-               OUT_RING(pitch);
-               if (dev_priv->current_page == 0)
-                       OUT_RING(dev_priv->back_offset + start);
-               else
-                       OUT_RING(dev_priv->front_offset + start);
-               ADVANCE_LP_RING();
-       }
-}
-
-static void i810_dma_dispatch_vertex(struct drm_device * dev,
-                                    struct drm_buf * buf, int discard, int used)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_clip_rect *box = sarea_priv->boxes;
-       int nbox = sarea_priv->nbox;
-       unsigned long address = (unsigned long)buf->bus_address;
-       unsigned long start = address - dev->agp->base;
-       int i = 0;
-       RING_LOCALS;
-
-       i810_kernel_lost_context(dev);
-
-       if (nbox > I810_NR_SAREA_CLIPRECTS)
-               nbox = I810_NR_SAREA_CLIPRECTS;
-
-       if (used > 4 * 1024)
-               used = 0;
-
-       if (sarea_priv->dirty)
-               i810EmitState(dev);
-
-       if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
-               unsigned int prim = (sarea_priv->vertex_prim & PR_MASK);
-
-               *(u32 *) buf_priv->kernel_virtual =
-                   ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
-
-               if (used & 4) {
-                       *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0;
-                       used += 4;
-               }
-
-               i810_unmap_buffer(buf);
-       }
-
-       if (used) {
-               do {
-                       if (i < nbox) {
-                               BEGIN_LP_RING(4);
-                               OUT_RING(GFX_OP_SCISSOR | SC_UPDATE_SCISSOR |
-                                        SC_ENABLE);
-                               OUT_RING(GFX_OP_SCISSOR_INFO);
-                               OUT_RING(box[i].x1 | (box[i].y1 << 16));
-                               OUT_RING((box[i].x2 -
-                                         1) | ((box[i].y2 - 1) << 16));
-                               ADVANCE_LP_RING();
-                       }
-
-                       BEGIN_LP_RING(4);
-                       OUT_RING(CMD_OP_BATCH_BUFFER);
-                       OUT_RING(start | BB1_PROTECTED);
-                       OUT_RING(start + used - 4);
-                       OUT_RING(0);
-                       ADVANCE_LP_RING();
-
-               } while (++i < nbox);
-       }
-
-       if (discard) {
-               dev_priv->counter++;
-
-               (void)cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
-                             I810_BUF_HARDWARE);
-
-               BEGIN_LP_RING(8);
-               OUT_RING(CMD_STORE_DWORD_IDX);
-               OUT_RING(20);
-               OUT_RING(dev_priv->counter);
-               OUT_RING(CMD_STORE_DWORD_IDX);
-               OUT_RING(buf_priv->my_use_idx);
-               OUT_RING(I810_BUF_FREE);
-               OUT_RING(CMD_REPORT_HEAD);
-               OUT_RING(0);
-               ADVANCE_LP_RING();
-       }
-}
-
-static void i810_dma_dispatch_flip(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       int pitch = dev_priv->pitch;
-       RING_LOCALS;
-
-       DRM_DEBUG("page=%d pfCurrentPage=%d\n",
-                 dev_priv->current_page,
-                 dev_priv->sarea_priv->pf_current_page);
-
-       i810_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(2);
-       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
-       /* On i815 at least ASYNC is buggy */
-       /* pitch<<5 is from 11.2.8 p158,
-          its the pitch / 8 then left shifted 8,
-          so (pitch >> 3) << 8 */
-       OUT_RING(CMD_OP_FRONTBUFFER_INFO | (pitch << 5) /*| ASYNC_FLIP */ );
-       if (dev_priv->current_page == 0) {
-               OUT_RING(dev_priv->back_offset);
-               dev_priv->current_page = 1;
-       } else {
-               OUT_RING(dev_priv->front_offset);
-               dev_priv->current_page = 0;
-       }
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(2);
-       OUT_RING(CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       /* Increment the frame counter.  The client-side 3D driver must
-        * throttle the framerate by waiting for this value before
-        * performing the swapbuffer ioctl.
-        */
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-
-}
-
-static void i810_dma_quiescent(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       i810_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(4);
-       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-       OUT_RING(CMD_REPORT_HEAD);
-       OUT_RING(0);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       i810_wait_ring(dev, dev_priv->ring.Size - 8);
-}
-
-static int i810_flush_queue(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       int i, ret = 0;
-       RING_LOCALS;
-
-       i810_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(2);
-       OUT_RING(CMD_REPORT_HEAD);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       i810_wait_ring(dev, dev_priv->ring.Size - 8);
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-
-               int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE,
-                                  I810_BUF_FREE);
-
-               if (used == I810_BUF_HARDWARE)
-                       DRM_DEBUG("reclaimed from HARDWARE\n");
-               if (used == I810_BUF_CLIENT)
-                       DRM_DEBUG("still on client\n");
-       }
-
-       return ret;
-}
-
-/* Must be called with the lock held */
-static void i810_reclaim_buffers(struct drm_device * dev,
-                                struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-
-       if (!dma)
-               return;
-       if (!dev->dev_private)
-               return;
-       if (!dma->buflist)
-               return;
-
-       i810_flush_queue(dev);
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-
-               if (buf->file_priv == file_priv && buf_priv) {
-                       int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
-                                          I810_BUF_FREE);
-
-                       if (used == I810_BUF_CLIENT)
-                               DRM_DEBUG("reclaimed from client\n");
-                       if (buf_priv->currently_mapped == I810_BUF_MAPPED)
-                               buf_priv->currently_mapped = I810_BUF_UNMAPPED;
-               }
-       }
-}
-
-static int i810_flush_ioctl(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv)
-{
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       i810_flush_queue(dev);
-       return 0;
-}
-
-static int i810_dma_vertex(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-           dev_priv->sarea_priv;
-       drm_i810_vertex_t *vertex = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("idx %d used %d discard %d\n",
-                 vertex->idx, vertex->used, vertex->discard);
-
-       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
-               return -EINVAL;
-
-       i810_dma_dispatch_vertex(dev,
-                                dma->buflist[vertex->idx],
-                                vertex->discard, vertex->used);
-
-       atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
-       atomic_inc(&dev->counts[_DRM_STAT_DMA]);
-       sarea_priv->last_enqueue = dev_priv->counter - 1;
-       sarea_priv->last_dispatch = (int)hw_status[5];
-
-       return 0;
-}
-
-static int i810_clear_bufs(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv)
-{
-       drm_i810_clear_t *clear = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* GH: Someone's doing nasty things... */
-       if (!dev->dev_private) {
-               return -EINVAL;
-       }
-
-       i810_dma_dispatch_clear(dev, clear->flags,
-                               clear->clear_color, clear->clear_depth);
-       return 0;
-}
-
-static int i810_swap_bufs(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       i810_dma_dispatch_swap(dev);
-       return 0;
-}
-
-static int i810_getage(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-           dev_priv->sarea_priv;
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-       return 0;
-}
-
-static int i810_getbuf(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       int retcode = 0;
-       drm_i810_dma_t *d = data;
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-           dev_priv->sarea_priv;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       d->granted = 0;
-
-       retcode = i810_dma_get_buffer(dev, d, file_priv);
-
-       DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n",
-                 task_pid_nr(current), retcode, d->granted);
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-
-       return retcode;
-}
-
-static int i810_copybuf(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       /* Never copy - 2.4.x doesn't need it */
-       return 0;
-}
-
-static int i810_docopy(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       /* Never copy - 2.4.x doesn't need it */
-       return 0;
-}
-
-static void i810_dma_dispatch_mc(struct drm_device * dev, struct drm_buf * buf, int used,
-                                unsigned int last_render)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
-       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned long address = (unsigned long)buf->bus_address;
-       unsigned long start = address - dev->agp->base;
-       int u;
-       RING_LOCALS;
-
-       i810_kernel_lost_context(dev);
-
-       u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_HARDWARE);
-       if (u != I810_BUF_CLIENT) {
-               DRM_DEBUG("MC found buffer that isn't mine!\n");
-       }
-
-       if (used > 4 * 1024)
-               used = 0;
-
-       sarea_priv->dirty = 0x7f;
-
-       DRM_DEBUG("addr 0x%lx, used 0x%x\n", address, used);
-
-       dev_priv->counter++;
-       DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
-       DRM_DEBUG("start : %lx\n", start);
-       DRM_DEBUG("used : %d\n", used);
-       DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
-
-       if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
-               if (used & 4) {
-                       *(u32 *) ((char *) buf_priv->virtual + used) = 0;
-                       used += 4;
-               }
-
-               i810_unmap_buffer(buf);
-       }
-       BEGIN_LP_RING(4);
-       OUT_RING(CMD_OP_BATCH_BUFFER);
-       OUT_RING(start | BB1_PROTECTED);
-       OUT_RING(start + used - 4);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(8);
-       OUT_RING(CMD_STORE_DWORD_IDX);
-       OUT_RING(buf_priv->my_use_idx);
-       OUT_RING(I810_BUF_FREE);
-       OUT_RING(0);
-
-       OUT_RING(CMD_STORE_DWORD_IDX);
-       OUT_RING(16);
-       OUT_RING(last_render);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-}
-
-static int i810_dma_mc(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
-           dev_priv->sarea_priv;
-       drm_i810_mc_t *mc = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (mc->idx >= dma->buf_count || mc->idx < 0)
-               return -EINVAL;
-
-       i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
-                            mc->last_render);
-
-       atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
-       atomic_inc(&dev->counts[_DRM_STAT_DMA]);
-       sarea_priv->last_enqueue = dev_priv->counter - 1;
-       sarea_priv->last_dispatch = (int)hw_status[5];
-
-       return 0;
-}
-
-static int i810_rstatus(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-
-       return (int)(((u32 *) (dev_priv->hw_status_page))[4]);
-}
-
-static int i810_ov0_info(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-       drm_i810_overlay_t *ov = data;
-
-       ov->offset = dev_priv->overlay_offset;
-       ov->physical = dev_priv->overlay_physical;
-
-       return 0;
-}
-
-static int i810_fstatus(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-       return I810_READ(0x30008);
-}
-
-static int i810_ov0_flip(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       //Tell the overlay to update
-       I810_WRITE(0x30000, dev_priv->overlay_physical | 0x80000000);
-
-       return 0;
-}
-
-/* Not sure why this isn't set all the time:
- */
-static void i810_do_init_pageflip(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-       dev_priv->page_flipping = 1;
-       dev_priv->current_page = 0;
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-}
-
-static int i810_do_cleanup_pageflip(struct drm_device * dev)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-       if (dev_priv->current_page != 0)
-               i810_dma_dispatch_flip(dev);
-
-       dev_priv->page_flipping = 0;
-       return 0;
-}
-
-static int i810_flip_bufs(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       drm_i810_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv->page_flipping)
-               i810_do_init_pageflip(dev);
-
-       i810_dma_dispatch_flip(dev);
-       return 0;
-}
-
-int i810_driver_load(struct drm_device *dev, unsigned long flags)
-{
-       /* i810 has 4 more counters */
-       dev->counters += 4;
-       dev->types[6] = _DRM_STAT_IRQ;
-       dev->types[7] = _DRM_STAT_PRIMARY;
-       dev->types[8] = _DRM_STAT_SECONDARY;
-       dev->types[9] = _DRM_STAT_DMA;
-
-       return 0;
-}
-
-void i810_driver_lastclose(struct drm_device * dev)
-{
-       i810_dma_cleanup(dev);
-}
-
-void i810_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
-{
-       if (dev->dev_private) {
-               drm_i810_private_t *dev_priv = dev->dev_private;
-               if (dev_priv->page_flipping) {
-                       i810_do_cleanup_pageflip(dev);
-               }
-       }
-}
-
-void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
-                                       struct drm_file *file_priv)
-{
-       i810_reclaim_buffers(dev, file_priv);
-}
-
-int i810_driver_dma_quiescent(struct drm_device * dev)
-{
-       i810_dma_quiescent(dev);
-       return 0;
-}
-
-struct drm_ioctl_desc i810_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_I810_INIT, i810_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I810_VERTEX, i810_dma_vertex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_CLEAR, i810_clear_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_FLUSH, i810_flush_ioctl, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_GETAGE, i810_getage, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_GETBUF, i810_getbuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_SWAP, i810_swap_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_COPY, i810_copybuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_DOCOPY, i810_docopy, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_OV0INFO, i810_ov0_info, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_FSTATUS, i810_fstatus, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_OV0FLIP, i810_ov0_flip, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_MC, i810_dma_mc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I810_RSTATUS, i810_rstatus, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I810_FLIP, i810_flip_bufs, DRM_AUTH)
-};
-
-int i810_max_ioctl = DRM_ARRAY_SIZE(i810_ioctls);
-
-/**
- * Determine if the device really is AGP or not.
- *
- * All Intel graphics chipsets are treated as AGP, even if they are really
- * PCI-e.
- *
- * \param dev   The device to be tested.
- *
- * \returns
- * A value of 1 is always retured to indictate every i810 is AGP.
- */
-int i810_driver_device_is_agp(struct drm_device * dev)
-{
-       return 1;
-}
diff --git a/drivers/char/drm/i810_drm.h b/drivers/char/drm/i810_drm.h
deleted file mode 100644 (file)
index 7a10bb6..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-#ifndef _I810_DRM_H_
-#define _I810_DRM_H_
-
-/* WARNING: These defines must be the same as what the Xserver uses.
- * if you change them, you must change the defines in the Xserver.
- */
-
-#ifndef _I810_DEFINES_
-#define _I810_DEFINES_
-
-#define I810_DMA_BUF_ORDER             12
-#define I810_DMA_BUF_SZ                (1<<I810_DMA_BUF_ORDER)
-#define I810_DMA_BUF_NR                256
-#define I810_NR_SAREA_CLIPRECTS        8
-
-/* Each region is a minimum of 64k, and there are at most 64 of them.
- */
-#define I810_NR_TEX_REGIONS 64
-#define I810_LOG_MIN_TEX_REGION_SIZE 16
-#endif
-
-#define I810_UPLOAD_TEX0IMAGE  0x1     /* handled clientside */
-#define I810_UPLOAD_TEX1IMAGE  0x2     /* handled clientside */
-#define I810_UPLOAD_CTX        0x4
-#define I810_UPLOAD_BUFFERS    0x8
-#define I810_UPLOAD_TEX0       0x10
-#define I810_UPLOAD_TEX1       0x20
-#define I810_UPLOAD_CLIPRECTS  0x40
-
-/* Indices into buf.Setup where various bits of state are mirrored per
- * context and per buffer.  These can be fired at the card as a unit,
- * or in a piecewise fashion as required.
- */
-
-/* Destbuffer state
- *    - backbuffer linear offset and pitch -- invarient in the current dri
- *    - zbuffer linear offset and pitch -- also invarient
- *    - drawing origin in back and depth buffers.
- *
- * Keep the depth/back buffer state here to accommodate private buffers
- * in the future.
- */
-#define I810_DESTREG_DI0  0    /* CMD_OP_DESTBUFFER_INFO (2 dwords) */
-#define I810_DESTREG_DI1  1
-#define I810_DESTREG_DV0  2    /* GFX_OP_DESTBUFFER_VARS (2 dwords) */
-#define I810_DESTREG_DV1  3
-#define I810_DESTREG_DR0  4    /* GFX_OP_DRAWRECT_INFO (4 dwords) */
-#define I810_DESTREG_DR1  5
-#define I810_DESTREG_DR2  6
-#define I810_DESTREG_DR3  7
-#define I810_DESTREG_DR4  8
-#define I810_DEST_SETUP_SIZE 10
-
-/* Context state
- */
-#define I810_CTXREG_CF0   0    /* GFX_OP_COLOR_FACTOR */
-#define I810_CTXREG_CF1   1
-#define I810_CTXREG_ST0   2    /* GFX_OP_STIPPLE */
-#define I810_CTXREG_ST1   3
-#define I810_CTXREG_VF    4    /* GFX_OP_VERTEX_FMT */
-#define I810_CTXREG_MT    5    /* GFX_OP_MAP_TEXELS */
-#define I810_CTXREG_MC0   6    /* GFX_OP_MAP_COLOR_STAGES - stage 0 */
-#define I810_CTXREG_MC1   7    /* GFX_OP_MAP_COLOR_STAGES - stage 1 */
-#define I810_CTXREG_MC2   8    /* GFX_OP_MAP_COLOR_STAGES - stage 2 */
-#define I810_CTXREG_MA0   9    /* GFX_OP_MAP_ALPHA_STAGES - stage 0 */
-#define I810_CTXREG_MA1   10   /* GFX_OP_MAP_ALPHA_STAGES - stage 1 */
-#define I810_CTXREG_MA2   11   /* GFX_OP_MAP_ALPHA_STAGES - stage 2 */
-#define I810_CTXREG_SDM   12   /* GFX_OP_SRC_DEST_MONO */
-#define I810_CTXREG_FOG   13   /* GFX_OP_FOG_COLOR */
-#define I810_CTXREG_B1    14   /* GFX_OP_BOOL_1 */
-#define I810_CTXREG_B2    15   /* GFX_OP_BOOL_2 */
-#define I810_CTXREG_LCS   16   /* GFX_OP_LINEWIDTH_CULL_SHADE_MODE */
-#define I810_CTXREG_PV    17   /* GFX_OP_PV_RULE -- Invarient! */
-#define I810_CTXREG_ZA    18   /* GFX_OP_ZBIAS_ALPHAFUNC */
-#define I810_CTXREG_AA    19   /* GFX_OP_ANTIALIAS */
-#define I810_CTX_SETUP_SIZE 20
-
-/* Texture state (per tex unit)
- */
-#define I810_TEXREG_MI0  0     /* GFX_OP_MAP_INFO (4 dwords) */
-#define I810_TEXREG_MI1  1
-#define I810_TEXREG_MI2  2
-#define I810_TEXREG_MI3  3
-#define I810_TEXREG_MF   4     /* GFX_OP_MAP_FILTER */
-#define I810_TEXREG_MLC  5     /* GFX_OP_MAP_LOD_CTL */
-#define I810_TEXREG_MLL  6     /* GFX_OP_MAP_LOD_LIMITS */
-#define I810_TEXREG_MCS  7     /* GFX_OP_MAP_COORD_SETS ??? */
-#define I810_TEX_SETUP_SIZE 8
-
-/* Flags for clear ioctl
- */
-#define I810_FRONT   0x1
-#define I810_BACK    0x2
-#define I810_DEPTH   0x4
-
-typedef enum _drm_i810_init_func {
-       I810_INIT_DMA = 0x01,
-       I810_CLEANUP_DMA = 0x02,
-       I810_INIT_DMA_1_4 = 0x03
-} drm_i810_init_func_t;
-
-/* This is the init structure after v1.2 */
-typedef struct _drm_i810_init {
-       drm_i810_init_func_t func;
-       unsigned int mmio_offset;
-       unsigned int buffers_offset;
-       int sarea_priv_offset;
-       unsigned int ring_start;
-       unsigned int ring_end;
-       unsigned int ring_size;
-       unsigned int front_offset;
-       unsigned int back_offset;
-       unsigned int depth_offset;
-       unsigned int overlay_offset;
-       unsigned int overlay_physical;
-       unsigned int w;
-       unsigned int h;
-       unsigned int pitch;
-       unsigned int pitch_bits;
-} drm_i810_init_t;
-
-/* This is the init structure prior to v1.2 */
-typedef struct _drm_i810_pre12_init {
-       drm_i810_init_func_t func;
-       unsigned int mmio_offset;
-       unsigned int buffers_offset;
-       int sarea_priv_offset;
-       unsigned int ring_start;
-       unsigned int ring_end;
-       unsigned int ring_size;
-       unsigned int front_offset;
-       unsigned int back_offset;
-       unsigned int depth_offset;
-       unsigned int w;
-       unsigned int h;
-       unsigned int pitch;
-       unsigned int pitch_bits;
-} drm_i810_pre12_init_t;
-
-/* Warning: If you change the SAREA structure you must change the Xserver
- * structure as well */
-
-typedef struct _drm_i810_tex_region {
-       unsigned char next, prev;       /* indices to form a circular LRU  */
-       unsigned char in_use;   /* owned by a client, or free? */
-       int age;                /* tracked by clients to update local LRU's */
-} drm_i810_tex_region_t;
-
-typedef struct _drm_i810_sarea {
-       unsigned int ContextState[I810_CTX_SETUP_SIZE];
-       unsigned int BufferState[I810_DEST_SETUP_SIZE];
-       unsigned int TexState[2][I810_TEX_SETUP_SIZE];
-       unsigned int dirty;
-
-       unsigned int nbox;
-       struct drm_clip_rect boxes[I810_NR_SAREA_CLIPRECTS];
-
-       /* Maintain an LRU of contiguous regions of texture space.  If
-        * you think you own a region of texture memory, and it has an
-        * age different to the one you set, then you are mistaken and
-        * it has been stolen by another client.  If global texAge
-        * hasn't changed, there is no need to walk the list.
-        *
-        * These regions can be used as a proxy for the fine-grained
-        * texture information of other clients - by maintaining them
-        * in the same lru which is used to age their own textures,
-        * clients have an approximate lru for the whole of global
-        * texture space, and can make informed decisions as to which
-        * areas to kick out.  There is no need to choose whether to
-        * kick out your own texture or someone else's - simply eject
-        * them all in LRU order.
-        */
-
-       drm_i810_tex_region_t texList[I810_NR_TEX_REGIONS + 1];
-       /* Last elt is sentinal */
-       int texAge;             /* last time texture was uploaded */
-       int last_enqueue;       /* last time a buffer was enqueued */
-       int last_dispatch;      /* age of the most recently dispatched buffer */
-       int last_quiescent;     /*  */
-       int ctxOwner;           /* last context to upload state */
-
-       int vertex_prim;
-
-       int pf_enabled;         /* is pageflipping allowed? */
-       int pf_active;
-       int pf_current_page;    /* which buffer is being displayed? */
-} drm_i810_sarea_t;
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the Xserver file (xf86drmMga.h)
- */
-
-/* i810 specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_I810_INIT          0x00
-#define DRM_I810_VERTEX                0x01
-#define DRM_I810_CLEAR         0x02
-#define DRM_I810_FLUSH         0x03
-#define DRM_I810_GETAGE                0x04
-#define DRM_I810_GETBUF                0x05
-#define DRM_I810_SWAP          0x06
-#define DRM_I810_COPY          0x07
-#define DRM_I810_DOCOPY                0x08
-#define DRM_I810_OV0INFO       0x09
-#define DRM_I810_FSTATUS       0x0a
-#define DRM_I810_OV0FLIP       0x0b
-#define DRM_I810_MC            0x0c
-#define DRM_I810_RSTATUS       0x0d
-#define DRM_I810_FLIP          0x0e
-
-#define DRM_IOCTL_I810_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_I810_INIT, drm_i810_init_t)
-#define DRM_IOCTL_I810_VERTEX          DRM_IOW( DRM_COMMAND_BASE + DRM_I810_VERTEX, drm_i810_vertex_t)
-#define DRM_IOCTL_I810_CLEAR           DRM_IOW( DRM_COMMAND_BASE + DRM_I810_CLEAR, drm_i810_clear_t)
-#define DRM_IOCTL_I810_FLUSH           DRM_IO(  DRM_COMMAND_BASE + DRM_I810_FLUSH)
-#define DRM_IOCTL_I810_GETAGE          DRM_IO(  DRM_COMMAND_BASE + DRM_I810_GETAGE)
-#define DRM_IOCTL_I810_GETBUF          DRM_IOWR(DRM_COMMAND_BASE + DRM_I810_GETBUF, drm_i810_dma_t)
-#define DRM_IOCTL_I810_SWAP            DRM_IO(  DRM_COMMAND_BASE + DRM_I810_SWAP)
-#define DRM_IOCTL_I810_COPY            DRM_IOW( DRM_COMMAND_BASE + DRM_I810_COPY, drm_i810_copy_t)
-#define DRM_IOCTL_I810_DOCOPY          DRM_IO(  DRM_COMMAND_BASE + DRM_I810_DOCOPY)
-#define DRM_IOCTL_I810_OV0INFO         DRM_IOR( DRM_COMMAND_BASE + DRM_I810_OV0INFO, drm_i810_overlay_t)
-#define DRM_IOCTL_I810_FSTATUS         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FSTATUS)
-#define DRM_IOCTL_I810_OV0FLIP         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_OV0FLIP)
-#define DRM_IOCTL_I810_MC              DRM_IOW( DRM_COMMAND_BASE + DRM_I810_MC, drm_i810_mc_t)
-#define DRM_IOCTL_I810_RSTATUS         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_RSTATUS)
-#define DRM_IOCTL_I810_FLIP             DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FLIP)
-
-typedef struct _drm_i810_clear {
-       int clear_color;
-       int clear_depth;
-       int flags;
-} drm_i810_clear_t;
-
-/* These may be placeholders if we have more cliprects than
- * I810_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
- * false, indicating that the buffer will be dispatched again with a
- * new set of cliprects.
- */
-typedef struct _drm_i810_vertex {
-       int idx;                /* buffer index */
-       int used;               /* nr bytes in use */
-       int discard;            /* client is finished with the buffer? */
-} drm_i810_vertex_t;
-
-typedef struct _drm_i810_copy_t {
-       int idx;                /* buffer index */
-       int used;               /* nr bytes in use */
-       void *address;          /* Address to copy from */
-} drm_i810_copy_t;
-
-#define PR_TRIANGLES         (0x0<<18)
-#define PR_TRISTRIP_0        (0x1<<18)
-#define PR_TRISTRIP_1        (0x2<<18)
-#define PR_TRIFAN            (0x3<<18)
-#define PR_POLYGON           (0x4<<18)
-#define PR_LINES             (0x5<<18)
-#define PR_LINESTRIP         (0x6<<18)
-#define PR_RECTS             (0x7<<18)
-#define PR_MASK              (0x7<<18)
-
-typedef struct drm_i810_dma {
-       void *virtual;
-       int request_idx;
-       int request_size;
-       int granted;
-} drm_i810_dma_t;
-
-typedef struct _drm_i810_overlay_t {
-       unsigned int offset;    /* Address of the Overlay Regs */
-       unsigned int physical;
-} drm_i810_overlay_t;
-
-typedef struct _drm_i810_mc {
-       int idx;                /* buffer index */
-       int used;               /* nr bytes in use */
-       int num_blocks;         /* number of GFXBlocks */
-       int *length;            /* List of lengths for GFXBlocks (FUTURE) */
-       unsigned int last_render;       /* Last Render Request */
-} drm_i810_mc_t;
-
-#endif                         /* _I810_DRM_H_ */
diff --git a/drivers/char/drm/i810_drv.c b/drivers/char/drm/i810_drv.c
deleted file mode 100644 (file)
index fabb9a8..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/* i810_drv.c -- I810 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Jeff Hartmann <jhartmann@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i810_drm.h"
-#include "i810_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       i810_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
-           DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
-       .dev_priv_size = sizeof(drm_i810_buf_priv_t),
-       .load = i810_driver_load,
-       .lastclose = i810_driver_lastclose,
-       .preclose = i810_driver_preclose,
-       .device_is_agp = i810_driver_device_is_agp,
-       .reclaim_buffers_locked = i810_driver_reclaim_buffers_locked,
-       .dma_quiescent = i810_driver_dma_quiescent,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = i810_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init i810_init(void)
-{
-       driver.num_ioctls = i810_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit i810_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(i810_init);
-module_exit(i810_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/i810_drv.h b/drivers/char/drm/i810_drv.h
deleted file mode 100644 (file)
index 0118849..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-/* i810_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
- *         Jeff Hartmann <jhartmann@valinux.com>
- *
- */
-
-#ifndef _I810_DRV_H_
-#define _I810_DRV_H_
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "VA Linux Systems Inc."
-
-#define DRIVER_NAME            "i810"
-#define DRIVER_DESC            "Intel i810"
-#define DRIVER_DATE            "20030605"
-
-/* Interface history
- *
- * 1.1   - XFree86 4.1
- * 1.2   - XvMC interfaces
- *       - XFree86 4.2
- * 1.2.1 - Disable copying code (leave stub ioctls for backwards compatibility)
- *       - Remove requirement for interrupt (leave stubs again)
- * 1.3   - Add page flipping.
- * 1.4   - fix DRM interface
- */
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           4
-#define DRIVER_PATCHLEVEL      0
-
-typedef struct drm_i810_buf_priv {
-       u32 *in_use;
-       int my_use_idx;
-       int currently_mapped;
-       void *virtual;
-       void *kernel_virtual;
-       drm_local_map_t map;
-} drm_i810_buf_priv_t;
-
-typedef struct _drm_i810_ring_buffer {
-       int tail_mask;
-       unsigned long Start;
-       unsigned long End;
-       unsigned long Size;
-       u8 *virtual_start;
-       int head;
-       int tail;
-       int space;
-       drm_local_map_t map;
-} drm_i810_ring_buffer_t;
-
-typedef struct drm_i810_private {
-       struct drm_map *sarea_map;
-       struct drm_map *mmio_map;
-
-       drm_i810_sarea_t *sarea_priv;
-       drm_i810_ring_buffer_t ring;
-
-       void *hw_status_page;
-       unsigned long counter;
-
-       dma_addr_t dma_status_page;
-
-       struct drm_buf *mmap_buffer;
-
-       u32 front_di1, back_di1, zi1;
-
-       int back_offset;
-       int depth_offset;
-       int overlay_offset;
-       int overlay_physical;
-       int w, h;
-       int pitch;
-       int back_pitch;
-       int depth_pitch;
-
-       int do_boxes;
-       int dma_used;
-
-       int current_page;
-       int page_flipping;
-
-       wait_queue_head_t irq_queue;
-       atomic_t irq_received;
-       atomic_t irq_emitted;
-
-       int front_offset;
-} drm_i810_private_t;
-
-                               /* i810_dma.c */
-extern int i810_driver_dma_quiescent(struct drm_device * dev);
-extern void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
-                                              struct drm_file *file_priv);
-extern int i810_driver_load(struct drm_device *, unsigned long flags);
-extern void i810_driver_lastclose(struct drm_device * dev);
-extern void i810_driver_preclose(struct drm_device * dev,
-                                struct drm_file *file_priv);
-extern void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
-                                              struct drm_file *file_priv);
-extern int i810_driver_device_is_agp(struct drm_device * dev);
-
-extern struct drm_ioctl_desc i810_ioctls[];
-extern int i810_max_ioctl;
-
-#define I810_BASE(reg)         ((unsigned long) \
-                               dev_priv->mmio_map->handle)
-#define I810_ADDR(reg)         (I810_BASE(reg) + reg)
-#define I810_DEREF(reg)                *(__volatile__ int *)I810_ADDR(reg)
-#define I810_READ(reg)         I810_DEREF(reg)
-#define I810_WRITE(reg,val)    do { I810_DEREF(reg) = val; } while (0)
-#define I810_DEREF16(reg)      *(__volatile__ u16 *)I810_ADDR(reg)
-#define I810_READ16(reg)       I810_DEREF16(reg)
-#define I810_WRITE16(reg,val)  do { I810_DEREF16(reg) = val; } while (0)
-
-#define I810_VERBOSE 0
-#define RING_LOCALS    unsigned int outring, ringmask; \
-                        volatile char *virt;
-
-#define BEGIN_LP_RING(n) do {                                          \
-       if (I810_VERBOSE)                                               \
-               DRM_DEBUG("BEGIN_LP_RING(%d)\n", n);                    \
-       if (dev_priv->ring.space < n*4)                                 \
-               i810_wait_ring(dev, n*4);                               \
-       dev_priv->ring.space -= n*4;                                    \
-       outring = dev_priv->ring.tail;                                  \
-       ringmask = dev_priv->ring.tail_mask;                            \
-       virt = dev_priv->ring.virtual_start;                            \
-} while (0)
-
-#define ADVANCE_LP_RING() do {                                 \
-       if (I810_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING\n");       \
-       dev_priv->ring.tail = outring;                          \
-       I810_WRITE(LP_RING + RING_TAIL, outring);               \
-} while(0)
-
-#define OUT_RING(n) do {                                               \
-       if (I810_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
-       *(volatile unsigned int *)(virt + outring) = n;                 \
-       outring += 4;                                                   \
-       outring &= ringmask;                                            \
-} while (0)
-
-#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
-#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
-#define CMD_REPORT_HEAD                        (7<<23)
-#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
-#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
-
-#define INST_PARSER_CLIENT   0x00000000
-#define INST_OP_FLUSH        0x02000000
-#define INST_FLUSH_MAP_CACHE 0x00000001
-
-#define BB1_START_ADDR_MASK   (~0x7)
-#define BB1_PROTECTED         (1<<0)
-#define BB1_UNPROTECTED       (0<<0)
-#define BB2_END_ADDR_MASK     (~0x7)
-
-#define I810REG_HWSTAM         0x02098
-#define I810REG_INT_IDENTITY_R 0x020a4
-#define I810REG_INT_MASK_R     0x020a8
-#define I810REG_INT_ENABLE_R   0x020a0
-
-#define LP_RING                        0x2030
-#define HP_RING                        0x2040
-#define RING_TAIL              0x00
-#define TAIL_ADDR              0x000FFFF8
-#define RING_HEAD              0x04
-#define HEAD_WRAP_COUNT                0xFFE00000
-#define HEAD_WRAP_ONE          0x00200000
-#define HEAD_ADDR              0x001FFFFC
-#define RING_START             0x08
-#define START_ADDR             0x00FFFFF8
-#define RING_LEN               0x0C
-#define RING_NR_PAGES          0x000FF000
-#define RING_REPORT_MASK       0x00000006
-#define RING_REPORT_64K                0x00000002
-#define RING_REPORT_128K       0x00000004
-#define RING_NO_REPORT         0x00000000
-#define RING_VALID_MASK                0x00000001
-#define RING_VALID             0x00000001
-#define RING_INVALID           0x00000000
-
-#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
-#define SC_UPDATE_SCISSOR       (0x1<<1)
-#define SC_ENABLE_MASK          (0x1<<0)
-#define SC_ENABLE               (0x1<<0)
-
-#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
-#define SCI_YMIN_MASK      (0xffff<<16)
-#define SCI_XMIN_MASK      (0xffff<<0)
-#define SCI_YMAX_MASK      (0xffff<<16)
-#define SCI_XMAX_MASK      (0xffff<<0)
-
-#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
-#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
-#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x2)
-#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
-#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
-#define GFX_OP_PRIMITIVE         ((0x3<<29)|(0x1f<<24))
-
-#define CMD_OP_Z_BUFFER_INFO     ((0x0<<29)|(0x16<<23))
-#define CMD_OP_DESTBUFFER_INFO   ((0x0<<29)|(0x15<<23))
-#define CMD_OP_FRONTBUFFER_INFO  ((0x0<<29)|(0x14<<23))
-#define CMD_OP_WAIT_FOR_EVENT    ((0x0<<29)|(0x03<<23))
-
-#define BR00_BITBLT_CLIENT   0x40000000
-#define BR00_OP_COLOR_BLT    0x10000000
-#define BR00_OP_SRC_COPY_BLT 0x10C00000
-#define BR13_SOLID_PATTERN   0x80000000
-
-#define WAIT_FOR_PLANE_A_SCANLINES (1<<1)
-#define WAIT_FOR_PLANE_A_FLIP      (1<<2)
-#define WAIT_FOR_VBLANK (1<<3)
-
-#endif
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
deleted file mode 100644 (file)
index a86ab30..0000000
+++ /dev/null
@@ -1,1553 +0,0 @@
-/* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
- *         Jeff Hartmann <jhartmann@valinux.com>
- *         Keith Whitwell <keith@tungstengraphics.com>
- *         Abraham vd Merwe <abraham@2d3d.co.za>
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i830_drm.h"
-#include "i830_drv.h"
-#include <linux/interrupt.h>   /* For task queue support */
-#include <linux/pagemap.h>
-#include <linux/delay.h>
-#include <asm/uaccess.h>
-
-#define I830_BUF_FREE          2
-#define I830_BUF_CLIENT                1
-#define I830_BUF_HARDWARE      0
-
-#define I830_BUF_UNMAPPED 0
-#define I830_BUF_MAPPED   1
-
-static struct drm_buf *i830_freelist_get(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-       int used;
-
-       /* Linear search might not be the best solution */
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-               /* In use is already a pointer */
-               used = cmpxchg(buf_priv->in_use, I830_BUF_FREE,
-                              I830_BUF_CLIENT);
-               if (used == I830_BUF_FREE) {
-                       return buf;
-               }
-       }
-       return NULL;
-}
-
-/* This should only be called if the buffer is not sent to the hardware
- * yet, the hardware updates in use for us once its on the ring buffer.
- */
-
-static int i830_freelist_put(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-       int used;
-
-       /* In use is already a pointer */
-       used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE);
-       if (used != I830_BUF_CLIENT) {
-               DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
-{
-       struct drm_file *priv = filp->private_data;
-       struct drm_device *dev;
-       drm_i830_private_t *dev_priv;
-       struct drm_buf *buf;
-       drm_i830_buf_priv_t *buf_priv;
-
-       lock_kernel();
-       dev = priv->minor->dev;
-       dev_priv = dev->dev_private;
-       buf = dev_priv->mmap_buffer;
-       buf_priv = buf->dev_private;
-
-       vma->vm_flags |= (VM_IO | VM_DONTCOPY);
-       vma->vm_file = filp;
-
-       buf_priv->currently_mapped = I830_BUF_MAPPED;
-       unlock_kernel();
-
-       if (io_remap_pfn_range(vma, vma->vm_start,
-                              vma->vm_pgoff,
-                              vma->vm_end - vma->vm_start, vma->vm_page_prot))
-               return -EAGAIN;
-       return 0;
-}
-
-static const struct file_operations i830_buffer_fops = {
-       .open = drm_open,
-       .release = drm_release,
-       .ioctl = drm_ioctl,
-       .mmap = i830_mmap_buffers,
-       .fasync = drm_fasync,
-};
-
-static int i830_map_buffer(struct drm_buf * buf, struct drm_file *file_priv)
-{
-       struct drm_device *dev = file_priv->minor->dev;
-       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       const struct file_operations *old_fops;
-       unsigned long virtual;
-       int retcode = 0;
-
-       if (buf_priv->currently_mapped == I830_BUF_MAPPED)
-               return -EINVAL;
-
-       down_write(&current->mm->mmap_sem);
-       old_fops = file_priv->filp->f_op;
-       file_priv->filp->f_op = &i830_buffer_fops;
-       dev_priv->mmap_buffer = buf;
-       virtual = do_mmap(file_priv->filp, 0, buf->total, PROT_READ | PROT_WRITE,
-                         MAP_SHARED, buf->bus_address);
-       dev_priv->mmap_buffer = NULL;
-       file_priv->filp->f_op = old_fops;
-       if (IS_ERR((void *)virtual)) {  /* ugh */
-               /* Real error */
-               DRM_ERROR("mmap error\n");
-               retcode = PTR_ERR((void *)virtual);
-               buf_priv->virtual = NULL;
-       } else {
-               buf_priv->virtual = (void __user *)virtual;
-       }
-       up_write(&current->mm->mmap_sem);
-
-       return retcode;
-}
-
-static int i830_unmap_buffer(struct drm_buf * buf)
-{
-       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-       int retcode = 0;
-
-       if (buf_priv->currently_mapped != I830_BUF_MAPPED)
-               return -EINVAL;
-
-       down_write(&current->mm->mmap_sem);
-       retcode = do_munmap(current->mm,
-                           (unsigned long)buf_priv->virtual,
-                           (size_t) buf->total);
-       up_write(&current->mm->mmap_sem);
-
-       buf_priv->currently_mapped = I830_BUF_UNMAPPED;
-       buf_priv->virtual = NULL;
-
-       return retcode;
-}
-
-static int i830_dma_get_buffer(struct drm_device * dev, drm_i830_dma_t * d,
-                              struct drm_file *file_priv)
-{
-       struct drm_buf *buf;
-       drm_i830_buf_priv_t *buf_priv;
-       int retcode = 0;
-
-       buf = i830_freelist_get(dev);
-       if (!buf) {
-               retcode = -ENOMEM;
-               DRM_DEBUG("retcode=%d\n", retcode);
-               return retcode;
-       }
-
-       retcode = i830_map_buffer(buf, file_priv);
-       if (retcode) {
-               i830_freelist_put(dev, buf);
-               DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
-               return retcode;
-       }
-       buf->file_priv = file_priv;
-       buf_priv = buf->dev_private;
-       d->granted = 1;
-       d->request_idx = buf->idx;
-       d->request_size = buf->total;
-       d->virtual = buf_priv->virtual;
-
-       return retcode;
-}
-
-static int i830_dma_cleanup(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-       if (dev->dev_private) {
-               int i;
-               drm_i830_private_t *dev_priv =
-                   (drm_i830_private_t *) dev->dev_private;
-
-               if (dev_priv->ring.virtual_start) {
-                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
-               }
-               if (dev_priv->hw_status_page) {
-                       pci_free_consistent(dev->pdev, PAGE_SIZE,
-                                           dev_priv->hw_status_page,
-                                           dev_priv->dma_status_page);
-                       /* Need to rewrite hardware status page */
-                       I830_WRITE(0x02080, 0x1ffff000);
-               }
-
-               drm_free(dev->dev_private, sizeof(drm_i830_private_t),
-                        DRM_MEM_DRIVER);
-               dev->dev_private = NULL;
-
-               for (i = 0; i < dma->buf_count; i++) {
-                       struct drm_buf *buf = dma->buflist[i];
-                       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-                       if (buf_priv->kernel_virtual && buf->total)
-                               drm_core_ioremapfree(&buf_priv->map, dev);
-               }
-       }
-       return 0;
-}
-
-int i830_wait_ring(struct drm_device * dev, int n, const char *caller)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
-       int iters = 0;
-       unsigned long end;
-       unsigned int last_head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-
-       end = jiffies + (HZ * 3);
-       while (ring->space < n) {
-               ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-               ring->space = ring->head - (ring->tail + 8);
-               if (ring->space < 0)
-                       ring->space += ring->Size;
-
-               if (ring->head != last_head) {
-                       end = jiffies + (HZ * 3);
-                       last_head = ring->head;
-               }
-
-               iters++;
-               if (time_before(end, jiffies)) {
-                       DRM_ERROR("space: %d wanted %d\n", ring->space, n);
-                       DRM_ERROR("lockup\n");
-                       goto out_wait_ring;
-               }
-               udelay(1);
-               dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
-       }
-
-      out_wait_ring:
-       return iters;
-}
-
-static void i830_kernel_lost_context(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
-
-       ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-       ring->tail = I830_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
-       ring->space = ring->head - (ring->tail + 8);
-       if (ring->space < 0)
-               ring->space += ring->Size;
-
-       if (ring->head == ring->tail)
-               dev_priv->sarea_priv->perf_boxes |= I830_BOX_RING_EMPTY;
-}
-
-static int i830_freelist_init(struct drm_device * dev, drm_i830_private_t * dev_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int my_idx = 36;
-       u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
-       int i;
-
-       if (dma->buf_count > 1019) {
-               /* Not enough space in the status page for the freelist */
-               return -EINVAL;
-       }
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-
-               buf_priv->in_use = hw_status++;
-               buf_priv->my_use_idx = my_idx;
-               my_idx += 4;
-
-               *buf_priv->in_use = I830_BUF_FREE;
-
-               buf_priv->map.offset = buf->bus_address;
-               buf_priv->map.size = buf->total;
-               buf_priv->map.type = _DRM_AGP;
-               buf_priv->map.flags = 0;
-               buf_priv->map.mtrr = 0;
-
-               drm_core_ioremap(&buf_priv->map, dev);
-               buf_priv->kernel_virtual = buf_priv->map.handle;
-       }
-       return 0;
-}
-
-static int i830_dma_initialize(struct drm_device * dev,
-                              drm_i830_private_t * dev_priv,
-                              drm_i830_init_t * init)
-{
-       struct drm_map_list *r_list;
-
-       memset(dev_priv, 0, sizeof(drm_i830_private_t));
-
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               if (r_list->map &&
-                   r_list->map->type == _DRM_SHM &&
-                   r_list->map->flags & _DRM_CONTAINS_LOCK) {
-                       dev_priv->sarea_map = r_list->map;
-                       break;
-               }
-       }
-
-       if (!dev_priv->sarea_map) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("can not find sarea!\n");
-               return -EINVAL;
-       }
-       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
-       if (!dev_priv->mmio_map) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("can not find mmio map!\n");
-               return -EINVAL;
-       }
-       dev->agp_buffer_token = init->buffers_offset;
-       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
-       if (!dev->agp_buffer_map) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("can not find dma buffer map!\n");
-               return -EINVAL;
-       }
-
-       dev_priv->sarea_priv = (drm_i830_sarea_t *)
-           ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
-
-       dev_priv->ring.Start = init->ring_start;
-       dev_priv->ring.End = init->ring_end;
-       dev_priv->ring.Size = init->ring_size;
-
-       dev_priv->ring.map.offset = dev->agp->base + init->ring_start;
-       dev_priv->ring.map.size = init->ring_size;
-       dev_priv->ring.map.type = _DRM_AGP;
-       dev_priv->ring.map.flags = 0;
-       dev_priv->ring.map.mtrr = 0;
-
-       drm_core_ioremap(&dev_priv->ring.map, dev);
-
-       if (dev_priv->ring.map.handle == NULL) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("can not ioremap virtual address for"
-                         " ring buffer\n");
-               return -ENOMEM;
-       }
-
-       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
-
-       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
-
-       dev_priv->w = init->w;
-       dev_priv->h = init->h;
-       dev_priv->pitch = init->pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->front_offset = init->front_offset;
-
-       dev_priv->front_di1 = init->front_offset | init->pitch_bits;
-       dev_priv->back_di1 = init->back_offset | init->pitch_bits;
-       dev_priv->zi1 = init->depth_offset | init->pitch_bits;
-
-       DRM_DEBUG("front_di1 %x\n", dev_priv->front_di1);
-       DRM_DEBUG("back_offset %x\n", dev_priv->back_offset);
-       DRM_DEBUG("back_di1 %x\n", dev_priv->back_di1);
-       DRM_DEBUG("pitch_bits %x\n", init->pitch_bits);
-
-       dev_priv->cpp = init->cpp;
-       /* We are using separate values as placeholders for mechanisms for
-        * private backbuffer/depthbuffer usage.
-        */
-
-       dev_priv->back_pitch = init->back_pitch;
-       dev_priv->depth_pitch = init->depth_pitch;
-       dev_priv->do_boxes = 0;
-       dev_priv->use_mi_batchbuffer_start = 0;
-
-       /* Program Hardware Status Page */
-       dev_priv->hw_status_page =
-           pci_alloc_consistent(dev->pdev, PAGE_SIZE,
-                                &dev_priv->dma_status_page);
-       if (!dev_priv->hw_status_page) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("Can not allocate hardware status page\n");
-               return -ENOMEM;
-       }
-       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
-
-       I830_WRITE(0x02080, dev_priv->dma_status_page);
-       DRM_DEBUG("Enabled hardware status page\n");
-
-       /* Now we need to init our freelist */
-       if (i830_freelist_init(dev, dev_priv) != 0) {
-               dev->dev_private = (void *)dev_priv;
-               i830_dma_cleanup(dev);
-               DRM_ERROR("Not enough space in the status page for"
-                         " the freelist\n");
-               return -ENOMEM;
-       }
-       dev->dev_private = (void *)dev_priv;
-
-       return 0;
-}
-
-static int i830_dma_init(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv;
-       drm_i830_init_t *init = data;
-       int retcode = 0;
-
-       switch (init->func) {
-       case I830_INIT_DMA:
-               dev_priv = drm_alloc(sizeof(drm_i830_private_t),
-                                    DRM_MEM_DRIVER);
-               if (dev_priv == NULL)
-                       return -ENOMEM;
-               retcode = i830_dma_initialize(dev, dev_priv, init);
-               break;
-       case I830_CLEANUP_DMA:
-               retcode = i830_dma_cleanup(dev);
-               break;
-       default:
-               retcode = -EINVAL;
-               break;
-       }
-
-       return retcode;
-}
-
-#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
-#define ST1_ENABLE               (1<<16)
-#define ST1_MASK                 (0xffff)
-
-/* Most efficient way to verify state for the i830 is as it is
- * emitted.  Non-conformant state is silently dropped.
- */
-static void i830EmitContextVerified(struct drm_device * dev, unsigned int *code)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       int i, j = 0;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(I830_CTX_SETUP_SIZE + 4);
-
-       for (i = 0; i < I830_CTXREG_BLENDCOLR0; i++) {
-               tmp = code[i];
-               if ((tmp & (7 << 29)) == CMD_3D &&
-                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
-                       OUT_RING(tmp);
-                       j++;
-               } else {
-                       DRM_ERROR("Skipping %d\n", i);
-               }
-       }
-
-       OUT_RING(STATE3D_CONST_BLEND_COLOR_CMD);
-       OUT_RING(code[I830_CTXREG_BLENDCOLR]);
-       j += 2;
-
-       for (i = I830_CTXREG_VF; i < I830_CTXREG_MCSB0; i++) {
-               tmp = code[i];
-               if ((tmp & (7 << 29)) == CMD_3D &&
-                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
-                       OUT_RING(tmp);
-                       j++;
-               } else {
-                       DRM_ERROR("Skipping %d\n", i);
-               }
-       }
-
-       OUT_RING(STATE3D_MAP_COORD_SETBIND_CMD);
-       OUT_RING(code[I830_CTXREG_MCSB1]);
-       j += 2;
-
-       if (j & 1)
-               OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-static void i830EmitTexVerified(struct drm_device * dev, unsigned int *code)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       int i, j = 0;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       if (code[I830_TEXREG_MI0] == GFX_OP_MAP_INFO ||
-           (code[I830_TEXREG_MI0] & ~(0xf * LOAD_TEXTURE_MAP0)) ==
-           (STATE3D_LOAD_STATE_IMMEDIATE_2 | 4)) {
-
-               BEGIN_LP_RING(I830_TEX_SETUP_SIZE);
-
-               OUT_RING(code[I830_TEXREG_MI0]);        /* TM0LI */
-               OUT_RING(code[I830_TEXREG_MI1]);        /* TM0S0 */
-               OUT_RING(code[I830_TEXREG_MI2]);        /* TM0S1 */
-               OUT_RING(code[I830_TEXREG_MI3]);        /* TM0S2 */
-               OUT_RING(code[I830_TEXREG_MI4]);        /* TM0S3 */
-               OUT_RING(code[I830_TEXREG_MI5]);        /* TM0S4 */
-
-               for (i = 6; i < I830_TEX_SETUP_SIZE; i++) {
-                       tmp = code[i];
-                       OUT_RING(tmp);
-                       j++;
-               }
-
-               if (j & 1)
-                       OUT_RING(0);
-
-               ADVANCE_LP_RING();
-       } else
-               printk("rejected packet %x\n", code[0]);
-}
-
-static void i830EmitTexBlendVerified(struct drm_device * dev,
-                                    unsigned int *code, unsigned int num)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       int i, j = 0;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       if (!num)
-               return;
-
-       BEGIN_LP_RING(num + 1);
-
-       for (i = 0; i < num; i++) {
-               tmp = code[i];
-               OUT_RING(tmp);
-               j++;
-       }
-
-       if (j & 1)
-               OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-static void i830EmitTexPalette(struct drm_device * dev,
-                              unsigned int *palette, int number, int is_shared)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       int i;
-       RING_LOCALS;
-
-       return;
-
-       BEGIN_LP_RING(258);
-
-       if (is_shared == 1) {
-               OUT_RING(CMD_OP_MAP_PALETTE_LOAD |
-                        MAP_PALETTE_NUM(0) | MAP_PALETTE_BOTH);
-       } else {
-               OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(number));
-       }
-       for (i = 0; i < 256; i++) {
-               OUT_RING(palette[i]);
-       }
-       OUT_RING(0);
-       /* KW:  WHERE IS THE ADVANCE_LP_RING?  This is effectively a noop!
-        */
-}
-
-/* Need to do some additional checking when setting the dest buffer.
- */
-static void i830EmitDestVerified(struct drm_device * dev, unsigned int *code)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       unsigned int tmp;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(I830_DEST_SETUP_SIZE + 10);
-
-       tmp = code[I830_DESTREG_CBUFADDR];
-       if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
-               if (((int)outring) & 8) {
-                       OUT_RING(0);
-                       OUT_RING(0);
-               }
-
-               OUT_RING(CMD_OP_DESTBUFFER_INFO);
-               OUT_RING(BUF_3D_ID_COLOR_BACK |
-                        BUF_3D_PITCH(dev_priv->back_pitch * dev_priv->cpp) |
-                        BUF_3D_USE_FENCE);
-               OUT_RING(tmp);
-               OUT_RING(0);
-
-               OUT_RING(CMD_OP_DESTBUFFER_INFO);
-               OUT_RING(BUF_3D_ID_DEPTH | BUF_3D_USE_FENCE |
-                        BUF_3D_PITCH(dev_priv->depth_pitch * dev_priv->cpp));
-               OUT_RING(dev_priv->zi1);
-               OUT_RING(0);
-       } else {
-               DRM_ERROR("bad di1 %x (allow %x or %x)\n",
-                         tmp, dev_priv->front_di1, dev_priv->back_di1);
-       }
-
-       /* invarient:
-        */
-
-       OUT_RING(GFX_OP_DESTBUFFER_VARS);
-       OUT_RING(code[I830_DESTREG_DV1]);
-
-       OUT_RING(GFX_OP_DRAWRECT_INFO);
-       OUT_RING(code[I830_DESTREG_DR1]);
-       OUT_RING(code[I830_DESTREG_DR2]);
-       OUT_RING(code[I830_DESTREG_DR3]);
-       OUT_RING(code[I830_DESTREG_DR4]);
-
-       /* Need to verify this */
-       tmp = code[I830_DESTREG_SENABLE];
-       if ((tmp & ~0x3) == GFX_OP_SCISSOR_ENABLE) {
-               OUT_RING(tmp);
-       } else {
-               DRM_ERROR("bad scissor enable\n");
-               OUT_RING(0);
-       }
-
-       OUT_RING(GFX_OP_SCISSOR_RECT);
-       OUT_RING(code[I830_DESTREG_SR1]);
-       OUT_RING(code[I830_DESTREG_SR2]);
-       OUT_RING(0);
-
-       ADVANCE_LP_RING();
-}
-
-static void i830EmitStippleVerified(struct drm_device * dev, unsigned int *code)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       BEGIN_LP_RING(2);
-       OUT_RING(GFX_OP_STIPPLE);
-       OUT_RING(code[1]);
-       ADVANCE_LP_RING();
-}
-
-static void i830EmitState(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-
-       DRM_DEBUG("%s %x\n", __func__, dirty);
-
-       if (dirty & I830_UPLOAD_BUFFERS) {
-               i830EmitDestVerified(dev, sarea_priv->BufferState);
-               sarea_priv->dirty &= ~I830_UPLOAD_BUFFERS;
-       }
-
-       if (dirty & I830_UPLOAD_CTX) {
-               i830EmitContextVerified(dev, sarea_priv->ContextState);
-               sarea_priv->dirty &= ~I830_UPLOAD_CTX;
-       }
-
-       if (dirty & I830_UPLOAD_TEX0) {
-               i830EmitTexVerified(dev, sarea_priv->TexState[0]);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEX0;
-       }
-
-       if (dirty & I830_UPLOAD_TEX1) {
-               i830EmitTexVerified(dev, sarea_priv->TexState[1]);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEX1;
-       }
-
-       if (dirty & I830_UPLOAD_TEXBLEND0) {
-               i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[0],
-                                        sarea_priv->TexBlendStateWordsUsed[0]);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND0;
-       }
-
-       if (dirty & I830_UPLOAD_TEXBLEND1) {
-               i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[1],
-                                        sarea_priv->TexBlendStateWordsUsed[1]);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND1;
-       }
-
-       if (dirty & I830_UPLOAD_TEX_PALETTE_SHARED) {
-               i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 1);
-       } else {
-               if (dirty & I830_UPLOAD_TEX_PALETTE_N(0)) {
-                       i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 0);
-                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(0);
-               }
-               if (dirty & I830_UPLOAD_TEX_PALETTE_N(1)) {
-                       i830EmitTexPalette(dev, sarea_priv->Palette[1], 1, 0);
-                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(1);
-               }
-
-               /* 1.3:
-                */
-#if 0
-               if (dirty & I830_UPLOAD_TEX_PALETTE_N(2)) {
-                       i830EmitTexPalette(dev, sarea_priv->Palette2[0], 0, 0);
-                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2);
-               }
-               if (dirty & I830_UPLOAD_TEX_PALETTE_N(3)) {
-                       i830EmitTexPalette(dev, sarea_priv->Palette2[1], 1, 0);
-                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2);
-               }
-#endif
-       }
-
-       /* 1.3:
-        */
-       if (dirty & I830_UPLOAD_STIPPLE) {
-               i830EmitStippleVerified(dev, sarea_priv->StippleState);
-               sarea_priv->dirty &= ~I830_UPLOAD_STIPPLE;
-       }
-
-       if (dirty & I830_UPLOAD_TEX2) {
-               i830EmitTexVerified(dev, sarea_priv->TexState2);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEX2;
-       }
-
-       if (dirty & I830_UPLOAD_TEX3) {
-               i830EmitTexVerified(dev, sarea_priv->TexState3);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEX3;
-       }
-
-       if (dirty & I830_UPLOAD_TEXBLEND2) {
-               i830EmitTexBlendVerified(dev,
-                                        sarea_priv->TexBlendState2,
-                                        sarea_priv->TexBlendStateWordsUsed2);
-
-               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND2;
-       }
-
-       if (dirty & I830_UPLOAD_TEXBLEND3) {
-               i830EmitTexBlendVerified(dev,
-                                        sarea_priv->TexBlendState3,
-                                        sarea_priv->TexBlendStateWordsUsed3);
-               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND3;
-       }
-}
-
-/* ================================================================
- * Performance monitoring functions
- */
-
-static void i830_fill_box(struct drm_device * dev,
-                         int x, int y, int w, int h, int r, int g, int b)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       u32 color;
-       unsigned int BR13, CMD;
-       RING_LOCALS;
-
-       BR13 = (0xF0 << 16) | (dev_priv->pitch * dev_priv->cpp) | (1 << 24);
-       CMD = XY_COLOR_BLT_CMD;
-       x += dev_priv->sarea_priv->boxes[0].x1;
-       y += dev_priv->sarea_priv->boxes[0].y1;
-
-       if (dev_priv->cpp == 4) {
-               BR13 |= (1 << 25);
-               CMD |= (XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB);
-               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
-       } else {
-               color = (((r & 0xf8) << 8) |
-                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
-       }
-
-       BEGIN_LP_RING(6);
-       OUT_RING(CMD);
-       OUT_RING(BR13);
-       OUT_RING((y << 16) | x);
-       OUT_RING(((y + h) << 16) | (x + w));
-
-       if (dev_priv->current_page == 1) {
-               OUT_RING(dev_priv->front_offset);
-       } else {
-               OUT_RING(dev_priv->back_offset);
-       }
-
-       OUT_RING(color);
-       ADVANCE_LP_RING();
-}
-
-static void i830_cp_performance_boxes(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-
-       /* Purple box for page flipping
-        */
-       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_FLIP)
-               i830_fill_box(dev, 4, 4, 8, 8, 255, 0, 255);
-
-       /* Red box if we have to wait for idle at any point
-        */
-       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_WAIT)
-               i830_fill_box(dev, 16, 4, 8, 8, 255, 0, 0);
-
-       /* Blue box: lost context?
-        */
-       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_LOST_CONTEXT)
-               i830_fill_box(dev, 28, 4, 8, 8, 0, 0, 255);
-
-       /* Yellow box for texture swaps
-        */
-       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_TEXTURE_LOAD)
-               i830_fill_box(dev, 40, 4, 8, 8, 255, 255, 0);
-
-       /* Green box if hardware never idles (as far as we can tell)
-        */
-       if (!(dev_priv->sarea_priv->perf_boxes & I830_BOX_RING_EMPTY))
-               i830_fill_box(dev, 64, 4, 8, 8, 0, 255, 0);
-
-       /* Draw bars indicating number of buffers allocated
-        * (not a great measure, easily confused)
-        */
-       if (dev_priv->dma_used) {
-               int bar = dev_priv->dma_used / 10240;
-               if (bar > 100)
-                       bar = 100;
-               if (bar < 1)
-                       bar = 1;
-               i830_fill_box(dev, 4, 16, bar, 4, 196, 128, 128);
-               dev_priv->dma_used = 0;
-       }
-
-       dev_priv->sarea_priv->perf_boxes = 0;
-}
-
-static void i830_dma_dispatch_clear(struct drm_device * dev, int flags,
-                                   unsigned int clear_color,
-                                   unsigned int clear_zval,
-                                   unsigned int clear_depthmask)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int pitch = dev_priv->pitch;
-       int cpp = dev_priv->cpp;
-       int i;
-       unsigned int BR13, CMD, D_CMD;
-       RING_LOCALS;
-
-       if (dev_priv->current_page == 1) {
-               unsigned int tmp = flags;
-
-               flags &= ~(I830_FRONT | I830_BACK);
-               if (tmp & I830_FRONT)
-                       flags |= I830_BACK;
-               if (tmp & I830_BACK)
-                       flags |= I830_FRONT;
-       }
-
-       i830_kernel_lost_context(dev);
-
-       switch (cpp) {
-       case 2:
-               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
-               D_CMD = CMD = XY_COLOR_BLT_CMD;
-               break;
-       case 4:
-               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24) | (1 << 25);
-               CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA |
-                      XY_COLOR_BLT_WRITE_RGB);
-               D_CMD = XY_COLOR_BLT_CMD;
-               if (clear_depthmask & 0x00ffffff)
-                       D_CMD |= XY_COLOR_BLT_WRITE_RGB;
-               if (clear_depthmask & 0xff000000)
-                       D_CMD |= XY_COLOR_BLT_WRITE_ALPHA;
-               break;
-       default:
-               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
-               D_CMD = CMD = XY_COLOR_BLT_CMD;
-               break;
-       }
-
-       if (nbox > I830_NR_SAREA_CLIPRECTS)
-               nbox = I830_NR_SAREA_CLIPRECTS;
-
-       for (i = 0; i < nbox; i++, pbox++) {
-               if (pbox->x1 > pbox->x2 ||
-                   pbox->y1 > pbox->y2 ||
-                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
-                       continue;
-
-               if (flags & I830_FRONT) {
-                       DRM_DEBUG("clear front\n");
-                       BEGIN_LP_RING(6);
-                       OUT_RING(CMD);
-                       OUT_RING(BR13);
-                       OUT_RING((pbox->y1 << 16) | pbox->x1);
-                       OUT_RING((pbox->y2 << 16) | pbox->x2);
-                       OUT_RING(dev_priv->front_offset);
-                       OUT_RING(clear_color);
-                       ADVANCE_LP_RING();
-               }
-
-               if (flags & I830_BACK) {
-                       DRM_DEBUG("clear back\n");
-                       BEGIN_LP_RING(6);
-                       OUT_RING(CMD);
-                       OUT_RING(BR13);
-                       OUT_RING((pbox->y1 << 16) | pbox->x1);
-                       OUT_RING((pbox->y2 << 16) | pbox->x2);
-                       OUT_RING(dev_priv->back_offset);
-                       OUT_RING(clear_color);
-                       ADVANCE_LP_RING();
-               }
-
-               if (flags & I830_DEPTH) {
-                       DRM_DEBUG("clear depth\n");
-                       BEGIN_LP_RING(6);
-                       OUT_RING(D_CMD);
-                       OUT_RING(BR13);
-                       OUT_RING((pbox->y1 << 16) | pbox->x1);
-                       OUT_RING((pbox->y2 << 16) | pbox->x2);
-                       OUT_RING(dev_priv->depth_offset);
-                       OUT_RING(clear_zval);
-                       ADVANCE_LP_RING();
-               }
-       }
-}
-
-static void i830_dma_dispatch_swap(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int pitch = dev_priv->pitch;
-       int cpp = dev_priv->cpp;
-       int i;
-       unsigned int CMD, BR13;
-       RING_LOCALS;
-
-       DRM_DEBUG("swapbuffers\n");
-
-       i830_kernel_lost_context(dev);
-
-       if (dev_priv->do_boxes)
-               i830_cp_performance_boxes(dev);
-
-       switch (cpp) {
-       case 2:
-               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
-               CMD = XY_SRC_COPY_BLT_CMD;
-               break;
-       case 4:
-               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24) | (1 << 25);
-               CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
-                      XY_SRC_COPY_BLT_WRITE_RGB);
-               break;
-       default:
-               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
-               CMD = XY_SRC_COPY_BLT_CMD;
-               break;
-       }
-
-       if (nbox > I830_NR_SAREA_CLIPRECTS)
-               nbox = I830_NR_SAREA_CLIPRECTS;
-
-       for (i = 0; i < nbox; i++, pbox++) {
-               if (pbox->x1 > pbox->x2 ||
-                   pbox->y1 > pbox->y2 ||
-                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
-                       continue;
-
-               DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n",
-                         pbox->x1, pbox->y1, pbox->x2, pbox->y2);
-
-               BEGIN_LP_RING(8);
-               OUT_RING(CMD);
-               OUT_RING(BR13);
-               OUT_RING((pbox->y1 << 16) | pbox->x1);
-               OUT_RING((pbox->y2 << 16) | pbox->x2);
-
-               if (dev_priv->current_page == 0)
-                       OUT_RING(dev_priv->front_offset);
-               else
-                       OUT_RING(dev_priv->back_offset);
-
-               OUT_RING((pbox->y1 << 16) | pbox->x1);
-               OUT_RING(BR13 & 0xffff);
-
-               if (dev_priv->current_page == 0)
-                       OUT_RING(dev_priv->back_offset);
-               else
-                       OUT_RING(dev_priv->front_offset);
-
-               ADVANCE_LP_RING();
-       }
-}
-
-static void i830_dma_dispatch_flip(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
-                 __func__,
-                 dev_priv->current_page,
-                 dev_priv->sarea_priv->pf_current_page);
-
-       i830_kernel_lost_context(dev);
-
-       if (dev_priv->do_boxes) {
-               dev_priv->sarea_priv->perf_boxes |= I830_BOX_FLIP;
-               i830_cp_performance_boxes(dev);
-       }
-
-       BEGIN_LP_RING(2);
-       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(6);
-       OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
-       OUT_RING(0);
-       if (dev_priv->current_page == 0) {
-               OUT_RING(dev_priv->back_offset);
-               dev_priv->current_page = 1;
-       } else {
-               OUT_RING(dev_priv->front_offset);
-               dev_priv->current_page = 0;
-       }
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(2);
-       OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-}
-
-static void i830_dma_dispatch_vertex(struct drm_device * dev,
-                                    struct drm_buf * buf, int discard, int used)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_clip_rect *box = sarea_priv->boxes;
-       int nbox = sarea_priv->nbox;
-       unsigned long address = (unsigned long)buf->bus_address;
-       unsigned long start = address - dev->agp->base;
-       int i = 0, u;
-       RING_LOCALS;
-
-       i830_kernel_lost_context(dev);
-
-       if (nbox > I830_NR_SAREA_CLIPRECTS)
-               nbox = I830_NR_SAREA_CLIPRECTS;
-
-       if (discard) {
-               u = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
-                           I830_BUF_HARDWARE);
-               if (u != I830_BUF_CLIENT) {
-                       DRM_DEBUG("xxxx 2\n");
-               }
-       }
-
-       if (used > 4 * 1023)
-               used = 0;
-
-       if (sarea_priv->dirty)
-               i830EmitState(dev);
-
-       DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n",
-                 address, used, nbox);
-
-       dev_priv->counter++;
-       DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
-       DRM_DEBUG("i830_dma_dispatch\n");
-       DRM_DEBUG("start : %lx\n", start);
-       DRM_DEBUG("used : %d\n", used);
-       DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
-
-       if (buf_priv->currently_mapped == I830_BUF_MAPPED) {
-               u32 *vp = buf_priv->kernel_virtual;
-
-               vp[0] = (GFX_OP_PRIMITIVE |
-                        sarea_priv->vertex_prim | ((used / 4) - 2));
-
-               if (dev_priv->use_mi_batchbuffer_start) {
-                       vp[used / 4] = MI_BATCH_BUFFER_END;
-                       used += 4;
-               }
-
-               if (used & 4) {
-                       vp[used / 4] = 0;
-                       used += 4;
-               }
-
-               i830_unmap_buffer(buf);
-       }
-
-       if (used) {
-               do {
-                       if (i < nbox) {
-                               BEGIN_LP_RING(6);
-                               OUT_RING(GFX_OP_DRAWRECT_INFO);
-                               OUT_RING(sarea_priv->
-                                        BufferState[I830_DESTREG_DR1]);
-                               OUT_RING(box[i].x1 | (box[i].y1 << 16));
-                               OUT_RING(box[i].x2 | (box[i].y2 << 16));
-                               OUT_RING(sarea_priv->
-                                        BufferState[I830_DESTREG_DR4]);
-                               OUT_RING(0);
-                               ADVANCE_LP_RING();
-                       }
-
-                       if (dev_priv->use_mi_batchbuffer_start) {
-                               BEGIN_LP_RING(2);
-                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
-                               OUT_RING(start | MI_BATCH_NON_SECURE);
-                               ADVANCE_LP_RING();
-                       } else {
-                               BEGIN_LP_RING(4);
-                               OUT_RING(MI_BATCH_BUFFER);
-                               OUT_RING(start | MI_BATCH_NON_SECURE);
-                               OUT_RING(start + used - 4);
-                               OUT_RING(0);
-                               ADVANCE_LP_RING();
-                       }
-
-               } while (++i < nbox);
-       }
-
-       if (discard) {
-               dev_priv->counter++;
-
-               (void)cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
-                             I830_BUF_HARDWARE);
-
-               BEGIN_LP_RING(8);
-               OUT_RING(CMD_STORE_DWORD_IDX);
-               OUT_RING(20);
-               OUT_RING(dev_priv->counter);
-               OUT_RING(CMD_STORE_DWORD_IDX);
-               OUT_RING(buf_priv->my_use_idx);
-               OUT_RING(I830_BUF_FREE);
-               OUT_RING(CMD_REPORT_HEAD);
-               OUT_RING(0);
-               ADVANCE_LP_RING();
-       }
-}
-
-static void i830_dma_quiescent(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       i830_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(4);
-       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-       OUT_RING(CMD_REPORT_HEAD);
-       OUT_RING(0);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
-}
-
-static int i830_flush_queue(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       int i, ret = 0;
-       RING_LOCALS;
-
-       i830_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(2);
-       OUT_RING(CMD_REPORT_HEAD);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-
-               int used = cmpxchg(buf_priv->in_use, I830_BUF_HARDWARE,
-                                  I830_BUF_FREE);
-
-               if (used == I830_BUF_HARDWARE)
-                       DRM_DEBUG("reclaimed from HARDWARE\n");
-               if (used == I830_BUF_CLIENT)
-                       DRM_DEBUG("still on client\n");
-       }
-
-       return ret;
-}
-
-/* Must be called with the lock held */
-static void i830_reclaim_buffers(struct drm_device * dev, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-
-       if (!dma)
-               return;
-       if (!dev->dev_private)
-               return;
-       if (!dma->buflist)
-               return;
-
-       i830_flush_queue(dev);
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
-
-               if (buf->file_priv == file_priv && buf_priv) {
-                       int used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
-                                          I830_BUF_FREE);
-
-                       if (used == I830_BUF_CLIENT)
-                               DRM_DEBUG("reclaimed from client\n");
-                       if (buf_priv->currently_mapped == I830_BUF_MAPPED)
-                               buf_priv->currently_mapped = I830_BUF_UNMAPPED;
-               }
-       }
-}
-
-static int i830_flush_ioctl(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv)
-{
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       i830_flush_queue(dev);
-       return 0;
-}
-
-static int i830_dma_vertex(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
-           dev_priv->sarea_priv;
-       drm_i830_vertex_t *vertex = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n",
-                 vertex->idx, vertex->used, vertex->discard);
-
-       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
-               return -EINVAL;
-
-       i830_dma_dispatch_vertex(dev,
-                                dma->buflist[vertex->idx],
-                                vertex->discard, vertex->used);
-
-       sarea_priv->last_enqueue = dev_priv->counter - 1;
-       sarea_priv->last_dispatch = (int)hw_status[5];
-
-       return 0;
-}
-
-static int i830_clear_bufs(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv)
-{
-       drm_i830_clear_t *clear = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* GH: Someone's doing nasty things... */
-       if (!dev->dev_private) {
-               return -EINVAL;
-       }
-
-       i830_dma_dispatch_clear(dev, clear->flags,
-                               clear->clear_color,
-                               clear->clear_depth, clear->clear_depthmask);
-       return 0;
-}
-
-static int i830_swap_bufs(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       DRM_DEBUG("i830_swap_bufs\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       i830_dma_dispatch_swap(dev);
-       return 0;
-}
-
-/* Not sure why this isn't set all the time:
- */
-static void i830_do_init_pageflip(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("%s\n", __func__);
-       dev_priv->page_flipping = 1;
-       dev_priv->current_page = 0;
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-}
-
-static int i830_do_cleanup_pageflip(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("%s\n", __func__);
-       if (dev_priv->current_page != 0)
-               i830_dma_dispatch_flip(dev);
-
-       dev_priv->page_flipping = 0;
-       return 0;
-}
-
-static int i830_flip_bufs(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("%s\n", __func__);
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv->page_flipping)
-               i830_do_init_pageflip(dev);
-
-       i830_dma_dispatch_flip(dev);
-       return 0;
-}
-
-static int i830_getage(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
-           dev_priv->sarea_priv;
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-       return 0;
-}
-
-static int i830_getbuf(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       int retcode = 0;
-       drm_i830_dma_t *d = data;
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
-           dev_priv->sarea_priv;
-
-       DRM_DEBUG("getbuf\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       d->granted = 0;
-
-       retcode = i830_dma_get_buffer(dev, d, file_priv);
-
-       DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n",
-                 task_pid_nr(current), retcode, d->granted);
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-
-       return retcode;
-}
-
-static int i830_copybuf(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       /* Never copy - 2.4.x doesn't need it */
-       return 0;
-}
-
-static int i830_docopy(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       return 0;
-}
-
-static int i830_getparam(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_getparam_t *param = data;
-       int value;
-
-       if (!dev_priv) {
-               DRM_ERROR("%s called with no initialization\n", __func__);
-               return -EINVAL;
-       }
-
-       switch (param->param) {
-       case I830_PARAM_IRQ_ACTIVE:
-               value = dev->irq_enabled;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if (copy_to_user(param->value, &value, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-static int i830_setparam(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_setparam_t *param = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("%s called with no initialization\n", __func__);
-               return -EINVAL;
-       }
-
-       switch (param->param) {
-       case I830_SETPARAM_USE_MI_BATCHBUFFER_START:
-               dev_priv->use_mi_batchbuffer_start = param->value;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-int i830_driver_load(struct drm_device *dev, unsigned long flags)
-{
-       /* i830 has 4 more counters */
-       dev->counters += 4;
-       dev->types[6] = _DRM_STAT_IRQ;
-       dev->types[7] = _DRM_STAT_PRIMARY;
-       dev->types[8] = _DRM_STAT_SECONDARY;
-       dev->types[9] = _DRM_STAT_DMA;
-
-       return 0;
-}
-
-void i830_driver_lastclose(struct drm_device * dev)
-{
-       i830_dma_cleanup(dev);
-}
-
-void i830_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
-{
-       if (dev->dev_private) {
-               drm_i830_private_t *dev_priv = dev->dev_private;
-               if (dev_priv->page_flipping) {
-                       i830_do_cleanup_pageflip(dev);
-               }
-       }
-}
-
-void i830_driver_reclaim_buffers_locked(struct drm_device * dev, struct drm_file *file_priv)
-{
-       i830_reclaim_buffers(dev, file_priv);
-}
-
-int i830_driver_dma_quiescent(struct drm_device * dev)
-{
-       i830_dma_quiescent(dev);
-       return 0;
-}
-
-struct drm_ioctl_desc i830_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_I830_INIT, i830_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I830_VERTEX, i830_dma_vertex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_CLEAR, i830_clear_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_FLUSH, i830_flush_ioctl, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_GETAGE, i830_getage, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_GETBUF, i830_getbuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_SWAP, i830_swap_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_COPY, i830_copybuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_DOCOPY, i830_docopy, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_FLIP, i830_flip_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_IRQ_EMIT, i830_irq_emit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_IRQ_WAIT, i830_irq_wait, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_GETPARAM, i830_getparam, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I830_SETPARAM, i830_setparam, DRM_AUTH)
-};
-
-int i830_max_ioctl = DRM_ARRAY_SIZE(i830_ioctls);
-
-/**
- * Determine if the device really is AGP or not.
- *
- * All Intel graphics chipsets are treated as AGP, even if they are really
- * PCI-e.
- *
- * \param dev   The device to be tested.
- *
- * \returns
- * A value of 1 is always retured to indictate every i8xx is AGP.
- */
-int i830_driver_device_is_agp(struct drm_device * dev)
-{
-       return 1;
-}
diff --git a/drivers/char/drm/i830_drm.h b/drivers/char/drm/i830_drm.h
deleted file mode 100644 (file)
index 4b00d2d..0000000
+++ /dev/null
@@ -1,342 +0,0 @@
-#ifndef _I830_DRM_H_
-#define _I830_DRM_H_
-
-/* WARNING: These defines must be the same as what the Xserver uses.
- * if you change them, you must change the defines in the Xserver.
- *
- * KW: Actually, you can't ever change them because doing so would
- * break backwards compatibility.
- */
-
-#ifndef _I830_DEFINES_
-#define _I830_DEFINES_
-
-#define I830_DMA_BUF_ORDER             12
-#define I830_DMA_BUF_SZ                        (1<<I830_DMA_BUF_ORDER)
-#define I830_DMA_BUF_NR                        256
-#define I830_NR_SAREA_CLIPRECTS                8
-
-/* Each region is a minimum of 64k, and there are at most 64 of them.
- */
-#define I830_NR_TEX_REGIONS 64
-#define I830_LOG_MIN_TEX_REGION_SIZE 16
-
-/* KW: These aren't correct but someone set them to two and then
- * released the module.  Now we can't change them as doing so would
- * break backwards compatibility.
- */
-#define I830_TEXTURE_COUNT     2
-#define I830_TEXBLEND_COUNT    I830_TEXTURE_COUNT
-
-#define I830_TEXBLEND_SIZE     12      /* (4 args + op) * 2 + COLOR_FACTOR */
-
-#define I830_UPLOAD_CTX                        0x1
-#define I830_UPLOAD_BUFFERS            0x2
-#define I830_UPLOAD_CLIPRECTS          0x4
-#define I830_UPLOAD_TEX0_IMAGE         0x100   /* handled clientside */
-#define I830_UPLOAD_TEX0_CUBE          0x200   /* handled clientside */
-#define I830_UPLOAD_TEX1_IMAGE         0x400   /* handled clientside */
-#define I830_UPLOAD_TEX1_CUBE          0x800   /* handled clientside */
-#define I830_UPLOAD_TEX2_IMAGE         0x1000  /* handled clientside */
-#define I830_UPLOAD_TEX2_CUBE          0x2000  /* handled clientside */
-#define I830_UPLOAD_TEX3_IMAGE         0x4000  /* handled clientside */
-#define I830_UPLOAD_TEX3_CUBE          0x8000  /* handled clientside */
-#define I830_UPLOAD_TEX_N_IMAGE(n)     (0x100 << (n * 2))
-#define I830_UPLOAD_TEX_N_CUBE(n)      (0x200 << (n * 2))
-#define I830_UPLOAD_TEXIMAGE_MASK      0xff00
-#define I830_UPLOAD_TEX0                       0x10000
-#define I830_UPLOAD_TEX1                       0x20000
-#define I830_UPLOAD_TEX2                       0x40000
-#define I830_UPLOAD_TEX3                       0x80000
-#define I830_UPLOAD_TEX_N(n)           (0x10000 << (n))
-#define I830_UPLOAD_TEX_MASK           0xf0000
-#define I830_UPLOAD_TEXBLEND0          0x100000
-#define I830_UPLOAD_TEXBLEND1          0x200000
-#define I830_UPLOAD_TEXBLEND2          0x400000
-#define I830_UPLOAD_TEXBLEND3          0x800000
-#define I830_UPLOAD_TEXBLEND_N(n)      (0x100000 << (n))
-#define I830_UPLOAD_TEXBLEND_MASK      0xf00000
-#define I830_UPLOAD_TEX_PALETTE_N(n)    (0x1000000 << (n))
-#define I830_UPLOAD_TEX_PALETTE_SHARED 0x4000000
-#define I830_UPLOAD_STIPPLE            0x8000000
-
-/* Indices into buf.Setup where various bits of state are mirrored per
- * context and per buffer.  These can be fired at the card as a unit,
- * or in a piecewise fashion as required.
- */
-
-/* Destbuffer state
- *    - backbuffer linear offset and pitch -- invarient in the current dri
- *    - zbuffer linear offset and pitch -- also invarient
- *    - drawing origin in back and depth buffers.
- *
- * Keep the depth/back buffer state here to accommodate private buffers
- * in the future.
- */
-
-#define I830_DESTREG_CBUFADDR 0
-#define I830_DESTREG_DBUFADDR 1
-#define I830_DESTREG_DV0 2
-#define I830_DESTREG_DV1 3
-#define I830_DESTREG_SENABLE 4
-#define I830_DESTREG_SR0 5
-#define I830_DESTREG_SR1 6
-#define I830_DESTREG_SR2 7
-#define I830_DESTREG_DR0 8
-#define I830_DESTREG_DR1 9
-#define I830_DESTREG_DR2 10
-#define I830_DESTREG_DR3 11
-#define I830_DESTREG_DR4 12
-#define I830_DEST_SETUP_SIZE 13
-
-/* Context state
- */
-#define I830_CTXREG_STATE1             0
-#define I830_CTXREG_STATE2             1
-#define I830_CTXREG_STATE3             2
-#define I830_CTXREG_STATE4             3
-#define I830_CTXREG_STATE5             4
-#define I830_CTXREG_IALPHAB            5
-#define I830_CTXREG_STENCILTST         6
-#define I830_CTXREG_ENABLES_1          7
-#define I830_CTXREG_ENABLES_2          8
-#define I830_CTXREG_AA                 9
-#define I830_CTXREG_FOGCOLOR           10
-#define I830_CTXREG_BLENDCOLR0         11
-#define I830_CTXREG_BLENDCOLR          12      /* Dword 1 of 2 dword command */
-#define I830_CTXREG_VF                 13
-#define I830_CTXREG_VF2                        14
-#define I830_CTXREG_MCSB0              15
-#define I830_CTXREG_MCSB1              16
-#define I830_CTX_SETUP_SIZE            17
-
-/* 1.3: Stipple state
- */
-#define I830_STPREG_ST0 0
-#define I830_STPREG_ST1 1
-#define I830_STP_SETUP_SIZE 2
-
-/* Texture state (per tex unit)
- */
-
-#define I830_TEXREG_MI0        0       /* GFX_OP_MAP_INFO (6 dwords) */
-#define I830_TEXREG_MI1        1
-#define I830_TEXREG_MI2        2
-#define I830_TEXREG_MI3        3
-#define I830_TEXREG_MI4        4
-#define I830_TEXREG_MI5        5
-#define I830_TEXREG_MF 6       /* GFX_OP_MAP_FILTER */
-#define I830_TEXREG_MLC        7       /* GFX_OP_MAP_LOD_CTL */
-#define I830_TEXREG_MLL        8       /* GFX_OP_MAP_LOD_LIMITS */
-#define I830_TEXREG_MCS        9       /* GFX_OP_MAP_COORD_SETS */
-#define I830_TEX_SETUP_SIZE 10
-
-#define I830_TEXREG_TM0LI      0       /* load immediate 2 texture map n */
-#define I830_TEXREG_TM0S0      1
-#define I830_TEXREG_TM0S1      2
-#define I830_TEXREG_TM0S2      3
-#define I830_TEXREG_TM0S3      4
-#define I830_TEXREG_TM0S4      5
-#define I830_TEXREG_NOP0       6       /* noop */
-#define I830_TEXREG_NOP1       7       /* noop */
-#define I830_TEXREG_NOP2       8       /* noop */
-#define __I830_TEXREG_MCS      9       /* GFX_OP_MAP_COORD_SETS -- shared */
-#define __I830_TEX_SETUP_SIZE   10
-
-#define I830_FRONT   0x1
-#define I830_BACK    0x2
-#define I830_DEPTH   0x4
-
-#endif                         /* _I830_DEFINES_ */
-
-typedef struct _drm_i830_init {
-       enum {
-               I830_INIT_DMA = 0x01,
-               I830_CLEANUP_DMA = 0x02
-       } func;
-       unsigned int mmio_offset;
-       unsigned int buffers_offset;
-       int sarea_priv_offset;
-       unsigned int ring_start;
-       unsigned int ring_end;
-       unsigned int ring_size;
-       unsigned int front_offset;
-       unsigned int back_offset;
-       unsigned int depth_offset;
-       unsigned int w;
-       unsigned int h;
-       unsigned int pitch;
-       unsigned int pitch_bits;
-       unsigned int back_pitch;
-       unsigned int depth_pitch;
-       unsigned int cpp;
-} drm_i830_init_t;
-
-/* Warning: If you change the SAREA structure you must change the Xserver
- * structure as well */
-
-typedef struct _drm_i830_tex_region {
-       unsigned char next, prev;       /* indices to form a circular LRU  */
-       unsigned char in_use;   /* owned by a client, or free? */
-       int age;                /* tracked by clients to update local LRU's */
-} drm_i830_tex_region_t;
-
-typedef struct _drm_i830_sarea {
-       unsigned int ContextState[I830_CTX_SETUP_SIZE];
-       unsigned int BufferState[I830_DEST_SETUP_SIZE];
-       unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
-       unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
-       unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
-       unsigned int Palette[2][256];
-       unsigned int dirty;
-
-       unsigned int nbox;
-       struct drm_clip_rect boxes[I830_NR_SAREA_CLIPRECTS];
-
-       /* Maintain an LRU of contiguous regions of texture space.  If
-        * you think you own a region of texture memory, and it has an
-        * age different to the one you set, then you are mistaken and
-        * it has been stolen by another client.  If global texAge
-        * hasn't changed, there is no need to walk the list.
-        *
-        * These regions can be used as a proxy for the fine-grained
-        * texture information of other clients - by maintaining them
-        * in the same lru which is used to age their own textures,
-        * clients have an approximate lru for the whole of global
-        * texture space, and can make informed decisions as to which
-        * areas to kick out.  There is no need to choose whether to
-        * kick out your own texture or someone else's - simply eject
-        * them all in LRU order.
-        */
-
-       drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS + 1];
-       /* Last elt is sentinal */
-       int texAge;             /* last time texture was uploaded */
-       int last_enqueue;       /* last time a buffer was enqueued */
-       int last_dispatch;      /* age of the most recently dispatched buffer */
-       int last_quiescent;     /*  */
-       int ctxOwner;           /* last context to upload state */
-
-       int vertex_prim;
-
-       int pf_enabled;         /* is pageflipping allowed? */
-       int pf_active;
-       int pf_current_page;    /* which buffer is being displayed? */
-
-       int perf_boxes;         /* performance boxes to be displayed */
-
-       /* Here's the state for texunits 2,3:
-        */
-       unsigned int TexState2[I830_TEX_SETUP_SIZE];
-       unsigned int TexBlendState2[I830_TEXBLEND_SIZE];
-       unsigned int TexBlendStateWordsUsed2;
-
-       unsigned int TexState3[I830_TEX_SETUP_SIZE];
-       unsigned int TexBlendState3[I830_TEXBLEND_SIZE];
-       unsigned int TexBlendStateWordsUsed3;
-
-       unsigned int StippleState[I830_STP_SETUP_SIZE];
-} drm_i830_sarea_t;
-
-/* Flags for perf_boxes
- */
-#define I830_BOX_RING_EMPTY    0x1     /* populated by kernel */
-#define I830_BOX_FLIP          0x2     /* populated by kernel */
-#define I830_BOX_WAIT          0x4     /* populated by kernel & client */
-#define I830_BOX_TEXTURE_LOAD  0x8     /* populated by kernel */
-#define I830_BOX_LOST_CONTEXT  0x10    /* populated by client */
-
-/* I830 specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_I830_INIT  0x00
-#define DRM_I830_VERTEX        0x01
-#define DRM_I830_CLEAR 0x02
-#define DRM_I830_FLUSH 0x03
-#define DRM_I830_GETAGE        0x04
-#define DRM_I830_GETBUF        0x05
-#define DRM_I830_SWAP  0x06
-#define DRM_I830_COPY  0x07
-#define DRM_I830_DOCOPY        0x08
-#define DRM_I830_FLIP  0x09
-#define DRM_I830_IRQ_EMIT      0x0a
-#define DRM_I830_IRQ_WAIT      0x0b
-#define DRM_I830_GETPARAM      0x0c
-#define DRM_I830_SETPARAM      0x0d
-
-#define DRM_IOCTL_I830_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_INIT, drm_i830_init_t)
-#define DRM_IOCTL_I830_VERTEX          DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_VERTEX, drm_i830_vertex_t)
-#define DRM_IOCTL_I830_CLEAR           DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_CLEAR, drm_i830_clear_t)
-#define DRM_IOCTL_I830_FLUSH           DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_FLUSH)
-#define DRM_IOCTL_I830_GETAGE          DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_GETAGE)
-#define DRM_IOCTL_I830_GETBUF          DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_GETBUF, drm_i830_dma_t)
-#define DRM_IOCTL_I830_SWAP            DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_SWAP)
-#define DRM_IOCTL_I830_COPY            DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_COPY, drm_i830_copy_t)
-#define DRM_IOCTL_I830_DOCOPY          DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_DOCOPY)
-#define DRM_IOCTL_I830_FLIP            DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_FLIP)
-#define DRM_IOCTL_I830_IRQ_EMIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_IRQ_EMIT, drm_i830_irq_emit_t)
-#define DRM_IOCTL_I830_IRQ_WAIT         DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_IRQ_WAIT, drm_i830_irq_wait_t)
-#define DRM_IOCTL_I830_GETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_GETPARAM, drm_i830_getparam_t)
-#define DRM_IOCTL_I830_SETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_SETPARAM, drm_i830_setparam_t)
-
-typedef struct _drm_i830_clear {
-       int clear_color;
-       int clear_depth;
-       int flags;
-       unsigned int clear_colormask;
-       unsigned int clear_depthmask;
-} drm_i830_clear_t;
-
-/* These may be placeholders if we have more cliprects than
- * I830_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
- * false, indicating that the buffer will be dispatched again with a
- * new set of cliprects.
- */
-typedef struct _drm_i830_vertex {
-       int idx;                /* buffer index */
-       int used;               /* nr bytes in use */
-       int discard;            /* client is finished with the buffer? */
-} drm_i830_vertex_t;
-
-typedef struct _drm_i830_copy_t {
-       int idx;                /* buffer index */
-       int used;               /* nr bytes in use */
-       void __user *address;   /* Address to copy from */
-} drm_i830_copy_t;
-
-typedef struct drm_i830_dma {
-       void __user *virtual;
-       int request_idx;
-       int request_size;
-       int granted;
-} drm_i830_dma_t;
-
-/* 1.3: Userspace can request & wait on irq's:
- */
-typedef struct drm_i830_irq_emit {
-       int __user *irq_seq;
-} drm_i830_irq_emit_t;
-
-typedef struct drm_i830_irq_wait {
-       int irq_seq;
-} drm_i830_irq_wait_t;
-
-/* 1.3: New ioctl to query kernel params:
- */
-#define I830_PARAM_IRQ_ACTIVE            1
-
-typedef struct drm_i830_getparam {
-       int param;
-       int __user *value;
-} drm_i830_getparam_t;
-
-/* 1.3: New ioctl to set kernel params:
- */
-#define I830_SETPARAM_USE_MI_BATCHBUFFER_START            1
-
-typedef struct drm_i830_setparam {
-       int param;
-       int value;
-} drm_i830_setparam_t;
-
-#endif                         /* _I830_DRM_H_ */
diff --git a/drivers/char/drm/i830_drv.c b/drivers/char/drm/i830_drv.c
deleted file mode 100644 (file)
index 389597e..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/* i830_drv.c -- I810 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Jeff Hartmann <jhartmann@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- *    Abraham vd Merwe <abraham@2d3d.co.za>
- *    Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i830_drm.h"
-#include "i830_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       i830_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
-           DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
-#if USE_IRQS
-       .driver_features |= DRIVER_HAVE_IRQ | DRIVER_SHARED_IRQ,
-#endif
-       .dev_priv_size = sizeof(drm_i830_buf_priv_t),
-       .load = i830_driver_load,
-       .lastclose = i830_driver_lastclose,
-       .preclose = i830_driver_preclose,
-       .device_is_agp = i830_driver_device_is_agp,
-       .reclaim_buffers_locked = i830_driver_reclaim_buffers_locked,
-       .dma_quiescent = i830_driver_dma_quiescent,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-#if USE_IRQS
-       .irq_preinstall = i830_driver_irq_preinstall,
-       .irq_postinstall = i830_driver_irq_postinstall,
-       .irq_uninstall = i830_driver_irq_uninstall,
-       .irq_handler = i830_driver_irq_handler,
-#endif
-       .ioctls = i830_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init i830_init(void)
-{
-       driver.num_ioctls = i830_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit i830_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(i830_init);
-module_exit(i830_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/i830_drv.h b/drivers/char/drm/i830_drv.h
deleted file mode 100644 (file)
index b5bf8cc..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-/* i830_drv.h -- Private header for the I830 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
- *         Jeff Hartmann <jhartmann@valinux.com>
- *
- */
-
-#ifndef _I830_DRV_H_
-#define _I830_DRV_H_
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "VA Linux Systems Inc."
-
-#define DRIVER_NAME            "i830"
-#define DRIVER_DESC            "Intel 830M"
-#define DRIVER_DATE            "20021108"
-
-/* Interface history:
- *
- * 1.1: Original.
- * 1.2: ?
- * 1.3: New irq emit/wait ioctls.
- *      New pageflip ioctl.
- *      New getparam ioctl.
- *      State for texunits 3&4 in sarea.
- *      New (alternative) layout for texture state.
- */
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           3
-#define DRIVER_PATCHLEVEL      2
-
-/* Driver will work either way: IRQ's save cpu time when waiting for
- * the card, but are subject to subtle interactions between bios,
- * hardware and the driver.
- */
-/* XXX: Add vblank support? */
-#define USE_IRQS 0
-
-typedef struct drm_i830_buf_priv {
-       u32 *in_use;
-       int my_use_idx;
-       int currently_mapped;
-       void __user *virtual;
-       void *kernel_virtual;
-       drm_local_map_t map;
-} drm_i830_buf_priv_t;
-
-typedef struct _drm_i830_ring_buffer {
-       int tail_mask;
-       unsigned long Start;
-       unsigned long End;
-       unsigned long Size;
-       u8 *virtual_start;
-       int head;
-       int tail;
-       int space;
-       drm_local_map_t map;
-} drm_i830_ring_buffer_t;
-
-typedef struct drm_i830_private {
-       struct drm_map *sarea_map;
-       struct drm_map *mmio_map;
-
-       drm_i830_sarea_t *sarea_priv;
-       drm_i830_ring_buffer_t ring;
-
-       void *hw_status_page;
-       unsigned long counter;
-
-       dma_addr_t dma_status_page;
-
-       struct drm_buf *mmap_buffer;
-
-       u32 front_di1, back_di1, zi1;
-
-       int back_offset;
-       int depth_offset;
-       int front_offset;
-       int w, h;
-       int pitch;
-       int back_pitch;
-       int depth_pitch;
-       unsigned int cpp;
-
-       int do_boxes;
-       int dma_used;
-
-       int current_page;
-       int page_flipping;
-
-       wait_queue_head_t irq_queue;
-       atomic_t irq_received;
-       atomic_t irq_emitted;
-
-       int use_mi_batchbuffer_start;
-
-} drm_i830_private_t;
-
-extern struct drm_ioctl_desc i830_ioctls[];
-extern int i830_max_ioctl;
-
-/* i830_irq.c */
-extern int i830_irq_emit(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int i830_irq_wait(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-
-extern irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS);
-extern void i830_driver_irq_preinstall(struct drm_device * dev);
-extern void i830_driver_irq_postinstall(struct drm_device * dev);
-extern void i830_driver_irq_uninstall(struct drm_device * dev);
-extern int i830_driver_load(struct drm_device *, unsigned long flags);
-extern void i830_driver_preclose(struct drm_device * dev,
-                                struct drm_file *file_priv);
-extern void i830_driver_lastclose(struct drm_device * dev);
-extern void i830_driver_reclaim_buffers_locked(struct drm_device * dev,
-                                              struct drm_file *file_priv);
-extern int i830_driver_dma_quiescent(struct drm_device * dev);
-extern int i830_driver_device_is_agp(struct drm_device * dev);
-
-#define I830_READ(reg)          DRM_READ32(dev_priv->mmio_map, reg)
-#define I830_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, reg, val)
-#define I830_READ16(reg)        DRM_READ16(dev_priv->mmio_map, reg)
-#define I830_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, reg, val)
-
-#define I830_VERBOSE 0
-
-#define RING_LOCALS    unsigned int outring, ringmask, outcount; \
-                        volatile char *virt;
-
-#define BEGIN_LP_RING(n) do {                          \
-       if (I830_VERBOSE)                               \
-               printk("BEGIN_LP_RING(%d)\n", (n));     \
-       if (dev_priv->ring.space < n*4)                 \
-               i830_wait_ring(dev, n*4, __func__);             \
-       outcount = 0;                                   \
-       outring = dev_priv->ring.tail;                  \
-       ringmask = dev_priv->ring.tail_mask;            \
-       virt = dev_priv->ring.virtual_start;            \
-} while (0)
-
-#define OUT_RING(n) do {                                       \
-       if (I830_VERBOSE) printk("   OUT_RING %x\n", (int)(n)); \
-       *(volatile unsigned int *)(virt + outring) = n;         \
-        outcount++;                                            \
-       outring += 4;                                           \
-       outring &= ringmask;                                    \
-} while (0)
-
-#define ADVANCE_LP_RING() do {                                         \
-       if (I830_VERBOSE) printk("ADVANCE_LP_RING %x\n", outring);      \
-       dev_priv->ring.tail = outring;                                  \
-       dev_priv->ring.space -= outcount * 4;                           \
-       I830_WRITE(LP_RING + RING_TAIL, outring);                       \
-} while(0)
-
-extern int i830_wait_ring(struct drm_device * dev, int n, const char *caller);
-
-#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
-#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
-#define CMD_REPORT_HEAD                        (7<<23)
-#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
-#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
-
-#define STATE3D_LOAD_STATE_IMMEDIATE_2      ((0x3<<29)|(0x1d<<24)|(0x03<<16))
-#define LOAD_TEXTURE_MAP0                   (1<<11)
-
-#define INST_PARSER_CLIENT   0x00000000
-#define INST_OP_FLUSH        0x02000000
-#define INST_FLUSH_MAP_CACHE 0x00000001
-
-#define BB1_START_ADDR_MASK   (~0x7)
-#define BB1_PROTECTED         (1<<0)
-#define BB1_UNPROTECTED       (0<<0)
-#define BB2_END_ADDR_MASK     (~0x7)
-
-#define I830REG_HWSTAM         0x02098
-#define I830REG_INT_IDENTITY_R 0x020a4
-#define I830REG_INT_MASK_R     0x020a8
-#define I830REG_INT_ENABLE_R   0x020a0
-
-#define I830_IRQ_RESERVED ((1<<13)|(3<<2))
-
-#define LP_RING                        0x2030
-#define HP_RING                        0x2040
-#define RING_TAIL              0x00
-#define TAIL_ADDR              0x001FFFF8
-#define RING_HEAD              0x04
-#define HEAD_WRAP_COUNT                0xFFE00000
-#define HEAD_WRAP_ONE          0x00200000
-#define HEAD_ADDR              0x001FFFFC
-#define RING_START             0x08
-#define START_ADDR             0x0xFFFFF000
-#define RING_LEN               0x0C
-#define RING_NR_PAGES          0x001FF000
-#define RING_REPORT_MASK       0x00000006
-#define RING_REPORT_64K                0x00000002
-#define RING_REPORT_128K       0x00000004
-#define RING_NO_REPORT         0x00000000
-#define RING_VALID_MASK                0x00000001
-#define RING_VALID             0x00000001
-#define RING_INVALID           0x00000000
-
-#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
-#define SC_UPDATE_SCISSOR       (0x1<<1)
-#define SC_ENABLE_MASK          (0x1<<0)
-#define SC_ENABLE               (0x1<<0)
-
-#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
-#define SCI_YMIN_MASK      (0xffff<<16)
-#define SCI_XMIN_MASK      (0xffff<<0)
-#define SCI_YMAX_MASK      (0xffff<<16)
-#define SCI_XMAX_MASK      (0xffff<<0)
-
-#define GFX_OP_SCISSOR_ENABLE   ((0x3<<29)|(0x1c<<24)|(0x10<<19))
-#define GFX_OP_SCISSOR_RECT     ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
-#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
-#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
-#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
-#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
-#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
-#define GFX_OP_PRIMITIVE         ((0x3<<29)|(0x1f<<24))
-
-#define CMD_OP_DESTBUFFER_INFO  ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
-
-#define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
-#define ASYNC_FLIP                (1<<22)
-
-#define CMD_3D                          (0x3<<29)
-#define STATE3D_CONST_BLEND_COLOR_CMD   (CMD_3D|(0x1d<<24)|(0x88<<16))
-#define STATE3D_MAP_COORD_SETBIND_CMD   (CMD_3D|(0x1d<<24)|(0x02<<16))
-
-#define BR00_BITBLT_CLIENT   0x40000000
-#define BR00_OP_COLOR_BLT    0x10000000
-#define BR00_OP_SRC_COPY_BLT 0x10C00000
-#define BR13_SOLID_PATTERN   0x80000000
-
-#define BUF_3D_ID_COLOR_BACK    (0x3<<24)
-#define BUF_3D_ID_DEPTH         (0x7<<24)
-#define BUF_3D_USE_FENCE        (1<<23)
-#define BUF_3D_PITCH(x)         (((x)/4)<<2)
-
-#define CMD_OP_MAP_PALETTE_LOAD        ((3<<29)|(0x1d<<24)|(0x82<<16)|255)
-#define MAP_PALETTE_NUM(x)     ((x<<8) & (1<<8))
-#define MAP_PALETTE_BOTH       (1<<11)
-
-#define XY_COLOR_BLT_CMD               ((2<<29)|(0x50<<22)|0x4)
-#define XY_COLOR_BLT_WRITE_ALPHA       (1<<21)
-#define XY_COLOR_BLT_WRITE_RGB         (1<<20)
-
-#define XY_SRC_COPY_BLT_CMD             ((2<<29)|(0x53<<22)|6)
-#define XY_SRC_COPY_BLT_WRITE_ALPHA     (1<<21)
-#define XY_SRC_COPY_BLT_WRITE_RGB       (1<<20)
-
-#define MI_BATCH_BUFFER                ((0x30<<23)|1)
-#define MI_BATCH_BUFFER_START  (0x31<<23)
-#define MI_BATCH_BUFFER_END    (0xA<<23)
-#define MI_BATCH_NON_SECURE    (1)
-
-#define MI_WAIT_FOR_EVENT       ((0x3<<23))
-#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
-#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
-
-#define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
-
-#endif
diff --git a/drivers/char/drm/i830_irq.c b/drivers/char/drm/i830_irq.c
deleted file mode 100644 (file)
index 91ec2bb..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
- *
- * Copyright 2002 Tungsten Graphics, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Keith Whitwell <keith@tungstengraphics.com>
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i830_drm.h"
-#include "i830_drv.h"
-#include <linux/interrupt.h>   /* For task queue support */
-#include <linux/delay.h>
-
-irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       u16 temp;
-
-       temp = I830_READ16(I830REG_INT_IDENTITY_R);
-       DRM_DEBUG("%x\n", temp);
-
-       if (!(temp & 2))
-               return IRQ_NONE;
-
-       I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
-
-       atomic_inc(&dev_priv->irq_received);
-       wake_up_interruptible(&dev_priv->irq_queue);
-
-       return IRQ_HANDLED;
-}
-
-static int i830_emit_irq(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       DRM_DEBUG("%s\n", __func__);
-
-       atomic_inc(&dev_priv->irq_emitted);
-
-       BEGIN_LP_RING(2);
-       OUT_RING(0);
-       OUT_RING(GFX_OP_USER_INTERRUPT);
-       ADVANCE_LP_RING();
-
-       return atomic_read(&dev_priv->irq_emitted);
-}
-
-static int i830_wait_irq(struct drm_device * dev, int irq_nr)
-{
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       DECLARE_WAITQUEUE(entry, current);
-       unsigned long end = jiffies + HZ * 3;
-       int ret = 0;
-
-       DRM_DEBUG("%s\n", __func__);
-
-       if (atomic_read(&dev_priv->irq_received) >= irq_nr)
-               return 0;
-
-       dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
-
-       add_wait_queue(&dev_priv->irq_queue, &entry);
-
-       for (;;) {
-               __set_current_state(TASK_INTERRUPTIBLE);
-               if (atomic_read(&dev_priv->irq_received) >= irq_nr)
-                       break;
-               if ((signed)(end - jiffies) <= 0) {
-                       DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
-                                 I830_READ16(I830REG_INT_IDENTITY_R),
-                                 I830_READ16(I830REG_INT_MASK_R),
-                                 I830_READ16(I830REG_INT_ENABLE_R),
-                                 I830_READ16(I830REG_HWSTAM));
-
-                       ret = -EBUSY;   /* Lockup?  Missed irq? */
-                       break;
-               }
-               schedule_timeout(HZ * 3);
-               if (signal_pending(current)) {
-                       ret = -EINTR;
-                       break;
-               }
-       }
-
-       __set_current_state(TASK_RUNNING);
-       remove_wait_queue(&dev_priv->irq_queue, &entry);
-       return ret;
-}
-
-/* Needs the lock as it touches the ring.
- */
-int i830_irq_emit(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_irq_emit_t *emit = data;
-       int result;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("%s called with no initialization\n", __func__);
-               return -EINVAL;
-       }
-
-       result = i830_emit_irq(dev);
-
-       if (copy_to_user(emit->irq_seq, &result, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-/* Doesn't need the hardware lock.
- */
-int i830_irq_wait(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_i830_private_t *dev_priv = dev->dev_private;
-       drm_i830_irq_wait_t *irqwait = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("%s called with no initialization\n", __func__);
-               return -EINVAL;
-       }
-
-       return i830_wait_irq(dev, irqwait->irq_seq);
-}
-
-/* drm_dma.h hooks
-*/
-void i830_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-
-       I830_WRITE16(I830REG_HWSTAM, 0xffff);
-       I830_WRITE16(I830REG_INT_MASK_R, 0x0);
-       I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
-       atomic_set(&dev_priv->irq_received, 0);
-       atomic_set(&dev_priv->irq_emitted, 0);
-       init_waitqueue_head(&dev_priv->irq_queue);
-}
-
-void i830_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-
-       I830_WRITE16(I830REG_INT_ENABLE_R, 0x2);
-}
-
-void i830_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
-       if (!dev_priv)
-               return;
-
-       I830_WRITE16(I830REG_INT_MASK_R, 0xffff);
-       I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
-}
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
deleted file mode 100644 (file)
index 8897434..0000000
+++ /dev/null
@@ -1,858 +0,0 @@
-/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
- */
-/*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-#include "i915_drv.h"
-
-/* Really want an OS-independent resettable timer.  Would like to have
- * this loop run for (eg) 3 sec, but have the timer reset every time
- * the head pointer changes, so that EBUSY only happens if the ring
- * actually stalls for (eg) 3 seconds.
- */
-int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
-       u32 last_head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-       int i;
-
-       for (i = 0; i < 10000; i++) {
-               ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-               ring->space = ring->head - (ring->tail + 8);
-               if (ring->space < 0)
-                       ring->space += ring->Size;
-               if (ring->space >= n)
-                       return 0;
-
-               dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
-
-               if (ring->head != last_head)
-                       i = 0;
-
-               last_head = ring->head;
-       }
-
-       return -EBUSY;
-}
-
-void i915_kernel_lost_context(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
-
-       ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
-       ring->tail = I915_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
-       ring->space = ring->head - (ring->tail + 8);
-       if (ring->space < 0)
-               ring->space += ring->Size;
-
-       if (ring->head == ring->tail)
-               dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
-}
-
-static int i915_dma_cleanup(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (dev->irq)
-               drm_irq_uninstall(dev);
-
-       if (dev_priv->ring.virtual_start) {
-               drm_core_ioremapfree(&dev_priv->ring.map, dev);
-               dev_priv->ring.virtual_start = 0;
-               dev_priv->ring.map.handle = 0;
-               dev_priv->ring.map.size = 0;
-       }
-
-       if (dev_priv->status_page_dmah) {
-               drm_pci_free(dev, dev_priv->status_page_dmah);
-               dev_priv->status_page_dmah = NULL;
-               /* Need to rewrite hardware status page */
-               I915_WRITE(0x02080, 0x1ffff000);
-       }
-
-       if (dev_priv->status_gfx_addr) {
-               dev_priv->status_gfx_addr = 0;
-               drm_core_ioremapfree(&dev_priv->hws_map, dev);
-               I915_WRITE(0x2080, 0x1ffff000);
-       }
-
-       return 0;
-}
-
-static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("can not find sarea!\n");
-               i915_dma_cleanup(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
-       if (!dev_priv->mmio_map) {
-               i915_dma_cleanup(dev);
-               DRM_ERROR("can not find mmio map!\n");
-               return -EINVAL;
-       }
-
-       dev_priv->sarea_priv = (drm_i915_sarea_t *)
-           ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);
-
-       dev_priv->ring.Start = init->ring_start;
-       dev_priv->ring.End = init->ring_end;
-       dev_priv->ring.Size = init->ring_size;
-       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
-
-       dev_priv->ring.map.offset = init->ring_start;
-       dev_priv->ring.map.size = init->ring_size;
-       dev_priv->ring.map.type = 0;
-       dev_priv->ring.map.flags = 0;
-       dev_priv->ring.map.mtrr = 0;
-
-       drm_core_ioremap(&dev_priv->ring.map, dev);
-
-       if (dev_priv->ring.map.handle == NULL) {
-               i915_dma_cleanup(dev);
-               DRM_ERROR("can not ioremap virtual address for"
-                         " ring buffer\n");
-               return -ENOMEM;
-       }
-
-       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
-
-       dev_priv->cpp = init->cpp;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->front_offset = init->front_offset;
-       dev_priv->current_page = 0;
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-
-       /* We are using separate values as placeholders for mechanisms for
-        * private backbuffer/depthbuffer usage.
-        */
-       dev_priv->use_mi_batchbuffer_start = 0;
-       if (IS_I965G(dev)) /* 965 doesn't support older method */
-               dev_priv->use_mi_batchbuffer_start = 1;
-
-       /* Allow hardware batchbuffers unless told otherwise.
-        */
-       dev_priv->allow_batchbuffer = 1;
-
-       /* Program Hardware Status Page */
-       if (!I915_NEED_GFX_HWS(dev)) {
-               dev_priv->status_page_dmah =
-                       drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
-
-               if (!dev_priv->status_page_dmah) {
-                       i915_dma_cleanup(dev);
-                       DRM_ERROR("Can not allocate hardware status page\n");
-                       return -ENOMEM;
-               }
-               dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
-               dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
-
-               memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-               I915_WRITE(0x02080, dev_priv->dma_status_page);
-       }
-       DRM_DEBUG("Enabled hardware status page\n");
-       return 0;
-}
-
-static int i915_dma_resume(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-
-       DRM_DEBUG("%s\n", __func__);
-
-       if (!dev_priv->sarea) {
-               DRM_ERROR("can not find sarea!\n");
-               return -EINVAL;
-       }
-
-       if (!dev_priv->mmio_map) {
-               DRM_ERROR("can not find mmio map!\n");
-               return -EINVAL;
-       }
-
-       if (dev_priv->ring.map.handle == NULL) {
-               DRM_ERROR("can not ioremap virtual address for"
-                         " ring buffer\n");
-               return -ENOMEM;
-       }
-
-       /* Program Hardware Status Page */
-       if (!dev_priv->hw_status_page) {
-               DRM_ERROR("Can not find hardware status page\n");
-               return -EINVAL;
-       }
-       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
-
-       if (dev_priv->status_gfx_addr != 0)
-               I915_WRITE(0x02080, dev_priv->status_gfx_addr);
-       else
-               I915_WRITE(0x02080, dev_priv->dma_status_page);
-       DRM_DEBUG("Enabled hardware status page\n");
-
-       return 0;
-}
-
-static int i915_dma_init(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_init_t *init = data;
-       int retcode = 0;
-
-       switch (init->func) {
-       case I915_INIT_DMA:
-               retcode = i915_initialize(dev, init);
-               break;
-       case I915_CLEANUP_DMA:
-               retcode = i915_dma_cleanup(dev);
-               break;
-       case I915_RESUME_DMA:
-               retcode = i915_dma_resume(dev);
-               break;
-       default:
-               retcode = -EINVAL;
-               break;
-       }
-
-       return retcode;
-}
-
-/* Implement basically the same security restrictions as hardware does
- * for MI_BATCH_NON_SECURE.  These can be made stricter at any time.
- *
- * Most of the calculations below involve calculating the size of a
- * particular instruction.  It's important to get the size right as
- * that tells us where the next instruction to check is.  Any illegal
- * instruction detected will be given a size of zero, which is a
- * signal to abort the rest of the buffer.
- */
-static int do_validate_cmd(int cmd)
-{
-       switch (((cmd >> 29) & 0x7)) {
-       case 0x0:
-               switch ((cmd >> 23) & 0x3f) {
-               case 0x0:
-                       return 1;       /* MI_NOOP */
-               case 0x4:
-                       return 1;       /* MI_FLUSH */
-               default:
-                       return 0;       /* disallow everything else */
-               }
-               break;
-       case 0x1:
-               return 0;       /* reserved */
-       case 0x2:
-               return (cmd & 0xff) + 2;        /* 2d commands */
-       case 0x3:
-               if (((cmd >> 24) & 0x1f) <= 0x18)
-                       return 1;
-
-               switch ((cmd >> 24) & 0x1f) {
-               case 0x1c:
-                       return 1;
-               case 0x1d:
-                       switch ((cmd >> 16) & 0xff) {
-                       case 0x3:
-                               return (cmd & 0x1f) + 2;
-                       case 0x4:
-                               return (cmd & 0xf) + 2;
-                       default:
-                               return (cmd & 0xffff) + 2;
-                       }
-               case 0x1e:
-                       if (cmd & (1 << 23))
-                               return (cmd & 0xffff) + 1;
-                       else
-                               return 1;
-               case 0x1f:
-                       if ((cmd & (1 << 23)) == 0)     /* inline vertices */
-                               return (cmd & 0x1ffff) + 2;
-                       else if (cmd & (1 << 17))       /* indirect random */
-                               if ((cmd & 0xffff) == 0)
-                                       return 0;       /* unknown length, too hard */
-                               else
-                                       return (((cmd & 0xffff) + 1) / 2) + 1;
-                       else
-                               return 2;       /* indirect sequential */
-               default:
-                       return 0;
-               }
-       default:
-               return 0;
-       }
-
-       return 0;
-}
-
-static int validate_cmd(int cmd)
-{
-       int ret = do_validate_cmd(cmd);
-
-/*     printk("validate_cmd( %x ): %d\n", cmd, ret); */
-
-       return ret;
-}
-
-static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       int i;
-       RING_LOCALS;
-
-       if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
-               return -EINVAL;
-
-       BEGIN_LP_RING((dwords+1)&~1);
-
-       for (i = 0; i < dwords;) {
-               int cmd, sz;
-
-               if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
-                       return -EINVAL;
-
-               if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
-                       return -EINVAL;
-
-               OUT_RING(cmd);
-
-               while (++i, --sz) {
-                       if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
-                                                        sizeof(cmd))) {
-                               return -EINVAL;
-                       }
-                       OUT_RING(cmd);
-               }
-       }
-
-       if (dwords & 1)
-               OUT_RING(0);
-
-       ADVANCE_LP_RING();
-
-       return 0;
-}
-
-static int i915_emit_box(struct drm_device * dev,
-                        struct drm_clip_rect __user * boxes,
-                        int i, int DR1, int DR4)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       struct drm_clip_rect box;
-       RING_LOCALS;
-
-       if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
-               return -EFAULT;
-       }
-
-       if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
-               DRM_ERROR("Bad box %d,%d..%d,%d\n",
-                         box.x1, box.y1, box.x2, box.y2);
-               return -EINVAL;
-       }
-
-       if (IS_I965G(dev)) {
-               BEGIN_LP_RING(4);
-               OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
-               OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
-               OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
-               OUT_RING(DR4);
-               ADVANCE_LP_RING();
-       } else {
-               BEGIN_LP_RING(6);
-               OUT_RING(GFX_OP_DRAWRECT_INFO);
-               OUT_RING(DR1);
-               OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
-               OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
-               OUT_RING(DR4);
-               OUT_RING(0);
-               ADVANCE_LP_RING();
-       }
-
-       return 0;
-}
-
-/* XXX: Emitting the counter should really be moved to part of the IRQ
- * emit. For now, do it in both places:
- */
-
-static void i915_emit_breadcrumb(struct drm_device *dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
-
-       if (dev_priv->counter > 0x7FFFFFFFUL)
-               dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
-
-       BEGIN_LP_RING(4);
-       OUT_RING(CMD_STORE_DWORD_IDX);
-       OUT_RING(20);
-       OUT_RING(dev_priv->counter);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-}
-
-static int i915_dispatch_cmdbuffer(struct drm_device * dev,
-                                  drm_i915_cmdbuffer_t * cmd)
-{
-       int nbox = cmd->num_cliprects;
-       int i = 0, count, ret;
-
-       if (cmd->sz & 0x3) {
-               DRM_ERROR("alignment");
-               return -EINVAL;
-       }
-
-       i915_kernel_lost_context(dev);
-
-       count = nbox ? nbox : 1;
-
-       for (i = 0; i < count; i++) {
-               if (i < nbox) {
-                       ret = i915_emit_box(dev, cmd->cliprects, i,
-                                           cmd->DR1, cmd->DR4);
-                       if (ret)
-                               return ret;
-               }
-
-               ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
-               if (ret)
-                       return ret;
-       }
-
-       i915_emit_breadcrumb(dev);
-       return 0;
-}
-
-static int i915_dispatch_batchbuffer(struct drm_device * dev,
-                                    drm_i915_batchbuffer_t * batch)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       struct drm_clip_rect __user *boxes = batch->cliprects;
-       int nbox = batch->num_cliprects;
-       int i = 0, count;
-       RING_LOCALS;
-
-       if ((batch->start | batch->used) & 0x7) {
-               DRM_ERROR("alignment");
-               return -EINVAL;
-       }
-
-       i915_kernel_lost_context(dev);
-
-       count = nbox ? nbox : 1;
-
-       for (i = 0; i < count; i++) {
-               if (i < nbox) {
-                       int ret = i915_emit_box(dev, boxes, i,
-                                               batch->DR1, batch->DR4);
-                       if (ret)
-                               return ret;
-               }
-
-               if (dev_priv->use_mi_batchbuffer_start) {
-                       BEGIN_LP_RING(2);
-                       if (IS_I965G(dev)) {
-                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
-                               OUT_RING(batch->start);
-                       } else {
-                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
-                               OUT_RING(batch->start | MI_BATCH_NON_SECURE);
-                       }
-                       ADVANCE_LP_RING();
-               } else {
-                       BEGIN_LP_RING(4);
-                       OUT_RING(MI_BATCH_BUFFER);
-                       OUT_RING(batch->start | MI_BATCH_NON_SECURE);
-                       OUT_RING(batch->start + batch->used - 4);
-                       OUT_RING(0);
-                       ADVANCE_LP_RING();
-               }
-       }
-
-       i915_emit_breadcrumb(dev);
-
-       return 0;
-}
-
-static int i915_dispatch_flip(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
-                 __FUNCTION__,
-                 dev_priv->current_page,
-                 dev_priv->sarea_priv->pf_current_page);
-
-       i915_kernel_lost_context(dev);
-
-       BEGIN_LP_RING(2);
-       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(6);
-       OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
-       OUT_RING(0);
-       if (dev_priv->current_page == 0) {
-               OUT_RING(dev_priv->back_offset);
-               dev_priv->current_page = 1;
-       } else {
-               OUT_RING(dev_priv->front_offset);
-               dev_priv->current_page = 0;
-       }
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       BEGIN_LP_RING(2);
-       OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
-
-       BEGIN_LP_RING(4);
-       OUT_RING(CMD_STORE_DWORD_IDX);
-       OUT_RING(20);
-       OUT_RING(dev_priv->counter);
-       OUT_RING(0);
-       ADVANCE_LP_RING();
-
-       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
-       return 0;
-}
-
-static int i915_quiescent(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-
-       i915_kernel_lost_context(dev);
-       return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
-}
-
-static int i915_flush_ioctl(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv)
-{
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return i915_quiescent(dev);
-}
-
-static int i915_batchbuffer(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
-           dev_priv->sarea_priv;
-       drm_i915_batchbuffer_t *batch = data;
-       int ret;
-
-       if (!dev_priv->allow_batchbuffer) {
-               DRM_ERROR("Batchbuffer ioctl disabled\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
-                 batch->start, batch->used, batch->num_cliprects);
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
-                                                      batch->num_cliprects *
-                                                      sizeof(struct drm_clip_rect)))
-               return -EFAULT;
-
-       ret = i915_dispatch_batchbuffer(dev, batch);
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-       return ret;
-}
-
-static int i915_cmdbuffer(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       u32 *hw_status = dev_priv->hw_status_page;
-       drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
-           dev_priv->sarea_priv;
-       drm_i915_cmdbuffer_t *cmdbuf = data;
-       int ret;
-
-       DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
-                 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (cmdbuf->num_cliprects &&
-           DRM_VERIFYAREA_READ(cmdbuf->cliprects,
-                               cmdbuf->num_cliprects *
-                               sizeof(struct drm_clip_rect))) {
-               DRM_ERROR("Fault accessing cliprects\n");
-               return -EFAULT;
-       }
-
-       ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
-       if (ret) {
-               DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
-               return ret;
-       }
-
-       sarea_priv->last_dispatch = (int)hw_status[5];
-       return 0;
-}
-
-static int i915_flip_bufs(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv)
-{
-       DRM_DEBUG("%s\n", __FUNCTION__);
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return i915_dispatch_flip(dev);
-}
-
-static int i915_getparam(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_getparam_t *param = data;
-       int value;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       switch (param->param) {
-       case I915_PARAM_IRQ_ACTIVE:
-               value = dev->irq ? 1 : 0;
-               break;
-       case I915_PARAM_ALLOW_BATCHBUFFER:
-               value = dev_priv->allow_batchbuffer ? 1 : 0;
-               break;
-       case I915_PARAM_LAST_DISPATCH:
-               value = READ_BREADCRUMB(dev_priv);
-               break;
-       default:
-               DRM_ERROR("Unknown parameter %d\n", param->param);
-               return -EINVAL;
-       }
-
-       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
-               DRM_ERROR("DRM_COPY_TO_USER failed\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-static int i915_setparam(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_setparam_t *param = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       switch (param->param) {
-       case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
-               if (!IS_I965G(dev))
-                       dev_priv->use_mi_batchbuffer_start = param->value;
-               break;
-       case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
-               dev_priv->tex_lru_log_granularity = param->value;
-               break;
-       case I915_SETPARAM_ALLOW_BATCHBUFFER:
-               dev_priv->allow_batchbuffer = param->value;
-               break;
-       default:
-               DRM_ERROR("unknown parameter %d\n", param->param);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int i915_set_status_page(struct drm_device *dev, void *data,
-                               struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_hws_addr_t *hws = data;
-
-       if (!I915_NEED_GFX_HWS(dev))
-               return -EINVAL;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr);
-
-       dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
-
-       dev_priv->hws_map.offset = dev->agp->base + hws->addr;
-       dev_priv->hws_map.size = 4*1024;
-       dev_priv->hws_map.type = 0;
-       dev_priv->hws_map.flags = 0;
-       dev_priv->hws_map.mtrr = 0;
-
-       drm_core_ioremap(&dev_priv->hws_map, dev);
-       if (dev_priv->hws_map.handle == NULL) {
-               i915_dma_cleanup(dev);
-               dev_priv->status_gfx_addr = 0;
-               DRM_ERROR("can not ioremap virtual address for"
-                               " G33 hw status page\n");
-               return -ENOMEM;
-       }
-       dev_priv->hw_status_page = dev_priv->hws_map.handle;
-
-       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
-       I915_WRITE(0x02080, dev_priv->status_gfx_addr);
-       DRM_DEBUG("load hws 0x2080 with gfx mem 0x%x\n",
-                       dev_priv->status_gfx_addr);
-       DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
-       return 0;
-}
-
-int i915_driver_load(struct drm_device *dev, unsigned long flags)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       unsigned long base, size;
-       int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
-
-       /* i915 has 4 more counters */
-       dev->counters += 4;
-       dev->types[6] = _DRM_STAT_IRQ;
-       dev->types[7] = _DRM_STAT_PRIMARY;
-       dev->types[8] = _DRM_STAT_SECONDARY;
-       dev->types[9] = _DRM_STAT_DMA;
-
-       dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv, 0, sizeof(drm_i915_private_t));
-
-       dev->dev_private = (void *)dev_priv;
-
-       /* Add register map (needed for suspend/resume) */
-       base = drm_get_resource_start(dev, mmio_bar);
-       size = drm_get_resource_len(dev, mmio_bar);
-
-       ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
-                        _DRM_KERNEL | _DRM_DRIVER,
-                        &dev_priv->mmio_map);
-       return ret;
-}
-
-int i915_driver_unload(struct drm_device *dev)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-
-       if (dev_priv->mmio_map)
-               drm_rmmap(dev, dev_priv->mmio_map);
-
-       drm_free(dev->dev_private, sizeof(drm_i915_private_t),
-                DRM_MEM_DRIVER);
-
-       return 0;
-}
-
-void i915_driver_lastclose(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-
-       if (!dev_priv)
-               return;
-
-       if (dev_priv->agp_heap)
-               i915_mem_takedown(&(dev_priv->agp_heap));
-
-       i915_dma_cleanup(dev);
-}
-
-void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       i915_mem_release(dev, file_priv, dev_priv->agp_heap);
-}
-
-struct drm_ioctl_desc i915_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP,  i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
-       DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE,  i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
-       DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE,  i915_vblank_pipe_get, DRM_AUTH ),
-       DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
-};
-
-int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
-
-/**
- * Determine if the device really is AGP or not.
- *
- * All Intel graphics chipsets are treated as AGP, even if they are really
- * PCI-e.
- *
- * \param dev   The device to be tested.
- *
- * \returns
- * A value of 1 is always retured to indictate every i9x5 is AGP.
- */
-int i915_driver_device_is_agp(struct drm_device * dev)
-{
-       return 1;
-}
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
deleted file mode 100644 (file)
index 05c66cf..0000000
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef _I915_DRM_H_
-#define _I915_DRM_H_
-
-/* Please note that modifications to all structs defined here are
- * subject to backwards-compatibility constraints.
- */
-
-#include "drm.h"
-
-/* Each region is a minimum of 16k, and there are at most 255 of them.
- */
-#define I915_NR_TEX_REGIONS 255        /* table size 2k - maximum due to use
-                                * of chars for next/prev indices */
-#define I915_LOG_MIN_TEX_REGION_SIZE 14
-
-typedef struct _drm_i915_init {
-       enum {
-               I915_INIT_DMA = 0x01,
-               I915_CLEANUP_DMA = 0x02,
-               I915_RESUME_DMA = 0x03
-       } func;
-       unsigned int mmio_offset;
-       int sarea_priv_offset;
-       unsigned int ring_start;
-       unsigned int ring_end;
-       unsigned int ring_size;
-       unsigned int front_offset;
-       unsigned int back_offset;
-       unsigned int depth_offset;
-       unsigned int w;
-       unsigned int h;
-       unsigned int pitch;
-       unsigned int pitch_bits;
-       unsigned int back_pitch;
-       unsigned int depth_pitch;
-       unsigned int cpp;
-       unsigned int chipset;
-} drm_i915_init_t;
-
-typedef struct _drm_i915_sarea {
-       struct drm_tex_region texList[I915_NR_TEX_REGIONS + 1];
-       int last_upload;        /* last time texture was uploaded */
-       int last_enqueue;       /* last time a buffer was enqueued */
-       int last_dispatch;      /* age of the most recently dispatched buffer */
-       int ctxOwner;           /* last context to upload state */
-       int texAge;
-       int pf_enabled;         /* is pageflipping allowed? */
-       int pf_active;
-       int pf_current_page;    /* which buffer is being displayed? */
-       int perf_boxes;         /* performance boxes to be displayed */
-       int width, height;      /* screen size in pixels */
-
-       drm_handle_t front_handle;
-       int front_offset;
-       int front_size;
-
-       drm_handle_t back_handle;
-       int back_offset;
-       int back_size;
-
-       drm_handle_t depth_handle;
-       int depth_offset;
-       int depth_size;
-
-       drm_handle_t tex_handle;
-       int tex_offset;
-       int tex_size;
-       int log_tex_granularity;
-       int pitch;
-       int rotation;           /* 0, 90, 180 or 270 */
-       int rotated_offset;
-       int rotated_size;
-       int rotated_pitch;
-       int virtualX, virtualY;
-
-       unsigned int front_tiled;
-       unsigned int back_tiled;
-       unsigned int depth_tiled;
-       unsigned int rotated_tiled;
-       unsigned int rotated2_tiled;
-
-       int pipeA_x;
-       int pipeA_y;
-       int pipeA_w;
-       int pipeA_h;
-       int pipeB_x;
-       int pipeB_y;
-       int pipeB_w;
-       int pipeB_h;
-} drm_i915_sarea_t;
-
-/* Flags for perf_boxes
- */
-#define I915_BOX_RING_EMPTY    0x1
-#define I915_BOX_FLIP          0x2
-#define I915_BOX_WAIT          0x4
-#define I915_BOX_TEXTURE_LOAD  0x8
-#define I915_BOX_LOST_CONTEXT  0x10
-
-/* I915 specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_I915_INIT          0x00
-#define DRM_I915_FLUSH         0x01
-#define DRM_I915_FLIP          0x02
-#define DRM_I915_BATCHBUFFER   0x03
-#define DRM_I915_IRQ_EMIT      0x04
-#define DRM_I915_IRQ_WAIT      0x05
-#define DRM_I915_GETPARAM      0x06
-#define DRM_I915_SETPARAM      0x07
-#define DRM_I915_ALLOC         0x08
-#define DRM_I915_FREE          0x09
-#define DRM_I915_INIT_HEAP     0x0a
-#define DRM_I915_CMDBUFFER     0x0b
-#define DRM_I915_DESTROY_HEAP  0x0c
-#define DRM_I915_SET_VBLANK_PIPE       0x0d
-#define DRM_I915_GET_VBLANK_PIPE       0x0e
-#define DRM_I915_VBLANK_SWAP   0x0f
-#define DRM_I915_HWS_ADDR      0x11
-
-#define DRM_IOCTL_I915_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
-#define DRM_IOCTL_I915_FLUSH           DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
-#define DRM_IOCTL_I915_FLIP            DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLIP)
-#define DRM_IOCTL_I915_BATCHBUFFER     DRM_IOW( DRM_COMMAND_BASE + DRM_I915_BATCHBUFFER, drm_i915_batchbuffer_t)
-#define DRM_IOCTL_I915_IRQ_EMIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_IRQ_EMIT, drm_i915_irq_emit_t)
-#define DRM_IOCTL_I915_IRQ_WAIT         DRM_IOW( DRM_COMMAND_BASE + DRM_I915_IRQ_WAIT, drm_i915_irq_wait_t)
-#define DRM_IOCTL_I915_GETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GETPARAM, drm_i915_getparam_t)
-#define DRM_IOCTL_I915_SETPARAM         DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SETPARAM, drm_i915_setparam_t)
-#define DRM_IOCTL_I915_ALLOC            DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_ALLOC, drm_i915_mem_alloc_t)
-#define DRM_IOCTL_I915_FREE             DRM_IOW( DRM_COMMAND_BASE + DRM_I915_FREE, drm_i915_mem_free_t)
-#define DRM_IOCTL_I915_INIT_HEAP        DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT_HEAP, drm_i915_mem_init_heap_t)
-#define DRM_IOCTL_I915_CMDBUFFER       DRM_IOW( DRM_COMMAND_BASE + DRM_I915_CMDBUFFER, drm_i915_cmdbuffer_t)
-#define DRM_IOCTL_I915_DESTROY_HEAP    DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t)
-#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
-#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
-#define DRM_IOCTL_I915_VBLANK_SWAP     DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_VBLANK_SWAP, drm_i915_vblank_swap_t)
-
-/* Allow drivers to submit batchbuffers directly to hardware, relying
- * on the security mechanisms provided by hardware.
- */
-typedef struct _drm_i915_batchbuffer {
-       int start;              /* agp offset */
-       int used;               /* nr bytes in use */
-       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
-       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
-       int num_cliprects;      /* mulitpass with multiple cliprects? */
-       struct drm_clip_rect __user *cliprects; /* pointer to userspace cliprects */
-} drm_i915_batchbuffer_t;
-
-/* As above, but pass a pointer to userspace buffer which can be
- * validated by the kernel prior to sending to hardware.
- */
-typedef struct _drm_i915_cmdbuffer {
-       char __user *buf;       /* pointer to userspace command buffer */
-       int sz;                 /* nr bytes in buf */
-       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
-       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
-       int num_cliprects;      /* mulitpass with multiple cliprects? */
-       struct drm_clip_rect __user *cliprects; /* pointer to userspace cliprects */
-} drm_i915_cmdbuffer_t;
-
-/* Userspace can request & wait on irq's:
- */
-typedef struct drm_i915_irq_emit {
-       int __user *irq_seq;
-} drm_i915_irq_emit_t;
-
-typedef struct drm_i915_irq_wait {
-       int irq_seq;
-} drm_i915_irq_wait_t;
-
-/* Ioctl to query kernel params:
- */
-#define I915_PARAM_IRQ_ACTIVE            1
-#define I915_PARAM_ALLOW_BATCHBUFFER     2
-#define I915_PARAM_LAST_DISPATCH         3
-
-typedef struct drm_i915_getparam {
-       int param;
-       int __user *value;
-} drm_i915_getparam_t;
-
-/* Ioctl to set kernel params:
- */
-#define I915_SETPARAM_USE_MI_BATCHBUFFER_START            1
-#define I915_SETPARAM_TEX_LRU_LOG_GRANULARITY             2
-#define I915_SETPARAM_ALLOW_BATCHBUFFER                   3
-
-typedef struct drm_i915_setparam {
-       int param;
-       int value;
-} drm_i915_setparam_t;
-
-/* A memory manager for regions of shared memory:
- */
-#define I915_MEM_REGION_AGP 1
-
-typedef struct drm_i915_mem_alloc {
-       int region;
-       int alignment;
-       int size;
-       int __user *region_offset;      /* offset from start of fb or agp */
-} drm_i915_mem_alloc_t;
-
-typedef struct drm_i915_mem_free {
-       int region;
-       int region_offset;
-} drm_i915_mem_free_t;
-
-typedef struct drm_i915_mem_init_heap {
-       int region;
-       int size;
-       int start;
-} drm_i915_mem_init_heap_t;
-
-/* Allow memory manager to be torn down and re-initialized (eg on
- * rotate):
- */
-typedef struct drm_i915_mem_destroy_heap {
-       int region;
-} drm_i915_mem_destroy_heap_t;
-
-/* Allow X server to configure which pipes to monitor for vblank signals
- */
-#define        DRM_I915_VBLANK_PIPE_A  1
-#define        DRM_I915_VBLANK_PIPE_B  2
-
-typedef struct drm_i915_vblank_pipe {
-       int pipe;
-} drm_i915_vblank_pipe_t;
-
-/* Schedule buffer swap at given vertical blank:
- */
-typedef struct drm_i915_vblank_swap {
-       drm_drawable_t drawable;
-       enum drm_vblank_seq_type seqtype;
-       unsigned int sequence;
-} drm_i915_vblank_swap_t;
-
-typedef struct drm_i915_hws_addr {
-       uint64_t addr;
-} drm_i915_hws_addr_t;
-
-#endif                         /* _I915_DRM_H_ */
diff --git a/drivers/char/drm/i915_drv.c b/drivers/char/drm/i915_drv.c
deleted file mode 100644 (file)
index 93aed1c..0000000
+++ /dev/null
@@ -1,605 +0,0 @@
-/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
- */
-/*
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-#include "i915_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       i915_PCI_IDS
-};
-
-enum pipe {
-    PIPE_A = 0,
-    PIPE_B,
-};
-
-static bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-
-       if (pipe == PIPE_A)
-               return (I915_READ(DPLL_A) & DPLL_VCO_ENABLE);
-       else
-               return (I915_READ(DPLL_B) & DPLL_VCO_ENABLE);
-}
-
-static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
-       u32 *array;
-       int i;
-
-       if (!i915_pipe_enabled(dev, pipe))
-               return;
-
-       if (pipe == PIPE_A)
-               array = dev_priv->save_palette_a;
-       else
-               array = dev_priv->save_palette_b;
-
-       for(i = 0; i < 256; i++)
-               array[i] = I915_READ(reg + (i << 2));
-}
-
-static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
-       u32 *array;
-       int i;
-
-       if (!i915_pipe_enabled(dev, pipe))
-               return;
-
-       if (pipe == PIPE_A)
-               array = dev_priv->save_palette_a;
-       else
-               array = dev_priv->save_palette_b;
-
-       for(i = 0; i < 256; i++)
-               I915_WRITE(reg + (i << 2), array[i]);
-}
-
-static u8 i915_read_indexed(u16 index_port, u16 data_port, u8 reg)
-{
-       outb(reg, index_port);
-       return inb(data_port);
-}
-
-static u8 i915_read_ar(u16 st01, u8 reg, u16 palette_enable)
-{
-       inb(st01);
-       outb(palette_enable | reg, VGA_AR_INDEX);
-       return inb(VGA_AR_DATA_READ);
-}
-
-static void i915_write_ar(u8 st01, u8 reg, u8 val, u16 palette_enable)
-{
-       inb(st01);
-       outb(palette_enable | reg, VGA_AR_INDEX);
-       outb(val, VGA_AR_DATA_WRITE);
-}
-
-static void i915_write_indexed(u16 index_port, u16 data_port, u8 reg, u8 val)
-{
-       outb(reg, index_port);
-       outb(val, data_port);
-}
-
-static void i915_save_vga(struct drm_device *dev)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       int i;
-       u16 cr_index, cr_data, st01;
-
-       /* VGA color palette registers */
-       dev_priv->saveDACMASK = inb(VGA_DACMASK);
-       /* DACCRX automatically increments during read */
-       outb(0, VGA_DACRX);
-       /* Read 3 bytes of color data from each index */
-       for (i = 0; i < 256 * 3; i++)
-               dev_priv->saveDACDATA[i] = inb(VGA_DACDATA);
-
-       /* MSR bits */
-       dev_priv->saveMSR = inb(VGA_MSR_READ);
-       if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
-               cr_index = VGA_CR_INDEX_CGA;
-               cr_data = VGA_CR_DATA_CGA;
-               st01 = VGA_ST01_CGA;
-       } else {
-               cr_index = VGA_CR_INDEX_MDA;
-               cr_data = VGA_CR_DATA_MDA;
-               st01 = VGA_ST01_MDA;
-       }
-
-       /* CRT controller regs */
-       i915_write_indexed(cr_index, cr_data, 0x11,
-                          i915_read_indexed(cr_index, cr_data, 0x11) &
-                          (~0x80));
-       for (i = 0; i <= 0x24; i++)
-               dev_priv->saveCR[i] =
-                       i915_read_indexed(cr_index, cr_data, i);
-       /* Make sure we don't turn off CR group 0 writes */
-       dev_priv->saveCR[0x11] &= ~0x80;
-
-       /* Attribute controller registers */
-       inb(st01);
-       dev_priv->saveAR_INDEX = inb(VGA_AR_INDEX);
-       for (i = 0; i <= 0x14; i++)
-               dev_priv->saveAR[i] = i915_read_ar(st01, i, 0);
-       inb(st01);
-       outb(dev_priv->saveAR_INDEX, VGA_AR_INDEX);
-       inb(st01);
-
-       /* Graphics controller registers */
-       for (i = 0; i < 9; i++)
-               dev_priv->saveGR[i] =
-                       i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, i);
-
-       dev_priv->saveGR[0x10] =
-               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10);
-       dev_priv->saveGR[0x11] =
-               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11);
-       dev_priv->saveGR[0x18] =
-               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18);
-
-       /* Sequencer registers */
-       for (i = 0; i < 8; i++)
-               dev_priv->saveSR[i] =
-                       i915_read_indexed(VGA_SR_INDEX, VGA_SR_DATA, i);
-}
-
-static void i915_restore_vga(struct drm_device *dev)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       int i;
-       u16 cr_index, cr_data, st01;
-
-       /* MSR bits */
-       outb(dev_priv->saveMSR, VGA_MSR_WRITE);
-       if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
-               cr_index = VGA_CR_INDEX_CGA;
-               cr_data = VGA_CR_DATA_CGA;
-               st01 = VGA_ST01_CGA;
-       } else {
-               cr_index = VGA_CR_INDEX_MDA;
-               cr_data = VGA_CR_DATA_MDA;
-               st01 = VGA_ST01_MDA;
-       }
-
-       /* Sequencer registers, don't write SR07 */
-       for (i = 0; i < 7; i++)
-               i915_write_indexed(VGA_SR_INDEX, VGA_SR_DATA, i,
-                                  dev_priv->saveSR[i]);
-
-       /* CRT controller regs */
-       /* Enable CR group 0 writes */
-       i915_write_indexed(cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
-       for (i = 0; i <= 0x24; i++)
-               i915_write_indexed(cr_index, cr_data, i, dev_priv->saveCR[i]);
-
-       /* Graphics controller regs */
-       for (i = 0; i < 9; i++)
-               i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, i,
-                                  dev_priv->saveGR[i]);
-
-       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10,
-                          dev_priv->saveGR[0x10]);
-       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11,
-                          dev_priv->saveGR[0x11]);
-       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18,
-                          dev_priv->saveGR[0x18]);
-
-       /* Attribute controller registers */
-       inb(st01);
-       for (i = 0; i <= 0x14; i++)
-               i915_write_ar(st01, i, dev_priv->saveAR[i], 0);
-       inb(st01); /* switch back to index mode */
-       outb(dev_priv->saveAR_INDEX | 0x20, VGA_AR_INDEX);
-       inb(st01);
-
-       /* VGA color palette registers */
-       outb(dev_priv->saveDACMASK, VGA_DACMASK);
-       /* DACCRX automatically increments during read */
-       outb(0, VGA_DACWX);
-       /* Read 3 bytes of color data from each index */
-       for (i = 0; i < 256 * 3; i++)
-               outb(dev_priv->saveDACDATA[i], VGA_DACDATA);
-
-}
-
-static int i915_suspend(struct drm_device *dev, pm_message_t state)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       int i;
-
-       if (!dev || !dev_priv) {
-               printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv);
-               printk(KERN_ERR "DRM not initialized, aborting suspend.\n");
-               return -ENODEV;
-       }
-
-       if (state.event == PM_EVENT_PRETHAW)
-               return 0;
-
-       pci_save_state(dev->pdev);
-       pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
-
-       /* Display arbitration control */
-       dev_priv->saveDSPARB = I915_READ(DSPARB);
-
-       /* Pipe & plane A info */
-       dev_priv->savePIPEACONF = I915_READ(PIPEACONF);
-       dev_priv->savePIPEASRC = I915_READ(PIPEASRC);
-       dev_priv->saveFPA0 = I915_READ(FPA0);
-       dev_priv->saveFPA1 = I915_READ(FPA1);
-       dev_priv->saveDPLL_A = I915_READ(DPLL_A);
-       if (IS_I965G(dev))
-               dev_priv->saveDPLL_A_MD = I915_READ(DPLL_A_MD);
-       dev_priv->saveHTOTAL_A = I915_READ(HTOTAL_A);
-       dev_priv->saveHBLANK_A = I915_READ(HBLANK_A);
-       dev_priv->saveHSYNC_A = I915_READ(HSYNC_A);
-       dev_priv->saveVTOTAL_A = I915_READ(VTOTAL_A);
-       dev_priv->saveVBLANK_A = I915_READ(VBLANK_A);
-       dev_priv->saveVSYNC_A = I915_READ(VSYNC_A);
-       dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
-
-       dev_priv->saveDSPACNTR = I915_READ(DSPACNTR);
-       dev_priv->saveDSPASTRIDE = I915_READ(DSPASTRIDE);
-       dev_priv->saveDSPASIZE = I915_READ(DSPASIZE);
-       dev_priv->saveDSPAPOS = I915_READ(DSPAPOS);
-       dev_priv->saveDSPABASE = I915_READ(DSPABASE);
-       if (IS_I965G(dev)) {
-               dev_priv->saveDSPASURF = I915_READ(DSPASURF);
-               dev_priv->saveDSPATILEOFF = I915_READ(DSPATILEOFF);
-       }
-       i915_save_palette(dev, PIPE_A);
-       dev_priv->savePIPEASTAT = I915_READ(I915REG_PIPEASTAT);
-
-       /* Pipe & plane B info */
-       dev_priv->savePIPEBCONF = I915_READ(PIPEBCONF);
-       dev_priv->savePIPEBSRC = I915_READ(PIPEBSRC);
-       dev_priv->saveFPB0 = I915_READ(FPB0);
-       dev_priv->saveFPB1 = I915_READ(FPB1);
-       dev_priv->saveDPLL_B = I915_READ(DPLL_B);
-       if (IS_I965G(dev))
-               dev_priv->saveDPLL_B_MD = I915_READ(DPLL_B_MD);
-       dev_priv->saveHTOTAL_B = I915_READ(HTOTAL_B);
-       dev_priv->saveHBLANK_B = I915_READ(HBLANK_B);
-       dev_priv->saveHSYNC_B = I915_READ(HSYNC_B);
-       dev_priv->saveVTOTAL_B = I915_READ(VTOTAL_B);
-       dev_priv->saveVBLANK_B = I915_READ(VBLANK_B);
-       dev_priv->saveVSYNC_B = I915_READ(VSYNC_B);
-       dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
-
-       dev_priv->saveDSPBCNTR = I915_READ(DSPBCNTR);
-       dev_priv->saveDSPBSTRIDE = I915_READ(DSPBSTRIDE);
-       dev_priv->saveDSPBSIZE = I915_READ(DSPBSIZE);
-       dev_priv->saveDSPBPOS = I915_READ(DSPBPOS);
-       dev_priv->saveDSPBBASE = I915_READ(DSPBBASE);
-       if (IS_I965GM(dev) || IS_IGD_GM(dev)) {
-               dev_priv->saveDSPBSURF = I915_READ(DSPBSURF);
-               dev_priv->saveDSPBTILEOFF = I915_READ(DSPBTILEOFF);
-       }
-       i915_save_palette(dev, PIPE_B);
-       dev_priv->savePIPEBSTAT = I915_READ(I915REG_PIPEBSTAT);
-
-       /* CRT state */
-       dev_priv->saveADPA = I915_READ(ADPA);
-
-       /* LVDS state */
-       dev_priv->savePP_CONTROL = I915_READ(PP_CONTROL);
-       dev_priv->savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
-       dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
-       if (IS_I965G(dev))
-               dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
-       if (IS_MOBILE(dev) && !IS_I830(dev))
-               dev_priv->saveLVDS = I915_READ(LVDS);
-       if (!IS_I830(dev) && !IS_845G(dev))
-               dev_priv->savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
-       dev_priv->saveLVDSPP_ON = I915_READ(LVDSPP_ON);
-       dev_priv->saveLVDSPP_OFF = I915_READ(LVDSPP_OFF);
-       dev_priv->savePP_CYCLE = I915_READ(PP_CYCLE);
-
-       /* FIXME: save TV & SDVO state */
-
-       /* FBC state */
-       dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
-       dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
-       dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
-       dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL);
-
-       /* Interrupt state */
-       dev_priv->saveIIR = I915_READ(I915REG_INT_IDENTITY_R);
-       dev_priv->saveIER = I915_READ(I915REG_INT_ENABLE_R);
-       dev_priv->saveIMR = I915_READ(I915REG_INT_MASK_R);
-
-       /* VGA state */
-       dev_priv->saveVCLK_DIVISOR_VGA0 = I915_READ(VCLK_DIVISOR_VGA0);
-       dev_priv->saveVCLK_DIVISOR_VGA1 = I915_READ(VCLK_DIVISOR_VGA1);
-       dev_priv->saveVCLK_POST_DIV = I915_READ(VCLK_POST_DIV);
-       dev_priv->saveVGACNTRL = I915_READ(VGACNTRL);
-
-       /* Clock gating state */
-       dev_priv->saveD_STATE = I915_READ(D_STATE);
-       dev_priv->saveDSPCLK_GATE_D = I915_READ(DSPCLK_GATE_D);
-
-       /* Cache mode state */
-       dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
-
-       /* Memory Arbitration state */
-       dev_priv->saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
-
-       /* Scratch space */
-       for (i = 0; i < 16; i++) {
-               dev_priv->saveSWF0[i] = I915_READ(SWF0 + (i << 2));
-               dev_priv->saveSWF1[i] = I915_READ(SWF10 + (i << 2));
-       }
-       for (i = 0; i < 3; i++)
-               dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
-
-       i915_save_vga(dev);
-
-       if (state.event == PM_EVENT_SUSPEND) {
-               /* Shut down the device */
-               pci_disable_device(dev->pdev);
-               pci_set_power_state(dev->pdev, PCI_D3hot);
-       }
-
-       return 0;
-}
-
-static int i915_resume(struct drm_device *dev)
-{
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       int i;
-
-       pci_set_power_state(dev->pdev, PCI_D0);
-       pci_restore_state(dev->pdev);
-       if (pci_enable_device(dev->pdev))
-               return -1;
-       pci_set_master(dev->pdev);
-
-       pci_write_config_byte(dev->pdev, LBB, dev_priv->saveLBB);
-
-       I915_WRITE(DSPARB, dev_priv->saveDSPARB);
-
-       /* Pipe & plane A info */
-       /* Prime the clock */
-       if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
-               I915_WRITE(DPLL_A, dev_priv->saveDPLL_A &
-                          ~DPLL_VCO_ENABLE);
-               udelay(150);
-       }
-       I915_WRITE(FPA0, dev_priv->saveFPA0);
-       I915_WRITE(FPA1, dev_priv->saveFPA1);
-       /* Actually enable it */
-       I915_WRITE(DPLL_A, dev_priv->saveDPLL_A);
-       udelay(150);
-       if (IS_I965G(dev))
-               I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
-       udelay(150);
-
-       /* Restore mode */
-       I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
-       I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
-       I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
-       I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
-       I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
-       I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
-       I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
-
-       /* Restore plane info */
-       I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
-       I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
-       I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
-       I915_WRITE(DSPABASE, dev_priv->saveDSPABASE);
-       I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
-       if (IS_I965G(dev)) {
-               I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
-               I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
-       }
-
-       I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
-
-       i915_restore_palette(dev, PIPE_A);
-       /* Enable the plane */
-       I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
-       I915_WRITE(DSPABASE, I915_READ(DSPABASE));
-
-       /* Pipe & plane B info */
-       if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
-               I915_WRITE(DPLL_B, dev_priv->saveDPLL_B &
-                          ~DPLL_VCO_ENABLE);
-               udelay(150);
-       }
-       I915_WRITE(FPB0, dev_priv->saveFPB0);
-       I915_WRITE(FPB1, dev_priv->saveFPB1);
-       /* Actually enable it */
-       I915_WRITE(DPLL_B, dev_priv->saveDPLL_B);
-       udelay(150);
-       if (IS_I965G(dev))
-               I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
-       udelay(150);
-
-       /* Restore mode */
-       I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
-       I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
-       I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
-       I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
-       I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
-       I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
-       I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
-
-       /* Restore plane info */
-       I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
-       I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
-       I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
-       I915_WRITE(DSPBBASE, dev_priv->saveDSPBBASE);
-       I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
-       if (IS_I965G(dev)) {
-               I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
-               I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
-       }
-
-       I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
-
-       i915_restore_palette(dev, PIPE_B);
-       /* Enable the plane */
-       I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
-       I915_WRITE(DSPBBASE, I915_READ(DSPBBASE));
-
-       /* CRT state */
-       I915_WRITE(ADPA, dev_priv->saveADPA);
-
-       /* LVDS state */
-       if (IS_I965G(dev))
-               I915_WRITE(BLC_PWM_CTL2, dev_priv->saveBLC_PWM_CTL2);
-       if (IS_MOBILE(dev) && !IS_I830(dev))
-               I915_WRITE(LVDS, dev_priv->saveLVDS);
-       if (!IS_I830(dev) && !IS_845G(dev))
-               I915_WRITE(PFIT_CONTROL, dev_priv->savePFIT_CONTROL);
-
-       I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS);
-       I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL);
-       I915_WRITE(LVDSPP_ON, dev_priv->saveLVDSPP_ON);
-       I915_WRITE(LVDSPP_OFF, dev_priv->saveLVDSPP_OFF);
-       I915_WRITE(PP_CYCLE, dev_priv->savePP_CYCLE);
-       I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
-
-       /* FIXME: restore TV & SDVO state */
-
-       /* FBC info */
-       I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE);
-       I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE);
-       I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2);
-       I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL);
-
-       /* VGA state */
-       I915_WRITE(VGACNTRL, dev_priv->saveVGACNTRL);
-       I915_WRITE(VCLK_DIVISOR_VGA0, dev_priv->saveVCLK_DIVISOR_VGA0);
-       I915_WRITE(VCLK_DIVISOR_VGA1, dev_priv->saveVCLK_DIVISOR_VGA1);
-       I915_WRITE(VCLK_POST_DIV, dev_priv->saveVCLK_POST_DIV);
-       udelay(150);
-
-       /* Clock gating state */
-       I915_WRITE (D_STATE, dev_priv->saveD_STATE);
-       I915_WRITE (DSPCLK_GATE_D, dev_priv->saveDSPCLK_GATE_D);
-
-       /* Cache mode state */
-       I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
-
-       /* Memory arbitration state */
-       I915_WRITE (MI_ARB_STATE, dev_priv->saveMI_ARB_STATE | 0xffff0000);
-
-       for (i = 0; i < 16; i++) {
-               I915_WRITE(SWF0 + (i << 2), dev_priv->saveSWF0[i]);
-               I915_WRITE(SWF10 + (i << 2), dev_priv->saveSWF1[i+7]);
-       }
-       for (i = 0; i < 3; i++)
-               I915_WRITE(SWF30 + (i << 2), dev_priv->saveSWF2[i]);
-
-       i915_restore_vga(dev);
-
-       return 0;
-}
-
-static struct drm_driver driver = {
-       /* don't use mtrr's here, the Xserver or user space app should
-        * deal with them for intel hardware.
-        */
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
-           DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL |
-           DRIVER_IRQ_VBL2,
-       .load = i915_driver_load,
-       .unload = i915_driver_unload,
-       .lastclose = i915_driver_lastclose,
-       .preclose = i915_driver_preclose,
-       .suspend = i915_suspend,
-       .resume = i915_resume,
-       .device_is_agp = i915_driver_device_is_agp,
-       .vblank_wait = i915_driver_vblank_wait,
-       .vblank_wait2 = i915_driver_vblank_wait2,
-       .irq_preinstall = i915_driver_irq_preinstall,
-       .irq_postinstall = i915_driver_irq_postinstall,
-       .irq_uninstall = i915_driver_irq_uninstall,
-       .irq_handler = i915_driver_irq_handler,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = i915_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = i915_compat_ioctl,
-#endif
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init i915_init(void)
-{
-       driver.num_ioctls = i915_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit i915_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(i915_init);
-module_exit(i915_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
deleted file mode 100644 (file)
index d7326d9..0000000
+++ /dev/null
@@ -1,1142 +0,0 @@
-/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
- */
-/*
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef _I915_DRV_H_
-#define _I915_DRV_H_
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "Tungsten Graphics, Inc."
-
-#define DRIVER_NAME            "i915"
-#define DRIVER_DESC            "Intel Graphics"
-#define DRIVER_DATE            "20060119"
-
-/* Interface history:
- *
- * 1.1: Original.
- * 1.2: Add Power Management
- * 1.3: Add vblank support
- * 1.4: Fix cmdbuffer path, add heap destroy
- * 1.5: Add vblank pipe configuration
- * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
- *      - Support vertical blank on secondary display pipe
- */
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           6
-#define DRIVER_PATCHLEVEL      0
-
-typedef struct _drm_i915_ring_buffer {
-       int tail_mask;
-       unsigned long Start;
-       unsigned long End;
-       unsigned long Size;
-       u8 *virtual_start;
-       int head;
-       int tail;
-       int space;
-       drm_local_map_t map;
-} drm_i915_ring_buffer_t;
-
-struct mem_block {
-       struct mem_block *next;
-       struct mem_block *prev;
-       int start;
-       int size;
-       struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
-};
-
-typedef struct _drm_i915_vbl_swap {
-       struct list_head head;
-       drm_drawable_t drw_id;
-       unsigned int pipe;
-       unsigned int sequence;
-} drm_i915_vbl_swap_t;
-
-typedef struct drm_i915_private {
-       drm_local_map_t *sarea;
-       drm_local_map_t *mmio_map;
-
-       drm_i915_sarea_t *sarea_priv;
-       drm_i915_ring_buffer_t ring;
-
-       drm_dma_handle_t *status_page_dmah;
-       void *hw_status_page;
-       dma_addr_t dma_status_page;
-       unsigned long counter;
-       unsigned int status_gfx_addr;
-       drm_local_map_t hws_map;
-
-       unsigned int cpp;
-       int back_offset;
-       int front_offset;
-       int current_page;
-       int page_flipping;
-       int use_mi_batchbuffer_start;
-
-       wait_queue_head_t irq_queue;
-       atomic_t irq_received;
-       atomic_t irq_emitted;
-
-       int tex_lru_log_granularity;
-       int allow_batchbuffer;
-       struct mem_block *agp_heap;
-       unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
-       int vblank_pipe;
-
-       spinlock_t swaps_lock;
-       drm_i915_vbl_swap_t vbl_swaps;
-       unsigned int swaps_pending;
-
-       /* Register state */
-       u8 saveLBB;
-       u32 saveDSPACNTR;
-       u32 saveDSPBCNTR;
-       u32 saveDSPARB;
-       u32 savePIPEACONF;
-       u32 savePIPEBCONF;
-       u32 savePIPEASRC;
-       u32 savePIPEBSRC;
-       u32 saveFPA0;
-       u32 saveFPA1;
-       u32 saveDPLL_A;
-       u32 saveDPLL_A_MD;
-       u32 saveHTOTAL_A;
-       u32 saveHBLANK_A;
-       u32 saveHSYNC_A;
-       u32 saveVTOTAL_A;
-       u32 saveVBLANK_A;
-       u32 saveVSYNC_A;
-       u32 saveBCLRPAT_A;
-       u32 savePIPEASTAT;
-       u32 saveDSPASTRIDE;
-       u32 saveDSPASIZE;
-       u32 saveDSPAPOS;
-       u32 saveDSPABASE;
-       u32 saveDSPASURF;
-       u32 saveDSPATILEOFF;
-       u32 savePFIT_PGM_RATIOS;
-       u32 saveBLC_PWM_CTL;
-       u32 saveBLC_PWM_CTL2;
-       u32 saveFPB0;
-       u32 saveFPB1;
-       u32 saveDPLL_B;
-       u32 saveDPLL_B_MD;
-       u32 saveHTOTAL_B;
-       u32 saveHBLANK_B;
-       u32 saveHSYNC_B;
-       u32 saveVTOTAL_B;
-       u32 saveVBLANK_B;
-       u32 saveVSYNC_B;
-       u32 saveBCLRPAT_B;
-       u32 savePIPEBSTAT;
-       u32 saveDSPBSTRIDE;
-       u32 saveDSPBSIZE;
-       u32 saveDSPBPOS;
-       u32 saveDSPBBASE;
-       u32 saveDSPBSURF;
-       u32 saveDSPBTILEOFF;
-       u32 saveVCLK_DIVISOR_VGA0;
-       u32 saveVCLK_DIVISOR_VGA1;
-       u32 saveVCLK_POST_DIV;
-       u32 saveVGACNTRL;
-       u32 saveADPA;
-       u32 saveLVDS;
-       u32 saveLVDSPP_ON;
-       u32 saveLVDSPP_OFF;
-       u32 saveDVOA;
-       u32 saveDVOB;
-       u32 saveDVOC;
-       u32 savePP_ON;
-       u32 savePP_OFF;
-       u32 savePP_CONTROL;
-       u32 savePP_CYCLE;
-       u32 savePFIT_CONTROL;
-       u32 save_palette_a[256];
-       u32 save_palette_b[256];
-       u32 saveFBC_CFB_BASE;
-       u32 saveFBC_LL_BASE;
-       u32 saveFBC_CONTROL;
-       u32 saveFBC_CONTROL2;
-       u32 saveIER;
-       u32 saveIIR;
-       u32 saveIMR;
-       u32 saveCACHE_MODE_0;
-       u32 saveD_STATE;
-       u32 saveDSPCLK_GATE_D;
-       u32 saveMI_ARB_STATE;
-       u32 saveSWF0[16];
-       u32 saveSWF1[16];
-       u32 saveSWF2[3];
-       u8 saveMSR;
-       u8 saveSR[8];
-       u8 saveGR[25];
-       u8 saveAR_INDEX;
-       u8 saveAR[21];
-       u8 saveDACMASK;
-       u8 saveDACDATA[256*3]; /* 256 3-byte colors */
-       u8 saveCR[37];
-} drm_i915_private_t;
-
-extern struct drm_ioctl_desc i915_ioctls[];
-extern int i915_max_ioctl;
-
-                               /* i915_dma.c */
-extern void i915_kernel_lost_context(struct drm_device * dev);
-extern int i915_driver_load(struct drm_device *, unsigned long flags);
-extern int i915_driver_unload(struct drm_device *);
-extern void i915_driver_lastclose(struct drm_device * dev);
-extern void i915_driver_preclose(struct drm_device *dev,
-                                struct drm_file *file_priv);
-extern int i915_driver_device_is_agp(struct drm_device * dev);
-extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
-                             unsigned long arg);
-
-/* i915_irq.c */
-extern int i915_irq_emit(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int i915_irq_wait(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-
-extern int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence);
-extern int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
-extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
-extern void i915_driver_irq_preinstall(struct drm_device * dev);
-extern void i915_driver_irq_postinstall(struct drm_device * dev);
-extern void i915_driver_irq_uninstall(struct drm_device * dev);
-extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
-                               struct drm_file *file_priv);
-extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
-                               struct drm_file *file_priv);
-extern int i915_vblank_swap(struct drm_device *dev, void *data,
-                           struct drm_file *file_priv);
-
-/* i915_mem.c */
-extern int i915_mem_alloc(struct drm_device *dev, void *data,
-                         struct drm_file *file_priv);
-extern int i915_mem_free(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int i915_mem_init_heap(struct drm_device *dev, void *data,
-                             struct drm_file *file_priv);
-extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
-                                struct drm_file *file_priv);
-extern void i915_mem_takedown(struct mem_block **heap);
-extern void i915_mem_release(struct drm_device * dev,
-                            struct drm_file *file_priv, struct mem_block *heap);
-
-#define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, (reg))
-#define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
-#define I915_READ16(reg)       DRM_READ16(dev_priv->mmio_map, (reg))
-#define I915_WRITE16(reg,val)  DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
-
-#define I915_VERBOSE 0
-
-#define RING_LOCALS    unsigned int outring, ringmask, outcount; \
-                        volatile char *virt;
-
-#define BEGIN_LP_RING(n) do {                          \
-       if (I915_VERBOSE)                               \
-               DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n));  \
-       if (dev_priv->ring.space < (n)*4)               \
-               i915_wait_ring(dev, (n)*4, __func__);           \
-       outcount = 0;                                   \
-       outring = dev_priv->ring.tail;                  \
-       ringmask = dev_priv->ring.tail_mask;            \
-       virt = dev_priv->ring.virtual_start;            \
-} while (0)
-
-#define OUT_RING(n) do {                                       \
-       if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
-       *(volatile unsigned int *)(virt + outring) = (n);       \
-        outcount++;                                            \
-       outring += 4;                                           \
-       outring &= ringmask;                                    \
-} while (0)
-
-#define ADVANCE_LP_RING() do {                                         \
-       if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
-       dev_priv->ring.tail = outring;                                  \
-       dev_priv->ring.space -= outcount * 4;                           \
-       I915_WRITE(LP_RING + RING_TAIL, outring);                       \
-} while(0)
-
-extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
-
-/* Extended config space */
-#define LBB 0xf4
-
-/* VGA stuff */
-
-#define VGA_ST01_MDA 0x3ba
-#define VGA_ST01_CGA 0x3da
-
-#define VGA_MSR_WRITE 0x3c2
-#define VGA_MSR_READ 0x3cc
-#define   VGA_MSR_MEM_EN (1<<1)
-#define   VGA_MSR_CGA_MODE (1<<0)
-
-#define VGA_SR_INDEX 0x3c4
-#define VGA_SR_DATA 0x3c5
-
-#define VGA_AR_INDEX 0x3c0
-#define   VGA_AR_VID_EN (1<<5)
-#define VGA_AR_DATA_WRITE 0x3c0
-#define VGA_AR_DATA_READ 0x3c1
-
-#define VGA_GR_INDEX 0x3ce
-#define VGA_GR_DATA 0x3cf
-/* GR05 */
-#define   VGA_GR_MEM_READ_MODE_SHIFT 3
-#define     VGA_GR_MEM_READ_MODE_PLANE 1
-/* GR06 */
-#define   VGA_GR_MEM_MODE_MASK 0xc
-#define   VGA_GR_MEM_MODE_SHIFT 2
-#define   VGA_GR_MEM_A0000_AFFFF 0
-#define   VGA_GR_MEM_A0000_BFFFF 1
-#define   VGA_GR_MEM_B0000_B7FFF 2
-#define   VGA_GR_MEM_B0000_BFFFF 3
-
-#define VGA_DACMASK 0x3c6
-#define VGA_DACRX 0x3c7
-#define VGA_DACWX 0x3c8
-#define VGA_DACDATA 0x3c9
-
-#define VGA_CR_INDEX_MDA 0x3b4
-#define VGA_CR_DATA_MDA 0x3b5
-#define VGA_CR_INDEX_CGA 0x3d4
-#define VGA_CR_DATA_CGA 0x3d5
-
-#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
-#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
-#define CMD_REPORT_HEAD                        (7<<23)
-#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
-#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
-
-#define INST_PARSER_CLIENT   0x00000000
-#define INST_OP_FLUSH        0x02000000
-#define INST_FLUSH_MAP_CACHE 0x00000001
-
-#define BB1_START_ADDR_MASK   (~0x7)
-#define BB1_PROTECTED         (1<<0)
-#define BB1_UNPROTECTED       (0<<0)
-#define BB2_END_ADDR_MASK     (~0x7)
-
-/* Framebuffer compression */
-#define FBC_CFB_BASE           0x03200 /* 4k page aligned */
-#define FBC_LL_BASE            0x03204 /* 4k page aligned */
-#define FBC_CONTROL            0x03208
-#define   FBC_CTL_EN           (1<<31)
-#define   FBC_CTL_PERIODIC     (1<<30)
-#define   FBC_CTL_INTERVAL_SHIFT (16)
-#define   FBC_CTL_UNCOMPRESSIBLE (1<<14)
-#define   FBC_CTL_STRIDE_SHIFT (5)
-#define   FBC_CTL_FENCENO      (1<<0)
-#define FBC_COMMAND            0x0320c
-#define   FBC_CMD_COMPRESS     (1<<0)
-#define FBC_STATUS             0x03210
-#define   FBC_STAT_COMPRESSING (1<<31)
-#define   FBC_STAT_COMPRESSED  (1<<30)
-#define   FBC_STAT_MODIFIED    (1<<29)
-#define   FBC_STAT_CURRENT_LINE        (1<<0)
-#define FBC_CONTROL2           0x03214
-#define   FBC_CTL_FENCE_DBL    (0<<4)
-#define   FBC_CTL_IDLE_IMM     (0<<2)
-#define   FBC_CTL_IDLE_FULL    (1<<2)
-#define   FBC_CTL_IDLE_LINE    (2<<2)
-#define   FBC_CTL_IDLE_DEBUG   (3<<2)
-#define   FBC_CTL_CPU_FENCE    (1<<1)
-#define   FBC_CTL_PLANEA       (0<<0)
-#define   FBC_CTL_PLANEB       (1<<0)
-#define FBC_FENCE_OFF          0x0321b
-
-#define FBC_LL_SIZE            (1536)
-#define FBC_LL_PAD             (32)
-
-/* Interrupt bits:
- */
-#define USER_INT_FLAG    (1<<1)
-#define VSYNC_PIPEB_FLAG (1<<5)
-#define VSYNC_PIPEA_FLAG (1<<7)
-#define HWB_OOM_FLAG     (1<<13) /* binner out of memory */
-
-#define I915REG_HWSTAM         0x02098
-#define I915REG_INT_IDENTITY_R 0x020a4
-#define I915REG_INT_MASK_R     0x020a8
-#define I915REG_INT_ENABLE_R   0x020a0
-
-#define I915REG_PIPEASTAT      0x70024
-#define I915REG_PIPEBSTAT      0x71024
-
-#define I915_VBLANK_INTERRUPT_ENABLE   (1UL<<17)
-#define I915_VBLANK_CLEAR              (1UL<<1)
-
-#define SRX_INDEX              0x3c4
-#define SRX_DATA               0x3c5
-#define SR01                   1
-#define SR01_SCREEN_OFF                (1<<5)
-
-#define PPCR                   0x61204
-#define PPCR_ON                        (1<<0)
-
-#define DVOB                   0x61140
-#define DVOB_ON                        (1<<31)
-#define DVOC                   0x61160
-#define DVOC_ON                        (1<<31)
-#define LVDS                   0x61180
-#define LVDS_ON                        (1<<31)
-
-#define ADPA                   0x61100
-#define ADPA_DPMS_MASK         (~(3<<10))
-#define ADPA_DPMS_ON           (0<<10)
-#define ADPA_DPMS_SUSPEND      (1<<10)
-#define ADPA_DPMS_STANDBY      (2<<10)
-#define ADPA_DPMS_OFF          (3<<10)
-
-#define NOPID                   0x2094
-#define LP_RING                        0x2030
-#define HP_RING                        0x2040
-/* The binner has its own ring buffer:
- */
-#define HWB_RING               0x2400
-
-#define RING_TAIL              0x00
-#define TAIL_ADDR              0x001FFFF8
-#define RING_HEAD              0x04
-#define HEAD_WRAP_COUNT                0xFFE00000
-#define HEAD_WRAP_ONE          0x00200000
-#define HEAD_ADDR              0x001FFFFC
-#define RING_START             0x08
-#define START_ADDR             0x0xFFFFF000
-#define RING_LEN               0x0C
-#define RING_NR_PAGES          0x001FF000
-#define RING_REPORT_MASK       0x00000006
-#define RING_REPORT_64K                0x00000002
-#define RING_REPORT_128K       0x00000004
-#define RING_NO_REPORT         0x00000000
-#define RING_VALID_MASK                0x00000001
-#define RING_VALID             0x00000001
-#define RING_INVALID           0x00000000
-
-/* Instruction parser error reg:
- */
-#define IPEIR                  0x2088
-
-/* Scratch pad debug 0 reg:
- */
-#define SCPD0                  0x209c
-
-/* Error status reg:
- */
-#define ESR                    0x20b8
-
-/* Secondary DMA fetch address debug reg:
- */
-#define DMA_FADD_S             0x20d4
-
-/* Memory Interface Arbitration State
- */
-#define MI_ARB_STATE           0x20e4
-
-/* Cache mode 0 reg.
- *  - Manipulating render cache behaviour is central
- *    to the concept of zone rendering, tuning this reg can help avoid
- *    unnecessary render cache reads and even writes (for z/stencil)
- *    at beginning and end of scene.
- *
- * - To change a bit, write to this reg with a mask bit set and the
- * bit of interest either set or cleared.  EG: (BIT<<16) | BIT to set.
- */
-#define Cache_Mode_0           0x2120
-#define CACHE_MODE_0           0x2120
-#define CM0_MASK_SHIFT          16
-#define CM0_IZ_OPT_DISABLE      (1<<6)
-#define CM0_ZR_OPT_DISABLE      (1<<5)
-#define CM0_DEPTH_EVICT_DISABLE (1<<4)
-#define CM0_COLOR_EVICT_DISABLE (1<<3)
-#define CM0_DEPTH_WRITE_DISABLE (1<<1)
-#define CM0_RC_OP_FLUSH_DISABLE (1<<0)
-
-
-/* Graphics flush control.  A CPU write flushes the GWB of all writes.
- * The data is discarded.
- */
-#define GFX_FLSH_CNTL          0x2170
-
-/* Binner control.  Defines the location of the bin pointer list:
- */
-#define BINCTL                 0x2420
-#define BC_MASK                        (1 << 9)
-
-/* Binned scene info.
- */
-#define BINSCENE               0x2428
-#define BS_OP_LOAD             (1 << 8)
-#define BS_MASK                        (1 << 22)
-
-/* Bin command parser debug reg:
- */
-#define BCPD                   0x2480
-
-/* Bin memory control debug reg:
- */
-#define BMCD                   0x2484
-
-/* Bin data cache debug reg:
- */
-#define BDCD                   0x2488
-
-/* Binner pointer cache debug reg:
- */
-#define BPCD                   0x248c
-
-/* Binner scratch pad debug reg:
- */
-#define BINSKPD                        0x24f0
-
-/* HWB scratch pad debug reg:
- */
-#define HWBSKPD                        0x24f4
-
-/* Binner memory pool reg:
- */
-#define BMP_BUFFER             0x2430
-#define BMP_PAGE_SIZE_4K       (0 << 10)
-#define BMP_BUFFER_SIZE_SHIFT  1
-#define BMP_ENABLE             (1 << 0)
-
-/* Get/put memory from the binner memory pool:
- */
-#define BMP_GET                        0x2438
-#define BMP_PUT                        0x2440
-#define BMP_OFFSET_SHIFT       5
-
-/* 3D state packets:
- */
-#define GFX_OP_RASTER_RULES    ((0x3<<29)|(0x7<<24))
-
-#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
-#define SC_UPDATE_SCISSOR       (0x1<<1)
-#define SC_ENABLE_MASK          (0x1<<0)
-#define SC_ENABLE               (0x1<<0)
-
-#define GFX_OP_LOAD_INDIRECT   ((0x3<<29)|(0x1d<<24)|(0x7<<16))
-
-#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
-#define SCI_YMIN_MASK      (0xffff<<16)
-#define SCI_XMIN_MASK      (0xffff<<0)
-#define SCI_YMAX_MASK      (0xffff<<16)
-#define SCI_XMAX_MASK      (0xffff<<0)
-
-#define GFX_OP_SCISSOR_ENABLE   ((0x3<<29)|(0x1c<<24)|(0x10<<19))
-#define GFX_OP_SCISSOR_RECT     ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
-#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
-#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
-#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
-#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
-#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
-
-#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
-
-#define SRC_COPY_BLT_CMD                ((2<<29)|(0x43<<22)|4)
-#define XY_SRC_COPY_BLT_CMD            ((2<<29)|(0x53<<22)|6)
-#define XY_SRC_COPY_BLT_WRITE_ALPHA    (1<<21)
-#define XY_SRC_COPY_BLT_WRITE_RGB      (1<<20)
-#define XY_SRC_COPY_BLT_SRC_TILED      (1<<15)
-#define XY_SRC_COPY_BLT_DST_TILED      (1<<11)
-
-#define MI_BATCH_BUFFER                ((0x30<<23)|1)
-#define MI_BATCH_BUFFER_START  (0x31<<23)
-#define MI_BATCH_BUFFER_END    (0xA<<23)
-#define MI_BATCH_NON_SECURE    (1)
-#define MI_BATCH_NON_SECURE_I965 (1<<8)
-
-#define MI_WAIT_FOR_EVENT       ((0x3<<23))
-#define MI_WAIT_FOR_PLANE_B_FLIP      (1<<6)
-#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
-#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
-
-#define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
-
-#define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
-#define ASYNC_FLIP                (1<<22)
-#define DISPLAY_PLANE_A           (0<<20)
-#define DISPLAY_PLANE_B           (1<<20)
-
-/* Display regs */
-#define DSPACNTR                0x70180
-#define DSPBCNTR                0x71180
-#define DISPPLANE_SEL_PIPE_MASK                 (1<<24)
-
-/* Define the region of interest for the binner:
- */
-#define CMD_OP_BIN_CONTROL      ((0x3<<29)|(0x1d<<24)|(0x84<<16)|4)
-
-#define CMD_OP_DESTBUFFER_INFO  ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
-
-#define CMD_MI_FLUSH         (0x04 << 23)
-#define MI_NO_WRITE_FLUSH    (1 << 2)
-#define MI_READ_FLUSH        (1 << 0)
-#define MI_EXE_FLUSH         (1 << 1)
-#define MI_END_SCENE         (1 << 4) /* flush binner and incr scene count */
-#define MI_SCENE_COUNT       (1 << 3) /* just increment scene count */
-
-#define BREADCRUMB_BITS 31
-#define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
-
-#define READ_BREADCRUMB(dev_priv)  (((volatile u32*)(dev_priv->hw_status_page))[5])
-#define READ_HWSP(dev_priv, reg)  (((volatile u32*)(dev_priv->hw_status_page))[reg])
-
-#define BLC_PWM_CTL            0x61254
-#define BACKLIGHT_MODULATION_FREQ_SHIFT                (17)
-
-#define BLC_PWM_CTL2           0x61250
-/**
- * This is the most significant 15 bits of the number of backlight cycles in a
- * complete cycle of the modulated backlight control.
- *
- * The actual value is this field multiplied by two.
- */
-#define BACKLIGHT_MODULATION_FREQ_MASK         (0x7fff << 17)
-#define BLM_LEGACY_MODE                                (1 << 16)
-/**
- * This is the number of cycles out of the backlight modulation cycle for which
- * the backlight is on.
- *
- * This field must be no greater than the number of cycles in the complete
- * backlight modulation cycle.
- */
-#define BACKLIGHT_DUTY_CYCLE_SHIFT             (0)
-#define BACKLIGHT_DUTY_CYCLE_MASK              (0xffff)
-
-#define I915_GCFGC                     0xf0
-#define I915_LOW_FREQUENCY_ENABLE              (1 << 7)
-#define I915_DISPLAY_CLOCK_190_200_MHZ         (0 << 4)
-#define I915_DISPLAY_CLOCK_333_MHZ             (4 << 4)
-#define I915_DISPLAY_CLOCK_MASK                        (7 << 4)
-
-#define I855_HPLLCC                    0xc0
-#define I855_CLOCK_CONTROL_MASK                        (3 << 0)
-#define I855_CLOCK_133_200                     (0 << 0)
-#define I855_CLOCK_100_200                     (1 << 0)
-#define I855_CLOCK_100_133                     (2 << 0)
-#define I855_CLOCK_166_250                     (3 << 0)
-
-/* p317, 319
- */
-#define VCLK2_VCO_M        0x6008 /* treat as 16 bit? (includes msbs) */
-#define VCLK2_VCO_N        0x600a
-#define VCLK2_VCO_DIV_SEL  0x6012
-
-#define VCLK_DIVISOR_VGA0   0x6000
-#define VCLK_DIVISOR_VGA1   0x6004
-#define VCLK_POST_DIV      0x6010
-/** Selects a post divisor of 4 instead of 2. */
-# define VGA1_PD_P2_DIV_4      (1 << 15)
-/** Overrides the p2 post divisor field */
-# define VGA1_PD_P1_DIV_2      (1 << 13)
-# define VGA1_PD_P1_SHIFT      8
-/** P1 value is 2 greater than this field */
-# define VGA1_PD_P1_MASK       (0x1f << 8)
-/** Selects a post divisor of 4 instead of 2. */
-# define VGA0_PD_P2_DIV_4      (1 << 7)
-/** Overrides the p2 post divisor field */
-# define VGA0_PD_P1_DIV_2      (1 << 5)
-# define VGA0_PD_P1_SHIFT      0
-/** P1 value is 2 greater than this field */
-# define VGA0_PD_P1_MASK       (0x1f << 0)
-
-/* PCI D state control register */
-#define D_STATE                0x6104
-#define DSPCLK_GATE_D  0x6200
-
-/* I830 CRTC registers */
-#define HTOTAL_A       0x60000
-#define HBLANK_A       0x60004
-#define HSYNC_A                0x60008
-#define VTOTAL_A       0x6000c
-#define VBLANK_A       0x60010
-#define VSYNC_A                0x60014
-#define PIPEASRC       0x6001c
-#define BCLRPAT_A      0x60020
-#define VSYNCSHIFT_A   0x60028
-
-#define HTOTAL_B       0x61000
-#define HBLANK_B       0x61004
-#define HSYNC_B                0x61008
-#define VTOTAL_B       0x6100c
-#define VBLANK_B       0x61010
-#define VSYNC_B                0x61014
-#define PIPEBSRC       0x6101c
-#define BCLRPAT_B      0x61020
-#define VSYNCSHIFT_B   0x61028
-
-#define PP_STATUS      0x61200
-# define PP_ON                                 (1 << 31)
-/**
- * Indicates that all dependencies of the panel are on:
- *
- * - PLL enabled
- * - pipe enabled
- * - LVDS/DVOB/DVOC on
- */
-# define PP_READY                              (1 << 30)
-# define PP_SEQUENCE_NONE                      (0 << 28)
-# define PP_SEQUENCE_ON                                (1 << 28)
-# define PP_SEQUENCE_OFF                       (2 << 28)
-# define PP_SEQUENCE_MASK                      0x30000000
-#define PP_CONTROL     0x61204
-# define POWER_TARGET_ON                       (1 << 0)
-
-#define LVDSPP_ON       0x61208
-#define LVDSPP_OFF      0x6120c
-#define PP_CYCLE        0x61210
-
-#define PFIT_CONTROL   0x61230
-# define PFIT_ENABLE                           (1 << 31)
-# define PFIT_PIPE_MASK                                (3 << 29)
-# define PFIT_PIPE_SHIFT                       29
-# define VERT_INTERP_DISABLE                   (0 << 10)
-# define VERT_INTERP_BILINEAR                  (1 << 10)
-# define VERT_INTERP_MASK                      (3 << 10)
-# define VERT_AUTO_SCALE                       (1 << 9)
-# define HORIZ_INTERP_DISABLE                  (0 << 6)
-# define HORIZ_INTERP_BILINEAR                 (1 << 6)
-# define HORIZ_INTERP_MASK                     (3 << 6)
-# define HORIZ_AUTO_SCALE                      (1 << 5)
-# define PANEL_8TO6_DITHER_ENABLE              (1 << 3)
-
-#define PFIT_PGM_RATIOS        0x61234
-# define PFIT_VERT_SCALE_MASK                  0xfff00000
-# define PFIT_HORIZ_SCALE_MASK                 0x0000fff0
-
-#define PFIT_AUTO_RATIOS       0x61238
-
-
-#define DPLL_A         0x06014
-#define DPLL_B         0x06018
-# define DPLL_VCO_ENABLE                       (1 << 31)
-# define DPLL_DVO_HIGH_SPEED                   (1 << 30)
-# define DPLL_SYNCLOCK_ENABLE                  (1 << 29)
-# define DPLL_VGA_MODE_DIS                     (1 << 28)
-# define DPLLB_MODE_DAC_SERIAL                 (1 << 26) /* i915 */
-# define DPLLB_MODE_LVDS                       (2 << 26) /* i915 */
-# define DPLL_MODE_MASK                                (3 << 26)
-# define DPLL_DAC_SERIAL_P2_CLOCK_DIV_10       (0 << 24) /* i915 */
-# define DPLL_DAC_SERIAL_P2_CLOCK_DIV_5                (1 << 24) /* i915 */
-# define DPLLB_LVDS_P2_CLOCK_DIV_14            (0 << 24) /* i915 */
-# define DPLLB_LVDS_P2_CLOCK_DIV_7             (1 << 24) /* i915 */
-# define DPLL_P2_CLOCK_DIV_MASK                        0x03000000 /* i915 */
-# define DPLL_FPA01_P1_POST_DIV_MASK           0x00ff0000 /* i915 */
-/**
- *  The i830 generation, in DAC/serial mode, defines p1 as two plus this
- * bitfield, or just 2 if PLL_P1_DIVIDE_BY_TWO is set.
- */
-# define DPLL_FPA01_P1_POST_DIV_MASK_I830      0x001f0000
-/**
- * The i830 generation, in LVDS mode, defines P1 as the bit number set within
- * this field (only one bit may be set).
- */
-# define DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS 0x003f0000
-# define DPLL_FPA01_P1_POST_DIV_SHIFT          16
-# define PLL_P2_DIVIDE_BY_4                    (1 << 23) /* i830, required in DVO non-gang */
-# define PLL_P1_DIVIDE_BY_TWO                  (1 << 21) /* i830 */
-# define PLL_REF_INPUT_DREFCLK                 (0 << 13)
-# define PLL_REF_INPUT_TVCLKINA                        (1 << 13) /* i830 */
-# define PLL_REF_INPUT_TVCLKINBC               (2 << 13) /* SDVO TVCLKIN */
-# define PLLB_REF_INPUT_SPREADSPECTRUMIN       (3 << 13)
-# define PLL_REF_INPUT_MASK                    (3 << 13)
-# define PLL_LOAD_PULSE_PHASE_SHIFT            9
-/*
- * Parallel to Serial Load Pulse phase selection.
- * Selects the phase for the 10X DPLL clock for the PCIe
- * digital display port. The range is 4 to 13; 10 or more
- * is just a flip delay. The default is 6
- */
-# define PLL_LOAD_PULSE_PHASE_MASK             (0xf << PLL_LOAD_PULSE_PHASE_SHIFT)
-# define DISPLAY_RATE_SELECT_FPA1              (1 << 8)
-
-/**
- * SDVO multiplier for 945G/GM. Not used on 965.
- *
- * \sa DPLL_MD_UDI_MULTIPLIER_MASK
- */
-# define SDVO_MULTIPLIER_MASK                  0x000000ff
-# define SDVO_MULTIPLIER_SHIFT_HIRES           4
-# define SDVO_MULTIPLIER_SHIFT_VGA             0
-
-/** @defgroup DPLL_MD
- * @{
- */
-/** Pipe A SDVO/UDI clock multiplier/divider register for G965. */
-#define DPLL_A_MD              0x0601c
-/** Pipe B SDVO/UDI clock multiplier/divider register for G965. */
-#define DPLL_B_MD              0x06020
-/**
- * UDI pixel divider, controlling how many pixels are stuffed into a packet.
- *
- * Value is pixels minus 1.  Must be set to 1 pixel for SDVO.
- */
-# define DPLL_MD_UDI_DIVIDER_MASK              0x3f000000
-# define DPLL_MD_UDI_DIVIDER_SHIFT             24
-/** UDI pixel divider for VGA, same as DPLL_MD_UDI_DIVIDER_MASK. */
-# define DPLL_MD_VGA_UDI_DIVIDER_MASK          0x003f0000
-# define DPLL_MD_VGA_UDI_DIVIDER_SHIFT         16
-/**
- * SDVO/UDI pixel multiplier.
- *
- * SDVO requires that the bus clock rate be between 1 and 2 Ghz, and the bus
- * clock rate is 10 times the DPLL clock.  At low resolution/refresh rate
- * modes, the bus rate would be below the limits, so SDVO allows for stuffing
- * dummy bytes in the datastream at an increased clock rate, with both sides of
- * the link knowing how many bytes are fill.
- *
- * So, for a mode with a dotclock of 65Mhz, we would want to double the clock
- * rate to 130Mhz to get a bus rate of 1.30Ghz.  The DPLL clock rate would be
- * set to 130Mhz, and the SDVO multiplier set to 2x in this register and
- * through an SDVO command.
- *
- * This register field has values of multiplication factor minus 1, with
- * a maximum multiplier of 5 for SDVO.
- */
-# define DPLL_MD_UDI_MULTIPLIER_MASK           0x00003f00
-# define DPLL_MD_UDI_MULTIPLIER_SHIFT          8
-/** SDVO/UDI pixel multiplier for VGA, same as DPLL_MD_UDI_MULTIPLIER_MASK.
- * This best be set to the default value (3) or the CRT won't work. No,
- * I don't entirely understand what this does...
- */
-# define DPLL_MD_VGA_UDI_MULTIPLIER_MASK       0x0000003f
-# define DPLL_MD_VGA_UDI_MULTIPLIER_SHIFT      0
-/** @} */
-
-#define DPLL_TEST              0x606c
-# define DPLLB_TEST_SDVO_DIV_1                 (0 << 22)
-# define DPLLB_TEST_SDVO_DIV_2                 (1 << 22)
-# define DPLLB_TEST_SDVO_DIV_4                 (2 << 22)
-# define DPLLB_TEST_SDVO_DIV_MASK              (3 << 22)
-# define DPLLB_TEST_N_BYPASS                   (1 << 19)
-# define DPLLB_TEST_M_BYPASS                   (1 << 18)
-# define DPLLB_INPUT_BUFFER_ENABLE             (1 << 16)
-# define DPLLA_TEST_N_BYPASS                   (1 << 3)
-# define DPLLA_TEST_M_BYPASS                   (1 << 2)
-# define DPLLA_INPUT_BUFFER_ENABLE             (1 << 0)
-
-#define ADPA                   0x61100
-#define ADPA_DAC_ENABLE                (1<<31)
-#define ADPA_DAC_DISABLE       0
-#define ADPA_PIPE_SELECT_MASK  (1<<30)
-#define ADPA_PIPE_A_SELECT     0
-#define ADPA_PIPE_B_SELECT     (1<<30)
-#define ADPA_USE_VGA_HVPOLARITY (1<<15)
-#define ADPA_SETS_HVPOLARITY   0
-#define ADPA_VSYNC_CNTL_DISABLE (1<<11)
-#define ADPA_VSYNC_CNTL_ENABLE 0
-#define ADPA_HSYNC_CNTL_DISABLE (1<<10)
-#define ADPA_HSYNC_CNTL_ENABLE 0
-#define ADPA_VSYNC_ACTIVE_HIGH (1<<4)
-#define ADPA_VSYNC_ACTIVE_LOW  0
-#define ADPA_HSYNC_ACTIVE_HIGH (1<<3)
-#define ADPA_HSYNC_ACTIVE_LOW  0
-
-#define FPA0           0x06040
-#define FPA1           0x06044
-#define FPB0           0x06048
-#define FPB1           0x0604c
-# define FP_N_DIV_MASK                         0x003f0000
-# define FP_N_DIV_SHIFT                                16
-# define FP_M1_DIV_MASK                                0x00003f00
-# define FP_M1_DIV_SHIFT                       8
-# define FP_M2_DIV_MASK                                0x0000003f
-# define FP_M2_DIV_SHIFT                       0
-
-
-#define PORT_HOTPLUG_EN                0x61110
-# define SDVOB_HOTPLUG_INT_EN                  (1 << 26)
-# define SDVOC_HOTPLUG_INT_EN                  (1 << 25)
-# define TV_HOTPLUG_INT_EN                     (1 << 18)
-# define CRT_HOTPLUG_INT_EN                    (1 << 9)
-# define CRT_HOTPLUG_FORCE_DETECT              (1 << 3)
-
-#define PORT_HOTPLUG_STAT      0x61114
-# define CRT_HOTPLUG_INT_STATUS                        (1 << 11)
-# define TV_HOTPLUG_INT_STATUS                 (1 << 10)
-# define CRT_HOTPLUG_MONITOR_MASK              (3 << 8)
-# define CRT_HOTPLUG_MONITOR_COLOR             (3 << 8)
-# define CRT_HOTPLUG_MONITOR_MONO              (2 << 8)
-# define CRT_HOTPLUG_MONITOR_NONE              (0 << 8)
-# define SDVOC_HOTPLUG_INT_STATUS              (1 << 7)
-# define SDVOB_HOTPLUG_INT_STATUS              (1 << 6)
-
-#define SDVOB                  0x61140
-#define SDVOC                  0x61160
-#define SDVO_ENABLE                            (1 << 31)
-#define SDVO_PIPE_B_SELECT                     (1 << 30)
-#define SDVO_STALL_SELECT                      (1 << 29)
-#define SDVO_INTERRUPT_ENABLE                  (1 << 26)
-/**
- * 915G/GM SDVO pixel multiplier.
- *
- * Programmed value is multiplier - 1, up to 5x.
- *
- * \sa DPLL_MD_UDI_MULTIPLIER_MASK
- */
-#define SDVO_PORT_MULTIPLY_MASK                        (7 << 23)
-#define SDVO_PORT_MULTIPLY_SHIFT               23
-#define SDVO_PHASE_SELECT_MASK                 (15 << 19)
-#define SDVO_PHASE_SELECT_DEFAULT              (6 << 19)
-#define SDVO_CLOCK_OUTPUT_INVERT               (1 << 18)
-#define SDVOC_GANG_MODE                                (1 << 16)
-#define SDVO_BORDER_ENABLE                     (1 << 7)
-#define SDVOB_PCIE_CONCURRENCY                 (1 << 3)
-#define SDVO_DETECTED                          (1 << 2)
-/* Bits to be preserved when writing */
-#define SDVOB_PRESERVE_MASK                    ((1 << 17) | (1 << 16) | (1 << 14))
-#define SDVOC_PRESERVE_MASK                    (1 << 17)
-
-/** @defgroup LVDS
- * @{
- */
-/**
- * This register controls the LVDS output enable, pipe selection, and data
- * format selection.
- *
- * All of the clock/data pairs are force powered down by power sequencing.
- */
-#define LVDS                   0x61180
-/**
- * Enables the LVDS port.  This bit must be set before DPLLs are enabled, as
- * the DPLL semantics change when the LVDS is assigned to that pipe.
- */
-# define LVDS_PORT_EN                  (1 << 31)
-/** Selects pipe B for LVDS data.  Must be set on pre-965. */
-# define LVDS_PIPEB_SELECT             (1 << 30)
-
-/**
- * Enables the A0-A2 data pairs and CLKA, containing 18 bits of color data per
- * pixel.
- */
-# define LVDS_A0A2_CLKA_POWER_MASK     (3 << 8)
-# define LVDS_A0A2_CLKA_POWER_DOWN     (0 << 8)
-# define LVDS_A0A2_CLKA_POWER_UP       (3 << 8)
-/**
- * Controls the A3 data pair, which contains the additional LSBs for 24 bit
- * mode.  Only enabled if LVDS_A0A2_CLKA_POWER_UP also indicates it should be
- * on.
- */
-# define LVDS_A3_POWER_MASK            (3 << 6)
-# define LVDS_A3_POWER_DOWN            (0 << 6)
-# define LVDS_A3_POWER_UP              (3 << 6)
-/**
- * Controls the CLKB pair.  This should only be set when LVDS_B0B3_POWER_UP
- * is set.
- */
-# define LVDS_CLKB_POWER_MASK          (3 << 4)
-# define LVDS_CLKB_POWER_DOWN          (0 << 4)
-# define LVDS_CLKB_POWER_UP            (3 << 4)
-
-/**
- * Controls the B0-B3 data pairs.  This must be set to match the DPLL p2
- * setting for whether we are in dual-channel mode.  The B3 pair will
- * additionally only be powered up when LVDS_A3_POWER_UP is set.
- */
-# define LVDS_B0B3_POWER_MASK          (3 << 2)
-# define LVDS_B0B3_POWER_DOWN          (0 << 2)
-# define LVDS_B0B3_POWER_UP            (3 << 2)
-
-#define PIPEACONF 0x70008
-#define PIPEACONF_ENABLE       (1<<31)
-#define PIPEACONF_DISABLE      0
-#define PIPEACONF_DOUBLE_WIDE  (1<<30)
-#define I965_PIPECONF_ACTIVE   (1<<30)
-#define PIPEACONF_SINGLE_WIDE  0
-#define PIPEACONF_PIPE_UNLOCKED 0
-#define PIPEACONF_PIPE_LOCKED  (1<<25)
-#define PIPEACONF_PALETTE      0
-#define PIPEACONF_GAMMA                (1<<24)
-#define PIPECONF_FORCE_BORDER  (1<<25)
-#define PIPECONF_PROGRESSIVE   (0 << 21)
-#define PIPECONF_INTERLACE_W_FIELD_INDICATION  (6 << 21)
-#define PIPECONF_INTERLACE_FIELD_0_ONLY                (7 << 21)
-
-#define DSPARB   0x70030
-#define DSPARB_CSTART_MASK     (0x7f << 7)
-#define DSPARB_CSTART_SHIFT    7
-#define DSPARB_BSTART_MASK     (0x7f)           
-#define DSPARB_BSTART_SHIFT    0
-
-#define PIPEBCONF 0x71008
-#define PIPEBCONF_ENABLE       (1<<31)
-#define PIPEBCONF_DISABLE      0
-#define PIPEBCONF_DOUBLE_WIDE  (1<<30)
-#define PIPEBCONF_DISABLE      0
-#define PIPEBCONF_GAMMA                (1<<24)
-#define PIPEBCONF_PALETTE      0
-
-#define PIPEBGCMAXRED          0x71010
-#define PIPEBGCMAXGREEN                0x71014
-#define PIPEBGCMAXBLUE         0x71018
-#define PIPEBSTAT              0x71024
-#define PIPEBFRAMEHIGH         0x71040
-#define PIPEBFRAMEPIXEL                0x71044
-
-#define DSPACNTR               0x70180
-#define DSPBCNTR               0x71180
-#define DISPLAY_PLANE_ENABLE                   (1<<31)
-#define DISPLAY_PLANE_DISABLE                  0
-#define DISPPLANE_GAMMA_ENABLE                 (1<<30)
-#define DISPPLANE_GAMMA_DISABLE                        0
-#define DISPPLANE_PIXFORMAT_MASK               (0xf<<26)
-#define DISPPLANE_8BPP                         (0x2<<26)
-#define DISPPLANE_15_16BPP                     (0x4<<26)
-#define DISPPLANE_16BPP                                (0x5<<26)
-#define DISPPLANE_32BPP_NO_ALPHA               (0x6<<26)
-#define DISPPLANE_32BPP                                (0x7<<26)
-#define DISPPLANE_STEREO_ENABLE                        (1<<25)
-#define DISPPLANE_STEREO_DISABLE               0
-#define DISPPLANE_SEL_PIPE_MASK                        (1<<24)
-#define DISPPLANE_SEL_PIPE_A                   0
-#define DISPPLANE_SEL_PIPE_B                   (1<<24)
-#define DISPPLANE_SRC_KEY_ENABLE               (1<<22)
-#define DISPPLANE_SRC_KEY_DISABLE              0
-#define DISPPLANE_LINE_DOUBLE                  (1<<20)
-#define DISPPLANE_NO_LINE_DOUBLE               0
-#define DISPPLANE_STEREO_POLARITY_FIRST                0
-#define DISPPLANE_STEREO_POLARITY_SECOND       (1<<18)
-/* plane B only */
-#define DISPPLANE_ALPHA_TRANS_ENABLE           (1<<15)
-#define DISPPLANE_ALPHA_TRANS_DISABLE          0
-#define DISPPLANE_SPRITE_ABOVE_DISPLAYA                0
-#define DISPPLANE_SPRITE_ABOVE_OVERLAY         (1)
-
-#define DSPABASE               0x70184
-#define DSPASTRIDE             0x70188
-
-#define DSPBBASE               0x71184
-#define DSPBADDR               DSPBBASE
-#define DSPBSTRIDE             0x71188
-
-#define DSPAKEYVAL             0x70194
-#define DSPAKEYMASK            0x70198
-
-#define DSPAPOS                        0x7018C /* reserved */
-#define DSPASIZE               0x70190
-#define DSPBPOS                        0x7118C
-#define DSPBSIZE               0x71190
-
-#define DSPASURF               0x7019C
-#define DSPATILEOFF            0x701A4
-
-#define DSPBSURF               0x7119C
-#define DSPBTILEOFF            0x711A4
-
-#define VGACNTRL               0x71400
-# define VGA_DISP_DISABLE                      (1 << 31)
-# define VGA_2X_MODE                           (1 << 30)
-# define VGA_PIPE_B_SELECT                     (1 << 29)
-
-/*
- * Some BIOS scratch area registers.  The 845 (and 830?) store the amount
- * of video memory available to the BIOS in SWF1.
- */
-
-#define SWF0                   0x71410
-
-/*
- * 855 scratch registers.
- */
-#define SWF10                  0x70410
-
-#define SWF30                  0x72414
-
-/*
- * Overlay registers.  These are overlay registers accessed via MMIO.
- * Those loaded via the overlay register page are defined in i830_video.c.
- */
-#define OVADD                  0x30000
-
-#define DOVSTA                 0x30008
-#define OC_BUF                 (0x3<<20)
-
-#define OGAMC5                 0x30010
-#define OGAMC4                 0x30014
-#define OGAMC3                 0x30018
-#define OGAMC2                 0x3001c
-#define OGAMC1                 0x30020
-#define OGAMC0                 0x30024
-/*
- * Palette registers
- */
-#define PALETTE_A              0x0a000
-#define PALETTE_B              0x0a800
-
-#define IS_I830(dev) ((dev)->pci_device == 0x3577)
-#define IS_845G(dev) ((dev)->pci_device == 0x2562)
-#define IS_I85X(dev) ((dev)->pci_device == 0x3582)
-#define IS_I855(dev) ((dev)->pci_device == 0x3582)
-#define IS_I865G(dev) ((dev)->pci_device == 0x2572)
-
-#define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
-#define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
-#define IS_I945G(dev) ((dev)->pci_device == 0x2772)
-#define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
-                       (dev)->pci_device == 0x27AE)
-#define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
-                      (dev)->pci_device == 0x2982 || \
-                      (dev)->pci_device == 0x2992 || \
-                      (dev)->pci_device == 0x29A2 || \
-                      (dev)->pci_device == 0x2A02 || \
-                      (dev)->pci_device == 0x2A12 || \
-                      (dev)->pci_device == 0x2A42 || \
-                      (dev)->pci_device == 0x2E02 || \
-                      (dev)->pci_device == 0x2E12 || \
-                      (dev)->pci_device == 0x2E22)
-
-#define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
-
-#define IS_IGD_GM(dev) ((dev)->pci_device == 0x2A42)
-
-#define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
-                    (dev)->pci_device == 0x2E12 || \
-                    (dev)->pci_device == 0x2E22)
-
-#define IS_G33(dev)    ((dev)->pci_device == 0x29C2 || \
-                       (dev)->pci_device == 0x29B2 ||  \
-                       (dev)->pci_device == 0x29D2)
-
-#define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
-                     IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
-
-#define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
-                       IS_I945GM(dev) || IS_I965GM(dev) || IS_IGD_GM(dev))
-
-#define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_IGD_GM(dev) || IS_G4X(dev))
-
-#define PRIMARY_RINGBUFFER_SIZE         (128*1024)
-
-#endif
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c
deleted file mode 100644 (file)
index 1fe68a2..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- * \file i915_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the i915 DRM.
- *
- * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
- *
- *
- * Copyright (C) Paul Mackerras 2005
- * Copyright (C) Alan Hourihane 2005
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-
-typedef struct _drm_i915_batchbuffer32 {
-       int start;              /* agp offset */
-       int used;               /* nr bytes in use */
-       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
-       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
-       int num_cliprects;      /* mulitpass with multiple cliprects? */
-       u32 cliprects;          /* pointer to userspace cliprects */
-} drm_i915_batchbuffer32_t;
-
-static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
-                                  unsigned long arg)
-{
-       drm_i915_batchbuffer32_t batchbuffer32;
-       drm_i915_batchbuffer_t __user *batchbuffer;
-
-       if (copy_from_user
-           (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
-               return -EFAULT;
-
-       batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
-       if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
-           || __put_user(batchbuffer32.start, &batchbuffer->start)
-           || __put_user(batchbuffer32.used, &batchbuffer->used)
-           || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
-           || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
-           || __put_user(batchbuffer32.num_cliprects,
-                         &batchbuffer->num_cliprects)
-           || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
-                         &batchbuffer->cliprects))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_I915_BATCHBUFFER,
-                        (unsigned long)batchbuffer);
-}
-
-typedef struct _drm_i915_cmdbuffer32 {
-       u32 buf;                /* pointer to userspace command buffer */
-       int sz;                 /* nr bytes in buf */
-       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
-       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
-       int num_cliprects;      /* mulitpass with multiple cliprects? */
-       u32 cliprects;          /* pointer to userspace cliprects */
-} drm_i915_cmdbuffer32_t;
-
-static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
-                                unsigned long arg)
-{
-       drm_i915_cmdbuffer32_t cmdbuffer32;
-       drm_i915_cmdbuffer_t __user *cmdbuffer;
-
-       if (copy_from_user
-           (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
-               return -EFAULT;
-
-       cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
-       if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
-           || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
-                         &cmdbuffer->buf)
-           || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
-           || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
-           || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
-           || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
-           || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
-                         &cmdbuffer->cliprects))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
-}
-
-typedef struct drm_i915_irq_emit32 {
-       u32 irq_seq;
-} drm_i915_irq_emit32_t;
-
-static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_i915_irq_emit32_t req32;
-       drm_i915_irq_emit_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user((int __user *)(unsigned long)req32.irq_seq,
-                         &request->irq_seq))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
-}
-typedef struct drm_i915_getparam32 {
-       int param;
-       u32 value;
-} drm_i915_getparam32_t;
-
-static int compat_i915_getparam(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_i915_getparam32_t req32;
-       drm_i915_getparam_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.param, &request->param)
-           || __put_user((void __user *)(unsigned long)req32.value,
-                         &request->value))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
-}
-
-typedef struct drm_i915_mem_alloc32 {
-       int region;
-       int alignment;
-       int size;
-       u32 region_offset;      /* offset from start of fb or agp */
-} drm_i915_mem_alloc32_t;
-
-static int compat_i915_alloc(struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       drm_i915_mem_alloc32_t req32;
-       drm_i915_mem_alloc_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.region, &request->region)
-           || __put_user(req32.alignment, &request->alignment)
-           || __put_user(req32.size, &request->size)
-           || __put_user((void __user *)(unsigned long)req32.region_offset,
-                         &request->region_offset))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_I915_ALLOC, (unsigned long)request);
-}
-
-drm_ioctl_compat_t *i915_compat_ioctls[] = {
-       [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
-       [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
-       [DRM_I915_GETPARAM] = compat_i915_getparam,
-       [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
-       [DRM_I915_ALLOC] = compat_i915_alloc
-};
-
-/**
- * Called whenever a 32-bit process running under a 64-bit kernel
- * performs an ioctl on /dev/dri/card<n>.
- *
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- */
-long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       drm_ioctl_compat_t *fn = NULL;
-       int ret;
-
-       if (nr < DRM_COMMAND_BASE)
-               return drm_compat_ioctl(filp, cmd, arg);
-
-       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
-               fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
-
-       lock_kernel();          /* XXX for now */
-       if (fn != NULL)
-               ret = (*fn) (filp, cmd, arg);
-       else
-               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
-       unlock_kernel();
-
-       return ret;
-}
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
deleted file mode 100644 (file)
index df03611..0000000
+++ /dev/null
@@ -1,623 +0,0 @@
-/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
- */
-/*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-#include "i915_drv.h"
-
-#define USER_INT_FLAG (1<<1)
-#define VSYNC_PIPEB_FLAG (1<<5)
-#define VSYNC_PIPEA_FLAG (1<<7)
-
-#define MAX_NOPID ((u32)~0)
-
-/**
- * Emit blits for scheduled buffer swaps.
- *
- * This function will be called with the HW lock held.
- */
-static void i915_vblank_tasklet(struct drm_device *dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       unsigned long irqflags;
-       struct list_head *list, *tmp, hits, *hit;
-       int nhits, nrects, slice[2], upper[2], lower[2], i;
-       unsigned counter[2] = { atomic_read(&dev->vbl_received),
-                               atomic_read(&dev->vbl_received2) };
-       struct drm_drawable_info *drw;
-       drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       u32 cpp = dev_priv->cpp;
-       u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
-                               XY_SRC_COPY_BLT_WRITE_ALPHA |
-                               XY_SRC_COPY_BLT_WRITE_RGB)
-                            : XY_SRC_COPY_BLT_CMD;
-       u32 src_pitch = sarea_priv->pitch * cpp;
-       u32 dst_pitch = sarea_priv->pitch * cpp;
-       u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24);
-       RING_LOCALS;
-
-       if (IS_I965G(dev) && sarea_priv->front_tiled) {
-               cmd |= XY_SRC_COPY_BLT_DST_TILED;
-               dst_pitch >>= 2;
-       }
-       if (IS_I965G(dev) && sarea_priv->back_tiled) {
-               cmd |= XY_SRC_COPY_BLT_SRC_TILED;
-               src_pitch >>= 2;
-       }
-
-       DRM_DEBUG("\n");
-
-       INIT_LIST_HEAD(&hits);
-
-       nhits = nrects = 0;
-
-       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
-
-       /* Find buffer swaps scheduled for this vertical blank */
-       list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
-               drm_i915_vbl_swap_t *vbl_swap =
-                       list_entry(list, drm_i915_vbl_swap_t, head);
-
-               if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23))
-                       continue;
-
-               list_del(list);
-               dev_priv->swaps_pending--;
-
-               spin_unlock(&dev_priv->swaps_lock);
-               spin_lock(&dev->drw_lock);
-
-               drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
-
-               if (!drw) {
-                       spin_unlock(&dev->drw_lock);
-                       drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
-                       spin_lock(&dev_priv->swaps_lock);
-                       continue;
-               }
-
-               list_for_each(hit, &hits) {
-                       drm_i915_vbl_swap_t *swap_cmp =
-                               list_entry(hit, drm_i915_vbl_swap_t, head);
-                       struct drm_drawable_info *drw_cmp =
-                               drm_get_drawable_info(dev, swap_cmp->drw_id);
-
-                       if (drw_cmp &&
-                           drw_cmp->rects[0].y1 > drw->rects[0].y1) {
-                               list_add_tail(list, hit);
-                               break;
-                       }
-               }
-
-               spin_unlock(&dev->drw_lock);
-
-               /* List of hits was empty, or we reached the end of it */
-               if (hit == &hits)
-                       list_add_tail(list, hits.prev);
-
-               nhits++;
-
-               spin_lock(&dev_priv->swaps_lock);
-       }
-
-       if (nhits == 0) {
-               spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
-               return;
-       }
-
-       spin_unlock(&dev_priv->swaps_lock);
-
-       i915_kernel_lost_context(dev);
-
-       if (IS_I965G(dev)) {
-               BEGIN_LP_RING(4);
-
-               OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
-               OUT_RING(0);
-               OUT_RING(((sarea_priv->width - 1) & 0xffff) | ((sarea_priv->height - 1) << 16));
-               OUT_RING(0);
-               ADVANCE_LP_RING();
-       } else {
-               BEGIN_LP_RING(6);
-
-               OUT_RING(GFX_OP_DRAWRECT_INFO);
-               OUT_RING(0);
-               OUT_RING(0);
-               OUT_RING(sarea_priv->width | sarea_priv->height << 16);
-               OUT_RING(sarea_priv->width | sarea_priv->height << 16);
-               OUT_RING(0);
-
-               ADVANCE_LP_RING();
-       }
-
-       sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
-
-       upper[0] = upper[1] = 0;
-       slice[0] = max(sarea_priv->pipeA_h / nhits, 1);
-       slice[1] = max(sarea_priv->pipeB_h / nhits, 1);
-       lower[0] = sarea_priv->pipeA_y + slice[0];
-       lower[1] = sarea_priv->pipeB_y + slice[0];
-
-       spin_lock(&dev->drw_lock);
-
-       /* Emit blits for buffer swaps, partitioning both outputs into as many
-        * slices as there are buffer swaps scheduled in order to avoid tearing
-        * (based on the assumption that a single buffer swap would always
-        * complete before scanout starts).
-        */
-       for (i = 0; i++ < nhits;
-            upper[0] = lower[0], lower[0] += slice[0],
-            upper[1] = lower[1], lower[1] += slice[1]) {
-               if (i == nhits)
-                       lower[0] = lower[1] = sarea_priv->height;
-
-               list_for_each(hit, &hits) {
-                       drm_i915_vbl_swap_t *swap_hit =
-                               list_entry(hit, drm_i915_vbl_swap_t, head);
-                       struct drm_clip_rect *rect;
-                       int num_rects, pipe;
-                       unsigned short top, bottom;
-
-                       drw = drm_get_drawable_info(dev, swap_hit->drw_id);
-
-                       if (!drw)
-                               continue;
-
-                       rect = drw->rects;
-                       pipe = swap_hit->pipe;
-                       top = upper[pipe];
-                       bottom = lower[pipe];
-
-                       for (num_rects = drw->num_rects; num_rects--; rect++) {
-                               int y1 = max(rect->y1, top);
-                               int y2 = min(rect->y2, bottom);
-
-                               if (y1 >= y2)
-                                       continue;
-
-                               BEGIN_LP_RING(8);
-
-                               OUT_RING(cmd);
-                               OUT_RING(ropcpp | dst_pitch);
-                               OUT_RING((y1 << 16) | rect->x1);
-                               OUT_RING((y2 << 16) | rect->x2);
-                               OUT_RING(sarea_priv->front_offset);
-                               OUT_RING((y1 << 16) | rect->x1);
-                               OUT_RING(src_pitch);
-                               OUT_RING(sarea_priv->back_offset);
-
-                               ADVANCE_LP_RING();
-                       }
-               }
-       }
-
-       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-
-       list_for_each_safe(hit, tmp, &hits) {
-               drm_i915_vbl_swap_t *swap_hit =
-                       list_entry(hit, drm_i915_vbl_swap_t, head);
-
-               list_del(hit);
-
-               drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
-       }
-}
-
-irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       u16 temp;
-       u32 pipea_stats, pipeb_stats;
-
-       pipea_stats = I915_READ(I915REG_PIPEASTAT);
-       pipeb_stats = I915_READ(I915REG_PIPEBSTAT);
-
-       temp = I915_READ16(I915REG_INT_IDENTITY_R);
-
-       temp &= (USER_INT_FLAG | VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG);
-
-       DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
-
-       if (temp == 0)
-               return IRQ_NONE;
-
-       I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
-       (void) I915_READ16(I915REG_INT_IDENTITY_R);
-       DRM_READMEMORYBARRIER();
-
-       dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
-
-       if (temp & USER_INT_FLAG)
-               DRM_WAKEUP(&dev_priv->irq_queue);
-
-       if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
-               int vblank_pipe = dev_priv->vblank_pipe;
-
-               if ((vblank_pipe &
-                    (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
-                   == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
-                       if (temp & VSYNC_PIPEA_FLAG)
-                               atomic_inc(&dev->vbl_received);
-                       if (temp & VSYNC_PIPEB_FLAG)
-                               atomic_inc(&dev->vbl_received2);
-               } else if (((temp & VSYNC_PIPEA_FLAG) &&
-                           (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
-                          ((temp & VSYNC_PIPEB_FLAG) &&
-                           (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
-                       atomic_inc(&dev->vbl_received);
-
-               DRM_WAKEUP(&dev->vbl_queue);
-               drm_vbl_send_signals(dev);
-
-               if (dev_priv->swaps_pending > 0)
-                       drm_locked_tasklet(dev, i915_vblank_tasklet);
-               I915_WRITE(I915REG_PIPEASTAT,
-                       pipea_stats|I915_VBLANK_INTERRUPT_ENABLE|
-                       I915_VBLANK_CLEAR);
-               I915_WRITE(I915REG_PIPEBSTAT,
-                       pipeb_stats|I915_VBLANK_INTERRUPT_ENABLE|
-                       I915_VBLANK_CLEAR);
-       }
-
-       return IRQ_HANDLED;
-}
-
-static int i915_emit_irq(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       i915_kernel_lost_context(dev);
-
-       DRM_DEBUG("\n");
-
-       dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
-
-       if (dev_priv->counter > 0x7FFFFFFFUL)
-               dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
-
-       BEGIN_LP_RING(6);
-       OUT_RING(CMD_STORE_DWORD_IDX);
-       OUT_RING(20);
-       OUT_RING(dev_priv->counter);
-       OUT_RING(0);
-       OUT_RING(0);
-       OUT_RING(GFX_OP_USER_INTERRUPT);
-       ADVANCE_LP_RING();
-
-       return dev_priv->counter;
-}
-
-static int i915_wait_irq(struct drm_device * dev, int irq_nr)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       int ret = 0;
-
-       DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
-                 READ_BREADCRUMB(dev_priv));
-
-       if (READ_BREADCRUMB(dev_priv) >= irq_nr)
-               return 0;
-
-       dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
-
-       DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
-                   READ_BREADCRUMB(dev_priv) >= irq_nr);
-
-       if (ret == -EBUSY) {
-               DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
-                         READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
-       }
-
-       dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
-       return ret;
-}
-
-static int i915_driver_vblank_do_wait(struct drm_device *dev, unsigned int *sequence,
-                                     atomic_t *counter)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       unsigned int cur_vblank;
-       int ret = 0;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
-                   (((cur_vblank = atomic_read(counter))
-                       - *sequence) <= (1<<23)));
-
-       *sequence = cur_vblank;
-
-       return ret;
-}
-
-
-int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
-{
-       return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received);
-}
-
-int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
-{
-       return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2);
-}
-
-/* Needs the lock as it touches the ring.
- */
-int i915_irq_emit(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_irq_emit_t *emit = data;
-       int result;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       result = i915_emit_irq(dev);
-
-       if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-/* Doesn't need the hardware lock.
- */
-int i915_irq_wait(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_irq_wait_t *irqwait = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       return i915_wait_irq(dev, irqwait->irq_seq);
-}
-
-static void i915_enable_interrupt (struct drm_device *dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       u16 flag;
-
-       flag = 0;
-       if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
-               flag |= VSYNC_PIPEA_FLAG;
-       if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
-               flag |= VSYNC_PIPEB_FLAG;
-
-       I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
-}
-
-/* Set the vblank monitor pipe
- */
-int i915_vblank_pipe_set(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_vblank_pipe_t *pipe = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
-               DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
-               return -EINVAL;
-       }
-
-       dev_priv->vblank_pipe = pipe->pipe;
-
-       i915_enable_interrupt (dev);
-
-       return 0;
-}
-
-int i915_vblank_pipe_get(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_vblank_pipe_t *pipe = data;
-       u16 flag;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       flag = I915_READ(I915REG_INT_ENABLE_R);
-       pipe->pipe = 0;
-       if (flag & VSYNC_PIPEA_FLAG)
-               pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
-       if (flag & VSYNC_PIPEB_FLAG)
-               pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
-
-       return 0;
-}
-
-/**
- * Schedule buffer swap at given vertical blank.
- */
-int i915_vblank_swap(struct drm_device *dev, void *data,
-                    struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_vblank_swap_t *swap = data;
-       drm_i915_vbl_swap_t *vbl_swap;
-       unsigned int pipe, seqtype, curseq;
-       unsigned long irqflags;
-       struct list_head *list;
-
-       if (!dev_priv) {
-               DRM_ERROR("%s called with no initialization\n", __func__);
-               return -EINVAL;
-       }
-
-       if (dev_priv->sarea_priv->rotation) {
-               DRM_DEBUG("Rotation not supported\n");
-               return -EINVAL;
-       }
-
-       if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
-                            _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) {
-               DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
-               return -EINVAL;
-       }
-
-       pipe = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
-
-       seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
-
-       if (!(dev_priv->vblank_pipe & (1 << pipe))) {
-               DRM_ERROR("Invalid pipe %d\n", pipe);
-               return -EINVAL;
-       }
-
-       spin_lock_irqsave(&dev->drw_lock, irqflags);
-
-       if (!drm_get_drawable_info(dev, swap->drawable)) {
-               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-               DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
-               return -EINVAL;
-       }
-
-       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
-
-       curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
-
-       if (seqtype == _DRM_VBLANK_RELATIVE)
-               swap->sequence += curseq;
-
-       if ((curseq - swap->sequence) <= (1<<23)) {
-               if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
-                       swap->sequence = curseq + 1;
-               } else {
-                       DRM_DEBUG("Missed target sequence\n");
-                       return -EINVAL;
-               }
-       }
-
-       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
-
-       list_for_each(list, &dev_priv->vbl_swaps.head) {
-               vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
-
-               if (vbl_swap->drw_id == swap->drawable &&
-                   vbl_swap->pipe == pipe &&
-                   vbl_swap->sequence == swap->sequence) {
-                       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
-                       DRM_DEBUG("Already scheduled\n");
-                       return 0;
-               }
-       }
-
-       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
-
-       if (dev_priv->swaps_pending >= 100) {
-               DRM_DEBUG("Too many swaps queued\n");
-               return -EBUSY;
-       }
-
-       vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
-
-       if (!vbl_swap) {
-               DRM_ERROR("Failed to allocate memory to queue swap\n");
-               return -ENOMEM;
-       }
-
-       DRM_DEBUG("\n");
-
-       vbl_swap->drw_id = swap->drawable;
-       vbl_swap->pipe = pipe;
-       vbl_swap->sequence = swap->sequence;
-
-       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
-
-       list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
-       dev_priv->swaps_pending++;
-
-       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
-
-       return 0;
-}
-
-/* drm_dma.h hooks
-*/
-void i915_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-
-       I915_WRITE16(I915REG_HWSTAM, 0xfffe);
-       I915_WRITE16(I915REG_INT_MASK_R, 0x0);
-       I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
-}
-
-void i915_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-
-       spin_lock_init(&dev_priv->swaps_lock);
-       INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
-       dev_priv->swaps_pending = 0;
-
-       if (!dev_priv->vblank_pipe)
-               dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
-       i915_enable_interrupt(dev);
-       DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
-}
-
-void i915_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
-       u16 temp;
-
-       if (!dev_priv)
-               return;
-
-       I915_WRITE16(I915REG_HWSTAM, 0xffff);
-       I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
-       I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
-
-       temp = I915_READ16(I915REG_INT_IDENTITY_R);
-       I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
-}
diff --git a/drivers/char/drm/i915_mem.c b/drivers/char/drm/i915_mem.c
deleted file mode 100644 (file)
index 6126a60..0000000
+++ /dev/null
@@ -1,386 +0,0 @@
-/* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*-
- */
-/*
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "i915_drm.h"
-#include "i915_drv.h"
-
-/* This memory manager is integrated into the global/local lru
- * mechanisms used by the clients.  Specifically, it operates by
- * setting the 'in_use' fields of the global LRU to indicate whether
- * this region is privately allocated to a client.
- *
- * This does require the client to actually respect that field.
- *
- * Currently no effort is made to allocate 'private' memory in any
- * clever way - the LRU information isn't used to determine which
- * block to allocate, and the ring is drained prior to allocations --
- * in other words allocation is expensive.
- */
-static void mark_block(struct drm_device * dev, struct mem_block *p, int in_use)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_tex_region *list;
-       unsigned shift, nr;
-       unsigned start;
-       unsigned end;
-       unsigned i;
-       int age;
-
-       shift = dev_priv->tex_lru_log_granularity;
-       nr = I915_NR_TEX_REGIONS;
-
-       start = p->start >> shift;
-       end = (p->start + p->size - 1) >> shift;
-
-       age = ++sarea_priv->texAge;
-       list = sarea_priv->texList;
-
-       /* Mark the regions with the new flag and update their age.  Move
-        * them to head of list to preserve LRU semantics.
-        */
-       for (i = start; i <= end; i++) {
-               list[i].in_use = in_use;
-               list[i].age = age;
-
-               /* remove_from_list(i)
-                */
-               list[(unsigned)list[i].next].prev = list[i].prev;
-               list[(unsigned)list[i].prev].next = list[i].next;
-
-               /* insert_at_head(list, i)
-                */
-               list[i].prev = nr;
-               list[i].next = list[nr].next;
-               list[(unsigned)list[nr].next].prev = i;
-               list[nr].next = i;
-       }
-}
-
-/* Very simple allocator for agp memory, working on a static range
- * already mapped into each client's address space.
- */
-
-static struct mem_block *split_block(struct mem_block *p, int start, int size,
-                                    struct drm_file *file_priv)
-{
-       /* Maybe cut off the start of an existing block */
-       if (start > p->start) {
-               struct mem_block *newblock =
-                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
-               if (!newblock)
-                       goto out;
-               newblock->start = start;
-               newblock->size = p->size - (start - p->start);
-               newblock->file_priv = NULL;
-               newblock->next = p->next;
-               newblock->prev = p;
-               p->next->prev = newblock;
-               p->next = newblock;
-               p->size -= newblock->size;
-               p = newblock;
-       }
-
-       /* Maybe cut off the end of an existing block */
-       if (size < p->size) {
-               struct mem_block *newblock =
-                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
-               if (!newblock)
-                       goto out;
-               newblock->start = start + size;
-               newblock->size = p->size - size;
-               newblock->file_priv = NULL;
-               newblock->next = p->next;
-               newblock->prev = p;
-               p->next->prev = newblock;
-               p->next = newblock;
-               p->size = size;
-       }
-
-      out:
-       /* Our block is in the middle */
-       p->file_priv = file_priv;
-       return p;
-}
-
-static struct mem_block *alloc_block(struct mem_block *heap, int size,
-                                    int align2, struct drm_file *file_priv)
-{
-       struct mem_block *p;
-       int mask = (1 << align2) - 1;
-
-       for (p = heap->next; p != heap; p = p->next) {
-               int start = (p->start + mask) & ~mask;
-               if (p->file_priv == NULL && start + size <= p->start + p->size)
-                       return split_block(p, start, size, file_priv);
-       }
-
-       return NULL;
-}
-
-static struct mem_block *find_block(struct mem_block *heap, int start)
-{
-       struct mem_block *p;
-
-       for (p = heap->next; p != heap; p = p->next)
-               if (p->start == start)
-                       return p;
-
-       return NULL;
-}
-
-static void free_block(struct mem_block *p)
-{
-       p->file_priv = NULL;
-
-       /* Assumes a single contiguous range.  Needs a special file_priv in
-        * 'heap' to stop it being subsumed.
-        */
-       if (p->next->file_priv == NULL) {
-               struct mem_block *q = p->next;
-               p->size += q->size;
-               p->next = q->next;
-               p->next->prev = p;
-               drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
-       }
-
-       if (p->prev->file_priv == NULL) {
-               struct mem_block *q = p->prev;
-               q->size += p->size;
-               q->next = p->next;
-               q->next->prev = q;
-               drm_free(p, sizeof(*q), DRM_MEM_BUFLISTS);
-       }
-}
-
-/* Initialize.  How to check for an uninitialized heap?
- */
-static int init_heap(struct mem_block **heap, int start, int size)
-{
-       struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFLISTS);
-
-       if (!blocks)
-               return -ENOMEM;
-
-       *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFLISTS);
-       if (!*heap) {
-               drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFLISTS);
-               return -ENOMEM;
-       }
-
-       blocks->start = start;
-       blocks->size = size;
-       blocks->file_priv = NULL;
-       blocks->next = blocks->prev = *heap;
-
-       memset(*heap, 0, sizeof(**heap));
-       (*heap)->file_priv = (struct drm_file *) - 1;
-       (*heap)->next = (*heap)->prev = blocks;
-       return 0;
-}
-
-/* Free all blocks associated with the releasing file.
- */
-void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv,
-                     struct mem_block *heap)
-{
-       struct mem_block *p;
-
-       if (!heap || !heap->next)
-               return;
-
-       for (p = heap->next; p != heap; p = p->next) {
-               if (p->file_priv == file_priv) {
-                       p->file_priv = NULL;
-                       mark_block(dev, p, 0);
-               }
-       }
-
-       /* Assumes a single contiguous range.  Needs a special file_priv in
-        * 'heap' to stop it being subsumed.
-        */
-       for (p = heap->next; p != heap; p = p->next) {
-               while (p->file_priv == NULL && p->next->file_priv == NULL) {
-                       struct mem_block *q = p->next;
-                       p->size += q->size;
-                       p->next = q->next;
-                       p->next->prev = p;
-                       drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
-               }
-       }
-}
-
-/* Shutdown.
- */
-void i915_mem_takedown(struct mem_block **heap)
-{
-       struct mem_block *p;
-
-       if (!*heap)
-               return;
-
-       for (p = (*heap)->next; p != *heap;) {
-               struct mem_block *q = p;
-               p = p->next;
-               drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
-       }
-
-       drm_free(*heap, sizeof(**heap), DRM_MEM_BUFLISTS);
-       *heap = NULL;
-}
-
-static struct mem_block **get_heap(drm_i915_private_t * dev_priv, int region)
-{
-       switch (region) {
-       case I915_MEM_REGION_AGP:
-               return &dev_priv->agp_heap;
-       default:
-               return NULL;
-       }
-}
-
-/* IOCTL HANDLERS */
-
-int i915_mem_alloc(struct drm_device *dev, void *data,
-                  struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_mem_alloc_t *alloc = data;
-       struct mem_block *block, **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, alloc->region);
-       if (!heap || !*heap)
-               return -EFAULT;
-
-       /* Make things easier on ourselves: all allocations at least
-        * 4k aligned.
-        */
-       if (alloc->alignment < 12)
-               alloc->alignment = 12;
-
-       block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv);
-
-       if (!block)
-               return -ENOMEM;
-
-       mark_block(dev, block, 1);
-
-       if (DRM_COPY_TO_USER(alloc->region_offset, &block->start,
-                            sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-int i915_mem_free(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_mem_free_t *memfree = data;
-       struct mem_block *block, **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, memfree->region);
-       if (!heap || !*heap)
-               return -EFAULT;
-
-       block = find_block(*heap, memfree->region_offset);
-       if (!block)
-               return -EFAULT;
-
-       if (block->file_priv != file_priv)
-               return -EPERM;
-
-       mark_block(dev, block, 0);
-       free_block(block);
-       return 0;
-}
-
-int i915_mem_init_heap(struct drm_device *dev, void *data,
-                      struct drm_file *file_priv)
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_mem_init_heap_t *initheap = data;
-       struct mem_block **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, initheap->region);
-       if (!heap)
-               return -EFAULT;
-
-       if (*heap) {
-               DRM_ERROR("heap already initialized?");
-               return -EFAULT;
-       }
-
-       return init_heap(heap, initheap->start, initheap->size);
-}
-
-int i915_mem_destroy_heap( struct drm_device *dev, void *data,
-                          struct drm_file *file_priv )
-{
-       drm_i915_private_t *dev_priv = dev->dev_private;
-       drm_i915_mem_destroy_heap_t *destroyheap = data;
-       struct mem_block **heap;
-
-       if ( !dev_priv ) {
-               DRM_ERROR( "called with no initialization\n" );
-               return -EINVAL;
-       }
-
-       heap = get_heap( dev_priv, destroyheap->region );
-       if (!heap) {
-               DRM_ERROR("get_heap failed");
-               return -EFAULT;
-       }
-
-       if (!*heap) {
-               DRM_ERROR("heap not initialized?");
-               return -EFAULT;
-       }
-
-       i915_mem_takedown( heap );
-       return 0;
-}
diff --git a/drivers/char/drm/mga_dma.c b/drivers/char/drm/mga_dma.c
deleted file mode 100644 (file)
index c1d12db..0000000
+++ /dev/null
@@ -1,1162 +0,0 @@
-/* mga_dma.c -- DMA support for mga g200/g400 -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file mga_dma.c
- * DMA support for MGA G200 / G400.
- *
- * \author Rickard E. (Rik) Faith <faith@valinux.com>
- * \author Jeff Hartmann <jhartmann@valinux.com>
- * \author Keith Whitwell <keith@tungstengraphics.com>
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "drm_sarea.h"
-#include "mga_drm.h"
-#include "mga_drv.h"
-
-#define MGA_DEFAULT_USEC_TIMEOUT       10000
-#define MGA_FREELIST_DEBUG             0
-
-#define MINIMAL_CLEANUP 0
-#define FULL_CLEANUP 1
-static int mga_do_cleanup_dma(struct drm_device *dev, int full_cleanup);
-
-/* ================================================================
- * Engine control
- */
-
-int mga_do_wait_for_idle(drm_mga_private_t * dev_priv)
-{
-       u32 status = 0;
-       int i;
-       DRM_DEBUG("\n");
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
-               if (status == MGA_ENDPRDMASTS) {
-                       MGA_WRITE8(MGA_CRTC_INDEX, 0);
-                       return 0;
-               }
-               DRM_UDELAY(1);
-       }
-
-#if MGA_DMA_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x\n", status);
-#endif
-       return -EBUSY;
-}
-
-static int mga_do_dma_reset(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
-
-       DRM_DEBUG("\n");
-
-       /* The primary DMA stream should look like new right about now.
-        */
-       primary->tail = 0;
-       primary->space = primary->size;
-       primary->last_flush = 0;
-
-       sarea_priv->last_wrap = 0;
-
-       /* FIXME: Reset counters, buffer ages etc...
-        */
-
-       /* FIXME: What else do we need to reinitialize?  WARP stuff?
-        */
-
-       return 0;
-}
-
-/* ================================================================
- * Primary DMA stream
- */
-
-void mga_do_dma_flush(drm_mga_private_t * dev_priv)
-{
-       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
-       u32 head, tail;
-       u32 status = 0;
-       int i;
-       DMA_LOCALS;
-       DRM_DEBUG("\n");
-
-       /* We need to wait so that we can do an safe flush */
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
-               if (status == MGA_ENDPRDMASTS)
-                       break;
-               DRM_UDELAY(1);
-       }
-
-       if (primary->tail == primary->last_flush) {
-               DRM_DEBUG("   bailing out...\n");
-               return;
-       }
-
-       tail = primary->tail + dev_priv->primary->offset;
-
-       /* We need to pad the stream between flushes, as the card
-        * actually (partially?) reads the first of these commands.
-        * See page 4-16 in the G400 manual, middle of the page or so.
-        */
-       BEGIN_DMA(1);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-       ADVANCE_DMA();
-
-       primary->last_flush = primary->tail;
-
-       head = MGA_READ(MGA_PRIMADDRESS);
-
-       if (head <= tail) {
-               primary->space = primary->size - primary->tail;
-       } else {
-               primary->space = head - tail;
-       }
-
-       DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
-       DRM_DEBUG("   tail = 0x%06lx\n", tail - dev_priv->primary->offset);
-       DRM_DEBUG("  space = 0x%06x\n", primary->space);
-
-       mga_flush_write_combine();
-       MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
-
-       DRM_DEBUG("done.\n");
-}
-
-void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv)
-{
-       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
-       u32 head, tail;
-       DMA_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_DMA_WRAP();
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-       ADVANCE_DMA();
-
-       tail = primary->tail + dev_priv->primary->offset;
-
-       primary->tail = 0;
-       primary->last_flush = 0;
-       primary->last_wrap++;
-
-       head = MGA_READ(MGA_PRIMADDRESS);
-
-       if (head == dev_priv->primary->offset) {
-               primary->space = primary->size;
-       } else {
-               primary->space = head - dev_priv->primary->offset;
-       }
-
-       DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
-       DRM_DEBUG("   tail = 0x%06x\n", primary->tail);
-       DRM_DEBUG("   wrap = %d\n", primary->last_wrap);
-       DRM_DEBUG("  space = 0x%06x\n", primary->space);
-
-       mga_flush_write_combine();
-       MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
-
-       set_bit(0, &primary->wrapped);
-       DRM_DEBUG("done.\n");
-}
-
-void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv)
-{
-       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       u32 head = dev_priv->primary->offset;
-       DRM_DEBUG("\n");
-
-       sarea_priv->last_wrap++;
-       DRM_DEBUG("   wrap = %d\n", sarea_priv->last_wrap);
-
-       mga_flush_write_combine();
-       MGA_WRITE(MGA_PRIMADDRESS, head | MGA_DMA_GENERAL);
-
-       clear_bit(0, &primary->wrapped);
-       DRM_DEBUG("done.\n");
-}
-
-/* ================================================================
- * Freelist management
- */
-
-#define MGA_BUFFER_USED                ~0
-#define MGA_BUFFER_FREE                0
-
-#if MGA_FREELIST_DEBUG
-static void mga_freelist_print(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_freelist_t *entry;
-
-       DRM_INFO("\n");
-       DRM_INFO("current dispatch: last=0x%x done=0x%x\n",
-                dev_priv->sarea_priv->last_dispatch,
-                (unsigned int)(MGA_READ(MGA_PRIMADDRESS) -
-                               dev_priv->primary->offset));
-       DRM_INFO("current freelist:\n");
-
-       for (entry = dev_priv->head->next; entry; entry = entry->next) {
-               DRM_INFO("   %p   idx=%2d  age=0x%x 0x%06lx\n",
-                        entry, entry->buf->idx, entry->age.head,
-                        entry->age.head - dev_priv->primary->offset);
-       }
-       DRM_INFO("\n");
-}
-#endif
-
-static int mga_freelist_init(struct drm_device * dev, drm_mga_private_t * dev_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_mga_buf_priv_t *buf_priv;
-       drm_mga_freelist_t *entry;
-       int i;
-       DRM_DEBUG("count=%d\n", dma->buf_count);
-
-       dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
-       if (dev_priv->head == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
-       SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
-
-       for (i = 0; i < dma->buf_count; i++) {
-               buf = dma->buflist[i];
-               buf_priv = buf->dev_private;
-
-               entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
-               if (entry == NULL)
-                       return -ENOMEM;
-
-               memset(entry, 0, sizeof(drm_mga_freelist_t));
-
-               entry->next = dev_priv->head->next;
-               entry->prev = dev_priv->head;
-               SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
-               entry->buf = buf;
-
-               if (dev_priv->head->next != NULL)
-                       dev_priv->head->next->prev = entry;
-               if (entry->next == NULL)
-                       dev_priv->tail = entry;
-
-               buf_priv->list_entry = entry;
-               buf_priv->discard = 0;
-               buf_priv->dispatched = 0;
-
-               dev_priv->head->next = entry;
-       }
-
-       return 0;
-}
-
-static void mga_freelist_cleanup(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_freelist_t *entry;
-       drm_mga_freelist_t *next;
-       DRM_DEBUG("\n");
-
-       entry = dev_priv->head;
-       while (entry) {
-               next = entry->next;
-               drm_free(entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
-               entry = next;
-       }
-
-       dev_priv->head = dev_priv->tail = NULL;
-}
-
-#if 0
-/* FIXME: Still needed?
- */
-static void mga_freelist_reset(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_mga_buf_priv_t *buf_priv;
-       int i;
-
-       for (i = 0; i < dma->buf_count; i++) {
-               buf = dma->buflist[i];
-               buf_priv = buf->dev_private;
-               SET_AGE(&buf_priv->list_entry->age, MGA_BUFFER_FREE, 0);
-       }
-}
-#endif
-
-static struct drm_buf *mga_freelist_get(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_freelist_t *next;
-       drm_mga_freelist_t *prev;
-       drm_mga_freelist_t *tail = dev_priv->tail;
-       u32 head, wrap;
-       DRM_DEBUG("\n");
-
-       head = MGA_READ(MGA_PRIMADDRESS);
-       wrap = dev_priv->sarea_priv->last_wrap;
-
-       DRM_DEBUG("   tail=0x%06lx %d\n",
-                 tail->age.head ?
-                 tail->age.head - dev_priv->primary->offset : 0,
-                 tail->age.wrap);
-       DRM_DEBUG("   head=0x%06lx %d\n",
-                 head - dev_priv->primary->offset, wrap);
-
-       if (TEST_AGE(&tail->age, head, wrap)) {
-               prev = dev_priv->tail->prev;
-               next = dev_priv->tail;
-               prev->next = NULL;
-               next->prev = next->next = NULL;
-               dev_priv->tail = prev;
-               SET_AGE(&next->age, MGA_BUFFER_USED, 0);
-               return next->buf;
-       }
-
-       DRM_DEBUG("returning NULL!\n");
-       return NULL;
-}
-
-int mga_freelist_put(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
-       drm_mga_freelist_t *head, *entry, *prev;
-
-       DRM_DEBUG("age=0x%06lx wrap=%d\n",
-                 buf_priv->list_entry->age.head -
-                 dev_priv->primary->offset, buf_priv->list_entry->age.wrap);
-
-       entry = buf_priv->list_entry;
-       head = dev_priv->head;
-
-       if (buf_priv->list_entry->age.head == MGA_BUFFER_USED) {
-               SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
-               prev = dev_priv->tail;
-               prev->next = entry;
-               entry->prev = prev;
-               entry->next = NULL;
-       } else {
-               prev = head->next;
-               head->next = entry;
-               prev->prev = entry;
-               entry->prev = head;
-               entry->next = prev;
-       }
-
-       return 0;
-}
-
-/* ================================================================
- * DMA initialization, cleanup
- */
-
-int mga_driver_load(struct drm_device * dev, unsigned long flags)
-{
-       drm_mga_private_t *dev_priv;
-
-       dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
-       if (!dev_priv)
-               return -ENOMEM;
-
-       dev->dev_private = (void *)dev_priv;
-       memset(dev_priv, 0, sizeof(drm_mga_private_t));
-
-       dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;
-       dev_priv->chipset = flags;
-
-       dev_priv->mmio_base = drm_get_resource_start(dev, 1);
-       dev_priv->mmio_size = drm_get_resource_len(dev, 1);
-
-       dev->counters += 3;
-       dev->types[6] = _DRM_STAT_IRQ;
-       dev->types[7] = _DRM_STAT_PRIMARY;
-       dev->types[8] = _DRM_STAT_SECONDARY;
-
-       return 0;
-}
-
-#if __OS_HAS_AGP
-/**
- * Bootstrap the driver for AGP DMA.
- *
- * \todo
- * Investigate whether there is any benifit to storing the WARP microcode in
- * AGP memory.  If not, the microcode may as well always be put in PCI
- * memory.
- *
- * \todo
- * This routine needs to set dma_bs->agp_mode to the mode actually configured
- * in the hardware.  Looking just at the Linux AGP driver code, I don't see
- * an easy way to determine this.
- *
- * \sa mga_do_dma_bootstrap, mga_do_pci_dma_bootstrap
- */
-static int mga_do_agp_dma_bootstrap(struct drm_device * dev,
-                                   drm_mga_dma_bootstrap_t * dma_bs)
-{
-       drm_mga_private_t *const dev_priv =
-           (drm_mga_private_t *) dev->dev_private;
-       unsigned int warp_size = mga_warp_microcode_size(dev_priv);
-       int err;
-       unsigned offset;
-       const unsigned secondary_size = dma_bs->secondary_bin_count
-           * dma_bs->secondary_bin_size;
-       const unsigned agp_size = (dma_bs->agp_size << 20);
-       struct drm_buf_desc req;
-       struct drm_agp_mode mode;
-       struct drm_agp_info info;
-       struct drm_agp_buffer agp_req;
-       struct drm_agp_binding bind_req;
-
-       /* Acquire AGP. */
-       err = drm_agp_acquire(dev);
-       if (err) {
-               DRM_ERROR("Unable to acquire AGP: %d\n", err);
-               return err;
-       }
-
-       err = drm_agp_info(dev, &info);
-       if (err) {
-               DRM_ERROR("Unable to get AGP info: %d\n", err);
-               return err;
-       }
-
-       mode.mode = (info.mode & ~0x07) | dma_bs->agp_mode;
-       err = drm_agp_enable(dev, mode);
-       if (err) {
-               DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode);
-               return err;
-       }
-
-       /* In addition to the usual AGP mode configuration, the G200 AGP cards
-        * need to have the AGP mode "manually" set.
-        */
-
-       if (dev_priv->chipset == MGA_CARD_TYPE_G200) {
-               if (mode.mode & 0x02) {
-                       MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE);
-               } else {
-                       MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE);
-               }
-       }
-
-       /* Allocate and bind AGP memory. */
-       agp_req.size = agp_size;
-       agp_req.type = 0;
-       err = drm_agp_alloc(dev, &agp_req);
-       if (err) {
-               dev_priv->agp_size = 0;
-               DRM_ERROR("Unable to allocate %uMB AGP memory\n",
-                         dma_bs->agp_size);
-               return err;
-       }
-
-       dev_priv->agp_size = agp_size;
-       dev_priv->agp_handle = agp_req.handle;
-
-       bind_req.handle = agp_req.handle;
-       bind_req.offset = 0;
-       err = drm_agp_bind(dev, &bind_req);
-       if (err) {
-               DRM_ERROR("Unable to bind AGP memory: %d\n", err);
-               return err;
-       }
-
-       /* Make drm_addbufs happy by not trying to create a mapping for less
-        * than a page.
-        */
-       if (warp_size < PAGE_SIZE)
-               warp_size = PAGE_SIZE;
-
-       offset = 0;
-       err = drm_addmap(dev, offset, warp_size,
-                        _DRM_AGP, _DRM_READ_ONLY, &dev_priv->warp);
-       if (err) {
-               DRM_ERROR("Unable to map WARP microcode: %d\n", err);
-               return err;
-       }
-
-       offset += warp_size;
-       err = drm_addmap(dev, offset, dma_bs->primary_size,
-                        _DRM_AGP, _DRM_READ_ONLY, &dev_priv->primary);
-       if (err) {
-               DRM_ERROR("Unable to map primary DMA region: %d\n", err);
-               return err;
-       }
-
-       offset += dma_bs->primary_size;
-       err = drm_addmap(dev, offset, secondary_size,
-                        _DRM_AGP, 0, &dev->agp_buffer_map);
-       if (err) {
-               DRM_ERROR("Unable to map secondary DMA region: %d\n", err);
-               return err;
-       }
-
-       (void)memset(&req, 0, sizeof(req));
-       req.count = dma_bs->secondary_bin_count;
-       req.size = dma_bs->secondary_bin_size;
-       req.flags = _DRM_AGP_BUFFER;
-       req.agp_start = offset;
-
-       err = drm_addbufs_agp(dev, &req);
-       if (err) {
-               DRM_ERROR("Unable to add secondary DMA buffers: %d\n", err);
-               return err;
-       }
-
-       {
-               struct drm_map_list *_entry;
-               unsigned long agp_token = 0;
-
-               list_for_each_entry(_entry, &dev->maplist, head) {
-                       if (_entry->map == dev->agp_buffer_map)
-                               agp_token = _entry->user_token;
-               }
-               if (!agp_token)
-                       return -EFAULT;
-
-               dev->agp_buffer_token = agp_token;
-       }
-
-       offset += secondary_size;
-       err = drm_addmap(dev, offset, agp_size - offset,
-                        _DRM_AGP, 0, &dev_priv->agp_textures);
-       if (err) {
-               DRM_ERROR("Unable to map AGP texture region %d\n", err);
-               return err;
-       }
-
-       drm_core_ioremap(dev_priv->warp, dev);
-       drm_core_ioremap(dev_priv->primary, dev);
-       drm_core_ioremap(dev->agp_buffer_map, dev);
-
-       if (!dev_priv->warp->handle ||
-           !dev_priv->primary->handle || !dev->agp_buffer_map->handle) {
-               DRM_ERROR("failed to ioremap agp regions! (%p, %p, %p)\n",
-                         dev_priv->warp->handle, dev_priv->primary->handle,
-                         dev->agp_buffer_map->handle);
-               return -ENOMEM;
-       }
-
-       dev_priv->dma_access = MGA_PAGPXFER;
-       dev_priv->wagp_enable = MGA_WAGP_ENABLE;
-
-       DRM_INFO("Initialized card for AGP DMA.\n");
-       return 0;
-}
-#else
-static int mga_do_agp_dma_bootstrap(struct drm_device * dev,
-                                   drm_mga_dma_bootstrap_t * dma_bs)
-{
-       return -EINVAL;
-}
-#endif
-
-/**
- * Bootstrap the driver for PCI DMA.
- *
- * \todo
- * The algorithm for decreasing the size of the primary DMA buffer could be
- * better.  The size should be rounded up to the nearest page size, then
- * decrease the request size by a single page each pass through the loop.
- *
- * \todo
- * Determine whether the maximum address passed to drm_pci_alloc is correct.
- * The same goes for drm_addbufs_pci.
- *
- * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap
- */
-static int mga_do_pci_dma_bootstrap(struct drm_device * dev,
-                                   drm_mga_dma_bootstrap_t * dma_bs)
-{
-       drm_mga_private_t *const dev_priv =
-           (drm_mga_private_t *) dev->dev_private;
-       unsigned int warp_size = mga_warp_microcode_size(dev_priv);
-       unsigned int primary_size;
-       unsigned int bin_count;
-       int err;
-       struct drm_buf_desc req;
-
-       if (dev->dma == NULL) {
-               DRM_ERROR("dev->dma is NULL\n");
-               return -EFAULT;
-       }
-
-       /* Make drm_addbufs happy by not trying to create a mapping for less
-        * than a page.
-        */
-       if (warp_size < PAGE_SIZE)
-               warp_size = PAGE_SIZE;
-
-       /* The proper alignment is 0x100 for this mapping */
-       err = drm_addmap(dev, 0, warp_size, _DRM_CONSISTENT,
-                        _DRM_READ_ONLY, &dev_priv->warp);
-       if (err != 0) {
-               DRM_ERROR("Unable to create mapping for WARP microcode: %d\n",
-                         err);
-               return err;
-       }
-
-       /* Other than the bottom two bits being used to encode other
-        * information, there don't appear to be any restrictions on the
-        * alignment of the primary or secondary DMA buffers.
-        */
-
-       for (primary_size = dma_bs->primary_size; primary_size != 0;
-            primary_size >>= 1) {
-               /* The proper alignment for this mapping is 0x04 */
-               err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT,
-                                _DRM_READ_ONLY, &dev_priv->primary);
-               if (!err)
-                       break;
-       }
-
-       if (err != 0) {
-               DRM_ERROR("Unable to allocate primary DMA region: %d\n", err);
-               return -ENOMEM;
-       }
-
-       if (dev_priv->primary->size != dma_bs->primary_size) {
-               DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n",
-                        dma_bs->primary_size,
-                        (unsigned)dev_priv->primary->size);
-               dma_bs->primary_size = dev_priv->primary->size;
-       }
-
-       for (bin_count = dma_bs->secondary_bin_count; bin_count > 0;
-            bin_count--) {
-               (void)memset(&req, 0, sizeof(req));
-               req.count = bin_count;
-               req.size = dma_bs->secondary_bin_size;
-
-               err = drm_addbufs_pci(dev, &req);
-               if (!err) {
-                       break;
-               }
-       }
-
-       if (bin_count == 0) {
-               DRM_ERROR("Unable to add secondary DMA buffers: %d\n", err);
-               return err;
-       }
-
-       if (bin_count != dma_bs->secondary_bin_count) {
-               DRM_INFO("Secondary PCI DMA buffer bin count reduced from %u "
-                        "to %u.\n", dma_bs->secondary_bin_count, bin_count);
-
-               dma_bs->secondary_bin_count = bin_count;
-       }
-
-       dev_priv->dma_access = 0;
-       dev_priv->wagp_enable = 0;
-
-       dma_bs->agp_mode = 0;
-
-       DRM_INFO("Initialized card for PCI DMA.\n");
-       return 0;
-}
-
-static int mga_do_dma_bootstrap(struct drm_device * dev,
-                               drm_mga_dma_bootstrap_t * dma_bs)
-{
-       const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev);
-       int err;
-       drm_mga_private_t *const dev_priv =
-           (drm_mga_private_t *) dev->dev_private;
-
-       dev_priv->used_new_dma_init = 1;
-
-       /* The first steps are the same for both PCI and AGP based DMA.  Map
-        * the cards MMIO registers and map a status page.
-        */
-       err = drm_addmap(dev, dev_priv->mmio_base, dev_priv->mmio_size,
-                        _DRM_REGISTERS, _DRM_READ_ONLY, &dev_priv->mmio);
-       if (err) {
-               DRM_ERROR("Unable to map MMIO region: %d\n", err);
-               return err;
-       }
-
-       err = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
-                        _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL,
-                        &dev_priv->status);
-       if (err) {
-               DRM_ERROR("Unable to map status region: %d\n", err);
-               return err;
-       }
-
-       /* The DMA initialization procedure is slightly different for PCI and
-        * AGP cards.  AGP cards just allocate a large block of AGP memory and
-        * carve off portions of it for internal uses.  The remaining memory
-        * is returned to user-mode to be used for AGP textures.
-        */
-       if (is_agp) {
-               err = mga_do_agp_dma_bootstrap(dev, dma_bs);
-       }
-
-       /* If we attempted to initialize the card for AGP DMA but failed,
-        * clean-up any mess that may have been created.
-        */
-
-       if (err) {
-               mga_do_cleanup_dma(dev, MINIMAL_CLEANUP);
-       }
-
-       /* Not only do we want to try and initialized PCI cards for PCI DMA,
-        * but we also try to initialized AGP cards that could not be
-        * initialized for AGP DMA.  This covers the case where we have an AGP
-        * card in a system with an unsupported AGP chipset.  In that case the
-        * card will be detected as AGP, but we won't be able to allocate any
-        * AGP memory, etc.
-        */
-
-       if (!is_agp || err) {
-               err = mga_do_pci_dma_bootstrap(dev, dma_bs);
-       }
-
-       return err;
-}
-
-int mga_dma_bootstrap(struct drm_device *dev, void *data,
-                     struct drm_file *file_priv)
-{
-       drm_mga_dma_bootstrap_t *bootstrap = data;
-       int err;
-       static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
-       const drm_mga_private_t *const dev_priv =
-               (drm_mga_private_t *) dev->dev_private;
-
-       err = mga_do_dma_bootstrap(dev, bootstrap);
-       if (err) {
-               mga_do_cleanup_dma(dev, FULL_CLEANUP);
-               return err;
-       }
-
-       if (dev_priv->agp_textures != NULL) {
-               bootstrap->texture_handle = dev_priv->agp_textures->offset;
-               bootstrap->texture_size = dev_priv->agp_textures->size;
-       } else {
-               bootstrap->texture_handle = 0;
-               bootstrap->texture_size = 0;
-       }
-
-       bootstrap->agp_mode = modes[bootstrap->agp_mode & 0x07];
-
-       return err;
-}
-
-static int mga_do_init_dma(struct drm_device * dev, drm_mga_init_t * init)
-{
-       drm_mga_private_t *dev_priv;
-       int ret;
-       DRM_DEBUG("\n");
-
-       dev_priv = dev->dev_private;
-
-       if (init->sgram) {
-               dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_BLK;
-       } else {
-               dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
-       }
-       dev_priv->maccess = init->maccess;
-
-       dev_priv->fb_cpp = init->fb_cpp;
-       dev_priv->front_offset = init->front_offset;
-       dev_priv->front_pitch = init->front_pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->back_pitch = init->back_pitch;
-
-       dev_priv->depth_cpp = init->depth_cpp;
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->depth_pitch = init->depth_pitch;
-
-       /* FIXME: Need to support AGP textures...
-        */
-       dev_priv->texture_offset = init->texture_offset[0];
-       dev_priv->texture_size = init->texture_size[0];
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("failed to find sarea!\n");
-               return -EINVAL;
-       }
-
-       if (!dev_priv->used_new_dma_init) {
-
-               dev_priv->dma_access = MGA_PAGPXFER;
-               dev_priv->wagp_enable = MGA_WAGP_ENABLE;
-
-               dev_priv->status = drm_core_findmap(dev, init->status_offset);
-               if (!dev_priv->status) {
-                       DRM_ERROR("failed to find status page!\n");
-                       return -EINVAL;
-               }
-               dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
-               if (!dev_priv->mmio) {
-                       DRM_ERROR("failed to find mmio region!\n");
-                       return -EINVAL;
-               }
-               dev_priv->warp = drm_core_findmap(dev, init->warp_offset);
-               if (!dev_priv->warp) {
-                       DRM_ERROR("failed to find warp microcode region!\n");
-                       return -EINVAL;
-               }
-               dev_priv->primary = drm_core_findmap(dev, init->primary_offset);
-               if (!dev_priv->primary) {
-                       DRM_ERROR("failed to find primary dma region!\n");
-                       return -EINVAL;
-               }
-               dev->agp_buffer_token = init->buffers_offset;
-               dev->agp_buffer_map =
-                   drm_core_findmap(dev, init->buffers_offset);
-               if (!dev->agp_buffer_map) {
-                       DRM_ERROR("failed to find dma buffer region!\n");
-                       return -EINVAL;
-               }
-
-               drm_core_ioremap(dev_priv->warp, dev);
-               drm_core_ioremap(dev_priv->primary, dev);
-               drm_core_ioremap(dev->agp_buffer_map, dev);
-       }
-
-       dev_priv->sarea_priv =
-           (drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle +
-                                init->sarea_priv_offset);
-
-       if (!dev_priv->warp->handle ||
-           !dev_priv->primary->handle ||
-           ((dev_priv->dma_access != 0) &&
-            ((dev->agp_buffer_map == NULL) ||
-             (dev->agp_buffer_map->handle == NULL)))) {
-               DRM_ERROR("failed to ioremap agp regions!\n");
-               return -ENOMEM;
-       }
-
-       ret = mga_warp_install_microcode(dev_priv);
-       if (ret < 0) {
-               DRM_ERROR("failed to install WARP ucode!: %d\n", ret);
-               return ret;
-       }
-
-       ret = mga_warp_init(dev_priv);
-       if (ret < 0) {
-               DRM_ERROR("failed to init WARP engine!: %d\n", ret);
-               return ret;
-       }
-
-       dev_priv->prim.status = (u32 *) dev_priv->status->handle;
-
-       mga_do_wait_for_idle(dev_priv);
-
-       /* Init the primary DMA registers.
-        */
-       MGA_WRITE(MGA_PRIMADDRESS, dev_priv->primary->offset | MGA_DMA_GENERAL);
-#if 0
-       MGA_WRITE(MGA_PRIMPTR, virt_to_bus((void *)dev_priv->prim.status) | MGA_PRIMPTREN0 |    /* Soft trap, SECEND, SETUPEND */
-                 MGA_PRIMPTREN1);      /* DWGSYNC */
-#endif
-
-       dev_priv->prim.start = (u8 *) dev_priv->primary->handle;
-       dev_priv->prim.end = ((u8 *) dev_priv->primary->handle
-                             + dev_priv->primary->size);
-       dev_priv->prim.size = dev_priv->primary->size;
-
-       dev_priv->prim.tail = 0;
-       dev_priv->prim.space = dev_priv->prim.size;
-       dev_priv->prim.wrapped = 0;
-
-       dev_priv->prim.last_flush = 0;
-       dev_priv->prim.last_wrap = 0;
-
-       dev_priv->prim.high_mark = 256 * DMA_BLOCK_SIZE;
-
-       dev_priv->prim.status[0] = dev_priv->primary->offset;
-       dev_priv->prim.status[1] = 0;
-
-       dev_priv->sarea_priv->last_wrap = 0;
-       dev_priv->sarea_priv->last_frame.head = 0;
-       dev_priv->sarea_priv->last_frame.wrap = 0;
-
-       if (mga_freelist_init(dev, dev_priv) < 0) {
-               DRM_ERROR("could not initialize freelist\n");
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-static int mga_do_cleanup_dma(struct drm_device *dev, int full_cleanup)
-{
-       int err = 0;
-       DRM_DEBUG("\n");
-
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-       if (dev->dev_private) {
-               drm_mga_private_t *dev_priv = dev->dev_private;
-
-               if ((dev_priv->warp != NULL)
-                   && (dev_priv->warp->type != _DRM_CONSISTENT))
-                       drm_core_ioremapfree(dev_priv->warp, dev);
-
-               if ((dev_priv->primary != NULL)
-                   && (dev_priv->primary->type != _DRM_CONSISTENT))
-                       drm_core_ioremapfree(dev_priv->primary, dev);
-
-               if (dev->agp_buffer_map != NULL)
-                       drm_core_ioremapfree(dev->agp_buffer_map, dev);
-
-               if (dev_priv->used_new_dma_init) {
-#if __OS_HAS_AGP
-                       if (dev_priv->agp_handle != 0) {
-                               struct drm_agp_binding unbind_req;
-                               struct drm_agp_buffer free_req;
-
-                               unbind_req.handle = dev_priv->agp_handle;
-                               drm_agp_unbind(dev, &unbind_req);
-
-                               free_req.handle = dev_priv->agp_handle;
-                               drm_agp_free(dev, &free_req);
-
-                               dev_priv->agp_textures = NULL;
-                               dev_priv->agp_size = 0;
-                               dev_priv->agp_handle = 0;
-                       }
-
-                       if ((dev->agp != NULL) && dev->agp->acquired) {
-                               err = drm_agp_release(dev);
-                       }
-#endif
-               }
-
-               dev_priv->warp = NULL;
-               dev_priv->primary = NULL;
-               dev_priv->sarea = NULL;
-               dev_priv->sarea_priv = NULL;
-               dev->agp_buffer_map = NULL;
-
-               if (full_cleanup) {
-                       dev_priv->mmio = NULL;
-                       dev_priv->status = NULL;
-                       dev_priv->used_new_dma_init = 0;
-               }
-
-               memset(&dev_priv->prim, 0, sizeof(dev_priv->prim));
-               dev_priv->warp_pipe = 0;
-               memset(dev_priv->warp_pipe_phys, 0,
-                      sizeof(dev_priv->warp_pipe_phys));
-
-               if (dev_priv->head != NULL) {
-                       mga_freelist_cleanup(dev);
-               }
-       }
-
-       return err;
-}
-
-int mga_dma_init(struct drm_device *dev, void *data,
-                struct drm_file *file_priv)
-{
-       drm_mga_init_t *init = data;
-       int err;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       switch (init->func) {
-       case MGA_INIT_DMA:
-               err = mga_do_init_dma(dev, init);
-               if (err) {
-                       (void)mga_do_cleanup_dma(dev, FULL_CLEANUP);
-               }
-               return err;
-       case MGA_CLEANUP_DMA:
-               return mga_do_cleanup_dma(dev, FULL_CLEANUP);
-       }
-
-       return -EINVAL;
-}
-
-/* ================================================================
- * Primary DMA stream management
- */
-
-int mga_dma_flush(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-       struct drm_lock *lock = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("%s%s%s\n",
-                 (lock->flags & _DRM_LOCK_FLUSH) ? "flush, " : "",
-                 (lock->flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "",
-                 (lock->flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "");
-
-       WRAP_WAIT_WITH_RETURN(dev_priv);
-
-       if (lock->flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL)) {
-               mga_do_dma_flush(dev_priv);
-       }
-
-       if (lock->flags & _DRM_LOCK_QUIESCENT) {
-#if MGA_DMA_DEBUG
-               int ret = mga_do_wait_for_idle(dev_priv);
-               if (ret < 0)
-                       DRM_INFO("-EBUSY\n");
-               return ret;
-#else
-               return mga_do_wait_for_idle(dev_priv);
-#endif
-       } else {
-               return 0;
-       }
-}
-
-int mga_dma_reset(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return mga_do_dma_reset(dev_priv);
-}
-
-/* ================================================================
- * DMA buffer management
- */
-
-static int mga_dma_get_buffers(struct drm_device * dev,
-                              struct drm_file *file_priv, struct drm_dma * d)
-{
-       struct drm_buf *buf;
-       int i;
-
-       for (i = d->granted_count; i < d->request_count; i++) {
-               buf = mga_freelist_get(dev);
-               if (!buf)
-                       return -EAGAIN;
-
-               buf->file_priv = file_priv;
-
-               if (DRM_COPY_TO_USER(&d->request_indices[i],
-                                    &buf->idx, sizeof(buf->idx)))
-                       return -EFAULT;
-               if (DRM_COPY_TO_USER(&d->request_sizes[i],
-                                    &buf->total, sizeof(buf->total)))
-                       return -EFAULT;
-
-               d->granted_count++;
-       }
-       return 0;
-}
-
-int mga_dma_buffers(struct drm_device *dev, void *data,
-                   struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-       struct drm_dma *d = data;
-       int ret = 0;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* Please don't send us buffers.
-        */
-       if (d->send_count != 0) {
-               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
-                         DRM_CURRENTPID, d->send_count);
-               return -EINVAL;
-       }
-
-       /* We'll send you buffers.
-        */
-       if (d->request_count < 0 || d->request_count > dma->buf_count) {
-               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
-                         DRM_CURRENTPID, d->request_count, dma->buf_count);
-               return -EINVAL;
-       }
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       d->granted_count = 0;
-
-       if (d->request_count) {
-               ret = mga_dma_get_buffers(dev, file_priv, d);
-       }
-
-       return ret;
-}
-
-/**
- * Called just before the module is unloaded.
- */
-int mga_driver_unload(struct drm_device * dev)
-{
-       drm_free(dev->dev_private, sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
-       dev->dev_private = NULL;
-
-       return 0;
-}
-
-/**
- * Called when the last opener of the device is closed.
- */
-void mga_driver_lastclose(struct drm_device * dev)
-{
-       mga_do_cleanup_dma(dev, FULL_CLEANUP);
-}
-
-int mga_driver_dma_quiescent(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       return mga_do_wait_for_idle(dev_priv);
-}
diff --git a/drivers/char/drm/mga_drm.h b/drivers/char/drm/mga_drm.h
deleted file mode 100644 (file)
index 944b50a..0000000
+++ /dev/null
@@ -1,417 +0,0 @@
-/* mga_drm.h -- Public header for the Matrox g200/g400 driver -*- linux-c -*-
- * Created: Tue Jan 25 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Jeff Hartmann <jhartmann@valinux.com>
- *    Keith Whitwell <keith@tungstengraphics.com>
- *
- * Rewritten by:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#ifndef __MGA_DRM_H__
-#define __MGA_DRM_H__
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the Xserver file (mga_sarea.h)
- */
-
-#ifndef __MGA_SAREA_DEFINES__
-#define __MGA_SAREA_DEFINES__
-
-/* WARP pipe flags
- */
-#define MGA_F                  0x1     /* fog */
-#define MGA_A                  0x2     /* alpha */
-#define MGA_S                  0x4     /* specular */
-#define MGA_T2                 0x8     /* multitexture */
-
-#define MGA_WARP_TGZ           0
-#define MGA_WARP_TGZF          (MGA_F)
-#define MGA_WARP_TGZA          (MGA_A)
-#define MGA_WARP_TGZAF         (MGA_F|MGA_A)
-#define MGA_WARP_TGZS          (MGA_S)
-#define MGA_WARP_TGZSF         (MGA_S|MGA_F)
-#define MGA_WARP_TGZSA         (MGA_S|MGA_A)
-#define MGA_WARP_TGZSAF                (MGA_S|MGA_F|MGA_A)
-#define MGA_WARP_T2GZ          (MGA_T2)
-#define MGA_WARP_T2GZF         (MGA_T2|MGA_F)
-#define MGA_WARP_T2GZA         (MGA_T2|MGA_A)
-#define MGA_WARP_T2GZAF                (MGA_T2|MGA_A|MGA_F)
-#define MGA_WARP_T2GZS         (MGA_T2|MGA_S)
-#define MGA_WARP_T2GZSF                (MGA_T2|MGA_S|MGA_F)
-#define MGA_WARP_T2GZSA                (MGA_T2|MGA_S|MGA_A)
-#define MGA_WARP_T2GZSAF       (MGA_T2|MGA_S|MGA_F|MGA_A)
-
-#define MGA_MAX_G200_PIPES     8       /* no multitex */
-#define MGA_MAX_G400_PIPES     16
-#define MGA_MAX_WARP_PIPES     MGA_MAX_G400_PIPES
-#define MGA_WARP_UCODE_SIZE    32768   /* in bytes */
-
-#define MGA_CARD_TYPE_G200     1
-#define MGA_CARD_TYPE_G400     2
-#define MGA_CARD_TYPE_G450     3       /* not currently used */
-#define MGA_CARD_TYPE_G550     4
-
-#define MGA_FRONT              0x1
-#define MGA_BACK               0x2
-#define MGA_DEPTH              0x4
-
-/* What needs to be changed for the current vertex dma buffer?
- */
-#define MGA_UPLOAD_CONTEXT     0x1
-#define MGA_UPLOAD_TEX0                0x2
-#define MGA_UPLOAD_TEX1                0x4
-#define MGA_UPLOAD_PIPE                0x8
-#define MGA_UPLOAD_TEX0IMAGE   0x10    /* handled client-side */
-#define MGA_UPLOAD_TEX1IMAGE   0x20    /* handled client-side */
-#define MGA_UPLOAD_2D          0x40
-#define MGA_WAIT_AGE           0x80    /* handled client-side */
-#define MGA_UPLOAD_CLIPRECTS   0x100   /* handled client-side */
-#if 0
-#define MGA_DMA_FLUSH          0x200   /* set when someone gets the lock
-                                          quiescent */
-#endif
-
-/* 32 buffers of 64k each, total 2 meg.
- */
-#define MGA_BUFFER_SIZE                (1 << 16)
-#define MGA_NUM_BUFFERS                128
-
-/* Keep these small for testing.
- */
-#define MGA_NR_SAREA_CLIPRECTS 8
-
-/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
- * regions, subject to a minimum region size of (1<<16) == 64k.
- *
- * Clients may subdivide regions internally, but when sharing between
- * clients, the region size is the minimum granularity.
- */
-
-#define MGA_CARD_HEAP                  0
-#define MGA_AGP_HEAP                   1
-#define MGA_NR_TEX_HEAPS               2
-#define MGA_NR_TEX_REGIONS             16
-#define MGA_LOG_MIN_TEX_REGION_SIZE    16
-
-#define  DRM_MGA_IDLE_RETRY          2048
-
-#endif                         /* __MGA_SAREA_DEFINES__ */
-
-/* Setup registers for 3D context
- */
-typedef struct {
-       unsigned int dstorg;
-       unsigned int maccess;
-       unsigned int plnwt;
-       unsigned int dwgctl;
-       unsigned int alphactrl;
-       unsigned int fogcolor;
-       unsigned int wflag;
-       unsigned int tdualstage0;
-       unsigned int tdualstage1;
-       unsigned int fcol;
-       unsigned int stencil;
-       unsigned int stencilctl;
-} drm_mga_context_regs_t;
-
-/* Setup registers for 2D, X server
- */
-typedef struct {
-       unsigned int pitch;
-} drm_mga_server_regs_t;
-
-/* Setup registers for each texture unit
- */
-typedef struct {
-       unsigned int texctl;
-       unsigned int texctl2;
-       unsigned int texfilter;
-       unsigned int texbordercol;
-       unsigned int texorg;
-       unsigned int texwidth;
-       unsigned int texheight;
-       unsigned int texorg1;
-       unsigned int texorg2;
-       unsigned int texorg3;
-       unsigned int texorg4;
-} drm_mga_texture_regs_t;
-
-/* General aging mechanism
- */
-typedef struct {
-       unsigned int head;      /* Position of head pointer          */
-       unsigned int wrap;      /* Primary DMA wrap count            */
-} drm_mga_age_t;
-
-typedef struct _drm_mga_sarea {
-       /* The channel for communication of state information to the kernel
-        * on firing a vertex dma buffer.
-        */
-       drm_mga_context_regs_t context_state;
-       drm_mga_server_regs_t server_state;
-       drm_mga_texture_regs_t tex_state[2];
-       unsigned int warp_pipe;
-       unsigned int dirty;
-       unsigned int vertsize;
-
-       /* The current cliprects, or a subset thereof.
-        */
-       struct drm_clip_rect boxes[MGA_NR_SAREA_CLIPRECTS];
-       unsigned int nbox;
-
-       /* Information about the most recently used 3d drawable.  The
-        * client fills in the req_* fields, the server fills in the
-        * exported_ fields and puts the cliprects into boxes, above.
-        *
-        * The client clears the exported_drawable field before
-        * clobbering the boxes data.
-        */
-       unsigned int req_drawable;      /* the X drawable id */
-       unsigned int req_draw_buffer;   /* MGA_FRONT or MGA_BACK */
-
-       unsigned int exported_drawable;
-       unsigned int exported_index;
-       unsigned int exported_stamp;
-       unsigned int exported_buffers;
-       unsigned int exported_nfront;
-       unsigned int exported_nback;
-       int exported_back_x, exported_front_x, exported_w;
-       int exported_back_y, exported_front_y, exported_h;
-       struct drm_clip_rect exported_boxes[MGA_NR_SAREA_CLIPRECTS];
-
-       /* Counters for aging textures and for client-side throttling.
-        */
-       unsigned int status[4];
-       unsigned int last_wrap;
-
-       drm_mga_age_t last_frame;
-       unsigned int last_enqueue;      /* last time a buffer was enqueued */
-       unsigned int last_dispatch;     /* age of the most recently dispatched buffer */
-       unsigned int last_quiescent;    /*  */
-
-       /* LRU lists for texture memory in agp space and on the card.
-        */
-       struct drm_tex_region texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS + 1];
-       unsigned int texAge[MGA_NR_TEX_HEAPS];
-
-       /* Mechanism to validate card state.
-        */
-       int ctxOwner;
-} drm_mga_sarea_t;
-
-/* MGA specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_MGA_INIT     0x00
-#define DRM_MGA_FLUSH    0x01
-#define DRM_MGA_RESET    0x02
-#define DRM_MGA_SWAP     0x03
-#define DRM_MGA_CLEAR    0x04
-#define DRM_MGA_VERTEX   0x05
-#define DRM_MGA_INDICES  0x06
-#define DRM_MGA_ILOAD    0x07
-#define DRM_MGA_BLIT     0x08
-#define DRM_MGA_GETPARAM 0x09
-
-/* 3.2:
- * ioctls for operating on fences.
- */
-#define DRM_MGA_SET_FENCE      0x0a
-#define DRM_MGA_WAIT_FENCE     0x0b
-#define DRM_MGA_DMA_BOOTSTRAP  0x0c
-
-#define DRM_IOCTL_MGA_INIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)
-#define DRM_IOCTL_MGA_FLUSH    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, drm_lock_t)
-#define DRM_IOCTL_MGA_RESET    DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_RESET)
-#define DRM_IOCTL_MGA_SWAP     DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_SWAP)
-#define DRM_IOCTL_MGA_CLEAR    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_CLEAR, drm_mga_clear_t)
-#define DRM_IOCTL_MGA_VERTEX   DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_VERTEX, drm_mga_vertex_t)
-#define DRM_IOCTL_MGA_INDICES  DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INDICES, drm_mga_indices_t)
-#define DRM_IOCTL_MGA_ILOAD    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_ILOAD, drm_mga_iload_t)
-#define DRM_IOCTL_MGA_BLIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_BLIT, drm_mga_blit_t)
-#define DRM_IOCTL_MGA_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_GETPARAM, drm_mga_getparam_t)
-#define DRM_IOCTL_MGA_SET_FENCE     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_SET_FENCE, uint32_t)
-#define DRM_IOCTL_MGA_WAIT_FENCE    DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_WAIT_FENCE, uint32_t)
-#define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)
-
-typedef struct _drm_mga_warp_index {
-       int installed;
-       unsigned long phys_addr;
-       int size;
-} drm_mga_warp_index_t;
-
-typedef struct drm_mga_init {
-       enum {
-               MGA_INIT_DMA = 0x01,
-               MGA_CLEANUP_DMA = 0x02
-       } func;
-
-       unsigned long sarea_priv_offset;
-
-       int chipset;
-       int sgram;
-
-       unsigned int maccess;
-
-       unsigned int fb_cpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-
-       unsigned int depth_cpp;
-       unsigned int depth_offset, depth_pitch;
-
-       unsigned int texture_offset[MGA_NR_TEX_HEAPS];
-       unsigned int texture_size[MGA_NR_TEX_HEAPS];
-
-       unsigned long fb_offset;
-       unsigned long mmio_offset;
-       unsigned long status_offset;
-       unsigned long warp_offset;
-       unsigned long primary_offset;
-       unsigned long buffers_offset;
-} drm_mga_init_t;
-
-typedef struct drm_mga_dma_bootstrap {
-       /**
-        * \name AGP texture region
-        *
-        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will
-        * be filled in with the actual AGP texture settings.
-        *
-        * \warning
-        * If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode
-        * is zero, it means that PCI memory (most likely through the use of
-        * an IOMMU) is being used for "AGP" textures.
-        */
-       /*@{ */
-       unsigned long texture_handle; /**< Handle used to map AGP textures. */
-       uint32_t texture_size;        /**< Size of the AGP texture region. */
-       /*@} */
-
-       /**
-        * Requested size of the primary DMA region.
-        *
-        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
-        * filled in with the actual AGP mode.  If AGP was not available
-        */
-       uint32_t primary_size;
-
-       /**
-        * Requested number of secondary DMA buffers.
-        *
-        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
-        * filled in with the actual number of secondary DMA buffers
-        * allocated.  Particularly when PCI DMA is used, this may be
-        * (subtantially) less than the number requested.
-        */
-       uint32_t secondary_bin_count;
-
-       /**
-        * Requested size of each secondary DMA buffer.
-        *
-        * While the kernel \b is free to reduce
-        * dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed
-        * to reduce dma_mga_dma_bootstrap::secondary_bin_size.
-        */
-       uint32_t secondary_bin_size;
-
-       /**
-        * Bit-wise mask of AGPSTAT2_* values.  Currently only \c AGPSTAT2_1X,
-        * \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported.  If this value is
-        * zero, it means that PCI DMA should be used, even if AGP is
-        * possible.
-        *
-        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
-        * filled in with the actual AGP mode.  If AGP was not available
-        * (i.e., PCI DMA was used), this value will be zero.
-        */
-       uint32_t agp_mode;
-
-       /**
-        * Desired AGP GART size, measured in megabytes.
-        */
-       uint8_t agp_size;
-} drm_mga_dma_bootstrap_t;
-
-typedef struct drm_mga_clear {
-       unsigned int flags;
-       unsigned int clear_color;
-       unsigned int clear_depth;
-       unsigned int color_mask;
-       unsigned int depth_mask;
-} drm_mga_clear_t;
-
-typedef struct drm_mga_vertex {
-       int idx;                /* buffer to queue */
-       int used;               /* bytes in use */
-       int discard;            /* client finished with buffer?  */
-} drm_mga_vertex_t;
-
-typedef struct drm_mga_indices {
-       int idx;                /* buffer to queue */
-       unsigned int start;
-       unsigned int end;
-       int discard;            /* client finished with buffer?  */
-} drm_mga_indices_t;
-
-typedef struct drm_mga_iload {
-       int idx;
-       unsigned int dstorg;
-       unsigned int length;
-} drm_mga_iload_t;
-
-typedef struct _drm_mga_blit {
-       unsigned int planemask;
-       unsigned int srcorg;
-       unsigned int dstorg;
-       int src_pitch, dst_pitch;
-       int delta_sx, delta_sy;
-       int delta_dx, delta_dy;
-       int height, ydir;       /* flip image vertically */
-       int source_pitch, dest_pitch;
-} drm_mga_blit_t;
-
-/* 3.1: An ioctl to get parameters that aren't available to the 3d
- * client any other way.
- */
-#define MGA_PARAM_IRQ_NR            1
-
-/* 3.2: Query the actual card type.  The DDX only distinguishes between
- * G200 chips and non-G200 chips, which it calls G400.  It turns out that
- * there are some very sublte differences between the G4x0 chips and the G550
- * chips.  Using this parameter query, a client-side driver can detect the
- * difference between a G4x0 and a G550.
- */
-#define MGA_PARAM_CARD_TYPE         2
-
-typedef struct drm_mga_getparam {
-       int param;
-       void __user *value;
-} drm_mga_getparam_t;
-
-#endif
diff --git a/drivers/char/drm/mga_drv.c b/drivers/char/drm/mga_drv.c
deleted file mode 100644 (file)
index 5572939..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "mga_drm.h"
-#include "mga_drv.h"
-
-#include "drm_pciids.h"
-
-static int mga_driver_device_is_agp(struct drm_device * dev);
-
-static struct pci_device_id pciidlist[] = {
-       mga_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
-           DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
-           DRIVER_IRQ_VBL,
-       .dev_priv_size = sizeof(drm_mga_buf_priv_t),
-       .load = mga_driver_load,
-       .unload = mga_driver_unload,
-       .lastclose = mga_driver_lastclose,
-       .dma_quiescent = mga_driver_dma_quiescent,
-       .device_is_agp = mga_driver_device_is_agp,
-       .vblank_wait = mga_driver_vblank_wait,
-       .irq_preinstall = mga_driver_irq_preinstall,
-       .irq_postinstall = mga_driver_irq_postinstall,
-       .irq_uninstall = mga_driver_irq_uninstall,
-       .irq_handler = mga_driver_irq_handler,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = mga_ioctls,
-       .dma_ioctl = mga_dma_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = mga_compat_ioctl,
-#endif
-                },
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init mga_init(void)
-{
-       driver.num_ioctls = mga_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit mga_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(mga_init);
-module_exit(mga_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
-
-/**
- * Determine if the device really is AGP or not.
- *
- * In addition to the usual tests performed by \c drm_device_is_agp, this
- * function detects PCI G450 cards that appear to the system exactly like
- * AGP G450 cards.
- *
- * \param dev   The device to be tested.
- *
- * \returns
- * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
- */
-static int mga_driver_device_is_agp(struct drm_device * dev)
-{
-       const struct pci_dev *const pdev = dev->pdev;
-
-       /* There are PCI versions of the G450.  These cards have the
-        * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
-        * bridge chip.  We detect these cards, which are not currently
-        * supported by this driver, by looking at the device ID of the
-        * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
-        * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
-        * device.
-        */
-
-       if ((pdev->device == 0x0525) && pdev->bus->self
-           && (pdev->bus->self->vendor == 0x3388)
-           && (pdev->bus->self->device == 0x0021)) {
-               return 0;
-       }
-
-       return 2;
-}
diff --git a/drivers/char/drm/mga_drv.h b/drivers/char/drm/mga_drv.h
deleted file mode 100644 (file)
index f6ebd24..0000000
+++ /dev/null
@@ -1,687 +0,0 @@
-/* mga_drv.h -- Private header for the Matrox G200/G400 driver -*- linux-c -*-
- * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#ifndef __MGA_DRV_H__
-#define __MGA_DRV_H__
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "Gareth Hughes, VA Linux Systems Inc."
-
-#define DRIVER_NAME            "mga"
-#define DRIVER_DESC            "Matrox G200/G400"
-#define DRIVER_DATE            "20051102"
-
-#define DRIVER_MAJOR           3
-#define DRIVER_MINOR           2
-#define DRIVER_PATCHLEVEL      1
-
-typedef struct drm_mga_primary_buffer {
-       u8 *start;
-       u8 *end;
-       int size;
-
-       u32 tail;
-       int space;
-       volatile long wrapped;
-
-       volatile u32 *status;
-
-       u32 last_flush;
-       u32 last_wrap;
-
-       u32 high_mark;
-} drm_mga_primary_buffer_t;
-
-typedef struct drm_mga_freelist {
-       struct drm_mga_freelist *next;
-       struct drm_mga_freelist *prev;
-       drm_mga_age_t age;
-       struct drm_buf *buf;
-} drm_mga_freelist_t;
-
-typedef struct {
-       drm_mga_freelist_t *list_entry;
-       int discard;
-       int dispatched;
-} drm_mga_buf_priv_t;
-
-typedef struct drm_mga_private {
-       drm_mga_primary_buffer_t prim;
-       drm_mga_sarea_t *sarea_priv;
-
-       drm_mga_freelist_t *head;
-       drm_mga_freelist_t *tail;
-
-       unsigned int warp_pipe;
-       unsigned long warp_pipe_phys[MGA_MAX_WARP_PIPES];
-
-       int chipset;
-       int usec_timeout;
-
-       /**
-        * If set, the new DMA initialization sequence was used.  This is
-        * primarilly used to select how the driver should uninitialized its
-        * internal DMA structures.
-        */
-       int used_new_dma_init;
-
-       /**
-        * If AGP memory is used for DMA buffers, this will be the value
-        * \c MGA_PAGPXFER.  Otherwise, it will be zero (for a PCI transfer).
-        */
-       u32 dma_access;
-
-       /**
-        * If AGP memory is used for DMA buffers, this will be the value
-        * \c MGA_WAGP_ENABLE.  Otherwise, it will be zero (for a PCI
-        * transfer).
-        */
-       u32 wagp_enable;
-
-       /**
-        * \name MMIO region parameters.
-        *
-        * \sa drm_mga_private_t::mmio
-        */
-       /*@{ */
-       u32 mmio_base;             /**< Bus address of base of MMIO. */
-       u32 mmio_size;             /**< Size of the MMIO region. */
-       /*@} */
-
-       u32 clear_cmd;
-       u32 maccess;
-
-       wait_queue_head_t fence_queue;
-       atomic_t last_fence_retired;
-       u32 next_fence_to_post;
-
-       unsigned int fb_cpp;
-       unsigned int front_offset;
-       unsigned int front_pitch;
-       unsigned int back_offset;
-       unsigned int back_pitch;
-
-       unsigned int depth_cpp;
-       unsigned int depth_offset;
-       unsigned int depth_pitch;
-
-       unsigned int texture_offset;
-       unsigned int texture_size;
-
-       drm_local_map_t *sarea;
-       drm_local_map_t *mmio;
-       drm_local_map_t *status;
-       drm_local_map_t *warp;
-       drm_local_map_t *primary;
-       drm_local_map_t *agp_textures;
-
-       unsigned long agp_handle;
-       unsigned int agp_size;
-} drm_mga_private_t;
-
-extern struct drm_ioctl_desc mga_ioctls[];
-extern int mga_max_ioctl;
-
-                               /* mga_dma.c */
-extern int mga_dma_bootstrap(struct drm_device *dev, void *data,
-                            struct drm_file *file_priv);
-extern int mga_dma_init(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv);
-extern int mga_dma_flush(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int mga_dma_reset(struct drm_device *dev, void *data,
-                        struct drm_file *file_priv);
-extern int mga_dma_buffers(struct drm_device *dev, void *data,
-                          struct drm_file *file_priv);
-extern int mga_driver_load(struct drm_device *dev, unsigned long flags);
-extern int mga_driver_unload(struct drm_device * dev);
-extern void mga_driver_lastclose(struct drm_device * dev);
-extern int mga_driver_dma_quiescent(struct drm_device * dev);
-
-extern int mga_do_wait_for_idle(drm_mga_private_t * dev_priv);
-
-extern void mga_do_dma_flush(drm_mga_private_t * dev_priv);
-extern void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv);
-extern void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv);
-
-extern int mga_freelist_put(struct drm_device * dev, struct drm_buf * buf);
-
-                               /* mga_warp.c */
-extern unsigned int mga_warp_microcode_size(const drm_mga_private_t * dev_priv);
-extern int mga_warp_install_microcode(drm_mga_private_t * dev_priv);
-extern int mga_warp_init(drm_mga_private_t * dev_priv);
-
-                               /* mga_irq.c */
-extern int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence);
-extern int mga_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
-extern irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS);
-extern void mga_driver_irq_preinstall(struct drm_device * dev);
-extern void mga_driver_irq_postinstall(struct drm_device * dev);
-extern void mga_driver_irq_uninstall(struct drm_device * dev);
-extern long mga_compat_ioctl(struct file *filp, unsigned int cmd,
-                            unsigned long arg);
-
-#define mga_flush_write_combine()      DRM_WRITEMEMORYBARRIER()
-
-#if defined(__linux__) && defined(__alpha__)
-#define MGA_BASE( reg )                ((unsigned long)(dev_priv->mmio->handle))
-#define MGA_ADDR( reg )                (MGA_BASE(reg) + reg)
-
-#define MGA_DEREF( reg )       *(volatile u32 *)MGA_ADDR( reg )
-#define MGA_DEREF8( reg )      *(volatile u8 *)MGA_ADDR( reg )
-
-#define MGA_READ( reg )                (_MGA_READ((u32 *)MGA_ADDR(reg)))
-#define MGA_READ8( reg )       (_MGA_READ((u8 *)MGA_ADDR(reg)))
-#define MGA_WRITE( reg, val )  do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF( reg ) = val; } while (0)
-#define MGA_WRITE8( reg, val )  do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF8( reg ) = val; } while (0)
-
-static inline u32 _MGA_READ(u32 * addr)
-{
-       DRM_MEMORYBARRIER();
-       return *(volatile u32 *)addr;
-}
-#else
-#define MGA_READ8( reg )       DRM_READ8(dev_priv->mmio, (reg))
-#define MGA_READ( reg )                DRM_READ32(dev_priv->mmio, (reg))
-#define MGA_WRITE8( reg, val )  DRM_WRITE8(dev_priv->mmio, (reg), (val))
-#define MGA_WRITE( reg, val )  DRM_WRITE32(dev_priv->mmio, (reg), (val))
-#endif
-
-#define DWGREG0                0x1c00
-#define DWGREG0_END    0x1dff
-#define DWGREG1                0x2c00
-#define DWGREG1_END    0x2dff
-
-#define ISREG0(r)      (r >= DWGREG0 && r <= DWGREG0_END)
-#define DMAREG0(r)     (u8)((r - DWGREG0) >> 2)
-#define DMAREG1(r)     (u8)(((r - DWGREG1) >> 2) | 0x80)
-#define DMAREG(r)      (ISREG0(r) ? DMAREG0(r) : DMAREG1(r))
-
-/* ================================================================
- * Helper macross...
- */
-
-#define MGA_EMIT_STATE( dev_priv, dirty )                              \
-do {                                                                   \
-       if ( (dirty) & ~MGA_UPLOAD_CLIPRECTS ) {                        \
-               if ( dev_priv->chipset >= MGA_CARD_TYPE_G400 ) {        \
-                       mga_g400_emit_state( dev_priv );                \
-               } else {                                                \
-                       mga_g200_emit_state( dev_priv );                \
-               }                                                       \
-       }                                                               \
-} while (0)
-
-#define WRAP_TEST_WITH_RETURN( dev_priv )                              \
-do {                                                                   \
-       if ( test_bit( 0, &dev_priv->prim.wrapped ) ) {                 \
-               if ( mga_is_idle( dev_priv ) ) {                        \
-                       mga_do_dma_wrap_end( dev_priv );                \
-               } else if ( dev_priv->prim.space <                      \
-                           dev_priv->prim.high_mark ) {                \
-                       if ( MGA_DMA_DEBUG )                            \
-                               DRM_INFO( "wrap...\n");         \
-                       return -EBUSY;                  \
-               }                                                       \
-       }                                                               \
-} while (0)
-
-#define WRAP_WAIT_WITH_RETURN( dev_priv )                              \
-do {                                                                   \
-       if ( test_bit( 0, &dev_priv->prim.wrapped ) ) {                 \
-               if ( mga_do_wait_for_idle( dev_priv ) < 0 ) {           \
-                       if ( MGA_DMA_DEBUG )                            \
-                               DRM_INFO( "wrap...\n");         \
-                       return -EBUSY;                  \
-               }                                                       \
-               mga_do_dma_wrap_end( dev_priv );                        \
-       }                                                               \
-} while (0)
-
-/* ================================================================
- * Primary DMA command stream
- */
-
-#define MGA_VERBOSE    0
-
-#define DMA_LOCALS     unsigned int write; volatile u8 *prim;
-
-#define DMA_BLOCK_SIZE (5 * sizeof(u32))
-
-#define BEGIN_DMA( n )                                                 \
-do {                                                                   \
-       if ( MGA_VERBOSE ) {                                            \
-               DRM_INFO( "BEGIN_DMA( %d )\n", (n) );           \
-               DRM_INFO( "   space=0x%x req=0x%Zx\n",                  \
-                         dev_priv->prim.space, (n) * DMA_BLOCK_SIZE ); \
-       }                                                               \
-       prim = dev_priv->prim.start;                                    \
-       write = dev_priv->prim.tail;                                    \
-} while (0)
-
-#define BEGIN_DMA_WRAP()                                               \
-do {                                                                   \
-       if ( MGA_VERBOSE ) {                                            \
-               DRM_INFO( "BEGIN_DMA()\n" );                            \
-               DRM_INFO( "   space=0x%x\n", dev_priv->prim.space );    \
-       }                                                               \
-       prim = dev_priv->prim.start;                                    \
-       write = dev_priv->prim.tail;                                    \
-} while (0)
-
-#define ADVANCE_DMA()                                                  \
-do {                                                                   \
-       dev_priv->prim.tail = write;                                    \
-       if ( MGA_VERBOSE ) {                                            \
-               DRM_INFO( "ADVANCE_DMA() tail=0x%05x sp=0x%x\n",        \
-                         write, dev_priv->prim.space );                \
-       }                                                               \
-} while (0)
-
-#define FLUSH_DMA()                                                    \
-do {                                                                   \
-       if ( 0 ) {                                                      \
-               DRM_INFO( "\n" );                                       \
-               DRM_INFO( "   tail=0x%06x head=0x%06lx\n",              \
-                         dev_priv->prim.tail,                          \
-                         MGA_READ( MGA_PRIMADDRESS ) -                 \
-                         dev_priv->primary->offset );                  \
-       }                                                               \
-       if ( !test_bit( 0, &dev_priv->prim.wrapped ) ) {                \
-               if ( dev_priv->prim.space <                             \
-                    dev_priv->prim.high_mark ) {                       \
-                       mga_do_dma_wrap_start( dev_priv );              \
-               } else {                                                \
-                       mga_do_dma_flush( dev_priv );                   \
-               }                                                       \
-       }                                                               \
-} while (0)
-
-/* Never use this, always use DMA_BLOCK(...) for primary DMA output.
- */
-#define DMA_WRITE( offset, val )                                       \
-do {                                                                   \
-       if ( MGA_VERBOSE ) {                                            \
-               DRM_INFO( "   DMA_WRITE( 0x%08x ) at 0x%04Zx\n",        \
-                         (u32)(val), write + (offset) * sizeof(u32) ); \
-       }                                                               \
-       *(volatile u32 *)(prim + write + (offset) * sizeof(u32)) = val; \
-} while (0)
-
-#define DMA_BLOCK( reg0, val0, reg1, val1, reg2, val2, reg3, val3 )    \
-do {                                                                   \
-       DMA_WRITE( 0, ((DMAREG( reg0 ) << 0) |                          \
-                      (DMAREG( reg1 ) << 8) |                          \
-                      (DMAREG( reg2 ) << 16) |                         \
-                      (DMAREG( reg3 ) << 24)) );                       \
-       DMA_WRITE( 1, val0 );                                           \
-       DMA_WRITE( 2, val1 );                                           \
-       DMA_WRITE( 3, val2 );                                           \
-       DMA_WRITE( 4, val3 );                                           \
-       write += DMA_BLOCK_SIZE;                                        \
-} while (0)
-
-/* Buffer aging via primary DMA stream head pointer.
- */
-
-#define SET_AGE( age, h, w )                                           \
-do {                                                                   \
-       (age)->head = h;                                                \
-       (age)->wrap = w;                                                \
-} while (0)
-
-#define TEST_AGE( age, h, w )          ( (age)->wrap < w ||            \
-                                         ( (age)->wrap == w &&         \
-                                           (age)->head < h ) )
-
-#define AGE_BUFFER( buf_priv )                                         \
-do {                                                                   \
-       drm_mga_freelist_t *entry = (buf_priv)->list_entry;             \
-       if ( (buf_priv)->dispatched ) {                                 \
-               entry->age.head = (dev_priv->prim.tail +                \
-                                  dev_priv->primary->offset);          \
-               entry->age.wrap = dev_priv->sarea_priv->last_wrap;      \
-       } else {                                                        \
-               entry->age.head = 0;                                    \
-               entry->age.wrap = 0;                                    \
-       }                                                               \
-} while (0)
-
-#define MGA_ENGINE_IDLE_MASK           (MGA_SOFTRAPEN |                \
-                                        MGA_DWGENGSTS |                \
-                                        MGA_ENDPRDMASTS)
-#define MGA_DMA_IDLE_MASK              (MGA_SOFTRAPEN |                \
-                                        MGA_ENDPRDMASTS)
-
-#define MGA_DMA_DEBUG                  0
-
-/* A reduced set of the mga registers.
- */
-#define MGA_CRTC_INDEX                 0x1fd4
-#define MGA_CRTC_DATA                  0x1fd5
-
-/* CRTC11 */
-#define MGA_VINTCLR                    (1 << 4)
-#define MGA_VINTEN                     (1 << 5)
-
-#define MGA_ALPHACTRL                  0x2c7c
-#define MGA_AR0                                0x1c60
-#define MGA_AR1                                0x1c64
-#define MGA_AR2                                0x1c68
-#define MGA_AR3                                0x1c6c
-#define MGA_AR4                                0x1c70
-#define MGA_AR5                                0x1c74
-#define MGA_AR6                                0x1c78
-
-#define MGA_CXBNDRY                    0x1c80
-#define MGA_CXLEFT                     0x1ca0
-#define MGA_CXRIGHT                    0x1ca4
-
-#define MGA_DMAPAD                     0x1c54
-#define MGA_DSTORG                     0x2cb8
-#define MGA_DWGCTL                     0x1c00
-#      define MGA_OPCOD_MASK                   (15 << 0)
-#      define MGA_OPCOD_TRAP                   (4 << 0)
-#      define MGA_OPCOD_TEXTURE_TRAP           (6 << 0)
-#      define MGA_OPCOD_BITBLT                 (8 << 0)
-#      define MGA_OPCOD_ILOAD                  (9 << 0)
-#      define MGA_ATYPE_MASK                   (7 << 4)
-#      define MGA_ATYPE_RPL                    (0 << 4)
-#      define MGA_ATYPE_RSTR                   (1 << 4)
-#      define MGA_ATYPE_ZI                     (3 << 4)
-#      define MGA_ATYPE_BLK                    (4 << 4)
-#      define MGA_ATYPE_I                      (7 << 4)
-#      define MGA_LINEAR                       (1 << 7)
-#      define MGA_ZMODE_MASK                   (7 << 8)
-#      define MGA_ZMODE_NOZCMP                 (0 << 8)
-#      define MGA_ZMODE_ZE                     (2 << 8)
-#      define MGA_ZMODE_ZNE                    (3 << 8)
-#      define MGA_ZMODE_ZLT                    (4 << 8)
-#      define MGA_ZMODE_ZLTE                   (5 << 8)
-#      define MGA_ZMODE_ZGT                    (6 << 8)
-#      define MGA_ZMODE_ZGTE                   (7 << 8)
-#      define MGA_SOLID                        (1 << 11)
-#      define MGA_ARZERO                       (1 << 12)
-#      define MGA_SGNZERO                      (1 << 13)
-#      define MGA_SHIFTZERO                    (1 << 14)
-#      define MGA_BOP_MASK                     (15 << 16)
-#      define MGA_BOP_ZERO                     (0 << 16)
-#      define MGA_BOP_DST                      (10 << 16)
-#      define MGA_BOP_SRC                      (12 << 16)
-#      define MGA_BOP_ONE                      (15 << 16)
-#      define MGA_TRANS_SHIFT                  20
-#      define MGA_TRANS_MASK                   (15 << 20)
-#      define MGA_BLTMOD_MASK                  (15 << 25)
-#      define MGA_BLTMOD_BMONOLEF              (0 << 25)
-#      define MGA_BLTMOD_BMONOWF               (4 << 25)
-#      define MGA_BLTMOD_PLAN                  (1 << 25)
-#      define MGA_BLTMOD_BFCOL                 (2 << 25)
-#      define MGA_BLTMOD_BU32BGR               (3 << 25)
-#      define MGA_BLTMOD_BU32RGB               (7 << 25)
-#      define MGA_BLTMOD_BU24BGR               (11 << 25)
-#      define MGA_BLTMOD_BU24RGB               (15 << 25)
-#      define MGA_PATTERN                      (1 << 29)
-#      define MGA_TRANSC                       (1 << 30)
-#      define MGA_CLIPDIS                      (1 << 31)
-#define MGA_DWGSYNC                    0x2c4c
-
-#define MGA_FCOL                       0x1c24
-#define MGA_FIFOSTATUS                 0x1e10
-#define MGA_FOGCOL                     0x1cf4
-#define MGA_FXBNDRY                    0x1c84
-#define MGA_FXLEFT                     0x1ca8
-#define MGA_FXRIGHT                    0x1cac
-
-#define MGA_ICLEAR                     0x1e18
-#      define MGA_SOFTRAPICLR                  (1 << 0)
-#      define MGA_VLINEICLR                    (1 << 5)
-#define MGA_IEN                                0x1e1c
-#      define MGA_SOFTRAPIEN                   (1 << 0)
-#      define MGA_VLINEIEN                     (1 << 5)
-
-#define MGA_LEN                                0x1c5c
-
-#define MGA_MACCESS                    0x1c04
-
-#define MGA_PITCH                      0x1c8c
-#define MGA_PLNWT                      0x1c1c
-#define MGA_PRIMADDRESS                        0x1e58
-#      define MGA_DMA_GENERAL                  (0 << 0)
-#      define MGA_DMA_BLIT                     (1 << 0)
-#      define MGA_DMA_VECTOR                   (2 << 0)
-#      define MGA_DMA_VERTEX                   (3 << 0)
-#define MGA_PRIMEND                    0x1e5c
-#      define MGA_PRIMNOSTART                  (1 << 0)
-#      define MGA_PAGPXFER                     (1 << 1)
-#define MGA_PRIMPTR                    0x1e50
-#      define MGA_PRIMPTREN0                   (1 << 0)
-#      define MGA_PRIMPTREN1                   (1 << 1)
-
-#define MGA_RST                                0x1e40
-#      define MGA_SOFTRESET                    (1 << 0)
-#      define MGA_SOFTEXTRST                   (1 << 1)
-
-#define MGA_SECADDRESS                 0x2c40
-#define MGA_SECEND                     0x2c44
-#define MGA_SETUPADDRESS               0x2cd0
-#define MGA_SETUPEND                   0x2cd4
-#define MGA_SGN                                0x1c58
-#define MGA_SOFTRAP                    0x2c48
-#define MGA_SRCORG                     0x2cb4
-#      define MGA_SRMMAP_MASK                  (1 << 0)
-#      define MGA_SRCMAP_FB                    (0 << 0)
-#      define MGA_SRCMAP_SYSMEM                (1 << 0)
-#      define MGA_SRCACC_MASK                  (1 << 1)
-#      define MGA_SRCACC_PCI                   (0 << 1)
-#      define MGA_SRCACC_AGP                   (1 << 1)
-#define MGA_STATUS                     0x1e14
-#      define MGA_SOFTRAPEN                    (1 << 0)
-#      define MGA_VSYNCPEN                     (1 << 4)
-#      define MGA_VLINEPEN                     (1 << 5)
-#      define MGA_DWGENGSTS                    (1 << 16)
-#      define MGA_ENDPRDMASTS                  (1 << 17)
-#define MGA_STENCIL                    0x2cc8
-#define MGA_STENCILCTL                 0x2ccc
-
-#define MGA_TDUALSTAGE0                        0x2cf8
-#define MGA_TDUALSTAGE1                        0x2cfc
-#define MGA_TEXBORDERCOL               0x2c5c
-#define MGA_TEXCTL                     0x2c30
-#define MGA_TEXCTL2                    0x2c3c
-#      define MGA_DUALTEX                      (1 << 7)
-#      define MGA_G400_TC2_MAGIC               (1 << 15)
-#      define MGA_MAP1_ENABLE                  (1 << 31)
-#define MGA_TEXFILTER                  0x2c58
-#define MGA_TEXHEIGHT                  0x2c2c
-#define MGA_TEXORG                     0x2c24
-#      define MGA_TEXORGMAP_MASK               (1 << 0)
-#      define MGA_TEXORGMAP_FB                 (0 << 0)
-#      define MGA_TEXORGMAP_SYSMEM             (1 << 0)
-#      define MGA_TEXORGACC_MASK               (1 << 1)
-#      define MGA_TEXORGACC_PCI                (0 << 1)
-#      define MGA_TEXORGACC_AGP                (1 << 1)
-#define MGA_TEXORG1                    0x2ca4
-#define MGA_TEXORG2                    0x2ca8
-#define MGA_TEXORG3                    0x2cac
-#define MGA_TEXORG4                    0x2cb0
-#define MGA_TEXTRANS                   0x2c34
-#define MGA_TEXTRANSHIGH               0x2c38
-#define MGA_TEXWIDTH                   0x2c28
-
-#define MGA_WACCEPTSEQ                 0x1dd4
-#define MGA_WCODEADDR                  0x1e6c
-#define MGA_WFLAG                      0x1dc4
-#define MGA_WFLAG1                     0x1de0
-#define MGA_WFLAGNB                    0x1e64
-#define MGA_WFLAGNB1                   0x1e08
-#define MGA_WGETMSB                    0x1dc8
-#define MGA_WIADDR                     0x1dc0
-#define MGA_WIADDR2                    0x1dd8
-#      define MGA_WMODE_SUSPEND                (0 << 0)
-#      define MGA_WMODE_RESUME                 (1 << 0)
-#      define MGA_WMODE_JUMP                   (2 << 0)
-#      define MGA_WMODE_START                  (3 << 0)
-#      define MGA_WAGP_ENABLE                  (1 << 2)
-#define MGA_WMISC                      0x1e70
-#      define MGA_WUCODECACHE_ENABLE           (1 << 0)
-#      define MGA_WMASTER_ENABLE               (1 << 1)
-#      define MGA_WCACHEFLUSH_ENABLE           (1 << 3)
-#define MGA_WVRTXSZ                    0x1dcc
-
-#define MGA_YBOT                       0x1c9c
-#define MGA_YDST                       0x1c90
-#define MGA_YDSTLEN                    0x1c88
-#define MGA_YDSTORG                    0x1c94
-#define MGA_YTOP                       0x1c98
-
-#define MGA_ZORG                       0x1c0c
-
-/* This finishes the current batch of commands
- */
-#define MGA_EXEC                       0x0100
-
-/* AGP PLL encoding (for G200 only).
- */
-#define MGA_AGP_PLL                    0x1e4c
-#      define MGA_AGP2XPLL_DISABLE             (0 << 0)
-#      define MGA_AGP2XPLL_ENABLE              (1 << 0)
-
-/* Warp registers
- */
-#define MGA_WR0                                0x2d00
-#define MGA_WR1                                0x2d04
-#define MGA_WR2                                0x2d08
-#define MGA_WR3                                0x2d0c
-#define MGA_WR4                                0x2d10
-#define MGA_WR5                                0x2d14
-#define MGA_WR6                                0x2d18
-#define MGA_WR7                                0x2d1c
-#define MGA_WR8                                0x2d20
-#define MGA_WR9                                0x2d24
-#define MGA_WR10                       0x2d28
-#define MGA_WR11                       0x2d2c
-#define MGA_WR12                       0x2d30
-#define MGA_WR13                       0x2d34
-#define MGA_WR14                       0x2d38
-#define MGA_WR15                       0x2d3c
-#define MGA_WR16                       0x2d40
-#define MGA_WR17                       0x2d44
-#define MGA_WR18                       0x2d48
-#define MGA_WR19                       0x2d4c
-#define MGA_WR20                       0x2d50
-#define MGA_WR21                       0x2d54
-#define MGA_WR22                       0x2d58
-#define MGA_WR23                       0x2d5c
-#define MGA_WR24                       0x2d60
-#define MGA_WR25                       0x2d64
-#define MGA_WR26                       0x2d68
-#define MGA_WR27                       0x2d6c
-#define MGA_WR28                       0x2d70
-#define MGA_WR29                       0x2d74
-#define MGA_WR30                       0x2d78
-#define MGA_WR31                       0x2d7c
-#define MGA_WR32                       0x2d80
-#define MGA_WR33                       0x2d84
-#define MGA_WR34                       0x2d88
-#define MGA_WR35                       0x2d8c
-#define MGA_WR36                       0x2d90
-#define MGA_WR37                       0x2d94
-#define MGA_WR38                       0x2d98
-#define MGA_WR39                       0x2d9c
-#define MGA_WR40                       0x2da0
-#define MGA_WR41                       0x2da4
-#define MGA_WR42                       0x2da8
-#define MGA_WR43                       0x2dac
-#define MGA_WR44                       0x2db0
-#define MGA_WR45                       0x2db4
-#define MGA_WR46                       0x2db8
-#define MGA_WR47                       0x2dbc
-#define MGA_WR48                       0x2dc0
-#define MGA_WR49                       0x2dc4
-#define MGA_WR50                       0x2dc8
-#define MGA_WR51                       0x2dcc
-#define MGA_WR52                       0x2dd0
-#define MGA_WR53                       0x2dd4
-#define MGA_WR54                       0x2dd8
-#define MGA_WR55                       0x2ddc
-#define MGA_WR56                       0x2de0
-#define MGA_WR57                       0x2de4
-#define MGA_WR58                       0x2de8
-#define MGA_WR59                       0x2dec
-#define MGA_WR60                       0x2df0
-#define MGA_WR61                       0x2df4
-#define MGA_WR62                       0x2df8
-#define MGA_WR63                       0x2dfc
-#      define MGA_G400_WR_MAGIC                (1 << 6)
-#      define MGA_G400_WR56_MAGIC              0x46480000      /* 12800.0f */
-
-#define MGA_ILOAD_ALIGN                64
-#define MGA_ILOAD_MASK         (MGA_ILOAD_ALIGN - 1)
-
-#define MGA_DWGCTL_FLUSH       (MGA_OPCOD_TEXTURE_TRAP |               \
-                                MGA_ATYPE_I |                          \
-                                MGA_ZMODE_NOZCMP |                     \
-                                MGA_ARZERO |                           \
-                                MGA_SGNZERO |                          \
-                                MGA_BOP_SRC |                          \
-                                (15 << MGA_TRANS_SHIFT))
-
-#define MGA_DWGCTL_CLEAR       (MGA_OPCOD_TRAP |                       \
-                                MGA_ZMODE_NOZCMP |                     \
-                                MGA_SOLID |                            \
-                                MGA_ARZERO |                           \
-                                MGA_SGNZERO |                          \
-                                MGA_SHIFTZERO |                        \
-                                MGA_BOP_SRC |                          \
-                                (0 << MGA_TRANS_SHIFT) |               \
-                                MGA_BLTMOD_BMONOLEF |                  \
-                                MGA_TRANSC |                           \
-                                MGA_CLIPDIS)
-
-#define MGA_DWGCTL_COPY                (MGA_OPCOD_BITBLT |                     \
-                                MGA_ATYPE_RPL |                        \
-                                MGA_SGNZERO |                          \
-                                MGA_SHIFTZERO |                        \
-                                MGA_BOP_SRC |                          \
-                                (0 << MGA_TRANS_SHIFT) |               \
-                                MGA_BLTMOD_BFCOL |                     \
-                                MGA_CLIPDIS)
-
-/* Simple idle test.
- */
-static __inline__ int mga_is_idle(drm_mga_private_t * dev_priv)
-{
-       u32 status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
-       return (status == MGA_ENDPRDMASTS);
-}
-
-#endif
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c
deleted file mode 100644 (file)
index 30d0047..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/**
- * \file mga_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the MGA DRM.
- *
- * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
- *
- *
- * Copyright (C) Paul Mackerras 2005
- * Copyright (C) Egbert Eich 2003,2004
- * Copyright (C) Dave Airlie 2005
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include "drmP.h"
-#include "drm.h"
-#include "mga_drm.h"
-
-typedef struct drm32_mga_init {
-       int func;
-       u32 sarea_priv_offset;
-       int chipset;
-       int sgram;
-       unsigned int maccess;
-       unsigned int fb_cpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_cpp;
-       unsigned int depth_offset, depth_pitch;
-       unsigned int texture_offset[MGA_NR_TEX_HEAPS];
-       unsigned int texture_size[MGA_NR_TEX_HEAPS];
-       u32 fb_offset;
-       u32 mmio_offset;
-       u32 status_offset;
-       u32 warp_offset;
-       u32 primary_offset;
-       u32 buffers_offset;
-} drm_mga_init32_t;
-
-static int compat_mga_init(struct file *file, unsigned int cmd,
-                          unsigned long arg)
-{
-       drm_mga_init32_t init32;
-       drm_mga_init_t __user *init;
-       int err = 0, i;
-
-       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
-               return -EFAULT;
-
-       init = compat_alloc_user_space(sizeof(*init));
-       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
-           || __put_user(init32.func, &init->func)
-           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
-           || __put_user(init32.chipset, &init->chipset)
-           || __put_user(init32.sgram, &init->sgram)
-           || __put_user(init32.maccess, &init->maccess)
-           || __put_user(init32.fb_cpp, &init->fb_cpp)
-           || __put_user(init32.front_offset, &init->front_offset)
-           || __put_user(init32.front_pitch, &init->front_pitch)
-           || __put_user(init32.back_offset, &init->back_offset)
-           || __put_user(init32.back_pitch, &init->back_pitch)
-           || __put_user(init32.depth_cpp, &init->depth_cpp)
-           || __put_user(init32.depth_offset, &init->depth_offset)
-           || __put_user(init32.depth_pitch, &init->depth_pitch)
-           || __put_user(init32.fb_offset, &init->fb_offset)
-           || __put_user(init32.mmio_offset, &init->mmio_offset)
-           || __put_user(init32.status_offset, &init->status_offset)
-           || __put_user(init32.warp_offset, &init->warp_offset)
-           || __put_user(init32.primary_offset, &init->primary_offset)
-           || __put_user(init32.buffers_offset, &init->buffers_offset))
-               return -EFAULT;
-
-       for (i = 0; i < MGA_NR_TEX_HEAPS; i++) {
-               err |=
-                   __put_user(init32.texture_offset[i],
-                              &init->texture_offset[i]);
-               err |=
-                   __put_user(init32.texture_size[i], &init->texture_size[i]);
-       }
-       if (err)
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_MGA_INIT, (unsigned long)init);
-}
-
-typedef struct drm_mga_getparam32 {
-       int param;
-       u32 value;
-} drm_mga_getparam32_t;
-
-static int compat_mga_getparam(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_mga_getparam32_t getparam32;
-       drm_mga_getparam_t __user *getparam;
-
-       if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
-               return -EFAULT;
-
-       getparam = compat_alloc_user_space(sizeof(*getparam));
-       if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
-           || __put_user(getparam32.param, &getparam->param)
-           || __put_user((void __user *)(unsigned long)getparam32.value,
-                         &getparam->value))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
-}
-
-typedef struct drm_mga_drm_bootstrap32 {
-       u32 texture_handle;
-       u32 texture_size;
-       u32 primary_size;
-       u32 secondary_bin_count;
-       u32 secondary_bin_size;
-       u32 agp_mode;
-       u8 agp_size;
-} drm_mga_dma_bootstrap32_t;
-
-static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
-                                   unsigned long arg)
-{
-       drm_mga_dma_bootstrap32_t dma_bootstrap32;
-       drm_mga_dma_bootstrap_t __user *dma_bootstrap;
-       int err;
-
-       if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
-                          sizeof(dma_bootstrap32)))
-               return -EFAULT;
-
-       dma_bootstrap = compat_alloc_user_space(sizeof(*dma_bootstrap));
-       if (!access_ok(VERIFY_WRITE, dma_bootstrap, sizeof(*dma_bootstrap))
-           || __put_user(dma_bootstrap32.texture_handle,
-                         &dma_bootstrap->texture_handle)
-           || __put_user(dma_bootstrap32.texture_size,
-                         &dma_bootstrap->texture_size)
-           || __put_user(dma_bootstrap32.primary_size,
-                         &dma_bootstrap->primary_size)
-           || __put_user(dma_bootstrap32.secondary_bin_count,
-                         &dma_bootstrap->secondary_bin_count)
-           || __put_user(dma_bootstrap32.secondary_bin_size,
-                         &dma_bootstrap->secondary_bin_size)
-           || __put_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
-           || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
-               return -EFAULT;
-
-       err = drm_ioctl(file->f_path.dentry->d_inode, file,
-                       DRM_IOCTL_MGA_DMA_BOOTSTRAP,
-                       (unsigned long)dma_bootstrap);
-       if (err)
-               return err;
-
-       if (__get_user(dma_bootstrap32.texture_handle,
-                      &dma_bootstrap->texture_handle)
-           || __get_user(dma_bootstrap32.texture_size,
-                         &dma_bootstrap->texture_size)
-           || __get_user(dma_bootstrap32.primary_size,
-                         &dma_bootstrap->primary_size)
-           || __get_user(dma_bootstrap32.secondary_bin_count,
-                         &dma_bootstrap->secondary_bin_count)
-           || __get_user(dma_bootstrap32.secondary_bin_size,
-                         &dma_bootstrap->secondary_bin_size)
-           || __get_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
-           || __get_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
-               return -EFAULT;
-
-       if (copy_to_user((void __user *)arg, &dma_bootstrap32,
-                        sizeof(dma_bootstrap32)))
-               return -EFAULT;
-
-       return 0;
-}
-
-drm_ioctl_compat_t *mga_compat_ioctls[] = {
-       [DRM_MGA_INIT] = compat_mga_init,
-       [DRM_MGA_GETPARAM] = compat_mga_getparam,
-       [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
-};
-
-/**
- * Called whenever a 32-bit process running under a 64-bit kernel
- * performs an ioctl on /dev/dri/card<n>.
- *
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- */
-long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       drm_ioctl_compat_t *fn = NULL;
-       int ret;
-
-       if (nr < DRM_COMMAND_BASE)
-               return drm_compat_ioctl(filp, cmd, arg);
-
-       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
-               fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
-
-       lock_kernel();          /* XXX for now */
-       if (fn != NULL)
-               ret = (*fn) (filp, cmd, arg);
-       else
-               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
-       unlock_kernel();
-
-       return ret;
-}
diff --git a/drivers/char/drm/mga_irq.c b/drivers/char/drm/mga_irq.c
deleted file mode 100644 (file)
index 9302cb8..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/* mga_irq.c -- IRQ handling for radeon -*- linux-c -*-
- *
- * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
- *
- * The Weather Channel (TM) funded Tungsten Graphics to develop the
- * initial release of the Radeon 8500 driver under the XFree86 license.
- * This notice must be preserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
- *    Eric Anholt <anholt@FreeBSD.org>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "mga_drm.h"
-#include "mga_drv.h"
-
-irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-       int status;
-       int handled = 0;
-
-       status = MGA_READ(MGA_STATUS);
-
-       /* VBLANK interrupt */
-       if (status & MGA_VLINEPEN) {
-               MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
-               atomic_inc(&dev->vbl_received);
-               DRM_WAKEUP(&dev->vbl_queue);
-               drm_vbl_send_signals(dev);
-               handled = 1;
-       }
-
-       /* SOFTRAP interrupt */
-       if (status & MGA_SOFTRAPEN) {
-               const u32 prim_start = MGA_READ(MGA_PRIMADDRESS);
-               const u32 prim_end = MGA_READ(MGA_PRIMEND);
-
-               MGA_WRITE(MGA_ICLEAR, MGA_SOFTRAPICLR);
-
-               /* In addition to clearing the interrupt-pending bit, we
-                * have to write to MGA_PRIMEND to re-start the DMA operation.
-                */
-               if ((prim_start & ~0x03) != (prim_end & ~0x03)) {
-                       MGA_WRITE(MGA_PRIMEND, prim_end);
-               }
-
-               atomic_inc(&dev_priv->last_fence_retired);
-               DRM_WAKEUP(&dev_priv->fence_queue);
-               handled = 1;
-       }
-
-       if (handled) {
-               return IRQ_HANDLED;
-       }
-       return IRQ_NONE;
-}
-
-int mga_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
-{
-       unsigned int cur_vblank;
-       int ret = 0;
-
-       /* Assume that the user has missed the current sequence number
-        * by about a day rather than she wants to wait for years
-        * using vertical blanks...
-        */
-       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
-                   (((cur_vblank = atomic_read(&dev->vbl_received))
-                     - *sequence) <= (1 << 23)));
-
-       *sequence = cur_vblank;
-
-       return ret;
-}
-
-int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-       unsigned int cur_fence;
-       int ret = 0;
-
-       /* Assume that the user has missed the current sequence number
-        * by about a day rather than she wants to wait for years
-        * using fences.
-        */
-       DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
-                   (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
-                     - *sequence) <= (1 << 23)));
-
-       *sequence = cur_fence;
-
-       return ret;
-}
-
-void mga_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-
-       /* Disable *all* interrupts */
-       MGA_WRITE(MGA_IEN, 0);
-       /* Clear bits if they're already high */
-       MGA_WRITE(MGA_ICLEAR, ~0);
-}
-
-void mga_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-
-       DRM_INIT_WAITQUEUE(&dev_priv->fence_queue);
-
-       /* Turn on vertical blank interrupt and soft trap interrupt. */
-       MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN);
-}
-
-void mga_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
-       if (!dev_priv)
-               return;
-
-       /* Disable *all* interrupts */
-       MGA_WRITE(MGA_IEN, 0);
-
-       dev->irq_enabled = 0;
-}
diff --git a/drivers/char/drm/mga_state.c b/drivers/char/drm/mga_state.c
deleted file mode 100644 (file)
index d3f8aad..0000000
+++ /dev/null
@@ -1,1104 +0,0 @@
-/* mga_state.c -- State support for MGA G200/G400 -*- linux-c -*-
- * Created: Thu Jan 27 02:53:43 2000 by jhartmann@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Jeff Hartmann <jhartmann@valinux.com>
- *    Keith Whitwell <keith@tungstengraphics.com>
- *
- * Rewritten by:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "mga_drm.h"
-#include "mga_drv.h"
-
-/* ================================================================
- * DMA hardware state programming functions
- */
-
-static void mga_emit_clip_rect(drm_mga_private_t * dev_priv,
-                              struct drm_clip_rect * box)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       unsigned int pitch = dev_priv->front_pitch;
-       DMA_LOCALS;
-
-       BEGIN_DMA(2);
-
-       /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
-        */
-       if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
-               DMA_BLOCK(MGA_DWGCTL, ctx->dwgctl,
-                         MGA_LEN + MGA_EXEC, 0x80000000,
-                         MGA_DWGCTL, ctx->dwgctl,
-                         MGA_LEN + MGA_EXEC, 0x80000000);
-       }
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_CXBNDRY, ((box->x2 - 1) << 16) | box->x1,
-                 MGA_YTOP, box->y1 * pitch, MGA_YBOT, (box->y2 - 1) * pitch);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g200_emit_context(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       DMA_LOCALS;
-
-       BEGIN_DMA(3);
-
-       DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
-                 MGA_MACCESS, ctx->maccess,
-                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
-
-       DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
-                 MGA_FOGCOL, ctx->fogcolor,
-                 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
-
-       DMA_BLOCK(MGA_FCOL, ctx->fcol,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g400_emit_context(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       DMA_LOCALS;
-
-       BEGIN_DMA(4);
-
-       DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
-                 MGA_MACCESS, ctx->maccess,
-                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
-
-       DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
-                 MGA_FOGCOL, ctx->fogcolor,
-                 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
-
-       DMA_BLOCK(MGA_WFLAG1, ctx->wflag,
-                 MGA_TDUALSTAGE0, ctx->tdualstage0,
-                 MGA_TDUALSTAGE1, ctx->tdualstage1, MGA_FCOL, ctx->fcol);
-
-       DMA_BLOCK(MGA_STENCIL, ctx->stencil,
-                 MGA_STENCILCTL, ctx->stencilctl,
-                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g200_emit_tex0(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
-       DMA_LOCALS;
-
-       BEGIN_DMA(4);
-
-       DMA_BLOCK(MGA_TEXCTL2, tex->texctl2,
-                 MGA_TEXCTL, tex->texctl,
-                 MGA_TEXFILTER, tex->texfilter,
-                 MGA_TEXBORDERCOL, tex->texbordercol);
-
-       DMA_BLOCK(MGA_TEXORG, tex->texorg,
-                 MGA_TEXORG1, tex->texorg1,
-                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
-
-       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
-                 MGA_TEXWIDTH, tex->texwidth,
-                 MGA_TEXHEIGHT, tex->texheight, MGA_WR24, tex->texwidth);
-
-       DMA_BLOCK(MGA_WR34, tex->texheight,
-                 MGA_TEXTRANS, 0x0000ffff,
-                 MGA_TEXTRANSHIGH, 0x0000ffff, MGA_DMAPAD, 0x00000000);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g400_emit_tex0(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
-       DMA_LOCALS;
-
-/*     printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
-/*            tex->texctl, tex->texctl2); */
-
-       BEGIN_DMA(6);
-
-       DMA_BLOCK(MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC,
-                 MGA_TEXCTL, tex->texctl,
-                 MGA_TEXFILTER, tex->texfilter,
-                 MGA_TEXBORDERCOL, tex->texbordercol);
-
-       DMA_BLOCK(MGA_TEXORG, tex->texorg,
-                 MGA_TEXORG1, tex->texorg1,
-                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
-
-       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
-                 MGA_TEXWIDTH, tex->texwidth,
-                 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
-
-       DMA_BLOCK(MGA_WR57, 0x00000000,
-                 MGA_WR53, 0x00000000,
-                 MGA_WR61, 0x00000000, MGA_WR52, MGA_G400_WR_MAGIC);
-
-       DMA_BLOCK(MGA_WR60, MGA_G400_WR_MAGIC,
-                 MGA_WR54, tex->texwidth | MGA_G400_WR_MAGIC,
-                 MGA_WR62, tex->texheight | MGA_G400_WR_MAGIC,
-                 MGA_DMAPAD, 0x00000000);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_TEXTRANS, 0x0000ffff, MGA_TEXTRANSHIGH, 0x0000ffff);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g400_emit_tex1(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[1];
-       DMA_LOCALS;
-
-/*     printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg,  */
-/*            tex->texctl, tex->texctl2); */
-
-       BEGIN_DMA(5);
-
-       DMA_BLOCK(MGA_TEXCTL2, (tex->texctl2 |
-                               MGA_MAP1_ENABLE |
-                               MGA_G400_TC2_MAGIC),
-                 MGA_TEXCTL, tex->texctl,
-                 MGA_TEXFILTER, tex->texfilter,
-                 MGA_TEXBORDERCOL, tex->texbordercol);
-
-       DMA_BLOCK(MGA_TEXORG, tex->texorg,
-                 MGA_TEXORG1, tex->texorg1,
-                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
-
-       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
-                 MGA_TEXWIDTH, tex->texwidth,
-                 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
-
-       DMA_BLOCK(MGA_WR57, 0x00000000,
-                 MGA_WR53, 0x00000000,
-                 MGA_WR61, 0x00000000,
-                 MGA_WR52, tex->texwidth | MGA_G400_WR_MAGIC);
-
-       DMA_BLOCK(MGA_WR60, tex->texheight | MGA_G400_WR_MAGIC,
-                 MGA_TEXTRANS, 0x0000ffff,
-                 MGA_TEXTRANSHIGH, 0x0000ffff,
-                 MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC);
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g200_emit_pipe(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int pipe = sarea_priv->warp_pipe;
-       DMA_LOCALS;
-
-       BEGIN_DMA(3);
-
-       DMA_BLOCK(MGA_WIADDR, MGA_WMODE_SUSPEND,
-                 MGA_WVRTXSZ, 0x00000007,
-                 MGA_WFLAG, 0x00000000, MGA_WR24, 0x00000000);
-
-       DMA_BLOCK(MGA_WR25, 0x00000100,
-                 MGA_WR34, 0x00000000,
-                 MGA_WR42, 0x0000ffff, MGA_WR60, 0x0000ffff);
-
-       /* Padding required to to hardware bug.
-        */
-       DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
-                 MGA_DMAPAD, 0xffffffff,
-                 MGA_DMAPAD, 0xffffffff,
-                 MGA_WIADDR, (dev_priv->warp_pipe_phys[pipe] |
-                              MGA_WMODE_START | dev_priv->wagp_enable));
-
-       ADVANCE_DMA();
-}
-
-static __inline__ void mga_g400_emit_pipe(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int pipe = sarea_priv->warp_pipe;
-       DMA_LOCALS;
-
-/*     printk("mga_g400_emit_pipe %x\n", pipe); */
-
-       BEGIN_DMA(10);
-
-       DMA_BLOCK(MGA_WIADDR2, MGA_WMODE_SUSPEND,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-       if (pipe & MGA_T2) {
-               DMA_BLOCK(MGA_WVRTXSZ, 0x00001e09,
-                         MGA_DMAPAD, 0x00000000,
-                         MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-               DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x1e000000);
-       } else {
-               if (dev_priv->warp_pipe & MGA_T2) {
-                       /* Flush the WARP pipe */
-                       DMA_BLOCK(MGA_YDST, 0x00000000,
-                                 MGA_FXLEFT, 0x00000000,
-                                 MGA_FXRIGHT, 0x00000001,
-                                 MGA_DWGCTL, MGA_DWGCTL_FLUSH);
-
-                       DMA_BLOCK(MGA_LEN + MGA_EXEC, 0x00000001,
-                                 MGA_DWGSYNC, 0x00007000,
-                                 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
-                                 MGA_LEN + MGA_EXEC, 0x00000000);
-
-                       DMA_BLOCK(MGA_TEXCTL2, (MGA_DUALTEX |
-                                               MGA_G400_TC2_MAGIC),
-                                 MGA_LEN + MGA_EXEC, 0x00000000,
-                                 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
-                                 MGA_DMAPAD, 0x00000000);
-               }
-
-               DMA_BLOCK(MGA_WVRTXSZ, 0x00001807,
-                         MGA_DMAPAD, 0x00000000,
-                         MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
-
-               DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x00000000,
-                         MGA_WACCEPTSEQ, 0x18000000);
-       }
-
-       DMA_BLOCK(MGA_WFLAG, 0x00000000,
-                 MGA_WFLAG1, 0x00000000,
-                 MGA_WR56, MGA_G400_WR56_MAGIC, MGA_DMAPAD, 0x00000000);
-
-       DMA_BLOCK(MGA_WR49, 0x00000000, /* tex0              */
-                 MGA_WR57, 0x00000000, /* tex0              */
-                 MGA_WR53, 0x00000000, /* tex1              */
-                 MGA_WR61, 0x00000000);        /* tex1              */
-
-       DMA_BLOCK(MGA_WR54, MGA_G400_WR_MAGIC,  /* tex0 width        */
-                 MGA_WR62, MGA_G400_WR_MAGIC,  /* tex0 height       */
-                 MGA_WR52, MGA_G400_WR_MAGIC,  /* tex1 width        */
-                 MGA_WR60, MGA_G400_WR_MAGIC); /* tex1 height       */
-
-       /* Padding required to to hardware bug */
-       DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
-                 MGA_DMAPAD, 0xffffffff,
-                 MGA_DMAPAD, 0xffffffff,
-                 MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
-                               MGA_WMODE_START | dev_priv->wagp_enable));
-
-       ADVANCE_DMA();
-}
-
-static void mga_g200_emit_state(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-
-       if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
-               mga_g200_emit_pipe(dev_priv);
-               dev_priv->warp_pipe = sarea_priv->warp_pipe;
-       }
-
-       if (dirty & MGA_UPLOAD_CONTEXT) {
-               mga_g200_emit_context(dev_priv);
-               sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
-       }
-
-       if (dirty & MGA_UPLOAD_TEX0) {
-               mga_g200_emit_tex0(dev_priv);
-               sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
-       }
-}
-
-static void mga_g400_emit_state(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-       int multitex = sarea_priv->warp_pipe & MGA_T2;
-
-       if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
-               mga_g400_emit_pipe(dev_priv);
-               dev_priv->warp_pipe = sarea_priv->warp_pipe;
-       }
-
-       if (dirty & MGA_UPLOAD_CONTEXT) {
-               mga_g400_emit_context(dev_priv);
-               sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
-       }
-
-       if (dirty & MGA_UPLOAD_TEX0) {
-               mga_g400_emit_tex0(dev_priv);
-               sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
-       }
-
-       if ((dirty & MGA_UPLOAD_TEX1) && multitex) {
-               mga_g400_emit_tex1(dev_priv);
-               sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
-       }
-}
-
-/* ================================================================
- * SAREA state verification
- */
-
-/* Disallow all write destinations except the front and backbuffer.
- */
-static int mga_verify_context(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-
-       if (ctx->dstorg != dev_priv->front_offset &&
-           ctx->dstorg != dev_priv->back_offset) {
-               DRM_ERROR("*** bad DSTORG: %x (front %x, back %x)\n\n",
-                         ctx->dstorg, dev_priv->front_offset,
-                         dev_priv->back_offset);
-               ctx->dstorg = 0;
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/* Disallow texture reads from PCI space.
- */
-static int mga_verify_tex(drm_mga_private_t * dev_priv, int unit)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
-       unsigned int org;
-
-       org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
-
-       if (org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI)) {
-               DRM_ERROR("*** bad TEXORG: 0x%x, unit %d\n", tex->texorg, unit);
-               tex->texorg = 0;
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int mga_verify_state(drm_mga_private_t * dev_priv)
-{
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-       int ret = 0;
-
-       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
-
-       if (dirty & MGA_UPLOAD_CONTEXT)
-               ret |= mga_verify_context(dev_priv);
-
-       if (dirty & MGA_UPLOAD_TEX0)
-               ret |= mga_verify_tex(dev_priv, 0);
-
-       if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
-               if (dirty & MGA_UPLOAD_TEX1)
-                       ret |= mga_verify_tex(dev_priv, 1);
-
-               if (dirty & MGA_UPLOAD_PIPE)
-                       ret |= (sarea_priv->warp_pipe > MGA_MAX_G400_PIPES);
-       } else {
-               if (dirty & MGA_UPLOAD_PIPE)
-                       ret |= (sarea_priv->warp_pipe > MGA_MAX_G200_PIPES);
-       }
-
-       return (ret == 0);
-}
-
-static int mga_verify_iload(drm_mga_private_t * dev_priv,
-                           unsigned int dstorg, unsigned int length)
-{
-       if (dstorg < dev_priv->texture_offset ||
-           dstorg + length > (dev_priv->texture_offset +
-                              dev_priv->texture_size)) {
-               DRM_ERROR("*** bad iload DSTORG: 0x%x\n", dstorg);
-               return -EINVAL;
-       }
-
-       if (length & MGA_ILOAD_MASK) {
-               DRM_ERROR("*** bad iload length: 0x%x\n",
-                         length & MGA_ILOAD_MASK);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int mga_verify_blit(drm_mga_private_t * dev_priv,
-                          unsigned int srcorg, unsigned int dstorg)
-{
-       if ((srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
-           (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM)) {
-               DRM_ERROR("*** bad blit: src=0x%x dst=0x%x\n", srcorg, dstorg);
-               return -EINVAL;
-       }
-       return 0;
-}
-
-/* ================================================================
- *
- */
-
-static void mga_dma_dispatch_clear(struct drm_device * dev, drm_mga_clear_t * clear)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int nbox = sarea_priv->nbox;
-       int i;
-       DMA_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_DMA(1);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
-
-       ADVANCE_DMA();
-
-       for (i = 0; i < nbox; i++) {
-               struct drm_clip_rect *box = &pbox[i];
-               u32 height = box->y2 - box->y1;
-
-               DRM_DEBUG("   from=%d,%d to=%d,%d\n",
-                         box->x1, box->y1, box->x2, box->y2);
-
-               if (clear->flags & MGA_FRONT) {
-                       BEGIN_DMA(2);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_PLNWT, clear->color_mask,
-                                 MGA_YDSTLEN, (box->y1 << 16) | height,
-                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_FCOL, clear->clear_color,
-                                 MGA_DSTORG, dev_priv->front_offset,
-                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
-
-                       ADVANCE_DMA();
-               }
-
-               if (clear->flags & MGA_BACK) {
-                       BEGIN_DMA(2);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_PLNWT, clear->color_mask,
-                                 MGA_YDSTLEN, (box->y1 << 16) | height,
-                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_FCOL, clear->clear_color,
-                                 MGA_DSTORG, dev_priv->back_offset,
-                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
-
-                       ADVANCE_DMA();
-               }
-
-               if (clear->flags & MGA_DEPTH) {
-                       BEGIN_DMA(2);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_PLNWT, clear->depth_mask,
-                                 MGA_YDSTLEN, (box->y1 << 16) | height,
-                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_FCOL, clear->clear_depth,
-                                 MGA_DSTORG, dev_priv->depth_offset,
-                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
-
-                       ADVANCE_DMA();
-               }
-
-       }
-
-       BEGIN_DMA(1);
-
-       /* Force reset of DWGCTL */
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
-
-       ADVANCE_DMA();
-
-       FLUSH_DMA();
-}
-
-static void mga_dma_dispatch_swap(struct drm_device * dev)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int nbox = sarea_priv->nbox;
-       int i;
-       DMA_LOCALS;
-       DRM_DEBUG("\n");
-
-       sarea_priv->last_frame.head = dev_priv->prim.tail;
-       sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
-
-       BEGIN_DMA(4 + nbox);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
-
-       DMA_BLOCK(MGA_DSTORG, dev_priv->front_offset,
-                 MGA_MACCESS, dev_priv->maccess,
-                 MGA_SRCORG, dev_priv->back_offset,
-                 MGA_AR5, dev_priv->front_pitch);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_PLNWT, 0xffffffff, MGA_DWGCTL, MGA_DWGCTL_COPY);
-
-       for (i = 0; i < nbox; i++) {
-               struct drm_clip_rect *box = &pbox[i];
-               u32 height = box->y2 - box->y1;
-               u32 start = box->y1 * dev_priv->front_pitch;
-
-               DRM_DEBUG("   from=%d,%d to=%d,%d\n",
-                         box->x1, box->y1, box->x2, box->y2);
-
-               DMA_BLOCK(MGA_AR0, start + box->x2 - 1,
-                         MGA_AR3, start + box->x1,
-                         MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
-                         MGA_YDSTLEN + MGA_EXEC, (box->y1 << 16) | height);
-       }
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_PLNWT, ctx->plnwt,
-                 MGA_SRCORG, dev_priv->front_offset, MGA_DWGCTL, ctx->dwgctl);
-
-       ADVANCE_DMA();
-
-       FLUSH_DMA();
-
-       DRM_DEBUG("... done.\n");
-}
-
-static void mga_dma_dispatch_vertex(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       u32 address = (u32) buf->bus_address;
-       u32 length = (u32) buf->used;
-       int i = 0;
-       DMA_LOCALS;
-       DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
-
-       if (buf->used) {
-               buf_priv->dispatched = 1;
-
-               MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
-
-               do {
-                       if (i < sarea_priv->nbox) {
-                               mga_emit_clip_rect(dev_priv,
-                                                  &sarea_priv->boxes[i]);
-                       }
-
-                       BEGIN_DMA(1);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_DMAPAD, 0x00000000,
-                                 MGA_SECADDRESS, (address |
-                                                  MGA_DMA_VERTEX),
-                                 MGA_SECEND, ((address + length) |
-                                              dev_priv->dma_access));
-
-                       ADVANCE_DMA();
-               } while (++i < sarea_priv->nbox);
-       }
-
-       if (buf_priv->discard) {
-               AGE_BUFFER(buf_priv);
-               buf->pending = 0;
-               buf->used = 0;
-               buf_priv->dispatched = 0;
-
-               mga_freelist_put(dev, buf);
-       }
-
-       FLUSH_DMA();
-}
-
-static void mga_dma_dispatch_indices(struct drm_device * dev, struct drm_buf * buf,
-                                    unsigned int start, unsigned int end)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       u32 address = (u32) buf->bus_address;
-       int i = 0;
-       DMA_LOCALS;
-       DRM_DEBUG("buf=%d start=%d end=%d\n", buf->idx, start, end);
-
-       if (start != end) {
-               buf_priv->dispatched = 1;
-
-               MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
-
-               do {
-                       if (i < sarea_priv->nbox) {
-                               mga_emit_clip_rect(dev_priv,
-                                                  &sarea_priv->boxes[i]);
-                       }
-
-                       BEGIN_DMA(1);
-
-                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                                 MGA_DMAPAD, 0x00000000,
-                                 MGA_SETUPADDRESS, address + start,
-                                 MGA_SETUPEND, ((address + end) |
-                                                dev_priv->dma_access));
-
-                       ADVANCE_DMA();
-               } while (++i < sarea_priv->nbox);
-       }
-
-       if (buf_priv->discard) {
-               AGE_BUFFER(buf_priv);
-               buf->pending = 0;
-               buf->used = 0;
-               buf_priv->dispatched = 0;
-
-               mga_freelist_put(dev, buf);
-       }
-
-       FLUSH_DMA();
-}
-
-/* This copies a 64 byte aligned agp region to the frambuffer with a
- * standard blit, the ioctl needs to do checking.
- */
-static void mga_dma_dispatch_iload(struct drm_device * dev, struct drm_buf * buf,
-                                  unsigned int dstorg, unsigned int length)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
-       drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
-       u32 srcorg =
-           buf->bus_address | dev_priv->dma_access | MGA_SRCMAP_SYSMEM;
-       u32 y2;
-       DMA_LOCALS;
-       DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
-
-       y2 = length / 64;
-
-       BEGIN_DMA(5);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
-
-       DMA_BLOCK(MGA_DSTORG, dstorg,
-                 MGA_MACCESS, 0x00000000, MGA_SRCORG, srcorg, MGA_AR5, 64);
-
-       DMA_BLOCK(MGA_PITCH, 64,
-                 MGA_PLNWT, 0xffffffff,
-                 MGA_DMAPAD, 0x00000000, MGA_DWGCTL, MGA_DWGCTL_COPY);
-
-       DMA_BLOCK(MGA_AR0, 63,
-                 MGA_AR3, 0,
-                 MGA_FXBNDRY, (63 << 16) | 0, MGA_YDSTLEN + MGA_EXEC, y2);
-
-       DMA_BLOCK(MGA_PLNWT, ctx->plnwt,
-                 MGA_SRCORG, dev_priv->front_offset,
-                 MGA_PITCH, dev_priv->front_pitch, MGA_DWGSYNC, 0x00007000);
-
-       ADVANCE_DMA();
-
-       AGE_BUFFER(buf_priv);
-
-       buf->pending = 0;
-       buf->used = 0;
-       buf_priv->dispatched = 0;
-
-       mga_freelist_put(dev, buf);
-
-       FLUSH_DMA();
-}
-
-static void mga_dma_dispatch_blit(struct drm_device * dev, drm_mga_blit_t * blit)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int nbox = sarea_priv->nbox;
-       u32 scandir = 0, i;
-       DMA_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_DMA(4 + nbox);
-
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
-
-       DMA_BLOCK(MGA_DWGCTL, MGA_DWGCTL_COPY,
-                 MGA_PLNWT, blit->planemask,
-                 MGA_SRCORG, blit->srcorg, MGA_DSTORG, blit->dstorg);
-
-       DMA_BLOCK(MGA_SGN, scandir,
-                 MGA_MACCESS, dev_priv->maccess,
-                 MGA_AR5, blit->ydir * blit->src_pitch,
-                 MGA_PITCH, blit->dst_pitch);
-
-       for (i = 0; i < nbox; i++) {
-               int srcx = pbox[i].x1 + blit->delta_sx;
-               int srcy = pbox[i].y1 + blit->delta_sy;
-               int dstx = pbox[i].x1 + blit->delta_dx;
-               int dsty = pbox[i].y1 + blit->delta_dy;
-               int h = pbox[i].y2 - pbox[i].y1;
-               int w = pbox[i].x2 - pbox[i].x1 - 1;
-               int start;
-
-               if (blit->ydir == -1) {
-                       srcy = blit->height - srcy - 1;
-               }
-
-               start = srcy * blit->src_pitch + srcx;
-
-               DMA_BLOCK(MGA_AR0, start + w,
-                         MGA_AR3, start,
-                         MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
-                         MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h);
-       }
-
-       /* Do something to flush AGP?
-        */
-
-       /* Force reset of DWGCTL */
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_PLNWT, ctx->plnwt,
-                 MGA_PITCH, dev_priv->front_pitch, MGA_DWGCTL, ctx->dwgctl);
-
-       ADVANCE_DMA();
-}
-
-/* ================================================================
- *
- */
-
-static int mga_dma_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_clear_t *clear = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_clear(dev, clear);
-
-       /* Make sure we restore the 3D state next time.
-        */
-       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
-
-       return 0;
-}
-
-static int mga_dma_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_swap(dev);
-
-       /* Make sure we restore the 3D state next time.
-        */
-       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
-
-       return 0;
-}
-
-static int mga_dma_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_mga_buf_priv_t *buf_priv;
-       drm_mga_vertex_t *vertex = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
-               return -EINVAL;
-       buf = dma->buflist[vertex->idx];
-       buf_priv = buf->dev_private;
-
-       buf->used = vertex->used;
-       buf_priv->discard = vertex->discard;
-
-       if (!mga_verify_state(dev_priv)) {
-               if (vertex->discard) {
-                       if (buf_priv->dispatched == 1)
-                               AGE_BUFFER(buf_priv);
-                       buf_priv->dispatched = 0;
-                       mga_freelist_put(dev, buf);
-               }
-               return -EINVAL;
-       }
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_vertex(dev, buf);
-
-       return 0;
-}
-
-static int mga_dma_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_mga_buf_priv_t *buf_priv;
-       drm_mga_indices_t *indices = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (indices->idx < 0 || indices->idx > dma->buf_count)
-               return -EINVAL;
-
-       buf = dma->buflist[indices->idx];
-       buf_priv = buf->dev_private;
-
-       buf_priv->discard = indices->discard;
-
-       if (!mga_verify_state(dev_priv)) {
-               if (indices->discard) {
-                       if (buf_priv->dispatched == 1)
-                               AGE_BUFFER(buf_priv);
-                       buf_priv->dispatched = 0;
-                       mga_freelist_put(dev, buf);
-               }
-               return -EINVAL;
-       }
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_indices(dev, buf, indices->start, indices->end);
-
-       return 0;
-}
-
-static int mga_dma_iload(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       struct drm_buf *buf;
-       drm_mga_buf_priv_t *buf_priv;
-       drm_mga_iload_t *iload = data;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-#if 0
-       if (mga_do_wait_for_idle(dev_priv) < 0) {
-               if (MGA_DMA_DEBUG)
-                       DRM_INFO("-EBUSY\n");
-               return -EBUSY;
-       }
-#endif
-       if (iload->idx < 0 || iload->idx > dma->buf_count)
-               return -EINVAL;
-
-       buf = dma->buflist[iload->idx];
-       buf_priv = buf->dev_private;
-
-       if (mga_verify_iload(dev_priv, iload->dstorg, iload->length)) {
-               mga_freelist_put(dev, buf);
-               return -EINVAL;
-       }
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_iload(dev, buf, iload->dstorg, iload->length);
-
-       /* Make sure we restore the 3D state next time.
-        */
-       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
-
-       return 0;
-}
-
-static int mga_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_mga_blit_t *blit = data;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
-
-       if (mga_verify_blit(dev_priv, blit->srcorg, blit->dstorg))
-               return -EINVAL;
-
-       WRAP_TEST_WITH_RETURN(dev_priv);
-
-       mga_dma_dispatch_blit(dev, blit);
-
-       /* Make sure we restore the 3D state next time.
-        */
-       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
-
-       return 0;
-}
-
-static int mga_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       drm_mga_getparam_t *param = data;
-       int value;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
-
-       switch (param->param) {
-       case MGA_PARAM_IRQ_NR:
-               value = dev->irq;
-               break;
-       case MGA_PARAM_CARD_TYPE:
-               value = dev_priv->chipset;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-static int mga_set_fence(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       u32 *fence = data;
-       DMA_LOCALS;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
-
-       /* I would normal do this assignment in the declaration of fence,
-        * but dev_priv may be NULL.
-        */
-
-       *fence = dev_priv->next_fence_to_post;
-       dev_priv->next_fence_to_post++;
-
-       BEGIN_DMA(1);
-       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000,
-                 MGA_DMAPAD, 0x00000000, MGA_SOFTRAP, 0x00000000);
-       ADVANCE_DMA();
-
-       return 0;
-}
-
-static int mga_wait_fence(struct drm_device *dev, void *data, struct drm_file *
-file_priv)
-{
-       drm_mga_private_t *dev_priv = dev->dev_private;
-       u32 *fence = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
-
-       mga_driver_fence_wait(dev, fence);
-       return 0;
-}
-
-struct drm_ioctl_desc mga_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_MGA_INIT, mga_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_MGA_FLUSH, mga_dma_flush, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_RESET, mga_dma_reset, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_SWAP, mga_dma_swap, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_CLEAR, mga_dma_clear, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_VERTEX, mga_dma_vertex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_INDICES, mga_dma_indices, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_ILOAD, mga_dma_iload, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_BLIT, mga_dma_blit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_GETPARAM, mga_getparam, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_SET_FENCE, mga_set_fence, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_WAIT_FENCE, mga_wait_fence, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_MGA_DMA_BOOTSTRAP, mga_dma_bootstrap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-};
-
-int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);
diff --git a/drivers/char/drm/mga_ucode.h b/drivers/char/drm/mga_ucode.h
deleted file mode 100644 (file)
index b611e27..0000000
+++ /dev/null
@@ -1,11645 +0,0 @@
-/* mga_ucode.h -- Matrox G200/G400 WARP engine microcode -*- linux-c -*-
- * Created: Thu Jan 11 21:20:43 2001 by gareth@valinux.com
- *
- * Copyright 1999 Matrox Graphics Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * MATROX GRAPHICS INC., OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
- * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Kernel-based WARP engine management:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * WARP pipes are named according to the functions they perform, where:
- *
- *   - T stands for computation of texture stage 0
- *   - T2 stands for computation of both texture stage 0 and texture stage 1
- *   - G stands for computation of triangle intensity (Gouraud interpolation)
- *   - Z stands for computation of Z buffer interpolation
- *   - S stands for computation of specular highlight
- *   - A stands for computation of the alpha channel
- *   - F stands for computation of vertex fog interpolation
- */
-
-static unsigned char warp_g200_tgz[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x72, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x60, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x03, 0x80, 0x0A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x57, 0x39, 0x20, 0xE9,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0x2B, 0x32, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0xB3, 0x05,
-       0x00, 0xE0,
-       0x16, 0x28, 0x20, 0xE9,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x1E, 0x2B, 0x20, 0xE9,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x85, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x84, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x82, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x7F, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgza[] = {
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x7D, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x6B, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2D, 0x44, 0x4C, 0xB6,
-       0x25, 0x44, 0x54, 0xB6,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x07, 0xC0, 0x44, 0xC6,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x1F, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x3F, 0x3D, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x07, 0x20,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0xB3, 0x05,
-       0x00, 0xE0,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0x26, 0x1F, 0xDF,
-       0x9D, 0x1F, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x9E, 0x3F, 0x4F, 0xE9,
-
-       0x07, 0x07, 0x1F, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x9C, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x7A, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x79, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x77, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x74, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzaf[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x83, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x6F, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0D, 0x21, 0x1A, 0xB6,
-       0x05, 0x21, 0x31, 0xB6,
-
-       0x2D, 0x44, 0x4C, 0xB6,
-       0x25, 0x44, 0x54, 0xB6,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x0D, 0x20,
-       0x05, 0x20,
-       0x2F, 0xC0, 0x21, 0xC6,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x07, 0xC0, 0x44, 0xC6,
-
-       0x17, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x2D, 0x20,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x1F, 0x62, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x07, 0x20,
-
-       0x3F, 0x3D, 0x5D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0xB3, 0x05,
-       0x00, 0xE0,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x35, 0x17, 0x4F, 0xE9,
-
-       0x1F, 0x26, 0x1F, 0xDF,
-       0x9D, 0x1F, 0x4F, 0xE9,
-
-       0x9E, 0x3F, 0x4F, 0xE9,
-       0x39, 0x37, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x17, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x07, 0x07, 0x1F, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x31, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x9C, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x74, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x73, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x71, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6E, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzf[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x7F, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x6B, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0D, 0x21, 0x1A, 0xB6,
-       0x05, 0x21, 0x31, 0xB6,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x0D, 0x20,
-       0x05, 0x20,
-       0x2F, 0xC0, 0x21, 0xC6,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x17, 0x50, 0x56, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0xB3, 0x05,
-       0x00, 0xE0,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x17, 0x26, 0x17, 0xDF,
-       0x35, 0x17, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x39, 0x37, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x17, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x31, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x78, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x77, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x75, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x72, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzs[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x8B, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x77, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2D, 0x21, 0x1A, 0xB0,
-       0x25, 0x21, 0x31, 0xB0,
-
-       0x0D, 0x21, 0x1A, 0xB2,
-       0x05, 0x21, 0x31, 0xB2,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x05, 0x20,
-       0x0D, 0x20,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x2F, 0xC0, 0x21, 0xC0,
-
-       0x16, 0x42, 0x56, 0x9F,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x1E, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x21, 0x31, 0xB4,
-       0x2D, 0x21, 0x1A, 0xB4,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0x05,
-       0x00, 0xE0,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x1E, 0x26, 0x1E, 0xDF,
-
-       0xA7, 0x1E, 0x4F, 0xE9,
-       0x17, 0x26, 0x16, 0xDF,
-
-       0x2D, 0x20,
-       0x00, 0xE0,
-       0xA8, 0x3F, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x1E, 0xAF,
-       0x25, 0x20,
-       0x00, 0xE0,
-
-       0xA4, 0x16, 0x4F, 0xE9,
-       0x0F, 0xC0, 0x21, 0xC2,
-
-       0xA6, 0x80, 0x4F, 0xE9,
-       0x1F, 0x62, 0x57, 0x9F,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x8F, 0x20,
-
-       0xA5, 0x37, 0x4F, 0xE9,
-       0x0F, 0x17, 0x0F, 0xAF,
-
-       0x06, 0xC0, 0x21, 0xC4,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0xA3, 0x80, 0x4F, 0xE9,
-
-       0x06, 0x20,
-       0x00, 0xE0,
-       0x1F, 0x26, 0x1F, 0xDF,
-
-       0xA1, 0x1F, 0x4F, 0xE9,
-       0xA2, 0x3F, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x06, 0x06, 0x1F, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x6C, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6B, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x69, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzsa[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x8F, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x7B, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2D, 0x21, 0x1A, 0xB0,
-       0x25, 0x21, 0x31, 0xB0,
-
-       0x0D, 0x21, 0x1A, 0xB2,
-       0x05, 0x21, 0x31, 0xB2,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x05, 0x20,
-       0x0D, 0x20,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x2F, 0xC0, 0x21, 0xC0,
-
-       0x16, 0x42, 0x56, 0x9F,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x1E, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x21, 0x31, 0xB4,
-       0x2D, 0x21, 0x1A, 0xB4,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0x05,
-       0x00, 0xE0,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0x0D, 0x44, 0x4C, 0xB6,
-       0x05, 0x44, 0x54, 0xB6,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x1E, 0x26, 0x1E, 0xDF,
-
-       0xA7, 0x1E, 0x4F, 0xE9,
-       0x17, 0x26, 0x16, 0xDF,
-
-       0x2D, 0x20,
-       0x00, 0xE0,
-       0xA8, 0x3F, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x1E, 0xAF,
-       0x25, 0x20,
-       0x00, 0xE0,
-
-       0xA4, 0x16, 0x4F, 0xE9,
-       0x0F, 0xC0, 0x21, 0xC2,
-
-       0xA6, 0x80, 0x4F, 0xE9,
-       0x1F, 0x62, 0x57, 0x9F,
-
-       0x0D, 0x20,
-       0x05, 0x20,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x0F, 0x20,
-
-       0x17, 0x50, 0x56, 0x9F,
-       0xA5, 0x37, 0x4F, 0xE9,
-
-       0x06, 0xC0, 0x21, 0xC4,
-       0x0F, 0x17, 0x0F, 0xAF,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2F, 0xC0, 0x44, 0xC6,
-       0xA3, 0x80, 0x4F, 0xE9,
-
-       0x06, 0x20,
-       0x00, 0xE0,
-       0x1F, 0x26, 0x1F, 0xDF,
-
-       0x17, 0x26, 0x17, 0xDF,
-       0x9D, 0x17, 0x4F, 0xE9,
-
-       0xA1, 0x1F, 0x4F, 0xE9,
-       0xA2, 0x3F, 0x4F, 0xE9,
-
-       0x06, 0x06, 0x1F, 0xAF,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x9E, 0x37, 0x4F, 0xE9,
-       0x2F, 0x17, 0x2F, 0xAF,
-
-       0xA0, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x9C, 0x80, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x68, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x67, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x65, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x62, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzsaf[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x94, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x80, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2D, 0x21, 0x1A, 0xB0,
-       0x25, 0x21, 0x31, 0xB0,
-
-       0x0D, 0x21, 0x1A, 0xB2,
-       0x05, 0x21, 0x31, 0xB2,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x05, 0x20,
-       0x0D, 0x20,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x2F, 0xC0, 0x21, 0xC0,
-
-       0x16, 0x42, 0x56, 0x9F,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x1E, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x21, 0x31, 0xB4,
-       0x2D, 0x21, 0x1A, 0xB4,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0x05,
-       0x00, 0xE0,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0x0D, 0x21, 0x1A, 0xB6,
-       0x05, 0x21, 0x31, 0xB6,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x1E, 0x26, 0x1E, 0xDF,
-
-       0xA7, 0x1E, 0x4F, 0xE9,
-       0x17, 0x26, 0x16, 0xDF,
-
-       0x2D, 0x20,
-       0x00, 0xE0,
-       0xA8, 0x3F, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x1E, 0xAF,
-       0x25, 0x20,
-       0x00, 0xE0,
-
-       0xA4, 0x16, 0x4F, 0xE9,
-       0x0F, 0xC0, 0x21, 0xC2,
-
-       0xA6, 0x80, 0x4F, 0xE9,
-       0x1F, 0x62, 0x57, 0x9F,
-
-       0x0D, 0x20,
-       0x05, 0x20,
-       0x2F, 0xC0, 0x21, 0xC6,
-
-       0x2D, 0x44, 0x4C, 0xB6,
-       0x25, 0x44, 0x54, 0xB6,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x0F, 0x20,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x07, 0xC0, 0x44, 0xC6,
-
-       0x17, 0x50, 0x56, 0x9F,
-       0xA5, 0x37, 0x4F, 0xE9,
-
-       0x06, 0xC0, 0x21, 0xC4,
-       0x0F, 0x17, 0x0F, 0xAF,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1E, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x3E, 0x3D, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x07, 0x20,
-
-       0x2F, 0x20,
-       0x00, 0xE0,
-       0xA3, 0x0F, 0x4F, 0xE9,
-
-       0x06, 0x20,
-       0x00, 0xE0,
-       0x1F, 0x26, 0x1F, 0xDF,
-
-       0x17, 0x26, 0x17, 0xDF,
-       0xA1, 0x1F, 0x4F, 0xE9,
-
-       0x1E, 0x26, 0x1E, 0xDF,
-       0x9D, 0x1E, 0x4F, 0xE9,
-
-       0x35, 0x17, 0x4F, 0xE9,
-       0xA2, 0x3F, 0x4F, 0xE9,
-
-       0x06, 0x06, 0x1F, 0xAF,
-       0x39, 0x37, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x17, 0xAF,
-       0x07, 0x07, 0x1E, 0xAF,
-
-       0xA0, 0x80, 0x4F, 0xE9,
-       0x9E, 0x3E, 0x4F, 0xE9,
-
-       0x31, 0x80, 0x4F, 0xE9,
-       0x9C, 0x80, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x63, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x62, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x60, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x5D, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g200_tgzsf[] = {
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x98, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x81, 0x04,
-       0x89, 0x04,
-       0x01, 0x04,
-       0x09, 0x04,
-
-       0xC9, 0x41, 0xC0, 0xEC,
-       0x11, 0x04,
-       0x00, 0xE0,
-
-       0x41, 0xCC, 0x41, 0xCD,
-       0x49, 0xCC, 0x49, 0xCD,
-
-       0xD1, 0x41, 0xC0, 0xEC,
-       0x51, 0xCC, 0x51, 0xCD,
-
-       0x80, 0x04,
-       0x10, 0x04,
-       0x08, 0x04,
-       0x00, 0xE0,
-
-       0x00, 0xCC, 0xC0, 0xCD,
-       0xD1, 0x49, 0xC0, 0xEC,
-
-       0x8A, 0x1F, 0x20, 0xE9,
-       0x8B, 0x3F, 0x20, 0xE9,
-
-       0x41, 0x3C, 0x41, 0xAD,
-       0x49, 0x3C, 0x49, 0xAD,
-
-       0x10, 0xCC, 0x10, 0xCD,
-       0x08, 0xCC, 0x08, 0xCD,
-
-       0xB9, 0x41, 0x49, 0xBB,
-       0x1F, 0xF0, 0x41, 0xCD,
-
-       0x51, 0x3C, 0x51, 0xAD,
-       0x00, 0x98, 0x80, 0xE9,
-
-       0x8F, 0x80, 0x07, 0xEA,
-       0x24, 0x1F, 0x20, 0xE9,
-
-       0x21, 0x45, 0x80, 0xE8,
-       0x1A, 0x4D, 0x80, 0xE8,
-
-       0x31, 0x55, 0x80, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0x41, 0x49, 0xBD,
-       0x1D, 0x41, 0x51, 0xBD,
-
-       0x2E, 0x41, 0x2A, 0xB8,
-       0x34, 0x53, 0xA0, 0xE8,
-
-       0x15, 0x30,
-       0x1D, 0x30,
-       0x58, 0xE3,
-       0x00, 0xE0,
-
-       0xB5, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x24, 0x43, 0xA0, 0xE8,
-       0x2C, 0x4B, 0xA0, 0xE8,
-
-       0x15, 0x72,
-       0x09, 0xE3,
-       0x00, 0xE0,
-       0x1D, 0x72,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0x97, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x6C, 0x64, 0xC8, 0xEC,
-       0x98, 0xE1,
-       0xB5, 0x05,
-
-       0xBD, 0x05,
-       0x2E, 0x30,
-       0x32, 0xC0, 0xA0, 0xE8,
-
-       0x33, 0xC0, 0xA0, 0xE8,
-       0x74, 0x64, 0xC8, 0xEC,
-
-       0x40, 0x3C, 0x40, 0xAD,
-       0x32, 0x6A,
-       0x2A, 0x30,
-
-       0x20, 0x73,
-       0x33, 0x6A,
-       0x00, 0xE0,
-       0x28, 0x73,
-
-       0x1C, 0x72,
-       0x83, 0xE2,
-       0x7B, 0x80, 0x15, 0xEA,
-
-       0xB8, 0x3D, 0x28, 0xDF,
-       0x30, 0x35, 0x20, 0xDF,
-
-       0x40, 0x30,
-       0x00, 0xE0,
-       0xCC, 0xE2,
-       0x64, 0x72,
-
-       0x25, 0x42, 0x52, 0xBF,
-       0x2D, 0x42, 0x4A, 0xBF,
-
-       0x30, 0x2E, 0x30, 0xDF,
-       0x38, 0x2E, 0x38, 0xDF,
-
-       0x18, 0x1D, 0x45, 0xE9,
-       0x1E, 0x15, 0x45, 0xE9,
-
-       0x2B, 0x49, 0x51, 0xBD,
-       0x00, 0xE0,
-       0x1F, 0x73,
-
-       0x38, 0x38, 0x40, 0xAF,
-       0x30, 0x30, 0x40, 0xAF,
-
-       0x24, 0x1F, 0x24, 0xDF,
-       0x1D, 0x32, 0x20, 0xE9,
-
-       0x2C, 0x1F, 0x2C, 0xDF,
-       0x1A, 0x33, 0x20, 0xE9,
-
-       0xB0, 0x10,
-       0x08, 0xE3,
-       0x40, 0x10,
-       0xB8, 0x10,
-
-       0x26, 0xF0, 0x30, 0xCD,
-       0x2F, 0xF0, 0x38, 0xCD,
-
-       0x2B, 0x80, 0x20, 0xE9,
-       0x2A, 0x80, 0x20, 0xE9,
-
-       0xA6, 0x20,
-       0x88, 0xE2,
-       0x00, 0xE0,
-       0xAF, 0x20,
-
-       0x28, 0x2A, 0x26, 0xAF,
-       0x20, 0x2A, 0xC0, 0xAF,
-
-       0x34, 0x1F, 0x34, 0xDF,
-       0x46, 0x24, 0x46, 0xDF,
-
-       0x28, 0x30, 0x80, 0xBF,
-       0x20, 0x38, 0x80, 0xBF,
-
-       0x47, 0x24, 0x47, 0xDF,
-       0x4E, 0x2C, 0x4E, 0xDF,
-
-       0x4F, 0x2C, 0x4F, 0xDF,
-       0x56, 0x34, 0x56, 0xDF,
-
-       0x28, 0x15, 0x28, 0xDF,
-       0x20, 0x1D, 0x20, 0xDF,
-
-       0x57, 0x34, 0x57, 0xDF,
-       0x00, 0xE0,
-       0x1D, 0x05,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x89, 0xE2,
-       0x2B, 0x30,
-
-       0x3F, 0xC1, 0x1D, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x68,
-       0xBF, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x20, 0xC0, 0x20, 0xAF,
-       0x28, 0x05,
-       0x97, 0x74,
-
-       0x00, 0xE0,
-       0x2A, 0x10,
-       0x16, 0xC0, 0x20, 0xE9,
-
-       0x04, 0x80, 0x10, 0xEA,
-       0x8C, 0xE2,
-       0x95, 0x05,
-
-       0x28, 0xC1, 0x28, 0xAD,
-       0x1F, 0xC1, 0x15, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA8, 0x67,
-       0x9F, 0x6B,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x28, 0xC0, 0x28, 0xAD,
-       0x1D, 0x25,
-       0x20, 0x05,
-
-       0x28, 0x32, 0x80, 0xAD,
-       0x40, 0x2A, 0x40, 0xBD,
-
-       0x1C, 0x80, 0x20, 0xE9,
-       0x20, 0x33, 0x20, 0xAD,
-
-       0x20, 0x73,
-       0x00, 0xE0,
-       0xB6, 0x49, 0x51, 0xBB,
-
-       0x26, 0x2F, 0xB0, 0xE8,
-       0x19, 0x20, 0x20, 0xE9,
-
-       0x35, 0x20, 0x35, 0xDF,
-       0x3D, 0x20, 0x3D, 0xDF,
-
-       0x15, 0x20, 0x15, 0xDF,
-       0x1D, 0x20, 0x1D, 0xDF,
-
-       0x26, 0xD0, 0x26, 0xCD,
-       0x29, 0x49, 0x2A, 0xB8,
-
-       0x26, 0x40, 0x80, 0xBD,
-       0x3B, 0x48, 0x50, 0xBD,
-
-       0x3E, 0x54, 0x57, 0x9F,
-       0x00, 0xE0,
-       0x82, 0xE1,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x26, 0x30,
-       0x29, 0x30,
-       0x48, 0x3C, 0x48, 0xAD,
-
-       0x2B, 0x72,
-       0xC2, 0xE1,
-       0x2C, 0xC0, 0x44, 0xC2,
-
-       0x05, 0x24, 0x34, 0xBF,
-       0x0D, 0x24, 0x2C, 0xBF,
-
-       0x2D, 0x46, 0x4E, 0xBF,
-       0x25, 0x46, 0x56, 0xBF,
-
-       0x20, 0x1D, 0x6F, 0x8F,
-       0x32, 0x3E, 0x5F, 0xE9,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x30,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x33, 0x1E, 0x5F, 0xE9,
-
-       0x05, 0x44, 0x54, 0xB2,
-       0x0D, 0x44, 0x4C, 0xB2,
-
-       0x19, 0xC0, 0xB0, 0xE8,
-       0x34, 0xC0, 0x44, 0xC4,
-
-       0x33, 0x73,
-       0x00, 0xE0,
-       0x3E, 0x62, 0x57, 0x9F,
-
-       0x1E, 0xAF, 0x59, 0x9F,
-       0x00, 0xE0,
-       0x0D, 0x20,
-
-       0x84, 0x3E, 0x58, 0xE9,
-       0x28, 0x1D, 0x6F, 0x8F,
-
-       0x05, 0x20,
-       0x00, 0xE0,
-       0x85, 0x1E, 0x58, 0xE9,
-
-       0x9B, 0x3B, 0x33, 0xDF,
-       0x20, 0x20, 0x42, 0xAF,
-
-       0x30, 0x42, 0x56, 0x9F,
-       0x80, 0x3E, 0x57, 0xE9,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x30, 0x80, 0x5F, 0xE9,
-
-       0x28, 0x28, 0x24, 0xAF,
-       0x81, 0x1E, 0x57, 0xE9,
-
-       0x05, 0x47, 0x57, 0xBF,
-       0x0D, 0x47, 0x4F, 0xBF,
-
-       0x88, 0x80, 0x58, 0xE9,
-       0x1B, 0x29, 0x1B, 0xDF,
-
-       0x30, 0x1D, 0x6F, 0x8F,
-       0x3A, 0x30, 0x4F, 0xE9,
-
-       0x1C, 0x30, 0x26, 0xDF,
-       0x09, 0xE3,
-       0x3B, 0x05,
-
-       0x3E, 0x50, 0x56, 0x9F,
-       0x3B, 0x3F, 0x4F, 0xE9,
-
-       0x1E, 0x8F, 0x51, 0x9F,
-       0x00, 0xE0,
-       0xAC, 0x20,
-
-       0x2D, 0x44, 0x4C, 0xB4,
-       0x2C, 0x1C, 0xC0, 0xAF,
-
-       0x25, 0x44, 0x54, 0xB4,
-       0x00, 0xE0,
-       0xC8, 0x30,
-
-       0x30, 0x46, 0x30, 0xAF,
-       0x1B, 0x1B, 0x48, 0xAF,
-
-       0x00, 0xE0,
-       0x25, 0x20,
-       0x38, 0x2C, 0x4F, 0xE9,
-
-       0x86, 0x80, 0x57, 0xE9,
-       0x38, 0x1D, 0x6F, 0x8F,
-
-       0x28, 0x74,
-       0x00, 0xE0,
-       0x0D, 0x44, 0x4C, 0xB0,
-
-       0x05, 0x44, 0x54, 0xB0,
-       0x2D, 0x20,
-       0x9B, 0x10,
-
-       0x82, 0x3E, 0x57, 0xE9,
-       0x32, 0xF0, 0x1B, 0xCD,
-
-       0x1E, 0xBD, 0x59, 0x9F,
-       0x83, 0x1E, 0x57, 0xE9,
-
-       0x38, 0x47, 0x38, 0xAF,
-       0x34, 0x20,
-       0x2A, 0x30,
-
-       0x00, 0xE0,
-       0x0D, 0x20,
-       0x32, 0x20,
-       0x05, 0x20,
-
-       0x87, 0x80, 0x57, 0xE9,
-       0x1F, 0x54, 0x57, 0x9F,
-
-       0x17, 0x42, 0x56, 0x9F,
-       0x00, 0xE0,
-       0x3B, 0x6A,
-
-       0x3F, 0x8F, 0x51, 0x9F,
-       0x37, 0x1E, 0x4F, 0xE9,
-
-       0x37, 0x32, 0x2A, 0xAF,
-       0x00, 0xE0,
-       0x32, 0x00,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x27, 0xC0, 0x44, 0xC0,
-
-       0x36, 0x1F, 0x4F, 0xE9,
-       0x1F, 0x1F, 0x26, 0xDF,
-
-       0x37, 0x1B, 0x37, 0xBF,
-       0x17, 0x26, 0x17, 0xDF,
-
-       0x3E, 0x17, 0x4F, 0xE9,
-       0x3F, 0x3F, 0x4F, 0xE9,
-
-       0x34, 0x1F, 0x34, 0xAF,
-       0x2B, 0x05,
-       0xA7, 0x20,
-
-       0x33, 0x2B, 0x37, 0xDF,
-       0x27, 0x17, 0xC0, 0xAF,
-
-       0x34, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2D, 0x21, 0x1A, 0xB0,
-       0x25, 0x21, 0x31, 0xB0,
-
-       0x0D, 0x21, 0x1A, 0xB2,
-       0x05, 0x21, 0x31, 0xB2,
-
-       0x03, 0x80, 0x2A, 0xEA,
-       0x17, 0xC1, 0x2B, 0xBD,
-
-       0x2D, 0x20,
-       0x25, 0x20,
-       0x05, 0x20,
-       0x0D, 0x20,
-
-       0xB3, 0x68,
-       0x97, 0x25,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0xC0, 0x33, 0xAF,
-       0x2F, 0xC0, 0x21, 0xC0,
-
-       0x16, 0x42, 0x56, 0x9F,
-       0x3C, 0x27, 0x4F, 0xE9,
-
-       0x1E, 0x62, 0x57, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x21, 0x31, 0xB4,
-       0x2D, 0x21, 0x1A, 0xB4,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x33, 0x05,
-       0x00, 0xE0,
-       0x28, 0x19, 0x60, 0xEC,
-
-       0x0D, 0x21, 0x1A, 0xB6,
-       0x05, 0x21, 0x31, 0xB6,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0xE0,
-       0x2F, 0x20,
-
-       0x23, 0x3B, 0x33, 0xAD,
-       0x1E, 0x26, 0x1E, 0xDF,
-
-       0xA7, 0x1E, 0x4F, 0xE9,
-       0x17, 0x26, 0x16, 0xDF,
-
-       0x2D, 0x20,
-       0x00, 0xE0,
-       0xA8, 0x3F, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x1E, 0xAF,
-       0x25, 0x20,
-       0x00, 0xE0,
-
-       0xA4, 0x16, 0x4F, 0xE9,
-       0x0F, 0xC0, 0x21, 0xC2,
-
-       0xA6, 0x80, 0x4F, 0xE9,
-       0x1F, 0x62, 0x57, 0x9F,
-
-       0x0D, 0x20,
-       0x05, 0x20,
-       0x2F, 0xC0, 0x21, 0xC6,
-
-       0x3F, 0x2F, 0x5D, 0x9F,
-       0x00, 0xE0,
-       0x0F, 0x20,
-
-       0x17, 0x50, 0x56, 0x9F,
-       0xA5, 0x37, 0x4F, 0xE9,
-
-       0x06, 0xC0, 0x21, 0xC4,
-       0x0F, 0x17, 0x0F, 0xAF,
-
-       0x37, 0x0F, 0x5C, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2F, 0x20,
-       0x00, 0xE0,
-       0xA3, 0x80, 0x4F, 0xE9,
-
-       0x06, 0x20,
-       0x00, 0xE0,
-       0x1F, 0x26, 0x1F, 0xDF,
-
-       0x17, 0x26, 0x17, 0xDF,
-       0x35, 0x17, 0x4F, 0xE9,
-
-       0xA1, 0x1F, 0x4F, 0xE9,
-       0xA2, 0x3F, 0x4F, 0xE9,
-
-       0x06, 0x06, 0x1F, 0xAF,
-       0x39, 0x37, 0x4F, 0xE9,
-
-       0x2F, 0x2F, 0x17, 0xAF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xA0, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x31, 0x80, 0x4F, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x57, 0x39, 0x20, 0xE9,
-
-       0x16, 0x28, 0x20, 0xE9,
-       0x1D, 0x3B, 0x20, 0xE9,
-
-       0x1E, 0x2B, 0x20, 0xE9,
-       0x2B, 0x32, 0x20, 0xE9,
-
-       0x1C, 0x23, 0x20, 0xE9,
-       0x57, 0x36, 0x20, 0xE9,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x40, 0x40, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x90, 0xE2,
-       0x00, 0xE0,
-
-       0x68, 0xFF, 0x20, 0xEA,
-       0x19, 0xC8, 0xC1, 0xCD,
-
-       0x1F, 0xD7, 0x18, 0xBD,
-       0x3F, 0xD7, 0x22, 0xBD,
-
-       0x9F, 0x41, 0x49, 0xBD,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x25, 0x41, 0x49, 0xBD,
-       0x2D, 0x41, 0x51, 0xBD,
-
-       0x0D, 0x80, 0x07, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x35, 0x40, 0x48, 0xBD,
-       0x3D, 0x40, 0x50, 0xBD,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x25, 0x30,
-       0x2D, 0x30,
-
-       0x35, 0x30,
-       0xB5, 0x30,
-       0xBD, 0x30,
-       0x3D, 0x30,
-
-       0x9C, 0xA7, 0x5B, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x67, 0xFF, 0x0A, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC9, 0x41, 0xC8, 0xEC,
-       0x42, 0xE1,
-       0x00, 0xE0,
-
-       0x65, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xC8, 0x40, 0xC0, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x62, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-};
-
-static unsigned char warp_g400_t2gz[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x78, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x69, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x25, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2A, 0x44, 0x54, 0xB4,
-       0x1A, 0x44, 0x64, 0xB4,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x9F, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xBE, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x7D, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gza[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x7C, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x6D, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x29, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0F, 0xCF, 0x74, 0xC6,
-       0x3D, 0xCF, 0x74, 0xC2,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x0F, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB4,
-       0x02, 0x44, 0x64, 0xB4,
-
-       0x2A, 0x44, 0x54, 0xB6,
-       0x1A, 0x44, 0x64, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x9B, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xBA, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x79, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzaf[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x81, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x72, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x2E, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x0F, 0xCF, 0x74, 0xC6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x0F, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB4,
-       0x02, 0x44, 0x64, 0xB4,
-
-       0x2A, 0x44, 0x54, 0xB6,
-       0x1A, 0x44, 0x64, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x3D, 0xCF, 0x75, 0xC6,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x45, 0x55, 0xB6,
-       0x02, 0x45, 0x65, 0xB6,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x3D, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x96, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xB5, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x74, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzf[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x7D, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x6E, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0F, 0xCF, 0x75, 0xC6,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x28, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x31, 0x0F, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x54, 0xB4,
-       0x02, 0x44, 0x64, 0xB4,
-
-       0x2A, 0x45, 0x55, 0xB6,
-       0x1A, 0x45, 0x65, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x9A, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xBB, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x78, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzs[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x85, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x76, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x0F, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x31, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0F, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB4,
-       0x1A, 0x44, 0x64, 0xB4,
-
-       0x0A, 0x45, 0x55, 0xB0,
-       0x02, 0x45, 0x65, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x55, 0xB2,
-       0x1A, 0x45, 0x65, 0xB2,
-
-       0x0A, 0x45, 0x55, 0xB4,
-       0x02, 0x45, 0x65, 0xB4,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x20,
-       0x1A, 0x20,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA7, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x92, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xB2, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x70, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzsa[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x8A, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x7B, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x0F, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x36, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0F, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB4,
-       0x1A, 0x44, 0x64, 0xB4,
-
-       0x0A, 0x45, 0x55, 0xB0,
-       0x02, 0x45, 0x65, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x55, 0xB2,
-       0x1A, 0x45, 0x65, 0xB2,
-
-       0x0A, 0x45, 0x55, 0xB4,
-       0x02, 0x45, 0x65, 0xB4,
-
-       0x0F, 0xCF, 0x74, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB6,
-       0x1A, 0x44, 0x64, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x8D, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xAD, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x6B, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzsaf[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x8E, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x7F, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x0F, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x3A, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0F, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB4,
-       0x1A, 0x44, 0x64, 0xB4,
-
-       0x0A, 0x45, 0x55, 0xB0,
-       0x02, 0x45, 0x65, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x55, 0xB2,
-       0x1A, 0x45, 0x65, 0xB2,
-
-       0x0A, 0x45, 0x55, 0xB4,
-       0x02, 0x45, 0x65, 0xB4,
-
-       0x0F, 0xCF, 0x74, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB6,
-       0x1A, 0x44, 0x64, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x45, 0x55, 0xB6,
-       0x02, 0x45, 0x65, 0xB6,
-
-       0x3D, 0xCF, 0x75, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x3D, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x89, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xA9, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x67, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_t2gzsf[] = {
-
-       0x00, 0x8A, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x0A, 0x40, 0x50, 0xBF,
-       0x2A, 0x40, 0x60, 0xBF,
-
-       0x32, 0x41, 0x51, 0xBF,
-       0x3A, 0x41, 0x61, 0xBF,
-
-       0xC3, 0x6B,
-       0xD3, 0x6B,
-       0x00, 0x8A, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x23, 0x9F,
-       0x00, 0xE0,
-       0x51, 0x04,
-
-       0x90, 0xE2,
-       0x61, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x51, 0x41, 0xE0, 0xEC,
-       0x39, 0x67, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x63, 0xA0, 0xE8,
-
-       0x61, 0x41, 0xE0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x8A, 0x80, 0x15, 0xEA,
-       0x10, 0x04,
-       0x20, 0x04,
-
-       0x61, 0x51, 0xE0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x52, 0xBF,
-       0x0F, 0x52, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x62, 0xBF,
-       0x1E, 0x51, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x0E, 0x61, 0x60, 0xEA,
-
-       0x32, 0x40, 0x50, 0xBD,
-       0x22, 0x40, 0x60, 0xBD,
-
-       0x12, 0x41, 0x51, 0xBD,
-       0x3A, 0x41, 0x61, 0xBD,
-
-       0xBF, 0x2F, 0x0E, 0xBD,
-       0x97, 0xE2,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x35, 0x48, 0xB1, 0xE8,
-       0x3D, 0x59, 0xB1, 0xE8,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x56, 0x31, 0x56, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x66, 0x31, 0x66, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x57, 0x39, 0x57, 0xBF,
-       0x67, 0x39, 0x67, 0xBF,
-
-       0x7B, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x35, 0x00,
-       0x3D, 0x00,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0x8D, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x75, 0xF8, 0xEC,
-       0x35, 0x20,
-       0x3D, 0x20,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x53, 0x53, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x0E, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x48, 0x35, 0x48, 0xBF,
-       0x58, 0x35, 0x58, 0xBF,
-
-       0x68, 0x35, 0x68, 0xBF,
-       0x49, 0x3D, 0x49, 0xBF,
-
-       0x59, 0x3D, 0x59, 0xBF,
-       0x69, 0x3D, 0x69, 0xBF,
-
-       0x63, 0x63, 0x2D, 0xDF,
-       0x4D, 0x7D, 0xF8, 0xEC,
-
-       0x59, 0xE3,
-       0x00, 0xE0,
-       0xB8, 0x38, 0x33, 0xBF,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x18, 0x3A, 0x41, 0xE9,
-
-       0x3F, 0x53, 0xA0, 0xE8,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x63, 0xA0, 0xE8,
-
-       0x50, 0x70, 0xF8, 0xEC,
-       0x2B, 0x50, 0x3C, 0xE9,
-
-       0x1F, 0x0F, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x59, 0x78, 0xF8, 0xEC,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x56, 0x3F, 0x56, 0xDF,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x66, 0x3D, 0x66, 0xDF,
-
-       0x1D, 0x32, 0x41, 0xE9,
-       0x67, 0x3D, 0x67, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3F, 0x57, 0xDF,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x59, 0x3F, 0x59, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x69, 0x3D, 0x69, 0xDF,
-
-       0x48, 0x37, 0x48, 0xDF,
-       0x58, 0x3F, 0x58, 0xDF,
-
-       0x68, 0x3D, 0x68, 0xDF,
-       0x49, 0x37, 0x49, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x0F, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x54, 0xB0,
-       0x02, 0x44, 0x64, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB2,
-       0x1A, 0x44, 0x64, 0xB2,
-
-       0x36, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0F, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x54, 0xB4,
-       0x1A, 0x44, 0x64, 0xB4,
-
-       0x0A, 0x45, 0x55, 0xB0,
-       0x02, 0x45, 0x65, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x55, 0xB2,
-       0x1A, 0x45, 0x65, 0xB2,
-
-       0x0A, 0x45, 0x55, 0xB4,
-       0x02, 0x45, 0x65, 0xB4,
-
-       0x0F, 0xCF, 0x75, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x31, 0x0F, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x55, 0xB6,
-       0x1A, 0x45, 0x65, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x56, 0xBF,
-       0x1A, 0x46, 0x66, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x57, 0xBF,
-       0x02, 0x47, 0x67, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x53, 0xBF,
-       0x1A, 0x43, 0x63, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x48, 0x58, 0xBF,
-       0x02, 0x48, 0x68, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x2A, 0x49, 0x59, 0xBF,
-       0x1A, 0x49, 0x69, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x82, 0x30, 0x57, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x83, 0x38, 0x57, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x84, 0x31, 0x5E, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x85, 0x39, 0x5E, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x87, 0x77, 0x57, 0xE9,
-       0x8B, 0x3E, 0xBF, 0xEA,
-
-       0x80, 0x30, 0x57, 0xE9,
-       0x81, 0x38, 0x57, 0xE9,
-
-       0x82, 0x31, 0x57, 0xE9,
-       0x86, 0x78, 0x57, 0xE9,
-
-       0x83, 0x39, 0x57, 0xE9,
-       0x87, 0x79, 0x57, 0xE9,
-
-       0x30, 0x1F, 0x5F, 0xE9,
-       0x8A, 0x34, 0x20, 0xE9,
-
-       0x8B, 0x3C, 0x20, 0xE9,
-       0x37, 0x50, 0x60, 0xBD,
-
-       0x57, 0x0D, 0x20, 0xE9,
-       0x35, 0x51, 0x61, 0xBD,
-
-       0x2B, 0x50, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x0E, 0x77,
-
-       0x24, 0x51, 0x20, 0xE9,
-       0x8D, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x0E, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x0B, 0x46, 0xA0, 0xE8,
-       0x1B, 0x56, 0xA0, 0xE8,
-
-       0x2B, 0x66, 0xA0, 0xE8,
-       0x0C, 0x47, 0xA0, 0xE8,
-
-       0x1C, 0x57, 0xA0, 0xE8,
-       0x2C, 0x67, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x57, 0x80, 0x57, 0xCF,
-
-       0x66, 0x33, 0x66, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x67, 0x3B, 0x67, 0xCF,
-
-       0x0B, 0x48, 0xA0, 0xE8,
-       0x1B, 0x58, 0xA0, 0xE8,
-
-       0x2B, 0x68, 0xA0, 0xE8,
-       0x0C, 0x49, 0xA0, 0xE8,
-
-       0x1C, 0x59, 0xA0, 0xE8,
-       0x2C, 0x69, 0xA0, 0xE8,
-
-       0x0B, 0x00,
-       0x1B, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x0C, 0x00,
-       0x1C, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x0B, 0x65,
-       0x1B, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x0C, 0x65,
-       0x1C, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x0B, 0x1B, 0x60, 0xEC,
-       0x34, 0xD7, 0x34, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x0C, 0x1C, 0x60, 0xEC,
-
-       0x3C, 0xD7, 0x3C, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x0B, 0x2B, 0xDE, 0xE8,
-       0x1B, 0x80, 0xDE, 0xE8,
-
-       0x34, 0x80, 0x34, 0xBD,
-       0x3C, 0x80, 0x3C, 0xBD,
-
-       0x33, 0xD7, 0x0B, 0xBD,
-       0x3B, 0xD7, 0x1B, 0xBD,
-
-       0x48, 0x80, 0x48, 0xCF,
-       0x59, 0x80, 0x59, 0xCF,
-
-       0x68, 0x33, 0x68, 0xCF,
-       0x49, 0x3B, 0x49, 0xCF,
-
-       0xAD, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x58, 0x33, 0x58, 0xCF,
-       0x69, 0x3B, 0x69, 0xCF,
-
-       0x6B, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgz[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x58, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x4A, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x1D, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x2A, 0x44, 0x4C, 0xB4,
-       0x1A, 0x44, 0x54, 0xB4,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0xAF, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xD6, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x9D, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgza[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x5C, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x4E, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x27, 0xCF, 0x74, 0xC6,
-       0x3D, 0xCF, 0x74, 0xC2,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x20, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x27, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x4C, 0xB4,
-       0x02, 0x44, 0x54, 0xB4,
-
-       0x2A, 0x44, 0x4C, 0xB6,
-       0x1A, 0x44, 0x54, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0xAB, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xD3, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x99, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzaf[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x61, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x53, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x26, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x27, 0xCF, 0x74, 0xC6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x27, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x4C, 0xB4,
-       0x02, 0x44, 0x54, 0xB4,
-
-       0x2A, 0x44, 0x4C, 0xB6,
-       0x1A, 0x44, 0x54, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x3D, 0xCF, 0x75, 0xC6,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x45, 0x4D, 0xB6,
-       0x02, 0x45, 0x55, 0xB6,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x3D, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0xA6, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xCD, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x94, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzf[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x5D, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x4F, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x34, 0x80, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x27, 0xCF, 0x75, 0xC6,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x20, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x3D, 0xCF, 0x74, 0xC2,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x31, 0x27, 0x20, 0xE9,
-
-       0x0A, 0x44, 0x4C, 0xB4,
-       0x02, 0x44, 0x54, 0xB4,
-
-       0x2A, 0x45, 0x4D, 0xB6,
-       0x1A, 0x45, 0x55, 0xB6,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x38, 0x3D, 0x20, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0xAA, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xD3, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x98, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzs[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x65, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x57, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x27, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x29, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x27, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB4,
-       0x1A, 0x44, 0x54, 0xB4,
-
-       0x0A, 0x45, 0x4D, 0xB0,
-       0x02, 0x45, 0x55, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x4D, 0xB2,
-       0x1A, 0x45, 0x55, 0xB2,
-
-       0x0A, 0x45, 0x4D, 0xB4,
-       0x02, 0x45, 0x55, 0xB4,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x20,
-       0x02, 0x20,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA7, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0xA2, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xCA, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x90, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzsa[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x6A, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x5C, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x27, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x2E, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x27, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB4,
-       0x1A, 0x44, 0x54, 0xB4,
-
-       0x0A, 0x45, 0x4D, 0xB0,
-       0x02, 0x45, 0x55, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x4D, 0xB2,
-       0x1A, 0x45, 0x55, 0xB2,
-
-       0x0A, 0x45, 0x4D, 0xB4,
-       0x02, 0x45, 0x55, 0xB4,
-
-       0x27, 0xCF, 0x74, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB6,
-       0x1A, 0x44, 0x54, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0x9D, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xC5, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x8B, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzsaf[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x6E, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x60, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x27, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x32, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x27, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB4,
-       0x1A, 0x44, 0x54, 0xB4,
-
-       0x0A, 0x45, 0x4D, 0xB0,
-       0x02, 0x45, 0x55, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x4D, 0xB2,
-       0x1A, 0x45, 0x55, 0xB2,
-
-       0x0A, 0x45, 0x4D, 0xB4,
-       0x02, 0x45, 0x55, 0xB4,
-
-       0x27, 0xCF, 0x74, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9C, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB6,
-       0x1A, 0x44, 0x54, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x45, 0x4D, 0xB6,
-       0x02, 0x45, 0x55, 0xB6,
-
-       0x3D, 0xCF, 0x75, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x3D, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x9D, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x9E, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x30, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x38, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0x99, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xC1, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x87, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
-
-static unsigned char warp_g400_tgzsf[] = {
-
-       0x00, 0x88, 0x98, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-       0xFF, 0x80, 0xC0, 0xE9,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x22, 0x40, 0x48, 0xBF,
-       0x2A, 0x40, 0x50, 0xBF,
-
-       0x32, 0x41, 0x49, 0xBF,
-       0x3A, 0x41, 0x51, 0xBF,
-
-       0xC3, 0x6B,
-       0xCB, 0x6B,
-       0x00, 0x88, 0x98, 0xE9,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x96, 0xE2,
-       0x41, 0x04,
-
-       0x7B, 0x43, 0xA0, 0xE8,
-       0x73, 0x4B, 0xA0, 0xE8,
-
-       0xAD, 0xEE, 0x29, 0x9F,
-       0x00, 0xE0,
-       0x49, 0x04,
-
-       0x90, 0xE2,
-       0x51, 0x04,
-       0x31, 0x46, 0xB1, 0xE8,
-
-       0x49, 0x41, 0xC0, 0xEC,
-       0x39, 0x57, 0xB1, 0xE8,
-
-       0x00, 0x04,
-       0x46, 0xE2,
-       0x73, 0x53, 0xA0, 0xE8,
-
-       0x51, 0x41, 0xC0, 0xEC,
-       0x31, 0x00,
-       0x39, 0x00,
-
-       0x6A, 0x80, 0x15, 0xEA,
-       0x08, 0x04,
-       0x10, 0x04,
-
-       0x51, 0x49, 0xC0, 0xEC,
-       0x2F, 0x41, 0x60, 0xEA,
-
-       0x31, 0x20,
-       0x39, 0x20,
-       0x1F, 0x42, 0xA0, 0xE8,
-
-       0x2A, 0x42, 0x4A, 0xBF,
-       0x27, 0x4A, 0xA0, 0xE8,
-
-       0x1A, 0x42, 0x52, 0xBF,
-       0x1E, 0x49, 0x60, 0xEA,
-
-       0x73, 0x7B, 0xC8, 0xEC,
-       0x26, 0x51, 0x60, 0xEA,
-
-       0x32, 0x40, 0x48, 0xBD,
-       0x22, 0x40, 0x50, 0xBD,
-
-       0x12, 0x41, 0x49, 0xBD,
-       0x3A, 0x41, 0x51, 0xBD,
-
-       0xBF, 0x2F, 0x26, 0xBD,
-       0x00, 0xE0,
-       0x7B, 0x72,
-
-       0x32, 0x20,
-       0x22, 0x20,
-       0x12, 0x20,
-       0x3A, 0x20,
-
-       0x46, 0x31, 0x46, 0xBF,
-       0x4E, 0x31, 0x4E, 0xBF,
-
-       0xB3, 0xE2, 0x2D, 0x9F,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x56, 0x31, 0x56, 0xBF,
-       0x47, 0x39, 0x47, 0xBF,
-
-       0x4F, 0x39, 0x4F, 0xBF,
-       0x57, 0x39, 0x57, 0xBF,
-
-       0x5C, 0x80, 0x07, 0xEA,
-       0x24, 0x41, 0x20, 0xE9,
-
-       0x42, 0x73, 0xF8, 0xEC,
-       0x00, 0xE0,
-       0x2D, 0x73,
-
-       0x33, 0x72,
-       0x0C, 0xE3,
-       0xA5, 0x2F, 0x1E, 0xBD,
-
-       0x43, 0x43, 0x2D, 0xDF,
-       0x4B, 0x4B, 0x2D, 0xDF,
-
-       0xAE, 0x1E, 0x26, 0xBD,
-       0x58, 0xE3,
-       0x33, 0x66,
-
-       0x53, 0x53, 0x2D, 0xDF,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0xB8, 0x38, 0x33, 0xBF,
-       0x00, 0xE0,
-       0x59, 0xE3,
-
-       0x1E, 0x12, 0x41, 0xE9,
-       0x1A, 0x22, 0x41, 0xE9,
-
-       0x2B, 0x40, 0x3D, 0xE9,
-       0x3F, 0x4B, 0xA0, 0xE8,
-
-       0x2D, 0x73,
-       0x30, 0x76,
-       0x05, 0x80, 0x3D, 0xEA,
-
-       0x37, 0x43, 0xA0, 0xE8,
-       0x3D, 0x53, 0xA0, 0xE8,
-
-       0x48, 0x70, 0xF8, 0xEC,
-       0x2B, 0x48, 0x3C, 0xE9,
-
-       0x1F, 0x27, 0xBC, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x15, 0xC0, 0x20, 0xE9,
-       0x15, 0xC0, 0x20, 0xE9,
-
-       0x18, 0x3A, 0x41, 0xE9,
-       0x1D, 0x32, 0x41, 0xE9,
-
-       0x2A, 0x40, 0x20, 0xE9,
-       0x56, 0x3D, 0x56, 0xDF,
-
-       0x46, 0x37, 0x46, 0xDF,
-       0x4E, 0x3F, 0x4E, 0xDF,
-
-       0x16, 0x30, 0x20, 0xE9,
-       0x4F, 0x3F, 0x4F, 0xDF,
-
-       0x47, 0x37, 0x47, 0xDF,
-       0x57, 0x3D, 0x57, 0xDF,
-
-       0x32, 0x32, 0x2D, 0xDF,
-       0x22, 0x22, 0x2D, 0xDF,
-
-       0x12, 0x12, 0x2D, 0xDF,
-       0x3A, 0x3A, 0x2D, 0xDF,
-
-       0x27, 0xCF, 0x74, 0xC2,
-       0x37, 0xCF, 0x74, 0xC4,
-
-       0x0A, 0x44, 0x4C, 0xB0,
-       0x02, 0x44, 0x54, 0xB0,
-
-       0x3D, 0xCF, 0x74, 0xC0,
-       0x34, 0x37, 0x20, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x38, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3C, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB2,
-       0x1A, 0x44, 0x54, 0xB2,
-
-       0x2E, 0x80, 0x3A, 0xEA,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x27, 0xCF, 0x75, 0xC0,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x32, 0x31, 0x5F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x33, 0x39, 0x5F, 0xE9,
-
-       0x3D, 0xCF, 0x75, 0xC2,
-       0x37, 0xCF, 0x75, 0xC4,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA6, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA3, 0x3D, 0x20, 0xE9,
-
-       0x2A, 0x44, 0x4C, 0xB4,
-       0x1A, 0x44, 0x54, 0xB4,
-
-       0x0A, 0x45, 0x4D, 0xB0,
-       0x02, 0x45, 0x55, 0xB0,
-
-       0x88, 0x73, 0x5E, 0xE9,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA0, 0x37, 0x20, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x3E, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x3F, 0x38, 0x4F, 0xE9,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x3A, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x3B, 0x39, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x4D, 0xB2,
-       0x1A, 0x45, 0x55, 0xB2,
-
-       0x0A, 0x45, 0x4D, 0xB4,
-       0x02, 0x45, 0x55, 0xB4,
-
-       0x27, 0xCF, 0x75, 0xC6,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0xA7, 0x30, 0x4F, 0xE9,
-       0x0A, 0x20,
-       0x02, 0x20,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x31, 0x27, 0x20, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA8, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x45, 0x4D, 0xB6,
-       0x1A, 0x45, 0x55, 0xB6,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x36, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x37, 0x39, 0x4F, 0xE9,
-
-       0x00, 0x80, 0x00, 0xE8,
-       0x2A, 0x20,
-       0x1A, 0x20,
-
-       0x2A, 0x46, 0x4E, 0xBF,
-       0x1A, 0x46, 0x56, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA4, 0x31, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA5, 0x39, 0x4F, 0xE9,
-
-       0x0A, 0x47, 0x4F, 0xBF,
-       0x02, 0x47, 0x57, 0xBF,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0xA1, 0x30, 0x4F, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0xA2, 0x38, 0x4F, 0xE9,
-
-       0x2A, 0x43, 0x4B, 0xBF,
-       0x1A, 0x43, 0x53, 0xBF,
-
-       0x30, 0x50, 0x2E, 0x9F,
-       0x35, 0x31, 0x4F, 0xE9,
-
-       0x38, 0x21, 0x2C, 0x9F,
-       0x39, 0x39, 0x4F, 0xE9,
-
-       0x31, 0x53, 0x2F, 0x9F,
-       0x80, 0x31, 0x57, 0xE9,
-
-       0x39, 0xE5, 0x2C, 0x9F,
-       0x81, 0x39, 0x57, 0xE9,
-
-       0x37, 0x48, 0x50, 0xBD,
-       0x8A, 0x36, 0x20, 0xE9,
-
-       0x86, 0x76, 0x57, 0xE9,
-       0x8B, 0x3E, 0x20, 0xE9,
-
-       0x82, 0x30, 0x57, 0xE9,
-       0x87, 0x77, 0x57, 0xE9,
-
-       0x83, 0x38, 0x57, 0xE9,
-       0x35, 0x49, 0x51, 0xBD,
-
-       0x84, 0x31, 0x5E, 0xE9,
-       0x30, 0x1F, 0x5F, 0xE9,
-
-       0x85, 0x39, 0x5E, 0xE9,
-       0x57, 0x25, 0x20, 0xE9,
-
-       0x2B, 0x48, 0x20, 0xE9,
-       0x1D, 0x37, 0xE1, 0xEA,
-
-       0x1E, 0x35, 0xE1, 0xEA,
-       0x00, 0xE0,
-       0x26, 0x77,
-
-       0x24, 0x49, 0x20, 0xE9,
-       0x9D, 0xFF, 0x20, 0xEA,
-
-       0x16, 0x26, 0x20, 0xE9,
-       0x57, 0x2E, 0xBF, 0xEA,
-
-       0x1C, 0x46, 0xA0, 0xE8,
-       0x23, 0x4E, 0xA0, 0xE8,
-
-       0x2B, 0x56, 0xA0, 0xE8,
-       0x1D, 0x47, 0xA0, 0xE8,
-
-       0x24, 0x4F, 0xA0, 0xE8,
-       0x2C, 0x57, 0xA0, 0xE8,
-
-       0x1C, 0x00,
-       0x23, 0x00,
-       0x2B, 0x00,
-       0x00, 0xE0,
-
-       0x1D, 0x00,
-       0x24, 0x00,
-       0x2C, 0x00,
-       0x00, 0xE0,
-
-       0x1C, 0x65,
-       0x23, 0x65,
-       0x2B, 0x65,
-       0x00, 0xE0,
-
-       0x1D, 0x65,
-       0x24, 0x65,
-       0x2C, 0x65,
-       0x00, 0xE0,
-
-       0x1C, 0x23, 0x60, 0xEC,
-       0x36, 0xD7, 0x36, 0xAD,
-
-       0x2B, 0x80, 0x60, 0xEC,
-       0x1D, 0x24, 0x60, 0xEC,
-
-       0x3E, 0xD7, 0x3E, 0xAD,
-       0x2C, 0x80, 0x60, 0xEC,
-
-       0x1C, 0x2B, 0xDE, 0xE8,
-       0x23, 0x80, 0xDE, 0xE8,
-
-       0x36, 0x80, 0x36, 0xBD,
-       0x3E, 0x80, 0x3E, 0xBD,
-
-       0x33, 0xD7, 0x1C, 0xBD,
-       0x3B, 0xD7, 0x23, 0xBD,
-
-       0x46, 0x80, 0x46, 0xCF,
-       0x4F, 0x80, 0x4F, 0xCF,
-
-       0x56, 0x33, 0x56, 0xCF,
-       0x47, 0x3B, 0x47, 0xCF,
-
-       0xC5, 0xFF, 0x20, 0xEA,
-       0x00, 0x80, 0x00, 0xE8,
-
-       0x4E, 0x33, 0x4E, 0xCF,
-       0x57, 0x3B, 0x57, 0xCF,
-
-       0x8B, 0xFF, 0x20, 0xEA,
-       0x57, 0xC0, 0xBF, 0xEA,
-
-       0x00, 0x80, 0xA0, 0xE9,
-       0x00, 0x00, 0xD8, 0xEC,
-
-};
diff --git a/drivers/char/drm/mga_warp.c b/drivers/char/drm/mga_warp.c
deleted file mode 100644 (file)
index 651b93c..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/* mga_warp.c -- Matrox G200/G400 WARP engine management -*- linux-c -*-
- * Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
- *
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "mga_drm.h"
-#include "mga_drv.h"
-#include "mga_ucode.h"
-
-#define MGA_WARP_CODE_ALIGN            256     /* in bytes */
-
-#define WARP_UCODE_SIZE( which )                                       \
-       ((sizeof(which) / MGA_WARP_CODE_ALIGN + 1) * MGA_WARP_CODE_ALIGN)
-
-#define WARP_UCODE_INSTALL( which, where )                             \
-do {                                                                   \
-       DRM_DEBUG( " pcbase = 0x%08lx  vcbase = %p\n", pcbase, vcbase );\
-       dev_priv->warp_pipe_phys[where] = pcbase;                       \
-       memcpy( vcbase, which, sizeof(which) );                         \
-       pcbase += WARP_UCODE_SIZE( which );                             \
-       vcbase += WARP_UCODE_SIZE( which );                             \
-} while (0)
-
-static const unsigned int mga_warp_g400_microcode_size =
-    (WARP_UCODE_SIZE(warp_g400_tgz) +
-     WARP_UCODE_SIZE(warp_g400_tgza) +
-     WARP_UCODE_SIZE(warp_g400_tgzaf) +
-     WARP_UCODE_SIZE(warp_g400_tgzf) +
-     WARP_UCODE_SIZE(warp_g400_tgzs) +
-     WARP_UCODE_SIZE(warp_g400_tgzsa) +
-     WARP_UCODE_SIZE(warp_g400_tgzsaf) +
-     WARP_UCODE_SIZE(warp_g400_tgzsf) +
-     WARP_UCODE_SIZE(warp_g400_t2gz) +
-     WARP_UCODE_SIZE(warp_g400_t2gza) +
-     WARP_UCODE_SIZE(warp_g400_t2gzaf) +
-     WARP_UCODE_SIZE(warp_g400_t2gzf) +
-     WARP_UCODE_SIZE(warp_g400_t2gzs) +
-     WARP_UCODE_SIZE(warp_g400_t2gzsa) +
-     WARP_UCODE_SIZE(warp_g400_t2gzsaf) + WARP_UCODE_SIZE(warp_g400_t2gzsf));
-
-static const unsigned int mga_warp_g200_microcode_size =
-    (WARP_UCODE_SIZE(warp_g200_tgz) +
-     WARP_UCODE_SIZE(warp_g200_tgza) +
-     WARP_UCODE_SIZE(warp_g200_tgzaf) +
-     WARP_UCODE_SIZE(warp_g200_tgzf) +
-     WARP_UCODE_SIZE(warp_g200_tgzs) +
-     WARP_UCODE_SIZE(warp_g200_tgzsa) +
-     WARP_UCODE_SIZE(warp_g200_tgzsaf) + WARP_UCODE_SIZE(warp_g200_tgzsf));
-
-unsigned int mga_warp_microcode_size(const drm_mga_private_t * dev_priv)
-{
-       switch (dev_priv->chipset) {
-       case MGA_CARD_TYPE_G400:
-       case MGA_CARD_TYPE_G550:
-               return PAGE_ALIGN(mga_warp_g400_microcode_size);
-       case MGA_CARD_TYPE_G200:
-               return PAGE_ALIGN(mga_warp_g200_microcode_size);
-       default:
-               return 0;
-       }
-}
-
-static int mga_warp_install_g400_microcode(drm_mga_private_t * dev_priv)
-{
-       unsigned char *vcbase = dev_priv->warp->handle;
-       unsigned long pcbase = dev_priv->warp->offset;
-
-       memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
-
-       WARP_UCODE_INSTALL(warp_g400_tgz, MGA_WARP_TGZ);
-       WARP_UCODE_INSTALL(warp_g400_tgzf, MGA_WARP_TGZF);
-       WARP_UCODE_INSTALL(warp_g400_tgza, MGA_WARP_TGZA);
-       WARP_UCODE_INSTALL(warp_g400_tgzaf, MGA_WARP_TGZAF);
-       WARP_UCODE_INSTALL(warp_g400_tgzs, MGA_WARP_TGZS);
-       WARP_UCODE_INSTALL(warp_g400_tgzsf, MGA_WARP_TGZSF);
-       WARP_UCODE_INSTALL(warp_g400_tgzsa, MGA_WARP_TGZSA);
-       WARP_UCODE_INSTALL(warp_g400_tgzsaf, MGA_WARP_TGZSAF);
-
-       WARP_UCODE_INSTALL(warp_g400_t2gz, MGA_WARP_T2GZ);
-       WARP_UCODE_INSTALL(warp_g400_t2gzf, MGA_WARP_T2GZF);
-       WARP_UCODE_INSTALL(warp_g400_t2gza, MGA_WARP_T2GZA);
-       WARP_UCODE_INSTALL(warp_g400_t2gzaf, MGA_WARP_T2GZAF);
-       WARP_UCODE_INSTALL(warp_g400_t2gzs, MGA_WARP_T2GZS);
-       WARP_UCODE_INSTALL(warp_g400_t2gzsf, MGA_WARP_T2GZSF);
-       WARP_UCODE_INSTALL(warp_g400_t2gzsa, MGA_WARP_T2GZSA);
-       WARP_UCODE_INSTALL(warp_g400_t2gzsaf, MGA_WARP_T2GZSAF);
-
-       return 0;
-}
-
-static int mga_warp_install_g200_microcode(drm_mga_private_t * dev_priv)
-{
-       unsigned char *vcbase = dev_priv->warp->handle;
-       unsigned long pcbase = dev_priv->warp->offset;
-
-       memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
-
-       WARP_UCODE_INSTALL(warp_g200_tgz, MGA_WARP_TGZ);
-       WARP_UCODE_INSTALL(warp_g200_tgzf, MGA_WARP_TGZF);
-       WARP_UCODE_INSTALL(warp_g200_tgza, MGA_WARP_TGZA);
-       WARP_UCODE_INSTALL(warp_g200_tgzaf, MGA_WARP_TGZAF);
-       WARP_UCODE_INSTALL(warp_g200_tgzs, MGA_WARP_TGZS);
-       WARP_UCODE_INSTALL(warp_g200_tgzsf, MGA_WARP_TGZSF);
-       WARP_UCODE_INSTALL(warp_g200_tgzsa, MGA_WARP_TGZSA);
-       WARP_UCODE_INSTALL(warp_g200_tgzsaf, MGA_WARP_TGZSAF);
-
-       return 0;
-}
-
-int mga_warp_install_microcode(drm_mga_private_t * dev_priv)
-{
-       const unsigned int size = mga_warp_microcode_size(dev_priv);
-
-       DRM_DEBUG("MGA ucode size = %d bytes\n", size);
-       if (size > dev_priv->warp->size) {
-               DRM_ERROR("microcode too large! (%u > %lu)\n",
-                         size, dev_priv->warp->size);
-               return -ENOMEM;
-       }
-
-       switch (dev_priv->chipset) {
-       case MGA_CARD_TYPE_G400:
-       case MGA_CARD_TYPE_G550:
-               return mga_warp_install_g400_microcode(dev_priv);
-       case MGA_CARD_TYPE_G200:
-               return mga_warp_install_g200_microcode(dev_priv);
-       default:
-               return -EINVAL;
-       }
-}
-
-#define WMISC_EXPECTED         (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
-
-int mga_warp_init(drm_mga_private_t * dev_priv)
-{
-       u32 wmisc;
-
-       /* FIXME: Get rid of these damned magic numbers...
-        */
-       switch (dev_priv->chipset) {
-       case MGA_CARD_TYPE_G400:
-       case MGA_CARD_TYPE_G550:
-               MGA_WRITE(MGA_WIADDR2, MGA_WMODE_SUSPEND);
-               MGA_WRITE(MGA_WGETMSB, 0x00000E00);
-               MGA_WRITE(MGA_WVRTXSZ, 0x00001807);
-               MGA_WRITE(MGA_WACCEPTSEQ, 0x18000000);
-               break;
-       case MGA_CARD_TYPE_G200:
-               MGA_WRITE(MGA_WIADDR, MGA_WMODE_SUSPEND);
-               MGA_WRITE(MGA_WGETMSB, 0x1606);
-               MGA_WRITE(MGA_WVRTXSZ, 7);
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       MGA_WRITE(MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
-                             MGA_WMASTER_ENABLE | MGA_WCACHEFLUSH_ENABLE));
-       wmisc = MGA_READ(MGA_WMISC);
-       if (wmisc != WMISC_EXPECTED) {
-               DRM_ERROR("WARP engine config failed! 0x%x != 0x%x\n",
-                         wmisc, WMISC_EXPECTED);
-               return -EINVAL;
-       }
-
-       return 0;
-}
diff --git a/drivers/char/drm/r128_cce.c b/drivers/char/drm/r128_cce.c
deleted file mode 100644 (file)
index c31afbd..0000000
+++ /dev/null
@@ -1,935 +0,0 @@
-/* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*-
- * Created: Wed Apr  5 19:24:19 2000 by kevin@precisioninsight.com
- */
-/*
- * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "r128_drm.h"
-#include "r128_drv.h"
-
-#define R128_FIFO_DEBUG                0
-
-/* CCE microcode (from ATI) */
-static u32 r128_cce_microcode[] = {
-       0, 276838400, 0, 268449792, 2, 142, 2, 145, 0, 1076765731, 0,
-       1617039951, 0, 774592877, 0, 1987540286, 0, 2307490946U, 0,
-       599558925, 0, 589505315, 0, 596487092, 0, 589505315, 1,
-       11544576, 1, 206848, 1, 311296, 1, 198656, 2, 912273422, 11,
-       262144, 0, 0, 1, 33559837, 1, 7438, 1, 14809, 1, 6615, 12, 28,
-       1, 6614, 12, 28, 2, 23, 11, 18874368, 0, 16790922, 1, 409600, 9,
-       30, 1, 147854772, 16, 420483072, 3, 8192, 0, 10240, 1, 198656,
-       1, 15630, 1, 51200, 10, 34858, 9, 42, 1, 33559823, 2, 10276, 1,
-       15717, 1, 15718, 2, 43, 1, 15936948, 1, 570480831, 1, 14715071,
-       12, 322123831, 1, 33953125, 12, 55, 1, 33559908, 1, 15718, 2,
-       46, 4, 2099258, 1, 526336, 1, 442623, 4, 4194365, 1, 509952, 1,
-       459007, 3, 0, 12, 92, 2, 46, 12, 176, 1, 15734, 1, 206848, 1,
-       18432, 1, 133120, 1, 100670734, 1, 149504, 1, 165888, 1,
-       15975928, 1, 1048576, 6, 3145806, 1, 15715, 16, 2150645232U, 2,
-       268449859, 2, 10307, 12, 176, 1, 15734, 1, 15735, 1, 15630, 1,
-       15631, 1, 5253120, 6, 3145810, 16, 2150645232U, 1, 15864, 2, 82,
-       1, 343310, 1, 1064207, 2, 3145813, 1, 15728, 1, 7817, 1, 15729,
-       3, 15730, 12, 92, 2, 98, 1, 16168, 1, 16167, 1, 16002, 1, 16008,
-       1, 15974, 1, 15975, 1, 15990, 1, 15976, 1, 15977, 1, 15980, 0,
-       15981, 1, 10240, 1, 5253120, 1, 15720, 1, 198656, 6, 110, 1,
-       180224, 1, 103824738, 2, 112, 2, 3145839, 0, 536885440, 1,
-       114880, 14, 125, 12, 206975, 1, 33559995, 12, 198784, 0,
-       33570236, 1, 15803, 0, 15804, 3, 294912, 1, 294912, 3, 442370,
-       1, 11544576, 0, 811612160, 1, 12593152, 1, 11536384, 1,
-       14024704, 7, 310382726, 0, 10240, 1, 14796, 1, 14797, 1, 14793,
-       1, 14794, 0, 14795, 1, 268679168, 1, 9437184, 1, 268449792, 1,
-       198656, 1, 9452827, 1, 1075854602, 1, 1075854603, 1, 557056, 1,
-       114880, 14, 159, 12, 198784, 1, 1109409213, 12, 198783, 1,
-       1107312059, 12, 198784, 1, 1109409212, 2, 162, 1, 1075854781, 1,
-       1073757627, 1, 1075854780, 1, 540672, 1, 10485760, 6, 3145894,
-       16, 274741248, 9, 168, 3, 4194304, 3, 4209949, 0, 0, 0, 256, 14,
-       174, 1, 114857, 1, 33560007, 12, 176, 0, 10240, 1, 114858, 1,
-       33560018, 1, 114857, 3, 33560007, 1, 16008, 1, 114874, 1,
-       33560360, 1, 114875, 1, 33560154, 0, 15963, 0, 256, 0, 4096, 1,
-       409611, 9, 188, 0, 10240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-static int R128_READ_PLL(struct drm_device * dev, int addr)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-
-       R128_WRITE8(R128_CLOCK_CNTL_INDEX, addr & 0x1f);
-       return R128_READ(R128_CLOCK_CNTL_DATA);
-}
-
-#if R128_FIFO_DEBUG
-static void r128_status(drm_r128_private_t * dev_priv)
-{
-       printk("GUI_STAT           = 0x%08x\n",
-              (unsigned int)R128_READ(R128_GUI_STAT));
-       printk("PM4_STAT           = 0x%08x\n",
-              (unsigned int)R128_READ(R128_PM4_STAT));
-       printk("PM4_BUFFER_DL_WPTR = 0x%08x\n",
-              (unsigned int)R128_READ(R128_PM4_BUFFER_DL_WPTR));
-       printk("PM4_BUFFER_DL_RPTR = 0x%08x\n",
-              (unsigned int)R128_READ(R128_PM4_BUFFER_DL_RPTR));
-       printk("PM4_MICRO_CNTL     = 0x%08x\n",
-              (unsigned int)R128_READ(R128_PM4_MICRO_CNTL));
-       printk("PM4_BUFFER_CNTL    = 0x%08x\n",
-              (unsigned int)R128_READ(R128_PM4_BUFFER_CNTL));
-}
-#endif
-
-/* ================================================================
- * Engine, FIFO control
- */
-
-static int r128_do_pixcache_flush(drm_r128_private_t * dev_priv)
-{
-       u32 tmp;
-       int i;
-
-       tmp = R128_READ(R128_PC_NGUI_CTLSTAT) | R128_PC_FLUSH_ALL;
-       R128_WRITE(R128_PC_NGUI_CTLSTAT, tmp);
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               if (!(R128_READ(R128_PC_NGUI_CTLSTAT) & R128_PC_BUSY)) {
-                       return 0;
-               }
-               DRM_UDELAY(1);
-       }
-
-#if R128_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-#endif
-       return -EBUSY;
-}
-
-static int r128_do_wait_for_fifo(drm_r128_private_t * dev_priv, int entries)
-{
-       int i;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               int slots = R128_READ(R128_GUI_STAT) & R128_GUI_FIFOCNT_MASK;
-               if (slots >= entries)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if R128_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-#endif
-       return -EBUSY;
-}
-
-static int r128_do_wait_for_idle(drm_r128_private_t * dev_priv)
-{
-       int i, ret;
-
-       ret = r128_do_wait_for_fifo(dev_priv, 64);
-       if (ret)
-               return ret;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               if (!(R128_READ(R128_GUI_STAT) & R128_GUI_ACTIVE)) {
-                       r128_do_pixcache_flush(dev_priv);
-                       return 0;
-               }
-               DRM_UDELAY(1);
-       }
-
-#if R128_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-#endif
-       return -EBUSY;
-}
-
-/* ================================================================
- * CCE control, initialization
- */
-
-/* Load the microcode for the CCE */
-static void r128_cce_load_microcode(drm_r128_private_t * dev_priv)
-{
-       int i;
-
-       DRM_DEBUG("\n");
-
-       r128_do_wait_for_idle(dev_priv);
-
-       R128_WRITE(R128_PM4_MICROCODE_ADDR, 0);
-       for (i = 0; i < 256; i++) {
-               R128_WRITE(R128_PM4_MICROCODE_DATAH, r128_cce_microcode[i * 2]);
-               R128_WRITE(R128_PM4_MICROCODE_DATAL,
-                          r128_cce_microcode[i * 2 + 1]);
-       }
-}
-
-/* Flush any pending commands to the CCE.  This should only be used just
- * prior to a wait for idle, as it informs the engine that the command
- * stream is ending.
- */
-static void r128_do_cce_flush(drm_r128_private_t * dev_priv)
-{
-       u32 tmp;
-
-       tmp = R128_READ(R128_PM4_BUFFER_DL_WPTR) | R128_PM4_BUFFER_DL_DONE;
-       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, tmp);
-}
-
-/* Wait for the CCE to go idle.
- */
-int r128_do_cce_idle(drm_r128_private_t * dev_priv)
-{
-       int i;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               if (GET_RING_HEAD(dev_priv) == dev_priv->ring.tail) {
-                       int pm4stat = R128_READ(R128_PM4_STAT);
-                       if (((pm4stat & R128_PM4_FIFOCNT_MASK) >=
-                            dev_priv->cce_fifo_size) &&
-                           !(pm4stat & (R128_PM4_BUSY |
-                                        R128_PM4_GUI_ACTIVE))) {
-                               return r128_do_pixcache_flush(dev_priv);
-                       }
-               }
-               DRM_UDELAY(1);
-       }
-
-#if R128_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-       r128_status(dev_priv);
-#endif
-       return -EBUSY;
-}
-
-/* Start the Concurrent Command Engine.
- */
-static void r128_do_cce_start(drm_r128_private_t * dev_priv)
-{
-       r128_do_wait_for_idle(dev_priv);
-
-       R128_WRITE(R128_PM4_BUFFER_CNTL,
-                  dev_priv->cce_mode | dev_priv->ring.size_l2qw
-                  | R128_PM4_BUFFER_CNTL_NOUPDATE);
-       R128_READ(R128_PM4_BUFFER_ADDR);        /* as per the sample code */
-       R128_WRITE(R128_PM4_MICRO_CNTL, R128_PM4_MICRO_FREERUN);
-
-       dev_priv->cce_running = 1;
-}
-
-/* Reset the Concurrent Command Engine.  This will not flush any pending
- * commands, so you must wait for the CCE command stream to complete
- * before calling this routine.
- */
-static void r128_do_cce_reset(drm_r128_private_t * dev_priv)
-{
-       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0);
-       R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0);
-       dev_priv->ring.tail = 0;
-}
-
-/* Stop the Concurrent Command Engine.  This will not flush any pending
- * commands, so you must flush the command stream and wait for the CCE
- * to go idle before calling this routine.
- */
-static void r128_do_cce_stop(drm_r128_private_t * dev_priv)
-{
-       R128_WRITE(R128_PM4_MICRO_CNTL, 0);
-       R128_WRITE(R128_PM4_BUFFER_CNTL,
-                  R128_PM4_NONPM4 | R128_PM4_BUFFER_CNTL_NOUPDATE);
-
-       dev_priv->cce_running = 0;
-}
-
-/* Reset the engine.  This will stop the CCE if it is running.
- */
-static int r128_do_engine_reset(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       u32 clock_cntl_index, mclk_cntl, gen_reset_cntl;
-
-       r128_do_pixcache_flush(dev_priv);
-
-       clock_cntl_index = R128_READ(R128_CLOCK_CNTL_INDEX);
-       mclk_cntl = R128_READ_PLL(dev, R128_MCLK_CNTL);
-
-       R128_WRITE_PLL(R128_MCLK_CNTL,
-                      mclk_cntl | R128_FORCE_GCP | R128_FORCE_PIPE3D_CP);
-
-       gen_reset_cntl = R128_READ(R128_GEN_RESET_CNTL);
-
-       /* Taken from the sample code - do not change */
-       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl | R128_SOFT_RESET_GUI);
-       R128_READ(R128_GEN_RESET_CNTL);
-       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl & ~R128_SOFT_RESET_GUI);
-       R128_READ(R128_GEN_RESET_CNTL);
-
-       R128_WRITE_PLL(R128_MCLK_CNTL, mclk_cntl);
-       R128_WRITE(R128_CLOCK_CNTL_INDEX, clock_cntl_index);
-       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl);
-
-       /* Reset the CCE ring */
-       r128_do_cce_reset(dev_priv);
-
-       /* The CCE is no longer running after an engine reset */
-       dev_priv->cce_running = 0;
-
-       /* Reset any pending vertex, indirect buffers */
-       r128_freelist_reset(dev);
-
-       return 0;
-}
-
-static void r128_cce_init_ring_buffer(struct drm_device * dev,
-                                     drm_r128_private_t * dev_priv)
-{
-       u32 ring_start;
-       u32 tmp;
-
-       DRM_DEBUG("\n");
-
-       /* The manual (p. 2) says this address is in "VM space".  This
-        * means it's an offset from the start of AGP space.
-        */
-#if __OS_HAS_AGP
-       if (!dev_priv->is_pci)
-               ring_start = dev_priv->cce_ring->offset - dev->agp->base;
-       else
-#endif
-               ring_start = dev_priv->cce_ring->offset -
-                   (unsigned long)dev->sg->virtual;
-
-       R128_WRITE(R128_PM4_BUFFER_OFFSET, ring_start | R128_AGP_OFFSET);
-
-       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0);
-       R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0);
-
-       /* Set watermark control */
-       R128_WRITE(R128_PM4_BUFFER_WM_CNTL,
-                  ((R128_WATERMARK_L / 4) << R128_WMA_SHIFT)
-                  | ((R128_WATERMARK_M / 4) << R128_WMB_SHIFT)
-                  | ((R128_WATERMARK_N / 4) << R128_WMC_SHIFT)
-                  | ((R128_WATERMARK_K / 64) << R128_WB_WM_SHIFT));
-
-       /* Force read.  Why?  Because it's in the examples... */
-       R128_READ(R128_PM4_BUFFER_ADDR);
-
-       /* Turn on bus mastering */
-       tmp = R128_READ(R128_BUS_CNTL) & ~R128_BUS_MASTER_DIS;
-       R128_WRITE(R128_BUS_CNTL, tmp);
-}
-
-static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
-{
-       drm_r128_private_t *dev_priv;
-
-       DRM_DEBUG("\n");
-
-       dev_priv = drm_alloc(sizeof(drm_r128_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv, 0, sizeof(drm_r128_private_t));
-
-       dev_priv->is_pci = init->is_pci;
-
-       if (dev_priv->is_pci && !dev->sg) {
-               DRM_ERROR("PCI GART memory not allocated!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->usec_timeout = init->usec_timeout;
-       if (dev_priv->usec_timeout < 1 ||
-           dev_priv->usec_timeout > R128_MAX_USEC_TIMEOUT) {
-               DRM_DEBUG("TIMEOUT problem!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->cce_mode = init->cce_mode;
-
-       /* GH: Simple idle check.
-        */
-       atomic_set(&dev_priv->idle_count, 0);
-
-       /* We don't support anything other than bus-mastering ring mode,
-        * but the ring can be in either AGP or PCI space for the ring
-        * read pointer.
-        */
-       if ((init->cce_mode != R128_PM4_192BM) &&
-           (init->cce_mode != R128_PM4_128BM_64INDBM) &&
-           (init->cce_mode != R128_PM4_64BM_128INDBM) &&
-           (init->cce_mode != R128_PM4_64BM_64VCBM_64INDBM)) {
-               DRM_DEBUG("Bad cce_mode!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-
-       switch (init->cce_mode) {
-       case R128_PM4_NONPM4:
-               dev_priv->cce_fifo_size = 0;
-               break;
-       case R128_PM4_192PIO:
-       case R128_PM4_192BM:
-               dev_priv->cce_fifo_size = 192;
-               break;
-       case R128_PM4_128PIO_64INDBM:
-       case R128_PM4_128BM_64INDBM:
-               dev_priv->cce_fifo_size = 128;
-               break;
-       case R128_PM4_64PIO_128INDBM:
-       case R128_PM4_64BM_128INDBM:
-       case R128_PM4_64PIO_64VCBM_64INDBM:
-       case R128_PM4_64BM_64VCBM_64INDBM:
-       case R128_PM4_64PIO_64VCPIO_64INDPIO:
-               dev_priv->cce_fifo_size = 64;
-               break;
-       }
-
-       switch (init->fb_bpp) {
-       case 16:
-               dev_priv->color_fmt = R128_DATATYPE_RGB565;
-               break;
-       case 32:
-       default:
-               dev_priv->color_fmt = R128_DATATYPE_ARGB8888;
-               break;
-       }
-       dev_priv->front_offset = init->front_offset;
-       dev_priv->front_pitch = init->front_pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->back_pitch = init->back_pitch;
-
-       switch (init->depth_bpp) {
-       case 16:
-               dev_priv->depth_fmt = R128_DATATYPE_RGB565;
-               break;
-       case 24:
-       case 32:
-       default:
-               dev_priv->depth_fmt = R128_DATATYPE_ARGB8888;
-               break;
-       }
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->depth_pitch = init->depth_pitch;
-       dev_priv->span_offset = init->span_offset;
-
-       dev_priv->front_pitch_offset_c = (((dev_priv->front_pitch / 8) << 21) |
-                                         (dev_priv->front_offset >> 5));
-       dev_priv->back_pitch_offset_c = (((dev_priv->back_pitch / 8) << 21) |
-                                        (dev_priv->back_offset >> 5));
-       dev_priv->depth_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) |
-                                         (dev_priv->depth_offset >> 5) |
-                                         R128_DST_TILE);
-       dev_priv->span_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) |
-                                        (dev_priv->span_offset >> 5));
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("could not find sarea!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
-       if (!dev_priv->mmio) {
-               DRM_ERROR("could not find mmio region!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-       dev_priv->cce_ring = drm_core_findmap(dev, init->ring_offset);
-       if (!dev_priv->cce_ring) {
-               DRM_ERROR("could not find cce ring region!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-       dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
-       if (!dev_priv->ring_rptr) {
-               DRM_ERROR("could not find ring read pointer!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-       dev->agp_buffer_token = init->buffers_offset;
-       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
-       if (!dev->agp_buffer_map) {
-               DRM_ERROR("could not find dma buffer region!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce(dev);
-               return -EINVAL;
-       }
-
-       if (!dev_priv->is_pci) {
-               dev_priv->agp_textures =
-                   drm_core_findmap(dev, init->agp_textures_offset);
-               if (!dev_priv->agp_textures) {
-                       DRM_ERROR("could not find agp texture region!\n");
-                       dev->dev_private = (void *)dev_priv;
-                       r128_do_cleanup_cce(dev);
-                       return -EINVAL;
-               }
-       }
-
-       dev_priv->sarea_priv =
-           (drm_r128_sarea_t *) ((u8 *) dev_priv->sarea->handle +
-                                 init->sarea_priv_offset);
-
-#if __OS_HAS_AGP
-       if (!dev_priv->is_pci) {
-               drm_core_ioremap(dev_priv->cce_ring, dev);
-               drm_core_ioremap(dev_priv->ring_rptr, dev);
-               drm_core_ioremap(dev->agp_buffer_map, dev);
-               if (!dev_priv->cce_ring->handle ||
-                   !dev_priv->ring_rptr->handle ||
-                   !dev->agp_buffer_map->handle) {
-                       DRM_ERROR("Could not ioremap agp regions!\n");
-                       dev->dev_private = (void *)dev_priv;
-                       r128_do_cleanup_cce(dev);
-                       return -ENOMEM;
-               }
-       } else
-#endif
-       {
-               dev_priv->cce_ring->handle = (void *)dev_priv->cce_ring->offset;
-               dev_priv->ring_rptr->handle =
-                   (void *)dev_priv->ring_rptr->offset;
-               dev->agp_buffer_map->handle =
-                   (void *)dev->agp_buffer_map->offset;
-       }
-
-#if __OS_HAS_AGP
-       if (!dev_priv->is_pci)
-               dev_priv->cce_buffers_offset = dev->agp->base;
-       else
-#endif
-               dev_priv->cce_buffers_offset = (unsigned long)dev->sg->virtual;
-
-       dev_priv->ring.start = (u32 *) dev_priv->cce_ring->handle;
-       dev_priv->ring.end = ((u32 *) dev_priv->cce_ring->handle
-                             + init->ring_size / sizeof(u32));
-       dev_priv->ring.size = init->ring_size;
-       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
-
-       dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
-
-       dev_priv->ring.high_mark = 128;
-
-       dev_priv->sarea_priv->last_frame = 0;
-       R128_WRITE(R128_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
-
-       dev_priv->sarea_priv->last_dispatch = 0;
-       R128_WRITE(R128_LAST_DISPATCH_REG, dev_priv->sarea_priv->last_dispatch);
-
-#if __OS_HAS_AGP
-       if (dev_priv->is_pci) {
-#endif
-               dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
-               dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
-               dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE;
-               dev_priv->gart_info.addr = NULL;
-               dev_priv->gart_info.bus_addr = 0;
-               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
-               if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
-                       DRM_ERROR("failed to init PCI GART!\n");
-                       dev->dev_private = (void *)dev_priv;
-                       r128_do_cleanup_cce(dev);
-                       return -ENOMEM;
-               }
-               R128_WRITE(R128_PCI_GART_PAGE, dev_priv->gart_info.bus_addr);
-#if __OS_HAS_AGP
-       }
-#endif
-
-       r128_cce_init_ring_buffer(dev, dev_priv);
-       r128_cce_load_microcode(dev_priv);
-
-       dev->dev_private = (void *)dev_priv;
-
-       r128_do_engine_reset(dev);
-
-       return 0;
-}
-
-int r128_do_cleanup_cce(struct drm_device * dev)
-{
-
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-       if (dev->dev_private) {
-               drm_r128_private_t *dev_priv = dev->dev_private;
-
-#if __OS_HAS_AGP
-               if (!dev_priv->is_pci) {
-                       if (dev_priv->cce_ring != NULL)
-                               drm_core_ioremapfree(dev_priv->cce_ring, dev);
-                       if (dev_priv->ring_rptr != NULL)
-                               drm_core_ioremapfree(dev_priv->ring_rptr, dev);
-                       if (dev->agp_buffer_map != NULL) {
-                               drm_core_ioremapfree(dev->agp_buffer_map, dev);
-                               dev->agp_buffer_map = NULL;
-                       }
-               } else
-#endif
-               {
-                       if (dev_priv->gart_info.bus_addr)
-                               if (!drm_ati_pcigart_cleanup(dev,
-                                                       &dev_priv->gart_info))
-                                       DRM_ERROR
-                                           ("failed to cleanup PCI GART!\n");
-               }
-
-               drm_free(dev->dev_private, sizeof(drm_r128_private_t),
-                        DRM_MEM_DRIVER);
-               dev->dev_private = NULL;
-       }
-
-       return 0;
-}
-
-int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_init_t *init = data;
-
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       switch (init->func) {
-       case R128_INIT_CCE:
-               return r128_do_init_cce(dev, init);
-       case R128_CLEANUP_CCE:
-               return r128_do_cleanup_cce(dev);
-       }
-
-       return -EINVAL;
-}
-
-int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4) {
-               DRM_DEBUG("while CCE running\n");
-               return 0;
-       }
-
-       r128_do_cce_start(dev_priv);
-
-       return 0;
-}
-
-/* Stop the CCE.  The engine must have been idled before calling this
- * routine.
- */
-int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_cce_stop_t *stop = data;
-       int ret;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* Flush any pending CCE commands.  This ensures any outstanding
-        * commands are exectuted by the engine before we turn it off.
-        */
-       if (stop->flush) {
-               r128_do_cce_flush(dev_priv);
-       }
-
-       /* If we fail to make the engine go idle, we return an error
-        * code so that the DRM ioctl wrapper can try again.
-        */
-       if (stop->idle) {
-               ret = r128_do_cce_idle(dev_priv);
-               if (ret)
-                       return ret;
-       }
-
-       /* Finally, we can turn off the CCE.  If the engine isn't idle,
-        * we will get some dropped triangles as they won't be fully
-        * rendered before the CCE is shut down.
-        */
-       r128_do_cce_stop(dev_priv);
-
-       /* Reset the engine */
-       r128_do_engine_reset(dev);
-
-       return 0;
-}
-
-/* Just reset the CCE ring.  Called as part of an X Server engine reset.
- */
-int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_DEBUG("called before init done\n");
-               return -EINVAL;
-       }
-
-       r128_do_cce_reset(dev_priv);
-
-       /* The CCE is no longer running after an engine reset */
-       dev_priv->cce_running = 0;
-
-       return 0;
-}
-
-int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (dev_priv->cce_running) {
-               r128_do_cce_flush(dev_priv);
-       }
-
-       return r128_do_cce_idle(dev_priv);
-}
-
-int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return r128_do_engine_reset(dev);
-}
-
-int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       return -EINVAL;
-}
-
-/* ================================================================
- * Freelist management
- */
-#define R128_BUFFER_USED       0xffffffff
-#define R128_BUFFER_FREE       0
-
-#if 0
-static int r128_freelist_init(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       struct drm_buf *buf;
-       drm_r128_buf_priv_t *buf_priv;
-       drm_r128_freelist_t *entry;
-       int i;
-
-       dev_priv->head = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
-       if (dev_priv->head == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv->head, 0, sizeof(drm_r128_freelist_t));
-       dev_priv->head->age = R128_BUFFER_USED;
-
-       for (i = 0; i < dma->buf_count; i++) {
-               buf = dma->buflist[i];
-               buf_priv = buf->dev_private;
-
-               entry = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
-               if (!entry)
-                       return -ENOMEM;
-
-               entry->age = R128_BUFFER_FREE;
-               entry->buf = buf;
-               entry->prev = dev_priv->head;
-               entry->next = dev_priv->head->next;
-               if (!entry->next)
-                       dev_priv->tail = entry;
-
-               buf_priv->discard = 0;
-               buf_priv->dispatched = 0;
-               buf_priv->list_entry = entry;
-
-               dev_priv->head->next = entry;
-
-               if (dev_priv->head->next)
-                       dev_priv->head->next->prev = entry;
-       }
-
-       return 0;
-
-}
-#endif
-
-static struct drm_buf *r128_freelist_get(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_buf_priv_t *buf_priv;
-       struct drm_buf *buf;
-       int i, t;
-
-       /* FIXME: Optimize -- use freelist code */
-
-       for (i = 0; i < dma->buf_count; i++) {
-               buf = dma->buflist[i];
-               buf_priv = buf->dev_private;
-               if (!buf->file_priv)
-                       return buf;
-       }
-
-       for (t = 0; t < dev_priv->usec_timeout; t++) {
-               u32 done_age = R128_READ(R128_LAST_DISPATCH_REG);
-
-               for (i = 0; i < dma->buf_count; i++) {
-                       buf = dma->buflist[i];
-                       buf_priv = buf->dev_private;
-                       if (buf->pending && buf_priv->age <= done_age) {
-                               /* The buffer has been processed, so it
-                                * can now be used.
-                                */
-                               buf->pending = 0;
-                               return buf;
-                       }
-               }
-               DRM_UDELAY(1);
-       }
-
-       DRM_DEBUG("returning NULL!\n");
-       return NULL;
-}
-
-void r128_freelist_reset(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int i;
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_r128_buf_priv_t *buf_priv = buf->dev_private;
-               buf_priv->age = 0;
-       }
-}
-
-/* ================================================================
- * CCE command submission
- */
-
-int r128_wait_ring(drm_r128_private_t * dev_priv, int n)
-{
-       drm_r128_ring_buffer_t *ring = &dev_priv->ring;
-       int i;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               r128_update_ring_snapshot(dev_priv);
-               if (ring->space >= n)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-       /* FIXME: This is being ignored... */
-       DRM_ERROR("failed!\n");
-       return -EBUSY;
-}
-
-static int r128_cce_get_buffers(struct drm_device * dev,
-                               struct drm_file *file_priv,
-                               struct drm_dma * d)
-{
-       int i;
-       struct drm_buf *buf;
-
-       for (i = d->granted_count; i < d->request_count; i++) {
-               buf = r128_freelist_get(dev);
-               if (!buf)
-                       return -EAGAIN;
-
-               buf->file_priv = file_priv;
-
-               if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
-                                    sizeof(buf->idx)))
-                       return -EFAULT;
-               if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
-                                    sizeof(buf->total)))
-                       return -EFAULT;
-
-               d->granted_count++;
-       }
-       return 0;
-}
-
-int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int ret = 0;
-       struct drm_dma *d = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* Please don't send us buffers.
-        */
-       if (d->send_count != 0) {
-               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
-                         DRM_CURRENTPID, d->send_count);
-               return -EINVAL;
-       }
-
-       /* We'll send you buffers.
-        */
-       if (d->request_count < 0 || d->request_count > dma->buf_count) {
-               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
-                         DRM_CURRENTPID, d->request_count, dma->buf_count);
-               return -EINVAL;
-       }
-
-       d->granted_count = 0;
-
-       if (d->request_count) {
-               ret = r128_cce_get_buffers(dev, file_priv, d);
-       }
-
-       return ret;
-}
diff --git a/drivers/char/drm/r128_drm.h b/drivers/char/drm/r128_drm.h
deleted file mode 100644 (file)
index 8d8878b..0000000
+++ /dev/null
@@ -1,326 +0,0 @@
-/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*-
- * Created: Wed Apr  5 19:24:19 2000 by kevin@precisioninsight.com
- */
-/*
- * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- *    Kevin E. Martin <martin@valinux.com>
- */
-
-#ifndef __R128_DRM_H__
-#define __R128_DRM_H__
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the X server file (r128_sarea.h)
- */
-#ifndef __R128_SAREA_DEFINES__
-#define __R128_SAREA_DEFINES__
-
-/* What needs to be changed for the current vertex buffer?
- */
-#define R128_UPLOAD_CONTEXT            0x001
-#define R128_UPLOAD_SETUP              0x002
-#define R128_UPLOAD_TEX0               0x004
-#define R128_UPLOAD_TEX1               0x008
-#define R128_UPLOAD_TEX0IMAGES         0x010
-#define R128_UPLOAD_TEX1IMAGES         0x020
-#define R128_UPLOAD_CORE               0x040
-#define R128_UPLOAD_MASKS              0x080
-#define R128_UPLOAD_WINDOW             0x100
-#define R128_UPLOAD_CLIPRECTS          0x200   /* handled client-side */
-#define R128_REQUIRE_QUIESCENCE                0x400
-#define R128_UPLOAD_ALL                        0x7ff
-
-#define R128_FRONT                     0x1
-#define R128_BACK                      0x2
-#define R128_DEPTH                     0x4
-
-/* Primitive types
- */
-#define R128_POINTS                    0x1
-#define R128_LINES                     0x2
-#define R128_LINE_STRIP                        0x3
-#define R128_TRIANGLES                 0x4
-#define R128_TRIANGLE_FAN              0x5
-#define R128_TRIANGLE_STRIP            0x6
-
-/* Vertex/indirect buffer size
- */
-#define R128_BUFFER_SIZE               16384
-
-/* Byte offsets for indirect buffer data
- */
-#define R128_INDEX_PRIM_OFFSET         20
-#define R128_HOSTDATA_BLIT_OFFSET      32
-
-/* Keep these small for testing.
- */
-#define R128_NR_SAREA_CLIPRECTS                12
-
-/* There are 2 heaps (local/AGP).  Each region within a heap is a
- *  minimum of 64k, and there are at most 64 of them per heap.
- */
-#define R128_LOCAL_TEX_HEAP            0
-#define R128_AGP_TEX_HEAP              1
-#define R128_NR_TEX_HEAPS              2
-#define R128_NR_TEX_REGIONS            64
-#define R128_LOG_TEX_GRANULARITY       16
-
-#define R128_NR_CONTEXT_REGS           12
-
-#define R128_MAX_TEXTURE_LEVELS                11
-#define R128_MAX_TEXTURE_UNITS         2
-
-#endif                         /* __R128_SAREA_DEFINES__ */
-
-typedef struct {
-       /* Context state - can be written in one large chunk */
-       unsigned int dst_pitch_offset_c;
-       unsigned int dp_gui_master_cntl_c;
-       unsigned int sc_top_left_c;
-       unsigned int sc_bottom_right_c;
-       unsigned int z_offset_c;
-       unsigned int z_pitch_c;
-       unsigned int z_sten_cntl_c;
-       unsigned int tex_cntl_c;
-       unsigned int misc_3d_state_cntl_reg;
-       unsigned int texture_clr_cmp_clr_c;
-       unsigned int texture_clr_cmp_msk_c;
-       unsigned int fog_color_c;
-
-       /* Texture state */
-       unsigned int tex_size_pitch_c;
-       unsigned int constant_color_c;
-
-       /* Setup state */
-       unsigned int pm4_vc_fpu_setup;
-       unsigned int setup_cntl;
-
-       /* Mask state */
-       unsigned int dp_write_mask;
-       unsigned int sten_ref_mask_c;
-       unsigned int plane_3d_mask_c;
-
-       /* Window state */
-       unsigned int window_xy_offset;
-
-       /* Core state */
-       unsigned int scale_3d_cntl;
-} drm_r128_context_regs_t;
-
-/* Setup registers for each texture unit
- */
-typedef struct {
-       unsigned int tex_cntl;
-       unsigned int tex_combine_cntl;
-       unsigned int tex_size_pitch;
-       unsigned int tex_offset[R128_MAX_TEXTURE_LEVELS];
-       unsigned int tex_border_color;
-} drm_r128_texture_regs_t;
-
-typedef struct drm_r128_sarea {
-       /* The channel for communication of state information to the kernel
-        * on firing a vertex buffer.
-        */
-       drm_r128_context_regs_t context_state;
-       drm_r128_texture_regs_t tex_state[R128_MAX_TEXTURE_UNITS];
-       unsigned int dirty;
-       unsigned int vertsize;
-       unsigned int vc_format;
-
-       /* The current cliprects, or a subset thereof.
-        */
-       struct drm_clip_rect boxes[R128_NR_SAREA_CLIPRECTS];
-       unsigned int nbox;
-
-       /* Counters for client-side throttling of rendering clients.
-        */
-       unsigned int last_frame;
-       unsigned int last_dispatch;
-
-       struct drm_tex_region tex_list[R128_NR_TEX_HEAPS][R128_NR_TEX_REGIONS + 1];
-       unsigned int tex_age[R128_NR_TEX_HEAPS];
-       int ctx_owner;
-       int pfAllowPageFlip;    /* number of 3d windows (0,1,2 or more) */
-       int pfCurrentPage;      /* which buffer is being displayed? */
-} drm_r128_sarea_t;
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the Xserver file (xf86drmR128.h)
- */
-
-/* Rage 128 specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_R128_INIT       0x00
-#define DRM_R128_CCE_START  0x01
-#define DRM_R128_CCE_STOP   0x02
-#define DRM_R128_CCE_RESET  0x03
-#define DRM_R128_CCE_IDLE   0x04
-/* 0x05 not used */
-#define DRM_R128_RESET      0x06
-#define DRM_R128_SWAP       0x07
-#define DRM_R128_CLEAR      0x08
-#define DRM_R128_VERTEX     0x09
-#define DRM_R128_INDICES    0x0a
-#define DRM_R128_BLIT       0x0b
-#define DRM_R128_DEPTH      0x0c
-#define DRM_R128_STIPPLE    0x0d
-/* 0x0e not used */
-#define DRM_R128_INDIRECT   0x0f
-#define DRM_R128_FULLSCREEN 0x10
-#define DRM_R128_CLEAR2     0x11
-#define DRM_R128_GETPARAM   0x12
-#define DRM_R128_FLIP       0x13
-
-#define DRM_IOCTL_R128_INIT       DRM_IOW( DRM_COMMAND_BASE + DRM_R128_INIT, drm_r128_init_t)
-#define DRM_IOCTL_R128_CCE_START  DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_START)
-#define DRM_IOCTL_R128_CCE_STOP   DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CCE_STOP, drm_r128_cce_stop_t)
-#define DRM_IOCTL_R128_CCE_RESET  DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_RESET)
-#define DRM_IOCTL_R128_CCE_IDLE   DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_IDLE)
-/* 0x05 not used */
-#define DRM_IOCTL_R128_RESET      DRM_IO(  DRM_COMMAND_BASE + DRM_R128_RESET)
-#define DRM_IOCTL_R128_SWAP       DRM_IO(  DRM_COMMAND_BASE + DRM_R128_SWAP)
-#define DRM_IOCTL_R128_CLEAR      DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CLEAR, drm_r128_clear_t)
-#define DRM_IOCTL_R128_VERTEX     DRM_IOW( DRM_COMMAND_BASE + DRM_R128_VERTEX, drm_r128_vertex_t)
-#define DRM_IOCTL_R128_INDICES    DRM_IOW( DRM_COMMAND_BASE + DRM_R128_INDICES, drm_r128_indices_t)
-#define DRM_IOCTL_R128_BLIT       DRM_IOW( DRM_COMMAND_BASE + DRM_R128_BLIT, drm_r128_blit_t)
-#define DRM_IOCTL_R128_DEPTH      DRM_IOW( DRM_COMMAND_BASE + DRM_R128_DEPTH, drm_r128_depth_t)
-#define DRM_IOCTL_R128_STIPPLE    DRM_IOW( DRM_COMMAND_BASE + DRM_R128_STIPPLE, drm_r128_stipple_t)
-/* 0x0e not used */
-#define DRM_IOCTL_R128_INDIRECT   DRM_IOWR(DRM_COMMAND_BASE + DRM_R128_INDIRECT, drm_r128_indirect_t)
-#define DRM_IOCTL_R128_FULLSCREEN DRM_IOW( DRM_COMMAND_BASE + DRM_R128_FULLSCREEN, drm_r128_fullscreen_t)
-#define DRM_IOCTL_R128_CLEAR2     DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CLEAR2, drm_r128_clear2_t)
-#define DRM_IOCTL_R128_GETPARAM   DRM_IOWR( DRM_COMMAND_BASE + DRM_R128_GETPARAM, drm_r128_getparam_t)
-#define DRM_IOCTL_R128_FLIP       DRM_IO(  DRM_COMMAND_BASE + DRM_R128_FLIP)
-
-typedef struct drm_r128_init {
-       enum {
-               R128_INIT_CCE = 0x01,
-               R128_CLEANUP_CCE = 0x02
-       } func;
-       unsigned long sarea_priv_offset;
-       int is_pci;
-       int cce_mode;
-       int cce_secure;
-       int ring_size;
-       int usec_timeout;
-
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-       unsigned int span_offset;
-
-       unsigned long fb_offset;
-       unsigned long mmio_offset;
-       unsigned long ring_offset;
-       unsigned long ring_rptr_offset;
-       unsigned long buffers_offset;
-       unsigned long agp_textures_offset;
-} drm_r128_init_t;
-
-typedef struct drm_r128_cce_stop {
-       int flush;
-       int idle;
-} drm_r128_cce_stop_t;
-
-typedef struct drm_r128_clear {
-       unsigned int flags;
-       unsigned int clear_color;
-       unsigned int clear_depth;
-       unsigned int color_mask;
-       unsigned int depth_mask;
-} drm_r128_clear_t;
-
-typedef struct drm_r128_vertex {
-       int prim;
-       int idx;                /* Index of vertex buffer */
-       int count;              /* Number of vertices in buffer */
-       int discard;            /* Client finished with buffer? */
-} drm_r128_vertex_t;
-
-typedef struct drm_r128_indices {
-       int prim;
-       int idx;
-       int start;
-       int end;
-       int discard;            /* Client finished with buffer? */
-} drm_r128_indices_t;
-
-typedef struct drm_r128_blit {
-       int idx;
-       int pitch;
-       int offset;
-       int format;
-       unsigned short x, y;
-       unsigned short width, height;
-} drm_r128_blit_t;
-
-typedef struct drm_r128_depth {
-       enum {
-               R128_WRITE_SPAN = 0x01,
-               R128_WRITE_PIXELS = 0x02,
-               R128_READ_SPAN = 0x03,
-               R128_READ_PIXELS = 0x04
-       } func;
-       int n;
-       int __user *x;
-       int __user *y;
-       unsigned int __user *buffer;
-       unsigned char __user *mask;
-} drm_r128_depth_t;
-
-typedef struct drm_r128_stipple {
-       unsigned int __user *mask;
-} drm_r128_stipple_t;
-
-typedef struct drm_r128_indirect {
-       int idx;
-       int start;
-       int end;
-       int discard;
-} drm_r128_indirect_t;
-
-typedef struct drm_r128_fullscreen {
-       enum {
-               R128_INIT_FULLSCREEN = 0x01,
-               R128_CLEANUP_FULLSCREEN = 0x02
-       } func;
-} drm_r128_fullscreen_t;
-
-/* 2.3: An ioctl to get parameters that aren't available to the 3d
- * client any other way.
- */
-#define R128_PARAM_IRQ_NR            1
-
-typedef struct drm_r128_getparam {
-       int param;
-       void __user *value;
-} drm_r128_getparam_t;
-
-#endif
diff --git a/drivers/char/drm/r128_drv.c b/drivers/char/drm/r128_drv.c
deleted file mode 100644 (file)
index 6108e75..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
- * Created: Mon Dec 13 09:47:27 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "r128_drm.h"
-#include "r128_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       r128_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
-           DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
-           DRIVER_IRQ_VBL,
-       .dev_priv_size = sizeof(drm_r128_buf_priv_t),
-       .preclose = r128_driver_preclose,
-       .lastclose = r128_driver_lastclose,
-       .vblank_wait = r128_driver_vblank_wait,
-       .irq_preinstall = r128_driver_irq_preinstall,
-       .irq_postinstall = r128_driver_irq_postinstall,
-       .irq_uninstall = r128_driver_irq_uninstall,
-       .irq_handler = r128_driver_irq_handler,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = r128_ioctls,
-       .dma_ioctl = r128_cce_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = r128_compat_ioctl,
-#endif
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init r128_init(void)
-{
-       driver.num_ioctls = r128_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit r128_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(r128_init);
-module_exit(r128_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h
deleted file mode 100644 (file)
index 011105e..0000000
+++ /dev/null
@@ -1,522 +0,0 @@
-/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
- * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
- */
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Kevin E. Martin <martin@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- *    Michel Dänzer <daenzerm@student.ethz.ch>
- */
-
-#ifndef __R128_DRV_H__
-#define __R128_DRV_H__
-
-/* General customization:
- */
-#define DRIVER_AUTHOR          "Gareth Hughes, VA Linux Systems Inc."
-
-#define DRIVER_NAME            "r128"
-#define DRIVER_DESC            "ATI Rage 128"
-#define DRIVER_DATE            "20030725"
-
-/* Interface history:
- *
- * ??  - ??
- * 2.4 - Add support for ycbcr textures (no new ioctls)
- * 2.5 - Add FLIP ioctl, disable FULLSCREEN.
- */
-#define DRIVER_MAJOR           2
-#define DRIVER_MINOR           5
-#define DRIVER_PATCHLEVEL      0
-
-#define GET_RING_HEAD(dev_priv)                R128_READ( R128_PM4_BUFFER_DL_RPTR )
-
-typedef struct drm_r128_freelist {
-       unsigned int age;
-       struct drm_buf *buf;
-       struct drm_r128_freelist *next;
-       struct drm_r128_freelist *prev;
-} drm_r128_freelist_t;
-
-typedef struct drm_r128_ring_buffer {
-       u32 *start;
-       u32 *end;
-       int size;
-       int size_l2qw;
-
-       u32 tail;
-       u32 tail_mask;
-       int space;
-
-       int high_mark;
-} drm_r128_ring_buffer_t;
-
-typedef struct drm_r128_private {
-       drm_r128_ring_buffer_t ring;
-       drm_r128_sarea_t *sarea_priv;
-
-       int cce_mode;
-       int cce_fifo_size;
-       int cce_running;
-
-       drm_r128_freelist_t *head;
-       drm_r128_freelist_t *tail;
-
-       int usec_timeout;
-       int is_pci;
-       unsigned long cce_buffers_offset;
-
-       atomic_t idle_count;
-
-       int page_flipping;
-       int current_page;
-       u32 crtc_offset;
-       u32 crtc_offset_cntl;
-
-       u32 color_fmt;
-       unsigned int front_offset;
-       unsigned int front_pitch;
-       unsigned int back_offset;
-       unsigned int back_pitch;
-
-       u32 depth_fmt;
-       unsigned int depth_offset;
-       unsigned int depth_pitch;
-       unsigned int span_offset;
-
-       u32 front_pitch_offset_c;
-       u32 back_pitch_offset_c;
-       u32 depth_pitch_offset_c;
-       u32 span_pitch_offset_c;
-
-       drm_local_map_t *sarea;
-       drm_local_map_t *mmio;
-       drm_local_map_t *cce_ring;
-       drm_local_map_t *ring_rptr;
-       drm_local_map_t *agp_textures;
-       struct drm_ati_pcigart_info gart_info;
-} drm_r128_private_t;
-
-typedef struct drm_r128_buf_priv {
-       u32 age;
-       int prim;
-       int discard;
-       int dispatched;
-       drm_r128_freelist_t *list_entry;
-} drm_r128_buf_priv_t;
-
-extern struct drm_ioctl_desc r128_ioctls[];
-extern int r128_max_ioctl;
-
-                               /* r128_cce.c */
-extern int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
-
-extern void r128_freelist_reset(struct drm_device * dev);
-
-extern int r128_wait_ring(drm_r128_private_t * dev_priv, int n);
-
-extern int r128_do_cce_idle(drm_r128_private_t * dev_priv);
-extern int r128_do_cleanup_cce(struct drm_device * dev);
-
-extern int r128_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
-
-extern irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS);
-extern void r128_driver_irq_preinstall(struct drm_device * dev);
-extern void r128_driver_irq_postinstall(struct drm_device * dev);
-extern void r128_driver_irq_uninstall(struct drm_device * dev);
-extern void r128_driver_lastclose(struct drm_device * dev);
-extern void r128_driver_preclose(struct drm_device * dev,
-                                struct drm_file *file_priv);
-
-extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
-                             unsigned long arg);
-
-/* Register definitions, register access macros and drmAddMap constants
- * for Rage 128 kernel driver.
- */
-
-#define R128_AUX_SC_CNTL               0x1660
-#      define R128_AUX1_SC_EN                  (1 << 0)
-#      define R128_AUX1_SC_MODE_OR             (0 << 1)
-#      define R128_AUX1_SC_MODE_NAND           (1 << 1)
-#      define R128_AUX2_SC_EN                  (1 << 2)
-#      define R128_AUX2_SC_MODE_OR             (0 << 3)
-#      define R128_AUX2_SC_MODE_NAND           (1 << 3)
-#      define R128_AUX3_SC_EN                  (1 << 4)
-#      define R128_AUX3_SC_MODE_OR             (0 << 5)
-#      define R128_AUX3_SC_MODE_NAND           (1 << 5)
-#define R128_AUX1_SC_LEFT              0x1664
-#define R128_AUX1_SC_RIGHT             0x1668
-#define R128_AUX1_SC_TOP               0x166c
-#define R128_AUX1_SC_BOTTOM            0x1670
-#define R128_AUX2_SC_LEFT              0x1674
-#define R128_AUX2_SC_RIGHT             0x1678
-#define R128_AUX2_SC_TOP               0x167c
-#define R128_AUX2_SC_BOTTOM            0x1680
-#define R128_AUX3_SC_LEFT              0x1684
-#define R128_AUX3_SC_RIGHT             0x1688
-#define R128_AUX3_SC_TOP               0x168c
-#define R128_AUX3_SC_BOTTOM            0x1690
-
-#define R128_BRUSH_DATA0               0x1480
-#define R128_BUS_CNTL                  0x0030
-#      define R128_BUS_MASTER_DIS              (1 << 6)
-
-#define R128_CLOCK_CNTL_INDEX          0x0008
-#define R128_CLOCK_CNTL_DATA           0x000c
-#      define R128_PLL_WR_EN                   (1 << 7)
-#define R128_CONSTANT_COLOR_C          0x1d34
-#define R128_CRTC_OFFSET               0x0224
-#define R128_CRTC_OFFSET_CNTL          0x0228
-#      define R128_CRTC_OFFSET_FLIP_CNTL       (1 << 16)
-
-#define R128_DP_GUI_MASTER_CNTL                0x146c
-#       define R128_GMC_SRC_PITCH_OFFSET_CNTL  (1    <<  0)
-#       define R128_GMC_DST_PITCH_OFFSET_CNTL  (1    <<  1)
-#      define R128_GMC_BRUSH_SOLID_COLOR       (13   <<  4)
-#      define R128_GMC_BRUSH_NONE              (15   <<  4)
-#      define R128_GMC_DST_16BPP               (4    <<  8)
-#      define R128_GMC_DST_24BPP               (5    <<  8)
-#      define R128_GMC_DST_32BPP               (6    <<  8)
-#       define R128_GMC_DST_DATATYPE_SHIFT     8
-#      define R128_GMC_SRC_DATATYPE_COLOR      (3    << 12)
-#      define R128_DP_SRC_SOURCE_MEMORY        (2    << 24)
-#      define R128_DP_SRC_SOURCE_HOST_DATA     (3    << 24)
-#      define R128_GMC_CLR_CMP_CNTL_DIS        (1    << 28)
-#      define R128_GMC_AUX_CLIP_DIS            (1    << 29)
-#      define R128_GMC_WR_MSK_DIS              (1    << 30)
-#      define R128_ROP3_S                      0x00cc0000
-#      define R128_ROP3_P                      0x00f00000
-#define R128_DP_WRITE_MASK             0x16cc
-#define R128_DST_PITCH_OFFSET_C                0x1c80
-#      define R128_DST_TILE                    (1 << 31)
-
-#define R128_GEN_INT_CNTL              0x0040
-#      define R128_CRTC_VBLANK_INT_EN          (1 <<  0)
-#define R128_GEN_INT_STATUS            0x0044
-#      define R128_CRTC_VBLANK_INT             (1 <<  0)
-#      define R128_CRTC_VBLANK_INT_AK          (1 <<  0)
-#define R128_GEN_RESET_CNTL            0x00f0
-#      define R128_SOFT_RESET_GUI              (1 <<  0)
-
-#define R128_GUI_SCRATCH_REG0          0x15e0
-#define R128_GUI_SCRATCH_REG1          0x15e4
-#define R128_GUI_SCRATCH_REG2          0x15e8
-#define R128_GUI_SCRATCH_REG3          0x15ec
-#define R128_GUI_SCRATCH_REG4          0x15f0
-#define R128_GUI_SCRATCH_REG5          0x15f4
-
-#define R128_GUI_STAT                  0x1740
-#      define R128_GUI_FIFOCNT_MASK            0x0fff
-#      define R128_GUI_ACTIVE                  (1 << 31)
-
-#define R128_MCLK_CNTL                 0x000f
-#      define R128_FORCE_GCP                   (1 << 16)
-#      define R128_FORCE_PIPE3D_CP             (1 << 17)
-#      define R128_FORCE_RCP                   (1 << 18)
-
-#define R128_PC_GUI_CTLSTAT            0x1748
-#define R128_PC_NGUI_CTLSTAT           0x0184
-#      define R128_PC_FLUSH_GUI                (3 << 0)
-#      define R128_PC_RI_GUI                   (1 << 2)
-#      define R128_PC_FLUSH_ALL                0x00ff
-#      define R128_PC_BUSY                     (1 << 31)
-
-#define R128_PCI_GART_PAGE             0x017c
-#define R128_PRIM_TEX_CNTL_C           0x1cb0
-
-#define R128_SCALE_3D_CNTL             0x1a00
-#define R128_SEC_TEX_CNTL_C            0x1d00
-#define R128_SEC_TEXTURE_BORDER_COLOR_C        0x1d3c
-#define R128_SETUP_CNTL                        0x1bc4
-#define R128_STEN_REF_MASK_C           0x1d40
-
-#define R128_TEX_CNTL_C                        0x1c9c
-#      define R128_TEX_CACHE_FLUSH             (1 << 23)
-
-#define R128_WAIT_UNTIL                        0x1720
-#      define R128_EVENT_CRTC_OFFSET           (1 << 0)
-#define R128_WINDOW_XY_OFFSET          0x1bcc
-
-/* CCE registers
- */
-#define R128_PM4_BUFFER_OFFSET         0x0700
-#define R128_PM4_BUFFER_CNTL           0x0704
-#      define R128_PM4_MASK                    (15 << 28)
-#      define R128_PM4_NONPM4                  (0  << 28)
-#      define R128_PM4_192PIO                  (1  << 28)
-#      define R128_PM4_192BM                   (2  << 28)
-#      define R128_PM4_128PIO_64INDBM          (3  << 28)
-#      define R128_PM4_128BM_64INDBM           (4  << 28)
-#      define R128_PM4_64PIO_128INDBM          (5  << 28)
-#      define R128_PM4_64BM_128INDBM           (6  << 28)
-#      define R128_PM4_64PIO_64VCBM_64INDBM    (7  << 28)
-#      define R128_PM4_64BM_64VCBM_64INDBM     (8  << 28)
-#      define R128_PM4_64PIO_64VCPIO_64INDPIO  (15 << 28)
-#      define R128_PM4_BUFFER_CNTL_NOUPDATE    (1  << 27)
-
-#define R128_PM4_BUFFER_WM_CNTL                0x0708
-#      define R128_WMA_SHIFT                   0
-#      define R128_WMB_SHIFT                   8
-#      define R128_WMC_SHIFT                   16
-#      define R128_WB_WM_SHIFT                 24
-
-#define R128_PM4_BUFFER_DL_RPTR_ADDR   0x070c
-#define R128_PM4_BUFFER_DL_RPTR                0x0710
-#define R128_PM4_BUFFER_DL_WPTR                0x0714
-#      define R128_PM4_BUFFER_DL_DONE          (1 << 31)
-
-#define R128_PM4_VC_FPU_SETUP          0x071c
-
-#define R128_PM4_IW_INDOFF             0x0738
-#define R128_PM4_IW_INDSIZE            0x073c
-
-#define R128_PM4_STAT                  0x07b8
-#      define R128_PM4_FIFOCNT_MASK            0x0fff
-#      define R128_PM4_BUSY                    (1 << 16)
-#      define R128_PM4_GUI_ACTIVE              (1 << 31)
-
-#define R128_PM4_MICROCODE_ADDR                0x07d4
-#define R128_PM4_MICROCODE_RADDR       0x07d8
-#define R128_PM4_MICROCODE_DATAH       0x07dc
-#define R128_PM4_MICROCODE_DATAL       0x07e0
-
-#define R128_PM4_BUFFER_ADDR           0x07f0
-#define R128_PM4_MICRO_CNTL            0x07fc
-#      define R128_PM4_MICRO_FREERUN           (1 << 30)
-
-#define R128_PM4_FIFO_DATA_EVEN                0x1000
-#define R128_PM4_FIFO_DATA_ODD         0x1004
-
-/* CCE command packets
- */
-#define R128_CCE_PACKET0               0x00000000
-#define R128_CCE_PACKET1               0x40000000
-#define R128_CCE_PACKET2               0x80000000
-#define R128_CCE_PACKET3               0xC0000000
-#      define R128_CNTL_HOSTDATA_BLT           0x00009400
-#      define R128_CNTL_PAINT_MULTI            0x00009A00
-#      define R128_CNTL_BITBLT_MULTI           0x00009B00
-#      define R128_3D_RNDR_GEN_INDX_PRIM       0x00002300
-
-#define R128_CCE_PACKET_MASK           0xC0000000
-#define R128_CCE_PACKET_COUNT_MASK     0x3fff0000
-#define R128_CCE_PACKET0_REG_MASK      0x000007ff
-#define R128_CCE_PACKET1_REG0_MASK     0x000007ff
-#define R128_CCE_PACKET1_REG1_MASK     0x003ff800
-
-#define R128_CCE_VC_CNTL_PRIM_TYPE_NONE                0x00000000
-#define R128_CCE_VC_CNTL_PRIM_TYPE_POINT       0x00000001
-#define R128_CCE_VC_CNTL_PRIM_TYPE_LINE                0x00000002
-#define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE   0x00000003
-#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST    0x00000004
-#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN     0x00000005
-#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP   0x00000006
-#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2   0x00000007
-#define R128_CCE_VC_CNTL_PRIM_WALK_IND         0x00000010
-#define R128_CCE_VC_CNTL_PRIM_WALK_LIST                0x00000020
-#define R128_CCE_VC_CNTL_PRIM_WALK_RING                0x00000030
-#define R128_CCE_VC_CNTL_NUM_SHIFT             16
-
-#define R128_DATATYPE_VQ               0
-#define R128_DATATYPE_CI4              1
-#define R128_DATATYPE_CI8              2
-#define R128_DATATYPE_ARGB1555         3
-#define R128_DATATYPE_RGB565           4
-#define R128_DATATYPE_RGB888           5
-#define R128_DATATYPE_ARGB8888         6
-#define R128_DATATYPE_RGB332           7
-#define R128_DATATYPE_Y8               8
-#define R128_DATATYPE_RGB8             9
-#define R128_DATATYPE_CI16             10
-#define R128_DATATYPE_YVYU422          11
-#define R128_DATATYPE_VYUY422          12
-#define R128_DATATYPE_AYUV444          14
-#define R128_DATATYPE_ARGB4444         15
-
-/* Constants */
-#define R128_AGP_OFFSET                        0x02000000
-
-#define R128_WATERMARK_L               16
-#define R128_WATERMARK_M               8
-#define R128_WATERMARK_N               8
-#define R128_WATERMARK_K               128
-
-#define R128_MAX_USEC_TIMEOUT          100000  /* 100 ms */
-
-#define R128_LAST_FRAME_REG            R128_GUI_SCRATCH_REG0
-#define R128_LAST_DISPATCH_REG         R128_GUI_SCRATCH_REG1
-#define R128_MAX_VB_AGE                        0x7fffffff
-#define R128_MAX_VB_VERTS              (0xffff)
-
-#define R128_RING_HIGH_MARK            128
-
-#define R128_PERFORMANCE_BOXES         0
-
-#define R128_PCIGART_TABLE_SIZE         32768
-
-#define R128_READ(reg)         DRM_READ32(  dev_priv->mmio, (reg) )
-#define R128_WRITE(reg,val)    DRM_WRITE32( dev_priv->mmio, (reg), (val) )
-#define R128_READ8(reg)                DRM_READ8(   dev_priv->mmio, (reg) )
-#define R128_WRITE8(reg,val)   DRM_WRITE8(  dev_priv->mmio, (reg), (val) )
-
-#define R128_WRITE_PLL(addr,val)                                       \
-do {                                                                   \
-       R128_WRITE8(R128_CLOCK_CNTL_INDEX,                              \
-                   ((addr) & 0x1f) | R128_PLL_WR_EN);                  \
-       R128_WRITE(R128_CLOCK_CNTL_DATA, (val));                        \
-} while (0)
-
-#define CCE_PACKET0( reg, n )          (R128_CCE_PACKET0 |             \
-                                        ((n) << 16) | ((reg) >> 2))
-#define CCE_PACKET1( reg0, reg1 )      (R128_CCE_PACKET1 |             \
-                                        (((reg1) >> 2) << 11) | ((reg0) >> 2))
-#define CCE_PACKET2()                  (R128_CCE_PACKET2)
-#define CCE_PACKET3( pkt, n )          (R128_CCE_PACKET3 |             \
-                                        (pkt) | ((n) << 16))
-
-static __inline__ void r128_update_ring_snapshot(drm_r128_private_t * dev_priv)
-{
-       drm_r128_ring_buffer_t *ring = &dev_priv->ring;
-       ring->space = (GET_RING_HEAD(dev_priv) - ring->tail) * sizeof(u32);
-       if (ring->space <= 0)
-               ring->space += ring->size;
-}
-
-/* ================================================================
- * Misc helper macros
- */
-
-#define RING_SPACE_TEST_WITH_RETURN( dev_priv )                                \
-do {                                                                   \
-       drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i;          \
-       if ( ring->space < ring->high_mark ) {                          \
-               for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {      \
-                       r128_update_ring_snapshot( dev_priv );          \
-                       if ( ring->space >= ring->high_mark )           \
-                               goto __ring_space_done;                 \
-                       DRM_UDELAY(1);                          \
-               }                                                       \
-               DRM_ERROR( "ring space check failed!\n" );              \
-               return -EBUSY;                          \
-       }                                                               \
- __ring_space_done:                                                    \
-       ;                                                               \
-} while (0)
-
-#define VB_AGE_TEST_WITH_RETURN( dev_priv )                            \
-do {                                                                   \
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;            \
-       if ( sarea_priv->last_dispatch >= R128_MAX_VB_AGE ) {           \
-               int __ret = r128_do_cce_idle( dev_priv );               \
-               if ( __ret ) return __ret;                              \
-               sarea_priv->last_dispatch = 0;                          \
-               r128_freelist_reset( dev );                             \
-       }                                                               \
-} while (0)
-
-#define R128_WAIT_UNTIL_PAGE_FLIPPED() do {                            \
-       OUT_RING( CCE_PACKET0( R128_WAIT_UNTIL, 0 ) );                  \
-       OUT_RING( R128_EVENT_CRTC_OFFSET );                             \
-} while (0)
-
-/* ================================================================
- * Ring control
- */
-
-#define R128_VERBOSE   0
-
-#define RING_LOCALS                                                    \
-       int write, _nr; unsigned int tail_mask; volatile u32 *ring;
-
-#define BEGIN_RING( n ) do {                                           \
-       if ( R128_VERBOSE ) {                                           \
-               DRM_INFO( "BEGIN_RING( %d )\n", (n));                   \
-       }                                                               \
-       if ( dev_priv->ring.space <= (n) * sizeof(u32) ) {              \
-               COMMIT_RING();                                          \
-               r128_wait_ring( dev_priv, (n) * sizeof(u32) );          \
-       }                                                               \
-       _nr = n; dev_priv->ring.space -= (n) * sizeof(u32);             \
-       ring = dev_priv->ring.start;                                    \
-       write = dev_priv->ring.tail;                                    \
-       tail_mask = dev_priv->ring.tail_mask;                           \
-} while (0)
-
-/* You can set this to zero if you want.  If the card locks up, you'll
- * need to keep this set.  It works around a bug in early revs of the
- * Rage 128 chipset, where the CCE would read 32 dwords past the end of
- * the ring buffer before wrapping around.
- */
-#define R128_BROKEN_CCE        1
-
-#define ADVANCE_RING() do {                                            \
-       if ( R128_VERBOSE ) {                                           \
-               DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",     \
-                         write, dev_priv->ring.tail );                 \
-       }                                                               \
-       if ( R128_BROKEN_CCE && write < 32 ) {                          \
-               memcpy( dev_priv->ring.end,                             \
-                       dev_priv->ring.start,                           \
-                       write * sizeof(u32) );                          \
-       }                                                               \
-       if (((dev_priv->ring.tail + _nr) & tail_mask) != write) {       \
-               DRM_ERROR(                                              \
-                       "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n",        \
-                       ((dev_priv->ring.tail + _nr) & tail_mask),      \
-                       write, __LINE__);                               \
-       } else                                                          \
-               dev_priv->ring.tail = write;                            \
-} while (0)
-
-#define COMMIT_RING() do {                                             \
-       if ( R128_VERBOSE ) {                                           \
-               DRM_INFO( "COMMIT_RING() tail=0x%06x\n",                \
-                       dev_priv->ring.tail );                          \
-       }                                                               \
-       DRM_MEMORYBARRIER();                                            \
-       R128_WRITE( R128_PM4_BUFFER_DL_WPTR, dev_priv->ring.tail );     \
-       R128_READ( R128_PM4_BUFFER_DL_WPTR );                           \
-} while (0)
-
-#define OUT_RING( x ) do {                                             \
-       if ( R128_VERBOSE ) {                                           \
-               DRM_INFO( "   OUT_RING( 0x%08x ) at 0x%x\n",            \
-                          (unsigned int)(x), write );                  \
-       }                                                               \
-       ring[write++] = cpu_to_le32( x );                               \
-       write &= tail_mask;                                             \
-} while (0)
-
-#endif                         /* __R128_DRV_H__ */
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c
deleted file mode 100644 (file)
index d3cb676..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * \file r128_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the R128 DRM.
- *
- * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
- *
- * Copyright (C) Paul Mackerras 2005
- * Copyright (C) Egbert Eich 2003,2004
- * Copyright (C) Dave Airlie 2005
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include "drmP.h"
-#include "drm.h"
-#include "r128_drm.h"
-
-typedef struct drm_r128_init32 {
-       int func;
-       unsigned int sarea_priv_offset;
-       int is_pci;
-       int cce_mode;
-       int cce_secure;
-       int ring_size;
-       int usec_timeout;
-
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-       unsigned int span_offset;
-
-       unsigned int fb_offset;
-       unsigned int mmio_offset;
-       unsigned int ring_offset;
-       unsigned int ring_rptr_offset;
-       unsigned int buffers_offset;
-       unsigned int agp_textures_offset;
-} drm_r128_init32_t;
-
-static int compat_r128_init(struct file *file, unsigned int cmd,
-                           unsigned long arg)
-{
-       drm_r128_init32_t init32;
-       drm_r128_init_t __user *init;
-
-       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
-               return -EFAULT;
-
-       init = compat_alloc_user_space(sizeof(*init));
-       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
-           || __put_user(init32.func, &init->func)
-           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
-           || __put_user(init32.is_pci, &init->is_pci)
-           || __put_user(init32.cce_mode, &init->cce_mode)
-           || __put_user(init32.cce_secure, &init->cce_secure)
-           || __put_user(init32.ring_size, &init->ring_size)
-           || __put_user(init32.usec_timeout, &init->usec_timeout)
-           || __put_user(init32.fb_bpp, &init->fb_bpp)
-           || __put_user(init32.front_offset, &init->front_offset)
-           || __put_user(init32.front_pitch, &init->front_pitch)
-           || __put_user(init32.back_offset, &init->back_offset)
-           || __put_user(init32.back_pitch, &init->back_pitch)
-           || __put_user(init32.depth_bpp, &init->depth_bpp)
-           || __put_user(init32.depth_offset, &init->depth_offset)
-           || __put_user(init32.depth_pitch, &init->depth_pitch)
-           || __put_user(init32.span_offset, &init->span_offset)
-           || __put_user(init32.fb_offset, &init->fb_offset)
-           || __put_user(init32.mmio_offset, &init->mmio_offset)
-           || __put_user(init32.ring_offset, &init->ring_offset)
-           || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
-           || __put_user(init32.buffers_offset, &init->buffers_offset)
-           || __put_user(init32.agp_textures_offset,
-                         &init->agp_textures_offset))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_R128_INIT, (unsigned long)init);
-}
-
-typedef struct drm_r128_depth32 {
-       int func;
-       int n;
-       u32 x;
-       u32 y;
-       u32 buffer;
-       u32 mask;
-} drm_r128_depth32_t;
-
-static int compat_r128_depth(struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       drm_r128_depth32_t depth32;
-       drm_r128_depth_t __user *depth;
-
-       if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
-               return -EFAULT;
-
-       depth = compat_alloc_user_space(sizeof(*depth));
-       if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
-           || __put_user(depth32.func, &depth->func)
-           || __put_user(depth32.n, &depth->n)
-           || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
-           || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
-           || __put_user((unsigned int __user *)(unsigned long)depth32.buffer,
-                         &depth->buffer)
-           || __put_user((unsigned char __user *)(unsigned long)depth32.mask,
-                         &depth->mask))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
-
-}
-
-typedef struct drm_r128_stipple32 {
-       u32 mask;
-} drm_r128_stipple32_t;
-
-static int compat_r128_stipple(struct file *file, unsigned int cmd,
-                              unsigned long arg)
-{
-       drm_r128_stipple32_t stipple32;
-       drm_r128_stipple_t __user *stipple;
-
-       if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
-               return -EFAULT;
-
-       stipple = compat_alloc_user_space(sizeof(*stipple));
-       if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
-           || __put_user((unsigned int __user *)(unsigned long)stipple32.mask,
-                         &stipple->mask))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
-}
-
-typedef struct drm_r128_getparam32 {
-       int param;
-       u32 value;
-} drm_r128_getparam32_t;
-
-static int compat_r128_getparam(struct file *file, unsigned int cmd,
-                               unsigned long arg)
-{
-       drm_r128_getparam32_t getparam32;
-       drm_r128_getparam_t __user *getparam;
-
-       if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
-               return -EFAULT;
-
-       getparam = compat_alloc_user_space(sizeof(*getparam));
-       if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
-           || __put_user(getparam32.param, &getparam->param)
-           || __put_user((void __user *)(unsigned long)getparam32.value,
-                         &getparam->value))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
-}
-
-drm_ioctl_compat_t *r128_compat_ioctls[] = {
-       [DRM_R128_INIT] = compat_r128_init,
-       [DRM_R128_DEPTH] = compat_r128_depth,
-       [DRM_R128_STIPPLE] = compat_r128_stipple,
-       [DRM_R128_GETPARAM] = compat_r128_getparam,
-};
-
-/**
- * Called whenever a 32-bit process running under a 64-bit kernel
- * performs an ioctl on /dev/dri/card<n>.
- *
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- */
-long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       drm_ioctl_compat_t *fn = NULL;
-       int ret;
-
-       if (nr < DRM_COMMAND_BASE)
-               return drm_compat_ioctl(filp, cmd, arg);
-
-       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
-               fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
-
-       lock_kernel();          /* XXX for now */
-       if (fn != NULL)
-               ret = (*fn) (filp, cmd, arg);
-       else
-               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
-       unlock_kernel();
-
-       return ret;
-}
diff --git a/drivers/char/drm/r128_irq.c b/drivers/char/drm/r128_irq.c
deleted file mode 100644 (file)
index c76fdca..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */
-/*
- * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
- *
- * The Weather Channel (TM) funded Tungsten Graphics to develop the
- * initial release of the Radeon 8500 driver under the XFree86 license.
- * This notice must be preserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
- *    Eric Anholt <anholt@FreeBSD.org>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "r128_drm.h"
-#include "r128_drv.h"
-
-irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
-       int status;
-
-       status = R128_READ(R128_GEN_INT_STATUS);
-
-       /* VBLANK interrupt */
-       if (status & R128_CRTC_VBLANK_INT) {
-               R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
-               atomic_inc(&dev->vbl_received);
-               DRM_WAKEUP(&dev->vbl_queue);
-               drm_vbl_send_signals(dev);
-               return IRQ_HANDLED;
-       }
-       return IRQ_NONE;
-}
-
-int r128_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
-{
-       unsigned int cur_vblank;
-       int ret = 0;
-
-       /* Assume that the user has missed the current sequence number
-        * by about a day rather than she wants to wait for years
-        * using vertical blanks...
-        */
-       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
-                   (((cur_vblank = atomic_read(&dev->vbl_received))
-                     - *sequence) <= (1 << 23)));
-
-       *sequence = cur_vblank;
-
-       return ret;
-}
-
-void r128_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
-
-       /* Disable *all* interrupts */
-       R128_WRITE(R128_GEN_INT_CNTL, 0);
-       /* Clear vblank bit if it's already high */
-       R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
-}
-
-void r128_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
-
-       /* Turn on VBL interrupt */
-       R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN);
-}
-
-void r128_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
-       if (!dev_priv)
-               return;
-
-       /* Disable *all* interrupts */
-       R128_WRITE(R128_GEN_INT_CNTL, 0);
-}
diff --git a/drivers/char/drm/r128_state.c b/drivers/char/drm/r128_state.c
deleted file mode 100644 (file)
index 51a9afc..0000000
+++ /dev/null
@@ -1,1681 +0,0 @@
-/* r128_state.c -- State support for r128 -*- linux-c -*-
- * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
- */
-/*
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "r128_drm.h"
-#include "r128_drv.h"
-
-/* ================================================================
- * CCE hardware state programming functions
- */
-
-static void r128_emit_clip_rects(drm_r128_private_t * dev_priv,
-                                struct drm_clip_rect * boxes, int count)
-{
-       u32 aux_sc_cntl = 0x00000000;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING((count < 3 ? count : 3) * 5 + 2);
-
-       if (count >= 1) {
-               OUT_RING(CCE_PACKET0(R128_AUX1_SC_LEFT, 3));
-               OUT_RING(boxes[0].x1);
-               OUT_RING(boxes[0].x2 - 1);
-               OUT_RING(boxes[0].y1);
-               OUT_RING(boxes[0].y2 - 1);
-
-               aux_sc_cntl |= (R128_AUX1_SC_EN | R128_AUX1_SC_MODE_OR);
-       }
-       if (count >= 2) {
-               OUT_RING(CCE_PACKET0(R128_AUX2_SC_LEFT, 3));
-               OUT_RING(boxes[1].x1);
-               OUT_RING(boxes[1].x2 - 1);
-               OUT_RING(boxes[1].y1);
-               OUT_RING(boxes[1].y2 - 1);
-
-               aux_sc_cntl |= (R128_AUX2_SC_EN | R128_AUX2_SC_MODE_OR);
-       }
-       if (count >= 3) {
-               OUT_RING(CCE_PACKET0(R128_AUX3_SC_LEFT, 3));
-               OUT_RING(boxes[2].x1);
-               OUT_RING(boxes[2].x2 - 1);
-               OUT_RING(boxes[2].y1);
-               OUT_RING(boxes[2].y2 - 1);
-
-               aux_sc_cntl |= (R128_AUX3_SC_EN | R128_AUX3_SC_MODE_OR);
-       }
-
-       OUT_RING(CCE_PACKET0(R128_AUX_SC_CNTL, 0));
-       OUT_RING(aux_sc_cntl);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_core(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_SCALE_3D_CNTL, 0));
-       OUT_RING(ctx->scale_3d_cntl);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_context(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(13);
-
-       OUT_RING(CCE_PACKET0(R128_DST_PITCH_OFFSET_C, 11));
-       OUT_RING(ctx->dst_pitch_offset_c);
-       OUT_RING(ctx->dp_gui_master_cntl_c);
-       OUT_RING(ctx->sc_top_left_c);
-       OUT_RING(ctx->sc_bottom_right_c);
-       OUT_RING(ctx->z_offset_c);
-       OUT_RING(ctx->z_pitch_c);
-       OUT_RING(ctx->z_sten_cntl_c);
-       OUT_RING(ctx->tex_cntl_c);
-       OUT_RING(ctx->misc_3d_state_cntl_reg);
-       OUT_RING(ctx->texture_clr_cmp_clr_c);
-       OUT_RING(ctx->texture_clr_cmp_msk_c);
-       OUT_RING(ctx->fog_color_c);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_setup(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(3);
-
-       OUT_RING(CCE_PACKET1(R128_SETUP_CNTL, R128_PM4_VC_FPU_SETUP));
-       OUT_RING(ctx->setup_cntl);
-       OUT_RING(ctx->pm4_vc_fpu_setup);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_masks(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(5);
-
-       OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
-       OUT_RING(ctx->dp_write_mask);
-
-       OUT_RING(CCE_PACKET0(R128_STEN_REF_MASK_C, 1));
-       OUT_RING(ctx->sten_ref_mask_c);
-       OUT_RING(ctx->plane_3d_mask_c);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_window(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_WINDOW_XY_OFFSET, 0));
-       OUT_RING(ctx->window_xy_offset);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_tex0(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
-       drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[0];
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(7 + R128_MAX_TEXTURE_LEVELS);
-
-       OUT_RING(CCE_PACKET0(R128_PRIM_TEX_CNTL_C,
-                            2 + R128_MAX_TEXTURE_LEVELS));
-       OUT_RING(tex->tex_cntl);
-       OUT_RING(tex->tex_combine_cntl);
-       OUT_RING(ctx->tex_size_pitch_c);
-       for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
-               OUT_RING(tex->tex_offset[i]);
-       }
-
-       OUT_RING(CCE_PACKET0(R128_CONSTANT_COLOR_C, 1));
-       OUT_RING(ctx->constant_color_c);
-       OUT_RING(tex->tex_border_color);
-
-       ADVANCE_RING();
-}
-
-static __inline__ void r128_emit_tex1(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[1];
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(5 + R128_MAX_TEXTURE_LEVELS);
-
-       OUT_RING(CCE_PACKET0(R128_SEC_TEX_CNTL_C, 1 + R128_MAX_TEXTURE_LEVELS));
-       OUT_RING(tex->tex_cntl);
-       OUT_RING(tex->tex_combine_cntl);
-       for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
-               OUT_RING(tex->tex_offset[i]);
-       }
-
-       OUT_RING(CCE_PACKET0(R128_SEC_TEXTURE_BORDER_COLOR_C, 0));
-       OUT_RING(tex->tex_border_color);
-
-       ADVANCE_RING();
-}
-
-static void r128_emit_state(drm_r128_private_t * dev_priv)
-{
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       unsigned int dirty = sarea_priv->dirty;
-
-       DRM_DEBUG("dirty=0x%08x\n", dirty);
-
-       if (dirty & R128_UPLOAD_CORE) {
-               r128_emit_core(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_CORE;
-       }
-
-       if (dirty & R128_UPLOAD_CONTEXT) {
-               r128_emit_context(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_CONTEXT;
-       }
-
-       if (dirty & R128_UPLOAD_SETUP) {
-               r128_emit_setup(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_SETUP;
-       }
-
-       if (dirty & R128_UPLOAD_MASKS) {
-               r128_emit_masks(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_MASKS;
-       }
-
-       if (dirty & R128_UPLOAD_WINDOW) {
-               r128_emit_window(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_WINDOW;
-       }
-
-       if (dirty & R128_UPLOAD_TEX0) {
-               r128_emit_tex0(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_TEX0;
-       }
-
-       if (dirty & R128_UPLOAD_TEX1) {
-               r128_emit_tex1(dev_priv);
-               sarea_priv->dirty &= ~R128_UPLOAD_TEX1;
-       }
-
-       /* Turn off the texture cache flushing */
-       sarea_priv->context_state.tex_cntl_c &= ~R128_TEX_CACHE_FLUSH;
-
-       sarea_priv->dirty &= ~R128_REQUIRE_QUIESCENCE;
-}
-
-#if R128_PERFORMANCE_BOXES
-/* ================================================================
- * Performance monitoring functions
- */
-
-static void r128_clear_box(drm_r128_private_t * dev_priv,
-                          int x, int y, int w, int h, int r, int g, int b)
-{
-       u32 pitch, offset;
-       u32 fb_bpp, color;
-       RING_LOCALS;
-
-       switch (dev_priv->fb_bpp) {
-       case 16:
-               fb_bpp = R128_GMC_DST_16BPP;
-               color = (((r & 0xf8) << 8) |
-                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
-               break;
-       case 24:
-               fb_bpp = R128_GMC_DST_24BPP;
-               color = ((r << 16) | (g << 8) | b);
-               break;
-       case 32:
-               fb_bpp = R128_GMC_DST_32BPP;
-               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
-               break;
-       default:
-               return;
-       }
-
-       offset = dev_priv->back_offset;
-       pitch = dev_priv->back_pitch >> 3;
-
-       BEGIN_RING(6);
-
-       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                R128_GMC_BRUSH_SOLID_COLOR |
-                fb_bpp |
-                R128_GMC_SRC_DATATYPE_COLOR |
-                R128_ROP3_P |
-                R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_AUX_CLIP_DIS);
-
-       OUT_RING((pitch << 21) | (offset >> 5));
-       OUT_RING(color);
-
-       OUT_RING((x << 16) | y);
-       OUT_RING((w << 16) | h);
-
-       ADVANCE_RING();
-}
-
-static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
-{
-       if (atomic_read(&dev_priv->idle_count) == 0) {
-               r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
-       } else {
-               atomic_set(&dev_priv->idle_count, 0);
-       }
-}
-
-#endif
-
-/* ================================================================
- * CCE command dispatch functions
- */
-
-static void r128_print_dirty(const char *msg, unsigned int flags)
-{
-       DRM_INFO("%s: (0x%x) %s%s%s%s%s%s%s%s%s\n",
-                msg,
-                flags,
-                (flags & R128_UPLOAD_CORE) ? "core, " : "",
-                (flags & R128_UPLOAD_CONTEXT) ? "context, " : "",
-                (flags & R128_UPLOAD_SETUP) ? "setup, " : "",
-                (flags & R128_UPLOAD_TEX0) ? "tex0, " : "",
-                (flags & R128_UPLOAD_TEX1) ? "tex1, " : "",
-                (flags & R128_UPLOAD_MASKS) ? "masks, " : "",
-                (flags & R128_UPLOAD_WINDOW) ? "window, " : "",
-                (flags & R128_UPLOAD_CLIPRECTS) ? "cliprects, " : "",
-                (flags & R128_REQUIRE_QUIESCENCE) ? "quiescence, " : "");
-}
-
-static void r128_cce_dispatch_clear(struct drm_device * dev,
-                                   drm_r128_clear_t * clear)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       unsigned int flags = clear->flags;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       if (dev_priv->page_flipping && dev_priv->current_page == 1) {
-               unsigned int tmp = flags;
-
-               flags &= ~(R128_FRONT | R128_BACK);
-               if (tmp & R128_FRONT)
-                       flags |= R128_BACK;
-               if (tmp & R128_BACK)
-                       flags |= R128_FRONT;
-       }
-
-       for (i = 0; i < nbox; i++) {
-               int x = pbox[i].x1;
-               int y = pbox[i].y1;
-               int w = pbox[i].x2 - x;
-               int h = pbox[i].y2 - y;
-
-               DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
-                         pbox[i].x1, pbox[i].y1, pbox[i].x2,
-                         pbox[i].y2, flags);
-
-               if (flags & (R128_FRONT | R128_BACK)) {
-                       BEGIN_RING(2);
-
-                       OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
-                       OUT_RING(clear->color_mask);
-
-                       ADVANCE_RING();
-               }
-
-               if (flags & R128_FRONT) {
-                       BEGIN_RING(6);
-
-                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                R128_GMC_BRUSH_SOLID_COLOR |
-                                (dev_priv->color_fmt << 8) |
-                                R128_GMC_SRC_DATATYPE_COLOR |
-                                R128_ROP3_P |
-                                R128_GMC_CLR_CMP_CNTL_DIS |
-                                R128_GMC_AUX_CLIP_DIS);
-
-                       OUT_RING(dev_priv->front_pitch_offset_c);
-                       OUT_RING(clear->clear_color);
-
-                       OUT_RING((x << 16) | y);
-                       OUT_RING((w << 16) | h);
-
-                       ADVANCE_RING();
-               }
-
-               if (flags & R128_BACK) {
-                       BEGIN_RING(6);
-
-                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                R128_GMC_BRUSH_SOLID_COLOR |
-                                (dev_priv->color_fmt << 8) |
-                                R128_GMC_SRC_DATATYPE_COLOR |
-                                R128_ROP3_P |
-                                R128_GMC_CLR_CMP_CNTL_DIS |
-                                R128_GMC_AUX_CLIP_DIS);
-
-                       OUT_RING(dev_priv->back_pitch_offset_c);
-                       OUT_RING(clear->clear_color);
-
-                       OUT_RING((x << 16) | y);
-                       OUT_RING((w << 16) | h);
-
-                       ADVANCE_RING();
-               }
-
-               if (flags & R128_DEPTH) {
-                       BEGIN_RING(6);
-
-                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                R128_GMC_BRUSH_SOLID_COLOR |
-                                (dev_priv->depth_fmt << 8) |
-                                R128_GMC_SRC_DATATYPE_COLOR |
-                                R128_ROP3_P |
-                                R128_GMC_CLR_CMP_CNTL_DIS |
-                                R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
-
-                       OUT_RING(dev_priv->depth_pitch_offset_c);
-                       OUT_RING(clear->clear_depth);
-
-                       OUT_RING((x << 16) | y);
-                       OUT_RING((w << 16) | h);
-
-                       ADVANCE_RING();
-               }
-       }
-}
-
-static void r128_cce_dispatch_swap(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-#if R128_PERFORMANCE_BOXES
-       /* Do some trivial performance monitoring...
-        */
-       r128_cce_performance_boxes(dev_priv);
-#endif
-
-       for (i = 0; i < nbox; i++) {
-               int x = pbox[i].x1;
-               int y = pbox[i].y1;
-               int w = pbox[i].x2 - x;
-               int h = pbox[i].y2 - y;
-
-               BEGIN_RING(7);
-
-               OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
-               OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
-                        R128_GMC_DST_PITCH_OFFSET_CNTL |
-                        R128_GMC_BRUSH_NONE |
-                        (dev_priv->color_fmt << 8) |
-                        R128_GMC_SRC_DATATYPE_COLOR |
-                        R128_ROP3_S |
-                        R128_DP_SRC_SOURCE_MEMORY |
-                        R128_GMC_CLR_CMP_CNTL_DIS |
-                        R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
-
-               /* Make this work even if front & back are flipped:
-                */
-               if (dev_priv->current_page == 0) {
-                       OUT_RING(dev_priv->back_pitch_offset_c);
-                       OUT_RING(dev_priv->front_pitch_offset_c);
-               } else {
-                       OUT_RING(dev_priv->front_pitch_offset_c);
-                       OUT_RING(dev_priv->back_pitch_offset_c);
-               }
-
-               OUT_RING((x << 16) | y);
-               OUT_RING((x << 16) | y);
-               OUT_RING((w << 16) | h);
-
-               ADVANCE_RING();
-       }
-
-       /* Increment the frame counter.  The client-side 3D driver must
-        * throttle the framerate by waiting for this value before
-        * performing the swapbuffer ioctl.
-        */
-       dev_priv->sarea_priv->last_frame++;
-
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
-       OUT_RING(dev_priv->sarea_priv->last_frame);
-
-       ADVANCE_RING();
-}
-
-static void r128_cce_dispatch_flip(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-       DRM_DEBUG("page=%d pfCurrentPage=%d\n",
-                 dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage);
-
-#if R128_PERFORMANCE_BOXES
-       /* Do some trivial performance monitoring...
-        */
-       r128_cce_performance_boxes(dev_priv);
-#endif
-
-       BEGIN_RING(4);
-
-       R128_WAIT_UNTIL_PAGE_FLIPPED();
-       OUT_RING(CCE_PACKET0(R128_CRTC_OFFSET, 0));
-
-       if (dev_priv->current_page == 0) {
-               OUT_RING(dev_priv->back_offset);
-       } else {
-               OUT_RING(dev_priv->front_offset);
-       }
-
-       ADVANCE_RING();
-
-       /* Increment the frame counter.  The client-side 3D driver must
-        * throttle the framerate by waiting for this value before
-        * performing the swapbuffer ioctl.
-        */
-       dev_priv->sarea_priv->last_frame++;
-       dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page =
-           1 - dev_priv->current_page;
-
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
-       OUT_RING(dev_priv->sarea_priv->last_frame);
-
-       ADVANCE_RING();
-}
-
-static void r128_cce_dispatch_vertex(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int format = sarea_priv->vc_format;
-       int offset = buf->bus_address;
-       int size = buf->used;
-       int prim = buf_priv->prim;
-       int i = 0;
-       RING_LOCALS;
-       DRM_DEBUG("buf=%d nbox=%d\n", buf->idx, sarea_priv->nbox);
-
-       if (0)
-               r128_print_dirty("dispatch_vertex", sarea_priv->dirty);
-
-       if (buf->used) {
-               buf_priv->dispatched = 1;
-
-               if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
-                       r128_emit_state(dev_priv);
-               }
-
-               do {
-                       /* Emit the next set of up to three cliprects */
-                       if (i < sarea_priv->nbox) {
-                               r128_emit_clip_rects(dev_priv,
-                                                    &sarea_priv->boxes[i],
-                                                    sarea_priv->nbox - i);
-                       }
-
-                       /* Emit the vertex buffer rendering commands */
-                       BEGIN_RING(5);
-
-                       OUT_RING(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM, 3));
-                       OUT_RING(offset);
-                       OUT_RING(size);
-                       OUT_RING(format);
-                       OUT_RING(prim | R128_CCE_VC_CNTL_PRIM_WALK_LIST |
-                                (size << R128_CCE_VC_CNTL_NUM_SHIFT));
-
-                       ADVANCE_RING();
-
-                       i += 3;
-               } while (i < sarea_priv->nbox);
-       }
-
-       if (buf_priv->discard) {
-               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
-
-               /* Emit the vertex buffer age */
-               BEGIN_RING(2);
-
-               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
-               OUT_RING(buf_priv->age);
-
-               ADVANCE_RING();
-
-               buf->pending = 1;
-               buf->used = 0;
-               /* FIXME: Check dispatched field */
-               buf_priv->dispatched = 0;
-       }
-
-       dev_priv->sarea_priv->last_dispatch++;
-
-       sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
-       sarea_priv->nbox = 0;
-}
-
-static void r128_cce_dispatch_indirect(struct drm_device * dev,
-                                      struct drm_buf * buf, int start, int end)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
-       RING_LOCALS;
-       DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
-
-       if (start != end) {
-               int offset = buf->bus_address + start;
-               int dwords = (end - start + 3) / sizeof(u32);
-
-               /* Indirect buffer data must be an even number of
-                * dwords, so if we've been given an odd number we must
-                * pad the data with a Type-2 CCE packet.
-                */
-               if (dwords & 1) {
-                       u32 *data = (u32 *)
-                           ((char *)dev->agp_buffer_map->handle
-                            + buf->offset + start);
-                       data[dwords++] = cpu_to_le32(R128_CCE_PACKET2);
-               }
-
-               buf_priv->dispatched = 1;
-
-               /* Fire off the indirect buffer */
-               BEGIN_RING(3);
-
-               OUT_RING(CCE_PACKET0(R128_PM4_IW_INDOFF, 1));
-               OUT_RING(offset);
-               OUT_RING(dwords);
-
-               ADVANCE_RING();
-       }
-
-       if (buf_priv->discard) {
-               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
-
-               /* Emit the indirect buffer age */
-               BEGIN_RING(2);
-
-               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
-               OUT_RING(buf_priv->age);
-
-               ADVANCE_RING();
-
-               buf->pending = 1;
-               buf->used = 0;
-               /* FIXME: Check dispatched field */
-               buf_priv->dispatched = 0;
-       }
-
-       dev_priv->sarea_priv->last_dispatch++;
-}
-
-static void r128_cce_dispatch_indices(struct drm_device * dev,
-                                     struct drm_buf * buf,
-                                     int start, int end, int count)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int format = sarea_priv->vc_format;
-       int offset = dev->agp_buffer_map->offset - dev_priv->cce_buffers_offset;
-       int prim = buf_priv->prim;
-       u32 *data;
-       int dwords;
-       int i = 0;
-       RING_LOCALS;
-       DRM_DEBUG("indices: s=%d e=%d c=%d\n", start, end, count);
-
-       if (0)
-               r128_print_dirty("dispatch_indices", sarea_priv->dirty);
-
-       if (start != end) {
-               buf_priv->dispatched = 1;
-
-               if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
-                       r128_emit_state(dev_priv);
-               }
-
-               dwords = (end - start + 3) / sizeof(u32);
-
-               data = (u32 *) ((char *)dev->agp_buffer_map->handle
-                               + buf->offset + start);
-
-               data[0] = cpu_to_le32(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM,
-                                                 dwords - 2));
-
-               data[1] = cpu_to_le32(offset);
-               data[2] = cpu_to_le32(R128_MAX_VB_VERTS);
-               data[3] = cpu_to_le32(format);
-               data[4] = cpu_to_le32((prim | R128_CCE_VC_CNTL_PRIM_WALK_IND |
-                                      (count << 16)));
-
-               if (count & 0x1) {
-#ifdef __LITTLE_ENDIAN
-                       data[dwords - 1] &= 0x0000ffff;
-#else
-                       data[dwords - 1] &= 0xffff0000;
-#endif
-               }
-
-               do {
-                       /* Emit the next set of up to three cliprects */
-                       if (i < sarea_priv->nbox) {
-                               r128_emit_clip_rects(dev_priv,
-                                                    &sarea_priv->boxes[i],
-                                                    sarea_priv->nbox - i);
-                       }
-
-                       r128_cce_dispatch_indirect(dev, buf, start, end);
-
-                       i += 3;
-               } while (i < sarea_priv->nbox);
-       }
-
-       if (buf_priv->discard) {
-               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
-
-               /* Emit the vertex buffer age */
-               BEGIN_RING(2);
-
-               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
-               OUT_RING(buf_priv->age);
-
-               ADVANCE_RING();
-
-               buf->pending = 1;
-               /* FIXME: Check dispatched field */
-               buf_priv->dispatched = 0;
-       }
-
-       dev_priv->sarea_priv->last_dispatch++;
-
-       sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
-       sarea_priv->nbox = 0;
-}
-
-static int r128_cce_dispatch_blit(struct drm_device * dev,
-                                 struct drm_file *file_priv,
-                                 drm_r128_blit_t * blit)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_r128_buf_priv_t *buf_priv;
-       u32 *data;
-       int dword_shift, dwords;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       /* The compiler won't optimize away a division by a variable,
-        * even if the only legal values are powers of two.  Thus, we'll
-        * use a shift instead.
-        */
-       switch (blit->format) {
-       case R128_DATATYPE_ARGB8888:
-               dword_shift = 0;
-               break;
-       case R128_DATATYPE_ARGB1555:
-       case R128_DATATYPE_RGB565:
-       case R128_DATATYPE_ARGB4444:
-       case R128_DATATYPE_YVYU422:
-       case R128_DATATYPE_VYUY422:
-               dword_shift = 1;
-               break;
-       case R128_DATATYPE_CI8:
-       case R128_DATATYPE_RGB8:
-               dword_shift = 2;
-               break;
-       default:
-               DRM_ERROR("invalid blit format %d\n", blit->format);
-               return -EINVAL;
-       }
-
-       /* Flush the pixel cache, and mark the contents as Read Invalid.
-        * This ensures no pixel data gets mixed up with the texture
-        * data from the host data blit, otherwise part of the texture
-        * image may be corrupted.
-        */
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
-       OUT_RING(R128_PC_RI_GUI | R128_PC_FLUSH_GUI);
-
-       ADVANCE_RING();
-
-       /* Dispatch the indirect buffer.
-        */
-       buf = dma->buflist[blit->idx];
-       buf_priv = buf->dev_private;
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", blit->idx);
-               return -EINVAL;
-       }
-
-       buf_priv->discard = 1;
-
-       dwords = (blit->width * blit->height) >> dword_shift;
-
-       data = (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);
-
-       data[0] = cpu_to_le32(CCE_PACKET3(R128_CNTL_HOSTDATA_BLT, dwords + 6));
-       data[1] = cpu_to_le32((R128_GMC_DST_PITCH_OFFSET_CNTL |
-                              R128_GMC_BRUSH_NONE |
-                              (blit->format << 8) |
-                              R128_GMC_SRC_DATATYPE_COLOR |
-                              R128_ROP3_S |
-                              R128_DP_SRC_SOURCE_HOST_DATA |
-                              R128_GMC_CLR_CMP_CNTL_DIS |
-                              R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS));
-
-       data[2] = cpu_to_le32((blit->pitch << 21) | (blit->offset >> 5));
-       data[3] = cpu_to_le32(0xffffffff);
-       data[4] = cpu_to_le32(0xffffffff);
-       data[5] = cpu_to_le32((blit->y << 16) | blit->x);
-       data[6] = cpu_to_le32((blit->height << 16) | blit->width);
-       data[7] = cpu_to_le32(dwords);
-
-       buf->used = (dwords + 8) * sizeof(u32);
-
-       r128_cce_dispatch_indirect(dev, buf, 0, buf->used);
-
-       /* Flush the pixel cache after the blit completes.  This ensures
-        * the texture data is written out to memory before rendering
-        * continues.
-        */
-       BEGIN_RING(2);
-
-       OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
-       OUT_RING(R128_PC_FLUSH_GUI);
-
-       ADVANCE_RING();
-
-       return 0;
-}
-
-/* ================================================================
- * Tiled depth buffer management
- *
- * FIXME: These should all set the destination write mask for when we
- * have hardware stencil support.
- */
-
-static int r128_cce_dispatch_write_span(struct drm_device * dev,
-                                       drm_r128_depth_t * depth)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       int count, x, y;
-       u32 *buffer;
-       u8 *mask;
-       int i, buffer_size, mask_size;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       count = depth->n;
-       if (count > 4096 || count <= 0)
-               return -EMSGSIZE;
-
-       if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
-               return -EFAULT;
-       }
-       if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
-               return -EFAULT;
-       }
-
-       buffer_size = depth->n * sizeof(u32);
-       buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
-       if (buffer == NULL)
-               return -ENOMEM;
-       if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
-               drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-
-       mask_size = depth->n * sizeof(u8);
-       if (depth->mask) {
-               mask = drm_alloc(mask_size, DRM_MEM_BUFS);
-               if (mask == NULL) {
-                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-                       return -ENOMEM;
-               }
-               if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
-                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-                       drm_free(mask, mask_size, DRM_MEM_BUFS);
-                       return -EFAULT;
-               }
-
-               for (i = 0; i < count; i++, x++) {
-                       if (mask[i]) {
-                               BEGIN_RING(6);
-
-                               OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                               OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                        R128_GMC_BRUSH_SOLID_COLOR |
-                                        (dev_priv->depth_fmt << 8) |
-                                        R128_GMC_SRC_DATATYPE_COLOR |
-                                        R128_ROP3_P |
-                                        R128_GMC_CLR_CMP_CNTL_DIS |
-                                        R128_GMC_WR_MSK_DIS);
-
-                               OUT_RING(dev_priv->depth_pitch_offset_c);
-                               OUT_RING(buffer[i]);
-
-                               OUT_RING((x << 16) | y);
-                               OUT_RING((1 << 16) | 1);
-
-                               ADVANCE_RING();
-                       }
-               }
-
-               drm_free(mask, mask_size, DRM_MEM_BUFS);
-       } else {
-               for (i = 0; i < count; i++, x++) {
-                       BEGIN_RING(6);
-
-                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                R128_GMC_BRUSH_SOLID_COLOR |
-                                (dev_priv->depth_fmt << 8) |
-                                R128_GMC_SRC_DATATYPE_COLOR |
-                                R128_ROP3_P |
-                                R128_GMC_CLR_CMP_CNTL_DIS |
-                                R128_GMC_WR_MSK_DIS);
-
-                       OUT_RING(dev_priv->depth_pitch_offset_c);
-                       OUT_RING(buffer[i]);
-
-                       OUT_RING((x << 16) | y);
-                       OUT_RING((1 << 16) | 1);
-
-                       ADVANCE_RING();
-               }
-       }
-
-       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-
-       return 0;
-}
-
-static int r128_cce_dispatch_write_pixels(struct drm_device * dev,
-                                         drm_r128_depth_t * depth)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       int count, *x, *y;
-       u32 *buffer;
-       u8 *mask;
-       int i, xbuf_size, ybuf_size, buffer_size, mask_size;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       count = depth->n;
-       if (count > 4096 || count <= 0)
-               return -EMSGSIZE;
-
-       xbuf_size = count * sizeof(*x);
-       ybuf_size = count * sizeof(*y);
-       x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
-       if (x == NULL) {
-               return -ENOMEM;
-       }
-       y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
-       if (y == NULL) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               return -ENOMEM;
-       }
-       if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-       if (DRM_COPY_FROM_USER(y, depth->y, xbuf_size)) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-
-       buffer_size = depth->n * sizeof(u32);
-       buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
-       if (buffer == NULL) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               return -ENOMEM;
-       }
-       if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-
-       if (depth->mask) {
-               mask_size = depth->n * sizeof(u8);
-               mask = drm_alloc(mask_size, DRM_MEM_BUFS);
-               if (mask == NULL) {
-                       drm_free(x, xbuf_size, DRM_MEM_BUFS);
-                       drm_free(y, ybuf_size, DRM_MEM_BUFS);
-                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-                       return -ENOMEM;
-               }
-               if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
-                       drm_free(x, xbuf_size, DRM_MEM_BUFS);
-                       drm_free(y, ybuf_size, DRM_MEM_BUFS);
-                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-                       drm_free(mask, mask_size, DRM_MEM_BUFS);
-                       return -EFAULT;
-               }
-
-               for (i = 0; i < count; i++) {
-                       if (mask[i]) {
-                               BEGIN_RING(6);
-
-                               OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                               OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                        R128_GMC_BRUSH_SOLID_COLOR |
-                                        (dev_priv->depth_fmt << 8) |
-                                        R128_GMC_SRC_DATATYPE_COLOR |
-                                        R128_ROP3_P |
-                                        R128_GMC_CLR_CMP_CNTL_DIS |
-                                        R128_GMC_WR_MSK_DIS);
-
-                               OUT_RING(dev_priv->depth_pitch_offset_c);
-                               OUT_RING(buffer[i]);
-
-                               OUT_RING((x[i] << 16) | y[i]);
-                               OUT_RING((1 << 16) | 1);
-
-                               ADVANCE_RING();
-                       }
-               }
-
-               drm_free(mask, mask_size, DRM_MEM_BUFS);
-       } else {
-               for (i = 0; i < count; i++) {
-                       BEGIN_RING(6);
-
-                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
-                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
-                                R128_GMC_BRUSH_SOLID_COLOR |
-                                (dev_priv->depth_fmt << 8) |
-                                R128_GMC_SRC_DATATYPE_COLOR |
-                                R128_ROP3_P |
-                                R128_GMC_CLR_CMP_CNTL_DIS |
-                                R128_GMC_WR_MSK_DIS);
-
-                       OUT_RING(dev_priv->depth_pitch_offset_c);
-                       OUT_RING(buffer[i]);
-
-                       OUT_RING((x[i] << 16) | y[i]);
-                       OUT_RING((1 << 16) | 1);
-
-                       ADVANCE_RING();
-               }
-       }
-
-       drm_free(x, xbuf_size, DRM_MEM_BUFS);
-       drm_free(y, ybuf_size, DRM_MEM_BUFS);
-       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
-
-       return 0;
-}
-
-static int r128_cce_dispatch_read_span(struct drm_device * dev,
-                                      drm_r128_depth_t * depth)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       int count, x, y;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       count = depth->n;
-       if (count > 4096 || count <= 0)
-               return -EMSGSIZE;
-
-       if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
-               return -EFAULT;
-       }
-       if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
-               return -EFAULT;
-       }
-
-       BEGIN_RING(7);
-
-       OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
-       OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
-                R128_GMC_DST_PITCH_OFFSET_CNTL |
-                R128_GMC_BRUSH_NONE |
-                (dev_priv->depth_fmt << 8) |
-                R128_GMC_SRC_DATATYPE_COLOR |
-                R128_ROP3_S |
-                R128_DP_SRC_SOURCE_MEMORY |
-                R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
-
-       OUT_RING(dev_priv->depth_pitch_offset_c);
-       OUT_RING(dev_priv->span_pitch_offset_c);
-
-       OUT_RING((x << 16) | y);
-       OUT_RING((0 << 16) | 0);
-       OUT_RING((count << 16) | 1);
-
-       ADVANCE_RING();
-
-       return 0;
-}
-
-static int r128_cce_dispatch_read_pixels(struct drm_device * dev,
-                                        drm_r128_depth_t * depth)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       int count, *x, *y;
-       int i, xbuf_size, ybuf_size;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       count = depth->n;
-       if (count > 4096 || count <= 0)
-               return -EMSGSIZE;
-
-       if (count > dev_priv->depth_pitch) {
-               count = dev_priv->depth_pitch;
-       }
-
-       xbuf_size = count * sizeof(*x);
-       ybuf_size = count * sizeof(*y);
-       x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
-       if (x == NULL) {
-               return -ENOMEM;
-       }
-       y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
-       if (y == NULL) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               return -ENOMEM;
-       }
-       if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-       if (DRM_COPY_FROM_USER(y, depth->y, ybuf_size)) {
-               drm_free(x, xbuf_size, DRM_MEM_BUFS);
-               drm_free(y, ybuf_size, DRM_MEM_BUFS);
-               return -EFAULT;
-       }
-
-       for (i = 0; i < count; i++) {
-               BEGIN_RING(7);
-
-               OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
-               OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
-                        R128_GMC_DST_PITCH_OFFSET_CNTL |
-                        R128_GMC_BRUSH_NONE |
-                        (dev_priv->depth_fmt << 8) |
-                        R128_GMC_SRC_DATATYPE_COLOR |
-                        R128_ROP3_S |
-                        R128_DP_SRC_SOURCE_MEMORY |
-                        R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
-
-               OUT_RING(dev_priv->depth_pitch_offset_c);
-               OUT_RING(dev_priv->span_pitch_offset_c);
-
-               OUT_RING((x[i] << 16) | y[i]);
-               OUT_RING((i << 16) | 0);
-               OUT_RING((1 << 16) | 1);
-
-               ADVANCE_RING();
-       }
-
-       drm_free(x, xbuf_size, DRM_MEM_BUFS);
-       drm_free(y, ybuf_size, DRM_MEM_BUFS);
-
-       return 0;
-}
-
-/* ================================================================
- * Polygon stipple
- */
-
-static void r128_cce_dispatch_stipple(struct drm_device * dev, u32 * stipple)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(33);
-
-       OUT_RING(CCE_PACKET0(R128_BRUSH_DATA0, 31));
-       for (i = 0; i < 32; i++) {
-               OUT_RING(stipple[i]);
-       }
-
-       ADVANCE_RING();
-}
-
-/* ================================================================
- * IOCTL functions
- */
-
-static int r128_cce_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_r128_clear_t *clear = data;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
-
-       r128_cce_dispatch_clear(dev, clear);
-       COMMIT_RING();
-
-       /* Make sure we restore the 3D state next time.
-        */
-       dev_priv->sarea_priv->dirty |= R128_UPLOAD_CONTEXT | R128_UPLOAD_MASKS;
-
-       return 0;
-}
-
-static int r128_do_init_pageflip(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       dev_priv->crtc_offset = R128_READ(R128_CRTC_OFFSET);
-       dev_priv->crtc_offset_cntl = R128_READ(R128_CRTC_OFFSET_CNTL);
-
-       R128_WRITE(R128_CRTC_OFFSET, dev_priv->front_offset);
-       R128_WRITE(R128_CRTC_OFFSET_CNTL,
-                  dev_priv->crtc_offset_cntl | R128_CRTC_OFFSET_FLIP_CNTL);
-
-       dev_priv->page_flipping = 1;
-       dev_priv->current_page = 0;
-       dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page;
-
-       return 0;
-}
-
-static int r128_do_cleanup_pageflip(struct drm_device * dev)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       R128_WRITE(R128_CRTC_OFFSET, dev_priv->crtc_offset);
-       R128_WRITE(R128_CRTC_OFFSET_CNTL, dev_priv->crtc_offset_cntl);
-
-       if (dev_priv->current_page != 0) {
-               r128_cce_dispatch_flip(dev);
-               COMMIT_RING();
-       }
-
-       dev_priv->page_flipping = 0;
-       return 0;
-}
-
-/* Swapping and flipping are different operations, need different ioctls.
- * They can & should be intermixed to support multiple 3d windows.
- */
-
-static int r128_cce_flip(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (!dev_priv->page_flipping)
-               r128_do_init_pageflip(dev);
-
-       r128_cce_dispatch_flip(dev);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_cce_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
-
-       r128_cce_dispatch_swap(dev);
-       dev_priv->sarea_priv->dirty |= (R128_UPLOAD_CONTEXT |
-                                       R128_UPLOAD_MASKS);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_cce_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_r128_buf_priv_t *buf_priv;
-       drm_r128_vertex_t *vertex = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
-                 DRM_CURRENTPID, vertex->idx, vertex->count, vertex->discard);
-
-       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         vertex->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-       if (vertex->prim < 0 ||
-           vertex->prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) {
-               DRM_ERROR("buffer prim %d\n", vertex->prim);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf = dma->buflist[vertex->idx];
-       buf_priv = buf->dev_private;
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
-               return -EINVAL;
-       }
-
-       buf->used = vertex->count;
-       buf_priv->prim = vertex->prim;
-       buf_priv->discard = vertex->discard;
-
-       r128_cce_dispatch_vertex(dev, buf);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_cce_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_r128_buf_priv_t *buf_priv;
-       drm_r128_indices_t *elts = data;
-       int count;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d buf=%d s=%d e=%d d=%d\n", DRM_CURRENTPID,
-                 elts->idx, elts->start, elts->end, elts->discard);
-
-       if (elts->idx < 0 || elts->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         elts->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-       if (elts->prim < 0 ||
-           elts->prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) {
-               DRM_ERROR("buffer prim %d\n", elts->prim);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf = dma->buflist[elts->idx];
-       buf_priv = buf->dev_private;
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", elts->idx);
-               return -EINVAL;
-       }
-
-       count = (elts->end - elts->start) / sizeof(u16);
-       elts->start -= R128_INDEX_PRIM_OFFSET;
-
-       if (elts->start & 0x7) {
-               DRM_ERROR("misaligned buffer 0x%x\n", elts->start);
-               return -EINVAL;
-       }
-       if (elts->start < buf->used) {
-               DRM_ERROR("no header 0x%x - 0x%x\n", elts->start, buf->used);
-               return -EINVAL;
-       }
-
-       buf->used = elts->end;
-       buf_priv->prim = elts->prim;
-       buf_priv->discard = elts->discard;
-
-       r128_cce_dispatch_indices(dev, buf, elts->start, elts->end, count);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_cce_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_blit_t *blit = data;
-       int ret;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("pid=%d index=%d\n", DRM_CURRENTPID, blit->idx);
-
-       if (blit->idx < 0 || blit->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         blit->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       ret = r128_cce_dispatch_blit(dev, file_priv, blit);
-
-       COMMIT_RING();
-       return ret;
-}
-
-static int r128_cce_depth(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_depth_t *depth = data;
-       int ret;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       ret = -EINVAL;
-       switch (depth->func) {
-       case R128_WRITE_SPAN:
-               ret = r128_cce_dispatch_write_span(dev, depth);
-               break;
-       case R128_WRITE_PIXELS:
-               ret = r128_cce_dispatch_write_pixels(dev, depth);
-               break;
-       case R128_READ_SPAN:
-               ret = r128_cce_dispatch_read_span(dev, depth);
-               break;
-       case R128_READ_PIXELS:
-               ret = r128_cce_dispatch_read_pixels(dev, depth);
-               break;
-       }
-
-       COMMIT_RING();
-       return ret;
-}
-
-static int r128_cce_stipple(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_stipple_t *stipple = data;
-       u32 mask[32];
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (DRM_COPY_FROM_USER(&mask, stipple->mask, 32 * sizeof(u32)))
-               return -EFAULT;
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       r128_cce_dispatch_stipple(dev, mask);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_cce_indirect(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_r128_buf_priv_t *buf_priv;
-       drm_r128_indirect_t *indirect = data;
-#if 0
-       RING_LOCALS;
-#endif
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
-                 indirect->idx, indirect->start, indirect->end,
-                 indirect->discard);
-
-       if (indirect->idx < 0 || indirect->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         indirect->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-
-       buf = dma->buflist[indirect->idx];
-       buf_priv = buf->dev_private;
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", indirect->idx);
-               return -EINVAL;
-       }
-
-       if (indirect->start < buf->used) {
-               DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
-                         indirect->start, buf->used);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf->used = indirect->end;
-       buf_priv->discard = indirect->discard;
-
-#if 0
-       /* Wait for the 3D stream to idle before the indirect buffer
-        * containing 2D acceleration commands is processed.
-        */
-       BEGIN_RING(2);
-       RADEON_WAIT_UNTIL_3D_IDLE();
-       ADVANCE_RING();
-#endif
-
-       /* Dispatch the indirect buffer full of commands from the
-        * X server.  This is insecure and is thus only available to
-        * privileged clients.
-        */
-       r128_cce_dispatch_indirect(dev, buf, indirect->start, indirect->end);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int r128_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_r128_private_t *dev_priv = dev->dev_private;
-       drm_r128_getparam_t *param = data;
-       int value;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
-
-       switch (param->param) {
-       case R128_PARAM_IRQ_NR:
-               value = dev->irq;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-void r128_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
-{
-       if (dev->dev_private) {
-               drm_r128_private_t *dev_priv = dev->dev_private;
-               if (dev_priv->page_flipping) {
-                       r128_do_cleanup_pageflip(dev);
-               }
-       }
-}
-
-void r128_driver_lastclose(struct drm_device * dev)
-{
-       r128_do_cleanup_cce(dev);
-}
-
-struct drm_ioctl_desc r128_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_R128_INIT, r128_cce_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_R128_CCE_START, r128_cce_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_R128_CCE_STOP, r128_cce_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_R128_CCE_RESET, r128_cce_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_R128_CCE_IDLE, r128_cce_idle, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_RESET, r128_engine_reset, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_FULLSCREEN, r128_fullscreen, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_SWAP, r128_cce_swap, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_FLIP, r128_cce_flip, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_CLEAR, r128_cce_clear, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_VERTEX, r128_cce_vertex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_INDICES, r128_cce_indices, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_BLIT, r128_cce_blit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_DEPTH, r128_cce_depth, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_STIPPLE, r128_cce_stipple, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_R128_INDIRECT, r128_cce_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_R128_GETPARAM, r128_getparam, DRM_AUTH),
-};
-
-int r128_max_ioctl = DRM_ARRAY_SIZE(r128_ioctls);
diff --git a/drivers/char/drm/r300_cmdbuf.c b/drivers/char/drm/r300_cmdbuf.c
deleted file mode 100644 (file)
index 702df45..0000000
+++ /dev/null
@@ -1,1071 +0,0 @@
-/* r300_cmdbuf.c -- Command buffer emission for R300 -*- linux-c -*-
- *
- * Copyright (C) The Weather Channel, Inc.  2002.
- * Copyright (C) 2004 Nicolai Haehnle.
- * All Rights Reserved.
- *
- * The Weather Channel (TM) funded Tungsten Graphics to develop the
- * initial release of the Radeon 8500 driver under the XFree86 license.
- * This notice must be preserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Nicolai Haehnle <prefect_@gmx.net>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-#include "r300_reg.h"
-
-#define R300_SIMULTANEOUS_CLIPRECTS            4
-
-/* Values for R300_RE_CLIPRECT_CNTL depending on the number of cliprects
- */
-static const int r300_cliprect_cntl[4] = {
-       0xAAAA,
-       0xEEEE,
-       0xFEFE,
-       0xFFFE
-};
-
-/**
- * Emit up to R300_SIMULTANEOUS_CLIPRECTS cliprects from the given command
- * buffer, starting with index n.
- */
-static int r300_emit_cliprects(drm_radeon_private_t *dev_priv,
-                              drm_radeon_kcmd_buffer_t *cmdbuf, int n)
-{
-       struct drm_clip_rect box;
-       int nr;
-       int i;
-       RING_LOCALS;
-
-       nr = cmdbuf->nbox - n;
-       if (nr > R300_SIMULTANEOUS_CLIPRECTS)
-               nr = R300_SIMULTANEOUS_CLIPRECTS;
-
-       DRM_DEBUG("%i cliprects\n", nr);
-
-       if (nr) {
-               BEGIN_RING(6 + nr * 2);
-               OUT_RING(CP_PACKET0(R300_RE_CLIPRECT_TL_0, nr * 2 - 1));
-
-               for (i = 0; i < nr; ++i) {
-                       if (DRM_COPY_FROM_USER_UNCHECKED
-                           (&box, &cmdbuf->boxes[n + i], sizeof(box))) {
-                               DRM_ERROR("copy cliprect faulted\n");
-                               return -EFAULT;
-                       }
-
-                       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
-                               box.x1 = (box.x1) &
-                                       R300_CLIPRECT_MASK;
-                               box.y1 = (box.y1) &
-                                       R300_CLIPRECT_MASK;
-                               box.x2 = (box.x2) &
-                                       R300_CLIPRECT_MASK;
-                               box.y2 = (box.y2) &
-                                       R300_CLIPRECT_MASK;
-                       } else {
-                               box.x1 = (box.x1 + R300_CLIPRECT_OFFSET) &
-                                       R300_CLIPRECT_MASK;
-                               box.y1 = (box.y1 + R300_CLIPRECT_OFFSET) &
-                                       R300_CLIPRECT_MASK;
-                               box.x2 = (box.x2 + R300_CLIPRECT_OFFSET) &
-                                       R300_CLIPRECT_MASK;
-                               box.y2 = (box.y2 + R300_CLIPRECT_OFFSET) &
-                                       R300_CLIPRECT_MASK;
-
-                       }
-                       OUT_RING((box.x1 << R300_CLIPRECT_X_SHIFT) |
-                                (box.y1 << R300_CLIPRECT_Y_SHIFT));
-                       OUT_RING((box.x2 << R300_CLIPRECT_X_SHIFT) |
-                                (box.y2 << R300_CLIPRECT_Y_SHIFT));
-
-               }
-
-               OUT_RING_REG(R300_RE_CLIPRECT_CNTL, r300_cliprect_cntl[nr - 1]);
-
-               /* TODO/SECURITY: Force scissors to a safe value, otherwise the
-                * client might be able to trample over memory.
-                * The impact should be very limited, but I'd rather be safe than
-                * sorry.
-                */
-               OUT_RING(CP_PACKET0(R300_RE_SCISSORS_TL, 1));
-               OUT_RING(0);
-               OUT_RING(R300_SCISSORS_X_MASK | R300_SCISSORS_Y_MASK);
-               ADVANCE_RING();
-       } else {
-               /* Why we allow zero cliprect rendering:
-                * There are some commands in a command buffer that must be submitted
-                * even when there are no cliprects, e.g. DMA buffer discard
-                * or state setting (though state setting could be avoided by
-                * simulating a loss of context).
-                *
-                * Now since the cmdbuf interface is so chaotic right now (and is
-                * bound to remain that way for a bit until things settle down),
-                * it is basically impossible to filter out the commands that are
-                * necessary and those that aren't.
-                *
-                * So I choose the safe way and don't do any filtering at all;
-                * instead, I simply set up the engine so that all rendering
-                * can't produce any fragments.
-                */
-               BEGIN_RING(2);
-               OUT_RING_REG(R300_RE_CLIPRECT_CNTL, 0);
-               ADVANCE_RING();
-       }
-
-       return 0;
-}
-
-static u8 r300_reg_flags[0x10000 >> 2];
-
-void r300_init_reg_flags(struct drm_device *dev)
-{
-       int i;
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       memset(r300_reg_flags, 0, 0x10000 >> 2);
-#define ADD_RANGE_MARK(reg, count,mark) \
-               for(i=((reg)>>2);i<((reg)>>2)+(count);i++)\
-                       r300_reg_flags[i]|=(mark);
-
-#define MARK_SAFE              1
-#define MARK_CHECK_OFFSET      2
-
-#define ADD_RANGE(reg, count)  ADD_RANGE_MARK(reg, count, MARK_SAFE)
-
-       /* these match cmducs() command in r300_driver/r300/r300_cmdbuf.c */
-       ADD_RANGE(R300_SE_VPORT_XSCALE, 6);
-       ADD_RANGE(R300_VAP_CNTL, 1);
-       ADD_RANGE(R300_SE_VTE_CNTL, 2);
-       ADD_RANGE(0x2134, 2);
-       ADD_RANGE(R300_VAP_CNTL_STATUS, 1);
-       ADD_RANGE(R300_VAP_INPUT_CNTL_0, 2);
-       ADD_RANGE(0x21DC, 1);
-       ADD_RANGE(R300_VAP_UNKNOWN_221C, 1);
-       ADD_RANGE(R300_VAP_CLIP_X_0, 4);
-       ADD_RANGE(R300_VAP_PVS_WAITIDLE, 1);
-       ADD_RANGE(R300_VAP_UNKNOWN_2288, 1);
-       ADD_RANGE(R300_VAP_OUTPUT_VTX_FMT_0, 2);
-       ADD_RANGE(R300_VAP_PVS_CNTL_1, 3);
-       ADD_RANGE(R300_GB_ENABLE, 1);
-       ADD_RANGE(R300_GB_MSPOS0, 5);
-       ADD_RANGE(R300_TX_CNTL, 1);
-       ADD_RANGE(R300_TX_ENABLE, 1);
-       ADD_RANGE(0x4200, 4);
-       ADD_RANGE(0x4214, 1);
-       ADD_RANGE(R300_RE_POINTSIZE, 1);
-       ADD_RANGE(0x4230, 3);
-       ADD_RANGE(R300_RE_LINE_CNT, 1);
-       ADD_RANGE(R300_RE_UNK4238, 1);
-       ADD_RANGE(0x4260, 3);
-       ADD_RANGE(R300_RE_SHADE, 4);
-       ADD_RANGE(R300_RE_POLYGON_MODE, 5);
-       ADD_RANGE(R300_RE_ZBIAS_CNTL, 1);
-       ADD_RANGE(R300_RE_ZBIAS_T_FACTOR, 4);
-       ADD_RANGE(R300_RE_OCCLUSION_CNTL, 1);
-       ADD_RANGE(R300_RE_CULL_CNTL, 1);
-       ADD_RANGE(0x42C0, 2);
-       ADD_RANGE(R300_RS_CNTL_0, 2);
-
-       ADD_RANGE(R300_SC_HYPERZ, 2);
-       ADD_RANGE(0x43E8, 1);
-
-       ADD_RANGE(0x46A4, 5);
-
-       ADD_RANGE(R300_RE_FOG_STATE, 1);
-       ADD_RANGE(R300_FOG_COLOR_R, 3);
-       ADD_RANGE(R300_PP_ALPHA_TEST, 2);
-       ADD_RANGE(0x4BD8, 1);
-       ADD_RANGE(R300_PFS_PARAM_0_X, 64);
-       ADD_RANGE(0x4E00, 1);
-       ADD_RANGE(R300_RB3D_CBLEND, 2);
-       ADD_RANGE(R300_RB3D_COLORMASK, 1);
-       ADD_RANGE(R300_RB3D_BLEND_COLOR, 3);
-       ADD_RANGE_MARK(R300_RB3D_COLOROFFSET0, 1, MARK_CHECK_OFFSET);   /* check offset */
-       ADD_RANGE(R300_RB3D_COLORPITCH0, 1);
-       ADD_RANGE(0x4E50, 9);
-       ADD_RANGE(0x4E88, 1);
-       ADD_RANGE(0x4EA0, 2);
-       ADD_RANGE(R300_ZB_CNTL, 3);
-       ADD_RANGE(R300_ZB_FORMAT, 4);
-       ADD_RANGE_MARK(R300_ZB_DEPTHOFFSET, 1, MARK_CHECK_OFFSET);      /* check offset */
-       ADD_RANGE(R300_ZB_DEPTHPITCH, 1);
-       ADD_RANGE(R300_ZB_DEPTHCLEARVALUE, 1);
-       ADD_RANGE(R300_ZB_ZMASK_OFFSET, 13);
-
-       ADD_RANGE(R300_TX_FILTER_0, 16);
-       ADD_RANGE(R300_TX_FILTER1_0, 16);
-       ADD_RANGE(R300_TX_SIZE_0, 16);
-       ADD_RANGE(R300_TX_FORMAT_0, 16);
-       ADD_RANGE(R300_TX_PITCH_0, 16);
-       /* Texture offset is dangerous and needs more checking */
-       ADD_RANGE_MARK(R300_TX_OFFSET_0, 16, MARK_CHECK_OFFSET);
-       ADD_RANGE(R300_TX_CHROMA_KEY_0, 16);
-       ADD_RANGE(R300_TX_BORDER_COLOR_0, 16);
-
-       /* Sporadic registers used as primitives are emitted */
-       ADD_RANGE(R300_ZB_ZCACHE_CTLSTAT, 1);
-       ADD_RANGE(R300_RB3D_DSTCACHE_CTLSTAT, 1);
-       ADD_RANGE(R300_VAP_INPUT_ROUTE_0_0, 8);
-       ADD_RANGE(R300_VAP_INPUT_ROUTE_1_0, 8);
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
-               ADD_RANGE(R500_VAP_INDEX_OFFSET, 1);
-               ADD_RANGE(R500_US_CONFIG, 2);
-               ADD_RANGE(R500_US_CODE_ADDR, 3);
-               ADD_RANGE(R500_US_FC_CTRL, 1);
-               ADD_RANGE(R500_RS_IP_0, 16);
-               ADD_RANGE(R500_RS_INST_0, 16);
-               ADD_RANGE(R500_RB3D_COLOR_CLEAR_VALUE_AR, 2);
-               ADD_RANGE(R500_RB3D_CONSTANT_COLOR_AR, 2);
-               ADD_RANGE(R500_ZB_FIFO_SIZE, 2);
-       } else {
-               ADD_RANGE(R300_PFS_CNTL_0, 3);
-               ADD_RANGE(R300_PFS_NODE_0, 4);
-               ADD_RANGE(R300_PFS_TEXI_0, 64);
-               ADD_RANGE(R300_PFS_INSTR0_0, 64);
-               ADD_RANGE(R300_PFS_INSTR1_0, 64);
-               ADD_RANGE(R300_PFS_INSTR2_0, 64);
-               ADD_RANGE(R300_PFS_INSTR3_0, 64);
-               ADD_RANGE(R300_RS_INTERP_0, 8);
-               ADD_RANGE(R300_RS_ROUTE_0, 8);
-
-       }
-}
-
-static __inline__ int r300_check_range(unsigned reg, int count)
-{
-       int i;
-       if (reg & ~0xffff)
-               return -1;
-       for (i = (reg >> 2); i < (reg >> 2) + count; i++)
-               if (r300_reg_flags[i] != MARK_SAFE)
-                       return 1;
-       return 0;
-}
-
-static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
-                                                         dev_priv,
-                                                         drm_radeon_kcmd_buffer_t
-                                                         * cmdbuf,
-                                                         drm_r300_cmd_header_t
-                                                         header)
-{
-       int reg;
-       int sz;
-       int i;
-       int values[64];
-       RING_LOCALS;
-
-       sz = header.packet0.count;
-       reg = (header.packet0.reghi << 8) | header.packet0.reglo;
-
-       if ((sz > 64) || (sz < 0)) {
-               DRM_ERROR
-                   ("Cannot emit more than 64 values at a time (reg=%04x sz=%d)\n",
-                    reg, sz);
-               return -EINVAL;
-       }
-       for (i = 0; i < sz; i++) {
-               values[i] = ((int *)cmdbuf->buf)[i];
-               switch (r300_reg_flags[(reg >> 2) + i]) {
-               case MARK_SAFE:
-                       break;
-               case MARK_CHECK_OFFSET:
-                       if (!radeon_check_offset(dev_priv, (u32) values[i])) {
-                               DRM_ERROR
-                                   ("Offset failed range check (reg=%04x sz=%d)\n",
-                                    reg, sz);
-                               return -EINVAL;
-                       }
-                       break;
-               default:
-                       DRM_ERROR("Register %04x failed check as flag=%02x\n",
-                                 reg + i * 4, r300_reg_flags[(reg >> 2) + i]);
-                       return -EINVAL;
-               }
-       }
-
-       BEGIN_RING(1 + sz);
-       OUT_RING(CP_PACKET0(reg, sz - 1));
-       OUT_RING_TABLE(values, sz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * 4;
-       cmdbuf->bufsz -= sz * 4;
-
-       return 0;
-}
-
-/**
- * Emits a packet0 setting arbitrary registers.
- * Called by r300_do_cp_cmdbuf.
- *
- * Note that checks are performed on contents and addresses of the registers
- */
-static __inline__ int r300_emit_packet0(drm_radeon_private_t *dev_priv,
-                                       drm_radeon_kcmd_buffer_t *cmdbuf,
-                                       drm_r300_cmd_header_t header)
-{
-       int reg;
-       int sz;
-       RING_LOCALS;
-
-       sz = header.packet0.count;
-       reg = (header.packet0.reghi << 8) | header.packet0.reglo;
-
-       if (!sz)
-               return 0;
-
-       if (sz * 4 > cmdbuf->bufsz)
-               return -EINVAL;
-
-       if (reg + sz * 4 >= 0x10000) {
-               DRM_ERROR("No such registers in hardware reg=%04x sz=%d\n", reg,
-                         sz);
-               return -EINVAL;
-       }
-
-       if (r300_check_range(reg, sz)) {
-               /* go and check everything */
-               return r300_emit_carefully_checked_packet0(dev_priv, cmdbuf,
-                                                          header);
-       }
-       /* the rest of the data is safe to emit, whatever the values the user passed */
-
-       BEGIN_RING(1 + sz);
-       OUT_RING(CP_PACKET0(reg, sz - 1));
-       OUT_RING_TABLE((int *)cmdbuf->buf, sz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * 4;
-       cmdbuf->bufsz -= sz * 4;
-
-       return 0;
-}
-
-/**
- * Uploads user-supplied vertex program instructions or parameters onto
- * the graphics card.
- * Called by r300_do_cp_cmdbuf.
- */
-static __inline__ int r300_emit_vpu(drm_radeon_private_t *dev_priv,
-                                   drm_radeon_kcmd_buffer_t *cmdbuf,
-                                   drm_r300_cmd_header_t header)
-{
-       int sz;
-       int addr;
-       RING_LOCALS;
-
-       sz = header.vpu.count;
-       addr = (header.vpu.adrhi << 8) | header.vpu.adrlo;
-
-       if (!sz)
-               return 0;
-       if (sz * 16 > cmdbuf->bufsz)
-               return -EINVAL;
-
-       BEGIN_RING(5 + sz * 4);
-       /* Wait for VAP to come to senses.. */
-       /* there is no need to emit it multiple times, (only once before VAP is programmed,
-          but this optimization is for later */
-       OUT_RING_REG(R300_VAP_PVS_WAITIDLE, 0);
-       OUT_RING_REG(R300_VAP_PVS_UPLOAD_ADDRESS, addr);
-       OUT_RING(CP_PACKET0_TABLE(R300_VAP_PVS_UPLOAD_DATA, sz * 4 - 1));
-       OUT_RING_TABLE((int *)cmdbuf->buf, sz * 4);
-
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * 16;
-       cmdbuf->bufsz -= sz * 16;
-
-       return 0;
-}
-
-/**
- * Emit a clear packet from userspace.
- * Called by r300_emit_packet3.
- */
-static __inline__ int r300_emit_clear(drm_radeon_private_t *dev_priv,
-                                     drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       RING_LOCALS;
-
-       if (8 * 4 > cmdbuf->bufsz)
-               return -EINVAL;
-
-       BEGIN_RING(10);
-       OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 8));
-       OUT_RING(R300_PRIM_TYPE_POINT | R300_PRIM_WALK_RING |
-                (1 << R300_PRIM_NUM_VERTICES_SHIFT));
-       OUT_RING_TABLE((int *)cmdbuf->buf, 8);
-       ADVANCE_RING();
-
-       cmdbuf->buf += 8 * 4;
-       cmdbuf->bufsz -= 8 * 4;
-
-       return 0;
-}
-
-static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
-                                              drm_radeon_kcmd_buffer_t *cmdbuf,
-                                              u32 header)
-{
-       int count, i, k;
-#define MAX_ARRAY_PACKET  64
-       u32 payload[MAX_ARRAY_PACKET];
-       u32 narrays;
-       RING_LOCALS;
-
-       count = (header >> 16) & 0x3fff;
-
-       if ((count + 1) > MAX_ARRAY_PACKET) {
-               DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
-                         count);
-               return -EINVAL;
-       }
-       memset(payload, 0, MAX_ARRAY_PACKET * 4);
-       memcpy(payload, cmdbuf->buf + 4, (count + 1) * 4);
-
-       /* carefully check packet contents */
-
-       narrays = payload[0];
-       k = 0;
-       i = 1;
-       while ((k < narrays) && (i < (count + 1))) {
-               i++;            /* skip attribute field */
-               if (!radeon_check_offset(dev_priv, payload[i])) {
-                       DRM_ERROR
-                           ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
-                            k, i);
-                       return -EINVAL;
-               }
-               k++;
-               i++;
-               if (k == narrays)
-                       break;
-               /* have one more to process, they come in pairs */
-               if (!radeon_check_offset(dev_priv, payload[i])) {
-                       DRM_ERROR
-                           ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
-                            k, i);
-                       return -EINVAL;
-               }
-               k++;
-               i++;
-       }
-       /* do the counts match what we expect ? */
-       if ((k != narrays) || (i != (count + 1))) {
-               DRM_ERROR
-                   ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
-                    k, i, narrays, count + 1);
-               return -EINVAL;
-       }
-
-       /* all clear, output packet */
-
-       BEGIN_RING(count + 2);
-       OUT_RING(header);
-       OUT_RING_TABLE(payload, count + 1);
-       ADVANCE_RING();
-
-       cmdbuf->buf += (count + 2) * 4;
-       cmdbuf->bufsz -= (count + 2) * 4;
-
-       return 0;
-}
-
-static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
-                                            drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       u32 *cmd = (u32 *) cmdbuf->buf;
-       int count, ret;
-       RING_LOCALS;
-
-       count=(cmd[0]>>16) & 0x3fff;
-
-       if (cmd[0] & 0x8000) {
-               u32 offset;
-
-               if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
-                             | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
-                       offset = cmd[2] << 10;
-                       ret = !radeon_check_offset(dev_priv, offset);
-                       if (ret) {
-                               DRM_ERROR("Invalid bitblt first offset is %08X\n", offset);
-                               return -EINVAL;
-                       }
-               }
-
-               if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
-                   (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
-                       offset = cmd[3] << 10;
-                       ret = !radeon_check_offset(dev_priv, offset);
-                       if (ret) {
-                               DRM_ERROR("Invalid bitblt second offset is %08X\n", offset);
-                               return -EINVAL;
-                       }
-
-               }
-       }
-
-       BEGIN_RING(count+2);
-       OUT_RING(cmd[0]);
-       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
-       ADVANCE_RING();
-
-       cmdbuf->buf += (count+2)*4;
-       cmdbuf->bufsz -= (count+2)*4;
-
-       return 0;
-}
-
-static __inline__ int r300_emit_indx_buffer(drm_radeon_private_t *dev_priv,
-                                            drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       u32 *cmd = (u32 *) cmdbuf->buf;
-       int count, ret;
-       RING_LOCALS;
-
-       count=(cmd[0]>>16) & 0x3fff;
-
-       if ((cmd[1] & 0x8000ffff) != 0x80000810) {
-               DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
-               return -EINVAL;
-       }
-       ret = !radeon_check_offset(dev_priv, cmd[2]);
-       if (ret) {
-               DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
-               return -EINVAL;
-       }
-
-       BEGIN_RING(count+2);
-       OUT_RING(cmd[0]);
-       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
-       ADVANCE_RING();
-
-       cmdbuf->buf += (count+2)*4;
-       cmdbuf->bufsz -= (count+2)*4;
-
-       return 0;
-}
-
-static __inline__ int r300_emit_raw_packet3(drm_radeon_private_t *dev_priv,
-                                           drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       u32 header;
-       int count;
-       RING_LOCALS;
-
-       if (4 > cmdbuf->bufsz)
-               return -EINVAL;
-
-       /* Fixme !! This simply emits a packet without much checking.
-          We need to be smarter. */
-
-       /* obtain first word - actual packet3 header */
-       header = *(u32 *) cmdbuf->buf;
-
-       /* Is it packet 3 ? */
-       if ((header >> 30) != 0x3) {
-               DRM_ERROR("Not a packet3 header (0x%08x)\n", header);
-               return -EINVAL;
-       }
-
-       count = (header >> 16) & 0x3fff;
-
-       /* Check again now that we know how much data to expect */
-       if ((count + 2) * 4 > cmdbuf->bufsz) {
-               DRM_ERROR
-                   ("Expected packet3 of length %d but have only %d bytes left\n",
-                    (count + 2) * 4, cmdbuf->bufsz);
-               return -EINVAL;
-       }
-
-       /* Is it a packet type we know about ? */
-       switch (header & 0xff00) {
-       case RADEON_3D_LOAD_VBPNTR:     /* load vertex array pointers */
-               return r300_emit_3d_load_vbpntr(dev_priv, cmdbuf, header);
-
-       case RADEON_CNTL_BITBLT_MULTI:
-               return r300_emit_bitblt_multi(dev_priv, cmdbuf);
-
-       case RADEON_CP_INDX_BUFFER:     /* DRAW_INDX_2 without INDX_BUFFER seems to lock up the gpu */
-               return r300_emit_indx_buffer(dev_priv, cmdbuf);
-       case RADEON_CP_3D_DRAW_IMMD_2:  /* triggers drawing using in-packet vertex data */
-       case RADEON_CP_3D_DRAW_VBUF_2:  /* triggers drawing of vertex buffers setup elsewhere */
-       case RADEON_CP_3D_DRAW_INDX_2:  /* triggers drawing using indices to vertex buffer */
-       case RADEON_WAIT_FOR_IDLE:
-       case RADEON_CP_NOP:
-               /* these packets are safe */
-               break;
-       default:
-               DRM_ERROR("Unknown packet3 header (0x%08x)\n", header);
-               return -EINVAL;
-       }
-
-       BEGIN_RING(count + 2);
-       OUT_RING(header);
-       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
-       ADVANCE_RING();
-
-       cmdbuf->buf += (count + 2) * 4;
-       cmdbuf->bufsz -= (count + 2) * 4;
-
-       return 0;
-}
-
-/**
- * Emit a rendering packet3 from userspace.
- * Called by r300_do_cp_cmdbuf.
- */
-static __inline__ int r300_emit_packet3(drm_radeon_private_t *dev_priv,
-                                       drm_radeon_kcmd_buffer_t *cmdbuf,
-                                       drm_r300_cmd_header_t header)
-{
-       int n;
-       int ret;
-       char *orig_buf = cmdbuf->buf;
-       int orig_bufsz = cmdbuf->bufsz;
-
-       /* This is a do-while-loop so that we run the interior at least once,
-        * even if cmdbuf->nbox is 0. Compare r300_emit_cliprects for rationale.
-        */
-       n = 0;
-       do {
-               if (cmdbuf->nbox > R300_SIMULTANEOUS_CLIPRECTS) {
-                       ret = r300_emit_cliprects(dev_priv, cmdbuf, n);
-                       if (ret)
-                               return ret;
-
-                       cmdbuf->buf = orig_buf;
-                       cmdbuf->bufsz = orig_bufsz;
-               }
-
-               switch (header.packet3.packet) {
-               case R300_CMD_PACKET3_CLEAR:
-                       DRM_DEBUG("R300_CMD_PACKET3_CLEAR\n");
-                       ret = r300_emit_clear(dev_priv, cmdbuf);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_clear failed\n");
-                               return ret;
-                       }
-                       break;
-
-               case R300_CMD_PACKET3_RAW:
-                       DRM_DEBUG("R300_CMD_PACKET3_RAW\n");
-                       ret = r300_emit_raw_packet3(dev_priv, cmdbuf);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_raw_packet3 failed\n");
-                               return ret;
-                       }
-                       break;
-
-               default:
-                       DRM_ERROR("bad packet3 type %i at %p\n",
-                                 header.packet3.packet,
-                                 cmdbuf->buf - sizeof(header));
-                       return -EINVAL;
-               }
-
-               n += R300_SIMULTANEOUS_CLIPRECTS;
-       } while (n < cmdbuf->nbox);
-
-       return 0;
-}
-
-/* Some of the R300 chips seem to be extremely touchy about the two registers
- * that are configured in r300_pacify.
- * Among the worst offenders seems to be the R300 ND (0x4E44): When userspace
- * sends a command buffer that contains only state setting commands and a
- * vertex program/parameter upload sequence, this will eventually lead to a
- * lockup, unless the sequence is bracketed by calls to r300_pacify.
- * So we should take great care to *always* call r300_pacify before
- * *anything* 3D related, and again afterwards. This is what the
- * call bracket in r300_do_cp_cmdbuf is for.
- */
-
-/**
- * Emit the sequence to pacify R300.
- */
-static __inline__ void r300_pacify(drm_radeon_private_t *dev_priv)
-{
-       RING_LOCALS;
-
-       BEGIN_RING(6);
-       OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
-       OUT_RING(R300_RB3D_DSTCACHE_UNKNOWN_0A);
-       OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0));
-       OUT_RING(R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE|
-                R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
-       OUT_RING(CP_PACKET3(RADEON_CP_NOP, 0));
-       OUT_RING(0x0);
-       ADVANCE_RING();
-}
-
-/**
- * Called by r300_do_cp_cmdbuf to update the internal buffer age and state.
- * The actual age emit is done by r300_do_cp_cmdbuf, which is why you must
- * be careful about how this function is called.
- */
-static void r300_discard_buffer(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
-
-       buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
-       buf->pending = 1;
-       buf->used = 0;
-}
-
-static void r300_cmd_wait(drm_radeon_private_t * dev_priv,
-                         drm_r300_cmd_header_t header)
-{
-       u32 wait_until;
-       RING_LOCALS;
-
-       if (!header.wait.flags)
-               return;
-
-       wait_until = 0;
-
-       switch(header.wait.flags) {
-       case R300_WAIT_2D:
-               wait_until = RADEON_WAIT_2D_IDLE;
-               break;
-       case R300_WAIT_3D:
-               wait_until = RADEON_WAIT_3D_IDLE;
-               break;
-       case R300_NEW_WAIT_2D_3D:
-               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_3D_IDLE;
-               break;
-       case R300_NEW_WAIT_2D_2D_CLEAN:
-               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_2D_IDLECLEAN;
-               break;
-       case R300_NEW_WAIT_3D_3D_CLEAN:
-               wait_until = RADEON_WAIT_3D_IDLE|RADEON_WAIT_3D_IDLECLEAN;
-               break;
-       case R300_NEW_WAIT_2D_2D_CLEAN_3D_3D_CLEAN:
-               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_2D_IDLECLEAN;
-               wait_until |= RADEON_WAIT_3D_IDLE|RADEON_WAIT_3D_IDLECLEAN;
-               break;
-       default:
-               return;
-       }
-
-       BEGIN_RING(2);
-       OUT_RING(CP_PACKET0(RADEON_WAIT_UNTIL, 0));
-       OUT_RING(wait_until);
-       ADVANCE_RING();
-}
-
-static int r300_scratch(drm_radeon_private_t *dev_priv,
-                       drm_radeon_kcmd_buffer_t *cmdbuf,
-                       drm_r300_cmd_header_t header)
-{
-       u32 *ref_age_base;
-       u32 i, buf_idx, h_pending;
-       RING_LOCALS;
-
-       if (cmdbuf->bufsz <
-           (sizeof(u64) + header.scratch.n_bufs * sizeof(buf_idx))) {
-               return -EINVAL;
-       }
-
-       if (header.scratch.reg >= 5) {
-               return -EINVAL;
-       }
-
-       dev_priv->scratch_ages[header.scratch.reg]++;
-
-       ref_age_base =  (u32 *)(unsigned long)*((uint64_t *)cmdbuf->buf);
-
-       cmdbuf->buf += sizeof(u64);
-       cmdbuf->bufsz -= sizeof(u64);
-
-       for (i=0; i < header.scratch.n_bufs; i++) {
-               buf_idx = *(u32 *)cmdbuf->buf;
-               buf_idx *= 2; /* 8 bytes per buf */
-
-               if (DRM_COPY_TO_USER(ref_age_base + buf_idx, &dev_priv->scratch_ages[header.scratch.reg], sizeof(u32))) {
-                       return -EINVAL;
-               }
-
-               if (DRM_COPY_FROM_USER(&h_pending, ref_age_base + buf_idx + 1, sizeof(u32))) {
-                       return -EINVAL;
-               }
-
-               if (h_pending == 0) {
-                       return -EINVAL;
-               }
-
-               h_pending--;
-
-               if (DRM_COPY_TO_USER(ref_age_base + buf_idx + 1, &h_pending, sizeof(u32))) {
-                       return -EINVAL;
-               }
-
-               cmdbuf->buf += sizeof(buf_idx);
-               cmdbuf->bufsz -= sizeof(buf_idx);
-       }
-
-       BEGIN_RING(2);
-       OUT_RING( CP_PACKET0( RADEON_SCRATCH_REG0 + header.scratch.reg * 4, 0 ) );
-       OUT_RING( dev_priv->scratch_ages[header.scratch.reg] );
-       ADVANCE_RING();
-
-       return 0;
-}
-
-/**
- * Uploads user-supplied vertex program instructions or parameters onto
- * the graphics card.
- * Called by r300_do_cp_cmdbuf.
- */
-static inline int r300_emit_r500fp(drm_radeon_private_t *dev_priv,
-                                      drm_radeon_kcmd_buffer_t *cmdbuf,
-                                      drm_r300_cmd_header_t header)
-{
-       int sz;
-       int addr;
-       int type;
-       int clamp;
-       int stride;
-       RING_LOCALS;
-
-       sz = header.r500fp.count;
-       /* address is 9 bits 0 - 8, bit 1 of flags is part of address */
-       addr = ((header.r500fp.adrhi_flags & 1) << 8) | header.r500fp.adrlo;
-
-       type = !!(header.r500fp.adrhi_flags & R500FP_CONSTANT_TYPE);
-       clamp = !!(header.r500fp.adrhi_flags & R500FP_CONSTANT_CLAMP);
-
-       addr |= (type << 16);
-       addr |= (clamp << 17);
-
-       stride = type ? 4 : 6;
-
-       DRM_DEBUG("r500fp %d %d type: %d\n", sz, addr, type);
-       if (!sz)
-               return 0;
-       if (sz * stride * 4 > cmdbuf->bufsz)
-               return -EINVAL;
-
-       BEGIN_RING(3 + sz * stride);
-       OUT_RING_REG(R500_GA_US_VECTOR_INDEX, addr);
-       OUT_RING(CP_PACKET0_TABLE(R500_GA_US_VECTOR_DATA, sz * stride - 1));
-       OUT_RING_TABLE((int *)cmdbuf->buf, sz * stride);
-
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * stride * 4;
-       cmdbuf->bufsz -= sz * stride * 4;
-
-       return 0;
-}
-
-
-/**
- * Parses and validates a user-supplied command buffer and emits appropriate
- * commands on the DMA ring buffer.
- * Called by the ioctl handler function radeon_cp_cmdbuf.
- */
-int r300_do_cp_cmdbuf(struct drm_device *dev,
-                     struct drm_file *file_priv,
-                     drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf = NULL;
-       int emit_dispatch_age = 0;
-       int ret = 0;
-
-       DRM_DEBUG("\n");
-
-       /* See the comment above r300_emit_begin3d for why this call must be here,
-        * and what the cleanup gotos are for. */
-       r300_pacify(dev_priv);
-
-       if (cmdbuf->nbox <= R300_SIMULTANEOUS_CLIPRECTS) {
-               ret = r300_emit_cliprects(dev_priv, cmdbuf, 0);
-               if (ret)
-                       goto cleanup;
-       }
-
-       while (cmdbuf->bufsz >= sizeof(drm_r300_cmd_header_t)) {
-               int idx;
-               drm_r300_cmd_header_t header;
-
-               header.u = *(unsigned int *)cmdbuf->buf;
-
-               cmdbuf->buf += sizeof(header);
-               cmdbuf->bufsz -= sizeof(header);
-
-               switch (header.header.cmd_type) {
-               case R300_CMD_PACKET0:
-                       DRM_DEBUG("R300_CMD_PACKET0\n");
-                       ret = r300_emit_packet0(dev_priv, cmdbuf, header);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_packet0 failed\n");
-                               goto cleanup;
-                       }
-                       break;
-
-               case R300_CMD_VPU:
-                       DRM_DEBUG("R300_CMD_VPU\n");
-                       ret = r300_emit_vpu(dev_priv, cmdbuf, header);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_vpu failed\n");
-                               goto cleanup;
-                       }
-                       break;
-
-               case R300_CMD_PACKET3:
-                       DRM_DEBUG("R300_CMD_PACKET3\n");
-                       ret = r300_emit_packet3(dev_priv, cmdbuf, header);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_packet3 failed\n");
-                               goto cleanup;
-                       }
-                       break;
-
-               case R300_CMD_END3D:
-                       DRM_DEBUG("R300_CMD_END3D\n");
-                       /* TODO:
-                          Ideally userspace driver should not need to issue this call,
-                          i.e. the drm driver should issue it automatically and prevent
-                          lockups.
-
-                          In practice, we do not understand why this call is needed and what
-                          it does (except for some vague guesses that it has to do with cache
-                          coherence) and so the user space driver does it.
-
-                          Once we are sure which uses prevent lockups the code could be moved
-                          into the kernel and the userspace driver will not
-                          need to use this command.
-
-                          Note that issuing this command does not hurt anything
-                          except, possibly, performance */
-                       r300_pacify(dev_priv);
-                       break;
-
-               case R300_CMD_CP_DELAY:
-                       /* simple enough, we can do it here */
-                       DRM_DEBUG("R300_CMD_CP_DELAY\n");
-                       {
-                               int i;
-                               RING_LOCALS;
-
-                               BEGIN_RING(header.delay.count);
-                               for (i = 0; i < header.delay.count; i++)
-                                       OUT_RING(RADEON_CP_PACKET2);
-                               ADVANCE_RING();
-                       }
-                       break;
-
-               case R300_CMD_DMA_DISCARD:
-                       DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
-                       idx = header.dma.buf_idx;
-                       if (idx < 0 || idx >= dma->buf_count) {
-                               DRM_ERROR("buffer index %d (of %d max)\n",
-                                         idx, dma->buf_count - 1);
-                               ret = -EINVAL;
-                               goto cleanup;
-                       }
-
-                       buf = dma->buflist[idx];
-                       if (buf->file_priv != file_priv || buf->pending) {
-                               DRM_ERROR("bad buffer %p %p %d\n",
-                                         buf->file_priv, file_priv,
-                                         buf->pending);
-                               ret = -EINVAL;
-                               goto cleanup;
-                       }
-
-                       emit_dispatch_age = 1;
-                       r300_discard_buffer(dev, buf);
-                       break;
-
-               case R300_CMD_WAIT:
-                       DRM_DEBUG("R300_CMD_WAIT\n");
-                       r300_cmd_wait(dev_priv, header);
-                       break;
-
-               case R300_CMD_SCRATCH:
-                       DRM_DEBUG("R300_CMD_SCRATCH\n");
-                       ret = r300_scratch(dev_priv, cmdbuf, header);
-                       if (ret) {
-                               DRM_ERROR("r300_scratch failed\n");
-                               goto cleanup;
-                       }
-                       break;
-
-               case R300_CMD_R500FP:
-                       if ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV515) {
-                               DRM_ERROR("Calling r500 command on r300 card\n");
-                               ret = -EINVAL;
-                               goto cleanup;
-                       }
-                       DRM_DEBUG("R300_CMD_R500FP\n");
-                       ret = r300_emit_r500fp(dev_priv, cmdbuf, header);
-                       if (ret) {
-                               DRM_ERROR("r300_emit_r500fp failed\n");
-                               goto cleanup;
-                       }
-                       break;
-               default:
-                       DRM_ERROR("bad cmd_type %i at %p\n",
-                                 header.header.cmd_type,
-                                 cmdbuf->buf - sizeof(header));
-                       ret = -EINVAL;
-                       goto cleanup;
-               }
-       }
-
-       DRM_DEBUG("END\n");
-
-      cleanup:
-       r300_pacify(dev_priv);
-
-       /* We emit the vertex buffer age here, outside the pacifier "brackets"
-        * for two reasons:
-        *  (1) This may coalesce multiple age emissions into a single one and
-        *  (2) more importantly, some chips lock up hard when scratch registers
-        *      are written inside the pacifier bracket.
-        */
-       if (emit_dispatch_age) {
-               RING_LOCALS;
-
-               /* Emit the vertex buffer age */
-               BEGIN_RING(2);
-               RADEON_DISPATCH_AGE(dev_priv->sarea_priv->last_dispatch);
-               ADVANCE_RING();
-       }
-
-       COMMIT_RING();
-
-       return ret;
-}
diff --git a/drivers/char/drm/r300_reg.h b/drivers/char/drm/r300_reg.h
deleted file mode 100644 (file)
index a6802f2..0000000
+++ /dev/null
@@ -1,1772 +0,0 @@
-/**************************************************************************
-
-Copyright (C) 2004-2005 Nicolai Haehnle et al.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-on the rights to use, copy, modify, merge, publish, distribute, sub
-license, and/or sell copies of the Software, and to permit persons to whom
-the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice (including the next
-paragraph) shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
-THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
-DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _R300_REG_H
-#define _R300_REG_H
-
-#define R300_MC_INIT_MISC_LAT_TIMER    0x180
-#      define R300_MC_MISC__MC_CPR_INIT_LAT_SHIFT      0
-#      define R300_MC_MISC__MC_VF_INIT_LAT_SHIFT       4
-#      define R300_MC_MISC__MC_DISP0R_INIT_LAT_SHIFT   8
-#      define R300_MC_MISC__MC_DISP1R_INIT_LAT_SHIFT   12
-#      define R300_MC_MISC__MC_FIXED_INIT_LAT_SHIFT    16
-#      define R300_MC_MISC__MC_E2R_INIT_LAT_SHIFT      20
-#      define R300_MC_MISC__MC_SAME_PAGE_PRIO_SHIFT    24
-#      define R300_MC_MISC__MC_GLOBW_INIT_LAT_SHIFT    28
-
-#define R300_MC_INIT_GFX_LAT_TIMER     0x154
-#      define R300_MC_MISC__MC_G3D0R_INIT_LAT_SHIFT    0
-#      define R300_MC_MISC__MC_G3D1R_INIT_LAT_SHIFT    4
-#      define R300_MC_MISC__MC_G3D2R_INIT_LAT_SHIFT    8
-#      define R300_MC_MISC__MC_G3D3R_INIT_LAT_SHIFT    12
-#      define R300_MC_MISC__MC_TX0R_INIT_LAT_SHIFT     16
-#      define R300_MC_MISC__MC_TX1R_INIT_LAT_SHIFT     20
-#      define R300_MC_MISC__MC_GLOBR_INIT_LAT_SHIFT    24
-#      define R300_MC_MISC__MC_GLOBW_FULL_LAT_SHIFT    28
-
-/*
- * This file contains registers and constants for the R300. They have been
- * found mostly by examining command buffers captured using glxtest, as well
- * as by extrapolating some known registers and constants from the R200.
- * I am fairly certain that they are correct unless stated otherwise
- * in comments.
- */
-
-#define R300_SE_VPORT_XSCALE                0x1D98
-#define R300_SE_VPORT_XOFFSET               0x1D9C
-#define R300_SE_VPORT_YSCALE                0x1DA0
-#define R300_SE_VPORT_YOFFSET               0x1DA4
-#define R300_SE_VPORT_ZSCALE                0x1DA8
-#define R300_SE_VPORT_ZOFFSET               0x1DAC
-
-
-/*
- * Vertex Array Processing (VAP) Control
- * Stolen from r200 code from Christoph Brill (It's a guess!)
- */
-#define R300_VAP_CNTL  0x2080
-
-/* This register is written directly and also starts data section
- * in many 3d CP_PACKET3's
- */
-#define R300_VAP_VF_CNTL       0x2084
-#      define  R300_VAP_VF_CNTL__PRIM_TYPE__SHIFT              0
-#      define  R300_VAP_VF_CNTL__PRIM_NONE                     (0<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_POINTS                   (1<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_LINES                    (2<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_LINE_STRIP               (3<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLES                (4<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN             (5<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP           (6<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_LINE_LOOP                (12<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_QUADS                    (13<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_QUAD_STRIP               (14<<0)
-#      define  R300_VAP_VF_CNTL__PRIM_POLYGON                  (15<<0)
-
-#      define  R300_VAP_VF_CNTL__PRIM_WALK__SHIFT              4
-       /* State based - direct writes to registers trigger vertex
-           generation */
-#      define  R300_VAP_VF_CNTL__PRIM_WALK_STATE_BASED         (0<<4)
-#      define  R300_VAP_VF_CNTL__PRIM_WALK_INDICES             (1<<4)
-#      define  R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST         (2<<4)
-#      define  R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED     (3<<4)
-
-       /* I don't think I saw these three used.. */
-#      define  R300_VAP_VF_CNTL__COLOR_ORDER__SHIFT            6
-#      define  R300_VAP_VF_CNTL__TCL_OUTPUT_CTL_ENA__SHIFT     9
-#      define  R300_VAP_VF_CNTL__PROG_STREAM_ENA__SHIFT        10
-
-       /* index size - when not set the indices are assumed to be 16 bit */
-#      define  R300_VAP_VF_CNTL__INDEX_SIZE_32bit              (1<<11)
-       /* number of vertices */
-#      define  R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT           16
-
-/* BEGIN: Wild guesses */
-#define R300_VAP_OUTPUT_VTX_FMT_0           0x2090
-#       define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT     (1<<0)
-#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT   (1<<1)
-#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT (1<<2)  /* GUESS */
-#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT (1<<3)  /* GUESS */
-#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT (1<<4)  /* GUESS */
-#       define R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT (1<<16) /* GUESS */
-
-#define R300_VAP_OUTPUT_VTX_FMT_1           0x2094
-       /* each of the following is 3 bits wide, specifies number
-          of components */
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT 0
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT 3
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT 6
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT 9
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT 12
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT 15
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT 18
-#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT 21
-/* END: Wild guesses */
-
-#define R300_SE_VTE_CNTL                  0x20b0
-#      define     R300_VPORT_X_SCALE_ENA                0x00000001
-#      define     R300_VPORT_X_OFFSET_ENA               0x00000002
-#      define     R300_VPORT_Y_SCALE_ENA                0x00000004
-#      define     R300_VPORT_Y_OFFSET_ENA               0x00000008
-#      define     R300_VPORT_Z_SCALE_ENA                0x00000010
-#      define     R300_VPORT_Z_OFFSET_ENA               0x00000020
-#      define     R300_VTX_XY_FMT                       0x00000100
-#      define     R300_VTX_Z_FMT                        0x00000200
-#      define     R300_VTX_W0_FMT                       0x00000400
-#      define     R300_VTX_W0_NORMALIZE                 0x00000800
-#      define     R300_VTX_ST_DENORMALIZED              0x00001000
-
-/* BEGIN: Vertex data assembly - lots of uncertainties */
-
-/* gap */
-
-#define R300_VAP_CNTL_STATUS              0x2140
-#      define R300_VC_NO_SWAP                  (0 << 0)
-#      define R300_VC_16BIT_SWAP               (1 << 0)
-#      define R300_VC_32BIT_SWAP               (2 << 0)
-#      define R300_VAP_TCL_BYPASS              (1 << 8)
-
-/* gap */
-
-/* Where do we get our vertex data?
- *
- * Vertex data either comes either from immediate mode registers or from
- * vertex arrays.
- * There appears to be no mixed mode (though we can force the pitch of
- * vertex arrays to 0, effectively reusing the same element over and over
- * again).
- *
- * Immediate mode is controlled by the INPUT_CNTL registers. I am not sure
- * if these registers influence vertex array processing.
- *
- * Vertex arrays are controlled via the 3D_LOAD_VBPNTR packet3.
- *
- * In both cases, vertex attributes are then passed through INPUT_ROUTE.
- *
- * Beginning with INPUT_ROUTE_0_0 is a list of WORDs that route vertex data
- * into the vertex processor's input registers.
- * The first word routes the first input, the second word the second, etc.
- * The corresponding input is routed into the register with the given index.
- * The list is ended by a word with INPUT_ROUTE_END set.
- *
- * Always set COMPONENTS_4 in immediate mode.
- */
-
-#define R300_VAP_INPUT_ROUTE_0_0            0x2150
-#       define R300_INPUT_ROUTE_COMPONENTS_1     (0 << 0)
-#       define R300_INPUT_ROUTE_COMPONENTS_2     (1 << 0)
-#       define R300_INPUT_ROUTE_COMPONENTS_3     (2 << 0)
-#       define R300_INPUT_ROUTE_COMPONENTS_4     (3 << 0)
-#       define R300_INPUT_ROUTE_COMPONENTS_RGBA  (4 << 0) /* GUESS */
-#       define R300_VAP_INPUT_ROUTE_IDX_SHIFT    8
-#       define R300_VAP_INPUT_ROUTE_IDX_MASK     (31 << 8) /* GUESS */
-#       define R300_VAP_INPUT_ROUTE_END          (1 << 13)
-#       define R300_INPUT_ROUTE_IMMEDIATE_MODE   (0 << 14) /* GUESS */
-#       define R300_INPUT_ROUTE_FLOAT            (1 << 14) /* GUESS */
-#       define R300_INPUT_ROUTE_UNSIGNED_BYTE    (2 << 14) /* GUESS */
-#       define R300_INPUT_ROUTE_FLOAT_COLOR      (3 << 14) /* GUESS */
-#define R300_VAP_INPUT_ROUTE_0_1            0x2154
-#define R300_VAP_INPUT_ROUTE_0_2            0x2158
-#define R300_VAP_INPUT_ROUTE_0_3            0x215C
-#define R300_VAP_INPUT_ROUTE_0_4            0x2160
-#define R300_VAP_INPUT_ROUTE_0_5            0x2164
-#define R300_VAP_INPUT_ROUTE_0_6            0x2168
-#define R300_VAP_INPUT_ROUTE_0_7            0x216C
-
-/* gap */
-
-/* Notes:
- *  - always set up to produce at least two attributes:
- *    if vertex program uses only position, fglrx will set normal, too
- *  - INPUT_CNTL_0_COLOR and INPUT_CNTL_COLOR bits are always equal.
- */
-#define R300_VAP_INPUT_CNTL_0               0x2180
-#       define R300_INPUT_CNTL_0_COLOR           0x00000001
-#define R300_VAP_INPUT_CNTL_1               0x2184
-#       define R300_INPUT_CNTL_POS               0x00000001
-#       define R300_INPUT_CNTL_NORMAL            0x00000002
-#       define R300_INPUT_CNTL_COLOR             0x00000004
-#       define R300_INPUT_CNTL_TC0               0x00000400
-#       define R300_INPUT_CNTL_TC1               0x00000800
-#       define R300_INPUT_CNTL_TC2               0x00001000 /* GUESS */
-#       define R300_INPUT_CNTL_TC3               0x00002000 /* GUESS */
-#       define R300_INPUT_CNTL_TC4               0x00004000 /* GUESS */
-#       define R300_INPUT_CNTL_TC5               0x00008000 /* GUESS */
-#       define R300_INPUT_CNTL_TC6               0x00010000 /* GUESS */
-#       define R300_INPUT_CNTL_TC7               0x00020000 /* GUESS */
-
-/* gap */
-
-/* Words parallel to INPUT_ROUTE_0; All words that are active in INPUT_ROUTE_0
- * are set to a swizzling bit pattern, other words are 0.
- *
- * In immediate mode, the pattern is always set to xyzw. In vertex array
- * mode, the swizzling pattern is e.g. used to set zw components in texture
- * coordinates with only tweo components.
- */
-#define R300_VAP_INPUT_ROUTE_1_0            0x21E0
-#       define R300_INPUT_ROUTE_SELECT_X    0
-#       define R300_INPUT_ROUTE_SELECT_Y    1
-#       define R300_INPUT_ROUTE_SELECT_Z    2
-#       define R300_INPUT_ROUTE_SELECT_W    3
-#       define R300_INPUT_ROUTE_SELECT_ZERO 4
-#       define R300_INPUT_ROUTE_SELECT_ONE  5
-#       define R300_INPUT_ROUTE_SELECT_MASK 7
-#       define R300_INPUT_ROUTE_X_SHIFT     0
-#       define R300_INPUT_ROUTE_Y_SHIFT     3
-#       define R300_INPUT_ROUTE_Z_SHIFT     6
-#       define R300_INPUT_ROUTE_W_SHIFT     9
-#       define R300_INPUT_ROUTE_ENABLE      (15 << 12)
-#define R300_VAP_INPUT_ROUTE_1_1            0x21E4
-#define R300_VAP_INPUT_ROUTE_1_2            0x21E8
-#define R300_VAP_INPUT_ROUTE_1_3            0x21EC
-#define R300_VAP_INPUT_ROUTE_1_4            0x21F0
-#define R300_VAP_INPUT_ROUTE_1_5            0x21F4
-#define R300_VAP_INPUT_ROUTE_1_6            0x21F8
-#define R300_VAP_INPUT_ROUTE_1_7            0x21FC
-
-/* END: Vertex data assembly */
-
-/* gap */
-
-/* BEGIN: Upload vertex program and data */
-
-/*
- * The programmable vertex shader unit has a memory bank of unknown size
- * that can be written to in 16 byte units by writing the address into
- * UPLOAD_ADDRESS, followed by data in UPLOAD_DATA (multiples of 4 DWORDs).
- *
- * Pointers into the memory bank are always in multiples of 16 bytes.
- *
- * The memory bank is divided into areas with fixed meaning.
- *
- * Starting at address UPLOAD_PROGRAM: Vertex program instructions.
- * Native limits reported by drivers from ATI suggest size 256 (i.e. 4KB),
- * whereas the difference between known addresses suggests size 512.
- *
- * Starting at address UPLOAD_PARAMETERS: Vertex program parameters.
- * Native reported limits and the VPI layout suggest size 256, whereas
- * difference between known addresses suggests size 512.
- *
- * At address UPLOAD_POINTSIZE is a vector (0, 0, ps, 0), where ps is the
- * floating point pointsize. The exact purpose of this state is uncertain,
- * as there is also the R300_RE_POINTSIZE register.
- *
- * Multiple vertex programs and parameter sets can be loaded at once,
- * which could explain the size discrepancy.
- */
-#define R300_VAP_PVS_UPLOAD_ADDRESS         0x2200
-#       define R300_PVS_UPLOAD_PROGRAM           0x00000000
-#       define R300_PVS_UPLOAD_PARAMETERS        0x00000200
-#       define R300_PVS_UPLOAD_POINTSIZE         0x00000406
-
-/* gap */
-
-#define R300_VAP_PVS_UPLOAD_DATA            0x2208
-
-/* END: Upload vertex program and data */
-
-/* gap */
-
-/* I do not know the purpose of this register. However, I do know that
- * it is set to 221C_CLEAR for clear operations and to 221C_NORMAL
- * for normal rendering.
- */
-#define R300_VAP_UNKNOWN_221C               0x221C
-#       define R300_221C_NORMAL                  0x00000000
-#       define R300_221C_CLEAR                   0x0001C000
-
-/* These seem to be per-pixel and per-vertex X and Y clipping planes. The first
- * plane is per-pixel and the second plane is per-vertex.
- *
- * This was determined by experimentation alone but I believe it is correct.
- *
- * These registers are called X_QUAD0_1_FL to X_QUAD0_4_FL by glxtest.
- */
-#define R300_VAP_CLIP_X_0                   0x2220
-#define R300_VAP_CLIP_X_1                   0x2224
-#define R300_VAP_CLIP_Y_0                   0x2228
-#define R300_VAP_CLIP_Y_1                   0x2230
-
-/* gap */
-
-/* Sometimes, END_OF_PKT and 0x2284=0 are the only commands sent between
- * rendering commands and overwriting vertex program parameters.
- * Therefore, I suspect writing zero to 0x2284 synchronizes the engine and
- * avoids bugs caused by still running shaders reading bad data from memory.
- */
-#define R300_VAP_PVS_WAITIDLE               0x2284 /* GUESS */
-
-/* Absolutely no clue what this register is about. */
-#define R300_VAP_UNKNOWN_2288               0x2288
-#       define R300_2288_R300                    0x00750000 /* -- nh */
-#       define R300_2288_RV350                   0x0000FFFF /* -- Vladimir */
-
-/* gap */
-
-/* Addresses are relative to the vertex program instruction area of the
- * memory bank. PROGRAM_END points to the last instruction of the active
- * program
- *
- * The meaning of the two UNKNOWN fields is obviously not known. However,
- * experiments so far have shown that both *must* point to an instruction
- * inside the vertex program, otherwise the GPU locks up.
- *
- * fglrx usually sets CNTL_3_UNKNOWN to the end of the program and
- * R300_PVS_CNTL_1_POS_END_SHIFT points to instruction where last write to
- * position takes place.
- *
- * Most likely this is used to ignore rest of the program in cases
- * where group of verts arent visible. For some reason this "section"
- * is sometimes accepted other instruction that have no relationship with
- * position calculations.
- */
-#define R300_VAP_PVS_CNTL_1                 0x22D0
-#       define R300_PVS_CNTL_1_PROGRAM_START_SHIFT   0
-#       define R300_PVS_CNTL_1_POS_END_SHIFT         10
-#       define R300_PVS_CNTL_1_PROGRAM_END_SHIFT     20
-/* Addresses are relative the the vertex program parameters area. */
-#define R300_VAP_PVS_CNTL_2                 0x22D4
-#       define R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT 0
-#       define R300_PVS_CNTL_2_PARAM_COUNT_SHIFT  16
-#define R300_VAP_PVS_CNTL_3               0x22D8
-#       define R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT 10
-#       define R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT 0
-
-/* The entire range from 0x2300 to 0x2AC inclusive seems to be used for
- * immediate vertices
- */
-#define R300_VAP_VTX_COLOR_R                0x2464
-#define R300_VAP_VTX_COLOR_G                0x2468
-#define R300_VAP_VTX_COLOR_B                0x246C
-#define R300_VAP_VTX_POS_0_X_1              0x2490 /* used for glVertex2*() */
-#define R300_VAP_VTX_POS_0_Y_1              0x2494
-#define R300_VAP_VTX_COLOR_PKD              0x249C /* RGBA */
-#define R300_VAP_VTX_POS_0_X_2              0x24A0 /* used for glVertex3*() */
-#define R300_VAP_VTX_POS_0_Y_2              0x24A4
-#define R300_VAP_VTX_POS_0_Z_2              0x24A8
-/* write 0 to indicate end of packet? */
-#define R300_VAP_VTX_END_OF_PKT             0x24AC
-
-/* gap */
-
-/* These are values from r300_reg/r300_reg.h - they are known to be correct
- * and are here so we can use one register file instead of several
- * - Vladimir
- */
-#define R300_GB_VAP_RASTER_VTX_FMT_0   0x4000
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__POS_PRESENT        (1<<0)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_0_PRESENT    (1<<1)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_1_PRESENT    (1<<2)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_2_PRESENT    (1<<3)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_3_PRESENT    (1<<4)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_SPACE        (0xf<<5)
-#      define R300_GB_VAP_RASTER_VTX_FMT_0__PT_SIZE_PRESENT    (0x1<<16)
-
-#define R300_GB_VAP_RASTER_VTX_FMT_1   0x4004
-       /* each of the following is 3 bits wide, specifies number
-          of components */
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT       0
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT       3
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT       6
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT       9
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT       12
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT       15
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT       18
-#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT       21
-
-/* UNK30 seems to enables point to quad transformation on textures
- * (or something closely related to that).
- * This bit is rather fatal at the time being due to lackings at pixel
- * shader side
- */
-#define R300_GB_ENABLE 0x4008
-#      define R300_GB_POINT_STUFF_ENABLE       (1<<0)
-#      define R300_GB_LINE_STUFF_ENABLE        (1<<1)
-#      define R300_GB_TRIANGLE_STUFF_ENABLE    (1<<2)
-#      define R300_GB_STENCIL_AUTO_ENABLE      (1<<4)
-#      define R300_GB_UNK31                    (1<<31)
-       /* each of the following is 2 bits wide */
-#define R300_GB_TEX_REPLICATE  0
-#define R300_GB_TEX_ST         1
-#define R300_GB_TEX_STR                2
-#      define R300_GB_TEX0_SOURCE_SHIFT        16
-#      define R300_GB_TEX1_SOURCE_SHIFT        18
-#      define R300_GB_TEX2_SOURCE_SHIFT        20
-#      define R300_GB_TEX3_SOURCE_SHIFT        22
-#      define R300_GB_TEX4_SOURCE_SHIFT        24
-#      define R300_GB_TEX5_SOURCE_SHIFT        26
-#      define R300_GB_TEX6_SOURCE_SHIFT        28
-#      define R300_GB_TEX7_SOURCE_SHIFT        30
-
-/* MSPOS - positions for multisample antialiasing (?) */
-#define R300_GB_MSPOS0 0x4010
-       /* shifts - each of the fields is 4 bits */
-#      define R300_GB_MSPOS0__MS_X0_SHIFT      0
-#      define R300_GB_MSPOS0__MS_Y0_SHIFT      4
-#      define R300_GB_MSPOS0__MS_X1_SHIFT      8
-#      define R300_GB_MSPOS0__MS_Y1_SHIFT      12
-#      define R300_GB_MSPOS0__MS_X2_SHIFT      16
-#      define R300_GB_MSPOS0__MS_Y2_SHIFT      20
-#      define R300_GB_MSPOS0__MSBD0_Y          24
-#      define R300_GB_MSPOS0__MSBD0_X          28
-
-#define R300_GB_MSPOS1 0x4014
-#      define R300_GB_MSPOS1__MS_X3_SHIFT      0
-#      define R300_GB_MSPOS1__MS_Y3_SHIFT      4
-#      define R300_GB_MSPOS1__MS_X4_SHIFT      8
-#      define R300_GB_MSPOS1__MS_Y4_SHIFT      12
-#      define R300_GB_MSPOS1__MS_X5_SHIFT      16
-#      define R300_GB_MSPOS1__MS_Y5_SHIFT      20
-#      define R300_GB_MSPOS1__MSBD1            24
-
-
-#define R300_GB_TILE_CONFIG    0x4018
-#      define R300_GB_TILE_ENABLE      (1<<0)
-#      define R300_GB_TILE_PIPE_COUNT_RV300    0
-#      define R300_GB_TILE_PIPE_COUNT_R300     (3<<1)
-#      define R300_GB_TILE_PIPE_COUNT_R420     (7<<1)
-#      define R300_GB_TILE_PIPE_COUNT_RV410    (3<<1)
-#      define R300_GB_TILE_SIZE_8              0
-#      define R300_GB_TILE_SIZE_16             (1<<4)
-#      define R300_GB_TILE_SIZE_32             (2<<4)
-#      define R300_GB_SUPER_SIZE_1             (0<<6)
-#      define R300_GB_SUPER_SIZE_2             (1<<6)
-#      define R300_GB_SUPER_SIZE_4             (2<<6)
-#      define R300_GB_SUPER_SIZE_8             (3<<6)
-#      define R300_GB_SUPER_SIZE_16            (4<<6)
-#      define R300_GB_SUPER_SIZE_32            (5<<6)
-#      define R300_GB_SUPER_SIZE_64            (6<<6)
-#      define R300_GB_SUPER_SIZE_128           (7<<6)
-#      define R300_GB_SUPER_X_SHIFT            9       /* 3 bits wide */
-#      define R300_GB_SUPER_Y_SHIFT            12      /* 3 bits wide */
-#      define R300_GB_SUPER_TILE_A             0
-#      define R300_GB_SUPER_TILE_B             (1<<15)
-#      define R300_GB_SUBPIXEL_1_12            0
-#      define R300_GB_SUBPIXEL_1_16            (1<<16)
-
-#define R300_GB_FIFO_SIZE      0x4024
-       /* each of the following is 2 bits wide */
-#define R300_GB_FIFO_SIZE_32   0
-#define R300_GB_FIFO_SIZE_64   1
-#define R300_GB_FIFO_SIZE_128  2
-#define R300_GB_FIFO_SIZE_256  3
-#      define R300_SC_IFIFO_SIZE_SHIFT 0
-#      define R300_SC_TZFIFO_SIZE_SHIFT        2
-#      define R300_SC_BFIFO_SIZE_SHIFT 4
-
-#      define R300_US_OFIFO_SIZE_SHIFT 12
-#      define R300_US_WFIFO_SIZE_SHIFT 14
-       /* the following use the same constants as above, but meaning is
-          is times 2 (i.e. instead of 32 words it means 64 */
-#      define R300_RS_TFIFO_SIZE_SHIFT 6
-#      define R300_RS_CFIFO_SIZE_SHIFT 8
-#      define R300_US_RAM_SIZE_SHIFT           10
-       /* watermarks, 3 bits wide */
-#      define R300_RS_HIGHWATER_COL_SHIFT      16
-#      define R300_RS_HIGHWATER_TEX_SHIFT      19
-#      define R300_OFIFO_HIGHWATER_SHIFT       22      /* two bits only */
-#      define R300_CUBE_FIFO_HIGHWATER_COL_SHIFT       24
-
-#define R300_GB_SELECT 0x401C
-#      define R300_GB_FOG_SELECT_C0A           0
-#      define R300_GB_FOG_SELECT_C1A           1
-#      define R300_GB_FOG_SELECT_C2A           2
-#      define R300_GB_FOG_SELECT_C3A           3
-#      define R300_GB_FOG_SELECT_1_1_W 4
-#      define R300_GB_FOG_SELECT_Z             5
-#      define R300_GB_DEPTH_SELECT_Z           0
-#      define R300_GB_DEPTH_SELECT_1_1_W       (1<<3)
-#      define R300_GB_W_SELECT_1_W             0
-#      define R300_GB_W_SELECT_1               (1<<4)
-
-#define R300_GB_AA_CONFIG              0x4020
-#      define R300_AA_DISABLE                  0x00
-#      define R300_AA_ENABLE                   0x01
-#      define R300_AA_SUBSAMPLES_2             0
-#      define R300_AA_SUBSAMPLES_3             (1<<1)
-#      define R300_AA_SUBSAMPLES_4             (2<<1)
-#      define R300_AA_SUBSAMPLES_6             (3<<1)
-
-/* gap */
-
-/* Zero to flush caches. */
-#define R300_TX_CNTL                        0x4100
-#define R300_TX_FLUSH                       0x0
-
-/* The upper enable bits are guessed, based on fglrx reported limits. */
-#define R300_TX_ENABLE                      0x4104
-#       define R300_TX_ENABLE_0                  (1 << 0)
-#       define R300_TX_ENABLE_1                  (1 << 1)
-#       define R300_TX_ENABLE_2                  (1 << 2)
-#       define R300_TX_ENABLE_3                  (1 << 3)
-#       define R300_TX_ENABLE_4                  (1 << 4)
-#       define R300_TX_ENABLE_5                  (1 << 5)
-#       define R300_TX_ENABLE_6                  (1 << 6)
-#       define R300_TX_ENABLE_7                  (1 << 7)
-#       define R300_TX_ENABLE_8                  (1 << 8)
-#       define R300_TX_ENABLE_9                  (1 << 9)
-#       define R300_TX_ENABLE_10                 (1 << 10)
-#       define R300_TX_ENABLE_11                 (1 << 11)
-#       define R300_TX_ENABLE_12                 (1 << 12)
-#       define R300_TX_ENABLE_13                 (1 << 13)
-#       define R300_TX_ENABLE_14                 (1 << 14)
-#       define R300_TX_ENABLE_15                 (1 << 15)
-
-/* The pointsize is given in multiples of 6. The pointsize can be
- * enormous: Clear() renders a single point that fills the entire
- * framebuffer.
- */
-#define R300_RE_POINTSIZE                   0x421C
-#       define R300_POINTSIZE_Y_SHIFT            0
-#       define R300_POINTSIZE_Y_MASK             (0xFFFF << 0) /* GUESS */
-#       define R300_POINTSIZE_X_SHIFT            16
-#       define R300_POINTSIZE_X_MASK             (0xFFFF << 16) /* GUESS */
-#       define R300_POINTSIZE_MAX             (R300_POINTSIZE_Y_MASK / 6)
-
-/* The line width is given in multiples of 6.
- * In default mode lines are classified as vertical lines.
- * HO: horizontal
- * VE: vertical or horizontal
- * HO & VE: no classification
- */
-#define R300_RE_LINE_CNT                      0x4234
-#       define R300_LINESIZE_SHIFT            0
-#       define R300_LINESIZE_MASK             (0xFFFF << 0) /* GUESS */
-#       define R300_LINESIZE_MAX             (R300_LINESIZE_MASK / 6)
-#       define R300_LINE_CNT_HO               (1 << 16)
-#       define R300_LINE_CNT_VE               (1 << 17)
-
-/* Some sort of scale or clamp value for texcoordless textures. */
-#define R300_RE_UNK4238                       0x4238
-
-/* Something shade related */
-#define R300_RE_SHADE                         0x4274
-
-#define R300_RE_SHADE_MODEL                   0x4278
-#      define R300_RE_SHADE_MODEL_SMOOTH     0x3aaaa
-#      define R300_RE_SHADE_MODEL_FLAT       0x39595
-
-/* Dangerous */
-#define R300_RE_POLYGON_MODE                  0x4288
-#      define R300_PM_ENABLED                (1 << 0)
-#      define R300_PM_FRONT_POINT            (0 << 0)
-#      define R300_PM_BACK_POINT             (0 << 0)
-#      define R300_PM_FRONT_LINE             (1 << 4)
-#      define R300_PM_FRONT_FILL             (1 << 5)
-#      define R300_PM_BACK_LINE              (1 << 7)
-#      define R300_PM_BACK_FILL              (1 << 8)
-
-/* Fog parameters */
-#define R300_RE_FOG_SCALE                     0x4294
-#define R300_RE_FOG_START                     0x4298
-
-/* Not sure why there are duplicate of factor and constant values.
- * My best guess so far is that there are separate zbiases for test and write.
- * Ordering might be wrong.
- * Some of the tests indicate that fgl has a fallback implementation of zbias
- * via pixel shaders.
- */
-#define R300_RE_ZBIAS_CNTL                    0x42A0 /* GUESS */
-#define R300_RE_ZBIAS_T_FACTOR                0x42A4
-#define R300_RE_ZBIAS_T_CONSTANT              0x42A8
-#define R300_RE_ZBIAS_W_FACTOR                0x42AC
-#define R300_RE_ZBIAS_W_CONSTANT              0x42B0
-
-/* This register needs to be set to (1<<1) for RV350 to correctly
- * perform depth test (see --vb-triangles in r300_demo)
- * Don't know about other chips. - Vladimir
- * This is set to 3 when GL_POLYGON_OFFSET_FILL is on.
- * My guess is that there are two bits for each zbias primitive
- * (FILL, LINE, POINT).
- *  One to enable depth test and one for depth write.
- * Yet this doesnt explain why depth writes work ...
- */
-#define R300_RE_OCCLUSION_CNTL             0x42B4
-#      define R300_OCCLUSION_ON                (1<<1)
-
-#define R300_RE_CULL_CNTL                   0x42B8
-#       define R300_CULL_FRONT                   (1 << 0)
-#       define R300_CULL_BACK                    (1 << 1)
-#       define R300_FRONT_FACE_CCW               (0 << 2)
-#       define R300_FRONT_FACE_CW                (1 << 2)
-
-
-/* BEGIN: Rasterization / Interpolators - many guesses */
-
-/* 0_UNKNOWN_18 has always been set except for clear operations.
- * TC_CNT is the number of incoming texture coordinate sets (i.e. it depends
- * on the vertex program, *not* the fragment program)
- */
-#define R300_RS_CNTL_0                      0x4300
-#       define R300_RS_CNTL_TC_CNT_SHIFT         2
-#       define R300_RS_CNTL_TC_CNT_MASK          (7 << 2)
-       /* number of color interpolators used */
-#      define R300_RS_CNTL_CI_CNT_SHIFT         7
-#       define R300_RS_CNTL_0_UNKNOWN_18         (1 << 18)
-       /* Guess: RS_CNTL_1 holds the index of the highest used RS_ROUTE_n
-          register. */
-#define R300_RS_CNTL_1                      0x4304
-
-/* gap */
-
-/* Only used for texture coordinates.
- * Use the source field to route texture coordinate input from the
- * vertex program to the desired interpolator. Note that the source
- * field is relative to the outputs the vertex program *actually*
- * writes. If a vertex program only writes texcoord[1], this will
- * be source index 0.
- * Set INTERP_USED on all interpolators that produce data used by
- * the fragment program. INTERP_USED looks like a swizzling mask,
- * but I haven't seen it used that way.
- *
- * Note: The _UNKNOWN constants are always set in their respective
- * register. I don't know if this is necessary.
- */
-#define R300_RS_INTERP_0                    0x4310
-#define R300_RS_INTERP_1                    0x4314
-#       define R300_RS_INTERP_1_UNKNOWN          0x40
-#define R300_RS_INTERP_2                    0x4318
-#       define R300_RS_INTERP_2_UNKNOWN          0x80
-#define R300_RS_INTERP_3                    0x431C
-#       define R300_RS_INTERP_3_UNKNOWN          0xC0
-#define R300_RS_INTERP_4                    0x4320
-#define R300_RS_INTERP_5                    0x4324
-#define R300_RS_INTERP_6                    0x4328
-#define R300_RS_INTERP_7                    0x432C
-#       define R300_RS_INTERP_SRC_SHIFT          2
-#       define R300_RS_INTERP_SRC_MASK           (7 << 2)
-#       define R300_RS_INTERP_USED               0x00D10000
-
-/* These DWORDs control how vertex data is routed into fragment program
- * registers, after interpolators.
- */
-#define R300_RS_ROUTE_0                     0x4330
-#define R300_RS_ROUTE_1                     0x4334
-#define R300_RS_ROUTE_2                     0x4338
-#define R300_RS_ROUTE_3                     0x433C /* GUESS */
-#define R300_RS_ROUTE_4                     0x4340 /* GUESS */
-#define R300_RS_ROUTE_5                     0x4344 /* GUESS */
-#define R300_RS_ROUTE_6                     0x4348 /* GUESS */
-#define R300_RS_ROUTE_7                     0x434C /* GUESS */
-#       define R300_RS_ROUTE_SOURCE_INTERP_0     0
-#       define R300_RS_ROUTE_SOURCE_INTERP_1     1
-#       define R300_RS_ROUTE_SOURCE_INTERP_2     2
-#       define R300_RS_ROUTE_SOURCE_INTERP_3     3
-#       define R300_RS_ROUTE_SOURCE_INTERP_4     4
-#       define R300_RS_ROUTE_SOURCE_INTERP_5     5 /* GUESS */
-#       define R300_RS_ROUTE_SOURCE_INTERP_6     6 /* GUESS */
-#       define R300_RS_ROUTE_SOURCE_INTERP_7     7 /* GUESS */
-#       define R300_RS_ROUTE_ENABLE              (1 << 3) /* GUESS */
-#       define R300_RS_ROUTE_DEST_SHIFT          6
-#       define R300_RS_ROUTE_DEST_MASK           (31 << 6) /* GUESS */
-
-/* Special handling for color: When the fragment program uses color,
- * the ROUTE_0_COLOR bit is set and ROUTE_0_COLOR_DEST contains the
- * color register index.
- *
- * Apperently you may set the R300_RS_ROUTE_0_COLOR bit, but not provide any
- * R300_RS_ROUTE_0_COLOR_DEST value; this setup is used for clearing the state.
- * See r300_ioctl.c:r300EmitClearState. I'm not sure if this setup is strictly
- * correct or not. - Oliver.
- */
-#       define R300_RS_ROUTE_0_COLOR             (1 << 14)
-#       define R300_RS_ROUTE_0_COLOR_DEST_SHIFT  17
-#       define R300_RS_ROUTE_0_COLOR_DEST_MASK   (31 << 17) /* GUESS */
-/* As above, but for secondary color */
-#              define R300_RS_ROUTE_1_COLOR1            (1 << 14)
-#              define R300_RS_ROUTE_1_COLOR1_DEST_SHIFT 17
-#              define R300_RS_ROUTE_1_COLOR1_DEST_MASK  (31 << 17)
-#              define R300_RS_ROUTE_1_UNKNOWN11         (1 << 11)
-/* END: Rasterization / Interpolators - many guesses */
-
-/* Hierarchical Z Enable */
-#define R300_SC_HYPERZ                   0x43a4
-#      define R300_SC_HYPERZ_DISABLE     (0 << 0)
-#      define R300_SC_HYPERZ_ENABLE      (1 << 0)
-#      define R300_SC_HYPERZ_MIN         (0 << 1)
-#      define R300_SC_HYPERZ_MAX         (1 << 1)
-#      define R300_SC_HYPERZ_ADJ_256     (0 << 2)
-#      define R300_SC_HYPERZ_ADJ_128     (1 << 2)
-#      define R300_SC_HYPERZ_ADJ_64      (2 << 2)
-#      define R300_SC_HYPERZ_ADJ_32      (3 << 2)
-#      define R300_SC_HYPERZ_ADJ_16      (4 << 2)
-#      define R300_SC_HYPERZ_ADJ_8       (5 << 2)
-#      define R300_SC_HYPERZ_ADJ_4       (6 << 2)
-#      define R300_SC_HYPERZ_ADJ_2       (7 << 2)
-#      define R300_SC_HYPERZ_HZ_Z0MIN_NO (0 << 5)
-#      define R300_SC_HYPERZ_HZ_Z0MIN    (1 << 5)
-#      define R300_SC_HYPERZ_HZ_Z0MAX_NO (0 << 6)
-#      define R300_SC_HYPERZ_HZ_Z0MAX    (1 << 6)
-
-#define R300_SC_EDGERULE                 0x43a8
-
-/* BEGIN: Scissors and cliprects */
-
-/* There are four clipping rectangles. Their corner coordinates are inclusive.
- * Every pixel is assigned a number from 0 and 15 by setting bits 0-3 depending
- * on whether the pixel is inside cliprects 0-3, respectively. For example,
- * if a pixel is inside cliprects 0 and 1, but outside 2 and 3, it is assigned
- * the number 3 (binary 0011).
- * Iff the bit corresponding to the pixel's number in RE_CLIPRECT_CNTL is set,
- * the pixel is rasterized.
- *
- * In addition to this, there is a scissors rectangle. Only pixels inside the
- * scissors rectangle are drawn. (coordinates are inclusive)
- *
- * For some reason, the top-left corner of the framebuffer is at (1440, 1440)
- * for the purpose of clipping and scissors.
- */
-#define R300_RE_CLIPRECT_TL_0               0x43B0
-#define R300_RE_CLIPRECT_BR_0               0x43B4
-#define R300_RE_CLIPRECT_TL_1               0x43B8
-#define R300_RE_CLIPRECT_BR_1               0x43BC
-#define R300_RE_CLIPRECT_TL_2               0x43C0
-#define R300_RE_CLIPRECT_BR_2               0x43C4
-#define R300_RE_CLIPRECT_TL_3               0x43C8
-#define R300_RE_CLIPRECT_BR_3               0x43CC
-#       define R300_CLIPRECT_OFFSET              1440
-#       define R300_CLIPRECT_MASK                0x1FFF
-#       define R300_CLIPRECT_X_SHIFT             0
-#       define R300_CLIPRECT_X_MASK              (0x1FFF << 0)
-#       define R300_CLIPRECT_Y_SHIFT             13
-#       define R300_CLIPRECT_Y_MASK              (0x1FFF << 13)
-#define R300_RE_CLIPRECT_CNTL               0x43D0
-#       define R300_CLIP_OUT                     (1 << 0)
-#       define R300_CLIP_0                       (1 << 1)
-#       define R300_CLIP_1                       (1 << 2)
-#       define R300_CLIP_10                      (1 << 3)
-#       define R300_CLIP_2                       (1 << 4)
-#       define R300_CLIP_20                      (1 << 5)
-#       define R300_CLIP_21                      (1 << 6)
-#       define R300_CLIP_210                     (1 << 7)
-#       define R300_CLIP_3                       (1 << 8)
-#       define R300_CLIP_30                      (1 << 9)
-#       define R300_CLIP_31                      (1 << 10)
-#       define R300_CLIP_310                     (1 << 11)
-#       define R300_CLIP_32                      (1 << 12)
-#       define R300_CLIP_320                     (1 << 13)
-#       define R300_CLIP_321                     (1 << 14)
-#       define R300_CLIP_3210                    (1 << 15)
-
-/* gap */
-
-#define R300_RE_SCISSORS_TL                 0x43E0
-#define R300_RE_SCISSORS_BR                 0x43E4
-#       define R300_SCISSORS_OFFSET              1440
-#       define R300_SCISSORS_X_SHIFT             0
-#       define R300_SCISSORS_X_MASK              (0x1FFF << 0)
-#       define R300_SCISSORS_Y_SHIFT             13
-#       define R300_SCISSORS_Y_MASK              (0x1FFF << 13)
-/* END: Scissors and cliprects */
-
-/* BEGIN: Texture specification */
-
-/*
- * The texture specification dwords are grouped by meaning and not by texture
- * unit. This means that e.g. the offset for texture image unit N is found in
- * register TX_OFFSET_0 + (4*N)
- */
-#define R300_TX_FILTER_0                    0x4400
-#       define R300_TX_REPEAT                    0
-#       define R300_TX_MIRRORED                  1
-#       define R300_TX_CLAMP                     4
-#       define R300_TX_CLAMP_TO_EDGE             2
-#       define R300_TX_CLAMP_TO_BORDER           6
-#       define R300_TX_WRAP_S_SHIFT              0
-#       define R300_TX_WRAP_S_MASK               (7 << 0)
-#       define R300_TX_WRAP_T_SHIFT              3
-#       define R300_TX_WRAP_T_MASK               (7 << 3)
-#       define R300_TX_WRAP_Q_SHIFT              6
-#       define R300_TX_WRAP_Q_MASK               (7 << 6)
-#       define R300_TX_MAG_FILTER_NEAREST        (1 << 9)
-#       define R300_TX_MAG_FILTER_LINEAR         (2 << 9)
-#       define R300_TX_MAG_FILTER_MASK           (3 << 9)
-#       define R300_TX_MIN_FILTER_NEAREST        (1 << 11)
-#       define R300_TX_MIN_FILTER_LINEAR         (2 << 11)
-#      define R300_TX_MIN_FILTER_NEAREST_MIP_NEAREST       (5  <<  11)
-#      define R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR        (9  <<  11)
-#      define R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST        (6  <<  11)
-#      define R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR         (10 <<  11)
-
-/* NOTE: NEAREST doesnt seem to exist.
- * Im not seting MAG_FILTER_MASK and (3 << 11) on for all
- * anisotropy modes because that would void selected mag filter
- */
-#      define R300_TX_MIN_FILTER_ANISO_NEAREST             (0 << 13)
-#      define R300_TX_MIN_FILTER_ANISO_LINEAR              (0 << 13)
-#      define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST (1 << 13)
-#      define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR  (2 << 13)
-#       define R300_TX_MIN_FILTER_MASK   ( (15 << 11) | (3 << 13) )
-#      define R300_TX_MAX_ANISO_1_TO_1  (0 << 21)
-#      define R300_TX_MAX_ANISO_2_TO_1  (2 << 21)
-#      define R300_TX_MAX_ANISO_4_TO_1  (4 << 21)
-#      define R300_TX_MAX_ANISO_8_TO_1  (6 << 21)
-#      define R300_TX_MAX_ANISO_16_TO_1 (8 << 21)
-#      define R300_TX_MAX_ANISO_MASK    (14 << 21)
-
-#define R300_TX_FILTER1_0                      0x4440
-#      define R300_CHROMA_KEY_MODE_DISABLE    0
-#      define R300_CHROMA_KEY_FORCE           1
-#      define R300_CHROMA_KEY_BLEND           2
-#      define R300_MC_ROUND_NORMAL            (0<<2)
-#      define R300_MC_ROUND_MPEG4             (1<<2)
-#      define R300_LOD_BIAS_MASK           0x1fff
-#      define R300_EDGE_ANISO_EDGE_DIAG       (0<<13)
-#      define R300_EDGE_ANISO_EDGE_ONLY       (1<<13)
-#      define R300_MC_COORD_TRUNCATE_DISABLE  (0<<14)
-#      define R300_MC_COORD_TRUNCATE_MPEG     (1<<14)
-#      define R300_TX_TRI_PERF_0_8            (0<<15)
-#      define R300_TX_TRI_PERF_1_8            (1<<15)
-#      define R300_TX_TRI_PERF_1_4            (2<<15)
-#      define R300_TX_TRI_PERF_3_8            (3<<15)
-#      define R300_ANISO_THRESHOLD_MASK       (7<<17)
-
-#define R300_TX_SIZE_0                      0x4480
-#       define R300_TX_WIDTHMASK_SHIFT           0
-#       define R300_TX_WIDTHMASK_MASK            (2047 << 0)
-#       define R300_TX_HEIGHTMASK_SHIFT          11
-#       define R300_TX_HEIGHTMASK_MASK           (2047 << 11)
-#       define R300_TX_UNK23                     (1 << 23)
-#       define R300_TX_MAX_MIP_LEVEL_SHIFT       26
-#       define R300_TX_MAX_MIP_LEVEL_MASK        (0xf << 26)
-#       define R300_TX_SIZE_PROJECTED            (1<<30)
-#       define R300_TX_SIZE_TXPITCH_EN           (1<<31)
-#define R300_TX_FORMAT_0                    0x44C0
-       /* The interpretation of the format word by Wladimir van der Laan */
-       /* The X, Y, Z and W refer to the layout of the components.
-          They are given meanings as R, G, B and Alpha by the swizzle
-          specification */
-#      define R300_TX_FORMAT_X8                    0x0
-#      define R300_TX_FORMAT_X16                   0x1
-#      define R300_TX_FORMAT_Y4X4                  0x2
-#      define R300_TX_FORMAT_Y8X8                  0x3
-#      define R300_TX_FORMAT_Y16X16                0x4
-#      define R300_TX_FORMAT_Z3Y3X2                0x5
-#      define R300_TX_FORMAT_Z5Y6X5                0x6
-#      define R300_TX_FORMAT_Z6Y5X5                0x7
-#      define R300_TX_FORMAT_Z11Y11X10             0x8
-#      define R300_TX_FORMAT_Z10Y11X11             0x9
-#      define R300_TX_FORMAT_W4Z4Y4X4              0xA
-#      define R300_TX_FORMAT_W1Z5Y5X5              0xB
-#      define R300_TX_FORMAT_W8Z8Y8X8              0xC
-#      define R300_TX_FORMAT_W2Z10Y10X10           0xD
-#      define R300_TX_FORMAT_W16Z16Y16X16          0xE
-#      define R300_TX_FORMAT_DXT1                  0xF
-#      define R300_TX_FORMAT_DXT3                  0x10
-#      define R300_TX_FORMAT_DXT5                  0x11
-#      define R300_TX_FORMAT_D3DMFT_CxV8U8         0x12     /* no swizzle */
-#      define R300_TX_FORMAT_A8R8G8B8              0x13     /* no swizzle */
-#      define R300_TX_FORMAT_B8G8_B8G8             0x14     /* no swizzle */
-#      define R300_TX_FORMAT_G8R8_G8B8             0x15     /* no swizzle */
-       /* 0x16 - some 16 bit green format.. ?? */
-#      define R300_TX_FORMAT_UNK25                (1 << 25) /* no swizzle */
-#      define R300_TX_FORMAT_CUBIC_MAP            (1 << 26)
-
-       /* gap */
-       /* Floating point formats */
-       /* Note - hardware supports both 16 and 32 bit floating point */
-#      define R300_TX_FORMAT_FL_I16                0x18
-#      define R300_TX_FORMAT_FL_I16A16             0x19
-#      define R300_TX_FORMAT_FL_R16G16B16A16       0x1A
-#      define R300_TX_FORMAT_FL_I32                0x1B
-#      define R300_TX_FORMAT_FL_I32A32             0x1C
-#      define R300_TX_FORMAT_FL_R32G32B32A32       0x1D
-       /* alpha modes, convenience mostly */
-       /* if you have alpha, pick constant appropriate to the
-          number of channels (1 for I8, 2 for I8A8, 4 for R8G8B8A8, etc */
-#      define R300_TX_FORMAT_ALPHA_1CH             0x000
-#      define R300_TX_FORMAT_ALPHA_2CH             0x200
-#      define R300_TX_FORMAT_ALPHA_4CH             0x600
-#      define R300_TX_FORMAT_ALPHA_NONE            0xA00
-       /* Swizzling */
-       /* constants */
-#      define R300_TX_FORMAT_X         0
-#      define R300_TX_FORMAT_Y         1
-#      define R300_TX_FORMAT_Z         2
-#      define R300_TX_FORMAT_W         3
-#      define R300_TX_FORMAT_ZERO      4
-#      define R300_TX_FORMAT_ONE       5
-       /* 2.0*Z, everything above 1.0 is set to 0.0 */
-#      define R300_TX_FORMAT_CUT_Z     6
-       /* 2.0*W, everything above 1.0 is set to 0.0 */
-#      define R300_TX_FORMAT_CUT_W     7
-
-#      define R300_TX_FORMAT_B_SHIFT   18
-#      define R300_TX_FORMAT_G_SHIFT   15
-#      define R300_TX_FORMAT_R_SHIFT   12
-#      define R300_TX_FORMAT_A_SHIFT   9
-       /* Convenience macro to take care of layout and swizzling */
-#      define R300_EASY_TX_FORMAT(B, G, R, A, FMT)     (               \
-               ((R300_TX_FORMAT_##B)<<R300_TX_FORMAT_B_SHIFT)          \
-               | ((R300_TX_FORMAT_##G)<<R300_TX_FORMAT_G_SHIFT)        \
-               | ((R300_TX_FORMAT_##R)<<R300_TX_FORMAT_R_SHIFT)        \
-               | ((R300_TX_FORMAT_##A)<<R300_TX_FORMAT_A_SHIFT)        \
-               | (R300_TX_FORMAT_##FMT)                                \
-               )
-       /* These can be ORed with result of R300_EASY_TX_FORMAT()
-          We don't really know what they do. Take values from a
-           constant color ? */
-#      define R300_TX_FORMAT_CONST_X           (1<<5)
-#      define R300_TX_FORMAT_CONST_Y           (2<<5)
-#      define R300_TX_FORMAT_CONST_Z           (4<<5)
-#      define R300_TX_FORMAT_CONST_W           (8<<5)
-
-#      define R300_TX_FORMAT_YUV_MODE          0x00800000
-
-#define R300_TX_PITCH_0                            0x4500 /* obvious missing in gap */
-#define R300_TX_OFFSET_0                    0x4540
-       /* BEGIN: Guess from R200 */
-#       define R300_TXO_ENDIAN_NO_SWAP           (0 << 0)
-#       define R300_TXO_ENDIAN_BYTE_SWAP         (1 << 0)
-#       define R300_TXO_ENDIAN_WORD_SWAP         (2 << 0)
-#       define R300_TXO_ENDIAN_HALFDW_SWAP       (3 << 0)
-#       define R300_TXO_MACRO_TILE               (1 << 2)
-#       define R300_TXO_MICRO_TILE               (1 << 3)
-#       define R300_TXO_OFFSET_MASK              0xffffffe0
-#       define R300_TXO_OFFSET_SHIFT             5
-       /* END: Guess from R200 */
-
-/* 32 bit chroma key */
-#define R300_TX_CHROMA_KEY_0                      0x4580
-/* ff00ff00 == { 0, 1.0, 0, 1.0 } */
-#define R300_TX_BORDER_COLOR_0              0x45C0
-
-/* END: Texture specification */
-
-/* BEGIN: Fragment program instruction set */
-
-/* Fragment programs are written directly into register space.
- * There are separate instruction streams for texture instructions and ALU
- * instructions.
- * In order to synchronize these streams, the program is divided into up
- * to 4 nodes. Each node begins with a number of TEX operations, followed
- * by a number of ALU operations.
- * The first node can have zero TEX ops, all subsequent nodes must have at
- * least
- * one TEX ops.
- * All nodes must have at least one ALU op.
- *
- * The index of the last node is stored in PFS_CNTL_0: A value of 0 means
- * 1 node, a value of 3 means 4 nodes.
- * The total amount of instructions is defined in PFS_CNTL_2. The offsets are
- * offsets into the respective instruction streams, while *_END points to the
- * last instruction relative to this offset.
- */
-#define R300_PFS_CNTL_0                     0x4600
-#       define R300_PFS_CNTL_LAST_NODES_SHIFT    0
-#       define R300_PFS_CNTL_LAST_NODES_MASK     (3 << 0)
-#       define R300_PFS_CNTL_FIRST_NODE_HAS_TEX  (1 << 3)
-#define R300_PFS_CNTL_1                     0x4604
-/* There is an unshifted value here which has so far always been equal to the
- * index of the highest used temporary register.
- */
-#define R300_PFS_CNTL_2                     0x4608
-#       define R300_PFS_CNTL_ALU_OFFSET_SHIFT    0
-#       define R300_PFS_CNTL_ALU_OFFSET_MASK     (63 << 0)
-#       define R300_PFS_CNTL_ALU_END_SHIFT       6
-#       define R300_PFS_CNTL_ALU_END_MASK        (63 << 6)
-#       define R300_PFS_CNTL_TEX_OFFSET_SHIFT    12
-#       define R300_PFS_CNTL_TEX_OFFSET_MASK     (31 << 12) /* GUESS */
-#       define R300_PFS_CNTL_TEX_END_SHIFT       18
-#       define R300_PFS_CNTL_TEX_END_MASK        (31 << 18) /* GUESS */
-
-/* gap */
-
-/* Nodes are stored backwards. The last active node is always stored in
- * PFS_NODE_3.
- * Example: In a 2-node program, NODE_0 and NODE_1 are set to 0. The
- * first node is stored in NODE_2, the second node is stored in NODE_3.
- *
- * Offsets are relative to the master offset from PFS_CNTL_2.
- */
-#define R300_PFS_NODE_0                     0x4610
-#define R300_PFS_NODE_1                     0x4614
-#define R300_PFS_NODE_2                     0x4618
-#define R300_PFS_NODE_3                     0x461C
-#       define R300_PFS_NODE_ALU_OFFSET_SHIFT    0
-#       define R300_PFS_NODE_ALU_OFFSET_MASK     (63 << 0)
-#       define R300_PFS_NODE_ALU_END_SHIFT       6
-#       define R300_PFS_NODE_ALU_END_MASK        (63 << 6)
-#       define R300_PFS_NODE_TEX_OFFSET_SHIFT    12
-#       define R300_PFS_NODE_TEX_OFFSET_MASK     (31 << 12)
-#       define R300_PFS_NODE_TEX_END_SHIFT       17
-#       define R300_PFS_NODE_TEX_END_MASK        (31 << 17)
-#              define R300_PFS_NODE_OUTPUT_COLOR        (1 << 22)
-#              define R300_PFS_NODE_OUTPUT_DEPTH        (1 << 23)
-
-/* TEX
- * As far as I can tell, texture instructions cannot write into output
- * registers directly. A subsequent ALU instruction is always necessary,
- * even if it's just MAD o0, r0, 1, 0
- */
-#define R300_PFS_TEXI_0                     0x4620
-#      define R300_FPITX_SRC_SHIFT              0
-#      define R300_FPITX_SRC_MASK               (31 << 0)
-       /* GUESS */
-#      define R300_FPITX_SRC_CONST              (1 << 5)
-#      define R300_FPITX_DST_SHIFT              6
-#      define R300_FPITX_DST_MASK               (31 << 6)
-#      define R300_FPITX_IMAGE_SHIFT            11
-       /* GUESS based on layout and native limits */
-#       define R300_FPITX_IMAGE_MASK             (15 << 11)
-/* Unsure if these are opcodes, or some kind of bitfield, but this is how
- * they were set when I checked
- */
-#      define R300_FPITX_OPCODE_SHIFT          15
-#              define R300_FPITX_OP_TEX        1
-#              define R300_FPITX_OP_KIL        2
-#              define R300_FPITX_OP_TXP        3
-#              define R300_FPITX_OP_TXB        4
-#      define R300_FPITX_OPCODE_MASK           (7 << 15)
-
-/* ALU
- * The ALU instructions register blocks are enumerated according to the order
- * in which fglrx. I assume there is space for 64 instructions, since
- * each block has space for a maximum of 64 DWORDs, and this matches reported
- * native limits.
- *
- * The basic functional block seems to be one MAD for each color and alpha,
- * and an adder that adds all components after the MUL.
- *  - ADD, MUL, MAD etc.: use MAD with appropriate neutral operands
- *  - DP4: Use OUTC_DP4, OUTA_DP4
- *  - DP3: Use OUTC_DP3, OUTA_DP4, appropriate alpha operands
- *  - DPH: Use OUTC_DP4, OUTA_DP4, appropriate alpha operands
- *  - CMPH: If ARG2 > 0.5, return ARG0, else return ARG1
- *  - CMP: If ARG2 < 0, return ARG1, else return ARG0
- *  - FLR: use FRC+MAD
- *  - XPD: use MAD+MAD
- *  - SGE, SLT: use MAD+CMP
- *  - RSQ: use ABS modifier for argument
- *  - Use OUTC_REPL_ALPHA to write results of an alpha-only operation
- *    (e.g. RCP) into color register
- *  - apparently, there's no quick DST operation
- *  - fglrx set FPI2_UNKNOWN_31 on a "MAD fragment.color, tmp0, tmp1, tmp2"
- *  - fglrx set FPI2_UNKNOWN_31 on a "MAX r2, r1, c0"
- *  - fglrx once set FPI0_UNKNOWN_31 on a "FRC r1, r1"
- *
- * Operand selection
- * First stage selects three sources from the available registers and
- * constant parameters. This is defined in INSTR1 (color) and INSTR3 (alpha).
- * fglrx sorts the three source fields: Registers before constants,
- * lower indices before higher indices; I do not know whether this is
- * necessary.
- *
- * fglrx fills unused sources with "read constant 0"
- * According to specs, you cannot select more than two different constants.
- *
- * Second stage selects the operands from the sources. This is defined in
- * INSTR0 (color) and INSTR2 (alpha). You can also select the special constants
- * zero and one.
- * Swizzling and negation happens in this stage, as well.
- *
- * Important: Color and alpha seem to be mostly separate, i.e. their sources
- * selection appears to be fully independent (the register storage is probably
- * physically split into a color and an alpha section).
- * However (because of the apparent physical split), there is some interaction
- * WRT swizzling. If, for example, you want to load an R component into an
- * Alpha operand, this R component is taken from a *color* source, not from
- * an alpha source. The corresponding register doesn't even have to appear in
- * the alpha sources list. (I hope this all makes sense to you)
- *
- * Destination selection
- * The destination register index is in FPI1 (color) and FPI3 (alpha)
- * together with enable bits.
- * There are separate enable bits for writing into temporary registers
- * (DSTC_REG_* /DSTA_REG) and and program output registers (DSTC_OUTPUT_*
- * /DSTA_OUTPUT). You can write to both at once, or not write at all (the
- * same index must be used for both).
- *
- * Note: There is a special form for LRP
- *  - Argument order is the same as in ARB_fragment_program.
- *  - Operation is MAD
- *  - ARG1 is set to ARGC_SRC1C_LRP/ARGC_SRC1A_LRP
- *  - Set FPI0/FPI2_SPECIAL_LRP
- * Arbitrary LRP (including support for swizzling) requires vanilla MAD+MAD
- */
-#define R300_PFS_INSTR1_0                   0x46C0
-#       define R300_FPI1_SRC0C_SHIFT             0
-#       define R300_FPI1_SRC0C_MASK              (31 << 0)
-#       define R300_FPI1_SRC0C_CONST             (1 << 5)
-#       define R300_FPI1_SRC1C_SHIFT             6
-#       define R300_FPI1_SRC1C_MASK              (31 << 6)
-#       define R300_FPI1_SRC1C_CONST             (1 << 11)
-#       define R300_FPI1_SRC2C_SHIFT             12
-#       define R300_FPI1_SRC2C_MASK              (31 << 12)
-#       define R300_FPI1_SRC2C_CONST             (1 << 17)
-#       define R300_FPI1_SRC_MASK                0x0003ffff
-#       define R300_FPI1_DSTC_SHIFT              18
-#       define R300_FPI1_DSTC_MASK               (31 << 18)
-#              define R300_FPI1_DSTC_REG_MASK_SHIFT     23
-#       define R300_FPI1_DSTC_REG_X              (1 << 23)
-#       define R300_FPI1_DSTC_REG_Y              (1 << 24)
-#       define R300_FPI1_DSTC_REG_Z              (1 << 25)
-#              define R300_FPI1_DSTC_OUTPUT_MASK_SHIFT  26
-#       define R300_FPI1_DSTC_OUTPUT_X           (1 << 26)
-#       define R300_FPI1_DSTC_OUTPUT_Y           (1 << 27)
-#       define R300_FPI1_DSTC_OUTPUT_Z           (1 << 28)
-
-#define R300_PFS_INSTR3_0                   0x47C0
-#       define R300_FPI3_SRC0A_SHIFT             0
-#       define R300_FPI3_SRC0A_MASK              (31 << 0)
-#       define R300_FPI3_SRC0A_CONST             (1 << 5)
-#       define R300_FPI3_SRC1A_SHIFT             6
-#       define R300_FPI3_SRC1A_MASK              (31 << 6)
-#       define R300_FPI3_SRC1A_CONST             (1 << 11)
-#       define R300_FPI3_SRC2A_SHIFT             12
-#       define R300_FPI3_SRC2A_MASK              (31 << 12)
-#       define R300_FPI3_SRC2A_CONST             (1 << 17)
-#       define R300_FPI3_SRC_MASK                0x0003ffff
-#       define R300_FPI3_DSTA_SHIFT              18
-#       define R300_FPI3_DSTA_MASK               (31 << 18)
-#       define R300_FPI3_DSTA_REG                (1 << 23)
-#       define R300_FPI3_DSTA_OUTPUT             (1 << 24)
-#              define R300_FPI3_DSTA_DEPTH              (1 << 27)
-
-#define R300_PFS_INSTR0_0                   0x48C0
-#       define R300_FPI0_ARGC_SRC0C_XYZ          0
-#       define R300_FPI0_ARGC_SRC0C_XXX          1
-#       define R300_FPI0_ARGC_SRC0C_YYY          2
-#       define R300_FPI0_ARGC_SRC0C_ZZZ          3
-#       define R300_FPI0_ARGC_SRC1C_XYZ          4
-#       define R300_FPI0_ARGC_SRC1C_XXX          5
-#       define R300_FPI0_ARGC_SRC1C_YYY          6
-#       define R300_FPI0_ARGC_SRC1C_ZZZ          7
-#       define R300_FPI0_ARGC_SRC2C_XYZ          8
-#       define R300_FPI0_ARGC_SRC2C_XXX          9
-#       define R300_FPI0_ARGC_SRC2C_YYY          10
-#       define R300_FPI0_ARGC_SRC2C_ZZZ          11
-#       define R300_FPI0_ARGC_SRC0A              12
-#       define R300_FPI0_ARGC_SRC1A              13
-#       define R300_FPI0_ARGC_SRC2A              14
-#       define R300_FPI0_ARGC_SRC1C_LRP          15
-#       define R300_FPI0_ARGC_ZERO               20
-#       define R300_FPI0_ARGC_ONE                21
-       /* GUESS */
-#       define R300_FPI0_ARGC_HALF               22
-#       define R300_FPI0_ARGC_SRC0C_YZX          23
-#       define R300_FPI0_ARGC_SRC1C_YZX          24
-#       define R300_FPI0_ARGC_SRC2C_YZX          25
-#       define R300_FPI0_ARGC_SRC0C_ZXY          26
-#       define R300_FPI0_ARGC_SRC1C_ZXY          27
-#       define R300_FPI0_ARGC_SRC2C_ZXY          28
-#       define R300_FPI0_ARGC_SRC0CA_WZY         29
-#       define R300_FPI0_ARGC_SRC1CA_WZY         30
-#       define R300_FPI0_ARGC_SRC2CA_WZY         31
-
-#       define R300_FPI0_ARG0C_SHIFT             0
-#       define R300_FPI0_ARG0C_MASK              (31 << 0)
-#       define R300_FPI0_ARG0C_NEG               (1 << 5)
-#       define R300_FPI0_ARG0C_ABS               (1 << 6)
-#       define R300_FPI0_ARG1C_SHIFT             7
-#       define R300_FPI0_ARG1C_MASK              (31 << 7)
-#       define R300_FPI0_ARG1C_NEG               (1 << 12)
-#       define R300_FPI0_ARG1C_ABS               (1 << 13)
-#       define R300_FPI0_ARG2C_SHIFT             14
-#       define R300_FPI0_ARG2C_MASK              (31 << 14)
-#       define R300_FPI0_ARG2C_NEG               (1 << 19)
-#       define R300_FPI0_ARG2C_ABS               (1 << 20)
-#       define R300_FPI0_SPECIAL_LRP             (1 << 21)
-#       define R300_FPI0_OUTC_MAD                (0 << 23)
-#       define R300_FPI0_OUTC_DP3                (1 << 23)
-#       define R300_FPI0_OUTC_DP4                (2 << 23)
-#       define R300_FPI0_OUTC_MIN                (4 << 23)
-#       define R300_FPI0_OUTC_MAX                (5 << 23)
-#       define R300_FPI0_OUTC_CMPH               (7 << 23)
-#       define R300_FPI0_OUTC_CMP                (8 << 23)
-#       define R300_FPI0_OUTC_FRC                (9 << 23)
-#       define R300_FPI0_OUTC_REPL_ALPHA         (10 << 23)
-#       define R300_FPI0_OUTC_SAT                (1 << 30)
-#       define R300_FPI0_INSERT_NOP              (1 << 31)
-
-#define R300_PFS_INSTR2_0                   0x49C0
-#       define R300_FPI2_ARGA_SRC0C_X            0
-#       define R300_FPI2_ARGA_SRC0C_Y            1
-#       define R300_FPI2_ARGA_SRC0C_Z            2
-#       define R300_FPI2_ARGA_SRC1C_X            3
-#       define R300_FPI2_ARGA_SRC1C_Y            4
-#       define R300_FPI2_ARGA_SRC1C_Z            5
-#       define R300_FPI2_ARGA_SRC2C_X            6
-#       define R300_FPI2_ARGA_SRC2C_Y            7
-#       define R300_FPI2_ARGA_SRC2C_Z            8
-#       define R300_FPI2_ARGA_SRC0A              9
-#       define R300_FPI2_ARGA_SRC1A              10
-#       define R300_FPI2_ARGA_SRC2A              11
-#       define R300_FPI2_ARGA_SRC1A_LRP          15
-#       define R300_FPI2_ARGA_ZERO               16
-#       define R300_FPI2_ARGA_ONE                17
-       /* GUESS */
-#       define R300_FPI2_ARGA_HALF               18
-#       define R300_FPI2_ARG0A_SHIFT             0
-#       define R300_FPI2_ARG0A_MASK              (31 << 0)
-#       define R300_FPI2_ARG0A_NEG               (1 << 5)
-       /* GUESS */
-#      define R300_FPI2_ARG0A_ABS               (1 << 6)
-#       define R300_FPI2_ARG1A_SHIFT             7
-#       define R300_FPI2_ARG1A_MASK              (31 << 7)
-#       define R300_FPI2_ARG1A_NEG               (1 << 12)
-       /* GUESS */
-#      define R300_FPI2_ARG1A_ABS               (1 << 13)
-#       define R300_FPI2_ARG2A_SHIFT             14
-#       define R300_FPI2_ARG2A_MASK              (31 << 14)
-#       define R300_FPI2_ARG2A_NEG               (1 << 19)
-       /* GUESS */
-#      define R300_FPI2_ARG2A_ABS               (1 << 20)
-#       define R300_FPI2_SPECIAL_LRP             (1 << 21)
-#       define R300_FPI2_OUTA_MAD                (0 << 23)
-#       define R300_FPI2_OUTA_DP4                (1 << 23)
-#       define R300_FPI2_OUTA_MIN                (2 << 23)
-#       define R300_FPI2_OUTA_MAX                (3 << 23)
-#       define R300_FPI2_OUTA_CMP                (6 << 23)
-#       define R300_FPI2_OUTA_FRC                (7 << 23)
-#       define R300_FPI2_OUTA_EX2                (8 << 23)
-#       define R300_FPI2_OUTA_LG2                (9 << 23)
-#       define R300_FPI2_OUTA_RCP                (10 << 23)
-#       define R300_FPI2_OUTA_RSQ                (11 << 23)
-#       define R300_FPI2_OUTA_SAT                (1 << 30)
-#       define R300_FPI2_UNKNOWN_31              (1 << 31)
-/* END: Fragment program instruction set */
-
-/* Fog state and color */
-#define R300_RE_FOG_STATE                   0x4BC0
-#       define R300_FOG_ENABLE                   (1 << 0)
-#      define R300_FOG_MODE_LINEAR              (0 << 1)
-#      define R300_FOG_MODE_EXP                 (1 << 1)
-#      define R300_FOG_MODE_EXP2                (2 << 1)
-#      define R300_FOG_MODE_MASK                (3 << 1)
-#define R300_FOG_COLOR_R                    0x4BC8
-#define R300_FOG_COLOR_G                    0x4BCC
-#define R300_FOG_COLOR_B                    0x4BD0
-
-#define R300_PP_ALPHA_TEST                  0x4BD4
-#       define R300_REF_ALPHA_MASK               0x000000ff
-#       define R300_ALPHA_TEST_FAIL              (0 << 8)
-#       define R300_ALPHA_TEST_LESS              (1 << 8)
-#       define R300_ALPHA_TEST_LEQUAL            (3 << 8)
-#       define R300_ALPHA_TEST_EQUAL             (2 << 8)
-#       define R300_ALPHA_TEST_GEQUAL            (6 << 8)
-#       define R300_ALPHA_TEST_GREATER           (4 << 8)
-#       define R300_ALPHA_TEST_NEQUAL            (5 << 8)
-#       define R300_ALPHA_TEST_PASS              (7 << 8)
-#       define R300_ALPHA_TEST_OP_MASK           (7 << 8)
-#       define R300_ALPHA_TEST_ENABLE            (1 << 11)
-
-/* gap */
-
-/* Fragment program parameters in 7.16 floating point */
-#define R300_PFS_PARAM_0_X                  0x4C00
-#define R300_PFS_PARAM_0_Y                  0x4C04
-#define R300_PFS_PARAM_0_Z                  0x4C08
-#define R300_PFS_PARAM_0_W                  0x4C0C
-/* GUESS: PARAM_31 is last, based on native limits reported by fglrx */
-#define R300_PFS_PARAM_31_X                 0x4DF0
-#define R300_PFS_PARAM_31_Y                 0x4DF4
-#define R300_PFS_PARAM_31_Z                 0x4DF8
-#define R300_PFS_PARAM_31_W                 0x4DFC
-
-/* Notes:
- * - AFAIK fglrx always sets BLEND_UNKNOWN when blending is used in
- *   the application
- * - AFAIK fglrx always sets BLEND_NO_SEPARATE when CBLEND and ABLEND
- *    are set to the same
- *   function (both registers are always set up completely in any case)
- * - Most blend flags are simply copied from R200 and not tested yet
- */
-#define R300_RB3D_CBLEND                    0x4E04
-#define R300_RB3D_ABLEND                    0x4E08
-/* the following only appear in CBLEND */
-#       define R300_BLEND_ENABLE                     (1 << 0)
-#       define R300_BLEND_UNKNOWN                    (3 << 1)
-#       define R300_BLEND_NO_SEPARATE                (1 << 3)
-/* the following are shared between CBLEND and ABLEND */
-#       define R300_FCN_MASK                         (3  << 12)
-#       define R300_COMB_FCN_ADD_CLAMP               (0  << 12)
-#       define R300_COMB_FCN_ADD_NOCLAMP             (1  << 12)
-#       define R300_COMB_FCN_SUB_CLAMP               (2  << 12)
-#       define R300_COMB_FCN_SUB_NOCLAMP             (3  << 12)
-#       define R300_COMB_FCN_MIN                     (4  << 12)
-#       define R300_COMB_FCN_MAX                     (5  << 12)
-#       define R300_COMB_FCN_RSUB_CLAMP              (6  << 12)
-#       define R300_COMB_FCN_RSUB_NOCLAMP            (7  << 12)
-#       define R300_BLEND_GL_ZERO                    (32)
-#       define R300_BLEND_GL_ONE                     (33)
-#       define R300_BLEND_GL_SRC_COLOR               (34)
-#       define R300_BLEND_GL_ONE_MINUS_SRC_COLOR     (35)
-#       define R300_BLEND_GL_DST_COLOR               (36)
-#       define R300_BLEND_GL_ONE_MINUS_DST_COLOR     (37)
-#       define R300_BLEND_GL_SRC_ALPHA               (38)
-#       define R300_BLEND_GL_ONE_MINUS_SRC_ALPHA     (39)
-#       define R300_BLEND_GL_DST_ALPHA               (40)
-#       define R300_BLEND_GL_ONE_MINUS_DST_ALPHA     (41)
-#       define R300_BLEND_GL_SRC_ALPHA_SATURATE      (42)
-#       define R300_BLEND_GL_CONST_COLOR             (43)
-#       define R300_BLEND_GL_ONE_MINUS_CONST_COLOR   (44)
-#       define R300_BLEND_GL_CONST_ALPHA             (45)
-#       define R300_BLEND_GL_ONE_MINUS_CONST_ALPHA   (46)
-#       define R300_BLEND_MASK                       (63)
-#       define R300_SRC_BLEND_SHIFT                  (16)
-#       define R300_DST_BLEND_SHIFT                  (24)
-#define R300_RB3D_BLEND_COLOR               0x4E10
-#define R300_RB3D_COLORMASK                 0x4E0C
-#       define R300_COLORMASK0_B                 (1<<0)
-#       define R300_COLORMASK0_G                 (1<<1)
-#       define R300_COLORMASK0_R                 (1<<2)
-#       define R300_COLORMASK0_A                 (1<<3)
-
-/* gap */
-
-#define R300_RB3D_COLOROFFSET0              0x4E28
-#       define R300_COLOROFFSET_MASK             0xFFFFFFF0 /* GUESS */
-#define R300_RB3D_COLOROFFSET1              0x4E2C /* GUESS */
-#define R300_RB3D_COLOROFFSET2              0x4E30 /* GUESS */
-#define R300_RB3D_COLOROFFSET3              0x4E34 /* GUESS */
-
-/* gap */
-
-/* Bit 16: Larger tiles
- * Bit 17: 4x2 tiles
- * Bit 18: Extremely weird tile like, but some pixels duplicated?
- */
-#define R300_RB3D_COLORPITCH0               0x4E38
-#       define R300_COLORPITCH_MASK              0x00001FF8 /* GUESS */
-#       define R300_COLOR_TILE_ENABLE            (1 << 16) /* GUESS */
-#       define R300_COLOR_MICROTILE_ENABLE       (1 << 17) /* GUESS */
-#       define R300_COLOR_ENDIAN_NO_SWAP         (0 << 18) /* GUESS */
-#       define R300_COLOR_ENDIAN_WORD_SWAP       (1 << 18) /* GUESS */
-#       define R300_COLOR_ENDIAN_DWORD_SWAP      (2 << 18) /* GUESS */
-#       define R300_COLOR_FORMAT_RGB565          (2 << 22)
-#       define R300_COLOR_FORMAT_ARGB8888        (3 << 22)
-#define R300_RB3D_COLORPITCH1               0x4E3C /* GUESS */
-#define R300_RB3D_COLORPITCH2               0x4E40 /* GUESS */
-#define R300_RB3D_COLORPITCH3               0x4E44 /* GUESS */
-
-/* gap */
-
-/* Guess by Vladimir.
- * Set to 0A before 3D operations, set to 02 afterwards.
- */
-/*#define R300_RB3D_DSTCACHE_CTLSTAT          0x4E4C*/
-#       define R300_RB3D_DSTCACHE_UNKNOWN_02             0x00000002
-#       define R300_RB3D_DSTCACHE_UNKNOWN_0A             0x0000000A
-
-/* gap */
-/* There seems to be no "write only" setting, so use Z-test = ALWAYS
- * for this.
- * Bit (1<<8) is the "test" bit. so plain write is 6  - vd
- */
-#define R300_ZB_CNTL                             0x4F00
-#      define R300_STENCIL_ENABLE               (1 << 0)
-#      define R300_Z_ENABLE                     (1 << 1)
-#      define R300_Z_WRITE_ENABLE               (1 << 2)
-#      define R300_Z_SIGNED_COMPARE             (1 << 3)
-#      define R300_STENCIL_FRONT_BACK           (1 << 4)
-
-#define R300_ZB_ZSTENCILCNTL                   0x4f04
-       /* functions */
-#      define R300_ZS_NEVER                    0
-#      define R300_ZS_LESS                     1
-#      define R300_ZS_LEQUAL                   2
-#      define R300_ZS_EQUAL                    3
-#      define R300_ZS_GEQUAL                   4
-#      define R300_ZS_GREATER                  5
-#      define R300_ZS_NOTEQUAL                 6
-#      define R300_ZS_ALWAYS                   7
-#       define R300_ZS_MASK                     7
-       /* operations */
-#      define R300_ZS_KEEP                     0
-#      define R300_ZS_ZERO                     1
-#      define R300_ZS_REPLACE                  2
-#      define R300_ZS_INCR                     3
-#      define R300_ZS_DECR                     4
-#      define R300_ZS_INVERT                   5
-#      define R300_ZS_INCR_WRAP                6
-#      define R300_ZS_DECR_WRAP                7
-#      define R300_Z_FUNC_SHIFT                0
-       /* front and back refer to operations done for front
-          and back faces, i.e. separate stencil function support */
-#      define R300_S_FRONT_FUNC_SHIFT          3
-#      define R300_S_FRONT_SFAIL_OP_SHIFT      6
-#      define R300_S_FRONT_ZPASS_OP_SHIFT      9
-#      define R300_S_FRONT_ZFAIL_OP_SHIFT      12
-#      define R300_S_BACK_FUNC_SHIFT           15
-#      define R300_S_BACK_SFAIL_OP_SHIFT       18
-#      define R300_S_BACK_ZPASS_OP_SHIFT       21
-#      define R300_S_BACK_ZFAIL_OP_SHIFT       24
-
-#define R300_ZB_STENCILREFMASK                        0x4f08
-#      define R300_STENCILREF_SHIFT       0
-#      define R300_STENCILREF_MASK        0x000000ff
-#      define R300_STENCILMASK_SHIFT      8
-#      define R300_STENCILMASK_MASK       0x0000ff00
-#      define R300_STENCILWRITEMASK_SHIFT 16
-#      define R300_STENCILWRITEMASK_MASK  0x00ff0000
-
-/* gap */
-
-#define R300_ZB_FORMAT                             0x4f10
-#      define R300_DEPTHFORMAT_16BIT_INT_Z   (0 << 0)
-#      define R300_DEPTHFORMAT_16BIT_13E3    (1 << 0)
-#      define R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL   (2 << 0)
-/* reserved up to (15 << 0) */
-#      define R300_INVERT_13E3_LEADING_ONES  (0 << 4)
-#      define R300_INVERT_13E3_LEADING_ZEROS (1 << 4)
-
-#define R300_ZB_ZTOP                             0x4F14
-#      define R300_ZTOP_DISABLE                 (0 << 0)
-#      define R300_ZTOP_ENABLE                  (1 << 0)
-
-/* gap */
-
-#define R300_ZB_ZCACHE_CTLSTAT            0x4f18
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_NO_EFFECT      (0 << 0)
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE (1 << 0)
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_NO_EFFECT       (0 << 1)
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE            (1 << 1)
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_IDLE            (0 << 31)
-#       define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_BUSY            (1 << 31)
-
-#define R300_ZB_BW_CNTL                     0x4f1c
-#      define R300_HIZ_DISABLE                              (0 << 0)
-#      define R300_HIZ_ENABLE                               (1 << 0)
-#      define R300_HIZ_MIN                                  (0 << 1)
-#      define R300_HIZ_MAX                                  (1 << 1)
-#      define R300_FAST_FILL_DISABLE                        (0 << 2)
-#      define R300_FAST_FILL_ENABLE                         (1 << 2)
-#      define R300_RD_COMP_DISABLE                          (0 << 3)
-#      define R300_RD_COMP_ENABLE                           (1 << 3)
-#      define R300_WR_COMP_DISABLE                          (0 << 4)
-#      define R300_WR_COMP_ENABLE                           (1 << 4)
-#      define R300_ZB_CB_CLEAR_RMW                          (0 << 5)
-#      define R300_ZB_CB_CLEAR_CACHE_LINEAR                 (1 << 5)
-#      define R300_FORCE_COMPRESSED_STENCIL_VALUE_DISABLE   (0 << 6)
-#      define R300_FORCE_COMPRESSED_STENCIL_VALUE_ENABLE    (1 << 6)
-
-#      define R500_ZEQUAL_OPTIMIZE_ENABLE                   (0 << 7)
-#      define R500_ZEQUAL_OPTIMIZE_DISABLE                  (1 << 7)
-#      define R500_SEQUAL_OPTIMIZE_ENABLE                   (0 << 8)
-#      define R500_SEQUAL_OPTIMIZE_DISABLE                  (1 << 8)
-
-#      define R500_BMASK_ENABLE                             (0 << 10)
-#      define R500_BMASK_DISABLE                            (1 << 10)
-#      define R500_HIZ_EQUAL_REJECT_DISABLE                 (0 << 11)
-#      define R500_HIZ_EQUAL_REJECT_ENABLE                  (1 << 11)
-#      define R500_HIZ_FP_EXP_BITS_DISABLE                  (0 << 12)
-#      define R500_HIZ_FP_EXP_BITS_1                        (1 << 12)
-#      define R500_HIZ_FP_EXP_BITS_2                        (2 << 12)
-#      define R500_HIZ_FP_EXP_BITS_3                        (3 << 12)
-#      define R500_HIZ_FP_EXP_BITS_4                        (4 << 12)
-#      define R500_HIZ_FP_EXP_BITS_5                        (5 << 12)
-#      define R500_HIZ_FP_INVERT_LEADING_ONES               (0 << 15)
-#      define R500_HIZ_FP_INVERT_LEADING_ZEROS              (1 << 15)
-#      define R500_TILE_OVERWRITE_RECOMPRESSION_ENABLE      (0 << 16)
-#      define R500_TILE_OVERWRITE_RECOMPRESSION_DISABLE     (1 << 16)
-#      define R500_CONTIGUOUS_6XAA_SAMPLES_ENABLE           (0 << 17)
-#      define R500_CONTIGUOUS_6XAA_SAMPLES_DISABLE          (1 << 17)
-#      define R500_PEQ_PACKING_DISABLE                      (0 << 18)
-#      define R500_PEQ_PACKING_ENABLE                       (1 << 18)
-#      define R500_COVERED_PTR_MASKING_DISABLE              (0 << 18)
-#      define R500_COVERED_PTR_MASKING_ENABLE               (1 << 18)
-
-
-/* gap */
-
-/* Z Buffer Address Offset.
- * Bits 31 to 5 are used for aligned Z buffer address offset for macro tiles.
- */
-#define R300_ZB_DEPTHOFFSET               0x4f20
-
-/* Z Buffer Pitch and Endian Control */
-#define R300_ZB_DEPTHPITCH                0x4f24
-#       define R300_DEPTHPITCH_MASK              0x00003FFC
-#       define R300_DEPTHMACROTILE_DISABLE      (0 << 16)
-#       define R300_DEPTHMACROTILE_ENABLE       (1 << 16)
-#       define R300_DEPTHMICROTILE_LINEAR       (0 << 17)
-#       define R300_DEPTHMICROTILE_TILED        (1 << 17)
-#       define R300_DEPTHMICROTILE_TILED_SQUARE (2 << 17)
-#       define R300_DEPTHENDIAN_NO_SWAP         (0 << 18)
-#       define R300_DEPTHENDIAN_WORD_SWAP       (1 << 18)
-#       define R300_DEPTHENDIAN_DWORD_SWAP      (2 << 18)
-#       define R300_DEPTHENDIAN_HALF_DWORD_SWAP (3 << 18)
-
-/* Z Buffer Clear Value */
-#define R300_ZB_DEPTHCLEARVALUE                  0x4f28
-
-#define R300_ZB_ZMASK_OFFSET                    0x4f30
-#define R300_ZB_ZMASK_PITCH                     0x4f34
-#define R300_ZB_ZMASK_WRINDEX                   0x4f38
-#define R300_ZB_ZMASK_DWORD                     0x4f3c
-#define R300_ZB_ZMASK_RDINDEX                   0x4f40
-
-/* Hierarchical Z Memory Offset */
-#define R300_ZB_HIZ_OFFSET                       0x4f44
-
-/* Hierarchical Z Write Index */
-#define R300_ZB_HIZ_WRINDEX                      0x4f48
-
-/* Hierarchical Z Data */
-#define R300_ZB_HIZ_DWORD                        0x4f4c
-
-/* Hierarchical Z Read Index */
-#define R300_ZB_HIZ_RDINDEX                      0x4f50
-
-/* Hierarchical Z Pitch */
-#define R300_ZB_HIZ_PITCH                        0x4f54
-
-/* Z Buffer Z Pass Counter Data */
-#define R300_ZB_ZPASS_DATA                       0x4f58
-
-/* Z Buffer Z Pass Counter Address */
-#define R300_ZB_ZPASS_ADDR                       0x4f5c
-
-/* Depth buffer X and Y coordinate offset */
-#define R300_ZB_DEPTHXY_OFFSET                   0x4f60
-#      define R300_DEPTHX_OFFSET_SHIFT  1
-#      define R300_DEPTHX_OFFSET_MASK   0x000007FE
-#      define R300_DEPTHY_OFFSET_SHIFT  17
-#      define R300_DEPTHY_OFFSET_MASK   0x07FE0000
-
-/* Sets the fifo sizes */
-#define R500_ZB_FIFO_SIZE                        0x4fd0
-#      define R500_OP_FIFO_SIZE_FULL   (0 << 0)
-#      define R500_OP_FIFO_SIZE_HALF   (1 << 0)
-#      define R500_OP_FIFO_SIZE_QUATER (2 << 0)
-#      define R500_OP_FIFO_SIZE_EIGTHS (4 << 0)
-
-/* Stencil Reference Value and Mask for backfacing quads */
-/* R300_ZB_STENCILREFMASK handles front face */
-#define R500_ZB_STENCILREFMASK_BF                0x4fd4
-#      define R500_STENCILREF_SHIFT       0
-#      define R500_STENCILREF_MASK        0x000000ff
-#      define R500_STENCILMASK_SHIFT      8
-#      define R500_STENCILMASK_MASK       0x0000ff00
-#      define R500_STENCILWRITEMASK_SHIFT 16
-#      define R500_STENCILWRITEMASK_MASK  0x00ff0000
-
-/* BEGIN: Vertex program instruction set */
-
-/* Every instruction is four dwords long:
- *  DWORD 0: output and opcode
- *  DWORD 1: first argument
- *  DWORD 2: second argument
- *  DWORD 3: third argument
- *
- * Notes:
- *  - ABS r, a is implemented as MAX r, a, -a
- *  - MOV is implemented as ADD to zero
- *  - XPD is implemented as MUL + MAD
- *  - FLR is implemented as FRC + ADD
- *  - apparently, fglrx tries to schedule instructions so that there is at
- *    least one instruction between the write to a temporary and the first
- *    read from said temporary; however, violations of this scheduling are
- *    allowed
- *  - register indices seem to be unrelated with OpenGL aliasing to
- *    conventional state
- *  - only one attribute and one parameter can be loaded at a time; however,
- *    the same attribute/parameter can be used for more than one argument
- *  - the second software argument for POW is the third hardware argument
- *    (no idea why)
- *  - MAD with only temporaries as input seems to use VPI_OUT_SELECT_MAD_2
- *
- * There is some magic surrounding LIT:
- *   The single argument is replicated across all three inputs, but swizzled:
- *     First argument: xyzy
- *     Second argument: xyzx
- *     Third argument: xyzw
- *   Whenever the result is used later in the fragment program, fglrx forces
- *   x and w to be 1.0 in the input selection; I don't know whether this is
- *   strictly necessary
- */
-#define R300_VPI_OUT_OP_DOT                     (1 << 0)
-#define R300_VPI_OUT_OP_MUL                     (2 << 0)
-#define R300_VPI_OUT_OP_ADD                     (3 << 0)
-#define R300_VPI_OUT_OP_MAD                     (4 << 0)
-#define R300_VPI_OUT_OP_DST                     (5 << 0)
-#define R300_VPI_OUT_OP_FRC                     (6 << 0)
-#define R300_VPI_OUT_OP_MAX                     (7 << 0)
-#define R300_VPI_OUT_OP_MIN                     (8 << 0)
-#define R300_VPI_OUT_OP_SGE                     (9 << 0)
-#define R300_VPI_OUT_OP_SLT                     (10 << 0)
-       /* Used in GL_POINT_DISTANCE_ATTENUATION_ARB, vector(scalar, vector) */
-#define R300_VPI_OUT_OP_UNK12                   (12 << 0)
-#define R300_VPI_OUT_OP_ARL                     (13 << 0)
-#define R300_VPI_OUT_OP_EXP                     (65 << 0)
-#define R300_VPI_OUT_OP_LOG                     (66 << 0)
-       /* Used in fog computations, scalar(scalar) */
-#define R300_VPI_OUT_OP_UNK67                   (67 << 0)
-#define R300_VPI_OUT_OP_LIT                     (68 << 0)
-#define R300_VPI_OUT_OP_POW                     (69 << 0)
-#define R300_VPI_OUT_OP_RCP                     (70 << 0)
-#define R300_VPI_OUT_OP_RSQ                     (72 << 0)
-       /* Used in GL_POINT_DISTANCE_ATTENUATION_ARB, scalar(scalar) */
-#define R300_VPI_OUT_OP_UNK73                   (73 << 0)
-#define R300_VPI_OUT_OP_EX2                     (75 << 0)
-#define R300_VPI_OUT_OP_LG2                     (76 << 0)
-#define R300_VPI_OUT_OP_MAD_2                   (128 << 0)
-       /* all temps, vector(scalar, vector, vector) */
-#define R300_VPI_OUT_OP_UNK129                  (129 << 0)
-
-#define R300_VPI_OUT_REG_CLASS_TEMPORARY        (0 << 8)
-#define R300_VPI_OUT_REG_CLASS_ADDR             (1 << 8)
-#define R300_VPI_OUT_REG_CLASS_RESULT           (2 << 8)
-#define R300_VPI_OUT_REG_CLASS_MASK             (31 << 8)
-
-#define R300_VPI_OUT_REG_INDEX_SHIFT            13
-       /* GUESS based on fglrx native limits */
-#define R300_VPI_OUT_REG_INDEX_MASK             (31 << 13)
-
-#define R300_VPI_OUT_WRITE_X                    (1 << 20)
-#define R300_VPI_OUT_WRITE_Y                    (1 << 21)
-#define R300_VPI_OUT_WRITE_Z                    (1 << 22)
-#define R300_VPI_OUT_WRITE_W                    (1 << 23)
-
-#define R300_VPI_IN_REG_CLASS_TEMPORARY         (0 << 0)
-#define R300_VPI_IN_REG_CLASS_ATTRIBUTE         (1 << 0)
-#define R300_VPI_IN_REG_CLASS_PARAMETER         (2 << 0)
-#define R300_VPI_IN_REG_CLASS_NONE              (9 << 0)
-#define R300_VPI_IN_REG_CLASS_MASK              (31 << 0)
-
-#define R300_VPI_IN_REG_INDEX_SHIFT             5
-       /* GUESS based on fglrx native limits */
-#define R300_VPI_IN_REG_INDEX_MASK              (255 << 5)
-
-/* The R300 can select components from the input register arbitrarily.
- * Use the following constants, shifted by the component shift you
- * want to select
- */
-#define R300_VPI_IN_SELECT_X    0
-#define R300_VPI_IN_SELECT_Y    1
-#define R300_VPI_IN_SELECT_Z    2
-#define R300_VPI_IN_SELECT_W    3
-#define R300_VPI_IN_SELECT_ZERO 4
-#define R300_VPI_IN_SELECT_ONE  5
-#define R300_VPI_IN_SELECT_MASK 7
-
-#define R300_VPI_IN_X_SHIFT                     13
-#define R300_VPI_IN_Y_SHIFT                     16
-#define R300_VPI_IN_Z_SHIFT                     19
-#define R300_VPI_IN_W_SHIFT                     22
-
-#define R300_VPI_IN_NEG_X                       (1 << 25)
-#define R300_VPI_IN_NEG_Y                       (1 << 26)
-#define R300_VPI_IN_NEG_Z                       (1 << 27)
-#define R300_VPI_IN_NEG_W                       (1 << 28)
-/* END: Vertex program instruction set */
-
-/* BEGIN: Packet 3 commands */
-
-/* A primitive emission dword. */
-#define R300_PRIM_TYPE_NONE                     (0 << 0)
-#define R300_PRIM_TYPE_POINT                    (1 << 0)
-#define R300_PRIM_TYPE_LINE                     (2 << 0)
-#define R300_PRIM_TYPE_LINE_STRIP               (3 << 0)
-#define R300_PRIM_TYPE_TRI_LIST                 (4 << 0)
-#define R300_PRIM_TYPE_TRI_FAN                  (5 << 0)
-#define R300_PRIM_TYPE_TRI_STRIP                (6 << 0)
-#define R300_PRIM_TYPE_TRI_TYPE2                (7 << 0)
-#define R300_PRIM_TYPE_RECT_LIST                (8 << 0)
-#define R300_PRIM_TYPE_3VRT_POINT_LIST          (9 << 0)
-#define R300_PRIM_TYPE_3VRT_LINE_LIST           (10 << 0)
-       /* GUESS (based on r200) */
-#define R300_PRIM_TYPE_POINT_SPRITES            (11 << 0)
-#define R300_PRIM_TYPE_LINE_LOOP                (12 << 0)
-#define R300_PRIM_TYPE_QUADS                    (13 << 0)
-#define R300_PRIM_TYPE_QUAD_STRIP               (14 << 0)
-#define R300_PRIM_TYPE_POLYGON                  (15 << 0)
-#define R300_PRIM_TYPE_MASK                     0xF
-#define R300_PRIM_WALK_IND                      (1 << 4)
-#define R300_PRIM_WALK_LIST                     (2 << 4)
-#define R300_PRIM_WALK_RING                     (3 << 4)
-#define R300_PRIM_WALK_MASK                     (3 << 4)
-       /* GUESS (based on r200) */
-#define R300_PRIM_COLOR_ORDER_BGRA              (0 << 6)
-#define R300_PRIM_COLOR_ORDER_RGBA              (1 << 6)
-#define R300_PRIM_NUM_VERTICES_SHIFT            16
-#define R300_PRIM_NUM_VERTICES_MASK             0xffff
-
-/* Draw a primitive from vertex data in arrays loaded via 3D_LOAD_VBPNTR.
- * Two parameter dwords:
- * 0. The first parameter appears to be always 0
- * 1. The second parameter is a standard primitive emission dword.
- */
-#define R300_PACKET3_3D_DRAW_VBUF           0x00002800
-
-/* Specify the full set of vertex arrays as (address, stride).
- * The first parameter is the number of vertex arrays specified.
- * The rest of the command is a variable length list of blocks, where
- * each block is three dwords long and specifies two arrays.
- * The first dword of a block is split into two words, the lower significant
- * word refers to the first array, the more significant word to the second
- * array in the block.
- * The low byte of each word contains the size of an array entry in dwords,
- * the high byte contains the stride of the array.
- * The second dword of a block contains the pointer to the first array,
- * the third dword of a block contains the pointer to the second array.
- * Note that if the total number of arrays is odd, the third dword of
- * the last block is omitted.
- */
-#define R300_PACKET3_3D_LOAD_VBPNTR         0x00002F00
-
-#define R300_PACKET3_INDX_BUFFER            0x00003300
-#    define R300_EB_UNK1_SHIFT                      24
-#    define R300_EB_UNK1                    (0x80<<24)
-#    define R300_EB_UNK2                        0x0810
-#define R300_PACKET3_3D_DRAW_VBUF_2         0x00003400
-#define R300_PACKET3_3D_DRAW_INDX_2         0x00003600
-
-/* END: Packet 3 commands */
-
-
-/* Color formats for 2d packets
- */
-#define R300_CP_COLOR_FORMAT_CI8       2
-#define R300_CP_COLOR_FORMAT_ARGB1555  3
-#define R300_CP_COLOR_FORMAT_RGB565    4
-#define R300_CP_COLOR_FORMAT_ARGB8888  6
-#define R300_CP_COLOR_FORMAT_RGB332    7
-#define R300_CP_COLOR_FORMAT_RGB8      9
-#define R300_CP_COLOR_FORMAT_ARGB4444  15
-
-/*
- * CP type-3 packets
- */
-#define R300_CP_CMD_BITBLT_MULTI       0xC0009B00
-
-#define R500_VAP_INDEX_OFFSET          0x208c
-
-#define R500_GA_US_VECTOR_INDEX         0x4250
-#define R500_GA_US_VECTOR_DATA          0x4254
-
-#define R500_RS_IP_0                    0x4074
-#define R500_RS_INST_0                  0x4320
-
-#define R500_US_CONFIG                  0x4600
-
-#define R500_US_FC_CTRL                        0x4624
-#define R500_US_CODE_ADDR              0x4630
-
-#define R500_RB3D_COLOR_CLEAR_VALUE_AR  0x46c0
-#define R500_RB3D_CONSTANT_COLOR_AR     0x4ef8
-
-#endif /* _R300_REG_H */
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
deleted file mode 100644 (file)
index e53158f..0000000
+++ /dev/null
@@ -1,1773 +0,0 @@
-/* radeon_cp.c -- CP support for Radeon -*- linux-c -*- */
-/*
- * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
- * Copyright 2007 Advanced Micro Devices, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Kevin E. Martin <martin@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-#include "r300_reg.h"
-
-#include "radeon_microcode.h"
-
-#define RADEON_FIFO_DEBUG      0
-
-static int radeon_do_cleanup_cp(struct drm_device * dev);
-
-static u32 R500_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
-{
-       u32 ret;
-       RADEON_WRITE(R520_MC_IND_INDEX, 0x7f0000 | (addr & 0xff));
-       ret = RADEON_READ(R520_MC_IND_DATA);
-       RADEON_WRITE(R520_MC_IND_INDEX, 0);
-       return ret;
-}
-
-static u32 RS480_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
-{
-       u32 ret;
-       RADEON_WRITE(RS480_NB_MC_INDEX, addr & 0xff);
-       ret = RADEON_READ(RS480_NB_MC_DATA);
-       RADEON_WRITE(RS480_NB_MC_INDEX, 0xff);
-       return ret;
-}
-
-static u32 RS690_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
-{
-       u32 ret;
-       RADEON_WRITE(RS690_MC_INDEX, (addr & RS690_MC_INDEX_MASK));
-       ret = RADEON_READ(RS690_MC_DATA);
-       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_MASK);
-       return ret;
-}
-
-static u32 IGP_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
-{
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
-               return RS690_READ_MCIND(dev_priv, addr);
-       else
-               return RS480_READ_MCIND(dev_priv, addr);
-}
-
-u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv)
-{
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
-               return R500_READ_MCIND(dev_priv, RV515_MC_FB_LOCATION);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
-               return RS690_READ_MCIND(dev_priv, RS690_MC_FB_LOCATION);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
-               return R500_READ_MCIND(dev_priv, R520_MC_FB_LOCATION);
-       else
-               return RADEON_READ(RADEON_MC_FB_LOCATION);
-}
-
-static void radeon_write_fb_location(drm_radeon_private_t *dev_priv, u32 fb_loc)
-{
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
-               R500_WRITE_MCIND(RV515_MC_FB_LOCATION, fb_loc);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
-               RS690_WRITE_MCIND(RS690_MC_FB_LOCATION, fb_loc);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
-               R500_WRITE_MCIND(R520_MC_FB_LOCATION, fb_loc);
-       else
-               RADEON_WRITE(RADEON_MC_FB_LOCATION, fb_loc);
-}
-
-static void radeon_write_agp_location(drm_radeon_private_t *dev_priv, u32 agp_loc)
-{
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
-               R500_WRITE_MCIND(RV515_MC_AGP_LOCATION, agp_loc);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
-               RS690_WRITE_MCIND(RS690_MC_AGP_LOCATION, agp_loc);
-       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
-               R500_WRITE_MCIND(R520_MC_AGP_LOCATION, agp_loc);
-       else
-               RADEON_WRITE(RADEON_MC_AGP_LOCATION, agp_loc);
-}
-
-static void radeon_write_agp_base(drm_radeon_private_t *dev_priv, u64 agp_base)
-{
-       u32 agp_base_hi = upper_32_bits(agp_base);
-       u32 agp_base_lo = agp_base & 0xffffffff;
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) {
-               R500_WRITE_MCIND(RV515_MC_AGP_BASE, agp_base_lo);
-               R500_WRITE_MCIND(RV515_MC_AGP_BASE_2, agp_base_hi);
-       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) {
-               RS690_WRITE_MCIND(RS690_MC_AGP_BASE, agp_base_lo);
-               RS690_WRITE_MCIND(RS690_MC_AGP_BASE_2, agp_base_hi);
-       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) {
-               R500_WRITE_MCIND(R520_MC_AGP_BASE, agp_base_lo);
-               R500_WRITE_MCIND(R520_MC_AGP_BASE_2, agp_base_hi);
-       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480) {
-               RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo);
-               RADEON_WRITE(RS480_AGP_BASE_2, 0);
-       } else {
-               RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo);
-               if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R200)
-                       RADEON_WRITE(RADEON_AGP_BASE_2, agp_base_hi);
-       }
-}
-
-static int RADEON_READ_PLL(struct drm_device * dev, int addr)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f);
-       return RADEON_READ(RADEON_CLOCK_CNTL_DATA);
-}
-
-static u32 RADEON_READ_PCIE(drm_radeon_private_t *dev_priv, int addr)
-{
-       RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff);
-       return RADEON_READ(RADEON_PCIE_DATA);
-}
-
-#if RADEON_FIFO_DEBUG
-static void radeon_status(drm_radeon_private_t * dev_priv)
-{
-       printk("%s:\n", __func__);
-       printk("RBBM_STATUS = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_RBBM_STATUS));
-       printk("CP_RB_RTPR = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR));
-       printk("CP_RB_WTPR = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR));
-       printk("AIC_CNTL = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_AIC_CNTL));
-       printk("AIC_STAT = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_AIC_STAT));
-       printk("AIC_PT_BASE = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE));
-       printk("TLB_ADDR = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR));
-       printk("TLB_DATA = 0x%08x\n",
-              (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA));
-}
-#endif
-
-/* ================================================================
- * Engine, FIFO control
- */
-
-static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
-{
-       u32 tmp;
-       int i;
-
-       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {
-               tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT);
-               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
-               RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp);
-
-               for (i = 0; i < dev_priv->usec_timeout; i++) {
-                       if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT)
-                             & RADEON_RB3D_DC_BUSY)) {
-                               return 0;
-                       }
-                       DRM_UDELAY(1);
-               }
-       } else {
-               /* 3D */
-               tmp = RADEON_READ(R300_RB3D_DSTCACHE_CTLSTAT);
-               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
-               RADEON_WRITE(R300_RB3D_DSTCACHE_CTLSTAT, tmp);
-
-               /* 2D */
-               tmp = RADEON_READ(R300_DSTCACHE_CTLSTAT);
-               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
-               RADEON_WRITE(R300_DSTCACHE_CTLSTAT, tmp);
-
-               for (i = 0; i < dev_priv->usec_timeout; i++) {
-                       if (!(RADEON_READ(R300_DSTCACHE_CTLSTAT)
-                         & RADEON_RB3D_DC_BUSY)) {
-                               return 0;
-                       }
-                       DRM_UDELAY(1);
-               }
-       }
-
-#if RADEON_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-       radeon_status(dev_priv);
-#endif
-       return -EBUSY;
-}
-
-static int radeon_do_wait_for_fifo(drm_radeon_private_t * dev_priv, int entries)
-{
-       int i;
-
-       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               int slots = (RADEON_READ(RADEON_RBBM_STATUS)
-                            & RADEON_RBBM_FIFOCNT_MASK);
-               if (slots >= entries)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if RADEON_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-       radeon_status(dev_priv);
-#endif
-       return -EBUSY;
-}
-
-static int radeon_do_wait_for_idle(drm_radeon_private_t * dev_priv)
-{
-       int i, ret;
-
-       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-       ret = radeon_do_wait_for_fifo(dev_priv, 64);
-       if (ret)
-               return ret;
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               if (!(RADEON_READ(RADEON_RBBM_STATUS)
-                     & RADEON_RBBM_ACTIVE)) {
-                       radeon_do_pixcache_flush(dev_priv);
-                       return 0;
-               }
-               DRM_UDELAY(1);
-       }
-
-#if RADEON_FIFO_DEBUG
-       DRM_ERROR("failed!\n");
-       radeon_status(dev_priv);
-#endif
-       return -EBUSY;
-}
-
-static void radeon_init_pipes(drm_radeon_private_t *dev_priv)
-{
-       uint32_t gb_tile_config, gb_pipe_sel = 0;
-
-       /* RS4xx/RS6xx/R4xx/R5xx */
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R420) {
-               gb_pipe_sel = RADEON_READ(R400_GB_PIPE_SELECT);
-               dev_priv->num_gb_pipes = ((gb_pipe_sel >> 12) & 0x3) + 1;
-       } else {
-               /* R3xx */
-               if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) ||
-                   ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350)) {
-                       dev_priv->num_gb_pipes = 2;
-               } else {
-                       /* R3Vxx */
-                       dev_priv->num_gb_pipes = 1;
-               }
-       }
-       DRM_INFO("Num pipes: %d\n", dev_priv->num_gb_pipes);
-
-       gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16 /*| R300_SUBPIXEL_1_16*/);
-
-       switch (dev_priv->num_gb_pipes) {
-       case 2: gb_tile_config |= R300_PIPE_COUNT_R300; break;
-       case 3: gb_tile_config |= R300_PIPE_COUNT_R420_3P; break;
-       case 4: gb_tile_config |= R300_PIPE_COUNT_R420; break;
-       default:
-       case 1: gb_tile_config |= R300_PIPE_COUNT_RV350; break;
-       }
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
-               RADEON_WRITE_PLL(R500_DYN_SCLK_PWMEM_PIPE, (1 | ((gb_pipe_sel >> 8) & 0xf) << 4));
-               RADEON_WRITE(R500_SU_REG_DEST, ((1 << dev_priv->num_gb_pipes) - 1));
-       }
-       RADEON_WRITE(R300_GB_TILE_CONFIG, gb_tile_config);
-       radeon_do_wait_for_idle(dev_priv);
-       RADEON_WRITE(R300_DST_PIPE_CONFIG, RADEON_READ(R300_DST_PIPE_CONFIG) | R300_PIPE_AUTO_CONFIG);
-       RADEON_WRITE(R300_RB2D_DSTCACHE_MODE, (RADEON_READ(R300_RB2D_DSTCACHE_MODE) |
-                                              R300_DC_AUTOFLUSH_ENABLE |
-                                              R300_DC_DC_DISABLE_IGNORE_PE));
-
-
-}
-
-/* ================================================================
- * CP control, initialization
- */
-
-/* Load the microcode for the CP */
-static void radeon_cp_load_microcode(drm_radeon_private_t * dev_priv)
-{
-       int i;
-       DRM_DEBUG("\n");
-
-       radeon_do_wait_for_idle(dev_priv);
-
-       RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0);
-       if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R100) ||
-           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV100) ||
-           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV200) ||
-           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS100) ||
-           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS200)) {
-               DRM_INFO("Loading R100 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    R100_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    R100_cp_microcode[i][0]);
-               }
-       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R200) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV250) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV280) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS300)) {
-               DRM_INFO("Loading R200 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    R200_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    R200_cp_microcode[i][0]);
-               }
-       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV350) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV380) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480)) {
-               DRM_INFO("Loading R300 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    R300_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    R300_cp_microcode[i][0]);
-               }
-       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV410)) {
-               DRM_INFO("Loading R400 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    R420_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    R420_cp_microcode[i][0]);
-               }
-       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) {
-               DRM_INFO("Loading RS690 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    RS690_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    RS690_cp_microcode[i][0]);
-               }
-       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R520) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV530) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R580) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV560) ||
-                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV570)) {
-               DRM_INFO("Loading R500 Microcode\n");
-               for (i = 0; i < 256; i++) {
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
-                                    R520_cp_microcode[i][1]);
-                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
-                                    R520_cp_microcode[i][0]);
-               }
-       }
-}
-
-/* Flush any pending commands to the CP.  This should only be used just
- * prior to a wait for idle, as it informs the engine that the command
- * stream is ending.
- */
-static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv)
-{
-       DRM_DEBUG("\n");
-#if 0
-       u32 tmp;
-
-       tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31);
-       RADEON_WRITE(RADEON_CP_RB_WPTR, tmp);
-#endif
-}
-
-/* Wait for the CP to go idle.
- */
-int radeon_do_cp_idle(drm_radeon_private_t * dev_priv)
-{
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(6);
-
-       RADEON_PURGE_CACHE();
-       RADEON_PURGE_ZCACHE();
-       RADEON_WAIT_UNTIL_IDLE();
-
-       ADVANCE_RING();
-       COMMIT_RING();
-
-       return radeon_do_wait_for_idle(dev_priv);
-}
-
-/* Start the Command Processor.
- */
-static void radeon_do_cp_start(drm_radeon_private_t * dev_priv)
-{
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       radeon_do_wait_for_idle(dev_priv);
-
-       RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode);
-
-       dev_priv->cp_running = 1;
-
-       BEGIN_RING(6);
-
-       RADEON_PURGE_CACHE();
-       RADEON_PURGE_ZCACHE();
-       RADEON_WAIT_UNTIL_IDLE();
-
-       ADVANCE_RING();
-       COMMIT_RING();
-}
-
-/* Reset the Command Processor.  This will not flush any pending
- * commands, so you must wait for the CP command stream to complete
- * before calling this routine.
- */
-static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv)
-{
-       u32 cur_read_ptr;
-       DRM_DEBUG("\n");
-
-       cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
-       RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
-       SET_RING_HEAD(dev_priv, cur_read_ptr);
-       dev_priv->ring.tail = cur_read_ptr;
-}
-
-/* Stop the Command Processor.  This will not flush any pending
- * commands, so you must flush the command stream and wait for the CP
- * to go idle before calling this routine.
- */
-static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv)
-{
-       DRM_DEBUG("\n");
-
-       RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS);
-
-       dev_priv->cp_running = 0;
-}
-
-/* Reset the engine.  This will stop the CP if it is running.
- */
-static int radeon_do_engine_reset(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       u32 clock_cntl_index = 0, mclk_cntl = 0, rbbm_soft_reset;
-       DRM_DEBUG("\n");
-
-       radeon_do_pixcache_flush(dev_priv);
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) {
-               /* may need something similar for newer chips */
-               clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX);
-               mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL);
-
-               RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl |
-                                                   RADEON_FORCEON_MCLKA |
-                                                   RADEON_FORCEON_MCLKB |
-                                                   RADEON_FORCEON_YCLKA |
-                                                   RADEON_FORCEON_YCLKB |
-                                                   RADEON_FORCEON_MC |
-                                                   RADEON_FORCEON_AIC));
-       }
-
-       rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET);
-
-       RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset |
-                                             RADEON_SOFT_RESET_CP |
-                                             RADEON_SOFT_RESET_HI |
-                                             RADEON_SOFT_RESET_SE |
-                                             RADEON_SOFT_RESET_RE |
-                                             RADEON_SOFT_RESET_PP |
-                                             RADEON_SOFT_RESET_E2 |
-                                             RADEON_SOFT_RESET_RB));
-       RADEON_READ(RADEON_RBBM_SOFT_RESET);
-       RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset &
-                                             ~(RADEON_SOFT_RESET_CP |
-                                               RADEON_SOFT_RESET_HI |
-                                               RADEON_SOFT_RESET_SE |
-                                               RADEON_SOFT_RESET_RE |
-                                               RADEON_SOFT_RESET_PP |
-                                               RADEON_SOFT_RESET_E2 |
-                                               RADEON_SOFT_RESET_RB)));
-       RADEON_READ(RADEON_RBBM_SOFT_RESET);
-
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) {
-               RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl);
-               RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index);
-               RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset);
-       }
-
-       /* setup the raster pipes */
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R300)
-           radeon_init_pipes(dev_priv);
-
-       /* Reset the CP ring */
-       radeon_do_cp_reset(dev_priv);
-
-       /* The CP is no longer running after an engine reset */
-       dev_priv->cp_running = 0;
-
-       /* Reset any pending vertex, indirect buffers */
-       radeon_freelist_reset(dev);
-
-       return 0;
-}
-
-static void radeon_cp_init_ring_buffer(struct drm_device * dev,
-                                      drm_radeon_private_t * dev_priv)
-{
-       u32 ring_start, cur_read_ptr;
-       u32 tmp;
-
-       /* Initialize the memory controller. With new memory map, the fb location
-        * is not changed, it should have been properly initialized already. Part
-        * of the problem is that the code below is bogus, assuming the GART is
-        * always appended to the fb which is not necessarily the case
-        */
-       if (!dev_priv->new_memmap)
-               radeon_write_fb_location(dev_priv,
-                            ((dev_priv->gart_vm_start - 1) & 0xffff0000)
-                            | (dev_priv->fb_location >> 16));
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               radeon_write_agp_base(dev_priv, dev->agp->base);
-
-               radeon_write_agp_location(dev_priv,
-                            (((dev_priv->gart_vm_start - 1 +
-                               dev_priv->gart_size) & 0xffff0000) |
-                             (dev_priv->gart_vm_start >> 16)));
-
-               ring_start = (dev_priv->cp_ring->offset
-                             - dev->agp->base
-                             + dev_priv->gart_vm_start);
-       } else
-#endif
-               ring_start = (dev_priv->cp_ring->offset
-                             - (unsigned long)dev->sg->virtual
-                             + dev_priv->gart_vm_start);
-
-       RADEON_WRITE(RADEON_CP_RB_BASE, ring_start);
-
-       /* Set the write pointer delay */
-       RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0);
-
-       /* Initialize the ring buffer's read and write pointers */
-       cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
-       RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
-       SET_RING_HEAD(dev_priv, cur_read_ptr);
-       dev_priv->ring.tail = cur_read_ptr;
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
-                            dev_priv->ring_rptr->offset
-                            - dev->agp->base + dev_priv->gart_vm_start);
-       } else
-#endif
-       {
-               struct drm_sg_mem *entry = dev->sg;
-               unsigned long tmp_ofs, page_ofs;
-
-               tmp_ofs = dev_priv->ring_rptr->offset -
-                               (unsigned long)dev->sg->virtual;
-               page_ofs = tmp_ofs >> PAGE_SHIFT;
-
-               RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]);
-               DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n",
-                         (unsigned long)entry->busaddr[page_ofs],
-                         entry->handle + tmp_ofs);
-       }
-
-       /* Set ring buffer size */
-#ifdef __BIG_ENDIAN
-       RADEON_WRITE(RADEON_CP_RB_CNTL,
-                    RADEON_BUF_SWAP_32BIT |
-                    (dev_priv->ring.fetch_size_l2ow << 18) |
-                    (dev_priv->ring.rptr_update_l2qw << 8) |
-                    dev_priv->ring.size_l2qw);
-#else
-       RADEON_WRITE(RADEON_CP_RB_CNTL,
-                    (dev_priv->ring.fetch_size_l2ow << 18) |
-                    (dev_priv->ring.rptr_update_l2qw << 8) |
-                    dev_priv->ring.size_l2qw);
-#endif
-
-       /* Start with assuming that writeback doesn't work */
-       dev_priv->writeback_works = 0;
-
-       /* Initialize the scratch register pointer.  This will cause
-        * the scratch register values to be written out to memory
-        * whenever they are updated.
-        *
-        * We simply put this behind the ring read pointer, this works
-        * with PCI GART as well as (whatever kind of) AGP GART
-        */
-       RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR)
-                    + RADEON_SCRATCH_REG_OFFSET);
-
-       dev_priv->scratch = ((__volatile__ u32 *)
-                            dev_priv->ring_rptr->handle +
-                            (RADEON_SCRATCH_REG_OFFSET / sizeof(u32)));
-
-       RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7);
-
-       /* Turn on bus mastering */
-       tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
-       RADEON_WRITE(RADEON_BUS_CNTL, tmp);
-
-       dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
-       RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
-
-       dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0;
-       RADEON_WRITE(RADEON_LAST_DISPATCH_REG,
-                    dev_priv->sarea_priv->last_dispatch);
-
-       dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
-       RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear);
-
-       radeon_do_wait_for_idle(dev_priv);
-
-       /* Sync everything up */
-       RADEON_WRITE(RADEON_ISYNC_CNTL,
-                    (RADEON_ISYNC_ANY2D_IDLE3D |
-                     RADEON_ISYNC_ANY3D_IDLE2D |
-                     RADEON_ISYNC_WAIT_IDLEGUI |
-                     RADEON_ISYNC_CPSCRATCH_IDLEGUI));
-
-}
-
-static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
-{
-       u32 tmp;
-
-       /* Writeback doesn't seem to work everywhere, test it here and possibly
-        * enable it if it appears to work
-        */
-       DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0);
-       RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef);
-
-       for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
-               if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
-                   0xdeadbeef)
-                       break;
-               DRM_UDELAY(1);
-       }
-
-       if (tmp < dev_priv->usec_timeout) {
-               dev_priv->writeback_works = 1;
-               DRM_INFO("writeback test succeeded in %d usecs\n", tmp);
-       } else {
-               dev_priv->writeback_works = 0;
-               DRM_INFO("writeback test failed\n");
-       }
-       if (radeon_no_wb == 1) {
-               dev_priv->writeback_works = 0;
-               DRM_INFO("writeback forced off\n");
-       }
-
-       if (!dev_priv->writeback_works) {
-               /* Disable writeback to avoid unnecessary bus master transfer */
-               RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) |
-                            RADEON_RB_NO_UPDATE);
-               RADEON_WRITE(RADEON_SCRATCH_UMSK, 0);
-       }
-}
-
-/* Enable or disable IGP GART on the chip */
-static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on)
-{
-       u32 temp;
-
-       if (on) {
-               DRM_DEBUG("programming igp gart %08X %08lX %08X\n",
-                         dev_priv->gart_vm_start,
-                         (long)dev_priv->gart_info.bus_addr,
-                         dev_priv->gart_size);
-
-               temp = IGP_READ_MCIND(dev_priv, RS480_MC_MISC_CNTL);
-               if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
-                       IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, (RS480_GART_INDEX_REG_EN |
-                                                            RS690_BLOCK_GFX_D3_EN));
-               else
-                       IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, RS480_GART_INDEX_REG_EN);
-
-               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN |
-                                                              RS480_VA_SIZE_32MB));
-
-               temp = IGP_READ_MCIND(dev_priv, RS480_GART_FEATURE_ID);
-               IGP_WRITE_MCIND(RS480_GART_FEATURE_ID, (RS480_HANG_EN |
-                                                       RS480_TLB_ENABLE |
-                                                       RS480_GTW_LAC_EN |
-                                                       RS480_1LEVEL_GART));
-
-               temp = dev_priv->gart_info.bus_addr & 0xfffff000;
-               temp |= (upper_32_bits(dev_priv->gart_info.bus_addr) & 0xff) << 4;
-               IGP_WRITE_MCIND(RS480_GART_BASE, temp);
-
-               temp = IGP_READ_MCIND(dev_priv, RS480_AGP_MODE_CNTL);
-               IGP_WRITE_MCIND(RS480_AGP_MODE_CNTL, ((1 << RS480_REQ_TYPE_SNOOP_SHIFT) |
-                                                     RS480_REQ_TYPE_SNOOP_DIS));
-
-               radeon_write_agp_base(dev_priv, dev_priv->gart_vm_start);
-
-               dev_priv->gart_size = 32*1024*1024;
-               temp = (((dev_priv->gart_vm_start - 1 + dev_priv->gart_size) &
-                        0xffff0000) | (dev_priv->gart_vm_start >> 16));
-
-               radeon_write_agp_location(dev_priv, temp);
-
-               temp = IGP_READ_MCIND(dev_priv, RS480_AGP_ADDRESS_SPACE_SIZE);
-               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN |
-                                                              RS480_VA_SIZE_32MB));
-
-               do {
-                       temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL);
-                       if ((temp & RS480_GART_CACHE_INVALIDATE) == 0)
-                               break;
-                       DRM_UDELAY(1);
-               } while (1);
-
-               IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL,
-                               RS480_GART_CACHE_INVALIDATE);
-
-               do {
-                       temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL);
-                       if ((temp & RS480_GART_CACHE_INVALIDATE) == 0)
-                               break;
-                       DRM_UDELAY(1);
-               } while (1);
-
-               IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL, 0);
-       } else {
-               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, 0);
-       }
-}
-
-static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on)
-{
-       u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL);
-       if (on) {
-
-               DRM_DEBUG("programming pcie %08X %08lX %08X\n",
-                         dev_priv->gart_vm_start,
-                         (long)dev_priv->gart_info.bus_addr,
-                         dev_priv->gart_size);
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO,
-                                 dev_priv->gart_vm_start);
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE,
-                                 dev_priv->gart_info.bus_addr);
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO,
-                                 dev_priv->gart_vm_start);
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO,
-                                 dev_priv->gart_vm_start +
-                                 dev_priv->gart_size - 1);
-
-               radeon_write_agp_location(dev_priv, 0xffffffc0); /* ?? */
-
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
-                                 RADEON_PCIE_TX_GART_EN);
-       } else {
-               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
-                                 tmp & ~RADEON_PCIE_TX_GART_EN);
-       }
-}
-
-/* Enable or disable PCI GART on the chip */
-static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
-{
-       u32 tmp;
-
-       if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) ||
-           (dev_priv->flags & RADEON_IS_IGPGART)) {
-               radeon_set_igpgart(dev_priv, on);
-               return;
-       }
-
-       if (dev_priv->flags & RADEON_IS_PCIE) {
-               radeon_set_pciegart(dev_priv, on);
-               return;
-       }
-
-       tmp = RADEON_READ(RADEON_AIC_CNTL);
-
-       if (on) {
-               RADEON_WRITE(RADEON_AIC_CNTL,
-                            tmp | RADEON_PCIGART_TRANSLATE_EN);
-
-               /* set PCI GART page-table base address
-                */
-               RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr);
-
-               /* set address range for PCI address translate
-                */
-               RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start);
-               RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
-                            + dev_priv->gart_size - 1);
-
-               /* Turn off AGP aperture -- is this required for PCI GART?
-                */
-               radeon_write_agp_location(dev_priv, 0xffffffc0);
-               RADEON_WRITE(RADEON_AGP_COMMAND, 0);    /* clear AGP_COMMAND */
-       } else {
-               RADEON_WRITE(RADEON_AIC_CNTL,
-                            tmp & ~RADEON_PCIGART_TRANSLATE_EN);
-       }
-}
-
-static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-
-       /* if we require new memory map but we don't have it fail */
-       if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
-               DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
-               DRM_DEBUG("Forcing AGP card to PCI mode\n");
-               dev_priv->flags &= ~RADEON_IS_AGP;
-       } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
-                  && !init->is_pci) {
-               DRM_DEBUG("Restoring AGP flag\n");
-               dev_priv->flags |= RADEON_IS_AGP;
-       }
-
-       if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) {
-               DRM_ERROR("PCI GART memory not allocated!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->usec_timeout = init->usec_timeout;
-       if (dev_priv->usec_timeout < 1 ||
-           dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
-               DRM_DEBUG("TIMEOUT problem!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       /* Enable vblank on CRTC1 for older X servers
-        */
-       dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1;
-
-       switch(init->func) {
-       case RADEON_INIT_R200_CP:
-               dev_priv->microcode_version = UCODE_R200;
-               break;
-       case RADEON_INIT_R300_CP:
-               dev_priv->microcode_version = UCODE_R300;
-               break;
-       default:
-               dev_priv->microcode_version = UCODE_R100;
-       }
-
-       dev_priv->do_boxes = 0;
-       dev_priv->cp_mode = init->cp_mode;
-
-       /* We don't support anything other than bus-mastering ring mode,
-        * but the ring can be in either AGP or PCI space for the ring
-        * read pointer.
-        */
-       if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
-           (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
-               DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       switch (init->fb_bpp) {
-       case 16:
-               dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
-               break;
-       case 32:
-       default:
-               dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
-               break;
-       }
-       dev_priv->front_offset = init->front_offset;
-       dev_priv->front_pitch = init->front_pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->back_pitch = init->back_pitch;
-
-       switch (init->depth_bpp) {
-       case 16:
-               dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
-               break;
-       case 32:
-       default:
-               dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
-               break;
-       }
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->depth_pitch = init->depth_pitch;
-
-       /* Hardware state for depth clears.  Remove this if/when we no
-        * longer clear the depth buffer with a 3D rectangle.  Hard-code
-        * all values to prevent unwanted 3D state from slipping through
-        * and screwing with the clear operation.
-        */
-       dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
-                                          (dev_priv->color_fmt << 10) |
-                                          (dev_priv->microcode_version ==
-                                           UCODE_R100 ? RADEON_ZBLOCK16 : 0));
-
-       dev_priv->depth_clear.rb3d_zstencilcntl =
-           (dev_priv->depth_fmt |
-            RADEON_Z_TEST_ALWAYS |
-            RADEON_STENCIL_TEST_ALWAYS |
-            RADEON_STENCIL_S_FAIL_REPLACE |
-            RADEON_STENCIL_ZPASS_REPLACE |
-            RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE);
-
-       dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
-                                        RADEON_BFACE_SOLID |
-                                        RADEON_FFACE_SOLID |
-                                        RADEON_FLAT_SHADE_VTX_LAST |
-                                        RADEON_DIFFUSE_SHADE_FLAT |
-                                        RADEON_ALPHA_SHADE_FLAT |
-                                        RADEON_SPECULAR_SHADE_FLAT |
-                                        RADEON_FOG_SHADE_FLAT |
-                                        RADEON_VTX_PIX_CENTER_OGL |
-                                        RADEON_ROUND_MODE_TRUNC |
-                                        RADEON_ROUND_PREC_8TH_PIX);
-
-
-       dev_priv->ring_offset = init->ring_offset;
-       dev_priv->ring_rptr_offset = init->ring_rptr_offset;
-       dev_priv->buffers_offset = init->buffers_offset;
-       dev_priv->gart_textures_offset = init->gart_textures_offset;
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("could not find sarea!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
-       if (!dev_priv->cp_ring) {
-               DRM_ERROR("could not find cp ring region!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-       dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
-       if (!dev_priv->ring_rptr) {
-               DRM_ERROR("could not find ring read pointer!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-       dev->agp_buffer_token = init->buffers_offset;
-       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
-       if (!dev->agp_buffer_map) {
-               DRM_ERROR("could not find dma buffer region!\n");
-               radeon_do_cleanup_cp(dev);
-               return -EINVAL;
-       }
-
-       if (init->gart_textures_offset) {
-               dev_priv->gart_textures =
-                   drm_core_findmap(dev, init->gart_textures_offset);
-               if (!dev_priv->gart_textures) {
-                       DRM_ERROR("could not find GART texture region!\n");
-                       radeon_do_cleanup_cp(dev);
-                       return -EINVAL;
-               }
-       }
-
-       dev_priv->sarea_priv =
-           (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle +
-                                   init->sarea_priv_offset);
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               drm_core_ioremap(dev_priv->cp_ring, dev);
-               drm_core_ioremap(dev_priv->ring_rptr, dev);
-               drm_core_ioremap(dev->agp_buffer_map, dev);
-               if (!dev_priv->cp_ring->handle ||
-                   !dev_priv->ring_rptr->handle ||
-                   !dev->agp_buffer_map->handle) {
-                       DRM_ERROR("could not find ioremap agp regions!\n");
-                       radeon_do_cleanup_cp(dev);
-                       return -EINVAL;
-               }
-       } else
-#endif
-       {
-               dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset;
-               dev_priv->ring_rptr->handle =
-                   (void *)dev_priv->ring_rptr->offset;
-               dev->agp_buffer_map->handle =
-                   (void *)dev->agp_buffer_map->offset;
-
-               DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
-                         dev_priv->cp_ring->handle);
-               DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
-                         dev_priv->ring_rptr->handle);
-               DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
-                         dev->agp_buffer_map->handle);
-       }
-
-       dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 16;
-       dev_priv->fb_size =
-               ((radeon_read_fb_location(dev_priv) & 0xffff0000u) + 0x10000)
-               - dev_priv->fb_location;
-
-       dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
-                                       ((dev_priv->front_offset
-                                         + dev_priv->fb_location) >> 10));
-
-       dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
-                                      ((dev_priv->back_offset
-                                        + dev_priv->fb_location) >> 10));
-
-       dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
-                                       ((dev_priv->depth_offset
-                                         + dev_priv->fb_location) >> 10));
-
-       dev_priv->gart_size = init->gart_size;
-
-       /* New let's set the memory map ... */
-       if (dev_priv->new_memmap) {
-               u32 base = 0;
-
-               DRM_INFO("Setting GART location based on new memory map\n");
-
-               /* If using AGP, try to locate the AGP aperture at the same
-                * location in the card and on the bus, though we have to
-                * align it down.
-                */
-#if __OS_HAS_AGP
-               if (dev_priv->flags & RADEON_IS_AGP) {
-                       base = dev->agp->base;
-                       /* Check if valid */
-                       if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location &&
-                           base < (dev_priv->fb_location + dev_priv->fb_size - 1)) {
-                               DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
-                                        dev->agp->base);
-                               base = 0;
-                       }
-               }
-#endif
-               /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
-               if (base == 0) {
-                       base = dev_priv->fb_location + dev_priv->fb_size;
-                       if (base < dev_priv->fb_location ||
-                           ((base + dev_priv->gart_size) & 0xfffffffful) < base)
-                               base = dev_priv->fb_location
-                                       - dev_priv->gart_size;
-               }
-               dev_priv->gart_vm_start = base & 0xffc00000u;
-               if (dev_priv->gart_vm_start != base)
-                       DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
-                                base, dev_priv->gart_vm_start);
-       } else {
-               DRM_INFO("Setting GART location based on old memory map\n");
-               dev_priv->gart_vm_start = dev_priv->fb_location +
-                       RADEON_READ(RADEON_CONFIG_APER_SIZE);
-       }
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP)
-               dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
-                                                - dev->agp->base
-                                                + dev_priv->gart_vm_start);
-       else
-#endif
-               dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
-                                       - (unsigned long)dev->sg->virtual
-                                       + dev_priv->gart_vm_start);
-
-       DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
-       DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start);
-       DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n",
-                 dev_priv->gart_buffers_offset);
-
-       dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
-       dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
-                             + init->ring_size / sizeof(u32));
-       dev_priv->ring.size = init->ring_size;
-       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
-
-       dev_priv->ring.rptr_update = /* init->rptr_update */ 4096;
-       dev_priv->ring.rptr_update_l2qw = drm_order( /* init->rptr_update */ 4096 / 8);
-
-       dev_priv->ring.fetch_size = /* init->fetch_size */ 32;
-       dev_priv->ring.fetch_size_l2ow = drm_order( /* init->fetch_size */ 32 / 16);
-       dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
-
-       dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               /* Turn off PCI GART */
-               radeon_set_pcigart(dev_priv, 0);
-       } else
-#endif
-       {
-               dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
-               /* if we have an offset set from userspace */
-               if (dev_priv->pcigart_offset_set) {
-                       dev_priv->gart_info.bus_addr =
-                           dev_priv->pcigart_offset + dev_priv->fb_location;
-                       dev_priv->gart_info.mapping.offset =
-                           dev_priv->pcigart_offset + dev_priv->fb_aper_offset;
-                       dev_priv->gart_info.mapping.size =
-                           dev_priv->gart_info.table_size;
-
-                       drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
-                       dev_priv->gart_info.addr =
-                           dev_priv->gart_info.mapping.handle;
-
-                       if (dev_priv->flags & RADEON_IS_PCIE)
-                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE;
-                       else
-                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
-                       dev_priv->gart_info.gart_table_location =
-                           DRM_ATI_GART_FB;
-
-                       DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
-                                 dev_priv->gart_info.addr,
-                                 dev_priv->pcigart_offset);
-               } else {
-                       if (dev_priv->flags & RADEON_IS_IGPGART)
-                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP;
-                       else
-                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
-                       dev_priv->gart_info.gart_table_location =
-                           DRM_ATI_GART_MAIN;
-                       dev_priv->gart_info.addr = NULL;
-                       dev_priv->gart_info.bus_addr = 0;
-                       if (dev_priv->flags & RADEON_IS_PCIE) {
-                               DRM_ERROR
-                                   ("Cannot use PCI Express without GART in FB memory\n");
-                               radeon_do_cleanup_cp(dev);
-                               return -EINVAL;
-                       }
-               }
-
-               if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
-                       DRM_ERROR("failed to init PCI GART!\n");
-                       radeon_do_cleanup_cp(dev);
-                       return -ENOMEM;
-               }
-
-               /* Turn on PCI GART */
-               radeon_set_pcigart(dev_priv, 1);
-       }
-
-       radeon_cp_load_microcode(dev_priv);
-       radeon_cp_init_ring_buffer(dev, dev_priv);
-
-       dev_priv->last_buf = 0;
-
-       radeon_do_engine_reset(dev);
-       radeon_test_writeback(dev_priv);
-
-       return 0;
-}
-
-static int radeon_do_cleanup_cp(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       /* Make sure interrupts are disabled here because the uninstall ioctl
-        * may not have been called from userspace and after dev_private
-        * is freed, it's too late.
-        */
-       if (dev->irq_enabled)
-               drm_irq_uninstall(dev);
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               if (dev_priv->cp_ring != NULL) {
-                       drm_core_ioremapfree(dev_priv->cp_ring, dev);
-                       dev_priv->cp_ring = NULL;
-               }
-               if (dev_priv->ring_rptr != NULL) {
-                       drm_core_ioremapfree(dev_priv->ring_rptr, dev);
-                       dev_priv->ring_rptr = NULL;
-               }
-               if (dev->agp_buffer_map != NULL) {
-                       drm_core_ioremapfree(dev->agp_buffer_map, dev);
-                       dev->agp_buffer_map = NULL;
-               }
-       } else
-#endif
-       {
-
-               if (dev_priv->gart_info.bus_addr) {
-                       /* Turn off PCI GART */
-                       radeon_set_pcigart(dev_priv, 0);
-                       if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info))
-                               DRM_ERROR("failed to cleanup PCI GART!\n");
-               }
-
-               if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
-               {
-                       drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
-                       dev_priv->gart_info.addr = 0;
-               }
-       }
-       /* only clear to the start of flags */
-       memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
-
-       return 0;
-}
-
-/* This code will reinit the Radeon CP hardware after a resume from disc.
- * AFAIK, it would be very difficult to pickle the state at suspend time, so
- * here we make sure that all Radeon hardware initialisation is re-done without
- * affecting running applications.
- *
- * Charl P. Botha <http://cpbotha.net>
- */
-static int radeon_do_resume_cp(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       if (!dev_priv) {
-               DRM_ERROR("Called with no initialization\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("Starting radeon_do_resume_cp()\n");
-
-#if __OS_HAS_AGP
-       if (dev_priv->flags & RADEON_IS_AGP) {
-               /* Turn off PCI GART */
-               radeon_set_pcigart(dev_priv, 0);
-       } else
-#endif
-       {
-               /* Turn on PCI GART */
-               radeon_set_pcigart(dev_priv, 1);
-       }
-
-       radeon_cp_load_microcode(dev_priv);
-       radeon_cp_init_ring_buffer(dev, dev_priv);
-
-       radeon_do_engine_reset(dev);
-       radeon_enable_interrupt(dev);
-
-       DRM_DEBUG("radeon_do_resume_cp() complete\n");
-
-       return 0;
-}
-
-int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_init_t *init = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (init->func == RADEON_INIT_R300_CP)
-               r300_init_reg_flags(dev);
-
-       switch (init->func) {
-       case RADEON_INIT_CP:
-       case RADEON_INIT_R200_CP:
-       case RADEON_INIT_R300_CP:
-               return radeon_do_init_cp(dev, init);
-       case RADEON_CLEANUP_CP:
-               return radeon_do_cleanup_cp(dev);
-       }
-
-       return -EINVAL;
-}
-
-int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (dev_priv->cp_running) {
-               DRM_DEBUG("while CP running\n");
-               return 0;
-       }
-       if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) {
-               DRM_DEBUG("called with bogus CP mode (%d)\n",
-                         dev_priv->cp_mode);
-               return 0;
-       }
-
-       radeon_do_cp_start(dev_priv);
-
-       return 0;
-}
-
-/* Stop the CP.  The engine must have been idled before calling this
- * routine.
- */
-int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_cp_stop_t *stop = data;
-       int ret;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv->cp_running)
-               return 0;
-
-       /* Flush any pending CP commands.  This ensures any outstanding
-        * commands are exectuted by the engine before we turn it off.
-        */
-       if (stop->flush) {
-               radeon_do_cp_flush(dev_priv);
-       }
-
-       /* If we fail to make the engine go idle, we return an error
-        * code so that the DRM ioctl wrapper can try again.
-        */
-       if (stop->idle) {
-               ret = radeon_do_cp_idle(dev_priv);
-               if (ret)
-                       return ret;
-       }
-
-       /* Finally, we can turn off the CP.  If the engine isn't idle,
-        * we will get some dropped triangles as they won't be fully
-        * rendered before the CP is shut down.
-        */
-       radeon_do_cp_stop(dev_priv);
-
-       /* Reset the engine */
-       radeon_do_engine_reset(dev);
-
-       return 0;
-}
-
-void radeon_do_release(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       int i, ret;
-
-       if (dev_priv) {
-               if (dev_priv->cp_running) {
-                       /* Stop the cp */
-                       while ((ret = radeon_do_cp_idle(dev_priv)) != 0) {
-                               DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
-#ifdef __linux__
-                               schedule();
-#else
-                               tsleep(&ret, PZERO, "rdnrel", 1);
-#endif
-                       }
-                       radeon_do_cp_stop(dev_priv);
-                       radeon_do_engine_reset(dev);
-               }
-
-               /* Disable *all* interrupts */
-               if (dev_priv->mmio)     /* remove this after permanent addmaps */
-                       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
-
-               if (dev_priv->mmio) {   /* remove all surfaces */
-                       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
-                               RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0);
-                               RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND +
-                                            16 * i, 0);
-                               RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND +
-                                            16 * i, 0);
-                       }
-               }
-
-               /* Free memory heap structures */
-               radeon_mem_takedown(&(dev_priv->gart_heap));
-               radeon_mem_takedown(&(dev_priv->fb_heap));
-
-               /* deallocate kernel resources */
-               radeon_do_cleanup_cp(dev);
-       }
-}
-
-/* Just reset the CP ring.  Called as part of an X Server engine reset.
- */
-int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_DEBUG("called before init done\n");
-               return -EINVAL;
-       }
-
-       radeon_do_cp_reset(dev_priv);
-
-       /* The CP is no longer running after an engine reset */
-       dev_priv->cp_running = 0;
-
-       return 0;
-}
-
-int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return radeon_do_cp_idle(dev_priv);
-}
-
-/* Added by Charl P. Botha to call radeon_do_resume_cp().
- */
-int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-
-       return radeon_do_resume_cp(dev);
-}
-
-int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return radeon_do_engine_reset(dev);
-}
-
-/* ================================================================
- * Fullscreen mode
- */
-
-/* KW: Deprecated to say the least:
- */
-int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       return 0;
-}
-
-/* ================================================================
- * Freelist management
- */
-
-/* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
- *   bufs until freelist code is used.  Note this hides a problem with
- *   the scratch register * (used to keep track of last buffer
- *   completed) being written to before * the last buffer has actually
- *   completed rendering.
- *
- * KW:  It's also a good way to find free buffers quickly.
- *
- * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
- * sleep.  However, bugs in older versions of radeon_accel.c mean that
- * we essentially have to do this, else old clients will break.
- *
- * However, it does leave open a potential deadlock where all the
- * buffers are held by other clients, which can't release them because
- * they can't get the lock.
- */
-
-struct drm_buf *radeon_freelist_get(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_buf_priv_t *buf_priv;
-       struct drm_buf *buf;
-       int i, t;
-       int start;
-
-       if (++dev_priv->last_buf >= dma->buf_count)
-               dev_priv->last_buf = 0;
-
-       start = dev_priv->last_buf;
-
-       for (t = 0; t < dev_priv->usec_timeout; t++) {
-               u32 done_age = GET_SCRATCH(1);
-               DRM_DEBUG("done_age = %d\n", done_age);
-               for (i = start; i < dma->buf_count; i++) {
-                       buf = dma->buflist[i];
-                       buf_priv = buf->dev_private;
-                       if (buf->file_priv == NULL || (buf->pending &&
-                                                      buf_priv->age <=
-                                                      done_age)) {
-                               dev_priv->stats.requested_bufs++;
-                               buf->pending = 0;
-                               return buf;
-                       }
-                       start = 0;
-               }
-
-               if (t) {
-                       DRM_UDELAY(1);
-                       dev_priv->stats.freelist_loops++;
-               }
-       }
-
-       DRM_DEBUG("returning NULL!\n");
-       return NULL;
-}
-
-#if 0
-struct drm_buf *radeon_freelist_get(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_buf_priv_t *buf_priv;
-       struct drm_buf *buf;
-       int i, t;
-       int start;
-       u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
-
-       if (++dev_priv->last_buf >= dma->buf_count)
-               dev_priv->last_buf = 0;
-
-       start = dev_priv->last_buf;
-       dev_priv->stats.freelist_loops++;
-
-       for (t = 0; t < 2; t++) {
-               for (i = start; i < dma->buf_count; i++) {
-                       buf = dma->buflist[i];
-                       buf_priv = buf->dev_private;
-                       if (buf->file_priv == 0 || (buf->pending &&
-                                                   buf_priv->age <=
-                                                   done_age)) {
-                               dev_priv->stats.requested_bufs++;
-                               buf->pending = 0;
-                               return buf;
-                       }
-               }
-               start = 0;
-       }
-
-       return NULL;
-}
-#endif
-
-void radeon_freelist_reset(struct drm_device * dev)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       int i;
-
-       dev_priv->last_buf = 0;
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
-               buf_priv->age = 0;
-       }
-}
-
-/* ================================================================
- * CP command submission
- */
-
-int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n)
-{
-       drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
-       int i;
-       u32 last_head = GET_RING_HEAD(dev_priv);
-
-       for (i = 0; i < dev_priv->usec_timeout; i++) {
-               u32 head = GET_RING_HEAD(dev_priv);
-
-               ring->space = (head - ring->tail) * sizeof(u32);
-               if (ring->space <= 0)
-                       ring->space += ring->size;
-               if (ring->space > n)
-                       return 0;
-
-               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-               if (head != last_head)
-                       i = 0;
-               last_head = head;
-
-               DRM_UDELAY(1);
-       }
-
-       /* FIXME: This return value is ignored in the BEGIN_RING macro! */
-#if RADEON_FIFO_DEBUG
-       radeon_status(dev_priv);
-       DRM_ERROR("failed!\n");
-#endif
-       return -EBUSY;
-}
-
-static int radeon_cp_get_buffers(struct drm_device *dev,
-                                struct drm_file *file_priv,
-                                struct drm_dma * d)
-{
-       int i;
-       struct drm_buf *buf;
-
-       for (i = d->granted_count; i < d->request_count; i++) {
-               buf = radeon_freelist_get(dev);
-               if (!buf)
-                       return -EBUSY;  /* NOTE: broken client */
-
-               buf->file_priv = file_priv;
-
-               if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
-                                    sizeof(buf->idx)))
-                       return -EFAULT;
-               if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
-                                    sizeof(buf->total)))
-                       return -EFAULT;
-
-               d->granted_count++;
-       }
-       return 0;
-}
-
-int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       int ret = 0;
-       struct drm_dma *d = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* Please don't send us buffers.
-        */
-       if (d->send_count != 0) {
-               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
-                         DRM_CURRENTPID, d->send_count);
-               return -EINVAL;
-       }
-
-       /* We'll send you buffers.
-        */
-       if (d->request_count < 0 || d->request_count > dma->buf_count) {
-               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
-                         DRM_CURRENTPID, d->request_count, dma->buf_count);
-               return -EINVAL;
-       }
-
-       d->granted_count = 0;
-
-       if (d->request_count) {
-               ret = radeon_cp_get_buffers(dev, file_priv, d);
-       }
-
-       return ret;
-}
-
-int radeon_driver_load(struct drm_device *dev, unsigned long flags)
-{
-       drm_radeon_private_t *dev_priv;
-       int ret = 0;
-
-       dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv, 0, sizeof(drm_radeon_private_t));
-       dev->dev_private = (void *)dev_priv;
-       dev_priv->flags = flags;
-
-       switch (flags & RADEON_FAMILY_MASK) {
-       case CHIP_R100:
-       case CHIP_RV200:
-       case CHIP_R200:
-       case CHIP_R300:
-       case CHIP_R350:
-       case CHIP_R420:
-       case CHIP_RV410:
-       case CHIP_RV515:
-       case CHIP_R520:
-       case CHIP_RV570:
-       case CHIP_R580:
-               dev_priv->flags |= RADEON_HAS_HIERZ;
-               break;
-       default:
-               /* all other chips have no hierarchical z buffer */
-               break;
-       }
-
-       if (drm_device_is_agp(dev))
-               dev_priv->flags |= RADEON_IS_AGP;
-       else if (drm_device_is_pcie(dev))
-               dev_priv->flags |= RADEON_IS_PCIE;
-       else
-               dev_priv->flags |= RADEON_IS_PCI;
-
-       DRM_DEBUG("%s card detected\n",
-                 ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI"))));
-       return ret;
-}
-
-/* Create mappings for registers and framebuffer so userland doesn't necessarily
- * have to find them.
- */
-int radeon_driver_firstopen(struct drm_device *dev)
-{
-       int ret;
-       drm_local_map_t *map;
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
-
-       ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
-                        drm_get_resource_len(dev, 2), _DRM_REGISTERS,
-                        _DRM_READ_ONLY, &dev_priv->mmio);
-       if (ret != 0)
-               return ret;
-
-       dev_priv->fb_aper_offset = drm_get_resource_start(dev, 0);
-       ret = drm_addmap(dev, dev_priv->fb_aper_offset,
-                        drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
-                        _DRM_WRITE_COMBINING, &map);
-       if (ret != 0)
-               return ret;
-
-       return 0;
-}
-
-int radeon_driver_unload(struct drm_device *dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-       drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
-
-       dev->dev_private = NULL;
-       return 0;
-}
diff --git a/drivers/char/drm/radeon_drm.h b/drivers/char/drm/radeon_drm.h
deleted file mode 100644 (file)
index 73ff51f..0000000
+++ /dev/null
@@ -1,749 +0,0 @@
-/* radeon_drm.h -- Public header for the radeon driver -*- linux-c -*-
- *
- * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
- * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Kevin E. Martin <martin@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- *    Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#ifndef __RADEON_DRM_H__
-#define __RADEON_DRM_H__
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the X server file (radeon_sarea.h)
- */
-#ifndef __RADEON_SAREA_DEFINES__
-#define __RADEON_SAREA_DEFINES__
-
-/* Old style state flags, required for sarea interface (1.1 and 1.2
- * clears) and 1.2 drm_vertex2 ioctl.
- */
-#define RADEON_UPLOAD_CONTEXT          0x00000001
-#define RADEON_UPLOAD_VERTFMT          0x00000002
-#define RADEON_UPLOAD_LINE             0x00000004
-#define RADEON_UPLOAD_BUMPMAP          0x00000008
-#define RADEON_UPLOAD_MASKS            0x00000010
-#define RADEON_UPLOAD_VIEWPORT         0x00000020
-#define RADEON_UPLOAD_SETUP            0x00000040
-#define RADEON_UPLOAD_TCL              0x00000080
-#define RADEON_UPLOAD_MISC             0x00000100
-#define RADEON_UPLOAD_TEX0             0x00000200
-#define RADEON_UPLOAD_TEX1             0x00000400
-#define RADEON_UPLOAD_TEX2             0x00000800
-#define RADEON_UPLOAD_TEX0IMAGES       0x00001000
-#define RADEON_UPLOAD_TEX1IMAGES       0x00002000
-#define RADEON_UPLOAD_TEX2IMAGES       0x00004000
-#define RADEON_UPLOAD_CLIPRECTS                0x00008000      /* handled client-side */
-#define RADEON_REQUIRE_QUIESCENCE      0x00010000
-#define RADEON_UPLOAD_ZBIAS            0x00020000      /* version 1.2 and newer */
-#define RADEON_UPLOAD_ALL              0x003effff
-#define RADEON_UPLOAD_CONTEXT_ALL       0x003e01ff
-
-/* New style per-packet identifiers for use in cmd_buffer ioctl with
- * the RADEON_EMIT_PACKET command.  Comments relate new packets to old
- * state bits and the packet size:
- */
-#define RADEON_EMIT_PP_MISC                         0  /* context/7 */
-#define RADEON_EMIT_PP_CNTL                         1  /* context/3 */
-#define RADEON_EMIT_RB3D_COLORPITCH                 2  /* context/1 */
-#define RADEON_EMIT_RE_LINE_PATTERN                 3  /* line/2 */
-#define RADEON_EMIT_SE_LINE_WIDTH                   4  /* line/1 */
-#define RADEON_EMIT_PP_LUM_MATRIX                   5  /* bumpmap/1 */
-#define RADEON_EMIT_PP_ROT_MATRIX_0                 6  /* bumpmap/2 */
-#define RADEON_EMIT_RB3D_STENCILREFMASK             7  /* masks/3 */
-#define RADEON_EMIT_SE_VPORT_XSCALE                 8  /* viewport/6 */
-#define RADEON_EMIT_SE_CNTL                         9  /* setup/2 */
-#define RADEON_EMIT_SE_CNTL_STATUS                  10 /* setup/1 */
-#define RADEON_EMIT_RE_MISC                         11 /* misc/1 */
-#define RADEON_EMIT_PP_TXFILTER_0                   12 /* tex0/6 */
-#define RADEON_EMIT_PP_BORDER_COLOR_0               13 /* tex0/1 */
-#define RADEON_EMIT_PP_TXFILTER_1                   14 /* tex1/6 */
-#define RADEON_EMIT_PP_BORDER_COLOR_1               15 /* tex1/1 */
-#define RADEON_EMIT_PP_TXFILTER_2                   16 /* tex2/6 */
-#define RADEON_EMIT_PP_BORDER_COLOR_2               17 /* tex2/1 */
-#define RADEON_EMIT_SE_ZBIAS_FACTOR                 18 /* zbias/2 */
-#define RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT           19 /* tcl/11 */
-#define RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED   20 /* material/17 */
-#define R200_EMIT_PP_TXCBLEND_0                     21 /* tex0/4 */
-#define R200_EMIT_PP_TXCBLEND_1                     22 /* tex1/4 */
-#define R200_EMIT_PP_TXCBLEND_2                     23 /* tex2/4 */
-#define R200_EMIT_PP_TXCBLEND_3                     24 /* tex3/4 */
-#define R200_EMIT_PP_TXCBLEND_4                     25 /* tex4/4 */
-#define R200_EMIT_PP_TXCBLEND_5                     26 /* tex5/4 */
-#define R200_EMIT_PP_TXCBLEND_6                     27 /* /4 */
-#define R200_EMIT_PP_TXCBLEND_7                     28 /* /4 */
-#define R200_EMIT_TCL_LIGHT_MODEL_CTL_0             29 /* tcl/7 */
-#define R200_EMIT_TFACTOR_0                         30 /* tf/7 */
-#define R200_EMIT_VTX_FMT_0                         31 /* vtx/5 */
-#define R200_EMIT_VAP_CTL                           32 /* vap/1 */
-#define R200_EMIT_MATRIX_SELECT_0                   33 /* msl/5 */
-#define R200_EMIT_TEX_PROC_CTL_2                    34 /* tcg/5 */
-#define R200_EMIT_TCL_UCP_VERT_BLEND_CTL            35 /* tcl/1 */
-#define R200_EMIT_PP_TXFILTER_0                     36 /* tex0/6 */
-#define R200_EMIT_PP_TXFILTER_1                     37 /* tex1/6 */
-#define R200_EMIT_PP_TXFILTER_2                     38 /* tex2/6 */
-#define R200_EMIT_PP_TXFILTER_3                     39 /* tex3/6 */
-#define R200_EMIT_PP_TXFILTER_4                     40 /* tex4/6 */
-#define R200_EMIT_PP_TXFILTER_5                     41 /* tex5/6 */
-#define R200_EMIT_PP_TXOFFSET_0                     42 /* tex0/1 */
-#define R200_EMIT_PP_TXOFFSET_1                     43 /* tex1/1 */
-#define R200_EMIT_PP_TXOFFSET_2                     44 /* tex2/1 */
-#define R200_EMIT_PP_TXOFFSET_3                     45 /* tex3/1 */
-#define R200_EMIT_PP_TXOFFSET_4                     46 /* tex4/1 */
-#define R200_EMIT_PP_TXOFFSET_5                     47 /* tex5/1 */
-#define R200_EMIT_VTE_CNTL                          48 /* vte/1 */
-#define R200_EMIT_OUTPUT_VTX_COMP_SEL               49 /* vtx/1 */
-#define R200_EMIT_PP_TAM_DEBUG3                     50 /* tam/1 */
-#define R200_EMIT_PP_CNTL_X                         51 /* cst/1 */
-#define R200_EMIT_RB3D_DEPTHXY_OFFSET               52 /* cst/1 */
-#define R200_EMIT_RE_AUX_SCISSOR_CNTL               53 /* cst/1 */
-#define R200_EMIT_RE_SCISSOR_TL_0                   54 /* cst/2 */
-#define R200_EMIT_RE_SCISSOR_TL_1                   55 /* cst/2 */
-#define R200_EMIT_RE_SCISSOR_TL_2                   56 /* cst/2 */
-#define R200_EMIT_SE_VAP_CNTL_STATUS                57 /* cst/1 */
-#define R200_EMIT_SE_VTX_STATE_CNTL                 58 /* cst/1 */
-#define R200_EMIT_RE_POINTSIZE                      59 /* cst/1 */
-#define R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0       60 /* cst/4 */
-#define R200_EMIT_PP_CUBIC_FACES_0                  61
-#define R200_EMIT_PP_CUBIC_OFFSETS_0                62
-#define R200_EMIT_PP_CUBIC_FACES_1                  63
-#define R200_EMIT_PP_CUBIC_OFFSETS_1                64
-#define R200_EMIT_PP_CUBIC_FACES_2                  65
-#define R200_EMIT_PP_CUBIC_OFFSETS_2                66
-#define R200_EMIT_PP_CUBIC_FACES_3                  67
-#define R200_EMIT_PP_CUBIC_OFFSETS_3                68
-#define R200_EMIT_PP_CUBIC_FACES_4                  69
-#define R200_EMIT_PP_CUBIC_OFFSETS_4                70
-#define R200_EMIT_PP_CUBIC_FACES_5                  71
-#define R200_EMIT_PP_CUBIC_OFFSETS_5                72
-#define RADEON_EMIT_PP_TEX_SIZE_0                   73
-#define RADEON_EMIT_PP_TEX_SIZE_1                   74
-#define RADEON_EMIT_PP_TEX_SIZE_2                   75
-#define R200_EMIT_RB3D_BLENDCOLOR                   76
-#define R200_EMIT_TCL_POINT_SPRITE_CNTL             77
-#define RADEON_EMIT_PP_CUBIC_FACES_0                78
-#define RADEON_EMIT_PP_CUBIC_OFFSETS_T0             79
-#define RADEON_EMIT_PP_CUBIC_FACES_1                80
-#define RADEON_EMIT_PP_CUBIC_OFFSETS_T1             81
-#define RADEON_EMIT_PP_CUBIC_FACES_2                82
-#define RADEON_EMIT_PP_CUBIC_OFFSETS_T2             83
-#define R200_EMIT_PP_TRI_PERF_CNTL                  84
-#define R200_EMIT_PP_AFS_0                          85
-#define R200_EMIT_PP_AFS_1                          86
-#define R200_EMIT_ATF_TFACTOR                       87
-#define R200_EMIT_PP_TXCTLALL_0                     88
-#define R200_EMIT_PP_TXCTLALL_1                     89
-#define R200_EMIT_PP_TXCTLALL_2                     90
-#define R200_EMIT_PP_TXCTLALL_3                     91
-#define R200_EMIT_PP_TXCTLALL_4                     92
-#define R200_EMIT_PP_TXCTLALL_5                     93
-#define R200_EMIT_VAP_PVS_CNTL                      94
-#define RADEON_MAX_STATE_PACKETS                    95
-
-/* Commands understood by cmd_buffer ioctl.  More can be added but
- * obviously these can't be removed or changed:
- */
-#define RADEON_CMD_PACKET      1       /* emit one of the register packets above */
-#define RADEON_CMD_SCALARS     2       /* emit scalar data */
-#define RADEON_CMD_VECTORS     3       /* emit vector data */
-#define RADEON_CMD_DMA_DISCARD 4       /* discard current dma buf */
-#define RADEON_CMD_PACKET3     5       /* emit hw packet */
-#define RADEON_CMD_PACKET3_CLIP 6      /* emit hw packet wrapped in cliprects */
-#define RADEON_CMD_SCALARS2     7      /* r200 stopgap */
-#define RADEON_CMD_WAIT         8      /* emit hw wait commands -- note:
-                                        *  doesn't make the cpu wait, just
-                                        *  the graphics hardware */
-#define RADEON_CMD_VECLINEAR   9       /* another r200 stopgap */
-
-typedef union {
-       int i;
-       struct {
-               unsigned char cmd_type, pad0, pad1, pad2;
-       } header;
-       struct {
-               unsigned char cmd_type, packet_id, pad0, pad1;
-       } packet;
-       struct {
-               unsigned char cmd_type, offset, stride, count;
-       } scalars;
-       struct {
-               unsigned char cmd_type, offset, stride, count;
-       } vectors;
-       struct {
-               unsigned char cmd_type, addr_lo, addr_hi, count;
-       } veclinear;
-       struct {
-               unsigned char cmd_type, buf_idx, pad0, pad1;
-       } dma;
-       struct {
-               unsigned char cmd_type, flags, pad0, pad1;
-       } wait;
-} drm_radeon_cmd_header_t;
-
-#define RADEON_WAIT_2D  0x1
-#define RADEON_WAIT_3D  0x2
-
-/* Allowed parameters for R300_CMD_PACKET3
- */
-#define R300_CMD_PACKET3_CLEAR         0
-#define R300_CMD_PACKET3_RAW           1
-
-/* Commands understood by cmd_buffer ioctl for R300.
- * The interface has not been stabilized, so some of these may be removed
- * and eventually reordered before stabilization.
- */
-#define R300_CMD_PACKET0               1
-#define R300_CMD_VPU                   2       /* emit vertex program upload */
-#define R300_CMD_PACKET3               3       /* emit a packet3 */
-#define R300_CMD_END3D                 4       /* emit sequence ending 3d rendering */
-#define R300_CMD_CP_DELAY              5
-#define R300_CMD_DMA_DISCARD           6
-#define R300_CMD_WAIT                  7
-#      define R300_WAIT_2D             0x1
-#      define R300_WAIT_3D             0x2
-/* these two defines are DOING IT WRONG - however
- * we have userspace which relies on using these.
- * The wait interface is backwards compat new 
- * code should use the NEW_WAIT defines below
- * THESE ARE NOT BIT FIELDS
- */
-#      define R300_WAIT_2D_CLEAN       0x3
-#      define R300_WAIT_3D_CLEAN       0x4
-
-#      define R300_NEW_WAIT_2D_3D      0x3
-#      define R300_NEW_WAIT_2D_2D_CLEAN        0x4
-#      define R300_NEW_WAIT_3D_3D_CLEAN        0x6
-#      define R300_NEW_WAIT_2D_2D_CLEAN_3D_3D_CLEAN    0x8
-
-#define R300_CMD_SCRATCH               8
-#define R300_CMD_R500FP                 9
-
-typedef union {
-       unsigned int u;
-       struct {
-               unsigned char cmd_type, pad0, pad1, pad2;
-       } header;
-       struct {
-               unsigned char cmd_type, count, reglo, reghi;
-       } packet0;
-       struct {
-               unsigned char cmd_type, count, adrlo, adrhi;
-       } vpu;
-       struct {
-               unsigned char cmd_type, packet, pad0, pad1;
-       } packet3;
-       struct {
-               unsigned char cmd_type, packet;
-               unsigned short count;   /* amount of packet2 to emit */
-       } delay;
-       struct {
-               unsigned char cmd_type, buf_idx, pad0, pad1;
-       } dma;
-       struct {
-               unsigned char cmd_type, flags, pad0, pad1;
-       } wait;
-       struct {
-               unsigned char cmd_type, reg, n_bufs, flags;
-       } scratch;
-       struct {
-               unsigned char cmd_type, count, adrlo, adrhi_flags;
-       } r500fp;
-} drm_r300_cmd_header_t;
-
-#define RADEON_FRONT                   0x1
-#define RADEON_BACK                    0x2
-#define RADEON_DEPTH                   0x4
-#define RADEON_STENCIL                 0x8
-#define RADEON_CLEAR_FASTZ             0x80000000
-#define RADEON_USE_HIERZ               0x40000000
-#define RADEON_USE_COMP_ZBUF           0x20000000
-
-#define R500FP_CONSTANT_TYPE  (1 << 1)
-#define R500FP_CONSTANT_CLAMP (1 << 2)
-
-/* Primitive types
- */
-#define RADEON_POINTS                  0x1
-#define RADEON_LINES                   0x2
-#define RADEON_LINE_STRIP              0x3
-#define RADEON_TRIANGLES               0x4
-#define RADEON_TRIANGLE_FAN            0x5
-#define RADEON_TRIANGLE_STRIP          0x6
-
-/* Vertex/indirect buffer size
- */
-#define RADEON_BUFFER_SIZE             65536
-
-/* Byte offsets for indirect buffer data
- */
-#define RADEON_INDEX_PRIM_OFFSET       20
-
-#define RADEON_SCRATCH_REG_OFFSET      32
-
-#define RADEON_NR_SAREA_CLIPRECTS      12
-
-/* There are 2 heaps (local/GART).  Each region within a heap is a
- * minimum of 64k, and there are at most 64 of them per heap.
- */
-#define RADEON_LOCAL_TEX_HEAP          0
-#define RADEON_GART_TEX_HEAP           1
-#define RADEON_NR_TEX_HEAPS            2
-#define RADEON_NR_TEX_REGIONS          64
-#define RADEON_LOG_TEX_GRANULARITY     16
-
-#define RADEON_MAX_TEXTURE_LEVELS      12
-#define RADEON_MAX_TEXTURE_UNITS       3
-
-#define RADEON_MAX_SURFACES            8
-
-/* Blits have strict offset rules.  All blit offset must be aligned on
- * a 1K-byte boundary.
- */
-#define RADEON_OFFSET_SHIFT             10
-#define RADEON_OFFSET_ALIGN             (1 << RADEON_OFFSET_SHIFT)
-#define RADEON_OFFSET_MASK              (RADEON_OFFSET_ALIGN - 1)
-
-#endif                         /* __RADEON_SAREA_DEFINES__ */
-
-typedef struct {
-       unsigned int red;
-       unsigned int green;
-       unsigned int blue;
-       unsigned int alpha;
-} radeon_color_regs_t;
-
-typedef struct {
-       /* Context state */
-       unsigned int pp_misc;   /* 0x1c14 */
-       unsigned int pp_fog_color;
-       unsigned int re_solid_color;
-       unsigned int rb3d_blendcntl;
-       unsigned int rb3d_depthoffset;
-       unsigned int rb3d_depthpitch;
-       unsigned int rb3d_zstencilcntl;
-
-       unsigned int pp_cntl;   /* 0x1c38 */
-       unsigned int rb3d_cntl;
-       unsigned int rb3d_coloroffset;
-       unsigned int re_width_height;
-       unsigned int rb3d_colorpitch;
-       unsigned int se_cntl;
-
-       /* Vertex format state */
-       unsigned int se_coord_fmt;      /* 0x1c50 */
-
-       /* Line state */
-       unsigned int re_line_pattern;   /* 0x1cd0 */
-       unsigned int re_line_state;
-
-       unsigned int se_line_width;     /* 0x1db8 */
-
-       /* Bumpmap state */
-       unsigned int pp_lum_matrix;     /* 0x1d00 */
-
-       unsigned int pp_rot_matrix_0;   /* 0x1d58 */
-       unsigned int pp_rot_matrix_1;
-
-       /* Mask state */
-       unsigned int rb3d_stencilrefmask;       /* 0x1d7c */
-       unsigned int rb3d_ropcntl;
-       unsigned int rb3d_planemask;
-
-       /* Viewport state */
-       unsigned int se_vport_xscale;   /* 0x1d98 */
-       unsigned int se_vport_xoffset;
-       unsigned int se_vport_yscale;
-       unsigned int se_vport_yoffset;
-       unsigned int se_vport_zscale;
-       unsigned int se_vport_zoffset;
-
-       /* Setup state */
-       unsigned int se_cntl_status;    /* 0x2140 */
-
-       /* Misc state */
-       unsigned int re_top_left;       /* 0x26c0 */
-       unsigned int re_misc;
-} drm_radeon_context_regs_t;
-
-typedef struct {
-       /* Zbias state */
-       unsigned int se_zbias_factor;   /* 0x1dac */
-       unsigned int se_zbias_constant;
-} drm_radeon_context2_regs_t;
-
-/* Setup registers for each texture unit
- */
-typedef struct {
-       unsigned int pp_txfilter;
-       unsigned int pp_txformat;
-       unsigned int pp_txoffset;
-       unsigned int pp_txcblend;
-       unsigned int pp_txablend;
-       unsigned int pp_tfactor;
-       unsigned int pp_border_color;
-} drm_radeon_texture_regs_t;
-
-typedef struct {
-       unsigned int start;
-       unsigned int finish;
-       unsigned int prim:8;
-       unsigned int stateidx:8;
-       unsigned int numverts:16;       /* overloaded as offset/64 for elt prims */
-       unsigned int vc_format; /* vertex format */
-} drm_radeon_prim_t;
-
-typedef struct {
-       drm_radeon_context_regs_t context;
-       drm_radeon_texture_regs_t tex[RADEON_MAX_TEXTURE_UNITS];
-       drm_radeon_context2_regs_t context2;
-       unsigned int dirty;
-} drm_radeon_state_t;
-
-typedef struct {
-       /* The channel for communication of state information to the
-        * kernel on firing a vertex buffer with either of the
-        * obsoleted vertex/index ioctls.
-        */
-       drm_radeon_context_regs_t context_state;
-       drm_radeon_texture_regs_t tex_state[RADEON_MAX_TEXTURE_UNITS];
-       unsigned int dirty;
-       unsigned int vertsize;
-       unsigned int vc_format;
-
-       /* The current cliprects, or a subset thereof.
-        */
-       struct drm_clip_rect boxes[RADEON_NR_SAREA_CLIPRECTS];
-       unsigned int nbox;
-
-       /* Counters for client-side throttling of rendering clients.
-        */
-       unsigned int last_frame;
-       unsigned int last_dispatch;
-       unsigned int last_clear;
-
-       struct drm_tex_region tex_list[RADEON_NR_TEX_HEAPS][RADEON_NR_TEX_REGIONS +
-                                                      1];
-       unsigned int tex_age[RADEON_NR_TEX_HEAPS];
-       int ctx_owner;
-       int pfState;            /* number of 3d windows (0,1,2ormore) */
-       int pfCurrentPage;      /* which buffer is being displayed? */
-       int crtc2_base;         /* CRTC2 frame offset */
-       int tiling_enabled;     /* set by drm, read by 2d + 3d clients */
-} drm_radeon_sarea_t;
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the Xserver file (xf86drmRadeon.h)
- *
- * KW: actually it's illegal to change any of this (backwards compatibility).
- */
-
-/* Radeon specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_RADEON_CP_INIT    0x00
-#define DRM_RADEON_CP_START   0x01
-#define DRM_RADEON_CP_STOP    0x02
-#define DRM_RADEON_CP_RESET   0x03
-#define DRM_RADEON_CP_IDLE    0x04
-#define DRM_RADEON_RESET      0x05
-#define DRM_RADEON_FULLSCREEN 0x06
-#define DRM_RADEON_SWAP       0x07
-#define DRM_RADEON_CLEAR      0x08
-#define DRM_RADEON_VERTEX     0x09
-#define DRM_RADEON_INDICES    0x0A
-#define DRM_RADEON_NOT_USED
-#define DRM_RADEON_STIPPLE    0x0C
-#define DRM_RADEON_INDIRECT   0x0D
-#define DRM_RADEON_TEXTURE    0x0E
-#define DRM_RADEON_VERTEX2    0x0F
-#define DRM_RADEON_CMDBUF     0x10
-#define DRM_RADEON_GETPARAM   0x11
-#define DRM_RADEON_FLIP       0x12
-#define DRM_RADEON_ALLOC      0x13
-#define DRM_RADEON_FREE       0x14
-#define DRM_RADEON_INIT_HEAP  0x15
-#define DRM_RADEON_IRQ_EMIT   0x16
-#define DRM_RADEON_IRQ_WAIT   0x17
-#define DRM_RADEON_CP_RESUME  0x18
-#define DRM_RADEON_SETPARAM   0x19
-#define DRM_RADEON_SURF_ALLOC 0x1a
-#define DRM_RADEON_SURF_FREE  0x1b
-
-#define DRM_IOCTL_RADEON_CP_INIT    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_INIT, drm_radeon_init_t)
-#define DRM_IOCTL_RADEON_CP_START   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_START)
-#define DRM_IOCTL_RADEON_CP_STOP    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_STOP, drm_radeon_cp_stop_t)
-#define DRM_IOCTL_RADEON_CP_RESET   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_RESET)
-#define DRM_IOCTL_RADEON_CP_IDLE    DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_IDLE)
-#define DRM_IOCTL_RADEON_RESET      DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_RESET)
-#define DRM_IOCTL_RADEON_FULLSCREEN DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_FULLSCREEN, drm_radeon_fullscreen_t)
-#define DRM_IOCTL_RADEON_SWAP       DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_SWAP)
-#define DRM_IOCTL_RADEON_CLEAR      DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CLEAR, drm_radeon_clear_t)
-#define DRM_IOCTL_RADEON_VERTEX     DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_VERTEX, drm_radeon_vertex_t)
-#define DRM_IOCTL_RADEON_INDICES    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_INDICES, drm_radeon_indices_t)
-#define DRM_IOCTL_RADEON_STIPPLE    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_STIPPLE, drm_radeon_stipple_t)
-#define DRM_IOCTL_RADEON_INDIRECT   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_INDIRECT, drm_radeon_indirect_t)
-#define DRM_IOCTL_RADEON_TEXTURE    DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_TEXTURE, drm_radeon_texture_t)
-#define DRM_IOCTL_RADEON_VERTEX2    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_VERTEX2, drm_radeon_vertex2_t)
-#define DRM_IOCTL_RADEON_CMDBUF     DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CMDBUF, drm_radeon_cmd_buffer_t)
-#define DRM_IOCTL_RADEON_GETPARAM   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GETPARAM, drm_radeon_getparam_t)
-#define DRM_IOCTL_RADEON_FLIP       DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_FLIP)
-#define DRM_IOCTL_RADEON_ALLOC      DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_ALLOC, drm_radeon_mem_alloc_t)
-#define DRM_IOCTL_RADEON_FREE       DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_FREE, drm_radeon_mem_free_t)
-#define DRM_IOCTL_RADEON_INIT_HEAP  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_INIT_HEAP, drm_radeon_mem_init_heap_t)
-#define DRM_IOCTL_RADEON_IRQ_EMIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_IRQ_EMIT, drm_radeon_irq_emit_t)
-#define DRM_IOCTL_RADEON_IRQ_WAIT   DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_IRQ_WAIT, drm_radeon_irq_wait_t)
-#define DRM_IOCTL_RADEON_CP_RESUME  DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_RESUME)
-#define DRM_IOCTL_RADEON_SETPARAM   DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SETPARAM, drm_radeon_setparam_t)
-#define DRM_IOCTL_RADEON_SURF_ALLOC DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_ALLOC, drm_radeon_surface_alloc_t)
-#define DRM_IOCTL_RADEON_SURF_FREE  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_FREE, drm_radeon_surface_free_t)
-
-typedef struct drm_radeon_init {
-       enum {
-               RADEON_INIT_CP = 0x01,
-               RADEON_CLEANUP_CP = 0x02,
-               RADEON_INIT_R200_CP = 0x03,
-               RADEON_INIT_R300_CP = 0x04
-       } func;
-       unsigned long sarea_priv_offset;
-       int is_pci;
-       int cp_mode;
-       int gart_size;
-       int ring_size;
-       int usec_timeout;
-
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-
-       unsigned long fb_offset;
-       unsigned long mmio_offset;
-       unsigned long ring_offset;
-       unsigned long ring_rptr_offset;
-       unsigned long buffers_offset;
-       unsigned long gart_textures_offset;
-} drm_radeon_init_t;
-
-typedef struct drm_radeon_cp_stop {
-       int flush;
-       int idle;
-} drm_radeon_cp_stop_t;
-
-typedef struct drm_radeon_fullscreen {
-       enum {
-               RADEON_INIT_FULLSCREEN = 0x01,
-               RADEON_CLEANUP_FULLSCREEN = 0x02
-       } func;
-} drm_radeon_fullscreen_t;
-
-#define CLEAR_X1       0
-#define CLEAR_Y1       1
-#define CLEAR_X2       2
-#define CLEAR_Y2       3
-#define CLEAR_DEPTH    4
-
-typedef union drm_radeon_clear_rect {
-       float f[5];
-       unsigned int ui[5];
-} drm_radeon_clear_rect_t;
-
-typedef struct drm_radeon_clear {
-       unsigned int flags;
-       unsigned int clear_color;
-       unsigned int clear_depth;
-       unsigned int color_mask;
-       unsigned int depth_mask;        /* misnamed field:  should be stencil */
-       drm_radeon_clear_rect_t __user *depth_boxes;
-} drm_radeon_clear_t;
-
-typedef struct drm_radeon_vertex {
-       int prim;
-       int idx;                /* Index of vertex buffer */
-       int count;              /* Number of vertices in buffer */
-       int discard;            /* Client finished with buffer? */
-} drm_radeon_vertex_t;
-
-typedef struct drm_radeon_indices {
-       int prim;
-       int idx;
-       int start;
-       int end;
-       int discard;            /* Client finished with buffer? */
-} drm_radeon_indices_t;
-
-/* v1.2 - obsoletes drm_radeon_vertex and drm_radeon_indices
- *      - allows multiple primitives and state changes in a single ioctl
- *      - supports driver change to emit native primitives
- */
-typedef struct drm_radeon_vertex2 {
-       int idx;                /* Index of vertex buffer */
-       int discard;            /* Client finished with buffer? */
-       int nr_states;
-       drm_radeon_state_t __user *state;
-       int nr_prims;
-       drm_radeon_prim_t __user *prim;
-} drm_radeon_vertex2_t;
-
-/* v1.3 - obsoletes drm_radeon_vertex2
- *      - allows arbitarily large cliprect list
- *      - allows updating of tcl packet, vector and scalar state
- *      - allows memory-efficient description of state updates
- *      - allows state to be emitted without a primitive
- *           (for clears, ctx switches)
- *      - allows more than one dma buffer to be referenced per ioctl
- *      - supports tcl driver
- *      - may be extended in future versions with new cmd types, packets
- */
-typedef struct drm_radeon_cmd_buffer {
-       int bufsz;
-       char __user *buf;
-       int nbox;
-       struct drm_clip_rect __user *boxes;
-} drm_radeon_cmd_buffer_t;
-
-typedef struct drm_radeon_tex_image {
-       unsigned int x, y;      /* Blit coordinates */
-       unsigned int width, height;
-       const void __user *data;
-} drm_radeon_tex_image_t;
-
-typedef struct drm_radeon_texture {
-       unsigned int offset;
-       int pitch;
-       int format;
-       int width;              /* Texture image coordinates */
-       int height;
-       drm_radeon_tex_image_t __user *image;
-} drm_radeon_texture_t;
-
-typedef struct drm_radeon_stipple {
-       unsigned int __user *mask;
-} drm_radeon_stipple_t;
-
-typedef struct drm_radeon_indirect {
-       int idx;
-       int start;
-       int end;
-       int discard;
-} drm_radeon_indirect_t;
-
-/* enum for card type parameters */
-#define RADEON_CARD_PCI 0
-#define RADEON_CARD_AGP 1
-#define RADEON_CARD_PCIE 2
-
-/* 1.3: An ioctl to get parameters that aren't available to the 3d
- * client any other way.
- */
-#define RADEON_PARAM_GART_BUFFER_OFFSET    1   /* card offset of 1st GART buffer */
-#define RADEON_PARAM_LAST_FRAME            2
-#define RADEON_PARAM_LAST_DISPATCH         3
-#define RADEON_PARAM_LAST_CLEAR            4
-/* Added with DRM version 1.6. */
-#define RADEON_PARAM_IRQ_NR                5
-#define RADEON_PARAM_GART_BASE             6   /* card offset of GART base */
-/* Added with DRM version 1.8. */
-#define RADEON_PARAM_REGISTER_HANDLE       7   /* for drmMap() */
-#define RADEON_PARAM_STATUS_HANDLE         8
-#define RADEON_PARAM_SAREA_HANDLE          9
-#define RADEON_PARAM_GART_TEX_HANDLE       10
-#define RADEON_PARAM_SCRATCH_OFFSET        11
-#define RADEON_PARAM_CARD_TYPE             12
-#define RADEON_PARAM_VBLANK_CRTC           13   /* VBLANK CRTC */
-#define RADEON_PARAM_FB_LOCATION           14   /* FB location */
-#define RADEON_PARAM_NUM_GB_PIPES          15   /* num GB pipes */
-
-typedef struct drm_radeon_getparam {
-       int param;
-       void __user *value;
-} drm_radeon_getparam_t;
-
-/* 1.6: Set up a memory manager for regions of shared memory:
- */
-#define RADEON_MEM_REGION_GART 1
-#define RADEON_MEM_REGION_FB   2
-
-typedef struct drm_radeon_mem_alloc {
-       int region;
-       int alignment;
-       int size;
-       int __user *region_offset;      /* offset from start of fb or GART */
-} drm_radeon_mem_alloc_t;
-
-typedef struct drm_radeon_mem_free {
-       int region;
-       int region_offset;
-} drm_radeon_mem_free_t;
-
-typedef struct drm_radeon_mem_init_heap {
-       int region;
-       int size;
-       int start;
-} drm_radeon_mem_init_heap_t;
-
-/* 1.6: Userspace can request & wait on irq's:
- */
-typedef struct drm_radeon_irq_emit {
-       int __user *irq_seq;
-} drm_radeon_irq_emit_t;
-
-typedef struct drm_radeon_irq_wait {
-       int irq_seq;
-} drm_radeon_irq_wait_t;
-
-/* 1.10: Clients tell the DRM where they think the framebuffer is located in
- * the card's address space, via a new generic ioctl to set parameters
- */
-
-typedef struct drm_radeon_setparam {
-       unsigned int param;
-       int64_t value;
-} drm_radeon_setparam_t;
-
-#define RADEON_SETPARAM_FB_LOCATION    1       /* determined framebuffer location */
-#define RADEON_SETPARAM_SWITCH_TILING  2       /* enable/disable color tiling */
-#define RADEON_SETPARAM_PCIGART_LOCATION 3     /* PCI Gart Location */
-#define RADEON_SETPARAM_NEW_MEMMAP 4           /* Use new memory map */
-#define RADEON_SETPARAM_PCIGART_TABLE_SIZE 5    /* PCI GART Table Size */
-#define RADEON_SETPARAM_VBLANK_CRTC 6           /* VBLANK CRTC */
-/* 1.14: Clients can allocate/free a surface
- */
-typedef struct drm_radeon_surface_alloc {
-       unsigned int address;
-       unsigned int size;
-       unsigned int flags;
-} drm_radeon_surface_alloc_t;
-
-typedef struct drm_radeon_surface_free {
-       unsigned int address;
-} drm_radeon_surface_free_t;
-
-#define        DRM_RADEON_VBLANK_CRTC1         1
-#define        DRM_RADEON_VBLANK_CRTC2         2
-
-#endif
diff --git a/drivers/char/drm/radeon_drv.c b/drivers/char/drm/radeon_drv.c
deleted file mode 100644 (file)
index 349ac3d..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/**
- * \file radeon_drv.c
- * ATI Radeon driver
- *
- * \author Gareth Hughes <gareth@valinux.com>
- */
-
-/*
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-
-#include "drm_pciids.h"
-
-int radeon_no_wb;
-
-MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n");
-module_param_named(no_wb, radeon_no_wb, int, 0444);
-
-static int dri_library_name(struct drm_device *dev, char *buf)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       int family = dev_priv->flags & RADEON_FAMILY_MASK;
-
-       return snprintf(buf, PAGE_SIZE, "%s\n",
-                       (family < CHIP_R200) ? "radeon" :
-                       ((family < CHIP_R300) ? "r200" :
-                       "r300"));
-}
-
-static struct pci_device_id pciidlist[] = {
-       radeon_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
-           DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED |
-           DRIVER_IRQ_VBL | DRIVER_IRQ_VBL2,
-       .dev_priv_size = sizeof(drm_radeon_buf_priv_t),
-       .load = radeon_driver_load,
-       .firstopen = radeon_driver_firstopen,
-       .open = radeon_driver_open,
-       .preclose = radeon_driver_preclose,
-       .postclose = radeon_driver_postclose,
-       .lastclose = radeon_driver_lastclose,
-       .unload = radeon_driver_unload,
-       .vblank_wait = radeon_driver_vblank_wait,
-       .vblank_wait2 = radeon_driver_vblank_wait2,
-       .dri_library_name = dri_library_name,
-       .irq_preinstall = radeon_driver_irq_preinstall,
-       .irq_postinstall = radeon_driver_irq_postinstall,
-       .irq_uninstall = radeon_driver_irq_uninstall,
-       .irq_handler = radeon_driver_irq_handler,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = radeon_ioctls,
-       .dma_ioctl = radeon_cp_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = radeon_compat_ioctl,
-#endif
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init radeon_init(void)
-{
-       driver.num_ioctls = radeon_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit radeon_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(radeon_init);
-module_exit(radeon_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
deleted file mode 100644 (file)
index 3f0eca9..0000000
+++ /dev/null
@@ -1,1406 +0,0 @@
-/* radeon_drv.h -- Private header for radeon driver -*- linux-c -*-
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Kevin E. Martin <martin@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#ifndef __RADEON_DRV_H__
-#define __RADEON_DRV_H__
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "Gareth Hughes, Keith Whitwell, others."
-
-#define DRIVER_NAME            "radeon"
-#define DRIVER_DESC            "ATI Radeon"
-#define DRIVER_DATE            "20080528"
-
-/* Interface history:
- *
- * 1.1 - ??
- * 1.2 - Add vertex2 ioctl (keith)
- *     - Add stencil capability to clear ioctl (gareth, keith)
- *     - Increase MAX_TEXTURE_LEVELS (brian)
- * 1.3 - Add cmdbuf ioctl (keith)
- *     - Add support for new radeon packets (keith)
- *     - Add getparam ioctl (keith)
- *     - Add flip-buffers ioctl, deprecate fullscreen foo (keith).
- * 1.4 - Add scratch registers to get_param ioctl.
- * 1.5 - Add r200 packets to cmdbuf ioctl
- *     - Add r200 function to init ioctl
- *     - Add 'scalar2' instruction to cmdbuf
- * 1.6 - Add static GART memory manager
- *       Add irq handler (won't be turned on unless X server knows to)
- *       Add irq ioctls and irq_active getparam.
- *       Add wait command for cmdbuf ioctl
- *       Add GART offset query for getparam
- * 1.7 - Add support for cube map registers: R200_PP_CUBIC_FACES_[0..5]
- *       and R200_PP_CUBIC_OFFSET_F1_[0..5].
- *       Added packets R200_EMIT_PP_CUBIC_FACES_[0..5] and
- *       R200_EMIT_PP_CUBIC_OFFSETS_[0..5].  (brian)
- * 1.8 - Remove need to call cleanup ioctls on last client exit (keith)
- *       Add 'GET' queries for starting additional clients on different VT's.
- * 1.9 - Add DRM_IOCTL_RADEON_CP_RESUME ioctl.
- *       Add texture rectangle support for r100.
- * 1.10- Add SETPARAM ioctl; first parameter to set is FB_LOCATION, which
- *       clients use to tell the DRM where they think the framebuffer is
- *       located in the card's address space
- * 1.11- Add packet R200_EMIT_RB3D_BLENDCOLOR to support GL_EXT_blend_color
- *       and GL_EXT_blend_[func|equation]_separate on r200
- * 1.12- Add R300 CP microcode support - this just loads the CP on r300
- *       (No 3D support yet - just microcode loading).
- * 1.13- Add packet R200_EMIT_TCL_POINT_SPRITE_CNTL for ARB_point_parameters
- *     - Add hyperz support, add hyperz flags to clear ioctl.
- * 1.14- Add support for color tiling
- *     - Add R100/R200 surface allocation/free support
- * 1.15- Add support for texture micro tiling
- *     - Add support for r100 cube maps
- * 1.16- Add R200_EMIT_PP_TRI_PERF_CNTL packet to support brilinear
- *       texture filtering on r200
- * 1.17- Add initial support for R300 (3D).
- * 1.18- Add support for GL_ATI_fragment_shader, new packets
- *       R200_EMIT_PP_AFS_0/1, R200_EMIT_PP_TXCTLALL_0-5 (replaces
- *       R200_EMIT_PP_TXFILTER_0-5, 2 more regs) and R200_EMIT_ATF_TFACTOR
- *       (replaces R200_EMIT_TFACTOR_0 (8 consts instead of 6)
- * 1.19- Add support for gart table in FB memory and PCIE r300
- * 1.20- Add support for r300 texrect
- * 1.21- Add support for card type getparam
- * 1.22- Add support for texture cache flushes (R300_TX_CNTL)
- * 1.23- Add new radeon memory map work from benh
- * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
- * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL,
- *       new packet type)
- * 1.26- Add support for variable size PCI(E) gart aperture
- * 1.27- Add support for IGP GART
- * 1.28- Add support for VBL on CRTC2
- * 1.29- R500 3D cmd buffer support
- */
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           29
-#define DRIVER_PATCHLEVEL      0
-
-/*
- * Radeon chip families
- */
-enum radeon_family {
-       CHIP_R100,
-       CHIP_RV100,
-       CHIP_RS100,
-       CHIP_RV200,
-       CHIP_RS200,
-       CHIP_R200,
-       CHIP_RV250,
-       CHIP_RS300,
-       CHIP_RV280,
-       CHIP_R300,
-       CHIP_R350,
-       CHIP_RV350,
-       CHIP_RV380,
-       CHIP_R420,
-       CHIP_RV410,
-       CHIP_RS480,
-       CHIP_RS690,
-       CHIP_RV515,
-       CHIP_R520,
-       CHIP_RV530,
-       CHIP_RV560,
-       CHIP_RV570,
-       CHIP_R580,
-       CHIP_LAST,
-};
-
-enum radeon_cp_microcode_version {
-       UCODE_R100,
-       UCODE_R200,
-       UCODE_R300,
-};
-
-/*
- * Chip flags
- */
-enum radeon_chip_flags {
-       RADEON_FAMILY_MASK = 0x0000ffffUL,
-       RADEON_FLAGS_MASK = 0xffff0000UL,
-       RADEON_IS_MOBILITY = 0x00010000UL,
-       RADEON_IS_IGP = 0x00020000UL,
-       RADEON_SINGLE_CRTC = 0x00040000UL,
-       RADEON_IS_AGP = 0x00080000UL,
-       RADEON_HAS_HIERZ = 0x00100000UL,
-       RADEON_IS_PCIE = 0x00200000UL,
-       RADEON_NEW_MEMMAP = 0x00400000UL,
-       RADEON_IS_PCI = 0x00800000UL,
-       RADEON_IS_IGPGART = 0x01000000UL,
-};
-
-#define GET_RING_HEAD(dev_priv)        (dev_priv->writeback_works ? \
-        DRM_READ32(  (dev_priv)->ring_rptr, 0 ) : RADEON_READ(RADEON_CP_RB_RPTR))
-#define SET_RING_HEAD(dev_priv,val)    DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) )
-
-typedef struct drm_radeon_freelist {
-       unsigned int age;
-       struct drm_buf *buf;
-       struct drm_radeon_freelist *next;
-       struct drm_radeon_freelist *prev;
-} drm_radeon_freelist_t;
-
-typedef struct drm_radeon_ring_buffer {
-       u32 *start;
-       u32 *end;
-       int size;
-       int size_l2qw;
-
-       int rptr_update; /* Double Words */
-       int rptr_update_l2qw; /* log2 Quad Words */
-
-       int fetch_size; /* Double Words */
-       int fetch_size_l2ow; /* log2 Oct Words */
-
-       u32 tail;
-       u32 tail_mask;
-       int space;
-
-       int high_mark;
-} drm_radeon_ring_buffer_t;
-
-typedef struct drm_radeon_depth_clear_t {
-       u32 rb3d_cntl;
-       u32 rb3d_zstencilcntl;
-       u32 se_cntl;
-} drm_radeon_depth_clear_t;
-
-struct drm_radeon_driver_file_fields {
-       int64_t radeon_fb_delta;
-};
-
-struct mem_block {
-       struct mem_block *next;
-       struct mem_block *prev;
-       int start;
-       int size;
-       struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
-};
-
-struct radeon_surface {
-       int refcount;
-       u32 lower;
-       u32 upper;
-       u32 flags;
-};
-
-struct radeon_virt_surface {
-       int surface_index;
-       u32 lower;
-       u32 upper;
-       u32 flags;
-       struct drm_file *file_priv;
-};
-
-typedef struct drm_radeon_private {
-       drm_radeon_ring_buffer_t ring;
-       drm_radeon_sarea_t *sarea_priv;
-
-       u32 fb_location;
-       u32 fb_size;
-       int new_memmap;
-
-       int gart_size;
-       u32 gart_vm_start;
-       unsigned long gart_buffers_offset;
-
-       int cp_mode;
-       int cp_running;
-
-       drm_radeon_freelist_t *head;
-       drm_radeon_freelist_t *tail;
-       int last_buf;
-       volatile u32 *scratch;
-       int writeback_works;
-
-       int usec_timeout;
-
-       int microcode_version;
-
-       struct {
-               u32 boxes;
-               int freelist_timeouts;
-               int freelist_loops;
-               int requested_bufs;
-               int last_frame_reads;
-               int last_clear_reads;
-               int clears;
-               int texture_uploads;
-       } stats;
-
-       int do_boxes;
-       int page_flipping;
-
-       u32 color_fmt;
-       unsigned int front_offset;
-       unsigned int front_pitch;
-       unsigned int back_offset;
-       unsigned int back_pitch;
-
-       u32 depth_fmt;
-       unsigned int depth_offset;
-       unsigned int depth_pitch;
-
-       u32 front_pitch_offset;
-       u32 back_pitch_offset;
-       u32 depth_pitch_offset;
-
-       drm_radeon_depth_clear_t depth_clear;
-
-       unsigned long ring_offset;
-       unsigned long ring_rptr_offset;
-       unsigned long buffers_offset;
-       unsigned long gart_textures_offset;
-
-       drm_local_map_t *sarea;
-       drm_local_map_t *mmio;
-       drm_local_map_t *cp_ring;
-       drm_local_map_t *ring_rptr;
-       drm_local_map_t *gart_textures;
-
-       struct mem_block *gart_heap;
-       struct mem_block *fb_heap;
-
-       /* SW interrupt */
-       wait_queue_head_t swi_queue;
-       atomic_t swi_emitted;
-       int vblank_crtc;
-       uint32_t irq_enable_reg;
-       int irq_enabled;
-       uint32_t r500_disp_irq_reg;
-
-       struct radeon_surface surfaces[RADEON_MAX_SURFACES];
-       struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES];
-
-       unsigned long pcigart_offset;
-       unsigned int pcigart_offset_set;
-       struct drm_ati_pcigart_info gart_info;
-
-       u32 scratch_ages[5];
-
-       /* starting from here on, data is preserved accross an open */
-       uint32_t flags;         /* see radeon_chip_flags */
-       unsigned long fb_aper_offset;
-
-       int num_gb_pipes;
-} drm_radeon_private_t;
-
-typedef struct drm_radeon_buf_priv {
-       u32 age;
-} drm_radeon_buf_priv_t;
-
-typedef struct drm_radeon_kcmd_buffer {
-       int bufsz;
-       char *buf;
-       int nbox;
-       struct drm_clip_rect __user *boxes;
-} drm_radeon_kcmd_buffer_t;
-
-extern int radeon_no_wb;
-extern struct drm_ioctl_desc radeon_ioctls[];
-extern int radeon_max_ioctl;
-
-/* Check whether the given hardware address is inside the framebuffer or the
- * GART area.
- */
-static __inline__ int radeon_check_offset(drm_radeon_private_t *dev_priv,
-                                         u64 off)
-{
-       u32 fb_start = dev_priv->fb_location;
-       u32 fb_end = fb_start + dev_priv->fb_size - 1;
-       u32 gart_start = dev_priv->gart_vm_start;
-       u32 gart_end = gart_start + dev_priv->gart_size - 1;
-
-       return ((off >= fb_start && off <= fb_end) ||
-               (off >= gart_start && off <= gart_end));
-}
-
-                               /* radeon_cp.c */
-extern int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv);
-
-extern void radeon_freelist_reset(struct drm_device * dev);
-extern struct drm_buf *radeon_freelist_get(struct drm_device * dev);
-
-extern int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n);
-
-extern int radeon_do_cp_idle(drm_radeon_private_t * dev_priv);
-
-extern int radeon_driver_preinit(struct drm_device *dev, unsigned long flags);
-extern int radeon_presetup(struct drm_device *dev);
-extern int radeon_driver_postcleanup(struct drm_device *dev);
-
-extern int radeon_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern void radeon_mem_takedown(struct mem_block **heap);
-extern void radeon_mem_release(struct drm_file *file_priv,
-                              struct mem_block *heap);
-
-                               /* radeon_irq.c */
-extern int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv);
-
-extern void radeon_do_release(struct drm_device * dev);
-extern int radeon_driver_vblank_wait(struct drm_device * dev,
-                                    unsigned int *sequence);
-extern int radeon_driver_vblank_wait2(struct drm_device * dev,
-                                     unsigned int *sequence);
-extern irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS);
-extern void radeon_driver_irq_preinstall(struct drm_device * dev);
-extern void radeon_driver_irq_postinstall(struct drm_device * dev);
-extern void radeon_driver_irq_uninstall(struct drm_device * dev);
-extern void radeon_enable_interrupt(struct drm_device *dev);
-extern int radeon_vblank_crtc_get(struct drm_device *dev);
-extern int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value);
-
-extern int radeon_driver_load(struct drm_device *dev, unsigned long flags);
-extern int radeon_driver_unload(struct drm_device *dev);
-extern int radeon_driver_firstopen(struct drm_device *dev);
-extern void radeon_driver_preclose(struct drm_device * dev, struct drm_file *file_priv);
-extern void radeon_driver_postclose(struct drm_device * dev, struct drm_file * filp);
-extern void radeon_driver_lastclose(struct drm_device * dev);
-extern int radeon_driver_open(struct drm_device * dev, struct drm_file * filp_priv);
-extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
-                               unsigned long arg);
-
-/* r300_cmdbuf.c */
-extern void r300_init_reg_flags(struct drm_device *dev);
-
-extern int r300_do_cp_cmdbuf(struct drm_device * dev,
-                            struct drm_file *file_priv,
-                            drm_radeon_kcmd_buffer_t * cmdbuf);
-
-/* Flags for stats.boxes
- */
-#define RADEON_BOX_DMA_IDLE      0x1
-#define RADEON_BOX_RING_FULL     0x2
-#define RADEON_BOX_FLIP          0x4
-#define RADEON_BOX_WAIT_IDLE     0x8
-#define RADEON_BOX_TEXTURE_LOAD  0x10
-
-/* Register definitions, register access macros and drmAddMap constants
- * for Radeon kernel driver.
- */
-
-#define RADEON_AGP_COMMAND             0x0f60
-#define RADEON_AGP_COMMAND_PCI_CONFIG   0x0060 /* offset in PCI config */
-#      define RADEON_AGP_ENABLE        (1<<8)
-#define RADEON_AUX_SCISSOR_CNTL                0x26f0
-#      define RADEON_EXCLUSIVE_SCISSOR_0       (1 << 24)
-#      define RADEON_EXCLUSIVE_SCISSOR_1       (1 << 25)
-#      define RADEON_EXCLUSIVE_SCISSOR_2       (1 << 26)
-#      define RADEON_SCISSOR_0_ENABLE          (1 << 28)
-#      define RADEON_SCISSOR_1_ENABLE          (1 << 29)
-#      define RADEON_SCISSOR_2_ENABLE          (1 << 30)
-
-#define RADEON_BUS_CNTL                        0x0030
-#      define RADEON_BUS_MASTER_DIS            (1 << 6)
-
-#define RADEON_CLOCK_CNTL_DATA         0x000c
-#      define RADEON_PLL_WR_EN                 (1 << 7)
-#define RADEON_CLOCK_CNTL_INDEX                0x0008
-#define RADEON_CONFIG_APER_SIZE                0x0108
-#define RADEON_CONFIG_MEMSIZE          0x00f8
-#define RADEON_CRTC_OFFSET             0x0224
-#define RADEON_CRTC_OFFSET_CNTL                0x0228
-#      define RADEON_CRTC_TILE_EN              (1 << 15)
-#      define RADEON_CRTC_OFFSET_FLIP_CNTL     (1 << 16)
-#define RADEON_CRTC2_OFFSET            0x0324
-#define RADEON_CRTC2_OFFSET_CNTL       0x0328
-
-#define RADEON_PCIE_INDEX               0x0030
-#define RADEON_PCIE_DATA                0x0034
-#define RADEON_PCIE_TX_GART_CNTL       0x10
-#      define RADEON_PCIE_TX_GART_EN           (1 << 0)
-#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_PASS_THRU (0 << 1)
-#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_CLAMP_LO  (1 << 1)
-#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD   (3 << 1)
-#      define RADEON_PCIE_TX_GART_MODE_32_128_CACHE    (0 << 3)
-#      define RADEON_PCIE_TX_GART_MODE_8_4_128_CACHE   (1 << 3)
-#      define RADEON_PCIE_TX_GART_CHK_RW_VALID_EN      (1 << 5)
-#      define RADEON_PCIE_TX_GART_INVALIDATE_TLB       (1 << 8)
-#define RADEON_PCIE_TX_DISCARD_RD_ADDR_LO 0x11
-#define RADEON_PCIE_TX_DISCARD_RD_ADDR_HI 0x12
-#define RADEON_PCIE_TX_GART_BASE       0x13
-#define RADEON_PCIE_TX_GART_START_LO   0x14
-#define RADEON_PCIE_TX_GART_START_HI   0x15
-#define RADEON_PCIE_TX_GART_END_LO     0x16
-#define RADEON_PCIE_TX_GART_END_HI     0x17
-
-#define RS480_NB_MC_INDEX               0x168
-#      define RS480_NB_MC_IND_WR_EN    (1 << 8)
-#define RS480_NB_MC_DATA                0x16c
-
-#define RS690_MC_INDEX                  0x78
-#   define RS690_MC_INDEX_MASK          0x1ff
-#   define RS690_MC_INDEX_WR_EN         (1 << 9)
-#   define RS690_MC_INDEX_WR_ACK        0x7f
-#define RS690_MC_DATA                   0x7c
-
-/* MC indirect registers */
-#define RS480_MC_MISC_CNTL              0x18
-#      define RS480_DISABLE_GTW        (1 << 1)
-/* switch between MCIND GART and MM GART registers. 0 = mmgart, 1 = mcind gart */
-#      define RS480_GART_INDEX_REG_EN  (1 << 12)
-#      define RS690_BLOCK_GFX_D3_EN    (1 << 14)
-#define RS480_K8_FB_LOCATION            0x1e
-#define RS480_GART_FEATURE_ID           0x2b
-#      define RS480_HANG_EN            (1 << 11)
-#      define RS480_TLB_ENABLE         (1 << 18)
-#      define RS480_P2P_ENABLE         (1 << 19)
-#      define RS480_GTW_LAC_EN         (1 << 25)
-#      define RS480_2LEVEL_GART        (0 << 30)
-#      define RS480_1LEVEL_GART        (1 << 30)
-#      define RS480_PDC_EN             (1 << 31)
-#define RS480_GART_BASE                 0x2c
-#define RS480_GART_CACHE_CNTRL          0x2e
-#      define RS480_GART_CACHE_INVALIDATE (1 << 0) /* wait for it to clear */
-#define RS480_AGP_ADDRESS_SPACE_SIZE    0x38
-#      define RS480_GART_EN            (1 << 0)
-#      define RS480_VA_SIZE_32MB       (0 << 1)
-#      define RS480_VA_SIZE_64MB       (1 << 1)
-#      define RS480_VA_SIZE_128MB      (2 << 1)
-#      define RS480_VA_SIZE_256MB      (3 << 1)
-#      define RS480_VA_SIZE_512MB      (4 << 1)
-#      define RS480_VA_SIZE_1GB        (5 << 1)
-#      define RS480_VA_SIZE_2GB        (6 << 1)
-#define RS480_AGP_MODE_CNTL             0x39
-#      define RS480_POST_GART_Q_SIZE   (1 << 18)
-#      define RS480_NONGART_SNOOP      (1 << 19)
-#      define RS480_AGP_RD_BUF_SIZE    (1 << 20)
-#      define RS480_REQ_TYPE_SNOOP_SHIFT 22
-#      define RS480_REQ_TYPE_SNOOP_MASK  0x3
-#      define RS480_REQ_TYPE_SNOOP_DIS (1 << 24)
-#define RS480_MC_MISC_UMA_CNTL          0x5f
-#define RS480_MC_MCLK_CNTL              0x7a
-#define RS480_MC_UMA_DUALCH_CNTL        0x86
-
-#define RS690_MC_FB_LOCATION            0x100
-#define RS690_MC_AGP_LOCATION           0x101
-#define RS690_MC_AGP_BASE               0x102
-#define RS690_MC_AGP_BASE_2             0x103
-
-#define R520_MC_IND_INDEX 0x70
-#define R520_MC_IND_WR_EN (1 << 24)
-#define R520_MC_IND_DATA  0x74
-
-#define RV515_MC_FB_LOCATION 0x01
-#define RV515_MC_AGP_LOCATION 0x02
-#define RV515_MC_AGP_BASE     0x03
-#define RV515_MC_AGP_BASE_2   0x04
-
-#define R520_MC_FB_LOCATION 0x04
-#define R520_MC_AGP_LOCATION 0x05
-#define R520_MC_AGP_BASE     0x06
-#define R520_MC_AGP_BASE_2   0x07
-
-#define RADEON_MPP_TB_CONFIG           0x01c0
-#define RADEON_MEM_CNTL                        0x0140
-#define RADEON_MEM_SDRAM_MODE_REG      0x0158
-#define RADEON_AGP_BASE_2              0x015c /* r200+ only */
-#define RS480_AGP_BASE_2               0x0164
-#define RADEON_AGP_BASE                        0x0170
-
-/* pipe config regs */
-#define R400_GB_PIPE_SELECT             0x402c
-#define R500_DYN_SCLK_PWMEM_PIPE        0x000d /* PLL */
-#define R500_SU_REG_DEST                0x42c8
-#define R300_GB_TILE_CONFIG             0x4018
-#       define R300_ENABLE_TILING       (1 << 0)
-#       define R300_PIPE_COUNT_RV350    (0 << 1)
-#       define R300_PIPE_COUNT_R300     (3 << 1)
-#       define R300_PIPE_COUNT_R420_3P  (6 << 1)
-#       define R300_PIPE_COUNT_R420     (7 << 1)
-#       define R300_TILE_SIZE_8         (0 << 4)
-#       define R300_TILE_SIZE_16        (1 << 4)
-#       define R300_TILE_SIZE_32        (2 << 4)
-#       define R300_SUBPIXEL_1_12       (0 << 16)
-#       define R300_SUBPIXEL_1_16       (1 << 16)
-#define R300_DST_PIPE_CONFIG            0x170c
-#       define R300_PIPE_AUTO_CONFIG    (1 << 31)
-#define R300_RB2D_DSTCACHE_MODE         0x3428
-#       define R300_DC_AUTOFLUSH_ENABLE (1 << 8)
-#       define R300_DC_DC_DISABLE_IGNORE_PE (1 << 17)
-
-#define RADEON_RB3D_COLOROFFSET                0x1c40
-#define RADEON_RB3D_COLORPITCH         0x1c48
-
-#define        RADEON_SRC_X_Y                  0x1590
-
-#define RADEON_DP_GUI_MASTER_CNTL      0x146c
-#      define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
-#      define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
-#      define RADEON_GMC_BRUSH_SOLID_COLOR     (13 << 4)
-#      define RADEON_GMC_BRUSH_NONE            (15 << 4)
-#      define RADEON_GMC_DST_16BPP             (4 << 8)
-#      define RADEON_GMC_DST_24BPP             (5 << 8)
-#      define RADEON_GMC_DST_32BPP             (6 << 8)
-#      define RADEON_GMC_DST_DATATYPE_SHIFT    8
-#      define RADEON_GMC_SRC_DATATYPE_COLOR    (3 << 12)
-#      define RADEON_DP_SRC_SOURCE_MEMORY      (2 << 24)
-#      define RADEON_DP_SRC_SOURCE_HOST_DATA   (3 << 24)
-#      define RADEON_GMC_CLR_CMP_CNTL_DIS      (1 << 28)
-#      define RADEON_GMC_WR_MSK_DIS            (1 << 30)
-#      define RADEON_ROP3_S                    0x00cc0000
-#      define RADEON_ROP3_P                    0x00f00000
-#define RADEON_DP_WRITE_MASK           0x16cc
-#define RADEON_SRC_PITCH_OFFSET                0x1428
-#define RADEON_DST_PITCH_OFFSET                0x142c
-#define RADEON_DST_PITCH_OFFSET_C      0x1c80
-#      define RADEON_DST_TILE_LINEAR           (0 << 30)
-#      define RADEON_DST_TILE_MACRO            (1 << 30)
-#      define RADEON_DST_TILE_MICRO            (2 << 30)
-#      define RADEON_DST_TILE_BOTH             (3 << 30)
-
-#define RADEON_SCRATCH_REG0            0x15e0
-#define RADEON_SCRATCH_REG1            0x15e4
-#define RADEON_SCRATCH_REG2            0x15e8
-#define RADEON_SCRATCH_REG3            0x15ec
-#define RADEON_SCRATCH_REG4            0x15f0
-#define RADEON_SCRATCH_REG5            0x15f4
-#define RADEON_SCRATCH_UMSK            0x0770
-#define RADEON_SCRATCH_ADDR            0x0774
-
-#define RADEON_SCRATCHOFF( x )         (RADEON_SCRATCH_REG_OFFSET + 4*(x))
-
-#define GET_SCRATCH( x )       (dev_priv->writeback_works                      \
-                               ? DRM_READ32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(x) ) \
-                               : RADEON_READ( RADEON_SCRATCH_REG0 + 4*(x) ) )
-
-#define RADEON_GEN_INT_CNTL            0x0040
-#      define RADEON_CRTC_VBLANK_MASK          (1 << 0)
-#      define RADEON_CRTC2_VBLANK_MASK         (1 << 9)
-#      define RADEON_GUI_IDLE_INT_ENABLE       (1 << 19)
-#      define RADEON_SW_INT_ENABLE             (1 << 25)
-
-#define RADEON_GEN_INT_STATUS          0x0044
-#      define RADEON_CRTC_VBLANK_STAT          (1 << 0)
-#      define RADEON_CRTC_VBLANK_STAT_ACK      (1 << 0)
-#      define RADEON_CRTC2_VBLANK_STAT         (1 << 9)
-#      define RADEON_CRTC2_VBLANK_STAT_ACK     (1 << 9)
-#      define RADEON_GUI_IDLE_INT_TEST_ACK     (1 << 19)
-#      define RADEON_SW_INT_TEST               (1 << 25)
-#      define RADEON_SW_INT_TEST_ACK           (1 << 25)
-#      define RADEON_SW_INT_FIRE               (1 << 26)
-
-#define RADEON_HOST_PATH_CNTL          0x0130
-#      define RADEON_HDP_SOFT_RESET            (1 << 26)
-#      define RADEON_HDP_WC_TIMEOUT_MASK       (7 << 28)
-#      define RADEON_HDP_WC_TIMEOUT_28BCLK     (7 << 28)
-
-#define RADEON_ISYNC_CNTL              0x1724
-#      define RADEON_ISYNC_ANY2D_IDLE3D        (1 << 0)
-#      define RADEON_ISYNC_ANY3D_IDLE2D        (1 << 1)
-#      define RADEON_ISYNC_TRIG2D_IDLE3D       (1 << 2)
-#      define RADEON_ISYNC_TRIG3D_IDLE2D       (1 << 3)
-#      define RADEON_ISYNC_WAIT_IDLEGUI        (1 << 4)
-#      define RADEON_ISYNC_CPSCRATCH_IDLEGUI   (1 << 5)
-
-#define RADEON_RBBM_GUICNTL            0x172c
-#      define RADEON_HOST_DATA_SWAP_NONE       (0 << 0)
-#      define RADEON_HOST_DATA_SWAP_16BIT      (1 << 0)
-#      define RADEON_HOST_DATA_SWAP_32BIT      (2 << 0)
-#      define RADEON_HOST_DATA_SWAP_HDW        (3 << 0)
-
-#define RADEON_MC_AGP_LOCATION         0x014c
-#define RADEON_MC_FB_LOCATION          0x0148
-#define RADEON_MCLK_CNTL               0x0012
-#      define RADEON_FORCEON_MCLKA             (1 << 16)
-#      define RADEON_FORCEON_MCLKB             (1 << 17)
-#      define RADEON_FORCEON_YCLKA             (1 << 18)
-#      define RADEON_FORCEON_YCLKB             (1 << 19)
-#      define RADEON_FORCEON_MC                (1 << 20)
-#      define RADEON_FORCEON_AIC               (1 << 21)
-
-#define RADEON_PP_BORDER_COLOR_0       0x1d40
-#define RADEON_PP_BORDER_COLOR_1       0x1d44
-#define RADEON_PP_BORDER_COLOR_2       0x1d48
-#define RADEON_PP_CNTL                 0x1c38
-#      define RADEON_SCISSOR_ENABLE            (1 <<  1)
-#define RADEON_PP_LUM_MATRIX           0x1d00
-#define RADEON_PP_MISC                 0x1c14
-#define RADEON_PP_ROT_MATRIX_0         0x1d58
-#define RADEON_PP_TXFILTER_0           0x1c54
-#define RADEON_PP_TXOFFSET_0           0x1c5c
-#define RADEON_PP_TXFILTER_1           0x1c6c
-#define RADEON_PP_TXFILTER_2           0x1c84
-
-#define R300_RB2D_DSTCACHE_CTLSTAT     0x342c /* use R300_DSTCACHE_CTLSTAT */
-#define R300_DSTCACHE_CTLSTAT          0x1714
-#      define R300_RB2D_DC_FLUSH               (3 << 0)
-#      define R300_RB2D_DC_FREE                (3 << 2)
-#      define R300_RB2D_DC_FLUSH_ALL           0xf
-#      define R300_RB2D_DC_BUSY                (1 << 31)
-#define RADEON_RB3D_CNTL               0x1c3c
-#      define RADEON_ALPHA_BLEND_ENABLE        (1 << 0)
-#      define RADEON_PLANE_MASK_ENABLE         (1 << 1)
-#      define RADEON_DITHER_ENABLE             (1 << 2)
-#      define RADEON_ROUND_ENABLE              (1 << 3)
-#      define RADEON_SCALE_DITHER_ENABLE       (1 << 4)
-#      define RADEON_DITHER_INIT               (1 << 5)
-#      define RADEON_ROP_ENABLE                (1 << 6)
-#      define RADEON_STENCIL_ENABLE            (1 << 7)
-#      define RADEON_Z_ENABLE                  (1 << 8)
-#      define RADEON_ZBLOCK16                  (1 << 15)
-#define RADEON_RB3D_DEPTHOFFSET                0x1c24
-#define RADEON_RB3D_DEPTHCLEARVALUE    0x3230
-#define RADEON_RB3D_DEPTHPITCH         0x1c28
-#define RADEON_RB3D_PLANEMASK          0x1d84
-#define RADEON_RB3D_STENCILREFMASK     0x1d7c
-#define RADEON_RB3D_ZCACHE_MODE                0x3250
-#define RADEON_RB3D_ZCACHE_CTLSTAT     0x3254
-#      define RADEON_RB3D_ZC_FLUSH             (1 << 0)
-#      define RADEON_RB3D_ZC_FREE              (1 << 2)
-#      define RADEON_RB3D_ZC_FLUSH_ALL         0x5
-#      define RADEON_RB3D_ZC_BUSY              (1 << 31)
-#define R300_ZB_ZCACHE_CTLSTAT                  0x4f18
-#      define R300_ZC_FLUSH                    (1 << 0)
-#      define R300_ZC_FREE                     (1 << 1)
-#      define R300_ZC_FLUSH_ALL                0x3
-#      define R300_ZC_BUSY                     (1 << 31)
-#define RADEON_RB3D_DSTCACHE_CTLSTAT   0x325c
-#      define RADEON_RB3D_DC_FLUSH             (3 << 0)
-#      define RADEON_RB3D_DC_FREE              (3 << 2)
-#      define RADEON_RB3D_DC_FLUSH_ALL         0xf
-#      define RADEON_RB3D_DC_BUSY              (1 << 31)
-#define R300_RB3D_DSTCACHE_CTLSTAT              0x4e4c
-#      define R300_RB3D_DC_FINISH              (1 << 4)
-#define RADEON_RB3D_ZSTENCILCNTL       0x1c2c
-#      define RADEON_Z_TEST_MASK               (7 << 4)
-#      define RADEON_Z_TEST_ALWAYS             (7 << 4)
-#      define RADEON_Z_HIERARCHY_ENABLE        (1 << 8)
-#      define RADEON_STENCIL_TEST_ALWAYS       (7 << 12)
-#      define RADEON_STENCIL_S_FAIL_REPLACE    (2 << 16)
-#      define RADEON_STENCIL_ZPASS_REPLACE     (2 << 20)
-#      define RADEON_STENCIL_ZFAIL_REPLACE     (2 << 24)
-#      define RADEON_Z_COMPRESSION_ENABLE      (1 << 28)
-#      define RADEON_FORCE_Z_DIRTY             (1 << 29)
-#      define RADEON_Z_WRITE_ENABLE            (1 << 30)
-#      define RADEON_Z_DECOMPRESSION_ENABLE    (1 << 31)
-#define RADEON_RBBM_SOFT_RESET         0x00f0
-#      define RADEON_SOFT_RESET_CP             (1 <<  0)
-#      define RADEON_SOFT_RESET_HI             (1 <<  1)
-#      define RADEON_SOFT_RESET_SE             (1 <<  2)
-#      define RADEON_SOFT_RESET_RE             (1 <<  3)
-#      define RADEON_SOFT_RESET_PP             (1 <<  4)
-#      define RADEON_SOFT_RESET_E2             (1 <<  5)
-#      define RADEON_SOFT_RESET_RB             (1 <<  6)
-#      define RADEON_SOFT_RESET_HDP            (1 <<  7)
-/*
- *   6:0  Available slots in the FIFO
- *   8    Host Interface active
- *   9    CP request active
- *   10   FIFO request active
- *   11   Host Interface retry active
- *   12   CP retry active
- *   13   FIFO retry active
- *   14   FIFO pipeline busy
- *   15   Event engine busy
- *   16   CP command stream busy
- *   17   2D engine busy
- *   18   2D portion of render backend busy
- *   20   3D setup engine busy
- *   26   GA engine busy
- *   27   CBA 2D engine busy
- *   31   2D engine busy or 3D engine busy or FIFO not empty or CP busy or
- *           command stream queue not empty or Ring Buffer not empty
- */
-#define RADEON_RBBM_STATUS             0x0e40
-/* Same as the previous RADEON_RBBM_STATUS; this is a mirror of that register.  */
-/* #define RADEON_RBBM_STATUS          0x1740 */
-/* bits 6:0 are dword slots available in the cmd fifo */
-#      define RADEON_RBBM_FIFOCNT_MASK         0x007f
-#      define RADEON_HIRQ_ON_RBB       (1 <<  8)
-#      define RADEON_CPRQ_ON_RBB       (1 <<  9)
-#      define RADEON_CFRQ_ON_RBB       (1 << 10)
-#      define RADEON_HIRQ_IN_RTBUF     (1 << 11)
-#      define RADEON_CPRQ_IN_RTBUF     (1 << 12)
-#      define RADEON_CFRQ_IN_RTBUF     (1 << 13)
-#      define RADEON_PIPE_BUSY         (1 << 14)
-#      define RADEON_ENG_EV_BUSY       (1 << 15)
-#      define RADEON_CP_CMDSTRM_BUSY   (1 << 16)
-#      define RADEON_E2_BUSY           (1 << 17)
-#      define RADEON_RB2D_BUSY         (1 << 18)
-#      define RADEON_RB3D_BUSY         (1 << 19) /* not used on r300 */
-#      define RADEON_VAP_BUSY          (1 << 20)
-#      define RADEON_RE_BUSY           (1 << 21) /* not used on r300 */
-#      define RADEON_TAM_BUSY          (1 << 22) /* not used on r300 */
-#      define RADEON_TDM_BUSY          (1 << 23) /* not used on r300 */
-#      define RADEON_PB_BUSY           (1 << 24) /* not used on r300 */
-#      define RADEON_TIM_BUSY          (1 << 25) /* not used on r300 */
-#      define RADEON_GA_BUSY           (1 << 26)
-#      define RADEON_CBA2D_BUSY        (1 << 27)
-#      define RADEON_RBBM_ACTIVE       (1 << 31)
-#define RADEON_RE_LINE_PATTERN         0x1cd0
-#define RADEON_RE_MISC                 0x26c4
-#define RADEON_RE_TOP_LEFT             0x26c0
-#define RADEON_RE_WIDTH_HEIGHT         0x1c44
-#define RADEON_RE_STIPPLE_ADDR         0x1cc8
-#define RADEON_RE_STIPPLE_DATA         0x1ccc
-
-#define RADEON_SCISSOR_TL_0            0x1cd8
-#define RADEON_SCISSOR_BR_0            0x1cdc
-#define RADEON_SCISSOR_TL_1            0x1ce0
-#define RADEON_SCISSOR_BR_1            0x1ce4
-#define RADEON_SCISSOR_TL_2            0x1ce8
-#define RADEON_SCISSOR_BR_2            0x1cec
-#define RADEON_SE_COORD_FMT            0x1c50
-#define RADEON_SE_CNTL                 0x1c4c
-#      define RADEON_FFACE_CULL_CW             (0 << 0)
-#      define RADEON_BFACE_SOLID               (3 << 1)
-#      define RADEON_FFACE_SOLID               (3 << 3)
-#      define RADEON_FLAT_SHADE_VTX_LAST       (3 << 6)
-#      define RADEON_DIFFUSE_SHADE_FLAT        (1 << 8)
-#      define RADEON_DIFFUSE_SHADE_GOURAUD     (2 << 8)
-#      define RADEON_ALPHA_SHADE_FLAT          (1 << 10)
-#      define RADEON_ALPHA_SHADE_GOURAUD       (2 << 10)
-#      define RADEON_SPECULAR_SHADE_FLAT       (1 << 12)
-#      define RADEON_SPECULAR_SHADE_GOURAUD    (2 << 12)
-#      define RADEON_FOG_SHADE_FLAT            (1 << 14)
-#      define RADEON_FOG_SHADE_GOURAUD         (2 << 14)
-#      define RADEON_VPORT_XY_XFORM_ENABLE     (1 << 24)
-#      define RADEON_VPORT_Z_XFORM_ENABLE      (1 << 25)
-#      define RADEON_VTX_PIX_CENTER_OGL        (1 << 27)
-#      define RADEON_ROUND_MODE_TRUNC          (0 << 28)
-#      define RADEON_ROUND_PREC_8TH_PIX        (1 << 30)
-#define RADEON_SE_CNTL_STATUS          0x2140
-#define RADEON_SE_LINE_WIDTH           0x1db8
-#define RADEON_SE_VPORT_XSCALE         0x1d98
-#define RADEON_SE_ZBIAS_FACTOR         0x1db0
-#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED 0x2210
-#define RADEON_SE_TCL_OUTPUT_VTX_FMT         0x2254
-#define RADEON_SE_TCL_VECTOR_INDX_REG        0x2200
-#       define RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT  16
-#       define RADEON_VEC_INDX_DWORD_COUNT_SHIFT     28
-#define RADEON_SE_TCL_VECTOR_DATA_REG       0x2204
-#define RADEON_SE_TCL_SCALAR_INDX_REG       0x2208
-#       define RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT  16
-#define RADEON_SE_TCL_SCALAR_DATA_REG       0x220C
-#define RADEON_SURFACE_ACCESS_FLAGS    0x0bf8
-#define RADEON_SURFACE_ACCESS_CLR      0x0bfc
-#define RADEON_SURFACE_CNTL            0x0b00
-#      define RADEON_SURF_TRANSLATION_DIS      (1 << 8)
-#      define RADEON_NONSURF_AP0_SWP_MASK      (3 << 20)
-#      define RADEON_NONSURF_AP0_SWP_LITTLE    (0 << 20)
-#      define RADEON_NONSURF_AP0_SWP_BIG16     (1 << 20)
-#      define RADEON_NONSURF_AP0_SWP_BIG32     (2 << 20)
-#      define RADEON_NONSURF_AP1_SWP_MASK      (3 << 22)
-#      define RADEON_NONSURF_AP1_SWP_LITTLE    (0 << 22)
-#      define RADEON_NONSURF_AP1_SWP_BIG16     (1 << 22)
-#      define RADEON_NONSURF_AP1_SWP_BIG32     (2 << 22)
-#define RADEON_SURFACE0_INFO           0x0b0c
-#      define RADEON_SURF_PITCHSEL_MASK        (0x1ff << 0)
-#      define RADEON_SURF_TILE_MODE_MASK       (3 << 16)
-#      define RADEON_SURF_TILE_MODE_MACRO      (0 << 16)
-#      define RADEON_SURF_TILE_MODE_MICRO      (1 << 16)
-#      define RADEON_SURF_TILE_MODE_32BIT_Z    (2 << 16)
-#      define RADEON_SURF_TILE_MODE_16BIT_Z    (3 << 16)
-#define RADEON_SURFACE0_LOWER_BOUND    0x0b04
-#define RADEON_SURFACE0_UPPER_BOUND    0x0b08
-#      define RADEON_SURF_ADDRESS_FIXED_MASK   (0x3ff << 0)
-#define RADEON_SURFACE1_INFO           0x0b1c
-#define RADEON_SURFACE1_LOWER_BOUND    0x0b14
-#define RADEON_SURFACE1_UPPER_BOUND    0x0b18
-#define RADEON_SURFACE2_INFO           0x0b2c
-#define RADEON_SURFACE2_LOWER_BOUND    0x0b24
-#define RADEON_SURFACE2_UPPER_BOUND    0x0b28
-#define RADEON_SURFACE3_INFO           0x0b3c
-#define RADEON_SURFACE3_LOWER_BOUND    0x0b34
-#define RADEON_SURFACE3_UPPER_BOUND    0x0b38
-#define RADEON_SURFACE4_INFO           0x0b4c
-#define RADEON_SURFACE4_LOWER_BOUND    0x0b44
-#define RADEON_SURFACE4_UPPER_BOUND    0x0b48
-#define RADEON_SURFACE5_INFO           0x0b5c
-#define RADEON_SURFACE5_LOWER_BOUND    0x0b54
-#define RADEON_SURFACE5_UPPER_BOUND    0x0b58
-#define RADEON_SURFACE6_INFO           0x0b6c
-#define RADEON_SURFACE6_LOWER_BOUND    0x0b64
-#define RADEON_SURFACE6_UPPER_BOUND    0x0b68
-#define RADEON_SURFACE7_INFO           0x0b7c
-#define RADEON_SURFACE7_LOWER_BOUND    0x0b74
-#define RADEON_SURFACE7_UPPER_BOUND    0x0b78
-#define RADEON_SW_SEMAPHORE            0x013c
-
-#define RADEON_WAIT_UNTIL              0x1720
-#      define RADEON_WAIT_CRTC_PFLIP           (1 << 0)
-#      define RADEON_WAIT_2D_IDLE              (1 << 14)
-#      define RADEON_WAIT_3D_IDLE              (1 << 15)
-#      define RADEON_WAIT_2D_IDLECLEAN         (1 << 16)
-#      define RADEON_WAIT_3D_IDLECLEAN         (1 << 17)
-#      define RADEON_WAIT_HOST_IDLECLEAN       (1 << 18)
-
-#define RADEON_RB3D_ZMASKOFFSET                0x3234
-#define RADEON_RB3D_ZSTENCILCNTL       0x1c2c
-#      define RADEON_DEPTH_FORMAT_16BIT_INT_Z  (0 << 0)
-#      define RADEON_DEPTH_FORMAT_24BIT_INT_Z  (2 << 0)
-
-/* CP registers */
-#define RADEON_CP_ME_RAM_ADDR          0x07d4
-#define RADEON_CP_ME_RAM_RADDR         0x07d8
-#define RADEON_CP_ME_RAM_DATAH         0x07dc
-#define RADEON_CP_ME_RAM_DATAL         0x07e0
-
-#define RADEON_CP_RB_BASE              0x0700
-#define RADEON_CP_RB_CNTL              0x0704
-#      define RADEON_BUF_SWAP_32BIT            (2 << 16)
-#      define RADEON_RB_NO_UPDATE              (1 << 27)
-#define RADEON_CP_RB_RPTR_ADDR         0x070c
-#define RADEON_CP_RB_RPTR              0x0710
-#define RADEON_CP_RB_WPTR              0x0714
-
-#define RADEON_CP_RB_WPTR_DELAY                0x0718
-#      define RADEON_PRE_WRITE_TIMER_SHIFT     0
-#      define RADEON_PRE_WRITE_LIMIT_SHIFT     23
-
-#define RADEON_CP_IB_BASE              0x0738
-
-#define RADEON_CP_CSQ_CNTL             0x0740
-#      define RADEON_CSQ_CNT_PRIMARY_MASK      (0xff << 0)
-#      define RADEON_CSQ_PRIDIS_INDDIS         (0 << 28)
-#      define RADEON_CSQ_PRIPIO_INDDIS         (1 << 28)
-#      define RADEON_CSQ_PRIBM_INDDIS          (2 << 28)
-#      define RADEON_CSQ_PRIPIO_INDBM          (3 << 28)
-#      define RADEON_CSQ_PRIBM_INDBM           (4 << 28)
-#      define RADEON_CSQ_PRIPIO_INDPIO         (15 << 28)
-
-#define RADEON_AIC_CNTL                        0x01d0
-#      define RADEON_PCIGART_TRANSLATE_EN      (1 << 0)
-#define RADEON_AIC_STAT                        0x01d4
-#define RADEON_AIC_PT_BASE             0x01d8
-#define RADEON_AIC_LO_ADDR             0x01dc
-#define RADEON_AIC_HI_ADDR             0x01e0
-#define RADEON_AIC_TLB_ADDR            0x01e4
-#define RADEON_AIC_TLB_DATA            0x01e8
-
-/* CP command packets */
-#define RADEON_CP_PACKET0              0x00000000
-#      define RADEON_ONE_REG_WR                (1 << 15)
-#define RADEON_CP_PACKET1              0x40000000
-#define RADEON_CP_PACKET2              0x80000000
-#define RADEON_CP_PACKET3              0xC0000000
-#       define RADEON_CP_NOP                    0x00001000
-#       define RADEON_CP_NEXT_CHAR              0x00001900
-#       define RADEON_CP_PLY_NEXTSCAN           0x00001D00
-#       define RADEON_CP_SET_SCISSORS           0x00001E00
-            /* GEN_INDX_PRIM is unsupported starting with R300 */
-#      define RADEON_3D_RNDR_GEN_INDX_PRIM     0x00002300
-#      define RADEON_WAIT_FOR_IDLE             0x00002600
-#      define RADEON_3D_DRAW_VBUF              0x00002800
-#      define RADEON_3D_DRAW_IMMD              0x00002900
-#      define RADEON_3D_DRAW_INDX              0x00002A00
-#       define RADEON_CP_LOAD_PALETTE           0x00002C00
-#      define RADEON_3D_LOAD_VBPNTR            0x00002F00
-#      define RADEON_MPEG_IDCT_MACROBLOCK      0x00003000
-#      define RADEON_MPEG_IDCT_MACROBLOCK_REV  0x00003100
-#      define RADEON_3D_CLEAR_ZMASK            0x00003200
-#      define RADEON_CP_INDX_BUFFER            0x00003300
-#       define RADEON_CP_3D_DRAW_VBUF_2         0x00003400
-#       define RADEON_CP_3D_DRAW_IMMD_2         0x00003500
-#       define RADEON_CP_3D_DRAW_INDX_2         0x00003600
-#      define RADEON_3D_CLEAR_HIZ              0x00003700
-#       define RADEON_CP_3D_CLEAR_CMASK         0x00003802
-#      define RADEON_CNTL_HOSTDATA_BLT         0x00009400
-#      define RADEON_CNTL_PAINT_MULTI          0x00009A00
-#      define RADEON_CNTL_BITBLT_MULTI         0x00009B00
-#      define RADEON_CNTL_SET_SCISSORS         0xC0001E00
-
-#define RADEON_CP_PACKET_MASK          0xC0000000
-#define RADEON_CP_PACKET_COUNT_MASK    0x3fff0000
-#define RADEON_CP_PACKET0_REG_MASK     0x000007ff
-#define RADEON_CP_PACKET1_REG0_MASK    0x000007ff
-#define RADEON_CP_PACKET1_REG1_MASK    0x003ff800
-
-#define RADEON_VTX_Z_PRESENT                   (1 << 31)
-#define RADEON_VTX_PKCOLOR_PRESENT             (1 << 3)
-
-#define RADEON_PRIM_TYPE_NONE                  (0 << 0)
-#define RADEON_PRIM_TYPE_POINT                 (1 << 0)
-#define RADEON_PRIM_TYPE_LINE                  (2 << 0)
-#define RADEON_PRIM_TYPE_LINE_STRIP            (3 << 0)
-#define RADEON_PRIM_TYPE_TRI_LIST              (4 << 0)
-#define RADEON_PRIM_TYPE_TRI_FAN               (5 << 0)
-#define RADEON_PRIM_TYPE_TRI_STRIP             (6 << 0)
-#define RADEON_PRIM_TYPE_TRI_TYPE2             (7 << 0)
-#define RADEON_PRIM_TYPE_RECT_LIST             (8 << 0)
-#define RADEON_PRIM_TYPE_3VRT_POINT_LIST       (9 << 0)
-#define RADEON_PRIM_TYPE_3VRT_LINE_LIST                (10 << 0)
-#define RADEON_PRIM_TYPE_MASK                   0xf
-#define RADEON_PRIM_WALK_IND                   (1 << 4)
-#define RADEON_PRIM_WALK_LIST                  (2 << 4)
-#define RADEON_PRIM_WALK_RING                  (3 << 4)
-#define RADEON_COLOR_ORDER_BGRA                        (0 << 6)
-#define RADEON_COLOR_ORDER_RGBA                        (1 << 6)
-#define RADEON_MAOS_ENABLE                     (1 << 7)
-#define RADEON_VTX_FMT_R128_MODE               (0 << 8)
-#define RADEON_VTX_FMT_RADEON_MODE             (1 << 8)
-#define RADEON_NUM_VERTICES_SHIFT              16
-
-#define RADEON_COLOR_FORMAT_CI8                2
-#define RADEON_COLOR_FORMAT_ARGB1555   3
-#define RADEON_COLOR_FORMAT_RGB565     4
-#define RADEON_COLOR_FORMAT_ARGB8888   6
-#define RADEON_COLOR_FORMAT_RGB332     7
-#define RADEON_COLOR_FORMAT_RGB8       9
-#define RADEON_COLOR_FORMAT_ARGB4444   15
-
-#define RADEON_TXFORMAT_I8             0
-#define RADEON_TXFORMAT_AI88           1
-#define RADEON_TXFORMAT_RGB332         2
-#define RADEON_TXFORMAT_ARGB1555       3
-#define RADEON_TXFORMAT_RGB565         4
-#define RADEON_TXFORMAT_ARGB4444       5
-#define RADEON_TXFORMAT_ARGB8888       6
-#define RADEON_TXFORMAT_RGBA8888       7
-#define RADEON_TXFORMAT_Y8             8
-#define RADEON_TXFORMAT_VYUY422         10
-#define RADEON_TXFORMAT_YVYU422         11
-#define RADEON_TXFORMAT_DXT1            12
-#define RADEON_TXFORMAT_DXT23           14
-#define RADEON_TXFORMAT_DXT45           15
-
-#define R200_PP_TXCBLEND_0                0x2f00
-#define R200_PP_TXCBLEND_1                0x2f10
-#define R200_PP_TXCBLEND_2                0x2f20
-#define R200_PP_TXCBLEND_3                0x2f30
-#define R200_PP_TXCBLEND_4                0x2f40
-#define R200_PP_TXCBLEND_5                0x2f50
-#define R200_PP_TXCBLEND_6                0x2f60
-#define R200_PP_TXCBLEND_7                0x2f70
-#define R200_SE_TCL_LIGHT_MODEL_CTL_0     0x2268
-#define R200_PP_TFACTOR_0                 0x2ee0
-#define R200_SE_VTX_FMT_0                 0x2088
-#define R200_SE_VAP_CNTL                  0x2080
-#define R200_SE_TCL_MATRIX_SEL_0          0x2230
-#define R200_SE_TCL_TEX_PROC_CTL_2        0x22a8
-#define R200_SE_TCL_UCP_VERT_BLEND_CTL    0x22c0
-#define R200_PP_TXFILTER_5                0x2ca0
-#define R200_PP_TXFILTER_4                0x2c80
-#define R200_PP_TXFILTER_3                0x2c60
-#define R200_PP_TXFILTER_2                0x2c40
-#define R200_PP_TXFILTER_1                0x2c20
-#define R200_PP_TXFILTER_0                0x2c00
-#define R200_PP_TXOFFSET_5                0x2d78
-#define R200_PP_TXOFFSET_4                0x2d60
-#define R200_PP_TXOFFSET_3                0x2d48
-#define R200_PP_TXOFFSET_2                0x2d30
-#define R200_PP_TXOFFSET_1                0x2d18
-#define R200_PP_TXOFFSET_0                0x2d00
-
-#define R200_PP_CUBIC_FACES_0             0x2c18
-#define R200_PP_CUBIC_FACES_1             0x2c38
-#define R200_PP_CUBIC_FACES_2             0x2c58
-#define R200_PP_CUBIC_FACES_3             0x2c78
-#define R200_PP_CUBIC_FACES_4             0x2c98
-#define R200_PP_CUBIC_FACES_5             0x2cb8
-#define R200_PP_CUBIC_OFFSET_F1_0         0x2d04
-#define R200_PP_CUBIC_OFFSET_F2_0         0x2d08
-#define R200_PP_CUBIC_OFFSET_F3_0         0x2d0c
-#define R200_PP_CUBIC_OFFSET_F4_0         0x2d10
-#define R200_PP_CUBIC_OFFSET_F5_0         0x2d14
-#define R200_PP_CUBIC_OFFSET_F1_1         0x2d1c
-#define R200_PP_CUBIC_OFFSET_F2_1         0x2d20
-#define R200_PP_CUBIC_OFFSET_F3_1         0x2d24
-#define R200_PP_CUBIC_OFFSET_F4_1         0x2d28
-#define R200_PP_CUBIC_OFFSET_F5_1         0x2d2c
-#define R200_PP_CUBIC_OFFSET_F1_2         0x2d34
-#define R200_PP_CUBIC_OFFSET_F2_2         0x2d38
-#define R200_PP_CUBIC_OFFSET_F3_2         0x2d3c
-#define R200_PP_CUBIC_OFFSET_F4_2         0x2d40
-#define R200_PP_CUBIC_OFFSET_F5_2         0x2d44
-#define R200_PP_CUBIC_OFFSET_F1_3         0x2d4c
-#define R200_PP_CUBIC_OFFSET_F2_3         0x2d50
-#define R200_PP_CUBIC_OFFSET_F3_3         0x2d54
-#define R200_PP_CUBIC_OFFSET_F4_3         0x2d58
-#define R200_PP_CUBIC_OFFSET_F5_3         0x2d5c
-#define R200_PP_CUBIC_OFFSET_F1_4         0x2d64
-#define R200_PP_CUBIC_OFFSET_F2_4         0x2d68
-#define R200_PP_CUBIC_OFFSET_F3_4         0x2d6c
-#define R200_PP_CUBIC_OFFSET_F4_4         0x2d70
-#define R200_PP_CUBIC_OFFSET_F5_4         0x2d74
-#define R200_PP_CUBIC_OFFSET_F1_5         0x2d7c
-#define R200_PP_CUBIC_OFFSET_F2_5         0x2d80
-#define R200_PP_CUBIC_OFFSET_F3_5         0x2d84
-#define R200_PP_CUBIC_OFFSET_F4_5         0x2d88
-#define R200_PP_CUBIC_OFFSET_F5_5         0x2d8c
-
-#define R200_RE_AUX_SCISSOR_CNTL          0x26f0
-#define R200_SE_VTE_CNTL                  0x20b0
-#define R200_SE_TCL_OUTPUT_VTX_COMP_SEL   0x2250
-#define R200_PP_TAM_DEBUG3                0x2d9c
-#define R200_PP_CNTL_X                    0x2cc4
-#define R200_SE_VAP_CNTL_STATUS           0x2140
-#define R200_RE_SCISSOR_TL_0              0x1cd8
-#define R200_RE_SCISSOR_TL_1              0x1ce0
-#define R200_RE_SCISSOR_TL_2              0x1ce8
-#define R200_RB3D_DEPTHXY_OFFSET          0x1d60
-#define R200_RE_AUX_SCISSOR_CNTL          0x26f0
-#define R200_SE_VTX_STATE_CNTL            0x2180
-#define R200_RE_POINTSIZE                 0x2648
-#define R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0 0x2254
-
-#define RADEON_PP_TEX_SIZE_0                0x1d04     /* NPOT */
-#define RADEON_PP_TEX_SIZE_1                0x1d0c
-#define RADEON_PP_TEX_SIZE_2                0x1d14
-
-#define RADEON_PP_CUBIC_FACES_0             0x1d24
-#define RADEON_PP_CUBIC_FACES_1             0x1d28
-#define RADEON_PP_CUBIC_FACES_2             0x1d2c
-#define RADEON_PP_CUBIC_OFFSET_T0_0         0x1dd0     /* bits [31:5] */
-#define RADEON_PP_CUBIC_OFFSET_T1_0         0x1e00
-#define RADEON_PP_CUBIC_OFFSET_T2_0         0x1e14
-
-#define RADEON_SE_TCL_STATE_FLUSH           0x2284
-
-#define SE_VAP_CNTL__TCL_ENA_MASK                          0x00000001
-#define SE_VAP_CNTL__FORCE_W_TO_ONE_MASK                   0x00010000
-#define SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT                 0x00000012
-#define SE_VTE_CNTL__VTX_XY_FMT_MASK                       0x00000100
-#define SE_VTE_CNTL__VTX_Z_FMT_MASK                        0x00000200
-#define SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK                  0x00000001
-#define SE_VTX_FMT_0__VTX_W0_PRESENT_MASK                  0x00000002
-#define SE_VTX_FMT_0__VTX_COLOR_0_FMT__SHIFT               0x0000000b
-#define R200_3D_DRAW_IMMD_2      0xC0003500
-#define R200_SE_VTX_FMT_1                 0x208c
-#define R200_RE_CNTL                      0x1c50
-
-#define R200_RB3D_BLENDCOLOR              0x3218
-
-#define R200_SE_TCL_POINT_SPRITE_CNTL     0x22c4
-
-#define R200_PP_TRI_PERF 0x2cf8
-
-#define R200_PP_AFS_0                     0x2f80
-#define R200_PP_AFS_1                     0x2f00       /* same as txcblend_0 */
-
-#define R200_VAP_PVS_CNTL_1               0x22D0
-
-#define R500_D1CRTC_STATUS 0x609c
-#define R500_D2CRTC_STATUS 0x689c
-#define R500_CRTC_V_BLANK (1<<0)
-
-#define R500_D1CRTC_FRAME_COUNT 0x60a4
-#define R500_D2CRTC_FRAME_COUNT 0x68a4
-
-#define R500_D1MODE_V_COUNTER 0x6530
-#define R500_D2MODE_V_COUNTER 0x6d30
-
-#define R500_D1MODE_VBLANK_STATUS 0x6534
-#define R500_D2MODE_VBLANK_STATUS 0x6d34
-#define R500_VBLANK_OCCURED (1<<0)
-#define R500_VBLANK_ACK     (1<<4)
-#define R500_VBLANK_STAT    (1<<12)
-#define R500_VBLANK_INT     (1<<16)
-
-#define R500_DxMODE_INT_MASK 0x6540
-#define R500_D1MODE_INT_MASK (1<<0)
-#define R500_D2MODE_INT_MASK (1<<8)
-
-#define R500_DISP_INTERRUPT_STATUS 0x7edc
-#define R500_D1_VBLANK_INTERRUPT (1 << 4)
-#define R500_D2_VBLANK_INTERRUPT (1 << 5)
-
-/* Constants */
-#define RADEON_MAX_USEC_TIMEOUT                100000  /* 100 ms */
-
-#define RADEON_LAST_FRAME_REG          RADEON_SCRATCH_REG0
-#define RADEON_LAST_DISPATCH_REG       RADEON_SCRATCH_REG1
-#define RADEON_LAST_CLEAR_REG          RADEON_SCRATCH_REG2
-#define RADEON_LAST_SWI_REG            RADEON_SCRATCH_REG3
-#define RADEON_LAST_DISPATCH           1
-
-#define RADEON_MAX_VB_AGE              0x7fffffff
-#define RADEON_MAX_VB_VERTS            (0xffff)
-
-#define RADEON_RING_HIGH_MARK          128
-
-#define RADEON_PCIGART_TABLE_SIZE      (32*1024)
-
-#define RADEON_READ(reg)       DRM_READ32(  dev_priv->mmio, (reg) )
-#define RADEON_WRITE(reg,val)  DRM_WRITE32( dev_priv->mmio, (reg), (val) )
-#define RADEON_READ8(reg)      DRM_READ8(  dev_priv->mmio, (reg) )
-#define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, (reg), (val) )
-
-#define RADEON_WRITE_PLL(addr, val)                                    \
-do {                                                                   \
-       RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX,                          \
-                      ((addr) & 0x1f) | RADEON_PLL_WR_EN );            \
-       RADEON_WRITE(RADEON_CLOCK_CNTL_DATA, (val));                    \
-} while (0)
-
-#define RADEON_WRITE_PCIE(addr, val)                                   \
-do {                                                                   \
-       RADEON_WRITE8(RADEON_PCIE_INDEX,                                \
-                       ((addr) & 0xff));                               \
-       RADEON_WRITE(RADEON_PCIE_DATA, (val));                  \
-} while (0)
-
-#define R500_WRITE_MCIND(addr, val)                                    \
-do {                                                           \
-       RADEON_WRITE(R520_MC_IND_INDEX, 0xff0000 | ((addr) & 0xff));    \
-       RADEON_WRITE(R520_MC_IND_DATA, (val));                  \
-       RADEON_WRITE(R520_MC_IND_INDEX, 0);     \
-} while (0)
-
-#define RS480_WRITE_MCIND(addr, val)                           \
-do {                                                                   \
-       RADEON_WRITE(RS480_NB_MC_INDEX,                         \
-                       ((addr) & 0xff) | RS480_NB_MC_IND_WR_EN);       \
-       RADEON_WRITE(RS480_NB_MC_DATA, (val));                  \
-       RADEON_WRITE(RS480_NB_MC_INDEX, 0xff);                  \
-} while (0)
-
-#define RS690_WRITE_MCIND(addr, val)                                   \
-do {                                                           \
-       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_EN | ((addr) & RS690_MC_INDEX_MASK));    \
-       RADEON_WRITE(RS690_MC_DATA, val);                       \
-       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_ACK);    \
-} while (0)
-
-#define IGP_WRITE_MCIND(addr, val)                             \
-do {                                                                   \
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)       \
-               RS690_WRITE_MCIND(addr, val);                           \
-       else                                                            \
-               RS480_WRITE_MCIND(addr, val);                           \
-} while (0)
-
-#define CP_PACKET0( reg, n )                                           \
-       (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
-#define CP_PACKET0_TABLE( reg, n )                                     \
-       (RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
-#define CP_PACKET1( reg0, reg1 )                                       \
-       (RADEON_CP_PACKET1 | (((reg1) >> 2) << 15) | ((reg0) >> 2))
-#define CP_PACKET2()                                                   \
-       (RADEON_CP_PACKET2)
-#define CP_PACKET3( pkt, n )                                           \
-       (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
-
-/* ================================================================
- * Engine control helper macros
- */
-
-#define RADEON_WAIT_UNTIL_2D_IDLE() do {                               \
-       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
-       OUT_RING( (RADEON_WAIT_2D_IDLECLEAN |                           \
-                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
-} while (0)
-
-#define RADEON_WAIT_UNTIL_3D_IDLE() do {                               \
-       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
-       OUT_RING( (RADEON_WAIT_3D_IDLECLEAN |                           \
-                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
-} while (0)
-
-#define RADEON_WAIT_UNTIL_IDLE() do {                                  \
-       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
-       OUT_RING( (RADEON_WAIT_2D_IDLECLEAN |                           \
-                  RADEON_WAIT_3D_IDLECLEAN |                           \
-                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
-} while (0)
-
-#define RADEON_WAIT_UNTIL_PAGE_FLIPPED() do {                          \
-       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
-       OUT_RING( RADEON_WAIT_CRTC_PFLIP );                             \
-} while (0)
-
-#define RADEON_FLUSH_CACHE() do {                                      \
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
-               OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));  \
-               OUT_RING(RADEON_RB3D_DC_FLUSH);                         \
-       } else {                                                        \
-               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
-               OUT_RING(RADEON_RB3D_DC_FLUSH);                         \
-       }                                                               \
-} while (0)
-
-#define RADEON_PURGE_CACHE() do {                                      \
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
-               OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));  \
-               OUT_RING(RADEON_RB3D_DC_FLUSH_ALL);                     \
-       } else {                                                        \
-               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
-               OUT_RING(RADEON_RB3D_DC_FLUSH_ALL);                     \
-       }                                                               \
-} while (0)
-
-#define RADEON_FLUSH_ZCACHE() do {                                     \
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
-               OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));    \
-               OUT_RING(RADEON_RB3D_ZC_FLUSH);                         \
-       } else {                                                        \
-               OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0));        \
-               OUT_RING(R300_ZC_FLUSH);                                \
-       }                                                               \
-} while (0)
-
-#define RADEON_PURGE_ZCACHE() do {                                     \
-       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
-               OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));    \
-               OUT_RING(RADEON_RB3D_ZC_FLUSH_ALL);                     \
-       } else {                                                        \
-               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
-               OUT_RING(R300_ZC_FLUSH_ALL);                            \
-       }                                                               \
-} while (0)
-
-/* ================================================================
- * Misc helper macros
- */
-
-/* Perfbox functionality only.
- */
-#define RING_SPACE_TEST_WITH_RETURN( dev_priv )                                \
-do {                                                                   \
-       if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE)) {           \
-               u32 head = GET_RING_HEAD( dev_priv );                   \
-               if (head == dev_priv->ring.tail)                        \
-                       dev_priv->stats.boxes |= RADEON_BOX_DMA_IDLE;   \
-       }                                                               \
-} while (0)
-
-#define VB_AGE_TEST_WITH_RETURN( dev_priv )                            \
-do {                                                                   \
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;          \
-       if ( sarea_priv->last_dispatch >= RADEON_MAX_VB_AGE ) {         \
-               int __ret = radeon_do_cp_idle( dev_priv );              \
-               if ( __ret ) return __ret;                              \
-               sarea_priv->last_dispatch = 0;                          \
-               radeon_freelist_reset( dev );                           \
-       }                                                               \
-} while (0)
-
-#define RADEON_DISPATCH_AGE( age ) do {                                        \
-       OUT_RING( CP_PACKET0( RADEON_LAST_DISPATCH_REG, 0 ) );          \
-       OUT_RING( age );                                                \
-} while (0)
-
-#define RADEON_FRAME_AGE( age ) do {                                   \
-       OUT_RING( CP_PACKET0( RADEON_LAST_FRAME_REG, 0 ) );             \
-       OUT_RING( age );                                                \
-} while (0)
-
-#define RADEON_CLEAR_AGE( age ) do {                                   \
-       OUT_RING( CP_PACKET0( RADEON_LAST_CLEAR_REG, 0 ) );             \
-       OUT_RING( age );                                                \
-} while (0)
-
-/* ================================================================
- * Ring control
- */
-
-#define RADEON_VERBOSE 0
-
-#define RING_LOCALS    int write, _nr; unsigned int mask; u32 *ring;
-
-#define BEGIN_RING( n ) do {                                           \
-       if ( RADEON_VERBOSE ) {                                         \
-               DRM_INFO( "BEGIN_RING( %d )\n", (n));                   \
-       }                                                               \
-       if ( dev_priv->ring.space <= (n) * sizeof(u32) ) {              \
-                COMMIT_RING();                                         \
-               radeon_wait_ring( dev_priv, (n) * sizeof(u32) );        \
-       }                                                               \
-       _nr = n; dev_priv->ring.space -= (n) * sizeof(u32);             \
-       ring = dev_priv->ring.start;                                    \
-       write = dev_priv->ring.tail;                                    \
-       mask = dev_priv->ring.tail_mask;                                \
-} while (0)
-
-#define ADVANCE_RING() do {                                            \
-       if ( RADEON_VERBOSE ) {                                         \
-               DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",     \
-                         write, dev_priv->ring.tail );                 \
-       }                                                               \
-       if (((dev_priv->ring.tail + _nr) & mask) != write) {            \
-               DRM_ERROR(                                              \
-                       "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n",        \
-                       ((dev_priv->ring.tail + _nr) & mask),           \
-                       write, __LINE__);                                               \
-       } else                                                          \
-               dev_priv->ring.tail = write;                            \
-} while (0)
-
-#define COMMIT_RING() do {                                             \
-       /* Flush writes to ring */                                      \
-       DRM_MEMORYBARRIER();                                            \
-       GET_RING_HEAD( dev_priv );                                      \
-       RADEON_WRITE( RADEON_CP_RB_WPTR, dev_priv->ring.tail );         \
-       /* read from PCI bus to ensure correct posting */               \
-       RADEON_READ( RADEON_CP_RB_RPTR );                               \
-} while (0)
-
-#define OUT_RING( x ) do {                                             \
-       if ( RADEON_VERBOSE ) {                                         \
-               DRM_INFO( "   OUT_RING( 0x%08x ) at 0x%x\n",            \
-                          (unsigned int)(x), write );                  \
-       }                                                               \
-       ring[write++] = (x);                                            \
-       write &= mask;                                                  \
-} while (0)
-
-#define OUT_RING_REG( reg, val ) do {                                  \
-       OUT_RING( CP_PACKET0( reg, 0 ) );                               \
-       OUT_RING( val );                                                \
-} while (0)
-
-#define OUT_RING_TABLE( tab, sz ) do {                                 \
-       int _size = (sz);                                       \
-       int *_tab = (int *)(tab);                               \
-                                                               \
-       if (write + _size > mask) {                             \
-               int _i = (mask+1) - write;                      \
-               _size -= _i;                                    \
-               while (_i > 0 ) {                               \
-                       *(int *)(ring + write) = *_tab++;       \
-                       write++;                                \
-                       _i--;                                   \
-               }                                               \
-               write = 0;                                      \
-               _tab += _i;                                     \
-       }                                                       \
-       while (_size > 0) {                                     \
-               *(ring + write) = *_tab++;                      \
-               write++;                                        \
-               _size--;                                        \
-       }                                                       \
-       write &= mask;                                          \
-} while (0)
-
-#endif                         /* __RADEON_DRV_H__ */
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
deleted file mode 100644 (file)
index 56decda..0000000
+++ /dev/null
@@ -1,424 +0,0 @@
-/**
- * \file radeon_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the Radeon DRM.
- *
- * \author Paul Mackerras <paulus@samba.org>
- *
- * Copyright (C) Paul Mackerras 2005
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-
-typedef struct drm_radeon_init32 {
-       int func;
-       u32 sarea_priv_offset;
-       int is_pci;
-       int cp_mode;
-       int gart_size;
-       int ring_size;
-       int usec_timeout;
-
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-
-       u32 fb_offset;
-       u32 mmio_offset;
-       u32 ring_offset;
-       u32 ring_rptr_offset;
-       u32 buffers_offset;
-       u32 gart_textures_offset;
-} drm_radeon_init32_t;
-
-static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
-                                unsigned long arg)
-{
-       drm_radeon_init32_t init32;
-       drm_radeon_init_t __user *init;
-
-       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
-               return -EFAULT;
-
-       init = compat_alloc_user_space(sizeof(*init));
-       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
-           || __put_user(init32.func, &init->func)
-           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
-           || __put_user(init32.is_pci, &init->is_pci)
-           || __put_user(init32.cp_mode, &init->cp_mode)
-           || __put_user(init32.gart_size, &init->gart_size)
-           || __put_user(init32.ring_size, &init->ring_size)
-           || __put_user(init32.usec_timeout, &init->usec_timeout)
-           || __put_user(init32.fb_bpp, &init->fb_bpp)
-           || __put_user(init32.front_offset, &init->front_offset)
-           || __put_user(init32.front_pitch, &init->front_pitch)
-           || __put_user(init32.back_offset, &init->back_offset)
-           || __put_user(init32.back_pitch, &init->back_pitch)
-           || __put_user(init32.depth_bpp, &init->depth_bpp)
-           || __put_user(init32.depth_offset, &init->depth_offset)
-           || __put_user(init32.depth_pitch, &init->depth_pitch)
-           || __put_user(init32.fb_offset, &init->fb_offset)
-           || __put_user(init32.mmio_offset, &init->mmio_offset)
-           || __put_user(init32.ring_offset, &init->ring_offset)
-           || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
-           || __put_user(init32.buffers_offset, &init->buffers_offset)
-           || __put_user(init32.gart_textures_offset,
-                         &init->gart_textures_offset))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
-}
-
-typedef struct drm_radeon_clear32 {
-       unsigned int flags;
-       unsigned int clear_color;
-       unsigned int clear_depth;
-       unsigned int color_mask;
-       unsigned int depth_mask;        /* misnamed field:  should be stencil */
-       u32 depth_boxes;
-} drm_radeon_clear32_t;
-
-static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
-                                 unsigned long arg)
-{
-       drm_radeon_clear32_t clr32;
-       drm_radeon_clear_t __user *clr;
-
-       if (copy_from_user(&clr32, (void __user *)arg, sizeof(clr32)))
-               return -EFAULT;
-
-       clr = compat_alloc_user_space(sizeof(*clr));
-       if (!access_ok(VERIFY_WRITE, clr, sizeof(*clr))
-           || __put_user(clr32.flags, &clr->flags)
-           || __put_user(clr32.clear_color, &clr->clear_color)
-           || __put_user(clr32.clear_depth, &clr->clear_depth)
-           || __put_user(clr32.color_mask, &clr->color_mask)
-           || __put_user(clr32.depth_mask, &clr->depth_mask)
-           || __put_user((void __user *)(unsigned long)clr32.depth_boxes,
-                         &clr->depth_boxes))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
-}
-
-typedef struct drm_radeon_stipple32 {
-       u32 mask;
-} drm_radeon_stipple32_t;
-
-static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
-                                   unsigned long arg)
-{
-       drm_radeon_stipple32_t __user *argp = (void __user *)arg;
-       drm_radeon_stipple_t __user *request;
-       u32 mask;
-
-       if (get_user(mask, &argp->mask))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user((unsigned int __user *)(unsigned long)mask,
-                         &request->mask))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
-}
-
-typedef struct drm_radeon_tex_image32 {
-       unsigned int x, y;      /* Blit coordinates */
-       unsigned int width, height;
-       u32 data;
-} drm_radeon_tex_image32_t;
-
-typedef struct drm_radeon_texture32 {
-       unsigned int offset;
-       int pitch;
-       int format;
-       int width;              /* Texture image coordinates */
-       int height;
-       u32 image;
-} drm_radeon_texture32_t;
-
-static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
-                                   unsigned long arg)
-{
-       drm_radeon_texture32_t req32;
-       drm_radeon_texture_t __user *request;
-       drm_radeon_tex_image32_t img32;
-       drm_radeon_tex_image_t __user *image;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-       if (req32.image == 0)
-               return -EINVAL;
-       if (copy_from_user(&img32, (void __user *)(unsigned long)req32.image,
-                          sizeof(img32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request) + sizeof(*image));
-       if (!access_ok(VERIFY_WRITE, request,
-                      sizeof(*request) + sizeof(*image)))
-               return -EFAULT;
-       image = (drm_radeon_tex_image_t __user *) (request + 1);
-
-       if (__put_user(req32.offset, &request->offset)
-           || __put_user(req32.pitch, &request->pitch)
-           || __put_user(req32.format, &request->format)
-           || __put_user(req32.width, &request->width)
-           || __put_user(req32.height, &request->height)
-           || __put_user(image, &request->image)
-           || __put_user(img32.x, &image->x)
-           || __put_user(img32.y, &image->y)
-           || __put_user(img32.width, &image->width)
-           || __put_user(img32.height, &image->height)
-           || __put_user((const void __user *)(unsigned long)img32.data,
-                         &image->data))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
-}
-
-typedef struct drm_radeon_vertex2_32 {
-       int idx;                /* Index of vertex buffer */
-       int discard;            /* Client finished with buffer? */
-       int nr_states;
-       u32 state;
-       int nr_prims;
-       u32 prim;
-} drm_radeon_vertex2_32_t;
-
-static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
-                                   unsigned long arg)
-{
-       drm_radeon_vertex2_32_t req32;
-       drm_radeon_vertex2_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.idx, &request->idx)
-           || __put_user(req32.discard, &request->discard)
-           || __put_user(req32.nr_states, &request->nr_states)
-           || __put_user((void __user *)(unsigned long)req32.state,
-                         &request->state)
-           || __put_user(req32.nr_prims, &request->nr_prims)
-           || __put_user((void __user *)(unsigned long)req32.prim,
-                         &request->prim))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
-}
-
-typedef struct drm_radeon_cmd_buffer32 {
-       int bufsz;
-       u32 buf;
-       int nbox;
-       u32 boxes;
-} drm_radeon_cmd_buffer32_t;
-
-static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
-                                  unsigned long arg)
-{
-       drm_radeon_cmd_buffer32_t req32;
-       drm_radeon_cmd_buffer_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.bufsz, &request->bufsz)
-           || __put_user((void __user *)(unsigned long)req32.buf,
-                         &request->buf)
-           || __put_user(req32.nbox, &request->nbox)
-           || __put_user((void __user *)(unsigned long)req32.boxes,
-                         &request->boxes))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
-}
-
-typedef struct drm_radeon_getparam32 {
-       int param;
-       u32 value;
-} drm_radeon_getparam32_t;
-
-static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
-                                    unsigned long arg)
-{
-       drm_radeon_getparam32_t req32;
-       drm_radeon_getparam_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.param, &request->param)
-           || __put_user((void __user *)(unsigned long)req32.value,
-                         &request->value))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
-}
-
-typedef struct drm_radeon_mem_alloc32 {
-       int region;
-       int alignment;
-       int size;
-       u32 region_offset;      /* offset from start of fb or GART */
-} drm_radeon_mem_alloc32_t;
-
-static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
-                                  unsigned long arg)
-{
-       drm_radeon_mem_alloc32_t req32;
-       drm_radeon_mem_alloc_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.region, &request->region)
-           || __put_user(req32.alignment, &request->alignment)
-           || __put_user(req32.size, &request->size)
-           || __put_user((int __user *)(unsigned long)req32.region_offset,
-                         &request->region_offset))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
-}
-
-typedef struct drm_radeon_irq_emit32 {
-       u32 irq_seq;
-} drm_radeon_irq_emit32_t;
-
-static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
-                                 unsigned long arg)
-{
-       drm_radeon_irq_emit32_t req32;
-       drm_radeon_irq_emit_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user((int __user *)(unsigned long)req32.irq_seq,
-                         &request->irq_seq))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_path.dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
-}
-
-/* The two 64-bit arches where alignof(u64)==4 in 32-bit code */
-#if defined (CONFIG_X86_64) || defined(CONFIG_IA64)
-typedef struct drm_radeon_setparam32 {
-       int param;
-       u64 value;
-} __attribute__((packed)) drm_radeon_setparam32_t;
-
-static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
-                                    unsigned long arg)
-{
-       drm_radeon_setparam32_t req32;
-       drm_radeon_setparam_t __user *request;
-
-       if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
-               return -EFAULT;
-
-       request = compat_alloc_user_space(sizeof(*request));
-       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
-           || __put_user(req32.param, &request->param)
-           || __put_user((void __user *)(unsigned long)req32.value,
-                         &request->value))
-               return -EFAULT;
-
-       return drm_ioctl(file->f_dentry->d_inode, file,
-                        DRM_IOCTL_RADEON_SETPARAM, (unsigned long) request);
-}
-#else
-#define compat_radeon_cp_setparam NULL
-#endif /* X86_64 || IA64 */
-
-drm_ioctl_compat_t *radeon_compat_ioctls[] = {
-       [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
-       [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
-       [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
-       [DRM_RADEON_TEXTURE] = compat_radeon_cp_texture,
-       [DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
-       [DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
-       [DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
-       [DRM_RADEON_SETPARAM] = compat_radeon_cp_setparam,
-       [DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
-       [DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
-};
-
-/**
- * Called whenever a 32-bit process running under a 64-bit kernel
- * performs an ioctl on /dev/dri/card<n>.
- *
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument.
- * \return zero on success or negative number on failure.
- */
-long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-       unsigned int nr = DRM_IOCTL_NR(cmd);
-       drm_ioctl_compat_t *fn = NULL;
-       int ret;
-
-       if (nr < DRM_COMMAND_BASE)
-               return drm_compat_ioctl(filp, cmd, arg);
-
-       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
-               fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
-
-       lock_kernel();          /* XXX for now */
-       if (fn != NULL)
-               ret = (*fn) (filp, cmd, arg);
-       else
-               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
-       unlock_kernel();
-
-       return ret;
-}
diff --git a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
deleted file mode 100644 (file)
index ee40d19..0000000
+++ /dev/null
@@ -1,320 +0,0 @@
-/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */
-/*
- * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
- *
- * The Weather Channel (TM) funded Tungsten Graphics to develop the
- * initial release of the Radeon 8500 driver under the XFree86 license.
- * This notice must be preserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
- *    Michel Dänzer <michel@daenzer.net>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-
-static __inline__ u32 radeon_acknowledge_irqs(drm_radeon_private_t * dev_priv,
-                                             u32 mask)
-{
-       u32 irqs = RADEON_READ(RADEON_GEN_INT_STATUS) & mask;
-       if (irqs)
-               RADEON_WRITE(RADEON_GEN_INT_STATUS, irqs);
-       return irqs;
-}
-
-/* Interrupts - Used for device synchronization and flushing in the
- * following circumstances:
- *
- * - Exclusive FB access with hw idle:
- *    - Wait for GUI Idle (?) interrupt, then do normal flush.
- *
- * - Frame throttling, NV_fence:
- *    - Drop marker irq's into command stream ahead of time.
- *    - Wait on irq's with lock *not held*
- *    - Check each for termination condition
- *
- * - Internally in cp_getbuffer, etc:
- *    - as above, but wait with lock held???
- *
- * NOTE: These functions are misleadingly named -- the irq's aren't
- * tied to dma at all, this is just a hangover from dri prehistory.
- */
-
-irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-       u32 stat;
-
-       /* Only consider the bits we're interested in - others could be used
-        * outside the DRM
-        */
-       stat = radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
-                                                 RADEON_CRTC_VBLANK_STAT |
-                                                 RADEON_CRTC2_VBLANK_STAT));
-       if (!stat)
-               return IRQ_NONE;
-
-       stat &= dev_priv->irq_enable_reg;
-
-       /* SW interrupt */
-       if (stat & RADEON_SW_INT_TEST) {
-               DRM_WAKEUP(&dev_priv->swi_queue);
-       }
-
-       /* VBLANK interrupt */
-       if (stat & (RADEON_CRTC_VBLANK_STAT|RADEON_CRTC2_VBLANK_STAT)) {
-               int vblank_crtc = dev_priv->vblank_crtc;
-
-               if ((vblank_crtc &
-                    (DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) ==
-                   (DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) {
-                       if (stat & RADEON_CRTC_VBLANK_STAT)
-                               atomic_inc(&dev->vbl_received);
-                       if (stat & RADEON_CRTC2_VBLANK_STAT)
-                               atomic_inc(&dev->vbl_received2);
-               } else if (((stat & RADEON_CRTC_VBLANK_STAT) &&
-                          (vblank_crtc & DRM_RADEON_VBLANK_CRTC1)) ||
-                          ((stat & RADEON_CRTC2_VBLANK_STAT) &&
-                           (vblank_crtc & DRM_RADEON_VBLANK_CRTC2)))
-                       atomic_inc(&dev->vbl_received);
-
-               DRM_WAKEUP(&dev->vbl_queue);
-               drm_vbl_send_signals(dev);
-       }
-
-       return IRQ_HANDLED;
-}
-
-static int radeon_emit_irq(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       unsigned int ret;
-       RING_LOCALS;
-
-       atomic_inc(&dev_priv->swi_emitted);
-       ret = atomic_read(&dev_priv->swi_emitted);
-
-       BEGIN_RING(4);
-       OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
-       OUT_RING_REG(RADEON_GEN_INT_STATUS, RADEON_SW_INT_FIRE);
-       ADVANCE_RING();
-       COMMIT_RING();
-
-       return ret;
-}
-
-static int radeon_wait_irq(struct drm_device * dev, int swi_nr)
-{
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-       int ret = 0;
-
-       if (RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr)
-               return 0;
-
-       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-       DRM_WAIT_ON(ret, dev_priv->swi_queue, 3 * DRM_HZ,
-                   RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr);
-
-       return ret;
-}
-
-static int radeon_driver_vblank_do_wait(struct drm_device * dev,
-                                       unsigned int *sequence, int crtc)
-{
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-       unsigned int cur_vblank;
-       int ret = 0;
-       int ack = 0;
-       atomic_t *counter;
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       if (crtc == DRM_RADEON_VBLANK_CRTC1) {
-               counter = &dev->vbl_received;
-               ack |= RADEON_CRTC_VBLANK_STAT;
-       } else if (crtc == DRM_RADEON_VBLANK_CRTC2) {
-               counter = &dev->vbl_received2;
-               ack |= RADEON_CRTC2_VBLANK_STAT;
-       } else
-               return -EINVAL;
-
-       radeon_acknowledge_irqs(dev_priv, ack);
-
-       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-
-       /* Assume that the user has missed the current sequence number
-        * by about a day rather than she wants to wait for years
-        * using vertical blanks...
-        */
-       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
-                   (((cur_vblank = atomic_read(counter))
-                     - *sequence) <= (1 << 23)));
-
-       *sequence = cur_vblank;
-
-       return ret;
-}
-
-int radeon_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
-{
-       return radeon_driver_vblank_do_wait(dev, sequence, DRM_RADEON_VBLANK_CRTC1);
-}
-
-int radeon_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
-{
-       return radeon_driver_vblank_do_wait(dev, sequence, DRM_RADEON_VBLANK_CRTC2);
-}
-
-/* Needs the lock as it touches the ring.
- */
-int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_irq_emit_t *emit = data;
-       int result;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       result = radeon_emit_irq(dev);
-
-       if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-/* Doesn't need the hardware lock.
- */
-int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_irq_wait_t *irqwait = data;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       return radeon_wait_irq(dev, irqwait->irq_seq);
-}
-
-void radeon_enable_interrupt(struct drm_device *dev)
-{
-       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
-
-       dev_priv->irq_enable_reg = RADEON_SW_INT_ENABLE;
-       if (dev_priv->vblank_crtc & DRM_RADEON_VBLANK_CRTC1)
-               dev_priv->irq_enable_reg |= RADEON_CRTC_VBLANK_MASK;
-
-       if (dev_priv->vblank_crtc & DRM_RADEON_VBLANK_CRTC2)
-               dev_priv->irq_enable_reg |= RADEON_CRTC2_VBLANK_MASK;
-
-       RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg);
-       dev_priv->irq_enabled = 1;
-}
-
-/* drm_dma.h hooks
-*/
-void radeon_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-
-       /* Disable *all* interrupts */
-       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
-
-       /* Clear bits if they're already high */
-       radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
-                                          RADEON_CRTC_VBLANK_STAT |
-                                          RADEON_CRTC2_VBLANK_STAT));
-}
-
-void radeon_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-
-       atomic_set(&dev_priv->swi_emitted, 0);
-       DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
-
-       radeon_enable_interrupt(dev);
-}
-
-void radeon_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv =
-           (drm_radeon_private_t *) dev->dev_private;
-       if (!dev_priv)
-               return;
-
-       dev_priv->irq_enabled = 0;
-
-       /* Disable *all* interrupts */
-       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
-}
-
-
-int radeon_vblank_crtc_get(struct drm_device *dev)
-{
-       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
-       u32 flag;
-       u32 value;
-
-       flag = RADEON_READ(RADEON_GEN_INT_CNTL);
-       value = 0;
-
-       if (flag & RADEON_CRTC_VBLANK_MASK)
-               value |= DRM_RADEON_VBLANK_CRTC1;
-
-       if (flag & RADEON_CRTC2_VBLANK_MASK)
-               value |= DRM_RADEON_VBLANK_CRTC2;
-       return value;
-}
-
-int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value)
-{
-       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
-       if (value & ~(DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) {
-               DRM_ERROR("called with invalid crtc 0x%x\n", (unsigned int)value);
-               return -EINVAL;
-       }
-       dev_priv->vblank_crtc = (unsigned int)value;
-       radeon_enable_interrupt(dev);
-       return 0;
-}
diff --git a/drivers/char/drm/radeon_mem.c b/drivers/char/drm/radeon_mem.c
deleted file mode 100644 (file)
index 4af5286..0000000
+++ /dev/null
@@ -1,302 +0,0 @@
-/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- */
-/*
- * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
- *
- * The Weather Channel (TM) funded Tungsten Graphics to develop the
- * initial release of the Radeon 8500 driver under the XFree86 license.
- * This notice must be preserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-
-/* Very simple allocator for GART memory, working on a static range
- * already mapped into each client's address space.
- */
-
-static struct mem_block *split_block(struct mem_block *p, int start, int size,
-                                    struct drm_file *file_priv)
-{
-       /* Maybe cut off the start of an existing block */
-       if (start > p->start) {
-               struct mem_block *newblock =
-                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
-               if (!newblock)
-                       goto out;
-               newblock->start = start;
-               newblock->size = p->size - (start - p->start);
-               newblock->file_priv = NULL;
-               newblock->next = p->next;
-               newblock->prev = p;
-               p->next->prev = newblock;
-               p->next = newblock;
-               p->size -= newblock->size;
-               p = newblock;
-       }
-
-       /* Maybe cut off the end of an existing block */
-       if (size < p->size) {
-               struct mem_block *newblock =
-                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
-               if (!newblock)
-                       goto out;
-               newblock->start = start + size;
-               newblock->size = p->size - size;
-               newblock->file_priv = NULL;
-               newblock->next = p->next;
-               newblock->prev = p;
-               p->next->prev = newblock;
-               p->next = newblock;
-               p->size = size;
-       }
-
-      out:
-       /* Our block is in the middle */
-       p->file_priv = file_priv;
-       return p;
-}
-
-static struct mem_block *alloc_block(struct mem_block *heap, int size,
-                                    int align2, struct drm_file *file_priv)
-{
-       struct mem_block *p;
-       int mask = (1 << align2) - 1;
-
-       list_for_each(p, heap) {
-               int start = (p->start + mask) & ~mask;
-               if (p->file_priv == NULL && start + size <= p->start + p->size)
-                       return split_block(p, start, size, file_priv);
-       }
-
-       return NULL;
-}
-
-static struct mem_block *find_block(struct mem_block *heap, int start)
-{
-       struct mem_block *p;
-
-       list_for_each(p, heap)
-           if (p->start == start)
-               return p;
-
-       return NULL;
-}
-
-static void free_block(struct mem_block *p)
-{
-       p->file_priv = NULL;
-
-       /* Assumes a single contiguous range.  Needs a special file_priv in
-        * 'heap' to stop it being subsumed.
-        */
-       if (p->next->file_priv == NULL) {
-               struct mem_block *q = p->next;
-               p->size += q->size;
-               p->next = q->next;
-               p->next->prev = p;
-               drm_free(q, sizeof(*q), DRM_MEM_BUFS);
-       }
-
-       if (p->prev->file_priv == NULL) {
-               struct mem_block *q = p->prev;
-               q->size += p->size;
-               q->next = p->next;
-               q->next->prev = q;
-               drm_free(p, sizeof(*q), DRM_MEM_BUFS);
-       }
-}
-
-/* Initialize.  How to check for an uninitialized heap?
- */
-static int init_heap(struct mem_block **heap, int start, int size)
-{
-       struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFS);
-
-       if (!blocks)
-               return -ENOMEM;
-
-       *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFS);
-       if (!*heap) {
-               drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFS);
-               return -ENOMEM;
-       }
-
-       blocks->start = start;
-       blocks->size = size;
-       blocks->file_priv = NULL;
-       blocks->next = blocks->prev = *heap;
-
-       memset(*heap, 0, sizeof(**heap));
-       (*heap)->file_priv = (struct drm_file *) - 1;
-       (*heap)->next = (*heap)->prev = blocks;
-       return 0;
-}
-
-/* Free all blocks associated with the releasing file.
- */
-void radeon_mem_release(struct drm_file *file_priv, struct mem_block *heap)
-{
-       struct mem_block *p;
-
-       if (!heap || !heap->next)
-               return;
-
-       list_for_each(p, heap) {
-               if (p->file_priv == file_priv)
-                       p->file_priv = NULL;
-       }
-
-       /* Assumes a single contiguous range.  Needs a special file_priv in
-        * 'heap' to stop it being subsumed.
-        */
-       list_for_each(p, heap) {
-               while (p->file_priv == NULL && p->next->file_priv == NULL) {
-                       struct mem_block *q = p->next;
-                       p->size += q->size;
-                       p->next = q->next;
-                       p->next->prev = p;
-                       drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
-               }
-       }
-}
-
-/* Shutdown.
- */
-void radeon_mem_takedown(struct mem_block **heap)
-{
-       struct mem_block *p;
-
-       if (!*heap)
-               return;
-
-       for (p = (*heap)->next; p != *heap;) {
-               struct mem_block *q = p;
-               p = p->next;
-               drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
-       }
-
-       drm_free(*heap, sizeof(**heap), DRM_MEM_DRIVER);
-       *heap = NULL;
-}
-
-/* IOCTL HANDLERS */
-
-static struct mem_block **get_heap(drm_radeon_private_t * dev_priv, int region)
-{
-       switch (region) {
-       case RADEON_MEM_REGION_GART:
-               return &dev_priv->gart_heap;
-       case RADEON_MEM_REGION_FB:
-               return &dev_priv->fb_heap;
-       default:
-               return NULL;
-       }
-}
-
-int radeon_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_mem_alloc_t *alloc = data;
-       struct mem_block *block, **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, alloc->region);
-       if (!heap || !*heap)
-               return -EFAULT;
-
-       /* Make things easier on ourselves: all allocations at least
-        * 4k aligned.
-        */
-       if (alloc->alignment < 12)
-               alloc->alignment = 12;
-
-       block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv);
-
-       if (!block)
-               return -ENOMEM;
-
-       if (DRM_COPY_TO_USER(alloc->region_offset, &block->start,
-                            sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-int radeon_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_mem_free_t *memfree = data;
-       struct mem_block *block, **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, memfree->region);
-       if (!heap || !*heap)
-               return -EFAULT;
-
-       block = find_block(*heap, memfree->region_offset);
-       if (!block)
-               return -EFAULT;
-
-       if (block->file_priv != file_priv)
-               return -EPERM;
-
-       free_block(block);
-       return 0;
-}
-
-int radeon_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_mem_init_heap_t *initheap = data;
-       struct mem_block **heap;
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       heap = get_heap(dev_priv, initheap->region);
-       if (!heap)
-               return -EFAULT;
-
-       if (*heap) {
-               DRM_ERROR("heap already initialized?");
-               return -EFAULT;
-       }
-
-       return init_heap(heap, initheap->start, initheap->size);
-}
diff --git a/drivers/char/drm/radeon_microcode.h b/drivers/char/drm/radeon_microcode.h
deleted file mode 100644 (file)
index a348c9e..0000000
+++ /dev/null
@@ -1,1844 +0,0 @@
-/*
- * Copyright 2007 Advanced Micro Devices, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef RADEON_MICROCODE_H
-#define RADEON_MICROCODE_H
-
-/* production radeon ucode r1xx-r6xx */
-static const u32 R100_cp_microcode[][2] = {
-    { 0x21007000, 0000000000 },
-    { 0x20007000, 0000000000 },
-    { 0x000000b4, 0x00000004 },
-    { 0x000000b8, 0x00000004 },
-    { 0x6f5b4d4c, 0000000000 },
-    { 0x4c4c427f, 0000000000 },
-    { 0x5b568a92, 0000000000 },
-    { 0x4ca09c6d, 0000000000 },
-    { 0xad4c4c4c, 0000000000 },
-    { 0x4ce1af3d, 0000000000 },
-    { 0xd8afafaf, 0000000000 },
-    { 0xd64c4cdc, 0000000000 },
-    { 0x4cd10d10, 0000000000 },
-    { 0x000f0000, 0x00000016 },
-    { 0x362f242d, 0000000000 },
-    { 0x00000012, 0x00000004 },
-    { 0x000f0000, 0x00000016 },
-    { 0x362f282d, 0000000000 },
-    { 0x000380e7, 0x00000002 },
-    { 0x04002c97, 0x00000002 },
-    { 0x000f0001, 0x00000016 },
-    { 0x333a3730, 0000000000 },
-    { 0x000077ef, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x00000021, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00061000, 0x00000002 },
-    { 0x00000021, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00061000, 0x00000002 },
-    { 0x00000021, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00000017, 0x00000004 },
-    { 0x0003802b, 0x00000002 },
-    { 0x040067e0, 0x00000002 },
-    { 0x00000017, 0x00000004 },
-    { 0x000077e0, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x000037e1, 0x00000002 },
-    { 0x040067e1, 0x00000006 },
-    { 0x000077e0, 0x00000002 },
-    { 0x000077e1, 0x00000002 },
-    { 0x000077e1, 0x00000006 },
-    { 0xffffffff, 0000000000 },
-    { 0x10000000, 0000000000 },
-    { 0x0003802b, 0x00000002 },
-    { 0x040067e0, 0x00000006 },
-    { 0x00007675, 0x00000002 },
-    { 0x00007676, 0x00000002 },
-    { 0x00007677, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0003802c, 0x00000002 },
-    { 0x04002676, 0x00000002 },
-    { 0x00007677, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0000002f, 0x00000018 },
-    { 0x0000002f, 0x00000018 },
-    { 0000000000, 0x00000006 },
-    { 0x00000030, 0x00000018 },
-    { 0x00000030, 0x00000018 },
-    { 0000000000, 0x00000006 },
-    { 0x01605000, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x00098000, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x64c0603e, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00080000, 0x00000016 },
-    { 0000000000, 0000000000 },
-    { 0x0400251d, 0x00000002 },
-    { 0x00007580, 0x00000002 },
-    { 0x00067581, 0x00000002 },
-    { 0x04002580, 0x00000002 },
-    { 0x00067581, 0x00000002 },
-    { 0x00000049, 0x00000004 },
-    { 0x00005000, 0000000000 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x0000750e, 0x00000002 },
-    { 0x00019000, 0x00000002 },
-    { 0x00011055, 0x00000014 },
-    { 0x00000055, 0x00000012 },
-    { 0x0400250f, 0x00000002 },
-    { 0x0000504f, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00007565, 0x00000002 },
-    { 0x00007566, 0x00000002 },
-    { 0x00000058, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x01e655b4, 0x00000002 },
-    { 0x4401b0e4, 0x00000002 },
-    { 0x01c110e4, 0x00000002 },
-    { 0x26667066, 0x00000018 },
-    { 0x040c2565, 0x00000002 },
-    { 0x00000066, 0x00000018 },
-    { 0x04002564, 0x00000002 },
-    { 0x00007566, 0x00000002 },
-    { 0x0000005d, 0x00000004 },
-    { 0x00401069, 0x00000008 },
-    { 0x00101000, 0x00000002 },
-    { 0x000d80ff, 0x00000002 },
-    { 0x0080006c, 0x00000008 },
-    { 0x000f9000, 0x00000002 },
-    { 0x000e00ff, 0x00000002 },
-    { 0000000000, 0x00000006 },
-    { 0x0000008f, 0x00000018 },
-    { 0x0000005b, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00007576, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x00009000, 0x00000002 },
-    { 0x00041000, 0x00000002 },
-    { 0x0c00350e, 0x00000002 },
-    { 0x00049000, 0x00000002 },
-    { 0x00051000, 0x00000002 },
-    { 0x01e785f8, 0x00000002 },
-    { 0x00200000, 0x00000002 },
-    { 0x0060007e, 0x0000000c },
-    { 0x00007563, 0x00000002 },
-    { 0x006075f0, 0x00000021 },
-    { 0x20007073, 0x00000004 },
-    { 0x00005073, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00007576, 0x00000002 },
-    { 0x00007577, 0x00000002 },
-    { 0x0000750e, 0x00000002 },
-    { 0x0000750f, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00600083, 0x0000000c },
-    { 0x006075f0, 0x00000021 },
-    { 0x000075f8, 0x00000002 },
-    { 0x00000083, 0x00000004 },
-    { 0x000a750e, 0x00000002 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x0020750f, 0x00000002 },
-    { 0x00600086, 0x00000004 },
-    { 0x00007570, 0x00000002 },
-    { 0x00007571, 0x00000002 },
-    { 0x00007572, 0x00000006 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00005000, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00007568, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x00000095, 0x0000000c },
-    { 0x00058000, 0x00000002 },
-    { 0x0c607562, 0x00000002 },
-    { 0x00000097, 0x00000004 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x00600096, 0x00000004 },
-    { 0x400070e5, 0000000000 },
-    { 0x000380e6, 0x00000002 },
-    { 0x040025c5, 0x00000002 },
-    { 0x000380e5, 0x00000002 },
-    { 0x000000a8, 0x0000001c },
-    { 0x000650aa, 0x00000018 },
-    { 0x040025bb, 0x00000002 },
-    { 0x000610ab, 0x00000018 },
-    { 0x040075bc, 0000000000 },
-    { 0x000075bb, 0x00000002 },
-    { 0x000075bc, 0000000000 },
-    { 0x00090000, 0x00000006 },
-    { 0x00090000, 0x00000002 },
-    { 0x000d8002, 0x00000006 },
-    { 0x00007832, 0x00000002 },
-    { 0x00005000, 0x00000002 },
-    { 0x000380e7, 0x00000002 },
-    { 0x04002c97, 0x00000002 },
-    { 0x00007820, 0x00000002 },
-    { 0x00007821, 0x00000002 },
-    { 0x00007800, 0000000000 },
-    { 0x01200000, 0x00000002 },
-    { 0x20077000, 0x00000002 },
-    { 0x01200000, 0x00000002 },
-    { 0x20007000, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x0120751b, 0x00000002 },
-    { 0x8040750a, 0x00000002 },
-    { 0x8040750b, 0x00000002 },
-    { 0x00110000, 0x00000002 },
-    { 0x000380e5, 0x00000002 },
-    { 0x000000c6, 0x0000001c },
-    { 0x000610ab, 0x00000018 },
-    { 0x844075bd, 0x00000002 },
-    { 0x000610aa, 0x00000018 },
-    { 0x840075bb, 0x00000002 },
-    { 0x000610ab, 0x00000018 },
-    { 0x844075bc, 0x00000002 },
-    { 0x000000c9, 0x00000004 },
-    { 0x804075bd, 0x00000002 },
-    { 0x800075bb, 0x00000002 },
-    { 0x804075bc, 0x00000002 },
-    { 0x00108000, 0x00000002 },
-    { 0x01400000, 0x00000002 },
-    { 0x006000cd, 0x0000000c },
-    { 0x20c07000, 0x00000020 },
-    { 0x000000cf, 0x00000012 },
-    { 0x00800000, 0x00000006 },
-    { 0x0080751d, 0x00000006 },
-    { 0000000000, 0000000000 },
-    { 0x0000775c, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00661000, 0x00000002 },
-    { 0x0460275d, 0x00000020 },
-    { 0x00004000, 0000000000 },
-    { 0x01e00830, 0x00000002 },
-    { 0x21007000, 0000000000 },
-    { 0x6464614d, 0000000000 },
-    { 0x69687420, 0000000000 },
-    { 0x00000073, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x00005000, 0x00000002 },
-    { 0x000380d0, 0x00000002 },
-    { 0x040025e0, 0x00000002 },
-    { 0x000075e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000380e0, 0x00000002 },
-    { 0x04002394, 0x00000002 },
-    { 0x00005000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x00000008, 0000000000 },
-    { 0x00000004, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 R200_cp_microcode[][2] = {
-    { 0x21007000, 0000000000 },
-    { 0x20007000, 0000000000 },
-    { 0x000000bf, 0x00000004 },
-    { 0x000000c3, 0x00000004 },
-    { 0x7a685e5d, 0000000000 },
-    { 0x5d5d5588, 0000000000 },
-    { 0x68659197, 0000000000 },
-    { 0x5da19f78, 0000000000 },
-    { 0x5d5d5d5d, 0000000000 },
-    { 0x5dee5d50, 0000000000 },
-    { 0xf2acacac, 0000000000 },
-    { 0xe75df9e9, 0000000000 },
-    { 0xb1dd0e11, 0000000000 },
-    { 0xe2afafaf, 0000000000 },
-    { 0x000f0000, 0x00000016 },
-    { 0x452f232d, 0000000000 },
-    { 0x00000013, 0x00000004 },
-    { 0x000f0000, 0x00000016 },
-    { 0x452f272d, 0000000000 },
-    { 0x000f0001, 0x00000016 },
-    { 0x3e4d4a37, 0000000000 },
-    { 0x000077ef, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x00000020, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00061000, 0x00000002 },
-    { 0x00000020, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00061000, 0x00000002 },
-    { 0x00000020, 0x0000001a },
-    { 0x00004000, 0x0000001e },
-    { 0x00000016, 0x00000004 },
-    { 0x0003802a, 0x00000002 },
-    { 0x040067e0, 0x00000002 },
-    { 0x00000016, 0x00000004 },
-    { 0x000077e0, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x000037e1, 0x00000002 },
-    { 0x040067e1, 0x00000006 },
-    { 0x000077e0, 0x00000002 },
-    { 0x000077e1, 0x00000002 },
-    { 0x000077e1, 0x00000006 },
-    { 0xffffffff, 0000000000 },
-    { 0x10000000, 0000000000 },
-    { 0x07f007f0, 0000000000 },
-    { 0x0003802a, 0x00000002 },
-    { 0x040067e0, 0x00000006 },
-    { 0x0003802c, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002743, 0x00000002 },
-    { 0x00007675, 0x00000002 },
-    { 0x00007676, 0x00000002 },
-    { 0x00007677, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0003802c, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002743, 0x00000002 },
-    { 0x00007676, 0x00000002 },
-    { 0x00007677, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0003802b, 0x00000002 },
-    { 0x04002676, 0x00000002 },
-    { 0x00007677, 0x00000002 },
-    { 0x0003802c, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002743, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0003802c, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002741, 0x00000002 },
-    { 0x04002743, 0x00000002 },
-    { 0x00007678, 0x00000006 },
-    { 0x0000002f, 0x00000018 },
-    { 0x0000002f, 0x00000018 },
-    { 0000000000, 0x00000006 },
-    { 0x00000037, 0x00000018 },
-    { 0x00000037, 0x00000018 },
-    { 0000000000, 0x00000006 },
-    { 0x01605000, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x00098000, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x64c06051, 0x00000004 },
-    { 0x00080000, 0x00000016 },
-    { 0000000000, 0000000000 },
-    { 0x0400251d, 0x00000002 },
-    { 0x00007580, 0x00000002 },
-    { 0x00067581, 0x00000002 },
-    { 0x04002580, 0x00000002 },
-    { 0x00067581, 0x00000002 },
-    { 0x0000005a, 0x00000004 },
-    { 0x00005000, 0000000000 },
-    { 0x00061000, 0x00000002 },
-    { 0x0000750e, 0x00000002 },
-    { 0x00019000, 0x00000002 },
-    { 0x00011064, 0x00000014 },
-    { 0x00000064, 0x00000012 },
-    { 0x0400250f, 0x00000002 },
-    { 0x0000505e, 0x00000004 },
-    { 0x00007565, 0x00000002 },
-    { 0x00007566, 0x00000002 },
-    { 0x00000065, 0x00000004 },
-    { 0x01e655b4, 0x00000002 },
-    { 0x4401b0f0, 0x00000002 },
-    { 0x01c110f0, 0x00000002 },
-    { 0x26667071, 0x00000018 },
-    { 0x040c2565, 0x00000002 },
-    { 0x00000071, 0x00000018 },
-    { 0x04002564, 0x00000002 },
-    { 0x00007566, 0x00000002 },
-    { 0x00000068, 0x00000004 },
-    { 0x00401074, 0x00000008 },
-    { 0x00101000, 0x00000002 },
-    { 0x000d80ff, 0x00000002 },
-    { 0x00800077, 0x00000008 },
-    { 0x000f9000, 0x00000002 },
-    { 0x000e00ff, 0x00000002 },
-    { 0000000000, 0x00000006 },
-    { 0x00000094, 0x00000018 },
-    { 0x00000068, 0x00000004 },
-    { 0x00007576, 0x00000002 },
-    { 0x00065000, 0x00000002 },
-    { 0x00009000, 0x00000002 },
-    { 0x00041000, 0x00000002 },
-    { 0x0c00350e, 0x00000002 },
-    { 0x00049000, 0x00000002 },
-    { 0x00051000, 0x00000002 },
-    { 0x01e785f8, 0x00000002 },
-    { 0x00200000, 0x00000002 },
-    { 0x00600087, 0x0000000c },
-    { 0x00007563, 0x00000002 },
-    { 0x006075f0, 0x00000021 },
-    { 0x2000707c, 0x00000004 },
-    { 0x0000507c, 0x00000004 },
-    { 0x00007576, 0x00000002 },
-    { 0x00007577, 0x00000002 },
-    { 0x0000750e, 0x00000002 },
-    { 0x0000750f, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x0060008a, 0x0000000c },
-    { 0x006075f0, 0x00000021 },
-    { 0x000075f8, 0x00000002 },
-    { 0x0000008a, 0x00000004 },
-    { 0x000a750e, 0x00000002 },
-    { 0x0020750f, 0x00000002 },
-    { 0x0060008d, 0x00000004 },
-    { 0x00007570, 0x00000002 },
-    { 0x00007571, 0x00000002 },
-    { 0x00007572, 0x00000006 },
-    { 0x00005000, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00007568, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x00000098, 0x0000000c },
-    { 0x00058000, 0x00000002 },
-    { 0x0c607562, 0x00000002 },
-    { 0x0000009a, 0x00000004 },
-    { 0x00600099, 0x00000004 },
-    { 0x400070f1, 0000000000 },
-    { 0x000380f1, 0x00000002 },
-    { 0x000000a7, 0x0000001c },
-    { 0x000650a9, 0x00000018 },
-    { 0x040025bb, 0x00000002 },
-    { 0x000610aa, 0x00000018 },
-    { 0x040075bc, 0000000000 },
-    { 0x000075bb, 0x00000002 },
-    { 0x000075bc, 0000000000 },
-    { 0x00090000, 0x00000006 },
-    { 0x00090000, 0x00000002 },
-    { 0x000d8002, 0x00000006 },
-    { 0x00005000, 0x00000002 },
-    { 0x00007821, 0x00000002 },
-    { 0x00007800, 0000000000 },
-    { 0x00007821, 0x00000002 },
-    { 0x00007800, 0000000000 },
-    { 0x01665000, 0x00000002 },
-    { 0x000a0000, 0x00000002 },
-    { 0x000671cc, 0x00000002 },
-    { 0x0286f1cd, 0x00000002 },
-    { 0x000000b7, 0x00000010 },
-    { 0x21007000, 0000000000 },
-    { 0x000000be, 0x0000001c },
-    { 0x00065000, 0x00000002 },
-    { 0x000a0000, 0x00000002 },
-    { 0x00061000, 0x00000002 },
-    { 0x000b0000, 0x00000002 },
-    { 0x38067000, 0x00000002 },
-    { 0x000a00ba, 0x00000004 },
-    { 0x20007000, 0000000000 },
-    { 0x01200000, 0x00000002 },
-    { 0x20077000, 0x00000002 },
-    { 0x01200000, 0x00000002 },
-    { 0x20007000, 0000000000 },
-    { 0x00061000, 0x00000002 },
-    { 0x0120751b, 0x00000002 },
-    { 0x8040750a, 0x00000002 },
-    { 0x8040750b, 0x00000002 },
-    { 0x00110000, 0x00000002 },
-    { 0x000380f1, 0x00000002 },
-    { 0x000000d1, 0x0000001c },
-    { 0x000610aa, 0x00000018 },
-    { 0x844075bd, 0x00000002 },
-    { 0x000610a9, 0x00000018 },
-    { 0x840075bb, 0x00000002 },
-    { 0x000610aa, 0x00000018 },
-    { 0x844075bc, 0x00000002 },
-    { 0x000000d4, 0x00000004 },
-    { 0x804075bd, 0x00000002 },
-    { 0x800075bb, 0x00000002 },
-    { 0x804075bc, 0x00000002 },
-    { 0x00108000, 0x00000002 },
-    { 0x01400000, 0x00000002 },
-    { 0x006000d8, 0x0000000c },
-    { 0x20c07000, 0x00000020 },
-    { 0x000000da, 0x00000012 },
-    { 0x00800000, 0x00000006 },
-    { 0x0080751d, 0x00000006 },
-    { 0x000025bb, 0x00000002 },
-    { 0x000040d4, 0x00000004 },
-    { 0x0000775c, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00661000, 0x00000002 },
-    { 0x0460275d, 0x00000020 },
-    { 0x00004000, 0000000000 },
-    { 0x00007999, 0x00000002 },
-    { 0x00a05000, 0x00000002 },
-    { 0x00661000, 0x00000002 },
-    { 0x0460299b, 0x00000020 },
-    { 0x00004000, 0000000000 },
-    { 0x01e00830, 0x00000002 },
-    { 0x21007000, 0000000000 },
-    { 0x00005000, 0x00000002 },
-    { 0x00038056, 0x00000002 },
-    { 0x040025e0, 0x00000002 },
-    { 0x000075e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000380ed, 0x00000002 },
-    { 0x04007394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000078c4, 0x00000002 },
-    { 0x000078c5, 0x00000002 },
-    { 0x000078c6, 0x00000002 },
-    { 0x00007924, 0x00000002 },
-    { 0x00007925, 0x00000002 },
-    { 0x00007926, 0x00000002 },
-    { 0x000000f2, 0x00000004 },
-    { 0x00007924, 0x00000002 },
-    { 0x00007925, 0x00000002 },
-    { 0x00007926, 0x00000002 },
-    { 0x000000f9, 0x00000004 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 R300_cp_microcode[][2] = {
-    { 0x4200e000, 0000000000 },
-    { 0x4000e000, 0000000000 },
-    { 0x000000ae, 0x00000008 },
-    { 0x000000b2, 0x00000008 },
-    { 0x67554b4a, 0000000000 },
-    { 0x4a4a4475, 0000000000 },
-    { 0x55527d83, 0000000000 },
-    { 0x4a8c8b65, 0000000000 },
-    { 0x4aef4af6, 0000000000 },
-    { 0x4ae14a4a, 0000000000 },
-    { 0xe4979797, 0000000000 },
-    { 0xdb4aebdd, 0000000000 },
-    { 0x9ccc4a4a, 0000000000 },
-    { 0xd1989898, 0000000000 },
-    { 0x4a0f9ad6, 0000000000 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000d0012, 0x00000038 },
-    { 0x0000e8b4, 0x00000004 },
-    { 0x000d0014, 0x00000038 },
-    { 0x0000e8b6, 0x00000004 },
-    { 0x000d0016, 0x00000038 },
-    { 0x0000e854, 0x00000004 },
-    { 0x000d0018, 0x00000038 },
-    { 0x0000e855, 0x00000004 },
-    { 0x000d001a, 0x00000038 },
-    { 0x0000e856, 0x00000004 },
-    { 0x000d001c, 0x00000038 },
-    { 0x0000e857, 0x00000004 },
-    { 0x000d001e, 0x00000038 },
-    { 0x0000e824, 0x00000004 },
-    { 0x000d0020, 0x00000038 },
-    { 0x0000e825, 0x00000004 },
-    { 0x000d0022, 0x00000038 },
-    { 0x0000e830, 0x00000004 },
-    { 0x000d0024, 0x00000038 },
-    { 0x0000f0c0, 0x00000004 },
-    { 0x000d0026, 0x00000038 },
-    { 0x0000f0c1, 0x00000004 },
-    { 0x000d0028, 0x00000038 },
-    { 0x0000f041, 0x00000004 },
-    { 0x000d002a, 0x00000038 },
-    { 0x0000f184, 0x00000004 },
-    { 0x000d002c, 0x00000038 },
-    { 0x0000f185, 0x00000004 },
-    { 0x000d002e, 0x00000038 },
-    { 0x0000f186, 0x00000004 },
-    { 0x000d0030, 0x00000038 },
-    { 0x0000f187, 0x00000004 },
-    { 0x000d0032, 0x00000038 },
-    { 0x0000f180, 0x00000004 },
-    { 0x000d0034, 0x00000038 },
-    { 0x0000f393, 0x00000004 },
-    { 0x000d0036, 0x00000038 },
-    { 0x0000f38a, 0x00000004 },
-    { 0x000d0038, 0x00000038 },
-    { 0x0000f38e, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000043, 0x00000018 },
-    { 0x00cce800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x0000003a, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x2000451d, 0x00000004 },
-    { 0x0000e580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x08004580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x00000047, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x00032000, 0x00000004 },
-    { 0x00022051, 0x00000028 },
-    { 0x00000051, 0x00000024 },
-    { 0x0800450f, 0x00000004 },
-    { 0x0000a04b, 0x00000008 },
-    { 0x0000e565, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000052, 0x00000008 },
-    { 0x03cca5b4, 0x00000004 },
-    { 0x05432000, 0x00000004 },
-    { 0x00022000, 0x00000004 },
-    { 0x4ccce05e, 0x00000030 },
-    { 0x08274565, 0x00000004 },
-    { 0x0000005e, 0x00000030 },
-    { 0x08004564, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000055, 0x00000008 },
-    { 0x00802061, 0x00000010 },
-    { 0x00202000, 0x00000004 },
-    { 0x001b00ff, 0x00000004 },
-    { 0x01000064, 0x00000010 },
-    { 0x001f2000, 0x00000004 },
-    { 0x001c00ff, 0x00000004 },
-    { 0000000000, 0x0000000c },
-    { 0x00000080, 0x00000030 },
-    { 0x00000055, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00012000, 0x00000004 },
-    { 0x00082000, 0x00000004 },
-    { 0x1800650e, 0x00000004 },
-    { 0x00092000, 0x00000004 },
-    { 0x000a2000, 0x00000004 },
-    { 0x000f0000, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x00000074, 0x00000018 },
-    { 0x0000e563, 0x00000004 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000069, 0x00000008 },
-    { 0x0000a069, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x0000e577, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x0000e50f, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000077, 0x00000018 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000077, 0x00000008 },
-    { 0x0014e50e, 0x00000004 },
-    { 0x0040e50f, 0x00000004 },
-    { 0x00c0007a, 0x00000008 },
-    { 0x0000e570, 0x00000004 },
-    { 0x0000e571, 0x00000004 },
-    { 0x0000e572, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x0000e568, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00000084, 0x00000018 },
-    { 0x000b0000, 0x00000004 },
-    { 0x18c0e562, 0x00000004 },
-    { 0x00000086, 0x00000008 },
-    { 0x00c00085, 0x00000008 },
-    { 0x000700e3, 0x00000004 },
-    { 0x00000092, 0x00000038 },
-    { 0x000ca094, 0x00000030 },
-    { 0x080045bb, 0x00000004 },
-    { 0x000c2095, 0x00000030 },
-    { 0x0800e5bc, 0000000000 },
-    { 0x0000e5bb, 0x00000004 },
-    { 0x0000e5bc, 0000000000 },
-    { 0x00120000, 0x0000000c },
-    { 0x00120000, 0x00000004 },
-    { 0x001b0002, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e800, 0000000000 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e82e, 0000000000 },
-    { 0x02cca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000ce1cc, 0x00000004 },
-    { 0x050de1cd, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x000000a4, 0x00000018 },
-    { 0x00c0a000, 0x00000004 },
-    { 0x000000a1, 0x00000008 },
-    { 0x000000a6, 0x00000020 },
-    { 0x4200e000, 0000000000 },
-    { 0x000000ad, 0x00000038 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00160000, 0x00000004 },
-    { 0x700ce000, 0x00000004 },
-    { 0x001400a9, 0x00000008 },
-    { 0x4000e000, 0000000000 },
-    { 0x02400000, 0x00000004 },
-    { 0x400ee000, 0x00000004 },
-    { 0x02400000, 0x00000004 },
-    { 0x4000e000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0240e51b, 0x00000004 },
-    { 0x0080e50a, 0x00000005 },
-    { 0x0080e50b, 0x00000005 },
-    { 0x00220000, 0x00000004 },
-    { 0x000700e3, 0x00000004 },
-    { 0x000000c0, 0x00000038 },
-    { 0x000c2095, 0x00000030 },
-    { 0x0880e5bd, 0x00000005 },
-    { 0x000c2094, 0x00000030 },
-    { 0x0800e5bb, 0x00000005 },
-    { 0x000c2095, 0x00000030 },
-    { 0x0880e5bc, 0x00000005 },
-    { 0x000000c3, 0x00000008 },
-    { 0x0080e5bd, 0x00000005 },
-    { 0x0000e5bb, 0x00000005 },
-    { 0x0080e5bc, 0x00000005 },
-    { 0x00210000, 0x00000004 },
-    { 0x02800000, 0x00000004 },
-    { 0x00c000c7, 0x00000018 },
-    { 0x4180e000, 0x00000040 },
-    { 0x000000c9, 0x00000024 },
-    { 0x01000000, 0x0000000c },
-    { 0x0100e51d, 0x0000000c },
-    { 0x000045bb, 0x00000004 },
-    { 0x000080c3, 0x00000008 },
-    { 0x0000f3ce, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053cf, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f3d2, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053d3, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f39d, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c0539e, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x03c00830, 0x00000004 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x200045e0, 0x00000004 },
-    { 0x0000e5e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000700e0, 0x00000004 },
-    { 0x0800e394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x0000e8c4, 0x00000004 },
-    { 0x0000e8c5, 0x00000004 },
-    { 0x0000e8c6, 0x00000004 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000e4, 0x00000008 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000eb, 0x00000008 },
-    { 0x02c02000, 0x00000004 },
-    { 0x00060000, 0x00000004 },
-    { 0x000000f3, 0x00000034 },
-    { 0x000000f0, 0x00000008 },
-    { 0x00008000, 0x00000004 },
-    { 0xc000e000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x001d0018, 0x00000004 },
-    { 0x001a0001, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0x0500a04a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 R420_cp_microcode[][2] = {
-    { 0x4200e000, 0000000000 },
-    { 0x4000e000, 0000000000 },
-    { 0x00000099, 0x00000008 },
-    { 0x0000009d, 0x00000008 },
-    { 0x4a554b4a, 0000000000 },
-    { 0x4a4a4467, 0000000000 },
-    { 0x55526f75, 0000000000 },
-    { 0x4a7e7d65, 0000000000 },
-    { 0xd9d3dff6, 0000000000 },
-    { 0x4ac54a4a, 0000000000 },
-    { 0xc8828282, 0000000000 },
-    { 0xbf4acfc1, 0000000000 },
-    { 0x87b04a4a, 0000000000 },
-    { 0xb5838383, 0000000000 },
-    { 0x4a0f85ba, 0000000000 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000d0012, 0x00000038 },
-    { 0x0000e8b4, 0x00000004 },
-    { 0x000d0014, 0x00000038 },
-    { 0x0000e8b6, 0x00000004 },
-    { 0x000d0016, 0x00000038 },
-    { 0x0000e854, 0x00000004 },
-    { 0x000d0018, 0x00000038 },
-    { 0x0000e855, 0x00000004 },
-    { 0x000d001a, 0x00000038 },
-    { 0x0000e856, 0x00000004 },
-    { 0x000d001c, 0x00000038 },
-    { 0x0000e857, 0x00000004 },
-    { 0x000d001e, 0x00000038 },
-    { 0x0000e824, 0x00000004 },
-    { 0x000d0020, 0x00000038 },
-    { 0x0000e825, 0x00000004 },
-    { 0x000d0022, 0x00000038 },
-    { 0x0000e830, 0x00000004 },
-    { 0x000d0024, 0x00000038 },
-    { 0x0000f0c0, 0x00000004 },
-    { 0x000d0026, 0x00000038 },
-    { 0x0000f0c1, 0x00000004 },
-    { 0x000d0028, 0x00000038 },
-    { 0x0000f041, 0x00000004 },
-    { 0x000d002a, 0x00000038 },
-    { 0x0000f184, 0x00000004 },
-    { 0x000d002c, 0x00000038 },
-    { 0x0000f185, 0x00000004 },
-    { 0x000d002e, 0x00000038 },
-    { 0x0000f186, 0x00000004 },
-    { 0x000d0030, 0x00000038 },
-    { 0x0000f187, 0x00000004 },
-    { 0x000d0032, 0x00000038 },
-    { 0x0000f180, 0x00000004 },
-    { 0x000d0034, 0x00000038 },
-    { 0x0000f393, 0x00000004 },
-    { 0x000d0036, 0x00000038 },
-    { 0x0000f38a, 0x00000004 },
-    { 0x000d0038, 0x00000038 },
-    { 0x0000f38e, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000043, 0x00000018 },
-    { 0x00cce800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x0000003a, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x2000451d, 0x00000004 },
-    { 0x0000e580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x08004580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x00000047, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x00032000, 0x00000004 },
-    { 0x00022051, 0x00000028 },
-    { 0x00000051, 0x00000024 },
-    { 0x0800450f, 0x00000004 },
-    { 0x0000a04b, 0x00000008 },
-    { 0x0000e565, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000052, 0x00000008 },
-    { 0x03cca5b4, 0x00000004 },
-    { 0x05432000, 0x00000004 },
-    { 0x00022000, 0x00000004 },
-    { 0x4ccce05e, 0x00000030 },
-    { 0x08274565, 0x00000004 },
-    { 0x0000005e, 0x00000030 },
-    { 0x08004564, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000055, 0x00000008 },
-    { 0x00802061, 0x00000010 },
-    { 0x00202000, 0x00000004 },
-    { 0x001b00ff, 0x00000004 },
-    { 0x01000064, 0x00000010 },
-    { 0x001f2000, 0x00000004 },
-    { 0x001c00ff, 0x00000004 },
-    { 0000000000, 0x0000000c },
-    { 0x00000072, 0x00000030 },
-    { 0x00000055, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x0000e577, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x0000e50f, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000069, 0x00000018 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000069, 0x00000008 },
-    { 0x0014e50e, 0x00000004 },
-    { 0x0040e50f, 0x00000004 },
-    { 0x00c0006c, 0x00000008 },
-    { 0x0000e570, 0x00000004 },
-    { 0x0000e571, 0x00000004 },
-    { 0x0000e572, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x0000e568, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00000076, 0x00000018 },
-    { 0x000b0000, 0x00000004 },
-    { 0x18c0e562, 0x00000004 },
-    { 0x00000078, 0x00000008 },
-    { 0x00c00077, 0x00000008 },
-    { 0x000700c7, 0x00000004 },
-    { 0x00000080, 0x00000038 },
-    { 0x0000e5bb, 0x00000004 },
-    { 0x0000e5bc, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e800, 0000000000 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e82e, 0000000000 },
-    { 0x02cca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000ce1cc, 0x00000004 },
-    { 0x050de1cd, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x0000008f, 0x00000018 },
-    { 0x00c0a000, 0x00000004 },
-    { 0x0000008c, 0x00000008 },
-    { 0x00000091, 0x00000020 },
-    { 0x4200e000, 0000000000 },
-    { 0x00000098, 0x00000038 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00160000, 0x00000004 },
-    { 0x700ce000, 0x00000004 },
-    { 0x00140094, 0x00000008 },
-    { 0x4000e000, 0000000000 },
-    { 0x02400000, 0x00000004 },
-    { 0x400ee000, 0x00000004 },
-    { 0x02400000, 0x00000004 },
-    { 0x4000e000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0240e51b, 0x00000004 },
-    { 0x0080e50a, 0x00000005 },
-    { 0x0080e50b, 0x00000005 },
-    { 0x00220000, 0x00000004 },
-    { 0x000700c7, 0x00000004 },
-    { 0x000000a4, 0x00000038 },
-    { 0x0080e5bd, 0x00000005 },
-    { 0x0000e5bb, 0x00000005 },
-    { 0x0080e5bc, 0x00000005 },
-    { 0x00210000, 0x00000004 },
-    { 0x02800000, 0x00000004 },
-    { 0x00c000ab, 0x00000018 },
-    { 0x4180e000, 0x00000040 },
-    { 0x000000ad, 0x00000024 },
-    { 0x01000000, 0x0000000c },
-    { 0x0100e51d, 0x0000000c },
-    { 0x000045bb, 0x00000004 },
-    { 0x000080a7, 0x00000008 },
-    { 0x0000f3ce, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053cf, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f3d2, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053d3, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f39d, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c0539e, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x03c00830, 0x00000004 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x200045e0, 0x00000004 },
-    { 0x0000e5e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000700c4, 0x00000004 },
-    { 0x0800e394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x0000e8c4, 0x00000004 },
-    { 0x0000e8c5, 0x00000004 },
-    { 0x0000e8c6, 0x00000004 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000c8, 0x00000008 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000cf, 0x00000008 },
-    { 0x02c02000, 0x00000004 },
-    { 0x00060000, 0x00000004 },
-    { 0x000000d7, 0x00000034 },
-    { 0x000000d4, 0x00000008 },
-    { 0x00008000, 0x00000004 },
-    { 0xc000e000, 0000000000 },
-    { 0x0000e1cc, 0x00000004 },
-    { 0x0500e1cd, 0x00000004 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000000de, 0x00000034 },
-    { 0x000000da, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x0019e1cc, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x0500a000, 0x00000004 },
-    { 0x080041cd, 0x00000004 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x001d0018, 0x00000004 },
-    { 0x001a0001, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0x0500a04a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 RS600_cp_microcode[][2] = {
-    { 0x4200e000, 0000000000 },
-    { 0x4000e000, 0000000000 },
-    { 0x000000a0, 0x00000008 },
-    { 0x000000a4, 0x00000008 },
-    { 0x4a554b4a, 0000000000 },
-    { 0x4a4a4467, 0000000000 },
-    { 0x55526f75, 0000000000 },
-    { 0x4a7e7d65, 0000000000 },
-    { 0x4ae74af6, 0000000000 },
-    { 0x4ad34a4a, 0000000000 },
-    { 0xd6898989, 0000000000 },
-    { 0xcd4addcf, 0000000000 },
-    { 0x8ebe4ae2, 0000000000 },
-    { 0xc38a8a8a, 0000000000 },
-    { 0x4a0f8cc8, 0000000000 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000d0012, 0x00000038 },
-    { 0x0000e8b4, 0x00000004 },
-    { 0x000d0014, 0x00000038 },
-    { 0x0000e8b6, 0x00000004 },
-    { 0x000d0016, 0x00000038 },
-    { 0x0000e854, 0x00000004 },
-    { 0x000d0018, 0x00000038 },
-    { 0x0000e855, 0x00000004 },
-    { 0x000d001a, 0x00000038 },
-    { 0x0000e856, 0x00000004 },
-    { 0x000d001c, 0x00000038 },
-    { 0x0000e857, 0x00000004 },
-    { 0x000d001e, 0x00000038 },
-    { 0x0000e824, 0x00000004 },
-    { 0x000d0020, 0x00000038 },
-    { 0x0000e825, 0x00000004 },
-    { 0x000d0022, 0x00000038 },
-    { 0x0000e830, 0x00000004 },
-    { 0x000d0024, 0x00000038 },
-    { 0x0000f0c0, 0x00000004 },
-    { 0x000d0026, 0x00000038 },
-    { 0x0000f0c1, 0x00000004 },
-    { 0x000d0028, 0x00000038 },
-    { 0x0000f041, 0x00000004 },
-    { 0x000d002a, 0x00000038 },
-    { 0x0000f184, 0x00000004 },
-    { 0x000d002c, 0x00000038 },
-    { 0x0000f185, 0x00000004 },
-    { 0x000d002e, 0x00000038 },
-    { 0x0000f186, 0x00000004 },
-    { 0x000d0030, 0x00000038 },
-    { 0x0000f187, 0x00000004 },
-    { 0x000d0032, 0x00000038 },
-    { 0x0000f180, 0x00000004 },
-    { 0x000d0034, 0x00000038 },
-    { 0x0000f393, 0x00000004 },
-    { 0x000d0036, 0x00000038 },
-    { 0x0000f38a, 0x00000004 },
-    { 0x000d0038, 0x00000038 },
-    { 0x0000f38e, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000043, 0x00000018 },
-    { 0x00cce800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x0000003a, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x2000451d, 0x00000004 },
-    { 0x0000e580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x08004580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x00000047, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x00032000, 0x00000004 },
-    { 0x00022051, 0x00000028 },
-    { 0x00000051, 0x00000024 },
-    { 0x0800450f, 0x00000004 },
-    { 0x0000a04b, 0x00000008 },
-    { 0x0000e565, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000052, 0x00000008 },
-    { 0x03cca5b4, 0x00000004 },
-    { 0x05432000, 0x00000004 },
-    { 0x00022000, 0x00000004 },
-    { 0x4ccce05e, 0x00000030 },
-    { 0x08274565, 0x00000004 },
-    { 0x0000005e, 0x00000030 },
-    { 0x08004564, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000055, 0x00000008 },
-    { 0x00802061, 0x00000010 },
-    { 0x00202000, 0x00000004 },
-    { 0x001b00ff, 0x00000004 },
-    { 0x01000064, 0x00000010 },
-    { 0x001f2000, 0x00000004 },
-    { 0x001c00ff, 0x00000004 },
-    { 0000000000, 0x0000000c },
-    { 0x00000072, 0x00000030 },
-    { 0x00000055, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x0000e577, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x0000e50f, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000069, 0x00000018 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000069, 0x00000008 },
-    { 0x0014e50e, 0x00000004 },
-    { 0x0040e50f, 0x00000004 },
-    { 0x00c0006c, 0x00000008 },
-    { 0x0000e570, 0x00000004 },
-    { 0x0000e571, 0x00000004 },
-    { 0x0000e572, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x0000e568, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00000076, 0x00000018 },
-    { 0x000b0000, 0x00000004 },
-    { 0x18c0e562, 0x00000004 },
-    { 0x00000078, 0x00000008 },
-    { 0x00c00077, 0x00000008 },
-    { 0x000700d5, 0x00000004 },
-    { 0x00000084, 0x00000038 },
-    { 0x000ca086, 0x00000030 },
-    { 0x080045bb, 0x00000004 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0800e5bc, 0000000000 },
-    { 0x0000e5bb, 0x00000004 },
-    { 0x0000e5bc, 0000000000 },
-    { 0x00120000, 0x0000000c },
-    { 0x00120000, 0x00000004 },
-    { 0x001b0002, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e800, 0000000000 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e82e, 0000000000 },
-    { 0x02cca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000ce1cc, 0x00000004 },
-    { 0x050de1cd, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x00000096, 0x00000018 },
-    { 0x00c0a000, 0x00000004 },
-    { 0x00000093, 0x00000008 },
-    { 0x00000098, 0x00000020 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000009f, 0x00000038 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00160000, 0x00000004 },
-    { 0x700ce000, 0x00000004 },
-    { 0x0014009b, 0x00000008 },
-    { 0x4000e000, 0000000000 },
-    { 0x02400000, 0x00000004 },
-    { 0x400ee000, 0x00000004 },
-    { 0x02400000, 0x00000004 },
-    { 0x4000e000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0240e51b, 0x00000004 },
-    { 0x0080e50a, 0x00000005 },
-    { 0x0080e50b, 0x00000005 },
-    { 0x00220000, 0x00000004 },
-    { 0x000700d5, 0x00000004 },
-    { 0x000000b2, 0x00000038 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0880e5bd, 0x00000005 },
-    { 0x000c2086, 0x00000030 },
-    { 0x0800e5bb, 0x00000005 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0880e5bc, 0x00000005 },
-    { 0x000000b5, 0x00000008 },
-    { 0x0080e5bd, 0x00000005 },
-    { 0x0000e5bb, 0x00000005 },
-    { 0x0080e5bc, 0x00000005 },
-    { 0x00210000, 0x00000004 },
-    { 0x02800000, 0x00000004 },
-    { 0x00c000b9, 0x00000018 },
-    { 0x4180e000, 0x00000040 },
-    { 0x000000bb, 0x00000024 },
-    { 0x01000000, 0x0000000c },
-    { 0x0100e51d, 0x0000000c },
-    { 0x000045bb, 0x00000004 },
-    { 0x000080b5, 0x00000008 },
-    { 0x0000f3ce, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053cf, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f3d2, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053d3, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f39d, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c0539e, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x03c00830, 0x00000004 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x200045e0, 0x00000004 },
-    { 0x0000e5e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000700d2, 0x00000004 },
-    { 0x0800e394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x0000e8c4, 0x00000004 },
-    { 0x0000e8c5, 0x00000004 },
-    { 0x0000e8c6, 0x00000004 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000d6, 0x00000008 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000dd, 0x00000008 },
-    { 0x00e00116, 0000000000 },
-    { 0x000700e1, 0x00000004 },
-    { 0x0800401c, 0x00000004 },
-    { 0x200050e7, 0x00000004 },
-    { 0x0000e01d, 0x00000004 },
-    { 0x000000e4, 0x00000008 },
-    { 0x02c02000, 0x00000004 },
-    { 0x00060000, 0x00000004 },
-    { 0x000000eb, 0x00000034 },
-    { 0x000000e8, 0x00000008 },
-    { 0x00008000, 0x00000004 },
-    { 0xc000e000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x001d0018, 0x00000004 },
-    { 0x001a0001, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0x0500a04a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 RS690_cp_microcode[][2] = {
-    { 0x000000dd, 0x00000008 },
-    { 0x000000df, 0x00000008 },
-    { 0x000000a0, 0x00000008 },
-    { 0x000000a4, 0x00000008 },
-    { 0x4a554b4a, 0000000000 },
-    { 0x4a4a4467, 0000000000 },
-    { 0x55526f75, 0000000000 },
-    { 0x4a7e7d65, 0000000000 },
-    { 0x4ad74af6, 0000000000 },
-    { 0x4ac94a4a, 0000000000 },
-    { 0xcc898989, 0000000000 },
-    { 0xc34ad3c5, 0000000000 },
-    { 0x8e4a4a4a, 0000000000 },
-    { 0x4a8a8a8a, 0000000000 },
-    { 0x4a0f8c4a, 0000000000 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000d0012, 0x00000038 },
-    { 0x0000e8b4, 0x00000004 },
-    { 0x000d0014, 0x00000038 },
-    { 0x0000e8b6, 0x00000004 },
-    { 0x000d0016, 0x00000038 },
-    { 0x0000e854, 0x00000004 },
-    { 0x000d0018, 0x00000038 },
-    { 0x0000e855, 0x00000004 },
-    { 0x000d001a, 0x00000038 },
-    { 0x0000e856, 0x00000004 },
-    { 0x000d001c, 0x00000038 },
-    { 0x0000e857, 0x00000004 },
-    { 0x000d001e, 0x00000038 },
-    { 0x0000e824, 0x00000004 },
-    { 0x000d0020, 0x00000038 },
-    { 0x0000e825, 0x00000004 },
-    { 0x000d0022, 0x00000038 },
-    { 0x0000e830, 0x00000004 },
-    { 0x000d0024, 0x00000038 },
-    { 0x0000f0c0, 0x00000004 },
-    { 0x000d0026, 0x00000038 },
-    { 0x0000f0c1, 0x00000004 },
-    { 0x000d0028, 0x00000038 },
-    { 0x0000f041, 0x00000004 },
-    { 0x000d002a, 0x00000038 },
-    { 0x0000f184, 0x00000004 },
-    { 0x000d002c, 0x00000038 },
-    { 0x0000f185, 0x00000004 },
-    { 0x000d002e, 0x00000038 },
-    { 0x0000f186, 0x00000004 },
-    { 0x000d0030, 0x00000038 },
-    { 0x0000f187, 0x00000004 },
-    { 0x000d0032, 0x00000038 },
-    { 0x0000f180, 0x00000004 },
-    { 0x000d0034, 0x00000038 },
-    { 0x0000f393, 0x00000004 },
-    { 0x000d0036, 0x00000038 },
-    { 0x0000f38a, 0x00000004 },
-    { 0x000d0038, 0x00000038 },
-    { 0x0000f38e, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000043, 0x00000018 },
-    { 0x00cce800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x0000003a, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x2000451d, 0x00000004 },
-    { 0x0000e580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x08004580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x00000047, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x00032000, 0x00000004 },
-    { 0x00022051, 0x00000028 },
-    { 0x00000051, 0x00000024 },
-    { 0x0800450f, 0x00000004 },
-    { 0x0000a04b, 0x00000008 },
-    { 0x0000e565, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000052, 0x00000008 },
-    { 0x03cca5b4, 0x00000004 },
-    { 0x05432000, 0x00000004 },
-    { 0x00022000, 0x00000004 },
-    { 0x4ccce05e, 0x00000030 },
-    { 0x08274565, 0x00000004 },
-    { 0x0000005e, 0x00000030 },
-    { 0x08004564, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000055, 0x00000008 },
-    { 0x00802061, 0x00000010 },
-    { 0x00202000, 0x00000004 },
-    { 0x001b00ff, 0x00000004 },
-    { 0x01000064, 0x00000010 },
-    { 0x001f2000, 0x00000004 },
-    { 0x001c00ff, 0x00000004 },
-    { 0000000000, 0x0000000c },
-    { 0x00000072, 0x00000030 },
-    { 0x00000055, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x0000e577, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x0000e50f, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000069, 0x00000018 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000069, 0x00000008 },
-    { 0x0014e50e, 0x00000004 },
-    { 0x0040e50f, 0x00000004 },
-    { 0x00c0006c, 0x00000008 },
-    { 0x0000e570, 0x00000004 },
-    { 0x0000e571, 0x00000004 },
-    { 0x0000e572, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x0000e568, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00000076, 0x00000018 },
-    { 0x000b0000, 0x00000004 },
-    { 0x18c0e562, 0x00000004 },
-    { 0x00000078, 0x00000008 },
-    { 0x00c00077, 0x00000008 },
-    { 0x000700cb, 0x00000004 },
-    { 0x00000084, 0x00000038 },
-    { 0x000ca086, 0x00000030 },
-    { 0x080045bb, 0x00000004 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0800e5bc, 0000000000 },
-    { 0x0000e5bb, 0x00000004 },
-    { 0x0000e5bc, 0000000000 },
-    { 0x00120000, 0x0000000c },
-    { 0x00120000, 0x00000004 },
-    { 0x001b0002, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e800, 0000000000 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e82e, 0000000000 },
-    { 0x02cca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000ce1cc, 0x00000004 },
-    { 0x050de1cd, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x00000096, 0x00000018 },
-    { 0x00c0a000, 0x00000004 },
-    { 0x00000093, 0x00000008 },
-    { 0x00000098, 0x00000020 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000009f, 0x00000038 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00160000, 0x00000004 },
-    { 0x700ce000, 0x00000004 },
-    { 0x0014009b, 0x00000008 },
-    { 0x4000e000, 0000000000 },
-    { 0x02400000, 0x00000004 },
-    { 0x400ee000, 0x00000004 },
-    { 0x02400000, 0x00000004 },
-    { 0x4000e000, 0000000000 },
-    { 0x00100000, 0x0000002c },
-    { 0x00004000, 0000000000 },
-    { 0x080045c8, 0x00000004 },
-    { 0x00240005, 0x00000004 },
-    { 0x08004d0b, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0240e51b, 0x00000004 },
-    { 0x0080e50a, 0x00000005 },
-    { 0x0080e50b, 0x00000005 },
-    { 0x00220000, 0x00000004 },
-    { 0x000700cb, 0x00000004 },
-    { 0x000000b7, 0x00000038 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0880e5bd, 0x00000005 },
-    { 0x000c2086, 0x00000030 },
-    { 0x0800e5bb, 0x00000005 },
-    { 0x000c2087, 0x00000030 },
-    { 0x0880e5bc, 0x00000005 },
-    { 0x000000ba, 0x00000008 },
-    { 0x0080e5bd, 0x00000005 },
-    { 0x0000e5bb, 0x00000005 },
-    { 0x0080e5bc, 0x00000005 },
-    { 0x00210000, 0x00000004 },
-    { 0x02800000, 0x00000004 },
-    { 0x00c000be, 0x00000018 },
-    { 0x4180e000, 0x00000040 },
-    { 0x000000c0, 0x00000024 },
-    { 0x01000000, 0x0000000c },
-    { 0x0100e51d, 0x0000000c },
-    { 0x000045bb, 0x00000004 },
-    { 0x000080ba, 0x00000008 },
-    { 0x03c00830, 0x00000004 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x200045e0, 0x00000004 },
-    { 0x0000e5e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000700c8, 0x00000004 },
-    { 0x0800e394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x0000e8c4, 0x00000004 },
-    { 0x0000e8c5, 0x00000004 },
-    { 0x0000e8c6, 0x00000004 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000cc, 0x00000008 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000d3, 0x00000008 },
-    { 0x02c02000, 0x00000004 },
-    { 0x00060000, 0x00000004 },
-    { 0x000000db, 0x00000034 },
-    { 0x000000d8, 0x00000008 },
-    { 0x00008000, 0x00000004 },
-    { 0xc000e000, 0000000000 },
-    { 0x000000e1, 0x00000030 },
-    { 0x4200e000, 0000000000 },
-    { 0x000000e1, 0x00000030 },
-    { 0x4000e000, 0000000000 },
-    { 0x0025001b, 0x00000004 },
-    { 0x00230000, 0x00000004 },
-    { 0x00250005, 0x00000004 },
-    { 0x000000e6, 0x00000034 },
-    { 0000000000, 0x0000000c },
-    { 0x00244000, 0x00000004 },
-    { 0x080045c8, 0x00000004 },
-    { 0x00240005, 0x00000004 },
-    { 0x08004d0b, 0x0000000c },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x001d0018, 0x00000004 },
-    { 0x001a0001, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0x0500a04a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-static const u32 R520_cp_microcode[][2] = {
-    { 0x4200e000, 0000000000 },
-    { 0x4000e000, 0000000000 },
-    { 0x00000099, 0x00000008 },
-    { 0x0000009d, 0x00000008 },
-    { 0x4a554b4a, 0000000000 },
-    { 0x4a4a4467, 0000000000 },
-    { 0x55526f75, 0000000000 },
-    { 0x4a7e7d65, 0000000000 },
-    { 0xe0dae6f6, 0000000000 },
-    { 0x4ac54a4a, 0000000000 },
-    { 0xc8828282, 0000000000 },
-    { 0xbf4acfc1, 0000000000 },
-    { 0x87b04ad5, 0000000000 },
-    { 0xb5838383, 0000000000 },
-    { 0x4a0f85ba, 0000000000 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000d0012, 0x00000038 },
-    { 0x0000e8b4, 0x00000004 },
-    { 0x000d0014, 0x00000038 },
-    { 0x0000e8b6, 0x00000004 },
-    { 0x000d0016, 0x00000038 },
-    { 0x0000e854, 0x00000004 },
-    { 0x000d0018, 0x00000038 },
-    { 0x0000e855, 0x00000004 },
-    { 0x000d001a, 0x00000038 },
-    { 0x0000e856, 0x00000004 },
-    { 0x000d001c, 0x00000038 },
-    { 0x0000e857, 0x00000004 },
-    { 0x000d001e, 0x00000038 },
-    { 0x0000e824, 0x00000004 },
-    { 0x000d0020, 0x00000038 },
-    { 0x0000e825, 0x00000004 },
-    { 0x000d0022, 0x00000038 },
-    { 0x0000e830, 0x00000004 },
-    { 0x000d0024, 0x00000038 },
-    { 0x0000f0c0, 0x00000004 },
-    { 0x000d0026, 0x00000038 },
-    { 0x0000f0c1, 0x00000004 },
-    { 0x000d0028, 0x00000038 },
-    { 0x0000e000, 0x00000004 },
-    { 0x000d002a, 0x00000038 },
-    { 0x0000e000, 0x00000004 },
-    { 0x000d002c, 0x00000038 },
-    { 0x0000e000, 0x00000004 },
-    { 0x000d002e, 0x00000038 },
-    { 0x0000e000, 0x00000004 },
-    { 0x000d0030, 0x00000038 },
-    { 0x0000e000, 0x00000004 },
-    { 0x000d0032, 0x00000038 },
-    { 0x0000f180, 0x00000004 },
-    { 0x000d0034, 0x00000038 },
-    { 0x0000f393, 0x00000004 },
-    { 0x000d0036, 0x00000038 },
-    { 0x0000f38a, 0x00000004 },
-    { 0x000d0038, 0x00000038 },
-    { 0x0000f38e, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000043, 0x00000018 },
-    { 0x00cce800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x08004800, 0x00000004 },
-    { 0x0000003a, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x2000451d, 0x00000004 },
-    { 0x0000e580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x08004580, 0x00000004 },
-    { 0x000ce581, 0x00000004 },
-    { 0x00000047, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x00032000, 0x00000004 },
-    { 0x00022051, 0x00000028 },
-    { 0x00000051, 0x00000024 },
-    { 0x0800450f, 0x00000004 },
-    { 0x0000a04b, 0x00000008 },
-    { 0x0000e565, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000052, 0x00000008 },
-    { 0x03cca5b4, 0x00000004 },
-    { 0x05432000, 0x00000004 },
-    { 0x00022000, 0x00000004 },
-    { 0x4ccce05e, 0x00000030 },
-    { 0x08274565, 0x00000004 },
-    { 0x0000005e, 0x00000030 },
-    { 0x08004564, 0x00000004 },
-    { 0x0000e566, 0x00000004 },
-    { 0x00000055, 0x00000008 },
-    { 0x00802061, 0x00000010 },
-    { 0x00202000, 0x00000004 },
-    { 0x001b00ff, 0x00000004 },
-    { 0x01000064, 0x00000010 },
-    { 0x001f2000, 0x00000004 },
-    { 0x001c00ff, 0x00000004 },
-    { 0000000000, 0x0000000c },
-    { 0x00000072, 0x00000030 },
-    { 0x00000055, 0x00000008 },
-    { 0x0000e576, 0x00000004 },
-    { 0x0000e577, 0x00000004 },
-    { 0x0000e50e, 0x00000004 },
-    { 0x0000e50f, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00000069, 0x00000018 },
-    { 0x00c0e5f9, 0x000000c2 },
-    { 0x00000069, 0x00000008 },
-    { 0x0014e50e, 0x00000004 },
-    { 0x0040e50f, 0x00000004 },
-    { 0x00c0006c, 0x00000008 },
-    { 0x0000e570, 0x00000004 },
-    { 0x0000e571, 0x00000004 },
-    { 0x0000e572, 0x0000000c },
-    { 0x0000a000, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x0000e568, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00000076, 0x00000018 },
-    { 0x000b0000, 0x00000004 },
-    { 0x18c0e562, 0x00000004 },
-    { 0x00000078, 0x00000008 },
-    { 0x00c00077, 0x00000008 },
-    { 0x000700c7, 0x00000004 },
-    { 0x00000080, 0x00000038 },
-    { 0x0000e5bb, 0x00000004 },
-    { 0x0000e5bc, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e800, 0000000000 },
-    { 0x0000e821, 0x00000004 },
-    { 0x0000e82e, 0000000000 },
-    { 0x02cca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000ce1cc, 0x00000004 },
-    { 0x050de1cd, 0x00000004 },
-    { 0x00400000, 0x00000004 },
-    { 0x0000008f, 0x00000018 },
-    { 0x00c0a000, 0x00000004 },
-    { 0x0000008c, 0x00000008 },
-    { 0x00000091, 0x00000020 },
-    { 0x4200e000, 0000000000 },
-    { 0x00000098, 0x00000038 },
-    { 0x000ca000, 0x00000004 },
-    { 0x00140000, 0x00000004 },
-    { 0x000c2000, 0x00000004 },
-    { 0x00160000, 0x00000004 },
-    { 0x700ce000, 0x00000004 },
-    { 0x00140094, 0x00000008 },
-    { 0x4000e000, 0000000000 },
-    { 0x02400000, 0x00000004 },
-    { 0x400ee000, 0x00000004 },
-    { 0x02400000, 0x00000004 },
-    { 0x4000e000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x0240e51b, 0x00000004 },
-    { 0x0080e50a, 0x00000005 },
-    { 0x0080e50b, 0x00000005 },
-    { 0x00220000, 0x00000004 },
-    { 0x000700c7, 0x00000004 },
-    { 0x000000a4, 0x00000038 },
-    { 0x0080e5bd, 0x00000005 },
-    { 0x0000e5bb, 0x00000005 },
-    { 0x0080e5bc, 0x00000005 },
-    { 0x00210000, 0x00000004 },
-    { 0x02800000, 0x00000004 },
-    { 0x00c000ab, 0x00000018 },
-    { 0x4180e000, 0x00000040 },
-    { 0x000000ad, 0x00000024 },
-    { 0x01000000, 0x0000000c },
-    { 0x0100e51d, 0x0000000c },
-    { 0x000045bb, 0x00000004 },
-    { 0x000080a7, 0x00000008 },
-    { 0x0000f3ce, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053cf, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f3d2, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c053d3, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x0000f39d, 0x00000004 },
-    { 0x0140a000, 0x00000004 },
-    { 0x00cc2000, 0x00000004 },
-    { 0x08c0539e, 0x00000040 },
-    { 0x00008000, 0000000000 },
-    { 0x03c00830, 0x00000004 },
-    { 0x4200e000, 0000000000 },
-    { 0x0000a000, 0x00000004 },
-    { 0x200045e0, 0x00000004 },
-    { 0x0000e5e1, 0000000000 },
-    { 0x00000001, 0000000000 },
-    { 0x000700c4, 0x00000004 },
-    { 0x0800e394, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x0000e8c4, 0x00000004 },
-    { 0x0000e8c5, 0x00000004 },
-    { 0x0000e8c6, 0x00000004 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000c8, 0x00000008 },
-    { 0x0000e928, 0x00000004 },
-    { 0x0000e929, 0x00000004 },
-    { 0x0000e92a, 0x00000004 },
-    { 0x000000cf, 0x00000008 },
-    { 0xdeadbeef, 0000000000 },
-    { 0x00000116, 0000000000 },
-    { 0x000700d3, 0x00000004 },
-    { 0x080050e7, 0x00000004 },
-    { 0x000700d4, 0x00000004 },
-    { 0x0800401c, 0x00000004 },
-    { 0x0000e01d, 0000000000 },
-    { 0x02c02000, 0x00000004 },
-    { 0x00060000, 0x00000004 },
-    { 0x000000de, 0x00000034 },
-    { 0x000000db, 0x00000008 },
-    { 0x00008000, 0x00000004 },
-    { 0xc000e000, 0000000000 },
-    { 0x0000e1cc, 0x00000004 },
-    { 0x0500e1cd, 0x00000004 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000000e5, 0x00000034 },
-    { 0x000000e1, 0x00000008 },
-    { 0x0000a000, 0000000000 },
-    { 0x0019e1cc, 0x00000004 },
-    { 0x001b0001, 0x00000004 },
-    { 0x0500a000, 0x00000004 },
-    { 0x080041cd, 0x00000004 },
-    { 0x000ca000, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0x000c2000, 0x00000004 },
-    { 0x001d0018, 0x00000004 },
-    { 0x001a0001, 0x00000004 },
-    { 0x000000fb, 0x00000034 },
-    { 0x0000004a, 0x00000008 },
-    { 0x0500a04a, 0x00000008 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-    { 0000000000, 0000000000 },
-};
-
-
-#endif
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
deleted file mode 100644 (file)
index 11c146b..0000000
+++ /dev/null
@@ -1,3203 +0,0 @@
-/* radeon_state.c -- State support for Radeon -*- linux-c -*- */
-/*
- * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- *    Kevin E. Martin <martin@valinux.com>
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "drm_sarea.h"
-#include "radeon_drm.h"
-#include "radeon_drv.h"
-
-/* ================================================================
- * Helper functions for client state checking and fixup
- */
-
-static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
-                                                   dev_priv,
-                                                   struct drm_file * file_priv,
-                                                   u32 *offset)
-{
-       u64 off = *offset;
-       u32 fb_end = dev_priv->fb_location + dev_priv->fb_size - 1;
-       struct drm_radeon_driver_file_fields *radeon_priv;
-
-       /* Hrm ... the story of the offset ... So this function converts
-        * the various ideas of what userland clients might have for an
-        * offset in the card address space into an offset into the card
-        * address space :) So with a sane client, it should just keep
-        * the value intact and just do some boundary checking. However,
-        * not all clients are sane. Some older clients pass us 0 based
-        * offsets relative to the start of the framebuffer and some may
-        * assume the AGP aperture it appended to the framebuffer, so we
-        * try to detect those cases and fix them up.
-        *
-        * Note: It might be a good idea here to make sure the offset lands
-        * in some "allowed" area to protect things like the PCIE GART...
-        */
-
-       /* First, the best case, the offset already lands in either the
-        * framebuffer or the GART mapped space
-        */
-       if (radeon_check_offset(dev_priv, off))
-               return 0;
-
-       /* Ok, that didn't happen... now check if we have a zero based
-        * offset that fits in the framebuffer + gart space, apply the
-        * magic offset we get from SETPARAM or calculated from fb_location
-        */
-       if (off < (dev_priv->fb_size + dev_priv->gart_size)) {
-               radeon_priv = file_priv->driver_priv;
-               off += radeon_priv->radeon_fb_delta;
-       }
-
-       /* Finally, assume we aimed at a GART offset if beyond the fb */
-       if (off > fb_end)
-               off = off - fb_end - 1 + dev_priv->gart_vm_start;
-
-       /* Now recheck and fail if out of bounds */
-       if (radeon_check_offset(dev_priv, off)) {
-               DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
-               *offset = off;
-               return 0;
-       }
-       return -EINVAL;
-}
-
-static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t *
-                                                    dev_priv,
-                                                    struct drm_file *file_priv,
-                                                    int id, u32 *data)
-{
-       switch (id) {
-
-       case RADEON_EMIT_PP_MISC:
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                   &data[(RADEON_RB3D_DEPTHOFFSET - RADEON_PP_MISC) / 4])) {
-                       DRM_ERROR("Invalid depth buffer offset\n");
-                       return -EINVAL;
-               }
-               break;
-
-       case RADEON_EMIT_PP_CNTL:
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                   &data[(RADEON_RB3D_COLOROFFSET - RADEON_PP_CNTL) / 4])) {
-                       DRM_ERROR("Invalid colour buffer offset\n");
-                       return -EINVAL;
-               }
-               break;
-
-       case R200_EMIT_PP_TXOFFSET_0:
-       case R200_EMIT_PP_TXOFFSET_1:
-       case R200_EMIT_PP_TXOFFSET_2:
-       case R200_EMIT_PP_TXOFFSET_3:
-       case R200_EMIT_PP_TXOFFSET_4:
-       case R200_EMIT_PP_TXOFFSET_5:
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &data[0])) {
-                       DRM_ERROR("Invalid R200 texture offset\n");
-                       return -EINVAL;
-               }
-               break;
-
-       case RADEON_EMIT_PP_TXFILTER_0:
-       case RADEON_EMIT_PP_TXFILTER_1:
-       case RADEON_EMIT_PP_TXFILTER_2:
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                   &data[(RADEON_PP_TXOFFSET_0 - RADEON_PP_TXFILTER_0) / 4])) {
-                       DRM_ERROR("Invalid R100 texture offset\n");
-                       return -EINVAL;
-               }
-               break;
-
-       case R200_EMIT_PP_CUBIC_OFFSETS_0:
-       case R200_EMIT_PP_CUBIC_OFFSETS_1:
-       case R200_EMIT_PP_CUBIC_OFFSETS_2:
-       case R200_EMIT_PP_CUBIC_OFFSETS_3:
-       case R200_EMIT_PP_CUBIC_OFFSETS_4:
-       case R200_EMIT_PP_CUBIC_OFFSETS_5:{
-                       int i;
-                       for (i = 0; i < 5; i++) {
-                               if (radeon_check_and_fixup_offset(dev_priv,
-                                                                 file_priv,
-                                                                 &data[i])) {
-                                       DRM_ERROR
-                                           ("Invalid R200 cubic texture offset\n");
-                                       return -EINVAL;
-                               }
-                       }
-                       break;
-               }
-
-       case RADEON_EMIT_PP_CUBIC_OFFSETS_T0:
-       case RADEON_EMIT_PP_CUBIC_OFFSETS_T1:
-       case RADEON_EMIT_PP_CUBIC_OFFSETS_T2:{
-                       int i;
-                       for (i = 0; i < 5; i++) {
-                               if (radeon_check_and_fixup_offset(dev_priv,
-                                                                 file_priv,
-                                                                 &data[i])) {
-                                       DRM_ERROR
-                                           ("Invalid R100 cubic texture offset\n");
-                                       return -EINVAL;
-                               }
-                       }
-               }
-               break;
-
-       case R200_EMIT_VAP_CTL:{
-                       RING_LOCALS;
-                       BEGIN_RING(2);
-                       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
-                       ADVANCE_RING();
-               }
-               break;
-
-       case RADEON_EMIT_RB3D_COLORPITCH:
-       case RADEON_EMIT_RE_LINE_PATTERN:
-       case RADEON_EMIT_SE_LINE_WIDTH:
-       case RADEON_EMIT_PP_LUM_MATRIX:
-       case RADEON_EMIT_PP_ROT_MATRIX_0:
-       case RADEON_EMIT_RB3D_STENCILREFMASK:
-       case RADEON_EMIT_SE_VPORT_XSCALE:
-       case RADEON_EMIT_SE_CNTL:
-       case RADEON_EMIT_SE_CNTL_STATUS:
-       case RADEON_EMIT_RE_MISC:
-       case RADEON_EMIT_PP_BORDER_COLOR_0:
-       case RADEON_EMIT_PP_BORDER_COLOR_1:
-       case RADEON_EMIT_PP_BORDER_COLOR_2:
-       case RADEON_EMIT_SE_ZBIAS_FACTOR:
-       case RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT:
-       case RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED:
-       case R200_EMIT_PP_TXCBLEND_0:
-       case R200_EMIT_PP_TXCBLEND_1:
-       case R200_EMIT_PP_TXCBLEND_2:
-       case R200_EMIT_PP_TXCBLEND_3:
-       case R200_EMIT_PP_TXCBLEND_4:
-       case R200_EMIT_PP_TXCBLEND_5:
-       case R200_EMIT_PP_TXCBLEND_6:
-       case R200_EMIT_PP_TXCBLEND_7:
-       case R200_EMIT_TCL_LIGHT_MODEL_CTL_0:
-       case R200_EMIT_TFACTOR_0:
-       case R200_EMIT_VTX_FMT_0:
-       case R200_EMIT_MATRIX_SELECT_0:
-       case R200_EMIT_TEX_PROC_CTL_2:
-       case R200_EMIT_TCL_UCP_VERT_BLEND_CTL:
-       case R200_EMIT_PP_TXFILTER_0:
-       case R200_EMIT_PP_TXFILTER_1:
-       case R200_EMIT_PP_TXFILTER_2:
-       case R200_EMIT_PP_TXFILTER_3:
-       case R200_EMIT_PP_TXFILTER_4:
-       case R200_EMIT_PP_TXFILTER_5:
-       case R200_EMIT_VTE_CNTL:
-       case R200_EMIT_OUTPUT_VTX_COMP_SEL:
-       case R200_EMIT_PP_TAM_DEBUG3:
-       case R200_EMIT_PP_CNTL_X:
-       case R200_EMIT_RB3D_DEPTHXY_OFFSET:
-       case R200_EMIT_RE_AUX_SCISSOR_CNTL:
-       case R200_EMIT_RE_SCISSOR_TL_0:
-       case R200_EMIT_RE_SCISSOR_TL_1:
-       case R200_EMIT_RE_SCISSOR_TL_2:
-       case R200_EMIT_SE_VAP_CNTL_STATUS:
-       case R200_EMIT_SE_VTX_STATE_CNTL:
-       case R200_EMIT_RE_POINTSIZE:
-       case R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0:
-       case R200_EMIT_PP_CUBIC_FACES_0:
-       case R200_EMIT_PP_CUBIC_FACES_1:
-       case R200_EMIT_PP_CUBIC_FACES_2:
-       case R200_EMIT_PP_CUBIC_FACES_3:
-       case R200_EMIT_PP_CUBIC_FACES_4:
-       case R200_EMIT_PP_CUBIC_FACES_5:
-       case RADEON_EMIT_PP_TEX_SIZE_0:
-       case RADEON_EMIT_PP_TEX_SIZE_1:
-       case RADEON_EMIT_PP_TEX_SIZE_2:
-       case R200_EMIT_RB3D_BLENDCOLOR:
-       case R200_EMIT_TCL_POINT_SPRITE_CNTL:
-       case RADEON_EMIT_PP_CUBIC_FACES_0:
-       case RADEON_EMIT_PP_CUBIC_FACES_1:
-       case RADEON_EMIT_PP_CUBIC_FACES_2:
-       case R200_EMIT_PP_TRI_PERF_CNTL:
-       case R200_EMIT_PP_AFS_0:
-       case R200_EMIT_PP_AFS_1:
-       case R200_EMIT_ATF_TFACTOR:
-       case R200_EMIT_PP_TXCTLALL_0:
-       case R200_EMIT_PP_TXCTLALL_1:
-       case R200_EMIT_PP_TXCTLALL_2:
-       case R200_EMIT_PP_TXCTLALL_3:
-       case R200_EMIT_PP_TXCTLALL_4:
-       case R200_EMIT_PP_TXCTLALL_5:
-       case R200_EMIT_VAP_PVS_CNTL:
-               /* These packets don't contain memory offsets */
-               break;
-
-       default:
-               DRM_ERROR("Unknown state packet ID %d\n", id);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static __inline__ int radeon_check_and_fixup_packet3(drm_radeon_private_t *
-                                                    dev_priv,
-                                                    struct drm_file *file_priv,
-                                                    drm_radeon_kcmd_buffer_t *
-                                                    cmdbuf,
-                                                    unsigned int *cmdsz)
-{
-       u32 *cmd = (u32 *) cmdbuf->buf;
-       u32 offset, narrays;
-       int count, i, k;
-
-       *cmdsz = 2 + ((cmd[0] & RADEON_CP_PACKET_COUNT_MASK) >> 16);
-
-       if ((cmd[0] & 0xc0000000) != RADEON_CP_PACKET3) {
-               DRM_ERROR("Not a type 3 packet\n");
-               return -EINVAL;
-       }
-
-       if (4 * *cmdsz > cmdbuf->bufsz) {
-               DRM_ERROR("Packet size larger than size of data provided\n");
-               return -EINVAL;
-       }
-
-       switch(cmd[0] & 0xff00) {
-       /* XXX Are there old drivers needing other packets? */
-
-       case RADEON_3D_DRAW_IMMD:
-       case RADEON_3D_DRAW_VBUF:
-       case RADEON_3D_DRAW_INDX:
-       case RADEON_WAIT_FOR_IDLE:
-       case RADEON_CP_NOP:
-       case RADEON_3D_CLEAR_ZMASK:
-/*     case RADEON_CP_NEXT_CHAR:
-       case RADEON_CP_PLY_NEXTSCAN:
-       case RADEON_CP_SET_SCISSORS: */ /* probably safe but will never need them? */
-               /* these packets are safe */
-               break;
-
-       case RADEON_CP_3D_DRAW_IMMD_2:
-       case RADEON_CP_3D_DRAW_VBUF_2:
-       case RADEON_CP_3D_DRAW_INDX_2:
-       case RADEON_3D_CLEAR_HIZ:
-               /* safe but r200 only */
-               if (dev_priv->microcode_version != UCODE_R200) {
-                       DRM_ERROR("Invalid 3d packet for r100-class chip\n");
-                       return -EINVAL;
-               }
-               break;
-
-       case RADEON_3D_LOAD_VBPNTR:
-               count = (cmd[0] >> 16) & 0x3fff;
-
-               if (count > 18) { /* 12 arrays max */
-                       DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
-                                 count);
-                       return -EINVAL;
-               }
-
-               /* carefully check packet contents */
-               narrays = cmd[1] & ~0xc000;
-               k = 0;
-               i = 2;
-               while ((k < narrays) && (i < (count + 2))) {
-                       i++;            /* skip attribute field */
-                       if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                         &cmd[i])) {
-                               DRM_ERROR
-                                   ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
-                                    k, i);
-                               return -EINVAL;
-                       }
-                       k++;
-                       i++;
-                       if (k == narrays)
-                               break;
-                       /* have one more to process, they come in pairs */
-                       if (radeon_check_and_fixup_offset(dev_priv,
-                                                         file_priv, &cmd[i]))
-                       {
-                               DRM_ERROR
-                                   ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
-                                    k, i);
-                               return -EINVAL;
-                       }
-                       k++;
-                       i++;
-               }
-               /* do the counts match what we expect ? */
-               if ((k != narrays) || (i != (count + 2))) {
-                       DRM_ERROR
-                           ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
-                             k, i, narrays, count + 1);
-                       return -EINVAL;
-               }
-               break;
-
-       case RADEON_3D_RNDR_GEN_INDX_PRIM:
-               if (dev_priv->microcode_version != UCODE_R100) {
-                       DRM_ERROR("Invalid 3d packet for r200-class chip\n");
-                       return -EINVAL;
-               }
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv, &cmd[1])) {
-                               DRM_ERROR("Invalid rndr_gen_indx offset\n");
-                               return -EINVAL;
-               }
-               break;
-
-       case RADEON_CP_INDX_BUFFER:
-               if (dev_priv->microcode_version != UCODE_R200) {
-                       DRM_ERROR("Invalid 3d packet for r100-class chip\n");
-                       return -EINVAL;
-               }
-               if ((cmd[1] & 0x8000ffff) != 0x80000810) {
-                       DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
-                       return -EINVAL;
-               }
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv, &cmd[2])) {
-                       DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
-                       return -EINVAL;
-               }
-               break;
-
-       case RADEON_CNTL_HOSTDATA_BLT:
-       case RADEON_CNTL_PAINT_MULTI:
-       case RADEON_CNTL_BITBLT_MULTI:
-               /* MSB of opcode: next DWORD GUI_CNTL */
-               if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
-                             | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
-                       offset = cmd[2] << 10;
-                       if (radeon_check_and_fixup_offset
-                           (dev_priv, file_priv, &offset)) {
-                               DRM_ERROR("Invalid first packet offset\n");
-                               return -EINVAL;
-                       }
-                       cmd[2] = (cmd[2] & 0xffc00000) | offset >> 10;
-               }
-
-               if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
-                   (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
-                       offset = cmd[3] << 10;
-                       if (radeon_check_and_fixup_offset
-                           (dev_priv, file_priv, &offset)) {
-                               DRM_ERROR("Invalid second packet offset\n");
-                               return -EINVAL;
-                       }
-                       cmd[3] = (cmd[3] & 0xffc00000) | offset >> 10;
-               }
-               break;
-
-       default:
-               DRM_ERROR("Invalid packet type %x\n", cmd[0] & 0xff00);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/* ================================================================
- * CP hardware state programming functions
- */
-
-static __inline__ void radeon_emit_clip_rect(drm_radeon_private_t * dev_priv,
-                                            struct drm_clip_rect * box)
-{
-       RING_LOCALS;
-
-       DRM_DEBUG("   box:  x1=%d y1=%d  x2=%d y2=%d\n",
-                 box->x1, box->y1, box->x2, box->y2);
-
-       BEGIN_RING(4);
-       OUT_RING(CP_PACKET0(RADEON_RE_TOP_LEFT, 0));
-       OUT_RING((box->y1 << 16) | box->x1);
-       OUT_RING(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT, 0));
-       OUT_RING(((box->y2 - 1) << 16) | (box->x2 - 1));
-       ADVANCE_RING();
-}
-
-/* Emit 1.1 state
- */
-static int radeon_emit_state(drm_radeon_private_t * dev_priv,
-                            struct drm_file *file_priv,
-                            drm_radeon_context_regs_t * ctx,
-                            drm_radeon_texture_regs_t * tex,
-                            unsigned int dirty)
-{
-       RING_LOCALS;
-       DRM_DEBUG("dirty=0x%08x\n", dirty);
-
-       if (dirty & RADEON_UPLOAD_CONTEXT) {
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &ctx->rb3d_depthoffset)) {
-                       DRM_ERROR("Invalid depth buffer offset\n");
-                       return -EINVAL;
-               }
-
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &ctx->rb3d_coloroffset)) {
-                       DRM_ERROR("Invalid depth buffer offset\n");
-                       return -EINVAL;
-               }
-
-               BEGIN_RING(14);
-               OUT_RING(CP_PACKET0(RADEON_PP_MISC, 6));
-               OUT_RING(ctx->pp_misc);
-               OUT_RING(ctx->pp_fog_color);
-               OUT_RING(ctx->re_solid_color);
-               OUT_RING(ctx->rb3d_blendcntl);
-               OUT_RING(ctx->rb3d_depthoffset);
-               OUT_RING(ctx->rb3d_depthpitch);
-               OUT_RING(ctx->rb3d_zstencilcntl);
-               OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 2));
-               OUT_RING(ctx->pp_cntl);
-               OUT_RING(ctx->rb3d_cntl);
-               OUT_RING(ctx->rb3d_coloroffset);
-               OUT_RING(CP_PACKET0(RADEON_RB3D_COLORPITCH, 0));
-               OUT_RING(ctx->rb3d_colorpitch);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_VERTFMT) {
-               BEGIN_RING(2);
-               OUT_RING(CP_PACKET0(RADEON_SE_COORD_FMT, 0));
-               OUT_RING(ctx->se_coord_fmt);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_LINE) {
-               BEGIN_RING(5);
-               OUT_RING(CP_PACKET0(RADEON_RE_LINE_PATTERN, 1));
-               OUT_RING(ctx->re_line_pattern);
-               OUT_RING(ctx->re_line_state);
-               OUT_RING(CP_PACKET0(RADEON_SE_LINE_WIDTH, 0));
-               OUT_RING(ctx->se_line_width);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_BUMPMAP) {
-               BEGIN_RING(5);
-               OUT_RING(CP_PACKET0(RADEON_PP_LUM_MATRIX, 0));
-               OUT_RING(ctx->pp_lum_matrix);
-               OUT_RING(CP_PACKET0(RADEON_PP_ROT_MATRIX_0, 1));
-               OUT_RING(ctx->pp_rot_matrix_0);
-               OUT_RING(ctx->pp_rot_matrix_1);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_MASKS) {
-               BEGIN_RING(4);
-               OUT_RING(CP_PACKET0(RADEON_RB3D_STENCILREFMASK, 2));
-               OUT_RING(ctx->rb3d_stencilrefmask);
-               OUT_RING(ctx->rb3d_ropcntl);
-               OUT_RING(ctx->rb3d_planemask);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_VIEWPORT) {
-               BEGIN_RING(7);
-               OUT_RING(CP_PACKET0(RADEON_SE_VPORT_XSCALE, 5));
-               OUT_RING(ctx->se_vport_xscale);
-               OUT_RING(ctx->se_vport_xoffset);
-               OUT_RING(ctx->se_vport_yscale);
-               OUT_RING(ctx->se_vport_yoffset);
-               OUT_RING(ctx->se_vport_zscale);
-               OUT_RING(ctx->se_vport_zoffset);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_SETUP) {
-               BEGIN_RING(4);
-               OUT_RING(CP_PACKET0(RADEON_SE_CNTL, 0));
-               OUT_RING(ctx->se_cntl);
-               OUT_RING(CP_PACKET0(RADEON_SE_CNTL_STATUS, 0));
-               OUT_RING(ctx->se_cntl_status);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_MISC) {
-               BEGIN_RING(2);
-               OUT_RING(CP_PACKET0(RADEON_RE_MISC, 0));
-               OUT_RING(ctx->re_misc);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_TEX0) {
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &tex[0].pp_txoffset)) {
-                       DRM_ERROR("Invalid texture offset for unit 0\n");
-                       return -EINVAL;
-               }
-
-               BEGIN_RING(9);
-               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_0, 5));
-               OUT_RING(tex[0].pp_txfilter);
-               OUT_RING(tex[0].pp_txformat);
-               OUT_RING(tex[0].pp_txoffset);
-               OUT_RING(tex[0].pp_txcblend);
-               OUT_RING(tex[0].pp_txablend);
-               OUT_RING(tex[0].pp_tfactor);
-               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_0, 0));
-               OUT_RING(tex[0].pp_border_color);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_TEX1) {
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &tex[1].pp_txoffset)) {
-                       DRM_ERROR("Invalid texture offset for unit 1\n");
-                       return -EINVAL;
-               }
-
-               BEGIN_RING(9);
-               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_1, 5));
-               OUT_RING(tex[1].pp_txfilter);
-               OUT_RING(tex[1].pp_txformat);
-               OUT_RING(tex[1].pp_txoffset);
-               OUT_RING(tex[1].pp_txcblend);
-               OUT_RING(tex[1].pp_txablend);
-               OUT_RING(tex[1].pp_tfactor);
-               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_1, 0));
-               OUT_RING(tex[1].pp_border_color);
-               ADVANCE_RING();
-       }
-
-       if (dirty & RADEON_UPLOAD_TEX2) {
-               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
-                                                 &tex[2].pp_txoffset)) {
-                       DRM_ERROR("Invalid texture offset for unit 2\n");
-                       return -EINVAL;
-               }
-
-               BEGIN_RING(9);
-               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_2, 5));
-               OUT_RING(tex[2].pp_txfilter);
-               OUT_RING(tex[2].pp_txformat);
-               OUT_RING(tex[2].pp_txoffset);
-               OUT_RING(tex[2].pp_txcblend);
-               OUT_RING(tex[2].pp_txablend);
-               OUT_RING(tex[2].pp_tfactor);
-               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_2, 0));
-               OUT_RING(tex[2].pp_border_color);
-               ADVANCE_RING();
-       }
-
-       return 0;
-}
-
-/* Emit 1.2 state
- */
-static int radeon_emit_state2(drm_radeon_private_t * dev_priv,
-                             struct drm_file *file_priv,
-                             drm_radeon_state_t * state)
-{
-       RING_LOCALS;
-
-       if (state->dirty & RADEON_UPLOAD_ZBIAS) {
-               BEGIN_RING(3);
-               OUT_RING(CP_PACKET0(RADEON_SE_ZBIAS_FACTOR, 1));
-               OUT_RING(state->context2.se_zbias_factor);
-               OUT_RING(state->context2.se_zbias_constant);
-               ADVANCE_RING();
-       }
-
-       return radeon_emit_state(dev_priv, file_priv, &state->context,
-                                state->tex, state->dirty);
-}
-
-/* New (1.3) state mechanism.  3 commands (packet, scalar, vector) in
- * 1.3 cmdbuffers allow all previous state to be updated as well as
- * the tcl scalar and vector areas.
- */
-static struct {
-       int start;
-       int len;
-       const char *name;
-} packet[RADEON_MAX_STATE_PACKETS] = {
-       {RADEON_PP_MISC, 7, "RADEON_PP_MISC"},
-       {RADEON_PP_CNTL, 3, "RADEON_PP_CNTL"},
-       {RADEON_RB3D_COLORPITCH, 1, "RADEON_RB3D_COLORPITCH"},
-       {RADEON_RE_LINE_PATTERN, 2, "RADEON_RE_LINE_PATTERN"},
-       {RADEON_SE_LINE_WIDTH, 1, "RADEON_SE_LINE_WIDTH"},
-       {RADEON_PP_LUM_MATRIX, 1, "RADEON_PP_LUM_MATRIX"},
-       {RADEON_PP_ROT_MATRIX_0, 2, "RADEON_PP_ROT_MATRIX_0"},
-       {RADEON_RB3D_STENCILREFMASK, 3, "RADEON_RB3D_STENCILREFMASK"},
-       {RADEON_SE_VPORT_XSCALE, 6, "RADEON_SE_VPORT_XSCALE"},
-       {RADEON_SE_CNTL, 2, "RADEON_SE_CNTL"},
-       {RADEON_SE_CNTL_STATUS, 1, "RADEON_SE_CNTL_STATUS"},
-       {RADEON_RE_MISC, 1, "RADEON_RE_MISC"},
-       {RADEON_PP_TXFILTER_0, 6, "RADEON_PP_TXFILTER_0"},
-       {RADEON_PP_BORDER_COLOR_0, 1, "RADEON_PP_BORDER_COLOR_0"},
-       {RADEON_PP_TXFILTER_1, 6, "RADEON_PP_TXFILTER_1"},
-       {RADEON_PP_BORDER_COLOR_1, 1, "RADEON_PP_BORDER_COLOR_1"},
-       {RADEON_PP_TXFILTER_2, 6, "RADEON_PP_TXFILTER_2"},
-       {RADEON_PP_BORDER_COLOR_2, 1, "RADEON_PP_BORDER_COLOR_2"},
-       {RADEON_SE_ZBIAS_FACTOR, 2, "RADEON_SE_ZBIAS_FACTOR"},
-       {RADEON_SE_TCL_OUTPUT_VTX_FMT, 11, "RADEON_SE_TCL_OUTPUT_VTX_FMT"},
-       {RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED, 17,
-                   "RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
-       {R200_PP_TXCBLEND_0, 4, "R200_PP_TXCBLEND_0"},
-       {R200_PP_TXCBLEND_1, 4, "R200_PP_TXCBLEND_1"},
-       {R200_PP_TXCBLEND_2, 4, "R200_PP_TXCBLEND_2"},
-       {R200_PP_TXCBLEND_3, 4, "R200_PP_TXCBLEND_3"},
-       {R200_PP_TXCBLEND_4, 4, "R200_PP_TXCBLEND_4"},
-       {R200_PP_TXCBLEND_5, 4, "R200_PP_TXCBLEND_5"},
-       {R200_PP_TXCBLEND_6, 4, "R200_PP_TXCBLEND_6"},
-       {R200_PP_TXCBLEND_7, 4, "R200_PP_TXCBLEND_7"},
-       {R200_SE_TCL_LIGHT_MODEL_CTL_0, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0"},
-       {R200_PP_TFACTOR_0, 6, "R200_PP_TFACTOR_0"},
-       {R200_SE_VTX_FMT_0, 4, "R200_SE_VTX_FMT_0"},
-       {R200_SE_VAP_CNTL, 1, "R200_SE_VAP_CNTL"},
-       {R200_SE_TCL_MATRIX_SEL_0, 5, "R200_SE_TCL_MATRIX_SEL_0"},
-       {R200_SE_TCL_TEX_PROC_CTL_2, 5, "R200_SE_TCL_TEX_PROC_CTL_2"},
-       {R200_SE_TCL_UCP_VERT_BLEND_CTL, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL"},
-       {R200_PP_TXFILTER_0, 6, "R200_PP_TXFILTER_0"},
-       {R200_PP_TXFILTER_1, 6, "R200_PP_TXFILTER_1"},
-       {R200_PP_TXFILTER_2, 6, "R200_PP_TXFILTER_2"},
-       {R200_PP_TXFILTER_3, 6, "R200_PP_TXFILTER_3"},
-       {R200_PP_TXFILTER_4, 6, "R200_PP_TXFILTER_4"},
-       {R200_PP_TXFILTER_5, 6, "R200_PP_TXFILTER_5"},
-       {R200_PP_TXOFFSET_0, 1, "R200_PP_TXOFFSET_0"},
-       {R200_PP_TXOFFSET_1, 1, "R200_PP_TXOFFSET_1"},
-       {R200_PP_TXOFFSET_2, 1, "R200_PP_TXOFFSET_2"},
-       {R200_PP_TXOFFSET_3, 1, "R200_PP_TXOFFSET_3"},
-       {R200_PP_TXOFFSET_4, 1, "R200_PP_TXOFFSET_4"},
-       {R200_PP_TXOFFSET_5, 1, "R200_PP_TXOFFSET_5"},
-       {R200_SE_VTE_CNTL, 1, "R200_SE_VTE_CNTL"},
-       {R200_SE_TCL_OUTPUT_VTX_COMP_SEL, 1,
-        "R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
-       {R200_PP_TAM_DEBUG3, 1, "R200_PP_TAM_DEBUG3"},
-       {R200_PP_CNTL_X, 1, "R200_PP_CNTL_X"},
-       {R200_RB3D_DEPTHXY_OFFSET, 1, "R200_RB3D_DEPTHXY_OFFSET"},
-       {R200_RE_AUX_SCISSOR_CNTL, 1, "R200_RE_AUX_SCISSOR_CNTL"},
-       {R200_RE_SCISSOR_TL_0, 2, "R200_RE_SCISSOR_TL_0"},
-       {R200_RE_SCISSOR_TL_1, 2, "R200_RE_SCISSOR_TL_1"},
-       {R200_RE_SCISSOR_TL_2, 2, "R200_RE_SCISSOR_TL_2"},
-       {R200_SE_VAP_CNTL_STATUS, 1, "R200_SE_VAP_CNTL_STATUS"},
-       {R200_SE_VTX_STATE_CNTL, 1, "R200_SE_VTX_STATE_CNTL"},
-       {R200_RE_POINTSIZE, 1, "R200_RE_POINTSIZE"},
-       {R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0, 4,
-                   "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
-       {R200_PP_CUBIC_FACES_0, 1, "R200_PP_CUBIC_FACES_0"},    /* 61 */
-       {R200_PP_CUBIC_OFFSET_F1_0, 5, "R200_PP_CUBIC_OFFSET_F1_0"}, /* 62 */
-       {R200_PP_CUBIC_FACES_1, 1, "R200_PP_CUBIC_FACES_1"},
-       {R200_PP_CUBIC_OFFSET_F1_1, 5, "R200_PP_CUBIC_OFFSET_F1_1"},
-       {R200_PP_CUBIC_FACES_2, 1, "R200_PP_CUBIC_FACES_2"},
-       {R200_PP_CUBIC_OFFSET_F1_2, 5, "R200_PP_CUBIC_OFFSET_F1_2"},
-       {R200_PP_CUBIC_FACES_3, 1, "R200_PP_CUBIC_FACES_3"},
-       {R200_PP_CUBIC_OFFSET_F1_3, 5, "R200_PP_CUBIC_OFFSET_F1_3"},
-       {R200_PP_CUBIC_FACES_4, 1, "R200_PP_CUBIC_FACES_4"},
-       {R200_PP_CUBIC_OFFSET_F1_4, 5, "R200_PP_CUBIC_OFFSET_F1_4"},
-       {R200_PP_CUBIC_FACES_5, 1, "R200_PP_CUBIC_FACES_5"},
-       {R200_PP_CUBIC_OFFSET_F1_5, 5, "R200_PP_CUBIC_OFFSET_F1_5"},
-       {RADEON_PP_TEX_SIZE_0, 2, "RADEON_PP_TEX_SIZE_0"},
-       {RADEON_PP_TEX_SIZE_1, 2, "RADEON_PP_TEX_SIZE_1"},
-       {RADEON_PP_TEX_SIZE_2, 2, "RADEON_PP_TEX_SIZE_2"},
-       {R200_RB3D_BLENDCOLOR, 3, "R200_RB3D_BLENDCOLOR"},
-       {R200_SE_TCL_POINT_SPRITE_CNTL, 1, "R200_SE_TCL_POINT_SPRITE_CNTL"},
-       {RADEON_PP_CUBIC_FACES_0, 1, "RADEON_PP_CUBIC_FACES_0"},
-       {RADEON_PP_CUBIC_OFFSET_T0_0, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
-       {RADEON_PP_CUBIC_FACES_1, 1, "RADEON_PP_CUBIC_FACES_1"},
-       {RADEON_PP_CUBIC_OFFSET_T1_0, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
-       {RADEON_PP_CUBIC_FACES_2, 1, "RADEON_PP_CUBIC_FACES_2"},
-       {RADEON_PP_CUBIC_OFFSET_T2_0, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
-       {R200_PP_TRI_PERF, 2, "R200_PP_TRI_PERF"},
-       {R200_PP_AFS_0, 32, "R200_PP_AFS_0"},     /* 85 */
-       {R200_PP_AFS_1, 32, "R200_PP_AFS_1"},
-       {R200_PP_TFACTOR_0, 8, "R200_ATF_TFACTOR"},
-       {R200_PP_TXFILTER_0, 8, "R200_PP_TXCTLALL_0"},
-       {R200_PP_TXFILTER_1, 8, "R200_PP_TXCTLALL_1"},
-       {R200_PP_TXFILTER_2, 8, "R200_PP_TXCTLALL_2"},
-       {R200_PP_TXFILTER_3, 8, "R200_PP_TXCTLALL_3"},
-       {R200_PP_TXFILTER_4, 8, "R200_PP_TXCTLALL_4"},
-       {R200_PP_TXFILTER_5, 8, "R200_PP_TXCTLALL_5"},
-       {R200_VAP_PVS_CNTL_1, 2, "R200_VAP_PVS_CNTL"},
-};
-
-/* ================================================================
- * Performance monitoring functions
- */
-
-static void radeon_clear_box(drm_radeon_private_t * dev_priv,
-                            int x, int y, int w, int h, int r, int g, int b)
-{
-       u32 color;
-       RING_LOCALS;
-
-       x += dev_priv->sarea_priv->boxes[0].x1;
-       y += dev_priv->sarea_priv->boxes[0].y1;
-
-       switch (dev_priv->color_fmt) {
-       case RADEON_COLOR_FORMAT_RGB565:
-               color = (((r & 0xf8) << 8) |
-                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
-               break;
-       case RADEON_COLOR_FORMAT_ARGB8888:
-       default:
-               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
-               break;
-       }
-
-       BEGIN_RING(4);
-       RADEON_WAIT_UNTIL_3D_IDLE();
-       OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
-       OUT_RING(0xffffffff);
-       ADVANCE_RING();
-
-       BEGIN_RING(6);
-
-       OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
-       OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-                RADEON_GMC_BRUSH_SOLID_COLOR |
-                (dev_priv->color_fmt << 8) |
-                RADEON_GMC_SRC_DATATYPE_COLOR |
-                RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS);
-
-       if (dev_priv->sarea_priv->pfCurrentPage == 1) {
-               OUT_RING(dev_priv->front_pitch_offset);
-       } else {
-               OUT_RING(dev_priv->back_pitch_offset);
-       }
-
-       OUT_RING(color);
-
-       OUT_RING((x << 16) | y);
-       OUT_RING((w << 16) | h);
-
-       ADVANCE_RING();
-}
-
-static void radeon_cp_performance_boxes(drm_radeon_private_t * dev_priv)
-{
-       /* Collapse various things into a wait flag -- trying to
-        * guess if userspase slept -- better just to have them tell us.
-        */
-       if (dev_priv->stats.last_frame_reads > 1 ||
-           dev_priv->stats.last_clear_reads > dev_priv->stats.clears) {
-               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-       }
-
-       if (dev_priv->stats.freelist_loops) {
-               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
-       }
-
-       /* Purple box for page flipping
-        */
-       if (dev_priv->stats.boxes & RADEON_BOX_FLIP)
-               radeon_clear_box(dev_priv, 4, 4, 8, 8, 255, 0, 255);
-
-       /* Red box if we have to wait for idle at any point
-        */
-       if (dev_priv->stats.boxes & RADEON_BOX_WAIT_IDLE)
-               radeon_clear_box(dev_priv, 16, 4, 8, 8, 255, 0, 0);
-
-       /* Blue box: lost context?
-        */
-
-       /* Yellow box for texture swaps
-        */
-       if (dev_priv->stats.boxes & RADEON_BOX_TEXTURE_LOAD)
-               radeon_clear_box(dev_priv, 40, 4, 8, 8, 255, 255, 0);
-
-       /* Green box if hardware never idles (as far as we can tell)
-        */
-       if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE))
-               radeon_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
-
-       /* Draw bars indicating number of buffers allocated
-        * (not a great measure, easily confused)
-        */
-       if (dev_priv->stats.requested_bufs) {
-               if (dev_priv->stats.requested_bufs > 100)
-                       dev_priv->stats.requested_bufs = 100;
-
-               radeon_clear_box(dev_priv, 4, 16,
-                                dev_priv->stats.requested_bufs, 4,
-                                196, 128, 128);
-       }
-
-       memset(&dev_priv->stats, 0, sizeof(dev_priv->stats));
-
-}
-
-/* ================================================================
- * CP command dispatch functions
- */
-
-static void radeon_cp_dispatch_clear(struct drm_device * dev,
-                                    drm_radeon_clear_t * clear,
-                                    drm_radeon_clear_rect_t * depth_boxes)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_radeon_depth_clear_t *depth_clear = &dev_priv->depth_clear;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       unsigned int flags = clear->flags;
-       u32 rb3d_cntl = 0, rb3d_stencilrefmask = 0;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("flags = 0x%x\n", flags);
-
-       dev_priv->stats.clears++;
-
-       if (dev_priv->sarea_priv->pfCurrentPage == 1) {
-               unsigned int tmp = flags;
-
-               flags &= ~(RADEON_FRONT | RADEON_BACK);
-               if (tmp & RADEON_FRONT)
-                       flags |= RADEON_BACK;
-               if (tmp & RADEON_BACK)
-                       flags |= RADEON_FRONT;
-       }
-
-       if (flags & (RADEON_FRONT | RADEON_BACK)) {
-
-               BEGIN_RING(4);
-
-               /* Ensure the 3D stream is idle before doing a
-                * 2D fill to clear the front or back buffer.
-                */
-               RADEON_WAIT_UNTIL_3D_IDLE();
-
-               OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
-               OUT_RING(clear->color_mask);
-
-               ADVANCE_RING();
-
-               /* Make sure we restore the 3D state next time.
-                */
-               dev_priv->sarea_priv->ctx_owner = 0;
-
-               for (i = 0; i < nbox; i++) {
-                       int x = pbox[i].x1;
-                       int y = pbox[i].y1;
-                       int w = pbox[i].x2 - x;
-                       int h = pbox[i].y2 - y;
-
-                       DRM_DEBUG("%d,%d-%d,%d flags 0x%x\n",
-                                 x, y, w, h, flags);
-
-                       if (flags & RADEON_FRONT) {
-                               BEGIN_RING(6);
-
-                               OUT_RING(CP_PACKET3
-                                        (RADEON_CNTL_PAINT_MULTI, 4));
-                               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-                                        RADEON_GMC_BRUSH_SOLID_COLOR |
-                                        (dev_priv->
-                                         color_fmt << 8) |
-                                        RADEON_GMC_SRC_DATATYPE_COLOR |
-                                        RADEON_ROP3_P |
-                                        RADEON_GMC_CLR_CMP_CNTL_DIS);
-
-                               OUT_RING(dev_priv->front_pitch_offset);
-                               OUT_RING(clear->clear_color);
-
-                               OUT_RING((x << 16) | y);
-                               OUT_RING((w << 16) | h);
-
-                               ADVANCE_RING();
-                       }
-
-                       if (flags & RADEON_BACK) {
-                               BEGIN_RING(6);
-
-                               OUT_RING(CP_PACKET3
-                                        (RADEON_CNTL_PAINT_MULTI, 4));
-                               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-                                        RADEON_GMC_BRUSH_SOLID_COLOR |
-                                        (dev_priv->
-                                         color_fmt << 8) |
-                                        RADEON_GMC_SRC_DATATYPE_COLOR |
-                                        RADEON_ROP3_P |
-                                        RADEON_GMC_CLR_CMP_CNTL_DIS);
-
-                               OUT_RING(dev_priv->back_pitch_offset);
-                               OUT_RING(clear->clear_color);
-
-                               OUT_RING((x << 16) | y);
-                               OUT_RING((w << 16) | h);
-
-                               ADVANCE_RING();
-                       }
-               }
-       }
-
-       /* hyper z clear */
-       /* no docs available, based on reverse engeneering by Stephane Marchesin */
-       if ((flags & (RADEON_DEPTH | RADEON_STENCIL))
-           && (flags & RADEON_CLEAR_FASTZ)) {
-
-               int i;
-               int depthpixperline =
-                   dev_priv->depth_fmt ==
-                   RADEON_DEPTH_FORMAT_16BIT_INT_Z ? (dev_priv->depth_pitch /
-                                                      2) : (dev_priv->
-                                                            depth_pitch / 4);
-
-               u32 clearmask;
-
-               u32 tempRB3D_DEPTHCLEARVALUE = clear->clear_depth |
-                   ((clear->depth_mask & 0xff) << 24);
-
-               /* Make sure we restore the 3D state next time.
-                * we haven't touched any "normal" state - still need this?
-                */
-               dev_priv->sarea_priv->ctx_owner = 0;
-
-               if ((dev_priv->flags & RADEON_HAS_HIERZ)
-                   && (flags & RADEON_USE_HIERZ)) {
-                       /* FIXME : reverse engineer that for Rx00 cards */
-                       /* FIXME : the mask supposedly contains low-res z values. So can't set
-                          just to the max (0xff? or actually 0x3fff?), need to take z clear
-                          value into account? */
-                       /* pattern seems to work for r100, though get slight
-                          rendering errors with glxgears. If hierz is not enabled for r100,
-                          only 4 bits which indicate clear (15,16,31,32, all zero) matter, the
-                          other ones are ignored, and the same clear mask can be used. That's
-                          very different behaviour than R200 which needs different clear mask
-                          and different number of tiles to clear if hierz is enabled or not !?!
-                        */
-                       clearmask = (0xff << 22) | (0xff << 6) | 0x003f003f;
-               } else {
-                       /* clear mask : chooses the clearing pattern.
-                          rv250: could be used to clear only parts of macrotiles
-                          (but that would get really complicated...)?
-                          bit 0 and 1 (either or both of them ?!?!) are used to
-                          not clear tile (or maybe one of the bits indicates if the tile is
-                          compressed or not), bit 2 and 3 to not clear tile 1,...,.
-                          Pattern is as follows:
-                          | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
-                          bits -------------------------------------------------
-                          | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
-                          rv100: clearmask covers 2x8 4x1 tiles, but one clear still
-                          covers 256 pixels ?!?
-                        */
-                       clearmask = 0x0;
-               }
-
-               BEGIN_RING(8);
-               RADEON_WAIT_UNTIL_2D_IDLE();
-               OUT_RING_REG(RADEON_RB3D_DEPTHCLEARVALUE,
-                            tempRB3D_DEPTHCLEARVALUE);
-               /* what offset is this exactly ? */
-               OUT_RING_REG(RADEON_RB3D_ZMASKOFFSET, 0);
-               /* need ctlstat, otherwise get some strange black flickering */
-               OUT_RING_REG(RADEON_RB3D_ZCACHE_CTLSTAT,
-                            RADEON_RB3D_ZC_FLUSH_ALL);
-               ADVANCE_RING();
-
-               for (i = 0; i < nbox; i++) {
-                       int tileoffset, nrtilesx, nrtilesy, j;
-                       /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
-                       if ((dev_priv->flags & RADEON_HAS_HIERZ)
-                           && !(dev_priv->microcode_version == UCODE_R200)) {
-                               /* FIXME : figure this out for r200 (when hierz is enabled). Or
-                                  maybe r200 actually doesn't need to put the low-res z value into
-                                  the tile cache like r100, but just needs to clear the hi-level z-buffer?
-                                  Works for R100, both with hierz and without.
-                                  R100 seems to operate on 2x1 8x8 tiles, but...
-                                  odd: offset/nrtiles need to be 64 pix (4 block) aligned? Potentially
-                                  problematic with resolutions which are not 64 pix aligned? */
-                               tileoffset =
-                                   ((pbox[i].y1 >> 3) * depthpixperline +
-                                    pbox[i].x1) >> 6;
-                               nrtilesx =
-                                   ((pbox[i].x2 & ~63) -
-                                    (pbox[i].x1 & ~63)) >> 4;
-                               nrtilesy =
-                                   (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
-                               for (j = 0; j <= nrtilesy; j++) {
-                                       BEGIN_RING(4);
-                                       OUT_RING(CP_PACKET3
-                                                (RADEON_3D_CLEAR_ZMASK, 2));
-                                       /* first tile */
-                                       OUT_RING(tileoffset * 8);
-                                       /* the number of tiles to clear */
-                                       OUT_RING(nrtilesx + 4);
-                                       /* clear mask : chooses the clearing pattern. */
-                                       OUT_RING(clearmask);
-                                       ADVANCE_RING();
-                                       tileoffset += depthpixperline >> 6;
-                               }
-                       } else if (dev_priv->microcode_version == UCODE_R200) {
-                               /* works for rv250. */
-                               /* find first macro tile (8x2 4x4 z-pixels on rv250) */
-                               tileoffset =
-                                   ((pbox[i].y1 >> 3) * depthpixperline +
-                                    pbox[i].x1) >> 5;
-                               nrtilesx =
-                                   (pbox[i].x2 >> 5) - (pbox[i].x1 >> 5);
-                               nrtilesy =
-                                   (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
-                               for (j = 0; j <= nrtilesy; j++) {
-                                       BEGIN_RING(4);
-                                       OUT_RING(CP_PACKET3
-                                                (RADEON_3D_CLEAR_ZMASK, 2));
-                                       /* first tile */
-                                       /* judging by the first tile offset needed, could possibly
-                                          directly address/clear 4x4 tiles instead of 8x2 * 4x4
-                                          macro tiles, though would still need clear mask for
-                                          right/bottom if truely 4x4 granularity is desired ? */
-                                       OUT_RING(tileoffset * 16);
-                                       /* the number of tiles to clear */
-                                       OUT_RING(nrtilesx + 1);
-                                       /* clear mask : chooses the clearing pattern. */
-                                       OUT_RING(clearmask);
-                                       ADVANCE_RING();
-                                       tileoffset += depthpixperline >> 5;
-                               }
-                       } else {        /* rv 100 */
-                               /* rv100 might not need 64 pix alignment, who knows */
-                               /* offsets are, hmm, weird */
-                               tileoffset =
-                                   ((pbox[i].y1 >> 4) * depthpixperline +
-                                    pbox[i].x1) >> 6;
-                               nrtilesx =
-                                   ((pbox[i].x2 & ~63) -
-                                    (pbox[i].x1 & ~63)) >> 4;
-                               nrtilesy =
-                                   (pbox[i].y2 >> 4) - (pbox[i].y1 >> 4);
-                               for (j = 0; j <= nrtilesy; j++) {
-                                       BEGIN_RING(4);
-                                       OUT_RING(CP_PACKET3
-                                                (RADEON_3D_CLEAR_ZMASK, 2));
-                                       OUT_RING(tileoffset * 128);
-                                       /* the number of tiles to clear */
-                                       OUT_RING(nrtilesx + 4);
-                                       /* clear mask : chooses the clearing pattern. */
-                                       OUT_RING(clearmask);
-                                       ADVANCE_RING();
-                                       tileoffset += depthpixperline >> 6;
-                               }
-                       }
-               }
-
-               /* TODO don't always clear all hi-level z tiles */
-               if ((dev_priv->flags & RADEON_HAS_HIERZ)
-                   && (dev_priv->microcode_version == UCODE_R200)
-                   && (flags & RADEON_USE_HIERZ))
-                       /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
-                       /* FIXME : the mask supposedly contains low-res z values. So can't set
-                          just to the max (0xff? or actually 0x3fff?), need to take z clear
-                          value into account? */
-               {
-                       BEGIN_RING(4);
-                       OUT_RING(CP_PACKET3(RADEON_3D_CLEAR_HIZ, 2));
-                       OUT_RING(0x0);  /* First tile */
-                       OUT_RING(0x3cc0);
-                       OUT_RING((0xff << 22) | (0xff << 6) | 0x003f003f);
-                       ADVANCE_RING();
-               }
-       }
-
-       /* We have to clear the depth and/or stencil buffers by
-        * rendering a quad into just those buffers.  Thus, we have to
-        * make sure the 3D engine is configured correctly.
-        */
-       else if ((dev_priv->microcode_version == UCODE_R200) &&
-               (flags & (RADEON_DEPTH | RADEON_STENCIL))) {
-
-               int tempPP_CNTL;
-               int tempRE_CNTL;
-               int tempRB3D_CNTL;
-               int tempRB3D_ZSTENCILCNTL;
-               int tempRB3D_STENCILREFMASK;
-               int tempRB3D_PLANEMASK;
-               int tempSE_CNTL;
-               int tempSE_VTE_CNTL;
-               int tempSE_VTX_FMT_0;
-               int tempSE_VTX_FMT_1;
-               int tempSE_VAP_CNTL;
-               int tempRE_AUX_SCISSOR_CNTL;
-
-               tempPP_CNTL = 0;
-               tempRE_CNTL = 0;
-
-               tempRB3D_CNTL = depth_clear->rb3d_cntl;
-
-               tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
-               tempRB3D_STENCILREFMASK = 0x0;
-
-               tempSE_CNTL = depth_clear->se_cntl;
-
-               /* Disable TCL */
-
-               tempSE_VAP_CNTL = (     /* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK |  */
-                                         (0x9 <<
-                                          SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT));
-
-               tempRB3D_PLANEMASK = 0x0;
-
-               tempRE_AUX_SCISSOR_CNTL = 0x0;
-
-               tempSE_VTE_CNTL =
-                   SE_VTE_CNTL__VTX_XY_FMT_MASK | SE_VTE_CNTL__VTX_Z_FMT_MASK;
-
-               /* Vertex format (X, Y, Z, W) */
-               tempSE_VTX_FMT_0 =
-                   SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK |
-                   SE_VTX_FMT_0__VTX_W0_PRESENT_MASK;
-               tempSE_VTX_FMT_1 = 0x0;
-
-               /*
-                * Depth buffer specific enables
-                */
-               if (flags & RADEON_DEPTH) {
-                       /* Enable depth buffer */
-                       tempRB3D_CNTL |= RADEON_Z_ENABLE;
-               } else {
-                       /* Disable depth buffer */
-                       tempRB3D_CNTL &= ~RADEON_Z_ENABLE;
-               }
-
-               /*
-                * Stencil buffer specific enables
-                */
-               if (flags & RADEON_STENCIL) {
-                       tempRB3D_CNTL |= RADEON_STENCIL_ENABLE;
-                       tempRB3D_STENCILREFMASK = clear->depth_mask;
-               } else {
-                       tempRB3D_CNTL &= ~RADEON_STENCIL_ENABLE;
-                       tempRB3D_STENCILREFMASK = 0x00000000;
-               }
-
-               if (flags & RADEON_USE_COMP_ZBUF) {
-                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
-                           RADEON_Z_DECOMPRESSION_ENABLE;
-               }
-               if (flags & RADEON_USE_HIERZ) {
-                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
-               }
-
-               BEGIN_RING(26);
-               RADEON_WAIT_UNTIL_2D_IDLE();
-
-               OUT_RING_REG(RADEON_PP_CNTL, tempPP_CNTL);
-               OUT_RING_REG(R200_RE_CNTL, tempRE_CNTL);
-               OUT_RING_REG(RADEON_RB3D_CNTL, tempRB3D_CNTL);
-               OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
-               OUT_RING_REG(RADEON_RB3D_STENCILREFMASK,
-                            tempRB3D_STENCILREFMASK);
-               OUT_RING_REG(RADEON_RB3D_PLANEMASK, tempRB3D_PLANEMASK);
-               OUT_RING_REG(RADEON_SE_CNTL, tempSE_CNTL);
-               OUT_RING_REG(R200_SE_VTE_CNTL, tempSE_VTE_CNTL);
-               OUT_RING_REG(R200_SE_VTX_FMT_0, tempSE_VTX_FMT_0);
-               OUT_RING_REG(R200_SE_VTX_FMT_1, tempSE_VTX_FMT_1);
-               OUT_RING_REG(R200_SE_VAP_CNTL, tempSE_VAP_CNTL);
-               OUT_RING_REG(R200_RE_AUX_SCISSOR_CNTL, tempRE_AUX_SCISSOR_CNTL);
-               ADVANCE_RING();
-
-               /* Make sure we restore the 3D state next time.
-                */
-               dev_priv->sarea_priv->ctx_owner = 0;
-
-               for (i = 0; i < nbox; i++) {
-
-                       /* Funny that this should be required --
-                        *  sets top-left?
-                        */
-                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
-
-                       BEGIN_RING(14);
-                       OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 12));
-                       OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
-                                 RADEON_PRIM_WALK_RING |
-                                 (3 << RADEON_NUM_VERTICES_SHIFT)));
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x3f800000);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x3f800000);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x3f800000);
-                       ADVANCE_RING();
-               }
-       } else if ((flags & (RADEON_DEPTH | RADEON_STENCIL))) {
-
-               int tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
-
-               rb3d_cntl = depth_clear->rb3d_cntl;
-
-               if (flags & RADEON_DEPTH) {
-                       rb3d_cntl |= RADEON_Z_ENABLE;
-               } else {
-                       rb3d_cntl &= ~RADEON_Z_ENABLE;
-               }
-
-               if (flags & RADEON_STENCIL) {
-                       rb3d_cntl |= RADEON_STENCIL_ENABLE;
-                       rb3d_stencilrefmask = clear->depth_mask;        /* misnamed field */
-               } else {
-                       rb3d_cntl &= ~RADEON_STENCIL_ENABLE;
-                       rb3d_stencilrefmask = 0x00000000;
-               }
-
-               if (flags & RADEON_USE_COMP_ZBUF) {
-                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
-                           RADEON_Z_DECOMPRESSION_ENABLE;
-               }
-               if (flags & RADEON_USE_HIERZ) {
-                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
-               }
-
-               BEGIN_RING(13);
-               RADEON_WAIT_UNTIL_2D_IDLE();
-
-               OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 1));
-               OUT_RING(0x00000000);
-               OUT_RING(rb3d_cntl);
-
-               OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
-               OUT_RING_REG(RADEON_RB3D_STENCILREFMASK, rb3d_stencilrefmask);
-               OUT_RING_REG(RADEON_RB3D_PLANEMASK, 0x00000000);
-               OUT_RING_REG(RADEON_SE_CNTL, depth_clear->se_cntl);
-               ADVANCE_RING();
-
-               /* Make sure we restore the 3D state next time.
-                */
-               dev_priv->sarea_priv->ctx_owner = 0;
-
-               for (i = 0; i < nbox; i++) {
-
-                       /* Funny that this should be required --
-                        *  sets top-left?
-                        */
-                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
-
-                       BEGIN_RING(15);
-
-                       OUT_RING(CP_PACKET3(RADEON_3D_DRAW_IMMD, 13));
-                       OUT_RING(RADEON_VTX_Z_PRESENT |
-                                RADEON_VTX_PKCOLOR_PRESENT);
-                       OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
-                                 RADEON_PRIM_WALK_RING |
-                                 RADEON_MAOS_ENABLE |
-                                 RADEON_VTX_FMT_RADEON_MODE |
-                                 (3 << RADEON_NUM_VERTICES_SHIFT)));
-
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x0);
-
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x0);
-
-                       OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
-                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
-                       OUT_RING(0x0);
-
-                       ADVANCE_RING();
-               }
-       }
-
-       /* Increment the clear counter.  The client-side 3D driver must
-        * wait on this value before performing the clear ioctl.  We
-        * need this because the card's so damned fast...
-        */
-       dev_priv->sarea_priv->last_clear++;
-
-       BEGIN_RING(4);
-
-       RADEON_CLEAR_AGE(dev_priv->sarea_priv->last_clear);
-       RADEON_WAIT_UNTIL_IDLE();
-
-       ADVANCE_RING();
-}
-
-static void radeon_cp_dispatch_swap(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int nbox = sarea_priv->nbox;
-       struct drm_clip_rect *pbox = sarea_priv->boxes;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       /* Do some trivial performance monitoring...
-        */
-       if (dev_priv->do_boxes)
-               radeon_cp_performance_boxes(dev_priv);
-
-       /* Wait for the 3D stream to idle before dispatching the bitblt.
-        * This will prevent data corruption between the two streams.
-        */
-       BEGIN_RING(2);
-
-       RADEON_WAIT_UNTIL_3D_IDLE();
-
-       ADVANCE_RING();
-
-       for (i = 0; i < nbox; i++) {
-               int x = pbox[i].x1;
-               int y = pbox[i].y1;
-               int w = pbox[i].x2 - x;
-               int h = pbox[i].y2 - y;
-
-               DRM_DEBUG("%d,%d-%d,%d\n", x, y, w, h);
-
-               BEGIN_RING(9);
-
-               OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL, 0));
-               OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
-                        RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-                        RADEON_GMC_BRUSH_NONE |
-                        (dev_priv->color_fmt << 8) |
-                        RADEON_GMC_SRC_DATATYPE_COLOR |
-                        RADEON_ROP3_S |
-                        RADEON_DP_SRC_SOURCE_MEMORY |
-                        RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
-
-               /* Make this work even if front & back are flipped:
-                */
-               OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
-               if (dev_priv->sarea_priv->pfCurrentPage == 0) {
-                       OUT_RING(dev_priv->back_pitch_offset);
-                       OUT_RING(dev_priv->front_pitch_offset);
-               } else {
-                       OUT_RING(dev_priv->front_pitch_offset);
-                       OUT_RING(dev_priv->back_pitch_offset);
-               }
-
-               OUT_RING(CP_PACKET0(RADEON_SRC_X_Y, 2));
-               OUT_RING((x << 16) | y);
-               OUT_RING((x << 16) | y);
-               OUT_RING((w << 16) | h);
-
-               ADVANCE_RING();
-       }
-
-       /* Increment the frame counter.  The client-side 3D driver must
-        * throttle the framerate by waiting for this value before
-        * performing the swapbuffer ioctl.
-        */
-       dev_priv->sarea_priv->last_frame++;
-
-       BEGIN_RING(4);
-
-       RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
-       RADEON_WAIT_UNTIL_2D_IDLE();
-
-       ADVANCE_RING();
-}
-
-static void radeon_cp_dispatch_flip(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_sarea *sarea = (struct drm_sarea *) dev_priv->sarea->handle;
-       int offset = (dev_priv->sarea_priv->pfCurrentPage == 1)
-           ? dev_priv->front_offset : dev_priv->back_offset;
-       RING_LOCALS;
-       DRM_DEBUG("pfCurrentPage=%d\n",
-                 dev_priv->sarea_priv->pfCurrentPage);
-
-       /* Do some trivial performance monitoring...
-        */
-       if (dev_priv->do_boxes) {
-               dev_priv->stats.boxes |= RADEON_BOX_FLIP;
-               radeon_cp_performance_boxes(dev_priv);
-       }
-
-       /* Update the frame offsets for both CRTCs
-        */
-       BEGIN_RING(6);
-
-       RADEON_WAIT_UNTIL_3D_IDLE();
-       OUT_RING_REG(RADEON_CRTC_OFFSET,
-                    ((sarea->frame.y * dev_priv->front_pitch +
-                      sarea->frame.x * (dev_priv->color_fmt - 2)) & ~7)
-                    + offset);
-       OUT_RING_REG(RADEON_CRTC2_OFFSET, dev_priv->sarea_priv->crtc2_base
-                    + offset);
-
-       ADVANCE_RING();
-
-       /* Increment the frame counter.  The client-side 3D driver must
-        * throttle the framerate by waiting for this value before
-        * performing the swapbuffer ioctl.
-        */
-       dev_priv->sarea_priv->last_frame++;
-       dev_priv->sarea_priv->pfCurrentPage =
-               1 - dev_priv->sarea_priv->pfCurrentPage;
-
-       BEGIN_RING(2);
-
-       RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
-
-       ADVANCE_RING();
-}
-
-static int bad_prim_vertex_nr(int primitive, int nr)
-{
-       switch (primitive & RADEON_PRIM_TYPE_MASK) {
-       case RADEON_PRIM_TYPE_NONE:
-       case RADEON_PRIM_TYPE_POINT:
-               return nr < 1;
-       case RADEON_PRIM_TYPE_LINE:
-               return (nr & 1) || nr == 0;
-       case RADEON_PRIM_TYPE_LINE_STRIP:
-               return nr < 2;
-       case RADEON_PRIM_TYPE_TRI_LIST:
-       case RADEON_PRIM_TYPE_3VRT_POINT_LIST:
-       case RADEON_PRIM_TYPE_3VRT_LINE_LIST:
-       case RADEON_PRIM_TYPE_RECT_LIST:
-               return nr % 3 || nr == 0;
-       case RADEON_PRIM_TYPE_TRI_FAN:
-       case RADEON_PRIM_TYPE_TRI_STRIP:
-               return nr < 3;
-       default:
-               return 1;
-       }
-}
-
-typedef struct {
-       unsigned int start;
-       unsigned int finish;
-       unsigned int prim;
-       unsigned int numverts;
-       unsigned int offset;
-       unsigned int vc_format;
-} drm_radeon_tcl_prim_t;
-
-static void radeon_cp_dispatch_vertex(struct drm_device * dev,
-                                     struct drm_buf * buf,
-                                     drm_radeon_tcl_prim_t * prim)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int offset = dev_priv->gart_buffers_offset + buf->offset + prim->start;
-       int numverts = (int)prim->numverts;
-       int nbox = sarea_priv->nbox;
-       int i = 0;
-       RING_LOCALS;
-
-       DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
-                 prim->prim,
-                 prim->vc_format, prim->start, prim->finish, prim->numverts);
-
-       if (bad_prim_vertex_nr(prim->prim, prim->numverts)) {
-               DRM_ERROR("bad prim %x numverts %d\n",
-                         prim->prim, prim->numverts);
-               return;
-       }
-
-       do {
-               /* Emit the next cliprect */
-               if (i < nbox) {
-                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
-               }
-
-               /* Emit the vertex buffer rendering commands */
-               BEGIN_RING(5);
-
-               OUT_RING(CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, 3));
-               OUT_RING(offset);
-               OUT_RING(numverts);
-               OUT_RING(prim->vc_format);
-               OUT_RING(prim->prim | RADEON_PRIM_WALK_LIST |
-                        RADEON_COLOR_ORDER_RGBA |
-                        RADEON_VTX_FMT_RADEON_MODE |
-                        (numverts << RADEON_NUM_VERTICES_SHIFT));
-
-               ADVANCE_RING();
-
-               i++;
-       } while (i < nbox);
-}
-
-static void radeon_cp_discard_buffer(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
-       RING_LOCALS;
-
-       buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
-
-       /* Emit the vertex buffer age */
-       BEGIN_RING(2);
-       RADEON_DISPATCH_AGE(buf_priv->age);
-       ADVANCE_RING();
-
-       buf->pending = 1;
-       buf->used = 0;
-}
-
-static void radeon_cp_dispatch_indirect(struct drm_device * dev,
-                                       struct drm_buf * buf, int start, int end)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-       DRM_DEBUG("buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
-
-       if (start != end) {
-               int offset = (dev_priv->gart_buffers_offset
-                             + buf->offset + start);
-               int dwords = (end - start + 3) / sizeof(u32);
-
-               /* Indirect buffer data must be an even number of
-                * dwords, so if we've been given an odd number we must
-                * pad the data with a Type-2 CP packet.
-                */
-               if (dwords & 1) {
-                       u32 *data = (u32 *)
-                           ((char *)dev->agp_buffer_map->handle
-                            + buf->offset + start);
-                       data[dwords++] = RADEON_CP_PACKET2;
-               }
-
-               /* Fire off the indirect buffer */
-               BEGIN_RING(3);
-
-               OUT_RING(CP_PACKET0(RADEON_CP_IB_BASE, 1));
-               OUT_RING(offset);
-               OUT_RING(dwords);
-
-               ADVANCE_RING();
-       }
-}
-
-static void radeon_cp_dispatch_indices(struct drm_device * dev,
-                                      struct drm_buf * elt_buf,
-                                      drm_radeon_tcl_prim_t * prim)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       int offset = dev_priv->gart_buffers_offset + prim->offset;
-       u32 *data;
-       int dwords;
-       int i = 0;
-       int start = prim->start + RADEON_INDEX_PRIM_OFFSET;
-       int count = (prim->finish - start) / sizeof(u16);
-       int nbox = sarea_priv->nbox;
-
-       DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
-                 prim->prim,
-                 prim->vc_format,
-                 prim->start, prim->finish, prim->offset, prim->numverts);
-
-       if (bad_prim_vertex_nr(prim->prim, count)) {
-               DRM_ERROR("bad prim %x count %d\n", prim->prim, count);
-               return;
-       }
-
-       if (start >= prim->finish || (prim->start & 0x7)) {
-               DRM_ERROR("buffer prim %d\n", prim->prim);
-               return;
-       }
-
-       dwords = (prim->finish - prim->start + 3) / sizeof(u32);
-
-       data = (u32 *) ((char *)dev->agp_buffer_map->handle +
-                       elt_buf->offset + prim->start);
-
-       data[0] = CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, dwords - 2);
-       data[1] = offset;
-       data[2] = prim->numverts;
-       data[3] = prim->vc_format;
-       data[4] = (prim->prim |
-                  RADEON_PRIM_WALK_IND |
-                  RADEON_COLOR_ORDER_RGBA |
-                  RADEON_VTX_FMT_RADEON_MODE |
-                  (count << RADEON_NUM_VERTICES_SHIFT));
-
-       do {
-               if (i < nbox)
-                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
-
-               radeon_cp_dispatch_indirect(dev, elt_buf,
-                                           prim->start, prim->finish);
-
-               i++;
-       } while (i < nbox);
-
-}
-
-#define RADEON_MAX_TEXTURE_SIZE RADEON_BUFFER_SIZE
-
-static int radeon_cp_dispatch_texture(struct drm_device * dev,
-                                     struct drm_file *file_priv,
-                                     drm_radeon_texture_t * tex,
-                                     drm_radeon_tex_image_t * image)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_buf *buf;
-       u32 format;
-       u32 *buffer;
-       const u8 __user *data;
-       int size, dwords, tex_width, blit_width, spitch;
-       u32 height;
-       int i;
-       u32 texpitch, microtile;
-       u32 offset, byte_offset;
-       RING_LOCALS;
-
-       if (radeon_check_and_fixup_offset(dev_priv, file_priv, &tex->offset)) {
-               DRM_ERROR("Invalid destination offset\n");
-               return -EINVAL;
-       }
-
-       dev_priv->stats.boxes |= RADEON_BOX_TEXTURE_LOAD;
-
-       /* Flush the pixel cache.  This ensures no pixel data gets mixed
-        * up with the texture data from the host data blit, otherwise
-        * part of the texture image may be corrupted.
-        */
-       BEGIN_RING(4);
-       RADEON_FLUSH_CACHE();
-       RADEON_WAIT_UNTIL_IDLE();
-       ADVANCE_RING();
-
-       /* The compiler won't optimize away a division by a variable,
-        * even if the only legal values are powers of two.  Thus, we'll
-        * use a shift instead.
-        */
-       switch (tex->format) {
-       case RADEON_TXFORMAT_ARGB8888:
-       case RADEON_TXFORMAT_RGBA8888:
-               format = RADEON_COLOR_FORMAT_ARGB8888;
-               tex_width = tex->width * 4;
-               blit_width = image->width * 4;
-               break;
-       case RADEON_TXFORMAT_AI88:
-       case RADEON_TXFORMAT_ARGB1555:
-       case RADEON_TXFORMAT_RGB565:
-       case RADEON_TXFORMAT_ARGB4444:
-       case RADEON_TXFORMAT_VYUY422:
-       case RADEON_TXFORMAT_YVYU422:
-               format = RADEON_COLOR_FORMAT_RGB565;
-               tex_width = tex->width * 2;
-               blit_width = image->width * 2;
-               break;
-       case RADEON_TXFORMAT_I8:
-       case RADEON_TXFORMAT_RGB332:
-               format = RADEON_COLOR_FORMAT_CI8;
-               tex_width = tex->width * 1;
-               blit_width = image->width * 1;
-               break;
-       default:
-               DRM_ERROR("invalid texture format %d\n", tex->format);
-               return -EINVAL;
-       }
-       spitch = blit_width >> 6;
-       if (spitch == 0 && image->height > 1)
-               return -EINVAL;
-
-       texpitch = tex->pitch;
-       if ((texpitch << 22) & RADEON_DST_TILE_MICRO) {
-               microtile = 1;
-               if (tex_width < 64) {
-                       texpitch &= ~(RADEON_DST_TILE_MICRO >> 22);
-                       /* we got tiled coordinates, untile them */
-                       image->x *= 2;
-               }
-       } else
-               microtile = 0;
-
-       /* this might fail for zero-sized uploads - are those illegal? */
-       if (!radeon_check_offset(dev_priv, tex->offset + image->height *
-                               blit_width - 1)) {
-               DRM_ERROR("Invalid final destination offset\n");
-               return -EINVAL;
-       }
-
-       DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width, tex->height, blit_width);
-
-       do {
-               DRM_DEBUG("tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
-                         tex->offset >> 10, tex->pitch, tex->format,
-                         image->x, image->y, image->width, image->height);
-
-               /* Make a copy of some parameters in case we have to
-                * update them for a multi-pass texture blit.
-                */
-               height = image->height;
-               data = (const u8 __user *)image->data;
-
-               size = height * blit_width;
-
-               if (size > RADEON_MAX_TEXTURE_SIZE) {
-                       height = RADEON_MAX_TEXTURE_SIZE / blit_width;
-                       size = height * blit_width;
-               } else if (size < 4 && size > 0) {
-                       size = 4;
-               } else if (size == 0) {
-                       return 0;
-               }
-
-               buf = radeon_freelist_get(dev);
-               if (0 && !buf) {
-                       radeon_do_cp_idle(dev_priv);
-                       buf = radeon_freelist_get(dev);
-               }
-               if (!buf) {
-                       DRM_DEBUG("EAGAIN\n");
-                       if (DRM_COPY_TO_USER(tex->image, image, sizeof(*image)))
-                               return -EFAULT;
-                       return -EAGAIN;
-               }
-
-               /* Dispatch the indirect buffer.
-                */
-               buffer =
-                   (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);
-               dwords = size / 4;
-
-#define RADEON_COPY_MT(_buf, _data, _width) \
-       do { \
-               if (DRM_COPY_FROM_USER(_buf, _data, (_width))) {\
-                       DRM_ERROR("EFAULT on pad, %d bytes\n", (_width)); \
-                       return -EFAULT; \
-               } \
-       } while(0)
-
-               if (microtile) {
-                       /* texture micro tiling in use, minimum texture width is thus 16 bytes.
-                          however, we cannot use blitter directly for texture width < 64 bytes,
-                          since minimum tex pitch is 64 bytes and we need this to match
-                          the texture width, otherwise the blitter will tile it wrong.
-                          Thus, tiling manually in this case. Additionally, need to special
-                          case tex height = 1, since our actual image will have height 2
-                          and we need to ensure we don't read beyond the texture size
-                          from user space. */
-                       if (tex->height == 1) {
-                               if (tex_width >= 64 || tex_width <= 16) {
-                                       RADEON_COPY_MT(buffer, data,
-                                               (int)(tex_width * sizeof(u32)));
-                               } else if (tex_width == 32) {
-                                       RADEON_COPY_MT(buffer, data, 16);
-                                       RADEON_COPY_MT(buffer + 8,
-                                                      data + 16, 16);
-                               }
-                       } else if (tex_width >= 64 || tex_width == 16) {
-                               RADEON_COPY_MT(buffer, data,
-                                              (int)(dwords * sizeof(u32)));
-                       } else if (tex_width < 16) {
-                               for (i = 0; i < tex->height; i++) {
-                                       RADEON_COPY_MT(buffer, data, tex_width);
-                                       buffer += 4;
-                                       data += tex_width;
-                               }
-                       } else if (tex_width == 32) {
-                               /* TODO: make sure this works when not fitting in one buffer
-                                  (i.e. 32bytes x 2048...) */
-                               for (i = 0; i < tex->height; i += 2) {
-                                       RADEON_COPY_MT(buffer, data, 16);
-                                       data += 16;
-                                       RADEON_COPY_MT(buffer + 8, data, 16);
-                                       data += 16;
-                                       RADEON_COPY_MT(buffer + 4, data, 16);
-                                       data += 16;
-                                       RADEON_COPY_MT(buffer + 12, data, 16);
-                                       data += 16;
-                                       buffer += 16;
-                               }
-                       }
-               } else {
-                       if (tex_width >= 32) {
-                               /* Texture image width is larger than the minimum, so we
-                                * can upload it directly.
-                                */
-                               RADEON_COPY_MT(buffer, data,
-                                              (int)(dwords * sizeof(u32)));
-                       } else {
-                               /* Texture image width is less than the minimum, so we
-                                * need to pad out each image scanline to the minimum
-                                * width.
-                                */
-                               for (i = 0; i < tex->height; i++) {
-                                       RADEON_COPY_MT(buffer, data, tex_width);
-                                       buffer += 8;
-                                       data += tex_width;
-                               }
-                       }
-               }
-
-#undef RADEON_COPY_MT
-               byte_offset = (image->y & ~2047) * blit_width;
-               buf->file_priv = file_priv;
-               buf->used = size;
-               offset = dev_priv->gart_buffers_offset + buf->offset;
-               BEGIN_RING(9);
-               OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI, 5));
-               OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
-                        RADEON_GMC_DST_PITCH_OFFSET_CNTL |
-                        RADEON_GMC_BRUSH_NONE |
-                        (format << 8) |
-                        RADEON_GMC_SRC_DATATYPE_COLOR |
-                        RADEON_ROP3_S |
-                        RADEON_DP_SRC_SOURCE_MEMORY |
-                        RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
-               OUT_RING((spitch << 22) | (offset >> 10));
-               OUT_RING((texpitch << 22) | ((tex->offset >> 10) + (byte_offset >> 10)));
-               OUT_RING(0);
-               OUT_RING((image->x << 16) | (image->y % 2048));
-               OUT_RING((image->width << 16) | height);
-               RADEON_WAIT_UNTIL_2D_IDLE();
-               ADVANCE_RING();
-               COMMIT_RING();
-
-               radeon_cp_discard_buffer(dev, buf);
-
-               /* Update the input parameters for next time */
-               image->y += height;
-               image->height -= height;
-               image->data = (const u8 __user *)image->data + size;
-       } while (image->height > 0);
-
-       /* Flush the pixel cache after the blit completes.  This ensures
-        * the texture data is written out to memory before rendering
-        * continues.
-        */
-       BEGIN_RING(4);
-       RADEON_FLUSH_CACHE();
-       RADEON_WAIT_UNTIL_2D_IDLE();
-       ADVANCE_RING();
-       COMMIT_RING();
-
-       return 0;
-}
-
-static void radeon_cp_dispatch_stipple(struct drm_device * dev, u32 * stipple)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       int i;
-       RING_LOCALS;
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(35);
-
-       OUT_RING(CP_PACKET0(RADEON_RE_STIPPLE_ADDR, 0));
-       OUT_RING(0x00000000);
-
-       OUT_RING(CP_PACKET0_TABLE(RADEON_RE_STIPPLE_DATA, 31));
-       for (i = 0; i < 32; i++) {
-               OUT_RING(stipple[i]);
-       }
-
-       ADVANCE_RING();
-}
-
-static void radeon_apply_surface_regs(int surf_index,
-                                     drm_radeon_private_t *dev_priv)
-{
-       if (!dev_priv->mmio)
-               return;
-
-       radeon_do_cp_idle(dev_priv);
-
-       RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * surf_index,
-                    dev_priv->surfaces[surf_index].flags);
-       RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + 16 * surf_index,
-                    dev_priv->surfaces[surf_index].lower);
-       RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + 16 * surf_index,
-                    dev_priv->surfaces[surf_index].upper);
-}
-
-/* Allocates a virtual surface
- * doesn't always allocate a real surface, will stretch an existing
- * surface when possible.
- *
- * Note that refcount can be at most 2, since during a free refcount=3
- * might mean we have to allocate a new surface which might not always
- * be available.
- * For example : we allocate three contigous surfaces ABC. If B is
- * freed, we suddenly need two surfaces to store A and C, which might
- * not always be available.
- */
-static int alloc_surface(drm_radeon_surface_alloc_t *new,
-                        drm_radeon_private_t *dev_priv,
-                        struct drm_file *file_priv)
-{
-       struct radeon_virt_surface *s;
-       int i;
-       int virt_surface_index;
-       uint32_t new_upper, new_lower;
-
-       new_lower = new->address;
-       new_upper = new_lower + new->size - 1;
-
-       /* sanity check */
-       if ((new_lower >= new_upper) || (new->flags == 0) || (new->size == 0) ||
-           ((new_upper & RADEON_SURF_ADDRESS_FIXED_MASK) !=
-            RADEON_SURF_ADDRESS_FIXED_MASK)
-           || ((new_lower & RADEON_SURF_ADDRESS_FIXED_MASK) != 0))
-               return -1;
-
-       /* make sure there is no overlap with existing surfaces */
-       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
-               if ((dev_priv->surfaces[i].refcount != 0) &&
-                   (((new_lower >= dev_priv->surfaces[i].lower) &&
-                     (new_lower < dev_priv->surfaces[i].upper)) ||
-                    ((new_lower < dev_priv->surfaces[i].lower) &&
-                     (new_upper > dev_priv->surfaces[i].lower)))) {
-                       return -1;
-               }
-       }
-
-       /* find a virtual surface */
-       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++)
-               if (dev_priv->virt_surfaces[i].file_priv == 0)
-                       break;
-       if (i == 2 * RADEON_MAX_SURFACES) {
-               return -1;
-       }
-       virt_surface_index = i;
-
-       /* try to reuse an existing surface */
-       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
-               /* extend before */
-               if ((dev_priv->surfaces[i].refcount == 1) &&
-                   (new->flags == dev_priv->surfaces[i].flags) &&
-                   (new_upper + 1 == dev_priv->surfaces[i].lower)) {
-                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
-                       s->surface_index = i;
-                       s->lower = new_lower;
-                       s->upper = new_upper;
-                       s->flags = new->flags;
-                       s->file_priv = file_priv;
-                       dev_priv->surfaces[i].refcount++;
-                       dev_priv->surfaces[i].lower = s->lower;
-                       radeon_apply_surface_regs(s->surface_index, dev_priv);
-                       return virt_surface_index;
-               }
-
-               /* extend after */
-               if ((dev_priv->surfaces[i].refcount == 1) &&
-                   (new->flags == dev_priv->surfaces[i].flags) &&
-                   (new_lower == dev_priv->surfaces[i].upper + 1)) {
-                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
-                       s->surface_index = i;
-                       s->lower = new_lower;
-                       s->upper = new_upper;
-                       s->flags = new->flags;
-                       s->file_priv = file_priv;
-                       dev_priv->surfaces[i].refcount++;
-                       dev_priv->surfaces[i].upper = s->upper;
-                       radeon_apply_surface_regs(s->surface_index, dev_priv);
-                       return virt_surface_index;
-               }
-       }
-
-       /* okay, we need a new one */
-       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
-               if (dev_priv->surfaces[i].refcount == 0) {
-                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
-                       s->surface_index = i;
-                       s->lower = new_lower;
-                       s->upper = new_upper;
-                       s->flags = new->flags;
-                       s->file_priv = file_priv;
-                       dev_priv->surfaces[i].refcount = 1;
-                       dev_priv->surfaces[i].lower = s->lower;
-                       dev_priv->surfaces[i].upper = s->upper;
-                       dev_priv->surfaces[i].flags = s->flags;
-                       radeon_apply_surface_regs(s->surface_index, dev_priv);
-                       return virt_surface_index;
-               }
-       }
-
-       /* we didn't find anything */
-       return -1;
-}
-
-static int free_surface(struct drm_file *file_priv,
-                       drm_radeon_private_t * dev_priv,
-                       int lower)
-{
-       struct radeon_virt_surface *s;
-       int i;
-       /* find the virtual surface */
-       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
-               s = &(dev_priv->virt_surfaces[i]);
-               if (s->file_priv) {
-                       if ((lower == s->lower) && (file_priv == s->file_priv))
-                       {
-                               if (dev_priv->surfaces[s->surface_index].
-                                   lower == s->lower)
-                                       dev_priv->surfaces[s->surface_index].
-                                           lower = s->upper;
-
-                               if (dev_priv->surfaces[s->surface_index].
-                                   upper == s->upper)
-                                       dev_priv->surfaces[s->surface_index].
-                                           upper = s->lower;
-
-                               dev_priv->surfaces[s->surface_index].refcount--;
-                               if (dev_priv->surfaces[s->surface_index].
-                                   refcount == 0)
-                                       dev_priv->surfaces[s->surface_index].
-                                           flags = 0;
-                               s->file_priv = NULL;
-                               radeon_apply_surface_regs(s->surface_index,
-                                                         dev_priv);
-                               return 0;
-                       }
-               }
-       }
-       return 1;
-}
-
-static void radeon_surfaces_release(struct drm_file *file_priv,
-                                   drm_radeon_private_t * dev_priv)
-{
-       int i;
-       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
-               if (dev_priv->virt_surfaces[i].file_priv == file_priv)
-                       free_surface(file_priv, dev_priv,
-                                    dev_priv->virt_surfaces[i].lower);
-       }
-}
-
-/* ================================================================
- * IOCTL functions
- */
-static int radeon_surface_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_surface_alloc_t *alloc = data;
-
-       if (alloc_surface(alloc, dev_priv, file_priv) == -1)
-               return -EINVAL;
-       else
-               return 0;
-}
-
-static int radeon_surface_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_surface_free_t *memfree = data;
-
-       if (free_surface(file_priv, dev_priv, memfree->address))
-               return -EINVAL;
-       else
-               return 0;
-}
-
-static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       drm_radeon_clear_t *clear = data;
-       drm_radeon_clear_rect_t depth_boxes[RADEON_NR_SAREA_CLIPRECTS];
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
-
-       if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
-                              sarea_priv->nbox * sizeof(depth_boxes[0])))
-               return -EFAULT;
-
-       radeon_cp_dispatch_clear(dev, clear, depth_boxes);
-
-       COMMIT_RING();
-       return 0;
-}
-
-/* Not sure why this isn't set all the time:
- */
-static int radeon_do_init_pageflip(struct drm_device * dev)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       DRM_DEBUG("\n");
-
-       BEGIN_RING(6);
-       RADEON_WAIT_UNTIL_3D_IDLE();
-       OUT_RING(CP_PACKET0(RADEON_CRTC_OFFSET_CNTL, 0));
-       OUT_RING(RADEON_READ(RADEON_CRTC_OFFSET_CNTL) |
-                RADEON_CRTC_OFFSET_FLIP_CNTL);
-       OUT_RING(CP_PACKET0(RADEON_CRTC2_OFFSET_CNTL, 0));
-       OUT_RING(RADEON_READ(RADEON_CRTC2_OFFSET_CNTL) |
-                RADEON_CRTC_OFFSET_FLIP_CNTL);
-       ADVANCE_RING();
-
-       dev_priv->page_flipping = 1;
-
-       if (dev_priv->sarea_priv->pfCurrentPage != 1)
-               dev_priv->sarea_priv->pfCurrentPage = 0;
-
-       return 0;
-}
-
-/* Swapping and flipping are different operations, need different ioctls.
- * They can & should be intermixed to support multiple 3d windows.
- */
-static int radeon_cp_flip(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (!dev_priv->page_flipping)
-               radeon_do_init_pageflip(dev);
-
-       radeon_cp_dispatch_flip(dev);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
-               sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
-
-       radeon_cp_dispatch_swap(dev);
-       dev_priv->sarea_priv->ctx_owner = 0;
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_radeon_vertex_t *vertex = data;
-       drm_radeon_tcl_prim_t prim;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
-                 DRM_CURRENTPID, vertex->idx, vertex->count, vertex->discard);
-
-       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         vertex->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-       if (vertex->prim < 0 || vertex->prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
-               DRM_ERROR("buffer prim %d\n", vertex->prim);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf = dma->buflist[vertex->idx];
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
-               return -EINVAL;
-       }
-
-       /* Build up a prim_t record:
-        */
-       if (vertex->count) {
-               buf->used = vertex->count;      /* not used? */
-
-               if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
-                       if (radeon_emit_state(dev_priv, file_priv,
-                                             &sarea_priv->context_state,
-                                             sarea_priv->tex_state,
-                                             sarea_priv->dirty)) {
-                               DRM_ERROR("radeon_emit_state failed\n");
-                               return -EINVAL;
-                       }
-
-                       sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
-                                              RADEON_UPLOAD_TEX1IMAGES |
-                                              RADEON_UPLOAD_TEX2IMAGES |
-                                              RADEON_REQUIRE_QUIESCENCE);
-               }
-
-               prim.start = 0;
-               prim.finish = vertex->count;    /* unused */
-               prim.prim = vertex->prim;
-               prim.numverts = vertex->count;
-               prim.vc_format = dev_priv->sarea_priv->vc_format;
-
-               radeon_cp_dispatch_vertex(dev, buf, &prim);
-       }
-
-       if (vertex->discard) {
-               radeon_cp_discard_buffer(dev, buf);
-       }
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_radeon_indices_t *elts = data;
-       drm_radeon_tcl_prim_t prim;
-       int count;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("pid=%d index=%d start=%d end=%d discard=%d\n",
-                 DRM_CURRENTPID, elts->idx, elts->start, elts->end,
-                 elts->discard);
-
-       if (elts->idx < 0 || elts->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         elts->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-       if (elts->prim < 0 || elts->prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
-               DRM_ERROR("buffer prim %d\n", elts->prim);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf = dma->buflist[elts->idx];
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", elts->idx);
-               return -EINVAL;
-       }
-
-       count = (elts->end - elts->start) / sizeof(u16);
-       elts->start -= RADEON_INDEX_PRIM_OFFSET;
-
-       if (elts->start & 0x7) {
-               DRM_ERROR("misaligned buffer 0x%x\n", elts->start);
-               return -EINVAL;
-       }
-       if (elts->start < buf->used) {
-               DRM_ERROR("no header 0x%x - 0x%x\n", elts->start, buf->used);
-               return -EINVAL;
-       }
-
-       buf->used = elts->end;
-
-       if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
-               if (radeon_emit_state(dev_priv, file_priv,
-                                     &sarea_priv->context_state,
-                                     sarea_priv->tex_state,
-                                     sarea_priv->dirty)) {
-                       DRM_ERROR("radeon_emit_state failed\n");
-                       return -EINVAL;
-               }
-
-               sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
-                                      RADEON_UPLOAD_TEX1IMAGES |
-                                      RADEON_UPLOAD_TEX2IMAGES |
-                                      RADEON_REQUIRE_QUIESCENCE);
-       }
-
-       /* Build up a prim_t record:
-        */
-       prim.start = elts->start;
-       prim.finish = elts->end;
-       prim.prim = elts->prim;
-       prim.offset = 0;        /* offset from start of dma buffers */
-       prim.numverts = RADEON_MAX_VB_VERTS;    /* duh */
-       prim.vc_format = dev_priv->sarea_priv->vc_format;
-
-       radeon_cp_dispatch_indices(dev, buf, &prim);
-       if (elts->discard) {
-               radeon_cp_discard_buffer(dev, buf);
-       }
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_texture(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_texture_t *tex = data;
-       drm_radeon_tex_image_t image;
-       int ret;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (tex->image == NULL) {
-               DRM_ERROR("null texture image!\n");
-               return -EINVAL;
-       }
-
-       if (DRM_COPY_FROM_USER(&image,
-                              (drm_radeon_tex_image_t __user *) tex->image,
-                              sizeof(image)))
-               return -EFAULT;
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       ret = radeon_cp_dispatch_texture(dev, file_priv, tex, &image);
-
-       return ret;
-}
-
-static int radeon_cp_stipple(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_stipple_t *stipple = data;
-       u32 mask[32];
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (DRM_COPY_FROM_USER(&mask, stipple->mask, 32 * sizeof(u32)))
-               return -EFAULT;
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-
-       radeon_cp_dispatch_stipple(dev, mask);
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_indirect(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_radeon_indirect_t *indirect = data;
-       RING_LOCALS;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
-                 indirect->idx, indirect->start, indirect->end,
-                 indirect->discard);
-
-       if (indirect->idx < 0 || indirect->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         indirect->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-
-       buf = dma->buflist[indirect->idx];
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", indirect->idx);
-               return -EINVAL;
-       }
-
-       if (indirect->start < buf->used) {
-               DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
-                         indirect->start, buf->used);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf->used = indirect->end;
-
-       /* Wait for the 3D stream to idle before the indirect buffer
-        * containing 2D acceleration commands is processed.
-        */
-       BEGIN_RING(2);
-
-       RADEON_WAIT_UNTIL_3D_IDLE();
-
-       ADVANCE_RING();
-
-       /* Dispatch the indirect buffer full of commands from the
-        * X server.  This is insecure and is thus only available to
-        * privileged clients.
-        */
-       radeon_cp_dispatch_indirect(dev, buf, indirect->start, indirect->end);
-       if (indirect->discard) {
-               radeon_cp_discard_buffer(dev, buf);
-       }
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_cp_vertex2(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_radeon_vertex2_t *vertex = data;
-       int i;
-       unsigned char laststate;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("pid=%d index=%d discard=%d\n",
-                 DRM_CURRENTPID, vertex->idx, vertex->discard);
-
-       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
-               DRM_ERROR("buffer index %d (of %d max)\n",
-                         vertex->idx, dma->buf_count - 1);
-               return -EINVAL;
-       }
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       buf = dma->buflist[vertex->idx];
-
-       if (buf->file_priv != file_priv) {
-               DRM_ERROR("process %d using buffer owned by %p\n",
-                         DRM_CURRENTPID, buf->file_priv);
-               return -EINVAL;
-       }
-
-       if (buf->pending) {
-               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
-               return -EINVAL;
-       }
-
-       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
-               return -EINVAL;
-
-       for (laststate = 0xff, i = 0; i < vertex->nr_prims; i++) {
-               drm_radeon_prim_t prim;
-               drm_radeon_tcl_prim_t tclprim;
-
-               if (DRM_COPY_FROM_USER(&prim, &vertex->prim[i], sizeof(prim)))
-                       return -EFAULT;
-
-               if (prim.stateidx != laststate) {
-                       drm_radeon_state_t state;
-
-                       if (DRM_COPY_FROM_USER(&state,
-                                              &vertex->state[prim.stateidx],
-                                              sizeof(state)))
-                               return -EFAULT;
-
-                       if (radeon_emit_state2(dev_priv, file_priv, &state)) {
-                               DRM_ERROR("radeon_emit_state2 failed\n");
-                               return -EINVAL;
-                       }
-
-                       laststate = prim.stateidx;
-               }
-
-               tclprim.start = prim.start;
-               tclprim.finish = prim.finish;
-               tclprim.prim = prim.prim;
-               tclprim.vc_format = prim.vc_format;
-
-               if (prim.prim & RADEON_PRIM_WALK_IND) {
-                       tclprim.offset = prim.numverts * 64;
-                       tclprim.numverts = RADEON_MAX_VB_VERTS; /* duh */
-
-                       radeon_cp_dispatch_indices(dev, buf, &tclprim);
-               } else {
-                       tclprim.numverts = prim.numverts;
-                       tclprim.offset = 0;     /* not used */
-
-                       radeon_cp_dispatch_vertex(dev, buf, &tclprim);
-               }
-
-               if (sarea_priv->nbox == 1)
-                       sarea_priv->nbox = 0;
-       }
-
-       if (vertex->discard) {
-               radeon_cp_discard_buffer(dev, buf);
-       }
-
-       COMMIT_RING();
-       return 0;
-}
-
-static int radeon_emit_packets(drm_radeon_private_t * dev_priv,
-                              struct drm_file *file_priv,
-                              drm_radeon_cmd_header_t header,
-                              drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       int id = (int)header.packet.packet_id;
-       int sz, reg;
-       int *data = (int *)cmdbuf->buf;
-       RING_LOCALS;
-
-       if (id >= RADEON_MAX_STATE_PACKETS)
-               return -EINVAL;
-
-       sz = packet[id].len;
-       reg = packet[id].start;
-
-       if (sz * sizeof(int) > cmdbuf->bufsz) {
-               DRM_ERROR("Packet size provided larger than data provided\n");
-               return -EINVAL;
-       }
-
-       if (radeon_check_and_fixup_packets(dev_priv, file_priv, id, data)) {
-               DRM_ERROR("Packet verification failed\n");
-               return -EINVAL;
-       }
-
-       BEGIN_RING(sz + 1);
-       OUT_RING(CP_PACKET0(reg, (sz - 1)));
-       OUT_RING_TABLE(data, sz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * sizeof(int);
-       cmdbuf->bufsz -= sz * sizeof(int);
-       return 0;
-}
-
-static __inline__ int radeon_emit_scalars(drm_radeon_private_t *dev_priv,
-                                         drm_radeon_cmd_header_t header,
-                                         drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       int sz = header.scalars.count;
-       int start = header.scalars.offset;
-       int stride = header.scalars.stride;
-       RING_LOCALS;
-
-       BEGIN_RING(3 + sz);
-       OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
-       OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
-       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
-       OUT_RING_TABLE(cmdbuf->buf, sz);
-       ADVANCE_RING();
-       cmdbuf->buf += sz * sizeof(int);
-       cmdbuf->bufsz -= sz * sizeof(int);
-       return 0;
-}
-
-/* God this is ugly
- */
-static __inline__ int radeon_emit_scalars2(drm_radeon_private_t *dev_priv,
-                                          drm_radeon_cmd_header_t header,
-                                          drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       int sz = header.scalars.count;
-       int start = ((unsigned int)header.scalars.offset) + 0x100;
-       int stride = header.scalars.stride;
-       RING_LOCALS;
-
-       BEGIN_RING(3 + sz);
-       OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
-       OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
-       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
-       OUT_RING_TABLE(cmdbuf->buf, sz);
-       ADVANCE_RING();
-       cmdbuf->buf += sz * sizeof(int);
-       cmdbuf->bufsz -= sz * sizeof(int);
-       return 0;
-}
-
-static __inline__ int radeon_emit_vectors(drm_radeon_private_t *dev_priv,
-                                         drm_radeon_cmd_header_t header,
-                                         drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       int sz = header.vectors.count;
-       int start = header.vectors.offset;
-       int stride = header.vectors.stride;
-       RING_LOCALS;
-
-       BEGIN_RING(5 + sz);
-       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
-       OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
-       OUT_RING(start | (stride << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
-       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
-       OUT_RING_TABLE(cmdbuf->buf, sz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * sizeof(int);
-       cmdbuf->bufsz -= sz * sizeof(int);
-       return 0;
-}
-
-static __inline__ int radeon_emit_veclinear(drm_radeon_private_t *dev_priv,
-                                         drm_radeon_cmd_header_t header,
-                                         drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       int sz = header.veclinear.count * 4;
-       int start = header.veclinear.addr_lo | (header.veclinear.addr_hi << 8);
-       RING_LOCALS;
-
-        if (!sz)
-                return 0;
-        if (sz * 4 > cmdbuf->bufsz)
-                return -EINVAL;
-
-       BEGIN_RING(5 + sz);
-       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
-       OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
-       OUT_RING(start | (1 << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
-       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
-       OUT_RING_TABLE(cmdbuf->buf, sz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += sz * sizeof(int);
-       cmdbuf->bufsz -= sz * sizeof(int);
-       return 0;
-}
-
-static int radeon_emit_packet3(struct drm_device * dev,
-                              struct drm_file *file_priv,
-                              drm_radeon_kcmd_buffer_t *cmdbuf)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       unsigned int cmdsz;
-       int ret;
-       RING_LOCALS;
-
-       DRM_DEBUG("\n");
-
-       if ((ret = radeon_check_and_fixup_packet3(dev_priv, file_priv,
-                                                 cmdbuf, &cmdsz))) {
-               DRM_ERROR("Packet verification failed\n");
-               return ret;
-       }
-
-       BEGIN_RING(cmdsz);
-       OUT_RING_TABLE(cmdbuf->buf, cmdsz);
-       ADVANCE_RING();
-
-       cmdbuf->buf += cmdsz * 4;
-       cmdbuf->bufsz -= cmdsz * 4;
-       return 0;
-}
-
-static int radeon_emit_packet3_cliprect(struct drm_device *dev,
-                                       struct drm_file *file_priv,
-                                       drm_radeon_kcmd_buffer_t *cmdbuf,
-                                       int orig_nbox)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_clip_rect box;
-       unsigned int cmdsz;
-       int ret;
-       struct drm_clip_rect __user *boxes = cmdbuf->boxes;
-       int i = 0;
-       RING_LOCALS;
-
-       DRM_DEBUG("\n");
-
-       if ((ret = radeon_check_and_fixup_packet3(dev_priv, file_priv,
-                                                 cmdbuf, &cmdsz))) {
-               DRM_ERROR("Packet verification failed\n");
-               return ret;
-       }
-
-       if (!orig_nbox)
-               goto out;
-
-       do {
-               if (i < cmdbuf->nbox) {
-                       if (DRM_COPY_FROM_USER(&box, &boxes[i], sizeof(box)))
-                               return -EFAULT;
-                       /* FIXME The second and subsequent times round
-                        * this loop, send a WAIT_UNTIL_3D_IDLE before
-                        * calling emit_clip_rect(). This fixes a
-                        * lockup on fast machines when sending
-                        * several cliprects with a cmdbuf, as when
-                        * waving a 2D window over a 3D
-                        * window. Something in the commands from user
-                        * space seems to hang the card when they're
-                        * sent several times in a row. That would be
-                        * the correct place to fix it but this works
-                        * around it until I can figure that out - Tim
-                        * Smith */
-                       if (i) {
-                               BEGIN_RING(2);
-                               RADEON_WAIT_UNTIL_3D_IDLE();
-                               ADVANCE_RING();
-                       }
-                       radeon_emit_clip_rect(dev_priv, &box);
-               }
-
-               BEGIN_RING(cmdsz);
-               OUT_RING_TABLE(cmdbuf->buf, cmdsz);
-               ADVANCE_RING();
-
-       } while (++i < cmdbuf->nbox);
-       if (cmdbuf->nbox == 1)
-               cmdbuf->nbox = 0;
-
-      out:
-       cmdbuf->buf += cmdsz * 4;
-       cmdbuf->bufsz -= cmdsz * 4;
-       return 0;
-}
-
-static int radeon_emit_wait(struct drm_device * dev, int flags)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       RING_LOCALS;
-
-       DRM_DEBUG("%x\n", flags);
-       switch (flags) {
-       case RADEON_WAIT_2D:
-               BEGIN_RING(2);
-               RADEON_WAIT_UNTIL_2D_IDLE();
-               ADVANCE_RING();
-               break;
-       case RADEON_WAIT_3D:
-               BEGIN_RING(2);
-               RADEON_WAIT_UNTIL_3D_IDLE();
-               ADVANCE_RING();
-               break;
-       case RADEON_WAIT_2D | RADEON_WAIT_3D:
-               BEGIN_RING(2);
-               RADEON_WAIT_UNTIL_IDLE();
-               ADVANCE_RING();
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int radeon_cp_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf = NULL;
-       int idx;
-       drm_radeon_kcmd_buffer_t *cmdbuf = data;
-       drm_radeon_cmd_header_t header;
-       int orig_nbox, orig_bufsz;
-       char *kbuf = NULL;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       RING_SPACE_TEST_WITH_RETURN(dev_priv);
-       VB_AGE_TEST_WITH_RETURN(dev_priv);
-
-       if (cmdbuf->bufsz > 64 * 1024 || cmdbuf->bufsz < 0) {
-               return -EINVAL;
-       }
-
-       /* Allocate an in-kernel area and copy in the cmdbuf.  Do this to avoid
-        * races between checking values and using those values in other code,
-        * and simply to avoid a lot of function calls to copy in data.
-        */
-       orig_bufsz = cmdbuf->bufsz;
-       if (orig_bufsz != 0) {
-               kbuf = drm_alloc(cmdbuf->bufsz, DRM_MEM_DRIVER);
-               if (kbuf == NULL)
-                       return -ENOMEM;
-               if (DRM_COPY_FROM_USER(kbuf, (void __user *)cmdbuf->buf,
-                                      cmdbuf->bufsz)) {
-                       drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
-                       return -EFAULT;
-               }
-               cmdbuf->buf = kbuf;
-       }
-
-       orig_nbox = cmdbuf->nbox;
-
-       if (dev_priv->microcode_version == UCODE_R300) {
-               int temp;
-               temp = r300_do_cp_cmdbuf(dev, file_priv, cmdbuf);
-
-               if (orig_bufsz != 0)
-                       drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
-
-               return temp;
-       }
-
-       /* microcode_version != r300 */
-       while (cmdbuf->bufsz >= sizeof(header)) {
-
-               header.i = *(int *)cmdbuf->buf;
-               cmdbuf->buf += sizeof(header);
-               cmdbuf->bufsz -= sizeof(header);
-
-               switch (header.header.cmd_type) {
-               case RADEON_CMD_PACKET:
-                       DRM_DEBUG("RADEON_CMD_PACKET\n");
-                       if (radeon_emit_packets
-                           (dev_priv, file_priv, header, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_packets failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_SCALARS:
-                       DRM_DEBUG("RADEON_CMD_SCALARS\n");
-                       if (radeon_emit_scalars(dev_priv, header, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_scalars failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_VECTORS:
-                       DRM_DEBUG("RADEON_CMD_VECTORS\n");
-                       if (radeon_emit_vectors(dev_priv, header, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_vectors failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_DMA_DISCARD:
-                       DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
-                       idx = header.dma.buf_idx;
-                       if (idx < 0 || idx >= dma->buf_count) {
-                               DRM_ERROR("buffer index %d (of %d max)\n",
-                                         idx, dma->buf_count - 1);
-                               goto err;
-                       }
-
-                       buf = dma->buflist[idx];
-                       if (buf->file_priv != file_priv || buf->pending) {
-                               DRM_ERROR("bad buffer %p %p %d\n",
-                                         buf->file_priv, file_priv,
-                                         buf->pending);
-                               goto err;
-                       }
-
-                       radeon_cp_discard_buffer(dev, buf);
-                       break;
-
-               case RADEON_CMD_PACKET3:
-                       DRM_DEBUG("RADEON_CMD_PACKET3\n");
-                       if (radeon_emit_packet3(dev, file_priv, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_packet3 failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_PACKET3_CLIP:
-                       DRM_DEBUG("RADEON_CMD_PACKET3_CLIP\n");
-                       if (radeon_emit_packet3_cliprect
-                           (dev, file_priv, cmdbuf, orig_nbox)) {
-                               DRM_ERROR("radeon_emit_packet3_clip failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_SCALARS2:
-                       DRM_DEBUG("RADEON_CMD_SCALARS2\n");
-                       if (radeon_emit_scalars2(dev_priv, header, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_scalars2 failed\n");
-                               goto err;
-                       }
-                       break;
-
-               case RADEON_CMD_WAIT:
-                       DRM_DEBUG("RADEON_CMD_WAIT\n");
-                       if (radeon_emit_wait(dev, header.wait.flags)) {
-                               DRM_ERROR("radeon_emit_wait failed\n");
-                               goto err;
-                       }
-                       break;
-               case RADEON_CMD_VECLINEAR:
-                       DRM_DEBUG("RADEON_CMD_VECLINEAR\n");
-                       if (radeon_emit_veclinear(dev_priv, header, cmdbuf)) {
-                               DRM_ERROR("radeon_emit_veclinear failed\n");
-                               goto err;
-                       }
-                       break;
-
-               default:
-                       DRM_ERROR("bad cmd_type %d at %p\n",
-                                 header.header.cmd_type,
-                                 cmdbuf->buf - sizeof(header));
-                       goto err;
-               }
-       }
-
-       if (orig_bufsz != 0)
-               drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
-
-       DRM_DEBUG("DONE\n");
-       COMMIT_RING();
-       return 0;
-
-      err:
-       if (orig_bufsz != 0)
-               drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
-       return -EINVAL;
-}
-
-static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_getparam_t *param = data;
-       int value;
-
-       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
-
-       switch (param->param) {
-       case RADEON_PARAM_GART_BUFFER_OFFSET:
-               value = dev_priv->gart_buffers_offset;
-               break;
-       case RADEON_PARAM_LAST_FRAME:
-               dev_priv->stats.last_frame_reads++;
-               value = GET_SCRATCH(0);
-               break;
-       case RADEON_PARAM_LAST_DISPATCH:
-               value = GET_SCRATCH(1);
-               break;
-       case RADEON_PARAM_LAST_CLEAR:
-               dev_priv->stats.last_clear_reads++;
-               value = GET_SCRATCH(2);
-               break;
-       case RADEON_PARAM_IRQ_NR:
-               value = dev->irq;
-               break;
-       case RADEON_PARAM_GART_BASE:
-               value = dev_priv->gart_vm_start;
-               break;
-       case RADEON_PARAM_REGISTER_HANDLE:
-               value = dev_priv->mmio->offset;
-               break;
-       case RADEON_PARAM_STATUS_HANDLE:
-               value = dev_priv->ring_rptr_offset;
-               break;
-#if BITS_PER_LONG == 32
-               /*
-                * This ioctl() doesn't work on 64-bit platforms because hw_lock is a
-                * pointer which can't fit into an int-sized variable.  According to
-                * Michel Dänzer, the ioctl() is only used on embedded platforms, so
-                * not supporting it shouldn't be a problem.  If the same functionality
-                * is needed on 64-bit platforms, a new ioctl() would have to be added,
-                * so backwards-compatibility for the embedded platforms can be
-                * maintained.  --davidm 4-Feb-2004.
-                */
-       case RADEON_PARAM_SAREA_HANDLE:
-               /* The lock is the first dword in the sarea. */
-               value = (long)dev->lock.hw_lock;
-               break;
-#endif
-       case RADEON_PARAM_GART_TEX_HANDLE:
-               value = dev_priv->gart_textures_offset;
-               break;
-       case RADEON_PARAM_SCRATCH_OFFSET:
-               if (!dev_priv->writeback_works)
-                       return -EINVAL;
-               value = RADEON_SCRATCH_REG_OFFSET;
-               break;
-       case RADEON_PARAM_CARD_TYPE:
-               if (dev_priv->flags & RADEON_IS_PCIE)
-                       value = RADEON_CARD_PCIE;
-               else if (dev_priv->flags & RADEON_IS_AGP)
-                       value = RADEON_CARD_AGP;
-               else
-                       value = RADEON_CARD_PCI;
-               break;
-       case RADEON_PARAM_VBLANK_CRTC:
-               value = radeon_vblank_crtc_get(dev);
-               break;
-       case RADEON_PARAM_FB_LOCATION:
-               value = radeon_read_fb_location(dev_priv);
-               break;
-       case RADEON_PARAM_NUM_GB_PIPES:
-               value = dev_priv->num_gb_pipes;
-               break;
-       default:
-               DRM_DEBUG("Invalid parameter %d\n", param->param);
-               return -EINVAL;
-       }
-
-       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
-               DRM_ERROR("copy_to_user\n");
-               return -EFAULT;
-       }
-
-       return 0;
-}
-
-static int radeon_cp_setparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       drm_radeon_setparam_t *sp = data;
-       struct drm_radeon_driver_file_fields *radeon_priv;
-
-       switch (sp->param) {
-       case RADEON_SETPARAM_FB_LOCATION:
-               radeon_priv = file_priv->driver_priv;
-               radeon_priv->radeon_fb_delta = dev_priv->fb_location -
-                   sp->value;
-               break;
-       case RADEON_SETPARAM_SWITCH_TILING:
-               if (sp->value == 0) {
-                       DRM_DEBUG("color tiling disabled\n");
-                       dev_priv->front_pitch_offset &= ~RADEON_DST_TILE_MACRO;
-                       dev_priv->back_pitch_offset &= ~RADEON_DST_TILE_MACRO;
-                       dev_priv->sarea_priv->tiling_enabled = 0;
-               } else if (sp->value == 1) {
-                       DRM_DEBUG("color tiling enabled\n");
-                       dev_priv->front_pitch_offset |= RADEON_DST_TILE_MACRO;
-                       dev_priv->back_pitch_offset |= RADEON_DST_TILE_MACRO;
-                       dev_priv->sarea_priv->tiling_enabled = 1;
-               }
-               break;
-       case RADEON_SETPARAM_PCIGART_LOCATION:
-               dev_priv->pcigart_offset = sp->value;
-               dev_priv->pcigart_offset_set = 1;
-               break;
-       case RADEON_SETPARAM_NEW_MEMMAP:
-               dev_priv->new_memmap = sp->value;
-               break;
-       case RADEON_SETPARAM_PCIGART_TABLE_SIZE:
-               dev_priv->gart_info.table_size = sp->value;
-               if (dev_priv->gart_info.table_size < RADEON_PCIGART_TABLE_SIZE)
-                       dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
-               break;
-       case RADEON_SETPARAM_VBLANK_CRTC:
-               return radeon_vblank_crtc_set(dev, sp->value);
-               break;
-       default:
-               DRM_DEBUG("Invalid parameter %d\n", sp->param);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/* When a client dies:
- *    - Check for and clean up flipped page state
- *    - Free any alloced GART memory.
- *    - Free any alloced radeon surfaces.
- *
- * DRM infrastructure takes care of reclaiming dma buffers.
- */
-void radeon_driver_preclose(struct drm_device *dev, struct drm_file *file_priv)
-{
-       if (dev->dev_private) {
-               drm_radeon_private_t *dev_priv = dev->dev_private;
-               dev_priv->page_flipping = 0;
-               radeon_mem_release(file_priv, dev_priv->gart_heap);
-               radeon_mem_release(file_priv, dev_priv->fb_heap);
-               radeon_surfaces_release(file_priv, dev_priv);
-       }
-}
-
-void radeon_driver_lastclose(struct drm_device *dev)
-{
-       if (dev->dev_private) {
-               drm_radeon_private_t *dev_priv = dev->dev_private;
-
-               if (dev_priv->sarea_priv &&
-                   dev_priv->sarea_priv->pfCurrentPage != 0)
-                       radeon_cp_dispatch_flip(dev);
-       }
-
-       radeon_do_release(dev);
-}
-
-int radeon_driver_open(struct drm_device *dev, struct drm_file *file_priv)
-{
-       drm_radeon_private_t *dev_priv = dev->dev_private;
-       struct drm_radeon_driver_file_fields *radeon_priv;
-
-       DRM_DEBUG("\n");
-       radeon_priv =
-           (struct drm_radeon_driver_file_fields *)
-           drm_alloc(sizeof(*radeon_priv), DRM_MEM_FILES);
-
-       if (!radeon_priv)
-               return -ENOMEM;
-
-       file_priv->driver_priv = radeon_priv;
-
-       if (dev_priv)
-               radeon_priv->radeon_fb_delta = dev_priv->fb_location;
-       else
-               radeon_priv->radeon_fb_delta = 0;
-       return 0;
-}
-
-void radeon_driver_postclose(struct drm_device *dev, struct drm_file *file_priv)
-{
-       struct drm_radeon_driver_file_fields *radeon_priv =
-           file_priv->driver_priv;
-
-       drm_free(radeon_priv, sizeof(*radeon_priv), DRM_MEM_FILES);
-}
-
-struct drm_ioctl_desc radeon_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_RADEON_CP_INIT, radeon_cp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_CP_START, radeon_cp_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_CP_STOP, radeon_cp_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_CP_RESET, radeon_cp_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_CP_IDLE, radeon_cp_idle, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_CP_RESUME, radeon_cp_resume, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_RESET, radeon_engine_reset, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_FULLSCREEN, radeon_fullscreen, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_SWAP, radeon_cp_swap, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_CLEAR, radeon_cp_clear, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_VERTEX, radeon_cp_vertex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_INDICES, radeon_cp_indices, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_TEXTURE, radeon_cp_texture, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_STIPPLE, radeon_cp_stipple, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_INDIRECT, radeon_cp_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_VERTEX2, radeon_cp_vertex2, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_CMDBUF, radeon_cp_cmdbuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_GETPARAM, radeon_cp_getparam, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_FLIP, radeon_cp_flip, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_ALLOC, radeon_mem_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_FREE, radeon_mem_free, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_INIT_HEAP, radeon_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_RADEON_IRQ_EMIT, radeon_irq_emit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_IRQ_WAIT, radeon_irq_wait, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_SETPARAM, radeon_cp_setparam, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_SURF_ALLOC, radeon_surface_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_RADEON_SURF_FREE, radeon_surface_free, DRM_AUTH)
-};
-
-int radeon_max_ioctl = DRM_ARRAY_SIZE(radeon_ioctls);
diff --git a/drivers/char/drm/savage_bci.c b/drivers/char/drm/savage_bci.c
deleted file mode 100644 (file)
index d465b2f..0000000
+++ /dev/null
@@ -1,1095 +0,0 @@
-/* savage_bci.c -- BCI support for Savage
- *
- * Copyright 2004  Felix Kuehling
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-#include "drmP.h"
-#include "savage_drm.h"
-#include "savage_drv.h"
-
-/* Need a long timeout for shadow status updates can take a while
- * and so can waiting for events when the queue is full. */
-#define SAVAGE_DEFAULT_USEC_TIMEOUT    1000000 /* 1s */
-#define SAVAGE_EVENT_USEC_TIMEOUT      5000000 /* 5s */
-#define SAVAGE_FREELIST_DEBUG          0
-
-static int savage_do_cleanup_bci(struct drm_device *dev);
-
-static int
-savage_bci_wait_fifo_shadow(drm_savage_private_t * dev_priv, unsigned int n)
-{
-       uint32_t mask = dev_priv->status_used_mask;
-       uint32_t threshold = dev_priv->bci_threshold_hi;
-       uint32_t status;
-       int i;
-
-#if SAVAGE_BCI_DEBUG
-       if (n > dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - threshold)
-               DRM_ERROR("Trying to emit %d words "
-                         "(more than guaranteed space in COB)\n", n);
-#endif
-
-       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
-               DRM_MEMORYBARRIER();
-               status = dev_priv->status_ptr[0];
-               if ((status & mask) < threshold)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if SAVAGE_BCI_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x, threshold=0x%08x\n", status, threshold);
-#endif
-       return -EBUSY;
-}
-
-static int
-savage_bci_wait_fifo_s3d(drm_savage_private_t * dev_priv, unsigned int n)
-{
-       uint32_t maxUsed = dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - n;
-       uint32_t status;
-       int i;
-
-       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
-               status = SAVAGE_READ(SAVAGE_STATUS_WORD0);
-               if ((status & SAVAGE_FIFO_USED_MASK_S3D) <= maxUsed)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if SAVAGE_BCI_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x\n", status);
-#endif
-       return -EBUSY;
-}
-
-static int
-savage_bci_wait_fifo_s4(drm_savage_private_t * dev_priv, unsigned int n)
-{
-       uint32_t maxUsed = dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - n;
-       uint32_t status;
-       int i;
-
-       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
-               status = SAVAGE_READ(SAVAGE_ALT_STATUS_WORD0);
-               if ((status & SAVAGE_FIFO_USED_MASK_S4) <= maxUsed)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if SAVAGE_BCI_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x\n", status);
-#endif
-       return -EBUSY;
-}
-
-/*
- * Waiting for events.
- *
- * The BIOSresets the event tag to 0 on mode changes. Therefore we
- * never emit 0 to the event tag. If we find a 0 event tag we know the
- * BIOS stomped on it and return success assuming that the BIOS waited
- * for engine idle.
- *
- * Note: if the Xserver uses the event tag it has to follow the same
- * rule. Otherwise there may be glitches every 2^16 events.
- */
-static int
-savage_bci_wait_event_shadow(drm_savage_private_t * dev_priv, uint16_t e)
-{
-       uint32_t status;
-       int i;
-
-       for (i = 0; i < SAVAGE_EVENT_USEC_TIMEOUT; i++) {
-               DRM_MEMORYBARRIER();
-               status = dev_priv->status_ptr[1];
-               if ((((status & 0xffff) - e) & 0xffff) <= 0x7fff ||
-                   (status & 0xffff) == 0)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if SAVAGE_BCI_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x, e=0x%04x\n", status, e);
-#endif
-
-       return -EBUSY;
-}
-
-static int
-savage_bci_wait_event_reg(drm_savage_private_t * dev_priv, uint16_t e)
-{
-       uint32_t status;
-       int i;
-
-       for (i = 0; i < SAVAGE_EVENT_USEC_TIMEOUT; i++) {
-               status = SAVAGE_READ(SAVAGE_STATUS_WORD1);
-               if ((((status & 0xffff) - e) & 0xffff) <= 0x7fff ||
-                   (status & 0xffff) == 0)
-                       return 0;
-               DRM_UDELAY(1);
-       }
-
-#if SAVAGE_BCI_DEBUG
-       DRM_ERROR("failed!\n");
-       DRM_INFO("   status=0x%08x, e=0x%04x\n", status, e);
-#endif
-
-       return -EBUSY;
-}
-
-uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
-                              unsigned int flags)
-{
-       uint16_t count;
-       BCI_LOCALS;
-
-       if (dev_priv->status_ptr) {
-               /* coordinate with Xserver */
-               count = dev_priv->status_ptr[1023];
-               if (count < dev_priv->event_counter)
-                       dev_priv->event_wrap++;
-       } else {
-               count = dev_priv->event_counter;
-       }
-       count = (count + 1) & 0xffff;
-       if (count == 0) {
-               count++;        /* See the comment above savage_wait_event_*. */
-               dev_priv->event_wrap++;
-       }
-       dev_priv->event_counter = count;
-       if (dev_priv->status_ptr)
-               dev_priv->status_ptr[1023] = (uint32_t) count;
-
-       if ((flags & (SAVAGE_WAIT_2D | SAVAGE_WAIT_3D))) {
-               unsigned int wait_cmd = BCI_CMD_WAIT;
-               if ((flags & SAVAGE_WAIT_2D))
-                       wait_cmd |= BCI_CMD_WAIT_2D;
-               if ((flags & SAVAGE_WAIT_3D))
-                       wait_cmd |= BCI_CMD_WAIT_3D;
-               BEGIN_BCI(2);
-               BCI_WRITE(wait_cmd);
-       } else {
-               BEGIN_BCI(1);
-       }
-       BCI_WRITE(BCI_CMD_UPDATE_EVENT_TAG | (uint32_t) count);
-
-       return count;
-}
-
-/*
- * Freelist management
- */
-static int savage_freelist_init(struct drm_device * dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *buf;
-       drm_savage_buf_priv_t *entry;
-       int i;
-       DRM_DEBUG("count=%d\n", dma->buf_count);
-
-       dev_priv->head.next = &dev_priv->tail;
-       dev_priv->head.prev = NULL;
-       dev_priv->head.buf = NULL;
-
-       dev_priv->tail.next = NULL;
-       dev_priv->tail.prev = &dev_priv->head;
-       dev_priv->tail.buf = NULL;
-
-       for (i = 0; i < dma->buf_count; i++) {
-               buf = dma->buflist[i];
-               entry = buf->dev_private;
-
-               SET_AGE(&entry->age, 0, 0);
-               entry->buf = buf;
-
-               entry->next = dev_priv->head.next;
-               entry->prev = &dev_priv->head;
-               dev_priv->head.next->prev = entry;
-               dev_priv->head.next = entry;
-       }
-
-       return 0;
-}
-
-static struct drm_buf *savage_freelist_get(struct drm_device * dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       drm_savage_buf_priv_t *tail = dev_priv->tail.prev;
-       uint16_t event;
-       unsigned int wrap;
-       DRM_DEBUG("\n");
-
-       UPDATE_EVENT_COUNTER();
-       if (dev_priv->status_ptr)
-               event = dev_priv->status_ptr[1] & 0xffff;
-       else
-               event = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
-       wrap = dev_priv->event_wrap;
-       if (event > dev_priv->event_counter)
-               wrap--;         /* hardware hasn't passed the last wrap yet */
-
-       DRM_DEBUG("   tail=0x%04x %d\n", tail->age.event, tail->age.wrap);
-       DRM_DEBUG("   head=0x%04x %d\n", event, wrap);
-
-       if (tail->buf && (TEST_AGE(&tail->age, event, wrap) || event == 0)) {
-               drm_savage_buf_priv_t *next = tail->next;
-               drm_savage_buf_priv_t *prev = tail->prev;
-               prev->next = next;
-               next->prev = prev;
-               tail->next = tail->prev = NULL;
-               return tail->buf;
-       }
-
-       DRM_DEBUG("returning NULL, tail->buf=%p!\n", tail->buf);
-       return NULL;
-}
-
-void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       drm_savage_buf_priv_t *entry = buf->dev_private, *prev, *next;
-
-       DRM_DEBUG("age=0x%04x wrap=%d\n", entry->age.event, entry->age.wrap);
-
-       if (entry->next != NULL || entry->prev != NULL) {
-               DRM_ERROR("entry already on freelist.\n");
-               return;
-       }
-
-       prev = &dev_priv->head;
-       next = prev->next;
-       prev->next = entry;
-       next->prev = entry;
-       entry->prev = prev;
-       entry->next = next;
-}
-
-/*
- * Command DMA
- */
-static int savage_dma_init(drm_savage_private_t * dev_priv)
-{
-       unsigned int i;
-
-       dev_priv->nr_dma_pages = dev_priv->cmd_dma->size /
-           (SAVAGE_DMA_PAGE_SIZE * 4);
-       dev_priv->dma_pages = drm_alloc(sizeof(drm_savage_dma_page_t) *
-                                       dev_priv->nr_dma_pages, DRM_MEM_DRIVER);
-       if (dev_priv->dma_pages == NULL)
-               return -ENOMEM;
-
-       for (i = 0; i < dev_priv->nr_dma_pages; ++i) {
-               SET_AGE(&dev_priv->dma_pages[i].age, 0, 0);
-               dev_priv->dma_pages[i].used = 0;
-               dev_priv->dma_pages[i].flushed = 0;
-       }
-       SET_AGE(&dev_priv->last_dma_age, 0, 0);
-
-       dev_priv->first_dma_page = 0;
-       dev_priv->current_dma_page = 0;
-
-       return 0;
-}
-
-void savage_dma_reset(drm_savage_private_t * dev_priv)
-{
-       uint16_t event;
-       unsigned int wrap, i;
-       event = savage_bci_emit_event(dev_priv, 0);
-       wrap = dev_priv->event_wrap;
-       for (i = 0; i < dev_priv->nr_dma_pages; ++i) {
-               SET_AGE(&dev_priv->dma_pages[i].age, event, wrap);
-               dev_priv->dma_pages[i].used = 0;
-               dev_priv->dma_pages[i].flushed = 0;
-       }
-       SET_AGE(&dev_priv->last_dma_age, event, wrap);
-       dev_priv->first_dma_page = dev_priv->current_dma_page = 0;
-}
-
-void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page)
-{
-       uint16_t event;
-       unsigned int wrap;
-
-       /* Faked DMA buffer pages don't age. */
-       if (dev_priv->cmd_dma == &dev_priv->fake_dma)
-               return;
-
-       UPDATE_EVENT_COUNTER();
-       if (dev_priv->status_ptr)
-               event = dev_priv->status_ptr[1] & 0xffff;
-       else
-               event = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
-       wrap = dev_priv->event_wrap;
-       if (event > dev_priv->event_counter)
-               wrap--;         /* hardware hasn't passed the last wrap yet */
-
-       if (dev_priv->dma_pages[page].age.wrap > wrap ||
-           (dev_priv->dma_pages[page].age.wrap == wrap &&
-            dev_priv->dma_pages[page].age.event > event)) {
-               if (dev_priv->wait_evnt(dev_priv,
-                                       dev_priv->dma_pages[page].age.event)
-                   < 0)
-                       DRM_ERROR("wait_evnt failed!\n");
-       }
-}
-
-uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv, unsigned int n)
-{
-       unsigned int cur = dev_priv->current_dma_page;
-       unsigned int rest = SAVAGE_DMA_PAGE_SIZE -
-           dev_priv->dma_pages[cur].used;
-       unsigned int nr_pages = (n - rest + SAVAGE_DMA_PAGE_SIZE - 1) /
-           SAVAGE_DMA_PAGE_SIZE;
-       uint32_t *dma_ptr;
-       unsigned int i;
-
-       DRM_DEBUG("cur=%u, cur->used=%u, n=%u, rest=%u, nr_pages=%u\n",
-                 cur, dev_priv->dma_pages[cur].used, n, rest, nr_pages);
-
-       if (cur + nr_pages < dev_priv->nr_dma_pages) {
-               dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
-                   cur * SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used;
-               if (n < rest)
-                       rest = n;
-               dev_priv->dma_pages[cur].used += rest;
-               n -= rest;
-               cur++;
-       } else {
-               dev_priv->dma_flush(dev_priv);
-               nr_pages =
-                   (n + SAVAGE_DMA_PAGE_SIZE - 1) / SAVAGE_DMA_PAGE_SIZE;
-               for (i = cur; i < dev_priv->nr_dma_pages; ++i) {
-                       dev_priv->dma_pages[i].age = dev_priv->last_dma_age;
-                       dev_priv->dma_pages[i].used = 0;
-                       dev_priv->dma_pages[i].flushed = 0;
-               }
-               dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle;
-               dev_priv->first_dma_page = cur = 0;
-       }
-       for (i = cur; nr_pages > 0; ++i, --nr_pages) {
-#if SAVAGE_DMA_DEBUG
-               if (dev_priv->dma_pages[i].used) {
-                       DRM_ERROR("unflushed page %u: used=%u\n",
-                                 i, dev_priv->dma_pages[i].used);
-               }
-#endif
-               if (n > SAVAGE_DMA_PAGE_SIZE)
-                       dev_priv->dma_pages[i].used = SAVAGE_DMA_PAGE_SIZE;
-               else
-                       dev_priv->dma_pages[i].used = n;
-               n -= SAVAGE_DMA_PAGE_SIZE;
-       }
-       dev_priv->current_dma_page = --i;
-
-       DRM_DEBUG("cur=%u, cur->used=%u, n=%u\n",
-                 i, dev_priv->dma_pages[i].used, n);
-
-       savage_dma_wait(dev_priv, dev_priv->current_dma_page);
-
-       return dma_ptr;
-}
-
-static void savage_dma_flush(drm_savage_private_t * dev_priv)
-{
-       unsigned int first = dev_priv->first_dma_page;
-       unsigned int cur = dev_priv->current_dma_page;
-       uint16_t event;
-       unsigned int wrap, pad, align, len, i;
-       unsigned long phys_addr;
-       BCI_LOCALS;
-
-       if (first == cur &&
-           dev_priv->dma_pages[cur].used == dev_priv->dma_pages[cur].flushed)
-               return;
-
-       /* pad length to multiples of 2 entries
-        * align start of next DMA block to multiles of 8 entries */
-       pad = -dev_priv->dma_pages[cur].used & 1;
-       align = -(dev_priv->dma_pages[cur].used + pad) & 7;
-
-       DRM_DEBUG("first=%u, cur=%u, first->flushed=%u, cur->used=%u, "
-                 "pad=%u, align=%u\n",
-                 first, cur, dev_priv->dma_pages[first].flushed,
-                 dev_priv->dma_pages[cur].used, pad, align);
-
-       /* pad with noops */
-       if (pad) {
-               uint32_t *dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
-                   cur * SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used;
-               dev_priv->dma_pages[cur].used += pad;
-               while (pad != 0) {
-                       *dma_ptr++ = BCI_CMD_WAIT;
-                       pad--;
-               }
-       }
-
-       DRM_MEMORYBARRIER();
-
-       /* do flush ... */
-       phys_addr = dev_priv->cmd_dma->offset +
-           (first * SAVAGE_DMA_PAGE_SIZE +
-            dev_priv->dma_pages[first].flushed) * 4;
-       len = (cur - first) * SAVAGE_DMA_PAGE_SIZE +
-           dev_priv->dma_pages[cur].used - dev_priv->dma_pages[first].flushed;
-
-       DRM_DEBUG("phys_addr=%lx, len=%u\n",
-                 phys_addr | dev_priv->dma_type, len);
-
-       BEGIN_BCI(3);
-       BCI_SET_REGISTERS(SAVAGE_DMABUFADDR, 1);
-       BCI_WRITE(phys_addr | dev_priv->dma_type);
-       BCI_DMA(len);
-
-       /* fix alignment of the start of the next block */
-       dev_priv->dma_pages[cur].used += align;
-
-       /* age DMA pages */
-       event = savage_bci_emit_event(dev_priv, 0);
-       wrap = dev_priv->event_wrap;
-       for (i = first; i < cur; ++i) {
-               SET_AGE(&dev_priv->dma_pages[i].age, event, wrap);
-               dev_priv->dma_pages[i].used = 0;
-               dev_priv->dma_pages[i].flushed = 0;
-       }
-       /* age the current page only when it's full */
-       if (dev_priv->dma_pages[cur].used == SAVAGE_DMA_PAGE_SIZE) {
-               SET_AGE(&dev_priv->dma_pages[cur].age, event, wrap);
-               dev_priv->dma_pages[cur].used = 0;
-               dev_priv->dma_pages[cur].flushed = 0;
-               /* advance to next page */
-               cur++;
-               if (cur == dev_priv->nr_dma_pages)
-                       cur = 0;
-               dev_priv->first_dma_page = dev_priv->current_dma_page = cur;
-       } else {
-               dev_priv->first_dma_page = cur;
-               dev_priv->dma_pages[cur].flushed = dev_priv->dma_pages[i].used;
-       }
-       SET_AGE(&dev_priv->last_dma_age, event, wrap);
-
-       DRM_DEBUG("first=cur=%u, cur->used=%u, cur->flushed=%u\n", cur,
-                 dev_priv->dma_pages[cur].used,
-                 dev_priv->dma_pages[cur].flushed);
-}
-
-static void savage_fake_dma_flush(drm_savage_private_t * dev_priv)
-{
-       unsigned int i, j;
-       BCI_LOCALS;
-
-       if (dev_priv->first_dma_page == dev_priv->current_dma_page &&
-           dev_priv->dma_pages[dev_priv->current_dma_page].used == 0)
-               return;
-
-       DRM_DEBUG("first=%u, cur=%u, cur->used=%u\n",
-                 dev_priv->first_dma_page, dev_priv->current_dma_page,
-                 dev_priv->dma_pages[dev_priv->current_dma_page].used);
-
-       for (i = dev_priv->first_dma_page;
-            i <= dev_priv->current_dma_page && dev_priv->dma_pages[i].used;
-            ++i) {
-               uint32_t *dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
-                   i * SAVAGE_DMA_PAGE_SIZE;
-#if SAVAGE_DMA_DEBUG
-               /* Sanity check: all pages except the last one must be full. */
-               if (i < dev_priv->current_dma_page &&
-                   dev_priv->dma_pages[i].used != SAVAGE_DMA_PAGE_SIZE) {
-                       DRM_ERROR("partial DMA page %u: used=%u",
-                                 i, dev_priv->dma_pages[i].used);
-               }
-#endif
-               BEGIN_BCI(dev_priv->dma_pages[i].used);
-               for (j = 0; j < dev_priv->dma_pages[i].used; ++j) {
-                       BCI_WRITE(dma_ptr[j]);
-               }
-               dev_priv->dma_pages[i].used = 0;
-       }
-
-       /* reset to first page */
-       dev_priv->first_dma_page = dev_priv->current_dma_page = 0;
-}
-
-int savage_driver_load(struct drm_device *dev, unsigned long chipset)
-{
-       drm_savage_private_t *dev_priv;
-
-       dev_priv = drm_alloc(sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       memset(dev_priv, 0, sizeof(drm_savage_private_t));
-       dev->dev_private = (void *)dev_priv;
-
-       dev_priv->chipset = (enum savage_family)chipset;
-
-       return 0;
-}
-
-
-/*
- * Initalize mappings. On Savage4 and SavageIX the alignment
- * and size of the aperture is not suitable for automatic MTRR setup
- * in drm_addmap. Therefore we add them manually before the maps are
- * initialized, and tear them down on last close.
- */
-int savage_driver_firstopen(struct drm_device *dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       unsigned long mmio_base, fb_base, fb_size, aperture_base;
-       /* fb_rsrc and aper_rsrc aren't really used currently, but still exist
-        * in case we decide we need information on the BAR for BSD in the
-        * future.
-        */
-       unsigned int fb_rsrc, aper_rsrc;
-       int ret = 0;
-
-       dev_priv->mtrr[0].handle = -1;
-       dev_priv->mtrr[1].handle = -1;
-       dev_priv->mtrr[2].handle = -1;
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               fb_rsrc = 0;
-               fb_base = drm_get_resource_start(dev, 0);
-               fb_size = SAVAGE_FB_SIZE_S3;
-               mmio_base = fb_base + SAVAGE_FB_SIZE_S3;
-               aper_rsrc = 0;
-               aperture_base = fb_base + SAVAGE_APERTURE_OFFSET;
-               /* this should always be true */
-               if (drm_get_resource_len(dev, 0) == 0x08000000) {
-                       /* Don't make MMIO write-cobining! We need 3
-                        * MTRRs. */
-                       dev_priv->mtrr[0].base = fb_base;
-                       dev_priv->mtrr[0].size = 0x01000000;
-                       dev_priv->mtrr[0].handle =
-                           drm_mtrr_add(dev_priv->mtrr[0].base,
-                                        dev_priv->mtrr[0].size, DRM_MTRR_WC);
-                       dev_priv->mtrr[1].base = fb_base + 0x02000000;
-                       dev_priv->mtrr[1].size = 0x02000000;
-                       dev_priv->mtrr[1].handle =
-                           drm_mtrr_add(dev_priv->mtrr[1].base,
-                                        dev_priv->mtrr[1].size, DRM_MTRR_WC);
-                       dev_priv->mtrr[2].base = fb_base + 0x04000000;
-                       dev_priv->mtrr[2].size = 0x04000000;
-                       dev_priv->mtrr[2].handle =
-                           drm_mtrr_add(dev_priv->mtrr[2].base,
-                                        dev_priv->mtrr[2].size, DRM_MTRR_WC);
-               } else {
-                       DRM_ERROR("strange pci_resource_len %08lx\n",
-                                 drm_get_resource_len(dev, 0));
-               }
-       } else if (dev_priv->chipset != S3_SUPERSAVAGE &&
-                  dev_priv->chipset != S3_SAVAGE2000) {
-               mmio_base = drm_get_resource_start(dev, 0);
-               fb_rsrc = 1;
-               fb_base = drm_get_resource_start(dev, 1);
-               fb_size = SAVAGE_FB_SIZE_S4;
-               aper_rsrc = 1;
-               aperture_base = fb_base + SAVAGE_APERTURE_OFFSET;
-               /* this should always be true */
-               if (drm_get_resource_len(dev, 1) == 0x08000000) {
-                       /* Can use one MTRR to cover both fb and
-                        * aperture. */
-                       dev_priv->mtrr[0].base = fb_base;
-                       dev_priv->mtrr[0].size = 0x08000000;
-                       dev_priv->mtrr[0].handle =
-                           drm_mtrr_add(dev_priv->mtrr[0].base,
-                                        dev_priv->mtrr[0].size, DRM_MTRR_WC);
-               } else {
-                       DRM_ERROR("strange pci_resource_len %08lx\n",
-                                 drm_get_resource_len(dev, 1));
-               }
-       } else {
-               mmio_base = drm_get_resource_start(dev, 0);
-               fb_rsrc = 1;
-               fb_base = drm_get_resource_start(dev, 1);
-               fb_size = drm_get_resource_len(dev, 1);
-               aper_rsrc = 2;
-               aperture_base = drm_get_resource_start(dev, 2);
-               /* Automatic MTRR setup will do the right thing. */
-       }
-
-       ret = drm_addmap(dev, mmio_base, SAVAGE_MMIO_SIZE, _DRM_REGISTERS,
-                        _DRM_READ_ONLY, &dev_priv->mmio);
-       if (ret)
-               return ret;
-
-       ret = drm_addmap(dev, fb_base, fb_size, _DRM_FRAME_BUFFER,
-                        _DRM_WRITE_COMBINING, &dev_priv->fb);
-       if (ret)
-               return ret;
-
-       ret = drm_addmap(dev, aperture_base, SAVAGE_APERTURE_SIZE,
-                        _DRM_FRAME_BUFFER, _DRM_WRITE_COMBINING,
-                        &dev_priv->aperture);
-       if (ret)
-               return ret;
-
-       return ret;
-}
-
-/*
- * Delete MTRRs and free device-private data.
- */
-void savage_driver_lastclose(struct drm_device *dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       int i;
-
-       for (i = 0; i < 3; ++i)
-               if (dev_priv->mtrr[i].handle >= 0)
-                       drm_mtrr_del(dev_priv->mtrr[i].handle,
-                                dev_priv->mtrr[i].base,
-                                dev_priv->mtrr[i].size, DRM_MTRR_WC);
-}
-
-int savage_driver_unload(struct drm_device *dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-
-       drm_free(dev_priv, sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
-
-       return 0;
-}
-
-static int savage_do_init_bci(struct drm_device * dev, drm_savage_init_t * init)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-
-       if (init->fb_bpp != 16 && init->fb_bpp != 32) {
-               DRM_ERROR("invalid frame buffer bpp %d!\n", init->fb_bpp);
-               return -EINVAL;
-       }
-       if (init->depth_bpp != 16 && init->depth_bpp != 32) {
-               DRM_ERROR("invalid depth buffer bpp %d!\n", init->fb_bpp);
-               return -EINVAL;
-       }
-       if (init->dma_type != SAVAGE_DMA_AGP &&
-           init->dma_type != SAVAGE_DMA_PCI) {
-               DRM_ERROR("invalid dma memory type %d!\n", init->dma_type);
-               return -EINVAL;
-       }
-
-       dev_priv->cob_size = init->cob_size;
-       dev_priv->bci_threshold_lo = init->bci_threshold_lo;
-       dev_priv->bci_threshold_hi = init->bci_threshold_hi;
-       dev_priv->dma_type = init->dma_type;
-
-       dev_priv->fb_bpp = init->fb_bpp;
-       dev_priv->front_offset = init->front_offset;
-       dev_priv->front_pitch = init->front_pitch;
-       dev_priv->back_offset = init->back_offset;
-       dev_priv->back_pitch = init->back_pitch;
-       dev_priv->depth_bpp = init->depth_bpp;
-       dev_priv->depth_offset = init->depth_offset;
-       dev_priv->depth_pitch = init->depth_pitch;
-
-       dev_priv->texture_offset = init->texture_offset;
-       dev_priv->texture_size = init->texture_size;
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("could not find sarea!\n");
-               savage_do_cleanup_bci(dev);
-               return -EINVAL;
-       }
-       if (init->status_offset != 0) {
-               dev_priv->status = drm_core_findmap(dev, init->status_offset);
-               if (!dev_priv->status) {
-                       DRM_ERROR("could not find shadow status region!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-       } else {
-               dev_priv->status = NULL;
-       }
-       if (dev_priv->dma_type == SAVAGE_DMA_AGP && init->buffers_offset) {
-               dev->agp_buffer_token = init->buffers_offset;
-               dev->agp_buffer_map = drm_core_findmap(dev,
-                                                      init->buffers_offset);
-               if (!dev->agp_buffer_map) {
-                       DRM_ERROR("could not find DMA buffer region!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-               drm_core_ioremap(dev->agp_buffer_map, dev);
-               if (!dev->agp_buffer_map) {
-                       DRM_ERROR("failed to ioremap DMA buffer region!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -ENOMEM;
-               }
-       }
-       if (init->agp_textures_offset) {
-               dev_priv->agp_textures =
-                   drm_core_findmap(dev, init->agp_textures_offset);
-               if (!dev_priv->agp_textures) {
-                       DRM_ERROR("could not find agp texture region!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-       } else {
-               dev_priv->agp_textures = NULL;
-       }
-
-       if (init->cmd_dma_offset) {
-               if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-                       DRM_ERROR("command DMA not supported on "
-                                 "Savage3D/MX/IX.\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-               if (dev->dma && dev->dma->buflist) {
-                       DRM_ERROR("command and vertex DMA not supported "
-                                 "at the same time.\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-               dev_priv->cmd_dma = drm_core_findmap(dev, init->cmd_dma_offset);
-               if (!dev_priv->cmd_dma) {
-                       DRM_ERROR("could not find command DMA region!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-               if (dev_priv->dma_type == SAVAGE_DMA_AGP) {
-                       if (dev_priv->cmd_dma->type != _DRM_AGP) {
-                               DRM_ERROR("AGP command DMA region is not a "
-                                         "_DRM_AGP map!\n");
-                               savage_do_cleanup_bci(dev);
-                               return -EINVAL;
-                       }
-                       drm_core_ioremap(dev_priv->cmd_dma, dev);
-                       if (!dev_priv->cmd_dma->handle) {
-                               DRM_ERROR("failed to ioremap command "
-                                         "DMA region!\n");
-                               savage_do_cleanup_bci(dev);
-                               return -ENOMEM;
-                       }
-               } else if (dev_priv->cmd_dma->type != _DRM_CONSISTENT) {
-                       DRM_ERROR("PCI command DMA region is not a "
-                                 "_DRM_CONSISTENT map!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -EINVAL;
-               }
-       } else {
-               dev_priv->cmd_dma = NULL;
-       }
-
-       dev_priv->dma_flush = savage_dma_flush;
-       if (!dev_priv->cmd_dma) {
-               DRM_DEBUG("falling back to faked command DMA.\n");
-               dev_priv->fake_dma.offset = 0;
-               dev_priv->fake_dma.size = SAVAGE_FAKE_DMA_SIZE;
-               dev_priv->fake_dma.type = _DRM_SHM;
-               dev_priv->fake_dma.handle = drm_alloc(SAVAGE_FAKE_DMA_SIZE,
-                                                     DRM_MEM_DRIVER);
-               if (!dev_priv->fake_dma.handle) {
-                       DRM_ERROR("could not allocate faked DMA buffer!\n");
-                       savage_do_cleanup_bci(dev);
-                       return -ENOMEM;
-               }
-               dev_priv->cmd_dma = &dev_priv->fake_dma;
-               dev_priv->dma_flush = savage_fake_dma_flush;
-       }
-
-       dev_priv->sarea_priv =
-           (drm_savage_sarea_t *) ((uint8_t *) dev_priv->sarea->handle +
-                                   init->sarea_priv_offset);
-
-       /* setup bitmap descriptors */
-       {
-               unsigned int color_tile_format;
-               unsigned int depth_tile_format;
-               unsigned int front_stride, back_stride, depth_stride;
-               if (dev_priv->chipset <= S3_SAVAGE4) {
-                       color_tile_format = dev_priv->fb_bpp == 16 ?
-                           SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP;
-                       depth_tile_format = dev_priv->depth_bpp == 16 ?
-                           SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP;
-               } else {
-                       color_tile_format = SAVAGE_BD_TILE_DEST;
-                       depth_tile_format = SAVAGE_BD_TILE_DEST;
-               }
-               front_stride = dev_priv->front_pitch / (dev_priv->fb_bpp / 8);
-               back_stride = dev_priv->back_pitch / (dev_priv->fb_bpp / 8);
-               depth_stride =
-                   dev_priv->depth_pitch / (dev_priv->depth_bpp / 8);
-
-               dev_priv->front_bd = front_stride | SAVAGE_BD_BW_DISABLE |
-                   (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) |
-                   (color_tile_format << SAVAGE_BD_TILE_SHIFT);
-
-               dev_priv->back_bd = back_stride | SAVAGE_BD_BW_DISABLE |
-                   (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) |
-                   (color_tile_format << SAVAGE_BD_TILE_SHIFT);
-
-               dev_priv->depth_bd = depth_stride | SAVAGE_BD_BW_DISABLE |
-                   (dev_priv->depth_bpp << SAVAGE_BD_BPP_SHIFT) |
-                   (depth_tile_format << SAVAGE_BD_TILE_SHIFT);
-       }
-
-       /* setup status and bci ptr */
-       dev_priv->event_counter = 0;
-       dev_priv->event_wrap = 0;
-       dev_priv->bci_ptr = (volatile uint32_t *)
-           ((uint8_t *) dev_priv->mmio->handle + SAVAGE_BCI_OFFSET);
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               dev_priv->status_used_mask = SAVAGE_FIFO_USED_MASK_S3D;
-       } else {
-               dev_priv->status_used_mask = SAVAGE_FIFO_USED_MASK_S4;
-       }
-       if (dev_priv->status != NULL) {
-               dev_priv->status_ptr =
-                   (volatile uint32_t *)dev_priv->status->handle;
-               dev_priv->wait_fifo = savage_bci_wait_fifo_shadow;
-               dev_priv->wait_evnt = savage_bci_wait_event_shadow;
-               dev_priv->status_ptr[1023] = dev_priv->event_counter;
-       } else {
-               dev_priv->status_ptr = NULL;
-               if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-                       dev_priv->wait_fifo = savage_bci_wait_fifo_s3d;
-               } else {
-                       dev_priv->wait_fifo = savage_bci_wait_fifo_s4;
-               }
-               dev_priv->wait_evnt = savage_bci_wait_event_reg;
-       }
-
-       /* cliprect functions */
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset))
-               dev_priv->emit_clip_rect = savage_emit_clip_rect_s3d;
-       else
-               dev_priv->emit_clip_rect = savage_emit_clip_rect_s4;
-
-       if (savage_freelist_init(dev) < 0) {
-               DRM_ERROR("could not initialize freelist\n");
-               savage_do_cleanup_bci(dev);
-               return -ENOMEM;
-       }
-
-       if (savage_dma_init(dev_priv) < 0) {
-               DRM_ERROR("could not initialize command DMA\n");
-               savage_do_cleanup_bci(dev);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-static int savage_do_cleanup_bci(struct drm_device * dev)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-
-       if (dev_priv->cmd_dma == &dev_priv->fake_dma) {
-               if (dev_priv->fake_dma.handle)
-                       drm_free(dev_priv->fake_dma.handle,
-                                SAVAGE_FAKE_DMA_SIZE, DRM_MEM_DRIVER);
-       } else if (dev_priv->cmd_dma && dev_priv->cmd_dma->handle &&
-                  dev_priv->cmd_dma->type == _DRM_AGP &&
-                  dev_priv->dma_type == SAVAGE_DMA_AGP)
-               drm_core_ioremapfree(dev_priv->cmd_dma, dev);
-
-       if (dev_priv->dma_type == SAVAGE_DMA_AGP &&
-           dev->agp_buffer_map && dev->agp_buffer_map->handle) {
-               drm_core_ioremapfree(dev->agp_buffer_map, dev);
-               /* make sure the next instance (which may be running
-                * in PCI mode) doesn't try to use an old
-                * agp_buffer_map. */
-               dev->agp_buffer_map = NULL;
-       }
-
-       if (dev_priv->dma_pages)
-               drm_free(dev_priv->dma_pages,
-                        sizeof(drm_savage_dma_page_t) * dev_priv->nr_dma_pages,
-                        DRM_MEM_DRIVER);
-
-       return 0;
-}
-
-static int savage_bci_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_savage_init_t *init = data;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       switch (init->func) {
-       case SAVAGE_INIT_BCI:
-               return savage_do_init_bci(dev, init);
-       case SAVAGE_CLEANUP_BCI:
-               return savage_do_cleanup_bci(dev);
-       }
-
-       return -EINVAL;
-}
-
-static int savage_bci_event_emit(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       drm_savage_event_emit_t *event = data;
-
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       event->count = savage_bci_emit_event(dev_priv, event->flags);
-       event->count |= dev_priv->event_wrap << 16;
-
-       return 0;
-}
-
-static int savage_bci_event_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       drm_savage_event_wait_t *event = data;
-       unsigned int event_e, hw_e;
-       unsigned int event_w, hw_w;
-
-       DRM_DEBUG("\n");
-
-       UPDATE_EVENT_COUNTER();
-       if (dev_priv->status_ptr)
-               hw_e = dev_priv->status_ptr[1] & 0xffff;
-       else
-               hw_e = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
-       hw_w = dev_priv->event_wrap;
-       if (hw_e > dev_priv->event_counter)
-               hw_w--;         /* hardware hasn't passed the last wrap yet */
-
-       event_e = event->count & 0xffff;
-       event_w = event->count >> 16;
-
-       /* Don't need to wait if
-        * - event counter wrapped since the event was emitted or
-        * - the hardware has advanced up to or over the event to wait for.
-        */
-       if (event_w < hw_w || (event_w == hw_w && event_e <= hw_e))
-               return 0;
-       else
-               return dev_priv->wait_evnt(dev_priv, event_e);
-}
-
-/*
- * DMA buffer management
- */
-
-static int savage_bci_get_buffers(struct drm_device *dev,
-                                 struct drm_file *file_priv,
-                                 struct drm_dma *d)
-{
-       struct drm_buf *buf;
-       int i;
-
-       for (i = d->granted_count; i < d->request_count; i++) {
-               buf = savage_freelist_get(dev);
-               if (!buf)
-                       return -EAGAIN;
-
-               buf->file_priv = file_priv;
-
-               if (DRM_COPY_TO_USER(&d->request_indices[i],
-                                    &buf->idx, sizeof(buf->idx)))
-                       return -EFAULT;
-               if (DRM_COPY_TO_USER(&d->request_sizes[i],
-                                    &buf->total, sizeof(buf->total)))
-                       return -EFAULT;
-
-               d->granted_count++;
-       }
-       return 0;
-}
-
-int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_dma *d = data;
-       int ret = 0;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       /* Please don't send us buffers.
-        */
-       if (d->send_count != 0) {
-               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
-                         DRM_CURRENTPID, d->send_count);
-               return -EINVAL;
-       }
-
-       /* We'll send you buffers.
-        */
-       if (d->request_count < 0 || d->request_count > dma->buf_count) {
-               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
-                         DRM_CURRENTPID, d->request_count, dma->buf_count);
-               return -EINVAL;
-       }
-
-       d->granted_count = 0;
-
-       if (d->request_count) {
-               ret = savage_bci_get_buffers(dev, file_priv, d);
-       }
-
-       return ret;
-}
-
-void savage_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
-{
-       struct drm_device_dma *dma = dev->dma;
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       int i;
-
-       if (!dma)
-               return;
-       if (!dev_priv)
-               return;
-       if (!dma->buflist)
-               return;
-
-       /*i830_flush_queue(dev); */
-
-       for (i = 0; i < dma->buf_count; i++) {
-               struct drm_buf *buf = dma->buflist[i];
-               drm_savage_buf_priv_t *buf_priv = buf->dev_private;
-
-               if (buf->file_priv == file_priv && buf_priv &&
-                   buf_priv->next == NULL && buf_priv->prev == NULL) {
-                       uint16_t event;
-                       DRM_DEBUG("reclaimed from client\n");
-                       event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
-                       SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
-                       savage_freelist_put(dev, buf);
-               }
-       }
-
-       drm_core_reclaim_buffers(dev, file_priv);
-}
-
-struct drm_ioctl_desc savage_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_INIT, savage_bci_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_CMDBUF, savage_bci_cmdbuf, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_EVENT_EMIT, savage_bci_event_emit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_EVENT_WAIT, savage_bci_event_wait, DRM_AUTH),
-};
-
-int savage_max_ioctl = DRM_ARRAY_SIZE(savage_ioctls);
diff --git a/drivers/char/drm/savage_drm.h b/drivers/char/drm/savage_drm.h
deleted file mode 100644 (file)
index 8a576ef..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/* savage_drm.h -- Public header for the savage driver
- *
- * Copyright 2004  Felix Kuehling
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __SAVAGE_DRM_H__
-#define __SAVAGE_DRM_H__
-
-#ifndef __SAVAGE_SAREA_DEFINES__
-#define __SAVAGE_SAREA_DEFINES__
-
-/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
- * regions, subject to a minimum region size of (1<<16) == 64k.
- *
- * Clients may subdivide regions internally, but when sharing between
- * clients, the region size is the minimum granularity.
- */
-
-#define SAVAGE_CARD_HEAP               0
-#define SAVAGE_AGP_HEAP                        1
-#define SAVAGE_NR_TEX_HEAPS            2
-#define SAVAGE_NR_TEX_REGIONS          16
-#define SAVAGE_LOG_MIN_TEX_REGION_SIZE 16
-
-#endif                         /* __SAVAGE_SAREA_DEFINES__ */
-
-typedef struct _drm_savage_sarea {
-       /* LRU lists for texture memory in agp space and on the card.
-        */
-       struct drm_tex_region texList[SAVAGE_NR_TEX_HEAPS][SAVAGE_NR_TEX_REGIONS +
-                                                     1];
-       unsigned int texAge[SAVAGE_NR_TEX_HEAPS];
-
-       /* Mechanism to validate card state.
-        */
-       int ctxOwner;
-} drm_savage_sarea_t, *drm_savage_sarea_ptr;
-
-/* Savage-specific ioctls
- */
-#define DRM_SAVAGE_BCI_INIT            0x00
-#define DRM_SAVAGE_BCI_CMDBUF           0x01
-#define DRM_SAVAGE_BCI_EVENT_EMIT      0x02
-#define DRM_SAVAGE_BCI_EVENT_WAIT      0x03
-
-#define DRM_IOCTL_SAVAGE_INIT          DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_INIT, drm_savage_init_t)
-#define DRM_IOCTL_SAVAGE_CMDBUF                DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_CMDBUF, drm_savage_cmdbuf_t)
-#define DRM_IOCTL_SAVAGE_EVENT_EMIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_SAVAGE_BCI_EVENT_EMIT, drm_savage_event_emit_t)
-#define DRM_IOCTL_SAVAGE_EVENT_WAIT    DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_EVENT_WAIT, drm_savage_event_wait_t)
-
-#define SAVAGE_DMA_PCI 1
-#define SAVAGE_DMA_AGP 3
-typedef struct drm_savage_init {
-       enum {
-               SAVAGE_INIT_BCI = 1,
-               SAVAGE_CLEANUP_BCI = 2
-       } func;
-       unsigned int sarea_priv_offset;
-
-       /* some parameters */
-       unsigned int cob_size;
-       unsigned int bci_threshold_lo, bci_threshold_hi;
-       unsigned int dma_type;
-
-       /* frame buffer layout */
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-
-       /* local textures */
-       unsigned int texture_offset;
-       unsigned int texture_size;
-
-       /* physical locations of non-permanent maps */
-       unsigned long status_offset;
-       unsigned long buffers_offset;
-       unsigned long agp_textures_offset;
-       unsigned long cmd_dma_offset;
-} drm_savage_init_t;
-
-typedef union drm_savage_cmd_header drm_savage_cmd_header_t;
-typedef struct drm_savage_cmdbuf {
-       /* command buffer in client's address space */
-       drm_savage_cmd_header_t __user *cmd_addr;
-       unsigned int size;      /* size of the command buffer in 64bit units */
-
-       unsigned int dma_idx;   /* DMA buffer index to use */
-       int discard;            /* discard DMA buffer when done */
-       /* vertex buffer in client's address space */
-       unsigned int __user *vb_addr;
-       unsigned int vb_size;   /* size of client vertex buffer in bytes */
-       unsigned int vb_stride; /* stride of vertices in 32bit words */
-       /* boxes in client's address space */
-       struct drm_clip_rect __user *box_addr;
-       unsigned int nbox;      /* number of clipping boxes */
-} drm_savage_cmdbuf_t;
-
-#define SAVAGE_WAIT_2D  0x1    /* wait for 2D idle before updating event tag */
-#define SAVAGE_WAIT_3D  0x2    /* wait for 3D idle before updating event tag */
-#define SAVAGE_WAIT_IRQ 0x4    /* emit or wait for IRQ, not implemented yet */
-typedef struct drm_savage_event {
-       unsigned int count;
-       unsigned int flags;
-} drm_savage_event_emit_t, drm_savage_event_wait_t;
-
-/* Commands for the cmdbuf ioctl
- */
-#define SAVAGE_CMD_STATE       0       /* a range of state registers */
-#define SAVAGE_CMD_DMA_PRIM    1       /* vertices from DMA buffer */
-#define SAVAGE_CMD_VB_PRIM     2       /* vertices from client vertex buffer */
-#define SAVAGE_CMD_DMA_IDX     3       /* indexed vertices from DMA buffer */
-#define SAVAGE_CMD_VB_IDX      4       /* indexed vertices client vertex buffer */
-#define SAVAGE_CMD_CLEAR       5       /* clear buffers */
-#define SAVAGE_CMD_SWAP                6       /* swap buffers */
-
-/* Primitive types
-*/
-#define SAVAGE_PRIM_TRILIST    0       /* triangle list */
-#define SAVAGE_PRIM_TRISTRIP   1       /* triangle strip */
-#define SAVAGE_PRIM_TRIFAN     2       /* triangle fan */
-#define SAVAGE_PRIM_TRILIST_201        3       /* reorder verts for correct flat
-                                        * shading on s3d */
-
-/* Skip flags (vertex format)
- */
-#define SAVAGE_SKIP_Z          0x01
-#define SAVAGE_SKIP_W          0x02
-#define SAVAGE_SKIP_C0         0x04
-#define SAVAGE_SKIP_C1         0x08
-#define SAVAGE_SKIP_S0         0x10
-#define SAVAGE_SKIP_T0         0x20
-#define SAVAGE_SKIP_ST0                0x30
-#define SAVAGE_SKIP_S1         0x40
-#define SAVAGE_SKIP_T1         0x80
-#define SAVAGE_SKIP_ST1                0xc0
-#define SAVAGE_SKIP_ALL_S3D    0x3f
-#define SAVAGE_SKIP_ALL_S4     0xff
-
-/* Buffer names for clear command
- */
-#define SAVAGE_FRONT           0x1
-#define SAVAGE_BACK            0x2
-#define SAVAGE_DEPTH           0x4
-
-/* 64-bit command header
- */
-union drm_savage_cmd_header {
-       struct {
-               unsigned char cmd;      /* command */
-               unsigned char pad0;
-               unsigned short pad1;
-               unsigned short pad2;
-               unsigned short pad3;
-       } cmd;                  /* generic */
-       struct {
-               unsigned char cmd;
-               unsigned char global;   /* need idle engine? */
-               unsigned short count;   /* number of consecutive registers */
-               unsigned short start;   /* first register */
-               unsigned short pad3;
-       } state;                /* SAVAGE_CMD_STATE */
-       struct {
-               unsigned char cmd;
-               unsigned char prim;     /* primitive type */
-               unsigned short skip;    /* vertex format (skip flags) */
-               unsigned short count;   /* number of vertices */
-               unsigned short start;   /* first vertex in DMA/vertex buffer */
-       } prim;                 /* SAVAGE_CMD_DMA_PRIM, SAVAGE_CMD_VB_PRIM */
-       struct {
-               unsigned char cmd;
-               unsigned char prim;
-               unsigned short skip;
-               unsigned short count;   /* number of indices that follow */
-               unsigned short pad3;
-       } idx;                  /* SAVAGE_CMD_DMA_IDX, SAVAGE_CMD_VB_IDX */
-       struct {
-               unsigned char cmd;
-               unsigned char pad0;
-               unsigned short pad1;
-               unsigned int flags;
-       } clear0;               /* SAVAGE_CMD_CLEAR */
-       struct {
-               unsigned int mask;
-               unsigned int value;
-       } clear1;               /* SAVAGE_CMD_CLEAR data */
-};
-
-#endif
diff --git a/drivers/char/drm/savage_drv.c b/drivers/char/drm/savage_drv.c
deleted file mode 100644 (file)
index eee52aa..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/* savage_drv.c -- Savage driver for Linux
- *
- * Copyright 2004  Felix Kuehling
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "savage_drm.h"
-#include "savage_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       savage_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
-       .dev_priv_size = sizeof(drm_savage_buf_priv_t),
-       .load = savage_driver_load,
-       .firstopen = savage_driver_firstopen,
-       .lastclose = savage_driver_lastclose,
-       .unload = savage_driver_unload,
-       .reclaim_buffers = savage_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = savage_ioctls,
-       .dma_ioctl = savage_bci_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init savage_init(void)
-{
-       driver.num_ioctls = savage_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit savage_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(savage_init);
-module_exit(savage_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/savage_drv.h b/drivers/char/drm/savage_drv.h
deleted file mode 100644 (file)
index df2aac6..0000000
+++ /dev/null
@@ -1,575 +0,0 @@
-/* savage_drv.h -- Private header for the savage driver */
-/*
- * Copyright 2004  Felix Kuehling
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef __SAVAGE_DRV_H__
-#define __SAVAGE_DRV_H__
-
-#define DRIVER_AUTHOR  "Felix Kuehling"
-
-#define DRIVER_NAME    "savage"
-#define DRIVER_DESC    "Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
-#define DRIVER_DATE    "20050313"
-
-#define DRIVER_MAJOR           2
-#define DRIVER_MINOR           4
-#define DRIVER_PATCHLEVEL      1
-/* Interface history:
- *
- * 1.x   The DRM driver from the VIA/S3 code drop, basically a dummy
- * 2.0   The first real DRM
- * 2.1   Scissors registers managed by the DRM, 3D operations clipped by
- *       cliprects of the cmdbuf ioctl
- * 2.2   Implemented SAVAGE_CMD_DMA_IDX and SAVAGE_CMD_VB_IDX
- * 2.3   Event counters used by BCI_EVENT_EMIT/WAIT ioctls are now 32 bits
- *       wide and thus very long lived (unlikely to ever wrap). The size
- *       in the struct was 32 bits before, but only 16 bits were used
- * 2.4   Implemented command DMA. Now drm_savage_init_t.cmd_dma_offset is
- *       actually used
- */
-
-typedef struct drm_savage_age {
-       uint16_t event;
-       unsigned int wrap;
-} drm_savage_age_t;
-
-typedef struct drm_savage_buf_priv {
-       struct drm_savage_buf_priv *next;
-       struct drm_savage_buf_priv *prev;
-       drm_savage_age_t age;
-       struct drm_buf *buf;
-} drm_savage_buf_priv_t;
-
-typedef struct drm_savage_dma_page {
-       drm_savage_age_t age;
-       unsigned int used, flushed;
-} drm_savage_dma_page_t;
-#define SAVAGE_DMA_PAGE_SIZE 1024      /* in dwords */
-/* Fake DMA buffer size in bytes. 4 pages. Allows a maximum command
- * size of 16kbytes or 4k entries. Minimum requirement would be
- * 10kbytes for 255 40-byte vertices in one drawing command. */
-#define SAVAGE_FAKE_DMA_SIZE (SAVAGE_DMA_PAGE_SIZE*4*4)
-
-/* interesting bits of hardware state that are saved in dev_priv */
-typedef union {
-       struct drm_savage_common_state {
-               uint32_t vbaddr;
-       } common;
-       struct {
-               unsigned char pad[sizeof(struct drm_savage_common_state)];
-               uint32_t texctrl, texaddr;
-               uint32_t scstart, new_scstart;
-               uint32_t scend, new_scend;
-       } s3d;
-       struct {
-               unsigned char pad[sizeof(struct drm_savage_common_state)];
-               uint32_t texdescr, texaddr0, texaddr1;
-               uint32_t drawctrl0, new_drawctrl0;
-               uint32_t drawctrl1, new_drawctrl1;
-       } s4;
-} drm_savage_state_t;
-
-/* these chip tags should match the ones in the 2D driver in savage_regs.h. */
-enum savage_family {
-       S3_UNKNOWN = 0,
-       S3_SAVAGE3D,
-       S3_SAVAGE_MX,
-       S3_SAVAGE4,
-       S3_PROSAVAGE,
-       S3_TWISTER,
-       S3_PROSAVAGEDDR,
-       S3_SUPERSAVAGE,
-       S3_SAVAGE2000,
-       S3_LAST
-};
-
-extern struct drm_ioctl_desc savage_ioctls[];
-extern int savage_max_ioctl;
-
-#define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
-
-#define S3_SAVAGE4_SERIES(chip)  ((chip==S3_SAVAGE4)            \
-                                  || (chip==S3_PROSAVAGE)       \
-                                  || (chip==S3_TWISTER)         \
-                                  || (chip==S3_PROSAVAGEDDR))
-
-#define        S3_SAVAGE_MOBILE_SERIES(chip)   ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
-
-#define S3_SAVAGE_SERIES(chip)    ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
-
-#define S3_MOBILE_TWISTER_SERIES(chip)   ((chip==S3_TWISTER)    \
-                                          ||(chip==S3_PROSAVAGEDDR))
-
-/* flags */
-#define SAVAGE_IS_AGP 1
-
-typedef struct drm_savage_private {
-       drm_savage_sarea_t *sarea_priv;
-
-       drm_savage_buf_priv_t head, tail;
-
-       /* who am I? */
-       enum savage_family chipset;
-
-       unsigned int cob_size;
-       unsigned int bci_threshold_lo, bci_threshold_hi;
-       unsigned int dma_type;
-
-       /* frame buffer layout */
-       unsigned int fb_bpp;
-       unsigned int front_offset, front_pitch;
-       unsigned int back_offset, back_pitch;
-       unsigned int depth_bpp;
-       unsigned int depth_offset, depth_pitch;
-
-       /* bitmap descriptors for swap and clear */
-       unsigned int front_bd, back_bd, depth_bd;
-
-       /* local textures */
-       unsigned int texture_offset;
-       unsigned int texture_size;
-
-       /* memory regions in physical memory */
-       drm_local_map_t *sarea;
-       drm_local_map_t *mmio;
-       drm_local_map_t *fb;
-       drm_local_map_t *aperture;
-       drm_local_map_t *status;
-       drm_local_map_t *agp_textures;
-       drm_local_map_t *cmd_dma;
-       drm_local_map_t fake_dma;
-
-       struct {
-               int handle;
-               unsigned long base, size;
-       } mtrr[3];
-
-       /* BCI and status-related stuff */
-       volatile uint32_t *status_ptr, *bci_ptr;
-       uint32_t status_used_mask;
-       uint16_t event_counter;
-       unsigned int event_wrap;
-
-       /* Savage4 command DMA */
-       drm_savage_dma_page_t *dma_pages;
-       unsigned int nr_dma_pages, first_dma_page, current_dma_page;
-       drm_savage_age_t last_dma_age;
-
-       /* saved hw state for global/local check on S3D */
-       uint32_t hw_draw_ctrl, hw_zbuf_ctrl;
-       /* and for scissors (global, so don't emit if not changed) */
-       uint32_t hw_scissors_start, hw_scissors_end;
-
-       drm_savage_state_t state;
-
-       /* after emitting a wait cmd Savage3D needs 63 nops before next DMA */
-       unsigned int waiting;
-
-       /* config/hardware-dependent function pointers */
-       int (*wait_fifo) (struct drm_savage_private * dev_priv, unsigned int n);
-       int (*wait_evnt) (struct drm_savage_private * dev_priv, uint16_t e);
-       /* Err, there is a macro wait_event in include/linux/wait.h.
-        * Avoid unwanted macro expansion. */
-       void (*emit_clip_rect) (struct drm_savage_private * dev_priv,
-                               const struct drm_clip_rect * pbox);
-       void (*dma_flush) (struct drm_savage_private * dev_priv);
-} drm_savage_private_t;
-
-/* ioctls */
-extern int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
-
-/* BCI functions */
-extern uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
-                                     unsigned int flags);
-extern void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf);
-extern void savage_dma_reset(drm_savage_private_t * dev_priv);
-extern void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page);
-extern uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv,
-                                 unsigned int n);
-extern int savage_driver_load(struct drm_device *dev, unsigned long chipset);
-extern int savage_driver_firstopen(struct drm_device *dev);
-extern void savage_driver_lastclose(struct drm_device *dev);
-extern int savage_driver_unload(struct drm_device *dev);
-extern void savage_reclaim_buffers(struct drm_device *dev,
-                                  struct drm_file *file_priv);
-
-/* state functions */
-extern void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
-                                     const struct drm_clip_rect * pbox);
-extern void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
-                                    const struct drm_clip_rect * pbox);
-
-#define SAVAGE_FB_SIZE_S3      0x01000000      /*  16MB */
-#define SAVAGE_FB_SIZE_S4      0x02000000      /*  32MB */
-#define SAVAGE_MMIO_SIZE        0x00080000     /* 512kB */
-#define SAVAGE_APERTURE_OFFSET  0x02000000     /*  32MB */
-#define SAVAGE_APERTURE_SIZE    0x05000000     /* 5 tiled surfaces, 16MB each */
-
-#define SAVAGE_BCI_OFFSET       0x00010000     /* offset of the BCI region
-                                                * inside the MMIO region */
-#define SAVAGE_BCI_FIFO_SIZE   32      /* number of entries in on-chip
-                                        * BCI FIFO */
-
-/*
- * MMIO registers
- */
-#define SAVAGE_STATUS_WORD0            0x48C00
-#define SAVAGE_STATUS_WORD1            0x48C04
-#define SAVAGE_ALT_STATUS_WORD0        0x48C60
-
-#define SAVAGE_FIFO_USED_MASK_S3D      0x0001ffff
-#define SAVAGE_FIFO_USED_MASK_S4       0x001fffff
-
-/* Copied from savage_bci.h in the 2D driver with some renaming. */
-
-/* Bitmap descriptors */
-#define SAVAGE_BD_STRIDE_SHIFT 0
-#define SAVAGE_BD_BPP_SHIFT   16
-#define SAVAGE_BD_TILE_SHIFT  24
-#define SAVAGE_BD_BW_DISABLE  (1<<28)
-/* common: */
-#define        SAVAGE_BD_TILE_LINEAR           0
-/* savage4, MX, IX, 3D */
-#define        SAVAGE_BD_TILE_16BPP            2
-#define        SAVAGE_BD_TILE_32BPP            3
-/* twister, prosavage, DDR, supersavage, 2000 */
-#define        SAVAGE_BD_TILE_DEST             1
-#define        SAVAGE_BD_TILE_TEXTURE          2
-/* GBD - BCI enable */
-/* savage4, MX, IX, 3D */
-#define SAVAGE_GBD_BCI_ENABLE                    8
-/* twister, prosavage, DDR, supersavage, 2000 */
-#define SAVAGE_GBD_BCI_ENABLE_TWISTER            0
-
-#define SAVAGE_GBD_BIG_ENDIAN                    4
-#define SAVAGE_GBD_LITTLE_ENDIAN                 0
-#define SAVAGE_GBD_64                            1
-
-/*  Global Bitmap Descriptor */
-#define SAVAGE_BCI_GLB_BD_LOW             0x8168
-#define SAVAGE_BCI_GLB_BD_HIGH            0x816C
-
-/*
- * BCI registers
- */
-/* Savage4/Twister/ProSavage 3D registers */
-#define SAVAGE_DRAWLOCALCTRL_S4                0x1e
-#define SAVAGE_TEXPALADDR_S4           0x1f
-#define SAVAGE_TEXCTRL0_S4             0x20
-#define SAVAGE_TEXCTRL1_S4             0x21
-#define SAVAGE_TEXADDR0_S4             0x22
-#define SAVAGE_TEXADDR1_S4             0x23
-#define SAVAGE_TEXBLEND0_S4            0x24
-#define SAVAGE_TEXBLEND1_S4            0x25
-#define SAVAGE_TEXXPRCLR_S4            0x26    /* never used */
-#define SAVAGE_TEXDESCR_S4             0x27
-#define SAVAGE_FOGTABLE_S4             0x28
-#define SAVAGE_FOGCTRL_S4              0x30
-#define SAVAGE_STENCILCTRL_S4          0x31
-#define SAVAGE_ZBUFCTRL_S4             0x32
-#define SAVAGE_ZBUFOFF_S4              0x33
-#define SAVAGE_DESTCTRL_S4             0x34
-#define SAVAGE_DRAWCTRL0_S4            0x35
-#define SAVAGE_DRAWCTRL1_S4            0x36
-#define SAVAGE_ZWATERMARK_S4           0x37
-#define SAVAGE_DESTTEXRWWATERMARK_S4   0x38
-#define SAVAGE_TEXBLENDCOLOR_S4                0x39
-/* Savage3D/MX/IX 3D registers */
-#define SAVAGE_TEXPALADDR_S3D          0x18
-#define SAVAGE_TEXXPRCLR_S3D           0x19    /* never used */
-#define SAVAGE_TEXADDR_S3D             0x1A
-#define SAVAGE_TEXDESCR_S3D            0x1B
-#define SAVAGE_TEXCTRL_S3D             0x1C
-#define SAVAGE_FOGTABLE_S3D            0x20
-#define SAVAGE_FOGCTRL_S3D             0x30
-#define SAVAGE_DRAWCTRL_S3D            0x31
-#define SAVAGE_ZBUFCTRL_S3D            0x32
-#define SAVAGE_ZBUFOFF_S3D             0x33
-#define SAVAGE_DESTCTRL_S3D            0x34
-#define SAVAGE_SCSTART_S3D             0x35
-#define SAVAGE_SCEND_S3D               0x36
-#define SAVAGE_ZWATERMARK_S3D          0x37
-#define SAVAGE_DESTTEXRWWATERMARK_S3D  0x38
-/* common stuff */
-#define SAVAGE_VERTBUFADDR             0x3e
-#define SAVAGE_BITPLANEWTMASK          0xd7
-#define SAVAGE_DMABUFADDR              0x51
-
-/* texture enable bits (needed for tex addr checking) */
-#define SAVAGE_TEXCTRL_TEXEN_MASK      0x00010000      /* S3D */
-#define SAVAGE_TEXDESCR_TEX0EN_MASK    0x02000000      /* S4 */
-#define SAVAGE_TEXDESCR_TEX1EN_MASK    0x04000000      /* S4 */
-
-/* Global fields in Savage4/Twister/ProSavage 3D registers:
- *
- * All texture registers and DrawLocalCtrl are local. All other
- * registers are global. */
-
-/* Global fields in Savage3D/MX/IX 3D registers:
- *
- * All texture registers are local. DrawCtrl and ZBufCtrl are
- * partially local. All other registers are global.
- *
- * DrawCtrl global fields: cullMode, alphaTestCmpFunc, alphaTestEn, alphaRefVal
- * ZBufCtrl global fields: zCmpFunc, zBufEn
- */
-#define SAVAGE_DRAWCTRL_S3D_GLOBAL     0x03f3c00c
-#define SAVAGE_ZBUFCTRL_S3D_GLOBAL     0x00000027
-
-/* Masks for scissor bits (drawCtrl[01] on s4, scissorStart/End on s3d)
- */
-#define SAVAGE_SCISSOR_MASK_S4         0x00fff7ff
-#define SAVAGE_SCISSOR_MASK_S3D                0x07ff07ff
-
-/*
- * BCI commands
- */
-#define BCI_CMD_NOP                  0x40000000
-#define BCI_CMD_RECT                 0x48000000
-#define BCI_CMD_RECT_XP              0x01000000
-#define BCI_CMD_RECT_YP              0x02000000
-#define BCI_CMD_SCANLINE             0x50000000
-#define BCI_CMD_LINE                 0x5C000000
-#define BCI_CMD_LINE_LAST_PIXEL      0x58000000
-#define BCI_CMD_BYTE_TEXT            0x63000000
-#define BCI_CMD_NT_BYTE_TEXT         0x67000000
-#define BCI_CMD_BIT_TEXT             0x6C000000
-#define BCI_CMD_GET_ROP(cmd)         (((cmd) >> 16) & 0xFF)
-#define BCI_CMD_SET_ROP(cmd, rop)    ((cmd) |= ((rop & 0xFF) << 16))
-#define BCI_CMD_SEND_COLOR           0x00008000
-
-#define BCI_CMD_CLIP_NONE            0x00000000
-#define BCI_CMD_CLIP_CURRENT         0x00002000
-#define BCI_CMD_CLIP_LR              0x00004000
-#define BCI_CMD_CLIP_NEW             0x00006000
-
-#define BCI_CMD_DEST_GBD             0x00000000
-#define BCI_CMD_DEST_PBD             0x00000800
-#define BCI_CMD_DEST_PBD_NEW         0x00000C00
-#define BCI_CMD_DEST_SBD             0x00001000
-#define BCI_CMD_DEST_SBD_NEW         0x00001400
-
-#define BCI_CMD_SRC_TRANSPARENT      0x00000200
-#define BCI_CMD_SRC_SOLID            0x00000000
-#define BCI_CMD_SRC_GBD              0x00000020
-#define BCI_CMD_SRC_COLOR            0x00000040
-#define BCI_CMD_SRC_MONO             0x00000060
-#define BCI_CMD_SRC_PBD_COLOR        0x00000080
-#define BCI_CMD_SRC_PBD_MONO         0x000000A0
-#define BCI_CMD_SRC_PBD_COLOR_NEW    0x000000C0
-#define BCI_CMD_SRC_PBD_MONO_NEW     0x000000E0
-#define BCI_CMD_SRC_SBD_COLOR        0x00000100
-#define BCI_CMD_SRC_SBD_MONO         0x00000120
-#define BCI_CMD_SRC_SBD_COLOR_NEW    0x00000140
-#define BCI_CMD_SRC_SBD_MONO_NEW     0x00000160
-
-#define BCI_CMD_PAT_TRANSPARENT      0x00000010
-#define BCI_CMD_PAT_NONE             0x00000000
-#define BCI_CMD_PAT_COLOR            0x00000002
-#define BCI_CMD_PAT_MONO             0x00000003
-#define BCI_CMD_PAT_PBD_COLOR        0x00000004
-#define BCI_CMD_PAT_PBD_MONO         0x00000005
-#define BCI_CMD_PAT_PBD_COLOR_NEW    0x00000006
-#define BCI_CMD_PAT_PBD_MONO_NEW     0x00000007
-#define BCI_CMD_PAT_SBD_COLOR        0x00000008
-#define BCI_CMD_PAT_SBD_MONO         0x00000009
-#define BCI_CMD_PAT_SBD_COLOR_NEW    0x0000000A
-#define BCI_CMD_PAT_SBD_MONO_NEW     0x0000000B
-
-#define BCI_BD_BW_DISABLE            0x10000000
-#define BCI_BD_TILE_MASK             0x03000000
-#define BCI_BD_TILE_NONE             0x00000000
-#define BCI_BD_TILE_16               0x02000000
-#define BCI_BD_TILE_32               0x03000000
-#define BCI_BD_GET_BPP(bd)           (((bd) >> 16) & 0xFF)
-#define BCI_BD_SET_BPP(bd, bpp)      ((bd) |= (((bpp) & 0xFF) << 16))
-#define BCI_BD_GET_STRIDE(bd)        ((bd) & 0xFFFF)
-#define BCI_BD_SET_STRIDE(bd, st)    ((bd) |= ((st) & 0xFFFF))
-
-#define BCI_CMD_SET_REGISTER            0x96000000
-
-#define BCI_CMD_WAIT                    0xC0000000
-#define BCI_CMD_WAIT_3D                 0x00010000
-#define BCI_CMD_WAIT_2D                 0x00020000
-
-#define BCI_CMD_UPDATE_EVENT_TAG        0x98000000
-
-#define BCI_CMD_DRAW_PRIM               0x80000000
-#define BCI_CMD_DRAW_INDEXED_PRIM       0x88000000
-#define BCI_CMD_DRAW_CONT               0x01000000
-#define BCI_CMD_DRAW_TRILIST            0x00000000
-#define BCI_CMD_DRAW_TRISTRIP           0x02000000
-#define BCI_CMD_DRAW_TRIFAN             0x04000000
-#define BCI_CMD_DRAW_SKIPFLAGS          0x000000ff
-#define BCI_CMD_DRAW_NO_Z              0x00000001
-#define BCI_CMD_DRAW_NO_W              0x00000002
-#define BCI_CMD_DRAW_NO_CD             0x00000004
-#define BCI_CMD_DRAW_NO_CS             0x00000008
-#define BCI_CMD_DRAW_NO_U0             0x00000010
-#define BCI_CMD_DRAW_NO_V0             0x00000020
-#define BCI_CMD_DRAW_NO_UV0            0x00000030
-#define BCI_CMD_DRAW_NO_U1             0x00000040
-#define BCI_CMD_DRAW_NO_V1             0x00000080
-#define BCI_CMD_DRAW_NO_UV1            0x000000c0
-
-#define BCI_CMD_DMA                    0xa8000000
-
-#define BCI_W_H(w, h)                ((((h) << 16) | (w)) & 0x0FFF0FFF)
-#define BCI_X_Y(x, y)                ((((y) << 16) | (x)) & 0x0FFF0FFF)
-#define BCI_X_W(x, y)                ((((w) << 16) | (x)) & 0x0FFF0FFF)
-#define BCI_CLIP_LR(l, r)            ((((r) << 16) | (l)) & 0x0FFF0FFF)
-#define BCI_CLIP_TL(t, l)            ((((t) << 16) | (l)) & 0x0FFF0FFF)
-#define BCI_CLIP_BR(b, r)            ((((b) << 16) | (r)) & 0x0FFF0FFF)
-
-#define BCI_LINE_X_Y(x, y)           (((y) << 16) | ((x) & 0xFFFF))
-#define BCI_LINE_STEPS(diag, axi)    (((axi) << 16) | ((diag) & 0xFFFF))
-#define BCI_LINE_MISC(maj, ym, xp, yp, err) \
-       (((maj) & 0x1FFF) | \
-       ((ym) ? 1<<13 : 0) | \
-       ((xp) ? 1<<14 : 0) | \
-       ((yp) ? 1<<15 : 0) | \
-       ((err) << 16))
-
-/*
- * common commands
- */
-#define BCI_SET_REGISTERS( first, n )                  \
-       BCI_WRITE(BCI_CMD_SET_REGISTER |                \
-                 ((uint32_t)(n) & 0xff) << 16 |        \
-                 ((uint32_t)(first) & 0xffff))
-#define DMA_SET_REGISTERS( first, n )                  \
-       DMA_WRITE(BCI_CMD_SET_REGISTER |                \
-                 ((uint32_t)(n) & 0xff) << 16 |        \
-                 ((uint32_t)(first) & 0xffff))
-
-#define BCI_DRAW_PRIMITIVE(n, type, skip)         \
-        BCI_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
-                 ((n) << 16))
-#define DMA_DRAW_PRIMITIVE(n, type, skip)         \
-        DMA_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
-                 ((n) << 16))
-
-#define BCI_DRAW_INDICES_S3D(n, type, i0)         \
-        BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
-                 ((n) << 16) | (i0))
-
-#define BCI_DRAW_INDICES_S4(n, type, skip)        \
-        BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
-                  (skip) | ((n) << 16))
-
-#define BCI_DMA(n)     \
-       BCI_WRITE(BCI_CMD_DMA | (((n) >> 1) - 1))
-
-/*
- * access to MMIO
- */
-#define SAVAGE_READ(reg)       DRM_READ32(  dev_priv->mmio, (reg) )
-#define SAVAGE_WRITE(reg)      DRM_WRITE32( dev_priv->mmio, (reg) )
-
-/*
- * access to the burst command interface (BCI)
- */
-#define SAVAGE_BCI_DEBUG 1
-
-#define BCI_LOCALS    volatile uint32_t *bci_ptr;
-
-#define BEGIN_BCI( n ) do {                    \
-       dev_priv->wait_fifo(dev_priv, (n));     \
-       bci_ptr = dev_priv->bci_ptr;            \
-} while(0)
-
-#define BCI_WRITE( val ) *bci_ptr++ = (uint32_t)(val)
-
-/*
- * command DMA support
- */
-#define SAVAGE_DMA_DEBUG 1
-
-#define DMA_LOCALS   uint32_t *dma_ptr;
-
-#define BEGIN_DMA( n ) do {                                            \
-       unsigned int cur = dev_priv->current_dma_page;                  \
-       unsigned int rest = SAVAGE_DMA_PAGE_SIZE -                      \
-               dev_priv->dma_pages[cur].used;                          \
-       if ((n) > rest) {                                               \
-               dma_ptr = savage_dma_alloc(dev_priv, (n));              \
-       } else { /* fast path for small allocations */                  \
-               dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle +       \
-                       cur * SAVAGE_DMA_PAGE_SIZE +                    \
-                       dev_priv->dma_pages[cur].used;                  \
-               if (dev_priv->dma_pages[cur].used == 0)                 \
-                       savage_dma_wait(dev_priv, cur);                 \
-               dev_priv->dma_pages[cur].used += (n);                   \
-       }                                                               \
-} while(0)
-
-#define DMA_WRITE( val ) *dma_ptr++ = (uint32_t)(val)
-
-#define DMA_COPY(src, n) do {                                  \
-       memcpy(dma_ptr, (src), (n)*4);                          \
-       dma_ptr += n;                                           \
-} while(0)
-
-#if SAVAGE_DMA_DEBUG
-#define DMA_COMMIT() do {                                              \
-       unsigned int cur = dev_priv->current_dma_page;                  \
-       uint32_t *expected = (uint32_t *)dev_priv->cmd_dma->handle +    \
-                       cur * SAVAGE_DMA_PAGE_SIZE +                    \
-                       dev_priv->dma_pages[cur].used;                  \
-       if (dma_ptr != expected) {                                      \
-               DRM_ERROR("DMA allocation and use don't match: "        \
-                         "%p != %p\n", expected, dma_ptr);             \
-               savage_dma_reset(dev_priv);                             \
-       }                                                               \
-} while(0)
-#else
-#define DMA_COMMIT() do {/* nothing */} while(0)
-#endif
-
-#define DMA_FLUSH() dev_priv->dma_flush(dev_priv)
-
-/* Buffer aging via event tag
- */
-
-#define UPDATE_EVENT_COUNTER( ) do {                   \
-       if (dev_priv->status_ptr) {                     \
-               uint16_t count;                         \
-               /* coordinate with Xserver */           \
-               count = dev_priv->status_ptr[1023];     \
-               if (count < dev_priv->event_counter)    \
-                       dev_priv->event_wrap++;         \
-               dev_priv->event_counter = count;        \
-       }                                               \
-} while(0)
-
-#define SET_AGE( age, e, w ) do {      \
-       (age)->event = e;               \
-       (age)->wrap = w;                \
-} while(0)
-
-#define TEST_AGE( age, e, w )                          \
-       ( (age)->wrap < (w) || ( (age)->wrap == (w) && (age)->event <= (e) ) )
-
-#endif                         /* __SAVAGE_DRV_H__ */
diff --git a/drivers/char/drm/savage_state.c b/drivers/char/drm/savage_state.c
deleted file mode 100644 (file)
index 5f6238f..0000000
+++ /dev/null
@@ -1,1163 +0,0 @@
-/* savage_state.c -- State and drawing support for Savage
- *
- * Copyright 2004  Felix Kuehling
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-#include "drmP.h"
-#include "savage_drm.h"
-#include "savage_drv.h"
-
-void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
-                              const struct drm_clip_rect * pbox)
-{
-       uint32_t scstart = dev_priv->state.s3d.new_scstart;
-       uint32_t scend = dev_priv->state.s3d.new_scend;
-       scstart = (scstart & ~SAVAGE_SCISSOR_MASK_S3D) |
-           ((uint32_t) pbox->x1 & 0x000007ff) |
-           (((uint32_t) pbox->y1 << 16) & 0x07ff0000);
-       scend = (scend & ~SAVAGE_SCISSOR_MASK_S3D) |
-           (((uint32_t) pbox->x2 - 1) & 0x000007ff) |
-           ((((uint32_t) pbox->y2 - 1) << 16) & 0x07ff0000);
-       if (scstart != dev_priv->state.s3d.scstart ||
-           scend != dev_priv->state.s3d.scend) {
-               DMA_LOCALS;
-               BEGIN_DMA(4);
-               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
-               DMA_SET_REGISTERS(SAVAGE_SCSTART_S3D, 2);
-               DMA_WRITE(scstart);
-               DMA_WRITE(scend);
-               dev_priv->state.s3d.scstart = scstart;
-               dev_priv->state.s3d.scend = scend;
-               dev_priv->waiting = 1;
-               DMA_COMMIT();
-       }
-}
-
-void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
-                             const struct drm_clip_rect * pbox)
-{
-       uint32_t drawctrl0 = dev_priv->state.s4.new_drawctrl0;
-       uint32_t drawctrl1 = dev_priv->state.s4.new_drawctrl1;
-       drawctrl0 = (drawctrl0 & ~SAVAGE_SCISSOR_MASK_S4) |
-           ((uint32_t) pbox->x1 & 0x000007ff) |
-           (((uint32_t) pbox->y1 << 12) & 0x00fff000);
-       drawctrl1 = (drawctrl1 & ~SAVAGE_SCISSOR_MASK_S4) |
-           (((uint32_t) pbox->x2 - 1) & 0x000007ff) |
-           ((((uint32_t) pbox->y2 - 1) << 12) & 0x00fff000);
-       if (drawctrl0 != dev_priv->state.s4.drawctrl0 ||
-           drawctrl1 != dev_priv->state.s4.drawctrl1) {
-               DMA_LOCALS;
-               BEGIN_DMA(4);
-               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
-               DMA_SET_REGISTERS(SAVAGE_DRAWCTRL0_S4, 2);
-               DMA_WRITE(drawctrl0);
-               DMA_WRITE(drawctrl1);
-               dev_priv->state.s4.drawctrl0 = drawctrl0;
-               dev_priv->state.s4.drawctrl1 = drawctrl1;
-               dev_priv->waiting = 1;
-               DMA_COMMIT();
-       }
-}
-
-static int savage_verify_texaddr(drm_savage_private_t * dev_priv, int unit,
-                                uint32_t addr)
-{
-       if ((addr & 6) != 2) {  /* reserved bits */
-               DRM_ERROR("bad texAddr%d %08x (reserved bits)\n", unit, addr);
-               return -EINVAL;
-       }
-       if (!(addr & 1)) {      /* local */
-               addr &= ~7;
-               if (addr < dev_priv->texture_offset ||
-                   addr >= dev_priv->texture_offset + dev_priv->texture_size) {
-                       DRM_ERROR
-                           ("bad texAddr%d %08x (local addr out of range)\n",
-                            unit, addr);
-                       return -EINVAL;
-               }
-       } else {                /* AGP */
-               if (!dev_priv->agp_textures) {
-                       DRM_ERROR("bad texAddr%d %08x (AGP not available)\n",
-                                 unit, addr);
-                       return -EINVAL;
-               }
-               addr &= ~7;
-               if (addr < dev_priv->agp_textures->offset ||
-                   addr >= (dev_priv->agp_textures->offset +
-                            dev_priv->agp_textures->size)) {
-                       DRM_ERROR
-                           ("bad texAddr%d %08x (AGP addr out of range)\n",
-                            unit, addr);
-                       return -EINVAL;
-               }
-       }
-       return 0;
-}
-
-#define SAVE_STATE(reg,where)                  \
-       if(start <= reg && start+count > reg)   \
-               dev_priv->state.where = regs[reg - start]
-#define SAVE_STATE_MASK(reg,where,mask) do {                   \
-       if(start <= reg && start+count > reg) {                 \
-               uint32_t tmp;                                   \
-               tmp = regs[reg - start];                        \
-               dev_priv->state.where = (tmp & (mask)) |        \
-                       (dev_priv->state.where & ~(mask));      \
-       }                                                       \
-} while (0)
-
-static int savage_verify_state_s3d(drm_savage_private_t * dev_priv,
-                                  unsigned int start, unsigned int count,
-                                  const uint32_t *regs)
-{
-       if (start < SAVAGE_TEXPALADDR_S3D ||
-           start + count - 1 > SAVAGE_DESTTEXRWWATERMARK_S3D) {
-               DRM_ERROR("invalid register range (0x%04x-0x%04x)\n",
-                         start, start + count - 1);
-               return -EINVAL;
-       }
-
-       SAVE_STATE_MASK(SAVAGE_SCSTART_S3D, s3d.new_scstart,
-                       ~SAVAGE_SCISSOR_MASK_S3D);
-       SAVE_STATE_MASK(SAVAGE_SCEND_S3D, s3d.new_scend,
-                       ~SAVAGE_SCISSOR_MASK_S3D);
-
-       /* if any texture regs were changed ... */
-       if (start <= SAVAGE_TEXCTRL_S3D &&
-           start + count > SAVAGE_TEXPALADDR_S3D) {
-               /* ... check texture state */
-               SAVE_STATE(SAVAGE_TEXCTRL_S3D, s3d.texctrl);
-               SAVE_STATE(SAVAGE_TEXADDR_S3D, s3d.texaddr);
-               if (dev_priv->state.s3d.texctrl & SAVAGE_TEXCTRL_TEXEN_MASK)
-                       return savage_verify_texaddr(dev_priv, 0,
-                                               dev_priv->state.s3d.texaddr);
-       }
-
-       return 0;
-}
-
-static int savage_verify_state_s4(drm_savage_private_t * dev_priv,
-                                 unsigned int start, unsigned int count,
-                                 const uint32_t *regs)
-{
-       int ret = 0;
-
-       if (start < SAVAGE_DRAWLOCALCTRL_S4 ||
-           start + count - 1 > SAVAGE_TEXBLENDCOLOR_S4) {
-               DRM_ERROR("invalid register range (0x%04x-0x%04x)\n",
-                         start, start + count - 1);
-               return -EINVAL;
-       }
-
-       SAVE_STATE_MASK(SAVAGE_DRAWCTRL0_S4, s4.new_drawctrl0,
-                       ~SAVAGE_SCISSOR_MASK_S4);
-       SAVE_STATE_MASK(SAVAGE_DRAWCTRL1_S4, s4.new_drawctrl1,
-                       ~SAVAGE_SCISSOR_MASK_S4);
-
-       /* if any texture regs were changed ... */
-       if (start <= SAVAGE_TEXDESCR_S4 &&
-           start + count > SAVAGE_TEXPALADDR_S4) {
-               /* ... check texture state */
-               SAVE_STATE(SAVAGE_TEXDESCR_S4, s4.texdescr);
-               SAVE_STATE(SAVAGE_TEXADDR0_S4, s4.texaddr0);
-               SAVE_STATE(SAVAGE_TEXADDR1_S4, s4.texaddr1);
-               if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX0EN_MASK)
-                       ret |= savage_verify_texaddr(dev_priv, 0,
-                                               dev_priv->state.s4.texaddr0);
-               if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX1EN_MASK)
-                       ret |= savage_verify_texaddr(dev_priv, 1,
-                                               dev_priv->state.s4.texaddr1);
-       }
-
-       return ret;
-}
-
-#undef SAVE_STATE
-#undef SAVE_STATE_MASK
-
-static int savage_dispatch_state(drm_savage_private_t * dev_priv,
-                                const drm_savage_cmd_header_t * cmd_header,
-                                const uint32_t *regs)
-{
-       unsigned int count = cmd_header->state.count;
-       unsigned int start = cmd_header->state.start;
-       unsigned int count2 = 0;
-       unsigned int bci_size;
-       int ret;
-       DMA_LOCALS;
-
-       if (!count)
-               return 0;
-
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               ret = savage_verify_state_s3d(dev_priv, start, count, regs);
-               if (ret != 0)
-                       return ret;
-               /* scissor regs are emitted in savage_dispatch_draw */
-               if (start < SAVAGE_SCSTART_S3D) {
-                       if (start + count > SAVAGE_SCEND_S3D + 1)
-                               count2 = count - (SAVAGE_SCEND_S3D + 1 - start);
-                       if (start + count > SAVAGE_SCSTART_S3D)
-                               count = SAVAGE_SCSTART_S3D - start;
-               } else if (start <= SAVAGE_SCEND_S3D) {
-                       if (start + count > SAVAGE_SCEND_S3D + 1) {
-                               count -= SAVAGE_SCEND_S3D + 1 - start;
-                               start = SAVAGE_SCEND_S3D + 1;
-                       } else
-                               return 0;
-               }
-       } else {
-               ret = savage_verify_state_s4(dev_priv, start, count, regs);
-               if (ret != 0)
-                       return ret;
-               /* scissor regs are emitted in savage_dispatch_draw */
-               if (start < SAVAGE_DRAWCTRL0_S4) {
-                       if (start + count > SAVAGE_DRAWCTRL1_S4 + 1)
-                               count2 = count -
-                                        (SAVAGE_DRAWCTRL1_S4 + 1 - start);
-                       if (start + count > SAVAGE_DRAWCTRL0_S4)
-                               count = SAVAGE_DRAWCTRL0_S4 - start;
-               } else if (start <= SAVAGE_DRAWCTRL1_S4) {
-                       if (start + count > SAVAGE_DRAWCTRL1_S4 + 1) {
-                               count -= SAVAGE_DRAWCTRL1_S4 + 1 - start;
-                               start = SAVAGE_DRAWCTRL1_S4 + 1;
-                       } else
-                               return 0;
-               }
-       }
-
-       bci_size = count + (count + 254) / 255 + count2 + (count2 + 254) / 255;
-
-       if (cmd_header->state.global) {
-               BEGIN_DMA(bci_size + 1);
-               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
-               dev_priv->waiting = 1;
-       } else {
-               BEGIN_DMA(bci_size);
-       }
-
-       do {
-               while (count > 0) {
-                       unsigned int n = count < 255 ? count : 255;
-                       DMA_SET_REGISTERS(start, n);
-                       DMA_COPY(regs, n);
-                       count -= n;
-                       start += n;
-                       regs += n;
-               }
-               start += 2;
-               regs += 2;
-               count = count2;
-               count2 = 0;
-       } while (count);
-
-       DMA_COMMIT();
-
-       return 0;
-}
-
-static int savage_dispatch_dma_prim(drm_savage_private_t * dev_priv,
-                                   const drm_savage_cmd_header_t * cmd_header,
-                                   const struct drm_buf * dmabuf)
-{
-       unsigned char reorder = 0;
-       unsigned int prim = cmd_header->prim.prim;
-       unsigned int skip = cmd_header->prim.skip;
-       unsigned int n = cmd_header->prim.count;
-       unsigned int start = cmd_header->prim.start;
-       unsigned int i;
-       BCI_LOCALS;
-
-       if (!dmabuf) {
-               DRM_ERROR("called without dma buffers!\n");
-               return -EINVAL;
-       }
-
-       if (!n)
-               return 0;
-
-       switch (prim) {
-       case SAVAGE_PRIM_TRILIST_201:
-               reorder = 1;
-               prim = SAVAGE_PRIM_TRILIST;
-       case SAVAGE_PRIM_TRILIST:
-               if (n % 3 != 0) {
-                       DRM_ERROR("wrong number of vertices %u in TRILIST\n",
-                                 n);
-                       return -EINVAL;
-               }
-               break;
-       case SAVAGE_PRIM_TRISTRIP:
-       case SAVAGE_PRIM_TRIFAN:
-               if (n < 3) {
-                       DRM_ERROR
-                           ("wrong number of vertices %u in TRIFAN/STRIP\n",
-                            n);
-                       return -EINVAL;
-               }
-               break;
-       default:
-               DRM_ERROR("invalid primitive type %u\n", prim);
-               return -EINVAL;
-       }
-
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               if (skip != 0) {
-                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
-                       return -EINVAL;
-               }
-       } else {
-               unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) -
-                   (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) -
-                   (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1);
-               if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) {
-                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
-                       return -EINVAL;
-               }
-               if (reorder) {
-                       DRM_ERROR("TRILIST_201 used on Savage4 hardware\n");
-                       return -EINVAL;
-               }
-       }
-
-       if (start + n > dmabuf->total / 32) {
-               DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n",
-                         start, start + n - 1, dmabuf->total / 32);
-               return -EINVAL;
-       }
-
-       /* Vertex DMA doesn't work with command DMA at the same time,
-        * so we use BCI_... to submit commands here. Flush buffered
-        * faked DMA first. */
-       DMA_FLUSH();
-
-       if (dmabuf->bus_address != dev_priv->state.common.vbaddr) {
-               BEGIN_BCI(2);
-               BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1);
-               BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type);
-               dev_priv->state.common.vbaddr = dmabuf->bus_address;
-       }
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) {
-               /* Workaround for what looks like a hardware bug. If a
-                * WAIT_3D_IDLE was emitted some time before the
-                * indexed drawing command then the engine will lock
-                * up. There are two known workarounds:
-                * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */
-               BEGIN_BCI(63);
-               for (i = 0; i < 63; ++i)
-                       BCI_WRITE(BCI_CMD_WAIT);
-               dev_priv->waiting = 0;
-       }
-
-       prim <<= 25;
-       while (n != 0) {
-               /* Can emit up to 255 indices (85 triangles) at once. */
-               unsigned int count = n > 255 ? 255 : n;
-               if (reorder) {
-                       /* Need to reorder indices for correct flat
-                        * shading while preserving the clock sense
-                        * for correct culling. Only on Savage3D. */
-                       int reorder[3] = { -1, -1, -1 };
-                       reorder[start % 3] = 2;
-
-                       BEGIN_BCI((count + 1 + 1) / 2);
-                       BCI_DRAW_INDICES_S3D(count, prim, start + 2);
-
-                       for (i = start + 1; i + 1 < start + count; i += 2)
-                               BCI_WRITE((i + reorder[i % 3]) |
-                                         ((i + 1 +
-                                           reorder[(i + 1) % 3]) << 16));
-                       if (i < start + count)
-                               BCI_WRITE(i + reorder[i % 3]);
-               } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-                       BEGIN_BCI((count + 1 + 1) / 2);
-                       BCI_DRAW_INDICES_S3D(count, prim, start);
-
-                       for (i = start + 1; i + 1 < start + count; i += 2)
-                               BCI_WRITE(i | ((i + 1) << 16));
-                       if (i < start + count)
-                               BCI_WRITE(i);
-               } else {
-                       BEGIN_BCI((count + 2 + 1) / 2);
-                       BCI_DRAW_INDICES_S4(count, prim, skip);
-
-                       for (i = start; i + 1 < start + count; i += 2)
-                               BCI_WRITE(i | ((i + 1) << 16));
-                       if (i < start + count)
-                               BCI_WRITE(i);
-               }
-
-               start += count;
-               n -= count;
-
-               prim |= BCI_CMD_DRAW_CONT;
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_vb_prim(drm_savage_private_t * dev_priv,
-                                  const drm_savage_cmd_header_t * cmd_header,
-                                  const uint32_t *vtxbuf, unsigned int vb_size,
-                                  unsigned int vb_stride)
-{
-       unsigned char reorder = 0;
-       unsigned int prim = cmd_header->prim.prim;
-       unsigned int skip = cmd_header->prim.skip;
-       unsigned int n = cmd_header->prim.count;
-       unsigned int start = cmd_header->prim.start;
-       unsigned int vtx_size;
-       unsigned int i;
-       DMA_LOCALS;
-
-       if (!n)
-               return 0;
-
-       switch (prim) {
-       case SAVAGE_PRIM_TRILIST_201:
-               reorder = 1;
-               prim = SAVAGE_PRIM_TRILIST;
-       case SAVAGE_PRIM_TRILIST:
-               if (n % 3 != 0) {
-                       DRM_ERROR("wrong number of vertices %u in TRILIST\n",
-                                 n);
-                       return -EINVAL;
-               }
-               break;
-       case SAVAGE_PRIM_TRISTRIP:
-       case SAVAGE_PRIM_TRIFAN:
-               if (n < 3) {
-                       DRM_ERROR
-                           ("wrong number of vertices %u in TRIFAN/STRIP\n",
-                            n);
-                       return -EINVAL;
-               }
-               break;
-       default:
-               DRM_ERROR("invalid primitive type %u\n", prim);
-               return -EINVAL;
-       }
-
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               if (skip > SAVAGE_SKIP_ALL_S3D) {
-                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
-                       return -EINVAL;
-               }
-               vtx_size = 8;   /* full vertex */
-       } else {
-               if (skip > SAVAGE_SKIP_ALL_S4) {
-                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
-                       return -EINVAL;
-               }
-               vtx_size = 10;  /* full vertex */
-       }
-
-       vtx_size -= (skip & 1) + (skip >> 1 & 1) +
-           (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) +
-           (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1);
-
-       if (vtx_size > vb_stride) {
-               DRM_ERROR("vertex size greater than vb stride (%u > %u)\n",
-                         vtx_size, vb_stride);
-               return -EINVAL;
-       }
-
-       if (start + n > vb_size / (vb_stride * 4)) {
-               DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n",
-                         start, start + n - 1, vb_size / (vb_stride * 4));
-               return -EINVAL;
-       }
-
-       prim <<= 25;
-       while (n != 0) {
-               /* Can emit up to 255 vertices (85 triangles) at once. */
-               unsigned int count = n > 255 ? 255 : n;
-               if (reorder) {
-                       /* Need to reorder vertices for correct flat
-                        * shading while preserving the clock sense
-                        * for correct culling. Only on Savage3D. */
-                       int reorder[3] = { -1, -1, -1 };
-                       reorder[start % 3] = 2;
-
-                       BEGIN_DMA(count * vtx_size + 1);
-                       DMA_DRAW_PRIMITIVE(count, prim, skip);
-
-                       for (i = start; i < start + count; ++i) {
-                               unsigned int j = i + reorder[i % 3];
-                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
-                       }
-
-                       DMA_COMMIT();
-               } else {
-                       BEGIN_DMA(count * vtx_size + 1);
-                       DMA_DRAW_PRIMITIVE(count, prim, skip);
-
-                       if (vb_stride == vtx_size) {
-                               DMA_COPY(&vtxbuf[vb_stride * start],
-                                        vtx_size * count);
-                       } else {
-                               for (i = start; i < start + count; ++i) {
-                                       DMA_COPY(&vtxbuf [vb_stride * i],
-                                                vtx_size);
-                               }
-                       }
-
-                       DMA_COMMIT();
-               }
-
-               start += count;
-               n -= count;
-
-               prim |= BCI_CMD_DRAW_CONT;
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_dma_idx(drm_savage_private_t * dev_priv,
-                                  const drm_savage_cmd_header_t * cmd_header,
-                                  const uint16_t *idx,
-                                  const struct drm_buf * dmabuf)
-{
-       unsigned char reorder = 0;
-       unsigned int prim = cmd_header->idx.prim;
-       unsigned int skip = cmd_header->idx.skip;
-       unsigned int n = cmd_header->idx.count;
-       unsigned int i;
-       BCI_LOCALS;
-
-       if (!dmabuf) {
-               DRM_ERROR("called without dma buffers!\n");
-               return -EINVAL;
-       }
-
-       if (!n)
-               return 0;
-
-       switch (prim) {
-       case SAVAGE_PRIM_TRILIST_201:
-               reorder = 1;
-               prim = SAVAGE_PRIM_TRILIST;
-       case SAVAGE_PRIM_TRILIST:
-               if (n % 3 != 0) {
-                       DRM_ERROR("wrong number of indices %u in TRILIST\n", n);
-                       return -EINVAL;
-               }
-               break;
-       case SAVAGE_PRIM_TRISTRIP:
-       case SAVAGE_PRIM_TRIFAN:
-               if (n < 3) {
-                       DRM_ERROR
-                           ("wrong number of indices %u in TRIFAN/STRIP\n", n);
-                       return -EINVAL;
-               }
-               break;
-       default:
-               DRM_ERROR("invalid primitive type %u\n", prim);
-               return -EINVAL;
-       }
-
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               if (skip != 0) {
-                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
-                       return -EINVAL;
-               }
-       } else {
-               unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) -
-                   (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) -
-                   (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1);
-               if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) {
-                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
-                       return -EINVAL;
-               }
-               if (reorder) {
-                       DRM_ERROR("TRILIST_201 used on Savage4 hardware\n");
-                       return -EINVAL;
-               }
-       }
-
-       /* Vertex DMA doesn't work with command DMA at the same time,
-        * so we use BCI_... to submit commands here. Flush buffered
-        * faked DMA first. */
-       DMA_FLUSH();
-
-       if (dmabuf->bus_address != dev_priv->state.common.vbaddr) {
-               BEGIN_BCI(2);
-               BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1);
-               BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type);
-               dev_priv->state.common.vbaddr = dmabuf->bus_address;
-       }
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) {
-               /* Workaround for what looks like a hardware bug. If a
-                * WAIT_3D_IDLE was emitted some time before the
-                * indexed drawing command then the engine will lock
-                * up. There are two known workarounds:
-                * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */
-               BEGIN_BCI(63);
-               for (i = 0; i < 63; ++i)
-                       BCI_WRITE(BCI_CMD_WAIT);
-               dev_priv->waiting = 0;
-       }
-
-       prim <<= 25;
-       while (n != 0) {
-               /* Can emit up to 255 indices (85 triangles) at once. */
-               unsigned int count = n > 255 ? 255 : n;
-
-               /* check indices */
-               for (i = 0; i < count; ++i) {
-                       if (idx[i] > dmabuf->total / 32) {
-                               DRM_ERROR("idx[%u]=%u out of range (0-%u)\n",
-                                         i, idx[i], dmabuf->total / 32);
-                               return -EINVAL;
-                       }
-               }
-
-               if (reorder) {
-                       /* Need to reorder indices for correct flat
-                        * shading while preserving the clock sense
-                        * for correct culling. Only on Savage3D. */
-                       int reorder[3] = { 2, -1, -1 };
-
-                       BEGIN_BCI((count + 1 + 1) / 2);
-                       BCI_DRAW_INDICES_S3D(count, prim, idx[2]);
-
-                       for (i = 1; i + 1 < count; i += 2)
-                               BCI_WRITE(idx[i + reorder[i % 3]] |
-                                         (idx[i + 1 +
-                                          reorder[(i + 1) % 3]] << 16));
-                       if (i < count)
-                               BCI_WRITE(idx[i + reorder[i % 3]]);
-               } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-                       BEGIN_BCI((count + 1 + 1) / 2);
-                       BCI_DRAW_INDICES_S3D(count, prim, idx[0]);
-
-                       for (i = 1; i + 1 < count; i += 2)
-                               BCI_WRITE(idx[i] | (idx[i + 1] << 16));
-                       if (i < count)
-                               BCI_WRITE(idx[i]);
-               } else {
-                       BEGIN_BCI((count + 2 + 1) / 2);
-                       BCI_DRAW_INDICES_S4(count, prim, skip);
-
-                       for (i = 0; i + 1 < count; i += 2)
-                               BCI_WRITE(idx[i] | (idx[i + 1] << 16));
-                       if (i < count)
-                               BCI_WRITE(idx[i]);
-               }
-
-               idx += count;
-               n -= count;
-
-               prim |= BCI_CMD_DRAW_CONT;
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_vb_idx(drm_savage_private_t * dev_priv,
-                                 const drm_savage_cmd_header_t * cmd_header,
-                                 const uint16_t *idx,
-                                 const uint32_t *vtxbuf,
-                                 unsigned int vb_size, unsigned int vb_stride)
-{
-       unsigned char reorder = 0;
-       unsigned int prim = cmd_header->idx.prim;
-       unsigned int skip = cmd_header->idx.skip;
-       unsigned int n = cmd_header->idx.count;
-       unsigned int vtx_size;
-       unsigned int i;
-       DMA_LOCALS;
-
-       if (!n)
-               return 0;
-
-       switch (prim) {
-       case SAVAGE_PRIM_TRILIST_201:
-               reorder = 1;
-               prim = SAVAGE_PRIM_TRILIST;
-       case SAVAGE_PRIM_TRILIST:
-               if (n % 3 != 0) {
-                       DRM_ERROR("wrong number of indices %u in TRILIST\n", n);
-                       return -EINVAL;
-               }
-               break;
-       case SAVAGE_PRIM_TRISTRIP:
-       case SAVAGE_PRIM_TRIFAN:
-               if (n < 3) {
-                       DRM_ERROR
-                           ("wrong number of indices %u in TRIFAN/STRIP\n", n);
-                       return -EINVAL;
-               }
-               break;
-       default:
-               DRM_ERROR("invalid primitive type %u\n", prim);
-               return -EINVAL;
-       }
-
-       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
-               if (skip > SAVAGE_SKIP_ALL_S3D) {
-                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
-                       return -EINVAL;
-               }
-               vtx_size = 8;   /* full vertex */
-       } else {
-               if (skip > SAVAGE_SKIP_ALL_S4) {
-                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
-                       return -EINVAL;
-               }
-               vtx_size = 10;  /* full vertex */
-       }
-
-       vtx_size -= (skip & 1) + (skip >> 1 & 1) +
-           (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) +
-           (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1);
-
-       if (vtx_size > vb_stride) {
-               DRM_ERROR("vertex size greater than vb stride (%u > %u)\n",
-                         vtx_size, vb_stride);
-               return -EINVAL;
-       }
-
-       prim <<= 25;
-       while (n != 0) {
-               /* Can emit up to 255 vertices (85 triangles) at once. */
-               unsigned int count = n > 255 ? 255 : n;
-
-               /* Check indices */
-               for (i = 0; i < count; ++i) {
-                       if (idx[i] > vb_size / (vb_stride * 4)) {
-                               DRM_ERROR("idx[%u]=%u out of range (0-%u)\n",
-                                         i, idx[i], vb_size / (vb_stride * 4));
-                               return -EINVAL;
-                       }
-               }
-
-               if (reorder) {
-                       /* Need to reorder vertices for correct flat
-                        * shading while preserving the clock sense
-                        * for correct culling. Only on Savage3D. */
-                       int reorder[3] = { 2, -1, -1 };
-
-                       BEGIN_DMA(count * vtx_size + 1);
-                       DMA_DRAW_PRIMITIVE(count, prim, skip);
-
-                       for (i = 0; i < count; ++i) {
-                               unsigned int j = idx[i + reorder[i % 3]];
-                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
-                       }
-
-                       DMA_COMMIT();
-               } else {
-                       BEGIN_DMA(count * vtx_size + 1);
-                       DMA_DRAW_PRIMITIVE(count, prim, skip);
-
-                       for (i = 0; i < count; ++i) {
-                               unsigned int j = idx[i];
-                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
-                       }
-
-                       DMA_COMMIT();
-               }
-
-               idx += count;
-               n -= count;
-
-               prim |= BCI_CMD_DRAW_CONT;
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_clear(drm_savage_private_t * dev_priv,
-                                const drm_savage_cmd_header_t * cmd_header,
-                                const drm_savage_cmd_header_t *data,
-                                unsigned int nbox,
-                                const struct drm_clip_rect *boxes)
-{
-       unsigned int flags = cmd_header->clear0.flags;
-       unsigned int clear_cmd;
-       unsigned int i, nbufs;
-       DMA_LOCALS;
-
-       if (nbox == 0)
-               return 0;
-
-       clear_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
-           BCI_CMD_SEND_COLOR | BCI_CMD_DEST_PBD_NEW;
-       BCI_CMD_SET_ROP(clear_cmd, 0xCC);
-
-       nbufs = ((flags & SAVAGE_FRONT) ? 1 : 0) +
-           ((flags & SAVAGE_BACK) ? 1 : 0) + ((flags & SAVAGE_DEPTH) ? 1 : 0);
-       if (nbufs == 0)
-               return 0;
-
-       if (data->clear1.mask != 0xffffffff) {
-               /* set mask */
-               BEGIN_DMA(2);
-               DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1);
-               DMA_WRITE(data->clear1.mask);
-               DMA_COMMIT();
-       }
-       for (i = 0; i < nbox; ++i) {
-               unsigned int x, y, w, h;
-               unsigned int buf;
-               x = boxes[i].x1, y = boxes[i].y1;
-               w = boxes[i].x2 - boxes[i].x1;
-               h = boxes[i].y2 - boxes[i].y1;
-               BEGIN_DMA(nbufs * 6);
-               for (buf = SAVAGE_FRONT; buf <= SAVAGE_DEPTH; buf <<= 1) {
-                       if (!(flags & buf))
-                               continue;
-                       DMA_WRITE(clear_cmd);
-                       switch (buf) {
-                       case SAVAGE_FRONT:
-                               DMA_WRITE(dev_priv->front_offset);
-                               DMA_WRITE(dev_priv->front_bd);
-                               break;
-                       case SAVAGE_BACK:
-                               DMA_WRITE(dev_priv->back_offset);
-                               DMA_WRITE(dev_priv->back_bd);
-                               break;
-                       case SAVAGE_DEPTH:
-                               DMA_WRITE(dev_priv->depth_offset);
-                               DMA_WRITE(dev_priv->depth_bd);
-                               break;
-                       }
-                       DMA_WRITE(data->clear1.value);
-                       DMA_WRITE(BCI_X_Y(x, y));
-                       DMA_WRITE(BCI_W_H(w, h));
-               }
-               DMA_COMMIT();
-       }
-       if (data->clear1.mask != 0xffffffff) {
-               /* reset mask */
-               BEGIN_DMA(2);
-               DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1);
-               DMA_WRITE(0xffffffff);
-               DMA_COMMIT();
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_swap(drm_savage_private_t * dev_priv,
-                               unsigned int nbox, const struct drm_clip_rect *boxes)
-{
-       unsigned int swap_cmd;
-       unsigned int i;
-       DMA_LOCALS;
-
-       if (nbox == 0)
-               return 0;
-
-       swap_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
-           BCI_CMD_SRC_PBD_COLOR_NEW | BCI_CMD_DEST_GBD;
-       BCI_CMD_SET_ROP(swap_cmd, 0xCC);
-
-       for (i = 0; i < nbox; ++i) {
-               BEGIN_DMA(6);
-               DMA_WRITE(swap_cmd);
-               DMA_WRITE(dev_priv->back_offset);
-               DMA_WRITE(dev_priv->back_bd);
-               DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1));
-               DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1));
-               DMA_WRITE(BCI_W_H(boxes[i].x2 - boxes[i].x1,
-                                 boxes[i].y2 - boxes[i].y1));
-               DMA_COMMIT();
-       }
-
-       return 0;
-}
-
-static int savage_dispatch_draw(drm_savage_private_t * dev_priv,
-                               const drm_savage_cmd_header_t *start,
-                               const drm_savage_cmd_header_t *end,
-                               const struct drm_buf * dmabuf,
-                               const unsigned int *vtxbuf,
-                               unsigned int vb_size, unsigned int vb_stride,
-                               unsigned int nbox,
-                               const struct drm_clip_rect *boxes)
-{
-       unsigned int i, j;
-       int ret;
-
-       for (i = 0; i < nbox; ++i) {
-               const drm_savage_cmd_header_t *cmdbuf;
-               dev_priv->emit_clip_rect(dev_priv, &boxes[i]);
-
-               cmdbuf = start;
-               while (cmdbuf < end) {
-                       drm_savage_cmd_header_t cmd_header;
-                       cmd_header = *cmdbuf;
-                       cmdbuf++;
-                       switch (cmd_header.cmd.cmd) {
-                       case SAVAGE_CMD_DMA_PRIM:
-                               ret = savage_dispatch_dma_prim(
-                                       dev_priv, &cmd_header, dmabuf);
-                               break;
-                       case SAVAGE_CMD_VB_PRIM:
-                               ret = savage_dispatch_vb_prim(
-                                       dev_priv, &cmd_header,
-                                       vtxbuf, vb_size, vb_stride);
-                               break;
-                       case SAVAGE_CMD_DMA_IDX:
-                               j = (cmd_header.idx.count + 3) / 4;
-                               /* j was check in savage_bci_cmdbuf */
-                               ret = savage_dispatch_dma_idx(dev_priv,
-                                       &cmd_header, (const uint16_t *)cmdbuf,
-                                       dmabuf);
-                               cmdbuf += j;
-                               break;
-                       case SAVAGE_CMD_VB_IDX:
-                               j = (cmd_header.idx.count + 3) / 4;
-                               /* j was check in savage_bci_cmdbuf */
-                               ret = savage_dispatch_vb_idx(dev_priv,
-                                       &cmd_header, (const uint16_t *)cmdbuf,
-                                       (const uint32_t *)vtxbuf, vb_size,
-                                       vb_stride);
-                               cmdbuf += j;
-                               break;
-                       default:
-                               /* What's the best return code? EFAULT? */
-                               DRM_ERROR("IMPLEMENTATION ERROR: "
-                                         "non-drawing-command %d\n",
-                                         cmd_header.cmd.cmd);
-                               return -EINVAL;
-                       }
-
-                       if (ret != 0)
-                               return ret;
-               }
-       }
-
-       return 0;
-}
-
-int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_savage_private_t *dev_priv = dev->dev_private;
-       struct drm_device_dma *dma = dev->dma;
-       struct drm_buf *dmabuf;
-       drm_savage_cmdbuf_t *cmdbuf = data;
-       drm_savage_cmd_header_t *kcmd_addr = NULL;
-       drm_savage_cmd_header_t *first_draw_cmd;
-       unsigned int *kvb_addr = NULL;
-       struct drm_clip_rect *kbox_addr = NULL;
-       unsigned int i, j;
-       int ret = 0;
-
-       DRM_DEBUG("\n");
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       if (dma && dma->buflist) {
-               if (cmdbuf->dma_idx > dma->buf_count) {
-                       DRM_ERROR
-                           ("vertex buffer index %u out of range (0-%u)\n",
-                            cmdbuf->dma_idx, dma->buf_count - 1);
-                       return -EINVAL;
-               }
-               dmabuf = dma->buflist[cmdbuf->dma_idx];
-       } else {
-               dmabuf = NULL;
-       }
-
-       /* Copy the user buffers into kernel temporary areas.  This hasn't been
-        * a performance loss compared to VERIFYAREA_READ/
-        * COPY_FROM_USER_UNCHECKED when done in other drivers, and is correct
-        * for locking on FreeBSD.
-        */
-       if (cmdbuf->size) {
-               kcmd_addr = drm_alloc(cmdbuf->size * 8, DRM_MEM_DRIVER);
-               if (kcmd_addr == NULL)
-                       return -ENOMEM;
-
-               if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf->cmd_addr,
-                                      cmdbuf->size * 8))
-               {
-                       drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
-                       return -EFAULT;
-               }
-               cmdbuf->cmd_addr = kcmd_addr;
-       }
-       if (cmdbuf->vb_size) {
-               kvb_addr = drm_alloc(cmdbuf->vb_size, DRM_MEM_DRIVER);
-               if (kvb_addr == NULL) {
-                       ret = -ENOMEM;
-                       goto done;
-               }
-
-               if (DRM_COPY_FROM_USER(kvb_addr, cmdbuf->vb_addr,
-                                      cmdbuf->vb_size)) {
-                       ret = -EFAULT;
-                       goto done;
-               }
-               cmdbuf->vb_addr = kvb_addr;
-       }
-       if (cmdbuf->nbox) {
-               kbox_addr = drm_alloc(cmdbuf->nbox * sizeof(struct drm_clip_rect),
-                                      DRM_MEM_DRIVER);
-               if (kbox_addr == NULL) {
-                       ret = -ENOMEM;
-                       goto done;
-               }
-
-               if (DRM_COPY_FROM_USER(kbox_addr, cmdbuf->box_addr,
-                                      cmdbuf->nbox * sizeof(struct drm_clip_rect))) {
-                       ret = -EFAULT;
-                       goto done;
-               }
-       cmdbuf->box_addr = kbox_addr;
-       }
-
-       /* Make sure writes to DMA buffers are finished before sending
-        * DMA commands to the graphics hardware. */
-       DRM_MEMORYBARRIER();
-
-       /* Coming from user space. Don't know if the Xserver has
-        * emitted wait commands. Assuming the worst. */
-       dev_priv->waiting = 1;
-
-       i = 0;
-       first_draw_cmd = NULL;
-       while (i < cmdbuf->size) {
-               drm_savage_cmd_header_t cmd_header;
-               cmd_header = *(drm_savage_cmd_header_t *)cmdbuf->cmd_addr;
-               cmdbuf->cmd_addr++;
-               i++;
-
-               /* Group drawing commands with same state to minimize
-                * iterations over clip rects. */
-               j = 0;
-               switch (cmd_header.cmd.cmd) {
-               case SAVAGE_CMD_DMA_IDX:
-               case SAVAGE_CMD_VB_IDX:
-                       j = (cmd_header.idx.count + 3) / 4;
-                       if (i + j > cmdbuf->size) {
-                               DRM_ERROR("indexed drawing command extends "
-                                         "beyond end of command buffer\n");
-                               DMA_FLUSH();
-                               return -EINVAL;
-                       }
-                       /* fall through */
-               case SAVAGE_CMD_DMA_PRIM:
-               case SAVAGE_CMD_VB_PRIM:
-                       if (!first_draw_cmd)
-                               first_draw_cmd = cmdbuf->cmd_addr - 1;
-                       cmdbuf->cmd_addr += j;
-                       i += j;
-                       break;
-               default:
-                       if (first_draw_cmd) {
-                               ret = savage_dispatch_draw(
-                                     dev_priv, first_draw_cmd,
-                                     cmdbuf->cmd_addr - 1,
-                                     dmabuf, cmdbuf->vb_addr, cmdbuf->vb_size,
-                                     cmdbuf->vb_stride,
-                                     cmdbuf->nbox, cmdbuf->box_addr);
-                               if (ret != 0)
-                                       return ret;
-                               first_draw_cmd = NULL;
-                       }
-               }
-               if (first_draw_cmd)
-                       continue;
-
-               switch (cmd_header.cmd.cmd) {
-               case SAVAGE_CMD_STATE:
-                       j = (cmd_header.state.count + 1) / 2;
-                       if (i + j > cmdbuf->size) {
-                               DRM_ERROR("command SAVAGE_CMD_STATE extends "
-                                         "beyond end of command buffer\n");
-                               DMA_FLUSH();
-                               ret = -EINVAL;
-                               goto done;
-                       }
-                       ret = savage_dispatch_state(dev_priv, &cmd_header,
-                               (const uint32_t *)cmdbuf->cmd_addr);
-                       cmdbuf->cmd_addr += j;
-                       i += j;
-                       break;
-               case SAVAGE_CMD_CLEAR:
-                       if (i + 1 > cmdbuf->size) {
-                               DRM_ERROR("command SAVAGE_CMD_CLEAR extends "
-                                         "beyond end of command buffer\n");
-                               DMA_FLUSH();
-                               ret = -EINVAL;
-                               goto done;
-                       }
-                       ret = savage_dispatch_clear(dev_priv, &cmd_header,
-                                                   cmdbuf->cmd_addr,
-                                                   cmdbuf->nbox,
-                                                   cmdbuf->box_addr);
-                       cmdbuf->cmd_addr++;
-                       i++;
-                       break;
-               case SAVAGE_CMD_SWAP:
-                       ret = savage_dispatch_swap(dev_priv, cmdbuf->nbox,
-                                                  cmdbuf->box_addr);
-                       break;
-               default:
-                       DRM_ERROR("invalid command 0x%x\n",
-                                 cmd_header.cmd.cmd);
-                       DMA_FLUSH();
-                       ret = -EINVAL;
-                       goto done;
-               }
-
-               if (ret != 0) {
-                       DMA_FLUSH();
-                       goto done;
-               }
-       }
-
-       if (first_draw_cmd) {
-               ret = savage_dispatch_draw (
-                       dev_priv, first_draw_cmd, cmdbuf->cmd_addr, dmabuf,
-                       cmdbuf->vb_addr, cmdbuf->vb_size, cmdbuf->vb_stride,
-                       cmdbuf->nbox, cmdbuf->box_addr);
-               if (ret != 0) {
-                       DMA_FLUSH();
-                       goto done;
-               }
-       }
-
-       DMA_FLUSH();
-
-       if (dmabuf && cmdbuf->discard) {
-               drm_savage_buf_priv_t *buf_priv = dmabuf->dev_private;
-               uint16_t event;
-               event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
-               SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
-               savage_freelist_put(dev, dmabuf);
-       }
-
-done:
-       /* If we didn't need to allocate them, these'll be NULL */
-       drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
-       drm_free(kvb_addr, cmdbuf->vb_size, DRM_MEM_DRIVER);
-       drm_free(kbox_addr, cmdbuf->nbox * sizeof(struct drm_clip_rect),
-                DRM_MEM_DRIVER);
-
-       return ret;
-}
diff --git a/drivers/char/drm/sis_drm.h b/drivers/char/drm/sis_drm.h
deleted file mode 100644 (file)
index 30f7b38..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* sis_drv.h -- Private header for sis driver -*- linux-c -*- */
-/*
- * Copyright 2005 Eric Anholt
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- */
-
-#ifndef __SIS_DRM_H__
-#define __SIS_DRM_H__
-
-/* SiS specific ioctls */
-#define NOT_USED_0_3
-#define DRM_SIS_FB_ALLOC       0x04
-#define DRM_SIS_FB_FREE                0x05
-#define NOT_USED_6_12
-#define DRM_SIS_AGP_INIT       0x13
-#define DRM_SIS_AGP_ALLOC      0x14
-#define DRM_SIS_AGP_FREE       0x15
-#define DRM_SIS_FB_INIT                0x16
-
-#define DRM_IOCTL_SIS_FB_ALLOC         DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_FB_ALLOC, drm_sis_mem_t)
-#define DRM_IOCTL_SIS_FB_FREE          DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_FB_FREE, drm_sis_mem_t)
-#define DRM_IOCTL_SIS_AGP_INIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_AGP_INIT, drm_sis_agp_t)
-#define DRM_IOCTL_SIS_AGP_ALLOC                DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_AGP_ALLOC, drm_sis_mem_t)
-#define DRM_IOCTL_SIS_AGP_FREE         DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_AGP_FREE, drm_sis_mem_t)
-#define DRM_IOCTL_SIS_FB_INIT          DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_FB_INIT, drm_sis_fb_t)
-/*
-#define DRM_IOCTL_SIS_FLIP             DRM_IOW( 0x48, drm_sis_flip_t)
-#define DRM_IOCTL_SIS_FLIP_INIT                DRM_IO(  0x49)
-#define DRM_IOCTL_SIS_FLIP_FINAL       DRM_IO(  0x50)
-*/
-
-typedef struct {
-       int context;
-       unsigned int offset;
-       unsigned int size;
-       unsigned long free;
-} drm_sis_mem_t;
-
-typedef struct {
-       unsigned int offset, size;
-} drm_sis_agp_t;
-
-typedef struct {
-       unsigned int offset, size;
-} drm_sis_fb_t;
-
-#endif                         /* __SIS_DRM_H__ */
diff --git a/drivers/char/drm/sis_drv.c b/drivers/char/drm/sis_drv.c
deleted file mode 100644 (file)
index 7dacc64..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/* sis.c -- sis driver -*- linux-c -*-
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "drmP.h"
-#include "sis_drm.h"
-#include "sis_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       sisdrv_PCI_IDS
-};
-
-static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
-{
-       drm_sis_private_t *dev_priv;
-       int ret;
-
-       dev_priv = drm_calloc(1, sizeof(drm_sis_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       dev->dev_private = (void *)dev_priv;
-       dev_priv->chipset = chipset;
-       ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
-       if (ret) {
-               drm_free(dev_priv, sizeof(dev_priv), DRM_MEM_DRIVER);
-       }
-
-       return ret;
-}
-
-static int sis_driver_unload(struct drm_device *dev)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-
-       drm_sman_takedown(&dev_priv->sman);
-       drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
-
-       return 0;
-}
-
-static struct drm_driver driver = {
-       .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
-       .load = sis_driver_load,
-       .unload = sis_driver_unload,
-       .context_dtor = NULL,
-       .dma_quiescent = sis_idle,
-       .reclaim_buffers = NULL,
-       .reclaim_buffers_idlelocked = sis_reclaim_buffers_locked,
-       .lastclose = sis_lastclose,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = sis_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init sis_init(void)
-{
-       driver.num_ioctls = sis_max_ioctl;
-       return drm_init(&driver);
-}
-
-static void __exit sis_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(sis_init);
-module_exit(sis_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/sis_drv.h b/drivers/char/drm/sis_drv.h
deleted file mode 100644 (file)
index ef940ba..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* sis_drv.h -- Private header for sis driver -*- linux-c -*- */
-/*
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef _SIS_DRV_H_
-#define _SIS_DRV_H_
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "SIS, Tungsten Graphics"
-#define DRIVER_NAME            "sis"
-#define DRIVER_DESC            "SIS 300/630/540 and XGI V3XE/V5/V8"
-#define DRIVER_DATE            "20070626"
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           3
-#define DRIVER_PATCHLEVEL      0
-
-enum sis_family {
-       SIS_OTHER = 0,
-       SIS_CHIP_315 = 1,
-};
-
-#include "drm_sman.h"
-
-
-#define SIS_BASE (dev_priv->mmio)
-#define SIS_READ(reg)         DRM_READ32(SIS_BASE, reg);
-#define SIS_WRITE(reg, val)   DRM_WRITE32(SIS_BASE, reg, val);
-
-typedef struct drm_sis_private {
-       drm_local_map_t *mmio;
-       unsigned int idle_fault;
-       struct drm_sman sman;
-       unsigned int chipset;
-       int vram_initialized;
-       int agp_initialized;
-       unsigned long vram_offset;
-       unsigned long agp_offset;
-} drm_sis_private_t;
-
-extern int sis_idle(struct drm_device *dev);
-extern void sis_reclaim_buffers_locked(struct drm_device *dev,
-                                      struct drm_file *file_priv);
-extern void sis_lastclose(struct drm_device *dev);
-
-extern struct drm_ioctl_desc sis_ioctls[];
-extern int sis_max_ioctl;
-
-#endif
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c
deleted file mode 100644 (file)
index b387877..0000000
+++ /dev/null
@@ -1,333 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- *
- **************************************************************************/
-
-/*
- * Authors:
- *    Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include "sis_drm.h"
-#include "sis_drv.h"
-
-#include <video/sisfb.h>
-
-#define VIDEO_TYPE 0
-#define AGP_TYPE 1
-
-
-#if defined(CONFIG_FB_SIS)
-/* fb management via fb device */
-
-#define SIS_MM_ALIGN_SHIFT 0
-#define SIS_MM_ALIGN_MASK 0
-
-static void *sis_sman_mm_allocate(void *private, unsigned long size,
-                                 unsigned alignment)
-{
-       struct sis_memreq req;
-
-       req.size = size;
-       sis_malloc(&req);
-       if (req.size == 0)
-               return NULL;
-       else
-               return (void *)~req.offset;
-}
-
-static void sis_sman_mm_free(void *private, void *ref)
-{
-       sis_free(~((unsigned long)ref));
-}
-
-static void sis_sman_mm_destroy(void *private)
-{
-       ;
-}
-
-static unsigned long sis_sman_mm_offset(void *private, void *ref)
-{
-       return ~((unsigned long)ref);
-}
-
-#else /* CONFIG_FB_SIS */
-
-#define SIS_MM_ALIGN_SHIFT 4
-#define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1)
-
-#endif /* CONFIG_FB_SIS */
-
-static int sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-       drm_sis_fb_t *fb = data;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-#if defined(CONFIG_FB_SIS)
-       {
-               struct drm_sman_mm sman_mm;
-               sman_mm.private = (void *)0xFFFFFFFF;
-               sman_mm.allocate = sis_sman_mm_allocate;
-               sman_mm.free = sis_sman_mm_free;
-               sman_mm.destroy = sis_sman_mm_destroy;
-               sman_mm.offset = sis_sman_mm_offset;
-               ret =
-                   drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm);
-       }
-#else
-       ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0,
-                                fb->size >> SIS_MM_ALIGN_SHIFT);
-#endif
-
-       if (ret) {
-               DRM_ERROR("VRAM memory manager initialisation error\n");
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       dev_priv->vram_initialized = 1;
-       dev_priv->vram_offset = fb->offset;
-
-       mutex_unlock(&dev->struct_mutex);
-       DRM_DEBUG("offset = %u, size = %u\n", fb->offset, fb->size);
-
-       return 0;
-}
-
-static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file_priv,
-                        void *data, int pool)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-       drm_sis_mem_t *mem = data;
-       int retval = 0;
-       struct drm_memblock_item *item;
-
-       mutex_lock(&dev->struct_mutex);
-
-       if (0 == ((pool == 0) ? dev_priv->vram_initialized :
-                     dev_priv->agp_initialized)) {
-               DRM_ERROR
-                   ("Attempt to allocate from uninitialized memory manager.\n");
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
-       item = drm_sman_alloc(&dev_priv->sman, pool, mem->size, 0,
-                             (unsigned long)file_priv);
-
-       mutex_unlock(&dev->struct_mutex);
-       if (item) {
-               mem->offset = ((pool == 0) ?
-                             dev_priv->vram_offset : dev_priv->agp_offset) +
-                   (item->mm->
-                    offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
-               mem->free = item->user_hash.key;
-               mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
-       } else {
-               mem->offset = 0;
-               mem->size = 0;
-               mem->free = 0;
-               retval = -ENOMEM;
-       }
-
-       DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem->size,
-                 mem->offset);
-
-       return retval;
-}
-
-static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-       drm_sis_mem_t *mem = data;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_sman_free_key(&dev_priv->sman, mem->free);
-       mutex_unlock(&dev->struct_mutex);
-       DRM_DEBUG("free = 0x%lx\n", mem->free);
-
-       return ret;
-}
-
-static int sis_fb_alloc(struct drm_device *dev, void *data,
-                       struct drm_file *file_priv)
-{
-       return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE);
-}
-
-static int sis_ioctl_agp_init(struct drm_device *dev, void *data,
-                             struct drm_file *file_priv)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-       drm_sis_agp_t *agp = data;
-       int ret;
-       dev_priv = dev->dev_private;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0,
-                                agp->size >> SIS_MM_ALIGN_SHIFT);
-
-       if (ret) {
-               DRM_ERROR("AGP memory manager initialisation error\n");
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       dev_priv->agp_initialized = 1;
-       dev_priv->agp_offset = agp->offset;
-       mutex_unlock(&dev->struct_mutex);
-
-       DRM_DEBUG("offset = %u, size = %u\n", agp->offset, agp->size);
-       return 0;
-}
-
-static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data,
-                              struct drm_file *file_priv)
-{
-
-       return sis_drm_alloc(dev, file_priv, data, AGP_TYPE);
-}
-
-static drm_local_map_t *sis_reg_init(struct drm_device *dev)
-{
-       struct drm_map_list *entry;
-       drm_local_map_t *map;
-
-       list_for_each_entry(entry, &dev->maplist, head) {
-               map = entry->map;
-               if (!map)
-                       continue;
-               if (map->type == _DRM_REGISTERS) {
-                       return map;
-               }
-       }
-       return NULL;
-}
-
-int sis_idle(struct drm_device *dev)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-       uint32_t idle_reg;
-       unsigned long end;
-       int i;
-
-       if (dev_priv->idle_fault)
-               return 0;
-
-       if (dev_priv->mmio == NULL) {
-               dev_priv->mmio = sis_reg_init(dev);
-               if (dev_priv->mmio == NULL) {
-                       DRM_ERROR("Could not find register map.\n");
-                       return 0;
-               }
-       }
-
-       /*
-        * Implement a device switch here if needed
-        */
-
-       if (dev_priv->chipset != SIS_CHIP_315)
-               return 0;
-
-       /*
-        * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
-        * because its polling frequency is too low.
-        */
-
-       end = jiffies + (DRM_HZ * 3);
-
-       for (i=0; i<4; ++i) {
-               do {
-                       idle_reg = SIS_READ(0x85cc);
-               } while ( !time_after_eq(jiffies, end) &&
-                         ((idle_reg & 0x80000000) != 0x80000000));
-       }
-
-       if (time_after_eq(jiffies, end)) {
-               DRM_ERROR("Graphics engine idle timeout. "
-                         "Disabling idle check\n");
-               dev_priv->idle_fault = 1;
-       }
-
-       /*
-        * The caller never sees an error code. It gets trapped
-        * in libdrm.
-        */
-
-       return 0;
-}
-
-
-void sis_lastclose(struct drm_device *dev)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-
-       if (!dev_priv)
-               return;
-
-       mutex_lock(&dev->struct_mutex);
-       drm_sman_cleanup(&dev_priv->sman);
-       dev_priv->vram_initialized = 0;
-       dev_priv->agp_initialized = 0;
-       dev_priv->mmio = NULL;
-       mutex_unlock(&dev->struct_mutex);
-}
-
-void sis_reclaim_buffers_locked(struct drm_device * dev,
-                               struct drm_file *file_priv)
-{
-       drm_sis_private_t *dev_priv = dev->dev_private;
-
-       mutex_lock(&dev->struct_mutex);
-       if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) {
-               mutex_unlock(&dev->struct_mutex);
-               return;
-       }
-
-       if (dev->driver->dma_quiescent) {
-               dev->driver->dma_quiescent(dev);
-       }
-
-       drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv);
-       mutex_unlock(&dev->struct_mutex);
-       return;
-}
-
-struct drm_ioctl_desc sis_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SIS_FB_FREE, sis_drm_free, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
-       DRM_IOCTL_DEF(DRM_SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SIS_AGP_FREE, sis_drm_free, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_SIS_FB_INIT, sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
-};
-
-int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls);
diff --git a/drivers/char/drm/tdfx_drv.c b/drivers/char/drm/tdfx_drv.c
deleted file mode 100644 (file)
index 012ff2e..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* tdfx_drv.c -- tdfx driver -*- linux-c -*-
- * Created: Thu Oct  7 10:38:32 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Rickard E. (Rik) Faith <faith@valinux.com>
- *    Daryll Strauss <daryll@valinux.com>
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#include "drmP.h"
-#include "tdfx_drv.h"
-
-#include "drm_pciids.h"
-
-static struct pci_device_id pciidlist[] = {
-       tdfx_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features = DRIVER_USE_MTRR,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init tdfx_init(void)
-{
-       return drm_init(&driver);
-}
-
-static void __exit tdfx_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(tdfx_init);
-module_exit(tdfx_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/tdfx_drv.h b/drivers/char/drm/tdfx_drv.h
deleted file mode 100644 (file)
index 84204ec..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* tdfx.h -- 3dfx DRM template customization -*- linux-c -*-
- * Created: Wed Feb 14 12:32:32 2001 by gareth@valinux.com
- */
-/*
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Gareth Hughes <gareth@valinux.com>
- */
-
-#ifndef __TDFX_H__
-#define __TDFX_H__
-
-/* General customization:
- */
-
-#define DRIVER_AUTHOR          "VA Linux Systems Inc."
-
-#define DRIVER_NAME            "tdfx"
-#define DRIVER_DESC            "3dfx Banshee/Voodoo3+"
-#define DRIVER_DATE            "20010216"
-
-#define DRIVER_MAJOR           1
-#define DRIVER_MINOR           0
-#define DRIVER_PATCHLEVEL      0
-
-#endif
diff --git a/drivers/char/drm/via_3d_reg.h b/drivers/char/drm/via_3d_reg.h
deleted file mode 100644 (file)
index 462375d..0000000
+++ /dev/null
@@ -1,1650 +0,0 @@
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef VIA_3D_REG_H
-#define VIA_3D_REG_H
-#define HC_REG_BASE             0x0400
-
-#define HC_REG_TRANS_SPACE      0x0040
-
-#define HC_ParaN_MASK           0xffffffff
-#define HC_Para_MASK            0x00ffffff
-#define HC_SubA_MASK            0xff000000
-#define HC_SubA_SHIFT           24
-/* Transmission Setting
- */
-#define HC_REG_TRANS_SET        0x003c
-#define HC_ParaSubType_MASK     0xff000000
-#define HC_ParaType_MASK        0x00ff0000
-#define HC_ParaOS_MASK          0x0000ff00
-#define HC_ParaAdr_MASK         0x000000ff
-#define HC_ParaSubType_SHIFT    24
-#define HC_ParaType_SHIFT       16
-#define HC_ParaOS_SHIFT         8
-#define HC_ParaAdr_SHIFT        0
-
-#define HC_ParaType_CmdVdata    0x0000
-#define HC_ParaType_NotTex      0x0001
-#define HC_ParaType_Tex         0x0002
-#define HC_ParaType_Palette     0x0003
-#define HC_ParaType_PreCR       0x0010
-#define HC_ParaType_Auto        0x00fe
-
-/* Transmission Space
- */
-#define HC_REG_Hpara0           0x0040
-#define HC_REG_HpataAF          0x02fc
-
-/* Read
- */
-#define HC_REG_HREngSt          0x0000
-#define HC_REG_HRFIFOempty      0x0004
-#define HC_REG_HRFIFOfull       0x0008
-#define HC_REG_HRErr            0x000c
-#define HC_REG_FIFOstatus       0x0010
-/* HC_REG_HREngSt          0x0000
- */
-#define HC_HDASZC_MASK          0x00010000
-#define HC_HSGEMI_MASK          0x0000f000
-#define HC_HLGEMISt_MASK        0x00000f00
-#define HC_HCRSt_MASK           0x00000080
-#define HC_HSE0St_MASK          0x00000040
-#define HC_HSE1St_MASK          0x00000020
-#define HC_HPESt_MASK           0x00000010
-#define HC_HXESt_MASK           0x00000008
-#define HC_HBESt_MASK           0x00000004
-#define HC_HE2St_MASK           0x00000002
-#define HC_HE3St_MASK           0x00000001
-/* HC_REG_HRFIFOempty      0x0004
- */
-#define HC_HRZDempty_MASK       0x00000010
-#define HC_HRTXAempty_MASK      0x00000008
-#define HC_HRTXDempty_MASK      0x00000004
-#define HC_HWZDempty_MASK       0x00000002
-#define HC_HWCDempty_MASK       0x00000001
-/* HC_REG_HRFIFOfull       0x0008
- */
-#define HC_HRZDfull_MASK        0x00000010
-#define HC_HRTXAfull_MASK       0x00000008
-#define HC_HRTXDfull_MASK       0x00000004
-#define HC_HWZDfull_MASK        0x00000002
-#define HC_HWCDfull_MASK        0x00000001
-/* HC_REG_HRErr            0x000c
- */
-#define HC_HAGPCMErr_MASK       0x80000000
-#define HC_HAGPCMErrC_MASK      0x70000000
-/* HC_REG_FIFOstatus       0x0010
- */
-#define HC_HRFIFOATall_MASK     0x80000000
-#define HC_HRFIFOATbusy_MASK    0x40000000
-#define HC_HRATFGMDo_MASK       0x00000100
-#define HC_HRATFGMDi_MASK       0x00000080
-#define HC_HRATFRZD_MASK        0x00000040
-#define HC_HRATFRTXA_MASK       0x00000020
-#define HC_HRATFRTXD_MASK       0x00000010
-#define HC_HRATFWZD_MASK        0x00000008
-#define HC_HRATFWCD_MASK        0x00000004
-#define HC_HRATTXTAG_MASK       0x00000002
-#define HC_HRATTXCH_MASK        0x00000001
-
-/* AGP Command Setting
- */
-#define HC_SubA_HAGPBstL        0x0060
-#define HC_SubA_HAGPBendL       0x0061
-#define HC_SubA_HAGPCMNT        0x0062
-#define HC_SubA_HAGPBpL         0x0063
-#define HC_SubA_HAGPBpH         0x0064
-/* HC_SubA_HAGPCMNT        0x0062
- */
-#define HC_HAGPCMNT_MASK        0x00800000
-#define HC_HCmdErrClr_MASK      0x00400000
-#define HC_HAGPBendH_MASK       0x0000ff00
-#define HC_HAGPBstH_MASK        0x000000ff
-#define HC_HAGPBendH_SHIFT      8
-#define HC_HAGPBstH_SHIFT       0
-/* HC_SubA_HAGPBpL         0x0063
- */
-#define HC_HAGPBpL_MASK         0x00fffffc
-#define HC_HAGPBpID_MASK        0x00000003
-#define HC_HAGPBpID_PAUSE       0x00000000
-#define HC_HAGPBpID_JUMP        0x00000001
-#define HC_HAGPBpID_STOP        0x00000002
-/* HC_SubA_HAGPBpH         0x0064
- */
-#define HC_HAGPBpH_MASK         0x00ffffff
-
-/* Miscellaneous Settings
- */
-#define HC_SubA_HClipTB         0x0070
-#define HC_SubA_HClipLR         0x0071
-#define HC_SubA_HFPClipTL       0x0072
-#define HC_SubA_HFPClipBL       0x0073
-#define HC_SubA_HFPClipLL       0x0074
-#define HC_SubA_HFPClipRL       0x0075
-#define HC_SubA_HFPClipTBH      0x0076
-#define HC_SubA_HFPClipLRH      0x0077
-#define HC_SubA_HLP             0x0078
-#define HC_SubA_HLPRF           0x0079
-#define HC_SubA_HSolidCL        0x007a
-#define HC_SubA_HPixGC          0x007b
-#define HC_SubA_HSPXYOS         0x007c
-#define HC_SubA_HVertexCNT      0x007d
-
-#define HC_HClipT_MASK          0x00fff000
-#define HC_HClipT_SHIFT         12
-#define HC_HClipB_MASK          0x00000fff
-#define HC_HClipB_SHIFT         0
-#define HC_HClipL_MASK          0x00fff000
-#define HC_HClipL_SHIFT         12
-#define HC_HClipR_MASK          0x00000fff
-#define HC_HClipR_SHIFT         0
-#define HC_HFPClipBH_MASK       0x0000ff00
-#define HC_HFPClipBH_SHIFT      8
-#define HC_HFPClipTH_MASK       0x000000ff
-#define HC_HFPClipTH_SHIFT      0
-#define HC_HFPClipRH_MASK       0x0000ff00
-#define HC_HFPClipRH_SHIFT      8
-#define HC_HFPClipLH_MASK       0x000000ff
-#define HC_HFPClipLH_SHIFT      0
-#define HC_HSolidCH_MASK        0x000000ff
-#define HC_HPixGC_MASK          0x00800000
-#define HC_HSPXOS_MASK          0x00fff000
-#define HC_HSPXOS_SHIFT         12
-#define HC_HSPYOS_MASK          0x00000fff
-
-/* Command
- * Command A
- */
-#define HC_HCmdHeader_MASK      0xfe000000     /*0xffe00000 */
-#define HC_HE3Fire_MASK         0x00100000
-#define HC_HPMType_MASK         0x000f0000
-#define HC_HEFlag_MASK          0x0000e000
-#define HC_HShading_MASK        0x00001c00
-#define HC_HPMValidN_MASK       0x00000200
-#define HC_HPLEND_MASK          0x00000100
-#define HC_HVCycle_MASK         0x000000ff
-#define HC_HVCycle_Style_MASK   0x000000c0
-#define HC_HVCycle_ChgA_MASK    0x00000030
-#define HC_HVCycle_ChgB_MASK    0x0000000c
-#define HC_HVCycle_ChgC_MASK    0x00000003
-#define HC_HPMType_Point        0x00000000
-#define HC_HPMType_Line         0x00010000
-#define HC_HPMType_Tri          0x00020000
-#define HC_HPMType_TriWF        0x00040000
-#define HC_HEFlag_NoAA          0x00000000
-#define HC_HEFlag_ab            0x00008000
-#define HC_HEFlag_bc            0x00004000
-#define HC_HEFlag_ca            0x00002000
-#define HC_HShading_Solid       0x00000000
-#define HC_HShading_FlatA       0x00000400
-#define HC_HShading_FlatB       0x00000800
-#define HC_HShading_FlatC       0x00000c00
-#define HC_HShading_Gouraud     0x00001000
-#define HC_HVCycle_Full         0x00000000
-#define HC_HVCycle_AFP          0x00000040
-#define HC_HVCycle_One          0x000000c0
-#define HC_HVCycle_NewA         0x00000000
-#define HC_HVCycle_AA           0x00000010
-#define HC_HVCycle_AB           0x00000020
-#define HC_HVCycle_AC           0x00000030
-#define HC_HVCycle_NewB         0x00000000
-#define HC_HVCycle_BA           0x00000004
-#define HC_HVCycle_BB           0x00000008
-#define HC_HVCycle_BC           0x0000000c
-#define HC_HVCycle_NewC         0x00000000
-#define HC_HVCycle_CA           0x00000001
-#define HC_HVCycle_CB           0x00000002
-#define HC_HVCycle_CC           0x00000003
-
-/* Command B
- */
-#define HC_HLPrst_MASK          0x00010000
-#define HC_HLLastP_MASK         0x00008000
-#define HC_HVPMSK_MASK          0x00007f80
-#define HC_HBFace_MASK          0x00000040
-#define HC_H2nd1VT_MASK         0x0000003f
-#define HC_HVPMSK_X             0x00004000
-#define HC_HVPMSK_Y             0x00002000
-#define HC_HVPMSK_Z             0x00001000
-#define HC_HVPMSK_W             0x00000800
-#define HC_HVPMSK_Cd            0x00000400
-#define HC_HVPMSK_Cs            0x00000200
-#define HC_HVPMSK_S             0x00000100
-#define HC_HVPMSK_T             0x00000080
-
-/* Enable Setting
- */
-#define HC_SubA_HEnable         0x0000
-#define HC_HenTXEnvMap_MASK     0x00200000
-#define HC_HenVertexCNT_MASK    0x00100000
-#define HC_HenCPUDAZ_MASK       0x00080000
-#define HC_HenDASZWC_MASK       0x00040000
-#define HC_HenFBCull_MASK       0x00020000
-#define HC_HenCW_MASK           0x00010000
-#define HC_HenAA_MASK           0x00008000
-#define HC_HenST_MASK           0x00004000
-#define HC_HenZT_MASK           0x00002000
-#define HC_HenZW_MASK           0x00001000
-#define HC_HenAT_MASK           0x00000800
-#define HC_HenAW_MASK           0x00000400
-#define HC_HenSP_MASK           0x00000200
-#define HC_HenLP_MASK           0x00000100
-#define HC_HenTXCH_MASK         0x00000080
-#define HC_HenTXMP_MASK         0x00000040
-#define HC_HenTXPP_MASK         0x00000020
-#define HC_HenTXTR_MASK         0x00000010
-#define HC_HenCS_MASK           0x00000008
-#define HC_HenFOG_MASK          0x00000004
-#define HC_HenABL_MASK          0x00000002
-#define HC_HenDT_MASK           0x00000001
-
-/* Z Setting
- */
-#define HC_SubA_HZWBBasL        0x0010
-#define HC_SubA_HZWBBasH        0x0011
-#define HC_SubA_HZWBType        0x0012
-#define HC_SubA_HZBiasL         0x0013
-#define HC_SubA_HZWBend         0x0014
-#define HC_SubA_HZWTMD          0x0015
-#define HC_SubA_HZWCDL          0x0016
-#define HC_SubA_HZWCTAGnum      0x0017
-#define HC_SubA_HZCYNum         0x0018
-#define HC_SubA_HZWCFire        0x0019
-/* HC_SubA_HZWBType
- */
-#define HC_HZWBType_MASK        0x00800000
-#define HC_HZBiasedWB_MASK      0x00400000
-#define HC_HZONEasFF_MASK       0x00200000
-#define HC_HZOONEasFF_MASK      0x00100000
-#define HC_HZWBFM_MASK          0x00030000
-#define HC_HZWBLoc_MASK         0x0000c000
-#define HC_HZWBPit_MASK         0x00003fff
-#define HC_HZWBFM_16            0x00000000
-#define HC_HZWBFM_32            0x00020000
-#define HC_HZWBFM_24            0x00030000
-#define HC_HZWBLoc_Local        0x00000000
-#define HC_HZWBLoc_SyS          0x00004000
-/* HC_SubA_HZWBend
- */
-#define HC_HZWBend_MASK         0x00ffe000
-#define HC_HZBiasH_MASK         0x000000ff
-#define HC_HZWBend_SHIFT        10
-/* HC_SubA_HZWTMD
- */
-#define HC_HZWTMD_MASK          0x00070000
-#define HC_HEBEBias_MASK        0x00007f00
-#define HC_HZNF_MASK            0x000000ff
-#define HC_HZWTMD_NeverPass     0x00000000
-#define HC_HZWTMD_LT            0x00010000
-#define HC_HZWTMD_EQ            0x00020000
-#define HC_HZWTMD_LE            0x00030000
-#define HC_HZWTMD_GT            0x00040000
-#define HC_HZWTMD_NE            0x00050000
-#define HC_HZWTMD_GE            0x00060000
-#define HC_HZWTMD_AllPass       0x00070000
-#define HC_HEBEBias_SHIFT       8
-/* HC_SubA_HZWCDL          0x0016
- */
-#define HC_HZWCDL_MASK          0x00ffffff
-/* HC_SubA_HZWCTAGnum      0x0017
- */
-#define HC_HZWCTAGnum_MASK      0x00ff0000
-#define HC_HZWCTAGnum_SHIFT     16
-#define HC_HZWCDH_MASK          0x000000ff
-#define HC_HZWCDH_SHIFT         0
-/* HC_SubA_HZCYNum         0x0018
- */
-#define HC_HZCYNum_MASK         0x00030000
-#define HC_HZCYNum_SHIFT        16
-#define HC_HZWCQWnum_MASK       0x00003fff
-#define HC_HZWCQWnum_SHIFT      0
-/* HC_SubA_HZWCFire        0x0019
- */
-#define HC_ZWCFire_MASK         0x00010000
-#define HC_HZWCQWnumLast_MASK   0x00003fff
-#define HC_HZWCQWnumLast_SHIFT  0
-
-/* Stencil Setting
- */
-#define HC_SubA_HSTREF          0x0023
-#define HC_SubA_HSTMD           0x0024
-/* HC_SubA_HSBFM
- */
-#define HC_HSBFM_MASK           0x00030000
-#define HC_HSBLoc_MASK          0x0000c000
-#define HC_HSBPit_MASK          0x00003fff
-/* HC_SubA_HSTREF
- */
-#define HC_HSTREF_MASK          0x00ff0000
-#define HC_HSTOPMSK_MASK        0x0000ff00
-#define HC_HSTBMSK_MASK         0x000000ff
-#define HC_HSTREF_SHIFT         16
-#define HC_HSTOPMSK_SHIFT       8
-/* HC_SubA_HSTMD
- */
-#define HC_HSTMD_MASK           0x00070000
-#define HC_HSTOPSF_MASK         0x000001c0
-#define HC_HSTOPSPZF_MASK       0x00000038
-#define HC_HSTOPSPZP_MASK       0x00000007
-#define HC_HSTMD_NeverPass      0x00000000
-#define HC_HSTMD_LT             0x00010000
-#define HC_HSTMD_EQ             0x00020000
-#define HC_HSTMD_LE             0x00030000
-#define HC_HSTMD_GT             0x00040000
-#define HC_HSTMD_NE             0x00050000
-#define HC_HSTMD_GE             0x00060000
-#define HC_HSTMD_AllPass        0x00070000
-#define HC_HSTOPSF_KEEP         0x00000000
-#define HC_HSTOPSF_ZERO         0x00000040
-#define HC_HSTOPSF_REPLACE      0x00000080
-#define HC_HSTOPSF_INCRSAT      0x000000c0
-#define HC_HSTOPSF_DECRSAT      0x00000100
-#define HC_HSTOPSF_INVERT       0x00000140
-#define HC_HSTOPSF_INCR         0x00000180
-#define HC_HSTOPSF_DECR         0x000001c0
-#define HC_HSTOPSPZF_KEEP       0x00000000
-#define HC_HSTOPSPZF_ZERO       0x00000008
-#define HC_HSTOPSPZF_REPLACE    0x00000010
-#define HC_HSTOPSPZF_INCRSAT    0x00000018
-#define HC_HSTOPSPZF_DECRSAT    0x00000020
-#define HC_HSTOPSPZF_INVERT     0x00000028
-#define HC_HSTOPSPZF_INCR       0x00000030
-#define HC_HSTOPSPZF_DECR       0x00000038
-#define HC_HSTOPSPZP_KEEP       0x00000000
-#define HC_HSTOPSPZP_ZERO       0x00000001
-#define HC_HSTOPSPZP_REPLACE    0x00000002
-#define HC_HSTOPSPZP_INCRSAT    0x00000003
-#define HC_HSTOPSPZP_DECRSAT    0x00000004
-#define HC_HSTOPSPZP_INVERT     0x00000005
-#define HC_HSTOPSPZP_INCR       0x00000006
-#define HC_HSTOPSPZP_DECR       0x00000007
-
-/* Alpha Setting
- */
-#define HC_SubA_HABBasL         0x0030
-#define HC_SubA_HABBasH         0x0031
-#define HC_SubA_HABFM           0x0032
-#define HC_SubA_HATMD           0x0033
-#define HC_SubA_HABLCsat        0x0034
-#define HC_SubA_HABLCop         0x0035
-#define HC_SubA_HABLAsat        0x0036
-#define HC_SubA_HABLAop         0x0037
-#define HC_SubA_HABLRCa         0x0038
-#define HC_SubA_HABLRFCa        0x0039
-#define HC_SubA_HABLRCbias      0x003a
-#define HC_SubA_HABLRCb         0x003b
-#define HC_SubA_HABLRFCb        0x003c
-#define HC_SubA_HABLRAa         0x003d
-#define HC_SubA_HABLRAb         0x003e
-/* HC_SubA_HABFM
- */
-#define HC_HABFM_MASK           0x00030000
-#define HC_HABLoc_MASK          0x0000c000
-#define HC_HABPit_MASK          0x000007ff
-/* HC_SubA_HATMD
- */
-#define HC_HATMD_MASK           0x00000700
-#define HC_HATREF_MASK          0x000000ff
-#define HC_HATMD_NeverPass      0x00000000
-#define HC_HATMD_LT             0x00000100
-#define HC_HATMD_EQ             0x00000200
-#define HC_HATMD_LE             0x00000300
-#define HC_HATMD_GT             0x00000400
-#define HC_HATMD_NE             0x00000500
-#define HC_HATMD_GE             0x00000600
-#define HC_HATMD_AllPass        0x00000700
-/* HC_SubA_HABLCsat
- */
-#define HC_HABLCsat_MASK        0x00010000
-#define HC_HABLCa_MASK          0x0000fc00
-#define HC_HABLCa_C_MASK        0x0000c000
-#define HC_HABLCa_OPC_MASK      0x00003c00
-#define HC_HABLFCa_MASK         0x000003f0
-#define HC_HABLFCa_C_MASK       0x00000300
-#define HC_HABLFCa_OPC_MASK     0x000000f0
-#define HC_HABLCbias_MASK       0x0000000f
-#define HC_HABLCbias_C_MASK     0x00000008
-#define HC_HABLCbias_OPC_MASK   0x00000007
-/*-- Define the input color.
- */
-#define HC_XC_Csrc              0x00000000
-#define HC_XC_Cdst              0x00000001
-#define HC_XC_Asrc              0x00000002
-#define HC_XC_Adst              0x00000003
-#define HC_XC_Fog               0x00000004
-#define HC_XC_HABLRC            0x00000005
-#define HC_XC_minSrcDst         0x00000006
-#define HC_XC_maxSrcDst         0x00000007
-#define HC_XC_mimAsrcInvAdst    0x00000008
-#define HC_XC_OPC               0x00000000
-#define HC_XC_InvOPC            0x00000010
-#define HC_XC_OPCp5             0x00000020
-/*-- Define the input Alpha
- */
-#define HC_XA_OPA               0x00000000
-#define HC_XA_InvOPA            0x00000010
-#define HC_XA_OPAp5             0x00000020
-#define HC_XA_0                 0x00000000
-#define HC_XA_Asrc              0x00000001
-#define HC_XA_Adst              0x00000002
-#define HC_XA_Fog               0x00000003
-#define HC_XA_minAsrcFog        0x00000004
-#define HC_XA_minAsrcAdst       0x00000005
-#define HC_XA_maxAsrcFog        0x00000006
-#define HC_XA_maxAsrcAdst       0x00000007
-#define HC_XA_HABLRA            0x00000008
-#define HC_XA_minAsrcInvAdst    0x00000008
-#define HC_XA_HABLFRA           0x00000009
-/*--
- */
-#define HC_HABLCa_OPC           (HC_XC_OPC << 10)
-#define HC_HABLCa_InvOPC        (HC_XC_InvOPC << 10)
-#define HC_HABLCa_OPCp5         (HC_XC_OPCp5 << 10)
-#define HC_HABLCa_Csrc          (HC_XC_Csrc << 10)
-#define HC_HABLCa_Cdst          (HC_XC_Cdst << 10)
-#define HC_HABLCa_Asrc          (HC_XC_Asrc << 10)
-#define HC_HABLCa_Adst          (HC_XC_Adst << 10)
-#define HC_HABLCa_Fog           (HC_XC_Fog << 10)
-#define HC_HABLCa_HABLRCa       (HC_XC_HABLRC << 10)
-#define HC_HABLCa_minSrcDst     (HC_XC_minSrcDst << 10)
-#define HC_HABLCa_maxSrcDst     (HC_XC_maxSrcDst << 10)
-#define HC_HABLFCa_OPC              (HC_XC_OPC << 4)
-#define HC_HABLFCa_InvOPC           (HC_XC_InvOPC << 4)
-#define HC_HABLFCa_OPCp5            (HC_XC_OPCp5 << 4)
-#define HC_HABLFCa_Csrc             (HC_XC_Csrc << 4)
-#define HC_HABLFCa_Cdst             (HC_XC_Cdst << 4)
-#define HC_HABLFCa_Asrc             (HC_XC_Asrc << 4)
-#define HC_HABLFCa_Adst             (HC_XC_Adst << 4)
-#define HC_HABLFCa_Fog              (HC_XC_Fog << 4)
-#define HC_HABLFCa_HABLRCa          (HC_XC_HABLRC << 4)
-#define HC_HABLFCa_minSrcDst        (HC_XC_minSrcDst << 4)
-#define HC_HABLFCa_maxSrcDst        (HC_XC_maxSrcDst << 4)
-#define HC_HABLFCa_mimAsrcInvAdst   (HC_XC_mimAsrcInvAdst << 4)
-#define HC_HABLCbias_HABLRCbias 0x00000000
-#define HC_HABLCbias_Asrc       0x00000001
-#define HC_HABLCbias_Adst       0x00000002
-#define HC_HABLCbias_Fog        0x00000003
-#define HC_HABLCbias_Cin        0x00000004
-/* HC_SubA_HABLCop         0x0035
- */
-#define HC_HABLdot_MASK         0x00010000
-#define HC_HABLCop_MASK         0x00004000
-#define HC_HABLCb_MASK          0x00003f00
-#define HC_HABLCb_C_MASK        0x00003000
-#define HC_HABLCb_OPC_MASK      0x00000f00
-#define HC_HABLFCb_MASK         0x000000fc
-#define HC_HABLFCb_C_MASK       0x000000c0
-#define HC_HABLFCb_OPC_MASK     0x0000003c
-#define HC_HABLCshift_MASK      0x00000003
-#define HC_HABLCb_OPC           (HC_XC_OPC << 8)
-#define HC_HABLCb_InvOPC        (HC_XC_InvOPC << 8)
-#define HC_HABLCb_OPCp5         (HC_XC_OPCp5 << 8)
-#define HC_HABLCb_Csrc          (HC_XC_Csrc << 8)
-#define HC_HABLCb_Cdst          (HC_XC_Cdst << 8)
-#define HC_HABLCb_Asrc          (HC_XC_Asrc << 8)
-#define HC_HABLCb_Adst          (HC_XC_Adst << 8)
-#define HC_HABLCb_Fog           (HC_XC_Fog << 8)
-#define HC_HABLCb_HABLRCa       (HC_XC_HABLRC << 8)
-#define HC_HABLCb_minSrcDst     (HC_XC_minSrcDst << 8)
-#define HC_HABLCb_maxSrcDst     (HC_XC_maxSrcDst << 8)
-#define HC_HABLFCb_OPC              (HC_XC_OPC << 2)
-#define HC_HABLFCb_InvOPC           (HC_XC_InvOPC << 2)
-#define HC_HABLFCb_OPCp5            (HC_XC_OPCp5 << 2)
-#define HC_HABLFCb_Csrc             (HC_XC_Csrc << 2)
-#define HC_HABLFCb_Cdst             (HC_XC_Cdst << 2)
-#define HC_HABLFCb_Asrc             (HC_XC_Asrc << 2)
-#define HC_HABLFCb_Adst             (HC_XC_Adst << 2)
-#define HC_HABLFCb_Fog              (HC_XC_Fog << 2)
-#define HC_HABLFCb_HABLRCb          (HC_XC_HABLRC << 2)
-#define HC_HABLFCb_minSrcDst        (HC_XC_minSrcDst << 2)
-#define HC_HABLFCb_maxSrcDst        (HC_XC_maxSrcDst << 2)
-#define HC_HABLFCb_mimAsrcInvAdst   (HC_XC_mimAsrcInvAdst << 2)
-/* HC_SubA_HABLAsat        0x0036
- */
-#define HC_HABLAsat_MASK        0x00010000
-#define HC_HABLAa_MASK          0x0000fc00
-#define HC_HABLAa_A_MASK        0x0000c000
-#define HC_HABLAa_OPA_MASK      0x00003c00
-#define HC_HABLFAa_MASK         0x000003f0
-#define HC_HABLFAa_A_MASK       0x00000300
-#define HC_HABLFAa_OPA_MASK     0x000000f0
-#define HC_HABLAbias_MASK       0x0000000f
-#define HC_HABLAbias_A_MASK     0x00000008
-#define HC_HABLAbias_OPA_MASK   0x00000007
-#define HC_HABLAa_OPA           (HC_XA_OPA << 10)
-#define HC_HABLAa_InvOPA        (HC_XA_InvOPA << 10)
-#define HC_HABLAa_OPAp5         (HC_XA_OPAp5 << 10)
-#define HC_HABLAa_0             (HC_XA_0 << 10)
-#define HC_HABLAa_Asrc          (HC_XA_Asrc << 10)
-#define HC_HABLAa_Adst          (HC_XA_Adst << 10)
-#define HC_HABLAa_Fog           (HC_XA_Fog << 10)
-#define HC_HABLAa_minAsrcFog    (HC_XA_minAsrcFog << 10)
-#define HC_HABLAa_minAsrcAdst   (HC_XA_minAsrcAdst << 10)
-#define HC_HABLAa_maxAsrcFog    (HC_XA_maxAsrcFog << 10)
-#define HC_HABLAa_maxAsrcAdst   (HC_XA_maxAsrcAdst << 10)
-#define HC_HABLAa_HABLRA        (HC_XA_HABLRA << 10)
-#define HC_HABLFAa_OPA          (HC_XA_OPA << 4)
-#define HC_HABLFAa_InvOPA       (HC_XA_InvOPA << 4)
-#define HC_HABLFAa_OPAp5        (HC_XA_OPAp5 << 4)
-#define HC_HABLFAa_0            (HC_XA_0 << 4)
-#define HC_HABLFAa_Asrc         (HC_XA_Asrc << 4)
-#define HC_HABLFAa_Adst         (HC_XA_Adst << 4)
-#define HC_HABLFAa_Fog          (HC_XA_Fog << 4)
-#define HC_HABLFAa_minAsrcFog   (HC_XA_minAsrcFog << 4)
-#define HC_HABLFAa_minAsrcAdst  (HC_XA_minAsrcAdst << 4)
-#define HC_HABLFAa_maxAsrcFog   (HC_XA_maxAsrcFog << 4)
-#define HC_HABLFAa_maxAsrcAdst  (HC_XA_maxAsrcAdst << 4)
-#define HC_HABLFAa_minAsrcInvAdst   (HC_XA_minAsrcInvAdst << 4)
-#define HC_HABLFAa_HABLFRA          (HC_XA_HABLFRA << 4)
-#define HC_HABLAbias_HABLRAbias 0x00000000
-#define HC_HABLAbias_Asrc       0x00000001
-#define HC_HABLAbias_Adst       0x00000002
-#define HC_HABLAbias_Fog        0x00000003
-#define HC_HABLAbias_Aaa        0x00000004
-/* HC_SubA_HABLAop         0x0037
- */
-#define HC_HABLAop_MASK         0x00004000
-#define HC_HABLAb_MASK          0x00003f00
-#define HC_HABLAb_OPA_MASK      0x00000f00
-#define HC_HABLFAb_MASK         0x000000fc
-#define HC_HABLFAb_OPA_MASK     0x0000003c
-#define HC_HABLAshift_MASK      0x00000003
-#define HC_HABLAb_OPA           (HC_XA_OPA << 8)
-#define HC_HABLAb_InvOPA        (HC_XA_InvOPA << 8)
-#define HC_HABLAb_OPAp5         (HC_XA_OPAp5 << 8)
-#define HC_HABLAb_0             (HC_XA_0 << 8)
-#define HC_HABLAb_Asrc          (HC_XA_Asrc << 8)
-#define HC_HABLAb_Adst          (HC_XA_Adst << 8)
-#define HC_HABLAb_Fog           (HC_XA_Fog << 8)
-#define HC_HABLAb_minAsrcFog    (HC_XA_minAsrcFog << 8)
-#define HC_HABLAb_minAsrcAdst   (HC_XA_minAsrcAdst << 8)
-#define HC_HABLAb_maxAsrcFog    (HC_XA_maxAsrcFog << 8)
-#define HC_HABLAb_maxAsrcAdst   (HC_XA_maxAsrcAdst << 8)
-#define HC_HABLAb_HABLRA        (HC_XA_HABLRA << 8)
-#define HC_HABLFAb_OPA          (HC_XA_OPA << 2)
-#define HC_HABLFAb_InvOPA       (HC_XA_InvOPA << 2)
-#define HC_HABLFAb_OPAp5        (HC_XA_OPAp5 << 2)
-#define HC_HABLFAb_0            (HC_XA_0 << 2)
-#define HC_HABLFAb_Asrc         (HC_XA_Asrc << 2)
-#define HC_HABLFAb_Adst         (HC_XA_Adst << 2)
-#define HC_HABLFAb_Fog          (HC_XA_Fog << 2)
-#define HC_HABLFAb_minAsrcFog   (HC_XA_minAsrcFog << 2)
-#define HC_HABLFAb_minAsrcAdst  (HC_XA_minAsrcAdst << 2)
-#define HC_HABLFAb_maxAsrcFog   (HC_XA_maxAsrcFog << 2)
-#define HC_HABLFAb_maxAsrcAdst  (HC_XA_maxAsrcAdst << 2)
-#define HC_HABLFAb_minAsrcInvAdst   (HC_XA_minAsrcInvAdst << 2)
-#define HC_HABLFAb_HABLFRA          (HC_XA_HABLFRA << 2)
-/* HC_SubA_HABLRAa         0x003d
- */
-#define HC_HABLRAa_MASK         0x00ff0000
-#define HC_HABLRFAa_MASK        0x0000ff00
-#define HC_HABLRAbias_MASK      0x000000ff
-#define HC_HABLRAa_SHIFT        16
-#define HC_HABLRFAa_SHIFT       8
-/* HC_SubA_HABLRAb         0x003e
- */
-#define HC_HABLRAb_MASK         0x0000ff00
-#define HC_HABLRFAb_MASK        0x000000ff
-#define HC_HABLRAb_SHIFT        8
-
-/* Destination Setting
- */
-#define HC_SubA_HDBBasL         0x0040
-#define HC_SubA_HDBBasH         0x0041
-#define HC_SubA_HDBFM           0x0042
-#define HC_SubA_HFBBMSKL        0x0043
-#define HC_SubA_HROP            0x0044
-/* HC_SubA_HDBFM           0x0042
- */
-#define HC_HDBFM_MASK           0x001f0000
-#define HC_HDBLoc_MASK          0x0000c000
-#define HC_HDBPit_MASK          0x00003fff
-#define HC_HDBFM_RGB555         0x00000000
-#define HC_HDBFM_RGB565         0x00010000
-#define HC_HDBFM_ARGB4444       0x00020000
-#define HC_HDBFM_ARGB1555       0x00030000
-#define HC_HDBFM_BGR555         0x00040000
-#define HC_HDBFM_BGR565         0x00050000
-#define HC_HDBFM_ABGR4444       0x00060000
-#define HC_HDBFM_ABGR1555       0x00070000
-#define HC_HDBFM_ARGB0888       0x00080000
-#define HC_HDBFM_ARGB8888       0x00090000
-#define HC_HDBFM_ABGR0888       0x000a0000
-#define HC_HDBFM_ABGR8888       0x000b0000
-#define HC_HDBLoc_Local         0x00000000
-#define HC_HDBLoc_Sys           0x00004000
-/* HC_SubA_HROP            0x0044
- */
-#define HC_HROP_MASK            0x00000f00
-#define HC_HFBBMSKH_MASK        0x000000ff
-#define HC_HROP_BLACK           0x00000000
-#define HC_HROP_DPon            0x00000100
-#define HC_HROP_DPna            0x00000200
-#define HC_HROP_Pn              0x00000300
-#define HC_HROP_PDna            0x00000400
-#define HC_HROP_Dn              0x00000500
-#define HC_HROP_DPx             0x00000600
-#define HC_HROP_DPan            0x00000700
-#define HC_HROP_DPa             0x00000800
-#define HC_HROP_DPxn            0x00000900
-#define HC_HROP_D               0x00000a00
-#define HC_HROP_DPno            0x00000b00
-#define HC_HROP_P               0x00000c00
-#define HC_HROP_PDno            0x00000d00
-#define HC_HROP_DPo             0x00000e00
-#define HC_HROP_WHITE           0x00000f00
-
-/* Fog Setting
- */
-#define HC_SubA_HFogLF          0x0050
-#define HC_SubA_HFogCL          0x0051
-#define HC_SubA_HFogCH          0x0052
-#define HC_SubA_HFogStL         0x0053
-#define HC_SubA_HFogStH         0x0054
-#define HC_SubA_HFogOOdMF       0x0055
-#define HC_SubA_HFogOOdEF       0x0056
-#define HC_SubA_HFogEndL        0x0057
-#define HC_SubA_HFogDenst       0x0058
-/* HC_SubA_FogLF           0x0050
- */
-#define HC_FogLF_MASK           0x00000010
-#define HC_FogEq_MASK           0x00000008
-#define HC_FogMD_MASK           0x00000007
-#define HC_FogMD_LocalFog        0x00000000
-#define HC_FogMD_LinearFog       0x00000002
-#define HC_FogMD_ExponentialFog  0x00000004
-#define HC_FogMD_Exponential2Fog 0x00000005
-/* #define HC_FogMD_FogTable       0x00000003 */
-
-/* HC_SubA_HFogDenst        0x0058
- */
-#define HC_FogDenst_MASK        0x001fff00
-#define HC_FogEndL_MASK         0x000000ff
-
-/* Texture subtype definitions
- */
-#define HC_SubType_Tex0         0x00000000
-#define HC_SubType_Tex1         0x00000001
-#define HC_SubType_TexGeneral   0x000000fe
-
-/* Attribute of texture n
- */
-#define HC_SubA_HTXnL0BasL      0x0000
-#define HC_SubA_HTXnL1BasL      0x0001
-#define HC_SubA_HTXnL2BasL      0x0002
-#define HC_SubA_HTXnL3BasL      0x0003
-#define HC_SubA_HTXnL4BasL      0x0004
-#define HC_SubA_HTXnL5BasL      0x0005
-#define HC_SubA_HTXnL6BasL      0x0006
-#define HC_SubA_HTXnL7BasL      0x0007
-#define HC_SubA_HTXnL8BasL      0x0008
-#define HC_SubA_HTXnL9BasL      0x0009
-#define HC_SubA_HTXnLaBasL      0x000a
-#define HC_SubA_HTXnLbBasL      0x000b
-#define HC_SubA_HTXnLcBasL      0x000c
-#define HC_SubA_HTXnLdBasL      0x000d
-#define HC_SubA_HTXnLeBasL      0x000e
-#define HC_SubA_HTXnLfBasL      0x000f
-#define HC_SubA_HTXnL10BasL     0x0010
-#define HC_SubA_HTXnL11BasL     0x0011
-#define HC_SubA_HTXnL012BasH    0x0020
-#define HC_SubA_HTXnL345BasH    0x0021
-#define HC_SubA_HTXnL678BasH    0x0022
-#define HC_SubA_HTXnL9abBasH    0x0023
-#define HC_SubA_HTXnLcdeBasH    0x0024
-#define HC_SubA_HTXnLf1011BasH  0x0025
-#define HC_SubA_HTXnL0Pit       0x002b
-#define HC_SubA_HTXnL1Pit       0x002c
-#define HC_SubA_HTXnL2Pit       0x002d
-#define HC_SubA_HTXnL3Pit       0x002e
-#define HC_SubA_HTXnL4Pit       0x002f
-#define HC_SubA_HTXnL5Pit       0x0030
-#define HC_SubA_HTXnL6Pit       0x0031
-#define HC_SubA_HTXnL7Pit       0x0032
-#define HC_SubA_HTXnL8Pit       0x0033
-#define HC_SubA_HTXnL9Pit       0x0034
-#define HC_SubA_HTXnLaPit       0x0035
-#define HC_SubA_HTXnLbPit       0x0036
-#define HC_SubA_HTXnLcPit       0x0037
-#define HC_SubA_HTXnLdPit       0x0038
-#define HC_SubA_HTXnLePit       0x0039
-#define HC_SubA_HTXnLfPit       0x003a
-#define HC_SubA_HTXnL10Pit      0x003b
-#define HC_SubA_HTXnL11Pit      0x003c
-#define HC_SubA_HTXnL0_5WE      0x004b
-#define HC_SubA_HTXnL6_bWE      0x004c
-#define HC_SubA_HTXnLc_11WE     0x004d
-#define HC_SubA_HTXnL0_5HE      0x0051
-#define HC_SubA_HTXnL6_bHE      0x0052
-#define HC_SubA_HTXnLc_11HE     0x0053
-#define HC_SubA_HTXnL0OS        0x0077
-#define HC_SubA_HTXnTB          0x0078
-#define HC_SubA_HTXnMPMD        0x0079
-#define HC_SubA_HTXnCLODu       0x007a
-#define HC_SubA_HTXnFM          0x007b
-#define HC_SubA_HTXnTRCH        0x007c
-#define HC_SubA_HTXnTRCL        0x007d
-#define HC_SubA_HTXnTBC         0x007e
-#define HC_SubA_HTXnTRAH        0x007f
-#define HC_SubA_HTXnTBLCsat     0x0080
-#define HC_SubA_HTXnTBLCop      0x0081
-#define HC_SubA_HTXnTBLMPfog    0x0082
-#define HC_SubA_HTXnTBLAsat     0x0083
-#define HC_SubA_HTXnTBLRCa      0x0085
-#define HC_SubA_HTXnTBLRCb      0x0086
-#define HC_SubA_HTXnTBLRCc      0x0087
-#define HC_SubA_HTXnTBLRCbias   0x0088
-#define HC_SubA_HTXnTBLRAa      0x0089
-#define HC_SubA_HTXnTBLRFog     0x008a
-#define HC_SubA_HTXnBumpM00     0x0090
-#define HC_SubA_HTXnBumpM01     0x0091
-#define HC_SubA_HTXnBumpM10     0x0092
-#define HC_SubA_HTXnBumpM11     0x0093
-#define HC_SubA_HTXnLScale      0x0094
-#define HC_SubA_HTXSMD          0x0000
-/* HC_SubA_HTXnL012BasH    0x0020
- */
-#define HC_HTXnL0BasH_MASK      0x000000ff
-#define HC_HTXnL1BasH_MASK      0x0000ff00
-#define HC_HTXnL2BasH_MASK      0x00ff0000
-#define HC_HTXnL1BasH_SHIFT     8
-#define HC_HTXnL2BasH_SHIFT     16
-/* HC_SubA_HTXnL345BasH    0x0021
- */
-#define HC_HTXnL3BasH_MASK      0x000000ff
-#define HC_HTXnL4BasH_MASK      0x0000ff00
-#define HC_HTXnL5BasH_MASK      0x00ff0000
-#define HC_HTXnL4BasH_SHIFT     8
-#define HC_HTXnL5BasH_SHIFT     16
-/* HC_SubA_HTXnL678BasH    0x0022
- */
-#define HC_HTXnL6BasH_MASK      0x000000ff
-#define HC_HTXnL7BasH_MASK      0x0000ff00
-#define HC_HTXnL8BasH_MASK      0x00ff0000
-#define HC_HTXnL7BasH_SHIFT     8
-#define HC_HTXnL8BasH_SHIFT     16
-/* HC_SubA_HTXnL9abBasH    0x0023
- */
-#define HC_HTXnL9BasH_MASK      0x000000ff
-#define HC_HTXnLaBasH_MASK      0x0000ff00
-#define HC_HTXnLbBasH_MASK      0x00ff0000
-#define HC_HTXnLaBasH_SHIFT     8
-#define HC_HTXnLbBasH_SHIFT     16
-/* HC_SubA_HTXnLcdeBasH    0x0024
- */
-#define HC_HTXnLcBasH_MASK      0x000000ff
-#define HC_HTXnLdBasH_MASK      0x0000ff00
-#define HC_HTXnLeBasH_MASK      0x00ff0000
-#define HC_HTXnLdBasH_SHIFT     8
-#define HC_HTXnLeBasH_SHIFT     16
-/* HC_SubA_HTXnLcdeBasH    0x0025
- */
-#define HC_HTXnLfBasH_MASK      0x000000ff
-#define HC_HTXnL10BasH_MASK      0x0000ff00
-#define HC_HTXnL11BasH_MASK      0x00ff0000
-#define HC_HTXnL10BasH_SHIFT     8
-#define HC_HTXnL11BasH_SHIFT     16
-/* HC_SubA_HTXnL0Pit       0x002b
- */
-#define HC_HTXnLnPit_MASK       0x00003fff
-#define HC_HTXnEnPit_MASK       0x00080000
-#define HC_HTXnLnPitE_MASK      0x00f00000
-#define HC_HTXnLnPitE_SHIFT     20
-/* HC_SubA_HTXnL0_5WE      0x004b
- */
-#define HC_HTXnL0WE_MASK        0x0000000f
-#define HC_HTXnL1WE_MASK        0x000000f0
-#define HC_HTXnL2WE_MASK        0x00000f00
-#define HC_HTXnL3WE_MASK        0x0000f000
-#define HC_HTXnL4WE_MASK        0x000f0000
-#define HC_HTXnL5WE_MASK        0x00f00000
-#define HC_HTXnL1WE_SHIFT       4
-#define HC_HTXnL2WE_SHIFT       8
-#define HC_HTXnL3WE_SHIFT       12
-#define HC_HTXnL4WE_SHIFT       16
-#define HC_HTXnL5WE_SHIFT       20
-/* HC_SubA_HTXnL6_bWE      0x004c
- */
-#define HC_HTXnL6WE_MASK        0x0000000f
-#define HC_HTXnL7WE_MASK        0x000000f0
-#define HC_HTXnL8WE_MASK        0x00000f00
-#define HC_HTXnL9WE_MASK        0x0000f000
-#define HC_HTXnLaWE_MASK        0x000f0000
-#define HC_HTXnLbWE_MASK        0x00f00000
-#define HC_HTXnL7WE_SHIFT       4
-#define HC_HTXnL8WE_SHIFT       8
-#define HC_HTXnL9WE_SHIFT       12
-#define HC_HTXnLaWE_SHIFT       16
-#define HC_HTXnLbWE_SHIFT       20
-/* HC_SubA_HTXnLc_11WE      0x004d
- */
-#define HC_HTXnLcWE_MASK        0x0000000f
-#define HC_HTXnLdWE_MASK        0x000000f0
-#define HC_HTXnLeWE_MASK        0x00000f00
-#define HC_HTXnLfWE_MASK        0x0000f000
-#define HC_HTXnL10WE_MASK       0x000f0000
-#define HC_HTXnL11WE_MASK       0x00f00000
-#define HC_HTXnLdWE_SHIFT       4
-#define HC_HTXnLeWE_SHIFT       8
-#define HC_HTXnLfWE_SHIFT       12
-#define HC_HTXnL10WE_SHIFT      16
-#define HC_HTXnL11WE_SHIFT      20
-/* HC_SubA_HTXnL0_5HE      0x0051
- */
-#define HC_HTXnL0HE_MASK        0x0000000f
-#define HC_HTXnL1HE_MASK        0x000000f0
-#define HC_HTXnL2HE_MASK        0x00000f00
-#define HC_HTXnL3HE_MASK        0x0000f000
-#define HC_HTXnL4HE_MASK        0x000f0000
-#define HC_HTXnL5HE_MASK        0x00f00000
-#define HC_HTXnL1HE_SHIFT       4
-#define HC_HTXnL2HE_SHIFT       8
-#define HC_HTXnL3HE_SHIFT       12
-#define HC_HTXnL4HE_SHIFT       16
-#define HC_HTXnL5HE_SHIFT       20
-/* HC_SubA_HTXnL6_bHE      0x0052
- */
-#define HC_HTXnL6HE_MASK        0x0000000f
-#define HC_HTXnL7HE_MASK        0x000000f0
-#define HC_HTXnL8HE_MASK        0x00000f00
-#define HC_HTXnL9HE_MASK        0x0000f000
-#define HC_HTXnLaHE_MASK        0x000f0000
-#define HC_HTXnLbHE_MASK        0x00f00000
-#define HC_HTXnL7HE_SHIFT       4
-#define HC_HTXnL8HE_SHIFT       8
-#define HC_HTXnL9HE_SHIFT       12
-#define HC_HTXnLaHE_SHIFT       16
-#define HC_HTXnLbHE_SHIFT       20
-/* HC_SubA_HTXnLc_11HE      0x0053
- */
-#define HC_HTXnLcHE_MASK        0x0000000f
-#define HC_HTXnLdHE_MASK        0x000000f0
-#define HC_HTXnLeHE_MASK        0x00000f00
-#define HC_HTXnLfHE_MASK        0x0000f000
-#define HC_HTXnL10HE_MASK       0x000f0000
-#define HC_HTXnL11HE_MASK       0x00f00000
-#define HC_HTXnLdHE_SHIFT       4
-#define HC_HTXnLeHE_SHIFT       8
-#define HC_HTXnLfHE_SHIFT       12
-#define HC_HTXnL10HE_SHIFT      16
-#define HC_HTXnL11HE_SHIFT      20
-/* HC_SubA_HTXnL0OS        0x0077
- */
-#define HC_HTXnL0OS_MASK        0x003ff000
-#define HC_HTXnLVmax_MASK       0x00000fc0
-#define HC_HTXnLVmin_MASK       0x0000003f
-#define HC_HTXnL0OS_SHIFT       12
-#define HC_HTXnLVmax_SHIFT      6
-/* HC_SubA_HTXnTB          0x0078
- */
-#define HC_HTXnTB_MASK          0x00f00000
-#define HC_HTXnFLSe_MASK        0x0000e000
-#define HC_HTXnFLSs_MASK        0x00001c00
-#define HC_HTXnFLTe_MASK        0x00000380
-#define HC_HTXnFLTs_MASK        0x00000070
-#define HC_HTXnFLDs_MASK        0x0000000f
-#define HC_HTXnTB_NoTB          0x00000000
-#define HC_HTXnTB_TBC_S         0x00100000
-#define HC_HTXnTB_TBC_T         0x00200000
-#define HC_HTXnTB_TB_S          0x00400000
-#define HC_HTXnTB_TB_T          0x00800000
-#define HC_HTXnFLSe_Nearest     0x00000000
-#define HC_HTXnFLSe_Linear      0x00002000
-#define HC_HTXnFLSe_NonLinear   0x00004000
-#define HC_HTXnFLSe_Sharp       0x00008000
-#define HC_HTXnFLSe_Flat_Gaussian_Cubic 0x0000c000
-#define HC_HTXnFLSs_Nearest     0x00000000
-#define HC_HTXnFLSs_Linear      0x00000400
-#define HC_HTXnFLSs_NonLinear   0x00000800
-#define HC_HTXnFLSs_Flat_Gaussian_Cubic 0x00001800
-#define HC_HTXnFLTe_Nearest     0x00000000
-#define HC_HTXnFLTe_Linear      0x00000080
-#define HC_HTXnFLTe_NonLinear   0x00000100
-#define HC_HTXnFLTe_Sharp       0x00000180
-#define HC_HTXnFLTe_Flat_Gaussian_Cubic 0x00000300
-#define HC_HTXnFLTs_Nearest     0x00000000
-#define HC_HTXnFLTs_Linear      0x00000010
-#define HC_HTXnFLTs_NonLinear   0x00000020
-#define HC_HTXnFLTs_Flat_Gaussian_Cubic 0x00000060
-#define HC_HTXnFLDs_Tex0        0x00000000
-#define HC_HTXnFLDs_Nearest     0x00000001
-#define HC_HTXnFLDs_Linear      0x00000002
-#define HC_HTXnFLDs_NonLinear   0x00000003
-#define HC_HTXnFLDs_Dither      0x00000004
-#define HC_HTXnFLDs_ConstLOD    0x00000005
-#define HC_HTXnFLDs_Ani         0x00000006
-#define HC_HTXnFLDs_AniDither   0x00000007
-/* HC_SubA_HTXnMPMD        0x0079
- */
-#define HC_HTXnMPMD_SMASK       0x00070000
-#define HC_HTXnMPMD_TMASK       0x00380000
-#define HC_HTXnLODDTf_MASK      0x00000007
-#define HC_HTXnXY2ST_MASK       0x00000008
-#define HC_HTXnMPMD_Tsingle     0x00000000
-#define HC_HTXnMPMD_Tclamp      0x00080000
-#define HC_HTXnMPMD_Trepeat     0x00100000
-#define HC_HTXnMPMD_Tmirror     0x00180000
-#define HC_HTXnMPMD_Twrap       0x00200000
-#define HC_HTXnMPMD_Ssingle     0x00000000
-#define HC_HTXnMPMD_Sclamp      0x00010000
-#define HC_HTXnMPMD_Srepeat     0x00020000
-#define HC_HTXnMPMD_Smirror     0x00030000
-#define HC_HTXnMPMD_Swrap       0x00040000
-/* HC_SubA_HTXnCLODu       0x007a
- */
-#define HC_HTXnCLODu_MASK       0x000ffc00
-#define HC_HTXnCLODd_MASK       0x000003ff
-#define HC_HTXnCLODu_SHIFT      10
-/* HC_SubA_HTXnFM          0x007b
- */
-#define HC_HTXnFM_MASK          0x00ff0000
-#define HC_HTXnLoc_MASK         0x00000003
-#define HC_HTXnFM_INDEX         0x00000000
-#define HC_HTXnFM_Intensity     0x00080000
-#define HC_HTXnFM_Lum           0x00100000
-#define HC_HTXnFM_Alpha         0x00180000
-#define HC_HTXnFM_DX            0x00280000
-#define HC_HTXnFM_ARGB16        0x00880000
-#define HC_HTXnFM_ARGB32        0x00980000
-#define HC_HTXnFM_ABGR16        0x00a80000
-#define HC_HTXnFM_ABGR32        0x00b80000
-#define HC_HTXnFM_RGBA16        0x00c80000
-#define HC_HTXnFM_RGBA32        0x00d80000
-#define HC_HTXnFM_BGRA16        0x00e80000
-#define HC_HTXnFM_BGRA32        0x00f80000
-#define HC_HTXnFM_BUMPMAP       0x00380000
-#define HC_HTXnFM_Index1        (HC_HTXnFM_INDEX     | 0x00000000)
-#define HC_HTXnFM_Index2        (HC_HTXnFM_INDEX     | 0x00010000)
-#define HC_HTXnFM_Index4        (HC_HTXnFM_INDEX     | 0x00020000)
-#define HC_HTXnFM_Index8        (HC_HTXnFM_INDEX     | 0x00030000)
-#define HC_HTXnFM_T1            (HC_HTXnFM_Intensity | 0x00000000)
-#define HC_HTXnFM_T2            (HC_HTXnFM_Intensity | 0x00010000)
-#define HC_HTXnFM_T4            (HC_HTXnFM_Intensity | 0x00020000)
-#define HC_HTXnFM_T8            (HC_HTXnFM_Intensity | 0x00030000)
-#define HC_HTXnFM_L1            (HC_HTXnFM_Lum       | 0x00000000)
-#define HC_HTXnFM_L2            (HC_HTXnFM_Lum       | 0x00010000)
-#define HC_HTXnFM_L4            (HC_HTXnFM_Lum       | 0x00020000)
-#define HC_HTXnFM_L8            (HC_HTXnFM_Lum       | 0x00030000)
-#define HC_HTXnFM_AL44          (HC_HTXnFM_Lum       | 0x00040000)
-#define HC_HTXnFM_AL88          (HC_HTXnFM_Lum       | 0x00050000)
-#define HC_HTXnFM_A1            (HC_HTXnFM_Alpha     | 0x00000000)
-#define HC_HTXnFM_A2            (HC_HTXnFM_Alpha     | 0x00010000)
-#define HC_HTXnFM_A4            (HC_HTXnFM_Alpha     | 0x00020000)
-#define HC_HTXnFM_A8            (HC_HTXnFM_Alpha     | 0x00030000)
-#define HC_HTXnFM_DX1           (HC_HTXnFM_DX        | 0x00010000)
-#define HC_HTXnFM_DX23          (HC_HTXnFM_DX        | 0x00020000)
-#define HC_HTXnFM_DX45          (HC_HTXnFM_DX        | 0x00030000)
-#define HC_HTXnFM_RGB555        (HC_HTXnFM_ARGB16    | 0x00000000)
-#define HC_HTXnFM_RGB565        (HC_HTXnFM_ARGB16    | 0x00010000)
-#define HC_HTXnFM_ARGB1555      (HC_HTXnFM_ARGB16    | 0x00020000)
-#define HC_HTXnFM_ARGB4444      (HC_HTXnFM_ARGB16    | 0x00030000)
-#define HC_HTXnFM_ARGB0888      (HC_HTXnFM_ARGB32    | 0x00000000)
-#define HC_HTXnFM_ARGB8888      (HC_HTXnFM_ARGB32    | 0x00010000)
-#define HC_HTXnFM_BGR555        (HC_HTXnFM_ABGR16    | 0x00000000)
-#define HC_HTXnFM_BGR565        (HC_HTXnFM_ABGR16    | 0x00010000)
-#define HC_HTXnFM_ABGR1555      (HC_HTXnFM_ABGR16    | 0x00020000)
-#define HC_HTXnFM_ABGR4444      (HC_HTXnFM_ABGR16    | 0x00030000)
-#define HC_HTXnFM_ABGR0888      (HC_HTXnFM_ABGR32    | 0x00000000)
-#define HC_HTXnFM_ABGR8888      (HC_HTXnFM_ABGR32    | 0x00010000)
-#define HC_HTXnFM_RGBA5550      (HC_HTXnFM_RGBA16    | 0x00000000)
-#define HC_HTXnFM_RGBA5551      (HC_HTXnFM_RGBA16    | 0x00020000)
-#define HC_HTXnFM_RGBA4444      (HC_HTXnFM_RGBA16    | 0x00030000)
-#define HC_HTXnFM_RGBA8880      (HC_HTXnFM_RGBA32    | 0x00000000)
-#define HC_HTXnFM_RGBA8888      (HC_HTXnFM_RGBA32    | 0x00010000)
-#define HC_HTXnFM_BGRA5550      (HC_HTXnFM_BGRA16    | 0x00000000)
-#define HC_HTXnFM_BGRA5551      (HC_HTXnFM_BGRA16    | 0x00020000)
-#define HC_HTXnFM_BGRA4444      (HC_HTXnFM_BGRA16    | 0x00030000)
-#define HC_HTXnFM_BGRA8880      (HC_HTXnFM_BGRA32    | 0x00000000)
-#define HC_HTXnFM_BGRA8888      (HC_HTXnFM_BGRA32    | 0x00010000)
-#define HC_HTXnFM_VU88          (HC_HTXnFM_BUMPMAP   | 0x00000000)
-#define HC_HTXnFM_LVU655        (HC_HTXnFM_BUMPMAP   | 0x00010000)
-#define HC_HTXnFM_LVU888        (HC_HTXnFM_BUMPMAP   | 0x00020000)
-#define HC_HTXnLoc_Local        0x00000000
-#define HC_HTXnLoc_Sys          0x00000002
-#define HC_HTXnLoc_AGP          0x00000003
-/* HC_SubA_HTXnTRAH        0x007f
- */
-#define HC_HTXnTRAH_MASK        0x00ff0000
-#define HC_HTXnTRAL_MASK        0x0000ff00
-#define HC_HTXnTBA_MASK         0x000000ff
-#define HC_HTXnTRAH_SHIFT       16
-#define HC_HTXnTRAL_SHIFT       8
-/* HC_SubA_HTXnTBLCsat     0x0080
- *-- Define the input texture.
- */
-#define HC_XTC_TOPC             0x00000000
-#define HC_XTC_InvTOPC          0x00000010
-#define HC_XTC_TOPCp5           0x00000020
-#define HC_XTC_Cbias            0x00000000
-#define HC_XTC_InvCbias         0x00000010
-#define HC_XTC_0                0x00000000
-#define HC_XTC_Dif              0x00000001
-#define HC_XTC_Spec             0x00000002
-#define HC_XTC_Tex              0x00000003
-#define HC_XTC_Cur              0x00000004
-#define HC_XTC_Adif             0x00000005
-#define HC_XTC_Fog              0x00000006
-#define HC_XTC_Atex             0x00000007
-#define HC_XTC_Acur             0x00000008
-#define HC_XTC_HTXnTBLRC        0x00000009
-#define HC_XTC_Ctexnext         0x0000000a
-/*--
- */
-#define HC_HTXnTBLCsat_MASK     0x00800000
-#define HC_HTXnTBLCa_MASK       0x000fc000
-#define HC_HTXnTBLCb_MASK       0x00001f80
-#define HC_HTXnTBLCc_MASK       0x0000003f
-#define HC_HTXnTBLCa_TOPC       (HC_XTC_TOPC << 14)
-#define HC_HTXnTBLCa_InvTOPC    (HC_XTC_InvTOPC << 14)
-#define HC_HTXnTBLCa_TOPCp5     (HC_XTC_TOPCp5 << 14)
-#define HC_HTXnTBLCa_0          (HC_XTC_0 << 14)
-#define HC_HTXnTBLCa_Dif        (HC_XTC_Dif << 14)
-#define HC_HTXnTBLCa_Spec       (HC_XTC_Spec << 14)
-#define HC_HTXnTBLCa_Tex        (HC_XTC_Tex << 14)
-#define HC_HTXnTBLCa_Cur        (HC_XTC_Cur << 14)
-#define HC_HTXnTBLCa_Adif       (HC_XTC_Adif << 14)
-#define HC_HTXnTBLCa_Fog        (HC_XTC_Fog << 14)
-#define HC_HTXnTBLCa_Atex       (HC_XTC_Atex << 14)
-#define HC_HTXnTBLCa_Acur       (HC_XTC_Acur << 14)
-#define HC_HTXnTBLCa_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 14)
-#define HC_HTXnTBLCa_Ctexnext   (HC_XTC_Ctexnext << 14)
-#define HC_HTXnTBLCb_TOPC       (HC_XTC_TOPC << 7)
-#define HC_HTXnTBLCb_InvTOPC    (HC_XTC_InvTOPC << 7)
-#define HC_HTXnTBLCb_TOPCp5     (HC_XTC_TOPCp5 << 7)
-#define HC_HTXnTBLCb_0          (HC_XTC_0 << 7)
-#define HC_HTXnTBLCb_Dif        (HC_XTC_Dif << 7)
-#define HC_HTXnTBLCb_Spec       (HC_XTC_Spec << 7)
-#define HC_HTXnTBLCb_Tex        (HC_XTC_Tex << 7)
-#define HC_HTXnTBLCb_Cur        (HC_XTC_Cur << 7)
-#define HC_HTXnTBLCb_Adif       (HC_XTC_Adif << 7)
-#define HC_HTXnTBLCb_Fog        (HC_XTC_Fog << 7)
-#define HC_HTXnTBLCb_Atex       (HC_XTC_Atex << 7)
-#define HC_HTXnTBLCb_Acur       (HC_XTC_Acur << 7)
-#define HC_HTXnTBLCb_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 7)
-#define HC_HTXnTBLCb_Ctexnext   (HC_XTC_Ctexnext << 7)
-#define HC_HTXnTBLCc_TOPC       (HC_XTC_TOPC << 0)
-#define HC_HTXnTBLCc_InvTOPC    (HC_XTC_InvTOPC << 0)
-#define HC_HTXnTBLCc_TOPCp5     (HC_XTC_TOPCp5 << 0)
-#define HC_HTXnTBLCc_0          (HC_XTC_0 << 0)
-#define HC_HTXnTBLCc_Dif        (HC_XTC_Dif << 0)
-#define HC_HTXnTBLCc_Spec       (HC_XTC_Spec << 0)
-#define HC_HTXnTBLCc_Tex        (HC_XTC_Tex << 0)
-#define HC_HTXnTBLCc_Cur        (HC_XTC_Cur << 0)
-#define HC_HTXnTBLCc_Adif       (HC_XTC_Adif << 0)
-#define HC_HTXnTBLCc_Fog        (HC_XTC_Fog << 0)
-#define HC_HTXnTBLCc_Atex       (HC_XTC_Atex << 0)
-#define HC_HTXnTBLCc_Acur       (HC_XTC_Acur << 0)
-#define HC_HTXnTBLCc_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 0)
-#define HC_HTXnTBLCc_Ctexnext   (HC_XTC_Ctexnext << 0)
-/* HC_SubA_HTXnTBLCop      0x0081
- */
-#define HC_HTXnTBLdot_MASK      0x00c00000
-#define HC_HTXnTBLCop_MASK      0x00380000
-#define HC_HTXnTBLCbias_MASK    0x0007c000
-#define HC_HTXnTBLCshift_MASK   0x00001800
-#define HC_HTXnTBLAop_MASK      0x00000380
-#define HC_HTXnTBLAbias_MASK    0x00000078
-#define HC_HTXnTBLAshift_MASK   0x00000003
-#define HC_HTXnTBLCop_Add       0x00000000
-#define HC_HTXnTBLCop_Sub       0x00080000
-#define HC_HTXnTBLCop_Min       0x00100000
-#define HC_HTXnTBLCop_Max       0x00180000
-#define HC_HTXnTBLCop_Mask      0x00200000
-#define HC_HTXnTBLCbias_Cbias           (HC_XTC_Cbias << 14)
-#define HC_HTXnTBLCbias_InvCbias        (HC_XTC_InvCbias << 14)
-#define HC_HTXnTBLCbias_0               (HC_XTC_0 << 14)
-#define HC_HTXnTBLCbias_Dif             (HC_XTC_Dif << 14)
-#define HC_HTXnTBLCbias_Spec            (HC_XTC_Spec << 14)
-#define HC_HTXnTBLCbias_Tex             (HC_XTC_Tex << 14)
-#define HC_HTXnTBLCbias_Cur             (HC_XTC_Cur << 14)
-#define HC_HTXnTBLCbias_Adif            (HC_XTC_Adif << 14)
-#define HC_HTXnTBLCbias_Fog             (HC_XTC_Fog << 14)
-#define HC_HTXnTBLCbias_Atex            (HC_XTC_Atex << 14)
-#define HC_HTXnTBLCbias_Acur            (HC_XTC_Acur << 14)
-#define HC_HTXnTBLCbias_HTXnTBLRC       (HC_XTC_HTXnTBLRC << 14)
-#define HC_HTXnTBLCshift_1      0x00000000
-#define HC_HTXnTBLCshift_2      0x00000800
-#define HC_HTXnTBLCshift_No     0x00001000
-#define HC_HTXnTBLCshift_DotP   0x00001800
-/*=* John Sheng [2003.7.18] texture combine *=*/
-#define HC_HTXnTBLDOT3   0x00080000
-#define HC_HTXnTBLDOT4   0x000C0000
-
-#define HC_HTXnTBLAop_Add       0x00000000
-#define HC_HTXnTBLAop_Sub       0x00000080
-#define HC_HTXnTBLAop_Min       0x00000100
-#define HC_HTXnTBLAop_Max       0x00000180
-#define HC_HTXnTBLAop_Mask      0x00000200
-#define HC_HTXnTBLAbias_Inv             0x00000040
-#define HC_HTXnTBLAbias_Adif            0x00000000
-#define HC_HTXnTBLAbias_Fog             0x00000008
-#define HC_HTXnTBLAbias_Acur            0x00000010
-#define HC_HTXnTBLAbias_HTXnTBLRAbias   0x00000018
-#define HC_HTXnTBLAbias_Atex            0x00000020
-#define HC_HTXnTBLAshift_1      0x00000000
-#define HC_HTXnTBLAshift_2      0x00000001
-#define HC_HTXnTBLAshift_No     0x00000002
-/* #define HC_HTXnTBLAshift_DotP   0x00000003 */
-/* HC_SubA_HTXnTBLMPFog    0x0082
- */
-#define HC_HTXnTBLMPfog_MASK    0x00e00000
-#define HC_HTXnTBLMPfog_0       0x00000000
-#define HC_HTXnTBLMPfog_Adif    0x00200000
-#define HC_HTXnTBLMPfog_Fog     0x00400000
-#define HC_HTXnTBLMPfog_Atex    0x00600000
-#define HC_HTXnTBLMPfog_Acur    0x00800000
-#define HC_HTXnTBLMPfog_GHTXnTBLRFog    0x00a00000
-/* HC_SubA_HTXnTBLAsat     0x0083
- *-- Define the texture alpha input.
- */
-#define HC_XTA_TOPA             0x00000000
-#define HC_XTA_InvTOPA          0x00000008
-#define HC_XTA_TOPAp5           0x00000010
-#define HC_XTA_Adif             0x00000000
-#define HC_XTA_Fog              0x00000001
-#define HC_XTA_Acur             0x00000002
-#define HC_XTA_HTXnTBLRA        0x00000003
-#define HC_XTA_Atex             0x00000004
-#define HC_XTA_Atexnext         0x00000005
-/*--
- */
-#define HC_HTXnTBLAsat_MASK     0x00800000
-#define HC_HTXnTBLAMB_MASK      0x00700000
-#define HC_HTXnTBLAa_MASK       0x0007c000
-#define HC_HTXnTBLAb_MASK       0x00000f80
-#define HC_HTXnTBLAc_MASK       0x0000001f
-#define HC_HTXnTBLAMB_SHIFT     20
-#define HC_HTXnTBLAa_TOPA       (HC_XTA_TOPA << 14)
-#define HC_HTXnTBLAa_InvTOPA    (HC_XTA_InvTOPA << 14)
-#define HC_HTXnTBLAa_TOPAp5     (HC_XTA_TOPAp5 << 14)
-#define HC_HTXnTBLAa_Adif       (HC_XTA_Adif << 14)
-#define HC_HTXnTBLAa_Fog        (HC_XTA_Fog << 14)
-#define HC_HTXnTBLAa_Acur       (HC_XTA_Acur << 14)
-#define HC_HTXnTBLAa_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 14)
-#define HC_HTXnTBLAa_Atex       (HC_XTA_Atex << 14)
-#define HC_HTXnTBLAa_Atexnext   (HC_XTA_Atexnext << 14)
-#define HC_HTXnTBLAb_TOPA       (HC_XTA_TOPA << 7)
-#define HC_HTXnTBLAb_InvTOPA    (HC_XTA_InvTOPA << 7)
-#define HC_HTXnTBLAb_TOPAp5     (HC_XTA_TOPAp5 << 7)
-#define HC_HTXnTBLAb_Adif       (HC_XTA_Adif << 7)
-#define HC_HTXnTBLAb_Fog        (HC_XTA_Fog << 7)
-#define HC_HTXnTBLAb_Acur       (HC_XTA_Acur << 7)
-#define HC_HTXnTBLAb_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 7)
-#define HC_HTXnTBLAb_Atex       (HC_XTA_Atex << 7)
-#define HC_HTXnTBLAb_Atexnext   (HC_XTA_Atexnext << 7)
-#define HC_HTXnTBLAc_TOPA       (HC_XTA_TOPA << 0)
-#define HC_HTXnTBLAc_InvTOPA    (HC_XTA_InvTOPA << 0)
-#define HC_HTXnTBLAc_TOPAp5     (HC_XTA_TOPAp5 << 0)
-#define HC_HTXnTBLAc_Adif       (HC_XTA_Adif << 0)
-#define HC_HTXnTBLAc_Fog        (HC_XTA_Fog << 0)
-#define HC_HTXnTBLAc_Acur       (HC_XTA_Acur << 0)
-#define HC_HTXnTBLAc_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 0)
-#define HC_HTXnTBLAc_Atex       (HC_XTA_Atex << 0)
-#define HC_HTXnTBLAc_Atexnext   (HC_XTA_Atexnext << 0)
-/* HC_SubA_HTXnTBLRAa      0x0089
- */
-#define HC_HTXnTBLRAa_MASK      0x00ff0000
-#define HC_HTXnTBLRAb_MASK      0x0000ff00
-#define HC_HTXnTBLRAc_MASK      0x000000ff
-#define HC_HTXnTBLRAa_SHIFT     16
-#define HC_HTXnTBLRAb_SHIFT     8
-#define HC_HTXnTBLRAc_SHIFT     0
-/* HC_SubA_HTXnTBLRFog     0x008a
- */
-#define HC_HTXnTBLRFog_MASK     0x0000ff00
-#define HC_HTXnTBLRAbias_MASK   0x000000ff
-#define HC_HTXnTBLRFog_SHIFT    8
-#define HC_HTXnTBLRAbias_SHIFT  0
-/* HC_SubA_HTXnLScale      0x0094
- */
-#define HC_HTXnLScale_MASK      0x0007fc00
-#define HC_HTXnLOff_MASK        0x000001ff
-#define HC_HTXnLScale_SHIFT     10
-/* HC_SubA_HTXSMD          0x0000
- */
-#define HC_HTXSMD_MASK          0x00000080
-#define HC_HTXTMD_MASK          0x00000040
-#define HC_HTXNum_MASK          0x00000038
-#define HC_HTXTRMD_MASK         0x00000006
-#define HC_HTXCHCLR_MASK        0x00000001
-#define HC_HTXNum_SHIFT         3
-
-/* Texture Palette n
- */
-#define HC_SubType_TexPalette0  0x00000000
-#define HC_SubType_TexPalette1  0x00000001
-#define HC_SubType_FogTable     0x00000010
-#define HC_SubType_Stipple      0x00000014
-/* HC_SubA_TexPalette0     0x0000
- */
-#define HC_HTPnA_MASK           0xff000000
-#define HC_HTPnR_MASK           0x00ff0000
-#define HC_HTPnG_MASK           0x0000ff00
-#define HC_HTPnB_MASK           0x000000ff
-/* HC_SubA_FogTable        0x0010
- */
-#define HC_HFPn3_MASK           0xff000000
-#define HC_HFPn2_MASK           0x00ff0000
-#define HC_HFPn1_MASK           0x0000ff00
-#define HC_HFPn_MASK            0x000000ff
-#define HC_HFPn3_SHIFT          24
-#define HC_HFPn2_SHIFT          16
-#define HC_HFPn1_SHIFT          8
-
-/* Auto Testing & Security
- */
-#define HC_SubA_HenFIFOAT       0x0000
-#define HC_SubA_HFBDrawFirst    0x0004
-#define HC_SubA_HFBBasL         0x0005
-#define HC_SubA_HFBDst          0x0006
-/* HC_SubA_HenFIFOAT       0x0000
- */
-#define HC_HenFIFOAT_MASK       0x00000020
-#define HC_HenGEMILock_MASK     0x00000010
-#define HC_HenFBASwap_MASK      0x00000008
-#define HC_HenOT_MASK           0x00000004
-#define HC_HenCMDQ_MASK         0x00000002
-#define HC_HenTXCTSU_MASK       0x00000001
-/* HC_SubA_HFBDrawFirst    0x0004
- */
-#define HC_HFBDrawFirst_MASK    0x00000800
-#define HC_HFBQueue_MASK        0x00000400
-#define HC_HFBLock_MASK         0x00000200
-#define HC_HEOF_MASK            0x00000100
-#define HC_HFBBasH_MASK         0x000000ff
-
-/* GEMI Setting
- */
-#define HC_SubA_HTArbRCM        0x0008
-#define HC_SubA_HTArbRZ         0x000a
-#define HC_SubA_HTArbWZ         0x000b
-#define HC_SubA_HTArbRTX        0x000c
-#define HC_SubA_HTArbRCW        0x000d
-#define HC_SubA_HTArbE2         0x000e
-#define HC_SubA_HArbRQCM        0x0010
-#define HC_SubA_HArbWQCM        0x0011
-#define HC_SubA_HGEMITout       0x0020
-#define HC_SubA_HFthRTXD        0x0040
-#define HC_SubA_HFthRTXA        0x0044
-#define HC_SubA_HCMDQstL        0x0050
-#define HC_SubA_HCMDQendL       0x0051
-#define HC_SubA_HCMDQLen        0x0052
-/* HC_SubA_HTArbRCM        0x0008
- */
-#define HC_HTArbRCM_MASK        0x0000ffff
-/* HC_SubA_HTArbRZ         0x000a
- */
-#define HC_HTArbRZ_MASK         0x0000ffff
-/* HC_SubA_HTArbWZ         0x000b
- */
-#define HC_HTArbWZ_MASK         0x0000ffff
-/* HC_SubA_HTArbRTX        0x000c
- */
-#define HC_HTArbRTX_MASK        0x0000ffff
-/* HC_SubA_HTArbRCW        0x000d
- */
-#define HC_HTArbRCW_MASK        0x0000ffff
-/* HC_SubA_HTArbE2         0x000e
- */
-#define HC_HTArbE2_MASK         0x0000ffff
-/* HC_SubA_HArbRQCM        0x0010
- */
-#define HC_HTArbRQCM_MASK       0x0000ffff
-/* HC_SubA_HArbWQCM        0x0011
- */
-#define HC_HArbWQCM_MASK        0x0000ffff
-/* HC_SubA_HGEMITout       0x0020
- */
-#define HC_HGEMITout_MASK       0x000f0000
-#define HC_HNPArbZC_MASK        0x0000ffff
-#define HC_HGEMITout_SHIFT      16
-/* HC_SubA_HFthRTXD        0x0040
- */
-#define HC_HFthRTXD_MASK        0x00ff0000
-#define HC_HFthRZD_MASK         0x0000ff00
-#define HC_HFthWZD_MASK         0x000000ff
-#define HC_HFthRTXD_SHIFT       16
-#define HC_HFthRZD_SHIFT        8
-/* HC_SubA_HFthRTXA        0x0044
- */
-#define HC_HFthRTXA_MASK        0x000000ff
-
-/******************************************************************************
-** Define the Halcyon Internal register access constants. For simulator only.
-******************************************************************************/
-#define HC_SIMA_HAGPBstL        0x0000
-#define HC_SIMA_HAGPBendL       0x0001
-#define HC_SIMA_HAGPCMNT        0x0002
-#define HC_SIMA_HAGPBpL         0x0003
-#define HC_SIMA_HAGPBpH         0x0004
-#define HC_SIMA_HClipTB         0x0005
-#define HC_SIMA_HClipLR         0x0006
-#define HC_SIMA_HFPClipTL       0x0007
-#define HC_SIMA_HFPClipBL       0x0008
-#define HC_SIMA_HFPClipLL       0x0009
-#define HC_SIMA_HFPClipRL       0x000a
-#define HC_SIMA_HFPClipTBH      0x000b
-#define HC_SIMA_HFPClipLRH      0x000c
-#define HC_SIMA_HLP             0x000d
-#define HC_SIMA_HLPRF           0x000e
-#define HC_SIMA_HSolidCL        0x000f
-#define HC_SIMA_HPixGC          0x0010
-#define HC_SIMA_HSPXYOS         0x0011
-#define HC_SIMA_HCmdA           0x0012
-#define HC_SIMA_HCmdB           0x0013
-#define HC_SIMA_HEnable         0x0014
-#define HC_SIMA_HZWBBasL        0x0015
-#define HC_SIMA_HZWBBasH        0x0016
-#define HC_SIMA_HZWBType        0x0017
-#define HC_SIMA_HZBiasL         0x0018
-#define HC_SIMA_HZWBend         0x0019
-#define HC_SIMA_HZWTMD          0x001a
-#define HC_SIMA_HZWCDL          0x001b
-#define HC_SIMA_HZWCTAGnum      0x001c
-#define HC_SIMA_HZCYNum         0x001d
-#define HC_SIMA_HZWCFire        0x001e
-/* #define HC_SIMA_HSBBasL         0x001d */
-/* #define HC_SIMA_HSBBasH         0x001e */
-/* #define HC_SIMA_HSBFM           0x001f */
-#define HC_SIMA_HSTREF          0x0020
-#define HC_SIMA_HSTMD           0x0021
-#define HC_SIMA_HABBasL         0x0022
-#define HC_SIMA_HABBasH         0x0023
-#define HC_SIMA_HABFM           0x0024
-#define HC_SIMA_HATMD           0x0025
-#define HC_SIMA_HABLCsat        0x0026
-#define HC_SIMA_HABLCop         0x0027
-#define HC_SIMA_HABLAsat        0x0028
-#define HC_SIMA_HABLAop         0x0029
-#define HC_SIMA_HABLRCa         0x002a
-#define HC_SIMA_HABLRFCa        0x002b
-#define HC_SIMA_HABLRCbias      0x002c
-#define HC_SIMA_HABLRCb         0x002d
-#define HC_SIMA_HABLRFCb        0x002e
-#define HC_SIMA_HABLRAa         0x002f
-#define HC_SIMA_HABLRAb         0x0030
-#define HC_SIMA_HDBBasL         0x0031
-#define HC_SIMA_HDBBasH         0x0032
-#define HC_SIMA_HDBFM           0x0033
-#define HC_SIMA_HFBBMSKL        0x0034
-#define HC_SIMA_HROP            0x0035
-#define HC_SIMA_HFogLF          0x0036
-#define HC_SIMA_HFogCL          0x0037
-#define HC_SIMA_HFogCH          0x0038
-#define HC_SIMA_HFogStL         0x0039
-#define HC_SIMA_HFogStH         0x003a
-#define HC_SIMA_HFogOOdMF       0x003b
-#define HC_SIMA_HFogOOdEF       0x003c
-#define HC_SIMA_HFogEndL        0x003d
-#define HC_SIMA_HFogDenst       0x003e
-/*---- start of texture 0 setting ----
- */
-#define HC_SIMA_HTX0L0BasL      0x0040
-#define HC_SIMA_HTX0L1BasL      0x0041
-#define HC_SIMA_HTX0L2BasL      0x0042
-#define HC_SIMA_HTX0L3BasL      0x0043
-#define HC_SIMA_HTX0L4BasL      0x0044
-#define HC_SIMA_HTX0L5BasL      0x0045
-#define HC_SIMA_HTX0L6BasL      0x0046
-#define HC_SIMA_HTX0L7BasL      0x0047
-#define HC_SIMA_HTX0L8BasL      0x0048
-#define HC_SIMA_HTX0L9BasL      0x0049
-#define HC_SIMA_HTX0LaBasL      0x004a
-#define HC_SIMA_HTX0LbBasL      0x004b
-#define HC_SIMA_HTX0LcBasL      0x004c
-#define HC_SIMA_HTX0LdBasL      0x004d
-#define HC_SIMA_HTX0LeBasL      0x004e
-#define HC_SIMA_HTX0LfBasL      0x004f
-#define HC_SIMA_HTX0L10BasL     0x0050
-#define HC_SIMA_HTX0L11BasL     0x0051
-#define HC_SIMA_HTX0L012BasH    0x0052
-#define HC_SIMA_HTX0L345BasH    0x0053
-#define HC_SIMA_HTX0L678BasH    0x0054
-#define HC_SIMA_HTX0L9abBasH    0x0055
-#define HC_SIMA_HTX0LcdeBasH    0x0056
-#define HC_SIMA_HTX0Lf1011BasH  0x0057
-#define HC_SIMA_HTX0L0Pit       0x0058
-#define HC_SIMA_HTX0L1Pit       0x0059
-#define HC_SIMA_HTX0L2Pit       0x005a
-#define HC_SIMA_HTX0L3Pit       0x005b
-#define HC_SIMA_HTX0L4Pit       0x005c
-#define HC_SIMA_HTX0L5Pit       0x005d
-#define HC_SIMA_HTX0L6Pit       0x005e
-#define HC_SIMA_HTX0L7Pit       0x005f
-#define HC_SIMA_HTX0L8Pit       0x0060
-#define HC_SIMA_HTX0L9Pit       0x0061
-#define HC_SIMA_HTX0LaPit       0x0062
-#define HC_SIMA_HTX0LbPit       0x0063
-#define HC_SIMA_HTX0LcPit       0x0064
-#define HC_SIMA_HTX0LdPit       0x0065
-#define HC_SIMA_HTX0LePit       0x0066
-#define HC_SIMA_HTX0LfPit       0x0067
-#define HC_SIMA_HTX0L10Pit      0x0068
-#define HC_SIMA_HTX0L11Pit      0x0069
-#define HC_SIMA_HTX0L0_5WE      0x006a
-#define HC_SIMA_HTX0L6_bWE      0x006b
-#define HC_SIMA_HTX0Lc_11WE     0x006c
-#define HC_SIMA_HTX0L0_5HE      0x006d
-#define HC_SIMA_HTX0L6_bHE      0x006e
-#define HC_SIMA_HTX0Lc_11HE     0x006f
-#define HC_SIMA_HTX0L0OS        0x0070
-#define HC_SIMA_HTX0TB          0x0071
-#define HC_SIMA_HTX0MPMD        0x0072
-#define HC_SIMA_HTX0CLODu       0x0073
-#define HC_SIMA_HTX0FM          0x0074
-#define HC_SIMA_HTX0TRCH        0x0075
-#define HC_SIMA_HTX0TRCL        0x0076
-#define HC_SIMA_HTX0TBC         0x0077
-#define HC_SIMA_HTX0TRAH        0x0078
-#define HC_SIMA_HTX0TBLCsat     0x0079
-#define HC_SIMA_HTX0TBLCop      0x007a
-#define HC_SIMA_HTX0TBLMPfog    0x007b
-#define HC_SIMA_HTX0TBLAsat     0x007c
-#define HC_SIMA_HTX0TBLRCa      0x007d
-#define HC_SIMA_HTX0TBLRCb      0x007e
-#define HC_SIMA_HTX0TBLRCc      0x007f
-#define HC_SIMA_HTX0TBLRCbias   0x0080
-#define HC_SIMA_HTX0TBLRAa      0x0081
-#define HC_SIMA_HTX0TBLRFog     0x0082
-#define HC_SIMA_HTX0BumpM00     0x0083
-#define HC_SIMA_HTX0BumpM01     0x0084
-#define HC_SIMA_HTX0BumpM10     0x0085
-#define HC_SIMA_HTX0BumpM11     0x0086
-#define HC_SIMA_HTX0LScale      0x0087
-/*---- end of texture 0 setting ----      0x008f
- */
-#define HC_SIMA_TX0TX1_OFF      0x0050
-/*---- start of texture 1 setting ----
- */
-#define HC_SIMA_HTX1L0BasL      (HC_SIMA_HTX0L0BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L1BasL      (HC_SIMA_HTX0L1BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L2BasL      (HC_SIMA_HTX0L2BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L3BasL      (HC_SIMA_HTX0L3BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L4BasL      (HC_SIMA_HTX0L4BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L5BasL      (HC_SIMA_HTX0L5BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L6BasL      (HC_SIMA_HTX0L6BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L7BasL      (HC_SIMA_HTX0L7BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L8BasL      (HC_SIMA_HTX0L8BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L9BasL      (HC_SIMA_HTX0L9BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LaBasL      (HC_SIMA_HTX0LaBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LbBasL      (HC_SIMA_HTX0LbBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LcBasL      (HC_SIMA_HTX0LcBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LdBasL      (HC_SIMA_HTX0LdBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LeBasL      (HC_SIMA_HTX0LeBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LfBasL      (HC_SIMA_HTX0LfBasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L10BasL     (HC_SIMA_HTX0L10BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L11BasL     (HC_SIMA_HTX0L11BasL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L012BasH    (HC_SIMA_HTX0L012BasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L345BasH    (HC_SIMA_HTX0L345BasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L678BasH    (HC_SIMA_HTX0L678BasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L9abBasH    (HC_SIMA_HTX0L9abBasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LcdeBasH    (HC_SIMA_HTX0LcdeBasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1Lf1011BasH  (HC_SIMA_HTX0Lf1011BasH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L0Pit       (HC_SIMA_HTX0L0Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L1Pit       (HC_SIMA_HTX0L1Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L2Pit       (HC_SIMA_HTX0L2Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L3Pit       (HC_SIMA_HTX0L3Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L4Pit       (HC_SIMA_HTX0L4Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L5Pit       (HC_SIMA_HTX0L5Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L6Pit       (HC_SIMA_HTX0L6Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L7Pit       (HC_SIMA_HTX0L7Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L8Pit       (HC_SIMA_HTX0L8Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L9Pit       (HC_SIMA_HTX0L9Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LaPit       (HC_SIMA_HTX0LaPit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LbPit       (HC_SIMA_HTX0LbPit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LcPit       (HC_SIMA_HTX0LcPit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LdPit       (HC_SIMA_HTX0LdPit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LePit       (HC_SIMA_HTX0LePit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LfPit       (HC_SIMA_HTX0LfPit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L10Pit      (HC_SIMA_HTX0L10Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L11Pit      (HC_SIMA_HTX0L11Pit + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L0_5WE      (HC_SIMA_HTX0L0_5WE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L6_bWE      (HC_SIMA_HTX0L6_bWE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1Lc_11WE     (HC_SIMA_HTX0Lc_11WE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L0_5HE      (HC_SIMA_HTX0L0_5HE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L6_bHE      (HC_SIMA_HTX0L6_bHE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1Lc_11HE      (HC_SIMA_HTX0Lc_11HE + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1L0OS        (HC_SIMA_HTX0L0OS + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TB          (HC_SIMA_HTX0TB + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1MPMD        (HC_SIMA_HTX0MPMD + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1CLODu       (HC_SIMA_HTX0CLODu + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1FM          (HC_SIMA_HTX0FM + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TRCH        (HC_SIMA_HTX0TRCH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TRCL        (HC_SIMA_HTX0TRCL + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBC         (HC_SIMA_HTX0TBC + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TRAH        (HC_SIMA_HTX0TRAH + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LTC         (HC_SIMA_HTX0LTC + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LTA         (HC_SIMA_HTX0LTA + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLCsat     (HC_SIMA_HTX0TBLCsat + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLCop      (HC_SIMA_HTX0TBLCop + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLMPfog    (HC_SIMA_HTX0TBLMPfog + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLAsat     (HC_SIMA_HTX0TBLAsat + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRCa      (HC_SIMA_HTX0TBLRCa + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRCb      (HC_SIMA_HTX0TBLRCb + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRCc      (HC_SIMA_HTX0TBLRCc + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRCbias   (HC_SIMA_HTX0TBLRCbias + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRAa      (HC_SIMA_HTX0TBLRAa + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1TBLRFog     (HC_SIMA_HTX0TBLRFog + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1BumpM00     (HC_SIMA_HTX0BumpM00 + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1BumpM01     (HC_SIMA_HTX0BumpM01 + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1BumpM10     (HC_SIMA_HTX0BumpM10 + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1BumpM11     (HC_SIMA_HTX0BumpM11 + HC_SIMA_TX0TX1_OFF)
-#define HC_SIMA_HTX1LScale      (HC_SIMA_HTX0LScale + HC_SIMA_TX0TX1_OFF)
-/*---- end of texture 1 setting ---- 0xaf
- */
-#define HC_SIMA_HTXSMD          0x00b0
-#define HC_SIMA_HenFIFOAT       0x00b1
-#define HC_SIMA_HFBDrawFirst    0x00b2
-#define HC_SIMA_HFBBasL         0x00b3
-#define HC_SIMA_HTArbRCM        0x00b4
-#define HC_SIMA_HTArbRZ         0x00b5
-#define HC_SIMA_HTArbWZ         0x00b6
-#define HC_SIMA_HTArbRTX        0x00b7
-#define HC_SIMA_HTArbRCW        0x00b8
-#define HC_SIMA_HTArbE2         0x00b9
-#define HC_SIMA_HGEMITout       0x00ba
-#define HC_SIMA_HFthRTXD        0x00bb
-#define HC_SIMA_HFthRTXA        0x00bc
-/* Define the texture palette 0
- */
-#define HC_SIMA_HTP0            0x0100
-#define HC_SIMA_HTP1            0x0200
-#define HC_SIMA_FOGTABLE        0x0300
-#define HC_SIMA_STIPPLE         0x0400
-#define HC_SIMA_HE3Fire         0x0440
-#define HC_SIMA_TRANS_SET       0x0441
-#define HC_SIMA_HREngSt         0x0442
-#define HC_SIMA_HRFIFOempty     0x0443
-#define HC_SIMA_HRFIFOfull      0x0444
-#define HC_SIMA_HRErr           0x0445
-#define HC_SIMA_FIFOstatus      0x0446
-
-/******************************************************************************
-** Define the AGP command header.
-******************************************************************************/
-#define HC_ACMD_MASK            0xfe000000
-#define HC_ACMD_SUB_MASK        0x0c000000
-#define HC_ACMD_HCmdA           0xee000000
-#define HC_ACMD_HCmdB           0xec000000
-#define HC_ACMD_HCmdC           0xea000000
-#define HC_ACMD_H1              0xf0000000
-#define HC_ACMD_H2              0xf2000000
-#define HC_ACMD_H3              0xf4000000
-#define HC_ACMD_H4              0xf6000000
-
-#define HC_ACMD_H1IO_MASK       0x000001ff
-#define HC_ACMD_H2IO1_MASK      0x001ff000
-#define HC_ACMD_H2IO2_MASK      0x000001ff
-#define HC_ACMD_H2IO1_SHIFT     12
-#define HC_ACMD_H2IO2_SHIFT     0
-#define HC_ACMD_H3IO_MASK       0x000001ff
-#define HC_ACMD_H3COUNT_MASK    0x01fff000
-#define HC_ACMD_H3COUNT_SHIFT   12
-#define HC_ACMD_H4ID_MASK       0x000001ff
-#define HC_ACMD_H4COUNT_MASK    0x01fffe00
-#define HC_ACMD_H4COUNT_SHIFT   9
-
-/********************************************************************************
-** Define Header
-********************************************************************************/
-#define HC_HEADER2             0xF210F110
-
-/********************************************************************************
-** Define Dummy Value
-********************************************************************************/
-#define HC_DUMMY               0xCCCCCCCC
-/********************************************************************************
-** Define for DMA use
-********************************************************************************/
-#define HALCYON_HEADER2     0XF210F110
-#define HALCYON_FIRECMD     0XEE100000
-#define HALCYON_FIREMASK    0XFFF00000
-#define HALCYON_CMDB        0XEC000000
-#define HALCYON_CMDBMASK    0XFFFE0000
-#define HALCYON_SUB_ADDR0   0X00000000
-#define HALCYON_HEADER1MASK 0XFFFFFC00
-#define HALCYON_HEADER1     0XF0000000
-#define HC_SubA_HAGPBstL        0x0060
-#define HC_SubA_HAGPBendL       0x0061
-#define HC_SubA_HAGPCMNT        0x0062
-#define HC_SubA_HAGPBpL         0x0063
-#define HC_SubA_HAGPBpH         0x0064
-#define HC_HAGPCMNT_MASK        0x00800000
-#define HC_HCmdErrClr_MASK      0x00400000
-#define HC_HAGPBendH_MASK       0x0000ff00
-#define HC_HAGPBstH_MASK        0x000000ff
-#define HC_HAGPBendH_SHIFT      8
-#define HC_HAGPBstH_SHIFT       0
-#define HC_HAGPBpL_MASK         0x00fffffc
-#define HC_HAGPBpID_MASK        0x00000003
-#define HC_HAGPBpID_PAUSE       0x00000000
-#define HC_HAGPBpID_JUMP        0x00000001
-#define HC_HAGPBpID_STOP        0x00000002
-#define HC_HAGPBpH_MASK         0x00ffffff
-
-#define VIA_VIDEO_HEADER5       0xFE040000
-#define VIA_VIDEO_HEADER6       0xFE050000
-#define VIA_VIDEO_HEADER7       0xFE060000
-#define VIA_VIDEOMASK           0xFFFF0000
-#endif
diff --git a/drivers/char/drm/via_dma.c b/drivers/char/drm/via_dma.c
deleted file mode 100644 (file)
index 7a339db..0000000
+++ /dev/null
@@ -1,755 +0,0 @@
-/* via_dma.c -- DMA support for the VIA Unichrome/Pro
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Copyright 2004 Digeo, Inc., Palo Alto, CA, U.S.A.
- * All Rights Reserved.
- *
- * Copyright 2004 The Unichrome project.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Tungsten Graphics,
- *    Erdi Chen,
- *    Thomas Hellstrom.
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "via_drm.h"
-#include "via_drv.h"
-#include "via_3d_reg.h"
-
-#define CMDBUF_ALIGNMENT_SIZE   (0x100)
-#define CMDBUF_ALIGNMENT_MASK   (0x0ff)
-
-/* defines for VIA 3D registers */
-#define VIA_REG_STATUS          0x400
-#define VIA_REG_TRANSET         0x43C
-#define VIA_REG_TRANSPACE       0x440
-
-/* VIA_REG_STATUS(0x400): Engine Status */
-#define VIA_CMD_RGTR_BUSY       0x00000080     /* Command Regulator is busy */
-#define VIA_2D_ENG_BUSY         0x00000001     /* 2D Engine is busy */
-#define VIA_3D_ENG_BUSY         0x00000002     /* 3D Engine is busy */
-#define VIA_VR_QUEUE_BUSY       0x00020000     /* Virtual Queue is busy */
-
-#define SetReg2DAGP(nReg, nData) {                             \
-       *((uint32_t *)(vb)) = ((nReg) >> 2) | HALCYON_HEADER1;  \
-       *((uint32_t *)(vb) + 1) = (nData);                      \
-       vb = ((uint32_t *)vb) + 2;                              \
-       dev_priv->dma_low +=8;                                  \
-}
-
-#define via_flush_write_combine() DRM_MEMORYBARRIER()
-
-#define VIA_OUT_RING_QW(w1,w2)                 \
-       *vb++ = (w1);                           \
-       *vb++ = (w2);                           \
-       dev_priv->dma_low += 8;
-
-static void via_cmdbuf_start(drm_via_private_t * dev_priv);
-static void via_cmdbuf_pause(drm_via_private_t * dev_priv);
-static void via_cmdbuf_reset(drm_via_private_t * dev_priv);
-static void via_cmdbuf_rewind(drm_via_private_t * dev_priv);
-static int via_wait_idle(drm_via_private_t * dev_priv);
-static void via_pad_cache(drm_via_private_t * dev_priv, int qwords);
-
-/*
- * Free space in command buffer.
- */
-
-static uint32_t via_cmdbuf_space(drm_via_private_t * dev_priv)
-{
-       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
-
-       return ((hw_addr <= dev_priv->dma_low) ?
-               (dev_priv->dma_high + hw_addr - dev_priv->dma_low) :
-               (hw_addr - dev_priv->dma_low));
-}
-
-/*
- * How much does the command regulator lag behind?
- */
-
-static uint32_t via_cmdbuf_lag(drm_via_private_t * dev_priv)
-{
-       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
-
-       return ((hw_addr <= dev_priv->dma_low) ?
-               (dev_priv->dma_low - hw_addr) :
-               (dev_priv->dma_wrap + dev_priv->dma_low - hw_addr));
-}
-
-/*
- * Check that the given size fits in the buffer, otherwise wait.
- */
-
-static inline int
-via_cmdbuf_wait(drm_via_private_t * dev_priv, unsigned int size)
-{
-       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       uint32_t cur_addr, hw_addr, next_addr;
-       volatile uint32_t *hw_addr_ptr;
-       uint32_t count;
-       hw_addr_ptr = dev_priv->hw_addr_ptr;
-       cur_addr = dev_priv->dma_low;
-       next_addr = cur_addr + size + 512 * 1024;
-       count = 1000000;
-       do {
-               hw_addr = *hw_addr_ptr - agp_base;
-               if (count-- == 0) {
-                       DRM_ERROR
-                           ("via_cmdbuf_wait timed out hw %x cur_addr %x next_addr %x\n",
-                            hw_addr, cur_addr, next_addr);
-                       return -1;
-               }
-               if  ((cur_addr < hw_addr) && (next_addr >= hw_addr))
-                       msleep(1);
-       } while ((cur_addr < hw_addr) && (next_addr >= hw_addr));
-       return 0;
-}
-
-/*
- * Checks whether buffer head has reach the end. Rewind the ring buffer
- * when necessary.
- *
- * Returns virtual pointer to ring buffer.
- */
-
-static inline uint32_t *via_check_dma(drm_via_private_t * dev_priv,
-                                     unsigned int size)
-{
-       if ((dev_priv->dma_low + size + 4 * CMDBUF_ALIGNMENT_SIZE) >
-           dev_priv->dma_high) {
-               via_cmdbuf_rewind(dev_priv);
-       }
-       if (via_cmdbuf_wait(dev_priv, size) != 0) {
-               return NULL;
-       }
-
-       return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
-}
-
-int via_dma_cleanup(struct drm_device * dev)
-{
-       if (dev->dev_private) {
-               drm_via_private_t *dev_priv =
-                   (drm_via_private_t *) dev->dev_private;
-
-               if (dev_priv->ring.virtual_start) {
-                       via_cmdbuf_reset(dev_priv);
-
-                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
-                       dev_priv->ring.virtual_start = NULL;
-               }
-
-       }
-
-       return 0;
-}
-
-static int via_initialize(struct drm_device * dev,
-                         drm_via_private_t * dev_priv,
-                         drm_via_dma_init_t * init)
-{
-       if (!dev_priv || !dev_priv->mmio) {
-               DRM_ERROR("via_dma_init called before via_map_init\n");
-               return -EFAULT;
-       }
-
-       if (dev_priv->ring.virtual_start != NULL) {
-               DRM_ERROR("called again without calling cleanup\n");
-               return -EFAULT;
-       }
-
-       if (!dev->agp || !dev->agp->base) {
-               DRM_ERROR("called with no agp memory available\n");
-               return -EFAULT;
-       }
-
-       if (dev_priv->chipset == VIA_DX9_0) {
-               DRM_ERROR("AGP DMA is not supported on this chip\n");
-               return -EINVAL;
-       }
-
-       dev_priv->ring.map.offset = dev->agp->base + init->offset;
-       dev_priv->ring.map.size = init->size;
-       dev_priv->ring.map.type = 0;
-       dev_priv->ring.map.flags = 0;
-       dev_priv->ring.map.mtrr = 0;
-
-       drm_core_ioremap(&dev_priv->ring.map, dev);
-
-       if (dev_priv->ring.map.handle == NULL) {
-               via_dma_cleanup(dev);
-               DRM_ERROR("can not ioremap virtual address for"
-                         " ring buffer\n");
-               return -ENOMEM;
-       }
-
-       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
-
-       dev_priv->dma_ptr = dev_priv->ring.virtual_start;
-       dev_priv->dma_low = 0;
-       dev_priv->dma_high = init->size;
-       dev_priv->dma_wrap = init->size;
-       dev_priv->dma_offset = init->offset;
-       dev_priv->last_pause_ptr = NULL;
-       dev_priv->hw_addr_ptr =
-               (volatile uint32_t *)((char *)dev_priv->mmio->handle +
-               init->reg_pause_addr);
-
-       via_cmdbuf_start(dev_priv);
-
-       return 0;
-}
-
-static int via_dma_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       drm_via_dma_init_t *init = data;
-       int retcode = 0;
-
-       switch (init->func) {
-       case VIA_INIT_DMA:
-               if (!DRM_SUSER(DRM_CURPROC))
-                       retcode = -EPERM;
-               else
-                       retcode = via_initialize(dev, dev_priv, init);
-               break;
-       case VIA_CLEANUP_DMA:
-               if (!DRM_SUSER(DRM_CURPROC))
-                       retcode = -EPERM;
-               else
-                       retcode = via_dma_cleanup(dev);
-               break;
-       case VIA_DMA_INITIALIZED:
-               retcode = (dev_priv->ring.virtual_start != NULL) ?
-                       0 : -EFAULT;
-               break;
-       default:
-               retcode = -EINVAL;
-               break;
-       }
-
-       return retcode;
-}
-
-static int via_dispatch_cmdbuffer(struct drm_device * dev, drm_via_cmdbuffer_t * cmd)
-{
-       drm_via_private_t *dev_priv;
-       uint32_t *vb;
-       int ret;
-
-       dev_priv = (drm_via_private_t *) dev->dev_private;
-
-       if (dev_priv->ring.virtual_start == NULL) {
-               DRM_ERROR("called without initializing AGP ring buffer.\n");
-               return -EFAULT;
-       }
-
-       if (cmd->size > VIA_PCI_BUF_SIZE) {
-               return -ENOMEM;
-       }
-
-       if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
-               return -EFAULT;
-
-       /*
-        * Running this function on AGP memory is dead slow. Therefore
-        * we run it on a temporary cacheable system memory buffer and
-        * copy it to AGP memory when ready.
-        */
-
-       if ((ret =
-            via_verify_command_stream((uint32_t *) dev_priv->pci_buf,
-                                      cmd->size, dev, 1))) {
-               return ret;
-       }
-
-       vb = via_check_dma(dev_priv, (cmd->size < 0x100) ? 0x102 : cmd->size);
-       if (vb == NULL) {
-               return -EAGAIN;
-       }
-
-       memcpy(vb, dev_priv->pci_buf, cmd->size);
-
-       dev_priv->dma_low += cmd->size;
-
-       /*
-        * Small submissions somehow stalls the CPU. (AGP cache effects?)
-        * pad to greater size.
-        */
-
-       if (cmd->size < 0x100)
-               via_pad_cache(dev_priv, (0x100 - cmd->size) >> 3);
-       via_cmdbuf_pause(dev_priv);
-
-       return 0;
-}
-
-int via_driver_dma_quiescent(struct drm_device * dev)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-
-       if (!via_wait_idle(dev_priv)) {
-               return -EBUSY;
-       }
-       return 0;
-}
-
-static int via_flush_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       return via_driver_dma_quiescent(dev);
-}
-
-static int via_cmdbuffer(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_cmdbuffer_t *cmdbuf = data;
-       int ret;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("buf %p size %lu\n", cmdbuf->buf, cmdbuf->size);
-
-       ret = via_dispatch_cmdbuffer(dev, cmdbuf);
-       if (ret) {
-               return ret;
-       }
-
-       return 0;
-}
-
-static int via_dispatch_pci_cmdbuffer(struct drm_device * dev,
-                                     drm_via_cmdbuffer_t * cmd)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-       int ret;
-
-       if (cmd->size > VIA_PCI_BUF_SIZE) {
-               return -ENOMEM;
-       }
-       if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
-               return -EFAULT;
-
-       if ((ret =
-            via_verify_command_stream((uint32_t *) dev_priv->pci_buf,
-                                      cmd->size, dev, 0))) {
-               return ret;
-       }
-
-       ret =
-           via_parse_command_stream(dev, (const uint32_t *)dev_priv->pci_buf,
-                                    cmd->size);
-       return ret;
-}
-
-static int via_pci_cmdbuffer(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_cmdbuffer_t *cmdbuf = data;
-       int ret;
-
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       DRM_DEBUG("buf %p size %lu\n", cmdbuf->buf, cmdbuf->size);
-
-       ret = via_dispatch_pci_cmdbuffer(dev, cmdbuf);
-       if (ret) {
-               return ret;
-       }
-
-       return 0;
-}
-
-static inline uint32_t *via_align_buffer(drm_via_private_t * dev_priv,
-                                        uint32_t * vb, int qw_count)
-{
-       for (; qw_count > 0; --qw_count) {
-               VIA_OUT_RING_QW(HC_DUMMY, HC_DUMMY);
-       }
-       return vb;
-}
-
-/*
- * This function is used internally by ring buffer management code.
- *
- * Returns virtual pointer to ring buffer.
- */
-static inline uint32_t *via_get_dma(drm_via_private_t * dev_priv)
-{
-       return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
-}
-
-/*
- * Hooks a segment of data into the tail of the ring-buffer by
- * modifying the pause address stored in the buffer itself. If
- * the regulator has already paused, restart it.
- */
-static int via_hook_segment(drm_via_private_t * dev_priv,
-                           uint32_t pause_addr_hi, uint32_t pause_addr_lo,
-                           int no_pci_fire)
-{
-       int paused, count;
-       volatile uint32_t *paused_at = dev_priv->last_pause_ptr;
-       uint32_t reader,ptr;
-       uint32_t diff;
-
-       paused = 0;
-       via_flush_write_combine();
-       (void) *(volatile uint32_t *)(via_get_dma(dev_priv) -1);
-
-       *paused_at = pause_addr_lo;
-       via_flush_write_combine();
-       (void) *paused_at;
-
-       reader = *(dev_priv->hw_addr_ptr);
-       ptr = ((volatile char *)paused_at - dev_priv->dma_ptr) +
-               dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
-
-       dev_priv->last_pause_ptr = via_get_dma(dev_priv) - 1;
-
-       /*
-        * If there is a possibility that the command reader will 
-        * miss the new pause address and pause on the old one,
-        * In that case we need to program the new start address
-        * using PCI.
-        */
-
-       diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
-       count = 10000000;
-       while(diff == 0 && count--) {
-               paused = (VIA_READ(0x41c) & 0x80000000);
-               if (paused) 
-                       break;
-               reader = *(dev_priv->hw_addr_ptr);
-               diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
-       }
-
-       paused = VIA_READ(0x41c) & 0x80000000;
-
-       if (paused && !no_pci_fire) {
-               reader = *(dev_priv->hw_addr_ptr);
-               diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
-               diff &= (dev_priv->dma_high - 1);
-               if (diff != 0 && diff < (dev_priv->dma_high >> 1)) {
-                       DRM_ERROR("Paused at incorrect address. "
-                                 "0x%08x, 0x%08x 0x%08x\n",
-                                 ptr, reader, dev_priv->dma_diff);
-               } else if (diff == 0) {
-                       /*
-                        * There is a concern that these writes may stall the PCI bus
-                        * if the GPU is not idle. However, idling the GPU first
-                        * doesn't make a difference.
-                        */
-
-                       VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
-                       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
-                       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
-                       VIA_READ(VIA_REG_TRANSPACE);
-               }
-       }
-       return paused;
-}
-
-static int via_wait_idle(drm_via_private_t * dev_priv)
-{
-       int count = 10000000;
-
-       while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
-
-       while (count-- && (VIA_READ(VIA_REG_STATUS) &
-                          (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
-                           VIA_3D_ENG_BUSY))) ;
-       return count;
-}
-
-static uint32_t *via_align_cmd(drm_via_private_t * dev_priv, uint32_t cmd_type,
-                              uint32_t addr, uint32_t * cmd_addr_hi,
-                              uint32_t * cmd_addr_lo, int skip_wait)
-{
-       uint32_t agp_base;
-       uint32_t cmd_addr, addr_lo, addr_hi;
-       uint32_t *vb;
-       uint32_t qw_pad_count;
-
-       if (!skip_wait)
-               via_cmdbuf_wait(dev_priv, 2 * CMDBUF_ALIGNMENT_SIZE);
-
-       vb = via_get_dma(dev_priv);
-       VIA_OUT_RING_QW(HC_HEADER2 | ((VIA_REG_TRANSET >> 2) << 12) |
-                       (VIA_REG_TRANSPACE >> 2), HC_ParaType_PreCR << 16);
-       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       qw_pad_count = (CMDBUF_ALIGNMENT_SIZE >> 3) -
-           ((dev_priv->dma_low & CMDBUF_ALIGNMENT_MASK) >> 3);
-
-       cmd_addr = (addr) ? addr :
-           agp_base + dev_priv->dma_low - 8 + (qw_pad_count << 3);
-       addr_lo = ((HC_SubA_HAGPBpL << 24) | (cmd_type & HC_HAGPBpID_MASK) |
-                  (cmd_addr & HC_HAGPBpL_MASK));
-       addr_hi = ((HC_SubA_HAGPBpH << 24) | (cmd_addr >> 24));
-
-       vb = via_align_buffer(dev_priv, vb, qw_pad_count - 1);
-       VIA_OUT_RING_QW(*cmd_addr_hi = addr_hi, *cmd_addr_lo = addr_lo);
-       return vb;
-}
-
-static void via_cmdbuf_start(drm_via_private_t * dev_priv)
-{
-       uint32_t pause_addr_lo, pause_addr_hi;
-       uint32_t start_addr, start_addr_lo;
-       uint32_t end_addr, end_addr_lo;
-       uint32_t command;
-       uint32_t agp_base;
-       uint32_t ptr;
-       uint32_t reader;
-       int count;
-
-       dev_priv->dma_low = 0;
-
-       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       start_addr = agp_base;
-       end_addr = agp_base + dev_priv->dma_high;
-
-       start_addr_lo = ((HC_SubA_HAGPBstL << 24) | (start_addr & 0xFFFFFF));
-       end_addr_lo = ((HC_SubA_HAGPBendL << 24) | (end_addr & 0xFFFFFF));
-       command = ((HC_SubA_HAGPCMNT << 24) | (start_addr >> 24) |
-                  ((end_addr & 0xff000000) >> 16));
-
-       dev_priv->last_pause_ptr =
-           via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0,
-                         &pause_addr_hi, &pause_addr_lo, 1) - 1;
-
-       via_flush_write_combine();
-       (void) *(volatile uint32_t *)dev_priv->last_pause_ptr;
-
-       VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
-       VIA_WRITE(VIA_REG_TRANSPACE, command);
-       VIA_WRITE(VIA_REG_TRANSPACE, start_addr_lo);
-       VIA_WRITE(VIA_REG_TRANSPACE, end_addr_lo);
-
-       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
-       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
-       DRM_WRITEMEMORYBARRIER();
-       VIA_WRITE(VIA_REG_TRANSPACE, command | HC_HAGPCMNT_MASK);
-       VIA_READ(VIA_REG_TRANSPACE);
-
-       dev_priv->dma_diff = 0;
-
-       count = 10000000;
-       while (!(VIA_READ(0x41c) & 0x80000000) && count--);
-
-       reader = *(dev_priv->hw_addr_ptr);
-       ptr = ((volatile char *)dev_priv->last_pause_ptr - dev_priv->dma_ptr) +
-           dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
-
-       /*
-        * This is the difference between where we tell the
-        * command reader to pause and where it actually pauses.
-        * This differs between hw implementation so we need to
-        * detect it.
-        */
-
-       dev_priv->dma_diff = ptr - reader;
-}
-
-static void via_pad_cache(drm_via_private_t * dev_priv, int qwords)
-{
-       uint32_t *vb;
-
-       via_cmdbuf_wait(dev_priv, qwords + 2);
-       vb = via_get_dma(dev_priv);
-       VIA_OUT_RING_QW(HC_HEADER2, HC_ParaType_NotTex << 16);
-       via_align_buffer(dev_priv, vb, qwords);
-}
-
-static inline void via_dummy_bitblt(drm_via_private_t * dev_priv)
-{
-       uint32_t *vb = via_get_dma(dev_priv);
-       SetReg2DAGP(0x0C, (0 | (0 << 16)));
-       SetReg2DAGP(0x10, 0 | (0 << 16));
-       SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xAA000000);
-}
-
-static void via_cmdbuf_jump(drm_via_private_t * dev_priv)
-{
-       uint32_t agp_base;
-       uint32_t pause_addr_lo, pause_addr_hi;
-       uint32_t jump_addr_lo, jump_addr_hi;
-       volatile uint32_t *last_pause_ptr;
-       uint32_t dma_low_save1, dma_low_save2;
-
-       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-       via_align_cmd(dev_priv, HC_HAGPBpID_JUMP, 0, &jump_addr_hi,
-                     &jump_addr_lo, 0);
-
-       dev_priv->dma_wrap = dev_priv->dma_low;
-
-       /*
-        * Wrap command buffer to the beginning.
-        */
-
-       dev_priv->dma_low = 0;
-       if (via_cmdbuf_wait(dev_priv, CMDBUF_ALIGNMENT_SIZE) != 0) {
-               DRM_ERROR("via_cmdbuf_jump failed\n");
-       }
-
-       via_dummy_bitblt(dev_priv);
-       via_dummy_bitblt(dev_priv);
-
-       last_pause_ptr =
-           via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
-                         &pause_addr_lo, 0) - 1;
-       via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
-                     &pause_addr_lo, 0);
-
-       *last_pause_ptr = pause_addr_lo;
-       dma_low_save1 = dev_priv->dma_low;
-
-       /*
-        * Now, set a trap that will pause the regulator if it tries to rerun the old
-        * command buffer. (Which may happen if via_hook_segment detecs a command regulator pause
-        * and reissues the jump command over PCI, while the regulator has already taken the jump
-        * and actually paused at the current buffer end).
-        * There appears to be no other way to detect this condition, since the hw_addr_pointer
-        * does not seem to get updated immediately when a jump occurs.
-        */
-
-       last_pause_ptr =
-               via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
-                             &pause_addr_lo, 0) - 1;
-       via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
-                     &pause_addr_lo, 0);
-       *last_pause_ptr = pause_addr_lo;
-
-       dma_low_save2 = dev_priv->dma_low;
-       dev_priv->dma_low = dma_low_save1;
-       via_hook_segment(dev_priv, jump_addr_hi, jump_addr_lo, 0);
-       dev_priv->dma_low = dma_low_save2;
-       via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
-}
-
-
-static void via_cmdbuf_rewind(drm_via_private_t * dev_priv)
-{
-       via_cmdbuf_jump(dev_priv);
-}
-
-static void via_cmdbuf_flush(drm_via_private_t * dev_priv, uint32_t cmd_type)
-{
-       uint32_t pause_addr_lo, pause_addr_hi;
-
-       via_align_cmd(dev_priv, cmd_type, 0, &pause_addr_hi, &pause_addr_lo, 0);
-       via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
-}
-
-static void via_cmdbuf_pause(drm_via_private_t * dev_priv)
-{
-       via_cmdbuf_flush(dev_priv, HC_HAGPBpID_PAUSE);
-}
-
-static void via_cmdbuf_reset(drm_via_private_t * dev_priv)
-{
-       via_cmdbuf_flush(dev_priv, HC_HAGPBpID_STOP);
-       via_wait_idle(dev_priv);
-}
-
-/*
- * User interface to the space and lag functions.
- */
-
-static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_cmdbuf_size_t *d_siz = data;
-       int ret = 0;
-       uint32_t tmp_size, count;
-       drm_via_private_t *dev_priv;
-
-       DRM_DEBUG("\n");
-       LOCK_TEST_WITH_RETURN(dev, file_priv);
-
-       dev_priv = (drm_via_private_t *) dev->dev_private;
-
-       if (dev_priv->ring.virtual_start == NULL) {
-               DRM_ERROR("called without initializing AGP ring buffer.\n");
-               return -EFAULT;
-       }
-
-       count = 1000000;
-       tmp_size = d_siz->size;
-       switch (d_siz->func) {
-       case VIA_CMDBUF_SPACE:
-               while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
-                      && count--) {
-                       if (!d_siz->wait) {
-                               break;
-                       }
-               }
-               if (!count) {
-                       DRM_ERROR("VIA_CMDBUF_SPACE timed out.\n");
-                       ret = -EAGAIN;
-               }
-               break;
-       case VIA_CMDBUF_LAG:
-               while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
-                      && count--) {
-                       if (!d_siz->wait) {
-                               break;
-                       }
-               }
-               if (!count) {
-                       DRM_ERROR("VIA_CMDBUF_LAG timed out.\n");
-                       ret = -EAGAIN;
-               }
-               break;
-       default:
-               ret = -EFAULT;
-       }
-       d_siz->size = tmp_size;
-
-       return ret;
-}
-
-struct drm_ioctl_desc via_ioctls[] = {
-       DRM_IOCTL_DEF(DRM_VIA_ALLOCMEM, via_mem_alloc, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_FREEMEM, via_mem_free, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_AGP_INIT, via_agp_init, DRM_AUTH|DRM_MASTER),
-       DRM_IOCTL_DEF(DRM_VIA_FB_INIT, via_fb_init, DRM_AUTH|DRM_MASTER),
-       DRM_IOCTL_DEF(DRM_VIA_MAP_INIT, via_map_init, DRM_AUTH|DRM_MASTER),
-       DRM_IOCTL_DEF(DRM_VIA_DEC_FUTEX, via_decoder_futex, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_DMA_INIT, via_dma_init, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_CMDBUFFER, via_cmdbuffer, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_FLUSH, via_flush_ioctl, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_PCICMD, via_pci_cmdbuffer, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_CMDBUF_SIZE, via_cmdbuf_size, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_WAIT_IRQ, via_wait_irq, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_DMA_BLIT, via_dma_blit, DRM_AUTH),
-       DRM_IOCTL_DEF(DRM_VIA_BLIT_SYNC, via_dma_blit_sync, DRM_AUTH)
-};
-
-int via_max_ioctl = DRM_ARRAY_SIZE(via_ioctls);
diff --git a/drivers/char/drm/via_dmablit.c b/drivers/char/drm/via_dmablit.c
deleted file mode 100644 (file)
index 409e00a..0000000
+++ /dev/null
@@ -1,816 +0,0 @@
-/* via_dmablit.c -- PCI DMA BitBlt support for the VIA Unichrome/Pro
- *
- * Copyright (C) 2005 Thomas Hellstrom, All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Thomas Hellstrom.
- *    Partially based on code obtained from Digeo Inc.
- */
-
-
-/*
- * Unmaps the DMA mappings.
- * FIXME: Is this a NoOp on x86? Also
- * FIXME: What happens if this one is called and a pending blit has previously done
- * the same DMA mappings?
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-#include "via_dmablit.h"
-
-#include <linux/pagemap.h>
-
-#define VIA_PGDN(x)         (((unsigned long)(x)) & PAGE_MASK)
-#define VIA_PGOFF(x)       (((unsigned long)(x)) & ~PAGE_MASK)
-#define VIA_PFN(x)           ((unsigned long)(x) >> PAGE_SHIFT)
-
-typedef struct _drm_via_descriptor {
-       uint32_t mem_addr;
-       uint32_t dev_addr;
-       uint32_t size;
-       uint32_t next;
-} drm_via_descriptor_t;
-
-
-/*
- * Unmap a DMA mapping.
- */
-
-
-
-static void
-via_unmap_blit_from_device(struct pci_dev *pdev, drm_via_sg_info_t *vsg)
-{
-       int num_desc = vsg->num_desc;
-       unsigned cur_descriptor_page = num_desc / vsg->descriptors_per_page;
-       unsigned descriptor_this_page = num_desc % vsg->descriptors_per_page;
-       drm_via_descriptor_t *desc_ptr = vsg->desc_pages[cur_descriptor_page] +
-               descriptor_this_page;
-       dma_addr_t next = vsg->chain_start;
-
-       while(num_desc--) {
-               if (descriptor_this_page-- == 0) {
-                       cur_descriptor_page--;
-                       descriptor_this_page = vsg->descriptors_per_page - 1;
-                       desc_ptr = vsg->desc_pages[cur_descriptor_page] +
-                               descriptor_this_page;
-               }
-               dma_unmap_single(&pdev->dev, next, sizeof(*desc_ptr), DMA_TO_DEVICE);
-               dma_unmap_page(&pdev->dev, desc_ptr->mem_addr, desc_ptr->size, vsg->direction);
-               next = (dma_addr_t) desc_ptr->next;
-               desc_ptr--;
-       }
-}
-
-/*
- * If mode = 0, count how many descriptors are needed.
- * If mode = 1, Map the DMA pages for the device, put together and map also the descriptors.
- * Descriptors are run in reverse order by the hardware because we are not allowed to update the
- * 'next' field without syncing calls when the descriptor is already mapped.
- */
-
-static void
-via_map_blit_for_device(struct pci_dev *pdev,
-                  const drm_via_dmablit_t *xfer,
-                  drm_via_sg_info_t *vsg,
-                  int mode)
-{
-       unsigned cur_descriptor_page = 0;
-       unsigned num_descriptors_this_page = 0;
-       unsigned char *mem_addr = xfer->mem_addr;
-       unsigned char *cur_mem;
-       unsigned char *first_addr = (unsigned char *)VIA_PGDN(mem_addr);
-       uint32_t fb_addr = xfer->fb_addr;
-       uint32_t cur_fb;
-       unsigned long line_len;
-       unsigned remaining_len;
-       int num_desc = 0;
-       int cur_line;
-       dma_addr_t next = 0 | VIA_DMA_DPR_EC;
-       drm_via_descriptor_t *desc_ptr = NULL;
-
-       if (mode == 1)
-               desc_ptr = vsg->desc_pages[cur_descriptor_page];
-
-       for (cur_line = 0; cur_line < xfer->num_lines; ++cur_line) {
-
-               line_len = xfer->line_length;
-               cur_fb = fb_addr;
-               cur_mem = mem_addr;
-
-               while (line_len > 0) {
-
-                       remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len);
-                       line_len -= remaining_len;
-
-                       if (mode == 1) {
-                               desc_ptr->mem_addr =
-                                       dma_map_page(&pdev->dev,
-                                                    vsg->pages[VIA_PFN(cur_mem) -
-                                                               VIA_PFN(first_addr)],
-                                                    VIA_PGOFF(cur_mem), remaining_len,
-                                                    vsg->direction);
-                               desc_ptr->dev_addr = cur_fb;
-
-                               desc_ptr->size = remaining_len;
-                               desc_ptr->next = (uint32_t) next;
-                               next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr),
-                                                     DMA_TO_DEVICE);
-                               desc_ptr++;
-                               if (++num_descriptors_this_page >= vsg->descriptors_per_page) {
-                                       num_descriptors_this_page = 0;
-                                       desc_ptr = vsg->desc_pages[++cur_descriptor_page];
-                               }
-                       }
-
-                       num_desc++;
-                       cur_mem += remaining_len;
-                       cur_fb += remaining_len;
-               }
-
-               mem_addr += xfer->mem_stride;
-               fb_addr += xfer->fb_stride;
-       }
-
-       if (mode == 1) {
-               vsg->chain_start = next;
-               vsg->state = dr_via_device_mapped;
-       }
-       vsg->num_desc = num_desc;
-}
-
-/*
- * Function that frees up all resources for a blit. It is usable even if the
- * blit info has only been partially built as long as the status enum is consistent
- * with the actual status of the used resources.
- */
-
-
-static void
-via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg)
-{
-       struct page *page;
-       int i;
-
-       switch(vsg->state) {
-       case dr_via_device_mapped:
-               via_unmap_blit_from_device(pdev, vsg);
-       case dr_via_desc_pages_alloc:
-               for (i=0; i<vsg->num_desc_pages; ++i) {
-                       if (vsg->desc_pages[i] != NULL)
-                         free_page((unsigned long)vsg->desc_pages[i]);
-               }
-               kfree(vsg->desc_pages);
-       case dr_via_pages_locked:
-               for (i=0; i<vsg->num_pages; ++i) {
-                       if ( NULL != (page = vsg->pages[i])) {
-                               if (! PageReserved(page) && (DMA_FROM_DEVICE == vsg->direction))
-                                       SetPageDirty(page);
-                               page_cache_release(page);
-                       }
-               }
-       case dr_via_pages_alloc:
-               vfree(vsg->pages);
-       default:
-               vsg->state = dr_via_sg_init;
-       }
-       if (vsg->bounce_buffer) {
-               vfree(vsg->bounce_buffer);
-               vsg->bounce_buffer = NULL;
-       }
-       vsg->free_on_sequence = 0;
-}
-
-/*
- * Fire a blit engine.
- */
-
-static void
-via_fire_dmablit(struct drm_device *dev, drm_via_sg_info_t *vsg, int engine)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-
-       VIA_WRITE(VIA_PCI_DMA_MAR0 + engine*0x10, 0);
-       VIA_WRITE(VIA_PCI_DMA_DAR0 + engine*0x10, 0);
-       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DD | VIA_DMA_CSR_TD |
-                 VIA_DMA_CSR_DE);
-       VIA_WRITE(VIA_PCI_DMA_MR0  + engine*0x04, VIA_DMA_MR_CM | VIA_DMA_MR_TDIE);
-       VIA_WRITE(VIA_PCI_DMA_BCR0 + engine*0x10, 0);
-       VIA_WRITE(VIA_PCI_DMA_DPR0 + engine*0x10, vsg->chain_start);
-       DRM_WRITEMEMORYBARRIER();
-       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DE | VIA_DMA_CSR_TS);
-       VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04);
-}
-
-/*
- * Obtain a page pointer array and lock all pages into system memory. A segmentation violation will
- * occur here if the calling user does not have access to the submitted address.
- */
-
-static int
-via_lock_all_dma_pages(drm_via_sg_info_t *vsg,  drm_via_dmablit_t *xfer)
-{
-       int ret;
-       unsigned long first_pfn = VIA_PFN(xfer->mem_addr);
-       vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride -1)) -
-               first_pfn + 1;
-
-       if (NULL == (vsg->pages = vmalloc(sizeof(struct page *) * vsg->num_pages)))
-               return -ENOMEM;
-       memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages);
-       down_read(&current->mm->mmap_sem);
-       ret = get_user_pages(current, current->mm,
-                            (unsigned long)xfer->mem_addr,
-                            vsg->num_pages,
-                            (vsg->direction == DMA_FROM_DEVICE),
-                            0, vsg->pages, NULL);
-
-       up_read(&current->mm->mmap_sem);
-       if (ret != vsg->num_pages) {
-               if (ret < 0)
-                       return ret;
-               vsg->state = dr_via_pages_locked;
-               return -EINVAL;
-       }
-       vsg->state = dr_via_pages_locked;
-       DRM_DEBUG("DMA pages locked\n");
-       return 0;
-}
-
-/*
- * Allocate DMA capable memory for the blit descriptor chain, and an array that keeps track of the
- * pages we allocate. We don't want to use kmalloc for the descriptor chain because it may be
- * quite large for some blits, and pages don't need to be contingous.
- */
-
-static int
-via_alloc_desc_pages(drm_via_sg_info_t *vsg)
-{
-       int i;
-
-       vsg->descriptors_per_page = PAGE_SIZE / sizeof( drm_via_descriptor_t);
-       vsg->num_desc_pages = (vsg->num_desc + vsg->descriptors_per_page - 1) /
-               vsg->descriptors_per_page;
-
-       if (NULL ==  (vsg->desc_pages = kcalloc(vsg->num_desc_pages, sizeof(void *), GFP_KERNEL)))
-               return -ENOMEM;
-
-       vsg->state = dr_via_desc_pages_alloc;
-       for (i=0; i<vsg->num_desc_pages; ++i) {
-               if (NULL == (vsg->desc_pages[i] =
-                            (drm_via_descriptor_t *) __get_free_page(GFP_KERNEL)))
-                       return -ENOMEM;
-       }
-       DRM_DEBUG("Allocated %d pages for %d descriptors.\n", vsg->num_desc_pages,
-                 vsg->num_desc);
-       return 0;
-}
-
-static void
-via_abort_dmablit(struct drm_device *dev, int engine)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-
-       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TA);
-}
-
-static void
-via_dmablit_engine_off(struct drm_device *dev, int engine)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-
-       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD | VIA_DMA_CSR_DD);
-}
-
-
-
-/*
- * The dmablit part of the IRQ handler. Trying to do only reasonably fast things here.
- * The rest, like unmapping and freeing memory for done blits is done in a separate workqueue
- * task. Basically the task of the interrupt handler is to submit a new blit to the engine, while
- * the workqueue task takes care of processing associated with the old blit.
- */
-
-void
-via_dmablit_handler(struct drm_device *dev, int engine, int from_irq)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-       drm_via_blitq_t *blitq = dev_priv->blit_queues + engine;
-       int cur;
-       int done_transfer;
-       unsigned long irqsave=0;
-       uint32_t status = 0;
-
-       DRM_DEBUG("DMA blit handler called. engine = %d, from_irq = %d, blitq = 0x%lx\n",
-                 engine, from_irq, (unsigned long) blitq);
-
-       if (from_irq) {
-               spin_lock(&blitq->blit_lock);
-       } else {
-               spin_lock_irqsave(&blitq->blit_lock, irqsave);
-       }
-
-       done_transfer = blitq->is_active &&
-         (( status = VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04)) & VIA_DMA_CSR_TD);
-       done_transfer = done_transfer || ( blitq->aborting && !(status & VIA_DMA_CSR_DE));
-
-       cur = blitq->cur;
-       if (done_transfer) {
-
-               blitq->blits[cur]->aborted = blitq->aborting;
-               blitq->done_blit_handle++;
-               DRM_WAKEUP(blitq->blit_queue + cur);
-
-               cur++;
-               if (cur >= VIA_NUM_BLIT_SLOTS)
-                       cur = 0;
-               blitq->cur = cur;
-
-               /*
-                * Clear transfer done flag.
-                */
-
-               VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04,  VIA_DMA_CSR_TD);
-
-               blitq->is_active = 0;
-               blitq->aborting = 0;
-               schedule_work(&blitq->wq);
-
-       } else if (blitq->is_active && time_after_eq(jiffies, blitq->end)) {
-
-               /*
-                * Abort transfer after one second.
-                */
-
-               via_abort_dmablit(dev, engine);
-               blitq->aborting = 1;
-               blitq->end = jiffies + DRM_HZ;
-       }
-
-       if (!blitq->is_active) {
-               if (blitq->num_outstanding) {
-                       via_fire_dmablit(dev, blitq->blits[cur], engine);
-                       blitq->is_active = 1;
-                       blitq->cur = cur;
-                       blitq->num_outstanding--;
-                       blitq->end = jiffies + DRM_HZ;
-                       if (!timer_pending(&blitq->poll_timer))
-                               mod_timer(&blitq->poll_timer, jiffies + 1);
-               } else {
-                       if (timer_pending(&blitq->poll_timer)) {
-                               del_timer(&blitq->poll_timer);
-                       }
-                       via_dmablit_engine_off(dev, engine);
-               }
-       }
-
-       if (from_irq) {
-               spin_unlock(&blitq->blit_lock);
-       } else {
-               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-       }
-}
-
-
-
-/*
- * Check whether this blit is still active, performing necessary locking.
- */
-
-static int
-via_dmablit_active(drm_via_blitq_t *blitq, int engine, uint32_t handle, wait_queue_head_t **queue)
-{
-       unsigned long irqsave;
-       uint32_t slot;
-       int active;
-
-       spin_lock_irqsave(&blitq->blit_lock, irqsave);
-
-       /*
-        * Allow for handle wraparounds.
-        */
-
-       active = ((blitq->done_blit_handle - handle) > (1 << 23)) &&
-               ((blitq->cur_blit_handle - handle) <= (1 << 23));
-
-       if (queue && active) {
-               slot = handle - blitq->done_blit_handle + blitq->cur -1;
-               if (slot >= VIA_NUM_BLIT_SLOTS) {
-                       slot -= VIA_NUM_BLIT_SLOTS;
-               }
-               *queue = blitq->blit_queue + slot;
-       }
-
-       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-
-       return active;
-}
-
-/*
- * Sync. Wait for at least three seconds for the blit to be performed.
- */
-
-static int
-via_dmablit_sync(struct drm_device *dev, uint32_t handle, int engine)
-{
-
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-       drm_via_blitq_t *blitq = dev_priv->blit_queues + engine;
-       wait_queue_head_t *queue;
-       int ret = 0;
-
-       if (via_dmablit_active(blitq, engine, handle, &queue)) {
-               DRM_WAIT_ON(ret, *queue, 3 * DRM_HZ,
-                           !via_dmablit_active(blitq, engine, handle, NULL));
-       }
-       DRM_DEBUG("DMA blit sync handle 0x%x engine %d returned %d\n",
-                 handle, engine, ret);
-
-       return ret;
-}
-
-
-/*
- * A timer that regularly polls the blit engine in cases where we don't have interrupts:
- * a) Broken hardware (typically those that don't have any video capture facility).
- * b) Blit abort. The hardware doesn't send an interrupt when a blit is aborted.
- * The timer and hardware IRQ's can and do work in parallel. If the hardware has
- * irqs, it will shorten the latency somewhat.
- */
-
-
-
-static void
-via_dmablit_timer(unsigned long data)
-{
-       drm_via_blitq_t *blitq = (drm_via_blitq_t *) data;
-       struct drm_device *dev = blitq->dev;
-       int engine = (int)
-               (blitq - ((drm_via_private_t *)dev->dev_private)->blit_queues);
-
-       DRM_DEBUG("Polling timer called for engine %d, jiffies %lu\n", engine,
-                 (unsigned long) jiffies);
-
-       via_dmablit_handler(dev, engine, 0);
-
-       if (!timer_pending(&blitq->poll_timer)) {
-               mod_timer(&blitq->poll_timer, jiffies + 1);
-
-              /*
-               * Rerun handler to delete timer if engines are off, and
-               * to shorten abort latency. This is a little nasty.
-               */
-
-              via_dmablit_handler(dev, engine, 0);
-
-       }
-}
-
-
-
-
-/*
- * Workqueue task that frees data and mappings associated with a blit.
- * Also wakes up waiting processes. Each of these tasks handles one
- * blit engine only and may not be called on each interrupt.
- */
-
-
-static void
-via_dmablit_workqueue(struct work_struct *work)
-{
-       drm_via_blitq_t *blitq = container_of(work, drm_via_blitq_t, wq);
-       struct drm_device *dev = blitq->dev;
-       unsigned long irqsave;
-       drm_via_sg_info_t *cur_sg;
-       int cur_released;
-
-
-       DRM_DEBUG("Workqueue task called for blit engine %ld\n",(unsigned long)
-                 (blitq - ((drm_via_private_t *)dev->dev_private)->blit_queues));
-
-       spin_lock_irqsave(&blitq->blit_lock, irqsave);
-
-       while(blitq->serviced != blitq->cur) {
-
-               cur_released = blitq->serviced++;
-
-               DRM_DEBUG("Releasing blit slot %d\n", cur_released);
-
-               if (blitq->serviced >= VIA_NUM_BLIT_SLOTS)
-                       blitq->serviced = 0;
-
-               cur_sg = blitq->blits[cur_released];
-               blitq->num_free++;
-
-               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-
-               DRM_WAKEUP(&blitq->busy_queue);
-
-               via_free_sg_info(dev->pdev, cur_sg);
-               kfree(cur_sg);
-
-               spin_lock_irqsave(&blitq->blit_lock, irqsave);
-       }
-
-       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-}
-
-
-/*
- * Init all blit engines. Currently we use two, but some hardware have 4.
- */
-
-
-void
-via_init_dmablit(struct drm_device *dev)
-{
-       int i,j;
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-       drm_via_blitq_t *blitq;
-
-       pci_set_master(dev->pdev);
-
-       for (i=0; i< VIA_NUM_BLIT_ENGINES; ++i) {
-               blitq = dev_priv->blit_queues + i;
-               blitq->dev = dev;
-               blitq->cur_blit_handle = 0;
-               blitq->done_blit_handle = 0;
-               blitq->head = 0;
-               blitq->cur = 0;
-               blitq->serviced = 0;
-               blitq->num_free = VIA_NUM_BLIT_SLOTS - 1;
-               blitq->num_outstanding = 0;
-               blitq->is_active = 0;
-               blitq->aborting = 0;
-               spin_lock_init(&blitq->blit_lock);
-               for (j=0; j<VIA_NUM_BLIT_SLOTS; ++j) {
-                       DRM_INIT_WAITQUEUE(blitq->blit_queue + j);
-               }
-               DRM_INIT_WAITQUEUE(&blitq->busy_queue);
-               INIT_WORK(&blitq->wq, via_dmablit_workqueue);
-               setup_timer(&blitq->poll_timer, via_dmablit_timer,
-                               (unsigned long)blitq);
-       }
-}
-
-/*
- * Build all info and do all mappings required for a blit.
- */
-
-
-static int
-via_build_sg_info(struct drm_device *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
-{
-       int draw = xfer->to_fb;
-       int ret = 0;
-
-       vsg->direction = (draw) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-       vsg->bounce_buffer = NULL;
-
-       vsg->state = dr_via_sg_init;
-
-       if (xfer->num_lines <= 0 || xfer->line_length <= 0) {
-               DRM_ERROR("Zero size bitblt.\n");
-               return -EINVAL;
-       }
-
-       /*
-        * Below check is a driver limitation, not a hardware one. We
-        * don't want to lock unused pages, and don't want to incoporate the
-        * extra logic of avoiding them. Make sure there are no.
-        * (Not a big limitation anyway.)
-        */
-
-       if ((xfer->mem_stride - xfer->line_length) > 2*PAGE_SIZE) {
-               DRM_ERROR("Too large system memory stride. Stride: %d, "
-                         "Length: %d\n", xfer->mem_stride, xfer->line_length);
-               return -EINVAL;
-       }
-
-       if ((xfer->mem_stride == xfer->line_length) &&
-          (xfer->fb_stride == xfer->line_length)) {
-               xfer->mem_stride *= xfer->num_lines;
-               xfer->line_length = xfer->mem_stride;
-               xfer->fb_stride = xfer->mem_stride;
-               xfer->num_lines = 1;
-       }
-
-       /*
-        * Don't lock an arbitrary large number of pages, since that causes a
-        * DOS security hole.
-        */
-
-       if (xfer->num_lines > 2048 || (xfer->num_lines*xfer->mem_stride > (2048*2048*4))) {
-               DRM_ERROR("Too large PCI DMA bitblt.\n");
-               return -EINVAL;
-       }
-
-       /*
-        * we allow a negative fb stride to allow flipping of images in
-        * transfer.
-        */
-
-       if (xfer->mem_stride < xfer->line_length ||
-               abs(xfer->fb_stride) < xfer->line_length) {
-               DRM_ERROR("Invalid frame-buffer / memory stride.\n");
-               return -EINVAL;
-       }
-
-       /*
-        * A hardware bug seems to be worked around if system memory addresses start on
-        * 16 byte boundaries. This seems a bit restrictive however. VIA is contacted
-        * about this. Meanwhile, impose the following restrictions:
-        */
-
-#ifdef VIA_BUGFREE
-       if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) ||
-           ((xfer->num_lines > 1) && ((xfer->mem_stride & 3) != (xfer->fb_stride & 3)))) {
-               DRM_ERROR("Invalid DRM bitblt alignment.\n");
-               return -EINVAL;
-       }
-#else
-       if ((((unsigned long)xfer->mem_addr & 15) ||
-             ((unsigned long)xfer->fb_addr & 3)) ||
-          ((xfer->num_lines > 1) &&
-          ((xfer->mem_stride & 15) || (xfer->fb_stride & 3)))) {
-               DRM_ERROR("Invalid DRM bitblt alignment.\n");
-               return -EINVAL;
-       }
-#endif
-
-       if (0 != (ret = via_lock_all_dma_pages(vsg, xfer))) {
-               DRM_ERROR("Could not lock DMA pages.\n");
-               via_free_sg_info(dev->pdev, vsg);
-               return ret;
-       }
-
-       via_map_blit_for_device(dev->pdev, xfer, vsg, 0);
-       if (0 != (ret = via_alloc_desc_pages(vsg))) {
-               DRM_ERROR("Could not allocate DMA descriptor pages.\n");
-               via_free_sg_info(dev->pdev, vsg);
-               return ret;
-       }
-       via_map_blit_for_device(dev->pdev, xfer, vsg, 1);
-
-       return 0;
-}
-
-
-/*
- * Reserve one free slot in the blit queue. Will wait for one second for one
- * to become available. Otherwise -EBUSY is returned.
- */
-
-static int
-via_dmablit_grab_slot(drm_via_blitq_t *blitq, int engine)
-{
-       int ret=0;
-       unsigned long irqsave;
-
-       DRM_DEBUG("Num free is %d\n", blitq->num_free);
-       spin_lock_irqsave(&blitq->blit_lock, irqsave);
-       while(blitq->num_free == 0) {
-               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-
-               DRM_WAIT_ON(ret, blitq->busy_queue, DRM_HZ, blitq->num_free > 0);
-               if (ret) {
-                       return (-EINTR == ret) ? -EAGAIN : ret;
-               }
-
-               spin_lock_irqsave(&blitq->blit_lock, irqsave);
-       }
-
-       blitq->num_free--;
-       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-
-       return 0;
-}
-
-/*
- * Hand back a free slot if we changed our mind.
- */
-
-static void
-via_dmablit_release_slot(drm_via_blitq_t *blitq)
-{
-       unsigned long irqsave;
-
-       spin_lock_irqsave(&blitq->blit_lock, irqsave);
-       blitq->num_free++;
-       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-       DRM_WAKEUP( &blitq->busy_queue );
-}
-
-/*
- * Grab a free slot. Build blit info and queue a blit.
- */
-
-
-static int
-via_dmablit(struct drm_device *dev, drm_via_dmablit_t *xfer)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
-       drm_via_sg_info_t *vsg;
-       drm_via_blitq_t *blitq;
-       int ret;
-       int engine;
-       unsigned long irqsave;
-
-       if (dev_priv == NULL) {
-               DRM_ERROR("Called without initialization.\n");
-               return -EINVAL;
-       }
-
-       engine = (xfer->to_fb) ? 0 : 1;
-       blitq = dev_priv->blit_queues + engine;
-       if (0 != (ret = via_dmablit_grab_slot(blitq, engine))) {
-               return ret;
-       }
-       if (NULL == (vsg = kmalloc(sizeof(*vsg), GFP_KERNEL))) {
-               via_dmablit_release_slot(blitq);
-               return -ENOMEM;
-       }
-       if (0 != (ret = via_build_sg_info(dev, vsg, xfer))) {
-               via_dmablit_release_slot(blitq);
-               kfree(vsg);
-               return ret;
-       }
-       spin_lock_irqsave(&blitq->blit_lock, irqsave);
-
-       blitq->blits[blitq->head++] = vsg;
-       if (blitq->head >= VIA_NUM_BLIT_SLOTS)
-               blitq->head = 0;
-       blitq->num_outstanding++;
-       xfer->sync.sync_handle = ++blitq->cur_blit_handle;
-
-       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
-       xfer->sync.engine = engine;
-
-       via_dmablit_handler(dev, engine, 0);
-
-       return 0;
-}
-
-/*
- * Sync on a previously submitted blit. Note that the X server use signals extensively, and
- * that there is a very big probability that this IOCTL will be interrupted by a signal. In that
- * case it returns with -EAGAIN for the signal to be delivered.
- * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock().
- */
-
-int
-via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv )
-{
-       drm_via_blitsync_t *sync = data;
-       int err;
-
-       if (sync->engine >= VIA_NUM_BLIT_ENGINES)
-               return -EINVAL;
-
-       err = via_dmablit_sync(dev, sync->sync_handle, sync->engine);
-
-       if (-EINTR == err)
-               err = -EAGAIN;
-
-       return err;
-}
-
-
-/*
- * Queue a blit and hand back a handle to be used for sync. This IOCTL may be interrupted by a signal
- * while waiting for a free slot in the blit queue. In that case it returns with -EAGAIN and should
- * be reissued. See the above IOCTL code.
- */
-
-int
-via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv )
-{
-       drm_via_dmablit_t *xfer = data;
-       int err;
-
-       err = via_dmablit(dev, xfer);
-
-       return err;
-}
diff --git a/drivers/char/drm/via_dmablit.h b/drivers/char/drm/via_dmablit.h
deleted file mode 100644 (file)
index 7408a54..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/* via_dmablit.h -- PCI DMA BitBlt support for the VIA Unichrome/Pro
- *
- * Copyright 2005 Thomas Hellstrom.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Thomas Hellstrom.
- *    Register info from Digeo Inc.
- */
-
-#ifndef _VIA_DMABLIT_H
-#define _VIA_DMABLIT_H
-
-#include <linux/dma-mapping.h>
-
-#define VIA_NUM_BLIT_ENGINES 2
-#define VIA_NUM_BLIT_SLOTS 8
-
-struct _drm_via_descriptor;
-
-typedef struct _drm_via_sg_info {
-       struct page **pages;
-       unsigned long num_pages;
-       struct _drm_via_descriptor **desc_pages;
-       int num_desc_pages;
-       int num_desc;
-       enum dma_data_direction direction;
-       unsigned char *bounce_buffer;
-        dma_addr_t chain_start;
-       uint32_t free_on_sequence;
-        unsigned int descriptors_per_page;
-       int aborted;
-       enum {
-               dr_via_device_mapped,
-               dr_via_desc_pages_alloc,
-               dr_via_pages_locked,
-               dr_via_pages_alloc,
-               dr_via_sg_init
-       } state;
-} drm_via_sg_info_t;
-
-typedef struct _drm_via_blitq {
-       struct drm_device *dev;
-       uint32_t cur_blit_handle;
-       uint32_t done_blit_handle;
-       unsigned serviced;
-       unsigned head;
-       unsigned cur;
-       unsigned num_free;
-       unsigned num_outstanding;
-       unsigned long end;
-        int aborting;
-       int is_active;
-       drm_via_sg_info_t *blits[VIA_NUM_BLIT_SLOTS];
-       spinlock_t blit_lock;
-       wait_queue_head_t blit_queue[VIA_NUM_BLIT_SLOTS];
-       wait_queue_head_t busy_queue;
-       struct work_struct wq;
-       struct timer_list poll_timer;
-} drm_via_blitq_t;
-
-
-/*
- *  PCI DMA Registers
- *  Channels 2 & 3 don't seem to be implemented in hardware.
- */
-
-#define VIA_PCI_DMA_MAR0            0xE40   /* Memory Address Register of Channel 0 */
-#define VIA_PCI_DMA_DAR0            0xE44   /* Device Address Register of Channel 0 */
-#define VIA_PCI_DMA_BCR0            0xE48   /* Byte Count Register of Channel 0 */
-#define VIA_PCI_DMA_DPR0            0xE4C   /* Descriptor Pointer Register of Channel 0 */
-
-#define VIA_PCI_DMA_MAR1            0xE50   /* Memory Address Register of Channel 1 */
-#define VIA_PCI_DMA_DAR1            0xE54   /* Device Address Register of Channel 1 */
-#define VIA_PCI_DMA_BCR1            0xE58   /* Byte Count Register of Channel 1 */
-#define VIA_PCI_DMA_DPR1            0xE5C   /* Descriptor Pointer Register of Channel 1 */
-
-#define VIA_PCI_DMA_MAR2            0xE60   /* Memory Address Register of Channel 2 */
-#define VIA_PCI_DMA_DAR2            0xE64   /* Device Address Register of Channel 2 */
-#define VIA_PCI_DMA_BCR2            0xE68   /* Byte Count Register of Channel 2 */
-#define VIA_PCI_DMA_DPR2            0xE6C   /* Descriptor Pointer Register of Channel 2 */
-
-#define VIA_PCI_DMA_MAR3            0xE70   /* Memory Address Register of Channel 3 */
-#define VIA_PCI_DMA_DAR3            0xE74   /* Device Address Register of Channel 3 */
-#define VIA_PCI_DMA_BCR3            0xE78   /* Byte Count Register of Channel 3 */
-#define VIA_PCI_DMA_DPR3            0xE7C   /* Descriptor Pointer Register of Channel 3 */
-
-#define VIA_PCI_DMA_MR0             0xE80   /* Mode Register of Channel 0 */
-#define VIA_PCI_DMA_MR1             0xE84   /* Mode Register of Channel 1 */
-#define VIA_PCI_DMA_MR2             0xE88   /* Mode Register of Channel 2 */
-#define VIA_PCI_DMA_MR3             0xE8C   /* Mode Register of Channel 3 */
-
-#define VIA_PCI_DMA_CSR0            0xE90   /* Command/Status Register of Channel 0 */
-#define VIA_PCI_DMA_CSR1            0xE94   /* Command/Status Register of Channel 1 */
-#define VIA_PCI_DMA_CSR2            0xE98   /* Command/Status Register of Channel 2 */
-#define VIA_PCI_DMA_CSR3            0xE9C   /* Command/Status Register of Channel 3 */
-
-#define VIA_PCI_DMA_PTR             0xEA0   /* Priority Type Register */
-
-/* Define for DMA engine */
-/* DPR */
-#define VIA_DMA_DPR_EC         (1<<1)  /* end of chain */
-#define VIA_DMA_DPR_DDIE       (1<<2)  /* descriptor done interrupt enable */
-#define VIA_DMA_DPR_DT         (1<<3)  /* direction of transfer (RO) */
-
-/* MR */
-#define VIA_DMA_MR_CM          (1<<0)  /* chaining mode */
-#define VIA_DMA_MR_TDIE                (1<<1)  /* transfer done interrupt enable */
-#define VIA_DMA_MR_HENDMACMD           (1<<7) /* ? */
-
-/* CSR */
-#define VIA_DMA_CSR_DE         (1<<0)  /* DMA enable */
-#define VIA_DMA_CSR_TS         (1<<1)  /* transfer start */
-#define VIA_DMA_CSR_TA         (1<<2)  /* transfer abort */
-#define VIA_DMA_CSR_TD         (1<<3)  /* transfer done */
-#define VIA_DMA_CSR_DD         (1<<4)  /* descriptor done */
-#define VIA_DMA_DPR_EC          (1<<1)  /* end of chain */
-
-
-
-#endif
diff --git a/drivers/char/drm/via_drm.h b/drivers/char/drm/via_drm.h
deleted file mode 100644 (file)
index a3b5c10..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#ifndef _VIA_DRM_H_
-#define _VIA_DRM_H_
-
-/* WARNING: These defines must be the same as what the Xserver uses.
- * if you change them, you must change the defines in the Xserver.
- */
-
-#ifndef _VIA_DEFINES_
-#define _VIA_DEFINES_
-
-#ifndef __KERNEL__
-#include "via_drmclient.h"
-#endif
-
-#define VIA_NR_SAREA_CLIPRECTS         8
-#define VIA_NR_XVMC_PORTS               10
-#define VIA_NR_XVMC_LOCKS               5
-#define VIA_MAX_CACHELINE_SIZE          64
-#define XVMCLOCKPTR(saPriv,lockNo)                                     \
-       ((volatile struct drm_hw_lock *)(((((unsigned long) (saPriv)->XvMCLockArea) + \
-                                     (VIA_MAX_CACHELINE_SIZE - 1)) &   \
-                                    ~(VIA_MAX_CACHELINE_SIZE - 1)) +   \
-                                   VIA_MAX_CACHELINE_SIZE*(lockNo)))
-
-/* Each region is a minimum of 64k, and there are at most 64 of them.
- */
-#define VIA_NR_TEX_REGIONS 64
-#define VIA_LOG_MIN_TEX_REGION_SIZE 16
-#endif
-
-#define VIA_UPLOAD_TEX0IMAGE  0x1      /* handled clientside */
-#define VIA_UPLOAD_TEX1IMAGE  0x2      /* handled clientside */
-#define VIA_UPLOAD_CTX        0x4
-#define VIA_UPLOAD_BUFFERS    0x8
-#define VIA_UPLOAD_TEX0       0x10
-#define VIA_UPLOAD_TEX1       0x20
-#define VIA_UPLOAD_CLIPRECTS  0x40
-#define VIA_UPLOAD_ALL        0xff
-
-/* VIA specific ioctls */
-#define DRM_VIA_ALLOCMEM       0x00
-#define DRM_VIA_FREEMEM                0x01
-#define DRM_VIA_AGP_INIT       0x02
-#define DRM_VIA_FB_INIT                0x03
-#define DRM_VIA_MAP_INIT       0x04
-#define DRM_VIA_DEC_FUTEX       0x05
-#define NOT_USED
-#define DRM_VIA_DMA_INIT       0x07
-#define DRM_VIA_CMDBUFFER      0x08
-#define DRM_VIA_FLUSH          0x09
-#define DRM_VIA_PCICMD         0x0a
-#define DRM_VIA_CMDBUF_SIZE    0x0b
-#define NOT_USED
-#define DRM_VIA_WAIT_IRQ        0x0d
-#define DRM_VIA_DMA_BLIT        0x0e
-#define DRM_VIA_BLIT_SYNC       0x0f
-
-#define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, drm_via_mem_t)
-#define DRM_IOCTL_VIA_FREEMEM    DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, drm_via_mem_t)
-#define DRM_IOCTL_VIA_AGP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_AGP_INIT, drm_via_agp_t)
-#define DRM_IOCTL_VIA_FB_INIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, drm_via_fb_t)
-#define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, drm_via_init_t)
-#define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_DEC_FUTEX, drm_via_futex_t)
-#define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, drm_via_dma_init_t)
-#define DRM_IOCTL_VIA_CMDBUFFER          DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
-#define DRM_IOCTL_VIA_FLUSH      DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
-#define DRM_IOCTL_VIA_PCICMD     DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_PCICMD, drm_via_cmdbuffer_t)
-#define DRM_IOCTL_VIA_CMDBUF_SIZE DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_CMDBUF_SIZE, \
-                                           drm_via_cmdbuf_size_t)
-#define DRM_IOCTL_VIA_WAIT_IRQ    DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_WAIT_IRQ, drm_via_irqwait_t)
-#define DRM_IOCTL_VIA_DMA_BLIT    DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_DMA_BLIT, drm_via_dmablit_t)
-#define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
-
-/* Indices into buf.Setup where various bits of state are mirrored per
- * context and per buffer.  These can be fired at the card as a unit,
- * or in a piecewise fashion as required.
- */
-
-#define VIA_TEX_SETUP_SIZE 8
-
-/* Flags for clear ioctl
- */
-#define VIA_FRONT   0x1
-#define VIA_BACK    0x2
-#define VIA_DEPTH   0x4
-#define VIA_STENCIL 0x8
-#define VIA_MEM_VIDEO   0      /* matches drm constant */
-#define VIA_MEM_AGP     1      /* matches drm constant */
-#define VIA_MEM_SYSTEM  2
-#define VIA_MEM_MIXED   3
-#define VIA_MEM_UNKNOWN 4
-
-typedef struct {
-       uint32_t offset;
-       uint32_t size;
-} drm_via_agp_t;
-
-typedef struct {
-       uint32_t offset;
-       uint32_t size;
-} drm_via_fb_t;
-
-typedef struct {
-       uint32_t context;
-       uint32_t type;
-       uint32_t size;
-       unsigned long index;
-       unsigned long offset;
-} drm_via_mem_t;
-
-typedef struct _drm_via_init {
-       enum {
-               VIA_INIT_MAP = 0x01,
-               VIA_CLEANUP_MAP = 0x02
-       } func;
-
-       unsigned long sarea_priv_offset;
-       unsigned long fb_offset;
-       unsigned long mmio_offset;
-       unsigned long agpAddr;
-} drm_via_init_t;
-
-typedef struct _drm_via_futex {
-       enum {
-               VIA_FUTEX_WAIT = 0x00,
-               VIA_FUTEX_WAKE = 0X01
-       } func;
-       uint32_t ms;
-       uint32_t lock;
-       uint32_t val;
-} drm_via_futex_t;
-
-typedef struct _drm_via_dma_init {
-       enum {
-               VIA_INIT_DMA = 0x01,
-               VIA_CLEANUP_DMA = 0x02,
-               VIA_DMA_INITIALIZED = 0x03
-       } func;
-
-       unsigned long offset;
-       unsigned long size;
-       unsigned long reg_pause_addr;
-} drm_via_dma_init_t;
-
-typedef struct _drm_via_cmdbuffer {
-       char __user *buf;
-       unsigned long size;
-} drm_via_cmdbuffer_t;
-
-/* Warning: If you change the SAREA structure you must change the Xserver
- * structure as well */
-
-typedef struct _drm_via_tex_region {
-       unsigned char next, prev;       /* indices to form a circular LRU  */
-       unsigned char inUse;    /* owned by a client, or free? */
-       int age;                /* tracked by clients to update local LRU's */
-} drm_via_tex_region_t;
-
-typedef struct _drm_via_sarea {
-       unsigned int dirty;
-       unsigned int nbox;
-       struct drm_clip_rect boxes[VIA_NR_SAREA_CLIPRECTS];
-       drm_via_tex_region_t texList[VIA_NR_TEX_REGIONS + 1];
-       int texAge;             /* last time texture was uploaded */
-       int ctxOwner;           /* last context to upload state */
-       int vertexPrim;
-
-       /*
-        * Below is for XvMC.
-        * We want the lock integers alone on, and aligned to, a cache line.
-        * Therefore this somewhat strange construct.
-        */
-
-       char XvMCLockArea[VIA_MAX_CACHELINE_SIZE * (VIA_NR_XVMC_LOCKS + 1)];
-
-       unsigned int XvMCDisplaying[VIA_NR_XVMC_PORTS];
-       unsigned int XvMCSubPicOn[VIA_NR_XVMC_PORTS];
-       unsigned int XvMCCtxNoGrabbed;  /* Last context to hold decoder */
-
-       /* Used by the 3d driver only at this point, for pageflipping:
-        */
-       unsigned int pfCurrentOffset;
-} drm_via_sarea_t;
-
-typedef struct _drm_via_cmdbuf_size {
-       enum {
-               VIA_CMDBUF_SPACE = 0x01,
-               VIA_CMDBUF_LAG = 0x02
-       } func;
-       int wait;
-       uint32_t size;
-} drm_via_cmdbuf_size_t;
-
-typedef enum {
-       VIA_IRQ_ABSOLUTE = 0x0,
-       VIA_IRQ_RELATIVE = 0x1,
-       VIA_IRQ_SIGNAL = 0x10000000,
-       VIA_IRQ_FORCE_SEQUENCE = 0x20000000
-} via_irq_seq_type_t;
-
-#define VIA_IRQ_FLAGS_MASK 0xF0000000
-
-enum drm_via_irqs {
-       drm_via_irq_hqv0 = 0,
-       drm_via_irq_hqv1,
-       drm_via_irq_dma0_dd,
-       drm_via_irq_dma0_td,
-       drm_via_irq_dma1_dd,
-       drm_via_irq_dma1_td,
-       drm_via_irq_num
-};
-
-struct drm_via_wait_irq_request {
-       unsigned irq;
-       via_irq_seq_type_t type;
-       uint32_t sequence;
-       uint32_t signal;
-};
-
-typedef union drm_via_irqwait {
-       struct drm_via_wait_irq_request request;
-       struct drm_wait_vblank_reply reply;
-} drm_via_irqwait_t;
-
-typedef struct drm_via_blitsync {
-       uint32_t sync_handle;
-       unsigned engine;
-} drm_via_blitsync_t;
-
-/* - * Below,"flags" is currently unused but will be used for possible future
- * extensions like kernel space bounce buffers for bad alignments and
- * blit engine busy-wait polling for better latency in the absence of
- * interrupts.
- */
-
-typedef struct drm_via_dmablit {
-       uint32_t num_lines;
-       uint32_t line_length;
-
-       uint32_t fb_addr;
-       uint32_t fb_stride;
-
-       unsigned char *mem_addr;
-       uint32_t mem_stride;
-
-       uint32_t flags;
-       int to_fb;
-
-       drm_via_blitsync_t sync;
-} drm_via_dmablit_t;
-
-#endif                         /* _VIA_DRM_H_ */
diff --git a/drivers/char/drm/via_drv.c b/drivers/char/drm/via_drv.c
deleted file mode 100644 (file)
index 80c01cd..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-#include "drm_pciids.h"
-
-static int dri_library_name(struct drm_device *dev, char *buf)
-{
-       return snprintf(buf, PAGE_SIZE, "unichrome");
-}
-
-static struct pci_device_id pciidlist[] = {
-       viadrv_PCI_IDS
-};
-
-static struct drm_driver driver = {
-       .driver_features =
-           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
-           DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
-       .load = via_driver_load,
-       .unload = via_driver_unload,
-       .context_dtor = via_final_context,
-       .vblank_wait = via_driver_vblank_wait,
-       .irq_preinstall = via_driver_irq_preinstall,
-       .irq_postinstall = via_driver_irq_postinstall,
-       .irq_uninstall = via_driver_irq_uninstall,
-       .irq_handler = via_driver_irq_handler,
-       .dma_quiescent = via_driver_dma_quiescent,
-       .dri_library_name = dri_library_name,
-       .reclaim_buffers = drm_core_reclaim_buffers,
-       .reclaim_buffers_locked = NULL,
-       .reclaim_buffers_idlelocked = via_reclaim_buffers_locked,
-       .lastclose = via_lastclose,
-       .get_map_ofs = drm_core_get_map_ofs,
-       .get_reg_ofs = drm_core_get_reg_ofs,
-       .ioctls = via_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-       },
-       .pci_driver = {
-                .name = DRIVER_NAME,
-                .id_table = pciidlist,
-       },
-
-       .name = DRIVER_NAME,
-       .desc = DRIVER_DESC,
-       .date = DRIVER_DATE,
-       .major = DRIVER_MAJOR,
-       .minor = DRIVER_MINOR,
-       .patchlevel = DRIVER_PATCHLEVEL,
-};
-
-static int __init via_init(void)
-{
-       driver.num_ioctls = via_max_ioctl;
-       via_init_command_verifier();
-       return drm_init(&driver);
-}
-
-static void __exit via_exit(void)
-{
-       drm_exit(&driver);
-}
-
-module_init(via_init);
-module_exit(via_exit);
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/char/drm/via_drv.h b/drivers/char/drm/via_drv.h
deleted file mode 100644 (file)
index 2daae81..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#ifndef _VIA_DRV_H_
-#define _VIA_DRV_H_
-
-#include "drm_sman.h"
-#define DRIVER_AUTHOR  "Various"
-
-#define DRIVER_NAME            "via"
-#define DRIVER_DESC            "VIA Unichrome / Pro"
-#define DRIVER_DATE            "20070202"
-
-#define DRIVER_MAJOR           2
-#define DRIVER_MINOR           11
-#define DRIVER_PATCHLEVEL      1
-
-#include "via_verifier.h"
-
-#include "via_dmablit.h"
-
-#define VIA_PCI_BUF_SIZE 60000
-#define VIA_FIRE_BUF_SIZE  1024
-#define VIA_NUM_IRQS 4
-
-typedef struct drm_via_ring_buffer {
-       drm_local_map_t map;
-       char *virtual_start;
-} drm_via_ring_buffer_t;
-
-typedef uint32_t maskarray_t[5];
-
-typedef struct drm_via_irq {
-       atomic_t irq_received;
-       uint32_t pending_mask;
-       uint32_t enable_mask;
-       wait_queue_head_t irq_queue;
-} drm_via_irq_t;
-
-typedef struct drm_via_private {
-       drm_via_sarea_t *sarea_priv;
-       drm_local_map_t *sarea;
-       drm_local_map_t *fb;
-       drm_local_map_t *mmio;
-       unsigned long agpAddr;
-       wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
-       char *dma_ptr;
-       unsigned int dma_low;
-       unsigned int dma_high;
-       unsigned int dma_offset;
-       uint32_t dma_wrap;
-       volatile uint32_t *last_pause_ptr;
-       volatile uint32_t *hw_addr_ptr;
-       drm_via_ring_buffer_t ring;
-       struct timeval last_vblank;
-       int last_vblank_valid;
-       unsigned usec_per_vblank;
-       drm_via_state_t hc_state;
-       char pci_buf[VIA_PCI_BUF_SIZE];
-       const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
-       uint32_t num_fire_offsets;
-       int chipset;
-       drm_via_irq_t via_irqs[VIA_NUM_IRQS];
-       unsigned num_irqs;
-       maskarray_t *irq_masks;
-       uint32_t irq_enable_mask;
-       uint32_t irq_pending_mask;
-       int *irq_map;
-       unsigned int idle_fault;
-       struct drm_sman sman;
-       int vram_initialized;
-       int agp_initialized;
-       unsigned long vram_offset;
-       unsigned long agp_offset;
-       drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
-       uint32_t dma_diff;
-} drm_via_private_t;
-
-enum via_family {
-  VIA_OTHER = 0,     /* Baseline */
-  VIA_PRO_GROUP_A,   /* Another video engine and DMA commands */
-  VIA_DX9_0          /* Same video as pro_group_a, but 3D is unsupported */
-};
-
-/* VIA MMIO register access */
-#define VIA_BASE ((dev_priv->mmio))
-
-#define VIA_READ(reg)          DRM_READ32(VIA_BASE, reg)
-#define VIA_WRITE(reg,val)     DRM_WRITE32(VIA_BASE, reg, val)
-#define VIA_READ8(reg)         DRM_READ8(VIA_BASE, reg)
-#define VIA_WRITE8(reg,val)    DRM_WRITE8(VIA_BASE, reg, val)
-
-extern struct drm_ioctl_desc via_ioctls[];
-extern int via_max_ioctl;
-
-extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
-extern int via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv );
-extern int via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv );
-
-extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
-extern int via_driver_unload(struct drm_device *dev);
-
-extern int via_init_context(struct drm_device * dev, int context);
-extern int via_final_context(struct drm_device * dev, int context);
-
-extern int via_do_cleanup_map(struct drm_device * dev);
-extern int via_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
-
-extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
-extern void via_driver_irq_preinstall(struct drm_device * dev);
-extern void via_driver_irq_postinstall(struct drm_device * dev);
-extern void via_driver_irq_uninstall(struct drm_device * dev);
-
-extern int via_dma_cleanup(struct drm_device * dev);
-extern void via_init_command_verifier(void);
-extern int via_driver_dma_quiescent(struct drm_device * dev);
-extern void via_init_futex(drm_via_private_t * dev_priv);
-extern void via_cleanup_futex(drm_via_private_t * dev_priv);
-extern void via_release_futex(drm_via_private_t * dev_priv, int context);
-
-extern void via_reclaim_buffers_locked(struct drm_device *dev, struct drm_file *file_priv);
-extern void via_lastclose(struct drm_device *dev);
-
-extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
-extern void via_init_dmablit(struct drm_device *dev);
-
-#endif
diff --git a/drivers/char/drm/via_irq.c b/drivers/char/drm/via_irq.c
deleted file mode 100644 (file)
index c6bb978..0000000
+++ /dev/null
@@ -1,377 +0,0 @@
-/* via_irq.c
- *
- * Copyright 2004 BEAM Ltd.
- * Copyright 2002 Tungsten Graphics, Inc.
- * Copyright 2005 Thomas Hellstrom.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BEAM LTD, TUNGSTEN GRAPHICS  AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Terry Barnaby <terry1@beam.ltd.uk>
- *    Keith Whitwell <keith@tungstengraphics.com>
- *    Thomas Hellstrom <unichrome@shipmail.org>
- *
- * This code provides standard DRM access to the Via Unichrome / Pro Vertical blank
- * interrupt, as well as an infrastructure to handle other interrupts of the chip.
- * The refresh rate is also calculated for video playback sync purposes.
- */
-
-#include "drmP.h"
-#include "drm.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-#define VIA_REG_INTERRUPT       0x200
-
-/* VIA_REG_INTERRUPT */
-#define VIA_IRQ_GLOBAL          (1 << 31)
-#define VIA_IRQ_VBLANK_ENABLE   (1 << 19)
-#define VIA_IRQ_VBLANK_PENDING  (1 << 3)
-#define VIA_IRQ_HQV0_ENABLE     (1 << 11)
-#define VIA_IRQ_HQV1_ENABLE     (1 << 25)
-#define VIA_IRQ_HQV0_PENDING    (1 << 9)
-#define VIA_IRQ_HQV1_PENDING    (1 << 10)
-#define VIA_IRQ_DMA0_DD_ENABLE  (1 << 20)
-#define VIA_IRQ_DMA0_TD_ENABLE  (1 << 21)
-#define VIA_IRQ_DMA1_DD_ENABLE  (1 << 22)
-#define VIA_IRQ_DMA1_TD_ENABLE  (1 << 23)
-#define VIA_IRQ_DMA0_DD_PENDING (1 << 4)
-#define VIA_IRQ_DMA0_TD_PENDING (1 << 5)
-#define VIA_IRQ_DMA1_DD_PENDING (1 << 6)
-#define VIA_IRQ_DMA1_TD_PENDING (1 << 7)
-
-
-/*
- * Device-specific IRQs go here. This type might need to be extended with
- * the register if there are multiple IRQ control registers.
- * Currently we activate the HQV interrupts of  Unichrome Pro group A.
- */
-
-static maskarray_t via_pro_group_a_irqs[] = {
-       {VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010,
-        0x00000000},
-       {VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010,
-        0x00000000},
-       {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
-        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
-       {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
-        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
-};
-static int via_num_pro_group_a =
-    sizeof(via_pro_group_a_irqs) / sizeof(maskarray_t);
-static int via_irqmap_pro_group_a[] = {0, 1, -1, 2, -1, 3};
-
-static maskarray_t via_unichrome_irqs[] = {
-       {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
-        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
-       {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
-        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}
-};
-static int via_num_unichrome = sizeof(via_unichrome_irqs) / sizeof(maskarray_t);
-static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1};
-
-static unsigned time_diff(struct timeval *now, struct timeval *then)
-{
-       return (now->tv_usec >= then->tv_usec) ?
-           now->tv_usec - then->tv_usec :
-           1000000 - (then->tv_usec - now->tv_usec);
-}
-
-irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
-{
-       struct drm_device *dev = (struct drm_device *) arg;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       u32 status;
-       int handled = 0;
-       struct timeval cur_vblank;
-       drm_via_irq_t *cur_irq = dev_priv->via_irqs;
-       int i;
-
-       status = VIA_READ(VIA_REG_INTERRUPT);
-       if (status & VIA_IRQ_VBLANK_PENDING) {
-               atomic_inc(&dev->vbl_received);
-               if (!(atomic_read(&dev->vbl_received) & 0x0F)) {
-                       do_gettimeofday(&cur_vblank);
-                       if (dev_priv->last_vblank_valid) {
-                               dev_priv->usec_per_vblank =
-                                   time_diff(&cur_vblank,
-                                             &dev_priv->last_vblank) >> 4;
-                       }
-                       dev_priv->last_vblank = cur_vblank;
-                       dev_priv->last_vblank_valid = 1;
-               }
-               if (!(atomic_read(&dev->vbl_received) & 0xFF)) {
-                       DRM_DEBUG("US per vblank is: %u\n",
-                                 dev_priv->usec_per_vblank);
-               }
-               DRM_WAKEUP(&dev->vbl_queue);
-               drm_vbl_send_signals(dev);
-               handled = 1;
-       }
-
-       for (i = 0; i < dev_priv->num_irqs; ++i) {
-               if (status & cur_irq->pending_mask) {
-                       atomic_inc(&cur_irq->irq_received);
-                       DRM_WAKEUP(&cur_irq->irq_queue);
-                       handled = 1;
-                       if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
-                               via_dmablit_handler(dev, 0, 1);
-                       } else if (dev_priv->irq_map[drm_via_irq_dma1_td] == i) {
-                               via_dmablit_handler(dev, 1, 1);
-                       }
-               }
-               cur_irq++;
-       }
-
-       /* Acknowlege interrupts */
-       VIA_WRITE(VIA_REG_INTERRUPT, status);
-
-       if (handled)
-               return IRQ_HANDLED;
-       else
-               return IRQ_NONE;
-}
-
-static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t * dev_priv)
-{
-       u32 status;
-
-       if (dev_priv) {
-               /* Acknowlege interrupts */
-               status = VIA_READ(VIA_REG_INTERRUPT);
-               VIA_WRITE(VIA_REG_INTERRUPT, status |
-                         dev_priv->irq_pending_mask);
-       }
-}
-
-int via_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       unsigned int cur_vblank;
-       int ret = 0;
-
-       DRM_DEBUG("\n");
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       viadrv_acknowledge_irqs(dev_priv);
-
-       /* Assume that the user has missed the current sequence number
-        * by about a day rather than she wants to wait for years
-        * using vertical blanks...
-        */
-
-       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
-                   (((cur_vblank = atomic_read(&dev->vbl_received)) -
-                     *sequence) <= (1 << 23)));
-
-       *sequence = cur_vblank;
-       return ret;
-}
-
-static int
-via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequence,
-                   unsigned int *sequence)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       unsigned int cur_irq_sequence;
-       drm_via_irq_t *cur_irq;
-       int ret = 0;
-       maskarray_t *masks;
-       int real_irq;
-
-       DRM_DEBUG("\n");
-
-       if (!dev_priv) {
-               DRM_ERROR("called with no initialization\n");
-               return -EINVAL;
-       }
-
-       if (irq >= drm_via_irq_num) {
-               DRM_ERROR("Trying to wait on unknown irq %d\n", irq);
-               return -EINVAL;
-       }
-
-       real_irq = dev_priv->irq_map[irq];
-
-       if (real_irq < 0) {
-               DRM_ERROR("Video IRQ %d not available on this hardware.\n",
-                         irq);
-               return -EINVAL;
-       }
-
-       masks = dev_priv->irq_masks;
-       cur_irq = dev_priv->via_irqs + real_irq;
-
-       if (masks[real_irq][2] && !force_sequence) {
-               DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
-                           ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
-                            masks[irq][4]));
-               cur_irq_sequence = atomic_read(&cur_irq->irq_received);
-       } else {
-               DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
-                           (((cur_irq_sequence =
-                              atomic_read(&cur_irq->irq_received)) -
-                             *sequence) <= (1 << 23)));
-       }
-       *sequence = cur_irq_sequence;
-       return ret;
-}
-
-/*
- * drm_dma.h hooks
- */
-
-void via_driver_irq_preinstall(struct drm_device * dev)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       u32 status;
-       drm_via_irq_t *cur_irq;
-       int i;
-
-       DRM_DEBUG("dev_priv: %p\n", dev_priv);
-       if (dev_priv) {
-               cur_irq = dev_priv->via_irqs;
-
-               dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE;
-               dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING;
-
-               if (dev_priv->chipset == VIA_PRO_GROUP_A ||
-                   dev_priv->chipset == VIA_DX9_0) {
-                       dev_priv->irq_masks = via_pro_group_a_irqs;
-                       dev_priv->num_irqs = via_num_pro_group_a;
-                       dev_priv->irq_map = via_irqmap_pro_group_a;
-               } else {
-                       dev_priv->irq_masks = via_unichrome_irqs;
-                       dev_priv->num_irqs = via_num_unichrome;
-                       dev_priv->irq_map = via_irqmap_unichrome;
-               }
-
-               for (i = 0; i < dev_priv->num_irqs; ++i) {
-                       atomic_set(&cur_irq->irq_received, 0);
-                       cur_irq->enable_mask = dev_priv->irq_masks[i][0];
-                       cur_irq->pending_mask = dev_priv->irq_masks[i][1];
-                       DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
-                       dev_priv->irq_enable_mask |= cur_irq->enable_mask;
-                       dev_priv->irq_pending_mask |= cur_irq->pending_mask;
-                       cur_irq++;
-
-                       DRM_DEBUG("Initializing IRQ %d\n", i);
-               }
-
-               dev_priv->last_vblank_valid = 0;
-
-               /* Clear VSync interrupt regs */
-               status = VIA_READ(VIA_REG_INTERRUPT);
-               VIA_WRITE(VIA_REG_INTERRUPT, status &
-                         ~(dev_priv->irq_enable_mask));
-
-               /* Clear bits if they're already high */
-               viadrv_acknowledge_irqs(dev_priv);
-       }
-}
-
-void via_driver_irq_postinstall(struct drm_device * dev)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       u32 status;
-
-       DRM_DEBUG("\n");
-       if (dev_priv) {
-               status = VIA_READ(VIA_REG_INTERRUPT);
-               VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_GLOBAL
-                         | dev_priv->irq_enable_mask);
-
-               /* Some magic, oh for some data sheets ! */
-
-               VIA_WRITE8(0x83d4, 0x11);
-               VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30);
-
-       }
-}
-
-void via_driver_irq_uninstall(struct drm_device * dev)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       u32 status;
-
-       DRM_DEBUG("\n");
-       if (dev_priv) {
-
-               /* Some more magic, oh for some data sheets ! */
-
-               VIA_WRITE8(0x83d4, 0x11);
-               VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30);
-
-               status = VIA_READ(VIA_REG_INTERRUPT);
-               VIA_WRITE(VIA_REG_INTERRUPT, status &
-                         ~(VIA_IRQ_VBLANK_ENABLE | dev_priv->irq_enable_mask));
-       }
-}
-
-int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_irqwait_t *irqwait = data;
-       struct timeval now;
-       int ret = 0;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       drm_via_irq_t *cur_irq = dev_priv->via_irqs;
-       int force_sequence;
-
-       if (!dev->irq)
-               return -EINVAL;
-
-       if (irqwait->request.irq >= dev_priv->num_irqs) {
-               DRM_ERROR("Trying to wait on unknown irq %d\n",
-                         irqwait->request.irq);
-               return -EINVAL;
-       }
-
-       cur_irq += irqwait->request.irq;
-
-       switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
-       case VIA_IRQ_RELATIVE:
-               irqwait->request.sequence += atomic_read(&cur_irq->irq_received);
-               irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
-       case VIA_IRQ_ABSOLUTE:
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       if (irqwait->request.type & VIA_IRQ_SIGNAL) {
-               DRM_ERROR("Signals on Via IRQs not implemented yet.\n");
-               return -EINVAL;
-       }
-
-       force_sequence = (irqwait->request.type & VIA_IRQ_FORCE_SEQUENCE);
-
-       ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence,
-                                 &irqwait->request.sequence);
-       do_gettimeofday(&now);
-       irqwait->reply.tval_sec = now.tv_sec;
-       irqwait->reply.tval_usec = now.tv_usec;
-
-       return ret;
-}
diff --git a/drivers/char/drm/via_map.c b/drivers/char/drm/via_map.c
deleted file mode 100644 (file)
index a967556..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-static int via_do_init_map(struct drm_device * dev, drm_via_init_t * init)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-
-       DRM_DEBUG("\n");
-
-       dev_priv->sarea = drm_getsarea(dev);
-       if (!dev_priv->sarea) {
-               DRM_ERROR("could not find sarea!\n");
-               dev->dev_private = (void *)dev_priv;
-               via_do_cleanup_map(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
-       if (!dev_priv->fb) {
-               DRM_ERROR("could not find framebuffer!\n");
-               dev->dev_private = (void *)dev_priv;
-               via_do_cleanup_map(dev);
-               return -EINVAL;
-       }
-       dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
-       if (!dev_priv->mmio) {
-               DRM_ERROR("could not find mmio region!\n");
-               dev->dev_private = (void *)dev_priv;
-               via_do_cleanup_map(dev);
-               return -EINVAL;
-       }
-
-       dev_priv->sarea_priv =
-           (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
-                                init->sarea_priv_offset);
-
-       dev_priv->agpAddr = init->agpAddr;
-
-       via_init_futex(dev_priv);
-
-       via_init_dmablit(dev);
-
-       dev->dev_private = (void *)dev_priv;
-       return 0;
-}
-
-int via_do_cleanup_map(struct drm_device * dev)
-{
-       via_dma_cleanup(dev);
-
-       return 0;
-}
-
-int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_init_t *init = data;
-
-       DRM_DEBUG("\n");
-
-       switch (init->func) {
-       case VIA_INIT_MAP:
-               return via_do_init_map(dev, init);
-       case VIA_CLEANUP_MAP:
-               return via_do_cleanup_map(dev);
-       }
-
-       return -EINVAL;
-}
-
-int via_driver_load(struct drm_device *dev, unsigned long chipset)
-{
-       drm_via_private_t *dev_priv;
-       int ret = 0;
-
-       dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
-       if (dev_priv == NULL)
-               return -ENOMEM;
-
-       dev->dev_private = (void *)dev_priv;
-
-       dev_priv->chipset = chipset;
-
-       ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
-       if (ret) {
-               drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
-       }
-       return ret;
-}
-
-int via_driver_unload(struct drm_device *dev)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-
-       drm_sman_takedown(&dev_priv->sman);
-
-       drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
-
-       return 0;
-}
diff --git a/drivers/char/drm/via_mm.c b/drivers/char/drm/via_mm.c
deleted file mode 100644 (file)
index e640949..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
- * All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/*
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-#include "drm_sman.h"
-
-#define VIA_MM_ALIGN_SHIFT 4
-#define VIA_MM_ALIGN_MASK ( (1 << VIA_MM_ALIGN_SHIFT) - 1)
-
-int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_agp_t *agp = data;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_AGP, 0,
-                                agp->size >> VIA_MM_ALIGN_SHIFT);
-
-       if (ret) {
-               DRM_ERROR("AGP memory manager initialisation error\n");
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       dev_priv->agp_initialized = 1;
-       dev_priv->agp_offset = agp->offset;
-       mutex_unlock(&dev->struct_mutex);
-
-       DRM_DEBUG("offset = %u, size = %u\n", agp->offset, agp->size);
-       return 0;
-}
-
-int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_fb_t *fb = data;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_VIDEO, 0,
-                                fb->size >> VIA_MM_ALIGN_SHIFT);
-
-       if (ret) {
-               DRM_ERROR("VRAM memory manager initialisation error\n");
-               mutex_unlock(&dev->struct_mutex);
-               return ret;
-       }
-
-       dev_priv->vram_initialized = 1;
-       dev_priv->vram_offset = fb->offset;
-
-       mutex_unlock(&dev->struct_mutex);
-       DRM_DEBUG("offset = %u, size = %u\n", fb->offset, fb->size);
-
-       return 0;
-
-}
-
-int via_final_context(struct drm_device *dev, int context)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-
-       via_release_futex(dev_priv, context);
-
-       /* Linux specific until context tracking code gets ported to BSD */
-       /* Last context, perform cleanup */
-       if (dev->ctx_count == 1 && dev->dev_private) {
-               DRM_DEBUG("Last Context\n");
-               if (dev->irq)
-                       drm_irq_uninstall(dev);
-               via_cleanup_futex(dev_priv);
-               via_do_cleanup_map(dev);
-       }
-       return 1;
-}
-
-void via_lastclose(struct drm_device *dev)
-{
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-
-       if (!dev_priv)
-               return;
-
-       mutex_lock(&dev->struct_mutex);
-       drm_sman_cleanup(&dev_priv->sman);
-       dev_priv->vram_initialized = 0;
-       dev_priv->agp_initialized = 0;
-       mutex_unlock(&dev->struct_mutex);
-}
-
-int via_mem_alloc(struct drm_device *dev, void *data,
-                 struct drm_file *file_priv)
-{
-       drm_via_mem_t *mem = data;
-       int retval = 0;
-       struct drm_memblock_item *item;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       unsigned long tmpSize;
-
-       if (mem->type > VIA_MEM_AGP) {
-               DRM_ERROR("Unknown memory type allocation\n");
-               return -EINVAL;
-       }
-       mutex_lock(&dev->struct_mutex);
-       if (0 == ((mem->type == VIA_MEM_VIDEO) ? dev_priv->vram_initialized :
-                     dev_priv->agp_initialized)) {
-               DRM_ERROR
-                   ("Attempt to allocate from uninitialized memory manager.\n");
-               mutex_unlock(&dev->struct_mutex);
-               return -EINVAL;
-       }
-
-       tmpSize = (mem->size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
-       item = drm_sman_alloc(&dev_priv->sman, mem->type, tmpSize, 0,
-                             (unsigned long)file_priv);
-       mutex_unlock(&dev->struct_mutex);
-       if (item) {
-               mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
-                             dev_priv->vram_offset : dev_priv->agp_offset) +
-                   (item->mm->
-                    offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
-               mem->index = item->user_hash.key;
-       } else {
-               mem->offset = 0;
-               mem->size = 0;
-               mem->index = 0;
-               DRM_DEBUG("Video memory allocation failed\n");
-               retval = -ENOMEM;
-       }
-
-       return retval;
-}
-
-int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-       drm_via_mem_t *mem = data;
-       int ret;
-
-       mutex_lock(&dev->struct_mutex);
-       ret = drm_sman_free_key(&dev_priv->sman, mem->index);
-       mutex_unlock(&dev->struct_mutex);
-       DRM_DEBUG("free = 0x%lx\n", mem->index);
-
-       return ret;
-}
-
-
-void via_reclaim_buffers_locked(struct drm_device * dev,
-                               struct drm_file *file_priv)
-{
-       drm_via_private_t *dev_priv = dev->dev_private;
-
-       mutex_lock(&dev->struct_mutex);
-       if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) {
-               mutex_unlock(&dev->struct_mutex);
-               return;
-       }
-
-       if (dev->driver->dma_quiescent) {
-               dev->driver->dma_quiescent(dev);
-       }
-
-       drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv);
-       mutex_unlock(&dev->struct_mutex);
-       return;
-}
diff --git a/drivers/char/drm/via_verifier.c b/drivers/char/drm/via_verifier.c
deleted file mode 100644 (file)
index 46a5791..0000000
+++ /dev/null
@@ -1,1116 +0,0 @@
-/*
- * Copyright 2004 The Unichrome Project. All Rights Reserved.
- * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author: Thomas Hellstrom 2004, 2005.
- * This code was written using docs obtained under NDA from VIA Inc.
- *
- * Don't run this code directly on an AGP buffer. Due to cache problems it will
- * be very slow.
- */
-
-#include "via_3d_reg.h"
-#include "drmP.h"
-#include "drm.h"
-#include "via_drm.h"
-#include "via_verifier.h"
-#include "via_drv.h"
-
-typedef enum {
-       state_command,
-       state_header2,
-       state_header1,
-       state_vheader5,
-       state_vheader6,
-       state_error
-} verifier_state_t;
-
-typedef enum {
-       no_check = 0,
-       check_for_header2,
-       check_for_header1,
-       check_for_header2_err,
-       check_for_header1_err,
-       check_for_fire,
-       check_z_buffer_addr0,
-       check_z_buffer_addr1,
-       check_z_buffer_addr_mode,
-       check_destination_addr0,
-       check_destination_addr1,
-       check_destination_addr_mode,
-       check_for_dummy,
-       check_for_dd,
-       check_texture_addr0,
-       check_texture_addr1,
-       check_texture_addr2,
-       check_texture_addr3,
-       check_texture_addr4,
-       check_texture_addr5,
-       check_texture_addr6,
-       check_texture_addr7,
-       check_texture_addr8,
-       check_texture_addr_mode,
-       check_for_vertex_count,
-       check_number_texunits,
-       forbidden_command
-} hazard_t;
-
-/*
- * Associates each hazard above with a possible multi-command
- * sequence. For example an address that is split over multiple
- * commands and that needs to be checked at the first command
- * that does not include any part of the address.
- */
-
-static drm_via_sequence_t seqs[] = {
-       no_sequence,
-       no_sequence,
-       no_sequence,
-       no_sequence,
-       no_sequence,
-       no_sequence,
-       z_address,
-       z_address,
-       z_address,
-       dest_address,
-       dest_address,
-       dest_address,
-       no_sequence,
-       no_sequence,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       tex_address,
-       no_sequence
-};
-
-typedef struct {
-       unsigned int code;
-       hazard_t hz;
-} hz_init_t;
-
-static hz_init_t init_table1[] = {
-       {0xf2, check_for_header2_err},
-       {0xf0, check_for_header1_err},
-       {0xee, check_for_fire},
-       {0xcc, check_for_dummy},
-       {0xdd, check_for_dd},
-       {0x00, no_check},
-       {0x10, check_z_buffer_addr0},
-       {0x11, check_z_buffer_addr1},
-       {0x12, check_z_buffer_addr_mode},
-       {0x13, no_check},
-       {0x14, no_check},
-       {0x15, no_check},
-       {0x23, no_check},
-       {0x24, no_check},
-       {0x33, no_check},
-       {0x34, no_check},
-       {0x35, no_check},
-       {0x36, no_check},
-       {0x37, no_check},
-       {0x38, no_check},
-       {0x39, no_check},
-       {0x3A, no_check},
-       {0x3B, no_check},
-       {0x3C, no_check},
-       {0x3D, no_check},
-       {0x3E, no_check},
-       {0x40, check_destination_addr0},
-       {0x41, check_destination_addr1},
-       {0x42, check_destination_addr_mode},
-       {0x43, no_check},
-       {0x44, no_check},
-       {0x50, no_check},
-       {0x51, no_check},
-       {0x52, no_check},
-       {0x53, no_check},
-       {0x54, no_check},
-       {0x55, no_check},
-       {0x56, no_check},
-       {0x57, no_check},
-       {0x58, no_check},
-       {0x70, no_check},
-       {0x71, no_check},
-       {0x78, no_check},
-       {0x79, no_check},
-       {0x7A, no_check},
-       {0x7B, no_check},
-       {0x7C, no_check},
-       {0x7D, check_for_vertex_count}
-};
-
-static hz_init_t init_table2[] = {
-       {0xf2, check_for_header2_err},
-       {0xf0, check_for_header1_err},
-       {0xee, check_for_fire},
-       {0xcc, check_for_dummy},
-       {0x00, check_texture_addr0},
-       {0x01, check_texture_addr0},
-       {0x02, check_texture_addr0},
-       {0x03, check_texture_addr0},
-       {0x04, check_texture_addr0},
-       {0x05, check_texture_addr0},
-       {0x06, check_texture_addr0},
-       {0x07, check_texture_addr0},
-       {0x08, check_texture_addr0},
-       {0x09, check_texture_addr0},
-       {0x20, check_texture_addr1},
-       {0x21, check_texture_addr1},
-       {0x22, check_texture_addr1},
-       {0x23, check_texture_addr4},
-       {0x2B, check_texture_addr3},
-       {0x2C, check_texture_addr3},
-       {0x2D, check_texture_addr3},
-       {0x2E, check_texture_addr3},
-       {0x2F, check_texture_addr3},
-       {0x30, check_texture_addr3},
-       {0x31, check_texture_addr3},
-       {0x32, check_texture_addr3},
-       {0x33, check_texture_addr3},
-       {0x34, check_texture_addr3},
-       {0x4B, check_texture_addr5},
-       {0x4C, check_texture_addr6},
-       {0x51, check_texture_addr7},
-       {0x52, check_texture_addr8},
-       {0x77, check_texture_addr2},
-       {0x78, no_check},
-       {0x79, no_check},
-       {0x7A, no_check},
-       {0x7B, check_texture_addr_mode},
-       {0x7C, no_check},
-       {0x7D, no_check},
-       {0x7E, no_check},
-       {0x7F, no_check},
-       {0x80, no_check},
-       {0x81, no_check},
-       {0x82, no_check},
-       {0x83, no_check},
-       {0x85, no_check},
-       {0x86, no_check},
-       {0x87, no_check},
-       {0x88, no_check},
-       {0x89, no_check},
-       {0x8A, no_check},
-       {0x90, no_check},
-       {0x91, no_check},
-       {0x92, no_check},
-       {0x93, no_check}
-};
-
-static hz_init_t init_table3[] = {
-       {0xf2, check_for_header2_err},
-       {0xf0, check_for_header1_err},
-       {0xcc, check_for_dummy},
-       {0x00, check_number_texunits}
-};
-
-static hazard_t table1[256];
-static hazard_t table2[256];
-static hazard_t table3[256];
-
-static __inline__ int
-eat_words(const uint32_t ** buf, const uint32_t * buf_end, unsigned num_words)
-{
-       if ((buf_end - *buf) >= num_words) {
-               *buf += num_words;
-               return 0;
-       }
-       DRM_ERROR("Illegal termination of DMA command buffer\n");
-       return 1;
-}
-
-/*
- * Partially stolen from drm_memory.h
- */
-
-static __inline__ drm_local_map_t *via_drm_lookup_agp_map(drm_via_state_t *seq,
-                                                   unsigned long offset,
-                                                   unsigned long size,
-                                                   struct drm_device * dev)
-{
-       struct drm_map_list *r_list;
-       drm_local_map_t *map = seq->map_cache;
-
-       if (map && map->offset <= offset
-           && (offset + size) <= (map->offset + map->size)) {
-               return map;
-       }
-
-       list_for_each_entry(r_list, &dev->maplist, head) {
-               map = r_list->map;
-               if (!map)
-                       continue;
-               if (map->offset <= offset
-                   && (offset + size) <= (map->offset + map->size)
-                   && !(map->flags & _DRM_RESTRICTED)
-                   && (map->type == _DRM_AGP)) {
-                       seq->map_cache = map;
-                       return map;
-               }
-       }
-       return NULL;
-}
-
-/*
- * Require that all AGP texture levels reside in the same AGP map which should
- * be mappable by the client. This is not a big restriction.
- * FIXME: To actually enforce this security policy strictly, drm_rmmap
- * would have to wait for dma quiescent before removing an AGP map.
- * The via_drm_lookup_agp_map call in reality seems to take
- * very little CPU time.
- */
-
-static __inline__ int finish_current_sequence(drm_via_state_t * cur_seq)
-{
-       switch (cur_seq->unfinished) {
-       case z_address:
-               DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq->z_addr);
-               break;
-       case dest_address:
-               DRM_DEBUG("Destination start address is 0x%x\n",
-                         cur_seq->d_addr);
-               break;
-       case tex_address:
-               if (cur_seq->agp_texture) {
-                       unsigned start =
-                           cur_seq->tex_level_lo[cur_seq->texture];
-                       unsigned end = cur_seq->tex_level_hi[cur_seq->texture];
-                       unsigned long lo = ~0, hi = 0, tmp;
-                       uint32_t *addr, *pitch, *height, tex;
-                       unsigned i;
-                       int npot;
-
-                       if (end > 9)
-                               end = 9;
-                       if (start > 9)
-                               start = 9;
-
-                       addr =
-                           &(cur_seq->t_addr[tex = cur_seq->texture][start]);
-                       pitch = &(cur_seq->pitch[tex][start]);
-                       height = &(cur_seq->height[tex][start]);
-                       npot = cur_seq->tex_npot[tex];
-                       for (i = start; i <= end; ++i) {
-                               tmp = *addr++;
-                               if (tmp < lo)
-                                       lo = tmp;
-                               if (i == 0 && npot)
-                                       tmp += (*height++ * *pitch++);
-                               else
-                                       tmp += (*height++ << *pitch++);
-                               if (tmp > hi)
-                                       hi = tmp;
-                       }
-
-                       if (!via_drm_lookup_agp_map
-                           (cur_seq, lo, hi - lo, cur_seq->dev)) {
-                               DRM_ERROR
-                                   ("AGP texture is not in allowed map\n");
-                               return 2;
-                       }
-               }
-               break;
-       default:
-               break;
-       }
-       cur_seq->unfinished = no_sequence;
-       return 0;
-}
-
-static __inline__ int
-investigate_hazard(uint32_t cmd, hazard_t hz, drm_via_state_t * cur_seq)
-{
-       register uint32_t tmp, *tmp_addr;
-
-       if (cur_seq->unfinished && (cur_seq->unfinished != seqs[hz])) {
-               int ret;
-               if ((ret = finish_current_sequence(cur_seq)))
-                       return ret;
-       }
-
-       switch (hz) {
-       case check_for_header2:
-               if (cmd == HALCYON_HEADER2)
-                       return 1;
-               return 0;
-       case check_for_header1:
-               if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
-                       return 1;
-               return 0;
-       case check_for_header2_err:
-               if (cmd == HALCYON_HEADER2)
-                       return 1;
-               DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n");
-               break;
-       case check_for_header1_err:
-               if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
-                       return 1;
-               DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n");
-               break;
-       case check_for_fire:
-               if ((cmd & HALCYON_FIREMASK) == HALCYON_FIRECMD)
-                       return 1;
-               DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n");
-               break;
-       case check_for_dummy:
-               if (HC_DUMMY == cmd)
-                       return 0;
-               DRM_ERROR("Illegal DMA HC_DUMMY command\n");
-               break;
-       case check_for_dd:
-               if (0xdddddddd == cmd)
-                       return 0;
-               DRM_ERROR("Illegal DMA 0xdddddddd command\n");
-               break;
-       case check_z_buffer_addr0:
-               cur_seq->unfinished = z_address;
-               cur_seq->z_addr = (cur_seq->z_addr & 0xFF000000) |
-                   (cmd & 0x00FFFFFF);
-               return 0;
-       case check_z_buffer_addr1:
-               cur_seq->unfinished = z_address;
-               cur_seq->z_addr = (cur_seq->z_addr & 0x00FFFFFF) |
-                   ((cmd & 0xFF) << 24);
-               return 0;
-       case check_z_buffer_addr_mode:
-               cur_seq->unfinished = z_address;
-               if ((cmd & 0x0000C000) == 0)
-                       return 0;
-               DRM_ERROR("Attempt to place Z buffer in system memory\n");
-               return 2;
-       case check_destination_addr0:
-               cur_seq->unfinished = dest_address;
-               cur_seq->d_addr = (cur_seq->d_addr & 0xFF000000) |
-                   (cmd & 0x00FFFFFF);
-               return 0;
-       case check_destination_addr1:
-               cur_seq->unfinished = dest_address;
-               cur_seq->d_addr = (cur_seq->d_addr & 0x00FFFFFF) |
-                   ((cmd & 0xFF) << 24);
-               return 0;
-       case check_destination_addr_mode:
-               cur_seq->unfinished = dest_address;
-               if ((cmd & 0x0000C000) == 0)
-                       return 0;
-               DRM_ERROR
-                   ("Attempt to place 3D drawing buffer in system memory\n");
-               return 2;
-       case check_texture_addr0:
-               cur_seq->unfinished = tex_address;
-               tmp = (cmd >> 24);
-               tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
-               *tmp_addr = (*tmp_addr & 0xFF000000) | (cmd & 0x00FFFFFF);
-               return 0;
-       case check_texture_addr1:
-               cur_seq->unfinished = tex_address;
-               tmp = ((cmd >> 24) - 0x20);
-               tmp += tmp << 1;
-               tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
-               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
-               tmp_addr++;
-               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF00) << 16);
-               tmp_addr++;
-               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF0000) << 8);
-               return 0;
-       case check_texture_addr2:
-               cur_seq->unfinished = tex_address;
-               cur_seq->tex_level_lo[tmp = cur_seq->texture] = cmd & 0x3F;
-               cur_seq->tex_level_hi[tmp] = (cmd & 0xFC0) >> 6;
-               return 0;
-       case check_texture_addr3:
-               cur_seq->unfinished = tex_address;
-               tmp = ((cmd >> 24) - HC_SubA_HTXnL0Pit);
-               if (tmp == 0 &&
-                   (cmd & HC_HTXnEnPit_MASK)) {
-                       cur_seq->pitch[cur_seq->texture][tmp] =
-                               (cmd & HC_HTXnLnPit_MASK);
-                       cur_seq->tex_npot[cur_seq->texture] = 1;
-               } else {
-                       cur_seq->pitch[cur_seq->texture][tmp] =
-                               (cmd & HC_HTXnLnPitE_MASK) >> HC_HTXnLnPitE_SHIFT;
-                       cur_seq->tex_npot[cur_seq->texture] = 0;
-                       if (cmd & 0x000FFFFF) {
-                               DRM_ERROR
-                                       ("Unimplemented texture level 0 pitch mode.\n");
-                               return 2;
-                       }
-               }
-               return 0;
-       case check_texture_addr4:
-               cur_seq->unfinished = tex_address;
-               tmp_addr = &cur_seq->t_addr[cur_seq->texture][9];
-               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
-               return 0;
-       case check_texture_addr5:
-       case check_texture_addr6:
-               cur_seq->unfinished = tex_address;
-               /*
-                * Texture width. We don't care since we have the pitch.
-                */
-               return 0;
-       case check_texture_addr7:
-               cur_seq->unfinished = tex_address;
-               tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
-               tmp_addr[5] = 1 << ((cmd & 0x00F00000) >> 20);
-               tmp_addr[4] = 1 << ((cmd & 0x000F0000) >> 16);
-               tmp_addr[3] = 1 << ((cmd & 0x0000F000) >> 12);
-               tmp_addr[2] = 1 << ((cmd & 0x00000F00) >> 8);
-               tmp_addr[1] = 1 << ((cmd & 0x000000F0) >> 4);
-               tmp_addr[0] = 1 << (cmd & 0x0000000F);
-               return 0;
-       case check_texture_addr8:
-               cur_seq->unfinished = tex_address;
-               tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
-               tmp_addr[9] = 1 << ((cmd & 0x0000F000) >> 12);
-               tmp_addr[8] = 1 << ((cmd & 0x00000F00) >> 8);
-               tmp_addr[7] = 1 << ((cmd & 0x000000F0) >> 4);
-               tmp_addr[6] = 1 << (cmd & 0x0000000F);
-               return 0;
-       case check_texture_addr_mode:
-               cur_seq->unfinished = tex_address;
-               if (2 == (tmp = cmd & 0x00000003)) {
-                       DRM_ERROR
-                           ("Attempt to fetch texture from system memory.\n");
-                       return 2;
-               }
-               cur_seq->agp_texture = (tmp == 3);
-               cur_seq->tex_palette_size[cur_seq->texture] =
-                   (cmd >> 16) & 0x000000007;
-               return 0;
-       case check_for_vertex_count:
-               cur_seq->vertex_count = cmd & 0x0000FFFF;
-               return 0;
-       case check_number_texunits:
-               cur_seq->multitex = (cmd >> 3) & 1;
-               return 0;
-       default:
-               DRM_ERROR("Illegal DMA data: 0x%x\n", cmd);
-               return 2;
-       }
-       return 2;
-}
-
-static __inline__ int
-via_check_prim_list(uint32_t const **buffer, const uint32_t * buf_end,
-                   drm_via_state_t * cur_seq)
-{
-       drm_via_private_t *dev_priv =
-           (drm_via_private_t *) cur_seq->dev->dev_private;
-       uint32_t a_fire, bcmd, dw_count;
-       int ret = 0;
-       int have_fire;
-       const uint32_t *buf = *buffer;
-
-       while (buf < buf_end) {
-               have_fire = 0;
-               if ((buf_end - buf) < 2) {
-                       DRM_ERROR
-                           ("Unexpected termination of primitive list.\n");
-                       ret = 1;
-                       break;
-               }
-               if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdB)
-                       break;
-               bcmd = *buf++;
-               if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdA) {
-                       DRM_ERROR("Expected Vertex List A command, got 0x%x\n",
-                                 *buf);
-                       ret = 1;
-                       break;
-               }
-               a_fire =
-                   *buf++ | HC_HPLEND_MASK | HC_HPMValidN_MASK |
-                   HC_HE3Fire_MASK;
-
-               /*
-                * How many dwords per vertex ?
-                */
-
-               if (cur_seq->agp && ((bcmd & (0xF << 11)) == 0)) {
-                       DRM_ERROR("Illegal B command vertex data for AGP.\n");
-                       ret = 1;
-                       break;
-               }
-
-               dw_count = 0;
-               if (bcmd & (1 << 7))
-                       dw_count += (cur_seq->multitex) ? 2 : 1;
-               if (bcmd & (1 << 8))
-                       dw_count += (cur_seq->multitex) ? 2 : 1;
-               if (bcmd & (1 << 9))
-                       dw_count++;
-               if (bcmd & (1 << 10))
-                       dw_count++;
-               if (bcmd & (1 << 11))
-                       dw_count++;
-               if (bcmd & (1 << 12))
-                       dw_count++;
-               if (bcmd & (1 << 13))
-                       dw_count++;
-               if (bcmd & (1 << 14))
-                       dw_count++;
-
-               while (buf < buf_end) {
-                       if (*buf == a_fire) {
-                               if (dev_priv->num_fire_offsets >=
-                                   VIA_FIRE_BUF_SIZE) {
-                                       DRM_ERROR("Fire offset buffer full.\n");
-                                       ret = 1;
-                                       break;
-                               }
-                               dev_priv->fire_offsets[dev_priv->
-                                                      num_fire_offsets++] =
-                                   buf;
-                               have_fire = 1;
-                               buf++;
-                               if (buf < buf_end && *buf == a_fire)
-                                       buf++;
-                               break;
-                       }
-                       if ((*buf == HALCYON_HEADER2) ||
-                           ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) {
-                               DRM_ERROR("Missing Vertex Fire command, "
-                                         "Stray Vertex Fire command  or verifier "
-                                         "lost sync.\n");
-                               ret = 1;
-                               break;
-                       }
-                       if ((ret = eat_words(&buf, buf_end, dw_count)))
-                               break;
-               }
-               if (buf >= buf_end && !have_fire) {
-                       DRM_ERROR("Missing Vertex Fire command or verifier "
-                                 "lost sync.\n");
-                       ret = 1;
-                       break;
-               }
-               if (cur_seq->agp && ((buf - cur_seq->buf_start) & 0x01)) {
-                       DRM_ERROR("AGP Primitive list end misaligned.\n");
-                       ret = 1;
-                       break;
-               }
-       }
-       *buffer = buf;
-       return ret;
-}
-
-static __inline__ verifier_state_t
-via_check_header2(uint32_t const **buffer, const uint32_t * buf_end,
-                 drm_via_state_t * hc_state)
-{
-       uint32_t cmd;
-       int hz_mode;
-       hazard_t hz;
-       const uint32_t *buf = *buffer;
-       const hazard_t *hz_table;
-
-       if ((buf_end - buf) < 2) {
-               DRM_ERROR
-                   ("Illegal termination of DMA HALCYON_HEADER2 sequence.\n");
-               return state_error;
-       }
-       buf++;
-       cmd = (*buf++ & 0xFFFF0000) >> 16;
-
-       switch (cmd) {
-       case HC_ParaType_CmdVdata:
-               if (via_check_prim_list(&buf, buf_end, hc_state))
-                       return state_error;
-               *buffer = buf;
-               return state_command;
-       case HC_ParaType_NotTex:
-               hz_table = table1;
-               break;
-       case HC_ParaType_Tex:
-               hc_state->texture = 0;
-               hz_table = table2;
-               break;
-       case (HC_ParaType_Tex | (HC_SubType_Tex1 << 8)):
-               hc_state->texture = 1;
-               hz_table = table2;
-               break;
-       case (HC_ParaType_Tex | (HC_SubType_TexGeneral << 8)):
-               hz_table = table3;
-               break;
-       case HC_ParaType_Auto:
-               if (eat_words(&buf, buf_end, 2))
-                       return state_error;
-               *buffer = buf;
-               return state_command;
-       case (HC_ParaType_Palette | (HC_SubType_Stipple << 8)):
-               if (eat_words(&buf, buf_end, 32))
-                       return state_error;
-               *buffer = buf;
-               return state_command;
-       case (HC_ParaType_Palette | (HC_SubType_TexPalette0 << 8)):
-       case (HC_ParaType_Palette | (HC_SubType_TexPalette1 << 8)):
-               DRM_ERROR("Texture palettes are rejected because of "
-                         "lack of info how to determine their size.\n");
-               return state_error;
-       case (HC_ParaType_Palette | (HC_SubType_FogTable << 8)):
-               DRM_ERROR("Fog factor palettes are rejected because of "
-                         "lack of info how to determine their size.\n");
-               return state_error;
-       default:
-
-               /*
-                * There are some unimplemented HC_ParaTypes here, that
-                * need to be implemented if the Mesa driver is extended.
-                */
-
-               DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 "
-                         "DMA subcommand: 0x%x. Previous dword: 0x%x\n",
-                         cmd, *(buf - 2));
-               *buffer = buf;
-               return state_error;
-       }
-
-       while (buf < buf_end) {
-               cmd = *buf++;
-               if ((hz = hz_table[cmd >> 24])) {
-                       if ((hz_mode = investigate_hazard(cmd, hz, hc_state))) {
-                               if (hz_mode == 1) {
-                                       buf--;
-                                       break;
-                               }
-                               return state_error;
-                       }
-               } else if (hc_state->unfinished &&
-                          finish_current_sequence(hc_state)) {
-                       return state_error;
-               }
-       }
-       if (hc_state->unfinished && finish_current_sequence(hc_state)) {
-               return state_error;
-       }
-       *buffer = buf;
-       return state_command;
-}
-
-static __inline__ verifier_state_t
-via_parse_header2(drm_via_private_t * dev_priv, uint32_t const **buffer,
-                 const uint32_t * buf_end, int *fire_count)
-{
-       uint32_t cmd;
-       const uint32_t *buf = *buffer;
-       const uint32_t *next_fire;
-       int burst = 0;
-
-       next_fire = dev_priv->fire_offsets[*fire_count];
-       buf++;
-       cmd = (*buf & 0xFFFF0000) >> 16;
-       VIA_WRITE(HC_REG_TRANS_SET + HC_REG_BASE, *buf++);
-       switch (cmd) {
-       case HC_ParaType_CmdVdata:
-               while ((buf < buf_end) &&
-                      (*fire_count < dev_priv->num_fire_offsets) &&
-                      (*buf & HC_ACMD_MASK) == HC_ACMD_HCmdB) {
-                       while (buf <= next_fire) {
-                               VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
-                                         (burst & 63), *buf++);
-                               burst += 4;
-                       }
-                       if ((buf < buf_end)
-                           && ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD))
-                               buf++;
-
-                       if (++(*fire_count) < dev_priv->num_fire_offsets)
-                               next_fire = dev_priv->fire_offsets[*fire_count];
-               }
-               break;
-       default:
-               while (buf < buf_end) {
-
-                       if (*buf == HC_HEADER2 ||
-                           (*buf & HALCYON_HEADER1MASK) == HALCYON_HEADER1 ||
-                           (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5 ||
-                           (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
-                               break;
-
-                       VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
-                                 (burst & 63), *buf++);
-                       burst += 4;
-               }
-       }
-       *buffer = buf;
-       return state_command;
-}
-
-static __inline__ int verify_mmio_address(uint32_t address)
-{
-       if ((address > 0x3FF) && (address < 0xC00)) {
-               DRM_ERROR("Invalid VIDEO DMA command. "
-                         "Attempt to access 3D- or command burst area.\n");
-               return 1;
-       } else if ((address > 0xCFF) && (address < 0x1300)) {
-               DRM_ERROR("Invalid VIDEO DMA command. "
-                         "Attempt to access PCI DMA area.\n");
-               return 1;
-       } else if (address > 0x13FF) {
-               DRM_ERROR("Invalid VIDEO DMA command. "
-                         "Attempt to access VGA registers.\n");
-               return 1;
-       }
-       return 0;
-}
-
-static __inline__ int
-verify_video_tail(uint32_t const **buffer, const uint32_t * buf_end,
-                 uint32_t dwords)
-{
-       const uint32_t *buf = *buffer;
-
-       if (buf_end - buf < dwords) {
-               DRM_ERROR("Illegal termination of video command.\n");
-               return 1;
-       }
-       while (dwords--) {
-               if (*buf++) {
-                       DRM_ERROR("Illegal video command tail.\n");
-                       return 1;
-               }
-       }
-       *buffer = buf;
-       return 0;
-}
-
-static __inline__ verifier_state_t
-via_check_header1(uint32_t const **buffer, const uint32_t * buf_end)
-{
-       uint32_t cmd;
-       const uint32_t *buf = *buffer;
-       verifier_state_t ret = state_command;
-
-       while (buf < buf_end) {
-               cmd = *buf;
-               if ((cmd > ((0x3FF >> 2) | HALCYON_HEADER1)) &&
-                   (cmd < ((0xC00 >> 2) | HALCYON_HEADER1))) {
-                       if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
-                               break;
-                       DRM_ERROR("Invalid HALCYON_HEADER1 command. "
-                                 "Attempt to access 3D- or command burst area.\n");
-                       ret = state_error;
-                       break;
-               } else if (cmd > ((0xCFF >> 2) | HALCYON_HEADER1)) {
-                       if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
-                               break;
-                       DRM_ERROR("Invalid HALCYON_HEADER1 command. "
-                                 "Attempt to access VGA registers.\n");
-                       ret = state_error;
-                       break;
-               } else {
-                       buf += 2;
-               }
-       }
-       *buffer = buf;
-       return ret;
-}
-
-static __inline__ verifier_state_t
-via_parse_header1(drm_via_private_t * dev_priv, uint32_t const **buffer,
-                 const uint32_t * buf_end)
-{
-       register uint32_t cmd;
-       const uint32_t *buf = *buffer;
-
-       while (buf < buf_end) {
-               cmd = *buf;
-               if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
-                       break;
-               VIA_WRITE((cmd & ~HALCYON_HEADER1MASK) << 2, *++buf);
-               buf++;
-       }
-       *buffer = buf;
-       return state_command;
-}
-
-static __inline__ verifier_state_t
-via_check_vheader5(uint32_t const **buffer, const uint32_t * buf_end)
-{
-       uint32_t data;
-       const uint32_t *buf = *buffer;
-
-       if (buf_end - buf < 4) {
-               DRM_ERROR("Illegal termination of video header5 command\n");
-               return state_error;
-       }
-
-       data = *buf++ & ~VIA_VIDEOMASK;
-       if (verify_mmio_address(data))
-               return state_error;
-
-       data = *buf++;
-       if (*buf++ != 0x00F50000) {
-               DRM_ERROR("Illegal header5 header data\n");
-               return state_error;
-       }
-       if (*buf++ != 0x00000000) {
-               DRM_ERROR("Illegal header5 header data\n");
-               return state_error;
-       }
-       if (eat_words(&buf, buf_end, data))
-               return state_error;
-       if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
-               return state_error;
-       *buffer = buf;
-       return state_command;
-
-}
-
-static __inline__ verifier_state_t
-via_parse_vheader5(drm_via_private_t * dev_priv, uint32_t const **buffer,
-                  const uint32_t * buf_end)
-{
-       uint32_t addr, count, i;
-       const uint32_t *buf = *buffer;
-
-       addr = *buf++ & ~VIA_VIDEOMASK;
-       i = count = *buf;
-       buf += 3;
-       while (i--) {
-               VIA_WRITE(addr, *buf++);
-       }
-       if (count & 3)
-               buf += 4 - (count & 3);
-       *buffer = buf;
-       return state_command;
-}
-
-static __inline__ verifier_state_t
-via_check_vheader6(uint32_t const **buffer, const uint32_t * buf_end)
-{
-       uint32_t data;
-       const uint32_t *buf = *buffer;
-       uint32_t i;
-
-       if (buf_end - buf < 4) {
-               DRM_ERROR("Illegal termination of video header6 command\n");
-               return state_error;
-       }
-       buf++;
-       data = *buf++;
-       if (*buf++ != 0x00F60000) {
-               DRM_ERROR("Illegal header6 header data\n");
-               return state_error;
-       }
-       if (*buf++ != 0x00000000) {
-               DRM_ERROR("Illegal header6 header data\n");
-               return state_error;
-       }
-       if ((buf_end - buf) < (data << 1)) {
-               DRM_ERROR("Illegal termination of video header6 command\n");
-               return state_error;
-       }
-       for (i = 0; i < data; ++i) {
-               if (verify_mmio_address(*buf++))
-                       return state_error;
-               buf++;
-       }
-       data <<= 1;
-       if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
-               return state_error;
-       *buffer = buf;
-       return state_command;
-}
-
-static __inline__ verifier_state_t
-via_parse_vheader6(drm_via_private_t * dev_priv, uint32_t const **buffer,
-                  const uint32_t * buf_end)
-{
-
-       uint32_t addr, count, i;
-       const uint32_t *buf = *buffer;
-
-       i = count = *++buf;
-       buf += 3;
-       while (i--) {
-               addr = *buf++;
-               VIA_WRITE(addr, *buf++);
-       }
-       count <<= 1;
-       if (count & 3)
-               buf += 4 - (count & 3);
-       *buffer = buf;
-       return state_command;
-}
-
-int
-via_verify_command_stream(const uint32_t * buf, unsigned int size,
-                         struct drm_device * dev, int agp)
-{
-
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       drm_via_state_t *hc_state = &dev_priv->hc_state;
-       drm_via_state_t saved_state = *hc_state;
-       uint32_t cmd;
-       const uint32_t *buf_end = buf + (size >> 2);
-       verifier_state_t state = state_command;
-       int cme_video;
-       int supported_3d;
-
-       cme_video = (dev_priv->chipset == VIA_PRO_GROUP_A ||
-                    dev_priv->chipset == VIA_DX9_0);
-
-       supported_3d = dev_priv->chipset != VIA_DX9_0;
-
-       hc_state->dev = dev;
-       hc_state->unfinished = no_sequence;
-       hc_state->map_cache = NULL;
-       hc_state->agp = agp;
-       hc_state->buf_start = buf;
-       dev_priv->num_fire_offsets = 0;
-
-       while (buf < buf_end) {
-
-               switch (state) {
-               case state_header2:
-                       state = via_check_header2(&buf, buf_end, hc_state);
-                       break;
-               case state_header1:
-                       state = via_check_header1(&buf, buf_end);
-                       break;
-               case state_vheader5:
-                       state = via_check_vheader5(&buf, buf_end);
-                       break;
-               case state_vheader6:
-                       state = via_check_vheader6(&buf, buf_end);
-                       break;
-               case state_command:
-                       if ((HALCYON_HEADER2 == (cmd = *buf)) &&
-                           supported_3d)
-                               state = state_header2;
-                       else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
-                               state = state_header1;
-                       else if (cme_video
-                                && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
-                               state = state_vheader5;
-                       else if (cme_video
-                                && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
-                               state = state_vheader6;
-                       else if ((cmd == HALCYON_HEADER2) && !supported_3d) {
-                               DRM_ERROR("Accelerated 3D is not supported on this chipset yet.\n");
-                               state = state_error;
-                       } else {
-                               DRM_ERROR
-                                   ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
-                                    cmd);
-                               state = state_error;
-                       }
-                       break;
-               case state_error:
-               default:
-                       *hc_state = saved_state;
-                       return -EINVAL;
-               }
-       }
-       if (state == state_error) {
-               *hc_state = saved_state;
-               return -EINVAL;
-       }
-       return 0;
-}
-
-int
-via_parse_command_stream(struct drm_device * dev, const uint32_t * buf,
-                        unsigned int size)
-{
-
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       uint32_t cmd;
-       const uint32_t *buf_end = buf + (size >> 2);
-       verifier_state_t state = state_command;
-       int fire_count = 0;
-
-       while (buf < buf_end) {
-
-               switch (state) {
-               case state_header2:
-                       state =
-                           via_parse_header2(dev_priv, &buf, buf_end,
-                                             &fire_count);
-                       break;
-               case state_header1:
-                       state = via_parse_header1(dev_priv, &buf, buf_end);
-                       break;
-               case state_vheader5:
-                       state = via_parse_vheader5(dev_priv, &buf, buf_end);
-                       break;
-               case state_vheader6:
-                       state = via_parse_vheader6(dev_priv, &buf, buf_end);
-                       break;
-               case state_command:
-                       if (HALCYON_HEADER2 == (cmd = *buf))
-                               state = state_header2;
-                       else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
-                               state = state_header1;
-                       else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
-                               state = state_vheader5;
-                       else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
-                               state = state_vheader6;
-                       else {
-                               DRM_ERROR
-                                   ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
-                                    cmd);
-                               state = state_error;
-                       }
-                       break;
-               case state_error:
-               default:
-                       return -EINVAL;
-               }
-       }
-       if (state == state_error) {
-               return -EINVAL;
-       }
-       return 0;
-}
-
-static void
-setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size)
-{
-       int i;
-
-       for (i = 0; i < 256; ++i) {
-               table[i] = forbidden_command;
-       }
-
-       for (i = 0; i < size; ++i) {
-               table[init_table[i].code] = init_table[i].hz;
-       }
-}
-
-void via_init_command_verifier(void)
-{
-       setup_hazard_table(init_table1, table1,
-                          sizeof(init_table1) / sizeof(hz_init_t));
-       setup_hazard_table(init_table2, table2,
-                          sizeof(init_table2) / sizeof(hz_init_t));
-       setup_hazard_table(init_table3, table3,
-                          sizeof(init_table3) / sizeof(hz_init_t));
-}
diff --git a/drivers/char/drm/via_verifier.h b/drivers/char/drm/via_verifier.h
deleted file mode 100644 (file)
index d6f8214..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2004 The Unichrome Project. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE UNICHROME PROJECT, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author: Thomas Hellström 2004.
- */
-
-#ifndef _VIA_VERIFIER_H_
-#define _VIA_VERIFIER_H_
-
-typedef enum {
-       no_sequence = 0,
-       z_address,
-       dest_address,
-       tex_address
-} drm_via_sequence_t;
-
-typedef struct {
-       unsigned texture;
-       uint32_t z_addr;
-       uint32_t d_addr;
-       uint32_t t_addr[2][10];
-       uint32_t pitch[2][10];
-       uint32_t height[2][10];
-       uint32_t tex_level_lo[2];
-       uint32_t tex_level_hi[2];
-       uint32_t tex_palette_size[2];
-       uint32_t tex_npot[2];
-       drm_via_sequence_t unfinished;
-       int agp_texture;
-       int multitex;
-       struct drm_device *dev;
-       drm_local_map_t *map_cache;
-       uint32_t vertex_count;
-       int agp;
-       const uint32_t *buf_start;
-} drm_via_state_t;
-
-extern int via_verify_command_stream(const uint32_t * buf, unsigned int size,
-                                    struct drm_device * dev, int agp);
-extern int via_parse_command_stream(struct drm_device *dev, const uint32_t *buf,
-                                   unsigned int size);
-
-#endif
diff --git a/drivers/char/drm/via_video.c b/drivers/char/drm/via_video.c
deleted file mode 100644 (file)
index 6ec04ac..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Author: Thomas Hellstrom 2005.
- *
- * Video and XvMC related functions.
- */
-
-#include "drmP.h"
-#include "via_drm.h"
-#include "via_drv.h"
-
-void via_init_futex(drm_via_private_t * dev_priv)
-{
-       unsigned int i;
-
-       DRM_DEBUG("\n");
-
-       for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
-               DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
-               XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
-       }
-}
-
-void via_cleanup_futex(drm_via_private_t * dev_priv)
-{
-}
-
-void via_release_futex(drm_via_private_t * dev_priv, int context)
-{
-       unsigned int i;
-       volatile int *lock;
-
-       if (!dev_priv->sarea_priv)
-               return;
-
-       for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
-               lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
-               if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
-                       if (_DRM_LOCK_IS_HELD(*lock)
-                           && (*lock & _DRM_LOCK_CONT)) {
-                               DRM_WAKEUP(&(dev_priv->decoder_queue[i]));
-                       }
-                       *lock = 0;
-               }
-       }
-}
-
-int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
-{
-       drm_via_futex_t *fx = data;
-       volatile int *lock;
-       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
-       drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
-       int ret = 0;
-
-       DRM_DEBUG("\n");
-
-       if (fx->lock > VIA_NR_XVMC_LOCKS)
-               return -EFAULT;
-
-       lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
-
-       switch (fx->func) {
-       case VIA_FUTEX_WAIT:
-               DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
-                           (fx->ms / 10) * (DRM_HZ / 100), *lock != fx->val);
-               return ret;
-       case VIA_FUTEX_WAKE:
-               DRM_WAKEUP(&(dev_priv->decoder_queue[fx->lock]));
-               return 0;
-       }
-       return 0;
-}
index ea35ab2..fb58493 100644 (file)
@@ -27,6 +27,7 @@
  * option) any later version.
  */
 #include <linux/ds1286.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -252,6 +253,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
 
 static int ds1286_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock_irq(&ds1286_lock);
 
        if (ds1286_status & RTC_IS_OPEN)
@@ -260,10 +262,12 @@ static int ds1286_open(struct inode *inode, struct file *file)
        ds1286_status |= RTC_IS_OPEN;
 
        spin_unlock_irq(&ds1286_lock);
+       unlock_kernel();
        return 0;
 
 out_busy:
        spin_lock_irq(&ds1286_lock);
+       unlock_kernel();
        return -EBUSY;
 }
 
index 334ad5b..34275c6 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/proc_fs.h>
 #include <linux/capability.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 
 #include <asm/hardware.h>
 #include <asm/mach-types.h>
@@ -208,6 +209,12 @@ static void ds1620_read_state(struct therm *therm)
        therm->hi = cvt_9_to_int(ds1620_in(THERM_READ_TH, 9));
 }
 
+static int ds1620_open(struct inode *inode, struct file *file)
+{
+       cycle_kernel_lock();
+       return nonseekable_open(inode, file);
+}
+
 static ssize_t
 ds1620_read(struct file *file, char __user *buf, size_t count, loff_t *ptr)
 {
@@ -336,7 +343,7 @@ static struct proc_dir_entry *proc_therm_ds1620;
 
 static const struct file_operations ds1620_fops = {
        .owner          = THIS_MODULE,
-       .open           = nonseekable_open,
+       .open           = ds1620_open,
        .read           = ds1620_read,
        .ioctl          = ds1620_ioctl,
 };
index a69c652..7bf7485 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #include <asm/atarihw.h>
 #include <asm/traps.h>
@@ -436,13 +437,17 @@ static unsigned int dsp56k_poll(struct file *file, poll_table *wait)
 static int dsp56k_open(struct inode *inode, struct file *file)
 {
        int dev = iminor(inode) & 0x0f;
+       int ret = 0;
 
+       lock_kernel();
        switch(dev)
        {
        case DSP56K_DEV_56001:
 
-               if (test_and_set_bit(0, &dsp56k.in_use))
-                       return -EBUSY;
+               if (test_and_set_bit(0, &dsp56k.in_use)) {
+                       ret = -EBUSY;
+                       goto out;
+               }
 
                dsp56k.timeout = TIMEOUT;
                dsp56k.maxio = MAXIO;
@@ -458,10 +463,11 @@ static int dsp56k_open(struct inode *inode, struct file *file)
                break;
 
        default:
-               return -ENODEV;
+               ret = -ENODEV;
        }
-
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int dsp56k_release(struct inode *inode, struct file *file)
index abde6dd..6b900b2 100644 (file)
@@ -56,6 +56,7 @@
 #include <linux/errno.h>       /* for -EBUSY */
 #include <linux/ioport.h>      /* for request_region */
 #include <linux/delay.h>       /* for loops_per_jiffy */
+#include <linux/smp_lock.h>    /* cycle_kernel_lock() */
 #include <asm/io.h>            /* for inb_p, outb_p, inb, outb, etc. */
 #include <asm/uaccess.h>       /* for get_user, etc. */
 #include <linux/wait.h>                /* for wait_queue */
@@ -288,10 +289,12 @@ static int dtlk_ioctl(struct inode *inode,
        }
 }
 
+/* Note that nobody ever sets dtlk_busy... */
 static int dtlk_open(struct inode *inode, struct file *file)
 {
        TRACE_TEXT("(dtlk_open");
 
+       cycle_kernel_lock();
        nonseekable_open(inode, file);
        switch (iminor(inode)) {
        case DTLK_MINOR:
index 49233f5..d57ca3e 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -272,6 +273,7 @@ efi_rtc_open(struct inode *inode, struct file *file)
         * We do accept multiple open files at the same time as we
         * synchronize on the per call operation.
         */
+       cycle_kernel_lock();
        return 0;
 }
 
index 69f0a29..aac0985 100644 (file)
@@ -51,6 +51,7 @@
 #include <linux/init.h>
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
+#include <linux/smp_lock.h>
 #include <linux/workqueue.h>
 
 #include <asm/uaccess.h>
@@ -338,12 +339,16 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
 
 static int gen_rtc_open(struct inode *inode, struct file *file)
 {
-       if (gen_rtc_status & RTC_IS_OPEN)
+       lock_kernel();
+       if (gen_rtc_status & RTC_IS_OPEN) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
        gen_rtc_status |= RTC_IS_OPEN;
        gen_rtc_irq_data = 0;
        irq_active = 0;
+       unlock_kernel();
 
        return 0;
 }
index e7fb0bc..fb0a85a 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/miscdevice.h>
 #include <linux/major.h>
@@ -193,6 +194,7 @@ static int hpet_open(struct inode *inode, struct file *file)
        if (file->f_mode & FMODE_WRITE)
                return -EINVAL;
 
+       lock_kernel();
        spin_lock_irq(&hpet_lock);
 
        for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
@@ -207,6 +209,7 @@ static int hpet_open(struct inode *inode, struct file *file)
 
        if (!devp) {
                spin_unlock_irq(&hpet_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -214,6 +217,7 @@ static int hpet_open(struct inode *inode, struct file *file)
        devp->hd_irqdata = 0;
        devp->hd_flags |= HPET_OPEN;
        spin_unlock_irq(&hpet_lock);
+       unlock_kernel();
 
        return 0;
 }
index dd68f85..db2ae42 100644 (file)
@@ -39,9 +39,14 @@ static int xencons_irq;
 
 /* ------------------------------------------------------------------ */
 
+static unsigned long console_pfn = ~0ul;
+
 static inline struct xencons_interface *xencons_interface(void)
 {
-       return mfn_to_virt(xen_start_info->console.domU.mfn);
+       if (console_pfn == ~0ul)
+               return mfn_to_virt(xen_start_info->console.domU.mfn);
+       else
+               return __va(console_pfn << PAGE_SHIFT);
 }
 
 static inline void notify_daemon(void)
@@ -101,20 +106,32 @@ static int __init xen_init(void)
 {
        struct hvc_struct *hp;
 
-       if (!is_running_on_xen())
-               return 0;
+       if (!is_running_on_xen() ||
+           is_initial_xendomain() ||
+           !xen_start_info->console.domU.evtchn)
+               return -ENODEV;
 
        xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn);
        if (xencons_irq < 0)
-               xencons_irq = 0 /* NO_IRQ */;
+               xencons_irq = 0; /* NO_IRQ */
+
        hp = hvc_alloc(HVC_COOKIE, xencons_irq, &hvc_ops, 256);
        if (IS_ERR(hp))
                return PTR_ERR(hp);
 
        hvc = hp;
+
+       console_pfn = mfn_to_pfn(xen_start_info->console.domU.mfn);
+
        return 0;
 }
 
+void xen_console_resume(void)
+{
+       if (xencons_irq)
+               rebind_evtchn_irq(xen_start_info->console.domU.evtchn, xencons_irq);
+}
+
 static void __exit xen_fini(void)
 {
        if (hvc)
@@ -134,12 +151,28 @@ module_init(xen_init);
 module_exit(xen_fini);
 console_initcall(xen_cons_init);
 
+static void raw_console_write(const char *str, int len)
+{
+       while(len > 0) {
+               int rc = HYPERVISOR_console_io(CONSOLEIO_write, len, (char *)str);
+               if (rc <= 0)
+                       break;
+
+               str += rc;
+               len -= rc;
+       }
+}
+
+#ifdef CONFIG_EARLY_PRINTK
 static void xenboot_write_console(struct console *console, const char *string,
                                  unsigned len)
 {
        unsigned int linelen, off = 0;
        const char *pos;
 
+       raw_console_write(string, len);
+
+       write_console(0, "(early) ", 8);
        while (off < len && NULL != (pos = strchr(string+off, '\n'))) {
                linelen = pos-string+off;
                if (off + linelen > len)
@@ -155,5 +188,23 @@ static void xenboot_write_console(struct console *console, const char *string,
 struct console xenboot_console = {
        .name           = "xenboot",
        .write          = xenboot_write_console,
-       .flags          = CON_PRINTBUFFER | CON_BOOT,
+       .flags          = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
 };
+#endif /* CONFIG_EARLY_PRINTK */
+
+void xen_raw_console_write(const char *str)
+{
+       raw_console_write(str, strlen(str));
+}
+
+void xen_raw_printk(const char *fmt, ...)
+{
+       static char buf[512];
+       va_list ap;
+
+       va_start(ap, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       va_end(ap);
+
+       xen_raw_console_write(buf);
+}
index 662d60e..e5d583c 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/kernel.h>
 #include <linux/fs.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/init.h>
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
@@ -86,6 +87,7 @@ static int rng_dev_open(struct inode *inode, struct file *filp)
                return -EINVAL;
        if (filp->f_mode & FMODE_WRITE)
                return -EINVAL;
+       cycle_kernel_lock();
        return 0;
 }
 
index c12cf8f..61b6fe4 100644 (file)
@@ -98,6 +98,7 @@
 #include <linux/major.h>
 #include <linux/wait.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
@@ -2908,42 +2909,11 @@ ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
 static int
 ip2_ipl_open( struct inode *pInode, struct file *pFile )
 {
-       unsigned int iplminor = iminor(pInode);
-       i2eBordStrPtr pB;
-       i2ChanStrPtr  pCh;
 
 #ifdef IP2DEBUG_IPL
        printk (KERN_DEBUG "IP2IPL: open\n" );
 #endif
-
-       switch(iplminor) {
-       // These are the IPL devices
-       case 0:
-       case 4:
-       case 8:
-       case 12:
-               break;
-
-       // These are the status devices
-       case 1:
-       case 5:
-       case 9:
-       case 13:
-               break;
-
-       // These are the debug devices
-       case 2:
-       case 6:
-       case 10:
-       case 14:
-               pB = i2BoardPtrTable[iplminor / 4];
-               pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
-               break;
-
-       // This is the trace device
-       case 3:
-               break;
-       }
+       cycle_kernel_lock();
        return 0;
 }
 
index 86e6538..ec9d044 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/bcd.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/miscdevice.h>
 #include <linux/ioport.h>
@@ -163,15 +164,18 @@ static long rtc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
 static int rtc_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock_irq(&rtc_lock);
 
        if (rtc_status & RTC_IS_OPEN) {
                spin_unlock_irq(&rtc_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
        rtc_status |= RTC_IS_OPEN;
        spin_unlock_irq(&rtc_lock);
+       unlock_kernel();
 
        return 0;
 }
index 0246a2b..c11a404 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/compat.h>
+#include <linux/smp_lock.h>
 
 struct ipmi_file_private
 {
@@ -100,7 +101,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)
        struct ipmi_file_private *priv = file->private_data;
        int                      result;
 
+       lock_kernel(); /* could race against open() otherwise */
        result = fasync_helper(fd, file, on, &priv->fasync_queue);
+       unlock_kernel();
 
        return (result);
 }
@@ -121,6 +124,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
        if (!priv)
                return -ENOMEM;
 
+       lock_kernel();
        priv->file = file;
 
        rv = ipmi_create_user(if_num,
@@ -129,7 +133,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
                              &(priv->user));
        if (rv) {
                kfree(priv);
-               return rv;
+               goto out;
        }
 
        file->private_data = priv;
@@ -144,7 +148,9 @@ static int ipmi_open(struct inode *inode, struct file *file)
        priv->default_retries = -1;
        priv->default_retry_time_ms = 0;
 
-       return 0;
+out:
+       unlock_kernel();
+       return rv;
 }
 
 static int ipmi_release(struct inode *inode, struct file *file)
index 0e6df28..235fab0 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/moduleparam.h>
 #include <linux/ipmi.h>
 #include <linux/ipmi_smi.h>
+#include <linux/smp_lock.h>
 #include <linux/watchdog.h>
 #include <linux/miscdevice.h>
 #include <linux/init.h>
@@ -818,6 +819,8 @@ static int ipmi_open(struct inode *ino, struct file *filep)
                if (test_and_set_bit(0, &ipmi_wdog_open))
                        return -EBUSY;
 
+               cycle_kernel_lock();
+
                /*
                 * Don't start the timer now, let it start on the
                 * first heartbeat.
index 4fe9206..1c29b20 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/netdevice.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/delay.h>
 
 #include <asm/io.h>
@@ -414,6 +415,8 @@ static int lcd_ioctl(struct inode *inode, struct file *file,
 
 static int lcd_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
+
        if (!lcd_present)
                return -ENXIO;
        else
index 60ac642..71abb4c 100644 (file)
 #include <linux/device.h>
 #include <linux/wait.h>
 #include <linux/jiffies.h>
+#include <linux/smp_lock.h>
 
 #include <linux/parport.h>
 #undef LP_STATS
@@ -489,14 +490,21 @@ static ssize_t lp_read(struct file * file, char __user * buf,
 static int lp_open(struct inode * inode, struct file * file)
 {
        unsigned int minor = iminor(inode);
+       int ret = 0;
 
-       if (minor >= LP_NO)
-               return -ENXIO;
-       if ((LP_F(minor) & LP_EXIST) == 0)
-               return -ENXIO;
-       if (test_and_set_bit(LP_BUSY_BIT_POS, &LP_F(minor)))
-               return -EBUSY;
-
+       lock_kernel();
+       if (minor >= LP_NO) {
+               ret = -ENXIO;
+               goto out;
+       }
+       if ((LP_F(minor) & LP_EXIST) == 0) {
+               ret = -ENXIO;
+               goto out;
+       }
+       if (test_and_set_bit(LP_BUSY_BIT_POS, &LP_F(minor))) {
+               ret = -EBUSY;
+               goto out;
+       }
        /* If ABORTOPEN is set and the printer is offline or out of paper,
           we may still want to open it to perform ioctl()s.  Therefore we
           have commandeered O_NONBLOCK, even though it is being used in
@@ -510,21 +518,25 @@ static int lp_open(struct inode * inode, struct file * file)
                if (status & LP_POUTPA) {
                        printk(KERN_INFO "lp%d out of paper\n", minor);
                        LP_F(minor) &= ~LP_BUSY;
-                       return -ENOSPC;
+                       ret = -ENOSPC;
+                       goto out;
                } else if (!(status & LP_PSELECD)) {
                        printk(KERN_INFO "lp%d off-line\n", minor);
                        LP_F(minor) &= ~LP_BUSY;
-                       return -EIO;
+                       ret = -EIO;
+                       goto out;
                } else if (!(status & LP_PERRORP)) {
                        printk(KERN_ERR "lp%d printer error\n", minor);
                        LP_F(minor) &= ~LP_BUSY;
-                       return -EIO;
+                       ret = -EIO;
+                       goto out;
                }
        }
        lp_table[minor].lp_buffer = kmalloc(LP_BUFFER_SIZE, GFP_KERNEL);
        if (!lp_table[minor].lp_buffer) {
                LP_F(minor) &= ~LP_BUSY;
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
        /* Determine if the peripheral supports ECP mode */
        lp_claim_parport_or_block (&lp_table[minor]);
@@ -540,7 +552,9 @@ static int lp_open(struct inode * inode, struct file * file)
        parport_negotiate (lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
        lp_release_parport (&lp_table[minor]);
        lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int lp_release(struct inode * inode, struct file * file)
index f4716ad..acd8e9e 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/mm.h>
 #include <linux/uio.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -382,15 +383,19 @@ static int mbcs_open(struct inode *ip, struct file *fp)
        struct mbcs_soft *soft;
        int minor;
 
+       lock_kernel();
        minor = iminor(ip);
 
+       /* Nothing protects access to this list... */
        list_for_each_entry(soft, &soft_list, list) {
                if (soft->nasid == minor) {
                        fp->private_data = soft->cxdev;
+                       unlock_kernel();
                        return 0;
                }
        }
 
+       unlock_kernel();
        return -ENODEV;
 }
 
index 934ffaf..070e22e 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/bootmem.h>
 #include <linux/splice.h>
 #include <linux/pfn.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -889,6 +890,9 @@ static const struct file_operations kmsg_fops = {
 
 static int memory_open(struct inode * inode, struct file * filp)
 {
+       int ret = 0;
+
+       lock_kernel();
        switch (iminor(inode)) {
                case 1:
                        filp->f_op = &mem_fops;
@@ -932,11 +936,13 @@ static int memory_open(struct inode * inode, struct file * filp)
                        break;
 #endif
                default:
+                       unlock_kernel();
                        return -ENXIO;
        }
        if (filp->f_op && filp->f_op->open)
-               return filp->f_op->open(inode,filp);
-       return 0;
+               ret = filp->f_op->open(inode,filp);
+       unlock_kernel();
+       return ret;
 }
 
 static const struct file_operations memory_fops = {
index eaace0d..6e1563c 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/device.h>
 #include <linux/tty.h>
 #include <linux/kmod.h>
+#include <linux/smp_lock.h>
 
 /*
  * Head entry for the doubly linked miscdevice list
@@ -118,6 +119,7 @@ static int misc_open(struct inode * inode, struct file * file)
        int err = -ENODEV;
        const struct file_operations *old_fops, *new_fops = NULL;
        
+       lock_kernel();
        mutex_lock(&misc_mtx);
        
        list_for_each_entry(c, &misc_list, list) {
@@ -155,6 +157,7 @@ static int misc_open(struct inode * inode, struct file * file)
        fops_put(old_fops);
 fail:
        mutex_unlock(&misc_mtx);
+       unlock_kernel();
        return err;
 }
 
index 8d14823..50243fc 100644 (file)
@@ -56,6 +56,7 @@
 #include <linux/serial.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/delay.h>
 #include <linux/serial_8250.h>
 #include "smapi.h"
@@ -100,6 +101,7 @@ static int mwave_open(struct inode *inode, struct file *file)
        PRINTK_2(TRACE_MWAVE,
                "mwavedd::mwave_open, exit return retval %x\n", retval);
 
+       cycle_kernel_lock();
        return retval;
 }
 
index 98dec38..197cd7a 100644 (file)
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -333,12 +334,14 @@ nvram_ioctl(struct inode *inode, struct file *file,
 static int
 nvram_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock(&nvram_state_lock);
 
        if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
            (nvram_open_mode & NVRAM_EXCL) ||
            ((file->f_mode & 2) && (nvram_open_mode & NVRAM_WRITE))) {
                spin_unlock(&nvram_state_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -349,6 +352,7 @@ nvram_open(struct inode *inode, struct file *file)
        nvram_open_cnt++;
 
        spin_unlock(&nvram_state_lock);
+       unlock_kernel();
 
        return 0;
 }
index ecfaf18..b930de5 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/mutex.h>
 #include <linux/nsc_gpio.h>
 #include <linux/platform_device.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
 #define DEVNAME "pc8736x_gpio"
@@ -217,6 +218,7 @@ static int pc8736x_gpio_open(struct inode *inode, struct file *file)
        unsigned m = iminor(inode);
        file->private_data = &pc8736x_gpio_ops;
 
+       cycle_kernel_lock();
        dev_dbg(&pdev->dev, "open %d\n", m);
 
        if (m >= PC8736X_GPIO_CT)
index 4a933d4..59ca351 100644 (file)
@@ -32,8 +32,9 @@
 #include <linux/fs.h>
 #include <linux/delay.h>
 #include <linux/bitrev.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
+#include <linux/smp_lock.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
@@ -1405,11 +1406,11 @@ static void stop_monitor(struct cm4000_dev *dev)
        DEBUGP(3, dev, "<- stop_monitor\n");
 }
 
-static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
-                    unsigned long arg)
+static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        struct cm4000_dev *dev = filp->private_data;
        unsigned int iobase = dev->p_dev->io.BasePort1;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct pcmcia_device *link;
        int size;
        int rc;
@@ -1426,38 +1427,42 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
        DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode),
               iminor(inode), ioctl_names[_IOC_NR(cmd)]);
 
+       lock_kernel();
+       rc = -ENODEV;
        link = dev_table[iminor(inode)];
        if (!pcmcia_dev_present(link)) {
                DEBUGP(4, dev, "DEV_OK false\n");
-               return -ENODEV;
+               goto out;
        }
 
        if (test_bit(IS_CMM_ABSENT, &dev->flags)) {
                DEBUGP(4, dev, "CMM_ABSENT flag set\n");
-               return -ENODEV;
+               goto out;
        }
+       rc = EINVAL;
 
        if (_IOC_TYPE(cmd) != CM_IOC_MAGIC) {
                DEBUGP(4, dev, "ioctype mismatch\n");
-               return -EINVAL;
+               goto out;
        }
        if (_IOC_NR(cmd) > CM_IOC_MAXNR) {
                DEBUGP(4, dev, "iocnr mismatch\n");
-               return -EINVAL;
+               goto out;
        }
        size = _IOC_SIZE(cmd);
-       rc = 0;
+       rc = -EFAULT;
        DEBUGP(4, dev, "iocdir=%.4x iocr=%.4x iocw=%.4x iocsize=%d cmd=%.4x\n",
              _IOC_DIR(cmd), _IOC_READ, _IOC_WRITE, size, cmd);
 
        if (_IOC_DIR(cmd) & _IOC_READ) {
                if (!access_ok(VERIFY_WRITE, argp, size))
-                       return -EFAULT;
+                       goto out;
        }
        if (_IOC_DIR(cmd) & _IOC_WRITE) {
                if (!access_ok(VERIFY_READ, argp, size))
-                       return -EFAULT;
+                       goto out;
        }
+       rc = 0;
 
        switch (cmd) {
        case CM_IOCGSTATUS:
@@ -1477,9 +1482,9 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                        if (test_bit(IS_BAD_CARD, &dev->flags))
                                status |= CM_BAD_CARD;
                        if (copy_to_user(argp, &status, sizeof(int)))
-                               return -EFAULT;
+                               rc = -EFAULT;
                }
-               return 0;
+               break;
        case CM_IOCGATR:
                DEBUGP(4, dev, "... in CM_IOCGATR\n");
                {
@@ -1492,25 +1497,29 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                              || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
                                  != 0)))) {
                                if (filp->f_flags & O_NONBLOCK)
-                                       return -EAGAIN;
-                               return -ERESTARTSYS;
+                                       rc = -EAGAIN;
+                               else
+                                       rc = -ERESTARTSYS;
+                               break;
                        }
 
+                       rc = -EFAULT;
                        if (test_bit(IS_ATR_VALID, &dev->flags) == 0) {
                                tmp = -1;
                                if (copy_to_user(&(atreq->atr_len), &tmp,
                                                 sizeof(int)))
-                                       return -EFAULT;
+                                       break;
                        } else {
                                if (copy_to_user(atreq->atr, dev->atr,
                                                 dev->atr_len))
-                                       return -EFAULT;
+                                       break;
 
                                tmp = dev->atr_len;
                                if (copy_to_user(&(atreq->atr_len), &tmp, sizeof(int)))
-                                       return -EFAULT;
+                                       break;
                        }
-                       return 0;
+                       rc = 0;
+                       break;
                }
        case CM_IOCARDOFF:
 
@@ -1538,8 +1547,10 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                              || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
                                  == 0)))) {
                                if (filp->f_flags & O_NONBLOCK)
-                                       return -EAGAIN;
-                               return -ERESTARTSYS;
+                                       rc = -EAGAIN;
+                               else
+                                       rc = -ERESTARTSYS;
+                               break;
                        }
                        /* Set Flags0 = 0x42 */
                        DEBUGP(4, dev, "Set Flags0=0x42 \n");
@@ -1554,8 +1565,10 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                              || (test_bit(IS_ATR_VALID, (void *)&dev->flags) !=
                                  0)))) {
                                if (filp->f_flags & O_NONBLOCK)
-                                       return -EAGAIN;
-                               return -ERESTARTSYS;
+                                       rc = -EAGAIN;
+                               else
+                                       rc = -ERESTARTSYS;
+                               break;
                        }
                }
                /* release lock */
@@ -1568,8 +1581,10 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                        struct ptsreq krnptsreq;
 
                        if (copy_from_user(&krnptsreq, argp,
-                                          sizeof(struct ptsreq)))
-                               return -EFAULT;
+                                          sizeof(struct ptsreq))) {
+                               rc = -EFAULT;
+                               break;
+                       }
 
                        rc = 0;
                        DEBUGP(4, dev, "... in CM_IOCSPTS\n");
@@ -1580,8 +1595,10 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                              || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
                                  != 0)))) {
                                if (filp->f_flags & O_NONBLOCK)
-                                       return -EAGAIN;
-                               return -ERESTARTSYS;
+                                       rc = -EAGAIN;
+                               else
+                                       rc = -ERESTARTSYS;
+                               break;
                        }
                        /* get IO lock */
                        if (wait_event_interruptible
@@ -1590,8 +1607,10 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                              || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
                                  == 0)))) {
                                if (filp->f_flags & O_NONBLOCK)
-                                       return -EAGAIN;
-                               return -ERESTARTSYS;
+                                       rc = -EAGAIN;
+                               else
+                                       rc = -ERESTARTSYS;
+                               break;
                        }
 
                        if ((rc = set_protocol(dev, &krnptsreq)) != 0) {
@@ -1604,7 +1623,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
                        wake_up_interruptible(&dev->ioq);
 
                }
-               return rc;
+               break;
 #ifdef PCMCIA_DEBUG
        case CM_IOSDBGLVL:      /* set debug log level */
                {
@@ -1612,18 +1631,20 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
 
                        old_pc_debug = pc_debug;
                        if (copy_from_user(&pc_debug, argp, sizeof(int)))
-                               return -EFAULT;
-
-                       if (old_pc_debug != pc_debug)
+                               rc = -EFAULT;
+                       else if (old_pc_debug != pc_debug)
                                DEBUGP(0, dev, "Changed debug log level "
                                       "to %i\n", pc_debug);
                }
-               return rc;
+               break;
 #endif
        default:
                DEBUGP(4, dev, "... in default (unknown IOCTL code)\n");
-               return -EINVAL;
+               rc = -ENOTTY;
        }
+out:
+       unlock_kernel();
+       return rc;
 }
 
 static int cmm_open(struct inode *inode, struct file *filp)
@@ -1631,16 +1652,22 @@ static int cmm_open(struct inode *inode, struct file *filp)
        struct cm4000_dev *dev;
        struct pcmcia_device *link;
        int minor = iminor(inode);
+       int ret;
 
        if (minor >= CM4000_MAX_DEV)
                return -ENODEV;
 
+       lock_kernel();
        link = dev_table[minor];
-       if (link == NULL || !pcmcia_dev_present(link))
-               return -ENODEV;
+       if (link == NULL || !pcmcia_dev_present(link)) {
+               ret = -ENODEV;
+               goto out;
+       }
 
-       if (link->open)
-               return -EBUSY;
+       if (link->open) {
+               ret = -EBUSY;
+               goto out;
+       }
 
        dev = link->priv;
        filp->private_data = dev;
@@ -1660,8 +1687,10 @@ static int cmm_open(struct inode *inode, struct file *filp)
         * vaild = block until valid (or card
         * inserted)
         */
-       if (filp->f_flags & O_NONBLOCK)
-               return -EAGAIN;
+       if (filp->f_flags & O_NONBLOCK) {
+               ret = -EAGAIN;
+               goto out;
+       }
 
        dev->mdelay = T_50MSEC;
 
@@ -1671,7 +1700,10 @@ static int cmm_open(struct inode *inode, struct file *filp)
        link->open = 1;         /* only one open per device */
 
        DEBUGP(2, dev, "<- cmm_open\n");
-       return nonseekable_open(inode, filp);
+       ret = nonseekable_open(inode, filp);
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int cmm_close(struct inode *inode, struct file *filp)
@@ -1897,7 +1929,7 @@ static const struct file_operations cm4000_fops = {
        .owner  = THIS_MODULE,
        .read   = cmm_read,
        .write  = cmm_write,
-       .ioctl  = cmm_ioctl,
+       .unlocked_ioctl = cmm_ioctl,
        .open   = cmm_open,
        .release= cmm_close,
 };
index 035084c..6181f8a 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/fs.h>
 #include <linux/delay.h>
 #include <linux/poll.h>
+#include <linux/smp_lock.h>
 #include <linux/wait.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -448,23 +449,30 @@ static int cm4040_open(struct inode *inode, struct file *filp)
        struct reader_dev *dev;
        struct pcmcia_device *link;
        int minor = iminor(inode);
+       int ret;
 
        if (minor >= CM_MAX_DEV)
                return -ENODEV;
 
+       lock_kernel();
        link = dev_table[minor];
-       if (link == NULL || !pcmcia_dev_present(link))
-               return -ENODEV;
+       if (link == NULL || !pcmcia_dev_present(link)) {
+               ret = -ENODEV;
+               goto out;
+       }
 
-       if (link->open)
-               return -EBUSY;
+       if (link->open) {
+               ret = -EBUSY;
+               goto out;
+       }
 
        dev = link->priv;
        filp->private_data = dev;
 
        if (filp->f_flags & O_NONBLOCK) {
                DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
-               return -EAGAIN;
+               ret = -EAGAIN;
+               goto out;
        }
 
        link->open = 1;
@@ -473,7 +481,10 @@ static int cm4040_open(struct inode *inode, struct file *filp)
        mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
 
        DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
-       return nonseekable_open(inode, filp);
+       ret = nonseekable_open(inode, filp);
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int cm4040_close(struct inode *inode, struct file *filp)
index 00c7f84..cc7dcea 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/device_id.h>
 #include <pcmcia/ss.h>
index 3aab837..f6e6aca 100644 (file)
@@ -66,6 +66,7 @@
 #include <linux/poll.h>
 #include <linux/major.h>
 #include <linux/ppdev.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
 #define PP_VERSION "ppdev: user-space parallel port driver"
@@ -638,6 +639,7 @@ static int pp_open (struct inode * inode, struct file * file)
        unsigned int minor = iminor(inode);
        struct pp_struct *pp;
 
+       cycle_kernel_lock();
        if (minor >= PARPORT_MAX)
                return -ENXIO;
 
index bbfa0e2..505fcbe 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/cdev.h>
 #include <linux/device.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -53,6 +54,7 @@ static int raw_open(struct inode *inode, struct file *filp)
                return 0;
        }
 
+       lock_kernel();
        mutex_lock(&raw_mutex);
 
        /*
@@ -79,6 +81,7 @@ static int raw_open(struct inode *inode, struct file *filp)
                        bdev->bd_inode->i_mapping;
        filp->private_data = bdev;
        mutex_unlock(&raw_mutex);
+       unlock_kernel();
        return 0;
 
 out2:
index 909cac9..fa92a8a 100644 (file)
@@ -73,6 +73,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/sysctl.h>
 #include <linux/wait.h>
 #include <linux/bcd.h>
@@ -734,6 +735,7 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
  * needed here. Or anywhere else in this driver. */
 static int rtc_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock_irq(&rtc_lock);
 
        if (rtc_status & RTC_IS_OPEN)
@@ -743,10 +745,12 @@ static int rtc_open(struct inode *inode, struct file *file)
 
        rtc_irq_data = 0;
        spin_unlock_irq(&rtc_lock);
+       unlock_kernel();
        return 0;
 
 out_busy:
        spin_unlock_irq(&rtc_lock);
+       unlock_kernel();
        return -EBUSY;
 }
 
index 99e5272..1d91005 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -51,6 +52,7 @@ static int scx200_gpio_open(struct inode *inode, struct file *file)
        unsigned m = iminor(inode);
        file->private_data = &scx200_gpio_ops;
 
+       cycle_kernel_lock();
        if (m >= MAX_PINS)
                return -EINVAL;
        return nonseekable_open(inode, file);
index 8fe099a..0b799ac 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/poll.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <asm/sn/io.h>
 #include <asm/sn/sn_sal.h>
 #include <asm/sn/module.h>
@@ -104,6 +105,7 @@ scdrv_open(struct inode *inode, struct file *file)
        file->private_data = sd;
 
        /* hook this subchannel up to the system controller interrupt */
+       lock_kernel();
        rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt,
                         IRQF_SHARED | IRQF_DISABLED,
                         SYSCTL_BASENAME, sd);
@@ -111,9 +113,10 @@ scdrv_open(struct inode *inode, struct file *file)
                ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch);
                kfree(sd);
                printk("%s: irq request failed (%d)\n", __func__, rv);
+               unlock_kernel();
                return -EBUSY;
        }
-
+       unlock_kernel();
        return 0;
 }
 
index 58533de..85e0eb7 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/err.h>
 #include <linux/kfifo.h>
 #include <linux/platform_device.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -906,12 +907,14 @@ static int sonypi_misc_release(struct inode *inode, struct file *file)
 
 static int sonypi_misc_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        mutex_lock(&sonypi_device.lock);
        /* Flush input queue on first open */
        if (!sonypi_device.open_count)
                kfifo_reset(sonypi_device.fifo);
        sonypi_device.open_count++;
        mutex_unlock(&sonypi_device.lock);
+       unlock_kernel();
        return 0;
 }
 
index 4c431cb..6062b62 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/smp_lock.h>
 
 #include <asm/io.h>
 #include <asm/reboot.h>
@@ -236,6 +237,7 @@ static int tanbac_tb0219_open(struct inode *inode, struct file *file)
 {
        unsigned int minor;
 
+       cycle_kernel_lock();
        minor = iminor(inode);
        switch (minor) {
        case 0:
index 35e5803..8f2284b 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/timer.h>
 #include <linux/sysfs.h>
 #include <linux/device.h>
@@ -204,11 +205,14 @@ static int tlclk_open(struct inode *inode, struct file *filp)
 {
        int result;
 
-       if (test_and_set_bit(0, &useflags))
-               return -EBUSY;
+       lock_kernel();
+       if (test_and_set_bit(0, &useflags)) {
+               result = -EBUSY;
                /* this legacy device is always one per system and it doesn't
                 * know how to handle multiple concurrent clients.
                 */
+               goto out;
+       }
 
        /* Make sure there is no interrupt pending while
         * initialising interrupt handler */
@@ -218,13 +222,14 @@ static int tlclk_open(struct inode *inode, struct file *filp)
         * we can't share this IRQ */
        result = request_irq(telclk_interrupt, &tlclk_interrupt,
                             IRQF_DISABLED, "telco_clock", tlclk_interrupt);
-       if (result == -EBUSY) {
+       if (result == -EBUSY)
                printk(KERN_ERR "tlclk: Interrupt can't be reserved.\n");
-               return -EBUSY;
-       }
-       inb(TLCLK_REG6);        /* Clear interrupt events */
+       else
+               inb(TLCLK_REG6);        /* Clear interrupt events */
 
-       return 0;
+out:
+       unlock_kernel();
+       return result;
 }
 
 static int tlclk_release(struct inode *inode, struct file *filp)
index a5d8bcb..e1fc193 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/poll.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 
 #include "tpm.h"
 
@@ -897,6 +898,7 @@ int tpm_open(struct inode *inode, struct file *file)
        int rc = 0, minor = iminor(inode);
        struct tpm_chip *chip = NULL, *pos;
 
+       lock_kernel();
        spin_lock(&driver_lock);
 
        list_for_each_entry(pos, &tpm_chip_list, list) {
@@ -926,16 +928,19 @@ int tpm_open(struct inode *inode, struct file *file)
        if (chip->data_buffer == NULL) {
                chip->num_opens--;
                put_device(chip->dev);
+               unlock_kernel();
                return -ENOMEM;
        }
 
        atomic_set(&chip->data_pending, 0);
 
        file->private_data = chip;
+       unlock_kernel();
        return 0;
 
 err_out:
        spin_unlock(&driver_lock);
+       unlock_kernel();
        return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_open);
index 7501310..047a173 100644 (file)
@@ -2665,7 +2665,7 @@ static void release_dev(struct file *filp)
  *              ->siglock protects ->signal/->sighand
  */
 
-static int tty_open(struct inode *inode, struct file *filp)
+static int __tty_open(struct inode *inode, struct file *filp)
 {
        struct tty_struct *tty;
        int noctty, retval;
@@ -2779,6 +2779,19 @@ got_driver:
        return 0;
 }
 
+/* BKL pushdown: scary code avoidance wrapper */
+static int tty_open(struct inode *inode, struct file *filp)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __tty_open(inode, filp);
+       unlock_kernel();
+       return ret;
+}
+
+
+
 #ifdef CONFIG_UNIX98_PTYS
 /**
  *     ptmx_open               -       open a unix 98 pty master
@@ -2792,7 +2805,7 @@ got_driver:
  *             allocated_ptys_lock handles the list of free pty numbers
  */
 
-static int ptmx_open(struct inode *inode, struct file *filp)
+static int __ptmx_open(struct inode *inode, struct file *filp)
 {
        struct tty_struct *tty;
        int retval;
@@ -2831,6 +2844,16 @@ out:
        devpts_kill_index(index);
        return retval;
 }
+
+static int ptmx_open(struct inode *inode, struct file *filp)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __ptmx_open(inode, filp);
+       unlock_kernel();
+       return ret;
+}
 #endif
 
 /**
@@ -2886,15 +2909,16 @@ static int tty_fasync(int fd, struct file *filp, int on)
 {
        struct tty_struct *tty;
        unsigned long flags;
-       int retval;
+       int retval = 0;
 
+       lock_kernel();
        tty = (struct tty_struct *)filp->private_data;
        if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
-               return 0;
+               goto out;
 
        retval = fasync_helper(fd, filp, on, &tty->fasync);
        if (retval <= 0)
-               return retval;
+               goto out;
 
        if (on) {
                enum pid_type type;
@@ -2912,12 +2936,15 @@ static int tty_fasync(int fd, struct file *filp, int on)
                spin_unlock_irqrestore(&tty->ctrl_lock, flags);
                retval = __f_setown(filp, pid, type, 0);
                if (retval)
-                       return retval;
+                       goto out;
        } else {
                if (!tty->fasync && !waitqueue_active(&tty->read_wait))
                        tty->minimum_to_wake = N_TTY_BUF_SIZE;
        }
-       return 0;
+       retval = 0;
+out:
+       unlock_kernel();
+       return retval;
 }
 
 /**
index 83aeedd..eebfad2 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/kbd_kern.h>
 #include <linux/console.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
@@ -460,9 +461,13 @@ static int
 vcs_open(struct inode *inode, struct file *filp)
 {
        unsigned int currcons = iminor(inode) & 127;
+       int ret = 0;
+       
+       lock_kernel();
        if(currcons && !vc_cons_allocated(currcons-1))
-               return -ENXIO;
-       return 0;
+               ret = -ENXIO;
+       unlock_kernel();
+       return ret;
 }
 
 static const struct file_operations vcs_fops = {
index d4db42c..e5da98d 100644 (file)
@@ -699,6 +699,7 @@ static int viotap_open(struct inode *inode, struct file *file)
        if (op == NULL)
                return -ENOMEM;
 
+       lock_kernel();
        get_dev_info(file->f_path.dentry->d_inode, &devi);
 
        /* Note: We currently only support one mode! */
@@ -729,6 +730,7 @@ static int viotap_open(struct inode *inode, struct file *file)
 
 free_op:
        free_op_struct(op);
+       unlock_kernel();
        return ret;
 }
 
index e5ed091..ffe9b4e 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
@@ -547,6 +548,7 @@ static int gpio_open(struct inode *inode, struct file *file)
 {
        unsigned int pin;
 
+       cycle_kernel_lock();
        pin = iminor(inode);
        if (pin >= giu_nr_pins)
                return -EBADF;
index 3edf1fc..1e1b81e 100644 (file)
@@ -85,6 +85,7 @@
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 #include <linux/sysctl.h>
 #include <linux/version.h>
 #include <linux/fs.h>
@@ -504,11 +505,12 @@ static int hwicap_open(struct inode *inode, struct file *file)
        struct hwicap_drvdata *drvdata;
        int status;
 
+       lock_kernel();
        drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev);
 
        status = mutex_lock_interruptible(&drvdata->sem);
        if (status)
-               return status;
+               goto out;
 
        if (drvdata->is_open) {
                status = -EBUSY;
@@ -528,6 +530,8 @@ static int hwicap_open(struct inode *inode, struct file *file)
 
  error:
        mutex_unlock(&drvdata->sem);
+ out:
+       unlock_kernel();
        return status;
 }
 
index 43b71b6..e522144 100644 (file)
@@ -174,4 +174,30 @@ config CRYPTO_DEV_HIFN_795X_RNG
          Select this option if you want to enable the random number generator
          on the HIFN 795x crypto adapters.
 
+config CRYPTO_DEV_TALITOS
+       tristate "Talitos Freescale Security Engine (SEC)"
+       select CRYPTO_ALGAPI
+       select CRYPTO_AUTHENC
+       select HW_RANDOM
+       depends on FSL_SOC
+       help
+         Say 'Y' here to use the Freescale Security Engine (SEC)
+         to offload cryptographic algorithm computation.
+
+         The Freescale SEC is present on PowerQUICC 'E' processors, such
+         as the MPC8349E and MPC8548E.
+
+         To compile this driver as a module, choose M here: the module
+         will be called talitos.
+
+config CRYPTO_DEV_IXP4XX
+       tristate "Driver for IXP4xx crypto hardware acceleration"
+       depends on ARCH_IXP4XX
+       select CRYPTO_DES
+       select CRYPTO_ALGAPI
+       select CRYPTO_AUTHENC
+       select CRYPTO_BLKCIPHER
+       help
+         Driver for the IXP4xx NPE crypto engine.
+
 endif # CRYPTO_HW
index c0327f0..73557b2 100644 (file)
@@ -2,3 +2,5 @@ obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o
 obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o
 obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
 obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
+obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o
+obj-$(CONFIG_CRYPTO_DEV_IXP4XX) += ixp4xx_crypto.o
index 81f3f95..4d22b21 100644 (file)
@@ -29,7 +29,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/scatterlist.h>
 #include <linux/highmem.h>
-#include <linux/interrupt.h>
 #include <linux/crypto.h>
 #include <linux/hw_random.h>
 #include <linux/ktime.h>
@@ -369,7 +368,9 @@ static atomic_t hifn_dev_number;
 #define        HIFN_D_DST_RSIZE                80*4
 #define        HIFN_D_RES_RSIZE                24*4
 
-#define HIFN_QUEUE_LENGTH              HIFN_D_CMD_RSIZE-5
+#define HIFN_D_DST_DALIGN              4
+
+#define HIFN_QUEUE_LENGTH              HIFN_D_CMD_RSIZE-1
 
 #define AES_MIN_KEY_SIZE               16
 #define AES_MAX_KEY_SIZE               32
@@ -535,10 +536,10 @@ struct hifn_crypt_command
  */
 struct hifn_mac_command
 {
-       volatile u16            masks;
-       volatile u16            header_skip;
-       volatile u16            source_count;
-       volatile u16            reserved;
+       volatile __le16         masks;
+       volatile __le16         header_skip;
+       volatile __le16         source_count;
+       volatile __le16         reserved;
 };
 
 #define        HIFN_MAC_CMD_ALG_MASK           0x0001
@@ -564,10 +565,10 @@ struct hifn_mac_command
 
 struct hifn_comp_command
 {
-       volatile u16            masks;
-       volatile u16            header_skip;
-       volatile u16            source_count;
-       volatile u16            reserved;
+       volatile __le16         masks;
+       volatile __le16         header_skip;
+       volatile __le16         source_count;
+       volatile __le16         reserved;
 };
 
 #define        HIFN_COMP_CMD_SRCLEN_M          0xc000
@@ -583,10 +584,10 @@ struct hifn_comp_command
 
 struct hifn_base_result
 {
-       volatile u16            flags;
-       volatile u16            session;
-       volatile u16            src_cnt;                /* 15:0 of source count */
-       volatile u16            dst_cnt;                /* 15:0 of dest count */
+       volatile __le16         flags;
+       volatile __le16         session;
+       volatile __le16         src_cnt;                /* 15:0 of source count */
+       volatile __le16         dst_cnt;                /* 15:0 of dest count */
 };
 
 #define        HIFN_BASE_RES_DSTOVERRUN        0x0200  /* destination overrun */
@@ -597,8 +598,8 @@ struct hifn_base_result
 
 struct hifn_comp_result
 {
-       volatile u16            flags;
-       volatile u16            crc;
+       volatile __le16         flags;
+       volatile __le16         crc;
 };
 
 #define        HIFN_COMP_RES_LCB_M             0xff00  /* longitudinal check byte */
@@ -609,8 +610,8 @@ struct hifn_comp_result
 
 struct hifn_mac_result
 {
-       volatile u16            flags;
-       volatile u16            reserved;
+       volatile __le16         flags;
+       volatile __le16         reserved;
        /* followed by 0, 6, 8, or 10 u16's of the MAC, then crypt */
 };
 
@@ -619,8 +620,8 @@ struct hifn_mac_result
 
 struct hifn_crypt_result
 {
-       volatile u16            flags;
-       volatile u16            reserved;
+       volatile __le16         flags;
+       volatile __le16         reserved;
 };
 
 #define        HIFN_CRYPT_RES_SRC_NOTZERO      0x0001  /* source expired */
@@ -686,12 +687,12 @@ static inline u32 hifn_read_1(struct hifn_device *dev, u32 reg)
 
 static inline void hifn_write_0(struct hifn_device *dev, u32 reg, u32 val)
 {
-       writel(val, dev->bar[0] + reg);
+       writel((__force u32)cpu_to_le32(val), dev->bar[0] + reg);
 }
 
 static inline void hifn_write_1(struct hifn_device *dev, u32 reg, u32 val)
 {
-       writel(val, dev->bar[1] + reg);
+       writel((__force u32)cpu_to_le32(val), dev->bar[1] + reg);
 }
 
 static void hifn_wait_puc(struct hifn_device *dev)
@@ -894,7 +895,7 @@ static int hifn_enable_crypto(struct hifn_device *dev)
        char *offtbl = NULL;
        int i;
 
-       for (i = 0; i < sizeof(pci2id)/sizeof(pci2id[0]); i++) {
+       for (i = 0; i < ARRAY_SIZE(pci2id); i++) {
                if (pci2id[i].pci_vendor == dev->pdev->vendor &&
                                pci2id[i].pci_prod == dev->pdev->device) {
                        offtbl = pci2id[i].card_id;
@@ -1037,14 +1038,14 @@ static void hifn_init_registers(struct hifn_device *dev)
        hifn_write_0(dev, HIFN_0_PUIER, HIFN_PUIER_DSTOVER);
 
        /* write all 4 ring address registers */
-       hifn_write_1(dev, HIFN_1_DMA_CRAR, __cpu_to_le32(dptr +
-                               offsetof(struct hifn_dma, cmdr[0])));
-       hifn_write_1(dev, HIFN_1_DMA_SRAR, __cpu_to_le32(dptr +
-                               offsetof(struct hifn_dma, srcr[0])));
-       hifn_write_1(dev, HIFN_1_DMA_DRAR, __cpu_to_le32(dptr +
-                               offsetof(struct hifn_dma, dstr[0])));
-       hifn_write_1(dev, HIFN_1_DMA_RRAR, __cpu_to_le32(dptr +
-                               offsetof(struct hifn_dma, resr[0])));
+       hifn_write_1(dev, HIFN_1_DMA_CRAR, dptr +
+                               offsetof(struct hifn_dma, cmdr[0]));
+       hifn_write_1(dev, HIFN_1_DMA_SRAR, dptr +
+                               offsetof(struct hifn_dma, srcr[0]));
+       hifn_write_1(dev, HIFN_1_DMA_DRAR, dptr +
+                               offsetof(struct hifn_dma, dstr[0]));
+       hifn_write_1(dev, HIFN_1_DMA_RRAR, dptr +
+                               offsetof(struct hifn_dma, resr[0]));
 
        mdelay(2);
 #if 0
@@ -1166,109 +1167,15 @@ static int hifn_setup_crypto_command(struct hifn_device *dev,
        return cmd_len;
 }
 
-static int hifn_setup_src_desc(struct hifn_device *dev, struct page *page,
-               unsigned int offset, unsigned int size)
-{
-       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
-       int idx;
-       dma_addr_t addr;
-
-       addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_TODEVICE);
-
-       idx = dma->srci;
-
-       dma->srcr[idx].p = __cpu_to_le32(addr);
-       dma->srcr[idx].l = __cpu_to_le32(size) | HIFN_D_VALID |
-                       HIFN_D_MASKDONEIRQ | HIFN_D_NOINVALID | HIFN_D_LAST;
-
-       if (++idx == HIFN_D_SRC_RSIZE) {
-               dma->srcr[idx].l = __cpu_to_le32(HIFN_D_VALID |
-                               HIFN_D_JUMP |
-                               HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
-               idx = 0;
-       }
-
-       dma->srci = idx;
-       dma->srcu++;
-
-       if (!(dev->flags & HIFN_FLAG_SRC_BUSY)) {
-               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_S_CTRL_ENA);
-               dev->flags |= HIFN_FLAG_SRC_BUSY;
-       }
-
-       return size;
-}
-
-static void hifn_setup_res_desc(struct hifn_device *dev)
-{
-       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
-
-       dma->resr[dma->resi].l = __cpu_to_le32(HIFN_USED_RESULT |
-                       HIFN_D_VALID | HIFN_D_LAST);
-       /*
-        * dma->resr[dma->resi].l = __cpu_to_le32(HIFN_MAX_RESULT | HIFN_D_VALID |
-        *                                      HIFN_D_LAST | HIFN_D_NOINVALID);
-        */
-
-       if (++dma->resi == HIFN_D_RES_RSIZE) {
-               dma->resr[HIFN_D_RES_RSIZE].l = __cpu_to_le32(HIFN_D_VALID |
-                               HIFN_D_JUMP | HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
-               dma->resi = 0;
-       }
-
-       dma->resu++;
-
-       if (!(dev->flags & HIFN_FLAG_RES_BUSY)) {
-               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_R_CTRL_ENA);
-               dev->flags |= HIFN_FLAG_RES_BUSY;
-       }
-}
-
-static void hifn_setup_dst_desc(struct hifn_device *dev, struct page *page,
-               unsigned offset, unsigned size)
-{
-       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
-       int idx;
-       dma_addr_t addr;
-
-       addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_FROMDEVICE);
-
-       idx = dma->dsti;
-       dma->dstr[idx].p = __cpu_to_le32(addr);
-       dma->dstr[idx].l = __cpu_to_le32(size | HIFN_D_VALID |
-                       HIFN_D_MASKDONEIRQ | HIFN_D_NOINVALID | HIFN_D_LAST);
-
-       if (++idx == HIFN_D_DST_RSIZE) {
-               dma->dstr[idx].l = __cpu_to_le32(HIFN_D_VALID |
-                               HIFN_D_JUMP | HIFN_D_MASKDONEIRQ |
-                               HIFN_D_LAST | HIFN_D_NOINVALID);
-               idx = 0;
-       }
-       dma->dsti = idx;
-       dma->dstu++;
-
-       if (!(dev->flags & HIFN_FLAG_DST_BUSY)) {
-               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_D_CTRL_ENA);
-               dev->flags |= HIFN_FLAG_DST_BUSY;
-       }
-}
-
-static int hifn_setup_dma(struct hifn_device *dev, struct page *spage, unsigned int soff,
-               struct page *dpage, unsigned int doff, unsigned int nbytes, void *priv,
-               struct hifn_context *ctx)
+static int hifn_setup_cmd_desc(struct hifn_device *dev,
+               struct hifn_context *ctx, void *priv, unsigned int nbytes)
 {
        struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
        int cmd_len, sa_idx;
        u8 *buf, *buf_pos;
        u16 mask;
 
-       dprintk("%s: spage: %p, soffset: %u, dpage: %p, doffset: %u, nbytes: %u, priv: %p, ctx: %p.\n",
-                       dev->name, spage, soff, dpage, doff, nbytes, priv, ctx);
-
-       sa_idx = dma->resi;
-
-       hifn_setup_src_desc(dev, spage, soff, nbytes);
-
+       sa_idx = dma->cmdi;
        buf_pos = buf = dma->command_bufs[dma->cmdi];
 
        mask = 0;
@@ -1370,16 +1277,113 @@ static int hifn_setup_dma(struct hifn_device *dev, struct page *spage, unsigned
                hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_C_CTRL_ENA);
                dev->flags |= HIFN_FLAG_CMD_BUSY;
        }
-
-       hifn_setup_dst_desc(dev, dpage, doff, nbytes);
-       hifn_setup_res_desc(dev);
-
        return 0;
 
 err_out:
        return -EINVAL;
 }
 
+static int hifn_setup_src_desc(struct hifn_device *dev, struct page *page,
+               unsigned int offset, unsigned int size)
+{
+       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
+       int idx;
+       dma_addr_t addr;
+
+       addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_TODEVICE);
+
+       idx = dma->srci;
+
+       dma->srcr[idx].p = __cpu_to_le32(addr);
+       dma->srcr[idx].l = __cpu_to_le32(size | HIFN_D_VALID |
+                       HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
+
+       if (++idx == HIFN_D_SRC_RSIZE) {
+               dma->srcr[idx].l = __cpu_to_le32(HIFN_D_VALID |
+                               HIFN_D_JUMP |
+                               HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
+               idx = 0;
+       }
+
+       dma->srci = idx;
+       dma->srcu++;
+
+       if (!(dev->flags & HIFN_FLAG_SRC_BUSY)) {
+               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_S_CTRL_ENA);
+               dev->flags |= HIFN_FLAG_SRC_BUSY;
+       }
+
+       return size;
+}
+
+static void hifn_setup_res_desc(struct hifn_device *dev)
+{
+       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
+
+       dma->resr[dma->resi].l = __cpu_to_le32(HIFN_USED_RESULT |
+                       HIFN_D_VALID | HIFN_D_LAST);
+       /*
+        * dma->resr[dma->resi].l = __cpu_to_le32(HIFN_MAX_RESULT | HIFN_D_VALID |
+        *                                      HIFN_D_LAST);
+        */
+
+       if (++dma->resi == HIFN_D_RES_RSIZE) {
+               dma->resr[HIFN_D_RES_RSIZE].l = __cpu_to_le32(HIFN_D_VALID |
+                               HIFN_D_JUMP | HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
+               dma->resi = 0;
+       }
+
+       dma->resu++;
+
+       if (!(dev->flags & HIFN_FLAG_RES_BUSY)) {
+               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_R_CTRL_ENA);
+               dev->flags |= HIFN_FLAG_RES_BUSY;
+       }
+}
+
+static void hifn_setup_dst_desc(struct hifn_device *dev, struct page *page,
+               unsigned offset, unsigned size)
+{
+       struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
+       int idx;
+       dma_addr_t addr;
+
+       addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_FROMDEVICE);
+
+       idx = dma->dsti;
+       dma->dstr[idx].p = __cpu_to_le32(addr);
+       dma->dstr[idx].l = __cpu_to_le32(size | HIFN_D_VALID |
+                       HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
+
+       if (++idx == HIFN_D_DST_RSIZE) {
+               dma->dstr[idx].l = __cpu_to_le32(HIFN_D_VALID |
+                               HIFN_D_JUMP | HIFN_D_MASKDONEIRQ |
+                               HIFN_D_LAST);
+               idx = 0;
+       }
+       dma->dsti = idx;
+       dma->dstu++;
+
+       if (!(dev->flags & HIFN_FLAG_DST_BUSY)) {
+               hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_D_CTRL_ENA);
+               dev->flags |= HIFN_FLAG_DST_BUSY;
+       }
+}
+
+static int hifn_setup_dma(struct hifn_device *dev, struct page *spage, unsigned int soff,
+               struct page *dpage, unsigned int doff, unsigned int nbytes, void *priv,
+               struct hifn_context *ctx)
+{
+       dprintk("%s: spage: %p, soffset: %u, dpage: %p, doffset: %u, nbytes: %u, priv: %p, ctx: %p.\n",
+                       dev->name, spage, soff, dpage, doff, nbytes, priv, ctx);
+
+       hifn_setup_src_desc(dev, spage, soff, nbytes);
+       hifn_setup_cmd_desc(dev, ctx, priv, nbytes);
+       hifn_setup_dst_desc(dev, dpage, doff, nbytes);
+       hifn_setup_res_desc(dev);
+       return 0;
+}
+
 static int ablkcipher_walk_init(struct ablkcipher_walk *w,
                int num, gfp_t gfp_flags)
 {
@@ -1431,7 +1435,7 @@ static int ablkcipher_add(void *daddr, unsigned int *drestp, struct scatterlist
                return -EINVAL;
 
        while (size) {
-               copy = min(drest, src->length);
+               copy = min(drest, min(size, src->length));
 
                saddr = kmap_atomic(sg_page(src), KM_SOFTIRQ1);
                memcpy(daddr, saddr + src->offset, copy);
@@ -1458,10 +1462,6 @@ static int ablkcipher_add(void *daddr, unsigned int *drestp, struct scatterlist
 static int ablkcipher_walk(struct ablkcipher_request *req,
                struct ablkcipher_walk *w)
 {
-       unsigned blocksize =
-               crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm(req));
-       unsigned alignmask =
-               crypto_ablkcipher_alignmask(crypto_ablkcipher_reqtfm(req));
        struct scatterlist *src, *dst, *t;
        void *daddr;
        unsigned int nbytes = req->nbytes, offset, copy, diff;
@@ -1477,16 +1477,14 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
                dst = &req->dst[idx];
 
                dprintk("\n%s: slen: %u, dlen: %u, soff: %u, doff: %u, offset: %u, "
-                               "blocksize: %u, nbytes: %u.\n",
+                               "nbytes: %u.\n",
                                __func__, src->length, dst->length, src->offset,
-                               dst->offset, offset, blocksize, nbytes);
-
-               if (src->length & (blocksize - 1) ||
-                               src->offset & (alignmask - 1) ||
-                               dst->length & (blocksize - 1) ||
-                               dst->offset & (alignmask - 1) ||
-                               offset) {
-                       unsigned slen = src->length - offset;
+                               dst->offset, offset, nbytes);
+
+               if (!IS_ALIGNED(dst->offset, HIFN_D_DST_DALIGN) ||
+                   !IS_ALIGNED(dst->length, HIFN_D_DST_DALIGN) ||
+                   offset) {
+                       unsigned slen = min(src->length - offset, nbytes);
                        unsigned dlen = PAGE_SIZE;
 
                        t = &w->cache[idx];
@@ -1498,8 +1496,8 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
 
                        idx += err;
 
-                       copy = slen & ~(blocksize - 1);
-                       diff = slen & (blocksize - 1);
+                       copy = slen & ~(HIFN_D_DST_DALIGN - 1);
+                       diff = slen & (HIFN_D_DST_DALIGN - 1);
 
                        if (dlen < nbytes) {
                                /*
@@ -1507,7 +1505,7 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
                                 * to put there additional blocksized chunk,
                                 * so we mark that page as containing only
                                 * blocksize aligned chunks:
-                                *      t->length = (slen & ~(blocksize - 1));
+                                *      t->length = (slen & ~(HIFN_D_DST_DALIGN - 1));
                                 * and increase number of bytes to be processed
                                 * in next chunk:
                                 *      nbytes += diff;
@@ -1544,7 +1542,7 @@ static int ablkcipher_walk(struct ablkcipher_request *req,
 
                        kunmap_atomic(daddr, KM_SOFTIRQ0);
                } else {
-                       nbytes -= src->length;
+                       nbytes -= min(src->length, nbytes);
                        idx++;
                }
 
@@ -1563,14 +1561,10 @@ static int hifn_setup_session(struct ablkcipher_request *req)
        struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
        struct hifn_device *dev = ctx->dev;
        struct page *spage, *dpage;
-       unsigned long soff, doff, flags;
+       unsigned long soff, doff, dlen, flags;
        unsigned int nbytes = req->nbytes, idx = 0, len;
        int err = -EINVAL, sg_num;
        struct scatterlist *src, *dst, *t;
-       unsigned blocksize =
-               crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm(req));
-       unsigned alignmask =
-               crypto_ablkcipher_alignmask(crypto_ablkcipher_reqtfm(req));
 
        if (ctx->iv && !ctx->ivsize && ctx->mode != ACRYPTO_MODE_ECB)
                goto err_out_exit;
@@ -1578,17 +1572,14 @@ static int hifn_setup_session(struct ablkcipher_request *req)
        ctx->walk.flags = 0;
 
        while (nbytes) {
-               src = &req->src[idx];
                dst = &req->dst[idx];
+               dlen = min(dst->length, nbytes);
 
-               if (src->length & (blocksize - 1) ||
-                               src->offset & (alignmask - 1) ||
-                               dst->length & (blocksize - 1) ||
-                               dst->offset & (alignmask - 1)) {
+               if (!IS_ALIGNED(dst->offset, HIFN_D_DST_DALIGN) ||
+                   !IS_ALIGNED(dlen, HIFN_D_DST_DALIGN))
                        ctx->walk.flags |= ASYNC_FLAGS_MISALIGNED;
-               }
 
-               nbytes -= src->length;
+               nbytes -= dlen;
                idx++;
        }
 
@@ -1602,7 +1593,10 @@ static int hifn_setup_session(struct ablkcipher_request *req)
        idx = 0;
 
        sg_num = ablkcipher_walk(req, &ctx->walk);
-
+       if (sg_num < 0) {
+               err = sg_num;
+               goto err_out_exit;
+       }
        atomic_set(&ctx->sg_num, sg_num);
 
        spin_lock_irqsave(&dev->lock, flags);
@@ -1640,7 +1634,7 @@ static int hifn_setup_session(struct ablkcipher_request *req)
                if (err)
                        goto err_out;
 
-               nbytes -= len;
+               nbytes -= min(len, nbytes);
        }
 
        dev->active = HIFN_DEFAULT_ACTIVE_NUM;
@@ -1651,7 +1645,7 @@ static int hifn_setup_session(struct ablkcipher_request *req)
 err_out:
        spin_unlock_irqrestore(&dev->lock, flags);
 err_out_exit:
-       if (err && printk_ratelimit())
+       if (err)
                dprintk("%s: iv: %p [%d], key: %p [%d], mode: %u, op: %u, "
                                "type: %u, err: %d.\n",
                        dev->name, ctx->iv, ctx->ivsize,
@@ -1745,8 +1739,7 @@ static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset
                return -EINVAL;
 
        while (size) {
-
-               copy = min(dst->length, srest);
+               copy = min(srest, min(dst->length, size));
 
                daddr = kmap_atomic(sg_page(dst), KM_IRQ0);
                memcpy(daddr + dst->offset + offset, saddr, copy);
@@ -1803,7 +1796,7 @@ static void hifn_process_ready(struct ablkcipher_request *req, int error)
                                        sg_page(dst), dst->length, nbytes);
 
                                if (!t->length) {
-                                       nbytes -= dst->length;
+                                       nbytes -= min(dst->length, nbytes);
                                        idx++;
                                        continue;
                                }
@@ -2202,9 +2195,9 @@ static int hifn_setup_crypto(struct ablkcipher_request *req, u8 op,
                return err;
 
        if (dev->started < HIFN_QUEUE_LENGTH && dev->queue.qlen)
-               err = hifn_process_queue(dev);
+               hifn_process_queue(dev);
 
-       return err;
+       return -EINPROGRESS;
 }
 
 /*
@@ -2364,7 +2357,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
         * 3DES ECB, CBC, CFB and OFB modes.
         */
        {
-               .name = "cfb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
+               .name = "cfb(des3_ede)", .drv_name = "cfb-3des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_3DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_3DES_KEY_LENGTH,
@@ -2374,7 +2367,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "ofb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
+               .name = "ofb(des3_ede)", .drv_name = "ofb-3des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_3DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_3DES_KEY_LENGTH,
@@ -2384,8 +2377,9 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "cbc(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
+               .name = "cbc(des3_ede)", .drv_name = "cbc-3des", .bsize = 8,
                .ablkcipher = {
+                       .ivsize         =       HIFN_IV_LENGTH,
                        .min_keysize    =       HIFN_3DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_3DES_KEY_LENGTH,
                        .setkey         =       hifn_setkey,
@@ -2394,7 +2388,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "ecb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
+               .name = "ecb(des3_ede)", .drv_name = "ecb-3des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_3DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_3DES_KEY_LENGTH,
@@ -2408,7 +2402,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
         * DES ECB, CBC, CFB and OFB modes.
         */
        {
-               .name = "cfb(des)", .drv_name = "hifn-des", .bsize = 8,
+               .name = "cfb(des)", .drv_name = "cfb-des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_DES_KEY_LENGTH,
@@ -2418,7 +2412,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "ofb(des)", .drv_name = "hifn-des", .bsize = 8,
+               .name = "ofb(des)", .drv_name = "ofb-des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_DES_KEY_LENGTH,
@@ -2428,8 +2422,9 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "cbc(des)", .drv_name = "hifn-des", .bsize = 8,
+               .name = "cbc(des)", .drv_name = "cbc-des", .bsize = 8,
                .ablkcipher = {
+                       .ivsize         =       HIFN_IV_LENGTH,
                        .min_keysize    =       HIFN_DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_DES_KEY_LENGTH,
                        .setkey         =       hifn_setkey,
@@ -2438,7 +2433,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "ecb(des)", .drv_name = "hifn-des", .bsize = 8,
+               .name = "ecb(des)", .drv_name = "ecb-des", .bsize = 8,
                .ablkcipher = {
                        .min_keysize    =       HIFN_DES_KEY_LENGTH,
                        .max_keysize    =       HIFN_DES_KEY_LENGTH,
@@ -2452,7 +2447,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
         * AES ECB, CBC, CFB and OFB modes.
         */
        {
-               .name = "ecb(aes)", .drv_name = "hifn-aes", .bsize = 16,
+               .name = "ecb(aes)", .drv_name = "ecb-aes", .bsize = 16,
                .ablkcipher = {
                        .min_keysize    =       AES_MIN_KEY_SIZE,
                        .max_keysize    =       AES_MAX_KEY_SIZE,
@@ -2462,8 +2457,9 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "cbc(aes)", .drv_name = "hifn-aes", .bsize = 16,
+               .name = "cbc(aes)", .drv_name = "cbc-aes", .bsize = 16,
                .ablkcipher = {
+                       .ivsize         =       HIFN_AES_IV_LENGTH,
                        .min_keysize    =       AES_MIN_KEY_SIZE,
                        .max_keysize    =       AES_MAX_KEY_SIZE,
                        .setkey         =       hifn_setkey,
@@ -2472,7 +2468,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "cfb(aes)", .drv_name = "hifn-aes", .bsize = 16,
+               .name = "cfb(aes)", .drv_name = "cfb-aes", .bsize = 16,
                .ablkcipher = {
                        .min_keysize    =       AES_MIN_KEY_SIZE,
                        .max_keysize    =       AES_MAX_KEY_SIZE,
@@ -2482,7 +2478,7 @@ static struct hifn_alg_template hifn_alg_templates[] = {
                },
        },
        {
-               .name = "ofb(aes)", .drv_name = "hifn-aes", .bsize = 16,
+               .name = "ofb(aes)", .drv_name = "ofb-aes", .bsize = 16,
                .ablkcipher = {
                        .min_keysize    =       AES_MIN_KEY_SIZE,
                        .max_keysize    =       AES_MAX_KEY_SIZE,
@@ -2514,15 +2510,14 @@ static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t)
                return -ENOMEM;
 
        snprintf(alg->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s", t->name);
-       snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name);
+       snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s-%s",
+                t->drv_name, dev->name);
 
        alg->alg.cra_priority = 300;
        alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
        alg->alg.cra_blocksize = t->bsize;
        alg->alg.cra_ctxsize = sizeof(struct hifn_context);
-       alg->alg.cra_alignmask = 15;
-       if (t->bsize == 8)
-               alg->alg.cra_alignmask = 3;
+       alg->alg.cra_alignmask = 0;
        alg->alg.cra_type = &crypto_ablkcipher_type;
        alg->alg.cra_module = THIS_MODULE;
        alg->alg.cra_u.ablkcipher = t->ablkcipher;
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
new file mode 100644 (file)
index 0000000..42a107f
--- /dev/null
@@ -0,0 +1,1506 @@
+/*
+ * Intel IXP4xx NPE-C crypto driver
+ *
+ * Copyright (C) 2008 Christian Hohnstaedt <chohnstaedt@innominate.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/crypto.h>
+#include <linux/kernel.h>
+#include <linux/rtnetlink.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+
+#include <crypto/ctr.h>
+#include <crypto/des.h>
+#include <crypto/aes.h>
+#include <crypto/sha.h>
+#include <crypto/algapi.h>
+#include <crypto/aead.h>
+#include <crypto/authenc.h>
+#include <crypto/scatterwalk.h>
+
+#include <asm/arch/npe.h>
+#include <asm/arch/qmgr.h>
+
+#define MAX_KEYLEN 32
+
+/* hash: cfgword + 2 * digestlen; crypt: keylen + cfgword */
+#define NPE_CTX_LEN 80
+#define AES_BLOCK128 16
+
+#define NPE_OP_HASH_VERIFY   0x01
+#define NPE_OP_CCM_ENABLE    0x04
+#define NPE_OP_CRYPT_ENABLE  0x08
+#define NPE_OP_HASH_ENABLE   0x10
+#define NPE_OP_NOT_IN_PLACE  0x20
+#define NPE_OP_HMAC_DISABLE  0x40
+#define NPE_OP_CRYPT_ENCRYPT 0x80
+
+#define NPE_OP_CCM_GEN_MIC   0xcc
+#define NPE_OP_HASH_GEN_ICV  0x50
+#define NPE_OP_ENC_GEN_KEY   0xc9
+
+#define MOD_ECB     0x0000
+#define MOD_CTR     0x1000
+#define MOD_CBC_ENC 0x2000
+#define MOD_CBC_DEC 0x3000
+#define MOD_CCM_ENC 0x4000
+#define MOD_CCM_DEC 0x5000
+
+#define KEYLEN_128  4
+#define KEYLEN_192  6
+#define KEYLEN_256  8
+
+#define CIPH_DECR   0x0000
+#define CIPH_ENCR   0x0400
+
+#define MOD_DES     0x0000
+#define MOD_TDEA2   0x0100
+#define MOD_3DES   0x0200
+#define MOD_AES     0x0800
+#define MOD_AES128  (0x0800 | KEYLEN_128)
+#define MOD_AES192  (0x0900 | KEYLEN_192)
+#define MOD_AES256  (0x0a00 | KEYLEN_256)
+
+#define MAX_IVLEN   16
+#define NPE_ID      2  /* NPE C */
+#define NPE_QLEN    16
+/* Space for registering when the first
+ * NPE_QLEN crypt_ctl are busy */
+#define NPE_QLEN_TOTAL 64
+
+#define SEND_QID    29
+#define RECV_QID    30
+
+#define CTL_FLAG_UNUSED                0x0000
+#define CTL_FLAG_USED          0x1000
+#define CTL_FLAG_PERFORM_ABLK  0x0001
+#define CTL_FLAG_GEN_ICV       0x0002
+#define CTL_FLAG_GEN_REVAES    0x0004
+#define CTL_FLAG_PERFORM_AEAD  0x0008
+#define CTL_FLAG_MASK          0x000f
+
+#define HMAC_IPAD_VALUE   0x36
+#define HMAC_OPAD_VALUE   0x5C
+#define HMAC_PAD_BLOCKLEN SHA1_BLOCK_SIZE
+
+#define MD5_DIGEST_SIZE   16
+
+struct buffer_desc {
+       u32 phys_next;
+       u16 buf_len;
+       u16 pkt_len;
+       u32 phys_addr;
+       u32 __reserved[4];
+       struct buffer_desc *next;
+};
+
+struct crypt_ctl {
+       u8 mode;                /* NPE_OP_*  operation mode */
+       u8 init_len;
+       u16 reserved;
+       u8 iv[MAX_IVLEN];       /* IV for CBC mode or CTR IV for CTR mode */
+       u32 icv_rev_aes;        /* icv or rev aes */
+       u32 src_buf;
+       u32 dst_buf;
+       u16 auth_offs;          /* Authentication start offset */
+       u16 auth_len;           /* Authentication data length */
+       u16 crypt_offs;         /* Cryption start offset */
+       u16 crypt_len;          /* Cryption data length */
+       u32 aadAddr;            /* Additional Auth Data Addr for CCM mode */
+       u32 crypto_ctx;         /* NPE Crypto Param structure address */
+
+       /* Used by Host: 4*4 bytes*/
+       unsigned ctl_flags;
+       union {
+               struct ablkcipher_request *ablk_req;
+               struct aead_request *aead_req;
+               struct crypto_tfm *tfm;
+       } data;
+       struct buffer_desc *regist_buf;
+       u8 *regist_ptr;
+};
+
+struct ablk_ctx {
+       struct buffer_desc *src;
+       struct buffer_desc *dst;
+       unsigned src_nents;
+       unsigned dst_nents;
+};
+
+struct aead_ctx {
+       struct buffer_desc *buffer;
+       unsigned short assoc_nents;
+       unsigned short src_nents;
+       struct scatterlist ivlist;
+       /* used when the hmac is not on one sg entry */
+       u8 *hmac_virt;
+       int encrypt;
+};
+
+struct ix_hash_algo {
+       u32 cfgword;
+       unsigned char *icv;
+};
+
+struct ix_sa_dir {
+       unsigned char *npe_ctx;
+       dma_addr_t npe_ctx_phys;
+       int npe_ctx_idx;
+       u8 npe_mode;
+};
+
+struct ixp_ctx {
+       struct ix_sa_dir encrypt;
+       struct ix_sa_dir decrypt;
+       int authkey_len;
+       u8 authkey[MAX_KEYLEN];
+       int enckey_len;
+       u8 enckey[MAX_KEYLEN];
+       u8 salt[MAX_IVLEN];
+       u8 nonce[CTR_RFC3686_NONCE_SIZE];
+       unsigned salted;
+       atomic_t configuring;
+       struct completion completion;
+};
+
+struct ixp_alg {
+       struct crypto_alg crypto;
+       const struct ix_hash_algo *hash;
+       u32 cfg_enc;
+       u32 cfg_dec;
+
+       int registered;
+};
+
+static const struct ix_hash_algo hash_alg_md5 = {
+       .cfgword        = 0xAA010004,
+       .icv            = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
+                         "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
+};
+static const struct ix_hash_algo hash_alg_sha1 = {
+       .cfgword        = 0x00000005,
+       .icv            = "\x67\x45\x23\x01\xEF\xCD\xAB\x89\x98\xBA"
+                         "\xDC\xFE\x10\x32\x54\x76\xC3\xD2\xE1\xF0",
+};
+
+static struct npe *npe_c;
+static struct dma_pool *buffer_pool = NULL;
+static struct dma_pool *ctx_pool = NULL;
+
+static struct crypt_ctl *crypt_virt = NULL;
+static dma_addr_t crypt_phys;
+
+static int support_aes = 1;
+
+static void dev_release(struct device *dev)
+{
+       return;
+}
+
+#define DRIVER_NAME "ixp4xx_crypto"
+static struct platform_device pseudo_dev = {
+       .name = DRIVER_NAME,
+       .id   = 0,
+       .num_resources = 0,
+       .dev  = {
+               .coherent_dma_mask = DMA_32BIT_MASK,
+               .release = dev_release,
+       }
+};
+
+static struct device *dev = &pseudo_dev.dev;
+
+static inline dma_addr_t crypt_virt2phys(struct crypt_ctl *virt)
+{
+       return crypt_phys + (virt - crypt_virt) * sizeof(struct crypt_ctl);
+}
+
+static inline struct crypt_ctl *crypt_phys2virt(dma_addr_t phys)
+{
+       return crypt_virt + (phys - crypt_phys) / sizeof(struct crypt_ctl);
+}
+
+static inline u32 cipher_cfg_enc(struct crypto_tfm *tfm)
+{
+       return container_of(tfm->__crt_alg, struct ixp_alg,crypto)->cfg_enc;
+}
+
+static inline u32 cipher_cfg_dec(struct crypto_tfm *tfm)
+{
+       return container_of(tfm->__crt_alg, struct ixp_alg,crypto)->cfg_dec;
+}
+
+static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm)
+{
+       return container_of(tfm->__crt_alg, struct ixp_alg, crypto)->hash;
+}
+
+static int setup_crypt_desc(void)
+{
+       BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);
+       crypt_virt = dma_alloc_coherent(dev,
+                       NPE_QLEN * sizeof(struct crypt_ctl),
+                       &crypt_phys, GFP_KERNEL);
+       if (!crypt_virt)
+               return -ENOMEM;
+       memset(crypt_virt, 0, NPE_QLEN * sizeof(struct crypt_ctl));
+       return 0;
+}
+
+static spinlock_t desc_lock;
+static struct crypt_ctl *get_crypt_desc(void)
+{
+       int i;
+       static int idx = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&desc_lock, flags);
+
+       if (unlikely(!crypt_virt))
+               setup_crypt_desc();
+       if (unlikely(!crypt_virt)) {
+               spin_unlock_irqrestore(&desc_lock, flags);
+               return NULL;
+       }
+       i = idx;
+       if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) {
+               if (++idx >= NPE_QLEN)
+                       idx = 0;
+               crypt_virt[i].ctl_flags = CTL_FLAG_USED;
+               spin_unlock_irqrestore(&desc_lock, flags);
+               return crypt_virt +i;
+       } else {
+               spin_unlock_irqrestore(&desc_lock, flags);
+               return NULL;
+       }
+}
+
+static spinlock_t emerg_lock;
+static struct crypt_ctl *get_crypt_desc_emerg(void)
+{
+       int i;
+       static int idx = NPE_QLEN;
+       struct crypt_ctl *desc;
+       unsigned long flags;
+
+       desc = get_crypt_desc();
+       if (desc)
+               return desc;
+       if (unlikely(!crypt_virt))
+               return NULL;
+
+       spin_lock_irqsave(&emerg_lock, flags);
+       i = idx;
+       if (crypt_virt[i].ctl_flags == CTL_FLAG_UNUSED) {
+               if (++idx >= NPE_QLEN_TOTAL)
+                       idx = NPE_QLEN;
+               crypt_virt[i].ctl_flags = CTL_FLAG_USED;
+               spin_unlock_irqrestore(&emerg_lock, flags);
+               return crypt_virt +i;
+       } else {
+               spin_unlock_irqrestore(&emerg_lock, flags);
+               return NULL;
+       }
+}
+
+static void free_buf_chain(struct buffer_desc *buf, u32 phys)
+{
+       while (buf) {
+               struct buffer_desc *buf1;
+               u32 phys1;
+
+               buf1 = buf->next;
+               phys1 = buf->phys_next;
+               dma_pool_free(buffer_pool, buf, phys);
+               buf = buf1;
+               phys = phys1;
+       }
+}
+
+static struct tasklet_struct crypto_done_tasklet;
+
+static void finish_scattered_hmac(struct crypt_ctl *crypt)
+{
+       struct aead_request *req = crypt->data.aead_req;
+       struct aead_ctx *req_ctx = aead_request_ctx(req);
+       struct crypto_aead *tfm = crypto_aead_reqtfm(req);
+       int authsize = crypto_aead_authsize(tfm);
+       int decryptlen = req->cryptlen - authsize;
+
+       if (req_ctx->encrypt) {
+               scatterwalk_map_and_copy(req_ctx->hmac_virt,
+                       req->src, decryptlen, authsize, 1);
+       }
+       dma_pool_free(buffer_pool, req_ctx->hmac_virt, crypt->icv_rev_aes);
+}
+
+static void one_packet(dma_addr_t phys)
+{
+       struct crypt_ctl *crypt;
+       struct ixp_ctx *ctx;
+       int failed;
+       enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
+
+       failed = phys & 0x1 ? -EBADMSG : 0;
+       phys &= ~0x3;
+       crypt = crypt_phys2virt(phys);
+
+       switch (crypt->ctl_flags & CTL_FLAG_MASK) {
+       case CTL_FLAG_PERFORM_AEAD: {
+               struct aead_request *req = crypt->data.aead_req;
+               struct aead_ctx *req_ctx = aead_request_ctx(req);
+               dma_unmap_sg(dev, req->assoc, req_ctx->assoc_nents,
+                               DMA_TO_DEVICE);
+               dma_unmap_sg(dev, &req_ctx->ivlist, 1, DMA_BIDIRECTIONAL);
+               dma_unmap_sg(dev, req->src, req_ctx->src_nents,
+                               DMA_BIDIRECTIONAL);
+
+               free_buf_chain(req_ctx->buffer, crypt->src_buf);
+               if (req_ctx->hmac_virt) {
+                       finish_scattered_hmac(crypt);
+               }
+               req->base.complete(&req->base, failed);
+               break;
+       }
+       case CTL_FLAG_PERFORM_ABLK: {
+               struct ablkcipher_request *req = crypt->data.ablk_req;
+               struct ablk_ctx *req_ctx = ablkcipher_request_ctx(req);
+               int nents;
+               if (req_ctx->dst) {
+                       nents = req_ctx->dst_nents;
+                       dma_unmap_sg(dev, req->dst, nents, DMA_FROM_DEVICE);
+                       free_buf_chain(req_ctx->dst, crypt->dst_buf);
+                       src_direction = DMA_TO_DEVICE;
+               }
+               nents = req_ctx->src_nents;
+               dma_unmap_sg(dev, req->src, nents, src_direction);
+               free_buf_chain(req_ctx->src, crypt->src_buf);
+               req->base.complete(&req->base, failed);
+               break;
+       }
+       case CTL_FLAG_GEN_ICV:
+               ctx = crypto_tfm_ctx(crypt->data.tfm);
+               dma_pool_free(ctx_pool, crypt->regist_ptr,
+                               crypt->regist_buf->phys_addr);
+               dma_pool_free(buffer_pool, crypt->regist_buf, crypt->src_buf);
+               if (atomic_dec_and_test(&ctx->configuring))
+                       complete(&ctx->completion);
+               break;
+       case CTL_FLAG_GEN_REVAES:
+               ctx = crypto_tfm_ctx(crypt->data.tfm);
+               *(u32*)ctx->decrypt.npe_ctx &= cpu_to_be32(~CIPH_ENCR);
+               if (atomic_dec_and_test(&ctx->configuring))
+                       complete(&ctx->completion);
+               break;
+       default:
+               BUG();
+       }
+       crypt->ctl_flags = CTL_FLAG_UNUSED;
+}
+
+static void irqhandler(void *_unused)
+{
+       tasklet_schedule(&crypto_done_tasklet);
+}
+
+static void crypto_done_action(unsigned long arg)
+{
+       int i;
+
+       for(i=0; i<4; i++) {
+               dma_addr_t phys = qmgr_get_entry(RECV_QID);
+               if (!phys)
+                       return;
+               one_packet(phys);
+       }
+       tasklet_schedule(&crypto_done_tasklet);
+}
+
+static int init_ixp_crypto(void)
+{
+       int ret = -ENODEV;
+
+       if (! ( ~(*IXP4XX_EXP_CFG2) & (IXP4XX_FEATURE_HASH |
+                               IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) {
+               printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
+               return ret;
+       }
+       npe_c = npe_request(NPE_ID);
+       if (!npe_c)
+               return ret;
+
+       if (!npe_running(npe_c)) {
+               npe_load_firmware(npe_c, npe_name(npe_c), dev);
+       }
+
+       /* buffer_pool will also be used to sometimes store the hmac,
+        * so assure it is large enough
+        */
+       BUILD_BUG_ON(SHA1_DIGEST_SIZE > sizeof(struct buffer_desc));
+       buffer_pool = dma_pool_create("buffer", dev,
+                       sizeof(struct buffer_desc), 32, 0);
+       ret = -ENOMEM;
+       if (!buffer_pool) {
+               goto err;
+       }
+       ctx_pool = dma_pool_create("context", dev,
+                       NPE_CTX_LEN, 16, 0);
+       if (!ctx_pool) {
+               goto err;
+       }
+       ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0);
+       if (ret)
+               goto err;
+       ret = qmgr_request_queue(RECV_QID, NPE_QLEN, 0, 0);
+       if (ret) {
+               qmgr_release_queue(SEND_QID);
+               goto err;
+       }
+       qmgr_set_irq(RECV_QID, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
+       tasklet_init(&crypto_done_tasklet, crypto_done_action, 0);
+
+       qmgr_enable_irq(RECV_QID);
+       return 0;
+err:
+       if (ctx_pool)
+               dma_pool_destroy(ctx_pool);
+       if (buffer_pool)
+               dma_pool_destroy(buffer_pool);
+       npe_release(npe_c);
+       return ret;
+}
+
+static void release_ixp_crypto(void)
+{
+       qmgr_disable_irq(RECV_QID);
+       tasklet_kill(&crypto_done_tasklet);
+
+       qmgr_release_queue(SEND_QID);
+       qmgr_release_queue(RECV_QID);
+
+       dma_pool_destroy(ctx_pool);
+       dma_pool_destroy(buffer_pool);
+
+       npe_release(npe_c);
+
+       if (crypt_virt) {
+               dma_free_coherent(dev,
+                       NPE_QLEN_TOTAL * sizeof( struct crypt_ctl),
+                       crypt_virt, crypt_phys);
+       }
+       return;
+}
+
+static void reset_sa_dir(struct ix_sa_dir *dir)
+{
+       memset(dir->npe_ctx, 0, NPE_CTX_LEN);
+       dir->npe_ctx_idx = 0;
+       dir->npe_mode = 0;
+}
+
+static int init_sa_dir(struct ix_sa_dir *dir)
+{
+       dir->npe_ctx = dma_pool_alloc(ctx_pool, GFP_KERNEL, &dir->npe_ctx_phys);
+       if (!dir->npe_ctx) {
+               return -ENOMEM;
+       }
+       reset_sa_dir(dir);
+       return 0;
+}
+
+static void free_sa_dir(struct ix_sa_dir *dir)
+{
+       memset(dir->npe_ctx, 0, NPE_CTX_LEN);
+       dma_pool_free(ctx_pool, dir->npe_ctx, dir->npe_ctx_phys);
+}
+
+static int init_tfm(struct crypto_tfm *tfm)
+{
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       int ret;
+
+       atomic_set(&ctx->configuring, 0);
+       ret = init_sa_dir(&ctx->encrypt);
+       if (ret)
+               return ret;
+       ret = init_sa_dir(&ctx->decrypt);
+       if (ret) {
+               free_sa_dir(&ctx->encrypt);
+       }
+       return ret;
+}
+
+static int init_tfm_ablk(struct crypto_tfm *tfm)
+{
+       tfm->crt_ablkcipher.reqsize = sizeof(struct ablk_ctx);
+       return init_tfm(tfm);
+}
+
+static int init_tfm_aead(struct crypto_tfm *tfm)
+{
+       tfm->crt_aead.reqsize = sizeof(struct aead_ctx);
+       return init_tfm(tfm);
+}
+
+static void exit_tfm(struct crypto_tfm *tfm)
+{
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       free_sa_dir(&ctx->encrypt);
+       free_sa_dir(&ctx->decrypt);
+}
+
+static int register_chain_var(struct crypto_tfm *tfm, u8 xpad, u32 target,
+               int init_len, u32 ctx_addr, const u8 *key, int key_len)
+{
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct crypt_ctl *crypt;
+       struct buffer_desc *buf;
+       int i;
+       u8 *pad;
+       u32 pad_phys, buf_phys;
+
+       BUILD_BUG_ON(NPE_CTX_LEN < HMAC_PAD_BLOCKLEN);
+       pad = dma_pool_alloc(ctx_pool, GFP_KERNEL, &pad_phys);
+       if (!pad)
+               return -ENOMEM;
+       buf = dma_pool_alloc(buffer_pool, GFP_KERNEL, &buf_phys);
+       if (!buf) {
+               dma_pool_free(ctx_pool, pad, pad_phys);
+               return -ENOMEM;
+       }
+       crypt = get_crypt_desc_emerg();
+       if (!crypt) {
+               dma_pool_free(ctx_pool, pad, pad_phys);
+               dma_pool_free(buffer_pool, buf, buf_phys);
+               return -EAGAIN;
+       }
+
+       memcpy(pad, key, key_len);
+       memset(pad + key_len, 0, HMAC_PAD_BLOCKLEN - key_len);
+       for (i = 0; i < HMAC_PAD_BLOCKLEN; i++) {
+               pad[i] ^= xpad;
+       }
+
+       crypt->data.tfm = tfm;
+       crypt->regist_ptr = pad;
+       crypt->regist_buf = buf;
+
+       crypt->auth_offs = 0;
+       crypt->auth_len = HMAC_PAD_BLOCKLEN;
+       crypt->crypto_ctx = ctx_addr;
+       crypt->src_buf = buf_phys;
+       crypt->icv_rev_aes = target;
+       crypt->mode = NPE_OP_HASH_GEN_ICV;
+       crypt->init_len = init_len;
+       crypt->ctl_flags |= CTL_FLAG_GEN_ICV;
+
+       buf->next = 0;
+       buf->buf_len = HMAC_PAD_BLOCKLEN;
+       buf->pkt_len = 0;
+       buf->phys_addr = pad_phys;
+
+       atomic_inc(&ctx->configuring);
+       qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
+       BUG_ON(qmgr_stat_overflow(SEND_QID));
+       return 0;
+}
+
+static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned authsize,
+               const u8 *key, int key_len, unsigned digest_len)
+{
+       u32 itarget, otarget, npe_ctx_addr;
+       unsigned char *cinfo;
+       int init_len, ret = 0;
+       u32 cfgword;
+       struct ix_sa_dir *dir;
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       const struct ix_hash_algo *algo;
+
+       dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
+       cinfo = dir->npe_ctx + dir->npe_ctx_idx;
+       algo = ix_hash(tfm);
+
+       /* write cfg word to cryptinfo */
+       cfgword = algo->cfgword | ( authsize << 6); /* (authsize/4) << 8 */
+       *(u32*)cinfo = cpu_to_be32(cfgword);
+       cinfo += sizeof(cfgword);
+
+       /* write ICV to cryptinfo */
+       memcpy(cinfo, algo->icv, digest_len);
+       cinfo += digest_len;
+
+       itarget = dir->npe_ctx_phys + dir->npe_ctx_idx
+                               + sizeof(algo->cfgword);
+       otarget = itarget + digest_len;
+       init_len = cinfo - (dir->npe_ctx + dir->npe_ctx_idx);
+       npe_ctx_addr = dir->npe_ctx_phys + dir->npe_ctx_idx;
+
+       dir->npe_ctx_idx += init_len;
+       dir->npe_mode |= NPE_OP_HASH_ENABLE;
+
+       if (!encrypt)
+               dir->npe_mode |= NPE_OP_HASH_VERIFY;
+
+       ret = register_chain_var(tfm, HMAC_OPAD_VALUE, otarget,
+                       init_len, npe_ctx_addr, key, key_len);
+       if (ret)
+               return ret;
+       return register_chain_var(tfm, HMAC_IPAD_VALUE, itarget,
+                       init_len, npe_ctx_addr, key, key_len);
+}
+
+static int gen_rev_aes_key(struct crypto_tfm *tfm)
+{
+       struct crypt_ctl *crypt;
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       struct ix_sa_dir *dir = &ctx->decrypt;
+
+       crypt = get_crypt_desc_emerg();
+       if (!crypt) {
+               return -EAGAIN;
+       }
+       *(u32*)dir->npe_ctx |= cpu_to_be32(CIPH_ENCR);
+
+       crypt->data.tfm = tfm;
+       crypt->crypt_offs = 0;
+       crypt->crypt_len = AES_BLOCK128;
+       crypt->src_buf = 0;
+       crypt->crypto_ctx = dir->npe_ctx_phys;
+       crypt->icv_rev_aes = dir->npe_ctx_phys + sizeof(u32);
+       crypt->mode = NPE_OP_ENC_GEN_KEY;
+       crypt->init_len = dir->npe_ctx_idx;
+       crypt->ctl_flags |= CTL_FLAG_GEN_REVAES;
+
+       atomic_inc(&ctx->configuring);
+       qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
+       BUG_ON(qmgr_stat_overflow(SEND_QID));
+       return 0;
+}
+
+static int setup_cipher(struct crypto_tfm *tfm, int encrypt,
+               const u8 *key, int key_len)
+{
+       u8 *cinfo;
+       u32 cipher_cfg;
+       u32 keylen_cfg = 0;
+       struct ix_sa_dir *dir;
+       struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
+
+       dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
+       cinfo = dir->npe_ctx;
+
+       if (encrypt) {
+               cipher_cfg = cipher_cfg_enc(tfm);
+               dir->npe_mode |= NPE_OP_CRYPT_ENCRYPT;
+       } else {
+               cipher_cfg = cipher_cfg_dec(tfm);
+       }
+       if (cipher_cfg & MOD_AES) {
+               switch (key_len) {
+                       case 16: keylen_cfg = MOD_AES128 | KEYLEN_128; break;
+                       case 24: keylen_cfg = MOD_AES192 | KEYLEN_192; break;
+                       case 32: keylen_cfg = MOD_AES256 | KEYLEN_256; break;
+                       default:
+                               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
+                               return -EINVAL;
+               }
+               cipher_cfg |= keylen_cfg;
+       } else if (cipher_cfg & MOD_3DES) {
+               const u32 *K = (const u32 *)key;
+               if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
+                            !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
+               {
+                       *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
+                       return -EINVAL;
+               }
+       } else {
+               u32 tmp[DES_EXPKEY_WORDS];
+               if (des_ekey(tmp, key) == 0) {
+                       *flags |= CRYPTO_TFM_RES_WEAK_KEY;
+               }
+       }
+       /* write cfg word to cryptinfo */
+       *(u32*)cinfo = cpu_to_be32(cipher_cfg);
+       cinfo += sizeof(cipher_cfg);
+
+       /* write cipher key to cryptinfo */
+       memcpy(cinfo, key, key_len);
+       /* NPE wants keylen set to DES3_EDE_KEY_SIZE even for single DES */
+       if (key_len < DES3_EDE_KEY_SIZE && !(cipher_cfg & MOD_AES)) {
+               memset(cinfo + key_len, 0, DES3_EDE_KEY_SIZE -key_len);
+               key_len = DES3_EDE_KEY_SIZE;
+       }
+       dir->npe_ctx_idx = sizeof(cipher_cfg) + key_len;
+       dir->npe_mode |= NPE_OP_CRYPT_ENABLE;
+       if ((cipher_cfg & MOD_AES) && !encrypt) {
+               return gen_rev_aes_key(tfm);
+       }
+       return 0;
+}
+
+static int count_sg(struct scatterlist *sg, int nbytes)
+{
+       int i;
+       for (i = 0; nbytes > 0; i++, sg = sg_next(sg))
+               nbytes -= sg->length;
+       return i;
+}
+
+static struct buffer_desc *chainup_buffers(struct scatterlist *sg,
+                       unsigned nbytes, struct buffer_desc *buf, gfp_t flags)
+{
+       int nents = 0;
+
+       while (nbytes > 0) {
+               struct buffer_desc *next_buf;
+               u32 next_buf_phys;
+               unsigned len = min(nbytes, sg_dma_len(sg));
+
+               nents++;
+               nbytes -= len;
+               if (!buf->phys_addr) {
+                       buf->phys_addr = sg_dma_address(sg);
+                       buf->buf_len = len;
+                       buf->next = NULL;
+                       buf->phys_next = 0;
+                       goto next;
+               }
+               /* Two consecutive chunks on one page may be handled by the old
+                * buffer descriptor, increased by the length of the new one
+                */
+               if (sg_dma_address(sg) == buf->phys_addr + buf->buf_len) {
+                       buf->buf_len += len;
+                       goto next;
+               }
+               next_buf = dma_pool_alloc(buffer_pool, flags, &next_buf_phys);
+               if (!next_buf)
+                       return NULL;
+               buf->next = next_buf;
+               buf->phys_next = next_buf_phys;
+
+               buf = next_buf;
+               buf->next = NULL;
+               buf->phys_next = 0;
+               buf->phys_addr = sg_dma_address(sg);
+               buf->buf_len = len;
+next:
+               if (nbytes > 0) {
+                       sg = sg_next(sg);
+               }
+       }
+       return buf;
+}
+
+static int ablk_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
+                       unsigned int key_len)
+{
+       struct ixp_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+       u32 *flags = &tfm->base.crt_flags;
+       int ret;
+
+       init_completion(&ctx->completion);
+       atomic_inc(&ctx->configuring);
+
+       reset_sa_dir(&ctx->encrypt);
+       reset_sa_dir(&ctx->decrypt);
+
+       ctx->encrypt.npe_mode = NPE_OP_HMAC_DISABLE;
+       ctx->decrypt.npe_mode = NPE_OP_HMAC_DISABLE;
+
+       ret = setup_cipher(&tfm->base, 0, key, key_len);
+       if (ret)
+               goto out;
+       ret = setup_cipher(&tfm->base, 1, key, key_len);
+       if (ret)
+               goto out;
+
+       if (*flags & CRYPTO_TFM_RES_WEAK_KEY) {
+               if (*flags & CRYPTO_TFM_REQ_WEAK_KEY) {
+                       ret = -EINVAL;
+               } else {
+                       *flags &= ~CRYPTO_TFM_RES_WEAK_KEY;
+               }
+       }
+out:
+       if (!atomic_dec_and_test(&ctx->configuring))
+               wait_for_completion(&ctx->completion);
+       return ret;
+}
+
+static int ablk_rfc3686_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
+               unsigned int key_len)
+{
+       struct ixp_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+
+       /* the nonce is stored in bytes at end of key */
+       if (key_len < CTR_RFC3686_NONCE_SIZE)
+               return -EINVAL;
+
+       memcpy(ctx->nonce, key + (key_len - CTR_RFC3686_NONCE_SIZE),
+                       CTR_RFC3686_NONCE_SIZE);
+
+       key_len -= CTR_RFC3686_NONCE_SIZE;
+       return ablk_setkey(tfm, key, key_len);
+}
+
+static int ablk_perform(struct ablkcipher_request *req, int encrypt)
+{
+       struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+       struct ixp_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+       unsigned ivsize = crypto_ablkcipher_ivsize(tfm);
+       int ret = -ENOMEM;
+       struct ix_sa_dir *dir;
+       struct crypt_ctl *crypt;
+       unsigned int nbytes = req->nbytes, nents;
+       enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;
+       struct ablk_ctx *req_ctx = ablkcipher_request_ctx(req);
+       gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
+                               GFP_KERNEL : GFP_ATOMIC;
+
+       if (qmgr_stat_full(SEND_QID))
+               return -EAGAIN;
+       if (atomic_read(&ctx->configuring))
+               return -EAGAIN;
+
+       dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
+
+       crypt = get_crypt_desc();
+       if (!crypt)
+               return ret;
+
+       crypt->data.ablk_req = req;
+       crypt->crypto_ctx = dir->npe_ctx_phys;
+       crypt->mode = dir->npe_mode;
+       crypt->init_len = dir->npe_ctx_idx;
+
+       crypt->crypt_offs = 0;
+       crypt->crypt_len = nbytes;
+
+       BUG_ON(ivsize && !req->info);
+       memcpy(crypt->iv, req->info, ivsize);
+       if (req->src != req->dst) {
+               crypt->mode |= NPE_OP_NOT_IN_PLACE;
+               nents = count_sg(req->dst, nbytes);
+               /* This was never tested by Intel
+                * for more than one dst buffer, I think. */
+               BUG_ON(nents != 1);
+               req_ctx->dst_nents = nents;
+               dma_map_sg(dev, req->dst, nents, DMA_FROM_DEVICE);
+               req_ctx->dst = dma_pool_alloc(buffer_pool, flags,&crypt->dst_buf);
+               if (!req_ctx->dst)
+                       goto unmap_sg_dest;
+               req_ctx->dst->phys_addr = 0;
+               if (!chainup_buffers(req->dst, nbytes, req_ctx->dst, flags))
+                       goto free_buf_dest;
+               src_direction = DMA_TO_DEVICE;
+       } else {
+               req_ctx->dst = NULL;
+               req_ctx->dst_nents = 0;
+       }
+       nents = count_sg(req->src, nbytes);
+       req_ctx->src_nents = nents;
+       dma_map_sg(dev, req->src, nents, src_direction);
+
+       req_ctx->src = dma_pool_alloc(buffer_pool, flags, &crypt->src_buf);
+       if (!req_ctx->src)
+               goto unmap_sg_src;
+       req_ctx->src->phys_addr = 0;
+       if (!chainup_buffers(req->src, nbytes, req_ctx->src, flags))
+               goto free_buf_src;
+
+       crypt->ctl_flags |= CTL_FLAG_PERFORM_ABLK;
+       qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
+       BUG_ON(qmgr_stat_overflow(SEND_QID));
+       return -EINPROGRESS;
+
+free_buf_src:
+       free_buf_chain(req_ctx->src, crypt->src_buf);
+unmap_sg_src:
+       dma_unmap_sg(dev, req->src, req_ctx->src_nents, src_direction);
+free_buf_dest:
+       if (req->src != req->dst) {
+               free_buf_chain(req_ctx->dst, crypt->dst_buf);
+unmap_sg_dest:
+               dma_unmap_sg(dev, req->src, req_ctx->dst_nents,
+                       DMA_FROM_DEVICE);
+       }
+       crypt->ctl_flags = CTL_FLAG_UNUSED;
+       return ret;
+}
+
+static int ablk_encrypt(struct ablkcipher_request *req)
+{
+       return ablk_perform(req, 1);
+}
+
+static int ablk_decrypt(struct ablkcipher_request *req)
+{
+       return ablk_perform(req, 0);
+}
+
+static int ablk_rfc3686_crypt(struct ablkcipher_request *req)
+{
+       struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
+       struct ixp_ctx *ctx = crypto_ablkcipher_ctx(tfm);
+       u8 iv[CTR_RFC3686_BLOCK_SIZE];
+       u8 *info = req->info;
+       int ret;
+
+       /* set up counter block */
+        memcpy(iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE);
+       memcpy(iv + CTR_RFC3686_NONCE_SIZE, info, CTR_RFC3686_IV_SIZE);
+
+       /* initialize counter portion of counter block */
+       *(__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE) =
+               cpu_to_be32(1);
+
+       req->info = iv;
+       ret = ablk_perform(req, 1);
+       req->info = info;
+       return ret;
+}
+
+static int hmac_inconsistent(struct scatterlist *sg, unsigned start,
+               unsigned int nbytes)
+{
+       int offset = 0;
+
+       if (!nbytes)
+               return 0;
+
+       for (;;) {
+               if (start < offset + sg->length)
+                       break;
+
+               offset += sg->length;
+               sg = sg_next(sg);
+       }
+       return (start + nbytes > offset + sg->length);
+}
+
+static int aead_perform(struct aead_request *req, int encrypt,
+               int cryptoffset, int eff_cryptlen, u8 *iv)
+{
+       struct crypto_aead *tfm = crypto_aead_reqtfm(req);
+       struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
+       unsigned ivsize = crypto_aead_ivsize(tfm);
+       unsigned authsize = crypto_aead_authsize(tfm);
+       int ret = -ENOMEM;
+       struct ix_sa_dir *dir;
+       struct crypt_ctl *crypt;
+       unsigned int cryptlen, nents;
+       struct buffer_desc *buf;
+       struct aead_ctx *req_ctx = aead_request_ctx(req);
+       gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
+                               GFP_KERNEL : GFP_ATOMIC;
+
+       if (qmgr_stat_full(SEND_QID))
+               return -EAGAIN;
+       if (atomic_read(&ctx->configuring))
+               return -EAGAIN;
+
+       if (encrypt) {
+               dir = &ctx->encrypt;
+               cryptlen = req->cryptlen;
+       } else {
+               dir = &ctx->decrypt;
+               /* req->cryptlen includes the authsize when decrypting */
+               cryptlen = req->cryptlen -authsize;
+               eff_cryptlen -= authsize;
+       }
+       crypt = get_crypt_desc();
+       if (!crypt)
+               return ret;
+
+       crypt->data.aead_req = req;
+       crypt->crypto_ctx = dir->npe_ctx_phys;
+       crypt->mode = dir->npe_mode;
+       crypt->init_len = dir->npe_ctx_idx;
+
+       crypt->crypt_offs = cryptoffset;
+       crypt->crypt_len = eff_cryptlen;
+
+       crypt->auth_offs = 0;
+       crypt->auth_len = req->assoclen + ivsize + cryptlen;
+       BUG_ON(ivsize && !req->iv);
+       memcpy(crypt->iv, req->iv, ivsize);
+
+       if (req->src != req->dst) {
+               BUG(); /* -ENOTSUP because of my lazyness */
+       }
+
+       req_ctx->buffer = dma_pool_alloc(buffer_pool, flags, &crypt->src_buf);
+       if (!req_ctx->buffer)
+               goto out;
+       req_ctx->buffer->phys_addr = 0;
+       /* ASSOC data */
+       nents = count_sg(req->assoc, req->assoclen);
+       req_ctx->assoc_nents = nents;
+       dma_map_sg(dev, req->assoc, nents, DMA_TO_DEVICE);
+       buf = chainup_buffers(req->assoc, req->assoclen, req_ctx->buffer,flags);
+       if (!buf)
+               goto unmap_sg_assoc;
+       /* IV */
+       sg_init_table(&req_ctx->ivlist, 1);
+       sg_set_buf(&req_ctx->ivlist, iv, ivsize);
+       dma_map_sg(dev, &req_ctx->ivlist, 1, DMA_BIDIRECTIONAL);
+       buf = chainup_buffers(&req_ctx->ivlist, ivsize, buf, flags);
+       if (!buf)
+               goto unmap_sg_iv;
+       if (unlikely(hmac_inconsistent(req->src, cryptlen, authsize))) {
+               /* The 12 hmac bytes are scattered,
+                * we need to copy them into a safe buffer */
+               req_ctx->hmac_virt = dma_pool_alloc(buffer_pool, flags,
+                               &crypt->icv_rev_aes);
+               if (unlikely(!req_ctx->hmac_virt))
+                       goto unmap_sg_iv;
+               if (!encrypt) {
+                       scatterwalk_map_and_copy(req_ctx->hmac_virt,
+                               req->src, cryptlen, authsize, 0);
+               }
+               req_ctx->encrypt = encrypt;
+       } else {
+               req_ctx->hmac_virt = NULL;
+       }
+       /* Crypt */
+       nents = count_sg(req->src, cryptlen + authsize);
+       req_ctx->src_nents = nents;
+       dma_map_sg(dev, req->src, nents, DMA_BIDIRECTIONAL);
+       buf = chainup_buffers(req->src, cryptlen + authsize, buf, flags);
+       if (!buf)
+               goto unmap_sg_src;
+       if (!req_ctx->hmac_virt) {
+               crypt->icv_rev_aes = buf->phys_addr + buf->buf_len - authsize;
+       }
+       crypt->ctl_flags |= CTL_FLAG_PERFORM_AEAD;
+       qmgr_put_entry(SEND_QID, crypt_virt2phys(crypt));
+       BUG_ON(qmgr_stat_overflow(SEND_QID));
+       return -EINPROGRESS;
+unmap_sg_src:
+       dma_unmap_sg(dev, req->src, req_ctx->src_nents, DMA_BIDIRECTIONAL);
+       if (req_ctx->hmac_virt) {
+               dma_pool_free(buffer_pool, req_ctx->hmac_virt,
+                               crypt->icv_rev_aes);
+       }
+unmap_sg_iv:
+       dma_unmap_sg(dev, &req_ctx->ivlist, 1, DMA_BIDIRECTIONAL);
+unmap_sg_assoc:
+       dma_unmap_sg(dev, req->assoc, req_ctx->assoc_nents, DMA_TO_DEVICE);
+       free_buf_chain(req_ctx->buffer, crypt->src_buf);
+out:
+       crypt->ctl_flags = CTL_FLAG_UNUSED;
+       return ret;
+}
+
+static int aead_setup(struct crypto_aead *tfm, unsigned int authsize)
+{
+       struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
+       u32 *flags = &tfm->base.crt_flags;
+       unsigned digest_len = crypto_aead_alg(tfm)->maxauthsize;
+       int ret;
+
+       if (!ctx->enckey_len && !ctx->authkey_len)
+               return 0;
+       init_completion(&ctx->completion);
+       atomic_inc(&ctx->configuring);
+
+       reset_sa_dir(&ctx->encrypt);
+       reset_sa_dir(&ctx->decrypt);
+
+       ret = setup_cipher(&tfm->base, 0, ctx->enckey, ctx->enckey_len);
+       if (ret)
+               goto out;
+       ret = setup_cipher(&tfm->base, 1, ctx->enckey, ctx->enckey_len);
+       if (ret)
+               goto out;
+       ret = setup_auth(&tfm->base, 0, authsize, ctx->authkey,
+                       ctx->authkey_len, digest_len);
+       if (ret)
+               goto out;
+       ret = setup_auth(&tfm->base, 1, authsize,  ctx->authkey,
+                       ctx->authkey_len, digest_len);
+       if (ret)
+               goto out;
+
+       if (*flags & CRYPTO_TFM_RES_WEAK_KEY) {
+               if (*flags & CRYPTO_TFM_REQ_WEAK_KEY) {
+                       ret = -EINVAL;
+                       goto out;
+               } else {
+                       *flags &= ~CRYPTO_TFM_RES_WEAK_KEY;
+               }
+       }
+out:
+       if (!atomic_dec_and_test(&ctx->configuring))
+               wait_for_completion(&ctx->completion);
+       return ret;
+}
+
+static int aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
+{
+       int max = crypto_aead_alg(tfm)->maxauthsize >> 2;
+
+       if ((authsize>>2) < 1 || (authsize>>2) > max || (authsize & 3))
+               return -EINVAL;
+       return aead_setup(tfm, authsize);
+}
+
+static int aead_setkey(struct crypto_aead *tfm, const u8 *key,
+                       unsigned int keylen)
+{
+       struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
+       struct rtattr *rta = (struct rtattr *)key;
+       struct crypto_authenc_key_param *param;
+
+       if (!RTA_OK(rta, keylen))
+               goto badkey;
+       if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
+               goto badkey;
+       if (RTA_PAYLOAD(rta) < sizeof(*param))
+               goto badkey;
+
+       param = RTA_DATA(rta);
+       ctx->enckey_len = be32_to_cpu(param->enckeylen);
+
+       key += RTA_ALIGN(rta->rta_len);
+       keylen -= RTA_ALIGN(rta->rta_len);
+
+       if (keylen < ctx->enckey_len)
+               goto badkey;
+
+       ctx->authkey_len = keylen - ctx->enckey_len;
+       memcpy(ctx->enckey, key + ctx->authkey_len, ctx->enckey_len);
+       memcpy(ctx->authkey, key, ctx->authkey_len);
+
+       return aead_setup(tfm, crypto_aead_authsize(tfm));
+badkey:
+       ctx->enckey_len = 0;
+       crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
+       return -EINVAL;
+}
+
+static int aead_encrypt(struct aead_request *req)
+{
+       unsigned ivsize = crypto_aead_ivsize(crypto_aead_reqtfm(req));
+       return aead_perform(req, 1, req->assoclen + ivsize,
+                       req->cryptlen, req->iv);
+}
+
+static int aead_decrypt(struct aead_request *req)
+{
+       unsigned ivsize = crypto_aead_ivsize(crypto_aead_reqtfm(req));
+       return aead_perform(req, 0, req->assoclen + ivsize,
+                       req->cryptlen, req->iv);
+}
+
+static int aead_givencrypt(struct aead_givcrypt_request *req)
+{
+       struct crypto_aead *tfm = aead_givcrypt_reqtfm(req);
+       struct ixp_ctx *ctx = crypto_aead_ctx(tfm);
+       unsigned len, ivsize = crypto_aead_ivsize(tfm);
+       __be64 seq;
+
+       /* copied from eseqiv.c */
+       if (!ctx->salted) {
+               get_random_bytes(ctx->salt, ivsize);
+               ctx->salted = 1;
+       }
+       memcpy(req->areq.iv, ctx->salt, ivsize);
+       len = ivsize;
+       if (ivsize > sizeof(u64)) {
+               memset(req->giv, 0, ivsize - sizeof(u64));
+               len = sizeof(u64);
+       }
+       seq = cpu_to_be64(req->seq);
+       memcpy(req->giv + ivsize - len, &seq, len);
+       return aead_perform(&req->areq, 1, req->areq.assoclen,
+                       req->areq.cryptlen +ivsize, req->giv);
+}
+
+static struct ixp_alg ixp4xx_algos[] = {
+{
+       .crypto = {
+               .cra_name       = "cbc(des)",
+               .cra_blocksize  = DES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = DES_KEY_SIZE,
+                       .max_keysize    = DES_KEY_SIZE,
+                       .ivsize         = DES_BLOCK_SIZE,
+                       .geniv          = "eseqiv",
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
+
+}, {
+       .crypto = {
+               .cra_name       = "ecb(des)",
+               .cra_blocksize  = DES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = DES_KEY_SIZE,
+                       .max_keysize    = DES_KEY_SIZE,
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_DES | MOD_ECB | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_DES | MOD_ECB | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "cbc(des3_ede)",
+               .cra_blocksize  = DES3_EDE_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = DES3_EDE_KEY_SIZE,
+                       .max_keysize    = DES3_EDE_KEY_SIZE,
+                       .ivsize         = DES3_EDE_BLOCK_SIZE,
+                       .geniv          = "eseqiv",
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "ecb(des3_ede)",
+               .cra_blocksize  = DES3_EDE_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = DES3_EDE_KEY_SIZE,
+                       .max_keysize    = DES3_EDE_KEY_SIZE,
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_ECB | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_3DES | MOD_ECB | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "cbc(aes)",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .geniv          = "eseqiv",
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
+       .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
+}, {
+       .crypto = {
+               .cra_name       = "ecb(aes)",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_ECB,
+       .cfg_dec = CIPH_DECR | MOD_AES | MOD_ECB,
+}, {
+       .crypto = {
+               .cra_name       = "ctr(aes)",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .geniv          = "eseqiv",
+                       }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR,
+       .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR,
+}, {
+       .crypto = {
+               .cra_name       = "rfc3686(ctr(aes))",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .ablkcipher = {
+                       .min_keysize    = AES_MIN_KEY_SIZE,
+                       .max_keysize    = AES_MAX_KEY_SIZE,
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .geniv          = "eseqiv",
+                       .setkey         = ablk_rfc3686_setkey,
+                       .encrypt        = ablk_rfc3686_crypt,
+                       .decrypt        = ablk_rfc3686_crypt }
+               }
+       },
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CTR,
+       .cfg_dec = CIPH_ENCR | MOD_AES | MOD_CTR,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(md5),cbc(des))",
+               .cra_blocksize  = DES_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = DES_BLOCK_SIZE,
+                       .maxauthsize    = MD5_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_md5,
+       .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(md5),cbc(des3_ede))",
+               .cra_blocksize  = DES3_EDE_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = DES3_EDE_BLOCK_SIZE,
+                       .maxauthsize    = MD5_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_md5,
+       .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(sha1),cbc(des))",
+               .cra_blocksize  = DES_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = DES_BLOCK_SIZE,
+                       .maxauthsize    = SHA1_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_sha1,
+       .cfg_enc = CIPH_ENCR | MOD_DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_DES | MOD_CBC_DEC | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(sha1),cbc(des3_ede))",
+               .cra_blocksize  = DES3_EDE_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = DES3_EDE_BLOCK_SIZE,
+                       .maxauthsize    = SHA1_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_sha1,
+       .cfg_enc = CIPH_ENCR | MOD_3DES | MOD_CBC_ENC | KEYLEN_192,
+       .cfg_dec = CIPH_DECR | MOD_3DES | MOD_CBC_DEC | KEYLEN_192,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(md5),cbc(aes))",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .maxauthsize    = MD5_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_md5,
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
+       .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
+}, {
+       .crypto = {
+               .cra_name       = "authenc(hmac(sha1),cbc(aes))",
+               .cra_blocksize  = AES_BLOCK_SIZE,
+               .cra_u          = { .aead = {
+                       .ivsize         = AES_BLOCK_SIZE,
+                       .maxauthsize    = SHA1_DIGEST_SIZE,
+                       }
+               }
+       },
+       .hash = &hash_alg_sha1,
+       .cfg_enc = CIPH_ENCR | MOD_AES | MOD_CBC_ENC,
+       .cfg_dec = CIPH_DECR | MOD_AES | MOD_CBC_DEC,
+} };
+
+#define IXP_POSTFIX "-ixp4xx"
+static int __init ixp_module_init(void)
+{
+       int num = ARRAY_SIZE(ixp4xx_algos);
+       int i,err ;
+
+       if (platform_device_register(&pseudo_dev))
+               return -ENODEV;
+
+       spin_lock_init(&desc_lock);
+       spin_lock_init(&emerg_lock);
+
+       err = init_ixp_crypto();
+       if (err) {
+               platform_device_unregister(&pseudo_dev);
+               return err;
+       }
+       for (i=0; i< num; i++) {
+               struct crypto_alg *cra = &ixp4xx_algos[i].crypto;
+
+               if (snprintf(cra->cra_driver_name, CRYPTO_MAX_ALG_NAME,
+                       "%s"IXP_POSTFIX, cra->cra_name) >=
+                       CRYPTO_MAX_ALG_NAME)
+               {
+                       continue;
+               }
+               if (!support_aes && (ixp4xx_algos[i].cfg_enc & MOD_AES)) {
+                       continue;
+               }
+               if (!ixp4xx_algos[i].hash) {
+                       /* block ciphers */
+                       cra->cra_type = &crypto_ablkcipher_type;
+                       cra->cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
+                                        CRYPTO_ALG_ASYNC;
+                       if (!cra->cra_ablkcipher.setkey)
+                               cra->cra_ablkcipher.setkey = ablk_setkey;
+                       if (!cra->cra_ablkcipher.encrypt)
+                               cra->cra_ablkcipher.encrypt = ablk_encrypt;
+                       if (!cra->cra_ablkcipher.decrypt)
+                               cra->cra_ablkcipher.decrypt = ablk_decrypt;
+                       cra->cra_init = init_tfm_ablk;
+               } else {
+                       /* authenc */
+                       cra->cra_type = &crypto_aead_type;
+                       cra->cra_flags = CRYPTO_ALG_TYPE_AEAD |
+                                        CRYPTO_ALG_ASYNC;
+                       cra->cra_aead.setkey = aead_setkey;
+                       cra->cra_aead.setauthsize = aead_setauthsize;
+                       cra->cra_aead.encrypt = aead_encrypt;
+                       cra->cra_aead.decrypt = aead_decrypt;
+                       cra->cra_aead.givencrypt = aead_givencrypt;
+                       cra->cra_init = init_tfm_aead;
+               }
+               cra->cra_ctxsize = sizeof(struct ixp_ctx);
+               cra->cra_module = THIS_MODULE;
+               cra->cra_alignmask = 3;
+               cra->cra_priority = 300;
+               cra->cra_exit = exit_tfm;
+               if (crypto_register_alg(cra))
+                       printk(KERN_ERR "Failed to register '%s'\n",
+                               cra->cra_name);
+               else
+                       ixp4xx_algos[i].registered = 1;
+       }
+       return 0;
+}
+
+static void __exit ixp_module_exit(void)
+{
+       int num = ARRAY_SIZE(ixp4xx_algos);
+       int i;
+
+       for (i=0; i< num; i++) {
+               if (ixp4xx_algos[i].registered)
+                       crypto_unregister_alg(&ixp4xx_algos[i].crypto);
+       }
+       release_ixp_crypto();
+       platform_device_unregister(&pseudo_dev);
+}
+
+module_init(ixp_module_init);
+module_exit(ixp_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Christian Hohnstaedt <chohnstaedt@innominate.com>");
+MODULE_DESCRIPTION("IXP4xx hardware crypto");
+
index bb30eb9..54a2a16 100644 (file)
@@ -385,12 +385,12 @@ static int __init padlock_init(void)
        int ret;
 
        if (!cpu_has_xcrypt) {
-               printk(KERN_ERR PFX "VIA PadLock not detected.\n");
+               printk(KERN_NOTICE PFX "VIA PadLock not detected.\n");
                return -ENODEV;
        }
 
        if (!cpu_has_xcrypt_enabled) {
-               printk(KERN_ERR PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
+               printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
                return -ENODEV;
        }
 
index c666b4e..40d5680 100644 (file)
@@ -254,12 +254,12 @@ static int __init padlock_init(void)
        int rc = -ENODEV;
 
        if (!cpu_has_phe) {
-               printk(KERN_ERR PFX "VIA PadLock Hash Engine not detected.\n");
+               printk(KERN_NOTICE PFX "VIA PadLock Hash Engine not detected.\n");
                return -ENODEV;
        }
 
        if (!cpu_has_phe_enabled) {
-               printk(KERN_ERR PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
+               printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
                return -ENODEV;
        }
 
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
new file mode 100644 (file)
index 0000000..b11943d
--- /dev/null
@@ -0,0 +1,1597 @@
+/*
+ * talitos - Freescale Integrated Security Engine (SEC) device driver
+ *
+ * Copyright (c) 2008 Freescale Semiconductor, Inc.
+ *
+ * Scatterlist Crypto API glue code copied from files with the following:
+ * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au>
+ *
+ * Crypto algorithm registration code copied from hifn driver:
+ * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/crypto.h>
+#include <linux/hw_random.h>
+#include <linux/of_platform.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/spinlock.h>
+#include <linux/rtnetlink.h>
+
+#include <crypto/algapi.h>
+#include <crypto/aes.h>
+#include <crypto/des.h>
+#include <crypto/sha.h>
+#include <crypto/aead.h>
+#include <crypto/authenc.h>
+
+#include "talitos.h"
+
+#define TALITOS_TIMEOUT 100000
+#define TALITOS_MAX_DATA_LEN 65535
+
+#define DESC_TYPE(desc_hdr) ((be32_to_cpu(desc_hdr) >> 3) & 0x1f)
+#define PRIMARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 28) & 0xf)
+#define SECONDARY_EU(desc_hdr) ((be32_to_cpu(desc_hdr) >> 16) & 0xf)
+
+/* descriptor pointer entry */
+struct talitos_ptr {
+       __be16 len;     /* length */
+       u8 j_extent;    /* jump to sg link table and/or extent */
+       u8 eptr;        /* extended address */
+       __be32 ptr;     /* address */
+};
+
+/* descriptor */
+struct talitos_desc {
+       __be32 hdr;                     /* header high bits */
+       __be32 hdr_lo;                  /* header low bits */
+       struct talitos_ptr ptr[7];      /* ptr/len pair array */
+};
+
+/**
+ * talitos_request - descriptor submission request
+ * @desc: descriptor pointer (kernel virtual)
+ * @dma_desc: descriptor's physical bus address
+ * @callback: whom to call when descriptor processing is done
+ * @context: caller context (optional)
+ */
+struct talitos_request {
+       struct talitos_desc *desc;
+       dma_addr_t dma_desc;
+       void (*callback) (struct device *dev, struct talitos_desc *desc,
+                         void *context, int error);
+       void *context;
+};
+
+struct talitos_private {
+       struct device *dev;
+       struct of_device *ofdev;
+       void __iomem *reg;
+       int irq;
+
+       /* SEC version geometry (from device tree node) */
+       unsigned int num_channels;
+       unsigned int chfifo_len;
+       unsigned int exec_units;
+       unsigned int desc_types;
+
+       /* next channel to be assigned next incoming descriptor */
+       atomic_t last_chan;
+
+       /* per-channel request fifo */
+       struct talitos_request **fifo;
+
+       /*
+        * length of the request fifo
+        * fifo_len is chfifo_len rounded up to next power of 2
+        * so we can use bitwise ops to wrap
+        */
+       unsigned int fifo_len;
+
+       /* per-channel index to next free descriptor request */
+       int *head;
+
+       /* per-channel index to next in-progress/done descriptor request */
+       int *tail;
+
+       /* per-channel request submission (head) and release (tail) locks */
+       spinlock_t *head_lock;
+       spinlock_t *tail_lock;
+
+       /* request callback tasklet */
+       struct tasklet_struct done_task;
+       struct tasklet_struct error_task;
+
+       /* list of registered algorithms */
+       struct list_head alg_list;
+
+       /* hwrng device */
+       struct hwrng rng;
+};
+
+/*
+ * map virtual single (contiguous) pointer to h/w descriptor pointer
+ */
+static void map_single_talitos_ptr(struct device *dev,
+                                  struct talitos_ptr *talitos_ptr,
+                                  unsigned short len, void *data,
+                                  unsigned char extent,
+                                  enum dma_data_direction dir)
+{
+       talitos_ptr->len = cpu_to_be16(len);
+       talitos_ptr->ptr = cpu_to_be32(dma_map_single(dev, data, len, dir));
+       talitos_ptr->j_extent = extent;
+}
+
+/*
+ * unmap bus single (contiguous) h/w descriptor pointer
+ */
+static void unmap_single_talitos_ptr(struct device *dev,
+                                    struct talitos_ptr *talitos_ptr,
+                                    enum dma_data_direction dir)
+{
+       dma_unmap_single(dev, be32_to_cpu(talitos_ptr->ptr),
+                        be16_to_cpu(talitos_ptr->len), dir);
+}
+
+static int reset_channel(struct device *dev, int ch)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       unsigned int timeout = TALITOS_TIMEOUT;
+
+       setbits32(priv->reg + TALITOS_CCCR(ch), TALITOS_CCCR_RESET);
+
+       while ((in_be32(priv->reg + TALITOS_CCCR(ch)) & TALITOS_CCCR_RESET)
+              && --timeout)
+               cpu_relax();
+
+       if (timeout == 0) {
+               dev_err(dev, "failed to reset channel %d\n", ch);
+               return -EIO;
+       }
+
+       /* set done writeback and IRQ */
+       setbits32(priv->reg + TALITOS_CCCR_LO(ch), TALITOS_CCCR_LO_CDWE |
+                 TALITOS_CCCR_LO_CDIE);
+
+       return 0;
+}
+
+static int reset_device(struct device *dev)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       unsigned int timeout = TALITOS_TIMEOUT;
+
+       setbits32(priv->reg + TALITOS_MCR, TALITOS_MCR_SWR);
+
+       while ((in_be32(priv->reg + TALITOS_MCR) & TALITOS_MCR_SWR)
+              && --timeout)
+               cpu_relax();
+
+       if (timeout == 0) {
+               dev_err(dev, "failed to reset device\n");
+               return -EIO;
+       }
+
+       return 0;
+}
+
+/*
+ * Reset and initialize the device
+ */
+static int init_device(struct device *dev)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       int ch, err;
+
+       /*
+        * Master reset
+        * errata documentation: warning: certain SEC interrupts
+        * are not fully cleared by writing the MCR:SWR bit,
+        * set bit twice to completely reset
+        */
+       err = reset_device(dev);
+       if (err)
+               return err;
+
+       err = reset_device(dev);
+       if (err)
+               return err;
+
+       /* reset channels */
+       for (ch = 0; ch < priv->num_channels; ch++) {
+               err = reset_channel(dev, ch);
+               if (err)
+                       return err;
+       }
+
+       /* enable channel done and error interrupts */
+       setbits32(priv->reg + TALITOS_IMR, TALITOS_IMR_INIT);
+       setbits32(priv->reg + TALITOS_IMR_LO, TALITOS_IMR_LO_INIT);
+
+       return 0;
+}
+
+/**
+ * talitos_submit - submits a descriptor to the device for processing
+ * @dev:       the SEC device to be used
+ * @desc:      the descriptor to be processed by the device
+ * @callback:  whom to call when processing is complete
+ * @context:   a handle for use by caller (optional)
+ *
+ * desc must contain valid dma-mapped (bus physical) address pointers.
+ * callback must check err and feedback in descriptor header
+ * for device processing status.
+ */
+static int talitos_submit(struct device *dev, struct talitos_desc *desc,
+                         void (*callback)(struct device *dev,
+                                          struct talitos_desc *desc,
+                                          void *context, int error),
+                         void *context)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       struct talitos_request *request;
+       unsigned long flags, ch;
+       int head;
+
+       /* select done notification */
+       desc->hdr |= DESC_HDR_DONE_NOTIFY;
+
+       /* emulate SEC's round-robin channel fifo polling scheme */
+       ch = atomic_inc_return(&priv->last_chan) & (priv->num_channels - 1);
+
+       spin_lock_irqsave(&priv->head_lock[ch], flags);
+
+       head = priv->head[ch];
+       request = &priv->fifo[ch][head];
+
+       if (request->desc) {
+               /* request queue is full */
+               spin_unlock_irqrestore(&priv->head_lock[ch], flags);
+               return -EAGAIN;
+       }
+
+       /* map descriptor and save caller data */
+       request->dma_desc = dma_map_single(dev, desc, sizeof(*desc),
+                                          DMA_BIDIRECTIONAL);
+       request->callback = callback;
+       request->context = context;
+
+       /* increment fifo head */
+       priv->head[ch] = (priv->head[ch] + 1) & (priv->fifo_len - 1);
+
+       smp_wmb();
+       request->desc = desc;
+
+       /* GO! */
+       wmb();
+       out_be32(priv->reg + TALITOS_FF_LO(ch), request->dma_desc);
+
+       spin_unlock_irqrestore(&priv->head_lock[ch], flags);
+
+       return -EINPROGRESS;
+}
+
+/*
+ * process what was done, notify callback of error if not
+ */
+static void flush_channel(struct device *dev, int ch, int error, int reset_ch)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       struct talitos_request *request, saved_req;
+       unsigned long flags;
+       int tail, status;
+
+       spin_lock_irqsave(&priv->tail_lock[ch], flags);
+
+       tail = priv->tail[ch];
+       while (priv->fifo[ch][tail].desc) {
+               request = &priv->fifo[ch][tail];
+
+               /* descriptors with their done bits set don't get the error */
+               rmb();
+               if ((request->desc->hdr & DESC_HDR_DONE) == DESC_HDR_DONE)
+                       status = 0;
+               else
+                       if (!error)
+                               break;
+                       else
+                               status = error;
+
+               dma_unmap_single(dev, request->dma_desc,
+                       sizeof(struct talitos_desc), DMA_BIDIRECTIONAL);
+
+               /* copy entries so we can call callback outside lock */
+               saved_req.desc = request->desc;
+               saved_req.callback = request->callback;
+               saved_req.context = request->context;
+
+               /* release request entry in fifo */
+               smp_wmb();
+               request->desc = NULL;
+
+               /* increment fifo tail */
+               priv->tail[ch] = (tail + 1) & (priv->fifo_len - 1);
+
+               spin_unlock_irqrestore(&priv->tail_lock[ch], flags);
+               saved_req.callback(dev, saved_req.desc, saved_req.context,
+                                  status);
+               /* channel may resume processing in single desc error case */
+               if (error && !reset_ch && status == error)
+                       return;
+               spin_lock_irqsave(&priv->tail_lock[ch], flags);
+               tail = priv->tail[ch];
+       }
+
+       spin_unlock_irqrestore(&priv->tail_lock[ch], flags);
+}
+
+/*
+ * process completed requests for channels that have done status
+ */
+static void talitos_done(unsigned long data)
+{
+       struct device *dev = (struct device *)data;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       int ch;
+
+       for (ch = 0; ch < priv->num_channels; ch++)
+               flush_channel(dev, ch, 0, 0);
+}
+
+/*
+ * locate current (offending) descriptor
+ */
+static struct talitos_desc *current_desc(struct device *dev, int ch)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       int tail = priv->tail[ch];
+       dma_addr_t cur_desc;
+
+       cur_desc = in_be32(priv->reg + TALITOS_CDPR_LO(ch));
+
+       while (priv->fifo[ch][tail].dma_desc != cur_desc) {
+               tail = (tail + 1) & (priv->fifo_len - 1);
+               if (tail == priv->tail[ch]) {
+                       dev_err(dev, "couldn't locate current descriptor\n");
+                       return NULL;
+               }
+       }
+
+       return priv->fifo[ch][tail].desc;
+}
+
+/*
+ * user diagnostics; report root cause of error based on execution unit status
+ */
+static void report_eu_error(struct device *dev, int ch, struct talitos_desc *desc)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       int i;
+
+       switch (desc->hdr & DESC_HDR_SEL0_MASK) {
+       case DESC_HDR_SEL0_AFEU:
+               dev_err(dev, "AFEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_AFEUISR),
+                       in_be32(priv->reg + TALITOS_AFEUISR_LO));
+               break;
+       case DESC_HDR_SEL0_DEU:
+               dev_err(dev, "DEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_DEUISR),
+                       in_be32(priv->reg + TALITOS_DEUISR_LO));
+               break;
+       case DESC_HDR_SEL0_MDEUA:
+       case DESC_HDR_SEL0_MDEUB:
+               dev_err(dev, "MDEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_MDEUISR),
+                       in_be32(priv->reg + TALITOS_MDEUISR_LO));
+               break;
+       case DESC_HDR_SEL0_RNG:
+               dev_err(dev, "RNGUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_RNGUISR),
+                       in_be32(priv->reg + TALITOS_RNGUISR_LO));
+               break;
+       case DESC_HDR_SEL0_PKEU:
+               dev_err(dev, "PKEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_PKEUISR),
+                       in_be32(priv->reg + TALITOS_PKEUISR_LO));
+               break;
+       case DESC_HDR_SEL0_AESU:
+               dev_err(dev, "AESUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_AESUISR),
+                       in_be32(priv->reg + TALITOS_AESUISR_LO));
+               break;
+       case DESC_HDR_SEL0_CRCU:
+               dev_err(dev, "CRCUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_CRCUISR),
+                       in_be32(priv->reg + TALITOS_CRCUISR_LO));
+               break;
+       case DESC_HDR_SEL0_KEU:
+               dev_err(dev, "KEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_KEUISR),
+                       in_be32(priv->reg + TALITOS_KEUISR_LO));
+               break;
+       }
+
+       switch (desc->hdr & DESC_HDR_SEL1_MASK) {
+       case DESC_HDR_SEL1_MDEUA:
+       case DESC_HDR_SEL1_MDEUB:
+               dev_err(dev, "MDEUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_MDEUISR),
+                       in_be32(priv->reg + TALITOS_MDEUISR_LO));
+               break;
+       case DESC_HDR_SEL1_CRCU:
+               dev_err(dev, "CRCUISR 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_CRCUISR),
+                       in_be32(priv->reg + TALITOS_CRCUISR_LO));
+               break;
+       }
+
+       for (i = 0; i < 8; i++)
+               dev_err(dev, "DESCBUF 0x%08x_%08x\n",
+                       in_be32(priv->reg + TALITOS_DESCBUF(ch) + 8*i),
+                       in_be32(priv->reg + TALITOS_DESCBUF_LO(ch) + 8*i));
+}
+
+/*
+ * recover from error interrupts
+ */
+static void talitos_error(unsigned long data)
+{
+       struct device *dev = (struct device *)data;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       unsigned int timeout = TALITOS_TIMEOUT;
+       int ch, error, reset_dev = 0, reset_ch = 0;
+       u32 isr, isr_lo, v, v_lo;
+
+       isr = in_be32(priv->reg + TALITOS_ISR);
+       isr_lo = in_be32(priv->reg + TALITOS_ISR_LO);
+
+       for (ch = 0; ch < priv->num_channels; ch++) {
+               /* skip channels without errors */
+               if (!(isr & (1 << (ch * 2 + 1))))
+                       continue;
+
+               error = -EINVAL;
+
+               v = in_be32(priv->reg + TALITOS_CCPSR(ch));
+               v_lo = in_be32(priv->reg + TALITOS_CCPSR_LO(ch));
+
+               if (v_lo & TALITOS_CCPSR_LO_DOF) {
+                       dev_err(dev, "double fetch fifo overflow error\n");
+                       error = -EAGAIN;
+                       reset_ch = 1;
+               }
+               if (v_lo & TALITOS_CCPSR_LO_SOF) {
+                       /* h/w dropped descriptor */
+                       dev_err(dev, "single fetch fifo overflow error\n");
+                       error = -EAGAIN;
+               }
+               if (v_lo & TALITOS_CCPSR_LO_MDTE)
+                       dev_err(dev, "master data transfer error\n");
+               if (v_lo & TALITOS_CCPSR_LO_SGDLZ)
+                       dev_err(dev, "s/g data length zero error\n");
+               if (v_lo & TALITOS_CCPSR_LO_FPZ)
+                       dev_err(dev, "fetch pointer zero error\n");
+               if (v_lo & TALITOS_CCPSR_LO_IDH)
+                       dev_err(dev, "illegal descriptor header error\n");
+               if (v_lo & TALITOS_CCPSR_LO_IEU)
+                       dev_err(dev, "invalid execution unit error\n");
+               if (v_lo & TALITOS_CCPSR_LO_EU)
+                       report_eu_error(dev, ch, current_desc(dev, ch));
+               if (v_lo & TALITOS_CCPSR_LO_GB)
+                       dev_err(dev, "gather boundary error\n");
+               if (v_lo & TALITOS_CCPSR_LO_GRL)
+                       dev_err(dev, "gather return/length error\n");
+               if (v_lo & TALITOS_CCPSR_LO_SB)
+                       dev_err(dev, "scatter boundary error\n");
+               if (v_lo & TALITOS_CCPSR_LO_SRL)
+                       dev_err(dev, "scatter return/length error\n");
+
+               flush_channel(dev, ch, error, reset_ch);
+
+               if (reset_ch) {
+                       reset_channel(dev, ch);
+               } else {
+                       setbits32(priv->reg + TALITOS_CCCR(ch),
+                                 TALITOS_CCCR_CONT);
+                       setbits32(priv->reg + TALITOS_CCCR_LO(ch), 0);
+                       while ((in_be32(priv->reg + TALITOS_CCCR(ch)) &
+                              TALITOS_CCCR_CONT) && --timeout)
+                               cpu_relax();
+                       if (timeout == 0) {
+                               dev_err(dev, "failed to restart channel %d\n",
+                                       ch);
+                               reset_dev = 1;
+                       }
+               }
+       }
+       if (reset_dev || isr & ~TALITOS_ISR_CHERR || isr_lo) {
+               dev_err(dev, "done overflow, internal time out, or rngu error: "
+                       "ISR 0x%08x_%08x\n", isr, isr_lo);
+
+               /* purge request queues */
+               for (ch = 0; ch < priv->num_channels; ch++)
+                       flush_channel(dev, ch, -EIO, 1);
+
+               /* reset and reinitialize the device */
+               init_device(dev);
+       }
+}
+
+static irqreturn_t talitos_interrupt(int irq, void *data)
+{
+       struct device *dev = data;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       u32 isr, isr_lo;
+
+       isr = in_be32(priv->reg + TALITOS_ISR);
+       isr_lo = in_be32(priv->reg + TALITOS_ISR_LO);
+
+       /* ack */
+       out_be32(priv->reg + TALITOS_ICR, isr);
+       out_be32(priv->reg + TALITOS_ICR_LO, isr_lo);
+
+       if (unlikely((isr & ~TALITOS_ISR_CHDONE) || isr_lo))
+               talitos_error((unsigned long)data);
+       else
+               if (likely(isr & TALITOS_ISR_CHDONE))
+                       tasklet_schedule(&priv->done_task);
+
+       return (isr || isr_lo) ? IRQ_HANDLED : IRQ_NONE;
+}
+
+/*
+ * hwrng
+ */
+static int talitos_rng_data_present(struct hwrng *rng, int wait)
+{
+       struct device *dev = (struct device *)rng->priv;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       u32 ofl;
+       int i;
+
+       for (i = 0; i < 20; i++) {
+               ofl = in_be32(priv->reg + TALITOS_RNGUSR_LO) &
+                     TALITOS_RNGUSR_LO_OFL;
+               if (ofl || !wait)
+                       break;
+               udelay(10);
+       }
+
+       return !!ofl;
+}
+
+static int talitos_rng_data_read(struct hwrng *rng, u32 *data)
+{
+       struct device *dev = (struct device *)rng->priv;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+
+       /* rng fifo requires 64-bit accesses */
+       *data = in_be32(priv->reg + TALITOS_RNGU_FIFO);
+       *data = in_be32(priv->reg + TALITOS_RNGU_FIFO_LO);
+
+       return sizeof(u32);
+}
+
+static int talitos_rng_init(struct hwrng *rng)
+{
+       struct device *dev = (struct device *)rng->priv;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       unsigned int timeout = TALITOS_TIMEOUT;
+
+       setbits32(priv->reg + TALITOS_RNGURCR_LO, TALITOS_RNGURCR_LO_SR);
+       while (!(in_be32(priv->reg + TALITOS_RNGUSR_LO) & TALITOS_RNGUSR_LO_RD)
+              && --timeout)
+               cpu_relax();
+       if (timeout == 0) {
+               dev_err(dev, "failed to reset rng hw\n");
+               return -ENODEV;
+       }
+
+       /* start generating */
+       setbits32(priv->reg + TALITOS_RNGUDSR_LO, 0);
+
+       return 0;
+}
+
+static int talitos_register_rng(struct device *dev)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+
+       priv->rng.name          = dev_driver_string(dev),
+       priv->rng.init          = talitos_rng_init,
+       priv->rng.data_present  = talitos_rng_data_present,
+       priv->rng.data_read     = talitos_rng_data_read,
+       priv->rng.priv          = (unsigned long)dev;
+
+       return hwrng_register(&priv->rng);
+}
+
+static void talitos_unregister_rng(struct device *dev)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+
+       hwrng_unregister(&priv->rng);
+}
+
+/*
+ * crypto alg
+ */
+#define TALITOS_CRA_PRIORITY           3000
+#define TALITOS_MAX_KEY_SIZE           64
+#define TALITOS_MAX_IV_LENGTH          16 /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
+
+#define MD5_DIGEST_SIZE   16
+
+struct talitos_ctx {
+       struct device *dev;
+       __be32 desc_hdr_template;
+       u8 key[TALITOS_MAX_KEY_SIZE];
+       u8 iv[TALITOS_MAX_IV_LENGTH];
+       unsigned int keylen;
+       unsigned int enckeylen;
+       unsigned int authkeylen;
+       unsigned int authsize;
+};
+
+static int aead_authenc_setauthsize(struct crypto_aead *authenc,
+                                                unsigned int authsize)
+{
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+
+       ctx->authsize = authsize;
+
+       return 0;
+}
+
+static int aead_authenc_setkey(struct crypto_aead *authenc,
+                                           const u8 *key, unsigned int keylen)
+{
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct rtattr *rta = (void *)key;
+       struct crypto_authenc_key_param *param;
+       unsigned int authkeylen;
+       unsigned int enckeylen;
+
+       if (!RTA_OK(rta, keylen))
+               goto badkey;
+
+       if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
+               goto badkey;
+
+       if (RTA_PAYLOAD(rta) < sizeof(*param))
+               goto badkey;
+
+       param = RTA_DATA(rta);
+       enckeylen = be32_to_cpu(param->enckeylen);
+
+       key += RTA_ALIGN(rta->rta_len);
+       keylen -= RTA_ALIGN(rta->rta_len);
+
+       if (keylen < enckeylen)
+               goto badkey;
+
+       authkeylen = keylen - enckeylen;
+
+       if (keylen > TALITOS_MAX_KEY_SIZE)
+               goto badkey;
+
+       memcpy(&ctx->key, key, keylen);
+
+       ctx->keylen = keylen;
+       ctx->enckeylen = enckeylen;
+       ctx->authkeylen = authkeylen;
+
+       return 0;
+
+badkey:
+       crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
+       return -EINVAL;
+}
+
+/*
+ * ipsec_esp_edesc - s/w-extended ipsec_esp descriptor
+ * @src_nents: number of segments in input scatterlist
+ * @dst_nents: number of segments in output scatterlist
+ * @dma_len: length of dma mapped link_tbl space
+ * @dma_link_tbl: bus physical address of link_tbl
+ * @desc: h/w descriptor
+ * @link_tbl: input and output h/w link tables (if {src,dst}_nents > 1)
+ *
+ * if decrypting (with authcheck), or either one of src_nents or dst_nents
+ * is greater than 1, an integrity check value is concatenated to the end
+ * of link_tbl data
+ */
+struct ipsec_esp_edesc {
+       int src_nents;
+       int dst_nents;
+       int dma_len;
+       dma_addr_t dma_link_tbl;
+       struct talitos_desc desc;
+       struct talitos_ptr link_tbl[0];
+};
+
+static void ipsec_esp_unmap(struct device *dev,
+                           struct ipsec_esp_edesc *edesc,
+                           struct aead_request *areq)
+{
+       unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE);
+       unmap_single_talitos_ptr(dev, &edesc->desc.ptr[3], DMA_TO_DEVICE);
+       unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
+       unmap_single_talitos_ptr(dev, &edesc->desc.ptr[0], DMA_TO_DEVICE);
+
+       dma_unmap_sg(dev, areq->assoc, 1, DMA_TO_DEVICE);
+
+       if (areq->src != areq->dst) {
+               dma_unmap_sg(dev, areq->src, edesc->src_nents ? : 1,
+                            DMA_TO_DEVICE);
+               dma_unmap_sg(dev, areq->dst, edesc->dst_nents ? : 1,
+                            DMA_FROM_DEVICE);
+       } else {
+               dma_unmap_sg(dev, areq->src, edesc->src_nents ? : 1,
+                            DMA_BIDIRECTIONAL);
+       }
+
+       if (edesc->dma_len)
+               dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
+                                DMA_BIDIRECTIONAL);
+}
+
+/*
+ * ipsec_esp descriptor callbacks
+ */
+static void ipsec_esp_encrypt_done(struct device *dev,
+                                  struct talitos_desc *desc, void *context,
+                                  int err)
+{
+       struct aead_request *areq = context;
+       struct ipsec_esp_edesc *edesc =
+                container_of(desc, struct ipsec_esp_edesc, desc);
+       struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct scatterlist *sg;
+       void *icvdata;
+
+       ipsec_esp_unmap(dev, edesc, areq);
+
+       /* copy the generated ICV to dst */
+       if (edesc->dma_len) {
+               icvdata = &edesc->link_tbl[edesc->src_nents +
+                                          edesc->dst_nents + 1];
+               sg = sg_last(areq->dst, edesc->dst_nents);
+               memcpy((char *)sg_virt(sg) + sg->length - ctx->authsize,
+                      icvdata, ctx->authsize);
+       }
+
+       kfree(edesc);
+
+       aead_request_complete(areq, err);
+}
+
+static void ipsec_esp_decrypt_done(struct device *dev,
+                                  struct talitos_desc *desc, void *context,
+                                  int err)
+{
+       struct aead_request *req = context;
+       struct ipsec_esp_edesc *edesc =
+                container_of(desc, struct ipsec_esp_edesc, desc);
+       struct crypto_aead *authenc = crypto_aead_reqtfm(req);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct scatterlist *sg;
+       void *icvdata;
+
+       ipsec_esp_unmap(dev, edesc, req);
+
+       if (!err) {
+               /* auth check */
+               if (edesc->dma_len)
+                       icvdata = &edesc->link_tbl[edesc->src_nents +
+                                                  edesc->dst_nents + 1];
+               else
+                       icvdata = &edesc->link_tbl[0];
+
+               sg = sg_last(req->dst, edesc->dst_nents ? : 1);
+               err = memcmp(icvdata, (char *)sg_virt(sg) + sg->length -
+                            ctx->authsize, ctx->authsize) ? -EBADMSG : 0;
+       }
+
+       kfree(edesc);
+
+       aead_request_complete(req, err);
+}
+
+/*
+ * convert scatterlist to SEC h/w link table format
+ * stop at cryptlen bytes
+ */
+static int sg_to_link_tbl(struct scatterlist *sg, int sg_count,
+                          int cryptlen, struct talitos_ptr *link_tbl_ptr)
+{
+       int n_sg = sg_count;
+
+       while (n_sg--) {
+               link_tbl_ptr->ptr = cpu_to_be32(sg_dma_address(sg));
+               link_tbl_ptr->len = cpu_to_be16(sg_dma_len(sg));
+               link_tbl_ptr->j_extent = 0;
+               link_tbl_ptr++;
+               cryptlen -= sg_dma_len(sg);
+               sg = sg_next(sg);
+       }
+
+       /* adjust (decrease) last one (or two) entry's len to cryptlen */
+       link_tbl_ptr--;
+       while (link_tbl_ptr->len <= (-cryptlen)) {
+               /* Empty this entry, and move to previous one */
+               cryptlen += be16_to_cpu(link_tbl_ptr->len);
+               link_tbl_ptr->len = 0;
+               sg_count--;
+               link_tbl_ptr--;
+       }
+       link_tbl_ptr->len = cpu_to_be16(be16_to_cpu(link_tbl_ptr->len)
+                                       + cryptlen);
+
+       /* tag end of link table */
+       link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
+
+       return sg_count;
+}
+
+/*
+ * fill in and submit ipsec_esp descriptor
+ */
+static int ipsec_esp(struct ipsec_esp_edesc *edesc, struct aead_request *areq,
+                    u8 *giv, u64 seq,
+                    void (*callback) (struct device *dev,
+                                      struct talitos_desc *desc,
+                                      void *context, int error))
+{
+       struct crypto_aead *aead = crypto_aead_reqtfm(areq);
+       struct talitos_ctx *ctx = crypto_aead_ctx(aead);
+       struct device *dev = ctx->dev;
+       struct talitos_desc *desc = &edesc->desc;
+       unsigned int cryptlen = areq->cryptlen;
+       unsigned int authsize = ctx->authsize;
+       unsigned int ivsize;
+       int sg_count;
+
+       /* hmac key */
+       map_single_talitos_ptr(dev, &desc->ptr[0], ctx->authkeylen, &ctx->key,
+                              0, DMA_TO_DEVICE);
+       /* hmac data */
+       map_single_talitos_ptr(dev, &desc->ptr[1], sg_virt(areq->src) -
+                              sg_virt(areq->assoc), sg_virt(areq->assoc), 0,
+                              DMA_TO_DEVICE);
+       /* cipher iv */
+       ivsize = crypto_aead_ivsize(aead);
+       map_single_talitos_ptr(dev, &desc->ptr[2], ivsize, giv ?: areq->iv, 0,
+                              DMA_TO_DEVICE);
+
+       /* cipher key */
+       map_single_talitos_ptr(dev, &desc->ptr[3], ctx->enckeylen,
+                              (char *)&ctx->key + ctx->authkeylen, 0,
+                              DMA_TO_DEVICE);
+
+       /*
+        * cipher in
+        * map and adjust cipher len to aead request cryptlen.
+        * extent is bytes of HMAC postpended to ciphertext,
+        * typically 12 for ipsec
+        */
+       desc->ptr[4].len = cpu_to_be16(cryptlen);
+       desc->ptr[4].j_extent = authsize;
+
+       if (areq->src == areq->dst)
+               sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ? : 1,
+                                     DMA_BIDIRECTIONAL);
+       else
+               sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ? : 1,
+                                     DMA_TO_DEVICE);
+
+       if (sg_count == 1) {
+               desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src));
+       } else {
+               sg_count = sg_to_link_tbl(areq->src, sg_count, cryptlen,
+                                         &edesc->link_tbl[0]);
+               if (sg_count > 1) {
+                       desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
+                       desc->ptr[4].ptr = cpu_to_be32(edesc->dma_link_tbl);
+                       dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
+                                                  edesc->dma_len, DMA_BIDIRECTIONAL);
+               } else {
+                       /* Only one segment now, so no link tbl needed */
+                       desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src));
+               }
+       }
+
+       /* cipher out */
+       desc->ptr[5].len = cpu_to_be16(cryptlen);
+       desc->ptr[5].j_extent = authsize;
+
+       if (areq->src != areq->dst) {
+               sg_count = dma_map_sg(dev, areq->dst, edesc->dst_nents ? : 1,
+                                     DMA_FROM_DEVICE);
+       }
+
+       if (sg_count == 1) {
+               desc->ptr[5].ptr = cpu_to_be32(sg_dma_address(areq->dst));
+       } else {
+               struct talitos_ptr *link_tbl_ptr =
+                       &edesc->link_tbl[edesc->src_nents];
+               struct scatterlist *sg;
+
+               desc->ptr[5].ptr = cpu_to_be32((struct talitos_ptr *)
+                                              edesc->dma_link_tbl +
+                                              edesc->src_nents);
+               if (areq->src == areq->dst) {
+                       memcpy(link_tbl_ptr, &edesc->link_tbl[0],
+                              edesc->src_nents * sizeof(struct talitos_ptr));
+               } else {
+                       sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen,
+                                                 link_tbl_ptr);
+               }
+               link_tbl_ptr += sg_count - 1;
+
+               /* handle case where sg_last contains the ICV exclusively */
+               sg = sg_last(areq->dst, edesc->dst_nents);
+               if (sg->length == ctx->authsize)
+                       link_tbl_ptr--;
+
+               link_tbl_ptr->j_extent = 0;
+               link_tbl_ptr++;
+               link_tbl_ptr->j_extent = DESC_PTR_LNKTBL_RETURN;
+               link_tbl_ptr->len = cpu_to_be16(authsize);
+
+               /* icv data follows link tables */
+               link_tbl_ptr->ptr = cpu_to_be32((struct talitos_ptr *)
+                                               edesc->dma_link_tbl +
+                                               edesc->src_nents +
+                                               edesc->dst_nents + 1);
+
+               desc->ptr[5].j_extent |= DESC_PTR_LNKTBL_JUMP;
+               dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
+                                          edesc->dma_len, DMA_BIDIRECTIONAL);
+       }
+
+       /* iv out */
+       map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0,
+                              DMA_FROM_DEVICE);
+
+       return talitos_submit(dev, desc, callback, areq);
+}
+
+
+/*
+ * derive number of elements in scatterlist
+ */
+static int sg_count(struct scatterlist *sg_list, int nbytes)
+{
+       struct scatterlist *sg = sg_list;
+       int sg_nents = 0;
+
+       while (nbytes) {
+               sg_nents++;
+               nbytes -= sg->length;
+               sg = sg_next(sg);
+       }
+
+       return sg_nents;
+}
+
+/*
+ * allocate and map the ipsec_esp extended descriptor
+ */
+static struct ipsec_esp_edesc *ipsec_esp_edesc_alloc(struct aead_request *areq,
+                                                    int icv_stashing)
+{
+       struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct ipsec_esp_edesc *edesc;
+       int src_nents, dst_nents, alloc_len, dma_len;
+
+       if (areq->cryptlen + ctx->authsize > TALITOS_MAX_DATA_LEN) {
+               dev_err(ctx->dev, "cryptlen exceeds h/w max limit\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       src_nents = sg_count(areq->src, areq->cryptlen + ctx->authsize);
+       src_nents = (src_nents == 1) ? 0 : src_nents;
+
+       if (areq->dst == areq->src) {
+               dst_nents = src_nents;
+       } else {
+               dst_nents = sg_count(areq->dst, areq->cryptlen + ctx->authsize);
+               dst_nents = (dst_nents == 1) ? 0 : src_nents;
+       }
+
+       /*
+        * allocate space for base edesc plus the link tables,
+        * allowing for a separate entry for the generated ICV (+ 1),
+        * and the ICV data itself
+        */
+       alloc_len = sizeof(struct ipsec_esp_edesc);
+       if (src_nents || dst_nents) {
+               dma_len = (src_nents + dst_nents + 1) *
+                                sizeof(struct talitos_ptr) + ctx->authsize;
+               alloc_len += dma_len;
+       } else {
+               dma_len = 0;
+               alloc_len += icv_stashing ? ctx->authsize : 0;
+       }
+
+       edesc = kmalloc(alloc_len, GFP_DMA);
+       if (!edesc) {
+               dev_err(ctx->dev, "could not allocate edescriptor\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       edesc->src_nents = src_nents;
+       edesc->dst_nents = dst_nents;
+       edesc->dma_len = dma_len;
+       edesc->dma_link_tbl = dma_map_single(ctx->dev, &edesc->link_tbl[0],
+                                            edesc->dma_len, DMA_BIDIRECTIONAL);
+
+       return edesc;
+}
+
+static int aead_authenc_encrypt(struct aead_request *req)
+{
+       struct crypto_aead *authenc = crypto_aead_reqtfm(req);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct ipsec_esp_edesc *edesc;
+
+       /* allocate extended descriptor */
+       edesc = ipsec_esp_edesc_alloc(req, 0);
+       if (IS_ERR(edesc))
+               return PTR_ERR(edesc);
+
+       /* set encrypt */
+       edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
+
+       return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_encrypt_done);
+}
+
+static int aead_authenc_decrypt(struct aead_request *req)
+{
+       struct crypto_aead *authenc = crypto_aead_reqtfm(req);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       unsigned int authsize = ctx->authsize;
+       struct ipsec_esp_edesc *edesc;
+       struct scatterlist *sg;
+       void *icvdata;
+
+       req->cryptlen -= authsize;
+
+       /* allocate extended descriptor */
+       edesc = ipsec_esp_edesc_alloc(req, 1);
+       if (IS_ERR(edesc))
+               return PTR_ERR(edesc);
+
+       /* stash incoming ICV for later cmp with ICV generated by the h/w */
+       if (edesc->dma_len)
+               icvdata = &edesc->link_tbl[edesc->src_nents +
+                                          edesc->dst_nents + 1];
+       else
+               icvdata = &edesc->link_tbl[0];
+
+       sg = sg_last(req->src, edesc->src_nents ? : 1);
+
+       memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize,
+              ctx->authsize);
+
+       /* decrypt */
+       edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
+
+       return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_done);
+}
+
+static int aead_authenc_givencrypt(
+       struct aead_givcrypt_request *req)
+{
+       struct aead_request *areq = &req->areq;
+       struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
+       struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
+       struct ipsec_esp_edesc *edesc;
+
+       /* allocate extended descriptor */
+       edesc = ipsec_esp_edesc_alloc(areq, 0);
+       if (IS_ERR(edesc))
+               return PTR_ERR(edesc);
+
+       /* set encrypt */
+       edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
+
+       memcpy(req->giv, ctx->iv, crypto_aead_ivsize(authenc));
+
+       return ipsec_esp(edesc, areq, req->giv, req->seq,
+                        ipsec_esp_encrypt_done);
+}
+
+struct talitos_alg_template {
+       char name[CRYPTO_MAX_ALG_NAME];
+       char driver_name[CRYPTO_MAX_ALG_NAME];
+       unsigned int blocksize;
+       struct aead_alg aead;
+       struct device *dev;
+       __be32 desc_hdr_template;
+};
+
+static struct talitos_alg_template driver_algs[] = {
+       /* single-pass ipsec_esp descriptor */
+       {
+               .name = "authenc(hmac(sha1),cbc(aes))",
+               .driver_name = "authenc-hmac-sha1-cbc-aes-talitos",
+               .blocksize = AES_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = AES_BLOCK_SIZE,
+                       .maxauthsize = SHA1_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_AESU |
+                                    DESC_HDR_MODE0_AESU_CBC |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_SHA1_HMAC,
+       },
+       {
+               .name = "authenc(hmac(sha1),cbc(des3_ede))",
+               .driver_name = "authenc-hmac-sha1-cbc-3des-talitos",
+               .blocksize = DES3_EDE_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = DES3_EDE_BLOCK_SIZE,
+                       .maxauthsize = SHA1_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_DEU |
+                                    DESC_HDR_MODE0_DEU_CBC |
+                                    DESC_HDR_MODE0_DEU_3DES |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_SHA1_HMAC,
+       },
+       {
+               .name = "authenc(hmac(sha256),cbc(aes))",
+               .driver_name = "authenc-hmac-sha256-cbc-aes-talitos",
+               .blocksize = AES_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = AES_BLOCK_SIZE,
+                       .maxauthsize = SHA256_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_AESU |
+                                    DESC_HDR_MODE0_AESU_CBC |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_SHA256_HMAC,
+       },
+       {
+               .name = "authenc(hmac(sha256),cbc(des3_ede))",
+               .driver_name = "authenc-hmac-sha256-cbc-3des-talitos",
+               .blocksize = DES3_EDE_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = DES3_EDE_BLOCK_SIZE,
+                       .maxauthsize = SHA256_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_DEU |
+                                    DESC_HDR_MODE0_DEU_CBC |
+                                    DESC_HDR_MODE0_DEU_3DES |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_SHA256_HMAC,
+       },
+       {
+               .name = "authenc(hmac(md5),cbc(aes))",
+               .driver_name = "authenc-hmac-md5-cbc-aes-talitos",
+               .blocksize = AES_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = AES_BLOCK_SIZE,
+                       .maxauthsize = MD5_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_AESU |
+                                    DESC_HDR_MODE0_AESU_CBC |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_MD5_HMAC,
+       },
+       {
+               .name = "authenc(hmac(md5),cbc(des3_ede))",
+               .driver_name = "authenc-hmac-md5-cbc-3des-talitos",
+               .blocksize = DES3_EDE_BLOCK_SIZE,
+               .aead = {
+                       .setkey = aead_authenc_setkey,
+                       .setauthsize = aead_authenc_setauthsize,
+                       .encrypt = aead_authenc_encrypt,
+                       .decrypt = aead_authenc_decrypt,
+                       .givencrypt = aead_authenc_givencrypt,
+                       .geniv = "<built-in>",
+                       .ivsize = DES3_EDE_BLOCK_SIZE,
+                       .maxauthsize = MD5_DIGEST_SIZE,
+                       },
+               .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
+                                    DESC_HDR_SEL0_DEU |
+                                    DESC_HDR_MODE0_DEU_CBC |
+                                    DESC_HDR_MODE0_DEU_3DES |
+                                    DESC_HDR_SEL1_MDEUA |
+                                    DESC_HDR_MODE1_MDEU_INIT |
+                                    DESC_HDR_MODE1_MDEU_PAD |
+                                    DESC_HDR_MODE1_MDEU_MD5_HMAC,
+       }
+};
+
+struct talitos_crypto_alg {
+       struct list_head entry;
+       struct device *dev;
+       __be32 desc_hdr_template;
+       struct crypto_alg crypto_alg;
+};
+
+static int talitos_cra_init(struct crypto_tfm *tfm)
+{
+       struct crypto_alg *alg = tfm->__crt_alg;
+       struct talitos_crypto_alg *talitos_alg =
+                container_of(alg, struct talitos_crypto_alg, crypto_alg);
+       struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
+
+       /* update context with ptr to dev */
+       ctx->dev = talitos_alg->dev;
+       /* copy descriptor header template value */
+       ctx->desc_hdr_template = talitos_alg->desc_hdr_template;
+
+       /* random first IV */
+       get_random_bytes(ctx->iv, TALITOS_MAX_IV_LENGTH);
+
+       return 0;
+}
+
+/*
+ * given the alg's descriptor header template, determine whether descriptor
+ * type and primary/secondary execution units required match the hw
+ * capabilities description provided in the device tree node.
+ */
+static int hw_supports(struct device *dev, __be32 desc_hdr_template)
+{
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       int ret;
+
+       ret = (1 << DESC_TYPE(desc_hdr_template) & priv->desc_types) &&
+             (1 << PRIMARY_EU(desc_hdr_template) & priv->exec_units);
+
+       if (SECONDARY_EU(desc_hdr_template))
+               ret = ret && (1 << SECONDARY_EU(desc_hdr_template)
+                             & priv->exec_units);
+
+       return ret;
+}
+
+static int __devexit talitos_remove(struct of_device *ofdev)
+{
+       struct device *dev = &ofdev->dev;
+       struct talitos_private *priv = dev_get_drvdata(dev);
+       struct talitos_crypto_alg *t_alg, *n;
+       int i;
+
+       list_for_each_entry_safe(t_alg, n, &priv->alg_list, entry) {
+               crypto_unregister_alg(&t_alg->crypto_alg);
+               list_del(&t_alg->entry);
+               kfree(t_alg);
+       }
+
+       if (hw_supports(dev, DESC_HDR_SEL0_RNG))
+               talitos_unregister_rng(dev);
+
+       kfree(priv->tail);
+       kfree(priv->head);
+
+       if (priv->fifo)
+               for (i = 0; i < priv->num_channels; i++)
+                       kfree(priv->fifo[i]);
+
+       kfree(priv->fifo);
+       kfree(priv->head_lock);
+       kfree(priv->tail_lock);
+
+       if (priv->irq != NO_IRQ) {
+               free_irq(priv->irq, dev);
+               irq_dispose_mapping(priv->irq);
+       }
+
+       tasklet_kill(&priv->done_task);
+       tasklet_kill(&priv->error_task);
+
+       iounmap(priv->reg);
+
+       dev_set_drvdata(dev, NULL);
+
+       kfree(priv);
+
+       return 0;
+}
+
+static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
+                                                   struct talitos_alg_template
+                                                          *template)
+{
+       struct talitos_crypto_alg *t_alg;
+       struct crypto_alg *alg;
+
+       t_alg = kzalloc(sizeof(struct talitos_crypto_alg), GFP_KERNEL);
+       if (!t_alg)
+               return ERR_PTR(-ENOMEM);
+
+       alg = &t_alg->crypto_alg;
+
+       snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
+       snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
+                template->driver_name);
+       alg->cra_module = THIS_MODULE;
+       alg->cra_init = talitos_cra_init;
+       alg->cra_priority = TALITOS_CRA_PRIORITY;
+       alg->cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
+       alg->cra_blocksize = template->blocksize;
+       alg->cra_alignmask = 0;
+       alg->cra_type = &crypto_aead_type;
+       alg->cra_ctxsize = sizeof(struct talitos_ctx);
+       alg->cra_u.aead = template->aead;
+
+       t_alg->desc_hdr_template = template->desc_hdr_template;
+       t_alg->dev = dev;
+
+       return t_alg;
+}
+
+static int talitos_probe(struct of_device *ofdev,
+                        const struct of_device_id *match)
+{
+       struct device *dev = &ofdev->dev;
+       struct device_node *np = ofdev->node;
+       struct talitos_private *priv;
+       const unsigned int *prop;
+       int i, err;
+
+       priv = kzalloc(sizeof(struct talitos_private), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       dev_set_drvdata(dev, priv);
+
+       priv->ofdev = ofdev;
+
+       tasklet_init(&priv->done_task, talitos_done, (unsigned long)dev);
+       tasklet_init(&priv->error_task, talitos_error, (unsigned long)dev);
+
+       priv->irq = irq_of_parse_and_map(np, 0);
+
+       if (priv->irq == NO_IRQ) {
+               dev_err(dev, "failed to map irq\n");
+               err = -EINVAL;
+               goto err_out;
+       }
+
+       /* get the irq line */
+       err = request_irq(priv->irq, talitos_interrupt, 0,
+                         dev_driver_string(dev), dev);
+       if (err) {
+               dev_err(dev, "failed to request irq %d\n", priv->irq);
+               irq_dispose_mapping(priv->irq);
+               priv->irq = NO_IRQ;
+               goto err_out;
+       }
+
+       priv->reg = of_iomap(np, 0);
+       if (!priv->reg) {
+               dev_err(dev, "failed to of_iomap\n");
+               err = -ENOMEM;
+               goto err_out;
+       }
+
+       /* get SEC version capabilities from device tree */
+       prop = of_get_property(np, "fsl,num-channels", NULL);
+       if (prop)
+               priv->num_channels = *prop;
+
+       prop = of_get_property(np, "fsl,channel-fifo-len", NULL);
+       if (prop)
+               priv->chfifo_len = *prop;
+
+       prop = of_get_property(np, "fsl,exec-units-mask", NULL);
+       if (prop)
+               priv->exec_units = *prop;
+
+       prop = of_get_property(np, "fsl,descriptor-types-mask", NULL);
+       if (prop)
+               priv->desc_types = *prop;
+
+       if (!is_power_of_2(priv->num_channels) || !priv->chfifo_len ||
+           !priv->exec_units || !priv->desc_types) {
+               dev_err(dev, "invalid property data in device tree node\n");
+               err = -EINVAL;
+               goto err_out;
+       }
+
+       of_node_put(np);
+       np = NULL;
+
+       priv->head_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels,
+                                 GFP_KERNEL);
+       priv->tail_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels,
+                                 GFP_KERNEL);
+       if (!priv->head_lock || !priv->tail_lock) {
+               dev_err(dev, "failed to allocate fifo locks\n");
+               err = -ENOMEM;
+               goto err_out;
+       }
+
+       for (i = 0; i < priv->num_channels; i++) {
+               spin_lock_init(&priv->head_lock[i]);
+               spin_lock_init(&priv->tail_lock[i]);
+       }
+
+       priv->fifo = kmalloc(sizeof(struct talitos_request *) *
+                            priv->num_channels, GFP_KERNEL);
+       if (!priv->fifo) {
+               dev_err(dev, "failed to allocate request fifo\n");
+               err = -ENOMEM;
+               goto err_out;
+       }
+
+       priv->fifo_len = roundup_pow_of_two(priv->chfifo_len);
+
+       for (i = 0; i < priv->num_channels; i++) {
+               priv->fifo[i] = kzalloc(sizeof(struct talitos_request) *
+                                       priv->fifo_len, GFP_KERNEL);
+               if (!priv->fifo[i]) {
+                       dev_err(dev, "failed to allocate request fifo %d\n", i);
+                       err = -ENOMEM;
+                       goto err_out;
+               }
+       }
+
+       priv->head = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL);
+       priv->tail = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL);
+       if (!priv->head || !priv->tail) {
+               dev_err(dev, "failed to allocate request index space\n");
+               err = -ENOMEM;
+               goto err_out;
+       }
+
+       /* reset and initialize the h/w */
+       err = init_device(dev);
+       if (err) {
+               dev_err(dev, "failed to initialize device\n");
+               goto err_out;
+       }
+
+       /* register the RNG, if available */
+       if (hw_supports(dev, DESC_HDR_SEL0_RNG)) {
+               err = talitos_register_rng(dev);
+               if (err) {
+                       dev_err(dev, "failed to register hwrng: %d\n", err);
+                       goto err_out;
+               } else
+                       dev_info(dev, "hwrng\n");
+       }
+
+       /* register crypto algorithms the device supports */
+       INIT_LIST_HEAD(&priv->alg_list);
+
+       for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
+               if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
+                       struct talitos_crypto_alg *t_alg;
+
+                       t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
+                       if (IS_ERR(t_alg)) {
+                               err = PTR_ERR(t_alg);
+                               goto err_out;
+                       }
+
+                       err = crypto_register_alg(&t_alg->crypto_alg);
+                       if (err) {
+                               dev_err(dev, "%s alg registration failed\n",
+                                       t_alg->crypto_alg.cra_driver_name);
+                               kfree(t_alg);
+                       } else {
+                               list_add_tail(&t_alg->entry, &priv->alg_list);
+                               dev_info(dev, "%s\n",
+                                        t_alg->crypto_alg.cra_driver_name);
+                       }
+               }
+       }
+
+       return 0;
+
+err_out:
+       talitos_remove(ofdev);
+       if (np)
+               of_node_put(np);
+
+       return err;
+}
+
+static struct of_device_id talitos_match[] = {
+       {
+               .compatible = "fsl,sec2.0",
+       },
+       {},
+};
+MODULE_DEVICE_TABLE(of, talitos_match);
+
+static struct of_platform_driver talitos_driver = {
+       .name = "talitos",
+       .match_table = talitos_match,
+       .probe = talitos_probe,
+       .remove = __devexit_p(talitos_remove),
+};
+
+static int __init talitos_init(void)
+{
+       return of_register_platform_driver(&talitos_driver);
+}
+module_init(talitos_init);
+
+static void __exit talitos_exit(void)
+{
+       of_unregister_platform_driver(&talitos_driver);
+}
+module_exit(talitos_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kim Phillips <kim.phillips@freescale.com>");
+MODULE_DESCRIPTION("Freescale integrated security engine (SEC) driver");
diff --git a/drivers/crypto/talitos.h b/drivers/crypto/talitos.h
new file mode 100644 (file)
index 0000000..c48a405
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Freescale SEC (talitos) device register and descriptor header defines
+ *
+ * Copyright (c) 2006-2008 Freescale Semiconductor, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * TALITOS_xxx_LO addresses point to the low data bits (32-63) of the register
+ */
+
+/* global register offset addresses */
+#define TALITOS_MCR                    0x1030  /* master control register */
+#define TALITOS_MCR_LO                 0x1038
+#define   TALITOS_MCR_SWR              0x1     /* s/w reset */
+#define TALITOS_IMR                    0x1008  /* interrupt mask register */
+#define   TALITOS_IMR_INIT             0x10fff /* enable channel IRQs */
+#define TALITOS_IMR_LO                 0x100C
+#define   TALITOS_IMR_LO_INIT          0x20000 /* allow RNGU error IRQs */
+#define TALITOS_ISR                    0x1010  /* interrupt status register */
+#define   TALITOS_ISR_CHERR            0xaa    /* channel errors mask */
+#define   TALITOS_ISR_CHDONE           0x55    /* channel done mask */
+#define TALITOS_ISR_LO                 0x1014
+#define TALITOS_ICR                    0x1018  /* interrupt clear register */
+#define TALITOS_ICR_LO                 0x101C
+
+/* channel register address stride */
+#define TALITOS_CH_STRIDE              0x100
+
+/* channel configuration register  */
+#define TALITOS_CCCR(ch)               (ch * TALITOS_CH_STRIDE + 0x1108)
+#define   TALITOS_CCCR_CONT            0x2    /* channel continue */
+#define   TALITOS_CCCR_RESET           0x1    /* channel reset */
+#define TALITOS_CCCR_LO(ch)            (ch * TALITOS_CH_STRIDE + 0x110c)
+#define   TALITOS_CCCR_LO_CDWE         0x10   /* chan. done writeback enab. */
+#define   TALITOS_CCCR_LO_NT           0x4    /* notification type */
+#define   TALITOS_CCCR_LO_CDIE         0x2    /* channel done IRQ enable */
+
+/* CCPSR: channel pointer status register */
+#define TALITOS_CCPSR(ch)              (ch * TALITOS_CH_STRIDE + 0x1110)
+#define TALITOS_CCPSR_LO(ch)           (ch * TALITOS_CH_STRIDE + 0x1114)
+#define   TALITOS_CCPSR_LO_DOF         0x8000 /* double FF write oflow error */
+#define   TALITOS_CCPSR_LO_SOF         0x4000 /* single FF write oflow error */
+#define   TALITOS_CCPSR_LO_MDTE                0x2000 /* master data transfer error */
+#define   TALITOS_CCPSR_LO_SGDLZ       0x1000 /* s/g data len zero error */
+#define   TALITOS_CCPSR_LO_FPZ         0x0800 /* fetch ptr zero error */
+#define   TALITOS_CCPSR_LO_IDH         0x0400 /* illegal desc hdr error */
+#define   TALITOS_CCPSR_LO_IEU         0x0200 /* invalid EU error */
+#define   TALITOS_CCPSR_LO_EU          0x0100 /* EU error detected */
+#define   TALITOS_CCPSR_LO_GB          0x0080 /* gather boundary error */
+#define   TALITOS_CCPSR_LO_GRL         0x0040 /* gather return/length error */
+#define   TALITOS_CCPSR_LO_SB          0x0020 /* scatter boundary error */
+#define   TALITOS_CCPSR_LO_SRL         0x0010 /* scatter return/length error */
+
+/* channel fetch fifo register */
+#define TALITOS_FF(ch)                 (ch * TALITOS_CH_STRIDE + 0x1148)
+#define TALITOS_FF_LO(ch)              (ch * TALITOS_CH_STRIDE + 0x114c)
+
+/* current descriptor pointer register */
+#define TALITOS_CDPR(ch)               (ch * TALITOS_CH_STRIDE + 0x1140)
+#define TALITOS_CDPR_LO(ch)            (ch * TALITOS_CH_STRIDE + 0x1144)
+
+/* descriptor buffer register */
+#define TALITOS_DESCBUF(ch)            (ch * TALITOS_CH_STRIDE + 0x1180)
+#define TALITOS_DESCBUF_LO(ch)         (ch * TALITOS_CH_STRIDE + 0x1184)
+
+/* gather link table */
+#define TALITOS_GATHER(ch)             (ch * TALITOS_CH_STRIDE + 0x11c0)
+#define TALITOS_GATHER_LO(ch)          (ch * TALITOS_CH_STRIDE + 0x11c4)
+
+/* scatter link table */
+#define TALITOS_SCATTER(ch)            (ch * TALITOS_CH_STRIDE + 0x11e0)
+#define TALITOS_SCATTER_LO(ch)         (ch * TALITOS_CH_STRIDE + 0x11e4)
+
+/* execution unit interrupt status registers */
+#define TALITOS_DEUISR                 0x2030 /* DES unit */
+#define TALITOS_DEUISR_LO              0x2034
+#define TALITOS_AESUISR                        0x4030 /* AES unit */
+#define TALITOS_AESUISR_LO             0x4034
+#define TALITOS_MDEUISR                        0x6030 /* message digest unit */
+#define TALITOS_MDEUISR_LO             0x6034
+#define TALITOS_AFEUISR                        0x8030 /* arc4 unit */
+#define TALITOS_AFEUISR_LO             0x8034
+#define TALITOS_RNGUISR                        0xa030 /* random number unit */
+#define TALITOS_RNGUISR_LO             0xa034
+#define TALITOS_RNGUSR                 0xa028 /* rng status */
+#define TALITOS_RNGUSR_LO              0xa02c
+#define   TALITOS_RNGUSR_LO_RD         0x1     /* reset done */
+#define   TALITOS_RNGUSR_LO_OFL                0xff0000/* output FIFO length */
+#define TALITOS_RNGUDSR                        0xa010  /* data size */
+#define TALITOS_RNGUDSR_LO             0xa014
+#define TALITOS_RNGU_FIFO              0xa800  /* output FIFO */
+#define TALITOS_RNGU_FIFO_LO           0xa804  /* output FIFO */
+#define TALITOS_RNGURCR                        0xa018  /* reset control */
+#define TALITOS_RNGURCR_LO             0xa01c
+#define   TALITOS_RNGURCR_LO_SR                0x1     /* software reset */
+#define TALITOS_PKEUISR                        0xc030 /* public key unit */
+#define TALITOS_PKEUISR_LO             0xc034
+#define TALITOS_KEUISR                 0xe030 /* kasumi unit */
+#define TALITOS_KEUISR_LO              0xe034
+#define TALITOS_CRCUISR                        0xf030 /* cyclic redundancy check unit*/
+#define TALITOS_CRCUISR_LO             0xf034
+
+/*
+ * talitos descriptor header (hdr) bits
+ */
+
+/* written back when done */
+#define DESC_HDR_DONE                  __constant_cpu_to_be32(0xff000000)
+
+/* primary execution unit select */
+#define        DESC_HDR_SEL0_MASK              __constant_cpu_to_be32(0xf0000000)
+#define        DESC_HDR_SEL0_AFEU              __constant_cpu_to_be32(0x10000000)
+#define        DESC_HDR_SEL0_DEU               __constant_cpu_to_be32(0x20000000)
+#define        DESC_HDR_SEL0_MDEUA             __constant_cpu_to_be32(0x30000000)
+#define        DESC_HDR_SEL0_MDEUB             __constant_cpu_to_be32(0xb0000000)
+#define        DESC_HDR_SEL0_RNG               __constant_cpu_to_be32(0x40000000)
+#define        DESC_HDR_SEL0_PKEU              __constant_cpu_to_be32(0x50000000)
+#define        DESC_HDR_SEL0_AESU              __constant_cpu_to_be32(0x60000000)
+#define        DESC_HDR_SEL0_KEU               __constant_cpu_to_be32(0x70000000)
+#define        DESC_HDR_SEL0_CRCU              __constant_cpu_to_be32(0x80000000)
+
+/* primary execution unit mode (MODE0) and derivatives */
+#define        DESC_HDR_MODE0_ENCRYPT          __constant_cpu_to_be32(0x00100000)
+#define        DESC_HDR_MODE0_AESU_CBC         __constant_cpu_to_be32(0x00200000)
+#define        DESC_HDR_MODE0_DEU_CBC          __constant_cpu_to_be32(0x00400000)
+#define        DESC_HDR_MODE0_DEU_3DES         __constant_cpu_to_be32(0x00200000)
+#define        DESC_HDR_MODE0_MDEU_INIT        __constant_cpu_to_be32(0x01000000)
+#define        DESC_HDR_MODE0_MDEU_HMAC        __constant_cpu_to_be32(0x00800000)
+#define        DESC_HDR_MODE0_MDEU_PAD         __constant_cpu_to_be32(0x00400000)
+#define        DESC_HDR_MODE0_MDEU_MD5         __constant_cpu_to_be32(0x00200000)
+#define        DESC_HDR_MODE0_MDEU_SHA256      __constant_cpu_to_be32(0x00100000)
+#define        DESC_HDR_MODE0_MDEU_SHA1        __constant_cpu_to_be32(0x00000000)
+#define        DESC_HDR_MODE0_MDEU_MD5_HMAC    (DESC_HDR_MODE0_MDEU_MD5 | \
+                                        DESC_HDR_MODE0_MDEU_HMAC)
+#define        DESC_HDR_MODE0_MDEU_SHA256_HMAC (DESC_HDR_MODE0_MDEU_SHA256 | \
+                                        DESC_HDR_MODE0_MDEU_HMAC)
+#define        DESC_HDR_MODE0_MDEU_SHA1_HMAC   (DESC_HDR_MODE0_MDEU_SHA1 | \
+                                        DESC_HDR_MODE0_MDEU_HMAC)
+
+/* secondary execution unit select (SEL1) */
+#define        DESC_HDR_SEL1_MASK              __constant_cpu_to_be32(0x000f0000)
+#define        DESC_HDR_SEL1_MDEUA             __constant_cpu_to_be32(0x00030000)
+#define        DESC_HDR_SEL1_MDEUB             __constant_cpu_to_be32(0x000b0000)
+#define        DESC_HDR_SEL1_CRCU              __constant_cpu_to_be32(0x00080000)
+
+/* secondary execution unit mode (MODE1) and derivatives */
+#define        DESC_HDR_MODE1_MDEU_INIT        __constant_cpu_to_be32(0x00001000)
+#define        DESC_HDR_MODE1_MDEU_HMAC        __constant_cpu_to_be32(0x00000800)
+#define        DESC_HDR_MODE1_MDEU_PAD         __constant_cpu_to_be32(0x00000400)
+#define        DESC_HDR_MODE1_MDEU_MD5         __constant_cpu_to_be32(0x00000200)
+#define        DESC_HDR_MODE1_MDEU_SHA256      __constant_cpu_to_be32(0x00000100)
+#define        DESC_HDR_MODE1_MDEU_SHA1        __constant_cpu_to_be32(0x00000000)
+#define        DESC_HDR_MODE1_MDEU_MD5_HMAC    (DESC_HDR_MODE1_MDEU_MD5 | \
+                                        DESC_HDR_MODE1_MDEU_HMAC)
+#define        DESC_HDR_MODE1_MDEU_SHA256_HMAC (DESC_HDR_MODE1_MDEU_SHA256 | \
+                                        DESC_HDR_MODE1_MDEU_HMAC)
+#define        DESC_HDR_MODE1_MDEU_SHA1_HMAC   (DESC_HDR_MODE1_MDEU_SHA1 | \
+                                        DESC_HDR_MODE1_MDEU_HMAC)
+
+/* direction of overall data flow (DIR) */
+#define        DESC_HDR_DIR_INBOUND            __constant_cpu_to_be32(0x00000002)
+
+/* request done notification (DN) */
+#define        DESC_HDR_DONE_NOTIFY            __constant_cpu_to_be32(0x00000001)
+
+/* descriptor types */
+#define DESC_HDR_TYPE_AESU_CTR_NONSNOOP                __constant_cpu_to_be32(0 << 3)
+#define DESC_HDR_TYPE_IPSEC_ESP                        __constant_cpu_to_be32(1 << 3)
+#define DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU  __constant_cpu_to_be32(2 << 3)
+#define DESC_HDR_TYPE_HMAC_SNOOP_NO_AFEU       __constant_cpu_to_be32(4 << 3)
+
+/* link table extent field bits */
+#define DESC_PTR_LNKTBL_JUMP                   0x80
+#define DESC_PTR_LNKTBL_RETURN                 0x02
+#define DESC_PTR_LNKTBL_NEXT                   0x01
index dc2cec6..ebb9e51 100644 (file)
@@ -26,6 +26,16 @@ config EDD_OFF
          kernel. Say N if you want EDD enabled by default. EDD can be dynamically set
          using the kernel parameter 'edd={on|skipmbr|off}'.
 
+config FIRMWARE_MEMMAP
+    bool "Add firmware-provided memory map to sysfs" if EMBEDDED
+    default (X86_64 || X86_32)
+    help
+      Add the firmware-provided (unmodified) memory map to /sys/firmware/memmap.
+      That memory map is used for example by kexec to set up parameter area
+      for the next kernel, but can also be used for debugging purposes.
+
+      See also Documentation/ABI/testing/sysfs-firmware-memmap.
+
 config EFI_VARS
        tristate "EFI Variable Support via sysfs"
        depends on EFI
index 4c91471..1c3c173 100644 (file)
@@ -10,3 +10,4 @@ obj-$(CONFIG_DCDBAS)          += dcdbas.o
 obj-$(CONFIG_DMIID)            += dmi-id.o
 obj-$(CONFIG_ISCSI_IBFT_FIND)  += iscsi_ibft_find.o
 obj-$(CONFIG_ISCSI_IBFT)       += iscsi_ibft.o
+obj-$(CONFIG_FIRMWARE_MEMMAP)  += memmap.o
index c5e3ed7..455575b 100644 (file)
@@ -8,6 +8,11 @@
 #include <linux/slab.h>
 #include <asm/dmi.h>
 
+/*
+ * DMI stands for "Desktop Management Interface".  It is part
+ * of and an antecedent to, SMBIOS, which stands for System
+ * Management BIOS.  See further: http://www.dmtf.org/standards
+ */
 static char dmi_empty_string[] = "        ";
 
 static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
new file mode 100644 (file)
index 0000000..e23399c
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * linux/drivers/firmware/memmap.c
+ *  Copyright (C) 2008 SUSE LINUX Products GmbH
+ *  by Bernhard Walle <bwalle@suse.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2.0 as published by
+ * the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/string.h>
+#include <linux/firmware-map.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/bootmem.h>
+
+/*
+ * Data types ------------------------------------------------------------------
+ */
+
+/*
+ * Firmware map entry. Because firmware memory maps are flat and not
+ * hierarchical, it's ok to organise them in a linked list. No parent
+ * information is necessary as for the resource tree.
+ */
+struct firmware_map_entry {
+       resource_size_t         start;  /* start of the memory range */
+       resource_size_t         end;    /* end of the memory range (incl.) */
+       const char              *type;  /* type of the memory range */
+       struct list_head        list;   /* entry for the linked list */
+       struct kobject          kobj;   /* kobject for each entry */
+};
+
+/*
+ * Forward declarations --------------------------------------------------------
+ */
+static ssize_t memmap_attr_show(struct kobject *kobj,
+                               struct attribute *attr, char *buf);
+static ssize_t start_show(struct firmware_map_entry *entry, char *buf);
+static ssize_t end_show(struct firmware_map_entry *entry, char *buf);
+static ssize_t type_show(struct firmware_map_entry *entry, char *buf);
+
+/*
+ * Static data -----------------------------------------------------------------
+ */
+
+struct memmap_attribute {
+       struct attribute attr;
+       ssize_t (*show)(struct firmware_map_entry *entry, char *buf);
+};
+
+struct memmap_attribute memmap_start_attr = __ATTR_RO(start);
+struct memmap_attribute memmap_end_attr   = __ATTR_RO(end);
+struct memmap_attribute memmap_type_attr  = __ATTR_RO(type);
+
+/*
+ * These are default attributes that are added for every memmap entry.
+ */
+static struct attribute *def_attrs[] = {
+       &memmap_start_attr.attr,
+       &memmap_end_attr.attr,
+       &memmap_type_attr.attr,
+       NULL
+};
+
+static struct sysfs_ops memmap_attr_ops = {
+       .show = memmap_attr_show,
+};
+
+static struct kobj_type memmap_ktype = {
+       .sysfs_ops      = &memmap_attr_ops,
+       .default_attrs  = def_attrs,
+};
+
+/*
+ * Registration functions ------------------------------------------------------
+ */
+
+/*
+ * Firmware memory map entries
+ */
+static LIST_HEAD(map_entries);
+
+/**
+ * Common implementation of firmware_map_add() and firmware_map_add_early()
+ * which expects a pre-allocated struct firmware_map_entry.
+ *
+ * @start: Start of the memory range.
+ * @end:   End of the memory range (inclusive).
+ * @type:  Type of the memory range.
+ * @entry: Pre-allocated (either kmalloc() or bootmem allocator), uninitialised
+ *         entry.
+ */
+static int firmware_map_add_entry(resource_size_t start, resource_size_t end,
+                                 const char *type,
+                                 struct firmware_map_entry *entry)
+{
+       BUG_ON(start > end);
+
+       entry->start = start;
+       entry->end = end;
+       entry->type = type;
+       INIT_LIST_HEAD(&entry->list);
+       kobject_init(&entry->kobj, &memmap_ktype);
+
+       list_add_tail(&entry->list, &map_entries);
+
+       return 0;
+}
+
+/*
+ * See <linux/firmware-map.h> for documentation.
+ */
+int firmware_map_add(resource_size_t start, resource_size_t end,
+                    const char *type)
+{
+       struct firmware_map_entry *entry;
+
+       entry = kmalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC);
+       WARN_ON(!entry);
+       if (!entry)
+               return -ENOMEM;
+
+       return firmware_map_add_entry(start, end, type, entry);
+}
+
+/*
+ * See <linux/firmware-map.h> for documentation.
+ */
+int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
+                                 const char *type)
+{
+       struct firmware_map_entry *entry;
+
+       entry = alloc_bootmem_low(sizeof(struct firmware_map_entry));
+       WARN_ON(!entry);
+       if (!entry)
+               return -ENOMEM;
+
+       return firmware_map_add_entry(start, end, type, entry);
+}
+
+/*
+ * Sysfs functions -------------------------------------------------------------
+ */
+
+static ssize_t start_show(struct firmware_map_entry *entry, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->start);
+}
+
+static ssize_t end_show(struct firmware_map_entry *entry, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->end);
+}
+
+static ssize_t type_show(struct firmware_map_entry *entry, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%s\n", entry->type);
+}
+
+#define to_memmap_attr(_attr) container_of(_attr, struct memmap_attribute, attr)
+#define to_memmap_entry(obj) container_of(obj, struct firmware_map_entry, kobj)
+
+static ssize_t memmap_attr_show(struct kobject *kobj,
+                               struct attribute *attr, char *buf)
+{
+       struct firmware_map_entry *entry = to_memmap_entry(kobj);
+       struct memmap_attribute *memmap_attr = to_memmap_attr(attr);
+
+       return memmap_attr->show(entry, buf);
+}
+
+/*
+ * Initialises stuff and adds the entries in the map_entries list to
+ * sysfs. Important is that firmware_map_add() and firmware_map_add_early()
+ * must be called before late_initcall.
+ */
+static int __init memmap_init(void)
+{
+       int i = 0;
+       struct firmware_map_entry *entry;
+       struct kset *memmap_kset;
+
+       memmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj);
+       WARN_ON(!memmap_kset);
+       if (!memmap_kset)
+               return -ENOMEM;
+
+       list_for_each_entry(entry, &map_entries, list) {
+               entry->kobj.kset = memmap_kset;
+               kobject_add(&entry->kobj, NULL, "%d", i++);
+       }
+
+       return 0;
+}
+late_initcall(memmap_init);
+
diff --git a/drivers/gpu/Makefile b/drivers/gpu/Makefile
new file mode 100644 (file)
index 0000000..de566cf
--- /dev/null
@@ -0,0 +1 @@
+obj-y                  += drm/
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
new file mode 100644 (file)
index 0000000..610d6fd
--- /dev/null
@@ -0,0 +1,107 @@
+#
+# Drm device configuration
+#
+# This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+#
+menuconfig DRM
+       tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
+       depends on (AGP || AGP=n) && PCI && !EMULATED_CMPXCHG
+       help
+         Kernel-level support for the Direct Rendering Infrastructure (DRI)
+         introduced in XFree86 4.0. If you say Y here, you need to select
+         the module that's right for your graphics card from the list below.
+         These modules provide support for synchronization, security, and
+         DMA transfers. Please see <http://dri.sourceforge.net/> for more
+         details.  You should also select and configure AGP
+         (/dev/agpgart) support.
+
+config DRM_TDFX
+       tristate "3dfx Banshee/Voodoo3+"
+       depends on DRM && PCI
+       help
+         Choose this option if you have a 3dfx Banshee or Voodoo3 (or later),
+         graphics card.  If M is selected, the module will be called tdfx.
+
+config DRM_R128
+       tristate "ATI Rage 128"
+       depends on DRM && PCI
+       help
+         Choose this option if you have an ATI Rage 128 graphics card.  If M
+         is selected, the module will be called r128.  AGP support for
+         this card is strongly suggested (unless you have a PCI version).
+
+config DRM_RADEON
+       tristate "ATI Radeon"
+       depends on DRM && PCI
+       help
+         Choose this option if you have an ATI Radeon graphics card.  There
+         are both PCI and AGP versions.  You don't need to choose this to
+         run the Radeon in plain VGA mode.
+
+         If M is selected, the module will be called radeon.
+
+config DRM_I810
+       tristate "Intel I810"
+       depends on DRM && AGP && AGP_INTEL
+       help
+         Choose this option if you have an Intel I810 graphics card.  If M is
+         selected, the module will be called i810.  AGP support is required
+         for this driver to work.
+
+choice
+       prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
+       depends on DRM && AGP && AGP_INTEL
+       optional
+
+config DRM_I830
+       tristate "i830 driver"
+       help
+         Choose this option if you have a system that has Intel 830M, 845G,
+         852GM, 855GM or 865G integrated graphics.  If M is selected, the
+         module will be called i830.  AGP support is required for this driver
+         to work. This driver is used by the older X releases X.org 6.7 and
+         XFree86 4.3. If unsure, build this and i915 as modules and the X server
+         will load the correct one.
+
+config DRM_I915
+       tristate "i915 driver"
+       help
+         Choose this option if you have a system that has Intel 830M, 845G,
+         852GM, 855GM 865G or 915G integrated graphics.  If M is selected, the
+         module will be called i915.  AGP support is required for this driver
+         to work. This driver is used by the Intel driver in X.org 6.8 and
+         XFree86 4.4 and above. If unsure, build this and i830 as modules and
+         the X server will load the correct one.
+
+endchoice
+
+config DRM_MGA
+       tristate "Matrox g200/g400"
+       depends on DRM
+       help
+         Choose this option if you have a Matrox G200, G400 or G450 graphics
+         card.  If M is selected, the module will be called mga.  AGP
+         support is required for this driver to work.
+
+config DRM_SIS
+       tristate "SiS video cards"
+       depends on DRM && AGP
+       help
+         Choose this option if you have a SiS 630 or compatible video
+          chipset. If M is selected the module will be called sis. AGP
+          support is required for this driver to work.
+
+config DRM_VIA
+       tristate "Via unichrome video cards"
+       depends on DRM
+       help
+         Choose this option if you have a Via unichrome or compatible video
+         chipset. If M is selected the module will be called via.
+
+config DRM_SAVAGE
+       tristate "Savage video cards"
+       depends on DRM
+       help
+         Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
+         chipset. If M is selected the module will be called savage.
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
new file mode 100644 (file)
index 0000000..e9f9a97
--- /dev/null
@@ -0,0 +1,26 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+
+drm-y       := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
+               drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
+               drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
+               drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
+               drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o
+
+drm-$(CONFIG_COMPAT) += drm_ioc32.o
+
+obj-$(CONFIG_DRM)      += drm.o
+obj-$(CONFIG_DRM_TDFX) += tdfx/
+obj-$(CONFIG_DRM_R128) += r128/
+obj-$(CONFIG_DRM_RADEON)+= radeon/
+obj-$(CONFIG_DRM_MGA)  += mga/
+obj-$(CONFIG_DRM_I810) += i810/
+obj-$(CONFIG_DRM_I830) += i830/
+obj-$(CONFIG_DRM_I915)  += i915/
+obj-$(CONFIG_DRM_SIS)   += sis/
+obj-$(CONFIG_DRM_SAVAGE)+= savage/
+obj-$(CONFIG_DRM_VIA)  +=via/
+
diff --git a/drivers/gpu/drm/README.drm b/drivers/gpu/drm/README.drm
new file mode 100644 (file)
index 0000000..b5b3327
--- /dev/null
@@ -0,0 +1,43 @@
+************************************************************
+* For the very latest on DRI development, please see:      *
+*     http://dri.freedesktop.org/                          *
+************************************************************
+
+The Direct Rendering Manager (drm) is a device-independent kernel-level
+device driver that provides support for the XFree86 Direct Rendering
+Infrastructure (DRI).
+
+The DRM supports the Direct Rendering Infrastructure (DRI) in four major
+ways:
+
+    1. The DRM provides synchronized access to the graphics hardware via
+       the use of an optimized two-tiered lock.
+
+    2. The DRM enforces the DRI security policy for access to the graphics
+       hardware by only allowing authenticated X11 clients access to
+       restricted regions of memory.
+
+    3. The DRM provides a generic DMA engine, complete with multiple
+       queues and the ability to detect the need for an OpenGL context
+       switch.
+
+    4. The DRM is extensible via the use of small device-specific modules
+       that rely extensively on the API exported by the DRM module.
+
+
+Documentation on the DRI is available from:
+    http://dri.freedesktop.org/wiki/Documentation
+    http://sourceforge.net/project/showfiles.php?group_id=387
+    http://dri.sourceforge.net/doc/
+
+For specific information about kernel-level support, see:
+
+    The Direct Rendering Manager, Kernel Support for the Direct Rendering
+    Infrastructure
+    http://dri.sourceforge.net/doc/drm_low_level.html
+
+    Hardware Locking for the Direct Rendering Infrastructure
+    http://dri.sourceforge.net/doc/hardware_locking_low_level.html
+
+    A Security Analysis of the Direct Rendering Infrastructure
+    http://dri.sourceforge.net/doc/security_low_level.html
diff --git a/drivers/gpu/drm/ati_pcigart.c b/drivers/gpu/drm/ati_pcigart.c
new file mode 100644 (file)
index 0000000..c533d0c
--- /dev/null
@@ -0,0 +1,181 @@
+/**
+ * \file ati_pcigart.c
+ * ATI PCI GART support
+ *
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
+ *
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+# define ATI_PCIGART_PAGE_SIZE         4096    /**< PCI GART page size */
+
+static int drm_ati_alloc_pcigart_table(struct drm_device *dev,
+                                      struct drm_ati_pcigart_info *gart_info)
+{
+       gart_info->table_handle = drm_pci_alloc(dev, gart_info->table_size,
+                                               PAGE_SIZE,
+                                               gart_info->table_mask);
+       if (gart_info->table_handle == NULL)
+               return -ENOMEM;
+
+       return 0;
+}
+
+static void drm_ati_free_pcigart_table(struct drm_device *dev,
+                                      struct drm_ati_pcigart_info *gart_info)
+{
+       drm_pci_free(dev, gart_info->table_handle);
+       gart_info->table_handle = NULL;
+}
+
+int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
+{
+       struct drm_sg_mem *entry = dev->sg;
+       unsigned long pages;
+       int i;
+       int max_pages;
+
+       /* we need to support large memory configurations */
+       if (!entry) {
+               DRM_ERROR("no scatter/gather memory!\n");
+               return 0;
+       }
+
+       if (gart_info->bus_addr) {
+
+               max_pages = (gart_info->table_size / sizeof(u32));
+               pages = (entry->pages <= max_pages)
+                 ? entry->pages : max_pages;
+
+               for (i = 0; i < pages; i++) {
+                       if (!entry->busaddr[i])
+                               break;
+                       pci_unmap_page(dev->pdev, entry->busaddr[i],
+                                        PAGE_SIZE, PCI_DMA_TODEVICE);
+               }
+
+               if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
+                       gart_info->bus_addr = 0;
+       }
+
+       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN &&
+           gart_info->table_handle) {
+               drm_ati_free_pcigart_table(dev, gart_info);
+       }
+
+       return 1;
+}
+EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
+
+int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
+{
+       struct drm_sg_mem *entry = dev->sg;
+       void *address = NULL;
+       unsigned long pages;
+       u32 *pci_gart, page_base;
+       dma_addr_t bus_address = 0;
+       int i, j, ret = 0;
+       int max_pages;
+
+       if (!entry) {
+               DRM_ERROR("no scatter/gather memory!\n");
+               goto done;
+       }
+
+       if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
+               DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
+
+               ret = drm_ati_alloc_pcigart_table(dev, gart_info);
+               if (ret) {
+                       DRM_ERROR("cannot allocate PCI GART page!\n");
+                       goto done;
+               }
+
+               address = gart_info->table_handle->vaddr;
+               bus_address = gart_info->table_handle->busaddr;
+       } else {
+               address = gart_info->addr;
+               bus_address = gart_info->bus_addr;
+               DRM_DEBUG("PCI: Gart Table: VRAM %08LX mapped at %08lX\n",
+                         (unsigned long long)bus_address,
+                         (unsigned long)address);
+       }
+
+       pci_gart = (u32 *) address;
+
+       max_pages = (gart_info->table_size / sizeof(u32));
+       pages = (entry->pages <= max_pages)
+           ? entry->pages : max_pages;
+
+       memset(pci_gart, 0, max_pages * sizeof(u32));
+
+       for (i = 0; i < pages; i++) {
+               /* we need to support large memory configurations */
+               entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i],
+                                                0, PAGE_SIZE, PCI_DMA_TODEVICE);
+               if (entry->busaddr[i] == 0) {
+                       DRM_ERROR("unable to map PCIGART pages!\n");
+                       drm_ati_pcigart_cleanup(dev, gart_info);
+                       address = NULL;
+                       bus_address = 0;
+                       goto done;
+               }
+               page_base = (u32) entry->busaddr[i];
+
+               for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
+                       switch(gart_info->gart_reg_if) {
+                       case DRM_ATI_GART_IGP:
+                               *pci_gart = cpu_to_le32((page_base) | 0xc);
+                               break;
+                       case DRM_ATI_GART_PCIE:
+                               *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
+                               break;
+                       default:
+                       case DRM_ATI_GART_PCI:
+                               *pci_gart = cpu_to_le32(page_base);
+                               break;
+                       }
+                       pci_gart++;
+                       page_base += ATI_PCIGART_PAGE_SIZE;
+               }
+       }
+       ret = 1;
+
+#if defined(__i386__) || defined(__x86_64__)
+       wbinvd();
+#else
+       mb();
+#endif
+
+      done:
+       gart_info->addr = address;
+       gart_info->bus_addr = bus_address;
+       return ret;
+}
+EXPORT_SYMBOL(drm_ati_pcigart_init);
diff --git a/drivers/gpu/drm/drm_agpsupport.c b/drivers/gpu/drm/drm_agpsupport.c
new file mode 100644 (file)
index 0000000..aefa5ac
--- /dev/null
@@ -0,0 +1,455 @@
+/**
+ * \file drm_agpsupport.c
+ * DRM support for AGP/GART backend
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include <linux/module.h>
+
+#if __OS_HAS_AGP
+
+/**
+ * Get AGP information.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a (output) drm_agp_info structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device has been initialized and acquired and fills in the
+ * drm_agp_info structure with the information in drm_agp_head::agp_info.
+ */
+int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info)
+{
+       DRM_AGP_KERN *kern;
+
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+
+       kern = &dev->agp->agp_info;
+       info->agp_version_major = kern->version.major;
+       info->agp_version_minor = kern->version.minor;
+       info->mode = kern->mode;
+       info->aperture_base = kern->aper_base;
+       info->aperture_size = kern->aper_size * 1024 * 1024;
+       info->memory_allowed = kern->max_memory << PAGE_SHIFT;
+       info->memory_used = kern->current_memory << PAGE_SHIFT;
+       info->id_vendor = kern->device->vendor;
+       info->id_device = kern->device->device;
+
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_agp_info);
+
+int drm_agp_info_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_agp_info *info = data;
+       int err;
+
+       err = drm_agp_info(dev, info);
+       if (err)
+               return err;
+
+       return 0;
+}
+
+/**
+ * Acquire the AGP device.
+ *
+ * \param dev DRM device that is to acquire AGP.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device hasn't been acquired before and calls
+ * \c agp_backend_acquire.
+ */
+int drm_agp_acquire(struct drm_device * dev)
+{
+       if (!dev->agp)
+               return -ENODEV;
+       if (dev->agp->acquired)
+               return -EBUSY;
+       if (!(dev->agp->bridge = agp_backend_acquire(dev->pdev)))
+               return -ENODEV;
+       dev->agp->acquired = 1;
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_agp_acquire);
+
+/**
+ * Acquire the AGP device (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device hasn't been acquired before and calls
+ * \c agp_backend_acquire.
+ */
+int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       return drm_agp_acquire((struct drm_device *) file_priv->minor->dev);
+}
+
+/**
+ * Release the AGP device.
+ *
+ * \param dev DRM device that is to release AGP.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device has been acquired and calls \c agp_backend_release.
+ */
+int drm_agp_release(struct drm_device * dev)
+{
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+       agp_backend_release(dev->agp->bridge);
+       dev->agp->acquired = 0;
+       return 0;
+}
+EXPORT_SYMBOL(drm_agp_release);
+
+int drm_agp_release_ioctl(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       return drm_agp_release(dev);
+}
+
+/**
+ * Enable the AGP bus.
+ *
+ * \param dev DRM device that has previously acquired AGP.
+ * \param mode Requested AGP mode.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device has been acquired but not enabled, and calls
+ * \c agp_enable.
+ */
+int drm_agp_enable(struct drm_device * dev, struct drm_agp_mode mode)
+{
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+
+       dev->agp->mode = mode.mode;
+       agp_enable(dev->agp->bridge, mode.mode);
+       dev->agp->enabled = 1;
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_agp_enable);
+
+int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       struct drm_agp_mode *mode = data;
+
+       return drm_agp_enable(dev, *mode);
+}
+
+/**
+ * Allocate AGP memory.
+ *
+ * \param inode device inode.
+ * \param file_priv file private pointer.
+ * \param cmd command.
+ * \param arg pointer to a drm_agp_buffer structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device is present and has been acquired, allocates the
+ * memory via alloc_agp() and creates a drm_agp_mem entry for it.
+ */
+int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request)
+{
+       struct drm_agp_mem *entry;
+       DRM_AGP_MEM *memory;
+       unsigned long pages;
+       u32 type;
+
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+       if (!(entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS)))
+               return -ENOMEM;
+
+       memset(entry, 0, sizeof(*entry));
+
+       pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
+       type = (u32) request->type;
+       if (!(memory = drm_alloc_agp(dev, pages, type))) {
+               drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
+               return -ENOMEM;
+       }
+
+       entry->handle = (unsigned long)memory->key + 1;
+       entry->memory = memory;
+       entry->bound = 0;
+       entry->pages = pages;
+       list_add(&entry->head, &dev->agp->memory);
+
+       request->handle = entry->handle;
+       request->physical = memory->physical;
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_agp_alloc);
+
+
+int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       struct drm_agp_buffer *request = data;
+
+       return drm_agp_alloc(dev, request);
+}
+
+/**
+ * Search for the AGP memory entry associated with a handle.
+ *
+ * \param dev DRM device structure.
+ * \param handle AGP memory handle.
+ * \return pointer to the drm_agp_mem structure associated with \p handle.
+ *
+ * Walks through drm_agp_head::memory until finding a matching handle.
+ */
+static struct drm_agp_mem *drm_agp_lookup_entry(struct drm_device * dev,
+                                          unsigned long handle)
+{
+       struct drm_agp_mem *entry;
+
+       list_for_each_entry(entry, &dev->agp->memory, head) {
+               if (entry->handle == handle)
+                       return entry;
+       }
+       return NULL;
+}
+
+/**
+ * Unbind AGP memory from the GATT (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_agp_binding structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device is present and acquired, looks-up the AGP memory
+ * entry and passes it to the unbind_agp() function.
+ */
+int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request)
+{
+       struct drm_agp_mem *entry;
+       int ret;
+
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
+               return -EINVAL;
+       if (!entry->bound)
+               return -EINVAL;
+       ret = drm_unbind_agp(entry->memory);
+       if (ret == 0)
+               entry->bound = 0;
+       return ret;
+}
+EXPORT_SYMBOL(drm_agp_unbind);
+
+
+int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       struct drm_agp_binding *request = data;
+
+       return drm_agp_unbind(dev, request);
+}
+
+/**
+ * Bind AGP memory into the GATT (ioctl)
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_agp_binding structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device is present and has been acquired and that no memory
+ * is currently bound into the GATT. Looks-up the AGP memory entry and passes
+ * it to bind_agp() function.
+ */
+int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request)
+{
+       struct drm_agp_mem *entry;
+       int retcode;
+       int page;
+
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
+               return -EINVAL;
+       if (entry->bound)
+               return -EINVAL;
+       page = (request->offset + PAGE_SIZE - 1) / PAGE_SIZE;
+       if ((retcode = drm_bind_agp(entry->memory, page)))
+               return retcode;
+       entry->bound = dev->agp->base + (page << PAGE_SHIFT);
+       DRM_DEBUG("base = 0x%lx entry->bound = 0x%lx\n",
+                 dev->agp->base, entry->bound);
+       return 0;
+}
+EXPORT_SYMBOL(drm_agp_bind);
+
+
+int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_agp_binding *request = data;
+
+       return drm_agp_bind(dev, request);
+}
+
+/**
+ * Free AGP memory (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_agp_buffer structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the AGP device is present and has been acquired and looks up the
+ * AGP memory entry. If the memory it's currently bound, unbind it via
+ * unbind_agp(). Frees it via free_agp() as well as the entry itself
+ * and unlinks from the doubly linked list it's inserted in.
+ */
+int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request)
+{
+       struct drm_agp_mem *entry;
+
+       if (!dev->agp || !dev->agp->acquired)
+               return -EINVAL;
+       if (!(entry = drm_agp_lookup_entry(dev, request->handle)))
+               return -EINVAL;
+       if (entry->bound)
+               drm_unbind_agp(entry->memory);
+
+       list_del(&entry->head);
+
+       drm_free_agp(entry->memory, entry->pages);
+       drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
+       return 0;
+}
+EXPORT_SYMBOL(drm_agp_free);
+
+
+
+int drm_agp_free_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_agp_buffer *request = data;
+
+       return drm_agp_free(dev, request);
+}
+
+/**
+ * Initialize the AGP resources.
+ *
+ * \return pointer to a drm_agp_head structure.
+ *
+ * Gets the drm_agp_t structure which is made available by the agpgart module
+ * via the inter_module_* functions. Creates and initializes a drm_agp_head
+ * structure.
+ */
+struct drm_agp_head *drm_agp_init(struct drm_device *dev)
+{
+       struct drm_agp_head *head = NULL;
+
+       if (!(head = drm_alloc(sizeof(*head), DRM_MEM_AGPLISTS)))
+               return NULL;
+       memset((void *)head, 0, sizeof(*head));
+       head->bridge = agp_find_bridge(dev->pdev);
+       if (!head->bridge) {
+               if (!(head->bridge = agp_backend_acquire(dev->pdev))) {
+                       drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
+                       return NULL;
+               }
+               agp_copy_info(head->bridge, &head->agp_info);
+               agp_backend_release(head->bridge);
+       } else {
+               agp_copy_info(head->bridge, &head->agp_info);
+       }
+       if (head->agp_info.chipset == NOT_SUPPORTED) {
+               drm_free(head, sizeof(*head), DRM_MEM_AGPLISTS);
+               return NULL;
+       }
+       INIT_LIST_HEAD(&head->memory);
+       head->cant_use_aperture = head->agp_info.cant_use_aperture;
+       head->page_mask = head->agp_info.page_mask;
+       head->base = head->agp_info.aper_base;
+       return head;
+}
+
+/** Calls agp_allocate_memory() */
+DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data * bridge,
+                                    size_t pages, u32 type)
+{
+       return agp_allocate_memory(bridge, pages, type);
+}
+
+/** Calls agp_free_memory() */
+int drm_agp_free_memory(DRM_AGP_MEM * handle)
+{
+       if (!handle)
+               return 0;
+       agp_free_memory(handle);
+       return 1;
+}
+
+/** Calls agp_bind_memory() */
+int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start)
+{
+       if (!handle)
+               return -EINVAL;
+       return agp_bind_memory(handle, start);
+}
+
+/** Calls agp_unbind_memory() */
+int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
+{
+       if (!handle)
+               return -EINVAL;
+       return agp_unbind_memory(handle);
+}
+
+#endif                         /* __OS_HAS_AGP */
diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
new file mode 100644 (file)
index 0000000..a734627
--- /dev/null
@@ -0,0 +1,190 @@
+/**
+ * \file drm_auth.c
+ * IOCTLs for authentication
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+/**
+ * Find the file with the given magic number.
+ *
+ * \param dev DRM device.
+ * \param magic magic number.
+ *
+ * Searches in drm_device::magiclist within all files with the same hash key
+ * the one with matching magic number, while holding the drm_device::struct_mutex
+ * lock.
+ */
+static struct drm_file *drm_find_file(struct drm_device * dev, drm_magic_t magic)
+{
+       struct drm_file *retval = NULL;
+       struct drm_magic_entry *pt;
+       struct drm_hash_item *hash;
+
+       mutex_lock(&dev->struct_mutex);
+       if (!drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
+               pt = drm_hash_entry(hash, struct drm_magic_entry, hash_item);
+               retval = pt->priv;
+       }
+       mutex_unlock(&dev->struct_mutex);
+       return retval;
+}
+
+/**
+ * Adds a magic number.
+ *
+ * \param dev DRM device.
+ * \param priv file private data.
+ * \param magic magic number.
+ *
+ * Creates a drm_magic_entry structure and appends to the linked list
+ * associated the magic number hash key in drm_device::magiclist, while holding
+ * the drm_device::struct_mutex lock.
+ */
+static int drm_add_magic(struct drm_device * dev, struct drm_file * priv,
+                        drm_magic_t magic)
+{
+       struct drm_magic_entry *entry;
+
+       DRM_DEBUG("%d\n", magic);
+
+       entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC);
+       if (!entry)
+               return -ENOMEM;
+       memset(entry, 0, sizeof(*entry));
+       entry->priv = priv;
+
+       entry->hash_item.key = (unsigned long)magic;
+       mutex_lock(&dev->struct_mutex);
+       drm_ht_insert_item(&dev->magiclist, &entry->hash_item);
+       list_add_tail(&entry->head, &dev->magicfree);
+       mutex_unlock(&dev->struct_mutex);
+
+       return 0;
+}
+
+/**
+ * Remove a magic number.
+ *
+ * \param dev DRM device.
+ * \param magic magic number.
+ *
+ * Searches and unlinks the entry in drm_device::magiclist with the magic
+ * number hash key, while holding the drm_device::struct_mutex lock.
+ */
+static int drm_remove_magic(struct drm_device * dev, drm_magic_t magic)
+{
+       struct drm_magic_entry *pt;
+       struct drm_hash_item *hash;
+
+       DRM_DEBUG("%d\n", magic);
+
+       mutex_lock(&dev->struct_mutex);
+       if (drm_ht_find_item(&dev->magiclist, (unsigned long)magic, &hash)) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+       pt = drm_hash_entry(hash, struct drm_magic_entry, hash_item);
+       drm_ht_remove_item(&dev->magiclist, hash);
+       list_del(&pt->head);
+       mutex_unlock(&dev->struct_mutex);
+
+       drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
+
+       return 0;
+}
+
+/**
+ * Get a unique magic number (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a resulting drm_auth structure.
+ * \return zero on success, or a negative number on failure.
+ *
+ * If there is a magic number in drm_file::magic then use it, otherwise
+ * searches an unique non-zero magic number and add it associating it with \p
+ * file_priv.
+ */
+int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       static drm_magic_t sequence = 0;
+       static DEFINE_SPINLOCK(lock);
+       struct drm_auth *auth = data;
+
+       /* Find unique magic */
+       if (file_priv->magic) {
+               auth->magic = file_priv->magic;
+       } else {
+               do {
+                       spin_lock(&lock);
+                       if (!sequence)
+                               ++sequence;     /* reserve 0 */
+                       auth->magic = sequence++;
+                       spin_unlock(&lock);
+               } while (drm_find_file(dev, auth->magic));
+               file_priv->magic = auth->magic;
+               drm_add_magic(dev, file_priv, auth->magic);
+       }
+
+       DRM_DEBUG("%u\n", auth->magic);
+
+       return 0;
+}
+
+/**
+ * Authenticate with a magic.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_auth structure.
+ * \return zero if authentication successed, or a negative number otherwise.
+ *
+ * Checks if \p file_priv is associated with the magic number passed in \arg.
+ */
+int drm_authmagic(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       struct drm_auth *auth = data;
+       struct drm_file *file;
+
+       DRM_DEBUG("%u\n", auth->magic);
+       if ((file = drm_find_file(dev, auth->magic))) {
+               file->authenticated = 1;
+               drm_remove_magic(dev, auth->magic);
+               return 0;
+       }
+       return -EINVAL;
+}
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
new file mode 100644 (file)
index 0000000..bde64b8
--- /dev/null
@@ -0,0 +1,1601 @@
+/**
+ * \file drm_bufs.c
+ * Generic buffer template
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/vmalloc.h>
+#include "drmP.h"
+
+unsigned long drm_get_resource_start(struct drm_device *dev, unsigned int resource)
+{
+       return pci_resource_start(dev->pdev, resource);
+}
+EXPORT_SYMBOL(drm_get_resource_start);
+
+unsigned long drm_get_resource_len(struct drm_device *dev, unsigned int resource)
+{
+       return pci_resource_len(dev->pdev, resource);
+}
+
+EXPORT_SYMBOL(drm_get_resource_len);
+
+static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
+                                            drm_local_map_t *map)
+{
+       struct drm_map_list *entry;
+       list_for_each_entry(entry, &dev->maplist, head) {
+               if (entry->map && map->type == entry->map->type &&
+                   ((entry->map->offset == map->offset) ||
+                    (map->type == _DRM_SHM && map->flags==_DRM_CONTAINS_LOCK))) {
+                       return entry;
+               }
+       }
+
+       return NULL;
+}
+
+static int drm_map_handle(struct drm_device *dev, struct drm_hash_item *hash,
+                         unsigned long user_token, int hashed_handle)
+{
+       int use_hashed_handle;
+#if (BITS_PER_LONG == 64)
+       use_hashed_handle = ((user_token & 0xFFFFFFFF00000000UL) || hashed_handle);
+#elif (BITS_PER_LONG == 32)
+       use_hashed_handle = hashed_handle;
+#else
+#error Unsupported long size. Neither 64 nor 32 bits.
+#endif
+
+       if (!use_hashed_handle) {
+               int ret;
+               hash->key = user_token >> PAGE_SHIFT;
+               ret = drm_ht_insert_item(&dev->map_hash, hash);
+               if (ret != -EINVAL)
+                       return ret;
+       }
+       return drm_ht_just_insert_please(&dev->map_hash, hash,
+                                        user_token, 32 - PAGE_SHIFT - 3,
+                                        0, DRM_MAP_HASH_OFFSET >> PAGE_SHIFT);
+}
+
+/**
+ * Ioctl to specify a range of memory that is available for mapping by a non-root process.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_map structure.
+ * \return zero on success or a negative value on error.
+ *
+ * Adjusts the memory offset to its absolute value according to the mapping
+ * type.  Adds the map to the map list drm_device::maplist. Adds MTRR's where
+ * applicable and if supported by the kernel.
+ */
+static int drm_addmap_core(struct drm_device * dev, unsigned int offset,
+                          unsigned int size, enum drm_map_type type,
+                          enum drm_map_flags flags,
+                          struct drm_map_list ** maplist)
+{
+       struct drm_map *map;
+       struct drm_map_list *list;
+       drm_dma_handle_t *dmah;
+       unsigned long user_token;
+       int ret;
+
+       map = drm_alloc(sizeof(*map), DRM_MEM_MAPS);
+       if (!map)
+               return -ENOMEM;
+
+       map->offset = offset;
+       map->size = size;
+       map->flags = flags;
+       map->type = type;
+
+       /* Only allow shared memory to be removable since we only keep enough
+        * book keeping information about shared memory to allow for removal
+        * when processes fork.
+        */
+       if ((map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM) {
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               return -EINVAL;
+       }
+       DRM_DEBUG("offset = 0x%08lx, size = 0x%08lx, type = %d\n",
+                 map->offset, map->size, map->type);
+       if ((map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK))) {
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               return -EINVAL;
+       }
+       map->mtrr = -1;
+       map->handle = NULL;
+
+       switch (map->type) {
+       case _DRM_REGISTERS:
+       case _DRM_FRAME_BUFFER:
+#if !defined(__sparc__) && !defined(__alpha__) && !defined(__ia64__) && !defined(__powerpc64__) && !defined(__x86_64__)
+               if (map->offset + (map->size-1) < map->offset ||
+                   map->offset < virt_to_phys(high_memory)) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -EINVAL;
+               }
+#endif
+#ifdef __alpha__
+               map->offset += dev->hose->mem_space->start;
+#endif
+               /* Some drivers preinitialize some maps, without the X Server
+                * needing to be aware of it.  Therefore, we just return success
+                * when the server tries to create a duplicate map.
+                */
+               list = drm_find_matching_map(dev, map);
+               if (list != NULL) {
+                       if (list->map->size != map->size) {
+                               DRM_DEBUG("Matching maps of type %d with "
+                                         "mismatched sizes, (%ld vs %ld)\n",
+                                         map->type, map->size,
+                                         list->map->size);
+                               list->map->size = map->size;
+                       }
+
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       *maplist = list;
+                       return 0;
+               }
+
+               if (drm_core_has_MTRR(dev)) {
+                       if (map->type == _DRM_FRAME_BUFFER ||
+                           (map->flags & _DRM_WRITE_COMBINING)) {
+                               map->mtrr = mtrr_add(map->offset, map->size,
+                                                    MTRR_TYPE_WRCOMB, 1);
+                       }
+               }
+               if (map->type == _DRM_REGISTERS) {
+                       map->handle = ioremap(map->offset, map->size);
+                       if (!map->handle) {
+                               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                               return -ENOMEM;
+                       }
+               }
+
+               break;
+       case _DRM_SHM:
+               list = drm_find_matching_map(dev, map);
+               if (list != NULL) {
+                       if(list->map->size != map->size) {
+                               DRM_DEBUG("Matching maps of type %d with "
+                                         "mismatched sizes, (%ld vs %ld)\n",
+                                         map->type, map->size, list->map->size);
+                               list->map->size = map->size;
+                       }
+
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       *maplist = list;
+                       return 0;
+               }
+               map->handle = vmalloc_user(map->size);
+               DRM_DEBUG("%lu %d %p\n",
+                         map->size, drm_order(map->size), map->handle);
+               if (!map->handle) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -ENOMEM;
+               }
+               map->offset = (unsigned long)map->handle;
+               if (map->flags & _DRM_CONTAINS_LOCK) {
+                       /* Prevent a 2nd X Server from creating a 2nd lock */
+                       if (dev->lock.hw_lock != NULL) {
+                               vfree(map->handle);
+                               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                               return -EBUSY;
+                       }
+                       dev->sigdata.lock = dev->lock.hw_lock = map->handle;    /* Pointer to lock */
+               }
+               break;
+       case _DRM_AGP: {
+               struct drm_agp_mem *entry;
+               int valid = 0;
+
+               if (!drm_core_has_AGP(dev)) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -EINVAL;
+               }
+#ifdef __alpha__
+               map->offset += dev->hose->mem_space->start;
+#endif
+               /* In some cases (i810 driver), user space may have already
+                * added the AGP base itself, because dev->agp->base previously
+                * only got set during AGP enable.  So, only add the base
+                * address if the map's offset isn't already within the
+                * aperture.
+                */
+               if (map->offset < dev->agp->base ||
+                   map->offset > dev->agp->base +
+                   dev->agp->agp_info.aper_size * 1024 * 1024 - 1) {
+                       map->offset += dev->agp->base;
+               }
+               map->mtrr = dev->agp->agp_mtrr; /* for getmap */
+
+               /* This assumes the DRM is in total control of AGP space.
+                * It's not always the case as AGP can be in the control
+                * of user space (i.e. i810 driver). So this loop will get
+                * skipped and we double check that dev->agp->memory is
+                * actually set as well as being invalid before EPERM'ing
+                */
+               list_for_each_entry(entry, &dev->agp->memory, head) {
+                       if ((map->offset >= entry->bound) &&
+                           (map->offset + map->size <= entry->bound + entry->pages * PAGE_SIZE)) {
+                               valid = 1;
+                               break;
+                       }
+               }
+               if (!list_empty(&dev->agp->memory) && !valid) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -EPERM;
+               }
+               DRM_DEBUG("AGP offset = 0x%08lx, size = 0x%08lx\n", map->offset, map->size);
+
+               break;
+       }
+       case _DRM_SCATTER_GATHER:
+               if (!dev->sg) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -EINVAL;
+               }
+               map->offset += (unsigned long)dev->sg->virtual;
+               break;
+       case _DRM_CONSISTENT:
+               /* dma_addr_t is 64bit on i386 with CONFIG_HIGHMEM64G,
+                * As we're limiting the address to 2^32-1 (or less),
+                * casting it down to 32 bits is no problem, but we
+                * need to point to a 64bit variable first. */
+               dmah = drm_pci_alloc(dev, map->size, map->size, 0xffffffffUL);
+               if (!dmah) {
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+                       return -ENOMEM;
+               }
+               map->handle = dmah->vaddr;
+               map->offset = (unsigned long)dmah->busaddr;
+               kfree(dmah);
+               break;
+       default:
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               return -EINVAL;
+       }
+
+       list = drm_alloc(sizeof(*list), DRM_MEM_MAPS);
+       if (!list) {
+               if (map->type == _DRM_REGISTERS)
+                       iounmap(map->handle);
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               return -EINVAL;
+       }
+       memset(list, 0, sizeof(*list));
+       list->map = map;
+
+       mutex_lock(&dev->struct_mutex);
+       list_add(&list->head, &dev->maplist);
+
+       /* Assign a 32-bit handle */
+       /* We do it here so that dev->struct_mutex protects the increment */
+       user_token = (map->type == _DRM_SHM) ? (unsigned long)map->handle :
+               map->offset;
+       ret = drm_map_handle(dev, &list->hash, user_token, 0);
+       if (ret) {
+               if (map->type == _DRM_REGISTERS)
+                       iounmap(map->handle);
+               drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               drm_free(list, sizeof(*list), DRM_MEM_MAPS);
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       list->user_token = list->hash.key << PAGE_SHIFT;
+       mutex_unlock(&dev->struct_mutex);
+
+       *maplist = list;
+       return 0;
+       }
+
+int drm_addmap(struct drm_device * dev, unsigned int offset,
+              unsigned int size, enum drm_map_type type,
+              enum drm_map_flags flags, drm_local_map_t ** map_ptr)
+{
+       struct drm_map_list *list;
+       int rc;
+
+       rc = drm_addmap_core(dev, offset, size, type, flags, &list);
+       if (!rc)
+               *map_ptr = list->map;
+       return rc;
+}
+
+EXPORT_SYMBOL(drm_addmap);
+
+int drm_addmap_ioctl(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv)
+{
+       struct drm_map *map = data;
+       struct drm_map_list *maplist;
+       int err;
+
+       if (!(capable(CAP_SYS_ADMIN) || map->type == _DRM_AGP))
+               return -EPERM;
+
+       err = drm_addmap_core(dev, map->offset, map->size, map->type,
+                             map->flags, &maplist);
+
+       if (err)
+               return err;
+
+       /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */
+       map->handle = (void *)(unsigned long)maplist->user_token;
+       return 0;
+}
+
+/**
+ * Remove a map private from list and deallocate resources if the mapping
+ * isn't in use.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a struct drm_map structure.
+ * \return zero on success or a negative value on error.
+ *
+ * Searches the map on drm_device::maplist, removes it from the list, see if
+ * its being used, and free any associate resource (such as MTRR's) if it's not
+ * being on use.
+ *
+ * \sa drm_addmap
+ */
+int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map)
+{
+       struct drm_map_list *r_list = NULL, *list_t;
+       drm_dma_handle_t dmah;
+       int found = 0;
+
+       /* Find the list entry for the map and remove it */
+       list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) {
+               if (r_list->map == map) {
+                       list_del(&r_list->head);
+                       drm_ht_remove_key(&dev->map_hash,
+                                         r_list->user_token >> PAGE_SHIFT);
+                       drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS);
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found)
+               return -EINVAL;
+
+       switch (map->type) {
+       case _DRM_REGISTERS:
+               iounmap(map->handle);
+               /* FALLTHROUGH */
+       case _DRM_FRAME_BUFFER:
+               if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
+                       int retcode;
+                       retcode = mtrr_del(map->mtrr, map->offset, map->size);
+                       DRM_DEBUG("mtrr_del=%d\n", retcode);
+               }
+               break;
+       case _DRM_SHM:
+               vfree(map->handle);
+               break;
+       case _DRM_AGP:
+       case _DRM_SCATTER_GATHER:
+               break;
+       case _DRM_CONSISTENT:
+               dmah.vaddr = map->handle;
+               dmah.busaddr = map->offset;
+               dmah.size = map->size;
+               __drm_pci_free(dev, &dmah);
+               break;
+       }
+       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+
+       return 0;
+}
+
+int drm_rmmap(struct drm_device *dev, drm_local_map_t *map)
+{
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_rmmap_locked(dev, map);
+       mutex_unlock(&dev->struct_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL(drm_rmmap);
+
+/* The rmmap ioctl appears to be unnecessary.  All mappings are torn down on
+ * the last close of the device, and this is necessary for cleanup when things
+ * exit uncleanly.  Therefore, having userland manually remove mappings seems
+ * like a pointless exercise since they're going away anyway.
+ *
+ * One use case might be after addmap is allowed for normal users for SHM and
+ * gets used by drivers that the server doesn't need to care about.  This seems
+ * unlikely.
+ */
+int drm_rmmap_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_map *request = data;
+       drm_local_map_t *map = NULL;
+       struct drm_map_list *r_list;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               if (r_list->map &&
+                   r_list->user_token == (unsigned long)request->handle &&
+                   r_list->map->flags & _DRM_REMOVABLE) {
+                       map = r_list->map;
+                       break;
+               }
+       }
+
+       /* List has wrapped around to the head pointer, or its empty we didn't
+        * find anything.
+        */
+       if (list_empty(&dev->maplist) || !map) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       /* Register and framebuffer maps are permanent */
+       if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) {
+               mutex_unlock(&dev->struct_mutex);
+               return 0;
+       }
+
+       ret = drm_rmmap_locked(dev, map);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       return ret;
+}
+
+/**
+ * Cleanup after an error on one of the addbufs() functions.
+ *
+ * \param dev DRM device.
+ * \param entry buffer entry where the error occurred.
+ *
+ * Frees any pages and buffers associated with the given entry.
+ */
+static void drm_cleanup_buf_error(struct drm_device * dev,
+                                 struct drm_buf_entry * entry)
+{
+       int i;
+
+       if (entry->seg_count) {
+               for (i = 0; i < entry->seg_count; i++) {
+                       if (entry->seglist[i]) {
+                               drm_pci_free(dev, entry->seglist[i]);
+                       }
+               }
+               drm_free(entry->seglist,
+                        entry->seg_count *
+                        sizeof(*entry->seglist), DRM_MEM_SEGS);
+
+               entry->seg_count = 0;
+       }
+
+       if (entry->buf_count) {
+               for (i = 0; i < entry->buf_count; i++) {
+                       if (entry->buflist[i].dev_private) {
+                               drm_free(entry->buflist[i].dev_private,
+                                        entry->buflist[i].dev_priv_size,
+                                        DRM_MEM_BUFS);
+                       }
+               }
+               drm_free(entry->buflist,
+                        entry->buf_count *
+                        sizeof(*entry->buflist), DRM_MEM_BUFS);
+
+               entry->buf_count = 0;
+       }
+}
+
+#if __OS_HAS_AGP
+/**
+ * Add AGP buffers for DMA transfers.
+ *
+ * \param dev struct drm_device to which the buffers are to be added.
+ * \param request pointer to a struct drm_buf_desc describing the request.
+ * \return zero on success or a negative number on failure.
+ *
+ * After some sanity checks creates a drm_buf structure for each buffer and
+ * reallocates the buffer list of the same size order to accommodate the new
+ * buffers.
+ */
+int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_entry *entry;
+       struct drm_agp_mem *agp_entry;
+       struct drm_buf *buf;
+       unsigned long offset;
+       unsigned long agp_offset;
+       int count;
+       int order;
+       int size;
+       int alignment;
+       int page_order;
+       int total;
+       int byte_count;
+       int i, valid;
+       struct drm_buf **temp_buflist;
+
+       if (!dma)
+               return -EINVAL;
+
+       count = request->count;
+       order = drm_order(request->size);
+       size = 1 << order;
+
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
+       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
+       total = PAGE_SIZE << page_order;
+
+       byte_count = 0;
+       agp_offset = dev->agp->base + request->agp_start;
+
+       DRM_DEBUG("count:      %d\n", count);
+       DRM_DEBUG("order:      %d\n", order);
+       DRM_DEBUG("size:       %d\n", size);
+       DRM_DEBUG("agp_offset: %lx\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n", alignment);
+       DRM_DEBUG("page_order: %d\n", page_order);
+       DRM_DEBUG("total:      %d\n", total);
+
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
+
+       /* Make sure buffers are located in AGP memory that we own */
+       valid = 0;
+       list_for_each_entry(agp_entry, &dev->agp->memory, head) {
+               if ((agp_offset >= agp_entry->bound) &&
+                   (agp_offset + total * count <= agp_entry->bound + agp_entry->pages * PAGE_SIZE)) {
+                       valid = 1;
+                       break;
+               }
+       }
+       if (!list_empty(&dev->agp->memory) && !valid) {
+               DRM_DEBUG("zone invalid\n");
+               return -EINVAL;
+       }
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
+
+       mutex_lock(&dev->struct_mutex);
+       entry = &dma->bufs[order];
+       if (entry->buf_count) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
+       }
+
+       if (count < 0 || count > 4096) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -EINVAL;
+       }
+
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+       entry->buf_size = size;
+       entry->page_order = page_order;
+
+       offset = 0;
+
+       while (entry->buf_count < count) {
+               buf = &entry->buflist[entry->buf_count];
+               buf->idx = dma->buf_count + entry->buf_count;
+               buf->total = alignment;
+               buf->order = order;
+               buf->used = 0;
+
+               buf->offset = (dma->byte_count + offset);
+               buf->bus_address = agp_offset + offset;
+               buf->address = (void *)(agp_offset + offset);
+               buf->next = NULL;
+               buf->waiting = 0;
+               buf->pending = 0;
+               init_waitqueue_head(&buf->dma_wait);
+               buf->file_priv = NULL;
+
+               buf->dev_priv_size = dev->driver->dev_priv_size;
+               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+               if (!buf->dev_private) {
+                       /* Set count correctly so we free the proper amount. */
+                       entry->buf_count = count;
+                       drm_cleanup_buf_error(dev, entry);
+                       mutex_unlock(&dev->struct_mutex);
+                       atomic_dec(&dev->buf_alloc);
+                       return -ENOMEM;
+               }
+               memset(buf->dev_private, 0, buf->dev_priv_size);
+
+               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
+
+               offset += alignment;
+               entry->buf_count++;
+               byte_count += PAGE_SIZE << page_order;
+       }
+
+       DRM_DEBUG("byte_count: %d\n", byte_count);
+
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
+               /* Free the entry because it isn't valid */
+               drm_cleanup_buf_error(dev, entry);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       dma->buflist = temp_buflist;
+
+       for (i = 0; i < entry->buf_count; i++) {
+               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
+       }
+
+       dma->buf_count += entry->buf_count;
+       dma->seg_count += entry->seg_count;
+       dma->page_count += byte_count >> PAGE_SHIFT;
+       dma->byte_count += byte_count;
+
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       request->count = entry->buf_count;
+       request->size = size;
+
+       dma->flags = _DRM_DMA_USE_AGP;
+
+       atomic_dec(&dev->buf_alloc);
+       return 0;
+}
+EXPORT_SYMBOL(drm_addbufs_agp);
+#endif                         /* __OS_HAS_AGP */
+
+int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int count;
+       int order;
+       int size;
+       int total;
+       int page_order;
+       struct drm_buf_entry *entry;
+       drm_dma_handle_t *dmah;
+       struct drm_buf *buf;
+       int alignment;
+       unsigned long offset;
+       int i;
+       int byte_count;
+       int page_count;
+       unsigned long *temp_pagelist;
+       struct drm_buf **temp_buflist;
+
+       if (!drm_core_check_feature(dev, DRIVER_PCI_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       count = request->count;
+       order = drm_order(request->size);
+       size = 1 << order;
+
+       DRM_DEBUG("count=%d, size=%d (%d), order=%d, queue_count=%d\n",
+                 request->count, request->size, size, order, dev->queue_count);
+
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
+
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
+       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
+       total = PAGE_SIZE << page_order;
+
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
+
+       mutex_lock(&dev->struct_mutex);
+       entry = &dma->bufs[order];
+       if (entry->buf_count) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
+       }
+
+       if (count < 0 || count > 4096) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -EINVAL;
+       }
+
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+       entry->seglist = drm_alloc(count * sizeof(*entry->seglist),
+                                  DRM_MEM_SEGS);
+       if (!entry->seglist) {
+               drm_free(entry->buflist,
+                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memset(entry->seglist, 0, count * sizeof(*entry->seglist));
+
+       /* Keep the original pagelist until we know all the allocations
+        * have succeeded
+        */
+       temp_pagelist = drm_alloc((dma->page_count + (count << page_order))
+                                 * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+       if (!temp_pagelist) {
+               drm_free(entry->buflist,
+                        count * sizeof(*entry->buflist), DRM_MEM_BUFS);
+               drm_free(entry->seglist,
+                        count * sizeof(*entry->seglist), DRM_MEM_SEGS);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memcpy(temp_pagelist,
+              dma->pagelist, dma->page_count * sizeof(*dma->pagelist));
+       DRM_DEBUG("pagelist: %d entries\n",
+                 dma->page_count + (count << page_order));
+
+       entry->buf_size = size;
+       entry->page_order = page_order;
+       byte_count = 0;
+       page_count = 0;
+
+       while (entry->buf_count < count) {
+
+               dmah = drm_pci_alloc(dev, PAGE_SIZE << page_order, 0x1000, 0xfffffffful);
+
+               if (!dmah) {
+                       /* Set count correctly so we free the proper amount. */
+                       entry->buf_count = count;
+                       entry->seg_count = count;
+                       drm_cleanup_buf_error(dev, entry);
+                       drm_free(temp_pagelist,
+                                (dma->page_count + (count << page_order))
+                                * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+                       mutex_unlock(&dev->struct_mutex);
+                       atomic_dec(&dev->buf_alloc);
+                       return -ENOMEM;
+               }
+               entry->seglist[entry->seg_count++] = dmah;
+               for (i = 0; i < (1 << page_order); i++) {
+                       DRM_DEBUG("page %d @ 0x%08lx\n",
+                                 dma->page_count + page_count,
+                                 (unsigned long)dmah->vaddr + PAGE_SIZE * i);
+                       temp_pagelist[dma->page_count + page_count++]
+                               = (unsigned long)dmah->vaddr + PAGE_SIZE * i;
+               }
+               for (offset = 0;
+                    offset + size <= total && entry->buf_count < count;
+                    offset += alignment, ++entry->buf_count) {
+                       buf = &entry->buflist[entry->buf_count];
+                       buf->idx = dma->buf_count + entry->buf_count;
+                       buf->total = alignment;
+                       buf->order = order;
+                       buf->used = 0;
+                       buf->offset = (dma->byte_count + byte_count + offset);
+                       buf->address = (void *)(dmah->vaddr + offset);
+                       buf->bus_address = dmah->busaddr + offset;
+                       buf->next = NULL;
+                       buf->waiting = 0;
+                       buf->pending = 0;
+                       init_waitqueue_head(&buf->dma_wait);
+                       buf->file_priv = NULL;
+
+                       buf->dev_priv_size = dev->driver->dev_priv_size;
+                       buf->dev_private = drm_alloc(buf->dev_priv_size,
+                                                    DRM_MEM_BUFS);
+                       if (!buf->dev_private) {
+                               /* Set count correctly so we free the proper amount. */
+                               entry->buf_count = count;
+                               entry->seg_count = count;
+                               drm_cleanup_buf_error(dev, entry);
+                               drm_free(temp_pagelist,
+                                        (dma->page_count +
+                                         (count << page_order))
+                                        * sizeof(*dma->pagelist),
+                                        DRM_MEM_PAGES);
+                               mutex_unlock(&dev->struct_mutex);
+                               atomic_dec(&dev->buf_alloc);
+                               return -ENOMEM;
+                       }
+                       memset(buf->dev_private, 0, buf->dev_priv_size);
+
+                       DRM_DEBUG("buffer %d @ %p\n",
+                                 entry->buf_count, buf->address);
+               }
+               byte_count += PAGE_SIZE << page_order;
+       }
+
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
+               /* Free the entry because it isn't valid */
+               drm_cleanup_buf_error(dev, entry);
+               drm_free(temp_pagelist,
+                        (dma->page_count + (count << page_order))
+                        * sizeof(*dma->pagelist), DRM_MEM_PAGES);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       dma->buflist = temp_buflist;
+
+       for (i = 0; i < entry->buf_count; i++) {
+               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
+       }
+
+       /* No allocations failed, so now we can replace the orginal pagelist
+        * with the new one.
+        */
+       if (dma->page_count) {
+               drm_free(dma->pagelist,
+                        dma->page_count * sizeof(*dma->pagelist),
+                        DRM_MEM_PAGES);
+       }
+       dma->pagelist = temp_pagelist;
+
+       dma->buf_count += entry->buf_count;
+       dma->seg_count += entry->seg_count;
+       dma->page_count += entry->seg_count << page_order;
+       dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       request->count = entry->buf_count;
+       request->size = size;
+
+       if (request->flags & _DRM_PCI_BUFFER_RO)
+               dma->flags = _DRM_DMA_USE_PCI_RO;
+
+       atomic_dec(&dev->buf_alloc);
+       return 0;
+
+}
+EXPORT_SYMBOL(drm_addbufs_pci);
+
+static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_entry *entry;
+       struct drm_buf *buf;
+       unsigned long offset;
+       unsigned long agp_offset;
+       int count;
+       int order;
+       int size;
+       int alignment;
+       int page_order;
+       int total;
+       int byte_count;
+       int i;
+       struct drm_buf **temp_buflist;
+
+       if (!drm_core_check_feature(dev, DRIVER_SG))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       count = request->count;
+       order = drm_order(request->size);
+       size = 1 << order;
+
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
+       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
+       total = PAGE_SIZE << page_order;
+
+       byte_count = 0;
+       agp_offset = request->agp_start;
+
+       DRM_DEBUG("count:      %d\n", count);
+       DRM_DEBUG("order:      %d\n", order);
+       DRM_DEBUG("size:       %d\n", size);
+       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n", alignment);
+       DRM_DEBUG("page_order: %d\n", page_order);
+       DRM_DEBUG("total:      %d\n", total);
+
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
+
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
+
+       mutex_lock(&dev->struct_mutex);
+       entry = &dma->bufs[order];
+       if (entry->buf_count) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
+       }
+
+       if (count < 0 || count > 4096) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -EINVAL;
+       }
+
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+       entry->buf_size = size;
+       entry->page_order = page_order;
+
+       offset = 0;
+
+       while (entry->buf_count < count) {
+               buf = &entry->buflist[entry->buf_count];
+               buf->idx = dma->buf_count + entry->buf_count;
+               buf->total = alignment;
+               buf->order = order;
+               buf->used = 0;
+
+               buf->offset = (dma->byte_count + offset);
+               buf->bus_address = agp_offset + offset;
+               buf->address = (void *)(agp_offset + offset
+                                       + (unsigned long)dev->sg->virtual);
+               buf->next = NULL;
+               buf->waiting = 0;
+               buf->pending = 0;
+               init_waitqueue_head(&buf->dma_wait);
+               buf->file_priv = NULL;
+
+               buf->dev_priv_size = dev->driver->dev_priv_size;
+               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+               if (!buf->dev_private) {
+                       /* Set count correctly so we free the proper amount. */
+                       entry->buf_count = count;
+                       drm_cleanup_buf_error(dev, entry);
+                       mutex_unlock(&dev->struct_mutex);
+                       atomic_dec(&dev->buf_alloc);
+                       return -ENOMEM;
+               }
+
+               memset(buf->dev_private, 0, buf->dev_priv_size);
+
+               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
+
+               offset += alignment;
+               entry->buf_count++;
+               byte_count += PAGE_SIZE << page_order;
+       }
+
+       DRM_DEBUG("byte_count: %d\n", byte_count);
+
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
+               /* Free the entry because it isn't valid */
+               drm_cleanup_buf_error(dev, entry);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       dma->buflist = temp_buflist;
+
+       for (i = 0; i < entry->buf_count; i++) {
+               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
+       }
+
+       dma->buf_count += entry->buf_count;
+       dma->seg_count += entry->seg_count;
+       dma->page_count += byte_count >> PAGE_SHIFT;
+       dma->byte_count += byte_count;
+
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       request->count = entry->buf_count;
+       request->size = size;
+
+       dma->flags = _DRM_DMA_USE_SG;
+
+       atomic_dec(&dev->buf_alloc);
+       return 0;
+}
+
+static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_entry *entry;
+       struct drm_buf *buf;
+       unsigned long offset;
+       unsigned long agp_offset;
+       int count;
+       int order;
+       int size;
+       int alignment;
+       int page_order;
+       int total;
+       int byte_count;
+       int i;
+       struct drm_buf **temp_buflist;
+
+       if (!drm_core_check_feature(dev, DRIVER_FB_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
+       count = request->count;
+       order = drm_order(request->size);
+       size = 1 << order;
+
+       alignment = (request->flags & _DRM_PAGE_ALIGN)
+           ? PAGE_ALIGN(size) : size;
+       page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
+       total = PAGE_SIZE << page_order;
+
+       byte_count = 0;
+       agp_offset = request->agp_start;
+
+       DRM_DEBUG("count:      %d\n", count);
+       DRM_DEBUG("order:      %d\n", order);
+       DRM_DEBUG("size:       %d\n", size);
+       DRM_DEBUG("agp_offset: %lu\n", agp_offset);
+       DRM_DEBUG("alignment:  %d\n", alignment);
+       DRM_DEBUG("page_order: %d\n", page_order);
+       DRM_DEBUG("total:      %d\n", total);
+
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       if (dev->queue_count)
+               return -EBUSY;  /* Not while in use */
+
+       spin_lock(&dev->count_lock);
+       if (dev->buf_use) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       atomic_inc(&dev->buf_alloc);
+       spin_unlock(&dev->count_lock);
+
+       mutex_lock(&dev->struct_mutex);
+       entry = &dma->bufs[order];
+       if (entry->buf_count) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM; /* May only call once for each order */
+       }
+
+       if (count < 0 || count > 4096) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -EINVAL;
+       }
+
+       entry->buflist = drm_alloc(count * sizeof(*entry->buflist),
+                                  DRM_MEM_BUFS);
+       if (!entry->buflist) {
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       memset(entry->buflist, 0, count * sizeof(*entry->buflist));
+
+       entry->buf_size = size;
+       entry->page_order = page_order;
+
+       offset = 0;
+
+       while (entry->buf_count < count) {
+               buf = &entry->buflist[entry->buf_count];
+               buf->idx = dma->buf_count + entry->buf_count;
+               buf->total = alignment;
+               buf->order = order;
+               buf->used = 0;
+
+               buf->offset = (dma->byte_count + offset);
+               buf->bus_address = agp_offset + offset;
+               buf->address = (void *)(agp_offset + offset);
+               buf->next = NULL;
+               buf->waiting = 0;
+               buf->pending = 0;
+               init_waitqueue_head(&buf->dma_wait);
+               buf->file_priv = NULL;
+
+               buf->dev_priv_size = dev->driver->dev_priv_size;
+               buf->dev_private = drm_alloc(buf->dev_priv_size, DRM_MEM_BUFS);
+               if (!buf->dev_private) {
+                       /* Set count correctly so we free the proper amount. */
+                       entry->buf_count = count;
+                       drm_cleanup_buf_error(dev, entry);
+                       mutex_unlock(&dev->struct_mutex);
+                       atomic_dec(&dev->buf_alloc);
+                       return -ENOMEM;
+               }
+               memset(buf->dev_private, 0, buf->dev_priv_size);
+
+               DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
+
+               offset += alignment;
+               entry->buf_count++;
+               byte_count += PAGE_SIZE << page_order;
+       }
+
+       DRM_DEBUG("byte_count: %d\n", byte_count);
+
+       temp_buflist = drm_realloc(dma->buflist,
+                                  dma->buf_count * sizeof(*dma->buflist),
+                                  (dma->buf_count + entry->buf_count)
+                                  * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       if (!temp_buflist) {
+               /* Free the entry because it isn't valid */
+               drm_cleanup_buf_error(dev, entry);
+               mutex_unlock(&dev->struct_mutex);
+               atomic_dec(&dev->buf_alloc);
+               return -ENOMEM;
+       }
+       dma->buflist = temp_buflist;
+
+       for (i = 0; i < entry->buf_count; i++) {
+               dma->buflist[i + dma->buf_count] = &entry->buflist[i];
+       }
+
+       dma->buf_count += entry->buf_count;
+       dma->seg_count += entry->seg_count;
+       dma->page_count += byte_count >> PAGE_SHIFT;
+       dma->byte_count += byte_count;
+
+       DRM_DEBUG("dma->buf_count : %d\n", dma->buf_count);
+       DRM_DEBUG("entry->buf_count : %d\n", entry->buf_count);
+
+       mutex_unlock(&dev->struct_mutex);
+
+       request->count = entry->buf_count;
+       request->size = size;
+
+       dma->flags = _DRM_DMA_USE_FB;
+
+       atomic_dec(&dev->buf_alloc);
+       return 0;
+}
+
+
+/**
+ * Add buffers for DMA transfers (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a struct drm_buf_desc request.
+ * \return zero on success or a negative number on failure.
+ *
+ * According with the memory type specified in drm_buf_desc::flags and the
+ * build options, it dispatches the call either to addbufs_agp(),
+ * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent
+ * PCI memory respectively.
+ */
+int drm_addbufs(struct drm_device *dev, void *data,
+               struct drm_file *file_priv)
+{
+       struct drm_buf_desc *request = data;
+       int ret;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               return -EINVAL;
+
+#if __OS_HAS_AGP
+       if (request->flags & _DRM_AGP_BUFFER)
+               ret = drm_addbufs_agp(dev, request);
+       else
+#endif
+       if (request->flags & _DRM_SG_BUFFER)
+               ret = drm_addbufs_sg(dev, request);
+       else if (request->flags & _DRM_FB_BUFFER)
+               ret = drm_addbufs_fb(dev, request);
+       else
+               ret = drm_addbufs_pci(dev, request);
+
+       return ret;
+}
+
+/**
+ * Get information about the buffer mappings.
+ *
+ * This was originally mean for debugging purposes, or by a sophisticated
+ * client library to determine how best to use the available buffers (e.g.,
+ * large buffers can be used for image transfer).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_buf_info structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Increments drm_device::buf_use while holding the drm_device::count_lock
+ * lock, preventing of allocating more buffers after this call. Information
+ * about each requested buffer is then copied into user space.
+ */
+int drm_infobufs(struct drm_device *dev, void *data,
+                struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_info *request = data;
+       int i;
+       int count;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       spin_lock(&dev->count_lock);
+       if (atomic_read(&dev->buf_alloc)) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       ++dev->buf_use;         /* Can't allocate more after this call */
+       spin_unlock(&dev->count_lock);
+
+       for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+               if (dma->bufs[i].buf_count)
+                       ++count;
+       }
+
+       DRM_DEBUG("count = %d\n", count);
+
+       if (request->count >= count) {
+               for (i = 0, count = 0; i < DRM_MAX_ORDER + 1; i++) {
+                       if (dma->bufs[i].buf_count) {
+                               struct drm_buf_desc __user *to =
+                                   &request->list[count];
+                               struct drm_buf_entry *from = &dma->bufs[i];
+                               struct drm_freelist *list = &dma->bufs[i].freelist;
+                               if (copy_to_user(&to->count,
+                                                &from->buf_count,
+                                                sizeof(from->buf_count)) ||
+                                   copy_to_user(&to->size,
+                                                &from->buf_size,
+                                                sizeof(from->buf_size)) ||
+                                   copy_to_user(&to->low_mark,
+                                                &list->low_mark,
+                                                sizeof(list->low_mark)) ||
+                                   copy_to_user(&to->high_mark,
+                                                &list->high_mark,
+                                                sizeof(list->high_mark)))
+                                       return -EFAULT;
+
+                               DRM_DEBUG("%d %d %d %d %d\n",
+                                         i,
+                                         dma->bufs[i].buf_count,
+                                         dma->bufs[i].buf_size,
+                                         dma->bufs[i].freelist.low_mark,
+                                         dma->bufs[i].freelist.high_mark);
+                               ++count;
+                       }
+               }
+       }
+       request->count = count;
+
+       return 0;
+}
+
+/**
+ * Specifies a low and high water mark for buffer allocation
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg a pointer to a drm_buf_desc structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies that the size order is bounded between the admissible orders and
+ * updates the respective drm_device_dma::bufs entry low and high water mark.
+ *
+ * \note This ioctl is deprecated and mostly never used.
+ */
+int drm_markbufs(struct drm_device *dev, void *data,
+                struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_desc *request = data;
+       int order;
+       struct drm_buf_entry *entry;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       DRM_DEBUG("%d, %d, %d\n",
+                 request->size, request->low_mark, request->high_mark);
+       order = drm_order(request->size);
+       if (order < DRM_MIN_ORDER || order > DRM_MAX_ORDER)
+               return -EINVAL;
+       entry = &dma->bufs[order];
+
+       if (request->low_mark < 0 || request->low_mark > entry->buf_count)
+               return -EINVAL;
+       if (request->high_mark < 0 || request->high_mark > entry->buf_count)
+               return -EINVAL;
+
+       entry->freelist.low_mark = request->low_mark;
+       entry->freelist.high_mark = request->high_mark;
+
+       return 0;
+}
+
+/**
+ * Unreserve the buffers in list, previously reserved using drmDMA.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_buf_free structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls free_buffer() for each used buffer.
+ * This function is primarily used for debugging.
+ */
+int drm_freebufs(struct drm_device *dev, void *data,
+                struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf_free *request = data;
+       int i;
+       int idx;
+       struct drm_buf *buf;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       DRM_DEBUG("%d\n", request->count);
+       for (i = 0; i < request->count; i++) {
+               if (copy_from_user(&idx, &request->list[i], sizeof(idx)))
+                       return -EFAULT;
+               if (idx < 0 || idx >= dma->buf_count) {
+                       DRM_ERROR("Index %d (of %d max)\n",
+                                 idx, dma->buf_count - 1);
+                       return -EINVAL;
+               }
+               buf = dma->buflist[idx];
+               if (buf->file_priv != file_priv) {
+                       DRM_ERROR("Process %d freeing buffer not owned\n",
+                                 task_pid_nr(current));
+                       return -EINVAL;
+               }
+               drm_free_buffer(dev, buf);
+       }
+
+       return 0;
+}
+
+/**
+ * Maps all of the DMA buffers into client-virtual space (ioctl).
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg pointer to a drm_buf_map structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information
+ * about each buffer into user space. For PCI buffers, it calls do_mmap() with
+ * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
+ * drm_mmap_dma().
+ */
+int drm_mapbufs(struct drm_device *dev, void *data,
+               struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int retcode = 0;
+       const int zero = 0;
+       unsigned long virtual;
+       unsigned long address;
+       struct drm_buf_map *request = data;
+       int i;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               return -EINVAL;
+
+       if (!dma)
+               return -EINVAL;
+
+       spin_lock(&dev->count_lock);
+       if (atomic_read(&dev->buf_alloc)) {
+               spin_unlock(&dev->count_lock);
+               return -EBUSY;
+       }
+       dev->buf_use++;         /* Can't allocate more after this call */
+       spin_unlock(&dev->count_lock);
+
+       if (request->count >= dma->buf_count) {
+               if ((drm_core_has_AGP(dev) && (dma->flags & _DRM_DMA_USE_AGP))
+                   || (drm_core_check_feature(dev, DRIVER_SG)
+                       && (dma->flags & _DRM_DMA_USE_SG))
+                   || (drm_core_check_feature(dev, DRIVER_FB_DMA)
+                       && (dma->flags & _DRM_DMA_USE_FB))) {
+                       struct drm_map *map = dev->agp_buffer_map;
+                       unsigned long token = dev->agp_buffer_token;
+
+                       if (!map) {
+                               retcode = -EINVAL;
+                               goto done;
+                       }
+                       down_write(&current->mm->mmap_sem);
+                       virtual = do_mmap(file_priv->filp, 0, map->size,
+                                         PROT_READ | PROT_WRITE,
+                                         MAP_SHARED,
+                                         token);
+                       up_write(&current->mm->mmap_sem);
+               } else {
+                       down_write(&current->mm->mmap_sem);
+                       virtual = do_mmap(file_priv->filp, 0, dma->byte_count,
+                                         PROT_READ | PROT_WRITE,
+                                         MAP_SHARED, 0);
+                       up_write(&current->mm->mmap_sem);
+               }
+               if (virtual > -1024UL) {
+                       /* Real error */
+                       retcode = (signed long)virtual;
+                       goto done;
+               }
+               request->virtual = (void __user *)virtual;
+
+               for (i = 0; i < dma->buf_count; i++) {
+                       if (copy_to_user(&request->list[i].idx,
+                                        &dma->buflist[i]->idx,
+                                        sizeof(request->list[0].idx))) {
+                               retcode = -EFAULT;
+                               goto done;
+                       }
+                       if (copy_to_user(&request->list[i].total,
+                                        &dma->buflist[i]->total,
+                                        sizeof(request->list[0].total))) {
+                               retcode = -EFAULT;
+                               goto done;
+                       }
+                       if (copy_to_user(&request->list[i].used,
+                                        &zero, sizeof(zero))) {
+                               retcode = -EFAULT;
+                               goto done;
+                       }
+                       address = virtual + dma->buflist[i]->offset;    /* *** */
+                       if (copy_to_user(&request->list[i].address,
+                                        &address, sizeof(address))) {
+                               retcode = -EFAULT;
+                               goto done;
+                       }
+               }
+       }
+      done:
+       request->count = dma->buf_count;
+       DRM_DEBUG("%d buffers, retcode = %d\n", request->count, retcode);
+
+       return retcode;
+}
+
+/**
+ * Compute size order.  Returns the exponent of the smaller power of two which
+ * is greater or equal to given number.
+ *
+ * \param size size.
+ * \return order.
+ *
+ * \todo Can be made faster.
+ */
+int drm_order(unsigned long size)
+{
+       int order;
+       unsigned long tmp;
+
+       for (order = 0, tmp = size >> 1; tmp; tmp >>= 1, order++) ;
+
+       if (size & (size - 1))
+               ++order;
+
+       return order;
+}
+EXPORT_SYMBOL(drm_order);
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
new file mode 100644 (file)
index 0000000..d505f69
--- /dev/null
@@ -0,0 +1,471 @@
+/**
+ * \file drm_context.c
+ * IOCTLs for generic contexts
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Nov 24 18:31:37 2000 by gareth@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * ChangeLog:
+ *  2001-11-16 Torsten Duwe <duwe@caldera.de>
+ *             added context constructor/destructor hooks,
+ *             needed by SiS driver's memory management.
+ */
+
+#include "drmP.h"
+
+/******************************************************************/
+/** \name Context bitmap support */
+/*@{*/
+
+/**
+ * Free a handle from the context bitmap.
+ *
+ * \param dev DRM device.
+ * \param ctx_handle context handle.
+ *
+ * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the entry
+ * in drm_device::ctx_idr, while holding the drm_device::struct_mutex
+ * lock.
+ */
+void drm_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
+{
+       mutex_lock(&dev->struct_mutex);
+       idr_remove(&dev->ctx_idr, ctx_handle);
+       mutex_unlock(&dev->struct_mutex);
+}
+
+/**
+ * Context bitmap allocation.
+ *
+ * \param dev DRM device.
+ * \return (non-negative) context handle on success or a negative number on failure.
+ *
+ * Allocate a new idr from drm_device::ctx_idr while holding the
+ * drm_device::struct_mutex lock.
+ */
+static int drm_ctxbitmap_next(struct drm_device * dev)
+{
+       int new_id;
+       int ret;
+
+again:
+       if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) {
+               DRM_ERROR("Out of memory expanding drawable idr\n");
+               return -ENOMEM;
+       }
+       mutex_lock(&dev->struct_mutex);
+       ret = idr_get_new_above(&dev->ctx_idr, NULL,
+                               DRM_RESERVED_CONTEXTS, &new_id);
+       if (ret == -EAGAIN) {
+               mutex_unlock(&dev->struct_mutex);
+               goto again;
+       }
+       mutex_unlock(&dev->struct_mutex);
+       return new_id;
+}
+
+/**
+ * Context bitmap initialization.
+ *
+ * \param dev DRM device.
+ *
+ * Initialise the drm_device::ctx_idr
+ */
+int drm_ctxbitmap_init(struct drm_device * dev)
+{
+       idr_init(&dev->ctx_idr);
+       return 0;
+}
+
+/**
+ * Context bitmap cleanup.
+ *
+ * \param dev DRM device.
+ *
+ * Free all idr members using drm_ctx_sarea_free helper function
+ * while holding the drm_device::struct_mutex lock.
+ */
+void drm_ctxbitmap_cleanup(struct drm_device * dev)
+{
+       mutex_lock(&dev->struct_mutex);
+       idr_remove_all(&dev->ctx_idr);
+       mutex_unlock(&dev->struct_mutex);
+}
+
+/*@}*/
+
+/******************************************************************/
+/** \name Per Context SAREA Support */
+/*@{*/
+
+/**
+ * Get per-context SAREA.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx_priv_map structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Gets the map from drm_device::ctx_idr with the handle specified and
+ * returns its handle.
+ */
+int drm_getsareactx(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_ctx_priv_map *request = data;
+       struct drm_map *map;
+       struct drm_map_list *_entry;
+
+       mutex_lock(&dev->struct_mutex);
+
+       map = idr_find(&dev->ctx_idr, request->ctx_id);
+       if (!map) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       mutex_unlock(&dev->struct_mutex);
+
+       request->handle = NULL;
+       list_for_each_entry(_entry, &dev->maplist, head) {
+               if (_entry->map == map) {
+                       request->handle =
+                           (void *)(unsigned long)_entry->user_token;
+                       break;
+               }
+       }
+       if (request->handle == NULL)
+               return -EINVAL;
+
+       return 0;
+}
+
+/**
+ * Set per-context SAREA.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx_priv_map structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Searches the mapping specified in \p arg and update the entry in
+ * drm_device::ctx_idr with it.
+ */
+int drm_setsareactx(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_ctx_priv_map *request = data;
+       struct drm_map *map = NULL;
+       struct drm_map_list *r_list = NULL;
+
+       mutex_lock(&dev->struct_mutex);
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               if (r_list->map
+                   && r_list->user_token == (unsigned long) request->handle)
+                       goto found;
+       }
+      bad:
+       mutex_unlock(&dev->struct_mutex);
+       return -EINVAL;
+
+      found:
+       map = r_list->map;
+       if (!map)
+               goto bad;
+
+       if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id)))
+               goto bad;
+
+       mutex_unlock(&dev->struct_mutex);
+
+       return 0;
+}
+
+/*@}*/
+
+/******************************************************************/
+/** \name The actual DRM context handling routines */
+/*@{*/
+
+/**
+ * Switch context.
+ *
+ * \param dev DRM device.
+ * \param old old context handle.
+ * \param new new context handle.
+ * \return zero on success or a negative number on failure.
+ *
+ * Attempt to set drm_device::context_flag.
+ */
+static int drm_context_switch(struct drm_device * dev, int old, int new)
+{
+       if (test_and_set_bit(0, &dev->context_flag)) {
+               DRM_ERROR("Reentering -- FIXME\n");
+               return -EBUSY;
+       }
+
+       DRM_DEBUG("Context switch from %d to %d\n", old, new);
+
+       if (new == dev->last_context) {
+               clear_bit(0, &dev->context_flag);
+               return 0;
+       }
+
+       return 0;
+}
+
+/**
+ * Complete context switch.
+ *
+ * \param dev DRM device.
+ * \param new new context handle.
+ * \return zero on success or a negative number on failure.
+ *
+ * Updates drm_device::last_context and drm_device::last_switch. Verifies the
+ * hardware lock is held, clears the drm_device::context_flag and wakes up
+ * drm_device::context_wait.
+ */
+static int drm_context_switch_complete(struct drm_device * dev, int new)
+{
+       dev->last_context = new;        /* PRE/POST: This is the _only_ writer. */
+       dev->last_switch = jiffies;
+
+       if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
+               DRM_ERROR("Lock isn't held after context switch\n");
+       }
+
+       /* If a context switch is ever initiated
+          when the kernel holds the lock, release
+          that lock here. */
+       clear_bit(0, &dev->context_flag);
+       wake_up(&dev->context_wait);
+
+       return 0;
+}
+
+/**
+ * Reserve contexts.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx_res structure.
+ * \return zero on success or a negative number on failure.
+ */
+int drm_resctx(struct drm_device *dev, void *data,
+              struct drm_file *file_priv)
+{
+       struct drm_ctx_res *res = data;
+       struct drm_ctx ctx;
+       int i;
+
+       if (res->count >= DRM_RESERVED_CONTEXTS) {
+               memset(&ctx, 0, sizeof(ctx));
+               for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
+                       ctx.handle = i;
+                       if (copy_to_user(&res->contexts[i], &ctx, sizeof(ctx)))
+                               return -EFAULT;
+               }
+       }
+       res->count = DRM_RESERVED_CONTEXTS;
+
+       return 0;
+}
+
+/**
+ * Add context.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Get a new handle for the context and copy to userspace.
+ */
+int drm_addctx(struct drm_device *dev, void *data,
+              struct drm_file *file_priv)
+{
+       struct drm_ctx_list *ctx_entry;
+       struct drm_ctx *ctx = data;
+
+       ctx->handle = drm_ctxbitmap_next(dev);
+       if (ctx->handle == DRM_KERNEL_CONTEXT) {
+               /* Skip kernel's context and get a new one. */
+               ctx->handle = drm_ctxbitmap_next(dev);
+       }
+       DRM_DEBUG("%d\n", ctx->handle);
+       if (ctx->handle == -1) {
+               DRM_DEBUG("Not enough free contexts.\n");
+               /* Should this return -EBUSY instead? */
+               return -ENOMEM;
+       }
+
+       if (ctx->handle != DRM_KERNEL_CONTEXT) {
+               if (dev->driver->context_ctor)
+                       if (!dev->driver->context_ctor(dev, ctx->handle)) {
+                               DRM_DEBUG("Running out of ctxs or memory.\n");
+                               return -ENOMEM;
+                       }
+       }
+
+       ctx_entry = drm_alloc(sizeof(*ctx_entry), DRM_MEM_CTXLIST);
+       if (!ctx_entry) {
+               DRM_DEBUG("out of memory\n");
+               return -ENOMEM;
+       }
+
+       INIT_LIST_HEAD(&ctx_entry->head);
+       ctx_entry->handle = ctx->handle;
+       ctx_entry->tag = file_priv;
+
+       mutex_lock(&dev->ctxlist_mutex);
+       list_add(&ctx_entry->head, &dev->ctxlist);
+       ++dev->ctx_count;
+       mutex_unlock(&dev->ctxlist_mutex);
+
+       return 0;
+}
+
+int drm_modctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       /* This does nothing */
+       return 0;
+}
+
+/**
+ * Get context.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx structure.
+ * \return zero on success or a negative number on failure.
+ */
+int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_ctx *ctx = data;
+
+       /* This is 0, because we don't handle any context flags */
+       ctx->flags = 0;
+
+       return 0;
+}
+
+/**
+ * Switch context.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls context_switch().
+ */
+int drm_switchctx(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       struct drm_ctx *ctx = data;
+
+       DRM_DEBUG("%d\n", ctx->handle);
+       return drm_context_switch(dev, dev->last_context, ctx->handle);
+}
+
+/**
+ * New context.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls context_switch_complete().
+ */
+int drm_newctx(struct drm_device *dev, void *data,
+              struct drm_file *file_priv)
+{
+       struct drm_ctx *ctx = data;
+
+       DRM_DEBUG("%d\n", ctx->handle);
+       drm_context_switch_complete(dev, ctx->handle);
+
+       return 0;
+}
+
+/**
+ * Remove context.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument pointing to a drm_ctx structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * If not the special kernel context, calls ctxbitmap_free() to free the specified context.
+ */
+int drm_rmctx(struct drm_device *dev, void *data,
+             struct drm_file *file_priv)
+{
+       struct drm_ctx *ctx = data;
+
+       DRM_DEBUG("%d\n", ctx->handle);
+       if (ctx->handle == DRM_KERNEL_CONTEXT + 1) {
+               file_priv->remove_auth_on_close = 1;
+       }
+       if (ctx->handle != DRM_KERNEL_CONTEXT) {
+               if (dev->driver->context_dtor)
+                       dev->driver->context_dtor(dev, ctx->handle);
+               drm_ctxbitmap_free(dev, ctx->handle);
+       }
+
+       mutex_lock(&dev->ctxlist_mutex);
+       if (!list_empty(&dev->ctxlist)) {
+               struct drm_ctx_list *pos, *n;
+
+               list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
+                       if (pos->handle == ctx->handle) {
+                               list_del(&pos->head);
+                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
+                               --dev->ctx_count;
+                       }
+               }
+       }
+       mutex_unlock(&dev->ctxlist_mutex);
+
+       return 0;
+}
+
+/*@}*/
diff --git a/drivers/gpu/drm/drm_dma.c b/drivers/gpu/drm/drm_dma.c
new file mode 100644 (file)
index 0000000..7a8e2fb
--- /dev/null
@@ -0,0 +1,180 @@
+/**
+ * \file drm_dma.c
+ * DMA IOCTL and function support
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+/**
+ * Initialize the DMA data.
+ *
+ * \param dev DRM device.
+ * \return zero on success or a negative value on failure.
+ *
+ * Allocate and initialize a drm_device_dma structure.
+ */
+int drm_dma_setup(struct drm_device *dev)
+{
+       int i;
+
+       dev->dma = drm_alloc(sizeof(*dev->dma), DRM_MEM_DRIVER);
+       if (!dev->dma)
+               return -ENOMEM;
+
+       memset(dev->dma, 0, sizeof(*dev->dma));
+
+       for (i = 0; i <= DRM_MAX_ORDER; i++)
+               memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
+
+       return 0;
+}
+
+/**
+ * Cleanup the DMA resources.
+ *
+ * \param dev DRM device.
+ *
+ * Free all pages associated with DMA buffers, the buffers and pages lists, and
+ * finally the drm_device::dma structure itself.
+ */
+void drm_dma_takedown(struct drm_device *dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i, j;
+
+       if (!dma)
+               return;
+
+       /* Clear dma buffers */
+       for (i = 0; i <= DRM_MAX_ORDER; i++) {
+               if (dma->bufs[i].seg_count) {
+                       DRM_DEBUG("order %d: buf_count = %d,"
+                                 " seg_count = %d\n",
+                                 i,
+                                 dma->bufs[i].buf_count,
+                                 dma->bufs[i].seg_count);
+                       for (j = 0; j < dma->bufs[i].seg_count; j++) {
+                               if (dma->bufs[i].seglist[j]) {
+                                       drm_pci_free(dev, dma->bufs[i].seglist[j]);
+                               }
+                       }
+                       drm_free(dma->bufs[i].seglist,
+                                dma->bufs[i].seg_count
+                                * sizeof(*dma->bufs[0].seglist), DRM_MEM_SEGS);
+               }
+               if (dma->bufs[i].buf_count) {
+                       for (j = 0; j < dma->bufs[i].buf_count; j++) {
+                               if (dma->bufs[i].buflist[j].dev_private) {
+                                       drm_free(dma->bufs[i].buflist[j].
+                                                dev_private,
+                                                dma->bufs[i].buflist[j].
+                                                dev_priv_size, DRM_MEM_BUFS);
+                               }
+                       }
+                       drm_free(dma->bufs[i].buflist,
+                                dma->bufs[i].buf_count *
+                                sizeof(*dma->bufs[0].buflist), DRM_MEM_BUFS);
+               }
+       }
+
+       if (dma->buflist) {
+               drm_free(dma->buflist,
+                        dma->buf_count * sizeof(*dma->buflist), DRM_MEM_BUFS);
+       }
+
+       if (dma->pagelist) {
+               drm_free(dma->pagelist,
+                        dma->page_count * sizeof(*dma->pagelist),
+                        DRM_MEM_PAGES);
+       }
+       drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DRIVER);
+       dev->dma = NULL;
+}
+
+/**
+ * Free a buffer.
+ *
+ * \param dev DRM device.
+ * \param buf buffer to free.
+ *
+ * Resets the fields of \p buf.
+ */
+void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf)
+{
+       if (!buf)
+               return;
+
+       buf->waiting = 0;
+       buf->pending = 0;
+       buf->file_priv = NULL;
+       buf->used = 0;
+
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE)
+           && waitqueue_active(&buf->dma_wait)) {
+               wake_up_interruptible(&buf->dma_wait);
+       }
+}
+
+/**
+ * Reclaim the buffers.
+ *
+ * \param file_priv DRM file private.
+ *
+ * Frees each buffer associated with \p file_priv not already on the hardware.
+ */
+void drm_core_reclaim_buffers(struct drm_device *dev,
+                             struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+
+       if (!dma)
+               return;
+       for (i = 0; i < dma->buf_count; i++) {
+               if (dma->buflist[i]->file_priv == file_priv) {
+                       switch (dma->buflist[i]->list) {
+                       case DRM_LIST_NONE:
+                               drm_free_buffer(dev, dma->buflist[i]);
+                               break;
+                       case DRM_LIST_WAIT:
+                               dma->buflist[i]->list = DRM_LIST_RECLAIM;
+                               break;
+                       default:
+                               /* Buffer already on hardware. */
+                               break;
+                       }
+               }
+       }
+}
+
+EXPORT_SYMBOL(drm_core_reclaim_buffers);
diff --git a/drivers/gpu/drm/drm_drawable.c b/drivers/gpu/drm/drm_drawable.c
new file mode 100644 (file)
index 0000000..1839c57
--- /dev/null
@@ -0,0 +1,192 @@
+/**
+ * \file drm_drawable.c
+ * IOCTLs for drawables
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ * \author Michel Dänzer <michel@tungstengraphics.com>
+ */
+
+/*
+ * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+/**
+ * Allocate drawable ID and memory to store information about it.
+ */
+int drm_adddraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       unsigned long irqflags;
+       struct drm_draw *draw = data;
+       int new_id = 0;
+       int ret;
+
+again:
+       if (idr_pre_get(&dev->drw_idr, GFP_KERNEL) == 0) {
+               DRM_ERROR("Out of memory expanding drawable idr\n");
+               return -ENOMEM;
+       }
+
+       spin_lock_irqsave(&dev->drw_lock, irqflags);
+       ret = idr_get_new_above(&dev->drw_idr, NULL, 1, &new_id);
+       if (ret == -EAGAIN) {
+               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+               goto again;
+       }
+
+       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+
+       draw->handle = new_id;
+
+       DRM_DEBUG("%d\n", draw->handle);
+
+       return 0;
+}
+
+/**
+ * Free drawable ID and memory to store information about it.
+ */
+int drm_rmdraw(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_draw *draw = data;
+       unsigned long irqflags;
+
+       spin_lock_irqsave(&dev->drw_lock, irqflags);
+
+       drm_free(drm_get_drawable_info(dev, draw->handle),
+                sizeof(struct drm_drawable_info), DRM_MEM_BUFS);
+
+       idr_remove(&dev->drw_idr, draw->handle);
+
+       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+       DRM_DEBUG("%d\n", draw->handle);
+       return 0;
+}
+
+int drm_update_drawable_info(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_update_draw *update = data;
+       unsigned long irqflags;
+       struct drm_clip_rect *rects;
+       struct drm_drawable_info *info;
+       int err;
+
+       info = idr_find(&dev->drw_idr, update->handle);
+       if (!info) {
+               info = drm_calloc(1, sizeof(*info), DRM_MEM_BUFS);
+               if (!info)
+                       return -ENOMEM;
+               if (IS_ERR(idr_replace(&dev->drw_idr, info, update->handle))) {
+                       DRM_ERROR("No such drawable %d\n", update->handle);
+                       drm_free(info, sizeof(*info), DRM_MEM_BUFS);
+                       return -EINVAL;
+               }
+       }
+
+       switch (update->type) {
+       case DRM_DRAWABLE_CLIPRECTS:
+               if (update->num != info->num_rects) {
+                       rects = drm_alloc(update->num * sizeof(struct drm_clip_rect),
+                                        DRM_MEM_BUFS);
+               } else
+                       rects = info->rects;
+
+               if (update->num && !rects) {
+                       DRM_ERROR("Failed to allocate cliprect memory\n");
+                       err = -ENOMEM;
+                       goto error;
+               }
+
+               if (update->num && DRM_COPY_FROM_USER(rects,
+                                                    (struct drm_clip_rect __user *)
+                                                    (unsigned long)update->data,
+                                                    update->num *
+                                                    sizeof(*rects))) {
+                       DRM_ERROR("Failed to copy cliprects from userspace\n");
+                       err = -EFAULT;
+                       goto error;
+               }
+
+               spin_lock_irqsave(&dev->drw_lock, irqflags);
+
+               if (rects != info->rects) {
+                       drm_free(info->rects, info->num_rects *
+                                sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
+               }
+
+               info->rects = rects;
+               info->num_rects = update->num;
+
+               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+
+               DRM_DEBUG("Updated %d cliprects for drawable %d\n",
+                         info->num_rects, update->handle);
+               break;
+       default:
+               DRM_ERROR("Invalid update type %d\n", update->type);
+               return -EINVAL;
+       }
+
+       return 0;
+
+error:
+       if (rects != info->rects)
+               drm_free(rects, update->num * sizeof(struct drm_clip_rect),
+                        DRM_MEM_BUFS);
+
+       return err;
+}
+
+/**
+ * Caller must hold the drawable spinlock!
+ */
+struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, drm_drawable_t id)
+{
+       return idr_find(&dev->drw_idr, id);
+}
+EXPORT_SYMBOL(drm_get_drawable_info);
+
+static int drm_drawable_free(int idr, void *p, void *data)
+{
+       struct drm_drawable_info *info = p;
+
+       if (info) {
+               drm_free(info->rects, info->num_rects *
+                        sizeof(struct drm_clip_rect), DRM_MEM_BUFS);
+               drm_free(info, sizeof(*info), DRM_MEM_BUFS);
+       }
+
+       return 0;
+}
+
+void drm_drawable_free_all(struct drm_device *dev)
+{
+       idr_for_each(&dev->drw_idr, drm_drawable_free, NULL);
+       idr_remove_all(&dev->drw_idr);
+}
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
new file mode 100644 (file)
index 0000000..5641387
--- /dev/null
@@ -0,0 +1,540 @@
+/**
+ * \file drm_drv.c
+ * Generic driver template
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ *
+ * To use this template, you must at least define the following (samples
+ * given for the MGA driver):
+ *
+ * \code
+ * #define DRIVER_AUTHOR       "VA Linux Systems, Inc."
+ *
+ * #define DRIVER_NAME         "mga"
+ * #define DRIVER_DESC         "Matrox G200/G400"
+ * #define DRIVER_DATE         "20001127"
+ *
+ * #define drm_x               mga_##x
+ * \endcode
+ */
+
+/*
+ * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_core.h"
+
+static int drm_version(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+
+/** Ioctl table */
+static struct drm_ioctl_desc drm_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_getmap, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, 0),
+       DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER|DRM_ROOT_ONLY),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_rmmap_ioctl, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_getctx, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_resctx, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_adddraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_rmdraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_LOCK, drm_lock, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_unlock, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
+       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
+       DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+
+#if __OS_HAS_AGP
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+#endif
+
+       DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0),
+
+       DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+};
+
+#define DRM_CORE_IOCTL_COUNT   ARRAY_SIZE( drm_ioctls )
+
+/**
+ * Take down the DRM device.
+ *
+ * \param dev DRM device structure.
+ *
+ * Frees every resource in \p dev.
+ *
+ * \sa drm_device
+ */
+int drm_lastclose(struct drm_device * dev)
+{
+       struct drm_magic_entry *pt, *next;
+       struct drm_map_list *r_list, *list_t;
+       struct drm_vma_entry *vma, *vma_temp;
+       int i;
+
+       DRM_DEBUG("\n");
+
+       if (dev->driver->lastclose)
+               dev->driver->lastclose(dev);
+       DRM_DEBUG("driver lastclose completed\n");
+
+       if (dev->unique) {
+               drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
+               dev->unique = NULL;
+               dev->unique_len = 0;
+       }
+
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+       mutex_lock(&dev->struct_mutex);
+
+       /* Free drawable information memory */
+       drm_drawable_free_all(dev);
+       del_timer(&dev->timer);
+
+       /* Clear pid list */
+       if (dev->magicfree.next) {
+               list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
+                       list_del(&pt->head);
+                       drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
+                       drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
+               }
+               drm_ht_remove(&dev->magiclist);
+       }
+
+       /* Clear AGP information */
+       if (drm_core_has_AGP(dev) && dev->agp) {
+               struct drm_agp_mem *entry, *tempe;
+
+               /* Remove AGP resources, but leave dev->agp
+                  intact until drv_cleanup is called. */
+               list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
+                       if (entry->bound)
+                               drm_unbind_agp(entry->memory);
+                       drm_free_agp(entry->memory, entry->pages);
+                       drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
+               }
+               INIT_LIST_HEAD(&dev->agp->memory);
+
+               if (dev->agp->acquired)
+                       drm_agp_release(dev);
+
+               dev->agp->acquired = 0;
+               dev->agp->enabled = 0;
+       }
+       if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
+               drm_sg_cleanup(dev->sg);
+               dev->sg = NULL;
+       }
+
+       /* Clear vma list (only built for debugging) */
+       list_for_each_entry_safe(vma, vma_temp, &dev->vmalist, head) {
+               list_del(&vma->head);
+               drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
+       }
+
+       list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) {
+               if (!(r_list->map->flags & _DRM_DRIVER)) {
+                       drm_rmmap_locked(dev, r_list->map);
+                       r_list = NULL;
+               }
+       }
+
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
+               for (i = 0; i < dev->queue_count; i++) {
+                       if (dev->queuelist[i]) {
+                               drm_free(dev->queuelist[i],
+                                        sizeof(*dev->queuelist[0]),
+                                        DRM_MEM_QUEUES);
+                               dev->queuelist[i] = NULL;
+                       }
+               }
+               drm_free(dev->queuelist,
+                        dev->queue_slots * sizeof(*dev->queuelist),
+                        DRM_MEM_QUEUES);
+               dev->queuelist = NULL;
+       }
+       dev->queue_count = 0;
+
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
+               drm_dma_takedown(dev);
+
+       if (dev->lock.hw_lock) {
+               dev->sigdata.lock = dev->lock.hw_lock = NULL;   /* SHM removed */
+               dev->lock.file_priv = NULL;
+               wake_up_interruptible(&dev->lock.lock_queue);
+       }
+       mutex_unlock(&dev->struct_mutex);
+
+       DRM_DEBUG("lastclose completed\n");
+       return 0;
+}
+
+/**
+ * Module initialization. Called via init_module at module load time, or via
+ * linux/init/main.c (this is not currently supported).
+ *
+ * \return zero on success or a negative number on failure.
+ *
+ * Initializes an array of drm_device structures, and attempts to
+ * initialize all available devices, using consecutive minors, registering the
+ * stubs and initializing the AGP device.
+ *
+ * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
+ * after the initialization for driver customization.
+ */
+int drm_init(struct drm_driver *driver)
+{
+       struct pci_dev *pdev = NULL;
+       struct pci_device_id *pid;
+       int i;
+
+       DRM_DEBUG("\n");
+
+       for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
+               pid = (struct pci_device_id *)&driver->pci_driver.id_table[i];
+
+               pdev = NULL;
+               /* pass back in pdev to account for multiple identical cards */
+               while ((pdev =
+                       pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
+                                      pid->subdevice, pdev)) != NULL) {
+                       /* stealth mode requires a manual probe */
+                       pci_dev_get(pdev);
+                       drm_get_dev(pdev, pid, driver);
+               }
+       }
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_init);
+
+/**
+ * Called via cleanup_module() at module unload time.
+ *
+ * Cleans up all DRM device, calling drm_lastclose().
+ *
+ * \sa drm_init
+ */
+static void drm_cleanup(struct drm_device * dev)
+{
+       DRM_DEBUG("\n");
+
+       if (!dev) {
+               DRM_ERROR("cleanup called no dev\n");
+               return;
+       }
+
+       drm_lastclose(dev);
+
+       if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) &&
+           dev->agp && dev->agp->agp_mtrr >= 0) {
+               int retval;
+               retval = mtrr_del(dev->agp->agp_mtrr,
+                                 dev->agp->agp_info.aper_base,
+                                 dev->agp->agp_info.aper_size * 1024 * 1024);
+               DRM_DEBUG("mtrr_del=%d\n", retval);
+       }
+
+       if (drm_core_has_AGP(dev) && dev->agp) {
+               drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
+               dev->agp = NULL;
+       }
+
+       if (dev->driver->unload)
+               dev->driver->unload(dev);
+
+       drm_ht_remove(&dev->map_hash);
+       drm_ctxbitmap_cleanup(dev);
+
+       drm_put_minor(&dev->primary);
+       if (drm_put_dev(dev))
+               DRM_ERROR("Cannot unload module\n");
+}
+
+int drm_minors_cleanup(int id, void *ptr, void *data)
+{
+       struct drm_minor *minor = ptr;
+       struct drm_device *dev;
+       struct drm_driver *driver = data;
+
+       dev = minor->dev;
+       if (minor->dev->driver != driver)
+               return 0;
+
+       if (minor->type != DRM_MINOR_LEGACY)
+               return 0;
+
+       if (dev)
+               pci_dev_put(dev->pdev);
+       drm_cleanup(dev);
+       return 1;
+}
+
+void drm_exit(struct drm_driver *driver)
+{
+       DRM_DEBUG("\n");
+
+       idr_for_each(&drm_minors_idr, &drm_minors_cleanup, driver);
+
+       DRM_INFO("Module unloaded\n");
+}
+
+EXPORT_SYMBOL(drm_exit);
+
+/** File operations structure */
+static const struct file_operations drm_stub_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_stub_open
+};
+
+static int __init drm_core_init(void)
+{
+       int ret = -ENOMEM;
+
+       idr_init(&drm_minors_idr);
+
+       if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
+               goto err_p1;
+
+       drm_class = drm_sysfs_create(THIS_MODULE, "drm");
+       if (IS_ERR(drm_class)) {
+               printk(KERN_ERR "DRM: Error creating drm class.\n");
+               ret = PTR_ERR(drm_class);
+               goto err_p2;
+       }
+
+       drm_proc_root = proc_mkdir("dri", NULL);
+       if (!drm_proc_root) {
+               DRM_ERROR("Cannot create /proc/dri\n");
+               ret = -1;
+               goto err_p3;
+       }
+
+       drm_mem_init();
+
+       DRM_INFO("Initialized %s %d.%d.%d %s\n",
+                CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
+       return 0;
+err_p3:
+       drm_sysfs_destroy();
+err_p2:
+       unregister_chrdev(DRM_MAJOR, "drm");
+
+       idr_destroy(&drm_minors_idr);
+err_p1:
+       return ret;
+}
+
+static void __exit drm_core_exit(void)
+{
+       remove_proc_entry("dri", NULL);
+       drm_sysfs_destroy();
+
+       unregister_chrdev(DRM_MAJOR, "drm");
+
+       idr_destroy(&drm_minors_idr);
+}
+
+module_init(drm_core_init);
+module_exit(drm_core_exit);
+
+/**
+ * Get version information
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_version structure.
+ * \return zero on success or negative number on failure.
+ *
+ * Fills in the version information in \p arg.
+ */
+static int drm_version(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_version *version = data;
+       int len;
+
+       version->version_major = dev->driver->major;
+       version->version_minor = dev->driver->minor;
+       version->version_patchlevel = dev->driver->patchlevel;
+       DRM_COPY(version->name, dev->driver->name);
+       DRM_COPY(version->date, dev->driver->date);
+       DRM_COPY(version->desc, dev->driver->desc);
+
+       return 0;
+}
+
+/**
+ * Called whenever a process performs an ioctl on /dev/drm.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ *
+ * Looks up the ioctl function in the ::ioctls table, checking for root
+ * previleges if so required, and dispatches to the respective function.
+ */
+int drm_ioctl(struct inode *inode, struct file *filp,
+             unsigned int cmd, unsigned long arg)
+{
+       struct drm_file *file_priv = filp->private_data;
+       struct drm_device *dev = file_priv->minor->dev;
+       struct drm_ioctl_desc *ioctl;
+       drm_ioctl_t *func;
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       int retcode = -EINVAL;
+       char *kdata = NULL;
+
+       atomic_inc(&dev->ioctl_count);
+       atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
+       ++file_priv->ioctl_count;
+
+       DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
+                 task_pid_nr(current), cmd, nr,
+                 (long)old_encode_dev(file_priv->minor->device),
+                 file_priv->authenticated);
+
+       if ((nr >= DRM_CORE_IOCTL_COUNT) &&
+           ((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END)))
+               goto err_i1;
+       if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) &&
+           (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
+               ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
+       else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) {
+               ioctl = &drm_ioctls[nr];
+               cmd = ioctl->cmd;
+       } else
+               goto err_i1;
+
+       /* Do not trust userspace, use our own definition */
+       func = ioctl->func;
+       /* is there a local override? */
+       if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
+               func = dev->driver->dma_ioctl;
+
+       if (!func) {
+               DRM_DEBUG("no function\n");
+               retcode = -EINVAL;
+       } else if (((ioctl->flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
+                  ((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
+                  ((ioctl->flags & DRM_MASTER) && !file_priv->master)) {
+               retcode = -EACCES;
+       } else {
+               if (cmd & (IOC_IN | IOC_OUT)) {
+                       kdata = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
+                       if (!kdata) {
+                               retcode = -ENOMEM;
+                               goto err_i1;
+                       }
+               }
+
+               if (cmd & IOC_IN) {
+                       if (copy_from_user(kdata, (void __user *)arg,
+                                          _IOC_SIZE(cmd)) != 0) {
+                               retcode = -EFAULT;
+                               goto err_i1;
+                       }
+               }
+               retcode = func(dev, kdata, file_priv);
+
+               if ((retcode == 0) && (cmd & IOC_OUT)) {
+                       if (copy_to_user((void __user *)arg, kdata,
+                                        _IOC_SIZE(cmd)) != 0)
+                               retcode = -EFAULT;
+               }
+       }
+
+      err_i1:
+       if (kdata)
+               kfree(kdata);
+       atomic_dec(&dev->ioctl_count);
+       if (retcode)
+               DRM_DEBUG("ret = %x\n", retcode);
+       return retcode;
+}
+
+EXPORT_SYMBOL(drm_ioctl);
+
+drm_local_map_t *drm_getsarea(struct drm_device *dev)
+{
+       struct drm_map_list *entry;
+
+       list_for_each_entry(entry, &dev->maplist, head) {
+               if (entry->map && entry->map->type == _DRM_SHM &&
+                   (entry->map->flags & _DRM_CONTAINS_LOCK)) {
+                       return entry->map;
+               }
+       }
+       return NULL;
+}
+EXPORT_SYMBOL(drm_getsarea);
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
new file mode 100644 (file)
index 0000000..851a53f
--- /dev/null
@@ -0,0 +1,471 @@
+/**
+ * \file drm_fops.c
+ * File operations for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Daryll Strauss <daryll@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_sarea.h"
+#include <linux/poll.h>
+#include <linux/smp_lock.h>
+
+static int drm_open_helper(struct inode *inode, struct file *filp,
+                          struct drm_device * dev);
+
+static int drm_setup(struct drm_device * dev)
+{
+       drm_local_map_t *map;
+       int i;
+       int ret;
+       u32 sareapage;
+
+       if (dev->driver->firstopen) {
+               ret = dev->driver->firstopen(dev);
+               if (ret != 0)
+                       return ret;
+       }
+
+       dev->magicfree.next = NULL;
+
+       /* prebuild the SAREA */
+       sareapage = max_t(unsigned, SAREA_MAX, PAGE_SIZE);
+       i = drm_addmap(dev, 0, sareapage, _DRM_SHM, _DRM_CONTAINS_LOCK, &map);
+       if (i != 0)
+               return i;
+
+       atomic_set(&dev->ioctl_count, 0);
+       atomic_set(&dev->vma_count, 0);
+       dev->buf_use = 0;
+       atomic_set(&dev->buf_alloc, 0);
+
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
+               i = drm_dma_setup(dev);
+               if (i < 0)
+                       return i;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
+               atomic_set(&dev->counts[i], 0);
+
+       drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
+       INIT_LIST_HEAD(&dev->magicfree);
+
+       dev->sigdata.lock = NULL;
+       init_waitqueue_head(&dev->lock.lock_queue);
+       dev->queue_count = 0;
+       dev->queue_reserved = 0;
+       dev->queue_slots = 0;
+       dev->queuelist = NULL;
+       dev->irq_enabled = 0;
+       dev->context_flag = 0;
+       dev->interrupt_flag = 0;
+       dev->dma_flag = 0;
+       dev->last_context = 0;
+       dev->last_switch = 0;
+       dev->last_checked = 0;
+       init_waitqueue_head(&dev->context_wait);
+       dev->if_version = 0;
+
+       dev->ctx_start = 0;
+       dev->lck_start = 0;
+
+       dev->buf_async = NULL;
+       init_waitqueue_head(&dev->buf_readers);
+       init_waitqueue_head(&dev->buf_writers);
+
+       DRM_DEBUG("\n");
+
+       /*
+        * The kernel's context could be created here, but is now created
+        * in drm_dma_enqueue.  This is more resource-efficient for
+        * hardware that does not do DMA, but may mean that
+        * drm_select_queue fails between the time the interrupt is
+        * initialized and the time the queues are initialized.
+        */
+
+       return 0;
+}
+
+/**
+ * Open file.
+ *
+ * \param inode device inode
+ * \param filp file pointer.
+ * \return zero on success or a negative number on failure.
+ *
+ * Searches the DRM device with the same minor number, calls open_helper(), and
+ * increments the device open count. If the open count was previous at zero,
+ * i.e., it's the first that the device is open, then calls setup().
+ */
+int drm_open(struct inode *inode, struct file *filp)
+{
+       struct drm_device *dev = NULL;
+       int minor_id = iminor(inode);
+       struct drm_minor *minor;
+       int retcode = 0;
+
+       minor = idr_find(&drm_minors_idr, minor_id);
+       if (!minor)
+               return -ENODEV;
+
+       if (!(dev = minor->dev))
+               return -ENODEV;
+
+       retcode = drm_open_helper(inode, filp, dev);
+       if (!retcode) {
+               atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
+               spin_lock(&dev->count_lock);
+               if (!dev->open_count++) {
+                       spin_unlock(&dev->count_lock);
+                       return drm_setup(dev);
+               }
+               spin_unlock(&dev->count_lock);
+       }
+
+       return retcode;
+}
+EXPORT_SYMBOL(drm_open);
+
+/**
+ * File \c open operation.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ *
+ * Puts the dev->fops corresponding to the device minor number into
+ * \p filp, call the \c open method, and restore the file operations.
+ */
+int drm_stub_open(struct inode *inode, struct file *filp)
+{
+       struct drm_device *dev = NULL;
+       struct drm_minor *minor;
+       int minor_id = iminor(inode);
+       int err = -ENODEV;
+       const struct file_operations *old_fops;
+
+       DRM_DEBUG("\n");
+
+       /* BKL pushdown: note that nothing else serializes idr_find() */
+       lock_kernel();
+       minor = idr_find(&drm_minors_idr, minor_id);
+       if (!minor)
+               goto out;
+
+       if (!(dev = minor->dev))
+               goto out;
+
+       old_fops = filp->f_op;
+       filp->f_op = fops_get(&dev->driver->fops);
+       if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
+               fops_put(filp->f_op);
+               filp->f_op = fops_get(old_fops);
+       }
+       fops_put(old_fops);
+
+out:
+       unlock_kernel();
+       return err;
+}
+
+/**
+ * Check whether DRI will run on this CPU.
+ *
+ * \return non-zero if the DRI will run on this CPU, or zero otherwise.
+ */
+static int drm_cpu_valid(void)
+{
+#if defined(__i386__)
+       if (boot_cpu_data.x86 == 3)
+               return 0;       /* No cmpxchg on a 386 */
+#endif
+#if defined(__sparc__) && !defined(__sparc_v9__)
+       return 0;               /* No cmpxchg before v9 sparc. */
+#endif
+       return 1;
+}
+
+/**
+ * Called whenever a process opens /dev/drm.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param dev device.
+ * \return zero on success or a negative number on failure.
+ *
+ * Creates and initializes a drm_file structure for the file private data in \p
+ * filp and add it into the double linked list in \p dev.
+ */
+static int drm_open_helper(struct inode *inode, struct file *filp,
+                          struct drm_device * dev)
+{
+       int minor_id = iminor(inode);
+       struct drm_file *priv;
+       int ret;
+
+       if (filp->f_flags & O_EXCL)
+               return -EBUSY;  /* No exclusive opens */
+       if (!drm_cpu_valid())
+               return -EINVAL;
+
+       DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
+
+       priv = drm_alloc(sizeof(*priv), DRM_MEM_FILES);
+       if (!priv)
+               return -ENOMEM;
+
+       memset(priv, 0, sizeof(*priv));
+       filp->private_data = priv;
+       priv->filp = filp;
+       priv->uid = current->euid;
+       priv->pid = task_pid_nr(current);
+       priv->minor = idr_find(&drm_minors_idr, minor_id);
+       priv->ioctl_count = 0;
+       /* for compatibility root is always authenticated */
+       priv->authenticated = capable(CAP_SYS_ADMIN);
+       priv->lock_count = 0;
+
+       INIT_LIST_HEAD(&priv->lhead);
+
+       if (dev->driver->open) {
+               ret = dev->driver->open(dev, priv);
+               if (ret < 0)
+                       goto out_free;
+       }
+
+       mutex_lock(&dev->struct_mutex);
+       if (list_empty(&dev->filelist))
+               priv->master = 1;
+
+       list_add(&priv->lhead, &dev->filelist);
+       mutex_unlock(&dev->struct_mutex);
+
+#ifdef __alpha__
+       /*
+        * Default the hose
+        */
+       if (!dev->hose) {
+               struct pci_dev *pci_dev;
+               pci_dev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
+               if (pci_dev) {
+                       dev->hose = pci_dev->sysdata;
+                       pci_dev_put(pci_dev);
+               }
+               if (!dev->hose) {
+                       struct pci_bus *b = pci_bus_b(pci_root_buses.next);
+                       if (b)
+                               dev->hose = b->sysdata;
+               }
+       }
+#endif
+
+       return 0;
+      out_free:
+       drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
+       filp->private_data = NULL;
+       return ret;
+}
+
+/** No-op. */
+int drm_fasync(int fd, struct file *filp, int on)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       int retcode;
+
+       DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
+                 (long)old_encode_dev(priv->minor->device));
+       retcode = fasync_helper(fd, filp, on, &dev->buf_async);
+       if (retcode < 0)
+               return retcode;
+       return 0;
+}
+EXPORT_SYMBOL(drm_fasync);
+
+/**
+ * Release file.
+ *
+ * \param inode device inode
+ * \param file_priv DRM file private.
+ * \return zero on success or a negative number on failure.
+ *
+ * If the hardware lock is held then free it, and take it again for the kernel
+ * context since it's necessary to reclaim buffers. Unlink the file private
+ * data from its list and free it. Decreases the open count and if it reaches
+ * zero calls drm_lastclose().
+ */
+int drm_release(struct inode *inode, struct file *filp)
+{
+       struct drm_file *file_priv = filp->private_data;
+       struct drm_device *dev = file_priv->minor->dev;
+       int retcode = 0;
+
+       lock_kernel();
+
+       DRM_DEBUG("open_count = %d\n", dev->open_count);
+
+       if (dev->driver->preclose)
+               dev->driver->preclose(dev, file_priv);
+
+       /* ========================================================
+        * Begin inline drm_release
+        */
+
+       DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
+                 task_pid_nr(current),
+                 (long)old_encode_dev(file_priv->minor->device),
+                 dev->open_count);
+
+       if (dev->driver->reclaim_buffers_locked && dev->lock.hw_lock) {
+               if (drm_i_have_hw_lock(dev, file_priv)) {
+                       dev->driver->reclaim_buffers_locked(dev, file_priv);
+               } else {
+                       unsigned long endtime = jiffies + 3 * DRM_HZ;
+                       int locked = 0;
+
+                       drm_idlelock_take(&dev->lock);
+
+                       /*
+                        * Wait for a while.
+                        */
+
+                       do{
+                               spin_lock_bh(&dev->lock.spinlock);
+                               locked = dev->lock.idle_has_lock;
+                               spin_unlock_bh(&dev->lock.spinlock);
+                               if (locked)
+                                       break;
+                               schedule();
+                       } while (!time_after_eq(jiffies, endtime));
+
+                       if (!locked) {
+                               DRM_ERROR("reclaim_buffers_locked() deadlock. Please rework this\n"
+                                         "\tdriver to use reclaim_buffers_idlelocked() instead.\n"
+                                         "\tI will go on reclaiming the buffers anyway.\n");
+                       }
+
+                       dev->driver->reclaim_buffers_locked(dev, file_priv);
+                       drm_idlelock_release(&dev->lock);
+               }
+       }
+
+       if (dev->driver->reclaim_buffers_idlelocked && dev->lock.hw_lock) {
+
+               drm_idlelock_take(&dev->lock);
+               dev->driver->reclaim_buffers_idlelocked(dev, file_priv);
+               drm_idlelock_release(&dev->lock);
+
+       }
+
+       if (drm_i_have_hw_lock(dev, file_priv)) {
+               DRM_DEBUG("File %p released, freeing lock for context %d\n",
+                         filp, _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
+
+               drm_lock_free(&dev->lock,
+                             _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
+       }
+
+
+       if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
+           !dev->driver->reclaim_buffers_locked) {
+               dev->driver->reclaim_buffers(dev, file_priv);
+       }
+
+       drm_fasync(-1, filp, 0);
+
+       mutex_lock(&dev->ctxlist_mutex);
+       if (!list_empty(&dev->ctxlist)) {
+               struct drm_ctx_list *pos, *n;
+
+               list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
+                       if (pos->tag == file_priv &&
+                           pos->handle != DRM_KERNEL_CONTEXT) {
+                               if (dev->driver->context_dtor)
+                                       dev->driver->context_dtor(dev,
+                                                                 pos->handle);
+
+                               drm_ctxbitmap_free(dev, pos->handle);
+
+                               list_del(&pos->head);
+                               drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST);
+                               --dev->ctx_count;
+                       }
+               }
+       }
+       mutex_unlock(&dev->ctxlist_mutex);
+
+       mutex_lock(&dev->struct_mutex);
+       if (file_priv->remove_auth_on_close == 1) {
+               struct drm_file *temp;
+
+               list_for_each_entry(temp, &dev->filelist, lhead)
+                       temp->authenticated = 0;
+       }
+       list_del(&file_priv->lhead);
+       mutex_unlock(&dev->struct_mutex);
+
+       if (dev->driver->postclose)
+               dev->driver->postclose(dev, file_priv);
+       drm_free(file_priv, sizeof(*file_priv), DRM_MEM_FILES);
+
+       /* ========================================================
+        * End inline drm_release
+        */
+
+       atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
+       spin_lock(&dev->count_lock);
+       if (!--dev->open_count) {
+               if (atomic_read(&dev->ioctl_count) || dev->blocked) {
+                       DRM_ERROR("Device busy: %d %d\n",
+                                 atomic_read(&dev->ioctl_count), dev->blocked);
+                       spin_unlock(&dev->count_lock);
+                       unlock_kernel();
+                       return -EBUSY;
+               }
+               spin_unlock(&dev->count_lock);
+               unlock_kernel();
+               return drm_lastclose(dev);
+       }
+       spin_unlock(&dev->count_lock);
+
+       unlock_kernel();
+
+       return retcode;
+}
+EXPORT_SYMBOL(drm_release);
+
+/** No-op. */
+unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
+{
+       return 0;
+}
+EXPORT_SYMBOL(drm_poll);
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c
new file mode 100644 (file)
index 0000000..3316067
--- /dev/null
@@ -0,0 +1,202 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ **************************************************************************/
+/*
+ * Simple open hash tab implementation.
+ *
+ * Authors:
+ * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#include "drmP.h"
+#include "drm_hashtab.h"
+#include <linux/hash.h>
+
+int drm_ht_create(struct drm_open_hash *ht, unsigned int order)
+{
+       unsigned int i;
+
+       ht->size = 1 << order;
+       ht->order = order;
+       ht->fill = 0;
+       ht->table = NULL;
+       ht->use_vmalloc = ((ht->size * sizeof(*ht->table)) > PAGE_SIZE);
+       if (!ht->use_vmalloc) {
+               ht->table = drm_calloc(ht->size, sizeof(*ht->table),
+                                      DRM_MEM_HASHTAB);
+       }
+       if (!ht->table) {
+               ht->use_vmalloc = 1;
+               ht->table = vmalloc(ht->size*sizeof(*ht->table));
+       }
+       if (!ht->table) {
+               DRM_ERROR("Out of memory for hash table\n");
+               return -ENOMEM;
+       }
+       for (i=0; i< ht->size; ++i) {
+               INIT_HLIST_HEAD(&ht->table[i]);
+       }
+       return 0;
+}
+
+void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
+{
+       struct drm_hash_item *entry;
+       struct hlist_head *h_list;
+       struct hlist_node *list;
+       unsigned int hashed_key;
+       int count = 0;
+
+       hashed_key = hash_long(key, ht->order);
+       DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
+       h_list = &ht->table[hashed_key];
+       hlist_for_each(list, h_list) {
+               entry = hlist_entry(list, struct drm_hash_item, head);
+               DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
+       }
+}
+
+static struct hlist_node *drm_ht_find_key(struct drm_open_hash *ht,
+                                         unsigned long key)
+{
+       struct drm_hash_item *entry;
+       struct hlist_head *h_list;
+       struct hlist_node *list;
+       unsigned int hashed_key;
+
+       hashed_key = hash_long(key, ht->order);
+       h_list = &ht->table[hashed_key];
+       hlist_for_each(list, h_list) {
+               entry = hlist_entry(list, struct drm_hash_item, head);
+               if (entry->key == key)
+                       return list;
+               if (entry->key > key)
+                       break;
+       }
+       return NULL;
+}
+
+
+int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
+{
+       struct drm_hash_item *entry;
+       struct hlist_head *h_list;
+       struct hlist_node *list, *parent;
+       unsigned int hashed_key;
+       unsigned long key = item->key;
+
+       hashed_key = hash_long(key, ht->order);
+       h_list = &ht->table[hashed_key];
+       parent = NULL;
+       hlist_for_each(list, h_list) {
+               entry = hlist_entry(list, struct drm_hash_item, head);
+               if (entry->key == key)
+                       return -EINVAL;
+               if (entry->key > key)
+                       break;
+               parent = list;
+       }
+       if (parent) {
+               hlist_add_after(parent, &item->head);
+       } else {
+               hlist_add_head(&item->head, h_list);
+       }
+       return 0;
+}
+
+/*
+ * Just insert an item and return any "bits" bit key that hasn't been
+ * used before.
+ */
+int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
+                             unsigned long seed, int bits, int shift,
+                             unsigned long add)
+{
+       int ret;
+       unsigned long mask = (1 << bits) - 1;
+       unsigned long first, unshifted_key;
+
+       unshifted_key = hash_long(seed, bits);
+       first = unshifted_key;
+       do {
+               item->key = (unshifted_key << shift) + add;
+               ret = drm_ht_insert_item(ht, item);
+               if (ret)
+                       unshifted_key = (unshifted_key + 1) & mask;
+       } while(ret && (unshifted_key != first));
+
+       if (ret) {
+               DRM_ERROR("Available key bit space exhausted\n");
+               return -EINVAL;
+       }
+       return 0;
+}
+
+int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key,
+                    struct drm_hash_item **item)
+{
+       struct hlist_node *list;
+
+       list = drm_ht_find_key(ht, key);
+       if (!list)
+               return -EINVAL;
+
+       *item = hlist_entry(list, struct drm_hash_item, head);
+       return 0;
+}
+
+int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key)
+{
+       struct hlist_node *list;
+
+       list = drm_ht_find_key(ht, key);
+       if (list) {
+               hlist_del_init(list);
+               ht->fill--;
+               return 0;
+       }
+       return -EINVAL;
+}
+
+int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item)
+{
+       hlist_del_init(&item->head);
+       ht->fill--;
+       return 0;
+}
+
+void drm_ht_remove(struct drm_open_hash *ht)
+{
+       if (ht->table) {
+               if (ht->use_vmalloc)
+                       vfree(ht->table);
+               else
+                       drm_free(ht->table, ht->size * sizeof(*ht->table),
+                                DRM_MEM_HASHTAB);
+               ht->table = NULL;
+       }
+}
diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
new file mode 100644 (file)
index 0000000..90f5a8d
--- /dev/null
@@ -0,0 +1,1073 @@
+/**
+ * \file drm_ioc32.c
+ *
+ * 32-bit ioctl compatibility routines for the DRM.
+ *
+ * \author Paul Mackerras <paulus@samba.org>
+ *
+ * Copyright (C) Paul Mackerras 2005.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include <linux/compat.h>
+
+#include "drmP.h"
+#include "drm_core.h"
+
+#define DRM_IOCTL_VERSION32            DRM_IOWR(0x00, drm_version32_t)
+#define DRM_IOCTL_GET_UNIQUE32         DRM_IOWR(0x01, drm_unique32_t)
+#define DRM_IOCTL_GET_MAP32            DRM_IOWR(0x04, drm_map32_t)
+#define DRM_IOCTL_GET_CLIENT32         DRM_IOWR(0x05, drm_client32_t)
+#define DRM_IOCTL_GET_STATS32          DRM_IOR( 0x06, drm_stats32_t)
+
+#define DRM_IOCTL_SET_UNIQUE32         DRM_IOW( 0x10, drm_unique32_t)
+#define DRM_IOCTL_ADD_MAP32            DRM_IOWR(0x15, drm_map32_t)
+#define DRM_IOCTL_ADD_BUFS32           DRM_IOWR(0x16, drm_buf_desc32_t)
+#define DRM_IOCTL_MARK_BUFS32          DRM_IOW( 0x17, drm_buf_desc32_t)
+#define DRM_IOCTL_INFO_BUFS32          DRM_IOWR(0x18, drm_buf_info32_t)
+#define DRM_IOCTL_MAP_BUFS32           DRM_IOWR(0x19, drm_buf_map32_t)
+#define DRM_IOCTL_FREE_BUFS32          DRM_IOW( 0x1a, drm_buf_free32_t)
+
+#define DRM_IOCTL_RM_MAP32             DRM_IOW( 0x1b, drm_map32_t)
+
+#define DRM_IOCTL_SET_SAREA_CTX32      DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
+#define DRM_IOCTL_GET_SAREA_CTX32      DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
+
+#define DRM_IOCTL_RES_CTX32            DRM_IOWR(0x26, drm_ctx_res32_t)
+#define DRM_IOCTL_DMA32                        DRM_IOWR(0x29, drm_dma32_t)
+
+#define DRM_IOCTL_AGP_ENABLE32         DRM_IOW( 0x32, drm_agp_mode32_t)
+#define DRM_IOCTL_AGP_INFO32           DRM_IOR( 0x33, drm_agp_info32_t)
+#define DRM_IOCTL_AGP_ALLOC32          DRM_IOWR(0x34, drm_agp_buffer32_t)
+#define DRM_IOCTL_AGP_FREE32           DRM_IOW( 0x35, drm_agp_buffer32_t)
+#define DRM_IOCTL_AGP_BIND32           DRM_IOW( 0x36, drm_agp_binding32_t)
+#define DRM_IOCTL_AGP_UNBIND32         DRM_IOW( 0x37, drm_agp_binding32_t)
+
+#define DRM_IOCTL_SG_ALLOC32           DRM_IOW( 0x38, drm_scatter_gather32_t)
+#define DRM_IOCTL_SG_FREE32            DRM_IOW( 0x39, drm_scatter_gather32_t)
+
+#define DRM_IOCTL_WAIT_VBLANK32                DRM_IOWR(0x3a, drm_wait_vblank32_t)
+
+typedef struct drm_version_32 {
+       int version_major;        /**< Major version */
+       int version_minor;        /**< Minor version */
+       int version_patchlevel;    /**< Patch level */
+       u32 name_len;             /**< Length of name buffer */
+       u32 name;                 /**< Name of driver */
+       u32 date_len;             /**< Length of date buffer */
+       u32 date;                 /**< User-space buffer to hold date */
+       u32 desc_len;             /**< Length of desc buffer */
+       u32 desc;                 /**< User-space buffer to hold desc */
+} drm_version32_t;
+
+static int compat_drm_version(struct file *file, unsigned int cmd,
+                             unsigned long arg)
+{
+       drm_version32_t v32;
+       struct drm_version __user *version;
+       int err;
+
+       if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
+               return -EFAULT;
+
+       version = compat_alloc_user_space(sizeof(*version));
+       if (!access_ok(VERIFY_WRITE, version, sizeof(*version)))
+               return -EFAULT;
+       if (__put_user(v32.name_len, &version->name_len)
+           || __put_user((void __user *)(unsigned long)v32.name,
+                         &version->name)
+           || __put_user(v32.date_len, &version->date_len)
+           || __put_user((void __user *)(unsigned long)v32.date,
+                         &version->date)
+           || __put_user(v32.desc_len, &version->desc_len)
+           || __put_user((void __user *)(unsigned long)v32.desc,
+                         &version->desc))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_VERSION, (unsigned long)version);
+       if (err)
+               return err;
+
+       if (__get_user(v32.version_major, &version->version_major)
+           || __get_user(v32.version_minor, &version->version_minor)
+           || __get_user(v32.version_patchlevel, &version->version_patchlevel)
+           || __get_user(v32.name_len, &version->name_len)
+           || __get_user(v32.date_len, &version->date_len)
+           || __get_user(v32.desc_len, &version->desc_len))
+               return -EFAULT;
+
+       if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
+               return -EFAULT;
+       return 0;
+}
+
+typedef struct drm_unique32 {
+       u32 unique_len; /**< Length of unique */
+       u32 unique;     /**< Unique name for driver instantiation */
+} drm_unique32_t;
+
+static int compat_drm_getunique(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_unique32_t uq32;
+       struct drm_unique __user *u;
+       int err;
+
+       if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
+               return -EFAULT;
+
+       u = compat_alloc_user_space(sizeof(*u));
+       if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
+               return -EFAULT;
+       if (__put_user(uq32.unique_len, &u->unique_len)
+           || __put_user((void __user *)(unsigned long)uq32.unique,
+                         &u->unique))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
+       if (err)
+               return err;
+
+       if (__get_user(uq32.unique_len, &u->unique_len))
+               return -EFAULT;
+       if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
+               return -EFAULT;
+       return 0;
+}
+
+static int compat_drm_setunique(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_unique32_t uq32;
+       struct drm_unique __user *u;
+
+       if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
+               return -EFAULT;
+
+       u = compat_alloc_user_space(sizeof(*u));
+       if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
+               return -EFAULT;
+       if (__put_user(uq32.unique_len, &u->unique_len)
+           || __put_user((void __user *)(unsigned long)uq32.unique,
+                         &u->unique))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
+}
+
+typedef struct drm_map32 {
+       u32 offset;             /**< Requested physical address (0 for SAREA)*/
+       u32 size;               /**< Requested physical size (bytes) */
+       enum drm_map_type type; /**< Type of memory to map */
+       enum drm_map_flags flags;       /**< Flags */
+       u32 handle;             /**< User-space: "Handle" to pass to mmap() */
+       int mtrr;               /**< MTRR slot used */
+} drm_map32_t;
+
+static int compat_drm_getmap(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       drm_map32_t __user *argp = (void __user *)arg;
+       drm_map32_t m32;
+       struct drm_map __user *map;
+       int idx, err;
+       void *handle;
+
+       if (get_user(idx, &argp->offset))
+               return -EFAULT;
+
+       map = compat_alloc_user_space(sizeof(*map));
+       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
+               return -EFAULT;
+       if (__put_user(idx, &map->offset))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_GET_MAP, (unsigned long)map);
+       if (err)
+               return err;
+
+       if (__get_user(m32.offset, &map->offset)
+           || __get_user(m32.size, &map->size)
+           || __get_user(m32.type, &map->type)
+           || __get_user(m32.flags, &map->flags)
+           || __get_user(handle, &map->handle)
+           || __get_user(m32.mtrr, &map->mtrr))
+               return -EFAULT;
+
+       m32.handle = (unsigned long)handle;
+       if (copy_to_user(argp, &m32, sizeof(m32)))
+               return -EFAULT;
+       return 0;
+
+}
+
+static int compat_drm_addmap(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       drm_map32_t __user *argp = (void __user *)arg;
+       drm_map32_t m32;
+       struct drm_map __user *map;
+       int err;
+       void *handle;
+
+       if (copy_from_user(&m32, argp, sizeof(m32)))
+               return -EFAULT;
+
+       map = compat_alloc_user_space(sizeof(*map));
+       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
+               return -EFAULT;
+       if (__put_user(m32.offset, &map->offset)
+           || __put_user(m32.size, &map->size)
+           || __put_user(m32.type, &map->type)
+           || __put_user(m32.flags, &map->flags))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_ADD_MAP, (unsigned long)map);
+       if (err)
+               return err;
+
+       if (__get_user(m32.offset, &map->offset)
+           || __get_user(m32.mtrr, &map->mtrr)
+           || __get_user(handle, &map->handle))
+               return -EFAULT;
+
+       m32.handle = (unsigned long)handle;
+       if (m32.handle != (unsigned long)handle && printk_ratelimit())
+               printk(KERN_ERR "compat_drm_addmap truncated handle"
+                      " %p for type %d offset %x\n",
+                      handle, m32.type, m32.offset);
+
+       if (copy_to_user(argp, &m32, sizeof(m32)))
+               return -EFAULT;
+
+       return 0;
+}
+
+static int compat_drm_rmmap(struct file *file, unsigned int cmd,
+                           unsigned long arg)
+{
+       drm_map32_t __user *argp = (void __user *)arg;
+       struct drm_map __user *map;
+       u32 handle;
+
+       if (get_user(handle, &argp->handle))
+               return -EFAULT;
+
+       map = compat_alloc_user_space(sizeof(*map));
+       if (!access_ok(VERIFY_WRITE, map, sizeof(*map)))
+               return -EFAULT;
+       if (__put_user((void *)(unsigned long)handle, &map->handle))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RM_MAP, (unsigned long)map);
+}
+
+typedef struct drm_client32 {
+       int idx;        /**< Which client desired? */
+       int auth;       /**< Is client authenticated? */
+       u32 pid;        /**< Process ID */
+       u32 uid;        /**< User ID */
+       u32 magic;      /**< Magic */
+       u32 iocs;       /**< Ioctl count */
+} drm_client32_t;
+
+static int compat_drm_getclient(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_client32_t c32;
+       drm_client32_t __user *argp = (void __user *)arg;
+       struct drm_client __user *client;
+       int idx, err;
+
+       if (get_user(idx, &argp->idx))
+               return -EFAULT;
+
+       client = compat_alloc_user_space(sizeof(*client));
+       if (!access_ok(VERIFY_WRITE, client, sizeof(*client)))
+               return -EFAULT;
+       if (__put_user(idx, &client->idx))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_GET_CLIENT, (unsigned long)client);
+       if (err)
+               return err;
+
+       if (__get_user(c32.auth, &client->auth)
+           || __get_user(c32.pid, &client->pid)
+           || __get_user(c32.uid, &client->uid)
+           || __get_user(c32.magic, &client->magic)
+           || __get_user(c32.iocs, &client->iocs))
+               return -EFAULT;
+
+       if (copy_to_user(argp, &c32, sizeof(c32)))
+               return -EFAULT;
+       return 0;
+}
+
+typedef struct drm_stats32 {
+       u32 count;
+       struct {
+               u32 value;
+               enum drm_stat_type type;
+       } data[15];
+} drm_stats32_t;
+
+static int compat_drm_getstats(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_stats32_t s32;
+       drm_stats32_t __user *argp = (void __user *)arg;
+       struct drm_stats __user *stats;
+       int i, err;
+
+       stats = compat_alloc_user_space(sizeof(*stats));
+       if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_GET_STATS, (unsigned long)stats);
+       if (err)
+               return err;
+
+       if (__get_user(s32.count, &stats->count))
+               return -EFAULT;
+       for (i = 0; i < 15; ++i)
+               if (__get_user(s32.data[i].value, &stats->data[i].value)
+                   || __get_user(s32.data[i].type, &stats->data[i].type))
+                       return -EFAULT;
+
+       if (copy_to_user(argp, &s32, sizeof(s32)))
+               return -EFAULT;
+       return 0;
+}
+
+typedef struct drm_buf_desc32 {
+       int count;               /**< Number of buffers of this size */
+       int size;                /**< Size in bytes */
+       int low_mark;            /**< Low water mark */
+       int high_mark;           /**< High water mark */
+       int flags;
+       u32 agp_start;           /**< Start address in the AGP aperture */
+} drm_buf_desc32_t;
+
+static int compat_drm_addbufs(struct file *file, unsigned int cmd,
+                             unsigned long arg)
+{
+       drm_buf_desc32_t __user *argp = (void __user *)arg;
+       struct drm_buf_desc __user *buf;
+       int err;
+       unsigned long agp_start;
+
+       buf = compat_alloc_user_space(sizeof(*buf));
+       if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf))
+           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)))
+               return -EFAULT;
+
+       if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start))
+           || __get_user(agp_start, &argp->agp_start)
+           || __put_user(agp_start, &buf->agp_start))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
+       if (err)
+               return err;
+
+       if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start))
+           || __get_user(agp_start, &buf->agp_start)
+           || __put_user(agp_start, &argp->agp_start))
+               return -EFAULT;
+
+       return 0;
+}
+
+static int compat_drm_markbufs(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_buf_desc32_t b32;
+       drm_buf_desc32_t __user *argp = (void __user *)arg;
+       struct drm_buf_desc __user *buf;
+
+       if (copy_from_user(&b32, argp, sizeof(b32)))
+               return -EFAULT;
+
+       buf = compat_alloc_user_space(sizeof(*buf));
+       if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))
+               return -EFAULT;
+
+       if (__put_user(b32.size, &buf->size)
+           || __put_user(b32.low_mark, &buf->low_mark)
+           || __put_user(b32.high_mark, &buf->high_mark))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
+}
+
+typedef struct drm_buf_info32 {
+       int count;              /**< Entries in list */
+       u32 list;
+} drm_buf_info32_t;
+
+static int compat_drm_infobufs(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_buf_info32_t req32;
+       drm_buf_info32_t __user *argp = (void __user *)arg;
+       drm_buf_desc32_t __user *to;
+       struct drm_buf_info __user *request;
+       struct drm_buf_desc __user *list;
+       size_t nbytes;
+       int i, err;
+       int count, actual;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       count = req32.count;
+       to = (drm_buf_desc32_t __user *) (unsigned long)req32.list;
+       if (count < 0)
+               count = 0;
+       if (count > 0
+           && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t)))
+               return -EFAULT;
+
+       nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc);
+       request = compat_alloc_user_space(nbytes);
+       if (!access_ok(VERIFY_WRITE, request, nbytes))
+               return -EFAULT;
+       list = (struct drm_buf_desc *) (request + 1);
+
+       if (__put_user(count, &request->count)
+           || __put_user(list, &request->list))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_INFO_BUFS, (unsigned long)request);
+       if (err)
+               return err;
+
+       if (__get_user(actual, &request->count))
+               return -EFAULT;
+       if (count >= actual)
+               for (i = 0; i < actual; ++i)
+                       if (__copy_in_user(&to[i], &list[i],
+                                          offsetof(struct drm_buf_desc, flags)))
+                               return -EFAULT;
+
+       if (__put_user(actual, &argp->count))
+               return -EFAULT;
+
+       return 0;
+}
+
+typedef struct drm_buf_pub32 {
+       int idx;                /**< Index into the master buffer list */
+       int total;              /**< Buffer size */
+       int used;               /**< Amount of buffer in use (for DMA) */
+       u32 address;            /**< Address of buffer */
+} drm_buf_pub32_t;
+
+typedef struct drm_buf_map32 {
+       int count;              /**< Length of the buffer list */
+       u32 virtual;            /**< Mmap'd area in user-virtual */
+       u32 list;               /**< Buffer information */
+} drm_buf_map32_t;
+
+static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
+                             unsigned long arg)
+{
+       drm_buf_map32_t __user *argp = (void __user *)arg;
+       drm_buf_map32_t req32;
+       drm_buf_pub32_t __user *list32;
+       struct drm_buf_map __user *request;
+       struct drm_buf_pub __user *list;
+       int i, err;
+       int count, actual;
+       size_t nbytes;
+       void __user *addr;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+       count = req32.count;
+       list32 = (void __user *)(unsigned long)req32.list;
+
+       if (count < 0)
+               return -EINVAL;
+       nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
+       request = compat_alloc_user_space(nbytes);
+       if (!access_ok(VERIFY_WRITE, request, nbytes))
+               return -EFAULT;
+       list = (struct drm_buf_pub *) (request + 1);
+
+       if (__put_user(count, &request->count)
+           || __put_user(list, &request->list))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_MAP_BUFS, (unsigned long)request);
+       if (err)
+               return err;
+
+       if (__get_user(actual, &request->count))
+               return -EFAULT;
+       if (count >= actual)
+               for (i = 0; i < actual; ++i)
+                       if (__copy_in_user(&list32[i], &list[i],
+                                          offsetof(struct drm_buf_pub, address))
+                           || __get_user(addr, &list[i].address)
+                           || __put_user((unsigned long)addr,
+                                         &list32[i].address))
+                               return -EFAULT;
+
+       if (__put_user(actual, &argp->count)
+           || __get_user(addr, &request->virtual)
+           || __put_user((unsigned long)addr, &argp->virtual))
+               return -EFAULT;
+
+       return 0;
+}
+
+typedef struct drm_buf_free32 {
+       int count;
+       u32 list;
+} drm_buf_free32_t;
+
+static int compat_drm_freebufs(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_buf_free32_t req32;
+       struct drm_buf_free __user *request;
+       drm_buf_free32_t __user *argp = (void __user *)arg;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
+               return -EFAULT;
+       if (__put_user(req32.count, &request->count)
+           || __put_user((int __user *)(unsigned long)req32.list,
+                         &request->list))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_FREE_BUFS, (unsigned long)request);
+}
+
+typedef struct drm_ctx_priv_map32 {
+       unsigned int ctx_id;     /**< Context requesting private mapping */
+       u32 handle;             /**< Handle of map */
+} drm_ctx_priv_map32_t;
+
+static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
+                                 unsigned long arg)
+{
+       drm_ctx_priv_map32_t req32;
+       struct drm_ctx_priv_map __user *request;
+       drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
+               return -EFAULT;
+       if (__put_user(req32.ctx_id, &request->ctx_id)
+           || __put_user((void *)(unsigned long)req32.handle,
+                         &request->handle))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
+}
+
+static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
+                                 unsigned long arg)
+{
+       struct drm_ctx_priv_map __user *request;
+       drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
+       int err;
+       unsigned int ctx_id;
+       void *handle;
+
+       if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp))
+           || __get_user(ctx_id, &argp->ctx_id))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request)))
+               return -EFAULT;
+       if (__put_user(ctx_id, &request->ctx_id))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
+       if (err)
+               return err;
+
+       if (__get_user(handle, &request->handle)
+           || __put_user((unsigned long)handle, &argp->handle))
+               return -EFAULT;
+
+       return 0;
+}
+
+typedef struct drm_ctx_res32 {
+       int count;
+       u32 contexts;
+} drm_ctx_res32_t;
+
+static int compat_drm_resctx(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       drm_ctx_res32_t __user *argp = (void __user *)arg;
+       drm_ctx_res32_t res32;
+       struct drm_ctx_res __user *res;
+       int err;
+
+       if (copy_from_user(&res32, argp, sizeof(res32)))
+               return -EFAULT;
+
+       res = compat_alloc_user_space(sizeof(*res));
+       if (!access_ok(VERIFY_WRITE, res, sizeof(*res)))
+               return -EFAULT;
+       if (__put_user(res32.count, &res->count)
+           || __put_user((struct drm_ctx __user *) (unsigned long)res32.contexts,
+                         &res->contexts))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_RES_CTX, (unsigned long)res);
+       if (err)
+               return err;
+
+       if (__get_user(res32.count, &res->count)
+           || __put_user(res32.count, &argp->count))
+               return -EFAULT;
+
+       return 0;
+}
+
+typedef struct drm_dma32 {
+       int context;              /**< Context handle */
+       int send_count;           /**< Number of buffers to send */
+       u32 send_indices;         /**< List of handles to buffers */
+       u32 send_sizes;           /**< Lengths of data to send */
+       enum drm_dma_flags flags;                 /**< Flags */
+       int request_count;        /**< Number of buffers requested */
+       int request_size;         /**< Desired size for buffers */
+       u32 request_indices;      /**< Buffer information */
+       u32 request_sizes;
+       int granted_count;        /**< Number of buffers granted */
+} drm_dma32_t;
+
+static int compat_drm_dma(struct file *file, unsigned int cmd,
+                         unsigned long arg)
+{
+       drm_dma32_t d32;
+       drm_dma32_t __user *argp = (void __user *)arg;
+       struct drm_dma __user *d;
+       int err;
+
+       if (copy_from_user(&d32, argp, sizeof(d32)))
+               return -EFAULT;
+
+       d = compat_alloc_user_space(sizeof(*d));
+       if (!access_ok(VERIFY_WRITE, d, sizeof(*d)))
+               return -EFAULT;
+
+       if (__put_user(d32.context, &d->context)
+           || __put_user(d32.send_count, &d->send_count)
+           || __put_user((int __user *)(unsigned long)d32.send_indices,
+                         &d->send_indices)
+           || __put_user((int __user *)(unsigned long)d32.send_sizes,
+                         &d->send_sizes)
+           || __put_user(d32.flags, &d->flags)
+           || __put_user(d32.request_count, &d->request_count)
+           || __put_user((int __user *)(unsigned long)d32.request_indices,
+                         &d->request_indices)
+           || __put_user((int __user *)(unsigned long)d32.request_sizes,
+                         &d->request_sizes))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_DMA, (unsigned long)d);
+       if (err)
+               return err;
+
+       if (__get_user(d32.request_size, &d->request_size)
+           || __get_user(d32.granted_count, &d->granted_count)
+           || __put_user(d32.request_size, &argp->request_size)
+           || __put_user(d32.granted_count, &argp->granted_count))
+               return -EFAULT;
+
+       return 0;
+}
+
+#if __OS_HAS_AGP
+typedef struct drm_agp_mode32 {
+       u32 mode;       /**< AGP mode */
+} drm_agp_mode32_t;
+
+static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
+                                unsigned long arg)
+{
+       drm_agp_mode32_t __user *argp = (void __user *)arg;
+       drm_agp_mode32_t m32;
+       struct drm_agp_mode __user *mode;
+
+       if (get_user(m32.mode, &argp->mode))
+               return -EFAULT;
+
+       mode = compat_alloc_user_space(sizeof(*mode));
+       if (put_user(m32.mode, &mode->mode))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
+}
+
+typedef struct drm_agp_info32 {
+       int agp_version_major;
+       int agp_version_minor;
+       u32 mode;
+       u32 aperture_base;      /* physical address */
+       u32 aperture_size;      /* bytes */
+       u32 memory_allowed;     /* bytes */
+       u32 memory_used;
+
+       /* PCI information */
+       unsigned short id_vendor;
+       unsigned short id_device;
+} drm_agp_info32_t;
+
+static int compat_drm_agp_info(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_agp_info32_t __user *argp = (void __user *)arg;
+       drm_agp_info32_t i32;
+       struct drm_agp_info __user *info;
+       int err;
+
+       info = compat_alloc_user_space(sizeof(*info));
+       if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_AGP_INFO, (unsigned long)info);
+       if (err)
+               return err;
+
+       if (__get_user(i32.agp_version_major, &info->agp_version_major)
+           || __get_user(i32.agp_version_minor, &info->agp_version_minor)
+           || __get_user(i32.mode, &info->mode)
+           || __get_user(i32.aperture_base, &info->aperture_base)
+           || __get_user(i32.aperture_size, &info->aperture_size)
+           || __get_user(i32.memory_allowed, &info->memory_allowed)
+           || __get_user(i32.memory_used, &info->memory_used)
+           || __get_user(i32.id_vendor, &info->id_vendor)
+           || __get_user(i32.id_device, &info->id_device))
+               return -EFAULT;
+
+       if (copy_to_user(argp, &i32, sizeof(i32)))
+               return -EFAULT;
+
+       return 0;
+}
+
+typedef struct drm_agp_buffer32 {
+       u32 size;       /**< In bytes -- will round to page boundary */
+       u32 handle;     /**< Used for binding / unbinding */
+       u32 type;       /**< Type of memory to allocate */
+       u32 physical;   /**< Physical used by i810 */
+} drm_agp_buffer32_t;
+
+static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_agp_buffer32_t __user *argp = (void __user *)arg;
+       drm_agp_buffer32_t req32;
+       struct drm_agp_buffer __user *request;
+       int err;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.size, &request->size)
+           || __put_user(req32.type, &request->type))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
+       if (err)
+               return err;
+
+       if (__get_user(req32.handle, &request->handle)
+           || __get_user(req32.physical, &request->physical)
+           || copy_to_user(argp, &req32, sizeof(req32))) {
+               drm_ioctl(file->f_path.dentry->d_inode, file,
+                         DRM_IOCTL_AGP_FREE, (unsigned long)request);
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int compat_drm_agp_free(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_agp_buffer32_t __user *argp = (void __user *)arg;
+       struct drm_agp_buffer __user *request;
+       u32 handle;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || get_user(handle, &argp->handle)
+           || __put_user(handle, &request->handle))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_AGP_FREE, (unsigned long)request);
+}
+
+typedef struct drm_agp_binding32 {
+       u32 handle;     /**< From drm_agp_buffer */
+       u32 offset;     /**< In bytes -- will round to page boundary */
+} drm_agp_binding32_t;
+
+static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_agp_binding32_t __user *argp = (void __user *)arg;
+       drm_agp_binding32_t req32;
+       struct drm_agp_binding __user *request;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.handle, &request->handle)
+           || __put_user(req32.offset, &request->offset))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_AGP_BIND, (unsigned long)request);
+}
+
+static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
+                                unsigned long arg)
+{
+       drm_agp_binding32_t __user *argp = (void __user *)arg;
+       struct drm_agp_binding __user *request;
+       u32 handle;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || get_user(handle, &argp->handle)
+           || __put_user(handle, &request->handle))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
+}
+#endif                         /* __OS_HAS_AGP */
+
+typedef struct drm_scatter_gather32 {
+       u32 size;       /**< In bytes -- will round to page boundary */
+       u32 handle;     /**< Used for mapping / unmapping */
+} drm_scatter_gather32_t;
+
+static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_scatter_gather32_t __user *argp = (void __user *)arg;
+       struct drm_scatter_gather __user *request;
+       int err;
+       unsigned long x;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
+           || __get_user(x, &argp->size)
+           || __put_user(x, &request->size))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_SG_ALLOC, (unsigned long)request);
+       if (err)
+               return err;
+
+       /* XXX not sure about the handle conversion here... */
+       if (__get_user(x, &request->handle)
+           || __put_user(x >> PAGE_SHIFT, &argp->handle))
+               return -EFAULT;
+
+       return 0;
+}
+
+static int compat_drm_sg_free(struct file *file, unsigned int cmd,
+                             unsigned long arg)
+{
+       drm_scatter_gather32_t __user *argp = (void __user *)arg;
+       struct drm_scatter_gather __user *request;
+       unsigned long x;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
+           || __get_user(x, &argp->handle)
+           || __put_user(x << PAGE_SHIFT, &request->handle))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_SG_FREE, (unsigned long)request);
+}
+
+struct drm_wait_vblank_request32 {
+       enum drm_vblank_seq_type type;
+       unsigned int sequence;
+       u32 signal;
+};
+
+struct drm_wait_vblank_reply32 {
+       enum drm_vblank_seq_type type;
+       unsigned int sequence;
+       s32 tval_sec;
+       s32 tval_usec;
+};
+
+typedef union drm_wait_vblank32 {
+       struct drm_wait_vblank_request32 request;
+       struct drm_wait_vblank_reply32 reply;
+} drm_wait_vblank32_t;
+
+static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
+                                 unsigned long arg)
+{
+       drm_wait_vblank32_t __user *argp = (void __user *)arg;
+       drm_wait_vblank32_t req32;
+       union drm_wait_vblank __user *request;
+       int err;
+
+       if (copy_from_user(&req32, argp, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.request.type, &request->request.type)
+           || __put_user(req32.request.sequence, &request->request.sequence)
+           || __put_user(req32.request.signal, &request->request.signal))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
+       if (err)
+               return err;
+
+       if (__get_user(req32.reply.type, &request->reply.type)
+           || __get_user(req32.reply.sequence, &request->reply.sequence)
+           || __get_user(req32.reply.tval_sec, &request->reply.tval_sec)
+           || __get_user(req32.reply.tval_usec, &request->reply.tval_usec))
+               return -EFAULT;
+
+       if (copy_to_user(argp, &req32, sizeof(req32)))
+               return -EFAULT;
+
+       return 0;
+}
+
+drm_ioctl_compat_t *drm_compat_ioctls[] = {
+       [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient,
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats,
+       [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique,
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap,
+       [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs,
+       [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs,
+       [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs,
+       [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs,
+       [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs,
+       [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap,
+       [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx,
+       [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx,
+       [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx,
+       [DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma,
+#if __OS_HAS_AGP
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable,
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info,
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc,
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free,
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind,
+       [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind,
+#endif
+       [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
+       [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
+       [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
+};
+
+/**
+ * Called whenever a 32-bit process running under a 64-bit kernel
+ * performs an ioctl on /dev/drm.
+ *
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ */
+long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       drm_ioctl_compat_t *fn;
+       int ret;
+
+       /* Assume that ioctls without an explicit compat routine will just
+        * work.  This may not always be a good assumption, but it's better
+        * than always failing.
+        */
+       if (nr >= ARRAY_SIZE(drm_compat_ioctls))
+               return drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
+
+       fn = drm_compat_ioctls[nr];
+
+       lock_kernel();          /* XXX for now */
+       if (fn != NULL)
+               ret = (*fn) (filp, cmd, arg);
+       else
+               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
+
+EXPORT_SYMBOL(drm_compat_ioctl);
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
new file mode 100644 (file)
index 0000000..16829fb
--- /dev/null
@@ -0,0 +1,352 @@
+/**
+ * \file drm_ioctl.c
+ * IOCTL processing for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Jan  8 09:01:26 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm_core.h"
+
+#include "linux/pci.h"
+
+/**
+ * Get the bus id.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_unique structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Copies the bus id from drm_device::unique into user space.
+ */
+int drm_getunique(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       struct drm_unique *u = data;
+
+       if (u->unique_len >= dev->unique_len) {
+               if (copy_to_user(u->unique, dev->unique, dev->unique_len))
+                       return -EFAULT;
+       }
+       u->unique_len = dev->unique_len;
+
+       return 0;
+}
+
+/**
+ * Set the bus id.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_unique structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Copies the bus id from userspace into drm_device::unique, and verifies that
+ * it matches the device this DRM is attached to (EINVAL otherwise).  Deprecated
+ * in interface version 1.1 and will return EBUSY when setversion has requested
+ * version 1.1 or greater.
+ */
+int drm_setunique(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       struct drm_unique *u = data;
+       int domain, bus, slot, func, ret;
+
+       if (dev->unique_len || dev->unique)
+               return -EBUSY;
+
+       if (!u->unique_len || u->unique_len > 1024)
+               return -EINVAL;
+
+       dev->unique_len = u->unique_len;
+       dev->unique = drm_alloc(u->unique_len + 1, DRM_MEM_DRIVER);
+       if (!dev->unique)
+               return -ENOMEM;
+       if (copy_from_user(dev->unique, u->unique, dev->unique_len))
+               return -EFAULT;
+
+       dev->unique[dev->unique_len] = '\0';
+
+       dev->devname =
+           drm_alloc(strlen(dev->driver->pci_driver.name) +
+                     strlen(dev->unique) + 2, DRM_MEM_DRIVER);
+       if (!dev->devname)
+               return -ENOMEM;
+
+       sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
+               dev->unique);
+
+       /* Return error if the busid submitted doesn't match the device's actual
+        * busid.
+        */
+       ret = sscanf(dev->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
+       if (ret != 3)
+               return -EINVAL;
+       domain = bus >> 8;
+       bus &= 0xff;
+
+       if ((domain != drm_get_pci_domain(dev)) ||
+           (bus != dev->pdev->bus->number) ||
+           (slot != PCI_SLOT(dev->pdev->devfn)) ||
+           (func != PCI_FUNC(dev->pdev->devfn)))
+               return -EINVAL;
+
+       return 0;
+}
+
+static int drm_set_busid(struct drm_device * dev)
+{
+       int len;
+
+       if (dev->unique != NULL)
+               return 0;
+
+       dev->unique_len = 40;
+       dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
+       if (dev->unique == NULL)
+               return -ENOMEM;
+
+       len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d",
+                      drm_get_pci_domain(dev), dev->pdev->bus->number,
+                      PCI_SLOT(dev->pdev->devfn),
+                      PCI_FUNC(dev->pdev->devfn));
+
+       if (len > dev->unique_len)
+               DRM_ERROR("Unique buffer overflowed\n");
+
+       dev->devname =
+           drm_alloc(strlen(dev->driver->pci_driver.name) + dev->unique_len +
+                     2, DRM_MEM_DRIVER);
+       if (dev->devname == NULL)
+               return -ENOMEM;
+
+       sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
+               dev->unique);
+
+       return 0;
+}
+
+/**
+ * Get a mapping information.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_map structure.
+ *
+ * \return zero on success or a negative number on failure.
+ *
+ * Searches for the mapping with the specified offset and copies its information
+ * into userspace
+ */
+int drm_getmap(struct drm_device *dev, void *data,
+              struct drm_file *file_priv)
+{
+       struct drm_map *map = data;
+       struct drm_map_list *r_list = NULL;
+       struct list_head *list;
+       int idx;
+       int i;
+
+       idx = map->offset;
+
+       mutex_lock(&dev->struct_mutex);
+       if (idx < 0) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       i = 0;
+       list_for_each(list, &dev->maplist) {
+               if (i == idx) {
+                       r_list = list_entry(list, struct drm_map_list, head);
+                       break;
+               }
+               i++;
+       }
+       if (!r_list || !r_list->map) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       map->offset = r_list->map->offset;
+       map->size = r_list->map->size;
+       map->type = r_list->map->type;
+       map->flags = r_list->map->flags;
+       map->handle = (void *)(unsigned long) r_list->user_token;
+       map->mtrr = r_list->map->mtrr;
+       mutex_unlock(&dev->struct_mutex);
+
+       return 0;
+}
+
+/**
+ * Get client information.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_client structure.
+ *
+ * \return zero on success or a negative number on failure.
+ *
+ * Searches for the client with the specified index and copies its information
+ * into userspace
+ */
+int drm_getclient(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       struct drm_client *client = data;
+       struct drm_file *pt;
+       int idx;
+       int i;
+
+       idx = client->idx;
+       mutex_lock(&dev->struct_mutex);
+
+       i = 0;
+       list_for_each_entry(pt, &dev->filelist, lhead) {
+               if (i++ >= idx) {
+                       client->auth = pt->authenticated;
+                       client->pid = pt->pid;
+                       client->uid = pt->uid;
+                       client->magic = pt->magic;
+                       client->iocs = pt->ioctl_count;
+                       mutex_unlock(&dev->struct_mutex);
+
+                       return 0;
+               }
+       }
+       mutex_unlock(&dev->struct_mutex);
+
+       return -EINVAL;
+}
+
+/**
+ * Get statistics information.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_stats structure.
+ *
+ * \return zero on success or a negative number on failure.
+ */
+int drm_getstats(struct drm_device *dev, void *data,
+                struct drm_file *file_priv)
+{
+       struct drm_stats *stats = data;
+       int i;
+
+       memset(stats, 0, sizeof(*stats));
+
+       mutex_lock(&dev->struct_mutex);
+
+       for (i = 0; i < dev->counters; i++) {
+               if (dev->types[i] == _DRM_STAT_LOCK)
+                       stats->data[i].value =
+                           (dev->lock.hw_lock ? dev->lock.hw_lock->lock : 0);
+               else
+                       stats->data[i].value = atomic_read(&dev->counts[i]);
+               stats->data[i].type = dev->types[i];
+       }
+
+       stats->count = dev->counters;
+
+       mutex_unlock(&dev->struct_mutex);
+
+       return 0;
+}
+
+/**
+ * Setversion ioctl.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_lock structure.
+ * \return zero on success or negative number on failure.
+ *
+ * Sets the requested interface version
+ */
+int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_set_version *sv = data;
+       int if_version, retcode = 0;
+
+       if (sv->drm_di_major != -1) {
+               if (sv->drm_di_major != DRM_IF_MAJOR ||
+                   sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) {
+                       retcode = -EINVAL;
+                       goto done;
+               }
+               if_version = DRM_IF_VERSION(sv->drm_di_major,
+                                           sv->drm_di_minor);
+               dev->if_version = max(if_version, dev->if_version);
+               if (sv->drm_di_minor >= 1) {
+                       /*
+                        * Version 1.1 includes tying of DRM to specific device
+                        */
+                       drm_set_busid(dev);
+               }
+       }
+
+       if (sv->drm_dd_major != -1) {
+               if (sv->drm_dd_major != dev->driver->major ||
+                   sv->drm_dd_minor < 0 || sv->drm_dd_minor >
+                   dev->driver->minor) {
+                       retcode = -EINVAL;
+                       goto done;
+               }
+
+               if (dev->driver->set_version)
+                       dev->driver->set_version(dev, sv);
+       }
+
+done:
+       sv->drm_di_major = DRM_IF_MAJOR;
+       sv->drm_di_minor = DRM_IF_MINOR;
+       sv->drm_dd_major = dev->driver->major;
+       sv->drm_dd_minor = dev->driver->minor;
+
+       return retcode;
+}
+
+/** No-op ioctl. */
+int drm_noop(struct drm_device *dev, void *data,
+            struct drm_file *file_priv)
+{
+       DRM_DEBUG("\n");
+       return 0;
+}
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
new file mode 100644 (file)
index 0000000..089c015
--- /dev/null
@@ -0,0 +1,462 @@
+/**
+ * \file drm_irq.c
+ * IRQ support
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+#include <linux/interrupt.h>   /* For task queue support */
+
+/**
+ * Get interrupt from bus id.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_irq_busid structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Finds the PCI device with the specified bus id and gets its IRQ number.
+ * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
+ * to that of the device that this DRM instance attached to.
+ */
+int drm_irq_by_busid(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv)
+{
+       struct drm_irq_busid *p = data;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
+               return -EINVAL;
+
+       if ((p->busnum >> 8) != drm_get_pci_domain(dev) ||
+           (p->busnum & 0xff) != dev->pdev->bus->number ||
+           p->devnum != PCI_SLOT(dev->pdev->devfn) || p->funcnum != PCI_FUNC(dev->pdev->devfn))
+               return -EINVAL;
+
+       p->irq = dev->irq;
+
+       DRM_DEBUG("%d:%d:%d => IRQ %d\n", p->busnum, p->devnum, p->funcnum,
+                 p->irq);
+
+       return 0;
+}
+
+/**
+ * Install IRQ handler.
+ *
+ * \param dev DRM device.
+ * \param irq IRQ number.
+ *
+ * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
+ * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions
+ * before and after the installation.
+ */
+static int drm_irq_install(struct drm_device * dev)
+{
+       int ret;
+       unsigned long sh_flags = 0;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
+               return -EINVAL;
+
+       if (dev->irq == 0)
+               return -EINVAL;
+
+       mutex_lock(&dev->struct_mutex);
+
+       /* Driver must have been initialized */
+       if (!dev->dev_private) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       if (dev->irq_enabled) {
+               mutex_unlock(&dev->struct_mutex);
+               return -EBUSY;
+       }
+       dev->irq_enabled = 1;
+       mutex_unlock(&dev->struct_mutex);
+
+       DRM_DEBUG("irq=%d\n", dev->irq);
+
+       if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) {
+               init_waitqueue_head(&dev->vbl_queue);
+
+               spin_lock_init(&dev->vbl_lock);
+
+               INIT_LIST_HEAD(&dev->vbl_sigs);
+               INIT_LIST_HEAD(&dev->vbl_sigs2);
+
+               dev->vbl_pending = 0;
+       }
+
+       /* Before installing handler */
+       dev->driver->irq_preinstall(dev);
+
+       /* Install handler */
+       if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
+               sh_flags = IRQF_SHARED;
+
+       ret = request_irq(dev->irq, dev->driver->irq_handler,
+                         sh_flags, dev->devname, dev);
+       if (ret < 0) {
+               mutex_lock(&dev->struct_mutex);
+               dev->irq_enabled = 0;
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       /* After installing handler */
+       dev->driver->irq_postinstall(dev);
+
+       return 0;
+}
+
+/**
+ * Uninstall the IRQ handler.
+ *
+ * \param dev DRM device.
+ *
+ * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq.
+ */
+int drm_irq_uninstall(struct drm_device * dev)
+{
+       int irq_enabled;
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
+               return -EINVAL;
+
+       mutex_lock(&dev->struct_mutex);
+       irq_enabled = dev->irq_enabled;
+       dev->irq_enabled = 0;
+       mutex_unlock(&dev->struct_mutex);
+
+       if (!irq_enabled)
+               return -EINVAL;
+
+       DRM_DEBUG("irq=%d\n", dev->irq);
+
+       dev->driver->irq_uninstall(dev);
+
+       free_irq(dev->irq, dev);
+
+       dev->locked_tasklet_func = NULL;
+
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_irq_uninstall);
+
+/**
+ * IRQ control ioctl.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_control structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls irq_install() or irq_uninstall() according to \p arg.
+ */
+int drm_control(struct drm_device *dev, void *data,
+               struct drm_file *file_priv)
+{
+       struct drm_control *ctl = data;
+
+       /* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */
+
+
+       switch (ctl->func) {
+       case DRM_INST_HANDLER:
+               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
+                       return 0;
+               if (dev->if_version < DRM_IF_VERSION(1, 2) &&
+                   ctl->irq != dev->irq)
+                       return -EINVAL;
+               return drm_irq_install(dev);
+       case DRM_UNINST_HANDLER:
+               if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
+                       return 0;
+               return drm_irq_uninstall(dev);
+       default:
+               return -EINVAL;
+       }
+}
+
+/**
+ * Wait for VBLANK.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param data user argument, pointing to a drm_wait_vblank structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the IRQ is installed.
+ *
+ * If a signal is requested checks if this task has already scheduled the same signal
+ * for the same vblank sequence number - nothing to be done in
+ * that case. If the number of tasks waiting for the interrupt exceeds 100 the
+ * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
+ * task.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       union drm_wait_vblank *vblwait = data;
+       struct timeval now;
+       int ret = 0;
+       unsigned int flags, seq;
+
+       if ((!dev->irq) || (!dev->irq_enabled))
+               return -EINVAL;
+
+       if (vblwait->request.type &
+           ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) {
+               DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n",
+                         vblwait->request.type,
+                         (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK));
+               return -EINVAL;
+       }
+
+       flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK;
+
+       if (!drm_core_check_feature(dev, (flags & _DRM_VBLANK_SECONDARY) ?
+                                   DRIVER_IRQ_VBL2 : DRIVER_IRQ_VBL))
+               return -EINVAL;
+
+       seq = atomic_read((flags & _DRM_VBLANK_SECONDARY) ? &dev->vbl_received2
+                         : &dev->vbl_received);
+
+       switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) {
+       case _DRM_VBLANK_RELATIVE:
+               vblwait->request.sequence += seq;
+               vblwait->request.type &= ~_DRM_VBLANK_RELATIVE;
+       case _DRM_VBLANK_ABSOLUTE:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if ((flags & _DRM_VBLANK_NEXTONMISS) &&
+           (seq - vblwait->request.sequence) <= (1<<23)) {
+               vblwait->request.sequence = seq + 1;
+       }
+
+       if (flags & _DRM_VBLANK_SIGNAL) {
+               unsigned long irqflags;
+               struct list_head *vbl_sigs = (flags & _DRM_VBLANK_SECONDARY)
+                                     ? &dev->vbl_sigs2 : &dev->vbl_sigs;
+               struct drm_vbl_sig *vbl_sig;
+
+               spin_lock_irqsave(&dev->vbl_lock, irqflags);
+
+               /* Check if this task has already scheduled the same signal
+                * for the same vblank sequence number; nothing to be done in
+                * that case
+                */
+               list_for_each_entry(vbl_sig, vbl_sigs, head) {
+                       if (vbl_sig->sequence == vblwait->request.sequence
+                           && vbl_sig->info.si_signo ==
+                           vblwait->request.signal
+                           && vbl_sig->task == current) {
+                               spin_unlock_irqrestore(&dev->vbl_lock,
+                                                      irqflags);
+                               vblwait->reply.sequence = seq;
+                               goto done;
+                       }
+               }
+
+               if (dev->vbl_pending >= 100) {
+                       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+                       return -EBUSY;
+               }
+
+               dev->vbl_pending++;
+
+               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+
+               if (!
+                   (vbl_sig =
+                    drm_alloc(sizeof(struct drm_vbl_sig), DRM_MEM_DRIVER))) {
+                       return -ENOMEM;
+               }
+
+               memset((void *)vbl_sig, 0, sizeof(*vbl_sig));
+
+               vbl_sig->sequence = vblwait->request.sequence;
+               vbl_sig->info.si_signo = vblwait->request.signal;
+               vbl_sig->task = current;
+
+               spin_lock_irqsave(&dev->vbl_lock, irqflags);
+
+               list_add_tail(&vbl_sig->head, vbl_sigs);
+
+               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+
+               vblwait->reply.sequence = seq;
+       } else {
+               if (flags & _DRM_VBLANK_SECONDARY) {
+                       if (dev->driver->vblank_wait2)
+                               ret = dev->driver->vblank_wait2(dev, &vblwait->request.sequence);
+               } else if (dev->driver->vblank_wait)
+                       ret =
+                           dev->driver->vblank_wait(dev,
+                                                    &vblwait->request.sequence);
+
+               do_gettimeofday(&now);
+               vblwait->reply.tval_sec = now.tv_sec;
+               vblwait->reply.tval_usec = now.tv_usec;
+       }
+
+      done:
+       return ret;
+}
+
+/**
+ * Send the VBLANK signals.
+ *
+ * \param dev DRM device.
+ *
+ * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+void drm_vbl_send_signals(struct drm_device * dev)
+{
+       unsigned long flags;
+       int i;
+
+       spin_lock_irqsave(&dev->vbl_lock, flags);
+
+       for (i = 0; i < 2; i++) {
+               struct drm_vbl_sig *vbl_sig, *tmp;
+               struct list_head *vbl_sigs = i ? &dev->vbl_sigs2 : &dev->vbl_sigs;
+               unsigned int vbl_seq = atomic_read(i ? &dev->vbl_received2 :
+                                                  &dev->vbl_received);
+
+               list_for_each_entry_safe(vbl_sig, tmp, vbl_sigs, head) {
+                       if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
+                               vbl_sig->info.si_code = vbl_seq;
+                               send_sig_info(vbl_sig->info.si_signo,
+                                             &vbl_sig->info, vbl_sig->task);
+
+                               list_del(&vbl_sig->head);
+
+                               drm_free(vbl_sig, sizeof(*vbl_sig),
+                                        DRM_MEM_DRIVER);
+
+                               dev->vbl_pending--;
+                       }
+               }
+       }
+
+       spin_unlock_irqrestore(&dev->vbl_lock, flags);
+}
+
+EXPORT_SYMBOL(drm_vbl_send_signals);
+
+/**
+ * Tasklet wrapper function.
+ *
+ * \param data DRM device in disguise.
+ *
+ * Attempts to grab the HW lock and calls the driver callback on success. On
+ * failure, leave the lock marked as contended so the callback can be called
+ * from drm_unlock().
+ */
+static void drm_locked_tasklet_func(unsigned long data)
+{
+       struct drm_device *dev = (struct drm_device *)data;
+       unsigned long irqflags;
+
+       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
+
+       if (!dev->locked_tasklet_func ||
+           !drm_lock_take(&dev->lock,
+                          DRM_KERNEL_CONTEXT)) {
+               spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
+               return;
+       }
+
+       dev->lock.lock_time = jiffies;
+       atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
+
+       dev->locked_tasklet_func(dev);
+
+       drm_lock_free(&dev->lock,
+                     DRM_KERNEL_CONTEXT);
+
+       dev->locked_tasklet_func = NULL;
+
+       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
+}
+
+/**
+ * Schedule a tasklet to call back a driver hook with the HW lock held.
+ *
+ * \param dev DRM device.
+ * \param func Driver callback.
+ *
+ * This is intended for triggering actions that require the HW lock from an
+ * interrupt handler. The lock will be grabbed ASAP after the interrupt handler
+ * completes. Note that the callback may be called from interrupt or process
+ * context, it must not make any assumptions about this. Also, the HW lock will
+ * be held with the kernel context or any client context.
+ */
+void drm_locked_tasklet(struct drm_device *dev, void (*func)(struct drm_device *))
+{
+       unsigned long irqflags;
+       static DECLARE_TASKLET(drm_tasklet, drm_locked_tasklet_func, 0);
+
+       if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ) ||
+           test_bit(TASKLET_STATE_SCHED, &drm_tasklet.state))
+               return;
+
+       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
+
+       if (dev->locked_tasklet_func) {
+               spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
+               return;
+       }
+
+       dev->locked_tasklet_func = func;
+
+       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
+
+       drm_tasklet.data = (unsigned long)dev;
+
+       tasklet_hi_schedule(&drm_tasklet);
+}
+EXPORT_SYMBOL(drm_locked_tasklet);
diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
new file mode 100644 (file)
index 0000000..0998723
--- /dev/null
@@ -0,0 +1,391 @@
+/**
+ * \file drm_lock.c
+ * IOCTLs for locking
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Tue Feb  2 08:37:54 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+static int drm_notifier(void *priv);
+
+/**
+ * Lock ioctl.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_lock structure.
+ * \return zero on success or negative number on failure.
+ *
+ * Add the current task to the lock wait queue, and attempt to take to lock.
+ */
+int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       DECLARE_WAITQUEUE(entry, current);
+       struct drm_lock *lock = data;
+       int ret = 0;
+
+       ++file_priv->lock_count;
+
+       if (lock->context == DRM_KERNEL_CONTEXT) {
+               DRM_ERROR("Process %d using kernel context %d\n",
+                         task_pid_nr(current), lock->context);
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
+                 lock->context, task_pid_nr(current),
+                 dev->lock.hw_lock->lock, lock->flags);
+
+       if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE))
+               if (lock->context < 0)
+                       return -EINVAL;
+
+       add_wait_queue(&dev->lock.lock_queue, &entry);
+       spin_lock_bh(&dev->lock.spinlock);
+       dev->lock.user_waiters++;
+       spin_unlock_bh(&dev->lock.spinlock);
+       for (;;) {
+               __set_current_state(TASK_INTERRUPTIBLE);
+               if (!dev->lock.hw_lock) {
+                       /* Device has been unregistered */
+                       ret = -EINTR;
+                       break;
+               }
+               if (drm_lock_take(&dev->lock, lock->context)) {
+                       dev->lock.file_priv = file_priv;
+                       dev->lock.lock_time = jiffies;
+                       atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
+                       break;  /* Got lock */
+               }
+
+               /* Contention */
+               schedule();
+               if (signal_pending(current)) {
+                       ret = -ERESTARTSYS;
+                       break;
+               }
+       }
+       spin_lock_bh(&dev->lock.spinlock);
+       dev->lock.user_waiters--;
+       spin_unlock_bh(&dev->lock.spinlock);
+       __set_current_state(TASK_RUNNING);
+       remove_wait_queue(&dev->lock.lock_queue, &entry);
+
+       DRM_DEBUG("%d %s\n", lock->context,
+                 ret ? "interrupted" : "has lock");
+       if (ret) return ret;
+
+       sigemptyset(&dev->sigmask);
+       sigaddset(&dev->sigmask, SIGSTOP);
+       sigaddset(&dev->sigmask, SIGTSTP);
+       sigaddset(&dev->sigmask, SIGTTIN);
+       sigaddset(&dev->sigmask, SIGTTOU);
+       dev->sigdata.context = lock->context;
+       dev->sigdata.lock = dev->lock.hw_lock;
+       block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
+
+       if (dev->driver->dma_ready && (lock->flags & _DRM_LOCK_READY))
+               dev->driver->dma_ready(dev);
+
+       if (dev->driver->dma_quiescent && (lock->flags & _DRM_LOCK_QUIESCENT))
+       {
+               if (dev->driver->dma_quiescent(dev)) {
+                       DRM_DEBUG("%d waiting for DMA quiescent\n",
+                                 lock->context);
+                       return -EBUSY;
+               }
+       }
+
+       if (dev->driver->kernel_context_switch &&
+           dev->last_context != lock->context) {
+               dev->driver->kernel_context_switch(dev, dev->last_context,
+                                                  lock->context);
+       }
+
+       return 0;
+}
+
+/**
+ * Unlock ioctl.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_lock structure.
+ * \return zero on success or negative number on failure.
+ *
+ * Transfer and free the lock.
+ */
+int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_lock *lock = data;
+       unsigned long irqflags;
+
+       if (lock->context == DRM_KERNEL_CONTEXT) {
+               DRM_ERROR("Process %d using kernel context %d\n",
+                         task_pid_nr(current), lock->context);
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&dev->tasklet_lock, irqflags);
+
+       if (dev->locked_tasklet_func) {
+               dev->locked_tasklet_func(dev);
+
+               dev->locked_tasklet_func = NULL;
+       }
+
+       spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
+
+       atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
+
+       /* kernel_context_switch isn't used by any of the x86 drm
+        * modules but is required by the Sparc driver.
+        */
+       if (dev->driver->kernel_context_switch_unlock)
+               dev->driver->kernel_context_switch_unlock(dev);
+       else {
+               if (drm_lock_free(&dev->lock,lock->context)) {
+                       /* FIXME: Should really bail out here. */
+               }
+       }
+
+       unblock_all_signals();
+       return 0;
+}
+
+/**
+ * Take the heavyweight lock.
+ *
+ * \param lock lock pointer.
+ * \param context locking context.
+ * \return one if the lock is held, or zero otherwise.
+ *
+ * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
+ */
+int drm_lock_take(struct drm_lock_data *lock_data,
+                 unsigned int context)
+{
+       unsigned int old, new, prev;
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+
+       spin_lock_bh(&lock_data->spinlock);
+       do {
+               old = *lock;
+               if (old & _DRM_LOCK_HELD)
+                       new = old | _DRM_LOCK_CONT;
+               else {
+                       new = context | _DRM_LOCK_HELD |
+                               ((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
+                                _DRM_LOCK_CONT : 0);
+               }
+               prev = cmpxchg(lock, old, new);
+       } while (prev != old);
+       spin_unlock_bh(&lock_data->spinlock);
+
+       if (_DRM_LOCKING_CONTEXT(old) == context) {
+               if (old & _DRM_LOCK_HELD) {
+                       if (context != DRM_KERNEL_CONTEXT) {
+                               DRM_ERROR("%d holds heavyweight lock\n",
+                                         context);
+                       }
+                       return 0;
+               }
+       }
+
+       if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
+               /* Have lock */
+               return 1;
+       }
+       return 0;
+}
+
+/**
+ * This takes a lock forcibly and hands it to context. Should ONLY be used
+ * inside *_unlock to give lock to kernel before calling *_dma_schedule.
+ *
+ * \param dev DRM device.
+ * \param lock lock pointer.
+ * \param context locking context.
+ * \return always one.
+ *
+ * Resets the lock file pointer.
+ * Marks the lock as held by the given context, via the \p cmpxchg instruction.
+ */
+static int drm_lock_transfer(struct drm_lock_data *lock_data,
+                            unsigned int context)
+{
+       unsigned int old, new, prev;
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+
+       lock_data->file_priv = NULL;
+       do {
+               old = *lock;
+               new = context | _DRM_LOCK_HELD;
+               prev = cmpxchg(lock, old, new);
+       } while (prev != old);
+       return 1;
+}
+
+/**
+ * Free lock.
+ *
+ * \param dev DRM device.
+ * \param lock lock.
+ * \param context context.
+ *
+ * Resets the lock file pointer.
+ * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
+ * waiting on the lock queue.
+ */
+int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context)
+{
+       unsigned int old, new, prev;
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+
+       spin_lock_bh(&lock_data->spinlock);
+       if (lock_data->kernel_waiters != 0) {
+               drm_lock_transfer(lock_data, 0);
+               lock_data->idle_has_lock = 1;
+               spin_unlock_bh(&lock_data->spinlock);
+               return 1;
+       }
+       spin_unlock_bh(&lock_data->spinlock);
+
+       do {
+               old = *lock;
+               new = _DRM_LOCKING_CONTEXT(old);
+               prev = cmpxchg(lock, old, new);
+       } while (prev != old);
+
+       if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
+               DRM_ERROR("%d freed heavyweight lock held by %d\n",
+                         context, _DRM_LOCKING_CONTEXT(old));
+               return 1;
+       }
+       wake_up_interruptible(&lock_data->lock_queue);
+       return 0;
+}
+
+/**
+ * If we get here, it means that the process has called DRM_IOCTL_LOCK
+ * without calling DRM_IOCTL_UNLOCK.
+ *
+ * If the lock is not held, then let the signal proceed as usual.  If the lock
+ * is held, then set the contended flag and keep the signal blocked.
+ *
+ * \param priv pointer to a drm_sigdata structure.
+ * \return one if the signal should be delivered normally, or zero if the
+ * signal should be blocked.
+ */
+static int drm_notifier(void *priv)
+{
+       struct drm_sigdata *s = (struct drm_sigdata *) priv;
+       unsigned int old, new, prev;
+
+       /* Allow signal delivery if lock isn't held */
+       if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
+           || _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context)
+               return 1;
+
+       /* Otherwise, set flag to force call to
+          drmUnlock */
+       do {
+               old = s->lock->lock;
+               new = old | _DRM_LOCK_CONT;
+               prev = cmpxchg(&s->lock->lock, old, new);
+       } while (prev != old);
+       return 0;
+}
+
+/**
+ * This function returns immediately and takes the hw lock
+ * with the kernel context if it is free, otherwise it gets the highest priority when and if
+ * it is eventually released.
+ *
+ * This guarantees that the kernel will _eventually_ have the lock _unless_ it is held
+ * by a blocked process. (In the latter case an explicit wait for the hardware lock would cause
+ * a deadlock, which is why the "idlelock" was invented).
+ *
+ * This should be sufficient to wait for GPU idle without
+ * having to worry about starvation.
+ */
+
+void drm_idlelock_take(struct drm_lock_data *lock_data)
+{
+       int ret = 0;
+
+       spin_lock_bh(&lock_data->spinlock);
+       lock_data->kernel_waiters++;
+       if (!lock_data->idle_has_lock) {
+
+               spin_unlock_bh(&lock_data->spinlock);
+               ret = drm_lock_take(lock_data, DRM_KERNEL_CONTEXT);
+               spin_lock_bh(&lock_data->spinlock);
+
+               if (ret == 1)
+                       lock_data->idle_has_lock = 1;
+       }
+       spin_unlock_bh(&lock_data->spinlock);
+}
+EXPORT_SYMBOL(drm_idlelock_take);
+
+void drm_idlelock_release(struct drm_lock_data *lock_data)
+{
+       unsigned int old, prev;
+       volatile unsigned int *lock = &lock_data->hw_lock->lock;
+
+       spin_lock_bh(&lock_data->spinlock);
+       if (--lock_data->kernel_waiters == 0) {
+               if (lock_data->idle_has_lock) {
+                       do {
+                               old = *lock;
+                               prev = cmpxchg(lock, old, DRM_KERNEL_CONTEXT);
+                       } while (prev != old);
+                       wake_up_interruptible(&lock_data->lock_queue);
+                       lock_data->idle_has_lock = 0;
+               }
+       }
+       spin_unlock_bh(&lock_data->spinlock);
+}
+EXPORT_SYMBOL(drm_idlelock_release);
+
+
+int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv)
+{
+       return (file_priv->lock_count && dev->lock.hw_lock &&
+               _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
+               dev->lock.file_priv == file_priv);
+}
+
+EXPORT_SYMBOL(drm_i_have_hw_lock);
diff --git a/drivers/gpu/drm/drm_memory.c b/drivers/gpu/drm/drm_memory.c
new file mode 100644 (file)
index 0000000..845081b
--- /dev/null
@@ -0,0 +1,181 @@
+/**
+ * \file drm_memory.c
+ * Memory management wrappers for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/highmem.h>
+#include "drmP.h"
+
+#ifdef DEBUG_MEMORY
+#include "drm_memory_debug.h"
+#else
+
+/** No-op. */
+void drm_mem_init(void)
+{
+}
+
+/**
+ * Called when "/proc/dri/%dev%/mem" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param len requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ *
+ * No-op.
+ */
+int drm_mem_info(char *buf, char **start, off_t offset,
+                int len, int *eof, void *data)
+{
+       return 0;
+}
+
+/** Wrapper around kmalloc() and kfree() */
+void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
+{
+       void *pt;
+
+       if (!(pt = kmalloc(size, GFP_KERNEL)))
+               return NULL;
+       if (oldpt && oldsize) {
+               memcpy(pt, oldpt, oldsize);
+               kfree(oldpt);
+       }
+       return pt;
+}
+
+#if __OS_HAS_AGP
+static void *agp_remap(unsigned long offset, unsigned long size,
+                      struct drm_device * dev)
+{
+       unsigned long *phys_addr_map, i, num_pages =
+           PAGE_ALIGN(size) / PAGE_SIZE;
+       struct drm_agp_mem *agpmem;
+       struct page **page_map;
+       void *addr;
+
+       size = PAGE_ALIGN(size);
+
+#ifdef __alpha__
+       offset -= dev->hose->mem_space->start;
+#endif
+
+       list_for_each_entry(agpmem, &dev->agp->memory, head)
+               if (agpmem->bound <= offset
+                   && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
+                   (offset + size))
+                       break;
+       if (!agpmem)
+               return NULL;
+
+       /*
+        * OK, we're mapping AGP space on a chipset/platform on which memory accesses by
+        * the CPU do not get remapped by the GART.  We fix this by using the kernel's
+        * page-table instead (that's probably faster anyhow...).
+        */
+       /* note: use vmalloc() because num_pages could be large... */
+       page_map = vmalloc(num_pages * sizeof(struct page *));
+       if (!page_map)
+               return NULL;
+
+       phys_addr_map =
+           agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
+       for (i = 0; i < num_pages; ++i)
+               page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
+       addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
+       vfree(page_map);
+
+       return addr;
+}
+
+/** Wrapper around agp_allocate_memory() */
+DRM_AGP_MEM *drm_alloc_agp(struct drm_device * dev, int pages, u32 type)
+{
+       return drm_agp_allocate_memory(dev->agp->bridge, pages, type);
+}
+
+/** Wrapper around agp_free_memory() */
+int drm_free_agp(DRM_AGP_MEM * handle, int pages)
+{
+       return drm_agp_free_memory(handle) ? 0 : -EINVAL;
+}
+
+/** Wrapper around agp_bind_memory() */
+int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
+{
+       return drm_agp_bind_memory(handle, start);
+}
+
+/** Wrapper around agp_unbind_memory() */
+int drm_unbind_agp(DRM_AGP_MEM * handle)
+{
+       return drm_agp_unbind_memory(handle);
+}
+
+#else  /*  __OS_HAS_AGP  */
+static inline void *agp_remap(unsigned long offset, unsigned long size,
+                             struct drm_device * dev)
+{
+       return NULL;
+}
+
+#endif                         /* agp */
+
+#endif                         /* debug_memory */
+
+void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
+{
+       if (drm_core_has_AGP(dev) &&
+           dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
+               map->handle = agp_remap(map->offset, map->size, dev);
+       else
+               map->handle = ioremap(map->offset, map->size);
+}
+EXPORT_SYMBOL(drm_core_ioremap);
+
+void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
+{
+       if (!map->handle || !map->size)
+               return;
+
+       if (drm_core_has_AGP(dev) &&
+           dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
+               vunmap(map->handle);
+       else
+               iounmap(map->handle);
+}
+EXPORT_SYMBOL(drm_core_ioremapfree);
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
new file mode 100644 (file)
index 0000000..dcff9e9
--- /dev/null
@@ -0,0 +1,295 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ **************************************************************************/
+
+/*
+ * Generic simple memory manager implementation. Intended to be used as a base
+ * class implementation for more advanced memory managers.
+ *
+ * Note that the algorithm used is quite simple and there might be substantial
+ * performance gains if a smarter free list is implemented. Currently it is just an
+ * unordered stack of free regions. This could easily be improved if an RB-tree
+ * is used instead. At least if we expect heavy fragmentation.
+ *
+ * Aligned allocations can also see improvement.
+ *
+ * Authors:
+ * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#include "drmP.h"
+#include <linux/slab.h>
+
+unsigned long drm_mm_tail_space(struct drm_mm *mm)
+{
+       struct list_head *tail_node;
+       struct drm_mm_node *entry;
+
+       tail_node = mm->ml_entry.prev;
+       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
+       if (!entry->free)
+               return 0;
+
+       return entry->size;
+}
+
+int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size)
+{
+       struct list_head *tail_node;
+       struct drm_mm_node *entry;
+
+       tail_node = mm->ml_entry.prev;
+       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
+       if (!entry->free)
+               return -ENOMEM;
+
+       if (entry->size <= size)
+               return -ENOMEM;
+
+       entry->size -= size;
+       return 0;
+}
+
+
+static int drm_mm_create_tail_node(struct drm_mm *mm,
+                           unsigned long start,
+                           unsigned long size)
+{
+       struct drm_mm_node *child;
+
+       child = (struct drm_mm_node *)
+               drm_alloc(sizeof(*child), DRM_MEM_MM);
+       if (!child)
+               return -ENOMEM;
+
+       child->free = 1;
+       child->size = size;
+       child->start = start;
+       child->mm = mm;
+
+       list_add_tail(&child->ml_entry, &mm->ml_entry);
+       list_add_tail(&child->fl_entry, &mm->fl_entry);
+
+       return 0;
+}
+
+
+int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size)
+{
+       struct list_head *tail_node;
+       struct drm_mm_node *entry;
+
+       tail_node = mm->ml_entry.prev;
+       entry = list_entry(tail_node, struct drm_mm_node, ml_entry);
+       if (!entry->free) {
+               return drm_mm_create_tail_node(mm, entry->start + entry->size, size);
+       }
+       entry->size += size;
+       return 0;
+}
+
+static struct drm_mm_node *drm_mm_split_at_start(struct drm_mm_node *parent,
+                                           unsigned long size)
+{
+       struct drm_mm_node *child;
+
+       child = (struct drm_mm_node *)
+               drm_alloc(sizeof(*child), DRM_MEM_MM);
+       if (!child)
+               return NULL;
+
+       INIT_LIST_HEAD(&child->fl_entry);
+
+       child->free = 0;
+       child->size = size;
+       child->start = parent->start;
+       child->mm = parent->mm;
+
+       list_add_tail(&child->ml_entry, &parent->ml_entry);
+       INIT_LIST_HEAD(&child->fl_entry);
+
+       parent->size -= size;
+       parent->start += size;
+       return child;
+}
+
+
+
+struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
+                               unsigned long size, unsigned alignment)
+{
+
+       struct drm_mm_node *align_splitoff = NULL;
+       struct drm_mm_node *child;
+       unsigned tmp = 0;
+
+       if (alignment)
+               tmp = parent->start % alignment;
+
+       if (tmp) {
+               align_splitoff = drm_mm_split_at_start(parent, alignment - tmp);
+               if (!align_splitoff)
+                       return NULL;
+       }
+
+       if (parent->size == size) {
+               list_del_init(&parent->fl_entry);
+               parent->free = 0;
+               return parent;
+       } else {
+               child = drm_mm_split_at_start(parent, size);
+       }
+
+       if (align_splitoff)
+               drm_mm_put_block(align_splitoff);
+
+       return child;
+}
+
+/*
+ * Put a block. Merge with the previous and / or next block if they are free.
+ * Otherwise add to the free stack.
+ */
+
+void drm_mm_put_block(struct drm_mm_node * cur)
+{
+
+       struct drm_mm *mm = cur->mm;
+       struct list_head *cur_head = &cur->ml_entry;
+       struct list_head *root_head = &mm->ml_entry;
+       struct drm_mm_node *prev_node = NULL;
+       struct drm_mm_node *next_node;
+
+       int merged = 0;
+
+       if (cur_head->prev != root_head) {
+               prev_node = list_entry(cur_head->prev, struct drm_mm_node, ml_entry);
+               if (prev_node->free) {
+                       prev_node->size += cur->size;
+                       merged = 1;
+               }
+       }
+       if (cur_head->next != root_head) {
+               next_node = list_entry(cur_head->next, struct drm_mm_node, ml_entry);
+               if (next_node->free) {
+                       if (merged) {
+                               prev_node->size += next_node->size;
+                               list_del(&next_node->ml_entry);
+                               list_del(&next_node->fl_entry);
+                               drm_free(next_node, sizeof(*next_node),
+                                        DRM_MEM_MM);
+                       } else {
+                               next_node->size += cur->size;
+                               next_node->start = cur->start;
+                               merged = 1;
+                       }
+               }
+       }
+       if (!merged) {
+               cur->free = 1;
+               list_add(&cur->fl_entry, &mm->fl_entry);
+       } else {
+               list_del(&cur->ml_entry);
+               drm_free(cur, sizeof(*cur), DRM_MEM_MM);
+       }
+}
+
+struct drm_mm_node *drm_mm_search_free(const struct drm_mm * mm,
+                                 unsigned long size,
+                                 unsigned alignment, int best_match)
+{
+       struct list_head *list;
+       const struct list_head *free_stack = &mm->fl_entry;
+       struct drm_mm_node *entry;
+       struct drm_mm_node *best;
+       unsigned long best_size;
+       unsigned wasted;
+
+       best = NULL;
+       best_size = ~0UL;
+
+       list_for_each(list, free_stack) {
+               entry = list_entry(list, struct drm_mm_node, fl_entry);
+               wasted = 0;
+
+               if (entry->size < size)
+                       continue;
+
+               if (alignment) {
+                       register unsigned tmp = entry->start % alignment;
+                       if (tmp)
+                               wasted += alignment - tmp;
+               }
+
+
+               if (entry->size >= size + wasted) {
+                       if (!best_match)
+                               return entry;
+                       if (size < best_size) {
+                               best = entry;
+                               best_size = entry->size;
+                       }
+               }
+       }
+
+       return best;
+}
+
+int drm_mm_clean(struct drm_mm * mm)
+{
+       struct list_head *head = &mm->ml_entry;
+
+       return (head->next->next == head);
+}
+
+int drm_mm_init(struct drm_mm * mm, unsigned long start, unsigned long size)
+{
+       INIT_LIST_HEAD(&mm->ml_entry);
+       INIT_LIST_HEAD(&mm->fl_entry);
+
+       return drm_mm_create_tail_node(mm, start, size);
+}
+
+
+void drm_mm_takedown(struct drm_mm * mm)
+{
+       struct list_head *bnode = mm->fl_entry.next;
+       struct drm_mm_node *entry;
+
+       entry = list_entry(bnode, struct drm_mm_node, fl_entry);
+
+       if (entry->ml_entry.next != &mm->ml_entry ||
+           entry->fl_entry.next != &mm->fl_entry) {
+               DRM_ERROR("Memory manager not clean. Delaying takedown\n");
+               return;
+       }
+
+       list_del(&entry->fl_entry);
+       list_del(&entry->ml_entry);
+
+       drm_free(entry, sizeof(*entry), DRM_MEM_MM);
+}
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
new file mode 100644 (file)
index 0000000..b55d5bc
--- /dev/null
@@ -0,0 +1,183 @@
+/* drm_pci.h -- PCI DMA memory management wrappers for DRM -*- linux-c -*- */
+/**
+ * \file drm_pci.c
+ * \brief Functions and ioctls to manage PCI memory
+ *
+ * \warning These interfaces aren't stable yet.
+ *
+ * \todo Implement the remaining ioctl's for the PCI pools.
+ * \todo The wrappers here are so thin that they would be better off inlined..
+ *
+ * \author José Fonseca <jrfonseca@tungstengraphics.com>
+ * \author Leif Delgass <ldelgass@retinalburn.net>
+ */
+
+/*
+ * Copyright 2003 José Fonseca.
+ * Copyright 2003 Leif Delgass.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include "drmP.h"
+
+/**********************************************************************/
+/** \name PCI memory */
+/*@{*/
+
+/**
+ * \brief Allocate a PCI consistent memory block, for DMA.
+ */
+drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align,
+                               dma_addr_t maxaddr)
+{
+       drm_dma_handle_t *dmah;
+#if 1
+       unsigned long addr;
+       size_t sz;
+#endif
+#ifdef DRM_DEBUG_MEMORY
+       int area = DRM_MEM_DMA;
+
+       spin_lock(&drm_mem_lock);
+       if ((drm_ram_used >> PAGE_SHIFT)
+           > (DRM_RAM_PERCENT * drm_ram_available) / 100) {
+               spin_unlock(&drm_mem_lock);
+               return 0;
+       }
+       spin_unlock(&drm_mem_lock);
+#endif
+
+       /* pci_alloc_consistent only guarantees alignment to the smallest
+        * PAGE_SIZE order which is greater than or equal to the requested size.
+        * Return NULL here for now to make sure nobody tries for larger alignment
+        */
+       if (align > size)
+               return NULL;
+
+       if (pci_set_dma_mask(dev->pdev, maxaddr) != 0) {
+               DRM_ERROR("Setting pci dma mask failed\n");
+               return NULL;
+       }
+
+       dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
+       if (!dmah)
+               return NULL;
+
+       dmah->size = size;
+       dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size, &dmah->busaddr, GFP_KERNEL | __GFP_COMP);
+
+#ifdef DRM_DEBUG_MEMORY
+       if (dmah->vaddr == NULL) {
+               spin_lock(&drm_mem_lock);
+               ++drm_mem_stats[area].fail_count;
+               spin_unlock(&drm_mem_lock);
+               kfree(dmah);
+               return NULL;
+       }
+
+       spin_lock(&drm_mem_lock);
+       ++drm_mem_stats[area].succeed_count;
+       drm_mem_stats[area].bytes_allocated += size;
+       drm_ram_used += size;
+       spin_unlock(&drm_mem_lock);
+#else
+       if (dmah->vaddr == NULL) {
+               kfree(dmah);
+               return NULL;
+       }
+#endif
+
+       memset(dmah->vaddr, 0, size);
+
+       /* XXX - Is virt_to_page() legal for consistent mem? */
+       /* Reserve */
+       for (addr = (unsigned long)dmah->vaddr, sz = size;
+            sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+               SetPageReserved(virt_to_page(addr));
+       }
+
+       return dmah;
+}
+
+EXPORT_SYMBOL(drm_pci_alloc);
+
+/**
+ * \brief Free a PCI consistent memory block without freeing its descriptor.
+ *
+ * This function is for internal use in the Linux-specific DRM core code.
+ */
+void __drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
+{
+#if 1
+       unsigned long addr;
+       size_t sz;
+#endif
+#ifdef DRM_DEBUG_MEMORY
+       int area = DRM_MEM_DMA;
+       int alloc_count;
+       int free_count;
+#endif
+
+       if (!dmah->vaddr) {
+#ifdef DRM_DEBUG_MEMORY
+               DRM_MEM_ERROR(area, "Attempt to free address 0\n");
+#endif
+       } else {
+               /* XXX - Is virt_to_page() legal for consistent mem? */
+               /* Unreserve */
+               for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
+                    sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
+                       ClearPageReserved(virt_to_page(addr));
+               }
+               dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
+                                 dmah->busaddr);
+       }
+
+#ifdef DRM_DEBUG_MEMORY
+       spin_lock(&drm_mem_lock);
+       free_count = ++drm_mem_stats[area].free_count;
+       alloc_count = drm_mem_stats[area].succeed_count;
+       drm_mem_stats[area].bytes_freed += size;
+       drm_ram_used -= size;
+       spin_unlock(&drm_mem_lock);
+       if (free_count > alloc_count) {
+               DRM_MEM_ERROR(area,
+                             "Excess frees: %d frees, %d allocs\n",
+                             free_count, alloc_count);
+       }
+#endif
+
+}
+
+/**
+ * \brief Free a PCI consistent memory block
+ */
+void drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
+{
+       __drm_pci_free(dev, dmah);
+       kfree(dmah);
+}
+
+EXPORT_SYMBOL(drm_pci_free);
+
+/*@}*/
diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
new file mode 100644 (file)
index 0000000..93b1e04
--- /dev/null
@@ -0,0 +1,557 @@
+/**
+ * \file drm_proc.c
+ * /proc support for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ *
+ * \par Acknowledgements:
+ *    Matthew J Sottek <matthew.j.sottek@intel.com> sent in a patch to fix
+ *    the problem with the proc files not outputting all their information.
+ */
+
+/*
+ * Created: Mon Jan 11 09:48:47 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+static int drm_name_info(char *buf, char **start, off_t offset,
+                        int request, int *eof, void *data);
+static int drm_vm_info(char *buf, char **start, off_t offset,
+                      int request, int *eof, void *data);
+static int drm_clients_info(char *buf, char **start, off_t offset,
+                           int request, int *eof, void *data);
+static int drm_queues_info(char *buf, char **start, off_t offset,
+                          int request, int *eof, void *data);
+static int drm_bufs_info(char *buf, char **start, off_t offset,
+                        int request, int *eof, void *data);
+#if DRM_DEBUG_CODE
+static int drm_vma_info(char *buf, char **start, off_t offset,
+                       int request, int *eof, void *data);
+#endif
+
+/**
+ * Proc file list.
+ */
+static struct drm_proc_list {
+       const char *name;       /**< file name */
+       int (*f) (char *, char **, off_t, int, int *, void *);          /**< proc callback*/
+} drm_proc_list[] = {
+       {"name", drm_name_info},
+       {"mem", drm_mem_info},
+       {"vm", drm_vm_info},
+       {"clients", drm_clients_info},
+       {"queues", drm_queues_info},
+       {"bufs", drm_bufs_info},
+#if DRM_DEBUG_CODE
+       {"vma", drm_vma_info},
+#endif
+};
+
+#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
+
+/**
+ * Initialize the DRI proc filesystem for a device.
+ *
+ * \param dev DRM device.
+ * \param minor device minor number.
+ * \param root DRI proc dir entry.
+ * \param dev_root resulting DRI device proc dir entry.
+ * \return root entry pointer on success, or NULL on failure.
+ *
+ * Create the DRI proc root entry "/proc/dri", the device proc root entry
+ * "/proc/dri/%minor%/", and each entry in proc_list as
+ * "/proc/dri/%minor%/%name%".
+ */
+int drm_proc_init(struct drm_minor *minor, int minor_id,
+                 struct proc_dir_entry *root)
+{
+       struct proc_dir_entry *ent;
+       int i, j;
+       char name[64];
+
+       sprintf(name, "%d", minor_id);
+       minor->dev_root = proc_mkdir(name, root);
+       if (!minor->dev_root) {
+               DRM_ERROR("Cannot create /proc/dri/%s\n", name);
+               return -1;
+       }
+
+       for (i = 0; i < DRM_PROC_ENTRIES; i++) {
+               ent = create_proc_entry(drm_proc_list[i].name,
+                                       S_IFREG | S_IRUGO, minor->dev_root);
+               if (!ent) {
+                       DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
+                                 name, drm_proc_list[i].name);
+                       for (j = 0; j < i; j++)
+                               remove_proc_entry(drm_proc_list[i].name,
+                                                 minor->dev_root);
+                       remove_proc_entry(name, root);
+                       minor->dev_root = NULL;
+                       return -1;
+               }
+               ent->read_proc = drm_proc_list[i].f;
+               ent->data = minor;
+       }
+
+       return 0;
+}
+
+/**
+ * Cleanup the proc filesystem resources.
+ *
+ * \param minor device minor number.
+ * \param root DRI proc dir entry.
+ * \param dev_root DRI device proc dir entry.
+ * \return always zero.
+ *
+ * Remove all proc entries created by proc_init().
+ */
+int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
+{
+       int i;
+       char name[64];
+
+       if (!root || !minor->dev_root)
+               return 0;
+
+       for (i = 0; i < DRM_PROC_ENTRIES; i++)
+               remove_proc_entry(drm_proc_list[i].name, minor->dev_root);
+       sprintf(name, "%d", minor->index);
+       remove_proc_entry(name, root);
+
+       return 0;
+}
+
+/**
+ * Called when "/proc/dri/.../name" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param request requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ *
+ * Prints the device name together with the bus id if available.
+ */
+static int drm_name_info(char *buf, char **start, off_t offset, int request,
+                        int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       if (dev->unique) {
+               DRM_PROC_PRINT("%s %s %s\n",
+                              dev->driver->pci_driver.name,
+                              pci_name(dev->pdev), dev->unique);
+       } else {
+               DRM_PROC_PRINT("%s %s\n", dev->driver->pci_driver.name,
+                              pci_name(dev->pdev));
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+/**
+ * Called when "/proc/dri/.../vm" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param request requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ *
+ * Prints information about all mappings in drm_device::maplist.
+ */
+static int drm__vm_info(char *buf, char **start, off_t offset, int request,
+                       int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+       struct drm_map *map;
+       struct drm_map_list *r_list;
+
+       /* Hardcoded from _DRM_FRAME_BUFFER,
+          _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
+          _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
+       const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
+       const char *type;
+       int i;
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       DRM_PROC_PRINT("slot     offset       size type flags    "
+                      "address mtrr\n\n");
+       i = 0;
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               map = r_list->map;
+               if (!map)
+                       continue;
+               if (map->type < 0 || map->type > 5)
+                       type = "??";
+               else
+                       type = types[map->type];
+               DRM_PROC_PRINT("%4d 0x%08lx 0x%08lx %4.4s  0x%02x 0x%08lx ",
+                              i,
+                              map->offset,
+                              map->size, type, map->flags,
+                              (unsigned long) r_list->user_token);
+               if (map->mtrr < 0) {
+                       DRM_PROC_PRINT("none\n");
+               } else {
+                       DRM_PROC_PRINT("%4d\n", map->mtrr);
+               }
+               i++;
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+/**
+ * Simply calls _vm_info() while holding the drm_device::struct_mutex lock.
+ */
+static int drm_vm_info(char *buf, char **start, off_t offset, int request,
+                      int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm__vm_info(buf, start, offset, request, eof, data);
+       mutex_unlock(&dev->struct_mutex);
+       return ret;
+}
+
+/**
+ * Called when "/proc/dri/.../queues" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param request requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ */
+static int drm__queues_info(char *buf, char **start, off_t offset,
+                           int request, int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+       int i;
+       struct drm_queue *q;
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       DRM_PROC_PRINT("  ctx/flags   use   fin"
+                      "   blk/rw/rwf  wait    flushed     queued"
+                      "      locks\n\n");
+       for (i = 0; i < dev->queue_count; i++) {
+               q = dev->queuelist[i];
+               atomic_inc(&q->use_count);
+               DRM_PROC_PRINT_RET(atomic_dec(&q->use_count),
+                                  "%5d/0x%03x %5d %5d"
+                                  " %5d/%c%c/%c%c%c %5Zd\n",
+                                  i,
+                                  q->flags,
+                                  atomic_read(&q->use_count),
+                                  atomic_read(&q->finalization),
+                                  atomic_read(&q->block_count),
+                                  atomic_read(&q->block_read) ? 'r' : '-',
+                                  atomic_read(&q->block_write) ? 'w' : '-',
+                                  waitqueue_active(&q->read_queue) ? 'r' : '-',
+                                  waitqueue_active(&q->
+                                                   write_queue) ? 'w' : '-',
+                                  waitqueue_active(&q->
+                                                   flush_queue) ? 'f' : '-',
+                                  DRM_BUFCOUNT(&q->waitlist));
+               atomic_dec(&q->use_count);
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+/**
+ * Simply calls _queues_info() while holding the drm_device::struct_mutex lock.
+ */
+static int drm_queues_info(char *buf, char **start, off_t offset, int request,
+                          int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm__queues_info(buf, start, offset, request, eof, data);
+       mutex_unlock(&dev->struct_mutex);
+       return ret;
+}
+
+/**
+ * Called when "/proc/dri/.../bufs" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param request requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ */
+static int drm__bufs_info(char *buf, char **start, off_t offset, int request,
+                         int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+
+       if (!dma || offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       DRM_PROC_PRINT(" o     size count  free  segs pages    kB\n\n");
+       for (i = 0; i <= DRM_MAX_ORDER; i++) {
+               if (dma->bufs[i].buf_count)
+                       DRM_PROC_PRINT("%2d %8d %5d %5d %5d %5d %5ld\n",
+                                      i,
+                                      dma->bufs[i].buf_size,
+                                      dma->bufs[i].buf_count,
+                                      atomic_read(&dma->bufs[i]
+                                                  .freelist.count),
+                                      dma->bufs[i].seg_count,
+                                      dma->bufs[i].seg_count
+                                      * (1 << dma->bufs[i].page_order),
+                                      (dma->bufs[i].seg_count
+                                       * (1 << dma->bufs[i].page_order))
+                                      * PAGE_SIZE / 1024);
+       }
+       DRM_PROC_PRINT("\n");
+       for (i = 0; i < dma->buf_count; i++) {
+               if (i && !(i % 32))
+                       DRM_PROC_PRINT("\n");
+               DRM_PROC_PRINT(" %d", dma->buflist[i]->list);
+       }
+       DRM_PROC_PRINT("\n");
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+/**
+ * Simply calls _bufs_info() while holding the drm_device::struct_mutex lock.
+ */
+static int drm_bufs_info(char *buf, char **start, off_t offset, int request,
+                        int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm__bufs_info(buf, start, offset, request, eof, data);
+       mutex_unlock(&dev->struct_mutex);
+       return ret;
+}
+
+/**
+ * Called when "/proc/dri/.../clients" is read.
+ *
+ * \param buf output buffer.
+ * \param start start of output data.
+ * \param offset requested start offset.
+ * \param request requested number of bytes.
+ * \param eof whether there is no more data to return.
+ * \param data private data.
+ * \return number of written bytes.
+ */
+static int drm__clients_info(char *buf, char **start, off_t offset,
+                            int request, int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+       struct drm_file *priv;
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       DRM_PROC_PRINT("a dev   pid    uid      magic     ioctls\n\n");
+       list_for_each_entry(priv, &dev->filelist, lhead) {
+               DRM_PROC_PRINT("%c %3d %5d %5d %10u %10lu\n",
+                              priv->authenticated ? 'y' : 'n',
+                              priv->minor->index,
+                              priv->pid,
+                              priv->uid, priv->magic, priv->ioctl_count);
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+/**
+ * Simply calls _clients_info() while holding the drm_device::struct_mutex lock.
+ */
+static int drm_clients_info(char *buf, char **start, off_t offset,
+                           int request, int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm__clients_info(buf, start, offset, request, eof, data);
+       mutex_unlock(&dev->struct_mutex);
+       return ret;
+}
+
+#if DRM_DEBUG_CODE
+
+static int drm__vma_info(char *buf, char **start, off_t offset, int request,
+                        int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int len = 0;
+       struct drm_vma_entry *pt;
+       struct vm_area_struct *vma;
+#if defined(__i386__)
+       unsigned int pgprot;
+#endif
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *start = &buf[offset];
+       *eof = 0;
+
+       DRM_PROC_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
+                      atomic_read(&dev->vma_count),
+                      high_memory, virt_to_phys(high_memory));
+       list_for_each_entry(pt, &dev->vmalist, head) {
+               if (!(vma = pt->vma))
+                       continue;
+               DRM_PROC_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
+                              pt->pid,
+                              vma->vm_start,
+                              vma->vm_end,
+                              vma->vm_flags & VM_READ ? 'r' : '-',
+                              vma->vm_flags & VM_WRITE ? 'w' : '-',
+                              vma->vm_flags & VM_EXEC ? 'x' : '-',
+                              vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
+                              vma->vm_flags & VM_LOCKED ? 'l' : '-',
+                              vma->vm_flags & VM_IO ? 'i' : '-',
+                              vma->vm_pgoff);
+
+#if defined(__i386__)
+               pgprot = pgprot_val(vma->vm_page_prot);
+               DRM_PROC_PRINT(" %c%c%c%c%c%c%c%c%c",
+                              pgprot & _PAGE_PRESENT ? 'p' : '-',
+                              pgprot & _PAGE_RW ? 'w' : 'r',
+                              pgprot & _PAGE_USER ? 'u' : 's',
+                              pgprot & _PAGE_PWT ? 't' : 'b',
+                              pgprot & _PAGE_PCD ? 'u' : 'c',
+                              pgprot & _PAGE_ACCESSED ? 'a' : '-',
+                              pgprot & _PAGE_DIRTY ? 'd' : '-',
+                              pgprot & _PAGE_PSE ? 'm' : 'k',
+                              pgprot & _PAGE_GLOBAL ? 'g' : 'l');
+#endif
+               DRM_PROC_PRINT("\n");
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+static int drm_vma_info(char *buf, char **start, off_t offset, int request,
+                       int *eof, void *data)
+{
+       struct drm_minor *minor = (struct drm_minor *) data;
+       struct drm_device *dev = minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm__vma_info(buf, start, offset, request, eof, data);
+       mutex_unlock(&dev->struct_mutex);
+       return ret;
+}
+#endif
diff --git a/drivers/gpu/drm/drm_scatter.c b/drivers/gpu/drm/drm_scatter.c
new file mode 100644 (file)
index 0000000..b2b0f3d
--- /dev/null
@@ -0,0 +1,227 @@
+/**
+ * \file drm_scatter.c
+ * IOCTLs to manage scatter/gather memory
+ *
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com
+ *
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/vmalloc.h>
+#include "drmP.h"
+
+#define DEBUG_SCATTER 0
+
+static inline void *drm_vmalloc_dma(unsigned long size)
+{
+#if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
+       return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL | _PAGE_NO_CACHE);
+#else
+       return vmalloc_32(size);
+#endif
+}
+
+void drm_sg_cleanup(struct drm_sg_mem * entry)
+{
+       struct page *page;
+       int i;
+
+       for (i = 0; i < entry->pages; i++) {
+               page = entry->pagelist[i];
+               if (page)
+                       ClearPageReserved(page);
+       }
+
+       vfree(entry->virtual);
+
+       drm_free(entry->busaddr,
+                entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
+       drm_free(entry->pagelist,
+                entry->pages * sizeof(*entry->pagelist), DRM_MEM_PAGES);
+       drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
+}
+
+#ifdef _LP64
+# define ScatterHandle(x) (unsigned int)((x >> 32) + (x & ((1L << 32) - 1)))
+#else
+# define ScatterHandle(x) (unsigned int)(x)
+#endif
+
+int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
+{
+       struct drm_sg_mem *entry;
+       unsigned long pages, i, j;
+
+       DRM_DEBUG("\n");
+
+       if (!drm_core_check_feature(dev, DRIVER_SG))
+               return -EINVAL;
+
+       if (dev->sg)
+               return -EINVAL;
+
+       entry = drm_alloc(sizeof(*entry), DRM_MEM_SGLISTS);
+       if (!entry)
+               return -ENOMEM;
+
+       memset(entry, 0, sizeof(*entry));
+       pages = (request->size + PAGE_SIZE - 1) / PAGE_SIZE;
+       DRM_DEBUG("size=%ld pages=%ld\n", request->size, pages);
+
+       entry->pages = pages;
+       entry->pagelist = drm_alloc(pages * sizeof(*entry->pagelist),
+                                   DRM_MEM_PAGES);
+       if (!entry->pagelist) {
+               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
+               return -ENOMEM;
+       }
+
+       memset(entry->pagelist, 0, pages * sizeof(*entry->pagelist));
+
+       entry->busaddr = drm_alloc(pages * sizeof(*entry->busaddr),
+                                  DRM_MEM_PAGES);
+       if (!entry->busaddr) {
+               drm_free(entry->pagelist,
+                        entry->pages * sizeof(*entry->pagelist),
+                        DRM_MEM_PAGES);
+               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
+               return -ENOMEM;
+       }
+       memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
+
+       entry->virtual = drm_vmalloc_dma(pages << PAGE_SHIFT);
+       if (!entry->virtual) {
+               drm_free(entry->busaddr,
+                        entry->pages * sizeof(*entry->busaddr), DRM_MEM_PAGES);
+               drm_free(entry->pagelist,
+                        entry->pages * sizeof(*entry->pagelist),
+                        DRM_MEM_PAGES);
+               drm_free(entry, sizeof(*entry), DRM_MEM_SGLISTS);
+               return -ENOMEM;
+       }
+
+       /* This also forces the mapping of COW pages, so our page list
+        * will be valid.  Please don't remove it...
+        */
+       memset(entry->virtual, 0, pages << PAGE_SHIFT);
+
+       entry->handle = ScatterHandle((unsigned long)entry->virtual);
+
+       DRM_DEBUG("handle  = %08lx\n", entry->handle);
+       DRM_DEBUG("virtual = %p\n", entry->virtual);
+
+       for (i = (unsigned long)entry->virtual, j = 0; j < pages;
+            i += PAGE_SIZE, j++) {
+               entry->pagelist[j] = vmalloc_to_page((void *)i);
+               if (!entry->pagelist[j])
+                       goto failed;
+               SetPageReserved(entry->pagelist[j]);
+       }
+
+       request->handle = entry->handle;
+
+       dev->sg = entry;
+
+#if DEBUG_SCATTER
+       /* Verify that each page points to its virtual address, and vice
+        * versa.
+        */
+       {
+               int error = 0;
+
+               for (i = 0; i < pages; i++) {
+                       unsigned long *tmp;
+
+                       tmp = page_address(entry->pagelist[i]);
+                       for (j = 0;
+                            j < PAGE_SIZE / sizeof(unsigned long);
+                            j++, tmp++) {
+                               *tmp = 0xcafebabe;
+                       }
+                       tmp = (unsigned long *)((u8 *) entry->virtual +
+                                               (PAGE_SIZE * i));
+                       for (j = 0;
+                            j < PAGE_SIZE / sizeof(unsigned long);
+                            j++, tmp++) {
+                               if (*tmp != 0xcafebabe && error == 0) {
+                                       error = 1;
+                                       DRM_ERROR("Scatter allocation error, "
+                                                 "pagelist does not match "
+                                                 "virtual mapping\n");
+                               }
+                       }
+                       tmp = page_address(entry->pagelist[i]);
+                       for (j = 0;
+                            j < PAGE_SIZE / sizeof(unsigned long);
+                            j++, tmp++) {
+                               *tmp = 0;
+                       }
+               }
+               if (error == 0)
+                       DRM_ERROR("Scatter allocation matches pagelist\n");
+       }
+#endif
+
+       return 0;
+
+      failed:
+       drm_sg_cleanup(entry);
+       return -ENOMEM;
+}
+EXPORT_SYMBOL(drm_sg_alloc);
+
+
+int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_scatter_gather *request = data;
+
+       return drm_sg_alloc(dev, request);
+
+}
+
+int drm_sg_free(struct drm_device *dev, void *data,
+               struct drm_file *file_priv)
+{
+       struct drm_scatter_gather *request = data;
+       struct drm_sg_mem *entry;
+
+       if (!drm_core_check_feature(dev, DRIVER_SG))
+               return -EINVAL;
+
+       entry = dev->sg;
+       dev->sg = NULL;
+
+       if (!entry || entry->handle != request->handle)
+               return -EINVAL;
+
+       DRM_DEBUG("virtual  = %p\n", entry->virtual);
+
+       drm_sg_cleanup(entry);
+
+       return 0;
+}
diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
new file mode 100644 (file)
index 0000000..926f146
--- /dev/null
@@ -0,0 +1,353 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ *
+ **************************************************************************/
+/*
+ * Simple memory manager interface that keeps track on allocate regions on a
+ * per "owner" basis. All regions associated with an "owner" can be released
+ * with a simple call. Typically if the "owner" exists. The owner is any
+ * "unsigned long" identifier. Can typically be a pointer to a file private
+ * struct or a context identifier.
+ *
+ * Authors:
+ * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#include "drm_sman.h"
+
+struct drm_owner_item {
+       struct drm_hash_item owner_hash;
+       struct list_head sman_list;
+       struct list_head mem_blocks;
+};
+
+void drm_sman_takedown(struct drm_sman * sman)
+{
+       drm_ht_remove(&sman->user_hash_tab);
+       drm_ht_remove(&sman->owner_hash_tab);
+       if (sman->mm)
+               drm_free(sman->mm, sman->num_managers * sizeof(*sman->mm),
+                        DRM_MEM_MM);
+}
+
+EXPORT_SYMBOL(drm_sman_takedown);
+
+int
+drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
+             unsigned int user_order, unsigned int owner_order)
+{
+       int ret = 0;
+
+       sman->mm = (struct drm_sman_mm *) drm_calloc(num_managers, sizeof(*sman->mm),
+                                               DRM_MEM_MM);
+       if (!sman->mm) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       sman->num_managers = num_managers;
+       INIT_LIST_HEAD(&sman->owner_items);
+       ret = drm_ht_create(&sman->owner_hash_tab, owner_order);
+       if (ret)
+               goto out1;
+       ret = drm_ht_create(&sman->user_hash_tab, user_order);
+       if (!ret)
+               goto out;
+
+       drm_ht_remove(&sman->owner_hash_tab);
+out1:
+       drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM);
+out:
+       return ret;
+}
+
+EXPORT_SYMBOL(drm_sman_init);
+
+static void *drm_sman_mm_allocate(void *private, unsigned long size,
+                                 unsigned alignment)
+{
+       struct drm_mm *mm = (struct drm_mm *) private;
+       struct drm_mm_node *tmp;
+
+       tmp = drm_mm_search_free(mm, size, alignment, 1);
+       if (!tmp) {
+               return NULL;
+       }
+       tmp = drm_mm_get_block(tmp, size, alignment);
+       return tmp;
+}
+
+static void drm_sman_mm_free(void *private, void *ref)
+{
+       struct drm_mm_node *node = (struct drm_mm_node *) ref;
+
+       drm_mm_put_block(node);
+}
+
+static void drm_sman_mm_destroy(void *private)
+{
+       struct drm_mm *mm = (struct drm_mm *) private;
+       drm_mm_takedown(mm);
+       drm_free(mm, sizeof(*mm), DRM_MEM_MM);
+}
+
+static unsigned long drm_sman_mm_offset(void *private, void *ref)
+{
+       struct drm_mm_node *node = (struct drm_mm_node *) ref;
+       return node->start;
+}
+
+int
+drm_sman_set_range(struct drm_sman * sman, unsigned int manager,
+                  unsigned long start, unsigned long size)
+{
+       struct drm_sman_mm *sman_mm;
+       struct drm_mm *mm;
+       int ret;
+
+       BUG_ON(manager >= sman->num_managers);
+
+       sman_mm = &sman->mm[manager];
+       mm = drm_calloc(1, sizeof(*mm), DRM_MEM_MM);
+       if (!mm) {
+               return -ENOMEM;
+       }
+       sman_mm->private = mm;
+       ret = drm_mm_init(mm, start, size);
+
+       if (ret) {
+               drm_free(mm, sizeof(*mm), DRM_MEM_MM);
+               return ret;
+       }
+
+       sman_mm->allocate = drm_sman_mm_allocate;
+       sman_mm->free = drm_sman_mm_free;
+       sman_mm->destroy = drm_sman_mm_destroy;
+       sman_mm->offset = drm_sman_mm_offset;
+
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_sman_set_range);
+
+int
+drm_sman_set_manager(struct drm_sman * sman, unsigned int manager,
+                    struct drm_sman_mm * allocator)
+{
+       BUG_ON(manager >= sman->num_managers);
+       sman->mm[manager] = *allocator;
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_sman_set_manager);
+
+static struct drm_owner_item *drm_sman_get_owner_item(struct drm_sman * sman,
+                                                unsigned long owner)
+{
+       int ret;
+       struct drm_hash_item *owner_hash_item;
+       struct drm_owner_item *owner_item;
+
+       ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item);
+       if (!ret) {
+               return drm_hash_entry(owner_hash_item, struct drm_owner_item,
+                                     owner_hash);
+       }
+
+       owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM);
+       if (!owner_item)
+               goto out;
+
+       INIT_LIST_HEAD(&owner_item->mem_blocks);
+       owner_item->owner_hash.key = owner;
+       if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash))
+               goto out1;
+
+       list_add_tail(&owner_item->sman_list, &sman->owner_items);
+       return owner_item;
+
+out1:
+       drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
+out:
+       return NULL;
+}
+
+struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int manager,
+                                   unsigned long size, unsigned alignment,
+                                   unsigned long owner)
+{
+       void *tmp;
+       struct drm_sman_mm *sman_mm;
+       struct drm_owner_item *owner_item;
+       struct drm_memblock_item *memblock;
+
+       BUG_ON(manager >= sman->num_managers);
+
+       sman_mm = &sman->mm[manager];
+       tmp = sman_mm->allocate(sman_mm->private, size, alignment);
+
+       if (!tmp) {
+               return NULL;
+       }
+
+       memblock = drm_calloc(1, sizeof(*memblock), DRM_MEM_MM);
+
+       if (!memblock)
+               goto out;
+
+       memblock->mm_info = tmp;
+       memblock->mm = sman_mm;
+       memblock->sman = sman;
+
+       if (drm_ht_just_insert_please
+           (&sman->user_hash_tab, &memblock->user_hash,
+            (unsigned long)memblock, 32, 0, 0))
+               goto out1;
+
+       owner_item = drm_sman_get_owner_item(sman, owner);
+       if (!owner_item)
+               goto out2;
+
+       list_add_tail(&memblock->owner_list, &owner_item->mem_blocks);
+
+       return memblock;
+
+out2:
+       drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash);
+out1:
+       drm_free(memblock, sizeof(*memblock), DRM_MEM_MM);
+out:
+       sman_mm->free(sman_mm->private, tmp);
+
+       return NULL;
+}
+
+EXPORT_SYMBOL(drm_sman_alloc);
+
+static void drm_sman_free(struct drm_memblock_item *item)
+{
+       struct drm_sman *sman = item->sman;
+
+       list_del(&item->owner_list);
+       drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash);
+       item->mm->free(item->mm->private, item->mm_info);
+       drm_free(item, sizeof(*item), DRM_MEM_MM);
+}
+
+int drm_sman_free_key(struct drm_sman *sman, unsigned int key)
+{
+       struct drm_hash_item *hash_item;
+       struct drm_memblock_item *memblock_item;
+
+       if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item))
+               return -EINVAL;
+
+       memblock_item = drm_hash_entry(hash_item, struct drm_memblock_item,
+                                      user_hash);
+       drm_sman_free(memblock_item);
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_sman_free_key);
+
+static void drm_sman_remove_owner(struct drm_sman *sman,
+                                 struct drm_owner_item *owner_item)
+{
+       list_del(&owner_item->sman_list);
+       drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash);
+       drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM);
+}
+
+int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner)
+{
+
+       struct drm_hash_item *hash_item;
+       struct drm_owner_item *owner_item;
+
+       if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
+               return -1;
+       }
+
+       owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash);
+       if (owner_item->mem_blocks.next == &owner_item->mem_blocks) {
+               drm_sman_remove_owner(sman, owner_item);
+               return -1;
+       }
+
+       return 0;
+}
+
+EXPORT_SYMBOL(drm_sman_owner_clean);
+
+static void drm_sman_do_owner_cleanup(struct drm_sman *sman,
+                                     struct drm_owner_item *owner_item)
+{
+       struct drm_memblock_item *entry, *next;
+
+       list_for_each_entry_safe(entry, next, &owner_item->mem_blocks,
+                                owner_list) {
+               drm_sman_free(entry);
+       }
+       drm_sman_remove_owner(sman, owner_item);
+}
+
+void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner)
+{
+
+       struct drm_hash_item *hash_item;
+       struct drm_owner_item *owner_item;
+
+       if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) {
+
+               return;
+       }
+
+       owner_item = drm_hash_entry(hash_item, struct drm_owner_item, owner_hash);
+       drm_sman_do_owner_cleanup(sman, owner_item);
+}
+
+EXPORT_SYMBOL(drm_sman_owner_cleanup);
+
+void drm_sman_cleanup(struct drm_sman *sman)
+{
+       struct drm_owner_item *entry, *next;
+       unsigned int i;
+       struct drm_sman_mm *sman_mm;
+
+       list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) {
+               drm_sman_do_owner_cleanup(sman, entry);
+       }
+       if (sman->mm) {
+               for (i = 0; i < sman->num_managers; ++i) {
+                       sman_mm = &sman->mm[i];
+                       if (sman_mm->private) {
+                               sman_mm->destroy(sman_mm->private);
+                               sman_mm->private = NULL;
+                       }
+               }
+       }
+}
+
+EXPORT_SYMBOL(drm_sman_cleanup);
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
new file mode 100644 (file)
index 0000000..c2f584f
--- /dev/null
@@ -0,0 +1,331 @@
+/**
+ * \file drm_stub.h
+ * Stub support
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ */
+
+/*
+ * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
+ *
+ * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include "drmP.h"
+#include "drm_core.h"
+
+unsigned int drm_debug = 0;    /* 1 to enable debug output */
+EXPORT_SYMBOL(drm_debug);
+
+MODULE_AUTHOR(CORE_AUTHOR);
+MODULE_DESCRIPTION(CORE_DESC);
+MODULE_LICENSE("GPL and additional rights");
+MODULE_PARM_DESC(debug, "Enable debug output");
+
+module_param_named(debug, drm_debug, int, 0600);
+
+struct idr drm_minors_idr;
+
+struct class *drm_class;
+struct proc_dir_entry *drm_proc_root;
+
+static int drm_minor_get_id(struct drm_device *dev, int type)
+{
+       int new_id;
+       int ret;
+       int base = 0, limit = 63;
+
+again:
+       if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) {
+               DRM_ERROR("Out of memory expanding drawable idr\n");
+               return -ENOMEM;
+       }
+       mutex_lock(&dev->struct_mutex);
+       ret = idr_get_new_above(&drm_minors_idr, NULL,
+                               base, &new_id);
+       mutex_unlock(&dev->struct_mutex);
+       if (ret == -EAGAIN) {
+               goto again;
+       } else if (ret) {
+               return ret;
+       }
+
+       if (new_id >= limit) {
+               idr_remove(&drm_minors_idr, new_id);
+               return -EINVAL;
+       }
+       return new_id;
+}
+
+static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
+                          const struct pci_device_id *ent,
+                          struct drm_driver *driver)
+{
+       int retcode;
+
+       INIT_LIST_HEAD(&dev->filelist);
+       INIT_LIST_HEAD(&dev->ctxlist);
+       INIT_LIST_HEAD(&dev->vmalist);
+       INIT_LIST_HEAD(&dev->maplist);
+
+       spin_lock_init(&dev->count_lock);
+       spin_lock_init(&dev->drw_lock);
+       spin_lock_init(&dev->tasklet_lock);
+       spin_lock_init(&dev->lock.spinlock);
+       init_timer(&dev->timer);
+       mutex_init(&dev->struct_mutex);
+       mutex_init(&dev->ctxlist_mutex);
+
+       idr_init(&dev->drw_idr);
+
+       dev->pdev = pdev;
+       dev->pci_device = pdev->device;
+       dev->pci_vendor = pdev->vendor;
+
+#ifdef __alpha__
+       dev->hose = pdev->sysdata;
+#endif
+       dev->irq = pdev->irq;
+
+       if (drm_ht_create(&dev->map_hash, 12)) {
+               return -ENOMEM;
+       }
+
+       /* the DRM has 6 basic counters */
+       dev->counters = 6;
+       dev->types[0] = _DRM_STAT_LOCK;
+       dev->types[1] = _DRM_STAT_OPENS;
+       dev->types[2] = _DRM_STAT_CLOSES;
+       dev->types[3] = _DRM_STAT_IOCTLS;
+       dev->types[4] = _DRM_STAT_LOCKS;
+       dev->types[5] = _DRM_STAT_UNLOCKS;
+
+       dev->driver = driver;
+
+       if (drm_core_has_AGP(dev)) {
+               if (drm_device_is_agp(dev))
+                       dev->agp = drm_agp_init(dev);
+               if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP)
+                   && (dev->agp == NULL)) {
+                       DRM_ERROR("Cannot initialize the agpgart module.\n");
+                       retcode = -EINVAL;
+                       goto error_out_unreg;
+               }
+               if (drm_core_has_MTRR(dev)) {
+                       if (dev->agp)
+                               dev->agp->agp_mtrr =
+                                   mtrr_add(dev->agp->agp_info.aper_base,
+                                            dev->agp->agp_info.aper_size *
+                                            1024 * 1024, MTRR_TYPE_WRCOMB, 1);
+               }
+       }
+
+       if (dev->driver->load)
+               if ((retcode = dev->driver->load(dev, ent->driver_data)))
+                       goto error_out_unreg;
+
+       retcode = drm_ctxbitmap_init(dev);
+       if (retcode) {
+               DRM_ERROR("Cannot allocate memory for context bitmap.\n");
+               goto error_out_unreg;
+       }
+
+       return 0;
+
+      error_out_unreg:
+       drm_lastclose(dev);
+       return retcode;
+}
+
+
+/**
+ * Get a secondary minor number.
+ *
+ * \param dev device data structure
+ * \param sec-minor structure to hold the assigned minor
+ * \return negative number on failure.
+ *
+ * Search an empty entry and initialize it to the given parameters, and
+ * create the proc init entry via proc_init(). This routines assigns
+ * minor numbers to secondary heads of multi-headed cards
+ */
+static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
+{
+       struct drm_minor *new_minor;
+       int ret;
+       int minor_id;
+
+       DRM_DEBUG("\n");
+
+       minor_id = drm_minor_get_id(dev, type);
+       if (minor_id < 0)
+               return minor_id;
+
+       new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL);
+       if (!new_minor) {
+               ret = -ENOMEM;
+               goto err_idr;
+       }
+
+       new_minor->type = type;
+       new_minor->device = MKDEV(DRM_MAJOR, minor_id);
+       new_minor->dev = dev;
+       new_minor->index = minor_id;
+
+       idr_replace(&drm_minors_idr, new_minor, minor_id);
+
+       if (type == DRM_MINOR_LEGACY) {
+               ret = drm_proc_init(new_minor, minor_id, drm_proc_root);
+               if (ret) {
+                       DRM_ERROR("DRM: Failed to initialize /proc/dri.\n");
+                       goto err_mem;
+               }
+       } else
+               new_minor->dev_root = NULL;
+
+       ret = drm_sysfs_device_add(new_minor);
+       if (ret) {
+               printk(KERN_ERR
+                      "DRM: Error sysfs_device_add.\n");
+               goto err_g2;
+       }
+       *minor = new_minor;
+
+       DRM_DEBUG("new minor assigned %d\n", minor_id);
+       return 0;
+
+
+err_g2:
+       if (new_minor->type == DRM_MINOR_LEGACY)
+               drm_proc_cleanup(new_minor, drm_proc_root);
+err_mem:
+       kfree(new_minor);
+err_idr:
+       idr_remove(&drm_minors_idr, minor_id);
+       *minor = NULL;
+       return ret;
+}
+
+/**
+ * Register.
+ *
+ * \param pdev - PCI device structure
+ * \param ent entry from the PCI ID table with device type flags
+ * \return zero on success or a negative number on failure.
+ *
+ * Attempt to gets inter module "drm" information. If we are first
+ * then register the character device and inter module information.
+ * Try and register, if we fail to register, backout previous work.
+ */
+int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
+               struct drm_driver *driver)
+{
+       struct drm_device *dev;
+       int ret;
+
+       DRM_DEBUG("\n");
+
+       dev = drm_calloc(1, sizeof(*dev), DRM_MEM_STUB);
+       if (!dev)
+               return -ENOMEM;
+
+       ret = pci_enable_device(pdev);
+       if (ret)
+               goto err_g1;
+
+       pci_set_master(pdev);
+       if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
+               printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
+               goto err_g2;
+       }
+       if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY)))
+               goto err_g2;
+
+       DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
+                driver->name, driver->major, driver->minor, driver->patchlevel,
+                driver->date, dev->primary->index);
+
+       return 0;
+
+err_g2:
+       pci_disable_device(pdev);
+err_g1:
+       drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
+       return ret;
+}
+
+/**
+ * Put a device minor number.
+ *
+ * \param dev device data structure
+ * \return always zero
+ *
+ * Cleans up the proc resources. If it is the last minor then release the foreign
+ * "drm" data, otherwise unregisters the "drm" data, frees the dev list and
+ * unregisters the character device.
+ */
+int drm_put_dev(struct drm_device * dev)
+{
+       DRM_DEBUG("release primary %s\n", dev->driver->pci_driver.name);
+
+       if (dev->unique) {
+               drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
+               dev->unique = NULL;
+               dev->unique_len = 0;
+       }
+       if (dev->devname) {
+               drm_free(dev->devname, strlen(dev->devname) + 1,
+                        DRM_MEM_DRIVER);
+               dev->devname = NULL;
+       }
+       drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
+       return 0;
+}
+
+/**
+ * Put a secondary minor number.
+ *
+ * \param sec_minor - structure to be released
+ * \return always zero
+ *
+ * Cleans up the proc resources. Not legal for this to be the
+ * last minor released.
+ *
+ */
+int drm_put_minor(struct drm_minor **minor_p)
+{
+       struct drm_minor *minor = *minor_p;
+       DRM_DEBUG("release secondary minor %d\n", minor->index);
+
+       if (minor->type == DRM_MINOR_LEGACY)
+               drm_proc_cleanup(minor, drm_proc_root);
+       drm_sysfs_device_remove(minor);
+
+       idr_remove(&drm_minors_idr, minor->index);
+
+       kfree(minor);
+       *minor_p = NULL;
+       return 0;
+}
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
new file mode 100644 (file)
index 0000000..af211a0
--- /dev/null
@@ -0,0 +1,208 @@
+
+/*
+ * drm_sysfs.c - Modifications to drm_sysfs_class.c to support
+ *               extra sysfs attribute from DRM. Normal drm_sysfs_class
+ *               does not allow adding attributes.
+ *
+ * Copyright (c) 2004 Jon Smirl <jonsmirl@gmail.com>
+ * Copyright (c) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (c) 2003-2004 IBM Corp.
+ *
+ * This file is released under the GPLv2
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/err.h>
+
+#include "drm_core.h"
+#include "drmP.h"
+
+#define to_drm_minor(d) container_of(d, struct drm_minor, kdev)
+
+/**
+ * drm_sysfs_suspend - DRM class suspend hook
+ * @dev: Linux device to suspend
+ * @state: power state to enter
+ *
+ * Just figures out what the actual struct drm_device associated with
+ * @dev is and calls its suspend hook, if present.
+ */
+static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
+{
+       struct drm_minor *drm_minor = to_drm_minor(dev);
+       struct drm_device *drm_dev = drm_minor->dev;
+
+       if (drm_dev->driver->suspend)
+               return drm_dev->driver->suspend(drm_dev, state);
+
+       return 0;
+}
+
+/**
+ * drm_sysfs_resume - DRM class resume hook
+ * @dev: Linux device to resume
+ *
+ * Just figures out what the actual struct drm_device associated with
+ * @dev is and calls its resume hook, if present.
+ */
+static int drm_sysfs_resume(struct device *dev)
+{
+       struct drm_minor *drm_minor = to_drm_minor(dev);
+       struct drm_device *drm_dev = drm_minor->dev;
+
+       if (drm_dev->driver->resume)
+               return drm_dev->driver->resume(drm_dev);
+
+       return 0;
+}
+
+/* Display the version of drm_core. This doesn't work right in current design */
+static ssize_t version_show(struct class *dev, char *buf)
+{
+       return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
+                      CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
+}
+
+static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
+
+/**
+ * drm_sysfs_create - create a struct drm_sysfs_class structure
+ * @owner: pointer to the module that is to "own" this struct drm_sysfs_class
+ * @name: pointer to a string for the name of this class.
+ *
+ * This is used to create DRM class pointer that can then be used
+ * in calls to drm_sysfs_device_add().
+ *
+ * Note, the pointer created here is to be destroyed when finished by making a
+ * call to drm_sysfs_destroy().
+ */
+struct class *drm_sysfs_create(struct module *owner, char *name)
+{
+       struct class *class;
+       int err;
+
+       class = class_create(owner, name);
+       if (IS_ERR(class)) {
+               err = PTR_ERR(class);
+               goto err_out;
+       }
+
+       class->suspend = drm_sysfs_suspend;
+       class->resume = drm_sysfs_resume;
+
+       err = class_create_file(class, &class_attr_version);
+       if (err)
+               goto err_out_class;
+
+       return class;
+
+err_out_class:
+       class_destroy(class);
+err_out:
+       return ERR_PTR(err);
+}
+
+/**
+ * drm_sysfs_destroy - destroys DRM class
+ *
+ * Destroy the DRM device class.
+ */
+void drm_sysfs_destroy(void)
+{
+       if ((drm_class == NULL) || (IS_ERR(drm_class)))
+               return;
+       class_remove_file(drm_class, &class_attr_version);
+       class_destroy(drm_class);
+}
+
+static ssize_t show_dri(struct device *device, struct device_attribute *attr,
+                       char *buf)
+{
+       struct drm_minor *drm_minor = to_drm_minor(device);
+       struct drm_device *drm_dev = drm_minor->dev;
+       if (drm_dev->driver->dri_library_name)
+               return drm_dev->driver->dri_library_name(drm_dev, buf);
+       return snprintf(buf, PAGE_SIZE, "%s\n", drm_dev->driver->pci_driver.name);
+}
+
+static struct device_attribute device_attrs[] = {
+       __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
+};
+
+/**
+ * drm_sysfs_device_release - do nothing
+ * @dev: Linux device
+ *
+ * Normally, this would free the DRM device associated with @dev, along
+ * with cleaning up any other stuff.  But we do that in the DRM core, so
+ * this function can just return and hope that the core does its job.
+ */
+static void drm_sysfs_device_release(struct device *dev)
+{
+       return;
+}
+
+/**
+ * drm_sysfs_device_add - adds a class device to sysfs for a character driver
+ * @dev: DRM device to be added
+ * @head: DRM head in question
+ *
+ * Add a DRM device to the DRM's device model class.  We use @dev's PCI device
+ * as the parent for the Linux device, and make sure it has a file containing
+ * the driver we're using (for userspace compatibility).
+ */
+int drm_sysfs_device_add(struct drm_minor *minor)
+{
+       int err;
+       int i, j;
+       char *minor_str;
+
+       minor->kdev.parent = &minor->dev->pdev->dev;
+       minor->kdev.class = drm_class;
+       minor->kdev.release = drm_sysfs_device_release;
+       minor->kdev.devt = minor->device;
+       minor_str = "card%d";
+
+       snprintf(minor->kdev.bus_id, BUS_ID_SIZE, minor_str, minor->index);
+
+       err = device_register(&minor->kdev);
+       if (err) {
+               DRM_ERROR("device add failed: %d\n", err);
+               goto err_out;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
+               err = device_create_file(&minor->kdev, &device_attrs[i]);
+               if (err)
+                       goto err_out_files;
+       }
+
+       return 0;
+
+err_out_files:
+       if (i > 0)
+               for (j = 0; j < i; j++)
+                       device_remove_file(&minor->kdev, &device_attrs[i]);
+       device_unregister(&minor->kdev);
+err_out:
+
+       return err;
+}
+
+/**
+ * drm_sysfs_device_remove - remove DRM device
+ * @dev: DRM device to remove
+ *
+ * This call unregisters and cleans up a class device that was created with a
+ * call to drm_sysfs_device_add()
+ */
+void drm_sysfs_device_remove(struct drm_minor *minor)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
+               device_remove_file(&minor->kdev, &device_attrs[i]);
+       device_unregister(&minor->kdev);
+}
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
new file mode 100644 (file)
index 0000000..c234c6f
--- /dev/null
@@ -0,0 +1,673 @@
+/**
+ * \file drm_vm.c
+ * Memory mapping for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#if defined(__ia64__)
+#include <linux/efi.h>
+#endif
+
+static void drm_vm_open(struct vm_area_struct *vma);
+static void drm_vm_close(struct vm_area_struct *vma);
+
+static pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma)
+{
+       pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
+
+#if defined(__i386__) || defined(__x86_64__)
+       if (boot_cpu_data.x86 > 3 && map_type != _DRM_AGP) {
+               pgprot_val(tmp) |= _PAGE_PCD;
+               pgprot_val(tmp) &= ~_PAGE_PWT;
+       }
+#elif defined(__powerpc__)
+       pgprot_val(tmp) |= _PAGE_NO_CACHE;
+       if (map_type == _DRM_REGISTERS)
+               pgprot_val(tmp) |= _PAGE_GUARDED;
+#elif defined(__ia64__)
+       if (efi_range_is_wc(vma->vm_start, vma->vm_end -
+                                   vma->vm_start))
+               tmp = pgprot_writecombine(tmp);
+       else
+               tmp = pgprot_noncached(tmp);
+#elif defined(__sparc__)
+       tmp = pgprot_noncached(tmp);
+#endif
+       return tmp;
+}
+
+static pgprot_t drm_dma_prot(uint32_t map_type, struct vm_area_struct *vma)
+{
+       pgprot_t tmp = vm_get_page_prot(vma->vm_flags);
+
+#if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
+       tmp |= _PAGE_NO_CACHE;
+#endif
+       return tmp;
+}
+
+/**
+ * \c fault method for AGP virtual memory.
+ *
+ * \param vma virtual memory area.
+ * \param address access address.
+ * \return pointer to the page structure.
+ *
+ * Find the right map and if it's AGP memory find the real physical page to
+ * map, get the page, increment the use count and return it.
+ */
+#if __OS_HAS_AGP
+static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_map *map = NULL;
+       struct drm_map_list *r_list;
+       struct drm_hash_item *hash;
+
+       /*
+        * Find the right map
+        */
+       if (!drm_core_has_AGP(dev))
+               goto vm_fault_error;
+
+       if (!dev->agp || !dev->agp->cant_use_aperture)
+               goto vm_fault_error;
+
+       if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
+               goto vm_fault_error;
+
+       r_list = drm_hash_entry(hash, struct drm_map_list, hash);
+       map = r_list->map;
+
+       if (map && map->type == _DRM_AGP) {
+               /*
+                * Using vm_pgoff as a selector forces us to use this unusual
+                * addressing scheme.
+                */
+               unsigned long offset = (unsigned long)vmf->virtual_address -
+                                                               vma->vm_start;
+               unsigned long baddr = map->offset + offset;
+               struct drm_agp_mem *agpmem;
+               struct page *page;
+
+#ifdef __alpha__
+               /*
+                * Adjust to a bus-relative address
+                */
+               baddr -= dev->hose->mem_space->start;
+#endif
+
+               /*
+                * It's AGP memory - find the real physical page to map
+                */
+               list_for_each_entry(agpmem, &dev->agp->memory, head) {
+                       if (agpmem->bound <= baddr &&
+                           agpmem->bound + agpmem->pages * PAGE_SIZE > baddr)
+                               break;
+               }
+
+               if (!agpmem)
+                       goto vm_fault_error;
+
+               /*
+                * Get the page, inc the use count, and return it
+                */
+               offset = (baddr - agpmem->bound) >> PAGE_SHIFT;
+               page = virt_to_page(__va(agpmem->memory->memory[offset]));
+               get_page(page);
+               vmf->page = page;
+
+               DRM_DEBUG
+                   ("baddr = 0x%lx page = 0x%p, offset = 0x%lx, count=%d\n",
+                    baddr, __va(agpmem->memory->memory[offset]), offset,
+                    page_count(page));
+               return 0;
+       }
+vm_fault_error:
+       return VM_FAULT_SIGBUS; /* Disallow mremap */
+}
+#else                          /* __OS_HAS_AGP */
+static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       return VM_FAULT_SIGBUS;
+}
+#endif                         /* __OS_HAS_AGP */
+
+/**
+ * \c nopage method for shared virtual memory.
+ *
+ * \param vma virtual memory area.
+ * \param address access address.
+ * \return pointer to the page structure.
+ *
+ * Get the mapping, find the real physical page to map, get the page, and
+ * return it.
+ */
+static int drm_do_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       struct drm_map *map = (struct drm_map *) vma->vm_private_data;
+       unsigned long offset;
+       unsigned long i;
+       struct page *page;
+
+       if (!map)
+               return VM_FAULT_SIGBUS; /* Nothing allocated */
+
+       offset = (unsigned long)vmf->virtual_address - vma->vm_start;
+       i = (unsigned long)map->handle + offset;
+       page = vmalloc_to_page((void *)i);
+       if (!page)
+               return VM_FAULT_SIGBUS;
+       get_page(page);
+       vmf->page = page;
+
+       DRM_DEBUG("shm_fault 0x%lx\n", offset);
+       return 0;
+}
+
+/**
+ * \c close method for shared virtual memory.
+ *
+ * \param vma virtual memory area.
+ *
+ * Deletes map information if we are the last
+ * person to close a mapping and it's not in the global maplist.
+ */
+static void drm_vm_shm_close(struct vm_area_struct *vma)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_vma_entry *pt, *temp;
+       struct drm_map *map;
+       struct drm_map_list *r_list;
+       int found_maps = 0;
+
+       DRM_DEBUG("0x%08lx,0x%08lx\n",
+                 vma->vm_start, vma->vm_end - vma->vm_start);
+       atomic_dec(&dev->vma_count);
+
+       map = vma->vm_private_data;
+
+       mutex_lock(&dev->struct_mutex);
+       list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
+               if (pt->vma->vm_private_data == map)
+                       found_maps++;
+               if (pt->vma == vma) {
+                       list_del(&pt->head);
+                       drm_free(pt, sizeof(*pt), DRM_MEM_VMAS);
+               }
+       }
+
+       /* We were the only map that was found */
+       if (found_maps == 1 && map->flags & _DRM_REMOVABLE) {
+               /* Check to see if we are in the maplist, if we are not, then
+                * we delete this mappings information.
+                */
+               found_maps = 0;
+               list_for_each_entry(r_list, &dev->maplist, head) {
+                       if (r_list->map == map)
+                               found_maps++;
+               }
+
+               if (!found_maps) {
+                       drm_dma_handle_t dmah;
+
+                       switch (map->type) {
+                       case _DRM_REGISTERS:
+                       case _DRM_FRAME_BUFFER:
+                               if (drm_core_has_MTRR(dev) && map->mtrr >= 0) {
+                                       int retcode;
+                                       retcode = mtrr_del(map->mtrr,
+                                                          map->offset,
+                                                          map->size);
+                                       DRM_DEBUG("mtrr_del = %d\n", retcode);
+                               }
+                               iounmap(map->handle);
+                               break;
+                       case _DRM_SHM:
+                               vfree(map->handle);
+                               break;
+                       case _DRM_AGP:
+                       case _DRM_SCATTER_GATHER:
+                               break;
+                       case _DRM_CONSISTENT:
+                               dmah.vaddr = map->handle;
+                               dmah.busaddr = map->offset;
+                               dmah.size = map->size;
+                               __drm_pci_free(dev, &dmah);
+                               break;
+                       }
+                       drm_free(map, sizeof(*map), DRM_MEM_MAPS);
+               }
+       }
+       mutex_unlock(&dev->struct_mutex);
+}
+
+/**
+ * \c fault method for DMA virtual memory.
+ *
+ * \param vma virtual memory area.
+ * \param address access address.
+ * \return pointer to the page structure.
+ *
+ * Determine the page number from the page offset and get it from drm_device_dma::pagelist.
+ */
+static int drm_do_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_device_dma *dma = dev->dma;
+       unsigned long offset;
+       unsigned long page_nr;
+       struct page *page;
+
+       if (!dma)
+               return VM_FAULT_SIGBUS; /* Error */
+       if (!dma->pagelist)
+               return VM_FAULT_SIGBUS; /* Nothing allocated */
+
+       offset = (unsigned long)vmf->virtual_address - vma->vm_start;   /* vm_[pg]off[set] should be 0 */
+       page_nr = offset >> PAGE_SHIFT; /* page_nr could just be vmf->pgoff */
+       page = virt_to_page((dma->pagelist[page_nr] + (offset & (~PAGE_MASK))));
+
+       get_page(page);
+       vmf->page = page;
+
+       DRM_DEBUG("dma_fault 0x%lx (page %lu)\n", offset, page_nr);
+       return 0;
+}
+
+/**
+ * \c fault method for scatter-gather virtual memory.
+ *
+ * \param vma virtual memory area.
+ * \param address access address.
+ * \return pointer to the page structure.
+ *
+ * Determine the map offset from the page offset and get it from drm_sg_mem::pagelist.
+ */
+static int drm_do_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       struct drm_map *map = (struct drm_map *) vma->vm_private_data;
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_sg_mem *entry = dev->sg;
+       unsigned long offset;
+       unsigned long map_offset;
+       unsigned long page_offset;
+       struct page *page;
+
+       if (!entry)
+               return VM_FAULT_SIGBUS; /* Error */
+       if (!entry->pagelist)
+               return VM_FAULT_SIGBUS; /* Nothing allocated */
+
+       offset = (unsigned long)vmf->virtual_address - vma->vm_start;
+       map_offset = map->offset - (unsigned long)dev->sg->virtual;
+       page_offset = (offset >> PAGE_SHIFT) + (map_offset >> PAGE_SHIFT);
+       page = entry->pagelist[page_offset];
+       get_page(page);
+       vmf->page = page;
+
+       return 0;
+}
+
+static int drm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       return drm_do_vm_fault(vma, vmf);
+}
+
+static int drm_vm_shm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       return drm_do_vm_shm_fault(vma, vmf);
+}
+
+static int drm_vm_dma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       return drm_do_vm_dma_fault(vma, vmf);
+}
+
+static int drm_vm_sg_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+       return drm_do_vm_sg_fault(vma, vmf);
+}
+
+/** AGP virtual memory operations */
+static struct vm_operations_struct drm_vm_ops = {
+       .fault = drm_vm_fault,
+       .open = drm_vm_open,
+       .close = drm_vm_close,
+};
+
+/** Shared virtual memory operations */
+static struct vm_operations_struct drm_vm_shm_ops = {
+       .fault = drm_vm_shm_fault,
+       .open = drm_vm_open,
+       .close = drm_vm_shm_close,
+};
+
+/** DMA virtual memory operations */
+static struct vm_operations_struct drm_vm_dma_ops = {
+       .fault = drm_vm_dma_fault,
+       .open = drm_vm_open,
+       .close = drm_vm_close,
+};
+
+/** Scatter-gather virtual memory operations */
+static struct vm_operations_struct drm_vm_sg_ops = {
+       .fault = drm_vm_sg_fault,
+       .open = drm_vm_open,
+       .close = drm_vm_close,
+};
+
+/**
+ * \c open method for shared virtual memory.
+ *
+ * \param vma virtual memory area.
+ *
+ * Create a new drm_vma_entry structure as the \p vma private data entry and
+ * add it to drm_device::vmalist.
+ */
+static void drm_vm_open_locked(struct vm_area_struct *vma)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_vma_entry *vma_entry;
+
+       DRM_DEBUG("0x%08lx,0x%08lx\n",
+                 vma->vm_start, vma->vm_end - vma->vm_start);
+       atomic_inc(&dev->vma_count);
+
+       vma_entry = drm_alloc(sizeof(*vma_entry), DRM_MEM_VMAS);
+       if (vma_entry) {
+               vma_entry->vma = vma;
+               vma_entry->pid = current->pid;
+               list_add(&vma_entry->head, &dev->vmalist);
+       }
+}
+
+static void drm_vm_open(struct vm_area_struct *vma)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+
+       mutex_lock(&dev->struct_mutex);
+       drm_vm_open_locked(vma);
+       mutex_unlock(&dev->struct_mutex);
+}
+
+/**
+ * \c close method for all virtual memory types.
+ *
+ * \param vma virtual memory area.
+ *
+ * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
+ * free it.
+ */
+static void drm_vm_close(struct vm_area_struct *vma)
+{
+       struct drm_file *priv = vma->vm_file->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_vma_entry *pt, *temp;
+
+       DRM_DEBUG("0x%08lx,0x%08lx\n",
+                 vma->vm_start, vma->vm_end - vma->vm_start);
+       atomic_dec(&dev->vma_count);
+
+       mutex_lock(&dev->struct_mutex);
+       list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
+               if (pt->vma == vma) {
+                       list_del(&pt->head);
+                       drm_free(pt, sizeof(*pt), DRM_MEM_VMAS);
+                       break;
+               }
+       }
+       mutex_unlock(&dev->struct_mutex);
+}
+
+/**
+ * mmap DMA memory.
+ *
+ * \param file_priv DRM file private.
+ * \param vma virtual memory area.
+ * \return zero on success or a negative number on failure.
+ *
+ * Sets the virtual memory area operations structure to vm_dma_ops, the file
+ * pointer, and calls vm_open().
+ */
+static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev;
+       struct drm_device_dma *dma;
+       unsigned long length = vma->vm_end - vma->vm_start;
+
+       dev = priv->minor->dev;
+       dma = dev->dma;
+       DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
+                 vma->vm_start, vma->vm_end, vma->vm_pgoff);
+
+       /* Length must match exact page count */
+       if (!dma || (length >> PAGE_SHIFT) != dma->page_count) {
+               return -EINVAL;
+       }
+
+       if (!capable(CAP_SYS_ADMIN) &&
+           (dma->flags & _DRM_DMA_USE_PCI_RO)) {
+               vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
+#if defined(__i386__) || defined(__x86_64__)
+               pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
+#else
+               /* Ye gads this is ugly.  With more thought
+                  we could move this up higher and use
+                  `protection_map' instead.  */
+               vma->vm_page_prot =
+                   __pgprot(pte_val
+                            (pte_wrprotect
+                             (__pte(pgprot_val(vma->vm_page_prot)))));
+#endif
+       }
+
+       vma->vm_ops = &drm_vm_dma_ops;
+
+       vma->vm_flags |= VM_RESERVED;   /* Don't swap */
+       vma->vm_flags |= VM_DONTEXPAND;
+
+       vma->vm_file = filp;    /* Needed for drm_vm_open() */
+       drm_vm_open_locked(vma);
+       return 0;
+}
+
+unsigned long drm_core_get_map_ofs(struct drm_map * map)
+{
+       return map->offset;
+}
+
+EXPORT_SYMBOL(drm_core_get_map_ofs);
+
+unsigned long drm_core_get_reg_ofs(struct drm_device *dev)
+{
+#ifdef __alpha__
+       return dev->hose->dense_mem_base - dev->hose->mem_space->start;
+#else
+       return 0;
+#endif
+}
+
+EXPORT_SYMBOL(drm_core_get_reg_ofs);
+
+/**
+ * mmap DMA memory.
+ *
+ * \param file_priv DRM file private.
+ * \param vma virtual memory area.
+ * \return zero on success or a negative number on failure.
+ *
+ * If the virtual memory area has no offset associated with it then it's a DMA
+ * area, so calls mmap_dma(). Otherwise searches the map in drm_device::maplist,
+ * checks that the restricted flag is not set, sets the virtual memory operations
+ * according to the mapping type and remaps the pages. Finally sets the file
+ * pointer and calls vm_open().
+ */
+static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_map *map = NULL;
+       unsigned long offset = 0;
+       struct drm_hash_item *hash;
+
+       DRM_DEBUG("start = 0x%lx, end = 0x%lx, page offset = 0x%lx\n",
+                 vma->vm_start, vma->vm_end, vma->vm_pgoff);
+
+       if (!priv->authenticated)
+               return -EACCES;
+
+       /* We check for "dma". On Apple's UniNorth, it's valid to have
+        * the AGP mapped at physical address 0
+        * --BenH.
+        */
+       if (!vma->vm_pgoff
+#if __OS_HAS_AGP
+           && (!dev->agp
+               || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE)
+#endif
+           )
+               return drm_mmap_dma(filp, vma);
+
+       if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash)) {
+               DRM_ERROR("Could not find map\n");
+               return -EINVAL;
+       }
+
+       map = drm_hash_entry(hash, struct drm_map_list, hash)->map;
+       if (!map || ((map->flags & _DRM_RESTRICTED) && !capable(CAP_SYS_ADMIN)))
+               return -EPERM;
+
+       /* Check for valid size. */
+       if (map->size < vma->vm_end - vma->vm_start)
+               return -EINVAL;
+
+       if (!capable(CAP_SYS_ADMIN) && (map->flags & _DRM_READ_ONLY)) {
+               vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
+#if defined(__i386__) || defined(__x86_64__)
+               pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
+#else
+               /* Ye gads this is ugly.  With more thought
+                  we could move this up higher and use
+                  `protection_map' instead.  */
+               vma->vm_page_prot =
+                   __pgprot(pte_val
+                            (pte_wrprotect
+                             (__pte(pgprot_val(vma->vm_page_prot)))));
+#endif
+       }
+
+       switch (map->type) {
+       case _DRM_AGP:
+               if (drm_core_has_AGP(dev) && dev->agp->cant_use_aperture) {
+                       /*
+                        * On some platforms we can't talk to bus dma address from the CPU, so for
+                        * memory of type DRM_AGP, we'll deal with sorting out the real physical
+                        * pages and mappings in fault()
+                        */
+#if defined(__powerpc__)
+                       pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
+#endif
+                       vma->vm_ops = &drm_vm_ops;
+                       break;
+               }
+               /* fall through to _DRM_FRAME_BUFFER... */
+       case _DRM_FRAME_BUFFER:
+       case _DRM_REGISTERS:
+               offset = dev->driver->get_reg_ofs(dev);
+               vma->vm_flags |= VM_IO; /* not in core dump */
+               vma->vm_page_prot = drm_io_prot(map->type, vma);
+               if (io_remap_pfn_range(vma, vma->vm_start,
+                                      (map->offset + offset) >> PAGE_SHIFT,
+                                      vma->vm_end - vma->vm_start,
+                                      vma->vm_page_prot))
+                       return -EAGAIN;
+               DRM_DEBUG("   Type = %d; start = 0x%lx, end = 0x%lx,"
+                         " offset = 0x%lx\n",
+                         map->type,
+                         vma->vm_start, vma->vm_end, map->offset + offset);
+               vma->vm_ops = &drm_vm_ops;
+               break;
+       case _DRM_CONSISTENT:
+               /* Consistent memory is really like shared memory. But
+                * it's allocated in a different way, so avoid fault */
+               if (remap_pfn_range(vma, vma->vm_start,
+                   page_to_pfn(virt_to_page(map->handle)),
+                   vma->vm_end - vma->vm_start, vma->vm_page_prot))
+                       return -EAGAIN;
+               vma->vm_page_prot = drm_dma_prot(map->type, vma);
+       /* fall through to _DRM_SHM */
+       case _DRM_SHM:
+               vma->vm_ops = &drm_vm_shm_ops;
+               vma->vm_private_data = (void *)map;
+               /* Don't let this area swap.  Change when
+                  DRM_KERNEL advisory is supported. */
+               vma->vm_flags |= VM_RESERVED;
+               break;
+       case _DRM_SCATTER_GATHER:
+               vma->vm_ops = &drm_vm_sg_ops;
+               vma->vm_private_data = (void *)map;
+               vma->vm_flags |= VM_RESERVED;
+               vma->vm_page_prot = drm_dma_prot(map->type, vma);
+               break;
+       default:
+               return -EINVAL; /* This should never happen. */
+       }
+       vma->vm_flags |= VM_RESERVED;   /* Don't swap */
+       vma->vm_flags |= VM_DONTEXPAND;
+
+       vma->vm_file = filp;    /* Needed for drm_vm_open() */
+       drm_vm_open_locked(vma);
+       return 0;
+}
+
+int drm_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_mmap_locked(filp, vma);
+       mutex_unlock(&dev->struct_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL(drm_mmap);
diff --git a/drivers/gpu/drm/i810/Makefile b/drivers/gpu/drm/i810/Makefile
new file mode 100644 (file)
index 0000000..43844ec
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+i810-y := i810_drv.o i810_dma.o
+
+obj-$(CONFIG_DRM_I810) += i810.o
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
new file mode 100644 (file)
index 0000000..e5de8ea
--- /dev/null
@@ -0,0 +1,1283 @@
+/* i810_dma.c -- DMA support for the i810 -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ *         Jeff Hartmann <jhartmann@valinux.com>
+ *          Keith Whitwell <keith@tungstengraphics.com>
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i810_drm.h"
+#include "i810_drv.h"
+#include <linux/interrupt.h>   /* For task queue support */
+#include <linux/delay.h>
+#include <linux/pagemap.h>
+
+#define I810_BUF_FREE          2
+#define I810_BUF_CLIENT                1
+#define I810_BUF_HARDWARE      0
+
+#define I810_BUF_UNMAPPED 0
+#define I810_BUF_MAPPED   1
+
+static struct drm_buf *i810_freelist_get(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+       int used;
+
+       /* Linear search might not be the best solution */
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+               /* In use is already a pointer */
+               used = cmpxchg(buf_priv->in_use, I810_BUF_FREE,
+                              I810_BUF_CLIENT);
+               if (used == I810_BUF_FREE) {
+                       return buf;
+               }
+       }
+       return NULL;
+}
+
+/* This should only be called if the buffer is not sent to the hardware
+ * yet, the hardware updates in use for us once its on the ring buffer.
+ */
+
+static int i810_freelist_put(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+       int used;
+
+       /* In use is already a pointer */
+       used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_FREE);
+       if (used != I810_BUF_CLIENT) {
+               DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev;
+       drm_i810_private_t *dev_priv;
+       struct drm_buf *buf;
+       drm_i810_buf_priv_t *buf_priv;
+
+       lock_kernel();
+       dev = priv->minor->dev;
+       dev_priv = dev->dev_private;
+       buf = dev_priv->mmap_buffer;
+       buf_priv = buf->dev_private;
+
+       vma->vm_flags |= (VM_IO | VM_DONTCOPY);
+       vma->vm_file = filp;
+
+       buf_priv->currently_mapped = I810_BUF_MAPPED;
+       unlock_kernel();
+
+       if (io_remap_pfn_range(vma, vma->vm_start,
+                              vma->vm_pgoff,
+                              vma->vm_end - vma->vm_start, vma->vm_page_prot))
+               return -EAGAIN;
+       return 0;
+}
+
+static const struct file_operations i810_buffer_fops = {
+       .open = drm_open,
+       .release = drm_release,
+       .ioctl = drm_ioctl,
+       .mmap = i810_mmap_buffers,
+       .fasync = drm_fasync,
+};
+
+static int i810_map_buffer(struct drm_buf * buf, struct drm_file *file_priv)
+{
+       struct drm_device *dev = file_priv->minor->dev;
+       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       const struct file_operations *old_fops;
+       int retcode = 0;
+
+       if (buf_priv->currently_mapped == I810_BUF_MAPPED)
+               return -EINVAL;
+
+       down_write(&current->mm->mmap_sem);
+       old_fops = file_priv->filp->f_op;
+       file_priv->filp->f_op = &i810_buffer_fops;
+       dev_priv->mmap_buffer = buf;
+       buf_priv->virtual = (void *)do_mmap(file_priv->filp, 0, buf->total,
+                                           PROT_READ | PROT_WRITE,
+                                           MAP_SHARED, buf->bus_address);
+       dev_priv->mmap_buffer = NULL;
+       file_priv->filp->f_op = old_fops;
+       if (IS_ERR(buf_priv->virtual)) {
+               /* Real error */
+               DRM_ERROR("mmap error\n");
+               retcode = PTR_ERR(buf_priv->virtual);
+               buf_priv->virtual = NULL;
+       }
+       up_write(&current->mm->mmap_sem);
+
+       return retcode;
+}
+
+static int i810_unmap_buffer(struct drm_buf * buf)
+{
+       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+       int retcode = 0;
+
+       if (buf_priv->currently_mapped != I810_BUF_MAPPED)
+               return -EINVAL;
+
+       down_write(&current->mm->mmap_sem);
+       retcode = do_munmap(current->mm,
+                           (unsigned long)buf_priv->virtual,
+                           (size_t) buf->total);
+       up_write(&current->mm->mmap_sem);
+
+       buf_priv->currently_mapped = I810_BUF_UNMAPPED;
+       buf_priv->virtual = NULL;
+
+       return retcode;
+}
+
+static int i810_dma_get_buffer(struct drm_device * dev, drm_i810_dma_t * d,
+                              struct drm_file *file_priv)
+{
+       struct drm_buf *buf;
+       drm_i810_buf_priv_t *buf_priv;
+       int retcode = 0;
+
+       buf = i810_freelist_get(dev);
+       if (!buf) {
+               retcode = -ENOMEM;
+               DRM_DEBUG("retcode=%d\n", retcode);
+               return retcode;
+       }
+
+       retcode = i810_map_buffer(buf, file_priv);
+       if (retcode) {
+               i810_freelist_put(dev, buf);
+               DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
+               return retcode;
+       }
+       buf->file_priv = file_priv;
+       buf_priv = buf->dev_private;
+       d->granted = 1;
+       d->request_idx = buf->idx;
+       d->request_size = buf->total;
+       d->virtual = buf_priv->virtual;
+
+       return retcode;
+}
+
+static int i810_dma_cleanup(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (drm_core_check_feature(dev, DRIVER_HAVE_IRQ) && dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+       if (dev->dev_private) {
+               int i;
+               drm_i810_private_t *dev_priv =
+                   (drm_i810_private_t *) dev->dev_private;
+
+               if (dev_priv->ring.virtual_start) {
+                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
+               }
+               if (dev_priv->hw_status_page) {
+                       pci_free_consistent(dev->pdev, PAGE_SIZE,
+                                           dev_priv->hw_status_page,
+                                           dev_priv->dma_status_page);
+                       /* Need to rewrite hardware status page */
+                       I810_WRITE(0x02080, 0x1ffff000);
+               }
+               drm_free(dev->dev_private, sizeof(drm_i810_private_t),
+                        DRM_MEM_DRIVER);
+               dev->dev_private = NULL;
+
+               for (i = 0; i < dma->buf_count; i++) {
+                       struct drm_buf *buf = dma->buflist[i];
+                       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+
+                       if (buf_priv->kernel_virtual && buf->total)
+                               drm_core_ioremapfree(&buf_priv->map, dev);
+               }
+       }
+       return 0;
+}
+
+static int i810_wait_ring(struct drm_device * dev, int n)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
+       int iters = 0;
+       unsigned long end;
+       unsigned int last_head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+
+       end = jiffies + (HZ * 3);
+       while (ring->space < n) {
+               ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+               ring->space = ring->head - (ring->tail + 8);
+               if (ring->space < 0)
+                       ring->space += ring->Size;
+
+               if (ring->head != last_head) {
+                       end = jiffies + (HZ * 3);
+                       last_head = ring->head;
+               }
+
+               iters++;
+               if (time_before(end, jiffies)) {
+                       DRM_ERROR("space: %d wanted %d\n", ring->space, n);
+                       DRM_ERROR("lockup\n");
+                       goto out_wait_ring;
+               }
+               udelay(1);
+       }
+
+      out_wait_ring:
+       return iters;
+}
+
+static void i810_kernel_lost_context(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_ring_buffer_t *ring = &(dev_priv->ring);
+
+       ring->head = I810_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       ring->tail = I810_READ(LP_RING + RING_TAIL);
+       ring->space = ring->head - (ring->tail + 8);
+       if (ring->space < 0)
+               ring->space += ring->Size;
+}
+
+static int i810_freelist_init(struct drm_device * dev, drm_i810_private_t * dev_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int my_idx = 24;
+       u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
+       int i;
+
+       if (dma->buf_count > 1019) {
+               /* Not enough space in the status page for the freelist */
+               return -EINVAL;
+       }
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+
+               buf_priv->in_use = hw_status++;
+               buf_priv->my_use_idx = my_idx;
+               my_idx += 4;
+
+               *buf_priv->in_use = I810_BUF_FREE;
+
+               buf_priv->map.offset = buf->bus_address;
+               buf_priv->map.size = buf->total;
+               buf_priv->map.type = _DRM_AGP;
+               buf_priv->map.flags = 0;
+               buf_priv->map.mtrr = 0;
+
+               drm_core_ioremap(&buf_priv->map, dev);
+               buf_priv->kernel_virtual = buf_priv->map.handle;
+
+       }
+       return 0;
+}
+
+static int i810_dma_initialize(struct drm_device * dev,
+                              drm_i810_private_t * dev_priv,
+                              drm_i810_init_t * init)
+{
+       struct drm_map_list *r_list;
+       memset(dev_priv, 0, sizeof(drm_i810_private_t));
+
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               if (r_list->map &&
+                   r_list->map->type == _DRM_SHM &&
+                   r_list->map->flags & _DRM_CONTAINS_LOCK) {
+                       dev_priv->sarea_map = r_list->map;
+                       break;
+               }
+       }
+       if (!dev_priv->sarea_map) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("can not find sarea!\n");
+               return -EINVAL;
+       }
+       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
+       if (!dev_priv->mmio_map) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("can not find mmio map!\n");
+               return -EINVAL;
+       }
+       dev->agp_buffer_token = init->buffers_offset;
+       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
+       if (!dev->agp_buffer_map) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("can not find dma buffer map!\n");
+               return -EINVAL;
+       }
+
+       dev_priv->sarea_priv = (drm_i810_sarea_t *)
+           ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
+
+       dev_priv->ring.Start = init->ring_start;
+       dev_priv->ring.End = init->ring_end;
+       dev_priv->ring.Size = init->ring_size;
+
+       dev_priv->ring.map.offset = dev->agp->base + init->ring_start;
+       dev_priv->ring.map.size = init->ring_size;
+       dev_priv->ring.map.type = _DRM_AGP;
+       dev_priv->ring.map.flags = 0;
+       dev_priv->ring.map.mtrr = 0;
+
+       drm_core_ioremap(&dev_priv->ring.map, dev);
+
+       if (dev_priv->ring.map.handle == NULL) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("can not ioremap virtual address for"
+                         " ring buffer\n");
+               return -ENOMEM;
+       }
+
+       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+
+       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+
+       dev_priv->w = init->w;
+       dev_priv->h = init->h;
+       dev_priv->pitch = init->pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->front_offset = init->front_offset;
+
+       dev_priv->overlay_offset = init->overlay_offset;
+       dev_priv->overlay_physical = init->overlay_physical;
+
+       dev_priv->front_di1 = init->front_offset | init->pitch_bits;
+       dev_priv->back_di1 = init->back_offset | init->pitch_bits;
+       dev_priv->zi1 = init->depth_offset | init->pitch_bits;
+
+       /* Program Hardware Status Page */
+       dev_priv->hw_status_page =
+           pci_alloc_consistent(dev->pdev, PAGE_SIZE,
+                                &dev_priv->dma_status_page);
+       if (!dev_priv->hw_status_page) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("Can not allocate hardware status page\n");
+               return -ENOMEM;
+       }
+       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
+
+       I810_WRITE(0x02080, dev_priv->dma_status_page);
+       DRM_DEBUG("Enabled hardware status page\n");
+
+       /* Now we need to init our freelist */
+       if (i810_freelist_init(dev, dev_priv) != 0) {
+               dev->dev_private = (void *)dev_priv;
+               i810_dma_cleanup(dev);
+               DRM_ERROR("Not enough space in the status page for"
+                         " the freelist\n");
+               return -ENOMEM;
+       }
+       dev->dev_private = (void *)dev_priv;
+
+       return 0;
+}
+
+static int i810_dma_init(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv;
+       drm_i810_init_t *init = data;
+       int retcode = 0;
+
+       switch (init->func) {
+       case I810_INIT_DMA_1_4:
+               DRM_INFO("Using v1.4 init.\n");
+               dev_priv = drm_alloc(sizeof(drm_i810_private_t),
+                                    DRM_MEM_DRIVER);
+               if (dev_priv == NULL)
+                       return -ENOMEM;
+               retcode = i810_dma_initialize(dev, dev_priv, init);
+               break;
+
+       case I810_CLEANUP_DMA:
+               DRM_INFO("DMA Cleanup\n");
+               retcode = i810_dma_cleanup(dev);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return retcode;
+}
+
+/* Most efficient way to verify state for the i810 is as it is
+ * emitted.  Non-conformant state is silently dropped.
+ *
+ * Use 'volatile' & local var tmp to force the emitted values to be
+ * identical to the verified ones.
+ */
+static void i810EmitContextVerified(struct drm_device * dev,
+                                   volatile unsigned int *code)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       int i, j = 0;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(I810_CTX_SETUP_SIZE);
+
+       OUT_RING(GFX_OP_COLOR_FACTOR);
+       OUT_RING(code[I810_CTXREG_CF1]);
+
+       OUT_RING(GFX_OP_STIPPLE);
+       OUT_RING(code[I810_CTXREG_ST1]);
+
+       for (i = 4; i < I810_CTX_SETUP_SIZE; i++) {
+               tmp = code[i];
+
+               if ((tmp & (7 << 29)) == (3 << 29) &&
+                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
+                       OUT_RING(tmp);
+                       j++;
+               } else
+                       printk("constext state dropped!!!\n");
+       }
+
+       if (j & 1)
+               OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+static void i810EmitTexVerified(struct drm_device * dev, volatile unsigned int *code)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       int i, j = 0;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(I810_TEX_SETUP_SIZE);
+
+       OUT_RING(GFX_OP_MAP_INFO);
+       OUT_RING(code[I810_TEXREG_MI1]);
+       OUT_RING(code[I810_TEXREG_MI2]);
+       OUT_RING(code[I810_TEXREG_MI3]);
+
+       for (i = 4; i < I810_TEX_SETUP_SIZE; i++) {
+               tmp = code[i];
+
+               if ((tmp & (7 << 29)) == (3 << 29) &&
+                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
+                       OUT_RING(tmp);
+                       j++;
+               } else
+                       printk("texture state dropped!!!\n");
+       }
+
+       if (j & 1)
+               OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+/* Need to do some additional checking when setting the dest buffer.
+ */
+static void i810EmitDestVerified(struct drm_device * dev,
+                                volatile unsigned int *code)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
+
+       tmp = code[I810_DESTREG_DI1];
+       if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
+               OUT_RING(CMD_OP_DESTBUFFER_INFO);
+               OUT_RING(tmp);
+       } else
+               DRM_DEBUG("bad di1 %x (allow %x or %x)\n",
+                         tmp, dev_priv->front_di1, dev_priv->back_di1);
+
+       /* invarient:
+        */
+       OUT_RING(CMD_OP_Z_BUFFER_INFO);
+       OUT_RING(dev_priv->zi1);
+
+       OUT_RING(GFX_OP_DESTBUFFER_VARS);
+       OUT_RING(code[I810_DESTREG_DV1]);
+
+       OUT_RING(GFX_OP_DRAWRECT_INFO);
+       OUT_RING(code[I810_DESTREG_DR1]);
+       OUT_RING(code[I810_DESTREG_DR2]);
+       OUT_RING(code[I810_DESTREG_DR3]);
+       OUT_RING(code[I810_DESTREG_DR4]);
+       OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+static void i810EmitState(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+
+       DRM_DEBUG("%x\n", dirty);
+
+       if (dirty & I810_UPLOAD_BUFFERS) {
+               i810EmitDestVerified(dev, sarea_priv->BufferState);
+               sarea_priv->dirty &= ~I810_UPLOAD_BUFFERS;
+       }
+
+       if (dirty & I810_UPLOAD_CTX) {
+               i810EmitContextVerified(dev, sarea_priv->ContextState);
+               sarea_priv->dirty &= ~I810_UPLOAD_CTX;
+       }
+
+       if (dirty & I810_UPLOAD_TEX0) {
+               i810EmitTexVerified(dev, sarea_priv->TexState[0]);
+               sarea_priv->dirty &= ~I810_UPLOAD_TEX0;
+       }
+
+       if (dirty & I810_UPLOAD_TEX1) {
+               i810EmitTexVerified(dev, sarea_priv->TexState[1]);
+               sarea_priv->dirty &= ~I810_UPLOAD_TEX1;
+       }
+}
+
+/* need to verify
+ */
+static void i810_dma_dispatch_clear(struct drm_device * dev, int flags,
+                                   unsigned int clear_color,
+                                   unsigned int clear_zval)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int pitch = dev_priv->pitch;
+       int cpp = 2;
+       int i;
+       RING_LOCALS;
+
+       if (dev_priv->current_page == 1) {
+               unsigned int tmp = flags;
+
+               flags &= ~(I810_FRONT | I810_BACK);
+               if (tmp & I810_FRONT)
+                       flags |= I810_BACK;
+               if (tmp & I810_BACK)
+                       flags |= I810_FRONT;
+       }
+
+       i810_kernel_lost_context(dev);
+
+       if (nbox > I810_NR_SAREA_CLIPRECTS)
+               nbox = I810_NR_SAREA_CLIPRECTS;
+
+       for (i = 0; i < nbox; i++, pbox++) {
+               unsigned int x = pbox->x1;
+               unsigned int y = pbox->y1;
+               unsigned int width = (pbox->x2 - x) * cpp;
+               unsigned int height = pbox->y2 - y;
+               unsigned int start = y * pitch + x * cpp;
+
+               if (pbox->x1 > pbox->x2 ||
+                   pbox->y1 > pbox->y2 ||
+                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
+                       continue;
+
+               if (flags & I810_FRONT) {
+                       BEGIN_LP_RING(6);
+                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+                       OUT_RING((height << 16) | width);
+                       OUT_RING(start);
+                       OUT_RING(clear_color);
+                       OUT_RING(0);
+                       ADVANCE_LP_RING();
+               }
+
+               if (flags & I810_BACK) {
+                       BEGIN_LP_RING(6);
+                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+                       OUT_RING((height << 16) | width);
+                       OUT_RING(dev_priv->back_offset + start);
+                       OUT_RING(clear_color);
+                       OUT_RING(0);
+                       ADVANCE_LP_RING();
+               }
+
+               if (flags & I810_DEPTH) {
+                       BEGIN_LP_RING(6);
+                       OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3);
+                       OUT_RING(BR13_SOLID_PATTERN | (0xF0 << 16) | pitch);
+                       OUT_RING((height << 16) | width);
+                       OUT_RING(dev_priv->depth_offset + start);
+                       OUT_RING(clear_zval);
+                       OUT_RING(0);
+                       ADVANCE_LP_RING();
+               }
+       }
+}
+
+static void i810_dma_dispatch_swap(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int pitch = dev_priv->pitch;
+       int cpp = 2;
+       int i;
+       RING_LOCALS;
+
+       DRM_DEBUG("swapbuffers\n");
+
+       i810_kernel_lost_context(dev);
+
+       if (nbox > I810_NR_SAREA_CLIPRECTS)
+               nbox = I810_NR_SAREA_CLIPRECTS;
+
+       for (i = 0; i < nbox; i++, pbox++) {
+               unsigned int w = pbox->x2 - pbox->x1;
+               unsigned int h = pbox->y2 - pbox->y1;
+               unsigned int dst = pbox->x1 * cpp + pbox->y1 * pitch;
+               unsigned int start = dst;
+
+               if (pbox->x1 > pbox->x2 ||
+                   pbox->y1 > pbox->y2 ||
+                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
+                       continue;
+
+               BEGIN_LP_RING(6);
+               OUT_RING(BR00_BITBLT_CLIENT | BR00_OP_SRC_COPY_BLT | 0x4);
+               OUT_RING(pitch | (0xCC << 16));
+               OUT_RING((h << 16) | (w * cpp));
+               if (dev_priv->current_page == 0)
+                       OUT_RING(dev_priv->front_offset + start);
+               else
+                       OUT_RING(dev_priv->back_offset + start);
+               OUT_RING(pitch);
+               if (dev_priv->current_page == 0)
+                       OUT_RING(dev_priv->back_offset + start);
+               else
+                       OUT_RING(dev_priv->front_offset + start);
+               ADVANCE_LP_RING();
+       }
+}
+
+static void i810_dma_dispatch_vertex(struct drm_device * dev,
+                                    struct drm_buf * buf, int discard, int used)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_clip_rect *box = sarea_priv->boxes;
+       int nbox = sarea_priv->nbox;
+       unsigned long address = (unsigned long)buf->bus_address;
+       unsigned long start = address - dev->agp->base;
+       int i = 0;
+       RING_LOCALS;
+
+       i810_kernel_lost_context(dev);
+
+       if (nbox > I810_NR_SAREA_CLIPRECTS)
+               nbox = I810_NR_SAREA_CLIPRECTS;
+
+       if (used > 4 * 1024)
+               used = 0;
+
+       if (sarea_priv->dirty)
+               i810EmitState(dev);
+
+       if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
+               unsigned int prim = (sarea_priv->vertex_prim & PR_MASK);
+
+               *(u32 *) buf_priv->kernel_virtual =
+                   ((GFX_OP_PRIMITIVE | prim | ((used / 4) - 2)));
+
+               if (used & 4) {
+                       *(u32 *) ((char *) buf_priv->kernel_virtual + used) = 0;
+                       used += 4;
+               }
+
+               i810_unmap_buffer(buf);
+       }
+
+       if (used) {
+               do {
+                       if (i < nbox) {
+                               BEGIN_LP_RING(4);
+                               OUT_RING(GFX_OP_SCISSOR | SC_UPDATE_SCISSOR |
+                                        SC_ENABLE);
+                               OUT_RING(GFX_OP_SCISSOR_INFO);
+                               OUT_RING(box[i].x1 | (box[i].y1 << 16));
+                               OUT_RING((box[i].x2 -
+                                         1) | ((box[i].y2 - 1) << 16));
+                               ADVANCE_LP_RING();
+                       }
+
+                       BEGIN_LP_RING(4);
+                       OUT_RING(CMD_OP_BATCH_BUFFER);
+                       OUT_RING(start | BB1_PROTECTED);
+                       OUT_RING(start + used - 4);
+                       OUT_RING(0);
+                       ADVANCE_LP_RING();
+
+               } while (++i < nbox);
+       }
+
+       if (discard) {
+               dev_priv->counter++;
+
+               (void)cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
+                             I810_BUF_HARDWARE);
+
+               BEGIN_LP_RING(8);
+               OUT_RING(CMD_STORE_DWORD_IDX);
+               OUT_RING(20);
+               OUT_RING(dev_priv->counter);
+               OUT_RING(CMD_STORE_DWORD_IDX);
+               OUT_RING(buf_priv->my_use_idx);
+               OUT_RING(I810_BUF_FREE);
+               OUT_RING(CMD_REPORT_HEAD);
+               OUT_RING(0);
+               ADVANCE_LP_RING();
+       }
+}
+
+static void i810_dma_dispatch_flip(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       int pitch = dev_priv->pitch;
+       RING_LOCALS;
+
+       DRM_DEBUG("page=%d pfCurrentPage=%d\n",
+                 dev_priv->current_page,
+                 dev_priv->sarea_priv->pf_current_page);
+
+       i810_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(2);
+       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(I810_DEST_SETUP_SIZE + 2);
+       /* On i815 at least ASYNC is buggy */
+       /* pitch<<5 is from 11.2.8 p158,
+          its the pitch / 8 then left shifted 8,
+          so (pitch >> 3) << 8 */
+       OUT_RING(CMD_OP_FRONTBUFFER_INFO | (pitch << 5) /*| ASYNC_FLIP */ );
+       if (dev_priv->current_page == 0) {
+               OUT_RING(dev_priv->back_offset);
+               dev_priv->current_page = 1;
+       } else {
+               OUT_RING(dev_priv->front_offset);
+               dev_priv->current_page = 0;
+       }
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(2);
+       OUT_RING(CMD_OP_WAIT_FOR_EVENT | WAIT_FOR_PLANE_A_FLIP);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       /* Increment the frame counter.  The client-side 3D driver must
+        * throttle the framerate by waiting for this value before
+        * performing the swapbuffer ioctl.
+        */
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+
+}
+
+static void i810_dma_quiescent(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       i810_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(4);
+       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+       OUT_RING(CMD_REPORT_HEAD);
+       OUT_RING(0);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       i810_wait_ring(dev, dev_priv->ring.Size - 8);
+}
+
+static int i810_flush_queue(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       int i, ret = 0;
+       RING_LOCALS;
+
+       i810_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(2);
+       OUT_RING(CMD_REPORT_HEAD);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       i810_wait_ring(dev, dev_priv->ring.Size - 8);
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+
+               int used = cmpxchg(buf_priv->in_use, I810_BUF_HARDWARE,
+                                  I810_BUF_FREE);
+
+               if (used == I810_BUF_HARDWARE)
+                       DRM_DEBUG("reclaimed from HARDWARE\n");
+               if (used == I810_BUF_CLIENT)
+                       DRM_DEBUG("still on client\n");
+       }
+
+       return ret;
+}
+
+/* Must be called with the lock held */
+static void i810_reclaim_buffers(struct drm_device * dev,
+                                struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+
+       if (!dma)
+               return;
+       if (!dev->dev_private)
+               return;
+       if (!dma->buflist)
+               return;
+
+       i810_flush_queue(dev);
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+
+               if (buf->file_priv == file_priv && buf_priv) {
+                       int used = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT,
+                                          I810_BUF_FREE);
+
+                       if (used == I810_BUF_CLIENT)
+                               DRM_DEBUG("reclaimed from client\n");
+                       if (buf_priv->currently_mapped == I810_BUF_MAPPED)
+                               buf_priv->currently_mapped = I810_BUF_UNMAPPED;
+               }
+       }
+}
+
+static int i810_flush_ioctl(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv)
+{
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       i810_flush_queue(dev);
+       return 0;
+}
+
+static int i810_dma_vertex(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+           dev_priv->sarea_priv;
+       drm_i810_vertex_t *vertex = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("idx %d used %d discard %d\n",
+                 vertex->idx, vertex->used, vertex->discard);
+
+       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
+               return -EINVAL;
+
+       i810_dma_dispatch_vertex(dev,
+                                dma->buflist[vertex->idx],
+                                vertex->discard, vertex->used);
+
+       atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
+       atomic_inc(&dev->counts[_DRM_STAT_DMA]);
+       sarea_priv->last_enqueue = dev_priv->counter - 1;
+       sarea_priv->last_dispatch = (int)hw_status[5];
+
+       return 0;
+}
+
+static int i810_clear_bufs(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv)
+{
+       drm_i810_clear_t *clear = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* GH: Someone's doing nasty things... */
+       if (!dev->dev_private) {
+               return -EINVAL;
+       }
+
+       i810_dma_dispatch_clear(dev, clear->flags,
+                               clear->clear_color, clear->clear_depth);
+       return 0;
+}
+
+static int i810_swap_bufs(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       i810_dma_dispatch_swap(dev);
+       return 0;
+}
+
+static int i810_getage(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+           dev_priv->sarea_priv;
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+       return 0;
+}
+
+static int i810_getbuf(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       int retcode = 0;
+       drm_i810_dma_t *d = data;
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+           dev_priv->sarea_priv;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       d->granted = 0;
+
+       retcode = i810_dma_get_buffer(dev, d, file_priv);
+
+       DRM_DEBUG("i810_dma: %d returning %d, granted = %d\n",
+                 task_pid_nr(current), retcode, d->granted);
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+
+       return retcode;
+}
+
+static int i810_copybuf(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       /* Never copy - 2.4.x doesn't need it */
+       return 0;
+}
+
+static int i810_docopy(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       /* Never copy - 2.4.x doesn't need it */
+       return 0;
+}
+
+static void i810_dma_dispatch_mc(struct drm_device * dev, struct drm_buf * buf, int used,
+                                unsigned int last_render)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+       drm_i810_buf_priv_t *buf_priv = buf->dev_private;
+       drm_i810_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned long address = (unsigned long)buf->bus_address;
+       unsigned long start = address - dev->agp->base;
+       int u;
+       RING_LOCALS;
+
+       i810_kernel_lost_context(dev);
+
+       u = cmpxchg(buf_priv->in_use, I810_BUF_CLIENT, I810_BUF_HARDWARE);
+       if (u != I810_BUF_CLIENT) {
+               DRM_DEBUG("MC found buffer that isn't mine!\n");
+       }
+
+       if (used > 4 * 1024)
+               used = 0;
+
+       sarea_priv->dirty = 0x7f;
+
+       DRM_DEBUG("addr 0x%lx, used 0x%x\n", address, used);
+
+       dev_priv->counter++;
+       DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
+       DRM_DEBUG("start : %lx\n", start);
+       DRM_DEBUG("used : %d\n", used);
+       DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
+
+       if (buf_priv->currently_mapped == I810_BUF_MAPPED) {
+               if (used & 4) {
+                       *(u32 *) ((char *) buf_priv->virtual + used) = 0;
+                       used += 4;
+               }
+
+               i810_unmap_buffer(buf);
+       }
+       BEGIN_LP_RING(4);
+       OUT_RING(CMD_OP_BATCH_BUFFER);
+       OUT_RING(start | BB1_PROTECTED);
+       OUT_RING(start + used - 4);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(8);
+       OUT_RING(CMD_STORE_DWORD_IDX);
+       OUT_RING(buf_priv->my_use_idx);
+       OUT_RING(I810_BUF_FREE);
+       OUT_RING(0);
+
+       OUT_RING(CMD_STORE_DWORD_IDX);
+       OUT_RING(16);
+       OUT_RING(last_render);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+}
+
+static int i810_dma_mc(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i810_sarea_t *sarea_priv = (drm_i810_sarea_t *)
+           dev_priv->sarea_priv;
+       drm_i810_mc_t *mc = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (mc->idx >= dma->buf_count || mc->idx < 0)
+               return -EINVAL;
+
+       i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
+                            mc->last_render);
+
+       atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
+       atomic_inc(&dev->counts[_DRM_STAT_DMA]);
+       sarea_priv->last_enqueue = dev_priv->counter - 1;
+       sarea_priv->last_dispatch = (int)hw_status[5];
+
+       return 0;
+}
+
+static int i810_rstatus(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+
+       return (int)(((u32 *) (dev_priv->hw_status_page))[4]);
+}
+
+static int i810_ov0_info(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+       drm_i810_overlay_t *ov = data;
+
+       ov->offset = dev_priv->overlay_offset;
+       ov->physical = dev_priv->overlay_physical;
+
+       return 0;
+}
+
+static int i810_fstatus(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+       return I810_READ(0x30008);
+}
+
+static int i810_ov0_flip(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = (drm_i810_private_t *) dev->dev_private;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       //Tell the overlay to update
+       I810_WRITE(0x30000, dev_priv->overlay_physical | 0x80000000);
+
+       return 0;
+}
+
+/* Not sure why this isn't set all the time:
+ */
+static void i810_do_init_pageflip(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+       dev_priv->page_flipping = 1;
+       dev_priv->current_page = 0;
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+}
+
+static int i810_do_cleanup_pageflip(struct drm_device * dev)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+       if (dev_priv->current_page != 0)
+               i810_dma_dispatch_flip(dev);
+
+       dev_priv->page_flipping = 0;
+       return 0;
+}
+
+static int i810_flip_bufs(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       drm_i810_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv->page_flipping)
+               i810_do_init_pageflip(dev);
+
+       i810_dma_dispatch_flip(dev);
+       return 0;
+}
+
+int i810_driver_load(struct drm_device *dev, unsigned long flags)
+{
+       /* i810 has 4 more counters */
+       dev->counters += 4;
+       dev->types[6] = _DRM_STAT_IRQ;
+       dev->types[7] = _DRM_STAT_PRIMARY;
+       dev->types[8] = _DRM_STAT_SECONDARY;
+       dev->types[9] = _DRM_STAT_DMA;
+
+       return 0;
+}
+
+void i810_driver_lastclose(struct drm_device * dev)
+{
+       i810_dma_cleanup(dev);
+}
+
+void i810_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
+{
+       if (dev->dev_private) {
+               drm_i810_private_t *dev_priv = dev->dev_private;
+               if (dev_priv->page_flipping) {
+                       i810_do_cleanup_pageflip(dev);
+               }
+       }
+}
+
+void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
+                                       struct drm_file *file_priv)
+{
+       i810_reclaim_buffers(dev, file_priv);
+}
+
+int i810_driver_dma_quiescent(struct drm_device * dev)
+{
+       i810_dma_quiescent(dev);
+       return 0;
+}
+
+struct drm_ioctl_desc i810_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_I810_INIT, i810_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I810_VERTEX, i810_dma_vertex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_CLEAR, i810_clear_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_FLUSH, i810_flush_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_GETAGE, i810_getage, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_GETBUF, i810_getbuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_SWAP, i810_swap_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_COPY, i810_copybuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_DOCOPY, i810_docopy, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_OV0INFO, i810_ov0_info, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_FSTATUS, i810_fstatus, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_OV0FLIP, i810_ov0_flip, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_MC, i810_dma_mc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I810_RSTATUS, i810_rstatus, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I810_FLIP, i810_flip_bufs, DRM_AUTH)
+};
+
+int i810_max_ioctl = DRM_ARRAY_SIZE(i810_ioctls);
+
+/**
+ * Determine if the device really is AGP or not.
+ *
+ * All Intel graphics chipsets are treated as AGP, even if they are really
+ * PCI-e.
+ *
+ * \param dev   The device to be tested.
+ *
+ * \returns
+ * A value of 1 is always retured to indictate every i810 is AGP.
+ */
+int i810_driver_device_is_agp(struct drm_device * dev)
+{
+       return 1;
+}
diff --git a/drivers/gpu/drm/i810/i810_drv.c b/drivers/gpu/drm/i810/i810_drv.c
new file mode 100644 (file)
index 0000000..fabb9a8
--- /dev/null
@@ -0,0 +1,97 @@
+/* i810_drv.c -- I810 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Jeff Hartmann <jhartmann@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i810_drm.h"
+#include "i810_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       i810_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+           DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
+       .dev_priv_size = sizeof(drm_i810_buf_priv_t),
+       .load = i810_driver_load,
+       .lastclose = i810_driver_lastclose,
+       .preclose = i810_driver_preclose,
+       .device_is_agp = i810_driver_device_is_agp,
+       .reclaim_buffers_locked = i810_driver_reclaim_buffers_locked,
+       .dma_quiescent = i810_driver_dma_quiescent,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = i810_ioctls,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init i810_init(void)
+{
+       driver.num_ioctls = i810_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit i810_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(i810_init);
+module_exit(i810_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
new file mode 100644 (file)
index 0000000..0118849
--- /dev/null
@@ -0,0 +1,242 @@
+/* i810_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ *         Jeff Hartmann <jhartmann@valinux.com>
+ *
+ */
+
+#ifndef _I810_DRV_H_
+#define _I810_DRV_H_
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "VA Linux Systems Inc."
+
+#define DRIVER_NAME            "i810"
+#define DRIVER_DESC            "Intel i810"
+#define DRIVER_DATE            "20030605"
+
+/* Interface history
+ *
+ * 1.1   - XFree86 4.1
+ * 1.2   - XvMC interfaces
+ *       - XFree86 4.2
+ * 1.2.1 - Disable copying code (leave stub ioctls for backwards compatibility)
+ *       - Remove requirement for interrupt (leave stubs again)
+ * 1.3   - Add page flipping.
+ * 1.4   - fix DRM interface
+ */
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           4
+#define DRIVER_PATCHLEVEL      0
+
+typedef struct drm_i810_buf_priv {
+       u32 *in_use;
+       int my_use_idx;
+       int currently_mapped;
+       void *virtual;
+       void *kernel_virtual;
+       drm_local_map_t map;
+} drm_i810_buf_priv_t;
+
+typedef struct _drm_i810_ring_buffer {
+       int tail_mask;
+       unsigned long Start;
+       unsigned long End;
+       unsigned long Size;
+       u8 *virtual_start;
+       int head;
+       int tail;
+       int space;
+       drm_local_map_t map;
+} drm_i810_ring_buffer_t;
+
+typedef struct drm_i810_private {
+       struct drm_map *sarea_map;
+       struct drm_map *mmio_map;
+
+       drm_i810_sarea_t *sarea_priv;
+       drm_i810_ring_buffer_t ring;
+
+       void *hw_status_page;
+       unsigned long counter;
+
+       dma_addr_t dma_status_page;
+
+       struct drm_buf *mmap_buffer;
+
+       u32 front_di1, back_di1, zi1;
+
+       int back_offset;
+       int depth_offset;
+       int overlay_offset;
+       int overlay_physical;
+       int w, h;
+       int pitch;
+       int back_pitch;
+       int depth_pitch;
+
+       int do_boxes;
+       int dma_used;
+
+       int current_page;
+       int page_flipping;
+
+       wait_queue_head_t irq_queue;
+       atomic_t irq_received;
+       atomic_t irq_emitted;
+
+       int front_offset;
+} drm_i810_private_t;
+
+                               /* i810_dma.c */
+extern int i810_driver_dma_quiescent(struct drm_device * dev);
+extern void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
+                                              struct drm_file *file_priv);
+extern int i810_driver_load(struct drm_device *, unsigned long flags);
+extern void i810_driver_lastclose(struct drm_device * dev);
+extern void i810_driver_preclose(struct drm_device * dev,
+                                struct drm_file *file_priv);
+extern void i810_driver_reclaim_buffers_locked(struct drm_device * dev,
+                                              struct drm_file *file_priv);
+extern int i810_driver_device_is_agp(struct drm_device * dev);
+
+extern struct drm_ioctl_desc i810_ioctls[];
+extern int i810_max_ioctl;
+
+#define I810_BASE(reg)         ((unsigned long) \
+                               dev_priv->mmio_map->handle)
+#define I810_ADDR(reg)         (I810_BASE(reg) + reg)
+#define I810_DEREF(reg)                *(__volatile__ int *)I810_ADDR(reg)
+#define I810_READ(reg)         I810_DEREF(reg)
+#define I810_WRITE(reg,val)    do { I810_DEREF(reg) = val; } while (0)
+#define I810_DEREF16(reg)      *(__volatile__ u16 *)I810_ADDR(reg)
+#define I810_READ16(reg)       I810_DEREF16(reg)
+#define I810_WRITE16(reg,val)  do { I810_DEREF16(reg) = val; } while (0)
+
+#define I810_VERBOSE 0
+#define RING_LOCALS    unsigned int outring, ringmask; \
+                        volatile char *virt;
+
+#define BEGIN_LP_RING(n) do {                                          \
+       if (I810_VERBOSE)                                               \
+               DRM_DEBUG("BEGIN_LP_RING(%d)\n", n);                    \
+       if (dev_priv->ring.space < n*4)                                 \
+               i810_wait_ring(dev, n*4);                               \
+       dev_priv->ring.space -= n*4;                                    \
+       outring = dev_priv->ring.tail;                                  \
+       ringmask = dev_priv->ring.tail_mask;                            \
+       virt = dev_priv->ring.virtual_start;                            \
+} while (0)
+
+#define ADVANCE_LP_RING() do {                                 \
+       if (I810_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING\n");       \
+       dev_priv->ring.tail = outring;                          \
+       I810_WRITE(LP_RING + RING_TAIL, outring);               \
+} while(0)
+
+#define OUT_RING(n) do {                                               \
+       if (I810_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
+       *(volatile unsigned int *)(virt + outring) = n;                 \
+       outring += 4;                                                   \
+       outring &= ringmask;                                            \
+} while (0)
+
+#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
+#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
+#define CMD_REPORT_HEAD                        (7<<23)
+#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
+#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
+
+#define INST_PARSER_CLIENT   0x00000000
+#define INST_OP_FLUSH        0x02000000
+#define INST_FLUSH_MAP_CACHE 0x00000001
+
+#define BB1_START_ADDR_MASK   (~0x7)
+#define BB1_PROTECTED         (1<<0)
+#define BB1_UNPROTECTED       (0<<0)
+#define BB2_END_ADDR_MASK     (~0x7)
+
+#define I810REG_HWSTAM         0x02098
+#define I810REG_INT_IDENTITY_R 0x020a4
+#define I810REG_INT_MASK_R     0x020a8
+#define I810REG_INT_ENABLE_R   0x020a0
+
+#define LP_RING                        0x2030
+#define HP_RING                        0x2040
+#define RING_TAIL              0x00
+#define TAIL_ADDR              0x000FFFF8
+#define RING_HEAD              0x04
+#define HEAD_WRAP_COUNT                0xFFE00000
+#define HEAD_WRAP_ONE          0x00200000
+#define HEAD_ADDR              0x001FFFFC
+#define RING_START             0x08
+#define START_ADDR             0x00FFFFF8
+#define RING_LEN               0x0C
+#define RING_NR_PAGES          0x000FF000
+#define RING_REPORT_MASK       0x00000006
+#define RING_REPORT_64K                0x00000002
+#define RING_REPORT_128K       0x00000004
+#define RING_NO_REPORT         0x00000000
+#define RING_VALID_MASK                0x00000001
+#define RING_VALID             0x00000001
+#define RING_INVALID           0x00000000
+
+#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
+#define SC_UPDATE_SCISSOR       (0x1<<1)
+#define SC_ENABLE_MASK          (0x1<<0)
+#define SC_ENABLE               (0x1<<0)
+
+#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
+#define SCI_YMIN_MASK      (0xffff<<16)
+#define SCI_XMIN_MASK      (0xffff<<0)
+#define SCI_YMAX_MASK      (0xffff<<16)
+#define SCI_XMAX_MASK      (0xffff<<0)
+
+#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
+#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
+#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x2)
+#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
+#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
+#define GFX_OP_PRIMITIVE         ((0x3<<29)|(0x1f<<24))
+
+#define CMD_OP_Z_BUFFER_INFO     ((0x0<<29)|(0x16<<23))
+#define CMD_OP_DESTBUFFER_INFO   ((0x0<<29)|(0x15<<23))
+#define CMD_OP_FRONTBUFFER_INFO  ((0x0<<29)|(0x14<<23))
+#define CMD_OP_WAIT_FOR_EVENT    ((0x0<<29)|(0x03<<23))
+
+#define BR00_BITBLT_CLIENT   0x40000000
+#define BR00_OP_COLOR_BLT    0x10000000
+#define BR00_OP_SRC_COPY_BLT 0x10C00000
+#define BR13_SOLID_PATTERN   0x80000000
+
+#define WAIT_FOR_PLANE_A_SCANLINES (1<<1)
+#define WAIT_FOR_PLANE_A_FLIP      (1<<2)
+#define WAIT_FOR_VBLANK (1<<3)
+
+#endif
diff --git a/drivers/gpu/drm/i830/Makefile b/drivers/gpu/drm/i830/Makefile
new file mode 100644 (file)
index 0000000..c642ee0
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+i830-y := i830_drv.o i830_dma.o i830_irq.o
+
+obj-$(CONFIG_DRM_I830) += i830.o
diff --git a/drivers/gpu/drm/i830/i830_dma.c b/drivers/gpu/drm/i830/i830_dma.c
new file mode 100644 (file)
index 0000000..a86ab30
--- /dev/null
@@ -0,0 +1,1553 @@
+/* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ *         Jeff Hartmann <jhartmann@valinux.com>
+ *         Keith Whitwell <keith@tungstengraphics.com>
+ *         Abraham vd Merwe <abraham@2d3d.co.za>
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i830_drm.h"
+#include "i830_drv.h"
+#include <linux/interrupt.h>   /* For task queue support */
+#include <linux/pagemap.h>
+#include <linux/delay.h>
+#include <asm/uaccess.h>
+
+#define I830_BUF_FREE          2
+#define I830_BUF_CLIENT                1
+#define I830_BUF_HARDWARE      0
+
+#define I830_BUF_UNMAPPED 0
+#define I830_BUF_MAPPED   1
+
+static struct drm_buf *i830_freelist_get(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+       int used;
+
+       /* Linear search might not be the best solution */
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+               /* In use is already a pointer */
+               used = cmpxchg(buf_priv->in_use, I830_BUF_FREE,
+                              I830_BUF_CLIENT);
+               if (used == I830_BUF_FREE) {
+                       return buf;
+               }
+       }
+       return NULL;
+}
+
+/* This should only be called if the buffer is not sent to the hardware
+ * yet, the hardware updates in use for us once its on the ring buffer.
+ */
+
+static int i830_freelist_put(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+       int used;
+
+       /* In use is already a pointer */
+       used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT, I830_BUF_FREE);
+       if (used != I830_BUF_CLIENT) {
+               DRM_ERROR("Freeing buffer thats not in use : %d\n", buf->idx);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
+{
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev;
+       drm_i830_private_t *dev_priv;
+       struct drm_buf *buf;
+       drm_i830_buf_priv_t *buf_priv;
+
+       lock_kernel();
+       dev = priv->minor->dev;
+       dev_priv = dev->dev_private;
+       buf = dev_priv->mmap_buffer;
+       buf_priv = buf->dev_private;
+
+       vma->vm_flags |= (VM_IO | VM_DONTCOPY);
+       vma->vm_file = filp;
+
+       buf_priv->currently_mapped = I830_BUF_MAPPED;
+       unlock_kernel();
+
+       if (io_remap_pfn_range(vma, vma->vm_start,
+                              vma->vm_pgoff,
+                              vma->vm_end - vma->vm_start, vma->vm_page_prot))
+               return -EAGAIN;
+       return 0;
+}
+
+static const struct file_operations i830_buffer_fops = {
+       .open = drm_open,
+       .release = drm_release,
+       .ioctl = drm_ioctl,
+       .mmap = i830_mmap_buffers,
+       .fasync = drm_fasync,
+};
+
+static int i830_map_buffer(struct drm_buf * buf, struct drm_file *file_priv)
+{
+       struct drm_device *dev = file_priv->minor->dev;
+       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       const struct file_operations *old_fops;
+       unsigned long virtual;
+       int retcode = 0;
+
+       if (buf_priv->currently_mapped == I830_BUF_MAPPED)
+               return -EINVAL;
+
+       down_write(&current->mm->mmap_sem);
+       old_fops = file_priv->filp->f_op;
+       file_priv->filp->f_op = &i830_buffer_fops;
+       dev_priv->mmap_buffer = buf;
+       virtual = do_mmap(file_priv->filp, 0, buf->total, PROT_READ | PROT_WRITE,
+                         MAP_SHARED, buf->bus_address);
+       dev_priv->mmap_buffer = NULL;
+       file_priv->filp->f_op = old_fops;
+       if (IS_ERR((void *)virtual)) {  /* ugh */
+               /* Real error */
+               DRM_ERROR("mmap error\n");
+               retcode = PTR_ERR((void *)virtual);
+               buf_priv->virtual = NULL;
+       } else {
+               buf_priv->virtual = (void __user *)virtual;
+       }
+       up_write(&current->mm->mmap_sem);
+
+       return retcode;
+}
+
+static int i830_unmap_buffer(struct drm_buf * buf)
+{
+       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+       int retcode = 0;
+
+       if (buf_priv->currently_mapped != I830_BUF_MAPPED)
+               return -EINVAL;
+
+       down_write(&current->mm->mmap_sem);
+       retcode = do_munmap(current->mm,
+                           (unsigned long)buf_priv->virtual,
+                           (size_t) buf->total);
+       up_write(&current->mm->mmap_sem);
+
+       buf_priv->currently_mapped = I830_BUF_UNMAPPED;
+       buf_priv->virtual = NULL;
+
+       return retcode;
+}
+
+static int i830_dma_get_buffer(struct drm_device * dev, drm_i830_dma_t * d,
+                              struct drm_file *file_priv)
+{
+       struct drm_buf *buf;
+       drm_i830_buf_priv_t *buf_priv;
+       int retcode = 0;
+
+       buf = i830_freelist_get(dev);
+       if (!buf) {
+               retcode = -ENOMEM;
+               DRM_DEBUG("retcode=%d\n", retcode);
+               return retcode;
+       }
+
+       retcode = i830_map_buffer(buf, file_priv);
+       if (retcode) {
+               i830_freelist_put(dev, buf);
+               DRM_ERROR("mapbuf failed, retcode %d\n", retcode);
+               return retcode;
+       }
+       buf->file_priv = file_priv;
+       buf_priv = buf->dev_private;
+       d->granted = 1;
+       d->request_idx = buf->idx;
+       d->request_size = buf->total;
+       d->virtual = buf_priv->virtual;
+
+       return retcode;
+}
+
+static int i830_dma_cleanup(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+       if (dev->dev_private) {
+               int i;
+               drm_i830_private_t *dev_priv =
+                   (drm_i830_private_t *) dev->dev_private;
+
+               if (dev_priv->ring.virtual_start) {
+                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
+               }
+               if (dev_priv->hw_status_page) {
+                       pci_free_consistent(dev->pdev, PAGE_SIZE,
+                                           dev_priv->hw_status_page,
+                                           dev_priv->dma_status_page);
+                       /* Need to rewrite hardware status page */
+                       I830_WRITE(0x02080, 0x1ffff000);
+               }
+
+               drm_free(dev->dev_private, sizeof(drm_i830_private_t),
+                        DRM_MEM_DRIVER);
+               dev->dev_private = NULL;
+
+               for (i = 0; i < dma->buf_count; i++) {
+                       struct drm_buf *buf = dma->buflist[i];
+                       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+                       if (buf_priv->kernel_virtual && buf->total)
+                               drm_core_ioremapfree(&buf_priv->map, dev);
+               }
+       }
+       return 0;
+}
+
+int i830_wait_ring(struct drm_device * dev, int n, const char *caller)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
+       int iters = 0;
+       unsigned long end;
+       unsigned int last_head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+
+       end = jiffies + (HZ * 3);
+       while (ring->space < n) {
+               ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+               ring->space = ring->head - (ring->tail + 8);
+               if (ring->space < 0)
+                       ring->space += ring->Size;
+
+               if (ring->head != last_head) {
+                       end = jiffies + (HZ * 3);
+                       last_head = ring->head;
+               }
+
+               iters++;
+               if (time_before(end, jiffies)) {
+                       DRM_ERROR("space: %d wanted %d\n", ring->space, n);
+                       DRM_ERROR("lockup\n");
+                       goto out_wait_ring;
+               }
+               udelay(1);
+               dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
+       }
+
+      out_wait_ring:
+       return iters;
+}
+
+static void i830_kernel_lost_context(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_ring_buffer_t *ring = &(dev_priv->ring);
+
+       ring->head = I830_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       ring->tail = I830_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
+       ring->space = ring->head - (ring->tail + 8);
+       if (ring->space < 0)
+               ring->space += ring->Size;
+
+       if (ring->head == ring->tail)
+               dev_priv->sarea_priv->perf_boxes |= I830_BOX_RING_EMPTY;
+}
+
+static int i830_freelist_init(struct drm_device * dev, drm_i830_private_t * dev_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int my_idx = 36;
+       u32 *hw_status = (u32 *) (dev_priv->hw_status_page + my_idx);
+       int i;
+
+       if (dma->buf_count > 1019) {
+               /* Not enough space in the status page for the freelist */
+               return -EINVAL;
+       }
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+
+               buf_priv->in_use = hw_status++;
+               buf_priv->my_use_idx = my_idx;
+               my_idx += 4;
+
+               *buf_priv->in_use = I830_BUF_FREE;
+
+               buf_priv->map.offset = buf->bus_address;
+               buf_priv->map.size = buf->total;
+               buf_priv->map.type = _DRM_AGP;
+               buf_priv->map.flags = 0;
+               buf_priv->map.mtrr = 0;
+
+               drm_core_ioremap(&buf_priv->map, dev);
+               buf_priv->kernel_virtual = buf_priv->map.handle;
+       }
+       return 0;
+}
+
+static int i830_dma_initialize(struct drm_device * dev,
+                              drm_i830_private_t * dev_priv,
+                              drm_i830_init_t * init)
+{
+       struct drm_map_list *r_list;
+
+       memset(dev_priv, 0, sizeof(drm_i830_private_t));
+
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               if (r_list->map &&
+                   r_list->map->type == _DRM_SHM &&
+                   r_list->map->flags & _DRM_CONTAINS_LOCK) {
+                       dev_priv->sarea_map = r_list->map;
+                       break;
+               }
+       }
+
+       if (!dev_priv->sarea_map) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("can not find sarea!\n");
+               return -EINVAL;
+       }
+       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
+       if (!dev_priv->mmio_map) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("can not find mmio map!\n");
+               return -EINVAL;
+       }
+       dev->agp_buffer_token = init->buffers_offset;
+       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
+       if (!dev->agp_buffer_map) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("can not find dma buffer map!\n");
+               return -EINVAL;
+       }
+
+       dev_priv->sarea_priv = (drm_i830_sarea_t *)
+           ((u8 *) dev_priv->sarea_map->handle + init->sarea_priv_offset);
+
+       dev_priv->ring.Start = init->ring_start;
+       dev_priv->ring.End = init->ring_end;
+       dev_priv->ring.Size = init->ring_size;
+
+       dev_priv->ring.map.offset = dev->agp->base + init->ring_start;
+       dev_priv->ring.map.size = init->ring_size;
+       dev_priv->ring.map.type = _DRM_AGP;
+       dev_priv->ring.map.flags = 0;
+       dev_priv->ring.map.mtrr = 0;
+
+       drm_core_ioremap(&dev_priv->ring.map, dev);
+
+       if (dev_priv->ring.map.handle == NULL) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("can not ioremap virtual address for"
+                         " ring buffer\n");
+               return -ENOMEM;
+       }
+
+       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+
+       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+
+       dev_priv->w = init->w;
+       dev_priv->h = init->h;
+       dev_priv->pitch = init->pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->front_offset = init->front_offset;
+
+       dev_priv->front_di1 = init->front_offset | init->pitch_bits;
+       dev_priv->back_di1 = init->back_offset | init->pitch_bits;
+       dev_priv->zi1 = init->depth_offset | init->pitch_bits;
+
+       DRM_DEBUG("front_di1 %x\n", dev_priv->front_di1);
+       DRM_DEBUG("back_offset %x\n", dev_priv->back_offset);
+       DRM_DEBUG("back_di1 %x\n", dev_priv->back_di1);
+       DRM_DEBUG("pitch_bits %x\n", init->pitch_bits);
+
+       dev_priv->cpp = init->cpp;
+       /* We are using separate values as placeholders for mechanisms for
+        * private backbuffer/depthbuffer usage.
+        */
+
+       dev_priv->back_pitch = init->back_pitch;
+       dev_priv->depth_pitch = init->depth_pitch;
+       dev_priv->do_boxes = 0;
+       dev_priv->use_mi_batchbuffer_start = 0;
+
+       /* Program Hardware Status Page */
+       dev_priv->hw_status_page =
+           pci_alloc_consistent(dev->pdev, PAGE_SIZE,
+                                &dev_priv->dma_status_page);
+       if (!dev_priv->hw_status_page) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("Can not allocate hardware status page\n");
+               return -ENOMEM;
+       }
+       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
+
+       I830_WRITE(0x02080, dev_priv->dma_status_page);
+       DRM_DEBUG("Enabled hardware status page\n");
+
+       /* Now we need to init our freelist */
+       if (i830_freelist_init(dev, dev_priv) != 0) {
+               dev->dev_private = (void *)dev_priv;
+               i830_dma_cleanup(dev);
+               DRM_ERROR("Not enough space in the status page for"
+                         " the freelist\n");
+               return -ENOMEM;
+       }
+       dev->dev_private = (void *)dev_priv;
+
+       return 0;
+}
+
+static int i830_dma_init(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv;
+       drm_i830_init_t *init = data;
+       int retcode = 0;
+
+       switch (init->func) {
+       case I830_INIT_DMA:
+               dev_priv = drm_alloc(sizeof(drm_i830_private_t),
+                                    DRM_MEM_DRIVER);
+               if (dev_priv == NULL)
+                       return -ENOMEM;
+               retcode = i830_dma_initialize(dev, dev_priv, init);
+               break;
+       case I830_CLEANUP_DMA:
+               retcode = i830_dma_cleanup(dev);
+               break;
+       default:
+               retcode = -EINVAL;
+               break;
+       }
+
+       return retcode;
+}
+
+#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
+#define ST1_ENABLE               (1<<16)
+#define ST1_MASK                 (0xffff)
+
+/* Most efficient way to verify state for the i830 is as it is
+ * emitted.  Non-conformant state is silently dropped.
+ */
+static void i830EmitContextVerified(struct drm_device * dev, unsigned int *code)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       int i, j = 0;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(I830_CTX_SETUP_SIZE + 4);
+
+       for (i = 0; i < I830_CTXREG_BLENDCOLR0; i++) {
+               tmp = code[i];
+               if ((tmp & (7 << 29)) == CMD_3D &&
+                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
+                       OUT_RING(tmp);
+                       j++;
+               } else {
+                       DRM_ERROR("Skipping %d\n", i);
+               }
+       }
+
+       OUT_RING(STATE3D_CONST_BLEND_COLOR_CMD);
+       OUT_RING(code[I830_CTXREG_BLENDCOLR]);
+       j += 2;
+
+       for (i = I830_CTXREG_VF; i < I830_CTXREG_MCSB0; i++) {
+               tmp = code[i];
+               if ((tmp & (7 << 29)) == CMD_3D &&
+                   (tmp & (0x1f << 24)) < (0x1d << 24)) {
+                       OUT_RING(tmp);
+                       j++;
+               } else {
+                       DRM_ERROR("Skipping %d\n", i);
+               }
+       }
+
+       OUT_RING(STATE3D_MAP_COORD_SETBIND_CMD);
+       OUT_RING(code[I830_CTXREG_MCSB1]);
+       j += 2;
+
+       if (j & 1)
+               OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+static void i830EmitTexVerified(struct drm_device * dev, unsigned int *code)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       int i, j = 0;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       if (code[I830_TEXREG_MI0] == GFX_OP_MAP_INFO ||
+           (code[I830_TEXREG_MI0] & ~(0xf * LOAD_TEXTURE_MAP0)) ==
+           (STATE3D_LOAD_STATE_IMMEDIATE_2 | 4)) {
+
+               BEGIN_LP_RING(I830_TEX_SETUP_SIZE);
+
+               OUT_RING(code[I830_TEXREG_MI0]);        /* TM0LI */
+               OUT_RING(code[I830_TEXREG_MI1]);        /* TM0S0 */
+               OUT_RING(code[I830_TEXREG_MI2]);        /* TM0S1 */
+               OUT_RING(code[I830_TEXREG_MI3]);        /* TM0S2 */
+               OUT_RING(code[I830_TEXREG_MI4]);        /* TM0S3 */
+               OUT_RING(code[I830_TEXREG_MI5]);        /* TM0S4 */
+
+               for (i = 6; i < I830_TEX_SETUP_SIZE; i++) {
+                       tmp = code[i];
+                       OUT_RING(tmp);
+                       j++;
+               }
+
+               if (j & 1)
+                       OUT_RING(0);
+
+               ADVANCE_LP_RING();
+       } else
+               printk("rejected packet %x\n", code[0]);
+}
+
+static void i830EmitTexBlendVerified(struct drm_device * dev,
+                                    unsigned int *code, unsigned int num)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       int i, j = 0;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       if (!num)
+               return;
+
+       BEGIN_LP_RING(num + 1);
+
+       for (i = 0; i < num; i++) {
+               tmp = code[i];
+               OUT_RING(tmp);
+               j++;
+       }
+
+       if (j & 1)
+               OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+static void i830EmitTexPalette(struct drm_device * dev,
+                              unsigned int *palette, int number, int is_shared)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       int i;
+       RING_LOCALS;
+
+       return;
+
+       BEGIN_LP_RING(258);
+
+       if (is_shared == 1) {
+               OUT_RING(CMD_OP_MAP_PALETTE_LOAD |
+                        MAP_PALETTE_NUM(0) | MAP_PALETTE_BOTH);
+       } else {
+               OUT_RING(CMD_OP_MAP_PALETTE_LOAD | MAP_PALETTE_NUM(number));
+       }
+       for (i = 0; i < 256; i++) {
+               OUT_RING(palette[i]);
+       }
+       OUT_RING(0);
+       /* KW:  WHERE IS THE ADVANCE_LP_RING?  This is effectively a noop!
+        */
+}
+
+/* Need to do some additional checking when setting the dest buffer.
+ */
+static void i830EmitDestVerified(struct drm_device * dev, unsigned int *code)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       unsigned int tmp;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(I830_DEST_SETUP_SIZE + 10);
+
+       tmp = code[I830_DESTREG_CBUFADDR];
+       if (tmp == dev_priv->front_di1 || tmp == dev_priv->back_di1) {
+               if (((int)outring) & 8) {
+                       OUT_RING(0);
+                       OUT_RING(0);
+               }
+
+               OUT_RING(CMD_OP_DESTBUFFER_INFO);
+               OUT_RING(BUF_3D_ID_COLOR_BACK |
+                        BUF_3D_PITCH(dev_priv->back_pitch * dev_priv->cpp) |
+                        BUF_3D_USE_FENCE);
+               OUT_RING(tmp);
+               OUT_RING(0);
+
+               OUT_RING(CMD_OP_DESTBUFFER_INFO);
+               OUT_RING(BUF_3D_ID_DEPTH | BUF_3D_USE_FENCE |
+                        BUF_3D_PITCH(dev_priv->depth_pitch * dev_priv->cpp));
+               OUT_RING(dev_priv->zi1);
+               OUT_RING(0);
+       } else {
+               DRM_ERROR("bad di1 %x (allow %x or %x)\n",
+                         tmp, dev_priv->front_di1, dev_priv->back_di1);
+       }
+
+       /* invarient:
+        */
+
+       OUT_RING(GFX_OP_DESTBUFFER_VARS);
+       OUT_RING(code[I830_DESTREG_DV1]);
+
+       OUT_RING(GFX_OP_DRAWRECT_INFO);
+       OUT_RING(code[I830_DESTREG_DR1]);
+       OUT_RING(code[I830_DESTREG_DR2]);
+       OUT_RING(code[I830_DESTREG_DR3]);
+       OUT_RING(code[I830_DESTREG_DR4]);
+
+       /* Need to verify this */
+       tmp = code[I830_DESTREG_SENABLE];
+       if ((tmp & ~0x3) == GFX_OP_SCISSOR_ENABLE) {
+               OUT_RING(tmp);
+       } else {
+               DRM_ERROR("bad scissor enable\n");
+               OUT_RING(0);
+       }
+
+       OUT_RING(GFX_OP_SCISSOR_RECT);
+       OUT_RING(code[I830_DESTREG_SR1]);
+       OUT_RING(code[I830_DESTREG_SR2]);
+       OUT_RING(0);
+
+       ADVANCE_LP_RING();
+}
+
+static void i830EmitStippleVerified(struct drm_device * dev, unsigned int *code)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       BEGIN_LP_RING(2);
+       OUT_RING(GFX_OP_STIPPLE);
+       OUT_RING(code[1]);
+       ADVANCE_LP_RING();
+}
+
+static void i830EmitState(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+
+       DRM_DEBUG("%s %x\n", __func__, dirty);
+
+       if (dirty & I830_UPLOAD_BUFFERS) {
+               i830EmitDestVerified(dev, sarea_priv->BufferState);
+               sarea_priv->dirty &= ~I830_UPLOAD_BUFFERS;
+       }
+
+       if (dirty & I830_UPLOAD_CTX) {
+               i830EmitContextVerified(dev, sarea_priv->ContextState);
+               sarea_priv->dirty &= ~I830_UPLOAD_CTX;
+       }
+
+       if (dirty & I830_UPLOAD_TEX0) {
+               i830EmitTexVerified(dev, sarea_priv->TexState[0]);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEX0;
+       }
+
+       if (dirty & I830_UPLOAD_TEX1) {
+               i830EmitTexVerified(dev, sarea_priv->TexState[1]);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEX1;
+       }
+
+       if (dirty & I830_UPLOAD_TEXBLEND0) {
+               i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[0],
+                                        sarea_priv->TexBlendStateWordsUsed[0]);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND0;
+       }
+
+       if (dirty & I830_UPLOAD_TEXBLEND1) {
+               i830EmitTexBlendVerified(dev, sarea_priv->TexBlendState[1],
+                                        sarea_priv->TexBlendStateWordsUsed[1]);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND1;
+       }
+
+       if (dirty & I830_UPLOAD_TEX_PALETTE_SHARED) {
+               i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 1);
+       } else {
+               if (dirty & I830_UPLOAD_TEX_PALETTE_N(0)) {
+                       i830EmitTexPalette(dev, sarea_priv->Palette[0], 0, 0);
+                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(0);
+               }
+               if (dirty & I830_UPLOAD_TEX_PALETTE_N(1)) {
+                       i830EmitTexPalette(dev, sarea_priv->Palette[1], 1, 0);
+                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(1);
+               }
+
+               /* 1.3:
+                */
+#if 0
+               if (dirty & I830_UPLOAD_TEX_PALETTE_N(2)) {
+                       i830EmitTexPalette(dev, sarea_priv->Palette2[0], 0, 0);
+                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2);
+               }
+               if (dirty & I830_UPLOAD_TEX_PALETTE_N(3)) {
+                       i830EmitTexPalette(dev, sarea_priv->Palette2[1], 1, 0);
+                       sarea_priv->dirty &= ~I830_UPLOAD_TEX_PALETTE_N(2);
+               }
+#endif
+       }
+
+       /* 1.3:
+        */
+       if (dirty & I830_UPLOAD_STIPPLE) {
+               i830EmitStippleVerified(dev, sarea_priv->StippleState);
+               sarea_priv->dirty &= ~I830_UPLOAD_STIPPLE;
+       }
+
+       if (dirty & I830_UPLOAD_TEX2) {
+               i830EmitTexVerified(dev, sarea_priv->TexState2);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEX2;
+       }
+
+       if (dirty & I830_UPLOAD_TEX3) {
+               i830EmitTexVerified(dev, sarea_priv->TexState3);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEX3;
+       }
+
+       if (dirty & I830_UPLOAD_TEXBLEND2) {
+               i830EmitTexBlendVerified(dev,
+                                        sarea_priv->TexBlendState2,
+                                        sarea_priv->TexBlendStateWordsUsed2);
+
+               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND2;
+       }
+
+       if (dirty & I830_UPLOAD_TEXBLEND3) {
+               i830EmitTexBlendVerified(dev,
+                                        sarea_priv->TexBlendState3,
+                                        sarea_priv->TexBlendStateWordsUsed3);
+               sarea_priv->dirty &= ~I830_UPLOAD_TEXBLEND3;
+       }
+}
+
+/* ================================================================
+ * Performance monitoring functions
+ */
+
+static void i830_fill_box(struct drm_device * dev,
+                         int x, int y, int w, int h, int r, int g, int b)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       u32 color;
+       unsigned int BR13, CMD;
+       RING_LOCALS;
+
+       BR13 = (0xF0 << 16) | (dev_priv->pitch * dev_priv->cpp) | (1 << 24);
+       CMD = XY_COLOR_BLT_CMD;
+       x += dev_priv->sarea_priv->boxes[0].x1;
+       y += dev_priv->sarea_priv->boxes[0].y1;
+
+       if (dev_priv->cpp == 4) {
+               BR13 |= (1 << 25);
+               CMD |= (XY_COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB);
+               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
+       } else {
+               color = (((r & 0xf8) << 8) |
+                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
+       }
+
+       BEGIN_LP_RING(6);
+       OUT_RING(CMD);
+       OUT_RING(BR13);
+       OUT_RING((y << 16) | x);
+       OUT_RING(((y + h) << 16) | (x + w));
+
+       if (dev_priv->current_page == 1) {
+               OUT_RING(dev_priv->front_offset);
+       } else {
+               OUT_RING(dev_priv->back_offset);
+       }
+
+       OUT_RING(color);
+       ADVANCE_LP_RING();
+}
+
+static void i830_cp_performance_boxes(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+
+       /* Purple box for page flipping
+        */
+       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_FLIP)
+               i830_fill_box(dev, 4, 4, 8, 8, 255, 0, 255);
+
+       /* Red box if we have to wait for idle at any point
+        */
+       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_WAIT)
+               i830_fill_box(dev, 16, 4, 8, 8, 255, 0, 0);
+
+       /* Blue box: lost context?
+        */
+       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_LOST_CONTEXT)
+               i830_fill_box(dev, 28, 4, 8, 8, 0, 0, 255);
+
+       /* Yellow box for texture swaps
+        */
+       if (dev_priv->sarea_priv->perf_boxes & I830_BOX_TEXTURE_LOAD)
+               i830_fill_box(dev, 40, 4, 8, 8, 255, 255, 0);
+
+       /* Green box if hardware never idles (as far as we can tell)
+        */
+       if (!(dev_priv->sarea_priv->perf_boxes & I830_BOX_RING_EMPTY))
+               i830_fill_box(dev, 64, 4, 8, 8, 0, 255, 0);
+
+       /* Draw bars indicating number of buffers allocated
+        * (not a great measure, easily confused)
+        */
+       if (dev_priv->dma_used) {
+               int bar = dev_priv->dma_used / 10240;
+               if (bar > 100)
+                       bar = 100;
+               if (bar < 1)
+                       bar = 1;
+               i830_fill_box(dev, 4, 16, bar, 4, 196, 128, 128);
+               dev_priv->dma_used = 0;
+       }
+
+       dev_priv->sarea_priv->perf_boxes = 0;
+}
+
+static void i830_dma_dispatch_clear(struct drm_device * dev, int flags,
+                                   unsigned int clear_color,
+                                   unsigned int clear_zval,
+                                   unsigned int clear_depthmask)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int pitch = dev_priv->pitch;
+       int cpp = dev_priv->cpp;
+       int i;
+       unsigned int BR13, CMD, D_CMD;
+       RING_LOCALS;
+
+       if (dev_priv->current_page == 1) {
+               unsigned int tmp = flags;
+
+               flags &= ~(I830_FRONT | I830_BACK);
+               if (tmp & I830_FRONT)
+                       flags |= I830_BACK;
+               if (tmp & I830_BACK)
+                       flags |= I830_FRONT;
+       }
+
+       i830_kernel_lost_context(dev);
+
+       switch (cpp) {
+       case 2:
+               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
+               D_CMD = CMD = XY_COLOR_BLT_CMD;
+               break;
+       case 4:
+               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24) | (1 << 25);
+               CMD = (XY_COLOR_BLT_CMD | XY_COLOR_BLT_WRITE_ALPHA |
+                      XY_COLOR_BLT_WRITE_RGB);
+               D_CMD = XY_COLOR_BLT_CMD;
+               if (clear_depthmask & 0x00ffffff)
+                       D_CMD |= XY_COLOR_BLT_WRITE_RGB;
+               if (clear_depthmask & 0xff000000)
+                       D_CMD |= XY_COLOR_BLT_WRITE_ALPHA;
+               break;
+       default:
+               BR13 = (0xF0 << 16) | (pitch * cpp) | (1 << 24);
+               D_CMD = CMD = XY_COLOR_BLT_CMD;
+               break;
+       }
+
+       if (nbox > I830_NR_SAREA_CLIPRECTS)
+               nbox = I830_NR_SAREA_CLIPRECTS;
+
+       for (i = 0; i < nbox; i++, pbox++) {
+               if (pbox->x1 > pbox->x2 ||
+                   pbox->y1 > pbox->y2 ||
+                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
+                       continue;
+
+               if (flags & I830_FRONT) {
+                       DRM_DEBUG("clear front\n");
+                       BEGIN_LP_RING(6);
+                       OUT_RING(CMD);
+                       OUT_RING(BR13);
+                       OUT_RING((pbox->y1 << 16) | pbox->x1);
+                       OUT_RING((pbox->y2 << 16) | pbox->x2);
+                       OUT_RING(dev_priv->front_offset);
+                       OUT_RING(clear_color);
+                       ADVANCE_LP_RING();
+               }
+
+               if (flags & I830_BACK) {
+                       DRM_DEBUG("clear back\n");
+                       BEGIN_LP_RING(6);
+                       OUT_RING(CMD);
+                       OUT_RING(BR13);
+                       OUT_RING((pbox->y1 << 16) | pbox->x1);
+                       OUT_RING((pbox->y2 << 16) | pbox->x2);
+                       OUT_RING(dev_priv->back_offset);
+                       OUT_RING(clear_color);
+                       ADVANCE_LP_RING();
+               }
+
+               if (flags & I830_DEPTH) {
+                       DRM_DEBUG("clear depth\n");
+                       BEGIN_LP_RING(6);
+                       OUT_RING(D_CMD);
+                       OUT_RING(BR13);
+                       OUT_RING((pbox->y1 << 16) | pbox->x1);
+                       OUT_RING((pbox->y2 << 16) | pbox->x2);
+                       OUT_RING(dev_priv->depth_offset);
+                       OUT_RING(clear_zval);
+                       ADVANCE_LP_RING();
+               }
+       }
+}
+
+static void i830_dma_dispatch_swap(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int pitch = dev_priv->pitch;
+       int cpp = dev_priv->cpp;
+       int i;
+       unsigned int CMD, BR13;
+       RING_LOCALS;
+
+       DRM_DEBUG("swapbuffers\n");
+
+       i830_kernel_lost_context(dev);
+
+       if (dev_priv->do_boxes)
+               i830_cp_performance_boxes(dev);
+
+       switch (cpp) {
+       case 2:
+               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
+               CMD = XY_SRC_COPY_BLT_CMD;
+               break;
+       case 4:
+               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24) | (1 << 25);
+               CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
+                      XY_SRC_COPY_BLT_WRITE_RGB);
+               break;
+       default:
+               BR13 = (pitch * cpp) | (0xCC << 16) | (1 << 24);
+               CMD = XY_SRC_COPY_BLT_CMD;
+               break;
+       }
+
+       if (nbox > I830_NR_SAREA_CLIPRECTS)
+               nbox = I830_NR_SAREA_CLIPRECTS;
+
+       for (i = 0; i < nbox; i++, pbox++) {
+               if (pbox->x1 > pbox->x2 ||
+                   pbox->y1 > pbox->y2 ||
+                   pbox->x2 > dev_priv->w || pbox->y2 > dev_priv->h)
+                       continue;
+
+               DRM_DEBUG("dispatch swap %d,%d-%d,%d!\n",
+                         pbox->x1, pbox->y1, pbox->x2, pbox->y2);
+
+               BEGIN_LP_RING(8);
+               OUT_RING(CMD);
+               OUT_RING(BR13);
+               OUT_RING((pbox->y1 << 16) | pbox->x1);
+               OUT_RING((pbox->y2 << 16) | pbox->x2);
+
+               if (dev_priv->current_page == 0)
+                       OUT_RING(dev_priv->front_offset);
+               else
+                       OUT_RING(dev_priv->back_offset);
+
+               OUT_RING((pbox->y1 << 16) | pbox->x1);
+               OUT_RING(BR13 & 0xffff);
+
+               if (dev_priv->current_page == 0)
+                       OUT_RING(dev_priv->back_offset);
+               else
+                       OUT_RING(dev_priv->front_offset);
+
+               ADVANCE_LP_RING();
+       }
+}
+
+static void i830_dma_dispatch_flip(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
+                 __func__,
+                 dev_priv->current_page,
+                 dev_priv->sarea_priv->pf_current_page);
+
+       i830_kernel_lost_context(dev);
+
+       if (dev_priv->do_boxes) {
+               dev_priv->sarea_priv->perf_boxes |= I830_BOX_FLIP;
+               i830_cp_performance_boxes(dev);
+       }
+
+       BEGIN_LP_RING(2);
+       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(6);
+       OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
+       OUT_RING(0);
+       if (dev_priv->current_page == 0) {
+               OUT_RING(dev_priv->back_offset);
+               dev_priv->current_page = 1;
+       } else {
+               OUT_RING(dev_priv->front_offset);
+               dev_priv->current_page = 0;
+       }
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(2);
+       OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+}
+
+static void i830_dma_dispatch_vertex(struct drm_device * dev,
+                                    struct drm_buf * buf, int discard, int used)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+       drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_clip_rect *box = sarea_priv->boxes;
+       int nbox = sarea_priv->nbox;
+       unsigned long address = (unsigned long)buf->bus_address;
+       unsigned long start = address - dev->agp->base;
+       int i = 0, u;
+       RING_LOCALS;
+
+       i830_kernel_lost_context(dev);
+
+       if (nbox > I830_NR_SAREA_CLIPRECTS)
+               nbox = I830_NR_SAREA_CLIPRECTS;
+
+       if (discard) {
+               u = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
+                           I830_BUF_HARDWARE);
+               if (u != I830_BUF_CLIENT) {
+                       DRM_DEBUG("xxxx 2\n");
+               }
+       }
+
+       if (used > 4 * 1023)
+               used = 0;
+
+       if (sarea_priv->dirty)
+               i830EmitState(dev);
+
+       DRM_DEBUG("dispatch vertex addr 0x%lx, used 0x%x nbox %d\n",
+                 address, used, nbox);
+
+       dev_priv->counter++;
+       DRM_DEBUG("dispatch counter : %ld\n", dev_priv->counter);
+       DRM_DEBUG("i830_dma_dispatch\n");
+       DRM_DEBUG("start : %lx\n", start);
+       DRM_DEBUG("used : %d\n", used);
+       DRM_DEBUG("start + used - 4 : %ld\n", start + used - 4);
+
+       if (buf_priv->currently_mapped == I830_BUF_MAPPED) {
+               u32 *vp = buf_priv->kernel_virtual;
+
+               vp[0] = (GFX_OP_PRIMITIVE |
+                        sarea_priv->vertex_prim | ((used / 4) - 2));
+
+               if (dev_priv->use_mi_batchbuffer_start) {
+                       vp[used / 4] = MI_BATCH_BUFFER_END;
+                       used += 4;
+               }
+
+               if (used & 4) {
+                       vp[used / 4] = 0;
+                       used += 4;
+               }
+
+               i830_unmap_buffer(buf);
+       }
+
+       if (used) {
+               do {
+                       if (i < nbox) {
+                               BEGIN_LP_RING(6);
+                               OUT_RING(GFX_OP_DRAWRECT_INFO);
+                               OUT_RING(sarea_priv->
+                                        BufferState[I830_DESTREG_DR1]);
+                               OUT_RING(box[i].x1 | (box[i].y1 << 16));
+                               OUT_RING(box[i].x2 | (box[i].y2 << 16));
+                               OUT_RING(sarea_priv->
+                                        BufferState[I830_DESTREG_DR4]);
+                               OUT_RING(0);
+                               ADVANCE_LP_RING();
+                       }
+
+                       if (dev_priv->use_mi_batchbuffer_start) {
+                               BEGIN_LP_RING(2);
+                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
+                               OUT_RING(start | MI_BATCH_NON_SECURE);
+                               ADVANCE_LP_RING();
+                       } else {
+                               BEGIN_LP_RING(4);
+                               OUT_RING(MI_BATCH_BUFFER);
+                               OUT_RING(start | MI_BATCH_NON_SECURE);
+                               OUT_RING(start + used - 4);
+                               OUT_RING(0);
+                               ADVANCE_LP_RING();
+                       }
+
+               } while (++i < nbox);
+       }
+
+       if (discard) {
+               dev_priv->counter++;
+
+               (void)cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
+                             I830_BUF_HARDWARE);
+
+               BEGIN_LP_RING(8);
+               OUT_RING(CMD_STORE_DWORD_IDX);
+               OUT_RING(20);
+               OUT_RING(dev_priv->counter);
+               OUT_RING(CMD_STORE_DWORD_IDX);
+               OUT_RING(buf_priv->my_use_idx);
+               OUT_RING(I830_BUF_FREE);
+               OUT_RING(CMD_REPORT_HEAD);
+               OUT_RING(0);
+               ADVANCE_LP_RING();
+       }
+}
+
+static void i830_dma_quiescent(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       i830_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(4);
+       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+       OUT_RING(CMD_REPORT_HEAD);
+       OUT_RING(0);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
+}
+
+static int i830_flush_queue(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       int i, ret = 0;
+       RING_LOCALS;
+
+       i830_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(2);
+       OUT_RING(CMD_REPORT_HEAD);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+
+               int used = cmpxchg(buf_priv->in_use, I830_BUF_HARDWARE,
+                                  I830_BUF_FREE);
+
+               if (used == I830_BUF_HARDWARE)
+                       DRM_DEBUG("reclaimed from HARDWARE\n");
+               if (used == I830_BUF_CLIENT)
+                       DRM_DEBUG("still on client\n");
+       }
+
+       return ret;
+}
+
+/* Must be called with the lock held */
+static void i830_reclaim_buffers(struct drm_device * dev, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+
+       if (!dma)
+               return;
+       if (!dev->dev_private)
+               return;
+       if (!dma->buflist)
+               return;
+
+       i830_flush_queue(dev);
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_i830_buf_priv_t *buf_priv = buf->dev_private;
+
+               if (buf->file_priv == file_priv && buf_priv) {
+                       int used = cmpxchg(buf_priv->in_use, I830_BUF_CLIENT,
+                                          I830_BUF_FREE);
+
+                       if (used == I830_BUF_CLIENT)
+                               DRM_DEBUG("reclaimed from client\n");
+                       if (buf_priv->currently_mapped == I830_BUF_MAPPED)
+                               buf_priv->currently_mapped = I830_BUF_UNMAPPED;
+               }
+       }
+}
+
+static int i830_flush_ioctl(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv)
+{
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       i830_flush_queue(dev);
+       return 0;
+}
+
+static int i830_dma_vertex(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+           dev_priv->sarea_priv;
+       drm_i830_vertex_t *vertex = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("i830 dma vertex, idx %d used %d discard %d\n",
+                 vertex->idx, vertex->used, vertex->discard);
+
+       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
+               return -EINVAL;
+
+       i830_dma_dispatch_vertex(dev,
+                                dma->buflist[vertex->idx],
+                                vertex->discard, vertex->used);
+
+       sarea_priv->last_enqueue = dev_priv->counter - 1;
+       sarea_priv->last_dispatch = (int)hw_status[5];
+
+       return 0;
+}
+
+static int i830_clear_bufs(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv)
+{
+       drm_i830_clear_t *clear = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* GH: Someone's doing nasty things... */
+       if (!dev->dev_private) {
+               return -EINVAL;
+       }
+
+       i830_dma_dispatch_clear(dev, clear->flags,
+                               clear->clear_color,
+                               clear->clear_depth, clear->clear_depthmask);
+       return 0;
+}
+
+static int i830_swap_bufs(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       DRM_DEBUG("i830_swap_bufs\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       i830_dma_dispatch_swap(dev);
+       return 0;
+}
+
+/* Not sure why this isn't set all the time:
+ */
+static void i830_do_init_pageflip(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("%s\n", __func__);
+       dev_priv->page_flipping = 1;
+       dev_priv->current_page = 0;
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+}
+
+static int i830_do_cleanup_pageflip(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("%s\n", __func__);
+       if (dev_priv->current_page != 0)
+               i830_dma_dispatch_flip(dev);
+
+       dev_priv->page_flipping = 0;
+       return 0;
+}
+
+static int i830_flip_bufs(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("%s\n", __func__);
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv->page_flipping)
+               i830_do_init_pageflip(dev);
+
+       i830_dma_dispatch_flip(dev);
+       return 0;
+}
+
+static int i830_getage(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+           dev_priv->sarea_priv;
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+       return 0;
+}
+
+static int i830_getbuf(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       int retcode = 0;
+       drm_i830_dma_t *d = data;
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i830_sarea_t *sarea_priv = (drm_i830_sarea_t *)
+           dev_priv->sarea_priv;
+
+       DRM_DEBUG("getbuf\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       d->granted = 0;
+
+       retcode = i830_dma_get_buffer(dev, d, file_priv);
+
+       DRM_DEBUG("i830_dma: %d returning %d, granted = %d\n",
+                 task_pid_nr(current), retcode, d->granted);
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+
+       return retcode;
+}
+
+static int i830_copybuf(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       /* Never copy - 2.4.x doesn't need it */
+       return 0;
+}
+
+static int i830_docopy(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       return 0;
+}
+
+static int i830_getparam(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_getparam_t *param = data;
+       int value;
+
+       if (!dev_priv) {
+               DRM_ERROR("%s called with no initialization\n", __func__);
+               return -EINVAL;
+       }
+
+       switch (param->param) {
+       case I830_PARAM_IRQ_ACTIVE:
+               value = dev->irq_enabled;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (copy_to_user(param->value, &value, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int i830_setparam(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_setparam_t *param = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("%s called with no initialization\n", __func__);
+               return -EINVAL;
+       }
+
+       switch (param->param) {
+       case I830_SETPARAM_USE_MI_BATCHBUFFER_START:
+               dev_priv->use_mi_batchbuffer_start = param->value;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+int i830_driver_load(struct drm_device *dev, unsigned long flags)
+{
+       /* i830 has 4 more counters */
+       dev->counters += 4;
+       dev->types[6] = _DRM_STAT_IRQ;
+       dev->types[7] = _DRM_STAT_PRIMARY;
+       dev->types[8] = _DRM_STAT_SECONDARY;
+       dev->types[9] = _DRM_STAT_DMA;
+
+       return 0;
+}
+
+void i830_driver_lastclose(struct drm_device * dev)
+{
+       i830_dma_cleanup(dev);
+}
+
+void i830_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
+{
+       if (dev->dev_private) {
+               drm_i830_private_t *dev_priv = dev->dev_private;
+               if (dev_priv->page_flipping) {
+                       i830_do_cleanup_pageflip(dev);
+               }
+       }
+}
+
+void i830_driver_reclaim_buffers_locked(struct drm_device * dev, struct drm_file *file_priv)
+{
+       i830_reclaim_buffers(dev, file_priv);
+}
+
+int i830_driver_dma_quiescent(struct drm_device * dev)
+{
+       i830_dma_quiescent(dev);
+       return 0;
+}
+
+struct drm_ioctl_desc i830_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_I830_INIT, i830_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I830_VERTEX, i830_dma_vertex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_CLEAR, i830_clear_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_FLUSH, i830_flush_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_GETAGE, i830_getage, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_GETBUF, i830_getbuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_SWAP, i830_swap_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_COPY, i830_copybuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_DOCOPY, i830_docopy, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_FLIP, i830_flip_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_IRQ_EMIT, i830_irq_emit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_IRQ_WAIT, i830_irq_wait, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_GETPARAM, i830_getparam, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I830_SETPARAM, i830_setparam, DRM_AUTH)
+};
+
+int i830_max_ioctl = DRM_ARRAY_SIZE(i830_ioctls);
+
+/**
+ * Determine if the device really is AGP or not.
+ *
+ * All Intel graphics chipsets are treated as AGP, even if they are really
+ * PCI-e.
+ *
+ * \param dev   The device to be tested.
+ *
+ * \returns
+ * A value of 1 is always retured to indictate every i8xx is AGP.
+ */
+int i830_driver_device_is_agp(struct drm_device * dev)
+{
+       return 1;
+}
diff --git a/drivers/gpu/drm/i830/i830_drv.c b/drivers/gpu/drm/i830/i830_drv.c
new file mode 100644 (file)
index 0000000..389597e
--- /dev/null
@@ -0,0 +1,108 @@
+/* i830_drv.c -- I810 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Jeff Hartmann <jhartmann@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ *    Abraham vd Merwe <abraham@2d3d.co.za>
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i830_drm.h"
+#include "i830_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       i830_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
+           DRIVER_HAVE_DMA | DRIVER_DMA_QUEUE,
+#if USE_IRQS
+       .driver_features |= DRIVER_HAVE_IRQ | DRIVER_SHARED_IRQ,
+#endif
+       .dev_priv_size = sizeof(drm_i830_buf_priv_t),
+       .load = i830_driver_load,
+       .lastclose = i830_driver_lastclose,
+       .preclose = i830_driver_preclose,
+       .device_is_agp = i830_driver_device_is_agp,
+       .reclaim_buffers_locked = i830_driver_reclaim_buffers_locked,
+       .dma_quiescent = i830_driver_dma_quiescent,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+#if USE_IRQS
+       .irq_preinstall = i830_driver_irq_preinstall,
+       .irq_postinstall = i830_driver_irq_postinstall,
+       .irq_uninstall = i830_driver_irq_uninstall,
+       .irq_handler = i830_driver_irq_handler,
+#endif
+       .ioctls = i830_ioctls,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init i830_init(void)
+{
+       driver.num_ioctls = i830_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit i830_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(i830_init);
+module_exit(i830_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
new file mode 100644 (file)
index 0000000..b5bf8cc
--- /dev/null
@@ -0,0 +1,292 @@
+/* i830_drv.h -- Private header for the I830 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
+ *         Jeff Hartmann <jhartmann@valinux.com>
+ *
+ */
+
+#ifndef _I830_DRV_H_
+#define _I830_DRV_H_
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "VA Linux Systems Inc."
+
+#define DRIVER_NAME            "i830"
+#define DRIVER_DESC            "Intel 830M"
+#define DRIVER_DATE            "20021108"
+
+/* Interface history:
+ *
+ * 1.1: Original.
+ * 1.2: ?
+ * 1.3: New irq emit/wait ioctls.
+ *      New pageflip ioctl.
+ *      New getparam ioctl.
+ *      State for texunits 3&4 in sarea.
+ *      New (alternative) layout for texture state.
+ */
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           3
+#define DRIVER_PATCHLEVEL      2
+
+/* Driver will work either way: IRQ's save cpu time when waiting for
+ * the card, but are subject to subtle interactions between bios,
+ * hardware and the driver.
+ */
+/* XXX: Add vblank support? */
+#define USE_IRQS 0
+
+typedef struct drm_i830_buf_priv {
+       u32 *in_use;
+       int my_use_idx;
+       int currently_mapped;
+       void __user *virtual;
+       void *kernel_virtual;
+       drm_local_map_t map;
+} drm_i830_buf_priv_t;
+
+typedef struct _drm_i830_ring_buffer {
+       int tail_mask;
+       unsigned long Start;
+       unsigned long End;
+       unsigned long Size;
+       u8 *virtual_start;
+       int head;
+       int tail;
+       int space;
+       drm_local_map_t map;
+} drm_i830_ring_buffer_t;
+
+typedef struct drm_i830_private {
+       struct drm_map *sarea_map;
+       struct drm_map *mmio_map;
+
+       drm_i830_sarea_t *sarea_priv;
+       drm_i830_ring_buffer_t ring;
+
+       void *hw_status_page;
+       unsigned long counter;
+
+       dma_addr_t dma_status_page;
+
+       struct drm_buf *mmap_buffer;
+
+       u32 front_di1, back_di1, zi1;
+
+       int back_offset;
+       int depth_offset;
+       int front_offset;
+       int w, h;
+       int pitch;
+       int back_pitch;
+       int depth_pitch;
+       unsigned int cpp;
+
+       int do_boxes;
+       int dma_used;
+
+       int current_page;
+       int page_flipping;
+
+       wait_queue_head_t irq_queue;
+       atomic_t irq_received;
+       atomic_t irq_emitted;
+
+       int use_mi_batchbuffer_start;
+
+} drm_i830_private_t;
+
+extern struct drm_ioctl_desc i830_ioctls[];
+extern int i830_max_ioctl;
+
+/* i830_irq.c */
+extern int i830_irq_emit(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int i830_irq_wait(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+
+extern irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS);
+extern void i830_driver_irq_preinstall(struct drm_device * dev);
+extern void i830_driver_irq_postinstall(struct drm_device * dev);
+extern void i830_driver_irq_uninstall(struct drm_device * dev);
+extern int i830_driver_load(struct drm_device *, unsigned long flags);
+extern void i830_driver_preclose(struct drm_device * dev,
+                                struct drm_file *file_priv);
+extern void i830_driver_lastclose(struct drm_device * dev);
+extern void i830_driver_reclaim_buffers_locked(struct drm_device * dev,
+                                              struct drm_file *file_priv);
+extern int i830_driver_dma_quiescent(struct drm_device * dev);
+extern int i830_driver_device_is_agp(struct drm_device * dev);
+
+#define I830_READ(reg)          DRM_READ32(dev_priv->mmio_map, reg)
+#define I830_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, reg, val)
+#define I830_READ16(reg)        DRM_READ16(dev_priv->mmio_map, reg)
+#define I830_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, reg, val)
+
+#define I830_VERBOSE 0
+
+#define RING_LOCALS    unsigned int outring, ringmask, outcount; \
+                        volatile char *virt;
+
+#define BEGIN_LP_RING(n) do {                          \
+       if (I830_VERBOSE)                               \
+               printk("BEGIN_LP_RING(%d)\n", (n));     \
+       if (dev_priv->ring.space < n*4)                 \
+               i830_wait_ring(dev, n*4, __func__);             \
+       outcount = 0;                                   \
+       outring = dev_priv->ring.tail;                  \
+       ringmask = dev_priv->ring.tail_mask;            \
+       virt = dev_priv->ring.virtual_start;            \
+} while (0)
+
+#define OUT_RING(n) do {                                       \
+       if (I830_VERBOSE) printk("   OUT_RING %x\n", (int)(n)); \
+       *(volatile unsigned int *)(virt + outring) = n;         \
+        outcount++;                                            \
+       outring += 4;                                           \
+       outring &= ringmask;                                    \
+} while (0)
+
+#define ADVANCE_LP_RING() do {                                         \
+       if (I830_VERBOSE) printk("ADVANCE_LP_RING %x\n", outring);      \
+       dev_priv->ring.tail = outring;                                  \
+       dev_priv->ring.space -= outcount * 4;                           \
+       I830_WRITE(LP_RING + RING_TAIL, outring);                       \
+} while(0)
+
+extern int i830_wait_ring(struct drm_device * dev, int n, const char *caller);
+
+#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
+#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
+#define CMD_REPORT_HEAD                        (7<<23)
+#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
+#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
+
+#define STATE3D_LOAD_STATE_IMMEDIATE_2      ((0x3<<29)|(0x1d<<24)|(0x03<<16))
+#define LOAD_TEXTURE_MAP0                   (1<<11)
+
+#define INST_PARSER_CLIENT   0x00000000
+#define INST_OP_FLUSH        0x02000000
+#define INST_FLUSH_MAP_CACHE 0x00000001
+
+#define BB1_START_ADDR_MASK   (~0x7)
+#define BB1_PROTECTED         (1<<0)
+#define BB1_UNPROTECTED       (0<<0)
+#define BB2_END_ADDR_MASK     (~0x7)
+
+#define I830REG_HWSTAM         0x02098
+#define I830REG_INT_IDENTITY_R 0x020a4
+#define I830REG_INT_MASK_R     0x020a8
+#define I830REG_INT_ENABLE_R   0x020a0
+
+#define I830_IRQ_RESERVED ((1<<13)|(3<<2))
+
+#define LP_RING                        0x2030
+#define HP_RING                        0x2040
+#define RING_TAIL              0x00
+#define TAIL_ADDR              0x001FFFF8
+#define RING_HEAD              0x04
+#define HEAD_WRAP_COUNT                0xFFE00000
+#define HEAD_WRAP_ONE          0x00200000
+#define HEAD_ADDR              0x001FFFFC
+#define RING_START             0x08
+#define START_ADDR             0x0xFFFFF000
+#define RING_LEN               0x0C
+#define RING_NR_PAGES          0x001FF000
+#define RING_REPORT_MASK       0x00000006
+#define RING_REPORT_64K                0x00000002
+#define RING_REPORT_128K       0x00000004
+#define RING_NO_REPORT         0x00000000
+#define RING_VALID_MASK                0x00000001
+#define RING_VALID             0x00000001
+#define RING_INVALID           0x00000000
+
+#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
+#define SC_UPDATE_SCISSOR       (0x1<<1)
+#define SC_ENABLE_MASK          (0x1<<0)
+#define SC_ENABLE               (0x1<<0)
+
+#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
+#define SCI_YMIN_MASK      (0xffff<<16)
+#define SCI_XMIN_MASK      (0xffff<<0)
+#define SCI_YMAX_MASK      (0xffff<<16)
+#define SCI_XMAX_MASK      (0xffff<<0)
+
+#define GFX_OP_SCISSOR_ENABLE   ((0x3<<29)|(0x1c<<24)|(0x10<<19))
+#define GFX_OP_SCISSOR_RECT     ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
+#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
+#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
+#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
+#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
+#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
+#define GFX_OP_PRIMITIVE         ((0x3<<29)|(0x1f<<24))
+
+#define CMD_OP_DESTBUFFER_INFO  ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
+
+#define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
+#define ASYNC_FLIP                (1<<22)
+
+#define CMD_3D                          (0x3<<29)
+#define STATE3D_CONST_BLEND_COLOR_CMD   (CMD_3D|(0x1d<<24)|(0x88<<16))
+#define STATE3D_MAP_COORD_SETBIND_CMD   (CMD_3D|(0x1d<<24)|(0x02<<16))
+
+#define BR00_BITBLT_CLIENT   0x40000000
+#define BR00_OP_COLOR_BLT    0x10000000
+#define BR00_OP_SRC_COPY_BLT 0x10C00000
+#define BR13_SOLID_PATTERN   0x80000000
+
+#define BUF_3D_ID_COLOR_BACK    (0x3<<24)
+#define BUF_3D_ID_DEPTH         (0x7<<24)
+#define BUF_3D_USE_FENCE        (1<<23)
+#define BUF_3D_PITCH(x)         (((x)/4)<<2)
+
+#define CMD_OP_MAP_PALETTE_LOAD        ((3<<29)|(0x1d<<24)|(0x82<<16)|255)
+#define MAP_PALETTE_NUM(x)     ((x<<8) & (1<<8))
+#define MAP_PALETTE_BOTH       (1<<11)
+
+#define XY_COLOR_BLT_CMD               ((2<<29)|(0x50<<22)|0x4)
+#define XY_COLOR_BLT_WRITE_ALPHA       (1<<21)
+#define XY_COLOR_BLT_WRITE_RGB         (1<<20)
+
+#define XY_SRC_COPY_BLT_CMD             ((2<<29)|(0x53<<22)|6)
+#define XY_SRC_COPY_BLT_WRITE_ALPHA     (1<<21)
+#define XY_SRC_COPY_BLT_WRITE_RGB       (1<<20)
+
+#define MI_BATCH_BUFFER                ((0x30<<23)|1)
+#define MI_BATCH_BUFFER_START  (0x31<<23)
+#define MI_BATCH_BUFFER_END    (0xA<<23)
+#define MI_BATCH_NON_SECURE    (1)
+
+#define MI_WAIT_FOR_EVENT       ((0x3<<23))
+#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
+#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
+
+#define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
+
+#endif
diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
new file mode 100644 (file)
index 0000000..91ec2bb
--- /dev/null
@@ -0,0 +1,186 @@
+/* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
+ *
+ * Copyright 2002 Tungsten Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Keith Whitwell <keith@tungstengraphics.com>
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i830_drm.h"
+#include "i830_drv.h"
+#include <linux/interrupt.h>   /* For task queue support */
+#include <linux/delay.h>
+
+irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       u16 temp;
+
+       temp = I830_READ16(I830REG_INT_IDENTITY_R);
+       DRM_DEBUG("%x\n", temp);
+
+       if (!(temp & 2))
+               return IRQ_NONE;
+
+       I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
+
+       atomic_inc(&dev_priv->irq_received);
+       wake_up_interruptible(&dev_priv->irq_queue);
+
+       return IRQ_HANDLED;
+}
+
+static int i830_emit_irq(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       DRM_DEBUG("%s\n", __func__);
+
+       atomic_inc(&dev_priv->irq_emitted);
+
+       BEGIN_LP_RING(2);
+       OUT_RING(0);
+       OUT_RING(GFX_OP_USER_INTERRUPT);
+       ADVANCE_LP_RING();
+
+       return atomic_read(&dev_priv->irq_emitted);
+}
+
+static int i830_wait_irq(struct drm_device * dev, int irq_nr)
+{
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       DECLARE_WAITQUEUE(entry, current);
+       unsigned long end = jiffies + HZ * 3;
+       int ret = 0;
+
+       DRM_DEBUG("%s\n", __func__);
+
+       if (atomic_read(&dev_priv->irq_received) >= irq_nr)
+               return 0;
+
+       dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
+
+       add_wait_queue(&dev_priv->irq_queue, &entry);
+
+       for (;;) {
+               __set_current_state(TASK_INTERRUPTIBLE);
+               if (atomic_read(&dev_priv->irq_received) >= irq_nr)
+                       break;
+               if ((signed)(end - jiffies) <= 0) {
+                       DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
+                                 I830_READ16(I830REG_INT_IDENTITY_R),
+                                 I830_READ16(I830REG_INT_MASK_R),
+                                 I830_READ16(I830REG_INT_ENABLE_R),
+                                 I830_READ16(I830REG_HWSTAM));
+
+                       ret = -EBUSY;   /* Lockup?  Missed irq? */
+                       break;
+               }
+               schedule_timeout(HZ * 3);
+               if (signal_pending(current)) {
+                       ret = -EINTR;
+                       break;
+               }
+       }
+
+       __set_current_state(TASK_RUNNING);
+       remove_wait_queue(&dev_priv->irq_queue, &entry);
+       return ret;
+}
+
+/* Needs the lock as it touches the ring.
+ */
+int i830_irq_emit(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_irq_emit_t *emit = data;
+       int result;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("%s called with no initialization\n", __func__);
+               return -EINVAL;
+       }
+
+       result = i830_emit_irq(dev);
+
+       if (copy_to_user(emit->irq_seq, &result, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+/* Doesn't need the hardware lock.
+ */
+int i830_irq_wait(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_i830_private_t *dev_priv = dev->dev_private;
+       drm_i830_irq_wait_t *irqwait = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("%s called with no initialization\n", __func__);
+               return -EINVAL;
+       }
+
+       return i830_wait_irq(dev, irqwait->irq_seq);
+}
+
+/* drm_dma.h hooks
+*/
+void i830_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+
+       I830_WRITE16(I830REG_HWSTAM, 0xffff);
+       I830_WRITE16(I830REG_INT_MASK_R, 0x0);
+       I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
+       atomic_set(&dev_priv->irq_received, 0);
+       atomic_set(&dev_priv->irq_emitted, 0);
+       init_waitqueue_head(&dev_priv->irq_queue);
+}
+
+void i830_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+
+       I830_WRITE16(I830REG_INT_ENABLE_R, 0x2);
+}
+
+void i830_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_i830_private_t *dev_priv = (drm_i830_private_t *) dev->dev_private;
+       if (!dev_priv)
+               return;
+
+       I830_WRITE16(I830REG_INT_MASK_R, 0xffff);
+       I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
+}
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
new file mode 100644 (file)
index 0000000..a9e6046
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+i915-y := i915_drv.o i915_dma.o i915_irq.o i915_mem.o
+
+i915-$(CONFIG_COMPAT)   += i915_ioc32.o
+
+obj-$(CONFIG_DRM_I915)  += i915.o
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
new file mode 100644 (file)
index 0000000..8897434
--- /dev/null
@@ -0,0 +1,858 @@
+/* i915_dma.c -- DMA support for the I915 -*- linux-c -*-
+ */
+/*
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+/* Really want an OS-independent resettable timer.  Would like to have
+ * this loop run for (eg) 3 sec, but have the timer reset every time
+ * the head pointer changes, so that EBUSY only happens if the ring
+ * actually stalls for (eg) 3 seconds.
+ */
+int i915_wait_ring(struct drm_device * dev, int n, const char *caller)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
+       u32 last_head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       int i;
+
+       for (i = 0; i < 10000; i++) {
+               ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+               ring->space = ring->head - (ring->tail + 8);
+               if (ring->space < 0)
+                       ring->space += ring->Size;
+               if (ring->space >= n)
+                       return 0;
+
+               dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
+
+               if (ring->head != last_head)
+                       i = 0;
+
+               last_head = ring->head;
+       }
+
+       return -EBUSY;
+}
+
+void i915_kernel_lost_context(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_ring_buffer_t *ring = &(dev_priv->ring);
+
+       ring->head = I915_READ(LP_RING + RING_HEAD) & HEAD_ADDR;
+       ring->tail = I915_READ(LP_RING + RING_TAIL) & TAIL_ADDR;
+       ring->space = ring->head - (ring->tail + 8);
+       if (ring->space < 0)
+               ring->space += ring->Size;
+
+       if (ring->head == ring->tail)
+               dev_priv->sarea_priv->perf_boxes |= I915_BOX_RING_EMPTY;
+}
+
+static int i915_dma_cleanup(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (dev->irq)
+               drm_irq_uninstall(dev);
+
+       if (dev_priv->ring.virtual_start) {
+               drm_core_ioremapfree(&dev_priv->ring.map, dev);
+               dev_priv->ring.virtual_start = 0;
+               dev_priv->ring.map.handle = 0;
+               dev_priv->ring.map.size = 0;
+       }
+
+       if (dev_priv->status_page_dmah) {
+               drm_pci_free(dev, dev_priv->status_page_dmah);
+               dev_priv->status_page_dmah = NULL;
+               /* Need to rewrite hardware status page */
+               I915_WRITE(0x02080, 0x1ffff000);
+       }
+
+       if (dev_priv->status_gfx_addr) {
+               dev_priv->status_gfx_addr = 0;
+               drm_core_ioremapfree(&dev_priv->hws_map, dev);
+               I915_WRITE(0x2080, 0x1ffff000);
+       }
+
+       return 0;
+}
+
+static int i915_initialize(struct drm_device * dev, drm_i915_init_t * init)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("can not find sarea!\n");
+               i915_dma_cleanup(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->mmio_map = drm_core_findmap(dev, init->mmio_offset);
+       if (!dev_priv->mmio_map) {
+               i915_dma_cleanup(dev);
+               DRM_ERROR("can not find mmio map!\n");
+               return -EINVAL;
+       }
+
+       dev_priv->sarea_priv = (drm_i915_sarea_t *)
+           ((u8 *) dev_priv->sarea->handle + init->sarea_priv_offset);
+
+       dev_priv->ring.Start = init->ring_start;
+       dev_priv->ring.End = init->ring_end;
+       dev_priv->ring.Size = init->ring_size;
+       dev_priv->ring.tail_mask = dev_priv->ring.Size - 1;
+
+       dev_priv->ring.map.offset = init->ring_start;
+       dev_priv->ring.map.size = init->ring_size;
+       dev_priv->ring.map.type = 0;
+       dev_priv->ring.map.flags = 0;
+       dev_priv->ring.map.mtrr = 0;
+
+       drm_core_ioremap(&dev_priv->ring.map, dev);
+
+       if (dev_priv->ring.map.handle == NULL) {
+               i915_dma_cleanup(dev);
+               DRM_ERROR("can not ioremap virtual address for"
+                         " ring buffer\n");
+               return -ENOMEM;
+       }
+
+       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+
+       dev_priv->cpp = init->cpp;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->front_offset = init->front_offset;
+       dev_priv->current_page = 0;
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+
+       /* We are using separate values as placeholders for mechanisms for
+        * private backbuffer/depthbuffer usage.
+        */
+       dev_priv->use_mi_batchbuffer_start = 0;
+       if (IS_I965G(dev)) /* 965 doesn't support older method */
+               dev_priv->use_mi_batchbuffer_start = 1;
+
+       /* Allow hardware batchbuffers unless told otherwise.
+        */
+       dev_priv->allow_batchbuffer = 1;
+
+       /* Program Hardware Status Page */
+       if (!I915_NEED_GFX_HWS(dev)) {
+               dev_priv->status_page_dmah =
+                       drm_pci_alloc(dev, PAGE_SIZE, PAGE_SIZE, 0xffffffff);
+
+               if (!dev_priv->status_page_dmah) {
+                       i915_dma_cleanup(dev);
+                       DRM_ERROR("Can not allocate hardware status page\n");
+                       return -ENOMEM;
+               }
+               dev_priv->hw_status_page = dev_priv->status_page_dmah->vaddr;
+               dev_priv->dma_status_page = dev_priv->status_page_dmah->busaddr;
+
+               memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+               I915_WRITE(0x02080, dev_priv->dma_status_page);
+       }
+       DRM_DEBUG("Enabled hardware status page\n");
+       return 0;
+}
+
+static int i915_dma_resume(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+
+       DRM_DEBUG("%s\n", __func__);
+
+       if (!dev_priv->sarea) {
+               DRM_ERROR("can not find sarea!\n");
+               return -EINVAL;
+       }
+
+       if (!dev_priv->mmio_map) {
+               DRM_ERROR("can not find mmio map!\n");
+               return -EINVAL;
+       }
+
+       if (dev_priv->ring.map.handle == NULL) {
+               DRM_ERROR("can not ioremap virtual address for"
+                         " ring buffer\n");
+               return -ENOMEM;
+       }
+
+       /* Program Hardware Status Page */
+       if (!dev_priv->hw_status_page) {
+               DRM_ERROR("Can not find hardware status page\n");
+               return -EINVAL;
+       }
+       DRM_DEBUG("hw status page @ %p\n", dev_priv->hw_status_page);
+
+       if (dev_priv->status_gfx_addr != 0)
+               I915_WRITE(0x02080, dev_priv->status_gfx_addr);
+       else
+               I915_WRITE(0x02080, dev_priv->dma_status_page);
+       DRM_DEBUG("Enabled hardware status page\n");
+
+       return 0;
+}
+
+static int i915_dma_init(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_init_t *init = data;
+       int retcode = 0;
+
+       switch (init->func) {
+       case I915_INIT_DMA:
+               retcode = i915_initialize(dev, init);
+               break;
+       case I915_CLEANUP_DMA:
+               retcode = i915_dma_cleanup(dev);
+               break;
+       case I915_RESUME_DMA:
+               retcode = i915_dma_resume(dev);
+               break;
+       default:
+               retcode = -EINVAL;
+               break;
+       }
+
+       return retcode;
+}
+
+/* Implement basically the same security restrictions as hardware does
+ * for MI_BATCH_NON_SECURE.  These can be made stricter at any time.
+ *
+ * Most of the calculations below involve calculating the size of a
+ * particular instruction.  It's important to get the size right as
+ * that tells us where the next instruction to check is.  Any illegal
+ * instruction detected will be given a size of zero, which is a
+ * signal to abort the rest of the buffer.
+ */
+static int do_validate_cmd(int cmd)
+{
+       switch (((cmd >> 29) & 0x7)) {
+       case 0x0:
+               switch ((cmd >> 23) & 0x3f) {
+               case 0x0:
+                       return 1;       /* MI_NOOP */
+               case 0x4:
+                       return 1;       /* MI_FLUSH */
+               default:
+                       return 0;       /* disallow everything else */
+               }
+               break;
+       case 0x1:
+               return 0;       /* reserved */
+       case 0x2:
+               return (cmd & 0xff) + 2;        /* 2d commands */
+       case 0x3:
+               if (((cmd >> 24) & 0x1f) <= 0x18)
+                       return 1;
+
+               switch ((cmd >> 24) & 0x1f) {
+               case 0x1c:
+                       return 1;
+               case 0x1d:
+                       switch ((cmd >> 16) & 0xff) {
+                       case 0x3:
+                               return (cmd & 0x1f) + 2;
+                       case 0x4:
+                               return (cmd & 0xf) + 2;
+                       default:
+                               return (cmd & 0xffff) + 2;
+                       }
+               case 0x1e:
+                       if (cmd & (1 << 23))
+                               return (cmd & 0xffff) + 1;
+                       else
+                               return 1;
+               case 0x1f:
+                       if ((cmd & (1 << 23)) == 0)     /* inline vertices */
+                               return (cmd & 0x1ffff) + 2;
+                       else if (cmd & (1 << 17))       /* indirect random */
+                               if ((cmd & 0xffff) == 0)
+                                       return 0;       /* unknown length, too hard */
+                               else
+                                       return (((cmd & 0xffff) + 1) / 2) + 1;
+                       else
+                               return 2;       /* indirect sequential */
+               default:
+                       return 0;
+               }
+       default:
+               return 0;
+       }
+
+       return 0;
+}
+
+static int validate_cmd(int cmd)
+{
+       int ret = do_validate_cmd(cmd);
+
+/*     printk("validate_cmd( %x ): %d\n", cmd, ret); */
+
+       return ret;
+}
+
+static int i915_emit_cmds(struct drm_device * dev, int __user * buffer, int dwords)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       int i;
+       RING_LOCALS;
+
+       if ((dwords+1) * sizeof(int) >= dev_priv->ring.Size - 8)
+               return -EINVAL;
+
+       BEGIN_LP_RING((dwords+1)&~1);
+
+       for (i = 0; i < dwords;) {
+               int cmd, sz;
+
+               if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i], sizeof(cmd)))
+                       return -EINVAL;
+
+               if ((sz = validate_cmd(cmd)) == 0 || i + sz > dwords)
+                       return -EINVAL;
+
+               OUT_RING(cmd);
+
+               while (++i, --sz) {
+                       if (DRM_COPY_FROM_USER_UNCHECKED(&cmd, &buffer[i],
+                                                        sizeof(cmd))) {
+                               return -EINVAL;
+                       }
+                       OUT_RING(cmd);
+               }
+       }
+
+       if (dwords & 1)
+               OUT_RING(0);
+
+       ADVANCE_LP_RING();
+
+       return 0;
+}
+
+static int i915_emit_box(struct drm_device * dev,
+                        struct drm_clip_rect __user * boxes,
+                        int i, int DR1, int DR4)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       struct drm_clip_rect box;
+       RING_LOCALS;
+
+       if (DRM_COPY_FROM_USER_UNCHECKED(&box, &boxes[i], sizeof(box))) {
+               return -EFAULT;
+       }
+
+       if (box.y2 <= box.y1 || box.x2 <= box.x1 || box.y2 <= 0 || box.x2 <= 0) {
+               DRM_ERROR("Bad box %d,%d..%d,%d\n",
+                         box.x1, box.y1, box.x2, box.y2);
+               return -EINVAL;
+       }
+
+       if (IS_I965G(dev)) {
+               BEGIN_LP_RING(4);
+               OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
+               OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
+               OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
+               OUT_RING(DR4);
+               ADVANCE_LP_RING();
+       } else {
+               BEGIN_LP_RING(6);
+               OUT_RING(GFX_OP_DRAWRECT_INFO);
+               OUT_RING(DR1);
+               OUT_RING((box.x1 & 0xffff) | (box.y1 << 16));
+               OUT_RING(((box.x2 - 1) & 0xffff) | ((box.y2 - 1) << 16));
+               OUT_RING(DR4);
+               OUT_RING(0);
+               ADVANCE_LP_RING();
+       }
+
+       return 0;
+}
+
+/* XXX: Emitting the counter should really be moved to part of the IRQ
+ * emit. For now, do it in both places:
+ */
+
+static void i915_emit_breadcrumb(struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
+
+       if (dev_priv->counter > 0x7FFFFFFFUL)
+               dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
+
+       BEGIN_LP_RING(4);
+       OUT_RING(CMD_STORE_DWORD_IDX);
+       OUT_RING(20);
+       OUT_RING(dev_priv->counter);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+}
+
+static int i915_dispatch_cmdbuffer(struct drm_device * dev,
+                                  drm_i915_cmdbuffer_t * cmd)
+{
+       int nbox = cmd->num_cliprects;
+       int i = 0, count, ret;
+
+       if (cmd->sz & 0x3) {
+               DRM_ERROR("alignment");
+               return -EINVAL;
+       }
+
+       i915_kernel_lost_context(dev);
+
+       count = nbox ? nbox : 1;
+
+       for (i = 0; i < count; i++) {
+               if (i < nbox) {
+                       ret = i915_emit_box(dev, cmd->cliprects, i,
+                                           cmd->DR1, cmd->DR4);
+                       if (ret)
+                               return ret;
+               }
+
+               ret = i915_emit_cmds(dev, (int __user *)cmd->buf, cmd->sz / 4);
+               if (ret)
+                       return ret;
+       }
+
+       i915_emit_breadcrumb(dev);
+       return 0;
+}
+
+static int i915_dispatch_batchbuffer(struct drm_device * dev,
+                                    drm_i915_batchbuffer_t * batch)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       struct drm_clip_rect __user *boxes = batch->cliprects;
+       int nbox = batch->num_cliprects;
+       int i = 0, count;
+       RING_LOCALS;
+
+       if ((batch->start | batch->used) & 0x7) {
+               DRM_ERROR("alignment");
+               return -EINVAL;
+       }
+
+       i915_kernel_lost_context(dev);
+
+       count = nbox ? nbox : 1;
+
+       for (i = 0; i < count; i++) {
+               if (i < nbox) {
+                       int ret = i915_emit_box(dev, boxes, i,
+                                               batch->DR1, batch->DR4);
+                       if (ret)
+                               return ret;
+               }
+
+               if (dev_priv->use_mi_batchbuffer_start) {
+                       BEGIN_LP_RING(2);
+                       if (IS_I965G(dev)) {
+                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6) | MI_BATCH_NON_SECURE_I965);
+                               OUT_RING(batch->start);
+                       } else {
+                               OUT_RING(MI_BATCH_BUFFER_START | (2 << 6));
+                               OUT_RING(batch->start | MI_BATCH_NON_SECURE);
+                       }
+                       ADVANCE_LP_RING();
+               } else {
+                       BEGIN_LP_RING(4);
+                       OUT_RING(MI_BATCH_BUFFER);
+                       OUT_RING(batch->start | MI_BATCH_NON_SECURE);
+                       OUT_RING(batch->start + batch->used - 4);
+                       OUT_RING(0);
+                       ADVANCE_LP_RING();
+               }
+       }
+
+       i915_emit_breadcrumb(dev);
+
+       return 0;
+}
+
+static int i915_dispatch_flip(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
+                 __FUNCTION__,
+                 dev_priv->current_page,
+                 dev_priv->sarea_priv->pf_current_page);
+
+       i915_kernel_lost_context(dev);
+
+       BEGIN_LP_RING(2);
+       OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(6);
+       OUT_RING(CMD_OP_DISPLAYBUFFER_INFO | ASYNC_FLIP);
+       OUT_RING(0);
+       if (dev_priv->current_page == 0) {
+               OUT_RING(dev_priv->back_offset);
+               dev_priv->current_page = 1;
+       } else {
+               OUT_RING(dev_priv->front_offset);
+               dev_priv->current_page = 0;
+       }
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       BEGIN_LP_RING(2);
+       OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PLANE_A_FLIP);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
+
+       BEGIN_LP_RING(4);
+       OUT_RING(CMD_STORE_DWORD_IDX);
+       OUT_RING(20);
+       OUT_RING(dev_priv->counter);
+       OUT_RING(0);
+       ADVANCE_LP_RING();
+
+       dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
+       return 0;
+}
+
+static int i915_quiescent(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+
+       i915_kernel_lost_context(dev);
+       return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
+}
+
+static int i915_flush_ioctl(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv)
+{
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return i915_quiescent(dev);
+}
+
+static int i915_batchbuffer(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
+           dev_priv->sarea_priv;
+       drm_i915_batchbuffer_t *batch = data;
+       int ret;
+
+       if (!dev_priv->allow_batchbuffer) {
+               DRM_ERROR("Batchbuffer ioctl disabled\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("i915 batchbuffer, start %x used %d cliprects %d\n",
+                 batch->start, batch->used, batch->num_cliprects);
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (batch->num_cliprects && DRM_VERIFYAREA_READ(batch->cliprects,
+                                                      batch->num_cliprects *
+                                                      sizeof(struct drm_clip_rect)))
+               return -EFAULT;
+
+       ret = i915_dispatch_batchbuffer(dev, batch);
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+       return ret;
+}
+
+static int i915_cmdbuffer(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       u32 *hw_status = dev_priv->hw_status_page;
+       drm_i915_sarea_t *sarea_priv = (drm_i915_sarea_t *)
+           dev_priv->sarea_priv;
+       drm_i915_cmdbuffer_t *cmdbuf = data;
+       int ret;
+
+       DRM_DEBUG("i915 cmdbuffer, buf %p sz %d cliprects %d\n",
+                 cmdbuf->buf, cmdbuf->sz, cmdbuf->num_cliprects);
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (cmdbuf->num_cliprects &&
+           DRM_VERIFYAREA_READ(cmdbuf->cliprects,
+                               cmdbuf->num_cliprects *
+                               sizeof(struct drm_clip_rect))) {
+               DRM_ERROR("Fault accessing cliprects\n");
+               return -EFAULT;
+       }
+
+       ret = i915_dispatch_cmdbuffer(dev, cmdbuf);
+       if (ret) {
+               DRM_ERROR("i915_dispatch_cmdbuffer failed\n");
+               return ret;
+       }
+
+       sarea_priv->last_dispatch = (int)hw_status[5];
+       return 0;
+}
+
+static int i915_flip_bufs(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv)
+{
+       DRM_DEBUG("%s\n", __FUNCTION__);
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return i915_dispatch_flip(dev);
+}
+
+static int i915_getparam(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_getparam_t *param = data;
+       int value;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       switch (param->param) {
+       case I915_PARAM_IRQ_ACTIVE:
+               value = dev->irq ? 1 : 0;
+               break;
+       case I915_PARAM_ALLOW_BATCHBUFFER:
+               value = dev_priv->allow_batchbuffer ? 1 : 0;
+               break;
+       case I915_PARAM_LAST_DISPATCH:
+               value = READ_BREADCRUMB(dev_priv);
+               break;
+       default:
+               DRM_ERROR("Unknown parameter %d\n", param->param);
+               return -EINVAL;
+       }
+
+       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
+               DRM_ERROR("DRM_COPY_TO_USER failed\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int i915_setparam(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_setparam_t *param = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       switch (param->param) {
+       case I915_SETPARAM_USE_MI_BATCHBUFFER_START:
+               if (!IS_I965G(dev))
+                       dev_priv->use_mi_batchbuffer_start = param->value;
+               break;
+       case I915_SETPARAM_TEX_LRU_LOG_GRANULARITY:
+               dev_priv->tex_lru_log_granularity = param->value;
+               break;
+       case I915_SETPARAM_ALLOW_BATCHBUFFER:
+               dev_priv->allow_batchbuffer = param->value;
+               break;
+       default:
+               DRM_ERROR("unknown parameter %d\n", param->param);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int i915_set_status_page(struct drm_device *dev, void *data,
+                               struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_hws_addr_t *hws = data;
+
+       if (!I915_NEED_GFX_HWS(dev))
+               return -EINVAL;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       printk(KERN_DEBUG "set status page addr 0x%08x\n", (u32)hws->addr);
+
+       dev_priv->status_gfx_addr = hws->addr & (0x1ffff<<12);
+
+       dev_priv->hws_map.offset = dev->agp->base + hws->addr;
+       dev_priv->hws_map.size = 4*1024;
+       dev_priv->hws_map.type = 0;
+       dev_priv->hws_map.flags = 0;
+       dev_priv->hws_map.mtrr = 0;
+
+       drm_core_ioremap(&dev_priv->hws_map, dev);
+       if (dev_priv->hws_map.handle == NULL) {
+               i915_dma_cleanup(dev);
+               dev_priv->status_gfx_addr = 0;
+               DRM_ERROR("can not ioremap virtual address for"
+                               " G33 hw status page\n");
+               return -ENOMEM;
+       }
+       dev_priv->hw_status_page = dev_priv->hws_map.handle;
+
+       memset(dev_priv->hw_status_page, 0, PAGE_SIZE);
+       I915_WRITE(0x02080, dev_priv->status_gfx_addr);
+       DRM_DEBUG("load hws 0x2080 with gfx mem 0x%x\n",
+                       dev_priv->status_gfx_addr);
+       DRM_DEBUG("load hws at %p\n", dev_priv->hw_status_page);
+       return 0;
+}
+
+int i915_driver_load(struct drm_device *dev, unsigned long flags)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       unsigned long base, size;
+       int ret = 0, mmio_bar = IS_I9XX(dev) ? 0 : 1;
+
+       /* i915 has 4 more counters */
+       dev->counters += 4;
+       dev->types[6] = _DRM_STAT_IRQ;
+       dev->types[7] = _DRM_STAT_PRIMARY;
+       dev->types[8] = _DRM_STAT_SECONDARY;
+       dev->types[9] = _DRM_STAT_DMA;
+
+       dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv, 0, sizeof(drm_i915_private_t));
+
+       dev->dev_private = (void *)dev_priv;
+
+       /* Add register map (needed for suspend/resume) */
+       base = drm_get_resource_start(dev, mmio_bar);
+       size = drm_get_resource_len(dev, mmio_bar);
+
+       ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
+                        _DRM_KERNEL | _DRM_DRIVER,
+                        &dev_priv->mmio_map);
+       return ret;
+}
+
+int i915_driver_unload(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+
+       if (dev_priv->mmio_map)
+               drm_rmmap(dev, dev_priv->mmio_map);
+
+       drm_free(dev->dev_private, sizeof(drm_i915_private_t),
+                DRM_MEM_DRIVER);
+
+       return 0;
+}
+
+void i915_driver_lastclose(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+
+       if (!dev_priv)
+               return;
+
+       if (dev_priv->agp_heap)
+               i915_mem_takedown(&(dev_priv->agp_heap));
+
+       i915_dma_cleanup(dev);
+}
+
+void i915_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       i915_mem_release(dev, file_priv, dev_priv->agp_heap);
+}
+
+struct drm_ioctl_desc i915_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_I915_INIT, i915_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I915_FLUSH, i915_flush_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_FLIP, i915_flip_bufs, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_BATCHBUFFER, i915_batchbuffer, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_IRQ_EMIT, i915_irq_emit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_IRQ_WAIT, i915_irq_wait, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_GETPARAM, i915_getparam, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_SETPARAM, i915_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I915_ALLOC, i915_mem_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_FREE, i915_mem_free, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_INIT_HEAP, i915_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_I915_CMDBUFFER, i915_cmdbuffer, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_DESTROY_HEAP,  i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
+       DRM_IOCTL_DEF(DRM_I915_SET_VBLANK_PIPE,  i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY ),
+       DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE,  i915_vblank_pipe_get, DRM_AUTH ),
+       DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH),
+};
+
+int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
+
+/**
+ * Determine if the device really is AGP or not.
+ *
+ * All Intel graphics chipsets are treated as AGP, even if they are really
+ * PCI-e.
+ *
+ * \param dev   The device to be tested.
+ *
+ * \returns
+ * A value of 1 is always retured to indictate every i9x5 is AGP.
+ */
+int i915_driver_device_is_agp(struct drm_device * dev)
+{
+       return 1;
+}
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
new file mode 100644 (file)
index 0000000..93aed1c
--- /dev/null
@@ -0,0 +1,605 @@
+/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
+ */
+/*
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       i915_PCI_IDS
+};
+
+enum pipe {
+    PIPE_A = 0,
+    PIPE_B,
+};
+
+static bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+
+       if (pipe == PIPE_A)
+               return (I915_READ(DPLL_A) & DPLL_VCO_ENABLE);
+       else
+               return (I915_READ(DPLL_B) & DPLL_VCO_ENABLE);
+}
+
+static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
+       u32 *array;
+       int i;
+
+       if (!i915_pipe_enabled(dev, pipe))
+               return;
+
+       if (pipe == PIPE_A)
+               array = dev_priv->save_palette_a;
+       else
+               array = dev_priv->save_palette_b;
+
+       for(i = 0; i < 256; i++)
+               array[i] = I915_READ(reg + (i << 2));
+}
+
+static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
+       u32 *array;
+       int i;
+
+       if (!i915_pipe_enabled(dev, pipe))
+               return;
+
+       if (pipe == PIPE_A)
+               array = dev_priv->save_palette_a;
+       else
+               array = dev_priv->save_palette_b;
+
+       for(i = 0; i < 256; i++)
+               I915_WRITE(reg + (i << 2), array[i]);
+}
+
+static u8 i915_read_indexed(u16 index_port, u16 data_port, u8 reg)
+{
+       outb(reg, index_port);
+       return inb(data_port);
+}
+
+static u8 i915_read_ar(u16 st01, u8 reg, u16 palette_enable)
+{
+       inb(st01);
+       outb(palette_enable | reg, VGA_AR_INDEX);
+       return inb(VGA_AR_DATA_READ);
+}
+
+static void i915_write_ar(u8 st01, u8 reg, u8 val, u16 palette_enable)
+{
+       inb(st01);
+       outb(palette_enable | reg, VGA_AR_INDEX);
+       outb(val, VGA_AR_DATA_WRITE);
+}
+
+static void i915_write_indexed(u16 index_port, u16 data_port, u8 reg, u8 val)
+{
+       outb(reg, index_port);
+       outb(val, data_port);
+}
+
+static void i915_save_vga(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int i;
+       u16 cr_index, cr_data, st01;
+
+       /* VGA color palette registers */
+       dev_priv->saveDACMASK = inb(VGA_DACMASK);
+       /* DACCRX automatically increments during read */
+       outb(0, VGA_DACRX);
+       /* Read 3 bytes of color data from each index */
+       for (i = 0; i < 256 * 3; i++)
+               dev_priv->saveDACDATA[i] = inb(VGA_DACDATA);
+
+       /* MSR bits */
+       dev_priv->saveMSR = inb(VGA_MSR_READ);
+       if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
+               cr_index = VGA_CR_INDEX_CGA;
+               cr_data = VGA_CR_DATA_CGA;
+               st01 = VGA_ST01_CGA;
+       } else {
+               cr_index = VGA_CR_INDEX_MDA;
+               cr_data = VGA_CR_DATA_MDA;
+               st01 = VGA_ST01_MDA;
+       }
+
+       /* CRT controller regs */
+       i915_write_indexed(cr_index, cr_data, 0x11,
+                          i915_read_indexed(cr_index, cr_data, 0x11) &
+                          (~0x80));
+       for (i = 0; i <= 0x24; i++)
+               dev_priv->saveCR[i] =
+                       i915_read_indexed(cr_index, cr_data, i);
+       /* Make sure we don't turn off CR group 0 writes */
+       dev_priv->saveCR[0x11] &= ~0x80;
+
+       /* Attribute controller registers */
+       inb(st01);
+       dev_priv->saveAR_INDEX = inb(VGA_AR_INDEX);
+       for (i = 0; i <= 0x14; i++)
+               dev_priv->saveAR[i] = i915_read_ar(st01, i, 0);
+       inb(st01);
+       outb(dev_priv->saveAR_INDEX, VGA_AR_INDEX);
+       inb(st01);
+
+       /* Graphics controller registers */
+       for (i = 0; i < 9; i++)
+               dev_priv->saveGR[i] =
+                       i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, i);
+
+       dev_priv->saveGR[0x10] =
+               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10);
+       dev_priv->saveGR[0x11] =
+               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11);
+       dev_priv->saveGR[0x18] =
+               i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18);
+
+       /* Sequencer registers */
+       for (i = 0; i < 8; i++)
+               dev_priv->saveSR[i] =
+                       i915_read_indexed(VGA_SR_INDEX, VGA_SR_DATA, i);
+}
+
+static void i915_restore_vga(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int i;
+       u16 cr_index, cr_data, st01;
+
+       /* MSR bits */
+       outb(dev_priv->saveMSR, VGA_MSR_WRITE);
+       if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
+               cr_index = VGA_CR_INDEX_CGA;
+               cr_data = VGA_CR_DATA_CGA;
+               st01 = VGA_ST01_CGA;
+       } else {
+               cr_index = VGA_CR_INDEX_MDA;
+               cr_data = VGA_CR_DATA_MDA;
+               st01 = VGA_ST01_MDA;
+       }
+
+       /* Sequencer registers, don't write SR07 */
+       for (i = 0; i < 7; i++)
+               i915_write_indexed(VGA_SR_INDEX, VGA_SR_DATA, i,
+                                  dev_priv->saveSR[i]);
+
+       /* CRT controller regs */
+       /* Enable CR group 0 writes */
+       i915_write_indexed(cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
+       for (i = 0; i <= 0x24; i++)
+               i915_write_indexed(cr_index, cr_data, i, dev_priv->saveCR[i]);
+
+       /* Graphics controller regs */
+       for (i = 0; i < 9; i++)
+               i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, i,
+                                  dev_priv->saveGR[i]);
+
+       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10,
+                          dev_priv->saveGR[0x10]);
+       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11,
+                          dev_priv->saveGR[0x11]);
+       i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18,
+                          dev_priv->saveGR[0x18]);
+
+       /* Attribute controller registers */
+       inb(st01);
+       for (i = 0; i <= 0x14; i++)
+               i915_write_ar(st01, i, dev_priv->saveAR[i], 0);
+       inb(st01); /* switch back to index mode */
+       outb(dev_priv->saveAR_INDEX | 0x20, VGA_AR_INDEX);
+       inb(st01);
+
+       /* VGA color palette registers */
+       outb(dev_priv->saveDACMASK, VGA_DACMASK);
+       /* DACCRX automatically increments during read */
+       outb(0, VGA_DACWX);
+       /* Read 3 bytes of color data from each index */
+       for (i = 0; i < 256 * 3; i++)
+               outb(dev_priv->saveDACDATA[i], VGA_DACDATA);
+
+}
+
+static int i915_suspend(struct drm_device *dev, pm_message_t state)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int i;
+
+       if (!dev || !dev_priv) {
+               printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv);
+               printk(KERN_ERR "DRM not initialized, aborting suspend.\n");
+               return -ENODEV;
+       }
+
+       if (state.event == PM_EVENT_PRETHAW)
+               return 0;
+
+       pci_save_state(dev->pdev);
+       pci_read_config_byte(dev->pdev, LBB, &dev_priv->saveLBB);
+
+       /* Display arbitration control */
+       dev_priv->saveDSPARB = I915_READ(DSPARB);
+
+       /* Pipe & plane A info */
+       dev_priv->savePIPEACONF = I915_READ(PIPEACONF);
+       dev_priv->savePIPEASRC = I915_READ(PIPEASRC);
+       dev_priv->saveFPA0 = I915_READ(FPA0);
+       dev_priv->saveFPA1 = I915_READ(FPA1);
+       dev_priv->saveDPLL_A = I915_READ(DPLL_A);
+       if (IS_I965G(dev))
+               dev_priv->saveDPLL_A_MD = I915_READ(DPLL_A_MD);
+       dev_priv->saveHTOTAL_A = I915_READ(HTOTAL_A);
+       dev_priv->saveHBLANK_A = I915_READ(HBLANK_A);
+       dev_priv->saveHSYNC_A = I915_READ(HSYNC_A);
+       dev_priv->saveVTOTAL_A = I915_READ(VTOTAL_A);
+       dev_priv->saveVBLANK_A = I915_READ(VBLANK_A);
+       dev_priv->saveVSYNC_A = I915_READ(VSYNC_A);
+       dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
+
+       dev_priv->saveDSPACNTR = I915_READ(DSPACNTR);
+       dev_priv->saveDSPASTRIDE = I915_READ(DSPASTRIDE);
+       dev_priv->saveDSPASIZE = I915_READ(DSPASIZE);
+       dev_priv->saveDSPAPOS = I915_READ(DSPAPOS);
+       dev_priv->saveDSPABASE = I915_READ(DSPABASE);
+       if (IS_I965G(dev)) {
+               dev_priv->saveDSPASURF = I915_READ(DSPASURF);
+               dev_priv->saveDSPATILEOFF = I915_READ(DSPATILEOFF);
+       }
+       i915_save_palette(dev, PIPE_A);
+       dev_priv->savePIPEASTAT = I915_READ(I915REG_PIPEASTAT);
+
+       /* Pipe & plane B info */
+       dev_priv->savePIPEBCONF = I915_READ(PIPEBCONF);
+       dev_priv->savePIPEBSRC = I915_READ(PIPEBSRC);
+       dev_priv->saveFPB0 = I915_READ(FPB0);
+       dev_priv->saveFPB1 = I915_READ(FPB1);
+       dev_priv->saveDPLL_B = I915_READ(DPLL_B);
+       if (IS_I965G(dev))
+               dev_priv->saveDPLL_B_MD = I915_READ(DPLL_B_MD);
+       dev_priv->saveHTOTAL_B = I915_READ(HTOTAL_B);
+       dev_priv->saveHBLANK_B = I915_READ(HBLANK_B);
+       dev_priv->saveHSYNC_B = I915_READ(HSYNC_B);
+       dev_priv->saveVTOTAL_B = I915_READ(VTOTAL_B);
+       dev_priv->saveVBLANK_B = I915_READ(VBLANK_B);
+       dev_priv->saveVSYNC_B = I915_READ(VSYNC_B);
+       dev_priv->saveBCLRPAT_A = I915_READ(BCLRPAT_A);
+
+       dev_priv->saveDSPBCNTR = I915_READ(DSPBCNTR);
+       dev_priv->saveDSPBSTRIDE = I915_READ(DSPBSTRIDE);
+       dev_priv->saveDSPBSIZE = I915_READ(DSPBSIZE);
+       dev_priv->saveDSPBPOS = I915_READ(DSPBPOS);
+       dev_priv->saveDSPBBASE = I915_READ(DSPBBASE);
+       if (IS_I965GM(dev) || IS_IGD_GM(dev)) {
+               dev_priv->saveDSPBSURF = I915_READ(DSPBSURF);
+               dev_priv->saveDSPBTILEOFF = I915_READ(DSPBTILEOFF);
+       }
+       i915_save_palette(dev, PIPE_B);
+       dev_priv->savePIPEBSTAT = I915_READ(I915REG_PIPEBSTAT);
+
+       /* CRT state */
+       dev_priv->saveADPA = I915_READ(ADPA);
+
+       /* LVDS state */
+       dev_priv->savePP_CONTROL = I915_READ(PP_CONTROL);
+       dev_priv->savePFIT_PGM_RATIOS = I915_READ(PFIT_PGM_RATIOS);
+       dev_priv->saveBLC_PWM_CTL = I915_READ(BLC_PWM_CTL);
+       if (IS_I965G(dev))
+               dev_priv->saveBLC_PWM_CTL2 = I915_READ(BLC_PWM_CTL2);
+       if (IS_MOBILE(dev) && !IS_I830(dev))
+               dev_priv->saveLVDS = I915_READ(LVDS);
+       if (!IS_I830(dev) && !IS_845G(dev))
+               dev_priv->savePFIT_CONTROL = I915_READ(PFIT_CONTROL);
+       dev_priv->saveLVDSPP_ON = I915_READ(LVDSPP_ON);
+       dev_priv->saveLVDSPP_OFF = I915_READ(LVDSPP_OFF);
+       dev_priv->savePP_CYCLE = I915_READ(PP_CYCLE);
+
+       /* FIXME: save TV & SDVO state */
+
+       /* FBC state */
+       dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE);
+       dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE);
+       dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2);
+       dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL);
+
+       /* Interrupt state */
+       dev_priv->saveIIR = I915_READ(I915REG_INT_IDENTITY_R);
+       dev_priv->saveIER = I915_READ(I915REG_INT_ENABLE_R);
+       dev_priv->saveIMR = I915_READ(I915REG_INT_MASK_R);
+
+       /* VGA state */
+       dev_priv->saveVCLK_DIVISOR_VGA0 = I915_READ(VCLK_DIVISOR_VGA0);
+       dev_priv->saveVCLK_DIVISOR_VGA1 = I915_READ(VCLK_DIVISOR_VGA1);
+       dev_priv->saveVCLK_POST_DIV = I915_READ(VCLK_POST_DIV);
+       dev_priv->saveVGACNTRL = I915_READ(VGACNTRL);
+
+       /* Clock gating state */
+       dev_priv->saveD_STATE = I915_READ(D_STATE);
+       dev_priv->saveDSPCLK_GATE_D = I915_READ(DSPCLK_GATE_D);
+
+       /* Cache mode state */
+       dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0);
+
+       /* Memory Arbitration state */
+       dev_priv->saveMI_ARB_STATE = I915_READ(MI_ARB_STATE);
+
+       /* Scratch space */
+       for (i = 0; i < 16; i++) {
+               dev_priv->saveSWF0[i] = I915_READ(SWF0 + (i << 2));
+               dev_priv->saveSWF1[i] = I915_READ(SWF10 + (i << 2));
+       }
+       for (i = 0; i < 3; i++)
+               dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
+
+       i915_save_vga(dev);
+
+       if (state.event == PM_EVENT_SUSPEND) {
+               /* Shut down the device */
+               pci_disable_device(dev->pdev);
+               pci_set_power_state(dev->pdev, PCI_D3hot);
+       }
+
+       return 0;
+}
+
+static int i915_resume(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int i;
+
+       pci_set_power_state(dev->pdev, PCI_D0);
+       pci_restore_state(dev->pdev);
+       if (pci_enable_device(dev->pdev))
+               return -1;
+       pci_set_master(dev->pdev);
+
+       pci_write_config_byte(dev->pdev, LBB, dev_priv->saveLBB);
+
+       I915_WRITE(DSPARB, dev_priv->saveDSPARB);
+
+       /* Pipe & plane A info */
+       /* Prime the clock */
+       if (dev_priv->saveDPLL_A & DPLL_VCO_ENABLE) {
+               I915_WRITE(DPLL_A, dev_priv->saveDPLL_A &
+                          ~DPLL_VCO_ENABLE);
+               udelay(150);
+       }
+       I915_WRITE(FPA0, dev_priv->saveFPA0);
+       I915_WRITE(FPA1, dev_priv->saveFPA1);
+       /* Actually enable it */
+       I915_WRITE(DPLL_A, dev_priv->saveDPLL_A);
+       udelay(150);
+       if (IS_I965G(dev))
+               I915_WRITE(DPLL_A_MD, dev_priv->saveDPLL_A_MD);
+       udelay(150);
+
+       /* Restore mode */
+       I915_WRITE(HTOTAL_A, dev_priv->saveHTOTAL_A);
+       I915_WRITE(HBLANK_A, dev_priv->saveHBLANK_A);
+       I915_WRITE(HSYNC_A, dev_priv->saveHSYNC_A);
+       I915_WRITE(VTOTAL_A, dev_priv->saveVTOTAL_A);
+       I915_WRITE(VBLANK_A, dev_priv->saveVBLANK_A);
+       I915_WRITE(VSYNC_A, dev_priv->saveVSYNC_A);
+       I915_WRITE(BCLRPAT_A, dev_priv->saveBCLRPAT_A);
+
+       /* Restore plane info */
+       I915_WRITE(DSPASIZE, dev_priv->saveDSPASIZE);
+       I915_WRITE(DSPAPOS, dev_priv->saveDSPAPOS);
+       I915_WRITE(PIPEASRC, dev_priv->savePIPEASRC);
+       I915_WRITE(DSPABASE, dev_priv->saveDSPABASE);
+       I915_WRITE(DSPASTRIDE, dev_priv->saveDSPASTRIDE);
+       if (IS_I965G(dev)) {
+               I915_WRITE(DSPASURF, dev_priv->saveDSPASURF);
+               I915_WRITE(DSPATILEOFF, dev_priv->saveDSPATILEOFF);
+       }
+
+       I915_WRITE(PIPEACONF, dev_priv->savePIPEACONF);
+
+       i915_restore_palette(dev, PIPE_A);
+       /* Enable the plane */
+       I915_WRITE(DSPACNTR, dev_priv->saveDSPACNTR);
+       I915_WRITE(DSPABASE, I915_READ(DSPABASE));
+
+       /* Pipe & plane B info */
+       if (dev_priv->saveDPLL_B & DPLL_VCO_ENABLE) {
+               I915_WRITE(DPLL_B, dev_priv->saveDPLL_B &
+                          ~DPLL_VCO_ENABLE);
+               udelay(150);
+       }
+       I915_WRITE(FPB0, dev_priv->saveFPB0);
+       I915_WRITE(FPB1, dev_priv->saveFPB1);
+       /* Actually enable it */
+       I915_WRITE(DPLL_B, dev_priv->saveDPLL_B);
+       udelay(150);
+       if (IS_I965G(dev))
+               I915_WRITE(DPLL_B_MD, dev_priv->saveDPLL_B_MD);
+       udelay(150);
+
+       /* Restore mode */
+       I915_WRITE(HTOTAL_B, dev_priv->saveHTOTAL_B);
+       I915_WRITE(HBLANK_B, dev_priv->saveHBLANK_B);
+       I915_WRITE(HSYNC_B, dev_priv->saveHSYNC_B);
+       I915_WRITE(VTOTAL_B, dev_priv->saveVTOTAL_B);
+       I915_WRITE(VBLANK_B, dev_priv->saveVBLANK_B);
+       I915_WRITE(VSYNC_B, dev_priv->saveVSYNC_B);
+       I915_WRITE(BCLRPAT_B, dev_priv->saveBCLRPAT_B);
+
+       /* Restore plane info */
+       I915_WRITE(DSPBSIZE, dev_priv->saveDSPBSIZE);
+       I915_WRITE(DSPBPOS, dev_priv->saveDSPBPOS);
+       I915_WRITE(PIPEBSRC, dev_priv->savePIPEBSRC);
+       I915_WRITE(DSPBBASE, dev_priv->saveDSPBBASE);
+       I915_WRITE(DSPBSTRIDE, dev_priv->saveDSPBSTRIDE);
+       if (IS_I965G(dev)) {
+               I915_WRITE(DSPBSURF, dev_priv->saveDSPBSURF);
+               I915_WRITE(DSPBTILEOFF, dev_priv->saveDSPBTILEOFF);
+       }
+
+       I915_WRITE(PIPEBCONF, dev_priv->savePIPEBCONF);
+
+       i915_restore_palette(dev, PIPE_B);
+       /* Enable the plane */
+       I915_WRITE(DSPBCNTR, dev_priv->saveDSPBCNTR);
+       I915_WRITE(DSPBBASE, I915_READ(DSPBBASE));
+
+       /* CRT state */
+       I915_WRITE(ADPA, dev_priv->saveADPA);
+
+       /* LVDS state */
+       if (IS_I965G(dev))
+               I915_WRITE(BLC_PWM_CTL2, dev_priv->saveBLC_PWM_CTL2);
+       if (IS_MOBILE(dev) && !IS_I830(dev))
+               I915_WRITE(LVDS, dev_priv->saveLVDS);
+       if (!IS_I830(dev) && !IS_845G(dev))
+               I915_WRITE(PFIT_CONTROL, dev_priv->savePFIT_CONTROL);
+
+       I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS);
+       I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL);
+       I915_WRITE(LVDSPP_ON, dev_priv->saveLVDSPP_ON);
+       I915_WRITE(LVDSPP_OFF, dev_priv->saveLVDSPP_OFF);
+       I915_WRITE(PP_CYCLE, dev_priv->savePP_CYCLE);
+       I915_WRITE(PP_CONTROL, dev_priv->savePP_CONTROL);
+
+       /* FIXME: restore TV & SDVO state */
+
+       /* FBC info */
+       I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE);
+       I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE);
+       I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2);
+       I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL);
+
+       /* VGA state */
+       I915_WRITE(VGACNTRL, dev_priv->saveVGACNTRL);
+       I915_WRITE(VCLK_DIVISOR_VGA0, dev_priv->saveVCLK_DIVISOR_VGA0);
+       I915_WRITE(VCLK_DIVISOR_VGA1, dev_priv->saveVCLK_DIVISOR_VGA1);
+       I915_WRITE(VCLK_POST_DIV, dev_priv->saveVCLK_POST_DIV);
+       udelay(150);
+
+       /* Clock gating state */
+       I915_WRITE (D_STATE, dev_priv->saveD_STATE);
+       I915_WRITE (DSPCLK_GATE_D, dev_priv->saveDSPCLK_GATE_D);
+
+       /* Cache mode state */
+       I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000);
+
+       /* Memory arbitration state */
+       I915_WRITE (MI_ARB_STATE, dev_priv->saveMI_ARB_STATE | 0xffff0000);
+
+       for (i = 0; i < 16; i++) {
+               I915_WRITE(SWF0 + (i << 2), dev_priv->saveSWF0[i]);
+               I915_WRITE(SWF10 + (i << 2), dev_priv->saveSWF1[i+7]);
+       }
+       for (i = 0; i < 3; i++)
+               I915_WRITE(SWF30 + (i << 2), dev_priv->saveSWF2[i]);
+
+       i915_restore_vga(dev);
+
+       return 0;
+}
+
+static struct drm_driver driver = {
+       /* don't use mtrr's here, the Xserver or user space app should
+        * deal with them for intel hardware.
+        */
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
+           DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL |
+           DRIVER_IRQ_VBL2,
+       .load = i915_driver_load,
+       .unload = i915_driver_unload,
+       .lastclose = i915_driver_lastclose,
+       .preclose = i915_driver_preclose,
+       .suspend = i915_suspend,
+       .resume = i915_resume,
+       .device_is_agp = i915_driver_device_is_agp,
+       .vblank_wait = i915_driver_vblank_wait,
+       .vblank_wait2 = i915_driver_vblank_wait2,
+       .irq_preinstall = i915_driver_irq_preinstall,
+       .irq_postinstall = i915_driver_irq_postinstall,
+       .irq_uninstall = i915_driver_irq_uninstall,
+       .irq_handler = i915_driver_irq_handler,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = i915_ioctls,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+                .compat_ioctl = i915_compat_ioctl,
+#endif
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init i915_init(void)
+{
+       driver.num_ioctls = i915_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit i915_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(i915_init);
+module_exit(i915_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
new file mode 100644 (file)
index 0000000..d7326d9
--- /dev/null
@@ -0,0 +1,1142 @@
+/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
+ */
+/*
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _I915_DRV_H_
+#define _I915_DRV_H_
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "Tungsten Graphics, Inc."
+
+#define DRIVER_NAME            "i915"
+#define DRIVER_DESC            "Intel Graphics"
+#define DRIVER_DATE            "20060119"
+
+/* Interface history:
+ *
+ * 1.1: Original.
+ * 1.2: Add Power Management
+ * 1.3: Add vblank support
+ * 1.4: Fix cmdbuffer path, add heap destroy
+ * 1.5: Add vblank pipe configuration
+ * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
+ *      - Support vertical blank on secondary display pipe
+ */
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           6
+#define DRIVER_PATCHLEVEL      0
+
+typedef struct _drm_i915_ring_buffer {
+       int tail_mask;
+       unsigned long Start;
+       unsigned long End;
+       unsigned long Size;
+       u8 *virtual_start;
+       int head;
+       int tail;
+       int space;
+       drm_local_map_t map;
+} drm_i915_ring_buffer_t;
+
+struct mem_block {
+       struct mem_block *next;
+       struct mem_block *prev;
+       int start;
+       int size;
+       struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
+};
+
+typedef struct _drm_i915_vbl_swap {
+       struct list_head head;
+       drm_drawable_t drw_id;
+       unsigned int pipe;
+       unsigned int sequence;
+} drm_i915_vbl_swap_t;
+
+typedef struct drm_i915_private {
+       drm_local_map_t *sarea;
+       drm_local_map_t *mmio_map;
+
+       drm_i915_sarea_t *sarea_priv;
+       drm_i915_ring_buffer_t ring;
+
+       drm_dma_handle_t *status_page_dmah;
+       void *hw_status_page;
+       dma_addr_t dma_status_page;
+       unsigned long counter;
+       unsigned int status_gfx_addr;
+       drm_local_map_t hws_map;
+
+       unsigned int cpp;
+       int back_offset;
+       int front_offset;
+       int current_page;
+       int page_flipping;
+       int use_mi_batchbuffer_start;
+
+       wait_queue_head_t irq_queue;
+       atomic_t irq_received;
+       atomic_t irq_emitted;
+
+       int tex_lru_log_granularity;
+       int allow_batchbuffer;
+       struct mem_block *agp_heap;
+       unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
+       int vblank_pipe;
+
+       spinlock_t swaps_lock;
+       drm_i915_vbl_swap_t vbl_swaps;
+       unsigned int swaps_pending;
+
+       /* Register state */
+       u8 saveLBB;
+       u32 saveDSPACNTR;
+       u32 saveDSPBCNTR;
+       u32 saveDSPARB;
+       u32 savePIPEACONF;
+       u32 savePIPEBCONF;
+       u32 savePIPEASRC;
+       u32 savePIPEBSRC;
+       u32 saveFPA0;
+       u32 saveFPA1;
+       u32 saveDPLL_A;
+       u32 saveDPLL_A_MD;
+       u32 saveHTOTAL_A;
+       u32 saveHBLANK_A;
+       u32 saveHSYNC_A;
+       u32 saveVTOTAL_A;
+       u32 saveVBLANK_A;
+       u32 saveVSYNC_A;
+       u32 saveBCLRPAT_A;
+       u32 savePIPEASTAT;
+       u32 saveDSPASTRIDE;
+       u32 saveDSPASIZE;
+       u32 saveDSPAPOS;
+       u32 saveDSPABASE;
+       u32 saveDSPASURF;
+       u32 saveDSPATILEOFF;
+       u32 savePFIT_PGM_RATIOS;
+       u32 saveBLC_PWM_CTL;
+       u32 saveBLC_PWM_CTL2;
+       u32 saveFPB0;
+       u32 saveFPB1;
+       u32 saveDPLL_B;
+       u32 saveDPLL_B_MD;
+       u32 saveHTOTAL_B;
+       u32 saveHBLANK_B;
+       u32 saveHSYNC_B;
+       u32 saveVTOTAL_B;
+       u32 saveVBLANK_B;
+       u32 saveVSYNC_B;
+       u32 saveBCLRPAT_B;
+       u32 savePIPEBSTAT;
+       u32 saveDSPBSTRIDE;
+       u32 saveDSPBSIZE;
+       u32 saveDSPBPOS;
+       u32 saveDSPBBASE;
+       u32 saveDSPBSURF;
+       u32 saveDSPBTILEOFF;
+       u32 saveVCLK_DIVISOR_VGA0;
+       u32 saveVCLK_DIVISOR_VGA1;
+       u32 saveVCLK_POST_DIV;
+       u32 saveVGACNTRL;
+       u32 saveADPA;
+       u32 saveLVDS;
+       u32 saveLVDSPP_ON;
+       u32 saveLVDSPP_OFF;
+       u32 saveDVOA;
+       u32 saveDVOB;
+       u32 saveDVOC;
+       u32 savePP_ON;
+       u32 savePP_OFF;
+       u32 savePP_CONTROL;
+       u32 savePP_CYCLE;
+       u32 savePFIT_CONTROL;
+       u32 save_palette_a[256];
+       u32 save_palette_b[256];
+       u32 saveFBC_CFB_BASE;
+       u32 saveFBC_LL_BASE;
+       u32 saveFBC_CONTROL;
+       u32 saveFBC_CONTROL2;
+       u32 saveIER;
+       u32 saveIIR;
+       u32 saveIMR;
+       u32 saveCACHE_MODE_0;
+       u32 saveD_STATE;
+       u32 saveDSPCLK_GATE_D;
+       u32 saveMI_ARB_STATE;
+       u32 saveSWF0[16];
+       u32 saveSWF1[16];
+       u32 saveSWF2[3];
+       u8 saveMSR;
+       u8 saveSR[8];
+       u8 saveGR[25];
+       u8 saveAR_INDEX;
+       u8 saveAR[21];
+       u8 saveDACMASK;
+       u8 saveDACDATA[256*3]; /* 256 3-byte colors */
+       u8 saveCR[37];
+} drm_i915_private_t;
+
+extern struct drm_ioctl_desc i915_ioctls[];
+extern int i915_max_ioctl;
+
+                               /* i915_dma.c */
+extern void i915_kernel_lost_context(struct drm_device * dev);
+extern int i915_driver_load(struct drm_device *, unsigned long flags);
+extern int i915_driver_unload(struct drm_device *);
+extern void i915_driver_lastclose(struct drm_device * dev);
+extern void i915_driver_preclose(struct drm_device *dev,
+                                struct drm_file *file_priv);
+extern int i915_driver_device_is_agp(struct drm_device * dev);
+extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
+                             unsigned long arg);
+
+/* i915_irq.c */
+extern int i915_irq_emit(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int i915_irq_wait(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+
+extern int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence);
+extern int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
+extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
+extern void i915_driver_irq_preinstall(struct drm_device * dev);
+extern void i915_driver_irq_postinstall(struct drm_device * dev);
+extern void i915_driver_irq_uninstall(struct drm_device * dev);
+extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
+                               struct drm_file *file_priv);
+extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
+                               struct drm_file *file_priv);
+extern int i915_vblank_swap(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv);
+
+/* i915_mem.c */
+extern int i915_mem_alloc(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv);
+extern int i915_mem_free(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int i915_mem_init_heap(struct drm_device *dev, void *data,
+                             struct drm_file *file_priv);
+extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
+                                struct drm_file *file_priv);
+extern void i915_mem_takedown(struct mem_block **heap);
+extern void i915_mem_release(struct drm_device * dev,
+                            struct drm_file *file_priv, struct mem_block *heap);
+
+#define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, (reg))
+#define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
+#define I915_READ16(reg)       DRM_READ16(dev_priv->mmio_map, (reg))
+#define I915_WRITE16(reg,val)  DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
+
+#define I915_VERBOSE 0
+
+#define RING_LOCALS    unsigned int outring, ringmask, outcount; \
+                        volatile char *virt;
+
+#define BEGIN_LP_RING(n) do {                          \
+       if (I915_VERBOSE)                               \
+               DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n));  \
+       if (dev_priv->ring.space < (n)*4)               \
+               i915_wait_ring(dev, (n)*4, __func__);           \
+       outcount = 0;                                   \
+       outring = dev_priv->ring.tail;                  \
+       ringmask = dev_priv->ring.tail_mask;            \
+       virt = dev_priv->ring.virtual_start;            \
+} while (0)
+
+#define OUT_RING(n) do {                                       \
+       if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
+       *(volatile unsigned int *)(virt + outring) = (n);       \
+        outcount++;                                            \
+       outring += 4;                                           \
+       outring &= ringmask;                                    \
+} while (0)
+
+#define ADVANCE_LP_RING() do {                                         \
+       if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
+       dev_priv->ring.tail = outring;                                  \
+       dev_priv->ring.space -= outcount * 4;                           \
+       I915_WRITE(LP_RING + RING_TAIL, outring);                       \
+} while(0)
+
+extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
+
+/* Extended config space */
+#define LBB 0xf4
+
+/* VGA stuff */
+
+#define VGA_ST01_MDA 0x3ba
+#define VGA_ST01_CGA 0x3da
+
+#define VGA_MSR_WRITE 0x3c2
+#define VGA_MSR_READ 0x3cc
+#define   VGA_MSR_MEM_EN (1<<1)
+#define   VGA_MSR_CGA_MODE (1<<0)
+
+#define VGA_SR_INDEX 0x3c4
+#define VGA_SR_DATA 0x3c5
+
+#define VGA_AR_INDEX 0x3c0
+#define   VGA_AR_VID_EN (1<<5)
+#define VGA_AR_DATA_WRITE 0x3c0
+#define VGA_AR_DATA_READ 0x3c1
+
+#define VGA_GR_INDEX 0x3ce
+#define VGA_GR_DATA 0x3cf
+/* GR05 */
+#define   VGA_GR_MEM_READ_MODE_SHIFT 3
+#define     VGA_GR_MEM_READ_MODE_PLANE 1
+/* GR06 */
+#define   VGA_GR_MEM_MODE_MASK 0xc
+#define   VGA_GR_MEM_MODE_SHIFT 2
+#define   VGA_GR_MEM_A0000_AFFFF 0
+#define   VGA_GR_MEM_A0000_BFFFF 1
+#define   VGA_GR_MEM_B0000_B7FFF 2
+#define   VGA_GR_MEM_B0000_BFFFF 3
+
+#define VGA_DACMASK 0x3c6
+#define VGA_DACRX 0x3c7
+#define VGA_DACWX 0x3c8
+#define VGA_DACDATA 0x3c9
+
+#define VGA_CR_INDEX_MDA 0x3b4
+#define VGA_CR_DATA_MDA 0x3b5
+#define VGA_CR_INDEX_CGA 0x3d4
+#define VGA_CR_DATA_CGA 0x3d5
+
+#define GFX_OP_USER_INTERRUPT          ((0<<29)|(2<<23))
+#define GFX_OP_BREAKPOINT_INTERRUPT    ((0<<29)|(1<<23))
+#define CMD_REPORT_HEAD                        (7<<23)
+#define CMD_STORE_DWORD_IDX            ((0x21<<23) | 0x1)
+#define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
+
+#define INST_PARSER_CLIENT   0x00000000
+#define INST_OP_FLUSH        0x02000000
+#define INST_FLUSH_MAP_CACHE 0x00000001
+
+#define BB1_START_ADDR_MASK   (~0x7)
+#define BB1_PROTECTED         (1<<0)
+#define BB1_UNPROTECTED       (0<<0)
+#define BB2_END_ADDR_MASK     (~0x7)
+
+/* Framebuffer compression */
+#define FBC_CFB_BASE           0x03200 /* 4k page aligned */
+#define FBC_LL_BASE            0x03204 /* 4k page aligned */
+#define FBC_CONTROL            0x03208
+#define   FBC_CTL_EN           (1<<31)
+#define   FBC_CTL_PERIODIC     (1<<30)
+#define   FBC_CTL_INTERVAL_SHIFT (16)
+#define   FBC_CTL_UNCOMPRESSIBLE (1<<14)
+#define   FBC_CTL_STRIDE_SHIFT (5)
+#define   FBC_CTL_FENCENO      (1<<0)
+#define FBC_COMMAND            0x0320c
+#define   FBC_CMD_COMPRESS     (1<<0)
+#define FBC_STATUS             0x03210
+#define   FBC_STAT_COMPRESSING (1<<31)
+#define   FBC_STAT_COMPRESSED  (1<<30)
+#define   FBC_STAT_MODIFIED    (1<<29)
+#define   FBC_STAT_CURRENT_LINE        (1<<0)
+#define FBC_CONTROL2           0x03214
+#define   FBC_CTL_FENCE_DBL    (0<<4)
+#define   FBC_CTL_IDLE_IMM     (0<<2)
+#define   FBC_CTL_IDLE_FULL    (1<<2)
+#define   FBC_CTL_IDLE_LINE    (2<<2)
+#define   FBC_CTL_IDLE_DEBUG   (3<<2)
+#define   FBC_CTL_CPU_FENCE    (1<<1)
+#define   FBC_CTL_PLANEA       (0<<0)
+#define   FBC_CTL_PLANEB       (1<<0)
+#define FBC_FENCE_OFF          0x0321b
+
+#define FBC_LL_SIZE            (1536)
+#define FBC_LL_PAD             (32)
+
+/* Interrupt bits:
+ */
+#define USER_INT_FLAG    (1<<1)
+#define VSYNC_PIPEB_FLAG (1<<5)
+#define VSYNC_PIPEA_FLAG (1<<7)
+#define HWB_OOM_FLAG     (1<<13) /* binner out of memory */
+
+#define I915REG_HWSTAM         0x02098
+#define I915REG_INT_IDENTITY_R 0x020a4
+#define I915REG_INT_MASK_R     0x020a8
+#define I915REG_INT_ENABLE_R   0x020a0
+
+#define I915REG_PIPEASTAT      0x70024
+#define I915REG_PIPEBSTAT      0x71024
+
+#define I915_VBLANK_INTERRUPT_ENABLE   (1UL<<17)
+#define I915_VBLANK_CLEAR              (1UL<<1)
+
+#define SRX_INDEX              0x3c4
+#define SRX_DATA               0x3c5
+#define SR01                   1
+#define SR01_SCREEN_OFF                (1<<5)
+
+#define PPCR                   0x61204
+#define PPCR_ON                        (1<<0)
+
+#define DVOB                   0x61140
+#define DVOB_ON                        (1<<31)
+#define DVOC                   0x61160
+#define DVOC_ON                        (1<<31)
+#define LVDS                   0x61180
+#define LVDS_ON                        (1<<31)
+
+#define ADPA                   0x61100
+#define ADPA_DPMS_MASK         (~(3<<10))
+#define ADPA_DPMS_ON           (0<<10)
+#define ADPA_DPMS_SUSPEND      (1<<10)
+#define ADPA_DPMS_STANDBY      (2<<10)
+#define ADPA_DPMS_OFF          (3<<10)
+
+#define NOPID                   0x2094
+#define LP_RING                        0x2030
+#define HP_RING                        0x2040
+/* The binner has its own ring buffer:
+ */
+#define HWB_RING               0x2400
+
+#define RING_TAIL              0x00
+#define TAIL_ADDR              0x001FFFF8
+#define RING_HEAD              0x04
+#define HEAD_WRAP_COUNT                0xFFE00000
+#define HEAD_WRAP_ONE          0x00200000
+#define HEAD_ADDR              0x001FFFFC
+#define RING_START             0x08
+#define START_ADDR             0x0xFFFFF000
+#define RING_LEN               0x0C
+#define RING_NR_PAGES          0x001FF000
+#define RING_REPORT_MASK       0x00000006
+#define RING_REPORT_64K                0x00000002
+#define RING_REPORT_128K       0x00000004
+#define RING_NO_REPORT         0x00000000
+#define RING_VALID_MASK                0x00000001
+#define RING_VALID             0x00000001
+#define RING_INVALID           0x00000000
+
+/* Instruction parser error reg:
+ */
+#define IPEIR                  0x2088
+
+/* Scratch pad debug 0 reg:
+ */
+#define SCPD0                  0x209c
+
+/* Error status reg:
+ */
+#define ESR                    0x20b8
+
+/* Secondary DMA fetch address debug reg:
+ */
+#define DMA_FADD_S             0x20d4
+
+/* Memory Interface Arbitration State
+ */
+#define MI_ARB_STATE           0x20e4
+
+/* Cache mode 0 reg.
+ *  - Manipulating render cache behaviour is central
+ *    to the concept of zone rendering, tuning this reg can help avoid
+ *    unnecessary render cache reads and even writes (for z/stencil)
+ *    at beginning and end of scene.
+ *
+ * - To change a bit, write to this reg with a mask bit set and the
+ * bit of interest either set or cleared.  EG: (BIT<<16) | BIT to set.
+ */
+#define Cache_Mode_0           0x2120
+#define CACHE_MODE_0           0x2120
+#define CM0_MASK_SHIFT          16
+#define CM0_IZ_OPT_DISABLE      (1<<6)
+#define CM0_ZR_OPT_DISABLE      (1<<5)
+#define CM0_DEPTH_EVICT_DISABLE (1<<4)
+#define CM0_COLOR_EVICT_DISABLE (1<<3)
+#define CM0_DEPTH_WRITE_DISABLE (1<<1)
+#define CM0_RC_OP_FLUSH_DISABLE (1<<0)
+
+
+/* Graphics flush control.  A CPU write flushes the GWB of all writes.
+ * The data is discarded.
+ */
+#define GFX_FLSH_CNTL          0x2170
+
+/* Binner control.  Defines the location of the bin pointer list:
+ */
+#define BINCTL                 0x2420
+#define BC_MASK                        (1 << 9)
+
+/* Binned scene info.
+ */
+#define BINSCENE               0x2428
+#define BS_OP_LOAD             (1 << 8)
+#define BS_MASK                        (1 << 22)
+
+/* Bin command parser debug reg:
+ */
+#define BCPD                   0x2480
+
+/* Bin memory control debug reg:
+ */
+#define BMCD                   0x2484
+
+/* Bin data cache debug reg:
+ */
+#define BDCD                   0x2488
+
+/* Binner pointer cache debug reg:
+ */
+#define BPCD                   0x248c
+
+/* Binner scratch pad debug reg:
+ */
+#define BINSKPD                        0x24f0
+
+/* HWB scratch pad debug reg:
+ */
+#define HWBSKPD                        0x24f4
+
+/* Binner memory pool reg:
+ */
+#define BMP_BUFFER             0x2430
+#define BMP_PAGE_SIZE_4K       (0 << 10)
+#define BMP_BUFFER_SIZE_SHIFT  1
+#define BMP_ENABLE             (1 << 0)
+
+/* Get/put memory from the binner memory pool:
+ */
+#define BMP_GET                        0x2438
+#define BMP_PUT                        0x2440
+#define BMP_OFFSET_SHIFT       5
+
+/* 3D state packets:
+ */
+#define GFX_OP_RASTER_RULES    ((0x3<<29)|(0x7<<24))
+
+#define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
+#define SC_UPDATE_SCISSOR       (0x1<<1)
+#define SC_ENABLE_MASK          (0x1<<0)
+#define SC_ENABLE               (0x1<<0)
+
+#define GFX_OP_LOAD_INDIRECT   ((0x3<<29)|(0x1d<<24)|(0x7<<16))
+
+#define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
+#define SCI_YMIN_MASK      (0xffff<<16)
+#define SCI_XMIN_MASK      (0xffff<<0)
+#define SCI_YMAX_MASK      (0xffff<<16)
+#define SCI_XMAX_MASK      (0xffff<<0)
+
+#define GFX_OP_SCISSOR_ENABLE   ((0x3<<29)|(0x1c<<24)|(0x10<<19))
+#define GFX_OP_SCISSOR_RECT     ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
+#define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
+#define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
+#define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
+#define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
+#define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
+
+#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
+
+#define SRC_COPY_BLT_CMD                ((2<<29)|(0x43<<22)|4)
+#define XY_SRC_COPY_BLT_CMD            ((2<<29)|(0x53<<22)|6)
+#define XY_SRC_COPY_BLT_WRITE_ALPHA    (1<<21)
+#define XY_SRC_COPY_BLT_WRITE_RGB      (1<<20)
+#define XY_SRC_COPY_BLT_SRC_TILED      (1<<15)
+#define XY_SRC_COPY_BLT_DST_TILED      (1<<11)
+
+#define MI_BATCH_BUFFER                ((0x30<<23)|1)
+#define MI_BATCH_BUFFER_START  (0x31<<23)
+#define MI_BATCH_BUFFER_END    (0xA<<23)
+#define MI_BATCH_NON_SECURE    (1)
+#define MI_BATCH_NON_SECURE_I965 (1<<8)
+
+#define MI_WAIT_FOR_EVENT       ((0x3<<23))
+#define MI_WAIT_FOR_PLANE_B_FLIP      (1<<6)
+#define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
+#define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
+
+#define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
+
+#define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
+#define ASYNC_FLIP                (1<<22)
+#define DISPLAY_PLANE_A           (0<<20)
+#define DISPLAY_PLANE_B           (1<<20)
+
+/* Display regs */
+#define DSPACNTR                0x70180
+#define DSPBCNTR                0x71180
+#define DISPPLANE_SEL_PIPE_MASK                 (1<<24)
+
+/* Define the region of interest for the binner:
+ */
+#define CMD_OP_BIN_CONTROL      ((0x3<<29)|(0x1d<<24)|(0x84<<16)|4)
+
+#define CMD_OP_DESTBUFFER_INFO  ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
+
+#define CMD_MI_FLUSH         (0x04 << 23)
+#define MI_NO_WRITE_FLUSH    (1 << 2)
+#define MI_READ_FLUSH        (1 << 0)
+#define MI_EXE_FLUSH         (1 << 1)
+#define MI_END_SCENE         (1 << 4) /* flush binner and incr scene count */
+#define MI_SCENE_COUNT       (1 << 3) /* just increment scene count */
+
+#define BREADCRUMB_BITS 31
+#define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
+
+#define READ_BREADCRUMB(dev_priv)  (((volatile u32*)(dev_priv->hw_status_page))[5])
+#define READ_HWSP(dev_priv, reg)  (((volatile u32*)(dev_priv->hw_status_page))[reg])
+
+#define BLC_PWM_CTL            0x61254
+#define BACKLIGHT_MODULATION_FREQ_SHIFT                (17)
+
+#define BLC_PWM_CTL2           0x61250
+/**
+ * This is the most significant 15 bits of the number of backlight cycles in a
+ * complete cycle of the modulated backlight control.
+ *
+ * The actual value is this field multiplied by two.
+ */
+#define BACKLIGHT_MODULATION_FREQ_MASK         (0x7fff << 17)
+#define BLM_LEGACY_MODE                                (1 << 16)
+/**
+ * This is the number of cycles out of the backlight modulation cycle for which
+ * the backlight is on.
+ *
+ * This field must be no greater than the number of cycles in the complete
+ * backlight modulation cycle.
+ */
+#define BACKLIGHT_DUTY_CYCLE_SHIFT             (0)
+#define BACKLIGHT_DUTY_CYCLE_MASK              (0xffff)
+
+#define I915_GCFGC                     0xf0
+#define I915_LOW_FREQUENCY_ENABLE              (1 << 7)
+#define I915_DISPLAY_CLOCK_190_200_MHZ         (0 << 4)
+#define I915_DISPLAY_CLOCK_333_MHZ             (4 << 4)
+#define I915_DISPLAY_CLOCK_MASK                        (7 << 4)
+
+#define I855_HPLLCC                    0xc0
+#define I855_CLOCK_CONTROL_MASK                        (3 << 0)
+#define I855_CLOCK_133_200                     (0 << 0)
+#define I855_CLOCK_100_200                     (1 << 0)
+#define I855_CLOCK_100_133                     (2 << 0)
+#define I855_CLOCK_166_250                     (3 << 0)
+
+/* p317, 319
+ */
+#define VCLK2_VCO_M        0x6008 /* treat as 16 bit? (includes msbs) */
+#define VCLK2_VCO_N        0x600a
+#define VCLK2_VCO_DIV_SEL  0x6012
+
+#define VCLK_DIVISOR_VGA0   0x6000
+#define VCLK_DIVISOR_VGA1   0x6004
+#define VCLK_POST_DIV      0x6010
+/** Selects a post divisor of 4 instead of 2. */
+# define VGA1_PD_P2_DIV_4      (1 << 15)
+/** Overrides the p2 post divisor field */
+# define VGA1_PD_P1_DIV_2      (1 << 13)
+# define VGA1_PD_P1_SHIFT      8
+/** P1 value is 2 greater than this field */
+# define VGA1_PD_P1_MASK       (0x1f << 8)
+/** Selects a post divisor of 4 instead of 2. */
+# define VGA0_PD_P2_DIV_4      (1 << 7)
+/** Overrides the p2 post divisor field */
+# define VGA0_PD_P1_DIV_2      (1 << 5)
+# define VGA0_PD_P1_SHIFT      0
+/** P1 value is 2 greater than this field */
+# define VGA0_PD_P1_MASK       (0x1f << 0)
+
+/* PCI D state control register */
+#define D_STATE                0x6104
+#define DSPCLK_GATE_D  0x6200
+
+/* I830 CRTC registers */
+#define HTOTAL_A       0x60000
+#define HBLANK_A       0x60004
+#define HSYNC_A                0x60008
+#define VTOTAL_A       0x6000c
+#define VBLANK_A       0x60010
+#define VSYNC_A                0x60014
+#define PIPEASRC       0x6001c
+#define BCLRPAT_A      0x60020
+#define VSYNCSHIFT_A   0x60028
+
+#define HTOTAL_B       0x61000
+#define HBLANK_B       0x61004
+#define HSYNC_B                0x61008
+#define VTOTAL_B       0x6100c
+#define VBLANK_B       0x61010
+#define VSYNC_B                0x61014
+#define PIPEBSRC       0x6101c
+#define BCLRPAT_B      0x61020
+#define VSYNCSHIFT_B   0x61028
+
+#define PP_STATUS      0x61200
+# define PP_ON                                 (1 << 31)
+/**
+ * Indicates that all dependencies of the panel are on:
+ *
+ * - PLL enabled
+ * - pipe enabled
+ * - LVDS/DVOB/DVOC on
+ */
+# define PP_READY                              (1 << 30)
+# define PP_SEQUENCE_NONE                      (0 << 28)
+# define PP_SEQUENCE_ON                                (1 << 28)
+# define PP_SEQUENCE_OFF                       (2 << 28)
+# define PP_SEQUENCE_MASK                      0x30000000
+#define PP_CONTROL     0x61204
+# define POWER_TARGET_ON                       (1 << 0)
+
+#define LVDSPP_ON       0x61208
+#define LVDSPP_OFF      0x6120c
+#define PP_CYCLE        0x61210
+
+#define PFIT_CONTROL   0x61230
+# define PFIT_ENABLE                           (1 << 31)
+# define PFIT_PIPE_MASK                                (3 << 29)
+# define PFIT_PIPE_SHIFT                       29
+# define VERT_INTERP_DISABLE                   (0 << 10)
+# define VERT_INTERP_BILINEAR                  (1 << 10)
+# define VERT_INTERP_MASK                      (3 << 10)
+# define VERT_AUTO_SCALE                       (1 << 9)
+# define HORIZ_INTERP_DISABLE                  (0 << 6)
+# define HORIZ_INTERP_BILINEAR                 (1 << 6)
+# define HORIZ_INTERP_MASK                     (3 << 6)
+# define HORIZ_AUTO_SCALE                      (1 << 5)
+# define PANEL_8TO6_DITHER_ENABLE              (1 << 3)
+
+#define PFIT_PGM_RATIOS        0x61234
+# define PFIT_VERT_SCALE_MASK                  0xfff00000
+# define PFIT_HORIZ_SCALE_MASK                 0x0000fff0
+
+#define PFIT_AUTO_RATIOS       0x61238
+
+
+#define DPLL_A         0x06014
+#define DPLL_B         0x06018
+# define DPLL_VCO_ENABLE                       (1 << 31)
+# define DPLL_DVO_HIGH_SPEED                   (1 << 30)
+# define DPLL_SYNCLOCK_ENABLE                  (1 << 29)
+# define DPLL_VGA_MODE_DIS                     (1 << 28)
+# define DPLLB_MODE_DAC_SERIAL                 (1 << 26) /* i915 */
+# define DPLLB_MODE_LVDS                       (2 << 26) /* i915 */
+# define DPLL_MODE_MASK                                (3 << 26)
+# define DPLL_DAC_SERIAL_P2_CLOCK_DIV_10       (0 << 24) /* i915 */
+# define DPLL_DAC_SERIAL_P2_CLOCK_DIV_5                (1 << 24) /* i915 */
+# define DPLLB_LVDS_P2_CLOCK_DIV_14            (0 << 24) /* i915 */
+# define DPLLB_LVDS_P2_CLOCK_DIV_7             (1 << 24) /* i915 */
+# define DPLL_P2_CLOCK_DIV_MASK                        0x03000000 /* i915 */
+# define DPLL_FPA01_P1_POST_DIV_MASK           0x00ff0000 /* i915 */
+/**
+ *  The i830 generation, in DAC/serial mode, defines p1 as two plus this
+ * bitfield, or just 2 if PLL_P1_DIVIDE_BY_TWO is set.
+ */
+# define DPLL_FPA01_P1_POST_DIV_MASK_I830      0x001f0000
+/**
+ * The i830 generation, in LVDS mode, defines P1 as the bit number set within
+ * this field (only one bit may be set).
+ */
+# define DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS 0x003f0000
+# define DPLL_FPA01_P1_POST_DIV_SHIFT          16
+# define PLL_P2_DIVIDE_BY_4                    (1 << 23) /* i830, required in DVO non-gang */
+# define PLL_P1_DIVIDE_BY_TWO                  (1 << 21) /* i830 */
+# define PLL_REF_INPUT_DREFCLK                 (0 << 13)
+# define PLL_REF_INPUT_TVCLKINA                        (1 << 13) /* i830 */
+# define PLL_REF_INPUT_TVCLKINBC               (2 << 13) /* SDVO TVCLKIN */
+# define PLLB_REF_INPUT_SPREADSPECTRUMIN       (3 << 13)
+# define PLL_REF_INPUT_MASK                    (3 << 13)
+# define PLL_LOAD_PULSE_PHASE_SHIFT            9
+/*
+ * Parallel to Serial Load Pulse phase selection.
+ * Selects the phase for the 10X DPLL clock for the PCIe
+ * digital display port. The range is 4 to 13; 10 or more
+ * is just a flip delay. The default is 6
+ */
+# define PLL_LOAD_PULSE_PHASE_MASK             (0xf << PLL_LOAD_PULSE_PHASE_SHIFT)
+# define DISPLAY_RATE_SELECT_FPA1              (1 << 8)
+
+/**
+ * SDVO multiplier for 945G/GM. Not used on 965.
+ *
+ * \sa DPLL_MD_UDI_MULTIPLIER_MASK
+ */
+# define SDVO_MULTIPLIER_MASK                  0x000000ff
+# define SDVO_MULTIPLIER_SHIFT_HIRES           4
+# define SDVO_MULTIPLIER_SHIFT_VGA             0
+
+/** @defgroup DPLL_MD
+ * @{
+ */
+/** Pipe A SDVO/UDI clock multiplier/divider register for G965. */
+#define DPLL_A_MD              0x0601c
+/** Pipe B SDVO/UDI clock multiplier/divider register for G965. */
+#define DPLL_B_MD              0x06020
+/**
+ * UDI pixel divider, controlling how many pixels are stuffed into a packet.
+ *
+ * Value is pixels minus 1.  Must be set to 1 pixel for SDVO.
+ */
+# define DPLL_MD_UDI_DIVIDER_MASK              0x3f000000
+# define DPLL_MD_UDI_DIVIDER_SHIFT             24
+/** UDI pixel divider for VGA, same as DPLL_MD_UDI_DIVIDER_MASK. */
+# define DPLL_MD_VGA_UDI_DIVIDER_MASK          0x003f0000
+# define DPLL_MD_VGA_UDI_DIVIDER_SHIFT         16
+/**
+ * SDVO/UDI pixel multiplier.
+ *
+ * SDVO requires that the bus clock rate be between 1 and 2 Ghz, and the bus
+ * clock rate is 10 times the DPLL clock.  At low resolution/refresh rate
+ * modes, the bus rate would be below the limits, so SDVO allows for stuffing
+ * dummy bytes in the datastream at an increased clock rate, with both sides of
+ * the link knowing how many bytes are fill.
+ *
+ * So, for a mode with a dotclock of 65Mhz, we would want to double the clock
+ * rate to 130Mhz to get a bus rate of 1.30Ghz.  The DPLL clock rate would be
+ * set to 130Mhz, and the SDVO multiplier set to 2x in this register and
+ * through an SDVO command.
+ *
+ * This register field has values of multiplication factor minus 1, with
+ * a maximum multiplier of 5 for SDVO.
+ */
+# define DPLL_MD_UDI_MULTIPLIER_MASK           0x00003f00
+# define DPLL_MD_UDI_MULTIPLIER_SHIFT          8
+/** SDVO/UDI pixel multiplier for VGA, same as DPLL_MD_UDI_MULTIPLIER_MASK.
+ * This best be set to the default value (3) or the CRT won't work. No,
+ * I don't entirely understand what this does...
+ */
+# define DPLL_MD_VGA_UDI_MULTIPLIER_MASK       0x0000003f
+# define DPLL_MD_VGA_UDI_MULTIPLIER_SHIFT      0
+/** @} */
+
+#define DPLL_TEST              0x606c
+# define DPLLB_TEST_SDVO_DIV_1                 (0 << 22)
+# define DPLLB_TEST_SDVO_DIV_2                 (1 << 22)
+# define DPLLB_TEST_SDVO_DIV_4                 (2 << 22)
+# define DPLLB_TEST_SDVO_DIV_MASK              (3 << 22)
+# define DPLLB_TEST_N_BYPASS                   (1 << 19)
+# define DPLLB_TEST_M_BYPASS                   (1 << 18)
+# define DPLLB_INPUT_BUFFER_ENABLE             (1 << 16)
+# define DPLLA_TEST_N_BYPASS                   (1 << 3)
+# define DPLLA_TEST_M_BYPASS                   (1 << 2)
+# define DPLLA_INPUT_BUFFER_ENABLE             (1 << 0)
+
+#define ADPA                   0x61100
+#define ADPA_DAC_ENABLE                (1<<31)
+#define ADPA_DAC_DISABLE       0
+#define ADPA_PIPE_SELECT_MASK  (1<<30)
+#define ADPA_PIPE_A_SELECT     0
+#define ADPA_PIPE_B_SELECT     (1<<30)
+#define ADPA_USE_VGA_HVPOLARITY (1<<15)
+#define ADPA_SETS_HVPOLARITY   0
+#define ADPA_VSYNC_CNTL_DISABLE (1<<11)
+#define ADPA_VSYNC_CNTL_ENABLE 0
+#define ADPA_HSYNC_CNTL_DISABLE (1<<10)
+#define ADPA_HSYNC_CNTL_ENABLE 0
+#define ADPA_VSYNC_ACTIVE_HIGH (1<<4)
+#define ADPA_VSYNC_ACTIVE_LOW  0
+#define ADPA_HSYNC_ACTIVE_HIGH (1<<3)
+#define ADPA_HSYNC_ACTIVE_LOW  0
+
+#define FPA0           0x06040
+#define FPA1           0x06044
+#define FPB0           0x06048
+#define FPB1           0x0604c
+# define FP_N_DIV_MASK                         0x003f0000
+# define FP_N_DIV_SHIFT                                16
+# define FP_M1_DIV_MASK                                0x00003f00
+# define FP_M1_DIV_SHIFT                       8
+# define FP_M2_DIV_MASK                                0x0000003f
+# define FP_M2_DIV_SHIFT                       0
+
+
+#define PORT_HOTPLUG_EN                0x61110
+# define SDVOB_HOTPLUG_INT_EN                  (1 << 26)
+# define SDVOC_HOTPLUG_INT_EN                  (1 << 25)
+# define TV_HOTPLUG_INT_EN                     (1 << 18)
+# define CRT_HOTPLUG_INT_EN                    (1 << 9)
+# define CRT_HOTPLUG_FORCE_DETECT              (1 << 3)
+
+#define PORT_HOTPLUG_STAT      0x61114
+# define CRT_HOTPLUG_INT_STATUS                        (1 << 11)
+# define TV_HOTPLUG_INT_STATUS                 (1 << 10)
+# define CRT_HOTPLUG_MONITOR_MASK              (3 << 8)
+# define CRT_HOTPLUG_MONITOR_COLOR             (3 << 8)
+# define CRT_HOTPLUG_MONITOR_MONO              (2 << 8)
+# define CRT_HOTPLUG_MONITOR_NONE              (0 << 8)
+# define SDVOC_HOTPLUG_INT_STATUS              (1 << 7)
+# define SDVOB_HOTPLUG_INT_STATUS              (1 << 6)
+
+#define SDVOB                  0x61140
+#define SDVOC                  0x61160
+#define SDVO_ENABLE                            (1 << 31)
+#define SDVO_PIPE_B_SELECT                     (1 << 30)
+#define SDVO_STALL_SELECT                      (1 << 29)
+#define SDVO_INTERRUPT_ENABLE                  (1 << 26)
+/**
+ * 915G/GM SDVO pixel multiplier.
+ *
+ * Programmed value is multiplier - 1, up to 5x.
+ *
+ * \sa DPLL_MD_UDI_MULTIPLIER_MASK
+ */
+#define SDVO_PORT_MULTIPLY_MASK                        (7 << 23)
+#define SDVO_PORT_MULTIPLY_SHIFT               23
+#define SDVO_PHASE_SELECT_MASK                 (15 << 19)
+#define SDVO_PHASE_SELECT_DEFAULT              (6 << 19)
+#define SDVO_CLOCK_OUTPUT_INVERT               (1 << 18)
+#define SDVOC_GANG_MODE                                (1 << 16)
+#define SDVO_BORDER_ENABLE                     (1 << 7)
+#define SDVOB_PCIE_CONCURRENCY                 (1 << 3)
+#define SDVO_DETECTED                          (1 << 2)
+/* Bits to be preserved when writing */
+#define SDVOB_PRESERVE_MASK                    ((1 << 17) | (1 << 16) | (1 << 14))
+#define SDVOC_PRESERVE_MASK                    (1 << 17)
+
+/** @defgroup LVDS
+ * @{
+ */
+/**
+ * This register controls the LVDS output enable, pipe selection, and data
+ * format selection.
+ *
+ * All of the clock/data pairs are force powered down by power sequencing.
+ */
+#define LVDS                   0x61180
+/**
+ * Enables the LVDS port.  This bit must be set before DPLLs are enabled, as
+ * the DPLL semantics change when the LVDS is assigned to that pipe.
+ */
+# define LVDS_PORT_EN                  (1 << 31)
+/** Selects pipe B for LVDS data.  Must be set on pre-965. */
+# define LVDS_PIPEB_SELECT             (1 << 30)
+
+/**
+ * Enables the A0-A2 data pairs and CLKA, containing 18 bits of color data per
+ * pixel.
+ */
+# define LVDS_A0A2_CLKA_POWER_MASK     (3 << 8)
+# define LVDS_A0A2_CLKA_POWER_DOWN     (0 << 8)
+# define LVDS_A0A2_CLKA_POWER_UP       (3 << 8)
+/**
+ * Controls the A3 data pair, which contains the additional LSBs for 24 bit
+ * mode.  Only enabled if LVDS_A0A2_CLKA_POWER_UP also indicates it should be
+ * on.
+ */
+# define LVDS_A3_POWER_MASK            (3 << 6)
+# define LVDS_A3_POWER_DOWN            (0 << 6)
+# define LVDS_A3_POWER_UP              (3 << 6)
+/**
+ * Controls the CLKB pair.  This should only be set when LVDS_B0B3_POWER_UP
+ * is set.
+ */
+# define LVDS_CLKB_POWER_MASK          (3 << 4)
+# define LVDS_CLKB_POWER_DOWN          (0 << 4)
+# define LVDS_CLKB_POWER_UP            (3 << 4)
+
+/**
+ * Controls the B0-B3 data pairs.  This must be set to match the DPLL p2
+ * setting for whether we are in dual-channel mode.  The B3 pair will
+ * additionally only be powered up when LVDS_A3_POWER_UP is set.
+ */
+# define LVDS_B0B3_POWER_MASK          (3 << 2)
+# define LVDS_B0B3_POWER_DOWN          (0 << 2)
+# define LVDS_B0B3_POWER_UP            (3 << 2)
+
+#define PIPEACONF 0x70008
+#define PIPEACONF_ENABLE       (1<<31)
+#define PIPEACONF_DISABLE      0
+#define PIPEACONF_DOUBLE_WIDE  (1<<30)
+#define I965_PIPECONF_ACTIVE   (1<<30)
+#define PIPEACONF_SINGLE_WIDE  0
+#define PIPEACONF_PIPE_UNLOCKED 0
+#define PIPEACONF_PIPE_LOCKED  (1<<25)
+#define PIPEACONF_PALETTE      0
+#define PIPEACONF_GAMMA                (1<<24)
+#define PIPECONF_FORCE_BORDER  (1<<25)
+#define PIPECONF_PROGRESSIVE   (0 << 21)
+#define PIPECONF_INTERLACE_W_FIELD_INDICATION  (6 << 21)
+#define PIPECONF_INTERLACE_FIELD_0_ONLY                (7 << 21)
+
+#define DSPARB   0x70030
+#define DSPARB_CSTART_MASK     (0x7f << 7)
+#define DSPARB_CSTART_SHIFT    7
+#define DSPARB_BSTART_MASK     (0x7f)           
+#define DSPARB_BSTART_SHIFT    0
+
+#define PIPEBCONF 0x71008
+#define PIPEBCONF_ENABLE       (1<<31)
+#define PIPEBCONF_DISABLE      0
+#define PIPEBCONF_DOUBLE_WIDE  (1<<30)
+#define PIPEBCONF_DISABLE      0
+#define PIPEBCONF_GAMMA                (1<<24)
+#define PIPEBCONF_PALETTE      0
+
+#define PIPEBGCMAXRED          0x71010
+#define PIPEBGCMAXGREEN                0x71014
+#define PIPEBGCMAXBLUE         0x71018
+#define PIPEBSTAT              0x71024
+#define PIPEBFRAMEHIGH         0x71040
+#define PIPEBFRAMEPIXEL                0x71044
+
+#define DSPACNTR               0x70180
+#define DSPBCNTR               0x71180
+#define DISPLAY_PLANE_ENABLE                   (1<<31)
+#define DISPLAY_PLANE_DISABLE                  0
+#define DISPPLANE_GAMMA_ENABLE                 (1<<30)
+#define DISPPLANE_GAMMA_DISABLE                        0
+#define DISPPLANE_PIXFORMAT_MASK               (0xf<<26)
+#define DISPPLANE_8BPP                         (0x2<<26)
+#define DISPPLANE_15_16BPP                     (0x4<<26)
+#define DISPPLANE_16BPP                                (0x5<<26)
+#define DISPPLANE_32BPP_NO_ALPHA               (0x6<<26)
+#define DISPPLANE_32BPP                                (0x7<<26)
+#define DISPPLANE_STEREO_ENABLE                        (1<<25)
+#define DISPPLANE_STEREO_DISABLE               0
+#define DISPPLANE_SEL_PIPE_MASK                        (1<<24)
+#define DISPPLANE_SEL_PIPE_A                   0
+#define DISPPLANE_SEL_PIPE_B                   (1<<24)
+#define DISPPLANE_SRC_KEY_ENABLE               (1<<22)
+#define DISPPLANE_SRC_KEY_DISABLE              0
+#define DISPPLANE_LINE_DOUBLE                  (1<<20)
+#define DISPPLANE_NO_LINE_DOUBLE               0
+#define DISPPLANE_STEREO_POLARITY_FIRST                0
+#define DISPPLANE_STEREO_POLARITY_SECOND       (1<<18)
+/* plane B only */
+#define DISPPLANE_ALPHA_TRANS_ENABLE           (1<<15)
+#define DISPPLANE_ALPHA_TRANS_DISABLE          0
+#define DISPPLANE_SPRITE_ABOVE_DISPLAYA                0
+#define DISPPLANE_SPRITE_ABOVE_OVERLAY         (1)
+
+#define DSPABASE               0x70184
+#define DSPASTRIDE             0x70188
+
+#define DSPBBASE               0x71184
+#define DSPBADDR               DSPBBASE
+#define DSPBSTRIDE             0x71188
+
+#define DSPAKEYVAL             0x70194
+#define DSPAKEYMASK            0x70198
+
+#define DSPAPOS                        0x7018C /* reserved */
+#define DSPASIZE               0x70190
+#define DSPBPOS                        0x7118C
+#define DSPBSIZE               0x71190
+
+#define DSPASURF               0x7019C
+#define DSPATILEOFF            0x701A4
+
+#define DSPBSURF               0x7119C
+#define DSPBTILEOFF            0x711A4
+
+#define VGACNTRL               0x71400
+# define VGA_DISP_DISABLE                      (1 << 31)
+# define VGA_2X_MODE                           (1 << 30)
+# define VGA_PIPE_B_SELECT                     (1 << 29)
+
+/*
+ * Some BIOS scratch area registers.  The 845 (and 830?) store the amount
+ * of video memory available to the BIOS in SWF1.
+ */
+
+#define SWF0                   0x71410
+
+/*
+ * 855 scratch registers.
+ */
+#define SWF10                  0x70410
+
+#define SWF30                  0x72414
+
+/*
+ * Overlay registers.  These are overlay registers accessed via MMIO.
+ * Those loaded via the overlay register page are defined in i830_video.c.
+ */
+#define OVADD                  0x30000
+
+#define DOVSTA                 0x30008
+#define OC_BUF                 (0x3<<20)
+
+#define OGAMC5                 0x30010
+#define OGAMC4                 0x30014
+#define OGAMC3                 0x30018
+#define OGAMC2                 0x3001c
+#define OGAMC1                 0x30020
+#define OGAMC0                 0x30024
+/*
+ * Palette registers
+ */
+#define PALETTE_A              0x0a000
+#define PALETTE_B              0x0a800
+
+#define IS_I830(dev) ((dev)->pci_device == 0x3577)
+#define IS_845G(dev) ((dev)->pci_device == 0x2562)
+#define IS_I85X(dev) ((dev)->pci_device == 0x3582)
+#define IS_I855(dev) ((dev)->pci_device == 0x3582)
+#define IS_I865G(dev) ((dev)->pci_device == 0x2572)
+
+#define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
+#define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
+#define IS_I945G(dev) ((dev)->pci_device == 0x2772)
+#define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
+                       (dev)->pci_device == 0x27AE)
+#define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
+                      (dev)->pci_device == 0x2982 || \
+                      (dev)->pci_device == 0x2992 || \
+                      (dev)->pci_device == 0x29A2 || \
+                      (dev)->pci_device == 0x2A02 || \
+                      (dev)->pci_device == 0x2A12 || \
+                      (dev)->pci_device == 0x2A42 || \
+                      (dev)->pci_device == 0x2E02 || \
+                      (dev)->pci_device == 0x2E12 || \
+                      (dev)->pci_device == 0x2E22)
+
+#define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
+
+#define IS_IGD_GM(dev) ((dev)->pci_device == 0x2A42)
+
+#define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
+                    (dev)->pci_device == 0x2E12 || \
+                    (dev)->pci_device == 0x2E22)
+
+#define IS_G33(dev)    ((dev)->pci_device == 0x29C2 || \
+                       (dev)->pci_device == 0x29B2 ||  \
+                       (dev)->pci_device == 0x29D2)
+
+#define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
+                     IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
+
+#define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
+                       IS_I945GM(dev) || IS_I965GM(dev) || IS_IGD_GM(dev))
+
+#define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_IGD_GM(dev) || IS_G4X(dev))
+
+#define PRIMARY_RINGBUFFER_SIZE         (128*1024)
+
+#endif
diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
new file mode 100644 (file)
index 0000000..1fe68a2
--- /dev/null
@@ -0,0 +1,222 @@
+/**
+ * \file i915_ioc32.c
+ *
+ * 32-bit ioctl compatibility routines for the i915 DRM.
+ *
+ * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
+ *
+ *
+ * Copyright (C) Paul Mackerras 2005
+ * Copyright (C) Alan Hourihane 2005
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include <linux/compat.h>
+
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+
+typedef struct _drm_i915_batchbuffer32 {
+       int start;              /* agp offset */
+       int used;               /* nr bytes in use */
+       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
+       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
+       int num_cliprects;      /* mulitpass with multiple cliprects? */
+       u32 cliprects;          /* pointer to userspace cliprects */
+} drm_i915_batchbuffer32_t;
+
+static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
+                                  unsigned long arg)
+{
+       drm_i915_batchbuffer32_t batchbuffer32;
+       drm_i915_batchbuffer_t __user *batchbuffer;
+
+       if (copy_from_user
+           (&batchbuffer32, (void __user *)arg, sizeof(batchbuffer32)))
+               return -EFAULT;
+
+       batchbuffer = compat_alloc_user_space(sizeof(*batchbuffer));
+       if (!access_ok(VERIFY_WRITE, batchbuffer, sizeof(*batchbuffer))
+           || __put_user(batchbuffer32.start, &batchbuffer->start)
+           || __put_user(batchbuffer32.used, &batchbuffer->used)
+           || __put_user(batchbuffer32.DR1, &batchbuffer->DR1)
+           || __put_user(batchbuffer32.DR4, &batchbuffer->DR4)
+           || __put_user(batchbuffer32.num_cliprects,
+                         &batchbuffer->num_cliprects)
+           || __put_user((int __user *)(unsigned long)batchbuffer32.cliprects,
+                         &batchbuffer->cliprects))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_I915_BATCHBUFFER,
+                        (unsigned long)batchbuffer);
+}
+
+typedef struct _drm_i915_cmdbuffer32 {
+       u32 buf;                /* pointer to userspace command buffer */
+       int sz;                 /* nr bytes in buf */
+       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
+       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
+       int num_cliprects;      /* mulitpass with multiple cliprects? */
+       u32 cliprects;          /* pointer to userspace cliprects */
+} drm_i915_cmdbuffer32_t;
+
+static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
+                                unsigned long arg)
+{
+       drm_i915_cmdbuffer32_t cmdbuffer32;
+       drm_i915_cmdbuffer_t __user *cmdbuffer;
+
+       if (copy_from_user
+           (&cmdbuffer32, (void __user *)arg, sizeof(cmdbuffer32)))
+               return -EFAULT;
+
+       cmdbuffer = compat_alloc_user_space(sizeof(*cmdbuffer));
+       if (!access_ok(VERIFY_WRITE, cmdbuffer, sizeof(*cmdbuffer))
+           || __put_user((int __user *)(unsigned long)cmdbuffer32.buf,
+                         &cmdbuffer->buf)
+           || __put_user(cmdbuffer32.sz, &cmdbuffer->sz)
+           || __put_user(cmdbuffer32.DR1, &cmdbuffer->DR1)
+           || __put_user(cmdbuffer32.DR4, &cmdbuffer->DR4)
+           || __put_user(cmdbuffer32.num_cliprects, &cmdbuffer->num_cliprects)
+           || __put_user((int __user *)(unsigned long)cmdbuffer32.cliprects,
+                         &cmdbuffer->cliprects))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
+}
+
+typedef struct drm_i915_irq_emit32 {
+       u32 irq_seq;
+} drm_i915_irq_emit32_t;
+
+static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_i915_irq_emit32_t req32;
+       drm_i915_irq_emit_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user((int __user *)(unsigned long)req32.irq_seq,
+                         &request->irq_seq))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
+}
+typedef struct drm_i915_getparam32 {
+       int param;
+       u32 value;
+} drm_i915_getparam32_t;
+
+static int compat_i915_getparam(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_i915_getparam32_t req32;
+       drm_i915_getparam_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.param, &request->param)
+           || __put_user((void __user *)(unsigned long)req32.value,
+                         &request->value))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
+}
+
+typedef struct drm_i915_mem_alloc32 {
+       int region;
+       int alignment;
+       int size;
+       u32 region_offset;      /* offset from start of fb or agp */
+} drm_i915_mem_alloc32_t;
+
+static int compat_i915_alloc(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       drm_i915_mem_alloc32_t req32;
+       drm_i915_mem_alloc_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.region, &request->region)
+           || __put_user(req32.alignment, &request->alignment)
+           || __put_user(req32.size, &request->size)
+           || __put_user((void __user *)(unsigned long)req32.region_offset,
+                         &request->region_offset))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_I915_ALLOC, (unsigned long)request);
+}
+
+drm_ioctl_compat_t *i915_compat_ioctls[] = {
+       [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
+       [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
+       [DRM_I915_GETPARAM] = compat_i915_getparam,
+       [DRM_I915_IRQ_EMIT] = compat_i915_irq_emit,
+       [DRM_I915_ALLOC] = compat_i915_alloc
+};
+
+/**
+ * Called whenever a 32-bit process running under a 64-bit kernel
+ * performs an ioctl on /dev/dri/card<n>.
+ *
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ */
+long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       drm_ioctl_compat_t *fn = NULL;
+       int ret;
+
+       if (nr < DRM_COMMAND_BASE)
+               return drm_compat_ioctl(filp, cmd, arg);
+
+       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
+               fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
+
+       lock_kernel();          /* XXX for now */
+       if (fn != NULL)
+               ret = (*fn) (filp, cmd, arg);
+       else
+               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
new file mode 100644 (file)
index 0000000..df03611
--- /dev/null
@@ -0,0 +1,623 @@
+/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
+ */
+/*
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+#define USER_INT_FLAG (1<<1)
+#define VSYNC_PIPEB_FLAG (1<<5)
+#define VSYNC_PIPEA_FLAG (1<<7)
+
+#define MAX_NOPID ((u32)~0)
+
+/**
+ * Emit blits for scheduled buffer swaps.
+ *
+ * This function will be called with the HW lock held.
+ */
+static void i915_vblank_tasklet(struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       unsigned long irqflags;
+       struct list_head *list, *tmp, hits, *hit;
+       int nhits, nrects, slice[2], upper[2], lower[2], i;
+       unsigned counter[2] = { atomic_read(&dev->vbl_received),
+                               atomic_read(&dev->vbl_received2) };
+       struct drm_drawable_info *drw;
+       drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       u32 cpp = dev_priv->cpp;
+       u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
+                               XY_SRC_COPY_BLT_WRITE_ALPHA |
+                               XY_SRC_COPY_BLT_WRITE_RGB)
+                            : XY_SRC_COPY_BLT_CMD;
+       u32 src_pitch = sarea_priv->pitch * cpp;
+       u32 dst_pitch = sarea_priv->pitch * cpp;
+       u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24);
+       RING_LOCALS;
+
+       if (IS_I965G(dev) && sarea_priv->front_tiled) {
+               cmd |= XY_SRC_COPY_BLT_DST_TILED;
+               dst_pitch >>= 2;
+       }
+       if (IS_I965G(dev) && sarea_priv->back_tiled) {
+               cmd |= XY_SRC_COPY_BLT_SRC_TILED;
+               src_pitch >>= 2;
+       }
+
+       DRM_DEBUG("\n");
+
+       INIT_LIST_HEAD(&hits);
+
+       nhits = nrects = 0;
+
+       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
+
+       /* Find buffer swaps scheduled for this vertical blank */
+       list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
+               drm_i915_vbl_swap_t *vbl_swap =
+                       list_entry(list, drm_i915_vbl_swap_t, head);
+
+               if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23))
+                       continue;
+
+               list_del(list);
+               dev_priv->swaps_pending--;
+
+               spin_unlock(&dev_priv->swaps_lock);
+               spin_lock(&dev->drw_lock);
+
+               drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
+
+               if (!drw) {
+                       spin_unlock(&dev->drw_lock);
+                       drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
+                       spin_lock(&dev_priv->swaps_lock);
+                       continue;
+               }
+
+               list_for_each(hit, &hits) {
+                       drm_i915_vbl_swap_t *swap_cmp =
+                               list_entry(hit, drm_i915_vbl_swap_t, head);
+                       struct drm_drawable_info *drw_cmp =
+                               drm_get_drawable_info(dev, swap_cmp->drw_id);
+
+                       if (drw_cmp &&
+                           drw_cmp->rects[0].y1 > drw->rects[0].y1) {
+                               list_add_tail(list, hit);
+                               break;
+                       }
+               }
+
+               spin_unlock(&dev->drw_lock);
+
+               /* List of hits was empty, or we reached the end of it */
+               if (hit == &hits)
+                       list_add_tail(list, hits.prev);
+
+               nhits++;
+
+               spin_lock(&dev_priv->swaps_lock);
+       }
+
+       if (nhits == 0) {
+               spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
+               return;
+       }
+
+       spin_unlock(&dev_priv->swaps_lock);
+
+       i915_kernel_lost_context(dev);
+
+       if (IS_I965G(dev)) {
+               BEGIN_LP_RING(4);
+
+               OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
+               OUT_RING(0);
+               OUT_RING(((sarea_priv->width - 1) & 0xffff) | ((sarea_priv->height - 1) << 16));
+               OUT_RING(0);
+               ADVANCE_LP_RING();
+       } else {
+               BEGIN_LP_RING(6);
+
+               OUT_RING(GFX_OP_DRAWRECT_INFO);
+               OUT_RING(0);
+               OUT_RING(0);
+               OUT_RING(sarea_priv->width | sarea_priv->height << 16);
+               OUT_RING(sarea_priv->width | sarea_priv->height << 16);
+               OUT_RING(0);
+
+               ADVANCE_LP_RING();
+       }
+
+       sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
+
+       upper[0] = upper[1] = 0;
+       slice[0] = max(sarea_priv->pipeA_h / nhits, 1);
+       slice[1] = max(sarea_priv->pipeB_h / nhits, 1);
+       lower[0] = sarea_priv->pipeA_y + slice[0];
+       lower[1] = sarea_priv->pipeB_y + slice[0];
+
+       spin_lock(&dev->drw_lock);
+
+       /* Emit blits for buffer swaps, partitioning both outputs into as many
+        * slices as there are buffer swaps scheduled in order to avoid tearing
+        * (based on the assumption that a single buffer swap would always
+        * complete before scanout starts).
+        */
+       for (i = 0; i++ < nhits;
+            upper[0] = lower[0], lower[0] += slice[0],
+            upper[1] = lower[1], lower[1] += slice[1]) {
+               if (i == nhits)
+                       lower[0] = lower[1] = sarea_priv->height;
+
+               list_for_each(hit, &hits) {
+                       drm_i915_vbl_swap_t *swap_hit =
+                               list_entry(hit, drm_i915_vbl_swap_t, head);
+                       struct drm_clip_rect *rect;
+                       int num_rects, pipe;
+                       unsigned short top, bottom;
+
+                       drw = drm_get_drawable_info(dev, swap_hit->drw_id);
+
+                       if (!drw)
+                               continue;
+
+                       rect = drw->rects;
+                       pipe = swap_hit->pipe;
+                       top = upper[pipe];
+                       bottom = lower[pipe];
+
+                       for (num_rects = drw->num_rects; num_rects--; rect++) {
+                               int y1 = max(rect->y1, top);
+                               int y2 = min(rect->y2, bottom);
+
+                               if (y1 >= y2)
+                                       continue;
+
+                               BEGIN_LP_RING(8);
+
+                               OUT_RING(cmd);
+                               OUT_RING(ropcpp | dst_pitch);
+                               OUT_RING((y1 << 16) | rect->x1);
+                               OUT_RING((y2 << 16) | rect->x2);
+                               OUT_RING(sarea_priv->front_offset);
+                               OUT_RING((y1 << 16) | rect->x1);
+                               OUT_RING(src_pitch);
+                               OUT_RING(sarea_priv->back_offset);
+
+                               ADVANCE_LP_RING();
+                       }
+               }
+       }
+
+       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+
+       list_for_each_safe(hit, tmp, &hits) {
+               drm_i915_vbl_swap_t *swap_hit =
+                       list_entry(hit, drm_i915_vbl_swap_t, head);
+
+               list_del(hit);
+
+               drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
+       }
+}
+
+irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       u16 temp;
+       u32 pipea_stats, pipeb_stats;
+
+       pipea_stats = I915_READ(I915REG_PIPEASTAT);
+       pipeb_stats = I915_READ(I915REG_PIPEBSTAT);
+
+       temp = I915_READ16(I915REG_INT_IDENTITY_R);
+
+       temp &= (USER_INT_FLAG | VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG);
+
+       DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
+
+       if (temp == 0)
+               return IRQ_NONE;
+
+       I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
+       (void) I915_READ16(I915REG_INT_IDENTITY_R);
+       DRM_READMEMORYBARRIER();
+
+       dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
+
+       if (temp & USER_INT_FLAG)
+               DRM_WAKEUP(&dev_priv->irq_queue);
+
+       if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
+               int vblank_pipe = dev_priv->vblank_pipe;
+
+               if ((vblank_pipe &
+                    (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
+                   == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
+                       if (temp & VSYNC_PIPEA_FLAG)
+                               atomic_inc(&dev->vbl_received);
+                       if (temp & VSYNC_PIPEB_FLAG)
+                               atomic_inc(&dev->vbl_received2);
+               } else if (((temp & VSYNC_PIPEA_FLAG) &&
+                           (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
+                          ((temp & VSYNC_PIPEB_FLAG) &&
+                           (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
+                       atomic_inc(&dev->vbl_received);
+
+               DRM_WAKEUP(&dev->vbl_queue);
+               drm_vbl_send_signals(dev);
+
+               if (dev_priv->swaps_pending > 0)
+                       drm_locked_tasklet(dev, i915_vblank_tasklet);
+               I915_WRITE(I915REG_PIPEASTAT,
+                       pipea_stats|I915_VBLANK_INTERRUPT_ENABLE|
+                       I915_VBLANK_CLEAR);
+               I915_WRITE(I915REG_PIPEBSTAT,
+                       pipeb_stats|I915_VBLANK_INTERRUPT_ENABLE|
+                       I915_VBLANK_CLEAR);
+       }
+
+       return IRQ_HANDLED;
+}
+
+static int i915_emit_irq(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       i915_kernel_lost_context(dev);
+
+       DRM_DEBUG("\n");
+
+       dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
+
+       if (dev_priv->counter > 0x7FFFFFFFUL)
+               dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
+
+       BEGIN_LP_RING(6);
+       OUT_RING(CMD_STORE_DWORD_IDX);
+       OUT_RING(20);
+       OUT_RING(dev_priv->counter);
+       OUT_RING(0);
+       OUT_RING(0);
+       OUT_RING(GFX_OP_USER_INTERRUPT);
+       ADVANCE_LP_RING();
+
+       return dev_priv->counter;
+}
+
+static int i915_wait_irq(struct drm_device * dev, int irq_nr)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       int ret = 0;
+
+       DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
+                 READ_BREADCRUMB(dev_priv));
+
+       if (READ_BREADCRUMB(dev_priv) >= irq_nr)
+               return 0;
+
+       dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
+
+       DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
+                   READ_BREADCRUMB(dev_priv) >= irq_nr);
+
+       if (ret == -EBUSY) {
+               DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
+                         READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
+       }
+
+       dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
+       return ret;
+}
+
+static int i915_driver_vblank_do_wait(struct drm_device *dev, unsigned int *sequence,
+                                     atomic_t *counter)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       unsigned int cur_vblank;
+       int ret = 0;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
+                   (((cur_vblank = atomic_read(counter))
+                       - *sequence) <= (1<<23)));
+
+       *sequence = cur_vblank;
+
+       return ret;
+}
+
+
+int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
+{
+       return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received);
+}
+
+int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
+{
+       return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2);
+}
+
+/* Needs the lock as it touches the ring.
+ */
+int i915_irq_emit(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_irq_emit_t *emit = data;
+       int result;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       result = i915_emit_irq(dev);
+
+       if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+/* Doesn't need the hardware lock.
+ */
+int i915_irq_wait(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_irq_wait_t *irqwait = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       return i915_wait_irq(dev, irqwait->irq_seq);
+}
+
+static void i915_enable_interrupt (struct drm_device *dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       u16 flag;
+
+       flag = 0;
+       if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
+               flag |= VSYNC_PIPEA_FLAG;
+       if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
+               flag |= VSYNC_PIPEB_FLAG;
+
+       I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
+}
+
+/* Set the vblank monitor pipe
+ */
+int i915_vblank_pipe_set(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_vblank_pipe_t *pipe = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
+               DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
+               return -EINVAL;
+       }
+
+       dev_priv->vblank_pipe = pipe->pipe;
+
+       i915_enable_interrupt (dev);
+
+       return 0;
+}
+
+int i915_vblank_pipe_get(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_vblank_pipe_t *pipe = data;
+       u16 flag;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       flag = I915_READ(I915REG_INT_ENABLE_R);
+       pipe->pipe = 0;
+       if (flag & VSYNC_PIPEA_FLAG)
+               pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
+       if (flag & VSYNC_PIPEB_FLAG)
+               pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
+
+       return 0;
+}
+
+/**
+ * Schedule buffer swap at given vertical blank.
+ */
+int i915_vblank_swap(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_vblank_swap_t *swap = data;
+       drm_i915_vbl_swap_t *vbl_swap;
+       unsigned int pipe, seqtype, curseq;
+       unsigned long irqflags;
+       struct list_head *list;
+
+       if (!dev_priv) {
+               DRM_ERROR("%s called with no initialization\n", __func__);
+               return -EINVAL;
+       }
+
+       if (dev_priv->sarea_priv->rotation) {
+               DRM_DEBUG("Rotation not supported\n");
+               return -EINVAL;
+       }
+
+       if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
+                            _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) {
+               DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
+               return -EINVAL;
+       }
+
+       pipe = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
+
+       seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
+
+       if (!(dev_priv->vblank_pipe & (1 << pipe))) {
+               DRM_ERROR("Invalid pipe %d\n", pipe);
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&dev->drw_lock, irqflags);
+
+       if (!drm_get_drawable_info(dev, swap->drawable)) {
+               spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+               DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
+               return -EINVAL;
+       }
+
+       spin_unlock_irqrestore(&dev->drw_lock, irqflags);
+
+       curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
+
+       if (seqtype == _DRM_VBLANK_RELATIVE)
+               swap->sequence += curseq;
+
+       if ((curseq - swap->sequence) <= (1<<23)) {
+               if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
+                       swap->sequence = curseq + 1;
+               } else {
+                       DRM_DEBUG("Missed target sequence\n");
+                       return -EINVAL;
+               }
+       }
+
+       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
+
+       list_for_each(list, &dev_priv->vbl_swaps.head) {
+               vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
+
+               if (vbl_swap->drw_id == swap->drawable &&
+                   vbl_swap->pipe == pipe &&
+                   vbl_swap->sequence == swap->sequence) {
+                       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
+                       DRM_DEBUG("Already scheduled\n");
+                       return 0;
+               }
+       }
+
+       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
+
+       if (dev_priv->swaps_pending >= 100) {
+               DRM_DEBUG("Too many swaps queued\n");
+               return -EBUSY;
+       }
+
+       vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
+
+       if (!vbl_swap) {
+               DRM_ERROR("Failed to allocate memory to queue swap\n");
+               return -ENOMEM;
+       }
+
+       DRM_DEBUG("\n");
+
+       vbl_swap->drw_id = swap->drawable;
+       vbl_swap->pipe = pipe;
+       vbl_swap->sequence = swap->sequence;
+
+       spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
+
+       list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
+       dev_priv->swaps_pending++;
+
+       spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
+
+       return 0;
+}
+
+/* drm_dma.h hooks
+*/
+void i915_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+
+       I915_WRITE16(I915REG_HWSTAM, 0xfffe);
+       I915_WRITE16(I915REG_INT_MASK_R, 0x0);
+       I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
+}
+
+void i915_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+
+       spin_lock_init(&dev_priv->swaps_lock);
+       INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
+       dev_priv->swaps_pending = 0;
+
+       if (!dev_priv->vblank_pipe)
+               dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
+       i915_enable_interrupt(dev);
+       DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
+}
+
+void i915_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
+       u16 temp;
+
+       if (!dev_priv)
+               return;
+
+       I915_WRITE16(I915REG_HWSTAM, 0xffff);
+       I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
+       I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
+
+       temp = I915_READ16(I915REG_INT_IDENTITY_R);
+       I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
+}
diff --git a/drivers/gpu/drm/i915/i915_mem.c b/drivers/gpu/drm/i915/i915_mem.c
new file mode 100644 (file)
index 0000000..6126a60
--- /dev/null
@@ -0,0 +1,386 @@
+/* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*-
+ */
+/*
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+/* This memory manager is integrated into the global/local lru
+ * mechanisms used by the clients.  Specifically, it operates by
+ * setting the 'in_use' fields of the global LRU to indicate whether
+ * this region is privately allocated to a client.
+ *
+ * This does require the client to actually respect that field.
+ *
+ * Currently no effort is made to allocate 'private' memory in any
+ * clever way - the LRU information isn't used to determine which
+ * block to allocate, and the ring is drained prior to allocations --
+ * in other words allocation is expensive.
+ */
+static void mark_block(struct drm_device * dev, struct mem_block *p, int in_use)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_tex_region *list;
+       unsigned shift, nr;
+       unsigned start;
+       unsigned end;
+       unsigned i;
+       int age;
+
+       shift = dev_priv->tex_lru_log_granularity;
+       nr = I915_NR_TEX_REGIONS;
+
+       start = p->start >> shift;
+       end = (p->start + p->size - 1) >> shift;
+
+       age = ++sarea_priv->texAge;
+       list = sarea_priv->texList;
+
+       /* Mark the regions with the new flag and update their age.  Move
+        * them to head of list to preserve LRU semantics.
+        */
+       for (i = start; i <= end; i++) {
+               list[i].in_use = in_use;
+               list[i].age = age;
+
+               /* remove_from_list(i)
+                */
+               list[(unsigned)list[i].next].prev = list[i].prev;
+               list[(unsigned)list[i].prev].next = list[i].next;
+
+               /* insert_at_head(list, i)
+                */
+               list[i].prev = nr;
+               list[i].next = list[nr].next;
+               list[(unsigned)list[nr].next].prev = i;
+               list[nr].next = i;
+       }
+}
+
+/* Very simple allocator for agp memory, working on a static range
+ * already mapped into each client's address space.
+ */
+
+static struct mem_block *split_block(struct mem_block *p, int start, int size,
+                                    struct drm_file *file_priv)
+{
+       /* Maybe cut off the start of an existing block */
+       if (start > p->start) {
+               struct mem_block *newblock =
+                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
+               if (!newblock)
+                       goto out;
+               newblock->start = start;
+               newblock->size = p->size - (start - p->start);
+               newblock->file_priv = NULL;
+               newblock->next = p->next;
+               newblock->prev = p;
+               p->next->prev = newblock;
+               p->next = newblock;
+               p->size -= newblock->size;
+               p = newblock;
+       }
+
+       /* Maybe cut off the end of an existing block */
+       if (size < p->size) {
+               struct mem_block *newblock =
+                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFLISTS);
+               if (!newblock)
+                       goto out;
+               newblock->start = start + size;
+               newblock->size = p->size - size;
+               newblock->file_priv = NULL;
+               newblock->next = p->next;
+               newblock->prev = p;
+               p->next->prev = newblock;
+               p->next = newblock;
+               p->size = size;
+       }
+
+      out:
+       /* Our block is in the middle */
+       p->file_priv = file_priv;
+       return p;
+}
+
+static struct mem_block *alloc_block(struct mem_block *heap, int size,
+                                    int align2, struct drm_file *file_priv)
+{
+       struct mem_block *p;
+       int mask = (1 << align2) - 1;
+
+       for (p = heap->next; p != heap; p = p->next) {
+               int start = (p->start + mask) & ~mask;
+               if (p->file_priv == NULL && start + size <= p->start + p->size)
+                       return split_block(p, start, size, file_priv);
+       }
+
+       return NULL;
+}
+
+static struct mem_block *find_block(struct mem_block *heap, int start)
+{
+       struct mem_block *p;
+
+       for (p = heap->next; p != heap; p = p->next)
+               if (p->start == start)
+                       return p;
+
+       return NULL;
+}
+
+static void free_block(struct mem_block *p)
+{
+       p->file_priv = NULL;
+
+       /* Assumes a single contiguous range.  Needs a special file_priv in
+        * 'heap' to stop it being subsumed.
+        */
+       if (p->next->file_priv == NULL) {
+               struct mem_block *q = p->next;
+               p->size += q->size;
+               p->next = q->next;
+               p->next->prev = p;
+               drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
+       }
+
+       if (p->prev->file_priv == NULL) {
+               struct mem_block *q = p->prev;
+               q->size += p->size;
+               q->next = p->next;
+               q->next->prev = q;
+               drm_free(p, sizeof(*q), DRM_MEM_BUFLISTS);
+       }
+}
+
+/* Initialize.  How to check for an uninitialized heap?
+ */
+static int init_heap(struct mem_block **heap, int start, int size)
+{
+       struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFLISTS);
+
+       if (!blocks)
+               return -ENOMEM;
+
+       *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFLISTS);
+       if (!*heap) {
+               drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFLISTS);
+               return -ENOMEM;
+       }
+
+       blocks->start = start;
+       blocks->size = size;
+       blocks->file_priv = NULL;
+       blocks->next = blocks->prev = *heap;
+
+       memset(*heap, 0, sizeof(**heap));
+       (*heap)->file_priv = (struct drm_file *) - 1;
+       (*heap)->next = (*heap)->prev = blocks;
+       return 0;
+}
+
+/* Free all blocks associated with the releasing file.
+ */
+void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv,
+                     struct mem_block *heap)
+{
+       struct mem_block *p;
+
+       if (!heap || !heap->next)
+               return;
+
+       for (p = heap->next; p != heap; p = p->next) {
+               if (p->file_priv == file_priv) {
+                       p->file_priv = NULL;
+                       mark_block(dev, p, 0);
+               }
+       }
+
+       /* Assumes a single contiguous range.  Needs a special file_priv in
+        * 'heap' to stop it being subsumed.
+        */
+       for (p = heap->next; p != heap; p = p->next) {
+               while (p->file_priv == NULL && p->next->file_priv == NULL) {
+                       struct mem_block *q = p->next;
+                       p->size += q->size;
+                       p->next = q->next;
+                       p->next->prev = p;
+                       drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
+               }
+       }
+}
+
+/* Shutdown.
+ */
+void i915_mem_takedown(struct mem_block **heap)
+{
+       struct mem_block *p;
+
+       if (!*heap)
+               return;
+
+       for (p = (*heap)->next; p != *heap;) {
+               struct mem_block *q = p;
+               p = p->next;
+               drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
+       }
+
+       drm_free(*heap, sizeof(**heap), DRM_MEM_BUFLISTS);
+       *heap = NULL;
+}
+
+static struct mem_block **get_heap(drm_i915_private_t * dev_priv, int region)
+{
+       switch (region) {
+       case I915_MEM_REGION_AGP:
+               return &dev_priv->agp_heap;
+       default:
+               return NULL;
+       }
+}
+
+/* IOCTL HANDLERS */
+
+int i915_mem_alloc(struct drm_device *dev, void *data,
+                  struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_mem_alloc_t *alloc = data;
+       struct mem_block *block, **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, alloc->region);
+       if (!heap || !*heap)
+               return -EFAULT;
+
+       /* Make things easier on ourselves: all allocations at least
+        * 4k aligned.
+        */
+       if (alloc->alignment < 12)
+               alloc->alignment = 12;
+
+       block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv);
+
+       if (!block)
+               return -ENOMEM;
+
+       mark_block(dev, block, 1);
+
+       if (DRM_COPY_TO_USER(alloc->region_offset, &block->start,
+                            sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+int i915_mem_free(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_mem_free_t *memfree = data;
+       struct mem_block *block, **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, memfree->region);
+       if (!heap || !*heap)
+               return -EFAULT;
+
+       block = find_block(*heap, memfree->region_offset);
+       if (!block)
+               return -EFAULT;
+
+       if (block->file_priv != file_priv)
+               return -EPERM;
+
+       mark_block(dev, block, 0);
+       free_block(block);
+       return 0;
+}
+
+int i915_mem_init_heap(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv)
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_mem_init_heap_t *initheap = data;
+       struct mem_block **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, initheap->region);
+       if (!heap)
+               return -EFAULT;
+
+       if (*heap) {
+               DRM_ERROR("heap already initialized?");
+               return -EFAULT;
+       }
+
+       return init_heap(heap, initheap->start, initheap->size);
+}
+
+int i915_mem_destroy_heap( struct drm_device *dev, void *data,
+                          struct drm_file *file_priv )
+{
+       drm_i915_private_t *dev_priv = dev->dev_private;
+       drm_i915_mem_destroy_heap_t *destroyheap = data;
+       struct mem_block **heap;
+
+       if ( !dev_priv ) {
+               DRM_ERROR( "called with no initialization\n" );
+               return -EINVAL;
+       }
+
+       heap = get_heap( dev_priv, destroyheap->region );
+       if (!heap) {
+               DRM_ERROR("get_heap failed");
+               return -EFAULT;
+       }
+
+       if (!*heap) {
+               DRM_ERROR("heap not initialized?");
+               return -EFAULT;
+       }
+
+       i915_mem_takedown( heap );
+       return 0;
+}
diff --git a/drivers/gpu/drm/mga/Makefile b/drivers/gpu/drm/mga/Makefile
new file mode 100644 (file)
index 0000000..6068478
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+mga-y := mga_drv.o mga_dma.o mga_state.o mga_warp.o mga_irq.o
+
+mga-$(CONFIG_COMPAT) += mga_ioc32.o
+
+obj-$(CONFIG_DRM_MGA)  += mga.o
+
diff --git a/drivers/gpu/drm/mga/mga_dma.c b/drivers/gpu/drm/mga/mga_dma.c
new file mode 100644 (file)
index 0000000..c1d12db
--- /dev/null
@@ -0,0 +1,1162 @@
+/* mga_dma.c -- DMA support for mga g200/g400 -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file mga_dma.c
+ * DMA support for MGA G200 / G400.
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Jeff Hartmann <jhartmann@valinux.com>
+ * \author Keith Whitwell <keith@tungstengraphics.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "drm_sarea.h"
+#include "mga_drm.h"
+#include "mga_drv.h"
+
+#define MGA_DEFAULT_USEC_TIMEOUT       10000
+#define MGA_FREELIST_DEBUG             0
+
+#define MINIMAL_CLEANUP 0
+#define FULL_CLEANUP 1
+static int mga_do_cleanup_dma(struct drm_device *dev, int full_cleanup);
+
+/* ================================================================
+ * Engine control
+ */
+
+int mga_do_wait_for_idle(drm_mga_private_t * dev_priv)
+{
+       u32 status = 0;
+       int i;
+       DRM_DEBUG("\n");
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
+               if (status == MGA_ENDPRDMASTS) {
+                       MGA_WRITE8(MGA_CRTC_INDEX, 0);
+                       return 0;
+               }
+               DRM_UDELAY(1);
+       }
+
+#if MGA_DMA_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x\n", status);
+#endif
+       return -EBUSY;
+}
+
+static int mga_do_dma_reset(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
+
+       DRM_DEBUG("\n");
+
+       /* The primary DMA stream should look like new right about now.
+        */
+       primary->tail = 0;
+       primary->space = primary->size;
+       primary->last_flush = 0;
+
+       sarea_priv->last_wrap = 0;
+
+       /* FIXME: Reset counters, buffer ages etc...
+        */
+
+       /* FIXME: What else do we need to reinitialize?  WARP stuff?
+        */
+
+       return 0;
+}
+
+/* ================================================================
+ * Primary DMA stream
+ */
+
+void mga_do_dma_flush(drm_mga_private_t * dev_priv)
+{
+       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
+       u32 head, tail;
+       u32 status = 0;
+       int i;
+       DMA_LOCALS;
+       DRM_DEBUG("\n");
+
+       /* We need to wait so that we can do an safe flush */
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
+               if (status == MGA_ENDPRDMASTS)
+                       break;
+               DRM_UDELAY(1);
+       }
+
+       if (primary->tail == primary->last_flush) {
+               DRM_DEBUG("   bailing out...\n");
+               return;
+       }
+
+       tail = primary->tail + dev_priv->primary->offset;
+
+       /* We need to pad the stream between flushes, as the card
+        * actually (partially?) reads the first of these commands.
+        * See page 4-16 in the G400 manual, middle of the page or so.
+        */
+       BEGIN_DMA(1);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+       ADVANCE_DMA();
+
+       primary->last_flush = primary->tail;
+
+       head = MGA_READ(MGA_PRIMADDRESS);
+
+       if (head <= tail) {
+               primary->space = primary->size - primary->tail;
+       } else {
+               primary->space = head - tail;
+       }
+
+       DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
+       DRM_DEBUG("   tail = 0x%06lx\n", tail - dev_priv->primary->offset);
+       DRM_DEBUG("  space = 0x%06x\n", primary->space);
+
+       mga_flush_write_combine();
+       MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
+
+       DRM_DEBUG("done.\n");
+}
+
+void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv)
+{
+       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
+       u32 head, tail;
+       DMA_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_DMA_WRAP();
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+       ADVANCE_DMA();
+
+       tail = primary->tail + dev_priv->primary->offset;
+
+       primary->tail = 0;
+       primary->last_flush = 0;
+       primary->last_wrap++;
+
+       head = MGA_READ(MGA_PRIMADDRESS);
+
+       if (head == dev_priv->primary->offset) {
+               primary->space = primary->size;
+       } else {
+               primary->space = head - dev_priv->primary->offset;
+       }
+
+       DRM_DEBUG("   head = 0x%06lx\n", head - dev_priv->primary->offset);
+       DRM_DEBUG("   tail = 0x%06x\n", primary->tail);
+       DRM_DEBUG("   wrap = %d\n", primary->last_wrap);
+       DRM_DEBUG("  space = 0x%06x\n", primary->space);
+
+       mga_flush_write_combine();
+       MGA_WRITE(MGA_PRIMEND, tail | dev_priv->dma_access);
+
+       set_bit(0, &primary->wrapped);
+       DRM_DEBUG("done.\n");
+}
+
+void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv)
+{
+       drm_mga_primary_buffer_t *primary = &dev_priv->prim;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       u32 head = dev_priv->primary->offset;
+       DRM_DEBUG("\n");
+
+       sarea_priv->last_wrap++;
+       DRM_DEBUG("   wrap = %d\n", sarea_priv->last_wrap);
+
+       mga_flush_write_combine();
+       MGA_WRITE(MGA_PRIMADDRESS, head | MGA_DMA_GENERAL);
+
+       clear_bit(0, &primary->wrapped);
+       DRM_DEBUG("done.\n");
+}
+
+/* ================================================================
+ * Freelist management
+ */
+
+#define MGA_BUFFER_USED                ~0
+#define MGA_BUFFER_FREE                0
+
+#if MGA_FREELIST_DEBUG
+static void mga_freelist_print(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_freelist_t *entry;
+
+       DRM_INFO("\n");
+       DRM_INFO("current dispatch: last=0x%x done=0x%x\n",
+                dev_priv->sarea_priv->last_dispatch,
+                (unsigned int)(MGA_READ(MGA_PRIMADDRESS) -
+                               dev_priv->primary->offset));
+       DRM_INFO("current freelist:\n");
+
+       for (entry = dev_priv->head->next; entry; entry = entry->next) {
+               DRM_INFO("   %p   idx=%2d  age=0x%x 0x%06lx\n",
+                        entry, entry->buf->idx, entry->age.head,
+                        entry->age.head - dev_priv->primary->offset);
+       }
+       DRM_INFO("\n");
+}
+#endif
+
+static int mga_freelist_init(struct drm_device * dev, drm_mga_private_t * dev_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_mga_buf_priv_t *buf_priv;
+       drm_mga_freelist_t *entry;
+       int i;
+       DRM_DEBUG("count=%d\n", dma->buf_count);
+
+       dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+       if (dev_priv->head == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
+       SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
+
+       for (i = 0; i < dma->buf_count; i++) {
+               buf = dma->buflist[i];
+               buf_priv = buf->dev_private;
+
+               entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+               if (entry == NULL)
+                       return -ENOMEM;
+
+               memset(entry, 0, sizeof(drm_mga_freelist_t));
+
+               entry->next = dev_priv->head->next;
+               entry->prev = dev_priv->head;
+               SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
+               entry->buf = buf;
+
+               if (dev_priv->head->next != NULL)
+                       dev_priv->head->next->prev = entry;
+               if (entry->next == NULL)
+                       dev_priv->tail = entry;
+
+               buf_priv->list_entry = entry;
+               buf_priv->discard = 0;
+               buf_priv->dispatched = 0;
+
+               dev_priv->head->next = entry;
+       }
+
+       return 0;
+}
+
+static void mga_freelist_cleanup(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_freelist_t *entry;
+       drm_mga_freelist_t *next;
+       DRM_DEBUG("\n");
+
+       entry = dev_priv->head;
+       while (entry) {
+               next = entry->next;
+               drm_free(entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+               entry = next;
+       }
+
+       dev_priv->head = dev_priv->tail = NULL;
+}
+
+#if 0
+/* FIXME: Still needed?
+ */
+static void mga_freelist_reset(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_mga_buf_priv_t *buf_priv;
+       int i;
+
+       for (i = 0; i < dma->buf_count; i++) {
+               buf = dma->buflist[i];
+               buf_priv = buf->dev_private;
+               SET_AGE(&buf_priv->list_entry->age, MGA_BUFFER_FREE, 0);
+       }
+}
+#endif
+
+static struct drm_buf *mga_freelist_get(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_freelist_t *next;
+       drm_mga_freelist_t *prev;
+       drm_mga_freelist_t *tail = dev_priv->tail;
+       u32 head, wrap;
+       DRM_DEBUG("\n");
+
+       head = MGA_READ(MGA_PRIMADDRESS);
+       wrap = dev_priv->sarea_priv->last_wrap;
+
+       DRM_DEBUG("   tail=0x%06lx %d\n",
+                 tail->age.head ?
+                 tail->age.head - dev_priv->primary->offset : 0,
+                 tail->age.wrap);
+       DRM_DEBUG("   head=0x%06lx %d\n",
+                 head - dev_priv->primary->offset, wrap);
+
+       if (TEST_AGE(&tail->age, head, wrap)) {
+               prev = dev_priv->tail->prev;
+               next = dev_priv->tail;
+               prev->next = NULL;
+               next->prev = next->next = NULL;
+               dev_priv->tail = prev;
+               SET_AGE(&next->age, MGA_BUFFER_USED, 0);
+               return next->buf;
+       }
+
+       DRM_DEBUG("returning NULL!\n");
+       return NULL;
+}
+
+int mga_freelist_put(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
+       drm_mga_freelist_t *head, *entry, *prev;
+
+       DRM_DEBUG("age=0x%06lx wrap=%d\n",
+                 buf_priv->list_entry->age.head -
+                 dev_priv->primary->offset, buf_priv->list_entry->age.wrap);
+
+       entry = buf_priv->list_entry;
+       head = dev_priv->head;
+
+       if (buf_priv->list_entry->age.head == MGA_BUFFER_USED) {
+               SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
+               prev = dev_priv->tail;
+               prev->next = entry;
+               entry->prev = prev;
+               entry->next = NULL;
+       } else {
+               prev = head->next;
+               head->next = entry;
+               prev->prev = entry;
+               entry->prev = head;
+               entry->next = prev;
+       }
+
+       return 0;
+}
+
+/* ================================================================
+ * DMA initialization, cleanup
+ */
+
+int mga_driver_load(struct drm_device * dev, unsigned long flags)
+{
+       drm_mga_private_t *dev_priv;
+
+       dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
+       if (!dev_priv)
+               return -ENOMEM;
+
+       dev->dev_private = (void *)dev_priv;
+       memset(dev_priv, 0, sizeof(drm_mga_private_t));
+
+       dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;
+       dev_priv->chipset = flags;
+
+       dev_priv->mmio_base = drm_get_resource_start(dev, 1);
+       dev_priv->mmio_size = drm_get_resource_len(dev, 1);
+
+       dev->counters += 3;
+       dev->types[6] = _DRM_STAT_IRQ;
+       dev->types[7] = _DRM_STAT_PRIMARY;
+       dev->types[8] = _DRM_STAT_SECONDARY;
+
+       return 0;
+}
+
+#if __OS_HAS_AGP
+/**
+ * Bootstrap the driver for AGP DMA.
+ *
+ * \todo
+ * Investigate whether there is any benifit to storing the WARP microcode in
+ * AGP memory.  If not, the microcode may as well always be put in PCI
+ * memory.
+ *
+ * \todo
+ * This routine needs to set dma_bs->agp_mode to the mode actually configured
+ * in the hardware.  Looking just at the Linux AGP driver code, I don't see
+ * an easy way to determine this.
+ *
+ * \sa mga_do_dma_bootstrap, mga_do_pci_dma_bootstrap
+ */
+static int mga_do_agp_dma_bootstrap(struct drm_device * dev,
+                                   drm_mga_dma_bootstrap_t * dma_bs)
+{
+       drm_mga_private_t *const dev_priv =
+           (drm_mga_private_t *) dev->dev_private;
+       unsigned int warp_size = mga_warp_microcode_size(dev_priv);
+       int err;
+       unsigned offset;
+       const unsigned secondary_size = dma_bs->secondary_bin_count
+           * dma_bs->secondary_bin_size;
+       const unsigned agp_size = (dma_bs->agp_size << 20);
+       struct drm_buf_desc req;
+       struct drm_agp_mode mode;
+       struct drm_agp_info info;
+       struct drm_agp_buffer agp_req;
+       struct drm_agp_binding bind_req;
+
+       /* Acquire AGP. */
+       err = drm_agp_acquire(dev);
+       if (err) {
+               DRM_ERROR("Unable to acquire AGP: %d\n", err);
+               return err;
+       }
+
+       err = drm_agp_info(dev, &info);
+       if (err) {
+               DRM_ERROR("Unable to get AGP info: %d\n", err);
+               return err;
+       }
+
+       mode.mode = (info.mode & ~0x07) | dma_bs->agp_mode;
+       err = drm_agp_enable(dev, mode);
+       if (err) {
+               DRM_ERROR("Unable to enable AGP (mode = 0x%lx)\n", mode.mode);
+               return err;
+       }
+
+       /* In addition to the usual AGP mode configuration, the G200 AGP cards
+        * need to have the AGP mode "manually" set.
+        */
+
+       if (dev_priv->chipset == MGA_CARD_TYPE_G200) {
+               if (mode.mode & 0x02) {
+                       MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_ENABLE);
+               } else {
+                       MGA_WRITE(MGA_AGP_PLL, MGA_AGP2XPLL_DISABLE);
+               }
+       }
+
+       /* Allocate and bind AGP memory. */
+       agp_req.size = agp_size;
+       agp_req.type = 0;
+       err = drm_agp_alloc(dev, &agp_req);
+       if (err) {
+               dev_priv->agp_size = 0;
+               DRM_ERROR("Unable to allocate %uMB AGP memory\n",
+                         dma_bs->agp_size);
+               return err;
+       }
+
+       dev_priv->agp_size = agp_size;
+       dev_priv->agp_handle = agp_req.handle;
+
+       bind_req.handle = agp_req.handle;
+       bind_req.offset = 0;
+       err = drm_agp_bind(dev, &bind_req);
+       if (err) {
+               DRM_ERROR("Unable to bind AGP memory: %d\n", err);
+               return err;
+       }
+
+       /* Make drm_addbufs happy by not trying to create a mapping for less
+        * than a page.
+        */
+       if (warp_size < PAGE_SIZE)
+               warp_size = PAGE_SIZE;
+
+       offset = 0;
+       err = drm_addmap(dev, offset, warp_size,
+                        _DRM_AGP, _DRM_READ_ONLY, &dev_priv->warp);
+       if (err) {
+               DRM_ERROR("Unable to map WARP microcode: %d\n", err);
+               return err;
+       }
+
+       offset += warp_size;
+       err = drm_addmap(dev, offset, dma_bs->primary_size,
+                        _DRM_AGP, _DRM_READ_ONLY, &dev_priv->primary);
+       if (err) {
+               DRM_ERROR("Unable to map primary DMA region: %d\n", err);
+               return err;
+       }
+
+       offset += dma_bs->primary_size;
+       err = drm_addmap(dev, offset, secondary_size,
+                        _DRM_AGP, 0, &dev->agp_buffer_map);
+       if (err) {
+               DRM_ERROR("Unable to map secondary DMA region: %d\n", err);
+               return err;
+       }
+
+       (void)memset(&req, 0, sizeof(req));
+       req.count = dma_bs->secondary_bin_count;
+       req.size = dma_bs->secondary_bin_size;
+       req.flags = _DRM_AGP_BUFFER;
+       req.agp_start = offset;
+
+       err = drm_addbufs_agp(dev, &req);
+       if (err) {
+               DRM_ERROR("Unable to add secondary DMA buffers: %d\n", err);
+               return err;
+       }
+
+       {
+               struct drm_map_list *_entry;
+               unsigned long agp_token = 0;
+
+               list_for_each_entry(_entry, &dev->maplist, head) {
+                       if (_entry->map == dev->agp_buffer_map)
+                               agp_token = _entry->user_token;
+               }
+               if (!agp_token)
+                       return -EFAULT;
+
+               dev->agp_buffer_token = agp_token;
+       }
+
+       offset += secondary_size;
+       err = drm_addmap(dev, offset, agp_size - offset,
+                        _DRM_AGP, 0, &dev_priv->agp_textures);
+       if (err) {
+               DRM_ERROR("Unable to map AGP texture region %d\n", err);
+               return err;
+       }
+
+       drm_core_ioremap(dev_priv->warp, dev);
+       drm_core_ioremap(dev_priv->primary, dev);
+       drm_core_ioremap(dev->agp_buffer_map, dev);
+
+       if (!dev_priv->warp->handle ||
+           !dev_priv->primary->handle || !dev->agp_buffer_map->handle) {
+               DRM_ERROR("failed to ioremap agp regions! (%p, %p, %p)\n",
+                         dev_priv->warp->handle, dev_priv->primary->handle,
+                         dev->agp_buffer_map->handle);
+               return -ENOMEM;
+       }
+
+       dev_priv->dma_access = MGA_PAGPXFER;
+       dev_priv->wagp_enable = MGA_WAGP_ENABLE;
+
+       DRM_INFO("Initialized card for AGP DMA.\n");
+       return 0;
+}
+#else
+static int mga_do_agp_dma_bootstrap(struct drm_device * dev,
+                                   drm_mga_dma_bootstrap_t * dma_bs)
+{
+       return -EINVAL;
+}
+#endif
+
+/**
+ * Bootstrap the driver for PCI DMA.
+ *
+ * \todo
+ * The algorithm for decreasing the size of the primary DMA buffer could be
+ * better.  The size should be rounded up to the nearest page size, then
+ * decrease the request size by a single page each pass through the loop.
+ *
+ * \todo
+ * Determine whether the maximum address passed to drm_pci_alloc is correct.
+ * The same goes for drm_addbufs_pci.
+ *
+ * \sa mga_do_dma_bootstrap, mga_do_agp_dma_bootstrap
+ */
+static int mga_do_pci_dma_bootstrap(struct drm_device * dev,
+                                   drm_mga_dma_bootstrap_t * dma_bs)
+{
+       drm_mga_private_t *const dev_priv =
+           (drm_mga_private_t *) dev->dev_private;
+       unsigned int warp_size = mga_warp_microcode_size(dev_priv);
+       unsigned int primary_size;
+       unsigned int bin_count;
+       int err;
+       struct drm_buf_desc req;
+
+       if (dev->dma == NULL) {
+               DRM_ERROR("dev->dma is NULL\n");
+               return -EFAULT;
+       }
+
+       /* Make drm_addbufs happy by not trying to create a mapping for less
+        * than a page.
+        */
+       if (warp_size < PAGE_SIZE)
+               warp_size = PAGE_SIZE;
+
+       /* The proper alignment is 0x100 for this mapping */
+       err = drm_addmap(dev, 0, warp_size, _DRM_CONSISTENT,
+                        _DRM_READ_ONLY, &dev_priv->warp);
+       if (err != 0) {
+               DRM_ERROR("Unable to create mapping for WARP microcode: %d\n",
+                         err);
+               return err;
+       }
+
+       /* Other than the bottom two bits being used to encode other
+        * information, there don't appear to be any restrictions on the
+        * alignment of the primary or secondary DMA buffers.
+        */
+
+       for (primary_size = dma_bs->primary_size; primary_size != 0;
+            primary_size >>= 1) {
+               /* The proper alignment for this mapping is 0x04 */
+               err = drm_addmap(dev, 0, primary_size, _DRM_CONSISTENT,
+                                _DRM_READ_ONLY, &dev_priv->primary);
+               if (!err)
+                       break;
+       }
+
+       if (err != 0) {
+               DRM_ERROR("Unable to allocate primary DMA region: %d\n", err);
+               return -ENOMEM;
+       }
+
+       if (dev_priv->primary->size != dma_bs->primary_size) {
+               DRM_INFO("Primary DMA buffer size reduced from %u to %u.\n",
+                        dma_bs->primary_size,
+                        (unsigned)dev_priv->primary->size);
+               dma_bs->primary_size = dev_priv->primary->size;
+       }
+
+       for (bin_count = dma_bs->secondary_bin_count; bin_count > 0;
+            bin_count--) {
+               (void)memset(&req, 0, sizeof(req));
+               req.count = bin_count;
+               req.size = dma_bs->secondary_bin_size;
+
+               err = drm_addbufs_pci(dev, &req);
+               if (!err) {
+                       break;
+               }
+       }
+
+       if (bin_count == 0) {
+               DRM_ERROR("Unable to add secondary DMA buffers: %d\n", err);
+               return err;
+       }
+
+       if (bin_count != dma_bs->secondary_bin_count) {
+               DRM_INFO("Secondary PCI DMA buffer bin count reduced from %u "
+                        "to %u.\n", dma_bs->secondary_bin_count, bin_count);
+
+               dma_bs->secondary_bin_count = bin_count;
+       }
+
+       dev_priv->dma_access = 0;
+       dev_priv->wagp_enable = 0;
+
+       dma_bs->agp_mode = 0;
+
+       DRM_INFO("Initialized card for PCI DMA.\n");
+       return 0;
+}
+
+static int mga_do_dma_bootstrap(struct drm_device * dev,
+                               drm_mga_dma_bootstrap_t * dma_bs)
+{
+       const int is_agp = (dma_bs->agp_mode != 0) && drm_device_is_agp(dev);
+       int err;
+       drm_mga_private_t *const dev_priv =
+           (drm_mga_private_t *) dev->dev_private;
+
+       dev_priv->used_new_dma_init = 1;
+
+       /* The first steps are the same for both PCI and AGP based DMA.  Map
+        * the cards MMIO registers and map a status page.
+        */
+       err = drm_addmap(dev, dev_priv->mmio_base, dev_priv->mmio_size,
+                        _DRM_REGISTERS, _DRM_READ_ONLY, &dev_priv->mmio);
+       if (err) {
+               DRM_ERROR("Unable to map MMIO region: %d\n", err);
+               return err;
+       }
+
+       err = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
+                        _DRM_READ_ONLY | _DRM_LOCKED | _DRM_KERNEL,
+                        &dev_priv->status);
+       if (err) {
+               DRM_ERROR("Unable to map status region: %d\n", err);
+               return err;
+       }
+
+       /* The DMA initialization procedure is slightly different for PCI and
+        * AGP cards.  AGP cards just allocate a large block of AGP memory and
+        * carve off portions of it for internal uses.  The remaining memory
+        * is returned to user-mode to be used for AGP textures.
+        */
+       if (is_agp) {
+               err = mga_do_agp_dma_bootstrap(dev, dma_bs);
+       }
+
+       /* If we attempted to initialize the card for AGP DMA but failed,
+        * clean-up any mess that may have been created.
+        */
+
+       if (err) {
+               mga_do_cleanup_dma(dev, MINIMAL_CLEANUP);
+       }
+
+       /* Not only do we want to try and initialized PCI cards for PCI DMA,
+        * but we also try to initialized AGP cards that could not be
+        * initialized for AGP DMA.  This covers the case where we have an AGP
+        * card in a system with an unsupported AGP chipset.  In that case the
+        * card will be detected as AGP, but we won't be able to allocate any
+        * AGP memory, etc.
+        */
+
+       if (!is_agp || err) {
+               err = mga_do_pci_dma_bootstrap(dev, dma_bs);
+       }
+
+       return err;
+}
+
+int mga_dma_bootstrap(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv)
+{
+       drm_mga_dma_bootstrap_t *bootstrap = data;
+       int err;
+       static const int modes[] = { 0, 1, 2, 2, 4, 4, 4, 4 };
+       const drm_mga_private_t *const dev_priv =
+               (drm_mga_private_t *) dev->dev_private;
+
+       err = mga_do_dma_bootstrap(dev, bootstrap);
+       if (err) {
+               mga_do_cleanup_dma(dev, FULL_CLEANUP);
+               return err;
+       }
+
+       if (dev_priv->agp_textures != NULL) {
+               bootstrap->texture_handle = dev_priv->agp_textures->offset;
+               bootstrap->texture_size = dev_priv->agp_textures->size;
+       } else {
+               bootstrap->texture_handle = 0;
+               bootstrap->texture_size = 0;
+       }
+
+       bootstrap->agp_mode = modes[bootstrap->agp_mode & 0x07];
+
+       return err;
+}
+
+static int mga_do_init_dma(struct drm_device * dev, drm_mga_init_t * init)
+{
+       drm_mga_private_t *dev_priv;
+       int ret;
+       DRM_DEBUG("\n");
+
+       dev_priv = dev->dev_private;
+
+       if (init->sgram) {
+               dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_BLK;
+       } else {
+               dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
+       }
+       dev_priv->maccess = init->maccess;
+
+       dev_priv->fb_cpp = init->fb_cpp;
+       dev_priv->front_offset = init->front_offset;
+       dev_priv->front_pitch = init->front_pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->back_pitch = init->back_pitch;
+
+       dev_priv->depth_cpp = init->depth_cpp;
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->depth_pitch = init->depth_pitch;
+
+       /* FIXME: Need to support AGP textures...
+        */
+       dev_priv->texture_offset = init->texture_offset[0];
+       dev_priv->texture_size = init->texture_size[0];
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("failed to find sarea!\n");
+               return -EINVAL;
+       }
+
+       if (!dev_priv->used_new_dma_init) {
+
+               dev_priv->dma_access = MGA_PAGPXFER;
+               dev_priv->wagp_enable = MGA_WAGP_ENABLE;
+
+               dev_priv->status = drm_core_findmap(dev, init->status_offset);
+               if (!dev_priv->status) {
+                       DRM_ERROR("failed to find status page!\n");
+                       return -EINVAL;
+               }
+               dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
+               if (!dev_priv->mmio) {
+                       DRM_ERROR("failed to find mmio region!\n");
+                       return -EINVAL;
+               }
+               dev_priv->warp = drm_core_findmap(dev, init->warp_offset);
+               if (!dev_priv->warp) {
+                       DRM_ERROR("failed to find warp microcode region!\n");
+                       return -EINVAL;
+               }
+               dev_priv->primary = drm_core_findmap(dev, init->primary_offset);
+               if (!dev_priv->primary) {
+                       DRM_ERROR("failed to find primary dma region!\n");
+                       return -EINVAL;
+               }
+               dev->agp_buffer_token = init->buffers_offset;
+               dev->agp_buffer_map =
+                   drm_core_findmap(dev, init->buffers_offset);
+               if (!dev->agp_buffer_map) {
+                       DRM_ERROR("failed to find dma buffer region!\n");
+                       return -EINVAL;
+               }
+
+               drm_core_ioremap(dev_priv->warp, dev);
+               drm_core_ioremap(dev_priv->primary, dev);
+               drm_core_ioremap(dev->agp_buffer_map, dev);
+       }
+
+       dev_priv->sarea_priv =
+           (drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle +
+                                init->sarea_priv_offset);
+
+       if (!dev_priv->warp->handle ||
+           !dev_priv->primary->handle ||
+           ((dev_priv->dma_access != 0) &&
+            ((dev->agp_buffer_map == NULL) ||
+             (dev->agp_buffer_map->handle == NULL)))) {
+               DRM_ERROR("failed to ioremap agp regions!\n");
+               return -ENOMEM;
+       }
+
+       ret = mga_warp_install_microcode(dev_priv);
+       if (ret < 0) {
+               DRM_ERROR("failed to install WARP ucode!: %d\n", ret);
+               return ret;
+       }
+
+       ret = mga_warp_init(dev_priv);
+       if (ret < 0) {
+               DRM_ERROR("failed to init WARP engine!: %d\n", ret);
+               return ret;
+       }
+
+       dev_priv->prim.status = (u32 *) dev_priv->status->handle;
+
+       mga_do_wait_for_idle(dev_priv);
+
+       /* Init the primary DMA registers.
+        */
+       MGA_WRITE(MGA_PRIMADDRESS, dev_priv->primary->offset | MGA_DMA_GENERAL);
+#if 0
+       MGA_WRITE(MGA_PRIMPTR, virt_to_bus((void *)dev_priv->prim.status) | MGA_PRIMPTREN0 |    /* Soft trap, SECEND, SETUPEND */
+                 MGA_PRIMPTREN1);      /* DWGSYNC */
+#endif
+
+       dev_priv->prim.start = (u8 *) dev_priv->primary->handle;
+       dev_priv->prim.end = ((u8 *) dev_priv->primary->handle
+                             + dev_priv->primary->size);
+       dev_priv->prim.size = dev_priv->primary->size;
+
+       dev_priv->prim.tail = 0;
+       dev_priv->prim.space = dev_priv->prim.size;
+       dev_priv->prim.wrapped = 0;
+
+       dev_priv->prim.last_flush = 0;
+       dev_priv->prim.last_wrap = 0;
+
+       dev_priv->prim.high_mark = 256 * DMA_BLOCK_SIZE;
+
+       dev_priv->prim.status[0] = dev_priv->primary->offset;
+       dev_priv->prim.status[1] = 0;
+
+       dev_priv->sarea_priv->last_wrap = 0;
+       dev_priv->sarea_priv->last_frame.head = 0;
+       dev_priv->sarea_priv->last_frame.wrap = 0;
+
+       if (mga_freelist_init(dev, dev_priv) < 0) {
+               DRM_ERROR("could not initialize freelist\n");
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static int mga_do_cleanup_dma(struct drm_device *dev, int full_cleanup)
+{
+       int err = 0;
+       DRM_DEBUG("\n");
+
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+       if (dev->dev_private) {
+               drm_mga_private_t *dev_priv = dev->dev_private;
+
+               if ((dev_priv->warp != NULL)
+                   && (dev_priv->warp->type != _DRM_CONSISTENT))
+                       drm_core_ioremapfree(dev_priv->warp, dev);
+
+               if ((dev_priv->primary != NULL)
+                   && (dev_priv->primary->type != _DRM_CONSISTENT))
+                       drm_core_ioremapfree(dev_priv->primary, dev);
+
+               if (dev->agp_buffer_map != NULL)
+                       drm_core_ioremapfree(dev->agp_buffer_map, dev);
+
+               if (dev_priv->used_new_dma_init) {
+#if __OS_HAS_AGP
+                       if (dev_priv->agp_handle != 0) {
+                               struct drm_agp_binding unbind_req;
+                               struct drm_agp_buffer free_req;
+
+                               unbind_req.handle = dev_priv->agp_handle;
+                               drm_agp_unbind(dev, &unbind_req);
+
+                               free_req.handle = dev_priv->agp_handle;
+                               drm_agp_free(dev, &free_req);
+
+                               dev_priv->agp_textures = NULL;
+                               dev_priv->agp_size = 0;
+                               dev_priv->agp_handle = 0;
+                       }
+
+                       if ((dev->agp != NULL) && dev->agp->acquired) {
+                               err = drm_agp_release(dev);
+                       }
+#endif
+               }
+
+               dev_priv->warp = NULL;
+               dev_priv->primary = NULL;
+               dev_priv->sarea = NULL;
+               dev_priv->sarea_priv = NULL;
+               dev->agp_buffer_map = NULL;
+
+               if (full_cleanup) {
+                       dev_priv->mmio = NULL;
+                       dev_priv->status = NULL;
+                       dev_priv->used_new_dma_init = 0;
+               }
+
+               memset(&dev_priv->prim, 0, sizeof(dev_priv->prim));
+               dev_priv->warp_pipe = 0;
+               memset(dev_priv->warp_pipe_phys, 0,
+                      sizeof(dev_priv->warp_pipe_phys));
+
+               if (dev_priv->head != NULL) {
+                       mga_freelist_cleanup(dev);
+               }
+       }
+
+       return err;
+}
+
+int mga_dma_init(struct drm_device *dev, void *data,
+                struct drm_file *file_priv)
+{
+       drm_mga_init_t *init = data;
+       int err;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       switch (init->func) {
+       case MGA_INIT_DMA:
+               err = mga_do_init_dma(dev, init);
+               if (err) {
+                       (void)mga_do_cleanup_dma(dev, FULL_CLEANUP);
+               }
+               return err;
+       case MGA_CLEANUP_DMA:
+               return mga_do_cleanup_dma(dev, FULL_CLEANUP);
+       }
+
+       return -EINVAL;
+}
+
+/* ================================================================
+ * Primary DMA stream management
+ */
+
+int mga_dma_flush(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+       struct drm_lock *lock = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("%s%s%s\n",
+                 (lock->flags & _DRM_LOCK_FLUSH) ? "flush, " : "",
+                 (lock->flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "",
+                 (lock->flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "");
+
+       WRAP_WAIT_WITH_RETURN(dev_priv);
+
+       if (lock->flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL)) {
+               mga_do_dma_flush(dev_priv);
+       }
+
+       if (lock->flags & _DRM_LOCK_QUIESCENT) {
+#if MGA_DMA_DEBUG
+               int ret = mga_do_wait_for_idle(dev_priv);
+               if (ret < 0)
+                       DRM_INFO("-EBUSY\n");
+               return ret;
+#else
+               return mga_do_wait_for_idle(dev_priv);
+#endif
+       } else {
+               return 0;
+       }
+}
+
+int mga_dma_reset(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return mga_do_dma_reset(dev_priv);
+}
+
+/* ================================================================
+ * DMA buffer management
+ */
+
+static int mga_dma_get_buffers(struct drm_device * dev,
+                              struct drm_file *file_priv, struct drm_dma * d)
+{
+       struct drm_buf *buf;
+       int i;
+
+       for (i = d->granted_count; i < d->request_count; i++) {
+               buf = mga_freelist_get(dev);
+               if (!buf)
+                       return -EAGAIN;
+
+               buf->file_priv = file_priv;
+
+               if (DRM_COPY_TO_USER(&d->request_indices[i],
+                                    &buf->idx, sizeof(buf->idx)))
+                       return -EFAULT;
+               if (DRM_COPY_TO_USER(&d->request_sizes[i],
+                                    &buf->total, sizeof(buf->total)))
+                       return -EFAULT;
+
+               d->granted_count++;
+       }
+       return 0;
+}
+
+int mga_dma_buffers(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+       struct drm_dma *d = data;
+       int ret = 0;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* Please don't send us buffers.
+        */
+       if (d->send_count != 0) {
+               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
+                         DRM_CURRENTPID, d->send_count);
+               return -EINVAL;
+       }
+
+       /* We'll send you buffers.
+        */
+       if (d->request_count < 0 || d->request_count > dma->buf_count) {
+               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
+                         DRM_CURRENTPID, d->request_count, dma->buf_count);
+               return -EINVAL;
+       }
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       d->granted_count = 0;
+
+       if (d->request_count) {
+               ret = mga_dma_get_buffers(dev, file_priv, d);
+       }
+
+       return ret;
+}
+
+/**
+ * Called just before the module is unloaded.
+ */
+int mga_driver_unload(struct drm_device * dev)
+{
+       drm_free(dev->dev_private, sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
+       dev->dev_private = NULL;
+
+       return 0;
+}
+
+/**
+ * Called when the last opener of the device is closed.
+ */
+void mga_driver_lastclose(struct drm_device * dev)
+{
+       mga_do_cleanup_dma(dev, FULL_CLEANUP);
+}
+
+int mga_driver_dma_quiescent(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       return mga_do_wait_for_idle(dev_priv);
+}
diff --git a/drivers/gpu/drm/mga/mga_drv.c b/drivers/gpu/drm/mga/mga_drv.c
new file mode 100644 (file)
index 0000000..5572939
--- /dev/null
@@ -0,0 +1,141 @@
+/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "mga_drm.h"
+#include "mga_drv.h"
+
+#include "drm_pciids.h"
+
+static int mga_driver_device_is_agp(struct drm_device * dev);
+
+static struct pci_device_id pciidlist[] = {
+       mga_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
+           DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
+           DRIVER_IRQ_VBL,
+       .dev_priv_size = sizeof(drm_mga_buf_priv_t),
+       .load = mga_driver_load,
+       .unload = mga_driver_unload,
+       .lastclose = mga_driver_lastclose,
+       .dma_quiescent = mga_driver_dma_quiescent,
+       .device_is_agp = mga_driver_device_is_agp,
+       .vblank_wait = mga_driver_vblank_wait,
+       .irq_preinstall = mga_driver_irq_preinstall,
+       .irq_postinstall = mga_driver_irq_postinstall,
+       .irq_uninstall = mga_driver_irq_uninstall,
+       .irq_handler = mga_driver_irq_handler,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = mga_ioctls,
+       .dma_ioctl = mga_dma_buffers,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+                .compat_ioctl = mga_compat_ioctl,
+#endif
+                },
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init mga_init(void)
+{
+       driver.num_ioctls = mga_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit mga_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(mga_init);
+module_exit(mga_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
+
+/**
+ * Determine if the device really is AGP or not.
+ *
+ * In addition to the usual tests performed by \c drm_device_is_agp, this
+ * function detects PCI G450 cards that appear to the system exactly like
+ * AGP G450 cards.
+ *
+ * \param dev   The device to be tested.
+ *
+ * \returns
+ * If the device is a PCI G450, zero is returned.  Otherwise 2 is returned.
+ */
+static int mga_driver_device_is_agp(struct drm_device * dev)
+{
+       const struct pci_dev *const pdev = dev->pdev;
+
+       /* There are PCI versions of the G450.  These cards have the
+        * same PCI ID as the AGP G450, but have an additional PCI-to-PCI
+        * bridge chip.  We detect these cards, which are not currently
+        * supported by this driver, by looking at the device ID of the
+        * bus the "card" is on.  If vendor is 0x3388 (Hint Corp) and the
+        * device is 0x0021 (HB6 Universal PCI-PCI bridge), we reject the
+        * device.
+        */
+
+       if ((pdev->device == 0x0525) && pdev->bus->self
+           && (pdev->bus->self->vendor == 0x3388)
+           && (pdev->bus->self->device == 0x0021)) {
+               return 0;
+       }
+
+       return 2;
+}
diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
new file mode 100644 (file)
index 0000000..f6ebd24
--- /dev/null
@@ -0,0 +1,687 @@
+/* mga_drv.h -- Private header for the Matrox G200/G400 driver -*- linux-c -*-
+ * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#ifndef __MGA_DRV_H__
+#define __MGA_DRV_H__
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "Gareth Hughes, VA Linux Systems Inc."
+
+#define DRIVER_NAME            "mga"
+#define DRIVER_DESC            "Matrox G200/G400"
+#define DRIVER_DATE            "20051102"
+
+#define DRIVER_MAJOR           3
+#define DRIVER_MINOR           2
+#define DRIVER_PATCHLEVEL      1
+
+typedef struct drm_mga_primary_buffer {
+       u8 *start;
+       u8 *end;
+       int size;
+
+       u32 tail;
+       int space;
+       volatile long wrapped;
+
+       volatile u32 *status;
+
+       u32 last_flush;
+       u32 last_wrap;
+
+       u32 high_mark;
+} drm_mga_primary_buffer_t;
+
+typedef struct drm_mga_freelist {
+       struct drm_mga_freelist *next;
+       struct drm_mga_freelist *prev;
+       drm_mga_age_t age;
+       struct drm_buf *buf;
+} drm_mga_freelist_t;
+
+typedef struct {
+       drm_mga_freelist_t *list_entry;
+       int discard;
+       int dispatched;
+} drm_mga_buf_priv_t;
+
+typedef struct drm_mga_private {
+       drm_mga_primary_buffer_t prim;
+       drm_mga_sarea_t *sarea_priv;
+
+       drm_mga_freelist_t *head;
+       drm_mga_freelist_t *tail;
+
+       unsigned int warp_pipe;
+       unsigned long warp_pipe_phys[MGA_MAX_WARP_PIPES];
+
+       int chipset;
+       int usec_timeout;
+
+       /**
+        * If set, the new DMA initialization sequence was used.  This is
+        * primarilly used to select how the driver should uninitialized its
+        * internal DMA structures.
+        */
+       int used_new_dma_init;
+
+       /**
+        * If AGP memory is used for DMA buffers, this will be the value
+        * \c MGA_PAGPXFER.  Otherwise, it will be zero (for a PCI transfer).
+        */
+       u32 dma_access;
+
+       /**
+        * If AGP memory is used for DMA buffers, this will be the value
+        * \c MGA_WAGP_ENABLE.  Otherwise, it will be zero (for a PCI
+        * transfer).
+        */
+       u32 wagp_enable;
+
+       /**
+        * \name MMIO region parameters.
+        *
+        * \sa drm_mga_private_t::mmio
+        */
+       /*@{ */
+       u32 mmio_base;             /**< Bus address of base of MMIO. */
+       u32 mmio_size;             /**< Size of the MMIO region. */
+       /*@} */
+
+       u32 clear_cmd;
+       u32 maccess;
+
+       wait_queue_head_t fence_queue;
+       atomic_t last_fence_retired;
+       u32 next_fence_to_post;
+
+       unsigned int fb_cpp;
+       unsigned int front_offset;
+       unsigned int front_pitch;
+       unsigned int back_offset;
+       unsigned int back_pitch;
+
+       unsigned int depth_cpp;
+       unsigned int depth_offset;
+       unsigned int depth_pitch;
+
+       unsigned int texture_offset;
+       unsigned int texture_size;
+
+       drm_local_map_t *sarea;
+       drm_local_map_t *mmio;
+       drm_local_map_t *status;
+       drm_local_map_t *warp;
+       drm_local_map_t *primary;
+       drm_local_map_t *agp_textures;
+
+       unsigned long agp_handle;
+       unsigned int agp_size;
+} drm_mga_private_t;
+
+extern struct drm_ioctl_desc mga_ioctls[];
+extern int mga_max_ioctl;
+
+                               /* mga_dma.c */
+extern int mga_dma_bootstrap(struct drm_device *dev, void *data,
+                            struct drm_file *file_priv);
+extern int mga_dma_init(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int mga_dma_flush(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int mga_dma_reset(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int mga_dma_buffers(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+extern int mga_driver_load(struct drm_device *dev, unsigned long flags);
+extern int mga_driver_unload(struct drm_device * dev);
+extern void mga_driver_lastclose(struct drm_device * dev);
+extern int mga_driver_dma_quiescent(struct drm_device * dev);
+
+extern int mga_do_wait_for_idle(drm_mga_private_t * dev_priv);
+
+extern void mga_do_dma_flush(drm_mga_private_t * dev_priv);
+extern void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv);
+extern void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv);
+
+extern int mga_freelist_put(struct drm_device * dev, struct drm_buf * buf);
+
+                               /* mga_warp.c */
+extern unsigned int mga_warp_microcode_size(const drm_mga_private_t * dev_priv);
+extern int mga_warp_install_microcode(drm_mga_private_t * dev_priv);
+extern int mga_warp_init(drm_mga_private_t * dev_priv);
+
+                               /* mga_irq.c */
+extern int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence);
+extern int mga_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
+extern irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS);
+extern void mga_driver_irq_preinstall(struct drm_device * dev);
+extern void mga_driver_irq_postinstall(struct drm_device * dev);
+extern void mga_driver_irq_uninstall(struct drm_device * dev);
+extern long mga_compat_ioctl(struct file *filp, unsigned int cmd,
+                            unsigned long arg);
+
+#define mga_flush_write_combine()      DRM_WRITEMEMORYBARRIER()
+
+#if defined(__linux__) && defined(__alpha__)
+#define MGA_BASE( reg )                ((unsigned long)(dev_priv->mmio->handle))
+#define MGA_ADDR( reg )                (MGA_BASE(reg) + reg)
+
+#define MGA_DEREF( reg )       *(volatile u32 *)MGA_ADDR( reg )
+#define MGA_DEREF8( reg )      *(volatile u8 *)MGA_ADDR( reg )
+
+#define MGA_READ( reg )                (_MGA_READ((u32 *)MGA_ADDR(reg)))
+#define MGA_READ8( reg )       (_MGA_READ((u8 *)MGA_ADDR(reg)))
+#define MGA_WRITE( reg, val )  do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF( reg ) = val; } while (0)
+#define MGA_WRITE8( reg, val )  do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF8( reg ) = val; } while (0)
+
+static inline u32 _MGA_READ(u32 * addr)
+{
+       DRM_MEMORYBARRIER();
+       return *(volatile u32 *)addr;
+}
+#else
+#define MGA_READ8( reg )       DRM_READ8(dev_priv->mmio, (reg))
+#define MGA_READ( reg )                DRM_READ32(dev_priv->mmio, (reg))
+#define MGA_WRITE8( reg, val )  DRM_WRITE8(dev_priv->mmio, (reg), (val))
+#define MGA_WRITE( reg, val )  DRM_WRITE32(dev_priv->mmio, (reg), (val))
+#endif
+
+#define DWGREG0                0x1c00
+#define DWGREG0_END    0x1dff
+#define DWGREG1                0x2c00
+#define DWGREG1_END    0x2dff
+
+#define ISREG0(r)      (r >= DWGREG0 && r <= DWGREG0_END)
+#define DMAREG0(r)     (u8)((r - DWGREG0) >> 2)
+#define DMAREG1(r)     (u8)(((r - DWGREG1) >> 2) | 0x80)
+#define DMAREG(r)      (ISREG0(r) ? DMAREG0(r) : DMAREG1(r))
+
+/* ================================================================
+ * Helper macross...
+ */
+
+#define MGA_EMIT_STATE( dev_priv, dirty )                              \
+do {                                                                   \
+       if ( (dirty) & ~MGA_UPLOAD_CLIPRECTS ) {                        \
+               if ( dev_priv->chipset >= MGA_CARD_TYPE_G400 ) {        \
+                       mga_g400_emit_state( dev_priv );                \
+               } else {                                                \
+                       mga_g200_emit_state( dev_priv );                \
+               }                                                       \
+       }                                                               \
+} while (0)
+
+#define WRAP_TEST_WITH_RETURN( dev_priv )                              \
+do {                                                                   \
+       if ( test_bit( 0, &dev_priv->prim.wrapped ) ) {                 \
+               if ( mga_is_idle( dev_priv ) ) {                        \
+                       mga_do_dma_wrap_end( dev_priv );                \
+               } else if ( dev_priv->prim.space <                      \
+                           dev_priv->prim.high_mark ) {                \
+                       if ( MGA_DMA_DEBUG )                            \
+                               DRM_INFO( "wrap...\n");         \
+                       return -EBUSY;                  \
+               }                                                       \
+       }                                                               \
+} while (0)
+
+#define WRAP_WAIT_WITH_RETURN( dev_priv )                              \
+do {                                                                   \
+       if ( test_bit( 0, &dev_priv->prim.wrapped ) ) {                 \
+               if ( mga_do_wait_for_idle( dev_priv ) < 0 ) {           \
+                       if ( MGA_DMA_DEBUG )                            \
+                               DRM_INFO( "wrap...\n");         \
+                       return -EBUSY;                  \
+               }                                                       \
+               mga_do_dma_wrap_end( dev_priv );                        \
+       }                                                               \
+} while (0)
+
+/* ================================================================
+ * Primary DMA command stream
+ */
+
+#define MGA_VERBOSE    0
+
+#define DMA_LOCALS     unsigned int write; volatile u8 *prim;
+
+#define DMA_BLOCK_SIZE (5 * sizeof(u32))
+
+#define BEGIN_DMA( n )                                                 \
+do {                                                                   \
+       if ( MGA_VERBOSE ) {                                            \
+               DRM_INFO( "BEGIN_DMA( %d )\n", (n) );           \
+               DRM_INFO( "   space=0x%x req=0x%Zx\n",                  \
+                         dev_priv->prim.space, (n) * DMA_BLOCK_SIZE ); \
+       }                                                               \
+       prim = dev_priv->prim.start;                                    \
+       write = dev_priv->prim.tail;                                    \
+} while (0)
+
+#define BEGIN_DMA_WRAP()                                               \
+do {                                                                   \
+       if ( MGA_VERBOSE ) {                                            \
+               DRM_INFO( "BEGIN_DMA()\n" );                            \
+               DRM_INFO( "   space=0x%x\n", dev_priv->prim.space );    \
+       }                                                               \
+       prim = dev_priv->prim.start;                                    \
+       write = dev_priv->prim.tail;                                    \
+} while (0)
+
+#define ADVANCE_DMA()                                                  \
+do {                                                                   \
+       dev_priv->prim.tail = write;                                    \
+       if ( MGA_VERBOSE ) {                                            \
+               DRM_INFO( "ADVANCE_DMA() tail=0x%05x sp=0x%x\n",        \
+                         write, dev_priv->prim.space );                \
+       }                                                               \
+} while (0)
+
+#define FLUSH_DMA()                                                    \
+do {                                                                   \
+       if ( 0 ) {                                                      \
+               DRM_INFO( "\n" );                                       \
+               DRM_INFO( "   tail=0x%06x head=0x%06lx\n",              \
+                         dev_priv->prim.tail,                          \
+                         MGA_READ( MGA_PRIMADDRESS ) -                 \
+                         dev_priv->primary->offset );                  \
+       }                                                               \
+       if ( !test_bit( 0, &dev_priv->prim.wrapped ) ) {                \
+               if ( dev_priv->prim.space <                             \
+                    dev_priv->prim.high_mark ) {                       \
+                       mga_do_dma_wrap_start( dev_priv );              \
+               } else {                                                \
+                       mga_do_dma_flush( dev_priv );                   \
+               }                                                       \
+       }                                                               \
+} while (0)
+
+/* Never use this, always use DMA_BLOCK(...) for primary DMA output.
+ */
+#define DMA_WRITE( offset, val )                                       \
+do {                                                                   \
+       if ( MGA_VERBOSE ) {                                            \
+               DRM_INFO( "   DMA_WRITE( 0x%08x ) at 0x%04Zx\n",        \
+                         (u32)(val), write + (offset) * sizeof(u32) ); \
+       }                                                               \
+       *(volatile u32 *)(prim + write + (offset) * sizeof(u32)) = val; \
+} while (0)
+
+#define DMA_BLOCK( reg0, val0, reg1, val1, reg2, val2, reg3, val3 )    \
+do {                                                                   \
+       DMA_WRITE( 0, ((DMAREG( reg0 ) << 0) |                          \
+                      (DMAREG( reg1 ) << 8) |                          \
+                      (DMAREG( reg2 ) << 16) |                         \
+                      (DMAREG( reg3 ) << 24)) );                       \
+       DMA_WRITE( 1, val0 );                                           \
+       DMA_WRITE( 2, val1 );                                           \
+       DMA_WRITE( 3, val2 );                                           \
+       DMA_WRITE( 4, val3 );                                           \
+       write += DMA_BLOCK_SIZE;                                        \
+} while (0)
+
+/* Buffer aging via primary DMA stream head pointer.
+ */
+
+#define SET_AGE( age, h, w )                                           \
+do {                                                                   \
+       (age)->head = h;                                                \
+       (age)->wrap = w;                                                \
+} while (0)
+
+#define TEST_AGE( age, h, w )          ( (age)->wrap < w ||            \
+                                         ( (age)->wrap == w &&         \
+                                           (age)->head < h ) )
+
+#define AGE_BUFFER( buf_priv )                                         \
+do {                                                                   \
+       drm_mga_freelist_t *entry = (buf_priv)->list_entry;             \
+       if ( (buf_priv)->dispatched ) {                                 \
+               entry->age.head = (dev_priv->prim.tail +                \
+                                  dev_priv->primary->offset);          \
+               entry->age.wrap = dev_priv->sarea_priv->last_wrap;      \
+       } else {                                                        \
+               entry->age.head = 0;                                    \
+               entry->age.wrap = 0;                                    \
+       }                                                               \
+} while (0)
+
+#define MGA_ENGINE_IDLE_MASK           (MGA_SOFTRAPEN |                \
+                                        MGA_DWGENGSTS |                \
+                                        MGA_ENDPRDMASTS)
+#define MGA_DMA_IDLE_MASK              (MGA_SOFTRAPEN |                \
+                                        MGA_ENDPRDMASTS)
+
+#define MGA_DMA_DEBUG                  0
+
+/* A reduced set of the mga registers.
+ */
+#define MGA_CRTC_INDEX                 0x1fd4
+#define MGA_CRTC_DATA                  0x1fd5
+
+/* CRTC11 */
+#define MGA_VINTCLR                    (1 << 4)
+#define MGA_VINTEN                     (1 << 5)
+
+#define MGA_ALPHACTRL                  0x2c7c
+#define MGA_AR0                                0x1c60
+#define MGA_AR1                                0x1c64
+#define MGA_AR2                                0x1c68
+#define MGA_AR3                                0x1c6c
+#define MGA_AR4                                0x1c70
+#define MGA_AR5                                0x1c74
+#define MGA_AR6                                0x1c78
+
+#define MGA_CXBNDRY                    0x1c80
+#define MGA_CXLEFT                     0x1ca0
+#define MGA_CXRIGHT                    0x1ca4
+
+#define MGA_DMAPAD                     0x1c54
+#define MGA_DSTORG                     0x2cb8
+#define MGA_DWGCTL                     0x1c00
+#      define MGA_OPCOD_MASK                   (15 << 0)
+#      define MGA_OPCOD_TRAP                   (4 << 0)
+#      define MGA_OPCOD_TEXTURE_TRAP           (6 << 0)
+#      define MGA_OPCOD_BITBLT                 (8 << 0)
+#      define MGA_OPCOD_ILOAD                  (9 << 0)
+#      define MGA_ATYPE_MASK                   (7 << 4)
+#      define MGA_ATYPE_RPL                    (0 << 4)
+#      define MGA_ATYPE_RSTR                   (1 << 4)
+#      define MGA_ATYPE_ZI                     (3 << 4)
+#      define MGA_ATYPE_BLK                    (4 << 4)
+#      define MGA_ATYPE_I                      (7 << 4)
+#      define MGA_LINEAR                       (1 << 7)
+#      define MGA_ZMODE_MASK                   (7 << 8)
+#      define MGA_ZMODE_NOZCMP                 (0 << 8)
+#      define MGA_ZMODE_ZE                     (2 << 8)
+#      define MGA_ZMODE_ZNE                    (3 << 8)
+#      define MGA_ZMODE_ZLT                    (4 << 8)
+#      define MGA_ZMODE_ZLTE                   (5 << 8)
+#      define MGA_ZMODE_ZGT                    (6 << 8)
+#      define MGA_ZMODE_ZGTE                   (7 << 8)
+#      define MGA_SOLID                        (1 << 11)
+#      define MGA_ARZERO                       (1 << 12)
+#      define MGA_SGNZERO                      (1 << 13)
+#      define MGA_SHIFTZERO                    (1 << 14)
+#      define MGA_BOP_MASK                     (15 << 16)
+#      define MGA_BOP_ZERO                     (0 << 16)
+#      define MGA_BOP_DST                      (10 << 16)
+#      define MGA_BOP_SRC                      (12 << 16)
+#      define MGA_BOP_ONE                      (15 << 16)
+#      define MGA_TRANS_SHIFT                  20
+#      define MGA_TRANS_MASK                   (15 << 20)
+#      define MGA_BLTMOD_MASK                  (15 << 25)
+#      define MGA_BLTMOD_BMONOLEF              (0 << 25)
+#      define MGA_BLTMOD_BMONOWF               (4 << 25)
+#      define MGA_BLTMOD_PLAN                  (1 << 25)
+#      define MGA_BLTMOD_BFCOL                 (2 << 25)
+#      define MGA_BLTMOD_BU32BGR               (3 << 25)
+#      define MGA_BLTMOD_BU32RGB               (7 << 25)
+#      define MGA_BLTMOD_BU24BGR               (11 << 25)
+#      define MGA_BLTMOD_BU24RGB               (15 << 25)
+#      define MGA_PATTERN                      (1 << 29)
+#      define MGA_TRANSC                       (1 << 30)
+#      define MGA_CLIPDIS                      (1 << 31)
+#define MGA_DWGSYNC                    0x2c4c
+
+#define MGA_FCOL                       0x1c24
+#define MGA_FIFOSTATUS                 0x1e10
+#define MGA_FOGCOL                     0x1cf4
+#define MGA_FXBNDRY                    0x1c84
+#define MGA_FXLEFT                     0x1ca8
+#define MGA_FXRIGHT                    0x1cac
+
+#define MGA_ICLEAR                     0x1e18
+#      define MGA_SOFTRAPICLR                  (1 << 0)
+#      define MGA_VLINEICLR                    (1 << 5)
+#define MGA_IEN                                0x1e1c
+#      define MGA_SOFTRAPIEN                   (1 << 0)
+#      define MGA_VLINEIEN                     (1 << 5)
+
+#define MGA_LEN                                0x1c5c
+
+#define MGA_MACCESS                    0x1c04
+
+#define MGA_PITCH                      0x1c8c
+#define MGA_PLNWT                      0x1c1c
+#define MGA_PRIMADDRESS                        0x1e58
+#      define MGA_DMA_GENERAL                  (0 << 0)
+#      define MGA_DMA_BLIT                     (1 << 0)
+#      define MGA_DMA_VECTOR                   (2 << 0)
+#      define MGA_DMA_VERTEX                   (3 << 0)
+#define MGA_PRIMEND                    0x1e5c
+#      define MGA_PRIMNOSTART                  (1 << 0)
+#      define MGA_PAGPXFER                     (1 << 1)
+#define MGA_PRIMPTR                    0x1e50
+#      define MGA_PRIMPTREN0                   (1 << 0)
+#      define MGA_PRIMPTREN1                   (1 << 1)
+
+#define MGA_RST                                0x1e40
+#      define MGA_SOFTRESET                    (1 << 0)
+#      define MGA_SOFTEXTRST                   (1 << 1)
+
+#define MGA_SECADDRESS                 0x2c40
+#define MGA_SECEND                     0x2c44
+#define MGA_SETUPADDRESS               0x2cd0
+#define MGA_SETUPEND                   0x2cd4
+#define MGA_SGN                                0x1c58
+#define MGA_SOFTRAP                    0x2c48
+#define MGA_SRCORG                     0x2cb4
+#      define MGA_SRMMAP_MASK                  (1 << 0)
+#      define MGA_SRCMAP_FB                    (0 << 0)
+#      define MGA_SRCMAP_SYSMEM                (1 << 0)
+#      define MGA_SRCACC_MASK                  (1 << 1)
+#      define MGA_SRCACC_PCI                   (0 << 1)
+#      define MGA_SRCACC_AGP                   (1 << 1)
+#define MGA_STATUS                     0x1e14
+#      define MGA_SOFTRAPEN                    (1 << 0)
+#      define MGA_VSYNCPEN                     (1 << 4)
+#      define MGA_VLINEPEN                     (1 << 5)
+#      define MGA_DWGENGSTS                    (1 << 16)
+#      define MGA_ENDPRDMASTS                  (1 << 17)
+#define MGA_STENCIL                    0x2cc8
+#define MGA_STENCILCTL                 0x2ccc
+
+#define MGA_TDUALSTAGE0                        0x2cf8
+#define MGA_TDUALSTAGE1                        0x2cfc
+#define MGA_TEXBORDERCOL               0x2c5c
+#define MGA_TEXCTL                     0x2c30
+#define MGA_TEXCTL2                    0x2c3c
+#      define MGA_DUALTEX                      (1 << 7)
+#      define MGA_G400_TC2_MAGIC               (1 << 15)
+#      define MGA_MAP1_ENABLE                  (1 << 31)
+#define MGA_TEXFILTER                  0x2c58
+#define MGA_TEXHEIGHT                  0x2c2c
+#define MGA_TEXORG                     0x2c24
+#      define MGA_TEXORGMAP_MASK               (1 << 0)
+#      define MGA_TEXORGMAP_FB                 (0 << 0)
+#      define MGA_TEXORGMAP_SYSMEM             (1 << 0)
+#      define MGA_TEXORGACC_MASK               (1 << 1)
+#      define MGA_TEXORGACC_PCI                (0 << 1)
+#      define MGA_TEXORGACC_AGP                (1 << 1)
+#define MGA_TEXORG1                    0x2ca4
+#define MGA_TEXORG2                    0x2ca8
+#define MGA_TEXORG3                    0x2cac
+#define MGA_TEXORG4                    0x2cb0
+#define MGA_TEXTRANS                   0x2c34
+#define MGA_TEXTRANSHIGH               0x2c38
+#define MGA_TEXWIDTH                   0x2c28
+
+#define MGA_WACCEPTSEQ                 0x1dd4
+#define MGA_WCODEADDR                  0x1e6c
+#define MGA_WFLAG                      0x1dc4
+#define MGA_WFLAG1                     0x1de0
+#define MGA_WFLAGNB                    0x1e64
+#define MGA_WFLAGNB1                   0x1e08
+#define MGA_WGETMSB                    0x1dc8
+#define MGA_WIADDR                     0x1dc0
+#define MGA_WIADDR2                    0x1dd8
+#      define MGA_WMODE_SUSPEND                (0 << 0)
+#      define MGA_WMODE_RESUME                 (1 << 0)
+#      define MGA_WMODE_JUMP                   (2 << 0)
+#      define MGA_WMODE_START                  (3 << 0)
+#      define MGA_WAGP_ENABLE                  (1 << 2)
+#define MGA_WMISC                      0x1e70
+#      define MGA_WUCODECACHE_ENABLE           (1 << 0)
+#      define MGA_WMASTER_ENABLE               (1 << 1)
+#      define MGA_WCACHEFLUSH_ENABLE           (1 << 3)
+#define MGA_WVRTXSZ                    0x1dcc
+
+#define MGA_YBOT                       0x1c9c
+#define MGA_YDST                       0x1c90
+#define MGA_YDSTLEN                    0x1c88
+#define MGA_YDSTORG                    0x1c94
+#define MGA_YTOP                       0x1c98
+
+#define MGA_ZORG                       0x1c0c
+
+/* This finishes the current batch of commands
+ */
+#define MGA_EXEC                       0x0100
+
+/* AGP PLL encoding (for G200 only).
+ */
+#define MGA_AGP_PLL                    0x1e4c
+#      define MGA_AGP2XPLL_DISABLE             (0 << 0)
+#      define MGA_AGP2XPLL_ENABLE              (1 << 0)
+
+/* Warp registers
+ */
+#define MGA_WR0                                0x2d00
+#define MGA_WR1                                0x2d04
+#define MGA_WR2                                0x2d08
+#define MGA_WR3                                0x2d0c
+#define MGA_WR4                                0x2d10
+#define MGA_WR5                                0x2d14
+#define MGA_WR6                                0x2d18
+#define MGA_WR7                                0x2d1c
+#define MGA_WR8                                0x2d20
+#define MGA_WR9                                0x2d24
+#define MGA_WR10                       0x2d28
+#define MGA_WR11                       0x2d2c
+#define MGA_WR12                       0x2d30
+#define MGA_WR13                       0x2d34
+#define MGA_WR14                       0x2d38
+#define MGA_WR15                       0x2d3c
+#define MGA_WR16                       0x2d40
+#define MGA_WR17                       0x2d44
+#define MGA_WR18                       0x2d48
+#define MGA_WR19                       0x2d4c
+#define MGA_WR20                       0x2d50
+#define MGA_WR21                       0x2d54
+#define MGA_WR22                       0x2d58
+#define MGA_WR23                       0x2d5c
+#define MGA_WR24                       0x2d60
+#define MGA_WR25                       0x2d64
+#define MGA_WR26                       0x2d68
+#define MGA_WR27                       0x2d6c
+#define MGA_WR28                       0x2d70
+#define MGA_WR29                       0x2d74
+#define MGA_WR30                       0x2d78
+#define MGA_WR31                       0x2d7c
+#define MGA_WR32                       0x2d80
+#define MGA_WR33                       0x2d84
+#define MGA_WR34                       0x2d88
+#define MGA_WR35                       0x2d8c
+#define MGA_WR36                       0x2d90
+#define MGA_WR37                       0x2d94
+#define MGA_WR38                       0x2d98
+#define MGA_WR39                       0x2d9c
+#define MGA_WR40                       0x2da0
+#define MGA_WR41                       0x2da4
+#define MGA_WR42                       0x2da8
+#define MGA_WR43                       0x2dac
+#define MGA_WR44                       0x2db0
+#define MGA_WR45                       0x2db4
+#define MGA_WR46                       0x2db8
+#define MGA_WR47                       0x2dbc
+#define MGA_WR48                       0x2dc0
+#define MGA_WR49                       0x2dc4
+#define MGA_WR50                       0x2dc8
+#define MGA_WR51                       0x2dcc
+#define MGA_WR52                       0x2dd0
+#define MGA_WR53                       0x2dd4
+#define MGA_WR54                       0x2dd8
+#define MGA_WR55                       0x2ddc
+#define MGA_WR56                       0x2de0
+#define MGA_WR57                       0x2de4
+#define MGA_WR58                       0x2de8
+#define MGA_WR59                       0x2dec
+#define MGA_WR60                       0x2df0
+#define MGA_WR61                       0x2df4
+#define MGA_WR62                       0x2df8
+#define MGA_WR63                       0x2dfc
+#      define MGA_G400_WR_MAGIC                (1 << 6)
+#      define MGA_G400_WR56_MAGIC              0x46480000      /* 12800.0f */
+
+#define MGA_ILOAD_ALIGN                64
+#define MGA_ILOAD_MASK         (MGA_ILOAD_ALIGN - 1)
+
+#define MGA_DWGCTL_FLUSH       (MGA_OPCOD_TEXTURE_TRAP |               \
+                                MGA_ATYPE_I |                          \
+                                MGA_ZMODE_NOZCMP |                     \
+                                MGA_ARZERO |                           \
+                                MGA_SGNZERO |                          \
+                                MGA_BOP_SRC |                          \
+                                (15 << MGA_TRANS_SHIFT))
+
+#define MGA_DWGCTL_CLEAR       (MGA_OPCOD_TRAP |                       \
+                                MGA_ZMODE_NOZCMP |                     \
+                                MGA_SOLID |                            \
+                                MGA_ARZERO |                           \
+                                MGA_SGNZERO |                          \
+                                MGA_SHIFTZERO |                        \
+                                MGA_BOP_SRC |                          \
+                                (0 << MGA_TRANS_SHIFT) |               \
+                                MGA_BLTMOD_BMONOLEF |                  \
+                                MGA_TRANSC |                           \
+                                MGA_CLIPDIS)
+
+#define MGA_DWGCTL_COPY                (MGA_OPCOD_BITBLT |                     \
+                                MGA_ATYPE_RPL |                        \
+                                MGA_SGNZERO |                          \
+                                MGA_SHIFTZERO |                        \
+                                MGA_BOP_SRC |                          \
+                                (0 << MGA_TRANS_SHIFT) |               \
+                                MGA_BLTMOD_BFCOL |                     \
+                                MGA_CLIPDIS)
+
+/* Simple idle test.
+ */
+static __inline__ int mga_is_idle(drm_mga_private_t * dev_priv)
+{
+       u32 status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
+       return (status == MGA_ENDPRDMASTS);
+}
+
+#endif
diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
new file mode 100644 (file)
index 0000000..30d0047
--- /dev/null
@@ -0,0 +1,231 @@
+/**
+ * \file mga_ioc32.c
+ *
+ * 32-bit ioctl compatibility routines for the MGA DRM.
+ *
+ * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
+ *
+ *
+ * Copyright (C) Paul Mackerras 2005
+ * Copyright (C) Egbert Eich 2003,2004
+ * Copyright (C) Dave Airlie 2005
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include <linux/compat.h>
+
+#include "drmP.h"
+#include "drm.h"
+#include "mga_drm.h"
+
+typedef struct drm32_mga_init {
+       int func;
+       u32 sarea_priv_offset;
+       int chipset;
+       int sgram;
+       unsigned int maccess;
+       unsigned int fb_cpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_cpp;
+       unsigned int depth_offset, depth_pitch;
+       unsigned int texture_offset[MGA_NR_TEX_HEAPS];
+       unsigned int texture_size[MGA_NR_TEX_HEAPS];
+       u32 fb_offset;
+       u32 mmio_offset;
+       u32 status_offset;
+       u32 warp_offset;
+       u32 primary_offset;
+       u32 buffers_offset;
+} drm_mga_init32_t;
+
+static int compat_mga_init(struct file *file, unsigned int cmd,
+                          unsigned long arg)
+{
+       drm_mga_init32_t init32;
+       drm_mga_init_t __user *init;
+       int err = 0, i;
+
+       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
+               return -EFAULT;
+
+       init = compat_alloc_user_space(sizeof(*init));
+       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
+           || __put_user(init32.func, &init->func)
+           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
+           || __put_user(init32.chipset, &init->chipset)
+           || __put_user(init32.sgram, &init->sgram)
+           || __put_user(init32.maccess, &init->maccess)
+           || __put_user(init32.fb_cpp, &init->fb_cpp)
+           || __put_user(init32.front_offset, &init->front_offset)
+           || __put_user(init32.front_pitch, &init->front_pitch)
+           || __put_user(init32.back_offset, &init->back_offset)
+           || __put_user(init32.back_pitch, &init->back_pitch)
+           || __put_user(init32.depth_cpp, &init->depth_cpp)
+           || __put_user(init32.depth_offset, &init->depth_offset)
+           || __put_user(init32.depth_pitch, &init->depth_pitch)
+           || __put_user(init32.fb_offset, &init->fb_offset)
+           || __put_user(init32.mmio_offset, &init->mmio_offset)
+           || __put_user(init32.status_offset, &init->status_offset)
+           || __put_user(init32.warp_offset, &init->warp_offset)
+           || __put_user(init32.primary_offset, &init->primary_offset)
+           || __put_user(init32.buffers_offset, &init->buffers_offset))
+               return -EFAULT;
+
+       for (i = 0; i < MGA_NR_TEX_HEAPS; i++) {
+               err |=
+                   __put_user(init32.texture_offset[i],
+                              &init->texture_offset[i]);
+               err |=
+                   __put_user(init32.texture_size[i], &init->texture_size[i]);
+       }
+       if (err)
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_MGA_INIT, (unsigned long)init);
+}
+
+typedef struct drm_mga_getparam32 {
+       int param;
+       u32 value;
+} drm_mga_getparam32_t;
+
+static int compat_mga_getparam(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_mga_getparam32_t getparam32;
+       drm_mga_getparam_t __user *getparam;
+
+       if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
+               return -EFAULT;
+
+       getparam = compat_alloc_user_space(sizeof(*getparam));
+       if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
+           || __put_user(getparam32.param, &getparam->param)
+           || __put_user((void __user *)(unsigned long)getparam32.value,
+                         &getparam->value))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
+}
+
+typedef struct drm_mga_drm_bootstrap32 {
+       u32 texture_handle;
+       u32 texture_size;
+       u32 primary_size;
+       u32 secondary_bin_count;
+       u32 secondary_bin_size;
+       u32 agp_mode;
+       u8 agp_size;
+} drm_mga_dma_bootstrap32_t;
+
+static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
+                                   unsigned long arg)
+{
+       drm_mga_dma_bootstrap32_t dma_bootstrap32;
+       drm_mga_dma_bootstrap_t __user *dma_bootstrap;
+       int err;
+
+       if (copy_from_user(&dma_bootstrap32, (void __user *)arg,
+                          sizeof(dma_bootstrap32)))
+               return -EFAULT;
+
+       dma_bootstrap = compat_alloc_user_space(sizeof(*dma_bootstrap));
+       if (!access_ok(VERIFY_WRITE, dma_bootstrap, sizeof(*dma_bootstrap))
+           || __put_user(dma_bootstrap32.texture_handle,
+                         &dma_bootstrap->texture_handle)
+           || __put_user(dma_bootstrap32.texture_size,
+                         &dma_bootstrap->texture_size)
+           || __put_user(dma_bootstrap32.primary_size,
+                         &dma_bootstrap->primary_size)
+           || __put_user(dma_bootstrap32.secondary_bin_count,
+                         &dma_bootstrap->secondary_bin_count)
+           || __put_user(dma_bootstrap32.secondary_bin_size,
+                         &dma_bootstrap->secondary_bin_size)
+           || __put_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
+           || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
+               return -EFAULT;
+
+       err = drm_ioctl(file->f_path.dentry->d_inode, file,
+                       DRM_IOCTL_MGA_DMA_BOOTSTRAP,
+                       (unsigned long)dma_bootstrap);
+       if (err)
+               return err;
+
+       if (__get_user(dma_bootstrap32.texture_handle,
+                      &dma_bootstrap->texture_handle)
+           || __get_user(dma_bootstrap32.texture_size,
+                         &dma_bootstrap->texture_size)
+           || __get_user(dma_bootstrap32.primary_size,
+                         &dma_bootstrap->primary_size)
+           || __get_user(dma_bootstrap32.secondary_bin_count,
+                         &dma_bootstrap->secondary_bin_count)
+           || __get_user(dma_bootstrap32.secondary_bin_size,
+                         &dma_bootstrap->secondary_bin_size)
+           || __get_user(dma_bootstrap32.agp_mode, &dma_bootstrap->agp_mode)
+           || __get_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
+               return -EFAULT;
+
+       if (copy_to_user((void __user *)arg, &dma_bootstrap32,
+                        sizeof(dma_bootstrap32)))
+               return -EFAULT;
+
+       return 0;
+}
+
+drm_ioctl_compat_t *mga_compat_ioctls[] = {
+       [DRM_MGA_INIT] = compat_mga_init,
+       [DRM_MGA_GETPARAM] = compat_mga_getparam,
+       [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
+};
+
+/**
+ * Called whenever a 32-bit process running under a 64-bit kernel
+ * performs an ioctl on /dev/dri/card<n>.
+ *
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ */
+long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       drm_ioctl_compat_t *fn = NULL;
+       int ret;
+
+       if (nr < DRM_COMMAND_BASE)
+               return drm_compat_ioctl(filp, cmd, arg);
+
+       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
+               fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
+
+       lock_kernel();          /* XXX for now */
+       if (fn != NULL)
+               ret = (*fn) (filp, cmd, arg);
+       else
+               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
new file mode 100644 (file)
index 0000000..9302cb8
--- /dev/null
@@ -0,0 +1,148 @@
+/* mga_irq.c -- IRQ handling for radeon -*- linux-c -*-
+ *
+ * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
+ *
+ * The Weather Channel (TM) funded Tungsten Graphics to develop the
+ * initial release of the Radeon 8500 driver under the XFree86 license.
+ * This notice must be preserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Eric Anholt <anholt@FreeBSD.org>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "mga_drm.h"
+#include "mga_drv.h"
+
+irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+       int status;
+       int handled = 0;
+
+       status = MGA_READ(MGA_STATUS);
+
+       /* VBLANK interrupt */
+       if (status & MGA_VLINEPEN) {
+               MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
+               atomic_inc(&dev->vbl_received);
+               DRM_WAKEUP(&dev->vbl_queue);
+               drm_vbl_send_signals(dev);
+               handled = 1;
+       }
+
+       /* SOFTRAP interrupt */
+       if (status & MGA_SOFTRAPEN) {
+               const u32 prim_start = MGA_READ(MGA_PRIMADDRESS);
+               const u32 prim_end = MGA_READ(MGA_PRIMEND);
+
+               MGA_WRITE(MGA_ICLEAR, MGA_SOFTRAPICLR);
+
+               /* In addition to clearing the interrupt-pending bit, we
+                * have to write to MGA_PRIMEND to re-start the DMA operation.
+                */
+               if ((prim_start & ~0x03) != (prim_end & ~0x03)) {
+                       MGA_WRITE(MGA_PRIMEND, prim_end);
+               }
+
+               atomic_inc(&dev_priv->last_fence_retired);
+               DRM_WAKEUP(&dev_priv->fence_queue);
+               handled = 1;
+       }
+
+       if (handled) {
+               return IRQ_HANDLED;
+       }
+       return IRQ_NONE;
+}
+
+int mga_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
+{
+       unsigned int cur_vblank;
+       int ret = 0;
+
+       /* Assume that the user has missed the current sequence number
+        * by about a day rather than she wants to wait for years
+        * using vertical blanks...
+        */
+       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
+                   (((cur_vblank = atomic_read(&dev->vbl_received))
+                     - *sequence) <= (1 << 23)));
+
+       *sequence = cur_vblank;
+
+       return ret;
+}
+
+int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+       unsigned int cur_fence;
+       int ret = 0;
+
+       /* Assume that the user has missed the current sequence number
+        * by about a day rather than she wants to wait for years
+        * using fences.
+        */
+       DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
+                   (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
+                     - *sequence) <= (1 << 23)));
+
+       *sequence = cur_fence;
+
+       return ret;
+}
+
+void mga_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+
+       /* Disable *all* interrupts */
+       MGA_WRITE(MGA_IEN, 0);
+       /* Clear bits if they're already high */
+       MGA_WRITE(MGA_ICLEAR, ~0);
+}
+
+void mga_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+
+       DRM_INIT_WAITQUEUE(&dev_priv->fence_queue);
+
+       /* Turn on vertical blank interrupt and soft trap interrupt. */
+       MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN);
+}
+
+void mga_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
+       if (!dev_priv)
+               return;
+
+       /* Disable *all* interrupts */
+       MGA_WRITE(MGA_IEN, 0);
+
+       dev->irq_enabled = 0;
+}
diff --git a/drivers/gpu/drm/mga/mga_state.c b/drivers/gpu/drm/mga/mga_state.c
new file mode 100644 (file)
index 0000000..d3f8aad
--- /dev/null
@@ -0,0 +1,1104 @@
+/* mga_state.c -- State support for MGA G200/G400 -*- linux-c -*-
+ * Created: Thu Jan 27 02:53:43 2000 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Jeff Hartmann <jhartmann@valinux.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *
+ * Rewritten by:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "mga_drm.h"
+#include "mga_drv.h"
+
+/* ================================================================
+ * DMA hardware state programming functions
+ */
+
+static void mga_emit_clip_rect(drm_mga_private_t * dev_priv,
+                              struct drm_clip_rect * box)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       unsigned int pitch = dev_priv->front_pitch;
+       DMA_LOCALS;
+
+       BEGIN_DMA(2);
+
+       /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
+        */
+       if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
+               DMA_BLOCK(MGA_DWGCTL, ctx->dwgctl,
+                         MGA_LEN + MGA_EXEC, 0x80000000,
+                         MGA_DWGCTL, ctx->dwgctl,
+                         MGA_LEN + MGA_EXEC, 0x80000000);
+       }
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_CXBNDRY, ((box->x2 - 1) << 16) | box->x1,
+                 MGA_YTOP, box->y1 * pitch, MGA_YBOT, (box->y2 - 1) * pitch);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g200_emit_context(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       DMA_LOCALS;
+
+       BEGIN_DMA(3);
+
+       DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
+                 MGA_MACCESS, ctx->maccess,
+                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
+
+       DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
+                 MGA_FOGCOL, ctx->fogcolor,
+                 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
+
+       DMA_BLOCK(MGA_FCOL, ctx->fcol,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g400_emit_context(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       DMA_LOCALS;
+
+       BEGIN_DMA(4);
+
+       DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
+                 MGA_MACCESS, ctx->maccess,
+                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
+
+       DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
+                 MGA_FOGCOL, ctx->fogcolor,
+                 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
+
+       DMA_BLOCK(MGA_WFLAG1, ctx->wflag,
+                 MGA_TDUALSTAGE0, ctx->tdualstage0,
+                 MGA_TDUALSTAGE1, ctx->tdualstage1, MGA_FCOL, ctx->fcol);
+
+       DMA_BLOCK(MGA_STENCIL, ctx->stencil,
+                 MGA_STENCILCTL, ctx->stencilctl,
+                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g200_emit_tex0(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
+       DMA_LOCALS;
+
+       BEGIN_DMA(4);
+
+       DMA_BLOCK(MGA_TEXCTL2, tex->texctl2,
+                 MGA_TEXCTL, tex->texctl,
+                 MGA_TEXFILTER, tex->texfilter,
+                 MGA_TEXBORDERCOL, tex->texbordercol);
+
+       DMA_BLOCK(MGA_TEXORG, tex->texorg,
+                 MGA_TEXORG1, tex->texorg1,
+                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
+
+       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
+                 MGA_TEXWIDTH, tex->texwidth,
+                 MGA_TEXHEIGHT, tex->texheight, MGA_WR24, tex->texwidth);
+
+       DMA_BLOCK(MGA_WR34, tex->texheight,
+                 MGA_TEXTRANS, 0x0000ffff,
+                 MGA_TEXTRANSHIGH, 0x0000ffff, MGA_DMAPAD, 0x00000000);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g400_emit_tex0(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
+       DMA_LOCALS;
+
+/*     printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
+/*            tex->texctl, tex->texctl2); */
+
+       BEGIN_DMA(6);
+
+       DMA_BLOCK(MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC,
+                 MGA_TEXCTL, tex->texctl,
+                 MGA_TEXFILTER, tex->texfilter,
+                 MGA_TEXBORDERCOL, tex->texbordercol);
+
+       DMA_BLOCK(MGA_TEXORG, tex->texorg,
+                 MGA_TEXORG1, tex->texorg1,
+                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
+
+       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
+                 MGA_TEXWIDTH, tex->texwidth,
+                 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
+
+       DMA_BLOCK(MGA_WR57, 0x00000000,
+                 MGA_WR53, 0x00000000,
+                 MGA_WR61, 0x00000000, MGA_WR52, MGA_G400_WR_MAGIC);
+
+       DMA_BLOCK(MGA_WR60, MGA_G400_WR_MAGIC,
+                 MGA_WR54, tex->texwidth | MGA_G400_WR_MAGIC,
+                 MGA_WR62, tex->texheight | MGA_G400_WR_MAGIC,
+                 MGA_DMAPAD, 0x00000000);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_TEXTRANS, 0x0000ffff, MGA_TEXTRANSHIGH, 0x0000ffff);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g400_emit_tex1(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[1];
+       DMA_LOCALS;
+
+/*     printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg,  */
+/*            tex->texctl, tex->texctl2); */
+
+       BEGIN_DMA(5);
+
+       DMA_BLOCK(MGA_TEXCTL2, (tex->texctl2 |
+                               MGA_MAP1_ENABLE |
+                               MGA_G400_TC2_MAGIC),
+                 MGA_TEXCTL, tex->texctl,
+                 MGA_TEXFILTER, tex->texfilter,
+                 MGA_TEXBORDERCOL, tex->texbordercol);
+
+       DMA_BLOCK(MGA_TEXORG, tex->texorg,
+                 MGA_TEXORG1, tex->texorg1,
+                 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
+
+       DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
+                 MGA_TEXWIDTH, tex->texwidth,
+                 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
+
+       DMA_BLOCK(MGA_WR57, 0x00000000,
+                 MGA_WR53, 0x00000000,
+                 MGA_WR61, 0x00000000,
+                 MGA_WR52, tex->texwidth | MGA_G400_WR_MAGIC);
+
+       DMA_BLOCK(MGA_WR60, tex->texheight | MGA_G400_WR_MAGIC,
+                 MGA_TEXTRANS, 0x0000ffff,
+                 MGA_TEXTRANSHIGH, 0x0000ffff,
+                 MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC);
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g200_emit_pipe(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int pipe = sarea_priv->warp_pipe;
+       DMA_LOCALS;
+
+       BEGIN_DMA(3);
+
+       DMA_BLOCK(MGA_WIADDR, MGA_WMODE_SUSPEND,
+                 MGA_WVRTXSZ, 0x00000007,
+                 MGA_WFLAG, 0x00000000, MGA_WR24, 0x00000000);
+
+       DMA_BLOCK(MGA_WR25, 0x00000100,
+                 MGA_WR34, 0x00000000,
+                 MGA_WR42, 0x0000ffff, MGA_WR60, 0x0000ffff);
+
+       /* Padding required to to hardware bug.
+        */
+       DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
+                 MGA_DMAPAD, 0xffffffff,
+                 MGA_DMAPAD, 0xffffffff,
+                 MGA_WIADDR, (dev_priv->warp_pipe_phys[pipe] |
+                              MGA_WMODE_START | dev_priv->wagp_enable));
+
+       ADVANCE_DMA();
+}
+
+static __inline__ void mga_g400_emit_pipe(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int pipe = sarea_priv->warp_pipe;
+       DMA_LOCALS;
+
+/*     printk("mga_g400_emit_pipe %x\n", pipe); */
+
+       BEGIN_DMA(10);
+
+       DMA_BLOCK(MGA_WIADDR2, MGA_WMODE_SUSPEND,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+       if (pipe & MGA_T2) {
+               DMA_BLOCK(MGA_WVRTXSZ, 0x00001e09,
+                         MGA_DMAPAD, 0x00000000,
+                         MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+               DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x1e000000);
+       } else {
+               if (dev_priv->warp_pipe & MGA_T2) {
+                       /* Flush the WARP pipe */
+                       DMA_BLOCK(MGA_YDST, 0x00000000,
+                                 MGA_FXLEFT, 0x00000000,
+                                 MGA_FXRIGHT, 0x00000001,
+                                 MGA_DWGCTL, MGA_DWGCTL_FLUSH);
+
+                       DMA_BLOCK(MGA_LEN + MGA_EXEC, 0x00000001,
+                                 MGA_DWGSYNC, 0x00007000,
+                                 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
+                                 MGA_LEN + MGA_EXEC, 0x00000000);
+
+                       DMA_BLOCK(MGA_TEXCTL2, (MGA_DUALTEX |
+                                               MGA_G400_TC2_MAGIC),
+                                 MGA_LEN + MGA_EXEC, 0x00000000,
+                                 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
+                                 MGA_DMAPAD, 0x00000000);
+               }
+
+               DMA_BLOCK(MGA_WVRTXSZ, 0x00001807,
+                         MGA_DMAPAD, 0x00000000,
+                         MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
+
+               DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x00000000,
+                         MGA_WACCEPTSEQ, 0x18000000);
+       }
+
+       DMA_BLOCK(MGA_WFLAG, 0x00000000,
+                 MGA_WFLAG1, 0x00000000,
+                 MGA_WR56, MGA_G400_WR56_MAGIC, MGA_DMAPAD, 0x00000000);
+
+       DMA_BLOCK(MGA_WR49, 0x00000000, /* tex0              */
+                 MGA_WR57, 0x00000000, /* tex0              */
+                 MGA_WR53, 0x00000000, /* tex1              */
+                 MGA_WR61, 0x00000000);        /* tex1              */
+
+       DMA_BLOCK(MGA_WR54, MGA_G400_WR_MAGIC,  /* tex0 width        */
+                 MGA_WR62, MGA_G400_WR_MAGIC,  /* tex0 height       */
+                 MGA_WR52, MGA_G400_WR_MAGIC,  /* tex1 width        */
+                 MGA_WR60, MGA_G400_WR_MAGIC); /* tex1 height       */
+
+       /* Padding required to to hardware bug */
+       DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
+                 MGA_DMAPAD, 0xffffffff,
+                 MGA_DMAPAD, 0xffffffff,
+                 MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
+                               MGA_WMODE_START | dev_priv->wagp_enable));
+
+       ADVANCE_DMA();
+}
+
+static void mga_g200_emit_state(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+
+       if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
+               mga_g200_emit_pipe(dev_priv);
+               dev_priv->warp_pipe = sarea_priv->warp_pipe;
+       }
+
+       if (dirty & MGA_UPLOAD_CONTEXT) {
+               mga_g200_emit_context(dev_priv);
+               sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
+       }
+
+       if (dirty & MGA_UPLOAD_TEX0) {
+               mga_g200_emit_tex0(dev_priv);
+               sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
+       }
+}
+
+static void mga_g400_emit_state(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+       int multitex = sarea_priv->warp_pipe & MGA_T2;
+
+       if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
+               mga_g400_emit_pipe(dev_priv);
+               dev_priv->warp_pipe = sarea_priv->warp_pipe;
+       }
+
+       if (dirty & MGA_UPLOAD_CONTEXT) {
+               mga_g400_emit_context(dev_priv);
+               sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
+       }
+
+       if (dirty & MGA_UPLOAD_TEX0) {
+               mga_g400_emit_tex0(dev_priv);
+               sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
+       }
+
+       if ((dirty & MGA_UPLOAD_TEX1) && multitex) {
+               mga_g400_emit_tex1(dev_priv);
+               sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
+       }
+}
+
+/* ================================================================
+ * SAREA state verification
+ */
+
+/* Disallow all write destinations except the front and backbuffer.
+ */
+static int mga_verify_context(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+
+       if (ctx->dstorg != dev_priv->front_offset &&
+           ctx->dstorg != dev_priv->back_offset) {
+               DRM_ERROR("*** bad DSTORG: %x (front %x, back %x)\n\n",
+                         ctx->dstorg, dev_priv->front_offset,
+                         dev_priv->back_offset);
+               ctx->dstorg = 0;
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/* Disallow texture reads from PCI space.
+ */
+static int mga_verify_tex(drm_mga_private_t * dev_priv, int unit)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
+       unsigned int org;
+
+       org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
+
+       if (org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI)) {
+               DRM_ERROR("*** bad TEXORG: 0x%x, unit %d\n", tex->texorg, unit);
+               tex->texorg = 0;
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int mga_verify_state(drm_mga_private_t * dev_priv)
+{
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+       int ret = 0;
+
+       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
+
+       if (dirty & MGA_UPLOAD_CONTEXT)
+               ret |= mga_verify_context(dev_priv);
+
+       if (dirty & MGA_UPLOAD_TEX0)
+               ret |= mga_verify_tex(dev_priv, 0);
+
+       if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
+               if (dirty & MGA_UPLOAD_TEX1)
+                       ret |= mga_verify_tex(dev_priv, 1);
+
+               if (dirty & MGA_UPLOAD_PIPE)
+                       ret |= (sarea_priv->warp_pipe > MGA_MAX_G400_PIPES);
+       } else {
+               if (dirty & MGA_UPLOAD_PIPE)
+                       ret |= (sarea_priv->warp_pipe > MGA_MAX_G200_PIPES);
+       }
+
+       return (ret == 0);
+}
+
+static int mga_verify_iload(drm_mga_private_t * dev_priv,
+                           unsigned int dstorg, unsigned int length)
+{
+       if (dstorg < dev_priv->texture_offset ||
+           dstorg + length > (dev_priv->texture_offset +
+                              dev_priv->texture_size)) {
+               DRM_ERROR("*** bad iload DSTORG: 0x%x\n", dstorg);
+               return -EINVAL;
+       }
+
+       if (length & MGA_ILOAD_MASK) {
+               DRM_ERROR("*** bad iload length: 0x%x\n",
+                         length & MGA_ILOAD_MASK);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int mga_verify_blit(drm_mga_private_t * dev_priv,
+                          unsigned int srcorg, unsigned int dstorg)
+{
+       if ((srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
+           (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM)) {
+               DRM_ERROR("*** bad blit: src=0x%x dst=0x%x\n", srcorg, dstorg);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/* ================================================================
+ *
+ */
+
+static void mga_dma_dispatch_clear(struct drm_device * dev, drm_mga_clear_t * clear)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int nbox = sarea_priv->nbox;
+       int i;
+       DMA_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_DMA(1);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
+
+       ADVANCE_DMA();
+
+       for (i = 0; i < nbox; i++) {
+               struct drm_clip_rect *box = &pbox[i];
+               u32 height = box->y2 - box->y1;
+
+               DRM_DEBUG("   from=%d,%d to=%d,%d\n",
+                         box->x1, box->y1, box->x2, box->y2);
+
+               if (clear->flags & MGA_FRONT) {
+                       BEGIN_DMA(2);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_PLNWT, clear->color_mask,
+                                 MGA_YDSTLEN, (box->y1 << 16) | height,
+                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_FCOL, clear->clear_color,
+                                 MGA_DSTORG, dev_priv->front_offset,
+                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
+
+                       ADVANCE_DMA();
+               }
+
+               if (clear->flags & MGA_BACK) {
+                       BEGIN_DMA(2);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_PLNWT, clear->color_mask,
+                                 MGA_YDSTLEN, (box->y1 << 16) | height,
+                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_FCOL, clear->clear_color,
+                                 MGA_DSTORG, dev_priv->back_offset,
+                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
+
+                       ADVANCE_DMA();
+               }
+
+               if (clear->flags & MGA_DEPTH) {
+                       BEGIN_DMA(2);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_PLNWT, clear->depth_mask,
+                                 MGA_YDSTLEN, (box->y1 << 16) | height,
+                                 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_FCOL, clear->clear_depth,
+                                 MGA_DSTORG, dev_priv->depth_offset,
+                                 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
+
+                       ADVANCE_DMA();
+               }
+
+       }
+
+       BEGIN_DMA(1);
+
+       /* Force reset of DWGCTL */
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
+
+       ADVANCE_DMA();
+
+       FLUSH_DMA();
+}
+
+static void mga_dma_dispatch_swap(struct drm_device * dev)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int nbox = sarea_priv->nbox;
+       int i;
+       DMA_LOCALS;
+       DRM_DEBUG("\n");
+
+       sarea_priv->last_frame.head = dev_priv->prim.tail;
+       sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
+
+       BEGIN_DMA(4 + nbox);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
+
+       DMA_BLOCK(MGA_DSTORG, dev_priv->front_offset,
+                 MGA_MACCESS, dev_priv->maccess,
+                 MGA_SRCORG, dev_priv->back_offset,
+                 MGA_AR5, dev_priv->front_pitch);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_PLNWT, 0xffffffff, MGA_DWGCTL, MGA_DWGCTL_COPY);
+
+       for (i = 0; i < nbox; i++) {
+               struct drm_clip_rect *box = &pbox[i];
+               u32 height = box->y2 - box->y1;
+               u32 start = box->y1 * dev_priv->front_pitch;
+
+               DRM_DEBUG("   from=%d,%d to=%d,%d\n",
+                         box->x1, box->y1, box->x2, box->y2);
+
+               DMA_BLOCK(MGA_AR0, start + box->x2 - 1,
+                         MGA_AR3, start + box->x1,
+                         MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
+                         MGA_YDSTLEN + MGA_EXEC, (box->y1 << 16) | height);
+       }
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_PLNWT, ctx->plnwt,
+                 MGA_SRCORG, dev_priv->front_offset, MGA_DWGCTL, ctx->dwgctl);
+
+       ADVANCE_DMA();
+
+       FLUSH_DMA();
+
+       DRM_DEBUG("... done.\n");
+}
+
+static void mga_dma_dispatch_vertex(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       u32 address = (u32) buf->bus_address;
+       u32 length = (u32) buf->used;
+       int i = 0;
+       DMA_LOCALS;
+       DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
+
+       if (buf->used) {
+               buf_priv->dispatched = 1;
+
+               MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
+
+               do {
+                       if (i < sarea_priv->nbox) {
+                               mga_emit_clip_rect(dev_priv,
+                                                  &sarea_priv->boxes[i]);
+                       }
+
+                       BEGIN_DMA(1);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_DMAPAD, 0x00000000,
+                                 MGA_SECADDRESS, (address |
+                                                  MGA_DMA_VERTEX),
+                                 MGA_SECEND, ((address + length) |
+                                              dev_priv->dma_access));
+
+                       ADVANCE_DMA();
+               } while (++i < sarea_priv->nbox);
+       }
+
+       if (buf_priv->discard) {
+               AGE_BUFFER(buf_priv);
+               buf->pending = 0;
+               buf->used = 0;
+               buf_priv->dispatched = 0;
+
+               mga_freelist_put(dev, buf);
+       }
+
+       FLUSH_DMA();
+}
+
+static void mga_dma_dispatch_indices(struct drm_device * dev, struct drm_buf * buf,
+                                    unsigned int start, unsigned int end)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       u32 address = (u32) buf->bus_address;
+       int i = 0;
+       DMA_LOCALS;
+       DRM_DEBUG("buf=%d start=%d end=%d\n", buf->idx, start, end);
+
+       if (start != end) {
+               buf_priv->dispatched = 1;
+
+               MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
+
+               do {
+                       if (i < sarea_priv->nbox) {
+                               mga_emit_clip_rect(dev_priv,
+                                                  &sarea_priv->boxes[i]);
+                       }
+
+                       BEGIN_DMA(1);
+
+                       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                                 MGA_DMAPAD, 0x00000000,
+                                 MGA_SETUPADDRESS, address + start,
+                                 MGA_SETUPEND, ((address + end) |
+                                                dev_priv->dma_access));
+
+                       ADVANCE_DMA();
+               } while (++i < sarea_priv->nbox);
+       }
+
+       if (buf_priv->discard) {
+               AGE_BUFFER(buf_priv);
+               buf->pending = 0;
+               buf->used = 0;
+               buf_priv->dispatched = 0;
+
+               mga_freelist_put(dev, buf);
+       }
+
+       FLUSH_DMA();
+}
+
+/* This copies a 64 byte aligned agp region to the frambuffer with a
+ * standard blit, the ioctl needs to do checking.
+ */
+static void mga_dma_dispatch_iload(struct drm_device * dev, struct drm_buf * buf,
+                                  unsigned int dstorg, unsigned int length)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_buf_priv_t *buf_priv = buf->dev_private;
+       drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
+       u32 srcorg =
+           buf->bus_address | dev_priv->dma_access | MGA_SRCMAP_SYSMEM;
+       u32 y2;
+       DMA_LOCALS;
+       DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
+
+       y2 = length / 64;
+
+       BEGIN_DMA(5);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
+
+       DMA_BLOCK(MGA_DSTORG, dstorg,
+                 MGA_MACCESS, 0x00000000, MGA_SRCORG, srcorg, MGA_AR5, 64);
+
+       DMA_BLOCK(MGA_PITCH, 64,
+                 MGA_PLNWT, 0xffffffff,
+                 MGA_DMAPAD, 0x00000000, MGA_DWGCTL, MGA_DWGCTL_COPY);
+
+       DMA_BLOCK(MGA_AR0, 63,
+                 MGA_AR3, 0,
+                 MGA_FXBNDRY, (63 << 16) | 0, MGA_YDSTLEN + MGA_EXEC, y2);
+
+       DMA_BLOCK(MGA_PLNWT, ctx->plnwt,
+                 MGA_SRCORG, dev_priv->front_offset,
+                 MGA_PITCH, dev_priv->front_pitch, MGA_DWGSYNC, 0x00007000);
+
+       ADVANCE_DMA();
+
+       AGE_BUFFER(buf_priv);
+
+       buf->pending = 0;
+       buf->used = 0;
+       buf_priv->dispatched = 0;
+
+       mga_freelist_put(dev, buf);
+
+       FLUSH_DMA();
+}
+
+static void mga_dma_dispatch_blit(struct drm_device * dev, drm_mga_blit_t * blit)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int nbox = sarea_priv->nbox;
+       u32 scandir = 0, i;
+       DMA_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_DMA(4 + nbox);
+
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
+
+       DMA_BLOCK(MGA_DWGCTL, MGA_DWGCTL_COPY,
+                 MGA_PLNWT, blit->planemask,
+                 MGA_SRCORG, blit->srcorg, MGA_DSTORG, blit->dstorg);
+
+       DMA_BLOCK(MGA_SGN, scandir,
+                 MGA_MACCESS, dev_priv->maccess,
+                 MGA_AR5, blit->ydir * blit->src_pitch,
+                 MGA_PITCH, blit->dst_pitch);
+
+       for (i = 0; i < nbox; i++) {
+               int srcx = pbox[i].x1 + blit->delta_sx;
+               int srcy = pbox[i].y1 + blit->delta_sy;
+               int dstx = pbox[i].x1 + blit->delta_dx;
+               int dsty = pbox[i].y1 + blit->delta_dy;
+               int h = pbox[i].y2 - pbox[i].y1;
+               int w = pbox[i].x2 - pbox[i].x1 - 1;
+               int start;
+
+               if (blit->ydir == -1) {
+                       srcy = blit->height - srcy - 1;
+               }
+
+               start = srcy * blit->src_pitch + srcx;
+
+               DMA_BLOCK(MGA_AR0, start + w,
+                         MGA_AR3, start,
+                         MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
+                         MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h);
+       }
+
+       /* Do something to flush AGP?
+        */
+
+       /* Force reset of DWGCTL */
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_PLNWT, ctx->plnwt,
+                 MGA_PITCH, dev_priv->front_pitch, MGA_DWGCTL, ctx->dwgctl);
+
+       ADVANCE_DMA();
+}
+
+/* ================================================================
+ *
+ */
+
+static int mga_dma_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_clear_t *clear = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_clear(dev, clear);
+
+       /* Make sure we restore the 3D state next time.
+        */
+       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
+
+       return 0;
+}
+
+static int mga_dma_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_swap(dev);
+
+       /* Make sure we restore the 3D state next time.
+        */
+       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
+
+       return 0;
+}
+
+static int mga_dma_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_mga_buf_priv_t *buf_priv;
+       drm_mga_vertex_t *vertex = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (vertex->idx < 0 || vertex->idx > dma->buf_count)
+               return -EINVAL;
+       buf = dma->buflist[vertex->idx];
+       buf_priv = buf->dev_private;
+
+       buf->used = vertex->used;
+       buf_priv->discard = vertex->discard;
+
+       if (!mga_verify_state(dev_priv)) {
+               if (vertex->discard) {
+                       if (buf_priv->dispatched == 1)
+                               AGE_BUFFER(buf_priv);
+                       buf_priv->dispatched = 0;
+                       mga_freelist_put(dev, buf);
+               }
+               return -EINVAL;
+       }
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_vertex(dev, buf);
+
+       return 0;
+}
+
+static int mga_dma_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_mga_buf_priv_t *buf_priv;
+       drm_mga_indices_t *indices = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (indices->idx < 0 || indices->idx > dma->buf_count)
+               return -EINVAL;
+
+       buf = dma->buflist[indices->idx];
+       buf_priv = buf->dev_private;
+
+       buf_priv->discard = indices->discard;
+
+       if (!mga_verify_state(dev_priv)) {
+               if (indices->discard) {
+                       if (buf_priv->dispatched == 1)
+                               AGE_BUFFER(buf_priv);
+                       buf_priv->dispatched = 0;
+                       mga_freelist_put(dev, buf);
+               }
+               return -EINVAL;
+       }
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_indices(dev, buf, indices->start, indices->end);
+
+       return 0;
+}
+
+static int mga_dma_iload(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       struct drm_buf *buf;
+       drm_mga_buf_priv_t *buf_priv;
+       drm_mga_iload_t *iload = data;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+#if 0
+       if (mga_do_wait_for_idle(dev_priv) < 0) {
+               if (MGA_DMA_DEBUG)
+                       DRM_INFO("-EBUSY\n");
+               return -EBUSY;
+       }
+#endif
+       if (iload->idx < 0 || iload->idx > dma->buf_count)
+               return -EINVAL;
+
+       buf = dma->buflist[iload->idx];
+       buf_priv = buf->dev_private;
+
+       if (mga_verify_iload(dev_priv, iload->dstorg, iload->length)) {
+               mga_freelist_put(dev, buf);
+               return -EINVAL;
+       }
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_iload(dev, buf, iload->dstorg, iload->length);
+
+       /* Make sure we restore the 3D state next time.
+        */
+       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
+
+       return 0;
+}
+
+static int mga_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_mga_blit_t *blit = data;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
+
+       if (mga_verify_blit(dev_priv, blit->srcorg, blit->dstorg))
+               return -EINVAL;
+
+       WRAP_TEST_WITH_RETURN(dev_priv);
+
+       mga_dma_dispatch_blit(dev, blit);
+
+       /* Make sure we restore the 3D state next time.
+        */
+       dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
+
+       return 0;
+}
+
+static int mga_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       drm_mga_getparam_t *param = data;
+       int value;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
+
+       switch (param->param) {
+       case MGA_PARAM_IRQ_NR:
+               value = dev->irq;
+               break;
+       case MGA_PARAM_CARD_TYPE:
+               value = dev_priv->chipset;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int mga_set_fence(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       u32 *fence = data;
+       DMA_LOCALS;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
+
+       /* I would normal do this assignment in the declaration of fence,
+        * but dev_priv may be NULL.
+        */
+
+       *fence = dev_priv->next_fence_to_post;
+       dev_priv->next_fence_to_post++;
+
+       BEGIN_DMA(1);
+       DMA_BLOCK(MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000,
+                 MGA_DMAPAD, 0x00000000, MGA_SOFTRAP, 0x00000000);
+       ADVANCE_DMA();
+
+       return 0;
+}
+
+static int mga_wait_fence(struct drm_device *dev, void *data, struct drm_file *
+file_priv)
+{
+       drm_mga_private_t *dev_priv = dev->dev_private;
+       u32 *fence = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
+
+       mga_driver_fence_wait(dev, fence);
+       return 0;
+}
+
+struct drm_ioctl_desc mga_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_MGA_INIT, mga_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_MGA_FLUSH, mga_dma_flush, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_RESET, mga_dma_reset, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_SWAP, mga_dma_swap, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_CLEAR, mga_dma_clear, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_VERTEX, mga_dma_vertex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_INDICES, mga_dma_indices, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_ILOAD, mga_dma_iload, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_BLIT, mga_dma_blit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_GETPARAM, mga_getparam, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_SET_FENCE, mga_set_fence, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_WAIT_FENCE, mga_wait_fence, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_MGA_DMA_BOOTSTRAP, mga_dma_bootstrap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+};
+
+int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);
diff --git a/drivers/gpu/drm/mga/mga_ucode.h b/drivers/gpu/drm/mga/mga_ucode.h
new file mode 100644 (file)
index 0000000..b611e27
--- /dev/null
@@ -0,0 +1,11645 @@
+/* mga_ucode.h -- Matrox G200/G400 WARP engine microcode -*- linux-c -*-
+ * Created: Thu Jan 11 21:20:43 2001 by gareth@valinux.com
+ *
+ * Copyright 1999 Matrox Graphics Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * MATROX GRAPHICS INC., OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Kernel-based WARP engine management:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * WARP pipes are named according to the functions they perform, where:
+ *
+ *   - T stands for computation of texture stage 0
+ *   - T2 stands for computation of both texture stage 0 and texture stage 1
+ *   - G stands for computation of triangle intensity (Gouraud interpolation)
+ *   - Z stands for computation of Z buffer interpolation
+ *   - S stands for computation of specular highlight
+ *   - A stands for computation of the alpha channel
+ *   - F stands for computation of vertex fog interpolation
+ */
+
+static unsigned char warp_g200_tgz[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x72, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x60, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x03, 0x80, 0x0A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x57, 0x39, 0x20, 0xE9,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0x2B, 0x32, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0xB3, 0x05,
+       0x00, 0xE0,
+       0x16, 0x28, 0x20, 0xE9,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x1E, 0x2B, 0x20, 0xE9,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x85, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x84, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x82, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x7F, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgza[] = {
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x7D, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x6B, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2D, 0x44, 0x4C, 0xB6,
+       0x25, 0x44, 0x54, 0xB6,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x07, 0xC0, 0x44, 0xC6,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x1F, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x3F, 0x3D, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x07, 0x20,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0xB3, 0x05,
+       0x00, 0xE0,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0x26, 0x1F, 0xDF,
+       0x9D, 0x1F, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x9E, 0x3F, 0x4F, 0xE9,
+
+       0x07, 0x07, 0x1F, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x9C, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x7A, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x79, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x77, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x74, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzaf[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x83, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x6F, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0D, 0x21, 0x1A, 0xB6,
+       0x05, 0x21, 0x31, 0xB6,
+
+       0x2D, 0x44, 0x4C, 0xB6,
+       0x25, 0x44, 0x54, 0xB6,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x0D, 0x20,
+       0x05, 0x20,
+       0x2F, 0xC0, 0x21, 0xC6,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x07, 0xC0, 0x44, 0xC6,
+
+       0x17, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x2D, 0x20,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x1F, 0x62, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x07, 0x20,
+
+       0x3F, 0x3D, 0x5D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0xB3, 0x05,
+       0x00, 0xE0,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x35, 0x17, 0x4F, 0xE9,
+
+       0x1F, 0x26, 0x1F, 0xDF,
+       0x9D, 0x1F, 0x4F, 0xE9,
+
+       0x9E, 0x3F, 0x4F, 0xE9,
+       0x39, 0x37, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x17, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x07, 0x07, 0x1F, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x31, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x9C, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x74, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x73, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x71, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6E, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzf[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x7F, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x6B, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0D, 0x21, 0x1A, 0xB6,
+       0x05, 0x21, 0x31, 0xB6,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x0D, 0x20,
+       0x05, 0x20,
+       0x2F, 0xC0, 0x21, 0xC6,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x17, 0x50, 0x56, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0xB3, 0x05,
+       0x00, 0xE0,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x17, 0x26, 0x17, 0xDF,
+       0x35, 0x17, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x39, 0x37, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x17, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x31, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x78, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x77, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x75, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x72, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzs[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x8B, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x77, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2D, 0x21, 0x1A, 0xB0,
+       0x25, 0x21, 0x31, 0xB0,
+
+       0x0D, 0x21, 0x1A, 0xB2,
+       0x05, 0x21, 0x31, 0xB2,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x05, 0x20,
+       0x0D, 0x20,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x2F, 0xC0, 0x21, 0xC0,
+
+       0x16, 0x42, 0x56, 0x9F,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x1E, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x21, 0x31, 0xB4,
+       0x2D, 0x21, 0x1A, 0xB4,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0x05,
+       0x00, 0xE0,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x1E, 0x26, 0x1E, 0xDF,
+
+       0xA7, 0x1E, 0x4F, 0xE9,
+       0x17, 0x26, 0x16, 0xDF,
+
+       0x2D, 0x20,
+       0x00, 0xE0,
+       0xA8, 0x3F, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x1E, 0xAF,
+       0x25, 0x20,
+       0x00, 0xE0,
+
+       0xA4, 0x16, 0x4F, 0xE9,
+       0x0F, 0xC0, 0x21, 0xC2,
+
+       0xA6, 0x80, 0x4F, 0xE9,
+       0x1F, 0x62, 0x57, 0x9F,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x8F, 0x20,
+
+       0xA5, 0x37, 0x4F, 0xE9,
+       0x0F, 0x17, 0x0F, 0xAF,
+
+       0x06, 0xC0, 0x21, 0xC4,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0xA3, 0x80, 0x4F, 0xE9,
+
+       0x06, 0x20,
+       0x00, 0xE0,
+       0x1F, 0x26, 0x1F, 0xDF,
+
+       0xA1, 0x1F, 0x4F, 0xE9,
+       0xA2, 0x3F, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x06, 0x06, 0x1F, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x6C, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6B, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x69, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzsa[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x8F, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x7B, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2D, 0x21, 0x1A, 0xB0,
+       0x25, 0x21, 0x31, 0xB0,
+
+       0x0D, 0x21, 0x1A, 0xB2,
+       0x05, 0x21, 0x31, 0xB2,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x05, 0x20,
+       0x0D, 0x20,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x2F, 0xC0, 0x21, 0xC0,
+
+       0x16, 0x42, 0x56, 0x9F,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x1E, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x21, 0x31, 0xB4,
+       0x2D, 0x21, 0x1A, 0xB4,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0x05,
+       0x00, 0xE0,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0x0D, 0x44, 0x4C, 0xB6,
+       0x05, 0x44, 0x54, 0xB6,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x1E, 0x26, 0x1E, 0xDF,
+
+       0xA7, 0x1E, 0x4F, 0xE9,
+       0x17, 0x26, 0x16, 0xDF,
+
+       0x2D, 0x20,
+       0x00, 0xE0,
+       0xA8, 0x3F, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x1E, 0xAF,
+       0x25, 0x20,
+       0x00, 0xE0,
+
+       0xA4, 0x16, 0x4F, 0xE9,
+       0x0F, 0xC0, 0x21, 0xC2,
+
+       0xA6, 0x80, 0x4F, 0xE9,
+       0x1F, 0x62, 0x57, 0x9F,
+
+       0x0D, 0x20,
+       0x05, 0x20,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x0F, 0x20,
+
+       0x17, 0x50, 0x56, 0x9F,
+       0xA5, 0x37, 0x4F, 0xE9,
+
+       0x06, 0xC0, 0x21, 0xC4,
+       0x0F, 0x17, 0x0F, 0xAF,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2F, 0xC0, 0x44, 0xC6,
+       0xA3, 0x80, 0x4F, 0xE9,
+
+       0x06, 0x20,
+       0x00, 0xE0,
+       0x1F, 0x26, 0x1F, 0xDF,
+
+       0x17, 0x26, 0x17, 0xDF,
+       0x9D, 0x17, 0x4F, 0xE9,
+
+       0xA1, 0x1F, 0x4F, 0xE9,
+       0xA2, 0x3F, 0x4F, 0xE9,
+
+       0x06, 0x06, 0x1F, 0xAF,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x9E, 0x37, 0x4F, 0xE9,
+       0x2F, 0x17, 0x2F, 0xAF,
+
+       0xA0, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x9C, 0x80, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x68, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x67, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x65, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x62, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzsaf[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x94, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x80, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2D, 0x21, 0x1A, 0xB0,
+       0x25, 0x21, 0x31, 0xB0,
+
+       0x0D, 0x21, 0x1A, 0xB2,
+       0x05, 0x21, 0x31, 0xB2,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x05, 0x20,
+       0x0D, 0x20,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x2F, 0xC0, 0x21, 0xC0,
+
+       0x16, 0x42, 0x56, 0x9F,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x1E, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x21, 0x31, 0xB4,
+       0x2D, 0x21, 0x1A, 0xB4,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0x05,
+       0x00, 0xE0,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0x0D, 0x21, 0x1A, 0xB6,
+       0x05, 0x21, 0x31, 0xB6,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x1E, 0x26, 0x1E, 0xDF,
+
+       0xA7, 0x1E, 0x4F, 0xE9,
+       0x17, 0x26, 0x16, 0xDF,
+
+       0x2D, 0x20,
+       0x00, 0xE0,
+       0xA8, 0x3F, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x1E, 0xAF,
+       0x25, 0x20,
+       0x00, 0xE0,
+
+       0xA4, 0x16, 0x4F, 0xE9,
+       0x0F, 0xC0, 0x21, 0xC2,
+
+       0xA6, 0x80, 0x4F, 0xE9,
+       0x1F, 0x62, 0x57, 0x9F,
+
+       0x0D, 0x20,
+       0x05, 0x20,
+       0x2F, 0xC0, 0x21, 0xC6,
+
+       0x2D, 0x44, 0x4C, 0xB6,
+       0x25, 0x44, 0x54, 0xB6,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x0F, 0x20,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x07, 0xC0, 0x44, 0xC6,
+
+       0x17, 0x50, 0x56, 0x9F,
+       0xA5, 0x37, 0x4F, 0xE9,
+
+       0x06, 0xC0, 0x21, 0xC4,
+       0x0F, 0x17, 0x0F, 0xAF,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1E, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x3E, 0x3D, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x07, 0x20,
+
+       0x2F, 0x20,
+       0x00, 0xE0,
+       0xA3, 0x0F, 0x4F, 0xE9,
+
+       0x06, 0x20,
+       0x00, 0xE0,
+       0x1F, 0x26, 0x1F, 0xDF,
+
+       0x17, 0x26, 0x17, 0xDF,
+       0xA1, 0x1F, 0x4F, 0xE9,
+
+       0x1E, 0x26, 0x1E, 0xDF,
+       0x9D, 0x1E, 0x4F, 0xE9,
+
+       0x35, 0x17, 0x4F, 0xE9,
+       0xA2, 0x3F, 0x4F, 0xE9,
+
+       0x06, 0x06, 0x1F, 0xAF,
+       0x39, 0x37, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x17, 0xAF,
+       0x07, 0x07, 0x1E, 0xAF,
+
+       0xA0, 0x80, 0x4F, 0xE9,
+       0x9E, 0x3E, 0x4F, 0xE9,
+
+       0x31, 0x80, 0x4F, 0xE9,
+       0x9C, 0x80, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x63, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x62, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x60, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x5D, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g200_tgzsf[] = {
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x98, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x81, 0x04,
+       0x89, 0x04,
+       0x01, 0x04,
+       0x09, 0x04,
+
+       0xC9, 0x41, 0xC0, 0xEC,
+       0x11, 0x04,
+       0x00, 0xE0,
+
+       0x41, 0xCC, 0x41, 0xCD,
+       0x49, 0xCC, 0x49, 0xCD,
+
+       0xD1, 0x41, 0xC0, 0xEC,
+       0x51, 0xCC, 0x51, 0xCD,
+
+       0x80, 0x04,
+       0x10, 0x04,
+       0x08, 0x04,
+       0x00, 0xE0,
+
+       0x00, 0xCC, 0xC0, 0xCD,
+       0xD1, 0x49, 0xC0, 0xEC,
+
+       0x8A, 0x1F, 0x20, 0xE9,
+       0x8B, 0x3F, 0x20, 0xE9,
+
+       0x41, 0x3C, 0x41, 0xAD,
+       0x49, 0x3C, 0x49, 0xAD,
+
+       0x10, 0xCC, 0x10, 0xCD,
+       0x08, 0xCC, 0x08, 0xCD,
+
+       0xB9, 0x41, 0x49, 0xBB,
+       0x1F, 0xF0, 0x41, 0xCD,
+
+       0x51, 0x3C, 0x51, 0xAD,
+       0x00, 0x98, 0x80, 0xE9,
+
+       0x8F, 0x80, 0x07, 0xEA,
+       0x24, 0x1F, 0x20, 0xE9,
+
+       0x21, 0x45, 0x80, 0xE8,
+       0x1A, 0x4D, 0x80, 0xE8,
+
+       0x31, 0x55, 0x80, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0x41, 0x49, 0xBD,
+       0x1D, 0x41, 0x51, 0xBD,
+
+       0x2E, 0x41, 0x2A, 0xB8,
+       0x34, 0x53, 0xA0, 0xE8,
+
+       0x15, 0x30,
+       0x1D, 0x30,
+       0x58, 0xE3,
+       0x00, 0xE0,
+
+       0xB5, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x24, 0x43, 0xA0, 0xE8,
+       0x2C, 0x4B, 0xA0, 0xE8,
+
+       0x15, 0x72,
+       0x09, 0xE3,
+       0x00, 0xE0,
+       0x1D, 0x72,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0x97, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x6C, 0x64, 0xC8, 0xEC,
+       0x98, 0xE1,
+       0xB5, 0x05,
+
+       0xBD, 0x05,
+       0x2E, 0x30,
+       0x32, 0xC0, 0xA0, 0xE8,
+
+       0x33, 0xC0, 0xA0, 0xE8,
+       0x74, 0x64, 0xC8, 0xEC,
+
+       0x40, 0x3C, 0x40, 0xAD,
+       0x32, 0x6A,
+       0x2A, 0x30,
+
+       0x20, 0x73,
+       0x33, 0x6A,
+       0x00, 0xE0,
+       0x28, 0x73,
+
+       0x1C, 0x72,
+       0x83, 0xE2,
+       0x7B, 0x80, 0x15, 0xEA,
+
+       0xB8, 0x3D, 0x28, 0xDF,
+       0x30, 0x35, 0x20, 0xDF,
+
+       0x40, 0x30,
+       0x00, 0xE0,
+       0xCC, 0xE2,
+       0x64, 0x72,
+
+       0x25, 0x42, 0x52, 0xBF,
+       0x2D, 0x42, 0x4A, 0xBF,
+
+       0x30, 0x2E, 0x30, 0xDF,
+       0x38, 0x2E, 0x38, 0xDF,
+
+       0x18, 0x1D, 0x45, 0xE9,
+       0x1E, 0x15, 0x45, 0xE9,
+
+       0x2B, 0x49, 0x51, 0xBD,
+       0x00, 0xE0,
+       0x1F, 0x73,
+
+       0x38, 0x38, 0x40, 0xAF,
+       0x30, 0x30, 0x40, 0xAF,
+
+       0x24, 0x1F, 0x24, 0xDF,
+       0x1D, 0x32, 0x20, 0xE9,
+
+       0x2C, 0x1F, 0x2C, 0xDF,
+       0x1A, 0x33, 0x20, 0xE9,
+
+       0xB0, 0x10,
+       0x08, 0xE3,
+       0x40, 0x10,
+       0xB8, 0x10,
+
+       0x26, 0xF0, 0x30, 0xCD,
+       0x2F, 0xF0, 0x38, 0xCD,
+
+       0x2B, 0x80, 0x20, 0xE9,
+       0x2A, 0x80, 0x20, 0xE9,
+
+       0xA6, 0x20,
+       0x88, 0xE2,
+       0x00, 0xE0,
+       0xAF, 0x20,
+
+       0x28, 0x2A, 0x26, 0xAF,
+       0x20, 0x2A, 0xC0, 0xAF,
+
+       0x34, 0x1F, 0x34, 0xDF,
+       0x46, 0x24, 0x46, 0xDF,
+
+       0x28, 0x30, 0x80, 0xBF,
+       0x20, 0x38, 0x80, 0xBF,
+
+       0x47, 0x24, 0x47, 0xDF,
+       0x4E, 0x2C, 0x4E, 0xDF,
+
+       0x4F, 0x2C, 0x4F, 0xDF,
+       0x56, 0x34, 0x56, 0xDF,
+
+       0x28, 0x15, 0x28, 0xDF,
+       0x20, 0x1D, 0x20, 0xDF,
+
+       0x57, 0x34, 0x57, 0xDF,
+       0x00, 0xE0,
+       0x1D, 0x05,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x89, 0xE2,
+       0x2B, 0x30,
+
+       0x3F, 0xC1, 0x1D, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x68,
+       0xBF, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x20, 0xC0, 0x20, 0xAF,
+       0x28, 0x05,
+       0x97, 0x74,
+
+       0x00, 0xE0,
+       0x2A, 0x10,
+       0x16, 0xC0, 0x20, 0xE9,
+
+       0x04, 0x80, 0x10, 0xEA,
+       0x8C, 0xE2,
+       0x95, 0x05,
+
+       0x28, 0xC1, 0x28, 0xAD,
+       0x1F, 0xC1, 0x15, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA8, 0x67,
+       0x9F, 0x6B,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x28, 0xC0, 0x28, 0xAD,
+       0x1D, 0x25,
+       0x20, 0x05,
+
+       0x28, 0x32, 0x80, 0xAD,
+       0x40, 0x2A, 0x40, 0xBD,
+
+       0x1C, 0x80, 0x20, 0xE9,
+       0x20, 0x33, 0x20, 0xAD,
+
+       0x20, 0x73,
+       0x00, 0xE0,
+       0xB6, 0x49, 0x51, 0xBB,
+
+       0x26, 0x2F, 0xB0, 0xE8,
+       0x19, 0x20, 0x20, 0xE9,
+
+       0x35, 0x20, 0x35, 0xDF,
+       0x3D, 0x20, 0x3D, 0xDF,
+
+       0x15, 0x20, 0x15, 0xDF,
+       0x1D, 0x20, 0x1D, 0xDF,
+
+       0x26, 0xD0, 0x26, 0xCD,
+       0x29, 0x49, 0x2A, 0xB8,
+
+       0x26, 0x40, 0x80, 0xBD,
+       0x3B, 0x48, 0x50, 0xBD,
+
+       0x3E, 0x54, 0x57, 0x9F,
+       0x00, 0xE0,
+       0x82, 0xE1,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x26, 0x30,
+       0x29, 0x30,
+       0x48, 0x3C, 0x48, 0xAD,
+
+       0x2B, 0x72,
+       0xC2, 0xE1,
+       0x2C, 0xC0, 0x44, 0xC2,
+
+       0x05, 0x24, 0x34, 0xBF,
+       0x0D, 0x24, 0x2C, 0xBF,
+
+       0x2D, 0x46, 0x4E, 0xBF,
+       0x25, 0x46, 0x56, 0xBF,
+
+       0x20, 0x1D, 0x6F, 0x8F,
+       0x32, 0x3E, 0x5F, 0xE9,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x30,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x33, 0x1E, 0x5F, 0xE9,
+
+       0x05, 0x44, 0x54, 0xB2,
+       0x0D, 0x44, 0x4C, 0xB2,
+
+       0x19, 0xC0, 0xB0, 0xE8,
+       0x34, 0xC0, 0x44, 0xC4,
+
+       0x33, 0x73,
+       0x00, 0xE0,
+       0x3E, 0x62, 0x57, 0x9F,
+
+       0x1E, 0xAF, 0x59, 0x9F,
+       0x00, 0xE0,
+       0x0D, 0x20,
+
+       0x84, 0x3E, 0x58, 0xE9,
+       0x28, 0x1D, 0x6F, 0x8F,
+
+       0x05, 0x20,
+       0x00, 0xE0,
+       0x85, 0x1E, 0x58, 0xE9,
+
+       0x9B, 0x3B, 0x33, 0xDF,
+       0x20, 0x20, 0x42, 0xAF,
+
+       0x30, 0x42, 0x56, 0x9F,
+       0x80, 0x3E, 0x57, 0xE9,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x30, 0x80, 0x5F, 0xE9,
+
+       0x28, 0x28, 0x24, 0xAF,
+       0x81, 0x1E, 0x57, 0xE9,
+
+       0x05, 0x47, 0x57, 0xBF,
+       0x0D, 0x47, 0x4F, 0xBF,
+
+       0x88, 0x80, 0x58, 0xE9,
+       0x1B, 0x29, 0x1B, 0xDF,
+
+       0x30, 0x1D, 0x6F, 0x8F,
+       0x3A, 0x30, 0x4F, 0xE9,
+
+       0x1C, 0x30, 0x26, 0xDF,
+       0x09, 0xE3,
+       0x3B, 0x05,
+
+       0x3E, 0x50, 0x56, 0x9F,
+       0x3B, 0x3F, 0x4F, 0xE9,
+
+       0x1E, 0x8F, 0x51, 0x9F,
+       0x00, 0xE0,
+       0xAC, 0x20,
+
+       0x2D, 0x44, 0x4C, 0xB4,
+       0x2C, 0x1C, 0xC0, 0xAF,
+
+       0x25, 0x44, 0x54, 0xB4,
+       0x00, 0xE0,
+       0xC8, 0x30,
+
+       0x30, 0x46, 0x30, 0xAF,
+       0x1B, 0x1B, 0x48, 0xAF,
+
+       0x00, 0xE0,
+       0x25, 0x20,
+       0x38, 0x2C, 0x4F, 0xE9,
+
+       0x86, 0x80, 0x57, 0xE9,
+       0x38, 0x1D, 0x6F, 0x8F,
+
+       0x28, 0x74,
+       0x00, 0xE0,
+       0x0D, 0x44, 0x4C, 0xB0,
+
+       0x05, 0x44, 0x54, 0xB0,
+       0x2D, 0x20,
+       0x9B, 0x10,
+
+       0x82, 0x3E, 0x57, 0xE9,
+       0x32, 0xF0, 0x1B, 0xCD,
+
+       0x1E, 0xBD, 0x59, 0x9F,
+       0x83, 0x1E, 0x57, 0xE9,
+
+       0x38, 0x47, 0x38, 0xAF,
+       0x34, 0x20,
+       0x2A, 0x30,
+
+       0x00, 0xE0,
+       0x0D, 0x20,
+       0x32, 0x20,
+       0x05, 0x20,
+
+       0x87, 0x80, 0x57, 0xE9,
+       0x1F, 0x54, 0x57, 0x9F,
+
+       0x17, 0x42, 0x56, 0x9F,
+       0x00, 0xE0,
+       0x3B, 0x6A,
+
+       0x3F, 0x8F, 0x51, 0x9F,
+       0x37, 0x1E, 0x4F, 0xE9,
+
+       0x37, 0x32, 0x2A, 0xAF,
+       0x00, 0xE0,
+       0x32, 0x00,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x27, 0xC0, 0x44, 0xC0,
+
+       0x36, 0x1F, 0x4F, 0xE9,
+       0x1F, 0x1F, 0x26, 0xDF,
+
+       0x37, 0x1B, 0x37, 0xBF,
+       0x17, 0x26, 0x17, 0xDF,
+
+       0x3E, 0x17, 0x4F, 0xE9,
+       0x3F, 0x3F, 0x4F, 0xE9,
+
+       0x34, 0x1F, 0x34, 0xAF,
+       0x2B, 0x05,
+       0xA7, 0x20,
+
+       0x33, 0x2B, 0x37, 0xDF,
+       0x27, 0x17, 0xC0, 0xAF,
+
+       0x34, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2D, 0x21, 0x1A, 0xB0,
+       0x25, 0x21, 0x31, 0xB0,
+
+       0x0D, 0x21, 0x1A, 0xB2,
+       0x05, 0x21, 0x31, 0xB2,
+
+       0x03, 0x80, 0x2A, 0xEA,
+       0x17, 0xC1, 0x2B, 0xBD,
+
+       0x2D, 0x20,
+       0x25, 0x20,
+       0x05, 0x20,
+       0x0D, 0x20,
+
+       0xB3, 0x68,
+       0x97, 0x25,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0xC0, 0x33, 0xAF,
+       0x2F, 0xC0, 0x21, 0xC0,
+
+       0x16, 0x42, 0x56, 0x9F,
+       0x3C, 0x27, 0x4F, 0xE9,
+
+       0x1E, 0x62, 0x57, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x21, 0x31, 0xB4,
+       0x2D, 0x21, 0x1A, 0xB4,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x33, 0x05,
+       0x00, 0xE0,
+       0x28, 0x19, 0x60, 0xEC,
+
+       0x0D, 0x21, 0x1A, 0xB6,
+       0x05, 0x21, 0x31, 0xB6,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0xE0,
+       0x2F, 0x20,
+
+       0x23, 0x3B, 0x33, 0xAD,
+       0x1E, 0x26, 0x1E, 0xDF,
+
+       0xA7, 0x1E, 0x4F, 0xE9,
+       0x17, 0x26, 0x16, 0xDF,
+
+       0x2D, 0x20,
+       0x00, 0xE0,
+       0xA8, 0x3F, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x1E, 0xAF,
+       0x25, 0x20,
+       0x00, 0xE0,
+
+       0xA4, 0x16, 0x4F, 0xE9,
+       0x0F, 0xC0, 0x21, 0xC2,
+
+       0xA6, 0x80, 0x4F, 0xE9,
+       0x1F, 0x62, 0x57, 0x9F,
+
+       0x0D, 0x20,
+       0x05, 0x20,
+       0x2F, 0xC0, 0x21, 0xC6,
+
+       0x3F, 0x2F, 0x5D, 0x9F,
+       0x00, 0xE0,
+       0x0F, 0x20,
+
+       0x17, 0x50, 0x56, 0x9F,
+       0xA5, 0x37, 0x4F, 0xE9,
+
+       0x06, 0xC0, 0x21, 0xC4,
+       0x0F, 0x17, 0x0F, 0xAF,
+
+       0x37, 0x0F, 0x5C, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2F, 0x20,
+       0x00, 0xE0,
+       0xA3, 0x80, 0x4F, 0xE9,
+
+       0x06, 0x20,
+       0x00, 0xE0,
+       0x1F, 0x26, 0x1F, 0xDF,
+
+       0x17, 0x26, 0x17, 0xDF,
+       0x35, 0x17, 0x4F, 0xE9,
+
+       0xA1, 0x1F, 0x4F, 0xE9,
+       0xA2, 0x3F, 0x4F, 0xE9,
+
+       0x06, 0x06, 0x1F, 0xAF,
+       0x39, 0x37, 0x4F, 0xE9,
+
+       0x2F, 0x2F, 0x17, 0xAF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xA0, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x31, 0x80, 0x4F, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x57, 0x39, 0x20, 0xE9,
+
+       0x16, 0x28, 0x20, 0xE9,
+       0x1D, 0x3B, 0x20, 0xE9,
+
+       0x1E, 0x2B, 0x20, 0xE9,
+       0x2B, 0x32, 0x20, 0xE9,
+
+       0x1C, 0x23, 0x20, 0xE9,
+       0x57, 0x36, 0x20, 0xE9,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x40, 0x40, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x90, 0xE2,
+       0x00, 0xE0,
+
+       0x68, 0xFF, 0x20, 0xEA,
+       0x19, 0xC8, 0xC1, 0xCD,
+
+       0x1F, 0xD7, 0x18, 0xBD,
+       0x3F, 0xD7, 0x22, 0xBD,
+
+       0x9F, 0x41, 0x49, 0xBD,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x25, 0x41, 0x49, 0xBD,
+       0x2D, 0x41, 0x51, 0xBD,
+
+       0x0D, 0x80, 0x07, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x35, 0x40, 0x48, 0xBD,
+       0x3D, 0x40, 0x50, 0xBD,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x25, 0x30,
+       0x2D, 0x30,
+
+       0x35, 0x30,
+       0xB5, 0x30,
+       0xBD, 0x30,
+       0x3D, 0x30,
+
+       0x9C, 0xA7, 0x5B, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x67, 0xFF, 0x0A, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC9, 0x41, 0xC8, 0xEC,
+       0x42, 0xE1,
+       0x00, 0xE0,
+
+       0x65, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xC8, 0x40, 0xC0, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x62, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+};
+
+static unsigned char warp_g400_t2gz[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x78, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x69, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x25, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2A, 0x44, 0x54, 0xB4,
+       0x1A, 0x44, 0x64, 0xB4,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x9F, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xBE, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x7D, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gza[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x7C, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x6D, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x29, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0F, 0xCF, 0x74, 0xC6,
+       0x3D, 0xCF, 0x74, 0xC2,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x0F, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB4,
+       0x02, 0x44, 0x64, 0xB4,
+
+       0x2A, 0x44, 0x54, 0xB6,
+       0x1A, 0x44, 0x64, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x9B, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xBA, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x79, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzaf[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x81, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x72, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x2E, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x0F, 0xCF, 0x74, 0xC6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x0F, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB4,
+       0x02, 0x44, 0x64, 0xB4,
+
+       0x2A, 0x44, 0x54, 0xB6,
+       0x1A, 0x44, 0x64, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x3D, 0xCF, 0x75, 0xC6,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x45, 0x55, 0xB6,
+       0x02, 0x45, 0x65, 0xB6,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x3D, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x96, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xB5, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x74, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzf[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x7D, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x6E, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0F, 0xCF, 0x75, 0xC6,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x28, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x31, 0x0F, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x54, 0xB4,
+       0x02, 0x44, 0x64, 0xB4,
+
+       0x2A, 0x45, 0x55, 0xB6,
+       0x1A, 0x45, 0x65, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x9A, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xBB, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x78, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzs[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x85, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x76, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x0F, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x31, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0F, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB4,
+       0x1A, 0x44, 0x64, 0xB4,
+
+       0x0A, 0x45, 0x55, 0xB0,
+       0x02, 0x45, 0x65, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x55, 0xB2,
+       0x1A, 0x45, 0x65, 0xB2,
+
+       0x0A, 0x45, 0x55, 0xB4,
+       0x02, 0x45, 0x65, 0xB4,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x20,
+       0x1A, 0x20,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA7, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x92, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xB2, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x70, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzsa[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x8A, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x7B, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x0F, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x36, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0F, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB4,
+       0x1A, 0x44, 0x64, 0xB4,
+
+       0x0A, 0x45, 0x55, 0xB0,
+       0x02, 0x45, 0x65, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x55, 0xB2,
+       0x1A, 0x45, 0x65, 0xB2,
+
+       0x0A, 0x45, 0x55, 0xB4,
+       0x02, 0x45, 0x65, 0xB4,
+
+       0x0F, 0xCF, 0x74, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB6,
+       0x1A, 0x44, 0x64, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x8D, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xAD, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x6B, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzsaf[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x8E, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x7F, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x0F, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x3A, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0F, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB4,
+       0x1A, 0x44, 0x64, 0xB4,
+
+       0x0A, 0x45, 0x55, 0xB0,
+       0x02, 0x45, 0x65, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x55, 0xB2,
+       0x1A, 0x45, 0x65, 0xB2,
+
+       0x0A, 0x45, 0x55, 0xB4,
+       0x02, 0x45, 0x65, 0xB4,
+
+       0x0F, 0xCF, 0x74, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB6,
+       0x1A, 0x44, 0x64, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x45, 0x55, 0xB6,
+       0x02, 0x45, 0x65, 0xB6,
+
+       0x3D, 0xCF, 0x75, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x3D, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x89, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xA9, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x67, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_t2gzsf[] = {
+
+       0x00, 0x8A, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x0A, 0x40, 0x50, 0xBF,
+       0x2A, 0x40, 0x60, 0xBF,
+
+       0x32, 0x41, 0x51, 0xBF,
+       0x3A, 0x41, 0x61, 0xBF,
+
+       0xC3, 0x6B,
+       0xD3, 0x6B,
+       0x00, 0x8A, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x23, 0x9F,
+       0x00, 0xE0,
+       0x51, 0x04,
+
+       0x90, 0xE2,
+       0x61, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x51, 0x41, 0xE0, 0xEC,
+       0x39, 0x67, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x63, 0xA0, 0xE8,
+
+       0x61, 0x41, 0xE0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x8A, 0x80, 0x15, 0xEA,
+       0x10, 0x04,
+       0x20, 0x04,
+
+       0x61, 0x51, 0xE0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x52, 0xBF,
+       0x0F, 0x52, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x62, 0xBF,
+       0x1E, 0x51, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x0E, 0x61, 0x60, 0xEA,
+
+       0x32, 0x40, 0x50, 0xBD,
+       0x22, 0x40, 0x60, 0xBD,
+
+       0x12, 0x41, 0x51, 0xBD,
+       0x3A, 0x41, 0x61, 0xBD,
+
+       0xBF, 0x2F, 0x0E, 0xBD,
+       0x97, 0xE2,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x35, 0x48, 0xB1, 0xE8,
+       0x3D, 0x59, 0xB1, 0xE8,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x56, 0x31, 0x56, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x66, 0x31, 0x66, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x57, 0x39, 0x57, 0xBF,
+       0x67, 0x39, 0x67, 0xBF,
+
+       0x7B, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x35, 0x00,
+       0x3D, 0x00,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0x8D, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x75, 0xF8, 0xEC,
+       0x35, 0x20,
+       0x3D, 0x20,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x53, 0x53, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x0E, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x48, 0x35, 0x48, 0xBF,
+       0x58, 0x35, 0x58, 0xBF,
+
+       0x68, 0x35, 0x68, 0xBF,
+       0x49, 0x3D, 0x49, 0xBF,
+
+       0x59, 0x3D, 0x59, 0xBF,
+       0x69, 0x3D, 0x69, 0xBF,
+
+       0x63, 0x63, 0x2D, 0xDF,
+       0x4D, 0x7D, 0xF8, 0xEC,
+
+       0x59, 0xE3,
+       0x00, 0xE0,
+       0xB8, 0x38, 0x33, 0xBF,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x18, 0x3A, 0x41, 0xE9,
+
+       0x3F, 0x53, 0xA0, 0xE8,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x63, 0xA0, 0xE8,
+
+       0x50, 0x70, 0xF8, 0xEC,
+       0x2B, 0x50, 0x3C, 0xE9,
+
+       0x1F, 0x0F, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x59, 0x78, 0xF8, 0xEC,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x56, 0x3F, 0x56, 0xDF,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x66, 0x3D, 0x66, 0xDF,
+
+       0x1D, 0x32, 0x41, 0xE9,
+       0x67, 0x3D, 0x67, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3F, 0x57, 0xDF,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x59, 0x3F, 0x59, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x69, 0x3D, 0x69, 0xDF,
+
+       0x48, 0x37, 0x48, 0xDF,
+       0x58, 0x3F, 0x58, 0xDF,
+
+       0x68, 0x3D, 0x68, 0xDF,
+       0x49, 0x37, 0x49, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x0F, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x54, 0xB0,
+       0x02, 0x44, 0x64, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB2,
+       0x1A, 0x44, 0x64, 0xB2,
+
+       0x36, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0F, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x54, 0xB4,
+       0x1A, 0x44, 0x64, 0xB4,
+
+       0x0A, 0x45, 0x55, 0xB0,
+       0x02, 0x45, 0x65, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x55, 0xB2,
+       0x1A, 0x45, 0x65, 0xB2,
+
+       0x0A, 0x45, 0x55, 0xB4,
+       0x02, 0x45, 0x65, 0xB4,
+
+       0x0F, 0xCF, 0x75, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x31, 0x0F, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x55, 0xB6,
+       0x1A, 0x45, 0x65, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x56, 0xBF,
+       0x1A, 0x46, 0x66, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x57, 0xBF,
+       0x02, 0x47, 0x67, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x53, 0xBF,
+       0x1A, 0x43, 0x63, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x48, 0x58, 0xBF,
+       0x02, 0x48, 0x68, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x2A, 0x49, 0x59, 0xBF,
+       0x1A, 0x49, 0x69, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x82, 0x30, 0x57, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x83, 0x38, 0x57, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x84, 0x31, 0x5E, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x85, 0x39, 0x5E, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x87, 0x77, 0x57, 0xE9,
+       0x8B, 0x3E, 0xBF, 0xEA,
+
+       0x80, 0x30, 0x57, 0xE9,
+       0x81, 0x38, 0x57, 0xE9,
+
+       0x82, 0x31, 0x57, 0xE9,
+       0x86, 0x78, 0x57, 0xE9,
+
+       0x83, 0x39, 0x57, 0xE9,
+       0x87, 0x79, 0x57, 0xE9,
+
+       0x30, 0x1F, 0x5F, 0xE9,
+       0x8A, 0x34, 0x20, 0xE9,
+
+       0x8B, 0x3C, 0x20, 0xE9,
+       0x37, 0x50, 0x60, 0xBD,
+
+       0x57, 0x0D, 0x20, 0xE9,
+       0x35, 0x51, 0x61, 0xBD,
+
+       0x2B, 0x50, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x0E, 0x77,
+
+       0x24, 0x51, 0x20, 0xE9,
+       0x8D, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x0E, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x0B, 0x46, 0xA0, 0xE8,
+       0x1B, 0x56, 0xA0, 0xE8,
+
+       0x2B, 0x66, 0xA0, 0xE8,
+       0x0C, 0x47, 0xA0, 0xE8,
+
+       0x1C, 0x57, 0xA0, 0xE8,
+       0x2C, 0x67, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x57, 0x80, 0x57, 0xCF,
+
+       0x66, 0x33, 0x66, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x67, 0x3B, 0x67, 0xCF,
+
+       0x0B, 0x48, 0xA0, 0xE8,
+       0x1B, 0x58, 0xA0, 0xE8,
+
+       0x2B, 0x68, 0xA0, 0xE8,
+       0x0C, 0x49, 0xA0, 0xE8,
+
+       0x1C, 0x59, 0xA0, 0xE8,
+       0x2C, 0x69, 0xA0, 0xE8,
+
+       0x0B, 0x00,
+       0x1B, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x0C, 0x00,
+       0x1C, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x0B, 0x65,
+       0x1B, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x0C, 0x65,
+       0x1C, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x0B, 0x1B, 0x60, 0xEC,
+       0x34, 0xD7, 0x34, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x0C, 0x1C, 0x60, 0xEC,
+
+       0x3C, 0xD7, 0x3C, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x0B, 0x2B, 0xDE, 0xE8,
+       0x1B, 0x80, 0xDE, 0xE8,
+
+       0x34, 0x80, 0x34, 0xBD,
+       0x3C, 0x80, 0x3C, 0xBD,
+
+       0x33, 0xD7, 0x0B, 0xBD,
+       0x3B, 0xD7, 0x1B, 0xBD,
+
+       0x48, 0x80, 0x48, 0xCF,
+       0x59, 0x80, 0x59, 0xCF,
+
+       0x68, 0x33, 0x68, 0xCF,
+       0x49, 0x3B, 0x49, 0xCF,
+
+       0xAD, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x58, 0x33, 0x58, 0xCF,
+       0x69, 0x3B, 0x69, 0xCF,
+
+       0x6B, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgz[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x58, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x4A, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x1D, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x2A, 0x44, 0x4C, 0xB4,
+       0x1A, 0x44, 0x54, 0xB4,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0xAF, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xD6, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x9D, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgza[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x5C, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x4E, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x27, 0xCF, 0x74, 0xC6,
+       0x3D, 0xCF, 0x74, 0xC2,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x20, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x27, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x4C, 0xB4,
+       0x02, 0x44, 0x54, 0xB4,
+
+       0x2A, 0x44, 0x4C, 0xB6,
+       0x1A, 0x44, 0x54, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0xAB, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xD3, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x99, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzaf[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x61, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x53, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x26, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x27, 0xCF, 0x74, 0xC6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x27, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x4C, 0xB4,
+       0x02, 0x44, 0x54, 0xB4,
+
+       0x2A, 0x44, 0x4C, 0xB6,
+       0x1A, 0x44, 0x54, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x3D, 0xCF, 0x75, 0xC6,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x45, 0x4D, 0xB6,
+       0x02, 0x45, 0x55, 0xB6,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x3D, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0xA6, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xCD, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x94, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzf[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x5D, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x4F, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x34, 0x80, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x27, 0xCF, 0x75, 0xC6,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x20, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x3D, 0xCF, 0x74, 0xC2,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x31, 0x27, 0x20, 0xE9,
+
+       0x0A, 0x44, 0x4C, 0xB4,
+       0x02, 0x44, 0x54, 0xB4,
+
+       0x2A, 0x45, 0x4D, 0xB6,
+       0x1A, 0x45, 0x55, 0xB6,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x38, 0x3D, 0x20, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0xAA, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xD3, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x98, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzs[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x65, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x57, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x27, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x29, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x27, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB4,
+       0x1A, 0x44, 0x54, 0xB4,
+
+       0x0A, 0x45, 0x4D, 0xB0,
+       0x02, 0x45, 0x55, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x4D, 0xB2,
+       0x1A, 0x45, 0x55, 0xB2,
+
+       0x0A, 0x45, 0x4D, 0xB4,
+       0x02, 0x45, 0x55, 0xB4,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x20,
+       0x02, 0x20,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA7, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0xA2, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xCA, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x90, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzsa[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x6A, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x5C, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x27, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x2E, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x27, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB4,
+       0x1A, 0x44, 0x54, 0xB4,
+
+       0x0A, 0x45, 0x4D, 0xB0,
+       0x02, 0x45, 0x55, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x4D, 0xB2,
+       0x1A, 0x45, 0x55, 0xB2,
+
+       0x0A, 0x45, 0x4D, 0xB4,
+       0x02, 0x45, 0x55, 0xB4,
+
+       0x27, 0xCF, 0x74, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB6,
+       0x1A, 0x44, 0x54, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0x9D, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xC5, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x8B, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzsaf[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x6E, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x60, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x27, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x32, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x27, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB4,
+       0x1A, 0x44, 0x54, 0xB4,
+
+       0x0A, 0x45, 0x4D, 0xB0,
+       0x02, 0x45, 0x55, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x4D, 0xB2,
+       0x1A, 0x45, 0x55, 0xB2,
+
+       0x0A, 0x45, 0x4D, 0xB4,
+       0x02, 0x45, 0x55, 0xB4,
+
+       0x27, 0xCF, 0x74, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9C, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB6,
+       0x1A, 0x44, 0x54, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x45, 0x4D, 0xB6,
+       0x02, 0x45, 0x55, 0xB6,
+
+       0x3D, 0xCF, 0x75, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x3D, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x9D, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x9E, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x30, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x38, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0x99, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xC1, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x87, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
+
+static unsigned char warp_g400_tgzsf[] = {
+
+       0x00, 0x88, 0x98, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+       0xFF, 0x80, 0xC0, 0xE9,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x22, 0x40, 0x48, 0xBF,
+       0x2A, 0x40, 0x50, 0xBF,
+
+       0x32, 0x41, 0x49, 0xBF,
+       0x3A, 0x41, 0x51, 0xBF,
+
+       0xC3, 0x6B,
+       0xCB, 0x6B,
+       0x00, 0x88, 0x98, 0xE9,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x96, 0xE2,
+       0x41, 0x04,
+
+       0x7B, 0x43, 0xA0, 0xE8,
+       0x73, 0x4B, 0xA0, 0xE8,
+
+       0xAD, 0xEE, 0x29, 0x9F,
+       0x00, 0xE0,
+       0x49, 0x04,
+
+       0x90, 0xE2,
+       0x51, 0x04,
+       0x31, 0x46, 0xB1, 0xE8,
+
+       0x49, 0x41, 0xC0, 0xEC,
+       0x39, 0x57, 0xB1, 0xE8,
+
+       0x00, 0x04,
+       0x46, 0xE2,
+       0x73, 0x53, 0xA0, 0xE8,
+
+       0x51, 0x41, 0xC0, 0xEC,
+       0x31, 0x00,
+       0x39, 0x00,
+
+       0x6A, 0x80, 0x15, 0xEA,
+       0x08, 0x04,
+       0x10, 0x04,
+
+       0x51, 0x49, 0xC0, 0xEC,
+       0x2F, 0x41, 0x60, 0xEA,
+
+       0x31, 0x20,
+       0x39, 0x20,
+       0x1F, 0x42, 0xA0, 0xE8,
+
+       0x2A, 0x42, 0x4A, 0xBF,
+       0x27, 0x4A, 0xA0, 0xE8,
+
+       0x1A, 0x42, 0x52, 0xBF,
+       0x1E, 0x49, 0x60, 0xEA,
+
+       0x73, 0x7B, 0xC8, 0xEC,
+       0x26, 0x51, 0x60, 0xEA,
+
+       0x32, 0x40, 0x48, 0xBD,
+       0x22, 0x40, 0x50, 0xBD,
+
+       0x12, 0x41, 0x49, 0xBD,
+       0x3A, 0x41, 0x51, 0xBD,
+
+       0xBF, 0x2F, 0x26, 0xBD,
+       0x00, 0xE0,
+       0x7B, 0x72,
+
+       0x32, 0x20,
+       0x22, 0x20,
+       0x12, 0x20,
+       0x3A, 0x20,
+
+       0x46, 0x31, 0x46, 0xBF,
+       0x4E, 0x31, 0x4E, 0xBF,
+
+       0xB3, 0xE2, 0x2D, 0x9F,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x56, 0x31, 0x56, 0xBF,
+       0x47, 0x39, 0x47, 0xBF,
+
+       0x4F, 0x39, 0x4F, 0xBF,
+       0x57, 0x39, 0x57, 0xBF,
+
+       0x5C, 0x80, 0x07, 0xEA,
+       0x24, 0x41, 0x20, 0xE9,
+
+       0x42, 0x73, 0xF8, 0xEC,
+       0x00, 0xE0,
+       0x2D, 0x73,
+
+       0x33, 0x72,
+       0x0C, 0xE3,
+       0xA5, 0x2F, 0x1E, 0xBD,
+
+       0x43, 0x43, 0x2D, 0xDF,
+       0x4B, 0x4B, 0x2D, 0xDF,
+
+       0xAE, 0x1E, 0x26, 0xBD,
+       0x58, 0xE3,
+       0x33, 0x66,
+
+       0x53, 0x53, 0x2D, 0xDF,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0xB8, 0x38, 0x33, 0xBF,
+       0x00, 0xE0,
+       0x59, 0xE3,
+
+       0x1E, 0x12, 0x41, 0xE9,
+       0x1A, 0x22, 0x41, 0xE9,
+
+       0x2B, 0x40, 0x3D, 0xE9,
+       0x3F, 0x4B, 0xA0, 0xE8,
+
+       0x2D, 0x73,
+       0x30, 0x76,
+       0x05, 0x80, 0x3D, 0xEA,
+
+       0x37, 0x43, 0xA0, 0xE8,
+       0x3D, 0x53, 0xA0, 0xE8,
+
+       0x48, 0x70, 0xF8, 0xEC,
+       0x2B, 0x48, 0x3C, 0xE9,
+
+       0x1F, 0x27, 0xBC, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x15, 0xC0, 0x20, 0xE9,
+       0x15, 0xC0, 0x20, 0xE9,
+
+       0x18, 0x3A, 0x41, 0xE9,
+       0x1D, 0x32, 0x41, 0xE9,
+
+       0x2A, 0x40, 0x20, 0xE9,
+       0x56, 0x3D, 0x56, 0xDF,
+
+       0x46, 0x37, 0x46, 0xDF,
+       0x4E, 0x3F, 0x4E, 0xDF,
+
+       0x16, 0x30, 0x20, 0xE9,
+       0x4F, 0x3F, 0x4F, 0xDF,
+
+       0x47, 0x37, 0x47, 0xDF,
+       0x57, 0x3D, 0x57, 0xDF,
+
+       0x32, 0x32, 0x2D, 0xDF,
+       0x22, 0x22, 0x2D, 0xDF,
+
+       0x12, 0x12, 0x2D, 0xDF,
+       0x3A, 0x3A, 0x2D, 0xDF,
+
+       0x27, 0xCF, 0x74, 0xC2,
+       0x37, 0xCF, 0x74, 0xC4,
+
+       0x0A, 0x44, 0x4C, 0xB0,
+       0x02, 0x44, 0x54, 0xB0,
+
+       0x3D, 0xCF, 0x74, 0xC0,
+       0x34, 0x37, 0x20, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x38, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3C, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB2,
+       0x1A, 0x44, 0x54, 0xB2,
+
+       0x2E, 0x80, 0x3A, 0xEA,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x27, 0xCF, 0x75, 0xC0,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x32, 0x31, 0x5F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x33, 0x39, 0x5F, 0xE9,
+
+       0x3D, 0xCF, 0x75, 0xC2,
+       0x37, 0xCF, 0x75, 0xC4,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA6, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA3, 0x3D, 0x20, 0xE9,
+
+       0x2A, 0x44, 0x4C, 0xB4,
+       0x1A, 0x44, 0x54, 0xB4,
+
+       0x0A, 0x45, 0x4D, 0xB0,
+       0x02, 0x45, 0x55, 0xB0,
+
+       0x88, 0x73, 0x5E, 0xE9,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA0, 0x37, 0x20, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x3E, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x3F, 0x38, 0x4F, 0xE9,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x3A, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x3B, 0x39, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x4D, 0xB2,
+       0x1A, 0x45, 0x55, 0xB2,
+
+       0x0A, 0x45, 0x4D, 0xB4,
+       0x02, 0x45, 0x55, 0xB4,
+
+       0x27, 0xCF, 0x75, 0xC6,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0xA7, 0x30, 0x4F, 0xE9,
+       0x0A, 0x20,
+       0x02, 0x20,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x31, 0x27, 0x20, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA8, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x45, 0x4D, 0xB6,
+       0x1A, 0x45, 0x55, 0xB6,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x36, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x37, 0x39, 0x4F, 0xE9,
+
+       0x00, 0x80, 0x00, 0xE8,
+       0x2A, 0x20,
+       0x1A, 0x20,
+
+       0x2A, 0x46, 0x4E, 0xBF,
+       0x1A, 0x46, 0x56, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA4, 0x31, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA5, 0x39, 0x4F, 0xE9,
+
+       0x0A, 0x47, 0x4F, 0xBF,
+       0x02, 0x47, 0x57, 0xBF,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0xA1, 0x30, 0x4F, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0xA2, 0x38, 0x4F, 0xE9,
+
+       0x2A, 0x43, 0x4B, 0xBF,
+       0x1A, 0x43, 0x53, 0xBF,
+
+       0x30, 0x50, 0x2E, 0x9F,
+       0x35, 0x31, 0x4F, 0xE9,
+
+       0x38, 0x21, 0x2C, 0x9F,
+       0x39, 0x39, 0x4F, 0xE9,
+
+       0x31, 0x53, 0x2F, 0x9F,
+       0x80, 0x31, 0x57, 0xE9,
+
+       0x39, 0xE5, 0x2C, 0x9F,
+       0x81, 0x39, 0x57, 0xE9,
+
+       0x37, 0x48, 0x50, 0xBD,
+       0x8A, 0x36, 0x20, 0xE9,
+
+       0x86, 0x76, 0x57, 0xE9,
+       0x8B, 0x3E, 0x20, 0xE9,
+
+       0x82, 0x30, 0x57, 0xE9,
+       0x87, 0x77, 0x57, 0xE9,
+
+       0x83, 0x38, 0x57, 0xE9,
+       0x35, 0x49, 0x51, 0xBD,
+
+       0x84, 0x31, 0x5E, 0xE9,
+       0x30, 0x1F, 0x5F, 0xE9,
+
+       0x85, 0x39, 0x5E, 0xE9,
+       0x57, 0x25, 0x20, 0xE9,
+
+       0x2B, 0x48, 0x20, 0xE9,
+       0x1D, 0x37, 0xE1, 0xEA,
+
+       0x1E, 0x35, 0xE1, 0xEA,
+       0x00, 0xE0,
+       0x26, 0x77,
+
+       0x24, 0x49, 0x20, 0xE9,
+       0x9D, 0xFF, 0x20, 0xEA,
+
+       0x16, 0x26, 0x20, 0xE9,
+       0x57, 0x2E, 0xBF, 0xEA,
+
+       0x1C, 0x46, 0xA0, 0xE8,
+       0x23, 0x4E, 0xA0, 0xE8,
+
+       0x2B, 0x56, 0xA0, 0xE8,
+       0x1D, 0x47, 0xA0, 0xE8,
+
+       0x24, 0x4F, 0xA0, 0xE8,
+       0x2C, 0x57, 0xA0, 0xE8,
+
+       0x1C, 0x00,
+       0x23, 0x00,
+       0x2B, 0x00,
+       0x00, 0xE0,
+
+       0x1D, 0x00,
+       0x24, 0x00,
+       0x2C, 0x00,
+       0x00, 0xE0,
+
+       0x1C, 0x65,
+       0x23, 0x65,
+       0x2B, 0x65,
+       0x00, 0xE0,
+
+       0x1D, 0x65,
+       0x24, 0x65,
+       0x2C, 0x65,
+       0x00, 0xE0,
+
+       0x1C, 0x23, 0x60, 0xEC,
+       0x36, 0xD7, 0x36, 0xAD,
+
+       0x2B, 0x80, 0x60, 0xEC,
+       0x1D, 0x24, 0x60, 0xEC,
+
+       0x3E, 0xD7, 0x3E, 0xAD,
+       0x2C, 0x80, 0x60, 0xEC,
+
+       0x1C, 0x2B, 0xDE, 0xE8,
+       0x23, 0x80, 0xDE, 0xE8,
+
+       0x36, 0x80, 0x36, 0xBD,
+       0x3E, 0x80, 0x3E, 0xBD,
+
+       0x33, 0xD7, 0x1C, 0xBD,
+       0x3B, 0xD7, 0x23, 0xBD,
+
+       0x46, 0x80, 0x46, 0xCF,
+       0x4F, 0x80, 0x4F, 0xCF,
+
+       0x56, 0x33, 0x56, 0xCF,
+       0x47, 0x3B, 0x47, 0xCF,
+
+       0xC5, 0xFF, 0x20, 0xEA,
+       0x00, 0x80, 0x00, 0xE8,
+
+       0x4E, 0x33, 0x4E, 0xCF,
+       0x57, 0x3B, 0x57, 0xCF,
+
+       0x8B, 0xFF, 0x20, 0xEA,
+       0x57, 0xC0, 0xBF, 0xEA,
+
+       0x00, 0x80, 0xA0, 0xE9,
+       0x00, 0x00, 0xD8, 0xEC,
+
+};
diff --git a/drivers/gpu/drm/mga/mga_warp.c b/drivers/gpu/drm/mga/mga_warp.c
new file mode 100644 (file)
index 0000000..651b93c
--- /dev/null
@@ -0,0 +1,193 @@
+/* mga_warp.c -- Matrox G200/G400 WARP engine management -*- linux-c -*-
+ * Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
+ *
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "mga_drm.h"
+#include "mga_drv.h"
+#include "mga_ucode.h"
+
+#define MGA_WARP_CODE_ALIGN            256     /* in bytes */
+
+#define WARP_UCODE_SIZE( which )                                       \
+       ((sizeof(which) / MGA_WARP_CODE_ALIGN + 1) * MGA_WARP_CODE_ALIGN)
+
+#define WARP_UCODE_INSTALL( which, where )                             \
+do {                                                                   \
+       DRM_DEBUG( " pcbase = 0x%08lx  vcbase = %p\n", pcbase, vcbase );\
+       dev_priv->warp_pipe_phys[where] = pcbase;                       \
+       memcpy( vcbase, which, sizeof(which) );                         \
+       pcbase += WARP_UCODE_SIZE( which );                             \
+       vcbase += WARP_UCODE_SIZE( which );                             \
+} while (0)
+
+static const unsigned int mga_warp_g400_microcode_size =
+    (WARP_UCODE_SIZE(warp_g400_tgz) +
+     WARP_UCODE_SIZE(warp_g400_tgza) +
+     WARP_UCODE_SIZE(warp_g400_tgzaf) +
+     WARP_UCODE_SIZE(warp_g400_tgzf) +
+     WARP_UCODE_SIZE(warp_g400_tgzs) +
+     WARP_UCODE_SIZE(warp_g400_tgzsa) +
+     WARP_UCODE_SIZE(warp_g400_tgzsaf) +
+     WARP_UCODE_SIZE(warp_g400_tgzsf) +
+     WARP_UCODE_SIZE(warp_g400_t2gz) +
+     WARP_UCODE_SIZE(warp_g400_t2gza) +
+     WARP_UCODE_SIZE(warp_g400_t2gzaf) +
+     WARP_UCODE_SIZE(warp_g400_t2gzf) +
+     WARP_UCODE_SIZE(warp_g400_t2gzs) +
+     WARP_UCODE_SIZE(warp_g400_t2gzsa) +
+     WARP_UCODE_SIZE(warp_g400_t2gzsaf) + WARP_UCODE_SIZE(warp_g400_t2gzsf));
+
+static const unsigned int mga_warp_g200_microcode_size =
+    (WARP_UCODE_SIZE(warp_g200_tgz) +
+     WARP_UCODE_SIZE(warp_g200_tgza) +
+     WARP_UCODE_SIZE(warp_g200_tgzaf) +
+     WARP_UCODE_SIZE(warp_g200_tgzf) +
+     WARP_UCODE_SIZE(warp_g200_tgzs) +
+     WARP_UCODE_SIZE(warp_g200_tgzsa) +
+     WARP_UCODE_SIZE(warp_g200_tgzsaf) + WARP_UCODE_SIZE(warp_g200_tgzsf));
+
+unsigned int mga_warp_microcode_size(const drm_mga_private_t * dev_priv)
+{
+       switch (dev_priv->chipset) {
+       case MGA_CARD_TYPE_G400:
+       case MGA_CARD_TYPE_G550:
+               return PAGE_ALIGN(mga_warp_g400_microcode_size);
+       case MGA_CARD_TYPE_G200:
+               return PAGE_ALIGN(mga_warp_g200_microcode_size);
+       default:
+               return 0;
+       }
+}
+
+static int mga_warp_install_g400_microcode(drm_mga_private_t * dev_priv)
+{
+       unsigned char *vcbase = dev_priv->warp->handle;
+       unsigned long pcbase = dev_priv->warp->offset;
+
+       memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
+
+       WARP_UCODE_INSTALL(warp_g400_tgz, MGA_WARP_TGZ);
+       WARP_UCODE_INSTALL(warp_g400_tgzf, MGA_WARP_TGZF);
+       WARP_UCODE_INSTALL(warp_g400_tgza, MGA_WARP_TGZA);
+       WARP_UCODE_INSTALL(warp_g400_tgzaf, MGA_WARP_TGZAF);
+       WARP_UCODE_INSTALL(warp_g400_tgzs, MGA_WARP_TGZS);
+       WARP_UCODE_INSTALL(warp_g400_tgzsf, MGA_WARP_TGZSF);
+       WARP_UCODE_INSTALL(warp_g400_tgzsa, MGA_WARP_TGZSA);
+       WARP_UCODE_INSTALL(warp_g400_tgzsaf, MGA_WARP_TGZSAF);
+
+       WARP_UCODE_INSTALL(warp_g400_t2gz, MGA_WARP_T2GZ);
+       WARP_UCODE_INSTALL(warp_g400_t2gzf, MGA_WARP_T2GZF);
+       WARP_UCODE_INSTALL(warp_g400_t2gza, MGA_WARP_T2GZA);
+       WARP_UCODE_INSTALL(warp_g400_t2gzaf, MGA_WARP_T2GZAF);
+       WARP_UCODE_INSTALL(warp_g400_t2gzs, MGA_WARP_T2GZS);
+       WARP_UCODE_INSTALL(warp_g400_t2gzsf, MGA_WARP_T2GZSF);
+       WARP_UCODE_INSTALL(warp_g400_t2gzsa, MGA_WARP_T2GZSA);
+       WARP_UCODE_INSTALL(warp_g400_t2gzsaf, MGA_WARP_T2GZSAF);
+
+       return 0;
+}
+
+static int mga_warp_install_g200_microcode(drm_mga_private_t * dev_priv)
+{
+       unsigned char *vcbase = dev_priv->warp->handle;
+       unsigned long pcbase = dev_priv->warp->offset;
+
+       memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
+
+       WARP_UCODE_INSTALL(warp_g200_tgz, MGA_WARP_TGZ);
+       WARP_UCODE_INSTALL(warp_g200_tgzf, MGA_WARP_TGZF);
+       WARP_UCODE_INSTALL(warp_g200_tgza, MGA_WARP_TGZA);
+       WARP_UCODE_INSTALL(warp_g200_tgzaf, MGA_WARP_TGZAF);
+       WARP_UCODE_INSTALL(warp_g200_tgzs, MGA_WARP_TGZS);
+       WARP_UCODE_INSTALL(warp_g200_tgzsf, MGA_WARP_TGZSF);
+       WARP_UCODE_INSTALL(warp_g200_tgzsa, MGA_WARP_TGZSA);
+       WARP_UCODE_INSTALL(warp_g200_tgzsaf, MGA_WARP_TGZSAF);
+
+       return 0;
+}
+
+int mga_warp_install_microcode(drm_mga_private_t * dev_priv)
+{
+       const unsigned int size = mga_warp_microcode_size(dev_priv);
+
+       DRM_DEBUG("MGA ucode size = %d bytes\n", size);
+       if (size > dev_priv->warp->size) {
+               DRM_ERROR("microcode too large! (%u > %lu)\n",
+                         size, dev_priv->warp->size);
+               return -ENOMEM;
+       }
+
+       switch (dev_priv->chipset) {
+       case MGA_CARD_TYPE_G400:
+       case MGA_CARD_TYPE_G550:
+               return mga_warp_install_g400_microcode(dev_priv);
+       case MGA_CARD_TYPE_G200:
+               return mga_warp_install_g200_microcode(dev_priv);
+       default:
+               return -EINVAL;
+       }
+}
+
+#define WMISC_EXPECTED         (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
+
+int mga_warp_init(drm_mga_private_t * dev_priv)
+{
+       u32 wmisc;
+
+       /* FIXME: Get rid of these damned magic numbers...
+        */
+       switch (dev_priv->chipset) {
+       case MGA_CARD_TYPE_G400:
+       case MGA_CARD_TYPE_G550:
+               MGA_WRITE(MGA_WIADDR2, MGA_WMODE_SUSPEND);
+               MGA_WRITE(MGA_WGETMSB, 0x00000E00);
+               MGA_WRITE(MGA_WVRTXSZ, 0x00001807);
+               MGA_WRITE(MGA_WACCEPTSEQ, 0x18000000);
+               break;
+       case MGA_CARD_TYPE_G200:
+               MGA_WRITE(MGA_WIADDR, MGA_WMODE_SUSPEND);
+               MGA_WRITE(MGA_WGETMSB, 0x1606);
+               MGA_WRITE(MGA_WVRTXSZ, 7);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       MGA_WRITE(MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
+                             MGA_WMASTER_ENABLE | MGA_WCACHEFLUSH_ENABLE));
+       wmisc = MGA_READ(MGA_WMISC);
+       if (wmisc != WMISC_EXPECTED) {
+               DRM_ERROR("WARP engine config failed! 0x%x != 0x%x\n",
+                         wmisc, WMISC_EXPECTED);
+               return -EINVAL;
+       }
+
+       return 0;
+}
diff --git a/drivers/gpu/drm/r128/Makefile b/drivers/gpu/drm/r128/Makefile
new file mode 100644 (file)
index 0000000..1cc72ae
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+r128-y   := r128_drv.o r128_cce.o r128_state.o r128_irq.o
+
+r128-$(CONFIG_COMPAT)   += r128_ioc32.o
+
+obj-$(CONFIG_DRM_R128) += r128.o
diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
new file mode 100644 (file)
index 0000000..c31afbd
--- /dev/null
@@ -0,0 +1,935 @@
+/* r128_cce.c -- ATI Rage 128 driver -*- linux-c -*-
+ * Created: Wed Apr  5 19:24:19 2000 by kevin@precisioninsight.com
+ */
+/*
+ * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "r128_drm.h"
+#include "r128_drv.h"
+
+#define R128_FIFO_DEBUG                0
+
+/* CCE microcode (from ATI) */
+static u32 r128_cce_microcode[] = {
+       0, 276838400, 0, 268449792, 2, 142, 2, 145, 0, 1076765731, 0,
+       1617039951, 0, 774592877, 0, 1987540286, 0, 2307490946U, 0,
+       599558925, 0, 589505315, 0, 596487092, 0, 589505315, 1,
+       11544576, 1, 206848, 1, 311296, 1, 198656, 2, 912273422, 11,
+       262144, 0, 0, 1, 33559837, 1, 7438, 1, 14809, 1, 6615, 12, 28,
+       1, 6614, 12, 28, 2, 23, 11, 18874368, 0, 16790922, 1, 409600, 9,
+       30, 1, 147854772, 16, 420483072, 3, 8192, 0, 10240, 1, 198656,
+       1, 15630, 1, 51200, 10, 34858, 9, 42, 1, 33559823, 2, 10276, 1,
+       15717, 1, 15718, 2, 43, 1, 15936948, 1, 570480831, 1, 14715071,
+       12, 322123831, 1, 33953125, 12, 55, 1, 33559908, 1, 15718, 2,
+       46, 4, 2099258, 1, 526336, 1, 442623, 4, 4194365, 1, 509952, 1,
+       459007, 3, 0, 12, 92, 2, 46, 12, 176, 1, 15734, 1, 206848, 1,
+       18432, 1, 133120, 1, 100670734, 1, 149504, 1, 165888, 1,
+       15975928, 1, 1048576, 6, 3145806, 1, 15715, 16, 2150645232U, 2,
+       268449859, 2, 10307, 12, 176, 1, 15734, 1, 15735, 1, 15630, 1,
+       15631, 1, 5253120, 6, 3145810, 16, 2150645232U, 1, 15864, 2, 82,
+       1, 343310, 1, 1064207, 2, 3145813, 1, 15728, 1, 7817, 1, 15729,
+       3, 15730, 12, 92, 2, 98, 1, 16168, 1, 16167, 1, 16002, 1, 16008,
+       1, 15974, 1, 15975, 1, 15990, 1, 15976, 1, 15977, 1, 15980, 0,
+       15981, 1, 10240, 1, 5253120, 1, 15720, 1, 198656, 6, 110, 1,
+       180224, 1, 103824738, 2, 112, 2, 3145839, 0, 536885440, 1,
+       114880, 14, 125, 12, 206975, 1, 33559995, 12, 198784, 0,
+       33570236, 1, 15803, 0, 15804, 3, 294912, 1, 294912, 3, 442370,
+       1, 11544576, 0, 811612160, 1, 12593152, 1, 11536384, 1,
+       14024704, 7, 310382726, 0, 10240, 1, 14796, 1, 14797, 1, 14793,
+       1, 14794, 0, 14795, 1, 268679168, 1, 9437184, 1, 268449792, 1,
+       198656, 1, 9452827, 1, 1075854602, 1, 1075854603, 1, 557056, 1,
+       114880, 14, 159, 12, 198784, 1, 1109409213, 12, 198783, 1,
+       1107312059, 12, 198784, 1, 1109409212, 2, 162, 1, 1075854781, 1,
+       1073757627, 1, 1075854780, 1, 540672, 1, 10485760, 6, 3145894,
+       16, 274741248, 9, 168, 3, 4194304, 3, 4209949, 0, 0, 0, 256, 14,
+       174, 1, 114857, 1, 33560007, 12, 176, 0, 10240, 1, 114858, 1,
+       33560018, 1, 114857, 3, 33560007, 1, 16008, 1, 114874, 1,
+       33560360, 1, 114875, 1, 33560154, 0, 15963, 0, 256, 0, 4096, 1,
+       409611, 9, 188, 0, 10240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+static int R128_READ_PLL(struct drm_device * dev, int addr)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+
+       R128_WRITE8(R128_CLOCK_CNTL_INDEX, addr & 0x1f);
+       return R128_READ(R128_CLOCK_CNTL_DATA);
+}
+
+#if R128_FIFO_DEBUG
+static void r128_status(drm_r128_private_t * dev_priv)
+{
+       printk("GUI_STAT           = 0x%08x\n",
+              (unsigned int)R128_READ(R128_GUI_STAT));
+       printk("PM4_STAT           = 0x%08x\n",
+              (unsigned int)R128_READ(R128_PM4_STAT));
+       printk("PM4_BUFFER_DL_WPTR = 0x%08x\n",
+              (unsigned int)R128_READ(R128_PM4_BUFFER_DL_WPTR));
+       printk("PM4_BUFFER_DL_RPTR = 0x%08x\n",
+              (unsigned int)R128_READ(R128_PM4_BUFFER_DL_RPTR));
+       printk("PM4_MICRO_CNTL     = 0x%08x\n",
+              (unsigned int)R128_READ(R128_PM4_MICRO_CNTL));
+       printk("PM4_BUFFER_CNTL    = 0x%08x\n",
+              (unsigned int)R128_READ(R128_PM4_BUFFER_CNTL));
+}
+#endif
+
+/* ================================================================
+ * Engine, FIFO control
+ */
+
+static int r128_do_pixcache_flush(drm_r128_private_t * dev_priv)
+{
+       u32 tmp;
+       int i;
+
+       tmp = R128_READ(R128_PC_NGUI_CTLSTAT) | R128_PC_FLUSH_ALL;
+       R128_WRITE(R128_PC_NGUI_CTLSTAT, tmp);
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               if (!(R128_READ(R128_PC_NGUI_CTLSTAT) & R128_PC_BUSY)) {
+                       return 0;
+               }
+               DRM_UDELAY(1);
+       }
+
+#if R128_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+#endif
+       return -EBUSY;
+}
+
+static int r128_do_wait_for_fifo(drm_r128_private_t * dev_priv, int entries)
+{
+       int i;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               int slots = R128_READ(R128_GUI_STAT) & R128_GUI_FIFOCNT_MASK;
+               if (slots >= entries)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if R128_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+#endif
+       return -EBUSY;
+}
+
+static int r128_do_wait_for_idle(drm_r128_private_t * dev_priv)
+{
+       int i, ret;
+
+       ret = r128_do_wait_for_fifo(dev_priv, 64);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               if (!(R128_READ(R128_GUI_STAT) & R128_GUI_ACTIVE)) {
+                       r128_do_pixcache_flush(dev_priv);
+                       return 0;
+               }
+               DRM_UDELAY(1);
+       }
+
+#if R128_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+#endif
+       return -EBUSY;
+}
+
+/* ================================================================
+ * CCE control, initialization
+ */
+
+/* Load the microcode for the CCE */
+static void r128_cce_load_microcode(drm_r128_private_t * dev_priv)
+{
+       int i;
+
+       DRM_DEBUG("\n");
+
+       r128_do_wait_for_idle(dev_priv);
+
+       R128_WRITE(R128_PM4_MICROCODE_ADDR, 0);
+       for (i = 0; i < 256; i++) {
+               R128_WRITE(R128_PM4_MICROCODE_DATAH, r128_cce_microcode[i * 2]);
+               R128_WRITE(R128_PM4_MICROCODE_DATAL,
+                          r128_cce_microcode[i * 2 + 1]);
+       }
+}
+
+/* Flush any pending commands to the CCE.  This should only be used just
+ * prior to a wait for idle, as it informs the engine that the command
+ * stream is ending.
+ */
+static void r128_do_cce_flush(drm_r128_private_t * dev_priv)
+{
+       u32 tmp;
+
+       tmp = R128_READ(R128_PM4_BUFFER_DL_WPTR) | R128_PM4_BUFFER_DL_DONE;
+       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, tmp);
+}
+
+/* Wait for the CCE to go idle.
+ */
+int r128_do_cce_idle(drm_r128_private_t * dev_priv)
+{
+       int i;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               if (GET_RING_HEAD(dev_priv) == dev_priv->ring.tail) {
+                       int pm4stat = R128_READ(R128_PM4_STAT);
+                       if (((pm4stat & R128_PM4_FIFOCNT_MASK) >=
+                            dev_priv->cce_fifo_size) &&
+                           !(pm4stat & (R128_PM4_BUSY |
+                                        R128_PM4_GUI_ACTIVE))) {
+                               return r128_do_pixcache_flush(dev_priv);
+                       }
+               }
+               DRM_UDELAY(1);
+       }
+
+#if R128_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+       r128_status(dev_priv);
+#endif
+       return -EBUSY;
+}
+
+/* Start the Concurrent Command Engine.
+ */
+static void r128_do_cce_start(drm_r128_private_t * dev_priv)
+{
+       r128_do_wait_for_idle(dev_priv);
+
+       R128_WRITE(R128_PM4_BUFFER_CNTL,
+                  dev_priv->cce_mode | dev_priv->ring.size_l2qw
+                  | R128_PM4_BUFFER_CNTL_NOUPDATE);
+       R128_READ(R128_PM4_BUFFER_ADDR);        /* as per the sample code */
+       R128_WRITE(R128_PM4_MICRO_CNTL, R128_PM4_MICRO_FREERUN);
+
+       dev_priv->cce_running = 1;
+}
+
+/* Reset the Concurrent Command Engine.  This will not flush any pending
+ * commands, so you must wait for the CCE command stream to complete
+ * before calling this routine.
+ */
+static void r128_do_cce_reset(drm_r128_private_t * dev_priv)
+{
+       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0);
+       R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0);
+       dev_priv->ring.tail = 0;
+}
+
+/* Stop the Concurrent Command Engine.  This will not flush any pending
+ * commands, so you must flush the command stream and wait for the CCE
+ * to go idle before calling this routine.
+ */
+static void r128_do_cce_stop(drm_r128_private_t * dev_priv)
+{
+       R128_WRITE(R128_PM4_MICRO_CNTL, 0);
+       R128_WRITE(R128_PM4_BUFFER_CNTL,
+                  R128_PM4_NONPM4 | R128_PM4_BUFFER_CNTL_NOUPDATE);
+
+       dev_priv->cce_running = 0;
+}
+
+/* Reset the engine.  This will stop the CCE if it is running.
+ */
+static int r128_do_engine_reset(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       u32 clock_cntl_index, mclk_cntl, gen_reset_cntl;
+
+       r128_do_pixcache_flush(dev_priv);
+
+       clock_cntl_index = R128_READ(R128_CLOCK_CNTL_INDEX);
+       mclk_cntl = R128_READ_PLL(dev, R128_MCLK_CNTL);
+
+       R128_WRITE_PLL(R128_MCLK_CNTL,
+                      mclk_cntl | R128_FORCE_GCP | R128_FORCE_PIPE3D_CP);
+
+       gen_reset_cntl = R128_READ(R128_GEN_RESET_CNTL);
+
+       /* Taken from the sample code - do not change */
+       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl | R128_SOFT_RESET_GUI);
+       R128_READ(R128_GEN_RESET_CNTL);
+       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl & ~R128_SOFT_RESET_GUI);
+       R128_READ(R128_GEN_RESET_CNTL);
+
+       R128_WRITE_PLL(R128_MCLK_CNTL, mclk_cntl);
+       R128_WRITE(R128_CLOCK_CNTL_INDEX, clock_cntl_index);
+       R128_WRITE(R128_GEN_RESET_CNTL, gen_reset_cntl);
+
+       /* Reset the CCE ring */
+       r128_do_cce_reset(dev_priv);
+
+       /* The CCE is no longer running after an engine reset */
+       dev_priv->cce_running = 0;
+
+       /* Reset any pending vertex, indirect buffers */
+       r128_freelist_reset(dev);
+
+       return 0;
+}
+
+static void r128_cce_init_ring_buffer(struct drm_device * dev,
+                                     drm_r128_private_t * dev_priv)
+{
+       u32 ring_start;
+       u32 tmp;
+
+       DRM_DEBUG("\n");
+
+       /* The manual (p. 2) says this address is in "VM space".  This
+        * means it's an offset from the start of AGP space.
+        */
+#if __OS_HAS_AGP
+       if (!dev_priv->is_pci)
+               ring_start = dev_priv->cce_ring->offset - dev->agp->base;
+       else
+#endif
+               ring_start = dev_priv->cce_ring->offset -
+                   (unsigned long)dev->sg->virtual;
+
+       R128_WRITE(R128_PM4_BUFFER_OFFSET, ring_start | R128_AGP_OFFSET);
+
+       R128_WRITE(R128_PM4_BUFFER_DL_WPTR, 0);
+       R128_WRITE(R128_PM4_BUFFER_DL_RPTR, 0);
+
+       /* Set watermark control */
+       R128_WRITE(R128_PM4_BUFFER_WM_CNTL,
+                  ((R128_WATERMARK_L / 4) << R128_WMA_SHIFT)
+                  | ((R128_WATERMARK_M / 4) << R128_WMB_SHIFT)
+                  | ((R128_WATERMARK_N / 4) << R128_WMC_SHIFT)
+                  | ((R128_WATERMARK_K / 64) << R128_WB_WM_SHIFT));
+
+       /* Force read.  Why?  Because it's in the examples... */
+       R128_READ(R128_PM4_BUFFER_ADDR);
+
+       /* Turn on bus mastering */
+       tmp = R128_READ(R128_BUS_CNTL) & ~R128_BUS_MASTER_DIS;
+       R128_WRITE(R128_BUS_CNTL, tmp);
+}
+
+static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
+{
+       drm_r128_private_t *dev_priv;
+
+       DRM_DEBUG("\n");
+
+       dev_priv = drm_alloc(sizeof(drm_r128_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv, 0, sizeof(drm_r128_private_t));
+
+       dev_priv->is_pci = init->is_pci;
+
+       if (dev_priv->is_pci && !dev->sg) {
+               DRM_ERROR("PCI GART memory not allocated!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->usec_timeout = init->usec_timeout;
+       if (dev_priv->usec_timeout < 1 ||
+           dev_priv->usec_timeout > R128_MAX_USEC_TIMEOUT) {
+               DRM_DEBUG("TIMEOUT problem!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->cce_mode = init->cce_mode;
+
+       /* GH: Simple idle check.
+        */
+       atomic_set(&dev_priv->idle_count, 0);
+
+       /* We don't support anything other than bus-mastering ring mode,
+        * but the ring can be in either AGP or PCI space for the ring
+        * read pointer.
+        */
+       if ((init->cce_mode != R128_PM4_192BM) &&
+           (init->cce_mode != R128_PM4_128BM_64INDBM) &&
+           (init->cce_mode != R128_PM4_64BM_128INDBM) &&
+           (init->cce_mode != R128_PM4_64BM_64VCBM_64INDBM)) {
+               DRM_DEBUG("Bad cce_mode!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+
+       switch (init->cce_mode) {
+       case R128_PM4_NONPM4:
+               dev_priv->cce_fifo_size = 0;
+               break;
+       case R128_PM4_192PIO:
+       case R128_PM4_192BM:
+               dev_priv->cce_fifo_size = 192;
+               break;
+       case R128_PM4_128PIO_64INDBM:
+       case R128_PM4_128BM_64INDBM:
+               dev_priv->cce_fifo_size = 128;
+               break;
+       case R128_PM4_64PIO_128INDBM:
+       case R128_PM4_64BM_128INDBM:
+       case R128_PM4_64PIO_64VCBM_64INDBM:
+       case R128_PM4_64BM_64VCBM_64INDBM:
+       case R128_PM4_64PIO_64VCPIO_64INDPIO:
+               dev_priv->cce_fifo_size = 64;
+               break;
+       }
+
+       switch (init->fb_bpp) {
+       case 16:
+               dev_priv->color_fmt = R128_DATATYPE_RGB565;
+               break;
+       case 32:
+       default:
+               dev_priv->color_fmt = R128_DATATYPE_ARGB8888;
+               break;
+       }
+       dev_priv->front_offset = init->front_offset;
+       dev_priv->front_pitch = init->front_pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->back_pitch = init->back_pitch;
+
+       switch (init->depth_bpp) {
+       case 16:
+               dev_priv->depth_fmt = R128_DATATYPE_RGB565;
+               break;
+       case 24:
+       case 32:
+       default:
+               dev_priv->depth_fmt = R128_DATATYPE_ARGB8888;
+               break;
+       }
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->depth_pitch = init->depth_pitch;
+       dev_priv->span_offset = init->span_offset;
+
+       dev_priv->front_pitch_offset_c = (((dev_priv->front_pitch / 8) << 21) |
+                                         (dev_priv->front_offset >> 5));
+       dev_priv->back_pitch_offset_c = (((dev_priv->back_pitch / 8) << 21) |
+                                        (dev_priv->back_offset >> 5));
+       dev_priv->depth_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) |
+                                         (dev_priv->depth_offset >> 5) |
+                                         R128_DST_TILE);
+       dev_priv->span_pitch_offset_c = (((dev_priv->depth_pitch / 8) << 21) |
+                                        (dev_priv->span_offset >> 5));
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("could not find sarea!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
+       if (!dev_priv->mmio) {
+               DRM_ERROR("could not find mmio region!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+       dev_priv->cce_ring = drm_core_findmap(dev, init->ring_offset);
+       if (!dev_priv->cce_ring) {
+               DRM_ERROR("could not find cce ring region!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+       dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
+       if (!dev_priv->ring_rptr) {
+               DRM_ERROR("could not find ring read pointer!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+       dev->agp_buffer_token = init->buffers_offset;
+       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
+       if (!dev->agp_buffer_map) {
+               DRM_ERROR("could not find dma buffer region!\n");
+               dev->dev_private = (void *)dev_priv;
+               r128_do_cleanup_cce(dev);
+               return -EINVAL;
+       }
+
+       if (!dev_priv->is_pci) {
+               dev_priv->agp_textures =
+                   drm_core_findmap(dev, init->agp_textures_offset);
+               if (!dev_priv->agp_textures) {
+                       DRM_ERROR("could not find agp texture region!\n");
+                       dev->dev_private = (void *)dev_priv;
+                       r128_do_cleanup_cce(dev);
+                       return -EINVAL;
+               }
+       }
+
+       dev_priv->sarea_priv =
+           (drm_r128_sarea_t *) ((u8 *) dev_priv->sarea->handle +
+                                 init->sarea_priv_offset);
+
+#if __OS_HAS_AGP
+       if (!dev_priv->is_pci) {
+               drm_core_ioremap(dev_priv->cce_ring, dev);
+               drm_core_ioremap(dev_priv->ring_rptr, dev);
+               drm_core_ioremap(dev->agp_buffer_map, dev);
+               if (!dev_priv->cce_ring->handle ||
+                   !dev_priv->ring_rptr->handle ||
+                   !dev->agp_buffer_map->handle) {
+                       DRM_ERROR("Could not ioremap agp regions!\n");
+                       dev->dev_private = (void *)dev_priv;
+                       r128_do_cleanup_cce(dev);
+                       return -ENOMEM;
+               }
+       } else
+#endif
+       {
+               dev_priv->cce_ring->handle = (void *)dev_priv->cce_ring->offset;
+               dev_priv->ring_rptr->handle =
+                   (void *)dev_priv->ring_rptr->offset;
+               dev->agp_buffer_map->handle =
+                   (void *)dev->agp_buffer_map->offset;
+       }
+
+#if __OS_HAS_AGP
+       if (!dev_priv->is_pci)
+               dev_priv->cce_buffers_offset = dev->agp->base;
+       else
+#endif
+               dev_priv->cce_buffers_offset = (unsigned long)dev->sg->virtual;
+
+       dev_priv->ring.start = (u32 *) dev_priv->cce_ring->handle;
+       dev_priv->ring.end = ((u32 *) dev_priv->cce_ring->handle
+                             + init->ring_size / sizeof(u32));
+       dev_priv->ring.size = init->ring_size;
+       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
+
+       dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
+
+       dev_priv->ring.high_mark = 128;
+
+       dev_priv->sarea_priv->last_frame = 0;
+       R128_WRITE(R128_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
+
+       dev_priv->sarea_priv->last_dispatch = 0;
+       R128_WRITE(R128_LAST_DISPATCH_REG, dev_priv->sarea_priv->last_dispatch);
+
+#if __OS_HAS_AGP
+       if (dev_priv->is_pci) {
+#endif
+               dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
+               dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
+               dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE;
+               dev_priv->gart_info.addr = NULL;
+               dev_priv->gart_info.bus_addr = 0;
+               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
+               if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
+                       DRM_ERROR("failed to init PCI GART!\n");
+                       dev->dev_private = (void *)dev_priv;
+                       r128_do_cleanup_cce(dev);
+                       return -ENOMEM;
+               }
+               R128_WRITE(R128_PCI_GART_PAGE, dev_priv->gart_info.bus_addr);
+#if __OS_HAS_AGP
+       }
+#endif
+
+       r128_cce_init_ring_buffer(dev, dev_priv);
+       r128_cce_load_microcode(dev_priv);
+
+       dev->dev_private = (void *)dev_priv;
+
+       r128_do_engine_reset(dev);
+
+       return 0;
+}
+
+int r128_do_cleanup_cce(struct drm_device * dev)
+{
+
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+       if (dev->dev_private) {
+               drm_r128_private_t *dev_priv = dev->dev_private;
+
+#if __OS_HAS_AGP
+               if (!dev_priv->is_pci) {
+                       if (dev_priv->cce_ring != NULL)
+                               drm_core_ioremapfree(dev_priv->cce_ring, dev);
+                       if (dev_priv->ring_rptr != NULL)
+                               drm_core_ioremapfree(dev_priv->ring_rptr, dev);
+                       if (dev->agp_buffer_map != NULL) {
+                               drm_core_ioremapfree(dev->agp_buffer_map, dev);
+                               dev->agp_buffer_map = NULL;
+                       }
+               } else
+#endif
+               {
+                       if (dev_priv->gart_info.bus_addr)
+                               if (!drm_ati_pcigart_cleanup(dev,
+                                                       &dev_priv->gart_info))
+                                       DRM_ERROR
+                                           ("failed to cleanup PCI GART!\n");
+               }
+
+               drm_free(dev->dev_private, sizeof(drm_r128_private_t),
+                        DRM_MEM_DRIVER);
+               dev->dev_private = NULL;
+       }
+
+       return 0;
+}
+
+int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_init_t *init = data;
+
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       switch (init->func) {
+       case R128_INIT_CCE:
+               return r128_do_init_cce(dev, init);
+       case R128_CLEANUP_CCE:
+               return r128_do_cleanup_cce(dev);
+       }
+
+       return -EINVAL;
+}
+
+int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4) {
+               DRM_DEBUG("while CCE running\n");
+               return 0;
+       }
+
+       r128_do_cce_start(dev_priv);
+
+       return 0;
+}
+
+/* Stop the CCE.  The engine must have been idled before calling this
+ * routine.
+ */
+int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_cce_stop_t *stop = data;
+       int ret;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* Flush any pending CCE commands.  This ensures any outstanding
+        * commands are exectuted by the engine before we turn it off.
+        */
+       if (stop->flush) {
+               r128_do_cce_flush(dev_priv);
+       }
+
+       /* If we fail to make the engine go idle, we return an error
+        * code so that the DRM ioctl wrapper can try again.
+        */
+       if (stop->idle) {
+               ret = r128_do_cce_idle(dev_priv);
+               if (ret)
+                       return ret;
+       }
+
+       /* Finally, we can turn off the CCE.  If the engine isn't idle,
+        * we will get some dropped triangles as they won't be fully
+        * rendered before the CCE is shut down.
+        */
+       r128_do_cce_stop(dev_priv);
+
+       /* Reset the engine */
+       r128_do_engine_reset(dev);
+
+       return 0;
+}
+
+/* Just reset the CCE ring.  Called as part of an X Server engine reset.
+ */
+int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_DEBUG("called before init done\n");
+               return -EINVAL;
+       }
+
+       r128_do_cce_reset(dev_priv);
+
+       /* The CCE is no longer running after an engine reset */
+       dev_priv->cce_running = 0;
+
+       return 0;
+}
+
+int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (dev_priv->cce_running) {
+               r128_do_cce_flush(dev_priv);
+       }
+
+       return r128_do_cce_idle(dev_priv);
+}
+
+int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return r128_do_engine_reset(dev);
+}
+
+int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       return -EINVAL;
+}
+
+/* ================================================================
+ * Freelist management
+ */
+#define R128_BUFFER_USED       0xffffffff
+#define R128_BUFFER_FREE       0
+
+#if 0
+static int r128_freelist_init(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       struct drm_buf *buf;
+       drm_r128_buf_priv_t *buf_priv;
+       drm_r128_freelist_t *entry;
+       int i;
+
+       dev_priv->head = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
+       if (dev_priv->head == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv->head, 0, sizeof(drm_r128_freelist_t));
+       dev_priv->head->age = R128_BUFFER_USED;
+
+       for (i = 0; i < dma->buf_count; i++) {
+               buf = dma->buflist[i];
+               buf_priv = buf->dev_private;
+
+               entry = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
+               if (!entry)
+                       return -ENOMEM;
+
+               entry->age = R128_BUFFER_FREE;
+               entry->buf = buf;
+               entry->prev = dev_priv->head;
+               entry->next = dev_priv->head->next;
+               if (!entry->next)
+                       dev_priv->tail = entry;
+
+               buf_priv->discard = 0;
+               buf_priv->dispatched = 0;
+               buf_priv->list_entry = entry;
+
+               dev_priv->head->next = entry;
+
+               if (dev_priv->head->next)
+                       dev_priv->head->next->prev = entry;
+       }
+
+       return 0;
+
+}
+#endif
+
+static struct drm_buf *r128_freelist_get(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_buf_priv_t *buf_priv;
+       struct drm_buf *buf;
+       int i, t;
+
+       /* FIXME: Optimize -- use freelist code */
+
+       for (i = 0; i < dma->buf_count; i++) {
+               buf = dma->buflist[i];
+               buf_priv = buf->dev_private;
+               if (!buf->file_priv)
+                       return buf;
+       }
+
+       for (t = 0; t < dev_priv->usec_timeout; t++) {
+               u32 done_age = R128_READ(R128_LAST_DISPATCH_REG);
+
+               for (i = 0; i < dma->buf_count; i++) {
+                       buf = dma->buflist[i];
+                       buf_priv = buf->dev_private;
+                       if (buf->pending && buf_priv->age <= done_age) {
+                               /* The buffer has been processed, so it
+                                * can now be used.
+                                */
+                               buf->pending = 0;
+                               return buf;
+                       }
+               }
+               DRM_UDELAY(1);
+       }
+
+       DRM_DEBUG("returning NULL!\n");
+       return NULL;
+}
+
+void r128_freelist_reset(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int i;
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_r128_buf_priv_t *buf_priv = buf->dev_private;
+               buf_priv->age = 0;
+       }
+}
+
+/* ================================================================
+ * CCE command submission
+ */
+
+int r128_wait_ring(drm_r128_private_t * dev_priv, int n)
+{
+       drm_r128_ring_buffer_t *ring = &dev_priv->ring;
+       int i;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               r128_update_ring_snapshot(dev_priv);
+               if (ring->space >= n)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+       /* FIXME: This is being ignored... */
+       DRM_ERROR("failed!\n");
+       return -EBUSY;
+}
+
+static int r128_cce_get_buffers(struct drm_device * dev,
+                               struct drm_file *file_priv,
+                               struct drm_dma * d)
+{
+       int i;
+       struct drm_buf *buf;
+
+       for (i = d->granted_count; i < d->request_count; i++) {
+               buf = r128_freelist_get(dev);
+               if (!buf)
+                       return -EAGAIN;
+
+               buf->file_priv = file_priv;
+
+               if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
+                                    sizeof(buf->idx)))
+                       return -EFAULT;
+               if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
+                                    sizeof(buf->total)))
+                       return -EFAULT;
+
+               d->granted_count++;
+       }
+       return 0;
+}
+
+int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int ret = 0;
+       struct drm_dma *d = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* Please don't send us buffers.
+        */
+       if (d->send_count != 0) {
+               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
+                         DRM_CURRENTPID, d->send_count);
+               return -EINVAL;
+       }
+
+       /* We'll send you buffers.
+        */
+       if (d->request_count < 0 || d->request_count > dma->buf_count) {
+               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
+                         DRM_CURRENTPID, d->request_count, dma->buf_count);
+               return -EINVAL;
+       }
+
+       d->granted_count = 0;
+
+       if (d->request_count) {
+               ret = r128_cce_get_buffers(dev, file_priv, d);
+       }
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/r128/r128_drv.c b/drivers/gpu/drm/r128/r128_drv.c
new file mode 100644 (file)
index 0000000..6108e75
--- /dev/null
@@ -0,0 +1,103 @@
+/* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
+ * Created: Mon Dec 13 09:47:27 1999 by faith@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "r128_drm.h"
+#include "r128_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       r128_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+           DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
+           DRIVER_IRQ_VBL,
+       .dev_priv_size = sizeof(drm_r128_buf_priv_t),
+       .preclose = r128_driver_preclose,
+       .lastclose = r128_driver_lastclose,
+       .vblank_wait = r128_driver_vblank_wait,
+       .irq_preinstall = r128_driver_irq_preinstall,
+       .irq_postinstall = r128_driver_irq_postinstall,
+       .irq_uninstall = r128_driver_irq_uninstall,
+       .irq_handler = r128_driver_irq_handler,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = r128_ioctls,
+       .dma_ioctl = r128_cce_buffers,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+                .compat_ioctl = r128_compat_ioctl,
+#endif
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init r128_init(void)
+{
+       driver.num_ioctls = r128_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit r128_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(r128_init);
+module_exit(r128_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
new file mode 100644 (file)
index 0000000..011105e
--- /dev/null
@@ -0,0 +1,522 @@
+/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
+ * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
+ */
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Kevin E. Martin <martin@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ *    Michel Dänzer <daenzerm@student.ethz.ch>
+ */
+
+#ifndef __R128_DRV_H__
+#define __R128_DRV_H__
+
+/* General customization:
+ */
+#define DRIVER_AUTHOR          "Gareth Hughes, VA Linux Systems Inc."
+
+#define DRIVER_NAME            "r128"
+#define DRIVER_DESC            "ATI Rage 128"
+#define DRIVER_DATE            "20030725"
+
+/* Interface history:
+ *
+ * ??  - ??
+ * 2.4 - Add support for ycbcr textures (no new ioctls)
+ * 2.5 - Add FLIP ioctl, disable FULLSCREEN.
+ */
+#define DRIVER_MAJOR           2
+#define DRIVER_MINOR           5
+#define DRIVER_PATCHLEVEL      0
+
+#define GET_RING_HEAD(dev_priv)                R128_READ( R128_PM4_BUFFER_DL_RPTR )
+
+typedef struct drm_r128_freelist {
+       unsigned int age;
+       struct drm_buf *buf;
+       struct drm_r128_freelist *next;
+       struct drm_r128_freelist *prev;
+} drm_r128_freelist_t;
+
+typedef struct drm_r128_ring_buffer {
+       u32 *start;
+       u32 *end;
+       int size;
+       int size_l2qw;
+
+       u32 tail;
+       u32 tail_mask;
+       int space;
+
+       int high_mark;
+} drm_r128_ring_buffer_t;
+
+typedef struct drm_r128_private {
+       drm_r128_ring_buffer_t ring;
+       drm_r128_sarea_t *sarea_priv;
+
+       int cce_mode;
+       int cce_fifo_size;
+       int cce_running;
+
+       drm_r128_freelist_t *head;
+       drm_r128_freelist_t *tail;
+
+       int usec_timeout;
+       int is_pci;
+       unsigned long cce_buffers_offset;
+
+       atomic_t idle_count;
+
+       int page_flipping;
+       int current_page;
+       u32 crtc_offset;
+       u32 crtc_offset_cntl;
+
+       u32 color_fmt;
+       unsigned int front_offset;
+       unsigned int front_pitch;
+       unsigned int back_offset;
+       unsigned int back_pitch;
+
+       u32 depth_fmt;
+       unsigned int depth_offset;
+       unsigned int depth_pitch;
+       unsigned int span_offset;
+
+       u32 front_pitch_offset_c;
+       u32 back_pitch_offset_c;
+       u32 depth_pitch_offset_c;
+       u32 span_pitch_offset_c;
+
+       drm_local_map_t *sarea;
+       drm_local_map_t *mmio;
+       drm_local_map_t *cce_ring;
+       drm_local_map_t *ring_rptr;
+       drm_local_map_t *agp_textures;
+       struct drm_ati_pcigart_info gart_info;
+} drm_r128_private_t;
+
+typedef struct drm_r128_buf_priv {
+       u32 age;
+       int prim;
+       int discard;
+       int dispatched;
+       drm_r128_freelist_t *list_entry;
+} drm_r128_buf_priv_t;
+
+extern struct drm_ioctl_desc r128_ioctls[];
+extern int r128_max_ioctl;
+
+                               /* r128_cce.c */
+extern int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
+
+extern void r128_freelist_reset(struct drm_device * dev);
+
+extern int r128_wait_ring(drm_r128_private_t * dev_priv, int n);
+
+extern int r128_do_cce_idle(drm_r128_private_t * dev_priv);
+extern int r128_do_cleanup_cce(struct drm_device * dev);
+
+extern int r128_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
+
+extern irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS);
+extern void r128_driver_irq_preinstall(struct drm_device * dev);
+extern void r128_driver_irq_postinstall(struct drm_device * dev);
+extern void r128_driver_irq_uninstall(struct drm_device * dev);
+extern void r128_driver_lastclose(struct drm_device * dev);
+extern void r128_driver_preclose(struct drm_device * dev,
+                                struct drm_file *file_priv);
+
+extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
+                             unsigned long arg);
+
+/* Register definitions, register access macros and drmAddMap constants
+ * for Rage 128 kernel driver.
+ */
+
+#define R128_AUX_SC_CNTL               0x1660
+#      define R128_AUX1_SC_EN                  (1 << 0)
+#      define R128_AUX1_SC_MODE_OR             (0 << 1)
+#      define R128_AUX1_SC_MODE_NAND           (1 << 1)
+#      define R128_AUX2_SC_EN                  (1 << 2)
+#      define R128_AUX2_SC_MODE_OR             (0 << 3)
+#      define R128_AUX2_SC_MODE_NAND           (1 << 3)
+#      define R128_AUX3_SC_EN                  (1 << 4)
+#      define R128_AUX3_SC_MODE_OR             (0 << 5)
+#      define R128_AUX3_SC_MODE_NAND           (1 << 5)
+#define R128_AUX1_SC_LEFT              0x1664
+#define R128_AUX1_SC_RIGHT             0x1668
+#define R128_AUX1_SC_TOP               0x166c
+#define R128_AUX1_SC_BOTTOM            0x1670
+#define R128_AUX2_SC_LEFT              0x1674
+#define R128_AUX2_SC_RIGHT             0x1678
+#define R128_AUX2_SC_TOP               0x167c
+#define R128_AUX2_SC_BOTTOM            0x1680
+#define R128_AUX3_SC_LEFT              0x1684
+#define R128_AUX3_SC_RIGHT             0x1688
+#define R128_AUX3_SC_TOP               0x168c
+#define R128_AUX3_SC_BOTTOM            0x1690
+
+#define R128_BRUSH_DATA0               0x1480
+#define R128_BUS_CNTL                  0x0030
+#      define R128_BUS_MASTER_DIS              (1 << 6)
+
+#define R128_CLOCK_CNTL_INDEX          0x0008
+#define R128_CLOCK_CNTL_DATA           0x000c
+#      define R128_PLL_WR_EN                   (1 << 7)
+#define R128_CONSTANT_COLOR_C          0x1d34
+#define R128_CRTC_OFFSET               0x0224
+#define R128_CRTC_OFFSET_CNTL          0x0228
+#      define R128_CRTC_OFFSET_FLIP_CNTL       (1 << 16)
+
+#define R128_DP_GUI_MASTER_CNTL                0x146c
+#       define R128_GMC_SRC_PITCH_OFFSET_CNTL  (1    <<  0)
+#       define R128_GMC_DST_PITCH_OFFSET_CNTL  (1    <<  1)
+#      define R128_GMC_BRUSH_SOLID_COLOR       (13   <<  4)
+#      define R128_GMC_BRUSH_NONE              (15   <<  4)
+#      define R128_GMC_DST_16BPP               (4    <<  8)
+#      define R128_GMC_DST_24BPP               (5    <<  8)
+#      define R128_GMC_DST_32BPP               (6    <<  8)
+#       define R128_GMC_DST_DATATYPE_SHIFT     8
+#      define R128_GMC_SRC_DATATYPE_COLOR      (3    << 12)
+#      define R128_DP_SRC_SOURCE_MEMORY        (2    << 24)
+#      define R128_DP_SRC_SOURCE_HOST_DATA     (3    << 24)
+#      define R128_GMC_CLR_CMP_CNTL_DIS        (1    << 28)
+#      define R128_GMC_AUX_CLIP_DIS            (1    << 29)
+#      define R128_GMC_WR_MSK_DIS              (1    << 30)
+#      define R128_ROP3_S                      0x00cc0000
+#      define R128_ROP3_P                      0x00f00000
+#define R128_DP_WRITE_MASK             0x16cc
+#define R128_DST_PITCH_OFFSET_C                0x1c80
+#      define R128_DST_TILE                    (1 << 31)
+
+#define R128_GEN_INT_CNTL              0x0040
+#      define R128_CRTC_VBLANK_INT_EN          (1 <<  0)
+#define R128_GEN_INT_STATUS            0x0044
+#      define R128_CRTC_VBLANK_INT             (1 <<  0)
+#      define R128_CRTC_VBLANK_INT_AK          (1 <<  0)
+#define R128_GEN_RESET_CNTL            0x00f0
+#      define R128_SOFT_RESET_GUI              (1 <<  0)
+
+#define R128_GUI_SCRATCH_REG0          0x15e0
+#define R128_GUI_SCRATCH_REG1          0x15e4
+#define R128_GUI_SCRATCH_REG2          0x15e8
+#define R128_GUI_SCRATCH_REG3          0x15ec
+#define R128_GUI_SCRATCH_REG4          0x15f0
+#define R128_GUI_SCRATCH_REG5          0x15f4
+
+#define R128_GUI_STAT                  0x1740
+#      define R128_GUI_FIFOCNT_MASK            0x0fff
+#      define R128_GUI_ACTIVE                  (1 << 31)
+
+#define R128_MCLK_CNTL                 0x000f
+#      define R128_FORCE_GCP                   (1 << 16)
+#      define R128_FORCE_PIPE3D_CP             (1 << 17)
+#      define R128_FORCE_RCP                   (1 << 18)
+
+#define R128_PC_GUI_CTLSTAT            0x1748
+#define R128_PC_NGUI_CTLSTAT           0x0184
+#      define R128_PC_FLUSH_GUI                (3 << 0)
+#      define R128_PC_RI_GUI                   (1 << 2)
+#      define R128_PC_FLUSH_ALL                0x00ff
+#      define R128_PC_BUSY                     (1 << 31)
+
+#define R128_PCI_GART_PAGE             0x017c
+#define R128_PRIM_TEX_CNTL_C           0x1cb0
+
+#define R128_SCALE_3D_CNTL             0x1a00
+#define R128_SEC_TEX_CNTL_C            0x1d00
+#define R128_SEC_TEXTURE_BORDER_COLOR_C        0x1d3c
+#define R128_SETUP_CNTL                        0x1bc4
+#define R128_STEN_REF_MASK_C           0x1d40
+
+#define R128_TEX_CNTL_C                        0x1c9c
+#      define R128_TEX_CACHE_FLUSH             (1 << 23)
+
+#define R128_WAIT_UNTIL                        0x1720
+#      define R128_EVENT_CRTC_OFFSET           (1 << 0)
+#define R128_WINDOW_XY_OFFSET          0x1bcc
+
+/* CCE registers
+ */
+#define R128_PM4_BUFFER_OFFSET         0x0700
+#define R128_PM4_BUFFER_CNTL           0x0704
+#      define R128_PM4_MASK                    (15 << 28)
+#      define R128_PM4_NONPM4                  (0  << 28)
+#      define R128_PM4_192PIO                  (1  << 28)
+#      define R128_PM4_192BM                   (2  << 28)
+#      define R128_PM4_128PIO_64INDBM          (3  << 28)
+#      define R128_PM4_128BM_64INDBM           (4  << 28)
+#      define R128_PM4_64PIO_128INDBM          (5  << 28)
+#      define R128_PM4_64BM_128INDBM           (6  << 28)
+#      define R128_PM4_64PIO_64VCBM_64INDBM    (7  << 28)
+#      define R128_PM4_64BM_64VCBM_64INDBM     (8  << 28)
+#      define R128_PM4_64PIO_64VCPIO_64INDPIO  (15 << 28)
+#      define R128_PM4_BUFFER_CNTL_NOUPDATE    (1  << 27)
+
+#define R128_PM4_BUFFER_WM_CNTL                0x0708
+#      define R128_WMA_SHIFT                   0
+#      define R128_WMB_SHIFT                   8
+#      define R128_WMC_SHIFT                   16
+#      define R128_WB_WM_SHIFT                 24
+
+#define R128_PM4_BUFFER_DL_RPTR_ADDR   0x070c
+#define R128_PM4_BUFFER_DL_RPTR                0x0710
+#define R128_PM4_BUFFER_DL_WPTR                0x0714
+#      define R128_PM4_BUFFER_DL_DONE          (1 << 31)
+
+#define R128_PM4_VC_FPU_SETUP          0x071c
+
+#define R128_PM4_IW_INDOFF             0x0738
+#define R128_PM4_IW_INDSIZE            0x073c
+
+#define R128_PM4_STAT                  0x07b8
+#      define R128_PM4_FIFOCNT_MASK            0x0fff
+#      define R128_PM4_BUSY                    (1 << 16)
+#      define R128_PM4_GUI_ACTIVE              (1 << 31)
+
+#define R128_PM4_MICROCODE_ADDR                0x07d4
+#define R128_PM4_MICROCODE_RADDR       0x07d8
+#define R128_PM4_MICROCODE_DATAH       0x07dc
+#define R128_PM4_MICROCODE_DATAL       0x07e0
+
+#define R128_PM4_BUFFER_ADDR           0x07f0
+#define R128_PM4_MICRO_CNTL            0x07fc
+#      define R128_PM4_MICRO_FREERUN           (1 << 30)
+
+#define R128_PM4_FIFO_DATA_EVEN                0x1000
+#define R128_PM4_FIFO_DATA_ODD         0x1004
+
+/* CCE command packets
+ */
+#define R128_CCE_PACKET0               0x00000000
+#define R128_CCE_PACKET1               0x40000000
+#define R128_CCE_PACKET2               0x80000000
+#define R128_CCE_PACKET3               0xC0000000
+#      define R128_CNTL_HOSTDATA_BLT           0x00009400
+#      define R128_CNTL_PAINT_MULTI            0x00009A00
+#      define R128_CNTL_BITBLT_MULTI           0x00009B00
+#      define R128_3D_RNDR_GEN_INDX_PRIM       0x00002300
+
+#define R128_CCE_PACKET_MASK           0xC0000000
+#define R128_CCE_PACKET_COUNT_MASK     0x3fff0000
+#define R128_CCE_PACKET0_REG_MASK      0x000007ff
+#define R128_CCE_PACKET1_REG0_MASK     0x000007ff
+#define R128_CCE_PACKET1_REG1_MASK     0x003ff800
+
+#define R128_CCE_VC_CNTL_PRIM_TYPE_NONE                0x00000000
+#define R128_CCE_VC_CNTL_PRIM_TYPE_POINT       0x00000001
+#define R128_CCE_VC_CNTL_PRIM_TYPE_LINE                0x00000002
+#define R128_CCE_VC_CNTL_PRIM_TYPE_POLY_LINE   0x00000003
+#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST    0x00000004
+#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_FAN     0x00000005
+#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_STRIP   0x00000006
+#define R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2   0x00000007
+#define R128_CCE_VC_CNTL_PRIM_WALK_IND         0x00000010
+#define R128_CCE_VC_CNTL_PRIM_WALK_LIST                0x00000020
+#define R128_CCE_VC_CNTL_PRIM_WALK_RING                0x00000030
+#define R128_CCE_VC_CNTL_NUM_SHIFT             16
+
+#define R128_DATATYPE_VQ               0
+#define R128_DATATYPE_CI4              1
+#define R128_DATATYPE_CI8              2
+#define R128_DATATYPE_ARGB1555         3
+#define R128_DATATYPE_RGB565           4
+#define R128_DATATYPE_RGB888           5
+#define R128_DATATYPE_ARGB8888         6
+#define R128_DATATYPE_RGB332           7
+#define R128_DATATYPE_Y8               8
+#define R128_DATATYPE_RGB8             9
+#define R128_DATATYPE_CI16             10
+#define R128_DATATYPE_YVYU422          11
+#define R128_DATATYPE_VYUY422          12
+#define R128_DATATYPE_AYUV444          14
+#define R128_DATATYPE_ARGB4444         15
+
+/* Constants */
+#define R128_AGP_OFFSET                        0x02000000
+
+#define R128_WATERMARK_L               16
+#define R128_WATERMARK_M               8
+#define R128_WATERMARK_N               8
+#define R128_WATERMARK_K               128
+
+#define R128_MAX_USEC_TIMEOUT          100000  /* 100 ms */
+
+#define R128_LAST_FRAME_REG            R128_GUI_SCRATCH_REG0
+#define R128_LAST_DISPATCH_REG         R128_GUI_SCRATCH_REG1
+#define R128_MAX_VB_AGE                        0x7fffffff
+#define R128_MAX_VB_VERTS              (0xffff)
+
+#define R128_RING_HIGH_MARK            128
+
+#define R128_PERFORMANCE_BOXES         0
+
+#define R128_PCIGART_TABLE_SIZE         32768
+
+#define R128_READ(reg)         DRM_READ32(  dev_priv->mmio, (reg) )
+#define R128_WRITE(reg,val)    DRM_WRITE32( dev_priv->mmio, (reg), (val) )
+#define R128_READ8(reg)                DRM_READ8(   dev_priv->mmio, (reg) )
+#define R128_WRITE8(reg,val)   DRM_WRITE8(  dev_priv->mmio, (reg), (val) )
+
+#define R128_WRITE_PLL(addr,val)                                       \
+do {                                                                   \
+       R128_WRITE8(R128_CLOCK_CNTL_INDEX,                              \
+                   ((addr) & 0x1f) | R128_PLL_WR_EN);                  \
+       R128_WRITE(R128_CLOCK_CNTL_DATA, (val));                        \
+} while (0)
+
+#define CCE_PACKET0( reg, n )          (R128_CCE_PACKET0 |             \
+                                        ((n) << 16) | ((reg) >> 2))
+#define CCE_PACKET1( reg0, reg1 )      (R128_CCE_PACKET1 |             \
+                                        (((reg1) >> 2) << 11) | ((reg0) >> 2))
+#define CCE_PACKET2()                  (R128_CCE_PACKET2)
+#define CCE_PACKET3( pkt, n )          (R128_CCE_PACKET3 |             \
+                                        (pkt) | ((n) << 16))
+
+static __inline__ void r128_update_ring_snapshot(drm_r128_private_t * dev_priv)
+{
+       drm_r128_ring_buffer_t *ring = &dev_priv->ring;
+       ring->space = (GET_RING_HEAD(dev_priv) - ring->tail) * sizeof(u32);
+       if (ring->space <= 0)
+               ring->space += ring->size;
+}
+
+/* ================================================================
+ * Misc helper macros
+ */
+
+#define RING_SPACE_TEST_WITH_RETURN( dev_priv )                                \
+do {                                                                   \
+       drm_r128_ring_buffer_t *ring = &dev_priv->ring; int i;          \
+       if ( ring->space < ring->high_mark ) {                          \
+               for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {      \
+                       r128_update_ring_snapshot( dev_priv );          \
+                       if ( ring->space >= ring->high_mark )           \
+                               goto __ring_space_done;                 \
+                       DRM_UDELAY(1);                          \
+               }                                                       \
+               DRM_ERROR( "ring space check failed!\n" );              \
+               return -EBUSY;                          \
+       }                                                               \
+ __ring_space_done:                                                    \
+       ;                                                               \
+} while (0)
+
+#define VB_AGE_TEST_WITH_RETURN( dev_priv )                            \
+do {                                                                   \
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;            \
+       if ( sarea_priv->last_dispatch >= R128_MAX_VB_AGE ) {           \
+               int __ret = r128_do_cce_idle( dev_priv );               \
+               if ( __ret ) return __ret;                              \
+               sarea_priv->last_dispatch = 0;                          \
+               r128_freelist_reset( dev );                             \
+       }                                                               \
+} while (0)
+
+#define R128_WAIT_UNTIL_PAGE_FLIPPED() do {                            \
+       OUT_RING( CCE_PACKET0( R128_WAIT_UNTIL, 0 ) );                  \
+       OUT_RING( R128_EVENT_CRTC_OFFSET );                             \
+} while (0)
+
+/* ================================================================
+ * Ring control
+ */
+
+#define R128_VERBOSE   0
+
+#define RING_LOCALS                                                    \
+       int write, _nr; unsigned int tail_mask; volatile u32 *ring;
+
+#define BEGIN_RING( n ) do {                                           \
+       if ( R128_VERBOSE ) {                                           \
+               DRM_INFO( "BEGIN_RING( %d )\n", (n));                   \
+       }                                                               \
+       if ( dev_priv->ring.space <= (n) * sizeof(u32) ) {              \
+               COMMIT_RING();                                          \
+               r128_wait_ring( dev_priv, (n) * sizeof(u32) );          \
+       }                                                               \
+       _nr = n; dev_priv->ring.space -= (n) * sizeof(u32);             \
+       ring = dev_priv->ring.start;                                    \
+       write = dev_priv->ring.tail;                                    \
+       tail_mask = dev_priv->ring.tail_mask;                           \
+} while (0)
+
+/* You can set this to zero if you want.  If the card locks up, you'll
+ * need to keep this set.  It works around a bug in early revs of the
+ * Rage 128 chipset, where the CCE would read 32 dwords past the end of
+ * the ring buffer before wrapping around.
+ */
+#define R128_BROKEN_CCE        1
+
+#define ADVANCE_RING() do {                                            \
+       if ( R128_VERBOSE ) {                                           \
+               DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",     \
+                         write, dev_priv->ring.tail );                 \
+       }                                                               \
+       if ( R128_BROKEN_CCE && write < 32 ) {                          \
+               memcpy( dev_priv->ring.end,                             \
+                       dev_priv->ring.start,                           \
+                       write * sizeof(u32) );                          \
+       }                                                               \
+       if (((dev_priv->ring.tail + _nr) & tail_mask) != write) {       \
+               DRM_ERROR(                                              \
+                       "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n",        \
+                       ((dev_priv->ring.tail + _nr) & tail_mask),      \
+                       write, __LINE__);                               \
+       } else                                                          \
+               dev_priv->ring.tail = write;                            \
+} while (0)
+
+#define COMMIT_RING() do {                                             \
+       if ( R128_VERBOSE ) {                                           \
+               DRM_INFO( "COMMIT_RING() tail=0x%06x\n",                \
+                       dev_priv->ring.tail );                          \
+       }                                                               \
+       DRM_MEMORYBARRIER();                                            \
+       R128_WRITE( R128_PM4_BUFFER_DL_WPTR, dev_priv->ring.tail );     \
+       R128_READ( R128_PM4_BUFFER_DL_WPTR );                           \
+} while (0)
+
+#define OUT_RING( x ) do {                                             \
+       if ( R128_VERBOSE ) {                                           \
+               DRM_INFO( "   OUT_RING( 0x%08x ) at 0x%x\n",            \
+                          (unsigned int)(x), write );                  \
+       }                                                               \
+       ring[write++] = cpu_to_le32( x );                               \
+       write &= tail_mask;                                             \
+} while (0)
+
+#endif                         /* __R128_DRV_H__ */
diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
new file mode 100644 (file)
index 0000000..d3cb676
--- /dev/null
@@ -0,0 +1,221 @@
+/**
+ * \file r128_ioc32.c
+ *
+ * 32-bit ioctl compatibility routines for the R128 DRM.
+ *
+ * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich
+ *
+ * Copyright (C) Paul Mackerras 2005
+ * Copyright (C) Egbert Eich 2003,2004
+ * Copyright (C) Dave Airlie 2005
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include <linux/compat.h>
+
+#include "drmP.h"
+#include "drm.h"
+#include "r128_drm.h"
+
+typedef struct drm_r128_init32 {
+       int func;
+       unsigned int sarea_priv_offset;
+       int is_pci;
+       int cce_mode;
+       int cce_secure;
+       int ring_size;
+       int usec_timeout;
+
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+       unsigned int span_offset;
+
+       unsigned int fb_offset;
+       unsigned int mmio_offset;
+       unsigned int ring_offset;
+       unsigned int ring_rptr_offset;
+       unsigned int buffers_offset;
+       unsigned int agp_textures_offset;
+} drm_r128_init32_t;
+
+static int compat_r128_init(struct file *file, unsigned int cmd,
+                           unsigned long arg)
+{
+       drm_r128_init32_t init32;
+       drm_r128_init_t __user *init;
+
+       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
+               return -EFAULT;
+
+       init = compat_alloc_user_space(sizeof(*init));
+       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
+           || __put_user(init32.func, &init->func)
+           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
+           || __put_user(init32.is_pci, &init->is_pci)
+           || __put_user(init32.cce_mode, &init->cce_mode)
+           || __put_user(init32.cce_secure, &init->cce_secure)
+           || __put_user(init32.ring_size, &init->ring_size)
+           || __put_user(init32.usec_timeout, &init->usec_timeout)
+           || __put_user(init32.fb_bpp, &init->fb_bpp)
+           || __put_user(init32.front_offset, &init->front_offset)
+           || __put_user(init32.front_pitch, &init->front_pitch)
+           || __put_user(init32.back_offset, &init->back_offset)
+           || __put_user(init32.back_pitch, &init->back_pitch)
+           || __put_user(init32.depth_bpp, &init->depth_bpp)
+           || __put_user(init32.depth_offset, &init->depth_offset)
+           || __put_user(init32.depth_pitch, &init->depth_pitch)
+           || __put_user(init32.span_offset, &init->span_offset)
+           || __put_user(init32.fb_offset, &init->fb_offset)
+           || __put_user(init32.mmio_offset, &init->mmio_offset)
+           || __put_user(init32.ring_offset, &init->ring_offset)
+           || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
+           || __put_user(init32.buffers_offset, &init->buffers_offset)
+           || __put_user(init32.agp_textures_offset,
+                         &init->agp_textures_offset))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_R128_INIT, (unsigned long)init);
+}
+
+typedef struct drm_r128_depth32 {
+       int func;
+       int n;
+       u32 x;
+       u32 y;
+       u32 buffer;
+       u32 mask;
+} drm_r128_depth32_t;
+
+static int compat_r128_depth(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       drm_r128_depth32_t depth32;
+       drm_r128_depth_t __user *depth;
+
+       if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
+               return -EFAULT;
+
+       depth = compat_alloc_user_space(sizeof(*depth));
+       if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
+           || __put_user(depth32.func, &depth->func)
+           || __put_user(depth32.n, &depth->n)
+           || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
+           || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
+           || __put_user((unsigned int __user *)(unsigned long)depth32.buffer,
+                         &depth->buffer)
+           || __put_user((unsigned char __user *)(unsigned long)depth32.mask,
+                         &depth->mask))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
+
+}
+
+typedef struct drm_r128_stipple32 {
+       u32 mask;
+} drm_r128_stipple32_t;
+
+static int compat_r128_stipple(struct file *file, unsigned int cmd,
+                              unsigned long arg)
+{
+       drm_r128_stipple32_t stipple32;
+       drm_r128_stipple_t __user *stipple;
+
+       if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
+               return -EFAULT;
+
+       stipple = compat_alloc_user_space(sizeof(*stipple));
+       if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
+           || __put_user((unsigned int __user *)(unsigned long)stipple32.mask,
+                         &stipple->mask))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
+}
+
+typedef struct drm_r128_getparam32 {
+       int param;
+       u32 value;
+} drm_r128_getparam32_t;
+
+static int compat_r128_getparam(struct file *file, unsigned int cmd,
+                               unsigned long arg)
+{
+       drm_r128_getparam32_t getparam32;
+       drm_r128_getparam_t __user *getparam;
+
+       if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
+               return -EFAULT;
+
+       getparam = compat_alloc_user_space(sizeof(*getparam));
+       if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
+           || __put_user(getparam32.param, &getparam->param)
+           || __put_user((void __user *)(unsigned long)getparam32.value,
+                         &getparam->value))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
+}
+
+drm_ioctl_compat_t *r128_compat_ioctls[] = {
+       [DRM_R128_INIT] = compat_r128_init,
+       [DRM_R128_DEPTH] = compat_r128_depth,
+       [DRM_R128_STIPPLE] = compat_r128_stipple,
+       [DRM_R128_GETPARAM] = compat_r128_getparam,
+};
+
+/**
+ * Called whenever a 32-bit process running under a 64-bit kernel
+ * performs an ioctl on /dev/dri/card<n>.
+ *
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ */
+long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       drm_ioctl_compat_t *fn = NULL;
+       int ret;
+
+       if (nr < DRM_COMMAND_BASE)
+               return drm_compat_ioctl(filp, cmd, arg);
+
+       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
+               fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
+
+       lock_kernel();          /* XXX for now */
+       if (fn != NULL)
+               ret = (*fn) (filp, cmd, arg);
+       else
+               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
new file mode 100644 (file)
index 0000000..c76fdca
--- /dev/null
@@ -0,0 +1,101 @@
+/* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */
+/*
+ * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
+ *
+ * The Weather Channel (TM) funded Tungsten Graphics to develop the
+ * initial release of the Radeon 8500 driver under the XFree86 license.
+ * This notice must be preserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Eric Anholt <anholt@FreeBSD.org>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "r128_drm.h"
+#include "r128_drv.h"
+
+irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
+       int status;
+
+       status = R128_READ(R128_GEN_INT_STATUS);
+
+       /* VBLANK interrupt */
+       if (status & R128_CRTC_VBLANK_INT) {
+               R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
+               atomic_inc(&dev->vbl_received);
+               DRM_WAKEUP(&dev->vbl_queue);
+               drm_vbl_send_signals(dev);
+               return IRQ_HANDLED;
+       }
+       return IRQ_NONE;
+}
+
+int r128_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
+{
+       unsigned int cur_vblank;
+       int ret = 0;
+
+       /* Assume that the user has missed the current sequence number
+        * by about a day rather than she wants to wait for years
+        * using vertical blanks...
+        */
+       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
+                   (((cur_vblank = atomic_read(&dev->vbl_received))
+                     - *sequence) <= (1 << 23)));
+
+       *sequence = cur_vblank;
+
+       return ret;
+}
+
+void r128_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
+
+       /* Disable *all* interrupts */
+       R128_WRITE(R128_GEN_INT_CNTL, 0);
+       /* Clear vblank bit if it's already high */
+       R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
+}
+
+void r128_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
+
+       /* Turn on VBL interrupt */
+       R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN);
+}
+
+void r128_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
+       if (!dev_priv)
+               return;
+
+       /* Disable *all* interrupts */
+       R128_WRITE(R128_GEN_INT_CNTL, 0);
+}
diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
new file mode 100644 (file)
index 0000000..51a9afc
--- /dev/null
@@ -0,0 +1,1681 @@
+/* r128_state.c -- State support for r128 -*- linux-c -*-
+ * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
+ */
+/*
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "r128_drm.h"
+#include "r128_drv.h"
+
+/* ================================================================
+ * CCE hardware state programming functions
+ */
+
+static void r128_emit_clip_rects(drm_r128_private_t * dev_priv,
+                                struct drm_clip_rect * boxes, int count)
+{
+       u32 aux_sc_cntl = 0x00000000;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING((count < 3 ? count : 3) * 5 + 2);
+
+       if (count >= 1) {
+               OUT_RING(CCE_PACKET0(R128_AUX1_SC_LEFT, 3));
+               OUT_RING(boxes[0].x1);
+               OUT_RING(boxes[0].x2 - 1);
+               OUT_RING(boxes[0].y1);
+               OUT_RING(boxes[0].y2 - 1);
+
+               aux_sc_cntl |= (R128_AUX1_SC_EN | R128_AUX1_SC_MODE_OR);
+       }
+       if (count >= 2) {
+               OUT_RING(CCE_PACKET0(R128_AUX2_SC_LEFT, 3));
+               OUT_RING(boxes[1].x1);
+               OUT_RING(boxes[1].x2 - 1);
+               OUT_RING(boxes[1].y1);
+               OUT_RING(boxes[1].y2 - 1);
+
+               aux_sc_cntl |= (R128_AUX2_SC_EN | R128_AUX2_SC_MODE_OR);
+       }
+       if (count >= 3) {
+               OUT_RING(CCE_PACKET0(R128_AUX3_SC_LEFT, 3));
+               OUT_RING(boxes[2].x1);
+               OUT_RING(boxes[2].x2 - 1);
+               OUT_RING(boxes[2].y1);
+               OUT_RING(boxes[2].y2 - 1);
+
+               aux_sc_cntl |= (R128_AUX3_SC_EN | R128_AUX3_SC_MODE_OR);
+       }
+
+       OUT_RING(CCE_PACKET0(R128_AUX_SC_CNTL, 0));
+       OUT_RING(aux_sc_cntl);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_core(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_SCALE_3D_CNTL, 0));
+       OUT_RING(ctx->scale_3d_cntl);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_context(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(13);
+
+       OUT_RING(CCE_PACKET0(R128_DST_PITCH_OFFSET_C, 11));
+       OUT_RING(ctx->dst_pitch_offset_c);
+       OUT_RING(ctx->dp_gui_master_cntl_c);
+       OUT_RING(ctx->sc_top_left_c);
+       OUT_RING(ctx->sc_bottom_right_c);
+       OUT_RING(ctx->z_offset_c);
+       OUT_RING(ctx->z_pitch_c);
+       OUT_RING(ctx->z_sten_cntl_c);
+       OUT_RING(ctx->tex_cntl_c);
+       OUT_RING(ctx->misc_3d_state_cntl_reg);
+       OUT_RING(ctx->texture_clr_cmp_clr_c);
+       OUT_RING(ctx->texture_clr_cmp_msk_c);
+       OUT_RING(ctx->fog_color_c);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_setup(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(3);
+
+       OUT_RING(CCE_PACKET1(R128_SETUP_CNTL, R128_PM4_VC_FPU_SETUP));
+       OUT_RING(ctx->setup_cntl);
+       OUT_RING(ctx->pm4_vc_fpu_setup);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_masks(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(5);
+
+       OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
+       OUT_RING(ctx->dp_write_mask);
+
+       OUT_RING(CCE_PACKET0(R128_STEN_REF_MASK_C, 1));
+       OUT_RING(ctx->sten_ref_mask_c);
+       OUT_RING(ctx->plane_3d_mask_c);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_window(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_WINDOW_XY_OFFSET, 0));
+       OUT_RING(ctx->window_xy_offset);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_tex0(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
+       drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[0];
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(7 + R128_MAX_TEXTURE_LEVELS);
+
+       OUT_RING(CCE_PACKET0(R128_PRIM_TEX_CNTL_C,
+                            2 + R128_MAX_TEXTURE_LEVELS));
+       OUT_RING(tex->tex_cntl);
+       OUT_RING(tex->tex_combine_cntl);
+       OUT_RING(ctx->tex_size_pitch_c);
+       for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
+               OUT_RING(tex->tex_offset[i]);
+       }
+
+       OUT_RING(CCE_PACKET0(R128_CONSTANT_COLOR_C, 1));
+       OUT_RING(ctx->constant_color_c);
+       OUT_RING(tex->tex_border_color);
+
+       ADVANCE_RING();
+}
+
+static __inline__ void r128_emit_tex1(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[1];
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(5 + R128_MAX_TEXTURE_LEVELS);
+
+       OUT_RING(CCE_PACKET0(R128_SEC_TEX_CNTL_C, 1 + R128_MAX_TEXTURE_LEVELS));
+       OUT_RING(tex->tex_cntl);
+       OUT_RING(tex->tex_combine_cntl);
+       for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
+               OUT_RING(tex->tex_offset[i]);
+       }
+
+       OUT_RING(CCE_PACKET0(R128_SEC_TEXTURE_BORDER_COLOR_C, 0));
+       OUT_RING(tex->tex_border_color);
+
+       ADVANCE_RING();
+}
+
+static void r128_emit_state(drm_r128_private_t * dev_priv)
+{
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       unsigned int dirty = sarea_priv->dirty;
+
+       DRM_DEBUG("dirty=0x%08x\n", dirty);
+
+       if (dirty & R128_UPLOAD_CORE) {
+               r128_emit_core(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_CORE;
+       }
+
+       if (dirty & R128_UPLOAD_CONTEXT) {
+               r128_emit_context(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_CONTEXT;
+       }
+
+       if (dirty & R128_UPLOAD_SETUP) {
+               r128_emit_setup(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_SETUP;
+       }
+
+       if (dirty & R128_UPLOAD_MASKS) {
+               r128_emit_masks(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_MASKS;
+       }
+
+       if (dirty & R128_UPLOAD_WINDOW) {
+               r128_emit_window(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_WINDOW;
+       }
+
+       if (dirty & R128_UPLOAD_TEX0) {
+               r128_emit_tex0(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_TEX0;
+       }
+
+       if (dirty & R128_UPLOAD_TEX1) {
+               r128_emit_tex1(dev_priv);
+               sarea_priv->dirty &= ~R128_UPLOAD_TEX1;
+       }
+
+       /* Turn off the texture cache flushing */
+       sarea_priv->context_state.tex_cntl_c &= ~R128_TEX_CACHE_FLUSH;
+
+       sarea_priv->dirty &= ~R128_REQUIRE_QUIESCENCE;
+}
+
+#if R128_PERFORMANCE_BOXES
+/* ================================================================
+ * Performance monitoring functions
+ */
+
+static void r128_clear_box(drm_r128_private_t * dev_priv,
+                          int x, int y, int w, int h, int r, int g, int b)
+{
+       u32 pitch, offset;
+       u32 fb_bpp, color;
+       RING_LOCALS;
+
+       switch (dev_priv->fb_bpp) {
+       case 16:
+               fb_bpp = R128_GMC_DST_16BPP;
+               color = (((r & 0xf8) << 8) |
+                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
+               break;
+       case 24:
+               fb_bpp = R128_GMC_DST_24BPP;
+               color = ((r << 16) | (g << 8) | b);
+               break;
+       case 32:
+               fb_bpp = R128_GMC_DST_32BPP;
+               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
+               break;
+       default:
+               return;
+       }
+
+       offset = dev_priv->back_offset;
+       pitch = dev_priv->back_pitch >> 3;
+
+       BEGIN_RING(6);
+
+       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                R128_GMC_BRUSH_SOLID_COLOR |
+                fb_bpp |
+                R128_GMC_SRC_DATATYPE_COLOR |
+                R128_ROP3_P |
+                R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_AUX_CLIP_DIS);
+
+       OUT_RING((pitch << 21) | (offset >> 5));
+       OUT_RING(color);
+
+       OUT_RING((x << 16) | y);
+       OUT_RING((w << 16) | h);
+
+       ADVANCE_RING();
+}
+
+static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
+{
+       if (atomic_read(&dev_priv->idle_count) == 0) {
+               r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
+       } else {
+               atomic_set(&dev_priv->idle_count, 0);
+       }
+}
+
+#endif
+
+/* ================================================================
+ * CCE command dispatch functions
+ */
+
+static void r128_print_dirty(const char *msg, unsigned int flags)
+{
+       DRM_INFO("%s: (0x%x) %s%s%s%s%s%s%s%s%s\n",
+                msg,
+                flags,
+                (flags & R128_UPLOAD_CORE) ? "core, " : "",
+                (flags & R128_UPLOAD_CONTEXT) ? "context, " : "",
+                (flags & R128_UPLOAD_SETUP) ? "setup, " : "",
+                (flags & R128_UPLOAD_TEX0) ? "tex0, " : "",
+                (flags & R128_UPLOAD_TEX1) ? "tex1, " : "",
+                (flags & R128_UPLOAD_MASKS) ? "masks, " : "",
+                (flags & R128_UPLOAD_WINDOW) ? "window, " : "",
+                (flags & R128_UPLOAD_CLIPRECTS) ? "cliprects, " : "",
+                (flags & R128_REQUIRE_QUIESCENCE) ? "quiescence, " : "");
+}
+
+static void r128_cce_dispatch_clear(struct drm_device * dev,
+                                   drm_r128_clear_t * clear)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       unsigned int flags = clear->flags;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       if (dev_priv->page_flipping && dev_priv->current_page == 1) {
+               unsigned int tmp = flags;
+
+               flags &= ~(R128_FRONT | R128_BACK);
+               if (tmp & R128_FRONT)
+                       flags |= R128_BACK;
+               if (tmp & R128_BACK)
+                       flags |= R128_FRONT;
+       }
+
+       for (i = 0; i < nbox; i++) {
+               int x = pbox[i].x1;
+               int y = pbox[i].y1;
+               int w = pbox[i].x2 - x;
+               int h = pbox[i].y2 - y;
+
+               DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
+                         pbox[i].x1, pbox[i].y1, pbox[i].x2,
+                         pbox[i].y2, flags);
+
+               if (flags & (R128_FRONT | R128_BACK)) {
+                       BEGIN_RING(2);
+
+                       OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
+                       OUT_RING(clear->color_mask);
+
+                       ADVANCE_RING();
+               }
+
+               if (flags & R128_FRONT) {
+                       BEGIN_RING(6);
+
+                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                R128_GMC_BRUSH_SOLID_COLOR |
+                                (dev_priv->color_fmt << 8) |
+                                R128_GMC_SRC_DATATYPE_COLOR |
+                                R128_ROP3_P |
+                                R128_GMC_CLR_CMP_CNTL_DIS |
+                                R128_GMC_AUX_CLIP_DIS);
+
+                       OUT_RING(dev_priv->front_pitch_offset_c);
+                       OUT_RING(clear->clear_color);
+
+                       OUT_RING((x << 16) | y);
+                       OUT_RING((w << 16) | h);
+
+                       ADVANCE_RING();
+               }
+
+               if (flags & R128_BACK) {
+                       BEGIN_RING(6);
+
+                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                R128_GMC_BRUSH_SOLID_COLOR |
+                                (dev_priv->color_fmt << 8) |
+                                R128_GMC_SRC_DATATYPE_COLOR |
+                                R128_ROP3_P |
+                                R128_GMC_CLR_CMP_CNTL_DIS |
+                                R128_GMC_AUX_CLIP_DIS);
+
+                       OUT_RING(dev_priv->back_pitch_offset_c);
+                       OUT_RING(clear->clear_color);
+
+                       OUT_RING((x << 16) | y);
+                       OUT_RING((w << 16) | h);
+
+                       ADVANCE_RING();
+               }
+
+               if (flags & R128_DEPTH) {
+                       BEGIN_RING(6);
+
+                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                R128_GMC_BRUSH_SOLID_COLOR |
+                                (dev_priv->depth_fmt << 8) |
+                                R128_GMC_SRC_DATATYPE_COLOR |
+                                R128_ROP3_P |
+                                R128_GMC_CLR_CMP_CNTL_DIS |
+                                R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
+
+                       OUT_RING(dev_priv->depth_pitch_offset_c);
+                       OUT_RING(clear->clear_depth);
+
+                       OUT_RING((x << 16) | y);
+                       OUT_RING((w << 16) | h);
+
+                       ADVANCE_RING();
+               }
+       }
+}
+
+static void r128_cce_dispatch_swap(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+#if R128_PERFORMANCE_BOXES
+       /* Do some trivial performance monitoring...
+        */
+       r128_cce_performance_boxes(dev_priv);
+#endif
+
+       for (i = 0; i < nbox; i++) {
+               int x = pbox[i].x1;
+               int y = pbox[i].y1;
+               int w = pbox[i].x2 - x;
+               int h = pbox[i].y2 - y;
+
+               BEGIN_RING(7);
+
+               OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
+               OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
+                        R128_GMC_DST_PITCH_OFFSET_CNTL |
+                        R128_GMC_BRUSH_NONE |
+                        (dev_priv->color_fmt << 8) |
+                        R128_GMC_SRC_DATATYPE_COLOR |
+                        R128_ROP3_S |
+                        R128_DP_SRC_SOURCE_MEMORY |
+                        R128_GMC_CLR_CMP_CNTL_DIS |
+                        R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
+
+               /* Make this work even if front & back are flipped:
+                */
+               if (dev_priv->current_page == 0) {
+                       OUT_RING(dev_priv->back_pitch_offset_c);
+                       OUT_RING(dev_priv->front_pitch_offset_c);
+               } else {
+                       OUT_RING(dev_priv->front_pitch_offset_c);
+                       OUT_RING(dev_priv->back_pitch_offset_c);
+               }
+
+               OUT_RING((x << 16) | y);
+               OUT_RING((x << 16) | y);
+               OUT_RING((w << 16) | h);
+
+               ADVANCE_RING();
+       }
+
+       /* Increment the frame counter.  The client-side 3D driver must
+        * throttle the framerate by waiting for this value before
+        * performing the swapbuffer ioctl.
+        */
+       dev_priv->sarea_priv->last_frame++;
+
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
+       OUT_RING(dev_priv->sarea_priv->last_frame);
+
+       ADVANCE_RING();
+}
+
+static void r128_cce_dispatch_flip(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+       DRM_DEBUG("page=%d pfCurrentPage=%d\n",
+                 dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage);
+
+#if R128_PERFORMANCE_BOXES
+       /* Do some trivial performance monitoring...
+        */
+       r128_cce_performance_boxes(dev_priv);
+#endif
+
+       BEGIN_RING(4);
+
+       R128_WAIT_UNTIL_PAGE_FLIPPED();
+       OUT_RING(CCE_PACKET0(R128_CRTC_OFFSET, 0));
+
+       if (dev_priv->current_page == 0) {
+               OUT_RING(dev_priv->back_offset);
+       } else {
+               OUT_RING(dev_priv->front_offset);
+       }
+
+       ADVANCE_RING();
+
+       /* Increment the frame counter.  The client-side 3D driver must
+        * throttle the framerate by waiting for this value before
+        * performing the swapbuffer ioctl.
+        */
+       dev_priv->sarea_priv->last_frame++;
+       dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page =
+           1 - dev_priv->current_page;
+
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
+       OUT_RING(dev_priv->sarea_priv->last_frame);
+
+       ADVANCE_RING();
+}
+
+static void r128_cce_dispatch_vertex(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int format = sarea_priv->vc_format;
+       int offset = buf->bus_address;
+       int size = buf->used;
+       int prim = buf_priv->prim;
+       int i = 0;
+       RING_LOCALS;
+       DRM_DEBUG("buf=%d nbox=%d\n", buf->idx, sarea_priv->nbox);
+
+       if (0)
+               r128_print_dirty("dispatch_vertex", sarea_priv->dirty);
+
+       if (buf->used) {
+               buf_priv->dispatched = 1;
+
+               if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
+                       r128_emit_state(dev_priv);
+               }
+
+               do {
+                       /* Emit the next set of up to three cliprects */
+                       if (i < sarea_priv->nbox) {
+                               r128_emit_clip_rects(dev_priv,
+                                                    &sarea_priv->boxes[i],
+                                                    sarea_priv->nbox - i);
+                       }
+
+                       /* Emit the vertex buffer rendering commands */
+                       BEGIN_RING(5);
+
+                       OUT_RING(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM, 3));
+                       OUT_RING(offset);
+                       OUT_RING(size);
+                       OUT_RING(format);
+                       OUT_RING(prim | R128_CCE_VC_CNTL_PRIM_WALK_LIST |
+                                (size << R128_CCE_VC_CNTL_NUM_SHIFT));
+
+                       ADVANCE_RING();
+
+                       i += 3;
+               } while (i < sarea_priv->nbox);
+       }
+
+       if (buf_priv->discard) {
+               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
+
+               /* Emit the vertex buffer age */
+               BEGIN_RING(2);
+
+               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
+               OUT_RING(buf_priv->age);
+
+               ADVANCE_RING();
+
+               buf->pending = 1;
+               buf->used = 0;
+               /* FIXME: Check dispatched field */
+               buf_priv->dispatched = 0;
+       }
+
+       dev_priv->sarea_priv->last_dispatch++;
+
+       sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
+       sarea_priv->nbox = 0;
+}
+
+static void r128_cce_dispatch_indirect(struct drm_device * dev,
+                                      struct drm_buf * buf, int start, int end)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
+       RING_LOCALS;
+       DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
+
+       if (start != end) {
+               int offset = buf->bus_address + start;
+               int dwords = (end - start + 3) / sizeof(u32);
+
+               /* Indirect buffer data must be an even number of
+                * dwords, so if we've been given an odd number we must
+                * pad the data with a Type-2 CCE packet.
+                */
+               if (dwords & 1) {
+                       u32 *data = (u32 *)
+                           ((char *)dev->agp_buffer_map->handle
+                            + buf->offset + start);
+                       data[dwords++] = cpu_to_le32(R128_CCE_PACKET2);
+               }
+
+               buf_priv->dispatched = 1;
+
+               /* Fire off the indirect buffer */
+               BEGIN_RING(3);
+
+               OUT_RING(CCE_PACKET0(R128_PM4_IW_INDOFF, 1));
+               OUT_RING(offset);
+               OUT_RING(dwords);
+
+               ADVANCE_RING();
+       }
+
+       if (buf_priv->discard) {
+               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
+
+               /* Emit the indirect buffer age */
+               BEGIN_RING(2);
+
+               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
+               OUT_RING(buf_priv->age);
+
+               ADVANCE_RING();
+
+               buf->pending = 1;
+               buf->used = 0;
+               /* FIXME: Check dispatched field */
+               buf_priv->dispatched = 0;
+       }
+
+       dev_priv->sarea_priv->last_dispatch++;
+}
+
+static void r128_cce_dispatch_indices(struct drm_device * dev,
+                                     struct drm_buf * buf,
+                                     int start, int end, int count)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_buf_priv_t *buf_priv = buf->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int format = sarea_priv->vc_format;
+       int offset = dev->agp_buffer_map->offset - dev_priv->cce_buffers_offset;
+       int prim = buf_priv->prim;
+       u32 *data;
+       int dwords;
+       int i = 0;
+       RING_LOCALS;
+       DRM_DEBUG("indices: s=%d e=%d c=%d\n", start, end, count);
+
+       if (0)
+               r128_print_dirty("dispatch_indices", sarea_priv->dirty);
+
+       if (start != end) {
+               buf_priv->dispatched = 1;
+
+               if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
+                       r128_emit_state(dev_priv);
+               }
+
+               dwords = (end - start + 3) / sizeof(u32);
+
+               data = (u32 *) ((char *)dev->agp_buffer_map->handle
+                               + buf->offset + start);
+
+               data[0] = cpu_to_le32(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM,
+                                                 dwords - 2));
+
+               data[1] = cpu_to_le32(offset);
+               data[2] = cpu_to_le32(R128_MAX_VB_VERTS);
+               data[3] = cpu_to_le32(format);
+               data[4] = cpu_to_le32((prim | R128_CCE_VC_CNTL_PRIM_WALK_IND |
+                                      (count << 16)));
+
+               if (count & 0x1) {
+#ifdef __LITTLE_ENDIAN
+                       data[dwords - 1] &= 0x0000ffff;
+#else
+                       data[dwords - 1] &= 0xffff0000;
+#endif
+               }
+
+               do {
+                       /* Emit the next set of up to three cliprects */
+                       if (i < sarea_priv->nbox) {
+                               r128_emit_clip_rects(dev_priv,
+                                                    &sarea_priv->boxes[i],
+                                                    sarea_priv->nbox - i);
+                       }
+
+                       r128_cce_dispatch_indirect(dev, buf, start, end);
+
+                       i += 3;
+               } while (i < sarea_priv->nbox);
+       }
+
+       if (buf_priv->discard) {
+               buf_priv->age = dev_priv->sarea_priv->last_dispatch;
+
+               /* Emit the vertex buffer age */
+               BEGIN_RING(2);
+
+               OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
+               OUT_RING(buf_priv->age);
+
+               ADVANCE_RING();
+
+               buf->pending = 1;
+               /* FIXME: Check dispatched field */
+               buf_priv->dispatched = 0;
+       }
+
+       dev_priv->sarea_priv->last_dispatch++;
+
+       sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
+       sarea_priv->nbox = 0;
+}
+
+static int r128_cce_dispatch_blit(struct drm_device * dev,
+                                 struct drm_file *file_priv,
+                                 drm_r128_blit_t * blit)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_r128_buf_priv_t *buf_priv;
+       u32 *data;
+       int dword_shift, dwords;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       /* The compiler won't optimize away a division by a variable,
+        * even if the only legal values are powers of two.  Thus, we'll
+        * use a shift instead.
+        */
+       switch (blit->format) {
+       case R128_DATATYPE_ARGB8888:
+               dword_shift = 0;
+               break;
+       case R128_DATATYPE_ARGB1555:
+       case R128_DATATYPE_RGB565:
+       case R128_DATATYPE_ARGB4444:
+       case R128_DATATYPE_YVYU422:
+       case R128_DATATYPE_VYUY422:
+               dword_shift = 1;
+               break;
+       case R128_DATATYPE_CI8:
+       case R128_DATATYPE_RGB8:
+               dword_shift = 2;
+               break;
+       default:
+               DRM_ERROR("invalid blit format %d\n", blit->format);
+               return -EINVAL;
+       }
+
+       /* Flush the pixel cache, and mark the contents as Read Invalid.
+        * This ensures no pixel data gets mixed up with the texture
+        * data from the host data blit, otherwise part of the texture
+        * image may be corrupted.
+        */
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
+       OUT_RING(R128_PC_RI_GUI | R128_PC_FLUSH_GUI);
+
+       ADVANCE_RING();
+
+       /* Dispatch the indirect buffer.
+        */
+       buf = dma->buflist[blit->idx];
+       buf_priv = buf->dev_private;
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", blit->idx);
+               return -EINVAL;
+       }
+
+       buf_priv->discard = 1;
+
+       dwords = (blit->width * blit->height) >> dword_shift;
+
+       data = (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);
+
+       data[0] = cpu_to_le32(CCE_PACKET3(R128_CNTL_HOSTDATA_BLT, dwords + 6));
+       data[1] = cpu_to_le32((R128_GMC_DST_PITCH_OFFSET_CNTL |
+                              R128_GMC_BRUSH_NONE |
+                              (blit->format << 8) |
+                              R128_GMC_SRC_DATATYPE_COLOR |
+                              R128_ROP3_S |
+                              R128_DP_SRC_SOURCE_HOST_DATA |
+                              R128_GMC_CLR_CMP_CNTL_DIS |
+                              R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS));
+
+       data[2] = cpu_to_le32((blit->pitch << 21) | (blit->offset >> 5));
+       data[3] = cpu_to_le32(0xffffffff);
+       data[4] = cpu_to_le32(0xffffffff);
+       data[5] = cpu_to_le32((blit->y << 16) | blit->x);
+       data[6] = cpu_to_le32((blit->height << 16) | blit->width);
+       data[7] = cpu_to_le32(dwords);
+
+       buf->used = (dwords + 8) * sizeof(u32);
+
+       r128_cce_dispatch_indirect(dev, buf, 0, buf->used);
+
+       /* Flush the pixel cache after the blit completes.  This ensures
+        * the texture data is written out to memory before rendering
+        * continues.
+        */
+       BEGIN_RING(2);
+
+       OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
+       OUT_RING(R128_PC_FLUSH_GUI);
+
+       ADVANCE_RING();
+
+       return 0;
+}
+
+/* ================================================================
+ * Tiled depth buffer management
+ *
+ * FIXME: These should all set the destination write mask for when we
+ * have hardware stencil support.
+ */
+
+static int r128_cce_dispatch_write_span(struct drm_device * dev,
+                                       drm_r128_depth_t * depth)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       int count, x, y;
+       u32 *buffer;
+       u8 *mask;
+       int i, buffer_size, mask_size;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       count = depth->n;
+       if (count > 4096 || count <= 0)
+               return -EMSGSIZE;
+
+       if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
+               return -EFAULT;
+       }
+       if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
+               return -EFAULT;
+       }
+
+       buffer_size = depth->n * sizeof(u32);
+       buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
+       if (buffer == NULL)
+               return -ENOMEM;
+       if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
+               drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+
+       mask_size = depth->n * sizeof(u8);
+       if (depth->mask) {
+               mask = drm_alloc(mask_size, DRM_MEM_BUFS);
+               if (mask == NULL) {
+                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+                       return -ENOMEM;
+               }
+               if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
+                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+                       drm_free(mask, mask_size, DRM_MEM_BUFS);
+                       return -EFAULT;
+               }
+
+               for (i = 0; i < count; i++, x++) {
+                       if (mask[i]) {
+                               BEGIN_RING(6);
+
+                               OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                               OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                        R128_GMC_BRUSH_SOLID_COLOR |
+                                        (dev_priv->depth_fmt << 8) |
+                                        R128_GMC_SRC_DATATYPE_COLOR |
+                                        R128_ROP3_P |
+                                        R128_GMC_CLR_CMP_CNTL_DIS |
+                                        R128_GMC_WR_MSK_DIS);
+
+                               OUT_RING(dev_priv->depth_pitch_offset_c);
+                               OUT_RING(buffer[i]);
+
+                               OUT_RING((x << 16) | y);
+                               OUT_RING((1 << 16) | 1);
+
+                               ADVANCE_RING();
+                       }
+               }
+
+               drm_free(mask, mask_size, DRM_MEM_BUFS);
+       } else {
+               for (i = 0; i < count; i++, x++) {
+                       BEGIN_RING(6);
+
+                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                R128_GMC_BRUSH_SOLID_COLOR |
+                                (dev_priv->depth_fmt << 8) |
+                                R128_GMC_SRC_DATATYPE_COLOR |
+                                R128_ROP3_P |
+                                R128_GMC_CLR_CMP_CNTL_DIS |
+                                R128_GMC_WR_MSK_DIS);
+
+                       OUT_RING(dev_priv->depth_pitch_offset_c);
+                       OUT_RING(buffer[i]);
+
+                       OUT_RING((x << 16) | y);
+                       OUT_RING((1 << 16) | 1);
+
+                       ADVANCE_RING();
+               }
+       }
+
+       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+
+       return 0;
+}
+
+static int r128_cce_dispatch_write_pixels(struct drm_device * dev,
+                                         drm_r128_depth_t * depth)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       int count, *x, *y;
+       u32 *buffer;
+       u8 *mask;
+       int i, xbuf_size, ybuf_size, buffer_size, mask_size;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       count = depth->n;
+       if (count > 4096 || count <= 0)
+               return -EMSGSIZE;
+
+       xbuf_size = count * sizeof(*x);
+       ybuf_size = count * sizeof(*y);
+       x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
+       if (x == NULL) {
+               return -ENOMEM;
+       }
+       y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
+       if (y == NULL) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               return -ENOMEM;
+       }
+       if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+       if (DRM_COPY_FROM_USER(y, depth->y, xbuf_size)) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+
+       buffer_size = depth->n * sizeof(u32);
+       buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
+       if (buffer == NULL) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               return -ENOMEM;
+       }
+       if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+
+       if (depth->mask) {
+               mask_size = depth->n * sizeof(u8);
+               mask = drm_alloc(mask_size, DRM_MEM_BUFS);
+               if (mask == NULL) {
+                       drm_free(x, xbuf_size, DRM_MEM_BUFS);
+                       drm_free(y, ybuf_size, DRM_MEM_BUFS);
+                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+                       return -ENOMEM;
+               }
+               if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
+                       drm_free(x, xbuf_size, DRM_MEM_BUFS);
+                       drm_free(y, ybuf_size, DRM_MEM_BUFS);
+                       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+                       drm_free(mask, mask_size, DRM_MEM_BUFS);
+                       return -EFAULT;
+               }
+
+               for (i = 0; i < count; i++) {
+                       if (mask[i]) {
+                               BEGIN_RING(6);
+
+                               OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                               OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                        R128_GMC_BRUSH_SOLID_COLOR |
+                                        (dev_priv->depth_fmt << 8) |
+                                        R128_GMC_SRC_DATATYPE_COLOR |
+                                        R128_ROP3_P |
+                                        R128_GMC_CLR_CMP_CNTL_DIS |
+                                        R128_GMC_WR_MSK_DIS);
+
+                               OUT_RING(dev_priv->depth_pitch_offset_c);
+                               OUT_RING(buffer[i]);
+
+                               OUT_RING((x[i] << 16) | y[i]);
+                               OUT_RING((1 << 16) | 1);
+
+                               ADVANCE_RING();
+                       }
+               }
+
+               drm_free(mask, mask_size, DRM_MEM_BUFS);
+       } else {
+               for (i = 0; i < count; i++) {
+                       BEGIN_RING(6);
+
+                       OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
+                       OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
+                                R128_GMC_BRUSH_SOLID_COLOR |
+                                (dev_priv->depth_fmt << 8) |
+                                R128_GMC_SRC_DATATYPE_COLOR |
+                                R128_ROP3_P |
+                                R128_GMC_CLR_CMP_CNTL_DIS |
+                                R128_GMC_WR_MSK_DIS);
+
+                       OUT_RING(dev_priv->depth_pitch_offset_c);
+                       OUT_RING(buffer[i]);
+
+                       OUT_RING((x[i] << 16) | y[i]);
+                       OUT_RING((1 << 16) | 1);
+
+                       ADVANCE_RING();
+               }
+       }
+
+       drm_free(x, xbuf_size, DRM_MEM_BUFS);
+       drm_free(y, ybuf_size, DRM_MEM_BUFS);
+       drm_free(buffer, buffer_size, DRM_MEM_BUFS);
+
+       return 0;
+}
+
+static int r128_cce_dispatch_read_span(struct drm_device * dev,
+                                      drm_r128_depth_t * depth)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       int count, x, y;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       count = depth->n;
+       if (count > 4096 || count <= 0)
+               return -EMSGSIZE;
+
+       if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
+               return -EFAULT;
+       }
+       if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
+               return -EFAULT;
+       }
+
+       BEGIN_RING(7);
+
+       OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
+       OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
+                R128_GMC_DST_PITCH_OFFSET_CNTL |
+                R128_GMC_BRUSH_NONE |
+                (dev_priv->depth_fmt << 8) |
+                R128_GMC_SRC_DATATYPE_COLOR |
+                R128_ROP3_S |
+                R128_DP_SRC_SOURCE_MEMORY |
+                R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
+
+       OUT_RING(dev_priv->depth_pitch_offset_c);
+       OUT_RING(dev_priv->span_pitch_offset_c);
+
+       OUT_RING((x << 16) | y);
+       OUT_RING((0 << 16) | 0);
+       OUT_RING((count << 16) | 1);
+
+       ADVANCE_RING();
+
+       return 0;
+}
+
+static int r128_cce_dispatch_read_pixels(struct drm_device * dev,
+                                        drm_r128_depth_t * depth)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       int count, *x, *y;
+       int i, xbuf_size, ybuf_size;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       count = depth->n;
+       if (count > 4096 || count <= 0)
+               return -EMSGSIZE;
+
+       if (count > dev_priv->depth_pitch) {
+               count = dev_priv->depth_pitch;
+       }
+
+       xbuf_size = count * sizeof(*x);
+       ybuf_size = count * sizeof(*y);
+       x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
+       if (x == NULL) {
+               return -ENOMEM;
+       }
+       y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
+       if (y == NULL) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               return -ENOMEM;
+       }
+       if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+       if (DRM_COPY_FROM_USER(y, depth->y, ybuf_size)) {
+               drm_free(x, xbuf_size, DRM_MEM_BUFS);
+               drm_free(y, ybuf_size, DRM_MEM_BUFS);
+               return -EFAULT;
+       }
+
+       for (i = 0; i < count; i++) {
+               BEGIN_RING(7);
+
+               OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
+               OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
+                        R128_GMC_DST_PITCH_OFFSET_CNTL |
+                        R128_GMC_BRUSH_NONE |
+                        (dev_priv->depth_fmt << 8) |
+                        R128_GMC_SRC_DATATYPE_COLOR |
+                        R128_ROP3_S |
+                        R128_DP_SRC_SOURCE_MEMORY |
+                        R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
+
+               OUT_RING(dev_priv->depth_pitch_offset_c);
+               OUT_RING(dev_priv->span_pitch_offset_c);
+
+               OUT_RING((x[i] << 16) | y[i]);
+               OUT_RING((i << 16) | 0);
+               OUT_RING((1 << 16) | 1);
+
+               ADVANCE_RING();
+       }
+
+       drm_free(x, xbuf_size, DRM_MEM_BUFS);
+       drm_free(y, ybuf_size, DRM_MEM_BUFS);
+
+       return 0;
+}
+
+/* ================================================================
+ * Polygon stipple
+ */
+
+static void r128_cce_dispatch_stipple(struct drm_device * dev, u32 * stipple)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(33);
+
+       OUT_RING(CCE_PACKET0(R128_BRUSH_DATA0, 31));
+       for (i = 0; i < 32; i++) {
+               OUT_RING(stipple[i]);
+       }
+
+       ADVANCE_RING();
+}
+
+/* ================================================================
+ * IOCTL functions
+ */
+
+static int r128_cce_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_r128_clear_t *clear = data;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
+
+       r128_cce_dispatch_clear(dev, clear);
+       COMMIT_RING();
+
+       /* Make sure we restore the 3D state next time.
+        */
+       dev_priv->sarea_priv->dirty |= R128_UPLOAD_CONTEXT | R128_UPLOAD_MASKS;
+
+       return 0;
+}
+
+static int r128_do_init_pageflip(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       dev_priv->crtc_offset = R128_READ(R128_CRTC_OFFSET);
+       dev_priv->crtc_offset_cntl = R128_READ(R128_CRTC_OFFSET_CNTL);
+
+       R128_WRITE(R128_CRTC_OFFSET, dev_priv->front_offset);
+       R128_WRITE(R128_CRTC_OFFSET_CNTL,
+                  dev_priv->crtc_offset_cntl | R128_CRTC_OFFSET_FLIP_CNTL);
+
+       dev_priv->page_flipping = 1;
+       dev_priv->current_page = 0;
+       dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page;
+
+       return 0;
+}
+
+static int r128_do_cleanup_pageflip(struct drm_device * dev)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       R128_WRITE(R128_CRTC_OFFSET, dev_priv->crtc_offset);
+       R128_WRITE(R128_CRTC_OFFSET_CNTL, dev_priv->crtc_offset_cntl);
+
+       if (dev_priv->current_page != 0) {
+               r128_cce_dispatch_flip(dev);
+               COMMIT_RING();
+       }
+
+       dev_priv->page_flipping = 0;
+       return 0;
+}
+
+/* Swapping and flipping are different operations, need different ioctls.
+ * They can & should be intermixed to support multiple 3d windows.
+ */
+
+static int r128_cce_flip(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (!dev_priv->page_flipping)
+               r128_do_init_pageflip(dev);
+
+       r128_cce_dispatch_flip(dev);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_cce_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS;
+
+       r128_cce_dispatch_swap(dev);
+       dev_priv->sarea_priv->dirty |= (R128_UPLOAD_CONTEXT |
+                                       R128_UPLOAD_MASKS);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_cce_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_r128_buf_priv_t *buf_priv;
+       drm_r128_vertex_t *vertex = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
+                 DRM_CURRENTPID, vertex->idx, vertex->count, vertex->discard);
+
+       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         vertex->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+       if (vertex->prim < 0 ||
+           vertex->prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) {
+               DRM_ERROR("buffer prim %d\n", vertex->prim);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf = dma->buflist[vertex->idx];
+       buf_priv = buf->dev_private;
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
+               return -EINVAL;
+       }
+
+       buf->used = vertex->count;
+       buf_priv->prim = vertex->prim;
+       buf_priv->discard = vertex->discard;
+
+       r128_cce_dispatch_vertex(dev, buf);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_cce_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_r128_buf_priv_t *buf_priv;
+       drm_r128_indices_t *elts = data;
+       int count;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d buf=%d s=%d e=%d d=%d\n", DRM_CURRENTPID,
+                 elts->idx, elts->start, elts->end, elts->discard);
+
+       if (elts->idx < 0 || elts->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         elts->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+       if (elts->prim < 0 ||
+           elts->prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) {
+               DRM_ERROR("buffer prim %d\n", elts->prim);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf = dma->buflist[elts->idx];
+       buf_priv = buf->dev_private;
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", elts->idx);
+               return -EINVAL;
+       }
+
+       count = (elts->end - elts->start) / sizeof(u16);
+       elts->start -= R128_INDEX_PRIM_OFFSET;
+
+       if (elts->start & 0x7) {
+               DRM_ERROR("misaligned buffer 0x%x\n", elts->start);
+               return -EINVAL;
+       }
+       if (elts->start < buf->used) {
+               DRM_ERROR("no header 0x%x - 0x%x\n", elts->start, buf->used);
+               return -EINVAL;
+       }
+
+       buf->used = elts->end;
+       buf_priv->prim = elts->prim;
+       buf_priv->discard = elts->discard;
+
+       r128_cce_dispatch_indices(dev, buf, elts->start, elts->end, count);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_cce_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_blit_t *blit = data;
+       int ret;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("pid=%d index=%d\n", DRM_CURRENTPID, blit->idx);
+
+       if (blit->idx < 0 || blit->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         blit->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       ret = r128_cce_dispatch_blit(dev, file_priv, blit);
+
+       COMMIT_RING();
+       return ret;
+}
+
+static int r128_cce_depth(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_depth_t *depth = data;
+       int ret;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       ret = -EINVAL;
+       switch (depth->func) {
+       case R128_WRITE_SPAN:
+               ret = r128_cce_dispatch_write_span(dev, depth);
+               break;
+       case R128_WRITE_PIXELS:
+               ret = r128_cce_dispatch_write_pixels(dev, depth);
+               break;
+       case R128_READ_SPAN:
+               ret = r128_cce_dispatch_read_span(dev, depth);
+               break;
+       case R128_READ_PIXELS:
+               ret = r128_cce_dispatch_read_pixels(dev, depth);
+               break;
+       }
+
+       COMMIT_RING();
+       return ret;
+}
+
+static int r128_cce_stipple(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_stipple_t *stipple = data;
+       u32 mask[32];
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (DRM_COPY_FROM_USER(&mask, stipple->mask, 32 * sizeof(u32)))
+               return -EFAULT;
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       r128_cce_dispatch_stipple(dev, mask);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_cce_indirect(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_r128_buf_priv_t *buf_priv;
+       drm_r128_indirect_t *indirect = data;
+#if 0
+       RING_LOCALS;
+#endif
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
+                 indirect->idx, indirect->start, indirect->end,
+                 indirect->discard);
+
+       if (indirect->idx < 0 || indirect->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         indirect->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+
+       buf = dma->buflist[indirect->idx];
+       buf_priv = buf->dev_private;
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", indirect->idx);
+               return -EINVAL;
+       }
+
+       if (indirect->start < buf->used) {
+               DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
+                         indirect->start, buf->used);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf->used = indirect->end;
+       buf_priv->discard = indirect->discard;
+
+#if 0
+       /* Wait for the 3D stream to idle before the indirect buffer
+        * containing 2D acceleration commands is processed.
+        */
+       BEGIN_RING(2);
+       RADEON_WAIT_UNTIL_3D_IDLE();
+       ADVANCE_RING();
+#endif
+
+       /* Dispatch the indirect buffer full of commands from the
+        * X server.  This is insecure and is thus only available to
+        * privileged clients.
+        */
+       r128_cce_dispatch_indirect(dev, buf, indirect->start, indirect->end);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int r128_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_r128_private_t *dev_priv = dev->dev_private;
+       drm_r128_getparam_t *param = data;
+       int value;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
+
+       switch (param->param) {
+       case R128_PARAM_IRQ_NR:
+               value = dev->irq;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+void r128_driver_preclose(struct drm_device * dev, struct drm_file *file_priv)
+{
+       if (dev->dev_private) {
+               drm_r128_private_t *dev_priv = dev->dev_private;
+               if (dev_priv->page_flipping) {
+                       r128_do_cleanup_pageflip(dev);
+               }
+       }
+}
+
+void r128_driver_lastclose(struct drm_device * dev)
+{
+       r128_do_cleanup_cce(dev);
+}
+
+struct drm_ioctl_desc r128_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_R128_INIT, r128_cce_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_R128_CCE_START, r128_cce_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_R128_CCE_STOP, r128_cce_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_R128_CCE_RESET, r128_cce_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_R128_CCE_IDLE, r128_cce_idle, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_RESET, r128_engine_reset, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_FULLSCREEN, r128_fullscreen, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_SWAP, r128_cce_swap, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_FLIP, r128_cce_flip, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_CLEAR, r128_cce_clear, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_VERTEX, r128_cce_vertex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_INDICES, r128_cce_indices, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_BLIT, r128_cce_blit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_DEPTH, r128_cce_depth, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_STIPPLE, r128_cce_stipple, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_R128_INDIRECT, r128_cce_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_R128_GETPARAM, r128_getparam, DRM_AUTH),
+};
+
+int r128_max_ioctl = DRM_ARRAY_SIZE(r128_ioctls);
diff --git a/drivers/gpu/drm/radeon/Makefile b/drivers/gpu/drm/radeon/Makefile
new file mode 100644 (file)
index 0000000..feb521e
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+radeon-y := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o
+
+radeon-$(CONFIG_COMPAT) += radeon_ioc32.o
+
+obj-$(CONFIG_DRM_RADEON)+= radeon.o
diff --git a/drivers/gpu/drm/radeon/r300_cmdbuf.c b/drivers/gpu/drm/radeon/r300_cmdbuf.c
new file mode 100644 (file)
index 0000000..702df45
--- /dev/null
@@ -0,0 +1,1071 @@
+/* r300_cmdbuf.c -- Command buffer emission for R300 -*- linux-c -*-
+ *
+ * Copyright (C) The Weather Channel, Inc.  2002.
+ * Copyright (C) 2004 Nicolai Haehnle.
+ * All Rights Reserved.
+ *
+ * The Weather Channel (TM) funded Tungsten Graphics to develop the
+ * initial release of the Radeon 8500 driver under the XFree86 license.
+ * This notice must be preserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Nicolai Haehnle <prefect_@gmx.net>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+#include "r300_reg.h"
+
+#define R300_SIMULTANEOUS_CLIPRECTS            4
+
+/* Values for R300_RE_CLIPRECT_CNTL depending on the number of cliprects
+ */
+static const int r300_cliprect_cntl[4] = {
+       0xAAAA,
+       0xEEEE,
+       0xFEFE,
+       0xFFFE
+};
+
+/**
+ * Emit up to R300_SIMULTANEOUS_CLIPRECTS cliprects from the given command
+ * buffer, starting with index n.
+ */
+static int r300_emit_cliprects(drm_radeon_private_t *dev_priv,
+                              drm_radeon_kcmd_buffer_t *cmdbuf, int n)
+{
+       struct drm_clip_rect box;
+       int nr;
+       int i;
+       RING_LOCALS;
+
+       nr = cmdbuf->nbox - n;
+       if (nr > R300_SIMULTANEOUS_CLIPRECTS)
+               nr = R300_SIMULTANEOUS_CLIPRECTS;
+
+       DRM_DEBUG("%i cliprects\n", nr);
+
+       if (nr) {
+               BEGIN_RING(6 + nr * 2);
+               OUT_RING(CP_PACKET0(R300_RE_CLIPRECT_TL_0, nr * 2 - 1));
+
+               for (i = 0; i < nr; ++i) {
+                       if (DRM_COPY_FROM_USER_UNCHECKED
+                           (&box, &cmdbuf->boxes[n + i], sizeof(box))) {
+                               DRM_ERROR("copy cliprect faulted\n");
+                               return -EFAULT;
+                       }
+
+                       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
+                               box.x1 = (box.x1) &
+                                       R300_CLIPRECT_MASK;
+                               box.y1 = (box.y1) &
+                                       R300_CLIPRECT_MASK;
+                               box.x2 = (box.x2) &
+                                       R300_CLIPRECT_MASK;
+                               box.y2 = (box.y2) &
+                                       R300_CLIPRECT_MASK;
+                       } else {
+                               box.x1 = (box.x1 + R300_CLIPRECT_OFFSET) &
+                                       R300_CLIPRECT_MASK;
+                               box.y1 = (box.y1 + R300_CLIPRECT_OFFSET) &
+                                       R300_CLIPRECT_MASK;
+                               box.x2 = (box.x2 + R300_CLIPRECT_OFFSET) &
+                                       R300_CLIPRECT_MASK;
+                               box.y2 = (box.y2 + R300_CLIPRECT_OFFSET) &
+                                       R300_CLIPRECT_MASK;
+
+                       }
+                       OUT_RING((box.x1 << R300_CLIPRECT_X_SHIFT) |
+                                (box.y1 << R300_CLIPRECT_Y_SHIFT));
+                       OUT_RING((box.x2 << R300_CLIPRECT_X_SHIFT) |
+                                (box.y2 << R300_CLIPRECT_Y_SHIFT));
+
+               }
+
+               OUT_RING_REG(R300_RE_CLIPRECT_CNTL, r300_cliprect_cntl[nr - 1]);
+
+               /* TODO/SECURITY: Force scissors to a safe value, otherwise the
+                * client might be able to trample over memory.
+                * The impact should be very limited, but I'd rather be safe than
+                * sorry.
+                */
+               OUT_RING(CP_PACKET0(R300_RE_SCISSORS_TL, 1));
+               OUT_RING(0);
+               OUT_RING(R300_SCISSORS_X_MASK | R300_SCISSORS_Y_MASK);
+               ADVANCE_RING();
+       } else {
+               /* Why we allow zero cliprect rendering:
+                * There are some commands in a command buffer that must be submitted
+                * even when there are no cliprects, e.g. DMA buffer discard
+                * or state setting (though state setting could be avoided by
+                * simulating a loss of context).
+                *
+                * Now since the cmdbuf interface is so chaotic right now (and is
+                * bound to remain that way for a bit until things settle down),
+                * it is basically impossible to filter out the commands that are
+                * necessary and those that aren't.
+                *
+                * So I choose the safe way and don't do any filtering at all;
+                * instead, I simply set up the engine so that all rendering
+                * can't produce any fragments.
+                */
+               BEGIN_RING(2);
+               OUT_RING_REG(R300_RE_CLIPRECT_CNTL, 0);
+               ADVANCE_RING();
+       }
+
+       return 0;
+}
+
+static u8 r300_reg_flags[0x10000 >> 2];
+
+void r300_init_reg_flags(struct drm_device *dev)
+{
+       int i;
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       memset(r300_reg_flags, 0, 0x10000 >> 2);
+#define ADD_RANGE_MARK(reg, count,mark) \
+               for(i=((reg)>>2);i<((reg)>>2)+(count);i++)\
+                       r300_reg_flags[i]|=(mark);
+
+#define MARK_SAFE              1
+#define MARK_CHECK_OFFSET      2
+
+#define ADD_RANGE(reg, count)  ADD_RANGE_MARK(reg, count, MARK_SAFE)
+
+       /* these match cmducs() command in r300_driver/r300/r300_cmdbuf.c */
+       ADD_RANGE(R300_SE_VPORT_XSCALE, 6);
+       ADD_RANGE(R300_VAP_CNTL, 1);
+       ADD_RANGE(R300_SE_VTE_CNTL, 2);
+       ADD_RANGE(0x2134, 2);
+       ADD_RANGE(R300_VAP_CNTL_STATUS, 1);
+       ADD_RANGE(R300_VAP_INPUT_CNTL_0, 2);
+       ADD_RANGE(0x21DC, 1);
+       ADD_RANGE(R300_VAP_UNKNOWN_221C, 1);
+       ADD_RANGE(R300_VAP_CLIP_X_0, 4);
+       ADD_RANGE(R300_VAP_PVS_WAITIDLE, 1);
+       ADD_RANGE(R300_VAP_UNKNOWN_2288, 1);
+       ADD_RANGE(R300_VAP_OUTPUT_VTX_FMT_0, 2);
+       ADD_RANGE(R300_VAP_PVS_CNTL_1, 3);
+       ADD_RANGE(R300_GB_ENABLE, 1);
+       ADD_RANGE(R300_GB_MSPOS0, 5);
+       ADD_RANGE(R300_TX_CNTL, 1);
+       ADD_RANGE(R300_TX_ENABLE, 1);
+       ADD_RANGE(0x4200, 4);
+       ADD_RANGE(0x4214, 1);
+       ADD_RANGE(R300_RE_POINTSIZE, 1);
+       ADD_RANGE(0x4230, 3);
+       ADD_RANGE(R300_RE_LINE_CNT, 1);
+       ADD_RANGE(R300_RE_UNK4238, 1);
+       ADD_RANGE(0x4260, 3);
+       ADD_RANGE(R300_RE_SHADE, 4);
+       ADD_RANGE(R300_RE_POLYGON_MODE, 5);
+       ADD_RANGE(R300_RE_ZBIAS_CNTL, 1);
+       ADD_RANGE(R300_RE_ZBIAS_T_FACTOR, 4);
+       ADD_RANGE(R300_RE_OCCLUSION_CNTL, 1);
+       ADD_RANGE(R300_RE_CULL_CNTL, 1);
+       ADD_RANGE(0x42C0, 2);
+       ADD_RANGE(R300_RS_CNTL_0, 2);
+
+       ADD_RANGE(R300_SC_HYPERZ, 2);
+       ADD_RANGE(0x43E8, 1);
+
+       ADD_RANGE(0x46A4, 5);
+
+       ADD_RANGE(R300_RE_FOG_STATE, 1);
+       ADD_RANGE(R300_FOG_COLOR_R, 3);
+       ADD_RANGE(R300_PP_ALPHA_TEST, 2);
+       ADD_RANGE(0x4BD8, 1);
+       ADD_RANGE(R300_PFS_PARAM_0_X, 64);
+       ADD_RANGE(0x4E00, 1);
+       ADD_RANGE(R300_RB3D_CBLEND, 2);
+       ADD_RANGE(R300_RB3D_COLORMASK, 1);
+       ADD_RANGE(R300_RB3D_BLEND_COLOR, 3);
+       ADD_RANGE_MARK(R300_RB3D_COLOROFFSET0, 1, MARK_CHECK_OFFSET);   /* check offset */
+       ADD_RANGE(R300_RB3D_COLORPITCH0, 1);
+       ADD_RANGE(0x4E50, 9);
+       ADD_RANGE(0x4E88, 1);
+       ADD_RANGE(0x4EA0, 2);
+       ADD_RANGE(R300_ZB_CNTL, 3);
+       ADD_RANGE(R300_ZB_FORMAT, 4);
+       ADD_RANGE_MARK(R300_ZB_DEPTHOFFSET, 1, MARK_CHECK_OFFSET);      /* check offset */
+       ADD_RANGE(R300_ZB_DEPTHPITCH, 1);
+       ADD_RANGE(R300_ZB_DEPTHCLEARVALUE, 1);
+       ADD_RANGE(R300_ZB_ZMASK_OFFSET, 13);
+
+       ADD_RANGE(R300_TX_FILTER_0, 16);
+       ADD_RANGE(R300_TX_FILTER1_0, 16);
+       ADD_RANGE(R300_TX_SIZE_0, 16);
+       ADD_RANGE(R300_TX_FORMAT_0, 16);
+       ADD_RANGE(R300_TX_PITCH_0, 16);
+       /* Texture offset is dangerous and needs more checking */
+       ADD_RANGE_MARK(R300_TX_OFFSET_0, 16, MARK_CHECK_OFFSET);
+       ADD_RANGE(R300_TX_CHROMA_KEY_0, 16);
+       ADD_RANGE(R300_TX_BORDER_COLOR_0, 16);
+
+       /* Sporadic registers used as primitives are emitted */
+       ADD_RANGE(R300_ZB_ZCACHE_CTLSTAT, 1);
+       ADD_RANGE(R300_RB3D_DSTCACHE_CTLSTAT, 1);
+       ADD_RANGE(R300_VAP_INPUT_ROUTE_0_0, 8);
+       ADD_RANGE(R300_VAP_INPUT_ROUTE_1_0, 8);
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
+               ADD_RANGE(R500_VAP_INDEX_OFFSET, 1);
+               ADD_RANGE(R500_US_CONFIG, 2);
+               ADD_RANGE(R500_US_CODE_ADDR, 3);
+               ADD_RANGE(R500_US_FC_CTRL, 1);
+               ADD_RANGE(R500_RS_IP_0, 16);
+               ADD_RANGE(R500_RS_INST_0, 16);
+               ADD_RANGE(R500_RB3D_COLOR_CLEAR_VALUE_AR, 2);
+               ADD_RANGE(R500_RB3D_CONSTANT_COLOR_AR, 2);
+               ADD_RANGE(R500_ZB_FIFO_SIZE, 2);
+       } else {
+               ADD_RANGE(R300_PFS_CNTL_0, 3);
+               ADD_RANGE(R300_PFS_NODE_0, 4);
+               ADD_RANGE(R300_PFS_TEXI_0, 64);
+               ADD_RANGE(R300_PFS_INSTR0_0, 64);
+               ADD_RANGE(R300_PFS_INSTR1_0, 64);
+               ADD_RANGE(R300_PFS_INSTR2_0, 64);
+               ADD_RANGE(R300_PFS_INSTR3_0, 64);
+               ADD_RANGE(R300_RS_INTERP_0, 8);
+               ADD_RANGE(R300_RS_ROUTE_0, 8);
+
+       }
+}
+
+static __inline__ int r300_check_range(unsigned reg, int count)
+{
+       int i;
+       if (reg & ~0xffff)
+               return -1;
+       for (i = (reg >> 2); i < (reg >> 2) + count; i++)
+               if (r300_reg_flags[i] != MARK_SAFE)
+                       return 1;
+       return 0;
+}
+
+static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
+                                                         dev_priv,
+                                                         drm_radeon_kcmd_buffer_t
+                                                         * cmdbuf,
+                                                         drm_r300_cmd_header_t
+                                                         header)
+{
+       int reg;
+       int sz;
+       int i;
+       int values[64];
+       RING_LOCALS;
+
+       sz = header.packet0.count;
+       reg = (header.packet0.reghi << 8) | header.packet0.reglo;
+
+       if ((sz > 64) || (sz < 0)) {
+               DRM_ERROR
+                   ("Cannot emit more than 64 values at a time (reg=%04x sz=%d)\n",
+                    reg, sz);
+               return -EINVAL;
+       }
+       for (i = 0; i < sz; i++) {
+               values[i] = ((int *)cmdbuf->buf)[i];
+               switch (r300_reg_flags[(reg >> 2) + i]) {
+               case MARK_SAFE:
+                       break;
+               case MARK_CHECK_OFFSET:
+                       if (!radeon_check_offset(dev_priv, (u32) values[i])) {
+                               DRM_ERROR
+                                   ("Offset failed range check (reg=%04x sz=%d)\n",
+                                    reg, sz);
+                               return -EINVAL;
+                       }
+                       break;
+               default:
+                       DRM_ERROR("Register %04x failed check as flag=%02x\n",
+                                 reg + i * 4, r300_reg_flags[(reg >> 2) + i]);
+                       return -EINVAL;
+               }
+       }
+
+       BEGIN_RING(1 + sz);
+       OUT_RING(CP_PACKET0(reg, sz - 1));
+       OUT_RING_TABLE(values, sz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * 4;
+       cmdbuf->bufsz -= sz * 4;
+
+       return 0;
+}
+
+/**
+ * Emits a packet0 setting arbitrary registers.
+ * Called by r300_do_cp_cmdbuf.
+ *
+ * Note that checks are performed on contents and addresses of the registers
+ */
+static __inline__ int r300_emit_packet0(drm_radeon_private_t *dev_priv,
+                                       drm_radeon_kcmd_buffer_t *cmdbuf,
+                                       drm_r300_cmd_header_t header)
+{
+       int reg;
+       int sz;
+       RING_LOCALS;
+
+       sz = header.packet0.count;
+       reg = (header.packet0.reghi << 8) | header.packet0.reglo;
+
+       if (!sz)
+               return 0;
+
+       if (sz * 4 > cmdbuf->bufsz)
+               return -EINVAL;
+
+       if (reg + sz * 4 >= 0x10000) {
+               DRM_ERROR("No such registers in hardware reg=%04x sz=%d\n", reg,
+                         sz);
+               return -EINVAL;
+       }
+
+       if (r300_check_range(reg, sz)) {
+               /* go and check everything */
+               return r300_emit_carefully_checked_packet0(dev_priv, cmdbuf,
+                                                          header);
+       }
+       /* the rest of the data is safe to emit, whatever the values the user passed */
+
+       BEGIN_RING(1 + sz);
+       OUT_RING(CP_PACKET0(reg, sz - 1));
+       OUT_RING_TABLE((int *)cmdbuf->buf, sz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * 4;
+       cmdbuf->bufsz -= sz * 4;
+
+       return 0;
+}
+
+/**
+ * Uploads user-supplied vertex program instructions or parameters onto
+ * the graphics card.
+ * Called by r300_do_cp_cmdbuf.
+ */
+static __inline__ int r300_emit_vpu(drm_radeon_private_t *dev_priv,
+                                   drm_radeon_kcmd_buffer_t *cmdbuf,
+                                   drm_r300_cmd_header_t header)
+{
+       int sz;
+       int addr;
+       RING_LOCALS;
+
+       sz = header.vpu.count;
+       addr = (header.vpu.adrhi << 8) | header.vpu.adrlo;
+
+       if (!sz)
+               return 0;
+       if (sz * 16 > cmdbuf->bufsz)
+               return -EINVAL;
+
+       BEGIN_RING(5 + sz * 4);
+       /* Wait for VAP to come to senses.. */
+       /* there is no need to emit it multiple times, (only once before VAP is programmed,
+          but this optimization is for later */
+       OUT_RING_REG(R300_VAP_PVS_WAITIDLE, 0);
+       OUT_RING_REG(R300_VAP_PVS_UPLOAD_ADDRESS, addr);
+       OUT_RING(CP_PACKET0_TABLE(R300_VAP_PVS_UPLOAD_DATA, sz * 4 - 1));
+       OUT_RING_TABLE((int *)cmdbuf->buf, sz * 4);
+
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * 16;
+       cmdbuf->bufsz -= sz * 16;
+
+       return 0;
+}
+
+/**
+ * Emit a clear packet from userspace.
+ * Called by r300_emit_packet3.
+ */
+static __inline__ int r300_emit_clear(drm_radeon_private_t *dev_priv,
+                                     drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       RING_LOCALS;
+
+       if (8 * 4 > cmdbuf->bufsz)
+               return -EINVAL;
+
+       BEGIN_RING(10);
+       OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 8));
+       OUT_RING(R300_PRIM_TYPE_POINT | R300_PRIM_WALK_RING |
+                (1 << R300_PRIM_NUM_VERTICES_SHIFT));
+       OUT_RING_TABLE((int *)cmdbuf->buf, 8);
+       ADVANCE_RING();
+
+       cmdbuf->buf += 8 * 4;
+       cmdbuf->bufsz -= 8 * 4;
+
+       return 0;
+}
+
+static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
+                                              drm_radeon_kcmd_buffer_t *cmdbuf,
+                                              u32 header)
+{
+       int count, i, k;
+#define MAX_ARRAY_PACKET  64
+       u32 payload[MAX_ARRAY_PACKET];
+       u32 narrays;
+       RING_LOCALS;
+
+       count = (header >> 16) & 0x3fff;
+
+       if ((count + 1) > MAX_ARRAY_PACKET) {
+               DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
+                         count);
+               return -EINVAL;
+       }
+       memset(payload, 0, MAX_ARRAY_PACKET * 4);
+       memcpy(payload, cmdbuf->buf + 4, (count + 1) * 4);
+
+       /* carefully check packet contents */
+
+       narrays = payload[0];
+       k = 0;
+       i = 1;
+       while ((k < narrays) && (i < (count + 1))) {
+               i++;            /* skip attribute field */
+               if (!radeon_check_offset(dev_priv, payload[i])) {
+                       DRM_ERROR
+                           ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
+                            k, i);
+                       return -EINVAL;
+               }
+               k++;
+               i++;
+               if (k == narrays)
+                       break;
+               /* have one more to process, they come in pairs */
+               if (!radeon_check_offset(dev_priv, payload[i])) {
+                       DRM_ERROR
+                           ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
+                            k, i);
+                       return -EINVAL;
+               }
+               k++;
+               i++;
+       }
+       /* do the counts match what we expect ? */
+       if ((k != narrays) || (i != (count + 1))) {
+               DRM_ERROR
+                   ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
+                    k, i, narrays, count + 1);
+               return -EINVAL;
+       }
+
+       /* all clear, output packet */
+
+       BEGIN_RING(count + 2);
+       OUT_RING(header);
+       OUT_RING_TABLE(payload, count + 1);
+       ADVANCE_RING();
+
+       cmdbuf->buf += (count + 2) * 4;
+       cmdbuf->bufsz -= (count + 2) * 4;
+
+       return 0;
+}
+
+static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
+                                            drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       u32 *cmd = (u32 *) cmdbuf->buf;
+       int count, ret;
+       RING_LOCALS;
+
+       count=(cmd[0]>>16) & 0x3fff;
+
+       if (cmd[0] & 0x8000) {
+               u32 offset;
+
+               if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
+                             | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
+                       offset = cmd[2] << 10;
+                       ret = !radeon_check_offset(dev_priv, offset);
+                       if (ret) {
+                               DRM_ERROR("Invalid bitblt first offset is %08X\n", offset);
+                               return -EINVAL;
+                       }
+               }
+
+               if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
+                   (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
+                       offset = cmd[3] << 10;
+                       ret = !radeon_check_offset(dev_priv, offset);
+                       if (ret) {
+                               DRM_ERROR("Invalid bitblt second offset is %08X\n", offset);
+                               return -EINVAL;
+                       }
+
+               }
+       }
+
+       BEGIN_RING(count+2);
+       OUT_RING(cmd[0]);
+       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
+       ADVANCE_RING();
+
+       cmdbuf->buf += (count+2)*4;
+       cmdbuf->bufsz -= (count+2)*4;
+
+       return 0;
+}
+
+static __inline__ int r300_emit_indx_buffer(drm_radeon_private_t *dev_priv,
+                                            drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       u32 *cmd = (u32 *) cmdbuf->buf;
+       int count, ret;
+       RING_LOCALS;
+
+       count=(cmd[0]>>16) & 0x3fff;
+
+       if ((cmd[1] & 0x8000ffff) != 0x80000810) {
+               DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
+               return -EINVAL;
+       }
+       ret = !radeon_check_offset(dev_priv, cmd[2]);
+       if (ret) {
+               DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
+               return -EINVAL;
+       }
+
+       BEGIN_RING(count+2);
+       OUT_RING(cmd[0]);
+       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
+       ADVANCE_RING();
+
+       cmdbuf->buf += (count+2)*4;
+       cmdbuf->bufsz -= (count+2)*4;
+
+       return 0;
+}
+
+static __inline__ int r300_emit_raw_packet3(drm_radeon_private_t *dev_priv,
+                                           drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       u32 header;
+       int count;
+       RING_LOCALS;
+
+       if (4 > cmdbuf->bufsz)
+               return -EINVAL;
+
+       /* Fixme !! This simply emits a packet without much checking.
+          We need to be smarter. */
+
+       /* obtain first word - actual packet3 header */
+       header = *(u32 *) cmdbuf->buf;
+
+       /* Is it packet 3 ? */
+       if ((header >> 30) != 0x3) {
+               DRM_ERROR("Not a packet3 header (0x%08x)\n", header);
+               return -EINVAL;
+       }
+
+       count = (header >> 16) & 0x3fff;
+
+       /* Check again now that we know how much data to expect */
+       if ((count + 2) * 4 > cmdbuf->bufsz) {
+               DRM_ERROR
+                   ("Expected packet3 of length %d but have only %d bytes left\n",
+                    (count + 2) * 4, cmdbuf->bufsz);
+               return -EINVAL;
+       }
+
+       /* Is it a packet type we know about ? */
+       switch (header & 0xff00) {
+       case RADEON_3D_LOAD_VBPNTR:     /* load vertex array pointers */
+               return r300_emit_3d_load_vbpntr(dev_priv, cmdbuf, header);
+
+       case RADEON_CNTL_BITBLT_MULTI:
+               return r300_emit_bitblt_multi(dev_priv, cmdbuf);
+
+       case RADEON_CP_INDX_BUFFER:     /* DRAW_INDX_2 without INDX_BUFFER seems to lock up the gpu */
+               return r300_emit_indx_buffer(dev_priv, cmdbuf);
+       case RADEON_CP_3D_DRAW_IMMD_2:  /* triggers drawing using in-packet vertex data */
+       case RADEON_CP_3D_DRAW_VBUF_2:  /* triggers drawing of vertex buffers setup elsewhere */
+       case RADEON_CP_3D_DRAW_INDX_2:  /* triggers drawing using indices to vertex buffer */
+       case RADEON_WAIT_FOR_IDLE:
+       case RADEON_CP_NOP:
+               /* these packets are safe */
+               break;
+       default:
+               DRM_ERROR("Unknown packet3 header (0x%08x)\n", header);
+               return -EINVAL;
+       }
+
+       BEGIN_RING(count + 2);
+       OUT_RING(header);
+       OUT_RING_TABLE((int *)(cmdbuf->buf + 4), count + 1);
+       ADVANCE_RING();
+
+       cmdbuf->buf += (count + 2) * 4;
+       cmdbuf->bufsz -= (count + 2) * 4;
+
+       return 0;
+}
+
+/**
+ * Emit a rendering packet3 from userspace.
+ * Called by r300_do_cp_cmdbuf.
+ */
+static __inline__ int r300_emit_packet3(drm_radeon_private_t *dev_priv,
+                                       drm_radeon_kcmd_buffer_t *cmdbuf,
+                                       drm_r300_cmd_header_t header)
+{
+       int n;
+       int ret;
+       char *orig_buf = cmdbuf->buf;
+       int orig_bufsz = cmdbuf->bufsz;
+
+       /* This is a do-while-loop so that we run the interior at least once,
+        * even if cmdbuf->nbox is 0. Compare r300_emit_cliprects for rationale.
+        */
+       n = 0;
+       do {
+               if (cmdbuf->nbox > R300_SIMULTANEOUS_CLIPRECTS) {
+                       ret = r300_emit_cliprects(dev_priv, cmdbuf, n);
+                       if (ret)
+                               return ret;
+
+                       cmdbuf->buf = orig_buf;
+                       cmdbuf->bufsz = orig_bufsz;
+               }
+
+               switch (header.packet3.packet) {
+               case R300_CMD_PACKET3_CLEAR:
+                       DRM_DEBUG("R300_CMD_PACKET3_CLEAR\n");
+                       ret = r300_emit_clear(dev_priv, cmdbuf);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_clear failed\n");
+                               return ret;
+                       }
+                       break;
+
+               case R300_CMD_PACKET3_RAW:
+                       DRM_DEBUG("R300_CMD_PACKET3_RAW\n");
+                       ret = r300_emit_raw_packet3(dev_priv, cmdbuf);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_raw_packet3 failed\n");
+                               return ret;
+                       }
+                       break;
+
+               default:
+                       DRM_ERROR("bad packet3 type %i at %p\n",
+                                 header.packet3.packet,
+                                 cmdbuf->buf - sizeof(header));
+                       return -EINVAL;
+               }
+
+               n += R300_SIMULTANEOUS_CLIPRECTS;
+       } while (n < cmdbuf->nbox);
+
+       return 0;
+}
+
+/* Some of the R300 chips seem to be extremely touchy about the two registers
+ * that are configured in r300_pacify.
+ * Among the worst offenders seems to be the R300 ND (0x4E44): When userspace
+ * sends a command buffer that contains only state setting commands and a
+ * vertex program/parameter upload sequence, this will eventually lead to a
+ * lockup, unless the sequence is bracketed by calls to r300_pacify.
+ * So we should take great care to *always* call r300_pacify before
+ * *anything* 3D related, and again afterwards. This is what the
+ * call bracket in r300_do_cp_cmdbuf is for.
+ */
+
+/**
+ * Emit the sequence to pacify R300.
+ */
+static __inline__ void r300_pacify(drm_radeon_private_t *dev_priv)
+{
+       RING_LOCALS;
+
+       BEGIN_RING(6);
+       OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
+       OUT_RING(R300_RB3D_DSTCACHE_UNKNOWN_0A);
+       OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0));
+       OUT_RING(R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE|
+                R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
+       OUT_RING(CP_PACKET3(RADEON_CP_NOP, 0));
+       OUT_RING(0x0);
+       ADVANCE_RING();
+}
+
+/**
+ * Called by r300_do_cp_cmdbuf to update the internal buffer age and state.
+ * The actual age emit is done by r300_do_cp_cmdbuf, which is why you must
+ * be careful about how this function is called.
+ */
+static void r300_discard_buffer(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
+
+       buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
+       buf->pending = 1;
+       buf->used = 0;
+}
+
+static void r300_cmd_wait(drm_radeon_private_t * dev_priv,
+                         drm_r300_cmd_header_t header)
+{
+       u32 wait_until;
+       RING_LOCALS;
+
+       if (!header.wait.flags)
+               return;
+
+       wait_until = 0;
+
+       switch(header.wait.flags) {
+       case R300_WAIT_2D:
+               wait_until = RADEON_WAIT_2D_IDLE;
+               break;
+       case R300_WAIT_3D:
+               wait_until = RADEON_WAIT_3D_IDLE;
+               break;
+       case R300_NEW_WAIT_2D_3D:
+               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_3D_IDLE;
+               break;
+       case R300_NEW_WAIT_2D_2D_CLEAN:
+               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_2D_IDLECLEAN;
+               break;
+       case R300_NEW_WAIT_3D_3D_CLEAN:
+               wait_until = RADEON_WAIT_3D_IDLE|RADEON_WAIT_3D_IDLECLEAN;
+               break;
+       case R300_NEW_WAIT_2D_2D_CLEAN_3D_3D_CLEAN:
+               wait_until = RADEON_WAIT_2D_IDLE|RADEON_WAIT_2D_IDLECLEAN;
+               wait_until |= RADEON_WAIT_3D_IDLE|RADEON_WAIT_3D_IDLECLEAN;
+               break;
+       default:
+               return;
+       }
+
+       BEGIN_RING(2);
+       OUT_RING(CP_PACKET0(RADEON_WAIT_UNTIL, 0));
+       OUT_RING(wait_until);
+       ADVANCE_RING();
+}
+
+static int r300_scratch(drm_radeon_private_t *dev_priv,
+                       drm_radeon_kcmd_buffer_t *cmdbuf,
+                       drm_r300_cmd_header_t header)
+{
+       u32 *ref_age_base;
+       u32 i, buf_idx, h_pending;
+       RING_LOCALS;
+
+       if (cmdbuf->bufsz <
+           (sizeof(u64) + header.scratch.n_bufs * sizeof(buf_idx))) {
+               return -EINVAL;
+       }
+
+       if (header.scratch.reg >= 5) {
+               return -EINVAL;
+       }
+
+       dev_priv->scratch_ages[header.scratch.reg]++;
+
+       ref_age_base =  (u32 *)(unsigned long)*((uint64_t *)cmdbuf->buf);
+
+       cmdbuf->buf += sizeof(u64);
+       cmdbuf->bufsz -= sizeof(u64);
+
+       for (i=0; i < header.scratch.n_bufs; i++) {
+               buf_idx = *(u32 *)cmdbuf->buf;
+               buf_idx *= 2; /* 8 bytes per buf */
+
+               if (DRM_COPY_TO_USER(ref_age_base + buf_idx, &dev_priv->scratch_ages[header.scratch.reg], sizeof(u32))) {
+                       return -EINVAL;
+               }
+
+               if (DRM_COPY_FROM_USER(&h_pending, ref_age_base + buf_idx + 1, sizeof(u32))) {
+                       return -EINVAL;
+               }
+
+               if (h_pending == 0) {
+                       return -EINVAL;
+               }
+
+               h_pending--;
+
+               if (DRM_COPY_TO_USER(ref_age_base + buf_idx + 1, &h_pending, sizeof(u32))) {
+                       return -EINVAL;
+               }
+
+               cmdbuf->buf += sizeof(buf_idx);
+               cmdbuf->bufsz -= sizeof(buf_idx);
+       }
+
+       BEGIN_RING(2);
+       OUT_RING( CP_PACKET0( RADEON_SCRATCH_REG0 + header.scratch.reg * 4, 0 ) );
+       OUT_RING( dev_priv->scratch_ages[header.scratch.reg] );
+       ADVANCE_RING();
+
+       return 0;
+}
+
+/**
+ * Uploads user-supplied vertex program instructions or parameters onto
+ * the graphics card.
+ * Called by r300_do_cp_cmdbuf.
+ */
+static inline int r300_emit_r500fp(drm_radeon_private_t *dev_priv,
+                                      drm_radeon_kcmd_buffer_t *cmdbuf,
+                                      drm_r300_cmd_header_t header)
+{
+       int sz;
+       int addr;
+       int type;
+       int clamp;
+       int stride;
+       RING_LOCALS;
+
+       sz = header.r500fp.count;
+       /* address is 9 bits 0 - 8, bit 1 of flags is part of address */
+       addr = ((header.r500fp.adrhi_flags & 1) << 8) | header.r500fp.adrlo;
+
+       type = !!(header.r500fp.adrhi_flags & R500FP_CONSTANT_TYPE);
+       clamp = !!(header.r500fp.adrhi_flags & R500FP_CONSTANT_CLAMP);
+
+       addr |= (type << 16);
+       addr |= (clamp << 17);
+
+       stride = type ? 4 : 6;
+
+       DRM_DEBUG("r500fp %d %d type: %d\n", sz, addr, type);
+       if (!sz)
+               return 0;
+       if (sz * stride * 4 > cmdbuf->bufsz)
+               return -EINVAL;
+
+       BEGIN_RING(3 + sz * stride);
+       OUT_RING_REG(R500_GA_US_VECTOR_INDEX, addr);
+       OUT_RING(CP_PACKET0_TABLE(R500_GA_US_VECTOR_DATA, sz * stride - 1));
+       OUT_RING_TABLE((int *)cmdbuf->buf, sz * stride);
+
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * stride * 4;
+       cmdbuf->bufsz -= sz * stride * 4;
+
+       return 0;
+}
+
+
+/**
+ * Parses and validates a user-supplied command buffer and emits appropriate
+ * commands on the DMA ring buffer.
+ * Called by the ioctl handler function radeon_cp_cmdbuf.
+ */
+int r300_do_cp_cmdbuf(struct drm_device *dev,
+                     struct drm_file *file_priv,
+                     drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf = NULL;
+       int emit_dispatch_age = 0;
+       int ret = 0;
+
+       DRM_DEBUG("\n");
+
+       /* See the comment above r300_emit_begin3d for why this call must be here,
+        * and what the cleanup gotos are for. */
+       r300_pacify(dev_priv);
+
+       if (cmdbuf->nbox <= R300_SIMULTANEOUS_CLIPRECTS) {
+               ret = r300_emit_cliprects(dev_priv, cmdbuf, 0);
+               if (ret)
+                       goto cleanup;
+       }
+
+       while (cmdbuf->bufsz >= sizeof(drm_r300_cmd_header_t)) {
+               int idx;
+               drm_r300_cmd_header_t header;
+
+               header.u = *(unsigned int *)cmdbuf->buf;
+
+               cmdbuf->buf += sizeof(header);
+               cmdbuf->bufsz -= sizeof(header);
+
+               switch (header.header.cmd_type) {
+               case R300_CMD_PACKET0:
+                       DRM_DEBUG("R300_CMD_PACKET0\n");
+                       ret = r300_emit_packet0(dev_priv, cmdbuf, header);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_packet0 failed\n");
+                               goto cleanup;
+                       }
+                       break;
+
+               case R300_CMD_VPU:
+                       DRM_DEBUG("R300_CMD_VPU\n");
+                       ret = r300_emit_vpu(dev_priv, cmdbuf, header);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_vpu failed\n");
+                               goto cleanup;
+                       }
+                       break;
+
+               case R300_CMD_PACKET3:
+                       DRM_DEBUG("R300_CMD_PACKET3\n");
+                       ret = r300_emit_packet3(dev_priv, cmdbuf, header);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_packet3 failed\n");
+                               goto cleanup;
+                       }
+                       break;
+
+               case R300_CMD_END3D:
+                       DRM_DEBUG("R300_CMD_END3D\n");
+                       /* TODO:
+                          Ideally userspace driver should not need to issue this call,
+                          i.e. the drm driver should issue it automatically and prevent
+                          lockups.
+
+                          In practice, we do not understand why this call is needed and what
+                          it does (except for some vague guesses that it has to do with cache
+                          coherence) and so the user space driver does it.
+
+                          Once we are sure which uses prevent lockups the code could be moved
+                          into the kernel and the userspace driver will not
+                          need to use this command.
+
+                          Note that issuing this command does not hurt anything
+                          except, possibly, performance */
+                       r300_pacify(dev_priv);
+                       break;
+
+               case R300_CMD_CP_DELAY:
+                       /* simple enough, we can do it here */
+                       DRM_DEBUG("R300_CMD_CP_DELAY\n");
+                       {
+                               int i;
+                               RING_LOCALS;
+
+                               BEGIN_RING(header.delay.count);
+                               for (i = 0; i < header.delay.count; i++)
+                                       OUT_RING(RADEON_CP_PACKET2);
+                               ADVANCE_RING();
+                       }
+                       break;
+
+               case R300_CMD_DMA_DISCARD:
+                       DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
+                       idx = header.dma.buf_idx;
+                       if (idx < 0 || idx >= dma->buf_count) {
+                               DRM_ERROR("buffer index %d (of %d max)\n",
+                                         idx, dma->buf_count - 1);
+                               ret = -EINVAL;
+                               goto cleanup;
+                       }
+
+                       buf = dma->buflist[idx];
+                       if (buf->file_priv != file_priv || buf->pending) {
+                               DRM_ERROR("bad buffer %p %p %d\n",
+                                         buf->file_priv, file_priv,
+                                         buf->pending);
+                               ret = -EINVAL;
+                               goto cleanup;
+                       }
+
+                       emit_dispatch_age = 1;
+                       r300_discard_buffer(dev, buf);
+                       break;
+
+               case R300_CMD_WAIT:
+                       DRM_DEBUG("R300_CMD_WAIT\n");
+                       r300_cmd_wait(dev_priv, header);
+                       break;
+
+               case R300_CMD_SCRATCH:
+                       DRM_DEBUG("R300_CMD_SCRATCH\n");
+                       ret = r300_scratch(dev_priv, cmdbuf, header);
+                       if (ret) {
+                               DRM_ERROR("r300_scratch failed\n");
+                               goto cleanup;
+                       }
+                       break;
+
+               case R300_CMD_R500FP:
+                       if ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV515) {
+                               DRM_ERROR("Calling r500 command on r300 card\n");
+                               ret = -EINVAL;
+                               goto cleanup;
+                       }
+                       DRM_DEBUG("R300_CMD_R500FP\n");
+                       ret = r300_emit_r500fp(dev_priv, cmdbuf, header);
+                       if (ret) {
+                               DRM_ERROR("r300_emit_r500fp failed\n");
+                               goto cleanup;
+                       }
+                       break;
+               default:
+                       DRM_ERROR("bad cmd_type %i at %p\n",
+                                 header.header.cmd_type,
+                                 cmdbuf->buf - sizeof(header));
+                       ret = -EINVAL;
+                       goto cleanup;
+               }
+       }
+
+       DRM_DEBUG("END\n");
+
+      cleanup:
+       r300_pacify(dev_priv);
+
+       /* We emit the vertex buffer age here, outside the pacifier "brackets"
+        * for two reasons:
+        *  (1) This may coalesce multiple age emissions into a single one and
+        *  (2) more importantly, some chips lock up hard when scratch registers
+        *      are written inside the pacifier bracket.
+        */
+       if (emit_dispatch_age) {
+               RING_LOCALS;
+
+               /* Emit the vertex buffer age */
+               BEGIN_RING(2);
+               RADEON_DISPATCH_AGE(dev_priv->sarea_priv->last_dispatch);
+               ADVANCE_RING();
+       }
+
+       COMMIT_RING();
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/radeon/r300_reg.h b/drivers/gpu/drm/radeon/r300_reg.h
new file mode 100644 (file)
index 0000000..a6802f2
--- /dev/null
@@ -0,0 +1,1772 @@
+/**************************************************************************
+
+Copyright (C) 2004-2005 Nicolai Haehnle et al.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, and/or sell copies of the Software, and to permit persons to whom
+the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _R300_REG_H
+#define _R300_REG_H
+
+#define R300_MC_INIT_MISC_LAT_TIMER    0x180
+#      define R300_MC_MISC__MC_CPR_INIT_LAT_SHIFT      0
+#      define R300_MC_MISC__MC_VF_INIT_LAT_SHIFT       4
+#      define R300_MC_MISC__MC_DISP0R_INIT_LAT_SHIFT   8
+#      define R300_MC_MISC__MC_DISP1R_INIT_LAT_SHIFT   12
+#      define R300_MC_MISC__MC_FIXED_INIT_LAT_SHIFT    16
+#      define R300_MC_MISC__MC_E2R_INIT_LAT_SHIFT      20
+#      define R300_MC_MISC__MC_SAME_PAGE_PRIO_SHIFT    24
+#      define R300_MC_MISC__MC_GLOBW_INIT_LAT_SHIFT    28
+
+#define R300_MC_INIT_GFX_LAT_TIMER     0x154
+#      define R300_MC_MISC__MC_G3D0R_INIT_LAT_SHIFT    0
+#      define R300_MC_MISC__MC_G3D1R_INIT_LAT_SHIFT    4
+#      define R300_MC_MISC__MC_G3D2R_INIT_LAT_SHIFT    8
+#      define R300_MC_MISC__MC_G3D3R_INIT_LAT_SHIFT    12
+#      define R300_MC_MISC__MC_TX0R_INIT_LAT_SHIFT     16
+#      define R300_MC_MISC__MC_TX1R_INIT_LAT_SHIFT     20
+#      define R300_MC_MISC__MC_GLOBR_INIT_LAT_SHIFT    24
+#      define R300_MC_MISC__MC_GLOBW_FULL_LAT_SHIFT    28
+
+/*
+ * This file contains registers and constants for the R300. They have been
+ * found mostly by examining command buffers captured using glxtest, as well
+ * as by extrapolating some known registers and constants from the R200.
+ * I am fairly certain that they are correct unless stated otherwise
+ * in comments.
+ */
+
+#define R300_SE_VPORT_XSCALE                0x1D98
+#define R300_SE_VPORT_XOFFSET               0x1D9C
+#define R300_SE_VPORT_YSCALE                0x1DA0
+#define R300_SE_VPORT_YOFFSET               0x1DA4
+#define R300_SE_VPORT_ZSCALE                0x1DA8
+#define R300_SE_VPORT_ZOFFSET               0x1DAC
+
+
+/*
+ * Vertex Array Processing (VAP) Control
+ * Stolen from r200 code from Christoph Brill (It's a guess!)
+ */
+#define R300_VAP_CNTL  0x2080
+
+/* This register is written directly and also starts data section
+ * in many 3d CP_PACKET3's
+ */
+#define R300_VAP_VF_CNTL       0x2084
+#      define  R300_VAP_VF_CNTL__PRIM_TYPE__SHIFT              0
+#      define  R300_VAP_VF_CNTL__PRIM_NONE                     (0<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_POINTS                   (1<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_LINES                    (2<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_LINE_STRIP               (3<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLES                (4<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN             (5<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP           (6<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_LINE_LOOP                (12<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_QUADS                    (13<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_QUAD_STRIP               (14<<0)
+#      define  R300_VAP_VF_CNTL__PRIM_POLYGON                  (15<<0)
+
+#      define  R300_VAP_VF_CNTL__PRIM_WALK__SHIFT              4
+       /* State based - direct writes to registers trigger vertex
+           generation */
+#      define  R300_VAP_VF_CNTL__PRIM_WALK_STATE_BASED         (0<<4)
+#      define  R300_VAP_VF_CNTL__PRIM_WALK_INDICES             (1<<4)
+#      define  R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST         (2<<4)
+#      define  R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED     (3<<4)
+
+       /* I don't think I saw these three used.. */
+#      define  R300_VAP_VF_CNTL__COLOR_ORDER__SHIFT            6
+#      define  R300_VAP_VF_CNTL__TCL_OUTPUT_CTL_ENA__SHIFT     9
+#      define  R300_VAP_VF_CNTL__PROG_STREAM_ENA__SHIFT        10
+
+       /* index size - when not set the indices are assumed to be 16 bit */
+#      define  R300_VAP_VF_CNTL__INDEX_SIZE_32bit              (1<<11)
+       /* number of vertices */
+#      define  R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT           16
+
+/* BEGIN: Wild guesses */
+#define R300_VAP_OUTPUT_VTX_FMT_0           0x2090
+#       define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT     (1<<0)
+#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT   (1<<1)
+#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT (1<<2)  /* GUESS */
+#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT (1<<3)  /* GUESS */
+#       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT (1<<4)  /* GUESS */
+#       define R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT (1<<16) /* GUESS */
+
+#define R300_VAP_OUTPUT_VTX_FMT_1           0x2094
+       /* each of the following is 3 bits wide, specifies number
+          of components */
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT 0
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT 3
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT 6
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT 9
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT 12
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT 15
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT 18
+#       define R300_VAP_OUTPUT_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT 21
+/* END: Wild guesses */
+
+#define R300_SE_VTE_CNTL                  0x20b0
+#      define     R300_VPORT_X_SCALE_ENA                0x00000001
+#      define     R300_VPORT_X_OFFSET_ENA               0x00000002
+#      define     R300_VPORT_Y_SCALE_ENA                0x00000004
+#      define     R300_VPORT_Y_OFFSET_ENA               0x00000008
+#      define     R300_VPORT_Z_SCALE_ENA                0x00000010
+#      define     R300_VPORT_Z_OFFSET_ENA               0x00000020
+#      define     R300_VTX_XY_FMT                       0x00000100
+#      define     R300_VTX_Z_FMT                        0x00000200
+#      define     R300_VTX_W0_FMT                       0x00000400
+#      define     R300_VTX_W0_NORMALIZE                 0x00000800
+#      define     R300_VTX_ST_DENORMALIZED              0x00001000
+
+/* BEGIN: Vertex data assembly - lots of uncertainties */
+
+/* gap */
+
+#define R300_VAP_CNTL_STATUS              0x2140
+#      define R300_VC_NO_SWAP                  (0 << 0)
+#      define R300_VC_16BIT_SWAP               (1 << 0)
+#      define R300_VC_32BIT_SWAP               (2 << 0)
+#      define R300_VAP_TCL_BYPASS              (1 << 8)
+
+/* gap */
+
+/* Where do we get our vertex data?
+ *
+ * Vertex data either comes either from immediate mode registers or from
+ * vertex arrays.
+ * There appears to be no mixed mode (though we can force the pitch of
+ * vertex arrays to 0, effectively reusing the same element over and over
+ * again).
+ *
+ * Immediate mode is controlled by the INPUT_CNTL registers. I am not sure
+ * if these registers influence vertex array processing.
+ *
+ * Vertex arrays are controlled via the 3D_LOAD_VBPNTR packet3.
+ *
+ * In both cases, vertex attributes are then passed through INPUT_ROUTE.
+ *
+ * Beginning with INPUT_ROUTE_0_0 is a list of WORDs that route vertex data
+ * into the vertex processor's input registers.
+ * The first word routes the first input, the second word the second, etc.
+ * The corresponding input is routed into the register with the given index.
+ * The list is ended by a word with INPUT_ROUTE_END set.
+ *
+ * Always set COMPONENTS_4 in immediate mode.
+ */
+
+#define R300_VAP_INPUT_ROUTE_0_0            0x2150
+#       define R300_INPUT_ROUTE_COMPONENTS_1     (0 << 0)
+#       define R300_INPUT_ROUTE_COMPONENTS_2     (1 << 0)
+#       define R300_INPUT_ROUTE_COMPONENTS_3     (2 << 0)
+#       define R300_INPUT_ROUTE_COMPONENTS_4     (3 << 0)
+#       define R300_INPUT_ROUTE_COMPONENTS_RGBA  (4 << 0) /* GUESS */
+#       define R300_VAP_INPUT_ROUTE_IDX_SHIFT    8
+#       define R300_VAP_INPUT_ROUTE_IDX_MASK     (31 << 8) /* GUESS */
+#       define R300_VAP_INPUT_ROUTE_END          (1 << 13)
+#       define R300_INPUT_ROUTE_IMMEDIATE_MODE   (0 << 14) /* GUESS */
+#       define R300_INPUT_ROUTE_FLOAT            (1 << 14) /* GUESS */
+#       define R300_INPUT_ROUTE_UNSIGNED_BYTE    (2 << 14) /* GUESS */
+#       define R300_INPUT_ROUTE_FLOAT_COLOR      (3 << 14) /* GUESS */
+#define R300_VAP_INPUT_ROUTE_0_1            0x2154
+#define R300_VAP_INPUT_ROUTE_0_2            0x2158
+#define R300_VAP_INPUT_ROUTE_0_3            0x215C
+#define R300_VAP_INPUT_ROUTE_0_4            0x2160
+#define R300_VAP_INPUT_ROUTE_0_5            0x2164
+#define R300_VAP_INPUT_ROUTE_0_6            0x2168
+#define R300_VAP_INPUT_ROUTE_0_7            0x216C
+
+/* gap */
+
+/* Notes:
+ *  - always set up to produce at least two attributes:
+ *    if vertex program uses only position, fglrx will set normal, too
+ *  - INPUT_CNTL_0_COLOR and INPUT_CNTL_COLOR bits are always equal.
+ */
+#define R300_VAP_INPUT_CNTL_0               0x2180
+#       define R300_INPUT_CNTL_0_COLOR           0x00000001
+#define R300_VAP_INPUT_CNTL_1               0x2184
+#       define R300_INPUT_CNTL_POS               0x00000001
+#       define R300_INPUT_CNTL_NORMAL            0x00000002
+#       define R300_INPUT_CNTL_COLOR             0x00000004
+#       define R300_INPUT_CNTL_TC0               0x00000400
+#       define R300_INPUT_CNTL_TC1               0x00000800
+#       define R300_INPUT_CNTL_TC2               0x00001000 /* GUESS */
+#       define R300_INPUT_CNTL_TC3               0x00002000 /* GUESS */
+#       define R300_INPUT_CNTL_TC4               0x00004000 /* GUESS */
+#       define R300_INPUT_CNTL_TC5               0x00008000 /* GUESS */
+#       define R300_INPUT_CNTL_TC6               0x00010000 /* GUESS */
+#       define R300_INPUT_CNTL_TC7               0x00020000 /* GUESS */
+
+/* gap */
+
+/* Words parallel to INPUT_ROUTE_0; All words that are active in INPUT_ROUTE_0
+ * are set to a swizzling bit pattern, other words are 0.
+ *
+ * In immediate mode, the pattern is always set to xyzw. In vertex array
+ * mode, the swizzling pattern is e.g. used to set zw components in texture
+ * coordinates with only tweo components.
+ */
+#define R300_VAP_INPUT_ROUTE_1_0            0x21E0
+#       define R300_INPUT_ROUTE_SELECT_X    0
+#       define R300_INPUT_ROUTE_SELECT_Y    1
+#       define R300_INPUT_ROUTE_SELECT_Z    2
+#       define R300_INPUT_ROUTE_SELECT_W    3
+#       define R300_INPUT_ROUTE_SELECT_ZERO 4
+#       define R300_INPUT_ROUTE_SELECT_ONE  5
+#       define R300_INPUT_ROUTE_SELECT_MASK 7
+#       define R300_INPUT_ROUTE_X_SHIFT     0
+#       define R300_INPUT_ROUTE_Y_SHIFT     3
+#       define R300_INPUT_ROUTE_Z_SHIFT     6
+#       define R300_INPUT_ROUTE_W_SHIFT     9
+#       define R300_INPUT_ROUTE_ENABLE      (15 << 12)
+#define R300_VAP_INPUT_ROUTE_1_1            0x21E4
+#define R300_VAP_INPUT_ROUTE_1_2            0x21E8
+#define R300_VAP_INPUT_ROUTE_1_3            0x21EC
+#define R300_VAP_INPUT_ROUTE_1_4            0x21F0
+#define R300_VAP_INPUT_ROUTE_1_5            0x21F4
+#define R300_VAP_INPUT_ROUTE_1_6            0x21F8
+#define R300_VAP_INPUT_ROUTE_1_7            0x21FC
+
+/* END: Vertex data assembly */
+
+/* gap */
+
+/* BEGIN: Upload vertex program and data */
+
+/*
+ * The programmable vertex shader unit has a memory bank of unknown size
+ * that can be written to in 16 byte units by writing the address into
+ * UPLOAD_ADDRESS, followed by data in UPLOAD_DATA (multiples of 4 DWORDs).
+ *
+ * Pointers into the memory bank are always in multiples of 16 bytes.
+ *
+ * The memory bank is divided into areas with fixed meaning.
+ *
+ * Starting at address UPLOAD_PROGRAM: Vertex program instructions.
+ * Native limits reported by drivers from ATI suggest size 256 (i.e. 4KB),
+ * whereas the difference between known addresses suggests size 512.
+ *
+ * Starting at address UPLOAD_PARAMETERS: Vertex program parameters.
+ * Native reported limits and the VPI layout suggest size 256, whereas
+ * difference between known addresses suggests size 512.
+ *
+ * At address UPLOAD_POINTSIZE is a vector (0, 0, ps, 0), where ps is the
+ * floating point pointsize. The exact purpose of this state is uncertain,
+ * as there is also the R300_RE_POINTSIZE register.
+ *
+ * Multiple vertex programs and parameter sets can be loaded at once,
+ * which could explain the size discrepancy.
+ */
+#define R300_VAP_PVS_UPLOAD_ADDRESS         0x2200
+#       define R300_PVS_UPLOAD_PROGRAM           0x00000000
+#       define R300_PVS_UPLOAD_PARAMETERS        0x00000200
+#       define R300_PVS_UPLOAD_POINTSIZE         0x00000406
+
+/* gap */
+
+#define R300_VAP_PVS_UPLOAD_DATA            0x2208
+
+/* END: Upload vertex program and data */
+
+/* gap */
+
+/* I do not know the purpose of this register. However, I do know that
+ * it is set to 221C_CLEAR for clear operations and to 221C_NORMAL
+ * for normal rendering.
+ */
+#define R300_VAP_UNKNOWN_221C               0x221C
+#       define R300_221C_NORMAL                  0x00000000
+#       define R300_221C_CLEAR                   0x0001C000
+
+/* These seem to be per-pixel and per-vertex X and Y clipping planes. The first
+ * plane is per-pixel and the second plane is per-vertex.
+ *
+ * This was determined by experimentation alone but I believe it is correct.
+ *
+ * These registers are called X_QUAD0_1_FL to X_QUAD0_4_FL by glxtest.
+ */
+#define R300_VAP_CLIP_X_0                   0x2220
+#define R300_VAP_CLIP_X_1                   0x2224
+#define R300_VAP_CLIP_Y_0                   0x2228
+#define R300_VAP_CLIP_Y_1                   0x2230
+
+/* gap */
+
+/* Sometimes, END_OF_PKT and 0x2284=0 are the only commands sent between
+ * rendering commands and overwriting vertex program parameters.
+ * Therefore, I suspect writing zero to 0x2284 synchronizes the engine and
+ * avoids bugs caused by still running shaders reading bad data from memory.
+ */
+#define R300_VAP_PVS_WAITIDLE               0x2284 /* GUESS */
+
+/* Absolutely no clue what this register is about. */
+#define R300_VAP_UNKNOWN_2288               0x2288
+#       define R300_2288_R300                    0x00750000 /* -- nh */
+#       define R300_2288_RV350                   0x0000FFFF /* -- Vladimir */
+
+/* gap */
+
+/* Addresses are relative to the vertex program instruction area of the
+ * memory bank. PROGRAM_END points to the last instruction of the active
+ * program
+ *
+ * The meaning of the two UNKNOWN fields is obviously not known. However,
+ * experiments so far have shown that both *must* point to an instruction
+ * inside the vertex program, otherwise the GPU locks up.
+ *
+ * fglrx usually sets CNTL_3_UNKNOWN to the end of the program and
+ * R300_PVS_CNTL_1_POS_END_SHIFT points to instruction where last write to
+ * position takes place.
+ *
+ * Most likely this is used to ignore rest of the program in cases
+ * where group of verts arent visible. For some reason this "section"
+ * is sometimes accepted other instruction that have no relationship with
+ * position calculations.
+ */
+#define R300_VAP_PVS_CNTL_1                 0x22D0
+#       define R300_PVS_CNTL_1_PROGRAM_START_SHIFT   0
+#       define R300_PVS_CNTL_1_POS_END_SHIFT         10
+#       define R300_PVS_CNTL_1_PROGRAM_END_SHIFT     20
+/* Addresses are relative the the vertex program parameters area. */
+#define R300_VAP_PVS_CNTL_2                 0x22D4
+#       define R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT 0
+#       define R300_PVS_CNTL_2_PARAM_COUNT_SHIFT  16
+#define R300_VAP_PVS_CNTL_3               0x22D8
+#       define R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT 10
+#       define R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT 0
+
+/* The entire range from 0x2300 to 0x2AC inclusive seems to be used for
+ * immediate vertices
+ */
+#define R300_VAP_VTX_COLOR_R                0x2464
+#define R300_VAP_VTX_COLOR_G                0x2468
+#define R300_VAP_VTX_COLOR_B                0x246C
+#define R300_VAP_VTX_POS_0_X_1              0x2490 /* used for glVertex2*() */
+#define R300_VAP_VTX_POS_0_Y_1              0x2494
+#define R300_VAP_VTX_COLOR_PKD              0x249C /* RGBA */
+#define R300_VAP_VTX_POS_0_X_2              0x24A0 /* used for glVertex3*() */
+#define R300_VAP_VTX_POS_0_Y_2              0x24A4
+#define R300_VAP_VTX_POS_0_Z_2              0x24A8
+/* write 0 to indicate end of packet? */
+#define R300_VAP_VTX_END_OF_PKT             0x24AC
+
+/* gap */
+
+/* These are values from r300_reg/r300_reg.h - they are known to be correct
+ * and are here so we can use one register file instead of several
+ * - Vladimir
+ */
+#define R300_GB_VAP_RASTER_VTX_FMT_0   0x4000
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__POS_PRESENT        (1<<0)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_0_PRESENT    (1<<1)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_1_PRESENT    (1<<2)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_2_PRESENT    (1<<3)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_3_PRESENT    (1<<4)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__COLOR_SPACE        (0xf<<5)
+#      define R300_GB_VAP_RASTER_VTX_FMT_0__PT_SIZE_PRESENT    (0x1<<16)
+
+#define R300_GB_VAP_RASTER_VTX_FMT_1   0x4004
+       /* each of the following is 3 bits wide, specifies number
+          of components */
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_0_COMP_CNT_SHIFT       0
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_1_COMP_CNT_SHIFT       3
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_2_COMP_CNT_SHIFT       6
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_3_COMP_CNT_SHIFT       9
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_4_COMP_CNT_SHIFT       12
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_5_COMP_CNT_SHIFT       15
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_6_COMP_CNT_SHIFT       18
+#      define R300_GB_VAP_RASTER_VTX_FMT_1__TEX_7_COMP_CNT_SHIFT       21
+
+/* UNK30 seems to enables point to quad transformation on textures
+ * (or something closely related to that).
+ * This bit is rather fatal at the time being due to lackings at pixel
+ * shader side
+ */
+#define R300_GB_ENABLE 0x4008
+#      define R300_GB_POINT_STUFF_ENABLE       (1<<0)
+#      define R300_GB_LINE_STUFF_ENABLE        (1<<1)
+#      define R300_GB_TRIANGLE_STUFF_ENABLE    (1<<2)
+#      define R300_GB_STENCIL_AUTO_ENABLE      (1<<4)
+#      define R300_GB_UNK31                    (1<<31)
+       /* each of the following is 2 bits wide */
+#define R300_GB_TEX_REPLICATE  0
+#define R300_GB_TEX_ST         1
+#define R300_GB_TEX_STR                2
+#      define R300_GB_TEX0_SOURCE_SHIFT        16
+#      define R300_GB_TEX1_SOURCE_SHIFT        18
+#      define R300_GB_TEX2_SOURCE_SHIFT        20
+#      define R300_GB_TEX3_SOURCE_SHIFT        22
+#      define R300_GB_TEX4_SOURCE_SHIFT        24
+#      define R300_GB_TEX5_SOURCE_SHIFT        26
+#      define R300_GB_TEX6_SOURCE_SHIFT        28
+#      define R300_GB_TEX7_SOURCE_SHIFT        30
+
+/* MSPOS - positions for multisample antialiasing (?) */
+#define R300_GB_MSPOS0 0x4010
+       /* shifts - each of the fields is 4 bits */
+#      define R300_GB_MSPOS0__MS_X0_SHIFT      0
+#      define R300_GB_MSPOS0__MS_Y0_SHIFT      4
+#      define R300_GB_MSPOS0__MS_X1_SHIFT      8
+#      define R300_GB_MSPOS0__MS_Y1_SHIFT      12
+#      define R300_GB_MSPOS0__MS_X2_SHIFT      16
+#      define R300_GB_MSPOS0__MS_Y2_SHIFT      20
+#      define R300_GB_MSPOS0__MSBD0_Y          24
+#      define R300_GB_MSPOS0__MSBD0_X          28
+
+#define R300_GB_MSPOS1 0x4014
+#      define R300_GB_MSPOS1__MS_X3_SHIFT      0
+#      define R300_GB_MSPOS1__MS_Y3_SHIFT      4
+#      define R300_GB_MSPOS1__MS_X4_SHIFT      8
+#      define R300_GB_MSPOS1__MS_Y4_SHIFT      12
+#      define R300_GB_MSPOS1__MS_X5_SHIFT      16
+#      define R300_GB_MSPOS1__MS_Y5_SHIFT      20
+#      define R300_GB_MSPOS1__MSBD1            24
+
+
+#define R300_GB_TILE_CONFIG    0x4018
+#      define R300_GB_TILE_ENABLE      (1<<0)
+#      define R300_GB_TILE_PIPE_COUNT_RV300    0
+#      define R300_GB_TILE_PIPE_COUNT_R300     (3<<1)
+#      define R300_GB_TILE_PIPE_COUNT_R420     (7<<1)
+#      define R300_GB_TILE_PIPE_COUNT_RV410    (3<<1)
+#      define R300_GB_TILE_SIZE_8              0
+#      define R300_GB_TILE_SIZE_16             (1<<4)
+#      define R300_GB_TILE_SIZE_32             (2<<4)
+#      define R300_GB_SUPER_SIZE_1             (0<<6)
+#      define R300_GB_SUPER_SIZE_2             (1<<6)
+#      define R300_GB_SUPER_SIZE_4             (2<<6)
+#      define R300_GB_SUPER_SIZE_8             (3<<6)
+#      define R300_GB_SUPER_SIZE_16            (4<<6)
+#      define R300_GB_SUPER_SIZE_32            (5<<6)
+#      define R300_GB_SUPER_SIZE_64            (6<<6)
+#      define R300_GB_SUPER_SIZE_128           (7<<6)
+#      define R300_GB_SUPER_X_SHIFT            9       /* 3 bits wide */
+#      define R300_GB_SUPER_Y_SHIFT            12      /* 3 bits wide */
+#      define R300_GB_SUPER_TILE_A             0
+#      define R300_GB_SUPER_TILE_B             (1<<15)
+#      define R300_GB_SUBPIXEL_1_12            0
+#      define R300_GB_SUBPIXEL_1_16            (1<<16)
+
+#define R300_GB_FIFO_SIZE      0x4024
+       /* each of the following is 2 bits wide */
+#define R300_GB_FIFO_SIZE_32   0
+#define R300_GB_FIFO_SIZE_64   1
+#define R300_GB_FIFO_SIZE_128  2
+#define R300_GB_FIFO_SIZE_256  3
+#      define R300_SC_IFIFO_SIZE_SHIFT 0
+#      define R300_SC_TZFIFO_SIZE_SHIFT        2
+#      define R300_SC_BFIFO_SIZE_SHIFT 4
+
+#      define R300_US_OFIFO_SIZE_SHIFT 12
+#      define R300_US_WFIFO_SIZE_SHIFT 14
+       /* the following use the same constants as above, but meaning is
+          is times 2 (i.e. instead of 32 words it means 64 */
+#      define R300_RS_TFIFO_SIZE_SHIFT 6
+#      define R300_RS_CFIFO_SIZE_SHIFT 8
+#      define R300_US_RAM_SIZE_SHIFT           10
+       /* watermarks, 3 bits wide */
+#      define R300_RS_HIGHWATER_COL_SHIFT      16
+#      define R300_RS_HIGHWATER_TEX_SHIFT      19
+#      define R300_OFIFO_HIGHWATER_SHIFT       22      /* two bits only */
+#      define R300_CUBE_FIFO_HIGHWATER_COL_SHIFT       24
+
+#define R300_GB_SELECT 0x401C
+#      define R300_GB_FOG_SELECT_C0A           0
+#      define R300_GB_FOG_SELECT_C1A           1
+#      define R300_GB_FOG_SELECT_C2A           2
+#      define R300_GB_FOG_SELECT_C3A           3
+#      define R300_GB_FOG_SELECT_1_1_W 4
+#      define R300_GB_FOG_SELECT_Z             5
+#      define R300_GB_DEPTH_SELECT_Z           0
+#      define R300_GB_DEPTH_SELECT_1_1_W       (1<<3)
+#      define R300_GB_W_SELECT_1_W             0
+#      define R300_GB_W_SELECT_1               (1<<4)
+
+#define R300_GB_AA_CONFIG              0x4020
+#      define R300_AA_DISABLE                  0x00
+#      define R300_AA_ENABLE                   0x01
+#      define R300_AA_SUBSAMPLES_2             0
+#      define R300_AA_SUBSAMPLES_3             (1<<1)
+#      define R300_AA_SUBSAMPLES_4             (2<<1)
+#      define R300_AA_SUBSAMPLES_6             (3<<1)
+
+/* gap */
+
+/* Zero to flush caches. */
+#define R300_TX_CNTL                        0x4100
+#define R300_TX_FLUSH                       0x0
+
+/* The upper enable bits are guessed, based on fglrx reported limits. */
+#define R300_TX_ENABLE                      0x4104
+#       define R300_TX_ENABLE_0                  (1 << 0)
+#       define R300_TX_ENABLE_1                  (1 << 1)
+#       define R300_TX_ENABLE_2                  (1 << 2)
+#       define R300_TX_ENABLE_3                  (1 << 3)
+#       define R300_TX_ENABLE_4                  (1 << 4)
+#       define R300_TX_ENABLE_5                  (1 << 5)
+#       define R300_TX_ENABLE_6                  (1 << 6)
+#       define R300_TX_ENABLE_7                  (1 << 7)
+#       define R300_TX_ENABLE_8                  (1 << 8)
+#       define R300_TX_ENABLE_9                  (1 << 9)
+#       define R300_TX_ENABLE_10                 (1 << 10)
+#       define R300_TX_ENABLE_11                 (1 << 11)
+#       define R300_TX_ENABLE_12                 (1 << 12)
+#       define R300_TX_ENABLE_13                 (1 << 13)
+#       define R300_TX_ENABLE_14                 (1 << 14)
+#       define R300_TX_ENABLE_15                 (1 << 15)
+
+/* The pointsize is given in multiples of 6. The pointsize can be
+ * enormous: Clear() renders a single point that fills the entire
+ * framebuffer.
+ */
+#define R300_RE_POINTSIZE                   0x421C
+#       define R300_POINTSIZE_Y_SHIFT            0
+#       define R300_POINTSIZE_Y_MASK             (0xFFFF << 0) /* GUESS */
+#       define R300_POINTSIZE_X_SHIFT            16
+#       define R300_POINTSIZE_X_MASK             (0xFFFF << 16) /* GUESS */
+#       define R300_POINTSIZE_MAX             (R300_POINTSIZE_Y_MASK / 6)
+
+/* The line width is given in multiples of 6.
+ * In default mode lines are classified as vertical lines.
+ * HO: horizontal
+ * VE: vertical or horizontal
+ * HO & VE: no classification
+ */
+#define R300_RE_LINE_CNT                      0x4234
+#       define R300_LINESIZE_SHIFT            0
+#       define R300_LINESIZE_MASK             (0xFFFF << 0) /* GUESS */
+#       define R300_LINESIZE_MAX             (R300_LINESIZE_MASK / 6)
+#       define R300_LINE_CNT_HO               (1 << 16)
+#       define R300_LINE_CNT_VE               (1 << 17)
+
+/* Some sort of scale or clamp value for texcoordless textures. */
+#define R300_RE_UNK4238                       0x4238
+
+/* Something shade related */
+#define R300_RE_SHADE                         0x4274
+
+#define R300_RE_SHADE_MODEL                   0x4278
+#      define R300_RE_SHADE_MODEL_SMOOTH     0x3aaaa
+#      define R300_RE_SHADE_MODEL_FLAT       0x39595
+
+/* Dangerous */
+#define R300_RE_POLYGON_MODE                  0x4288
+#      define R300_PM_ENABLED                (1 << 0)
+#      define R300_PM_FRONT_POINT            (0 << 0)
+#      define R300_PM_BACK_POINT             (0 << 0)
+#      define R300_PM_FRONT_LINE             (1 << 4)
+#      define R300_PM_FRONT_FILL             (1 << 5)
+#      define R300_PM_BACK_LINE              (1 << 7)
+#      define R300_PM_BACK_FILL              (1 << 8)
+
+/* Fog parameters */
+#define R300_RE_FOG_SCALE                     0x4294
+#define R300_RE_FOG_START                     0x4298
+
+/* Not sure why there are duplicate of factor and constant values.
+ * My best guess so far is that there are separate zbiases for test and write.
+ * Ordering might be wrong.
+ * Some of the tests indicate that fgl has a fallback implementation of zbias
+ * via pixel shaders.
+ */
+#define R300_RE_ZBIAS_CNTL                    0x42A0 /* GUESS */
+#define R300_RE_ZBIAS_T_FACTOR                0x42A4
+#define R300_RE_ZBIAS_T_CONSTANT              0x42A8
+#define R300_RE_ZBIAS_W_FACTOR                0x42AC
+#define R300_RE_ZBIAS_W_CONSTANT              0x42B0
+
+/* This register needs to be set to (1<<1) for RV350 to correctly
+ * perform depth test (see --vb-triangles in r300_demo)
+ * Don't know about other chips. - Vladimir
+ * This is set to 3 when GL_POLYGON_OFFSET_FILL is on.
+ * My guess is that there are two bits for each zbias primitive
+ * (FILL, LINE, POINT).
+ *  One to enable depth test and one for depth write.
+ * Yet this doesnt explain why depth writes work ...
+ */
+#define R300_RE_OCCLUSION_CNTL             0x42B4
+#      define R300_OCCLUSION_ON                (1<<1)
+
+#define R300_RE_CULL_CNTL                   0x42B8
+#       define R300_CULL_FRONT                   (1 << 0)
+#       define R300_CULL_BACK                    (1 << 1)
+#       define R300_FRONT_FACE_CCW               (0 << 2)
+#       define R300_FRONT_FACE_CW                (1 << 2)
+
+
+/* BEGIN: Rasterization / Interpolators - many guesses */
+
+/* 0_UNKNOWN_18 has always been set except for clear operations.
+ * TC_CNT is the number of incoming texture coordinate sets (i.e. it depends
+ * on the vertex program, *not* the fragment program)
+ */
+#define R300_RS_CNTL_0                      0x4300
+#       define R300_RS_CNTL_TC_CNT_SHIFT         2
+#       define R300_RS_CNTL_TC_CNT_MASK          (7 << 2)
+       /* number of color interpolators used */
+#      define R300_RS_CNTL_CI_CNT_SHIFT         7
+#       define R300_RS_CNTL_0_UNKNOWN_18         (1 << 18)
+       /* Guess: RS_CNTL_1 holds the index of the highest used RS_ROUTE_n
+          register. */
+#define R300_RS_CNTL_1                      0x4304
+
+/* gap */
+
+/* Only used for texture coordinates.
+ * Use the source field to route texture coordinate input from the
+ * vertex program to the desired interpolator. Note that the source
+ * field is relative to the outputs the vertex program *actually*
+ * writes. If a vertex program only writes texcoord[1], this will
+ * be source index 0.
+ * Set INTERP_USED on all interpolators that produce data used by
+ * the fragment program. INTERP_USED looks like a swizzling mask,
+ * but I haven't seen it used that way.
+ *
+ * Note: The _UNKNOWN constants are always set in their respective
+ * register. I don't know if this is necessary.
+ */
+#define R300_RS_INTERP_0                    0x4310
+#define R300_RS_INTERP_1                    0x4314
+#       define R300_RS_INTERP_1_UNKNOWN          0x40
+#define R300_RS_INTERP_2                    0x4318
+#       define R300_RS_INTERP_2_UNKNOWN          0x80
+#define R300_RS_INTERP_3                    0x431C
+#       define R300_RS_INTERP_3_UNKNOWN          0xC0
+#define R300_RS_INTERP_4                    0x4320
+#define R300_RS_INTERP_5                    0x4324
+#define R300_RS_INTERP_6                    0x4328
+#define R300_RS_INTERP_7                    0x432C
+#       define R300_RS_INTERP_SRC_SHIFT          2
+#       define R300_RS_INTERP_SRC_MASK           (7 << 2)
+#       define R300_RS_INTERP_USED               0x00D10000
+
+/* These DWORDs control how vertex data is routed into fragment program
+ * registers, after interpolators.
+ */
+#define R300_RS_ROUTE_0                     0x4330
+#define R300_RS_ROUTE_1                     0x4334
+#define R300_RS_ROUTE_2                     0x4338
+#define R300_RS_ROUTE_3                     0x433C /* GUESS */
+#define R300_RS_ROUTE_4                     0x4340 /* GUESS */
+#define R300_RS_ROUTE_5                     0x4344 /* GUESS */
+#define R300_RS_ROUTE_6                     0x4348 /* GUESS */
+#define R300_RS_ROUTE_7                     0x434C /* GUESS */
+#       define R300_RS_ROUTE_SOURCE_INTERP_0     0
+#       define R300_RS_ROUTE_SOURCE_INTERP_1     1
+#       define R300_RS_ROUTE_SOURCE_INTERP_2     2
+#       define R300_RS_ROUTE_SOURCE_INTERP_3     3
+#       define R300_RS_ROUTE_SOURCE_INTERP_4     4
+#       define R300_RS_ROUTE_SOURCE_INTERP_5     5 /* GUESS */
+#       define R300_RS_ROUTE_SOURCE_INTERP_6     6 /* GUESS */
+#       define R300_RS_ROUTE_SOURCE_INTERP_7     7 /* GUESS */
+#       define R300_RS_ROUTE_ENABLE              (1 << 3) /* GUESS */
+#       define R300_RS_ROUTE_DEST_SHIFT          6
+#       define R300_RS_ROUTE_DEST_MASK           (31 << 6) /* GUESS */
+
+/* Special handling for color: When the fragment program uses color,
+ * the ROUTE_0_COLOR bit is set and ROUTE_0_COLOR_DEST contains the
+ * color register index.
+ *
+ * Apperently you may set the R300_RS_ROUTE_0_COLOR bit, but not provide any
+ * R300_RS_ROUTE_0_COLOR_DEST value; this setup is used for clearing the state.
+ * See r300_ioctl.c:r300EmitClearState. I'm not sure if this setup is strictly
+ * correct or not. - Oliver.
+ */
+#       define R300_RS_ROUTE_0_COLOR             (1 << 14)
+#       define R300_RS_ROUTE_0_COLOR_DEST_SHIFT  17
+#       define R300_RS_ROUTE_0_COLOR_DEST_MASK   (31 << 17) /* GUESS */
+/* As above, but for secondary color */
+#              define R300_RS_ROUTE_1_COLOR1            (1 << 14)
+#              define R300_RS_ROUTE_1_COLOR1_DEST_SHIFT 17
+#              define R300_RS_ROUTE_1_COLOR1_DEST_MASK  (31 << 17)
+#              define R300_RS_ROUTE_1_UNKNOWN11         (1 << 11)
+/* END: Rasterization / Interpolators - many guesses */
+
+/* Hierarchical Z Enable */
+#define R300_SC_HYPERZ                   0x43a4
+#      define R300_SC_HYPERZ_DISABLE     (0 << 0)
+#      define R300_SC_HYPERZ_ENABLE      (1 << 0)
+#      define R300_SC_HYPERZ_MIN         (0 << 1)
+#      define R300_SC_HYPERZ_MAX         (1 << 1)
+#      define R300_SC_HYPERZ_ADJ_256     (0 << 2)
+#      define R300_SC_HYPERZ_ADJ_128     (1 << 2)
+#      define R300_SC_HYPERZ_ADJ_64      (2 << 2)
+#      define R300_SC_HYPERZ_ADJ_32      (3 << 2)
+#      define R300_SC_HYPERZ_ADJ_16      (4 << 2)
+#      define R300_SC_HYPERZ_ADJ_8       (5 << 2)
+#      define R300_SC_HYPERZ_ADJ_4       (6 << 2)
+#      define R300_SC_HYPERZ_ADJ_2       (7 << 2)
+#      define R300_SC_HYPERZ_HZ_Z0MIN_NO (0 << 5)
+#      define R300_SC_HYPERZ_HZ_Z0MIN    (1 << 5)
+#      define R300_SC_HYPERZ_HZ_Z0MAX_NO (0 << 6)
+#      define R300_SC_HYPERZ_HZ_Z0MAX    (1 << 6)
+
+#define R300_SC_EDGERULE                 0x43a8
+
+/* BEGIN: Scissors and cliprects */
+
+/* There are four clipping rectangles. Their corner coordinates are inclusive.
+ * Every pixel is assigned a number from 0 and 15 by setting bits 0-3 depending
+ * on whether the pixel is inside cliprects 0-3, respectively. For example,
+ * if a pixel is inside cliprects 0 and 1, but outside 2 and 3, it is assigned
+ * the number 3 (binary 0011).
+ * Iff the bit corresponding to the pixel's number in RE_CLIPRECT_CNTL is set,
+ * the pixel is rasterized.
+ *
+ * In addition to this, there is a scissors rectangle. Only pixels inside the
+ * scissors rectangle are drawn. (coordinates are inclusive)
+ *
+ * For some reason, the top-left corner of the framebuffer is at (1440, 1440)
+ * for the purpose of clipping and scissors.
+ */
+#define R300_RE_CLIPRECT_TL_0               0x43B0
+#define R300_RE_CLIPRECT_BR_0               0x43B4
+#define R300_RE_CLIPRECT_TL_1               0x43B8
+#define R300_RE_CLIPRECT_BR_1               0x43BC
+#define R300_RE_CLIPRECT_TL_2               0x43C0
+#define R300_RE_CLIPRECT_BR_2               0x43C4
+#define R300_RE_CLIPRECT_TL_3               0x43C8
+#define R300_RE_CLIPRECT_BR_3               0x43CC
+#       define R300_CLIPRECT_OFFSET              1440
+#       define R300_CLIPRECT_MASK                0x1FFF
+#       define R300_CLIPRECT_X_SHIFT             0
+#       define R300_CLIPRECT_X_MASK              (0x1FFF << 0)
+#       define R300_CLIPRECT_Y_SHIFT             13
+#       define R300_CLIPRECT_Y_MASK              (0x1FFF << 13)
+#define R300_RE_CLIPRECT_CNTL               0x43D0
+#       define R300_CLIP_OUT                     (1 << 0)
+#       define R300_CLIP_0                       (1 << 1)
+#       define R300_CLIP_1                       (1 << 2)
+#       define R300_CLIP_10                      (1 << 3)
+#       define R300_CLIP_2                       (1 << 4)
+#       define R300_CLIP_20                      (1 << 5)
+#       define R300_CLIP_21                      (1 << 6)
+#       define R300_CLIP_210                     (1 << 7)
+#       define R300_CLIP_3                       (1 << 8)
+#       define R300_CLIP_30                      (1 << 9)
+#       define R300_CLIP_31                      (1 << 10)
+#       define R300_CLIP_310                     (1 << 11)
+#       define R300_CLIP_32                      (1 << 12)
+#       define R300_CLIP_320                     (1 << 13)
+#       define R300_CLIP_321                     (1 << 14)
+#       define R300_CLIP_3210                    (1 << 15)
+
+/* gap */
+
+#define R300_RE_SCISSORS_TL                 0x43E0
+#define R300_RE_SCISSORS_BR                 0x43E4
+#       define R300_SCISSORS_OFFSET              1440
+#       define R300_SCISSORS_X_SHIFT             0
+#       define R300_SCISSORS_X_MASK              (0x1FFF << 0)
+#       define R300_SCISSORS_Y_SHIFT             13
+#       define R300_SCISSORS_Y_MASK              (0x1FFF << 13)
+/* END: Scissors and cliprects */
+
+/* BEGIN: Texture specification */
+
+/*
+ * The texture specification dwords are grouped by meaning and not by texture
+ * unit. This means that e.g. the offset for texture image unit N is found in
+ * register TX_OFFSET_0 + (4*N)
+ */
+#define R300_TX_FILTER_0                    0x4400
+#       define R300_TX_REPEAT                    0
+#       define R300_TX_MIRRORED                  1
+#       define R300_TX_CLAMP                     4
+#       define R300_TX_CLAMP_TO_EDGE             2
+#       define R300_TX_CLAMP_TO_BORDER           6
+#       define R300_TX_WRAP_S_SHIFT              0
+#       define R300_TX_WRAP_S_MASK               (7 << 0)
+#       define R300_TX_WRAP_T_SHIFT              3
+#       define R300_TX_WRAP_T_MASK               (7 << 3)
+#       define R300_TX_WRAP_Q_SHIFT              6
+#       define R300_TX_WRAP_Q_MASK               (7 << 6)
+#       define R300_TX_MAG_FILTER_NEAREST        (1 << 9)
+#       define R300_TX_MAG_FILTER_LINEAR         (2 << 9)
+#       define R300_TX_MAG_FILTER_MASK           (3 << 9)
+#       define R300_TX_MIN_FILTER_NEAREST        (1 << 11)
+#       define R300_TX_MIN_FILTER_LINEAR         (2 << 11)
+#      define R300_TX_MIN_FILTER_NEAREST_MIP_NEAREST       (5  <<  11)
+#      define R300_TX_MIN_FILTER_NEAREST_MIP_LINEAR        (9  <<  11)
+#      define R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST        (6  <<  11)
+#      define R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR         (10 <<  11)
+
+/* NOTE: NEAREST doesnt seem to exist.
+ * Im not seting MAG_FILTER_MASK and (3 << 11) on for all
+ * anisotropy modes because that would void selected mag filter
+ */
+#      define R300_TX_MIN_FILTER_ANISO_NEAREST             (0 << 13)
+#      define R300_TX_MIN_FILTER_ANISO_LINEAR              (0 << 13)
+#      define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_NEAREST (1 << 13)
+#      define R300_TX_MIN_FILTER_ANISO_NEAREST_MIP_LINEAR  (2 << 13)
+#       define R300_TX_MIN_FILTER_MASK   ( (15 << 11) | (3 << 13) )
+#      define R300_TX_MAX_ANISO_1_TO_1  (0 << 21)
+#      define R300_TX_MAX_ANISO_2_TO_1  (2 << 21)
+#      define R300_TX_MAX_ANISO_4_TO_1  (4 << 21)
+#      define R300_TX_MAX_ANISO_8_TO_1  (6 << 21)
+#      define R300_TX_MAX_ANISO_16_TO_1 (8 << 21)
+#      define R300_TX_MAX_ANISO_MASK    (14 << 21)
+
+#define R300_TX_FILTER1_0                      0x4440
+#      define R300_CHROMA_KEY_MODE_DISABLE    0
+#      define R300_CHROMA_KEY_FORCE           1
+#      define R300_CHROMA_KEY_BLEND           2
+#      define R300_MC_ROUND_NORMAL            (0<<2)
+#      define R300_MC_ROUND_MPEG4             (1<<2)
+#      define R300_LOD_BIAS_MASK           0x1fff
+#      define R300_EDGE_ANISO_EDGE_DIAG       (0<<13)
+#      define R300_EDGE_ANISO_EDGE_ONLY       (1<<13)
+#      define R300_MC_COORD_TRUNCATE_DISABLE  (0<<14)
+#      define R300_MC_COORD_TRUNCATE_MPEG     (1<<14)
+#      define R300_TX_TRI_PERF_0_8            (0<<15)
+#      define R300_TX_TRI_PERF_1_8            (1<<15)
+#      define R300_TX_TRI_PERF_1_4            (2<<15)
+#      define R300_TX_TRI_PERF_3_8            (3<<15)
+#      define R300_ANISO_THRESHOLD_MASK       (7<<17)
+
+#define R300_TX_SIZE_0                      0x4480
+#       define R300_TX_WIDTHMASK_SHIFT           0
+#       define R300_TX_WIDTHMASK_MASK            (2047 << 0)
+#       define R300_TX_HEIGHTMASK_SHIFT          11
+#       define R300_TX_HEIGHTMASK_MASK           (2047 << 11)
+#       define R300_TX_UNK23                     (1 << 23)
+#       define R300_TX_MAX_MIP_LEVEL_SHIFT       26
+#       define R300_TX_MAX_MIP_LEVEL_MASK        (0xf << 26)
+#       define R300_TX_SIZE_PROJECTED            (1<<30)
+#       define R300_TX_SIZE_TXPITCH_EN           (1<<31)
+#define R300_TX_FORMAT_0                    0x44C0
+       /* The interpretation of the format word by Wladimir van der Laan */
+       /* The X, Y, Z and W refer to the layout of the components.
+          They are given meanings as R, G, B and Alpha by the swizzle
+          specification */
+#      define R300_TX_FORMAT_X8                    0x0
+#      define R300_TX_FORMAT_X16                   0x1
+#      define R300_TX_FORMAT_Y4X4                  0x2
+#      define R300_TX_FORMAT_Y8X8                  0x3
+#      define R300_TX_FORMAT_Y16X16                0x4
+#      define R300_TX_FORMAT_Z3Y3X2                0x5
+#      define R300_TX_FORMAT_Z5Y6X5                0x6
+#      define R300_TX_FORMAT_Z6Y5X5                0x7
+#      define R300_TX_FORMAT_Z11Y11X10             0x8
+#      define R300_TX_FORMAT_Z10Y11X11             0x9
+#      define R300_TX_FORMAT_W4Z4Y4X4              0xA
+#      define R300_TX_FORMAT_W1Z5Y5X5              0xB
+#      define R300_TX_FORMAT_W8Z8Y8X8              0xC
+#      define R300_TX_FORMAT_W2Z10Y10X10           0xD
+#      define R300_TX_FORMAT_W16Z16Y16X16          0xE
+#      define R300_TX_FORMAT_DXT1                  0xF
+#      define R300_TX_FORMAT_DXT3                  0x10
+#      define R300_TX_FORMAT_DXT5                  0x11
+#      define R300_TX_FORMAT_D3DMFT_CxV8U8         0x12     /* no swizzle */
+#      define R300_TX_FORMAT_A8R8G8B8              0x13     /* no swizzle */
+#      define R300_TX_FORMAT_B8G8_B8G8             0x14     /* no swizzle */
+#      define R300_TX_FORMAT_G8R8_G8B8             0x15     /* no swizzle */
+       /* 0x16 - some 16 bit green format.. ?? */
+#      define R300_TX_FORMAT_UNK25                (1 << 25) /* no swizzle */
+#      define R300_TX_FORMAT_CUBIC_MAP            (1 << 26)
+
+       /* gap */
+       /* Floating point formats */
+       /* Note - hardware supports both 16 and 32 bit floating point */
+#      define R300_TX_FORMAT_FL_I16                0x18
+#      define R300_TX_FORMAT_FL_I16A16             0x19
+#      define R300_TX_FORMAT_FL_R16G16B16A16       0x1A
+#      define R300_TX_FORMAT_FL_I32                0x1B
+#      define R300_TX_FORMAT_FL_I32A32             0x1C
+#      define R300_TX_FORMAT_FL_R32G32B32A32       0x1D
+       /* alpha modes, convenience mostly */
+       /* if you have alpha, pick constant appropriate to the
+          number of channels (1 for I8, 2 for I8A8, 4 for R8G8B8A8, etc */
+#      define R300_TX_FORMAT_ALPHA_1CH             0x000
+#      define R300_TX_FORMAT_ALPHA_2CH             0x200
+#      define R300_TX_FORMAT_ALPHA_4CH             0x600
+#      define R300_TX_FORMAT_ALPHA_NONE            0xA00
+       /* Swizzling */
+       /* constants */
+#      define R300_TX_FORMAT_X         0
+#      define R300_TX_FORMAT_Y         1
+#      define R300_TX_FORMAT_Z         2
+#      define R300_TX_FORMAT_W         3
+#      define R300_TX_FORMAT_ZERO      4
+#      define R300_TX_FORMAT_ONE       5
+       /* 2.0*Z, everything above 1.0 is set to 0.0 */
+#      define R300_TX_FORMAT_CUT_Z     6
+       /* 2.0*W, everything above 1.0 is set to 0.0 */
+#      define R300_TX_FORMAT_CUT_W     7
+
+#      define R300_TX_FORMAT_B_SHIFT   18
+#      define R300_TX_FORMAT_G_SHIFT   15
+#      define R300_TX_FORMAT_R_SHIFT   12
+#      define R300_TX_FORMAT_A_SHIFT   9
+       /* Convenience macro to take care of layout and swizzling */
+#      define R300_EASY_TX_FORMAT(B, G, R, A, FMT)     (               \
+               ((R300_TX_FORMAT_##B)<<R300_TX_FORMAT_B_SHIFT)          \
+               | ((R300_TX_FORMAT_##G)<<R300_TX_FORMAT_G_SHIFT)        \
+               | ((R300_TX_FORMAT_##R)<<R300_TX_FORMAT_R_SHIFT)        \
+               | ((R300_TX_FORMAT_##A)<<R300_TX_FORMAT_A_SHIFT)        \
+               | (R300_TX_FORMAT_##FMT)                                \
+               )
+       /* These can be ORed with result of R300_EASY_TX_FORMAT()
+          We don't really know what they do. Take values from a
+           constant color ? */
+#      define R300_TX_FORMAT_CONST_X           (1<<5)
+#      define R300_TX_FORMAT_CONST_Y           (2<<5)
+#      define R300_TX_FORMAT_CONST_Z           (4<<5)
+#      define R300_TX_FORMAT_CONST_W           (8<<5)
+
+#      define R300_TX_FORMAT_YUV_MODE          0x00800000
+
+#define R300_TX_PITCH_0                            0x4500 /* obvious missing in gap */
+#define R300_TX_OFFSET_0                    0x4540
+       /* BEGIN: Guess from R200 */
+#       define R300_TXO_ENDIAN_NO_SWAP           (0 << 0)
+#       define R300_TXO_ENDIAN_BYTE_SWAP         (1 << 0)
+#       define R300_TXO_ENDIAN_WORD_SWAP         (2 << 0)
+#       define R300_TXO_ENDIAN_HALFDW_SWAP       (3 << 0)
+#       define R300_TXO_MACRO_TILE               (1 << 2)
+#       define R300_TXO_MICRO_TILE               (1 << 3)
+#       define R300_TXO_OFFSET_MASK              0xffffffe0
+#       define R300_TXO_OFFSET_SHIFT             5
+       /* END: Guess from R200 */
+
+/* 32 bit chroma key */
+#define R300_TX_CHROMA_KEY_0                      0x4580
+/* ff00ff00 == { 0, 1.0, 0, 1.0 } */
+#define R300_TX_BORDER_COLOR_0              0x45C0
+
+/* END: Texture specification */
+
+/* BEGIN: Fragment program instruction set */
+
+/* Fragment programs are written directly into register space.
+ * There are separate instruction streams for texture instructions and ALU
+ * instructions.
+ * In order to synchronize these streams, the program is divided into up
+ * to 4 nodes. Each node begins with a number of TEX operations, followed
+ * by a number of ALU operations.
+ * The first node can have zero TEX ops, all subsequent nodes must have at
+ * least
+ * one TEX ops.
+ * All nodes must have at least one ALU op.
+ *
+ * The index of the last node is stored in PFS_CNTL_0: A value of 0 means
+ * 1 node, a value of 3 means 4 nodes.
+ * The total amount of instructions is defined in PFS_CNTL_2. The offsets are
+ * offsets into the respective instruction streams, while *_END points to the
+ * last instruction relative to this offset.
+ */
+#define R300_PFS_CNTL_0                     0x4600
+#       define R300_PFS_CNTL_LAST_NODES_SHIFT    0
+#       define R300_PFS_CNTL_LAST_NODES_MASK     (3 << 0)
+#       define R300_PFS_CNTL_FIRST_NODE_HAS_TEX  (1 << 3)
+#define R300_PFS_CNTL_1                     0x4604
+/* There is an unshifted value here which has so far always been equal to the
+ * index of the highest used temporary register.
+ */
+#define R300_PFS_CNTL_2                     0x4608
+#       define R300_PFS_CNTL_ALU_OFFSET_SHIFT    0
+#       define R300_PFS_CNTL_ALU_OFFSET_MASK     (63 << 0)
+#       define R300_PFS_CNTL_ALU_END_SHIFT       6
+#       define R300_PFS_CNTL_ALU_END_MASK        (63 << 6)
+#       define R300_PFS_CNTL_TEX_OFFSET_SHIFT    12
+#       define R300_PFS_CNTL_TEX_OFFSET_MASK     (31 << 12) /* GUESS */
+#       define R300_PFS_CNTL_TEX_END_SHIFT       18
+#       define R300_PFS_CNTL_TEX_END_MASK        (31 << 18) /* GUESS */
+
+/* gap */
+
+/* Nodes are stored backwards. The last active node is always stored in
+ * PFS_NODE_3.
+ * Example: In a 2-node program, NODE_0 and NODE_1 are set to 0. The
+ * first node is stored in NODE_2, the second node is stored in NODE_3.
+ *
+ * Offsets are relative to the master offset from PFS_CNTL_2.
+ */
+#define R300_PFS_NODE_0                     0x4610
+#define R300_PFS_NODE_1                     0x4614
+#define R300_PFS_NODE_2                     0x4618
+#define R300_PFS_NODE_3                     0x461C
+#       define R300_PFS_NODE_ALU_OFFSET_SHIFT    0
+#       define R300_PFS_NODE_ALU_OFFSET_MASK     (63 << 0)
+#       define R300_PFS_NODE_ALU_END_SHIFT       6
+#       define R300_PFS_NODE_ALU_END_MASK        (63 << 6)
+#       define R300_PFS_NODE_TEX_OFFSET_SHIFT    12
+#       define R300_PFS_NODE_TEX_OFFSET_MASK     (31 << 12)
+#       define R300_PFS_NODE_TEX_END_SHIFT       17
+#       define R300_PFS_NODE_TEX_END_MASK        (31 << 17)
+#              define R300_PFS_NODE_OUTPUT_COLOR        (1 << 22)
+#              define R300_PFS_NODE_OUTPUT_DEPTH        (1 << 23)
+
+/* TEX
+ * As far as I can tell, texture instructions cannot write into output
+ * registers directly. A subsequent ALU instruction is always necessary,
+ * even if it's just MAD o0, r0, 1, 0
+ */
+#define R300_PFS_TEXI_0                     0x4620
+#      define R300_FPITX_SRC_SHIFT              0
+#      define R300_FPITX_SRC_MASK               (31 << 0)
+       /* GUESS */
+#      define R300_FPITX_SRC_CONST              (1 << 5)
+#      define R300_FPITX_DST_SHIFT              6
+#      define R300_FPITX_DST_MASK               (31 << 6)
+#      define R300_FPITX_IMAGE_SHIFT            11
+       /* GUESS based on layout and native limits */
+#       define R300_FPITX_IMAGE_MASK             (15 << 11)
+/* Unsure if these are opcodes, or some kind of bitfield, but this is how
+ * they were set when I checked
+ */
+#      define R300_FPITX_OPCODE_SHIFT          15
+#              define R300_FPITX_OP_TEX        1
+#              define R300_FPITX_OP_KIL        2
+#              define R300_FPITX_OP_TXP        3
+#              define R300_FPITX_OP_TXB        4
+#      define R300_FPITX_OPCODE_MASK           (7 << 15)
+
+/* ALU
+ * The ALU instructions register blocks are enumerated according to the order
+ * in which fglrx. I assume there is space for 64 instructions, since
+ * each block has space for a maximum of 64 DWORDs, and this matches reported
+ * native limits.
+ *
+ * The basic functional block seems to be one MAD for each color and alpha,
+ * and an adder that adds all components after the MUL.
+ *  - ADD, MUL, MAD etc.: use MAD with appropriate neutral operands
+ *  - DP4: Use OUTC_DP4, OUTA_DP4
+ *  - DP3: Use OUTC_DP3, OUTA_DP4, appropriate alpha operands
+ *  - DPH: Use OUTC_DP4, OUTA_DP4, appropriate alpha operands
+ *  - CMPH: If ARG2 > 0.5, return ARG0, else return ARG1
+ *  - CMP: If ARG2 < 0, return ARG1, else return ARG0
+ *  - FLR: use FRC+MAD
+ *  - XPD: use MAD+MAD
+ *  - SGE, SLT: use MAD+CMP
+ *  - RSQ: use ABS modifier for argument
+ *  - Use OUTC_REPL_ALPHA to write results of an alpha-only operation
+ *    (e.g. RCP) into color register
+ *  - apparently, there's no quick DST operation
+ *  - fglrx set FPI2_UNKNOWN_31 on a "MAD fragment.color, tmp0, tmp1, tmp2"
+ *  - fglrx set FPI2_UNKNOWN_31 on a "MAX r2, r1, c0"
+ *  - fglrx once set FPI0_UNKNOWN_31 on a "FRC r1, r1"
+ *
+ * Operand selection
+ * First stage selects three sources from the available registers and
+ * constant parameters. This is defined in INSTR1 (color) and INSTR3 (alpha).
+ * fglrx sorts the three source fields: Registers before constants,
+ * lower indices before higher indices; I do not know whether this is
+ * necessary.
+ *
+ * fglrx fills unused sources with "read constant 0"
+ * According to specs, you cannot select more than two different constants.
+ *
+ * Second stage selects the operands from the sources. This is defined in
+ * INSTR0 (color) and INSTR2 (alpha). You can also select the special constants
+ * zero and one.
+ * Swizzling and negation happens in this stage, as well.
+ *
+ * Important: Color and alpha seem to be mostly separate, i.e. their sources
+ * selection appears to be fully independent (the register storage is probably
+ * physically split into a color and an alpha section).
+ * However (because of the apparent physical split), there is some interaction
+ * WRT swizzling. If, for example, you want to load an R component into an
+ * Alpha operand, this R component is taken from a *color* source, not from
+ * an alpha source. The corresponding register doesn't even have to appear in
+ * the alpha sources list. (I hope this all makes sense to you)
+ *
+ * Destination selection
+ * The destination register index is in FPI1 (color) and FPI3 (alpha)
+ * together with enable bits.
+ * There are separate enable bits for writing into temporary registers
+ * (DSTC_REG_* /DSTA_REG) and and program output registers (DSTC_OUTPUT_*
+ * /DSTA_OUTPUT). You can write to both at once, or not write at all (the
+ * same index must be used for both).
+ *
+ * Note: There is a special form for LRP
+ *  - Argument order is the same as in ARB_fragment_program.
+ *  - Operation is MAD
+ *  - ARG1 is set to ARGC_SRC1C_LRP/ARGC_SRC1A_LRP
+ *  - Set FPI0/FPI2_SPECIAL_LRP
+ * Arbitrary LRP (including support for swizzling) requires vanilla MAD+MAD
+ */
+#define R300_PFS_INSTR1_0                   0x46C0
+#       define R300_FPI1_SRC0C_SHIFT             0
+#       define R300_FPI1_SRC0C_MASK              (31 << 0)
+#       define R300_FPI1_SRC0C_CONST             (1 << 5)
+#       define R300_FPI1_SRC1C_SHIFT             6
+#       define R300_FPI1_SRC1C_MASK              (31 << 6)
+#       define R300_FPI1_SRC1C_CONST             (1 << 11)
+#       define R300_FPI1_SRC2C_SHIFT             12
+#       define R300_FPI1_SRC2C_MASK              (31 << 12)
+#       define R300_FPI1_SRC2C_CONST             (1 << 17)
+#       define R300_FPI1_SRC_MASK                0x0003ffff
+#       define R300_FPI1_DSTC_SHIFT              18
+#       define R300_FPI1_DSTC_MASK               (31 << 18)
+#              define R300_FPI1_DSTC_REG_MASK_SHIFT     23
+#       define R300_FPI1_DSTC_REG_X              (1 << 23)
+#       define R300_FPI1_DSTC_REG_Y              (1 << 24)
+#       define R300_FPI1_DSTC_REG_Z              (1 << 25)
+#              define R300_FPI1_DSTC_OUTPUT_MASK_SHIFT  26
+#       define R300_FPI1_DSTC_OUTPUT_X           (1 << 26)
+#       define R300_FPI1_DSTC_OUTPUT_Y           (1 << 27)
+#       define R300_FPI1_DSTC_OUTPUT_Z           (1 << 28)
+
+#define R300_PFS_INSTR3_0                   0x47C0
+#       define R300_FPI3_SRC0A_SHIFT             0
+#       define R300_FPI3_SRC0A_MASK              (31 << 0)
+#       define R300_FPI3_SRC0A_CONST             (1 << 5)
+#       define R300_FPI3_SRC1A_SHIFT             6
+#       define R300_FPI3_SRC1A_MASK              (31 << 6)
+#       define R300_FPI3_SRC1A_CONST             (1 << 11)
+#       define R300_FPI3_SRC2A_SHIFT             12
+#       define R300_FPI3_SRC2A_MASK              (31 << 12)
+#       define R300_FPI3_SRC2A_CONST             (1 << 17)
+#       define R300_FPI3_SRC_MASK                0x0003ffff
+#       define R300_FPI3_DSTA_SHIFT              18
+#       define R300_FPI3_DSTA_MASK               (31 << 18)
+#       define R300_FPI3_DSTA_REG                (1 << 23)
+#       define R300_FPI3_DSTA_OUTPUT             (1 << 24)
+#              define R300_FPI3_DSTA_DEPTH              (1 << 27)
+
+#define R300_PFS_INSTR0_0                   0x48C0
+#       define R300_FPI0_ARGC_SRC0C_XYZ          0
+#       define R300_FPI0_ARGC_SRC0C_XXX          1
+#       define R300_FPI0_ARGC_SRC0C_YYY          2
+#       define R300_FPI0_ARGC_SRC0C_ZZZ          3
+#       define R300_FPI0_ARGC_SRC1C_XYZ          4
+#       define R300_FPI0_ARGC_SRC1C_XXX          5
+#       define R300_FPI0_ARGC_SRC1C_YYY          6
+#       define R300_FPI0_ARGC_SRC1C_ZZZ          7
+#       define R300_FPI0_ARGC_SRC2C_XYZ          8
+#       define R300_FPI0_ARGC_SRC2C_XXX          9
+#       define R300_FPI0_ARGC_SRC2C_YYY          10
+#       define R300_FPI0_ARGC_SRC2C_ZZZ          11
+#       define R300_FPI0_ARGC_SRC0A              12
+#       define R300_FPI0_ARGC_SRC1A              13
+#       define R300_FPI0_ARGC_SRC2A              14
+#       define R300_FPI0_ARGC_SRC1C_LRP          15
+#       define R300_FPI0_ARGC_ZERO               20
+#       define R300_FPI0_ARGC_ONE                21
+       /* GUESS */
+#       define R300_FPI0_ARGC_HALF               22
+#       define R300_FPI0_ARGC_SRC0C_YZX          23
+#       define R300_FPI0_ARGC_SRC1C_YZX          24
+#       define R300_FPI0_ARGC_SRC2C_YZX          25
+#       define R300_FPI0_ARGC_SRC0C_ZXY          26
+#       define R300_FPI0_ARGC_SRC1C_ZXY          27
+#       define R300_FPI0_ARGC_SRC2C_ZXY          28
+#       define R300_FPI0_ARGC_SRC0CA_WZY         29
+#       define R300_FPI0_ARGC_SRC1CA_WZY         30
+#       define R300_FPI0_ARGC_SRC2CA_WZY         31
+
+#       define R300_FPI0_ARG0C_SHIFT             0
+#       define R300_FPI0_ARG0C_MASK              (31 << 0)
+#       define R300_FPI0_ARG0C_NEG               (1 << 5)
+#       define R300_FPI0_ARG0C_ABS               (1 << 6)
+#       define R300_FPI0_ARG1C_SHIFT             7
+#       define R300_FPI0_ARG1C_MASK              (31 << 7)
+#       define R300_FPI0_ARG1C_NEG               (1 << 12)
+#       define R300_FPI0_ARG1C_ABS               (1 << 13)
+#       define R300_FPI0_ARG2C_SHIFT             14
+#       define R300_FPI0_ARG2C_MASK              (31 << 14)
+#       define R300_FPI0_ARG2C_NEG               (1 << 19)
+#       define R300_FPI0_ARG2C_ABS               (1 << 20)
+#       define R300_FPI0_SPECIAL_LRP             (1 << 21)
+#       define R300_FPI0_OUTC_MAD                (0 << 23)
+#       define R300_FPI0_OUTC_DP3                (1 << 23)
+#       define R300_FPI0_OUTC_DP4                (2 << 23)
+#       define R300_FPI0_OUTC_MIN                (4 << 23)
+#       define R300_FPI0_OUTC_MAX                (5 << 23)
+#       define R300_FPI0_OUTC_CMPH               (7 << 23)
+#       define R300_FPI0_OUTC_CMP                (8 << 23)
+#       define R300_FPI0_OUTC_FRC                (9 << 23)
+#       define R300_FPI0_OUTC_REPL_ALPHA         (10 << 23)
+#       define R300_FPI0_OUTC_SAT                (1 << 30)
+#       define R300_FPI0_INSERT_NOP              (1 << 31)
+
+#define R300_PFS_INSTR2_0                   0x49C0
+#       define R300_FPI2_ARGA_SRC0C_X            0
+#       define R300_FPI2_ARGA_SRC0C_Y            1
+#       define R300_FPI2_ARGA_SRC0C_Z            2
+#       define R300_FPI2_ARGA_SRC1C_X            3
+#       define R300_FPI2_ARGA_SRC1C_Y            4
+#       define R300_FPI2_ARGA_SRC1C_Z            5
+#       define R300_FPI2_ARGA_SRC2C_X            6
+#       define R300_FPI2_ARGA_SRC2C_Y            7
+#       define R300_FPI2_ARGA_SRC2C_Z            8
+#       define R300_FPI2_ARGA_SRC0A              9
+#       define R300_FPI2_ARGA_SRC1A              10
+#       define R300_FPI2_ARGA_SRC2A              11
+#       define R300_FPI2_ARGA_SRC1A_LRP          15
+#       define R300_FPI2_ARGA_ZERO               16
+#       define R300_FPI2_ARGA_ONE                17
+       /* GUESS */
+#       define R300_FPI2_ARGA_HALF               18
+#       define R300_FPI2_ARG0A_SHIFT             0
+#       define R300_FPI2_ARG0A_MASK              (31 << 0)
+#       define R300_FPI2_ARG0A_NEG               (1 << 5)
+       /* GUESS */
+#      define R300_FPI2_ARG0A_ABS               (1 << 6)
+#       define R300_FPI2_ARG1A_SHIFT             7
+#       define R300_FPI2_ARG1A_MASK              (31 << 7)
+#       define R300_FPI2_ARG1A_NEG               (1 << 12)
+       /* GUESS */
+#      define R300_FPI2_ARG1A_ABS               (1 << 13)
+#       define R300_FPI2_ARG2A_SHIFT             14
+#       define R300_FPI2_ARG2A_MASK              (31 << 14)
+#       define R300_FPI2_ARG2A_NEG               (1 << 19)
+       /* GUESS */
+#      define R300_FPI2_ARG2A_ABS               (1 << 20)
+#       define R300_FPI2_SPECIAL_LRP             (1 << 21)
+#       define R300_FPI2_OUTA_MAD                (0 << 23)
+#       define R300_FPI2_OUTA_DP4                (1 << 23)
+#       define R300_FPI2_OUTA_MIN                (2 << 23)
+#       define R300_FPI2_OUTA_MAX                (3 << 23)
+#       define R300_FPI2_OUTA_CMP                (6 << 23)
+#       define R300_FPI2_OUTA_FRC                (7 << 23)
+#       define R300_FPI2_OUTA_EX2                (8 << 23)
+#       define R300_FPI2_OUTA_LG2                (9 << 23)
+#       define R300_FPI2_OUTA_RCP                (10 << 23)
+#       define R300_FPI2_OUTA_RSQ                (11 << 23)
+#       define R300_FPI2_OUTA_SAT                (1 << 30)
+#       define R300_FPI2_UNKNOWN_31              (1 << 31)
+/* END: Fragment program instruction set */
+
+/* Fog state and color */
+#define R300_RE_FOG_STATE                   0x4BC0
+#       define R300_FOG_ENABLE                   (1 << 0)
+#      define R300_FOG_MODE_LINEAR              (0 << 1)
+#      define R300_FOG_MODE_EXP                 (1 << 1)
+#      define R300_FOG_MODE_EXP2                (2 << 1)
+#      define R300_FOG_MODE_MASK                (3 << 1)
+#define R300_FOG_COLOR_R                    0x4BC8
+#define R300_FOG_COLOR_G                    0x4BCC
+#define R300_FOG_COLOR_B                    0x4BD0
+
+#define R300_PP_ALPHA_TEST                  0x4BD4
+#       define R300_REF_ALPHA_MASK               0x000000ff
+#       define R300_ALPHA_TEST_FAIL              (0 << 8)
+#       define R300_ALPHA_TEST_LESS              (1 << 8)
+#       define R300_ALPHA_TEST_LEQUAL            (3 << 8)
+#       define R300_ALPHA_TEST_EQUAL             (2 << 8)
+#       define R300_ALPHA_TEST_GEQUAL            (6 << 8)
+#       define R300_ALPHA_TEST_GREATER           (4 << 8)
+#       define R300_ALPHA_TEST_NEQUAL            (5 << 8)
+#       define R300_ALPHA_TEST_PASS              (7 << 8)
+#       define R300_ALPHA_TEST_OP_MASK           (7 << 8)
+#       define R300_ALPHA_TEST_ENABLE            (1 << 11)
+
+/* gap */
+
+/* Fragment program parameters in 7.16 floating point */
+#define R300_PFS_PARAM_0_X                  0x4C00
+#define R300_PFS_PARAM_0_Y                  0x4C04
+#define R300_PFS_PARAM_0_Z                  0x4C08
+#define R300_PFS_PARAM_0_W                  0x4C0C
+/* GUESS: PARAM_31 is last, based on native limits reported by fglrx */
+#define R300_PFS_PARAM_31_X                 0x4DF0
+#define R300_PFS_PARAM_31_Y                 0x4DF4
+#define R300_PFS_PARAM_31_Z                 0x4DF8
+#define R300_PFS_PARAM_31_W                 0x4DFC
+
+/* Notes:
+ * - AFAIK fglrx always sets BLEND_UNKNOWN when blending is used in
+ *   the application
+ * - AFAIK fglrx always sets BLEND_NO_SEPARATE when CBLEND and ABLEND
+ *    are set to the same
+ *   function (both registers are always set up completely in any case)
+ * - Most blend flags are simply copied from R200 and not tested yet
+ */
+#define R300_RB3D_CBLEND                    0x4E04
+#define R300_RB3D_ABLEND                    0x4E08
+/* the following only appear in CBLEND */
+#       define R300_BLEND_ENABLE                     (1 << 0)
+#       define R300_BLEND_UNKNOWN                    (3 << 1)
+#       define R300_BLEND_NO_SEPARATE                (1 << 3)
+/* the following are shared between CBLEND and ABLEND */
+#       define R300_FCN_MASK                         (3  << 12)
+#       define R300_COMB_FCN_ADD_CLAMP               (0  << 12)
+#       define R300_COMB_FCN_ADD_NOCLAMP             (1  << 12)
+#       define R300_COMB_FCN_SUB_CLAMP               (2  << 12)
+#       define R300_COMB_FCN_SUB_NOCLAMP             (3  << 12)
+#       define R300_COMB_FCN_MIN                     (4  << 12)
+#       define R300_COMB_FCN_MAX                     (5  << 12)
+#       define R300_COMB_FCN_RSUB_CLAMP              (6  << 12)
+#       define R300_COMB_FCN_RSUB_NOCLAMP            (7  << 12)
+#       define R300_BLEND_GL_ZERO                    (32)
+#       define R300_BLEND_GL_ONE                     (33)
+#       define R300_BLEND_GL_SRC_COLOR               (34)
+#       define R300_BLEND_GL_ONE_MINUS_SRC_COLOR     (35)
+#       define R300_BLEND_GL_DST_COLOR               (36)
+#       define R300_BLEND_GL_ONE_MINUS_DST_COLOR     (37)
+#       define R300_BLEND_GL_SRC_ALPHA               (38)
+#       define R300_BLEND_GL_ONE_MINUS_SRC_ALPHA     (39)
+#       define R300_BLEND_GL_DST_ALPHA               (40)
+#       define R300_BLEND_GL_ONE_MINUS_DST_ALPHA     (41)
+#       define R300_BLEND_GL_SRC_ALPHA_SATURATE      (42)
+#       define R300_BLEND_GL_CONST_COLOR             (43)
+#       define R300_BLEND_GL_ONE_MINUS_CONST_COLOR   (44)
+#       define R300_BLEND_GL_CONST_ALPHA             (45)
+#       define R300_BLEND_GL_ONE_MINUS_CONST_ALPHA   (46)
+#       define R300_BLEND_MASK                       (63)
+#       define R300_SRC_BLEND_SHIFT                  (16)
+#       define R300_DST_BLEND_SHIFT                  (24)
+#define R300_RB3D_BLEND_COLOR               0x4E10
+#define R300_RB3D_COLORMASK                 0x4E0C
+#       define R300_COLORMASK0_B                 (1<<0)
+#       define R300_COLORMASK0_G                 (1<<1)
+#       define R300_COLORMASK0_R                 (1<<2)
+#       define R300_COLORMASK0_A                 (1<<3)
+
+/* gap */
+
+#define R300_RB3D_COLOROFFSET0              0x4E28
+#       define R300_COLOROFFSET_MASK             0xFFFFFFF0 /* GUESS */
+#define R300_RB3D_COLOROFFSET1              0x4E2C /* GUESS */
+#define R300_RB3D_COLOROFFSET2              0x4E30 /* GUESS */
+#define R300_RB3D_COLOROFFSET3              0x4E34 /* GUESS */
+
+/* gap */
+
+/* Bit 16: Larger tiles
+ * Bit 17: 4x2 tiles
+ * Bit 18: Extremely weird tile like, but some pixels duplicated?
+ */
+#define R300_RB3D_COLORPITCH0               0x4E38
+#       define R300_COLORPITCH_MASK              0x00001FF8 /* GUESS */
+#       define R300_COLOR_TILE_ENABLE            (1 << 16) /* GUESS */
+#       define R300_COLOR_MICROTILE_ENABLE       (1 << 17) /* GUESS */
+#       define R300_COLOR_ENDIAN_NO_SWAP         (0 << 18) /* GUESS */
+#       define R300_COLOR_ENDIAN_WORD_SWAP       (1 << 18) /* GUESS */
+#       define R300_COLOR_ENDIAN_DWORD_SWAP      (2 << 18) /* GUESS */
+#       define R300_COLOR_FORMAT_RGB565          (2 << 22)
+#       define R300_COLOR_FORMAT_ARGB8888        (3 << 22)
+#define R300_RB3D_COLORPITCH1               0x4E3C /* GUESS */
+#define R300_RB3D_COLORPITCH2               0x4E40 /* GUESS */
+#define R300_RB3D_COLORPITCH3               0x4E44 /* GUESS */
+
+/* gap */
+
+/* Guess by Vladimir.
+ * Set to 0A before 3D operations, set to 02 afterwards.
+ */
+/*#define R300_RB3D_DSTCACHE_CTLSTAT          0x4E4C*/
+#       define R300_RB3D_DSTCACHE_UNKNOWN_02             0x00000002
+#       define R300_RB3D_DSTCACHE_UNKNOWN_0A             0x0000000A
+
+/* gap */
+/* There seems to be no "write only" setting, so use Z-test = ALWAYS
+ * for this.
+ * Bit (1<<8) is the "test" bit. so plain write is 6  - vd
+ */
+#define R300_ZB_CNTL                             0x4F00
+#      define R300_STENCIL_ENABLE               (1 << 0)
+#      define R300_Z_ENABLE                     (1 << 1)
+#      define R300_Z_WRITE_ENABLE               (1 << 2)
+#      define R300_Z_SIGNED_COMPARE             (1 << 3)
+#      define R300_STENCIL_FRONT_BACK           (1 << 4)
+
+#define R300_ZB_ZSTENCILCNTL                   0x4f04
+       /* functions */
+#      define R300_ZS_NEVER                    0
+#      define R300_ZS_LESS                     1
+#      define R300_ZS_LEQUAL                   2
+#      define R300_ZS_EQUAL                    3
+#      define R300_ZS_GEQUAL                   4
+#      define R300_ZS_GREATER                  5
+#      define R300_ZS_NOTEQUAL                 6
+#      define R300_ZS_ALWAYS                   7
+#       define R300_ZS_MASK                     7
+       /* operations */
+#      define R300_ZS_KEEP                     0
+#      define R300_ZS_ZERO                     1
+#      define R300_ZS_REPLACE                  2
+#      define R300_ZS_INCR                     3
+#      define R300_ZS_DECR                     4
+#      define R300_ZS_INVERT                   5
+#      define R300_ZS_INCR_WRAP                6
+#      define R300_ZS_DECR_WRAP                7
+#      define R300_Z_FUNC_SHIFT                0
+       /* front and back refer to operations done for front
+          and back faces, i.e. separate stencil function support */
+#      define R300_S_FRONT_FUNC_SHIFT          3
+#      define R300_S_FRONT_SFAIL_OP_SHIFT      6
+#      define R300_S_FRONT_ZPASS_OP_SHIFT      9
+#      define R300_S_FRONT_ZFAIL_OP_SHIFT      12
+#      define R300_S_BACK_FUNC_SHIFT           15
+#      define R300_S_BACK_SFAIL_OP_SHIFT       18
+#      define R300_S_BACK_ZPASS_OP_SHIFT       21
+#      define R300_S_BACK_ZFAIL_OP_SHIFT       24
+
+#define R300_ZB_STENCILREFMASK                        0x4f08
+#      define R300_STENCILREF_SHIFT       0
+#      define R300_STENCILREF_MASK        0x000000ff
+#      define R300_STENCILMASK_SHIFT      8
+#      define R300_STENCILMASK_MASK       0x0000ff00
+#      define R300_STENCILWRITEMASK_SHIFT 16
+#      define R300_STENCILWRITEMASK_MASK  0x00ff0000
+
+/* gap */
+
+#define R300_ZB_FORMAT                             0x4f10
+#      define R300_DEPTHFORMAT_16BIT_INT_Z   (0 << 0)
+#      define R300_DEPTHFORMAT_16BIT_13E3    (1 << 0)
+#      define R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL   (2 << 0)
+/* reserved up to (15 << 0) */
+#      define R300_INVERT_13E3_LEADING_ONES  (0 << 4)
+#      define R300_INVERT_13E3_LEADING_ZEROS (1 << 4)
+
+#define R300_ZB_ZTOP                             0x4F14
+#      define R300_ZTOP_DISABLE                 (0 << 0)
+#      define R300_ZTOP_ENABLE                  (1 << 0)
+
+/* gap */
+
+#define R300_ZB_ZCACHE_CTLSTAT            0x4f18
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_NO_EFFECT      (0 << 0)
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE (1 << 0)
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_NO_EFFECT       (0 << 1)
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE            (1 << 1)
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_IDLE            (0 << 31)
+#       define R300_ZB_ZCACHE_CTLSTAT_ZC_BUSY_BUSY            (1 << 31)
+
+#define R300_ZB_BW_CNTL                     0x4f1c
+#      define R300_HIZ_DISABLE                              (0 << 0)
+#      define R300_HIZ_ENABLE                               (1 << 0)
+#      define R300_HIZ_MIN                                  (0 << 1)
+#      define R300_HIZ_MAX                                  (1 << 1)
+#      define R300_FAST_FILL_DISABLE                        (0 << 2)
+#      define R300_FAST_FILL_ENABLE                         (1 << 2)
+#      define R300_RD_COMP_DISABLE                          (0 << 3)
+#      define R300_RD_COMP_ENABLE                           (1 << 3)
+#      define R300_WR_COMP_DISABLE                          (0 << 4)
+#      define R300_WR_COMP_ENABLE                           (1 << 4)
+#      define R300_ZB_CB_CLEAR_RMW                          (0 << 5)
+#      define R300_ZB_CB_CLEAR_CACHE_LINEAR                 (1 << 5)
+#      define R300_FORCE_COMPRESSED_STENCIL_VALUE_DISABLE   (0 << 6)
+#      define R300_FORCE_COMPRESSED_STENCIL_VALUE_ENABLE    (1 << 6)
+
+#      define R500_ZEQUAL_OPTIMIZE_ENABLE                   (0 << 7)
+#      define R500_ZEQUAL_OPTIMIZE_DISABLE                  (1 << 7)
+#      define R500_SEQUAL_OPTIMIZE_ENABLE                   (0 << 8)
+#      define R500_SEQUAL_OPTIMIZE_DISABLE                  (1 << 8)
+
+#      define R500_BMASK_ENABLE                             (0 << 10)
+#      define R500_BMASK_DISABLE                            (1 << 10)
+#      define R500_HIZ_EQUAL_REJECT_DISABLE                 (0 << 11)
+#      define R500_HIZ_EQUAL_REJECT_ENABLE                  (1 << 11)
+#      define R500_HIZ_FP_EXP_BITS_DISABLE                  (0 << 12)
+#      define R500_HIZ_FP_EXP_BITS_1                        (1 << 12)
+#      define R500_HIZ_FP_EXP_BITS_2                        (2 << 12)
+#      define R500_HIZ_FP_EXP_BITS_3                        (3 << 12)
+#      define R500_HIZ_FP_EXP_BITS_4                        (4 << 12)
+#      define R500_HIZ_FP_EXP_BITS_5                        (5 << 12)
+#      define R500_HIZ_FP_INVERT_LEADING_ONES               (0 << 15)
+#      define R500_HIZ_FP_INVERT_LEADING_ZEROS              (1 << 15)
+#      define R500_TILE_OVERWRITE_RECOMPRESSION_ENABLE      (0 << 16)
+#      define R500_TILE_OVERWRITE_RECOMPRESSION_DISABLE     (1 << 16)
+#      define R500_CONTIGUOUS_6XAA_SAMPLES_ENABLE           (0 << 17)
+#      define R500_CONTIGUOUS_6XAA_SAMPLES_DISABLE          (1 << 17)
+#      define R500_PEQ_PACKING_DISABLE                      (0 << 18)
+#      define R500_PEQ_PACKING_ENABLE                       (1 << 18)
+#      define R500_COVERED_PTR_MASKING_DISABLE              (0 << 18)
+#      define R500_COVERED_PTR_MASKING_ENABLE               (1 << 18)
+
+
+/* gap */
+
+/* Z Buffer Address Offset.
+ * Bits 31 to 5 are used for aligned Z buffer address offset for macro tiles.
+ */
+#define R300_ZB_DEPTHOFFSET               0x4f20
+
+/* Z Buffer Pitch and Endian Control */
+#define R300_ZB_DEPTHPITCH                0x4f24
+#       define R300_DEPTHPITCH_MASK              0x00003FFC
+#       define R300_DEPTHMACROTILE_DISABLE      (0 << 16)
+#       define R300_DEPTHMACROTILE_ENABLE       (1 << 16)
+#       define R300_DEPTHMICROTILE_LINEAR       (0 << 17)
+#       define R300_DEPTHMICROTILE_TILED        (1 << 17)
+#       define R300_DEPTHMICROTILE_TILED_SQUARE (2 << 17)
+#       define R300_DEPTHENDIAN_NO_SWAP         (0 << 18)
+#       define R300_DEPTHENDIAN_WORD_SWAP       (1 << 18)
+#       define R300_DEPTHENDIAN_DWORD_SWAP      (2 << 18)
+#       define R300_DEPTHENDIAN_HALF_DWORD_SWAP (3 << 18)
+
+/* Z Buffer Clear Value */
+#define R300_ZB_DEPTHCLEARVALUE                  0x4f28
+
+#define R300_ZB_ZMASK_OFFSET                    0x4f30
+#define R300_ZB_ZMASK_PITCH                     0x4f34
+#define R300_ZB_ZMASK_WRINDEX                   0x4f38
+#define R300_ZB_ZMASK_DWORD                     0x4f3c
+#define R300_ZB_ZMASK_RDINDEX                   0x4f40
+
+/* Hierarchical Z Memory Offset */
+#define R300_ZB_HIZ_OFFSET                       0x4f44
+
+/* Hierarchical Z Write Index */
+#define R300_ZB_HIZ_WRINDEX                      0x4f48
+
+/* Hierarchical Z Data */
+#define R300_ZB_HIZ_DWORD                        0x4f4c
+
+/* Hierarchical Z Read Index */
+#define R300_ZB_HIZ_RDINDEX                      0x4f50
+
+/* Hierarchical Z Pitch */
+#define R300_ZB_HIZ_PITCH                        0x4f54
+
+/* Z Buffer Z Pass Counter Data */
+#define R300_ZB_ZPASS_DATA                       0x4f58
+
+/* Z Buffer Z Pass Counter Address */
+#define R300_ZB_ZPASS_ADDR                       0x4f5c
+
+/* Depth buffer X and Y coordinate offset */
+#define R300_ZB_DEPTHXY_OFFSET                   0x4f60
+#      define R300_DEPTHX_OFFSET_SHIFT  1
+#      define R300_DEPTHX_OFFSET_MASK   0x000007FE
+#      define R300_DEPTHY_OFFSET_SHIFT  17
+#      define R300_DEPTHY_OFFSET_MASK   0x07FE0000
+
+/* Sets the fifo sizes */
+#define R500_ZB_FIFO_SIZE                        0x4fd0
+#      define R500_OP_FIFO_SIZE_FULL   (0 << 0)
+#      define R500_OP_FIFO_SIZE_HALF   (1 << 0)
+#      define R500_OP_FIFO_SIZE_QUATER (2 << 0)
+#      define R500_OP_FIFO_SIZE_EIGTHS (4 << 0)
+
+/* Stencil Reference Value and Mask for backfacing quads */
+/* R300_ZB_STENCILREFMASK handles front face */
+#define R500_ZB_STENCILREFMASK_BF                0x4fd4
+#      define R500_STENCILREF_SHIFT       0
+#      define R500_STENCILREF_MASK        0x000000ff
+#      define R500_STENCILMASK_SHIFT      8
+#      define R500_STENCILMASK_MASK       0x0000ff00
+#      define R500_STENCILWRITEMASK_SHIFT 16
+#      define R500_STENCILWRITEMASK_MASK  0x00ff0000
+
+/* BEGIN: Vertex program instruction set */
+
+/* Every instruction is four dwords long:
+ *  DWORD 0: output and opcode
+ *  DWORD 1: first argument
+ *  DWORD 2: second argument
+ *  DWORD 3: third argument
+ *
+ * Notes:
+ *  - ABS r, a is implemented as MAX r, a, -a
+ *  - MOV is implemented as ADD to zero
+ *  - XPD is implemented as MUL + MAD
+ *  - FLR is implemented as FRC + ADD
+ *  - apparently, fglrx tries to schedule instructions so that there is at
+ *    least one instruction between the write to a temporary and the first
+ *    read from said temporary; however, violations of this scheduling are
+ *    allowed
+ *  - register indices seem to be unrelated with OpenGL aliasing to
+ *    conventional state
+ *  - only one attribute and one parameter can be loaded at a time; however,
+ *    the same attribute/parameter can be used for more than one argument
+ *  - the second software argument for POW is the third hardware argument
+ *    (no idea why)
+ *  - MAD with only temporaries as input seems to use VPI_OUT_SELECT_MAD_2
+ *
+ * There is some magic surrounding LIT:
+ *   The single argument is replicated across all three inputs, but swizzled:
+ *     First argument: xyzy
+ *     Second argument: xyzx
+ *     Third argument: xyzw
+ *   Whenever the result is used later in the fragment program, fglrx forces
+ *   x and w to be 1.0 in the input selection; I don't know whether this is
+ *   strictly necessary
+ */
+#define R300_VPI_OUT_OP_DOT                     (1 << 0)
+#define R300_VPI_OUT_OP_MUL                     (2 << 0)
+#define R300_VPI_OUT_OP_ADD                     (3 << 0)
+#define R300_VPI_OUT_OP_MAD                     (4 << 0)
+#define R300_VPI_OUT_OP_DST                     (5 << 0)
+#define R300_VPI_OUT_OP_FRC                     (6 << 0)
+#define R300_VPI_OUT_OP_MAX                     (7 << 0)
+#define R300_VPI_OUT_OP_MIN                     (8 << 0)
+#define R300_VPI_OUT_OP_SGE                     (9 << 0)
+#define R300_VPI_OUT_OP_SLT                     (10 << 0)
+       /* Used in GL_POINT_DISTANCE_ATTENUATION_ARB, vector(scalar, vector) */
+#define R300_VPI_OUT_OP_UNK12                   (12 << 0)
+#define R300_VPI_OUT_OP_ARL                     (13 << 0)
+#define R300_VPI_OUT_OP_EXP                     (65 << 0)
+#define R300_VPI_OUT_OP_LOG                     (66 << 0)
+       /* Used in fog computations, scalar(scalar) */
+#define R300_VPI_OUT_OP_UNK67                   (67 << 0)
+#define R300_VPI_OUT_OP_LIT                     (68 << 0)
+#define R300_VPI_OUT_OP_POW                     (69 << 0)
+#define R300_VPI_OUT_OP_RCP                     (70 << 0)
+#define R300_VPI_OUT_OP_RSQ                     (72 << 0)
+       /* Used in GL_POINT_DISTANCE_ATTENUATION_ARB, scalar(scalar) */
+#define R300_VPI_OUT_OP_UNK73                   (73 << 0)
+#define R300_VPI_OUT_OP_EX2                     (75 << 0)
+#define R300_VPI_OUT_OP_LG2                     (76 << 0)
+#define R300_VPI_OUT_OP_MAD_2                   (128 << 0)
+       /* all temps, vector(scalar, vector, vector) */
+#define R300_VPI_OUT_OP_UNK129                  (129 << 0)
+
+#define R300_VPI_OUT_REG_CLASS_TEMPORARY        (0 << 8)
+#define R300_VPI_OUT_REG_CLASS_ADDR             (1 << 8)
+#define R300_VPI_OUT_REG_CLASS_RESULT           (2 << 8)
+#define R300_VPI_OUT_REG_CLASS_MASK             (31 << 8)
+
+#define R300_VPI_OUT_REG_INDEX_SHIFT            13
+       /* GUESS based on fglrx native limits */
+#define R300_VPI_OUT_REG_INDEX_MASK             (31 << 13)
+
+#define R300_VPI_OUT_WRITE_X                    (1 << 20)
+#define R300_VPI_OUT_WRITE_Y                    (1 << 21)
+#define R300_VPI_OUT_WRITE_Z                    (1 << 22)
+#define R300_VPI_OUT_WRITE_W                    (1 << 23)
+
+#define R300_VPI_IN_REG_CLASS_TEMPORARY         (0 << 0)
+#define R300_VPI_IN_REG_CLASS_ATTRIBUTE         (1 << 0)
+#define R300_VPI_IN_REG_CLASS_PARAMETER         (2 << 0)
+#define R300_VPI_IN_REG_CLASS_NONE              (9 << 0)
+#define R300_VPI_IN_REG_CLASS_MASK              (31 << 0)
+
+#define R300_VPI_IN_REG_INDEX_SHIFT             5
+       /* GUESS based on fglrx native limits */
+#define R300_VPI_IN_REG_INDEX_MASK              (255 << 5)
+
+/* The R300 can select components from the input register arbitrarily.
+ * Use the following constants, shifted by the component shift you
+ * want to select
+ */
+#define R300_VPI_IN_SELECT_X    0
+#define R300_VPI_IN_SELECT_Y    1
+#define R300_VPI_IN_SELECT_Z    2
+#define R300_VPI_IN_SELECT_W    3
+#define R300_VPI_IN_SELECT_ZERO 4
+#define R300_VPI_IN_SELECT_ONE  5
+#define R300_VPI_IN_SELECT_MASK 7
+
+#define R300_VPI_IN_X_SHIFT                     13
+#define R300_VPI_IN_Y_SHIFT                     16
+#define R300_VPI_IN_Z_SHIFT                     19
+#define R300_VPI_IN_W_SHIFT                     22
+
+#define R300_VPI_IN_NEG_X                       (1 << 25)
+#define R300_VPI_IN_NEG_Y                       (1 << 26)
+#define R300_VPI_IN_NEG_Z                       (1 << 27)
+#define R300_VPI_IN_NEG_W                       (1 << 28)
+/* END: Vertex program instruction set */
+
+/* BEGIN: Packet 3 commands */
+
+/* A primitive emission dword. */
+#define R300_PRIM_TYPE_NONE                     (0 << 0)
+#define R300_PRIM_TYPE_POINT                    (1 << 0)
+#define R300_PRIM_TYPE_LINE                     (2 << 0)
+#define R300_PRIM_TYPE_LINE_STRIP               (3 << 0)
+#define R300_PRIM_TYPE_TRI_LIST                 (4 << 0)
+#define R300_PRIM_TYPE_TRI_FAN                  (5 << 0)
+#define R300_PRIM_TYPE_TRI_STRIP                (6 << 0)
+#define R300_PRIM_TYPE_TRI_TYPE2                (7 << 0)
+#define R300_PRIM_TYPE_RECT_LIST                (8 << 0)
+#define R300_PRIM_TYPE_3VRT_POINT_LIST          (9 << 0)
+#define R300_PRIM_TYPE_3VRT_LINE_LIST           (10 << 0)
+       /* GUESS (based on r200) */
+#define R300_PRIM_TYPE_POINT_SPRITES            (11 << 0)
+#define R300_PRIM_TYPE_LINE_LOOP                (12 << 0)
+#define R300_PRIM_TYPE_QUADS                    (13 << 0)
+#define R300_PRIM_TYPE_QUAD_STRIP               (14 << 0)
+#define R300_PRIM_TYPE_POLYGON                  (15 << 0)
+#define R300_PRIM_TYPE_MASK                     0xF
+#define R300_PRIM_WALK_IND                      (1 << 4)
+#define R300_PRIM_WALK_LIST                     (2 << 4)
+#define R300_PRIM_WALK_RING                     (3 << 4)
+#define R300_PRIM_WALK_MASK                     (3 << 4)
+       /* GUESS (based on r200) */
+#define R300_PRIM_COLOR_ORDER_BGRA              (0 << 6)
+#define R300_PRIM_COLOR_ORDER_RGBA              (1 << 6)
+#define R300_PRIM_NUM_VERTICES_SHIFT            16
+#define R300_PRIM_NUM_VERTICES_MASK             0xffff
+
+/* Draw a primitive from vertex data in arrays loaded via 3D_LOAD_VBPNTR.
+ * Two parameter dwords:
+ * 0. The first parameter appears to be always 0
+ * 1. The second parameter is a standard primitive emission dword.
+ */
+#define R300_PACKET3_3D_DRAW_VBUF           0x00002800
+
+/* Specify the full set of vertex arrays as (address, stride).
+ * The first parameter is the number of vertex arrays specified.
+ * The rest of the command is a variable length list of blocks, where
+ * each block is three dwords long and specifies two arrays.
+ * The first dword of a block is split into two words, the lower significant
+ * word refers to the first array, the more significant word to the second
+ * array in the block.
+ * The low byte of each word contains the size of an array entry in dwords,
+ * the high byte contains the stride of the array.
+ * The second dword of a block contains the pointer to the first array,
+ * the third dword of a block contains the pointer to the second array.
+ * Note that if the total number of arrays is odd, the third dword of
+ * the last block is omitted.
+ */
+#define R300_PACKET3_3D_LOAD_VBPNTR         0x00002F00
+
+#define R300_PACKET3_INDX_BUFFER            0x00003300
+#    define R300_EB_UNK1_SHIFT                      24
+#    define R300_EB_UNK1                    (0x80<<24)
+#    define R300_EB_UNK2                        0x0810
+#define R300_PACKET3_3D_DRAW_VBUF_2         0x00003400
+#define R300_PACKET3_3D_DRAW_INDX_2         0x00003600
+
+/* END: Packet 3 commands */
+
+
+/* Color formats for 2d packets
+ */
+#define R300_CP_COLOR_FORMAT_CI8       2
+#define R300_CP_COLOR_FORMAT_ARGB1555  3
+#define R300_CP_COLOR_FORMAT_RGB565    4
+#define R300_CP_COLOR_FORMAT_ARGB8888  6
+#define R300_CP_COLOR_FORMAT_RGB332    7
+#define R300_CP_COLOR_FORMAT_RGB8      9
+#define R300_CP_COLOR_FORMAT_ARGB4444  15
+
+/*
+ * CP type-3 packets
+ */
+#define R300_CP_CMD_BITBLT_MULTI       0xC0009B00
+
+#define R500_VAP_INDEX_OFFSET          0x208c
+
+#define R500_GA_US_VECTOR_INDEX         0x4250
+#define R500_GA_US_VECTOR_DATA          0x4254
+
+#define R500_RS_IP_0                    0x4074
+#define R500_RS_INST_0                  0x4320
+
+#define R500_US_CONFIG                  0x4600
+
+#define R500_US_FC_CTRL                        0x4624
+#define R500_US_CODE_ADDR              0x4630
+
+#define R500_RB3D_COLOR_CLEAR_VALUE_AR  0x46c0
+#define R500_RB3D_CONSTANT_COLOR_AR     0x4ef8
+
+#endif /* _R300_REG_H */
diff --git a/drivers/gpu/drm/radeon/radeon_cp.c b/drivers/gpu/drm/radeon/radeon_cp.c
new file mode 100644 (file)
index 0000000..e53158f
--- /dev/null
@@ -0,0 +1,1773 @@
+/* radeon_cp.c -- CP support for Radeon -*- linux-c -*- */
+/*
+ * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
+ * Copyright 2007 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Kevin E. Martin <martin@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+#include "r300_reg.h"
+
+#include "radeon_microcode.h"
+
+#define RADEON_FIFO_DEBUG      0
+
+static int radeon_do_cleanup_cp(struct drm_device * dev);
+
+static u32 R500_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
+{
+       u32 ret;
+       RADEON_WRITE(R520_MC_IND_INDEX, 0x7f0000 | (addr & 0xff));
+       ret = RADEON_READ(R520_MC_IND_DATA);
+       RADEON_WRITE(R520_MC_IND_INDEX, 0);
+       return ret;
+}
+
+static u32 RS480_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
+{
+       u32 ret;
+       RADEON_WRITE(RS480_NB_MC_INDEX, addr & 0xff);
+       ret = RADEON_READ(RS480_NB_MC_DATA);
+       RADEON_WRITE(RS480_NB_MC_INDEX, 0xff);
+       return ret;
+}
+
+static u32 RS690_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
+{
+       u32 ret;
+       RADEON_WRITE(RS690_MC_INDEX, (addr & RS690_MC_INDEX_MASK));
+       ret = RADEON_READ(RS690_MC_DATA);
+       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_MASK);
+       return ret;
+}
+
+static u32 IGP_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
+{
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
+               return RS690_READ_MCIND(dev_priv, addr);
+       else
+               return RS480_READ_MCIND(dev_priv, addr);
+}
+
+u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv)
+{
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
+               return R500_READ_MCIND(dev_priv, RV515_MC_FB_LOCATION);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
+               return RS690_READ_MCIND(dev_priv, RS690_MC_FB_LOCATION);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
+               return R500_READ_MCIND(dev_priv, R520_MC_FB_LOCATION);
+       else
+               return RADEON_READ(RADEON_MC_FB_LOCATION);
+}
+
+static void radeon_write_fb_location(drm_radeon_private_t *dev_priv, u32 fb_loc)
+{
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
+               R500_WRITE_MCIND(RV515_MC_FB_LOCATION, fb_loc);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
+               RS690_WRITE_MCIND(RS690_MC_FB_LOCATION, fb_loc);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
+               R500_WRITE_MCIND(R520_MC_FB_LOCATION, fb_loc);
+       else
+               RADEON_WRITE(RADEON_MC_FB_LOCATION, fb_loc);
+}
+
+static void radeon_write_agp_location(drm_radeon_private_t *dev_priv, u32 agp_loc)
+{
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
+               R500_WRITE_MCIND(RV515_MC_AGP_LOCATION, agp_loc);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
+               RS690_WRITE_MCIND(RS690_MC_AGP_LOCATION, agp_loc);
+       else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
+               R500_WRITE_MCIND(R520_MC_AGP_LOCATION, agp_loc);
+       else
+               RADEON_WRITE(RADEON_MC_AGP_LOCATION, agp_loc);
+}
+
+static void radeon_write_agp_base(drm_radeon_private_t *dev_priv, u64 agp_base)
+{
+       u32 agp_base_hi = upper_32_bits(agp_base);
+       u32 agp_base_lo = agp_base & 0xffffffff;
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) {
+               R500_WRITE_MCIND(RV515_MC_AGP_BASE, agp_base_lo);
+               R500_WRITE_MCIND(RV515_MC_AGP_BASE_2, agp_base_hi);
+       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) {
+               RS690_WRITE_MCIND(RS690_MC_AGP_BASE, agp_base_lo);
+               RS690_WRITE_MCIND(RS690_MC_AGP_BASE_2, agp_base_hi);
+       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515) {
+               R500_WRITE_MCIND(R520_MC_AGP_BASE, agp_base_lo);
+               R500_WRITE_MCIND(R520_MC_AGP_BASE_2, agp_base_hi);
+       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480) {
+               RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo);
+               RADEON_WRITE(RS480_AGP_BASE_2, 0);
+       } else {
+               RADEON_WRITE(RADEON_AGP_BASE, agp_base_lo);
+               if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R200)
+                       RADEON_WRITE(RADEON_AGP_BASE_2, agp_base_hi);
+       }
+}
+
+static int RADEON_READ_PLL(struct drm_device * dev, int addr)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f);
+       return RADEON_READ(RADEON_CLOCK_CNTL_DATA);
+}
+
+static u32 RADEON_READ_PCIE(drm_radeon_private_t *dev_priv, int addr)
+{
+       RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff);
+       return RADEON_READ(RADEON_PCIE_DATA);
+}
+
+#if RADEON_FIFO_DEBUG
+static void radeon_status(drm_radeon_private_t * dev_priv)
+{
+       printk("%s:\n", __func__);
+       printk("RBBM_STATUS = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_RBBM_STATUS));
+       printk("CP_RB_RTPR = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR));
+       printk("CP_RB_WTPR = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR));
+       printk("AIC_CNTL = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_AIC_CNTL));
+       printk("AIC_STAT = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_AIC_STAT));
+       printk("AIC_PT_BASE = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE));
+       printk("TLB_ADDR = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR));
+       printk("TLB_DATA = 0x%08x\n",
+              (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA));
+}
+#endif
+
+/* ================================================================
+ * Engine, FIFO control
+ */
+
+static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
+{
+       u32 tmp;
+       int i;
+
+       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {
+               tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT);
+               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
+               RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp);
+
+               for (i = 0; i < dev_priv->usec_timeout; i++) {
+                       if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT)
+                             & RADEON_RB3D_DC_BUSY)) {
+                               return 0;
+                       }
+                       DRM_UDELAY(1);
+               }
+       } else {
+               /* 3D */
+               tmp = RADEON_READ(R300_RB3D_DSTCACHE_CTLSTAT);
+               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
+               RADEON_WRITE(R300_RB3D_DSTCACHE_CTLSTAT, tmp);
+
+               /* 2D */
+               tmp = RADEON_READ(R300_DSTCACHE_CTLSTAT);
+               tmp |= RADEON_RB3D_DC_FLUSH_ALL;
+               RADEON_WRITE(R300_DSTCACHE_CTLSTAT, tmp);
+
+               for (i = 0; i < dev_priv->usec_timeout; i++) {
+                       if (!(RADEON_READ(R300_DSTCACHE_CTLSTAT)
+                         & RADEON_RB3D_DC_BUSY)) {
+                               return 0;
+                       }
+                       DRM_UDELAY(1);
+               }
+       }
+
+#if RADEON_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+       radeon_status(dev_priv);
+#endif
+       return -EBUSY;
+}
+
+static int radeon_do_wait_for_fifo(drm_radeon_private_t * dev_priv, int entries)
+{
+       int i;
+
+       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               int slots = (RADEON_READ(RADEON_RBBM_STATUS)
+                            & RADEON_RBBM_FIFOCNT_MASK);
+               if (slots >= entries)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if RADEON_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+       radeon_status(dev_priv);
+#endif
+       return -EBUSY;
+}
+
+static int radeon_do_wait_for_idle(drm_radeon_private_t * dev_priv)
+{
+       int i, ret;
+
+       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+       ret = radeon_do_wait_for_fifo(dev_priv, 64);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               if (!(RADEON_READ(RADEON_RBBM_STATUS)
+                     & RADEON_RBBM_ACTIVE)) {
+                       radeon_do_pixcache_flush(dev_priv);
+                       return 0;
+               }
+               DRM_UDELAY(1);
+       }
+
+#if RADEON_FIFO_DEBUG
+       DRM_ERROR("failed!\n");
+       radeon_status(dev_priv);
+#endif
+       return -EBUSY;
+}
+
+static void radeon_init_pipes(drm_radeon_private_t *dev_priv)
+{
+       uint32_t gb_tile_config, gb_pipe_sel = 0;
+
+       /* RS4xx/RS6xx/R4xx/R5xx */
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R420) {
+               gb_pipe_sel = RADEON_READ(R400_GB_PIPE_SELECT);
+               dev_priv->num_gb_pipes = ((gb_pipe_sel >> 12) & 0x3) + 1;
+       } else {
+               /* R3xx */
+               if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) ||
+                   ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350)) {
+                       dev_priv->num_gb_pipes = 2;
+               } else {
+                       /* R3Vxx */
+                       dev_priv->num_gb_pipes = 1;
+               }
+       }
+       DRM_INFO("Num pipes: %d\n", dev_priv->num_gb_pipes);
+
+       gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16 /*| R300_SUBPIXEL_1_16*/);
+
+       switch (dev_priv->num_gb_pipes) {
+       case 2: gb_tile_config |= R300_PIPE_COUNT_R300; break;
+       case 3: gb_tile_config |= R300_PIPE_COUNT_R420_3P; break;
+       case 4: gb_tile_config |= R300_PIPE_COUNT_R420; break;
+       default:
+       case 1: gb_tile_config |= R300_PIPE_COUNT_RV350; break;
+       }
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV515) {
+               RADEON_WRITE_PLL(R500_DYN_SCLK_PWMEM_PIPE, (1 | ((gb_pipe_sel >> 8) & 0xf) << 4));
+               RADEON_WRITE(R500_SU_REG_DEST, ((1 << dev_priv->num_gb_pipes) - 1));
+       }
+       RADEON_WRITE(R300_GB_TILE_CONFIG, gb_tile_config);
+       radeon_do_wait_for_idle(dev_priv);
+       RADEON_WRITE(R300_DST_PIPE_CONFIG, RADEON_READ(R300_DST_PIPE_CONFIG) | R300_PIPE_AUTO_CONFIG);
+       RADEON_WRITE(R300_RB2D_DSTCACHE_MODE, (RADEON_READ(R300_RB2D_DSTCACHE_MODE) |
+                                              R300_DC_AUTOFLUSH_ENABLE |
+                                              R300_DC_DC_DISABLE_IGNORE_PE));
+
+
+}
+
+/* ================================================================
+ * CP control, initialization
+ */
+
+/* Load the microcode for the CP */
+static void radeon_cp_load_microcode(drm_radeon_private_t * dev_priv)
+{
+       int i;
+       DRM_DEBUG("\n");
+
+       radeon_do_wait_for_idle(dev_priv);
+
+       RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0);
+       if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R100) ||
+           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV100) ||
+           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV200) ||
+           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS100) ||
+           ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS200)) {
+               DRM_INFO("Loading R100 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    R100_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    R100_cp_microcode[i][0]);
+               }
+       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R200) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV250) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV280) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS300)) {
+               DRM_INFO("Loading R200 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    R200_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    R200_cp_microcode[i][0]);
+               }
+       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R300) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R350) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV350) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV380) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS480)) {
+               DRM_INFO("Loading R300 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    R300_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    R300_cp_microcode[i][0]);
+               }
+       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R420) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV410)) {
+               DRM_INFO("Loading R400 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    R420_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    R420_cp_microcode[i][0]);
+               }
+       } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) {
+               DRM_INFO("Loading RS690 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    RS690_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    RS690_cp_microcode[i][0]);
+               }
+       } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R520) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV530) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R580) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV560) ||
+                  ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV570)) {
+               DRM_INFO("Loading R500 Microcode\n");
+               for (i = 0; i < 256; i++) {
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
+                                    R520_cp_microcode[i][1]);
+                       RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
+                                    R520_cp_microcode[i][0]);
+               }
+       }
+}
+
+/* Flush any pending commands to the CP.  This should only be used just
+ * prior to a wait for idle, as it informs the engine that the command
+ * stream is ending.
+ */
+static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv)
+{
+       DRM_DEBUG("\n");
+#if 0
+       u32 tmp;
+
+       tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31);
+       RADEON_WRITE(RADEON_CP_RB_WPTR, tmp);
+#endif
+}
+
+/* Wait for the CP to go idle.
+ */
+int radeon_do_cp_idle(drm_radeon_private_t * dev_priv)
+{
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(6);
+
+       RADEON_PURGE_CACHE();
+       RADEON_PURGE_ZCACHE();
+       RADEON_WAIT_UNTIL_IDLE();
+
+       ADVANCE_RING();
+       COMMIT_RING();
+
+       return radeon_do_wait_for_idle(dev_priv);
+}
+
+/* Start the Command Processor.
+ */
+static void radeon_do_cp_start(drm_radeon_private_t * dev_priv)
+{
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       radeon_do_wait_for_idle(dev_priv);
+
+       RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode);
+
+       dev_priv->cp_running = 1;
+
+       BEGIN_RING(6);
+
+       RADEON_PURGE_CACHE();
+       RADEON_PURGE_ZCACHE();
+       RADEON_WAIT_UNTIL_IDLE();
+
+       ADVANCE_RING();
+       COMMIT_RING();
+}
+
+/* Reset the Command Processor.  This will not flush any pending
+ * commands, so you must wait for the CP command stream to complete
+ * before calling this routine.
+ */
+static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv)
+{
+       u32 cur_read_ptr;
+       DRM_DEBUG("\n");
+
+       cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
+       RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
+       SET_RING_HEAD(dev_priv, cur_read_ptr);
+       dev_priv->ring.tail = cur_read_ptr;
+}
+
+/* Stop the Command Processor.  This will not flush any pending
+ * commands, so you must flush the command stream and wait for the CP
+ * to go idle before calling this routine.
+ */
+static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv)
+{
+       DRM_DEBUG("\n");
+
+       RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS);
+
+       dev_priv->cp_running = 0;
+}
+
+/* Reset the engine.  This will stop the CP if it is running.
+ */
+static int radeon_do_engine_reset(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       u32 clock_cntl_index = 0, mclk_cntl = 0, rbbm_soft_reset;
+       DRM_DEBUG("\n");
+
+       radeon_do_pixcache_flush(dev_priv);
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) {
+               /* may need something similar for newer chips */
+               clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX);
+               mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL);
+
+               RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl |
+                                                   RADEON_FORCEON_MCLKA |
+                                                   RADEON_FORCEON_MCLKB |
+                                                   RADEON_FORCEON_YCLKA |
+                                                   RADEON_FORCEON_YCLKB |
+                                                   RADEON_FORCEON_MC |
+                                                   RADEON_FORCEON_AIC));
+       }
+
+       rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET);
+
+       RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset |
+                                             RADEON_SOFT_RESET_CP |
+                                             RADEON_SOFT_RESET_HI |
+                                             RADEON_SOFT_RESET_SE |
+                                             RADEON_SOFT_RESET_RE |
+                                             RADEON_SOFT_RESET_PP |
+                                             RADEON_SOFT_RESET_E2 |
+                                             RADEON_SOFT_RESET_RB));
+       RADEON_READ(RADEON_RBBM_SOFT_RESET);
+       RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset &
+                                             ~(RADEON_SOFT_RESET_CP |
+                                               RADEON_SOFT_RESET_HI |
+                                               RADEON_SOFT_RESET_SE |
+                                               RADEON_SOFT_RESET_RE |
+                                               RADEON_SOFT_RESET_PP |
+                                               RADEON_SOFT_RESET_E2 |
+                                               RADEON_SOFT_RESET_RB)));
+       RADEON_READ(RADEON_RBBM_SOFT_RESET);
+
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV410) {
+               RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl);
+               RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index);
+               RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset);
+       }
+
+       /* setup the raster pipes */
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R300)
+           radeon_init_pipes(dev_priv);
+
+       /* Reset the CP ring */
+       radeon_do_cp_reset(dev_priv);
+
+       /* The CP is no longer running after an engine reset */
+       dev_priv->cp_running = 0;
+
+       /* Reset any pending vertex, indirect buffers */
+       radeon_freelist_reset(dev);
+
+       return 0;
+}
+
+static void radeon_cp_init_ring_buffer(struct drm_device * dev,
+                                      drm_radeon_private_t * dev_priv)
+{
+       u32 ring_start, cur_read_ptr;
+       u32 tmp;
+
+       /* Initialize the memory controller. With new memory map, the fb location
+        * is not changed, it should have been properly initialized already. Part
+        * of the problem is that the code below is bogus, assuming the GART is
+        * always appended to the fb which is not necessarily the case
+        */
+       if (!dev_priv->new_memmap)
+               radeon_write_fb_location(dev_priv,
+                            ((dev_priv->gart_vm_start - 1) & 0xffff0000)
+                            | (dev_priv->fb_location >> 16));
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               radeon_write_agp_base(dev_priv, dev->agp->base);
+
+               radeon_write_agp_location(dev_priv,
+                            (((dev_priv->gart_vm_start - 1 +
+                               dev_priv->gart_size) & 0xffff0000) |
+                             (dev_priv->gart_vm_start >> 16)));
+
+               ring_start = (dev_priv->cp_ring->offset
+                             - dev->agp->base
+                             + dev_priv->gart_vm_start);
+       } else
+#endif
+               ring_start = (dev_priv->cp_ring->offset
+                             - (unsigned long)dev->sg->virtual
+                             + dev_priv->gart_vm_start);
+
+       RADEON_WRITE(RADEON_CP_RB_BASE, ring_start);
+
+       /* Set the write pointer delay */
+       RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0);
+
+       /* Initialize the ring buffer's read and write pointers */
+       cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
+       RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
+       SET_RING_HEAD(dev_priv, cur_read_ptr);
+       dev_priv->ring.tail = cur_read_ptr;
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
+                            dev_priv->ring_rptr->offset
+                            - dev->agp->base + dev_priv->gart_vm_start);
+       } else
+#endif
+       {
+               struct drm_sg_mem *entry = dev->sg;
+               unsigned long tmp_ofs, page_ofs;
+
+               tmp_ofs = dev_priv->ring_rptr->offset -
+                               (unsigned long)dev->sg->virtual;
+               page_ofs = tmp_ofs >> PAGE_SHIFT;
+
+               RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]);
+               DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n",
+                         (unsigned long)entry->busaddr[page_ofs],
+                         entry->handle + tmp_ofs);
+       }
+
+       /* Set ring buffer size */
+#ifdef __BIG_ENDIAN
+       RADEON_WRITE(RADEON_CP_RB_CNTL,
+                    RADEON_BUF_SWAP_32BIT |
+                    (dev_priv->ring.fetch_size_l2ow << 18) |
+                    (dev_priv->ring.rptr_update_l2qw << 8) |
+                    dev_priv->ring.size_l2qw);
+#else
+       RADEON_WRITE(RADEON_CP_RB_CNTL,
+                    (dev_priv->ring.fetch_size_l2ow << 18) |
+                    (dev_priv->ring.rptr_update_l2qw << 8) |
+                    dev_priv->ring.size_l2qw);
+#endif
+
+       /* Start with assuming that writeback doesn't work */
+       dev_priv->writeback_works = 0;
+
+       /* Initialize the scratch register pointer.  This will cause
+        * the scratch register values to be written out to memory
+        * whenever they are updated.
+        *
+        * We simply put this behind the ring read pointer, this works
+        * with PCI GART as well as (whatever kind of) AGP GART
+        */
+       RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR)
+                    + RADEON_SCRATCH_REG_OFFSET);
+
+       dev_priv->scratch = ((__volatile__ u32 *)
+                            dev_priv->ring_rptr->handle +
+                            (RADEON_SCRATCH_REG_OFFSET / sizeof(u32)));
+
+       RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7);
+
+       /* Turn on bus mastering */
+       tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
+       RADEON_WRITE(RADEON_BUS_CNTL, tmp);
+
+       dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
+       RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
+
+       dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0;
+       RADEON_WRITE(RADEON_LAST_DISPATCH_REG,
+                    dev_priv->sarea_priv->last_dispatch);
+
+       dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
+       RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear);
+
+       radeon_do_wait_for_idle(dev_priv);
+
+       /* Sync everything up */
+       RADEON_WRITE(RADEON_ISYNC_CNTL,
+                    (RADEON_ISYNC_ANY2D_IDLE3D |
+                     RADEON_ISYNC_ANY3D_IDLE2D |
+                     RADEON_ISYNC_WAIT_IDLEGUI |
+                     RADEON_ISYNC_CPSCRATCH_IDLEGUI));
+
+}
+
+static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
+{
+       u32 tmp;
+
+       /* Writeback doesn't seem to work everywhere, test it here and possibly
+        * enable it if it appears to work
+        */
+       DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0);
+       RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef);
+
+       for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
+               if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
+                   0xdeadbeef)
+                       break;
+               DRM_UDELAY(1);
+       }
+
+       if (tmp < dev_priv->usec_timeout) {
+               dev_priv->writeback_works = 1;
+               DRM_INFO("writeback test succeeded in %d usecs\n", tmp);
+       } else {
+               dev_priv->writeback_works = 0;
+               DRM_INFO("writeback test failed\n");
+       }
+       if (radeon_no_wb == 1) {
+               dev_priv->writeback_works = 0;
+               DRM_INFO("writeback forced off\n");
+       }
+
+       if (!dev_priv->writeback_works) {
+               /* Disable writeback to avoid unnecessary bus master transfer */
+               RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) |
+                            RADEON_RB_NO_UPDATE);
+               RADEON_WRITE(RADEON_SCRATCH_UMSK, 0);
+       }
+}
+
+/* Enable or disable IGP GART on the chip */
+static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on)
+{
+       u32 temp;
+
+       if (on) {
+               DRM_DEBUG("programming igp gart %08X %08lX %08X\n",
+                         dev_priv->gart_vm_start,
+                         (long)dev_priv->gart_info.bus_addr,
+                         dev_priv->gart_size);
+
+               temp = IGP_READ_MCIND(dev_priv, RS480_MC_MISC_CNTL);
+               if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)
+                       IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, (RS480_GART_INDEX_REG_EN |
+                                                            RS690_BLOCK_GFX_D3_EN));
+               else
+                       IGP_WRITE_MCIND(RS480_MC_MISC_CNTL, RS480_GART_INDEX_REG_EN);
+
+               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN |
+                                                              RS480_VA_SIZE_32MB));
+
+               temp = IGP_READ_MCIND(dev_priv, RS480_GART_FEATURE_ID);
+               IGP_WRITE_MCIND(RS480_GART_FEATURE_ID, (RS480_HANG_EN |
+                                                       RS480_TLB_ENABLE |
+                                                       RS480_GTW_LAC_EN |
+                                                       RS480_1LEVEL_GART));
+
+               temp = dev_priv->gart_info.bus_addr & 0xfffff000;
+               temp |= (upper_32_bits(dev_priv->gart_info.bus_addr) & 0xff) << 4;
+               IGP_WRITE_MCIND(RS480_GART_BASE, temp);
+
+               temp = IGP_READ_MCIND(dev_priv, RS480_AGP_MODE_CNTL);
+               IGP_WRITE_MCIND(RS480_AGP_MODE_CNTL, ((1 << RS480_REQ_TYPE_SNOOP_SHIFT) |
+                                                     RS480_REQ_TYPE_SNOOP_DIS));
+
+               radeon_write_agp_base(dev_priv, dev_priv->gart_vm_start);
+
+               dev_priv->gart_size = 32*1024*1024;
+               temp = (((dev_priv->gart_vm_start - 1 + dev_priv->gart_size) &
+                        0xffff0000) | (dev_priv->gart_vm_start >> 16));
+
+               radeon_write_agp_location(dev_priv, temp);
+
+               temp = IGP_READ_MCIND(dev_priv, RS480_AGP_ADDRESS_SPACE_SIZE);
+               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN |
+                                                              RS480_VA_SIZE_32MB));
+
+               do {
+                       temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL);
+                       if ((temp & RS480_GART_CACHE_INVALIDATE) == 0)
+                               break;
+                       DRM_UDELAY(1);
+               } while (1);
+
+               IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL,
+                               RS480_GART_CACHE_INVALIDATE);
+
+               do {
+                       temp = IGP_READ_MCIND(dev_priv, RS480_GART_CACHE_CNTRL);
+                       if ((temp & RS480_GART_CACHE_INVALIDATE) == 0)
+                               break;
+                       DRM_UDELAY(1);
+               } while (1);
+
+               IGP_WRITE_MCIND(RS480_GART_CACHE_CNTRL, 0);
+       } else {
+               IGP_WRITE_MCIND(RS480_AGP_ADDRESS_SPACE_SIZE, 0);
+       }
+}
+
+static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on)
+{
+       u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL);
+       if (on) {
+
+               DRM_DEBUG("programming pcie %08X %08lX %08X\n",
+                         dev_priv->gart_vm_start,
+                         (long)dev_priv->gart_info.bus_addr,
+                         dev_priv->gart_size);
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO,
+                                 dev_priv->gart_vm_start);
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE,
+                                 dev_priv->gart_info.bus_addr);
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO,
+                                 dev_priv->gart_vm_start);
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO,
+                                 dev_priv->gart_vm_start +
+                                 dev_priv->gart_size - 1);
+
+               radeon_write_agp_location(dev_priv, 0xffffffc0); /* ?? */
+
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
+                                 RADEON_PCIE_TX_GART_EN);
+       } else {
+               RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
+                                 tmp & ~RADEON_PCIE_TX_GART_EN);
+       }
+}
+
+/* Enable or disable PCI GART on the chip */
+static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
+{
+       u32 tmp;
+
+       if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690) ||
+           (dev_priv->flags & RADEON_IS_IGPGART)) {
+               radeon_set_igpgart(dev_priv, on);
+               return;
+       }
+
+       if (dev_priv->flags & RADEON_IS_PCIE) {
+               radeon_set_pciegart(dev_priv, on);
+               return;
+       }
+
+       tmp = RADEON_READ(RADEON_AIC_CNTL);
+
+       if (on) {
+               RADEON_WRITE(RADEON_AIC_CNTL,
+                            tmp | RADEON_PCIGART_TRANSLATE_EN);
+
+               /* set PCI GART page-table base address
+                */
+               RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr);
+
+               /* set address range for PCI address translate
+                */
+               RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start);
+               RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
+                            + dev_priv->gart_size - 1);
+
+               /* Turn off AGP aperture -- is this required for PCI GART?
+                */
+               radeon_write_agp_location(dev_priv, 0xffffffc0);
+               RADEON_WRITE(RADEON_AGP_COMMAND, 0);    /* clear AGP_COMMAND */
+       } else {
+               RADEON_WRITE(RADEON_AIC_CNTL,
+                            tmp & ~RADEON_PCIGART_TRANSLATE_EN);
+       }
+}
+
+static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+
+       /* if we require new memory map but we don't have it fail */
+       if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
+               DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
+               DRM_DEBUG("Forcing AGP card to PCI mode\n");
+               dev_priv->flags &= ~RADEON_IS_AGP;
+       } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
+                  && !init->is_pci) {
+               DRM_DEBUG("Restoring AGP flag\n");
+               dev_priv->flags |= RADEON_IS_AGP;
+       }
+
+       if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) {
+               DRM_ERROR("PCI GART memory not allocated!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->usec_timeout = init->usec_timeout;
+       if (dev_priv->usec_timeout < 1 ||
+           dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
+               DRM_DEBUG("TIMEOUT problem!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       /* Enable vblank on CRTC1 for older X servers
+        */
+       dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1;
+
+       switch(init->func) {
+       case RADEON_INIT_R200_CP:
+               dev_priv->microcode_version = UCODE_R200;
+               break;
+       case RADEON_INIT_R300_CP:
+               dev_priv->microcode_version = UCODE_R300;
+               break;
+       default:
+               dev_priv->microcode_version = UCODE_R100;
+       }
+
+       dev_priv->do_boxes = 0;
+       dev_priv->cp_mode = init->cp_mode;
+
+       /* We don't support anything other than bus-mastering ring mode,
+        * but the ring can be in either AGP or PCI space for the ring
+        * read pointer.
+        */
+       if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
+           (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
+               DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       switch (init->fb_bpp) {
+       case 16:
+               dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
+               break;
+       case 32:
+       default:
+               dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
+               break;
+       }
+       dev_priv->front_offset = init->front_offset;
+       dev_priv->front_pitch = init->front_pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->back_pitch = init->back_pitch;
+
+       switch (init->depth_bpp) {
+       case 16:
+               dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
+               break;
+       case 32:
+       default:
+               dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
+               break;
+       }
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->depth_pitch = init->depth_pitch;
+
+       /* Hardware state for depth clears.  Remove this if/when we no
+        * longer clear the depth buffer with a 3D rectangle.  Hard-code
+        * all values to prevent unwanted 3D state from slipping through
+        * and screwing with the clear operation.
+        */
+       dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
+                                          (dev_priv->color_fmt << 10) |
+                                          (dev_priv->microcode_version ==
+                                           UCODE_R100 ? RADEON_ZBLOCK16 : 0));
+
+       dev_priv->depth_clear.rb3d_zstencilcntl =
+           (dev_priv->depth_fmt |
+            RADEON_Z_TEST_ALWAYS |
+            RADEON_STENCIL_TEST_ALWAYS |
+            RADEON_STENCIL_S_FAIL_REPLACE |
+            RADEON_STENCIL_ZPASS_REPLACE |
+            RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE);
+
+       dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
+                                        RADEON_BFACE_SOLID |
+                                        RADEON_FFACE_SOLID |
+                                        RADEON_FLAT_SHADE_VTX_LAST |
+                                        RADEON_DIFFUSE_SHADE_FLAT |
+                                        RADEON_ALPHA_SHADE_FLAT |
+                                        RADEON_SPECULAR_SHADE_FLAT |
+                                        RADEON_FOG_SHADE_FLAT |
+                                        RADEON_VTX_PIX_CENTER_OGL |
+                                        RADEON_ROUND_MODE_TRUNC |
+                                        RADEON_ROUND_PREC_8TH_PIX);
+
+
+       dev_priv->ring_offset = init->ring_offset;
+       dev_priv->ring_rptr_offset = init->ring_rptr_offset;
+       dev_priv->buffers_offset = init->buffers_offset;
+       dev_priv->gart_textures_offset = init->gart_textures_offset;
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("could not find sarea!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
+       if (!dev_priv->cp_ring) {
+               DRM_ERROR("could not find cp ring region!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+       dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
+       if (!dev_priv->ring_rptr) {
+               DRM_ERROR("could not find ring read pointer!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+       dev->agp_buffer_token = init->buffers_offset;
+       dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
+       if (!dev->agp_buffer_map) {
+               DRM_ERROR("could not find dma buffer region!\n");
+               radeon_do_cleanup_cp(dev);
+               return -EINVAL;
+       }
+
+       if (init->gart_textures_offset) {
+               dev_priv->gart_textures =
+                   drm_core_findmap(dev, init->gart_textures_offset);
+               if (!dev_priv->gart_textures) {
+                       DRM_ERROR("could not find GART texture region!\n");
+                       radeon_do_cleanup_cp(dev);
+                       return -EINVAL;
+               }
+       }
+
+       dev_priv->sarea_priv =
+           (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle +
+                                   init->sarea_priv_offset);
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               drm_core_ioremap(dev_priv->cp_ring, dev);
+               drm_core_ioremap(dev_priv->ring_rptr, dev);
+               drm_core_ioremap(dev->agp_buffer_map, dev);
+               if (!dev_priv->cp_ring->handle ||
+                   !dev_priv->ring_rptr->handle ||
+                   !dev->agp_buffer_map->handle) {
+                       DRM_ERROR("could not find ioremap agp regions!\n");
+                       radeon_do_cleanup_cp(dev);
+                       return -EINVAL;
+               }
+       } else
+#endif
+       {
+               dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset;
+               dev_priv->ring_rptr->handle =
+                   (void *)dev_priv->ring_rptr->offset;
+               dev->agp_buffer_map->handle =
+                   (void *)dev->agp_buffer_map->offset;
+
+               DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
+                         dev_priv->cp_ring->handle);
+               DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
+                         dev_priv->ring_rptr->handle);
+               DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
+                         dev->agp_buffer_map->handle);
+       }
+
+       dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 16;
+       dev_priv->fb_size =
+               ((radeon_read_fb_location(dev_priv) & 0xffff0000u) + 0x10000)
+               - dev_priv->fb_location;
+
+       dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
+                                       ((dev_priv->front_offset
+                                         + dev_priv->fb_location) >> 10));
+
+       dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
+                                      ((dev_priv->back_offset
+                                        + dev_priv->fb_location) >> 10));
+
+       dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
+                                       ((dev_priv->depth_offset
+                                         + dev_priv->fb_location) >> 10));
+
+       dev_priv->gart_size = init->gart_size;
+
+       /* New let's set the memory map ... */
+       if (dev_priv->new_memmap) {
+               u32 base = 0;
+
+               DRM_INFO("Setting GART location based on new memory map\n");
+
+               /* If using AGP, try to locate the AGP aperture at the same
+                * location in the card and on the bus, though we have to
+                * align it down.
+                */
+#if __OS_HAS_AGP
+               if (dev_priv->flags & RADEON_IS_AGP) {
+                       base = dev->agp->base;
+                       /* Check if valid */
+                       if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location &&
+                           base < (dev_priv->fb_location + dev_priv->fb_size - 1)) {
+                               DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
+                                        dev->agp->base);
+                               base = 0;
+                       }
+               }
+#endif
+               /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
+               if (base == 0) {
+                       base = dev_priv->fb_location + dev_priv->fb_size;
+                       if (base < dev_priv->fb_location ||
+                           ((base + dev_priv->gart_size) & 0xfffffffful) < base)
+                               base = dev_priv->fb_location
+                                       - dev_priv->gart_size;
+               }
+               dev_priv->gart_vm_start = base & 0xffc00000u;
+               if (dev_priv->gart_vm_start != base)
+                       DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
+                                base, dev_priv->gart_vm_start);
+       } else {
+               DRM_INFO("Setting GART location based on old memory map\n");
+               dev_priv->gart_vm_start = dev_priv->fb_location +
+                       RADEON_READ(RADEON_CONFIG_APER_SIZE);
+       }
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP)
+               dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
+                                                - dev->agp->base
+                                                + dev_priv->gart_vm_start);
+       else
+#endif
+               dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
+                                       - (unsigned long)dev->sg->virtual
+                                       + dev_priv->gart_vm_start);
+
+       DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
+       DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start);
+       DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n",
+                 dev_priv->gart_buffers_offset);
+
+       dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
+       dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
+                             + init->ring_size / sizeof(u32));
+       dev_priv->ring.size = init->ring_size;
+       dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
+
+       dev_priv->ring.rptr_update = /* init->rptr_update */ 4096;
+       dev_priv->ring.rptr_update_l2qw = drm_order( /* init->rptr_update */ 4096 / 8);
+
+       dev_priv->ring.fetch_size = /* init->fetch_size */ 32;
+       dev_priv->ring.fetch_size_l2ow = drm_order( /* init->fetch_size */ 32 / 16);
+       dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
+
+       dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               /* Turn off PCI GART */
+               radeon_set_pcigart(dev_priv, 0);
+       } else
+#endif
+       {
+               dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
+               /* if we have an offset set from userspace */
+               if (dev_priv->pcigart_offset_set) {
+                       dev_priv->gart_info.bus_addr =
+                           dev_priv->pcigart_offset + dev_priv->fb_location;
+                       dev_priv->gart_info.mapping.offset =
+                           dev_priv->pcigart_offset + dev_priv->fb_aper_offset;
+                       dev_priv->gart_info.mapping.size =
+                           dev_priv->gart_info.table_size;
+
+                       drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
+                       dev_priv->gart_info.addr =
+                           dev_priv->gart_info.mapping.handle;
+
+                       if (dev_priv->flags & RADEON_IS_PCIE)
+                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE;
+                       else
+                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
+                       dev_priv->gart_info.gart_table_location =
+                           DRM_ATI_GART_FB;
+
+                       DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
+                                 dev_priv->gart_info.addr,
+                                 dev_priv->pcigart_offset);
+               } else {
+                       if (dev_priv->flags & RADEON_IS_IGPGART)
+                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP;
+                       else
+                               dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
+                       dev_priv->gart_info.gart_table_location =
+                           DRM_ATI_GART_MAIN;
+                       dev_priv->gart_info.addr = NULL;
+                       dev_priv->gart_info.bus_addr = 0;
+                       if (dev_priv->flags & RADEON_IS_PCIE) {
+                               DRM_ERROR
+                                   ("Cannot use PCI Express without GART in FB memory\n");
+                               radeon_do_cleanup_cp(dev);
+                               return -EINVAL;
+                       }
+               }
+
+               if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
+                       DRM_ERROR("failed to init PCI GART!\n");
+                       radeon_do_cleanup_cp(dev);
+                       return -ENOMEM;
+               }
+
+               /* Turn on PCI GART */
+               radeon_set_pcigart(dev_priv, 1);
+       }
+
+       radeon_cp_load_microcode(dev_priv);
+       radeon_cp_init_ring_buffer(dev, dev_priv);
+
+       dev_priv->last_buf = 0;
+
+       radeon_do_engine_reset(dev);
+       radeon_test_writeback(dev_priv);
+
+       return 0;
+}
+
+static int radeon_do_cleanup_cp(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       /* Make sure interrupts are disabled here because the uninstall ioctl
+        * may not have been called from userspace and after dev_private
+        * is freed, it's too late.
+        */
+       if (dev->irq_enabled)
+               drm_irq_uninstall(dev);
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               if (dev_priv->cp_ring != NULL) {
+                       drm_core_ioremapfree(dev_priv->cp_ring, dev);
+                       dev_priv->cp_ring = NULL;
+               }
+               if (dev_priv->ring_rptr != NULL) {
+                       drm_core_ioremapfree(dev_priv->ring_rptr, dev);
+                       dev_priv->ring_rptr = NULL;
+               }
+               if (dev->agp_buffer_map != NULL) {
+                       drm_core_ioremapfree(dev->agp_buffer_map, dev);
+                       dev->agp_buffer_map = NULL;
+               }
+       } else
+#endif
+       {
+
+               if (dev_priv->gart_info.bus_addr) {
+                       /* Turn off PCI GART */
+                       radeon_set_pcigart(dev_priv, 0);
+                       if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info))
+                               DRM_ERROR("failed to cleanup PCI GART!\n");
+               }
+
+               if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
+               {
+                       drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
+                       dev_priv->gart_info.addr = 0;
+               }
+       }
+       /* only clear to the start of flags */
+       memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
+
+       return 0;
+}
+
+/* This code will reinit the Radeon CP hardware after a resume from disc.
+ * AFAIK, it would be very difficult to pickle the state at suspend time, so
+ * here we make sure that all Radeon hardware initialisation is re-done without
+ * affecting running applications.
+ *
+ * Charl P. Botha <http://cpbotha.net>
+ */
+static int radeon_do_resume_cp(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       if (!dev_priv) {
+               DRM_ERROR("Called with no initialization\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("Starting radeon_do_resume_cp()\n");
+
+#if __OS_HAS_AGP
+       if (dev_priv->flags & RADEON_IS_AGP) {
+               /* Turn off PCI GART */
+               radeon_set_pcigart(dev_priv, 0);
+       } else
+#endif
+       {
+               /* Turn on PCI GART */
+               radeon_set_pcigart(dev_priv, 1);
+       }
+
+       radeon_cp_load_microcode(dev_priv);
+       radeon_cp_init_ring_buffer(dev, dev_priv);
+
+       radeon_do_engine_reset(dev);
+       radeon_enable_interrupt(dev);
+
+       DRM_DEBUG("radeon_do_resume_cp() complete\n");
+
+       return 0;
+}
+
+int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_init_t *init = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (init->func == RADEON_INIT_R300_CP)
+               r300_init_reg_flags(dev);
+
+       switch (init->func) {
+       case RADEON_INIT_CP:
+       case RADEON_INIT_R200_CP:
+       case RADEON_INIT_R300_CP:
+               return radeon_do_init_cp(dev, init);
+       case RADEON_CLEANUP_CP:
+               return radeon_do_cleanup_cp(dev);
+       }
+
+       return -EINVAL;
+}
+
+int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (dev_priv->cp_running) {
+               DRM_DEBUG("while CP running\n");
+               return 0;
+       }
+       if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) {
+               DRM_DEBUG("called with bogus CP mode (%d)\n",
+                         dev_priv->cp_mode);
+               return 0;
+       }
+
+       radeon_do_cp_start(dev_priv);
+
+       return 0;
+}
+
+/* Stop the CP.  The engine must have been idled before calling this
+ * routine.
+ */
+int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_cp_stop_t *stop = data;
+       int ret;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv->cp_running)
+               return 0;
+
+       /* Flush any pending CP commands.  This ensures any outstanding
+        * commands are exectuted by the engine before we turn it off.
+        */
+       if (stop->flush) {
+               radeon_do_cp_flush(dev_priv);
+       }
+
+       /* If we fail to make the engine go idle, we return an error
+        * code so that the DRM ioctl wrapper can try again.
+        */
+       if (stop->idle) {
+               ret = radeon_do_cp_idle(dev_priv);
+               if (ret)
+                       return ret;
+       }
+
+       /* Finally, we can turn off the CP.  If the engine isn't idle,
+        * we will get some dropped triangles as they won't be fully
+        * rendered before the CP is shut down.
+        */
+       radeon_do_cp_stop(dev_priv);
+
+       /* Reset the engine */
+       radeon_do_engine_reset(dev);
+
+       return 0;
+}
+
+void radeon_do_release(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       int i, ret;
+
+       if (dev_priv) {
+               if (dev_priv->cp_running) {
+                       /* Stop the cp */
+                       while ((ret = radeon_do_cp_idle(dev_priv)) != 0) {
+                               DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
+#ifdef __linux__
+                               schedule();
+#else
+                               tsleep(&ret, PZERO, "rdnrel", 1);
+#endif
+                       }
+                       radeon_do_cp_stop(dev_priv);
+                       radeon_do_engine_reset(dev);
+               }
+
+               /* Disable *all* interrupts */
+               if (dev_priv->mmio)     /* remove this after permanent addmaps */
+                       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
+
+               if (dev_priv->mmio) {   /* remove all surfaces */
+                       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
+                               RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0);
+                               RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND +
+                                            16 * i, 0);
+                               RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND +
+                                            16 * i, 0);
+                       }
+               }
+
+               /* Free memory heap structures */
+               radeon_mem_takedown(&(dev_priv->gart_heap));
+               radeon_mem_takedown(&(dev_priv->fb_heap));
+
+               /* deallocate kernel resources */
+               radeon_do_cleanup_cp(dev);
+       }
+}
+
+/* Just reset the CP ring.  Called as part of an X Server engine reset.
+ */
+int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_DEBUG("called before init done\n");
+               return -EINVAL;
+       }
+
+       radeon_do_cp_reset(dev_priv);
+
+       /* The CP is no longer running after an engine reset */
+       dev_priv->cp_running = 0;
+
+       return 0;
+}
+
+int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return radeon_do_cp_idle(dev_priv);
+}
+
+/* Added by Charl P. Botha to call radeon_do_resume_cp().
+ */
+int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+
+       return radeon_do_resume_cp(dev);
+}
+
+int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return radeon_do_engine_reset(dev);
+}
+
+/* ================================================================
+ * Fullscreen mode
+ */
+
+/* KW: Deprecated to say the least:
+ */
+int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       return 0;
+}
+
+/* ================================================================
+ * Freelist management
+ */
+
+/* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
+ *   bufs until freelist code is used.  Note this hides a problem with
+ *   the scratch register * (used to keep track of last buffer
+ *   completed) being written to before * the last buffer has actually
+ *   completed rendering.
+ *
+ * KW:  It's also a good way to find free buffers quickly.
+ *
+ * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
+ * sleep.  However, bugs in older versions of radeon_accel.c mean that
+ * we essentially have to do this, else old clients will break.
+ *
+ * However, it does leave open a potential deadlock where all the
+ * buffers are held by other clients, which can't release them because
+ * they can't get the lock.
+ */
+
+struct drm_buf *radeon_freelist_get(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_buf_priv_t *buf_priv;
+       struct drm_buf *buf;
+       int i, t;
+       int start;
+
+       if (++dev_priv->last_buf >= dma->buf_count)
+               dev_priv->last_buf = 0;
+
+       start = dev_priv->last_buf;
+
+       for (t = 0; t < dev_priv->usec_timeout; t++) {
+               u32 done_age = GET_SCRATCH(1);
+               DRM_DEBUG("done_age = %d\n", done_age);
+               for (i = start; i < dma->buf_count; i++) {
+                       buf = dma->buflist[i];
+                       buf_priv = buf->dev_private;
+                       if (buf->file_priv == NULL || (buf->pending &&
+                                                      buf_priv->age <=
+                                                      done_age)) {
+                               dev_priv->stats.requested_bufs++;
+                               buf->pending = 0;
+                               return buf;
+                       }
+                       start = 0;
+               }
+
+               if (t) {
+                       DRM_UDELAY(1);
+                       dev_priv->stats.freelist_loops++;
+               }
+       }
+
+       DRM_DEBUG("returning NULL!\n");
+       return NULL;
+}
+
+#if 0
+struct drm_buf *radeon_freelist_get(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_buf_priv_t *buf_priv;
+       struct drm_buf *buf;
+       int i, t;
+       int start;
+       u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
+
+       if (++dev_priv->last_buf >= dma->buf_count)
+               dev_priv->last_buf = 0;
+
+       start = dev_priv->last_buf;
+       dev_priv->stats.freelist_loops++;
+
+       for (t = 0; t < 2; t++) {
+               for (i = start; i < dma->buf_count; i++) {
+                       buf = dma->buflist[i];
+                       buf_priv = buf->dev_private;
+                       if (buf->file_priv == 0 || (buf->pending &&
+                                                   buf_priv->age <=
+                                                   done_age)) {
+                               dev_priv->stats.requested_bufs++;
+                               buf->pending = 0;
+                               return buf;
+                       }
+               }
+               start = 0;
+       }
+
+       return NULL;
+}
+#endif
+
+void radeon_freelist_reset(struct drm_device * dev)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       int i;
+
+       dev_priv->last_buf = 0;
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
+               buf_priv->age = 0;
+       }
+}
+
+/* ================================================================
+ * CP command submission
+ */
+
+int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n)
+{
+       drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
+       int i;
+       u32 last_head = GET_RING_HEAD(dev_priv);
+
+       for (i = 0; i < dev_priv->usec_timeout; i++) {
+               u32 head = GET_RING_HEAD(dev_priv);
+
+               ring->space = (head - ring->tail) * sizeof(u32);
+               if (ring->space <= 0)
+                       ring->space += ring->size;
+               if (ring->space > n)
+                       return 0;
+
+               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+               if (head != last_head)
+                       i = 0;
+               last_head = head;
+
+               DRM_UDELAY(1);
+       }
+
+       /* FIXME: This return value is ignored in the BEGIN_RING macro! */
+#if RADEON_FIFO_DEBUG
+       radeon_status(dev_priv);
+       DRM_ERROR("failed!\n");
+#endif
+       return -EBUSY;
+}
+
+static int radeon_cp_get_buffers(struct drm_device *dev,
+                                struct drm_file *file_priv,
+                                struct drm_dma * d)
+{
+       int i;
+       struct drm_buf *buf;
+
+       for (i = d->granted_count; i < d->request_count; i++) {
+               buf = radeon_freelist_get(dev);
+               if (!buf)
+                       return -EBUSY;  /* NOTE: broken client */
+
+               buf->file_priv = file_priv;
+
+               if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
+                                    sizeof(buf->idx)))
+                       return -EFAULT;
+               if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
+                                    sizeof(buf->total)))
+                       return -EFAULT;
+
+               d->granted_count++;
+       }
+       return 0;
+}
+
+int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       int ret = 0;
+       struct drm_dma *d = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* Please don't send us buffers.
+        */
+       if (d->send_count != 0) {
+               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
+                         DRM_CURRENTPID, d->send_count);
+               return -EINVAL;
+       }
+
+       /* We'll send you buffers.
+        */
+       if (d->request_count < 0 || d->request_count > dma->buf_count) {
+               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
+                         DRM_CURRENTPID, d->request_count, dma->buf_count);
+               return -EINVAL;
+       }
+
+       d->granted_count = 0;
+
+       if (d->request_count) {
+               ret = radeon_cp_get_buffers(dev, file_priv, d);
+       }
+
+       return ret;
+}
+
+int radeon_driver_load(struct drm_device *dev, unsigned long flags)
+{
+       drm_radeon_private_t *dev_priv;
+       int ret = 0;
+
+       dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv, 0, sizeof(drm_radeon_private_t));
+       dev->dev_private = (void *)dev_priv;
+       dev_priv->flags = flags;
+
+       switch (flags & RADEON_FAMILY_MASK) {
+       case CHIP_R100:
+       case CHIP_RV200:
+       case CHIP_R200:
+       case CHIP_R300:
+       case CHIP_R350:
+       case CHIP_R420:
+       case CHIP_RV410:
+       case CHIP_RV515:
+       case CHIP_R520:
+       case CHIP_RV570:
+       case CHIP_R580:
+               dev_priv->flags |= RADEON_HAS_HIERZ;
+               break;
+       default:
+               /* all other chips have no hierarchical z buffer */
+               break;
+       }
+
+       if (drm_device_is_agp(dev))
+               dev_priv->flags |= RADEON_IS_AGP;
+       else if (drm_device_is_pcie(dev))
+               dev_priv->flags |= RADEON_IS_PCIE;
+       else
+               dev_priv->flags |= RADEON_IS_PCI;
+
+       DRM_DEBUG("%s card detected\n",
+                 ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI"))));
+       return ret;
+}
+
+/* Create mappings for registers and framebuffer so userland doesn't necessarily
+ * have to find them.
+ */
+int radeon_driver_firstopen(struct drm_device *dev)
+{
+       int ret;
+       drm_local_map_t *map;
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
+
+       ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
+                        drm_get_resource_len(dev, 2), _DRM_REGISTERS,
+                        _DRM_READ_ONLY, &dev_priv->mmio);
+       if (ret != 0)
+               return ret;
+
+       dev_priv->fb_aper_offset = drm_get_resource_start(dev, 0);
+       ret = drm_addmap(dev, dev_priv->fb_aper_offset,
+                        drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
+                        _DRM_WRITE_COMBINING, &map);
+       if (ret != 0)
+               return ret;
+
+       return 0;
+}
+
+int radeon_driver_unload(struct drm_device *dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+       drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
+
+       dev->dev_private = NULL;
+       return 0;
+}
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
new file mode 100644 (file)
index 0000000..349ac3d
--- /dev/null
@@ -0,0 +1,126 @@
+/**
+ * \file radeon_drv.c
+ * ATI Radeon driver
+ *
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+
+#include "drm_pciids.h"
+
+int radeon_no_wb;
+
+MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n");
+module_param_named(no_wb, radeon_no_wb, int, 0444);
+
+static int dri_library_name(struct drm_device *dev, char *buf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       int family = dev_priv->flags & RADEON_FAMILY_MASK;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n",
+                       (family < CHIP_R200) ? "radeon" :
+                       ((family < CHIP_R300) ? "r200" :
+                       "r300"));
+}
+
+static struct pci_device_id pciidlist[] = {
+       radeon_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
+           DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED |
+           DRIVER_IRQ_VBL | DRIVER_IRQ_VBL2,
+       .dev_priv_size = sizeof(drm_radeon_buf_priv_t),
+       .load = radeon_driver_load,
+       .firstopen = radeon_driver_firstopen,
+       .open = radeon_driver_open,
+       .preclose = radeon_driver_preclose,
+       .postclose = radeon_driver_postclose,
+       .lastclose = radeon_driver_lastclose,
+       .unload = radeon_driver_unload,
+       .vblank_wait = radeon_driver_vblank_wait,
+       .vblank_wait2 = radeon_driver_vblank_wait2,
+       .dri_library_name = dri_library_name,
+       .irq_preinstall = radeon_driver_irq_preinstall,
+       .irq_postinstall = radeon_driver_irq_postinstall,
+       .irq_uninstall = radeon_driver_irq_uninstall,
+       .irq_handler = radeon_driver_irq_handler,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = radeon_ioctls,
+       .dma_ioctl = radeon_cp_buffers,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+                .compat_ioctl = radeon_compat_ioctl,
+#endif
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init radeon_init(void)
+{
+       driver.num_ioctls = radeon_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit radeon_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(radeon_init);
+module_exit(radeon_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
new file mode 100644 (file)
index 0000000..3f0eca9
--- /dev/null
@@ -0,0 +1,1406 @@
+/* radeon_drv.h -- Private header for radeon driver -*- linux-c -*-
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Kevin E. Martin <martin@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#ifndef __RADEON_DRV_H__
+#define __RADEON_DRV_H__
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "Gareth Hughes, Keith Whitwell, others."
+
+#define DRIVER_NAME            "radeon"
+#define DRIVER_DESC            "ATI Radeon"
+#define DRIVER_DATE            "20080528"
+
+/* Interface history:
+ *
+ * 1.1 - ??
+ * 1.2 - Add vertex2 ioctl (keith)
+ *     - Add stencil capability to clear ioctl (gareth, keith)
+ *     - Increase MAX_TEXTURE_LEVELS (brian)
+ * 1.3 - Add cmdbuf ioctl (keith)
+ *     - Add support for new radeon packets (keith)
+ *     - Add getparam ioctl (keith)
+ *     - Add flip-buffers ioctl, deprecate fullscreen foo (keith).
+ * 1.4 - Add scratch registers to get_param ioctl.
+ * 1.5 - Add r200 packets to cmdbuf ioctl
+ *     - Add r200 function to init ioctl
+ *     - Add 'scalar2' instruction to cmdbuf
+ * 1.6 - Add static GART memory manager
+ *       Add irq handler (won't be turned on unless X server knows to)
+ *       Add irq ioctls and irq_active getparam.
+ *       Add wait command for cmdbuf ioctl
+ *       Add GART offset query for getparam
+ * 1.7 - Add support for cube map registers: R200_PP_CUBIC_FACES_[0..5]
+ *       and R200_PP_CUBIC_OFFSET_F1_[0..5].
+ *       Added packets R200_EMIT_PP_CUBIC_FACES_[0..5] and
+ *       R200_EMIT_PP_CUBIC_OFFSETS_[0..5].  (brian)
+ * 1.8 - Remove need to call cleanup ioctls on last client exit (keith)
+ *       Add 'GET' queries for starting additional clients on different VT's.
+ * 1.9 - Add DRM_IOCTL_RADEON_CP_RESUME ioctl.
+ *       Add texture rectangle support for r100.
+ * 1.10- Add SETPARAM ioctl; first parameter to set is FB_LOCATION, which
+ *       clients use to tell the DRM where they think the framebuffer is
+ *       located in the card's address space
+ * 1.11- Add packet R200_EMIT_RB3D_BLENDCOLOR to support GL_EXT_blend_color
+ *       and GL_EXT_blend_[func|equation]_separate on r200
+ * 1.12- Add R300 CP microcode support - this just loads the CP on r300
+ *       (No 3D support yet - just microcode loading).
+ * 1.13- Add packet R200_EMIT_TCL_POINT_SPRITE_CNTL for ARB_point_parameters
+ *     - Add hyperz support, add hyperz flags to clear ioctl.
+ * 1.14- Add support for color tiling
+ *     - Add R100/R200 surface allocation/free support
+ * 1.15- Add support for texture micro tiling
+ *     - Add support for r100 cube maps
+ * 1.16- Add R200_EMIT_PP_TRI_PERF_CNTL packet to support brilinear
+ *       texture filtering on r200
+ * 1.17- Add initial support for R300 (3D).
+ * 1.18- Add support for GL_ATI_fragment_shader, new packets
+ *       R200_EMIT_PP_AFS_0/1, R200_EMIT_PP_TXCTLALL_0-5 (replaces
+ *       R200_EMIT_PP_TXFILTER_0-5, 2 more regs) and R200_EMIT_ATF_TFACTOR
+ *       (replaces R200_EMIT_TFACTOR_0 (8 consts instead of 6)
+ * 1.19- Add support for gart table in FB memory and PCIE r300
+ * 1.20- Add support for r300 texrect
+ * 1.21- Add support for card type getparam
+ * 1.22- Add support for texture cache flushes (R300_TX_CNTL)
+ * 1.23- Add new radeon memory map work from benh
+ * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
+ * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL,
+ *       new packet type)
+ * 1.26- Add support for variable size PCI(E) gart aperture
+ * 1.27- Add support for IGP GART
+ * 1.28- Add support for VBL on CRTC2
+ * 1.29- R500 3D cmd buffer support
+ */
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           29
+#define DRIVER_PATCHLEVEL      0
+
+/*
+ * Radeon chip families
+ */
+enum radeon_family {
+       CHIP_R100,
+       CHIP_RV100,
+       CHIP_RS100,
+       CHIP_RV200,
+       CHIP_RS200,
+       CHIP_R200,
+       CHIP_RV250,
+       CHIP_RS300,
+       CHIP_RV280,
+       CHIP_R300,
+       CHIP_R350,
+       CHIP_RV350,
+       CHIP_RV380,
+       CHIP_R420,
+       CHIP_RV410,
+       CHIP_RS480,
+       CHIP_RS690,
+       CHIP_RV515,
+       CHIP_R520,
+       CHIP_RV530,
+       CHIP_RV560,
+       CHIP_RV570,
+       CHIP_R580,
+       CHIP_LAST,
+};
+
+enum radeon_cp_microcode_version {
+       UCODE_R100,
+       UCODE_R200,
+       UCODE_R300,
+};
+
+/*
+ * Chip flags
+ */
+enum radeon_chip_flags {
+       RADEON_FAMILY_MASK = 0x0000ffffUL,
+       RADEON_FLAGS_MASK = 0xffff0000UL,
+       RADEON_IS_MOBILITY = 0x00010000UL,
+       RADEON_IS_IGP = 0x00020000UL,
+       RADEON_SINGLE_CRTC = 0x00040000UL,
+       RADEON_IS_AGP = 0x00080000UL,
+       RADEON_HAS_HIERZ = 0x00100000UL,
+       RADEON_IS_PCIE = 0x00200000UL,
+       RADEON_NEW_MEMMAP = 0x00400000UL,
+       RADEON_IS_PCI = 0x00800000UL,
+       RADEON_IS_IGPGART = 0x01000000UL,
+};
+
+#define GET_RING_HEAD(dev_priv)        (dev_priv->writeback_works ? \
+        DRM_READ32(  (dev_priv)->ring_rptr, 0 ) : RADEON_READ(RADEON_CP_RB_RPTR))
+#define SET_RING_HEAD(dev_priv,val)    DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) )
+
+typedef struct drm_radeon_freelist {
+       unsigned int age;
+       struct drm_buf *buf;
+       struct drm_radeon_freelist *next;
+       struct drm_radeon_freelist *prev;
+} drm_radeon_freelist_t;
+
+typedef struct drm_radeon_ring_buffer {
+       u32 *start;
+       u32 *end;
+       int size;
+       int size_l2qw;
+
+       int rptr_update; /* Double Words */
+       int rptr_update_l2qw; /* log2 Quad Words */
+
+       int fetch_size; /* Double Words */
+       int fetch_size_l2ow; /* log2 Oct Words */
+
+       u32 tail;
+       u32 tail_mask;
+       int space;
+
+       int high_mark;
+} drm_radeon_ring_buffer_t;
+
+typedef struct drm_radeon_depth_clear_t {
+       u32 rb3d_cntl;
+       u32 rb3d_zstencilcntl;
+       u32 se_cntl;
+} drm_radeon_depth_clear_t;
+
+struct drm_radeon_driver_file_fields {
+       int64_t radeon_fb_delta;
+};
+
+struct mem_block {
+       struct mem_block *next;
+       struct mem_block *prev;
+       int start;
+       int size;
+       struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
+};
+
+struct radeon_surface {
+       int refcount;
+       u32 lower;
+       u32 upper;
+       u32 flags;
+};
+
+struct radeon_virt_surface {
+       int surface_index;
+       u32 lower;
+       u32 upper;
+       u32 flags;
+       struct drm_file *file_priv;
+};
+
+typedef struct drm_radeon_private {
+       drm_radeon_ring_buffer_t ring;
+       drm_radeon_sarea_t *sarea_priv;
+
+       u32 fb_location;
+       u32 fb_size;
+       int new_memmap;
+
+       int gart_size;
+       u32 gart_vm_start;
+       unsigned long gart_buffers_offset;
+
+       int cp_mode;
+       int cp_running;
+
+       drm_radeon_freelist_t *head;
+       drm_radeon_freelist_t *tail;
+       int last_buf;
+       volatile u32 *scratch;
+       int writeback_works;
+
+       int usec_timeout;
+
+       int microcode_version;
+
+       struct {
+               u32 boxes;
+               int freelist_timeouts;
+               int freelist_loops;
+               int requested_bufs;
+               int last_frame_reads;
+               int last_clear_reads;
+               int clears;
+               int texture_uploads;
+       } stats;
+
+       int do_boxes;
+       int page_flipping;
+
+       u32 color_fmt;
+       unsigned int front_offset;
+       unsigned int front_pitch;
+       unsigned int back_offset;
+       unsigned int back_pitch;
+
+       u32 depth_fmt;
+       unsigned int depth_offset;
+       unsigned int depth_pitch;
+
+       u32 front_pitch_offset;
+       u32 back_pitch_offset;
+       u32 depth_pitch_offset;
+
+       drm_radeon_depth_clear_t depth_clear;
+
+       unsigned long ring_offset;
+       unsigned long ring_rptr_offset;
+       unsigned long buffers_offset;
+       unsigned long gart_textures_offset;
+
+       drm_local_map_t *sarea;
+       drm_local_map_t *mmio;
+       drm_local_map_t *cp_ring;
+       drm_local_map_t *ring_rptr;
+       drm_local_map_t *gart_textures;
+
+       struct mem_block *gart_heap;
+       struct mem_block *fb_heap;
+
+       /* SW interrupt */
+       wait_queue_head_t swi_queue;
+       atomic_t swi_emitted;
+       int vblank_crtc;
+       uint32_t irq_enable_reg;
+       int irq_enabled;
+       uint32_t r500_disp_irq_reg;
+
+       struct radeon_surface surfaces[RADEON_MAX_SURFACES];
+       struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES];
+
+       unsigned long pcigart_offset;
+       unsigned int pcigart_offset_set;
+       struct drm_ati_pcigart_info gart_info;
+
+       u32 scratch_ages[5];
+
+       /* starting from here on, data is preserved accross an open */
+       uint32_t flags;         /* see radeon_chip_flags */
+       unsigned long fb_aper_offset;
+
+       int num_gb_pipes;
+} drm_radeon_private_t;
+
+typedef struct drm_radeon_buf_priv {
+       u32 age;
+} drm_radeon_buf_priv_t;
+
+typedef struct drm_radeon_kcmd_buffer {
+       int bufsz;
+       char *buf;
+       int nbox;
+       struct drm_clip_rect __user *boxes;
+} drm_radeon_kcmd_buffer_t;
+
+extern int radeon_no_wb;
+extern struct drm_ioctl_desc radeon_ioctls[];
+extern int radeon_max_ioctl;
+
+/* Check whether the given hardware address is inside the framebuffer or the
+ * GART area.
+ */
+static __inline__ int radeon_check_offset(drm_radeon_private_t *dev_priv,
+                                         u64 off)
+{
+       u32 fb_start = dev_priv->fb_location;
+       u32 fb_end = fb_start + dev_priv->fb_size - 1;
+       u32 gart_start = dev_priv->gart_vm_start;
+       u32 gart_end = gart_start + dev_priv->gart_size - 1;
+
+       return ((off >= fb_start && off <= fb_end) ||
+               (off >= gart_start && off <= gart_end));
+}
+
+                               /* radeon_cp.c */
+extern int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv);
+
+extern void radeon_freelist_reset(struct drm_device * dev);
+extern struct drm_buf *radeon_freelist_get(struct drm_device * dev);
+
+extern int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n);
+
+extern int radeon_do_cp_idle(drm_radeon_private_t * dev_priv);
+
+extern int radeon_driver_preinit(struct drm_device *dev, unsigned long flags);
+extern int radeon_presetup(struct drm_device *dev);
+extern int radeon_driver_postcleanup(struct drm_device *dev);
+
+extern int radeon_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern void radeon_mem_takedown(struct mem_block **heap);
+extern void radeon_mem_release(struct drm_file *file_priv,
+                              struct mem_block *heap);
+
+                               /* radeon_irq.c */
+extern int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv);
+
+extern void radeon_do_release(struct drm_device * dev);
+extern int radeon_driver_vblank_wait(struct drm_device * dev,
+                                    unsigned int *sequence);
+extern int radeon_driver_vblank_wait2(struct drm_device * dev,
+                                     unsigned int *sequence);
+extern irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS);
+extern void radeon_driver_irq_preinstall(struct drm_device * dev);
+extern void radeon_driver_irq_postinstall(struct drm_device * dev);
+extern void radeon_driver_irq_uninstall(struct drm_device * dev);
+extern void radeon_enable_interrupt(struct drm_device *dev);
+extern int radeon_vblank_crtc_get(struct drm_device *dev);
+extern int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value);
+
+extern int radeon_driver_load(struct drm_device *dev, unsigned long flags);
+extern int radeon_driver_unload(struct drm_device *dev);
+extern int radeon_driver_firstopen(struct drm_device *dev);
+extern void radeon_driver_preclose(struct drm_device * dev, struct drm_file *file_priv);
+extern void radeon_driver_postclose(struct drm_device * dev, struct drm_file * filp);
+extern void radeon_driver_lastclose(struct drm_device * dev);
+extern int radeon_driver_open(struct drm_device * dev, struct drm_file * filp_priv);
+extern long radeon_compat_ioctl(struct file *filp, unsigned int cmd,
+                               unsigned long arg);
+
+/* r300_cmdbuf.c */
+extern void r300_init_reg_flags(struct drm_device *dev);
+
+extern int r300_do_cp_cmdbuf(struct drm_device * dev,
+                            struct drm_file *file_priv,
+                            drm_radeon_kcmd_buffer_t * cmdbuf);
+
+/* Flags for stats.boxes
+ */
+#define RADEON_BOX_DMA_IDLE      0x1
+#define RADEON_BOX_RING_FULL     0x2
+#define RADEON_BOX_FLIP          0x4
+#define RADEON_BOX_WAIT_IDLE     0x8
+#define RADEON_BOX_TEXTURE_LOAD  0x10
+
+/* Register definitions, register access macros and drmAddMap constants
+ * for Radeon kernel driver.
+ */
+
+#define RADEON_AGP_COMMAND             0x0f60
+#define RADEON_AGP_COMMAND_PCI_CONFIG   0x0060 /* offset in PCI config */
+#      define RADEON_AGP_ENABLE        (1<<8)
+#define RADEON_AUX_SCISSOR_CNTL                0x26f0
+#      define RADEON_EXCLUSIVE_SCISSOR_0       (1 << 24)
+#      define RADEON_EXCLUSIVE_SCISSOR_1       (1 << 25)
+#      define RADEON_EXCLUSIVE_SCISSOR_2       (1 << 26)
+#      define RADEON_SCISSOR_0_ENABLE          (1 << 28)
+#      define RADEON_SCISSOR_1_ENABLE          (1 << 29)
+#      define RADEON_SCISSOR_2_ENABLE          (1 << 30)
+
+#define RADEON_BUS_CNTL                        0x0030
+#      define RADEON_BUS_MASTER_DIS            (1 << 6)
+
+#define RADEON_CLOCK_CNTL_DATA         0x000c
+#      define RADEON_PLL_WR_EN                 (1 << 7)
+#define RADEON_CLOCK_CNTL_INDEX                0x0008
+#define RADEON_CONFIG_APER_SIZE                0x0108
+#define RADEON_CONFIG_MEMSIZE          0x00f8
+#define RADEON_CRTC_OFFSET             0x0224
+#define RADEON_CRTC_OFFSET_CNTL                0x0228
+#      define RADEON_CRTC_TILE_EN              (1 << 15)
+#      define RADEON_CRTC_OFFSET_FLIP_CNTL     (1 << 16)
+#define RADEON_CRTC2_OFFSET            0x0324
+#define RADEON_CRTC2_OFFSET_CNTL       0x0328
+
+#define RADEON_PCIE_INDEX               0x0030
+#define RADEON_PCIE_DATA                0x0034
+#define RADEON_PCIE_TX_GART_CNTL       0x10
+#      define RADEON_PCIE_TX_GART_EN           (1 << 0)
+#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_PASS_THRU (0 << 1)
+#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_CLAMP_LO  (1 << 1)
+#      define RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD   (3 << 1)
+#      define RADEON_PCIE_TX_GART_MODE_32_128_CACHE    (0 << 3)
+#      define RADEON_PCIE_TX_GART_MODE_8_4_128_CACHE   (1 << 3)
+#      define RADEON_PCIE_TX_GART_CHK_RW_VALID_EN      (1 << 5)
+#      define RADEON_PCIE_TX_GART_INVALIDATE_TLB       (1 << 8)
+#define RADEON_PCIE_TX_DISCARD_RD_ADDR_LO 0x11
+#define RADEON_PCIE_TX_DISCARD_RD_ADDR_HI 0x12
+#define RADEON_PCIE_TX_GART_BASE       0x13
+#define RADEON_PCIE_TX_GART_START_LO   0x14
+#define RADEON_PCIE_TX_GART_START_HI   0x15
+#define RADEON_PCIE_TX_GART_END_LO     0x16
+#define RADEON_PCIE_TX_GART_END_HI     0x17
+
+#define RS480_NB_MC_INDEX               0x168
+#      define RS480_NB_MC_IND_WR_EN    (1 << 8)
+#define RS480_NB_MC_DATA                0x16c
+
+#define RS690_MC_INDEX                  0x78
+#   define RS690_MC_INDEX_MASK          0x1ff
+#   define RS690_MC_INDEX_WR_EN         (1 << 9)
+#   define RS690_MC_INDEX_WR_ACK        0x7f
+#define RS690_MC_DATA                   0x7c
+
+/* MC indirect registers */
+#define RS480_MC_MISC_CNTL              0x18
+#      define RS480_DISABLE_GTW        (1 << 1)
+/* switch between MCIND GART and MM GART registers. 0 = mmgart, 1 = mcind gart */
+#      define RS480_GART_INDEX_REG_EN  (1 << 12)
+#      define RS690_BLOCK_GFX_D3_EN    (1 << 14)
+#define RS480_K8_FB_LOCATION            0x1e
+#define RS480_GART_FEATURE_ID           0x2b
+#      define RS480_HANG_EN            (1 << 11)
+#      define RS480_TLB_ENABLE         (1 << 18)
+#      define RS480_P2P_ENABLE         (1 << 19)
+#      define RS480_GTW_LAC_EN         (1 << 25)
+#      define RS480_2LEVEL_GART        (0 << 30)
+#      define RS480_1LEVEL_GART        (1 << 30)
+#      define RS480_PDC_EN             (1 << 31)
+#define RS480_GART_BASE                 0x2c
+#define RS480_GART_CACHE_CNTRL          0x2e
+#      define RS480_GART_CACHE_INVALIDATE (1 << 0) /* wait for it to clear */
+#define RS480_AGP_ADDRESS_SPACE_SIZE    0x38
+#      define RS480_GART_EN            (1 << 0)
+#      define RS480_VA_SIZE_32MB       (0 << 1)
+#      define RS480_VA_SIZE_64MB       (1 << 1)
+#      define RS480_VA_SIZE_128MB      (2 << 1)
+#      define RS480_VA_SIZE_256MB      (3 << 1)
+#      define RS480_VA_SIZE_512MB      (4 << 1)
+#      define RS480_VA_SIZE_1GB        (5 << 1)
+#      define RS480_VA_SIZE_2GB        (6 << 1)
+#define RS480_AGP_MODE_CNTL             0x39
+#      define RS480_POST_GART_Q_SIZE   (1 << 18)
+#      define RS480_NONGART_SNOOP      (1 << 19)
+#      define RS480_AGP_RD_BUF_SIZE    (1 << 20)
+#      define RS480_REQ_TYPE_SNOOP_SHIFT 22
+#      define RS480_REQ_TYPE_SNOOP_MASK  0x3
+#      define RS480_REQ_TYPE_SNOOP_DIS (1 << 24)
+#define RS480_MC_MISC_UMA_CNTL          0x5f
+#define RS480_MC_MCLK_CNTL              0x7a
+#define RS480_MC_UMA_DUALCH_CNTL        0x86
+
+#define RS690_MC_FB_LOCATION            0x100
+#define RS690_MC_AGP_LOCATION           0x101
+#define RS690_MC_AGP_BASE               0x102
+#define RS690_MC_AGP_BASE_2             0x103
+
+#define R520_MC_IND_INDEX 0x70
+#define R520_MC_IND_WR_EN (1 << 24)
+#define R520_MC_IND_DATA  0x74
+
+#define RV515_MC_FB_LOCATION 0x01
+#define RV515_MC_AGP_LOCATION 0x02
+#define RV515_MC_AGP_BASE     0x03
+#define RV515_MC_AGP_BASE_2   0x04
+
+#define R520_MC_FB_LOCATION 0x04
+#define R520_MC_AGP_LOCATION 0x05
+#define R520_MC_AGP_BASE     0x06
+#define R520_MC_AGP_BASE_2   0x07
+
+#define RADEON_MPP_TB_CONFIG           0x01c0
+#define RADEON_MEM_CNTL                        0x0140
+#define RADEON_MEM_SDRAM_MODE_REG      0x0158
+#define RADEON_AGP_BASE_2              0x015c /* r200+ only */
+#define RS480_AGP_BASE_2               0x0164
+#define RADEON_AGP_BASE                        0x0170
+
+/* pipe config regs */
+#define R400_GB_PIPE_SELECT             0x402c
+#define R500_DYN_SCLK_PWMEM_PIPE        0x000d /* PLL */
+#define R500_SU_REG_DEST                0x42c8
+#define R300_GB_TILE_CONFIG             0x4018
+#       define R300_ENABLE_TILING       (1 << 0)
+#       define R300_PIPE_COUNT_RV350    (0 << 1)
+#       define R300_PIPE_COUNT_R300     (3 << 1)
+#       define R300_PIPE_COUNT_R420_3P  (6 << 1)
+#       define R300_PIPE_COUNT_R420     (7 << 1)
+#       define R300_TILE_SIZE_8         (0 << 4)
+#       define R300_TILE_SIZE_16        (1 << 4)
+#       define R300_TILE_SIZE_32        (2 << 4)
+#       define R300_SUBPIXEL_1_12       (0 << 16)
+#       define R300_SUBPIXEL_1_16       (1 << 16)
+#define R300_DST_PIPE_CONFIG            0x170c
+#       define R300_PIPE_AUTO_CONFIG    (1 << 31)
+#define R300_RB2D_DSTCACHE_MODE         0x3428
+#       define R300_DC_AUTOFLUSH_ENABLE (1 << 8)
+#       define R300_DC_DC_DISABLE_IGNORE_PE (1 << 17)
+
+#define RADEON_RB3D_COLOROFFSET                0x1c40
+#define RADEON_RB3D_COLORPITCH         0x1c48
+
+#define        RADEON_SRC_X_Y                  0x1590
+
+#define RADEON_DP_GUI_MASTER_CNTL      0x146c
+#      define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
+#      define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
+#      define RADEON_GMC_BRUSH_SOLID_COLOR     (13 << 4)
+#      define RADEON_GMC_BRUSH_NONE            (15 << 4)
+#      define RADEON_GMC_DST_16BPP             (4 << 8)
+#      define RADEON_GMC_DST_24BPP             (5 << 8)
+#      define RADEON_GMC_DST_32BPP             (6 << 8)
+#      define RADEON_GMC_DST_DATATYPE_SHIFT    8
+#      define RADEON_GMC_SRC_DATATYPE_COLOR    (3 << 12)
+#      define RADEON_DP_SRC_SOURCE_MEMORY      (2 << 24)
+#      define RADEON_DP_SRC_SOURCE_HOST_DATA   (3 << 24)
+#      define RADEON_GMC_CLR_CMP_CNTL_DIS      (1 << 28)
+#      define RADEON_GMC_WR_MSK_DIS            (1 << 30)
+#      define RADEON_ROP3_S                    0x00cc0000
+#      define RADEON_ROP3_P                    0x00f00000
+#define RADEON_DP_WRITE_MASK           0x16cc
+#define RADEON_SRC_PITCH_OFFSET                0x1428
+#define RADEON_DST_PITCH_OFFSET                0x142c
+#define RADEON_DST_PITCH_OFFSET_C      0x1c80
+#      define RADEON_DST_TILE_LINEAR           (0 << 30)
+#      define RADEON_DST_TILE_MACRO            (1 << 30)
+#      define RADEON_DST_TILE_MICRO            (2 << 30)
+#      define RADEON_DST_TILE_BOTH             (3 << 30)
+
+#define RADEON_SCRATCH_REG0            0x15e0
+#define RADEON_SCRATCH_REG1            0x15e4
+#define RADEON_SCRATCH_REG2            0x15e8
+#define RADEON_SCRATCH_REG3            0x15ec
+#define RADEON_SCRATCH_REG4            0x15f0
+#define RADEON_SCRATCH_REG5            0x15f4
+#define RADEON_SCRATCH_UMSK            0x0770
+#define RADEON_SCRATCH_ADDR            0x0774
+
+#define RADEON_SCRATCHOFF( x )         (RADEON_SCRATCH_REG_OFFSET + 4*(x))
+
+#define GET_SCRATCH( x )       (dev_priv->writeback_works                      \
+                               ? DRM_READ32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(x) ) \
+                               : RADEON_READ( RADEON_SCRATCH_REG0 + 4*(x) ) )
+
+#define RADEON_GEN_INT_CNTL            0x0040
+#      define RADEON_CRTC_VBLANK_MASK          (1 << 0)
+#      define RADEON_CRTC2_VBLANK_MASK         (1 << 9)
+#      define RADEON_GUI_IDLE_INT_ENABLE       (1 << 19)
+#      define RADEON_SW_INT_ENABLE             (1 << 25)
+
+#define RADEON_GEN_INT_STATUS          0x0044
+#      define RADEON_CRTC_VBLANK_STAT          (1 << 0)
+#      define RADEON_CRTC_VBLANK_STAT_ACK      (1 << 0)
+#      define RADEON_CRTC2_VBLANK_STAT         (1 << 9)
+#      define RADEON_CRTC2_VBLANK_STAT_ACK     (1 << 9)
+#      define RADEON_GUI_IDLE_INT_TEST_ACK     (1 << 19)
+#      define RADEON_SW_INT_TEST               (1 << 25)
+#      define RADEON_SW_INT_TEST_ACK           (1 << 25)
+#      define RADEON_SW_INT_FIRE               (1 << 26)
+
+#define RADEON_HOST_PATH_CNTL          0x0130
+#      define RADEON_HDP_SOFT_RESET            (1 << 26)
+#      define RADEON_HDP_WC_TIMEOUT_MASK       (7 << 28)
+#      define RADEON_HDP_WC_TIMEOUT_28BCLK     (7 << 28)
+
+#define RADEON_ISYNC_CNTL              0x1724
+#      define RADEON_ISYNC_ANY2D_IDLE3D        (1 << 0)
+#      define RADEON_ISYNC_ANY3D_IDLE2D        (1 << 1)
+#      define RADEON_ISYNC_TRIG2D_IDLE3D       (1 << 2)
+#      define RADEON_ISYNC_TRIG3D_IDLE2D       (1 << 3)
+#      define RADEON_ISYNC_WAIT_IDLEGUI        (1 << 4)
+#      define RADEON_ISYNC_CPSCRATCH_IDLEGUI   (1 << 5)
+
+#define RADEON_RBBM_GUICNTL            0x172c
+#      define RADEON_HOST_DATA_SWAP_NONE       (0 << 0)
+#      define RADEON_HOST_DATA_SWAP_16BIT      (1 << 0)
+#      define RADEON_HOST_DATA_SWAP_32BIT      (2 << 0)
+#      define RADEON_HOST_DATA_SWAP_HDW        (3 << 0)
+
+#define RADEON_MC_AGP_LOCATION         0x014c
+#define RADEON_MC_FB_LOCATION          0x0148
+#define RADEON_MCLK_CNTL               0x0012
+#      define RADEON_FORCEON_MCLKA             (1 << 16)
+#      define RADEON_FORCEON_MCLKB             (1 << 17)
+#      define RADEON_FORCEON_YCLKA             (1 << 18)
+#      define RADEON_FORCEON_YCLKB             (1 << 19)
+#      define RADEON_FORCEON_MC                (1 << 20)
+#      define RADEON_FORCEON_AIC               (1 << 21)
+
+#define RADEON_PP_BORDER_COLOR_0       0x1d40
+#define RADEON_PP_BORDER_COLOR_1       0x1d44
+#define RADEON_PP_BORDER_COLOR_2       0x1d48
+#define RADEON_PP_CNTL                 0x1c38
+#      define RADEON_SCISSOR_ENABLE            (1 <<  1)
+#define RADEON_PP_LUM_MATRIX           0x1d00
+#define RADEON_PP_MISC                 0x1c14
+#define RADEON_PP_ROT_MATRIX_0         0x1d58
+#define RADEON_PP_TXFILTER_0           0x1c54
+#define RADEON_PP_TXOFFSET_0           0x1c5c
+#define RADEON_PP_TXFILTER_1           0x1c6c
+#define RADEON_PP_TXFILTER_2           0x1c84
+
+#define R300_RB2D_DSTCACHE_CTLSTAT     0x342c /* use R300_DSTCACHE_CTLSTAT */
+#define R300_DSTCACHE_CTLSTAT          0x1714
+#      define R300_RB2D_DC_FLUSH               (3 << 0)
+#      define R300_RB2D_DC_FREE                (3 << 2)
+#      define R300_RB2D_DC_FLUSH_ALL           0xf
+#      define R300_RB2D_DC_BUSY                (1 << 31)
+#define RADEON_RB3D_CNTL               0x1c3c
+#      define RADEON_ALPHA_BLEND_ENABLE        (1 << 0)
+#      define RADEON_PLANE_MASK_ENABLE         (1 << 1)
+#      define RADEON_DITHER_ENABLE             (1 << 2)
+#      define RADEON_ROUND_ENABLE              (1 << 3)
+#      define RADEON_SCALE_DITHER_ENABLE       (1 << 4)
+#      define RADEON_DITHER_INIT               (1 << 5)
+#      define RADEON_ROP_ENABLE                (1 << 6)
+#      define RADEON_STENCIL_ENABLE            (1 << 7)
+#      define RADEON_Z_ENABLE                  (1 << 8)
+#      define RADEON_ZBLOCK16                  (1 << 15)
+#define RADEON_RB3D_DEPTHOFFSET                0x1c24
+#define RADEON_RB3D_DEPTHCLEARVALUE    0x3230
+#define RADEON_RB3D_DEPTHPITCH         0x1c28
+#define RADEON_RB3D_PLANEMASK          0x1d84
+#define RADEON_RB3D_STENCILREFMASK     0x1d7c
+#define RADEON_RB3D_ZCACHE_MODE                0x3250
+#define RADEON_RB3D_ZCACHE_CTLSTAT     0x3254
+#      define RADEON_RB3D_ZC_FLUSH             (1 << 0)
+#      define RADEON_RB3D_ZC_FREE              (1 << 2)
+#      define RADEON_RB3D_ZC_FLUSH_ALL         0x5
+#      define RADEON_RB3D_ZC_BUSY              (1 << 31)
+#define R300_ZB_ZCACHE_CTLSTAT                  0x4f18
+#      define R300_ZC_FLUSH                    (1 << 0)
+#      define R300_ZC_FREE                     (1 << 1)
+#      define R300_ZC_FLUSH_ALL                0x3
+#      define R300_ZC_BUSY                     (1 << 31)
+#define RADEON_RB3D_DSTCACHE_CTLSTAT   0x325c
+#      define RADEON_RB3D_DC_FLUSH             (3 << 0)
+#      define RADEON_RB3D_DC_FREE              (3 << 2)
+#      define RADEON_RB3D_DC_FLUSH_ALL         0xf
+#      define RADEON_RB3D_DC_BUSY              (1 << 31)
+#define R300_RB3D_DSTCACHE_CTLSTAT              0x4e4c
+#      define R300_RB3D_DC_FINISH              (1 << 4)
+#define RADEON_RB3D_ZSTENCILCNTL       0x1c2c
+#      define RADEON_Z_TEST_MASK               (7 << 4)
+#      define RADEON_Z_TEST_ALWAYS             (7 << 4)
+#      define RADEON_Z_HIERARCHY_ENABLE        (1 << 8)
+#      define RADEON_STENCIL_TEST_ALWAYS       (7 << 12)
+#      define RADEON_STENCIL_S_FAIL_REPLACE    (2 << 16)
+#      define RADEON_STENCIL_ZPASS_REPLACE     (2 << 20)
+#      define RADEON_STENCIL_ZFAIL_REPLACE     (2 << 24)
+#      define RADEON_Z_COMPRESSION_ENABLE      (1 << 28)
+#      define RADEON_FORCE_Z_DIRTY             (1 << 29)
+#      define RADEON_Z_WRITE_ENABLE            (1 << 30)
+#      define RADEON_Z_DECOMPRESSION_ENABLE    (1 << 31)
+#define RADEON_RBBM_SOFT_RESET         0x00f0
+#      define RADEON_SOFT_RESET_CP             (1 <<  0)
+#      define RADEON_SOFT_RESET_HI             (1 <<  1)
+#      define RADEON_SOFT_RESET_SE             (1 <<  2)
+#      define RADEON_SOFT_RESET_RE             (1 <<  3)
+#      define RADEON_SOFT_RESET_PP             (1 <<  4)
+#      define RADEON_SOFT_RESET_E2             (1 <<  5)
+#      define RADEON_SOFT_RESET_RB             (1 <<  6)
+#      define RADEON_SOFT_RESET_HDP            (1 <<  7)
+/*
+ *   6:0  Available slots in the FIFO
+ *   8    Host Interface active
+ *   9    CP request active
+ *   10   FIFO request active
+ *   11   Host Interface retry active
+ *   12   CP retry active
+ *   13   FIFO retry active
+ *   14   FIFO pipeline busy
+ *   15   Event engine busy
+ *   16   CP command stream busy
+ *   17   2D engine busy
+ *   18   2D portion of render backend busy
+ *   20   3D setup engine busy
+ *   26   GA engine busy
+ *   27   CBA 2D engine busy
+ *   31   2D engine busy or 3D engine busy or FIFO not empty or CP busy or
+ *           command stream queue not empty or Ring Buffer not empty
+ */
+#define RADEON_RBBM_STATUS             0x0e40
+/* Same as the previous RADEON_RBBM_STATUS; this is a mirror of that register.  */
+/* #define RADEON_RBBM_STATUS          0x1740 */
+/* bits 6:0 are dword slots available in the cmd fifo */
+#      define RADEON_RBBM_FIFOCNT_MASK         0x007f
+#      define RADEON_HIRQ_ON_RBB       (1 <<  8)
+#      define RADEON_CPRQ_ON_RBB       (1 <<  9)
+#      define RADEON_CFRQ_ON_RBB       (1 << 10)
+#      define RADEON_HIRQ_IN_RTBUF     (1 << 11)
+#      define RADEON_CPRQ_IN_RTBUF     (1 << 12)
+#      define RADEON_CFRQ_IN_RTBUF     (1 << 13)
+#      define RADEON_PIPE_BUSY         (1 << 14)
+#      define RADEON_ENG_EV_BUSY       (1 << 15)
+#      define RADEON_CP_CMDSTRM_BUSY   (1 << 16)
+#      define RADEON_E2_BUSY           (1 << 17)
+#      define RADEON_RB2D_BUSY         (1 << 18)
+#      define RADEON_RB3D_BUSY         (1 << 19) /* not used on r300 */
+#      define RADEON_VAP_BUSY          (1 << 20)
+#      define RADEON_RE_BUSY           (1 << 21) /* not used on r300 */
+#      define RADEON_TAM_BUSY          (1 << 22) /* not used on r300 */
+#      define RADEON_TDM_BUSY          (1 << 23) /* not used on r300 */
+#      define RADEON_PB_BUSY           (1 << 24) /* not used on r300 */
+#      define RADEON_TIM_BUSY          (1 << 25) /* not used on r300 */
+#      define RADEON_GA_BUSY           (1 << 26)
+#      define RADEON_CBA2D_BUSY        (1 << 27)
+#      define RADEON_RBBM_ACTIVE       (1 << 31)
+#define RADEON_RE_LINE_PATTERN         0x1cd0
+#define RADEON_RE_MISC                 0x26c4
+#define RADEON_RE_TOP_LEFT             0x26c0
+#define RADEON_RE_WIDTH_HEIGHT         0x1c44
+#define RADEON_RE_STIPPLE_ADDR         0x1cc8
+#define RADEON_RE_STIPPLE_DATA         0x1ccc
+
+#define RADEON_SCISSOR_TL_0            0x1cd8
+#define RADEON_SCISSOR_BR_0            0x1cdc
+#define RADEON_SCISSOR_TL_1            0x1ce0
+#define RADEON_SCISSOR_BR_1            0x1ce4
+#define RADEON_SCISSOR_TL_2            0x1ce8
+#define RADEON_SCISSOR_BR_2            0x1cec
+#define RADEON_SE_COORD_FMT            0x1c50
+#define RADEON_SE_CNTL                 0x1c4c
+#      define RADEON_FFACE_CULL_CW             (0 << 0)
+#      define RADEON_BFACE_SOLID               (3 << 1)
+#      define RADEON_FFACE_SOLID               (3 << 3)
+#      define RADEON_FLAT_SHADE_VTX_LAST       (3 << 6)
+#      define RADEON_DIFFUSE_SHADE_FLAT        (1 << 8)
+#      define RADEON_DIFFUSE_SHADE_GOURAUD     (2 << 8)
+#      define RADEON_ALPHA_SHADE_FLAT          (1 << 10)
+#      define RADEON_ALPHA_SHADE_GOURAUD       (2 << 10)
+#      define RADEON_SPECULAR_SHADE_FLAT       (1 << 12)
+#      define RADEON_SPECULAR_SHADE_GOURAUD    (2 << 12)
+#      define RADEON_FOG_SHADE_FLAT            (1 << 14)
+#      define RADEON_FOG_SHADE_GOURAUD         (2 << 14)
+#      define RADEON_VPORT_XY_XFORM_ENABLE     (1 << 24)
+#      define RADEON_VPORT_Z_XFORM_ENABLE      (1 << 25)
+#      define RADEON_VTX_PIX_CENTER_OGL        (1 << 27)
+#      define RADEON_ROUND_MODE_TRUNC          (0 << 28)
+#      define RADEON_ROUND_PREC_8TH_PIX        (1 << 30)
+#define RADEON_SE_CNTL_STATUS          0x2140
+#define RADEON_SE_LINE_WIDTH           0x1db8
+#define RADEON_SE_VPORT_XSCALE         0x1d98
+#define RADEON_SE_ZBIAS_FACTOR         0x1db0
+#define RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED 0x2210
+#define RADEON_SE_TCL_OUTPUT_VTX_FMT         0x2254
+#define RADEON_SE_TCL_VECTOR_INDX_REG        0x2200
+#       define RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT  16
+#       define RADEON_VEC_INDX_DWORD_COUNT_SHIFT     28
+#define RADEON_SE_TCL_VECTOR_DATA_REG       0x2204
+#define RADEON_SE_TCL_SCALAR_INDX_REG       0x2208
+#       define RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT  16
+#define RADEON_SE_TCL_SCALAR_DATA_REG       0x220C
+#define RADEON_SURFACE_ACCESS_FLAGS    0x0bf8
+#define RADEON_SURFACE_ACCESS_CLR      0x0bfc
+#define RADEON_SURFACE_CNTL            0x0b00
+#      define RADEON_SURF_TRANSLATION_DIS      (1 << 8)
+#      define RADEON_NONSURF_AP0_SWP_MASK      (3 << 20)
+#      define RADEON_NONSURF_AP0_SWP_LITTLE    (0 << 20)
+#      define RADEON_NONSURF_AP0_SWP_BIG16     (1 << 20)
+#      define RADEON_NONSURF_AP0_SWP_BIG32     (2 << 20)
+#      define RADEON_NONSURF_AP1_SWP_MASK      (3 << 22)
+#      define RADEON_NONSURF_AP1_SWP_LITTLE    (0 << 22)
+#      define RADEON_NONSURF_AP1_SWP_BIG16     (1 << 22)
+#      define RADEON_NONSURF_AP1_SWP_BIG32     (2 << 22)
+#define RADEON_SURFACE0_INFO           0x0b0c
+#      define RADEON_SURF_PITCHSEL_MASK        (0x1ff << 0)
+#      define RADEON_SURF_TILE_MODE_MASK       (3 << 16)
+#      define RADEON_SURF_TILE_MODE_MACRO      (0 << 16)
+#      define RADEON_SURF_TILE_MODE_MICRO      (1 << 16)
+#      define RADEON_SURF_TILE_MODE_32BIT_Z    (2 << 16)
+#      define RADEON_SURF_TILE_MODE_16BIT_Z    (3 << 16)
+#define RADEON_SURFACE0_LOWER_BOUND    0x0b04
+#define RADEON_SURFACE0_UPPER_BOUND    0x0b08
+#      define RADEON_SURF_ADDRESS_FIXED_MASK   (0x3ff << 0)
+#define RADEON_SURFACE1_INFO           0x0b1c
+#define RADEON_SURFACE1_LOWER_BOUND    0x0b14
+#define RADEON_SURFACE1_UPPER_BOUND    0x0b18
+#define RADEON_SURFACE2_INFO           0x0b2c
+#define RADEON_SURFACE2_LOWER_BOUND    0x0b24
+#define RADEON_SURFACE2_UPPER_BOUND    0x0b28
+#define RADEON_SURFACE3_INFO           0x0b3c
+#define RADEON_SURFACE3_LOWER_BOUND    0x0b34
+#define RADEON_SURFACE3_UPPER_BOUND    0x0b38
+#define RADEON_SURFACE4_INFO           0x0b4c
+#define RADEON_SURFACE4_LOWER_BOUND    0x0b44
+#define RADEON_SURFACE4_UPPER_BOUND    0x0b48
+#define RADEON_SURFACE5_INFO           0x0b5c
+#define RADEON_SURFACE5_LOWER_BOUND    0x0b54
+#define RADEON_SURFACE5_UPPER_BOUND    0x0b58
+#define RADEON_SURFACE6_INFO           0x0b6c
+#define RADEON_SURFACE6_LOWER_BOUND    0x0b64
+#define RADEON_SURFACE6_UPPER_BOUND    0x0b68
+#define RADEON_SURFACE7_INFO           0x0b7c
+#define RADEON_SURFACE7_LOWER_BOUND    0x0b74
+#define RADEON_SURFACE7_UPPER_BOUND    0x0b78
+#define RADEON_SW_SEMAPHORE            0x013c
+
+#define RADEON_WAIT_UNTIL              0x1720
+#      define RADEON_WAIT_CRTC_PFLIP           (1 << 0)
+#      define RADEON_WAIT_2D_IDLE              (1 << 14)
+#      define RADEON_WAIT_3D_IDLE              (1 << 15)
+#      define RADEON_WAIT_2D_IDLECLEAN         (1 << 16)
+#      define RADEON_WAIT_3D_IDLECLEAN         (1 << 17)
+#      define RADEON_WAIT_HOST_IDLECLEAN       (1 << 18)
+
+#define RADEON_RB3D_ZMASKOFFSET                0x3234
+#define RADEON_RB3D_ZSTENCILCNTL       0x1c2c
+#      define RADEON_DEPTH_FORMAT_16BIT_INT_Z  (0 << 0)
+#      define RADEON_DEPTH_FORMAT_24BIT_INT_Z  (2 << 0)
+
+/* CP registers */
+#define RADEON_CP_ME_RAM_ADDR          0x07d4
+#define RADEON_CP_ME_RAM_RADDR         0x07d8
+#define RADEON_CP_ME_RAM_DATAH         0x07dc
+#define RADEON_CP_ME_RAM_DATAL         0x07e0
+
+#define RADEON_CP_RB_BASE              0x0700
+#define RADEON_CP_RB_CNTL              0x0704
+#      define RADEON_BUF_SWAP_32BIT            (2 << 16)
+#      define RADEON_RB_NO_UPDATE              (1 << 27)
+#define RADEON_CP_RB_RPTR_ADDR         0x070c
+#define RADEON_CP_RB_RPTR              0x0710
+#define RADEON_CP_RB_WPTR              0x0714
+
+#define RADEON_CP_RB_WPTR_DELAY                0x0718
+#      define RADEON_PRE_WRITE_TIMER_SHIFT     0
+#      define RADEON_PRE_WRITE_LIMIT_SHIFT     23
+
+#define RADEON_CP_IB_BASE              0x0738
+
+#define RADEON_CP_CSQ_CNTL             0x0740
+#      define RADEON_CSQ_CNT_PRIMARY_MASK      (0xff << 0)
+#      define RADEON_CSQ_PRIDIS_INDDIS         (0 << 28)
+#      define RADEON_CSQ_PRIPIO_INDDIS         (1 << 28)
+#      define RADEON_CSQ_PRIBM_INDDIS          (2 << 28)
+#      define RADEON_CSQ_PRIPIO_INDBM          (3 << 28)
+#      define RADEON_CSQ_PRIBM_INDBM           (4 << 28)
+#      define RADEON_CSQ_PRIPIO_INDPIO         (15 << 28)
+
+#define RADEON_AIC_CNTL                        0x01d0
+#      define RADEON_PCIGART_TRANSLATE_EN      (1 << 0)
+#define RADEON_AIC_STAT                        0x01d4
+#define RADEON_AIC_PT_BASE             0x01d8
+#define RADEON_AIC_LO_ADDR             0x01dc
+#define RADEON_AIC_HI_ADDR             0x01e0
+#define RADEON_AIC_TLB_ADDR            0x01e4
+#define RADEON_AIC_TLB_DATA            0x01e8
+
+/* CP command packets */
+#define RADEON_CP_PACKET0              0x00000000
+#      define RADEON_ONE_REG_WR                (1 << 15)
+#define RADEON_CP_PACKET1              0x40000000
+#define RADEON_CP_PACKET2              0x80000000
+#define RADEON_CP_PACKET3              0xC0000000
+#       define RADEON_CP_NOP                    0x00001000
+#       define RADEON_CP_NEXT_CHAR              0x00001900
+#       define RADEON_CP_PLY_NEXTSCAN           0x00001D00
+#       define RADEON_CP_SET_SCISSORS           0x00001E00
+            /* GEN_INDX_PRIM is unsupported starting with R300 */
+#      define RADEON_3D_RNDR_GEN_INDX_PRIM     0x00002300
+#      define RADEON_WAIT_FOR_IDLE             0x00002600
+#      define RADEON_3D_DRAW_VBUF              0x00002800
+#      define RADEON_3D_DRAW_IMMD              0x00002900
+#      define RADEON_3D_DRAW_INDX              0x00002A00
+#       define RADEON_CP_LOAD_PALETTE           0x00002C00
+#      define RADEON_3D_LOAD_VBPNTR            0x00002F00
+#      define RADEON_MPEG_IDCT_MACROBLOCK      0x00003000
+#      define RADEON_MPEG_IDCT_MACROBLOCK_REV  0x00003100
+#      define RADEON_3D_CLEAR_ZMASK            0x00003200
+#      define RADEON_CP_INDX_BUFFER            0x00003300
+#       define RADEON_CP_3D_DRAW_VBUF_2         0x00003400
+#       define RADEON_CP_3D_DRAW_IMMD_2         0x00003500
+#       define RADEON_CP_3D_DRAW_INDX_2         0x00003600
+#      define RADEON_3D_CLEAR_HIZ              0x00003700
+#       define RADEON_CP_3D_CLEAR_CMASK         0x00003802
+#      define RADEON_CNTL_HOSTDATA_BLT         0x00009400
+#      define RADEON_CNTL_PAINT_MULTI          0x00009A00
+#      define RADEON_CNTL_BITBLT_MULTI         0x00009B00
+#      define RADEON_CNTL_SET_SCISSORS         0xC0001E00
+
+#define RADEON_CP_PACKET_MASK          0xC0000000
+#define RADEON_CP_PACKET_COUNT_MASK    0x3fff0000
+#define RADEON_CP_PACKET0_REG_MASK     0x000007ff
+#define RADEON_CP_PACKET1_REG0_MASK    0x000007ff
+#define RADEON_CP_PACKET1_REG1_MASK    0x003ff800
+
+#define RADEON_VTX_Z_PRESENT                   (1 << 31)
+#define RADEON_VTX_PKCOLOR_PRESENT             (1 << 3)
+
+#define RADEON_PRIM_TYPE_NONE                  (0 << 0)
+#define RADEON_PRIM_TYPE_POINT                 (1 << 0)
+#define RADEON_PRIM_TYPE_LINE                  (2 << 0)
+#define RADEON_PRIM_TYPE_LINE_STRIP            (3 << 0)
+#define RADEON_PRIM_TYPE_TRI_LIST              (4 << 0)
+#define RADEON_PRIM_TYPE_TRI_FAN               (5 << 0)
+#define RADEON_PRIM_TYPE_TRI_STRIP             (6 << 0)
+#define RADEON_PRIM_TYPE_TRI_TYPE2             (7 << 0)
+#define RADEON_PRIM_TYPE_RECT_LIST             (8 << 0)
+#define RADEON_PRIM_TYPE_3VRT_POINT_LIST       (9 << 0)
+#define RADEON_PRIM_TYPE_3VRT_LINE_LIST                (10 << 0)
+#define RADEON_PRIM_TYPE_MASK                   0xf
+#define RADEON_PRIM_WALK_IND                   (1 << 4)
+#define RADEON_PRIM_WALK_LIST                  (2 << 4)
+#define RADEON_PRIM_WALK_RING                  (3 << 4)
+#define RADEON_COLOR_ORDER_BGRA                        (0 << 6)
+#define RADEON_COLOR_ORDER_RGBA                        (1 << 6)
+#define RADEON_MAOS_ENABLE                     (1 << 7)
+#define RADEON_VTX_FMT_R128_MODE               (0 << 8)
+#define RADEON_VTX_FMT_RADEON_MODE             (1 << 8)
+#define RADEON_NUM_VERTICES_SHIFT              16
+
+#define RADEON_COLOR_FORMAT_CI8                2
+#define RADEON_COLOR_FORMAT_ARGB1555   3
+#define RADEON_COLOR_FORMAT_RGB565     4
+#define RADEON_COLOR_FORMAT_ARGB8888   6
+#define RADEON_COLOR_FORMAT_RGB332     7
+#define RADEON_COLOR_FORMAT_RGB8       9
+#define RADEON_COLOR_FORMAT_ARGB4444   15
+
+#define RADEON_TXFORMAT_I8             0
+#define RADEON_TXFORMAT_AI88           1
+#define RADEON_TXFORMAT_RGB332         2
+#define RADEON_TXFORMAT_ARGB1555       3
+#define RADEON_TXFORMAT_RGB565         4
+#define RADEON_TXFORMAT_ARGB4444       5
+#define RADEON_TXFORMAT_ARGB8888       6
+#define RADEON_TXFORMAT_RGBA8888       7
+#define RADEON_TXFORMAT_Y8             8
+#define RADEON_TXFORMAT_VYUY422         10
+#define RADEON_TXFORMAT_YVYU422         11
+#define RADEON_TXFORMAT_DXT1            12
+#define RADEON_TXFORMAT_DXT23           14
+#define RADEON_TXFORMAT_DXT45           15
+
+#define R200_PP_TXCBLEND_0                0x2f00
+#define R200_PP_TXCBLEND_1                0x2f10
+#define R200_PP_TXCBLEND_2                0x2f20
+#define R200_PP_TXCBLEND_3                0x2f30
+#define R200_PP_TXCBLEND_4                0x2f40
+#define R200_PP_TXCBLEND_5                0x2f50
+#define R200_PP_TXCBLEND_6                0x2f60
+#define R200_PP_TXCBLEND_7                0x2f70
+#define R200_SE_TCL_LIGHT_MODEL_CTL_0     0x2268
+#define R200_PP_TFACTOR_0                 0x2ee0
+#define R200_SE_VTX_FMT_0                 0x2088
+#define R200_SE_VAP_CNTL                  0x2080
+#define R200_SE_TCL_MATRIX_SEL_0          0x2230
+#define R200_SE_TCL_TEX_PROC_CTL_2        0x22a8
+#define R200_SE_TCL_UCP_VERT_BLEND_CTL    0x22c0
+#define R200_PP_TXFILTER_5                0x2ca0
+#define R200_PP_TXFILTER_4                0x2c80
+#define R200_PP_TXFILTER_3                0x2c60
+#define R200_PP_TXFILTER_2                0x2c40
+#define R200_PP_TXFILTER_1                0x2c20
+#define R200_PP_TXFILTER_0                0x2c00
+#define R200_PP_TXOFFSET_5                0x2d78
+#define R200_PP_TXOFFSET_4                0x2d60
+#define R200_PP_TXOFFSET_3                0x2d48
+#define R200_PP_TXOFFSET_2                0x2d30
+#define R200_PP_TXOFFSET_1                0x2d18
+#define R200_PP_TXOFFSET_0                0x2d00
+
+#define R200_PP_CUBIC_FACES_0             0x2c18
+#define R200_PP_CUBIC_FACES_1             0x2c38
+#define R200_PP_CUBIC_FACES_2             0x2c58
+#define R200_PP_CUBIC_FACES_3             0x2c78
+#define R200_PP_CUBIC_FACES_4             0x2c98
+#define R200_PP_CUBIC_FACES_5             0x2cb8
+#define R200_PP_CUBIC_OFFSET_F1_0         0x2d04
+#define R200_PP_CUBIC_OFFSET_F2_0         0x2d08
+#define R200_PP_CUBIC_OFFSET_F3_0         0x2d0c
+#define R200_PP_CUBIC_OFFSET_F4_0         0x2d10
+#define R200_PP_CUBIC_OFFSET_F5_0         0x2d14
+#define R200_PP_CUBIC_OFFSET_F1_1         0x2d1c
+#define R200_PP_CUBIC_OFFSET_F2_1         0x2d20
+#define R200_PP_CUBIC_OFFSET_F3_1         0x2d24
+#define R200_PP_CUBIC_OFFSET_F4_1         0x2d28
+#define R200_PP_CUBIC_OFFSET_F5_1         0x2d2c
+#define R200_PP_CUBIC_OFFSET_F1_2         0x2d34
+#define R200_PP_CUBIC_OFFSET_F2_2         0x2d38
+#define R200_PP_CUBIC_OFFSET_F3_2         0x2d3c
+#define R200_PP_CUBIC_OFFSET_F4_2         0x2d40
+#define R200_PP_CUBIC_OFFSET_F5_2         0x2d44
+#define R200_PP_CUBIC_OFFSET_F1_3         0x2d4c
+#define R200_PP_CUBIC_OFFSET_F2_3         0x2d50
+#define R200_PP_CUBIC_OFFSET_F3_3         0x2d54
+#define R200_PP_CUBIC_OFFSET_F4_3         0x2d58
+#define R200_PP_CUBIC_OFFSET_F5_3         0x2d5c
+#define R200_PP_CUBIC_OFFSET_F1_4         0x2d64
+#define R200_PP_CUBIC_OFFSET_F2_4         0x2d68
+#define R200_PP_CUBIC_OFFSET_F3_4         0x2d6c
+#define R200_PP_CUBIC_OFFSET_F4_4         0x2d70
+#define R200_PP_CUBIC_OFFSET_F5_4         0x2d74
+#define R200_PP_CUBIC_OFFSET_F1_5         0x2d7c
+#define R200_PP_CUBIC_OFFSET_F2_5         0x2d80
+#define R200_PP_CUBIC_OFFSET_F3_5         0x2d84
+#define R200_PP_CUBIC_OFFSET_F4_5         0x2d88
+#define R200_PP_CUBIC_OFFSET_F5_5         0x2d8c
+
+#define R200_RE_AUX_SCISSOR_CNTL          0x26f0
+#define R200_SE_VTE_CNTL                  0x20b0
+#define R200_SE_TCL_OUTPUT_VTX_COMP_SEL   0x2250
+#define R200_PP_TAM_DEBUG3                0x2d9c
+#define R200_PP_CNTL_X                    0x2cc4
+#define R200_SE_VAP_CNTL_STATUS           0x2140
+#define R200_RE_SCISSOR_TL_0              0x1cd8
+#define R200_RE_SCISSOR_TL_1              0x1ce0
+#define R200_RE_SCISSOR_TL_2              0x1ce8
+#define R200_RB3D_DEPTHXY_OFFSET          0x1d60
+#define R200_RE_AUX_SCISSOR_CNTL          0x26f0
+#define R200_SE_VTX_STATE_CNTL            0x2180
+#define R200_RE_POINTSIZE                 0x2648
+#define R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0 0x2254
+
+#define RADEON_PP_TEX_SIZE_0                0x1d04     /* NPOT */
+#define RADEON_PP_TEX_SIZE_1                0x1d0c
+#define RADEON_PP_TEX_SIZE_2                0x1d14
+
+#define RADEON_PP_CUBIC_FACES_0             0x1d24
+#define RADEON_PP_CUBIC_FACES_1             0x1d28
+#define RADEON_PP_CUBIC_FACES_2             0x1d2c
+#define RADEON_PP_CUBIC_OFFSET_T0_0         0x1dd0     /* bits [31:5] */
+#define RADEON_PP_CUBIC_OFFSET_T1_0         0x1e00
+#define RADEON_PP_CUBIC_OFFSET_T2_0         0x1e14
+
+#define RADEON_SE_TCL_STATE_FLUSH           0x2284
+
+#define SE_VAP_CNTL__TCL_ENA_MASK                          0x00000001
+#define SE_VAP_CNTL__FORCE_W_TO_ONE_MASK                   0x00010000
+#define SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT                 0x00000012
+#define SE_VTE_CNTL__VTX_XY_FMT_MASK                       0x00000100
+#define SE_VTE_CNTL__VTX_Z_FMT_MASK                        0x00000200
+#define SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK                  0x00000001
+#define SE_VTX_FMT_0__VTX_W0_PRESENT_MASK                  0x00000002
+#define SE_VTX_FMT_0__VTX_COLOR_0_FMT__SHIFT               0x0000000b
+#define R200_3D_DRAW_IMMD_2      0xC0003500
+#define R200_SE_VTX_FMT_1                 0x208c
+#define R200_RE_CNTL                      0x1c50
+
+#define R200_RB3D_BLENDCOLOR              0x3218
+
+#define R200_SE_TCL_POINT_SPRITE_CNTL     0x22c4
+
+#define R200_PP_TRI_PERF 0x2cf8
+
+#define R200_PP_AFS_0                     0x2f80
+#define R200_PP_AFS_1                     0x2f00       /* same as txcblend_0 */
+
+#define R200_VAP_PVS_CNTL_1               0x22D0
+
+#define R500_D1CRTC_STATUS 0x609c
+#define R500_D2CRTC_STATUS 0x689c
+#define R500_CRTC_V_BLANK (1<<0)
+
+#define R500_D1CRTC_FRAME_COUNT 0x60a4
+#define R500_D2CRTC_FRAME_COUNT 0x68a4
+
+#define R500_D1MODE_V_COUNTER 0x6530
+#define R500_D2MODE_V_COUNTER 0x6d30
+
+#define R500_D1MODE_VBLANK_STATUS 0x6534
+#define R500_D2MODE_VBLANK_STATUS 0x6d34
+#define R500_VBLANK_OCCURED (1<<0)
+#define R500_VBLANK_ACK     (1<<4)
+#define R500_VBLANK_STAT    (1<<12)
+#define R500_VBLANK_INT     (1<<16)
+
+#define R500_DxMODE_INT_MASK 0x6540
+#define R500_D1MODE_INT_MASK (1<<0)
+#define R500_D2MODE_INT_MASK (1<<8)
+
+#define R500_DISP_INTERRUPT_STATUS 0x7edc
+#define R500_D1_VBLANK_INTERRUPT (1 << 4)
+#define R500_D2_VBLANK_INTERRUPT (1 << 5)
+
+/* Constants */
+#define RADEON_MAX_USEC_TIMEOUT                100000  /* 100 ms */
+
+#define RADEON_LAST_FRAME_REG          RADEON_SCRATCH_REG0
+#define RADEON_LAST_DISPATCH_REG       RADEON_SCRATCH_REG1
+#define RADEON_LAST_CLEAR_REG          RADEON_SCRATCH_REG2
+#define RADEON_LAST_SWI_REG            RADEON_SCRATCH_REG3
+#define RADEON_LAST_DISPATCH           1
+
+#define RADEON_MAX_VB_AGE              0x7fffffff
+#define RADEON_MAX_VB_VERTS            (0xffff)
+
+#define RADEON_RING_HIGH_MARK          128
+
+#define RADEON_PCIGART_TABLE_SIZE      (32*1024)
+
+#define RADEON_READ(reg)       DRM_READ32(  dev_priv->mmio, (reg) )
+#define RADEON_WRITE(reg,val)  DRM_WRITE32( dev_priv->mmio, (reg), (val) )
+#define RADEON_READ8(reg)      DRM_READ8(  dev_priv->mmio, (reg) )
+#define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, (reg), (val) )
+
+#define RADEON_WRITE_PLL(addr, val)                                    \
+do {                                                                   \
+       RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX,                          \
+                      ((addr) & 0x1f) | RADEON_PLL_WR_EN );            \
+       RADEON_WRITE(RADEON_CLOCK_CNTL_DATA, (val));                    \
+} while (0)
+
+#define RADEON_WRITE_PCIE(addr, val)                                   \
+do {                                                                   \
+       RADEON_WRITE8(RADEON_PCIE_INDEX,                                \
+                       ((addr) & 0xff));                               \
+       RADEON_WRITE(RADEON_PCIE_DATA, (val));                  \
+} while (0)
+
+#define R500_WRITE_MCIND(addr, val)                                    \
+do {                                                           \
+       RADEON_WRITE(R520_MC_IND_INDEX, 0xff0000 | ((addr) & 0xff));    \
+       RADEON_WRITE(R520_MC_IND_DATA, (val));                  \
+       RADEON_WRITE(R520_MC_IND_INDEX, 0);     \
+} while (0)
+
+#define RS480_WRITE_MCIND(addr, val)                           \
+do {                                                                   \
+       RADEON_WRITE(RS480_NB_MC_INDEX,                         \
+                       ((addr) & 0xff) | RS480_NB_MC_IND_WR_EN);       \
+       RADEON_WRITE(RS480_NB_MC_DATA, (val));                  \
+       RADEON_WRITE(RS480_NB_MC_INDEX, 0xff);                  \
+} while (0)
+
+#define RS690_WRITE_MCIND(addr, val)                                   \
+do {                                                           \
+       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_EN | ((addr) & RS690_MC_INDEX_MASK));    \
+       RADEON_WRITE(RS690_MC_DATA, val);                       \
+       RADEON_WRITE(RS690_MC_INDEX, RS690_MC_INDEX_WR_ACK);    \
+} while (0)
+
+#define IGP_WRITE_MCIND(addr, val)                             \
+do {                                                                   \
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS690)       \
+               RS690_WRITE_MCIND(addr, val);                           \
+       else                                                            \
+               RS480_WRITE_MCIND(addr, val);                           \
+} while (0)
+
+#define CP_PACKET0( reg, n )                                           \
+       (RADEON_CP_PACKET0 | ((n) << 16) | ((reg) >> 2))
+#define CP_PACKET0_TABLE( reg, n )                                     \
+       (RADEON_CP_PACKET0 | RADEON_ONE_REG_WR | ((n) << 16) | ((reg) >> 2))
+#define CP_PACKET1( reg0, reg1 )                                       \
+       (RADEON_CP_PACKET1 | (((reg1) >> 2) << 15) | ((reg0) >> 2))
+#define CP_PACKET2()                                                   \
+       (RADEON_CP_PACKET2)
+#define CP_PACKET3( pkt, n )                                           \
+       (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
+
+/* ================================================================
+ * Engine control helper macros
+ */
+
+#define RADEON_WAIT_UNTIL_2D_IDLE() do {                               \
+       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
+       OUT_RING( (RADEON_WAIT_2D_IDLECLEAN |                           \
+                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
+} while (0)
+
+#define RADEON_WAIT_UNTIL_3D_IDLE() do {                               \
+       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
+       OUT_RING( (RADEON_WAIT_3D_IDLECLEAN |                           \
+                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
+} while (0)
+
+#define RADEON_WAIT_UNTIL_IDLE() do {                                  \
+       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
+       OUT_RING( (RADEON_WAIT_2D_IDLECLEAN |                           \
+                  RADEON_WAIT_3D_IDLECLEAN |                           \
+                  RADEON_WAIT_HOST_IDLECLEAN) );                       \
+} while (0)
+
+#define RADEON_WAIT_UNTIL_PAGE_FLIPPED() do {                          \
+       OUT_RING( CP_PACKET0( RADEON_WAIT_UNTIL, 0 ) );                 \
+       OUT_RING( RADEON_WAIT_CRTC_PFLIP );                             \
+} while (0)
+
+#define RADEON_FLUSH_CACHE() do {                                      \
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
+               OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));  \
+               OUT_RING(RADEON_RB3D_DC_FLUSH);                         \
+       } else {                                                        \
+               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
+               OUT_RING(RADEON_RB3D_DC_FLUSH);                         \
+       }                                                               \
+} while (0)
+
+#define RADEON_PURGE_CACHE() do {                                      \
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
+               OUT_RING(CP_PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));  \
+               OUT_RING(RADEON_RB3D_DC_FLUSH_ALL);                     \
+       } else {                                                        \
+               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
+               OUT_RING(RADEON_RB3D_DC_FLUSH_ALL);                     \
+       }                                                               \
+} while (0)
+
+#define RADEON_FLUSH_ZCACHE() do {                                     \
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
+               OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));    \
+               OUT_RING(RADEON_RB3D_ZC_FLUSH);                         \
+       } else {                                                        \
+               OUT_RING(CP_PACKET0(R300_ZB_ZCACHE_CTLSTAT, 0));        \
+               OUT_RING(R300_ZC_FLUSH);                                \
+       }                                                               \
+} while (0)
+
+#define RADEON_PURGE_ZCACHE() do {                                     \
+       if ((dev_priv->flags & RADEON_FAMILY_MASK) <= CHIP_RV280) {     \
+               OUT_RING(CP_PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));    \
+               OUT_RING(RADEON_RB3D_ZC_FLUSH_ALL);                     \
+       } else {                                                        \
+               OUT_RING(CP_PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));    \
+               OUT_RING(R300_ZC_FLUSH_ALL);                            \
+       }                                                               \
+} while (0)
+
+/* ================================================================
+ * Misc helper macros
+ */
+
+/* Perfbox functionality only.
+ */
+#define RING_SPACE_TEST_WITH_RETURN( dev_priv )                                \
+do {                                                                   \
+       if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE)) {           \
+               u32 head = GET_RING_HEAD( dev_priv );                   \
+               if (head == dev_priv->ring.tail)                        \
+                       dev_priv->stats.boxes |= RADEON_BOX_DMA_IDLE;   \
+       }                                                               \
+} while (0)
+
+#define VB_AGE_TEST_WITH_RETURN( dev_priv )                            \
+do {                                                                   \
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;          \
+       if ( sarea_priv->last_dispatch >= RADEON_MAX_VB_AGE ) {         \
+               int __ret = radeon_do_cp_idle( dev_priv );              \
+               if ( __ret ) return __ret;                              \
+               sarea_priv->last_dispatch = 0;                          \
+               radeon_freelist_reset( dev );                           \
+       }                                                               \
+} while (0)
+
+#define RADEON_DISPATCH_AGE( age ) do {                                        \
+       OUT_RING( CP_PACKET0( RADEON_LAST_DISPATCH_REG, 0 ) );          \
+       OUT_RING( age );                                                \
+} while (0)
+
+#define RADEON_FRAME_AGE( age ) do {                                   \
+       OUT_RING( CP_PACKET0( RADEON_LAST_FRAME_REG, 0 ) );             \
+       OUT_RING( age );                                                \
+} while (0)
+
+#define RADEON_CLEAR_AGE( age ) do {                                   \
+       OUT_RING( CP_PACKET0( RADEON_LAST_CLEAR_REG, 0 ) );             \
+       OUT_RING( age );                                                \
+} while (0)
+
+/* ================================================================
+ * Ring control
+ */
+
+#define RADEON_VERBOSE 0
+
+#define RING_LOCALS    int write, _nr; unsigned int mask; u32 *ring;
+
+#define BEGIN_RING( n ) do {                                           \
+       if ( RADEON_VERBOSE ) {                                         \
+               DRM_INFO( "BEGIN_RING( %d )\n", (n));                   \
+       }                                                               \
+       if ( dev_priv->ring.space <= (n) * sizeof(u32) ) {              \
+                COMMIT_RING();                                         \
+               radeon_wait_ring( dev_priv, (n) * sizeof(u32) );        \
+       }                                                               \
+       _nr = n; dev_priv->ring.space -= (n) * sizeof(u32);             \
+       ring = dev_priv->ring.start;                                    \
+       write = dev_priv->ring.tail;                                    \
+       mask = dev_priv->ring.tail_mask;                                \
+} while (0)
+
+#define ADVANCE_RING() do {                                            \
+       if ( RADEON_VERBOSE ) {                                         \
+               DRM_INFO( "ADVANCE_RING() wr=0x%06x tail=0x%06x\n",     \
+                         write, dev_priv->ring.tail );                 \
+       }                                                               \
+       if (((dev_priv->ring.tail + _nr) & mask) != write) {            \
+               DRM_ERROR(                                              \
+                       "ADVANCE_RING(): mismatch: nr: %x write: %x line: %d\n",        \
+                       ((dev_priv->ring.tail + _nr) & mask),           \
+                       write, __LINE__);                                               \
+       } else                                                          \
+               dev_priv->ring.tail = write;                            \
+} while (0)
+
+#define COMMIT_RING() do {                                             \
+       /* Flush writes to ring */                                      \
+       DRM_MEMORYBARRIER();                                            \
+       GET_RING_HEAD( dev_priv );                                      \
+       RADEON_WRITE( RADEON_CP_RB_WPTR, dev_priv->ring.tail );         \
+       /* read from PCI bus to ensure correct posting */               \
+       RADEON_READ( RADEON_CP_RB_RPTR );                               \
+} while (0)
+
+#define OUT_RING( x ) do {                                             \
+       if ( RADEON_VERBOSE ) {                                         \
+               DRM_INFO( "   OUT_RING( 0x%08x ) at 0x%x\n",            \
+                          (unsigned int)(x), write );                  \
+       }                                                               \
+       ring[write++] = (x);                                            \
+       write &= mask;                                                  \
+} while (0)
+
+#define OUT_RING_REG( reg, val ) do {                                  \
+       OUT_RING( CP_PACKET0( reg, 0 ) );                               \
+       OUT_RING( val );                                                \
+} while (0)
+
+#define OUT_RING_TABLE( tab, sz ) do {                                 \
+       int _size = (sz);                                       \
+       int *_tab = (int *)(tab);                               \
+                                                               \
+       if (write + _size > mask) {                             \
+               int _i = (mask+1) - write;                      \
+               _size -= _i;                                    \
+               while (_i > 0 ) {                               \
+                       *(int *)(ring + write) = *_tab++;       \
+                       write++;                                \
+                       _i--;                                   \
+               }                                               \
+               write = 0;                                      \
+               _tab += _i;                                     \
+       }                                                       \
+       while (_size > 0) {                                     \
+               *(ring + write) = *_tab++;                      \
+               write++;                                        \
+               _size--;                                        \
+       }                                                       \
+       write &= mask;                                          \
+} while (0)
+
+#endif                         /* __RADEON_DRV_H__ */
diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
new file mode 100644 (file)
index 0000000..56decda
--- /dev/null
@@ -0,0 +1,424 @@
+/**
+ * \file radeon_ioc32.c
+ *
+ * 32-bit ioctl compatibility routines for the Radeon DRM.
+ *
+ * \author Paul Mackerras <paulus@samba.org>
+ *
+ * Copyright (C) Paul Mackerras 2005
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include <linux/compat.h>
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+
+typedef struct drm_radeon_init32 {
+       int func;
+       u32 sarea_priv_offset;
+       int is_pci;
+       int cp_mode;
+       int gart_size;
+       int ring_size;
+       int usec_timeout;
+
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+
+       u32 fb_offset;
+       u32 mmio_offset;
+       u32 ring_offset;
+       u32 ring_rptr_offset;
+       u32 buffers_offset;
+       u32 gart_textures_offset;
+} drm_radeon_init32_t;
+
+static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
+                                unsigned long arg)
+{
+       drm_radeon_init32_t init32;
+       drm_radeon_init_t __user *init;
+
+       if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
+               return -EFAULT;
+
+       init = compat_alloc_user_space(sizeof(*init));
+       if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
+           || __put_user(init32.func, &init->func)
+           || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
+           || __put_user(init32.is_pci, &init->is_pci)
+           || __put_user(init32.cp_mode, &init->cp_mode)
+           || __put_user(init32.gart_size, &init->gart_size)
+           || __put_user(init32.ring_size, &init->ring_size)
+           || __put_user(init32.usec_timeout, &init->usec_timeout)
+           || __put_user(init32.fb_bpp, &init->fb_bpp)
+           || __put_user(init32.front_offset, &init->front_offset)
+           || __put_user(init32.front_pitch, &init->front_pitch)
+           || __put_user(init32.back_offset, &init->back_offset)
+           || __put_user(init32.back_pitch, &init->back_pitch)
+           || __put_user(init32.depth_bpp, &init->depth_bpp)
+           || __put_user(init32.depth_offset, &init->depth_offset)
+           || __put_user(init32.depth_pitch, &init->depth_pitch)
+           || __put_user(init32.fb_offset, &init->fb_offset)
+           || __put_user(init32.mmio_offset, &init->mmio_offset)
+           || __put_user(init32.ring_offset, &init->ring_offset)
+           || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
+           || __put_user(init32.buffers_offset, &init->buffers_offset)
+           || __put_user(init32.gart_textures_offset,
+                         &init->gart_textures_offset))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
+}
+
+typedef struct drm_radeon_clear32 {
+       unsigned int flags;
+       unsigned int clear_color;
+       unsigned int clear_depth;
+       unsigned int color_mask;
+       unsigned int depth_mask;        /* misnamed field:  should be stencil */
+       u32 depth_boxes;
+} drm_radeon_clear32_t;
+
+static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
+                                 unsigned long arg)
+{
+       drm_radeon_clear32_t clr32;
+       drm_radeon_clear_t __user *clr;
+
+       if (copy_from_user(&clr32, (void __user *)arg, sizeof(clr32)))
+               return -EFAULT;
+
+       clr = compat_alloc_user_space(sizeof(*clr));
+       if (!access_ok(VERIFY_WRITE, clr, sizeof(*clr))
+           || __put_user(clr32.flags, &clr->flags)
+           || __put_user(clr32.clear_color, &clr->clear_color)
+           || __put_user(clr32.clear_depth, &clr->clear_depth)
+           || __put_user(clr32.color_mask, &clr->color_mask)
+           || __put_user(clr32.depth_mask, &clr->depth_mask)
+           || __put_user((void __user *)(unsigned long)clr32.depth_boxes,
+                         &clr->depth_boxes))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
+}
+
+typedef struct drm_radeon_stipple32 {
+       u32 mask;
+} drm_radeon_stipple32_t;
+
+static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
+                                   unsigned long arg)
+{
+       drm_radeon_stipple32_t __user *argp = (void __user *)arg;
+       drm_radeon_stipple_t __user *request;
+       u32 mask;
+
+       if (get_user(mask, &argp->mask))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user((unsigned int __user *)(unsigned long)mask,
+                         &request->mask))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
+}
+
+typedef struct drm_radeon_tex_image32 {
+       unsigned int x, y;      /* Blit coordinates */
+       unsigned int width, height;
+       u32 data;
+} drm_radeon_tex_image32_t;
+
+typedef struct drm_radeon_texture32 {
+       unsigned int offset;
+       int pitch;
+       int format;
+       int width;              /* Texture image coordinates */
+       int height;
+       u32 image;
+} drm_radeon_texture32_t;
+
+static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
+                                   unsigned long arg)
+{
+       drm_radeon_texture32_t req32;
+       drm_radeon_texture_t __user *request;
+       drm_radeon_tex_image32_t img32;
+       drm_radeon_tex_image_t __user *image;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+       if (req32.image == 0)
+               return -EINVAL;
+       if (copy_from_user(&img32, (void __user *)(unsigned long)req32.image,
+                          sizeof(img32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request) + sizeof(*image));
+       if (!access_ok(VERIFY_WRITE, request,
+                      sizeof(*request) + sizeof(*image)))
+               return -EFAULT;
+       image = (drm_radeon_tex_image_t __user *) (request + 1);
+
+       if (__put_user(req32.offset, &request->offset)
+           || __put_user(req32.pitch, &request->pitch)
+           || __put_user(req32.format, &request->format)
+           || __put_user(req32.width, &request->width)
+           || __put_user(req32.height, &request->height)
+           || __put_user(image, &request->image)
+           || __put_user(img32.x, &image->x)
+           || __put_user(img32.y, &image->y)
+           || __put_user(img32.width, &image->width)
+           || __put_user(img32.height, &image->height)
+           || __put_user((const void __user *)(unsigned long)img32.data,
+                         &image->data))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
+}
+
+typedef struct drm_radeon_vertex2_32 {
+       int idx;                /* Index of vertex buffer */
+       int discard;            /* Client finished with buffer? */
+       int nr_states;
+       u32 state;
+       int nr_prims;
+       u32 prim;
+} drm_radeon_vertex2_32_t;
+
+static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
+                                   unsigned long arg)
+{
+       drm_radeon_vertex2_32_t req32;
+       drm_radeon_vertex2_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.idx, &request->idx)
+           || __put_user(req32.discard, &request->discard)
+           || __put_user(req32.nr_states, &request->nr_states)
+           || __put_user((void __user *)(unsigned long)req32.state,
+                         &request->state)
+           || __put_user(req32.nr_prims, &request->nr_prims)
+           || __put_user((void __user *)(unsigned long)req32.prim,
+                         &request->prim))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
+}
+
+typedef struct drm_radeon_cmd_buffer32 {
+       int bufsz;
+       u32 buf;
+       int nbox;
+       u32 boxes;
+} drm_radeon_cmd_buffer32_t;
+
+static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
+                                  unsigned long arg)
+{
+       drm_radeon_cmd_buffer32_t req32;
+       drm_radeon_cmd_buffer_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.bufsz, &request->bufsz)
+           || __put_user((void __user *)(unsigned long)req32.buf,
+                         &request->buf)
+           || __put_user(req32.nbox, &request->nbox)
+           || __put_user((void __user *)(unsigned long)req32.boxes,
+                         &request->boxes))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
+}
+
+typedef struct drm_radeon_getparam32 {
+       int param;
+       u32 value;
+} drm_radeon_getparam32_t;
+
+static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
+                                    unsigned long arg)
+{
+       drm_radeon_getparam32_t req32;
+       drm_radeon_getparam_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.param, &request->param)
+           || __put_user((void __user *)(unsigned long)req32.value,
+                         &request->value))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
+}
+
+typedef struct drm_radeon_mem_alloc32 {
+       int region;
+       int alignment;
+       int size;
+       u32 region_offset;      /* offset from start of fb or GART */
+} drm_radeon_mem_alloc32_t;
+
+static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
+                                  unsigned long arg)
+{
+       drm_radeon_mem_alloc32_t req32;
+       drm_radeon_mem_alloc_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.region, &request->region)
+           || __put_user(req32.alignment, &request->alignment)
+           || __put_user(req32.size, &request->size)
+           || __put_user((int __user *)(unsigned long)req32.region_offset,
+                         &request->region_offset))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
+}
+
+typedef struct drm_radeon_irq_emit32 {
+       u32 irq_seq;
+} drm_radeon_irq_emit32_t;
+
+static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
+                                 unsigned long arg)
+{
+       drm_radeon_irq_emit32_t req32;
+       drm_radeon_irq_emit_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user((int __user *)(unsigned long)req32.irq_seq,
+                         &request->irq_seq))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_path.dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
+}
+
+/* The two 64-bit arches where alignof(u64)==4 in 32-bit code */
+#if defined (CONFIG_X86_64) || defined(CONFIG_IA64)
+typedef struct drm_radeon_setparam32 {
+       int param;
+       u64 value;
+} __attribute__((packed)) drm_radeon_setparam32_t;
+
+static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
+                                    unsigned long arg)
+{
+       drm_radeon_setparam32_t req32;
+       drm_radeon_setparam_t __user *request;
+
+       if (copy_from_user(&req32, (void __user *) arg, sizeof(req32)))
+               return -EFAULT;
+
+       request = compat_alloc_user_space(sizeof(*request));
+       if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
+           || __put_user(req32.param, &request->param)
+           || __put_user((void __user *)(unsigned long)req32.value,
+                         &request->value))
+               return -EFAULT;
+
+       return drm_ioctl(file->f_dentry->d_inode, file,
+                        DRM_IOCTL_RADEON_SETPARAM, (unsigned long) request);
+}
+#else
+#define compat_radeon_cp_setparam NULL
+#endif /* X86_64 || IA64 */
+
+drm_ioctl_compat_t *radeon_compat_ioctls[] = {
+       [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
+       [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
+       [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
+       [DRM_RADEON_TEXTURE] = compat_radeon_cp_texture,
+       [DRM_RADEON_VERTEX2] = compat_radeon_cp_vertex2,
+       [DRM_RADEON_CMDBUF] = compat_radeon_cp_cmdbuf,
+       [DRM_RADEON_GETPARAM] = compat_radeon_cp_getparam,
+       [DRM_RADEON_SETPARAM] = compat_radeon_cp_setparam,
+       [DRM_RADEON_ALLOC] = compat_radeon_mem_alloc,
+       [DRM_RADEON_IRQ_EMIT] = compat_radeon_irq_emit,
+};
+
+/**
+ * Called whenever a 32-bit process running under a 64-bit kernel
+ * performs an ioctl on /dev/dri/card<n>.
+ *
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument.
+ * \return zero on success or negative number on failure.
+ */
+long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int nr = DRM_IOCTL_NR(cmd);
+       drm_ioctl_compat_t *fn = NULL;
+       int ret;
+
+       if (nr < DRM_COMMAND_BASE)
+               return drm_compat_ioctl(filp, cmd, arg);
+
+       if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
+               fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
+
+       lock_kernel();          /* XXX for now */
+       if (fn != NULL)
+               ret = (*fn) (filp, cmd, arg);
+       else
+               ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
new file mode 100644 (file)
index 0000000..ee40d19
--- /dev/null
@@ -0,0 +1,320 @@
+/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */
+/*
+ * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
+ *
+ * The Weather Channel (TM) funded Tungsten Graphics to develop the
+ * initial release of the Radeon 8500 driver under the XFree86 license.
+ * This notice must be preserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Michel Dänzer <michel@daenzer.net>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+
+static __inline__ u32 radeon_acknowledge_irqs(drm_radeon_private_t * dev_priv,
+                                             u32 mask)
+{
+       u32 irqs = RADEON_READ(RADEON_GEN_INT_STATUS) & mask;
+       if (irqs)
+               RADEON_WRITE(RADEON_GEN_INT_STATUS, irqs);
+       return irqs;
+}
+
+/* Interrupts - Used for device synchronization and flushing in the
+ * following circumstances:
+ *
+ * - Exclusive FB access with hw idle:
+ *    - Wait for GUI Idle (?) interrupt, then do normal flush.
+ *
+ * - Frame throttling, NV_fence:
+ *    - Drop marker irq's into command stream ahead of time.
+ *    - Wait on irq's with lock *not held*
+ *    - Check each for termination condition
+ *
+ * - Internally in cp_getbuffer, etc:
+ *    - as above, but wait with lock held???
+ *
+ * NOTE: These functions are misleadingly named -- the irq's aren't
+ * tied to dma at all, this is just a hangover from dri prehistory.
+ */
+
+irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+       u32 stat;
+
+       /* Only consider the bits we're interested in - others could be used
+        * outside the DRM
+        */
+       stat = radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
+                                                 RADEON_CRTC_VBLANK_STAT |
+                                                 RADEON_CRTC2_VBLANK_STAT));
+       if (!stat)
+               return IRQ_NONE;
+
+       stat &= dev_priv->irq_enable_reg;
+
+       /* SW interrupt */
+       if (stat & RADEON_SW_INT_TEST) {
+               DRM_WAKEUP(&dev_priv->swi_queue);
+       }
+
+       /* VBLANK interrupt */
+       if (stat & (RADEON_CRTC_VBLANK_STAT|RADEON_CRTC2_VBLANK_STAT)) {
+               int vblank_crtc = dev_priv->vblank_crtc;
+
+               if ((vblank_crtc &
+                    (DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) ==
+                   (DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) {
+                       if (stat & RADEON_CRTC_VBLANK_STAT)
+                               atomic_inc(&dev->vbl_received);
+                       if (stat & RADEON_CRTC2_VBLANK_STAT)
+                               atomic_inc(&dev->vbl_received2);
+               } else if (((stat & RADEON_CRTC_VBLANK_STAT) &&
+                          (vblank_crtc & DRM_RADEON_VBLANK_CRTC1)) ||
+                          ((stat & RADEON_CRTC2_VBLANK_STAT) &&
+                           (vblank_crtc & DRM_RADEON_VBLANK_CRTC2)))
+                       atomic_inc(&dev->vbl_received);
+
+               DRM_WAKEUP(&dev->vbl_queue);
+               drm_vbl_send_signals(dev);
+       }
+
+       return IRQ_HANDLED;
+}
+
+static int radeon_emit_irq(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       unsigned int ret;
+       RING_LOCALS;
+
+       atomic_inc(&dev_priv->swi_emitted);
+       ret = atomic_read(&dev_priv->swi_emitted);
+
+       BEGIN_RING(4);
+       OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
+       OUT_RING_REG(RADEON_GEN_INT_STATUS, RADEON_SW_INT_FIRE);
+       ADVANCE_RING();
+       COMMIT_RING();
+
+       return ret;
+}
+
+static int radeon_wait_irq(struct drm_device * dev, int swi_nr)
+{
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+       int ret = 0;
+
+       if (RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr)
+               return 0;
+
+       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+       DRM_WAIT_ON(ret, dev_priv->swi_queue, 3 * DRM_HZ,
+                   RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr);
+
+       return ret;
+}
+
+static int radeon_driver_vblank_do_wait(struct drm_device * dev,
+                                       unsigned int *sequence, int crtc)
+{
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+       unsigned int cur_vblank;
+       int ret = 0;
+       int ack = 0;
+       atomic_t *counter;
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       if (crtc == DRM_RADEON_VBLANK_CRTC1) {
+               counter = &dev->vbl_received;
+               ack |= RADEON_CRTC_VBLANK_STAT;
+       } else if (crtc == DRM_RADEON_VBLANK_CRTC2) {
+               counter = &dev->vbl_received2;
+               ack |= RADEON_CRTC2_VBLANK_STAT;
+       } else
+               return -EINVAL;
+
+       radeon_acknowledge_irqs(dev_priv, ack);
+
+       dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+
+       /* Assume that the user has missed the current sequence number
+        * by about a day rather than she wants to wait for years
+        * using vertical blanks...
+        */
+       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
+                   (((cur_vblank = atomic_read(counter))
+                     - *sequence) <= (1 << 23)));
+
+       *sequence = cur_vblank;
+
+       return ret;
+}
+
+int radeon_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
+{
+       return radeon_driver_vblank_do_wait(dev, sequence, DRM_RADEON_VBLANK_CRTC1);
+}
+
+int radeon_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
+{
+       return radeon_driver_vblank_do_wait(dev, sequence, DRM_RADEON_VBLANK_CRTC2);
+}
+
+/* Needs the lock as it touches the ring.
+ */
+int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_irq_emit_t *emit = data;
+       int result;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       result = radeon_emit_irq(dev);
+
+       if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+/* Doesn't need the hardware lock.
+ */
+int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_irq_wait_t *irqwait = data;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       return radeon_wait_irq(dev, irqwait->irq_seq);
+}
+
+void radeon_enable_interrupt(struct drm_device *dev)
+{
+       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
+
+       dev_priv->irq_enable_reg = RADEON_SW_INT_ENABLE;
+       if (dev_priv->vblank_crtc & DRM_RADEON_VBLANK_CRTC1)
+               dev_priv->irq_enable_reg |= RADEON_CRTC_VBLANK_MASK;
+
+       if (dev_priv->vblank_crtc & DRM_RADEON_VBLANK_CRTC2)
+               dev_priv->irq_enable_reg |= RADEON_CRTC2_VBLANK_MASK;
+
+       RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg);
+       dev_priv->irq_enabled = 1;
+}
+
+/* drm_dma.h hooks
+*/
+void radeon_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+
+       /* Disable *all* interrupts */
+       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
+
+       /* Clear bits if they're already high */
+       radeon_acknowledge_irqs(dev_priv, (RADEON_SW_INT_TEST_ACK |
+                                          RADEON_CRTC_VBLANK_STAT |
+                                          RADEON_CRTC2_VBLANK_STAT));
+}
+
+void radeon_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+
+       atomic_set(&dev_priv->swi_emitted, 0);
+       DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
+
+       radeon_enable_interrupt(dev);
+}
+
+void radeon_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv =
+           (drm_radeon_private_t *) dev->dev_private;
+       if (!dev_priv)
+               return;
+
+       dev_priv->irq_enabled = 0;
+
+       /* Disable *all* interrupts */
+       RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
+}
+
+
+int radeon_vblank_crtc_get(struct drm_device *dev)
+{
+       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
+       u32 flag;
+       u32 value;
+
+       flag = RADEON_READ(RADEON_GEN_INT_CNTL);
+       value = 0;
+
+       if (flag & RADEON_CRTC_VBLANK_MASK)
+               value |= DRM_RADEON_VBLANK_CRTC1;
+
+       if (flag & RADEON_CRTC2_VBLANK_MASK)
+               value |= DRM_RADEON_VBLANK_CRTC2;
+       return value;
+}
+
+int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value)
+{
+       drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private;
+       if (value & ~(DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) {
+               DRM_ERROR("called with invalid crtc 0x%x\n", (unsigned int)value);
+               return -EINVAL;
+       }
+       dev_priv->vblank_crtc = (unsigned int)value;
+       radeon_enable_interrupt(dev);
+       return 0;
+}
diff --git a/drivers/gpu/drm/radeon/radeon_mem.c b/drivers/gpu/drm/radeon/radeon_mem.c
new file mode 100644 (file)
index 0000000..4af5286
--- /dev/null
@@ -0,0 +1,302 @@
+/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- */
+/*
+ * Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
+ *
+ * The Weather Channel (TM) funded Tungsten Graphics to develop the
+ * initial release of the Radeon 8500 driver under the XFree86 license.
+ * This notice must be preserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+
+/* Very simple allocator for GART memory, working on a static range
+ * already mapped into each client's address space.
+ */
+
+static struct mem_block *split_block(struct mem_block *p, int start, int size,
+                                    struct drm_file *file_priv)
+{
+       /* Maybe cut off the start of an existing block */
+       if (start > p->start) {
+               struct mem_block *newblock =
+                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
+               if (!newblock)
+                       goto out;
+               newblock->start = start;
+               newblock->size = p->size - (start - p->start);
+               newblock->file_priv = NULL;
+               newblock->next = p->next;
+               newblock->prev = p;
+               p->next->prev = newblock;
+               p->next = newblock;
+               p->size -= newblock->size;
+               p = newblock;
+       }
+
+       /* Maybe cut off the end of an existing block */
+       if (size < p->size) {
+               struct mem_block *newblock =
+                   drm_alloc(sizeof(*newblock), DRM_MEM_BUFS);
+               if (!newblock)
+                       goto out;
+               newblock->start = start + size;
+               newblock->size = p->size - size;
+               newblock->file_priv = NULL;
+               newblock->next = p->next;
+               newblock->prev = p;
+               p->next->prev = newblock;
+               p->next = newblock;
+               p->size = size;
+       }
+
+      out:
+       /* Our block is in the middle */
+       p->file_priv = file_priv;
+       return p;
+}
+
+static struct mem_block *alloc_block(struct mem_block *heap, int size,
+                                    int align2, struct drm_file *file_priv)
+{
+       struct mem_block *p;
+       int mask = (1 << align2) - 1;
+
+       list_for_each(p, heap) {
+               int start = (p->start + mask) & ~mask;
+               if (p->file_priv == NULL && start + size <= p->start + p->size)
+                       return split_block(p, start, size, file_priv);
+       }
+
+       return NULL;
+}
+
+static struct mem_block *find_block(struct mem_block *heap, int start)
+{
+       struct mem_block *p;
+
+       list_for_each(p, heap)
+           if (p->start == start)
+               return p;
+
+       return NULL;
+}
+
+static void free_block(struct mem_block *p)
+{
+       p->file_priv = NULL;
+
+       /* Assumes a single contiguous range.  Needs a special file_priv in
+        * 'heap' to stop it being subsumed.
+        */
+       if (p->next->file_priv == NULL) {
+               struct mem_block *q = p->next;
+               p->size += q->size;
+               p->next = q->next;
+               p->next->prev = p;
+               drm_free(q, sizeof(*q), DRM_MEM_BUFS);
+       }
+
+       if (p->prev->file_priv == NULL) {
+               struct mem_block *q = p->prev;
+               q->size += p->size;
+               q->next = p->next;
+               q->next->prev = q;
+               drm_free(p, sizeof(*q), DRM_MEM_BUFS);
+       }
+}
+
+/* Initialize.  How to check for an uninitialized heap?
+ */
+static int init_heap(struct mem_block **heap, int start, int size)
+{
+       struct mem_block *blocks = drm_alloc(sizeof(*blocks), DRM_MEM_BUFS);
+
+       if (!blocks)
+               return -ENOMEM;
+
+       *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFS);
+       if (!*heap) {
+               drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFS);
+               return -ENOMEM;
+       }
+
+       blocks->start = start;
+       blocks->size = size;
+       blocks->file_priv = NULL;
+       blocks->next = blocks->prev = *heap;
+
+       memset(*heap, 0, sizeof(**heap));
+       (*heap)->file_priv = (struct drm_file *) - 1;
+       (*heap)->next = (*heap)->prev = blocks;
+       return 0;
+}
+
+/* Free all blocks associated with the releasing file.
+ */
+void radeon_mem_release(struct drm_file *file_priv, struct mem_block *heap)
+{
+       struct mem_block *p;
+
+       if (!heap || !heap->next)
+               return;
+
+       list_for_each(p, heap) {
+               if (p->file_priv == file_priv)
+                       p->file_priv = NULL;
+       }
+
+       /* Assumes a single contiguous range.  Needs a special file_priv in
+        * 'heap' to stop it being subsumed.
+        */
+       list_for_each(p, heap) {
+               while (p->file_priv == NULL && p->next->file_priv == NULL) {
+                       struct mem_block *q = p->next;
+                       p->size += q->size;
+                       p->next = q->next;
+                       p->next->prev = p;
+                       drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
+               }
+       }
+}
+
+/* Shutdown.
+ */
+void radeon_mem_takedown(struct mem_block **heap)
+{
+       struct mem_block *p;
+
+       if (!*heap)
+               return;
+
+       for (p = (*heap)->next; p != *heap;) {
+               struct mem_block *q = p;
+               p = p->next;
+               drm_free(q, sizeof(*q), DRM_MEM_DRIVER);
+       }
+
+       drm_free(*heap, sizeof(**heap), DRM_MEM_DRIVER);
+       *heap = NULL;
+}
+
+/* IOCTL HANDLERS */
+
+static struct mem_block **get_heap(drm_radeon_private_t * dev_priv, int region)
+{
+       switch (region) {
+       case RADEON_MEM_REGION_GART:
+               return &dev_priv->gart_heap;
+       case RADEON_MEM_REGION_FB:
+               return &dev_priv->fb_heap;
+       default:
+               return NULL;
+       }
+}
+
+int radeon_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_mem_alloc_t *alloc = data;
+       struct mem_block *block, **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, alloc->region);
+       if (!heap || !*heap)
+               return -EFAULT;
+
+       /* Make things easier on ourselves: all allocations at least
+        * 4k aligned.
+        */
+       if (alloc->alignment < 12)
+               alloc->alignment = 12;
+
+       block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv);
+
+       if (!block)
+               return -ENOMEM;
+
+       if (DRM_COPY_TO_USER(alloc->region_offset, &block->start,
+                            sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+int radeon_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_mem_free_t *memfree = data;
+       struct mem_block *block, **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, memfree->region);
+       if (!heap || !*heap)
+               return -EFAULT;
+
+       block = find_block(*heap, memfree->region_offset);
+       if (!block)
+               return -EFAULT;
+
+       if (block->file_priv != file_priv)
+               return -EPERM;
+
+       free_block(block);
+       return 0;
+}
+
+int radeon_mem_init_heap(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_mem_init_heap_t *initheap = data;
+       struct mem_block **heap;
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       heap = get_heap(dev_priv, initheap->region);
+       if (!heap)
+               return -EFAULT;
+
+       if (*heap) {
+               DRM_ERROR("heap already initialized?");
+               return -EFAULT;
+       }
+
+       return init_heap(heap, initheap->start, initheap->size);
+}
diff --git a/drivers/gpu/drm/radeon/radeon_microcode.h b/drivers/gpu/drm/radeon/radeon_microcode.h
new file mode 100644 (file)
index 0000000..a348c9e
--- /dev/null
@@ -0,0 +1,1844 @@
+/*
+ * Copyright 2007 Advanced Micro Devices, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef RADEON_MICROCODE_H
+#define RADEON_MICROCODE_H
+
+/* production radeon ucode r1xx-r6xx */
+static const u32 R100_cp_microcode[][2] = {
+    { 0x21007000, 0000000000 },
+    { 0x20007000, 0000000000 },
+    { 0x000000b4, 0x00000004 },
+    { 0x000000b8, 0x00000004 },
+    { 0x6f5b4d4c, 0000000000 },
+    { 0x4c4c427f, 0000000000 },
+    { 0x5b568a92, 0000000000 },
+    { 0x4ca09c6d, 0000000000 },
+    { 0xad4c4c4c, 0000000000 },
+    { 0x4ce1af3d, 0000000000 },
+    { 0xd8afafaf, 0000000000 },
+    { 0xd64c4cdc, 0000000000 },
+    { 0x4cd10d10, 0000000000 },
+    { 0x000f0000, 0x00000016 },
+    { 0x362f242d, 0000000000 },
+    { 0x00000012, 0x00000004 },
+    { 0x000f0000, 0x00000016 },
+    { 0x362f282d, 0000000000 },
+    { 0x000380e7, 0x00000002 },
+    { 0x04002c97, 0x00000002 },
+    { 0x000f0001, 0x00000016 },
+    { 0x333a3730, 0000000000 },
+    { 0x000077ef, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x00000021, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00061000, 0x00000002 },
+    { 0x00000021, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00061000, 0x00000002 },
+    { 0x00000021, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00000017, 0x00000004 },
+    { 0x0003802b, 0x00000002 },
+    { 0x040067e0, 0x00000002 },
+    { 0x00000017, 0x00000004 },
+    { 0x000077e0, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x000037e1, 0x00000002 },
+    { 0x040067e1, 0x00000006 },
+    { 0x000077e0, 0x00000002 },
+    { 0x000077e1, 0x00000002 },
+    { 0x000077e1, 0x00000006 },
+    { 0xffffffff, 0000000000 },
+    { 0x10000000, 0000000000 },
+    { 0x0003802b, 0x00000002 },
+    { 0x040067e0, 0x00000006 },
+    { 0x00007675, 0x00000002 },
+    { 0x00007676, 0x00000002 },
+    { 0x00007677, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0003802c, 0x00000002 },
+    { 0x04002676, 0x00000002 },
+    { 0x00007677, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0000002f, 0x00000018 },
+    { 0x0000002f, 0x00000018 },
+    { 0000000000, 0x00000006 },
+    { 0x00000030, 0x00000018 },
+    { 0x00000030, 0x00000018 },
+    { 0000000000, 0x00000006 },
+    { 0x01605000, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x00098000, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x64c0603e, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00080000, 0x00000016 },
+    { 0000000000, 0000000000 },
+    { 0x0400251d, 0x00000002 },
+    { 0x00007580, 0x00000002 },
+    { 0x00067581, 0x00000002 },
+    { 0x04002580, 0x00000002 },
+    { 0x00067581, 0x00000002 },
+    { 0x00000049, 0x00000004 },
+    { 0x00005000, 0000000000 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x0000750e, 0x00000002 },
+    { 0x00019000, 0x00000002 },
+    { 0x00011055, 0x00000014 },
+    { 0x00000055, 0x00000012 },
+    { 0x0400250f, 0x00000002 },
+    { 0x0000504f, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00007565, 0x00000002 },
+    { 0x00007566, 0x00000002 },
+    { 0x00000058, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x01e655b4, 0x00000002 },
+    { 0x4401b0e4, 0x00000002 },
+    { 0x01c110e4, 0x00000002 },
+    { 0x26667066, 0x00000018 },
+    { 0x040c2565, 0x00000002 },
+    { 0x00000066, 0x00000018 },
+    { 0x04002564, 0x00000002 },
+    { 0x00007566, 0x00000002 },
+    { 0x0000005d, 0x00000004 },
+    { 0x00401069, 0x00000008 },
+    { 0x00101000, 0x00000002 },
+    { 0x000d80ff, 0x00000002 },
+    { 0x0080006c, 0x00000008 },
+    { 0x000f9000, 0x00000002 },
+    { 0x000e00ff, 0x00000002 },
+    { 0000000000, 0x00000006 },
+    { 0x0000008f, 0x00000018 },
+    { 0x0000005b, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00007576, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x00009000, 0x00000002 },
+    { 0x00041000, 0x00000002 },
+    { 0x0c00350e, 0x00000002 },
+    { 0x00049000, 0x00000002 },
+    { 0x00051000, 0x00000002 },
+    { 0x01e785f8, 0x00000002 },
+    { 0x00200000, 0x00000002 },
+    { 0x0060007e, 0x0000000c },
+    { 0x00007563, 0x00000002 },
+    { 0x006075f0, 0x00000021 },
+    { 0x20007073, 0x00000004 },
+    { 0x00005073, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00007576, 0x00000002 },
+    { 0x00007577, 0x00000002 },
+    { 0x0000750e, 0x00000002 },
+    { 0x0000750f, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00600083, 0x0000000c },
+    { 0x006075f0, 0x00000021 },
+    { 0x000075f8, 0x00000002 },
+    { 0x00000083, 0x00000004 },
+    { 0x000a750e, 0x00000002 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x0020750f, 0x00000002 },
+    { 0x00600086, 0x00000004 },
+    { 0x00007570, 0x00000002 },
+    { 0x00007571, 0x00000002 },
+    { 0x00007572, 0x00000006 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00005000, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00007568, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x00000095, 0x0000000c },
+    { 0x00058000, 0x00000002 },
+    { 0x0c607562, 0x00000002 },
+    { 0x00000097, 0x00000004 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x00600096, 0x00000004 },
+    { 0x400070e5, 0000000000 },
+    { 0x000380e6, 0x00000002 },
+    { 0x040025c5, 0x00000002 },
+    { 0x000380e5, 0x00000002 },
+    { 0x000000a8, 0x0000001c },
+    { 0x000650aa, 0x00000018 },
+    { 0x040025bb, 0x00000002 },
+    { 0x000610ab, 0x00000018 },
+    { 0x040075bc, 0000000000 },
+    { 0x000075bb, 0x00000002 },
+    { 0x000075bc, 0000000000 },
+    { 0x00090000, 0x00000006 },
+    { 0x00090000, 0x00000002 },
+    { 0x000d8002, 0x00000006 },
+    { 0x00007832, 0x00000002 },
+    { 0x00005000, 0x00000002 },
+    { 0x000380e7, 0x00000002 },
+    { 0x04002c97, 0x00000002 },
+    { 0x00007820, 0x00000002 },
+    { 0x00007821, 0x00000002 },
+    { 0x00007800, 0000000000 },
+    { 0x01200000, 0x00000002 },
+    { 0x20077000, 0x00000002 },
+    { 0x01200000, 0x00000002 },
+    { 0x20007000, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x0120751b, 0x00000002 },
+    { 0x8040750a, 0x00000002 },
+    { 0x8040750b, 0x00000002 },
+    { 0x00110000, 0x00000002 },
+    { 0x000380e5, 0x00000002 },
+    { 0x000000c6, 0x0000001c },
+    { 0x000610ab, 0x00000018 },
+    { 0x844075bd, 0x00000002 },
+    { 0x000610aa, 0x00000018 },
+    { 0x840075bb, 0x00000002 },
+    { 0x000610ab, 0x00000018 },
+    { 0x844075bc, 0x00000002 },
+    { 0x000000c9, 0x00000004 },
+    { 0x804075bd, 0x00000002 },
+    { 0x800075bb, 0x00000002 },
+    { 0x804075bc, 0x00000002 },
+    { 0x00108000, 0x00000002 },
+    { 0x01400000, 0x00000002 },
+    { 0x006000cd, 0x0000000c },
+    { 0x20c07000, 0x00000020 },
+    { 0x000000cf, 0x00000012 },
+    { 0x00800000, 0x00000006 },
+    { 0x0080751d, 0x00000006 },
+    { 0000000000, 0000000000 },
+    { 0x0000775c, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00661000, 0x00000002 },
+    { 0x0460275d, 0x00000020 },
+    { 0x00004000, 0000000000 },
+    { 0x01e00830, 0x00000002 },
+    { 0x21007000, 0000000000 },
+    { 0x6464614d, 0000000000 },
+    { 0x69687420, 0000000000 },
+    { 0x00000073, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x00005000, 0x00000002 },
+    { 0x000380d0, 0x00000002 },
+    { 0x040025e0, 0x00000002 },
+    { 0x000075e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000380e0, 0x00000002 },
+    { 0x04002394, 0x00000002 },
+    { 0x00005000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x00000008, 0000000000 },
+    { 0x00000004, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 R200_cp_microcode[][2] = {
+    { 0x21007000, 0000000000 },
+    { 0x20007000, 0000000000 },
+    { 0x000000bf, 0x00000004 },
+    { 0x000000c3, 0x00000004 },
+    { 0x7a685e5d, 0000000000 },
+    { 0x5d5d5588, 0000000000 },
+    { 0x68659197, 0000000000 },
+    { 0x5da19f78, 0000000000 },
+    { 0x5d5d5d5d, 0000000000 },
+    { 0x5dee5d50, 0000000000 },
+    { 0xf2acacac, 0000000000 },
+    { 0xe75df9e9, 0000000000 },
+    { 0xb1dd0e11, 0000000000 },
+    { 0xe2afafaf, 0000000000 },
+    { 0x000f0000, 0x00000016 },
+    { 0x452f232d, 0000000000 },
+    { 0x00000013, 0x00000004 },
+    { 0x000f0000, 0x00000016 },
+    { 0x452f272d, 0000000000 },
+    { 0x000f0001, 0x00000016 },
+    { 0x3e4d4a37, 0000000000 },
+    { 0x000077ef, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x00000020, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00061000, 0x00000002 },
+    { 0x00000020, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00061000, 0x00000002 },
+    { 0x00000020, 0x0000001a },
+    { 0x00004000, 0x0000001e },
+    { 0x00000016, 0x00000004 },
+    { 0x0003802a, 0x00000002 },
+    { 0x040067e0, 0x00000002 },
+    { 0x00000016, 0x00000004 },
+    { 0x000077e0, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x000037e1, 0x00000002 },
+    { 0x040067e1, 0x00000006 },
+    { 0x000077e0, 0x00000002 },
+    { 0x000077e1, 0x00000002 },
+    { 0x000077e1, 0x00000006 },
+    { 0xffffffff, 0000000000 },
+    { 0x10000000, 0000000000 },
+    { 0x07f007f0, 0000000000 },
+    { 0x0003802a, 0x00000002 },
+    { 0x040067e0, 0x00000006 },
+    { 0x0003802c, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002743, 0x00000002 },
+    { 0x00007675, 0x00000002 },
+    { 0x00007676, 0x00000002 },
+    { 0x00007677, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0003802c, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002743, 0x00000002 },
+    { 0x00007676, 0x00000002 },
+    { 0x00007677, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0003802b, 0x00000002 },
+    { 0x04002676, 0x00000002 },
+    { 0x00007677, 0x00000002 },
+    { 0x0003802c, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002743, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0003802c, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002741, 0x00000002 },
+    { 0x04002743, 0x00000002 },
+    { 0x00007678, 0x00000006 },
+    { 0x0000002f, 0x00000018 },
+    { 0x0000002f, 0x00000018 },
+    { 0000000000, 0x00000006 },
+    { 0x00000037, 0x00000018 },
+    { 0x00000037, 0x00000018 },
+    { 0000000000, 0x00000006 },
+    { 0x01605000, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x00098000, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x64c06051, 0x00000004 },
+    { 0x00080000, 0x00000016 },
+    { 0000000000, 0000000000 },
+    { 0x0400251d, 0x00000002 },
+    { 0x00007580, 0x00000002 },
+    { 0x00067581, 0x00000002 },
+    { 0x04002580, 0x00000002 },
+    { 0x00067581, 0x00000002 },
+    { 0x0000005a, 0x00000004 },
+    { 0x00005000, 0000000000 },
+    { 0x00061000, 0x00000002 },
+    { 0x0000750e, 0x00000002 },
+    { 0x00019000, 0x00000002 },
+    { 0x00011064, 0x00000014 },
+    { 0x00000064, 0x00000012 },
+    { 0x0400250f, 0x00000002 },
+    { 0x0000505e, 0x00000004 },
+    { 0x00007565, 0x00000002 },
+    { 0x00007566, 0x00000002 },
+    { 0x00000065, 0x00000004 },
+    { 0x01e655b4, 0x00000002 },
+    { 0x4401b0f0, 0x00000002 },
+    { 0x01c110f0, 0x00000002 },
+    { 0x26667071, 0x00000018 },
+    { 0x040c2565, 0x00000002 },
+    { 0x00000071, 0x00000018 },
+    { 0x04002564, 0x00000002 },
+    { 0x00007566, 0x00000002 },
+    { 0x00000068, 0x00000004 },
+    { 0x00401074, 0x00000008 },
+    { 0x00101000, 0x00000002 },
+    { 0x000d80ff, 0x00000002 },
+    { 0x00800077, 0x00000008 },
+    { 0x000f9000, 0x00000002 },
+    { 0x000e00ff, 0x00000002 },
+    { 0000000000, 0x00000006 },
+    { 0x00000094, 0x00000018 },
+    { 0x00000068, 0x00000004 },
+    { 0x00007576, 0x00000002 },
+    { 0x00065000, 0x00000002 },
+    { 0x00009000, 0x00000002 },
+    { 0x00041000, 0x00000002 },
+    { 0x0c00350e, 0x00000002 },
+    { 0x00049000, 0x00000002 },
+    { 0x00051000, 0x00000002 },
+    { 0x01e785f8, 0x00000002 },
+    { 0x00200000, 0x00000002 },
+    { 0x00600087, 0x0000000c },
+    { 0x00007563, 0x00000002 },
+    { 0x006075f0, 0x00000021 },
+    { 0x2000707c, 0x00000004 },
+    { 0x0000507c, 0x00000004 },
+    { 0x00007576, 0x00000002 },
+    { 0x00007577, 0x00000002 },
+    { 0x0000750e, 0x00000002 },
+    { 0x0000750f, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x0060008a, 0x0000000c },
+    { 0x006075f0, 0x00000021 },
+    { 0x000075f8, 0x00000002 },
+    { 0x0000008a, 0x00000004 },
+    { 0x000a750e, 0x00000002 },
+    { 0x0020750f, 0x00000002 },
+    { 0x0060008d, 0x00000004 },
+    { 0x00007570, 0x00000002 },
+    { 0x00007571, 0x00000002 },
+    { 0x00007572, 0x00000006 },
+    { 0x00005000, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00007568, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x00000098, 0x0000000c },
+    { 0x00058000, 0x00000002 },
+    { 0x0c607562, 0x00000002 },
+    { 0x0000009a, 0x00000004 },
+    { 0x00600099, 0x00000004 },
+    { 0x400070f1, 0000000000 },
+    { 0x000380f1, 0x00000002 },
+    { 0x000000a7, 0x0000001c },
+    { 0x000650a9, 0x00000018 },
+    { 0x040025bb, 0x00000002 },
+    { 0x000610aa, 0x00000018 },
+    { 0x040075bc, 0000000000 },
+    { 0x000075bb, 0x00000002 },
+    { 0x000075bc, 0000000000 },
+    { 0x00090000, 0x00000006 },
+    { 0x00090000, 0x00000002 },
+    { 0x000d8002, 0x00000006 },
+    { 0x00005000, 0x00000002 },
+    { 0x00007821, 0x00000002 },
+    { 0x00007800, 0000000000 },
+    { 0x00007821, 0x00000002 },
+    { 0x00007800, 0000000000 },
+    { 0x01665000, 0x00000002 },
+    { 0x000a0000, 0x00000002 },
+    { 0x000671cc, 0x00000002 },
+    { 0x0286f1cd, 0x00000002 },
+    { 0x000000b7, 0x00000010 },
+    { 0x21007000, 0000000000 },
+    { 0x000000be, 0x0000001c },
+    { 0x00065000, 0x00000002 },
+    { 0x000a0000, 0x00000002 },
+    { 0x00061000, 0x00000002 },
+    { 0x000b0000, 0x00000002 },
+    { 0x38067000, 0x00000002 },
+    { 0x000a00ba, 0x00000004 },
+    { 0x20007000, 0000000000 },
+    { 0x01200000, 0x00000002 },
+    { 0x20077000, 0x00000002 },
+    { 0x01200000, 0x00000002 },
+    { 0x20007000, 0000000000 },
+    { 0x00061000, 0x00000002 },
+    { 0x0120751b, 0x00000002 },
+    { 0x8040750a, 0x00000002 },
+    { 0x8040750b, 0x00000002 },
+    { 0x00110000, 0x00000002 },
+    { 0x000380f1, 0x00000002 },
+    { 0x000000d1, 0x0000001c },
+    { 0x000610aa, 0x00000018 },
+    { 0x844075bd, 0x00000002 },
+    { 0x000610a9, 0x00000018 },
+    { 0x840075bb, 0x00000002 },
+    { 0x000610aa, 0x00000018 },
+    { 0x844075bc, 0x00000002 },
+    { 0x000000d4, 0x00000004 },
+    { 0x804075bd, 0x00000002 },
+    { 0x800075bb, 0x00000002 },
+    { 0x804075bc, 0x00000002 },
+    { 0x00108000, 0x00000002 },
+    { 0x01400000, 0x00000002 },
+    { 0x006000d8, 0x0000000c },
+    { 0x20c07000, 0x00000020 },
+    { 0x000000da, 0x00000012 },
+    { 0x00800000, 0x00000006 },
+    { 0x0080751d, 0x00000006 },
+    { 0x000025bb, 0x00000002 },
+    { 0x000040d4, 0x00000004 },
+    { 0x0000775c, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00661000, 0x00000002 },
+    { 0x0460275d, 0x00000020 },
+    { 0x00004000, 0000000000 },
+    { 0x00007999, 0x00000002 },
+    { 0x00a05000, 0x00000002 },
+    { 0x00661000, 0x00000002 },
+    { 0x0460299b, 0x00000020 },
+    { 0x00004000, 0000000000 },
+    { 0x01e00830, 0x00000002 },
+    { 0x21007000, 0000000000 },
+    { 0x00005000, 0x00000002 },
+    { 0x00038056, 0x00000002 },
+    { 0x040025e0, 0x00000002 },
+    { 0x000075e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000380ed, 0x00000002 },
+    { 0x04007394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000078c4, 0x00000002 },
+    { 0x000078c5, 0x00000002 },
+    { 0x000078c6, 0x00000002 },
+    { 0x00007924, 0x00000002 },
+    { 0x00007925, 0x00000002 },
+    { 0x00007926, 0x00000002 },
+    { 0x000000f2, 0x00000004 },
+    { 0x00007924, 0x00000002 },
+    { 0x00007925, 0x00000002 },
+    { 0x00007926, 0x00000002 },
+    { 0x000000f9, 0x00000004 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 R300_cp_microcode[][2] = {
+    { 0x4200e000, 0000000000 },
+    { 0x4000e000, 0000000000 },
+    { 0x000000ae, 0x00000008 },
+    { 0x000000b2, 0x00000008 },
+    { 0x67554b4a, 0000000000 },
+    { 0x4a4a4475, 0000000000 },
+    { 0x55527d83, 0000000000 },
+    { 0x4a8c8b65, 0000000000 },
+    { 0x4aef4af6, 0000000000 },
+    { 0x4ae14a4a, 0000000000 },
+    { 0xe4979797, 0000000000 },
+    { 0xdb4aebdd, 0000000000 },
+    { 0x9ccc4a4a, 0000000000 },
+    { 0xd1989898, 0000000000 },
+    { 0x4a0f9ad6, 0000000000 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000d0012, 0x00000038 },
+    { 0x0000e8b4, 0x00000004 },
+    { 0x000d0014, 0x00000038 },
+    { 0x0000e8b6, 0x00000004 },
+    { 0x000d0016, 0x00000038 },
+    { 0x0000e854, 0x00000004 },
+    { 0x000d0018, 0x00000038 },
+    { 0x0000e855, 0x00000004 },
+    { 0x000d001a, 0x00000038 },
+    { 0x0000e856, 0x00000004 },
+    { 0x000d001c, 0x00000038 },
+    { 0x0000e857, 0x00000004 },
+    { 0x000d001e, 0x00000038 },
+    { 0x0000e824, 0x00000004 },
+    { 0x000d0020, 0x00000038 },
+    { 0x0000e825, 0x00000004 },
+    { 0x000d0022, 0x00000038 },
+    { 0x0000e830, 0x00000004 },
+    { 0x000d0024, 0x00000038 },
+    { 0x0000f0c0, 0x00000004 },
+    { 0x000d0026, 0x00000038 },
+    { 0x0000f0c1, 0x00000004 },
+    { 0x000d0028, 0x00000038 },
+    { 0x0000f041, 0x00000004 },
+    { 0x000d002a, 0x00000038 },
+    { 0x0000f184, 0x00000004 },
+    { 0x000d002c, 0x00000038 },
+    { 0x0000f185, 0x00000004 },
+    { 0x000d002e, 0x00000038 },
+    { 0x0000f186, 0x00000004 },
+    { 0x000d0030, 0x00000038 },
+    { 0x0000f187, 0x00000004 },
+    { 0x000d0032, 0x00000038 },
+    { 0x0000f180, 0x00000004 },
+    { 0x000d0034, 0x00000038 },
+    { 0x0000f393, 0x00000004 },
+    { 0x000d0036, 0x00000038 },
+    { 0x0000f38a, 0x00000004 },
+    { 0x000d0038, 0x00000038 },
+    { 0x0000f38e, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000043, 0x00000018 },
+    { 0x00cce800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x0000003a, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x2000451d, 0x00000004 },
+    { 0x0000e580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x08004580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x00000047, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x00032000, 0x00000004 },
+    { 0x00022051, 0x00000028 },
+    { 0x00000051, 0x00000024 },
+    { 0x0800450f, 0x00000004 },
+    { 0x0000a04b, 0x00000008 },
+    { 0x0000e565, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000052, 0x00000008 },
+    { 0x03cca5b4, 0x00000004 },
+    { 0x05432000, 0x00000004 },
+    { 0x00022000, 0x00000004 },
+    { 0x4ccce05e, 0x00000030 },
+    { 0x08274565, 0x00000004 },
+    { 0x0000005e, 0x00000030 },
+    { 0x08004564, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000055, 0x00000008 },
+    { 0x00802061, 0x00000010 },
+    { 0x00202000, 0x00000004 },
+    { 0x001b00ff, 0x00000004 },
+    { 0x01000064, 0x00000010 },
+    { 0x001f2000, 0x00000004 },
+    { 0x001c00ff, 0x00000004 },
+    { 0000000000, 0x0000000c },
+    { 0x00000080, 0x00000030 },
+    { 0x00000055, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00012000, 0x00000004 },
+    { 0x00082000, 0x00000004 },
+    { 0x1800650e, 0x00000004 },
+    { 0x00092000, 0x00000004 },
+    { 0x000a2000, 0x00000004 },
+    { 0x000f0000, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x00000074, 0x00000018 },
+    { 0x0000e563, 0x00000004 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000069, 0x00000008 },
+    { 0x0000a069, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x0000e577, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x0000e50f, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000077, 0x00000018 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000077, 0x00000008 },
+    { 0x0014e50e, 0x00000004 },
+    { 0x0040e50f, 0x00000004 },
+    { 0x00c0007a, 0x00000008 },
+    { 0x0000e570, 0x00000004 },
+    { 0x0000e571, 0x00000004 },
+    { 0x0000e572, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x0000e568, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00000084, 0x00000018 },
+    { 0x000b0000, 0x00000004 },
+    { 0x18c0e562, 0x00000004 },
+    { 0x00000086, 0x00000008 },
+    { 0x00c00085, 0x00000008 },
+    { 0x000700e3, 0x00000004 },
+    { 0x00000092, 0x00000038 },
+    { 0x000ca094, 0x00000030 },
+    { 0x080045bb, 0x00000004 },
+    { 0x000c2095, 0x00000030 },
+    { 0x0800e5bc, 0000000000 },
+    { 0x0000e5bb, 0x00000004 },
+    { 0x0000e5bc, 0000000000 },
+    { 0x00120000, 0x0000000c },
+    { 0x00120000, 0x00000004 },
+    { 0x001b0002, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e800, 0000000000 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e82e, 0000000000 },
+    { 0x02cca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000ce1cc, 0x00000004 },
+    { 0x050de1cd, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x000000a4, 0x00000018 },
+    { 0x00c0a000, 0x00000004 },
+    { 0x000000a1, 0x00000008 },
+    { 0x000000a6, 0x00000020 },
+    { 0x4200e000, 0000000000 },
+    { 0x000000ad, 0x00000038 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00160000, 0x00000004 },
+    { 0x700ce000, 0x00000004 },
+    { 0x001400a9, 0x00000008 },
+    { 0x4000e000, 0000000000 },
+    { 0x02400000, 0x00000004 },
+    { 0x400ee000, 0x00000004 },
+    { 0x02400000, 0x00000004 },
+    { 0x4000e000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0240e51b, 0x00000004 },
+    { 0x0080e50a, 0x00000005 },
+    { 0x0080e50b, 0x00000005 },
+    { 0x00220000, 0x00000004 },
+    { 0x000700e3, 0x00000004 },
+    { 0x000000c0, 0x00000038 },
+    { 0x000c2095, 0x00000030 },
+    { 0x0880e5bd, 0x00000005 },
+    { 0x000c2094, 0x00000030 },
+    { 0x0800e5bb, 0x00000005 },
+    { 0x000c2095, 0x00000030 },
+    { 0x0880e5bc, 0x00000005 },
+    { 0x000000c3, 0x00000008 },
+    { 0x0080e5bd, 0x00000005 },
+    { 0x0000e5bb, 0x00000005 },
+    { 0x0080e5bc, 0x00000005 },
+    { 0x00210000, 0x00000004 },
+    { 0x02800000, 0x00000004 },
+    { 0x00c000c7, 0x00000018 },
+    { 0x4180e000, 0x00000040 },
+    { 0x000000c9, 0x00000024 },
+    { 0x01000000, 0x0000000c },
+    { 0x0100e51d, 0x0000000c },
+    { 0x000045bb, 0x00000004 },
+    { 0x000080c3, 0x00000008 },
+    { 0x0000f3ce, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053cf, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f3d2, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053d3, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f39d, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c0539e, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x03c00830, 0x00000004 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x200045e0, 0x00000004 },
+    { 0x0000e5e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000700e0, 0x00000004 },
+    { 0x0800e394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x0000e8c4, 0x00000004 },
+    { 0x0000e8c5, 0x00000004 },
+    { 0x0000e8c6, 0x00000004 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000e4, 0x00000008 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000eb, 0x00000008 },
+    { 0x02c02000, 0x00000004 },
+    { 0x00060000, 0x00000004 },
+    { 0x000000f3, 0x00000034 },
+    { 0x000000f0, 0x00000008 },
+    { 0x00008000, 0x00000004 },
+    { 0xc000e000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x001d0018, 0x00000004 },
+    { 0x001a0001, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0x0500a04a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 R420_cp_microcode[][2] = {
+    { 0x4200e000, 0000000000 },
+    { 0x4000e000, 0000000000 },
+    { 0x00000099, 0x00000008 },
+    { 0x0000009d, 0x00000008 },
+    { 0x4a554b4a, 0000000000 },
+    { 0x4a4a4467, 0000000000 },
+    { 0x55526f75, 0000000000 },
+    { 0x4a7e7d65, 0000000000 },
+    { 0xd9d3dff6, 0000000000 },
+    { 0x4ac54a4a, 0000000000 },
+    { 0xc8828282, 0000000000 },
+    { 0xbf4acfc1, 0000000000 },
+    { 0x87b04a4a, 0000000000 },
+    { 0xb5838383, 0000000000 },
+    { 0x4a0f85ba, 0000000000 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000d0012, 0x00000038 },
+    { 0x0000e8b4, 0x00000004 },
+    { 0x000d0014, 0x00000038 },
+    { 0x0000e8b6, 0x00000004 },
+    { 0x000d0016, 0x00000038 },
+    { 0x0000e854, 0x00000004 },
+    { 0x000d0018, 0x00000038 },
+    { 0x0000e855, 0x00000004 },
+    { 0x000d001a, 0x00000038 },
+    { 0x0000e856, 0x00000004 },
+    { 0x000d001c, 0x00000038 },
+    { 0x0000e857, 0x00000004 },
+    { 0x000d001e, 0x00000038 },
+    { 0x0000e824, 0x00000004 },
+    { 0x000d0020, 0x00000038 },
+    { 0x0000e825, 0x00000004 },
+    { 0x000d0022, 0x00000038 },
+    { 0x0000e830, 0x00000004 },
+    { 0x000d0024, 0x00000038 },
+    { 0x0000f0c0, 0x00000004 },
+    { 0x000d0026, 0x00000038 },
+    { 0x0000f0c1, 0x00000004 },
+    { 0x000d0028, 0x00000038 },
+    { 0x0000f041, 0x00000004 },
+    { 0x000d002a, 0x00000038 },
+    { 0x0000f184, 0x00000004 },
+    { 0x000d002c, 0x00000038 },
+    { 0x0000f185, 0x00000004 },
+    { 0x000d002e, 0x00000038 },
+    { 0x0000f186, 0x00000004 },
+    { 0x000d0030, 0x00000038 },
+    { 0x0000f187, 0x00000004 },
+    { 0x000d0032, 0x00000038 },
+    { 0x0000f180, 0x00000004 },
+    { 0x000d0034, 0x00000038 },
+    { 0x0000f393, 0x00000004 },
+    { 0x000d0036, 0x00000038 },
+    { 0x0000f38a, 0x00000004 },
+    { 0x000d0038, 0x00000038 },
+    { 0x0000f38e, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000043, 0x00000018 },
+    { 0x00cce800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x0000003a, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x2000451d, 0x00000004 },
+    { 0x0000e580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x08004580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x00000047, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x00032000, 0x00000004 },
+    { 0x00022051, 0x00000028 },
+    { 0x00000051, 0x00000024 },
+    { 0x0800450f, 0x00000004 },
+    { 0x0000a04b, 0x00000008 },
+    { 0x0000e565, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000052, 0x00000008 },
+    { 0x03cca5b4, 0x00000004 },
+    { 0x05432000, 0x00000004 },
+    { 0x00022000, 0x00000004 },
+    { 0x4ccce05e, 0x00000030 },
+    { 0x08274565, 0x00000004 },
+    { 0x0000005e, 0x00000030 },
+    { 0x08004564, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000055, 0x00000008 },
+    { 0x00802061, 0x00000010 },
+    { 0x00202000, 0x00000004 },
+    { 0x001b00ff, 0x00000004 },
+    { 0x01000064, 0x00000010 },
+    { 0x001f2000, 0x00000004 },
+    { 0x001c00ff, 0x00000004 },
+    { 0000000000, 0x0000000c },
+    { 0x00000072, 0x00000030 },
+    { 0x00000055, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x0000e577, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x0000e50f, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000069, 0x00000018 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000069, 0x00000008 },
+    { 0x0014e50e, 0x00000004 },
+    { 0x0040e50f, 0x00000004 },
+    { 0x00c0006c, 0x00000008 },
+    { 0x0000e570, 0x00000004 },
+    { 0x0000e571, 0x00000004 },
+    { 0x0000e572, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x0000e568, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00000076, 0x00000018 },
+    { 0x000b0000, 0x00000004 },
+    { 0x18c0e562, 0x00000004 },
+    { 0x00000078, 0x00000008 },
+    { 0x00c00077, 0x00000008 },
+    { 0x000700c7, 0x00000004 },
+    { 0x00000080, 0x00000038 },
+    { 0x0000e5bb, 0x00000004 },
+    { 0x0000e5bc, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e800, 0000000000 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e82e, 0000000000 },
+    { 0x02cca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000ce1cc, 0x00000004 },
+    { 0x050de1cd, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x0000008f, 0x00000018 },
+    { 0x00c0a000, 0x00000004 },
+    { 0x0000008c, 0x00000008 },
+    { 0x00000091, 0x00000020 },
+    { 0x4200e000, 0000000000 },
+    { 0x00000098, 0x00000038 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00160000, 0x00000004 },
+    { 0x700ce000, 0x00000004 },
+    { 0x00140094, 0x00000008 },
+    { 0x4000e000, 0000000000 },
+    { 0x02400000, 0x00000004 },
+    { 0x400ee000, 0x00000004 },
+    { 0x02400000, 0x00000004 },
+    { 0x4000e000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0240e51b, 0x00000004 },
+    { 0x0080e50a, 0x00000005 },
+    { 0x0080e50b, 0x00000005 },
+    { 0x00220000, 0x00000004 },
+    { 0x000700c7, 0x00000004 },
+    { 0x000000a4, 0x00000038 },
+    { 0x0080e5bd, 0x00000005 },
+    { 0x0000e5bb, 0x00000005 },
+    { 0x0080e5bc, 0x00000005 },
+    { 0x00210000, 0x00000004 },
+    { 0x02800000, 0x00000004 },
+    { 0x00c000ab, 0x00000018 },
+    { 0x4180e000, 0x00000040 },
+    { 0x000000ad, 0x00000024 },
+    { 0x01000000, 0x0000000c },
+    { 0x0100e51d, 0x0000000c },
+    { 0x000045bb, 0x00000004 },
+    { 0x000080a7, 0x00000008 },
+    { 0x0000f3ce, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053cf, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f3d2, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053d3, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f39d, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c0539e, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x03c00830, 0x00000004 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x200045e0, 0x00000004 },
+    { 0x0000e5e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000700c4, 0x00000004 },
+    { 0x0800e394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x0000e8c4, 0x00000004 },
+    { 0x0000e8c5, 0x00000004 },
+    { 0x0000e8c6, 0x00000004 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000c8, 0x00000008 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000cf, 0x00000008 },
+    { 0x02c02000, 0x00000004 },
+    { 0x00060000, 0x00000004 },
+    { 0x000000d7, 0x00000034 },
+    { 0x000000d4, 0x00000008 },
+    { 0x00008000, 0x00000004 },
+    { 0xc000e000, 0000000000 },
+    { 0x0000e1cc, 0x00000004 },
+    { 0x0500e1cd, 0x00000004 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000000de, 0x00000034 },
+    { 0x000000da, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x0019e1cc, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x0500a000, 0x00000004 },
+    { 0x080041cd, 0x00000004 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x001d0018, 0x00000004 },
+    { 0x001a0001, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0x0500a04a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 RS600_cp_microcode[][2] = {
+    { 0x4200e000, 0000000000 },
+    { 0x4000e000, 0000000000 },
+    { 0x000000a0, 0x00000008 },
+    { 0x000000a4, 0x00000008 },
+    { 0x4a554b4a, 0000000000 },
+    { 0x4a4a4467, 0000000000 },
+    { 0x55526f75, 0000000000 },
+    { 0x4a7e7d65, 0000000000 },
+    { 0x4ae74af6, 0000000000 },
+    { 0x4ad34a4a, 0000000000 },
+    { 0xd6898989, 0000000000 },
+    { 0xcd4addcf, 0000000000 },
+    { 0x8ebe4ae2, 0000000000 },
+    { 0xc38a8a8a, 0000000000 },
+    { 0x4a0f8cc8, 0000000000 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000d0012, 0x00000038 },
+    { 0x0000e8b4, 0x00000004 },
+    { 0x000d0014, 0x00000038 },
+    { 0x0000e8b6, 0x00000004 },
+    { 0x000d0016, 0x00000038 },
+    { 0x0000e854, 0x00000004 },
+    { 0x000d0018, 0x00000038 },
+    { 0x0000e855, 0x00000004 },
+    { 0x000d001a, 0x00000038 },
+    { 0x0000e856, 0x00000004 },
+    { 0x000d001c, 0x00000038 },
+    { 0x0000e857, 0x00000004 },
+    { 0x000d001e, 0x00000038 },
+    { 0x0000e824, 0x00000004 },
+    { 0x000d0020, 0x00000038 },
+    { 0x0000e825, 0x00000004 },
+    { 0x000d0022, 0x00000038 },
+    { 0x0000e830, 0x00000004 },
+    { 0x000d0024, 0x00000038 },
+    { 0x0000f0c0, 0x00000004 },
+    { 0x000d0026, 0x00000038 },
+    { 0x0000f0c1, 0x00000004 },
+    { 0x000d0028, 0x00000038 },
+    { 0x0000f041, 0x00000004 },
+    { 0x000d002a, 0x00000038 },
+    { 0x0000f184, 0x00000004 },
+    { 0x000d002c, 0x00000038 },
+    { 0x0000f185, 0x00000004 },
+    { 0x000d002e, 0x00000038 },
+    { 0x0000f186, 0x00000004 },
+    { 0x000d0030, 0x00000038 },
+    { 0x0000f187, 0x00000004 },
+    { 0x000d0032, 0x00000038 },
+    { 0x0000f180, 0x00000004 },
+    { 0x000d0034, 0x00000038 },
+    { 0x0000f393, 0x00000004 },
+    { 0x000d0036, 0x00000038 },
+    { 0x0000f38a, 0x00000004 },
+    { 0x000d0038, 0x00000038 },
+    { 0x0000f38e, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000043, 0x00000018 },
+    { 0x00cce800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x0000003a, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x2000451d, 0x00000004 },
+    { 0x0000e580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x08004580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x00000047, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x00032000, 0x00000004 },
+    { 0x00022051, 0x00000028 },
+    { 0x00000051, 0x00000024 },
+    { 0x0800450f, 0x00000004 },
+    { 0x0000a04b, 0x00000008 },
+    { 0x0000e565, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000052, 0x00000008 },
+    { 0x03cca5b4, 0x00000004 },
+    { 0x05432000, 0x00000004 },
+    { 0x00022000, 0x00000004 },
+    { 0x4ccce05e, 0x00000030 },
+    { 0x08274565, 0x00000004 },
+    { 0x0000005e, 0x00000030 },
+    { 0x08004564, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000055, 0x00000008 },
+    { 0x00802061, 0x00000010 },
+    { 0x00202000, 0x00000004 },
+    { 0x001b00ff, 0x00000004 },
+    { 0x01000064, 0x00000010 },
+    { 0x001f2000, 0x00000004 },
+    { 0x001c00ff, 0x00000004 },
+    { 0000000000, 0x0000000c },
+    { 0x00000072, 0x00000030 },
+    { 0x00000055, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x0000e577, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x0000e50f, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000069, 0x00000018 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000069, 0x00000008 },
+    { 0x0014e50e, 0x00000004 },
+    { 0x0040e50f, 0x00000004 },
+    { 0x00c0006c, 0x00000008 },
+    { 0x0000e570, 0x00000004 },
+    { 0x0000e571, 0x00000004 },
+    { 0x0000e572, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x0000e568, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00000076, 0x00000018 },
+    { 0x000b0000, 0x00000004 },
+    { 0x18c0e562, 0x00000004 },
+    { 0x00000078, 0x00000008 },
+    { 0x00c00077, 0x00000008 },
+    { 0x000700d5, 0x00000004 },
+    { 0x00000084, 0x00000038 },
+    { 0x000ca086, 0x00000030 },
+    { 0x080045bb, 0x00000004 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0800e5bc, 0000000000 },
+    { 0x0000e5bb, 0x00000004 },
+    { 0x0000e5bc, 0000000000 },
+    { 0x00120000, 0x0000000c },
+    { 0x00120000, 0x00000004 },
+    { 0x001b0002, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e800, 0000000000 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e82e, 0000000000 },
+    { 0x02cca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000ce1cc, 0x00000004 },
+    { 0x050de1cd, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x00000096, 0x00000018 },
+    { 0x00c0a000, 0x00000004 },
+    { 0x00000093, 0x00000008 },
+    { 0x00000098, 0x00000020 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000009f, 0x00000038 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00160000, 0x00000004 },
+    { 0x700ce000, 0x00000004 },
+    { 0x0014009b, 0x00000008 },
+    { 0x4000e000, 0000000000 },
+    { 0x02400000, 0x00000004 },
+    { 0x400ee000, 0x00000004 },
+    { 0x02400000, 0x00000004 },
+    { 0x4000e000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0240e51b, 0x00000004 },
+    { 0x0080e50a, 0x00000005 },
+    { 0x0080e50b, 0x00000005 },
+    { 0x00220000, 0x00000004 },
+    { 0x000700d5, 0x00000004 },
+    { 0x000000b2, 0x00000038 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0880e5bd, 0x00000005 },
+    { 0x000c2086, 0x00000030 },
+    { 0x0800e5bb, 0x00000005 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0880e5bc, 0x00000005 },
+    { 0x000000b5, 0x00000008 },
+    { 0x0080e5bd, 0x00000005 },
+    { 0x0000e5bb, 0x00000005 },
+    { 0x0080e5bc, 0x00000005 },
+    { 0x00210000, 0x00000004 },
+    { 0x02800000, 0x00000004 },
+    { 0x00c000b9, 0x00000018 },
+    { 0x4180e000, 0x00000040 },
+    { 0x000000bb, 0x00000024 },
+    { 0x01000000, 0x0000000c },
+    { 0x0100e51d, 0x0000000c },
+    { 0x000045bb, 0x00000004 },
+    { 0x000080b5, 0x00000008 },
+    { 0x0000f3ce, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053cf, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f3d2, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053d3, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f39d, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c0539e, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x03c00830, 0x00000004 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x200045e0, 0x00000004 },
+    { 0x0000e5e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000700d2, 0x00000004 },
+    { 0x0800e394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x0000e8c4, 0x00000004 },
+    { 0x0000e8c5, 0x00000004 },
+    { 0x0000e8c6, 0x00000004 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000d6, 0x00000008 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000dd, 0x00000008 },
+    { 0x00e00116, 0000000000 },
+    { 0x000700e1, 0x00000004 },
+    { 0x0800401c, 0x00000004 },
+    { 0x200050e7, 0x00000004 },
+    { 0x0000e01d, 0x00000004 },
+    { 0x000000e4, 0x00000008 },
+    { 0x02c02000, 0x00000004 },
+    { 0x00060000, 0x00000004 },
+    { 0x000000eb, 0x00000034 },
+    { 0x000000e8, 0x00000008 },
+    { 0x00008000, 0x00000004 },
+    { 0xc000e000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x001d0018, 0x00000004 },
+    { 0x001a0001, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0x0500a04a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 RS690_cp_microcode[][2] = {
+    { 0x000000dd, 0x00000008 },
+    { 0x000000df, 0x00000008 },
+    { 0x000000a0, 0x00000008 },
+    { 0x000000a4, 0x00000008 },
+    { 0x4a554b4a, 0000000000 },
+    { 0x4a4a4467, 0000000000 },
+    { 0x55526f75, 0000000000 },
+    { 0x4a7e7d65, 0000000000 },
+    { 0x4ad74af6, 0000000000 },
+    { 0x4ac94a4a, 0000000000 },
+    { 0xcc898989, 0000000000 },
+    { 0xc34ad3c5, 0000000000 },
+    { 0x8e4a4a4a, 0000000000 },
+    { 0x4a8a8a8a, 0000000000 },
+    { 0x4a0f8c4a, 0000000000 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000d0012, 0x00000038 },
+    { 0x0000e8b4, 0x00000004 },
+    { 0x000d0014, 0x00000038 },
+    { 0x0000e8b6, 0x00000004 },
+    { 0x000d0016, 0x00000038 },
+    { 0x0000e854, 0x00000004 },
+    { 0x000d0018, 0x00000038 },
+    { 0x0000e855, 0x00000004 },
+    { 0x000d001a, 0x00000038 },
+    { 0x0000e856, 0x00000004 },
+    { 0x000d001c, 0x00000038 },
+    { 0x0000e857, 0x00000004 },
+    { 0x000d001e, 0x00000038 },
+    { 0x0000e824, 0x00000004 },
+    { 0x000d0020, 0x00000038 },
+    { 0x0000e825, 0x00000004 },
+    { 0x000d0022, 0x00000038 },
+    { 0x0000e830, 0x00000004 },
+    { 0x000d0024, 0x00000038 },
+    { 0x0000f0c0, 0x00000004 },
+    { 0x000d0026, 0x00000038 },
+    { 0x0000f0c1, 0x00000004 },
+    { 0x000d0028, 0x00000038 },
+    { 0x0000f041, 0x00000004 },
+    { 0x000d002a, 0x00000038 },
+    { 0x0000f184, 0x00000004 },
+    { 0x000d002c, 0x00000038 },
+    { 0x0000f185, 0x00000004 },
+    { 0x000d002e, 0x00000038 },
+    { 0x0000f186, 0x00000004 },
+    { 0x000d0030, 0x00000038 },
+    { 0x0000f187, 0x00000004 },
+    { 0x000d0032, 0x00000038 },
+    { 0x0000f180, 0x00000004 },
+    { 0x000d0034, 0x00000038 },
+    { 0x0000f393, 0x00000004 },
+    { 0x000d0036, 0x00000038 },
+    { 0x0000f38a, 0x00000004 },
+    { 0x000d0038, 0x00000038 },
+    { 0x0000f38e, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000043, 0x00000018 },
+    { 0x00cce800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x0000003a, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x2000451d, 0x00000004 },
+    { 0x0000e580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x08004580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x00000047, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x00032000, 0x00000004 },
+    { 0x00022051, 0x00000028 },
+    { 0x00000051, 0x00000024 },
+    { 0x0800450f, 0x00000004 },
+    { 0x0000a04b, 0x00000008 },
+    { 0x0000e565, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000052, 0x00000008 },
+    { 0x03cca5b4, 0x00000004 },
+    { 0x05432000, 0x00000004 },
+    { 0x00022000, 0x00000004 },
+    { 0x4ccce05e, 0x00000030 },
+    { 0x08274565, 0x00000004 },
+    { 0x0000005e, 0x00000030 },
+    { 0x08004564, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000055, 0x00000008 },
+    { 0x00802061, 0x00000010 },
+    { 0x00202000, 0x00000004 },
+    { 0x001b00ff, 0x00000004 },
+    { 0x01000064, 0x00000010 },
+    { 0x001f2000, 0x00000004 },
+    { 0x001c00ff, 0x00000004 },
+    { 0000000000, 0x0000000c },
+    { 0x00000072, 0x00000030 },
+    { 0x00000055, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x0000e577, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x0000e50f, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000069, 0x00000018 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000069, 0x00000008 },
+    { 0x0014e50e, 0x00000004 },
+    { 0x0040e50f, 0x00000004 },
+    { 0x00c0006c, 0x00000008 },
+    { 0x0000e570, 0x00000004 },
+    { 0x0000e571, 0x00000004 },
+    { 0x0000e572, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x0000e568, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00000076, 0x00000018 },
+    { 0x000b0000, 0x00000004 },
+    { 0x18c0e562, 0x00000004 },
+    { 0x00000078, 0x00000008 },
+    { 0x00c00077, 0x00000008 },
+    { 0x000700cb, 0x00000004 },
+    { 0x00000084, 0x00000038 },
+    { 0x000ca086, 0x00000030 },
+    { 0x080045bb, 0x00000004 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0800e5bc, 0000000000 },
+    { 0x0000e5bb, 0x00000004 },
+    { 0x0000e5bc, 0000000000 },
+    { 0x00120000, 0x0000000c },
+    { 0x00120000, 0x00000004 },
+    { 0x001b0002, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e800, 0000000000 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e82e, 0000000000 },
+    { 0x02cca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000ce1cc, 0x00000004 },
+    { 0x050de1cd, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x00000096, 0x00000018 },
+    { 0x00c0a000, 0x00000004 },
+    { 0x00000093, 0x00000008 },
+    { 0x00000098, 0x00000020 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000009f, 0x00000038 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00160000, 0x00000004 },
+    { 0x700ce000, 0x00000004 },
+    { 0x0014009b, 0x00000008 },
+    { 0x4000e000, 0000000000 },
+    { 0x02400000, 0x00000004 },
+    { 0x400ee000, 0x00000004 },
+    { 0x02400000, 0x00000004 },
+    { 0x4000e000, 0000000000 },
+    { 0x00100000, 0x0000002c },
+    { 0x00004000, 0000000000 },
+    { 0x080045c8, 0x00000004 },
+    { 0x00240005, 0x00000004 },
+    { 0x08004d0b, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0240e51b, 0x00000004 },
+    { 0x0080e50a, 0x00000005 },
+    { 0x0080e50b, 0x00000005 },
+    { 0x00220000, 0x00000004 },
+    { 0x000700cb, 0x00000004 },
+    { 0x000000b7, 0x00000038 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0880e5bd, 0x00000005 },
+    { 0x000c2086, 0x00000030 },
+    { 0x0800e5bb, 0x00000005 },
+    { 0x000c2087, 0x00000030 },
+    { 0x0880e5bc, 0x00000005 },
+    { 0x000000ba, 0x00000008 },
+    { 0x0080e5bd, 0x00000005 },
+    { 0x0000e5bb, 0x00000005 },
+    { 0x0080e5bc, 0x00000005 },
+    { 0x00210000, 0x00000004 },
+    { 0x02800000, 0x00000004 },
+    { 0x00c000be, 0x00000018 },
+    { 0x4180e000, 0x00000040 },
+    { 0x000000c0, 0x00000024 },
+    { 0x01000000, 0x0000000c },
+    { 0x0100e51d, 0x0000000c },
+    { 0x000045bb, 0x00000004 },
+    { 0x000080ba, 0x00000008 },
+    { 0x03c00830, 0x00000004 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x200045e0, 0x00000004 },
+    { 0x0000e5e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000700c8, 0x00000004 },
+    { 0x0800e394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x0000e8c4, 0x00000004 },
+    { 0x0000e8c5, 0x00000004 },
+    { 0x0000e8c6, 0x00000004 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000cc, 0x00000008 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000d3, 0x00000008 },
+    { 0x02c02000, 0x00000004 },
+    { 0x00060000, 0x00000004 },
+    { 0x000000db, 0x00000034 },
+    { 0x000000d8, 0x00000008 },
+    { 0x00008000, 0x00000004 },
+    { 0xc000e000, 0000000000 },
+    { 0x000000e1, 0x00000030 },
+    { 0x4200e000, 0000000000 },
+    { 0x000000e1, 0x00000030 },
+    { 0x4000e000, 0000000000 },
+    { 0x0025001b, 0x00000004 },
+    { 0x00230000, 0x00000004 },
+    { 0x00250005, 0x00000004 },
+    { 0x000000e6, 0x00000034 },
+    { 0000000000, 0x0000000c },
+    { 0x00244000, 0x00000004 },
+    { 0x080045c8, 0x00000004 },
+    { 0x00240005, 0x00000004 },
+    { 0x08004d0b, 0x0000000c },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x001d0018, 0x00000004 },
+    { 0x001a0001, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0x0500a04a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+static const u32 R520_cp_microcode[][2] = {
+    { 0x4200e000, 0000000000 },
+    { 0x4000e000, 0000000000 },
+    { 0x00000099, 0x00000008 },
+    { 0x0000009d, 0x00000008 },
+    { 0x4a554b4a, 0000000000 },
+    { 0x4a4a4467, 0000000000 },
+    { 0x55526f75, 0000000000 },
+    { 0x4a7e7d65, 0000000000 },
+    { 0xe0dae6f6, 0000000000 },
+    { 0x4ac54a4a, 0000000000 },
+    { 0xc8828282, 0000000000 },
+    { 0xbf4acfc1, 0000000000 },
+    { 0x87b04ad5, 0000000000 },
+    { 0xb5838383, 0000000000 },
+    { 0x4a0f85ba, 0000000000 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000d0012, 0x00000038 },
+    { 0x0000e8b4, 0x00000004 },
+    { 0x000d0014, 0x00000038 },
+    { 0x0000e8b6, 0x00000004 },
+    { 0x000d0016, 0x00000038 },
+    { 0x0000e854, 0x00000004 },
+    { 0x000d0018, 0x00000038 },
+    { 0x0000e855, 0x00000004 },
+    { 0x000d001a, 0x00000038 },
+    { 0x0000e856, 0x00000004 },
+    { 0x000d001c, 0x00000038 },
+    { 0x0000e857, 0x00000004 },
+    { 0x000d001e, 0x00000038 },
+    { 0x0000e824, 0x00000004 },
+    { 0x000d0020, 0x00000038 },
+    { 0x0000e825, 0x00000004 },
+    { 0x000d0022, 0x00000038 },
+    { 0x0000e830, 0x00000004 },
+    { 0x000d0024, 0x00000038 },
+    { 0x0000f0c0, 0x00000004 },
+    { 0x000d0026, 0x00000038 },
+    { 0x0000f0c1, 0x00000004 },
+    { 0x000d0028, 0x00000038 },
+    { 0x0000e000, 0x00000004 },
+    { 0x000d002a, 0x00000038 },
+    { 0x0000e000, 0x00000004 },
+    { 0x000d002c, 0x00000038 },
+    { 0x0000e000, 0x00000004 },
+    { 0x000d002e, 0x00000038 },
+    { 0x0000e000, 0x00000004 },
+    { 0x000d0030, 0x00000038 },
+    { 0x0000e000, 0x00000004 },
+    { 0x000d0032, 0x00000038 },
+    { 0x0000f180, 0x00000004 },
+    { 0x000d0034, 0x00000038 },
+    { 0x0000f393, 0x00000004 },
+    { 0x000d0036, 0x00000038 },
+    { 0x0000f38a, 0x00000004 },
+    { 0x000d0038, 0x00000038 },
+    { 0x0000f38e, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000043, 0x00000018 },
+    { 0x00cce800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x08004800, 0x00000004 },
+    { 0x0000003a, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x2000451d, 0x00000004 },
+    { 0x0000e580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x08004580, 0x00000004 },
+    { 0x000ce581, 0x00000004 },
+    { 0x00000047, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x00032000, 0x00000004 },
+    { 0x00022051, 0x00000028 },
+    { 0x00000051, 0x00000024 },
+    { 0x0800450f, 0x00000004 },
+    { 0x0000a04b, 0x00000008 },
+    { 0x0000e565, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000052, 0x00000008 },
+    { 0x03cca5b4, 0x00000004 },
+    { 0x05432000, 0x00000004 },
+    { 0x00022000, 0x00000004 },
+    { 0x4ccce05e, 0x00000030 },
+    { 0x08274565, 0x00000004 },
+    { 0x0000005e, 0x00000030 },
+    { 0x08004564, 0x00000004 },
+    { 0x0000e566, 0x00000004 },
+    { 0x00000055, 0x00000008 },
+    { 0x00802061, 0x00000010 },
+    { 0x00202000, 0x00000004 },
+    { 0x001b00ff, 0x00000004 },
+    { 0x01000064, 0x00000010 },
+    { 0x001f2000, 0x00000004 },
+    { 0x001c00ff, 0x00000004 },
+    { 0000000000, 0x0000000c },
+    { 0x00000072, 0x00000030 },
+    { 0x00000055, 0x00000008 },
+    { 0x0000e576, 0x00000004 },
+    { 0x0000e577, 0x00000004 },
+    { 0x0000e50e, 0x00000004 },
+    { 0x0000e50f, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00000069, 0x00000018 },
+    { 0x00c0e5f9, 0x000000c2 },
+    { 0x00000069, 0x00000008 },
+    { 0x0014e50e, 0x00000004 },
+    { 0x0040e50f, 0x00000004 },
+    { 0x00c0006c, 0x00000008 },
+    { 0x0000e570, 0x00000004 },
+    { 0x0000e571, 0x00000004 },
+    { 0x0000e572, 0x0000000c },
+    { 0x0000a000, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x0000e568, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00000076, 0x00000018 },
+    { 0x000b0000, 0x00000004 },
+    { 0x18c0e562, 0x00000004 },
+    { 0x00000078, 0x00000008 },
+    { 0x00c00077, 0x00000008 },
+    { 0x000700c7, 0x00000004 },
+    { 0x00000080, 0x00000038 },
+    { 0x0000e5bb, 0x00000004 },
+    { 0x0000e5bc, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e800, 0000000000 },
+    { 0x0000e821, 0x00000004 },
+    { 0x0000e82e, 0000000000 },
+    { 0x02cca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000ce1cc, 0x00000004 },
+    { 0x050de1cd, 0x00000004 },
+    { 0x00400000, 0x00000004 },
+    { 0x0000008f, 0x00000018 },
+    { 0x00c0a000, 0x00000004 },
+    { 0x0000008c, 0x00000008 },
+    { 0x00000091, 0x00000020 },
+    { 0x4200e000, 0000000000 },
+    { 0x00000098, 0x00000038 },
+    { 0x000ca000, 0x00000004 },
+    { 0x00140000, 0x00000004 },
+    { 0x000c2000, 0x00000004 },
+    { 0x00160000, 0x00000004 },
+    { 0x700ce000, 0x00000004 },
+    { 0x00140094, 0x00000008 },
+    { 0x4000e000, 0000000000 },
+    { 0x02400000, 0x00000004 },
+    { 0x400ee000, 0x00000004 },
+    { 0x02400000, 0x00000004 },
+    { 0x4000e000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x0240e51b, 0x00000004 },
+    { 0x0080e50a, 0x00000005 },
+    { 0x0080e50b, 0x00000005 },
+    { 0x00220000, 0x00000004 },
+    { 0x000700c7, 0x00000004 },
+    { 0x000000a4, 0x00000038 },
+    { 0x0080e5bd, 0x00000005 },
+    { 0x0000e5bb, 0x00000005 },
+    { 0x0080e5bc, 0x00000005 },
+    { 0x00210000, 0x00000004 },
+    { 0x02800000, 0x00000004 },
+    { 0x00c000ab, 0x00000018 },
+    { 0x4180e000, 0x00000040 },
+    { 0x000000ad, 0x00000024 },
+    { 0x01000000, 0x0000000c },
+    { 0x0100e51d, 0x0000000c },
+    { 0x000045bb, 0x00000004 },
+    { 0x000080a7, 0x00000008 },
+    { 0x0000f3ce, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053cf, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f3d2, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c053d3, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x0000f39d, 0x00000004 },
+    { 0x0140a000, 0x00000004 },
+    { 0x00cc2000, 0x00000004 },
+    { 0x08c0539e, 0x00000040 },
+    { 0x00008000, 0000000000 },
+    { 0x03c00830, 0x00000004 },
+    { 0x4200e000, 0000000000 },
+    { 0x0000a000, 0x00000004 },
+    { 0x200045e0, 0x00000004 },
+    { 0x0000e5e1, 0000000000 },
+    { 0x00000001, 0000000000 },
+    { 0x000700c4, 0x00000004 },
+    { 0x0800e394, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x0000e8c4, 0x00000004 },
+    { 0x0000e8c5, 0x00000004 },
+    { 0x0000e8c6, 0x00000004 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000c8, 0x00000008 },
+    { 0x0000e928, 0x00000004 },
+    { 0x0000e929, 0x00000004 },
+    { 0x0000e92a, 0x00000004 },
+    { 0x000000cf, 0x00000008 },
+    { 0xdeadbeef, 0000000000 },
+    { 0x00000116, 0000000000 },
+    { 0x000700d3, 0x00000004 },
+    { 0x080050e7, 0x00000004 },
+    { 0x000700d4, 0x00000004 },
+    { 0x0800401c, 0x00000004 },
+    { 0x0000e01d, 0000000000 },
+    { 0x02c02000, 0x00000004 },
+    { 0x00060000, 0x00000004 },
+    { 0x000000de, 0x00000034 },
+    { 0x000000db, 0x00000008 },
+    { 0x00008000, 0x00000004 },
+    { 0xc000e000, 0000000000 },
+    { 0x0000e1cc, 0x00000004 },
+    { 0x0500e1cd, 0x00000004 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000000e5, 0x00000034 },
+    { 0x000000e1, 0x00000008 },
+    { 0x0000a000, 0000000000 },
+    { 0x0019e1cc, 0x00000004 },
+    { 0x001b0001, 0x00000004 },
+    { 0x0500a000, 0x00000004 },
+    { 0x080041cd, 0x00000004 },
+    { 0x000ca000, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0x000c2000, 0x00000004 },
+    { 0x001d0018, 0x00000004 },
+    { 0x001a0001, 0x00000004 },
+    { 0x000000fb, 0x00000034 },
+    { 0x0000004a, 0x00000008 },
+    { 0x0500a04a, 0x00000008 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+    { 0000000000, 0000000000 },
+};
+
+
+#endif
diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
new file mode 100644 (file)
index 0000000..11c146b
--- /dev/null
@@ -0,0 +1,3203 @@
+/* radeon_state.c -- State support for Radeon -*- linux-c -*- */
+/*
+ * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ *    Kevin E. Martin <martin@valinux.com>
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "drm_sarea.h"
+#include "radeon_drm.h"
+#include "radeon_drv.h"
+
+/* ================================================================
+ * Helper functions for client state checking and fixup
+ */
+
+static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
+                                                   dev_priv,
+                                                   struct drm_file * file_priv,
+                                                   u32 *offset)
+{
+       u64 off = *offset;
+       u32 fb_end = dev_priv->fb_location + dev_priv->fb_size - 1;
+       struct drm_radeon_driver_file_fields *radeon_priv;
+
+       /* Hrm ... the story of the offset ... So this function converts
+        * the various ideas of what userland clients might have for an
+        * offset in the card address space into an offset into the card
+        * address space :) So with a sane client, it should just keep
+        * the value intact and just do some boundary checking. However,
+        * not all clients are sane. Some older clients pass us 0 based
+        * offsets relative to the start of the framebuffer and some may
+        * assume the AGP aperture it appended to the framebuffer, so we
+        * try to detect those cases and fix them up.
+        *
+        * Note: It might be a good idea here to make sure the offset lands
+        * in some "allowed" area to protect things like the PCIE GART...
+        */
+
+       /* First, the best case, the offset already lands in either the
+        * framebuffer or the GART mapped space
+        */
+       if (radeon_check_offset(dev_priv, off))
+               return 0;
+
+       /* Ok, that didn't happen... now check if we have a zero based
+        * offset that fits in the framebuffer + gart space, apply the
+        * magic offset we get from SETPARAM or calculated from fb_location
+        */
+       if (off < (dev_priv->fb_size + dev_priv->gart_size)) {
+               radeon_priv = file_priv->driver_priv;
+               off += radeon_priv->radeon_fb_delta;
+       }
+
+       /* Finally, assume we aimed at a GART offset if beyond the fb */
+       if (off > fb_end)
+               off = off - fb_end - 1 + dev_priv->gart_vm_start;
+
+       /* Now recheck and fail if out of bounds */
+       if (radeon_check_offset(dev_priv, off)) {
+               DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
+               *offset = off;
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t *
+                                                    dev_priv,
+                                                    struct drm_file *file_priv,
+                                                    int id, u32 *data)
+{
+       switch (id) {
+
+       case RADEON_EMIT_PP_MISC:
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                   &data[(RADEON_RB3D_DEPTHOFFSET - RADEON_PP_MISC) / 4])) {
+                       DRM_ERROR("Invalid depth buffer offset\n");
+                       return -EINVAL;
+               }
+               break;
+
+       case RADEON_EMIT_PP_CNTL:
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                   &data[(RADEON_RB3D_COLOROFFSET - RADEON_PP_CNTL) / 4])) {
+                       DRM_ERROR("Invalid colour buffer offset\n");
+                       return -EINVAL;
+               }
+               break;
+
+       case R200_EMIT_PP_TXOFFSET_0:
+       case R200_EMIT_PP_TXOFFSET_1:
+       case R200_EMIT_PP_TXOFFSET_2:
+       case R200_EMIT_PP_TXOFFSET_3:
+       case R200_EMIT_PP_TXOFFSET_4:
+       case R200_EMIT_PP_TXOFFSET_5:
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &data[0])) {
+                       DRM_ERROR("Invalid R200 texture offset\n");
+                       return -EINVAL;
+               }
+               break;
+
+       case RADEON_EMIT_PP_TXFILTER_0:
+       case RADEON_EMIT_PP_TXFILTER_1:
+       case RADEON_EMIT_PP_TXFILTER_2:
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                   &data[(RADEON_PP_TXOFFSET_0 - RADEON_PP_TXFILTER_0) / 4])) {
+                       DRM_ERROR("Invalid R100 texture offset\n");
+                       return -EINVAL;
+               }
+               break;
+
+       case R200_EMIT_PP_CUBIC_OFFSETS_0:
+       case R200_EMIT_PP_CUBIC_OFFSETS_1:
+       case R200_EMIT_PP_CUBIC_OFFSETS_2:
+       case R200_EMIT_PP_CUBIC_OFFSETS_3:
+       case R200_EMIT_PP_CUBIC_OFFSETS_4:
+       case R200_EMIT_PP_CUBIC_OFFSETS_5:{
+                       int i;
+                       for (i = 0; i < 5; i++) {
+                               if (radeon_check_and_fixup_offset(dev_priv,
+                                                                 file_priv,
+                                                                 &data[i])) {
+                                       DRM_ERROR
+                                           ("Invalid R200 cubic texture offset\n");
+                                       return -EINVAL;
+                               }
+                       }
+                       break;
+               }
+
+       case RADEON_EMIT_PP_CUBIC_OFFSETS_T0:
+       case RADEON_EMIT_PP_CUBIC_OFFSETS_T1:
+       case RADEON_EMIT_PP_CUBIC_OFFSETS_T2:{
+                       int i;
+                       for (i = 0; i < 5; i++) {
+                               if (radeon_check_and_fixup_offset(dev_priv,
+                                                                 file_priv,
+                                                                 &data[i])) {
+                                       DRM_ERROR
+                                           ("Invalid R100 cubic texture offset\n");
+                                       return -EINVAL;
+                               }
+                       }
+               }
+               break;
+
+       case R200_EMIT_VAP_CTL:{
+                       RING_LOCALS;
+                       BEGIN_RING(2);
+                       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
+                       ADVANCE_RING();
+               }
+               break;
+
+       case RADEON_EMIT_RB3D_COLORPITCH:
+       case RADEON_EMIT_RE_LINE_PATTERN:
+       case RADEON_EMIT_SE_LINE_WIDTH:
+       case RADEON_EMIT_PP_LUM_MATRIX:
+       case RADEON_EMIT_PP_ROT_MATRIX_0:
+       case RADEON_EMIT_RB3D_STENCILREFMASK:
+       case RADEON_EMIT_SE_VPORT_XSCALE:
+       case RADEON_EMIT_SE_CNTL:
+       case RADEON_EMIT_SE_CNTL_STATUS:
+       case RADEON_EMIT_RE_MISC:
+       case RADEON_EMIT_PP_BORDER_COLOR_0:
+       case RADEON_EMIT_PP_BORDER_COLOR_1:
+       case RADEON_EMIT_PP_BORDER_COLOR_2:
+       case RADEON_EMIT_SE_ZBIAS_FACTOR:
+       case RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT:
+       case RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED:
+       case R200_EMIT_PP_TXCBLEND_0:
+       case R200_EMIT_PP_TXCBLEND_1:
+       case R200_EMIT_PP_TXCBLEND_2:
+       case R200_EMIT_PP_TXCBLEND_3:
+       case R200_EMIT_PP_TXCBLEND_4:
+       case R200_EMIT_PP_TXCBLEND_5:
+       case R200_EMIT_PP_TXCBLEND_6:
+       case R200_EMIT_PP_TXCBLEND_7:
+       case R200_EMIT_TCL_LIGHT_MODEL_CTL_0:
+       case R200_EMIT_TFACTOR_0:
+       case R200_EMIT_VTX_FMT_0:
+       case R200_EMIT_MATRIX_SELECT_0:
+       case R200_EMIT_TEX_PROC_CTL_2:
+       case R200_EMIT_TCL_UCP_VERT_BLEND_CTL:
+       case R200_EMIT_PP_TXFILTER_0:
+       case R200_EMIT_PP_TXFILTER_1:
+       case R200_EMIT_PP_TXFILTER_2:
+       case R200_EMIT_PP_TXFILTER_3:
+       case R200_EMIT_PP_TXFILTER_4:
+       case R200_EMIT_PP_TXFILTER_5:
+       case R200_EMIT_VTE_CNTL:
+       case R200_EMIT_OUTPUT_VTX_COMP_SEL:
+       case R200_EMIT_PP_TAM_DEBUG3:
+       case R200_EMIT_PP_CNTL_X:
+       case R200_EMIT_RB3D_DEPTHXY_OFFSET:
+       case R200_EMIT_RE_AUX_SCISSOR_CNTL:
+       case R200_EMIT_RE_SCISSOR_TL_0:
+       case R200_EMIT_RE_SCISSOR_TL_1:
+       case R200_EMIT_RE_SCISSOR_TL_2:
+       case R200_EMIT_SE_VAP_CNTL_STATUS:
+       case R200_EMIT_SE_VTX_STATE_CNTL:
+       case R200_EMIT_RE_POINTSIZE:
+       case R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0:
+       case R200_EMIT_PP_CUBIC_FACES_0:
+       case R200_EMIT_PP_CUBIC_FACES_1:
+       case R200_EMIT_PP_CUBIC_FACES_2:
+       case R200_EMIT_PP_CUBIC_FACES_3:
+       case R200_EMIT_PP_CUBIC_FACES_4:
+       case R200_EMIT_PP_CUBIC_FACES_5:
+       case RADEON_EMIT_PP_TEX_SIZE_0:
+       case RADEON_EMIT_PP_TEX_SIZE_1:
+       case RADEON_EMIT_PP_TEX_SIZE_2:
+       case R200_EMIT_RB3D_BLENDCOLOR:
+       case R200_EMIT_TCL_POINT_SPRITE_CNTL:
+       case RADEON_EMIT_PP_CUBIC_FACES_0:
+       case RADEON_EMIT_PP_CUBIC_FACES_1:
+       case RADEON_EMIT_PP_CUBIC_FACES_2:
+       case R200_EMIT_PP_TRI_PERF_CNTL:
+       case R200_EMIT_PP_AFS_0:
+       case R200_EMIT_PP_AFS_1:
+       case R200_EMIT_ATF_TFACTOR:
+       case R200_EMIT_PP_TXCTLALL_0:
+       case R200_EMIT_PP_TXCTLALL_1:
+       case R200_EMIT_PP_TXCTLALL_2:
+       case R200_EMIT_PP_TXCTLALL_3:
+       case R200_EMIT_PP_TXCTLALL_4:
+       case R200_EMIT_PP_TXCTLALL_5:
+       case R200_EMIT_VAP_PVS_CNTL:
+               /* These packets don't contain memory offsets */
+               break;
+
+       default:
+               DRM_ERROR("Unknown state packet ID %d\n", id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static __inline__ int radeon_check_and_fixup_packet3(drm_radeon_private_t *
+                                                    dev_priv,
+                                                    struct drm_file *file_priv,
+                                                    drm_radeon_kcmd_buffer_t *
+                                                    cmdbuf,
+                                                    unsigned int *cmdsz)
+{
+       u32 *cmd = (u32 *) cmdbuf->buf;
+       u32 offset, narrays;
+       int count, i, k;
+
+       *cmdsz = 2 + ((cmd[0] & RADEON_CP_PACKET_COUNT_MASK) >> 16);
+
+       if ((cmd[0] & 0xc0000000) != RADEON_CP_PACKET3) {
+               DRM_ERROR("Not a type 3 packet\n");
+               return -EINVAL;
+       }
+
+       if (4 * *cmdsz > cmdbuf->bufsz) {
+               DRM_ERROR("Packet size larger than size of data provided\n");
+               return -EINVAL;
+       }
+
+       switch(cmd[0] & 0xff00) {
+       /* XXX Are there old drivers needing other packets? */
+
+       case RADEON_3D_DRAW_IMMD:
+       case RADEON_3D_DRAW_VBUF:
+       case RADEON_3D_DRAW_INDX:
+       case RADEON_WAIT_FOR_IDLE:
+       case RADEON_CP_NOP:
+       case RADEON_3D_CLEAR_ZMASK:
+/*     case RADEON_CP_NEXT_CHAR:
+       case RADEON_CP_PLY_NEXTSCAN:
+       case RADEON_CP_SET_SCISSORS: */ /* probably safe but will never need them? */
+               /* these packets are safe */
+               break;
+
+       case RADEON_CP_3D_DRAW_IMMD_2:
+       case RADEON_CP_3D_DRAW_VBUF_2:
+       case RADEON_CP_3D_DRAW_INDX_2:
+       case RADEON_3D_CLEAR_HIZ:
+               /* safe but r200 only */
+               if (dev_priv->microcode_version != UCODE_R200) {
+                       DRM_ERROR("Invalid 3d packet for r100-class chip\n");
+                       return -EINVAL;
+               }
+               break;
+
+       case RADEON_3D_LOAD_VBPNTR:
+               count = (cmd[0] >> 16) & 0x3fff;
+
+               if (count > 18) { /* 12 arrays max */
+                       DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
+                                 count);
+                       return -EINVAL;
+               }
+
+               /* carefully check packet contents */
+               narrays = cmd[1] & ~0xc000;
+               k = 0;
+               i = 2;
+               while ((k < narrays) && (i < (count + 2))) {
+                       i++;            /* skip attribute field */
+                       if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                         &cmd[i])) {
+                               DRM_ERROR
+                                   ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
+                                    k, i);
+                               return -EINVAL;
+                       }
+                       k++;
+                       i++;
+                       if (k == narrays)
+                               break;
+                       /* have one more to process, they come in pairs */
+                       if (radeon_check_and_fixup_offset(dev_priv,
+                                                         file_priv, &cmd[i]))
+                       {
+                               DRM_ERROR
+                                   ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
+                                    k, i);
+                               return -EINVAL;
+                       }
+                       k++;
+                       i++;
+               }
+               /* do the counts match what we expect ? */
+               if ((k != narrays) || (i != (count + 2))) {
+                       DRM_ERROR
+                           ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
+                             k, i, narrays, count + 1);
+                       return -EINVAL;
+               }
+               break;
+
+       case RADEON_3D_RNDR_GEN_INDX_PRIM:
+               if (dev_priv->microcode_version != UCODE_R100) {
+                       DRM_ERROR("Invalid 3d packet for r200-class chip\n");
+                       return -EINVAL;
+               }
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv, &cmd[1])) {
+                               DRM_ERROR("Invalid rndr_gen_indx offset\n");
+                               return -EINVAL;
+               }
+               break;
+
+       case RADEON_CP_INDX_BUFFER:
+               if (dev_priv->microcode_version != UCODE_R200) {
+                       DRM_ERROR("Invalid 3d packet for r100-class chip\n");
+                       return -EINVAL;
+               }
+               if ((cmd[1] & 0x8000ffff) != 0x80000810) {
+                       DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
+                       return -EINVAL;
+               }
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv, &cmd[2])) {
+                       DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
+                       return -EINVAL;
+               }
+               break;
+
+       case RADEON_CNTL_HOSTDATA_BLT:
+       case RADEON_CNTL_PAINT_MULTI:
+       case RADEON_CNTL_BITBLT_MULTI:
+               /* MSB of opcode: next DWORD GUI_CNTL */
+               if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
+                             | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
+                       offset = cmd[2] << 10;
+                       if (radeon_check_and_fixup_offset
+                           (dev_priv, file_priv, &offset)) {
+                               DRM_ERROR("Invalid first packet offset\n");
+                               return -EINVAL;
+                       }
+                       cmd[2] = (cmd[2] & 0xffc00000) | offset >> 10;
+               }
+
+               if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
+                   (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
+                       offset = cmd[3] << 10;
+                       if (radeon_check_and_fixup_offset
+                           (dev_priv, file_priv, &offset)) {
+                               DRM_ERROR("Invalid second packet offset\n");
+                               return -EINVAL;
+                       }
+                       cmd[3] = (cmd[3] & 0xffc00000) | offset >> 10;
+               }
+               break;
+
+       default:
+               DRM_ERROR("Invalid packet type %x\n", cmd[0] & 0xff00);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/* ================================================================
+ * CP hardware state programming functions
+ */
+
+static __inline__ void radeon_emit_clip_rect(drm_radeon_private_t * dev_priv,
+                                            struct drm_clip_rect * box)
+{
+       RING_LOCALS;
+
+       DRM_DEBUG("   box:  x1=%d y1=%d  x2=%d y2=%d\n",
+                 box->x1, box->y1, box->x2, box->y2);
+
+       BEGIN_RING(4);
+       OUT_RING(CP_PACKET0(RADEON_RE_TOP_LEFT, 0));
+       OUT_RING((box->y1 << 16) | box->x1);
+       OUT_RING(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT, 0));
+       OUT_RING(((box->y2 - 1) << 16) | (box->x2 - 1));
+       ADVANCE_RING();
+}
+
+/* Emit 1.1 state
+ */
+static int radeon_emit_state(drm_radeon_private_t * dev_priv,
+                            struct drm_file *file_priv,
+                            drm_radeon_context_regs_t * ctx,
+                            drm_radeon_texture_regs_t * tex,
+                            unsigned int dirty)
+{
+       RING_LOCALS;
+       DRM_DEBUG("dirty=0x%08x\n", dirty);
+
+       if (dirty & RADEON_UPLOAD_CONTEXT) {
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &ctx->rb3d_depthoffset)) {
+                       DRM_ERROR("Invalid depth buffer offset\n");
+                       return -EINVAL;
+               }
+
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &ctx->rb3d_coloroffset)) {
+                       DRM_ERROR("Invalid depth buffer offset\n");
+                       return -EINVAL;
+               }
+
+               BEGIN_RING(14);
+               OUT_RING(CP_PACKET0(RADEON_PP_MISC, 6));
+               OUT_RING(ctx->pp_misc);
+               OUT_RING(ctx->pp_fog_color);
+               OUT_RING(ctx->re_solid_color);
+               OUT_RING(ctx->rb3d_blendcntl);
+               OUT_RING(ctx->rb3d_depthoffset);
+               OUT_RING(ctx->rb3d_depthpitch);
+               OUT_RING(ctx->rb3d_zstencilcntl);
+               OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 2));
+               OUT_RING(ctx->pp_cntl);
+               OUT_RING(ctx->rb3d_cntl);
+               OUT_RING(ctx->rb3d_coloroffset);
+               OUT_RING(CP_PACKET0(RADEON_RB3D_COLORPITCH, 0));
+               OUT_RING(ctx->rb3d_colorpitch);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_VERTFMT) {
+               BEGIN_RING(2);
+               OUT_RING(CP_PACKET0(RADEON_SE_COORD_FMT, 0));
+               OUT_RING(ctx->se_coord_fmt);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_LINE) {
+               BEGIN_RING(5);
+               OUT_RING(CP_PACKET0(RADEON_RE_LINE_PATTERN, 1));
+               OUT_RING(ctx->re_line_pattern);
+               OUT_RING(ctx->re_line_state);
+               OUT_RING(CP_PACKET0(RADEON_SE_LINE_WIDTH, 0));
+               OUT_RING(ctx->se_line_width);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_BUMPMAP) {
+               BEGIN_RING(5);
+               OUT_RING(CP_PACKET0(RADEON_PP_LUM_MATRIX, 0));
+               OUT_RING(ctx->pp_lum_matrix);
+               OUT_RING(CP_PACKET0(RADEON_PP_ROT_MATRIX_0, 1));
+               OUT_RING(ctx->pp_rot_matrix_0);
+               OUT_RING(ctx->pp_rot_matrix_1);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_MASKS) {
+               BEGIN_RING(4);
+               OUT_RING(CP_PACKET0(RADEON_RB3D_STENCILREFMASK, 2));
+               OUT_RING(ctx->rb3d_stencilrefmask);
+               OUT_RING(ctx->rb3d_ropcntl);
+               OUT_RING(ctx->rb3d_planemask);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_VIEWPORT) {
+               BEGIN_RING(7);
+               OUT_RING(CP_PACKET0(RADEON_SE_VPORT_XSCALE, 5));
+               OUT_RING(ctx->se_vport_xscale);
+               OUT_RING(ctx->se_vport_xoffset);
+               OUT_RING(ctx->se_vport_yscale);
+               OUT_RING(ctx->se_vport_yoffset);
+               OUT_RING(ctx->se_vport_zscale);
+               OUT_RING(ctx->se_vport_zoffset);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_SETUP) {
+               BEGIN_RING(4);
+               OUT_RING(CP_PACKET0(RADEON_SE_CNTL, 0));
+               OUT_RING(ctx->se_cntl);
+               OUT_RING(CP_PACKET0(RADEON_SE_CNTL_STATUS, 0));
+               OUT_RING(ctx->se_cntl_status);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_MISC) {
+               BEGIN_RING(2);
+               OUT_RING(CP_PACKET0(RADEON_RE_MISC, 0));
+               OUT_RING(ctx->re_misc);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_TEX0) {
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &tex[0].pp_txoffset)) {
+                       DRM_ERROR("Invalid texture offset for unit 0\n");
+                       return -EINVAL;
+               }
+
+               BEGIN_RING(9);
+               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_0, 5));
+               OUT_RING(tex[0].pp_txfilter);
+               OUT_RING(tex[0].pp_txformat);
+               OUT_RING(tex[0].pp_txoffset);
+               OUT_RING(tex[0].pp_txcblend);
+               OUT_RING(tex[0].pp_txablend);
+               OUT_RING(tex[0].pp_tfactor);
+               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_0, 0));
+               OUT_RING(tex[0].pp_border_color);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_TEX1) {
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &tex[1].pp_txoffset)) {
+                       DRM_ERROR("Invalid texture offset for unit 1\n");
+                       return -EINVAL;
+               }
+
+               BEGIN_RING(9);
+               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_1, 5));
+               OUT_RING(tex[1].pp_txfilter);
+               OUT_RING(tex[1].pp_txformat);
+               OUT_RING(tex[1].pp_txoffset);
+               OUT_RING(tex[1].pp_txcblend);
+               OUT_RING(tex[1].pp_txablend);
+               OUT_RING(tex[1].pp_tfactor);
+               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_1, 0));
+               OUT_RING(tex[1].pp_border_color);
+               ADVANCE_RING();
+       }
+
+       if (dirty & RADEON_UPLOAD_TEX2) {
+               if (radeon_check_and_fixup_offset(dev_priv, file_priv,
+                                                 &tex[2].pp_txoffset)) {
+                       DRM_ERROR("Invalid texture offset for unit 2\n");
+                       return -EINVAL;
+               }
+
+               BEGIN_RING(9);
+               OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_2, 5));
+               OUT_RING(tex[2].pp_txfilter);
+               OUT_RING(tex[2].pp_txformat);
+               OUT_RING(tex[2].pp_txoffset);
+               OUT_RING(tex[2].pp_txcblend);
+               OUT_RING(tex[2].pp_txablend);
+               OUT_RING(tex[2].pp_tfactor);
+               OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_2, 0));
+               OUT_RING(tex[2].pp_border_color);
+               ADVANCE_RING();
+       }
+
+       return 0;
+}
+
+/* Emit 1.2 state
+ */
+static int radeon_emit_state2(drm_radeon_private_t * dev_priv,
+                             struct drm_file *file_priv,
+                             drm_radeon_state_t * state)
+{
+       RING_LOCALS;
+
+       if (state->dirty & RADEON_UPLOAD_ZBIAS) {
+               BEGIN_RING(3);
+               OUT_RING(CP_PACKET0(RADEON_SE_ZBIAS_FACTOR, 1));
+               OUT_RING(state->context2.se_zbias_factor);
+               OUT_RING(state->context2.se_zbias_constant);
+               ADVANCE_RING();
+       }
+
+       return radeon_emit_state(dev_priv, file_priv, &state->context,
+                                state->tex, state->dirty);
+}
+
+/* New (1.3) state mechanism.  3 commands (packet, scalar, vector) in
+ * 1.3 cmdbuffers allow all previous state to be updated as well as
+ * the tcl scalar and vector areas.
+ */
+static struct {
+       int start;
+       int len;
+       const char *name;
+} packet[RADEON_MAX_STATE_PACKETS] = {
+       {RADEON_PP_MISC, 7, "RADEON_PP_MISC"},
+       {RADEON_PP_CNTL, 3, "RADEON_PP_CNTL"},
+       {RADEON_RB3D_COLORPITCH, 1, "RADEON_RB3D_COLORPITCH"},
+       {RADEON_RE_LINE_PATTERN, 2, "RADEON_RE_LINE_PATTERN"},
+       {RADEON_SE_LINE_WIDTH, 1, "RADEON_SE_LINE_WIDTH"},
+       {RADEON_PP_LUM_MATRIX, 1, "RADEON_PP_LUM_MATRIX"},
+       {RADEON_PP_ROT_MATRIX_0, 2, "RADEON_PP_ROT_MATRIX_0"},
+       {RADEON_RB3D_STENCILREFMASK, 3, "RADEON_RB3D_STENCILREFMASK"},
+       {RADEON_SE_VPORT_XSCALE, 6, "RADEON_SE_VPORT_XSCALE"},
+       {RADEON_SE_CNTL, 2, "RADEON_SE_CNTL"},
+       {RADEON_SE_CNTL_STATUS, 1, "RADEON_SE_CNTL_STATUS"},
+       {RADEON_RE_MISC, 1, "RADEON_RE_MISC"},
+       {RADEON_PP_TXFILTER_0, 6, "RADEON_PP_TXFILTER_0"},
+       {RADEON_PP_BORDER_COLOR_0, 1, "RADEON_PP_BORDER_COLOR_0"},
+       {RADEON_PP_TXFILTER_1, 6, "RADEON_PP_TXFILTER_1"},
+       {RADEON_PP_BORDER_COLOR_1, 1, "RADEON_PP_BORDER_COLOR_1"},
+       {RADEON_PP_TXFILTER_2, 6, "RADEON_PP_TXFILTER_2"},
+       {RADEON_PP_BORDER_COLOR_2, 1, "RADEON_PP_BORDER_COLOR_2"},
+       {RADEON_SE_ZBIAS_FACTOR, 2, "RADEON_SE_ZBIAS_FACTOR"},
+       {RADEON_SE_TCL_OUTPUT_VTX_FMT, 11, "RADEON_SE_TCL_OUTPUT_VTX_FMT"},
+       {RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED, 17,
+                   "RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
+       {R200_PP_TXCBLEND_0, 4, "R200_PP_TXCBLEND_0"},
+       {R200_PP_TXCBLEND_1, 4, "R200_PP_TXCBLEND_1"},
+       {R200_PP_TXCBLEND_2, 4, "R200_PP_TXCBLEND_2"},
+       {R200_PP_TXCBLEND_3, 4, "R200_PP_TXCBLEND_3"},
+       {R200_PP_TXCBLEND_4, 4, "R200_PP_TXCBLEND_4"},
+       {R200_PP_TXCBLEND_5, 4, "R200_PP_TXCBLEND_5"},
+       {R200_PP_TXCBLEND_6, 4, "R200_PP_TXCBLEND_6"},
+       {R200_PP_TXCBLEND_7, 4, "R200_PP_TXCBLEND_7"},
+       {R200_SE_TCL_LIGHT_MODEL_CTL_0, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0"},
+       {R200_PP_TFACTOR_0, 6, "R200_PP_TFACTOR_0"},
+       {R200_SE_VTX_FMT_0, 4, "R200_SE_VTX_FMT_0"},
+       {R200_SE_VAP_CNTL, 1, "R200_SE_VAP_CNTL"},
+       {R200_SE_TCL_MATRIX_SEL_0, 5, "R200_SE_TCL_MATRIX_SEL_0"},
+       {R200_SE_TCL_TEX_PROC_CTL_2, 5, "R200_SE_TCL_TEX_PROC_CTL_2"},
+       {R200_SE_TCL_UCP_VERT_BLEND_CTL, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL"},
+       {R200_PP_TXFILTER_0, 6, "R200_PP_TXFILTER_0"},
+       {R200_PP_TXFILTER_1, 6, "R200_PP_TXFILTER_1"},
+       {R200_PP_TXFILTER_2, 6, "R200_PP_TXFILTER_2"},
+       {R200_PP_TXFILTER_3, 6, "R200_PP_TXFILTER_3"},
+       {R200_PP_TXFILTER_4, 6, "R200_PP_TXFILTER_4"},
+       {R200_PP_TXFILTER_5, 6, "R200_PP_TXFILTER_5"},
+       {R200_PP_TXOFFSET_0, 1, "R200_PP_TXOFFSET_0"},
+       {R200_PP_TXOFFSET_1, 1, "R200_PP_TXOFFSET_1"},
+       {R200_PP_TXOFFSET_2, 1, "R200_PP_TXOFFSET_2"},
+       {R200_PP_TXOFFSET_3, 1, "R200_PP_TXOFFSET_3"},
+       {R200_PP_TXOFFSET_4, 1, "R200_PP_TXOFFSET_4"},
+       {R200_PP_TXOFFSET_5, 1, "R200_PP_TXOFFSET_5"},
+       {R200_SE_VTE_CNTL, 1, "R200_SE_VTE_CNTL"},
+       {R200_SE_TCL_OUTPUT_VTX_COMP_SEL, 1,
+        "R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
+       {R200_PP_TAM_DEBUG3, 1, "R200_PP_TAM_DEBUG3"},
+       {R200_PP_CNTL_X, 1, "R200_PP_CNTL_X"},
+       {R200_RB3D_DEPTHXY_OFFSET, 1, "R200_RB3D_DEPTHXY_OFFSET"},
+       {R200_RE_AUX_SCISSOR_CNTL, 1, "R200_RE_AUX_SCISSOR_CNTL"},
+       {R200_RE_SCISSOR_TL_0, 2, "R200_RE_SCISSOR_TL_0"},
+       {R200_RE_SCISSOR_TL_1, 2, "R200_RE_SCISSOR_TL_1"},
+       {R200_RE_SCISSOR_TL_2, 2, "R200_RE_SCISSOR_TL_2"},
+       {R200_SE_VAP_CNTL_STATUS, 1, "R200_SE_VAP_CNTL_STATUS"},
+       {R200_SE_VTX_STATE_CNTL, 1, "R200_SE_VTX_STATE_CNTL"},
+       {R200_RE_POINTSIZE, 1, "R200_RE_POINTSIZE"},
+       {R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0, 4,
+                   "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
+       {R200_PP_CUBIC_FACES_0, 1, "R200_PP_CUBIC_FACES_0"},    /* 61 */
+       {R200_PP_CUBIC_OFFSET_F1_0, 5, "R200_PP_CUBIC_OFFSET_F1_0"}, /* 62 */
+       {R200_PP_CUBIC_FACES_1, 1, "R200_PP_CUBIC_FACES_1"},
+       {R200_PP_CUBIC_OFFSET_F1_1, 5, "R200_PP_CUBIC_OFFSET_F1_1"},
+       {R200_PP_CUBIC_FACES_2, 1, "R200_PP_CUBIC_FACES_2"},
+       {R200_PP_CUBIC_OFFSET_F1_2, 5, "R200_PP_CUBIC_OFFSET_F1_2"},
+       {R200_PP_CUBIC_FACES_3, 1, "R200_PP_CUBIC_FACES_3"},
+       {R200_PP_CUBIC_OFFSET_F1_3, 5, "R200_PP_CUBIC_OFFSET_F1_3"},
+       {R200_PP_CUBIC_FACES_4, 1, "R200_PP_CUBIC_FACES_4"},
+       {R200_PP_CUBIC_OFFSET_F1_4, 5, "R200_PP_CUBIC_OFFSET_F1_4"},
+       {R200_PP_CUBIC_FACES_5, 1, "R200_PP_CUBIC_FACES_5"},
+       {R200_PP_CUBIC_OFFSET_F1_5, 5, "R200_PP_CUBIC_OFFSET_F1_5"},
+       {RADEON_PP_TEX_SIZE_0, 2, "RADEON_PP_TEX_SIZE_0"},
+       {RADEON_PP_TEX_SIZE_1, 2, "RADEON_PP_TEX_SIZE_1"},
+       {RADEON_PP_TEX_SIZE_2, 2, "RADEON_PP_TEX_SIZE_2"},
+       {R200_RB3D_BLENDCOLOR, 3, "R200_RB3D_BLENDCOLOR"},
+       {R200_SE_TCL_POINT_SPRITE_CNTL, 1, "R200_SE_TCL_POINT_SPRITE_CNTL"},
+       {RADEON_PP_CUBIC_FACES_0, 1, "RADEON_PP_CUBIC_FACES_0"},
+       {RADEON_PP_CUBIC_OFFSET_T0_0, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
+       {RADEON_PP_CUBIC_FACES_1, 1, "RADEON_PP_CUBIC_FACES_1"},
+       {RADEON_PP_CUBIC_OFFSET_T1_0, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
+       {RADEON_PP_CUBIC_FACES_2, 1, "RADEON_PP_CUBIC_FACES_2"},
+       {RADEON_PP_CUBIC_OFFSET_T2_0, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
+       {R200_PP_TRI_PERF, 2, "R200_PP_TRI_PERF"},
+       {R200_PP_AFS_0, 32, "R200_PP_AFS_0"},     /* 85 */
+       {R200_PP_AFS_1, 32, "R200_PP_AFS_1"},
+       {R200_PP_TFACTOR_0, 8, "R200_ATF_TFACTOR"},
+       {R200_PP_TXFILTER_0, 8, "R200_PP_TXCTLALL_0"},
+       {R200_PP_TXFILTER_1, 8, "R200_PP_TXCTLALL_1"},
+       {R200_PP_TXFILTER_2, 8, "R200_PP_TXCTLALL_2"},
+       {R200_PP_TXFILTER_3, 8, "R200_PP_TXCTLALL_3"},
+       {R200_PP_TXFILTER_4, 8, "R200_PP_TXCTLALL_4"},
+       {R200_PP_TXFILTER_5, 8, "R200_PP_TXCTLALL_5"},
+       {R200_VAP_PVS_CNTL_1, 2, "R200_VAP_PVS_CNTL"},
+};
+
+/* ================================================================
+ * Performance monitoring functions
+ */
+
+static void radeon_clear_box(drm_radeon_private_t * dev_priv,
+                            int x, int y, int w, int h, int r, int g, int b)
+{
+       u32 color;
+       RING_LOCALS;
+
+       x += dev_priv->sarea_priv->boxes[0].x1;
+       y += dev_priv->sarea_priv->boxes[0].y1;
+
+       switch (dev_priv->color_fmt) {
+       case RADEON_COLOR_FORMAT_RGB565:
+               color = (((r & 0xf8) << 8) |
+                        ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
+               break;
+       case RADEON_COLOR_FORMAT_ARGB8888:
+       default:
+               color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
+               break;
+       }
+
+       BEGIN_RING(4);
+       RADEON_WAIT_UNTIL_3D_IDLE();
+       OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
+       OUT_RING(0xffffffff);
+       ADVANCE_RING();
+
+       BEGIN_RING(6);
+
+       OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
+       OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+                RADEON_GMC_BRUSH_SOLID_COLOR |
+                (dev_priv->color_fmt << 8) |
+                RADEON_GMC_SRC_DATATYPE_COLOR |
+                RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS);
+
+       if (dev_priv->sarea_priv->pfCurrentPage == 1) {
+               OUT_RING(dev_priv->front_pitch_offset);
+       } else {
+               OUT_RING(dev_priv->back_pitch_offset);
+       }
+
+       OUT_RING(color);
+
+       OUT_RING((x << 16) | y);
+       OUT_RING((w << 16) | h);
+
+       ADVANCE_RING();
+}
+
+static void radeon_cp_performance_boxes(drm_radeon_private_t * dev_priv)
+{
+       /* Collapse various things into a wait flag -- trying to
+        * guess if userspase slept -- better just to have them tell us.
+        */
+       if (dev_priv->stats.last_frame_reads > 1 ||
+           dev_priv->stats.last_clear_reads > dev_priv->stats.clears) {
+               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+       }
+
+       if (dev_priv->stats.freelist_loops) {
+               dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
+       }
+
+       /* Purple box for page flipping
+        */
+       if (dev_priv->stats.boxes & RADEON_BOX_FLIP)
+               radeon_clear_box(dev_priv, 4, 4, 8, 8, 255, 0, 255);
+
+       /* Red box if we have to wait for idle at any point
+        */
+       if (dev_priv->stats.boxes & RADEON_BOX_WAIT_IDLE)
+               radeon_clear_box(dev_priv, 16, 4, 8, 8, 255, 0, 0);
+
+       /* Blue box: lost context?
+        */
+
+       /* Yellow box for texture swaps
+        */
+       if (dev_priv->stats.boxes & RADEON_BOX_TEXTURE_LOAD)
+               radeon_clear_box(dev_priv, 40, 4, 8, 8, 255, 255, 0);
+
+       /* Green box if hardware never idles (as far as we can tell)
+        */
+       if (!(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE))
+               radeon_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
+
+       /* Draw bars indicating number of buffers allocated
+        * (not a great measure, easily confused)
+        */
+       if (dev_priv->stats.requested_bufs) {
+               if (dev_priv->stats.requested_bufs > 100)
+                       dev_priv->stats.requested_bufs = 100;
+
+               radeon_clear_box(dev_priv, 4, 16,
+                                dev_priv->stats.requested_bufs, 4,
+                                196, 128, 128);
+       }
+
+       memset(&dev_priv->stats, 0, sizeof(dev_priv->stats));
+
+}
+
+/* ================================================================
+ * CP command dispatch functions
+ */
+
+static void radeon_cp_dispatch_clear(struct drm_device * dev,
+                                    drm_radeon_clear_t * clear,
+                                    drm_radeon_clear_rect_t * depth_boxes)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_radeon_depth_clear_t *depth_clear = &dev_priv->depth_clear;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       unsigned int flags = clear->flags;
+       u32 rb3d_cntl = 0, rb3d_stencilrefmask = 0;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("flags = 0x%x\n", flags);
+
+       dev_priv->stats.clears++;
+
+       if (dev_priv->sarea_priv->pfCurrentPage == 1) {
+               unsigned int tmp = flags;
+
+               flags &= ~(RADEON_FRONT | RADEON_BACK);
+               if (tmp & RADEON_FRONT)
+                       flags |= RADEON_BACK;
+               if (tmp & RADEON_BACK)
+                       flags |= RADEON_FRONT;
+       }
+
+       if (flags & (RADEON_FRONT | RADEON_BACK)) {
+
+               BEGIN_RING(4);
+
+               /* Ensure the 3D stream is idle before doing a
+                * 2D fill to clear the front or back buffer.
+                */
+               RADEON_WAIT_UNTIL_3D_IDLE();
+
+               OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK, 0));
+               OUT_RING(clear->color_mask);
+
+               ADVANCE_RING();
+
+               /* Make sure we restore the 3D state next time.
+                */
+               dev_priv->sarea_priv->ctx_owner = 0;
+
+               for (i = 0; i < nbox; i++) {
+                       int x = pbox[i].x1;
+                       int y = pbox[i].y1;
+                       int w = pbox[i].x2 - x;
+                       int h = pbox[i].y2 - y;
+
+                       DRM_DEBUG("%d,%d-%d,%d flags 0x%x\n",
+                                 x, y, w, h, flags);
+
+                       if (flags & RADEON_FRONT) {
+                               BEGIN_RING(6);
+
+                               OUT_RING(CP_PACKET3
+                                        (RADEON_CNTL_PAINT_MULTI, 4));
+                               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+                                        RADEON_GMC_BRUSH_SOLID_COLOR |
+                                        (dev_priv->
+                                         color_fmt << 8) |
+                                        RADEON_GMC_SRC_DATATYPE_COLOR |
+                                        RADEON_ROP3_P |
+                                        RADEON_GMC_CLR_CMP_CNTL_DIS);
+
+                               OUT_RING(dev_priv->front_pitch_offset);
+                               OUT_RING(clear->clear_color);
+
+                               OUT_RING((x << 16) | y);
+                               OUT_RING((w << 16) | h);
+
+                               ADVANCE_RING();
+                       }
+
+                       if (flags & RADEON_BACK) {
+                               BEGIN_RING(6);
+
+                               OUT_RING(CP_PACKET3
+                                        (RADEON_CNTL_PAINT_MULTI, 4));
+                               OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+                                        RADEON_GMC_BRUSH_SOLID_COLOR |
+                                        (dev_priv->
+                                         color_fmt << 8) |
+                                        RADEON_GMC_SRC_DATATYPE_COLOR |
+                                        RADEON_ROP3_P |
+                                        RADEON_GMC_CLR_CMP_CNTL_DIS);
+
+                               OUT_RING(dev_priv->back_pitch_offset);
+                               OUT_RING(clear->clear_color);
+
+                               OUT_RING((x << 16) | y);
+                               OUT_RING((w << 16) | h);
+
+                               ADVANCE_RING();
+                       }
+               }
+       }
+
+       /* hyper z clear */
+       /* no docs available, based on reverse engeneering by Stephane Marchesin */
+       if ((flags & (RADEON_DEPTH | RADEON_STENCIL))
+           && (flags & RADEON_CLEAR_FASTZ)) {
+
+               int i;
+               int depthpixperline =
+                   dev_priv->depth_fmt ==
+                   RADEON_DEPTH_FORMAT_16BIT_INT_Z ? (dev_priv->depth_pitch /
+                                                      2) : (dev_priv->
+                                                            depth_pitch / 4);
+
+               u32 clearmask;
+
+               u32 tempRB3D_DEPTHCLEARVALUE = clear->clear_depth |
+                   ((clear->depth_mask & 0xff) << 24);
+
+               /* Make sure we restore the 3D state next time.
+                * we haven't touched any "normal" state - still need this?
+                */
+               dev_priv->sarea_priv->ctx_owner = 0;
+
+               if ((dev_priv->flags & RADEON_HAS_HIERZ)
+                   && (flags & RADEON_USE_HIERZ)) {
+                       /* FIXME : reverse engineer that for Rx00 cards */
+                       /* FIXME : the mask supposedly contains low-res z values. So can't set
+                          just to the max (0xff? or actually 0x3fff?), need to take z clear
+                          value into account? */
+                       /* pattern seems to work for r100, though get slight
+                          rendering errors with glxgears. If hierz is not enabled for r100,
+                          only 4 bits which indicate clear (15,16,31,32, all zero) matter, the
+                          other ones are ignored, and the same clear mask can be used. That's
+                          very different behaviour than R200 which needs different clear mask
+                          and different number of tiles to clear if hierz is enabled or not !?!
+                        */
+                       clearmask = (0xff << 22) | (0xff << 6) | 0x003f003f;
+               } else {
+                       /* clear mask : chooses the clearing pattern.
+                          rv250: could be used to clear only parts of macrotiles
+                          (but that would get really complicated...)?
+                          bit 0 and 1 (either or both of them ?!?!) are used to
+                          not clear tile (or maybe one of the bits indicates if the tile is
+                          compressed or not), bit 2 and 3 to not clear tile 1,...,.
+                          Pattern is as follows:
+                          | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
+                          bits -------------------------------------------------
+                          | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
+                          rv100: clearmask covers 2x8 4x1 tiles, but one clear still
+                          covers 256 pixels ?!?
+                        */
+                       clearmask = 0x0;
+               }
+
+               BEGIN_RING(8);
+               RADEON_WAIT_UNTIL_2D_IDLE();
+               OUT_RING_REG(RADEON_RB3D_DEPTHCLEARVALUE,
+                            tempRB3D_DEPTHCLEARVALUE);
+               /* what offset is this exactly ? */
+               OUT_RING_REG(RADEON_RB3D_ZMASKOFFSET, 0);
+               /* need ctlstat, otherwise get some strange black flickering */
+               OUT_RING_REG(RADEON_RB3D_ZCACHE_CTLSTAT,
+                            RADEON_RB3D_ZC_FLUSH_ALL);
+               ADVANCE_RING();
+
+               for (i = 0; i < nbox; i++) {
+                       int tileoffset, nrtilesx, nrtilesy, j;
+                       /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
+                       if ((dev_priv->flags & RADEON_HAS_HIERZ)
+                           && !(dev_priv->microcode_version == UCODE_R200)) {
+                               /* FIXME : figure this out for r200 (when hierz is enabled). Or
+                                  maybe r200 actually doesn't need to put the low-res z value into
+                                  the tile cache like r100, but just needs to clear the hi-level z-buffer?
+                                  Works for R100, both with hierz and without.
+                                  R100 seems to operate on 2x1 8x8 tiles, but...
+                                  odd: offset/nrtiles need to be 64 pix (4 block) aligned? Potentially
+                                  problematic with resolutions which are not 64 pix aligned? */
+                               tileoffset =
+                                   ((pbox[i].y1 >> 3) * depthpixperline +
+                                    pbox[i].x1) >> 6;
+                               nrtilesx =
+                                   ((pbox[i].x2 & ~63) -
+                                    (pbox[i].x1 & ~63)) >> 4;
+                               nrtilesy =
+                                   (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
+                               for (j = 0; j <= nrtilesy; j++) {
+                                       BEGIN_RING(4);
+                                       OUT_RING(CP_PACKET3
+                                                (RADEON_3D_CLEAR_ZMASK, 2));
+                                       /* first tile */
+                                       OUT_RING(tileoffset * 8);
+                                       /* the number of tiles to clear */
+                                       OUT_RING(nrtilesx + 4);
+                                       /* clear mask : chooses the clearing pattern. */
+                                       OUT_RING(clearmask);
+                                       ADVANCE_RING();
+                                       tileoffset += depthpixperline >> 6;
+                               }
+                       } else if (dev_priv->microcode_version == UCODE_R200) {
+                               /* works for rv250. */
+                               /* find first macro tile (8x2 4x4 z-pixels on rv250) */
+                               tileoffset =
+                                   ((pbox[i].y1 >> 3) * depthpixperline +
+                                    pbox[i].x1) >> 5;
+                               nrtilesx =
+                                   (pbox[i].x2 >> 5) - (pbox[i].x1 >> 5);
+                               nrtilesy =
+                                   (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
+                               for (j = 0; j <= nrtilesy; j++) {
+                                       BEGIN_RING(4);
+                                       OUT_RING(CP_PACKET3
+                                                (RADEON_3D_CLEAR_ZMASK, 2));
+                                       /* first tile */
+                                       /* judging by the first tile offset needed, could possibly
+                                          directly address/clear 4x4 tiles instead of 8x2 * 4x4
+                                          macro tiles, though would still need clear mask for
+                                          right/bottom if truely 4x4 granularity is desired ? */
+                                       OUT_RING(tileoffset * 16);
+                                       /* the number of tiles to clear */
+                                       OUT_RING(nrtilesx + 1);
+                                       /* clear mask : chooses the clearing pattern. */
+                                       OUT_RING(clearmask);
+                                       ADVANCE_RING();
+                                       tileoffset += depthpixperline >> 5;
+                               }
+                       } else {        /* rv 100 */
+                               /* rv100 might not need 64 pix alignment, who knows */
+                               /* offsets are, hmm, weird */
+                               tileoffset =
+                                   ((pbox[i].y1 >> 4) * depthpixperline +
+                                    pbox[i].x1) >> 6;
+                               nrtilesx =
+                                   ((pbox[i].x2 & ~63) -
+                                    (pbox[i].x1 & ~63)) >> 4;
+                               nrtilesy =
+                                   (pbox[i].y2 >> 4) - (pbox[i].y1 >> 4);
+                               for (j = 0; j <= nrtilesy; j++) {
+                                       BEGIN_RING(4);
+                                       OUT_RING(CP_PACKET3
+                                                (RADEON_3D_CLEAR_ZMASK, 2));
+                                       OUT_RING(tileoffset * 128);
+                                       /* the number of tiles to clear */
+                                       OUT_RING(nrtilesx + 4);
+                                       /* clear mask : chooses the clearing pattern. */
+                                       OUT_RING(clearmask);
+                                       ADVANCE_RING();
+                                       tileoffset += depthpixperline >> 6;
+                               }
+                       }
+               }
+
+               /* TODO don't always clear all hi-level z tiles */
+               if ((dev_priv->flags & RADEON_HAS_HIERZ)
+                   && (dev_priv->microcode_version == UCODE_R200)
+                   && (flags & RADEON_USE_HIERZ))
+                       /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
+                       /* FIXME : the mask supposedly contains low-res z values. So can't set
+                          just to the max (0xff? or actually 0x3fff?), need to take z clear
+                          value into account? */
+               {
+                       BEGIN_RING(4);
+                       OUT_RING(CP_PACKET3(RADEON_3D_CLEAR_HIZ, 2));
+                       OUT_RING(0x0);  /* First tile */
+                       OUT_RING(0x3cc0);
+                       OUT_RING((0xff << 22) | (0xff << 6) | 0x003f003f);
+                       ADVANCE_RING();
+               }
+       }
+
+       /* We have to clear the depth and/or stencil buffers by
+        * rendering a quad into just those buffers.  Thus, we have to
+        * make sure the 3D engine is configured correctly.
+        */
+       else if ((dev_priv->microcode_version == UCODE_R200) &&
+               (flags & (RADEON_DEPTH | RADEON_STENCIL))) {
+
+               int tempPP_CNTL;
+               int tempRE_CNTL;
+               int tempRB3D_CNTL;
+               int tempRB3D_ZSTENCILCNTL;
+               int tempRB3D_STENCILREFMASK;
+               int tempRB3D_PLANEMASK;
+               int tempSE_CNTL;
+               int tempSE_VTE_CNTL;
+               int tempSE_VTX_FMT_0;
+               int tempSE_VTX_FMT_1;
+               int tempSE_VAP_CNTL;
+               int tempRE_AUX_SCISSOR_CNTL;
+
+               tempPP_CNTL = 0;
+               tempRE_CNTL = 0;
+
+               tempRB3D_CNTL = depth_clear->rb3d_cntl;
+
+               tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
+               tempRB3D_STENCILREFMASK = 0x0;
+
+               tempSE_CNTL = depth_clear->se_cntl;
+
+               /* Disable TCL */
+
+               tempSE_VAP_CNTL = (     /* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK |  */
+                                         (0x9 <<
+                                          SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT));
+
+               tempRB3D_PLANEMASK = 0x0;
+
+               tempRE_AUX_SCISSOR_CNTL = 0x0;
+
+               tempSE_VTE_CNTL =
+                   SE_VTE_CNTL__VTX_XY_FMT_MASK | SE_VTE_CNTL__VTX_Z_FMT_MASK;
+
+               /* Vertex format (X, Y, Z, W) */
+               tempSE_VTX_FMT_0 =
+                   SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK |
+                   SE_VTX_FMT_0__VTX_W0_PRESENT_MASK;
+               tempSE_VTX_FMT_1 = 0x0;
+
+               /*
+                * Depth buffer specific enables
+                */
+               if (flags & RADEON_DEPTH) {
+                       /* Enable depth buffer */
+                       tempRB3D_CNTL |= RADEON_Z_ENABLE;
+               } else {
+                       /* Disable depth buffer */
+                       tempRB3D_CNTL &= ~RADEON_Z_ENABLE;
+               }
+
+               /*
+                * Stencil buffer specific enables
+                */
+               if (flags & RADEON_STENCIL) {
+                       tempRB3D_CNTL |= RADEON_STENCIL_ENABLE;
+                       tempRB3D_STENCILREFMASK = clear->depth_mask;
+               } else {
+                       tempRB3D_CNTL &= ~RADEON_STENCIL_ENABLE;
+                       tempRB3D_STENCILREFMASK = 0x00000000;
+               }
+
+               if (flags & RADEON_USE_COMP_ZBUF) {
+                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
+                           RADEON_Z_DECOMPRESSION_ENABLE;
+               }
+               if (flags & RADEON_USE_HIERZ) {
+                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
+               }
+
+               BEGIN_RING(26);
+               RADEON_WAIT_UNTIL_2D_IDLE();
+
+               OUT_RING_REG(RADEON_PP_CNTL, tempPP_CNTL);
+               OUT_RING_REG(R200_RE_CNTL, tempRE_CNTL);
+               OUT_RING_REG(RADEON_RB3D_CNTL, tempRB3D_CNTL);
+               OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
+               OUT_RING_REG(RADEON_RB3D_STENCILREFMASK,
+                            tempRB3D_STENCILREFMASK);
+               OUT_RING_REG(RADEON_RB3D_PLANEMASK, tempRB3D_PLANEMASK);
+               OUT_RING_REG(RADEON_SE_CNTL, tempSE_CNTL);
+               OUT_RING_REG(R200_SE_VTE_CNTL, tempSE_VTE_CNTL);
+               OUT_RING_REG(R200_SE_VTX_FMT_0, tempSE_VTX_FMT_0);
+               OUT_RING_REG(R200_SE_VTX_FMT_1, tempSE_VTX_FMT_1);
+               OUT_RING_REG(R200_SE_VAP_CNTL, tempSE_VAP_CNTL);
+               OUT_RING_REG(R200_RE_AUX_SCISSOR_CNTL, tempRE_AUX_SCISSOR_CNTL);
+               ADVANCE_RING();
+
+               /* Make sure we restore the 3D state next time.
+                */
+               dev_priv->sarea_priv->ctx_owner = 0;
+
+               for (i = 0; i < nbox; i++) {
+
+                       /* Funny that this should be required --
+                        *  sets top-left?
+                        */
+                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
+
+                       BEGIN_RING(14);
+                       OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2, 12));
+                       OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
+                                 RADEON_PRIM_WALK_RING |
+                                 (3 << RADEON_NUM_VERTICES_SHIFT)));
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x3f800000);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x3f800000);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x3f800000);
+                       ADVANCE_RING();
+               }
+       } else if ((flags & (RADEON_DEPTH | RADEON_STENCIL))) {
+
+               int tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
+
+               rb3d_cntl = depth_clear->rb3d_cntl;
+
+               if (flags & RADEON_DEPTH) {
+                       rb3d_cntl |= RADEON_Z_ENABLE;
+               } else {
+                       rb3d_cntl &= ~RADEON_Z_ENABLE;
+               }
+
+               if (flags & RADEON_STENCIL) {
+                       rb3d_cntl |= RADEON_STENCIL_ENABLE;
+                       rb3d_stencilrefmask = clear->depth_mask;        /* misnamed field */
+               } else {
+                       rb3d_cntl &= ~RADEON_STENCIL_ENABLE;
+                       rb3d_stencilrefmask = 0x00000000;
+               }
+
+               if (flags & RADEON_USE_COMP_ZBUF) {
+                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
+                           RADEON_Z_DECOMPRESSION_ENABLE;
+               }
+               if (flags & RADEON_USE_HIERZ) {
+                       tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
+               }
+
+               BEGIN_RING(13);
+               RADEON_WAIT_UNTIL_2D_IDLE();
+
+               OUT_RING(CP_PACKET0(RADEON_PP_CNTL, 1));
+               OUT_RING(0x00000000);
+               OUT_RING(rb3d_cntl);
+
+               OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL);
+               OUT_RING_REG(RADEON_RB3D_STENCILREFMASK, rb3d_stencilrefmask);
+               OUT_RING_REG(RADEON_RB3D_PLANEMASK, 0x00000000);
+               OUT_RING_REG(RADEON_SE_CNTL, depth_clear->se_cntl);
+               ADVANCE_RING();
+
+               /* Make sure we restore the 3D state next time.
+                */
+               dev_priv->sarea_priv->ctx_owner = 0;
+
+               for (i = 0; i < nbox; i++) {
+
+                       /* Funny that this should be required --
+                        *  sets top-left?
+                        */
+                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
+
+                       BEGIN_RING(15);
+
+                       OUT_RING(CP_PACKET3(RADEON_3D_DRAW_IMMD, 13));
+                       OUT_RING(RADEON_VTX_Z_PRESENT |
+                                RADEON_VTX_PKCOLOR_PRESENT);
+                       OUT_RING((RADEON_PRIM_TYPE_RECT_LIST |
+                                 RADEON_PRIM_WALK_RING |
+                                 RADEON_MAOS_ENABLE |
+                                 RADEON_VTX_FMT_RADEON_MODE |
+                                 (3 << RADEON_NUM_VERTICES_SHIFT)));
+
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x0);
+
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X1]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x0);
+
+                       OUT_RING(depth_boxes[i].ui[CLEAR_X2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_Y2]);
+                       OUT_RING(depth_boxes[i].ui[CLEAR_DEPTH]);
+                       OUT_RING(0x0);
+
+                       ADVANCE_RING();
+               }
+       }
+
+       /* Increment the clear counter.  The client-side 3D driver must
+        * wait on this value before performing the clear ioctl.  We
+        * need this because the card's so damned fast...
+        */
+       dev_priv->sarea_priv->last_clear++;
+
+       BEGIN_RING(4);
+
+       RADEON_CLEAR_AGE(dev_priv->sarea_priv->last_clear);
+       RADEON_WAIT_UNTIL_IDLE();
+
+       ADVANCE_RING();
+}
+
+static void radeon_cp_dispatch_swap(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int nbox = sarea_priv->nbox;
+       struct drm_clip_rect *pbox = sarea_priv->boxes;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       /* Do some trivial performance monitoring...
+        */
+       if (dev_priv->do_boxes)
+               radeon_cp_performance_boxes(dev_priv);
+
+       /* Wait for the 3D stream to idle before dispatching the bitblt.
+        * This will prevent data corruption between the two streams.
+        */
+       BEGIN_RING(2);
+
+       RADEON_WAIT_UNTIL_3D_IDLE();
+
+       ADVANCE_RING();
+
+       for (i = 0; i < nbox; i++) {
+               int x = pbox[i].x1;
+               int y = pbox[i].y1;
+               int w = pbox[i].x2 - x;
+               int h = pbox[i].y2 - y;
+
+               DRM_DEBUG("%d,%d-%d,%d\n", x, y, w, h);
+
+               BEGIN_RING(9);
+
+               OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL, 0));
+               OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
+                        RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+                        RADEON_GMC_BRUSH_NONE |
+                        (dev_priv->color_fmt << 8) |
+                        RADEON_GMC_SRC_DATATYPE_COLOR |
+                        RADEON_ROP3_S |
+                        RADEON_DP_SRC_SOURCE_MEMORY |
+                        RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
+
+               /* Make this work even if front & back are flipped:
+                */
+               OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
+               if (dev_priv->sarea_priv->pfCurrentPage == 0) {
+                       OUT_RING(dev_priv->back_pitch_offset);
+                       OUT_RING(dev_priv->front_pitch_offset);
+               } else {
+                       OUT_RING(dev_priv->front_pitch_offset);
+                       OUT_RING(dev_priv->back_pitch_offset);
+               }
+
+               OUT_RING(CP_PACKET0(RADEON_SRC_X_Y, 2));
+               OUT_RING((x << 16) | y);
+               OUT_RING((x << 16) | y);
+               OUT_RING((w << 16) | h);
+
+               ADVANCE_RING();
+       }
+
+       /* Increment the frame counter.  The client-side 3D driver must
+        * throttle the framerate by waiting for this value before
+        * performing the swapbuffer ioctl.
+        */
+       dev_priv->sarea_priv->last_frame++;
+
+       BEGIN_RING(4);
+
+       RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
+       RADEON_WAIT_UNTIL_2D_IDLE();
+
+       ADVANCE_RING();
+}
+
+static void radeon_cp_dispatch_flip(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_sarea *sarea = (struct drm_sarea *) dev_priv->sarea->handle;
+       int offset = (dev_priv->sarea_priv->pfCurrentPage == 1)
+           ? dev_priv->front_offset : dev_priv->back_offset;
+       RING_LOCALS;
+       DRM_DEBUG("pfCurrentPage=%d\n",
+                 dev_priv->sarea_priv->pfCurrentPage);
+
+       /* Do some trivial performance monitoring...
+        */
+       if (dev_priv->do_boxes) {
+               dev_priv->stats.boxes |= RADEON_BOX_FLIP;
+               radeon_cp_performance_boxes(dev_priv);
+       }
+
+       /* Update the frame offsets for both CRTCs
+        */
+       BEGIN_RING(6);
+
+       RADEON_WAIT_UNTIL_3D_IDLE();
+       OUT_RING_REG(RADEON_CRTC_OFFSET,
+                    ((sarea->frame.y * dev_priv->front_pitch +
+                      sarea->frame.x * (dev_priv->color_fmt - 2)) & ~7)
+                    + offset);
+       OUT_RING_REG(RADEON_CRTC2_OFFSET, dev_priv->sarea_priv->crtc2_base
+                    + offset);
+
+       ADVANCE_RING();
+
+       /* Increment the frame counter.  The client-side 3D driver must
+        * throttle the framerate by waiting for this value before
+        * performing the swapbuffer ioctl.
+        */
+       dev_priv->sarea_priv->last_frame++;
+       dev_priv->sarea_priv->pfCurrentPage =
+               1 - dev_priv->sarea_priv->pfCurrentPage;
+
+       BEGIN_RING(2);
+
+       RADEON_FRAME_AGE(dev_priv->sarea_priv->last_frame);
+
+       ADVANCE_RING();
+}
+
+static int bad_prim_vertex_nr(int primitive, int nr)
+{
+       switch (primitive & RADEON_PRIM_TYPE_MASK) {
+       case RADEON_PRIM_TYPE_NONE:
+       case RADEON_PRIM_TYPE_POINT:
+               return nr < 1;
+       case RADEON_PRIM_TYPE_LINE:
+               return (nr & 1) || nr == 0;
+       case RADEON_PRIM_TYPE_LINE_STRIP:
+               return nr < 2;
+       case RADEON_PRIM_TYPE_TRI_LIST:
+       case RADEON_PRIM_TYPE_3VRT_POINT_LIST:
+       case RADEON_PRIM_TYPE_3VRT_LINE_LIST:
+       case RADEON_PRIM_TYPE_RECT_LIST:
+               return nr % 3 || nr == 0;
+       case RADEON_PRIM_TYPE_TRI_FAN:
+       case RADEON_PRIM_TYPE_TRI_STRIP:
+               return nr < 3;
+       default:
+               return 1;
+       }
+}
+
+typedef struct {
+       unsigned int start;
+       unsigned int finish;
+       unsigned int prim;
+       unsigned int numverts;
+       unsigned int offset;
+       unsigned int vc_format;
+} drm_radeon_tcl_prim_t;
+
+static void radeon_cp_dispatch_vertex(struct drm_device * dev,
+                                     struct drm_buf * buf,
+                                     drm_radeon_tcl_prim_t * prim)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int offset = dev_priv->gart_buffers_offset + buf->offset + prim->start;
+       int numverts = (int)prim->numverts;
+       int nbox = sarea_priv->nbox;
+       int i = 0;
+       RING_LOCALS;
+
+       DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
+                 prim->prim,
+                 prim->vc_format, prim->start, prim->finish, prim->numverts);
+
+       if (bad_prim_vertex_nr(prim->prim, prim->numverts)) {
+               DRM_ERROR("bad prim %x numverts %d\n",
+                         prim->prim, prim->numverts);
+               return;
+       }
+
+       do {
+               /* Emit the next cliprect */
+               if (i < nbox) {
+                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
+               }
+
+               /* Emit the vertex buffer rendering commands */
+               BEGIN_RING(5);
+
+               OUT_RING(CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, 3));
+               OUT_RING(offset);
+               OUT_RING(numverts);
+               OUT_RING(prim->vc_format);
+               OUT_RING(prim->prim | RADEON_PRIM_WALK_LIST |
+                        RADEON_COLOR_ORDER_RGBA |
+                        RADEON_VTX_FMT_RADEON_MODE |
+                        (numverts << RADEON_NUM_VERTICES_SHIFT));
+
+               ADVANCE_RING();
+
+               i++;
+       } while (i < nbox);
+}
+
+static void radeon_cp_discard_buffer(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
+       RING_LOCALS;
+
+       buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
+
+       /* Emit the vertex buffer age */
+       BEGIN_RING(2);
+       RADEON_DISPATCH_AGE(buf_priv->age);
+       ADVANCE_RING();
+
+       buf->pending = 1;
+       buf->used = 0;
+}
+
+static void radeon_cp_dispatch_indirect(struct drm_device * dev,
+                                       struct drm_buf * buf, int start, int end)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+       DRM_DEBUG("buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
+
+       if (start != end) {
+               int offset = (dev_priv->gart_buffers_offset
+                             + buf->offset + start);
+               int dwords = (end - start + 3) / sizeof(u32);
+
+               /* Indirect buffer data must be an even number of
+                * dwords, so if we've been given an odd number we must
+                * pad the data with a Type-2 CP packet.
+                */
+               if (dwords & 1) {
+                       u32 *data = (u32 *)
+                           ((char *)dev->agp_buffer_map->handle
+                            + buf->offset + start);
+                       data[dwords++] = RADEON_CP_PACKET2;
+               }
+
+               /* Fire off the indirect buffer */
+               BEGIN_RING(3);
+
+               OUT_RING(CP_PACKET0(RADEON_CP_IB_BASE, 1));
+               OUT_RING(offset);
+               OUT_RING(dwords);
+
+               ADVANCE_RING();
+       }
+}
+
+static void radeon_cp_dispatch_indices(struct drm_device * dev,
+                                      struct drm_buf * elt_buf,
+                                      drm_radeon_tcl_prim_t * prim)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       int offset = dev_priv->gart_buffers_offset + prim->offset;
+       u32 *data;
+       int dwords;
+       int i = 0;
+       int start = prim->start + RADEON_INDEX_PRIM_OFFSET;
+       int count = (prim->finish - start) / sizeof(u16);
+       int nbox = sarea_priv->nbox;
+
+       DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
+                 prim->prim,
+                 prim->vc_format,
+                 prim->start, prim->finish, prim->offset, prim->numverts);
+
+       if (bad_prim_vertex_nr(prim->prim, count)) {
+               DRM_ERROR("bad prim %x count %d\n", prim->prim, count);
+               return;
+       }
+
+       if (start >= prim->finish || (prim->start & 0x7)) {
+               DRM_ERROR("buffer prim %d\n", prim->prim);
+               return;
+       }
+
+       dwords = (prim->finish - prim->start + 3) / sizeof(u32);
+
+       data = (u32 *) ((char *)dev->agp_buffer_map->handle +
+                       elt_buf->offset + prim->start);
+
+       data[0] = CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM, dwords - 2);
+       data[1] = offset;
+       data[2] = prim->numverts;
+       data[3] = prim->vc_format;
+       data[4] = (prim->prim |
+                  RADEON_PRIM_WALK_IND |
+                  RADEON_COLOR_ORDER_RGBA |
+                  RADEON_VTX_FMT_RADEON_MODE |
+                  (count << RADEON_NUM_VERTICES_SHIFT));
+
+       do {
+               if (i < nbox)
+                       radeon_emit_clip_rect(dev_priv, &sarea_priv->boxes[i]);
+
+               radeon_cp_dispatch_indirect(dev, elt_buf,
+                                           prim->start, prim->finish);
+
+               i++;
+       } while (i < nbox);
+
+}
+
+#define RADEON_MAX_TEXTURE_SIZE RADEON_BUFFER_SIZE
+
+static int radeon_cp_dispatch_texture(struct drm_device * dev,
+                                     struct drm_file *file_priv,
+                                     drm_radeon_texture_t * tex,
+                                     drm_radeon_tex_image_t * image)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_buf *buf;
+       u32 format;
+       u32 *buffer;
+       const u8 __user *data;
+       int size, dwords, tex_width, blit_width, spitch;
+       u32 height;
+       int i;
+       u32 texpitch, microtile;
+       u32 offset, byte_offset;
+       RING_LOCALS;
+
+       if (radeon_check_and_fixup_offset(dev_priv, file_priv, &tex->offset)) {
+               DRM_ERROR("Invalid destination offset\n");
+               return -EINVAL;
+       }
+
+       dev_priv->stats.boxes |= RADEON_BOX_TEXTURE_LOAD;
+
+       /* Flush the pixel cache.  This ensures no pixel data gets mixed
+        * up with the texture data from the host data blit, otherwise
+        * part of the texture image may be corrupted.
+        */
+       BEGIN_RING(4);
+       RADEON_FLUSH_CACHE();
+       RADEON_WAIT_UNTIL_IDLE();
+       ADVANCE_RING();
+
+       /* The compiler won't optimize away a division by a variable,
+        * even if the only legal values are powers of two.  Thus, we'll
+        * use a shift instead.
+        */
+       switch (tex->format) {
+       case RADEON_TXFORMAT_ARGB8888:
+       case RADEON_TXFORMAT_RGBA8888:
+               format = RADEON_COLOR_FORMAT_ARGB8888;
+               tex_width = tex->width * 4;
+               blit_width = image->width * 4;
+               break;
+       case RADEON_TXFORMAT_AI88:
+       case RADEON_TXFORMAT_ARGB1555:
+       case RADEON_TXFORMAT_RGB565:
+       case RADEON_TXFORMAT_ARGB4444:
+       case RADEON_TXFORMAT_VYUY422:
+       case RADEON_TXFORMAT_YVYU422:
+               format = RADEON_COLOR_FORMAT_RGB565;
+               tex_width = tex->width * 2;
+               blit_width = image->width * 2;
+               break;
+       case RADEON_TXFORMAT_I8:
+       case RADEON_TXFORMAT_RGB332:
+               format = RADEON_COLOR_FORMAT_CI8;
+               tex_width = tex->width * 1;
+               blit_width = image->width * 1;
+               break;
+       default:
+               DRM_ERROR("invalid texture format %d\n", tex->format);
+               return -EINVAL;
+       }
+       spitch = blit_width >> 6;
+       if (spitch == 0 && image->height > 1)
+               return -EINVAL;
+
+       texpitch = tex->pitch;
+       if ((texpitch << 22) & RADEON_DST_TILE_MICRO) {
+               microtile = 1;
+               if (tex_width < 64) {
+                       texpitch &= ~(RADEON_DST_TILE_MICRO >> 22);
+                       /* we got tiled coordinates, untile them */
+                       image->x *= 2;
+               }
+       } else
+               microtile = 0;
+
+       /* this might fail for zero-sized uploads - are those illegal? */
+       if (!radeon_check_offset(dev_priv, tex->offset + image->height *
+                               blit_width - 1)) {
+               DRM_ERROR("Invalid final destination offset\n");
+               return -EINVAL;
+       }
+
+       DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width, tex->height, blit_width);
+
+       do {
+               DRM_DEBUG("tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
+                         tex->offset >> 10, tex->pitch, tex->format,
+                         image->x, image->y, image->width, image->height);
+
+               /* Make a copy of some parameters in case we have to
+                * update them for a multi-pass texture blit.
+                */
+               height = image->height;
+               data = (const u8 __user *)image->data;
+
+               size = height * blit_width;
+
+               if (size > RADEON_MAX_TEXTURE_SIZE) {
+                       height = RADEON_MAX_TEXTURE_SIZE / blit_width;
+                       size = height * blit_width;
+               } else if (size < 4 && size > 0) {
+                       size = 4;
+               } else if (size == 0) {
+                       return 0;
+               }
+
+               buf = radeon_freelist_get(dev);
+               if (0 && !buf) {
+                       radeon_do_cp_idle(dev_priv);
+                       buf = radeon_freelist_get(dev);
+               }
+               if (!buf) {
+                       DRM_DEBUG("EAGAIN\n");
+                       if (DRM_COPY_TO_USER(tex->image, image, sizeof(*image)))
+                               return -EFAULT;
+                       return -EAGAIN;
+               }
+
+               /* Dispatch the indirect buffer.
+                */
+               buffer =
+                   (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);
+               dwords = size / 4;
+
+#define RADEON_COPY_MT(_buf, _data, _width) \
+       do { \
+               if (DRM_COPY_FROM_USER(_buf, _data, (_width))) {\
+                       DRM_ERROR("EFAULT on pad, %d bytes\n", (_width)); \
+                       return -EFAULT; \
+               } \
+       } while(0)
+
+               if (microtile) {
+                       /* texture micro tiling in use, minimum texture width is thus 16 bytes.
+                          however, we cannot use blitter directly for texture width < 64 bytes,
+                          since minimum tex pitch is 64 bytes and we need this to match
+                          the texture width, otherwise the blitter will tile it wrong.
+                          Thus, tiling manually in this case. Additionally, need to special
+                          case tex height = 1, since our actual image will have height 2
+                          and we need to ensure we don't read beyond the texture size
+                          from user space. */
+                       if (tex->height == 1) {
+                               if (tex_width >= 64 || tex_width <= 16) {
+                                       RADEON_COPY_MT(buffer, data,
+                                               (int)(tex_width * sizeof(u32)));
+                               } else if (tex_width == 32) {
+                                       RADEON_COPY_MT(buffer, data, 16);
+                                       RADEON_COPY_MT(buffer + 8,
+                                                      data + 16, 16);
+                               }
+                       } else if (tex_width >= 64 || tex_width == 16) {
+                               RADEON_COPY_MT(buffer, data,
+                                              (int)(dwords * sizeof(u32)));
+                       } else if (tex_width < 16) {
+                               for (i = 0; i < tex->height; i++) {
+                                       RADEON_COPY_MT(buffer, data, tex_width);
+                                       buffer += 4;
+                                       data += tex_width;
+                               }
+                       } else if (tex_width == 32) {
+                               /* TODO: make sure this works when not fitting in one buffer
+                                  (i.e. 32bytes x 2048...) */
+                               for (i = 0; i < tex->height; i += 2) {
+                                       RADEON_COPY_MT(buffer, data, 16);
+                                       data += 16;
+                                       RADEON_COPY_MT(buffer + 8, data, 16);
+                                       data += 16;
+                                       RADEON_COPY_MT(buffer + 4, data, 16);
+                                       data += 16;
+                                       RADEON_COPY_MT(buffer + 12, data, 16);
+                                       data += 16;
+                                       buffer += 16;
+                               }
+                       }
+               } else {
+                       if (tex_width >= 32) {
+                               /* Texture image width is larger than the minimum, so we
+                                * can upload it directly.
+                                */
+                               RADEON_COPY_MT(buffer, data,
+                                              (int)(dwords * sizeof(u32)));
+                       } else {
+                               /* Texture image width is less than the minimum, so we
+                                * need to pad out each image scanline to the minimum
+                                * width.
+                                */
+                               for (i = 0; i < tex->height; i++) {
+                                       RADEON_COPY_MT(buffer, data, tex_width);
+                                       buffer += 8;
+                                       data += tex_width;
+                               }
+                       }
+               }
+
+#undef RADEON_COPY_MT
+               byte_offset = (image->y & ~2047) * blit_width;
+               buf->file_priv = file_priv;
+               buf->used = size;
+               offset = dev_priv->gart_buffers_offset + buf->offset;
+               BEGIN_RING(9);
+               OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI, 5));
+               OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
+                        RADEON_GMC_DST_PITCH_OFFSET_CNTL |
+                        RADEON_GMC_BRUSH_NONE |
+                        (format << 8) |
+                        RADEON_GMC_SRC_DATATYPE_COLOR |
+                        RADEON_ROP3_S |
+                        RADEON_DP_SRC_SOURCE_MEMORY |
+                        RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
+               OUT_RING((spitch << 22) | (offset >> 10));
+               OUT_RING((texpitch << 22) | ((tex->offset >> 10) + (byte_offset >> 10)));
+               OUT_RING(0);
+               OUT_RING((image->x << 16) | (image->y % 2048));
+               OUT_RING((image->width << 16) | height);
+               RADEON_WAIT_UNTIL_2D_IDLE();
+               ADVANCE_RING();
+               COMMIT_RING();
+
+               radeon_cp_discard_buffer(dev, buf);
+
+               /* Update the input parameters for next time */
+               image->y += height;
+               image->height -= height;
+               image->data = (const u8 __user *)image->data + size;
+       } while (image->height > 0);
+
+       /* Flush the pixel cache after the blit completes.  This ensures
+        * the texture data is written out to memory before rendering
+        * continues.
+        */
+       BEGIN_RING(4);
+       RADEON_FLUSH_CACHE();
+       RADEON_WAIT_UNTIL_2D_IDLE();
+       ADVANCE_RING();
+       COMMIT_RING();
+
+       return 0;
+}
+
+static void radeon_cp_dispatch_stipple(struct drm_device * dev, u32 * stipple)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       int i;
+       RING_LOCALS;
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(35);
+
+       OUT_RING(CP_PACKET0(RADEON_RE_STIPPLE_ADDR, 0));
+       OUT_RING(0x00000000);
+
+       OUT_RING(CP_PACKET0_TABLE(RADEON_RE_STIPPLE_DATA, 31));
+       for (i = 0; i < 32; i++) {
+               OUT_RING(stipple[i]);
+       }
+
+       ADVANCE_RING();
+}
+
+static void radeon_apply_surface_regs(int surf_index,
+                                     drm_radeon_private_t *dev_priv)
+{
+       if (!dev_priv->mmio)
+               return;
+
+       radeon_do_cp_idle(dev_priv);
+
+       RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * surf_index,
+                    dev_priv->surfaces[surf_index].flags);
+       RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + 16 * surf_index,
+                    dev_priv->surfaces[surf_index].lower);
+       RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + 16 * surf_index,
+                    dev_priv->surfaces[surf_index].upper);
+}
+
+/* Allocates a virtual surface
+ * doesn't always allocate a real surface, will stretch an existing
+ * surface when possible.
+ *
+ * Note that refcount can be at most 2, since during a free refcount=3
+ * might mean we have to allocate a new surface which might not always
+ * be available.
+ * For example : we allocate three contigous surfaces ABC. If B is
+ * freed, we suddenly need two surfaces to store A and C, which might
+ * not always be available.
+ */
+static int alloc_surface(drm_radeon_surface_alloc_t *new,
+                        drm_radeon_private_t *dev_priv,
+                        struct drm_file *file_priv)
+{
+       struct radeon_virt_surface *s;
+       int i;
+       int virt_surface_index;
+       uint32_t new_upper, new_lower;
+
+       new_lower = new->address;
+       new_upper = new_lower + new->size - 1;
+
+       /* sanity check */
+       if ((new_lower >= new_upper) || (new->flags == 0) || (new->size == 0) ||
+           ((new_upper & RADEON_SURF_ADDRESS_FIXED_MASK) !=
+            RADEON_SURF_ADDRESS_FIXED_MASK)
+           || ((new_lower & RADEON_SURF_ADDRESS_FIXED_MASK) != 0))
+               return -1;
+
+       /* make sure there is no overlap with existing surfaces */
+       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
+               if ((dev_priv->surfaces[i].refcount != 0) &&
+                   (((new_lower >= dev_priv->surfaces[i].lower) &&
+                     (new_lower < dev_priv->surfaces[i].upper)) ||
+                    ((new_lower < dev_priv->surfaces[i].lower) &&
+                     (new_upper > dev_priv->surfaces[i].lower)))) {
+                       return -1;
+               }
+       }
+
+       /* find a virtual surface */
+       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++)
+               if (dev_priv->virt_surfaces[i].file_priv == 0)
+                       break;
+       if (i == 2 * RADEON_MAX_SURFACES) {
+               return -1;
+       }
+       virt_surface_index = i;
+
+       /* try to reuse an existing surface */
+       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
+               /* extend before */
+               if ((dev_priv->surfaces[i].refcount == 1) &&
+                   (new->flags == dev_priv->surfaces[i].flags) &&
+                   (new_upper + 1 == dev_priv->surfaces[i].lower)) {
+                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
+                       s->surface_index = i;
+                       s->lower = new_lower;
+                       s->upper = new_upper;
+                       s->flags = new->flags;
+                       s->file_priv = file_priv;
+                       dev_priv->surfaces[i].refcount++;
+                       dev_priv->surfaces[i].lower = s->lower;
+                       radeon_apply_surface_regs(s->surface_index, dev_priv);
+                       return virt_surface_index;
+               }
+
+               /* extend after */
+               if ((dev_priv->surfaces[i].refcount == 1) &&
+                   (new->flags == dev_priv->surfaces[i].flags) &&
+                   (new_lower == dev_priv->surfaces[i].upper + 1)) {
+                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
+                       s->surface_index = i;
+                       s->lower = new_lower;
+                       s->upper = new_upper;
+                       s->flags = new->flags;
+                       s->file_priv = file_priv;
+                       dev_priv->surfaces[i].refcount++;
+                       dev_priv->surfaces[i].upper = s->upper;
+                       radeon_apply_surface_regs(s->surface_index, dev_priv);
+                       return virt_surface_index;
+               }
+       }
+
+       /* okay, we need a new one */
+       for (i = 0; i < RADEON_MAX_SURFACES; i++) {
+               if (dev_priv->surfaces[i].refcount == 0) {
+                       s = &(dev_priv->virt_surfaces[virt_surface_index]);
+                       s->surface_index = i;
+                       s->lower = new_lower;
+                       s->upper = new_upper;
+                       s->flags = new->flags;
+                       s->file_priv = file_priv;
+                       dev_priv->surfaces[i].refcount = 1;
+                       dev_priv->surfaces[i].lower = s->lower;
+                       dev_priv->surfaces[i].upper = s->upper;
+                       dev_priv->surfaces[i].flags = s->flags;
+                       radeon_apply_surface_regs(s->surface_index, dev_priv);
+                       return virt_surface_index;
+               }
+       }
+
+       /* we didn't find anything */
+       return -1;
+}
+
+static int free_surface(struct drm_file *file_priv,
+                       drm_radeon_private_t * dev_priv,
+                       int lower)
+{
+       struct radeon_virt_surface *s;
+       int i;
+       /* find the virtual surface */
+       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
+               s = &(dev_priv->virt_surfaces[i]);
+               if (s->file_priv) {
+                       if ((lower == s->lower) && (file_priv == s->file_priv))
+                       {
+                               if (dev_priv->surfaces[s->surface_index].
+                                   lower == s->lower)
+                                       dev_priv->surfaces[s->surface_index].
+                                           lower = s->upper;
+
+                               if (dev_priv->surfaces[s->surface_index].
+                                   upper == s->upper)
+                                       dev_priv->surfaces[s->surface_index].
+                                           upper = s->lower;
+
+                               dev_priv->surfaces[s->surface_index].refcount--;
+                               if (dev_priv->surfaces[s->surface_index].
+                                   refcount == 0)
+                                       dev_priv->surfaces[s->surface_index].
+                                           flags = 0;
+                               s->file_priv = NULL;
+                               radeon_apply_surface_regs(s->surface_index,
+                                                         dev_priv);
+                               return 0;
+                       }
+               }
+       }
+       return 1;
+}
+
+static void radeon_surfaces_release(struct drm_file *file_priv,
+                                   drm_radeon_private_t * dev_priv)
+{
+       int i;
+       for (i = 0; i < 2 * RADEON_MAX_SURFACES; i++) {
+               if (dev_priv->virt_surfaces[i].file_priv == file_priv)
+                       free_surface(file_priv, dev_priv,
+                                    dev_priv->virt_surfaces[i].lower);
+       }
+}
+
+/* ================================================================
+ * IOCTL functions
+ */
+static int radeon_surface_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_surface_alloc_t *alloc = data;
+
+       if (alloc_surface(alloc, dev_priv, file_priv) == -1)
+               return -EINVAL;
+       else
+               return 0;
+}
+
+static int radeon_surface_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_surface_free_t *memfree = data;
+
+       if (free_surface(file_priv, dev_priv, memfree->address))
+               return -EINVAL;
+       else
+               return 0;
+}
+
+static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       drm_radeon_clear_t *clear = data;
+       drm_radeon_clear_rect_t depth_boxes[RADEON_NR_SAREA_CLIPRECTS];
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
+
+       if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
+                              sarea_priv->nbox * sizeof(depth_boxes[0])))
+               return -EFAULT;
+
+       radeon_cp_dispatch_clear(dev, clear, depth_boxes);
+
+       COMMIT_RING();
+       return 0;
+}
+
+/* Not sure why this isn't set all the time:
+ */
+static int radeon_do_init_pageflip(struct drm_device * dev)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       DRM_DEBUG("\n");
+
+       BEGIN_RING(6);
+       RADEON_WAIT_UNTIL_3D_IDLE();
+       OUT_RING(CP_PACKET0(RADEON_CRTC_OFFSET_CNTL, 0));
+       OUT_RING(RADEON_READ(RADEON_CRTC_OFFSET_CNTL) |
+                RADEON_CRTC_OFFSET_FLIP_CNTL);
+       OUT_RING(CP_PACKET0(RADEON_CRTC2_OFFSET_CNTL, 0));
+       OUT_RING(RADEON_READ(RADEON_CRTC2_OFFSET_CNTL) |
+                RADEON_CRTC_OFFSET_FLIP_CNTL);
+       ADVANCE_RING();
+
+       dev_priv->page_flipping = 1;
+
+       if (dev_priv->sarea_priv->pfCurrentPage != 1)
+               dev_priv->sarea_priv->pfCurrentPage = 0;
+
+       return 0;
+}
+
+/* Swapping and flipping are different operations, need different ioctls.
+ * They can & should be intermixed to support multiple 3d windows.
+ */
+static int radeon_cp_flip(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (!dev_priv->page_flipping)
+               radeon_do_init_pageflip(dev);
+
+       radeon_cp_dispatch_flip(dev);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
+               sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
+
+       radeon_cp_dispatch_swap(dev);
+       dev_priv->sarea_priv->ctx_owner = 0;
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_radeon_vertex_t *vertex = data;
+       drm_radeon_tcl_prim_t prim;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
+                 DRM_CURRENTPID, vertex->idx, vertex->count, vertex->discard);
+
+       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         vertex->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+       if (vertex->prim < 0 || vertex->prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
+               DRM_ERROR("buffer prim %d\n", vertex->prim);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf = dma->buflist[vertex->idx];
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
+               return -EINVAL;
+       }
+
+       /* Build up a prim_t record:
+        */
+       if (vertex->count) {
+               buf->used = vertex->count;      /* not used? */
+
+               if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
+                       if (radeon_emit_state(dev_priv, file_priv,
+                                             &sarea_priv->context_state,
+                                             sarea_priv->tex_state,
+                                             sarea_priv->dirty)) {
+                               DRM_ERROR("radeon_emit_state failed\n");
+                               return -EINVAL;
+                       }
+
+                       sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
+                                              RADEON_UPLOAD_TEX1IMAGES |
+                                              RADEON_UPLOAD_TEX2IMAGES |
+                                              RADEON_REQUIRE_QUIESCENCE);
+               }
+
+               prim.start = 0;
+               prim.finish = vertex->count;    /* unused */
+               prim.prim = vertex->prim;
+               prim.numverts = vertex->count;
+               prim.vc_format = dev_priv->sarea_priv->vc_format;
+
+               radeon_cp_dispatch_vertex(dev, buf, &prim);
+       }
+
+       if (vertex->discard) {
+               radeon_cp_discard_buffer(dev, buf);
+       }
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_radeon_indices_t *elts = data;
+       drm_radeon_tcl_prim_t prim;
+       int count;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("pid=%d index=%d start=%d end=%d discard=%d\n",
+                 DRM_CURRENTPID, elts->idx, elts->start, elts->end,
+                 elts->discard);
+
+       if (elts->idx < 0 || elts->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         elts->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+       if (elts->prim < 0 || elts->prim > RADEON_PRIM_TYPE_3VRT_LINE_LIST) {
+               DRM_ERROR("buffer prim %d\n", elts->prim);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf = dma->buflist[elts->idx];
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", elts->idx);
+               return -EINVAL;
+       }
+
+       count = (elts->end - elts->start) / sizeof(u16);
+       elts->start -= RADEON_INDEX_PRIM_OFFSET;
+
+       if (elts->start & 0x7) {
+               DRM_ERROR("misaligned buffer 0x%x\n", elts->start);
+               return -EINVAL;
+       }
+       if (elts->start < buf->used) {
+               DRM_ERROR("no header 0x%x - 0x%x\n", elts->start, buf->used);
+               return -EINVAL;
+       }
+
+       buf->used = elts->end;
+
+       if (sarea_priv->dirty & ~RADEON_UPLOAD_CLIPRECTS) {
+               if (radeon_emit_state(dev_priv, file_priv,
+                                     &sarea_priv->context_state,
+                                     sarea_priv->tex_state,
+                                     sarea_priv->dirty)) {
+                       DRM_ERROR("radeon_emit_state failed\n");
+                       return -EINVAL;
+               }
+
+               sarea_priv->dirty &= ~(RADEON_UPLOAD_TEX0IMAGES |
+                                      RADEON_UPLOAD_TEX1IMAGES |
+                                      RADEON_UPLOAD_TEX2IMAGES |
+                                      RADEON_REQUIRE_QUIESCENCE);
+       }
+
+       /* Build up a prim_t record:
+        */
+       prim.start = elts->start;
+       prim.finish = elts->end;
+       prim.prim = elts->prim;
+       prim.offset = 0;        /* offset from start of dma buffers */
+       prim.numverts = RADEON_MAX_VB_VERTS;    /* duh */
+       prim.vc_format = dev_priv->sarea_priv->vc_format;
+
+       radeon_cp_dispatch_indices(dev, buf, &prim);
+       if (elts->discard) {
+               radeon_cp_discard_buffer(dev, buf);
+       }
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_texture(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_texture_t *tex = data;
+       drm_radeon_tex_image_t image;
+       int ret;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (tex->image == NULL) {
+               DRM_ERROR("null texture image!\n");
+               return -EINVAL;
+       }
+
+       if (DRM_COPY_FROM_USER(&image,
+                              (drm_radeon_tex_image_t __user *) tex->image,
+                              sizeof(image)))
+               return -EFAULT;
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       ret = radeon_cp_dispatch_texture(dev, file_priv, tex, &image);
+
+       return ret;
+}
+
+static int radeon_cp_stipple(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_stipple_t *stipple = data;
+       u32 mask[32];
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (DRM_COPY_FROM_USER(&mask, stipple->mask, 32 * sizeof(u32)))
+               return -EFAULT;
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+
+       radeon_cp_dispatch_stipple(dev, mask);
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_indirect(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_radeon_indirect_t *indirect = data;
+       RING_LOCALS;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
+                 indirect->idx, indirect->start, indirect->end,
+                 indirect->discard);
+
+       if (indirect->idx < 0 || indirect->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         indirect->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+
+       buf = dma->buflist[indirect->idx];
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", indirect->idx);
+               return -EINVAL;
+       }
+
+       if (indirect->start < buf->used) {
+               DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
+                         indirect->start, buf->used);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf->used = indirect->end;
+
+       /* Wait for the 3D stream to idle before the indirect buffer
+        * containing 2D acceleration commands is processed.
+        */
+       BEGIN_RING(2);
+
+       RADEON_WAIT_UNTIL_3D_IDLE();
+
+       ADVANCE_RING();
+
+       /* Dispatch the indirect buffer full of commands from the
+        * X server.  This is insecure and is thus only available to
+        * privileged clients.
+        */
+       radeon_cp_dispatch_indirect(dev, buf, indirect->start, indirect->end);
+       if (indirect->discard) {
+               radeon_cp_discard_buffer(dev, buf);
+       }
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_cp_vertex2(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_radeon_vertex2_t *vertex = data;
+       int i;
+       unsigned char laststate;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("pid=%d index=%d discard=%d\n",
+                 DRM_CURRENTPID, vertex->idx, vertex->discard);
+
+       if (vertex->idx < 0 || vertex->idx >= dma->buf_count) {
+               DRM_ERROR("buffer index %d (of %d max)\n",
+                         vertex->idx, dma->buf_count - 1);
+               return -EINVAL;
+       }
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       buf = dma->buflist[vertex->idx];
+
+       if (buf->file_priv != file_priv) {
+               DRM_ERROR("process %d using buffer owned by %p\n",
+                         DRM_CURRENTPID, buf->file_priv);
+               return -EINVAL;
+       }
+
+       if (buf->pending) {
+               DRM_ERROR("sending pending buffer %d\n", vertex->idx);
+               return -EINVAL;
+       }
+
+       if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
+               return -EINVAL;
+
+       for (laststate = 0xff, i = 0; i < vertex->nr_prims; i++) {
+               drm_radeon_prim_t prim;
+               drm_radeon_tcl_prim_t tclprim;
+
+               if (DRM_COPY_FROM_USER(&prim, &vertex->prim[i], sizeof(prim)))
+                       return -EFAULT;
+
+               if (prim.stateidx != laststate) {
+                       drm_radeon_state_t state;
+
+                       if (DRM_COPY_FROM_USER(&state,
+                                              &vertex->state[prim.stateidx],
+                                              sizeof(state)))
+                               return -EFAULT;
+
+                       if (radeon_emit_state2(dev_priv, file_priv, &state)) {
+                               DRM_ERROR("radeon_emit_state2 failed\n");
+                               return -EINVAL;
+                       }
+
+                       laststate = prim.stateidx;
+               }
+
+               tclprim.start = prim.start;
+               tclprim.finish = prim.finish;
+               tclprim.prim = prim.prim;
+               tclprim.vc_format = prim.vc_format;
+
+               if (prim.prim & RADEON_PRIM_WALK_IND) {
+                       tclprim.offset = prim.numverts * 64;
+                       tclprim.numverts = RADEON_MAX_VB_VERTS; /* duh */
+
+                       radeon_cp_dispatch_indices(dev, buf, &tclprim);
+               } else {
+                       tclprim.numverts = prim.numverts;
+                       tclprim.offset = 0;     /* not used */
+
+                       radeon_cp_dispatch_vertex(dev, buf, &tclprim);
+               }
+
+               if (sarea_priv->nbox == 1)
+                       sarea_priv->nbox = 0;
+       }
+
+       if (vertex->discard) {
+               radeon_cp_discard_buffer(dev, buf);
+       }
+
+       COMMIT_RING();
+       return 0;
+}
+
+static int radeon_emit_packets(drm_radeon_private_t * dev_priv,
+                              struct drm_file *file_priv,
+                              drm_radeon_cmd_header_t header,
+                              drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       int id = (int)header.packet.packet_id;
+       int sz, reg;
+       int *data = (int *)cmdbuf->buf;
+       RING_LOCALS;
+
+       if (id >= RADEON_MAX_STATE_PACKETS)
+               return -EINVAL;
+
+       sz = packet[id].len;
+       reg = packet[id].start;
+
+       if (sz * sizeof(int) > cmdbuf->bufsz) {
+               DRM_ERROR("Packet size provided larger than data provided\n");
+               return -EINVAL;
+       }
+
+       if (radeon_check_and_fixup_packets(dev_priv, file_priv, id, data)) {
+               DRM_ERROR("Packet verification failed\n");
+               return -EINVAL;
+       }
+
+       BEGIN_RING(sz + 1);
+       OUT_RING(CP_PACKET0(reg, (sz - 1)));
+       OUT_RING_TABLE(data, sz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * sizeof(int);
+       cmdbuf->bufsz -= sz * sizeof(int);
+       return 0;
+}
+
+static __inline__ int radeon_emit_scalars(drm_radeon_private_t *dev_priv,
+                                         drm_radeon_cmd_header_t header,
+                                         drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       int sz = header.scalars.count;
+       int start = header.scalars.offset;
+       int stride = header.scalars.stride;
+       RING_LOCALS;
+
+       BEGIN_RING(3 + sz);
+       OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
+       OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
+       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
+       OUT_RING_TABLE(cmdbuf->buf, sz);
+       ADVANCE_RING();
+       cmdbuf->buf += sz * sizeof(int);
+       cmdbuf->bufsz -= sz * sizeof(int);
+       return 0;
+}
+
+/* God this is ugly
+ */
+static __inline__ int radeon_emit_scalars2(drm_radeon_private_t *dev_priv,
+                                          drm_radeon_cmd_header_t header,
+                                          drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       int sz = header.scalars.count;
+       int start = ((unsigned int)header.scalars.offset) + 0x100;
+       int stride = header.scalars.stride;
+       RING_LOCALS;
+
+       BEGIN_RING(3 + sz);
+       OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG, 0));
+       OUT_RING(start | (stride << RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT));
+       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG, sz - 1));
+       OUT_RING_TABLE(cmdbuf->buf, sz);
+       ADVANCE_RING();
+       cmdbuf->buf += sz * sizeof(int);
+       cmdbuf->bufsz -= sz * sizeof(int);
+       return 0;
+}
+
+static __inline__ int radeon_emit_vectors(drm_radeon_private_t *dev_priv,
+                                         drm_radeon_cmd_header_t header,
+                                         drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       int sz = header.vectors.count;
+       int start = header.vectors.offset;
+       int stride = header.vectors.stride;
+       RING_LOCALS;
+
+       BEGIN_RING(5 + sz);
+       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
+       OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
+       OUT_RING(start | (stride << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
+       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
+       OUT_RING_TABLE(cmdbuf->buf, sz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * sizeof(int);
+       cmdbuf->bufsz -= sz * sizeof(int);
+       return 0;
+}
+
+static __inline__ int radeon_emit_veclinear(drm_radeon_private_t *dev_priv,
+                                         drm_radeon_cmd_header_t header,
+                                         drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       int sz = header.veclinear.count * 4;
+       int start = header.veclinear.addr_lo | (header.veclinear.addr_hi << 8);
+       RING_LOCALS;
+
+        if (!sz)
+                return 0;
+        if (sz * 4 > cmdbuf->bufsz)
+                return -EINVAL;
+
+       BEGIN_RING(5 + sz);
+       OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH, 0);
+       OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG, 0));
+       OUT_RING(start | (1 << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT));
+       OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG, (sz - 1)));
+       OUT_RING_TABLE(cmdbuf->buf, sz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += sz * sizeof(int);
+       cmdbuf->bufsz -= sz * sizeof(int);
+       return 0;
+}
+
+static int radeon_emit_packet3(struct drm_device * dev,
+                              struct drm_file *file_priv,
+                              drm_radeon_kcmd_buffer_t *cmdbuf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       unsigned int cmdsz;
+       int ret;
+       RING_LOCALS;
+
+       DRM_DEBUG("\n");
+
+       if ((ret = radeon_check_and_fixup_packet3(dev_priv, file_priv,
+                                                 cmdbuf, &cmdsz))) {
+               DRM_ERROR("Packet verification failed\n");
+               return ret;
+       }
+
+       BEGIN_RING(cmdsz);
+       OUT_RING_TABLE(cmdbuf->buf, cmdsz);
+       ADVANCE_RING();
+
+       cmdbuf->buf += cmdsz * 4;
+       cmdbuf->bufsz -= cmdsz * 4;
+       return 0;
+}
+
+static int radeon_emit_packet3_cliprect(struct drm_device *dev,
+                                       struct drm_file *file_priv,
+                                       drm_radeon_kcmd_buffer_t *cmdbuf,
+                                       int orig_nbox)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_clip_rect box;
+       unsigned int cmdsz;
+       int ret;
+       struct drm_clip_rect __user *boxes = cmdbuf->boxes;
+       int i = 0;
+       RING_LOCALS;
+
+       DRM_DEBUG("\n");
+
+       if ((ret = radeon_check_and_fixup_packet3(dev_priv, file_priv,
+                                                 cmdbuf, &cmdsz))) {
+               DRM_ERROR("Packet verification failed\n");
+               return ret;
+       }
+
+       if (!orig_nbox)
+               goto out;
+
+       do {
+               if (i < cmdbuf->nbox) {
+                       if (DRM_COPY_FROM_USER(&box, &boxes[i], sizeof(box)))
+                               return -EFAULT;
+                       /* FIXME The second and subsequent times round
+                        * this loop, send a WAIT_UNTIL_3D_IDLE before
+                        * calling emit_clip_rect(). This fixes a
+                        * lockup on fast machines when sending
+                        * several cliprects with a cmdbuf, as when
+                        * waving a 2D window over a 3D
+                        * window. Something in the commands from user
+                        * space seems to hang the card when they're
+                        * sent several times in a row. That would be
+                        * the correct place to fix it but this works
+                        * around it until I can figure that out - Tim
+                        * Smith */
+                       if (i) {
+                               BEGIN_RING(2);
+                               RADEON_WAIT_UNTIL_3D_IDLE();
+                               ADVANCE_RING();
+                       }
+                       radeon_emit_clip_rect(dev_priv, &box);
+               }
+
+               BEGIN_RING(cmdsz);
+               OUT_RING_TABLE(cmdbuf->buf, cmdsz);
+               ADVANCE_RING();
+
+       } while (++i < cmdbuf->nbox);
+       if (cmdbuf->nbox == 1)
+               cmdbuf->nbox = 0;
+
+      out:
+       cmdbuf->buf += cmdsz * 4;
+       cmdbuf->bufsz -= cmdsz * 4;
+       return 0;
+}
+
+static int radeon_emit_wait(struct drm_device * dev, int flags)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       RING_LOCALS;
+
+       DRM_DEBUG("%x\n", flags);
+       switch (flags) {
+       case RADEON_WAIT_2D:
+               BEGIN_RING(2);
+               RADEON_WAIT_UNTIL_2D_IDLE();
+               ADVANCE_RING();
+               break;
+       case RADEON_WAIT_3D:
+               BEGIN_RING(2);
+               RADEON_WAIT_UNTIL_3D_IDLE();
+               ADVANCE_RING();
+               break;
+       case RADEON_WAIT_2D | RADEON_WAIT_3D:
+               BEGIN_RING(2);
+               RADEON_WAIT_UNTIL_IDLE();
+               ADVANCE_RING();
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int radeon_cp_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf = NULL;
+       int idx;
+       drm_radeon_kcmd_buffer_t *cmdbuf = data;
+       drm_radeon_cmd_header_t header;
+       int orig_nbox, orig_bufsz;
+       char *kbuf = NULL;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       RING_SPACE_TEST_WITH_RETURN(dev_priv);
+       VB_AGE_TEST_WITH_RETURN(dev_priv);
+
+       if (cmdbuf->bufsz > 64 * 1024 || cmdbuf->bufsz < 0) {
+               return -EINVAL;
+       }
+
+       /* Allocate an in-kernel area and copy in the cmdbuf.  Do this to avoid
+        * races between checking values and using those values in other code,
+        * and simply to avoid a lot of function calls to copy in data.
+        */
+       orig_bufsz = cmdbuf->bufsz;
+       if (orig_bufsz != 0) {
+               kbuf = drm_alloc(cmdbuf->bufsz, DRM_MEM_DRIVER);
+               if (kbuf == NULL)
+                       return -ENOMEM;
+               if (DRM_COPY_FROM_USER(kbuf, (void __user *)cmdbuf->buf,
+                                      cmdbuf->bufsz)) {
+                       drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
+                       return -EFAULT;
+               }
+               cmdbuf->buf = kbuf;
+       }
+
+       orig_nbox = cmdbuf->nbox;
+
+       if (dev_priv->microcode_version == UCODE_R300) {
+               int temp;
+               temp = r300_do_cp_cmdbuf(dev, file_priv, cmdbuf);
+
+               if (orig_bufsz != 0)
+                       drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
+
+               return temp;
+       }
+
+       /* microcode_version != r300 */
+       while (cmdbuf->bufsz >= sizeof(header)) {
+
+               header.i = *(int *)cmdbuf->buf;
+               cmdbuf->buf += sizeof(header);
+               cmdbuf->bufsz -= sizeof(header);
+
+               switch (header.header.cmd_type) {
+               case RADEON_CMD_PACKET:
+                       DRM_DEBUG("RADEON_CMD_PACKET\n");
+                       if (radeon_emit_packets
+                           (dev_priv, file_priv, header, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_packets failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_SCALARS:
+                       DRM_DEBUG("RADEON_CMD_SCALARS\n");
+                       if (radeon_emit_scalars(dev_priv, header, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_scalars failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_VECTORS:
+                       DRM_DEBUG("RADEON_CMD_VECTORS\n");
+                       if (radeon_emit_vectors(dev_priv, header, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_vectors failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_DMA_DISCARD:
+                       DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
+                       idx = header.dma.buf_idx;
+                       if (idx < 0 || idx >= dma->buf_count) {
+                               DRM_ERROR("buffer index %d (of %d max)\n",
+                                         idx, dma->buf_count - 1);
+                               goto err;
+                       }
+
+                       buf = dma->buflist[idx];
+                       if (buf->file_priv != file_priv || buf->pending) {
+                               DRM_ERROR("bad buffer %p %p %d\n",
+                                         buf->file_priv, file_priv,
+                                         buf->pending);
+                               goto err;
+                       }
+
+                       radeon_cp_discard_buffer(dev, buf);
+                       break;
+
+               case RADEON_CMD_PACKET3:
+                       DRM_DEBUG("RADEON_CMD_PACKET3\n");
+                       if (radeon_emit_packet3(dev, file_priv, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_packet3 failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_PACKET3_CLIP:
+                       DRM_DEBUG("RADEON_CMD_PACKET3_CLIP\n");
+                       if (radeon_emit_packet3_cliprect
+                           (dev, file_priv, cmdbuf, orig_nbox)) {
+                               DRM_ERROR("radeon_emit_packet3_clip failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_SCALARS2:
+                       DRM_DEBUG("RADEON_CMD_SCALARS2\n");
+                       if (radeon_emit_scalars2(dev_priv, header, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_scalars2 failed\n");
+                               goto err;
+                       }
+                       break;
+
+               case RADEON_CMD_WAIT:
+                       DRM_DEBUG("RADEON_CMD_WAIT\n");
+                       if (radeon_emit_wait(dev, header.wait.flags)) {
+                               DRM_ERROR("radeon_emit_wait failed\n");
+                               goto err;
+                       }
+                       break;
+               case RADEON_CMD_VECLINEAR:
+                       DRM_DEBUG("RADEON_CMD_VECLINEAR\n");
+                       if (radeon_emit_veclinear(dev_priv, header, cmdbuf)) {
+                               DRM_ERROR("radeon_emit_veclinear failed\n");
+                               goto err;
+                       }
+                       break;
+
+               default:
+                       DRM_ERROR("bad cmd_type %d at %p\n",
+                                 header.header.cmd_type,
+                                 cmdbuf->buf - sizeof(header));
+                       goto err;
+               }
+       }
+
+       if (orig_bufsz != 0)
+               drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
+
+       DRM_DEBUG("DONE\n");
+       COMMIT_RING();
+       return 0;
+
+      err:
+       if (orig_bufsz != 0)
+               drm_free(kbuf, orig_bufsz, DRM_MEM_DRIVER);
+       return -EINVAL;
+}
+
+static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_getparam_t *param = data;
+       int value;
+
+       DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
+
+       switch (param->param) {
+       case RADEON_PARAM_GART_BUFFER_OFFSET:
+               value = dev_priv->gart_buffers_offset;
+               break;
+       case RADEON_PARAM_LAST_FRAME:
+               dev_priv->stats.last_frame_reads++;
+               value = GET_SCRATCH(0);
+               break;
+       case RADEON_PARAM_LAST_DISPATCH:
+               value = GET_SCRATCH(1);
+               break;
+       case RADEON_PARAM_LAST_CLEAR:
+               dev_priv->stats.last_clear_reads++;
+               value = GET_SCRATCH(2);
+               break;
+       case RADEON_PARAM_IRQ_NR:
+               value = dev->irq;
+               break;
+       case RADEON_PARAM_GART_BASE:
+               value = dev_priv->gart_vm_start;
+               break;
+       case RADEON_PARAM_REGISTER_HANDLE:
+               value = dev_priv->mmio->offset;
+               break;
+       case RADEON_PARAM_STATUS_HANDLE:
+               value = dev_priv->ring_rptr_offset;
+               break;
+#if BITS_PER_LONG == 32
+               /*
+                * This ioctl() doesn't work on 64-bit platforms because hw_lock is a
+                * pointer which can't fit into an int-sized variable.  According to
+                * Michel Dänzer, the ioctl() is only used on embedded platforms, so
+                * not supporting it shouldn't be a problem.  If the same functionality
+                * is needed on 64-bit platforms, a new ioctl() would have to be added,
+                * so backwards-compatibility for the embedded platforms can be
+                * maintained.  --davidm 4-Feb-2004.
+                */
+       case RADEON_PARAM_SAREA_HANDLE:
+               /* The lock is the first dword in the sarea. */
+               value = (long)dev->lock.hw_lock;
+               break;
+#endif
+       case RADEON_PARAM_GART_TEX_HANDLE:
+               value = dev_priv->gart_textures_offset;
+               break;
+       case RADEON_PARAM_SCRATCH_OFFSET:
+               if (!dev_priv->writeback_works)
+                       return -EINVAL;
+               value = RADEON_SCRATCH_REG_OFFSET;
+               break;
+       case RADEON_PARAM_CARD_TYPE:
+               if (dev_priv->flags & RADEON_IS_PCIE)
+                       value = RADEON_CARD_PCIE;
+               else if (dev_priv->flags & RADEON_IS_AGP)
+                       value = RADEON_CARD_AGP;
+               else
+                       value = RADEON_CARD_PCI;
+               break;
+       case RADEON_PARAM_VBLANK_CRTC:
+               value = radeon_vblank_crtc_get(dev);
+               break;
+       case RADEON_PARAM_FB_LOCATION:
+               value = radeon_read_fb_location(dev_priv);
+               break;
+       case RADEON_PARAM_NUM_GB_PIPES:
+               value = dev_priv->num_gb_pipes;
+               break;
+       default:
+               DRM_DEBUG("Invalid parameter %d\n", param->param);
+               return -EINVAL;
+       }
+
+       if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
+               DRM_ERROR("copy_to_user\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
+static int radeon_cp_setparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       drm_radeon_setparam_t *sp = data;
+       struct drm_radeon_driver_file_fields *radeon_priv;
+
+       switch (sp->param) {
+       case RADEON_SETPARAM_FB_LOCATION:
+               radeon_priv = file_priv->driver_priv;
+               radeon_priv->radeon_fb_delta = dev_priv->fb_location -
+                   sp->value;
+               break;
+       case RADEON_SETPARAM_SWITCH_TILING:
+               if (sp->value == 0) {
+                       DRM_DEBUG("color tiling disabled\n");
+                       dev_priv->front_pitch_offset &= ~RADEON_DST_TILE_MACRO;
+                       dev_priv->back_pitch_offset &= ~RADEON_DST_TILE_MACRO;
+                       dev_priv->sarea_priv->tiling_enabled = 0;
+               } else if (sp->value == 1) {
+                       DRM_DEBUG("color tiling enabled\n");
+                       dev_priv->front_pitch_offset |= RADEON_DST_TILE_MACRO;
+                       dev_priv->back_pitch_offset |= RADEON_DST_TILE_MACRO;
+                       dev_priv->sarea_priv->tiling_enabled = 1;
+               }
+               break;
+       case RADEON_SETPARAM_PCIGART_LOCATION:
+               dev_priv->pcigart_offset = sp->value;
+               dev_priv->pcigart_offset_set = 1;
+               break;
+       case RADEON_SETPARAM_NEW_MEMMAP:
+               dev_priv->new_memmap = sp->value;
+               break;
+       case RADEON_SETPARAM_PCIGART_TABLE_SIZE:
+               dev_priv->gart_info.table_size = sp->value;
+               if (dev_priv->gart_info.table_size < RADEON_PCIGART_TABLE_SIZE)
+                       dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
+               break;
+       case RADEON_SETPARAM_VBLANK_CRTC:
+               return radeon_vblank_crtc_set(dev, sp->value);
+               break;
+       default:
+               DRM_DEBUG("Invalid parameter %d\n", sp->param);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/* When a client dies:
+ *    - Check for and clean up flipped page state
+ *    - Free any alloced GART memory.
+ *    - Free any alloced radeon surfaces.
+ *
+ * DRM infrastructure takes care of reclaiming dma buffers.
+ */
+void radeon_driver_preclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       if (dev->dev_private) {
+               drm_radeon_private_t *dev_priv = dev->dev_private;
+               dev_priv->page_flipping = 0;
+               radeon_mem_release(file_priv, dev_priv->gart_heap);
+               radeon_mem_release(file_priv, dev_priv->fb_heap);
+               radeon_surfaces_release(file_priv, dev_priv);
+       }
+}
+
+void radeon_driver_lastclose(struct drm_device *dev)
+{
+       if (dev->dev_private) {
+               drm_radeon_private_t *dev_priv = dev->dev_private;
+
+               if (dev_priv->sarea_priv &&
+                   dev_priv->sarea_priv->pfCurrentPage != 0)
+                       radeon_cp_dispatch_flip(dev);
+       }
+
+       radeon_do_release(dev);
+}
+
+int radeon_driver_open(struct drm_device *dev, struct drm_file *file_priv)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       struct drm_radeon_driver_file_fields *radeon_priv;
+
+       DRM_DEBUG("\n");
+       radeon_priv =
+           (struct drm_radeon_driver_file_fields *)
+           drm_alloc(sizeof(*radeon_priv), DRM_MEM_FILES);
+
+       if (!radeon_priv)
+               return -ENOMEM;
+
+       file_priv->driver_priv = radeon_priv;
+
+       if (dev_priv)
+               radeon_priv->radeon_fb_delta = dev_priv->fb_location;
+       else
+               radeon_priv->radeon_fb_delta = 0;
+       return 0;
+}
+
+void radeon_driver_postclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       struct drm_radeon_driver_file_fields *radeon_priv =
+           file_priv->driver_priv;
+
+       drm_free(radeon_priv, sizeof(*radeon_priv), DRM_MEM_FILES);
+}
+
+struct drm_ioctl_desc radeon_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_RADEON_CP_INIT, radeon_cp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_CP_START, radeon_cp_start, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_CP_STOP, radeon_cp_stop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_CP_RESET, radeon_cp_reset, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_CP_IDLE, radeon_cp_idle, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_CP_RESUME, radeon_cp_resume, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_RESET, radeon_engine_reset, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_FULLSCREEN, radeon_fullscreen, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_SWAP, radeon_cp_swap, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_CLEAR, radeon_cp_clear, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_VERTEX, radeon_cp_vertex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_INDICES, radeon_cp_indices, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_TEXTURE, radeon_cp_texture, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_STIPPLE, radeon_cp_stipple, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_INDIRECT, radeon_cp_indirect, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_VERTEX2, radeon_cp_vertex2, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_CMDBUF, radeon_cp_cmdbuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_GETPARAM, radeon_cp_getparam, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_FLIP, radeon_cp_flip, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_ALLOC, radeon_mem_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_FREE, radeon_mem_free, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_INIT_HEAP, radeon_mem_init_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_RADEON_IRQ_EMIT, radeon_irq_emit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_IRQ_WAIT, radeon_irq_wait, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_SETPARAM, radeon_cp_setparam, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_SURF_ALLOC, radeon_surface_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_RADEON_SURF_FREE, radeon_surface_free, DRM_AUTH)
+};
+
+int radeon_max_ioctl = DRM_ARRAY_SIZE(radeon_ioctls);
diff --git a/drivers/gpu/drm/savage/Makefile b/drivers/gpu/drm/savage/Makefile
new file mode 100644 (file)
index 0000000..d8f84ac
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y = -Iinclude/drm
+savage-y := savage_drv.o savage_bci.o savage_state.o
+
+obj-$(CONFIG_DRM_SAVAGE)+= savage.o
+
diff --git a/drivers/gpu/drm/savage/savage_bci.c b/drivers/gpu/drm/savage/savage_bci.c
new file mode 100644 (file)
index 0000000..d465b2f
--- /dev/null
@@ -0,0 +1,1095 @@
+/* savage_bci.c -- BCI support for Savage
+ *
+ * Copyright 2004  Felix Kuehling
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "drmP.h"
+#include "savage_drm.h"
+#include "savage_drv.h"
+
+/* Need a long timeout for shadow status updates can take a while
+ * and so can waiting for events when the queue is full. */
+#define SAVAGE_DEFAULT_USEC_TIMEOUT    1000000 /* 1s */
+#define SAVAGE_EVENT_USEC_TIMEOUT      5000000 /* 5s */
+#define SAVAGE_FREELIST_DEBUG          0
+
+static int savage_do_cleanup_bci(struct drm_device *dev);
+
+static int
+savage_bci_wait_fifo_shadow(drm_savage_private_t * dev_priv, unsigned int n)
+{
+       uint32_t mask = dev_priv->status_used_mask;
+       uint32_t threshold = dev_priv->bci_threshold_hi;
+       uint32_t status;
+       int i;
+
+#if SAVAGE_BCI_DEBUG
+       if (n > dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - threshold)
+               DRM_ERROR("Trying to emit %d words "
+                         "(more than guaranteed space in COB)\n", n);
+#endif
+
+       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
+               DRM_MEMORYBARRIER();
+               status = dev_priv->status_ptr[0];
+               if ((status & mask) < threshold)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if SAVAGE_BCI_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x, threshold=0x%08x\n", status, threshold);
+#endif
+       return -EBUSY;
+}
+
+static int
+savage_bci_wait_fifo_s3d(drm_savage_private_t * dev_priv, unsigned int n)
+{
+       uint32_t maxUsed = dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - n;
+       uint32_t status;
+       int i;
+
+       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
+               status = SAVAGE_READ(SAVAGE_STATUS_WORD0);
+               if ((status & SAVAGE_FIFO_USED_MASK_S3D) <= maxUsed)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if SAVAGE_BCI_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x\n", status);
+#endif
+       return -EBUSY;
+}
+
+static int
+savage_bci_wait_fifo_s4(drm_savage_private_t * dev_priv, unsigned int n)
+{
+       uint32_t maxUsed = dev_priv->cob_size + SAVAGE_BCI_FIFO_SIZE - n;
+       uint32_t status;
+       int i;
+
+       for (i = 0; i < SAVAGE_DEFAULT_USEC_TIMEOUT; i++) {
+               status = SAVAGE_READ(SAVAGE_ALT_STATUS_WORD0);
+               if ((status & SAVAGE_FIFO_USED_MASK_S4) <= maxUsed)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if SAVAGE_BCI_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x\n", status);
+#endif
+       return -EBUSY;
+}
+
+/*
+ * Waiting for events.
+ *
+ * The BIOSresets the event tag to 0 on mode changes. Therefore we
+ * never emit 0 to the event tag. If we find a 0 event tag we know the
+ * BIOS stomped on it and return success assuming that the BIOS waited
+ * for engine idle.
+ *
+ * Note: if the Xserver uses the event tag it has to follow the same
+ * rule. Otherwise there may be glitches every 2^16 events.
+ */
+static int
+savage_bci_wait_event_shadow(drm_savage_private_t * dev_priv, uint16_t e)
+{
+       uint32_t status;
+       int i;
+
+       for (i = 0; i < SAVAGE_EVENT_USEC_TIMEOUT; i++) {
+               DRM_MEMORYBARRIER();
+               status = dev_priv->status_ptr[1];
+               if ((((status & 0xffff) - e) & 0xffff) <= 0x7fff ||
+                   (status & 0xffff) == 0)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if SAVAGE_BCI_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x, e=0x%04x\n", status, e);
+#endif
+
+       return -EBUSY;
+}
+
+static int
+savage_bci_wait_event_reg(drm_savage_private_t * dev_priv, uint16_t e)
+{
+       uint32_t status;
+       int i;
+
+       for (i = 0; i < SAVAGE_EVENT_USEC_TIMEOUT; i++) {
+               status = SAVAGE_READ(SAVAGE_STATUS_WORD1);
+               if ((((status & 0xffff) - e) & 0xffff) <= 0x7fff ||
+                   (status & 0xffff) == 0)
+                       return 0;
+               DRM_UDELAY(1);
+       }
+
+#if SAVAGE_BCI_DEBUG
+       DRM_ERROR("failed!\n");
+       DRM_INFO("   status=0x%08x, e=0x%04x\n", status, e);
+#endif
+
+       return -EBUSY;
+}
+
+uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
+                              unsigned int flags)
+{
+       uint16_t count;
+       BCI_LOCALS;
+
+       if (dev_priv->status_ptr) {
+               /* coordinate with Xserver */
+               count = dev_priv->status_ptr[1023];
+               if (count < dev_priv->event_counter)
+                       dev_priv->event_wrap++;
+       } else {
+               count = dev_priv->event_counter;
+       }
+       count = (count + 1) & 0xffff;
+       if (count == 0) {
+               count++;        /* See the comment above savage_wait_event_*. */
+               dev_priv->event_wrap++;
+       }
+       dev_priv->event_counter = count;
+       if (dev_priv->status_ptr)
+               dev_priv->status_ptr[1023] = (uint32_t) count;
+
+       if ((flags & (SAVAGE_WAIT_2D | SAVAGE_WAIT_3D))) {
+               unsigned int wait_cmd = BCI_CMD_WAIT;
+               if ((flags & SAVAGE_WAIT_2D))
+                       wait_cmd |= BCI_CMD_WAIT_2D;
+               if ((flags & SAVAGE_WAIT_3D))
+                       wait_cmd |= BCI_CMD_WAIT_3D;
+               BEGIN_BCI(2);
+               BCI_WRITE(wait_cmd);
+       } else {
+               BEGIN_BCI(1);
+       }
+       BCI_WRITE(BCI_CMD_UPDATE_EVENT_TAG | (uint32_t) count);
+
+       return count;
+}
+
+/*
+ * Freelist management
+ */
+static int savage_freelist_init(struct drm_device * dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *buf;
+       drm_savage_buf_priv_t *entry;
+       int i;
+       DRM_DEBUG("count=%d\n", dma->buf_count);
+
+       dev_priv->head.next = &dev_priv->tail;
+       dev_priv->head.prev = NULL;
+       dev_priv->head.buf = NULL;
+
+       dev_priv->tail.next = NULL;
+       dev_priv->tail.prev = &dev_priv->head;
+       dev_priv->tail.buf = NULL;
+
+       for (i = 0; i < dma->buf_count; i++) {
+               buf = dma->buflist[i];
+               entry = buf->dev_private;
+
+               SET_AGE(&entry->age, 0, 0);
+               entry->buf = buf;
+
+               entry->next = dev_priv->head.next;
+               entry->prev = &dev_priv->head;
+               dev_priv->head.next->prev = entry;
+               dev_priv->head.next = entry;
+       }
+
+       return 0;
+}
+
+static struct drm_buf *savage_freelist_get(struct drm_device * dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       drm_savage_buf_priv_t *tail = dev_priv->tail.prev;
+       uint16_t event;
+       unsigned int wrap;
+       DRM_DEBUG("\n");
+
+       UPDATE_EVENT_COUNTER();
+       if (dev_priv->status_ptr)
+               event = dev_priv->status_ptr[1] & 0xffff;
+       else
+               event = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
+       wrap = dev_priv->event_wrap;
+       if (event > dev_priv->event_counter)
+               wrap--;         /* hardware hasn't passed the last wrap yet */
+
+       DRM_DEBUG("   tail=0x%04x %d\n", tail->age.event, tail->age.wrap);
+       DRM_DEBUG("   head=0x%04x %d\n", event, wrap);
+
+       if (tail->buf && (TEST_AGE(&tail->age, event, wrap) || event == 0)) {
+               drm_savage_buf_priv_t *next = tail->next;
+               drm_savage_buf_priv_t *prev = tail->prev;
+               prev->next = next;
+               next->prev = prev;
+               tail->next = tail->prev = NULL;
+               return tail->buf;
+       }
+
+       DRM_DEBUG("returning NULL, tail->buf=%p!\n", tail->buf);
+       return NULL;
+}
+
+void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       drm_savage_buf_priv_t *entry = buf->dev_private, *prev, *next;
+
+       DRM_DEBUG("age=0x%04x wrap=%d\n", entry->age.event, entry->age.wrap);
+
+       if (entry->next != NULL || entry->prev != NULL) {
+               DRM_ERROR("entry already on freelist.\n");
+               return;
+       }
+
+       prev = &dev_priv->head;
+       next = prev->next;
+       prev->next = entry;
+       next->prev = entry;
+       entry->prev = prev;
+       entry->next = next;
+}
+
+/*
+ * Command DMA
+ */
+static int savage_dma_init(drm_savage_private_t * dev_priv)
+{
+       unsigned int i;
+
+       dev_priv->nr_dma_pages = dev_priv->cmd_dma->size /
+           (SAVAGE_DMA_PAGE_SIZE * 4);
+       dev_priv->dma_pages = drm_alloc(sizeof(drm_savage_dma_page_t) *
+                                       dev_priv->nr_dma_pages, DRM_MEM_DRIVER);
+       if (dev_priv->dma_pages == NULL)
+               return -ENOMEM;
+
+       for (i = 0; i < dev_priv->nr_dma_pages; ++i) {
+               SET_AGE(&dev_priv->dma_pages[i].age, 0, 0);
+               dev_priv->dma_pages[i].used = 0;
+               dev_priv->dma_pages[i].flushed = 0;
+       }
+       SET_AGE(&dev_priv->last_dma_age, 0, 0);
+
+       dev_priv->first_dma_page = 0;
+       dev_priv->current_dma_page = 0;
+
+       return 0;
+}
+
+void savage_dma_reset(drm_savage_private_t * dev_priv)
+{
+       uint16_t event;
+       unsigned int wrap, i;
+       event = savage_bci_emit_event(dev_priv, 0);
+       wrap = dev_priv->event_wrap;
+       for (i = 0; i < dev_priv->nr_dma_pages; ++i) {
+               SET_AGE(&dev_priv->dma_pages[i].age, event, wrap);
+               dev_priv->dma_pages[i].used = 0;
+               dev_priv->dma_pages[i].flushed = 0;
+       }
+       SET_AGE(&dev_priv->last_dma_age, event, wrap);
+       dev_priv->first_dma_page = dev_priv->current_dma_page = 0;
+}
+
+void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page)
+{
+       uint16_t event;
+       unsigned int wrap;
+
+       /* Faked DMA buffer pages don't age. */
+       if (dev_priv->cmd_dma == &dev_priv->fake_dma)
+               return;
+
+       UPDATE_EVENT_COUNTER();
+       if (dev_priv->status_ptr)
+               event = dev_priv->status_ptr[1] & 0xffff;
+       else
+               event = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
+       wrap = dev_priv->event_wrap;
+       if (event > dev_priv->event_counter)
+               wrap--;         /* hardware hasn't passed the last wrap yet */
+
+       if (dev_priv->dma_pages[page].age.wrap > wrap ||
+           (dev_priv->dma_pages[page].age.wrap == wrap &&
+            dev_priv->dma_pages[page].age.event > event)) {
+               if (dev_priv->wait_evnt(dev_priv,
+                                       dev_priv->dma_pages[page].age.event)
+                   < 0)
+                       DRM_ERROR("wait_evnt failed!\n");
+       }
+}
+
+uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv, unsigned int n)
+{
+       unsigned int cur = dev_priv->current_dma_page;
+       unsigned int rest = SAVAGE_DMA_PAGE_SIZE -
+           dev_priv->dma_pages[cur].used;
+       unsigned int nr_pages = (n - rest + SAVAGE_DMA_PAGE_SIZE - 1) /
+           SAVAGE_DMA_PAGE_SIZE;
+       uint32_t *dma_ptr;
+       unsigned int i;
+
+       DRM_DEBUG("cur=%u, cur->used=%u, n=%u, rest=%u, nr_pages=%u\n",
+                 cur, dev_priv->dma_pages[cur].used, n, rest, nr_pages);
+
+       if (cur + nr_pages < dev_priv->nr_dma_pages) {
+               dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
+                   cur * SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used;
+               if (n < rest)
+                       rest = n;
+               dev_priv->dma_pages[cur].used += rest;
+               n -= rest;
+               cur++;
+       } else {
+               dev_priv->dma_flush(dev_priv);
+               nr_pages =
+                   (n + SAVAGE_DMA_PAGE_SIZE - 1) / SAVAGE_DMA_PAGE_SIZE;
+               for (i = cur; i < dev_priv->nr_dma_pages; ++i) {
+                       dev_priv->dma_pages[i].age = dev_priv->last_dma_age;
+                       dev_priv->dma_pages[i].used = 0;
+                       dev_priv->dma_pages[i].flushed = 0;
+               }
+               dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle;
+               dev_priv->first_dma_page = cur = 0;
+       }
+       for (i = cur; nr_pages > 0; ++i, --nr_pages) {
+#if SAVAGE_DMA_DEBUG
+               if (dev_priv->dma_pages[i].used) {
+                       DRM_ERROR("unflushed page %u: used=%u\n",
+                                 i, dev_priv->dma_pages[i].used);
+               }
+#endif
+               if (n > SAVAGE_DMA_PAGE_SIZE)
+                       dev_priv->dma_pages[i].used = SAVAGE_DMA_PAGE_SIZE;
+               else
+                       dev_priv->dma_pages[i].used = n;
+               n -= SAVAGE_DMA_PAGE_SIZE;
+       }
+       dev_priv->current_dma_page = --i;
+
+       DRM_DEBUG("cur=%u, cur->used=%u, n=%u\n",
+                 i, dev_priv->dma_pages[i].used, n);
+
+       savage_dma_wait(dev_priv, dev_priv->current_dma_page);
+
+       return dma_ptr;
+}
+
+static void savage_dma_flush(drm_savage_private_t * dev_priv)
+{
+       unsigned int first = dev_priv->first_dma_page;
+       unsigned int cur = dev_priv->current_dma_page;
+       uint16_t event;
+       unsigned int wrap, pad, align, len, i;
+       unsigned long phys_addr;
+       BCI_LOCALS;
+
+       if (first == cur &&
+           dev_priv->dma_pages[cur].used == dev_priv->dma_pages[cur].flushed)
+               return;
+
+       /* pad length to multiples of 2 entries
+        * align start of next DMA block to multiles of 8 entries */
+       pad = -dev_priv->dma_pages[cur].used & 1;
+       align = -(dev_priv->dma_pages[cur].used + pad) & 7;
+
+       DRM_DEBUG("first=%u, cur=%u, first->flushed=%u, cur->used=%u, "
+                 "pad=%u, align=%u\n",
+                 first, cur, dev_priv->dma_pages[first].flushed,
+                 dev_priv->dma_pages[cur].used, pad, align);
+
+       /* pad with noops */
+       if (pad) {
+               uint32_t *dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
+                   cur * SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used;
+               dev_priv->dma_pages[cur].used += pad;
+               while (pad != 0) {
+                       *dma_ptr++ = BCI_CMD_WAIT;
+                       pad--;
+               }
+       }
+
+       DRM_MEMORYBARRIER();
+
+       /* do flush ... */
+       phys_addr = dev_priv->cmd_dma->offset +
+           (first * SAVAGE_DMA_PAGE_SIZE +
+            dev_priv->dma_pages[first].flushed) * 4;
+       len = (cur - first) * SAVAGE_DMA_PAGE_SIZE +
+           dev_priv->dma_pages[cur].used - dev_priv->dma_pages[first].flushed;
+
+       DRM_DEBUG("phys_addr=%lx, len=%u\n",
+                 phys_addr | dev_priv->dma_type, len);
+
+       BEGIN_BCI(3);
+       BCI_SET_REGISTERS(SAVAGE_DMABUFADDR, 1);
+       BCI_WRITE(phys_addr | dev_priv->dma_type);
+       BCI_DMA(len);
+
+       /* fix alignment of the start of the next block */
+       dev_priv->dma_pages[cur].used += align;
+
+       /* age DMA pages */
+       event = savage_bci_emit_event(dev_priv, 0);
+       wrap = dev_priv->event_wrap;
+       for (i = first; i < cur; ++i) {
+               SET_AGE(&dev_priv->dma_pages[i].age, event, wrap);
+               dev_priv->dma_pages[i].used = 0;
+               dev_priv->dma_pages[i].flushed = 0;
+       }
+       /* age the current page only when it's full */
+       if (dev_priv->dma_pages[cur].used == SAVAGE_DMA_PAGE_SIZE) {
+               SET_AGE(&dev_priv->dma_pages[cur].age, event, wrap);
+               dev_priv->dma_pages[cur].used = 0;
+               dev_priv->dma_pages[cur].flushed = 0;
+               /* advance to next page */
+               cur++;
+               if (cur == dev_priv->nr_dma_pages)
+                       cur = 0;
+               dev_priv->first_dma_page = dev_priv->current_dma_page = cur;
+       } else {
+               dev_priv->first_dma_page = cur;
+               dev_priv->dma_pages[cur].flushed = dev_priv->dma_pages[i].used;
+       }
+       SET_AGE(&dev_priv->last_dma_age, event, wrap);
+
+       DRM_DEBUG("first=cur=%u, cur->used=%u, cur->flushed=%u\n", cur,
+                 dev_priv->dma_pages[cur].used,
+                 dev_priv->dma_pages[cur].flushed);
+}
+
+static void savage_fake_dma_flush(drm_savage_private_t * dev_priv)
+{
+       unsigned int i, j;
+       BCI_LOCALS;
+
+       if (dev_priv->first_dma_page == dev_priv->current_dma_page &&
+           dev_priv->dma_pages[dev_priv->current_dma_page].used == 0)
+               return;
+
+       DRM_DEBUG("first=%u, cur=%u, cur->used=%u\n",
+                 dev_priv->first_dma_page, dev_priv->current_dma_page,
+                 dev_priv->dma_pages[dev_priv->current_dma_page].used);
+
+       for (i = dev_priv->first_dma_page;
+            i <= dev_priv->current_dma_page && dev_priv->dma_pages[i].used;
+            ++i) {
+               uint32_t *dma_ptr = (uint32_t *) dev_priv->cmd_dma->handle +
+                   i * SAVAGE_DMA_PAGE_SIZE;
+#if SAVAGE_DMA_DEBUG
+               /* Sanity check: all pages except the last one must be full. */
+               if (i < dev_priv->current_dma_page &&
+                   dev_priv->dma_pages[i].used != SAVAGE_DMA_PAGE_SIZE) {
+                       DRM_ERROR("partial DMA page %u: used=%u",
+                                 i, dev_priv->dma_pages[i].used);
+               }
+#endif
+               BEGIN_BCI(dev_priv->dma_pages[i].used);
+               for (j = 0; j < dev_priv->dma_pages[i].used; ++j) {
+                       BCI_WRITE(dma_ptr[j]);
+               }
+               dev_priv->dma_pages[i].used = 0;
+       }
+
+       /* reset to first page */
+       dev_priv->first_dma_page = dev_priv->current_dma_page = 0;
+}
+
+int savage_driver_load(struct drm_device *dev, unsigned long chipset)
+{
+       drm_savage_private_t *dev_priv;
+
+       dev_priv = drm_alloc(sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       memset(dev_priv, 0, sizeof(drm_savage_private_t));
+       dev->dev_private = (void *)dev_priv;
+
+       dev_priv->chipset = (enum savage_family)chipset;
+
+       return 0;
+}
+
+
+/*
+ * Initalize mappings. On Savage4 and SavageIX the alignment
+ * and size of the aperture is not suitable for automatic MTRR setup
+ * in drm_addmap. Therefore we add them manually before the maps are
+ * initialized, and tear them down on last close.
+ */
+int savage_driver_firstopen(struct drm_device *dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       unsigned long mmio_base, fb_base, fb_size, aperture_base;
+       /* fb_rsrc and aper_rsrc aren't really used currently, but still exist
+        * in case we decide we need information on the BAR for BSD in the
+        * future.
+        */
+       unsigned int fb_rsrc, aper_rsrc;
+       int ret = 0;
+
+       dev_priv->mtrr[0].handle = -1;
+       dev_priv->mtrr[1].handle = -1;
+       dev_priv->mtrr[2].handle = -1;
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               fb_rsrc = 0;
+               fb_base = drm_get_resource_start(dev, 0);
+               fb_size = SAVAGE_FB_SIZE_S3;
+               mmio_base = fb_base + SAVAGE_FB_SIZE_S3;
+               aper_rsrc = 0;
+               aperture_base = fb_base + SAVAGE_APERTURE_OFFSET;
+               /* this should always be true */
+               if (drm_get_resource_len(dev, 0) == 0x08000000) {
+                       /* Don't make MMIO write-cobining! We need 3
+                        * MTRRs. */
+                       dev_priv->mtrr[0].base = fb_base;
+                       dev_priv->mtrr[0].size = 0x01000000;
+                       dev_priv->mtrr[0].handle =
+                           drm_mtrr_add(dev_priv->mtrr[0].base,
+                                        dev_priv->mtrr[0].size, DRM_MTRR_WC);
+                       dev_priv->mtrr[1].base = fb_base + 0x02000000;
+                       dev_priv->mtrr[1].size = 0x02000000;
+                       dev_priv->mtrr[1].handle =
+                           drm_mtrr_add(dev_priv->mtrr[1].base,
+                                        dev_priv->mtrr[1].size, DRM_MTRR_WC);
+                       dev_priv->mtrr[2].base = fb_base + 0x04000000;
+                       dev_priv->mtrr[2].size = 0x04000000;
+                       dev_priv->mtrr[2].handle =
+                           drm_mtrr_add(dev_priv->mtrr[2].base,
+                                        dev_priv->mtrr[2].size, DRM_MTRR_WC);
+               } else {
+                       DRM_ERROR("strange pci_resource_len %08lx\n",
+                                 drm_get_resource_len(dev, 0));
+               }
+       } else if (dev_priv->chipset != S3_SUPERSAVAGE &&
+                  dev_priv->chipset != S3_SAVAGE2000) {
+               mmio_base = drm_get_resource_start(dev, 0);
+               fb_rsrc = 1;
+               fb_base = drm_get_resource_start(dev, 1);
+               fb_size = SAVAGE_FB_SIZE_S4;
+               aper_rsrc = 1;
+               aperture_base = fb_base + SAVAGE_APERTURE_OFFSET;
+               /* this should always be true */
+               if (drm_get_resource_len(dev, 1) == 0x08000000) {
+                       /* Can use one MTRR to cover both fb and
+                        * aperture. */
+                       dev_priv->mtrr[0].base = fb_base;
+                       dev_priv->mtrr[0].size = 0x08000000;
+                       dev_priv->mtrr[0].handle =
+                           drm_mtrr_add(dev_priv->mtrr[0].base,
+                                        dev_priv->mtrr[0].size, DRM_MTRR_WC);
+               } else {
+                       DRM_ERROR("strange pci_resource_len %08lx\n",
+                                 drm_get_resource_len(dev, 1));
+               }
+       } else {
+               mmio_base = drm_get_resource_start(dev, 0);
+               fb_rsrc = 1;
+               fb_base = drm_get_resource_start(dev, 1);
+               fb_size = drm_get_resource_len(dev, 1);
+               aper_rsrc = 2;
+               aperture_base = drm_get_resource_start(dev, 2);
+               /* Automatic MTRR setup will do the right thing. */
+       }
+
+       ret = drm_addmap(dev, mmio_base, SAVAGE_MMIO_SIZE, _DRM_REGISTERS,
+                        _DRM_READ_ONLY, &dev_priv->mmio);
+       if (ret)
+               return ret;
+
+       ret = drm_addmap(dev, fb_base, fb_size, _DRM_FRAME_BUFFER,
+                        _DRM_WRITE_COMBINING, &dev_priv->fb);
+       if (ret)
+               return ret;
+
+       ret = drm_addmap(dev, aperture_base, SAVAGE_APERTURE_SIZE,
+                        _DRM_FRAME_BUFFER, _DRM_WRITE_COMBINING,
+                        &dev_priv->aperture);
+       if (ret)
+               return ret;
+
+       return ret;
+}
+
+/*
+ * Delete MTRRs and free device-private data.
+ */
+void savage_driver_lastclose(struct drm_device *dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       int i;
+
+       for (i = 0; i < 3; ++i)
+               if (dev_priv->mtrr[i].handle >= 0)
+                       drm_mtrr_del(dev_priv->mtrr[i].handle,
+                                dev_priv->mtrr[i].base,
+                                dev_priv->mtrr[i].size, DRM_MTRR_WC);
+}
+
+int savage_driver_unload(struct drm_device *dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+
+       drm_free(dev_priv, sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
+
+       return 0;
+}
+
+static int savage_do_init_bci(struct drm_device * dev, drm_savage_init_t * init)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+
+       if (init->fb_bpp != 16 && init->fb_bpp != 32) {
+               DRM_ERROR("invalid frame buffer bpp %d!\n", init->fb_bpp);
+               return -EINVAL;
+       }
+       if (init->depth_bpp != 16 && init->depth_bpp != 32) {
+               DRM_ERROR("invalid depth buffer bpp %d!\n", init->fb_bpp);
+               return -EINVAL;
+       }
+       if (init->dma_type != SAVAGE_DMA_AGP &&
+           init->dma_type != SAVAGE_DMA_PCI) {
+               DRM_ERROR("invalid dma memory type %d!\n", init->dma_type);
+               return -EINVAL;
+       }
+
+       dev_priv->cob_size = init->cob_size;
+       dev_priv->bci_threshold_lo = init->bci_threshold_lo;
+       dev_priv->bci_threshold_hi = init->bci_threshold_hi;
+       dev_priv->dma_type = init->dma_type;
+
+       dev_priv->fb_bpp = init->fb_bpp;
+       dev_priv->front_offset = init->front_offset;
+       dev_priv->front_pitch = init->front_pitch;
+       dev_priv->back_offset = init->back_offset;
+       dev_priv->back_pitch = init->back_pitch;
+       dev_priv->depth_bpp = init->depth_bpp;
+       dev_priv->depth_offset = init->depth_offset;
+       dev_priv->depth_pitch = init->depth_pitch;
+
+       dev_priv->texture_offset = init->texture_offset;
+       dev_priv->texture_size = init->texture_size;
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("could not find sarea!\n");
+               savage_do_cleanup_bci(dev);
+               return -EINVAL;
+       }
+       if (init->status_offset != 0) {
+               dev_priv->status = drm_core_findmap(dev, init->status_offset);
+               if (!dev_priv->status) {
+                       DRM_ERROR("could not find shadow status region!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+       } else {
+               dev_priv->status = NULL;
+       }
+       if (dev_priv->dma_type == SAVAGE_DMA_AGP && init->buffers_offset) {
+               dev->agp_buffer_token = init->buffers_offset;
+               dev->agp_buffer_map = drm_core_findmap(dev,
+                                                      init->buffers_offset);
+               if (!dev->agp_buffer_map) {
+                       DRM_ERROR("could not find DMA buffer region!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+               drm_core_ioremap(dev->agp_buffer_map, dev);
+               if (!dev->agp_buffer_map) {
+                       DRM_ERROR("failed to ioremap DMA buffer region!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -ENOMEM;
+               }
+       }
+       if (init->agp_textures_offset) {
+               dev_priv->agp_textures =
+                   drm_core_findmap(dev, init->agp_textures_offset);
+               if (!dev_priv->agp_textures) {
+                       DRM_ERROR("could not find agp texture region!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+       } else {
+               dev_priv->agp_textures = NULL;
+       }
+
+       if (init->cmd_dma_offset) {
+               if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+                       DRM_ERROR("command DMA not supported on "
+                                 "Savage3D/MX/IX.\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+               if (dev->dma && dev->dma->buflist) {
+                       DRM_ERROR("command and vertex DMA not supported "
+                                 "at the same time.\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+               dev_priv->cmd_dma = drm_core_findmap(dev, init->cmd_dma_offset);
+               if (!dev_priv->cmd_dma) {
+                       DRM_ERROR("could not find command DMA region!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+               if (dev_priv->dma_type == SAVAGE_DMA_AGP) {
+                       if (dev_priv->cmd_dma->type != _DRM_AGP) {
+                               DRM_ERROR("AGP command DMA region is not a "
+                                         "_DRM_AGP map!\n");
+                               savage_do_cleanup_bci(dev);
+                               return -EINVAL;
+                       }
+                       drm_core_ioremap(dev_priv->cmd_dma, dev);
+                       if (!dev_priv->cmd_dma->handle) {
+                               DRM_ERROR("failed to ioremap command "
+                                         "DMA region!\n");
+                               savage_do_cleanup_bci(dev);
+                               return -ENOMEM;
+                       }
+               } else if (dev_priv->cmd_dma->type != _DRM_CONSISTENT) {
+                       DRM_ERROR("PCI command DMA region is not a "
+                                 "_DRM_CONSISTENT map!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -EINVAL;
+               }
+       } else {
+               dev_priv->cmd_dma = NULL;
+       }
+
+       dev_priv->dma_flush = savage_dma_flush;
+       if (!dev_priv->cmd_dma) {
+               DRM_DEBUG("falling back to faked command DMA.\n");
+               dev_priv->fake_dma.offset = 0;
+               dev_priv->fake_dma.size = SAVAGE_FAKE_DMA_SIZE;
+               dev_priv->fake_dma.type = _DRM_SHM;
+               dev_priv->fake_dma.handle = drm_alloc(SAVAGE_FAKE_DMA_SIZE,
+                                                     DRM_MEM_DRIVER);
+               if (!dev_priv->fake_dma.handle) {
+                       DRM_ERROR("could not allocate faked DMA buffer!\n");
+                       savage_do_cleanup_bci(dev);
+                       return -ENOMEM;
+               }
+               dev_priv->cmd_dma = &dev_priv->fake_dma;
+               dev_priv->dma_flush = savage_fake_dma_flush;
+       }
+
+       dev_priv->sarea_priv =
+           (drm_savage_sarea_t *) ((uint8_t *) dev_priv->sarea->handle +
+                                   init->sarea_priv_offset);
+
+       /* setup bitmap descriptors */
+       {
+               unsigned int color_tile_format;
+               unsigned int depth_tile_format;
+               unsigned int front_stride, back_stride, depth_stride;
+               if (dev_priv->chipset <= S3_SAVAGE4) {
+                       color_tile_format = dev_priv->fb_bpp == 16 ?
+                           SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP;
+                       depth_tile_format = dev_priv->depth_bpp == 16 ?
+                           SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP;
+               } else {
+                       color_tile_format = SAVAGE_BD_TILE_DEST;
+                       depth_tile_format = SAVAGE_BD_TILE_DEST;
+               }
+               front_stride = dev_priv->front_pitch / (dev_priv->fb_bpp / 8);
+               back_stride = dev_priv->back_pitch / (dev_priv->fb_bpp / 8);
+               depth_stride =
+                   dev_priv->depth_pitch / (dev_priv->depth_bpp / 8);
+
+               dev_priv->front_bd = front_stride | SAVAGE_BD_BW_DISABLE |
+                   (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) |
+                   (color_tile_format << SAVAGE_BD_TILE_SHIFT);
+
+               dev_priv->back_bd = back_stride | SAVAGE_BD_BW_DISABLE |
+                   (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) |
+                   (color_tile_format << SAVAGE_BD_TILE_SHIFT);
+
+               dev_priv->depth_bd = depth_stride | SAVAGE_BD_BW_DISABLE |
+                   (dev_priv->depth_bpp << SAVAGE_BD_BPP_SHIFT) |
+                   (depth_tile_format << SAVAGE_BD_TILE_SHIFT);
+       }
+
+       /* setup status and bci ptr */
+       dev_priv->event_counter = 0;
+       dev_priv->event_wrap = 0;
+       dev_priv->bci_ptr = (volatile uint32_t *)
+           ((uint8_t *) dev_priv->mmio->handle + SAVAGE_BCI_OFFSET);
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               dev_priv->status_used_mask = SAVAGE_FIFO_USED_MASK_S3D;
+       } else {
+               dev_priv->status_used_mask = SAVAGE_FIFO_USED_MASK_S4;
+       }
+       if (dev_priv->status != NULL) {
+               dev_priv->status_ptr =
+                   (volatile uint32_t *)dev_priv->status->handle;
+               dev_priv->wait_fifo = savage_bci_wait_fifo_shadow;
+               dev_priv->wait_evnt = savage_bci_wait_event_shadow;
+               dev_priv->status_ptr[1023] = dev_priv->event_counter;
+       } else {
+               dev_priv->status_ptr = NULL;
+               if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+                       dev_priv->wait_fifo = savage_bci_wait_fifo_s3d;
+               } else {
+                       dev_priv->wait_fifo = savage_bci_wait_fifo_s4;
+               }
+               dev_priv->wait_evnt = savage_bci_wait_event_reg;
+       }
+
+       /* cliprect functions */
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset))
+               dev_priv->emit_clip_rect = savage_emit_clip_rect_s3d;
+       else
+               dev_priv->emit_clip_rect = savage_emit_clip_rect_s4;
+
+       if (savage_freelist_init(dev) < 0) {
+               DRM_ERROR("could not initialize freelist\n");
+               savage_do_cleanup_bci(dev);
+               return -ENOMEM;
+       }
+
+       if (savage_dma_init(dev_priv) < 0) {
+               DRM_ERROR("could not initialize command DMA\n");
+               savage_do_cleanup_bci(dev);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static int savage_do_cleanup_bci(struct drm_device * dev)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+
+       if (dev_priv->cmd_dma == &dev_priv->fake_dma) {
+               if (dev_priv->fake_dma.handle)
+                       drm_free(dev_priv->fake_dma.handle,
+                                SAVAGE_FAKE_DMA_SIZE, DRM_MEM_DRIVER);
+       } else if (dev_priv->cmd_dma && dev_priv->cmd_dma->handle &&
+                  dev_priv->cmd_dma->type == _DRM_AGP &&
+                  dev_priv->dma_type == SAVAGE_DMA_AGP)
+               drm_core_ioremapfree(dev_priv->cmd_dma, dev);
+
+       if (dev_priv->dma_type == SAVAGE_DMA_AGP &&
+           dev->agp_buffer_map && dev->agp_buffer_map->handle) {
+               drm_core_ioremapfree(dev->agp_buffer_map, dev);
+               /* make sure the next instance (which may be running
+                * in PCI mode) doesn't try to use an old
+                * agp_buffer_map. */
+               dev->agp_buffer_map = NULL;
+       }
+
+       if (dev_priv->dma_pages)
+               drm_free(dev_priv->dma_pages,
+                        sizeof(drm_savage_dma_page_t) * dev_priv->nr_dma_pages,
+                        DRM_MEM_DRIVER);
+
+       return 0;
+}
+
+static int savage_bci_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_savage_init_t *init = data;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       switch (init->func) {
+       case SAVAGE_INIT_BCI:
+               return savage_do_init_bci(dev, init);
+       case SAVAGE_CLEANUP_BCI:
+               return savage_do_cleanup_bci(dev);
+       }
+
+       return -EINVAL;
+}
+
+static int savage_bci_event_emit(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       drm_savage_event_emit_t *event = data;
+
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       event->count = savage_bci_emit_event(dev_priv, event->flags);
+       event->count |= dev_priv->event_wrap << 16;
+
+       return 0;
+}
+
+static int savage_bci_event_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       drm_savage_event_wait_t *event = data;
+       unsigned int event_e, hw_e;
+       unsigned int event_w, hw_w;
+
+       DRM_DEBUG("\n");
+
+       UPDATE_EVENT_COUNTER();
+       if (dev_priv->status_ptr)
+               hw_e = dev_priv->status_ptr[1] & 0xffff;
+       else
+               hw_e = SAVAGE_READ(SAVAGE_STATUS_WORD1) & 0xffff;
+       hw_w = dev_priv->event_wrap;
+       if (hw_e > dev_priv->event_counter)
+               hw_w--;         /* hardware hasn't passed the last wrap yet */
+
+       event_e = event->count & 0xffff;
+       event_w = event->count >> 16;
+
+       /* Don't need to wait if
+        * - event counter wrapped since the event was emitted or
+        * - the hardware has advanced up to or over the event to wait for.
+        */
+       if (event_w < hw_w || (event_w == hw_w && event_e <= hw_e))
+               return 0;
+       else
+               return dev_priv->wait_evnt(dev_priv, event_e);
+}
+
+/*
+ * DMA buffer management
+ */
+
+static int savage_bci_get_buffers(struct drm_device *dev,
+                                 struct drm_file *file_priv,
+                                 struct drm_dma *d)
+{
+       struct drm_buf *buf;
+       int i;
+
+       for (i = d->granted_count; i < d->request_count; i++) {
+               buf = savage_freelist_get(dev);
+               if (!buf)
+                       return -EAGAIN;
+
+               buf->file_priv = file_priv;
+
+               if (DRM_COPY_TO_USER(&d->request_indices[i],
+                                    &buf->idx, sizeof(buf->idx)))
+                       return -EFAULT;
+               if (DRM_COPY_TO_USER(&d->request_sizes[i],
+                                    &buf->total, sizeof(buf->total)))
+                       return -EFAULT;
+
+               d->granted_count++;
+       }
+       return 0;
+}
+
+int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_dma *d = data;
+       int ret = 0;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       /* Please don't send us buffers.
+        */
+       if (d->send_count != 0) {
+               DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
+                         DRM_CURRENTPID, d->send_count);
+               return -EINVAL;
+       }
+
+       /* We'll send you buffers.
+        */
+       if (d->request_count < 0 || d->request_count > dma->buf_count) {
+               DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
+                         DRM_CURRENTPID, d->request_count, dma->buf_count);
+               return -EINVAL;
+       }
+
+       d->granted_count = 0;
+
+       if (d->request_count) {
+               ret = savage_bci_get_buffers(dev, file_priv, d);
+       }
+
+       return ret;
+}
+
+void savage_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
+{
+       struct drm_device_dma *dma = dev->dma;
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       int i;
+
+       if (!dma)
+               return;
+       if (!dev_priv)
+               return;
+       if (!dma->buflist)
+               return;
+
+       /*i830_flush_queue(dev); */
+
+       for (i = 0; i < dma->buf_count; i++) {
+               struct drm_buf *buf = dma->buflist[i];
+               drm_savage_buf_priv_t *buf_priv = buf->dev_private;
+
+               if (buf->file_priv == file_priv && buf_priv &&
+                   buf_priv->next == NULL && buf_priv->prev == NULL) {
+                       uint16_t event;
+                       DRM_DEBUG("reclaimed from client\n");
+                       event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
+                       SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
+                       savage_freelist_put(dev, buf);
+               }
+       }
+
+       drm_core_reclaim_buffers(dev, file_priv);
+}
+
+struct drm_ioctl_desc savage_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_INIT, savage_bci_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_CMDBUF, savage_bci_cmdbuf, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_EVENT_EMIT, savage_bci_event_emit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SAVAGE_BCI_EVENT_WAIT, savage_bci_event_wait, DRM_AUTH),
+};
+
+int savage_max_ioctl = DRM_ARRAY_SIZE(savage_ioctls);
diff --git a/drivers/gpu/drm/savage/savage_drv.c b/drivers/gpu/drm/savage/savage_drv.c
new file mode 100644 (file)
index 0000000..eee52aa
--- /dev/null
@@ -0,0 +1,88 @@
+/* savage_drv.c -- Savage driver for Linux
+ *
+ * Copyright 2004  Felix Kuehling
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "savage_drm.h"
+#include "savage_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       savage_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
+       .dev_priv_size = sizeof(drm_savage_buf_priv_t),
+       .load = savage_driver_load,
+       .firstopen = savage_driver_firstopen,
+       .lastclose = savage_driver_lastclose,
+       .unload = savage_driver_unload,
+       .reclaim_buffers = savage_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = savage_ioctls,
+       .dma_ioctl = savage_bci_buffers,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init savage_init(void)
+{
+       driver.num_ioctls = savage_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit savage_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(savage_init);
+module_exit(savage_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/savage/savage_drv.h b/drivers/gpu/drm/savage/savage_drv.h
new file mode 100644 (file)
index 0000000..df2aac6
--- /dev/null
@@ -0,0 +1,575 @@
+/* savage_drv.h -- Private header for the savage driver */
+/*
+ * Copyright 2004  Felix Kuehling
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __SAVAGE_DRV_H__
+#define __SAVAGE_DRV_H__
+
+#define DRIVER_AUTHOR  "Felix Kuehling"
+
+#define DRIVER_NAME    "savage"
+#define DRIVER_DESC    "Savage3D/MX/IX, Savage4, SuperSavage, Twister, ProSavage[DDR]"
+#define DRIVER_DATE    "20050313"
+
+#define DRIVER_MAJOR           2
+#define DRIVER_MINOR           4
+#define DRIVER_PATCHLEVEL      1
+/* Interface history:
+ *
+ * 1.x   The DRM driver from the VIA/S3 code drop, basically a dummy
+ * 2.0   The first real DRM
+ * 2.1   Scissors registers managed by the DRM, 3D operations clipped by
+ *       cliprects of the cmdbuf ioctl
+ * 2.2   Implemented SAVAGE_CMD_DMA_IDX and SAVAGE_CMD_VB_IDX
+ * 2.3   Event counters used by BCI_EVENT_EMIT/WAIT ioctls are now 32 bits
+ *       wide and thus very long lived (unlikely to ever wrap). The size
+ *       in the struct was 32 bits before, but only 16 bits were used
+ * 2.4   Implemented command DMA. Now drm_savage_init_t.cmd_dma_offset is
+ *       actually used
+ */
+
+typedef struct drm_savage_age {
+       uint16_t event;
+       unsigned int wrap;
+} drm_savage_age_t;
+
+typedef struct drm_savage_buf_priv {
+       struct drm_savage_buf_priv *next;
+       struct drm_savage_buf_priv *prev;
+       drm_savage_age_t age;
+       struct drm_buf *buf;
+} drm_savage_buf_priv_t;
+
+typedef struct drm_savage_dma_page {
+       drm_savage_age_t age;
+       unsigned int used, flushed;
+} drm_savage_dma_page_t;
+#define SAVAGE_DMA_PAGE_SIZE 1024      /* in dwords */
+/* Fake DMA buffer size in bytes. 4 pages. Allows a maximum command
+ * size of 16kbytes or 4k entries. Minimum requirement would be
+ * 10kbytes for 255 40-byte vertices in one drawing command. */
+#define SAVAGE_FAKE_DMA_SIZE (SAVAGE_DMA_PAGE_SIZE*4*4)
+
+/* interesting bits of hardware state that are saved in dev_priv */
+typedef union {
+       struct drm_savage_common_state {
+               uint32_t vbaddr;
+       } common;
+       struct {
+               unsigned char pad[sizeof(struct drm_savage_common_state)];
+               uint32_t texctrl, texaddr;
+               uint32_t scstart, new_scstart;
+               uint32_t scend, new_scend;
+       } s3d;
+       struct {
+               unsigned char pad[sizeof(struct drm_savage_common_state)];
+               uint32_t texdescr, texaddr0, texaddr1;
+               uint32_t drawctrl0, new_drawctrl0;
+               uint32_t drawctrl1, new_drawctrl1;
+       } s4;
+} drm_savage_state_t;
+
+/* these chip tags should match the ones in the 2D driver in savage_regs.h. */
+enum savage_family {
+       S3_UNKNOWN = 0,
+       S3_SAVAGE3D,
+       S3_SAVAGE_MX,
+       S3_SAVAGE4,
+       S3_PROSAVAGE,
+       S3_TWISTER,
+       S3_PROSAVAGEDDR,
+       S3_SUPERSAVAGE,
+       S3_SAVAGE2000,
+       S3_LAST
+};
+
+extern struct drm_ioctl_desc savage_ioctls[];
+extern int savage_max_ioctl;
+
+#define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
+
+#define S3_SAVAGE4_SERIES(chip)  ((chip==S3_SAVAGE4)            \
+                                  || (chip==S3_PROSAVAGE)       \
+                                  || (chip==S3_TWISTER)         \
+                                  || (chip==S3_PROSAVAGEDDR))
+
+#define        S3_SAVAGE_MOBILE_SERIES(chip)   ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
+
+#define S3_SAVAGE_SERIES(chip)    ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
+
+#define S3_MOBILE_TWISTER_SERIES(chip)   ((chip==S3_TWISTER)    \
+                                          ||(chip==S3_PROSAVAGEDDR))
+
+/* flags */
+#define SAVAGE_IS_AGP 1
+
+typedef struct drm_savage_private {
+       drm_savage_sarea_t *sarea_priv;
+
+       drm_savage_buf_priv_t head, tail;
+
+       /* who am I? */
+       enum savage_family chipset;
+
+       unsigned int cob_size;
+       unsigned int bci_threshold_lo, bci_threshold_hi;
+       unsigned int dma_type;
+
+       /* frame buffer layout */
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+
+       /* bitmap descriptors for swap and clear */
+       unsigned int front_bd, back_bd, depth_bd;
+
+       /* local textures */
+       unsigned int texture_offset;
+       unsigned int texture_size;
+
+       /* memory regions in physical memory */
+       drm_local_map_t *sarea;
+       drm_local_map_t *mmio;
+       drm_local_map_t *fb;
+       drm_local_map_t *aperture;
+       drm_local_map_t *status;
+       drm_local_map_t *agp_textures;
+       drm_local_map_t *cmd_dma;
+       drm_local_map_t fake_dma;
+
+       struct {
+               int handle;
+               unsigned long base, size;
+       } mtrr[3];
+
+       /* BCI and status-related stuff */
+       volatile uint32_t *status_ptr, *bci_ptr;
+       uint32_t status_used_mask;
+       uint16_t event_counter;
+       unsigned int event_wrap;
+
+       /* Savage4 command DMA */
+       drm_savage_dma_page_t *dma_pages;
+       unsigned int nr_dma_pages, first_dma_page, current_dma_page;
+       drm_savage_age_t last_dma_age;
+
+       /* saved hw state for global/local check on S3D */
+       uint32_t hw_draw_ctrl, hw_zbuf_ctrl;
+       /* and for scissors (global, so don't emit if not changed) */
+       uint32_t hw_scissors_start, hw_scissors_end;
+
+       drm_savage_state_t state;
+
+       /* after emitting a wait cmd Savage3D needs 63 nops before next DMA */
+       unsigned int waiting;
+
+       /* config/hardware-dependent function pointers */
+       int (*wait_fifo) (struct drm_savage_private * dev_priv, unsigned int n);
+       int (*wait_evnt) (struct drm_savage_private * dev_priv, uint16_t e);
+       /* Err, there is a macro wait_event in include/linux/wait.h.
+        * Avoid unwanted macro expansion. */
+       void (*emit_clip_rect) (struct drm_savage_private * dev_priv,
+                               const struct drm_clip_rect * pbox);
+       void (*dma_flush) (struct drm_savage_private * dev_priv);
+} drm_savage_private_t;
+
+/* ioctls */
+extern int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int savage_bci_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv);
+
+/* BCI functions */
+extern uint16_t savage_bci_emit_event(drm_savage_private_t * dev_priv,
+                                     unsigned int flags);
+extern void savage_freelist_put(struct drm_device * dev, struct drm_buf * buf);
+extern void savage_dma_reset(drm_savage_private_t * dev_priv);
+extern void savage_dma_wait(drm_savage_private_t * dev_priv, unsigned int page);
+extern uint32_t *savage_dma_alloc(drm_savage_private_t * dev_priv,
+                                 unsigned int n);
+extern int savage_driver_load(struct drm_device *dev, unsigned long chipset);
+extern int savage_driver_firstopen(struct drm_device *dev);
+extern void savage_driver_lastclose(struct drm_device *dev);
+extern int savage_driver_unload(struct drm_device *dev);
+extern void savage_reclaim_buffers(struct drm_device *dev,
+                                  struct drm_file *file_priv);
+
+/* state functions */
+extern void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
+                                     const struct drm_clip_rect * pbox);
+extern void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
+                                    const struct drm_clip_rect * pbox);
+
+#define SAVAGE_FB_SIZE_S3      0x01000000      /*  16MB */
+#define SAVAGE_FB_SIZE_S4      0x02000000      /*  32MB */
+#define SAVAGE_MMIO_SIZE        0x00080000     /* 512kB */
+#define SAVAGE_APERTURE_OFFSET  0x02000000     /*  32MB */
+#define SAVAGE_APERTURE_SIZE    0x05000000     /* 5 tiled surfaces, 16MB each */
+
+#define SAVAGE_BCI_OFFSET       0x00010000     /* offset of the BCI region
+                                                * inside the MMIO region */
+#define SAVAGE_BCI_FIFO_SIZE   32      /* number of entries in on-chip
+                                        * BCI FIFO */
+
+/*
+ * MMIO registers
+ */
+#define SAVAGE_STATUS_WORD0            0x48C00
+#define SAVAGE_STATUS_WORD1            0x48C04
+#define SAVAGE_ALT_STATUS_WORD0        0x48C60
+
+#define SAVAGE_FIFO_USED_MASK_S3D      0x0001ffff
+#define SAVAGE_FIFO_USED_MASK_S4       0x001fffff
+
+/* Copied from savage_bci.h in the 2D driver with some renaming. */
+
+/* Bitmap descriptors */
+#define SAVAGE_BD_STRIDE_SHIFT 0
+#define SAVAGE_BD_BPP_SHIFT   16
+#define SAVAGE_BD_TILE_SHIFT  24
+#define SAVAGE_BD_BW_DISABLE  (1<<28)
+/* common: */
+#define        SAVAGE_BD_TILE_LINEAR           0
+/* savage4, MX, IX, 3D */
+#define        SAVAGE_BD_TILE_16BPP            2
+#define        SAVAGE_BD_TILE_32BPP            3
+/* twister, prosavage, DDR, supersavage, 2000 */
+#define        SAVAGE_BD_TILE_DEST             1
+#define        SAVAGE_BD_TILE_TEXTURE          2
+/* GBD - BCI enable */
+/* savage4, MX, IX, 3D */
+#define SAVAGE_GBD_BCI_ENABLE                    8
+/* twister, prosavage, DDR, supersavage, 2000 */
+#define SAVAGE_GBD_BCI_ENABLE_TWISTER            0
+
+#define SAVAGE_GBD_BIG_ENDIAN                    4
+#define SAVAGE_GBD_LITTLE_ENDIAN                 0
+#define SAVAGE_GBD_64                            1
+
+/*  Global Bitmap Descriptor */
+#define SAVAGE_BCI_GLB_BD_LOW             0x8168
+#define SAVAGE_BCI_GLB_BD_HIGH            0x816C
+
+/*
+ * BCI registers
+ */
+/* Savage4/Twister/ProSavage 3D registers */
+#define SAVAGE_DRAWLOCALCTRL_S4                0x1e
+#define SAVAGE_TEXPALADDR_S4           0x1f
+#define SAVAGE_TEXCTRL0_S4             0x20
+#define SAVAGE_TEXCTRL1_S4             0x21
+#define SAVAGE_TEXADDR0_S4             0x22
+#define SAVAGE_TEXADDR1_S4             0x23
+#define SAVAGE_TEXBLEND0_S4            0x24
+#define SAVAGE_TEXBLEND1_S4            0x25
+#define SAVAGE_TEXXPRCLR_S4            0x26    /* never used */
+#define SAVAGE_TEXDESCR_S4             0x27
+#define SAVAGE_FOGTABLE_S4             0x28
+#define SAVAGE_FOGCTRL_S4              0x30
+#define SAVAGE_STENCILCTRL_S4          0x31
+#define SAVAGE_ZBUFCTRL_S4             0x32
+#define SAVAGE_ZBUFOFF_S4              0x33
+#define SAVAGE_DESTCTRL_S4             0x34
+#define SAVAGE_DRAWCTRL0_S4            0x35
+#define SAVAGE_DRAWCTRL1_S4            0x36
+#define SAVAGE_ZWATERMARK_S4           0x37
+#define SAVAGE_DESTTEXRWWATERMARK_S4   0x38
+#define SAVAGE_TEXBLENDCOLOR_S4                0x39
+/* Savage3D/MX/IX 3D registers */
+#define SAVAGE_TEXPALADDR_S3D          0x18
+#define SAVAGE_TEXXPRCLR_S3D           0x19    /* never used */
+#define SAVAGE_TEXADDR_S3D             0x1A
+#define SAVAGE_TEXDESCR_S3D            0x1B
+#define SAVAGE_TEXCTRL_S3D             0x1C
+#define SAVAGE_FOGTABLE_S3D            0x20
+#define SAVAGE_FOGCTRL_S3D             0x30
+#define SAVAGE_DRAWCTRL_S3D            0x31
+#define SAVAGE_ZBUFCTRL_S3D            0x32
+#define SAVAGE_ZBUFOFF_S3D             0x33
+#define SAVAGE_DESTCTRL_S3D            0x34
+#define SAVAGE_SCSTART_S3D             0x35
+#define SAVAGE_SCEND_S3D               0x36
+#define SAVAGE_ZWATERMARK_S3D          0x37
+#define SAVAGE_DESTTEXRWWATERMARK_S3D  0x38
+/* common stuff */
+#define SAVAGE_VERTBUFADDR             0x3e
+#define SAVAGE_BITPLANEWTMASK          0xd7
+#define SAVAGE_DMABUFADDR              0x51
+
+/* texture enable bits (needed for tex addr checking) */
+#define SAVAGE_TEXCTRL_TEXEN_MASK      0x00010000      /* S3D */
+#define SAVAGE_TEXDESCR_TEX0EN_MASK    0x02000000      /* S4 */
+#define SAVAGE_TEXDESCR_TEX1EN_MASK    0x04000000      /* S4 */
+
+/* Global fields in Savage4/Twister/ProSavage 3D registers:
+ *
+ * All texture registers and DrawLocalCtrl are local. All other
+ * registers are global. */
+
+/* Global fields in Savage3D/MX/IX 3D registers:
+ *
+ * All texture registers are local. DrawCtrl and ZBufCtrl are
+ * partially local. All other registers are global.
+ *
+ * DrawCtrl global fields: cullMode, alphaTestCmpFunc, alphaTestEn, alphaRefVal
+ * ZBufCtrl global fields: zCmpFunc, zBufEn
+ */
+#define SAVAGE_DRAWCTRL_S3D_GLOBAL     0x03f3c00c
+#define SAVAGE_ZBUFCTRL_S3D_GLOBAL     0x00000027
+
+/* Masks for scissor bits (drawCtrl[01] on s4, scissorStart/End on s3d)
+ */
+#define SAVAGE_SCISSOR_MASK_S4         0x00fff7ff
+#define SAVAGE_SCISSOR_MASK_S3D                0x07ff07ff
+
+/*
+ * BCI commands
+ */
+#define BCI_CMD_NOP                  0x40000000
+#define BCI_CMD_RECT                 0x48000000
+#define BCI_CMD_RECT_XP              0x01000000
+#define BCI_CMD_RECT_YP              0x02000000
+#define BCI_CMD_SCANLINE             0x50000000
+#define BCI_CMD_LINE                 0x5C000000
+#define BCI_CMD_LINE_LAST_PIXEL      0x58000000
+#define BCI_CMD_BYTE_TEXT            0x63000000
+#define BCI_CMD_NT_BYTE_TEXT         0x67000000
+#define BCI_CMD_BIT_TEXT             0x6C000000
+#define BCI_CMD_GET_ROP(cmd)         (((cmd) >> 16) & 0xFF)
+#define BCI_CMD_SET_ROP(cmd, rop)    ((cmd) |= ((rop & 0xFF) << 16))
+#define BCI_CMD_SEND_COLOR           0x00008000
+
+#define BCI_CMD_CLIP_NONE            0x00000000
+#define BCI_CMD_CLIP_CURRENT         0x00002000
+#define BCI_CMD_CLIP_LR              0x00004000
+#define BCI_CMD_CLIP_NEW             0x00006000
+
+#define BCI_CMD_DEST_GBD             0x00000000
+#define BCI_CMD_DEST_PBD             0x00000800
+#define BCI_CMD_DEST_PBD_NEW         0x00000C00
+#define BCI_CMD_DEST_SBD             0x00001000
+#define BCI_CMD_DEST_SBD_NEW         0x00001400
+
+#define BCI_CMD_SRC_TRANSPARENT      0x00000200
+#define BCI_CMD_SRC_SOLID            0x00000000
+#define BCI_CMD_SRC_GBD              0x00000020
+#define BCI_CMD_SRC_COLOR            0x00000040
+#define BCI_CMD_SRC_MONO             0x00000060
+#define BCI_CMD_SRC_PBD_COLOR        0x00000080
+#define BCI_CMD_SRC_PBD_MONO         0x000000A0
+#define BCI_CMD_SRC_PBD_COLOR_NEW    0x000000C0
+#define BCI_CMD_SRC_PBD_MONO_NEW     0x000000E0
+#define BCI_CMD_SRC_SBD_COLOR        0x00000100
+#define BCI_CMD_SRC_SBD_MONO         0x00000120
+#define BCI_CMD_SRC_SBD_COLOR_NEW    0x00000140
+#define BCI_CMD_SRC_SBD_MONO_NEW     0x00000160
+
+#define BCI_CMD_PAT_TRANSPARENT      0x00000010
+#define BCI_CMD_PAT_NONE             0x00000000
+#define BCI_CMD_PAT_COLOR            0x00000002
+#define BCI_CMD_PAT_MONO             0x00000003
+#define BCI_CMD_PAT_PBD_COLOR        0x00000004
+#define BCI_CMD_PAT_PBD_MONO         0x00000005
+#define BCI_CMD_PAT_PBD_COLOR_NEW    0x00000006
+#define BCI_CMD_PAT_PBD_MONO_NEW     0x00000007
+#define BCI_CMD_PAT_SBD_COLOR        0x00000008
+#define BCI_CMD_PAT_SBD_MONO         0x00000009
+#define BCI_CMD_PAT_SBD_COLOR_NEW    0x0000000A
+#define BCI_CMD_PAT_SBD_MONO_NEW     0x0000000B
+
+#define BCI_BD_BW_DISABLE            0x10000000
+#define BCI_BD_TILE_MASK             0x03000000
+#define BCI_BD_TILE_NONE             0x00000000
+#define BCI_BD_TILE_16               0x02000000
+#define BCI_BD_TILE_32               0x03000000
+#define BCI_BD_GET_BPP(bd)           (((bd) >> 16) & 0xFF)
+#define BCI_BD_SET_BPP(bd, bpp)      ((bd) |= (((bpp) & 0xFF) << 16))
+#define BCI_BD_GET_STRIDE(bd)        ((bd) & 0xFFFF)
+#define BCI_BD_SET_STRIDE(bd, st)    ((bd) |= ((st) & 0xFFFF))
+
+#define BCI_CMD_SET_REGISTER            0x96000000
+
+#define BCI_CMD_WAIT                    0xC0000000
+#define BCI_CMD_WAIT_3D                 0x00010000
+#define BCI_CMD_WAIT_2D                 0x00020000
+
+#define BCI_CMD_UPDATE_EVENT_TAG        0x98000000
+
+#define BCI_CMD_DRAW_PRIM               0x80000000
+#define BCI_CMD_DRAW_INDEXED_PRIM       0x88000000
+#define BCI_CMD_DRAW_CONT               0x01000000
+#define BCI_CMD_DRAW_TRILIST            0x00000000
+#define BCI_CMD_DRAW_TRISTRIP           0x02000000
+#define BCI_CMD_DRAW_TRIFAN             0x04000000
+#define BCI_CMD_DRAW_SKIPFLAGS          0x000000ff
+#define BCI_CMD_DRAW_NO_Z              0x00000001
+#define BCI_CMD_DRAW_NO_W              0x00000002
+#define BCI_CMD_DRAW_NO_CD             0x00000004
+#define BCI_CMD_DRAW_NO_CS             0x00000008
+#define BCI_CMD_DRAW_NO_U0             0x00000010
+#define BCI_CMD_DRAW_NO_V0             0x00000020
+#define BCI_CMD_DRAW_NO_UV0            0x00000030
+#define BCI_CMD_DRAW_NO_U1             0x00000040
+#define BCI_CMD_DRAW_NO_V1             0x00000080
+#define BCI_CMD_DRAW_NO_UV1            0x000000c0
+
+#define BCI_CMD_DMA                    0xa8000000
+
+#define BCI_W_H(w, h)                ((((h) << 16) | (w)) & 0x0FFF0FFF)
+#define BCI_X_Y(x, y)                ((((y) << 16) | (x)) & 0x0FFF0FFF)
+#define BCI_X_W(x, y)                ((((w) << 16) | (x)) & 0x0FFF0FFF)
+#define BCI_CLIP_LR(l, r)            ((((r) << 16) | (l)) & 0x0FFF0FFF)
+#define BCI_CLIP_TL(t, l)            ((((t) << 16) | (l)) & 0x0FFF0FFF)
+#define BCI_CLIP_BR(b, r)            ((((b) << 16) | (r)) & 0x0FFF0FFF)
+
+#define BCI_LINE_X_Y(x, y)           (((y) << 16) | ((x) & 0xFFFF))
+#define BCI_LINE_STEPS(diag, axi)    (((axi) << 16) | ((diag) & 0xFFFF))
+#define BCI_LINE_MISC(maj, ym, xp, yp, err) \
+       (((maj) & 0x1FFF) | \
+       ((ym) ? 1<<13 : 0) | \
+       ((xp) ? 1<<14 : 0) | \
+       ((yp) ? 1<<15 : 0) | \
+       ((err) << 16))
+
+/*
+ * common commands
+ */
+#define BCI_SET_REGISTERS( first, n )                  \
+       BCI_WRITE(BCI_CMD_SET_REGISTER |                \
+                 ((uint32_t)(n) & 0xff) << 16 |        \
+                 ((uint32_t)(first) & 0xffff))
+#define DMA_SET_REGISTERS( first, n )                  \
+       DMA_WRITE(BCI_CMD_SET_REGISTER |                \
+                 ((uint32_t)(n) & 0xff) << 16 |        \
+                 ((uint32_t)(first) & 0xffff))
+
+#define BCI_DRAW_PRIMITIVE(n, type, skip)         \
+        BCI_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
+                 ((n) << 16))
+#define DMA_DRAW_PRIMITIVE(n, type, skip)         \
+        DMA_WRITE(BCI_CMD_DRAW_PRIM | (type) | (skip) | \
+                 ((n) << 16))
+
+#define BCI_DRAW_INDICES_S3D(n, type, i0)         \
+        BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
+                 ((n) << 16) | (i0))
+
+#define BCI_DRAW_INDICES_S4(n, type, skip)        \
+        BCI_WRITE(BCI_CMD_DRAW_INDEXED_PRIM | (type) |  \
+                  (skip) | ((n) << 16))
+
+#define BCI_DMA(n)     \
+       BCI_WRITE(BCI_CMD_DMA | (((n) >> 1) - 1))
+
+/*
+ * access to MMIO
+ */
+#define SAVAGE_READ(reg)       DRM_READ32(  dev_priv->mmio, (reg) )
+#define SAVAGE_WRITE(reg)      DRM_WRITE32( dev_priv->mmio, (reg) )
+
+/*
+ * access to the burst command interface (BCI)
+ */
+#define SAVAGE_BCI_DEBUG 1
+
+#define BCI_LOCALS    volatile uint32_t *bci_ptr;
+
+#define BEGIN_BCI( n ) do {                    \
+       dev_priv->wait_fifo(dev_priv, (n));     \
+       bci_ptr = dev_priv->bci_ptr;            \
+} while(0)
+
+#define BCI_WRITE( val ) *bci_ptr++ = (uint32_t)(val)
+
+/*
+ * command DMA support
+ */
+#define SAVAGE_DMA_DEBUG 1
+
+#define DMA_LOCALS   uint32_t *dma_ptr;
+
+#define BEGIN_DMA( n ) do {                                            \
+       unsigned int cur = dev_priv->current_dma_page;                  \
+       unsigned int rest = SAVAGE_DMA_PAGE_SIZE -                      \
+               dev_priv->dma_pages[cur].used;                          \
+       if ((n) > rest) {                                               \
+               dma_ptr = savage_dma_alloc(dev_priv, (n));              \
+       } else { /* fast path for small allocations */                  \
+               dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle +       \
+                       cur * SAVAGE_DMA_PAGE_SIZE +                    \
+                       dev_priv->dma_pages[cur].used;                  \
+               if (dev_priv->dma_pages[cur].used == 0)                 \
+                       savage_dma_wait(dev_priv, cur);                 \
+               dev_priv->dma_pages[cur].used += (n);                   \
+       }                                                               \
+} while(0)
+
+#define DMA_WRITE( val ) *dma_ptr++ = (uint32_t)(val)
+
+#define DMA_COPY(src, n) do {                                  \
+       memcpy(dma_ptr, (src), (n)*4);                          \
+       dma_ptr += n;                                           \
+} while(0)
+
+#if SAVAGE_DMA_DEBUG
+#define DMA_COMMIT() do {                                              \
+       unsigned int cur = dev_priv->current_dma_page;                  \
+       uint32_t *expected = (uint32_t *)dev_priv->cmd_dma->handle +    \
+                       cur * SAVAGE_DMA_PAGE_SIZE +                    \
+                       dev_priv->dma_pages[cur].used;                  \
+       if (dma_ptr != expected) {                                      \
+               DRM_ERROR("DMA allocation and use don't match: "        \
+                         "%p != %p\n", expected, dma_ptr);             \
+               savage_dma_reset(dev_priv);                             \
+       }                                                               \
+} while(0)
+#else
+#define DMA_COMMIT() do {/* nothing */} while(0)
+#endif
+
+#define DMA_FLUSH() dev_priv->dma_flush(dev_priv)
+
+/* Buffer aging via event tag
+ */
+
+#define UPDATE_EVENT_COUNTER( ) do {                   \
+       if (dev_priv->status_ptr) {                     \
+               uint16_t count;                         \
+               /* coordinate with Xserver */           \
+               count = dev_priv->status_ptr[1023];     \
+               if (count < dev_priv->event_counter)    \
+                       dev_priv->event_wrap++;         \
+               dev_priv->event_counter = count;        \
+       }                                               \
+} while(0)
+
+#define SET_AGE( age, e, w ) do {      \
+       (age)->event = e;               \
+       (age)->wrap = w;                \
+} while(0)
+
+#define TEST_AGE( age, e, w )                          \
+       ( (age)->wrap < (w) || ( (age)->wrap == (w) && (age)->event <= (e) ) )
+
+#endif                         /* __SAVAGE_DRV_H__ */
diff --git a/drivers/gpu/drm/savage/savage_state.c b/drivers/gpu/drm/savage/savage_state.c
new file mode 100644 (file)
index 0000000..5f6238f
--- /dev/null
@@ -0,0 +1,1163 @@
+/* savage_state.c -- State and drawing support for Savage
+ *
+ * Copyright 2004  Felix Kuehling
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "drmP.h"
+#include "savage_drm.h"
+#include "savage_drv.h"
+
+void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv,
+                              const struct drm_clip_rect * pbox)
+{
+       uint32_t scstart = dev_priv->state.s3d.new_scstart;
+       uint32_t scend = dev_priv->state.s3d.new_scend;
+       scstart = (scstart & ~SAVAGE_SCISSOR_MASK_S3D) |
+           ((uint32_t) pbox->x1 & 0x000007ff) |
+           (((uint32_t) pbox->y1 << 16) & 0x07ff0000);
+       scend = (scend & ~SAVAGE_SCISSOR_MASK_S3D) |
+           (((uint32_t) pbox->x2 - 1) & 0x000007ff) |
+           ((((uint32_t) pbox->y2 - 1) << 16) & 0x07ff0000);
+       if (scstart != dev_priv->state.s3d.scstart ||
+           scend != dev_priv->state.s3d.scend) {
+               DMA_LOCALS;
+               BEGIN_DMA(4);
+               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
+               DMA_SET_REGISTERS(SAVAGE_SCSTART_S3D, 2);
+               DMA_WRITE(scstart);
+               DMA_WRITE(scend);
+               dev_priv->state.s3d.scstart = scstart;
+               dev_priv->state.s3d.scend = scend;
+               dev_priv->waiting = 1;
+               DMA_COMMIT();
+       }
+}
+
+void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv,
+                             const struct drm_clip_rect * pbox)
+{
+       uint32_t drawctrl0 = dev_priv->state.s4.new_drawctrl0;
+       uint32_t drawctrl1 = dev_priv->state.s4.new_drawctrl1;
+       drawctrl0 = (drawctrl0 & ~SAVAGE_SCISSOR_MASK_S4) |
+           ((uint32_t) pbox->x1 & 0x000007ff) |
+           (((uint32_t) pbox->y1 << 12) & 0x00fff000);
+       drawctrl1 = (drawctrl1 & ~SAVAGE_SCISSOR_MASK_S4) |
+           (((uint32_t) pbox->x2 - 1) & 0x000007ff) |
+           ((((uint32_t) pbox->y2 - 1) << 12) & 0x00fff000);
+       if (drawctrl0 != dev_priv->state.s4.drawctrl0 ||
+           drawctrl1 != dev_priv->state.s4.drawctrl1) {
+               DMA_LOCALS;
+               BEGIN_DMA(4);
+               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
+               DMA_SET_REGISTERS(SAVAGE_DRAWCTRL0_S4, 2);
+               DMA_WRITE(drawctrl0);
+               DMA_WRITE(drawctrl1);
+               dev_priv->state.s4.drawctrl0 = drawctrl0;
+               dev_priv->state.s4.drawctrl1 = drawctrl1;
+               dev_priv->waiting = 1;
+               DMA_COMMIT();
+       }
+}
+
+static int savage_verify_texaddr(drm_savage_private_t * dev_priv, int unit,
+                                uint32_t addr)
+{
+       if ((addr & 6) != 2) {  /* reserved bits */
+               DRM_ERROR("bad texAddr%d %08x (reserved bits)\n", unit, addr);
+               return -EINVAL;
+       }
+       if (!(addr & 1)) {      /* local */
+               addr &= ~7;
+               if (addr < dev_priv->texture_offset ||
+                   addr >= dev_priv->texture_offset + dev_priv->texture_size) {
+                       DRM_ERROR
+                           ("bad texAddr%d %08x (local addr out of range)\n",
+                            unit, addr);
+                       return -EINVAL;
+               }
+       } else {                /* AGP */
+               if (!dev_priv->agp_textures) {
+                       DRM_ERROR("bad texAddr%d %08x (AGP not available)\n",
+                                 unit, addr);
+                       return -EINVAL;
+               }
+               addr &= ~7;
+               if (addr < dev_priv->agp_textures->offset ||
+                   addr >= (dev_priv->agp_textures->offset +
+                            dev_priv->agp_textures->size)) {
+                       DRM_ERROR
+                           ("bad texAddr%d %08x (AGP addr out of range)\n",
+                            unit, addr);
+                       return -EINVAL;
+               }
+       }
+       return 0;
+}
+
+#define SAVE_STATE(reg,where)                  \
+       if(start <= reg && start+count > reg)   \
+               dev_priv->state.where = regs[reg - start]
+#define SAVE_STATE_MASK(reg,where,mask) do {                   \
+       if(start <= reg && start+count > reg) {                 \
+               uint32_t tmp;                                   \
+               tmp = regs[reg - start];                        \
+               dev_priv->state.where = (tmp & (mask)) |        \
+                       (dev_priv->state.where & ~(mask));      \
+       }                                                       \
+} while (0)
+
+static int savage_verify_state_s3d(drm_savage_private_t * dev_priv,
+                                  unsigned int start, unsigned int count,
+                                  const uint32_t *regs)
+{
+       if (start < SAVAGE_TEXPALADDR_S3D ||
+           start + count - 1 > SAVAGE_DESTTEXRWWATERMARK_S3D) {
+               DRM_ERROR("invalid register range (0x%04x-0x%04x)\n",
+                         start, start + count - 1);
+               return -EINVAL;
+       }
+
+       SAVE_STATE_MASK(SAVAGE_SCSTART_S3D, s3d.new_scstart,
+                       ~SAVAGE_SCISSOR_MASK_S3D);
+       SAVE_STATE_MASK(SAVAGE_SCEND_S3D, s3d.new_scend,
+                       ~SAVAGE_SCISSOR_MASK_S3D);
+
+       /* if any texture regs were changed ... */
+       if (start <= SAVAGE_TEXCTRL_S3D &&
+           start + count > SAVAGE_TEXPALADDR_S3D) {
+               /* ... check texture state */
+               SAVE_STATE(SAVAGE_TEXCTRL_S3D, s3d.texctrl);
+               SAVE_STATE(SAVAGE_TEXADDR_S3D, s3d.texaddr);
+               if (dev_priv->state.s3d.texctrl & SAVAGE_TEXCTRL_TEXEN_MASK)
+                       return savage_verify_texaddr(dev_priv, 0,
+                                               dev_priv->state.s3d.texaddr);
+       }
+
+       return 0;
+}
+
+static int savage_verify_state_s4(drm_savage_private_t * dev_priv,
+                                 unsigned int start, unsigned int count,
+                                 const uint32_t *regs)
+{
+       int ret = 0;
+
+       if (start < SAVAGE_DRAWLOCALCTRL_S4 ||
+           start + count - 1 > SAVAGE_TEXBLENDCOLOR_S4) {
+               DRM_ERROR("invalid register range (0x%04x-0x%04x)\n",
+                         start, start + count - 1);
+               return -EINVAL;
+       }
+
+       SAVE_STATE_MASK(SAVAGE_DRAWCTRL0_S4, s4.new_drawctrl0,
+                       ~SAVAGE_SCISSOR_MASK_S4);
+       SAVE_STATE_MASK(SAVAGE_DRAWCTRL1_S4, s4.new_drawctrl1,
+                       ~SAVAGE_SCISSOR_MASK_S4);
+
+       /* if any texture regs were changed ... */
+       if (start <= SAVAGE_TEXDESCR_S4 &&
+           start + count > SAVAGE_TEXPALADDR_S4) {
+               /* ... check texture state */
+               SAVE_STATE(SAVAGE_TEXDESCR_S4, s4.texdescr);
+               SAVE_STATE(SAVAGE_TEXADDR0_S4, s4.texaddr0);
+               SAVE_STATE(SAVAGE_TEXADDR1_S4, s4.texaddr1);
+               if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX0EN_MASK)
+                       ret |= savage_verify_texaddr(dev_priv, 0,
+                                               dev_priv->state.s4.texaddr0);
+               if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX1EN_MASK)
+                       ret |= savage_verify_texaddr(dev_priv, 1,
+                                               dev_priv->state.s4.texaddr1);
+       }
+
+       return ret;
+}
+
+#undef SAVE_STATE
+#undef SAVE_STATE_MASK
+
+static int savage_dispatch_state(drm_savage_private_t * dev_priv,
+                                const drm_savage_cmd_header_t * cmd_header,
+                                const uint32_t *regs)
+{
+       unsigned int count = cmd_header->state.count;
+       unsigned int start = cmd_header->state.start;
+       unsigned int count2 = 0;
+       unsigned int bci_size;
+       int ret;
+       DMA_LOCALS;
+
+       if (!count)
+               return 0;
+
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               ret = savage_verify_state_s3d(dev_priv, start, count, regs);
+               if (ret != 0)
+                       return ret;
+               /* scissor regs are emitted in savage_dispatch_draw */
+               if (start < SAVAGE_SCSTART_S3D) {
+                       if (start + count > SAVAGE_SCEND_S3D + 1)
+                               count2 = count - (SAVAGE_SCEND_S3D + 1 - start);
+                       if (start + count > SAVAGE_SCSTART_S3D)
+                               count = SAVAGE_SCSTART_S3D - start;
+               } else if (start <= SAVAGE_SCEND_S3D) {
+                       if (start + count > SAVAGE_SCEND_S3D + 1) {
+                               count -= SAVAGE_SCEND_S3D + 1 - start;
+                               start = SAVAGE_SCEND_S3D + 1;
+                       } else
+                               return 0;
+               }
+       } else {
+               ret = savage_verify_state_s4(dev_priv, start, count, regs);
+               if (ret != 0)
+                       return ret;
+               /* scissor regs are emitted in savage_dispatch_draw */
+               if (start < SAVAGE_DRAWCTRL0_S4) {
+                       if (start + count > SAVAGE_DRAWCTRL1_S4 + 1)
+                               count2 = count -
+                                        (SAVAGE_DRAWCTRL1_S4 + 1 - start);
+                       if (start + count > SAVAGE_DRAWCTRL0_S4)
+                               count = SAVAGE_DRAWCTRL0_S4 - start;
+               } else if (start <= SAVAGE_DRAWCTRL1_S4) {
+                       if (start + count > SAVAGE_DRAWCTRL1_S4 + 1) {
+                               count -= SAVAGE_DRAWCTRL1_S4 + 1 - start;
+                               start = SAVAGE_DRAWCTRL1_S4 + 1;
+                       } else
+                               return 0;
+               }
+       }
+
+       bci_size = count + (count + 254) / 255 + count2 + (count2 + 254) / 255;
+
+       if (cmd_header->state.global) {
+               BEGIN_DMA(bci_size + 1);
+               DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D);
+               dev_priv->waiting = 1;
+       } else {
+               BEGIN_DMA(bci_size);
+       }
+
+       do {
+               while (count > 0) {
+                       unsigned int n = count < 255 ? count : 255;
+                       DMA_SET_REGISTERS(start, n);
+                       DMA_COPY(regs, n);
+                       count -= n;
+                       start += n;
+                       regs += n;
+               }
+               start += 2;
+               regs += 2;
+               count = count2;
+               count2 = 0;
+       } while (count);
+
+       DMA_COMMIT();
+
+       return 0;
+}
+
+static int savage_dispatch_dma_prim(drm_savage_private_t * dev_priv,
+                                   const drm_savage_cmd_header_t * cmd_header,
+                                   const struct drm_buf * dmabuf)
+{
+       unsigned char reorder = 0;
+       unsigned int prim = cmd_header->prim.prim;
+       unsigned int skip = cmd_header->prim.skip;
+       unsigned int n = cmd_header->prim.count;
+       unsigned int start = cmd_header->prim.start;
+       unsigned int i;
+       BCI_LOCALS;
+
+       if (!dmabuf) {
+               DRM_ERROR("called without dma buffers!\n");
+               return -EINVAL;
+       }
+
+       if (!n)
+               return 0;
+
+       switch (prim) {
+       case SAVAGE_PRIM_TRILIST_201:
+               reorder = 1;
+               prim = SAVAGE_PRIM_TRILIST;
+       case SAVAGE_PRIM_TRILIST:
+               if (n % 3 != 0) {
+                       DRM_ERROR("wrong number of vertices %u in TRILIST\n",
+                                 n);
+                       return -EINVAL;
+               }
+               break;
+       case SAVAGE_PRIM_TRISTRIP:
+       case SAVAGE_PRIM_TRIFAN:
+               if (n < 3) {
+                       DRM_ERROR
+                           ("wrong number of vertices %u in TRIFAN/STRIP\n",
+                            n);
+                       return -EINVAL;
+               }
+               break;
+       default:
+               DRM_ERROR("invalid primitive type %u\n", prim);
+               return -EINVAL;
+       }
+
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               if (skip != 0) {
+                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
+                       return -EINVAL;
+               }
+       } else {
+               unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) -
+                   (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) -
+                   (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1);
+               if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) {
+                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
+                       return -EINVAL;
+               }
+               if (reorder) {
+                       DRM_ERROR("TRILIST_201 used on Savage4 hardware\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (start + n > dmabuf->total / 32) {
+               DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n",
+                         start, start + n - 1, dmabuf->total / 32);
+               return -EINVAL;
+       }
+
+       /* Vertex DMA doesn't work with command DMA at the same time,
+        * so we use BCI_... to submit commands here. Flush buffered
+        * faked DMA first. */
+       DMA_FLUSH();
+
+       if (dmabuf->bus_address != dev_priv->state.common.vbaddr) {
+               BEGIN_BCI(2);
+               BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1);
+               BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type);
+               dev_priv->state.common.vbaddr = dmabuf->bus_address;
+       }
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) {
+               /* Workaround for what looks like a hardware bug. If a
+                * WAIT_3D_IDLE was emitted some time before the
+                * indexed drawing command then the engine will lock
+                * up. There are two known workarounds:
+                * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */
+               BEGIN_BCI(63);
+               for (i = 0; i < 63; ++i)
+                       BCI_WRITE(BCI_CMD_WAIT);
+               dev_priv->waiting = 0;
+       }
+
+       prim <<= 25;
+       while (n != 0) {
+               /* Can emit up to 255 indices (85 triangles) at once. */
+               unsigned int count = n > 255 ? 255 : n;
+               if (reorder) {
+                       /* Need to reorder indices for correct flat
+                        * shading while preserving the clock sense
+                        * for correct culling. Only on Savage3D. */
+                       int reorder[3] = { -1, -1, -1 };
+                       reorder[start % 3] = 2;
+
+                       BEGIN_BCI((count + 1 + 1) / 2);
+                       BCI_DRAW_INDICES_S3D(count, prim, start + 2);
+
+                       for (i = start + 1; i + 1 < start + count; i += 2)
+                               BCI_WRITE((i + reorder[i % 3]) |
+                                         ((i + 1 +
+                                           reorder[(i + 1) % 3]) << 16));
+                       if (i < start + count)
+                               BCI_WRITE(i + reorder[i % 3]);
+               } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+                       BEGIN_BCI((count + 1 + 1) / 2);
+                       BCI_DRAW_INDICES_S3D(count, prim, start);
+
+                       for (i = start + 1; i + 1 < start + count; i += 2)
+                               BCI_WRITE(i | ((i + 1) << 16));
+                       if (i < start + count)
+                               BCI_WRITE(i);
+               } else {
+                       BEGIN_BCI((count + 2 + 1) / 2);
+                       BCI_DRAW_INDICES_S4(count, prim, skip);
+
+                       for (i = start; i + 1 < start + count; i += 2)
+                               BCI_WRITE(i | ((i + 1) << 16));
+                       if (i < start + count)
+                               BCI_WRITE(i);
+               }
+
+               start += count;
+               n -= count;
+
+               prim |= BCI_CMD_DRAW_CONT;
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_vb_prim(drm_savage_private_t * dev_priv,
+                                  const drm_savage_cmd_header_t * cmd_header,
+                                  const uint32_t *vtxbuf, unsigned int vb_size,
+                                  unsigned int vb_stride)
+{
+       unsigned char reorder = 0;
+       unsigned int prim = cmd_header->prim.prim;
+       unsigned int skip = cmd_header->prim.skip;
+       unsigned int n = cmd_header->prim.count;
+       unsigned int start = cmd_header->prim.start;
+       unsigned int vtx_size;
+       unsigned int i;
+       DMA_LOCALS;
+
+       if (!n)
+               return 0;
+
+       switch (prim) {
+       case SAVAGE_PRIM_TRILIST_201:
+               reorder = 1;
+               prim = SAVAGE_PRIM_TRILIST;
+       case SAVAGE_PRIM_TRILIST:
+               if (n % 3 != 0) {
+                       DRM_ERROR("wrong number of vertices %u in TRILIST\n",
+                                 n);
+                       return -EINVAL;
+               }
+               break;
+       case SAVAGE_PRIM_TRISTRIP:
+       case SAVAGE_PRIM_TRIFAN:
+               if (n < 3) {
+                       DRM_ERROR
+                           ("wrong number of vertices %u in TRIFAN/STRIP\n",
+                            n);
+                       return -EINVAL;
+               }
+               break;
+       default:
+               DRM_ERROR("invalid primitive type %u\n", prim);
+               return -EINVAL;
+       }
+
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               if (skip > SAVAGE_SKIP_ALL_S3D) {
+                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
+                       return -EINVAL;
+               }
+               vtx_size = 8;   /* full vertex */
+       } else {
+               if (skip > SAVAGE_SKIP_ALL_S4) {
+                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
+                       return -EINVAL;
+               }
+               vtx_size = 10;  /* full vertex */
+       }
+
+       vtx_size -= (skip & 1) + (skip >> 1 & 1) +
+           (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) +
+           (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1);
+
+       if (vtx_size > vb_stride) {
+               DRM_ERROR("vertex size greater than vb stride (%u > %u)\n",
+                         vtx_size, vb_stride);
+               return -EINVAL;
+       }
+
+       if (start + n > vb_size / (vb_stride * 4)) {
+               DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n",
+                         start, start + n - 1, vb_size / (vb_stride * 4));
+               return -EINVAL;
+       }
+
+       prim <<= 25;
+       while (n != 0) {
+               /* Can emit up to 255 vertices (85 triangles) at once. */
+               unsigned int count = n > 255 ? 255 : n;
+               if (reorder) {
+                       /* Need to reorder vertices for correct flat
+                        * shading while preserving the clock sense
+                        * for correct culling. Only on Savage3D. */
+                       int reorder[3] = { -1, -1, -1 };
+                       reorder[start % 3] = 2;
+
+                       BEGIN_DMA(count * vtx_size + 1);
+                       DMA_DRAW_PRIMITIVE(count, prim, skip);
+
+                       for (i = start; i < start + count; ++i) {
+                               unsigned int j = i + reorder[i % 3];
+                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
+                       }
+
+                       DMA_COMMIT();
+               } else {
+                       BEGIN_DMA(count * vtx_size + 1);
+                       DMA_DRAW_PRIMITIVE(count, prim, skip);
+
+                       if (vb_stride == vtx_size) {
+                               DMA_COPY(&vtxbuf[vb_stride * start],
+                                        vtx_size * count);
+                       } else {
+                               for (i = start; i < start + count; ++i) {
+                                       DMA_COPY(&vtxbuf [vb_stride * i],
+                                                vtx_size);
+                               }
+                       }
+
+                       DMA_COMMIT();
+               }
+
+               start += count;
+               n -= count;
+
+               prim |= BCI_CMD_DRAW_CONT;
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_dma_idx(drm_savage_private_t * dev_priv,
+                                  const drm_savage_cmd_header_t * cmd_header,
+                                  const uint16_t *idx,
+                                  const struct drm_buf * dmabuf)
+{
+       unsigned char reorder = 0;
+       unsigned int prim = cmd_header->idx.prim;
+       unsigned int skip = cmd_header->idx.skip;
+       unsigned int n = cmd_header->idx.count;
+       unsigned int i;
+       BCI_LOCALS;
+
+       if (!dmabuf) {
+               DRM_ERROR("called without dma buffers!\n");
+               return -EINVAL;
+       }
+
+       if (!n)
+               return 0;
+
+       switch (prim) {
+       case SAVAGE_PRIM_TRILIST_201:
+               reorder = 1;
+               prim = SAVAGE_PRIM_TRILIST;
+       case SAVAGE_PRIM_TRILIST:
+               if (n % 3 != 0) {
+                       DRM_ERROR("wrong number of indices %u in TRILIST\n", n);
+                       return -EINVAL;
+               }
+               break;
+       case SAVAGE_PRIM_TRISTRIP:
+       case SAVAGE_PRIM_TRIFAN:
+               if (n < 3) {
+                       DRM_ERROR
+                           ("wrong number of indices %u in TRIFAN/STRIP\n", n);
+                       return -EINVAL;
+               }
+               break;
+       default:
+               DRM_ERROR("invalid primitive type %u\n", prim);
+               return -EINVAL;
+       }
+
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               if (skip != 0) {
+                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
+                       return -EINVAL;
+               }
+       } else {
+               unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) -
+                   (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) -
+                   (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1);
+               if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) {
+                       DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip);
+                       return -EINVAL;
+               }
+               if (reorder) {
+                       DRM_ERROR("TRILIST_201 used on Savage4 hardware\n");
+                       return -EINVAL;
+               }
+       }
+
+       /* Vertex DMA doesn't work with command DMA at the same time,
+        * so we use BCI_... to submit commands here. Flush buffered
+        * faked DMA first. */
+       DMA_FLUSH();
+
+       if (dmabuf->bus_address != dev_priv->state.common.vbaddr) {
+               BEGIN_BCI(2);
+               BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1);
+               BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type);
+               dev_priv->state.common.vbaddr = dmabuf->bus_address;
+       }
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) {
+               /* Workaround for what looks like a hardware bug. If a
+                * WAIT_3D_IDLE was emitted some time before the
+                * indexed drawing command then the engine will lock
+                * up. There are two known workarounds:
+                * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */
+               BEGIN_BCI(63);
+               for (i = 0; i < 63; ++i)
+                       BCI_WRITE(BCI_CMD_WAIT);
+               dev_priv->waiting = 0;
+       }
+
+       prim <<= 25;
+       while (n != 0) {
+               /* Can emit up to 255 indices (85 triangles) at once. */
+               unsigned int count = n > 255 ? 255 : n;
+
+               /* check indices */
+               for (i = 0; i < count; ++i) {
+                       if (idx[i] > dmabuf->total / 32) {
+                               DRM_ERROR("idx[%u]=%u out of range (0-%u)\n",
+                                         i, idx[i], dmabuf->total / 32);
+                               return -EINVAL;
+                       }
+               }
+
+               if (reorder) {
+                       /* Need to reorder indices for correct flat
+                        * shading while preserving the clock sense
+                        * for correct culling. Only on Savage3D. */
+                       int reorder[3] = { 2, -1, -1 };
+
+                       BEGIN_BCI((count + 1 + 1) / 2);
+                       BCI_DRAW_INDICES_S3D(count, prim, idx[2]);
+
+                       for (i = 1; i + 1 < count; i += 2)
+                               BCI_WRITE(idx[i + reorder[i % 3]] |
+                                         (idx[i + 1 +
+                                          reorder[(i + 1) % 3]] << 16));
+                       if (i < count)
+                               BCI_WRITE(idx[i + reorder[i % 3]]);
+               } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+                       BEGIN_BCI((count + 1 + 1) / 2);
+                       BCI_DRAW_INDICES_S3D(count, prim, idx[0]);
+
+                       for (i = 1; i + 1 < count; i += 2)
+                               BCI_WRITE(idx[i] | (idx[i + 1] << 16));
+                       if (i < count)
+                               BCI_WRITE(idx[i]);
+               } else {
+                       BEGIN_BCI((count + 2 + 1) / 2);
+                       BCI_DRAW_INDICES_S4(count, prim, skip);
+
+                       for (i = 0; i + 1 < count; i += 2)
+                               BCI_WRITE(idx[i] | (idx[i + 1] << 16));
+                       if (i < count)
+                               BCI_WRITE(idx[i]);
+               }
+
+               idx += count;
+               n -= count;
+
+               prim |= BCI_CMD_DRAW_CONT;
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_vb_idx(drm_savage_private_t * dev_priv,
+                                 const drm_savage_cmd_header_t * cmd_header,
+                                 const uint16_t *idx,
+                                 const uint32_t *vtxbuf,
+                                 unsigned int vb_size, unsigned int vb_stride)
+{
+       unsigned char reorder = 0;
+       unsigned int prim = cmd_header->idx.prim;
+       unsigned int skip = cmd_header->idx.skip;
+       unsigned int n = cmd_header->idx.count;
+       unsigned int vtx_size;
+       unsigned int i;
+       DMA_LOCALS;
+
+       if (!n)
+               return 0;
+
+       switch (prim) {
+       case SAVAGE_PRIM_TRILIST_201:
+               reorder = 1;
+               prim = SAVAGE_PRIM_TRILIST;
+       case SAVAGE_PRIM_TRILIST:
+               if (n % 3 != 0) {
+                       DRM_ERROR("wrong number of indices %u in TRILIST\n", n);
+                       return -EINVAL;
+               }
+               break;
+       case SAVAGE_PRIM_TRISTRIP:
+       case SAVAGE_PRIM_TRIFAN:
+               if (n < 3) {
+                       DRM_ERROR
+                           ("wrong number of indices %u in TRIFAN/STRIP\n", n);
+                       return -EINVAL;
+               }
+               break;
+       default:
+               DRM_ERROR("invalid primitive type %u\n", prim);
+               return -EINVAL;
+       }
+
+       if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) {
+               if (skip > SAVAGE_SKIP_ALL_S3D) {
+                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
+                       return -EINVAL;
+               }
+               vtx_size = 8;   /* full vertex */
+       } else {
+               if (skip > SAVAGE_SKIP_ALL_S4) {
+                       DRM_ERROR("invalid skip flags 0x%04x\n", skip);
+                       return -EINVAL;
+               }
+               vtx_size = 10;  /* full vertex */
+       }
+
+       vtx_size -= (skip & 1) + (skip >> 1 & 1) +
+           (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) +
+           (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1);
+
+       if (vtx_size > vb_stride) {
+               DRM_ERROR("vertex size greater than vb stride (%u > %u)\n",
+                         vtx_size, vb_stride);
+               return -EINVAL;
+       }
+
+       prim <<= 25;
+       while (n != 0) {
+               /* Can emit up to 255 vertices (85 triangles) at once. */
+               unsigned int count = n > 255 ? 255 : n;
+
+               /* Check indices */
+               for (i = 0; i < count; ++i) {
+                       if (idx[i] > vb_size / (vb_stride * 4)) {
+                               DRM_ERROR("idx[%u]=%u out of range (0-%u)\n",
+                                         i, idx[i], vb_size / (vb_stride * 4));
+                               return -EINVAL;
+                       }
+               }
+
+               if (reorder) {
+                       /* Need to reorder vertices for correct flat
+                        * shading while preserving the clock sense
+                        * for correct culling. Only on Savage3D. */
+                       int reorder[3] = { 2, -1, -1 };
+
+                       BEGIN_DMA(count * vtx_size + 1);
+                       DMA_DRAW_PRIMITIVE(count, prim, skip);
+
+                       for (i = 0; i < count; ++i) {
+                               unsigned int j = idx[i + reorder[i % 3]];
+                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
+                       }
+
+                       DMA_COMMIT();
+               } else {
+                       BEGIN_DMA(count * vtx_size + 1);
+                       DMA_DRAW_PRIMITIVE(count, prim, skip);
+
+                       for (i = 0; i < count; ++i) {
+                               unsigned int j = idx[i];
+                               DMA_COPY(&vtxbuf[vb_stride * j], vtx_size);
+                       }
+
+                       DMA_COMMIT();
+               }
+
+               idx += count;
+               n -= count;
+
+               prim |= BCI_CMD_DRAW_CONT;
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_clear(drm_savage_private_t * dev_priv,
+                                const drm_savage_cmd_header_t * cmd_header,
+                                const drm_savage_cmd_header_t *data,
+                                unsigned int nbox,
+                                const struct drm_clip_rect *boxes)
+{
+       unsigned int flags = cmd_header->clear0.flags;
+       unsigned int clear_cmd;
+       unsigned int i, nbufs;
+       DMA_LOCALS;
+
+       if (nbox == 0)
+               return 0;
+
+       clear_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
+           BCI_CMD_SEND_COLOR | BCI_CMD_DEST_PBD_NEW;
+       BCI_CMD_SET_ROP(clear_cmd, 0xCC);
+
+       nbufs = ((flags & SAVAGE_FRONT) ? 1 : 0) +
+           ((flags & SAVAGE_BACK) ? 1 : 0) + ((flags & SAVAGE_DEPTH) ? 1 : 0);
+       if (nbufs == 0)
+               return 0;
+
+       if (data->clear1.mask != 0xffffffff) {
+               /* set mask */
+               BEGIN_DMA(2);
+               DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1);
+               DMA_WRITE(data->clear1.mask);
+               DMA_COMMIT();
+       }
+       for (i = 0; i < nbox; ++i) {
+               unsigned int x, y, w, h;
+               unsigned int buf;
+               x = boxes[i].x1, y = boxes[i].y1;
+               w = boxes[i].x2 - boxes[i].x1;
+               h = boxes[i].y2 - boxes[i].y1;
+               BEGIN_DMA(nbufs * 6);
+               for (buf = SAVAGE_FRONT; buf <= SAVAGE_DEPTH; buf <<= 1) {
+                       if (!(flags & buf))
+                               continue;
+                       DMA_WRITE(clear_cmd);
+                       switch (buf) {
+                       case SAVAGE_FRONT:
+                               DMA_WRITE(dev_priv->front_offset);
+                               DMA_WRITE(dev_priv->front_bd);
+                               break;
+                       case SAVAGE_BACK:
+                               DMA_WRITE(dev_priv->back_offset);
+                               DMA_WRITE(dev_priv->back_bd);
+                               break;
+                       case SAVAGE_DEPTH:
+                               DMA_WRITE(dev_priv->depth_offset);
+                               DMA_WRITE(dev_priv->depth_bd);
+                               break;
+                       }
+                       DMA_WRITE(data->clear1.value);
+                       DMA_WRITE(BCI_X_Y(x, y));
+                       DMA_WRITE(BCI_W_H(w, h));
+               }
+               DMA_COMMIT();
+       }
+       if (data->clear1.mask != 0xffffffff) {
+               /* reset mask */
+               BEGIN_DMA(2);
+               DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1);
+               DMA_WRITE(0xffffffff);
+               DMA_COMMIT();
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_swap(drm_savage_private_t * dev_priv,
+                               unsigned int nbox, const struct drm_clip_rect *boxes)
+{
+       unsigned int swap_cmd;
+       unsigned int i;
+       DMA_LOCALS;
+
+       if (nbox == 0)
+               return 0;
+
+       swap_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
+           BCI_CMD_SRC_PBD_COLOR_NEW | BCI_CMD_DEST_GBD;
+       BCI_CMD_SET_ROP(swap_cmd, 0xCC);
+
+       for (i = 0; i < nbox; ++i) {
+               BEGIN_DMA(6);
+               DMA_WRITE(swap_cmd);
+               DMA_WRITE(dev_priv->back_offset);
+               DMA_WRITE(dev_priv->back_bd);
+               DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1));
+               DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1));
+               DMA_WRITE(BCI_W_H(boxes[i].x2 - boxes[i].x1,
+                                 boxes[i].y2 - boxes[i].y1));
+               DMA_COMMIT();
+       }
+
+       return 0;
+}
+
+static int savage_dispatch_draw(drm_savage_private_t * dev_priv,
+                               const drm_savage_cmd_header_t *start,
+                               const drm_savage_cmd_header_t *end,
+                               const struct drm_buf * dmabuf,
+                               const unsigned int *vtxbuf,
+                               unsigned int vb_size, unsigned int vb_stride,
+                               unsigned int nbox,
+                               const struct drm_clip_rect *boxes)
+{
+       unsigned int i, j;
+       int ret;
+
+       for (i = 0; i < nbox; ++i) {
+               const drm_savage_cmd_header_t *cmdbuf;
+               dev_priv->emit_clip_rect(dev_priv, &boxes[i]);
+
+               cmdbuf = start;
+               while (cmdbuf < end) {
+                       drm_savage_cmd_header_t cmd_header;
+                       cmd_header = *cmdbuf;
+                       cmdbuf++;
+                       switch (cmd_header.cmd.cmd) {
+                       case SAVAGE_CMD_DMA_PRIM:
+                               ret = savage_dispatch_dma_prim(
+                                       dev_priv, &cmd_header, dmabuf);
+                               break;
+                       case SAVAGE_CMD_VB_PRIM:
+                               ret = savage_dispatch_vb_prim(
+                                       dev_priv, &cmd_header,
+                                       vtxbuf, vb_size, vb_stride);
+                               break;
+                       case SAVAGE_CMD_DMA_IDX:
+                               j = (cmd_header.idx.count + 3) / 4;
+                               /* j was check in savage_bci_cmdbuf */
+                               ret = savage_dispatch_dma_idx(dev_priv,
+                                       &cmd_header, (const uint16_t *)cmdbuf,
+                                       dmabuf);
+                               cmdbuf += j;
+                               break;
+                       case SAVAGE_CMD_VB_IDX:
+                               j = (cmd_header.idx.count + 3) / 4;
+                               /* j was check in savage_bci_cmdbuf */
+                               ret = savage_dispatch_vb_idx(dev_priv,
+                                       &cmd_header, (const uint16_t *)cmdbuf,
+                                       (const uint32_t *)vtxbuf, vb_size,
+                                       vb_stride);
+                               cmdbuf += j;
+                               break;
+                       default:
+                               /* What's the best return code? EFAULT? */
+                               DRM_ERROR("IMPLEMENTATION ERROR: "
+                                         "non-drawing-command %d\n",
+                                         cmd_header.cmd.cmd);
+                               return -EINVAL;
+                       }
+
+                       if (ret != 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_savage_private_t *dev_priv = dev->dev_private;
+       struct drm_device_dma *dma = dev->dma;
+       struct drm_buf *dmabuf;
+       drm_savage_cmdbuf_t *cmdbuf = data;
+       drm_savage_cmd_header_t *kcmd_addr = NULL;
+       drm_savage_cmd_header_t *first_draw_cmd;
+       unsigned int *kvb_addr = NULL;
+       struct drm_clip_rect *kbox_addr = NULL;
+       unsigned int i, j;
+       int ret = 0;
+
+       DRM_DEBUG("\n");
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       if (dma && dma->buflist) {
+               if (cmdbuf->dma_idx > dma->buf_count) {
+                       DRM_ERROR
+                           ("vertex buffer index %u out of range (0-%u)\n",
+                            cmdbuf->dma_idx, dma->buf_count - 1);
+                       return -EINVAL;
+               }
+               dmabuf = dma->buflist[cmdbuf->dma_idx];
+       } else {
+               dmabuf = NULL;
+       }
+
+       /* Copy the user buffers into kernel temporary areas.  This hasn't been
+        * a performance loss compared to VERIFYAREA_READ/
+        * COPY_FROM_USER_UNCHECKED when done in other drivers, and is correct
+        * for locking on FreeBSD.
+        */
+       if (cmdbuf->size) {
+               kcmd_addr = drm_alloc(cmdbuf->size * 8, DRM_MEM_DRIVER);
+               if (kcmd_addr == NULL)
+                       return -ENOMEM;
+
+               if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf->cmd_addr,
+                                      cmdbuf->size * 8))
+               {
+                       drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
+                       return -EFAULT;
+               }
+               cmdbuf->cmd_addr = kcmd_addr;
+       }
+       if (cmdbuf->vb_size) {
+               kvb_addr = drm_alloc(cmdbuf->vb_size, DRM_MEM_DRIVER);
+               if (kvb_addr == NULL) {
+                       ret = -ENOMEM;
+                       goto done;
+               }
+
+               if (DRM_COPY_FROM_USER(kvb_addr, cmdbuf->vb_addr,
+                                      cmdbuf->vb_size)) {
+                       ret = -EFAULT;
+                       goto done;
+               }
+               cmdbuf->vb_addr = kvb_addr;
+       }
+       if (cmdbuf->nbox) {
+               kbox_addr = drm_alloc(cmdbuf->nbox * sizeof(struct drm_clip_rect),
+                                      DRM_MEM_DRIVER);
+               if (kbox_addr == NULL) {
+                       ret = -ENOMEM;
+                       goto done;
+               }
+
+               if (DRM_COPY_FROM_USER(kbox_addr, cmdbuf->box_addr,
+                                      cmdbuf->nbox * sizeof(struct drm_clip_rect))) {
+                       ret = -EFAULT;
+                       goto done;
+               }
+       cmdbuf->box_addr = kbox_addr;
+       }
+
+       /* Make sure writes to DMA buffers are finished before sending
+        * DMA commands to the graphics hardware. */
+       DRM_MEMORYBARRIER();
+
+       /* Coming from user space. Don't know if the Xserver has
+        * emitted wait commands. Assuming the worst. */
+       dev_priv->waiting = 1;
+
+       i = 0;
+       first_draw_cmd = NULL;
+       while (i < cmdbuf->size) {
+               drm_savage_cmd_header_t cmd_header;
+               cmd_header = *(drm_savage_cmd_header_t *)cmdbuf->cmd_addr;
+               cmdbuf->cmd_addr++;
+               i++;
+
+               /* Group drawing commands with same state to minimize
+                * iterations over clip rects. */
+               j = 0;
+               switch (cmd_header.cmd.cmd) {
+               case SAVAGE_CMD_DMA_IDX:
+               case SAVAGE_CMD_VB_IDX:
+                       j = (cmd_header.idx.count + 3) / 4;
+                       if (i + j > cmdbuf->size) {
+                               DRM_ERROR("indexed drawing command extends "
+                                         "beyond end of command buffer\n");
+                               DMA_FLUSH();
+                               return -EINVAL;
+                       }
+                       /* fall through */
+               case SAVAGE_CMD_DMA_PRIM:
+               case SAVAGE_CMD_VB_PRIM:
+                       if (!first_draw_cmd)
+                               first_draw_cmd = cmdbuf->cmd_addr - 1;
+                       cmdbuf->cmd_addr += j;
+                       i += j;
+                       break;
+               default:
+                       if (first_draw_cmd) {
+                               ret = savage_dispatch_draw(
+                                     dev_priv, first_draw_cmd,
+                                     cmdbuf->cmd_addr - 1,
+                                     dmabuf, cmdbuf->vb_addr, cmdbuf->vb_size,
+                                     cmdbuf->vb_stride,
+                                     cmdbuf->nbox, cmdbuf->box_addr);
+                               if (ret != 0)
+                                       return ret;
+                               first_draw_cmd = NULL;
+                       }
+               }
+               if (first_draw_cmd)
+                       continue;
+
+               switch (cmd_header.cmd.cmd) {
+               case SAVAGE_CMD_STATE:
+                       j = (cmd_header.state.count + 1) / 2;
+                       if (i + j > cmdbuf->size) {
+                               DRM_ERROR("command SAVAGE_CMD_STATE extends "
+                                         "beyond end of command buffer\n");
+                               DMA_FLUSH();
+                               ret = -EINVAL;
+                               goto done;
+                       }
+                       ret = savage_dispatch_state(dev_priv, &cmd_header,
+                               (const uint32_t *)cmdbuf->cmd_addr);
+                       cmdbuf->cmd_addr += j;
+                       i += j;
+                       break;
+               case SAVAGE_CMD_CLEAR:
+                       if (i + 1 > cmdbuf->size) {
+                               DRM_ERROR("command SAVAGE_CMD_CLEAR extends "
+                                         "beyond end of command buffer\n");
+                               DMA_FLUSH();
+                               ret = -EINVAL;
+                               goto done;
+                       }
+                       ret = savage_dispatch_clear(dev_priv, &cmd_header,
+                                                   cmdbuf->cmd_addr,
+                                                   cmdbuf->nbox,
+                                                   cmdbuf->box_addr);
+                       cmdbuf->cmd_addr++;
+                       i++;
+                       break;
+               case SAVAGE_CMD_SWAP:
+                       ret = savage_dispatch_swap(dev_priv, cmdbuf->nbox,
+                                                  cmdbuf->box_addr);
+                       break;
+               default:
+                       DRM_ERROR("invalid command 0x%x\n",
+                                 cmd_header.cmd.cmd);
+                       DMA_FLUSH();
+                       ret = -EINVAL;
+                       goto done;
+               }
+
+               if (ret != 0) {
+                       DMA_FLUSH();
+                       goto done;
+               }
+       }
+
+       if (first_draw_cmd) {
+               ret = savage_dispatch_draw (
+                       dev_priv, first_draw_cmd, cmdbuf->cmd_addr, dmabuf,
+                       cmdbuf->vb_addr, cmdbuf->vb_size, cmdbuf->vb_stride,
+                       cmdbuf->nbox, cmdbuf->box_addr);
+               if (ret != 0) {
+                       DMA_FLUSH();
+                       goto done;
+               }
+       }
+
+       DMA_FLUSH();
+
+       if (dmabuf && cmdbuf->discard) {
+               drm_savage_buf_priv_t *buf_priv = dmabuf->dev_private;
+               uint16_t event;
+               event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
+               SET_AGE(&buf_priv->age, event, dev_priv->event_wrap);
+               savage_freelist_put(dev, dmabuf);
+       }
+
+done:
+       /* If we didn't need to allocate them, these'll be NULL */
+       drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
+       drm_free(kvb_addr, cmdbuf->vb_size, DRM_MEM_DRIVER);
+       drm_free(kbox_addr, cmdbuf->nbox * sizeof(struct drm_clip_rect),
+                DRM_MEM_DRIVER);
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/sis/Makefile b/drivers/gpu/drm/sis/Makefile
new file mode 100644 (file)
index 0000000..441c061
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y = -Iinclude/drm
+sis-y := sis_drv.o sis_mm.o
+
+obj-$(CONFIG_DRM_SIS)   += sis.o
+
+
diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
new file mode 100644 (file)
index 0000000..7dacc64
--- /dev/null
@@ -0,0 +1,117 @@
+/* sis.c -- sis driver -*- linux-c -*-
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "drmP.h"
+#include "sis_drm.h"
+#include "sis_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       sisdrv_PCI_IDS
+};
+
+static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
+{
+       drm_sis_private_t *dev_priv;
+       int ret;
+
+       dev_priv = drm_calloc(1, sizeof(drm_sis_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = (void *)dev_priv;
+       dev_priv->chipset = chipset;
+       ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
+       if (ret) {
+               drm_free(dev_priv, sizeof(dev_priv), DRM_MEM_DRIVER);
+       }
+
+       return ret;
+}
+
+static int sis_driver_unload(struct drm_device *dev)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+
+       drm_sman_takedown(&dev_priv->sman);
+       drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
+
+       return 0;
+}
+
+static struct drm_driver driver = {
+       .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
+       .load = sis_driver_load,
+       .unload = sis_driver_unload,
+       .context_dtor = NULL,
+       .dma_quiescent = sis_idle,
+       .reclaim_buffers = NULL,
+       .reclaim_buffers_idlelocked = sis_reclaim_buffers_locked,
+       .lastclose = sis_lastclose,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = sis_ioctls,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init sis_init(void)
+{
+       driver.num_ioctls = sis_max_ioctl;
+       return drm_init(&driver);
+}
+
+static void __exit sis_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(sis_init);
+module_exit(sis_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/sis/sis_drv.h b/drivers/gpu/drm/sis/sis_drv.h
new file mode 100644 (file)
index 0000000..ef940ba
--- /dev/null
@@ -0,0 +1,73 @@
+/* sis_drv.h -- Private header for sis driver -*- linux-c -*- */
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _SIS_DRV_H_
+#define _SIS_DRV_H_
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "SIS, Tungsten Graphics"
+#define DRIVER_NAME            "sis"
+#define DRIVER_DESC            "SIS 300/630/540 and XGI V3XE/V5/V8"
+#define DRIVER_DATE            "20070626"
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           3
+#define DRIVER_PATCHLEVEL      0
+
+enum sis_family {
+       SIS_OTHER = 0,
+       SIS_CHIP_315 = 1,
+};
+
+#include "drm_sman.h"
+
+
+#define SIS_BASE (dev_priv->mmio)
+#define SIS_READ(reg)         DRM_READ32(SIS_BASE, reg);
+#define SIS_WRITE(reg, val)   DRM_WRITE32(SIS_BASE, reg, val);
+
+typedef struct drm_sis_private {
+       drm_local_map_t *mmio;
+       unsigned int idle_fault;
+       struct drm_sman sman;
+       unsigned int chipset;
+       int vram_initialized;
+       int agp_initialized;
+       unsigned long vram_offset;
+       unsigned long agp_offset;
+} drm_sis_private_t;
+
+extern int sis_idle(struct drm_device *dev);
+extern void sis_reclaim_buffers_locked(struct drm_device *dev,
+                                      struct drm_file *file_priv);
+extern void sis_lastclose(struct drm_device *dev);
+
+extern struct drm_ioctl_desc sis_ioctls[];
+extern int sis_max_ioctl;
+
+#endif
diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c
new file mode 100644 (file)
index 0000000..b387877
--- /dev/null
@@ -0,0 +1,333 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ **************************************************************************/
+
+/*
+ * Authors:
+ *    Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#include "drmP.h"
+#include "sis_drm.h"
+#include "sis_drv.h"
+
+#include <video/sisfb.h>
+
+#define VIDEO_TYPE 0
+#define AGP_TYPE 1
+
+
+#if defined(CONFIG_FB_SIS)
+/* fb management via fb device */
+
+#define SIS_MM_ALIGN_SHIFT 0
+#define SIS_MM_ALIGN_MASK 0
+
+static void *sis_sman_mm_allocate(void *private, unsigned long size,
+                                 unsigned alignment)
+{
+       struct sis_memreq req;
+
+       req.size = size;
+       sis_malloc(&req);
+       if (req.size == 0)
+               return NULL;
+       else
+               return (void *)~req.offset;
+}
+
+static void sis_sman_mm_free(void *private, void *ref)
+{
+       sis_free(~((unsigned long)ref));
+}
+
+static void sis_sman_mm_destroy(void *private)
+{
+       ;
+}
+
+static unsigned long sis_sman_mm_offset(void *private, void *ref)
+{
+       return ~((unsigned long)ref);
+}
+
+#else /* CONFIG_FB_SIS */
+
+#define SIS_MM_ALIGN_SHIFT 4
+#define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1)
+
+#endif /* CONFIG_FB_SIS */
+
+static int sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+       drm_sis_fb_t *fb = data;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+#if defined(CONFIG_FB_SIS)
+       {
+               struct drm_sman_mm sman_mm;
+               sman_mm.private = (void *)0xFFFFFFFF;
+               sman_mm.allocate = sis_sman_mm_allocate;
+               sman_mm.free = sis_sman_mm_free;
+               sman_mm.destroy = sis_sman_mm_destroy;
+               sman_mm.offset = sis_sman_mm_offset;
+               ret =
+                   drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm);
+       }
+#else
+       ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0,
+                                fb->size >> SIS_MM_ALIGN_SHIFT);
+#endif
+
+       if (ret) {
+               DRM_ERROR("VRAM memory manager initialisation error\n");
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       dev_priv->vram_initialized = 1;
+       dev_priv->vram_offset = fb->offset;
+
+       mutex_unlock(&dev->struct_mutex);
+       DRM_DEBUG("offset = %u, size = %u\n", fb->offset, fb->size);
+
+       return 0;
+}
+
+static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file_priv,
+                        void *data, int pool)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+       drm_sis_mem_t *mem = data;
+       int retval = 0;
+       struct drm_memblock_item *item;
+
+       mutex_lock(&dev->struct_mutex);
+
+       if (0 == ((pool == 0) ? dev_priv->vram_initialized :
+                     dev_priv->agp_initialized)) {
+               DRM_ERROR
+                   ("Attempt to allocate from uninitialized memory manager.\n");
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
+       item = drm_sman_alloc(&dev_priv->sman, pool, mem->size, 0,
+                             (unsigned long)file_priv);
+
+       mutex_unlock(&dev->struct_mutex);
+       if (item) {
+               mem->offset = ((pool == 0) ?
+                             dev_priv->vram_offset : dev_priv->agp_offset) +
+                   (item->mm->
+                    offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
+               mem->free = item->user_hash.key;
+               mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
+       } else {
+               mem->offset = 0;
+               mem->size = 0;
+               mem->free = 0;
+               retval = -ENOMEM;
+       }
+
+       DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem->size,
+                 mem->offset);
+
+       return retval;
+}
+
+static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+       drm_sis_mem_t *mem = data;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_sman_free_key(&dev_priv->sman, mem->free);
+       mutex_unlock(&dev->struct_mutex);
+       DRM_DEBUG("free = 0x%lx\n", mem->free);
+
+       return ret;
+}
+
+static int sis_fb_alloc(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv)
+{
+       return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE);
+}
+
+static int sis_ioctl_agp_init(struct drm_device *dev, void *data,
+                             struct drm_file *file_priv)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+       drm_sis_agp_t *agp = data;
+       int ret;
+       dev_priv = dev->dev_private;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0,
+                                agp->size >> SIS_MM_ALIGN_SHIFT);
+
+       if (ret) {
+               DRM_ERROR("AGP memory manager initialisation error\n");
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       dev_priv->agp_initialized = 1;
+       dev_priv->agp_offset = agp->offset;
+       mutex_unlock(&dev->struct_mutex);
+
+       DRM_DEBUG("offset = %u, size = %u\n", agp->offset, agp->size);
+       return 0;
+}
+
+static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data,
+                              struct drm_file *file_priv)
+{
+
+       return sis_drm_alloc(dev, file_priv, data, AGP_TYPE);
+}
+
+static drm_local_map_t *sis_reg_init(struct drm_device *dev)
+{
+       struct drm_map_list *entry;
+       drm_local_map_t *map;
+
+       list_for_each_entry(entry, &dev->maplist, head) {
+               map = entry->map;
+               if (!map)
+                       continue;
+               if (map->type == _DRM_REGISTERS) {
+                       return map;
+               }
+       }
+       return NULL;
+}
+
+int sis_idle(struct drm_device *dev)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+       uint32_t idle_reg;
+       unsigned long end;
+       int i;
+
+       if (dev_priv->idle_fault)
+               return 0;
+
+       if (dev_priv->mmio == NULL) {
+               dev_priv->mmio = sis_reg_init(dev);
+               if (dev_priv->mmio == NULL) {
+                       DRM_ERROR("Could not find register map.\n");
+                       return 0;
+               }
+       }
+
+       /*
+        * Implement a device switch here if needed
+        */
+
+       if (dev_priv->chipset != SIS_CHIP_315)
+               return 0;
+
+       /*
+        * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here
+        * because its polling frequency is too low.
+        */
+
+       end = jiffies + (DRM_HZ * 3);
+
+       for (i=0; i<4; ++i) {
+               do {
+                       idle_reg = SIS_READ(0x85cc);
+               } while ( !time_after_eq(jiffies, end) &&
+                         ((idle_reg & 0x80000000) != 0x80000000));
+       }
+
+       if (time_after_eq(jiffies, end)) {
+               DRM_ERROR("Graphics engine idle timeout. "
+                         "Disabling idle check\n");
+               dev_priv->idle_fault = 1;
+       }
+
+       /*
+        * The caller never sees an error code. It gets trapped
+        * in libdrm.
+        */
+
+       return 0;
+}
+
+
+void sis_lastclose(struct drm_device *dev)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+
+       if (!dev_priv)
+               return;
+
+       mutex_lock(&dev->struct_mutex);
+       drm_sman_cleanup(&dev_priv->sman);
+       dev_priv->vram_initialized = 0;
+       dev_priv->agp_initialized = 0;
+       dev_priv->mmio = NULL;
+       mutex_unlock(&dev->struct_mutex);
+}
+
+void sis_reclaim_buffers_locked(struct drm_device * dev,
+                               struct drm_file *file_priv)
+{
+       drm_sis_private_t *dev_priv = dev->dev_private;
+
+       mutex_lock(&dev->struct_mutex);
+       if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) {
+               mutex_unlock(&dev->struct_mutex);
+               return;
+       }
+
+       if (dev->driver->dma_quiescent) {
+               dev->driver->dma_quiescent(dev);
+       }
+
+       drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv);
+       mutex_unlock(&dev->struct_mutex);
+       return;
+}
+
+struct drm_ioctl_desc sis_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SIS_FB_FREE, sis_drm_free, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
+       DRM_IOCTL_DEF(DRM_SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SIS_AGP_FREE, sis_drm_free, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_SIS_FB_INIT, sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
+};
+
+int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls);
diff --git a/drivers/gpu/drm/tdfx/Makefile b/drivers/gpu/drm/tdfx/Makefile
new file mode 100644 (file)
index 0000000..0379f29
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+tdfx-y := tdfx_drv.o
+
+obj-$(CONFIG_DRM_TDFX) += tdfx.o
diff --git a/drivers/gpu/drm/tdfx/tdfx_drv.c b/drivers/gpu/drm/tdfx/tdfx_drv.c
new file mode 100644 (file)
index 0000000..012ff2e
--- /dev/null
@@ -0,0 +1,84 @@
+/* tdfx_drv.c -- tdfx driver -*- linux-c -*-
+ * Created: Thu Oct  7 10:38:32 1999 by faith@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@valinux.com>
+ *    Daryll Strauss <daryll@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#include "drmP.h"
+#include "tdfx_drv.h"
+
+#include "drm_pciids.h"
+
+static struct pci_device_id pciidlist[] = {
+       tdfx_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features = DRIVER_USE_MTRR,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init tdfx_init(void)
+{
+       return drm_init(&driver);
+}
+
+static void __exit tdfx_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(tdfx_init);
+module_exit(tdfx_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/tdfx/tdfx_drv.h b/drivers/gpu/drm/tdfx/tdfx_drv.h
new file mode 100644 (file)
index 0000000..84204ec
--- /dev/null
@@ -0,0 +1,47 @@
+/* tdfx.h -- 3dfx DRM template customization -*- linux-c -*-
+ * Created: Wed Feb 14 12:32:32 2001 by gareth@valinux.com
+ */
+/*
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#ifndef __TDFX_H__
+#define __TDFX_H__
+
+/* General customization:
+ */
+
+#define DRIVER_AUTHOR          "VA Linux Systems Inc."
+
+#define DRIVER_NAME            "tdfx"
+#define DRIVER_DESC            "3dfx Banshee/Voodoo3+"
+#define DRIVER_DATE            "20010216"
+
+#define DRIVER_MAJOR           1
+#define DRIVER_MINOR           0
+#define DRIVER_PATCHLEVEL      0
+
+#endif
diff --git a/drivers/gpu/drm/via/Makefile b/drivers/gpu/drm/via/Makefile
new file mode 100644 (file)
index 0000000..d59e258
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the drm device driver.  This driver provides support for the
+# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
+
+ccflags-y := -Iinclude/drm
+via-y    := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o
+
+obj-$(CONFIG_DRM_VIA)  +=via.o
diff --git a/drivers/gpu/drm/via/via_3d_reg.h b/drivers/gpu/drm/via/via_3d_reg.h
new file mode 100644 (file)
index 0000000..462375d
--- /dev/null
@@ -0,0 +1,1650 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef VIA_3D_REG_H
+#define VIA_3D_REG_H
+#define HC_REG_BASE             0x0400
+
+#define HC_REG_TRANS_SPACE      0x0040
+
+#define HC_ParaN_MASK           0xffffffff
+#define HC_Para_MASK            0x00ffffff
+#define HC_SubA_MASK            0xff000000
+#define HC_SubA_SHIFT           24
+/* Transmission Setting
+ */
+#define HC_REG_TRANS_SET        0x003c
+#define HC_ParaSubType_MASK     0xff000000
+#define HC_ParaType_MASK        0x00ff0000
+#define HC_ParaOS_MASK          0x0000ff00
+#define HC_ParaAdr_MASK         0x000000ff
+#define HC_ParaSubType_SHIFT    24
+#define HC_ParaType_SHIFT       16
+#define HC_ParaOS_SHIFT         8
+#define HC_ParaAdr_SHIFT        0
+
+#define HC_ParaType_CmdVdata    0x0000
+#define HC_ParaType_NotTex      0x0001
+#define HC_ParaType_Tex         0x0002
+#define HC_ParaType_Palette     0x0003
+#define HC_ParaType_PreCR       0x0010
+#define HC_ParaType_Auto        0x00fe
+
+/* Transmission Space
+ */
+#define HC_REG_Hpara0           0x0040
+#define HC_REG_HpataAF          0x02fc
+
+/* Read
+ */
+#define HC_REG_HREngSt          0x0000
+#define HC_REG_HRFIFOempty      0x0004
+#define HC_REG_HRFIFOfull       0x0008
+#define HC_REG_HRErr            0x000c
+#define HC_REG_FIFOstatus       0x0010
+/* HC_REG_HREngSt          0x0000
+ */
+#define HC_HDASZC_MASK          0x00010000
+#define HC_HSGEMI_MASK          0x0000f000
+#define HC_HLGEMISt_MASK        0x00000f00
+#define HC_HCRSt_MASK           0x00000080
+#define HC_HSE0St_MASK          0x00000040
+#define HC_HSE1St_MASK          0x00000020
+#define HC_HPESt_MASK           0x00000010
+#define HC_HXESt_MASK           0x00000008
+#define HC_HBESt_MASK           0x00000004
+#define HC_HE2St_MASK           0x00000002
+#define HC_HE3St_MASK           0x00000001
+/* HC_REG_HRFIFOempty      0x0004
+ */
+#define HC_HRZDempty_MASK       0x00000010
+#define HC_HRTXAempty_MASK      0x00000008
+#define HC_HRTXDempty_MASK      0x00000004
+#define HC_HWZDempty_MASK       0x00000002
+#define HC_HWCDempty_MASK       0x00000001
+/* HC_REG_HRFIFOfull       0x0008
+ */
+#define HC_HRZDfull_MASK        0x00000010
+#define HC_HRTXAfull_MASK       0x00000008
+#define HC_HRTXDfull_MASK       0x00000004
+#define HC_HWZDfull_MASK        0x00000002
+#define HC_HWCDfull_MASK        0x00000001
+/* HC_REG_HRErr            0x000c
+ */
+#define HC_HAGPCMErr_MASK       0x80000000
+#define HC_HAGPCMErrC_MASK      0x70000000
+/* HC_REG_FIFOstatus       0x0010
+ */
+#define HC_HRFIFOATall_MASK     0x80000000
+#define HC_HRFIFOATbusy_MASK    0x40000000
+#define HC_HRATFGMDo_MASK       0x00000100
+#define HC_HRATFGMDi_MASK       0x00000080
+#define HC_HRATFRZD_MASK        0x00000040
+#define HC_HRATFRTXA_MASK       0x00000020
+#define HC_HRATFRTXD_MASK       0x00000010
+#define HC_HRATFWZD_MASK        0x00000008
+#define HC_HRATFWCD_MASK        0x00000004
+#define HC_HRATTXTAG_MASK       0x00000002
+#define HC_HRATTXCH_MASK        0x00000001
+
+/* AGP Command Setting
+ */
+#define HC_SubA_HAGPBstL        0x0060
+#define HC_SubA_HAGPBendL       0x0061
+#define HC_SubA_HAGPCMNT        0x0062
+#define HC_SubA_HAGPBpL         0x0063
+#define HC_SubA_HAGPBpH         0x0064
+/* HC_SubA_HAGPCMNT        0x0062
+ */
+#define HC_HAGPCMNT_MASK        0x00800000
+#define HC_HCmdErrClr_MASK      0x00400000
+#define HC_HAGPBendH_MASK       0x0000ff00
+#define HC_HAGPBstH_MASK        0x000000ff
+#define HC_HAGPBendH_SHIFT      8
+#define HC_HAGPBstH_SHIFT       0
+/* HC_SubA_HAGPBpL         0x0063
+ */
+#define HC_HAGPBpL_MASK         0x00fffffc
+#define HC_HAGPBpID_MASK        0x00000003
+#define HC_HAGPBpID_PAUSE       0x00000000
+#define HC_HAGPBpID_JUMP        0x00000001
+#define HC_HAGPBpID_STOP        0x00000002
+/* HC_SubA_HAGPBpH         0x0064
+ */
+#define HC_HAGPBpH_MASK         0x00ffffff
+
+/* Miscellaneous Settings
+ */
+#define HC_SubA_HClipTB         0x0070
+#define HC_SubA_HClipLR         0x0071
+#define HC_SubA_HFPClipTL       0x0072
+#define HC_SubA_HFPClipBL       0x0073
+#define HC_SubA_HFPClipLL       0x0074
+#define HC_SubA_HFPClipRL       0x0075
+#define HC_SubA_HFPClipTBH      0x0076
+#define HC_SubA_HFPClipLRH      0x0077
+#define HC_SubA_HLP             0x0078
+#define HC_SubA_HLPRF           0x0079
+#define HC_SubA_HSolidCL        0x007a
+#define HC_SubA_HPixGC          0x007b
+#define HC_SubA_HSPXYOS         0x007c
+#define HC_SubA_HVertexCNT      0x007d
+
+#define HC_HClipT_MASK          0x00fff000
+#define HC_HClipT_SHIFT         12
+#define HC_HClipB_MASK          0x00000fff
+#define HC_HClipB_SHIFT         0
+#define HC_HClipL_MASK          0x00fff000
+#define HC_HClipL_SHIFT         12
+#define HC_HClipR_MASK          0x00000fff
+#define HC_HClipR_SHIFT         0
+#define HC_HFPClipBH_MASK       0x0000ff00
+#define HC_HFPClipBH_SHIFT      8
+#define HC_HFPClipTH_MASK       0x000000ff
+#define HC_HFPClipTH_SHIFT      0
+#define HC_HFPClipRH_MASK       0x0000ff00
+#define HC_HFPClipRH_SHIFT      8
+#define HC_HFPClipLH_MASK       0x000000ff
+#define HC_HFPClipLH_SHIFT      0
+#define HC_HSolidCH_MASK        0x000000ff
+#define HC_HPixGC_MASK          0x00800000
+#define HC_HSPXOS_MASK          0x00fff000
+#define HC_HSPXOS_SHIFT         12
+#define HC_HSPYOS_MASK          0x00000fff
+
+/* Command
+ * Command A
+ */
+#define HC_HCmdHeader_MASK      0xfe000000     /*0xffe00000 */
+#define HC_HE3Fire_MASK         0x00100000
+#define HC_HPMType_MASK         0x000f0000
+#define HC_HEFlag_MASK          0x0000e000
+#define HC_HShading_MASK        0x00001c00
+#define HC_HPMValidN_MASK       0x00000200
+#define HC_HPLEND_MASK          0x00000100
+#define HC_HVCycle_MASK         0x000000ff
+#define HC_HVCycle_Style_MASK   0x000000c0
+#define HC_HVCycle_ChgA_MASK    0x00000030
+#define HC_HVCycle_ChgB_MASK    0x0000000c
+#define HC_HVCycle_ChgC_MASK    0x00000003
+#define HC_HPMType_Point        0x00000000
+#define HC_HPMType_Line         0x00010000
+#define HC_HPMType_Tri          0x00020000
+#define HC_HPMType_TriWF        0x00040000
+#define HC_HEFlag_NoAA          0x00000000
+#define HC_HEFlag_ab            0x00008000
+#define HC_HEFlag_bc            0x00004000
+#define HC_HEFlag_ca            0x00002000
+#define HC_HShading_Solid       0x00000000
+#define HC_HShading_FlatA       0x00000400
+#define HC_HShading_FlatB       0x00000800
+#define HC_HShading_FlatC       0x00000c00
+#define HC_HShading_Gouraud     0x00001000
+#define HC_HVCycle_Full         0x00000000
+#define HC_HVCycle_AFP          0x00000040
+#define HC_HVCycle_One          0x000000c0
+#define HC_HVCycle_NewA         0x00000000
+#define HC_HVCycle_AA           0x00000010
+#define HC_HVCycle_AB           0x00000020
+#define HC_HVCycle_AC           0x00000030
+#define HC_HVCycle_NewB         0x00000000
+#define HC_HVCycle_BA           0x00000004
+#define HC_HVCycle_BB           0x00000008
+#define HC_HVCycle_BC           0x0000000c
+#define HC_HVCycle_NewC         0x00000000
+#define HC_HVCycle_CA           0x00000001
+#define HC_HVCycle_CB           0x00000002
+#define HC_HVCycle_CC           0x00000003
+
+/* Command B
+ */
+#define HC_HLPrst_MASK          0x00010000
+#define HC_HLLastP_MASK         0x00008000
+#define HC_HVPMSK_MASK          0x00007f80
+#define HC_HBFace_MASK          0x00000040
+#define HC_H2nd1VT_MASK         0x0000003f
+#define HC_HVPMSK_X             0x00004000
+#define HC_HVPMSK_Y             0x00002000
+#define HC_HVPMSK_Z             0x00001000
+#define HC_HVPMSK_W             0x00000800
+#define HC_HVPMSK_Cd            0x00000400
+#define HC_HVPMSK_Cs            0x00000200
+#define HC_HVPMSK_S             0x00000100
+#define HC_HVPMSK_T             0x00000080
+
+/* Enable Setting
+ */
+#define HC_SubA_HEnable         0x0000
+#define HC_HenTXEnvMap_MASK     0x00200000
+#define HC_HenVertexCNT_MASK    0x00100000
+#define HC_HenCPUDAZ_MASK       0x00080000
+#define HC_HenDASZWC_MASK       0x00040000
+#define HC_HenFBCull_MASK       0x00020000
+#define HC_HenCW_MASK           0x00010000
+#define HC_HenAA_MASK           0x00008000
+#define HC_HenST_MASK           0x00004000
+#define HC_HenZT_MASK           0x00002000
+#define HC_HenZW_MASK           0x00001000
+#define HC_HenAT_MASK           0x00000800
+#define HC_HenAW_MASK           0x00000400
+#define HC_HenSP_MASK           0x00000200
+#define HC_HenLP_MASK           0x00000100
+#define HC_HenTXCH_MASK         0x00000080
+#define HC_HenTXMP_MASK         0x00000040
+#define HC_HenTXPP_MASK         0x00000020
+#define HC_HenTXTR_MASK         0x00000010
+#define HC_HenCS_MASK           0x00000008
+#define HC_HenFOG_MASK          0x00000004
+#define HC_HenABL_MASK          0x00000002
+#define HC_HenDT_MASK           0x00000001
+
+/* Z Setting
+ */
+#define HC_SubA_HZWBBasL        0x0010
+#define HC_SubA_HZWBBasH        0x0011
+#define HC_SubA_HZWBType        0x0012
+#define HC_SubA_HZBiasL         0x0013
+#define HC_SubA_HZWBend         0x0014
+#define HC_SubA_HZWTMD          0x0015
+#define HC_SubA_HZWCDL          0x0016
+#define HC_SubA_HZWCTAGnum      0x0017
+#define HC_SubA_HZCYNum         0x0018
+#define HC_SubA_HZWCFire        0x0019
+/* HC_SubA_HZWBType
+ */
+#define HC_HZWBType_MASK        0x00800000
+#define HC_HZBiasedWB_MASK      0x00400000
+#define HC_HZONEasFF_MASK       0x00200000
+#define HC_HZOONEasFF_MASK      0x00100000
+#define HC_HZWBFM_MASK          0x00030000
+#define HC_HZWBLoc_MASK         0x0000c000
+#define HC_HZWBPit_MASK         0x00003fff
+#define HC_HZWBFM_16            0x00000000
+#define HC_HZWBFM_32            0x00020000
+#define HC_HZWBFM_24            0x00030000
+#define HC_HZWBLoc_Local        0x00000000
+#define HC_HZWBLoc_SyS          0x00004000
+/* HC_SubA_HZWBend
+ */
+#define HC_HZWBend_MASK         0x00ffe000
+#define HC_HZBiasH_MASK         0x000000ff
+#define HC_HZWBend_SHIFT        10
+/* HC_SubA_HZWTMD
+ */
+#define HC_HZWTMD_MASK          0x00070000
+#define HC_HEBEBias_MASK        0x00007f00
+#define HC_HZNF_MASK            0x000000ff
+#define HC_HZWTMD_NeverPass     0x00000000
+#define HC_HZWTMD_LT            0x00010000
+#define HC_HZWTMD_EQ            0x00020000
+#define HC_HZWTMD_LE            0x00030000
+#define HC_HZWTMD_GT            0x00040000
+#define HC_HZWTMD_NE            0x00050000
+#define HC_HZWTMD_GE            0x00060000
+#define HC_HZWTMD_AllPass       0x00070000
+#define HC_HEBEBias_SHIFT       8
+/* HC_SubA_HZWCDL          0x0016
+ */
+#define HC_HZWCDL_MASK          0x00ffffff
+/* HC_SubA_HZWCTAGnum      0x0017
+ */
+#define HC_HZWCTAGnum_MASK      0x00ff0000
+#define HC_HZWCTAGnum_SHIFT     16
+#define HC_HZWCDH_MASK          0x000000ff
+#define HC_HZWCDH_SHIFT         0
+/* HC_SubA_HZCYNum         0x0018
+ */
+#define HC_HZCYNum_MASK         0x00030000
+#define HC_HZCYNum_SHIFT        16
+#define HC_HZWCQWnum_MASK       0x00003fff
+#define HC_HZWCQWnum_SHIFT      0
+/* HC_SubA_HZWCFire        0x0019
+ */
+#define HC_ZWCFire_MASK         0x00010000
+#define HC_HZWCQWnumLast_MASK   0x00003fff
+#define HC_HZWCQWnumLast_SHIFT  0
+
+/* Stencil Setting
+ */
+#define HC_SubA_HSTREF          0x0023
+#define HC_SubA_HSTMD           0x0024
+/* HC_SubA_HSBFM
+ */
+#define HC_HSBFM_MASK           0x00030000
+#define HC_HSBLoc_MASK          0x0000c000
+#define HC_HSBPit_MASK          0x00003fff
+/* HC_SubA_HSTREF
+ */
+#define HC_HSTREF_MASK          0x00ff0000
+#define HC_HSTOPMSK_MASK        0x0000ff00
+#define HC_HSTBMSK_MASK         0x000000ff
+#define HC_HSTREF_SHIFT         16
+#define HC_HSTOPMSK_SHIFT       8
+/* HC_SubA_HSTMD
+ */
+#define HC_HSTMD_MASK           0x00070000
+#define HC_HSTOPSF_MASK         0x000001c0
+#define HC_HSTOPSPZF_MASK       0x00000038
+#define HC_HSTOPSPZP_MASK       0x00000007
+#define HC_HSTMD_NeverPass      0x00000000
+#define HC_HSTMD_LT             0x00010000
+#define HC_HSTMD_EQ             0x00020000
+#define HC_HSTMD_LE             0x00030000
+#define HC_HSTMD_GT             0x00040000
+#define HC_HSTMD_NE             0x00050000
+#define HC_HSTMD_GE             0x00060000
+#define HC_HSTMD_AllPass        0x00070000
+#define HC_HSTOPSF_KEEP         0x00000000
+#define HC_HSTOPSF_ZERO         0x00000040
+#define HC_HSTOPSF_REPLACE      0x00000080
+#define HC_HSTOPSF_INCRSAT      0x000000c0
+#define HC_HSTOPSF_DECRSAT      0x00000100
+#define HC_HSTOPSF_INVERT       0x00000140
+#define HC_HSTOPSF_INCR         0x00000180
+#define HC_HSTOPSF_DECR         0x000001c0
+#define HC_HSTOPSPZF_KEEP       0x00000000
+#define HC_HSTOPSPZF_ZERO       0x00000008
+#define HC_HSTOPSPZF_REPLACE    0x00000010
+#define HC_HSTOPSPZF_INCRSAT    0x00000018
+#define HC_HSTOPSPZF_DECRSAT    0x00000020
+#define HC_HSTOPSPZF_INVERT     0x00000028
+#define HC_HSTOPSPZF_INCR       0x00000030
+#define HC_HSTOPSPZF_DECR       0x00000038
+#define HC_HSTOPSPZP_KEEP       0x00000000
+#define HC_HSTOPSPZP_ZERO       0x00000001
+#define HC_HSTOPSPZP_REPLACE    0x00000002
+#define HC_HSTOPSPZP_INCRSAT    0x00000003
+#define HC_HSTOPSPZP_DECRSAT    0x00000004
+#define HC_HSTOPSPZP_INVERT     0x00000005
+#define HC_HSTOPSPZP_INCR       0x00000006
+#define HC_HSTOPSPZP_DECR       0x00000007
+
+/* Alpha Setting
+ */
+#define HC_SubA_HABBasL         0x0030
+#define HC_SubA_HABBasH         0x0031
+#define HC_SubA_HABFM           0x0032
+#define HC_SubA_HATMD           0x0033
+#define HC_SubA_HABLCsat        0x0034
+#define HC_SubA_HABLCop         0x0035
+#define HC_SubA_HABLAsat        0x0036
+#define HC_SubA_HABLAop         0x0037
+#define HC_SubA_HABLRCa         0x0038
+#define HC_SubA_HABLRFCa        0x0039
+#define HC_SubA_HABLRCbias      0x003a
+#define HC_SubA_HABLRCb         0x003b
+#define HC_SubA_HABLRFCb        0x003c
+#define HC_SubA_HABLRAa         0x003d
+#define HC_SubA_HABLRAb         0x003e
+/* HC_SubA_HABFM
+ */
+#define HC_HABFM_MASK           0x00030000
+#define HC_HABLoc_MASK          0x0000c000
+#define HC_HABPit_MASK          0x000007ff
+/* HC_SubA_HATMD
+ */
+#define HC_HATMD_MASK           0x00000700
+#define HC_HATREF_MASK          0x000000ff
+#define HC_HATMD_NeverPass      0x00000000
+#define HC_HATMD_LT             0x00000100
+#define HC_HATMD_EQ             0x00000200
+#define HC_HATMD_LE             0x00000300
+#define HC_HATMD_GT             0x00000400
+#define HC_HATMD_NE             0x00000500
+#define HC_HATMD_GE             0x00000600
+#define HC_HATMD_AllPass        0x00000700
+/* HC_SubA_HABLCsat
+ */
+#define HC_HABLCsat_MASK        0x00010000
+#define HC_HABLCa_MASK          0x0000fc00
+#define HC_HABLCa_C_MASK        0x0000c000
+#define HC_HABLCa_OPC_MASK      0x00003c00
+#define HC_HABLFCa_MASK         0x000003f0
+#define HC_HABLFCa_C_MASK       0x00000300
+#define HC_HABLFCa_OPC_MASK     0x000000f0
+#define HC_HABLCbias_MASK       0x0000000f
+#define HC_HABLCbias_C_MASK     0x00000008
+#define HC_HABLCbias_OPC_MASK   0x00000007
+/*-- Define the input color.
+ */
+#define HC_XC_Csrc              0x00000000
+#define HC_XC_Cdst              0x00000001
+#define HC_XC_Asrc              0x00000002
+#define HC_XC_Adst              0x00000003
+#define HC_XC_Fog               0x00000004
+#define HC_XC_HABLRC            0x00000005
+#define HC_XC_minSrcDst         0x00000006
+#define HC_XC_maxSrcDst         0x00000007
+#define HC_XC_mimAsrcInvAdst    0x00000008
+#define HC_XC_OPC               0x00000000
+#define HC_XC_InvOPC            0x00000010
+#define HC_XC_OPCp5             0x00000020
+/*-- Define the input Alpha
+ */
+#define HC_XA_OPA               0x00000000
+#define HC_XA_InvOPA            0x00000010
+#define HC_XA_OPAp5             0x00000020
+#define HC_XA_0                 0x00000000
+#define HC_XA_Asrc              0x00000001
+#define HC_XA_Adst              0x00000002
+#define HC_XA_Fog               0x00000003
+#define HC_XA_minAsrcFog        0x00000004
+#define HC_XA_minAsrcAdst       0x00000005
+#define HC_XA_maxAsrcFog        0x00000006
+#define HC_XA_maxAsrcAdst       0x00000007
+#define HC_XA_HABLRA            0x00000008
+#define HC_XA_minAsrcInvAdst    0x00000008
+#define HC_XA_HABLFRA           0x00000009
+/*--
+ */
+#define HC_HABLCa_OPC           (HC_XC_OPC << 10)
+#define HC_HABLCa_InvOPC        (HC_XC_InvOPC << 10)
+#define HC_HABLCa_OPCp5         (HC_XC_OPCp5 << 10)
+#define HC_HABLCa_Csrc          (HC_XC_Csrc << 10)
+#define HC_HABLCa_Cdst          (HC_XC_Cdst << 10)
+#define HC_HABLCa_Asrc          (HC_XC_Asrc << 10)
+#define HC_HABLCa_Adst          (HC_XC_Adst << 10)
+#define HC_HABLCa_Fog           (HC_XC_Fog << 10)
+#define HC_HABLCa_HABLRCa       (HC_XC_HABLRC << 10)
+#define HC_HABLCa_minSrcDst     (HC_XC_minSrcDst << 10)
+#define HC_HABLCa_maxSrcDst     (HC_XC_maxSrcDst << 10)
+#define HC_HABLFCa_OPC              (HC_XC_OPC << 4)
+#define HC_HABLFCa_InvOPC           (HC_XC_InvOPC << 4)
+#define HC_HABLFCa_OPCp5            (HC_XC_OPCp5 << 4)
+#define HC_HABLFCa_Csrc             (HC_XC_Csrc << 4)
+#define HC_HABLFCa_Cdst             (HC_XC_Cdst << 4)
+#define HC_HABLFCa_Asrc             (HC_XC_Asrc << 4)
+#define HC_HABLFCa_Adst             (HC_XC_Adst << 4)
+#define HC_HABLFCa_Fog              (HC_XC_Fog << 4)
+#define HC_HABLFCa_HABLRCa          (HC_XC_HABLRC << 4)
+#define HC_HABLFCa_minSrcDst        (HC_XC_minSrcDst << 4)
+#define HC_HABLFCa_maxSrcDst        (HC_XC_maxSrcDst << 4)
+#define HC_HABLFCa_mimAsrcInvAdst   (HC_XC_mimAsrcInvAdst << 4)
+#define HC_HABLCbias_HABLRCbias 0x00000000
+#define HC_HABLCbias_Asrc       0x00000001
+#define HC_HABLCbias_Adst       0x00000002
+#define HC_HABLCbias_Fog        0x00000003
+#define HC_HABLCbias_Cin        0x00000004
+/* HC_SubA_HABLCop         0x0035
+ */
+#define HC_HABLdot_MASK         0x00010000
+#define HC_HABLCop_MASK         0x00004000
+#define HC_HABLCb_MASK          0x00003f00
+#define HC_HABLCb_C_MASK        0x00003000
+#define HC_HABLCb_OPC_MASK      0x00000f00
+#define HC_HABLFCb_MASK         0x000000fc
+#define HC_HABLFCb_C_MASK       0x000000c0
+#define HC_HABLFCb_OPC_MASK     0x0000003c
+#define HC_HABLCshift_MASK      0x00000003
+#define HC_HABLCb_OPC           (HC_XC_OPC << 8)
+#define HC_HABLCb_InvOPC        (HC_XC_InvOPC << 8)
+#define HC_HABLCb_OPCp5         (HC_XC_OPCp5 << 8)
+#define HC_HABLCb_Csrc          (HC_XC_Csrc << 8)
+#define HC_HABLCb_Cdst          (HC_XC_Cdst << 8)
+#define HC_HABLCb_Asrc          (HC_XC_Asrc << 8)
+#define HC_HABLCb_Adst          (HC_XC_Adst << 8)
+#define HC_HABLCb_Fog           (HC_XC_Fog << 8)
+#define HC_HABLCb_HABLRCa       (HC_XC_HABLRC << 8)
+#define HC_HABLCb_minSrcDst     (HC_XC_minSrcDst << 8)
+#define HC_HABLCb_maxSrcDst     (HC_XC_maxSrcDst << 8)
+#define HC_HABLFCb_OPC              (HC_XC_OPC << 2)
+#define HC_HABLFCb_InvOPC           (HC_XC_InvOPC << 2)
+#define HC_HABLFCb_OPCp5            (HC_XC_OPCp5 << 2)
+#define HC_HABLFCb_Csrc             (HC_XC_Csrc << 2)
+#define HC_HABLFCb_Cdst             (HC_XC_Cdst << 2)
+#define HC_HABLFCb_Asrc             (HC_XC_Asrc << 2)
+#define HC_HABLFCb_Adst             (HC_XC_Adst << 2)
+#define HC_HABLFCb_Fog              (HC_XC_Fog << 2)
+#define HC_HABLFCb_HABLRCb          (HC_XC_HABLRC << 2)
+#define HC_HABLFCb_minSrcDst        (HC_XC_minSrcDst << 2)
+#define HC_HABLFCb_maxSrcDst        (HC_XC_maxSrcDst << 2)
+#define HC_HABLFCb_mimAsrcInvAdst   (HC_XC_mimAsrcInvAdst << 2)
+/* HC_SubA_HABLAsat        0x0036
+ */
+#define HC_HABLAsat_MASK        0x00010000
+#define HC_HABLAa_MASK          0x0000fc00
+#define HC_HABLAa_A_MASK        0x0000c000
+#define HC_HABLAa_OPA_MASK      0x00003c00
+#define HC_HABLFAa_MASK         0x000003f0
+#define HC_HABLFAa_A_MASK       0x00000300
+#define HC_HABLFAa_OPA_MASK     0x000000f0
+#define HC_HABLAbias_MASK       0x0000000f
+#define HC_HABLAbias_A_MASK     0x00000008
+#define HC_HABLAbias_OPA_MASK   0x00000007
+#define HC_HABLAa_OPA           (HC_XA_OPA << 10)
+#define HC_HABLAa_InvOPA        (HC_XA_InvOPA << 10)
+#define HC_HABLAa_OPAp5         (HC_XA_OPAp5 << 10)
+#define HC_HABLAa_0             (HC_XA_0 << 10)
+#define HC_HABLAa_Asrc          (HC_XA_Asrc << 10)
+#define HC_HABLAa_Adst          (HC_XA_Adst << 10)
+#define HC_HABLAa_Fog           (HC_XA_Fog << 10)
+#define HC_HABLAa_minAsrcFog    (HC_XA_minAsrcFog << 10)
+#define HC_HABLAa_minAsrcAdst   (HC_XA_minAsrcAdst << 10)
+#define HC_HABLAa_maxAsrcFog    (HC_XA_maxAsrcFog << 10)
+#define HC_HABLAa_maxAsrcAdst   (HC_XA_maxAsrcAdst << 10)
+#define HC_HABLAa_HABLRA        (HC_XA_HABLRA << 10)
+#define HC_HABLFAa_OPA          (HC_XA_OPA << 4)
+#define HC_HABLFAa_InvOPA       (HC_XA_InvOPA << 4)
+#define HC_HABLFAa_OPAp5        (HC_XA_OPAp5 << 4)
+#define HC_HABLFAa_0            (HC_XA_0 << 4)
+#define HC_HABLFAa_Asrc         (HC_XA_Asrc << 4)
+#define HC_HABLFAa_Adst         (HC_XA_Adst << 4)
+#define HC_HABLFAa_Fog          (HC_XA_Fog << 4)
+#define HC_HABLFAa_minAsrcFog   (HC_XA_minAsrcFog << 4)
+#define HC_HABLFAa_minAsrcAdst  (HC_XA_minAsrcAdst << 4)
+#define HC_HABLFAa_maxAsrcFog   (HC_XA_maxAsrcFog << 4)
+#define HC_HABLFAa_maxAsrcAdst  (HC_XA_maxAsrcAdst << 4)
+#define HC_HABLFAa_minAsrcInvAdst   (HC_XA_minAsrcInvAdst << 4)
+#define HC_HABLFAa_HABLFRA          (HC_XA_HABLFRA << 4)
+#define HC_HABLAbias_HABLRAbias 0x00000000
+#define HC_HABLAbias_Asrc       0x00000001
+#define HC_HABLAbias_Adst       0x00000002
+#define HC_HABLAbias_Fog        0x00000003
+#define HC_HABLAbias_Aaa        0x00000004
+/* HC_SubA_HABLAop         0x0037
+ */
+#define HC_HABLAop_MASK         0x00004000
+#define HC_HABLAb_MASK          0x00003f00
+#define HC_HABLAb_OPA_MASK      0x00000f00
+#define HC_HABLFAb_MASK         0x000000fc
+#define HC_HABLFAb_OPA_MASK     0x0000003c
+#define HC_HABLAshift_MASK      0x00000003
+#define HC_HABLAb_OPA           (HC_XA_OPA << 8)
+#define HC_HABLAb_InvOPA        (HC_XA_InvOPA << 8)
+#define HC_HABLAb_OPAp5         (HC_XA_OPAp5 << 8)
+#define HC_HABLAb_0             (HC_XA_0 << 8)
+#define HC_HABLAb_Asrc          (HC_XA_Asrc << 8)
+#define HC_HABLAb_Adst          (HC_XA_Adst << 8)
+#define HC_HABLAb_Fog           (HC_XA_Fog << 8)
+#define HC_HABLAb_minAsrcFog    (HC_XA_minAsrcFog << 8)
+#define HC_HABLAb_minAsrcAdst   (HC_XA_minAsrcAdst << 8)
+#define HC_HABLAb_maxAsrcFog    (HC_XA_maxAsrcFog << 8)
+#define HC_HABLAb_maxAsrcAdst   (HC_XA_maxAsrcAdst << 8)
+#define HC_HABLAb_HABLRA        (HC_XA_HABLRA << 8)
+#define HC_HABLFAb_OPA          (HC_XA_OPA << 2)
+#define HC_HABLFAb_InvOPA       (HC_XA_InvOPA << 2)
+#define HC_HABLFAb_OPAp5        (HC_XA_OPAp5 << 2)
+#define HC_HABLFAb_0            (HC_XA_0 << 2)
+#define HC_HABLFAb_Asrc         (HC_XA_Asrc << 2)
+#define HC_HABLFAb_Adst         (HC_XA_Adst << 2)
+#define HC_HABLFAb_Fog          (HC_XA_Fog << 2)
+#define HC_HABLFAb_minAsrcFog   (HC_XA_minAsrcFog << 2)
+#define HC_HABLFAb_minAsrcAdst  (HC_XA_minAsrcAdst << 2)
+#define HC_HABLFAb_maxAsrcFog   (HC_XA_maxAsrcFog << 2)
+#define HC_HABLFAb_maxAsrcAdst  (HC_XA_maxAsrcAdst << 2)
+#define HC_HABLFAb_minAsrcInvAdst   (HC_XA_minAsrcInvAdst << 2)
+#define HC_HABLFAb_HABLFRA          (HC_XA_HABLFRA << 2)
+/* HC_SubA_HABLRAa         0x003d
+ */
+#define HC_HABLRAa_MASK         0x00ff0000
+#define HC_HABLRFAa_MASK        0x0000ff00
+#define HC_HABLRAbias_MASK      0x000000ff
+#define HC_HABLRAa_SHIFT        16
+#define HC_HABLRFAa_SHIFT       8
+/* HC_SubA_HABLRAb         0x003e
+ */
+#define HC_HABLRAb_MASK         0x0000ff00
+#define HC_HABLRFAb_MASK        0x000000ff
+#define HC_HABLRAb_SHIFT        8
+
+/* Destination Setting
+ */
+#define HC_SubA_HDBBasL         0x0040
+#define HC_SubA_HDBBasH         0x0041
+#define HC_SubA_HDBFM           0x0042
+#define HC_SubA_HFBBMSKL        0x0043
+#define HC_SubA_HROP            0x0044
+/* HC_SubA_HDBFM           0x0042
+ */
+#define HC_HDBFM_MASK           0x001f0000
+#define HC_HDBLoc_MASK          0x0000c000
+#define HC_HDBPit_MASK          0x00003fff
+#define HC_HDBFM_RGB555         0x00000000
+#define HC_HDBFM_RGB565         0x00010000
+#define HC_HDBFM_ARGB4444       0x00020000
+#define HC_HDBFM_ARGB1555       0x00030000
+#define HC_HDBFM_BGR555         0x00040000
+#define HC_HDBFM_BGR565         0x00050000
+#define HC_HDBFM_ABGR4444       0x00060000
+#define HC_HDBFM_ABGR1555       0x00070000
+#define HC_HDBFM_ARGB0888       0x00080000
+#define HC_HDBFM_ARGB8888       0x00090000
+#define HC_HDBFM_ABGR0888       0x000a0000
+#define HC_HDBFM_ABGR8888       0x000b0000
+#define HC_HDBLoc_Local         0x00000000
+#define HC_HDBLoc_Sys           0x00004000
+/* HC_SubA_HROP            0x0044
+ */
+#define HC_HROP_MASK            0x00000f00
+#define HC_HFBBMSKH_MASK        0x000000ff
+#define HC_HROP_BLACK           0x00000000
+#define HC_HROP_DPon            0x00000100
+#define HC_HROP_DPna            0x00000200
+#define HC_HROP_Pn              0x00000300
+#define HC_HROP_PDna            0x00000400
+#define HC_HROP_Dn              0x00000500
+#define HC_HROP_DPx             0x00000600
+#define HC_HROP_DPan            0x00000700
+#define HC_HROP_DPa             0x00000800
+#define HC_HROP_DPxn            0x00000900
+#define HC_HROP_D               0x00000a00
+#define HC_HROP_DPno            0x00000b00
+#define HC_HROP_P               0x00000c00
+#define HC_HROP_PDno            0x00000d00
+#define HC_HROP_DPo             0x00000e00
+#define HC_HROP_WHITE           0x00000f00
+
+/* Fog Setting
+ */
+#define HC_SubA_HFogLF          0x0050
+#define HC_SubA_HFogCL          0x0051
+#define HC_SubA_HFogCH          0x0052
+#define HC_SubA_HFogStL         0x0053
+#define HC_SubA_HFogStH         0x0054
+#define HC_SubA_HFogOOdMF       0x0055
+#define HC_SubA_HFogOOdEF       0x0056
+#define HC_SubA_HFogEndL        0x0057
+#define HC_SubA_HFogDenst       0x0058
+/* HC_SubA_FogLF           0x0050
+ */
+#define HC_FogLF_MASK           0x00000010
+#define HC_FogEq_MASK           0x00000008
+#define HC_FogMD_MASK           0x00000007
+#define HC_FogMD_LocalFog        0x00000000
+#define HC_FogMD_LinearFog       0x00000002
+#define HC_FogMD_ExponentialFog  0x00000004
+#define HC_FogMD_Exponential2Fog 0x00000005
+/* #define HC_FogMD_FogTable       0x00000003 */
+
+/* HC_SubA_HFogDenst        0x0058
+ */
+#define HC_FogDenst_MASK        0x001fff00
+#define HC_FogEndL_MASK         0x000000ff
+
+/* Texture subtype definitions
+ */
+#define HC_SubType_Tex0         0x00000000
+#define HC_SubType_Tex1         0x00000001
+#define HC_SubType_TexGeneral   0x000000fe
+
+/* Attribute of texture n
+ */
+#define HC_SubA_HTXnL0BasL      0x0000
+#define HC_SubA_HTXnL1BasL      0x0001
+#define HC_SubA_HTXnL2BasL      0x0002
+#define HC_SubA_HTXnL3BasL      0x0003
+#define HC_SubA_HTXnL4BasL      0x0004
+#define HC_SubA_HTXnL5BasL      0x0005
+#define HC_SubA_HTXnL6BasL      0x0006
+#define HC_SubA_HTXnL7BasL      0x0007
+#define HC_SubA_HTXnL8BasL      0x0008
+#define HC_SubA_HTXnL9BasL      0x0009
+#define HC_SubA_HTXnLaBasL      0x000a
+#define HC_SubA_HTXnLbBasL      0x000b
+#define HC_SubA_HTXnLcBasL      0x000c
+#define HC_SubA_HTXnLdBasL      0x000d
+#define HC_SubA_HTXnLeBasL      0x000e
+#define HC_SubA_HTXnLfBasL      0x000f
+#define HC_SubA_HTXnL10BasL     0x0010
+#define HC_SubA_HTXnL11BasL     0x0011
+#define HC_SubA_HTXnL012BasH    0x0020
+#define HC_SubA_HTXnL345BasH    0x0021
+#define HC_SubA_HTXnL678BasH    0x0022
+#define HC_SubA_HTXnL9abBasH    0x0023
+#define HC_SubA_HTXnLcdeBasH    0x0024
+#define HC_SubA_HTXnLf1011BasH  0x0025
+#define HC_SubA_HTXnL0Pit       0x002b
+#define HC_SubA_HTXnL1Pit       0x002c
+#define HC_SubA_HTXnL2Pit       0x002d
+#define HC_SubA_HTXnL3Pit       0x002e
+#define HC_SubA_HTXnL4Pit       0x002f
+#define HC_SubA_HTXnL5Pit       0x0030
+#define HC_SubA_HTXnL6Pit       0x0031
+#define HC_SubA_HTXnL7Pit       0x0032
+#define HC_SubA_HTXnL8Pit       0x0033
+#define HC_SubA_HTXnL9Pit       0x0034
+#define HC_SubA_HTXnLaPit       0x0035
+#define HC_SubA_HTXnLbPit       0x0036
+#define HC_SubA_HTXnLcPit       0x0037
+#define HC_SubA_HTXnLdPit       0x0038
+#define HC_SubA_HTXnLePit       0x0039
+#define HC_SubA_HTXnLfPit       0x003a
+#define HC_SubA_HTXnL10Pit      0x003b
+#define HC_SubA_HTXnL11Pit      0x003c
+#define HC_SubA_HTXnL0_5WE      0x004b
+#define HC_SubA_HTXnL6_bWE      0x004c
+#define HC_SubA_HTXnLc_11WE     0x004d
+#define HC_SubA_HTXnL0_5HE      0x0051
+#define HC_SubA_HTXnL6_bHE      0x0052
+#define HC_SubA_HTXnLc_11HE     0x0053
+#define HC_SubA_HTXnL0OS        0x0077
+#define HC_SubA_HTXnTB          0x0078
+#define HC_SubA_HTXnMPMD        0x0079
+#define HC_SubA_HTXnCLODu       0x007a
+#define HC_SubA_HTXnFM          0x007b
+#define HC_SubA_HTXnTRCH        0x007c
+#define HC_SubA_HTXnTRCL        0x007d
+#define HC_SubA_HTXnTBC         0x007e
+#define HC_SubA_HTXnTRAH        0x007f
+#define HC_SubA_HTXnTBLCsat     0x0080
+#define HC_SubA_HTXnTBLCop      0x0081
+#define HC_SubA_HTXnTBLMPfog    0x0082
+#define HC_SubA_HTXnTBLAsat     0x0083
+#define HC_SubA_HTXnTBLRCa      0x0085
+#define HC_SubA_HTXnTBLRCb      0x0086
+#define HC_SubA_HTXnTBLRCc      0x0087
+#define HC_SubA_HTXnTBLRCbias   0x0088
+#define HC_SubA_HTXnTBLRAa      0x0089
+#define HC_SubA_HTXnTBLRFog     0x008a
+#define HC_SubA_HTXnBumpM00     0x0090
+#define HC_SubA_HTXnBumpM01     0x0091
+#define HC_SubA_HTXnBumpM10     0x0092
+#define HC_SubA_HTXnBumpM11     0x0093
+#define HC_SubA_HTXnLScale      0x0094
+#define HC_SubA_HTXSMD          0x0000
+/* HC_SubA_HTXnL012BasH    0x0020
+ */
+#define HC_HTXnL0BasH_MASK      0x000000ff
+#define HC_HTXnL1BasH_MASK      0x0000ff00
+#define HC_HTXnL2BasH_MASK      0x00ff0000
+#define HC_HTXnL1BasH_SHIFT     8
+#define HC_HTXnL2BasH_SHIFT     16
+/* HC_SubA_HTXnL345BasH    0x0021
+ */
+#define HC_HTXnL3BasH_MASK      0x000000ff
+#define HC_HTXnL4BasH_MASK      0x0000ff00
+#define HC_HTXnL5BasH_MASK      0x00ff0000
+#define HC_HTXnL4BasH_SHIFT     8
+#define HC_HTXnL5BasH_SHIFT     16
+/* HC_SubA_HTXnL678BasH    0x0022
+ */
+#define HC_HTXnL6BasH_MASK      0x000000ff
+#define HC_HTXnL7BasH_MASK      0x0000ff00
+#define HC_HTXnL8BasH_MASK      0x00ff0000
+#define HC_HTXnL7BasH_SHIFT     8
+#define HC_HTXnL8BasH_SHIFT     16
+/* HC_SubA_HTXnL9abBasH    0x0023
+ */
+#define HC_HTXnL9BasH_MASK      0x000000ff
+#define HC_HTXnLaBasH_MASK      0x0000ff00
+#define HC_HTXnLbBasH_MASK      0x00ff0000
+#define HC_HTXnLaBasH_SHIFT     8
+#define HC_HTXnLbBasH_SHIFT     16
+/* HC_SubA_HTXnLcdeBasH    0x0024
+ */
+#define HC_HTXnLcBasH_MASK      0x000000ff
+#define HC_HTXnLdBasH_MASK      0x0000ff00
+#define HC_HTXnLeBasH_MASK      0x00ff0000
+#define HC_HTXnLdBasH_SHIFT     8
+#define HC_HTXnLeBasH_SHIFT     16
+/* HC_SubA_HTXnLcdeBasH    0x0025
+ */
+#define HC_HTXnLfBasH_MASK      0x000000ff
+#define HC_HTXnL10BasH_MASK      0x0000ff00
+#define HC_HTXnL11BasH_MASK      0x00ff0000
+#define HC_HTXnL10BasH_SHIFT     8
+#define HC_HTXnL11BasH_SHIFT     16
+/* HC_SubA_HTXnL0Pit       0x002b
+ */
+#define HC_HTXnLnPit_MASK       0x00003fff
+#define HC_HTXnEnPit_MASK       0x00080000
+#define HC_HTXnLnPitE_MASK      0x00f00000
+#define HC_HTXnLnPitE_SHIFT     20
+/* HC_SubA_HTXnL0_5WE      0x004b
+ */
+#define HC_HTXnL0WE_MASK        0x0000000f
+#define HC_HTXnL1WE_MASK        0x000000f0
+#define HC_HTXnL2WE_MASK        0x00000f00
+#define HC_HTXnL3WE_MASK        0x0000f000
+#define HC_HTXnL4WE_MASK        0x000f0000
+#define HC_HTXnL5WE_MASK        0x00f00000
+#define HC_HTXnL1WE_SHIFT       4
+#define HC_HTXnL2WE_SHIFT       8
+#define HC_HTXnL3WE_SHIFT       12
+#define HC_HTXnL4WE_SHIFT       16
+#define HC_HTXnL5WE_SHIFT       20
+/* HC_SubA_HTXnL6_bWE      0x004c
+ */
+#define HC_HTXnL6WE_MASK        0x0000000f
+#define HC_HTXnL7WE_MASK        0x000000f0
+#define HC_HTXnL8WE_MASK        0x00000f00
+#define HC_HTXnL9WE_MASK        0x0000f000
+#define HC_HTXnLaWE_MASK        0x000f0000
+#define HC_HTXnLbWE_MASK        0x00f00000
+#define HC_HTXnL7WE_SHIFT       4
+#define HC_HTXnL8WE_SHIFT       8
+#define HC_HTXnL9WE_SHIFT       12
+#define HC_HTXnLaWE_SHIFT       16
+#define HC_HTXnLbWE_SHIFT       20
+/* HC_SubA_HTXnLc_11WE      0x004d
+ */
+#define HC_HTXnLcWE_MASK        0x0000000f
+#define HC_HTXnLdWE_MASK        0x000000f0
+#define HC_HTXnLeWE_MASK        0x00000f00
+#define HC_HTXnLfWE_MASK        0x0000f000
+#define HC_HTXnL10WE_MASK       0x000f0000
+#define HC_HTXnL11WE_MASK       0x00f00000
+#define HC_HTXnLdWE_SHIFT       4
+#define HC_HTXnLeWE_SHIFT       8
+#define HC_HTXnLfWE_SHIFT       12
+#define HC_HTXnL10WE_SHIFT      16
+#define HC_HTXnL11WE_SHIFT      20
+/* HC_SubA_HTXnL0_5HE      0x0051
+ */
+#define HC_HTXnL0HE_MASK        0x0000000f
+#define HC_HTXnL1HE_MASK        0x000000f0
+#define HC_HTXnL2HE_MASK        0x00000f00
+#define HC_HTXnL3HE_MASK        0x0000f000
+#define HC_HTXnL4HE_MASK        0x000f0000
+#define HC_HTXnL5HE_MASK        0x00f00000
+#define HC_HTXnL1HE_SHIFT       4
+#define HC_HTXnL2HE_SHIFT       8
+#define HC_HTXnL3HE_SHIFT       12
+#define HC_HTXnL4HE_SHIFT       16
+#define HC_HTXnL5HE_SHIFT       20
+/* HC_SubA_HTXnL6_bHE      0x0052
+ */
+#define HC_HTXnL6HE_MASK        0x0000000f
+#define HC_HTXnL7HE_MASK        0x000000f0
+#define HC_HTXnL8HE_MASK        0x00000f00
+#define HC_HTXnL9HE_MASK        0x0000f000
+#define HC_HTXnLaHE_MASK        0x000f0000
+#define HC_HTXnLbHE_MASK        0x00f00000
+#define HC_HTXnL7HE_SHIFT       4
+#define HC_HTXnL8HE_SHIFT       8
+#define HC_HTXnL9HE_SHIFT       12
+#define HC_HTXnLaHE_SHIFT       16
+#define HC_HTXnLbHE_SHIFT       20
+/* HC_SubA_HTXnLc_11HE      0x0053
+ */
+#define HC_HTXnLcHE_MASK        0x0000000f
+#define HC_HTXnLdHE_MASK        0x000000f0
+#define HC_HTXnLeHE_MASK        0x00000f00
+#define HC_HTXnLfHE_MASK        0x0000f000
+#define HC_HTXnL10HE_MASK       0x000f0000
+#define HC_HTXnL11HE_MASK       0x00f00000
+#define HC_HTXnLdHE_SHIFT       4
+#define HC_HTXnLeHE_SHIFT       8
+#define HC_HTXnLfHE_SHIFT       12
+#define HC_HTXnL10HE_SHIFT      16
+#define HC_HTXnL11HE_SHIFT      20
+/* HC_SubA_HTXnL0OS        0x0077
+ */
+#define HC_HTXnL0OS_MASK        0x003ff000
+#define HC_HTXnLVmax_MASK       0x00000fc0
+#define HC_HTXnLVmin_MASK       0x0000003f
+#define HC_HTXnL0OS_SHIFT       12
+#define HC_HTXnLVmax_SHIFT      6
+/* HC_SubA_HTXnTB          0x0078
+ */
+#define HC_HTXnTB_MASK          0x00f00000
+#define HC_HTXnFLSe_MASK        0x0000e000
+#define HC_HTXnFLSs_MASK        0x00001c00
+#define HC_HTXnFLTe_MASK        0x00000380
+#define HC_HTXnFLTs_MASK        0x00000070
+#define HC_HTXnFLDs_MASK        0x0000000f
+#define HC_HTXnTB_NoTB          0x00000000
+#define HC_HTXnTB_TBC_S         0x00100000
+#define HC_HTXnTB_TBC_T         0x00200000
+#define HC_HTXnTB_TB_S          0x00400000
+#define HC_HTXnTB_TB_T          0x00800000
+#define HC_HTXnFLSe_Nearest     0x00000000
+#define HC_HTXnFLSe_Linear      0x00002000
+#define HC_HTXnFLSe_NonLinear   0x00004000
+#define HC_HTXnFLSe_Sharp       0x00008000
+#define HC_HTXnFLSe_Flat_Gaussian_Cubic 0x0000c000
+#define HC_HTXnFLSs_Nearest     0x00000000
+#define HC_HTXnFLSs_Linear      0x00000400
+#define HC_HTXnFLSs_NonLinear   0x00000800
+#define HC_HTXnFLSs_Flat_Gaussian_Cubic 0x00001800
+#define HC_HTXnFLTe_Nearest     0x00000000
+#define HC_HTXnFLTe_Linear      0x00000080
+#define HC_HTXnFLTe_NonLinear   0x00000100
+#define HC_HTXnFLTe_Sharp       0x00000180
+#define HC_HTXnFLTe_Flat_Gaussian_Cubic 0x00000300
+#define HC_HTXnFLTs_Nearest     0x00000000
+#define HC_HTXnFLTs_Linear      0x00000010
+#define HC_HTXnFLTs_NonLinear   0x00000020
+#define HC_HTXnFLTs_Flat_Gaussian_Cubic 0x00000060
+#define HC_HTXnFLDs_Tex0        0x00000000
+#define HC_HTXnFLDs_Nearest     0x00000001
+#define HC_HTXnFLDs_Linear      0x00000002
+#define HC_HTXnFLDs_NonLinear   0x00000003
+#define HC_HTXnFLDs_Dither      0x00000004
+#define HC_HTXnFLDs_ConstLOD    0x00000005
+#define HC_HTXnFLDs_Ani         0x00000006
+#define HC_HTXnFLDs_AniDither   0x00000007
+/* HC_SubA_HTXnMPMD        0x0079
+ */
+#define HC_HTXnMPMD_SMASK       0x00070000
+#define HC_HTXnMPMD_TMASK       0x00380000
+#define HC_HTXnLODDTf_MASK      0x00000007
+#define HC_HTXnXY2ST_MASK       0x00000008
+#define HC_HTXnMPMD_Tsingle     0x00000000
+#define HC_HTXnMPMD_Tclamp      0x00080000
+#define HC_HTXnMPMD_Trepeat     0x00100000
+#define HC_HTXnMPMD_Tmirror     0x00180000
+#define HC_HTXnMPMD_Twrap       0x00200000
+#define HC_HTXnMPMD_Ssingle     0x00000000
+#define HC_HTXnMPMD_Sclamp      0x00010000
+#define HC_HTXnMPMD_Srepeat     0x00020000
+#define HC_HTXnMPMD_Smirror     0x00030000
+#define HC_HTXnMPMD_Swrap       0x00040000
+/* HC_SubA_HTXnCLODu       0x007a
+ */
+#define HC_HTXnCLODu_MASK       0x000ffc00
+#define HC_HTXnCLODd_MASK       0x000003ff
+#define HC_HTXnCLODu_SHIFT      10
+/* HC_SubA_HTXnFM          0x007b
+ */
+#define HC_HTXnFM_MASK          0x00ff0000
+#define HC_HTXnLoc_MASK         0x00000003
+#define HC_HTXnFM_INDEX         0x00000000
+#define HC_HTXnFM_Intensity     0x00080000
+#define HC_HTXnFM_Lum           0x00100000
+#define HC_HTXnFM_Alpha         0x00180000
+#define HC_HTXnFM_DX            0x00280000
+#define HC_HTXnFM_ARGB16        0x00880000
+#define HC_HTXnFM_ARGB32        0x00980000
+#define HC_HTXnFM_ABGR16        0x00a80000
+#define HC_HTXnFM_ABGR32        0x00b80000
+#define HC_HTXnFM_RGBA16        0x00c80000
+#define HC_HTXnFM_RGBA32        0x00d80000
+#define HC_HTXnFM_BGRA16        0x00e80000
+#define HC_HTXnFM_BGRA32        0x00f80000
+#define HC_HTXnFM_BUMPMAP       0x00380000
+#define HC_HTXnFM_Index1        (HC_HTXnFM_INDEX     | 0x00000000)
+#define HC_HTXnFM_Index2        (HC_HTXnFM_INDEX     | 0x00010000)
+#define HC_HTXnFM_Index4        (HC_HTXnFM_INDEX     | 0x00020000)
+#define HC_HTXnFM_Index8        (HC_HTXnFM_INDEX     | 0x00030000)
+#define HC_HTXnFM_T1            (HC_HTXnFM_Intensity | 0x00000000)
+#define HC_HTXnFM_T2            (HC_HTXnFM_Intensity | 0x00010000)
+#define HC_HTXnFM_T4            (HC_HTXnFM_Intensity | 0x00020000)
+#define HC_HTXnFM_T8            (HC_HTXnFM_Intensity | 0x00030000)
+#define HC_HTXnFM_L1            (HC_HTXnFM_Lum       | 0x00000000)
+#define HC_HTXnFM_L2            (HC_HTXnFM_Lum       | 0x00010000)
+#define HC_HTXnFM_L4            (HC_HTXnFM_Lum       | 0x00020000)
+#define HC_HTXnFM_L8            (HC_HTXnFM_Lum       | 0x00030000)
+#define HC_HTXnFM_AL44          (HC_HTXnFM_Lum       | 0x00040000)
+#define HC_HTXnFM_AL88          (HC_HTXnFM_Lum       | 0x00050000)
+#define HC_HTXnFM_A1            (HC_HTXnFM_Alpha     | 0x00000000)
+#define HC_HTXnFM_A2            (HC_HTXnFM_Alpha     | 0x00010000)
+#define HC_HTXnFM_A4            (HC_HTXnFM_Alpha     | 0x00020000)
+#define HC_HTXnFM_A8            (HC_HTXnFM_Alpha     | 0x00030000)
+#define HC_HTXnFM_DX1           (HC_HTXnFM_DX        | 0x00010000)
+#define HC_HTXnFM_DX23          (HC_HTXnFM_DX        | 0x00020000)
+#define HC_HTXnFM_DX45          (HC_HTXnFM_DX        | 0x00030000)
+#define HC_HTXnFM_RGB555        (HC_HTXnFM_ARGB16    | 0x00000000)
+#define HC_HTXnFM_RGB565        (HC_HTXnFM_ARGB16    | 0x00010000)
+#define HC_HTXnFM_ARGB1555      (HC_HTXnFM_ARGB16    | 0x00020000)
+#define HC_HTXnFM_ARGB4444      (HC_HTXnFM_ARGB16    | 0x00030000)
+#define HC_HTXnFM_ARGB0888      (HC_HTXnFM_ARGB32    | 0x00000000)
+#define HC_HTXnFM_ARGB8888      (HC_HTXnFM_ARGB32    | 0x00010000)
+#define HC_HTXnFM_BGR555        (HC_HTXnFM_ABGR16    | 0x00000000)
+#define HC_HTXnFM_BGR565        (HC_HTXnFM_ABGR16    | 0x00010000)
+#define HC_HTXnFM_ABGR1555      (HC_HTXnFM_ABGR16    | 0x00020000)
+#define HC_HTXnFM_ABGR4444      (HC_HTXnFM_ABGR16    | 0x00030000)
+#define HC_HTXnFM_ABGR0888      (HC_HTXnFM_ABGR32    | 0x00000000)
+#define HC_HTXnFM_ABGR8888      (HC_HTXnFM_ABGR32    | 0x00010000)
+#define HC_HTXnFM_RGBA5550      (HC_HTXnFM_RGBA16    | 0x00000000)
+#define HC_HTXnFM_RGBA5551      (HC_HTXnFM_RGBA16    | 0x00020000)
+#define HC_HTXnFM_RGBA4444      (HC_HTXnFM_RGBA16    | 0x00030000)
+#define HC_HTXnFM_RGBA8880      (HC_HTXnFM_RGBA32    | 0x00000000)
+#define HC_HTXnFM_RGBA8888      (HC_HTXnFM_RGBA32    | 0x00010000)
+#define HC_HTXnFM_BGRA5550      (HC_HTXnFM_BGRA16    | 0x00000000)
+#define HC_HTXnFM_BGRA5551      (HC_HTXnFM_BGRA16    | 0x00020000)
+#define HC_HTXnFM_BGRA4444      (HC_HTXnFM_BGRA16    | 0x00030000)
+#define HC_HTXnFM_BGRA8880      (HC_HTXnFM_BGRA32    | 0x00000000)
+#define HC_HTXnFM_BGRA8888      (HC_HTXnFM_BGRA32    | 0x00010000)
+#define HC_HTXnFM_VU88          (HC_HTXnFM_BUMPMAP   | 0x00000000)
+#define HC_HTXnFM_LVU655        (HC_HTXnFM_BUMPMAP   | 0x00010000)
+#define HC_HTXnFM_LVU888        (HC_HTXnFM_BUMPMAP   | 0x00020000)
+#define HC_HTXnLoc_Local        0x00000000
+#define HC_HTXnLoc_Sys          0x00000002
+#define HC_HTXnLoc_AGP          0x00000003
+/* HC_SubA_HTXnTRAH        0x007f
+ */
+#define HC_HTXnTRAH_MASK        0x00ff0000
+#define HC_HTXnTRAL_MASK        0x0000ff00
+#define HC_HTXnTBA_MASK         0x000000ff
+#define HC_HTXnTRAH_SHIFT       16
+#define HC_HTXnTRAL_SHIFT       8
+/* HC_SubA_HTXnTBLCsat     0x0080
+ *-- Define the input texture.
+ */
+#define HC_XTC_TOPC             0x00000000
+#define HC_XTC_InvTOPC          0x00000010
+#define HC_XTC_TOPCp5           0x00000020
+#define HC_XTC_Cbias            0x00000000
+#define HC_XTC_InvCbias         0x00000010
+#define HC_XTC_0                0x00000000
+#define HC_XTC_Dif              0x00000001
+#define HC_XTC_Spec             0x00000002
+#define HC_XTC_Tex              0x00000003
+#define HC_XTC_Cur              0x00000004
+#define HC_XTC_Adif             0x00000005
+#define HC_XTC_Fog              0x00000006
+#define HC_XTC_Atex             0x00000007
+#define HC_XTC_Acur             0x00000008
+#define HC_XTC_HTXnTBLRC        0x00000009
+#define HC_XTC_Ctexnext         0x0000000a
+/*--
+ */
+#define HC_HTXnTBLCsat_MASK     0x00800000
+#define HC_HTXnTBLCa_MASK       0x000fc000
+#define HC_HTXnTBLCb_MASK       0x00001f80
+#define HC_HTXnTBLCc_MASK       0x0000003f
+#define HC_HTXnTBLCa_TOPC       (HC_XTC_TOPC << 14)
+#define HC_HTXnTBLCa_InvTOPC    (HC_XTC_InvTOPC << 14)
+#define HC_HTXnTBLCa_TOPCp5     (HC_XTC_TOPCp5 << 14)
+#define HC_HTXnTBLCa_0          (HC_XTC_0 << 14)
+#define HC_HTXnTBLCa_Dif        (HC_XTC_Dif << 14)
+#define HC_HTXnTBLCa_Spec       (HC_XTC_Spec << 14)
+#define HC_HTXnTBLCa_Tex        (HC_XTC_Tex << 14)
+#define HC_HTXnTBLCa_Cur        (HC_XTC_Cur << 14)
+#define HC_HTXnTBLCa_Adif       (HC_XTC_Adif << 14)
+#define HC_HTXnTBLCa_Fog        (HC_XTC_Fog << 14)
+#define HC_HTXnTBLCa_Atex       (HC_XTC_Atex << 14)
+#define HC_HTXnTBLCa_Acur       (HC_XTC_Acur << 14)
+#define HC_HTXnTBLCa_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 14)
+#define HC_HTXnTBLCa_Ctexnext   (HC_XTC_Ctexnext << 14)
+#define HC_HTXnTBLCb_TOPC       (HC_XTC_TOPC << 7)
+#define HC_HTXnTBLCb_InvTOPC    (HC_XTC_InvTOPC << 7)
+#define HC_HTXnTBLCb_TOPCp5     (HC_XTC_TOPCp5 << 7)
+#define HC_HTXnTBLCb_0          (HC_XTC_0 << 7)
+#define HC_HTXnTBLCb_Dif        (HC_XTC_Dif << 7)
+#define HC_HTXnTBLCb_Spec       (HC_XTC_Spec << 7)
+#define HC_HTXnTBLCb_Tex        (HC_XTC_Tex << 7)
+#define HC_HTXnTBLCb_Cur        (HC_XTC_Cur << 7)
+#define HC_HTXnTBLCb_Adif       (HC_XTC_Adif << 7)
+#define HC_HTXnTBLCb_Fog        (HC_XTC_Fog << 7)
+#define HC_HTXnTBLCb_Atex       (HC_XTC_Atex << 7)
+#define HC_HTXnTBLCb_Acur       (HC_XTC_Acur << 7)
+#define HC_HTXnTBLCb_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 7)
+#define HC_HTXnTBLCb_Ctexnext   (HC_XTC_Ctexnext << 7)
+#define HC_HTXnTBLCc_TOPC       (HC_XTC_TOPC << 0)
+#define HC_HTXnTBLCc_InvTOPC    (HC_XTC_InvTOPC << 0)
+#define HC_HTXnTBLCc_TOPCp5     (HC_XTC_TOPCp5 << 0)
+#define HC_HTXnTBLCc_0          (HC_XTC_0 << 0)
+#define HC_HTXnTBLCc_Dif        (HC_XTC_Dif << 0)
+#define HC_HTXnTBLCc_Spec       (HC_XTC_Spec << 0)
+#define HC_HTXnTBLCc_Tex        (HC_XTC_Tex << 0)
+#define HC_HTXnTBLCc_Cur        (HC_XTC_Cur << 0)
+#define HC_HTXnTBLCc_Adif       (HC_XTC_Adif << 0)
+#define HC_HTXnTBLCc_Fog        (HC_XTC_Fog << 0)
+#define HC_HTXnTBLCc_Atex       (HC_XTC_Atex << 0)
+#define HC_HTXnTBLCc_Acur       (HC_XTC_Acur << 0)
+#define HC_HTXnTBLCc_HTXnTBLRC  (HC_XTC_HTXnTBLRC << 0)
+#define HC_HTXnTBLCc_Ctexnext   (HC_XTC_Ctexnext << 0)
+/* HC_SubA_HTXnTBLCop      0x0081
+ */
+#define HC_HTXnTBLdot_MASK      0x00c00000
+#define HC_HTXnTBLCop_MASK      0x00380000
+#define HC_HTXnTBLCbias_MASK    0x0007c000
+#define HC_HTXnTBLCshift_MASK   0x00001800
+#define HC_HTXnTBLAop_MASK      0x00000380
+#define HC_HTXnTBLAbias_MASK    0x00000078
+#define HC_HTXnTBLAshift_MASK   0x00000003
+#define HC_HTXnTBLCop_Add       0x00000000
+#define HC_HTXnTBLCop_Sub       0x00080000
+#define HC_HTXnTBLCop_Min       0x00100000
+#define HC_HTXnTBLCop_Max       0x00180000
+#define HC_HTXnTBLCop_Mask      0x00200000
+#define HC_HTXnTBLCbias_Cbias           (HC_XTC_Cbias << 14)
+#define HC_HTXnTBLCbias_InvCbias        (HC_XTC_InvCbias << 14)
+#define HC_HTXnTBLCbias_0               (HC_XTC_0 << 14)
+#define HC_HTXnTBLCbias_Dif             (HC_XTC_Dif << 14)
+#define HC_HTXnTBLCbias_Spec            (HC_XTC_Spec << 14)
+#define HC_HTXnTBLCbias_Tex             (HC_XTC_Tex << 14)
+#define HC_HTXnTBLCbias_Cur             (HC_XTC_Cur << 14)
+#define HC_HTXnTBLCbias_Adif            (HC_XTC_Adif << 14)
+#define HC_HTXnTBLCbias_Fog             (HC_XTC_Fog << 14)
+#define HC_HTXnTBLCbias_Atex            (HC_XTC_Atex << 14)
+#define HC_HTXnTBLCbias_Acur            (HC_XTC_Acur << 14)
+#define HC_HTXnTBLCbias_HTXnTBLRC       (HC_XTC_HTXnTBLRC << 14)
+#define HC_HTXnTBLCshift_1      0x00000000
+#define HC_HTXnTBLCshift_2      0x00000800
+#define HC_HTXnTBLCshift_No     0x00001000
+#define HC_HTXnTBLCshift_DotP   0x00001800
+/*=* John Sheng [2003.7.18] texture combine *=*/
+#define HC_HTXnTBLDOT3   0x00080000
+#define HC_HTXnTBLDOT4   0x000C0000
+
+#define HC_HTXnTBLAop_Add       0x00000000
+#define HC_HTXnTBLAop_Sub       0x00000080
+#define HC_HTXnTBLAop_Min       0x00000100
+#define HC_HTXnTBLAop_Max       0x00000180
+#define HC_HTXnTBLAop_Mask      0x00000200
+#define HC_HTXnTBLAbias_Inv             0x00000040
+#define HC_HTXnTBLAbias_Adif            0x00000000
+#define HC_HTXnTBLAbias_Fog             0x00000008
+#define HC_HTXnTBLAbias_Acur            0x00000010
+#define HC_HTXnTBLAbias_HTXnTBLRAbias   0x00000018
+#define HC_HTXnTBLAbias_Atex            0x00000020
+#define HC_HTXnTBLAshift_1      0x00000000
+#define HC_HTXnTBLAshift_2      0x00000001
+#define HC_HTXnTBLAshift_No     0x00000002
+/* #define HC_HTXnTBLAshift_DotP   0x00000003 */
+/* HC_SubA_HTXnTBLMPFog    0x0082
+ */
+#define HC_HTXnTBLMPfog_MASK    0x00e00000
+#define HC_HTXnTBLMPfog_0       0x00000000
+#define HC_HTXnTBLMPfog_Adif    0x00200000
+#define HC_HTXnTBLMPfog_Fog     0x00400000
+#define HC_HTXnTBLMPfog_Atex    0x00600000
+#define HC_HTXnTBLMPfog_Acur    0x00800000
+#define HC_HTXnTBLMPfog_GHTXnTBLRFog    0x00a00000
+/* HC_SubA_HTXnTBLAsat     0x0083
+ *-- Define the texture alpha input.
+ */
+#define HC_XTA_TOPA             0x00000000
+#define HC_XTA_InvTOPA          0x00000008
+#define HC_XTA_TOPAp5           0x00000010
+#define HC_XTA_Adif             0x00000000
+#define HC_XTA_Fog              0x00000001
+#define HC_XTA_Acur             0x00000002
+#define HC_XTA_HTXnTBLRA        0x00000003
+#define HC_XTA_Atex             0x00000004
+#define HC_XTA_Atexnext         0x00000005
+/*--
+ */
+#define HC_HTXnTBLAsat_MASK     0x00800000
+#define HC_HTXnTBLAMB_MASK      0x00700000
+#define HC_HTXnTBLAa_MASK       0x0007c000
+#define HC_HTXnTBLAb_MASK       0x00000f80
+#define HC_HTXnTBLAc_MASK       0x0000001f
+#define HC_HTXnTBLAMB_SHIFT     20
+#define HC_HTXnTBLAa_TOPA       (HC_XTA_TOPA << 14)
+#define HC_HTXnTBLAa_InvTOPA    (HC_XTA_InvTOPA << 14)
+#define HC_HTXnTBLAa_TOPAp5     (HC_XTA_TOPAp5 << 14)
+#define HC_HTXnTBLAa_Adif       (HC_XTA_Adif << 14)
+#define HC_HTXnTBLAa_Fog        (HC_XTA_Fog << 14)
+#define HC_HTXnTBLAa_Acur       (HC_XTA_Acur << 14)
+#define HC_HTXnTBLAa_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 14)
+#define HC_HTXnTBLAa_Atex       (HC_XTA_Atex << 14)
+#define HC_HTXnTBLAa_Atexnext   (HC_XTA_Atexnext << 14)
+#define HC_HTXnTBLAb_TOPA       (HC_XTA_TOPA << 7)
+#define HC_HTXnTBLAb_InvTOPA    (HC_XTA_InvTOPA << 7)
+#define HC_HTXnTBLAb_TOPAp5     (HC_XTA_TOPAp5 << 7)
+#define HC_HTXnTBLAb_Adif       (HC_XTA_Adif << 7)
+#define HC_HTXnTBLAb_Fog        (HC_XTA_Fog << 7)
+#define HC_HTXnTBLAb_Acur       (HC_XTA_Acur << 7)
+#define HC_HTXnTBLAb_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 7)
+#define HC_HTXnTBLAb_Atex       (HC_XTA_Atex << 7)
+#define HC_HTXnTBLAb_Atexnext   (HC_XTA_Atexnext << 7)
+#define HC_HTXnTBLAc_TOPA       (HC_XTA_TOPA << 0)
+#define HC_HTXnTBLAc_InvTOPA    (HC_XTA_InvTOPA << 0)
+#define HC_HTXnTBLAc_TOPAp5     (HC_XTA_TOPAp5 << 0)
+#define HC_HTXnTBLAc_Adif       (HC_XTA_Adif << 0)
+#define HC_HTXnTBLAc_Fog        (HC_XTA_Fog << 0)
+#define HC_HTXnTBLAc_Acur       (HC_XTA_Acur << 0)
+#define HC_HTXnTBLAc_HTXnTBLRA  (HC_XTA_HTXnTBLRA << 0)
+#define HC_HTXnTBLAc_Atex       (HC_XTA_Atex << 0)
+#define HC_HTXnTBLAc_Atexnext   (HC_XTA_Atexnext << 0)
+/* HC_SubA_HTXnTBLRAa      0x0089
+ */
+#define HC_HTXnTBLRAa_MASK      0x00ff0000
+#define HC_HTXnTBLRAb_MASK      0x0000ff00
+#define HC_HTXnTBLRAc_MASK      0x000000ff
+#define HC_HTXnTBLRAa_SHIFT     16
+#define HC_HTXnTBLRAb_SHIFT     8
+#define HC_HTXnTBLRAc_SHIFT     0
+/* HC_SubA_HTXnTBLRFog     0x008a
+ */
+#define HC_HTXnTBLRFog_MASK     0x0000ff00
+#define HC_HTXnTBLRAbias_MASK   0x000000ff
+#define HC_HTXnTBLRFog_SHIFT    8
+#define HC_HTXnTBLRAbias_SHIFT  0
+/* HC_SubA_HTXnLScale      0x0094
+ */
+#define HC_HTXnLScale_MASK      0x0007fc00
+#define HC_HTXnLOff_MASK        0x000001ff
+#define HC_HTXnLScale_SHIFT     10
+/* HC_SubA_HTXSMD          0x0000
+ */
+#define HC_HTXSMD_MASK          0x00000080
+#define HC_HTXTMD_MASK          0x00000040
+#define HC_HTXNum_MASK          0x00000038
+#define HC_HTXTRMD_MASK         0x00000006
+#define HC_HTXCHCLR_MASK        0x00000001
+#define HC_HTXNum_SHIFT         3
+
+/* Texture Palette n
+ */
+#define HC_SubType_TexPalette0  0x00000000
+#define HC_SubType_TexPalette1  0x00000001
+#define HC_SubType_FogTable     0x00000010
+#define HC_SubType_Stipple      0x00000014
+/* HC_SubA_TexPalette0     0x0000
+ */
+#define HC_HTPnA_MASK           0xff000000
+#define HC_HTPnR_MASK           0x00ff0000
+#define HC_HTPnG_MASK           0x0000ff00
+#define HC_HTPnB_MASK           0x000000ff
+/* HC_SubA_FogTable        0x0010
+ */
+#define HC_HFPn3_MASK           0xff000000
+#define HC_HFPn2_MASK           0x00ff0000
+#define HC_HFPn1_MASK           0x0000ff00
+#define HC_HFPn_MASK            0x000000ff
+#define HC_HFPn3_SHIFT          24
+#define HC_HFPn2_SHIFT          16
+#define HC_HFPn1_SHIFT          8
+
+/* Auto Testing & Security
+ */
+#define HC_SubA_HenFIFOAT       0x0000
+#define HC_SubA_HFBDrawFirst    0x0004
+#define HC_SubA_HFBBasL         0x0005
+#define HC_SubA_HFBDst          0x0006
+/* HC_SubA_HenFIFOAT       0x0000
+ */
+#define HC_HenFIFOAT_MASK       0x00000020
+#define HC_HenGEMILock_MASK     0x00000010
+#define HC_HenFBASwap_MASK      0x00000008
+#define HC_HenOT_MASK           0x00000004
+#define HC_HenCMDQ_MASK         0x00000002
+#define HC_HenTXCTSU_MASK       0x00000001
+/* HC_SubA_HFBDrawFirst    0x0004
+ */
+#define HC_HFBDrawFirst_MASK    0x00000800
+#define HC_HFBQueue_MASK        0x00000400
+#define HC_HFBLock_MASK         0x00000200
+#define HC_HEOF_MASK            0x00000100
+#define HC_HFBBasH_MASK         0x000000ff
+
+/* GEMI Setting
+ */
+#define HC_SubA_HTArbRCM        0x0008
+#define HC_SubA_HTArbRZ         0x000a
+#define HC_SubA_HTArbWZ         0x000b
+#define HC_SubA_HTArbRTX        0x000c
+#define HC_SubA_HTArbRCW        0x000d
+#define HC_SubA_HTArbE2         0x000e
+#define HC_SubA_HArbRQCM        0x0010
+#define HC_SubA_HArbWQCM        0x0011
+#define HC_SubA_HGEMITout       0x0020
+#define HC_SubA_HFthRTXD        0x0040
+#define HC_SubA_HFthRTXA        0x0044
+#define HC_SubA_HCMDQstL        0x0050
+#define HC_SubA_HCMDQendL       0x0051
+#define HC_SubA_HCMDQLen        0x0052
+/* HC_SubA_HTArbRCM        0x0008
+ */
+#define HC_HTArbRCM_MASK        0x0000ffff
+/* HC_SubA_HTArbRZ         0x000a
+ */
+#define HC_HTArbRZ_MASK         0x0000ffff
+/* HC_SubA_HTArbWZ         0x000b
+ */
+#define HC_HTArbWZ_MASK         0x0000ffff
+/* HC_SubA_HTArbRTX        0x000c
+ */
+#define HC_HTArbRTX_MASK        0x0000ffff
+/* HC_SubA_HTArbRCW        0x000d
+ */
+#define HC_HTArbRCW_MASK        0x0000ffff
+/* HC_SubA_HTArbE2         0x000e
+ */
+#define HC_HTArbE2_MASK         0x0000ffff
+/* HC_SubA_HArbRQCM        0x0010
+ */
+#define HC_HTArbRQCM_MASK       0x0000ffff
+/* HC_SubA_HArbWQCM        0x0011
+ */
+#define HC_HArbWQCM_MASK        0x0000ffff
+/* HC_SubA_HGEMITout       0x0020
+ */
+#define HC_HGEMITout_MASK       0x000f0000
+#define HC_HNPArbZC_MASK        0x0000ffff
+#define HC_HGEMITout_SHIFT      16
+/* HC_SubA_HFthRTXD        0x0040
+ */
+#define HC_HFthRTXD_MASK        0x00ff0000
+#define HC_HFthRZD_MASK         0x0000ff00
+#define HC_HFthWZD_MASK         0x000000ff
+#define HC_HFthRTXD_SHIFT       16
+#define HC_HFthRZD_SHIFT        8
+/* HC_SubA_HFthRTXA        0x0044
+ */
+#define HC_HFthRTXA_MASK        0x000000ff
+
+/******************************************************************************
+** Define the Halcyon Internal register access constants. For simulator only.
+******************************************************************************/
+#define HC_SIMA_HAGPBstL        0x0000
+#define HC_SIMA_HAGPBendL       0x0001
+#define HC_SIMA_HAGPCMNT        0x0002
+#define HC_SIMA_HAGPBpL         0x0003
+#define HC_SIMA_HAGPBpH         0x0004
+#define HC_SIMA_HClipTB         0x0005
+#define HC_SIMA_HClipLR         0x0006
+#define HC_SIMA_HFPClipTL       0x0007
+#define HC_SIMA_HFPClipBL       0x0008
+#define HC_SIMA_HFPClipLL       0x0009
+#define HC_SIMA_HFPClipRL       0x000a
+#define HC_SIMA_HFPClipTBH      0x000b
+#define HC_SIMA_HFPClipLRH      0x000c
+#define HC_SIMA_HLP             0x000d
+#define HC_SIMA_HLPRF           0x000e
+#define HC_SIMA_HSolidCL        0x000f
+#define HC_SIMA_HPixGC          0x0010
+#define HC_SIMA_HSPXYOS         0x0011
+#define HC_SIMA_HCmdA           0x0012
+#define HC_SIMA_HCmdB           0x0013
+#define HC_SIMA_HEnable         0x0014
+#define HC_SIMA_HZWBBasL        0x0015
+#define HC_SIMA_HZWBBasH        0x0016
+#define HC_SIMA_HZWBType        0x0017
+#define HC_SIMA_HZBiasL         0x0018
+#define HC_SIMA_HZWBend         0x0019
+#define HC_SIMA_HZWTMD          0x001a
+#define HC_SIMA_HZWCDL          0x001b
+#define HC_SIMA_HZWCTAGnum      0x001c
+#define HC_SIMA_HZCYNum         0x001d
+#define HC_SIMA_HZWCFire        0x001e
+/* #define HC_SIMA_HSBBasL         0x001d */
+/* #define HC_SIMA_HSBBasH         0x001e */
+/* #define HC_SIMA_HSBFM           0x001f */
+#define HC_SIMA_HSTREF          0x0020
+#define HC_SIMA_HSTMD           0x0021
+#define HC_SIMA_HABBasL         0x0022
+#define HC_SIMA_HABBasH         0x0023
+#define HC_SIMA_HABFM           0x0024
+#define HC_SIMA_HATMD           0x0025
+#define HC_SIMA_HABLCsat        0x0026
+#define HC_SIMA_HABLCop         0x0027
+#define HC_SIMA_HABLAsat        0x0028
+#define HC_SIMA_HABLAop         0x0029
+#define HC_SIMA_HABLRCa         0x002a
+#define HC_SIMA_HABLRFCa        0x002b
+#define HC_SIMA_HABLRCbias      0x002c
+#define HC_SIMA_HABLRCb         0x002d
+#define HC_SIMA_HABLRFCb        0x002e
+#define HC_SIMA_HABLRAa         0x002f
+#define HC_SIMA_HABLRAb         0x0030
+#define HC_SIMA_HDBBasL         0x0031
+#define HC_SIMA_HDBBasH         0x0032
+#define HC_SIMA_HDBFM           0x0033
+#define HC_SIMA_HFBBMSKL        0x0034
+#define HC_SIMA_HROP            0x0035
+#define HC_SIMA_HFogLF          0x0036
+#define HC_SIMA_HFogCL          0x0037
+#define HC_SIMA_HFogCH          0x0038
+#define HC_SIMA_HFogStL         0x0039
+#define HC_SIMA_HFogStH         0x003a
+#define HC_SIMA_HFogOOdMF       0x003b
+#define HC_SIMA_HFogOOdEF       0x003c
+#define HC_SIMA_HFogEndL        0x003d
+#define HC_SIMA_HFogDenst       0x003e
+/*---- start of texture 0 setting ----
+ */
+#define HC_SIMA_HTX0L0BasL      0x0040
+#define HC_SIMA_HTX0L1BasL      0x0041
+#define HC_SIMA_HTX0L2BasL      0x0042
+#define HC_SIMA_HTX0L3BasL      0x0043
+#define HC_SIMA_HTX0L4BasL      0x0044
+#define HC_SIMA_HTX0L5BasL      0x0045
+#define HC_SIMA_HTX0L6BasL      0x0046
+#define HC_SIMA_HTX0L7BasL      0x0047
+#define HC_SIMA_HTX0L8BasL      0x0048
+#define HC_SIMA_HTX0L9BasL      0x0049
+#define HC_SIMA_HTX0LaBasL      0x004a
+#define HC_SIMA_HTX0LbBasL      0x004b
+#define HC_SIMA_HTX0LcBasL      0x004c
+#define HC_SIMA_HTX0LdBasL      0x004d
+#define HC_SIMA_HTX0LeBasL      0x004e
+#define HC_SIMA_HTX0LfBasL      0x004f
+#define HC_SIMA_HTX0L10BasL     0x0050
+#define HC_SIMA_HTX0L11BasL     0x0051
+#define HC_SIMA_HTX0L012BasH    0x0052
+#define HC_SIMA_HTX0L345BasH    0x0053
+#define HC_SIMA_HTX0L678BasH    0x0054
+#define HC_SIMA_HTX0L9abBasH    0x0055
+#define HC_SIMA_HTX0LcdeBasH    0x0056
+#define HC_SIMA_HTX0Lf1011BasH  0x0057
+#define HC_SIMA_HTX0L0Pit       0x0058
+#define HC_SIMA_HTX0L1Pit       0x0059
+#define HC_SIMA_HTX0L2Pit       0x005a
+#define HC_SIMA_HTX0L3Pit       0x005b
+#define HC_SIMA_HTX0L4Pit       0x005c
+#define HC_SIMA_HTX0L5Pit       0x005d
+#define HC_SIMA_HTX0L6Pit       0x005e
+#define HC_SIMA_HTX0L7Pit       0x005f
+#define HC_SIMA_HTX0L8Pit       0x0060
+#define HC_SIMA_HTX0L9Pit       0x0061
+#define HC_SIMA_HTX0LaPit       0x0062
+#define HC_SIMA_HTX0LbPit       0x0063
+#define HC_SIMA_HTX0LcPit       0x0064
+#define HC_SIMA_HTX0LdPit       0x0065
+#define HC_SIMA_HTX0LePit       0x0066
+#define HC_SIMA_HTX0LfPit       0x0067
+#define HC_SIMA_HTX0L10Pit      0x0068
+#define HC_SIMA_HTX0L11Pit      0x0069
+#define HC_SIMA_HTX0L0_5WE      0x006a
+#define HC_SIMA_HTX0L6_bWE      0x006b
+#define HC_SIMA_HTX0Lc_11WE     0x006c
+#define HC_SIMA_HTX0L0_5HE      0x006d
+#define HC_SIMA_HTX0L6_bHE      0x006e
+#define HC_SIMA_HTX0Lc_11HE     0x006f
+#define HC_SIMA_HTX0L0OS        0x0070
+#define HC_SIMA_HTX0TB          0x0071
+#define HC_SIMA_HTX0MPMD        0x0072
+#define HC_SIMA_HTX0CLODu       0x0073
+#define HC_SIMA_HTX0FM          0x0074
+#define HC_SIMA_HTX0TRCH        0x0075
+#define HC_SIMA_HTX0TRCL        0x0076
+#define HC_SIMA_HTX0TBC         0x0077
+#define HC_SIMA_HTX0TRAH        0x0078
+#define HC_SIMA_HTX0TBLCsat     0x0079
+#define HC_SIMA_HTX0TBLCop      0x007a
+#define HC_SIMA_HTX0TBLMPfog    0x007b
+#define HC_SIMA_HTX0TBLAsat     0x007c
+#define HC_SIMA_HTX0TBLRCa      0x007d
+#define HC_SIMA_HTX0TBLRCb      0x007e
+#define HC_SIMA_HTX0TBLRCc      0x007f
+#define HC_SIMA_HTX0TBLRCbias   0x0080
+#define HC_SIMA_HTX0TBLRAa      0x0081
+#define HC_SIMA_HTX0TBLRFog     0x0082
+#define HC_SIMA_HTX0BumpM00     0x0083
+#define HC_SIMA_HTX0BumpM01     0x0084
+#define HC_SIMA_HTX0BumpM10     0x0085
+#define HC_SIMA_HTX0BumpM11     0x0086
+#define HC_SIMA_HTX0LScale      0x0087
+/*---- end of texture 0 setting ----      0x008f
+ */
+#define HC_SIMA_TX0TX1_OFF      0x0050
+/*---- start of texture 1 setting ----
+ */
+#define HC_SIMA_HTX1L0BasL      (HC_SIMA_HTX0L0BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L1BasL      (HC_SIMA_HTX0L1BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L2BasL      (HC_SIMA_HTX0L2BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L3BasL      (HC_SIMA_HTX0L3BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L4BasL      (HC_SIMA_HTX0L4BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L5BasL      (HC_SIMA_HTX0L5BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L6BasL      (HC_SIMA_HTX0L6BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L7BasL      (HC_SIMA_HTX0L7BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L8BasL      (HC_SIMA_HTX0L8BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L9BasL      (HC_SIMA_HTX0L9BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LaBasL      (HC_SIMA_HTX0LaBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LbBasL      (HC_SIMA_HTX0LbBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LcBasL      (HC_SIMA_HTX0LcBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LdBasL      (HC_SIMA_HTX0LdBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LeBasL      (HC_SIMA_HTX0LeBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LfBasL      (HC_SIMA_HTX0LfBasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L10BasL     (HC_SIMA_HTX0L10BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L11BasL     (HC_SIMA_HTX0L11BasL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L012BasH    (HC_SIMA_HTX0L012BasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L345BasH    (HC_SIMA_HTX0L345BasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L678BasH    (HC_SIMA_HTX0L678BasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L9abBasH    (HC_SIMA_HTX0L9abBasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LcdeBasH    (HC_SIMA_HTX0LcdeBasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1Lf1011BasH  (HC_SIMA_HTX0Lf1011BasH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L0Pit       (HC_SIMA_HTX0L0Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L1Pit       (HC_SIMA_HTX0L1Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L2Pit       (HC_SIMA_HTX0L2Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L3Pit       (HC_SIMA_HTX0L3Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L4Pit       (HC_SIMA_HTX0L4Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L5Pit       (HC_SIMA_HTX0L5Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L6Pit       (HC_SIMA_HTX0L6Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L7Pit       (HC_SIMA_HTX0L7Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L8Pit       (HC_SIMA_HTX0L8Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L9Pit       (HC_SIMA_HTX0L9Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LaPit       (HC_SIMA_HTX0LaPit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LbPit       (HC_SIMA_HTX0LbPit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LcPit       (HC_SIMA_HTX0LcPit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LdPit       (HC_SIMA_HTX0LdPit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LePit       (HC_SIMA_HTX0LePit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LfPit       (HC_SIMA_HTX0LfPit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L10Pit      (HC_SIMA_HTX0L10Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L11Pit      (HC_SIMA_HTX0L11Pit + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L0_5WE      (HC_SIMA_HTX0L0_5WE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L6_bWE      (HC_SIMA_HTX0L6_bWE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1Lc_11WE     (HC_SIMA_HTX0Lc_11WE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L0_5HE      (HC_SIMA_HTX0L0_5HE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L6_bHE      (HC_SIMA_HTX0L6_bHE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1Lc_11HE      (HC_SIMA_HTX0Lc_11HE + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1L0OS        (HC_SIMA_HTX0L0OS + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TB          (HC_SIMA_HTX0TB + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1MPMD        (HC_SIMA_HTX0MPMD + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1CLODu       (HC_SIMA_HTX0CLODu + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1FM          (HC_SIMA_HTX0FM + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TRCH        (HC_SIMA_HTX0TRCH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TRCL        (HC_SIMA_HTX0TRCL + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBC         (HC_SIMA_HTX0TBC + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TRAH        (HC_SIMA_HTX0TRAH + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LTC         (HC_SIMA_HTX0LTC + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LTA         (HC_SIMA_HTX0LTA + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLCsat     (HC_SIMA_HTX0TBLCsat + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLCop      (HC_SIMA_HTX0TBLCop + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLMPfog    (HC_SIMA_HTX0TBLMPfog + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLAsat     (HC_SIMA_HTX0TBLAsat + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRCa      (HC_SIMA_HTX0TBLRCa + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRCb      (HC_SIMA_HTX0TBLRCb + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRCc      (HC_SIMA_HTX0TBLRCc + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRCbias   (HC_SIMA_HTX0TBLRCbias + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRAa      (HC_SIMA_HTX0TBLRAa + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1TBLRFog     (HC_SIMA_HTX0TBLRFog + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1BumpM00     (HC_SIMA_HTX0BumpM00 + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1BumpM01     (HC_SIMA_HTX0BumpM01 + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1BumpM10     (HC_SIMA_HTX0BumpM10 + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1BumpM11     (HC_SIMA_HTX0BumpM11 + HC_SIMA_TX0TX1_OFF)
+#define HC_SIMA_HTX1LScale      (HC_SIMA_HTX0LScale + HC_SIMA_TX0TX1_OFF)
+/*---- end of texture 1 setting ---- 0xaf
+ */
+#define HC_SIMA_HTXSMD          0x00b0
+#define HC_SIMA_HenFIFOAT       0x00b1
+#define HC_SIMA_HFBDrawFirst    0x00b2
+#define HC_SIMA_HFBBasL         0x00b3
+#define HC_SIMA_HTArbRCM        0x00b4
+#define HC_SIMA_HTArbRZ         0x00b5
+#define HC_SIMA_HTArbWZ         0x00b6
+#define HC_SIMA_HTArbRTX        0x00b7
+#define HC_SIMA_HTArbRCW        0x00b8
+#define HC_SIMA_HTArbE2         0x00b9
+#define HC_SIMA_HGEMITout       0x00ba
+#define HC_SIMA_HFthRTXD        0x00bb
+#define HC_SIMA_HFthRTXA        0x00bc
+/* Define the texture palette 0
+ */
+#define HC_SIMA_HTP0            0x0100
+#define HC_SIMA_HTP1            0x0200
+#define HC_SIMA_FOGTABLE        0x0300
+#define HC_SIMA_STIPPLE         0x0400
+#define HC_SIMA_HE3Fire         0x0440
+#define HC_SIMA_TRANS_SET       0x0441
+#define HC_SIMA_HREngSt         0x0442
+#define HC_SIMA_HRFIFOempty     0x0443
+#define HC_SIMA_HRFIFOfull      0x0444
+#define HC_SIMA_HRErr           0x0445
+#define HC_SIMA_FIFOstatus      0x0446
+
+/******************************************************************************
+** Define the AGP command header.
+******************************************************************************/
+#define HC_ACMD_MASK            0xfe000000
+#define HC_ACMD_SUB_MASK        0x0c000000
+#define HC_ACMD_HCmdA           0xee000000
+#define HC_ACMD_HCmdB           0xec000000
+#define HC_ACMD_HCmdC           0xea000000
+#define HC_ACMD_H1              0xf0000000
+#define HC_ACMD_H2              0xf2000000
+#define HC_ACMD_H3              0xf4000000
+#define HC_ACMD_H4              0xf6000000
+
+#define HC_ACMD_H1IO_MASK       0x000001ff
+#define HC_ACMD_H2IO1_MASK      0x001ff000
+#define HC_ACMD_H2IO2_MASK      0x000001ff
+#define HC_ACMD_H2IO1_SHIFT     12
+#define HC_ACMD_H2IO2_SHIFT     0
+#define HC_ACMD_H3IO_MASK       0x000001ff
+#define HC_ACMD_H3COUNT_MASK    0x01fff000
+#define HC_ACMD_H3COUNT_SHIFT   12
+#define HC_ACMD_H4ID_MASK       0x000001ff
+#define HC_ACMD_H4COUNT_MASK    0x01fffe00
+#define HC_ACMD_H4COUNT_SHIFT   9
+
+/********************************************************************************
+** Define Header
+********************************************************************************/
+#define HC_HEADER2             0xF210F110
+
+/********************************************************************************
+** Define Dummy Value
+********************************************************************************/
+#define HC_DUMMY               0xCCCCCCCC
+/********************************************************************************
+** Define for DMA use
+********************************************************************************/
+#define HALCYON_HEADER2     0XF210F110
+#define HALCYON_FIRECMD     0XEE100000
+#define HALCYON_FIREMASK    0XFFF00000
+#define HALCYON_CMDB        0XEC000000
+#define HALCYON_CMDBMASK    0XFFFE0000
+#define HALCYON_SUB_ADDR0   0X00000000
+#define HALCYON_HEADER1MASK 0XFFFFFC00
+#define HALCYON_HEADER1     0XF0000000
+#define HC_SubA_HAGPBstL        0x0060
+#define HC_SubA_HAGPBendL       0x0061
+#define HC_SubA_HAGPCMNT        0x0062
+#define HC_SubA_HAGPBpL         0x0063
+#define HC_SubA_HAGPBpH         0x0064
+#define HC_HAGPCMNT_MASK        0x00800000
+#define HC_HCmdErrClr_MASK      0x00400000
+#define HC_HAGPBendH_MASK       0x0000ff00
+#define HC_HAGPBstH_MASK        0x000000ff
+#define HC_HAGPBendH_SHIFT      8
+#define HC_HAGPBstH_SHIFT       0
+#define HC_HAGPBpL_MASK         0x00fffffc
+#define HC_HAGPBpID_MASK        0x00000003
+#define HC_HAGPBpID_PAUSE       0x00000000
+#define HC_HAGPBpID_JUMP        0x00000001
+#define HC_HAGPBpID_STOP        0x00000002
+#define HC_HAGPBpH_MASK         0x00ffffff
+
+#define VIA_VIDEO_HEADER5       0xFE040000
+#define VIA_VIDEO_HEADER6       0xFE050000
+#define VIA_VIDEO_HEADER7       0xFE060000
+#define VIA_VIDEOMASK           0xFFFF0000
+#endif
diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
new file mode 100644 (file)
index 0000000..7a339db
--- /dev/null
@@ -0,0 +1,755 @@
+/* via_dma.c -- DMA support for the VIA Unichrome/Pro
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Copyright 2004 Digeo, Inc., Palo Alto, CA, U.S.A.
+ * All Rights Reserved.
+ *
+ * Copyright 2004 The Unichrome project.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Tungsten Graphics,
+ *    Erdi Chen,
+ *    Thomas Hellstrom.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "via_drm.h"
+#include "via_drv.h"
+#include "via_3d_reg.h"
+
+#define CMDBUF_ALIGNMENT_SIZE   (0x100)
+#define CMDBUF_ALIGNMENT_MASK   (0x0ff)
+
+/* defines for VIA 3D registers */
+#define VIA_REG_STATUS          0x400
+#define VIA_REG_TRANSET         0x43C
+#define VIA_REG_TRANSPACE       0x440
+
+/* VIA_REG_STATUS(0x400): Engine Status */
+#define VIA_CMD_RGTR_BUSY       0x00000080     /* Command Regulator is busy */
+#define VIA_2D_ENG_BUSY         0x00000001     /* 2D Engine is busy */
+#define VIA_3D_ENG_BUSY         0x00000002     /* 3D Engine is busy */
+#define VIA_VR_QUEUE_BUSY       0x00020000     /* Virtual Queue is busy */
+
+#define SetReg2DAGP(nReg, nData) {                             \
+       *((uint32_t *)(vb)) = ((nReg) >> 2) | HALCYON_HEADER1;  \
+       *((uint32_t *)(vb) + 1) = (nData);                      \
+       vb = ((uint32_t *)vb) + 2;                              \
+       dev_priv->dma_low +=8;                                  \
+}
+
+#define via_flush_write_combine() DRM_MEMORYBARRIER()
+
+#define VIA_OUT_RING_QW(w1,w2)                 \
+       *vb++ = (w1);                           \
+       *vb++ = (w2);                           \
+       dev_priv->dma_low += 8;
+
+static void via_cmdbuf_start(drm_via_private_t * dev_priv);
+static void via_cmdbuf_pause(drm_via_private_t * dev_priv);
+static void via_cmdbuf_reset(drm_via_private_t * dev_priv);
+static void via_cmdbuf_rewind(drm_via_private_t * dev_priv);
+static int via_wait_idle(drm_via_private_t * dev_priv);
+static void via_pad_cache(drm_via_private_t * dev_priv, int qwords);
+
+/*
+ * Free space in command buffer.
+ */
+
+static uint32_t via_cmdbuf_space(drm_via_private_t * dev_priv)
+{
+       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
+
+       return ((hw_addr <= dev_priv->dma_low) ?
+               (dev_priv->dma_high + hw_addr - dev_priv->dma_low) :
+               (hw_addr - dev_priv->dma_low));
+}
+
+/*
+ * How much does the command regulator lag behind?
+ */
+
+static uint32_t via_cmdbuf_lag(drm_via_private_t * dev_priv)
+{
+       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
+
+       return ((hw_addr <= dev_priv->dma_low) ?
+               (dev_priv->dma_low - hw_addr) :
+               (dev_priv->dma_wrap + dev_priv->dma_low - hw_addr));
+}
+
+/*
+ * Check that the given size fits in the buffer, otherwise wait.
+ */
+
+static inline int
+via_cmdbuf_wait(drm_via_private_t * dev_priv, unsigned int size)
+{
+       uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       uint32_t cur_addr, hw_addr, next_addr;
+       volatile uint32_t *hw_addr_ptr;
+       uint32_t count;
+       hw_addr_ptr = dev_priv->hw_addr_ptr;
+       cur_addr = dev_priv->dma_low;
+       next_addr = cur_addr + size + 512 * 1024;
+       count = 1000000;
+       do {
+               hw_addr = *hw_addr_ptr - agp_base;
+               if (count-- == 0) {
+                       DRM_ERROR
+                           ("via_cmdbuf_wait timed out hw %x cur_addr %x next_addr %x\n",
+                            hw_addr, cur_addr, next_addr);
+                       return -1;
+               }
+               if  ((cur_addr < hw_addr) && (next_addr >= hw_addr))
+                       msleep(1);
+       } while ((cur_addr < hw_addr) && (next_addr >= hw_addr));
+       return 0;
+}
+
+/*
+ * Checks whether buffer head has reach the end. Rewind the ring buffer
+ * when necessary.
+ *
+ * Returns virtual pointer to ring buffer.
+ */
+
+static inline uint32_t *via_check_dma(drm_via_private_t * dev_priv,
+                                     unsigned int size)
+{
+       if ((dev_priv->dma_low + size + 4 * CMDBUF_ALIGNMENT_SIZE) >
+           dev_priv->dma_high) {
+               via_cmdbuf_rewind(dev_priv);
+       }
+       if (via_cmdbuf_wait(dev_priv, size) != 0) {
+               return NULL;
+       }
+
+       return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
+}
+
+int via_dma_cleanup(struct drm_device * dev)
+{
+       if (dev->dev_private) {
+               drm_via_private_t *dev_priv =
+                   (drm_via_private_t *) dev->dev_private;
+
+               if (dev_priv->ring.virtual_start) {
+                       via_cmdbuf_reset(dev_priv);
+
+                       drm_core_ioremapfree(&dev_priv->ring.map, dev);
+                       dev_priv->ring.virtual_start = NULL;
+               }
+
+       }
+
+       return 0;
+}
+
+static int via_initialize(struct drm_device * dev,
+                         drm_via_private_t * dev_priv,
+                         drm_via_dma_init_t * init)
+{
+       if (!dev_priv || !dev_priv->mmio) {
+               DRM_ERROR("via_dma_init called before via_map_init\n");
+               return -EFAULT;
+       }
+
+       if (dev_priv->ring.virtual_start != NULL) {
+               DRM_ERROR("called again without calling cleanup\n");
+               return -EFAULT;
+       }
+
+       if (!dev->agp || !dev->agp->base) {
+               DRM_ERROR("called with no agp memory available\n");
+               return -EFAULT;
+       }
+
+       if (dev_priv->chipset == VIA_DX9_0) {
+               DRM_ERROR("AGP DMA is not supported on this chip\n");
+               return -EINVAL;
+       }
+
+       dev_priv->ring.map.offset = dev->agp->base + init->offset;
+       dev_priv->ring.map.size = init->size;
+       dev_priv->ring.map.type = 0;
+       dev_priv->ring.map.flags = 0;
+       dev_priv->ring.map.mtrr = 0;
+
+       drm_core_ioremap(&dev_priv->ring.map, dev);
+
+       if (dev_priv->ring.map.handle == NULL) {
+               via_dma_cleanup(dev);
+               DRM_ERROR("can not ioremap virtual address for"
+                         " ring buffer\n");
+               return -ENOMEM;
+       }
+
+       dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
+
+       dev_priv->dma_ptr = dev_priv->ring.virtual_start;
+       dev_priv->dma_low = 0;
+       dev_priv->dma_high = init->size;
+       dev_priv->dma_wrap = init->size;
+       dev_priv->dma_offset = init->offset;
+       dev_priv->last_pause_ptr = NULL;
+       dev_priv->hw_addr_ptr =
+               (volatile uint32_t *)((char *)dev_priv->mmio->handle +
+               init->reg_pause_addr);
+
+       via_cmdbuf_start(dev_priv);
+
+       return 0;
+}
+
+static int via_dma_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       drm_via_dma_init_t *init = data;
+       int retcode = 0;
+
+       switch (init->func) {
+       case VIA_INIT_DMA:
+               if (!DRM_SUSER(DRM_CURPROC))
+                       retcode = -EPERM;
+               else
+                       retcode = via_initialize(dev, dev_priv, init);
+               break;
+       case VIA_CLEANUP_DMA:
+               if (!DRM_SUSER(DRM_CURPROC))
+                       retcode = -EPERM;
+               else
+                       retcode = via_dma_cleanup(dev);
+               break;
+       case VIA_DMA_INITIALIZED:
+               retcode = (dev_priv->ring.virtual_start != NULL) ?
+                       0 : -EFAULT;
+               break;
+       default:
+               retcode = -EINVAL;
+               break;
+       }
+
+       return retcode;
+}
+
+static int via_dispatch_cmdbuffer(struct drm_device * dev, drm_via_cmdbuffer_t * cmd)
+{
+       drm_via_private_t *dev_priv;
+       uint32_t *vb;
+       int ret;
+
+       dev_priv = (drm_via_private_t *) dev->dev_private;
+
+       if (dev_priv->ring.virtual_start == NULL) {
+               DRM_ERROR("called without initializing AGP ring buffer.\n");
+               return -EFAULT;
+       }
+
+       if (cmd->size > VIA_PCI_BUF_SIZE) {
+               return -ENOMEM;
+       }
+
+       if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
+               return -EFAULT;
+
+       /*
+        * Running this function on AGP memory is dead slow. Therefore
+        * we run it on a temporary cacheable system memory buffer and
+        * copy it to AGP memory when ready.
+        */
+
+       if ((ret =
+            via_verify_command_stream((uint32_t *) dev_priv->pci_buf,
+                                      cmd->size, dev, 1))) {
+               return ret;
+       }
+
+       vb = via_check_dma(dev_priv, (cmd->size < 0x100) ? 0x102 : cmd->size);
+       if (vb == NULL) {
+               return -EAGAIN;
+       }
+
+       memcpy(vb, dev_priv->pci_buf, cmd->size);
+
+       dev_priv->dma_low += cmd->size;
+
+       /*
+        * Small submissions somehow stalls the CPU. (AGP cache effects?)
+        * pad to greater size.
+        */
+
+       if (cmd->size < 0x100)
+               via_pad_cache(dev_priv, (0x100 - cmd->size) >> 3);
+       via_cmdbuf_pause(dev_priv);
+
+       return 0;
+}
+
+int via_driver_dma_quiescent(struct drm_device * dev)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+
+       if (!via_wait_idle(dev_priv)) {
+               return -EBUSY;
+       }
+       return 0;
+}
+
+static int via_flush_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       return via_driver_dma_quiescent(dev);
+}
+
+static int via_cmdbuffer(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_cmdbuffer_t *cmdbuf = data;
+       int ret;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("buf %p size %lu\n", cmdbuf->buf, cmdbuf->size);
+
+       ret = via_dispatch_cmdbuffer(dev, cmdbuf);
+       if (ret) {
+               return ret;
+       }
+
+       return 0;
+}
+
+static int via_dispatch_pci_cmdbuffer(struct drm_device * dev,
+                                     drm_via_cmdbuffer_t * cmd)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+       int ret;
+
+       if (cmd->size > VIA_PCI_BUF_SIZE) {
+               return -ENOMEM;
+       }
+       if (DRM_COPY_FROM_USER(dev_priv->pci_buf, cmd->buf, cmd->size))
+               return -EFAULT;
+
+       if ((ret =
+            via_verify_command_stream((uint32_t *) dev_priv->pci_buf,
+                                      cmd->size, dev, 0))) {
+               return ret;
+       }
+
+       ret =
+           via_parse_command_stream(dev, (const uint32_t *)dev_priv->pci_buf,
+                                    cmd->size);
+       return ret;
+}
+
+static int via_pci_cmdbuffer(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_cmdbuffer_t *cmdbuf = data;
+       int ret;
+
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       DRM_DEBUG("buf %p size %lu\n", cmdbuf->buf, cmdbuf->size);
+
+       ret = via_dispatch_pci_cmdbuffer(dev, cmdbuf);
+       if (ret) {
+               return ret;
+       }
+
+       return 0;
+}
+
+static inline uint32_t *via_align_buffer(drm_via_private_t * dev_priv,
+                                        uint32_t * vb, int qw_count)
+{
+       for (; qw_count > 0; --qw_count) {
+               VIA_OUT_RING_QW(HC_DUMMY, HC_DUMMY);
+       }
+       return vb;
+}
+
+/*
+ * This function is used internally by ring buffer management code.
+ *
+ * Returns virtual pointer to ring buffer.
+ */
+static inline uint32_t *via_get_dma(drm_via_private_t * dev_priv)
+{
+       return (uint32_t *) (dev_priv->dma_ptr + dev_priv->dma_low);
+}
+
+/*
+ * Hooks a segment of data into the tail of the ring-buffer by
+ * modifying the pause address stored in the buffer itself. If
+ * the regulator has already paused, restart it.
+ */
+static int via_hook_segment(drm_via_private_t * dev_priv,
+                           uint32_t pause_addr_hi, uint32_t pause_addr_lo,
+                           int no_pci_fire)
+{
+       int paused, count;
+       volatile uint32_t *paused_at = dev_priv->last_pause_ptr;
+       uint32_t reader,ptr;
+       uint32_t diff;
+
+       paused = 0;
+       via_flush_write_combine();
+       (void) *(volatile uint32_t *)(via_get_dma(dev_priv) -1);
+
+       *paused_at = pause_addr_lo;
+       via_flush_write_combine();
+       (void) *paused_at;
+
+       reader = *(dev_priv->hw_addr_ptr);
+       ptr = ((volatile char *)paused_at - dev_priv->dma_ptr) +
+               dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
+
+       dev_priv->last_pause_ptr = via_get_dma(dev_priv) - 1;
+
+       /*
+        * If there is a possibility that the command reader will 
+        * miss the new pause address and pause on the old one,
+        * In that case we need to program the new start address
+        * using PCI.
+        */
+
+       diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
+       count = 10000000;
+       while(diff == 0 && count--) {
+               paused = (VIA_READ(0x41c) & 0x80000000);
+               if (paused) 
+                       break;
+               reader = *(dev_priv->hw_addr_ptr);
+               diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
+       }
+
+       paused = VIA_READ(0x41c) & 0x80000000;
+
+       if (paused && !no_pci_fire) {
+               reader = *(dev_priv->hw_addr_ptr);
+               diff = (uint32_t) (ptr - reader) - dev_priv->dma_diff;
+               diff &= (dev_priv->dma_high - 1);
+               if (diff != 0 && diff < (dev_priv->dma_high >> 1)) {
+                       DRM_ERROR("Paused at incorrect address. "
+                                 "0x%08x, 0x%08x 0x%08x\n",
+                                 ptr, reader, dev_priv->dma_diff);
+               } else if (diff == 0) {
+                       /*
+                        * There is a concern that these writes may stall the PCI bus
+                        * if the GPU is not idle. However, idling the GPU first
+                        * doesn't make a difference.
+                        */
+
+                       VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
+                       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
+                       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
+                       VIA_READ(VIA_REG_TRANSPACE);
+               }
+       }
+       return paused;
+}
+
+static int via_wait_idle(drm_via_private_t * dev_priv)
+{
+       int count = 10000000;
+
+       while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
+
+       while (count-- && (VIA_READ(VIA_REG_STATUS) &
+                          (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
+                           VIA_3D_ENG_BUSY))) ;
+       return count;
+}
+
+static uint32_t *via_align_cmd(drm_via_private_t * dev_priv, uint32_t cmd_type,
+                              uint32_t addr, uint32_t * cmd_addr_hi,
+                              uint32_t * cmd_addr_lo, int skip_wait)
+{
+       uint32_t agp_base;
+       uint32_t cmd_addr, addr_lo, addr_hi;
+       uint32_t *vb;
+       uint32_t qw_pad_count;
+
+       if (!skip_wait)
+               via_cmdbuf_wait(dev_priv, 2 * CMDBUF_ALIGNMENT_SIZE);
+
+       vb = via_get_dma(dev_priv);
+       VIA_OUT_RING_QW(HC_HEADER2 | ((VIA_REG_TRANSET >> 2) << 12) |
+                       (VIA_REG_TRANSPACE >> 2), HC_ParaType_PreCR << 16);
+       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       qw_pad_count = (CMDBUF_ALIGNMENT_SIZE >> 3) -
+           ((dev_priv->dma_low & CMDBUF_ALIGNMENT_MASK) >> 3);
+
+       cmd_addr = (addr) ? addr :
+           agp_base + dev_priv->dma_low - 8 + (qw_pad_count << 3);
+       addr_lo = ((HC_SubA_HAGPBpL << 24) | (cmd_type & HC_HAGPBpID_MASK) |
+                  (cmd_addr & HC_HAGPBpL_MASK));
+       addr_hi = ((HC_SubA_HAGPBpH << 24) | (cmd_addr >> 24));
+
+       vb = via_align_buffer(dev_priv, vb, qw_pad_count - 1);
+       VIA_OUT_RING_QW(*cmd_addr_hi = addr_hi, *cmd_addr_lo = addr_lo);
+       return vb;
+}
+
+static void via_cmdbuf_start(drm_via_private_t * dev_priv)
+{
+       uint32_t pause_addr_lo, pause_addr_hi;
+       uint32_t start_addr, start_addr_lo;
+       uint32_t end_addr, end_addr_lo;
+       uint32_t command;
+       uint32_t agp_base;
+       uint32_t ptr;
+       uint32_t reader;
+       int count;
+
+       dev_priv->dma_low = 0;
+
+       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       start_addr = agp_base;
+       end_addr = agp_base + dev_priv->dma_high;
+
+       start_addr_lo = ((HC_SubA_HAGPBstL << 24) | (start_addr & 0xFFFFFF));
+       end_addr_lo = ((HC_SubA_HAGPBendL << 24) | (end_addr & 0xFFFFFF));
+       command = ((HC_SubA_HAGPCMNT << 24) | (start_addr >> 24) |
+                  ((end_addr & 0xff000000) >> 16));
+
+       dev_priv->last_pause_ptr =
+           via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0,
+                         &pause_addr_hi, &pause_addr_lo, 1) - 1;
+
+       via_flush_write_combine();
+       (void) *(volatile uint32_t *)dev_priv->last_pause_ptr;
+
+       VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
+       VIA_WRITE(VIA_REG_TRANSPACE, command);
+       VIA_WRITE(VIA_REG_TRANSPACE, start_addr_lo);
+       VIA_WRITE(VIA_REG_TRANSPACE, end_addr_lo);
+
+       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
+       VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
+       DRM_WRITEMEMORYBARRIER();
+       VIA_WRITE(VIA_REG_TRANSPACE, command | HC_HAGPCMNT_MASK);
+       VIA_READ(VIA_REG_TRANSPACE);
+
+       dev_priv->dma_diff = 0;
+
+       count = 10000000;
+       while (!(VIA_READ(0x41c) & 0x80000000) && count--);
+
+       reader = *(dev_priv->hw_addr_ptr);
+       ptr = ((volatile char *)dev_priv->last_pause_ptr - dev_priv->dma_ptr) +
+           dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
+
+       /*
+        * This is the difference between where we tell the
+        * command reader to pause and where it actually pauses.
+        * This differs between hw implementation so we need to
+        * detect it.
+        */
+
+       dev_priv->dma_diff = ptr - reader;
+}
+
+static void via_pad_cache(drm_via_private_t * dev_priv, int qwords)
+{
+       uint32_t *vb;
+
+       via_cmdbuf_wait(dev_priv, qwords + 2);
+       vb = via_get_dma(dev_priv);
+       VIA_OUT_RING_QW(HC_HEADER2, HC_ParaType_NotTex << 16);
+       via_align_buffer(dev_priv, vb, qwords);
+}
+
+static inline void via_dummy_bitblt(drm_via_private_t * dev_priv)
+{
+       uint32_t *vb = via_get_dma(dev_priv);
+       SetReg2DAGP(0x0C, (0 | (0 << 16)));
+       SetReg2DAGP(0x10, 0 | (0 << 16));
+       SetReg2DAGP(0x0, 0x1 | 0x2000 | 0xAA000000);
+}
+
+static void via_cmdbuf_jump(drm_via_private_t * dev_priv)
+{
+       uint32_t agp_base;
+       uint32_t pause_addr_lo, pause_addr_hi;
+       uint32_t jump_addr_lo, jump_addr_hi;
+       volatile uint32_t *last_pause_ptr;
+       uint32_t dma_low_save1, dma_low_save2;
+
+       agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
+       via_align_cmd(dev_priv, HC_HAGPBpID_JUMP, 0, &jump_addr_hi,
+                     &jump_addr_lo, 0);
+
+       dev_priv->dma_wrap = dev_priv->dma_low;
+
+       /*
+        * Wrap command buffer to the beginning.
+        */
+
+       dev_priv->dma_low = 0;
+       if (via_cmdbuf_wait(dev_priv, CMDBUF_ALIGNMENT_SIZE) != 0) {
+               DRM_ERROR("via_cmdbuf_jump failed\n");
+       }
+
+       via_dummy_bitblt(dev_priv);
+       via_dummy_bitblt(dev_priv);
+
+       last_pause_ptr =
+           via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
+                         &pause_addr_lo, 0) - 1;
+       via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
+                     &pause_addr_lo, 0);
+
+       *last_pause_ptr = pause_addr_lo;
+       dma_low_save1 = dev_priv->dma_low;
+
+       /*
+        * Now, set a trap that will pause the regulator if it tries to rerun the old
+        * command buffer. (Which may happen if via_hook_segment detecs a command regulator pause
+        * and reissues the jump command over PCI, while the regulator has already taken the jump
+        * and actually paused at the current buffer end).
+        * There appears to be no other way to detect this condition, since the hw_addr_pointer
+        * does not seem to get updated immediately when a jump occurs.
+        */
+
+       last_pause_ptr =
+               via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
+                             &pause_addr_lo, 0) - 1;
+       via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
+                     &pause_addr_lo, 0);
+       *last_pause_ptr = pause_addr_lo;
+
+       dma_low_save2 = dev_priv->dma_low;
+       dev_priv->dma_low = dma_low_save1;
+       via_hook_segment(dev_priv, jump_addr_hi, jump_addr_lo, 0);
+       dev_priv->dma_low = dma_low_save2;
+       via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
+}
+
+
+static void via_cmdbuf_rewind(drm_via_private_t * dev_priv)
+{
+       via_cmdbuf_jump(dev_priv);
+}
+
+static void via_cmdbuf_flush(drm_via_private_t * dev_priv, uint32_t cmd_type)
+{
+       uint32_t pause_addr_lo, pause_addr_hi;
+
+       via_align_cmd(dev_priv, cmd_type, 0, &pause_addr_hi, &pause_addr_lo, 0);
+       via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
+}
+
+static void via_cmdbuf_pause(drm_via_private_t * dev_priv)
+{
+       via_cmdbuf_flush(dev_priv, HC_HAGPBpID_PAUSE);
+}
+
+static void via_cmdbuf_reset(drm_via_private_t * dev_priv)
+{
+       via_cmdbuf_flush(dev_priv, HC_HAGPBpID_STOP);
+       via_wait_idle(dev_priv);
+}
+
+/*
+ * User interface to the space and lag functions.
+ */
+
+static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_cmdbuf_size_t *d_siz = data;
+       int ret = 0;
+       uint32_t tmp_size, count;
+       drm_via_private_t *dev_priv;
+
+       DRM_DEBUG("\n");
+       LOCK_TEST_WITH_RETURN(dev, file_priv);
+
+       dev_priv = (drm_via_private_t *) dev->dev_private;
+
+       if (dev_priv->ring.virtual_start == NULL) {
+               DRM_ERROR("called without initializing AGP ring buffer.\n");
+               return -EFAULT;
+       }
+
+       count = 1000000;
+       tmp_size = d_siz->size;
+       switch (d_siz->func) {
+       case VIA_CMDBUF_SPACE:
+               while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
+                      && count--) {
+                       if (!d_siz->wait) {
+                               break;
+                       }
+               }
+               if (!count) {
+                       DRM_ERROR("VIA_CMDBUF_SPACE timed out.\n");
+                       ret = -EAGAIN;
+               }
+               break;
+       case VIA_CMDBUF_LAG:
+               while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
+                      && count--) {
+                       if (!d_siz->wait) {
+                               break;
+                       }
+               }
+               if (!count) {
+                       DRM_ERROR("VIA_CMDBUF_LAG timed out.\n");
+                       ret = -EAGAIN;
+               }
+               break;
+       default:
+               ret = -EFAULT;
+       }
+       d_siz->size = tmp_size;
+
+       return ret;
+}
+
+struct drm_ioctl_desc via_ioctls[] = {
+       DRM_IOCTL_DEF(DRM_VIA_ALLOCMEM, via_mem_alloc, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_FREEMEM, via_mem_free, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_AGP_INIT, via_agp_init, DRM_AUTH|DRM_MASTER),
+       DRM_IOCTL_DEF(DRM_VIA_FB_INIT, via_fb_init, DRM_AUTH|DRM_MASTER),
+       DRM_IOCTL_DEF(DRM_VIA_MAP_INIT, via_map_init, DRM_AUTH|DRM_MASTER),
+       DRM_IOCTL_DEF(DRM_VIA_DEC_FUTEX, via_decoder_futex, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_DMA_INIT, via_dma_init, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_CMDBUFFER, via_cmdbuffer, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_FLUSH, via_flush_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_PCICMD, via_pci_cmdbuffer, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_CMDBUF_SIZE, via_cmdbuf_size, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_WAIT_IRQ, via_wait_irq, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_DMA_BLIT, via_dma_blit, DRM_AUTH),
+       DRM_IOCTL_DEF(DRM_VIA_BLIT_SYNC, via_dma_blit_sync, DRM_AUTH)
+};
+
+int via_max_ioctl = DRM_ARRAY_SIZE(via_ioctls);
diff --git a/drivers/gpu/drm/via/via_dmablit.c b/drivers/gpu/drm/via/via_dmablit.c
new file mode 100644 (file)
index 0000000..409e00a
--- /dev/null
@@ -0,0 +1,816 @@
+/* via_dmablit.c -- PCI DMA BitBlt support for the VIA Unichrome/Pro
+ *
+ * Copyright (C) 2005 Thomas Hellstrom, All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Thomas Hellstrom.
+ *    Partially based on code obtained from Digeo Inc.
+ */
+
+
+/*
+ * Unmaps the DMA mappings.
+ * FIXME: Is this a NoOp on x86? Also
+ * FIXME: What happens if this one is called and a pending blit has previously done
+ * the same DMA mappings?
+ */
+
+#include "drmP.h"
+#include "via_drm.h"
+#include "via_drv.h"
+#include "via_dmablit.h"
+
+#include <linux/pagemap.h>
+
+#define VIA_PGDN(x)         (((unsigned long)(x)) & PAGE_MASK)
+#define VIA_PGOFF(x)       (((unsigned long)(x)) & ~PAGE_MASK)
+#define VIA_PFN(x)           ((unsigned long)(x) >> PAGE_SHIFT)
+
+typedef struct _drm_via_descriptor {
+       uint32_t mem_addr;
+       uint32_t dev_addr;
+       uint32_t size;
+       uint32_t next;
+} drm_via_descriptor_t;
+
+
+/*
+ * Unmap a DMA mapping.
+ */
+
+
+
+static void
+via_unmap_blit_from_device(struct pci_dev *pdev, drm_via_sg_info_t *vsg)
+{
+       int num_desc = vsg->num_desc;
+       unsigned cur_descriptor_page = num_desc / vsg->descriptors_per_page;
+       unsigned descriptor_this_page = num_desc % vsg->descriptors_per_page;
+       drm_via_descriptor_t *desc_ptr = vsg->desc_pages[cur_descriptor_page] +
+               descriptor_this_page;
+       dma_addr_t next = vsg->chain_start;
+
+       while(num_desc--) {
+               if (descriptor_this_page-- == 0) {
+                       cur_descriptor_page--;
+                       descriptor_this_page = vsg->descriptors_per_page - 1;
+                       desc_ptr = vsg->desc_pages[cur_descriptor_page] +
+                               descriptor_this_page;
+               }
+               dma_unmap_single(&pdev->dev, next, sizeof(*desc_ptr), DMA_TO_DEVICE);
+               dma_unmap_page(&pdev->dev, desc_ptr->mem_addr, desc_ptr->size, vsg->direction);
+               next = (dma_addr_t) desc_ptr->next;
+               desc_ptr--;
+       }
+}
+
+/*
+ * If mode = 0, count how many descriptors are needed.
+ * If mode = 1, Map the DMA pages for the device, put together and map also the descriptors.
+ * Descriptors are run in reverse order by the hardware because we are not allowed to update the
+ * 'next' field without syncing calls when the descriptor is already mapped.
+ */
+
+static void
+via_map_blit_for_device(struct pci_dev *pdev,
+                  const drm_via_dmablit_t *xfer,
+                  drm_via_sg_info_t *vsg,
+                  int mode)
+{
+       unsigned cur_descriptor_page = 0;
+       unsigned num_descriptors_this_page = 0;
+       unsigned char *mem_addr = xfer->mem_addr;
+       unsigned char *cur_mem;
+       unsigned char *first_addr = (unsigned char *)VIA_PGDN(mem_addr);
+       uint32_t fb_addr = xfer->fb_addr;
+       uint32_t cur_fb;
+       unsigned long line_len;
+       unsigned remaining_len;
+       int num_desc = 0;
+       int cur_line;
+       dma_addr_t next = 0 | VIA_DMA_DPR_EC;
+       drm_via_descriptor_t *desc_ptr = NULL;
+
+       if (mode == 1)
+               desc_ptr = vsg->desc_pages[cur_descriptor_page];
+
+       for (cur_line = 0; cur_line < xfer->num_lines; ++cur_line) {
+
+               line_len = xfer->line_length;
+               cur_fb = fb_addr;
+               cur_mem = mem_addr;
+
+               while (line_len > 0) {
+
+                       remaining_len = min(PAGE_SIZE-VIA_PGOFF(cur_mem), line_len);
+                       line_len -= remaining_len;
+
+                       if (mode == 1) {
+                               desc_ptr->mem_addr =
+                                       dma_map_page(&pdev->dev,
+                                                    vsg->pages[VIA_PFN(cur_mem) -
+                                                               VIA_PFN(first_addr)],
+                                                    VIA_PGOFF(cur_mem), remaining_len,
+                                                    vsg->direction);
+                               desc_ptr->dev_addr = cur_fb;
+
+                               desc_ptr->size = remaining_len;
+                               desc_ptr->next = (uint32_t) next;
+                               next = dma_map_single(&pdev->dev, desc_ptr, sizeof(*desc_ptr),
+                                                     DMA_TO_DEVICE);
+                               desc_ptr++;
+                               if (++num_descriptors_this_page >= vsg->descriptors_per_page) {
+                                       num_descriptors_this_page = 0;
+                                       desc_ptr = vsg->desc_pages[++cur_descriptor_page];
+                               }
+                       }
+
+                       num_desc++;
+                       cur_mem += remaining_len;
+                       cur_fb += remaining_len;
+               }
+
+               mem_addr += xfer->mem_stride;
+               fb_addr += xfer->fb_stride;
+       }
+
+       if (mode == 1) {
+               vsg->chain_start = next;
+               vsg->state = dr_via_device_mapped;
+       }
+       vsg->num_desc = num_desc;
+}
+
+/*
+ * Function that frees up all resources for a blit. It is usable even if the
+ * blit info has only been partially built as long as the status enum is consistent
+ * with the actual status of the used resources.
+ */
+
+
+static void
+via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg)
+{
+       struct page *page;
+       int i;
+
+       switch(vsg->state) {
+       case dr_via_device_mapped:
+               via_unmap_blit_from_device(pdev, vsg);
+       case dr_via_desc_pages_alloc:
+               for (i=0; i<vsg->num_desc_pages; ++i) {
+                       if (vsg->desc_pages[i] != NULL)
+                         free_page((unsigned long)vsg->desc_pages[i]);
+               }
+               kfree(vsg->desc_pages);
+       case dr_via_pages_locked:
+               for (i=0; i<vsg->num_pages; ++i) {
+                       if ( NULL != (page = vsg->pages[i])) {
+                               if (! PageReserved(page) && (DMA_FROM_DEVICE == vsg->direction))
+                                       SetPageDirty(page);
+                               page_cache_release(page);
+                       }
+               }
+       case dr_via_pages_alloc:
+               vfree(vsg->pages);
+       default:
+               vsg->state = dr_via_sg_init;
+       }
+       if (vsg->bounce_buffer) {
+               vfree(vsg->bounce_buffer);
+               vsg->bounce_buffer = NULL;
+       }
+       vsg->free_on_sequence = 0;
+}
+
+/*
+ * Fire a blit engine.
+ */
+
+static void
+via_fire_dmablit(struct drm_device *dev, drm_via_sg_info_t *vsg, int engine)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+
+       VIA_WRITE(VIA_PCI_DMA_MAR0 + engine*0x10, 0);
+       VIA_WRITE(VIA_PCI_DMA_DAR0 + engine*0x10, 0);
+       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DD | VIA_DMA_CSR_TD |
+                 VIA_DMA_CSR_DE);
+       VIA_WRITE(VIA_PCI_DMA_MR0  + engine*0x04, VIA_DMA_MR_CM | VIA_DMA_MR_TDIE);
+       VIA_WRITE(VIA_PCI_DMA_BCR0 + engine*0x10, 0);
+       VIA_WRITE(VIA_PCI_DMA_DPR0 + engine*0x10, vsg->chain_start);
+       DRM_WRITEMEMORYBARRIER();
+       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_DE | VIA_DMA_CSR_TS);
+       VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04);
+}
+
+/*
+ * Obtain a page pointer array and lock all pages into system memory. A segmentation violation will
+ * occur here if the calling user does not have access to the submitted address.
+ */
+
+static int
+via_lock_all_dma_pages(drm_via_sg_info_t *vsg,  drm_via_dmablit_t *xfer)
+{
+       int ret;
+       unsigned long first_pfn = VIA_PFN(xfer->mem_addr);
+       vsg->num_pages = VIA_PFN(xfer->mem_addr + (xfer->num_lines * xfer->mem_stride -1)) -
+               first_pfn + 1;
+
+       if (NULL == (vsg->pages = vmalloc(sizeof(struct page *) * vsg->num_pages)))
+               return -ENOMEM;
+       memset(vsg->pages, 0, sizeof(struct page *) * vsg->num_pages);
+       down_read(&current->mm->mmap_sem);
+       ret = get_user_pages(current, current->mm,
+                            (unsigned long)xfer->mem_addr,
+                            vsg->num_pages,
+                            (vsg->direction == DMA_FROM_DEVICE),
+                            0, vsg->pages, NULL);
+
+       up_read(&current->mm->mmap_sem);
+       if (ret != vsg->num_pages) {
+               if (ret < 0)
+                       return ret;
+               vsg->state = dr_via_pages_locked;
+               return -EINVAL;
+       }
+       vsg->state = dr_via_pages_locked;
+       DRM_DEBUG("DMA pages locked\n");
+       return 0;
+}
+
+/*
+ * Allocate DMA capable memory for the blit descriptor chain, and an array that keeps track of the
+ * pages we allocate. We don't want to use kmalloc for the descriptor chain because it may be
+ * quite large for some blits, and pages don't need to be contingous.
+ */
+
+static int
+via_alloc_desc_pages(drm_via_sg_info_t *vsg)
+{
+       int i;
+
+       vsg->descriptors_per_page = PAGE_SIZE / sizeof( drm_via_descriptor_t);
+       vsg->num_desc_pages = (vsg->num_desc + vsg->descriptors_per_page - 1) /
+               vsg->descriptors_per_page;
+
+       if (NULL ==  (vsg->desc_pages = kcalloc(vsg->num_desc_pages, sizeof(void *), GFP_KERNEL)))
+               return -ENOMEM;
+
+       vsg->state = dr_via_desc_pages_alloc;
+       for (i=0; i<vsg->num_desc_pages; ++i) {
+               if (NULL == (vsg->desc_pages[i] =
+                            (drm_via_descriptor_t *) __get_free_page(GFP_KERNEL)))
+                       return -ENOMEM;
+       }
+       DRM_DEBUG("Allocated %d pages for %d descriptors.\n", vsg->num_desc_pages,
+                 vsg->num_desc);
+       return 0;
+}
+
+static void
+via_abort_dmablit(struct drm_device *dev, int engine)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+
+       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TA);
+}
+
+static void
+via_dmablit_engine_off(struct drm_device *dev, int engine)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+
+       VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04, VIA_DMA_CSR_TD | VIA_DMA_CSR_DD);
+}
+
+
+
+/*
+ * The dmablit part of the IRQ handler. Trying to do only reasonably fast things here.
+ * The rest, like unmapping and freeing memory for done blits is done in a separate workqueue
+ * task. Basically the task of the interrupt handler is to submit a new blit to the engine, while
+ * the workqueue task takes care of processing associated with the old blit.
+ */
+
+void
+via_dmablit_handler(struct drm_device *dev, int engine, int from_irq)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+       drm_via_blitq_t *blitq = dev_priv->blit_queues + engine;
+       int cur;
+       int done_transfer;
+       unsigned long irqsave=0;
+       uint32_t status = 0;
+
+       DRM_DEBUG("DMA blit handler called. engine = %d, from_irq = %d, blitq = 0x%lx\n",
+                 engine, from_irq, (unsigned long) blitq);
+
+       if (from_irq) {
+               spin_lock(&blitq->blit_lock);
+       } else {
+               spin_lock_irqsave(&blitq->blit_lock, irqsave);
+       }
+
+       done_transfer = blitq->is_active &&
+         (( status = VIA_READ(VIA_PCI_DMA_CSR0 + engine*0x04)) & VIA_DMA_CSR_TD);
+       done_transfer = done_transfer || ( blitq->aborting && !(status & VIA_DMA_CSR_DE));
+
+       cur = blitq->cur;
+       if (done_transfer) {
+
+               blitq->blits[cur]->aborted = blitq->aborting;
+               blitq->done_blit_handle++;
+               DRM_WAKEUP(blitq->blit_queue + cur);
+
+               cur++;
+               if (cur >= VIA_NUM_BLIT_SLOTS)
+                       cur = 0;
+               blitq->cur = cur;
+
+               /*
+                * Clear transfer done flag.
+                */
+
+               VIA_WRITE(VIA_PCI_DMA_CSR0 + engine*0x04,  VIA_DMA_CSR_TD);
+
+               blitq->is_active = 0;
+               blitq->aborting = 0;
+               schedule_work(&blitq->wq);
+
+       } else if (blitq->is_active && time_after_eq(jiffies, blitq->end)) {
+
+               /*
+                * Abort transfer after one second.
+                */
+
+               via_abort_dmablit(dev, engine);
+               blitq->aborting = 1;
+               blitq->end = jiffies + DRM_HZ;
+       }
+
+       if (!blitq->is_active) {
+               if (blitq->num_outstanding) {
+                       via_fire_dmablit(dev, blitq->blits[cur], engine);
+                       blitq->is_active = 1;
+                       blitq->cur = cur;
+                       blitq->num_outstanding--;
+                       blitq->end = jiffies + DRM_HZ;
+                       if (!timer_pending(&blitq->poll_timer))
+                               mod_timer(&blitq->poll_timer, jiffies + 1);
+               } else {
+                       if (timer_pending(&blitq->poll_timer)) {
+                               del_timer(&blitq->poll_timer);
+                       }
+                       via_dmablit_engine_off(dev, engine);
+               }
+       }
+
+       if (from_irq) {
+               spin_unlock(&blitq->blit_lock);
+       } else {
+               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+       }
+}
+
+
+
+/*
+ * Check whether this blit is still active, performing necessary locking.
+ */
+
+static int
+via_dmablit_active(drm_via_blitq_t *blitq, int engine, uint32_t handle, wait_queue_head_t **queue)
+{
+       unsigned long irqsave;
+       uint32_t slot;
+       int active;
+
+       spin_lock_irqsave(&blitq->blit_lock, irqsave);
+
+       /*
+        * Allow for handle wraparounds.
+        */
+
+       active = ((blitq->done_blit_handle - handle) > (1 << 23)) &&
+               ((blitq->cur_blit_handle - handle) <= (1 << 23));
+
+       if (queue && active) {
+               slot = handle - blitq->done_blit_handle + blitq->cur -1;
+               if (slot >= VIA_NUM_BLIT_SLOTS) {
+                       slot -= VIA_NUM_BLIT_SLOTS;
+               }
+               *queue = blitq->blit_queue + slot;
+       }
+
+       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+
+       return active;
+}
+
+/*
+ * Sync. Wait for at least three seconds for the blit to be performed.
+ */
+
+static int
+via_dmablit_sync(struct drm_device *dev, uint32_t handle, int engine)
+{
+
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+       drm_via_blitq_t *blitq = dev_priv->blit_queues + engine;
+       wait_queue_head_t *queue;
+       int ret = 0;
+
+       if (via_dmablit_active(blitq, engine, handle, &queue)) {
+               DRM_WAIT_ON(ret, *queue, 3 * DRM_HZ,
+                           !via_dmablit_active(blitq, engine, handle, NULL));
+       }
+       DRM_DEBUG("DMA blit sync handle 0x%x engine %d returned %d\n",
+                 handle, engine, ret);
+
+       return ret;
+}
+
+
+/*
+ * A timer that regularly polls the blit engine in cases where we don't have interrupts:
+ * a) Broken hardware (typically those that don't have any video capture facility).
+ * b) Blit abort. The hardware doesn't send an interrupt when a blit is aborted.
+ * The timer and hardware IRQ's can and do work in parallel. If the hardware has
+ * irqs, it will shorten the latency somewhat.
+ */
+
+
+
+static void
+via_dmablit_timer(unsigned long data)
+{
+       drm_via_blitq_t *blitq = (drm_via_blitq_t *) data;
+       struct drm_device *dev = blitq->dev;
+       int engine = (int)
+               (blitq - ((drm_via_private_t *)dev->dev_private)->blit_queues);
+
+       DRM_DEBUG("Polling timer called for engine %d, jiffies %lu\n", engine,
+                 (unsigned long) jiffies);
+
+       via_dmablit_handler(dev, engine, 0);
+
+       if (!timer_pending(&blitq->poll_timer)) {
+               mod_timer(&blitq->poll_timer, jiffies + 1);
+
+              /*
+               * Rerun handler to delete timer if engines are off, and
+               * to shorten abort latency. This is a little nasty.
+               */
+
+              via_dmablit_handler(dev, engine, 0);
+
+       }
+}
+
+
+
+
+/*
+ * Workqueue task that frees data and mappings associated with a blit.
+ * Also wakes up waiting processes. Each of these tasks handles one
+ * blit engine only and may not be called on each interrupt.
+ */
+
+
+static void
+via_dmablit_workqueue(struct work_struct *work)
+{
+       drm_via_blitq_t *blitq = container_of(work, drm_via_blitq_t, wq);
+       struct drm_device *dev = blitq->dev;
+       unsigned long irqsave;
+       drm_via_sg_info_t *cur_sg;
+       int cur_released;
+
+
+       DRM_DEBUG("Workqueue task called for blit engine %ld\n",(unsigned long)
+                 (blitq - ((drm_via_private_t *)dev->dev_private)->blit_queues));
+
+       spin_lock_irqsave(&blitq->blit_lock, irqsave);
+
+       while(blitq->serviced != blitq->cur) {
+
+               cur_released = blitq->serviced++;
+
+               DRM_DEBUG("Releasing blit slot %d\n", cur_released);
+
+               if (blitq->serviced >= VIA_NUM_BLIT_SLOTS)
+                       blitq->serviced = 0;
+
+               cur_sg = blitq->blits[cur_released];
+               blitq->num_free++;
+
+               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+
+               DRM_WAKEUP(&blitq->busy_queue);
+
+               via_free_sg_info(dev->pdev, cur_sg);
+               kfree(cur_sg);
+
+               spin_lock_irqsave(&blitq->blit_lock, irqsave);
+       }
+
+       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+}
+
+
+/*
+ * Init all blit engines. Currently we use two, but some hardware have 4.
+ */
+
+
+void
+via_init_dmablit(struct drm_device *dev)
+{
+       int i,j;
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+       drm_via_blitq_t *blitq;
+
+       pci_set_master(dev->pdev);
+
+       for (i=0; i< VIA_NUM_BLIT_ENGINES; ++i) {
+               blitq = dev_priv->blit_queues + i;
+               blitq->dev = dev;
+               blitq->cur_blit_handle = 0;
+               blitq->done_blit_handle = 0;
+               blitq->head = 0;
+               blitq->cur = 0;
+               blitq->serviced = 0;
+               blitq->num_free = VIA_NUM_BLIT_SLOTS - 1;
+               blitq->num_outstanding = 0;
+               blitq->is_active = 0;
+               blitq->aborting = 0;
+               spin_lock_init(&blitq->blit_lock);
+               for (j=0; j<VIA_NUM_BLIT_SLOTS; ++j) {
+                       DRM_INIT_WAITQUEUE(blitq->blit_queue + j);
+               }
+               DRM_INIT_WAITQUEUE(&blitq->busy_queue);
+               INIT_WORK(&blitq->wq, via_dmablit_workqueue);
+               setup_timer(&blitq->poll_timer, via_dmablit_timer,
+                               (unsigned long)blitq);
+       }
+}
+
+/*
+ * Build all info and do all mappings required for a blit.
+ */
+
+
+static int
+via_build_sg_info(struct drm_device *dev, drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
+{
+       int draw = xfer->to_fb;
+       int ret = 0;
+
+       vsg->direction = (draw) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+       vsg->bounce_buffer = NULL;
+
+       vsg->state = dr_via_sg_init;
+
+       if (xfer->num_lines <= 0 || xfer->line_length <= 0) {
+               DRM_ERROR("Zero size bitblt.\n");
+               return -EINVAL;
+       }
+
+       /*
+        * Below check is a driver limitation, not a hardware one. We
+        * don't want to lock unused pages, and don't want to incoporate the
+        * extra logic of avoiding them. Make sure there are no.
+        * (Not a big limitation anyway.)
+        */
+
+       if ((xfer->mem_stride - xfer->line_length) > 2*PAGE_SIZE) {
+               DRM_ERROR("Too large system memory stride. Stride: %d, "
+                         "Length: %d\n", xfer->mem_stride, xfer->line_length);
+               return -EINVAL;
+       }
+
+       if ((xfer->mem_stride == xfer->line_length) &&
+          (xfer->fb_stride == xfer->line_length)) {
+               xfer->mem_stride *= xfer->num_lines;
+               xfer->line_length = xfer->mem_stride;
+               xfer->fb_stride = xfer->mem_stride;
+               xfer->num_lines = 1;
+       }
+
+       /*
+        * Don't lock an arbitrary large number of pages, since that causes a
+        * DOS security hole.
+        */
+
+       if (xfer->num_lines > 2048 || (xfer->num_lines*xfer->mem_stride > (2048*2048*4))) {
+               DRM_ERROR("Too large PCI DMA bitblt.\n");
+               return -EINVAL;
+       }
+
+       /*
+        * we allow a negative fb stride to allow flipping of images in
+        * transfer.
+        */
+
+       if (xfer->mem_stride < xfer->line_length ||
+               abs(xfer->fb_stride) < xfer->line_length) {
+               DRM_ERROR("Invalid frame-buffer / memory stride.\n");
+               return -EINVAL;
+       }
+
+       /*
+        * A hardware bug seems to be worked around if system memory addresses start on
+        * 16 byte boundaries. This seems a bit restrictive however. VIA is contacted
+        * about this. Meanwhile, impose the following restrictions:
+        */
+
+#ifdef VIA_BUGFREE
+       if ((((unsigned long)xfer->mem_addr & 3) != ((unsigned long)xfer->fb_addr & 3)) ||
+           ((xfer->num_lines > 1) && ((xfer->mem_stride & 3) != (xfer->fb_stride & 3)))) {
+               DRM_ERROR("Invalid DRM bitblt alignment.\n");
+               return -EINVAL;
+       }
+#else
+       if ((((unsigned long)xfer->mem_addr & 15) ||
+             ((unsigned long)xfer->fb_addr & 3)) ||
+          ((xfer->num_lines > 1) &&
+          ((xfer->mem_stride & 15) || (xfer->fb_stride & 3)))) {
+               DRM_ERROR("Invalid DRM bitblt alignment.\n");
+               return -EINVAL;
+       }
+#endif
+
+       if (0 != (ret = via_lock_all_dma_pages(vsg, xfer))) {
+               DRM_ERROR("Could not lock DMA pages.\n");
+               via_free_sg_info(dev->pdev, vsg);
+               return ret;
+       }
+
+       via_map_blit_for_device(dev->pdev, xfer, vsg, 0);
+       if (0 != (ret = via_alloc_desc_pages(vsg))) {
+               DRM_ERROR("Could not allocate DMA descriptor pages.\n");
+               via_free_sg_info(dev->pdev, vsg);
+               return ret;
+       }
+       via_map_blit_for_device(dev->pdev, xfer, vsg, 1);
+
+       return 0;
+}
+
+
+/*
+ * Reserve one free slot in the blit queue. Will wait for one second for one
+ * to become available. Otherwise -EBUSY is returned.
+ */
+
+static int
+via_dmablit_grab_slot(drm_via_blitq_t *blitq, int engine)
+{
+       int ret=0;
+       unsigned long irqsave;
+
+       DRM_DEBUG("Num free is %d\n", blitq->num_free);
+       spin_lock_irqsave(&blitq->blit_lock, irqsave);
+       while(blitq->num_free == 0) {
+               spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+
+               DRM_WAIT_ON(ret, blitq->busy_queue, DRM_HZ, blitq->num_free > 0);
+               if (ret) {
+                       return (-EINTR == ret) ? -EAGAIN : ret;
+               }
+
+               spin_lock_irqsave(&blitq->blit_lock, irqsave);
+       }
+
+       blitq->num_free--;
+       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+
+       return 0;
+}
+
+/*
+ * Hand back a free slot if we changed our mind.
+ */
+
+static void
+via_dmablit_release_slot(drm_via_blitq_t *blitq)
+{
+       unsigned long irqsave;
+
+       spin_lock_irqsave(&blitq->blit_lock, irqsave);
+       blitq->num_free++;
+       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+       DRM_WAKEUP( &blitq->busy_queue );
+}
+
+/*
+ * Grab a free slot. Build blit info and queue a blit.
+ */
+
+
+static int
+via_dmablit(struct drm_device *dev, drm_via_dmablit_t *xfer)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *)dev->dev_private;
+       drm_via_sg_info_t *vsg;
+       drm_via_blitq_t *blitq;
+       int ret;
+       int engine;
+       unsigned long irqsave;
+
+       if (dev_priv == NULL) {
+               DRM_ERROR("Called without initialization.\n");
+               return -EINVAL;
+       }
+
+       engine = (xfer->to_fb) ? 0 : 1;
+       blitq = dev_priv->blit_queues + engine;
+       if (0 != (ret = via_dmablit_grab_slot(blitq, engine))) {
+               return ret;
+       }
+       if (NULL == (vsg = kmalloc(sizeof(*vsg), GFP_KERNEL))) {
+               via_dmablit_release_slot(blitq);
+               return -ENOMEM;
+       }
+       if (0 != (ret = via_build_sg_info(dev, vsg, xfer))) {
+               via_dmablit_release_slot(blitq);
+               kfree(vsg);
+               return ret;
+       }
+       spin_lock_irqsave(&blitq->blit_lock, irqsave);
+
+       blitq->blits[blitq->head++] = vsg;
+       if (blitq->head >= VIA_NUM_BLIT_SLOTS)
+               blitq->head = 0;
+       blitq->num_outstanding++;
+       xfer->sync.sync_handle = ++blitq->cur_blit_handle;
+
+       spin_unlock_irqrestore(&blitq->blit_lock, irqsave);
+       xfer->sync.engine = engine;
+
+       via_dmablit_handler(dev, engine, 0);
+
+       return 0;
+}
+
+/*
+ * Sync on a previously submitted blit. Note that the X server use signals extensively, and
+ * that there is a very big probability that this IOCTL will be interrupted by a signal. In that
+ * case it returns with -EAGAIN for the signal to be delivered.
+ * The caller should then reissue the IOCTL. This is similar to what is being done for drmGetLock().
+ */
+
+int
+via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv )
+{
+       drm_via_blitsync_t *sync = data;
+       int err;
+
+       if (sync->engine >= VIA_NUM_BLIT_ENGINES)
+               return -EINVAL;
+
+       err = via_dmablit_sync(dev, sync->sync_handle, sync->engine);
+
+       if (-EINTR == err)
+               err = -EAGAIN;
+
+       return err;
+}
+
+
+/*
+ * Queue a blit and hand back a handle to be used for sync. This IOCTL may be interrupted by a signal
+ * while waiting for a free slot in the blit queue. In that case it returns with -EAGAIN and should
+ * be reissued. See the above IOCTL code.
+ */
+
+int
+via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv )
+{
+       drm_via_dmablit_t *xfer = data;
+       int err;
+
+       err = via_dmablit(dev, xfer);
+
+       return err;
+}
diff --git a/drivers/gpu/drm/via/via_dmablit.h b/drivers/gpu/drm/via/via_dmablit.h
new file mode 100644 (file)
index 0000000..7408a54
--- /dev/null
@@ -0,0 +1,140 @@
+/* via_dmablit.h -- PCI DMA BitBlt support for the VIA Unichrome/Pro
+ *
+ * Copyright 2005 Thomas Hellstrom.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Thomas Hellstrom.
+ *    Register info from Digeo Inc.
+ */
+
+#ifndef _VIA_DMABLIT_H
+#define _VIA_DMABLIT_H
+
+#include <linux/dma-mapping.h>
+
+#define VIA_NUM_BLIT_ENGINES 2
+#define VIA_NUM_BLIT_SLOTS 8
+
+struct _drm_via_descriptor;
+
+typedef struct _drm_via_sg_info {
+       struct page **pages;
+       unsigned long num_pages;
+       struct _drm_via_descriptor **desc_pages;
+       int num_desc_pages;
+       int num_desc;
+       enum dma_data_direction direction;
+       unsigned char *bounce_buffer;
+        dma_addr_t chain_start;
+       uint32_t free_on_sequence;
+        unsigned int descriptors_per_page;
+       int aborted;
+       enum {
+               dr_via_device_mapped,
+               dr_via_desc_pages_alloc,
+               dr_via_pages_locked,
+               dr_via_pages_alloc,
+               dr_via_sg_init
+       } state;
+} drm_via_sg_info_t;
+
+typedef struct _drm_via_blitq {
+       struct drm_device *dev;
+       uint32_t cur_blit_handle;
+       uint32_t done_blit_handle;
+       unsigned serviced;
+       unsigned head;
+       unsigned cur;
+       unsigned num_free;
+       unsigned num_outstanding;
+       unsigned long end;
+        int aborting;
+       int is_active;
+       drm_via_sg_info_t *blits[VIA_NUM_BLIT_SLOTS];
+       spinlock_t blit_lock;
+       wait_queue_head_t blit_queue[VIA_NUM_BLIT_SLOTS];
+       wait_queue_head_t busy_queue;
+       struct work_struct wq;
+       struct timer_list poll_timer;
+} drm_via_blitq_t;
+
+
+/*
+ *  PCI DMA Registers
+ *  Channels 2 & 3 don't seem to be implemented in hardware.
+ */
+
+#define VIA_PCI_DMA_MAR0            0xE40   /* Memory Address Register of Channel 0 */
+#define VIA_PCI_DMA_DAR0            0xE44   /* Device Address Register of Channel 0 */
+#define VIA_PCI_DMA_BCR0            0xE48   /* Byte Count Register of Channel 0 */
+#define VIA_PCI_DMA_DPR0            0xE4C   /* Descriptor Pointer Register of Channel 0 */
+
+#define VIA_PCI_DMA_MAR1            0xE50   /* Memory Address Register of Channel 1 */
+#define VIA_PCI_DMA_DAR1            0xE54   /* Device Address Register of Channel 1 */
+#define VIA_PCI_DMA_BCR1            0xE58   /* Byte Count Register of Channel 1 */
+#define VIA_PCI_DMA_DPR1            0xE5C   /* Descriptor Pointer Register of Channel 1 */
+
+#define VIA_PCI_DMA_MAR2            0xE60   /* Memory Address Register of Channel 2 */
+#define VIA_PCI_DMA_DAR2            0xE64   /* Device Address Register of Channel 2 */
+#define VIA_PCI_DMA_BCR2            0xE68   /* Byte Count Register of Channel 2 */
+#define VIA_PCI_DMA_DPR2            0xE6C   /* Descriptor Pointer Register of Channel 2 */
+
+#define VIA_PCI_DMA_MAR3            0xE70   /* Memory Address Register of Channel 3 */
+#define VIA_PCI_DMA_DAR3            0xE74   /* Device Address Register of Channel 3 */
+#define VIA_PCI_DMA_BCR3            0xE78   /* Byte Count Register of Channel 3 */
+#define VIA_PCI_DMA_DPR3            0xE7C   /* Descriptor Pointer Register of Channel 3 */
+
+#define VIA_PCI_DMA_MR0             0xE80   /* Mode Register of Channel 0 */
+#define VIA_PCI_DMA_MR1             0xE84   /* Mode Register of Channel 1 */
+#define VIA_PCI_DMA_MR2             0xE88   /* Mode Register of Channel 2 */
+#define VIA_PCI_DMA_MR3             0xE8C   /* Mode Register of Channel 3 */
+
+#define VIA_PCI_DMA_CSR0            0xE90   /* Command/Status Register of Channel 0 */
+#define VIA_PCI_DMA_CSR1            0xE94   /* Command/Status Register of Channel 1 */
+#define VIA_PCI_DMA_CSR2            0xE98   /* Command/Status Register of Channel 2 */
+#define VIA_PCI_DMA_CSR3            0xE9C   /* Command/Status Register of Channel 3 */
+
+#define VIA_PCI_DMA_PTR             0xEA0   /* Priority Type Register */
+
+/* Define for DMA engine */
+/* DPR */
+#define VIA_DMA_DPR_EC         (1<<1)  /* end of chain */
+#define VIA_DMA_DPR_DDIE       (1<<2)  /* descriptor done interrupt enable */
+#define VIA_DMA_DPR_DT         (1<<3)  /* direction of transfer (RO) */
+
+/* MR */
+#define VIA_DMA_MR_CM          (1<<0)  /* chaining mode */
+#define VIA_DMA_MR_TDIE                (1<<1)  /* transfer done interrupt enable */
+#define VIA_DMA_MR_HENDMACMD           (1<<7) /* ? */
+
+/* CSR */
+#define VIA_DMA_CSR_DE         (1<<0)  /* DMA enable */
+#define VIA_DMA_CSR_TS         (1<<1)  /* transfer start */
+#define VIA_DMA_CSR_TA         (1<<2)  /* transfer abort */
+#define VIA_DMA_CSR_TD         (1<<3)  /* transfer done */
+#define VIA_DMA_CSR_DD         (1<<4)  /* descriptor done */
+#define VIA_DMA_DPR_EC          (1<<1)  /* end of chain */
+
+
+
+#endif
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
new file mode 100644 (file)
index 0000000..80c01cd
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "via_drm.h"
+#include "via_drv.h"
+
+#include "drm_pciids.h"
+
+static int dri_library_name(struct drm_device *dev, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "unichrome");
+}
+
+static struct pci_device_id pciidlist[] = {
+       viadrv_PCI_IDS
+};
+
+static struct drm_driver driver = {
+       .driver_features =
+           DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
+           DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL,
+       .load = via_driver_load,
+       .unload = via_driver_unload,
+       .context_dtor = via_final_context,
+       .vblank_wait = via_driver_vblank_wait,
+       .irq_preinstall = via_driver_irq_preinstall,
+       .irq_postinstall = via_driver_irq_postinstall,
+       .irq_uninstall = via_driver_irq_uninstall,
+       .irq_handler = via_driver_irq_handler,
+       .dma_quiescent = via_driver_dma_quiescent,
+       .dri_library_name = dri_library_name,
+       .reclaim_buffers = drm_core_reclaim_buffers,
+       .reclaim_buffers_locked = NULL,
+       .reclaim_buffers_idlelocked = via_reclaim_buffers_locked,
+       .lastclose = via_lastclose,
+       .get_map_ofs = drm_core_get_map_ofs,
+       .get_reg_ofs = drm_core_get_reg_ofs,
+       .ioctls = via_ioctls,
+       .fops = {
+                .owner = THIS_MODULE,
+                .open = drm_open,
+                .release = drm_release,
+                .ioctl = drm_ioctl,
+                .mmap = drm_mmap,
+                .poll = drm_poll,
+                .fasync = drm_fasync,
+       },
+       .pci_driver = {
+                .name = DRIVER_NAME,
+                .id_table = pciidlist,
+       },
+
+       .name = DRIVER_NAME,
+       .desc = DRIVER_DESC,
+       .date = DRIVER_DATE,
+       .major = DRIVER_MAJOR,
+       .minor = DRIVER_MINOR,
+       .patchlevel = DRIVER_PATCHLEVEL,
+};
+
+static int __init via_init(void)
+{
+       driver.num_ioctls = via_max_ioctl;
+       via_init_command_verifier();
+       return drm_init(&driver);
+}
+
+static void __exit via_exit(void)
+{
+       drm_exit(&driver);
+}
+
+module_init(via_init);
+module_exit(via_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
new file mode 100644 (file)
index 0000000..2daae81
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#ifndef _VIA_DRV_H_
+#define _VIA_DRV_H_
+
+#include "drm_sman.h"
+#define DRIVER_AUTHOR  "Various"
+
+#define DRIVER_NAME            "via"
+#define DRIVER_DESC            "VIA Unichrome / Pro"
+#define DRIVER_DATE            "20070202"
+
+#define DRIVER_MAJOR           2
+#define DRIVER_MINOR           11
+#define DRIVER_PATCHLEVEL      1
+
+#include "via_verifier.h"
+
+#include "via_dmablit.h"
+
+#define VIA_PCI_BUF_SIZE 60000
+#define VIA_FIRE_BUF_SIZE  1024
+#define VIA_NUM_IRQS 4
+
+typedef struct drm_via_ring_buffer {
+       drm_local_map_t map;
+       char *virtual_start;
+} drm_via_ring_buffer_t;
+
+typedef uint32_t maskarray_t[5];
+
+typedef struct drm_via_irq {
+       atomic_t irq_received;
+       uint32_t pending_mask;
+       uint32_t enable_mask;
+       wait_queue_head_t irq_queue;
+} drm_via_irq_t;
+
+typedef struct drm_via_private {
+       drm_via_sarea_t *sarea_priv;
+       drm_local_map_t *sarea;
+       drm_local_map_t *fb;
+       drm_local_map_t *mmio;
+       unsigned long agpAddr;
+       wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
+       char *dma_ptr;
+       unsigned int dma_low;
+       unsigned int dma_high;
+       unsigned int dma_offset;
+       uint32_t dma_wrap;
+       volatile uint32_t *last_pause_ptr;
+       volatile uint32_t *hw_addr_ptr;
+       drm_via_ring_buffer_t ring;
+       struct timeval last_vblank;
+       int last_vblank_valid;
+       unsigned usec_per_vblank;
+       drm_via_state_t hc_state;
+       char pci_buf[VIA_PCI_BUF_SIZE];
+       const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
+       uint32_t num_fire_offsets;
+       int chipset;
+       drm_via_irq_t via_irqs[VIA_NUM_IRQS];
+       unsigned num_irqs;
+       maskarray_t *irq_masks;
+       uint32_t irq_enable_mask;
+       uint32_t irq_pending_mask;
+       int *irq_map;
+       unsigned int idle_fault;
+       struct drm_sman sman;
+       int vram_initialized;
+       int agp_initialized;
+       unsigned long vram_offset;
+       unsigned long agp_offset;
+       drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
+       uint32_t dma_diff;
+} drm_via_private_t;
+
+enum via_family {
+  VIA_OTHER = 0,     /* Baseline */
+  VIA_PRO_GROUP_A,   /* Another video engine and DMA commands */
+  VIA_DX9_0          /* Same video as pro_group_a, but 3D is unsupported */
+};
+
+/* VIA MMIO register access */
+#define VIA_BASE ((dev_priv->mmio))
+
+#define VIA_READ(reg)          DRM_READ32(VIA_BASE, reg)
+#define VIA_WRITE(reg,val)     DRM_WRITE32(VIA_BASE, reg, val)
+#define VIA_READ8(reg)         DRM_READ8(VIA_BASE, reg)
+#define VIA_WRITE8(reg,val)    DRM_WRITE8(VIA_BASE, reg, val)
+
+extern struct drm_ioctl_desc via_ioctls[];
+extern int via_max_ioctl;
+
+extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
+extern int via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv );
+extern int via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv );
+
+extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
+extern int via_driver_unload(struct drm_device *dev);
+
+extern int via_init_context(struct drm_device * dev, int context);
+extern int via_final_context(struct drm_device * dev, int context);
+
+extern int via_do_cleanup_map(struct drm_device * dev);
+extern int via_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence);
+
+extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
+extern void via_driver_irq_preinstall(struct drm_device * dev);
+extern void via_driver_irq_postinstall(struct drm_device * dev);
+extern void via_driver_irq_uninstall(struct drm_device * dev);
+
+extern int via_dma_cleanup(struct drm_device * dev);
+extern void via_init_command_verifier(void);
+extern int via_driver_dma_quiescent(struct drm_device * dev);
+extern void via_init_futex(drm_via_private_t * dev_priv);
+extern void via_cleanup_futex(drm_via_private_t * dev_priv);
+extern void via_release_futex(drm_via_private_t * dev_priv, int context);
+
+extern void via_reclaim_buffers_locked(struct drm_device *dev, struct drm_file *file_priv);
+extern void via_lastclose(struct drm_device *dev);
+
+extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
+extern void via_init_dmablit(struct drm_device *dev);
+
+#endif
diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
new file mode 100644 (file)
index 0000000..c6bb978
--- /dev/null
@@ -0,0 +1,377 @@
+/* via_irq.c
+ *
+ * Copyright 2004 BEAM Ltd.
+ * Copyright 2002 Tungsten Graphics, Inc.
+ * Copyright 2005 Thomas Hellstrom.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BEAM LTD, TUNGSTEN GRAPHICS  AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Terry Barnaby <terry1@beam.ltd.uk>
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Thomas Hellstrom <unichrome@shipmail.org>
+ *
+ * This code provides standard DRM access to the Via Unichrome / Pro Vertical blank
+ * interrupt, as well as an infrastructure to handle other interrupts of the chip.
+ * The refresh rate is also calculated for video playback sync purposes.
+ */
+
+#include "drmP.h"
+#include "drm.h"
+#include "via_drm.h"
+#include "via_drv.h"
+
+#define VIA_REG_INTERRUPT       0x200
+
+/* VIA_REG_INTERRUPT */
+#define VIA_IRQ_GLOBAL          (1 << 31)
+#define VIA_IRQ_VBLANK_ENABLE   (1 << 19)
+#define VIA_IRQ_VBLANK_PENDING  (1 << 3)
+#define VIA_IRQ_HQV0_ENABLE     (1 << 11)
+#define VIA_IRQ_HQV1_ENABLE     (1 << 25)
+#define VIA_IRQ_HQV0_PENDING    (1 << 9)
+#define VIA_IRQ_HQV1_PENDING    (1 << 10)
+#define VIA_IRQ_DMA0_DD_ENABLE  (1 << 20)
+#define VIA_IRQ_DMA0_TD_ENABLE  (1 << 21)
+#define VIA_IRQ_DMA1_DD_ENABLE  (1 << 22)
+#define VIA_IRQ_DMA1_TD_ENABLE  (1 << 23)
+#define VIA_IRQ_DMA0_DD_PENDING (1 << 4)
+#define VIA_IRQ_DMA0_TD_PENDING (1 << 5)
+#define VIA_IRQ_DMA1_DD_PENDING (1 << 6)
+#define VIA_IRQ_DMA1_TD_PENDING (1 << 7)
+
+
+/*
+ * Device-specific IRQs go here. This type might need to be extended with
+ * the register if there are multiple IRQ control registers.
+ * Currently we activate the HQV interrupts of  Unichrome Pro group A.
+ */
+
+static maskarray_t via_pro_group_a_irqs[] = {
+       {VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010,
+        0x00000000},
+       {VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010,
+        0x00000000},
+       {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
+        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
+       {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
+        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
+};
+static int via_num_pro_group_a =
+    sizeof(via_pro_group_a_irqs) / sizeof(maskarray_t);
+static int via_irqmap_pro_group_a[] = {0, 1, -1, 2, -1, 3};
+
+static maskarray_t via_unichrome_irqs[] = {
+       {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0,
+        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008},
+       {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1,
+        VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}
+};
+static int via_num_unichrome = sizeof(via_unichrome_irqs) / sizeof(maskarray_t);
+static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1};
+
+static unsigned time_diff(struct timeval *now, struct timeval *then)
+{
+       return (now->tv_usec >= then->tv_usec) ?
+           now->tv_usec - then->tv_usec :
+           1000000 - (then->tv_usec - now->tv_usec);
+}
+
+irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       u32 status;
+       int handled = 0;
+       struct timeval cur_vblank;
+       drm_via_irq_t *cur_irq = dev_priv->via_irqs;
+       int i;
+
+       status = VIA_READ(VIA_REG_INTERRUPT);
+       if (status & VIA_IRQ_VBLANK_PENDING) {
+               atomic_inc(&dev->vbl_received);
+               if (!(atomic_read(&dev->vbl_received) & 0x0F)) {
+                       do_gettimeofday(&cur_vblank);
+                       if (dev_priv->last_vblank_valid) {
+                               dev_priv->usec_per_vblank =
+                                   time_diff(&cur_vblank,
+                                             &dev_priv->last_vblank) >> 4;
+                       }
+                       dev_priv->last_vblank = cur_vblank;
+                       dev_priv->last_vblank_valid = 1;
+               }
+               if (!(atomic_read(&dev->vbl_received) & 0xFF)) {
+                       DRM_DEBUG("US per vblank is: %u\n",
+                                 dev_priv->usec_per_vblank);
+               }
+               DRM_WAKEUP(&dev->vbl_queue);
+               drm_vbl_send_signals(dev);
+               handled = 1;
+       }
+
+       for (i = 0; i < dev_priv->num_irqs; ++i) {
+               if (status & cur_irq->pending_mask) {
+                       atomic_inc(&cur_irq->irq_received);
+                       DRM_WAKEUP(&cur_irq->irq_queue);
+                       handled = 1;
+                       if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
+                               via_dmablit_handler(dev, 0, 1);
+                       } else if (dev_priv->irq_map[drm_via_irq_dma1_td] == i) {
+                               via_dmablit_handler(dev, 1, 1);
+                       }
+               }
+               cur_irq++;
+       }
+
+       /* Acknowlege interrupts */
+       VIA_WRITE(VIA_REG_INTERRUPT, status);
+
+       if (handled)
+               return IRQ_HANDLED;
+       else
+               return IRQ_NONE;
+}
+
+static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t * dev_priv)
+{
+       u32 status;
+
+       if (dev_priv) {
+               /* Acknowlege interrupts */
+               status = VIA_READ(VIA_REG_INTERRUPT);
+               VIA_WRITE(VIA_REG_INTERRUPT, status |
+                         dev_priv->irq_pending_mask);
+       }
+}
+
+int via_driver_vblank_wait(struct drm_device * dev, unsigned int *sequence)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       unsigned int cur_vblank;
+       int ret = 0;
+
+       DRM_DEBUG("\n");
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       viadrv_acknowledge_irqs(dev_priv);
+
+       /* Assume that the user has missed the current sequence number
+        * by about a day rather than she wants to wait for years
+        * using vertical blanks...
+        */
+
+       DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
+                   (((cur_vblank = atomic_read(&dev->vbl_received)) -
+                     *sequence) <= (1 << 23)));
+
+       *sequence = cur_vblank;
+       return ret;
+}
+
+static int
+via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequence,
+                   unsigned int *sequence)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       unsigned int cur_irq_sequence;
+       drm_via_irq_t *cur_irq;
+       int ret = 0;
+       maskarray_t *masks;
+       int real_irq;
+
+       DRM_DEBUG("\n");
+
+       if (!dev_priv) {
+               DRM_ERROR("called with no initialization\n");
+               return -EINVAL;
+       }
+
+       if (irq >= drm_via_irq_num) {
+               DRM_ERROR("Trying to wait on unknown irq %d\n", irq);
+               return -EINVAL;
+       }
+
+       real_irq = dev_priv->irq_map[irq];
+
+       if (real_irq < 0) {
+               DRM_ERROR("Video IRQ %d not available on this hardware.\n",
+                         irq);
+               return -EINVAL;
+       }
+
+       masks = dev_priv->irq_masks;
+       cur_irq = dev_priv->via_irqs + real_irq;
+
+       if (masks[real_irq][2] && !force_sequence) {
+               DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
+                           ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
+                            masks[irq][4]));
+               cur_irq_sequence = atomic_read(&cur_irq->irq_received);
+       } else {
+               DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
+                           (((cur_irq_sequence =
+                              atomic_read(&cur_irq->irq_received)) -
+                             *sequence) <= (1 << 23)));
+       }
+       *sequence = cur_irq_sequence;
+       return ret;
+}
+
+/*
+ * drm_dma.h hooks
+ */
+
+void via_driver_irq_preinstall(struct drm_device * dev)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       u32 status;
+       drm_via_irq_t *cur_irq;
+       int i;
+
+       DRM_DEBUG("dev_priv: %p\n", dev_priv);
+       if (dev_priv) {
+               cur_irq = dev_priv->via_irqs;
+
+               dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE;
+               dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING;
+
+               if (dev_priv->chipset == VIA_PRO_GROUP_A ||
+                   dev_priv->chipset == VIA_DX9_0) {
+                       dev_priv->irq_masks = via_pro_group_a_irqs;
+                       dev_priv->num_irqs = via_num_pro_group_a;
+                       dev_priv->irq_map = via_irqmap_pro_group_a;
+               } else {
+                       dev_priv->irq_masks = via_unichrome_irqs;
+                       dev_priv->num_irqs = via_num_unichrome;
+                       dev_priv->irq_map = via_irqmap_unichrome;
+               }
+
+               for (i = 0; i < dev_priv->num_irqs; ++i) {
+                       atomic_set(&cur_irq->irq_received, 0);
+                       cur_irq->enable_mask = dev_priv->irq_masks[i][0];
+                       cur_irq->pending_mask = dev_priv->irq_masks[i][1];
+                       DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
+                       dev_priv->irq_enable_mask |= cur_irq->enable_mask;
+                       dev_priv->irq_pending_mask |= cur_irq->pending_mask;
+                       cur_irq++;
+
+                       DRM_DEBUG("Initializing IRQ %d\n", i);
+               }
+
+               dev_priv->last_vblank_valid = 0;
+
+               /* Clear VSync interrupt regs */
+               status = VIA_READ(VIA_REG_INTERRUPT);
+               VIA_WRITE(VIA_REG_INTERRUPT, status &
+                         ~(dev_priv->irq_enable_mask));
+
+               /* Clear bits if they're already high */
+               viadrv_acknowledge_irqs(dev_priv);
+       }
+}
+
+void via_driver_irq_postinstall(struct drm_device * dev)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       u32 status;
+
+       DRM_DEBUG("\n");
+       if (dev_priv) {
+               status = VIA_READ(VIA_REG_INTERRUPT);
+               VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_GLOBAL
+                         | dev_priv->irq_enable_mask);
+
+               /* Some magic, oh for some data sheets ! */
+
+               VIA_WRITE8(0x83d4, 0x11);
+               VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30);
+
+       }
+}
+
+void via_driver_irq_uninstall(struct drm_device * dev)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       u32 status;
+
+       DRM_DEBUG("\n");
+       if (dev_priv) {
+
+               /* Some more magic, oh for some data sheets ! */
+
+               VIA_WRITE8(0x83d4, 0x11);
+               VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30);
+
+               status = VIA_READ(VIA_REG_INTERRUPT);
+               VIA_WRITE(VIA_REG_INTERRUPT, status &
+                         ~(VIA_IRQ_VBLANK_ENABLE | dev_priv->irq_enable_mask));
+       }
+}
+
+int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_irqwait_t *irqwait = data;
+       struct timeval now;
+       int ret = 0;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       drm_via_irq_t *cur_irq = dev_priv->via_irqs;
+       int force_sequence;
+
+       if (!dev->irq)
+               return -EINVAL;
+
+       if (irqwait->request.irq >= dev_priv->num_irqs) {
+               DRM_ERROR("Trying to wait on unknown irq %d\n",
+                         irqwait->request.irq);
+               return -EINVAL;
+       }
+
+       cur_irq += irqwait->request.irq;
+
+       switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
+       case VIA_IRQ_RELATIVE:
+               irqwait->request.sequence += atomic_read(&cur_irq->irq_received);
+               irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
+       case VIA_IRQ_ABSOLUTE:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (irqwait->request.type & VIA_IRQ_SIGNAL) {
+               DRM_ERROR("Signals on Via IRQs not implemented yet.\n");
+               return -EINVAL;
+       }
+
+       force_sequence = (irqwait->request.type & VIA_IRQ_FORCE_SEQUENCE);
+
+       ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence,
+                                 &irqwait->request.sequence);
+       do_gettimeofday(&now);
+       irqwait->reply.tval_sec = now.tv_sec;
+       irqwait->reply.tval_usec = now.tv_usec;
+
+       return ret;
+}
diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
new file mode 100644 (file)
index 0000000..a967556
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include "drmP.h"
+#include "via_drm.h"
+#include "via_drv.h"
+
+static int via_do_init_map(struct drm_device * dev, drm_via_init_t * init)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+
+       DRM_DEBUG("\n");
+
+       dev_priv->sarea = drm_getsarea(dev);
+       if (!dev_priv->sarea) {
+               DRM_ERROR("could not find sarea!\n");
+               dev->dev_private = (void *)dev_priv;
+               via_do_cleanup_map(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->fb = drm_core_findmap(dev, init->fb_offset);
+       if (!dev_priv->fb) {
+               DRM_ERROR("could not find framebuffer!\n");
+               dev->dev_private = (void *)dev_priv;
+               via_do_cleanup_map(dev);
+               return -EINVAL;
+       }
+       dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
+       if (!dev_priv->mmio) {
+               DRM_ERROR("could not find mmio region!\n");
+               dev->dev_private = (void *)dev_priv;
+               via_do_cleanup_map(dev);
+               return -EINVAL;
+       }
+
+       dev_priv->sarea_priv =
+           (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
+                                init->sarea_priv_offset);
+
+       dev_priv->agpAddr = init->agpAddr;
+
+       via_init_futex(dev_priv);
+
+       via_init_dmablit(dev);
+
+       dev->dev_private = (void *)dev_priv;
+       return 0;
+}
+
+int via_do_cleanup_map(struct drm_device * dev)
+{
+       via_dma_cleanup(dev);
+
+       return 0;
+}
+
+int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_init_t *init = data;
+
+       DRM_DEBUG("\n");
+
+       switch (init->func) {
+       case VIA_INIT_MAP:
+               return via_do_init_map(dev, init);
+       case VIA_CLEANUP_MAP:
+               return via_do_cleanup_map(dev);
+       }
+
+       return -EINVAL;
+}
+
+int via_driver_load(struct drm_device *dev, unsigned long chipset)
+{
+       drm_via_private_t *dev_priv;
+       int ret = 0;
+
+       dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = (void *)dev_priv;
+
+       dev_priv->chipset = chipset;
+
+       ret = drm_sman_init(&dev_priv->sman, 2, 12, 8);
+       if (ret) {
+               drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
+       }
+       return ret;
+}
+
+int via_driver_unload(struct drm_device *dev)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+
+       drm_sman_takedown(&dev_priv->sman);
+
+       drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
+
+       return 0;
+}
diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
new file mode 100644 (file)
index 0000000..e640949
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#include "drmP.h"
+#include "via_drm.h"
+#include "via_drv.h"
+#include "drm_sman.h"
+
+#define VIA_MM_ALIGN_SHIFT 4
+#define VIA_MM_ALIGN_MASK ( (1 << VIA_MM_ALIGN_SHIFT) - 1)
+
+int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_agp_t *agp = data;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_AGP, 0,
+                                agp->size >> VIA_MM_ALIGN_SHIFT);
+
+       if (ret) {
+               DRM_ERROR("AGP memory manager initialisation error\n");
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       dev_priv->agp_initialized = 1;
+       dev_priv->agp_offset = agp->offset;
+       mutex_unlock(&dev->struct_mutex);
+
+       DRM_DEBUG("offset = %u, size = %u\n", agp->offset, agp->size);
+       return 0;
+}
+
+int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_fb_t *fb = data;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_sman_set_range(&dev_priv->sman, VIA_MEM_VIDEO, 0,
+                                fb->size >> VIA_MM_ALIGN_SHIFT);
+
+       if (ret) {
+               DRM_ERROR("VRAM memory manager initialisation error\n");
+               mutex_unlock(&dev->struct_mutex);
+               return ret;
+       }
+
+       dev_priv->vram_initialized = 1;
+       dev_priv->vram_offset = fb->offset;
+
+       mutex_unlock(&dev->struct_mutex);
+       DRM_DEBUG("offset = %u, size = %u\n", fb->offset, fb->size);
+
+       return 0;
+
+}
+
+int via_final_context(struct drm_device *dev, int context)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+
+       via_release_futex(dev_priv, context);
+
+       /* Linux specific until context tracking code gets ported to BSD */
+       /* Last context, perform cleanup */
+       if (dev->ctx_count == 1 && dev->dev_private) {
+               DRM_DEBUG("Last Context\n");
+               if (dev->irq)
+                       drm_irq_uninstall(dev);
+               via_cleanup_futex(dev_priv);
+               via_do_cleanup_map(dev);
+       }
+       return 1;
+}
+
+void via_lastclose(struct drm_device *dev)
+{
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+
+       if (!dev_priv)
+               return;
+
+       mutex_lock(&dev->struct_mutex);
+       drm_sman_cleanup(&dev_priv->sman);
+       dev_priv->vram_initialized = 0;
+       dev_priv->agp_initialized = 0;
+       mutex_unlock(&dev->struct_mutex);
+}
+
+int via_mem_alloc(struct drm_device *dev, void *data,
+                 struct drm_file *file_priv)
+{
+       drm_via_mem_t *mem = data;
+       int retval = 0;
+       struct drm_memblock_item *item;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       unsigned long tmpSize;
+
+       if (mem->type > VIA_MEM_AGP) {
+               DRM_ERROR("Unknown memory type allocation\n");
+               return -EINVAL;
+       }
+       mutex_lock(&dev->struct_mutex);
+       if (0 == ((mem->type == VIA_MEM_VIDEO) ? dev_priv->vram_initialized :
+                     dev_priv->agp_initialized)) {
+               DRM_ERROR
+                   ("Attempt to allocate from uninitialized memory manager.\n");
+               mutex_unlock(&dev->struct_mutex);
+               return -EINVAL;
+       }
+
+       tmpSize = (mem->size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
+       item = drm_sman_alloc(&dev_priv->sman, mem->type, tmpSize, 0,
+                             (unsigned long)file_priv);
+       mutex_unlock(&dev->struct_mutex);
+       if (item) {
+               mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
+                             dev_priv->vram_offset : dev_priv->agp_offset) +
+                   (item->mm->
+                    offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
+               mem->index = item->user_hash.key;
+       } else {
+               mem->offset = 0;
+               mem->size = 0;
+               mem->index = 0;
+               DRM_DEBUG("Video memory allocation failed\n");
+               retval = -ENOMEM;
+       }
+
+       return retval;
+}
+
+int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+       drm_via_mem_t *mem = data;
+       int ret;
+
+       mutex_lock(&dev->struct_mutex);
+       ret = drm_sman_free_key(&dev_priv->sman, mem->index);
+       mutex_unlock(&dev->struct_mutex);
+       DRM_DEBUG("free = 0x%lx\n", mem->index);
+
+       return ret;
+}
+
+
+void via_reclaim_buffers_locked(struct drm_device * dev,
+                               struct drm_file *file_priv)
+{
+       drm_via_private_t *dev_priv = dev->dev_private;
+
+       mutex_lock(&dev->struct_mutex);
+       if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) {
+               mutex_unlock(&dev->struct_mutex);
+               return;
+       }
+
+       if (dev->driver->dma_quiescent) {
+               dev->driver->dma_quiescent(dev);
+       }
+
+       drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv);
+       mutex_unlock(&dev->struct_mutex);
+       return;
+}
diff --git a/drivers/gpu/drm/via/via_verifier.c b/drivers/gpu/drm/via/via_verifier.c
new file mode 100644 (file)
index 0000000..46a5791
--- /dev/null
@@ -0,0 +1,1116 @@
+/*
+ * Copyright 2004 The Unichrome Project. All Rights Reserved.
+ * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Thomas Hellstrom 2004, 2005.
+ * This code was written using docs obtained under NDA from VIA Inc.
+ *
+ * Don't run this code directly on an AGP buffer. Due to cache problems it will
+ * be very slow.
+ */
+
+#include "via_3d_reg.h"
+#include "drmP.h"
+#include "drm.h"
+#include "via_drm.h"
+#include "via_verifier.h"
+#include "via_drv.h"
+
+typedef enum {
+       state_command,
+       state_header2,
+       state_header1,
+       state_vheader5,
+       state_vheader6,
+       state_error
+} verifier_state_t;
+
+typedef enum {
+       no_check = 0,
+       check_for_header2,
+       check_for_header1,
+       check_for_header2_err,
+       check_for_header1_err,
+       check_for_fire,
+       check_z_buffer_addr0,
+       check_z_buffer_addr1,
+       check_z_buffer_addr_mode,
+       check_destination_addr0,
+       check_destination_addr1,
+       check_destination_addr_mode,
+       check_for_dummy,
+       check_for_dd,
+       check_texture_addr0,
+       check_texture_addr1,
+       check_texture_addr2,
+       check_texture_addr3,
+       check_texture_addr4,
+       check_texture_addr5,
+       check_texture_addr6,
+       check_texture_addr7,
+       check_texture_addr8,
+       check_texture_addr_mode,
+       check_for_vertex_count,
+       check_number_texunits,
+       forbidden_command
+} hazard_t;
+
+/*
+ * Associates each hazard above with a possible multi-command
+ * sequence. For example an address that is split over multiple
+ * commands and that needs to be checked at the first command
+ * that does not include any part of the address.
+ */
+
+static drm_via_sequence_t seqs[] = {
+       no_sequence,
+       no_sequence,
+       no_sequence,
+       no_sequence,
+       no_sequence,
+       no_sequence,
+       z_address,
+       z_address,
+       z_address,
+       dest_address,
+       dest_address,
+       dest_address,
+       no_sequence,
+       no_sequence,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       tex_address,
+       no_sequence
+};
+
+typedef struct {
+       unsigned int code;
+       hazard_t hz;
+} hz_init_t;
+
+static hz_init_t init_table1[] = {
+       {0xf2, check_for_header2_err},
+       {0xf0, check_for_header1_err},
+       {0xee, check_for_fire},
+       {0xcc, check_for_dummy},
+       {0xdd, check_for_dd},
+       {0x00, no_check},
+       {0x10, check_z_buffer_addr0},
+       {0x11, check_z_buffer_addr1},
+       {0x12, check_z_buffer_addr_mode},
+       {0x13, no_check},
+       {0x14, no_check},
+       {0x15, no_check},
+       {0x23, no_check},
+       {0x24, no_check},
+       {0x33, no_check},
+       {0x34, no_check},
+       {0x35, no_check},
+       {0x36, no_check},
+       {0x37, no_check},
+       {0x38, no_check},
+       {0x39, no_check},
+       {0x3A, no_check},
+       {0x3B, no_check},
+       {0x3C, no_check},
+       {0x3D, no_check},
+       {0x3E, no_check},
+       {0x40, check_destination_addr0},
+       {0x41, check_destination_addr1},
+       {0x42, check_destination_addr_mode},
+       {0x43, no_check},
+       {0x44, no_check},
+       {0x50, no_check},
+       {0x51, no_check},
+       {0x52, no_check},
+       {0x53, no_check},
+       {0x54, no_check},
+       {0x55, no_check},
+       {0x56, no_check},
+       {0x57, no_check},
+       {0x58, no_check},
+       {0x70, no_check},
+       {0x71, no_check},
+       {0x78, no_check},
+       {0x79, no_check},
+       {0x7A, no_check},
+       {0x7B, no_check},
+       {0x7C, no_check},
+       {0x7D, check_for_vertex_count}
+};
+
+static hz_init_t init_table2[] = {
+       {0xf2, check_for_header2_err},
+       {0xf0, check_for_header1_err},
+       {0xee, check_for_fire},
+       {0xcc, check_for_dummy},
+       {0x00, check_texture_addr0},
+       {0x01, check_texture_addr0},
+       {0x02, check_texture_addr0},
+       {0x03, check_texture_addr0},
+       {0x04, check_texture_addr0},
+       {0x05, check_texture_addr0},
+       {0x06, check_texture_addr0},
+       {0x07, check_texture_addr0},
+       {0x08, check_texture_addr0},
+       {0x09, check_texture_addr0},
+       {0x20, check_texture_addr1},
+       {0x21, check_texture_addr1},
+       {0x22, check_texture_addr1},
+       {0x23, check_texture_addr4},
+       {0x2B, check_texture_addr3},
+       {0x2C, check_texture_addr3},
+       {0x2D, check_texture_addr3},
+       {0x2E, check_texture_addr3},
+       {0x2F, check_texture_addr3},
+       {0x30, check_texture_addr3},
+       {0x31, check_texture_addr3},
+       {0x32, check_texture_addr3},
+       {0x33, check_texture_addr3},
+       {0x34, check_texture_addr3},
+       {0x4B, check_texture_addr5},
+       {0x4C, check_texture_addr6},
+       {0x51, check_texture_addr7},
+       {0x52, check_texture_addr8},
+       {0x77, check_texture_addr2},
+       {0x78, no_check},
+       {0x79, no_check},
+       {0x7A, no_check},
+       {0x7B, check_texture_addr_mode},
+       {0x7C, no_check},
+       {0x7D, no_check},
+       {0x7E, no_check},
+       {0x7F, no_check},
+       {0x80, no_check},
+       {0x81, no_check},
+       {0x82, no_check},
+       {0x83, no_check},
+       {0x85, no_check},
+       {0x86, no_check},
+       {0x87, no_check},
+       {0x88, no_check},
+       {0x89, no_check},
+       {0x8A, no_check},
+       {0x90, no_check},
+       {0x91, no_check},
+       {0x92, no_check},
+       {0x93, no_check}
+};
+
+static hz_init_t init_table3[] = {
+       {0xf2, check_for_header2_err},
+       {0xf0, check_for_header1_err},
+       {0xcc, check_for_dummy},
+       {0x00, check_number_texunits}
+};
+
+static hazard_t table1[256];
+static hazard_t table2[256];
+static hazard_t table3[256];
+
+static __inline__ int
+eat_words(const uint32_t ** buf, const uint32_t * buf_end, unsigned num_words)
+{
+       if ((buf_end - *buf) >= num_words) {
+               *buf += num_words;
+               return 0;
+       }
+       DRM_ERROR("Illegal termination of DMA command buffer\n");
+       return 1;
+}
+
+/*
+ * Partially stolen from drm_memory.h
+ */
+
+static __inline__ drm_local_map_t *via_drm_lookup_agp_map(drm_via_state_t *seq,
+                                                   unsigned long offset,
+                                                   unsigned long size,
+                                                   struct drm_device * dev)
+{
+       struct drm_map_list *r_list;
+       drm_local_map_t *map = seq->map_cache;
+
+       if (map && map->offset <= offset
+           && (offset + size) <= (map->offset + map->size)) {
+               return map;
+       }
+
+       list_for_each_entry(r_list, &dev->maplist, head) {
+               map = r_list->map;
+               if (!map)
+                       continue;
+               if (map->offset <= offset
+                   && (offset + size) <= (map->offset + map->size)
+                   && !(map->flags & _DRM_RESTRICTED)
+                   && (map->type == _DRM_AGP)) {
+                       seq->map_cache = map;
+                       return map;
+               }
+       }
+       return NULL;
+}
+
+/*
+ * Require that all AGP texture levels reside in the same AGP map which should
+ * be mappable by the client. This is not a big restriction.
+ * FIXME: To actually enforce this security policy strictly, drm_rmmap
+ * would have to wait for dma quiescent before removing an AGP map.
+ * The via_drm_lookup_agp_map call in reality seems to take
+ * very little CPU time.
+ */
+
+static __inline__ int finish_current_sequence(drm_via_state_t * cur_seq)
+{
+       switch (cur_seq->unfinished) {
+       case z_address:
+               DRM_DEBUG("Z Buffer start address is 0x%x\n", cur_seq->z_addr);
+               break;
+       case dest_address:
+               DRM_DEBUG("Destination start address is 0x%x\n",
+                         cur_seq->d_addr);
+               break;
+       case tex_address:
+               if (cur_seq->agp_texture) {
+                       unsigned start =
+                           cur_seq->tex_level_lo[cur_seq->texture];
+                       unsigned end = cur_seq->tex_level_hi[cur_seq->texture];
+                       unsigned long lo = ~0, hi = 0, tmp;
+                       uint32_t *addr, *pitch, *height, tex;
+                       unsigned i;
+                       int npot;
+
+                       if (end > 9)
+                               end = 9;
+                       if (start > 9)
+                               start = 9;
+
+                       addr =
+                           &(cur_seq->t_addr[tex = cur_seq->texture][start]);
+                       pitch = &(cur_seq->pitch[tex][start]);
+                       height = &(cur_seq->height[tex][start]);
+                       npot = cur_seq->tex_npot[tex];
+                       for (i = start; i <= end; ++i) {
+                               tmp = *addr++;
+                               if (tmp < lo)
+                                       lo = tmp;
+                               if (i == 0 && npot)
+                                       tmp += (*height++ * *pitch++);
+                               else
+                                       tmp += (*height++ << *pitch++);
+                               if (tmp > hi)
+                                       hi = tmp;
+                       }
+
+                       if (!via_drm_lookup_agp_map
+                           (cur_seq, lo, hi - lo, cur_seq->dev)) {
+                               DRM_ERROR
+                                   ("AGP texture is not in allowed map\n");
+                               return 2;
+                       }
+               }
+               break;
+       default:
+               break;
+       }
+       cur_seq->unfinished = no_sequence;
+       return 0;
+}
+
+static __inline__ int
+investigate_hazard(uint32_t cmd, hazard_t hz, drm_via_state_t * cur_seq)
+{
+       register uint32_t tmp, *tmp_addr;
+
+       if (cur_seq->unfinished && (cur_seq->unfinished != seqs[hz])) {
+               int ret;
+               if ((ret = finish_current_sequence(cur_seq)))
+                       return ret;
+       }
+
+       switch (hz) {
+       case check_for_header2:
+               if (cmd == HALCYON_HEADER2)
+                       return 1;
+               return 0;
+       case check_for_header1:
+               if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
+                       return 1;
+               return 0;
+       case check_for_header2_err:
+               if (cmd == HALCYON_HEADER2)
+                       return 1;
+               DRM_ERROR("Illegal DMA HALCYON_HEADER2 command\n");
+               break;
+       case check_for_header1_err:
+               if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
+                       return 1;
+               DRM_ERROR("Illegal DMA HALCYON_HEADER1 command\n");
+               break;
+       case check_for_fire:
+               if ((cmd & HALCYON_FIREMASK) == HALCYON_FIRECMD)
+                       return 1;
+               DRM_ERROR("Illegal DMA HALCYON_FIRECMD command\n");
+               break;
+       case check_for_dummy:
+               if (HC_DUMMY == cmd)
+                       return 0;
+               DRM_ERROR("Illegal DMA HC_DUMMY command\n");
+               break;
+       case check_for_dd:
+               if (0xdddddddd == cmd)
+                       return 0;
+               DRM_ERROR("Illegal DMA 0xdddddddd command\n");
+               break;
+       case check_z_buffer_addr0:
+               cur_seq->unfinished = z_address;
+               cur_seq->z_addr = (cur_seq->z_addr & 0xFF000000) |
+                   (cmd & 0x00FFFFFF);
+               return 0;
+       case check_z_buffer_addr1:
+               cur_seq->unfinished = z_address;
+               cur_seq->z_addr = (cur_seq->z_addr & 0x00FFFFFF) |
+                   ((cmd & 0xFF) << 24);
+               return 0;
+       case check_z_buffer_addr_mode:
+               cur_seq->unfinished = z_address;
+               if ((cmd & 0x0000C000) == 0)
+                       return 0;
+               DRM_ERROR("Attempt to place Z buffer in system memory\n");
+               return 2;
+       case check_destination_addr0:
+               cur_seq->unfinished = dest_address;
+               cur_seq->d_addr = (cur_seq->d_addr & 0xFF000000) |
+                   (cmd & 0x00FFFFFF);
+               return 0;
+       case check_destination_addr1:
+               cur_seq->unfinished = dest_address;
+               cur_seq->d_addr = (cur_seq->d_addr & 0x00FFFFFF) |
+                   ((cmd & 0xFF) << 24);
+               return 0;
+       case check_destination_addr_mode:
+               cur_seq->unfinished = dest_address;
+               if ((cmd & 0x0000C000) == 0)
+                       return 0;
+               DRM_ERROR
+                   ("Attempt to place 3D drawing buffer in system memory\n");
+               return 2;
+       case check_texture_addr0:
+               cur_seq->unfinished = tex_address;
+               tmp = (cmd >> 24);
+               tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
+               *tmp_addr = (*tmp_addr & 0xFF000000) | (cmd & 0x00FFFFFF);
+               return 0;
+       case check_texture_addr1:
+               cur_seq->unfinished = tex_address;
+               tmp = ((cmd >> 24) - 0x20);
+               tmp += tmp << 1;
+               tmp_addr = &cur_seq->t_addr[cur_seq->texture][tmp];
+               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
+               tmp_addr++;
+               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF00) << 16);
+               tmp_addr++;
+               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF0000) << 8);
+               return 0;
+       case check_texture_addr2:
+               cur_seq->unfinished = tex_address;
+               cur_seq->tex_level_lo[tmp = cur_seq->texture] = cmd & 0x3F;
+               cur_seq->tex_level_hi[tmp] = (cmd & 0xFC0) >> 6;
+               return 0;
+       case check_texture_addr3:
+               cur_seq->unfinished = tex_address;
+               tmp = ((cmd >> 24) - HC_SubA_HTXnL0Pit);
+               if (tmp == 0 &&
+                   (cmd & HC_HTXnEnPit_MASK)) {
+                       cur_seq->pitch[cur_seq->texture][tmp] =
+                               (cmd & HC_HTXnLnPit_MASK);
+                       cur_seq->tex_npot[cur_seq->texture] = 1;
+               } else {
+                       cur_seq->pitch[cur_seq->texture][tmp] =
+                               (cmd & HC_HTXnLnPitE_MASK) >> HC_HTXnLnPitE_SHIFT;
+                       cur_seq->tex_npot[cur_seq->texture] = 0;
+                       if (cmd & 0x000FFFFF) {
+                               DRM_ERROR
+                                       ("Unimplemented texture level 0 pitch mode.\n");
+                               return 2;
+                       }
+               }
+               return 0;
+       case check_texture_addr4:
+               cur_seq->unfinished = tex_address;
+               tmp_addr = &cur_seq->t_addr[cur_seq->texture][9];
+               *tmp_addr = (*tmp_addr & 0x00FFFFFF) | ((cmd & 0xFF) << 24);
+               return 0;
+       case check_texture_addr5:
+       case check_texture_addr6:
+               cur_seq->unfinished = tex_address;
+               /*
+                * Texture width. We don't care since we have the pitch.
+                */
+               return 0;
+       case check_texture_addr7:
+               cur_seq->unfinished = tex_address;
+               tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
+               tmp_addr[5] = 1 << ((cmd & 0x00F00000) >> 20);
+               tmp_addr[4] = 1 << ((cmd & 0x000F0000) >> 16);
+               tmp_addr[3] = 1 << ((cmd & 0x0000F000) >> 12);
+               tmp_addr[2] = 1 << ((cmd & 0x00000F00) >> 8);
+               tmp_addr[1] = 1 << ((cmd & 0x000000F0) >> 4);
+               tmp_addr[0] = 1 << (cmd & 0x0000000F);
+               return 0;
+       case check_texture_addr8:
+               cur_seq->unfinished = tex_address;
+               tmp_addr = &(cur_seq->height[cur_seq->texture][0]);
+               tmp_addr[9] = 1 << ((cmd & 0x0000F000) >> 12);
+               tmp_addr[8] = 1 << ((cmd & 0x00000F00) >> 8);
+               tmp_addr[7] = 1 << ((cmd & 0x000000F0) >> 4);
+               tmp_addr[6] = 1 << (cmd & 0x0000000F);
+               return 0;
+       case check_texture_addr_mode:
+               cur_seq->unfinished = tex_address;
+               if (2 == (tmp = cmd & 0x00000003)) {
+                       DRM_ERROR
+                           ("Attempt to fetch texture from system memory.\n");
+                       return 2;
+               }
+               cur_seq->agp_texture = (tmp == 3);
+               cur_seq->tex_palette_size[cur_seq->texture] =
+                   (cmd >> 16) & 0x000000007;
+               return 0;
+       case check_for_vertex_count:
+               cur_seq->vertex_count = cmd & 0x0000FFFF;
+               return 0;
+       case check_number_texunits:
+               cur_seq->multitex = (cmd >> 3) & 1;
+               return 0;
+       default:
+               DRM_ERROR("Illegal DMA data: 0x%x\n", cmd);
+               return 2;
+       }
+       return 2;
+}
+
+static __inline__ int
+via_check_prim_list(uint32_t const **buffer, const uint32_t * buf_end,
+                   drm_via_state_t * cur_seq)
+{
+       drm_via_private_t *dev_priv =
+           (drm_via_private_t *) cur_seq->dev->dev_private;
+       uint32_t a_fire, bcmd, dw_count;
+       int ret = 0;
+       int have_fire;
+       const uint32_t *buf = *buffer;
+
+       while (buf < buf_end) {
+               have_fire = 0;
+               if ((buf_end - buf) < 2) {
+                       DRM_ERROR
+                           ("Unexpected termination of primitive list.\n");
+                       ret = 1;
+                       break;
+               }
+               if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdB)
+                       break;
+               bcmd = *buf++;
+               if ((*buf & HC_ACMD_MASK) != HC_ACMD_HCmdA) {
+                       DRM_ERROR("Expected Vertex List A command, got 0x%x\n",
+                                 *buf);
+                       ret = 1;
+                       break;
+               }
+               a_fire =
+                   *buf++ | HC_HPLEND_MASK | HC_HPMValidN_MASK |
+                   HC_HE3Fire_MASK;
+
+               /*
+                * How many dwords per vertex ?
+                */
+
+               if (cur_seq->agp && ((bcmd & (0xF << 11)) == 0)) {
+                       DRM_ERROR("Illegal B command vertex data for AGP.\n");
+                       ret = 1;
+                       break;
+               }
+
+               dw_count = 0;
+               if (bcmd & (1 << 7))
+                       dw_count += (cur_seq->multitex) ? 2 : 1;
+               if (bcmd & (1 << 8))
+                       dw_count += (cur_seq->multitex) ? 2 : 1;
+               if (bcmd & (1 << 9))
+                       dw_count++;
+               if (bcmd & (1 << 10))
+                       dw_count++;
+               if (bcmd & (1 << 11))
+                       dw_count++;
+               if (bcmd & (1 << 12))
+                       dw_count++;
+               if (bcmd & (1 << 13))
+                       dw_count++;
+               if (bcmd & (1 << 14))
+                       dw_count++;
+
+               while (buf < buf_end) {
+                       if (*buf == a_fire) {
+                               if (dev_priv->num_fire_offsets >=
+                                   VIA_FIRE_BUF_SIZE) {
+                                       DRM_ERROR("Fire offset buffer full.\n");
+                                       ret = 1;
+                                       break;
+                               }
+                               dev_priv->fire_offsets[dev_priv->
+                                                      num_fire_offsets++] =
+                                   buf;
+                               have_fire = 1;
+                               buf++;
+                               if (buf < buf_end && *buf == a_fire)
+                                       buf++;
+                               break;
+                       }
+                       if ((*buf == HALCYON_HEADER2) ||
+                           ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD)) {
+                               DRM_ERROR("Missing Vertex Fire command, "
+                                         "Stray Vertex Fire command  or verifier "
+                                         "lost sync.\n");
+                               ret = 1;
+                               break;
+                       }
+                       if ((ret = eat_words(&buf, buf_end, dw_count)))
+                               break;
+               }
+               if (buf >= buf_end && !have_fire) {
+                       DRM_ERROR("Missing Vertex Fire command or verifier "
+                                 "lost sync.\n");
+                       ret = 1;
+                       break;
+               }
+               if (cur_seq->agp && ((buf - cur_seq->buf_start) & 0x01)) {
+                       DRM_ERROR("AGP Primitive list end misaligned.\n");
+                       ret = 1;
+                       break;
+               }
+       }
+       *buffer = buf;
+       return ret;
+}
+
+static __inline__ verifier_state_t
+via_check_header2(uint32_t const **buffer, const uint32_t * buf_end,
+                 drm_via_state_t * hc_state)
+{
+       uint32_t cmd;
+       int hz_mode;
+       hazard_t hz;
+       const uint32_t *buf = *buffer;
+       const hazard_t *hz_table;
+
+       if ((buf_end - buf) < 2) {
+               DRM_ERROR
+                   ("Illegal termination of DMA HALCYON_HEADER2 sequence.\n");
+               return state_error;
+       }
+       buf++;
+       cmd = (*buf++ & 0xFFFF0000) >> 16;
+
+       switch (cmd) {
+       case HC_ParaType_CmdVdata:
+               if (via_check_prim_list(&buf, buf_end, hc_state))
+                       return state_error;
+               *buffer = buf;
+               return state_command;
+       case HC_ParaType_NotTex:
+               hz_table = table1;
+               break;
+       case HC_ParaType_Tex:
+               hc_state->texture = 0;
+               hz_table = table2;
+               break;
+       case (HC_ParaType_Tex | (HC_SubType_Tex1 << 8)):
+               hc_state->texture = 1;
+               hz_table = table2;
+               break;
+       case (HC_ParaType_Tex | (HC_SubType_TexGeneral << 8)):
+               hz_table = table3;
+               break;
+       case HC_ParaType_Auto:
+               if (eat_words(&buf, buf_end, 2))
+                       return state_error;
+               *buffer = buf;
+               return state_command;
+       case (HC_ParaType_Palette | (HC_SubType_Stipple << 8)):
+               if (eat_words(&buf, buf_end, 32))
+                       return state_error;
+               *buffer = buf;
+               return state_command;
+       case (HC_ParaType_Palette | (HC_SubType_TexPalette0 << 8)):
+       case (HC_ParaType_Palette | (HC_SubType_TexPalette1 << 8)):
+               DRM_ERROR("Texture palettes are rejected because of "
+                         "lack of info how to determine their size.\n");
+               return state_error;
+       case (HC_ParaType_Palette | (HC_SubType_FogTable << 8)):
+               DRM_ERROR("Fog factor palettes are rejected because of "
+                         "lack of info how to determine their size.\n");
+               return state_error;
+       default:
+
+               /*
+                * There are some unimplemented HC_ParaTypes here, that
+                * need to be implemented if the Mesa driver is extended.
+                */
+
+               DRM_ERROR("Invalid or unimplemented HALCYON_HEADER2 "
+                         "DMA subcommand: 0x%x. Previous dword: 0x%x\n",
+                         cmd, *(buf - 2));
+               *buffer = buf;
+               return state_error;
+       }
+
+       while (buf < buf_end) {
+               cmd = *buf++;
+               if ((hz = hz_table[cmd >> 24])) {
+                       if ((hz_mode = investigate_hazard(cmd, hz, hc_state))) {
+                               if (hz_mode == 1) {
+                                       buf--;
+                                       break;
+                               }
+                               return state_error;
+                       }
+               } else if (hc_state->unfinished &&
+                          finish_current_sequence(hc_state)) {
+                       return state_error;
+               }
+       }
+       if (hc_state->unfinished && finish_current_sequence(hc_state)) {
+               return state_error;
+       }
+       *buffer = buf;
+       return state_command;
+}
+
+static __inline__ verifier_state_t
+via_parse_header2(drm_via_private_t * dev_priv, uint32_t const **buffer,
+                 const uint32_t * buf_end, int *fire_count)
+{
+       uint32_t cmd;
+       const uint32_t *buf = *buffer;
+       const uint32_t *next_fire;
+       int burst = 0;
+
+       next_fire = dev_priv->fire_offsets[*fire_count];
+       buf++;
+       cmd = (*buf & 0xFFFF0000) >> 16;
+       VIA_WRITE(HC_REG_TRANS_SET + HC_REG_BASE, *buf++);
+       switch (cmd) {
+       case HC_ParaType_CmdVdata:
+               while ((buf < buf_end) &&
+                      (*fire_count < dev_priv->num_fire_offsets) &&
+                      (*buf & HC_ACMD_MASK) == HC_ACMD_HCmdB) {
+                       while (buf <= next_fire) {
+                               VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
+                                         (burst & 63), *buf++);
+                               burst += 4;
+                       }
+                       if ((buf < buf_end)
+                           && ((*buf & HALCYON_FIREMASK) == HALCYON_FIRECMD))
+                               buf++;
+
+                       if (++(*fire_count) < dev_priv->num_fire_offsets)
+                               next_fire = dev_priv->fire_offsets[*fire_count];
+               }
+               break;
+       default:
+               while (buf < buf_end) {
+
+                       if (*buf == HC_HEADER2 ||
+                           (*buf & HALCYON_HEADER1MASK) == HALCYON_HEADER1 ||
+                           (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5 ||
+                           (*buf & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
+                               break;
+
+                       VIA_WRITE(HC_REG_TRANS_SPACE + HC_REG_BASE +
+                                 (burst & 63), *buf++);
+                       burst += 4;
+               }
+       }
+       *buffer = buf;
+       return state_command;
+}
+
+static __inline__ int verify_mmio_address(uint32_t address)
+{
+       if ((address > 0x3FF) && (address < 0xC00)) {
+               DRM_ERROR("Invalid VIDEO DMA command. "
+                         "Attempt to access 3D- or command burst area.\n");
+               return 1;
+       } else if ((address > 0xCFF) && (address < 0x1300)) {
+               DRM_ERROR("Invalid VIDEO DMA command. "
+                         "Attempt to access PCI DMA area.\n");
+               return 1;
+       } else if (address > 0x13FF) {
+               DRM_ERROR("Invalid VIDEO DMA command. "
+                         "Attempt to access VGA registers.\n");
+               return 1;
+       }
+       return 0;
+}
+
+static __inline__ int
+verify_video_tail(uint32_t const **buffer, const uint32_t * buf_end,
+                 uint32_t dwords)
+{
+       const uint32_t *buf = *buffer;
+
+       if (buf_end - buf < dwords) {
+               DRM_ERROR("Illegal termination of video command.\n");
+               return 1;
+       }
+       while (dwords--) {
+               if (*buf++) {
+                       DRM_ERROR("Illegal video command tail.\n");
+                       return 1;
+               }
+       }
+       *buffer = buf;
+       return 0;
+}
+
+static __inline__ verifier_state_t
+via_check_header1(uint32_t const **buffer, const uint32_t * buf_end)
+{
+       uint32_t cmd;
+       const uint32_t *buf = *buffer;
+       verifier_state_t ret = state_command;
+
+       while (buf < buf_end) {
+               cmd = *buf;
+               if ((cmd > ((0x3FF >> 2) | HALCYON_HEADER1)) &&
+                   (cmd < ((0xC00 >> 2) | HALCYON_HEADER1))) {
+                       if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
+                               break;
+                       DRM_ERROR("Invalid HALCYON_HEADER1 command. "
+                                 "Attempt to access 3D- or command burst area.\n");
+                       ret = state_error;
+                       break;
+               } else if (cmd > ((0xCFF >> 2) | HALCYON_HEADER1)) {
+                       if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
+                               break;
+                       DRM_ERROR("Invalid HALCYON_HEADER1 command. "
+                                 "Attempt to access VGA registers.\n");
+                       ret = state_error;
+                       break;
+               } else {
+                       buf += 2;
+               }
+       }
+       *buffer = buf;
+       return ret;
+}
+
+static __inline__ verifier_state_t
+via_parse_header1(drm_via_private_t * dev_priv, uint32_t const **buffer,
+                 const uint32_t * buf_end)
+{
+       register uint32_t cmd;
+       const uint32_t *buf = *buffer;
+
+       while (buf < buf_end) {
+               cmd = *buf;
+               if ((cmd & HALCYON_HEADER1MASK) != HALCYON_HEADER1)
+                       break;
+               VIA_WRITE((cmd & ~HALCYON_HEADER1MASK) << 2, *++buf);
+               buf++;
+       }
+       *buffer = buf;
+       return state_command;
+}
+
+static __inline__ verifier_state_t
+via_check_vheader5(uint32_t const **buffer, const uint32_t * buf_end)
+{
+       uint32_t data;
+       const uint32_t *buf = *buffer;
+
+       if (buf_end - buf < 4) {
+               DRM_ERROR("Illegal termination of video header5 command\n");
+               return state_error;
+       }
+
+       data = *buf++ & ~VIA_VIDEOMASK;
+       if (verify_mmio_address(data))
+               return state_error;
+
+       data = *buf++;
+       if (*buf++ != 0x00F50000) {
+               DRM_ERROR("Illegal header5 header data\n");
+               return state_error;
+       }
+       if (*buf++ != 0x00000000) {
+               DRM_ERROR("Illegal header5 header data\n");
+               return state_error;
+       }
+       if (eat_words(&buf, buf_end, data))
+               return state_error;
+       if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
+               return state_error;
+       *buffer = buf;
+       return state_command;
+
+}
+
+static __inline__ verifier_state_t
+via_parse_vheader5(drm_via_private_t * dev_priv, uint32_t const **buffer,
+                  const uint32_t * buf_end)
+{
+       uint32_t addr, count, i;
+       const uint32_t *buf = *buffer;
+
+       addr = *buf++ & ~VIA_VIDEOMASK;
+       i = count = *buf;
+       buf += 3;
+       while (i--) {
+               VIA_WRITE(addr, *buf++);
+       }
+       if (count & 3)
+               buf += 4 - (count & 3);
+       *buffer = buf;
+       return state_command;
+}
+
+static __inline__ verifier_state_t
+via_check_vheader6(uint32_t const **buffer, const uint32_t * buf_end)
+{
+       uint32_t data;
+       const uint32_t *buf = *buffer;
+       uint32_t i;
+
+       if (buf_end - buf < 4) {
+               DRM_ERROR("Illegal termination of video header6 command\n");
+               return state_error;
+       }
+       buf++;
+       data = *buf++;
+       if (*buf++ != 0x00F60000) {
+               DRM_ERROR("Illegal header6 header data\n");
+               return state_error;
+       }
+       if (*buf++ != 0x00000000) {
+               DRM_ERROR("Illegal header6 header data\n");
+               return state_error;
+       }
+       if ((buf_end - buf) < (data << 1)) {
+               DRM_ERROR("Illegal termination of video header6 command\n");
+               return state_error;
+       }
+       for (i = 0; i < data; ++i) {
+               if (verify_mmio_address(*buf++))
+                       return state_error;
+               buf++;
+       }
+       data <<= 1;
+       if ((data & 3) && verify_video_tail(&buf, buf_end, 4 - (data & 3)))
+               return state_error;
+       *buffer = buf;
+       return state_command;
+}
+
+static __inline__ verifier_state_t
+via_parse_vheader6(drm_via_private_t * dev_priv, uint32_t const **buffer,
+                  const uint32_t * buf_end)
+{
+
+       uint32_t addr, count, i;
+       const uint32_t *buf = *buffer;
+
+       i = count = *++buf;
+       buf += 3;
+       while (i--) {
+               addr = *buf++;
+               VIA_WRITE(addr, *buf++);
+       }
+       count <<= 1;
+       if (count & 3)
+               buf += 4 - (count & 3);
+       *buffer = buf;
+       return state_command;
+}
+
+int
+via_verify_command_stream(const uint32_t * buf, unsigned int size,
+                         struct drm_device * dev, int agp)
+{
+
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       drm_via_state_t *hc_state = &dev_priv->hc_state;
+       drm_via_state_t saved_state = *hc_state;
+       uint32_t cmd;
+       const uint32_t *buf_end = buf + (size >> 2);
+       verifier_state_t state = state_command;
+       int cme_video;
+       int supported_3d;
+
+       cme_video = (dev_priv->chipset == VIA_PRO_GROUP_A ||
+                    dev_priv->chipset == VIA_DX9_0);
+
+       supported_3d = dev_priv->chipset != VIA_DX9_0;
+
+       hc_state->dev = dev;
+       hc_state->unfinished = no_sequence;
+       hc_state->map_cache = NULL;
+       hc_state->agp = agp;
+       hc_state->buf_start = buf;
+       dev_priv->num_fire_offsets = 0;
+
+       while (buf < buf_end) {
+
+               switch (state) {
+               case state_header2:
+                       state = via_check_header2(&buf, buf_end, hc_state);
+                       break;
+               case state_header1:
+                       state = via_check_header1(&buf, buf_end);
+                       break;
+               case state_vheader5:
+                       state = via_check_vheader5(&buf, buf_end);
+                       break;
+               case state_vheader6:
+                       state = via_check_vheader6(&buf, buf_end);
+                       break;
+               case state_command:
+                       if ((HALCYON_HEADER2 == (cmd = *buf)) &&
+                           supported_3d)
+                               state = state_header2;
+                       else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
+                               state = state_header1;
+                       else if (cme_video
+                                && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
+                               state = state_vheader5;
+                       else if (cme_video
+                                && (cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
+                               state = state_vheader6;
+                       else if ((cmd == HALCYON_HEADER2) && !supported_3d) {
+                               DRM_ERROR("Accelerated 3D is not supported on this chipset yet.\n");
+                               state = state_error;
+                       } else {
+                               DRM_ERROR
+                                   ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
+                                    cmd);
+                               state = state_error;
+                       }
+                       break;
+               case state_error:
+               default:
+                       *hc_state = saved_state;
+                       return -EINVAL;
+               }
+       }
+       if (state == state_error) {
+               *hc_state = saved_state;
+               return -EINVAL;
+       }
+       return 0;
+}
+
+int
+via_parse_command_stream(struct drm_device * dev, const uint32_t * buf,
+                        unsigned int size)
+{
+
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       uint32_t cmd;
+       const uint32_t *buf_end = buf + (size >> 2);
+       verifier_state_t state = state_command;
+       int fire_count = 0;
+
+       while (buf < buf_end) {
+
+               switch (state) {
+               case state_header2:
+                       state =
+                           via_parse_header2(dev_priv, &buf, buf_end,
+                                             &fire_count);
+                       break;
+               case state_header1:
+                       state = via_parse_header1(dev_priv, &buf, buf_end);
+                       break;
+               case state_vheader5:
+                       state = via_parse_vheader5(dev_priv, &buf, buf_end);
+                       break;
+               case state_vheader6:
+                       state = via_parse_vheader6(dev_priv, &buf, buf_end);
+                       break;
+               case state_command:
+                       if (HALCYON_HEADER2 == (cmd = *buf))
+                               state = state_header2;
+                       else if ((cmd & HALCYON_HEADER1MASK) == HALCYON_HEADER1)
+                               state = state_header1;
+                       else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER5)
+                               state = state_vheader5;
+                       else if ((cmd & VIA_VIDEOMASK) == VIA_VIDEO_HEADER6)
+                               state = state_vheader6;
+                       else {
+                               DRM_ERROR
+                                   ("Invalid / Unimplemented DMA HEADER command. 0x%x\n",
+                                    cmd);
+                               state = state_error;
+                       }
+                       break;
+               case state_error:
+               default:
+                       return -EINVAL;
+               }
+       }
+       if (state == state_error) {
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static void
+setup_hazard_table(hz_init_t init_table[], hazard_t table[], int size)
+{
+       int i;
+
+       for (i = 0; i < 256; ++i) {
+               table[i] = forbidden_command;
+       }
+
+       for (i = 0; i < size; ++i) {
+               table[init_table[i].code] = init_table[i].hz;
+       }
+}
+
+void via_init_command_verifier(void)
+{
+       setup_hazard_table(init_table1, table1,
+                          sizeof(init_table1) / sizeof(hz_init_t));
+       setup_hazard_table(init_table2, table2,
+                          sizeof(init_table2) / sizeof(hz_init_t));
+       setup_hazard_table(init_table3, table3,
+                          sizeof(init_table3) / sizeof(hz_init_t));
+}
diff --git a/drivers/gpu/drm/via/via_verifier.h b/drivers/gpu/drm/via/via_verifier.h
new file mode 100644 (file)
index 0000000..d6f8214
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004 The Unichrome Project. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE UNICHROME PROJECT, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Thomas Hellström 2004.
+ */
+
+#ifndef _VIA_VERIFIER_H_
+#define _VIA_VERIFIER_H_
+
+typedef enum {
+       no_sequence = 0,
+       z_address,
+       dest_address,
+       tex_address
+} drm_via_sequence_t;
+
+typedef struct {
+       unsigned texture;
+       uint32_t z_addr;
+       uint32_t d_addr;
+       uint32_t t_addr[2][10];
+       uint32_t pitch[2][10];
+       uint32_t height[2][10];
+       uint32_t tex_level_lo[2];
+       uint32_t tex_level_hi[2];
+       uint32_t tex_palette_size[2];
+       uint32_t tex_npot[2];
+       drm_via_sequence_t unfinished;
+       int agp_texture;
+       int multitex;
+       struct drm_device *dev;
+       drm_local_map_t *map_cache;
+       uint32_t vertex_count;
+       int agp;
+       const uint32_t *buf_start;
+} drm_via_state_t;
+
+extern int via_verify_command_stream(const uint32_t * buf, unsigned int size,
+                                    struct drm_device * dev, int agp);
+extern int via_parse_command_stream(struct drm_device *dev, const uint32_t *buf,
+                                   unsigned int size);
+
+#endif
diff --git a/drivers/gpu/drm/via/via_video.c b/drivers/gpu/drm/via/via_video.c
new file mode 100644 (file)
index 0000000..6ec04ac
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005 Thomas Hellstrom. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Thomas Hellstrom 2005.
+ *
+ * Video and XvMC related functions.
+ */
+
+#include "drmP.h"
+#include "via_drm.h"
+#include "via_drv.h"
+
+void via_init_futex(drm_via_private_t * dev_priv)
+{
+       unsigned int i;
+
+       DRM_DEBUG("\n");
+
+       for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
+               DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
+               XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
+       }
+}
+
+void via_cleanup_futex(drm_via_private_t * dev_priv)
+{
+}
+
+void via_release_futex(drm_via_private_t * dev_priv, int context)
+{
+       unsigned int i;
+       volatile int *lock;
+
+       if (!dev_priv->sarea_priv)
+               return;
+
+       for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
+               lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
+               if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
+                       if (_DRM_LOCK_IS_HELD(*lock)
+                           && (*lock & _DRM_LOCK_CONT)) {
+                               DRM_WAKEUP(&(dev_priv->decoder_queue[i]));
+                       }
+                       *lock = 0;
+               }
+       }
+}
+
+int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+       drm_via_futex_t *fx = data;
+       volatile int *lock;
+       drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
+       drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
+       int ret = 0;
+
+       DRM_DEBUG("\n");
+
+       if (fx->lock > VIA_NR_XVMC_LOCKS)
+               return -EFAULT;
+
+       lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
+
+       switch (fx->func) {
+       case VIA_FUTEX_WAIT:
+               DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
+                           (fx->ms / 10) * (DRM_HZ / 100), *lock != fx->val);
+               return ret;
+       case VIA_FUTEX_WAKE:
+               DRM_WAKEUP(&(dev_priv->decoder_queue[fx->lock]));
+               return 0;
+       }
+       return 0;
+}
index 1ca6f46..2fde6c6 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/major.h>
 #include <linux/hid.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 
 #include <linux/hidraw.h>
 
@@ -157,6 +158,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
        struct hidraw_list *list;
        int err = 0;
 
+       lock_kernel();
        if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) {
                err = -ENOMEM;
                goto out;
@@ -183,6 +185,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
 out_unlock:
        spin_unlock(&minors_lock);
 out:
+       unlock_kernel();
        return err;
 
 }
index eb69fba..dde6ce9 100644 (file)
@@ -39,7 +39,6 @@
 #include <asm/io.h>
 #include <asm/arch/i2c.h>
 #include <asm/arch/pxa-regs.h>
-#include <asm/arch/pxa2xx-gpio.h>
 
 struct pxa_i2c {
        spinlock_t              lock;
@@ -945,32 +944,6 @@ static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
        .functionality  = i2c_pxa_functionality,
 };
 
-static void i2c_pxa_enable(struct platform_device *dev)
-{
-       if (cpu_is_pxa27x()) {
-               switch (dev->id) {
-               case 0:
-                       pxa_gpio_mode(GPIO117_I2CSCL_MD);
-                       pxa_gpio_mode(GPIO118_I2CSDA_MD);
-                       break;
-               case 1:
-                       local_irq_disable();
-                       PCFR |= PCFR_PI2CEN;
-                       local_irq_enable();
-                       break;
-               }
-       }
-}
-
-static void i2c_pxa_disable(struct platform_device *dev)
-{
-       if (cpu_is_pxa27x() && dev->id == 1) {
-               local_irq_disable();
-               PCFR &= ~PCFR_PI2CEN;
-               local_irq_enable();
-       }
-}
-
 #define res_len(r)             ((r)->end - (r)->start + 1)
 static int i2c_pxa_probe(struct platform_device *dev)
 {
@@ -1036,7 +1009,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
 #endif
 
        clk_enable(i2c->clk);
-       i2c_pxa_enable(dev);
 
        if (plat) {
                i2c->adap.class = plat->class;
@@ -1080,7 +1052,6 @@ eadapt:
                free_irq(irq, i2c);
 ereqirq:
        clk_disable(i2c->clk);
-       i2c_pxa_disable(dev);
        iounmap(i2c->reg_base);
 eremap:
        clk_put(i2c->clk);
@@ -1103,7 +1074,6 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
 
        clk_disable(i2c->clk);
        clk_put(i2c->clk);
-       i2c_pxa_disable(dev);
 
        iounmap(i2c->reg_base);
        release_mem_region(i2c->iobase, i2c->iosize);
index b1b45dd..03a33f1 100644 (file)
@@ -72,7 +72,7 @@ struct isp1301 {
 };
 
 
-/* bits in OTG_CTRL_REG */
+/* bits in OTG_CTRL */
 
 #define        OTG_XCEIV_OUTPUTS \
        (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
@@ -186,8 +186,8 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
 
 /* operational registers */
 #define        ISP1301_MODE_CONTROL_1          0x04    /* u8 read, set, +1 clear */
-#      define  MC1_SPEED_REG           (1 << 0)
-#      define  MC1_SUSPEND_REG         (1 << 1)
+#      define  MC1_SPEED               (1 << 0)
+#      define  MC1_SUSPEND             (1 << 1)
 #      define  MC1_DAT_SE0             (1 << 2)
 #      define  MC1_TRANSPARENT         (1 << 3)
 #      define  MC1_BDIS_ACON_EN        (1 << 4)
@@ -274,7 +274,7 @@ static void power_down(struct isp1301 *isp)
        isp->otg.state = OTG_STATE_UNDEFINED;
 
        // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
-       isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
+       isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
 
        isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
        isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
@@ -283,7 +283,7 @@ static void power_down(struct isp1301 *isp)
 static void power_up(struct isp1301 *isp)
 {
        // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
-       isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
+       isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
 
        /* do this only when cpu is driving transceiver,
         * so host won't see a low speed device...
@@ -360,6 +360,8 @@ isp1301_defer_work(struct isp1301 *isp, int work)
 /* called from irq handlers */
 static void a_idle(struct isp1301 *isp, const char *tag)
 {
+       u32 l;
+
        if (isp->otg.state == OTG_STATE_A_IDLE)
                return;
 
@@ -373,13 +375,17 @@ static void a_idle(struct isp1301 *isp, const char *tag)
                gadget_suspend(isp);
        }
        isp->otg.state = OTG_STATE_A_IDLE;
-       isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
+       l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
+       omap_writel(l, OTG_CTRL);
+       isp->last_otg_ctrl = l;
        pr_debug("  --> %s/%s\n", state_name(isp), tag);
 }
 
 /* called from irq handlers */
 static void b_idle(struct isp1301 *isp, const char *tag)
 {
+       u32 l;
+
        if (isp->otg.state == OTG_STATE_B_IDLE)
                return;
 
@@ -393,7 +399,9 @@ static void b_idle(struct isp1301 *isp, const char *tag)
                gadget_suspend(isp);
        }
        isp->otg.state = OTG_STATE_B_IDLE;
-       isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
+       l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
+       omap_writel(l, OTG_CTRL);
+       isp->last_otg_ctrl = l;
        pr_debug("  --> %s/%s\n", state_name(isp), tag);
 }
 
@@ -406,7 +414,7 @@ dump_regs(struct isp1301 *isp, const char *label)
        u8      src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
 
        pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
-               OTG_CTRL_REG, label, state_name(isp),
+               omap_readl(OTG_CTRL), label, state_name(isp),
                ctrl, status, src);
        /* mode control and irq enables don't change much */
 #endif
@@ -429,7 +437,7 @@ dump_regs(struct isp1301 *isp, const char *label)
 static void check_state(struct isp1301 *isp, const char *tag)
 {
        enum usb_otg_state      state = OTG_STATE_UNDEFINED;
-       u8                      fsm = OTG_TEST_REG & 0x0ff;
+       u8                      fsm = omap_readw(OTG_TEST) & 0x0ff;
        unsigned                extra = 0;
 
        switch (fsm) {
@@ -494,7 +502,8 @@ static void check_state(struct isp1301 *isp, const char *tag)
        if (isp->otg.state == state && !extra)
                return;
        pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
-               state_string(state), fsm, state_name(isp), OTG_CTRL_REG);
+               state_string(state), fsm, state_name(isp),
+               omap_readl(OTG_CTRL));
 }
 
 #else
@@ -508,10 +517,11 @@ static void update_otg1(struct isp1301 *isp, u8 int_src)
 {
        u32     otg_ctrl;
 
-       otg_ctrl = OTG_CTRL_REG
-                       & OTG_CTRL_MASK
-                       & ~OTG_XCEIV_INPUTS
-                       & ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
+       otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
+       otg_ctrl &= ~OTG_XCEIV_INPUTS;
+       otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
+
+
        if (int_src & INTR_SESS_VLD)
                otg_ctrl |= OTG_ASESSVLD;
        else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
@@ -534,7 +544,7 @@ static void update_otg1(struct isp1301 *isp, u8 int_src)
                        return;
                }
        }
-       OTG_CTRL_REG = otg_ctrl;
+       omap_writel(otg_ctrl, OTG_CTRL);
 }
 
 /* outputs from ISP1301_OTG_STATUS */
@@ -542,15 +552,14 @@ static void update_otg2(struct isp1301 *isp, u8 otg_status)
 {
        u32     otg_ctrl;
 
-       otg_ctrl = OTG_CTRL_REG
-                       & OTG_CTRL_MASK
-                       & ~OTG_XCEIV_INPUTS
-                       & ~(OTG_BSESSVLD|OTG_BSESSEND);
+       otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
+       otg_ctrl &= ~OTG_XCEIV_INPUTS;
+       otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
        if (otg_status & OTG_B_SESS_VLD)
                otg_ctrl |= OTG_BSESSVLD;
        else if (otg_status & OTG_B_SESS_END)
                otg_ctrl |= OTG_BSESSEND;
-       OTG_CTRL_REG = otg_ctrl;
+       omap_writel(otg_ctrl, OTG_CTRL);
 }
 
 /* inputs going to ISP1301 */
@@ -559,7 +568,7 @@ static void otg_update_isp(struct isp1301 *isp)
        u32     otg_ctrl, otg_change;
        u8      set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
 
-       otg_ctrl = OTG_CTRL_REG;
+       otg_ctrl = omap_readl(OTG_CTRL);
        otg_change = otg_ctrl ^ isp->last_otg_ctrl;
        isp->last_otg_ctrl = otg_ctrl;
        otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
@@ -639,6 +648,8 @@ pulldown:
 
        /* HNP switch to host or peripheral; and SRP */
        if (otg_change & OTG_PULLUP) {
+               u32 l;
+
                switch (isp->otg.state) {
                case OTG_STATE_B_IDLE:
                        if (clr & OTG1_DP_PULLUP)
@@ -655,7 +666,9 @@ pulldown:
                default:
                        break;
                }
-               OTG_CTRL_REG |= OTG_PULLUP;
+               l = omap_readl(OTG_CTRL);
+               l |= OTG_PULLUP;
+               omap_writel(l, OTG_CTRL);
        }
 
        check_state(isp, __func__);
@@ -664,20 +677,20 @@ pulldown:
 
 static irqreturn_t omap_otg_irq(int irq, void *_isp)
 {
-       u16             otg_irq = OTG_IRQ_SRC_REG;
+       u16             otg_irq = omap_readw(OTG_IRQ_SRC);
        u32             otg_ctrl;
        int             ret = IRQ_NONE;
        struct isp1301  *isp = _isp;
 
        /* update ISP1301 transciever from OTG controller */
        if (otg_irq & OPRT_CHG) {
-               OTG_IRQ_SRC_REG = OPRT_CHG;
+               omap_writew(OPRT_CHG, OTG_IRQ_SRC);
                isp1301_defer_work(isp, WORK_UPDATE_ISP);
                ret = IRQ_HANDLED;
 
        /* SRP to become b_peripheral failed */
        } else if (otg_irq & B_SRP_TMROUT) {
-               pr_debug("otg: B_SRP_TIMEOUT, %06x\n", OTG_CTRL_REG);
+               pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
                notresponding(isp);
 
                /* gadget drivers that care should monitor all kinds of
@@ -687,31 +700,31 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                if (isp->otg.state == OTG_STATE_B_SRP_INIT)
                        b_idle(isp, "srp_timeout");
 
-               OTG_IRQ_SRC_REG = B_SRP_TMROUT;
+               omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
        /* HNP to become b_host failed */
        } else if (otg_irq & B_HNP_FAIL) {
                pr_debug("otg: %s B_HNP_FAIL, %06x\n",
-                               state_name(isp), OTG_CTRL_REG);
+                               state_name(isp), omap_readl(OTG_CTRL));
                notresponding(isp);
 
-               otg_ctrl = OTG_CTRL_REG;
+               otg_ctrl = omap_readl(OTG_CTRL);
                otg_ctrl |= OTG_BUSDROP;
                otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
-               OTG_CTRL_REG = otg_ctrl;
+               omap_writel(otg_ctrl, OTG_CTRL);
 
                /* subset of b_peripheral()... */
                isp->otg.state = OTG_STATE_B_PERIPHERAL;
                pr_debug("  --> b_peripheral\n");
 
-               OTG_IRQ_SRC_REG = B_HNP_FAIL;
+               omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
        /* detect SRP from B-device ... */
        } else if (otg_irq & A_SRP_DETECT) {
                pr_debug("otg: %s SRP_DETECT, %06x\n",
-                               state_name(isp), OTG_CTRL_REG);
+                               state_name(isp), omap_readl(OTG_CTRL));
 
                isp1301_defer_work(isp, WORK_UPDATE_OTG);
                switch (isp->otg.state) {
@@ -719,49 +732,49 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                        if (!isp->otg.host)
                                break;
                        isp1301_defer_work(isp, WORK_HOST_RESUME);
-                       otg_ctrl = OTG_CTRL_REG;
+                       otg_ctrl = omap_readl(OTG_CTRL);
                        otg_ctrl |= OTG_A_BUSREQ;
                        otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
                                        & ~OTG_XCEIV_INPUTS
                                        & OTG_CTRL_MASK;
-                       OTG_CTRL_REG = otg_ctrl;
+                       omap_writel(otg_ctrl, OTG_CTRL);
                        break;
                default:
                        break;
                }
 
-               OTG_IRQ_SRC_REG = A_SRP_DETECT;
+               omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
        /* timer expired:  T(a_wait_bcon) and maybe T(a_wait_vrise)
         * we don't track them separately
         */
        } else if (otg_irq & A_REQ_TMROUT) {
-               otg_ctrl = OTG_CTRL_REG;
+               otg_ctrl = omap_readl(OTG_CTRL);
                pr_info("otg: BCON_TMOUT from %s, %06x\n",
                                state_name(isp), otg_ctrl);
                notresponding(isp);
 
                otg_ctrl |= OTG_BUSDROP;
                otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
-               OTG_CTRL_REG = otg_ctrl;
+               omap_writel(otg_ctrl, OTG_CTRL);
                isp->otg.state = OTG_STATE_A_WAIT_VFALL;
 
-               OTG_IRQ_SRC_REG = A_REQ_TMROUT;
+               omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
        /* A-supplied voltage fell too low; overcurrent */
        } else if (otg_irq & A_VBUS_ERR) {
-               otg_ctrl = OTG_CTRL_REG;
+               otg_ctrl = omap_readl(OTG_CTRL);
                printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
                        state_name(isp), otg_irq, otg_ctrl);
 
                otg_ctrl |= OTG_BUSDROP;
                otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
-               OTG_CTRL_REG = otg_ctrl;
+               omap_writel(otg_ctrl, OTG_CTRL);
                isp->otg.state = OTG_STATE_A_VBUS_ERR;
 
-               OTG_IRQ_SRC_REG = A_VBUS_ERR;
+               omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
        /* switch driver; the transciever code activates it,
@@ -770,7 +783,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
        } else if (otg_irq & DRIVER_SWITCH) {
                int     kick = 0;
 
-               otg_ctrl = OTG_CTRL_REG;
+               otg_ctrl = omap_readl(OTG_CTRL);
                printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
                                state_name(isp),
                                (otg_ctrl & OTG_DRIVER_SEL)
@@ -793,7 +806,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                } else {
                        if (!(otg_ctrl & OTG_ID)) {
                                otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
-                               OTG_CTRL_REG = otg_ctrl | OTG_A_BUSREQ;
+                               omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
                        }
 
                        if (isp->otg.host) {
@@ -818,7 +831,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                        }
                }
 
-               OTG_IRQ_SRC_REG = DRIVER_SWITCH;
+               omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
 
                if (kick)
@@ -834,12 +847,15 @@ static struct platform_device *otg_dev;
 
 static int otg_init(struct isp1301 *isp)
 {
+       u32 l;
+
        if (!otg_dev)
                return -ENODEV;
 
        dump_regs(isp, __func__);
        /* some of these values are board-specific... */
-       OTG_SYSCON_2_REG |= OTG_EN
+       l = omap_readl(OTG_SYSCON_2);
+       l |= OTG_EN
                /* for B-device: */
                | SRP_GPDATA            /* 9msec Bdev D+ pulse */
                | SRP_GPDVBUS           /* discharge after VBUS pulse */
@@ -849,18 +865,22 @@ static int otg_init(struct isp1301 *isp)
                | SRP_DPW               /* detect 167+ns SRP pulses */
                | SRP_DATA | SRP_VBUS   /* accept both kinds of SRP pulse */
                ;
+       omap_writel(l, OTG_SYSCON_2);
 
        update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
        update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
 
        check_state(isp, __func__);
        pr_debug("otg: %s, %s %06x\n",
-                       state_name(isp), __func__, OTG_CTRL_REG);
+                       state_name(isp), __func__, omap_readl(OTG_CTRL));
 
-       OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG
+       omap_writew(DRIVER_SWITCH | OPRT_CHG
                        | B_SRP_TMROUT | B_HNP_FAIL
-                       | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT;
-       OTG_SYSCON_2_REG |= OTG_EN;
+                       | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
+
+       l = omap_readl(OTG_SYSCON_2);
+       l |= OTG_EN;
+       omap_writel(l, OTG_SYSCON_2);
 
        return 0;
 }
@@ -927,7 +947,11 @@ static void otg_unbind(struct isp1301 *isp)
 
 static void b_peripheral(struct isp1301 *isp)
 {
-       OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
+       u32 l;
+
+       l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
+       omap_writel(l, OTG_CTRL);
+
        usb_gadget_vbus_connect(isp->otg.gadget);
 
 #ifdef CONFIG_USB_OTG
@@ -999,6 +1023,8 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                        isp_bstat = 0;
                }
        } else {
+               u32 l;
+
                /* if user unplugged mini-A end of cable,
                 * don't bypass A_WAIT_VFALL.
                 */
@@ -1019,8 +1045,9 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                                isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
                                                MC1_BDIS_ACON_EN);
                                isp->otg.state = OTG_STATE_B_IDLE;
-                               OTG_CTRL_REG &= OTG_CTRL_REG & OTG_CTRL_MASK
-                                               & ~OTG_CTRL_BITS;
+                               l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
+                               l &= ~OTG_CTRL_BITS;
+                               omap_writel(l, OTG_CTRL);
                                break;
                        case OTG_STATE_B_IDLE:
                                break;
@@ -1046,7 +1073,8 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                        /* FALLTHROUGH */
                case OTG_STATE_B_SRP_INIT:
                        b_idle(isp, __func__);
-                       OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
+                       l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
+                       omap_writel(l, OTG_CTRL);
                        /* FALLTHROUGH */
                case OTG_STATE_B_IDLE:
                        if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
@@ -1130,11 +1158,11 @@ isp1301_work(struct work_struct *work)
                        case OTG_STATE_A_WAIT_VRISE:
                                isp->otg.state = OTG_STATE_A_HOST;
                                pr_debug("  --> a_host\n");
-                               otg_ctrl = OTG_CTRL_REG;
+                               otg_ctrl = omap_readl(OTG_CTRL);
                                otg_ctrl |= OTG_A_BUSREQ;
                                otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
                                                & OTG_CTRL_MASK;
-                               OTG_CTRL_REG = otg_ctrl;
+                               omap_writel(otg_ctrl, OTG_CTRL);
                                break;
                        case OTG_STATE_B_WAIT_ACON:
                                isp->otg.state = OTG_STATE_B_HOST;
@@ -1274,7 +1302,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
                return -ENODEV;
 
        if (!host) {
-               OTG_IRQ_EN_REG = 0;
+               omap_writew(0, OTG_IRQ_EN);
                power_down(isp);
                isp->otg.host = 0;
                return 0;
@@ -1325,12 +1353,13 @@ static int
 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
 {
        struct isp1301  *isp = container_of(otg, struct isp1301, otg);
+       u32 l;
 
        if (!otg || isp != the_transceiver)
                return -ENODEV;
 
        if (!gadget) {
-               OTG_IRQ_EN_REG = 0;
+               omap_writew(0, OTG_IRQ_EN);
                if (!isp->otg.default_a)
                        enable_vbus_draw(isp, 0);
                usb_gadget_vbus_disconnect(isp->otg.gadget);
@@ -1351,9 +1380,11 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
        isp->otg.gadget = gadget;
        // FIXME update its refcount
 
-       OTG_CTRL_REG = (OTG_CTRL_REG & OTG_CTRL_MASK
-                               & ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS))
-                       | OTG_ID;
+       l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
+       l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
+       l |= OTG_ID;
+       omap_writel(l, OTG_CTRL);
+
        power_up(isp);
        isp->otg.state = OTG_STATE_B_IDLE;
 
@@ -1405,16 +1436,17 @@ isp1301_start_srp(struct otg_transceiver *dev)
                        || isp->otg.state != OTG_STATE_B_IDLE)
                return -ENODEV;
 
-       otg_ctrl = OTG_CTRL_REG;
+       otg_ctrl = omap_readl(OTG_CTRL);
        if (!(otg_ctrl & OTG_BSESSEND))
                return -EINVAL;
 
        otg_ctrl |= OTG_B_BUSREQ;
        otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
-       OTG_CTRL_REG = otg_ctrl;
+       omap_writel(otg_ctrl, OTG_CTRL);
        isp->otg.state = OTG_STATE_B_SRP_INIT;
 
-       pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG);
+       pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
+                       omap_readl(OTG_CTRL));
 #ifdef CONFIG_USB_OTG
        check_state(isp, __func__);
 #endif
@@ -1426,6 +1458,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
 {
 #ifdef CONFIG_USB_OTG
        struct isp1301  *isp = container_of(dev, struct isp1301, otg);
+       u32 l;
 
        if (!dev || isp != the_transceiver)
                return -ENODEV;
@@ -1452,7 +1485,9 @@ isp1301_start_hnp(struct otg_transceiver *dev)
 #endif
                /* caller must suspend then clear A_BUSREQ */
                usb_gadget_vbus_connect(isp->otg.gadget);
-               OTG_CTRL_REG |= OTG_A_SETB_HNPEN;
+               l = omap_readl(OTG_CTRL);
+               l |= OTG_A_SETB_HNPEN;
+               omap_writel(l, OTG_CTRL);
 
                break;
        case OTG_STATE_A_PERIPHERAL:
@@ -1462,7 +1497,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
                return -EILSEQ;
        }
        pr_debug("otg: HNP %s, %06x ...\n",
-               state_name(isp), OTG_CTRL_REG);
+               state_name(isp), omap_readl(OTG_CTRL));
        check_state(isp, __func__);
        return 0;
 #else
index d34c14c..006a585 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/list.h>
 #include <linux/i2c.h>
 #include <linux/i2c-dev.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
 static struct i2c_driver i2cdev_driver;
@@ -441,14 +442,20 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        struct i2c_client *client;
        struct i2c_adapter *adap;
        struct i2c_dev *i2c_dev;
+       int ret = 0;
 
+       lock_kernel();
        i2c_dev = i2c_dev_get_by_minor(minor);
-       if (!i2c_dev)
-               return -ENODEV;
+       if (!i2c_dev) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        adap = i2c_get_adapter(i2c_dev->adap->nr);
-       if (!adap)
-               return -ENODEV;
+       if (!adap) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        /* This creates an anonymous i2c_client, which may later be
         * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -460,7 +467,8 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client = kzalloc(sizeof(*client), GFP_KERNEL);
        if (!client) {
                i2c_put_adapter(adap);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
        snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
        client->driver = &i2cdev_driver;
@@ -468,7 +476,9 @@ static int i2cdev_open(struct inode *inode, struct file *file)
        client->adapter = adap;
        file->private_data = client;
 
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int i2cdev_release(struct inode *inode, struct file *file)
index 1e1f263..a3d2283 100644 (file)
@@ -2421,9 +2421,12 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
        if (i >= MAX_HWIFS * MAX_DRIVES)
                return -ENXIO;
 
+       lock_kernel();
        tape = ide_tape_chrdev_get(i);
-       if (!tape)
+       if (!tape) {
+               unlock_kernel();
                return -ENXIO;
+       }
 
        debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
 
@@ -2482,10 +2485,12 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
                        }
                }
        }
+       unlock_kernel();
        return 0;
 
 out_put_tape:
        ide_tape_put(tape);
+       unlock_kernel();
        return retval;
 }
 
index 3381424..8dbf4d9 100644 (file)
@@ -63,11 +63,11 @@ MODULE_LICENSE("Dual MPL/GPL");
 
 #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0)
 
-#ifdef PCMCIA_DEBUG
-INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
+#ifdef CONFIG_PCMCIA_DEBUG
+INT_MODULE_PARM(pc_debug, 0);
 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
-"ide-cs.c 1.3 2002/10/26 05:45:31 (David Hinds)";
+/*static char *version =
+"ide-cs.c 1.3 2002/10/26 05:45:31 (David Hinds)";*/
 #else
 #define DEBUG(n, args...)
 #endif
@@ -375,7 +375,7 @@ failed:
 
 ======================================================================*/
 
-void ide_release(struct pcmcia_device *link)
+static void ide_release(struct pcmcia_device *link)
 {
     ide_info_t *info = link->priv;
     ide_hwif_t *hwif = info->hwif;
index d7a6881..b25675f 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/cdev.h>
 #include <linux/idr.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -1159,6 +1160,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
 {
        struct ib_ucm_file *file;
 
+       cycle_kernel_lock();
        file = kmalloc(sizeof(*file), GFP_KERNEL);
        if (!file)
                return -ENOMEM;
index ca4cf3a..195f973 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/in.h>
 #include <linux/in6.h>
 #include <linux/miscdevice.h>
+#include <linux/smp_lock.h>
 
 #include <rdma/rdma_user_cm.h>
 #include <rdma/ib_marshall.h>
@@ -1156,6 +1157,7 @@ static int ucma_open(struct inode *inode, struct file *filp)
        if (!file)
                return -ENOMEM;
 
+       lock_kernel();
        INIT_LIST_HEAD(&file->event_list);
        INIT_LIST_HEAD(&file->ctx_list);
        init_waitqueue_head(&file->poll_wait);
@@ -1163,6 +1165,7 @@ static int ucma_open(struct inode *inode, struct file *filp)
 
        filp->private_data = file;
        file->filp = filp;
+       unlock_kernel();
        return 0;
 }
 
index 840ede9..208c7f3 100644 (file)
@@ -777,6 +777,19 @@ static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd,
 }
 #endif
 
+/*
+ * ib_umad_open() does not need the BKL:
+ *
+ *  - umad_port[] accesses are protected by port_lock, the
+ *    ib_umad_port structures are properly reference counted, and
+ *    everything else is purely local to the file being created, so
+ *    races against other open calls are not a problem;
+ *  - the ioctl method does not affect any global state outside of the
+ *    file structure being operated on;
+ *  - the port is added to umad_port[] as the last part of module
+ *    initialization so the open method will either immediately run
+ *    -ENXIO, or all required initialization will be done.
+ */
 static int ib_umad_open(struct inode *inode, struct file *filp)
 {
        struct ib_umad_port *port;
index caed42b..0f34858 100644 (file)
@@ -610,6 +610,18 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
                return file->device->ib_dev->mmap(file->ucontext, vma);
 }
 
+/*
+ * ib_uverbs_open() does not need the BKL:
+ *
+ *  - dev_table[] accesses are protected by map_lock, the
+ *    ib_uverbs_device structures are properly reference counted, and
+ *    everything else is purely local to the file being created, so
+ *    races against other open calls are not a problem;
+ *  - there is no ioctl method to race against;
+ *  - the device is added to dev_table[] as the last part of module
+ *    initialization, the open method will either immediately run
+ *    -ENXIO, or all required initialization will be done.
+ */
 static int ib_uverbs_open(struct inode *inode, struct file *filp)
 {
        struct ib_uverbs_device *dev;
@@ -651,7 +663,6 @@ err_module:
 
 err:
        kref_put(&dev->ref, ib_uverbs_release_dev);
-
        return ret;
 }
 
index b472b15..35f301c 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/highmem.h>
 #include <linux/io.h>
 #include <linux/jiffies.h>
+#include <linux/smp_lock.h>
 #include <asm/pgtable.h>
 
 #include "ipath_kernel.h"
@@ -1815,6 +1816,7 @@ done:
 static int ipath_open(struct inode *in, struct file *fp)
 {
        /* The real work is performed later in ipath_assign_port() */
+       cycle_kernel_lock();
        fp->private_data = kzalloc(sizeof(struct ipath_filedata), GFP_KERNEL);
        return fp->private_data ? 0 : -ENOMEM;
 }
index 27006fc..408df0b 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/device.h>
 #include <linux/mutex.h>
 #include <linux/rcupdate.h>
+#include <linux/smp_lock.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
 MODULE_DESCRIPTION("Input core");
@@ -1588,13 +1589,17 @@ EXPORT_SYMBOL(input_unregister_handle);
 
 static int input_open_file(struct inode *inode, struct file *file)
 {
-       struct input_handler *handler = input_table[iminor(inode) >> 5];
+       struct input_handler *handler;
        const struct file_operations *old_fops, *new_fops = NULL;
        int err;
 
+       lock_kernel();
        /* No load-on-demand here? */
-       if (!handler || !(new_fops = fops_get(handler->fops)))
-               return -ENODEV;
+       handler = input_table[iminor(inode) >> 5];
+       if (!handler || !(new_fops = fops_get(handler->fops))) {
+               err = -ENODEV;
+               goto out;
+       }
 
        /*
         * That's _really_ odd. Usually NULL ->open means "nothing special",
@@ -1602,7 +1607,8 @@ static int input_open_file(struct inode *inode, struct file *file)
         */
        if (!new_fops->open) {
                fops_put(new_fops);
-               return -ENODEV;
+               err = -ENODEV;
+               goto out;
        }
        old_fops = file->f_op;
        file->f_op = new_fops;
@@ -1614,6 +1620,8 @@ static int input_open_file(struct inode *inode, struct file *file)
                file->f_op = fops_get(old_fops);
        }
        fops_put(old_fops);
+out:
+       unlock_kernel();
        return err;
 }
 
index 45e5d05..49d8abf 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <linux/hp_sdc.h>
 #include <linux/errno.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -408,6 +409,7 @@ static unsigned int hp_sdc_rtc_poll(struct file *file, poll_table *wait)
 
 static int hp_sdc_rtc_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
         return 0;
 }
 
index a56ad4b..2bcfa0b 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
 #include <linux/uinput.h>
+#include <linux/smp_lock.h>
 
 static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
 {
@@ -222,6 +223,7 @@ static int uinput_open(struct inode *inode, struct file *file)
        if (!newdev)
                return -ENOMEM;
 
+       lock_kernel();
        mutex_init(&newdev->mutex);
        spin_lock_init(&newdev->requests_lock);
        init_waitqueue_head(&newdev->requests_waitq);
@@ -229,6 +231,7 @@ static int uinput_open(struct inode *inode, struct file *file)
        newdev->state = UIST_NEW_DEVICE;
 
        file->private_data = newdev;
+       unlock_kernel();
 
        return 0;
 }
index b989748..8137e50 100644 (file)
@@ -14,6 +14,7 @@
 #define MOUSEDEV_MIX           31
 
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/poll.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -545,16 +546,21 @@ static int mousedev_open(struct inode *inode, struct file *file)
        if (i >= MOUSEDEV_MINORS)
                return -ENODEV;
 
+       lock_kernel();
        error = mutex_lock_interruptible(&mousedev_table_mutex);
-       if (error)
+       if (error) {
+               unlock_kernel();
                return error;
+       }
        mousedev = mousedev_table[i];
        if (mousedev)
                get_device(&mousedev->dev);
        mutex_unlock(&mousedev_table_mutex);
 
-       if (!mousedev)
+       if (!mousedev) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        client = kzalloc(sizeof(struct mousedev_client), GFP_KERNEL);
        if (!client) {
@@ -573,6 +579,7 @@ static int mousedev_open(struct inode *inode, struct file *file)
                goto err_free_client;
 
        file->private_data = client;
+       unlock_kernel();
        return 0;
 
  err_free_client:
@@ -580,6 +587,7 @@ static int mousedev_open(struct inode *inode, struct file *file)
        kfree(client);
  err_put_mousedev:
        put_device(&mousedev->dev);
+       unlock_kernel();
        return error;
 }
 
index 0403622..c9397c8 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/poll.h>
 #include <linux/module.h>
 #include <linux/serio.h>
@@ -81,9 +82,10 @@ static int serio_raw_open(struct inode *inode, struct file *file)
        struct serio_raw_list *list;
        int retval = 0;
 
+       lock_kernel();
        retval = mutex_lock_interruptible(&serio_raw_mutex);
        if (retval)
-               return retval;
+               goto out_bkl;
 
        if (!(serio_raw = serio_raw_locate(iminor(inode)))) {
                retval = -ENODEV;
@@ -108,6 +110,8 @@ static int serio_raw_open(struct inode *inode, struct file *file)
 
 out:
        mutex_unlock(&serio_raw_mutex);
+out_bkl:
+       unlock_kernel();
        return retval;
 }
 
index 0f47f46..9ce3b3b 100644 (file)
@@ -66,6 +66,9 @@ static irqreturn_t input_handler(int rq, void *dev_id)
                case XENKBD_TYPE_MOTION:
                        input_report_rel(dev, REL_X, event->motion.rel_x);
                        input_report_rel(dev, REL_Y, event->motion.rel_y);
+                       if (event->motion.rel_z)
+                               input_report_rel(dev, REL_WHEEL,
+                                                -event->motion.rel_z);
                        break;
                case XENKBD_TYPE_KEY:
                        dev = NULL;
@@ -84,6 +87,9 @@ static irqreturn_t input_handler(int rq, void *dev_id)
                case XENKBD_TYPE_POS:
                        input_report_abs(dev, ABS_X, event->pos.abs_x);
                        input_report_abs(dev, ABS_Y, event->pos.abs_y);
+                       if (event->pos.rel_z)
+                               input_report_rel(dev, REL_WHEEL,
+                                                -event->pos.rel_z);
                        break;
                }
                if (dev)
@@ -152,7 +158,7 @@ static int __devinit xenkbd_probe(struct xenbus_device *dev,
        ptr->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
        for (i = BTN_LEFT; i <= BTN_TASK; i++)
                set_bit(i, ptr->keybit);
-       ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y);
+       ptr->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
        input_set_abs_params(ptr, ABS_X, 0, XENFB_WIDTH, 0, 0);
        input_set_abs_params(ptr, ABS_Y, 0, XENFB_HEIGHT, 0, 0);
 
@@ -294,6 +300,16 @@ InitWait:
                 */
                if (dev->state != XenbusStateConnected)
                        goto InitWait; /* no InitWait seen yet, fudge it */
+
+               /* Set input abs params to match backend screen res */
+               if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+                                "width", "%d", &val) > 0)
+                       input_set_abs_params(info->ptr, ABS_X, 0, val, 0, 0);
+
+               if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+                                "height", "%d", &val) > 0)
+                       input_set_abs_params(info->ptr, ABS_Y, 0, val, 0, 0);
+
                break;
 
        case XenbusStateClosing:
@@ -337,4 +353,6 @@ static void __exit xenkbd_cleanup(void)
 module_init(xenkbd_init);
 module_exit(xenkbd_cleanup);
 
+MODULE_DESCRIPTION("Xen virtual keyboard/pointer device frontend");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("xen:vkbd");
index 6ca0bb9..2095153 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/signal.h>
 #include <linux/mutex.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 #include <linux/timer.h>
 #include <linux/wait.h>
 #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -983,13 +984,17 @@ capi_ioctl(struct inode *inode, struct file *file,
 static int
 capi_open(struct inode *inode, struct file *file)
 {
+       int ret;
+       
+       lock_kernel();
        if (file->private_data)
-               return -EEXIST;
-
-       if ((file->private_data = capidev_alloc()) == NULL)
-               return -ENOMEM;
-
-       return nonseekable_open(inode, file);
+               ret = -EEXIST;
+       else if ((file->private_data = capidev_alloc()) == NULL)
+               ret = -ENOMEM;
+       else
+               ret = nonseekable_open(inode, file);
+       unlock_kernel();
+       return ret;
 }
 
 static int
index c909289..1e85f74 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/poll.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
 #include "platform.h"
@@ -127,14 +128,19 @@ static unsigned int maint_poll(struct file *file, poll_table * wait)
 
 static int maint_open(struct inode *ino, struct file *filep)
 {
+       int ret;
+
+       lock_kernel();
        /* only one open is allowed, so we test
           it atomically */
        if (test_and_set_bit(0, &opened))
-               return (-EBUSY);
-
-       filep->private_data = NULL;
-
-       return nonseekable_open(ino, filep);
+               ret = -EBUSY;
+       else {
+               filep->private_data = NULL;
+               ret = nonseekable_open(ino, filep);
+       }
+       unlock_kernel();
+       return ret;
 }
 
 static int maint_close(struct inode *ino, struct file *filep)
index 78f141e..f4969fe 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/skbuff.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 
 #include "platform.h"
@@ -400,6 +401,7 @@ static unsigned int um_idi_poll(struct file *file, poll_table * wait)
 
 static int um_idi_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        return (0);
 }
 
index 16a874b..fbbcb27 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/list.h>
 #include <linux/poll.h>
 #include <linux/kmod.h>
+#include <linux/smp_lock.h>
 
 #include "platform.h"
 #undef ID_MASK
@@ -580,6 +581,7 @@ xdi_copy_from_user(void *os_handle, void *dst, const void __user *src, int lengt
  */
 static int divas_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        return (0);
 }
 
index 8d8c6b7..7188c59 100644 (file)
@@ -1732,7 +1732,7 @@ isdn_open(struct inode *ino, struct file *filep)
        int chidx;
        int retval = -ENODEV;
 
-
+       lock_kernel();
        if (minor == ISDN_MINOR_STATUS) {
                infostruct *p;
 
@@ -1783,6 +1783,7 @@ isdn_open(struct inode *ino, struct file *filep)
 #endif
  out:
        nonseekable_open(ino, filep);
+       unlock_kernel();
        return retval;
 }
 
index 6b8dbb9..76f2b36 100644 (file)
@@ -1,6 +1,6 @@
 config LGUEST
        tristate "Linux hypervisor example code"
-       depends on X86_32 && EXPERIMENTAL && !X86_PAE && FUTEX && !(X86_VISWS || X86_VOYAGER)
+       depends on X86_32 && EXPERIMENTAL && !X86_PAE && FUTEX && !X86_VOYAGER
        select HVC_DRIVER
        ---help---
          This is a very simple module which allows you to run
index 005bd04..5faefea 100644 (file)
@@ -136,7 +136,6 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user);
  * first step in the migration to the kernel types.  pte_pfn is already defined
  * in the kernel. */
 #define pgd_flags(x)   (pgd_val(x) & ~PAGE_MASK)
-#define pte_flags(x)   (pte_val(x) & ~PAGE_MASK)
 #define pgd_pfn(x)     (pgd_val(x) >> PAGE_SHIFT)
 
 /* interrupts_and_traps.c: */
index 61b62a6..e5d4468 100644 (file)
@@ -643,12 +643,18 @@ do_adb_query(struct adb_request *req)
 static int adb_open(struct inode *inode, struct file *file)
 {
        struct adbdev_state *state;
+       int ret = 0;
 
-       if (iminor(inode) > 0 || adb_controller == NULL)
-               return -ENXIO;
+       lock_kernel();
+       if (iminor(inode) > 0 || adb_controller == NULL) {
+               ret = -ENXIO;
+               goto out;
+       }
        state = kmalloc(sizeof(struct adbdev_state), GFP_KERNEL);
-       if (state == 0)
-               return -ENOMEM;
+       if (state == 0) {
+               ret = -ENOMEM;
+               goto out;
+       }
        file->private_data = state;
        spin_lock_init(&state->lock);
        atomic_set(&state->n_pending, 0);
@@ -656,7 +662,9 @@ static int adb_open(struct inode *inode, struct file *file)
        init_waitqueue_head(&state->wait_queue);
        state->inuse = 1;
 
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int adb_release(struct inode *inode, struct file *file)
index 73c50bc..6a82218 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include <linux/types.h>
+#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
@@ -119,6 +120,7 @@ anslcd_ioctl( struct inode * inode, struct file * file,
 static int
 anslcd_open( struct inode * inode, struct file * file )
 {
+       cycle_kernel_lock();
        return 0;
 }
 
index 76dbf25..96faa79 100644 (file)
@@ -19,6 +19,7 @@
  *    the userland interface
  */
 
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
@@ -1090,10 +1091,12 @@ static int smu_open(struct inode *inode, struct file *file)
        pp->mode = smu_file_commands;
        init_waitqueue_head(&pp->wait);
 
+       lock_kernel();
        spin_lock_irqsave(&smu_clist_lock, flags);
        list_add(&pp->list, &smu_clist);
        spin_unlock_irqrestore(&smu_clist_lock, flags);
        file->private_data = pp;
+       unlock_kernel();
 
        return 0;
 }
index d6365a9..d524dc2 100644 (file)
@@ -18,6 +18,7 @@
  *
  */
 #include <stdarg.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -2047,6 +2048,7 @@ pmu_open(struct inode *inode, struct file *file)
        pp->rb_get = pp->rb_put = 0;
        spin_lock_init(&pp->lock);
        init_waitqueue_head(&pp->wait);
+       lock_kernel();
        spin_lock_irqsave(&all_pvt_lock, flags);
 #if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
        pp->backlight_locker = 0;
@@ -2054,6 +2056,7 @@ pmu_open(struct inode *inode, struct file *file)
        list_add(&pp->list, &all_pmu_pvt);
        spin_unlock_irqrestore(&all_pvt_lock, flags);
        file->private_data = pp;
+       unlock_kernel();
        return 0;
 }
 
index 1074824..6a866d7 100644 (file)
@@ -50,17 +50,19 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
 /**
  *     linear_mergeable_bvec -- tell bio layer if two requests can be merged
  *     @q: request queue
- *     @bio: the buffer head that's been built up so far
+ *     @bvm: properties of new bio
  *     @biovec: the request that could be merged to it.
  *
  *     Return amount of bytes we can take at this offset
  */
-static int linear_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
+static int linear_mergeable_bvec(struct request_queue *q,
+                                struct bvec_merge_data *bvm,
+                                struct bio_vec *biovec)
 {
        mddev_t *mddev = q->queuedata;
        dev_info_t *dev0;
-       unsigned long maxsectors, bio_sectors = bio->bi_size >> 9;
-       sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
+       unsigned long maxsectors, bio_sectors = bvm->bi_size >> 9;
+       sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
 
        dev0 = which_dev(mddev, sector);
        maxsectors = (dev0->size << 1) - (sector - (dev0->offset<<1));
index 914c04d..bcbb825 100644 (file)
@@ -241,18 +241,20 @@ static int create_strip_zones (mddev_t *mddev)
 /**
  *     raid0_mergeable_bvec -- tell bio layer if a two requests can be merged
  *     @q: request queue
- *     @bio: the buffer head that's been built up so far
+ *     @bvm: properties of new bio
  *     @biovec: the request that could be merged to it.
  *
  *     Return amount of bytes we can accept at this offset
  */
-static int raid0_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
+static int raid0_mergeable_bvec(struct request_queue *q,
+                               struct bvec_merge_data *bvm,
+                               struct bio_vec *biovec)
 {
        mddev_t *mddev = q->queuedata;
-       sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
+       sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
        int max;
        unsigned int chunk_sectors = mddev->chunk_size >> 9;
-       unsigned int bio_sectors = bio->bi_size >> 9;
+       unsigned int bio_sectors = bvm->bi_size >> 9;
 
        max =  (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
        if (max < 0) max = 0; /* bio_add cannot handle a negative return */
index a71277b..22bb2b1 100644 (file)
@@ -439,26 +439,27 @@ static sector_t raid10_find_virt(conf_t *conf, sector_t sector, int dev)
 /**
  *     raid10_mergeable_bvec -- tell bio layer if a two requests can be merged
  *     @q: request queue
- *     @bio: the buffer head that's been built up so far
+ *     @bvm: properties of new bio
  *     @biovec: the request that could be merged to it.
  *
  *     Return amount of bytes we can accept at this offset
  *      If near_copies == raid_disk, there are no striping issues,
  *      but in that case, the function isn't called at all.
  */
-static int raid10_mergeable_bvec(struct request_queue *q, struct bio *bio,
-                               struct bio_vec *bio_vec)
+static int raid10_mergeable_bvec(struct request_queue *q,
+                                struct bvec_merge_data *bvm,
+                                struct bio_vec *biovec)
 {
        mddev_t *mddev = q->queuedata;
-       sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
+       sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
        int max;
        unsigned int chunk_sectors = mddev->chunk_size >> 9;
-       unsigned int bio_sectors = bio->bi_size >> 9;
+       unsigned int bio_sectors = bvm->bi_size >> 9;
 
        max =  (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
        if (max < 0) max = 0; /* bio_add cannot handle a negative return */
-       if (max <= bio_vec->bv_len && bio_sectors == 0)
-               return bio_vec->bv_len;
+       if (max <= biovec->bv_len && bio_sectors == 0)
+               return biovec->bv_len;
        else
                return max;
 }
index 3b27df5..9ce7154 100644 (file)
@@ -3314,15 +3314,17 @@ static int raid5_congested(void *data, int bits)
 /* We want read requests to align with chunks where possible,
  * but write requests don't need to.
  */
-static int raid5_mergeable_bvec(struct request_queue *q, struct bio *bio, struct bio_vec *biovec)
+static int raid5_mergeable_bvec(struct request_queue *q,
+                               struct bvec_merge_data *bvm,
+                               struct bio_vec *biovec)
 {
        mddev_t *mddev = q->queuedata;
-       sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
+       sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
        int max;
        unsigned int chunk_sectors = mddev->chunk_size >> 9;
-       unsigned int bio_sectors = bio->bi_size >> 9;
+       unsigned int bio_sectors = bvm->bi_size >> 9;
 
-       if (bio_data_dir(bio) == WRITE)
+       if ((bvm->bi_rw & 1) == WRITE)
                return biovec->bv_len; /* always allow writes to be mergeable */
 
        max =  (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
index 8b56d92..e208a60 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/fs.h>
 #include <linux/cdev.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 #include "dvbdev.h"
 
 static int dvbdev_debug;
@@ -74,6 +75,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
 {
        struct dvb_device *dvbdev;
 
+       lock_kernel();
        dvbdev = dvbdev_find_device (iminor(inode));
 
        if (dvbdev && dvbdev->fops) {
@@ -90,8 +92,10 @@ static int dvb_device_open(struct inode *inode, struct file *file)
                        file->f_op = fops_get(old_fops);
                }
                fops_put(old_fops);
+               unlock_kernel();
                return err;
        }
+       unlock_kernel();
        return -ENODEV;
 }
 
index 06dfed9..3e840f7 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
@@ -27,13 +28,16 @@ static int rds_f_open(struct inode *in, struct file *fi)
        if (rds_users)
                return -EBUSY;
 
+       lock_kernel();
        rds_users++;
        if ((text_buffer=kmalloc(66, GFP_KERNEL)) == 0) {
                rds_users--;
                printk(KERN_NOTICE "aci-rds: Out of memory by open()...\n");
+               unlock_kernel();
                return -ENOMEM;
        }
 
+       unlock_kernel();
        return 0;
 }
 
index 67a661c..7649860 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/init.h>
 #include <linux/kmod.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
@@ -442,6 +443,7 @@ static int video_open(struct inode *inode, struct file *file)
 
        if(minor>=VIDEO_NUM_DEVICES)
                return -ENODEV;
+       lock_kernel();
        mutex_lock(&videodev_lock);
        vfl=video_device[minor];
        if(vfl==NULL) {
@@ -451,6 +453,7 @@ static int video_open(struct inode *inode, struct file *file)
                vfl=video_device[minor];
                if (vfl==NULL) {
                        mutex_unlock(&videodev_lock);
+                       unlock_kernel();
                        return -ENODEV;
                }
        }
@@ -464,6 +467,7 @@ static int video_open(struct inode *inode, struct file *file)
        }
        fops_put(old_fops);
        mutex_unlock(&videodev_lock);
+       unlock_kernel();
        return err;
 }
 
index e630b50..c594656 100644 (file)
@@ -548,11 +548,15 @@ static int
 mptctl_fasync(int fd, struct file *filep, int mode)
 {
        MPT_ADAPTER     *ioc;
+       int ret;
 
+       lock_kernel();
        list_for_each_entry(ioc, &ioc_list, list)
                ioc->aen_event_read_flag=0;
 
-       return fasync_helper(fd, filep, mode, &async_queue);
+       ret = fasync_helper(fd, filep, mode, &async_queue);
+       unlock_kernel();
+       return ret;
 }
 
 static int
index c0fb77d..4238de9 100644 (file)
@@ -1061,6 +1061,7 @@ static int cfg_open(struct inode *inode, struct file *file)
        if (!tmp)
                return -ENOMEM;
 
+       lock_kernel();
        file->private_data = (void *)(i2o_cfg_info_id++);
        tmp->fp = file;
        tmp->fasync = NULL;
@@ -1074,6 +1075,7 @@ static int cfg_open(struct inode *inode, struct file *file)
        spin_lock_irqsave(&i2o_config_lock, flags);
        open_files = tmp;
        spin_unlock_irqrestore(&i2o_config_lock, flags);
+       unlock_kernel();
 
        return 0;
 }
@@ -1082,15 +1084,17 @@ static int cfg_fasync(int fd, struct file *fp, int on)
 {
        ulong id = (ulong) fp->private_data;
        struct i2o_cfg_info *p;
+       int ret = -EBADF;
 
+       lock_kernel();
        for (p = open_files; p; p = p->next)
                if (p->q_id == id)
                        break;
 
-       if (!p)
-               return -EBADF;
-
-       return fasync_helper(fd, fp, on, &p->fasync);
+       if (p)
+               ret = fasync_helper(fd, fp, on, &p->fasync);
+       unlock_kernel();
+       return ret;
 }
 
 static int cfg_release(struct inode *inode, struct file *file)
index 0d5ce03..5b5a14d 100644 (file)
@@ -332,7 +332,7 @@ static int __init pwm_probe(struct platform_device *pdev)
        p->base = ioremap(r->start, r->end - r->start + 1);
        if (!p->base)
                goto fail;
-       p->clk = clk_get(&pdev->dev, "mck");
+       p->clk = clk_get(&pdev->dev, "pwm_clk");
        if (IS_ERR(p->clk)) {
                status = PTR_ERR(p->clk);
                p->clk = NULL;
index ff51ab6..176fe4e 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/miscdevice.h>
 #include <linux/proc_fs.h>
 #include <linux/hdpu_features.h>
@@ -151,7 +152,13 @@ static ssize_t cpustate_write(struct file *file, const char *buf,
 
 static int cpustate_open(struct inode *inode, struct file *file)
 {
-       return cpustate_get_ref((file->f_flags & O_EXCL));
+       int ret;
+
+       lock_kernel();
+       ret = cpustate_get_ref((file->f_flags & O_EXCL));
+       unlock_kernel();
+
+       return ret;
 }
 
 static int cpustate_release(struct inode *inode, struct file *file)
index 71d1c84..1861624 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/cdev.h>
 #include <linux/phantom.h>
+#include <linux/smp_lock.h>
 
 #include <asm/atomic.h>
 #include <asm/io.h>
@@ -212,13 +213,17 @@ static int phantom_open(struct inode *inode, struct file *file)
        struct phantom_device *dev = container_of(inode->i_cdev,
                        struct phantom_device, cdev);
 
+       lock_kernel();
        nonseekable_open(inode, file);
 
-       if (mutex_lock_interruptible(&dev->open_lock))
+       if (mutex_lock_interruptible(&dev->open_lock)) {
+               unlock_kernel();
                return -ERESTARTSYS;
+       }
 
        if (dev->opened) {
                mutex_unlock(&dev->open_lock);
+               unlock_kernel();
                return -EINVAL;
        }
 
@@ -229,7 +234,7 @@ static int phantom_open(struct inode *inode, struct file *file)
        atomic_set(&dev->counter, 0);
        dev->opened++;
        mutex_unlock(&dev->open_lock);
-
+       unlock_kernel();
        return 0;
 }
 
index 00e48e2..60775be 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/backlight.h>
 #include <linux/platform_device.h>
@@ -1927,8 +1928,10 @@ static int sonypi_misc_release(struct inode *inode, struct file *file)
 static int sonypi_misc_open(struct inode *inode, struct file *file)
 {
        /* Flush input queue on first open */
+       lock_kernel();
        if (atomic_inc_return(&sonypi_compat.open_count) == 1)
                kfifo_reset(sonypi_compat.fifo);
+       unlock_kernel();
        return 0;
 }
 
index 95f33e8..eed211b 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
 #include <linux/delay.h>
+#include <linux/clk.h>
 
 #include <asm/dma.h>
 #include <asm/io.h>
@@ -92,6 +93,8 @@ struct imxmci_host {
        unsigned char           actual_bus_width;
 
        int                     prev_cmd_code;
+
+       struct clk              *clk;
 };
 
 #define IMXMCI_PEND_IRQ_b      0
@@ -841,7 +844,7 @@ static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                /* The prescaler is 5 for PERCLK2 equal to 96MHz
                 * then 96MHz / 5 = 19.2 MHz
                 */
-               clk=imx_get_perclk2();
+               clk = clk_get_rate(host->clk);
                prescaler=(clk+(CLK_RATE*7)/8)/CLK_RATE;
                switch(prescaler) {
                case 0:
@@ -994,6 +997,13 @@ static int imxmci_probe(struct platform_device *pdev)
        host->res = r;
        host->irq = irq;
 
+       host->clk = clk_get(&pdev->dev, "perclk2");
+       if (IS_ERR(host->clk)) {
+               ret = PTR_ERR(host->clk);
+               goto out;
+       }
+       clk_enable(host->clk);
+
        imx_gpio_mode(PB8_PF_SD_DAT0);
        imx_gpio_mode(PB9_PF_SD_DAT1);
        imx_gpio_mode(PB10_PF_SD_DAT2);
@@ -1017,8 +1027,8 @@ static int imxmci_probe(struct platform_device *pdev)
        host->imask = IMXMCI_INT_MASK_DEFAULT;
        MMC_INT_MASK = host->imask;
 
-
-       if(imx_dma_request_by_prio(&host->dma, DRIVER_NAME, DMA_PRIO_LOW)<0){
+       host->dma = imx_dma_request_by_prio(DRIVER_NAME, DMA_PRIO_LOW);
+       if(host->dma < 0) {
                dev_err(mmc_dev(host->mmc), "imx_dma_request_by_prio failed\n");
                ret = -EBUSY;
                goto out;
@@ -1053,6 +1063,10 @@ out:
                        imx_dma_free(host->dma);
                        host->dma_allocated=0;
                }
+               if (host->clk) {
+                       clk_disable(host->clk);
+                       clk_put(host->clk);
+               }
        }
        if (mmc)
                mmc_free_host(mmc);
@@ -1082,6 +1096,9 @@ static int imxmci_remove(struct platform_device *pdev)
 
                tasklet_kill(&host->tasklet);
 
+               clk_disable(host->clk);
+               clk_put(host->clk);
+
                release_resource(host->res);
 
                mmc_free_host(mmc);
index 4a79b18..5c29872 100644 (file)
@@ -130,10 +130,6 @@ typedef struct partition_t {
     u_int16_t          DataUnits;
     u_int32_t          BlocksPerUnit;
     erase_unit_header_t        header;
-#if 0
-    region_info_t      region;
-    memory_handle_t    handle;
-#endif
 } partition_t;
 
 /* Partition state flags */
index c12d805..68eec6c 100644 (file)
@@ -60,13 +60,22 @@ struct omapflash_info {
 static void omap_set_vpp(struct map_info *map, int enable)
 {
        static int      count;
-
-       if (enable) {
-               if (count++ == 0)
-                       OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP;
-       } else {
-               if (count && (--count == 0))
-                       OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP;
+       u32 l;
+
+       if (cpu_class_is_omap1()) {
+               if (enable) {
+                       if (count++ == 0) {
+                               l = omap_readl(EMIFS_CONFIG);
+                               l |= OMAP_EMIFS_CONFIG_WP;
+                               omap_writel(l, EMIFS_CONFIG);
+                       }
+               } else {
+                       if (count && (--count == 0)) {
+                               l = omap_readl(EMIFS_CONFIG);
+                               l &= ~OMAP_EMIFS_CONFIG_WP;
+                               omap_writel(l, EMIFS_CONFIG);
+                       }
+               }
        }
 }
 
index 1912d96..0cc3167 100644 (file)
@@ -498,17 +498,14 @@ static int pcmciamtd_config(struct pcmcia_device *link)
        int i;
        config_info_t t;
        static char *probes[] = { "jedec_probe", "cfi_probe" };
-       cisinfo_t cisinfo;
        int new_name = 0;
 
        DEBUG(3, "link=0x%p", link);
 
        DEBUG(2, "Validating CIS");
-       ret = pcmcia_validate_cis(link, &cisinfo);
+       ret = pcmcia_validate_cis(link, NULL);
        if(ret != CS_SUCCESS) {
                cs_error(link, GetTupleData, ret);
-       } else {
-               DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
        }
 
        card_settings(dev, link, &new_name);
@@ -563,9 +560,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
        DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
 
        /* Get write protect status */
-       CS_CHECK(GetStatus, pcmcia_get_status(link, &status));
-       DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
-             status.CardState, (unsigned long)link->win);
+       DEBUG(2, "window handle = 0x%8.8lx", (unsigned long)link->win);
        dev->win_base = ioremap(req.Base, req.Size);
        if(!dev->win_base) {
                err("ioremap(%lu, %u) failed", req.Base, req.Size);
index 5d3ac51..129d429 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/compatmac.h>
@@ -86,6 +87,7 @@ static int mtd_open(struct inode *inode, struct file *file)
 {
        int minor = iminor(inode);
        int devnum = minor >> 1;
+       int ret = 0;
        struct mtd_info *mtd;
        struct mtd_file_info *mfi;
 
@@ -98,31 +100,39 @@ static int mtd_open(struct inode *inode, struct file *file)
        if ((file->f_mode & 2) && (minor & 1))
                return -EACCES;
 
+       lock_kernel();
        mtd = get_mtd_device(NULL, devnum);
 
-       if (IS_ERR(mtd))
-               return PTR_ERR(mtd);
+       if (IS_ERR(mtd)) {
+               ret = PTR_ERR(mtd);
+               goto out;
+       }
 
        if (MTD_ABSENT == mtd->type) {
                put_mtd_device(mtd);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto out;
        }
 
        /* You can't open it RW if it's not a writeable device */
        if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) {
                put_mtd_device(mtd);
-               return -EACCES;
+               ret = -EACCES;
+               goto out;
        }
 
        mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
        if (!mfi) {
                put_mtd_device(mtd);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto out;
        }
        mfi->mtd = mtd;
        file->private_data = mfi;
 
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 } /* mtd_open */
 
 /*====================================================================*/
index 59e05a1..ee2ac39 100644 (file)
@@ -85,6 +85,9 @@ static int __init orion_nand_probe(struct platform_device *pdev)
        nc->cmd_ctrl = orion_nand_cmd_ctrl;
        nc->ecc.mode = NAND_ECC_SOFT;
 
+       if (board->chip_delay)
+               nc->chip_delay = board->chip_delay;
+
        if (board->width == 16)
                nc->options |= NAND_BUSWIDTH_16;
 
index 9d6aae5..89193ba 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/stat.h>
 #include <linux/ioctl.h>
 #include <linux/capability.h>
+#include <linux/smp_lock.h>
 #include <mtd/ubi-user.h>
 #include <asm/uaccess.h>
 #include <asm/div64.h>
@@ -103,9 +104,12 @@ static int vol_cdev_open(struct inode *inode, struct file *file)
        struct ubi_volume_desc *desc;
        int vol_id = iminor(inode) - 1, mode, ubi_num;
 
+       lock_kernel();
        ubi_num = ubi_major2num(imajor(inode));
-       if (ubi_num < 0)
+       if (ubi_num < 0) {
+               unlock_kernel();
                return ubi_num;
+       }
 
        if (file->f_mode & FMODE_WRITE)
                mode = UBI_READWRITE;
@@ -115,6 +119,7 @@ static int vol_cdev_open(struct inode *inode, struct file *file)
        dbg_msg("open volume %d, mode %d", vol_id, mode);
 
        desc = ubi_open_volume(ubi_num, vol_id, mode);
+       unlock_kernel();
        if (IS_ERR(desc))
                return PTR_ERR(desc);
 
index 8e3e968..2683ee3 100644 (file)
@@ -217,7 +217,7 @@ config MII
 
 config MACB
        tristate "Atmel MACB support"
-       depends on AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263 || ARCH_AT91CAP9
+       depends on AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263 || ARCH_AT91SAM9G20 || ARCH_AT91CAP9
        select PHYLIB
        help
          The Atmel MACB ethernet interface is found on many AT32 and AT91
index 00081d2..e9d15ec 100644 (file)
@@ -647,7 +647,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
        struct ei_device *ei_local;
        struct net_device *dev;
        struct etherh_priv *eh;
-       int i, ret;
+       int ret;
        DECLARE_MAC_BUF(mac);
 
        etherh_banner();
index d5c2d27..f76b0b6 100644 (file)
  *
  */
 #include <linux/module.h>
-#include <linux/types.h>
-#include <linux/init.h>
-#include <linux/errno.h>
 #include <linux/netdevice.h>
-#include <linux/slab.h>
-#include <linux/rtnetlink.h>
-#include <linux/interrupt.h>
-#include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
-#include <linux/pm.h>
 #include <linux/clk.h>
 
 #include <net/irda/irda.h>
 #include <net/irda/wrapper.h>
 #include <net/irda/irda_device.h>
 
-#include <asm/irq.h>
 #include <asm/dma.h>
-#include <asm/delay.h>
-#include <asm/hardware.h>
 #include <asm/arch/irda.h>
 #include <asm/arch/pxa-regs.h>
-#include <asm/arch/pxa2xx-gpio.h>
-
-#ifdef CONFIG_MACH_MAINSTONE
-#include <asm/arch/mainstone.h>
-#endif
 
 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
 #define IrSR_RXPL_POS_IS_ZERO 0x0
@@ -163,10 +147,6 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                        /* set board transceiver to SIR mode */
                        si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
 
-                       /* configure GPIO46/47 */
-                       pxa_gpio_mode(GPIO46_STRXD_MD);
-                       pxa_gpio_mode(GPIO47_STTXD_MD);
-
                        /* enable the STUART clock */
                        pxa_irda_enable_sirclk(si);
                }
@@ -201,10 +181,6 @@ static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
                /* set board transceiver to FIR mode */
                si->pdata->transceiver_mode(si->dev, IR_FIRMODE);
 
-               /* configure GPIO46/47 */
-               pxa_gpio_mode(GPIO46_ICPRXD_MD);
-               pxa_gpio_mode(GPIO47_ICPTXD_MD);
-
                /* enable the FICP clock */
                pxa_irda_enable_firclk(si);
 
index 92dccd4..0a5745a 100644 (file)
@@ -1277,8 +1277,45 @@ static int __exit macb_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int macb_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct net_device *netdev = platform_get_drvdata(pdev);
+       struct macb *bp = netdev_priv(netdev);
+
+       netif_device_detach(netdev);
+
+#ifndef CONFIG_ARCH_AT91
+       clk_disable(bp->hclk);
+#endif
+       clk_disable(bp->pclk);
+
+       return 0;
+}
+
+static int macb_resume(struct platform_device *pdev)
+{
+       struct net_device *netdev = platform_get_drvdata(pdev);
+       struct macb *bp = netdev_priv(netdev);
+
+       clk_enable(bp->pclk);
+#ifndef CONFIG_ARCH_AT91
+       clk_enable(bp->hclk);
+#endif
+
+       netif_device_attach(netdev);
+
+       return 0;
+}
+#else
+#define macb_suspend   NULL
+#define macb_resume    NULL
+#endif
+
 static struct platform_driver macb_driver = {
        .remove         = __exit_p(macb_remove),
+       .suspend        = macb_suspend,
+       .resume         = macb_resume,
        .driver         = {
                .name           = "macb",
                .owner  = THIS_MODULE,
index 1f4ca2b..83625fd 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/if_arp.h>
 #include <linux/ip.h>
 #include <linux/tcp.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/rwsem.h>
 #include <linux/stddef.h>
@@ -353,6 +354,7 @@ static const int npindex_to_ethertype[NUM_NP] = {
  */
 static int ppp_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        /*
         * This could (should?) be enforced by the permissions on /dev/ppp.
         */
index b9018bf..eba1271 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/kernel.h>
 #include <linux/major.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/poll.h>
 #include <linux/fcntl.h>
 #include <linux/init.h>
@@ -802,22 +803,26 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
 
        DBG(KERN_INFO "%s: tun_chr_fasync %d\n", tun->dev->name, on);
 
+       lock_kernel();
        if ((ret = fasync_helper(fd, file, on, &tun->fasync)) < 0)
-               return ret;
+               goto out;
 
        if (on) {
                ret = __f_setown(file, task_pid(current), PIDTYPE_PID, 0);
                if (ret)
-                       return ret;
+                       goto out;
                tun->flags |= TUN_FASYNC;
        } else
                tun->flags &= ~TUN_FASYNC;
-
-       return 0;
+       ret = 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int tun_chr_open(struct inode *inode, struct file * file)
 {
+       cycle_kernel_lock();
        DBG1(KERN_INFO "tunX: tun_chr_open\n");
        file->private_data = NULL;
        return 0;
index b0fce13..5827324 100644 (file)
@@ -92,6 +92,7 @@
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #undef COSA_SLOW_IO    /* for testing purposes only */
 
@@ -970,15 +971,21 @@ static int cosa_open(struct inode *inode, struct file *file)
        struct channel_data *chan;
        unsigned long flags;
        int n;
+       int ret = 0;
 
+       lock_kernel();
        if ((n=iminor(file->f_path.dentry->d_inode)>>CARD_MINOR_BITS)
-               >= nr_cards)
-               return -ENODEV;
+               >= nr_cards) {
+               ret = -ENODEV;
+               goto out;
+       }
        cosa = cosa_cards+n;
 
        if ((n=iminor(file->f_path.dentry->d_inode)
-               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels)
-               return -ENODEV;
+               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) {
+               ret = -ENODEV;
+               goto out;
+       }
        chan = cosa->chan + n;
        
        file->private_data = chan;
@@ -987,7 +994,8 @@ static int cosa_open(struct inode *inode, struct file *file)
 
        if (chan->usage < 0) { /* in netdev mode */
                spin_unlock_irqrestore(&cosa->lock, flags);
-               return -EBUSY;
+               ret = -EBUSY;
+               goto out;
        }
        cosa->usage++;
        chan->usage++;
@@ -996,7 +1004,9 @@ static int cosa_open(struct inode *inode, struct file *file)
        chan->setup_rx = chrdev_setup_rx;
        chan->rx_done = chrdev_rx_done;
        spin_unlock_irqrestore(&cosa->lock, flags);
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int cosa_release(struct inode *inode, struct file *file)
index d26f69b..ef671d1 100644 (file)
@@ -1324,7 +1324,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
                goto fail;
        }
 
-       txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_KERNEL);
+       txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
        if (!txs) {
                err = -ENOMEM;
                xenbus_dev_fatal(dev, err, "allocating tx ring page");
@@ -1340,7 +1340,7 @@ static int setup_netfront(struct xenbus_device *dev, struct netfront_info *info)
        }
 
        info->tx_ring_ref = err;
-       rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_KERNEL);
+       rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
        if (!rxs) {
                err = -ENOMEM;
                xenbus_dev_fatal(dev, err, "allocating rx ring page");
index 86e9c84..5ac2079 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/fs.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -83,6 +84,8 @@ static int eisa_eeprom_ioctl(struct inode *inode, struct file *file,
 
 static int eisa_eeprom_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
+
        if (file->f_mode & 2)
                return -EINVAL;
    
index 66c0fd2..bb06423 100644 (file)
@@ -1637,12 +1637,43 @@ static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr,
 }
 
 #ifdef CONFIG_DMAR_GFX_WA
-extern int arch_get_ram_range(int slot, u64 *addr, u64 *size);
+struct iommu_prepare_data {
+       struct pci_dev *pdev;
+       int ret;
+};
+
+static int __init iommu_prepare_work_fn(unsigned long start_pfn,
+                                        unsigned long end_pfn, void *datax)
+{
+       struct iommu_prepare_data *data;
+
+       data = (struct iommu_prepare_data *)datax;
+
+       data->ret = iommu_prepare_identity_map(data->pdev,
+                               start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
+       return data->ret;
+
+}
+
+static int __init iommu_prepare_with_active_regions(struct pci_dev *pdev)
+{
+       int nid;
+       struct iommu_prepare_data data;
+
+       data.pdev = pdev;
+       data.ret = 0;
+
+       for_each_online_node(nid) {
+               work_with_active_regions(nid, iommu_prepare_work_fn, &data);
+               if (data.ret)
+                       return data.ret;
+       }
+       return data.ret;
+}
+
 static void __init iommu_prepare_gfx_mapping(void)
 {
        struct pci_dev *pdev = NULL;
-       u64 base, size;
-       int slot;
        int ret;
 
        for_each_pci_dev(pdev) {
@@ -1651,17 +1682,9 @@ static void __init iommu_prepare_gfx_mapping(void)
                        continue;
                printk(KERN_INFO "IOMMU: gfx device %s 1-1 mapping\n",
                        pci_name(pdev));
-               slot = arch_get_ram_range(0, &base, &size);
-               while (slot >= 0) {
-                       ret = iommu_prepare_identity_map(pdev,
-                                       base, base + size);
-                       if (ret)
-                               goto error;
-                       slot = arch_get_ram_range(slot, &base, &size);
-               }
-               continue;
-error:
-               printk(KERN_ERR "IOMMU: mapping reserved region failed\n");
+               ret = iommu_prepare_with_active_regions(pdev);
+               if (ret)
+                       printk(KERN_ERR "IOMMU: mapping reserved region failed\n");
        }
 }
 #endif
index 1b0eb5a..e45402a 100644 (file)
@@ -263,6 +263,13 @@ config OMAP_CF
          Say Y here to support the CompactFlash controller on OMAP.
          Note that this doesn't support "True IDE" mode.
 
+config BFIN_CFPCMCIA
+       tristate "Blackfin CompactFlash PCMCIA Driver"
+       depends on PCMCIA && BLACKFIN
+       help
+         Say Y here to support the CompactFlash PCMCIA driver for Blackfin.
+
+
 config AT91_CF
        tristate "AT91 CompactFlash Controller"
        depends on PCMCIA && ARCH_AT91RM9200
index 6f6478b..85c6cc9 100644 (file)
@@ -36,6 +36,7 @@ obj-$(CONFIG_PCMCIA_AU1X00)                   += au1x00_ss.o
 obj-$(CONFIG_PCMCIA_VRC4171)                   += vrc4171_card.o
 obj-$(CONFIG_PCMCIA_VRC4173)                   += vrc4173_cardu.o
 obj-$(CONFIG_OMAP_CF)                          += omap_cf.o
+obj-$(CONFIG_BFIN_CFPCMCIA)                    += bfin_cf_pcmcia.o
 obj-$(CONFIG_AT91_CF)                          += at91_cf.o
 obj-$(CONFIG_ELECTRA_CF)                       += electra_cf.o
 
index 1e467bb..a53ef59 100644 (file)
@@ -26,7 +26,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
@@ -34,9 +33,9 @@
 #define AU1000_PCMCIA_IO_SPEED       (255)
 #define AU1000_PCMCIA_MEM_SPEED      (300)
 
-#define AU1X_SOCK0_IO        0xF00000000
-#define AU1X_SOCK0_PHYS_ATTR 0xF40000000
-#define AU1X_SOCK0_PHYS_MEM  0xF80000000
+#define AU1X_SOCK0_IO        0xF00000000ULL
+#define AU1X_SOCK0_PHYS_ATTR 0xF40000000ULL
+#define AU1X_SOCK0_PHYS_MEM  0xF80000000ULL
 /* pseudo 32 bit phys addresses, which get fixed up to the
  * real 36 bit address in fixup_bigphys_addr() */
 #define AU1X_SOCK0_PSEUDO_PHYS_ATTR 0xF4000000
 /* pcmcia socket 1 needs external glue logic so the memory map
  * differs from board to board.
  */
-#if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) || defined(CONFIG_MIPS_PB1200)
-#define AU1X_SOCK1_IO        0xF08000000
-#define AU1X_SOCK1_PHYS_ATTR 0xF48000000
-#define AU1X_SOCK1_PHYS_MEM  0xF88000000
+#if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || \
+    defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) || \
+    defined(CONFIG_MIPS_PB1200)
+#define AU1X_SOCK1_IO        0xF08000000ULL
+#define AU1X_SOCK1_PHYS_ATTR 0xF48000000ULL
+#define AU1X_SOCK1_PHYS_MEM  0xF88000000ULL
 #define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4800000
 #define AU1X_SOCK1_PSEUDO_PHYS_MEM  0xF8800000
-#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) || defined(CONFIG_MIPS_DB1200)
-#define AU1X_SOCK1_IO        0xF04000000
-#define AU1X_SOCK1_PHYS_ATTR 0xF44000000
-#define AU1X_SOCK1_PHYS_MEM  0xF84000000
+#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || \
+      defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) || \
+      defined(CONFIG_MIPS_DB1200)
+#define AU1X_SOCK1_IO        0xF04000000ULL
+#define AU1X_SOCK1_PHYS_ATTR 0xF44000000ULL
+#define AU1X_SOCK1_PHYS_MEM  0xF84000000ULL
 #define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4400000
 #define AU1X_SOCK1_PSEUDO_PHYS_MEM  0xF8400000
 #endif
index 157e414..aa1cd4d 100644 (file)
@@ -35,7 +35,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/bus_ops.h>
 #include "cs_internal.h"
index c78ed53..8a9b18c 100644 (file)
@@ -39,7 +39,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/bus_ops.h>
 #include "cs_internal.h"
diff --git a/drivers/pcmcia/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c
new file mode 100644 (file)
index 0000000..bb73388
--- /dev/null
@@ -0,0 +1,339 @@
+/*
+ * file: drivers/pcmcia/bfin_cf.c
+ *
+ * based on: drivers/pcmcia/omap_cf.c
+ * omap_cf.c -- OMAP 16xx CompactFlash controller driver
+ *
+ * Copyright (c) 2005 David Brownell
+ * Copyright (c) 2006-2008 Michael Hennerich Analog Devices Inc.
+ *
+ * bugs:         enter bugs at http://blackfin.uclinux.org/
+ *
+ * this program is free software; you can redistribute it and/or modify
+ * it under the terms of the gnu general public license as published by
+ * the free software foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * this program is distributed in the hope that it will be useful,
+ * but without any warranty; without even the implied warranty of
+ * merchantability or fitness for a particular purpose.  see the
+ * gnu general public license for more details.
+ *
+ * you should have received a copy of the gnu general public license
+ * along with this program; see the file copying.
+ * if not, write to the free software foundation,
+ * 59 temple place - suite 330, boston, ma 02111-1307, usa.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/platform_device.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+
+#include <pcmcia/ss.h>
+#include <pcmcia/cisreg.h>
+#include <asm/gpio.h>
+
+#define        SZ_1K   0x00000400
+#define        SZ_8K   0x00002000
+#define        SZ_2K   (2 * SZ_1K)
+
+#define        POLL_INTERVAL   (2 * HZ)
+
+#define        CF_ATASEL_ENA   0x20311802      /* Inverts RESET */
+#define        CF_ATASEL_DIS   0x20311800
+
+#define bfin_cf_present(pfx) (gpio_get_value(pfx))
+
+/*--------------------------------------------------------------------------*/
+
+static const char driver_name[] = "bfin_cf_pcmcia";
+
+struct bfin_cf_socket {
+       struct pcmcia_socket socket;
+
+       struct timer_list timer;
+       unsigned present:1;
+       unsigned active:1;
+
+       struct platform_device *pdev;
+       unsigned long phys_cf_io;
+       unsigned long phys_cf_attr;
+       u_int irq;
+       u_short cd_pfx;
+};
+
+/*--------------------------------------------------------------------------*/
+static int bfin_cf_reset(void)
+{
+       outw(0, CF_ATASEL_ENA);
+       mdelay(200);
+       outw(0, CF_ATASEL_DIS);
+
+       return 0;
+}
+
+static int bfin_cf_ss_init(struct pcmcia_socket *s)
+{
+       return 0;
+}
+
+/* the timer is primarily to kick this socket's pccardd */
+static void bfin_cf_timer(unsigned long _cf)
+{
+       struct bfin_cf_socket *cf = (void *)_cf;
+       unsigned short present = bfin_cf_present(cf->cd_pfx);
+
+       if (present != cf->present) {
+               cf->present = present;
+               dev_dbg(&cf->pdev->dev, ": card %s\n",
+                        present ? "present" : "gone");
+               pcmcia_parse_events(&cf->socket, SS_DETECT);
+       }
+
+       if (cf->active)
+               mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
+}
+
+static int bfin_cf_get_status(struct pcmcia_socket *s, u_int *sp)
+{
+       struct bfin_cf_socket *cf;
+
+       if (!sp)
+               return -EINVAL;
+
+       cf = container_of(s, struct bfin_cf_socket, socket);
+
+       if (bfin_cf_present(cf->cd_pfx)) {
+               *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
+               s->irq.AssignedIRQ = 0;
+               s->pci_irq = cf->irq;
+
+       } else
+               *sp = 0;
+       return 0;
+}
+
+static int
+bfin_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
+{
+
+       struct bfin_cf_socket *cf;
+       cf = container_of(sock, struct bfin_cf_socket, socket);
+
+       switch (s->Vcc) {
+       case 0:
+       case 33:
+               break;
+       case 50:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (s->flags & SS_RESET) {
+               disable_irq(cf->irq);
+               bfin_cf_reset();
+               enable_irq(cf->irq);
+       }
+
+       dev_dbg(&cf->pdev->dev, ": Vcc %d, io_irq %d, flags %04x csc %04x\n",
+                s->Vcc, s->io_irq, s->flags, s->csc_mask);
+
+       return 0;
+}
+
+static int bfin_cf_ss_suspend(struct pcmcia_socket *s)
+{
+       return bfin_cf_set_socket(s, &dead_socket);
+}
+
+/* regions are 2K each:  mem, attrib, io (and reserved-for-ide) */
+
+static int bfin_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
+{
+       struct bfin_cf_socket *cf;
+
+       cf = container_of(s, struct bfin_cf_socket, socket);
+       io->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT;
+       io->start = cf->phys_cf_io;
+       io->stop = io->start + SZ_2K - 1;
+       return 0;
+}
+
+static int
+bfin_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
+{
+       struct bfin_cf_socket *cf;
+
+       if (map->card_start)
+               return -EINVAL;
+       cf = container_of(s, struct bfin_cf_socket, socket);
+       map->static_start = cf->phys_cf_io;
+       map->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT;
+       if (map->flags & MAP_ATTRIB)
+               map->static_start = cf->phys_cf_attr;
+
+       return 0;
+}
+
+static struct pccard_operations bfin_cf_ops = {
+       .init = bfin_cf_ss_init,
+       .suspend = bfin_cf_ss_suspend,
+       .get_status = bfin_cf_get_status,
+       .set_socket = bfin_cf_set_socket,
+       .set_io_map = bfin_cf_set_io_map,
+       .set_mem_map = bfin_cf_set_mem_map,
+};
+
+/*--------------------------------------------------------------------------*/
+
+static int __devinit bfin_cf_probe(struct platform_device *pdev)
+{
+       struct bfin_cf_socket *cf;
+       struct resource *io_mem, *attr_mem;
+       int irq;
+       unsigned short cd_pfx;
+       int status = 0;
+
+       dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n");
+
+       irq = platform_get_irq(pdev, 0);
+       if (!irq)
+               return -EINVAL;
+
+       cd_pfx = platform_get_irq(pdev, 1);     /*Card Detect GPIO PIN */
+
+       if (gpio_request(cd_pfx, "pcmcia: CD")) {
+               dev_err(&pdev->dev,
+                      "Failed ro request Card Detect GPIO_%d\n",
+                      cd_pfx);
+               return -EBUSY;
+       }
+       gpio_direction_input(cd_pfx);
+
+       cf = kzalloc(sizeof *cf, GFP_KERNEL);
+       if (!cf) {
+               gpio_free(cd_pfx);
+               return -ENOMEM;
+       }
+
+       cf->cd_pfx = cd_pfx;
+
+       setup_timer(&cf->timer, bfin_cf_timer, (unsigned long)cf);
+
+       cf->pdev = pdev;
+       platform_set_drvdata(pdev, cf);
+
+       cf->irq = irq;
+       cf->socket.pci_irq = irq;
+
+       set_irq_type(irq, IRQF_TRIGGER_LOW);
+
+       io_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       attr_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+
+       if (!io_mem || !attr_mem)
+               goto fail0;
+
+       cf->phys_cf_io = io_mem->start;
+       cf->phys_cf_attr = attr_mem->start;
+
+       /* pcmcia layer only remaps "real" memory */
+       cf->socket.io_offset = (unsigned long)
+           ioremap(cf->phys_cf_io, SZ_2K);
+
+       if (!cf->socket.io_offset)
+               goto fail0;
+
+       dev_err(&pdev->dev, ": on irq %d\n", irq);
+
+       dev_dbg(&pdev->dev, ": %s\n",
+                bfin_cf_present(cf->cd_pfx) ? "present" : "(not present)");
+
+       cf->socket.owner = THIS_MODULE;
+       cf->socket.dev.parent = &pdev->dev;
+       cf->socket.ops = &bfin_cf_ops;
+       cf->socket.resource_ops = &pccard_static_ops;
+       cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
+           | SS_CAP_MEM_ALIGN;
+       cf->socket.map_size = SZ_2K;
+
+       status = pcmcia_register_socket(&cf->socket);
+       if (status < 0)
+               goto fail2;
+
+       cf->active = 1;
+       mod_timer(&cf->timer, jiffies + POLL_INTERVAL);
+       return 0;
+
+fail2:
+       iounmap((void __iomem *)cf->socket.io_offset);
+       release_mem_region(cf->phys_cf_io, SZ_8K);
+
+fail0:
+       gpio_free(cf->cd_pfx);
+       kfree(cf);
+       platform_set_drvdata(pdev, NULL);
+
+       return status;
+}
+
+static int __devexit bfin_cf_remove(struct platform_device *pdev)
+{
+       struct bfin_cf_socket *cf = platform_get_drvdata(pdev);
+
+       gpio_free(cf->cd_pfx);
+       cf->active = 0;
+       pcmcia_unregister_socket(&cf->socket);
+       del_timer_sync(&cf->timer);
+       iounmap((void __iomem *)cf->socket.io_offset);
+       release_mem_region(cf->phys_cf_io, SZ_8K);
+       platform_set_drvdata(pdev, NULL);
+       kfree(cf);
+       return 0;
+}
+
+static int bfin_cf_suspend(struct platform_device *pdev, pm_message_t mesg)
+{
+       return pcmcia_socket_dev_suspend(&pdev->dev, mesg);
+}
+
+static int bfin_cf_resume(struct platform_device *pdev)
+{
+       return pcmcia_socket_dev_resume(&pdev->dev);
+}
+
+static struct platform_driver bfin_cf_driver = {
+       .driver = {
+                  .name = (char *)driver_name,
+                  .owner = THIS_MODULE,
+                  },
+       .probe = bfin_cf_probe,
+       .remove = __devexit_p(bfin_cf_remove),
+       .suspend = bfin_cf_suspend,
+       .resume = bfin_cf_resume,
+};
+
+static int __init bfin_cf_init(void)
+{
+       return platform_driver_register(&bfin_cf_driver);
+}
+
+static void __exit bfin_cf_exit(void)
+{
+       platform_driver_unregister(&bfin_cf_driver);
+}
+
+module_init(bfin_cf_init);
+module_exit(bfin_cf_exit);
+
+MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>")
+MODULE_DESCRIPTION("BFIN CF/PCMCIA Driver");
+MODULE_LICENSE("GPL");
index fb2f38d..911ca0e 100644 (file)
 #include <asm/irq.h>
 #include <asm/io.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
index 3637953..9fcff0c 100644 (file)
@@ -30,7 +30,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
@@ -1439,10 +1438,11 @@ EXPORT_SYMBOL(pccard_read_tuple);
     
 ======================================================================*/
 
-int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_t *info)
+int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned int *info)
 {
     tuple_t *tuple;
     cisparse_t *p;
+    unsigned int count = 0;
     int ret, reserved, dev_ok = 0, ident_ok = 0;
 
     if (!s)
@@ -1457,7 +1457,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
        return CS_OUT_OF_RESOURCE;
     }
 
-    info->Chains = reserved = 0;
+    count = reserved = 0;
     tuple->DesiredTuple = RETURN_FIRST_TUPLE;
     tuple->Attributes = TUPLE_RETURN_COMMON;
     ret = pccard_get_first_tuple(s, function, tuple);
@@ -1482,7 +1482,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
     if (!dev_ok && !ident_ok)
        goto done;
 
-    for (info->Chains = 1; info->Chains < MAX_TUPLES; info->Chains++) {
+    for (count = 1; count < MAX_TUPLES; count++) {
        ret = pccard_get_next_tuple(s, function, tuple);
        if (ret != CS_SUCCESS) break;
        if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
@@ -1490,11 +1490,13 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_
            ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
            reserved++;
     }
-    if ((info->Chains == MAX_TUPLES) || (reserved > 5) ||
-       ((!dev_ok || !ident_ok) && (info->Chains > 10)))
-       info->Chains = 0;
+    if ((count) || (reserved > 5) ||
+       ((!dev_ok || !ident_ok) && (count > 10)))
+       count = 0;
 
 done:
+    if (info)
+           *info = count;
     kfree(tuple);
     kfree(p);
     return CS_SUCCESS;
index 29276bd..d120739 100644 (file)
 #include <asm/system.h>
 #include <asm/irq.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
@@ -238,7 +236,6 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
 
        init_completion(&socket->socket_released);
        init_completion(&socket->thread_done);
-       init_waitqueue_head(&socket->thread_wait);
        mutex_init(&socket->skt_mutex);
        spin_lock_init(&socket->thread_lock);
 
@@ -278,10 +275,9 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket)
 
        cs_dbg(socket, 0, "pcmcia_unregister_socket(0x%p)\n", socket->ops);
 
-       if (socket->thread) {
-               wake_up(&socket->thread_wait);
+       if (socket->thread)
                kthread_stop(socket->thread);
-       }
+
        release_cis_mem(socket);
 
        /* remove from our own list */
@@ -635,7 +631,6 @@ static void socket_detect_change(struct pcmcia_socket *skt)
 static int pccardd(void *__skt)
 {
        struct pcmcia_socket *skt = __skt;
-       DECLARE_WAITQUEUE(wait, current);
        int ret;
 
        skt->thread = current;
@@ -656,7 +651,6 @@ static int pccardd(void *__skt)
        if (ret)
                dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
 
-       add_wait_queue(&skt->thread_wait, &wait);
        complete(&skt->thread_done);
 
        set_freezable();
@@ -694,8 +688,6 @@ static int pccardd(void *__skt)
        /* make sure we are running before we exit */
        set_current_state(TASK_RUNNING);
 
-       remove_wait_queue(&skt->thread_wait, &wait);
-
        /* remove from the device core */
        pccard_sysfs_remove_socket(&skt->dev);
        device_unregister(&skt->dev);
@@ -716,7 +708,7 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
                s->thread_events |= events;
                spin_unlock_irqrestore(&s->thread_lock, flags);
 
-               wake_up(&s->thread_wait);
+               wake_up_process(s->thread);
        }
 } /* pcmcia_parse_events */
 EXPORT_SYMBOL(pcmcia_parse_events);
index e7d5d14..63dc1a2 100644 (file)
 #define CLIENT_WIN_REQ(i)      (0x1<<(i))
 #define CLIENT_CARDBUS         0x8000
 
-#define REGION_MAGIC   0xE3C9
-typedef struct region_t {
-    u_short            region_magic;
-    u_short            state;
-    dev_info_t         dev_info;
-    struct pcmcia_device       *mtd;
-    u_int              MediaID;
-    region_info_t      info;
-} region_t;
-
-#define REGION_STALE   0x01
-
 /* Each card function gets one of these guys */
 typedef struct config_t {
        struct kref     ref;
@@ -130,7 +118,6 @@ extern struct list_head pcmcia_socket_list;
 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
 int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config);
 int pccard_reset_card(struct pcmcia_socket *skt);
-int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev, cs_status_t *status);
 
 
 struct pcmcia_callback{
index e407754..4174d96 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/kref.h>
 #include <linux/dma-mapping.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -741,9 +740,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
 
 static int pcmcia_card_add(struct pcmcia_socket *s)
 {
-       cisinfo_t cisinfo;
        cistpl_longlink_mfc_t mfc;
-       unsigned int no_funcs, i;
+       unsigned int no_funcs, i, no_chains;
        int ret = 0;
 
        if (!(s->resource_setup_done)) {
@@ -757,8 +755,8 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
                return -EAGAIN; /* try again, but later... */
        }
 
-       ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo);
-       if (ret || !cisinfo.Chains) {
+       ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains);
+       if (ret || !no_chains) {
                ds_dbg(0, "invalid CIS or invalid resources\n");
                return -ENODEV;
        }
@@ -852,7 +850,7 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
 {
        struct pcmcia_socket *s = dev->socket;
        const struct firmware *fw;
-       char path[20];
+       char path[FIRMWARE_NAME_MAX];
        int ret = -ENOMEM;
        int no_funcs;
        int old_funcs;
@@ -864,7 +862,7 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
 
        ds_dbg(1, "trying to load CIS file %s\n", filename);
 
-       if (strlen(filename) > 14) {
+       if (strlen(filename) > (FIRMWARE_NAME_MAX - 1)) {
                printk(KERN_WARNING "pcmcia: CIS filename is too long [%s]\n",
                        filename);
                return -EINVAL;
index f2e810f..fb2bc1f 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: hd64465_ss.c,v 1.7 2003/07/06 14:42:50 lethal Exp $
- *
  * Device driver for the PCMCIA controller module of the
  * Hitachi HD64465 handheld companion chip.
  *
@@ -48,7 +46,6 @@
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include "cs_internal.h"
 
 #define MODNAME "hd64465_ss"
index e136186..46561fa 100644 (file)
@@ -5,8 +5,6 @@
  *
  * Author: Arjan Van De Ven <arjanv@redhat.com>
  * Loosly based on i82365.c from the pcmcia-cs package
- *
- * $Id: i82092aa.c,v 1.2 2001/10/23 14:43:34 arjanv Exp $
  */
 
 #include <linux/kernel.h>
index b0d4533..8836d39 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <linux/interrupt.h>
 
-/* $Id: i82092aa.h,v 1.1.1.1 2001/09/19 14:53:15 dwmw2 Exp $ */
-
 /* Debuging defines */
 #ifdef NOTRACE
 #define enter(x)   printk("Enter: %s, %s line %i\n",x,__FILE__,__LINE__)
index 32a2ab1..68f6b27 100644 (file)
@@ -1263,7 +1263,7 @@ static int __init init_i82365(void)
 
     ret = driver_register(&i82365_driver);
     if (ret)
-       return ret;
+       goto err_out;
 
     i82365_device = platform_device_alloc("i82365", 0);
     if (i82365_device) {
@@ -1273,10 +1273,8 @@ static int __init init_i82365(void)
     } else
            ret = -ENOMEM;
 
-    if (ret) {
-       driver_unregister(&i82365_driver);
-       return ret;
-    }
+    if (ret)
+       goto err_driver_unregister;
 
     printk(KERN_INFO "Intel ISA PCIC probe: ");
     sockets = 0;
@@ -1285,16 +1283,17 @@ static int __init init_i82365(void)
 
     if (sockets == 0) {
        printk("not found.\n");
-       platform_device_unregister(i82365_device);
-       release_region(i365_base, 2);
-       driver_unregister(&i82365_driver);
-       return -ENODEV;
+       ret = -ENODEV;
+       goto err_dev_unregister;
     }
 
     /* Set up interrupt handler(s) */
     if (grab_irq != 0)
-       request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
-    
+       ret = request_irq(cs_irq, pcic_interrupt, 0, "i82365", pcic_interrupt);
+
+    if (ret)
+       goto err_socket_release;
+
     /* register sockets with the pcmcia core */
     for (i = 0; i < sockets; i++) {
            socket[i].socket.dev.parent = &i82365_device->dev;
@@ -1324,7 +1323,23 @@ static int __init init_i82365(void)
     }
     
     return 0;
-    
+err_socket_release:
+    for (i = 0; i < sockets; i++) {
+       /* Turn off all interrupt sources! */
+       i365_set(i, I365_CSCINT, 0);
+       release_region(socket[i].ioaddr, 2);
+    }
+err_dev_unregister:
+    platform_device_unregister(i82365_device);
+    release_region(i365_base, 2);
+#ifdef CONFIG_PNP
+    if (i82365_pnpdev)
+       pnp_disable_dev(i82365_pnpdev);
+#endif
+err_driver_unregister:
+    driver_unregister(&i82365_driver);
+err_out:
+    return ret;
 } /* init_i82365 */
 
 static void __exit exit_i82365(void)
index 9c5be9a..ff66604 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series.
  *
- * (C) 1999-2000 Magnus Damm <damm@bitsmart.com>
+ * (C) 1999-2000 Magnus Damm <damm@opensource.se>
  * (C) 2001-2002 Montavista Software, Inc.
  *     <mlocke@mvista.com>
  *
@@ -60,7 +60,6 @@
 #include <asm/irq.h>
 #include <asm/fs_pd.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
index 46314b4..569b746 100644 (file)
 #define        CF_BASE 0xfffe2800
 
 /* status; read after IRQ */
-#define CF_STATUS_REG          __REG16(CF_BASE + 0x00)
+#define CF_STATUS                      (CF_BASE + 0x00)
 #      define  CF_STATUS_BAD_READ      (1 << 2)
 #      define  CF_STATUS_BAD_WRITE     (1 << 1)
 #      define  CF_STATUS_CARD_DETECT   (1 << 0)
 
 /* which chipselect (CS0..CS3) is used for CF (active low) */
-#define CF_CFG_REG             __REG16(CF_BASE + 0x02)
+#define CF_CFG                         (CF_BASE + 0x02)
 
 /* card reset */
-#define CF_CONTROL_REG         __REG16(CF_BASE + 0x04)
+#define CF_CONTROL                     (CF_BASE + 0x04)
 #      define  CF_CONTROL_RESET        (1 << 0)
 
-#define omap_cf_present() (!(CF_STATUS_REG & CF_STATUS_CARD_DETECT))
+#define omap_cf_present() (!(omap_readw(CF_STATUS) & CF_STATUS_CARD_DETECT))
 
 /*--------------------------------------------------------------------------*/
 
@@ -139,11 +139,11 @@ omap_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
                return -EINVAL;
        }
 
-       control = CF_CONTROL_REG;
+       control = omap_readw(CF_CONTROL);
        if (s->flags & SS_RESET)
-               CF_CONTROL_REG = CF_CONTROL_RESET;
+               omap_writew(CF_CONTROL_RESET, CF_CONTROL);
        else
-               CF_CONTROL_REG = 0;
+               omap_writew(0, CF_CONTROL);
 
        pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
                driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
@@ -270,7 +270,7 @@ static int __init omap_cf_probe(struct platform_device *pdev)
        omap_cfg_reg(V10_1610_CF_IREQ);
        omap_cfg_reg(W10_1610_CF_RESET);
 
-       CF_CFG_REG = ~(1 << seg);
+       omap_writew(~(1 << seg), CF_CFG);
 
        pr_info("%s: cs%d on irq %d\n", driver_name, seg, irq);
 
@@ -279,14 +279,15 @@ static int __init omap_cf_probe(struct platform_device *pdev)
         * CF/PCMCIA variants...
         */
        pr_debug("%s: cs%d, previous ccs %08x acs %08x\n", driver_name,
-                       seg, EMIFS_CCS(seg), EMIFS_ACS(seg));
-       EMIFS_CCS(seg) = 0x0004a1b3;    /* synch mode 4 etc */
-       EMIFS_ACS(seg) = 0x00000000;    /* OE hold/setup */
+               seg, omap_readl(EMIFS_CCS(seg)), omap_readl(EMIFS_ACS(seg)));
+       omap_writel(0x0004a1b3, EMIFS_CCS(seg));        /* synch mode 4 etc */
+       omap_writel(0x00000000, EMIFS_ACS(seg));        /* OE hold/setup */
 
        /* CF uses armxor_ck, which is "always" available */
 
        pr_debug("%s: sts %04x cfg %04x control %04x %s\n", driver_name,
-               CF_STATUS_REG, CF_CFG_REG, CF_CONTROL_REG,
+               omap_readw(CF_STATUS), omap_readw(CF_CFG),
+               omap_readw(CF_CONTROL),
                omap_cf_present() ? "present" : "(not present)");
 
        cf->socket.owner = THIS_MODULE;
index 5f186ab..419f97f 100644 (file)
 #include <linux/proc_fs.h>
 #include <linux/poll.h>
 #include <linux/pci.h>
+#include <linux/smp_lock.h>
 #include <linux/workqueue.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
+#include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
 #include <pcmcia/ss.h>
 
@@ -138,6 +139,154 @@ static int proc_read_drivers(char *buf, char **start, off_t pos,
 }
 #endif
 
+
+#ifdef CONFIG_PCMCIA_PROBE
+
+static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
+{
+       int irq;
+       u32 mask;
+
+       irq = adj->resource.irq.IRQ;
+       if ((irq < 0) || (irq > 15))
+               return CS_BAD_IRQ;
+
+       if (adj->Action != REMOVE_MANAGED_RESOURCE)
+               return 0;
+
+       mask = 1 << irq;
+
+       if (!(s->irq_mask & mask))
+               return 0;
+
+       s->irq_mask &= ~mask;
+
+       return 0;
+}
+
+#else
+
+static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
+       return CS_SUCCESS;
+}
+
+#endif
+
+static int pcmcia_adjust_resource_info(adjust_t *adj)
+{
+       struct pcmcia_socket *s;
+       int ret = CS_UNSUPPORTED_FUNCTION;
+       unsigned long flags;
+
+       down_read(&pcmcia_socket_list_rwsem);
+       list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
+
+               if (adj->Resource == RES_IRQ)
+                       ret = adjust_irq(s, adj);
+
+               else if (s->resource_ops->add_io) {
+                       unsigned long begin, end;
+
+                       /* you can't use the old interface if the new
+                        * one was used before */
+                       spin_lock_irqsave(&s->lock, flags);
+                       if ((s->resource_setup_new) &&
+                           !(s->resource_setup_old)) {
+                               spin_unlock_irqrestore(&s->lock, flags);
+                               continue;
+                       } else if (!(s->resource_setup_old))
+                               s->resource_setup_old = 1;
+                       spin_unlock_irqrestore(&s->lock, flags);
+
+                       switch (adj->Resource) {
+                       case RES_MEMORY_RANGE:
+                               begin = adj->resource.memory.Base;
+                               end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
+                               if (s->resource_ops->add_mem)
+                                       ret =s->resource_ops->add_mem(s, adj->Action, begin, end);
+                       case RES_IO_RANGE:
+                               begin = adj->resource.io.BasePort;
+                               end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
+                               if (s->resource_ops->add_io)
+                                       ret = s->resource_ops->add_io(s, adj->Action, begin, end);
+                       }
+                       if (!ret) {
+                               /* as there's no way we know this is the
+                                * last call to adjust_resource_info, we
+                                * always need to assume this is the latest
+                                * one... */
+                               spin_lock_irqsave(&s->lock, flags);
+                               s->resource_setup_done = 1;
+                               spin_unlock_irqrestore(&s->lock, flags);
+                       }
+               }
+       }
+       up_read(&pcmcia_socket_list_rwsem);
+
+       return (ret);
+}
+
+/** pccard_get_status
+ *
+ * Get the current socket state bits.  We don't support the latched
+ * SocketState yet: I haven't seen any point for it.
+ */
+
+static int pccard_get_status(struct pcmcia_socket *s,
+                            struct pcmcia_device *p_dev,
+                            cs_status_t *status)
+{
+       config_t *c;
+       int val;
+
+       s->ops->get_status(s, &val);
+       status->CardState = status->SocketState = 0;
+       status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
+       status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
+       status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
+       status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
+       if (s->state & SOCKET_SUSPEND)
+               status->CardState |= CS_EVENT_PM_SUSPEND;
+       if (!(s->state & SOCKET_PRESENT))
+               return CS_NO_CARD;
+
+       c = (p_dev) ? p_dev->function_config : NULL;
+
+       if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
+           (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
+               u_char reg;
+               if (c->CardValues & PRESENT_PIN_REPLACE) {
+                       pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
+                       status->CardState |=
+                               (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
+                       status->CardState |=
+                               (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
+                       status->CardState |=
+                               (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
+                       status->CardState |=
+                               (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
+               } else {
+                       /* No PRR?  Then assume we're always ready */
+                       status->CardState |= CS_EVENT_READY_CHANGE;
+               }
+               if (c->CardValues & PRESENT_EXT_STATUS) {
+                       pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
+                       status->CardState |=
+                               (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
+               }
+               return CS_SUCCESS;
+       }
+       status->CardState |=
+               (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
+       status->CardState |=
+               (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
+       status->CardState |=
+               (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
+       status->CardState |=
+               (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
+       return CS_SUCCESS;
+} /* pccard_get_status */
+
 /*======================================================================
 
     These manage a ring buffer of events pending for one user process
@@ -397,20 +546,27 @@ static int ds_open(struct inode *inode, struct file *file)
     struct pcmcia_socket *s;
     user_info_t *user;
     static int warning_printed = 0;
+    int ret = 0;
 
     ds_dbg(0, "ds_open(socket %d)\n", i);
 
+    lock_kernel();
     s = pcmcia_get_socket_by_nr(i);
-    if (!s)
-           return -ENODEV;
+    if (!s) {
+           ret = -ENODEV;
+           goto out;
+    }
     s = pcmcia_get_socket(s);
-    if (!s)
-           return -ENODEV;
+    if (!s) {
+           ret = -ENODEV;
+           goto out;
+    }
 
     if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
            if (s->pcmcia_state.busy) {
                    pcmcia_put_socket(s);
-                   return -EBUSY;
+                   ret = -EBUSY;
+                   goto out;
            }
        else
            s->pcmcia_state.busy = 1;
@@ -419,7 +575,8 @@ static int ds_open(struct inode *inode, struct file *file)
     user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
     if (!user) {
            pcmcia_put_socket(s);
-           return -ENOMEM;
+           ret = -ENOMEM;
+           goto out;
     }
     user->event_tail = user->event_head = 0;
     user->next = s->user;
@@ -441,7 +598,9 @@ static int ds_open(struct inode *inode, struct file *file)
 
     if (s->pcmcia_state.present)
        queue_event(user, CS_EVENT_CARD_INSERTION);
-    return 0;
+out:
+    unlock_kernel();
+    return ret;
 } /* ds_open */
 
 /*====================================================================*/
@@ -546,8 +705,6 @@ static u_int ds_poll(struct file *file, poll_table *wait)
 
 /*====================================================================*/
 
-extern int pcmcia_adjust_resource_info(adjust_t *adj);
-
 static int ds_ioctl(struct inode * inode, struct file * file,
                    u_int cmd, u_long arg)
 {
@@ -649,7 +806,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
        mutex_lock(&s->skt_mutex);
        pcmcia_validate_mem(s);
        mutex_unlock(&s->skt_mutex);
-       ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
+       ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo.Chains);
        break;
     case DS_SUSPEND_CARD:
        ret = pcmcia_suspend_card(s);
index 1d128fb..4884a18 100644 (file)
 #include <linux/pci.h>
 #include <linux/device.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
@@ -311,74 +309,6 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
 EXPORT_SYMBOL(pcmcia_get_window);
 
 
-/** pccard_get_status
- *
- * Get the current socket state bits.  We don't support the latched
- * SocketState yet: I haven't seen any point for it.
- */
-
-int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev,
-                     cs_status_t *status)
-{
-       config_t *c;
-       int val;
-
-       s->ops->get_status(s, &val);
-       status->CardState = status->SocketState = 0;
-       status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
-       status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
-       status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
-       status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
-       if (s->state & SOCKET_SUSPEND)
-               status->CardState |= CS_EVENT_PM_SUSPEND;
-       if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
-
-       c = (p_dev) ? p_dev->function_config : NULL;
-
-       if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
-           (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
-               u_char reg;
-               if (c->CardValues & PRESENT_PIN_REPLACE) {
-                       pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
-                       status->CardState |=
-                               (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
-                       status->CardState |=
-                               (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
-                       status->CardState |=
-                               (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
-                       status->CardState |=
-                               (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
-               } else {
-                       /* No PRR?  Then assume we're always ready */
-                       status->CardState |= CS_EVENT_READY_CHANGE;
-               }
-               if (c->CardValues & PRESENT_EXT_STATUS) {
-                       pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
-                       status->CardState |=
-                               (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
-               }
-               return CS_SUCCESS;
-       }
-       status->CardState |=
-               (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
-       status->CardState |=
-               (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
-       status->CardState |=
-               (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
-       status->CardState |=
-               (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
-       return CS_SUCCESS;
-} /* pccard_get_status */
-
-int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status)
-{
-       return pccard_get_status(p_dev->socket, p_dev, status);
-}
-EXPORT_SYMBOL(pcmcia_get_status);
-
-
-
 /** pcmcia_get_mem_page
  *
  * Change the card address of an already open memory window.
@@ -812,6 +742,15 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
                type = IRQF_SHARED;
 
 #ifdef CONFIG_PCMCIA_PROBE
+
+#ifdef IRQ_NOAUTOEN
+       /* if the underlying IRQ infrastructure allows for it, only allocate
+        * the IRQ, but do not enable it
+        */
+       if (!(req->Attributes & IRQ_HANDLE_PRESENT))
+               type |= IRQ_NOAUTOEN;
+#endif /* IRQ_NOAUTOEN */
+
        if (s->irq.AssignedIRQ != 0) {
                /* If the interrupt is already assigned, it must be the same */
                irq = s->irq.AssignedIRQ;
@@ -966,7 +905,7 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev) {
        pcmcia_release_configuration(p_dev);
        pcmcia_release_io(p_dev, &p_dev->io);
        pcmcia_release_irq(p_dev, &p_dev->irq);
-       if (&p_dev->win)
+       if (p_dev->win)
                pcmcia_release_window(p_dev->win);
 }
 EXPORT_SYMBOL(pcmcia_disable_device);
index 9414163..ccfdf19 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 
 #include "cs_internal.h"
index e7ab060..f123fce 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <pcmcia/ss.h>
 #include <asm/hardware.h>
+#include <asm/mach-types.h>
 
 #include <asm/arch/pxa-regs.h>
 #include <asm/arch/pxa2xx-gpio.h>
@@ -130,7 +131,7 @@ static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 }
 
 
-static struct pcmcia_low_level cmx270_pcmcia_ops = {
+static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = cmx270_pcmcia_hw_init,
        .hw_shutdown            = cmx270_pcmcia_shutdown,
@@ -147,15 +148,21 @@ static int __init cmx270_pcmcia_init(void)
 {
        int ret;
 
+       if (!machine_is_armcore())
+               return -ENODEV;
+
        cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
 
        if (!cmx270_pcmcia_device)
                return -ENOMEM;
 
-       cmx270_pcmcia_device->dev.platform_data = &cmx270_pcmcia_ops;
+       ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
+                                      sizeof(cmx270_pcmcia_ops));
 
-       printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
-       ret = platform_device_add(cmx270_pcmcia_device);
+       if (ret == 0) {
+               printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
+               ret = platform_device_add(cmx270_pcmcia_device);
+       }
 
        if (ret)
                platform_device_put(cmx270_pcmcia_device);
index 145b85e..92d1cc3 100644 (file)
@@ -22,6 +22,7 @@
 #include <pcmcia/ss.h>
 
 #include <asm/hardware.h>
+#include <asm/mach-types.h>
 #include <asm/irq.h>
 
 #include <asm/arch/pxa-regs.h>
@@ -136,7 +137,7 @@ static void mst_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 {
 }
 
-static struct pcmcia_low_level mst_pcmcia_ops = {
+static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = mst_pcmcia_hw_init,
        .hw_shutdown            = mst_pcmcia_hw_shutdown,
@@ -153,13 +154,17 @@ static int __init mst_pcmcia_init(void)
 {
        int ret;
 
+       if (!machine_is_mainstone())
+               return -ENODEV;
+
        mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
        if (!mst_pcmcia_device)
                return -ENOMEM;
 
-       mst_pcmcia_device->dev.platform_data = &mst_pcmcia_ops;
-
-       ret = platform_device_add(mst_pcmcia_device);
+       ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
+                                      sizeof(mst_pcmcia_ops));
+       if (ret == 0)
+               ret = platform_device_add(mst_pcmcia_device);
 
        if (ret)
                platform_device_put(mst_pcmcia_device);
index d5c33bd..d71f93d 100644 (file)
@@ -222,7 +222,7 @@ static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
        sharpsl_pcmcia_init_reset(skt);
 }
 
-static struct pcmcia_low_level sharpsl_pcmcia_ops = {
+static struct pcmcia_low_level sharpsl_pcmcia_ops __initdata = {
        .owner                  = THIS_MODULE,
        .hw_init                = sharpsl_pcmcia_hw_init,
        .hw_shutdown            = sharpsl_pcmcia_hw_shutdown,
@@ -261,10 +261,12 @@ static int __init sharpsl_pcmcia_init(void)
        if (!sharpsl_pcmcia_device)
                return -ENOMEM;
 
-       sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops;
-       sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
-
-       ret = platform_device_add(sharpsl_pcmcia_device);
+       ret = platform_device_add_data(sharpsl_pcmcia_device,
+                       &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops));
+       if (ret == 0) {
+               sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
+               ret = platform_device_add(sharpsl_pcmcia_device);
+       }
 
        if (ret)
                platform_device_put(sharpsl_pcmcia_device);
index ce22262..c0e2afc 100644 (file)
 #include "cs_internal.h"
 
 
-#ifdef CONFIG_PCMCIA_IOCTL
-
-#ifdef CONFIG_PCMCIA_PROBE
-
-static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
-{
-       int irq;
-       u32 mask;
-
-       irq = adj->resource.irq.IRQ;
-       if ((irq < 0) || (irq > 15))
-               return CS_BAD_IRQ;
-
-       if (adj->Action != REMOVE_MANAGED_RESOURCE)
-               return 0;
-
-       mask = 1 << irq;
-
-       if (!(s->irq_mask & mask))
-               return 0;
-
-       s->irq_mask &= ~mask;
-
-       return 0;
-}
-
-#else
-
-static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
-       return CS_SUCCESS;
-}
-
-#endif
-
-
-int pcmcia_adjust_resource_info(adjust_t *adj)
-{
-       struct pcmcia_socket *s;
-       int ret = CS_UNSUPPORTED_FUNCTION;
-       unsigned long flags;
-
-       down_read(&pcmcia_socket_list_rwsem);
-       list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
-
-               if (adj->Resource == RES_IRQ)
-                       ret = adjust_irq(s, adj);
-
-               else if (s->resource_ops->adjust_resource) {
-
-                       /* you can't use the old interface if the new
-                        * one was used before */
-                       spin_lock_irqsave(&s->lock, flags);
-                       if ((s->resource_setup_new) &&
-                           !(s->resource_setup_old)) {
-                               spin_unlock_irqrestore(&s->lock, flags);
-                               continue;
-                       } else if (!(s->resource_setup_old))
-                               s->resource_setup_old = 1;
-                       spin_unlock_irqrestore(&s->lock, flags);
-
-                       ret = s->resource_ops->adjust_resource(s, adj);
-                       if (!ret) {
-                               /* as there's no way we know this is the
-                                * last call to adjust_resource_info, we
-                                * always need to assume this is the latest
-                                * one... */
-                               spin_lock_irqsave(&s->lock, flags);
-                               s->resource_setup_done = 1;
-                               spin_unlock_irqrestore(&s->lock, flags);
-                       }
-               }
-       }
-       up_read(&pcmcia_socket_list_rwsem);
-
-       return (ret);
-}
-EXPORT_SYMBOL(pcmcia_adjust_resource_info);
-
-#endif
-
 int pcmcia_validate_mem(struct pcmcia_socket *s)
 {
        if (s->resource_ops->validate_mem)
@@ -164,7 +84,8 @@ struct pccard_resource_ops pccard_static_ops = {
        .adjust_io_region = NULL,
        .find_io = NULL,
        .find_mem = NULL,
-       .adjust_resource = NULL,
+       .add_io = NULL,
+       .add_mem = NULL,
        .init = static_init,
        .exit = NULL,
 };
@@ -264,7 +185,8 @@ struct pccard_resource_ops pccard_iodyn_ops = {
        .adjust_io_region = iodyn_adjust_io_region,
        .find_io = iodyn_find_io_region,
        .find_mem = NULL,
-       .adjust_resource = NULL,
+       .add_io = NULL,
+       .add_mem = NULL,
        .init = static_init,
        .exit = NULL,
 };
index 0fcf763..d0c1d63 100644 (file)
@@ -31,7 +31,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
@@ -261,21 +260,22 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
 ======================================================================*/
 
 /* Validation function for cards with a valid CIS */
-static int readable(struct pcmcia_socket *s, struct resource *res, cisinfo_t *info)
+static int readable(struct pcmcia_socket *s, struct resource *res,
+                   unsigned int *count)
 {
        int ret = -1;
 
        s->cis_mem.res = res;
        s->cis_virt = ioremap(res->start, s->map_size);
        if (s->cis_virt) {
-               ret = pccard_validate_cis(s, BIND_FN_ALL, info);
+               ret = pccard_validate_cis(s, BIND_FN_ALL, count);
                /* invalidate mapping and CIS cache */
                iounmap(s->cis_virt);
                s->cis_virt = NULL;
                destroy_cis_cache(s);
        }
        s->cis_mem.res = NULL;
-       if ((ret != 0) || (info->Chains == 0))
+       if ((ret != 0) || (count == 0))
                return 0;
        return 1;
 }
@@ -316,7 +316,7 @@ static int
 cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size)
 {
        struct resource *res1, *res2;
-       cisinfo_t info1, info2;
+       unsigned int info1, info2;
        int ret = 0;
 
        res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "cs memory probe");
@@ -330,7 +330,7 @@ cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size)
        free_region(res2);
        free_region(res1);
 
-       return (ret == 2) && (info1.Chains == info2.Chains);
+       return (ret == 2) && (info1 == info2);
 }
 
 static int
@@ -766,21 +766,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
 }
 
 
-static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj)
-{
-       unsigned long end;
-
-       switch (adj->Resource) {
-       case RES_MEMORY_RANGE:
-               end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
-               return adjust_memory(s, adj->Action, adj->resource.memory.Base, end);
-       case RES_IO_RANGE:
-               end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
-               return adjust_io(s, adj->Action, adj->resource.io.BasePort, end);
-       }
-       return CS_UNSUPPORTED_FUNCTION;
-}
-
 #ifdef CONFIG_PCI
 static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
 {
@@ -889,7 +874,8 @@ struct pccard_resource_ops pccard_nonstatic_ops = {
        .adjust_io_region = nonstatic_adjust_io_region,
        .find_io = nonstatic_find_io_region,
        .find_mem = nonstatic_find_mem_region,
-       .adjust_resource = nonstatic_adjust_resource_info,
+       .add_io = adjust_io,
+       .add_mem = adjust_memory,
        .init = nonstatic_init,
        .exit = nonstatic_release_resource_db,
 };
@@ -1008,41 +994,34 @@ static ssize_t store_mem_db(struct device *dev,
 }
 static DEVICE_ATTR(available_resources_mem, 0600, show_mem_db, store_mem_db);
 
-static struct device_attribute *pccard_rsrc_attributes[] = {
-       &dev_attr_available_resources_io,
-       &dev_attr_available_resources_mem,
+static struct attribute *pccard_rsrc_attributes[] = {
+       &dev_attr_available_resources_io.attr,
+       &dev_attr_available_resources_mem.attr,
        NULL,
 };
 
+static const struct attribute_group rsrc_attributes = {
+       .attrs = pccard_rsrc_attributes,
+};
+
 static int __devinit pccard_sysfs_add_rsrc(struct device *dev,
                                           struct class_interface *class_intf)
 {
        struct pcmcia_socket *s = dev_get_drvdata(dev);
-       struct device_attribute **attr;
-       int ret = 0;
+
        if (s->resource_ops != &pccard_nonstatic_ops)
                return 0;
-
-       for (attr = pccard_rsrc_attributes; *attr; attr++) {
-               ret = device_create_file(dev, *attr);
-               if (ret)
-                       break;
-       }
-
-       return ret;
+       return sysfs_create_group(&dev->kobj, &rsrc_attributes);
 }
 
 static void __devexit pccard_sysfs_remove_rsrc(struct device *dev,
                                               struct class_interface *class_intf)
 {
        struct pcmcia_socket *s = dev_get_drvdata(dev);
-       struct device_attribute **attr;
 
        if (s->resource_ops != &pccard_nonstatic_ops)
                return;
-
-       for (attr = pccard_rsrc_attributes; *attr; attr++)
-               device_remove_file(dev, *attr);
+       sysfs_remove_group(&dev->kobj, &rsrc_attributes);
 }
 
 static struct class_interface pccard_rsrc_interface __refdata = {
index 1edc1da..91ef6a0 100644 (file)
@@ -14,7 +14,6 @@
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
index 562384d..006a29e 100644 (file)
 #include <asm/system.h>
 #include <asm/irq.h>
 
-#define IN_CARD_SERVICES
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
@@ -293,7 +291,7 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
                count = 0;
        else {
                struct pcmcia_socket *s;
-               cisinfo_t cisinfo;
+               unsigned int chains;
 
                if (off + count > size)
                        count = size - off;
@@ -302,9 +300,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj,
 
                if (!(s->state & SOCKET_PRESENT))
                        return -ENODEV;
-               if (pccard_validate_cis(s, BIND_FN_ALL, &cisinfo))
+               if (pccard_validate_cis(s, BIND_FN_ALL, &chains))
                        return -EIO;
-               if (!cisinfo.Chains)
+               if (!chains)
                        return -ENODATA;
 
                count = pccard_extract_cis(s, buf, off, count);
index d29657b..129db7b 100644 (file)
 #define ENE_TEST_C9_TLTENABLE          0x02
 #define ENE_TEST_C9_PFENABLE_F0                0x04
 #define ENE_TEST_C9_PFENABLE_F1                0x08
-#define ENE_TEST_C9_PFENABLE           (ENE_TEST_C9_PFENABLE_F0 | ENE_TEST_C9_PFENABLE_F0)
+#define ENE_TEST_C9_PFENABLE           (ENE_TEST_C9_PFENABLE_F0 | ENE_TEST_C9_PFENABLE_F1)
 #define ENE_TEST_C9_WPDISALBLE_F0      0x40
 #define ENE_TEST_C9_WPDISALBLE_F1      0x80
 #define ENE_TEST_C9_WPDISALBLE         (ENE_TEST_C9_WPDISALBLE_F0 | ENE_TEST_C9_WPDISALBLE_F1)
@@ -692,7 +692,7 @@ static int ti12xx_2nd_slot_empty(struct yenta_socket *socket)
                goto out;
 
        /* check state */
-       yenta_get_status(&socket->socket, &state);
+       yenta_get_status(&slot2->socket, &state);
        if (state & SS_DETECT) {
                ret = 0;
                goto out;
index 4949dc4..fc85bf2 100644 (file)
@@ -469,6 +469,16 @@ config RTC_DRV_VR41XX
          To compile this driver as a module, choose M here: the
          module will be called rtc-vr41xx.
 
+config RTC_DRV_PL030
+       tristate "ARM AMBA PL030 RTC"
+       depends on ARM_AMBA
+       help
+         If you say Y here you will get access to ARM AMBA
+         PrimeCell PL030 RTC found on certain ARM SOCs.
+
+         To compile this driver as a module, choose M here: the
+         module will be called rtc-pl030.
+
 config RTC_DRV_PL031
        tristate "ARM AMBA PL031 RTC"
        depends on ARM_AMBA
@@ -495,12 +505,13 @@ config RTC_DRV_AT91RM9200
          this is powered by the backup power supply.
 
 config RTC_DRV_AT91SAM9
-       tristate "AT91SAM9x"
+       tristate "AT91SAM9x/AT91CAP9"
        depends on ARCH_AT91 && !(ARCH_AT91RM9200 || ARCH_AT91X40)
        help
-         RTC driver for the Atmel AT91SAM9x internal RTT (Real Time Timer).
-         These timers are powered by the backup power supply (such as a
-         small coin cell battery), but do not need to be used as RTCs.
+         RTC driver for the Atmel AT91SAM9x and AT91CAP9 internal RTT
+         (Real Time Timer). These timers are powered by the backup power
+         supply (such as a small coin cell battery), but do not need to
+         be used as RTCs.
 
          (On AT91SAM9rl chips you probably want to use the dedicated RTC
          module and leave the RTT available for other uses.)
index b6e14d5..b5d9d67 100644 (file)
@@ -41,6 +41,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_OMAP)     += rtc-omap.o
 obj-$(CONFIG_RTC_DRV_PCF8563)  += rtc-pcf8563.o
 obj-$(CONFIG_RTC_DRV_PCF8583)  += rtc-pcf8583.o
+obj-$(CONFIG_RTC_DRV_PL030)    += rtc-pl030.o
 obj-$(CONFIG_RTC_DRV_PL031)    += rtc-pl031.o
 obj-$(CONFIG_RTC_DRV_PPC)      += rtc-ppc.o
 obj-$(CONFIG_RTC_DRV_R9701)    += rtc-r9701.o
index 2ef8cdf..90b9a65 100644 (file)
@@ -265,6 +265,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
        }
 
        platform_set_drvdata(pdev, rtc);
+       device_init_wakeup(&pdev->dev, 1);
 
        dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
                        (unsigned long)rtc->regs, rtc->irq);
@@ -284,6 +285,8 @@ static int __exit at32_rtc_remove(struct platform_device *pdev)
 {
        struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
 
+       device_init_wakeup(&pdev->dev, 0);
+
        free_irq(rtc->irq, rtc);
        iounmap(rtc->regs);
        rtc_device_unregister(rtc->rtc);
index 39e64ab..9c3db93 100644 (file)
 #include <linux/completion.h>
 
 #include <asm/uaccess.h>
-#include <asm/rtc.h>
-
-#include <asm/mach/time.h>
-
 #include <asm/arch/at91_rtc.h>
 
 
index 38d8742..f0246ef 100644 (file)
@@ -19,7 +19,6 @@
 #include <linux/interrupt.h>
 #include <linux/ioctl.h>
 
-#include <asm/mach/time.h>
 #include <asm/arch/board.h>
 #include <asm/arch/at91_rtt.h>
 
index 90dfa0d..0114a78 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <linux/module.h>
 #include <linux/rtc.h>
+#include <linux/smp_lock.h>
 #include "rtc-core.h"
 
 static dev_t rtc_devt;
@@ -26,8 +27,11 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
                                        struct rtc_device, char_dev);
        const struct rtc_class_ops *ops = rtc->ops;
 
-       if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
-               return -EBUSY;
+       lock_kernel();
+       if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) {
+               err = -EBUSY;
+               goto out;
+       }
 
        file->private_data = rtc;
 
@@ -37,11 +41,13 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
                rtc->irq_data = 0;
                spin_unlock_irq(&rtc->irq_lock);
 
-               return 0;
+               goto out;
        }
 
        /* something has gone wrong */
        clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
+out:
+       unlock_kernel();
        return err;
 }
 
index a3e0880..0a19c06 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/i2c.h>
 #include <linux/rtc.h>
@@ -655,12 +656,16 @@ static int wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 static int wdt_open(struct inode *inode, struct file *file)
 {
        if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
-               if (test_and_set_bit(0, &wdt_is_open))
+               lock_kernel();
+               if (test_and_set_bit(0, &wdt_is_open)) {
+                       unlock_kernel();
                        return -EBUSY;
+               }
                /*
                 *      Activate
                 */
                wdt_is_open = 1;
+               unlock_kernel();
                return 0;
        }
        return -ENODEV;
index 58f81c7..eb23d84 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/platform_device.h>
 
 #include <asm/io.h>
-#include <asm/mach/time.h>
 
 
 /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
new file mode 100644 (file)
index 0000000..8448eeb
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ *  linux/drivers/rtc/rtc-pl030.c
+ *
+ *  Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/rtc.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/amba/bus.h>
+#include <linux/io.h>
+
+#define RTC_DR         (0)
+#define RTC_MR         (4)
+#define RTC_STAT       (8)
+#define RTC_EOI                (8)
+#define RTC_LR         (12)
+#define RTC_CR         (16)
+#define RTC_CR_MIE     (1 << 0)
+
+struct pl030_rtc {
+       struct rtc_device       *rtc;
+       void __iomem            *base;
+};
+
+static irqreturn_t pl030_interrupt(int irq, void *dev_id)
+{
+       struct pl030_rtc *rtc = dev_id;
+       writel(0, rtc->base + RTC_EOI);
+       return IRQ_HANDLED;
+}
+
+static int pl030_open(struct device *dev)
+{
+       return 0;
+}
+
+static void pl030_release(struct device *dev)
+{
+}
+
+static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+       return -ENOIOCTLCMD;
+}
+
+static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct pl030_rtc *rtc = dev_get_drvdata(dev);
+
+       rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
+       return 0;
+}
+
+static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+       struct pl030_rtc *rtc = dev_get_drvdata(dev);
+       unsigned long time;
+       int ret;
+
+       /*
+        * At the moment, we can only deal with non-wildcarded alarm times.
+        */
+       ret = rtc_valid_tm(&alrm->time);
+       if (ret == 0)
+               ret = rtc_tm_to_time(&alrm->time, &time);
+       if (ret == 0)
+               writel(time, rtc->base + RTC_MR);
+       return ret;
+}
+
+static int pl030_read_time(struct device *dev, struct rtc_time *tm)
+{
+       struct pl030_rtc *rtc = dev_get_drvdata(dev);
+
+       rtc_time_to_tm(readl(rtc->base + RTC_DR), tm);
+
+       return 0;
+}
+
+/*
+ * Set the RTC time.  Unfortunately, we can't accurately set
+ * the point at which the counter updates.
+ *
+ * Also, since RTC_LR is transferred to RTC_CR on next rising
+ * edge of the 1Hz clock, we must write the time one second
+ * in advance.
+ */
+static int pl030_set_time(struct device *dev, struct rtc_time *tm)
+{
+       struct pl030_rtc *rtc = dev_get_drvdata(dev);
+       unsigned long time;
+       int ret;
+
+       ret = rtc_tm_to_time(tm, &time);
+       if (ret == 0)
+               writel(time + 1, rtc->base + RTC_LR);
+
+       return ret;
+}
+
+static const struct rtc_class_ops pl030_ops = {
+       .open           = pl030_open,
+       .release        = pl030_release,
+       .ioctl          = pl030_ioctl,
+       .read_time      = pl030_read_time,
+       .set_time       = pl030_set_time,
+       .read_alarm     = pl030_read_alarm,
+       .set_alarm      = pl030_set_alarm,
+};
+
+static int pl030_probe(struct amba_device *dev, void *id)
+{
+       struct pl030_rtc *rtc;
+       int ret;
+
+       ret = amba_request_regions(dev, NULL);
+       if (ret)
+               goto err_req;
+
+       rtc = kmalloc(sizeof(*rtc), GFP_KERNEL);
+       if (!rtc) {
+               ret = -ENOMEM;
+               goto err_rtc;
+       }
+
+       rtc->base = ioremap(dev->res.start, SZ_4K);
+       if (!rtc->base) {
+               ret = -ENOMEM;
+               goto err_map;
+       }
+
+       __raw_writel(0, rtc->base + RTC_CR);
+       __raw_writel(0, rtc->base + RTC_EOI);
+
+       amba_set_drvdata(dev, rtc);
+
+       ret = request_irq(dev->irq[0], pl030_interrupt, IRQF_DISABLED,
+                         "rtc-pl030", rtc);
+       if (ret)
+               goto err_irq;
+
+       rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops,
+                                      THIS_MODULE);
+       if (IS_ERR(rtc->rtc)) {
+               ret = PTR_ERR(rtc->rtc);
+               goto err_reg;
+       }
+
+       return 0;
+
+ err_reg:
+       free_irq(dev->irq[0], rtc);
+ err_irq:
+       iounmap(rtc->base);
+ err_map:
+       kfree(rtc);
+ err_rtc:
+       amba_release_regions(dev);
+ err_req:
+       return ret;
+}
+
+static int pl030_remove(struct amba_device *dev)
+{
+       struct pl030_rtc *rtc = amba_get_drvdata(dev);
+
+       amba_set_drvdata(dev, NULL);
+
+       writel(0, rtc->base + RTC_CR);
+
+       free_irq(dev->irq[0], rtc);
+       rtc_device_unregister(rtc->rtc);
+       iounmap(rtc->base);
+       kfree(rtc);
+       amba_release_regions(dev);
+
+       return 0;
+}
+
+static struct amba_id pl030_ids[] = {
+       {
+               .id     = 0x00041030,
+               .mask   = 0x000fffff,
+       },
+       { 0, 0 },
+};
+
+static struct amba_driver pl030_driver = {
+       .drv            = {
+               .name   = "rtc-pl030",
+       },
+       .probe          = pl030_probe,
+       .remove         = pl030_remove,
+       .id_table       = pl030_ids,
+};
+
+static int __init pl030_init(void)
+{
+       return amba_driver_register(&pl030_driver);
+}
+
+static void __exit pl030_exit(void)
+{
+       amba_driver_unregister(&pl030_driver);
+}
+
+module_init(pl030_init);
+module_exit(pl030_exit);
+
+MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
+MODULE_DESCRIPTION("ARM AMBA PL030 RTC Driver");
+MODULE_LICENSE("GPL");
index 2fd49ed..08b4610 100644 (file)
  * as published by the Free Software Foundation; either version
  * 2 of the License, or (at your option) any later version.
  */
-
-#include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
-#include <linux/fs.h>
 #include <linux/interrupt.h>
-#include <linux/string.h>
-#include <linux/pm.h>
-#include <linux/bitops.h>
-
 #include <linux/amba/bus.h>
-
-#include <asm/io.h>
-#include <asm/hardware.h>
-#include <asm/irq.h>
-#include <asm/rtc.h>
+#include <linux/io.h>
 
 /*
  * Register definitions
@@ -142,13 +131,12 @@ static int pl031_remove(struct amba_device *adev)
 {
        struct pl031_local *ldata = dev_get_drvdata(&adev->dev);
 
-       if (ldata) {
-               dev_set_drvdata(&adev->dev, NULL);
-               free_irq(adev->irq[0], ldata->rtc);
-               rtc_device_unregister(ldata->rtc);
-               iounmap(ldata->base);
-               kfree(ldata);
-       }
+       amba_set_drvdata(adev, NULL);
+       free_irq(adev->irq[0], ldata->rtc);
+       rtc_device_unregister(ldata->rtc);
+       iounmap(ldata->base);
+       kfree(ldata);
+       amba_release_regions(adev);
 
        return 0;
 }
@@ -158,13 +146,15 @@ static int pl031_probe(struct amba_device *adev, void *id)
        int ret;
        struct pl031_local *ldata;
 
+       ret = amba_request_regions(adev, NULL);
+       if (ret)
+               goto err_req;
 
        ldata = kmalloc(sizeof(struct pl031_local), GFP_KERNEL);
        if (!ldata) {
                ret = -ENOMEM;
                goto out;
        }
-       dev_set_drvdata(&adev->dev, ldata);
 
        ldata->base = ioremap(adev->res.start,
                              adev->res.end - adev->res.start + 1);
@@ -173,6 +163,8 @@ static int pl031_probe(struct amba_device *adev, void *id)
                goto out_no_remap;
        }
 
+       amba_set_drvdata(adev, ldata);
+
        if (request_irq(adev->irq[0], pl031_interrupt, IRQF_DISABLED,
                        "rtc-pl031", ldata->rtc)) {
                ret = -EIO;
@@ -192,10 +184,12 @@ out_no_rtc:
        free_irq(adev->irq[0], ldata->rtc);
 out_no_irq:
        iounmap(ldata->base);
+       amba_set_drvdata(adev, NULL);
 out_no_remap:
-       dev_set_drvdata(&adev->dev, NULL);
        kfree(ldata);
 out:
+       amba_release_regions(adev);
+err_req:
        return ret;
 }
 
index f26e0ca..fed86e5 100644 (file)
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/irq.h>
-#include <asm/rtc.h>
-
-#include <asm/mach/time.h>
-
 #include <asm/plat-s3c/regs-rtc.h>
 
 /* I have yet to find an S3C implementation with more than one
index 67421b0..f47294c 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <asm/hardware.h>
 #include <asm/irq.h>
-#include <asm/rtc.h>
 
 #ifdef CONFIG_ARCH_PXA
 #include <asm/arch/pxa-regs.h>
@@ -47,6 +46,42 @@ static unsigned long rtc_freq = 1024;
 static struct rtc_time rtc_alarm;
 static DEFINE_SPINLOCK(sa1100_rtc_lock);
 
+static inline int rtc_periodic_alarm(struct rtc_time *tm)
+{
+       return  (tm->tm_year == -1) ||
+               ((unsigned)tm->tm_mon >= 12) ||
+               ((unsigned)(tm->tm_mday - 1) >= 31) ||
+               ((unsigned)tm->tm_hour > 23) ||
+               ((unsigned)tm->tm_min > 59) ||
+               ((unsigned)tm->tm_sec > 59);
+}
+
+/*
+ * Calculate the next alarm time given the requested alarm time mask
+ * and the current time.
+ */
+static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm)
+{
+       unsigned long next_time;
+       unsigned long now_time;
+
+       next->tm_year = now->tm_year;
+       next->tm_mon = now->tm_mon;
+       next->tm_mday = now->tm_mday;
+       next->tm_hour = alrm->tm_hour;
+       next->tm_min = alrm->tm_min;
+       next->tm_sec = alrm->tm_sec;
+
+       rtc_tm_to_time(now, &now_time);
+       rtc_tm_to_time(next, &next_time);
+
+       if (next_time < now_time) {
+               /* Advance one day */
+               next_time += 60 * 60 * 24;
+               rtc_time_to_tm(next_time, next);
+       }
+}
+
 static int rtc_update_alarm(struct rtc_time *alrm)
 {
        struct rtc_time alarm_tm, now_tm;
index 1a40256..1b6c52e 100644 (file)
@@ -995,14 +995,14 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
        now = get_clock();
 
        DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
-                 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
-                 (unsigned int) intparm);
+                 cdev->dev.bus_id, ((irb->scsw.cmd.cstat << 8) |
+                 irb->scsw.cmd.dstat), (unsigned int) intparm);
 
        /* check for unsolicited interrupts */
        cqr = (struct dasd_ccw_req *) intparm;
-       if (!cqr || ((irb->scsw.cc == 1) &&
-                    (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
-                    (irb->scsw.stctl & SCSW_STCTL_STATUS_PEND)) ) {
+       if (!cqr || ((irb->scsw.cmd.cc == 1) &&
+                    (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
+                    (irb->scsw.cmd.stctl & SCSW_STCTL_STATUS_PEND))) {
                if (cqr && cqr->status == DASD_CQR_IN_IO)
                        cqr->status = DASD_CQR_QUEUED;
                device = dasd_device_from_cdev_locked(cdev);
@@ -1025,7 +1025,7 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
 
        /* Check for clear pending */
        if (cqr->status == DASD_CQR_CLEAR_PENDING &&
-           irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
+           irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC) {
                cqr->status = DASD_CQR_CLEARED;
                dasd_device_clear_timer(device);
                wake_up(&dasd_flush_wq);
@@ -1041,11 +1041,11 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
                return;
        }
        DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
-                     ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
+                     ((irb->scsw.cmd.cstat << 8) | irb->scsw.cmd.dstat), cqr);
        next = NULL;
        expires = 0;
-       if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
-           irb->scsw.cstat == 0 && !irb->esw.esw0.erw.cons) {
+       if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
+           irb->scsw.cmd.cstat == 0 && !irb->esw.esw0.erw.cons) {
                /* request was completed successfully */
                cqr->status = DASD_CQR_SUCCESS;
                cqr->stopclk = now;
index e6700df..5c6e6f3 100644 (file)
@@ -1572,7 +1572,7 @@ dasd_3990_erp_action_1B_32(struct dasd_ccw_req * default_erp, char *sense)
 
        /* determine the address of the CCW to be restarted */
        /* Imprecise ending is not set -> addr from IRB-SCSW */
-       cpa = default_erp->refers->irb.scsw.cpa;
+       cpa = default_erp->refers->irb.scsw.cmd.cpa;
 
        if (cpa == 0) {
 
@@ -1725,7 +1725,7 @@ dasd_3990_update_1B(struct dasd_ccw_req * previous_erp, char *sense)
 
        /* determine the address of the CCW to be restarted */
        /* Imprecise ending is not set -> addr from IRB-SCSW */
-       cpa = previous_erp->irb.scsw.cpa;
+       cpa = previous_erp->irb.scsw.cmd.cpa;
 
        if (cpa == 0) {
 
@@ -2171,7 +2171,7 @@ dasd_3990_erp_control_check(struct dasd_ccw_req *erp)
 {
        struct dasd_device *device = erp->startdev;
 
-       if (erp->refers->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK
+       if (erp->refers->irb.scsw.cmd.cstat & (SCHN_STAT_INTF_CTRL_CHK
                                           | SCHN_STAT_CHN_CTRL_CHK)) {
                DEV_MESSAGE(KERN_DEBUG, device, "%s",
                            "channel or interface control check");
@@ -2352,9 +2352,9 @@ dasd_3990_erp_error_match(struct dasd_ccw_req *cqr1, struct dasd_ccw_req *cqr2)
 
        if ((cqr1->irb.esw.esw0.erw.cons == 0) &&
            (cqr2->irb.esw.esw0.erw.cons == 0)) {
-               if ((cqr1->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK |
+               if ((cqr1->irb.scsw.cmd.cstat & (SCHN_STAT_INTF_CTRL_CHK |
                                             SCHN_STAT_CHN_CTRL_CHK)) ==
-                   (cqr2->irb.scsw.cstat & (SCHN_STAT_INTF_CTRL_CHK |
+                   (cqr2->irb.scsw.cmd.cstat & (SCHN_STAT_INTF_CTRL_CHK |
                                             SCHN_STAT_CHN_CTRL_CHK)))
                        return 1; /* match with ifcc*/
        }
@@ -2622,8 +2622,9 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
        }
 
        /* double-check if current erp/cqr was successfull */
-       if ((cqr->irb.scsw.cstat == 0x00) &&
-           (cqr->irb.scsw.dstat == (DEV_STAT_CHN_END|DEV_STAT_DEV_END))) {
+       if ((cqr->irb.scsw.cmd.cstat == 0x00) &&
+           (cqr->irb.scsw.cmd.dstat ==
+            (DEV_STAT_CHN_END | DEV_STAT_DEV_END))) {
 
                DEV_MESSAGE(KERN_DEBUG, device,
                            "ERP called for successful request %p"
index a0edae0..e0b7721 100644 (file)
@@ -1404,13 +1404,14 @@ static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
 
        /* first of all check for state change pending interrupt */
        mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
-       if ((irb->scsw.dstat & mask) == mask) {
+       if ((irb->scsw.cmd.dstat & mask) == mask) {
                dasd_generic_handle_state_change(device);
                return;
        }
 
        /* summary unit check */
-       if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) && irb->ecw[7] == 0x0D) {
+       if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
+           (irb->ecw[7] == 0x0D)) {
                dasd_alias_handle_summary_unit_check(device, irb);
                return;
        }
@@ -2068,11 +2069,11 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
                      device->cdev->dev.bus_id);
        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
                       " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
-                      irb->scsw.cstat, irb->scsw.dstat);
+                      irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
                       " device %s: Failing CCW: %p\n",
                       device->cdev->dev.bus_id,
-                      (void *) (addr_t) irb->scsw.cpa);
+                      (void *) (addr_t) irb->scsw.cmd.cpa);
        if (irb->esw.esw0.erw.cons) {
                for (sl = 0; sl < 4; sl++) {
                        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
@@ -2122,7 +2123,8 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
                /* scsw->cda is either valid or zero  */
                len = 0;
                from = ++to;
-               fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
+               fail = (struct ccw1 *)(addr_t)
+                               irb->scsw.cmd.cpa; /* failing CCW */
                if (from <  fail - 2) {
                        from = fail - 2;     /* there is a gap - print header */
                        len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
index 6e53ab6..29da441 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/device.h>
 #include <linux/poll.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/atomic.h>
@@ -525,6 +526,7 @@ static int dasd_eer_open(struct inode *inp, struct file *filp)
        eerb = kzalloc(sizeof(struct eerbuffer), GFP_KERNEL);
        if (!eerb)
                return -ENOMEM;
+       lock_kernel();
        eerb->buffer_page_count = eer_pages;
        if (eerb->buffer_page_count < 1 ||
            eerb->buffer_page_count > INT_MAX / PAGE_SIZE) {
@@ -532,6 +534,7 @@ static int dasd_eer_open(struct inode *inp, struct file *filp)
                MESSAGE(KERN_WARNING, "can't open device since module "
                        "parameter eer_pages is smaller then 1 or"
                        " bigger then %d", (int)(INT_MAX / PAGE_SIZE));
+               unlock_kernel();
                return -EINVAL;
        }
        eerb->buffersize = eerb->buffer_page_count * PAGE_SIZE;
@@ -539,12 +542,14 @@ static int dasd_eer_open(struct inode *inp, struct file *filp)
                               GFP_KERNEL);
         if (!eerb->buffer) {
                kfree(eerb);
+               unlock_kernel();
                 return -ENOMEM;
        }
        if (dasd_eer_allocate_buffer_pages(eerb->buffer,
                                           eerb->buffer_page_count)) {
                kfree(eerb->buffer);
                kfree(eerb);
+               unlock_kernel();
                return -ENOMEM;
        }
        filp->private_data = eerb;
@@ -552,6 +557,7 @@ static int dasd_eer_open(struct inode *inp, struct file *filp)
        list_add(&eerb->list, &bufferlist);
        spin_unlock_irqrestore(&bufferlock, flags);
 
+       unlock_kernel();
        return nonseekable_open(inp,filp);
 }
 
index 1166115..aee4656 100644 (file)
@@ -222,7 +222,7 @@ static void dasd_fba_handle_unsolicited_interrupt(struct dasd_device *device,
 
        /* first of all check for state change pending interrupt */
        mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
-       if ((irb->scsw.dstat & mask) == mask) {
+       if ((irb->scsw.cmd.dstat & mask) == mask) {
                dasd_generic_handle_state_change(device);
                return;
        }
@@ -449,11 +449,11 @@ dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
                      device->cdev->dev.bus_id);
        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
                       " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
-                      irb->scsw.cstat, irb->scsw.dstat);
+                      irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
                       " device %s: Failing CCW: %p\n",
                       device->cdev->dev.bus_id,
-                      (void *) (addr_t) irb->scsw.cpa);
+                      (void *) (addr_t) irb->scsw.cmd.cpa);
        if (irb->esw.esw0.erw.cons) {
                for (sl = 0; sl < 4; sl++) {
                        len += sprintf(page + len, KERN_ERR PRINTK_HEADER
@@ -498,11 +498,11 @@ dasd_fba_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
 
        /* print failing CCW area */
        len = 0;
-       if (act <  ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2) {
-               act = ((struct ccw1 *)(addr_t) irb->scsw.cpa) - 2;
+       if (act <  ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2) {
+               act = ((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa) - 2;
                len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
        }
-       end = min((struct ccw1 *)(addr_t) irb->scsw.cpa + 2, last);
+       end = min((struct ccw1 *)(addr_t) irb->scsw.cmd.cpa + 2, last);
        while (act <= end) {
                len += sprintf(page + len, KERN_ERR PRINTK_HEADER
                               " CCW %p: %08X %08X DAT:",
index bb52d2f..01fcdd9 100644 (file)
@@ -167,10 +167,8 @@ dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const ch
        struct dcssblk_dev_info *dev_info;
        int rc;
 
-       if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0')) {
-               PRINT_WARN("Invalid value, must be 0 or 1\n");
+       if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
                return -EINVAL;
-       }
        down_write(&dcssblk_devices_sem);
        dev_info = container_of(dev, struct dcssblk_dev_info, dev);
        if (atomic_read(&dev_info->use_count)) {
@@ -215,7 +213,6 @@ dcssblk_shared_store(struct device *dev, struct device_attribute *attr, const ch
                        set_disk_ro(dev_info->gd, 0);
                }
        } else {
-               PRINT_WARN("Invalid value, must be 0 or 1\n");
                rc = -EINVAL;
                goto out;
        }
@@ -258,10 +255,8 @@ dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char
 {
        struct dcssblk_dev_info *dev_info;
 
-       if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0')) {
-               PRINT_WARN("Invalid value, must be 0 or 1\n");
+       if ((count > 1) && (inbuf[1] != '\n') && (inbuf[1] != '\0'))
                return -EINVAL;
-       }
        dev_info = container_of(dev, struct dcssblk_dev_info, dev);
 
        down_write(&dcssblk_devices_sem);
@@ -289,7 +284,6 @@ dcssblk_save_store(struct device *dev, struct device_attribute *attr, const char
                }
        } else {
                up_write(&dcssblk_devices_sem);
-               PRINT_WARN("Invalid value, must be 0 or 1\n");
                return -EINVAL;
        }
        up_write(&dcssblk_devices_sem);
@@ -441,7 +435,6 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        goto out;
 
 unregister_dev:
-       PRINT_ERR("device_create_file() failed!\n");
        list_del(&dev_info->lh);
        blk_cleanup_queue(dev_info->dcssblk_queue);
        dev_info->gd->queue = NULL;
@@ -702,10 +695,8 @@ dcssblk_check_params(void)
 static void __exit
 dcssblk_exit(void)
 {
-       PRINT_DEBUG("DCSSBLOCK EXIT...\n");
        s390_root_dev_unregister(dcssblk_root_dev);
        unregister_blkdev(dcssblk_major, DCSSBLK_NAME);
-       PRINT_DEBUG("...finished!\n");
 }
 
 static int __init
@@ -713,27 +704,21 @@ dcssblk_init(void)
 {
        int rc;
 
-       PRINT_DEBUG("DCSSBLOCK INIT...\n");
        dcssblk_root_dev = s390_root_dev_register("dcssblk");
-       if (IS_ERR(dcssblk_root_dev)) {
-               PRINT_ERR("device_register() failed!\n");
+       if (IS_ERR(dcssblk_root_dev))
                return PTR_ERR(dcssblk_root_dev);
-       }
        rc = device_create_file(dcssblk_root_dev, &dev_attr_add);
        if (rc) {
-               PRINT_ERR("device_create_file(add) failed!\n");
                s390_root_dev_unregister(dcssblk_root_dev);
                return rc;
        }
        rc = device_create_file(dcssblk_root_dev, &dev_attr_remove);
        if (rc) {
-               PRINT_ERR("device_create_file(remove) failed!\n");
                s390_root_dev_unregister(dcssblk_root_dev);
                return rc;
        }
        rc = register_blkdev(0, DCSSBLK_NAME);
        if (rc < 0) {
-               PRINT_ERR("Can't get dynamic major!\n");
                s390_root_dev_unregister(dcssblk_root_dev);
                return rc;
        }
@@ -742,7 +727,6 @@ dcssblk_init(void)
 
        dcssblk_check_params();
 
-       PRINT_DEBUG("...finished!\n");
        return 0;
 }
 
index f231bc2..dd9b986 100644 (file)
@@ -100,15 +100,10 @@ static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
                : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
        if (cc == 3)
                return -ENXIO;
-       if (cc == 2) {
-               PRINT_ERR("expanded storage lost!\n");
+       if (cc == 2)
                return -ENXIO;
-       }
-       if (cc == 1) {
-               PRINT_ERR("page in failed for page index %u.\n",
-                         xpage_index);
+       if (cc == 1)
                return -EIO;
-       }
        return 0;
 }
 
@@ -135,15 +130,10 @@ static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
                : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
        if (cc == 3)
                return -ENXIO;
-       if (cc == 2) {
-               PRINT_ERR("expanded storage lost!\n");
+       if (cc == 2)
                return -ENXIO;
-       }
-       if (cc == 1) {
-               PRINT_ERR("page out failed for page index %u.\n",
-                         xpage_index);
+       if (cc == 1)
                return -EIO;
-       }
        return 0;
 }
 
index 3e5653c..d3ec9b5 100644 (file)
@@ -93,9 +93,6 @@ struct raw3215_info {
        struct raw3215_req *queued_write;/* pointer to queued write requests */
        wait_queue_head_t empty_wait; /* wait queue for flushing */
        struct timer_list timer;      /* timer for delayed output */
-       char *message;                /* pending message from raw3215_irq */
-       int msg_dstat;                /* dstat for pending message */
-       int msg_cstat;                /* cstat for pending message */
        int line_pos;                 /* position on the line (for tabs) */
        char ubuffer[80];             /* copy_from_user buffer */
 };
@@ -359,11 +356,6 @@ raw3215_tasklet(void *data)
        raw3215_mk_write_req(raw);
        raw3215_try_io(raw);
        spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
-       /* Check for pending message from raw3215_irq */
-       if (raw->message != NULL) {
-               printk(raw->message, raw->msg_dstat, raw->msg_cstat);
-               raw->message = NULL;
-       }
        tty = raw->tty;
        if (tty != NULL &&
            RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
@@ -381,20 +373,14 @@ raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        struct raw3215_req *req;
        struct tty_struct *tty;
        int cstat, dstat;
-       int count, slen;
+       int count;
 
        raw = cdev->dev.driver_data;
        req = (struct raw3215_req *) intparm;
-       cstat = irb->scsw.cstat;
-       dstat = irb->scsw.dstat;
-       if (cstat != 0) {
-               raw->message = KERN_WARNING
-                       "Got nonzero channel status in raw3215_irq "
-                       "(dev sts 0x%2x, sch sts 0x%2x)";
-               raw->msg_dstat = dstat;
-               raw->msg_cstat = cstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
+       if (cstat != 0)
                tasklet_schedule(&raw->tasklet);
-       }
        if (dstat & 0x01) { /* we got a unit exception */
                dstat &= ~0x01;  /* we can ignore it */
        }
@@ -404,8 +390,6 @@ raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                        break;
                /* Attention interrupt, someone hit the enter key */
                raw3215_mk_read_req(raw);
-               if (MACHINE_IS_P390)
-                       memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
                tasklet_schedule(&raw->tasklet);
                break;
        case 0x08:
@@ -415,7 +399,7 @@ raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                        return;              /* That shouldn't happen ... */
                if (req->type == RAW3215_READ) {
                        /* store residual count, then wait for device end */
-                       req->residual = irb->scsw.count;
+                       req->residual = irb->scsw.cmd.count;
                }
                if (dstat == 0x08)
                        break;
@@ -428,11 +412,6 @@ raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
 
                        tty = raw->tty;
                        count = 160 - req->residual;
-                       if (MACHINE_IS_P390) {
-                               slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE);
-                               if (count > slen)
-                                       count = slen;
-                       } else
                        EBCASC(raw->inbuf, count);
                        cchar = ctrlchar_handle(raw->inbuf, count, tty);
                        switch (cchar & CTRLCHAR_MASK) {
@@ -481,11 +460,6 @@ raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                        raw->flags &= ~RAW3215_WORKING;
                        raw3215_free_req(req);
                }
-               raw->message = KERN_WARNING
-                       "Spurious interrupt in in raw3215_irq "
-                       "(dev sts 0x%2x, sch sts 0x%2x)";
-               raw->msg_dstat = dstat;
-               raw->msg_cstat = cstat;
                tasklet_schedule(&raw->tasklet);
        }
        return;
@@ -883,7 +857,6 @@ con3215_init(void)
                free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
                free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
                raw3215[0] = NULL;
-               printk("Couldn't find a 3215 console device\n");
                return -ENODEV;
        }
        register_console(&con3215);
@@ -1157,7 +1130,6 @@ tty3215_init(void)
        tty_set_operations(driver, &tty3215_ops);
        ret = tty_register_driver(driver);
        if (ret) {
-               printk("Couldn't register tty3215 driver\n");
                put_tty_driver(driver);
                return ret;
        }
index 0b04055..3c07974 100644 (file)
@@ -411,15 +411,15 @@ static int
 con3270_irq(struct con3270 *cp, struct raw3270_request *rq, struct irb *irb)
 {
        /* Handle ATTN. Schedule tasklet to read aid. */
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION)
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
                con3270_issue_read(cp);
 
        if (rq) {
-               if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
+               if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                        rq->rc = -EIO;
                else
                        /* Normal end. Copy residual count. */
-                       rq->rescnt = irb->scsw.count;
+                       rq->rescnt = irb->scsw.cmd.count;
        }
        return RAW3270_IO_DONE;
 }
index ef36f21..d18e6d2 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/interrupt.h>
 #include <linux/list.h>
 #include <linux/types.h>
+#include <linux/smp_lock.h>
 
 #include <asm/ccwdev.h>
 #include <asm/cio.h>
@@ -216,17 +217,17 @@ static int
 fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
 {
        /* Handle ATTN. Set indication and wake waiters for attention. */
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                fp->attention = 1;
                wake_up(&fp->wait);
        }
 
        if (rq) {
-               if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
+               if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                        rq->rc = -EIO;
                else
                        /* Normal end. Copy residual count. */
-                       rq->rescnt = irb->scsw.count;
+                       rq->rescnt = irb->scsw.cmd.count;
        }
        return RAW3270_IO_DONE;
 }
@@ -421,6 +422,7 @@ fs3270_open(struct inode *inode, struct file *filp)
 
        if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR)
                return -ENODEV;
+       lock_kernel();
        minor = iminor(filp->f_path.dentry->d_inode);
        /* Check for minor 0 multiplexer. */
        if (minor == 0) {
@@ -429,7 +431,8 @@ fs3270_open(struct inode *inode, struct file *filp)
                tty = get_current_tty();
                if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
                        mutex_unlock(&tty_mutex);
-                       return -ENODEV;
+                       rc = -ENODEV;
+                       goto out;
                }
                minor = tty->index + RAW3270_FIRSTMINOR;
                mutex_unlock(&tty_mutex);
@@ -438,19 +441,22 @@ fs3270_open(struct inode *inode, struct file *filp)
        fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
        if (!IS_ERR(fp)) {
                raw3270_put_view(&fp->view);
-               return -EBUSY;
+               rc = -EBUSY;
+               goto out;
        }
        /* Allocate fullscreen view structure. */
        fp = fs3270_alloc_view();
-       if (IS_ERR(fp))
-               return PTR_ERR(fp);
+       if (IS_ERR(fp)) {
+               rc = PTR_ERR(fp);
+               goto out;
+       }
 
        init_waitqueue_head(&fp->wait);
        fp->fs_pid = get_pid(task_pid(current));
        rc = raw3270_add_view(&fp->view, &fs3270_fn, minor);
        if (rc) {
                fs3270_free_view(&fp->view);
-               return rc;
+               goto out;
        }
 
        /* Allocate idal-buffer. */
@@ -458,7 +464,8 @@ fs3270_open(struct inode *inode, struct file *filp)
        if (IS_ERR(ib)) {
                raw3270_put_view(&fp->view);
                raw3270_del_view(&fp->view);
-               return PTR_ERR(fp);
+               rc = PTR_ERR(fp);
+               goto out;
        }
        fp->rdbuf = ib;
 
@@ -466,9 +473,11 @@ fs3270_open(struct inode *inode, struct file *filp)
        if (rc) {
                raw3270_put_view(&fp->view);
                raw3270_del_view(&fp->view);
-               return rc;
+               goto out;
        }
        filp->private_data = fp;
+out:
+       unlock_kernel();
        return 0;
 }
 
@@ -512,11 +521,8 @@ fs3270_init(void)
        int rc;
 
        rc = register_chrdev(IBM_FS3270_MAJOR, "fs3270", &fs3270_fops);
-       if (rc) {
-               printk(KERN_ERR "fs3270 can't get major number %d: errno %d\n",
-                      IBM_FS3270_MAJOR, rc);
+       if (rc)
                return rc;
-       }
        return 0;
 }
 
index 1e1f506..35fd8df 100644 (file)
@@ -3,14 +3,14 @@
  *
  * Character device driver for reading z/VM *MONITOR service records.
  *
- * Copyright 2004 IBM Corporation, IBM Deutschland Entwicklung GmbH.
- *
- * Author: Gerald Schaefer <geraldsc@de.ibm.com>
+ *   Copyright IBM Corp. 2004, 2008
+ *   Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  */
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/ctype.h>
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
+#include <linux/poll.h>
+#include <net/iucv/iucv.h>
 #include <asm/uaccess.h>
 #include <asm/ebcdic.h>
 #include <asm/extmem.h>
-#include <linux/poll.h>
-#include <net/iucv/iucv.h>
-
 
 //#define MON_DEBUG                    /* Debug messages on/off */
 
@@ -152,10 +151,7 @@ static int mon_check_mca(struct mon_msg *monmsg)
            (mon_mca_end(monmsg) > mon_dcss_end) ||
            (mon_mca_start(monmsg) < mon_dcss_start) ||
            ((mon_mca_type(monmsg, 1) == 0) && (mon_mca_type(monmsg, 2) == 0)))
-       {
-               P_DEBUG("READ, IGNORED INVALID MCA\n\n");
                return -EINVAL;
-       }
        return 0;
 }
 
@@ -164,10 +160,6 @@ static int mon_send_reply(struct mon_msg *monmsg,
 {
        int rc;
 
-       P_DEBUG("read, REPLY: pathid = 0x%04X, msgid = 0x%08X, trgcls = "
-               "0x%08X\n\n",
-               monpriv->path->pathid, monmsg->msg.id, monmsg->msg.class);
-
        rc = iucv_message_reply(monpriv->path, &monmsg->msg,
                                IUCV_IPRMDATA, NULL, 0);
        atomic_dec(&monpriv->msglim_count);
@@ -202,15 +194,12 @@ static struct mon_private *mon_alloc_mem(void)
        struct mon_private *monpriv;
 
        monpriv = kzalloc(sizeof(struct mon_private), GFP_KERNEL);
-       if (!monpriv) {
-               P_ERROR("no memory for monpriv\n");
+       if (!monpriv)
                return NULL;
-       }
        for (i = 0; i < MON_MSGLIM; i++) {
                monpriv->msg_array[i] = kzalloc(sizeof(struct mon_msg),
                                                    GFP_KERNEL);
                if (!monpriv->msg_array[i]) {
-                       P_ERROR("open, no memory for msg_array\n");
                        mon_free_mem(monpriv);
                        return NULL;
                }
@@ -218,41 +207,10 @@ static struct mon_private *mon_alloc_mem(void)
        return monpriv;
 }
 
-static inline void mon_read_debug(struct mon_msg *monmsg,
-                                 struct mon_private *monpriv)
-{
-#ifdef MON_DEBUG
-       u8 msg_type[2], mca_type;
-       unsigned long records_len;
-
-       records_len = mon_rec_end(monmsg) - mon_rec_start(monmsg) + 1;
-
-       memcpy(msg_type, &monmsg->msg.class, 2);
-       EBCASC(msg_type, 2);
-       mca_type = mon_mca_type(monmsg, 0);
-       EBCASC(&mca_type, 1);
-
-       P_DEBUG("read, mon_read_index = %i, mon_write_index = %i\n",
-               monpriv->read_index, monpriv->write_index);
-       P_DEBUG("read, pathid = 0x%04X, msgid = 0x%08X, trgcls = 0x%08X\n",
-               monpriv->path->pathid, monmsg->msg.id, monmsg->msg.class);
-       P_DEBUG("read, msg_type = '%c%c', mca_type = '%c' / 0x%X / 0x%X\n",
-               msg_type[0], msg_type[1], mca_type ? mca_type : 'X',
-               mon_mca_type(monmsg, 1), mon_mca_type(monmsg, 2));
-       P_DEBUG("read, MCA: start = 0x%lX, end = 0x%lX\n",
-               mon_mca_start(monmsg), mon_mca_end(monmsg));
-       P_DEBUG("read, REC: start = 0x%X, end = 0x%X, len = %lu\n\n",
-               mon_rec_start(monmsg), mon_rec_end(monmsg), records_len);
-       if (mon_mca_size(monmsg) > 12)
-               P_DEBUG("READ, MORE THAN ONE MCA\n\n");
-#endif
-}
-
 static inline void mon_next_mca(struct mon_msg *monmsg)
 {
        if (likely((mon_mca_size(monmsg) - monmsg->mca_offset) == 12))
                return;
-       P_DEBUG("READ, NEXT MCA\n\n");
        monmsg->mca_offset += 12;
        monmsg->pos = 0;
 }
@@ -269,7 +227,6 @@ static struct mon_msg *mon_next_message(struct mon_private *monpriv)
                monmsg->msglim_reached = 0;
                monmsg->pos = 0;
                monmsg->mca_offset = 0;
-               P_WARNING("read, message limit reached\n");
                monpriv->read_index = (monpriv->read_index + 1) %
                                      MON_MSGLIM;
                atomic_dec(&monpriv->read_ready);
@@ -286,10 +243,6 @@ static void mon_iucv_path_complete(struct iucv_path *path, u8 ipuser[16])
 {
        struct mon_private *monpriv = path->private;
 
-       P_DEBUG("IUCV connection completed\n");
-       P_DEBUG("IUCV ACCEPT (from *MONITOR): Version = 0x%02X, Event = "
-               "0x%02X, Sample = 0x%02X\n",
-               ipuser[0], ipuser[1], ipuser[2]);
        atomic_set(&monpriv->iucv_connected, 1);
        wake_up(&mon_conn_wait_queue);
 }
@@ -310,7 +263,6 @@ static void mon_iucv_message_pending(struct iucv_path *path,
 {
        struct mon_private *monpriv = path->private;
 
-       P_DEBUG("IUCV message pending\n");
        memcpy(&monpriv->msg_array[monpriv->write_index]->msg,
               msg, sizeof(*msg));
        if (atomic_inc_return(&monpriv->msglim_count) == MON_MSGLIM) {
@@ -340,6 +292,7 @@ static int mon_open(struct inode *inode, struct file *filp)
        /*
         * only one user allowed
         */
+       lock_kernel();
        rc = -EBUSY;
        if (test_and_set_bit(MON_IN_USE, &mon_in_use))
                goto out;
@@ -375,8 +328,8 @@ static int mon_open(struct inode *inode, struct file *filp)
                rc = -EIO;
                goto out_path;
        }
-       P_INFO("open, established connection to *MONITOR service\n\n");
        filp->private_data = monpriv;
+       unlock_kernel();
        return nonseekable_open(inode, filp);
 
 out_path:
@@ -386,6 +339,7 @@ out_priv:
 out_use:
        clear_bit(MON_IN_USE, &mon_in_use);
 out:
+       unlock_kernel();
        return rc;
 }
 
@@ -400,8 +354,6 @@ static int mon_close(struct inode *inode, struct file *filp)
        rc = iucv_path_sever(monpriv->path, user_data_sever);
        if (rc)
                P_ERROR("close, iucv_sever failed with rc = %i\n", rc);
-       else
-               P_INFO("close, terminated connection to *MONITOR service\n");
 
        atomic_set(&monpriv->iucv_severed, 0);
        atomic_set(&monpriv->iucv_connected, 0);
@@ -442,10 +394,8 @@ static ssize_t mon_read(struct file *filp, char __user *data,
                monmsg = monpriv->msg_array[monpriv->read_index];
        }
 
-       if (!monmsg->pos) {
+       if (!monmsg->pos)
                monmsg->pos = mon_mca_start(monmsg) + monmsg->mca_offset;
-               mon_read_debug(monmsg, monpriv);
-       }
        if (mon_check_mca(monmsg))
                goto reply;
 
@@ -531,7 +481,6 @@ static int __init mon_init(void)
                P_ERROR("failed to register with iucv driver\n");
                return rc;
        }
-       P_INFO("open, registered with IUCV\n");
 
        rc = segment_type(mon_dcss_name);
        if (rc < 0) {
@@ -555,13 +504,8 @@ static int __init mon_init(void)
        dcss_mkname(mon_dcss_name, &user_data_connect[8]);
 
        rc = misc_register(&mon_dev);
-       if (rc < 0 ) {
-               P_ERROR("misc_register failed, rc = %i\n", rc);
+       if (rc < 0 )
                goto out;
-       }
-       P_INFO("Loaded segment %s from %p to %p, size = %lu Byte\n",
-               mon_dcss_name, (void *) mon_dcss_start, (void *) mon_dcss_end,
-               mon_dcss_end - mon_dcss_start + 1);
        return 0;
 
 out:
index a86c053..4d71aa8 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/errno.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
@@ -179,10 +180,12 @@ static int monwrite_open(struct inode *inode, struct file *filp)
        monpriv = kzalloc(sizeof(struct mon_private), GFP_KERNEL);
        if (!monpriv)
                return -ENOMEM;
+       lock_kernel();
        INIT_LIST_HEAD(&monpriv->list);
        monpriv->hdr_to_read = sizeof(monpriv->hdr);
        mutex_init(&monpriv->thread_mutex);
        filp->private_data = monpriv;
+       unlock_kernel();
        return nonseekable_open(inode, filp);
 }
 
index 848ef7e..81a96e0 100644 (file)
@@ -153,19 +153,10 @@ struct raw3270_request __init *raw3270_request_alloc_bootmem(size_t size)
        struct raw3270_request *rq;
 
        rq = alloc_bootmem_low(sizeof(struct raw3270));
-       if (!rq)
-               return ERR_PTR(-ENOMEM);
-       memset(rq, 0, sizeof(struct raw3270_request));
 
        /* alloc output buffer. */
-       if (size > 0) {
+       if (size > 0)
                rq->buffer = alloc_bootmem_low(size);
-               if (!rq->buffer) {
-                       free_bootmem((unsigned long) rq,
-                                    sizeof(struct raw3270));
-                       return ERR_PTR(-ENOMEM);
-               }
-       }
        rq->size = size;
        INIT_LIST_HEAD(&rq->list);
 
@@ -372,17 +363,17 @@ raw3270_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
 
        if (IS_ERR(irb))
                rc = RAW3270_IO_RETRY;
-       else if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) {
+       else if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) {
                rq->rc = -EIO;
                rc = RAW3270_IO_DONE;
-       } else if (irb->scsw.dstat ==  (DEV_STAT_CHN_END | DEV_STAT_DEV_END |
-                                       DEV_STAT_UNIT_EXCEP)) {
+       } else if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END |
+                                          DEV_STAT_UNIT_EXCEP)) {
                /* Handle CE-DE-UE and subsequent UDE */
                set_bit(RAW3270_FLAGS_BUSY, &rp->flags);
                rc = RAW3270_IO_BUSY;
        } else if (test_bit(RAW3270_FLAGS_BUSY, &rp->flags)) {
                /* Wait for UDE if busy flag is set. */
-               if (irb->scsw.dstat & DEV_STAT_DEV_END) {
+               if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
                        clear_bit(RAW3270_FLAGS_BUSY, &rp->flags);
                        /* Got it, now retry. */
                        rc = RAW3270_IO_RETRY;
@@ -497,7 +488,7 @@ raw3270_init_irq(struct raw3270_view *view, struct raw3270_request *rq,
         * Unit-Check Processing:
         * Expect Command Reject or Intervention Required.
         */
-       if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
                /* Request finished abnormally. */
                if (irb->ecw[0] & SNS0_INTERVENTION_REQ) {
                        set_bit(RAW3270_FLAGS_BUSY, &view->dev->flags);
@@ -505,16 +496,16 @@ raw3270_init_irq(struct raw3270_view *view, struct raw3270_request *rq,
                }
        }
        if (rq) {
-               if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+               if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
                        if (irb->ecw[0] & SNS0_CMD_REJECT)
                                rq->rc = -EOPNOTSUPP;
                        else
                                rq->rc = -EIO;
                } else
                        /* Request finished normally. Copy residual count. */
-                       rq->rescnt = irb->scsw.count;
+                       rq->rescnt = irb->scsw.cmd.count;
        }
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                set_bit(RAW3270_FLAGS_ATTN, &view->dev->flags);
                wake_up(&raw3270_wait_queue);
        }
@@ -619,7 +610,6 @@ __raw3270_size_device_vm(struct raw3270 *rp)
                rp->cols = 132;
                break;
        default:
-               printk(KERN_WARNING "vrdccrmd is 0x%.8x\n", model);
                rc = -EOPNOTSUPP;
                break;
        }
index 2c7a1ee..3c8b25e 100644 (file)
@@ -506,6 +506,8 @@ sclp_state_change_cb(struct evbuf_header *evbuf)
        if (scbuf->validity_sclp_send_mask)
                sclp_send_mask = scbuf->sclp_send_mask;
        spin_unlock_irqrestore(&sclp_lock, flags);
+       if (scbuf->validity_sclp_active_facility_mask)
+               sclp_facilities = scbuf->sclp_active_facility_mask;
        sclp_dispatch_state_change();
 }
 
@@ -782,11 +784,9 @@ sclp_check_handler(__u16 code)
        /* Is this the interrupt we are waiting for? */
        if (finished_sccb == 0)
                return;
-       if (finished_sccb != (u32) (addr_t) sclp_init_sccb) {
-               printk(KERN_WARNING SCLP_HEADER "unsolicited interrupt "
-                      "for buffer at 0x%x\n", finished_sccb);
-               return;
-       }
+       if (finished_sccb != (u32) (addr_t) sclp_init_sccb)
+               panic("sclp: unsolicited interrupt for buffer at 0x%x\n",
+                     finished_sccb);
        spin_lock(&sclp_lock);
        if (sclp_running_state == sclp_running_state_running) {
                sclp_init_req.status = SCLP_REQ_DONE;
@@ -883,8 +883,6 @@ sclp_init(void)
        unsigned long flags;
        int rc;
 
-       if (!MACHINE_HAS_SCLP)
-               return -ENODEV;
        spin_lock_irqsave(&sclp_lock, flags);
        /* Check for previous or running initialization */
        if (sclp_init_state != sclp_init_state_uninitialized) {
index b5c2339..0c2b774 100644 (file)
@@ -11,6 +11,9 @@
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/mmzone.h>
+#include <linux/memory.h>
 #include <asm/chpid.h>
 #include <asm/sclp.h>
 #include "sclp.h"
@@ -43,6 +46,8 @@ static int __initdata early_read_info_sccb_valid;
 
 u64 sclp_facilities;
 static u8 sclp_fac84;
+static unsigned long long rzm;
+static unsigned long long rnmax;
 
 static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
 {
@@ -62,7 +67,7 @@ out:
        return rc;
 }
 
-void __init sclp_read_info_early(void)
+static void __init sclp_read_info_early(void)
 {
        int rc;
        int i;
@@ -92,34 +97,33 @@ void __init sclp_read_info_early(void)
 
 void __init sclp_facilities_detect(void)
 {
+       struct read_info_sccb *sccb;
+
+       sclp_read_info_early();
        if (!early_read_info_sccb_valid)
                return;
-       sclp_facilities = early_read_info_sccb.facilities;
-       sclp_fac84 = early_read_info_sccb.fac84;
+
+       sccb = &early_read_info_sccb;
+       sclp_facilities = sccb->facilities;
+       sclp_fac84 = sccb->fac84;
+       rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
+       rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
+       rzm <<= 20;
 }
 
-unsigned long long __init sclp_memory_detect(void)
+unsigned long long sclp_get_rnmax(void)
 {
-       unsigned long long memsize;
-       struct read_info_sccb *sccb;
+       return rnmax;
+}
 
-       if (!early_read_info_sccb_valid)
-               return 0;
-       sccb = &early_read_info_sccb;
-       if (sccb->rnsize)
-               memsize = sccb->rnsize << 20;
-       else
-               memsize = sccb->rnsize2 << 20;
-       if (sccb->rnmax)
-               memsize *= sccb->rnmax;
-       else
-               memsize *= sccb->rnmax2;
-       return memsize;
+unsigned long long sclp_get_rzm(void)
+{
+       return rzm;
 }
 
 /*
- * This function will be called after sclp_memory_detect(), which gets called
- * early from early.c code. Therefore the sccb should have valid contents.
+ * This function will be called after sclp_facilities_detect(), which gets
+ * called from early.c code. Therefore the sccb should have valid contents.
  */
 void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
 {
@@ -278,6 +282,305 @@ int sclp_cpu_deconfigure(u8 cpu)
        return do_cpu_configure(SCLP_CMDW_DECONFIGURE_CPU | cpu << 8);
 }
 
+#ifdef CONFIG_MEMORY_HOTPLUG
+
+static DEFINE_MUTEX(sclp_mem_mutex);
+static LIST_HEAD(sclp_mem_list);
+static u8 sclp_max_storage_id;
+static unsigned long sclp_storage_ids[256 / BITS_PER_LONG];
+
+struct memory_increment {
+       struct list_head list;
+       u16 rn;
+       int standby;
+       int usecount;
+};
+
+struct assign_storage_sccb {
+       struct sccb_header header;
+       u16 rn;
+} __packed;
+
+static unsigned long long rn2addr(u16 rn)
+{
+       return (unsigned long long) (rn - 1) * rzm;
+}
+
+static int do_assign_storage(sclp_cmdw_t cmd, u16 rn)
+{
+       struct assign_storage_sccb *sccb;
+       int rc;
+
+       sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sccb)
+               return -ENOMEM;
+       sccb->header.length = PAGE_SIZE;
+       sccb->rn = rn;
+       rc = do_sync_request(cmd, sccb);
+       if (rc)
+               goto out;
+       switch (sccb->header.response_code) {
+       case 0x0020:
+       case 0x0120:
+               break;
+       default:
+               rc = -EIO;
+               break;
+       }
+out:
+       free_page((unsigned long) sccb);
+       return rc;
+}
+
+static int sclp_assign_storage(u16 rn)
+{
+       return do_assign_storage(0x000d0001, rn);
+}
+
+static int sclp_unassign_storage(u16 rn)
+{
+       return do_assign_storage(0x000c0001, rn);
+}
+
+struct attach_storage_sccb {
+       struct sccb_header header;
+       u16 :16;
+       u16 assigned;
+       u32 :32;
+       u32 entries[0];
+} __packed;
+
+static int sclp_attach_storage(u8 id)
+{
+       struct attach_storage_sccb *sccb;
+       int rc;
+       int i;
+
+       sccb = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sccb)
+               return -ENOMEM;
+       sccb->header.length = PAGE_SIZE;
+       rc = do_sync_request(0x00080001 | id << 8, sccb);
+       if (rc)
+               goto out;
+       switch (sccb->header.response_code) {
+       case 0x0020:
+               set_bit(id, sclp_storage_ids);
+               for (i = 0; i < sccb->assigned; i++)
+                       sclp_unassign_storage(sccb->entries[i] >> 16);
+               break;
+       default:
+               rc = -EIO;
+               break;
+       }
+out:
+       free_page((unsigned long) sccb);
+       return rc;
+}
+
+static int sclp_mem_change_state(unsigned long start, unsigned long size,
+                                int online)
+{
+       struct memory_increment *incr;
+       unsigned long long istart;
+       int rc = 0;
+
+       list_for_each_entry(incr, &sclp_mem_list, list) {
+               istart = rn2addr(incr->rn);
+               if (start + size - 1 < istart)
+                       break;
+               if (start > istart + rzm - 1)
+                       continue;
+               if (online) {
+                       if (incr->usecount++)
+                               continue;
+                       /*
+                        * Don't break the loop if one assign fails. Loop may
+                        * be walked again on CANCEL and we can't save
+                        * information if state changed before or not.
+                        * So continue and increase usecount for all increments.
+                        */
+                       rc |= sclp_assign_storage(incr->rn);
+               } else {
+                       if (--incr->usecount)
+                               continue;
+                       sclp_unassign_storage(incr->rn);
+               }
+       }
+       return rc ? -EIO : 0;
+}
+
+static int sclp_mem_notifier(struct notifier_block *nb,
+                            unsigned long action, void *data)
+{
+       unsigned long start, size;
+       struct memory_notify *arg;
+       unsigned char id;
+       int rc = 0;
+
+       arg = data;
+       start = arg->start_pfn << PAGE_SHIFT;
+       size = arg->nr_pages << PAGE_SHIFT;
+       mutex_lock(&sclp_mem_mutex);
+       for (id = 0; id <= sclp_max_storage_id; id++)
+               if (!test_bit(id, sclp_storage_ids))
+                       sclp_attach_storage(id);
+       switch (action) {
+       case MEM_ONLINE:
+               break;
+       case MEM_GOING_ONLINE:
+               rc = sclp_mem_change_state(start, size, 1);
+               break;
+       case MEM_CANCEL_ONLINE:
+               sclp_mem_change_state(start, size, 0);
+               break;
+       default:
+               rc = -EINVAL;
+               break;
+       }
+       mutex_unlock(&sclp_mem_mutex);
+       return rc ? NOTIFY_BAD : NOTIFY_OK;
+}
+
+static struct notifier_block sclp_mem_nb = {
+       .notifier_call = sclp_mem_notifier,
+};
+
+static void __init add_memory_merged(u16 rn)
+{
+       static u16 first_rn, num;
+       unsigned long long start, size;
+
+       if (rn && first_rn && (first_rn + num == rn)) {
+               num++;
+               return;
+       }
+       if (!first_rn)
+               goto skip_add;
+       start = rn2addr(first_rn);
+       size = (unsigned long long ) num * rzm;
+       if (start >= VMEM_MAX_PHYS)
+               goto skip_add;
+       if (start + size > VMEM_MAX_PHYS)
+               size = VMEM_MAX_PHYS - start;
+       add_memory(0, start, size);
+skip_add:
+       first_rn = rn;
+       num = 1;
+}
+
+static void __init sclp_add_standby_memory(void)
+{
+       struct memory_increment *incr;
+
+       list_for_each_entry(incr, &sclp_mem_list, list)
+               if (incr->standby)
+                       add_memory_merged(incr->rn);
+       add_memory_merged(0);
+}
+
+static void __init insert_increment(u16 rn, int standby, int assigned)
+{
+       struct memory_increment *incr, *new_incr;
+       struct list_head *prev;
+       u16 last_rn;
+
+       new_incr = kzalloc(sizeof(*new_incr), GFP_KERNEL);
+       if (!new_incr)
+               return;
+       new_incr->rn = rn;
+       new_incr->standby = standby;
+       last_rn = 0;
+       prev = &sclp_mem_list;
+       list_for_each_entry(incr, &sclp_mem_list, list) {
+               if (assigned && incr->rn > rn)
+                       break;
+               if (!assigned && incr->rn - last_rn > 1)
+                       break;
+               last_rn = incr->rn;
+               prev = &incr->list;
+       }
+       if (!assigned)
+               new_incr->rn = last_rn + 1;
+       if (new_incr->rn > rnmax) {
+               kfree(new_incr);
+               return;
+       }
+       list_add(&new_incr->list, prev);
+}
+
+struct read_storage_sccb {
+       struct sccb_header header;
+       u16 max_id;
+       u16 assigned;
+       u16 standby;
+       u16 :16;
+       u32 entries[0];
+} __packed;
+
+static int __init sclp_detect_standby_memory(void)
+{
+       struct read_storage_sccb *sccb;
+       int i, id, assigned, rc;
+
+       if (!early_read_info_sccb_valid)
+               return 0;
+       if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
+               return 0;
+       rc = -ENOMEM;
+       sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
+       if (!sccb)
+               goto out;
+       assigned = 0;
+       for (id = 0; id <= sclp_max_storage_id; id++) {
+               memset(sccb, 0, PAGE_SIZE);
+               sccb->header.length = PAGE_SIZE;
+               rc = do_sync_request(0x00040001 | id << 8, sccb);
+               if (rc)
+                       goto out;
+               switch (sccb->header.response_code) {
+               case 0x0010:
+                       set_bit(id, sclp_storage_ids);
+                       for (i = 0; i < sccb->assigned; i++) {
+                               if (!sccb->entries[i])
+                                       continue;
+                               assigned++;
+                               insert_increment(sccb->entries[i] >> 16, 0, 1);
+                       }
+                       break;
+               case 0x0310:
+                       break;
+               case 0x0410:
+                       for (i = 0; i < sccb->assigned; i++) {
+                               if (!sccb->entries[i])
+                                       continue;
+                               assigned++;
+                               insert_increment(sccb->entries[i] >> 16, 1, 1);
+                       }
+                       break;
+               default:
+                       rc = -EIO;
+                       break;
+               }
+               if (!rc)
+                       sclp_max_storage_id = sccb->max_id;
+       }
+       if (rc || list_empty(&sclp_mem_list))
+               goto out;
+       for (i = 1; i <= rnmax - assigned; i++)
+               insert_increment(0, 1, 0);
+       rc = register_memory_notifier(&sclp_mem_nb);
+       if (rc)
+               goto out;
+       sclp_add_standby_memory();
+out:
+       free_page((unsigned long) sccb);
+       return rc;
+}
+__initcall(sclp_detect_standby_memory);
+
+#endif /* CONFIG_MEMORY_HOTPLUG */
+
 /*
  * Channel path configuration related functions.
  */
index ead1043..7e619c5 100644 (file)
 #include <linux/timer.h>
 #include <linux/jiffies.h>
 #include <linux/bootmem.h>
+#include <linux/termios.h>
 #include <linux/err.h>
 
 #include "sclp.h"
 #include "sclp_rw.h"
 #include "sclp_tty.h"
 
-#define SCLP_CON_PRINT_HEADER "sclp console driver: "
-
 #define sclp_console_major 4           /* TTYAUX_MAJOR */
 #define sclp_console_minor 64
 #define sclp_console_name  "ttyS"
@@ -222,8 +221,6 @@ sclp_console_init(void)
        INIT_LIST_HEAD(&sclp_con_pages);
        for (i = 0; i < MAX_CONSOLE_PAGES; i++) {
                page = alloc_bootmem_low_pages(PAGE_SIZE);
-               if (page == NULL)
-                       return -ENOMEM;
                list_add_tail((struct list_head *) page, &sclp_con_pages);
        }
        INIT_LIST_HEAD(&sclp_con_outqueue);
index ad05a87..fff4ff4 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/cpu.h>
+#include <linux/kthread.h>
 #include <linux/sysdev.h>
 #include <linux/workqueue.h>
 #include <asm/smp.h>
@@ -40,9 +41,19 @@ static void sclp_cpu_capability_notify(struct work_struct *work)
        put_online_cpus();
 }
 
-static void __ref sclp_cpu_change_notify(struct work_struct *work)
+static int sclp_cpu_kthread(void *data)
 {
        smp_rescan_cpus();
+       return 0;
+}
+
+static void __ref sclp_cpu_change_notify(struct work_struct *work)
+{
+       /* Can't call smp_rescan_cpus() from  workqueue context since it may
+        * deadlock in case of cpu hotplug. So we have to create a kernel
+        * thread in order to call it.
+        */
+       kthread_run(sclp_cpu_kthread, NULL, "cpu_rescan");
 }
 
 static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
@@ -74,10 +85,8 @@ static int __init sclp_conf_init(void)
        INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
 
        rc = sclp_register(&sclp_conf_register);
-       if (rc) {
-               printk(KERN_ERR TAG "failed to register (%d).\n", rc);
+       if (rc)
                return rc;
-       }
 
        if (!(sclp_conf_register.sclp_send_mask & EVTYP_CONFMGMDATA_MASK)) {
                printk(KERN_WARNING TAG "no configuration management.\n");
index 9f37456..d887bd2 100644 (file)
@@ -27,6 +27,8 @@
 #define CPI_LENGTH_NAME 8
 #define CPI_LENGTH_LEVEL 16
 
+static DEFINE_MUTEX(sclp_cpi_mutex);
+
 struct cpi_evbuf {
        struct evbuf_header header;
        u8      id_format;
@@ -124,21 +126,15 @@ static int cpi_req(void)
        int response;
 
        rc = sclp_register(&sclp_cpi_event);
-       if (rc) {
-               printk(KERN_WARNING "cpi: could not register "
-                       "to hardware console.\n");
+       if (rc)
                goto out;
-       }
        if (!(sclp_cpi_event.sclp_receive_mask & EVTYP_CTLPROGIDENT_MASK)) {
-               printk(KERN_WARNING "cpi: no control program "
-                       "identification support\n");
                rc = -EOPNOTSUPP;
                goto out_unregister;
        }
 
        req = cpi_prepare_req();
        if (IS_ERR(req)) {
-               printk(KERN_WARNING "cpi: could not allocate request\n");
                rc = PTR_ERR(req);
                goto out_unregister;
        }
@@ -148,10 +144,8 @@ static int cpi_req(void)
 
        /* Add request to sclp queue */
        rc = sclp_add_request(req);
-       if (rc) {
-               printk(KERN_WARNING "cpi: could not start request\n");
+       if (rc)
                goto out_free_req;
-       }
 
        wait_for_completion(&completion);
 
@@ -223,7 +217,12 @@ static void set_string(char *attr, const char *value)
 static ssize_t system_name_show(struct kobject *kobj,
                                struct kobj_attribute *attr, char *page)
 {
-       return snprintf(page, PAGE_SIZE, "%s\n", system_name);
+       int rc;
+
+       mutex_lock(&sclp_cpi_mutex);
+       rc = snprintf(page, PAGE_SIZE, "%s\n", system_name);
+       mutex_unlock(&sclp_cpi_mutex);
+       return rc;
 }
 
 static ssize_t system_name_store(struct kobject *kobj,
@@ -237,7 +236,9 @@ static ssize_t system_name_store(struct kobject *kobj,
        if (rc)
                return rc;
 
+       mutex_lock(&sclp_cpi_mutex);
        set_string(system_name, buf);
+       mutex_unlock(&sclp_cpi_mutex);
 
        return len;
 }
@@ -248,7 +249,12 @@ static struct kobj_attribute system_name_attr =
 static ssize_t sysplex_name_show(struct kobject *kobj,
                                 struct kobj_attribute *attr, char *page)
 {
-       return snprintf(page, PAGE_SIZE, "%s\n", sysplex_name);
+       int rc;
+
+       mutex_lock(&sclp_cpi_mutex);
+       rc = snprintf(page, PAGE_SIZE, "%s\n", sysplex_name);
+       mutex_unlock(&sclp_cpi_mutex);
+       return rc;
 }
 
 static ssize_t sysplex_name_store(struct kobject *kobj,
@@ -262,7 +268,9 @@ static ssize_t sysplex_name_store(struct kobject *kobj,
        if (rc)
                return rc;
 
+       mutex_lock(&sclp_cpi_mutex);
        set_string(sysplex_name, buf);
+       mutex_unlock(&sclp_cpi_mutex);
 
        return len;
 }
@@ -273,7 +281,12 @@ static struct kobj_attribute sysplex_name_attr =
 static ssize_t system_type_show(struct kobject *kobj,
                                struct kobj_attribute *attr, char *page)
 {
-       return snprintf(page, PAGE_SIZE, "%s\n", system_type);
+       int rc;
+
+       mutex_lock(&sclp_cpi_mutex);
+       rc = snprintf(page, PAGE_SIZE, "%s\n", system_type);
+       mutex_unlock(&sclp_cpi_mutex);
+       return rc;
 }
 
 static ssize_t system_type_store(struct kobject *kobj,
@@ -287,7 +300,9 @@ static ssize_t system_type_store(struct kobject *kobj,
        if (rc)
                return rc;
 
+       mutex_lock(&sclp_cpi_mutex);
        set_string(system_type, buf);
+       mutex_unlock(&sclp_cpi_mutex);
 
        return len;
 }
@@ -298,8 +313,11 @@ static struct kobj_attribute system_type_attr =
 static ssize_t system_level_show(struct kobject *kobj,
                                 struct kobj_attribute *attr, char *page)
 {
-       unsigned long long level = system_level;
+       unsigned long long level;
 
+       mutex_lock(&sclp_cpi_mutex);
+       level = system_level;
+       mutex_unlock(&sclp_cpi_mutex);
        return snprintf(page, PAGE_SIZE, "%#018llx\n", level);
 }
 
@@ -320,8 +338,9 @@ static ssize_t system_level_store(struct kobject *kobj,
        if (*endp)
                return -EINVAL;
 
+       mutex_lock(&sclp_cpi_mutex);
        system_level = level;
-
+       mutex_unlock(&sclp_cpi_mutex);
        return len;
 }
 
@@ -334,7 +353,9 @@ static ssize_t set_store(struct kobject *kobj,
 {
        int rc;
 
+       mutex_lock(&sclp_cpi_mutex);
        rc = cpi_req();
+       mutex_unlock(&sclp_cpi_mutex);
        if (rc)
                return rc;
 
@@ -373,12 +394,16 @@ int sclp_cpi_set_data(const char *system, const char *sysplex, const char *type,
        if (rc)
                return rc;
 
+       mutex_lock(&sclp_cpi_mutex);
        set_string(system_name, system);
        set_string(sysplex_name, sysplex);
        set_string(system_type, type);
        system_level = level;
 
-       return cpi_req();
+       rc = cpi_req();
+       mutex_unlock(&sclp_cpi_mutex);
+
+       return rc;
 }
 EXPORT_SYMBOL(sclp_cpi_set_data);
 
index 45ff25e..84c191c 100644 (file)
@@ -51,13 +51,7 @@ static struct sclp_register sclp_quiesce_event = {
 static int __init
 sclp_quiesce_init(void)
 {
-       int rc;
-
-       rc = sclp_register(&sclp_quiesce_event);
-       if (rc)
-               printk(KERN_WARNING "sclp: could not register quiesce handler "
-                      "(rc=%d)\n", rc);
-       return rc;
+       return sclp_register(&sclp_quiesce_event);
 }
 
 module_init(sclp_quiesce_init);
index da09781..710af42 100644 (file)
@@ -19,8 +19,6 @@
 #include "sclp.h"
 #include "sclp_rw.h"
 
-#define SCLP_RW_PRINT_HEADER "sclp low level driver: "
-
 /*
  * The room for the SCCB (only for writing) is not equal to a pages size
  * (as it is specified as the maximum size in the SCLP documentation)
index 1c06497..8b85485 100644 (file)
@@ -239,10 +239,8 @@ int __init sclp_sdias_init(void)
        debug_register_view(sdias_dbf, &debug_sprintf_view);
        debug_set_level(sdias_dbf, 6);
        rc = sclp_register(&sclp_sdias_register);
-       if (rc) {
-               ERROR_MSG("sclp register failed\n");
+       if (rc)
                return rc;
-       }
        init_waitqueue_head(&sdias_wq);
        TRACE("init done\n");
        return 0;
index 40b1152..434ba04 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/tty.h>
 #include <linux/tty_driver.h>
 #include <linux/tty_flip.h>
-#include <linux/wait.h>
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/init.h>
@@ -25,8 +24,6 @@
 #include "sclp_rw.h"
 #include "sclp_tty.h"
 
-#define SCLP_TTY_PRINT_HEADER "sclp tty driver: "
-
 /*
  * size of a buffer that collects single characters coming in
  * via sclp_tty_put_char()
@@ -50,8 +47,6 @@ static int sclp_tty_buffer_count;
 static struct sclp_buffer *sclp_ttybuf;
 /* Timer for delayed output of console messages. */
 static struct timer_list sclp_tty_timer;
-/* Waitqueue to wait for buffers to get empty. */
-static wait_queue_head_t sclp_tty_waitq;
 
 static struct tty_struct *sclp_tty;
 static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE];
@@ -59,19 +54,11 @@ static unsigned short int sclp_tty_chars_count;
 
 struct tty_driver *sclp_tty_driver;
 
-static struct sclp_ioctls sclp_ioctls;
-static struct sclp_ioctls sclp_ioctls_init =
-{
-       8,                      /* 1 hor. tab. = 8 spaces */
-       0,                      /* no echo of input by this driver */
-       80,                     /* 80 characters/line */
-       1,                      /* write after 1/10 s without final new line */
-       MAX_KMEM_PAGES,         /* quick fix: avoid __alloc_pages */
-       MAX_KMEM_PAGES,         /* take 32/64 pages from kernel memory, */
-       0,                      /* do not convert to lower case */
-       0x6c                    /* to seprate upper and lower case */
-                               /* ('%' in EBCDIC) */
-};
+static int sclp_tty_tolower;
+static int sclp_tty_columns = 80;
+
+#define SPACES_PER_TAB 8
+#define CASE_DELIMITER 0x6c /* to separate upper and lower case (% in EBCDIC) */
 
 /* This routine is called whenever we try to open a SCLP terminal. */
 static int
@@ -92,136 +79,6 @@ sclp_tty_close(struct tty_struct *tty, struct file *filp)
        sclp_tty = NULL;
 }
 
-/* execute commands to control the i/o behaviour of the SCLP tty at runtime */
-static int
-sclp_tty_ioctl(struct tty_struct *tty, struct file * file,
-              unsigned int cmd, unsigned long arg)
-{
-       unsigned long flags;
-       unsigned int obuf;
-       int check;
-       int rc;
-
-       if (tty->flags & (1 << TTY_IO_ERROR))
-               return -EIO;
-       rc = 0;
-       check = 0;
-       switch (cmd) {
-       case TIOCSCLPSHTAB:
-               /* set width of horizontal tab  */
-               if (get_user(sclp_ioctls.htab, (unsigned short __user *) arg))
-                       rc = -EFAULT;
-               else
-                       check = 1;
-               break;
-       case TIOCSCLPGHTAB:
-               /* get width of horizontal tab  */
-               if (put_user(sclp_ioctls.htab, (unsigned short __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSECHO:
-               /* enable/disable echo of input */
-               if (get_user(sclp_ioctls.echo, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGECHO:
-               /* Is echo of input enabled ?  */
-               if (put_user(sclp_ioctls.echo, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSCOLS:
-               /* set number of columns for output  */
-               if (get_user(sclp_ioctls.columns, (unsigned short __user *) arg))
-                       rc = -EFAULT;
-               else
-                       check = 1;
-               break;
-       case TIOCSCLPGCOLS:
-               /* get number of columns for output  */
-               if (put_user(sclp_ioctls.columns, (unsigned short __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSNL:
-               /* enable/disable writing without final new line character  */
-               if (get_user(sclp_ioctls.final_nl, (signed char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGNL:
-               /* Is writing without final new line character enabled ?  */
-               if (put_user(sclp_ioctls.final_nl, (signed char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSOBUF:
-               /*
-                * set the maximum buffers size for output, will be rounded
-                * up to next 4kB boundary and stored as number of SCCBs
-                * (4kB Buffers) limitation: 256 x 4kB
-                */
-               if (get_user(obuf, (unsigned int __user *) arg) == 0) {
-                       if (obuf & 0xFFF)
-                               sclp_ioctls.max_sccb = (obuf >> 12) + 1;
-                       else
-                               sclp_ioctls.max_sccb = (obuf >> 12);
-               } else
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGOBUF:
-               /* get the maximum buffers size for output  */
-               obuf = sclp_ioctls.max_sccb << 12;
-               if (put_user(obuf, (unsigned int __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGKBUF:
-               /* get the number of buffers got from kernel at startup */
-               if (put_user(sclp_ioctls.kmem_sccb, (unsigned short __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSCASE:
-               /* enable/disable conversion from upper to lower case */
-               if (get_user(sclp_ioctls.tolower, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGCASE:
-               /* Is conversion from upper to lower case of input enabled? */
-               if (put_user(sclp_ioctls.tolower, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSDELIM:
-               /*
-                * set special character used for separating upper and
-                * lower case, 0x00 disables this feature
-                */
-               if (get_user(sclp_ioctls.delim, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPGDELIM:
-               /*
-                * get special character used for separating upper and
-                * lower case, 0x00 disables this feature
-                */
-               if (put_user(sclp_ioctls.delim, (unsigned char __user *) arg))
-                       rc = -EFAULT;
-               break;
-       case TIOCSCLPSINIT:
-               /* set initial (default) sclp ioctls  */
-               sclp_ioctls = sclp_ioctls_init;
-               check = 1;
-               break;
-       default:
-               rc = -ENOIOCTLCMD;
-               break;
-       }
-       if (check) {
-               spin_lock_irqsave(&sclp_tty_lock, flags);
-               if (sclp_ttybuf != NULL) {
-                       sclp_set_htab(sclp_ttybuf, sclp_ioctls.htab);
-                       sclp_set_columns(sclp_ttybuf, sclp_ioctls.columns);
-               }
-               spin_unlock_irqrestore(&sclp_tty_lock, flags);
-       }
-       return rc;
-}
-
 /*
  * This routine returns the numbers of characters the tty driver
  * will accept for queuing to be written.  This number is subject
@@ -268,7 +125,6 @@ sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
                                            struct sclp_buffer, list);
                spin_unlock_irqrestore(&sclp_tty_lock, flags);
        } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback));
-       wake_up(&sclp_tty_waitq);
        /* check if the tty needs a wake up call */
        if (sclp_tty != NULL) {
                tty_wakeup(sclp_tty);
@@ -316,37 +172,37 @@ sclp_tty_timeout(unsigned long data)
 /*
  * Write a string to the sclp tty.
  */
-static void
-sclp_tty_write_string(const unsigned char *str, int count)
+static int sclp_tty_write_string(const unsigned char *str, int count, int may_fail)
 {
        unsigned long flags;
        void *page;
        int written;
+       int overall_written;
        struct sclp_buffer *buf;
 
        if (count <= 0)
-               return;
+               return 0;
+       overall_written = 0;
        spin_lock_irqsave(&sclp_tty_lock, flags);
        do {
                /* Create a sclp output buffer if none exists yet */
                if (sclp_ttybuf == NULL) {
                        while (list_empty(&sclp_tty_pages)) {
                                spin_unlock_irqrestore(&sclp_tty_lock, flags);
-                               if (in_interrupt())
-                                       sclp_sync_wait();
+                               if (may_fail)
+                                       goto out;
                                else
-                                       wait_event(sclp_tty_waitq,
-                                               !list_empty(&sclp_tty_pages));
+                                       sclp_sync_wait();
                                spin_lock_irqsave(&sclp_tty_lock, flags);
                        }
                        page = sclp_tty_pages.next;
                        list_del((struct list_head *) page);
-                       sclp_ttybuf = sclp_make_buffer(page,
-                                                      sclp_ioctls.columns,
-                                                      sclp_ioctls.htab);
+                       sclp_ttybuf = sclp_make_buffer(page, sclp_tty_columns,
+                                                      SPACES_PER_TAB);
                }
                /* try to write the string to the current output buffer */
                written = sclp_write(sclp_ttybuf, str, count);
+               overall_written += written;
                if (written == count)
                        break;
                /*
@@ -363,27 +219,17 @@ sclp_tty_write_string(const unsigned char *str, int count)
                count -= written;
        } while (count > 0);
        /* Setup timer to output current console buffer after 1/10 second */
-       if (sclp_ioctls.final_nl) {
-               if (sclp_ttybuf != NULL &&
-                   sclp_chars_in_buffer(sclp_ttybuf) != 0 &&
-                   !timer_pending(&sclp_tty_timer)) {
-                       init_timer(&sclp_tty_timer);
-                       sclp_tty_timer.function = sclp_tty_timeout;
-                       sclp_tty_timer.data = 0UL;
-                       sclp_tty_timer.expires = jiffies + HZ/10;
-                       add_timer(&sclp_tty_timer);
-               }
-       } else {
-               if (sclp_ttybuf != NULL &&
-                   sclp_chars_in_buffer(sclp_ttybuf) != 0) {
-                       buf = sclp_ttybuf;
-                       sclp_ttybuf = NULL;
-                       spin_unlock_irqrestore(&sclp_tty_lock, flags);
-                       __sclp_ttybuf_emit(buf);
-                       spin_lock_irqsave(&sclp_tty_lock, flags);
-               }
+       if (sclp_ttybuf && sclp_chars_in_buffer(sclp_ttybuf) &&
+           !timer_pending(&sclp_tty_timer)) {
+               init_timer(&sclp_tty_timer);
+               sclp_tty_timer.function = sclp_tty_timeout;
+               sclp_tty_timer.data = 0UL;
+               sclp_tty_timer.expires = jiffies + HZ/10;
+               add_timer(&sclp_tty_timer);
        }
        spin_unlock_irqrestore(&sclp_tty_lock, flags);
+out:
+       return overall_written;
 }
 
 /*
@@ -395,11 +241,10 @@ static int
 sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
        if (sclp_tty_chars_count > 0) {
-               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count);
+               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
                sclp_tty_chars_count = 0;
        }
-       sclp_tty_write_string(buf, count);
-       return count;
+       return sclp_tty_write_string(buf, count, 1);
 }
 
 /*
@@ -417,9 +262,10 @@ sclp_tty_put_char(struct tty_struct *tty, unsigned char ch)
 {
        sclp_tty_chars[sclp_tty_chars_count++] = ch;
        if (ch == '\n' || sclp_tty_chars_count >= SCLP_TTY_BUF_SIZE) {
-               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count);
+               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
                sclp_tty_chars_count = 0;
-       } return 1;
+       }
+       return 1;
 }
 
 /*
@@ -430,7 +276,7 @@ static void
 sclp_tty_flush_chars(struct tty_struct *tty)
 {
        if (sclp_tty_chars_count > 0) {
-               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count);
+               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
                sclp_tty_chars_count = 0;
        }
 }
@@ -469,7 +315,7 @@ static void
 sclp_tty_flush_buffer(struct tty_struct *tty)
 {
        if (sclp_tty_chars_count > 0) {
-               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count);
+               sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
                sclp_tty_chars_count = 0;
        }
 }
@@ -517,9 +363,7 @@ sclp_tty_input(unsigned char* buf, unsigned int count)
  * modifiy original string,
  * returns length of resulting string
  */
-static int
-sclp_switch_cases(unsigned char *buf, int count,
-                 unsigned char delim, int tolower)
+static int sclp_switch_cases(unsigned char *buf, int count)
 {
        unsigned char *ip, *op;
        int toggle;
@@ -529,9 +373,9 @@ sclp_switch_cases(unsigned char *buf, int count,
        ip = op = buf;
        while (count-- > 0) {
                /* compare with special character */
-               if (*ip == delim) {
+               if (*ip == CASE_DELIMITER) {
                        /* followed by another special character? */
-                       if (count && ip[1] == delim) {
+                       if (count && ip[1] == CASE_DELIMITER) {
                                /*
                                 * ... then put a single copy of the special
                                 * character to the output string
@@ -550,7 +394,7 @@ sclp_switch_cases(unsigned char *buf, int count,
                        /* not the special character */
                        if (toggle)
                                /* but case switching is on */
-                               if (tolower)
+                               if (sclp_tty_tolower)
                                        /* switch to uppercase */
                                        *op++ = _ebc_toupper[(int) *ip++];
                                else
@@ -570,30 +414,12 @@ sclp_get_input(unsigned char *start, unsigned char *end)
        int count;
 
        count = end - start;
-       /*
-        * if set in ioctl convert EBCDIC to lower case
-        * (modify original input in SCCB)
-        */
-       if (sclp_ioctls.tolower)
+       if (sclp_tty_tolower)
                EBC_TOLOWER(start, count);
-
-       /*
-        * if set in ioctl find out characters in lower or upper case
-        * (depends on current case) separated by a special character,
-        * works on EBCDIC
-        */
-       if (sclp_ioctls.delim)
-               count = sclp_switch_cases(start, count,
-                                         sclp_ioctls.delim,
-                                         sclp_ioctls.tolower);
-
+       count = sclp_switch_cases(start, count);
        /* convert EBCDIC to ASCII (modify original input in SCCB) */
        sclp_ebcasc_str(start, count);
 
-       /* if set in ioctl write operators input to console  */
-       if (sclp_ioctls.echo)
-               sclp_tty_write(sclp_tty, start, count);
-
        /* transfer input to high level driver */
        sclp_tty_input(start, count);
 }
@@ -717,7 +543,6 @@ static const struct tty_operations sclp_ops = {
        .write_room = sclp_tty_write_room,
        .chars_in_buffer = sclp_tty_chars_in_buffer,
        .flush_buffer = sclp_tty_flush_buffer,
-       .ioctl = sclp_tty_ioctl,
 };
 
 static int __init
@@ -736,9 +561,6 @@ sclp_tty_init(void)
 
        rc = sclp_rw_init();
        if (rc) {
-               printk(KERN_ERR SCLP_TTY_PRINT_HEADER
-                      "could not register tty - "
-                      "sclp_rw_init returned %d\n", rc);
                put_tty_driver(driver);
                return rc;
        }
@@ -754,7 +576,6 @@ sclp_tty_init(void)
        }
        INIT_LIST_HEAD(&sclp_tty_outqueue);
        spin_lock_init(&sclp_tty_lock);
-       init_waitqueue_head(&sclp_tty_waitq);
        init_timer(&sclp_tty_timer);
        sclp_ttybuf = NULL;
        sclp_tty_buffer_count = 0;
@@ -763,11 +584,10 @@ sclp_tty_init(void)
                 * save 4 characters for the CPU number
                 * written at start of each line by VM/CP
                 */
-               sclp_ioctls_init.columns = 76;
+               sclp_tty_columns = 76;
                /* case input lines to lowercase */
-               sclp_ioctls_init.tolower = 1;
+               sclp_tty_tolower = 1;
        }
-       sclp_ioctls = sclp_ioctls_init;
        sclp_tty_chars_count = 0;
        sclp_tty = NULL;
 
@@ -792,9 +612,6 @@ sclp_tty_init(void)
        tty_set_operations(driver, &sclp_ops);
        rc = tty_register_driver(driver);
        if (rc) {
-               printk(KERN_ERR SCLP_TTY_PRINT_HEADER
-                      "could not register tty - "
-                      "tty_register_driver returned %d\n", rc);
                put_tty_driver(driver);
                return rc;
        }
index 0ce2c1f..4b965b2 100644 (file)
 #ifndef __SCLP_TTY_H__
 #define __SCLP_TTY_H__
 
-#include <linux/ioctl.h>
-#include <linux/termios.h>
 #include <linux/tty_driver.h>
 
-/* This is the type of data structures storing sclp ioctl setting. */
-struct sclp_ioctls {
-       unsigned short htab;
-       unsigned char echo;
-       unsigned short columns;
-       unsigned char final_nl;
-       unsigned short max_sccb;
-       unsigned short kmem_sccb;       /* can't be modified at run time */
-       unsigned char tolower;
-       unsigned char delim;
-};
-
-/* must be unique, FIXME: must be added in Documentation/ioctl_number.txt */
-#define SCLP_IOCTL_LETTER 'B'
-
-/* set width of horizontal tabulator */
-#define TIOCSCLPSHTAB  _IOW(SCLP_IOCTL_LETTER, 0, unsigned short)
-/* enable/disable echo of input (independent from line discipline) */
-#define TIOCSCLPSECHO  _IOW(SCLP_IOCTL_LETTER, 1, unsigned char)
-/* set number of colums for output */
-#define TIOCSCLPSCOLS  _IOW(SCLP_IOCTL_LETTER, 2, unsigned short)
-/* enable/disable writing without final new line character */
-#define TIOCSCLPSNL    _IOW(SCLP_IOCTL_LETTER, 4, signed char)
-/* set the maximum buffers size for output, rounded up to next 4kB boundary */
-#define TIOCSCLPSOBUF  _IOW(SCLP_IOCTL_LETTER, 5, unsigned short)
-/* set initial (default) sclp ioctls */
-#define TIOCSCLPSINIT  _IO(SCLP_IOCTL_LETTER, 6)
-/* enable/disable conversion from upper to lower case of input */
-#define TIOCSCLPSCASE  _IOW(SCLP_IOCTL_LETTER, 7, unsigned char)
-/* set special character used for separating upper and lower case, */
-/* 0x00 disables this feature */
-#define TIOCSCLPSDELIM _IOW(SCLP_IOCTL_LETTER, 9, unsigned char)
-
-/* get width of horizontal tabulator */
-#define TIOCSCLPGHTAB  _IOR(SCLP_IOCTL_LETTER, 10, unsigned short)
-/* Is echo of input enabled ? (independent from line discipline) */
-#define TIOCSCLPGECHO  _IOR(SCLP_IOCTL_LETTER, 11, unsigned char)
-/* get number of colums for output */
-#define TIOCSCLPGCOLS  _IOR(SCLP_IOCTL_LETTER, 12, unsigned short)
-/* Is writing without final new line character enabled ? */
-#define TIOCSCLPGNL    _IOR(SCLP_IOCTL_LETTER, 14, signed char)
-/* get the maximum buffers size for output */
-#define TIOCSCLPGOBUF  _IOR(SCLP_IOCTL_LETTER, 15, unsigned short)
-/* Is conversion from upper to lower case of input enabled ? */
-#define TIOCSCLPGCASE  _IOR(SCLP_IOCTL_LETTER, 17, unsigned char)
-/* get special character used for separating upper and lower case, */
-/* 0x00 disables this feature */
-#define TIOCSCLPGDELIM _IOR(SCLP_IOCTL_LETTER, 19, unsigned char)
-/* get the number of buffers/pages got from kernel at startup */
-#define TIOCSCLPGKBUF  _IOR(SCLP_IOCTL_LETTER, 20, unsigned short)
-
 extern struct tty_driver *sclp_tty_driver;
 
 #endif /* __SCLP_TTY_H__ */
index 3e577f6..ad51738 100644 (file)
@@ -27,7 +27,6 @@
 #include <asm/uaccess.h>
 #include "sclp.h"
 
-#define SCLP_VT220_PRINT_HEADER        "sclp vt220 tty driver: "
 #define SCLP_VT220_MAJOR               TTY_MAJOR
 #define SCLP_VT220_MINOR               65
 #define SCLP_VT220_DRIVER_NAME         "sclp_vt220"
@@ -82,8 +81,8 @@ static struct sclp_vt220_request *sclp_vt220_current_request;
 /* Number of characters in current request buffer */
 static int sclp_vt220_buffered_chars;
 
-/* Flag indicating whether this driver has already been initialized */
-static int sclp_vt220_initialized = 0;
+/* Counter controlling core driver initialization. */
+static int __initdata sclp_vt220_init_count;
 
 /* Flag indicating that sclp_vt220_current_request should really
  * have been already queued but wasn't because the SCLP was processing
@@ -609,10 +608,8 @@ sclp_vt220_flush_buffer(struct tty_struct *tty)
        sclp_vt220_emit_current();
 }
 
-/*
- * Initialize all relevant components and register driver with system.
- */
-static void __init __sclp_vt220_cleanup(void)
+/* Release allocated pages. */
+static void __init __sclp_vt220_free_pages(void)
 {
        struct list_head *page, *p;
 
@@ -623,21 +620,30 @@ static void __init __sclp_vt220_cleanup(void)
                else
                        free_bootmem((unsigned long) page, PAGE_SIZE);
        }
-       if (!list_empty(&sclp_vt220_register.list))
-               sclp_unregister(&sclp_vt220_register);
-       sclp_vt220_initialized = 0;
 }
 
-static int __init __sclp_vt220_init(void)
+/* Release memory and unregister from sclp core. Controlled by init counting -
+ * only the last invoker will actually perform these actions. */
+static void __init __sclp_vt220_cleanup(void)
+{
+       sclp_vt220_init_count--;
+       if (sclp_vt220_init_count != 0)
+               return;
+       sclp_unregister(&sclp_vt220_register);
+       __sclp_vt220_free_pages();
+}
+
+/* Allocate buffer pages and register with sclp core. Controlled by init
+ * counting - only the first invoker will actually perform these actions. */
+static int __init __sclp_vt220_init(int num_pages)
 {
        void *page;
        int i;
-       int num_pages;
        int rc;
 
-       if (sclp_vt220_initialized)
+       sclp_vt220_init_count++;
+       if (sclp_vt220_init_count != 1)
                return 0;
-       sclp_vt220_initialized = 1;
        spin_lock_init(&sclp_vt220_lock);
        INIT_LIST_HEAD(&sclp_vt220_empty);
        INIT_LIST_HEAD(&sclp_vt220_outqueue);
@@ -649,24 +655,22 @@ static int __init __sclp_vt220_init(void)
        sclp_vt220_flush_later = 0;
 
        /* Allocate pages for output buffering */
-       num_pages = slab_is_available() ? MAX_KMEM_PAGES : MAX_CONSOLE_PAGES;
        for (i = 0; i < num_pages; i++) {
                if (slab_is_available())
                        page = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
                else
                        page = alloc_bootmem_low_pages(PAGE_SIZE);
                if (!page) {
-                       __sclp_vt220_cleanup();
-                       return -ENOMEM;
+                       rc = -ENOMEM;
+                       goto out;
                }
                list_add_tail((struct list_head *) page, &sclp_vt220_empty);
        }
        rc = sclp_register(&sclp_vt220_register);
+out:
        if (rc) {
-               printk(KERN_ERR SCLP_VT220_PRINT_HEADER
-                      "could not register vt220 - "
-                      "sclp_register returned %d\n", rc);
-               __sclp_vt220_cleanup();
+               __sclp_vt220_free_pages();
+               sclp_vt220_init_count--;
        }
        return rc;
 }
@@ -689,15 +693,13 @@ static int __init sclp_vt220_tty_init(void)
 {
        struct tty_driver *driver;
        int rc;
-       int cleanup;
 
        /* Note: we're not testing for CONSOLE_IS_SCLP here to preserve
         * symmetry between VM and LPAR systems regarding ttyS1. */
        driver = alloc_tty_driver(1);
        if (!driver)
                return -ENOMEM;
-       cleanup = !sclp_vt220_initialized;
-       rc = __sclp_vt220_init();
+       rc = __sclp_vt220_init(MAX_KMEM_PAGES);
        if (rc)
                goto out_driver;
 
@@ -713,18 +715,13 @@ static int __init sclp_vt220_tty_init(void)
        tty_set_operations(driver, &sclp_vt220_ops);
 
        rc = tty_register_driver(driver);
-       if (rc) {
-               printk(KERN_ERR SCLP_VT220_PRINT_HEADER
-                      "could not register tty - "
-                      "tty_register_driver returned %d\n", rc);
+       if (rc)
                goto out_init;
-       }
        sclp_vt220_driver = driver;
        return 0;
 
 out_init:
-       if (cleanup)
-               __sclp_vt220_cleanup();
+       __sclp_vt220_cleanup();
 out_driver:
        put_tty_driver(driver);
        return rc;
@@ -773,10 +770,9 @@ sclp_vt220_con_init(void)
 {
        int rc;
 
-       INIT_LIST_HEAD(&sclp_vt220_register.list);
        if (!CONSOLE_IS_SCLP)
                return 0;
-       rc = __sclp_vt220_init();
+       rc = __sclp_vt220_init(MAX_CONSOLE_PAGES);
        if (rc)
                return rc;
        /* Attach linux console */
index 874adf3..22ca343 100644 (file)
@@ -196,7 +196,7 @@ tape_34xx_erp_retry(struct tape_request *request)
 static int
 tape_34xx_unsolicited_irq(struct tape_device *device, struct irb *irb)
 {
-       if (irb->scsw.dstat == 0x85 /* READY */) {
+       if (irb->scsw.cmd.dstat == 0x85) { /* READY */
                /* A medium was inserted in the drive. */
                DBF_EVENT(6, "xuud med\n");
                tape_34xx_delete_sbid_from(device, 0);
@@ -844,22 +844,22 @@ tape_34xx_irq(struct tape_device *device, struct tape_request *request,
        if (request == NULL)
                return tape_34xx_unsolicited_irq(device, irb);
 
-       if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
-           (irb->scsw.dstat & DEV_STAT_DEV_END) &&
+       if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
+           (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
            (request->op == TO_WRI)) {
                /* Write at end of volume */
                PRINT_INFO("End of volume\n"); /* XXX */
                return tape_34xx_erp_failed(request, -ENOSPC);
        }
 
-       if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
+       if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                return tape_34xx_unit_check(device, request, irb);
 
-       if (irb->scsw.dstat & DEV_STAT_DEV_END) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
                /*
                 * A unit exception occurs on skipping over a tapemark block.
                 */
-               if (irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
+               if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
                        if (request->op == TO_BSB || request->op == TO_FSB)
                                request->rescnt++;
                        else
index 42ce791..8399876 100644 (file)
@@ -837,13 +837,13 @@ tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
 static int
 tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
 {
-       if (irb->scsw.dstat == DEV_STAT_CHN_END)
+       if (irb->scsw.cmd.dstat == DEV_STAT_CHN_END)
                /* Probably result of halt ssch */
                return TAPE_IO_PENDING;
-       else if (irb->scsw.dstat == 0x85)
+       else if (irb->scsw.cmd.dstat == 0x85)
                /* Device Ready */
                DBF_EVENT(3, "unsol.irq! tape ready: %08x\n", device->cdev_id);
-       else if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       else if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                tape_3590_schedule_work(device, TO_READ_ATTMSG);
        } else {
                DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
@@ -1515,18 +1515,19 @@ tape_3590_irq(struct tape_device *device, struct tape_request *request,
        if (request == NULL)
                return tape_3590_unsolicited_irq(device, irb);
 
-       if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
-           (irb->scsw.dstat & DEV_STAT_DEV_END) && (request->op == TO_WRI)) {
+       if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) &&
+           (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) &&
+           (request->op == TO_WRI)) {
                /* Write at end of volume */
                DBF_EVENT(2, "End of volume\n");
                return tape_3590_erp_failed(device, request, irb, -ENOSPC);
        }
 
-       if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
+       if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                return tape_3590_unit_check(device, request, irb);
 
-       if (irb->scsw.dstat & DEV_STAT_DEV_END) {
-               if (irb->scsw.dstat == DEV_STAT_UNIT_EXCEP) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END) {
+               if (irb->scsw.cmd.dstat == DEV_STAT_UNIT_EXCEP) {
                        if (request->op == TO_FSB || request->op == TO_BSB)
                                request->rescnt++;
                        else
@@ -1536,12 +1537,12 @@ tape_3590_irq(struct tape_device *device, struct tape_request *request,
                return tape_3590_done(device, request);
        }
 
-       if (irb->scsw.dstat & DEV_STAT_CHN_END) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) {
                DBF_EVENT(2, "cannel end\n");
                return TAPE_IO_PENDING;
        }
 
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                DBF_EVENT(2, "Unit Attention when busy..\n");
                return TAPE_IO_PENDING;
        }
index ebe8406..687720b 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/mtio.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -289,21 +290,26 @@ tapechar_open (struct inode *inode, struct file *filp)
        if (imajor(filp->f_path.dentry->d_inode) != tapechar_major)
                return -ENODEV;
 
+       lock_kernel();
        minor = iminor(filp->f_path.dentry->d_inode);
        device = tape_get_device(minor / TAPE_MINORS_PER_DEV);
        if (IS_ERR(device)) {
                DBF_EVENT(3, "TCHAR:open: tape_get_device() failed\n");
-               return PTR_ERR(device);
+               rc = PTR_ERR(device);
+               goto out;
        }
 
 
        rc = tape_open(device);
        if (rc == 0) {
                filp->private_data = device;
-               return nonseekable_open(inode, filp);
+               rc = nonseekable_open(inode, filp);
        }
-       tape_put_device(device);
+       else
+               tape_put_device(device);
 
+out:
+       unlock_kernel();
        return rc;
 }
 
index c20e3c5..181a544 100644 (file)
@@ -839,7 +839,7 @@ tape_dump_sense(struct tape_device* device, struct tape_request *request,
 
        PRINT_INFO("-------------------------------------------------\n");
        PRINT_INFO("DSTAT : %02x  CSTAT: %02x   CPA: %04x\n",
-                  irb->scsw.dstat, irb->scsw.cstat, irb->scsw.cpa);
+                  irb->scsw.cmd.dstat, irb->scsw.cmd.cstat, irb->scsw.cmd.cpa);
        PRINT_INFO("DEVICE: %s\n", device->cdev->dev.bus_id);
        if (request != NULL)
                PRINT_INFO("OP    : %s\n", tape_op_verbose[request->op]);
@@ -867,7 +867,7 @@ tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request,
        else
                op = "---";
        DBF_EVENT(3, "DSTAT : %02x   CSTAT: %02x\n",
-                 irb->scsw.dstat,irb->scsw.cstat);
+                 irb->scsw.cmd.dstat, irb->scsw.cmd.cstat);
        DBF_EVENT(3, "DEVICE: %08x OP\t: %s\n", device->cdev_id, op);
        sptr = (unsigned int *) irb->ecw;
        DBF_EVENT(3, "%08x %08x\n", sptr[0], sptr[1]);
@@ -1083,10 +1083,11 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
         * error might still apply. So we just schedule the request to be
         * started later.
         */
-       if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
+       if (irb->scsw.cmd.cc != 0 &&
+           (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) &&
            (request->status == TAPE_REQUEST_IN_IO)) {
                DBF_EVENT(3,"(%08x): deferred cc=%i, fctl=%i. restarting\n",
-                       device->cdev_id, irb->scsw.cc, irb->scsw.fctl);
+                       device->cdev_id, irb->scsw.cmd.cc, irb->scsw.cmd.fctl);
                request->status = TAPE_REQUEST_QUEUED;
                schedule_delayed_work(&device->tape_dnr, HZ);
                return;
@@ -1094,8 +1095,8 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
 
        /* May be an unsolicited irq */
        if(request != NULL)
-               request->rescnt = irb->scsw.count;
-       else if ((irb->scsw.dstat == 0x85 || irb->scsw.dstat == 0x80) &&
+               request->rescnt = irb->scsw.cmd.count;
+       else if ((irb->scsw.cmd.dstat == 0x85 || irb->scsw.cmd.dstat == 0x80) &&
                 !list_empty(&device->req_queue)) {
                /* Not Ready to Ready after long busy ? */
                struct tape_request *req;
@@ -1111,7 +1112,7 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                        return;
                }
        }
-       if (irb->scsw.dstat != 0x0c) {
+       if (irb->scsw.cmd.dstat != 0x0c) {
                /* Set the 'ONLINE' flag depending on sense byte 1 */
                if(*(((__u8 *) irb->ecw) + 1) & SENSE_DRIVE_ONLINE)
                        device->tape_generic_status |= GMT_ONLINE(~0);
index 5043150..a7fe630 100644 (file)
@@ -663,7 +663,7 @@ static int
 tty3270_irq(struct tty3270 *tp, struct raw3270_request *rq, struct irb *irb)
 {
        /* Handle ATTN. Schedule tasklet to read aid. */
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                if (!tp->throttle)
                        tty3270_issue_read(tp, 0);
                else
@@ -671,11 +671,11 @@ tty3270_irq(struct tty3270 *tp, struct raw3270_request *rq, struct irb *irb)
        }
 
        if (rq) {
-               if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
+               if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                        rq->rc = -EIO;
                else
                        /* Normal end. Copy residual count. */
-                       rq->rescnt = irb->scsw.count;
+                       rq->rescnt = irb->scsw.cmd.count;
        }
        return RAW3270_IO_DONE;
 }
@@ -1792,15 +1792,12 @@ static int __init tty3270_init(void)
        tty_set_operations(driver, &tty3270_ops);
        ret = tty_register_driver(driver);
        if (ret) {
-               printk(KERN_ERR "tty3270 registration failed with %d\n", ret);
                put_tty_driver(driver);
                return ret;
        }
        tty3270_driver = driver;
        ret = raw3270_register_notifier(tty3270_notifier);
        if (ret) {
-               printk(KERN_ERR "tty3270 notifier registration failed "
-                      "with %d\n", ret);
                put_tty_driver(driver);
                return ret;
 
index 2f419b0..09e7d9b 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/smp_lock.h>
 #include <asm/cpcmd.h>
 #include <asm/debug.h>
 #include <asm/uaccess.h>
@@ -39,11 +40,14 @@ static int vmcp_open(struct inode *inode, struct file *file)
        session = kmalloc(sizeof(*session), GFP_KERNEL);
        if (!session)
                return -ENOMEM;
+
+       lock_kernel();
        session->bufsize = PAGE_SIZE;
        session->response = NULL;
        session->resp_size = 0;
        mutex_init(&session->mutex);
        file->private_data = session;
+       unlock_kernel();
        return nonseekable_open(inode, file);
 }
 
@@ -61,30 +65,24 @@ static int vmcp_release(struct inode *inode, struct file *file)
 static ssize_t
 vmcp_read(struct file *file, char __user *buff, size_t count, loff_t *ppos)
 {
-       size_t tocopy;
+       ssize_t ret;
+       size_t size;
        struct vmcp_session *session;
 
-       session = (struct vmcp_session *)file->private_data;
+       session = file->private_data;
        if (mutex_lock_interruptible(&session->mutex))
                return -ERESTARTSYS;
        if (!session->response) {
                mutex_unlock(&session->mutex);
                return 0;
        }
-       if (*ppos > session->resp_size) {
-               mutex_unlock(&session->mutex);
-               return 0;
-       }
-       tocopy = min(session->resp_size - (size_t) (*ppos), count);
-       tocopy = min(tocopy, session->bufsize - (size_t) (*ppos));
+       size = min_t(size_t, session->resp_size, session->bufsize);
+       ret = simple_read_from_buffer(buff, count, ppos,
+                                       session->response, size);
 
-       if (copy_to_user(buff, session->response + (*ppos), tocopy)) {
-               mutex_unlock(&session->mutex);
-               return -EFAULT;
-       }
        mutex_unlock(&session->mutex);
-       *ppos += tocopy;
-       return tocopy;
+
+       return ret;
 }
 
 static ssize_t
@@ -198,27 +196,23 @@ static int __init vmcp_init(void)
                PRINT_WARN("z/VM CP interface is only available under z/VM\n");
                return -ENODEV;
        }
+
        vmcp_debug = debug_register("vmcp", 1, 1, 240);
-       if (!vmcp_debug) {
-               PRINT_ERR("z/VM CP interface not loaded. Could not register "
-                          "debug feature\n");
+       if (!vmcp_debug)
                return -ENOMEM;
-       }
+
        ret = debug_register_view(vmcp_debug, &debug_hex_ascii_view);
        if (ret) {
-               PRINT_ERR("z/VM CP interface not loaded. Could not register "
-                         "debug feature view. Error code: %d\n", ret);
                debug_unregister(vmcp_debug);
                return ret;
        }
+
        ret = misc_register(&vmcp_dev);
        if (ret) {
-               PRINT_ERR("z/VM CP interface not loaded. Could not register "
-                          "misc device. Error code: %d\n", ret);
                debug_unregister(vmcp_debug);
                return ret;
        }
-       PRINT_INFO("z/VM CP interface loaded\n");
+
        return 0;
 }
 
@@ -226,7 +220,6 @@ static void __exit vmcp_exit(void)
 {
        misc_deregister(&vmcp_dev);
        debug_unregister(vmcp_debug);
-       PRINT_INFO("z/VM CP interface unloaded.\n");
 }
 
 module_init(vmcp_init);
index 2c2428c..c31faef 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/kmod.h>
 #include <linux/cdev.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 
 
@@ -216,9 +217,7 @@ static int vmlogrdr_get_recording_class_AB(void)
        char *tail;
        int len,i;
 
-       printk (KERN_DEBUG "vmlogrdr: query command: %s\n", cp_command);
        cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
-       printk (KERN_DEBUG "vmlogrdr: response: %s", cp_response);
        len = strnlen(cp_response,sizeof(cp_response));
        // now the parsing
        tail=strnchr(cp_response,len,'=');
@@ -268,11 +267,7 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
                         logptr->recording_name,
                         qid_string);
 
-               printk (KERN_DEBUG "vmlogrdr: recording command: %s\n",
-                       cp_command);
                cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
-               printk (KERN_DEBUG "vmlogrdr: recording response: %s",
-                       cp_response);
        }
 
        memset(cp_command, 0x00, sizeof(cp_command));
@@ -282,10 +277,7 @@ static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
                onoff,
                qid_string);
 
-       printk (KERN_DEBUG "vmlogrdr: recording command: %s\n", cp_command);
        cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
-       printk (KERN_DEBUG "vmlogrdr: recording response: %s",
-               cp_response);
        /* The recording command will usually answer with 'Command complete'
         * on success, but when the specific service was never connected
         * before then there might be an additional informational message
@@ -319,9 +311,11 @@ static int vmlogrdr_open (struct inode *inode, struct file *filp)
                return -ENOSYS;
 
        /* Besure this device hasn't already been opened */
+       lock_kernel();
        spin_lock_bh(&logptr->priv_lock);
        if (logptr->dev_in_use) {
                spin_unlock_bh(&logptr->priv_lock);
+               unlock_kernel();
                return -EBUSY;
        }
        logptr->dev_in_use = 1;
@@ -365,7 +359,9 @@ static int vmlogrdr_open (struct inode *inode, struct file *filp)
                   || (logptr->iucv_path_severed));
        if (logptr->iucv_path_severed)
                goto out_record;
-       return nonseekable_open(inode, filp);
+       ret = nonseekable_open(inode, filp);
+       unlock_kernel();
+       return ret;
 
 out_record:
        if (logptr->autorecording)
@@ -375,6 +371,7 @@ out_path:
        logptr->path = NULL;
 out_dev:
        logptr->dev_in_use = 0;
+       unlock_kernel();
        return -EIO;
 }
 
@@ -567,10 +564,7 @@ static ssize_t vmlogrdr_purge_store(struct device * dev,
                         "RECORDING %s PURGE ",
                         priv->recording_name);
 
-       printk (KERN_DEBUG "vmlogrdr: recording command: %s\n", cp_command);
        cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
-       printk (KERN_DEBUG "vmlogrdr: recording response: %s",
-               cp_response);
 
        return count;
 }
@@ -682,28 +676,20 @@ static int vmlogrdr_register_driver(void)
 
        /* Register with iucv driver */
        ret = iucv_register(&vmlogrdr_iucv_handler, 1);
-       if (ret) {
-               printk (KERN_ERR "vmlogrdr: failed to register with "
-                       "iucv driver\n");
+       if (ret)
                goto out;
-       }
 
        ret = driver_register(&vmlogrdr_driver);
-       if (ret) {
-               printk(KERN_ERR "vmlogrdr: failed to register driver.\n");
+       if (ret)
                goto out_iucv;
-       }
 
        ret = driver_create_file(&vmlogrdr_driver,
                                 &driver_attr_recording_status);
-       if (ret) {
-               printk(KERN_ERR "vmlogrdr: failed to add driver attribute.\n");
+       if (ret)
                goto out_driver;
-       }
 
        vmlogrdr_class = class_create(THIS_MODULE, "vmlogrdr");
        if (IS_ERR(vmlogrdr_class)) {
-               printk(KERN_ERR "vmlogrdr: failed to create class.\n");
                ret = PTR_ERR(vmlogrdr_class);
                vmlogrdr_class = NULL;
                goto out_attr;
@@ -871,12 +857,10 @@ static int __init vmlogrdr_init(void)
        rc = vmlogrdr_register_cdev(dev);
        if (rc)
                goto cleanup;
-       printk (KERN_INFO "vmlogrdr: driver loaded\n");
        return 0;
 
 cleanup:
        vmlogrdr_cleanup();
-       printk (KERN_ERR "vmlogrdr: driver not loaded.\n");
        return rc;
 }
 
@@ -884,7 +868,6 @@ cleanup:
 static void __exit vmlogrdr_exit(void)
 {
        vmlogrdr_cleanup();
-       printk (KERN_INFO "vmlogrdr: driver unloaded\n");
        return;
 }
 
index 83ae9a8..0a9f1cc 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <linux/cdev.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/cio.h>
@@ -277,7 +278,8 @@ static void ur_int_handler(struct ccw_device *cdev, unsigned long intparm,
        struct urdev *urd;
 
        TRACE("ur_int_handler: intparm=0x%lx cstat=%02x dstat=%02x res=%u\n",
-             intparm, irb->scsw.cstat, irb->scsw.dstat, irb->scsw.count);
+             intparm, irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
+             irb->scsw.cmd.count);
 
        if (!intparm) {
                TRACE("ur_int_handler: unsolicited interrupt\n");
@@ -288,7 +290,7 @@ static void ur_int_handler(struct ccw_device *cdev, unsigned long intparm,
        /* On special conditions irb is an error pointer */
        if (IS_ERR(irb))
                urd->io_request_rc = PTR_ERR(irb);
-       else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
+       else if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
                urd->io_request_rc = 0;
        else
                urd->io_request_rc = -EIO;
@@ -668,7 +670,7 @@ static int ur_open(struct inode *inode, struct file *file)
 
        if (accmode == O_RDWR)
                return -EACCES;
-
+       lock_kernel();
        /*
         * We treat the minor number as the devno of the ur device
         * to find in the driver tree.
@@ -676,8 +678,10 @@ static int ur_open(struct inode *inode, struct file *file)
        devno = MINOR(file->f_dentry->d_inode->i_rdev);
 
        urd = urdev_get_from_devno(devno);
-       if (!urd)
-               return -ENXIO;
+       if (!urd) {
+               rc = -ENXIO;
+               goto out;
+       }
 
        spin_lock(&urd->open_lock);
        while (urd->open_flag) {
@@ -720,6 +724,7 @@ static int ur_open(struct inode *inode, struct file *file)
                goto fail_urfile_free;
        urf->file_reclen = rc;
        file->private_data = urf;
+       unlock_kernel();
        return 0;
 
 fail_urfile_free:
@@ -730,6 +735,8 @@ fail_unlock:
        spin_unlock(&urd->open_lock);
 fail_put:
        urdev_put(urd);
+out:
+       unlock_kernel();
        return rc;
 }
 
index 19f8389..21a2a82 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/watchdog.h>
+#include <linux/smp_lock.h>
 
 #include <asm/ebcdic.h>
 #include <asm/io.h>
@@ -92,23 +93,15 @@ static int vmwdt_keepalive(void)
 
        func = vmwdt_conceal ? (wdt_init | wdt_conceal) : wdt_init;
        ret = __diag288(func, vmwdt_interval, ebc_cmd, len);
+       WARN_ON(ret != 0);
        kfree(ebc_cmd);
-
-       if (ret) {
-               printk(KERN_WARNING "%s: problem setting interval %d, "
-                       "cmd %s\n", __func__, vmwdt_interval,
-                       vmwdt_cmd);
-       }
        return ret;
 }
 
 static int vmwdt_disable(void)
 {
        int ret = __diag288(wdt_cancel, 0, "", 0);
-       if (ret) {
-               printk(KERN_WARNING "%s: problem disabling watchdog\n",
-                       __func__);
-       }
+       WARN_ON(ret != 0);
        return ret;
 }
 
@@ -121,21 +114,23 @@ static int __init vmwdt_probe(void)
        static char __initdata ebc_begin[] = {
                194, 197, 199, 201, 213
        };
-       if (__diag288(wdt_init, 15, ebc_begin, sizeof(ebc_begin)) != 0) {
-               printk(KERN_INFO "z/VM watchdog not available\n");
+       if (__diag288(wdt_init, 15, ebc_begin, sizeof(ebc_begin)) != 0)
                return -EINVAL;
-       }
        return vmwdt_disable();
 }
 
 static int vmwdt_open(struct inode *i, struct file *f)
 {
        int ret;
-       if (test_and_set_bit(0, &vmwdt_is_open))
+       lock_kernel();
+       if (test_and_set_bit(0, &vmwdt_is_open)) {
+               unlock_kernel();
                return -EBUSY;
+       }
        ret = vmwdt_keepalive();
        if (ret)
                clear_bit(0, &vmwdt_is_open);
+       unlock_kernel();
        return ret ? ret : nonseekable_open(i, f);
 }
 
index bbbd14e..047dd92 100644 (file)
@@ -223,12 +223,10 @@ static int __init init_cpu_info(enum arch_id arch)
        /* get info for boot cpu from lowcore, stored in the HSA */
 
        sa = kmalloc(sizeof(*sa), GFP_KERNEL);
-       if (!sa) {
-               ERROR_MSG("kmalloc failed: %s: %i\n",__func__, __LINE__);
+       if (!sa)
                return -ENOMEM;
-       }
        if (memcpy_hsa_kernel(sa, sys_info.sa_base, sys_info.sa_size) < 0) {
-               ERROR_MSG("could not copy from HSA\n");
+               TRACE("could not copy from HSA\n");
                kfree(sa);
                return -EIO;
        }
@@ -511,6 +509,8 @@ static void __init set_s390x_lc_mask(union save_area *map)
  */
 static int __init sys_info_init(enum arch_id arch)
 {
+       int rc;
+
        switch (arch) {
        case ARCH_S390X:
                MSG("DETECTED 'S390X (64 bit) OS'\n");
@@ -529,10 +529,9 @@ static int __init sys_info_init(enum arch_id arch)
                return -EINVAL;
        }
        sys_info.arch = arch;
-       if (init_cpu_info(arch)) {
-               ERROR_MSG("get cpu info failed\n");
-               return -ENOMEM;
-       }
+       rc = init_cpu_info(arch);
+       if (rc)
+               return rc;
        sys_info.mem_size = real_memory_size;
 
        return 0;
@@ -544,12 +543,12 @@ static int __init check_sdias(void)
 
        rc = sclp_sdias_blk_count();
        if (rc < 0) {
-               ERROR_MSG("Could not determine HSA size\n");
+               TRACE("Could not determine HSA size\n");
                return rc;
        }
        act_hsa_size = (rc - 1) * PAGE_SIZE;
        if (act_hsa_size < ZFCPDUMP_HSA_SIZE) {
-               ERROR_MSG("HSA size too small: %i\n", act_hsa_size);
+               TRACE("HSA size too small: %i\n", act_hsa_size);
                return -EINVAL;
        }
        return 0;
@@ -590,16 +589,12 @@ static int __init zcore_init(void)
                goto fail;
 
        rc = check_sdias();
-       if (rc) {
-               ERROR_MSG("Dump initialization failed\n");
+       if (rc)
                goto fail;
-       }
 
        rc = memcpy_hsa_kernel(&arch, __LC_AR_MODE_ID, 1);
-       if (rc) {
-               ERROR_MSG("sdial memcpy for arch id failed\n");
+       if (rc)
                goto fail;
-       }
 
 #ifndef __s390x__
        if (arch == ARCH_S390X) {
@@ -610,10 +605,8 @@ static int __init zcore_init(void)
 #endif
 
        rc = sys_info_init(arch);
-       if (rc) {
-               ERROR_MSG("arch init failed\n");
+       if (rc)
                goto fail;
-       }
 
        zcore_header_init(arch, &zcore_header);
 
index cfaf77b..91e9e3f 100644 (file)
@@ -2,9 +2,11 @@
 # Makefile for the S/390 common i/o drivers
 #
 
-obj-y += airq.o blacklist.o chsc.o cio.o css.o chp.o idset.o
+obj-y += airq.o blacklist.o chsc.o cio.o css.o chp.o idset.o isc.o scsw.o \
+       fcx.o itcw.o
 ccw_device-objs += device.o device_fsm.o device_ops.o
 ccw_device-objs += device_id.o device_pgid.o device_status.o
 obj-y += ccw_device.o cmf.o
+obj-$(CONFIG_CHSC_SCH) += chsc_sch.o
 obj-$(CONFIG_CCWGROUP) += ccwgroup.o
 obj-$(CONFIG_QDIO) += qdio.o
index b7a07a8..fe6cea1 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/rcupdate.h>
 
 #include <asm/airq.h>
+#include <asm/isc.h>
 
 #include "cio.h"
 #include "cio_debug.h"
@@ -33,15 +34,15 @@ struct airq_t {
        void *drv_data;
 };
 
-static union indicator_t indicators;
-static struct airq_t *airqs[NR_AIRQS];
+static union indicator_t indicators[MAX_ISC];
+static struct airq_t *airqs[MAX_ISC][NR_AIRQS];
 
-static int register_airq(struct airq_t *airq)
+static int register_airq(struct airq_t *airq, u8 isc)
 {
        int i;
 
        for (i = 0; i < NR_AIRQS; i++)
-               if (!cmpxchg(&airqs[i], NULL, airq))
+               if (!cmpxchg(&airqs[isc][i], NULL, airq))
                        return i;
        return -ENOMEM;
 }
@@ -50,18 +51,21 @@ static int register_airq(struct airq_t *airq)
  * s390_register_adapter_interrupt() - register adapter interrupt handler
  * @handler: adapter handler to be registered
  * @drv_data: driver data passed with each call to the handler
+ * @isc: isc for which the handler should be called
  *
  * Returns:
  *  Pointer to the indicator to be used on success
  *  ERR_PTR() if registration failed
  */
 void *s390_register_adapter_interrupt(adapter_int_handler_t handler,
-                                     void *drv_data)
+                                     void *drv_data, u8 isc)
 {
        struct airq_t *airq;
        char dbf_txt[16];
        int ret;
 
+       if (isc > MAX_ISC)
+               return ERR_PTR(-EINVAL);
        airq = kmalloc(sizeof(struct airq_t), GFP_KERNEL);
        if (!airq) {
                ret = -ENOMEM;
@@ -69,34 +73,35 @@ void *s390_register_adapter_interrupt(adapter_int_handler_t handler,
        }
        airq->handler = handler;
        airq->drv_data = drv_data;
-       ret = register_airq(airq);
-       if (ret < 0)
-               kfree(airq);
+
+       ret = register_airq(airq, isc);
 out:
        snprintf(dbf_txt, sizeof(dbf_txt), "rairq:%d", ret);
        CIO_TRACE_EVENT(4, dbf_txt);
-       if (ret < 0)
+       if (ret < 0) {
+               kfree(airq);
                return ERR_PTR(ret);
-       else
-               return &indicators.byte[ret];
+       else
+               return &indicators[isc].byte[ret];
 }
 EXPORT_SYMBOL(s390_register_adapter_interrupt);
 
 /**
  * s390_unregister_adapter_interrupt - unregister adapter interrupt handler
  * @ind: indicator for which the handler is to be unregistered
+ * @isc: interruption subclass
  */
-void s390_unregister_adapter_interrupt(void *ind)
+void s390_unregister_adapter_interrupt(void *ind, u8 isc)
 {
        struct airq_t *airq;
        char dbf_txt[16];
        int i;
 
-       i = (int) ((addr_t) ind) - ((addr_t) &indicators.byte[0]);
+       i = (int) ((addr_t) ind) - ((addr_t) &indicators[isc].byte[0]);
        snprintf(dbf_txt, sizeof(dbf_txt), "urairq:%d", i);
        CIO_TRACE_EVENT(4, dbf_txt);
-       indicators.byte[i] = 0;
-       airq = xchg(&airqs[i], NULL);
+       indicators[isc].byte[i] = 0;
+       airq = xchg(&airqs[isc][i], NULL);
        /*
         * Allow interrupts to complete. This will ensure that the airq handle
         * is no longer referenced by any interrupt handler.
@@ -108,7 +113,7 @@ EXPORT_SYMBOL(s390_unregister_adapter_interrupt);
 
 #define INDICATOR_MASK (0xffUL << ((NR_AIRQS_PER_WORD - 1) * 8))
 
-void do_adapter_IO(void)
+void do_adapter_IO(u8 isc)
 {
        int w;
        int i;
@@ -120,22 +125,22 @@ void do_adapter_IO(void)
         * fetch operations.
         */
        for (w = 0; w < NR_AIRQ_WORDS; w++) {
-               word = indicators.word[w];
+               word = indicators[isc].word[w];
                i = w * NR_AIRQS_PER_WORD;
                /*
                 * Check bytes within word for active indicators.
                 */
                while (word) {
                        if (word & INDICATOR_MASK) {
-                               airq = airqs[i];
+                               airq = airqs[isc][i];
                                if (likely(airq))
-                                       airq->handler(&indicators.byte[i],
+                                       airq->handler(&indicators[isc].byte[i],
                                                      airq->drv_data);
                                else
                                        /*
                                         * Reset ill-behaved indicator.
                                         */
-                                       indicators.byte[i] = 0;
+                                       indicators[isc].byte[i] = 0;
                        }
                        word <<= 8;
                        i++;
index 297cdce..db00b05 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/chpid.h>
 #include <asm/sclp.h>
 
+#include "../s390mach.h"
 #include "cio.h"
 #include "css.h"
 #include "ioasm.h"
@@ -94,6 +95,7 @@ u8 chp_get_sch_opm(struct subchannel *sch)
        }
        return opm;
 }
+EXPORT_SYMBOL_GPL(chp_get_sch_opm);
 
 /**
  * chp_is_registered - check if a channel-path is registered
@@ -121,11 +123,8 @@ static int s390_vary_chpid(struct chp_id chpid, int on)
        CIO_TRACE_EVENT(2, dbf_text);
 
        status = chp_get_status(chpid);
-       if (!on && !status) {
-               printk(KERN_ERR "cio: chpid %x.%02x is already offline\n",
-                      chpid.cssid, chpid.id);
-               return -EINVAL;
-       }
+       if (!on && !status)
+               return 0;
 
        set_chp_logically_online(chpid, on);
        chsc_chp_vary(chpid, on);
@@ -141,21 +140,14 @@ static ssize_t chp_measurement_chars_read(struct kobject *kobj,
 {
        struct channel_path *chp;
        struct device *device;
-       unsigned int size;
 
        device = container_of(kobj, struct device, kobj);
        chp = to_channelpath(device);
        if (!chp->cmg_chars)
                return 0;
 
-       size = sizeof(struct cmg_chars);
-
-       if (off > size)
-               return 0;
-       if (off + count > size)
-               count = size - off;
-       memcpy(buf, chp->cmg_chars + off, count);
-       return count;
+       return memory_read_from_buffer(buf, count, &off,
+                               chp->cmg_chars, sizeof(struct cmg_chars));
 }
 
 static struct bin_attribute chp_measurement_chars_attr = {
@@ -405,7 +397,7 @@ int chp_new(struct chp_id chpid)
                 chpid.id);
 
        /* Obtain channel path description and fill it in. */
-       ret = chsc_determine_channel_path_description(chpid, &chp->desc);
+       ret = chsc_determine_base_channel_path_desc(chpid, &chp->desc);
        if (ret)
                goto out_free;
        if ((chp->desc.flags & 0x80) == 0) {
@@ -413,8 +405,7 @@ int chp_new(struct chp_id chpid)
                goto out_free;
        }
        /* Get channel-measurement characteristics. */
-       if (css_characteristics_avail && css_chsc_characteristics.scmc
-           && css_chsc_characteristics.secm) {
+       if (css_chsc_characteristics.scmc && css_chsc_characteristics.secm) {
                ret = chsc_get_channel_measurement_chars(chp);
                if (ret)
                        goto out_free;
@@ -476,26 +467,74 @@ void *chp_get_chp_desc(struct chp_id chpid)
 
 /**
  * chp_process_crw - process channel-path status change
- * @id: channel-path ID number
- * @status: non-zero if channel-path has become available, zero otherwise
+ * @crw0: channel report-word to handler
+ * @crw1: second channel-report word (always NULL)
+ * @overflow: crw overflow indication
  *
  * Handle channel-report-words indicating that the status of a channel-path
  * has changed.
  */
-void chp_process_crw(int id, int status)
+static void chp_process_crw(struct crw *crw0, struct crw *crw1,
+                           int overflow)
 {
        struct chp_id chpid;
 
+       if (overflow) {
+               css_schedule_eval_all();
+               return;
+       }
+       CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
+                     "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
+                     crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
+                     crw0->erc, crw0->rsid);
+       /*
+        * Check for solicited machine checks. These are
+        * created by reset channel path and need not be
+        * handled here.
+        */
+       if (crw0->slct) {
+               CIO_CRW_EVENT(2, "solicited machine check for "
+                             "channel path %02X\n", crw0->rsid);
+               return;
+       }
        chp_id_init(&chpid);
-       chpid.id = id;
-       if (status) {
+       chpid.id = crw0->rsid;
+       switch (crw0->erc) {
+       case CRW_ERC_IPARM: /* Path has come. */
                if (!chp_is_registered(chpid))
                        chp_new(chpid);
                chsc_chp_online(chpid);
-       } else
+               break;
+       case CRW_ERC_PERRI: /* Path has gone. */
+       case CRW_ERC_PERRN:
                chsc_chp_offline(chpid);
+               break;
+       default:
+               CIO_CRW_EVENT(2, "Don't know how to handle erc=%x\n",
+                             crw0->erc);
+       }
 }
 
+int chp_ssd_get_mask(struct chsc_ssd_info *ssd, struct chp_link *link)
+{
+       int i;
+       int mask;
+
+       for (i = 0; i < 8; i++) {
+               mask = 0x80 >> i;
+               if (!(ssd->path_mask & mask))
+                       continue;
+               if (!chp_id_is_equal(&ssd->chpid[i], &link->chpid))
+                       continue;
+               if ((ssd->fla_valid_mask & mask) &&
+                   ((ssd->fla[i] & link->fla_mask) != link->fla))
+                       continue;
+               return mask;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(chp_ssd_get_mask);
+
 static inline int info_bit_num(struct chp_id id)
 {
        return id.id + id.cssid * (__MAX_CHPID + 1);
@@ -575,6 +614,7 @@ static void cfg_func(struct work_struct *work)
 {
        struct chp_id chpid;
        enum cfg_task_t t;
+       int rc;
 
        mutex_lock(&cfg_lock);
        t = cfg_none;
@@ -589,14 +629,24 @@ static void cfg_func(struct work_struct *work)
 
        switch (t) {
        case cfg_configure:
-               sclp_chp_configure(chpid);
-               info_expire();
-               chsc_chp_online(chpid);
+               rc = sclp_chp_configure(chpid);
+               if (rc)
+                       CIO_MSG_EVENT(2, "chp: sclp_chp_configure(%x.%02x)="
+                                     "%d\n", chpid.cssid, chpid.id, rc);
+               else {
+                       info_expire();
+                       chsc_chp_online(chpid);
+               }
                break;
        case cfg_deconfigure:
-               sclp_chp_deconfigure(chpid);
-               info_expire();
-               chsc_chp_offline(chpid);
+               rc = sclp_chp_deconfigure(chpid);
+               if (rc)
+                       CIO_MSG_EVENT(2, "chp: sclp_chp_deconfigure(%x.%02x)="
+                                     "%d\n", chpid.cssid, chpid.id, rc);
+               else {
+                       info_expire();
+                       chsc_chp_offline(chpid);
+               }
                break;
        case cfg_none:
                /* Get updated information after last change. */
@@ -654,10 +704,16 @@ static int cfg_wait_idle(void)
 static int __init chp_init(void)
 {
        struct chp_id chpid;
+       int ret;
 
+       ret = s390_register_crw_handler(CRW_RSC_CPATH, chp_process_crw);
+       if (ret)
+               return ret;
        chp_wq = create_singlethread_workqueue("cio_chp");
-       if (!chp_wq)
+       if (!chp_wq) {
+               s390_unregister_crw_handler(CRW_RSC_CPATH);
                return -ENOMEM;
+       }
        INIT_WORK(&cfg_work, cfg_func);
        init_waitqueue_head(&cfg_wait_queue);
        if (info_update())
index 6528656..26c3d22 100644 (file)
 #include <linux/device.h>
 #include <asm/chpid.h>
 #include "chsc.h"
+#include "css.h"
 
 #define CHP_STATUS_STANDBY             0
 #define CHP_STATUS_CONFIGURED          1
 #define CHP_STATUS_RESERVED            2
 #define CHP_STATUS_NOT_RECOGNIZED      3
 
+#define CHP_ONLINE 0
+#define CHP_OFFLINE 1
+#define CHP_VARY_ON 2
+#define CHP_VARY_OFF 3
+
+struct chp_link {
+       struct chp_id chpid;
+       u32 fla_mask;
+       u16 fla;
+};
+
 static inline int chp_test_bit(u8 *bitmap, int num)
 {
        int byte = num >> 3;
@@ -42,12 +54,11 @@ int chp_get_status(struct chp_id chpid);
 u8 chp_get_sch_opm(struct subchannel *sch);
 int chp_is_registered(struct chp_id chpid);
 void *chp_get_chp_desc(struct chp_id chpid);
-void chp_process_crw(int id, int available);
 void chp_remove_cmg_attr(struct channel_path *chp);
 int chp_add_cmg_attr(struct channel_path *chp);
 int chp_new(struct chp_id chpid);
 void chp_cfg_schedule(struct chp_id chpid, int configure);
 void chp_cfg_cancel_deconfigure(struct chp_id chpid);
 int chp_info_get_status(struct chp_id chpid);
-
+int chp_ssd_get_mask(struct chsc_ssd_info *, struct chp_link *);
 #endif /* S390_CHP_H */
index 5de8690..65264a3 100644 (file)
@@ -2,8 +2,7 @@
  *  drivers/s390/cio/chsc.c
  *   S/390 common I/O routines -- channel subsystem call
  *
- *    Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
- *                           IBM Corporation
+ *    Copyright IBM Corp. 1999,2008
  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
  *              Cornelia Huck (cornelia.huck@de.ibm.com)
  *              Arnd Bergmann (arndb@de.ibm.com)
@@ -16,7 +15,9 @@
 
 #include <asm/cio.h>
 #include <asm/chpid.h>
+#include <asm/chsc.h>
 
+#include "../s390mach.h"
 #include "css.h"
 #include "cio.h"
 #include "cio_debug.h"
@@ -127,77 +128,12 @@ out_free:
        return ret;
 }
 
-static int check_for_io_on_path(struct subchannel *sch, int mask)
-{
-       int cc;
-
-       cc = stsch(sch->schid, &sch->schib);
-       if (cc)
-               return 0;
-       if (sch->schib.scsw.actl && sch->schib.pmcw.lpum == mask)
-               return 1;
-       return 0;
-}
-
-static void terminate_internal_io(struct subchannel *sch)
-{
-       if (cio_clear(sch)) {
-               /* Recheck device in case clear failed. */
-               sch->lpm = 0;
-               if (device_trigger_verify(sch) != 0)
-                       css_schedule_eval(sch->schid);
-               return;
-       }
-       /* Request retry of internal operation. */
-       device_set_intretry(sch);
-       /* Call handler. */
-       if (sch->driver && sch->driver->termination)
-               sch->driver->termination(sch);
-}
-
 static int s390_subchannel_remove_chpid(struct subchannel *sch, void *data)
 {
-       int j;
-       int mask;
-       struct chp_id *chpid = data;
-       struct schib schib;
-
-       for (j = 0; j < 8; j++) {
-               mask = 0x80 >> j;
-               if ((sch->schib.pmcw.pim & mask) &&
-                   (sch->schib.pmcw.chpid[j] == chpid->id))
-                       break;
-       }
-       if (j >= 8)
-               return 0;
-
        spin_lock_irq(sch->lock);
-
-       stsch(sch->schid, &schib);
-       if (!css_sch_is_valid(&schib))
-               goto out_unreg;
-       memcpy(&sch->schib, &schib, sizeof(struct schib));
-       /* Check for single path devices. */
-       if (sch->schib.pmcw.pim == 0x80)
-               goto out_unreg;
-
-       if (check_for_io_on_path(sch, mask)) {
-               if (device_is_online(sch))
-                       device_kill_io(sch);
-               else {
-                       terminate_internal_io(sch);
-                       /* Re-start path verification. */
-                       if (sch->driver && sch->driver->verify)
-                               sch->driver->verify(sch);
-               }
-       } else {
-               /* trigger path verification. */
-               if (sch->driver && sch->driver->verify)
-                       sch->driver->verify(sch);
-               else if (sch->lpm == mask)
+       if (sch->driver && sch->driver->chp_event)
+               if (sch->driver->chp_event(sch, data, CHP_OFFLINE) != 0)
                        goto out_unreg;
-       }
-
        spin_unlock_irq(sch->lock);
        return 0;
 
@@ -211,15 +147,18 @@ out_unreg:
 void chsc_chp_offline(struct chp_id chpid)
 {
        char dbf_txt[15];
+       struct chp_link link;
 
        sprintf(dbf_txt, "chpr%x.%02x", chpid.cssid, chpid.id);
        CIO_TRACE_EVENT(2, dbf_txt);
 
        if (chp_get_status(chpid) <= 0)
                return;
+       memset(&link, 0, sizeof(struct chp_link));
+       link.chpid = chpid;
        /* Wait until previous actions have settled. */
        css_wait_for_slow_path();
-       for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &chpid);
+       for_each_subchannel_staged(s390_subchannel_remove_chpid, NULL, &link);
 }
 
 static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
@@ -242,67 +181,25 @@ static int s390_process_res_acc_new_sch(struct subchannel_id schid, void *data)
        return 0;
 }
 
-struct res_acc_data {
-       struct chp_id chpid;
-       u32 fla_mask;
-       u16 fla;
-};
-
-static int get_res_chpid_mask(struct chsc_ssd_info *ssd,
-                             struct res_acc_data *data)
-{
-       int i;
-       int mask;
-
-       for (i = 0; i < 8; i++) {
-               mask = 0x80 >> i;
-               if (!(ssd->path_mask & mask))
-                       continue;
-               if (!chp_id_is_equal(&ssd->chpid[i], &data->chpid))
-                       continue;
-               if ((ssd->fla_valid_mask & mask) &&
-                   ((ssd->fla[i] & data->fla_mask) != data->fla))
-                       continue;
-               return mask;
-       }
-       return 0;
-}
-
 static int __s390_process_res_acc(struct subchannel *sch, void *data)
 {
-       int chp_mask, old_lpm;
-       struct res_acc_data *res_data = data;
-
        spin_lock_irq(sch->lock);
-       chp_mask = get_res_chpid_mask(&sch->ssd_info, res_data);
-       if (chp_mask == 0)
-               goto out;
-       if (stsch(sch->schid, &sch->schib))
-               goto out;
-       old_lpm = sch->lpm;
-       sch->lpm = ((sch->schib.pmcw.pim &
-                    sch->schib.pmcw.pam &
-                    sch->schib.pmcw.pom)
-                   | chp_mask) & sch->opm;
-       if (!old_lpm && sch->lpm)
-               device_trigger_reprobe(sch);
-       else if (sch->driver && sch->driver->verify)
-               sch->driver->verify(sch);
-out:
+       if (sch->driver && sch->driver->chp_event)
+               sch->driver->chp_event(sch, data, CHP_ONLINE);
        spin_unlock_irq(sch->lock);
 
        return 0;
 }
 
-static void s390_process_res_acc (struct res_acc_data *res_data)
+static void s390_process_res_acc(struct chp_link *link)
 {
        char dbf_txt[15];
 
-       sprintf(dbf_txt, "accpr%x.%02x", res_data->chpid.cssid,
-               res_data->chpid.id);
+       sprintf(dbf_txt, "accpr%x.%02x", link->chpid.cssid,
+               link->chpid.id);
        CIO_TRACE_EVENT( 2, dbf_txt);
-       if (res_data->fla != 0) {
-               sprintf(dbf_txt, "fla%x", res_data->fla);
+       if (link->fla != 0) {
+               sprintf(dbf_txt, "fla%x", link->fla);
                CIO_TRACE_EVENT( 2, dbf_txt);
        }
        /* Wait until previous actions have settled. */
@@ -315,7 +212,7 @@ static void s390_process_res_acc (struct res_acc_data *res_data)
         * will we have to do.
         */
        for_each_subchannel_staged(__s390_process_res_acc,
-                                  s390_process_res_acc_new_sch, res_data);
+                                  s390_process_res_acc_new_sch, link);
 }
 
 static int
@@ -388,7 +285,7 @@ static void chsc_process_sei_link_incident(struct chsc_sei_area *sei_area)
 
 static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
 {
-       struct res_acc_data res_data;
+       struct chp_link link;
        struct chp_id chpid;
        int status;
 
@@ -404,18 +301,18 @@ static void chsc_process_sei_res_acc(struct chsc_sei_area *sei_area)
                chp_new(chpid);
        else if (!status)
                return;
-       memset(&res_data, 0, sizeof(struct res_acc_data));
-       res_data.chpid = chpid;
+       memset(&link, 0, sizeof(struct chp_link));
+       link.chpid = chpid;
        if ((sei_area->vf & 0xc0) != 0) {
-               res_data.fla = sei_area->fla;
+               link.fla = sei_area->fla;
                if ((sei_area->vf & 0xc0) == 0xc0)
                        /* full link address */
-                       res_data.fla_mask = 0xffff;
+                       link.fla_mask = 0xffff;
                else
                        /* link address */
-                       res_data.fla_mask = 0xff00;
+                       link.fla_mask = 0xff00;
        }
-       s390_process_res_acc(&res_data);
+       s390_process_res_acc(&link);
 }
 
 struct chp_config_data {
@@ -480,17 +377,25 @@ static void chsc_process_sei(struct chsc_sei_area *sei_area)
        }
 }
 
-void chsc_process_crw(void)
+static void chsc_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
 {
        struct chsc_sei_area *sei_area;
 
+       if (overflow) {
+               css_schedule_eval_all();
+               return;
+       }
+       CIO_CRW_EVENT(2, "CRW reports slct=%d, oflw=%d, "
+                     "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
+                     crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
+                     crw0->erc, crw0->rsid);
        if (!sei_page)
                return;
        /* Access to sei_page is serialized through machine check handler
         * thread, so no need for locking. */
        sei_area = sei_page;
 
-       CIO_TRACE_EVENT( 2, "prcss");
+       CIO_TRACE_EVENT(2, "prcss");
        do {
                memset(sei_area, 0, sizeof(*sei_area));
                sei_area->request.length = 0x0010;
@@ -509,114 +414,36 @@ void chsc_process_crw(void)
        } while (sei_area->flags & 0x80);
 }
 
-static int __chp_add_new_sch(struct subchannel_id schid, void *data)
-{
-       struct schib schib;
-
-       if (stsch_err(schid, &schib))
-               /* We're through */
-               return -ENXIO;
-
-       /* Put it on the slow path. */
-       css_schedule_eval(schid);
-       return 0;
-}
-
-
-static int __chp_add(struct subchannel *sch, void *data)
-{
-       int i, mask;
-       struct chp_id *chpid = data;
-
-       spin_lock_irq(sch->lock);
-       for (i=0; i<8; i++) {
-               mask = 0x80 >> i;
-               if ((sch->schib.pmcw.pim & mask) &&
-                   (sch->schib.pmcw.chpid[i] == chpid->id))
-                       break;
-       }
-       if (i==8) {
-               spin_unlock_irq(sch->lock);
-               return 0;
-       }
-       if (stsch(sch->schid, &sch->schib)) {
-               spin_unlock_irq(sch->lock);
-               css_schedule_eval(sch->schid);
-               return 0;
-       }
-       sch->lpm = ((sch->schib.pmcw.pim &
-                    sch->schib.pmcw.pam &
-                    sch->schib.pmcw.pom)
-                   | mask) & sch->opm;
-
-       if (sch->driver && sch->driver->verify)
-               sch->driver->verify(sch);
-
-       spin_unlock_irq(sch->lock);
-
-       return 0;
-}
-
 void chsc_chp_online(struct chp_id chpid)
 {
        char dbf_txt[15];
+       struct chp_link link;
 
        sprintf(dbf_txt, "cadd%x.%02x", chpid.cssid, chpid.id);
        CIO_TRACE_EVENT(2, dbf_txt);
 
        if (chp_get_status(chpid) != 0) {
+               memset(&link, 0, sizeof(struct chp_link));
+               link.chpid = chpid;
                /* Wait until previous actions have settled. */
                css_wait_for_slow_path();
-               for_each_subchannel_staged(__chp_add, __chp_add_new_sch,
-                                          &chpid);
+               for_each_subchannel_staged(__s390_process_res_acc, NULL,
+                                          &link);
        }
 }
 
 static void __s390_subchannel_vary_chpid(struct subchannel *sch,
                                         struct chp_id chpid, int on)
 {
-       int chp, old_lpm;
-       int mask;
        unsigned long flags;
+       struct chp_link link;
 
+       memset(&link, 0, sizeof(struct chp_link));
+       link.chpid = chpid;
        spin_lock_irqsave(sch->lock, flags);
-       old_lpm = sch->lpm;
-       for (chp = 0; chp < 8; chp++) {
-               mask = 0x80 >> chp;
-               if (!(sch->ssd_info.path_mask & mask))
-                       continue;
-               if (!chp_id_is_equal(&sch->ssd_info.chpid[chp], &chpid))
-                       continue;
-
-               if (on) {
-                       sch->opm |= mask;
-                       sch->lpm |= mask;
-                       if (!old_lpm)
-                               device_trigger_reprobe(sch);
-                       else if (sch->driver && sch->driver->verify)
-                               sch->driver->verify(sch);
-                       break;
-               }
-               sch->opm &= ~mask;
-               sch->lpm &= ~mask;
-               if (check_for_io_on_path(sch, mask)) {
-                       if (device_is_online(sch))
-                               /* Path verification is done after killing. */
-                               device_kill_io(sch);
-                       else {
-                               /* Kill and retry internal I/O. */
-                               terminate_internal_io(sch);
-                               /* Re-start path verification. */
-                               if (sch->driver && sch->driver->verify)
-                                       sch->driver->verify(sch);
-                       }
-               } else if (!sch->lpm) {
-                       if (device_trigger_verify(sch) != 0)
-                               css_schedule_eval(sch->schid);
-               } else if (sch->driver && sch->driver->verify)
-                       sch->driver->verify(sch);
-               break;
-       }
+       if (sch->driver && sch->driver->chp_event)
+               sch->driver->chp_event(sch, &link,
+                                      on ? CHP_VARY_ON : CHP_VARY_OFF);
        spin_unlock_irqrestore(sch->lock, flags);
 }
 
@@ -656,6 +483,10 @@ __s390_vary_chpid_on(struct subchannel_id schid, void *data)
  */
 int chsc_chp_vary(struct chp_id chpid, int on)
 {
+       struct chp_link link;
+
+       memset(&link, 0, sizeof(struct chp_link));
+       link.chpid = chpid;
        /* Wait until previous actions have settled. */
        css_wait_for_slow_path();
        /*
@@ -664,10 +495,10 @@ int chsc_chp_vary(struct chp_id chpid, int on)
 
        if (on)
                for_each_subchannel_staged(s390_subchannel_vary_chpid_on,
-                                          __s390_vary_chpid_on, &chpid);
+                                          __s390_vary_chpid_on, &link);
        else
                for_each_subchannel_staged(s390_subchannel_vary_chpid_off,
-                                          NULL, &chpid);
+                                          NULL, &link);
 
        return 0;
 }
@@ -797,23 +628,33 @@ chsc_secm(struct channel_subsystem *css, int enable)
        return ret;
 }
 
-int chsc_determine_channel_path_description(struct chp_id chpid,
-                                           struct channel_path_desc *desc)
+int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
+                                    int c, int m,
+                                    struct chsc_response_struct *resp)
 {
        int ccode, ret;
 
        struct {
                struct chsc_header request;
-               u32 : 24;
+               u32 : 2;
+               u32 m : 1;
+               u32 c : 1;
+               u32 fmt : 4;
+               u32 cssid : 8;
+               u32 : 4;
+               u32 rfmt : 4;
                u32 first_chpid : 8;
                u32 : 24;
                u32 last_chpid : 8;
                u32 zeroes1;
                struct chsc_header response;
-               u32 zeroes2;
-               struct channel_path_desc desc;
+               u8 data[PAGE_SIZE - 20];
        } __attribute__ ((packed)) *scpd_area;
 
+       if ((rfmt == 1) && !css_general_characteristics.fcs)
+               return -EINVAL;
+       if ((rfmt == 2) && !css_general_characteristics.cib)
+               return -EINVAL;
        scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
        if (!scpd_area)
                return -ENOMEM;
@@ -821,8 +662,13 @@ int chsc_determine_channel_path_description(struct chp_id chpid,
        scpd_area->request.length = 0x0010;
        scpd_area->request.code = 0x0002;
 
+       scpd_area->cssid = chpid.cssid;
        scpd_area->first_chpid = chpid.id;
        scpd_area->last_chpid = chpid.id;
+       scpd_area->m = m;
+       scpd_area->c = c;
+       scpd_area->fmt = fmt;
+       scpd_area->rfmt = rfmt;
 
        ccode = chsc(scpd_area);
        if (ccode > 0) {
@@ -833,8 +679,7 @@ int chsc_determine_channel_path_description(struct chp_id chpid,
        ret = chsc_error_from_response(scpd_area->response.code);
        if (ret == 0)
                /* Success. */
-               memcpy(desc, &scpd_area->desc,
-                      sizeof(struct channel_path_desc));
+               memcpy(resp, &scpd_area->response, scpd_area->response.length);
        else
                CIO_CRW_EVENT(2, "chsc: scpd failed (rc=%04x)\n",
                              scpd_area->response.code);
@@ -842,6 +687,25 @@ out:
        free_page((unsigned long)scpd_area);
        return ret;
 }
+EXPORT_SYMBOL_GPL(chsc_determine_channel_path_desc);
+
+int chsc_determine_base_channel_path_desc(struct chp_id chpid,
+                                         struct channel_path_desc *desc)
+{
+       struct chsc_response_struct *chsc_resp;
+       int ret;
+
+       chsc_resp = kzalloc(sizeof(*chsc_resp), GFP_KERNEL);
+       if (!chsc_resp)
+               return -ENOMEM;
+       ret = chsc_determine_channel_path_desc(chpid, 0, 0, 0, 0, chsc_resp);
+       if (ret)
+               goto out_free;
+       memcpy(desc, &chsc_resp->data, chsc_resp->length);
+out_free:
+       kfree(chsc_resp);
+       return ret;
+}
 
 static void
 chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
@@ -937,15 +801,23 @@ out:
 
 int __init chsc_alloc_sei_area(void)
 {
+       int ret;
+
        sei_page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
-       if (!sei_page)
+       if (!sei_page) {
                CIO_MSG_EVENT(0, "Can't allocate page for processing of "
                              "chsc machine checks!\n");
-       return (sei_page ? 0 : -ENOMEM);
+               return -ENOMEM;
+       }
+       ret = s390_register_crw_handler(CRW_RSC_CSS, chsc_process_crw);
+       if (ret)
+               kfree(sei_page);
+       return ret;
 }
 
 void __init chsc_free_sei_area(void)
 {
+       s390_unregister_crw_handler(CRW_RSC_CSS);
        kfree(sei_page);
 }
 
@@ -1043,3 +915,52 @@ exit:
 
 EXPORT_SYMBOL_GPL(css_general_characteristics);
 EXPORT_SYMBOL_GPL(css_chsc_characteristics);
+
+int chsc_sstpc(void *page, unsigned int op, u16 ctrl)
+{
+       struct {
+               struct chsc_header request;
+               unsigned int rsvd0;
+               unsigned int op : 8;
+               unsigned int rsvd1 : 8;
+               unsigned int ctrl : 16;
+               unsigned int rsvd2[5];
+               struct chsc_header response;
+               unsigned int rsvd3[7];
+       } __attribute__ ((packed)) *rr;
+       int rc;
+
+       memset(page, 0, PAGE_SIZE);
+       rr = page;
+       rr->request.length = 0x0020;
+       rr->request.code = 0x0033;
+       rr->op = op;
+       rr->ctrl = ctrl;
+       rc = chsc(rr);
+       if (rc)
+               return -EIO;
+       rc = (rr->response.code == 0x0001) ? 0 : -EIO;
+       return rc;
+}
+
+int chsc_sstpi(void *page, void *result, size_t size)
+{
+       struct {
+               struct chsc_header request;
+               unsigned int rsvd0[3];
+               struct chsc_header response;
+               char data[size];
+       } __attribute__ ((packed)) *rr;
+       int rc;
+
+       memset(page, 0, PAGE_SIZE);
+       rr = page;
+       rr->request.length = 0x0010;
+       rr->request.code = 0x0038;
+       rc = chsc(rr);
+       if (rc)
+               return -EIO;
+       memcpy(result, &rr->data, size);
+       return (rr->response.code == 0x0001) ? 0 : -EIO;
+}
+
index d1f5db1..fb6c4d6 100644 (file)
@@ -4,7 +4,8 @@
 #include <linux/types.h>
 #include <linux/device.h>
 #include <asm/chpid.h>
-#include "schid.h"
+#include <asm/chsc.h>
+#include <asm/schid.h>
 
 #define CHSC_SDA_OC_MSS   0x2
 
@@ -36,14 +37,15 @@ struct channel_path_desc {
 
 struct channel_path;
 
-extern void chsc_process_crw(void);
-
 struct css_general_char {
-       u64 : 41;
+       u64 : 12;
+       u32 dynio : 1;   /* bit 12 */
+       u32 : 28;
        u32 aif : 1;     /* bit 41 */
        u32 : 3;
        u32 mcss : 1;    /* bit 45 */
-       u32 : 2;
+       u32 fcs : 1;     /* bit 46 */
+       u32 : 1;
        u32 ext_mb : 1;  /* bit 48 */
        u32 : 7;
        u32 aif_tdd : 1; /* bit 56 */
@@ -51,7 +53,11 @@ struct css_general_char {
        u32 qebsm : 1;   /* bit 58 */
        u32 : 8;
        u32 aif_osa : 1; /* bit 67 */
-       u32 : 28;
+       u32 : 14;
+       u32 cib : 1;     /* bit 82 */
+       u32 : 5;
+       u32 fcx : 1;     /* bit 88 */
+       u32 : 7;
 }__attribute__((packed));
 
 struct css_chsc_char {
@@ -78,7 +84,6 @@ struct chsc_ssd_info {
 extern int chsc_get_ssd_info(struct subchannel_id schid,
                             struct chsc_ssd_info *ssd);
 extern int chsc_determine_css_characteristics(void);
-extern int css_characteristics_avail;
 extern int chsc_alloc_sei_area(void);
 extern void chsc_free_sei_area(void);
 
@@ -87,8 +92,11 @@ struct channel_subsystem;
 extern int chsc_secm(struct channel_subsystem *, int);
 
 int chsc_chp_vary(struct chp_id chpid, int on);
-int chsc_determine_channel_path_description(struct chp_id chpid,
-                                           struct channel_path_desc *desc);
+int chsc_determine_channel_path_desc(struct chp_id chpid, int fmt, int rfmt,
+                                    int c, int m,
+                                    struct chsc_response_struct *resp);
+int chsc_determine_base_channel_path_desc(struct chp_id chpid,
+                                         struct channel_path_desc *desc);
 void chsc_chp_online(struct chp_id chpid);
 void chsc_chp_offline(struct chp_id chpid);
 int chsc_get_channel_measurement_chars(struct channel_path *chp);
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
new file mode 100644 (file)
index 0000000..91ca87a
--- /dev/null
@@ -0,0 +1,820 @@
+/*
+ * Driver for s390 chsc subchannels
+ *
+ * Copyright IBM Corp. 2008
+ * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/miscdevice.h>
+
+#include <asm/cio.h>
+#include <asm/chsc.h>
+#include <asm/isc.h>
+
+#include "cio.h"
+#include "cio_debug.h"
+#include "css.h"
+#include "chsc_sch.h"
+#include "ioasm.h"
+
+static debug_info_t *chsc_debug_msg_id;
+static debug_info_t *chsc_debug_log_id;
+
+#define CHSC_MSG(imp, args...) do {                                    \
+               debug_sprintf_event(chsc_debug_msg_id, imp , ##args);   \
+       } while (0)
+
+#define CHSC_LOG(imp, txt) do {                                        \
+               debug_text_event(chsc_debug_log_id, imp , txt); \
+       } while (0)
+
+static void CHSC_LOG_HEX(int level, void *data, int length)
+{
+       while (length > 0) {
+               debug_event(chsc_debug_log_id, level, data, length);
+               length -= chsc_debug_log_id->buf_size;
+               data += chsc_debug_log_id->buf_size;
+       }
+}
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("driver for s390 chsc subchannels");
+MODULE_LICENSE("GPL");
+
+static void chsc_subchannel_irq(struct subchannel *sch)
+{
+       struct chsc_private *private = sch->private;
+       struct chsc_request *request = private->request;
+       struct irb *irb = (struct irb *)__LC_IRB;
+
+       CHSC_LOG(4, "irb");
+       CHSC_LOG_HEX(4, irb, sizeof(*irb));
+       /* Copy irb to provided request and set done. */
+       if (!request) {
+               CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
+                        sch->schid.ssid, sch->schid.sch_no);
+               return;
+       }
+       private->request = NULL;
+       memcpy(&request->irb, irb, sizeof(*irb));
+       stsch(sch->schid, &sch->schib);
+       complete(&request->completion);
+       put_device(&sch->dev);
+}
+
+static int chsc_subchannel_probe(struct subchannel *sch)
+{
+       struct chsc_private *private;
+       int ret;
+
+       CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
+                sch->schid.ssid, sch->schid.sch_no);
+       sch->isc = CHSC_SCH_ISC;
+       private = kzalloc(sizeof(*private), GFP_KERNEL);
+       if (!private)
+               return -ENOMEM;
+       ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
+       if (ret) {
+               CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
+                        sch->schid.ssid, sch->schid.sch_no, ret);
+               kfree(private);
+       } else {
+               sch->private = private;
+               if (sch->dev.uevent_suppress) {
+                       sch->dev.uevent_suppress = 0;
+                       kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
+               }
+       }
+       return ret;
+}
+
+static int chsc_subchannel_remove(struct subchannel *sch)
+{
+       struct chsc_private *private;
+
+       cio_disable_subchannel(sch);
+       private = sch->private;
+       sch->private = NULL;
+       if (private->request) {
+               complete(&private->request->completion);
+               put_device(&sch->dev);
+       }
+       kfree(private);
+       return 0;
+}
+
+static void chsc_subchannel_shutdown(struct subchannel *sch)
+{
+       cio_disable_subchannel(sch);
+}
+
+static struct css_device_id chsc_subchannel_ids[] = {
+       { .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
+       { /* end of list */ },
+};
+MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
+
+static struct css_driver chsc_subchannel_driver = {
+       .owner = THIS_MODULE,
+       .subchannel_type = chsc_subchannel_ids,
+       .irq = chsc_subchannel_irq,
+       .probe = chsc_subchannel_probe,
+       .remove = chsc_subchannel_remove,
+       .shutdown = chsc_subchannel_shutdown,
+       .name = "chsc_subchannel",
+};
+
+static int __init chsc_init_dbfs(void)
+{
+       chsc_debug_msg_id = debug_register("chsc_msg", 16, 1,
+                                          16 * sizeof(long));
+       if (!chsc_debug_msg_id)
+               goto out;
+       debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
+       debug_set_level(chsc_debug_msg_id, 2);
+       chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
+       if (!chsc_debug_log_id)
+               goto out;
+       debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
+       debug_set_level(chsc_debug_log_id, 2);
+       return 0;
+out:
+       if (chsc_debug_msg_id)
+               debug_unregister(chsc_debug_msg_id);
+       return -ENOMEM;
+}
+
+static void chsc_remove_dbfs(void)
+{
+       debug_unregister(chsc_debug_log_id);
+       debug_unregister(chsc_debug_msg_id);
+}
+
+static int __init chsc_init_sch_driver(void)
+{
+       return css_driver_register(&chsc_subchannel_driver);
+}
+
+static void chsc_cleanup_sch_driver(void)
+{
+       css_driver_unregister(&chsc_subchannel_driver);
+}
+
+static DEFINE_SPINLOCK(chsc_lock);
+
+static int chsc_subchannel_match_next_free(struct device *dev, void *data)
+{
+       struct subchannel *sch = to_subchannel(dev);
+
+       return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
+}
+
+static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
+{
+       struct device *dev;
+
+       dev = driver_find_device(&chsc_subchannel_driver.drv,
+                                sch ? &sch->dev : NULL, NULL,
+                                chsc_subchannel_match_next_free);
+       return dev ? to_subchannel(dev) : NULL;
+}
+
+/**
+ * chsc_async() - try to start a chsc request asynchronously
+ * @chsc_area: request to be started
+ * @request: request structure to associate
+ *
+ * Tries to start a chsc request on one of the existing chsc subchannels.
+ * Returns:
+ *  %0 if the request was performed synchronously
+ *  %-EINPROGRESS if the request was successfully started
+ *  %-EBUSY if all chsc subchannels are busy
+ *  %-ENODEV if no chsc subchannels are available
+ * Context:
+ *  interrupts disabled, chsc_lock held
+ */
+static int chsc_async(struct chsc_async_area *chsc_area,
+                     struct chsc_request *request)
+{
+       int cc;
+       struct chsc_private *private;
+       struct subchannel *sch = NULL;
+       int ret = -ENODEV;
+       char dbf[10];
+
+       chsc_area->header.key = PAGE_DEFAULT_KEY;
+       while ((sch = chsc_get_next_subchannel(sch))) {
+               spin_lock(sch->lock);
+               private = sch->private;
+               if (private->request) {
+                       spin_unlock(sch->lock);
+                       ret = -EBUSY;
+                       continue;
+               }
+               chsc_area->header.sid = sch->schid;
+               CHSC_LOG(2, "schid");
+               CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
+               cc = chsc(chsc_area);
+               sprintf(dbf, "cc:%d", cc);
+               CHSC_LOG(2, dbf);
+               switch (cc) {
+               case 0:
+                       ret = 0;
+                       break;
+               case 1:
+                       sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
+                       ret = -EINPROGRESS;
+                       private->request = request;
+                       break;
+               case 2:
+                       ret = -EBUSY;
+                       break;
+               default:
+                       ret = -ENODEV;
+               }
+               spin_unlock(sch->lock);
+               CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
+                        sch->schid.ssid, sch->schid.sch_no, cc);
+               if (ret == -EINPROGRESS)
+                       return -EINPROGRESS;
+               put_device(&sch->dev);
+               if (ret == 0)
+                       return 0;
+       }
+       return ret;
+}
+
+static void chsc_log_command(struct chsc_async_area *chsc_area)
+{
+       char dbf[10];
+
+       sprintf(dbf, "CHSC:%x", chsc_area->header.code);
+       CHSC_LOG(0, dbf);
+       CHSC_LOG_HEX(0, chsc_area, 32);
+}
+
+static int chsc_examine_irb(struct chsc_request *request)
+{
+       int backed_up;
+
+       if (!scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND)
+               return -EIO;
+       backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
+       request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
+       if (scsw_cstat(&request->irb.scsw) == 0)
+               return 0;
+       if (!backed_up)
+               return 0;
+       if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
+               return -EIO;
+       if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
+               return -EPERM;
+       if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
+               return -EAGAIN;
+       if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
+               return -EAGAIN;
+       return -EIO;
+}
+
+static int chsc_ioctl_start(void __user *user_area)
+{
+       struct chsc_request *request;
+       struct chsc_async_area *chsc_area;
+       int ret;
+       char dbf[10];
+
+       if (!css_general_characteristics.dynio)
+               /* It makes no sense to try. */
+               return -EOPNOTSUPP;
+       chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
+       if (!chsc_area)
+               return -ENOMEM;
+       request = kzalloc(sizeof(*request), GFP_KERNEL);
+       if (!request) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       init_completion(&request->completion);
+       if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       chsc_log_command(chsc_area);
+       spin_lock_irq(&chsc_lock);
+       ret = chsc_async(chsc_area, request);
+       spin_unlock_irq(&chsc_lock);
+       if (ret == -EINPROGRESS) {
+               wait_for_completion(&request->completion);
+               ret = chsc_examine_irb(request);
+       }
+       /* copy area back to user */
+       if (!ret)
+               if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
+                       ret = -EFAULT;
+out_free:
+       sprintf(dbf, "ret:%d", ret);
+       CHSC_LOG(0, dbf);
+       kfree(request);
+       free_page((unsigned long)chsc_area);
+       return ret;
+}
+
+static int chsc_ioctl_info_channel_path(void __user *user_cd)
+{
+       struct chsc_chp_cd *cd;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 : 2;
+               u32 m : 1;
+               u32 : 1;
+               u32 fmt1 : 4;
+               u32 cssid : 8;
+               u32 : 8;
+               u32 first_chpid : 8;
+               u32 : 24;
+               u32 last_chpid : 8;
+               u32 : 32;
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 20];
+       } __attribute__ ((packed)) *scpcd_area;
+
+       scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!scpcd_area)
+               return -ENOMEM;
+       cd = kzalloc(sizeof(*cd), GFP_KERNEL);
+       if (!cd) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(cd, user_cd, sizeof(*cd))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       scpcd_area->request.length = 0x0010;
+       scpcd_area->request.code = 0x0028;
+       scpcd_area->m = cd->m;
+       scpcd_area->fmt1 = cd->fmt;
+       scpcd_area->cssid = cd->chpid.cssid;
+       scpcd_area->first_chpid = cd->chpid.id;
+       scpcd_area->last_chpid = cd->chpid.id;
+
+       ccode = chsc(scpcd_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (scpcd_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "scpcd: response code=%x\n",
+                        scpcd_area->response.code);
+               goto out_free;
+       }
+       memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
+       if (copy_to_user(user_cd, cd, sizeof(*cd)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(cd);
+       free_page((unsigned long)scpcd_area);
+       return ret;
+}
+
+static int chsc_ioctl_info_cu(void __user *user_cd)
+{
+       struct chsc_cu_cd *cd;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 : 2;
+               u32 m : 1;
+               u32 : 1;
+               u32 fmt1 : 4;
+               u32 cssid : 8;
+               u32 : 8;
+               u32 first_cun : 8;
+               u32 : 24;
+               u32 last_cun : 8;
+               u32 : 32;
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 20];
+       } __attribute__ ((packed)) *scucd_area;
+
+       scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!scucd_area)
+               return -ENOMEM;
+       cd = kzalloc(sizeof(*cd), GFP_KERNEL);
+       if (!cd) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(cd, user_cd, sizeof(*cd))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       scucd_area->request.length = 0x0010;
+       scucd_area->request.code = 0x0028;
+       scucd_area->m = cd->m;
+       scucd_area->fmt1 = cd->fmt;
+       scucd_area->cssid = cd->cssid;
+       scucd_area->first_cun = cd->cun;
+       scucd_area->last_cun = cd->cun;
+
+       ccode = chsc(scucd_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (scucd_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "scucd: response code=%x\n",
+                        scucd_area->response.code);
+               goto out_free;
+       }
+       memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
+       if (copy_to_user(user_cd, cd, sizeof(*cd)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(cd);
+       free_page((unsigned long)scucd_area);
+       return ret;
+}
+
+static int chsc_ioctl_info_sch_cu(void __user *user_cud)
+{
+       struct chsc_sch_cud *cud;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 : 2;
+               u32 m : 1;
+               u32 : 5;
+               u32 fmt1 : 4;
+               u32 : 2;
+               u32 ssid : 2;
+               u32 first_sch : 16;
+               u32 : 8;
+               u32 cssid : 8;
+               u32 last_sch : 16;
+               u32 : 32;
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 20];
+       } __attribute__ ((packed)) *sscud_area;
+
+       sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sscud_area)
+               return -ENOMEM;
+       cud = kzalloc(sizeof(*cud), GFP_KERNEL);
+       if (!cud) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(cud, user_cud, sizeof(*cud))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       sscud_area->request.length = 0x0010;
+       sscud_area->request.code = 0x0006;
+       sscud_area->m = cud->schid.m;
+       sscud_area->fmt1 = cud->fmt;
+       sscud_area->ssid = cud->schid.ssid;
+       sscud_area->first_sch = cud->schid.sch_no;
+       sscud_area->cssid = cud->schid.cssid;
+       sscud_area->last_sch = cud->schid.sch_no;
+
+       ccode = chsc(sscud_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (sscud_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "sscud: response code=%x\n",
+                        sscud_area->response.code);
+               goto out_free;
+       }
+       memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
+       if (copy_to_user(user_cud, cud, sizeof(*cud)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(cud);
+       free_page((unsigned long)sscud_area);
+       return ret;
+}
+
+static int chsc_ioctl_conf_info(void __user *user_ci)
+{
+       struct chsc_conf_info *ci;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 : 2;
+               u32 m : 1;
+               u32 : 1;
+               u32 fmt1 : 4;
+               u32 cssid : 8;
+               u32 : 6;
+               u32 ssid : 2;
+               u32 : 8;
+               u64 : 64;
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 20];
+       } __attribute__ ((packed)) *sci_area;
+
+       sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sci_area)
+               return -ENOMEM;
+       ci = kzalloc(sizeof(*ci), GFP_KERNEL);
+       if (!ci) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(ci, user_ci, sizeof(*ci))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       sci_area->request.length = 0x0010;
+       sci_area->request.code = 0x0012;
+       sci_area->m = ci->id.m;
+       sci_area->fmt1 = ci->fmt;
+       sci_area->cssid = ci->id.cssid;
+       sci_area->ssid = ci->id.ssid;
+
+       ccode = chsc(sci_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (sci_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "sci: response code=%x\n",
+                        sci_area->response.code);
+               goto out_free;
+       }
+       memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
+       if (copy_to_user(user_ci, ci, sizeof(*ci)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(ci);
+       free_page((unsigned long)sci_area);
+       return ret;
+}
+
+static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
+{
+       struct chsc_comp_list *ccl;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 ctype : 8;
+               u32 : 4;
+               u32 fmt : 4;
+               u32 : 16;
+               u64 : 64;
+               u32 list_parm[2];
+               u64 : 64;
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 36];
+       } __attribute__ ((packed)) *sccl_area;
+       struct {
+               u32 m : 1;
+               u32 : 31;
+               u32 cssid : 8;
+               u32 : 16;
+               u32 chpid : 8;
+       } __attribute__ ((packed)) *chpid_parm;
+       struct {
+               u32 f_cssid : 8;
+               u32 l_cssid : 8;
+               u32 : 16;
+               u32 res;
+       } __attribute__ ((packed)) *cssids_parm;
+
+       sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sccl_area)
+               return -ENOMEM;
+       ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
+       if (!ccl) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       sccl_area->request.length = 0x0020;
+       sccl_area->request.code = 0x0030;
+       sccl_area->fmt = ccl->req.fmt;
+       sccl_area->ctype = ccl->req.ctype;
+       switch (sccl_area->ctype) {
+       case CCL_CU_ON_CHP:
+       case CCL_IOP_CHP:
+               chpid_parm = (void *)&sccl_area->list_parm;
+               chpid_parm->m = ccl->req.chpid.m;
+               chpid_parm->cssid = ccl->req.chpid.chp.cssid;
+               chpid_parm->chpid = ccl->req.chpid.chp.id;
+               break;
+       case CCL_CSS_IMG:
+       case CCL_CSS_IMG_CONF_CHAR:
+               cssids_parm = (void *)&sccl_area->list_parm;
+               cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
+               cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
+               break;
+       }
+       ccode = chsc(sccl_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (sccl_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "sccl: response code=%x\n",
+                        sccl_area->response.code);
+               goto out_free;
+       }
+       memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
+       if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(ccl);
+       free_page((unsigned long)sccl_area);
+       return ret;
+}
+
+static int chsc_ioctl_chpd(void __user *user_chpd)
+{
+       struct chsc_cpd_info *chpd;
+       int ret;
+
+       chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
+       if (!chpd)
+               return -ENOMEM;
+       if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
+                                              chpd->rfmt, chpd->c, chpd->m,
+                                              &chpd->chpdb);
+       if (ret)
+               goto out_free;
+       if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
+               ret = -EFAULT;
+out_free:
+       kfree(chpd);
+       return ret;
+}
+
+static int chsc_ioctl_dcal(void __user *user_dcal)
+{
+       struct chsc_dcal *dcal;
+       int ret, ccode;
+       struct {
+               struct chsc_header request;
+               u32 atype : 8;
+               u32 : 4;
+               u32 fmt : 4;
+               u32 : 16;
+               u32 res0[2];
+               u32 list_parm[2];
+               u32 res1[2];
+               struct chsc_header response;
+               u8 data[PAGE_SIZE - 36];
+       } __attribute__ ((packed)) *sdcal_area;
+
+       sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
+       if (!sdcal_area)
+               return -ENOMEM;
+       dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
+       if (!dcal) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+       if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
+               ret = -EFAULT;
+               goto out_free;
+       }
+       sdcal_area->request.length = 0x0020;
+       sdcal_area->request.code = 0x0034;
+       sdcal_area->atype = dcal->req.atype;
+       sdcal_area->fmt = dcal->req.fmt;
+       memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
+              sizeof(sdcal_area->list_parm));
+
+       ccode = chsc(sdcal_area);
+       if (ccode != 0) {
+               ret = -EIO;
+               goto out_free;
+       }
+       if (sdcal_area->response.code != 0x0001) {
+               ret = -EIO;
+               CHSC_MSG(0, "sdcal: response code=%x\n",
+                        sdcal_area->response.code);
+               goto out_free;
+       }
+       memcpy(&dcal->sdcal, &sdcal_area->response,
+              sdcal_area->response.length);
+       if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
+               ret = -EFAULT;
+       else
+               ret = 0;
+out_free:
+       kfree(dcal);
+       free_page((unsigned long)sdcal_area);
+       return ret;
+}
+
+static long chsc_ioctl(struct file *filp, unsigned int cmd,
+                      unsigned long arg)
+{
+       CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
+       switch (cmd) {
+       case CHSC_START:
+               return chsc_ioctl_start((void __user *)arg);
+       case CHSC_INFO_CHANNEL_PATH:
+               return chsc_ioctl_info_channel_path((void __user *)arg);
+       case CHSC_INFO_CU:
+               return chsc_ioctl_info_cu((void __user *)arg);
+       case CHSC_INFO_SCH_CU:
+               return chsc_ioctl_info_sch_cu((void __user *)arg);
+       case CHSC_INFO_CI:
+               return chsc_ioctl_conf_info((void __user *)arg);
+       case CHSC_INFO_CCL:
+               return chsc_ioctl_conf_comp_list((void __user *)arg);
+       case CHSC_INFO_CPD:
+               return chsc_ioctl_chpd((void __user *)arg);
+       case CHSC_INFO_DCAL:
+               return chsc_ioctl_dcal((void __user *)arg);
+       default: /* unknown ioctl number */
+               return -ENOIOCTLCMD;
+       }
+}
+
+static const struct file_operations chsc_fops = {
+       .owner = THIS_MODULE,
+       .unlocked_ioctl = chsc_ioctl,
+       .compat_ioctl = chsc_ioctl,
+};
+
+static struct miscdevice chsc_misc_device = {
+       .minor = MISC_DYNAMIC_MINOR,
+       .name = "chsc",
+       .fops = &chsc_fops,
+};
+
+static int __init chsc_misc_init(void)
+{
+       return misc_register(&chsc_misc_device);
+}
+
+static void chsc_misc_cleanup(void)
+{
+       misc_deregister(&chsc_misc_device);
+}
+
+static int __init chsc_sch_init(void)
+{
+       int ret;
+
+       ret = chsc_init_dbfs();
+       if (ret)
+               return ret;
+       isc_register(CHSC_SCH_ISC);
+       ret = chsc_init_sch_driver();
+       if (ret)
+               goto out_dbf;
+       ret = chsc_misc_init();
+       if (ret)
+               goto out_driver;
+       return ret;
+out_driver:
+       chsc_cleanup_sch_driver();
+out_dbf:
+       isc_unregister(CHSC_SCH_ISC);
+       chsc_remove_dbfs();
+       return ret;
+}
+
+static void __exit chsc_sch_exit(void)
+{
+       chsc_misc_cleanup();
+       chsc_cleanup_sch_driver();
+       isc_unregister(CHSC_SCH_ISC);
+       chsc_remove_dbfs();
+}
+
+module_init(chsc_sch_init);
+module_exit(chsc_sch_exit);
diff --git a/drivers/s390/cio/chsc_sch.h b/drivers/s390/cio/chsc_sch.h
new file mode 100644 (file)
index 0000000..589ebfa
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _CHSC_SCH_H
+#define _CHSC_SCH_H
+
+struct chsc_request {
+       struct completion completion;
+       struct irb irb;
+};
+
+struct chsc_private {
+       struct chsc_request *request;
+};
+
+#endif
index b32d7eb..33bff8f 100644 (file)
@@ -2,7 +2,7 @@
  *  drivers/s390/cio/cio.c
  *   S/390 common I/O routines -- low level i/o calls
  *
- *    Copyright (C) IBM Corp. 1999,2006
+ *    Copyright IBM Corp. 1999,2008
  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
  *              Cornelia Huck (cornelia.huck@de.ibm.com)
  *              Arnd Bergmann (arndb@de.ibm.com)
@@ -24,7 +24,9 @@
 #include <asm/ipl.h>
 #include <asm/chpid.h>
 #include <asm/airq.h>
+#include <asm/isc.h>
 #include <asm/cpu.h>
+#include <asm/fcx.h>
 #include "cio.h"
 #include "css.h"
 #include "chsc.h"
@@ -72,7 +74,6 @@ out_unregister:
                debug_unregister(cio_debug_trace_id);
        if (cio_debug_crw_id)
                debug_unregister(cio_debug_crw_id);
-       printk(KERN_WARNING"cio: could not initialize debugging\n");
        return -1;
 }
 
@@ -128,7 +129,7 @@ cio_tpi(void)
        local_bh_disable();
        irq_enter ();
        spin_lock(sch->lock);
-       memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
+       memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
        if (sch->driver && sch->driver->irq)
                sch->driver->irq(sch);
        spin_unlock(sch->lock);
@@ -167,30 +168,30 @@ cio_start_key (struct subchannel *sch,    /* subchannel structure */
 {
        char dbf_txt[15];
        int ccode;
-       struct orb *orb;
+       union orb *orb;
 
        CIO_TRACE_EVENT(4, "stIO");
        CIO_TRACE_EVENT(4, sch->dev.bus_id);
 
        orb = &to_io_private(sch)->orb;
        /* sch is always under 2G. */
-       orb->intparm = (u32)(addr_t)sch;
-       orb->fmt = 1;
+       orb->cmd.intparm = (u32)(addr_t)sch;
+       orb->cmd.fmt = 1;
 
-       orb->pfch = sch->options.prefetch == 0;
-       orb->spnd = sch->options.suspend;
-       orb->ssic = sch->options.suspend && sch->options.inter;
-       orb->lpm = (lpm != 0) ? lpm : sch->lpm;
+       orb->cmd.pfch = sch->options.prefetch == 0;
+       orb->cmd.spnd = sch->options.suspend;
+       orb->cmd.ssic = sch->options.suspend && sch->options.inter;
+       orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
 #ifdef CONFIG_64BIT
        /*
         * for 64 bit we always support 64 bit IDAWs with 4k page size only
         */
-       orb->c64 = 1;
-       orb->i2k = 0;
+       orb->cmd.c64 = 1;
+       orb->cmd.i2k = 0;
 #endif
-       orb->key = key >> 4;
+       orb->cmd.key = key >> 4;
        /* issue "Start Subchannel" */
-       orb->cpa = (__u32) __pa(cpa);
+       orb->cmd.cpa = (__u32) __pa(cpa);
        ccode = ssch(sch->schid, orb);
 
        /* process condition code */
@@ -202,7 +203,7 @@ cio_start_key (struct subchannel *sch,      /* subchannel structure */
                /*
                 * initialize device status information
                 */
-               sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
+               sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
                return 0;
        case 1:         /* status pending */
        case 2:         /* busy */
@@ -237,7 +238,7 @@ cio_resume (struct subchannel *sch)
 
        switch (ccode) {
        case 0:
-               sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
+               sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
                return 0;
        case 1:
                return -EBUSY;
@@ -277,7 +278,7 @@ cio_halt(struct subchannel *sch)
 
        switch (ccode) {
        case 0:
-               sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
+               sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
                return 0;
        case 1:         /* status pending */
        case 2:         /* busy */
@@ -312,7 +313,7 @@ cio_clear(struct subchannel *sch)
 
        switch (ccode) {
        case 0:
-               sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
+               sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
                return 0;
        default:                /* device not operational */
                return -ENODEV;
@@ -387,8 +388,10 @@ cio_modify (struct subchannel *sch)
        return ret;
 }
 
-/*
- * Enable subchannel.
+/**
+ * cio_enable_subchannel - enable a subchannel.
+ * @sch: subchannel to be enabled
+ * @intparm: interruption parameter to set
  */
 int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
 {
@@ -434,12 +437,13 @@ int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
        CIO_TRACE_EVENT (2, dbf_txt);
        return ret;
 }
+EXPORT_SYMBOL_GPL(cio_enable_subchannel);
 
-/*
- * Disable subchannel.
+/**
+ * cio_disable_subchannel - disable a subchannel.
+ * @sch: subchannel to disable
  */
-int
-cio_disable_subchannel (struct subchannel *sch)
+int cio_disable_subchannel(struct subchannel *sch)
 {
        char dbf_txt[15];
        int ccode;
@@ -455,7 +459,7 @@ cio_disable_subchannel (struct subchannel *sch)
        if (ccode == 3)         /* Not operational. */
                return -ENODEV;
 
-       if (sch->schib.scsw.actl != 0)
+       if (scsw_actl(&sch->schib.scsw) != 0)
                /*
                 * the disable function must not be called while there are
                 *  requests pending for completion !
@@ -484,6 +488,7 @@ cio_disable_subchannel (struct subchannel *sch)
        CIO_TRACE_EVENT (2, dbf_txt);
        return ret;
 }
+EXPORT_SYMBOL_GPL(cio_disable_subchannel);
 
 int cio_create_sch_lock(struct subchannel *sch)
 {
@@ -494,27 +499,61 @@ int cio_create_sch_lock(struct subchannel *sch)
        return 0;
 }
 
-/*
- * cio_validate_subchannel()
+static int cio_check_devno_blacklisted(struct subchannel *sch)
+{
+       if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
+               /*
+                * This device must not be known to Linux. So we simply
+                * say that there is no device and return ENODEV.
+                */
+               CIO_MSG_EVENT(6, "Blacklisted device detected "
+                             "at devno %04X, subchannel set %x\n",
+                             sch->schib.pmcw.dev, sch->schid.ssid);
+               return -ENODEV;
+       }
+       return 0;
+}
+
+static int cio_validate_io_subchannel(struct subchannel *sch)
+{
+       /* Initialization for io subchannels. */
+       if (!css_sch_is_valid(&sch->schib))
+               return -ENODEV;
+
+       /* Devno is valid. */
+       return cio_check_devno_blacklisted(sch);
+}
+
+static int cio_validate_msg_subchannel(struct subchannel *sch)
+{
+       /* Initialization for message subchannels. */
+       if (!css_sch_is_valid(&sch->schib))
+               return -ENODEV;
+
+       /* Devno is valid. */
+       return cio_check_devno_blacklisted(sch);
+}
+
+/**
+ * cio_validate_subchannel - basic validation of subchannel
+ * @sch: subchannel structure to be filled out
+ * @schid: subchannel id
  *
  * Find out subchannel type and initialize struct subchannel.
  * Return codes:
- *   SUBCHANNEL_TYPE_IO for a normal io subchannel
- *   SUBCHANNEL_TYPE_CHSC for a chsc subchannel
- *   SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
- *   SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
+ *   0 on success
  *   -ENXIO for non-defined subchannels
- *   -ENODEV for subchannels with invalid device number or blacklisted devices
+ *   -ENODEV for invalid subchannels or blacklisted devices
+ *   -EIO for subchannels in an invalid subchannel set
  */
-int
-cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
+int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
 {
        char dbf_txt[15];
        int ccode;
        int err;
 
-       sprintf (dbf_txt, "valsch%x", schid.sch_no);
-       CIO_TRACE_EVENT (4, dbf_txt);
+       sprintf(dbf_txt, "valsch%x", schid.sch_no);
+       CIO_TRACE_EVENT(4, dbf_txt);
 
        /* Nuke all fields. */
        memset(sch, 0, sizeof(struct subchannel));
@@ -546,67 +585,21 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
        /* Copy subchannel type from path management control word. */
        sch->st = sch->schib.pmcw.st;
 
-       /*
-        * ... just being curious we check for non I/O subchannels
-        */
-       if (sch->st != 0) {
-               CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports "
-                             "non-I/O subchannel type %04X\n",
-                             sch->schid.ssid, sch->schid.sch_no, sch->st);
-               /* We stop here for non-io subchannels. */
-               err = sch->st;
-               goto out;
-       }
-
-       /* Initialization for io subchannels. */
-       if (!css_sch_is_valid(&sch->schib)) {
-               err = -ENODEV;
-               goto out;
+       switch (sch->st) {
+       case SUBCHANNEL_TYPE_IO:
+               err = cio_validate_io_subchannel(sch);
+               break;
+       case SUBCHANNEL_TYPE_MSG:
+               err = cio_validate_msg_subchannel(sch);
+               break;
+       default:
+               err = 0;
        }
-
-       /* Devno is valid. */
-       if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
-               /*
-                * This device must not be known to Linux. So we simply
-                * say that there is no device and return ENODEV.
-                */
-               CIO_MSG_EVENT(6, "Blacklisted device detected "
-                             "at devno %04X, subchannel set %x\n",
-                             sch->schib.pmcw.dev, sch->schid.ssid);
-               err = -ENODEV;
+       if (err)
                goto out;
-       }
-       if (cio_is_console(sch->schid)) {
-               sch->opm = 0xff;
-               sch->isc = 1;
-       } else {
-               sch->opm = chp_get_sch_opm(sch);
-               sch->isc = 3;
-       }
-       sch->lpm = sch->schib.pmcw.pam & sch->opm;
-
-       CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X "
-                     "- PIM = %02X, PAM = %02X, POM = %02X\n",
-                     sch->schib.pmcw.dev, sch->schid.ssid,
-                     sch->schid.sch_no, sch->schib.pmcw.pim,
-                     sch->schib.pmcw.pam, sch->schib.pmcw.pom);
 
-       /*
-        * We now have to initially ...
-        *  ... enable "concurrent sense"
-        *  ... enable "multipath mode" if more than one
-        *        CHPID is available. This is done regardless
-        *        whether multiple paths are available for us.
-        */
-       sch->schib.pmcw.csense = 1;     /* concurrent sense */
-       sch->schib.pmcw.ena = 0;
-       if ((sch->lpm & (sch->lpm - 1)) != 0)
-               sch->schib.pmcw.mp = 1; /* multipath mode */
-       /* clean up possible residual cmf stuff */
-       sch->schib.pmcw.mme = 0;
-       sch->schib.pmcw.mbfc = 0;
-       sch->schib.pmcw.mbi = 0;
-       sch->schib.mba = 0;
+       CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
+                     sch->schid.ssid, sch->schid.sch_no, sch->st);
        return 0;
 out:
        if (!cio_is_console(schid))
@@ -647,7 +640,7 @@ do_IRQ (struct pt_regs *regs)
                 */
                if (tpi_info->adapter_IO == 1 &&
                    tpi_info->int_type == IO_INTERRUPT_TYPE) {
-                       do_adapter_IO();
+                       do_adapter_IO(tpi_info->isc);
                        continue;
                }
                sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
@@ -706,9 +699,9 @@ void wait_cons_dev(void)
        if (!console_subchannel_in_use)
                return;
 
-       /* disable all but isc 1 (console device) */
+       /* disable all but the console isc */
        __ctl_store (save_cr6, 6, 6);
-       cr6 = 0x40000000;
+       cr6 = 1UL << (31 - CONSOLE_ISC);
        __ctl_load (cr6, 6, 6);
 
        do {
@@ -716,7 +709,7 @@ void wait_cons_dev(void)
                if (!cio_tpi())
                        cpu_relax();
                spin_lock(console_subchannel.lock);
-       } while (console_subchannel.schib.scsw.actl != 0);
+       } while (console_subchannel.schib.scsw.cmd.actl != 0);
        /*
         * restore previous isc value
         */
@@ -761,7 +754,6 @@ cio_get_console_sch_no(void)
                /* unlike in 2.4, we cannot autoprobe here, since
                 * the channel subsystem is not fully initialized.
                 * With some luck, the HWC console can take over */
-               printk(KERN_WARNING "cio: No ccw console found!\n");
                return -1;
        }
        return console_irq;
@@ -778,6 +770,7 @@ cio_probe_console(void)
        sch_no = cio_get_console_sch_no();
        if (sch_no == -1) {
                console_subchannel_in_use = 0;
+               printk(KERN_WARNING "cio: No ccw console found!\n");
                return ERR_PTR(-ENODEV);
        }
        memset(&console_subchannel, 0, sizeof(struct subchannel));
@@ -790,15 +783,15 @@ cio_probe_console(void)
        }
 
        /*
-        * enable console I/O-interrupt subclass 1
+        * enable console I/O-interrupt subclass
         */
-       ctl_set_bit(6, 30);
-       console_subchannel.isc = 1;
-       console_subchannel.schib.pmcw.isc = 1;
+       isc_register(CONSOLE_ISC);
+       console_subchannel.schib.pmcw.isc = CONSOLE_ISC;
        console_subchannel.schib.pmcw.intparm =
                (u32)(addr_t)&console_subchannel;
        ret = cio_modify(&console_subchannel);
        if (ret) {
+               isc_unregister(CONSOLE_ISC);
                console_subchannel_in_use = 0;
                return ERR_PTR(ret);
        }
@@ -810,7 +803,7 @@ cio_release_console(void)
 {
        console_subchannel.schib.pmcw.intparm = 0;
        cio_modify(&console_subchannel);
-       ctl_clear_bit(6, 24);
+       isc_unregister(CONSOLE_ISC);
        console_subchannel_in_use = 0;
 }
 
@@ -864,7 +857,7 @@ static void udelay_reset(unsigned long usecs)
 }
 
 static int
-__clear_subchannel_easy(struct subchannel_id schid)
+__clear_io_subchannel_easy(struct subchannel_id schid)
 {
        int retry;
 
@@ -883,6 +876,12 @@ __clear_subchannel_easy(struct subchannel_id schid)
        return -EBUSY;
 }
 
+static void __clear_chsc_subchannel_easy(void)
+{
+       /* It seems we can only wait for a bit here :/ */
+       udelay_reset(100);
+}
+
 static int pgm_check_occured;
 
 static void cio_reset_pgm_check_handler(void)
@@ -921,11 +920,22 @@ static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
        case -ENODEV:
                break;
        default: /* -EBUSY */
-               if (__clear_subchannel_easy(schid))
-                       break; /* give up... */
+               switch (schib.pmcw.st) {
+               case SUBCHANNEL_TYPE_IO:
+                       if (__clear_io_subchannel_easy(schid))
+                               goto out; /* give up... */
+                       break;
+               case SUBCHANNEL_TYPE_CHSC:
+                       __clear_chsc_subchannel_easy();
+                       break;
+               default:
+                       /* No default clear strategy */
+                       break;
+               }
                stsch(schid, &schib);
                __disable_subchannel_easy(schid, &schib);
        }
+out:
        return 0;
 }
 
@@ -1068,3 +1078,61 @@ int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
        iplinfo->is_qdio = schib.pmcw.qf;
        return 0;
 }
+
+/**
+ * cio_tm_start_key - perform start function
+ * @sch: subchannel on which to perform the start function
+ * @tcw: transport-command word to be started
+ * @lpm: mask of paths to use
+ * @key: storage key to use for storage access
+ *
+ * Start the tcw on the given subchannel. Return zero on success, non-zero
+ * otherwise.
+ */
+int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
+{
+       int cc;
+       union orb *orb = &to_io_private(sch)->orb;
+
+       memset(orb, 0, sizeof(union orb));
+       orb->tm.intparm = (u32) (addr_t) sch;
+       orb->tm.key = key >> 4;
+       orb->tm.b = 1;
+       orb->tm.lpm = lpm ? lpm : sch->lpm;
+       orb->tm.tcw = (u32) (addr_t) tcw;
+       cc = ssch(sch->schid, orb);
+       switch (cc) {
+       case 0:
+               return 0;
+       case 1:
+       case 2:
+               return -EBUSY;
+       default:
+               return cio_start_handle_notoper(sch, lpm);
+       }
+}
+
+/**
+ * cio_tm_intrg - perform interrogate function
+ * @sch - subchannel on which to perform the interrogate function
+ *
+ * If the specified subchannel is running in transport-mode, perform the
+ * interrogate function. Return zero on success, non-zero otherwie.
+ */
+int cio_tm_intrg(struct subchannel *sch)
+{
+       int cc;
+
+       if (!to_io_private(sch)->orb.tm.b)
+               return -EINVAL;
+       cc = xsch(sch->schid);
+       switch (cc) {
+       case 0:
+       case 2:
+               return 0;
+       case 1:
+               return -EBUSY;
+       default:
+               return -ENODEV;
+       }
+}
index 6e933ae..3b236d2 100644 (file)
@@ -3,9 +3,12 @@
 
 #include <linux/mutex.h>
 #include <linux/device.h>
+#include <linux/mod_devicetable.h>
 #include <asm/chpid.h>
+#include <asm/cio.h>
+#include <asm/fcx.h>
+#include <asm/schid.h>
 #include "chsc.h"
-#include "schid.h"
 
 /*
  * path management control word
@@ -13,7 +16,7 @@
 struct pmcw {
        u32 intparm;            /* interruption parameter */
        u32 qf   : 1;           /* qdio facility */
-       u32 res0 : 1;           /* reserved zeros */
+       u32 w    : 1;
        u32 isc  : 3;           /* interruption sublass */
        u32 res5 : 3;           /* reserved zeros */
        u32 ena  : 1;           /* enabled */
@@ -47,7 +50,7 @@ struct pmcw {
  */
 struct schib {
        struct pmcw pmcw;        /* path management control word */
-       struct scsw scsw;        /* subchannel status word */
+       union scsw scsw;         /* subchannel status word */
        __u64 mba;               /* measurement block address */
        __u8 mda[4];             /* model dependent area */
 } __attribute__ ((packed,aligned(4)));
@@ -99,8 +102,11 @@ extern int cio_set_options (struct subchannel *, int);
 extern int cio_get_options (struct subchannel *);
 extern int cio_modify (struct subchannel *);
 
+int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key);
+int cio_tm_intrg(struct subchannel *sch);
+
 int cio_create_sch_lock(struct subchannel *);
-void do_adapter_IO(void);
+void do_adapter_IO(u8 isc);
 void do_IRQ(struct pt_regs *);
 
 /* Use with care. */
index 2808b68..a90b28c 100644 (file)
@@ -341,12 +341,12 @@ static int cmf_copy_block(struct ccw_device *cdev)
        if (stsch(sch->schid, &sch->schib))
                return -ENODEV;
 
-       if (sch->schib.scsw.fctl & SCSW_FCTL_START_FUNC) {
+       if (scsw_fctl(&sch->schib.scsw) & SCSW_FCTL_START_FUNC) {
                /* Don't copy if a start function is in progress. */
-               if ((!(sch->schib.scsw.actl & SCSW_ACTL_SUSPENDED)) &&
-                   (sch->schib.scsw.actl &
+               if ((!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_SUSPENDED)) &&
+                   (scsw_actl(&sch->schib.scsw) &
                     (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) &&
-                   (!(sch->schib.scsw.stctl & SCSW_STCTL_SEC_STATUS)))
+                   (!(scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_SEC_STATUS)))
                        return -EBUSY;
        }
        cmb_data = cdev->private->cmb;
@@ -612,9 +612,6 @@ static int alloc_cmb(struct ccw_device *cdev)
                        free_pages((unsigned long)mem, get_order(size));
                } else if (!mem) {
                        /* no luck */
-                       printk(KERN_WARNING "cio: failed to allocate area "
-                              "for measuring %d subchannels\n",
-                              cmb_area.num_channels);
                        ret = -ENOMEM;
                        goto out;
                } else {
@@ -1230,13 +1227,9 @@ static ssize_t cmb_enable_store(struct device *dev,
        switch (val) {
        case 0:
                ret = disable_cmf(cdev);
-               if (ret)
-                       dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret);
                break;
        case 1:
                ret = enable_cmf(cdev);
-               if (ret && ret != -EBUSY)
-                       dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret);
                break;
        }
 
@@ -1344,8 +1337,7 @@ static int __init init_cmf(void)
         * to basic mode.
         */
        if (format == CMF_AUTODETECT) {
-               if (!css_characteristics_avail ||
-                   !css_general_characteristics.ext_mb) {
+               if (!css_general_characteristics.ext_mb) {
                        format = CMF_BASIC;
                } else {
                        format = CMF_EXTENDED;
@@ -1365,8 +1357,6 @@ static int __init init_cmf(void)
                cmbops = &cmbops_extended;
                break;
        default:
-               printk(KERN_ERR "cio: Invalid format %d for channel "
-                       "measurement facility\n", format);
                return 1;
        }
 
index a769565..46c021d 100644 (file)
@@ -2,8 +2,7 @@
  *  drivers/s390/cio/css.c
  *  driver for channel subsystem
  *
- *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
- *                      IBM Corporation
+ *    Copyright IBM Corp. 2002,2008
  *    Author(s): Arnd Bergmann (arndb@de.ibm.com)
  *              Cornelia Huck (cornelia.huck@de.ibm.com)
  */
@@ -14,7 +13,9 @@
 #include <linux/errno.h>
 #include <linux/list.h>
 #include <linux/reboot.h>
+#include <asm/isc.h>
 
+#include "../s390mach.h"
 #include "css.h"
 #include "cio.h"
 #include "cio_debug.h"
@@ -30,8 +31,6 @@ static int max_ssid = 0;
 
 struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
 
-int css_characteristics_avail = 0;
-
 int
 for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
 {
@@ -121,25 +120,6 @@ css_alloc_subchannel(struct subchannel_id schid)
                kfree(sch);
                return ERR_PTR(ret);
        }
-
-       if (sch->st != SUBCHANNEL_TYPE_IO) {
-               /* For now we ignore all non-io subchannels. */
-               kfree(sch);
-               return ERR_PTR(-EINVAL);
-       }
-
-       /* 
-        * Set intparm to subchannel address.
-        * This is fine even on 64bit since the subchannel is always located
-        * under 2G.
-        */
-       sch->schib.pmcw.intparm = (u32)(addr_t)sch;
-       ret = cio_modify(sch);
-       if (ret) {
-               kfree(sch->lock);
-               kfree(sch);
-               return ERR_PTR(ret);
-       }
        return sch;
 }
 
@@ -177,12 +157,18 @@ static int css_sch_device_register(struct subchannel *sch)
        return ret;
 }
 
+/**
+ * css_sch_device_unregister - unregister a subchannel
+ * @sch: subchannel to be unregistered
+ */
 void css_sch_device_unregister(struct subchannel *sch)
 {
        mutex_lock(&sch->reg_mutex);
-       device_unregister(&sch->dev);
+       if (device_is_registered(&sch->dev))
+               device_unregister(&sch->dev);
        mutex_unlock(&sch->reg_mutex);
 }
+EXPORT_SYMBOL_GPL(css_sch_device_unregister);
 
 static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
 {
@@ -229,6 +215,41 @@ void css_update_ssd_info(struct subchannel *sch)
        }
 }
 
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct subchannel *sch = to_subchannel(dev);
+
+       return sprintf(buf, "%01x\n", sch->st);
+}
+
+static DEVICE_ATTR(type, 0444, type_show, NULL);
+
+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct subchannel *sch = to_subchannel(dev);
+
+       return sprintf(buf, "css:t%01X\n", sch->st);
+}
+
+static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
+
+static struct attribute *subch_attrs[] = {
+       &dev_attr_type.attr,
+       &dev_attr_modalias.attr,
+       NULL,
+};
+
+static struct attribute_group subch_attr_group = {
+       .attrs = subch_attrs,
+};
+
+static struct attribute_group *default_subch_attr_groups[] = {
+       &subch_attr_group,
+       NULL,
+};
+
 static int css_register_subchannel(struct subchannel *sch)
 {
        int ret;
@@ -237,16 +258,17 @@ static int css_register_subchannel(struct subchannel *sch)
        sch->dev.parent = &channel_subsystems[0]->device;
        sch->dev.bus = &css_bus_type;
        sch->dev.release = &css_subchannel_release;
-       sch->dev.groups = subch_attr_groups;
+       sch->dev.groups = default_subch_attr_groups;
        /*
         * We don't want to generate uevents for I/O subchannels that don't
         * have a working ccw device behind them since they will be
         * unregistered before they can be used anyway, so we delay the add
         * uevent until after device recognition was successful.
+        * Note that we suppress the uevent for all subchannel types;
+        * the subchannel driver can decide itself when it wants to inform
+        * userspace of its existence.
         */
-       if (!cio_is_console(sch->schid))
-               /* Console is special, no need to suppress. */
-               sch->dev.uevent_suppress = 1;
+       sch->dev.uevent_suppress = 1;
        css_update_ssd_info(sch);
        /* make it known to the system */
        ret = css_sch_device_register(sch);
@@ -255,10 +277,19 @@ static int css_register_subchannel(struct subchannel *sch)
                              sch->schid.ssid, sch->schid.sch_no, ret);
                return ret;
        }
+       if (!sch->driver) {
+               /*
+                * No driver matched. Generate the uevent now so that
+                * a fitting driver module may be loaded based on the
+                * modalias.
+                */
+               sch->dev.uevent_suppress = 0;
+               kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
+       }
        return ret;
 }
 
-static int css_probe_device(struct subchannel_id schid)
+int css_probe_device(struct subchannel_id schid)
 {
        int ret;
        struct subchannel *sch;
@@ -301,116 +332,12 @@ int css_sch_is_valid(struct schib *schib)
 {
        if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv)
                return 0;
+       if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w)
+               return 0;
        return 1;
 }
 EXPORT_SYMBOL_GPL(css_sch_is_valid);
 
-static int css_get_subchannel_status(struct subchannel *sch)
-{
-       struct schib schib;
-
-       if (stsch(sch->schid, &schib))
-               return CIO_GONE;
-       if (!css_sch_is_valid(&schib))
-               return CIO_GONE;
-       if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
-               return CIO_REVALIDATE;
-       if (!sch->lpm)
-               return CIO_NO_PATH;
-       return CIO_OPER;
-}
-
-static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
-{
-       int event, ret, disc;
-       unsigned long flags;
-       enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
-
-       spin_lock_irqsave(sch->lock, flags);
-       disc = device_is_disconnected(sch);
-       if (disc && slow) {
-               /* Disconnected devices are evaluated directly only.*/
-               spin_unlock_irqrestore(sch->lock, flags);
-               return 0;
-       }
-       /* No interrupt after machine check - kill pending timers. */
-       device_kill_pending_timer(sch);
-       if (!disc && !slow) {
-               /* Non-disconnected devices are evaluated on the slow path. */
-               spin_unlock_irqrestore(sch->lock, flags);
-               return -EAGAIN;
-       }
-       event = css_get_subchannel_status(sch);
-       CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
-                     sch->schid.ssid, sch->schid.sch_no, event,
-                     disc ? "disconnected" : "normal",
-                     slow ? "slow" : "fast");
-       /* Analyze subchannel status. */
-       action = NONE;
-       switch (event) {
-       case CIO_NO_PATH:
-               if (disc) {
-                       /* Check if paths have become available. */
-                       action = REPROBE;
-                       break;
-               }
-               /* fall through */
-       case CIO_GONE:
-               /* Prevent unwanted effects when opening lock. */
-               cio_disable_subchannel(sch);
-               device_set_disconnected(sch);
-               /* Ask driver what to do with device. */
-               action = UNREGISTER;
-               if (sch->driver && sch->driver->notify) {
-                       spin_unlock_irqrestore(sch->lock, flags);
-                       ret = sch->driver->notify(sch, event);
-                       spin_lock_irqsave(sch->lock, flags);
-                       if (ret)
-                               action = NONE;
-               }
-               break;
-       case CIO_REVALIDATE:
-               /* Device will be removed, so no notify necessary. */
-               if (disc)
-                       /* Reprobe because immediate unregister might block. */
-                       action = REPROBE;
-               else
-                       action = UNREGISTER_PROBE;
-               break;
-       case CIO_OPER:
-               if (disc)
-                       /* Get device operational again. */
-                       action = REPROBE;
-               break;
-       }
-       /* Perform action. */
-       ret = 0;
-       switch (action) {
-       case UNREGISTER:
-       case UNREGISTER_PROBE:
-               /* Unregister device (will use subchannel lock). */
-               spin_unlock_irqrestore(sch->lock, flags);
-               css_sch_device_unregister(sch);
-               spin_lock_irqsave(sch->lock, flags);
-
-               /* Reset intparm to zeroes. */
-               sch->schib.pmcw.intparm = 0;
-               cio_modify(sch);
-               break;
-       case REPROBE:
-               device_trigger_reprobe(sch);
-               break;
-       default:
-               break;
-       }
-       spin_unlock_irqrestore(sch->lock, flags);
-       /* Probe if necessary. */
-       if (action == UNREGISTER_PROBE)
-               ret = css_probe_device(sch->schid);
-
-       return ret;
-}
-
 static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
 {
        struct schib schib;
@@ -429,6 +356,21 @@ static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
        return css_probe_device(schid);
 }
 
+static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
+{
+       int ret = 0;
+
+       if (sch->driver) {
+               if (sch->driver->sch_event)
+                       ret = sch->driver->sch_event(sch, slow);
+               else
+                       dev_dbg(&sch->dev,
+                               "Got subchannel machine check but "
+                               "no sch_event handler provided.\n");
+       }
+       return ret;
+}
+
 static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
 {
        struct subchannel *sch;
@@ -596,18 +538,29 @@ EXPORT_SYMBOL_GPL(css_schedule_reprobe);
 /*
  * Called from the machine check handler for subchannel report words.
  */
-void css_process_crw(int rsid1, int rsid2)
+static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
 {
        struct subchannel_id mchk_schid;
 
-       CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
-                     rsid1, rsid2);
+       if (overflow) {
+               css_schedule_eval_all();
+               return;
+       }
+       CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, "
+                     "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
+                     crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc,
+                     crw0->erc, crw0->rsid);
+       if (crw1)
+               CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, "
+                             "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
+                             crw1->slct, crw1->oflw, crw1->chn, crw1->rsc,
+                             crw1->anc, crw1->erc, crw1->rsid);
        init_subchannel_id(&mchk_schid);
-       mchk_schid.sch_no = rsid1;
-       if (rsid2 != 0)
-               mchk_schid.ssid = (rsid2 >> 8) & 3;
+       mchk_schid.sch_no = crw0->rsid;
+       if (crw1)
+               mchk_schid.ssid = (crw1->rsid >> 8) & 3;
 
-       /* 
+       /*
         * Since we are always presented with IPI in the CRW, we have to
         * use stsch() to find out if the subchannel in question has come
         * or gone.
@@ -658,7 +611,7 @@ __init_channel_subsystem(struct subchannel_id schid, void *data)
 static void __init
 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
 {
-       if (css_characteristics_avail && css_general_characteristics.mcss) {
+       if (css_general_characteristics.mcss) {
                css->global_pgid.pgid_high.ext_cssid.version = 0x80;
                css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
        } else {
@@ -795,8 +748,6 @@ init_channel_subsystem (void)
        ret = chsc_determine_css_characteristics();
        if (ret == -ENOMEM)
                goto out; /* No need to continue. */
-       if (ret == 0)
-               css_characteristics_avail = 1;
 
        ret = chsc_alloc_sei_area();
        if (ret)
@@ -806,6 +757,10 @@ init_channel_subsystem (void)
        if (ret)
                goto out;
 
+       ret = s390_register_crw_handler(CRW_RSC_SCH, css_process_crw);
+       if (ret)
+               goto out;
+
        if ((ret = bus_register(&css_bus_type)))
                goto out;
 
@@ -836,8 +791,7 @@ init_channel_subsystem (void)
                ret = device_register(&css->device);
                if (ret)
                        goto out_free_all;
-               if (css_characteristics_avail &&
-                   css_chsc_characteristics.secm) {
+               if (css_chsc_characteristics.secm) {
                        ret = device_create_file(&css->device,
                                                 &dev_attr_cm_enable);
                        if (ret)
@@ -852,7 +806,8 @@ init_channel_subsystem (void)
                goto out_pseudo;
        css_init_done = 1;
 
-       ctl_set_bit(6, 28);
+       /* Enable default isc for I/O subchannels. */
+       isc_register(IO_SCH_ISC);
 
        for_each_subchannel(__init_channel_subsystem, NULL);
        return 0;
@@ -875,7 +830,7 @@ out_unregister:
                i--;
                css = channel_subsystems[i];
                device_unregister(&css->pseudo_subchannel->dev);
-               if (css_characteristics_avail && css_chsc_characteristics.secm)
+               if (css_chsc_characteristics.secm)
                        device_remove_file(&css->device,
                                           &dev_attr_cm_enable);
                device_unregister(&css->device);
@@ -883,6 +838,7 @@ out_unregister:
 out_bus:
        bus_unregister(&css_bus_type);
 out:
+       s390_unregister_crw_handler(CRW_RSC_CSS);
        chsc_free_sei_area();
        kfree(slow_subchannel_set);
        printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n",
@@ -895,19 +851,16 @@ int sch_is_pseudo_sch(struct subchannel *sch)
        return sch == to_css(sch->dev.parent)->pseudo_subchannel;
 }
 
-/*
- * find a driver for a subchannel. They identify by the subchannel
- * type with the exception that the console subchannel driver has its own
- * subchannel type although the device is an i/o subchannel
- */
-static int
-css_bus_match (struct device *dev, struct device_driver *drv)
+static int css_bus_match(struct device *dev, struct device_driver *drv)
 {
        struct subchannel *sch = to_subchannel(dev);
        struct css_driver *driver = to_cssdriver(drv);
+       struct css_device_id *id;
 
-       if (sch->st == driver->subchannel_type)
-               return 1;
+       for (id = driver->subchannel_type; id->match_flags; id++) {
+               if (sch->st == id->type)
+                       return 1;
+       }
 
        return 0;
 }
@@ -945,12 +898,25 @@ static void css_shutdown(struct device *dev)
                sch->driver->shutdown(sch);
 }
 
+static int css_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       struct subchannel *sch = to_subchannel(dev);
+       int ret;
+
+       ret = add_uevent_var(env, "ST=%01X", sch->st);
+       if (ret)
+               return ret;
+       ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st);
+       return ret;
+}
+
 struct bus_type css_bus_type = {
        .name     = "css",
        .match    = css_bus_match,
        .probe    = css_probe,
        .remove   = css_remove,
        .shutdown = css_shutdown,
+       .uevent   = css_uevent,
 };
 
 /**
@@ -985,4 +951,3 @@ subsys_initcall(init_channel_subsystem);
 
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(css_bus_type);
-EXPORT_SYMBOL_GPL(css_characteristics_avail);
index e191351..57ebf12 100644 (file)
@@ -9,8 +9,7 @@
 
 #include <asm/cio.h>
 #include <asm/chpid.h>
-
-#include "schid.h"
+#include <asm/schid.h>
 
 /*
  * path grouping stuff
@@ -58,20 +57,28 @@ struct pgid {
        __u32 tod_high;         /* high word TOD clock */
 } __attribute__ ((packed));
 
-/*
- * A css driver handles all subchannels of one type.
- * Currently, we only care about I/O subchannels (type 0), these
- * have a ccw_device connected to them.
- */
 struct subchannel;
+struct chp_link;
+/**
+ * struct css_driver - device driver for subchannels
+ * @owner: owning module
+ * @subchannel_type: subchannel type supported by this driver
+ * @drv: embedded device driver structure
+ * @irq: called on interrupts
+ * @chp_event: called for events affecting a channel path
+ * @sch_event: called for events affecting the subchannel
+ * @probe: function called on probe
+ * @remove: function called on remove
+ * @shutdown: called at device shutdown
+ * @name: name of the device driver
+ */
 struct css_driver {
        struct module *owner;
-       unsigned int subchannel_type;
+       struct css_device_id *subchannel_type;
        struct device_driver drv;
        void (*irq)(struct subchannel *);
-       int (*notify)(struct subchannel *, int);
-       void (*verify)(struct subchannel *);
-       void (*termination)(struct subchannel *);
+       int (*chp_event)(struct subchannel *, struct chp_link *, int);
+       int (*sch_event)(struct subchannel *, int);
        int (*probe)(struct subchannel *);
        int (*remove)(struct subchannel *);
        void (*shutdown)(struct subchannel *);
@@ -89,13 +96,13 @@ extern int css_driver_register(struct css_driver *);
 extern void css_driver_unregister(struct css_driver *);
 
 extern void css_sch_device_unregister(struct subchannel *);
-extern struct subchannel * get_subchannel_by_schid(struct subchannel_id);
+extern int css_probe_device(struct subchannel_id);
+extern struct subchannel *get_subchannel_by_schid(struct subchannel_id);
 extern int css_init_done;
 int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *),
                               int (*fn_unknown)(struct subchannel_id,
                               void *), void *data);
 extern int for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *);
-extern void css_process_crw(int, int);
 extern void css_reiterate_subchannels(void);
 void css_update_ssd_info(struct subchannel *sch);
 
@@ -121,20 +128,6 @@ struct channel_subsystem {
 extern struct bus_type css_bus_type;
 extern struct channel_subsystem *channel_subsystems[];
 
-/* Some helper functions for disconnected state. */
-int device_is_disconnected(struct subchannel *);
-void device_set_disconnected(struct subchannel *);
-void device_trigger_reprobe(struct subchannel *);
-
-/* Helper functions for vary on/off. */
-int device_is_online(struct subchannel *);
-void device_kill_io(struct subchannel *);
-void device_set_intretry(struct subchannel *sch);
-int device_trigger_verify(struct subchannel *sch);
-
-/* Machine check helper function. */
-void device_kill_pending_timer(struct subchannel *);
-
 /* Helper functions to build lists for the slow path. */
 void css_schedule_eval(struct subchannel_id schid);
 void css_schedule_eval_all(void);
@@ -145,6 +138,4 @@ int css_sch_is_valid(struct schib *);
 
 extern struct workqueue_struct *slow_path_wq;
 void css_wait_for_slow_path(void);
-
-extern struct attribute_group *subch_attr_groups[];
 #endif
index e22813d..e818d0c 100644 (file)
@@ -2,8 +2,7 @@
  *  drivers/s390/cio/device.c
  *  bus driver for ccw devices
  *
- *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
- *                      IBM Corporation
+ *    Copyright IBM Corp. 2002,2008
  *    Author(s): Arnd Bergmann (arndb@de.ibm.com)
  *              Cornelia Huck (cornelia.huck@de.ibm.com)
  *              Martin Schwidefsky (schwidefsky@de.ibm.com)
@@ -23,7 +22,9 @@
 #include <asm/cio.h>
 #include <asm/param.h>         /* HZ */
 #include <asm/cmb.h>
+#include <asm/isc.h>
 
+#include "chp.h"
 #include "cio.h"
 #include "cio_debug.h"
 #include "css.h"
@@ -125,19 +126,24 @@ struct bus_type ccw_bus_type;
 static void io_subchannel_irq(struct subchannel *);
 static int io_subchannel_probe(struct subchannel *);
 static int io_subchannel_remove(struct subchannel *);
-static int io_subchannel_notify(struct subchannel *, int);
-static void io_subchannel_verify(struct subchannel *);
-static void io_subchannel_ioterm(struct subchannel *);
 static void io_subchannel_shutdown(struct subchannel *);
+static int io_subchannel_sch_event(struct subchannel *, int);
+static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
+                                  int);
+
+static struct css_device_id io_subchannel_ids[] = {
+       { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
+       { /* end of list */ },
+};
+MODULE_DEVICE_TABLE(css, io_subchannel_ids);
 
 static struct css_driver io_subchannel_driver = {
        .owner = THIS_MODULE,
-       .subchannel_type = SUBCHANNEL_TYPE_IO,
+       .subchannel_type = io_subchannel_ids,
        .name = "io_subchannel",
        .irq = io_subchannel_irq,
-       .notify = io_subchannel_notify,
-       .verify = io_subchannel_verify,
-       .termination = io_subchannel_ioterm,
+       .sch_event = io_subchannel_sch_event,
+       .chp_event = io_subchannel_chp_event,
        .probe = io_subchannel_probe,
        .remove = io_subchannel_remove,
        .shutdown = io_subchannel_shutdown,
@@ -487,25 +493,22 @@ static int online_store_recog_and_online(struct ccw_device *cdev)
                ccw_device_set_online(cdev);
        return 0;
 }
-static void online_store_handle_online(struct ccw_device *cdev, int force)
+static int online_store_handle_online(struct ccw_device *cdev, int force)
 {
        int ret;
 
        ret = online_store_recog_and_online(cdev);
        if (ret)
-               return;
+               return ret;
        if (force && cdev->private->state == DEV_STATE_BOXED) {
                ret = ccw_device_stlck(cdev);
-               if (ret) {
-                       dev_warn(&cdev->dev,
-                                "ccw_device_stlck returned %d!\n", ret);
-                       return;
-               }
+               if (ret)
+                       return ret;
                if (cdev->id.cu_type == 0)
                        cdev->private->state = DEV_STATE_NOT_OPER;
                online_store_recog_and_online(cdev);
        }
-
+       return 0;
 }
 
 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
@@ -538,8 +541,9 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr,
                ret = count;
                break;
        case 1:
-               online_store_handle_online(cdev, force);
-               ret = count;
+               ret = online_store_handle_online(cdev, force);
+               if (!ret)
+                       ret = count;
                break;
        default:
                ret = -EINVAL;
@@ -584,19 +588,14 @@ static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
 static DEVICE_ATTR(online, 0644, online_show, online_store);
 static DEVICE_ATTR(availability, 0444, available_show, NULL);
 
-static struct attribute * subch_attrs[] = {
+static struct attribute *io_subchannel_attrs[] = {
        &dev_attr_chpids.attr,
        &dev_attr_pimpampom.attr,
        NULL,
 };
 
-static struct attribute_group subch_attr_group = {
-       .attrs = subch_attrs,
-};
-
-struct attribute_group *subch_attr_groups[] = {
-       &subch_attr_group,
-       NULL,
+static struct attribute_group io_subchannel_attr_group = {
+       .attrs = io_subchannel_attrs,
 };
 
 static struct attribute * ccwdev_attrs[] = {
@@ -790,7 +789,7 @@ static void sch_attach_device(struct subchannel *sch,
        sch_set_cdev(sch, cdev);
        cdev->private->schid = sch->schid;
        cdev->ccwlock = sch->lock;
-       device_trigger_reprobe(sch);
+       ccw_device_trigger_reprobe(cdev);
        spin_unlock_irq(sch->lock);
 }
 
@@ -1037,7 +1036,6 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
        struct ccw_device_private *priv;
 
        sch_set_cdev(sch, cdev);
-       sch->driver = &io_subchannel_driver;
        cdev->ccwlock = sch->lock;
 
        /* Init private data. */
@@ -1122,8 +1120,33 @@ static void io_subchannel_irq(struct subchannel *sch)
                dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
 }
 
-static int
-io_subchannel_probe (struct subchannel *sch)
+static void io_subchannel_init_fields(struct subchannel *sch)
+{
+       if (cio_is_console(sch->schid))
+               sch->opm = 0xff;
+       else
+               sch->opm = chp_get_sch_opm(sch);
+       sch->lpm = sch->schib.pmcw.pam & sch->opm;
+       sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
+
+       CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
+                     " - PIM = %02X, PAM = %02X, POM = %02X\n",
+                     sch->schib.pmcw.dev, sch->schid.ssid,
+                     sch->schid.sch_no, sch->schib.pmcw.pim,
+                     sch->schib.pmcw.pam, sch->schib.pmcw.pom);
+       /* Initially set up some fields in the pmcw. */
+       sch->schib.pmcw.ena = 0;
+       sch->schib.pmcw.csense = 1;     /* concurrent sense */
+       if ((sch->lpm & (sch->lpm - 1)) != 0)
+               sch->schib.pmcw.mp = 1; /* multipath mode */
+       /* clean up possible residual cmf stuff */
+       sch->schib.pmcw.mme = 0;
+       sch->schib.pmcw.mbfc = 0;
+       sch->schib.pmcw.mbi = 0;
+       sch->schib.mba = 0;
+}
+
+static int io_subchannel_probe(struct subchannel *sch)
 {
        struct ccw_device *cdev;
        int rc;
@@ -1132,11 +1155,21 @@ io_subchannel_probe (struct subchannel *sch)
 
        cdev = sch_get_cdev(sch);
        if (cdev) {
+               rc = sysfs_create_group(&sch->dev.kobj,
+                                       &io_subchannel_attr_group);
+               if (rc)
+                       CIO_MSG_EVENT(0, "Failed to create io subchannel "
+                                     "attributes for subchannel "
+                                     "0.%x.%04x (rc=%d)\n",
+                                     sch->schid.ssid, sch->schid.sch_no, rc);
                /*
                 * This subchannel already has an associated ccw_device.
-                * Register it and exit. This happens for all early
-                * device, e.g. the console.
+                * Throw the delayed uevent for the subchannel, register
+                * the ccw_device and exit. This happens for all early
+                * devices, e.g. the console.
                 */
+               sch->dev.uevent_suppress = 0;
+               kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
                cdev->dev.groups = ccwdev_attr_groups;
                device_initialize(&cdev->dev);
                ccw_device_register(cdev);
@@ -1152,17 +1185,24 @@ io_subchannel_probe (struct subchannel *sch)
                        get_device(&cdev->dev);
                return 0;
        }
+       io_subchannel_init_fields(sch);
        /*
         * First check if a fitting device may be found amongst the
         * disconnected devices or in the orphanage.
         */
        dev_id.devno = sch->schib.pmcw.dev;
        dev_id.ssid = sch->schid.ssid;
+       rc = sysfs_create_group(&sch->dev.kobj,
+                               &io_subchannel_attr_group);
+       if (rc)
+               return rc;
        /* Allocate I/O subchannel private data. */
        sch->private = kzalloc(sizeof(struct io_subchannel_private),
                               GFP_KERNEL | GFP_DMA);
-       if (!sch->private)
-               return -ENOMEM;
+       if (!sch->private) {
+               rc = -ENOMEM;
+               goto out_err;
+       }
        cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
        if (!cdev)
                cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
@@ -1181,8 +1221,8 @@ io_subchannel_probe (struct subchannel *sch)
        }
        cdev = io_subchannel_create_ccwdev(sch);
        if (IS_ERR(cdev)) {
-               kfree(sch->private);
-               return PTR_ERR(cdev);
+               rc = PTR_ERR(cdev);
+               goto out_err;
        }
        rc = io_subchannel_recog(cdev, sch);
        if (rc) {
@@ -1191,9 +1231,12 @@ io_subchannel_probe (struct subchannel *sch)
                spin_unlock_irqrestore(sch->lock, flags);
                if (cdev->dev.release)
                        cdev->dev.release(&cdev->dev);
-               kfree(sch->private);
+               goto out_err;
        }
-
+       return 0;
+out_err:
+       kfree(sch->private);
+       sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
        return rc;
 }
 
@@ -1214,6 +1257,7 @@ io_subchannel_remove (struct subchannel *sch)
        ccw_device_unregister(cdev);
        put_device(&cdev->dev);
        kfree(sch->private);
+       sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
        return 0;
 }
 
@@ -1224,11 +1268,7 @@ static int io_subchannel_notify(struct subchannel *sch, int event)
        cdev = sch_get_cdev(sch);
        if (!cdev)
                return 0;
-       if (!cdev->drv)
-               return 0;
-       if (!cdev->online)
-               return 0;
-       return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
+       return ccw_device_notify(cdev, event);
 }
 
 static void io_subchannel_verify(struct subchannel *sch)
@@ -1240,22 +1280,96 @@ static void io_subchannel_verify(struct subchannel *sch)
                dev_fsm_event(cdev, DEV_EVENT_VERIFY);
 }
 
-static void io_subchannel_ioterm(struct subchannel *sch)
+static int check_for_io_on_path(struct subchannel *sch, int mask)
 {
-       struct ccw_device *cdev;
+       int cc;
 
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return;
-       /* Internal I/O will be retried by the interrupt handler. */
-       if (cdev->private->flags.intretry)
+       cc = stsch(sch->schid, &sch->schib);
+       if (cc)
+               return 0;
+       if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
+               return 1;
+       return 0;
+}
+
+static void terminate_internal_io(struct subchannel *sch,
+                                 struct ccw_device *cdev)
+{
+       if (cio_clear(sch)) {
+               /* Recheck device in case clear failed. */
+               sch->lpm = 0;
+               if (cdev->online)
+                       dev_fsm_event(cdev, DEV_EVENT_VERIFY);
+               else
+                       css_schedule_eval(sch->schid);
                return;
+       }
        cdev->private->state = DEV_STATE_CLEAR_VERIFY;
+       /* Request retry of internal operation. */
+       cdev->private->flags.intretry = 1;
+       /* Call handler. */
        if (cdev->handler)
                cdev->handler(cdev, cdev->private->intparm,
                              ERR_PTR(-EIO));
 }
 
+static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
+{
+       struct ccw_device *cdev;
+
+       cdev = sch_get_cdev(sch);
+       if (!cdev)
+               return;
+       if (check_for_io_on_path(sch, mask)) {
+               if (cdev->private->state == DEV_STATE_ONLINE)
+                       ccw_device_kill_io(cdev);
+               else {
+                       terminate_internal_io(sch, cdev);
+                       /* Re-start path verification. */
+                       dev_fsm_event(cdev, DEV_EVENT_VERIFY);
+               }
+       } else
+               /* trigger path verification. */
+               dev_fsm_event(cdev, DEV_EVENT_VERIFY);
+
+}
+
+static int io_subchannel_chp_event(struct subchannel *sch,
+                                  struct chp_link *link, int event)
+{
+       int mask;
+
+       mask = chp_ssd_get_mask(&sch->ssd_info, link);
+       if (!mask)
+               return 0;
+       switch (event) {
+       case CHP_VARY_OFF:
+               sch->opm &= ~mask;
+               sch->lpm &= ~mask;
+               io_subchannel_terminate_path(sch, mask);
+               break;
+       case CHP_VARY_ON:
+               sch->opm |= mask;
+               sch->lpm |= mask;
+               io_subchannel_verify(sch);
+               break;
+       case CHP_OFFLINE:
+               if (stsch(sch->schid, &sch->schib))
+                       return -ENXIO;
+               if (!css_sch_is_valid(&sch->schib))
+                       return -ENODEV;
+               io_subchannel_terminate_path(sch, mask);
+               break;
+       case CHP_ONLINE:
+               if (stsch(sch->schid, &sch->schib))
+                       return -ENXIO;
+               sch->lpm |= mask & sch->opm;
+               io_subchannel_verify(sch);
+               break;
+       }
+       return 0;
+}
+
 static void
 io_subchannel_shutdown(struct subchannel *sch)
 {
@@ -1285,6 +1399,195 @@ io_subchannel_shutdown(struct subchannel *sch)
        cio_disable_subchannel(sch);
 }
 
+static int io_subchannel_get_status(struct subchannel *sch)
+{
+       struct schib schib;
+
+       if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
+               return CIO_GONE;
+       if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
+               return CIO_REVALIDATE;
+       if (!sch->lpm)
+               return CIO_NO_PATH;
+       return CIO_OPER;
+}
+
+static int device_is_disconnected(struct ccw_device *cdev)
+{
+       if (!cdev)
+               return 0;
+       return (cdev->private->state == DEV_STATE_DISCONNECTED ||
+               cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
+}
+
+static int recovery_check(struct device *dev, void *data)
+{
+       struct ccw_device *cdev = to_ccwdev(dev);
+       int *redo = data;
+
+       spin_lock_irq(cdev->ccwlock);
+       switch (cdev->private->state) {
+       case DEV_STATE_DISCONNECTED:
+               CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
+                             cdev->private->dev_id.ssid,
+                             cdev->private->dev_id.devno);
+               dev_fsm_event(cdev, DEV_EVENT_VERIFY);
+               *redo = 1;
+               break;
+       case DEV_STATE_DISCONNECTED_SENSE_ID:
+               *redo = 1;
+               break;
+       }
+       spin_unlock_irq(cdev->ccwlock);
+
+       return 0;
+}
+
+static void recovery_work_func(struct work_struct *unused)
+{
+       int redo = 0;
+
+       bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
+       if (redo) {
+               spin_lock_irq(&recovery_lock);
+               if (!timer_pending(&recovery_timer)) {
+                       if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
+                               recovery_phase++;
+                       mod_timer(&recovery_timer, jiffies +
+                                 recovery_delay[recovery_phase] * HZ);
+               }
+               spin_unlock_irq(&recovery_lock);
+       } else
+               CIO_MSG_EVENT(4, "recovery: end\n");
+}
+
+static DECLARE_WORK(recovery_work, recovery_work_func);
+
+static void recovery_func(unsigned long data)
+{
+       /*
+        * We can't do our recovery in softirq context and it's not
+        * performance critical, so we schedule it.
+        */
+       schedule_work(&recovery_work);
+}
+
+static void ccw_device_schedule_recovery(void)
+{
+       unsigned long flags;
+
+       CIO_MSG_EVENT(4, "recovery: schedule\n");
+       spin_lock_irqsave(&recovery_lock, flags);
+       if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
+               recovery_phase = 0;
+               mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
+       }
+       spin_unlock_irqrestore(&recovery_lock, flags);
+}
+
+static void device_set_disconnected(struct ccw_device *cdev)
+{
+       if (!cdev)
+               return;
+       ccw_device_set_timeout(cdev, 0);
+       cdev->private->flags.fake_irb = 0;
+       cdev->private->state = DEV_STATE_DISCONNECTED;
+       if (cdev->online)
+               ccw_device_schedule_recovery();
+}
+
+static int io_subchannel_sch_event(struct subchannel *sch, int slow)
+{
+       int event, ret, disc;
+       unsigned long flags;
+       enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
+       struct ccw_device *cdev;
+
+       spin_lock_irqsave(sch->lock, flags);
+       cdev = sch_get_cdev(sch);
+       disc = device_is_disconnected(cdev);
+       if (disc && slow) {
+               /* Disconnected devices are evaluated directly only.*/
+               spin_unlock_irqrestore(sch->lock, flags);
+               return 0;
+       }
+       /* No interrupt after machine check - kill pending timers. */
+       if (cdev)
+               ccw_device_set_timeout(cdev, 0);
+       if (!disc && !slow) {
+               /* Non-disconnected devices are evaluated on the slow path. */
+               spin_unlock_irqrestore(sch->lock, flags);
+               return -EAGAIN;
+       }
+       event = io_subchannel_get_status(sch);
+       CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
+                     sch->schid.ssid, sch->schid.sch_no, event,
+                     disc ? "disconnected" : "normal",
+                     slow ? "slow" : "fast");
+       /* Analyze subchannel status. */
+       action = NONE;
+       switch (event) {
+       case CIO_NO_PATH:
+               if (disc) {
+                       /* Check if paths have become available. */
+                       action = REPROBE;
+                       break;
+               }
+               /* fall through */
+       case CIO_GONE:
+               /* Prevent unwanted effects when opening lock. */
+               cio_disable_subchannel(sch);
+               device_set_disconnected(cdev);
+               /* Ask driver what to do with device. */
+               action = UNREGISTER;
+               spin_unlock_irqrestore(sch->lock, flags);
+               ret = io_subchannel_notify(sch, event);
+               spin_lock_irqsave(sch->lock, flags);
+               if (ret)
+                       action = NONE;
+               break;
+       case CIO_REVALIDATE:
+               /* Device will be removed, so no notify necessary. */
+               if (disc)
+                       /* Reprobe because immediate unregister might block. */
+                       action = REPROBE;
+               else
+                       action = UNREGISTER_PROBE;
+               break;
+       case CIO_OPER:
+               if (disc)
+                       /* Get device operational again. */
+                       action = REPROBE;
+               break;
+       }
+       /* Perform action. */
+       ret = 0;
+       switch (action) {
+       case UNREGISTER:
+       case UNREGISTER_PROBE:
+               /* Unregister device (will use subchannel lock). */
+               spin_unlock_irqrestore(sch->lock, flags);
+               css_sch_device_unregister(sch);
+               spin_lock_irqsave(sch->lock, flags);
+
+               /* Reset intparm to zeroes. */
+               sch->schib.pmcw.intparm = 0;
+               cio_modify(sch);
+               break;
+       case REPROBE:
+               ccw_device_trigger_reprobe(cdev);
+               break;
+       default:
+               break;
+       }
+       spin_unlock_irqrestore(sch->lock, flags);
+       /* Probe if necessary. */
+       if (action == UNREGISTER_PROBE)
+               ret = css_probe_device(sch->schid);
+
+       return ret;
+}
+
 #ifdef CONFIG_CCW_CONSOLE
 static struct ccw_device console_cdev;
 static struct ccw_device_private console_private;
@@ -1297,14 +1600,16 @@ spinlock_t * cio_get_console_lock(void)
        return &ccw_console_lock;
 }
 
-static int
-ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
+static int ccw_device_console_enable(struct ccw_device *cdev,
+                                    struct subchannel *sch)
 {
        int rc;
 
        /* Attach subchannel private data. */
        sch->private = cio_get_console_priv();
        memset(sch->private, 0, sizeof(struct io_subchannel_private));
+       io_subchannel_init_fields(sch);
+       sch->driver = &io_subchannel_driver;
        /* Initialize the ccw_device structure. */
        cdev->dev.parent= &sch->dev;
        rc = io_subchannel_recog(cdev, sch);
@@ -1515,71 +1820,6 @@ ccw_device_get_subchannel_id(struct ccw_device *cdev)
        return sch->schid;
 }
 
-static int recovery_check(struct device *dev, void *data)
-{
-       struct ccw_device *cdev = to_ccwdev(dev);
-       int *redo = data;
-
-       spin_lock_irq(cdev->ccwlock);
-       switch (cdev->private->state) {
-       case DEV_STATE_DISCONNECTED:
-               CIO_MSG_EVENT(4, "recovery: trigger 0.%x.%04x\n",
-                             cdev->private->dev_id.ssid,
-                             cdev->private->dev_id.devno);
-               dev_fsm_event(cdev, DEV_EVENT_VERIFY);
-               *redo = 1;
-               break;
-       case DEV_STATE_DISCONNECTED_SENSE_ID:
-               *redo = 1;
-               break;
-       }
-       spin_unlock_irq(cdev->ccwlock);
-
-       return 0;
-}
-
-static void recovery_work_func(struct work_struct *unused)
-{
-       int redo = 0;
-
-       bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
-       if (redo) {
-               spin_lock_irq(&recovery_lock);
-               if (!timer_pending(&recovery_timer)) {
-                       if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
-                               recovery_phase++;
-                       mod_timer(&recovery_timer, jiffies +
-                                 recovery_delay[recovery_phase] * HZ);
-               }
-               spin_unlock_irq(&recovery_lock);
-       } else
-               CIO_MSG_EVENT(4, "recovery: end\n");
-}
-
-static DECLARE_WORK(recovery_work, recovery_work_func);
-
-static void recovery_func(unsigned long data)
-{
-       /*
-        * We can't do our recovery in softirq context and it's not
-        * performance critical, so we schedule it.
-        */
-       schedule_work(&recovery_work);
-}
-
-void ccw_device_schedule_recovery(void)
-{
-       unsigned long flags;
-
-       CIO_MSG_EVENT(4, "recovery: schedule\n");
-       spin_lock_irqsave(&recovery_lock, flags);
-       if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
-               recovery_phase = 0;
-               mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
-       }
-       spin_unlock_irqrestore(&recovery_lock, flags);
-}
-
 MODULE_LICENSE("GPL");
 EXPORT_SYMBOL(ccw_device_set_online);
 EXPORT_SYMBOL(ccw_device_set_offline);
index cb08092..9800a83 100644 (file)
@@ -88,8 +88,6 @@ int ccw_device_recognition(struct ccw_device *);
 int ccw_device_online(struct ccw_device *);
 int ccw_device_offline(struct ccw_device *);
 
-void ccw_device_schedule_recovery(void);
-
 /* Function prototypes for device status and basic sense stuff. */
 void ccw_device_accumulate_irb(struct ccw_device *, struct irb *);
 void ccw_device_accumulate_basic_sense(struct ccw_device *, struct irb *);
@@ -118,6 +116,11 @@ int ccw_device_call_handler(struct ccw_device *);
 
 int ccw_device_stlck(struct ccw_device *);
 
+/* Helper function for machine check handling. */
+void ccw_device_trigger_reprobe(struct ccw_device *);
+void ccw_device_kill_io(struct ccw_device *);
+int ccw_device_notify(struct ccw_device *, int);
+
 /* qdio needs this. */
 void ccw_device_set_timeout(struct ccw_device *, int);
 extern struct subchannel_id ccw_device_get_subchannel_id(struct ccw_device *);
index e268d5a..8b5fe57 100644 (file)
@@ -2,8 +2,7 @@
  * drivers/s390/cio/device_fsm.c
  * finite state machine for device handling
  *
- *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
- *                      IBM Corporation
+ *    Copyright IBM Corp. 2002,2008
  *    Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
  *              Martin Schwidefsky (schwidefsky@de.ibm.com)
  */
 
 static int timeout_log_enabled;
 
-int
-device_is_online(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return 0;
-       return (cdev->private->state == DEV_STATE_ONLINE);
-}
-
-int
-device_is_disconnected(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return 0;
-       return (cdev->private->state == DEV_STATE_DISCONNECTED ||
-               cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
-}
-
-void
-device_set_disconnected(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return;
-       ccw_device_set_timeout(cdev, 0);
-       cdev->private->flags.fake_irb = 0;
-       cdev->private->state = DEV_STATE_DISCONNECTED;
-       if (cdev->online)
-               ccw_device_schedule_recovery();
-}
-
-void device_set_intretry(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return;
-       cdev->private->flags.intretry = 1;
-}
-
-int device_trigger_verify(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev || !cdev->online)
-               return -EINVAL;
-       dev_fsm_event(cdev, DEV_EVENT_VERIFY);
-       return 0;
-}
-
 static int __init ccw_timeout_log_setup(char *unused)
 {
        timeout_log_enabled = 1;
@@ -99,31 +39,43 @@ static void ccw_timeout_log(struct ccw_device *cdev)
        struct schib schib;
        struct subchannel *sch;
        struct io_subchannel_private *private;
+       union orb *orb;
        int cc;
 
        sch = to_subchannel(cdev->dev.parent);
        private = to_io_private(sch);
+       orb = &private->orb;
        cc = stsch(sch->schid, &schib);
 
        printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
               "device information:\n", get_clock());
        printk(KERN_WARNING "cio: orb:\n");
        print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
-                      &private->orb, sizeof(private->orb), 0);
+                      orb, sizeof(*orb), 0);
        printk(KERN_WARNING "cio: ccw device bus id: %s\n", cdev->dev.bus_id);
        printk(KERN_WARNING "cio: subchannel bus id: %s\n", sch->dev.bus_id);
        printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, "
               "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm);
 
-       if ((void *)(addr_t)private->orb.cpa == &private->sense_ccw ||
-           (void *)(addr_t)private->orb.cpa == cdev->private->iccws)
-               printk(KERN_WARNING "cio: last channel program (intern):\n");
-       else
-               printk(KERN_WARNING "cio: last channel program:\n");
-
-       print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
-                      (void *)(addr_t)private->orb.cpa,
-                      sizeof(struct ccw1), 0);
+       if (orb->tm.b) {
+               printk(KERN_WARNING "cio: orb indicates transport mode\n");
+               printk(KERN_WARNING "cio: last tcw:\n");
+               print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
+                              (void *)(addr_t)orb->tm.tcw,
+                              sizeof(struct tcw), 0);
+       } else {
+               printk(KERN_WARNING "cio: orb indicates command mode\n");
+               if ((void *)(addr_t)orb->cmd.cpa == &private->sense_ccw ||
+                   (void *)(addr_t)orb->cmd.cpa == cdev->private->iccws)
+                       printk(KERN_WARNING "cio: last channel program "
+                              "(intern):\n");
+               else
+                       printk(KERN_WARNING "cio: last channel program:\n");
+
+               print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
+                              (void *)(addr_t)orb->cmd.cpa,
+                              sizeof(struct ccw1), 0);
+       }
        printk(KERN_WARNING "cio: ccw device state: %d\n",
               cdev->private->state);
        printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc);
@@ -171,18 +123,6 @@ ccw_device_set_timeout(struct ccw_device *cdev, int expires)
        add_timer(&cdev->private->timer);
 }
 
-/* Kill any pending timers after machine check. */
-void
-device_kill_pending_timer(struct subchannel *sch)
-{
-       struct ccw_device *cdev;
-
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return;
-       ccw_device_set_timeout(cdev, 0);
-}
-
 /*
  * Cancel running i/o. This is called repeatedly since halt/clear are
  * asynchronous operations. We do one try with cio_cancel, two tries
@@ -205,15 +145,18 @@ ccw_device_cancel_halt_clear(struct ccw_device *cdev)
                /* Not operational -> done. */
                return 0;
        /* Stage 1: cancel io. */
-       if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
-           !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
-               ret = cio_cancel(sch);
-               if (ret != -EINVAL)
-                       return ret;
-               /* cancel io unsuccessful. From now on it is asynchronous. */
+       if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
+           !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
+               if (!scsw_is_tm(&sch->schib.scsw)) {
+                       ret = cio_cancel(sch);
+                       if (ret != -EINVAL)
+                               return ret;
+               }
+               /* cancel io unsuccessful or not applicable (transport mode).
+                * Continue with asynchronous instructions. */
                cdev->private->iretry = 3;      /* 3 halt retries. */
        }
-       if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
+       if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
                /* Stage 2: halt io. */
                if (cdev->private->iretry) {
                        cdev->private->iretry--;
@@ -388,34 +331,30 @@ ccw_device_sense_id_done(struct ccw_device *cdev, int err)
        }
 }
 
+int ccw_device_notify(struct ccw_device *cdev, int event)
+{
+       if (!cdev->drv)
+               return 0;
+       if (!cdev->online)
+               return 0;
+       return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
+}
+
 static void
 ccw_device_oper_notify(struct work_struct *work)
 {
        struct ccw_device_private *priv;
        struct ccw_device *cdev;
-       struct subchannel *sch;
        int ret;
-       unsigned long flags;
 
        priv = container_of(work, struct ccw_device_private, kick_work);
        cdev = priv->cdev;
-       spin_lock_irqsave(cdev->ccwlock, flags);
-       sch = to_subchannel(cdev->dev.parent);
-       if (sch->driver && sch->driver->notify) {
-               spin_unlock_irqrestore(cdev->ccwlock, flags);
-               ret = sch->driver->notify(sch, CIO_OPER);
-               spin_lock_irqsave(cdev->ccwlock, flags);
-       } else
-               ret = 0;
+       ret = ccw_device_notify(cdev, CIO_OPER);
        if (ret) {
                /* Reenable channel measurements, if needed. */
-               spin_unlock_irqrestore(cdev->ccwlock, flags);
                cmf_reenable(cdev);
-               spin_lock_irqsave(cdev->ccwlock, flags);
                wake_up(&cdev->private->wait_q);
-       }
-       spin_unlock_irqrestore(cdev->ccwlock, flags);
-       if (!ret)
+       } else
                /* Driver doesn't want device back. */
                ccw_device_do_unreg_rereg(work);
 }
@@ -621,10 +560,11 @@ ccw_device_verify_done(struct ccw_device *cdev, int err)
                /* Deliver fake irb to device driver, if needed. */
                if (cdev->private->flags.fake_irb) {
                        memset(&cdev->private->irb, 0, sizeof(struct irb));
-                       cdev->private->irb.scsw.cc = 1;
-                       cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
-                       cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
-                       cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
+                       cdev->private->irb.scsw.cmd.cc = 1;
+                       cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC;
+                       cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND;
+                       cdev->private->irb.scsw.cmd.stctl =
+                               SCSW_STCTL_STATUS_PEND;
                        cdev->private->flags.fake_irb = 0;
                        if (cdev->handler)
                                cdev->handler(cdev, cdev->private->intparm,
@@ -718,13 +658,10 @@ ccw_device_offline(struct ccw_device *cdev)
        sch = to_subchannel(cdev->dev.parent);
        if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
                return -ENODEV;
-       if (cdev->private->state != DEV_STATE_ONLINE) {
-               if (sch->schib.scsw.actl != 0)
-                       return -EBUSY;
-               return -EINVAL;
-       }
-       if (sch->schib.scsw.actl != 0)
+       if (scsw_actl(&sch->schib.scsw) != 0)
                return -EBUSY;
+       if (cdev->private->state != DEV_STATE_ONLINE)
+               return -EINVAL;
        /* Are we doing path grouping? */
        if (!cdev->private->options.pgroup) {
                /* No, set state offline immediately. */
@@ -799,9 +736,9 @@ ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
         */
        stsch(sch->schid, &sch->schib);
 
-       if (sch->schib.scsw.actl != 0 ||
-           (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
-           (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
+       if (scsw_actl(&sch->schib.scsw) != 0 ||
+           (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
+           (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
                /*
                 * No final status yet or final status not yet delivered
                 * to the device driver. Can't do path verfication now,
@@ -823,13 +760,13 @@ static void
 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
 {
        struct irb *irb;
+       int is_cmd;
 
        irb = (struct irb *) __LC_IRB;
+       is_cmd = !scsw_is_tm(&irb->scsw);
        /* Check for unsolicited interrupt. */
-       if ((irb->scsw.stctl ==
-                       (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
-           && (!irb->scsw.cc)) {
-               if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
+       if (!scsw_is_solicited(&irb->scsw)) {
+               if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
                    !irb->esw.esw0.erw.cons) {
                        /* Unit check but no sense data. Need basic sense. */
                        if (ccw_device_do_sense(cdev, irb) != 0)
@@ -848,7 +785,7 @@ call_handler_unsol:
        }
        /* Accumulate status and find out if a basic sense is needed. */
        ccw_device_accumulate_irb(cdev, irb);
-       if (cdev->private->flags.dosense) {
+       if (is_cmd && cdev->private->flags.dosense) {
                if (ccw_device_do_sense(cdev, irb) == 0) {
                        cdev->private->state = DEV_STATE_W4SENSE;
                }
@@ -892,9 +829,9 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
 
        irb = (struct irb *) __LC_IRB;
        /* Check for unsolicited interrupt. */
-       if (irb->scsw.stctl ==
-                       (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
-               if (irb->scsw.cc == 1)
+       if (scsw_stctl(&irb->scsw) ==
+           (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
+               if (scsw_cc(&irb->scsw) == 1)
                        /* Basic sense hasn't started. Try again. */
                        ccw_device_do_sense(cdev, irb);
                else {
@@ -912,7 +849,8 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
         * only deliver the halt/clear interrupt to the device driver as if it
         * had killed the original request.
         */
-       if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
+       if (scsw_fctl(&irb->scsw) &
+           (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
                /* Retry Basic Sense if requested. */
                if (cdev->private->flags.intretry) {
                        cdev->private->flags.intretry = 0;
@@ -986,12 +924,10 @@ ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
                              ERR_PTR(-EIO));
 }
 
-void device_kill_io(struct subchannel *sch)
+void ccw_device_kill_io(struct ccw_device *cdev)
 {
        int ret;
-       struct ccw_device *cdev;
 
-       cdev = sch_get_cdev(sch);
        ret = ccw_device_cancel_halt_clear(cdev);
        if (ret == -EBUSY) {
                ccw_device_set_timeout(cdev, 3*HZ);
@@ -1021,9 +957,9 @@ ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
        case DEV_EVENT_INTERRUPT:
                irb = (struct irb *) __LC_IRB;
                /* Check for unsolicited interrupt. */
-               if ((irb->scsw.stctl ==
+               if ((scsw_stctl(&irb->scsw) ==
                     (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
-                   (!irb->scsw.cc))
+                   (!scsw_cc(&irb->scsw)))
                        /* FIXME: we should restart stlck here, but this
                         * is extremely unlikely ... */
                        goto out_wakeup;
@@ -1055,17 +991,14 @@ ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
        ccw_device_sense_id_start(cdev);
 }
 
-void
-device_trigger_reprobe(struct subchannel *sch)
+void ccw_device_trigger_reprobe(struct ccw_device *cdev)
 {
-       struct ccw_device *cdev;
+       struct subchannel *sch;
 
-       cdev = sch_get_cdev(sch);
-       if (!cdev)
-               return;
        if (cdev->private->state != DEV_STATE_DISCONNECTED)
                return;
 
+       sch = to_subchannel(cdev->dev.parent);
        /* Update some values. */
        if (stsch(sch->schid, &sch->schib))
                return;
@@ -1081,7 +1014,6 @@ device_trigger_reprobe(struct subchannel *sch)
        sch->schib.pmcw.ena = 0;
        if ((sch->lpm & (sch->lpm - 1)) != 0)
                sch->schib.pmcw.mp = 1;
-       sch->schib.pmcw.intparm = (u32)(addr_t)sch;
        /* We should also udate ssd info, but this has to wait. */
        /* Check if this is another device which appeared on the same sch. */
        if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
index cba7020..1bdaa61 100644 (file)
@@ -196,7 +196,7 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
        irb = &cdev->private->irb;
 
        /* Check the error cases. */
-       if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
                /* Retry Sense ID if requested. */
                if (cdev->private->flags.intretry) {
                        cdev->private->flags.intretry = 0;
@@ -234,10 +234,10 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
                              irb->ecw[6], irb->ecw[7]);
                return -EAGAIN;
        }
-       if (irb->scsw.cc == 3) {
+       if (irb->scsw.cmd.cc == 3) {
                u8 lpm;
 
-               lpm = to_io_private(sch)->orb.lpm;
+               lpm = to_io_private(sch)->orb.cmd.lpm;
                if ((lpm & sch->schib.pmcw.pim & sch->schib.pmcw.pam) != 0)
                        CIO_MSG_EVENT(4, "SenseID : path %02X for device %04x "
                                      "on subchannel 0.%x.%04x is "
@@ -248,9 +248,9 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
        }
 
        /* Did we get a proper answer ? */
-       if (irb->scsw.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF &&
+       if (irb->scsw.cmd.cc == 0 && cdev->private->senseid.cu_type != 0xFFFF &&
            cdev->private->senseid.reserved == 0xFF) {
-               if (irb->scsw.count < sizeof(struct senseid) - 8)
+               if (irb->scsw.cmd.count < sizeof(struct senseid) - 8)
                        cdev->private->flags.esid = 1;
                return 0; /* Success */
        }
@@ -260,7 +260,7 @@ ccw_device_check_sense_id(struct ccw_device *cdev)
                      "subchannel 0.%x.%04x returns status %02X%02X\n",
                      cdev->private->dev_id.devno, sch->schid.ssid,
                      sch->schid.sch_no,
-                     irb->scsw.dstat, irb->scsw.cstat);
+                     irb->scsw.cmd.dstat, irb->scsw.cmd.cstat);
        return -EAGAIN;
 }
 
@@ -277,9 +277,9 @@ ccw_device_sense_id_irq(struct ccw_device *cdev, enum dev_event dev_event)
        sch = to_subchannel(cdev->dev.parent);
        irb = (struct irb *) __LC_IRB;
        /* Retry sense id, if needed. */
-       if (irb->scsw.stctl ==
+       if (irb->scsw.cmd.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
-               if ((irb->scsw.cc == 1) || !irb->scsw.actl) {
+               if ((irb->scsw.cmd.cc == 1) || !irb->scsw.cmd.actl) {
                        ret = __ccw_device_sense_id_start(cdev);
                        if (ret && ret != -EBUSY)
                                ccw_device_sense_id_done(cdev, ret);
index f308ad5..ee1a283 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/ccwdev.h>
 #include <asm/idals.h>
 #include <asm/chpid.h>
+#include <asm/fcx.h>
 
 #include "cio.h"
 #include "cio_debug.h"
@@ -179,8 +180,8 @@ int ccw_device_start_key(struct ccw_device *cdev, struct ccw1 *cpa,
                        return -EBUSY;
        }
        if (cdev->private->state != DEV_STATE_ONLINE ||
-           ((sch->schib.scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
-            !(sch->schib.scsw.stctl & SCSW_STCTL_SEC_STATUS)) ||
+           ((sch->schib.scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
+            !(sch->schib.scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS)) ||
            cdev->private->flags.doverify)
                return -EBUSY;
        ret = cio_set_options (sch, flags);
@@ -379,7 +380,7 @@ int ccw_device_resume(struct ccw_device *cdev)
        if (cdev->private->state == DEV_STATE_NOT_OPER)
                return -ENODEV;
        if (cdev->private->state != DEV_STATE_ONLINE ||
-           !(sch->schib.scsw.actl & SCSW_ACTL_SUSPENDED))
+           !(sch->schib.scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
                return -EINVAL;
        return cio_resume(sch);
 }
@@ -404,7 +405,7 @@ ccw_device_call_handler(struct ccw_device *cdev)
         *  - fast notification was requested (primary status)
         *  - unsolicited interrupts
         */
-       stctl = cdev->private->irb.scsw.stctl;
+       stctl = scsw_stctl(&cdev->private->irb.scsw);
        ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
                (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
                (stctl == SCSW_STCTL_STATUS_PEND);
@@ -528,14 +529,15 @@ ccw_device_stlck(struct ccw_device *cdev)
                cio_disable_subchannel(sch); //FIXME: return code?
                goto out_unlock;
        }
-       cdev->private->irb.scsw.actl |= SCSW_ACTL_START_PEND;
+       cdev->private->irb.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
        spin_unlock_irqrestore(sch->lock, flags);
-       wait_event(cdev->private->wait_q, cdev->private->irb.scsw.actl == 0);
+       wait_event(cdev->private->wait_q,
+                  cdev->private->irb.scsw.cmd.actl == 0);
        spin_lock_irqsave(sch->lock, flags);
        cio_disable_subchannel(sch); //FIXME: return code?
-       if ((cdev->private->irb.scsw.dstat !=
+       if ((cdev->private->irb.scsw.cmd.dstat !=
             (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
-           (cdev->private->irb.scsw.cstat != 0))
+           (cdev->private->irb.scsw.cmd.cstat != 0))
                ret = -EIO;
        /* Clear irb. */
        memset(&cdev->private->irb, 0, sizeof(struct irb));
@@ -568,6 +570,122 @@ void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
 }
 EXPORT_SYMBOL(ccw_device_get_id);
 
+/**
+ * ccw_device_tm_start_key - perform start function
+ * @cdev: ccw device on which to perform the start function
+ * @tcw: transport-command word to be started
+ * @intparm: user defined parameter to be passed to the interrupt handler
+ * @lpm: mask of paths to use
+ * @key: storage key to use for storage access
+ *
+ * Start the tcw on the given ccw device. Return zero on success, non-zero
+ * otherwise.
+ */
+int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
+                           unsigned long intparm, u8 lpm, u8 key)
+{
+       struct subchannel *sch;
+       int rc;
+
+       sch = to_subchannel(cdev->dev.parent);
+       if (cdev->private->state != DEV_STATE_ONLINE)
+               return -EIO;
+       /* Adjust requested path mask to excluded varied off paths. */
+       if (lpm) {
+               lpm &= sch->opm;
+               if (lpm == 0)
+                       return -EACCES;
+       }
+       rc = cio_tm_start_key(sch, tcw, lpm, key);
+       if (rc == 0)
+               cdev->private->intparm = intparm;
+       return rc;
+}
+EXPORT_SYMBOL(ccw_device_tm_start_key);
+
+/**
+ * ccw_device_tm_start_timeout_key - perform start function
+ * @cdev: ccw device on which to perform the start function
+ * @tcw: transport-command word to be started
+ * @intparm: user defined parameter to be passed to the interrupt handler
+ * @lpm: mask of paths to use
+ * @key: storage key to use for storage access
+ * @expires: time span in jiffies after which to abort request
+ *
+ * Start the tcw on the given ccw device. Return zero on success, non-zero
+ * otherwise.
+ */
+int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,
+                                   unsigned long intparm, u8 lpm, u8 key,
+                                   int expires)
+{
+       int ret;
+
+       ccw_device_set_timeout(cdev, expires);
+       ret = ccw_device_tm_start_key(cdev, tcw, intparm, lpm, key);
+       if (ret != 0)
+               ccw_device_set_timeout(cdev, 0);
+       return ret;
+}
+EXPORT_SYMBOL(ccw_device_tm_start_timeout_key);
+
+/**
+ * ccw_device_tm_start - perform start function
+ * @cdev: ccw device on which to perform the start function
+ * @tcw: transport-command word to be started
+ * @intparm: user defined parameter to be passed to the interrupt handler
+ * @lpm: mask of paths to use
+ *
+ * Start the tcw on the given ccw device. Return zero on success, non-zero
+ * otherwise.
+ */
+int ccw_device_tm_start(struct ccw_device *cdev, struct tcw *tcw,
+                       unsigned long intparm, u8 lpm)
+{
+       return ccw_device_tm_start_key(cdev, tcw, intparm, lpm,
+                                      PAGE_DEFAULT_KEY);
+}
+EXPORT_SYMBOL(ccw_device_tm_start);
+
+/**
+ * ccw_device_tm_start_timeout - perform start function
+ * @cdev: ccw device on which to perform the start function
+ * @tcw: transport-command word to be started
+ * @intparm: user defined parameter to be passed to the interrupt handler
+ * @lpm: mask of paths to use
+ * @expires: time span in jiffies after which to abort request
+ *
+ * Start the tcw on the given ccw device. Return zero on success, non-zero
+ * otherwise.
+ */
+int ccw_device_tm_start_timeout(struct ccw_device *cdev, struct tcw *tcw,
+                              unsigned long intparm, u8 lpm, int expires)
+{
+       return ccw_device_tm_start_timeout_key(cdev, tcw, intparm, lpm,
+                                              PAGE_DEFAULT_KEY, expires);
+}
+EXPORT_SYMBOL(ccw_device_tm_start_timeout);
+
+/**
+ * ccw_device_tm_intrg - perform interrogate function
+ * @cdev: ccw device on which to perform the interrogate function
+ *
+ * Perform an interrogate function on the given ccw device. Return zero on
+ * success, non-zero otherwise.
+ */
+int ccw_device_tm_intrg(struct ccw_device *cdev)
+{
+       struct subchannel *sch = to_subchannel(cdev->dev.parent);
+
+       if (cdev->private->state != DEV_STATE_ONLINE)
+               return -EIO;
+       if (!scsw_is_tm(&sch->schib.scsw) ||
+           !(scsw_actl(&sch->schib.scsw) | SCSW_ACTL_START_PEND))
+               return -EINVAL;
+       return cio_tm_intrg(sch);
+}
+EXPORT_SYMBOL(ccw_device_tm_intrg);
+
 // FIXME: these have to go:
 
 int
index 5cf7be0..86bc94e 100644 (file)
  * Helper function called from interrupt context to decide whether an
  * operation should be tried again.
  */
-static int __ccw_device_should_retry(struct scsw *scsw)
+static int __ccw_device_should_retry(union scsw *scsw)
 {
        /* CC is only valid if start function bit is set. */
-       if ((scsw->fctl & SCSW_FCTL_START_FUNC) && scsw->cc == 1)
+       if ((scsw->cmd.fctl & SCSW_FCTL_START_FUNC) && scsw->cmd.cc == 1)
                return 1;
        /* No more activity. For sense and set PGID we stubbornly try again. */
-       if (!scsw->actl)
+       if (!scsw->cmd.actl)
                return 1;
        return 0;
 }
@@ -125,7 +125,7 @@ __ccw_device_check_sense_pgid(struct ccw_device *cdev)
 
        sch = to_subchannel(cdev->dev.parent);
        irb = &cdev->private->irb;
-       if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
                /* Retry Sense PGID if requested. */
                if (cdev->private->flags.intretry) {
                        cdev->private->flags.intretry = 0;
@@ -155,10 +155,10 @@ __ccw_device_check_sense_pgid(struct ccw_device *cdev)
                              irb->ecw[6], irb->ecw[7]);
                return -EAGAIN;
        }
-       if (irb->scsw.cc == 3) {
+       if (irb->scsw.cmd.cc == 3) {
                u8 lpm;
 
-               lpm = to_io_private(sch)->orb.lpm;
+               lpm = to_io_private(sch)->orb.cmd.lpm;
                CIO_MSG_EVENT(3, "SNID - Device %04x on Subchannel 0.%x.%04x,"
                              " lpm %02X, became 'not operational'\n",
                              cdev->private->dev_id.devno, sch->schid.ssid,
@@ -188,7 +188,7 @@ ccw_device_sense_pgid_irq(struct ccw_device *cdev, enum dev_event dev_event)
 
        irb = (struct irb *) __LC_IRB;
 
-       if (irb->scsw.stctl ==
+       if (irb->scsw.cmd.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
                if (__ccw_device_should_retry(&irb->scsw)) {
                        ret = __ccw_device_sense_pgid_start(cdev);
@@ -331,7 +331,7 @@ __ccw_device_check_pgid(struct ccw_device *cdev)
 
        sch = to_subchannel(cdev->dev.parent);
        irb = &cdev->private->irb;
-       if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
                /* Retry Set PGID if requested. */
                if (cdev->private->flags.intretry) {
                        cdev->private->flags.intretry = 0;
@@ -355,7 +355,7 @@ __ccw_device_check_pgid(struct ccw_device *cdev)
                              irb->ecw[6], irb->ecw[7]);
                return -EAGAIN;
        }
-       if (irb->scsw.cc == 3) {
+       if (irb->scsw.cmd.cc == 3) {
                CIO_MSG_EVENT(3, "SPID - Device %04x on Subchannel 0.%x.%04x,"
                              " lpm %02X, became 'not operational'\n",
                              cdev->private->dev_id.devno, sch->schid.ssid,
@@ -376,7 +376,7 @@ static int __ccw_device_check_nop(struct ccw_device *cdev)
 
        sch = to_subchannel(cdev->dev.parent);
        irb = &cdev->private->irb;
-       if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
                /* Retry NOP if requested. */
                if (cdev->private->flags.intretry) {
                        cdev->private->flags.intretry = 0;
@@ -384,7 +384,7 @@ static int __ccw_device_check_nop(struct ccw_device *cdev)
                }
                return -ETIME;
        }
-       if (irb->scsw.cc == 3) {
+       if (irb->scsw.cmd.cc == 3) {
                CIO_MSG_EVENT(3, "NOP - Device %04x on Subchannel 0.%x.%04x,"
                              " lpm %02X, became 'not operational'\n",
                              cdev->private->dev_id.devno, sch->schid.ssid,
@@ -438,7 +438,7 @@ ccw_device_verify_irq(struct ccw_device *cdev, enum dev_event dev_event)
 
        irb = (struct irb *) __LC_IRB;
 
-       if (irb->scsw.stctl ==
+       if (irb->scsw.cmd.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
                if (__ccw_device_should_retry(&irb->scsw))
                        __ccw_device_verify_start(cdev);
@@ -544,7 +544,7 @@ ccw_device_disband_irq(struct ccw_device *cdev, enum dev_event dev_event)
 
        irb = (struct irb *) __LC_IRB;
 
-       if (irb->scsw.stctl ==
+       if (irb->scsw.cmd.stctl ==
            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
                if (__ccw_device_should_retry(&irb->scsw))
                        __ccw_device_disband_start(cdev);
index 4a38993..1b03c54 100644 (file)
 static void
 ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
 {
-       if (!(irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
-                                SCHN_STAT_CHN_CTRL_CHK |
-                                SCHN_STAT_INTF_CTRL_CHK)))
+       char dbf_text[15];
+
+       if (!scsw_is_valid_cstat(&irb->scsw) ||
+           !(scsw_cstat(&irb->scsw) & (SCHN_STAT_CHN_DATA_CHK |
+             SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK)))
                return;
        CIO_MSG_EVENT(0, "Channel-Check or Interface-Control-Check "
                      "received"
@@ -39,15 +41,10 @@ ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
                      ": %02X sch_stat : %02X\n",
                      cdev->private->dev_id.devno, cdev->private->schid.ssid,
                      cdev->private->schid.sch_no,
-                     irb->scsw.dstat, irb->scsw.cstat);
-
-       if (irb->scsw.cc != 3) {
-               char dbf_text[15];
-
-               sprintf(dbf_text, "chk%x", cdev->private->schid.sch_no);
-               CIO_TRACE_EVENT(0, dbf_text);
-               CIO_HEX_EVENT(0, irb, sizeof (struct irb));
-       }
+                     scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw));
+       sprintf(dbf_text, "chk%x", cdev->private->schid.sch_no);
+       CIO_TRACE_EVENT(0, dbf_text);
+       CIO_HEX_EVENT(0, irb, sizeof(struct irb));
 }
 
 /*
@@ -81,12 +78,12 @@ ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
         * are condition that have to be met for the extended control
         * bit to have meaning. Sick.
         */
-       cdev->private->irb.scsw.ectl = 0;
-       if ((irb->scsw.stctl & SCSW_STCTL_ALERT_STATUS) &&
-           !(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS))
-               cdev->private->irb.scsw.ectl = irb->scsw.ectl;
+       cdev->private->irb.scsw.cmd.ectl = 0;
+       if ((irb->scsw.cmd.stctl & SCSW_STCTL_ALERT_STATUS) &&
+           !(irb->scsw.cmd.stctl & SCSW_STCTL_INTER_STATUS))
+               cdev->private->irb.scsw.cmd.ectl = irb->scsw.cmd.ectl;
        /* Check if extended control word is valid. */
-       if (!cdev->private->irb.scsw.ectl)
+       if (!cdev->private->irb.scsw.cmd.ectl)
                return;
        /* Copy concurrent sense / model dependent information. */
        memcpy (&cdev->private->irb.ecw, irb->ecw, sizeof (irb->ecw));
@@ -98,11 +95,12 @@ ccw_device_accumulate_ecw(struct ccw_device *cdev, struct irb *irb)
 static int
 ccw_device_accumulate_esw_valid(struct irb *irb)
 {
-       if (!irb->scsw.eswf && irb->scsw.stctl == SCSW_STCTL_STATUS_PEND)
+       if (!irb->scsw.cmd.eswf &&
+           (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND))
                return 0;
-       if (irb->scsw.stctl == 
-                       (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
-           !(irb->scsw.actl & SCSW_ACTL_SUSPENDED))
+       if (irb->scsw.cmd.stctl ==
+                       (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND) &&
+           !(irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
                return 0;
        return 1;
 }
@@ -125,7 +123,7 @@ ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
        cdev_irb->esw.esw1.lpum = irb->esw.esw1.lpum;
 
        /* Copy subchannel logout information if esw is of format 0. */
-       if (irb->scsw.eswf) {
+       if (irb->scsw.cmd.eswf) {
                cdev_sublog = &cdev_irb->esw.esw0.sublog;
                sublog = &irb->esw.esw0.sublog;
                /* Copy extended status flags. */
@@ -134,7 +132,7 @@ ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
                 * Copy fields that have a meaning for channel data check
                 * channel control check and interface control check.
                 */
-               if (irb->scsw.cstat & (SCHN_STAT_CHN_DATA_CHK |
+               if (irb->scsw.cmd.cstat & (SCHN_STAT_CHN_DATA_CHK |
                                       SCHN_STAT_CHN_CTRL_CHK |
                                       SCHN_STAT_INTF_CTRL_CHK)) {
                        /* Copy ancillary report bit. */
@@ -155,7 +153,7 @@ ccw_device_accumulate_esw(struct ccw_device *cdev, struct irb *irb)
                /* Copy i/o-error alert. */
                cdev_sublog->ioerr = sublog->ioerr;
                /* Copy channel path timeout bit. */
-               if (irb->scsw.cstat & SCHN_STAT_INTF_CTRL_CHK)
+               if (irb->scsw.cmd.cstat & SCHN_STAT_INTF_CTRL_CHK)
                        cdev_irb->esw.esw0.erw.cpt = irb->esw.esw0.erw.cpt;
                /* Copy failing storage address validity flag. */
                cdev_irb->esw.esw0.erw.fsavf = irb->esw.esw0.erw.fsavf;
@@ -200,24 +198,24 @@ ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
         * If not, the remaining bit have no meaning and we must ignore them.
         * The esw is not meaningful as well...
         */
-       if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
+       if (!(scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))
                return;
 
        /* Check for channel checks and interface control checks. */
        ccw_device_msg_control_check(cdev, irb);
 
        /* Check for path not operational. */
-       if (irb->scsw.pno && irb->scsw.fctl != 0 &&
-           (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
-            (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
+       if (scsw_is_valid_pno(&irb->scsw) && scsw_pno(&irb->scsw))
                ccw_device_path_notoper(cdev);
-
+       /* No irb accumulation for transport mode irbs. */
+       if (scsw_is_tm(&irb->scsw)) {
+               memcpy(&cdev->private->irb, irb, sizeof(struct irb));
+               return;
+       }
        /*
         * Don't accumulate unsolicited interrupts.
         */
-       if ((irb->scsw.stctl ==
-            (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
-           (!irb->scsw.cc))
+       if (!scsw_is_solicited(&irb->scsw))
                return;
 
        cdev_irb = &cdev->private->irb;
@@ -227,62 +225,63 @@ ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
         * status at the subchannel has been cleared and we must not pass
         * intermediate accumulated status to the device driver.
         */
-       if (irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC)
+       if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC)
                memset(&cdev->private->irb, 0, sizeof(struct irb));
 
        /* Copy bits which are valid only for the start function. */
-       if (irb->scsw.fctl & SCSW_FCTL_START_FUNC) {
+       if (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC) {
                /* Copy key. */
-               cdev_irb->scsw.key = irb->scsw.key;
+               cdev_irb->scsw.cmd.key = irb->scsw.cmd.key;
                /* Copy suspend control bit. */
-               cdev_irb->scsw.sctl = irb->scsw.sctl;
+               cdev_irb->scsw.cmd.sctl = irb->scsw.cmd.sctl;
                /* Accumulate deferred condition code. */
-               cdev_irb->scsw.cc |= irb->scsw.cc;
+               cdev_irb->scsw.cmd.cc |= irb->scsw.cmd.cc;
                /* Copy ccw format bit. */
-               cdev_irb->scsw.fmt = irb->scsw.fmt;
+               cdev_irb->scsw.cmd.fmt = irb->scsw.cmd.fmt;
                /* Copy prefetch bit. */
-               cdev_irb->scsw.pfch = irb->scsw.pfch;
+               cdev_irb->scsw.cmd.pfch = irb->scsw.cmd.pfch;
                /* Copy initial-status-interruption-control. */
-               cdev_irb->scsw.isic = irb->scsw.isic;
+               cdev_irb->scsw.cmd.isic = irb->scsw.cmd.isic;
                /* Copy address limit checking control. */
-               cdev_irb->scsw.alcc = irb->scsw.alcc;
+               cdev_irb->scsw.cmd.alcc = irb->scsw.cmd.alcc;
                /* Copy suppress suspend bit. */
-               cdev_irb->scsw.ssi = irb->scsw.ssi;
+               cdev_irb->scsw.cmd.ssi = irb->scsw.cmd.ssi;
        }
 
        /* Take care of the extended control bit and extended control word. */
        ccw_device_accumulate_ecw(cdev, irb);
            
        /* Accumulate function control. */
-       cdev_irb->scsw.fctl |= irb->scsw.fctl;
+       cdev_irb->scsw.cmd.fctl |= irb->scsw.cmd.fctl;
        /* Copy activity control. */
-       cdev_irb->scsw.actl= irb->scsw.actl;
+       cdev_irb->scsw.cmd.actl = irb->scsw.cmd.actl;
        /* Accumulate status control. */
-       cdev_irb->scsw.stctl |= irb->scsw.stctl;
+       cdev_irb->scsw.cmd.stctl |= irb->scsw.cmd.stctl;
        /*
         * Copy ccw address if it is valid. This is a bit simplified
         * but should be close enough for all practical purposes.
         */
-       if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) ||
-           ((irb->scsw.stctl == 
+       if ((irb->scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) ||
+           ((irb->scsw.cmd.stctl ==
              (SCSW_STCTL_INTER_STATUS|SCSW_STCTL_STATUS_PEND)) &&
-            (irb->scsw.actl & SCSW_ACTL_DEVACT) &&
-            (irb->scsw.actl & SCSW_ACTL_SCHACT)) ||
-           (irb->scsw.actl & SCSW_ACTL_SUSPENDED))
-               cdev_irb->scsw.cpa = irb->scsw.cpa;
+            (irb->scsw.cmd.actl & SCSW_ACTL_DEVACT) &&
+            (irb->scsw.cmd.actl & SCSW_ACTL_SCHACT)) ||
+           (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED))
+               cdev_irb->scsw.cmd.cpa = irb->scsw.cmd.cpa;
        /* Accumulate device status, but not the device busy flag. */
-       cdev_irb->scsw.dstat &= ~DEV_STAT_BUSY;
+       cdev_irb->scsw.cmd.dstat &= ~DEV_STAT_BUSY;
        /* dstat is not always valid. */
-       if (irb->scsw.stctl &
+       if (irb->scsw.cmd.stctl &
            (SCSW_STCTL_PRIM_STATUS | SCSW_STCTL_SEC_STATUS
             | SCSW_STCTL_INTER_STATUS | SCSW_STCTL_ALERT_STATUS))
-               cdev_irb->scsw.dstat |= irb->scsw.dstat;
+               cdev_irb->scsw.cmd.dstat |= irb->scsw.cmd.dstat;
        /* Accumulate subchannel status. */
-       cdev_irb->scsw.cstat |= irb->scsw.cstat;
+       cdev_irb->scsw.cmd.cstat |= irb->scsw.cmd.cstat;
        /* Copy residual count if it is valid. */
-       if ((irb->scsw.stctl & SCSW_STCTL_PRIM_STATUS) &&
-           (irb->scsw.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN)) == 0)
-               cdev_irb->scsw.count = irb->scsw.count;
+       if ((irb->scsw.cmd.stctl & SCSW_STCTL_PRIM_STATUS) &&
+           (irb->scsw.cmd.cstat & ~(SCHN_STAT_PCI | SCHN_STAT_INCORR_LEN))
+            == 0)
+               cdev_irb->scsw.cmd.count = irb->scsw.cmd.count;
 
        /* Take care of bits in the extended status word. */
        ccw_device_accumulate_esw(cdev, irb);
@@ -299,7 +298,7 @@ ccw_device_accumulate_irb(struct ccw_device *cdev, struct irb *irb)
         *       sense facility available/supported when enabling the
         *       concurrent sense facility.
         */
-       if ((cdev_irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
+       if ((cdev_irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
            !(cdev_irb->esw.esw0.erw.cons))
                cdev->private->flags.dosense = 1;
 }
@@ -317,7 +316,7 @@ ccw_device_do_sense(struct ccw_device *cdev, struct irb *irb)
        sch = to_subchannel(cdev->dev.parent);
 
        /* A sense is required, can we do it now ? */
-       if ((irb->scsw.actl  & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
+       if (scsw_actl(&irb->scsw) & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT))
                /*
                 * we received an Unit Check but we have no final
                 *  status yet, therefore we must delay the SENSE
@@ -355,20 +354,18 @@ ccw_device_accumulate_basic_sense(struct ccw_device *cdev, struct irb *irb)
         * If not, the remaining bit have no meaning and we must ignore them.
         * The esw is not meaningful as well...
         */
-       if (!(irb->scsw.stctl & SCSW_STCTL_STATUS_PEND))
+       if (!(scsw_stctl(&irb->scsw) & SCSW_STCTL_STATUS_PEND))
                return;
 
        /* Check for channel checks and interface control checks. */
        ccw_device_msg_control_check(cdev, irb);
 
        /* Check for path not operational. */
-       if (irb->scsw.pno && irb->scsw.fctl != 0 &&
-           (!(irb->scsw.stctl & SCSW_STCTL_INTER_STATUS) ||
-            (irb->scsw.actl & SCSW_ACTL_SUSPENDED)))
+       if (scsw_is_valid_pno(&irb->scsw) && scsw_pno(&irb->scsw))
                ccw_device_path_notoper(cdev);
 
-       if (!(irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
-           (irb->scsw.dstat & DEV_STAT_CHN_END)) {
+       if (!(irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
+           (irb->scsw.cmd.dstat & DEV_STAT_CHN_END)) {
                cdev->private->irb.esw.esw0.erw.cons = 1;
                cdev->private->flags.dosense = 0;
        }
@@ -386,11 +383,11 @@ int
 ccw_device_accumulate_and_sense(struct ccw_device *cdev, struct irb *irb)
 {
        ccw_device_accumulate_irb(cdev, irb);
-       if ((irb->scsw.actl  & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
+       if ((irb->scsw.cmd.actl  & (SCSW_ACTL_DEVACT | SCSW_ACTL_SCHACT)) != 0)
                return -EBUSY;
        /* Check for basic sense. */
        if (cdev->private->flags.dosense &&
-           !(irb->scsw.dstat & DEV_STAT_UNIT_CHECK)) {
+           !(irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)) {
                cdev->private->irb.esw.esw0.erw.cons = 1;
                cdev->private->flags.dosense = 0;
                return 0;
diff --git a/drivers/s390/cio/fcx.c b/drivers/s390/cio/fcx.c
new file mode 100644 (file)
index 0000000..61677df
--- /dev/null
@@ -0,0 +1,350 @@
+/*
+ *  Functions for assembling fcx enabled I/O control blocks.
+ *
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <asm/fcx.h>
+#include "cio.h"
+
+/**
+ * tcw_get_intrg - return pointer to associated interrogate tcw
+ * @tcw: pointer to the original tcw
+ *
+ * Return a pointer to the interrogate tcw associated with the specified tcw
+ * or %NULL if there is no associated interrogate tcw.
+ */
+struct tcw *tcw_get_intrg(struct tcw *tcw)
+{
+       return (struct tcw *) ((addr_t) tcw->intrg);
+}
+EXPORT_SYMBOL(tcw_get_intrg);
+
+/**
+ * tcw_get_data - return pointer to input/output data associated with tcw
+ * @tcw: pointer to the tcw
+ *
+ * Return the input or output data address specified in the tcw depending
+ * on whether the r-bit or the w-bit is set. If neither bit is set, return
+ * %NULL.
+ */
+void *tcw_get_data(struct tcw *tcw)
+{
+       if (tcw->r)
+               return (void *) ((addr_t) tcw->input);
+       if (tcw->w)
+               return (void *) ((addr_t) tcw->output);
+       return NULL;
+}
+EXPORT_SYMBOL(tcw_get_data);
+
+/**
+ * tcw_get_tccb - return pointer to tccb associated with tcw
+ * @tcw: pointer to the tcw
+ *
+ * Return pointer to the tccb associated with this tcw.
+ */
+struct tccb *tcw_get_tccb(struct tcw *tcw)
+{
+       return (struct tccb *) ((addr_t) tcw->tccb);
+}
+EXPORT_SYMBOL(tcw_get_tccb);
+
+/**
+ * tcw_get_tsb - return pointer to tsb associated with tcw
+ * @tcw: pointer to the tcw
+ *
+ * Return pointer to the tsb associated with this tcw.
+ */
+struct tsb *tcw_get_tsb(struct tcw *tcw)
+{
+       return (struct tsb *) ((addr_t) tcw->tsb);
+}
+EXPORT_SYMBOL(tcw_get_tsb);
+
+/**
+ * tcw_init - initialize tcw data structure
+ * @tcw: pointer to the tcw to be initialized
+ * @r: initial value of the r-bit
+ * @w: initial value of the w-bit
+ *
+ * Initialize all fields of the specified tcw data structure with zero and
+ * fill in the format, flags, r and w fields.
+ */
+void tcw_init(struct tcw *tcw, int r, int w)
+{
+       memset(tcw, 0, sizeof(struct tcw));
+       tcw->format = TCW_FORMAT_DEFAULT;
+       tcw->flags = TCW_FLAGS_TIDAW_FORMAT(TCW_TIDAW_FORMAT_DEFAULT);
+       if (r)
+               tcw->r = 1;
+       if (w)
+               tcw->w = 1;
+}
+EXPORT_SYMBOL(tcw_init);
+
+static inline size_t tca_size(struct tccb *tccb)
+{
+       return tccb->tcah.tcal - 12;
+}
+
+static u32 calc_dcw_count(struct tccb *tccb)
+{
+       int offset;
+       struct dcw *dcw;
+       u32 count = 0;
+       size_t size;
+
+       size = tca_size(tccb);
+       for (offset = 0; offset < size;) {
+               dcw = (struct dcw *) &tccb->tca[offset];
+               count += dcw->count;
+               if (!(dcw->flags & DCW_FLAGS_CC))
+                       break;
+               offset += sizeof(struct dcw) + ALIGN((int) dcw->cd_count, 4);
+       }
+       return count;
+}
+
+static u32 calc_cbc_size(struct tidaw *tidaw, int num)
+{
+       int i;
+       u32 cbc_data;
+       u32 cbc_count = 0;
+       u64 data_count = 0;
+
+       for (i = 0; i < num; i++) {
+               if (tidaw[i].flags & TIDAW_FLAGS_LAST)
+                       break;
+               /* TODO: find out if padding applies to total of data
+                * transferred or data transferred by this tidaw. Assumption:
+                * applies to total. */
+               data_count += tidaw[i].count;
+               if (tidaw[i].flags & TIDAW_FLAGS_INSERT_CBC) {
+                       cbc_data = 4 + ALIGN(data_count, 4) - data_count;
+                       cbc_count += cbc_data;
+                       data_count += cbc_data;
+               }
+       }
+       return cbc_count;
+}
+
+/**
+ * tcw_finalize - finalize tcw length fields and tidaw list
+ * @tcw: pointer to the tcw
+ * @num_tidaws: the number of tidaws used to address input/output data or zero
+ * if no tida is used
+ *
+ * Calculate the input-/output-count and tccbl field in the tcw, add a
+ * tcat the tccb and terminate the data tidaw list if used.
+ *
+ * Note: in case input- or output-tida is used, the tidaw-list must be stored
+ * in contiguous storage (no ttic). The tcal field in the tccb must be
+ * up-to-date.
+ */
+void tcw_finalize(struct tcw *tcw, int num_tidaws)
+{
+       struct tidaw *tidaw;
+       struct tccb *tccb;
+       struct tccb_tcat *tcat;
+       u32 count;
+
+       /* Terminate tidaw list. */
+       tidaw = tcw_get_data(tcw);
+       if (num_tidaws > 0)
+               tidaw[num_tidaws - 1].flags |= TIDAW_FLAGS_LAST;
+       /* Add tcat to tccb. */
+       tccb = tcw_get_tccb(tcw);
+       tcat = (struct tccb_tcat *) &tccb->tca[tca_size(tccb)];
+       memset(tcat, 0, sizeof(tcat));
+       /* Calculate tcw input/output count and tcat transport count. */
+       count = calc_dcw_count(tccb);
+       if (tcw->w && (tcw->flags & TCW_FLAGS_OUTPUT_TIDA))
+               count += calc_cbc_size(tidaw, num_tidaws);
+       if (tcw->r)
+               tcw->input_count = count;
+       else if (tcw->w)
+               tcw->output_count = count;
+       tcat->count = ALIGN(count, 4) + 4;
+       /* Calculate tccbl. */
+       tcw->tccbl = (sizeof(struct tccb) + tca_size(tccb) +
+                     sizeof(struct tccb_tcat) - 20) >> 2;
+}
+EXPORT_SYMBOL(tcw_finalize);
+
+/**
+ * tcw_set_intrg - set the interrogate tcw address of a tcw
+ * @tcw: the tcw address
+ * @intrg_tcw: the address of the interrogate tcw
+ *
+ * Set the address of the interrogate tcw in the specified tcw.
+ */
+void tcw_set_intrg(struct tcw *tcw, struct tcw *intrg_tcw)
+{
+       tcw->intrg = (u32) ((addr_t) intrg_tcw);
+}
+EXPORT_SYMBOL(tcw_set_intrg);
+
+/**
+ * tcw_set_data - set data address and tida flag of a tcw
+ * @tcw: the tcw address
+ * @data: the data address
+ * @use_tidal: zero of the data address specifies a contiguous block of data,
+ * non-zero if it specifies a list if tidaws.
+ *
+ * Set the input/output data address of a tcw (depending on the value of the
+ * r-flag and w-flag). If @use_tidal is non-zero, the corresponding tida flag
+ * is set as well.
+ */
+void tcw_set_data(struct tcw *tcw, void *data, int use_tidal)
+{
+       if (tcw->r) {
+               tcw->input = (u64) ((addr_t) data);
+               if (use_tidal)
+                       tcw->flags |= TCW_FLAGS_INPUT_TIDA;
+       } else if (tcw->w) {
+               tcw->output = (u64) ((addr_t) data);
+               if (use_tidal)
+                       tcw->flags |= TCW_FLAGS_OUTPUT_TIDA;
+       }
+}
+EXPORT_SYMBOL(tcw_set_data);
+
+/**
+ * tcw_set_tccb - set tccb address of a tcw
+ * @tcw: the tcw address
+ * @tccb: the tccb address
+ *
+ * Set the address of the tccb in the specified tcw.
+ */
+void tcw_set_tccb(struct tcw *tcw, struct tccb *tccb)
+{
+       tcw->tccb = (u64) ((addr_t) tccb);
+}
+EXPORT_SYMBOL(tcw_set_tccb);
+
+/**
+ * tcw_set_tsb - set tsb address of a tcw
+ * @tcw: the tcw address
+ * @tsb: the tsb address
+ *
+ * Set the address of the tsb in the specified tcw.
+ */
+void tcw_set_tsb(struct tcw *tcw, struct tsb *tsb)
+{
+       tcw->tsb = (u64) ((addr_t) tsb);
+}
+EXPORT_SYMBOL(tcw_set_tsb);
+
+/**
+ * tccb_init - initialize tccb
+ * @tccb: the tccb address
+ * @size: the maximum size of the tccb
+ * @sac: the service-action-code to be user
+ *
+ * Initialize the header of the specified tccb by resetting all values to zero
+ * and filling in defaults for format, sac and initial tcal fields.
+ */
+void tccb_init(struct tccb *tccb, size_t size, u32 sac)
+{
+       memset(tccb, 0, size);
+       tccb->tcah.format = TCCB_FORMAT_DEFAULT;
+       tccb->tcah.sac = sac;
+       tccb->tcah.tcal = 12;
+}
+EXPORT_SYMBOL(tccb_init);
+
+/**
+ * tsb_init - initialize tsb
+ * @tsb: the tsb address
+ *
+ * Initialize the specified tsb by resetting all values to zero.
+ */
+void tsb_init(struct tsb *tsb)
+{
+       memset(tsb, 0, sizeof(tsb));
+}
+EXPORT_SYMBOL(tsb_init);
+
+/**
+ * tccb_add_dcw - add a dcw to the tccb
+ * @tccb: the tccb address
+ * @tccb_size: the maximum tccb size
+ * @cmd: the dcw command
+ * @flags: flags for the dcw
+ * @cd: pointer to control data for this dcw or NULL if none is required
+ * @cd_count: number of control data bytes for this dcw
+ * @count: number of data bytes for this dcw
+ *
+ * Add a new dcw to the specified tccb by writing the dcw information specified
+ * by @cmd, @flags, @cd, @cd_count and @count to the tca of the tccb. Return
+ * a pointer to the newly added dcw on success or -%ENOSPC if the new dcw
+ * would exceed the available space as defined by @tccb_size.
+ *
+ * Note: the tcal field of the tccb header will be updates to reflect added
+ * content.
+ */
+struct dcw *tccb_add_dcw(struct tccb *tccb, size_t tccb_size, u8 cmd, u8 flags,
+                        void *cd, u8 cd_count, u32 count)
+{
+       struct dcw *dcw;
+       int size;
+       int tca_offset;
+
+       /* Check for space. */
+       tca_offset = tca_size(tccb);
+       size = ALIGN(sizeof(struct dcw) + cd_count, 4);
+       if (sizeof(struct tccb_tcah) + tca_offset + size +
+           sizeof(struct tccb_tcat) > tccb_size)
+               return ERR_PTR(-ENOSPC);
+       /* Add dcw to tca. */
+       dcw = (struct dcw *) &tccb->tca[tca_offset];
+       memset(dcw, 0, size);
+       dcw->cmd = cmd;
+       dcw->flags = flags;
+       dcw->count = count;
+       dcw->cd_count = cd_count;
+       if (cd)
+               memcpy(&dcw->cd[0], cd, cd_count);
+       tccb->tcah.tcal += size;
+       return dcw;
+}
+EXPORT_SYMBOL(tccb_add_dcw);
+
+/**
+ * tcw_add_tidaw - add a tidaw to a tcw
+ * @tcw: the tcw address
+ * @num_tidaws: the current number of tidaws
+ * @flags: flags for the new tidaw
+ * @addr: address value for the new tidaw
+ * @count: count value for the new tidaw
+ *
+ * Add a new tidaw to the input/output data tidaw-list of the specified tcw
+ * (depending on the value of the r-flag and w-flag) and return a pointer to
+ * the new tidaw.
+ *
+ * Note: the tidaw-list is assumed to be contiguous with no ttics. The caller
+ * must ensure that there is enough space for the new tidaw. The last-tidaw
+ * flag for the last tidaw in the list will be set by tcw_finalize.
+ */
+struct tidaw *tcw_add_tidaw(struct tcw *tcw, int num_tidaws, u8 flags,
+                           void *addr, u32 count)
+{
+       struct tidaw *tidaw;
+
+       /* Add tidaw to tidaw-list. */
+       tidaw = ((struct tidaw *) tcw_get_data(tcw)) + num_tidaws;
+       memset(tidaw, 0, sizeof(struct tidaw));
+       tidaw->flags = flags;
+       tidaw->count = count;
+       tidaw->addr = (u64) ((addr_t) addr);
+       return tidaw;
+}
+EXPORT_SYMBOL(tcw_add_tidaw);
index 144466a..528065c 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef S390_IDSET_H
 #define S390_IDSET_H S390_IDSET_H
 
-#include "schid.h"
+#include <asm/schid.h>
 
 struct idset;
 
index 8c61316..3f8f1cf 100644 (file)
@@ -1,12 +1,12 @@
 #ifndef S390_IO_SCH_H
 #define S390_IO_SCH_H
 
-#include "schid.h"
+#include <asm/schid.h>
 
 /*
- * operation request block
+ * command-mode operation request block
  */
-struct orb {
+struct cmd_orb {
        u32 intparm;    /* interruption parameter */
        u32 key  : 4;   /* flags, like key, suspend control, etc. */
        u32 spnd : 1;   /* suspend control */
@@ -28,8 +28,36 @@ struct orb {
        u32 cpa;        /* channel program address */
 }  __attribute__ ((packed, aligned(4)));
 
+/*
+ * transport-mode operation request block
+ */
+struct tm_orb {
+       u32 intparm;
+       u32 key:4;
+       u32 :9;
+       u32 b:1;
+       u32 :2;
+       u32 lpm:8;
+       u32 :7;
+       u32 x:1;
+       u32 tcw;
+       u32 prio:8;
+       u32 :8;
+       u32 rsvpgm:8;
+       u32 :8;
+       u32 :32;
+       u32 :32;
+       u32 :32;
+       u32 :32;
+}  __attribute__ ((packed, aligned(4)));
+
+union orb {
+       struct cmd_orb cmd;
+       struct tm_orb tm;
+}  __attribute__ ((packed, aligned(4)));
+
 struct io_subchannel_private {
-       struct orb orb;         /* operation request block */
+       union orb orb;          /* operation request block */
        struct ccw1 sense_ccw;  /* static ccw for sense command */
 } __attribute__ ((aligned(8)));
 
@@ -95,16 +123,18 @@ struct ccw_device_private {
        void *cmb_wait;                 /* deferred cmb enable/disable */
 };
 
-static inline int ssch(struct subchannel_id schid, volatile struct orb *addr)
+static inline int ssch(struct subchannel_id schid, volatile union orb *addr)
 {
        register struct subchannel_id reg1 asm("1") = schid;
-       int ccode;
+       int ccode = -EIO;
 
        asm volatile(
                "       ssch    0(%2)\n"
-               "       ipm     %0\n"
-               "       srl     %0,28"
-               : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
+               "0:     ipm     %0\n"
+               "       srl     %0,28\n"
+               "1:\n"
+               EX_TABLE(0b, 1b)
+               : "+d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
        return ccode;
 }
 
index 652ea36..9fa2ac1 100644 (file)
@@ -2,7 +2,7 @@
 #define S390_CIO_IOASM_H
 
 #include <asm/chpid.h>
-#include "schid.h"
+#include <asm/schid.h>
 
 /*
  * TPI info structure
diff --git a/drivers/s390/cio/isc.c b/drivers/s390/cio/isc.c
new file mode 100644 (file)
index 0000000..c592087
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Functions for registration of I/O interruption subclasses on s390.
+ *
+ * Copyright IBM Corp. 2008
+ * Authors: Sebastian Ott <sebott@linux.vnet.ibm.com>
+ */
+
+#include <linux/spinlock.h>
+#include <linux/module.h>
+#include <asm/isc.h>
+
+static unsigned int isc_refs[MAX_ISC + 1];
+static DEFINE_SPINLOCK(isc_ref_lock);
+
+
+/**
+ * isc_register - register an I/O interruption subclass.
+ * @isc: I/O interruption subclass to register
+ *
+ * The number of users for @isc is increased. If this is the first user to
+ * register @isc, the corresponding I/O interruption subclass mask is enabled.
+ *
+ * Context:
+ *   This function must not be called in interrupt context.
+ */
+void isc_register(unsigned int isc)
+{
+       if (isc > MAX_ISC) {
+               WARN_ON(1);
+               return;
+       }
+
+       spin_lock(&isc_ref_lock);
+       if (isc_refs[isc] == 0)
+               ctl_set_bit(6, 31 - isc);
+       isc_refs[isc]++;
+       spin_unlock(&isc_ref_lock);
+}
+EXPORT_SYMBOL_GPL(isc_register);
+
+/**
+ * isc_unregister - unregister an I/O interruption subclass.
+ * @isc: I/O interruption subclass to unregister
+ *
+ * The number of users for @isc is decreased. If this is the last user to
+ * unregister @isc, the corresponding I/O interruption subclass mask is
+ * disabled.
+ * Note: This function must not be called if isc_register() hasn't been called
+ * before by the driver for @isc.
+ *
+ * Context:
+ *   This function must not be called in interrupt context.
+ */
+void isc_unregister(unsigned int isc)
+{
+       spin_lock(&isc_ref_lock);
+       /* check for misuse */
+       if (isc > MAX_ISC || isc_refs[isc] == 0) {
+               WARN_ON(1);
+               goto out_unlock;
+       }
+       if (isc_refs[isc] == 1)
+               ctl_clear_bit(6, 31 - isc);
+       isc_refs[isc]--;
+out_unlock:
+       spin_unlock(&isc_ref_lock);
+}
+EXPORT_SYMBOL_GPL(isc_unregister);
diff --git a/drivers/s390/cio/itcw.c b/drivers/s390/cio/itcw.c
new file mode 100644 (file)
index 0000000..17da9ab
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+ *  Functions for incremental construction of fcx enabled I/O control blocks.
+ *
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <asm/fcx.h>
+#include <asm/itcw.h>
+
+/**
+ * struct itcw - incremental tcw helper data type
+ *
+ * This structure serves as a handle for the incremental construction of a
+ * tcw and associated tccb, tsb, data tidaw-list plus an optional interrogate
+ * tcw and associated data. The data structures are contained inside a single
+ * contiguous buffer provided by the user.
+ *
+ * The itcw construction functions take care of overall data integrity:
+ * - reset unused fields to zero
+ * - fill in required pointers
+ * - ensure required alignment for data structures
+ * - prevent data structures to cross 4k-byte boundary where required
+ * - calculate tccb-related length fields
+ * - optionally provide ready-made interrogate tcw and associated structures
+ *
+ * Restrictions apply to the itcws created with these construction functions:
+ * - tida only supported for data address, not for tccb
+ * - only contiguous tidaw-lists (no ttic)
+ * - total number of bytes required per itcw may not exceed 4k bytes
+ * - either read or write operation (may not work with r=0 and w=0)
+ *
+ * Example:
+ * struct itcw *itcw;
+ * void *buffer;
+ * size_t size;
+ *
+ * size = itcw_calc_size(1, 2, 0);
+ * buffer = kmalloc(size, GFP_DMA);
+ * if (!buffer)
+ *     return -ENOMEM;
+ * itcw = itcw_init(buffer, size, ITCW_OP_READ, 1, 2, 0);
+ * if (IS_ERR(itcw))
+ *     return PTR_ER(itcw);
+ * itcw_add_dcw(itcw, 0x2, 0, NULL, 0, 72);
+ * itcw_add_tidaw(itcw, 0, 0x30000, 20);
+ * itcw_add_tidaw(itcw, 0, 0x40000, 52);
+ * itcw_finalize(itcw);
+ *
+ */
+struct itcw {
+       struct tcw *tcw;
+       struct tcw *intrg_tcw;
+       int num_tidaws;
+       int max_tidaws;
+       int intrg_num_tidaws;
+       int intrg_max_tidaws;
+};
+
+/**
+ * itcw_get_tcw - return pointer to tcw associated with the itcw
+ * @itcw: address of the itcw
+ *
+ * Return pointer to the tcw associated with the itcw.
+ */
+struct tcw *itcw_get_tcw(struct itcw *itcw)
+{
+       return itcw->tcw;
+}
+EXPORT_SYMBOL(itcw_get_tcw);
+
+/**
+ * itcw_calc_size - return the size of an itcw with the given parameters
+ * @intrg: if non-zero, add an interrogate tcw
+ * @max_tidaws: maximum number of tidaws to be used for data addressing or zero
+ * if no tida is to be used.
+ * @intrg_max_tidaws: maximum number of tidaws to be used for data addressing
+ * by the interrogate tcw, if specified
+ *
+ * Calculate and return the number of bytes required to hold an itcw with the
+ * given parameters and assuming tccbs with maximum size.
+ *
+ * Note that the resulting size also contains bytes needed for alignment
+ * padding as well as padding to ensure that data structures don't cross a
+ * 4k-boundary where required.
+ */
+size_t itcw_calc_size(int intrg, int max_tidaws, int intrg_max_tidaws)
+{
+       size_t len;
+
+       /* Main data. */
+       len = sizeof(struct itcw);
+       len += /* TCW */ sizeof(struct tcw) + /* TCCB */ TCCB_MAX_SIZE +
+              /* TSB */ sizeof(struct tsb) +
+              /* TIDAL */ max_tidaws * sizeof(struct tidaw);
+       /* Interrogate data. */
+       if (intrg) {
+               len += /* TCW */ sizeof(struct tcw) + /* TCCB */ TCCB_MAX_SIZE +
+                      /* TSB */ sizeof(struct tsb) +
+                      /* TIDAL */ intrg_max_tidaws * sizeof(struct tidaw);
+       }
+       /* Maximum required alignment padding. */
+       len += /* Initial TCW */ 63 + /* Interrogate TCCB */ 7;
+       /* Maximum padding for structures that may not cross 4k boundary. */
+       if ((max_tidaws > 0) || (intrg_max_tidaws > 0))
+               len += max(max_tidaws, intrg_max_tidaws) *
+                      sizeof(struct tidaw) - 1;
+       return len;
+}
+EXPORT_SYMBOL(itcw_calc_size);
+
+#define CROSS4K(x, l)  (((x) & ~4095) != ((x + l) & ~4095))
+
+static inline void *fit_chunk(addr_t *start, addr_t end, size_t len,
+                             int align, int check_4k)
+{
+       addr_t addr;
+
+       addr = ALIGN(*start, align);
+       if (check_4k && CROSS4K(addr, len)) {
+               addr = ALIGN(addr, 4096);
+               addr = ALIGN(addr, align);
+       }
+       if (addr + len > end)
+               return ERR_PTR(-ENOSPC);
+       *start = addr + len;
+       return (void *) addr;
+}
+
+/**
+ * itcw_init - initialize incremental tcw data structure
+ * @buffer: address of buffer to use for data structures
+ * @size: number of bytes in buffer
+ * @op: %ITCW_OP_READ for a read operation tcw, %ITCW_OP_WRITE for a write
+ * operation tcw
+ * @intrg: if non-zero, add and initialize an interrogate tcw
+ * @max_tidaws: maximum number of tidaws to be used for data addressing or zero
+ * if no tida is to be used.
+ * @intrg_max_tidaws: maximum number of tidaws to be used for data addressing
+ * by the interrogate tcw, if specified
+ *
+ * Prepare the specified buffer to be used as an incremental tcw, i.e. a
+ * helper data structure that can be used to construct a valid tcw by
+ * successive calls to other helper functions. Note: the buffer needs to be
+ * located below the 2G address limit. The resulting tcw has the following
+ * restrictions:
+ *  - no tccb tidal
+ *  - input/output tidal is contiguous (no ttic)
+ *  - total data should not exceed 4k
+ *  - tcw specifies either read or write operation
+ *
+ * On success, return pointer to the resulting incremental tcw data structure,
+ * ERR_PTR otherwise.
+ */
+struct itcw *itcw_init(void *buffer, size_t size, int op, int intrg,
+                      int max_tidaws, int intrg_max_tidaws)
+{
+       struct itcw *itcw;
+       void *chunk;
+       addr_t start;
+       addr_t end;
+
+       /* Check for 2G limit. */
+       start = (addr_t) buffer;
+       end = start + size;
+       if (end > (1 << 31))
+               return ERR_PTR(-EINVAL);
+       memset(buffer, 0, size);
+       /* ITCW. */
+       chunk = fit_chunk(&start, end, sizeof(struct itcw), 1, 0);
+       if (IS_ERR(chunk))
+               return chunk;
+       itcw = chunk;
+       itcw->max_tidaws = max_tidaws;
+       itcw->intrg_max_tidaws = intrg_max_tidaws;
+       /* Main TCW. */
+       chunk = fit_chunk(&start, end, sizeof(struct tcw), 64, 0);
+       if (IS_ERR(chunk))
+               return chunk;
+       itcw->tcw = chunk;
+       tcw_init(itcw->tcw, (op == ITCW_OP_READ) ? 1 : 0,
+                (op == ITCW_OP_WRITE) ? 1 : 0);
+       /* Interrogate TCW. */
+       if (intrg) {
+               chunk = fit_chunk(&start, end, sizeof(struct tcw), 64, 0);
+               if (IS_ERR(chunk))
+                       return chunk;
+               itcw->intrg_tcw = chunk;
+               tcw_init(itcw->intrg_tcw, 1, 0);
+               tcw_set_intrg(itcw->tcw, itcw->intrg_tcw);
+       }
+       /* Data TIDAL. */
+       if (max_tidaws > 0) {
+               chunk = fit_chunk(&start, end, sizeof(struct tidaw) *
+                                 max_tidaws, 16, 1);
+               if (IS_ERR(chunk))
+                       return chunk;
+               tcw_set_data(itcw->tcw, chunk, 1);
+       }
+       /* Interrogate data TIDAL. */
+       if (intrg && (intrg_max_tidaws > 0)) {
+               chunk = fit_chunk(&start, end, sizeof(struct tidaw) *
+                                 intrg_max_tidaws, 16, 1);
+               if (IS_ERR(chunk))
+                       return chunk;
+               tcw_set_data(itcw->intrg_tcw, chunk, 1);
+       }
+       /* TSB. */
+       chunk = fit_chunk(&start, end, sizeof(struct tsb), 8, 0);
+       if (IS_ERR(chunk))
+               return chunk;
+       tsb_init(chunk);
+       tcw_set_tsb(itcw->tcw, chunk);
+       /* Interrogate TSB. */
+       if (intrg) {
+               chunk = fit_chunk(&start, end, sizeof(struct tsb), 8, 0);
+               if (IS_ERR(chunk))
+                       return chunk;
+               tsb_init(chunk);
+               tcw_set_tsb(itcw->intrg_tcw, chunk);
+       }
+       /* TCCB. */
+       chunk = fit_chunk(&start, end, TCCB_MAX_SIZE, 8, 0);
+       if (IS_ERR(chunk))
+               return chunk;
+       tccb_init(chunk, TCCB_MAX_SIZE, TCCB_SAC_DEFAULT);
+       tcw_set_tccb(itcw->tcw, chunk);
+       /* Interrogate TCCB. */
+       if (intrg) {
+               chunk = fit_chunk(&start, end, TCCB_MAX_SIZE, 8, 0);
+               if (IS_ERR(chunk))
+                       return chunk;
+               tccb_init(chunk, TCCB_MAX_SIZE, TCCB_SAC_INTRG);
+               tcw_set_tccb(itcw->intrg_tcw, chunk);
+               tccb_add_dcw(chunk, TCCB_MAX_SIZE, DCW_CMD_INTRG, 0, NULL,
+                            sizeof(struct dcw_intrg_data), 0);
+               tcw_finalize(itcw->intrg_tcw, 0);
+       }
+       return itcw;
+}
+EXPORT_SYMBOL(itcw_init);
+
+/**
+ * itcw_add_dcw - add a dcw to the itcw
+ * @itcw: address of the itcw
+ * @cmd: the dcw command
+ * @flags: flags for the dcw
+ * @cd: address of control data for this dcw or NULL if none is required
+ * @cd_count: number of control data bytes for this dcw
+ * @count: number of data bytes for this dcw
+ *
+ * Add a new dcw to the specified itcw by writing the dcw information specified
+ * by @cmd, @flags, @cd, @cd_count and @count to the tca of the tccb. Return
+ * a pointer to the newly added dcw on success or -%ENOSPC if the new dcw
+ * would exceed the available space.
+ *
+ * Note: the tcal field of the tccb header will be updated to reflect added
+ * content.
+ */
+struct dcw *itcw_add_dcw(struct itcw *itcw, u8 cmd, u8 flags, void *cd,
+                        u8 cd_count, u32 count)
+{
+       return tccb_add_dcw(tcw_get_tccb(itcw->tcw), TCCB_MAX_SIZE, cmd,
+                           flags, cd, cd_count, count);
+}
+EXPORT_SYMBOL(itcw_add_dcw);
+
+/**
+ * itcw_add_tidaw - add a tidaw to the itcw
+ * @itcw: address of the itcw
+ * @flags: flags for the new tidaw
+ * @addr: address value for the new tidaw
+ * @count: count value for the new tidaw
+ *
+ * Add a new tidaw to the input/output data tidaw-list of the specified itcw
+ * (depending on the value of the r-flag and w-flag). Return a pointer to
+ * the new tidaw on success or -%ENOSPC if the new tidaw would exceed the
+ * available space.
+ *
+ * Note: the tidaw-list is assumed to be contiguous with no ttics. The
+ * last-tidaw flag for the last tidaw in the list will be set by itcw_finalize.
+ */
+struct tidaw *itcw_add_tidaw(struct itcw *itcw, u8 flags, void *addr, u32 count)
+{
+       if (itcw->num_tidaws >= itcw->max_tidaws)
+               return ERR_PTR(-ENOSPC);
+       return tcw_add_tidaw(itcw->tcw, itcw->num_tidaws++, flags, addr, count);
+}
+EXPORT_SYMBOL(itcw_add_tidaw);
+
+/**
+ * itcw_set_data - set data address and tida flag of the itcw
+ * @itcw: address of the itcw
+ * @addr: the data address
+ * @use_tidal: zero of the data address specifies a contiguous block of data,
+ * non-zero if it specifies a list if tidaws.
+ *
+ * Set the input/output data address of the itcw (depending on the value of the
+ * r-flag and w-flag). If @use_tidal is non-zero, the corresponding tida flag
+ * is set as well.
+ */
+void itcw_set_data(struct itcw *itcw, void *addr, int use_tidal)
+{
+       tcw_set_data(itcw->tcw, addr, use_tidal);
+}
+EXPORT_SYMBOL(itcw_set_data);
+
+/**
+ * itcw_finalize - calculate length and count fields of the itcw
+ * @itcw: address of the itcw
+ *
+ * Calculate tcw input-/output-count and tccbl fields and add a tcat the tccb.
+ * In case input- or output-tida is used, the tidaw-list must be stored in
+ * continuous storage (no ttic). The tcal field in the tccb must be
+ * up-to-date.
+ */
+void itcw_finalize(struct itcw *itcw)
+{
+       tcw_finalize(itcw->tcw, itcw->num_tidaws);
+}
+EXPORT_SYMBOL(itcw_finalize);
index 445cf36..2bf36e1 100644 (file)
@@ -2082,7 +2082,6 @@ qdio_timeout_handler(struct ccw_device *cdev)
        default:
                BUG();
        }
-       ccw_device_set_timeout(cdev, 0);
        wake_up(&cdev->private->wait_q);
 }
 
@@ -2121,6 +2120,8 @@ qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                case -EIO:
                        QDIO_PRINT_ERR("i/o error on device %s\n",
                                       cdev->dev.bus_id);
+                       qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR);
+                       wake_up(&cdev->private->wait_q);
                        return;
                case -ETIMEDOUT:
                        qdio_timeout_handler(cdev);
@@ -2139,8 +2140,8 @@ qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        QDIO_DBF_TEXT4(0, trace, dbf_text);
 #endif /* CONFIG_QDIO_DEBUG */
 
-        cstat = irb->scsw.cstat;
-        dstat = irb->scsw.dstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
 
        switch (irq_ptr->state) {
        case QDIO_IRQ_STATE_INACTIVE:
@@ -2353,9 +2354,6 @@ tiqdio_check_chsc_availability(void)
 {
        char dbf_text[15];
 
-       if (!css_characteristics_avail)
-               return -EIO;
-
        /* Check for bit 41. */
        if (!css_general_characteristics.aif) {
                QDIO_PRINT_WARN("Adapter interruption facility not " \
@@ -2667,12 +2665,12 @@ qdio_shutdown(struct ccw_device *cdev, int how)
                spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
        } else if (rc == 0) {
                qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP);
-               ccw_device_set_timeout(cdev, timeout);
                spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags);
 
-               wait_event(cdev->private->wait_q,
-                          irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
-                          irq_ptr->state == QDIO_IRQ_STATE_ERR);
+               wait_event_interruptible_timeout(cdev->private->wait_q,
+                       irq_ptr->state == QDIO_IRQ_STATE_INACTIVE ||
+                       irq_ptr->state == QDIO_IRQ_STATE_ERR,
+                       timeout);
        } else {
                QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for "
                                "device %s\n", result, cdev->dev.bus_id);
@@ -2692,7 +2690,6 @@ qdio_shutdown(struct ccw_device *cdev, int how)
 
        /* Ignore errors. */
        qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE);
-       ccw_device_set_timeout(cdev, 0);
 out:
        up(&irq_ptr->setting_up_sema);
        return result;
@@ -2907,13 +2904,10 @@ qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat)
        QDIO_DBF_TEXT0(0,setup,dbf_text);
        QDIO_DBF_TEXT0(0,trace,dbf_text);
 
-       if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) {
-               ccw_device_set_timeout(cdev, 0);
+       if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat))
                return;
-       }
 
        qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED);
-       ccw_device_set_timeout(cdev, 0);
 }
 
 int
@@ -3196,8 +3190,6 @@ qdio_establish(struct qdio_initialize *init_data)
                                irq_ptr->schid.ssid, irq_ptr->schid.sch_no,
                                result, result2);
                result=result2;
-               if (result)
-                       ccw_device_set_timeout(cdev, 0);
        }
 
        spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags);
@@ -3279,7 +3271,6 @@ qdio_activate(struct ccw_device *cdev, int flags)
 
        spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
 
-       ccw_device_set_timeout(cdev, 0);
        ccw_device_set_options(cdev, CCWDEV_REPORT_ALL);
        result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE,
                                0, DOIO_DENY_PREFETCH);
@@ -3722,7 +3713,8 @@ tiqdio_register_thinints(void)
        char dbf_text[20];
 
        tiqdio_ind =
-               s390_register_adapter_interrupt(&tiqdio_thinint_handler, NULL);
+               s390_register_adapter_interrupt(&tiqdio_thinint_handler, NULL,
+                                               TIQDIO_THININT_ISC);
        if (IS_ERR(tiqdio_ind)) {
                sprintf(dbf_text, "regthn%lx", PTR_ERR(tiqdio_ind));
                QDIO_DBF_TEXT0(0,setup,dbf_text);
@@ -3738,7 +3730,8 @@ static void
 tiqdio_unregister_thinints(void)
 {
        if (tiqdio_ind)
-               s390_unregister_adapter_interrupt(tiqdio_ind);
+               s390_unregister_adapter_interrupt(tiqdio_ind,
+                                                 TIQDIO_THININT_ISC);
 }
 
 static int
@@ -3899,6 +3892,7 @@ init_QDIO(void)
                                            qdio_mempool_alloc,
                                            qdio_mempool_free, NULL);
 
+       isc_register(QDIO_AIRQ_ISC);
        if (tiqdio_check_chsc_availability())
                QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n");
 
@@ -3911,6 +3905,7 @@ static void __exit
 cleanup_QDIO(void)
 {
        tiqdio_unregister_thinints();
+       isc_unregister(QDIO_AIRQ_ISC);
        qdio_remove_procfs_entry();
        qdio_release_qdio_memory();
        qdio_unregister_dbf_views();
index c3df6b2..7656081 100644 (file)
@@ -2,8 +2,8 @@
 #define _CIO_QDIO_H
 
 #include <asm/page.h>
-
-#include "schid.h"
+#include <asm/isc.h>
+#include <asm/schid.h>
 
 #ifdef CONFIG_QDIO_DEBUG
 #define QDIO_VERBOSE_LEVEL 9
@@ -26,7 +26,7 @@
  */
 #define IQDIO_FILL_LEVEL_TO_POLL 4
 
-#define TIQDIO_THININT_ISC 3
+#define TIQDIO_THININT_ISC QDIO_AIRQ_ISC
 #define TIQDIO_DELAY_TARGET 0
 #define QDIO_BUSY_BIT_PATIENCE 100 /* in microsecs */
 #define QDIO_BUSY_BIT_GIVE_UP 10000000 /* 10 seconds */
diff --git a/drivers/s390/cio/schid.h b/drivers/s390/cio/schid.h
deleted file mode 100644 (file)
index 54328fe..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef S390_SCHID_H
-#define S390_SCHID_H
-
-struct subchannel_id {
-       __u32 reserved:13;
-       __u32 ssid:2;
-       __u32 one:1;
-       __u32 sch_no:16;
-} __attribute__ ((packed,aligned(4)));
-
-
-/* Helper function for sane state of pre-allocated subchannel_id. */
-static inline void
-init_subchannel_id(struct subchannel_id *schid)
-{
-       memset(schid, 0, sizeof(struct subchannel_id));
-       schid->one = 1;
-}
-
-static inline int
-schid_equal(struct subchannel_id *schid1, struct subchannel_id *schid2)
-{
-       return !memcmp(schid1, schid2, sizeof(struct subchannel_id));
-}
-
-#endif /* S390_SCHID_H */
diff --git a/drivers/s390/cio/scsw.c b/drivers/s390/cio/scsw.c
new file mode 100644 (file)
index 0000000..f8da25a
--- /dev/null
@@ -0,0 +1,843 @@
+/*
+ *  Helper functions for scsw access.
+ *
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <asm/cio.h>
+#include "css.h"
+#include "chsc.h"
+
+/**
+ * scsw_is_tm - check for transport mode scsw
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the specified scsw is a transport mode scsw, zero
+ * otherwise.
+ */
+int scsw_is_tm(union scsw *scsw)
+{
+       return css_general_characteristics.fcx && (scsw->tm.x == 1);
+}
+EXPORT_SYMBOL(scsw_is_tm);
+
+/**
+ * scsw_key - return scsw key field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the key field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_key(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.key;
+       else
+               return scsw->cmd.key;
+}
+EXPORT_SYMBOL(scsw_key);
+
+/**
+ * scsw_eswf - return scsw eswf field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the eswf field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_eswf(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.eswf;
+       else
+               return scsw->cmd.eswf;
+}
+EXPORT_SYMBOL(scsw_eswf);
+
+/**
+ * scsw_cc - return scsw cc field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the cc field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_cc(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.cc;
+       else
+               return scsw->cmd.cc;
+}
+EXPORT_SYMBOL(scsw_cc);
+
+/**
+ * scsw_ectl - return scsw ectl field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the ectl field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_ectl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.ectl;
+       else
+               return scsw->cmd.ectl;
+}
+EXPORT_SYMBOL(scsw_ectl);
+
+/**
+ * scsw_pno - return scsw pno field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the pno field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_pno(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.pno;
+       else
+               return scsw->cmd.pno;
+}
+EXPORT_SYMBOL(scsw_pno);
+
+/**
+ * scsw_fctl - return scsw fctl field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the fctl field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_fctl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.fctl;
+       else
+               return scsw->cmd.fctl;
+}
+EXPORT_SYMBOL(scsw_fctl);
+
+/**
+ * scsw_actl - return scsw actl field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the actl field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_actl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.actl;
+       else
+               return scsw->cmd.actl;
+}
+EXPORT_SYMBOL(scsw_actl);
+
+/**
+ * scsw_stctl - return scsw stctl field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the stctl field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_stctl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.stctl;
+       else
+               return scsw->cmd.stctl;
+}
+EXPORT_SYMBOL(scsw_stctl);
+
+/**
+ * scsw_dstat - return scsw dstat field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the dstat field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_dstat(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.dstat;
+       else
+               return scsw->cmd.dstat;
+}
+EXPORT_SYMBOL(scsw_dstat);
+
+/**
+ * scsw_cstat - return scsw cstat field
+ * @scsw: pointer to scsw
+ *
+ * Return the value of the cstat field of the specified scsw, regardless of
+ * whether it is a transport mode or command mode scsw.
+ */
+u32 scsw_cstat(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw->tm.cstat;
+       else
+               return scsw->cmd.cstat;
+}
+EXPORT_SYMBOL(scsw_cstat);
+
+/**
+ * scsw_cmd_is_valid_key - check key field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the key field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_key(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_key);
+
+/**
+ * scsw_cmd_is_valid_sctl - check fctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fctl field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_sctl(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_sctl);
+
+/**
+ * scsw_cmd_is_valid_eswf - check eswf field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the eswf field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_eswf(union scsw *scsw)
+{
+       return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_eswf);
+
+/**
+ * scsw_cmd_is_valid_cc - check cc field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cc field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_cc(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) &&
+              (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_cc);
+
+/**
+ * scsw_cmd_is_valid_fmt - check fmt field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fmt field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_fmt(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_fmt);
+
+/**
+ * scsw_cmd_is_valid_pfch - check pfch field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the pfch field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_pfch(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_pfch);
+
+/**
+ * scsw_cmd_is_valid_isic - check isic field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the isic field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_isic(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_isic);
+
+/**
+ * scsw_cmd_is_valid_alcc - check alcc field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the alcc field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_alcc(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_alcc);
+
+/**
+ * scsw_cmd_is_valid_ssi - check ssi field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the ssi field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_ssi(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_ssi);
+
+/**
+ * scsw_cmd_is_valid_zcc - check zcc field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the zcc field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_zcc(union scsw *scsw)
+{
+       return (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) &&
+              (scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_zcc);
+
+/**
+ * scsw_cmd_is_valid_ectl - check ectl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the ectl field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_ectl(union scsw *scsw)
+{
+       return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
+              !(scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS) &&
+              (scsw->cmd.stctl & SCSW_STCTL_ALERT_STATUS);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_ectl);
+
+/**
+ * scsw_cmd_is_valid_pno - check pno field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the pno field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_pno(union scsw *scsw)
+{
+       return (scsw->cmd.fctl != 0) &&
+              (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (!(scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS) ||
+                ((scsw->cmd.stctl & SCSW_STCTL_INTER_STATUS) &&
+                 (scsw->cmd.actl & SCSW_ACTL_SUSPENDED)));
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_pno);
+
+/**
+ * scsw_cmd_is_valid_fctl - check fctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fctl field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_fctl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_fctl);
+
+/**
+ * scsw_cmd_is_valid_actl - check actl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the actl field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_actl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_actl);
+
+/**
+ * scsw_cmd_is_valid_stctl - check stctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the stctl field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_stctl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_stctl);
+
+/**
+ * scsw_cmd_is_valid_dstat - check dstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the dstat field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_dstat(union scsw *scsw)
+{
+       return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (scsw->cmd.cc != 3);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_dstat);
+
+/**
+ * scsw_cmd_is_valid_cstat - check cstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cstat field of the specified command mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_cmd_is_valid_cstat(union scsw *scsw)
+{
+       return (scsw->cmd.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (scsw->cmd.cc != 3);
+}
+EXPORT_SYMBOL(scsw_cmd_is_valid_cstat);
+
+/**
+ * scsw_tm_is_valid_key - check key field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the key field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_key(union scsw *scsw)
+{
+       return (scsw->tm.fctl & SCSW_FCTL_START_FUNC);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_key);
+
+/**
+ * scsw_tm_is_valid_eswf - check eswf field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the eswf field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_eswf(union scsw *scsw)
+{
+       return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_eswf);
+
+/**
+ * scsw_tm_is_valid_cc - check cc field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cc field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_cc(union scsw *scsw)
+{
+       return (scsw->tm.fctl & SCSW_FCTL_START_FUNC) &&
+              (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_cc);
+
+/**
+ * scsw_tm_is_valid_fmt - check fmt field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fmt field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_fmt(union scsw *scsw)
+{
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_fmt);
+
+/**
+ * scsw_tm_is_valid_x - check x field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the x field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_x(union scsw *scsw)
+{
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_x);
+
+/**
+ * scsw_tm_is_valid_q - check q field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the q field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_q(union scsw *scsw)
+{
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_q);
+
+/**
+ * scsw_tm_is_valid_ectl - check ectl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the ectl field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_ectl(union scsw *scsw)
+{
+       return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
+              !(scsw->tm.stctl & SCSW_STCTL_INTER_STATUS) &&
+              (scsw->tm.stctl & SCSW_STCTL_ALERT_STATUS);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_ectl);
+
+/**
+ * scsw_tm_is_valid_pno - check pno field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the pno field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_pno(union scsw *scsw)
+{
+       return (scsw->tm.fctl != 0) &&
+              (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (!(scsw->tm.stctl & SCSW_STCTL_INTER_STATUS) ||
+                ((scsw->tm.stctl & SCSW_STCTL_INTER_STATUS) &&
+                 (scsw->tm.actl & SCSW_ACTL_SUSPENDED)));
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_pno);
+
+/**
+ * scsw_tm_is_valid_fctl - check fctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fctl field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_fctl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_fctl);
+
+/**
+ * scsw_tm_is_valid_actl - check actl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the actl field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_actl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_actl);
+
+/**
+ * scsw_tm_is_valid_stctl - check stctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the stctl field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_stctl(union scsw *scsw)
+{
+       /* Only valid if pmcw.dnv == 1*/
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_stctl);
+
+/**
+ * scsw_tm_is_valid_dstat - check dstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the dstat field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_dstat(union scsw *scsw)
+{
+       return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (scsw->tm.cc != 3);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_dstat);
+
+/**
+ * scsw_tm_is_valid_cstat - check cstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cstat field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_cstat(union scsw *scsw)
+{
+       return (scsw->tm.stctl & SCSW_STCTL_STATUS_PEND) &&
+              (scsw->tm.cc != 3);
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_cstat);
+
+/**
+ * scsw_tm_is_valid_fcxs - check fcxs field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fcxs field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_fcxs(union scsw *scsw)
+{
+       return 1;
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_fcxs);
+
+/**
+ * scsw_tm_is_valid_schxs - check schxs field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the schxs field of the specified transport mode scsw is
+ * valid, zero otherwise.
+ */
+int scsw_tm_is_valid_schxs(union scsw *scsw)
+{
+       return (scsw->tm.cstat & (SCHN_STAT_PROG_CHECK |
+                                 SCHN_STAT_INTF_CTRL_CHK |
+                                 SCHN_STAT_PROT_CHECK |
+                                 SCHN_STAT_CHN_DATA_CHK));
+}
+EXPORT_SYMBOL(scsw_tm_is_valid_schxs);
+
+/**
+ * scsw_is_valid_actl - check actl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the actl field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_actl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_actl(scsw);
+       else
+               return scsw_cmd_is_valid_actl(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_actl);
+
+/**
+ * scsw_is_valid_cc - check cc field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cc field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_cc(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_cc(scsw);
+       else
+               return scsw_cmd_is_valid_cc(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_cc);
+
+/**
+ * scsw_is_valid_cstat - check cstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the cstat field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_cstat(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_cstat(scsw);
+       else
+               return scsw_cmd_is_valid_cstat(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_cstat);
+
+/**
+ * scsw_is_valid_dstat - check dstat field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the dstat field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_dstat(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_dstat(scsw);
+       else
+               return scsw_cmd_is_valid_dstat(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_dstat);
+
+/**
+ * scsw_is_valid_ectl - check ectl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the ectl field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_ectl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_ectl(scsw);
+       else
+               return scsw_cmd_is_valid_ectl(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_ectl);
+
+/**
+ * scsw_is_valid_eswf - check eswf field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the eswf field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_eswf(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_eswf(scsw);
+       else
+               return scsw_cmd_is_valid_eswf(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_eswf);
+
+/**
+ * scsw_is_valid_fctl - check fctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the fctl field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_fctl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_fctl(scsw);
+       else
+               return scsw_cmd_is_valid_fctl(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_fctl);
+
+/**
+ * scsw_is_valid_key - check key field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the key field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_key(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_key(scsw);
+       else
+               return scsw_cmd_is_valid_key(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_key);
+
+/**
+ * scsw_is_valid_pno - check pno field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the pno field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_pno(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_pno(scsw);
+       else
+               return scsw_cmd_is_valid_pno(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_pno);
+
+/**
+ * scsw_is_valid_stctl - check stctl field validity
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the stctl field of the specified scsw is valid,
+ * regardless of whether it is a transport mode or command mode scsw.
+ * Return zero if the field does not contain a valid value.
+ */
+int scsw_is_valid_stctl(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_valid_stctl(scsw);
+       else
+               return scsw_cmd_is_valid_stctl(scsw);
+}
+EXPORT_SYMBOL(scsw_is_valid_stctl);
+
+/**
+ * scsw_cmd_is_solicited - check for solicited scsw
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the command mode scsw indicates that the associated
+ * status condition is solicited, zero if it is unsolicited.
+ */
+int scsw_cmd_is_solicited(union scsw *scsw)
+{
+       return (scsw->cmd.cc != 0) || (scsw->cmd.stctl !=
+               (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS));
+}
+EXPORT_SYMBOL(scsw_cmd_is_solicited);
+
+/**
+ * scsw_tm_is_solicited - check for solicited scsw
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the transport mode scsw indicates that the associated
+ * status condition is solicited, zero if it is unsolicited.
+ */
+int scsw_tm_is_solicited(union scsw *scsw)
+{
+       return (scsw->tm.cc != 0) || (scsw->tm.stctl !=
+               (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS));
+}
+EXPORT_SYMBOL(scsw_tm_is_solicited);
+
+/**
+ * scsw_is_solicited - check for solicited scsw
+ * @scsw: pointer to scsw
+ *
+ * Return non-zero if the transport or command mode scsw indicates that the
+ * associated status condition is solicited, zero if it is unsolicited.
+ */
+int scsw_is_solicited(union scsw *scsw)
+{
+       if (scsw_is_tm(scsw))
+               return scsw_tm_is_solicited(scsw);
+       else
+               return scsw_cmd_is_solicited(scsw);
+}
+EXPORT_SYMBOL(scsw_is_solicited);
index a1ab3e3..62b6b55 100644 (file)
 #include <linux/mutex.h>
 #include <asm/s390_rdev.h>
 #include <asm/reset.h>
+#include <linux/hrtimer.h>
+#include <linux/ktime.h>
 
 #include "ap_bus.h"
 
 /* Some prototypes. */
 static void ap_scan_bus(struct work_struct *);
 static void ap_poll_all(unsigned long);
-static void ap_poll_timeout(unsigned long);
+static enum hrtimer_restart ap_poll_timeout(struct hrtimer *);
 static int ap_poll_thread_start(void);
 static void ap_poll_thread_stop(void);
 static void ap_request_timeout(unsigned long);
@@ -80,12 +82,15 @@ static DECLARE_WORK(ap_config_work, ap_scan_bus);
 /*
  * Tasklet & timer for AP request polling.
  */
-static struct timer_list ap_poll_timer = TIMER_INITIALIZER(ap_poll_timeout,0,0);
 static DECLARE_TASKLET(ap_tasklet, ap_poll_all, 0);
 static atomic_t ap_poll_requests = ATOMIC_INIT(0);
 static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
 static struct task_struct *ap_poll_kthread = NULL;
 static DEFINE_MUTEX(ap_poll_thread_mutex);
+static struct hrtimer ap_poll_timer;
+/* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
+ * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
+static unsigned long long poll_timeout = 250000;
 
 /**
  * ap_intructions_available() - Test if AP instructions are available.
@@ -636,11 +641,39 @@ static ssize_t ap_poll_thread_store(struct bus_type *bus,
 
 static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
 
+static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
+}
+
+static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
+                                 size_t count)
+{
+       unsigned long long time;
+       ktime_t hr_time;
+
+       /* 120 seconds = maximum poll interval */
+       if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 || time > 120000000000)
+               return -EINVAL;
+       poll_timeout = time;
+       hr_time = ktime_set(0, poll_timeout);
+
+       if (!hrtimer_is_queued(&ap_poll_timer) ||
+           !hrtimer_forward(&ap_poll_timer, ap_poll_timer.expires, hr_time)) {
+               ap_poll_timer.expires = hr_time;
+               hrtimer_start(&ap_poll_timer, hr_time, HRTIMER_MODE_ABS);
+       }
+       return count;
+}
+
+static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
+
 static struct bus_attribute *const ap_bus_attrs[] = {
        &bus_attr_ap_domain,
        &bus_attr_config_time,
        &bus_attr_poll_thread,
-       NULL
+       &bus_attr_poll_timeout,
+       NULL,
 };
 
 /**
@@ -895,9 +928,10 @@ ap_config_timeout(unsigned long ptr)
  */
 static inline void ap_schedule_poll_timer(void)
 {
-       if (timer_pending(&ap_poll_timer))
+       if (hrtimer_is_queued(&ap_poll_timer))
                return;
-       mod_timer(&ap_poll_timer, jiffies + AP_POLL_TIME);
+       hrtimer_start(&ap_poll_timer, ktime_set(0, poll_timeout),
+                     HRTIMER_MODE_ABS);
 }
 
 /**
@@ -1115,13 +1149,14 @@ EXPORT_SYMBOL(ap_cancel_message);
 
 /**
  * ap_poll_timeout(): AP receive polling for finished AP requests.
- * @unused: Unused variable.
+ * @unused: Unused pointer.
  *
- * Schedules the AP tasklet.
+ * Schedules the AP tasklet using a high resolution timer.
  */
-static void ap_poll_timeout(unsigned long unused)
+static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
 {
        tasklet_schedule(&ap_tasklet);
+       return HRTIMER_NORESTART;
 }
 
 /**
@@ -1344,6 +1379,14 @@ int __init ap_module_init(void)
        ap_config_timer.expires = jiffies + ap_config_time * HZ;
        add_timer(&ap_config_timer);
 
+       /* Setup the high resultion poll timer.
+        * If we are running under z/VM adjust polling to z/VM polling rate.
+        */
+       if (MACHINE_IS_VM)
+               poll_timeout = 1500000;
+       hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
+       ap_poll_timer.function = ap_poll_timeout;
+
        /* Start the low priority AP bus poll thread. */
        if (ap_thread_flag) {
                rc = ap_poll_thread_start();
@@ -1355,7 +1398,7 @@ int __init ap_module_init(void)
 
 out_work:
        del_timer_sync(&ap_config_timer);
-       del_timer_sync(&ap_poll_timer);
+       hrtimer_cancel(&ap_poll_timer);
        destroy_workqueue(ap_work_queue);
 out_root:
        s390_root_dev_unregister(ap_root_device);
@@ -1386,7 +1429,7 @@ void ap_module_exit(void)
        ap_reset_domain();
        ap_poll_thread_stop();
        del_timer_sync(&ap_config_timer);
-       del_timer_sync(&ap_poll_timer);
+       hrtimer_cancel(&ap_poll_timer);
        destroy_workqueue(ap_work_queue);
        tasklet_kill(&ap_tasklet);
        s390_root_dev_unregister(ap_root_device);
index c1e1200..446378b 100644 (file)
@@ -92,6 +92,8 @@ struct ap_queue_status {
 #define AP_DEVICE_TYPE_PCIXCC  5
 #define AP_DEVICE_TYPE_CEX2A   6
 #define AP_DEVICE_TYPE_CEX2C   7
+#define AP_DEVICE_TYPE_CEX2A2  8
+#define AP_DEVICE_TYPE_CEX2C2  9
 
 /*
  * AP reset flag states
index 4d36e80..cb22b97 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
 #include <linux/compat.h>
+#include <linux/smp_lock.h>
 #include <asm/atomic.h>
 #include <asm/uaccess.h>
 #include <linux/hw_random.h>
@@ -300,7 +301,9 @@ static ssize_t zcrypt_write(struct file *filp, const char __user *buf,
  */
 static int zcrypt_open(struct inode *inode, struct file *filp)
 {
+       lock_kernel();
        atomic_inc(&zcrypt_open_count);
+       unlock_kernel();
        return 0;
 }
 
@@ -1068,10 +1071,8 @@ static int zcrypt_status_write(struct file *file, const char __user *buffer,
 
 #define LBUFSIZE 1200UL
        lbuf = kmalloc(LBUFSIZE, GFP_KERNEL);
-       if (!lbuf) {
-               PRINTK("kmalloc failed!\n");
+       if (!lbuf)
                return 0;
-       }
 
        local_count = min(LBUFSIZE - 1, count);
        if (copy_from_user(lbuf, buffer, local_count) != 0) {
@@ -1081,23 +1082,15 @@ static int zcrypt_status_write(struct file *file, const char __user *buffer,
        lbuf[local_count] = '\0';
 
        ptr = strstr(lbuf, "Online devices");
-       if (!ptr) {
-               PRINTK("Unable to parse data (missing \"Online devices\")\n");
+       if (!ptr)
                goto out;
-       }
        ptr = strstr(ptr, "\n");
-       if (!ptr) {
-               PRINTK("Unable to parse data (missing newline "
-                      "after \"Online devices\")\n");
+       if (!ptr)
                goto out;
-       }
        ptr++;
 
-       if (strstr(ptr, "Waiting work element counts") == NULL) {
-               PRINTK("Unable to parse data (missing "
-                      "\"Waiting work element counts\")\n");
+       if (strstr(ptr, "Waiting work element counts") == NULL)
                goto out;
-       }
 
        for (j = 0; j < 64 && *ptr; ptr++) {
                /*
@@ -1197,16 +1190,12 @@ int __init zcrypt_api_init(void)
 
        /* Register the request sprayer. */
        rc = misc_register(&zcrypt_misc_device);
-       if (rc < 0) {
-               PRINTKW(KERN_ERR "misc_register (minor %d) failed with %d\n",
-                       zcrypt_misc_device.minor, rc);
+       if (rc < 0)
                goto out;
-       }
 
        /* Set up the proc file system */
        zcrypt_entry = create_proc_entry("driver/z90crypt", 0644, NULL);
        if (!zcrypt_entry) {
-               PRINTK("Couldn't create z90crypt proc entry\n");
                rc = -ENOMEM;
                goto out_misc;
        }
index 5c6e222..1d1ec74 100644 (file)
 #ifndef _ZCRYPT_API_H_
 #define _ZCRYPT_API_H_
 
-/**
- * Macro definitions
- *
- * PDEBUG debugs in the form "zcrypt: function_name -> message"
- *
- * PRINTK is like PDEBUG, except that it is always enabled
- * PRINTKN is like PRINTK, except that it does not include the function name
- * PRINTKW is like PRINTK, except that it uses KERN_WARNING
- * PRINTKC is like PRINTK, except that it uses KERN_CRIT
- */
-#define DEV_NAME       "zcrypt"
-
-#define PRINTK(fmt, args...) \
-       printk(KERN_DEBUG DEV_NAME ": %s -> " fmt, __func__ , ## args)
-#define PRINTKN(fmt, args...) \
-       printk(KERN_DEBUG DEV_NAME ": " fmt, ## args)
-#define PRINTKW(fmt, args...) \
-       printk(KERN_WARNING DEV_NAME ": %s -> " fmt, __func__ , ## args)
-#define PRINTKC(fmt, args...) \
-       printk(KERN_CRIT DEV_NAME ": %s -> " fmt, __func__ , ## args)
-
-#ifdef ZCRYPT_DEBUG
-#define PDEBUG(fmt, args...) \
-       printk(KERN_DEBUG DEV_NAME ": %s -> " fmt, __func__ , ## args)
-#else
-#define PDEBUG(fmt, args...) do {} while (0)
-#endif
-
 #include "ap_bus.h"
 #include <asm/zcrypt.h>
 
index 08657f6..54f4cbc 100644 (file)
@@ -49,6 +49,7 @@
 
 static struct ap_device_id zcrypt_cex2a_ids[] = {
        { AP_DEVICE(AP_DEVICE_TYPE_CEX2A) },
+       { AP_DEVICE(AP_DEVICE_TYPE_CEX2A2) },
        { /* end of list */ },
 };
 
@@ -242,9 +243,6 @@ static int convert_response(struct zcrypt_device *zdev,
                return convert_type80(zdev, reply,
                                      outputdata, outputdatalength);
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
index 3e27fe7..03ba27f 100644 (file)
@@ -92,10 +92,6 @@ static inline int convert_error(struct zcrypt_device *zdev,
 {
        struct error_hdr *ehdr = reply->message;
 
-       PRINTK("Hardware error : Type %02x Message Header: %08x%08x\n",
-              ehdr->type, *(unsigned int *) reply->message,
-              *(unsigned int *) (reply->message + 4));
-
        switch (ehdr->reply_code) {
        case REP82_ERROR_OPERAND_INVALID:
        case REP82_ERROR_OPERAND_SIZE:
@@ -123,8 +119,6 @@ static inline int convert_error(struct zcrypt_device *zdev,
                zdev->online = 0;
                return -EAGAIN;
        default:
-               PRINTKW("unknown type %02x reply code = %d\n",
-                       ehdr->type, ehdr->reply_code);
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
index 6e93b47..12da481 100644 (file)
@@ -226,9 +226,6 @@ static int convert_response(struct zcrypt_device *zdev,
                return convert_type84(zdev, reply,
                                      outputdata, outputdatalength);
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
index 17ea56c..779952c 100644 (file)
@@ -361,26 +361,18 @@ static int convert_type86(struct zcrypt_device *zdev,
        service_rc = le16_to_cpu(msg->cprb.ccp_rtcode);
        if (unlikely(service_rc != 0)) {
                service_rs = le16_to_cpu(msg->cprb.ccp_rscode);
-               if (service_rc == 8 && service_rs == 66) {
-                       PDEBUG("Bad block format on PCICC\n");
+               if (service_rc == 8 && service_rs == 66)
                        return -EINVAL;
-               }
-               if (service_rc == 8 && service_rs == 65) {
-                       PDEBUG("Probably an even modulus on PCICC\n");
+               if (service_rc == 8 && service_rs == 65)
                        return -EINVAL;
-               }
                if (service_rc == 8 && service_rs == 770) {
-                       PDEBUG("Invalid key length on PCICC\n");
                        zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD;
                        return -EAGAIN;
                }
                if (service_rc == 8 && service_rs == 783) {
-                       PDEBUG("Extended bitlengths not enabled on PCICC\n");
                        zdev->max_mod_size = PCICC_MAX_MOD_SIZE_OLD;
                        return -EAGAIN;
                }
-               PRINTK("Unknown service rc/rs (PCICC): %d/%d\n",
-                      service_rc, service_rs);
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
@@ -434,9 +426,6 @@ static int convert_response(struct zcrypt_device *zdev,
                                              outputdata, outputdatalength);
                /* no break, incorrect cprb version is an unknown response */
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
index 0bc9b31..d8ad36f 100644 (file)
@@ -72,6 +72,7 @@ struct response_type {
 static struct ap_device_id zcrypt_pcixcc_ids[] = {
        { AP_DEVICE(AP_DEVICE_TYPE_PCIXCC) },
        { AP_DEVICE(AP_DEVICE_TYPE_CEX2C) },
+       { AP_DEVICE(AP_DEVICE_TYPE_CEX2C2) },
        { /* end of list */ },
 };
 
@@ -289,38 +290,19 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
        ap_msg->length = sizeof(struct type6_hdr) +
                CEIL4(xcRB->request_control_blk_length) +
                xcRB->request_data_length;
-       if (ap_msg->length > PCIXCC_MAX_XCRB_MESSAGE_SIZE) {
-               PRINTK("Combined message is too large (%ld/%d/%d).\n",
-                   sizeof(struct type6_hdr),
-                   xcRB->request_control_blk_length,
-                   xcRB->request_data_length);
+       if (ap_msg->length > PCIXCC_MAX_XCRB_MESSAGE_SIZE)
                return -EFAULT;
-       }
-       if (CEIL4(xcRB->reply_control_blk_length) >
-           PCIXCC_MAX_XCRB_REPLY_SIZE) {
-               PDEBUG("Reply CPRB length is too large (%d).\n",
-                   xcRB->request_control_blk_length);
+       if (CEIL4(xcRB->reply_control_blk_length) > PCIXCC_MAX_XCRB_REPLY_SIZE)
                return -EFAULT;
-       }
-       if (CEIL4(xcRB->reply_data_length) > PCIXCC_MAX_XCRB_DATA_SIZE) {
-               PDEBUG("Reply data block length is too large (%d).\n",
-                   xcRB->reply_data_length);
+       if (CEIL4(xcRB->reply_data_length) > PCIXCC_MAX_XCRB_DATA_SIZE)
                return -EFAULT;
-       }
        replylen = CEIL4(xcRB->reply_control_blk_length) +
                CEIL4(xcRB->reply_data_length) +
                sizeof(struct type86_fmt2_msg);
        if (replylen > PCIXCC_MAX_XCRB_RESPONSE_SIZE) {
-               PDEBUG("Reply CPRB + data block > PCIXCC_MAX_XCRB_RESPONSE_SIZE"
-                      " (%d/%d/%d).\n",
-                      sizeof(struct type86_fmt2_msg),
-                      xcRB->reply_control_blk_length,
-                      xcRB->reply_data_length);
                xcRB->reply_control_blk_length = PCIXCC_MAX_XCRB_RESPONSE_SIZE -
                        (sizeof(struct type86_fmt2_msg) +
                            CEIL4(xcRB->reply_data_length));
-               PDEBUG("Capping Reply CPRB length at %d\n",
-                      xcRB->reply_control_blk_length);
        }
 
        /* prepare type6 header */
@@ -339,11 +321,8 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
                    xcRB->request_control_blk_length))
                return -EFAULT;
        if (msg->cprbx.cprb_len + sizeof(msg->hdr.function_code) >
-           xcRB->request_control_blk_length) {
-               PDEBUG("cprb_len too large (%d/%d)\n", msg->cprbx.cprb_len,
-                   xcRB->request_control_blk_length);
+           xcRB->request_control_blk_length)
                return -EFAULT;
-       }
        function_code = ((unsigned char *)&msg->cprbx) + msg->cprbx.cprb_len;
        memcpy(msg->hdr.function_code, function_code, sizeof(msg->hdr.function_code));
 
@@ -471,29 +450,18 @@ static int convert_type86_ica(struct zcrypt_device *zdev,
        service_rc = msg->cprbx.ccp_rtcode;
        if (unlikely(service_rc != 0)) {
                service_rs = msg->cprbx.ccp_rscode;
-               if (service_rc == 8 && service_rs == 66) {
-                       PDEBUG("Bad block format on PCIXCC/CEX2C\n");
+               if (service_rc == 8 && service_rs == 66)
                        return -EINVAL;
-               }
-               if (service_rc == 8 && service_rs == 65) {
-                       PDEBUG("Probably an even modulus on PCIXCC/CEX2C\n");
+               if (service_rc == 8 && service_rs == 65)
                        return -EINVAL;
-               }
-               if (service_rc == 8 && service_rs == 770) {
-                       PDEBUG("Invalid key length on PCIXCC/CEX2C\n");
+               if (service_rc == 8 && service_rs == 770)
                        return -EINVAL;
-               }
                if (service_rc == 8 && service_rs == 783) {
-                       PDEBUG("Extended bitlengths not enabled on PCIXCC/CEX2C\n");
                        zdev->min_mod_size = PCIXCC_MIN_MOD_SIZE_OLD;
                        return -EAGAIN;
                }
-               if (service_rc == 12 && service_rs == 769) {
-                       PDEBUG("Invalid key on PCIXCC/CEX2C\n");
+               if (service_rc == 12 && service_rs == 769)
                        return -EINVAL;
-               }
-               PRINTK("Unknown service rc/rs (PCIXCC/CEX2C): %d/%d\n",
-                      service_rc, service_rs);
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
@@ -569,11 +537,8 @@ static int convert_type86_rng(struct zcrypt_device *zdev,
        } __attribute__((packed)) *msg = reply->message;
        char *data = reply->message;
 
-       if (msg->cprbx.ccp_rtcode != 0 || msg->cprbx.ccp_rscode != 0) {
-               PDEBUG("RNG response error on PCIXCC/CEX2C rc=%hu/rs=%hu\n",
-                      rc, rs);
+       if (msg->cprbx.ccp_rtcode != 0 || msg->cprbx.ccp_rscode != 0)
                return -EINVAL;
-       }
        memcpy(buffer, data + msg->fmt2.offset2, msg->fmt2.count2);
        return msg->fmt2.count2;
 }
@@ -598,9 +563,6 @@ static int convert_response_ica(struct zcrypt_device *zdev,
                                                  outputdata, outputdatalength);
                /* no break, incorrect cprb version is an unknown response */
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
@@ -627,9 +589,6 @@ static int convert_response_xcrb(struct zcrypt_device *zdev,
                        return convert_type86_xcrb(zdev, reply, xcRB);
                /* no break, incorrect cprb version is an unknown response */
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                xcRB->status = 0x0008044DL; /* HDD_InvalidParm */
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
@@ -653,9 +612,6 @@ static int convert_response_rng(struct zcrypt_device *zdev,
                        return convert_type86_rng(zdev, reply, data);
                /* no break, incorrect cprb version is an unknown response */
        default: /* Unknown response type, this should NEVER EVER happen */
-               PRINTK("Unrecognized Message Header: %08x%08x\n",
-                      *(unsigned int *) reply->message,
-                      *(unsigned int *) (reply->message+4));
                zdev->online = 0;
                return -EAGAIN; /* repeat the request on a different device. */
        }
@@ -700,10 +656,7 @@ static void zcrypt_pcixcc_receive(struct ap_device *ap_dev,
                        memcpy(msg->message, reply->message, length);
                        break;
                default:
-                       PRINTK("Invalid internal response type: %i\n",
-                           resp_type->type);
-                       memcpy(msg->message, &error_reply,
-                           sizeof error_reply);
+                       memcpy(msg->message, &error_reply, sizeof error_reply);
                }
        } else
                memcpy(msg->message, reply->message, sizeof error_reply);
index 04a1d7b..c644669 100644 (file)
@@ -703,7 +703,8 @@ claw_irq_handler(struct ccw_device *cdev,
        if (!cdev->dev.driver_data) {
                 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
                        "%s received c-%02x d-%02x\n",
-                        cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
+                      cdev->dev.bus_id, irb->scsw.cmd.cstat,
+                      irb->scsw.cmd.dstat);
 #ifdef FUNCTRACE
                 printk(KERN_INFO "claw: %s() "
                        "exit on line %d\n",__func__,__LINE__);
@@ -732,22 +733,23 @@ claw_irq_handler(struct ccw_device *cdev,
 #ifdef IOTRACE
         printk(KERN_INFO "%s: interrupt for device: %04x "
                "received c-%02x d-%02x state-%02x\n",
-                dev->name, p_ch->devno, irb->scsw.cstat,
-               irb->scsw.dstat, p_ch->claw_state);
+              dev->name, p_ch->devno, irb->scsw.cmd.cstat,
+              irb->scsw.cmd.dstat, p_ch->claw_state);
 #endif
 
        /* Copy interruption response block. */
        memcpy(p_ch->irb, irb, sizeof(struct irb));
 
         /* Check for good subchannel return code, otherwise error message */
-        if (irb->scsw.cstat  &&  !(irb->scsw.cstat & SCHN_STAT_PCI)) {
+       if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
                 printk(KERN_INFO "%s: subchannel check for device: %04x -"
                        " Sch Stat %02x  Dev Stat %02x CPA - %04x\n",
                         dev->name, p_ch->devno,
-                       irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
+                       irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
+                       irb->scsw.cmd.cpa);
 #ifdef IOTRACE
                dumpit((char *)irb,sizeof(struct irb));
-               dumpit((char *)(unsigned long)irb->scsw.cpa,
+               dumpit((char *)(unsigned long)irb->scsw.cmd.cpa,
                        sizeof(struct ccw1));
 #endif
 #ifdef FUNCTRACE
@@ -759,22 +761,24 @@ claw_irq_handler(struct ccw_device *cdev,
         }
 
         /* Check the reason-code of a unit check */
-        if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
                 ccw_check_unit_check(p_ch, irb->ecw[0]);
-        }
 
         /* State machine to bring the connection up, down and to restart */
-        p_ch->last_dstat = irb->scsw.dstat;
+       p_ch->last_dstat = irb->scsw.cmd.dstat;
 
         switch (p_ch->claw_state) {
                 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
 #ifdef DEBUGMSG
                         printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
 #endif
-                        if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
-                       (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
-                       (p_ch->irb->scsw.stctl ==
-                       (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
+                       if (!((p_ch->irb->scsw.cmd.stctl &
+                              SCSW_STCTL_SEC_STATUS) ||
+                           (p_ch->irb->scsw.cmd.stctl ==
+                               SCSW_STCTL_STATUS_PEND) ||
+                           (p_ch->irb->scsw.cmd.stctl ==
+                               (SCSW_STCTL_ALERT_STATUS |
+                                SCSW_STCTL_STATUS_PEND)))) {
 #ifdef FUNCTRACE
                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
                                        dev->name,__func__,__LINE__);
@@ -798,10 +802,13 @@ claw_irq_handler(struct ccw_device *cdev,
                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
                                dev->name);
 #endif
-                        if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
-                       (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
-                       (p_ch->irb->scsw.stctl ==
-                       (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
+                       if (!((p_ch->irb->scsw.cmd.stctl &
+                              SCSW_STCTL_SEC_STATUS) ||
+                           (p_ch->irb->scsw.cmd.stctl ==
+                            SCSW_STCTL_STATUS_PEND) ||
+                           (p_ch->irb->scsw.cmd.stctl ==
+                            (SCSW_STCTL_ALERT_STATUS |
+                             SCSW_STCTL_STATUS_PEND)))) {
 #ifdef FUNCTRACE
                                printk(KERN_INFO "%s:%s Exit on line %d\n",
                                        dev->name,__func__,__LINE__);
@@ -828,8 +835,8 @@ claw_irq_handler(struct ccw_device *cdev,
                                        "interrupt for device:"
                                        "%s received c-%02x d-%02x\n",
                                        cdev->dev.bus_id,
-                                       irb->scsw.cstat,
-                                       irb->scsw.dstat);
+                                       irb->scsw.cmd.cstat,
+                                       irb->scsw.cmd.dstat);
                                return;
                                }
 #ifdef DEBUGMSG
@@ -844,7 +851,7 @@ claw_irq_handler(struct ccw_device *cdev,
                         return;
                 case CLAW_START_READ:
                        CLAW_DBF_TEXT(4,trace,"ReadIRQ");
-                        if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+                       if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
                                 clear_bit(0, (void *)&p_ch->IO_active);
                                 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
                                     (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
@@ -863,8 +870,8 @@ claw_irq_handler(struct ccw_device *cdev,
                                        CLAW_DBF_TEXT(4,trace,"notrdy");
                                         return;
                         }
-                        if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
-                           (p_ch->irb->scsw.dstat==0)) {
+                       if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
+                           (p_ch->irb->scsw.cmd.dstat == 0)) {
                                 if (test_and_set_bit(CLAW_BH_ACTIVE,
                                        (void *)&p_ch->flag_a) == 0) {
                                        tasklet_schedule(&p_ch->tasklet);
@@ -879,10 +886,13 @@ claw_irq_handler(struct ccw_device *cdev,
                                CLAW_DBF_TEXT(4,trace,"PCI_read");
                                 return;
                         }
-                        if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
-                        (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
-                        (p_ch->irb->scsw.stctl ==
-                        (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
+                       if (!((p_ch->irb->scsw.cmd.stctl &
+                              SCSW_STCTL_SEC_STATUS) ||
+                            (p_ch->irb->scsw.cmd.stctl ==
+                             SCSW_STCTL_STATUS_PEND) ||
+                            (p_ch->irb->scsw.cmd.stctl ==
+                             (SCSW_STCTL_ALERT_STATUS |
+                              SCSW_STCTL_STATUS_PEND)))) {
 #ifdef FUNCTRACE
                                printk(KERN_INFO "%s:%s Exit on line %d\n",
                                        dev->name,__func__,__LINE__);
@@ -911,7 +921,7 @@ claw_irq_handler(struct ccw_device *cdev,
                        CLAW_DBF_TEXT(4,trace,"RdIRQXit");
                         return;
                 case CLAW_START_WRITE:
-                        if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+                       if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
                                 printk(KERN_INFO "%s: Unit Check Occured in "
                                        "write channel\n",dev->name);
                                 clear_bit(0, (void *)&p_ch->IO_active);
@@ -934,16 +944,19 @@ claw_irq_handler(struct ccw_device *cdev,
                                CLAW_DBF_TEXT(4,trace,"rstrtwrt");
                                 return;
                         }
-                        if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
+                       if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
                                         clear_bit(0, (void *)&p_ch->IO_active);
                                         printk(KERN_INFO "%s: Unit Exception "
                                                "Occured in write channel\n",
                                                dev->name);
                         }
-                        if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
-                       (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
-                       (p_ch->irb->scsw.stctl ==
-                       (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
+                       if (!((p_ch->irb->scsw.cmd.stctl &
+                              SCSW_STCTL_SEC_STATUS) ||
+                            (p_ch->irb->scsw.cmd.stctl ==
+                             SCSW_STCTL_STATUS_PEND) ||
+                            (p_ch->irb->scsw.cmd.stctl ==
+                             (SCSW_STCTL_ALERT_STATUS |
+                              SCSW_STCTL_STATUS_PEND)))) {
 #ifdef FUNCTRACE
                                printk(KERN_INFO "%s:%s Exit on line %d\n",
                                        dev->name,__func__,__LINE__);
index 2a106f3..7e6bd38 100644 (file)
@@ -257,9 +257,9 @@ static void chx_txdone(fsm_instance *fi, int event, void *arg)
        if (duration > ch->prof.tx_time)
                ch->prof.tx_time = duration;
 
-       if (ch->irb->scsw.count != 0)
+       if (ch->irb->scsw.cmd.count != 0)
                ctcm_pr_debug("%s: TX not complete, remaining %d bytes\n",
-                            dev->name, ch->irb->scsw.count);
+                            dev->name, ch->irb->scsw.cmd.count);
        fsm_deltimer(&ch->timer);
        while ((skb = skb_dequeue(&ch->io_queue))) {
                priv->stats.tx_packets++;
@@ -353,7 +353,7 @@ static void chx_rx(fsm_instance *fi, int event, void *arg)
        struct channel *ch = arg;
        struct net_device *dev = ch->netdev;
        struct ctcm_priv *priv = dev->priv;
-       int len = ch->max_bufsize - ch->irb->scsw.count;
+       int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
        struct sk_buff *skb = ch->trans_skb;
        __u16 block_len = *((__u16 *)skb->data);
        int check_len;
@@ -1234,9 +1234,9 @@ static void ctcmpc_chx_txdone(fsm_instance *fi, int event, void *arg)
        if (duration > ch->prof.tx_time)
                ch->prof.tx_time = duration;
 
-       if (ch->irb->scsw.count != 0)
+       if (ch->irb->scsw.cmd.count != 0)
                ctcm_pr_debug("%s: TX not complete, remaining %d bytes\n",
-                               dev->name, ch->irb->scsw.count);
+                               dev->name, ch->irb->scsw.cmd.count);
        fsm_deltimer(&ch->timer);
        while ((skb = skb_dequeue(&ch->io_queue))) {
                priv->stats.tx_packets++;
@@ -1394,7 +1394,7 @@ static void ctcmpc_chx_rx(fsm_instance *fi, int event, void *arg)
        struct sk_buff          *skb = ch->trans_skb;
        struct sk_buff          *new_skb;
        unsigned long   saveflags = 0;  /* avoids compiler warning */
-       int len = ch->max_bufsize - ch->irb->scsw.count;
+       int len = ch->max_bufsize - ch->irb->scsw.cmd.count;
 
        if (do_debug_data) {
                CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG, "mpc_ch_rx %s cp:%i %s\n",
index d52843d..6b13c1c 100644 (file)
@@ -1236,8 +1236,8 @@ static void ctcm_irq_handler(struct ccw_device *cdev,
        /* Check for unsolicited interrupts. */
        if (cgdev == NULL) {
                ctcm_pr_warn("ctcm: Got unsolicited irq: %s c-%02x d-%02x\n",
-                           cdev->dev.bus_id, irb->scsw.cstat,
-                           irb->scsw.dstat);
+                           cdev->dev.bus_id, irb->scsw.cmd.cstat,
+                           irb->scsw.cmd.dstat);
                return;
        }
 
@@ -1266,40 +1266,40 @@ static void ctcm_irq_handler(struct ccw_device *cdev,
                                "received c-%02x d-%02x\n",
                                dev->name,
                                ch->id,
-                               irb->scsw.cstat,
-                               irb->scsw.dstat);
+                               irb->scsw.cmd.cstat,
+                               irb->scsw.cmd.dstat);
 
        /* Copy interruption response block. */
        memcpy(ch->irb, irb, sizeof(struct irb));
 
        /* Check for good subchannel return code, otherwise error message */
-       if (irb->scsw.cstat) {
+       if (irb->scsw.cmd.cstat) {
                fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch);
                ctcm_pr_warn("%s: subchannel check for dev: %s - %02x %02x\n",
-                           dev->name, ch->id, irb->scsw.cstat,
-                           irb->scsw.dstat);
+                           dev->name, ch->id, irb->scsw.cmd.cstat,
+                           irb->scsw.cmd.dstat);
                return;
        }
 
        /* Check the reason-code of a unit check */
-       if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
                ccw_unit_check(ch, irb->ecw[0]);
                return;
        }
-       if (irb->scsw.dstat & DEV_STAT_BUSY) {
-               if (irb->scsw.dstat & DEV_STAT_ATTENTION)
+       if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) {
+               if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION)
                        fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch);
                else
                        fsm_event(ch->fsm, CTC_EVENT_BUSY, ch);
                return;
        }
-       if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
+       if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
                fsm_event(ch->fsm, CTC_EVENT_ATTN, ch);
                return;
        }
-       if ((irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
-           (irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
-           (irb->scsw.stctl ==
+       if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
+           (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
+           (irb->scsw.cmd.stctl ==
             (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))
                fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch);
        else
index 8e76973..f4a3237 100644 (file)
@@ -36,7 +36,6 @@ const char *cu3088_type[] = {
        "CTC/A",
        "ESCON channel",
        "FICON channel",
-       "P390 LCS card",
        "OSA LCS card",
        "CLAW channel device",
        "unknown channel type",
@@ -49,7 +48,6 @@ static struct ccw_device_id cu3088_ids[] = {
        { CCW_DEVICE(0x3088, 0x08), .driver_info = channel_type_parallel },
        { CCW_DEVICE(0x3088, 0x1f), .driver_info = channel_type_escon },
        { CCW_DEVICE(0x3088, 0x1e), .driver_info = channel_type_ficon },
-       { CCW_DEVICE(0x3088, 0x01), .driver_info = channel_type_p390 },
        { CCW_DEVICE(0x3088, 0x60), .driver_info = channel_type_osa2 },
        { CCW_DEVICE(0x3088, 0x61), .driver_info = channel_type_claw },
        { /* end of list */ }
index 1753661..d8558a7 100644 (file)
@@ -17,9 +17,6 @@ enum channel_types {
        /* Device is a FICON channel */
        channel_type_ficon,
 
-       /* Device is a P390 LCS card */
-       channel_type_p390,
-
        /* Device is a OSA2 card */
        channel_type_osa2,
 
index dd22f4b..6de2838 100644 (file)
@@ -1327,8 +1327,8 @@ lcs_get_problem(struct ccw_device *cdev, struct irb *irb)
        char *sense;
 
        sense = (char *) irb->ecw;
-       cstat = irb->scsw.cstat;
-       dstat = irb->scsw.dstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
 
        if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
                     SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
@@ -1388,11 +1388,13 @@ lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        else
                channel = &card->write;
 
-       cstat = irb->scsw.cstat;
-       dstat = irb->scsw.dstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
        LCS_DBF_TEXT_(5, trace, "Rint%s",cdev->dev.bus_id);
-       LCS_DBF_TEXT_(5, trace, "%4x%4x",irb->scsw.cstat, irb->scsw.dstat);
-       LCS_DBF_TEXT_(5, trace, "%4x%4x",irb->scsw.fctl, irb->scsw.actl);
+       LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.cstat,
+                     irb->scsw.cmd.dstat);
+       LCS_DBF_TEXT_(5, trace, "%4x%4x", irb->scsw.cmd.fctl,
+                     irb->scsw.cmd.actl);
 
        /* Check for channel and device errors presented */
        rc = lcs_get_problem(cdev, irb);
@@ -1410,11 +1412,11 @@ lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
        }
        /* How far in the ccw chain have we processed? */
        if ((channel->state != LCS_CH_STATE_INIT) &&
-           (irb->scsw.fctl & SCSW_FCTL_START_FUNC)) {
-               index = (struct ccw1 *) __va((addr_t) irb->scsw.cpa)
+           (irb->scsw.cmd.fctl & SCSW_FCTL_START_FUNC)) {
+               index = (struct ccw1 *) __va((addr_t) irb->scsw.cmd.cpa)
                        - channel->ccws;
-               if ((irb->scsw.actl & SCSW_ACTL_SUSPENDED) ||
-                   (irb->scsw.cstat & SCHN_STAT_PCI))
+               if ((irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED) ||
+                   (irb->scsw.cmd.cstat & SCHN_STAT_PCI))
                        /* Bloody io subsystem tells us lies about cpa... */
                        index = (index - 1) & (LCS_NUM_BUFFS - 1);
                while (channel->io_idx != index) {
@@ -1425,25 +1427,24 @@ lcs_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
                }
        }
 
-       if ((irb->scsw.dstat & DEV_STAT_DEV_END) ||
-           (irb->scsw.dstat & DEV_STAT_CHN_END) ||
-           (irb->scsw.dstat & DEV_STAT_UNIT_CHECK))
+       if ((irb->scsw.cmd.dstat & DEV_STAT_DEV_END) ||
+           (irb->scsw.cmd.dstat & DEV_STAT_CHN_END) ||
+           (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK))
                /* Mark channel as stopped. */
                channel->state = LCS_CH_STATE_STOPPED;
-       else if (irb->scsw.actl & SCSW_ACTL_SUSPENDED)
+       else if (irb->scsw.cmd.actl & SCSW_ACTL_SUSPENDED)
                /* CCW execution stopped on a suspend bit. */
                channel->state = LCS_CH_STATE_SUSPENDED;
-       if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC) {
-               if (irb->scsw.cc != 0) {
+       if (irb->scsw.cmd.fctl & SCSW_FCTL_HALT_FUNC) {
+               if (irb->scsw.cmd.cc != 0) {
                        ccw_device_halt(channel->ccwdev, (addr_t) channel);
                        return;
                }
                /* The channel has been stopped by halt_IO. */
                channel->state = LCS_CH_STATE_HALTED;
        }
-       if (irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
+       if (irb->scsw.cmd.fctl & SCSW_FCTL_CLEAR_FUNC)
                channel->state = LCS_CH_STATE_CLEARED;
-       }
        /* Do the rest in the tasklet. */
        tasklet_schedule(&channel->irq_tasklet);
 }
@@ -1761,7 +1762,7 @@ lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd)
                                netif_carrier_off(card->dev);
                        break;
                default:
-                       PRINT_INFO("UNRECOGNIZED LGW COMMAND\n");
+                       LCS_DBF_TEXT(5, trace, "noLGWcmd");
                        break;
                }
        } else
@@ -2042,13 +2043,12 @@ lcs_probe_device(struct ccwgroup_device *ccwgdev)
        LCS_DBF_TEXT(2, setup, "add_dev");
         card = lcs_alloc_card();
         if (!card) {
-                PRINT_ERR("Allocation of lcs card failed\n");
+               LCS_DBF_TEXT_(2, setup, "  rc%d", -ENOMEM);
                put_device(&ccwgdev->dev);
                 return -ENOMEM;
         }
        ret = sysfs_create_group(&ccwgdev->dev.kobj, &lcs_attr_group);
        if (ret) {
-                PRINT_ERR("Creating attributes failed");
                lcs_free_card(card);
                put_device(&ccwgdev->dev);
                return ret;
@@ -2140,7 +2140,6 @@ lcs_new_device(struct ccwgroup_device *ccwgdev)
        default:
                LCS_DBF_TEXT(3, setup, "errinit");
                PRINT_ERR("LCS: Initialization failed\n");
-               PRINT_ERR("LCS: No device found!\n");
                goto out;
        }
        if (!dev)
@@ -2269,7 +2268,6 @@ lcs_remove_device(struct ccwgroup_device *ccwgdev)
        if (!card)
                return;
 
-       PRINT_INFO("Removing lcs group device ....\n");
        LCS_DBF_TEXT(3, setup, "remdev");
        LCS_DBF_HEX(3, setup, &card, sizeof(void*));
        if (ccwgdev->state == CCWGROUP_ONLINE) {
index e4ba6a0..9242b5a 100644 (file)
@@ -625,9 +625,6 @@ static void netiucv_unpack_skb(struct iucv_connection *conn,
                offset += header->next;
                header->next -= NETIUCV_HDRLEN;
                if (skb_tailroom(pskb) < header->next) {
-                       PRINT_WARN("%s: Illegal next field in iucv header: "
-                              "%d > %d\n",
-                              dev->name, header->next, skb_tailroom(pskb));
                        IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n",
                                header->next, skb_tailroom(pskb));
                        return;
@@ -636,8 +633,6 @@ static void netiucv_unpack_skb(struct iucv_connection *conn,
                skb_reset_mac_header(pskb);
                skb = dev_alloc_skb(pskb->len);
                if (!skb) {
-                       PRINT_WARN("%s Out of memory in netiucv_unpack_skb\n",
-                              dev->name);
                        IUCV_DBF_TEXT(data, 2,
                                "Out of memory in netiucv_unpack_skb\n");
                        privptr->stats.rx_dropped++;
@@ -674,7 +669,6 @@ static void conn_action_rx(fsm_instance *fi, int event, void *arg)
 
        if (!conn->netdev) {
                iucv_message_reject(conn->path, msg);
-               PRINT_WARN("Received data for unlinked connection\n");
                IUCV_DBF_TEXT(data, 2,
                              "Received data for unlinked connection\n");
                return;
@@ -682,8 +676,6 @@ static void conn_action_rx(fsm_instance *fi, int event, void *arg)
        if (msg->length > conn->max_buffsize) {
                iucv_message_reject(conn->path, msg);
                privptr->stats.rx_dropped++;
-               PRINT_WARN("msglen %d > max_buffsize %d\n",
-                          msg->length, conn->max_buffsize);
                IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n",
                               msg->length, conn->max_buffsize);
                return;
@@ -695,7 +687,6 @@ static void conn_action_rx(fsm_instance *fi, int event, void *arg)
                                  msg->length, NULL);
        if (rc || msg->length < 5) {
                privptr->stats.rx_errors++;
-               PRINT_WARN("iucv_receive returned %08x\n", rc);
                IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc);
                return;
        }
@@ -778,7 +769,6 @@ static void conn_action_txdone(fsm_instance *fi, int event, void *arg)
                fsm_newstate(fi, CONN_STATE_IDLE);
                if (privptr)
                        privptr->stats.tx_errors += txpackets;
-               PRINT_WARN("iucv_send returned %08x\n", rc);
                IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
        } else {
                if (privptr) {
@@ -806,8 +796,6 @@ static void conn_action_connaccept(fsm_instance *fi, int event, void *arg)
        path->flags = 0;
        rc = iucv_path_accept(path, &netiucv_handler, NULL, conn);
        if (rc) {
-               PRINT_WARN("%s: IUCV accept failed with error %d\n",
-                      netdev->name, rc);
                IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc);
                return;
        }
@@ -873,7 +861,7 @@ static void conn_action_start(fsm_instance *fi, int event, void *arg)
        IUCV_DBF_TEXT(trace, 3, __func__);
 
        fsm_newstate(fi, CONN_STATE_STARTWAIT);
-       PRINT_DEBUG("%s('%s'): connecting ...\n",
+       IUCV_DBF_TEXT_(setup, 2, "%s('%s'): connecting ...\n",
                    conn->netdev->name, conn->userid);
 
        /*
@@ -968,8 +956,8 @@ static void conn_action_inval(fsm_instance *fi, int event, void *arg)
        struct iucv_connection *conn = arg;
        struct net_device *netdev = conn->netdev;
 
-       PRINT_WARN("%s: Cannot connect without username\n", netdev->name);
-       IUCV_DBF_TEXT(data, 2, "conn_action_inval called\n");
+       IUCV_DBF_TEXT_(data, 2, "%s('%s'): conn_action_inval called\n",
+               netdev->name, conn->userid);
 }
 
 static const fsm_node conn_fsm[] = {
@@ -1077,9 +1065,6 @@ dev_action_connup(fsm_instance *fi, int event, void *arg)
                                "connection is up and running\n");
                        break;
                case DEV_STATE_STOPWAIT:
-                       PRINT_INFO(
-                              "%s: got connection UP event during shutdown!\n",
-                              dev->name);
                        IUCV_DBF_TEXT(data, 2,
                                "dev_action_connup: in DEV_STATE_STOPWAIT\n");
                        break;
@@ -1174,8 +1159,6 @@ static int netiucv_transmit_skb(struct iucv_connection *conn,
                        nskb = alloc_skb(skb->len + NETIUCV_HDRLEN +
                                         NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA);
                        if (!nskb) {
-                               PRINT_WARN("%s: Could not allocate tx_skb\n",
-                                      conn->netdev->name);
                                IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n");
                                rc = -ENOMEM;
                                return rc;
@@ -1223,7 +1206,6 @@ static int netiucv_transmit_skb(struct iucv_connection *conn,
                                skb_pull(skb, NETIUCV_HDRLEN);
                                skb_trim(skb, skb->len - NETIUCV_HDRLEN);
                        }
-                       PRINT_WARN("iucv_send returned %08x\n", rc);
                        IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc);
                } else {
                        if (copied)
@@ -1293,14 +1275,11 @@ static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
         * Some sanity checks ...
         */
        if (skb == NULL) {
-               PRINT_WARN("%s: NULL sk_buff passed\n", dev->name);
                IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n");
                privptr->stats.tx_dropped++;
                return 0;
        }
        if (skb_headroom(skb) < NETIUCV_HDRLEN) {
-               PRINT_WARN("%s: Got sk_buff with head room < %ld bytes\n",
-                      dev->name, NETIUCV_HDRLEN);
                IUCV_DBF_TEXT(data, 2,
                        "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
                dev_kfree_skb(skb);
@@ -1393,7 +1372,6 @@ static ssize_t user_write(struct device *dev, struct device_attribute *attr,
 
        IUCV_DBF_TEXT(trace, 3, __func__);
        if (count > 9) {
-               PRINT_WARN("netiucv: username too long (%d)!\n", (int) count);
                IUCV_DBF_TEXT_(setup, 2,
                               "%d is length of username\n", (int) count);
                return -EINVAL;
@@ -1409,7 +1387,6 @@ static ssize_t user_write(struct device *dev, struct device_attribute *attr,
                        /* trailing lf, grr */
                        break;
                }
-               PRINT_WARN("netiucv: Invalid char %c in username!\n", *p);
                IUCV_DBF_TEXT_(setup, 2,
                               "username: invalid character %c\n", *p);
                return -EINVAL;
@@ -1421,18 +1398,15 @@ static ssize_t user_write(struct device *dev, struct device_attribute *attr,
        if (memcmp(username, priv->conn->userid, 9) &&
            (ndev->flags & (IFF_UP | IFF_RUNNING))) {
                /* username changed while the interface is active. */
-               PRINT_WARN("netiucv: device %s active, connected to %s\n",
-                          dev->bus_id, priv->conn->userid);
-               PRINT_WARN("netiucv: user cannot be updated\n");
                IUCV_DBF_TEXT(setup, 2, "user_write: device active\n");
-               return -EBUSY;
+               return -EPERM;
        }
        read_lock_bh(&iucv_connection_rwlock);
        list_for_each_entry(cp, &iucv_connection_list, list) {
                if (!strncmp(username, cp->userid, 9) && cp->netdev != ndev) {
                        read_unlock_bh(&iucv_connection_rwlock);
-                       PRINT_WARN("netiucv: Connection to %s already "
-                                  "exists\n", username);
+                       IUCV_DBF_TEXT_(setup, 2, "user_write: Connection "
+                               "to %s already exists\n", username);
                        return -EEXIST;
                }
        }
@@ -1466,13 +1440,10 @@ static ssize_t buffer_write (struct device *dev, struct device_attribute *attr,
        bs1 = simple_strtoul(buf, &e, 0);
 
        if (e && (!isspace(*e))) {
-               PRINT_WARN("netiucv: Invalid character in buffer!\n");
                IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %c\n", *e);
                return -EINVAL;
        }
        if (bs1 > NETIUCV_BUFSIZE_MAX) {
-               PRINT_WARN("netiucv: Given buffer size %d too large.\n",
-                       bs1);
                IUCV_DBF_TEXT_(setup, 2,
                        "buffer_write: buffer size %d too large\n",
                        bs1);
@@ -1480,16 +1451,12 @@ static ssize_t buffer_write (struct device *dev, struct device_attribute *attr,
        }
        if ((ndev->flags & IFF_RUNNING) &&
            (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) {
-               PRINT_WARN("netiucv: Given buffer size %d too small.\n",
-                       bs1);
                IUCV_DBF_TEXT_(setup, 2,
                        "buffer_write: buffer size %d too small\n",
                        bs1);
                return -EINVAL;
        }
        if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) {
-               PRINT_WARN("netiucv: Given buffer size %d too small.\n",
-                       bs1);
                IUCV_DBF_TEXT_(setup, 2,
                        "buffer_write: buffer size %d too small\n",
                        bs1);
@@ -1963,7 +1930,6 @@ static ssize_t conn_write(struct device_driver *drv,
 
        IUCV_DBF_TEXT(trace, 3, __func__);
        if (count>9) {
-               PRINT_WARN("netiucv: username too long (%d)!\n", (int)count);
                IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n");
                return -EINVAL;
        }
@@ -1976,7 +1942,6 @@ static ssize_t conn_write(struct device_driver *drv,
                if (*p == '\n')
                        /* trailing lf, grr */
                        break;
-               PRINT_WARN("netiucv: Invalid character in username!\n");
                IUCV_DBF_TEXT_(setup, 2,
                               "conn_write: invalid character %c\n", *p);
                return -EINVAL;
@@ -1989,8 +1954,8 @@ static ssize_t conn_write(struct device_driver *drv,
        list_for_each_entry(cp, &iucv_connection_list, list) {
                if (!strncmp(username, cp->userid, 9)) {
                        read_unlock_bh(&iucv_connection_rwlock);
-                       PRINT_WARN("netiucv: Connection to %s already "
-                                  "exists\n", username);
+                       IUCV_DBF_TEXT_(setup, 2, "conn_write: Connection "
+                               "to %s already exists\n", username);
                        return -EEXIST;
                }
        }
@@ -1998,9 +1963,6 @@ static ssize_t conn_write(struct device_driver *drv,
 
        dev = netiucv_init_netdevice(username);
        if (!dev) {
-               PRINT_WARN("netiucv: Could not allocate network device "
-                          "structure for user '%s'\n",
-                          netiucv_printname(username));
                IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n");
                return -ENODEV;
        }
@@ -2020,15 +1982,12 @@ static ssize_t conn_write(struct device_driver *drv,
        if (rc)
                goto out_unreg;
 
-       PRINT_INFO("%s: '%s'\n", dev->name, netiucv_printname(username));
 
        return count;
 
 out_unreg:
        netiucv_unregister_device(priv->dev);
 out_free_ndev:
-       PRINT_WARN("netiucv: Could not register '%s'\n", dev->name);
-       IUCV_DBF_TEXT(setup, 2, "conn_write: could not register\n");
        netiucv_free_netdevice(dev);
        return rc;
 }
@@ -2073,14 +2032,13 @@ static ssize_t remove_write (struct device_driver *drv,
                         PRINT_WARN("netiucv: %s cannot be removed\n",
                                   ndev->name);
                        IUCV_DBF_TEXT(data, 2, "remove_write: still active\n");
-                        return -EBUSY;
+                       return -EPERM;
                 }
                 unregister_netdev(ndev);
                 netiucv_unregister_device(dev);
                 return count;
         }
        read_unlock_bh(&iucv_connection_rwlock);
-        PRINT_WARN("netiucv: net device %s unknown\n", name);
        IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n");
         return -EINVAL;
 }
@@ -2148,7 +2106,6 @@ static int __init netiucv_init(void)
        netiucv_driver.groups = netiucv_drv_attr_groups;
        rc = driver_register(&netiucv_driver);
        if (rc) {
-               PRINT_ERR("NETIUCV: failed to register driver.\n");
                IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", rc);
                goto out_iucv;
        }
index 9a71dae..0ac54dc 100644 (file)
@@ -420,7 +420,7 @@ static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
                                QETH_DBF_TEXT(TRACE, 3, "urla");
                                break;
                        default:
-                               PRINT_WARN("Received data is IPA "
+                               QETH_DBF_MESSAGE(2, "Received data is IPA "
                                           "but not a reply!\n");
                                break;
                        }
@@ -735,8 +735,8 @@ static int qeth_get_problem(struct ccw_device *cdev, struct irb *irb)
        char *sense;
 
        sense = (char *) irb->ecw;
-       cstat = irb->scsw.cstat;
-       dstat = irb->scsw.dstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
 
        if (cstat & (SCHN_STAT_CHN_CTRL_CHK | SCHN_STAT_INTF_CTRL_CHK |
                     SCHN_STAT_CHN_DATA_CHK | SCHN_STAT_CHAIN_CHECK |
@@ -823,8 +823,8 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
 
        if (__qeth_check_irb_error(cdev, intparm, irb))
                return;
-       cstat = irb->scsw.cstat;
-       dstat = irb->scsw.dstat;
+       cstat = irb->scsw.cmd.cstat;
+       dstat = irb->scsw.cmd.dstat;
 
        card = CARD_FROM_CDEV(cdev);
        if (!card)
@@ -842,10 +842,10 @@ static void qeth_irq(struct ccw_device *cdev, unsigned long intparm,
        }
        atomic_set(&channel->irq_pending, 0);
 
-       if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC))
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_CLEAR_FUNC))
                channel->state = CH_STATE_STOPPED;
 
-       if (irb->scsw.fctl & (SCSW_FCTL_HALT_FUNC))
+       if (irb->scsw.cmd.fctl & (SCSW_FCTL_HALT_FUNC))
                channel->state = CH_STATE_HALTED;
 
        /*let's wake up immediately on data channel*/
@@ -4092,7 +4092,6 @@ static int qeth_core_probe_device(struct ccwgroup_device *gdev)
 
        rc = qeth_determine_card_type(card);
        if (rc) {
-               PRINT_WARN("%s: not a valid card type\n", __func__);
                QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
                goto err_card;
        }
index 999552c..06deaee 100644 (file)
@@ -944,15 +944,8 @@ static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
        else
                rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
                                        addr->del_flags);
-       if (rc) {
+       if (rc)
                QETH_DBF_TEXT(TRACE, 2, "failed");
-               /* TODO: re-activate this warning as soon as we have a
-                * clean mirco code
-               qeth_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
-               PRINT_WARN("Could not deregister IP address %s (rc=%x)\n",
-                          buf, rc);
-               */
-       }
 
        return rc;
 }
index 8735a41..164e090 100644 (file)
@@ -156,11 +156,8 @@ static int __init smsg_init(void)
        if (rc != 0)
                goto out;
        rc = iucv_register(&smsg_handler, 1);
-       if (rc) {
-               printk(KERN_ERR "SMSGIUCV: failed to register to iucv");
-               rc = -EIO;      /* better errno ? */
+       if (rc)
                goto out_driver;
-       }
        smsg_path = iucv_path_alloc(255, 0, GFP_KERNEL);
        if (!smsg_path) {
                rc = -ENOMEM;
@@ -168,11 +165,8 @@ static int __init smsg_init(void)
        }
        rc = iucv_path_connect(smsg_path, &smsg_handler, "*MSG    ",
                               NULL, NULL, NULL);
-       if (rc) {
-               printk(KERN_ERR "SMSGIUCV: failed to connect to *MSG");
-               rc = -EIO;      /* better errno ? */
+       if (rc)
                goto out_free;
-       }
        cpcmd("SET SMSG IUCV", NULL, 0, NULL);
        return 0;
 
index 5bfbe76..834e9ee 100644 (file)
@@ -2,10 +2,10 @@
  *  drivers/s390/s390mach.c
  *   S/390 machine check handler
  *
- *  S390 version
- *    Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ *    Copyright IBM Corp. 2000,2008
  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
  *              Martin Schwidefsky (schwidefsky@de.ibm.com)
+ *              Cornelia Huck <cornelia.huck@de.ibm.com>
  */
 
 #include <linux/init.h>
 #include <asm/etr.h>
 #include <asm/lowcore.h>
 #include <asm/cio.h>
-#include "cio/cio.h"
-#include "cio/chsc.h"
-#include "cio/css.h"
-#include "cio/chp.h"
 #include "s390mach.h"
 
 static struct semaphore m_sem;
@@ -36,13 +32,40 @@ s390_handle_damage(char *msg)
        for(;;);
 }
 
+static crw_handler_t crw_handlers[NR_RSCS];
+
+/**
+ * s390_register_crw_handler() - register a channel report word handler
+ * @rsc: reporting source code to handle
+ * @handler: handler to be registered
+ *
+ * Returns %0 on success and a negative error value otherwise.
+ */
+int s390_register_crw_handler(int rsc, crw_handler_t handler)
+{
+       if ((rsc < 0) || (rsc >= NR_RSCS))
+               return -EINVAL;
+       if (!cmpxchg(&crw_handlers[rsc], NULL, handler))
+               return 0;
+       return -EBUSY;
+}
+
+/**
+ * s390_unregister_crw_handler() - unregister a channel report word handler
+ * @rsc: reporting source code to handle
+ */
+void s390_unregister_crw_handler(int rsc)
+{
+       if ((rsc < 0) || (rsc >= NR_RSCS))
+               return;
+       xchg(&crw_handlers[rsc], NULL);
+       synchronize_sched();
+}
+
 /*
  * Retrieve CRWs and call function to handle event.
- *
- * Note : we currently process CRWs for io and chsc subchannels only
  */
-static int
-s390_collect_crw_info(void *param)
+static int s390_collect_crw_info(void *param)
 {
        struct crw crw[2];
        int ccode;
@@ -84,57 +107,24 @@ repeat:
                       crw[chain].rsid);
                /* Check for overflows. */
                if (crw[chain].oflw) {
+                       int i;
+
                        pr_debug("%s: crw overflow detected!\n", __func__);
-                       css_schedule_eval_all();
+                       for (i = 0; i < NR_RSCS; i++) {
+                               if (crw_handlers[i])
+                                       crw_handlers[i](NULL, NULL, 1);
+                       }
                        chain = 0;
                        continue;
                }
-               switch (crw[chain].rsc) {
-               case CRW_RSC_SCH:
-                       if (crw[0].chn && !chain)
-                               break;
-                       pr_debug("source is subchannel %04X\n", crw[0].rsid);
-                       css_process_crw(crw[0].rsid, chain ? crw[1].rsid : 0);
-                       break;
-               case CRW_RSC_MONITOR:
-                       pr_debug("source is monitoring facility\n");
-                       break;
-               case CRW_RSC_CPATH:
-                       pr_debug("source is channel path %02X\n", crw[0].rsid);
-                       /*
-                        * Check for solicited machine checks. These are
-                        * created by reset channel path and need not be
-                        * reported to the common I/O layer.
-                        */
-                       if (crw[chain].slct) {
-                               pr_debug("solicited machine check for "
-                                        "channel path %02X\n", crw[0].rsid);
-                               break;
-                       }
-                       switch (crw[0].erc) {
-                       case CRW_ERC_IPARM: /* Path has come. */
-                               chp_process_crw(crw[0].rsid, 1);
-                               break;
-                       case CRW_ERC_PERRI: /* Path has gone. */
-                       case CRW_ERC_PERRN:
-                               chp_process_crw(crw[0].rsid, 0);
-                               break;
-                       default:
-                               pr_debug("Don't know how to handle erc=%x\n",
-                                        crw[0].erc);
-                       }
-                       break;
-               case CRW_RSC_CONFIG:
-                       pr_debug("source is configuration-alert facility\n");
-                       break;
-               case CRW_RSC_CSS:
-                       pr_debug("source is channel subsystem\n");
-                       chsc_process_crw();
-                       break;
-               default:
-                       pr_debug("unknown source\n");
-                       break;
+               if (crw[0].chn && !chain) {
+                       chain++;
+                       continue;
                }
+               if (crw_handlers[crw[chain].rsc])
+                       crw_handlers[crw[chain].rsc](&crw[0],
+                                                    chain ? &crw[1] : NULL,
+                                                    0);
                /* chain is always 0 or 1 here. */
                chain = crw[chain].chn ? chain + 1 : 0;
        }
@@ -468,6 +458,10 @@ s390_do_machine_check(struct pt_regs *regs)
                        etr_sync_check();
                if (S390_lowcore.external_damage_code & (1U << ED_ETR_SWITCH))
                        etr_switch_to_local();
+               if (S390_lowcore.external_damage_code & (1U << ED_STP_SYNC))
+                       stp_sync_check();
+               if (S390_lowcore.external_damage_code & (1U << ED_STP_ISLAND))
+                       stp_island_check();
        }
 
        if (mci->se)
index ca681f9..d39f8b6 100644 (file)
@@ -72,6 +72,13 @@ struct crw {
        __u32 rsid    : 16;   /* reporting-source ID */
 } __attribute__ ((packed));
 
+typedef void (*crw_handler_t)(struct crw *, struct crw *, int);
+
+extern int s390_register_crw_handler(int rsc, crw_handler_t handler);
+extern void s390_unregister_crw_handler(int rsc);
+
+#define NR_RSCS 16
+
 #define CRW_RSC_MONITOR  0x2  /* monitoring facility */
 #define CRW_RSC_SCH      0x3  /* subchannel */
 #define CRW_RSC_CPATH    0x4  /* channel path */
@@ -105,6 +112,9 @@ static inline int stcrw(struct crw *pcrw )
 #define ED_ETR_SYNC    12      /* External damage ETR sync check */
 #define ED_ETR_SWITCH  13      /* External damage ETR switch to local */
 
+#define ED_STP_SYNC    7       /* External damage STP sync check */
+#define ED_STP_ISLAND  6       /* External damage STP island check */
+
 struct pt_regs;
 
 void s390_handle_mcck(void);
index 03c9660..bba21e0 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/timer.h>
 #include <linux/ioport.h>
 #include <linux/major.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -429,6 +430,7 @@ static int bpp_open(struct inode *inode, struct file *f)
       unsigned minor = iminor(inode);
       int ret;
 
+      lock_kernel();
       spin_lock(&bpp_open_lock);
       ret = 0;
       if (minor >= BPP_NO) {
@@ -444,6 +446,7 @@ static int bpp_open(struct inode *inode, struct file *f)
              }
       }
       spin_unlock(&bpp_open_lock);
+      unlock_kernel();
 
       return ret;
 }
index 2357034..23abfdf 100644 (file)
@@ -279,6 +279,7 @@ static inline int wd_opt_timeout(void)
 
 static int wd_open(struct inode *inode, struct file *f)
 {
+       lock_kernel();
        switch(iminor(inode))
        {
                case WD0_MINOR:
@@ -291,6 +292,7 @@ static int wd_open(struct inode *inode, struct file *f)
                        f->private_data = &wd_dev.watchdog[WD2_ID];
                        break;
                default:
+                       unlock_kernel();
                        return(-ENODEV);
        }
 
@@ -304,11 +306,13 @@ static int wd_open(struct inode *inode, struct file *f)
                                                (void *)wd_dev.regs)) {
                        printk("%s: Cannot register IRQ %d\n", 
                                WD_OBPNAME, wd_dev.irq);
+                       unlock_kernel();
                        return(-EBUSY);
                }
                wd_dev.initialized = 1;
        }
 
+       unlock_kernel();
        return(nonseekable_open(inode, f));
 }
 
index 3279a1b..d8f5c0c 100644 (file)
@@ -94,6 +94,7 @@ static int d7s_open(struct inode *inode, struct file *f)
 {
        if (D7S_MINOR != iminor(inode))
                return -ENODEV;
+       cycle_kernel_lock();
        atomic_inc(&d7s_users);
        return 0;
 }
index dadabef..a408402 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/miscdevice.h>
 #include <linux/kmod.h>
 #include <linux/reboot.h>
+#include <linux/smp_lock.h>
 
 #include <asm/ebus.h>
 #include <asm/uaccess.h>
@@ -694,6 +695,7 @@ envctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 static int
 envctrl_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        file->private_data = NULL;
        return 0;
 }
index 44e0398..7d95e15 100644 (file)
@@ -127,9 +127,13 @@ flash_read(struct file * file, char __user * buf,
 static int
 flash_open(struct inode *inode, struct file *file)
 {
-       if (test_and_set_bit(0, (void *)&flash.busy) != 0)
+       lock_kernel();
+       if (test_and_set_bit(0, (void *)&flash.busy) != 0) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
+       unlock_kernel();
        return 0;
 }
 
index 4b7079f..2bec9cc 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -417,11 +418,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma)
 
 static int jsf_open(struct inode * inode, struct file * filp)
 {
-
-       if (jsf0.base == 0) return -ENXIO;
-       if (test_and_set_bit(0, (void *)&jsf0.busy) != 0)
+       lock_kernel();
+       if (jsf0.base == 0) {
+               unlock_kernel();
+               return -ENXIO;
+       }
+       if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) {
+               unlock_kernel();
                return -EBUSY;
+       }
 
+       unlock_kernel();
        return 0;       /* XXX What security? */
 }
 
index fbfeb89..29dc735 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/miscdevice.h>
 #include <linux/init.h>
@@ -689,9 +690,11 @@ static int openprom_open(struct inode * inode, struct file * file)
        if (!data)
                return -ENOMEM;
 
+       lock_kernel();
        data->current_node = of_find_node_by_path("/");
        data->lastnode = data->current_node;
        file->private_data = (void *) data;
+       unlock_kernel();
 
        return 0;
 }
index a2fc6b8..88c0fc6 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/miscdevice.h>
+#include <linux/smp_lock.h>
 
 #include <asm/io.h>
 #include <asm/ebus.h>
@@ -116,6 +117,7 @@ static void riowd_starttimer(void)
 
 static int riowd_open(struct inode *inode, struct file *filp)
 {
+       cycle_kernel_lock();
        nonseekable_open(inode, filp);
        return 0;
 }
index 18d18f1..b042991 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -213,6 +214,7 @@ static int rtc_open(struct inode *inode, struct file *file)
 {
        int ret;
 
+       lock_kernel();
        spin_lock_irq(&mostek_lock);
        if (rtc_busy) {
                ret = -EBUSY;
@@ -221,6 +223,7 @@ static int rtc_open(struct inode *inode, struct file *file)
                ret = 0;
        }
        spin_unlock_irq(&mostek_lock);
+       unlock_kernel();
 
        return ret;
 }
index 383f32c..513ba61 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/miscdevice.h>
@@ -211,8 +212,10 @@ uctrl_ioctl(struct inode *inode, struct file *file,
 static int
 uctrl_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        uctrl_get_event_status();
        uctrl_get_external_status();
+       unlock_kernel();
        return 0;
 }
 
index d4f8fcd..1f6cb8a 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 
 #include <asm/openprom.h>
 #include <asm/oplib.h>
@@ -178,14 +179,17 @@ static int vfc_open(struct inode *inode, struct file *file)
 {
        struct vfc_dev *dev;
 
+       lock_kernel();
        spin_lock(&vfc_dev_lock);
        dev = vfc_get_dev_ptr(iminor(inode));
        if (dev == NULL) {
                spin_unlock(&vfc_dev_lock);
+               unlock_kernel();
                return -ENODEV;
        }
        if (dev->busy) {
                spin_unlock(&vfc_dev_lock);
+               unlock_kernel();
                return -EBUSY;
        }
 
@@ -202,6 +206,7 @@ static int vfc_open(struct inode *inode, struct file *file)
        vfc_captstat_reset(dev);
        
        vfc_unlock_device(dev);
+       unlock_kernel();
        return 0;
 }
 
index 867f6fd..7045511 100644 (file)
@@ -84,6 +84,7 @@
 #include <linux/pci.h>
 #include <linux/time.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
@@ -862,11 +863,13 @@ out:
 } /* End twa_chrdev_ioctl() */
 
 /* This function handles open for the character device */
+/* NOTE that this function will race with remove. */
 static int twa_chrdev_open(struct inode *inode, struct file *file)
 {
        unsigned int minor_number;
        int retval = TW_IOCTL_ERROR_OS_ENODEV;
 
+       cycle_kernel_lock();
        minor_number = iminor(inode);
        if (minor_number >= twa_device_extension_count)
                goto out;
index 8c22329..a0537f0 100644 (file)
 
 #include <linux/module.h>
 #include <linux/reboot.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/moduleparam.h>
@@ -1027,10 +1028,12 @@ out:
 } /* End tw_chrdev_ioctl() */
 
 /* This function handles open for the character device */
+/* NOTE that this function races with remove. */
 static int tw_chrdev_open(struct inode *inode, struct file *file)
 {
        unsigned int minor_number;
 
+       cycle_kernel_lock();
        dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n");
 
        minor_number = iminor(inode);
index 1f7c836..68c140e 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/moduleparam.h>
 #include <linux/pci.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/syscalls.h>
 #include <linux/delay.h>
@@ -667,6 +668,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
        unsigned minor_number = iminor(inode);
        int err = -ENODEV;
 
+       lock_kernel();  /* BKL pushdown: nothing else protects this list */
        list_for_each_entry(aac, &aac_devices, entry) {
                if (aac->id == minor_number) {
                        file->private_data = aac;
@@ -674,6 +676,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
                        break;
                }
        }
+       unlock_kernel();
 
        return err;
 }
index 7236143..a8587f1 100644 (file)
@@ -3,7 +3,7 @@
 #
 config SCSI_ACORNSCSI_3
        tristate "Acorn SCSI card (aka30) support"
-       depends on ARCH_ACORN && SCSI && BROKEN
+       depends on ARCH_ACORN && SCSI
        select SCSI_SPI_ATTRS
        help
          This enables support for the Acorn SCSI card (aka30). If you have an
index 93467e6..5cebe31 100644 (file)
 #include <asm/assembler.h>
 #include <asm/hardware.h>
 
-#if (IO_BASE == (PCIO_BASE & 0xff000000))
-#define ADDR(off,reg)                                          \
-               tst     off, $0x80000000                        ;\
-               mov     reg, $IO_BASE                           ;\
-               orreq   reg, reg, $(PCIO_BASE & 0x00ff0000)
-#else
-#define ADDR(off,reg)                                          \
-               tst     off, $0x80000000                        ;\
-               movne   reg, $IO_BASE                           ;\
-               moveq   reg, $(PCIO_BASE & 0xff000000)          ;\
-               orreq   reg, reg, $(PCIO_BASE & 0x00ff0000)
+#if defined(__APCS_32__)
+#define LOADREGS(t,r,l...)     ldm##t  r, l
+#elif defined(__APCS_26__)
+#define LOADREGS(t,r,l...)     ldm##t  r, l##^
 #endif
 
 @ Purpose: transfer a block of data from the acorn scsi card to memory
index 8e53f02..918ccf8 100644 (file)
 #define DBG(cmd,xxx...) xxx
 #endif
 
-#ifndef STRINGIFY
-#define STRINGIFY(x) #x
-#endif
-#define STRx(x) STRINGIFY(x)
-#define NO_WRITE_STR STRx(NO_WRITE)
-
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/bitops.h>
+#include <linux/stringify.h>
+#include <linux/io.h>
 
 #include <asm/system.h>
-#include <asm/io.h>
 #include <asm/ecard.h>
 
 #include "../scsi.h"
@@ -203,44 +198,46 @@ static void acornscsi_abortcmd(AS_Host *host, unsigned char tag);
  * Miscellaneous
  */
 
-static inline void
-sbic_arm_write(unsigned int io_port, int reg, int value)
+/* Offsets from MEMC base */
+#define SBIC_REGIDX    0x2000
+#define SBIC_REGVAL    0x2004
+#define DMAC_OFFSET    0x3000
+
+/* Offsets from FAST IOC base */
+#define INT_REG                0x2000
+#define PAGE_REG       0x3000
+
+static inline void sbic_arm_write(AS_Host *host, unsigned int reg, unsigned int value)
 {
-    __raw_writeb(reg, io_port);
-    __raw_writeb(value, io_port + 4);
+    writeb(reg, host->base + SBIC_REGIDX);
+    writeb(value, host->base + SBIC_REGVAL);
 }
 
-#define sbic_arm_writenext(io,val) \
-       __raw_writeb((val), (io) + 4)
-
-static inline
-int sbic_arm_read(unsigned int io_port, int reg)
+static inline int sbic_arm_read(AS_Host *host, unsigned int reg)
 {
     if(reg == SBIC_ASR)
-          return __raw_readl(io_port) & 255;
-    __raw_writeb(reg, io_port);
-    return __raw_readl(io_port + 4) & 255;
+          return readl(host->base + SBIC_REGIDX) & 255;
+    writeb(reg, host->base + SBIC_REGIDX);
+    return readl(host->base + SBIC_REGVAL) & 255;
 }
 
-#define sbic_arm_readnext(io) \
-       __raw_readb((io) + 4)
+#define sbic_arm_writenext(host, val)  writeb((val), (host)->base + SBIC_REGVAL)
+#define sbic_arm_readnext(host)        readb((host)->base + SBIC_REGVAL)
 
 #ifdef USE_DMAC
-#define dmac_read(io_port,reg) \
-       inb((io_port) + (reg))
+#define dmac_read(host,reg) \
+       readb((host)->base + DMAC_OFFSET + ((reg) << 2))
 
-#define dmac_write(io_port,reg,value) \
-       ({ outb((value), (io_port) + (reg)); })
+#define dmac_write(host,reg,value) \
+       ({ writeb((value), (host)->base + DMAC_OFFSET + ((reg) << 2)); })
 
-#define dmac_clearintr(io_port) \
-       ({ outb(0, (io_port)); })
+#define dmac_clearintr(host)   writeb(0, (host)->fast + INT_REG)
 
-static inline
-unsigned int dmac_address(unsigned int io_port)
+static inline unsigned int dmac_address(AS_Host *host)
 {
-    return dmac_read(io_port, DMAC_TXADRHI) << 16 |
-          dmac_read(io_port, DMAC_TXADRMD) << 8 |
-          dmac_read(io_port, DMAC_TXADRLO);
+    return dmac_read(host, DMAC_TXADRHI) << 16 |
+          dmac_read(host, DMAC_TXADRMD) << 8 |
+          dmac_read(host, DMAC_TXADRLO);
 }
 
 static
@@ -248,15 +245,15 @@ void acornscsi_dumpdma(AS_Host *host, char *where)
 {
        unsigned int mode, addr, len;
 
-       mode = dmac_read(host->dma.io_port, DMAC_MODECON);
-       addr = dmac_address(host->dma.io_port);
-       len  = dmac_read(host->dma.io_port, DMAC_TXCNTHI) << 8 |
-              dmac_read(host->dma.io_port, DMAC_TXCNTLO);
+       mode = dmac_read(host, DMAC_MODECON);
+       addr = dmac_address(host);
+       len  = dmac_read(host, DMAC_TXCNTHI) << 8 |
+              dmac_read(host, DMAC_TXCNTLO);
 
        printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
                host->host->host_no, where,
                mode, addr, (len + 1) & 0xffff,
-               dmac_read(host->dma.io_port, DMAC_MASKREG));
+               dmac_read(host, DMAC_MASKREG));
 
        printk("DMA @%06x, ", host->dma.start_addr);
        printk("BH @%p +%04x, ", host->scsi.SCp.ptr,
@@ -272,9 +269,9 @@ unsigned long acornscsi_sbic_xfcount(AS_Host *host)
 {
     unsigned long length;
 
-    length = sbic_arm_read(host->scsi.io_port, SBIC_TRANSCNTH) << 16;
-    length |= sbic_arm_readnext(host->scsi.io_port) << 8;
-    length |= sbic_arm_readnext(host->scsi.io_port);
+    length = sbic_arm_read(host, SBIC_TRANSCNTH) << 16;
+    length |= sbic_arm_readnext(host) << 8;
+    length |= sbic_arm_readnext(host);
 
     return length;
 }
@@ -285,7 +282,7 @@ acornscsi_sbic_wait(AS_Host *host, int stat_mask, int stat, int timeout, char *m
        int asr;
 
        do {
-               asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
+               asr = sbic_arm_read(host, SBIC_ASR);
 
                if ((asr & stat_mask) == stat)
                        return 0;
@@ -304,7 +301,7 @@ int acornscsi_sbic_issuecmd(AS_Host *host, int command)
     if (acornscsi_sbic_wait(host, ASR_CIP, 0, 1000, "issuing command"))
        return -1;
 
-    sbic_arm_write(host->scsi.io_port, SBIC_CMND, command);
+    sbic_arm_write(host, SBIC_CMND, command);
 
     return 0;
 }
@@ -331,20 +328,20 @@ void acornscsi_resetcard(AS_Host *host)
 
     /* assert reset line */
     host->card.page_reg = 0x80;
-    outb(host->card.page_reg, host->card.io_page);
+    writeb(host->card.page_reg, host->fast + PAGE_REG);
 
     /* wait 3 cs.  SCSI standard says 25ms. */
     acornscsi_csdelay(3);
 
     host->card.page_reg = 0;
-    outb(host->card.page_reg, host->card.io_page);
+    writeb(host->card.page_reg, host->fast + PAGE_REG);
 
     /*
      * Should get a reset from the card
      */
     timeout = 1000;
     do {
-       if (inb(host->card.io_intr) & 8)
+       if (readb(host->fast + INT_REG) & 8)
            break;
        udelay(1);
     } while (--timeout);
@@ -353,19 +350,19 @@ void acornscsi_resetcard(AS_Host *host)
        printk("scsi%d: timeout while resetting card\n",
                host->host->host_no);
 
-    sbic_arm_read(host->scsi.io_port, SBIC_ASR);
-    sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+    sbic_arm_read(host, SBIC_ASR);
+    sbic_arm_read(host, SBIC_SSR);
 
     /* setup sbic - WD33C93A */
-    sbic_arm_write(host->scsi.io_port, SBIC_OWNID, OWNID_EAF | host->host->this_id);
-    sbic_arm_write(host->scsi.io_port, SBIC_CMND, CMND_RESET);
+    sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
+    sbic_arm_write(host, SBIC_CMND, CMND_RESET);
 
     /*
      * Command should cause a reset interrupt
      */
     timeout = 1000;
     do {
-       if (inb(host->card.io_intr) & 8)
+       if (readb(host->fast + INT_REG) & 8)
            break;
        udelay(1);
     } while (--timeout);
@@ -374,26 +371,26 @@ void acornscsi_resetcard(AS_Host *host)
        printk("scsi%d: timeout while resetting card\n",
                host->host->host_no);
 
-    sbic_arm_read(host->scsi.io_port, SBIC_ASR);
-    if (sbic_arm_read(host->scsi.io_port, SBIC_SSR) != 0x01)
+    sbic_arm_read(host, SBIC_ASR);
+    if (sbic_arm_read(host, SBIC_SSR) != 0x01)
        printk(KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
                host->host->host_no);
 
-    sbic_arm_write(host->scsi.io_port, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
-    sbic_arm_write(host->scsi.io_port, SBIC_TIMEOUT, TIMEOUT_TIME);
-    sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
-    sbic_arm_write(host->scsi.io_port, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
+    sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
+    sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
+    sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
+    sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
 
     host->card.page_reg = 0x40;
-    outb(host->card.page_reg, host->card.io_page);
+    writeb(host->card.page_reg, host->fast + PAGE_REG);
 
     /* setup dmac - uPC71071 */
-    dmac_write(host->dma.io_port, DMAC_INIT, 0);
+    dmac_write(host, DMAC_INIT, 0);
 #ifdef USE_DMAC
-    dmac_write(host->dma.io_port, DMAC_INIT, INIT_8BIT);
-    dmac_write(host->dma.io_port, DMAC_CHANNEL, CHANNEL_0);
-    dmac_write(host->dma.io_port, DMAC_DEVCON0, INIT_DEVCON0);
-    dmac_write(host->dma.io_port, DMAC_DEVCON1, INIT_DEVCON1);
+    dmac_write(host, DMAC_INIT, INIT_8BIT);
+    dmac_write(host, DMAC_CHANNEL, CHANNEL_0);
+    dmac_write(host, DMAC_DEVCON0, INIT_DEVCON0);
+    dmac_write(host, DMAC_DEVCON1, INIT_DEVCON1);
 #endif
 
     host->SCpnt = NULL;
@@ -741,9 +738,9 @@ intr_ret_t acornscsi_kick(AS_Host *host)
      * If we have an interrupt pending, then we may have been reselected.
      * In this case, we don't want to write to the registers
      */
-    if (!(sbic_arm_read(host->scsi.io_port, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
-       sbic_arm_write(host->scsi.io_port, SBIC_DESTID, SCpnt->device->id);
-       sbic_arm_write(host->scsi.io_port, SBIC_CMND, CMND_SELWITHATN);
+    if (!(sbic_arm_read(host, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
+       sbic_arm_write(host, SBIC_DESTID, SCpnt->device->id);
+       sbic_arm_write(host, SBIC_CMND, CMND_SELWITHATN);
     }
 
     /*
@@ -807,7 +804,7 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
        struct scsi_cmnd *SCpnt = *SCpntp;
 
     /* clean up */
-    sbic_arm_write(host->scsi.io_port, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
+    sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
 
     host->stats.fins += 1;
 
@@ -918,13 +915,13 @@ static
 void acornscsi_data_read(AS_Host *host, char *ptr,
                                 unsigned int start_addr, unsigned int length)
 {
-    extern void __acornscsi_in(int port, char *buf, int len);
+    extern void __acornscsi_in(void __iomem *, char *buf, int len);
     unsigned int page, offset, len = length;
 
     page = (start_addr >> 12);
     offset = start_addr & ((1 << 12) - 1);
 
-    outb((page & 0x3f) | host->card.page_reg, host->card.io_page);
+    writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
 
     while (len > 0) {
        unsigned int this_len;
@@ -934,7 +931,7 @@ void acornscsi_data_read(AS_Host *host, char *ptr,
        else
            this_len = len;
 
-       __acornscsi_in(host->card.io_ram + (offset << 1), ptr, this_len);
+       __acornscsi_in(host->base + (offset << 1), ptr, this_len);
 
        offset += this_len;
        ptr += this_len;
@@ -943,10 +940,10 @@ void acornscsi_data_read(AS_Host *host, char *ptr,
        if (offset == (1 << 12)) {
            offset = 0;
            page ++;
-           outb((page & 0x3f) | host->card.page_reg, host->card.io_page);
+           writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
        }
     }
-    outb(host->card.page_reg, host->card.io_page);
+    writeb(host->card.page_reg, host->fast + PAGE_REG);
 }
 
 /*
@@ -963,13 +960,13 @@ static
 void acornscsi_data_write(AS_Host *host, char *ptr,
                                 unsigned int start_addr, unsigned int length)
 {
-    extern void __acornscsi_out(int port, char *buf, int len);
+    extern void __acornscsi_out(void __iomem *, char *buf, int len);
     unsigned int page, offset, len = length;
 
     page = (start_addr >> 12);
     offset = start_addr & ((1 << 12) - 1);
 
-    outb((page & 0x3f) | host->card.page_reg, host->card.io_page);
+    writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
 
     while (len > 0) {
        unsigned int this_len;
@@ -979,7 +976,7 @@ void acornscsi_data_write(AS_Host *host, char *ptr,
        else
            this_len = len;
 
-       __acornscsi_out(host->card.io_ram + (offset << 1), ptr, this_len);
+       __acornscsi_out(host->base + (offset << 1), ptr, this_len);
 
        offset += this_len;
        ptr += this_len;
@@ -988,10 +985,10 @@ void acornscsi_data_write(AS_Host *host, char *ptr,
        if (offset == (1 << 12)) {
            offset = 0;
            page ++;
-           outb((page & 0x3f) | host->card.page_reg, host->card.io_page);
+           writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
        }
     }
-    outb(host->card.page_reg, host->card.io_page);
+    writeb(host->card.page_reg, host->fast + PAGE_REG);
 }
 
 /* =========================================================================================
@@ -1008,8 +1005,8 @@ void acornscsi_data_write(AS_Host *host, char *ptr,
 static inline
 void acornscsi_dma_stop(AS_Host *host)
 {
-    dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_ON);
-    dmac_clearintr(host->dma.io_intr_clear);
+    dmac_write(host, DMAC_MASKREG, MASK_ON);
+    dmac_clearintr(host);
 
 #if (DEBUG & DEBUG_DMA)
     DBG(host->SCpnt, acornscsi_dumpdma(host, "stop"));
@@ -1031,7 +1028,7 @@ void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
 
     host->dma.direction = direction;
 
-    dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_ON);
+    dmac_write(host, DMAC_MASKREG, MASK_ON);
 
     if (direction == DMA_OUT) {
 #if (DEBUG & DEBUG_NO_WRITE)
@@ -1062,13 +1059,13 @@ void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
                                length);
 
        length -= 1;
-       dmac_write(host->dma.io_port, DMAC_TXCNTLO, length);
-       dmac_write(host->dma.io_port, DMAC_TXCNTHI, length >> 8);
-       dmac_write(host->dma.io_port, DMAC_TXADRLO, address);
-       dmac_write(host->dma.io_port, DMAC_TXADRMD, address >> 8);
-       dmac_write(host->dma.io_port, DMAC_TXADRHI, 0);
-       dmac_write(host->dma.io_port, DMAC_MODECON, mode);
-       dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_OFF);
+       dmac_write(host, DMAC_TXCNTLO, length);
+       dmac_write(host, DMAC_TXCNTHI, length >> 8);
+       dmac_write(host, DMAC_TXADRLO, address);
+       dmac_write(host, DMAC_TXADRMD, address >> 8);
+       dmac_write(host, DMAC_TXADRHI, 0);
+       dmac_write(host, DMAC_MODECON, mode);
+       dmac_write(host, DMAC_MASKREG, MASK_OFF);
 
 #if (DEBUG & DEBUG_DMA)
        DBG(host->SCpnt, acornscsi_dumpdma(host, "strt"));
@@ -1088,8 +1085,8 @@ void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
 static
 void acornscsi_dma_cleanup(AS_Host *host)
 {
-    dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_ON);
-    dmac_clearintr(host->dma.io_intr_clear);
+    dmac_write(host, DMAC_MASKREG, MASK_ON);
+    dmac_clearintr(host);
 
     /*
      * Check for a pending transfer
@@ -1116,7 +1113,7 @@ void acornscsi_dma_cleanup(AS_Host *host)
        /*
         * Calculate number of bytes transferred from DMA.
         */
-       transferred = dmac_address(host->dma.io_port) - host->dma.start_addr;
+       transferred = dmac_address(host) - host->dma.start_addr;
        host->dma.transferred += transferred;
 
        if (host->dma.direction == DMA_IN)
@@ -1152,13 +1149,13 @@ void acornscsi_dma_intr(AS_Host *host)
     DBG(host->SCpnt, acornscsi_dumpdma(host, "inti"));
 #endif
 
-    dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_ON);
-    dmac_clearintr(host->dma.io_intr_clear);
+    dmac_write(host, DMAC_MASKREG, MASK_ON);
+    dmac_clearintr(host);
 
     /*
      * Calculate amount transferred via DMA
      */
-    transferred = dmac_address(host->dma.io_port) - host->dma.start_addr;
+    transferred = dmac_address(host) - host->dma.start_addr;
     host->dma.transferred += transferred;
 
     /*
@@ -1190,12 +1187,12 @@ void acornscsi_dma_intr(AS_Host *host)
                                length);
 
        length -= 1;
-       dmac_write(host->dma.io_port, DMAC_TXCNTLO, length);
-       dmac_write(host->dma.io_port, DMAC_TXCNTHI, length >> 8);
-       dmac_write(host->dma.io_port, DMAC_TXADRLO, address);
-       dmac_write(host->dma.io_port, DMAC_TXADRMD, address >> 8);
-       dmac_write(host->dma.io_port, DMAC_TXADRHI, 0);
-       dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_OFF);
+       dmac_write(host, DMAC_TXCNTLO, length);
+       dmac_write(host, DMAC_TXCNTHI, length >> 8);
+       dmac_write(host, DMAC_TXADRLO, address);
+       dmac_write(host, DMAC_TXADRMD, address >> 8);
+       dmac_write(host, DMAC_TXADRHI, 0);
+       dmac_write(host, DMAC_MASKREG, MASK_OFF);
 
 #if (DEBUG & DEBUG_DMA)
        DBG(host->SCpnt, acornscsi_dumpdma(host, "into"));
@@ -1209,15 +1206,15 @@ void acornscsi_dma_intr(AS_Host *host)
         * attention condition.  We continue giving one byte until
         * the device recognises the attention.
         */
-       if (dmac_read(host->dma.io_port, DMAC_STATUS) & STATUS_RQ0) {
+       if (dmac_read(host, DMAC_STATUS) & STATUS_RQ0) {
            acornscsi_abortcmd(host, host->SCpnt->tag);
 
-           dmac_write(host->dma.io_port, DMAC_TXCNTLO, 0);
-           dmac_write(host->dma.io_port, DMAC_TXCNTHI, 0);
-           dmac_write(host->dma.io_port, DMAC_TXADRLO, 0);
-           dmac_write(host->dma.io_port, DMAC_TXADRMD, 0);
-           dmac_write(host->dma.io_port, DMAC_TXADRHI, 0);
-           dmac_write(host->dma.io_port, DMAC_MASKREG, MASK_OFF);
+           dmac_write(host, DMAC_TXCNTLO, 0);
+           dmac_write(host, DMAC_TXCNTHI, 0);
+           dmac_write(host, DMAC_TXADRLO, 0);
+           dmac_write(host, DMAC_TXADRMD, 0);
+           dmac_write(host, DMAC_TXADRHI, 0);
+           dmac_write(host, DMAC_MASKREG, MASK_OFF);
        }
 #endif
     }
@@ -1271,9 +1268,9 @@ void acornscsi_dma_adjust(AS_Host *host)
            host->dma.xfer_setup = 0;
        else {
            transferred += host->dma.start_addr;
-           dmac_write(host->dma.io_port, DMAC_TXADRLO, transferred);
-           dmac_write(host->dma.io_port, DMAC_TXADRMD, transferred >> 8);
-           dmac_write(host->dma.io_port, DMAC_TXADRHI, transferred >> 16);
+           dmac_write(host, DMAC_TXADRLO, transferred);
+           dmac_write(host, DMAC_TXADRMD, transferred >> 8);
+           dmac_write(host, DMAC_TXADRHI, transferred >> 16);
 #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
            DBG(host->SCpnt, acornscsi_dumpdma(host, "adjo"));
 #endif
@@ -1292,12 +1289,12 @@ acornscsi_write_pio(AS_Host *host, char *bytes, int *ptr, int len, unsigned int
        int my_ptr = *ptr;
 
        while (my_ptr < len) {
-               asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
+               asr = sbic_arm_read(host, SBIC_ASR);
 
                if (asr & ASR_DBR) {
                        timeout = max_timeout;
 
-                       sbic_arm_write(host->scsi.io_port, SBIC_DATA, bytes[my_ptr++]);
+                       sbic_arm_write(host, SBIC_DATA, bytes[my_ptr++]);
                } else if (asr & ASR_INT)
                        break;
                else if (--timeout == 0)
@@ -1320,9 +1317,9 @@ acornscsi_sendcommand(AS_Host *host)
 {
        struct scsi_cmnd *SCpnt = host->SCpnt;
 
-    sbic_arm_write(host->scsi.io_port, SBIC_TRANSCNTH, 0);
-    sbic_arm_writenext(host->scsi.io_port, 0);
-    sbic_arm_writenext(host->scsi.io_port, SCpnt->cmd_len - host->scsi.SCp.sent_command);
+    sbic_arm_write(host, SBIC_TRANSCNTH, 0);
+    sbic_arm_writenext(host, 0);
+    sbic_arm_writenext(host, SCpnt->cmd_len - host->scsi.SCp.sent_command);
 
     acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
 
@@ -1351,7 +1348,7 @@ void acornscsi_sendmessage(AS_Host *host)
 
        acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 1");
 
-       sbic_arm_write(host->scsi.io_port, SBIC_DATA, NOP);
+       sbic_arm_write(host, SBIC_DATA, NOP);
 
        host->scsi.last_message = NOP;
 #if (DEBUG & DEBUG_MESSAGES)
@@ -1365,7 +1362,7 @@ void acornscsi_sendmessage(AS_Host *host)
 
        acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 2");
 
-       sbic_arm_write(host->scsi.io_port, SBIC_DATA, msg->msg[0]);
+       sbic_arm_write(host, SBIC_DATA, msg->msg[0]);
 
        host->scsi.last_message = msg->msg[0];
 #if (DEBUG & DEBUG_MESSAGES)
@@ -1382,9 +1379,9 @@ void acornscsi_sendmessage(AS_Host *host)
         *  initiator.  This provides an interlock so that the
         *  initiator can determine which message byte is rejected.
         */
-       sbic_arm_write(host->scsi.io_port, SBIC_TRANSCNTH, 0);
-       sbic_arm_writenext(host->scsi.io_port, 0);
-       sbic_arm_writenext(host->scsi.io_port, message_length);
+       sbic_arm_write(host, SBIC_TRANSCNTH, 0);
+       sbic_arm_writenext(host, 0);
+       sbic_arm_writenext(host, message_length);
        acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
 
        msgnr = 0;
@@ -1421,7 +1418,7 @@ void acornscsi_readstatusbyte(AS_Host *host)
 {
     acornscsi_sbic_issuecmd(host, CMND_XFERINFO|CMND_SBT);
     acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "reading status byte");
-    host->scsi.SCp.Status = sbic_arm_read(host->scsi.io_port, SBIC_DATA);
+    host->scsi.SCp.Status = sbic_arm_read(host, SBIC_DATA);
 }
 
 /*
@@ -1438,12 +1435,12 @@ unsigned char acornscsi_readmessagebyte(AS_Host *host)
 
     acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "for message byte");
 
-    message = sbic_arm_read(host->scsi.io_port, SBIC_DATA);
+    message = sbic_arm_read(host, SBIC_DATA);
 
     /* wait for MSGIN-XFER-PAUSED */
     acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after message byte");
 
-    sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+    sbic_arm_read(host, SBIC_SSR);
 
     return message;
 }
@@ -1480,7 +1477,7 @@ void acornscsi_message(AS_Host *host)
 
            /* wait for next msg-in */
            acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after negate ack");
-           sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+           sbic_arm_read(host, SBIC_SSR);
        }
     } while (msgidx < msglen);
 
@@ -1602,7 +1599,7 @@ void acornscsi_message(AS_Host *host)
                    host->host->host_no, acornscsi_target(host));
            host->device[host->SCpnt->device->id].sync_xfer = SYNCHTRANSFER_2DBA;
            host->device[host->SCpnt->device->id].sync_state = SYNC_ASYNCHRONOUS;
-           sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
+           sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
            break;
 
        default:
@@ -1652,7 +1649,7 @@ void acornscsi_message(AS_Host *host)
                host->device[host->SCpnt->device->id].sync_xfer =
                        calc_sync_xfer(period * 4, length);
            }
-           sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
+           sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
            break;
 #else
            /* We do not accept synchronous transfers.  Respond with a
@@ -1792,10 +1789,10 @@ int acornscsi_starttransfer(AS_Host *host)
 
     residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
 
-    sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
-    sbic_arm_writenext(host->scsi.io_port, residual >> 16);
-    sbic_arm_writenext(host->scsi.io_port, residual >> 8);
-    sbic_arm_writenext(host->scsi.io_port, residual);
+    sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
+    sbic_arm_writenext(host, residual >> 16);
+    sbic_arm_writenext(host, residual >> 8);
+    sbic_arm_writenext(host, residual);
     acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
     return 1;
 }
@@ -1816,7 +1813,7 @@ int acornscsi_reconnect(AS_Host *host)
 {
     unsigned int target, lun, ok = 0;
 
-    target = sbic_arm_read(host->scsi.io_port, SBIC_SOURCEID);
+    target = sbic_arm_read(host, SBIC_SOURCEID);
 
     if (!(target & 8))
        printk(KERN_ERR "scsi%d: invalid source id after reselection "
@@ -1832,7 +1829,7 @@ int acornscsi_reconnect(AS_Host *host)
        host->SCpnt = NULL;
     }
 
-    lun = sbic_arm_read(host->scsi.io_port, SBIC_DATA) & 7;
+    lun = sbic_arm_read(host, SBIC_DATA) & 7;
 
     host->scsi.reconnected.target = target;
     host->scsi.reconnected.lun = lun;
@@ -1952,7 +1949,7 @@ static
 void acornscsi_abortcmd(AS_Host *host, unsigned char tag)
 {
     host->scsi.phase = PHASE_ABORTED;
-    sbic_arm_write(host->scsi.io_port, SBIC_CMND, CMND_ASSERTATN);
+    sbic_arm_write(host, SBIC_CMND, CMND_ASSERTATN);
 
     msgqueue_flush(&host->scsi.msgs);
 #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
@@ -1979,11 +1976,11 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
 {
     unsigned int asr, ssr;
 
-    asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
+    asr = sbic_arm_read(host, SBIC_ASR);
     if (!(asr & ASR_INT))
        return INTR_IDLE;
 
-    ssr = sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+    ssr = sbic_arm_read(host, SBIC_SSR);
 
 #if (DEBUG & DEBUG_PHASES)
     print_sbic_status(asr, ssr, host->scsi.phase);
@@ -1999,15 +1996,15 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        printk(KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
                host->host->host_no);
        /* setup sbic - WD33C93A */
-       sbic_arm_write(host->scsi.io_port, SBIC_OWNID, OWNID_EAF | host->host->this_id);
-       sbic_arm_write(host->scsi.io_port, SBIC_CMND, CMND_RESET);
+       sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
+       sbic_arm_write(host, SBIC_CMND, CMND_RESET);
        return INTR_IDLE;
 
     case 0x01:                         /* reset state - advanced                       */
-       sbic_arm_write(host->scsi.io_port, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
-       sbic_arm_write(host->scsi.io_port, SBIC_TIMEOUT, TIMEOUT_TIME);
-       sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
-       sbic_arm_write(host->scsi.io_port, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
+       sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
+       sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
+       sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
+       sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
        msgqueue_flush(&host->scsi.msgs);
        return INTR_IDLE;
 
@@ -2025,10 +2022,10 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
            msgqueue_flush(&host->scsi.msgs);
            host->dma.transferred = host->scsi.SCp.scsi_xferred;
            /* 33C93 gives next interrupt indicating bus phase */
-           asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
+           asr = sbic_arm_read(host, SBIC_ASR);
            if (!(asr & ASR_INT))
                break;
-           ssr = sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+           ssr = sbic_arm_read(host, SBIC_SSR);
            ADD_STATUS(8, ssr, host->scsi.phase, 1);
            ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, 1);
            goto connected;
@@ -2476,11 +2473,11 @@ acornscsi_intr(int irq, void *dev_id)
     do {
        ret = INTR_IDLE;
 
-       iostatus = inb(host->card.io_intr);
+       iostatus = readb(host->fast + INT_REG);
 
        if (iostatus & 2) {
            acornscsi_dma_intr(host);
-           iostatus = inb(host->card.io_intr);
+           iostatus = readb(host->fast + INT_REG);
        }
 
        if (iostatus & 8)
@@ -2655,7 +2652,7 @@ static enum res_abort acornscsi_do_abort(AS_Host *host, struct scsi_cmnd *SCpnt)
                 * busylun bit.
                 */
                case PHASE_CONNECTED:
-                       sbic_arm_write(host->scsi.io_port, SBIC_CMND, CMND_DISCONNECT);
+                       sbic_arm_write(host, SBIC_CMND, CMND_DISCONNECT);
                        host->SCpnt = NULL;
                        res = res_success_clear;
                        break;
@@ -2699,8 +2696,8 @@ int acornscsi_abort(struct scsi_cmnd *SCpnt)
 #if (DEBUG & DEBUG_ABORT)
        {
                int asr, ssr;
-               asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
-               ssr = sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+               asr = sbic_arm_read(host, SBIC_ASR);
+               ssr = sbic_arm_read(host, SBIC_SSR);
 
                printk(KERN_WARNING "acornscsi_abort: ");
                print_sbic_status(asr, ssr, host->scsi.phase);
@@ -2731,9 +2728,7 @@ int acornscsi_abort(struct scsi_cmnd *SCpnt)
 //#if (DEBUG & DEBUG_ABORT)
                printk("success\n");
 //#endif
-               SCpnt->result = DID_ABORT << 16;
-               SCpnt->scsi_done(SCpnt);
-               result = SCSI_ABORT_SUCCESS;
+               result = SUCCESS;
                break;
 
        /*
@@ -2745,7 +2740,7 @@ int acornscsi_abort(struct scsi_cmnd *SCpnt)
 //#if (DEBUG & DEBUG_ABORT)
                printk("snooze\n");
 //#endif
-               result = SCSI_ABORT_SNOOZE;
+               result = FAILED;
                break;
 
        /*
@@ -2755,11 +2750,7 @@ int acornscsi_abort(struct scsi_cmnd *SCpnt)
        default:
        case res_not_running:
                acornscsi_dumplog(host, SCpnt->device->id);
-#if (DEBUG & DEBUG_ABORT)
-               result = SCSI_ABORT_SNOOZE;
-#else
-               result = SCSI_ABORT_NOT_RUNNING;
-#endif
+               result = FAILED;
 //#if (DEBUG & DEBUG_ABORT)
                printk("not running\n");
 //#endif
@@ -2770,13 +2761,12 @@ int acornscsi_abort(struct scsi_cmnd *SCpnt)
 }
 
 /*
- * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt, unsigned int reset_flags)
+ * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt)
  * Purpose  : reset a command on this host/reset this host
  * Params   : SCpnt  - command causing reset
- *           result - what type of reset to perform
  * Returns  : one of SCSI_RESET_ macros
  */
-int acornscsi_reset(struct scsi_cmnd *SCpnt, unsigned int reset_flags)
+int acornscsi_bus_reset(struct scsi_cmnd *SCpnt)
 {
        AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
        struct scsi_cmnd *SCptr;
@@ -2787,8 +2777,8 @@ int acornscsi_reset(struct scsi_cmnd *SCpnt, unsigned int reset_flags)
     {
        int asr, ssr;
 
-       asr = sbic_arm_read(host->scsi.io_port, SBIC_ASR);
-       ssr = sbic_arm_read(host->scsi.io_port, SBIC_SSR);
+       asr = sbic_arm_read(host, SBIC_ASR);
+       ssr = sbic_arm_read(host, SBIC_SSR);
 
        printk(KERN_WARNING "acornscsi_reset: ");
        print_sbic_status(asr, ssr, host->scsi.phase);
@@ -2798,28 +2788,16 @@ int acornscsi_reset(struct scsi_cmnd *SCpnt, unsigned int reset_flags)
 
     acornscsi_dma_stop(host);
 
-    SCptr = host->SCpnt;
-
     /*
      * do hard reset.  This resets all devices on this host, and so we
      * must set the reset status on all commands.
      */
     acornscsi_resetcard(host);
 
-    /*
-     * report reset on commands current connected/disconnected
-     */
-    acornscsi_reportstatus(&host->SCpnt, &SCptr, DID_RESET);
-
     while ((SCptr = queue_remove(&host->queues.disconnected)) != NULL)
-       acornscsi_reportstatus(&SCptr, &SCpnt, DID_RESET);
-
-    if (SCpnt) {
-       SCpnt->result = DID_RESET << 16;
-       SCpnt->scsi_done(SCpnt);
-    }
+       ;
 
-    return SCSI_RESET_BUS_RESET | SCSI_RESET_HOST_RESET | SCSI_RESET_SUCCESS;
+    return SUCCESS;
 }
 
 /*==============================================================================================
@@ -2850,7 +2828,7 @@ char *acornscsi_info(struct Scsi_Host *host)
     " LINK"
 #endif
 #if (DEBUG & DEBUG_NO_WRITE)
-    " NOWRITE ("NO_WRITE_STR")"
+    " NOWRITE (" __stringify(NO_WRITE) ")"
 #endif
                , host->hostt->name, host->io_port, host->irq,
                VER_MAJOR, VER_MINOR, VER_PATCH);
@@ -2881,15 +2859,15 @@ int acornscsi_proc_info(struct Scsi_Host *instance, char *buffer, char **start,
     " LINK"
 #endif
 #if (DEBUG & DEBUG_NO_WRITE)
-    " NOWRITE ("NO_WRITE_STR")"
+    " NOWRITE (" __stringify(NO_WRITE) ")"
 #endif
                "\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
 
-    p += sprintf(p,    "SBIC: WD33C93A  Address: %08X  IRQ : %d\n",
-                       host->scsi.io_port, host->scsi.irq);
+    p += sprintf(p,    "SBIC: WD33C93A  Address: %p    IRQ : %d\n",
+                       host->base + SBIC_REGIDX, host->scsi.irq);
 #ifdef USE_DMAC
-    p += sprintf(p,    "DMAC: uPC71071  Address: %08X  IRQ : %d\n\n",
-                       host->dma.io_port, host->scsi.irq);
+    p += sprintf(p,    "DMAC: uPC71071  Address: %p  IRQ : %d\n\n",
+                       host->base + DMAC_OFFSET, host->scsi.irq);
 #endif
 
     p += sprintf(p,    "Statistics:\n"
@@ -2976,9 +2954,8 @@ static struct scsi_host_template acornscsi_template = {
        .name                   = "AcornSCSI",
        .info                   = acornscsi_info,
        .queuecommand           = acornscsi_queuecmd,
-#warning fixme
-       .abort                  = acornscsi_abort,
-       .reset                  = acornscsi_reset,
+       .eh_abort_handler       = acornscsi_abort,
+       .eh_bus_reset_handler   = acornscsi_bus_reset,
        .can_queue              = 16,
        .this_id                = 7,
        .sg_tablesize           = SG_ALL,
@@ -2992,48 +2969,37 @@ acornscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
 {
        struct Scsi_Host *host;
        AS_Host *ashost;
-       int ret = -ENOMEM;
+       int ret;
 
-       host = scsi_host_alloc(&acornscsi_template, sizeof(AS_Host));
-       if (!host)
+       ret = ecard_request_resources(ec);
+       if (ret)
                goto out;
 
+       host = scsi_host_alloc(&acornscsi_template, sizeof(AS_Host));
+       if (!host) {
+               ret = -ENOMEM;
+               goto out_release;
+       }
+
        ashost = (AS_Host *)host->hostdata;
 
-       host->io_port = ecard_address(ec, ECARD_MEMC, 0);
-       host->irq = ec->irq;
+       ashost->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
+       ashost->fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
+       if (!ashost->base || !ashost->fast)
+               goto out_put;
 
-       ashost->host            = host;
-       ashost->scsi.io_port    = ioaddr(host->io_port + 0x800);
-       ashost->scsi.irq        = host->irq;
-       ashost->card.io_intr    = POD_SPACE(host->io_port) + 0x800;
-       ashost->card.io_page    = POD_SPACE(host->io_port) + 0xc00;
-       ashost->card.io_ram     = ioaddr(host->io_port);
-       ashost->dma.io_port     = host->io_port + 0xc00;
-       ashost->dma.io_intr_clear = POD_SPACE(host->io_port) + 0x800;
+       host->irq = ec->irq;
+       ashost->host = host;
+       ashost->scsi.irq = host->irq;
 
-       ec->irqaddr     = (char *)ioaddr(ashost->card.io_intr);
+       ec->irqaddr     = ashost->fast + INT_REG;
        ec->irqmask     = 0x0a;
 
-       ret = -EBUSY;
-       if (!request_region(host->io_port + 0x800, 2, "acornscsi(sbic)"))
-               goto err_1;
-       if (!request_region(ashost->card.io_intr, 1, "acornscsi(intr)"))
-               goto err_2;
-       if (!request_region(ashost->card.io_page, 1, "acornscsi(page)"))
-               goto err_3;
-#ifdef USE_DMAC
-       if (!request_region(ashost->dma.io_port, 256, "acornscsi(dmac)"))
-               goto err_4;
-#endif
-       if (!request_region(host->io_port, 2048, "acornscsi(ram)"))
-               goto err_5;
-
        ret = request_irq(host->irq, acornscsi_intr, IRQF_DISABLED, "acornscsi", ashost);
        if (ret) {
                printk(KERN_CRIT "scsi%d: IRQ%d not free: %d\n",
                        host->host_no, ashost->scsi.irq, ret);
-               goto err_6;
+               goto out_put;
        }
 
        memset(&ashost->stats, 0, sizeof (ashost->stats));
@@ -3045,27 +3011,22 @@ acornscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
 
        ret = scsi_add_host(host, &ec->dev);
        if (ret)
-               goto err_7;
+               goto out_irq;
 
        scsi_scan_host(host);
        goto out;
 
err_7:
out_irq:
        free_irq(host->irq, ashost);
- err_6:
-       release_region(host->io_port, 2048);
- err_5:
-#ifdef USE_DMAC
-       release_region(ashost->dma.io_port, 256);
-#endif
- err_4:
-       release_region(ashost->card.io_page, 1);
- err_3:
-       release_region(ashost->card.io_intr, 1);    
- err_2:
-       release_region(host->io_port + 0x800, 2);
- err_1:
+       msgqueue_free(&ashost->scsi.msgs);
+       queue_free(&ashost->queues.disconnected);
+       queue_free(&ashost->queues.issue);
+ out_put:
+       ecardm_iounmap(ec, ashost->fast);
+       ecardm_iounmap(ec, ashost->base);
        scsi_host_put(host);
+ out_release:
+       ecard_release_resources(ec);
  out:
        return ret;
 }
@@ -3081,20 +3042,17 @@ static void __devexit acornscsi_remove(struct expansion_card *ec)
        /*
         * Put card into RESET state
         */
-       outb(0x80, ashost->card.io_page);
+       writeb(0x80, ashost->fast + PAGE_REG);
 
        free_irq(host->irq, ashost);
 
-       release_region(host->io_port + 0x800, 2);
-       release_region(ashost->card.io_intr, 1);
-       release_region(ashost->card.io_page, 1);
-       release_region(ashost->dma.io_port, 256);
-       release_region(host->io_port, 2048);
-
        msgqueue_free(&ashost->scsi.msgs);
        queue_free(&ashost->queues.disconnected);
        queue_free(&ashost->queues.issue);
+       ecardm_iounmap(ec, ashost->fast);
+       ecardm_iounmap(ec, ashost->base);
        scsi_host_put(host);
+       ecard_release_resources(ec);
 }
 
 static const struct ecard_id acornscsi_cids[] = {
index d11424b..8d2172a 100644 (file)
 
 /* miscellaneous internal variables */
 
-#define POD_SPACE(x)   ((x) + 0xd0000)
 #define MASK_ON                (MASKREG_M3|MASKREG_M2|MASKREG_M1|MASKREG_M0)
 #define MASK_OFF       (MASKREG_M3|MASKREG_M2|MASKREG_M1)
 
@@ -279,10 +278,11 @@ typedef struct acornscsi_hostdata {
     struct Scsi_Host   *host;                  /* host                                 */
     struct scsi_cmnd   *SCpnt;                 /* currently processing command         */
     struct scsi_cmnd   *origSCpnt;             /* original connecting command          */
+    void __iomem       *base;                  /* memc base address                    */
+    void __iomem       *fast;                  /* fast ioc base address                */
 
     /* driver information */
     struct {
-       unsigned int    io_port;                /* base address of WD33C93              */
        unsigned int    irq;                    /* interrupt                            */
        phase_t         phase;                  /* current phase                        */
 
@@ -329,8 +329,6 @@ typedef struct acornscsi_hostdata {
 
     /* DMA info */
     struct {
-       unsigned int    io_port;                /* base address of DMA controller       */
-       unsigned int    io_intr_clear;          /* address of DMA interrupt clear       */
        unsigned int    free_addr;              /* next free address                    */
        unsigned int    start_addr;             /* start address of current transfer    */
        dmadir_t        direction;              /* dma direction                        */
@@ -345,9 +343,6 @@ typedef struct acornscsi_hostdata {
 
     /* card info */
     struct {
-       unsigned int    io_intr;                /* base address of interrupt id reg     */
-       unsigned int    io_page;                /* base address of page reg             */
-       unsigned int    io_ram;                 /* base address of RAM access           */
        unsigned char   page_reg;               /* current setting of page reg          */
     } card;
 
index c4b938b..aa2011b 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/chio.h>                        /* here are all the ioctls */
 #include <linux/mutex.h>
 #include <linux/idr.h>
+#include <linux/smp_lock.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -571,16 +572,19 @@ ch_open(struct inode *inode, struct file *file)
        scsi_changer *ch;
        int minor = iminor(inode);
 
+       lock_kernel();
        spin_lock(&ch_index_lock);
        ch = idr_find(&ch_index_idr, minor);
 
        if (NULL == ch || scsi_device_get(ch->device)) {
                spin_unlock(&ch_index_lock);
+               unlock_kernel();
                return -ENXIO;
        }
        spin_unlock(&ch_index_lock);
 
        file->private_data = ch;
+       unlock_kernel();
        return 0;
 }
 
index 8508816..2bc30e3 100644 (file)
@@ -49,6 +49,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
 #include <linux/kernel.h>      /* for printk */
 #include <linux/sched.h>
 #include <linux/reboot.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/dma-mapping.h>
 
@@ -1727,10 +1728,12 @@ static int adpt_open(struct inode *inode, struct file *file)
        int minor;
        adpt_hba* pHba;
 
+       lock_kernel();
        //TODO check for root access
        //
        minor = iminor(inode);
        if (minor >= hba_count) {
+               unlock_kernel();
                return -ENXIO;
        }
        mutex_lock(&adpt_configuration_lock);
@@ -1741,6 +1744,7 @@ static int adpt_open(struct inode *inode, struct file *file)
        }
        if (pHba == NULL) {
                mutex_unlock(&adpt_configuration_lock);
+               unlock_kernel();
                return -ENXIO;
        }
 
@@ -1751,6 +1755,7 @@ static int adpt_open(struct inode *inode, struct file *file)
 
        pHba->in_use = 1;
        mutex_unlock(&adpt_configuration_lock);
+       unlock_kernel();
 
        return 0;
 }
index 46771d4..822d521 100644 (file)
 #include <linux/timer.h>
 #include <linux/dma-mapping.h>
 #include <linux/list.h>
+#include <linux/smp_lock.h>
 
 #ifdef GDTH_RTC
 #include <linux/mc146818rtc.h>
@@ -4019,10 +4020,12 @@ static int gdth_open(struct inode *inode, struct file *filep)
 {
     gdth_ha_str *ha;
 
+    lock_kernel();
     list_for_each_entry(ha, &gdth_instances, list) {
         if (!ha->sdev)
             ha->sdev = scsi_get_host_dev(ha->shost);
     }
+    unlock_kernel();
 
     TRACE(("gdth_open()\n"));
     return 0;
index 18551aa..28c9da7 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/dma-mapping.h>
+#include <linux/smp_lock.h>
 #include <scsi/scsicam.h>
 
 #include "scsi.h"
@@ -3272,12 +3273,12 @@ mega_init_scb(adapter_t *adapter)
  * @filep - unused
  *
  * Routines for the character/ioctl interface to the driver. Find out if this
- * is a valid open. If yes, increment the module use count so that it cannot
- * be unloaded.
+ * is a valid open. 
  */
 static int
 megadev_open (struct inode *inode, struct file *filep)
 {
+       cycle_kernel_lock();
        /*
         * Only allow superuser to access private ioctl interface
         */
index 0ad215e..ac3b280 100644 (file)
@@ -15,6 +15,7 @@
  * Common management module
  */
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include "megaraid_mm.h"
 
 
@@ -96,6 +97,7 @@ mraid_mm_open(struct inode *inode, struct file *filep)
         */
        if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
 
+       cycle_kernel_lock();
        return 0;
 }
 
index 7d84c8b..fc7ac15 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/smp_lock.h>
 #include <linux/uio.h>
 #include <asm/uaccess.h>
 #include <linux/fs.h>
@@ -2863,6 +2864,7 @@ static void megasas_shutdown(struct pci_dev *pdev)
  */
 static int megasas_mgmt_open(struct inode *inode, struct file *filep)
 {
+       cycle_kernel_lock();
        /*
         * Allow only those users with admin rights
         */
index 243d8be..1c79f97 100644 (file)
@@ -50,6 +50,7 @@ static const char * osst_version = "0.99.4";
 #include <linux/moduleparam.h>
 #include <linux/delay.h>
 #include <linux/jiffies.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/dma.h>
 #include <asm/system.h>
@@ -4359,7 +4360,7 @@ os_bypass:
 
 
 /* Open the device */
-static int os_scsi_tape_open(struct inode * inode, struct file * filp)
+static int __os_scsi_tape_open(struct inode * inode, struct file * filp)
 {
        unsigned short        flags;
        int                   i, b_size, new_session = 0, retval = 0;
@@ -4725,6 +4726,18 @@ err_out:
        return retval;
 }
 
+/* BKL pushdown: spaghetti avoidance wrapper */
+static int os_scsi_tape_open(struct inode * inode, struct file * filp)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __os_scsi_tape_open(inode, filp);
+       unlock_kernel();
+       return ret;
+}
+
+
 
 /* Flush the tape buffer before close */
 static int os_scsi_tape_flush(struct file * filp, fl_owner_t id)
index d2557db..0e9533f 100644 (file)
@@ -21,6 +21,7 @@
  */
 #include <linux/miscdevice.h>
 #include <linux/file.h>
+#include <linux/smp_lock.h>
 #include <net/tcp.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -321,6 +322,7 @@ static int tgt_open(struct inode *inode, struct file *file)
 {
        tx_ring.tr_idx = rx_ring.tr_idx = 0;
 
+       cycle_kernel_lock();
        return 0;
 }
 
index ea0edd1..fccd2e8 100644 (file)
@@ -49,6 +49,7 @@ static int sg_version_num = 30534;    /* 2 digits for each component */
 #include <linux/delay.h>
 #include <linux/scatterlist.h>
 #include <linux/blktrace_api.h>
+#include <linux/smp_lock.h>
 
 #include "scsi.h"
 #include <scsi/scsi_dbg.h>
@@ -182,8 +183,9 @@ static int sg_build_sgat(Sg_scatter_hold * schp, const Sg_fd * sfp,
                         int tablesize);
 static ssize_t sg_new_read(Sg_fd * sfp, char __user *buf, size_t count,
                           Sg_request * srp);
-static ssize_t sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count,
-                           int blocking, int read_only, Sg_request ** o_srp);
+static ssize_t sg_new_write(Sg_fd *sfp, struct file *file,
+                       const char __user *buf, size_t count, int blocking,
+                       int read_only, Sg_request **o_srp);
 static int sg_common_write(Sg_fd * sfp, Sg_request * srp,
                           unsigned char *cmnd, int timeout, int blocking);
 static int sg_u_iovec(sg_io_hdr_t * hp, int sg_num, int ind,
@@ -204,7 +206,6 @@ static Sg_request *sg_get_rq_mark(Sg_fd * sfp, int pack_id);
 static Sg_request *sg_add_request(Sg_fd * sfp);
 static int sg_remove_request(Sg_fd * sfp, Sg_request * srp);
 static int sg_res_in_use(Sg_fd * sfp);
-static int sg_allow_access(unsigned char opcode, char dev_type);
 static int sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len);
 static Sg_device *sg_get_dev(int dev);
 #ifdef CONFIG_SCSI_PROC_FS
@@ -227,19 +228,26 @@ sg_open(struct inode *inode, struct file *filp)
        int res;
        int retval;
 
+       lock_kernel();
        nonseekable_open(inode, filp);
        SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags));
        sdp = sg_get_dev(dev);
-       if ((!sdp) || (!sdp->device))
+       if ((!sdp) || (!sdp->device)) {
+               unlock_kernel();
                return -ENXIO;
-       if (sdp->detached)
+       }
+       if (sdp->detached) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        /* This driver's module count bumped by fops_get in <linux/fs.h> */
        /* Prevent the device driver from vanishing while we sleep */
        retval = scsi_device_get(sdp->device);
-       if (retval)
+       if (retval) {
+               unlock_kernel();
                return retval;
+       }
 
        if (!((flags & O_NONBLOCK) ||
              scsi_block_when_processing_errors(sdp->device))) {
@@ -295,10 +303,12 @@ sg_open(struct inode *inode, struct file *filp)
                retval = -ENOMEM;
                goto error_out;
        }
+       unlock_kernel();
        return 0;
 
       error_out:
        scsi_device_put(sdp->device);
+       unlock_kernel();
        return retval;
 }
 
@@ -544,7 +554,7 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
                return -EFAULT;
        blocking = !(filp->f_flags & O_NONBLOCK);
        if (old_hdr.reply_len < 0)
-               return sg_new_write(sfp, buf, count, blocking, 0, NULL);
+               return sg_new_write(sfp, filp, buf, count, blocking, 0, NULL);
        if (count < (SZ_SG_HEADER + 6))
                return -EIO;    /* The minimum scsi command length is 6 bytes. */
 
@@ -621,8 +631,9 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
 }
 
 static ssize_t
-sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count,
-            int blocking, int read_only, Sg_request ** o_srp)
+sg_new_write(Sg_fd *sfp, struct file *file, const char __user *buf,
+                size_t count, int blocking, int read_only,
+                Sg_request **o_srp)
 {
        int k;
        Sg_request *srp;
@@ -678,8 +689,7 @@ sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count,
                sg_remove_request(sfp, srp);
                return -EFAULT;
        }
-       if (read_only &&
-           (!sg_allow_access(cmnd[0], sfp->parentdp->device->type))) {
+       if (read_only && !blk_verify_command(file, cmnd)) {
                sg_remove_request(sfp, srp);
                return -EPERM;
        }
@@ -799,7 +809,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
                        if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR))
                                return -EFAULT;
                        result =
-                           sg_new_write(sfp, p, SZ_SG_IO_HDR,
+                           sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
                                         blocking, read_only, &srp);
                        if (result < 0)
                                return result;
@@ -1048,7 +1058,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
 
                        if (copy_from_user(&opcode, siocp->data, 1))
                                return -EFAULT;
-                       if (!sg_allow_access(opcode, sdp->device->type))
+                       if (!blk_verify_command(filp, &opcode))
                                return -EPERM;
                }
                return sg_scsi_ioctl(filp, sdp->device->request_queue, NULL, p);
@@ -2502,30 +2512,6 @@ sg_page_free(struct page *page, int size)
        __free_pages(page, order);
 }
 
-#ifndef MAINTENANCE_IN_CMD
-#define MAINTENANCE_IN_CMD 0xa3
-#endif
-
-static unsigned char allow_ops[] = { TEST_UNIT_READY, REQUEST_SENSE,
-       INQUIRY, READ_CAPACITY, READ_BUFFER, READ_6, READ_10, READ_12,
-       READ_16, MODE_SENSE, MODE_SENSE_10, LOG_SENSE, REPORT_LUNS,
-       SERVICE_ACTION_IN, RECEIVE_DIAGNOSTIC, READ_LONG, MAINTENANCE_IN_CMD
-};
-
-static int
-sg_allow_access(unsigned char opcode, char dev_type)
-{
-       int k;
-
-       if (TYPE_SCANNER == dev_type)   /* TYPE_ROM maybe burner */
-               return 1;
-       for (k = 0; k < sizeof (allow_ops); ++k) {
-               if (opcode == allow_ops[k])
-                       return 1;
-       }
-       return 0;
-}
-
 #ifdef CONFIG_SCSI_PROC_FS
 static int
 sg_idr_max_id(int id, void *p, void *data)
index c82df8b..27f5bfd 100644 (file)
@@ -673,24 +673,20 @@ fail:
 static void get_sectorsize(struct scsi_cd *cd)
 {
        unsigned char cmd[10];
-       unsigned char *buffer;
+       unsigned char buffer[8];
        int the_result, retries = 3;
        int sector_size;
        struct request_queue *queue;
 
-       buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
-       if (!buffer)
-               goto Enomem;
-
        do {
                cmd[0] = READ_CAPACITY;
                memset((void *) &cmd[1], 0, 9);
-               memset(buffer, 0, 8);
+               memset(buffer, 0, sizeof(buffer));
 
                /* Do the command and wait.. */
                the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
-                                             buffer, 8, NULL, SR_TIMEOUT,
-                                             MAX_RETRIES);
+                                             buffer, sizeof(buffer), NULL,
+                                             SR_TIMEOUT, MAX_RETRIES);
 
                retries--;
 
@@ -745,14 +741,8 @@ static void get_sectorsize(struct scsi_cd *cd)
 
        queue = cd->device->request_queue;
        blk_queue_hardsect_size(queue, sector_size);
-out:
-       kfree(buffer);
-       return;
 
-Enomem:
-       cd->capacity = 0x1fffff;
-       cd->device->sector_size = 2048; /* A guess, just in case */
-       goto out;
+       return;
 }
 
 static void get_capabilities(struct scsi_cd *cd)
index 6e5a5bb..4684cc7 100644 (file)
@@ -38,6 +38,7 @@ static const char *verstr = "20080224";
 #include <linux/cdev.h>
 #include <linux/delay.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/dma.h>
@@ -1113,7 +1114,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
 }
 
 
-\f/* Open the device. Needs to be called with BKL only because of incrementing the SCSI host
+\f/* Open the device. Needs to take the BKL only because of incrementing the SCSI host
    module count. */
 static int st_open(struct inode *inode, struct file *filp)
 {
@@ -1123,6 +1124,7 @@ static int st_open(struct inode *inode, struct file *filp)
        int dev = TAPE_NR(inode);
        char *name;
 
+       lock_kernel();
        /*
         * We really want to do nonseekable_open(inode, filp); here, but some
         * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -1130,8 +1132,10 @@ static int st_open(struct inode *inode, struct file *filp)
         */
        filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
 
-       if (!(STp = scsi_tape_get(dev)))
+       if (!(STp = scsi_tape_get(dev))) {
+               unlock_kernel();
                return -ENXIO;
+       }
 
        write_lock(&st_dev_arr_lock);
        filp->private_data = STp;
@@ -1140,6 +1144,7 @@ static int st_open(struct inode *inode, struct file *filp)
        if (STp->in_use) {
                write_unlock(&st_dev_arr_lock);
                scsi_tape_put(STp);
+               unlock_kernel();
                DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
                return (-EBUSY);
        }
@@ -1188,12 +1193,14 @@ static int st_open(struct inode *inode, struct file *filp)
                        retval = (-EIO);
                goto err_out;
        }
+       unlock_kernel();
        return 0;
 
  err_out:
        normalize_buffer(STp->buffer);
        STp->in_use = 0;
        scsi_tape_put(STp);
+       unlock_kernel();
        return retval;
 
 }
index 9bc4276..18ca907 100644 (file)
@@ -448,22 +448,27 @@ config SERIAL_CLPS711X_CONSOLE
          your boot loader (lilo or loadlin) about how to pass options to the
          kernel at boot time.)
 
-config SERIAL_S3C2410
-       tristate "Samsung S3C2410/S3C2440/S3C2442/S3C2412 Serial port support"
-       depends on ARM && ARCH_S3C2410
-       select SERIAL_CORE
+config SERIAL_SAMSUNG
+       tristate "Samsung SoC serial support"
+       depends on ARM && PLAT_S3C24XX
        help
          Support for the on-chip UARTs on the Samsung S3C24XX series CPUs,
          providing /dev/ttySAC0, 1 and 2 (note, some machines may not
          provide all of these ports, depending on how the serial port
          pins are configured.
 
-         Currently this driver supports the UARTS on the S3C2410, S3C2440,
-         S3C2442, S3C2412 and S3C2413 CPUs.
+config SERIAL_SAMSUNG_DEBUG
+       bool "Samsung SoC serial debug"
+       depends on SERIAL_SAMSUNG
+       help
+         Add support for debugging the serial driver. Since this is
+         generally being used as a console, we use our own output
+         routines that go via the low-level debug printascii()
+         function.
 
-config SERIAL_S3C2410_CONSOLE
-       bool "Support for console on S3C2410 serial port"
-       depends on SERIAL_S3C2410=y
+config SERIAL_SAMSUNG_CONSOLE
+       bool "Support for console on Samsung SoC serial port"
+       depends on SERIAL_SAMSUNG=y
        select SERIAL_CORE_CONSOLE
        help
          Allow selection of the S3C24XX on-board serial ports for use as
@@ -476,6 +481,37 @@ config SERIAL_S3C2410_CONSOLE
          your boot loader about how to pass options to the kernel at
          boot time.)
 
+config SERIAL_S3C2400
+       tristate "Samsung S3C2410 Serial port support"
+       depends on ARM && SERIAL_SAMSUNG && CPU_S3C2400
+       default y if CPU_S3C2400
+       help
+         Serial port support for the Samsung S3C2400 SoC
+
+config SERIAL_S3C2410
+       tristate "Samsung S3C2410 Serial port support"
+       depends on SERIAL_SAMSUNG && CPU_S3C2410
+       default y if CPU_S3C2410
+       help
+         Serial port support for the Samsung S3C2410 SoC
+
+config SERIAL_S3C2412
+       tristate "Samsung S3C2412/S3C2413 Serial port support"
+       depends on SERIAL_SAMSUNG && CPU_S3C2412
+       default y if CPU_S3C2412
+       help
+         Serial port support for the Samsung S3C2412 and S3C2413 SoC
+
+config SERIAL_S3C2440
+       tristate "Samsung S3C2440/S3C2442 Serial port support"
+       depends on SERIAL_SAMSUNG && (CPU_S3C2440 || CPU_S3C2442)
+       default y if CPU_S3C2440
+       default y if CPU_S3C2442
+       help
+         Serial port support for the Samsung S3C2440 and S3C2442 SoC
+
+
+
 config SERIAL_DZ
        bool "DECstation DZ serial driver"
        depends on MACH_DECSTATION && 32BIT
@@ -753,7 +789,7 @@ config BFIN_UART3_CTSRTS
 
 config SERIAL_IMX
        bool "IMX serial port support"
-       depends on ARM && ARCH_IMX
+       depends on ARM && (ARCH_IMX || ARCH_MXC)
        select SERIAL_CORE
        help
          If you have a machine based on a Motorola IMX CPU you
index 0d9c09b..7d85c1f 100644 (file)
@@ -28,7 +28,11 @@ obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
 obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
+obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o
+obj-$(CONFIG_SERIAL_S3C2400) += s3c2400.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
+obj-$(CONFIG_SERIAL_S3C2412) += s3c2412.o
+obj-$(CONFIG_SERIAL_S3C2440) += s3c2440.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
 obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
index 42be8b0..6aeef22 100644 (file)
@@ -1439,14 +1439,29 @@ static struct uart_driver atmel_uart = {
 };
 
 #ifdef CONFIG_PM
+static bool atmel_serial_clk_will_stop(void)
+{
+#ifdef CONFIG_ARCH_AT91
+       return at91_suspend_entering_slow_clock();
+#else
+       return false;
+#endif
+}
+
 static int atmel_serial_suspend(struct platform_device *pdev,
                                pm_message_t state)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
        struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
+       if (atmel_is_console_port(port) && console_suspend_enabled) {
+               /* Drain the TX shifter */
+               while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY))
+                       cpu_relax();
+       }
+
        if (device_may_wakeup(&pdev->dev)
-           && !at91_suspend_entering_slow_clock())
+           && !atmel_serial_clk_will_stop())
                enable_irq_wake(port->irq);
        else {
                uart_suspend_port(&atmel_uart, port);
index 5a375bf..64acb39 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
 #include <linux/serial.h>
+#include <linux/clk.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
 #define UBIR  0xa4 /* BRM Incremental Register */
 #define UBMR  0xa8 /* BRM Modulator Register */
 #define UBRC  0xac /* Baud Rate Count Register */
+#if defined CONFIG_ARCH_MX3 || defined CONFIG_ARCH_MX2
+#define ONEMS 0xb0 /* One Millisecond register */
+#define UTS   0xb4 /* UART Test Register */
+#endif
+#ifdef CONFIG_ARCH_IMX
 #define BIPR1 0xb0 /* Incremental Preset Register 1 */
 #define BIPR2 0xb4 /* Incremental Preset Register 2 */
 #define BIPR3 0xb8 /* Incremental Preset Register 3 */
@@ -70,6 +76,7 @@
 #define BMPR3 0xc8 /* BRM Modulator Register 3 */
 #define BMPR4 0xcc /* BRM Modulator Register 4 */
 #define UTS   0xd0 /* UART Test Register */
+#endif
 
 /* UART Control Register Bit Fields.*/
 #define  URXD_CHARRDY    (1<<15)
 #define  UCR1_RTSDEN     (1<<5)         /* RTS delta interrupt enable */
 #define  UCR1_SNDBRK     (1<<4)         /* Send break */
 #define  UCR1_TDMAEN     (1<<3)         /* Transmitter ready DMA enable */
+#ifdef CONFIG_ARCH_IMX
 #define  UCR1_UARTCLKEN  (1<<2)         /* UART clock enabled */
+#endif
+#if defined CONFIG_ARCH_MX3 || defined CONFIG_ARCH_MX2
+#define  UCR1_UARTCLKEN  (0)    /* not present on mx2/mx3 */
+#endif
 #define  UCR1_DOZE       (1<<1)         /* Doze */
 #define  UCR1_UARTEN     (1<<0)         /* UART enabled */
 #define  UCR2_ESCI              (1<<15) /* Escape seq interrupt enable */
 #define  UTS_SOFTRST    (1<<0)  /* Software reset */
 
 /* We've been assigned a range on the "Low-density serial ports" major */
+#ifdef CONFIG_ARCH_IMX
 #define SERIAL_IMX_MAJOR       204
 #define MINOR_START            41
+#define DEV_NAME               "ttySMX"
+#define MAX_INTERNAL_IRQ       IMX_IRQS
+#endif
+
+#if defined CONFIG_ARCH_MX3 || defined CONFIG_ARCH_MX2
+#define SERIAL_IMX_MAJOR        207
+#define MINOR_START            16
+#define DEV_NAME               "ttymxc"
+#define MAX_INTERNAL_IRQ       MXC_MAX_INT_LINES
+#endif
 
 /*
  * This determines how often we check the modem status signals
 
 #define DRIVER_NAME "IMX-uart"
 
+#define UART_NR 8
+
 struct imx_port {
        struct uart_port        port;
        struct timer_list       timer;
        unsigned int            old_status;
        int                     txirq,rxirq,rtsirq;
        int                     have_rtscts:1;
+       struct clk              *clk;
 };
 
 /*
@@ -405,6 +431,26 @@ out:
        return IRQ_HANDLED;
 }
 
+static irqreturn_t imx_int(int irq, void *dev_id)
+{
+       struct imx_port *sport = dev_id;
+       unsigned int sts;
+
+       sts = readl(sport->port.membase + USR1);
+
+       if (sts & USR1_RRDY)
+               imx_rxint(irq, dev_id);
+
+       if (sts & USR1_TRDY &&
+                       readl(sport->port.membase + UCR1) & UCR1_TXMPTYEN)
+               imx_txint(irq, dev_id);
+
+       if (sts & USR1_RTSS)
+               imx_rtsint(irq, dev_id);
+
+       return IRQ_HANDLED;
+}
+
 /*
  * Return TIOCSER_TEMT when transmitter is not busy.
  */
@@ -477,7 +523,8 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
         * RFDIV is set such way to satisfy requested uartclk value
         */
        val = TXTL << 10 | RXTL;
-       ufcr_rfdiv = (imx_get_perclk1() + sport->port.uartclk / 2) / sport->port.uartclk;
+       ufcr_rfdiv = (clk_get_rate(sport->clk) + sport->port.uartclk / 2)
+                       / sport->port.uartclk;
 
        if(!ufcr_rfdiv)
                ufcr_rfdiv = 1;
@@ -509,21 +556,34 @@ static int imx_startup(struct uart_port *port)
        writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);
 
        /*
-        * Allocate the IRQ
+        * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
+        * chips only have one interrupt.
         */
-       retval = request_irq(sport->rxirq, imx_rxint, 0,
-                            DRIVER_NAME, sport);
-       if (retval) goto error_out1;
-
-       retval = request_irq(sport->txirq, imx_txint, 0,
-                            DRIVER_NAME, sport);
-       if (retval) goto error_out2;
-
-       retval = request_irq(sport->rtsirq, imx_rtsint,
-                            (sport->rtsirq < IMX_IRQS) ? 0 :
+       if (sport->txirq > 0) {
+               retval = request_irq(sport->rxirq, imx_rxint, 0,
+                               DRIVER_NAME, sport);
+               if (retval)
+                       goto error_out1;
+
+               retval = request_irq(sport->txirq, imx_txint, 0,
+                               DRIVER_NAME, sport);
+               if (retval)
+                       goto error_out2;
+
+               retval = request_irq(sport->rtsirq, imx_rtsint,
+                            (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 :
                               IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
-                            DRIVER_NAME, sport);
-       if (retval) goto error_out3;
+                               DRIVER_NAME, sport);
+               if (retval)
+                       goto error_out3;
+       } else {
+               retval = request_irq(sport->port.irq, imx_int, 0,
+                               DRIVER_NAME, sport);
+               if (retval) {
+                       free_irq(sport->port.irq, sport);
+                       goto error_out1;
+               }
+       }
 
        /*
         * Finally, clear and enable interrupts
@@ -548,9 +608,11 @@ static int imx_startup(struct uart_port *port)
        return 0;
 
 error_out3:
-       free_irq(sport->txirq, sport);
+       if (sport->txirq)
+               free_irq(sport->txirq, sport);
 error_out2:
-       free_irq(sport->rxirq, sport);
+       if (sport->rxirq)
+               free_irq(sport->rxirq, sport);
 error_out1:
        return retval;
 }
@@ -568,9 +630,12 @@ static void imx_shutdown(struct uart_port *port)
        /*
         * Free the interrupts
         */
-       free_irq(sport->rtsirq, sport);
-       free_irq(sport->txirq, sport);
-       free_irq(sport->rxirq, sport);
+       if (sport->txirq > 0) {
+               free_irq(sport->rtsirq, sport);
+               free_irq(sport->txirq, sport);
+               free_irq(sport->rxirq, sport);
+       } else
+               free_irq(sport->port.irq, sport);
 
        /*
         * Disable all interrupts, port and break condition.
@@ -589,6 +654,7 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
        unsigned long flags;
        unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
        unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+       unsigned int div, num, denom, ufcr;
 
        /*
         * If we don't support modem control lines, don't allow
@@ -634,7 +700,7 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
        /*
         * Ask the core to calculate the divisor for us.
         */
-       baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
+       baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16);
        quot = uart_get_divisor(port, baud);
 
        spin_lock_irqsave(&sport->port.lock, flags);
@@ -684,14 +750,41 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
                        sport->port.membase + UCR2);
        old_txrxen &= (UCR2_TXEN | UCR2_RXEN);
 
-       /* set the baud rate. We assume uartclk = 16 MHz
-        *
-        * baud * 16   UBIR - 1
-        * --------- = --------
-        *  uartclk    UBMR - 1
-        */
-       writel((baud / 100) - 1, sport->port.membase + UBIR);
-       writel(10000 - 1, sport->port.membase + UBMR);
+       div = sport->port.uartclk / (baud * 16);
+       if (div > 7)
+               div = 7;
+       if (!div)
+               div = 1;
+
+       num = baud;
+       denom = port->uartclk / div / 16;
+
+       /* shift num and denom right until they fit into 16 bits */
+       while (num > 0x10000 || denom > 0x10000) {
+               num >>= 1;
+               denom >>= 1;
+       }
+       if (num > 0)
+               num -= 1;
+       if (denom > 0)
+               denom -= 1;
+
+       writel(num, sport->port.membase + UBIR);
+       writel(denom, sport->port.membase + UBMR);
+
+       if (div == 7)
+               div = 6; /* 6 in RFDIV means divide by 7 */
+       else
+               div = 6 - div;
+
+       ufcr = readl(sport->port.membase + UFCR);
+       ufcr = (ufcr & (~UFCR_RFDIV)) |
+           (div << 7);
+       writel(ufcr, sport->port.membase + UFCR);
+
+#ifdef ONEMS
+       writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
+#endif
 
        writel(old_ucr1, sport->port.membase + UCR1);
 
@@ -801,65 +894,7 @@ static struct uart_ops imx_pops = {
        .verify_port    = imx_verify_port,
 };
 
-static struct imx_port imx_ports[] = {
-       {
-       .txirq  = UART1_MINT_TX,
-       .rxirq  = UART1_MINT_RX,
-       .rtsirq = UART1_MINT_RTS,
-       .port   = {
-               .type           = PORT_IMX,
-               .iotype         = UPIO_MEM,
-               .membase        = (void *)IMX_UART1_BASE,
-               .mapbase        = 0x00206000,
-               .irq            = UART1_MINT_RX,
-               .uartclk        = 16000000,
-               .fifosize       = 32,
-               .flags          = UPF_BOOT_AUTOCONF,
-               .ops            = &imx_pops,
-               .line           = 0,
-       },
-       }, {
-       .txirq  = UART2_MINT_TX,
-       .rxirq  = UART2_MINT_RX,
-       .rtsirq = UART2_MINT_RTS,
-       .port   = {
-               .type           = PORT_IMX,
-               .iotype         = UPIO_MEM,
-               .membase        = (void *)IMX_UART2_BASE,
-               .mapbase        = 0x00207000,
-               .irq            = UART2_MINT_RX,
-               .uartclk        = 16000000,
-               .fifosize       = 32,
-               .flags          = UPF_BOOT_AUTOCONF,
-               .ops            = &imx_pops,
-               .line           = 1,
-       },
-       }
-};
-
-/*
- * Setup the IMX serial ports.
- * Note also that we support "console=ttySMXx" where "x" is either 0 or 1.
- * Which serial port this ends up being depends on the machine you're
- * running this kernel on.  I'm not convinced that this is a good idea,
- * but that's the way it traditionally works.
- *
- */
-static void __init imx_init_ports(void)
-{
-       static int first = 1;
-       int i;
-
-       if (!first)
-               return;
-       first = 0;
-
-       for (i = 0; i < ARRAY_SIZE(imx_ports); i++) {
-               init_timer(&imx_ports[i].timer);
-               imx_ports[i].timer.function = imx_timeout;
-               imx_ports[i].timer.data     = (unsigned long)&imx_ports[i];
-       }
-}
+static struct imx_port *imx_ports[UART_NR];
 
 #ifdef CONFIG_SERIAL_IMX_CONSOLE
 static void imx_console_putchar(struct uart_port *port, int ch)
@@ -878,7 +913,7 @@ static void imx_console_putchar(struct uart_port *port, int ch)
 static void
 imx_console_write(struct console *co, const char *s, unsigned int count)
 {
-       struct imx_port *sport = &imx_ports[co->index];
+       struct imx_port *sport = imx_ports[co->index];
        unsigned int old_ucr1, old_ucr2;
 
        /*
@@ -944,7 +979,7 @@ imx_console_get_options(struct imx_port *sport, int *baud,
                else
                        ucfr_rfdiv = 6 - ucfr_rfdiv;
 
-               uartclk = imx_get_perclk1();
+               uartclk = clk_get_rate(sport->clk);
                uartclk /= ucfr_rfdiv;
 
                {       /*
@@ -984,7 +1019,7 @@ imx_console_setup(struct console *co, char *options)
         */
        if (co->index == -1 || co->index >= ARRAY_SIZE(imx_ports))
                co->index = 0;
-       sport = &imx_ports[co->index];
+       sport = imx_ports[co->index];
 
        if (options)
                uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -998,7 +1033,7 @@ imx_console_setup(struct console *co, char *options)
 
 static struct uart_driver imx_reg;
 static struct console imx_console = {
-       .name           = "ttySMX",
+       .name           = DEV_NAME,
        .write          = imx_console_write,
        .device         = uart_console_device,
        .setup          = imx_console_setup,
@@ -1007,14 +1042,6 @@ static struct console imx_console = {
        .data           = &imx_reg,
 };
 
-static int __init imx_rs_console_init(void)
-{
-       imx_init_ports();
-       register_console(&imx_console);
-       return 0;
-}
-console_initcall(imx_rs_console_init);
-
 #define IMX_CONSOLE    &imx_console
 #else
 #define IMX_CONSOLE    NULL
@@ -1023,7 +1050,7 @@ console_initcall(imx_rs_console_init);
 static struct uart_driver imx_reg = {
        .owner          = THIS_MODULE,
        .driver_name    = DRIVER_NAME,
-       .dev_name       = "ttySMX",
+       .dev_name       = DEV_NAME,
        .major          = SERIAL_IMX_MAJOR,
        .minor          = MINOR_START,
        .nr             = ARRAY_SIZE(imx_ports),
@@ -1050,29 +1077,98 @@ static int serial_imx_resume(struct platform_device *dev)
         return 0;
 }
 
-static int serial_imx_probe(struct platform_device *dev)
+static int serial_imx_probe(struct platform_device *pdev)
 {
+       struct imx_port *sport;
        struct imxuart_platform_data *pdata;
+       void __iomem *base;
+       int ret = 0;
+       struct resource *res;
+
+       sport = kzalloc(sizeof(*sport), GFP_KERNEL);
+       if (!sport)
+               return -ENOMEM;
 
-       imx_ports[dev->id].port.dev = &dev->dev;
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               ret = -ENODEV;
+               goto free;
+       }
+
+       base = ioremap(res->start, PAGE_SIZE);
+       if (!base) {
+               ret = -ENOMEM;
+               goto free;
+       }
+
+       sport->port.dev = &pdev->dev;
+       sport->port.mapbase = res->start;
+       sport->port.membase = base;
+       sport->port.type = PORT_IMX,
+       sport->port.iotype = UPIO_MEM;
+       sport->port.irq = platform_get_irq(pdev, 0);
+       sport->rxirq = platform_get_irq(pdev, 0);
+       sport->txirq = platform_get_irq(pdev, 1);
+       sport->rtsirq = platform_get_irq(pdev, 2);
+       sport->port.fifosize = 32;
+       sport->port.ops = &imx_pops;
+       sport->port.flags = UPF_BOOT_AUTOCONF;
+       sport->port.line = pdev->id;
+       init_timer(&sport->timer);
+       sport->timer.function = imx_timeout;
+       sport->timer.data     = (unsigned long)sport;
+
+       sport->clk = clk_get(&pdev->dev, "uart_clk");
+       if (IS_ERR(sport->clk)) {
+               ret = PTR_ERR(sport->clk);
+               goto unmap;
+       }
+       clk_enable(sport->clk);
 
-       pdata = (struct imxuart_platform_data *)dev->dev.platform_data;
+       sport->port.uartclk = clk_get_rate(sport->clk);
+
+       imx_ports[pdev->id] = sport;
+
+       pdata = pdev->dev.platform_data;
        if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
-               imx_ports[dev->id].have_rtscts = 1;
+               sport->have_rtscts = 1;
+
+       if (pdata->init)
+               pdata->init(pdev);
+
+       uart_add_one_port(&imx_reg, &sport->port);
+       platform_set_drvdata(pdev, &sport->port);
 
-       uart_add_one_port(&imx_reg, &imx_ports[dev->id].port);
-       platform_set_drvdata(dev, &imx_ports[dev->id]);
        return 0;
+unmap:
+       iounmap(sport->port.membase);
+free:
+       kfree(sport);
+
+       return ret;
 }
 
-static int serial_imx_remove(struct platform_device *dev)
+static int serial_imx_remove(struct platform_device *pdev)
 {
-       struct imx_port *sport = platform_get_drvdata(dev);
+       struct imxuart_platform_data *pdata;
+       struct imx_port *sport = platform_get_drvdata(pdev);
 
-       platform_set_drvdata(dev, NULL);
+       pdata = pdev->dev.platform_data;
 
-       if (sport)
+       platform_set_drvdata(pdev, NULL);
+
+       if (sport) {
                uart_remove_one_port(&imx_reg, &sport->port);
+               clk_put(sport->clk);
+       }
+
+       clk_disable(sport->clk);
+
+       if (pdata->exit)
+               pdata->exit(pdev);
+
+       iounmap(sport->port.membase);
+       kfree(sport);
 
        return 0;
 }
@@ -1095,8 +1191,6 @@ static int __init imx_serial_init(void)
 
        printk(KERN_INFO "Serial: IMX driver\n");
 
-       imx_init_ports();
-
        ret = uart_register_driver(&imx_reg);
        if (ret)
                return ret;
diff --git a/drivers/serial/s3c2400.c b/drivers/serial/s3c2400.c
new file mode 100644 (file)
index 0000000..a110205
--- /dev/null
@@ -0,0 +1,106 @@
+/* linux/drivers/serial/s3c240.c
+ *
+ * Driver for Samsung SoC onboard UARTs.
+ *
+ * Ben Dooks, Copyright (c) 2003-2005 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+#include <asm/irq.h>
+
+#include <asm/hardware.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
+
+#include "samsung.h"
+
+static int s3c2400_serial_getsource(struct uart_port *port,
+                                   struct s3c24xx_uart_clksrc *clk)
+{
+       clk->divisor = 1;
+       clk->name = "pclk";
+
+       return 0;
+}
+
+static int s3c2400_serial_setsource(struct uart_port *port,
+                                   struct s3c24xx_uart_clksrc *clk)
+{
+       return 0;
+}
+
+static int s3c2400_serial_resetport(struct uart_port *port,
+                                   struct s3c2410_uartcfg *cfg)
+{
+       dbg("s3c2400_serial_resetport: port=%p (%08lx), cfg=%p\n",
+           port, port->mapbase, cfg);
+
+       wr_regl(port, S3C2410_UCON,  cfg->ucon);
+       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
+
+       /* reset both fifos */
+
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
+
+       return 0;
+}
+
+static struct s3c24xx_uart_info s3c2400_uart_inf = {
+       .name           = "Samsung S3C2400 UART",
+       .type           = PORT_S3C2400,
+       .fifosize       = 16,
+       .rx_fifomask    = S3C2410_UFSTAT_RXMASK,
+       .rx_fifoshift   = S3C2410_UFSTAT_RXSHIFT,
+       .rx_fifofull    = S3C2410_UFSTAT_RXFULL,
+       .tx_fifofull    = S3C2410_UFSTAT_TXFULL,
+       .tx_fifomask    = S3C2410_UFSTAT_TXMASK,
+       .tx_fifoshift   = S3C2410_UFSTAT_TXSHIFT,
+       .get_clksrc     = s3c2400_serial_getsource,
+       .set_clksrc     = s3c2400_serial_setsource,
+       .reset_port     = s3c2400_serial_resetport,
+};
+
+static int s3c2400_serial_probe(struct platform_device *dev)
+{
+       return s3c24xx_serial_probe(dev, &s3c2400_uart_inf);
+}
+
+static struct platform_driver s3c2400_serial_drv = {
+       .probe          = s3c2400_serial_probe,
+       .remove         = s3c24xx_serial_remove,
+       .driver         = {
+               .name   = "s3c2400-uart",
+               .owner  = THIS_MODULE,
+       },
+};
+
+s3c24xx_console_init(&s3c2400_serial_drv, &s3c2400_uart_inf);
+
+static inline int s3c2400_serial_init(void)
+{
+       return s3c24xx_serial_init(&s3c2400_serial_drv, &s3c2400_uart_inf);
+}
+
+static inline void s3c2400_serial_exit(void)
+{
+       platform_driver_unregister(&s3c2400_serial_drv);
+}
+
+module_init(s3c2400_serial_init);
+module_exit(s3c2400_serial_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
+MODULE_DESCRIPTION("Samsung S3C2400 SoC Serial port driver");
+MODULE_ALIAS("platform:s3c2400-uart");
index 2b6a013..c5f03f4 100644 (file)
-/*
- * linux/drivers/serial/s3c2410.c
+/* linux/drivers/serial/s3c2410.c
  *
- * Driver for onboard UARTs on the Samsung S3C24XX
+ * Driver for Samsung S3C2410 SoC onboard UARTs.
  *
- * Based on drivers/char/serial.c and drivers/char/21285.c
+ * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
  *
- * Ben Dooks, (c) 2003-2005 Simtec Electronics
- *     http://www.simtec.co.uk/products/SWLINUX/
- *
- * Changelog:
- *
- * 22-Jul-2004  BJD  Finished off device rewrite
- *
- * 21-Jul-2004  BJD  Thanks to <herbet@13thfloor.at> for pointing out
- *                   problems with baud rate and loss of IR settings. Update
- *                   to add configuration via platform_device structure
- *
- * 28-Sep-2004  BJD  Re-write for the following items
- *                  - S3C2410 and S3C2440 serial support
- *                  - Power Management support
- *                  - Fix console via IrDA devices
- *                  - SysReq (Herbert Pötzl)
- *                  - Break character handling (Herbert Pötzl)
- *                  - spin-lock initialisation (Dimitry Andric)
- *                  - added clock control
- *                  - updated init code to use platform_device info
- *
- * 06-Mar-2005  BJD  Add s3c2440 fclk clock source
- *
- * 09-Mar-2005  BJD  Add s3c2400 support
- *
- * 10-Mar-2005  LCVR Changed S3C2410_VA_UART to S3C24XX_VA_UART
-*/
-
-/* Note on 2440 fclk clock source handling
- *
- * Whilst it is possible to use the fclk as clock source, the method
- * of properly switching too/from this is currently un-implemented, so
- * whichever way is configured at startup is the one that will be used.
-*/
-
-/* Hote on 2410 error handling
- *
- * The s3c2410 manual has a love/hate affair with the contents of the
- * UERSTAT register in the UART blocks, and keeps marking some of the
- * error bits as reserved. Having checked with the s3c2410x01,
- * it copes with BREAKs properly, so I am happy to ignore the RESERVED
- * feature from the latter versions of the manual.
- *
- * If it becomes aparrent that latter versions of the 2410 remove these
- * bits, then action will have to be taken to differentiate the versions
- * and change the policy on BREAK
- *
- * BJD, 04-Nov-2004
-*/
-
-
-#if defined(CONFIG_SERIAL_S3C2410_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
-#define SUPPORT_SYSRQ
-#endif
-
-#include <linux/module.h>
-#include <linux/ioport.h>
-#include <linux/platform_device.h>
-#include <linux/init.h>
-#include <linux/sysrq.h>
-#include <linux/console.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial_core.h>
-#include <linux/serial.h>
-#include <linux/delay.h>
-#include <linux/clk.h>
-
-#include <asm/io.h>
-#include <asm/irq.h>
-
-#include <asm/hardware.h>
-
-#include <asm/plat-s3c/regs-serial.h>
-#include <asm/arch/regs-gpio.h>
-
-/* structures */
-
-struct s3c24xx_uart_info {
-       char                    *name;
-       unsigned int            type;
-       unsigned int            fifosize;
-       unsigned long           rx_fifomask;
-       unsigned long           rx_fifoshift;
-       unsigned long           rx_fifofull;
-       unsigned long           tx_fifomask;
-       unsigned long           tx_fifoshift;
-       unsigned long           tx_fifofull;
-
-       /* clock source control */
-
-       int (*get_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
-       int (*set_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
-
-       /* uart controls */
-       int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *);
-};
-
-struct s3c24xx_uart_port {
-       unsigned char                   rx_claimed;
-       unsigned char                   tx_claimed;
-
-       struct s3c24xx_uart_info        *info;
-       struct s3c24xx_uart_clksrc      *clksrc;
-       struct clk                      *clk;
-       struct clk                      *baudclk;
-       struct uart_port                port;
-};
-
-
-/* configuration defines */
-
-#if 0
-#if 1
-/* send debug to the low-level output routines */
-
-extern void printascii(const char *);
-
-static void
-s3c24xx_serial_dbg(const char *fmt, ...)
-{
-       va_list va;
-       char buff[256];
-
-       va_start(va, fmt);
-       vsprintf(buff, fmt, va);
-       va_end(va);
-
-       printascii(buff);
-}
-
-#define dbg(x...) s3c24xx_serial_dbg(x)
-
-#else
-#define dbg(x...) printk(KERN_DEBUG "s3c24xx: ");
-#endif
-#else /* no debug */
-#define dbg(x...) do {} while(0)
-#endif
-
-/* UART name and device definitions */
-
-#define S3C24XX_SERIAL_NAME    "ttySAC"
-#define S3C24XX_SERIAL_MAJOR   204
-#define S3C24XX_SERIAL_MINOR   64
-
-
-/* conversion functions */
-
-#define s3c24xx_dev_to_port(__dev) (struct uart_port *)dev_get_drvdata(__dev)
-#define s3c24xx_dev_to_cfg(__dev) (struct s3c2410_uartcfg *)((__dev)->platform_data)
-
-/* we can support 3 uarts, but not always use them */
-
-#ifdef CONFIG_CPU_S3C2400
-#define NR_PORTS (2)
-#else
-#define NR_PORTS (3)
-#endif
-
-/* port irq numbers */
-
-#define TX_IRQ(port) ((port)->irq + 1)
-#define RX_IRQ(port) ((port)->irq)
-
-/* register access controls */
-
-#define portaddr(port, reg) ((port)->membase + (reg))
-
-#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
-#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
-
-#define wr_regb(port, reg, val) \
-  do { __raw_writeb(val, portaddr(port, reg)); } while(0)
-
-#define wr_regl(port, reg, val) \
-  do { __raw_writel(val, portaddr(port, reg)); } while(0)
-
-/* macros to change one thing to another */
-
-#define tx_enabled(port) ((port)->unused[0])
-#define rx_enabled(port) ((port)->unused[1])
-
-/* flag to ignore all characters comming in */
-#define RXSTAT_DUMMY_READ (0x10000000)
-
-static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
-{
-       return container_of(port, struct s3c24xx_uart_port, port);
-}
-
-/* translate a port to the device name */
-
-static inline const char *s3c24xx_serial_portname(struct uart_port *port)
-{
-       return to_platform_device(port->dev)->name;
-}
-
-static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
-{
-       return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
-}
-
-static void s3c24xx_serial_rx_enable(struct uart_port *port)
-{
-       unsigned long flags;
-       unsigned int ucon, ufcon;
-       int count = 10000;
-
-       spin_lock_irqsave(&port->lock, flags);
-
-       while (--count && !s3c24xx_serial_txempty_nofifo(port))
-               udelay(100);
-
-       ufcon = rd_regl(port, S3C2410_UFCON);
-       ufcon |= S3C2410_UFCON_RESETRX;
-       wr_regl(port, S3C2410_UFCON, ufcon);
-
-       ucon = rd_regl(port, S3C2410_UCON);
-       ucon |= S3C2410_UCON_RXIRQMODE;
-       wr_regl(port, S3C2410_UCON, ucon);
-
-       rx_enabled(port) = 1;
-       spin_unlock_irqrestore(&port->lock, flags);
-}
-
-static void s3c24xx_serial_rx_disable(struct uart_port *port)
-{
-       unsigned long flags;
-       unsigned int ucon;
-
-       spin_lock_irqsave(&port->lock, flags);
-
-       ucon = rd_regl(port, S3C2410_UCON);
-       ucon &= ~S3C2410_UCON_RXIRQMODE;
-       wr_regl(port, S3C2410_UCON, ucon);
-
-       rx_enabled(port) = 0;
-       spin_unlock_irqrestore(&port->lock, flags);
-}
-
-static void s3c24xx_serial_stop_tx(struct uart_port *port)
-{
-       if (tx_enabled(port)) {
-               disable_irq(TX_IRQ(port));
-               tx_enabled(port) = 0;
-               if (port->flags & UPF_CONS_FLOW)
-                       s3c24xx_serial_rx_enable(port);
-       }
-}
-
-static void s3c24xx_serial_start_tx(struct uart_port *port)
-{
-       if (!tx_enabled(port)) {
-               if (port->flags & UPF_CONS_FLOW)
-                       s3c24xx_serial_rx_disable(port);
-
-               enable_irq(TX_IRQ(port));
-               tx_enabled(port) = 1;
-       }
-}
-
-
-static void s3c24xx_serial_stop_rx(struct uart_port *port)
-{
-       if (rx_enabled(port)) {
-               dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
-               disable_irq(RX_IRQ(port));
-               rx_enabled(port) = 0;
-       }
-}
-
-static void s3c24xx_serial_enable_ms(struct uart_port *port)
-{
-}
-
-static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
-{
-       return to_ourport(port)->info;
-}
-
-static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
-{
-       if (port->dev == NULL)
-               return NULL;
-
-       return (struct s3c2410_uartcfg *)port->dev->platform_data;
-}
-
-static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
-                                    unsigned long ufstat)
-{
-       struct s3c24xx_uart_info *info = ourport->info;
-
-       if (ufstat & info->rx_fifofull)
-               return info->fifosize;
-
-       return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
-}
-
-
-/* ? - where has parity gone?? */
-#define S3C2410_UERSTAT_PARITY (0x1000)
-
-static irqreturn_t
-s3c24xx_serial_rx_chars(int irq, void *dev_id)
-{
-       struct s3c24xx_uart_port *ourport = dev_id;
-       struct uart_port *port = &ourport->port;
-       struct tty_struct *tty = port->info->tty;
-       unsigned int ufcon, ch, flag, ufstat, uerstat;
-       int max_count = 64;
-
-       while (max_count-- > 0) {
-               ufcon = rd_regl(port, S3C2410_UFCON);
-               ufstat = rd_regl(port, S3C2410_UFSTAT);
-
-               if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
-                       break;
-
-               uerstat = rd_regl(port, S3C2410_UERSTAT);
-               ch = rd_regb(port, S3C2410_URXH);
-
-               if (port->flags & UPF_CONS_FLOW) {
-                       int txe = s3c24xx_serial_txempty_nofifo(port);
-
-                       if (rx_enabled(port)) {
-                               if (!txe) {
-                                       rx_enabled(port) = 0;
-                                       continue;
-                               }
-                       } else {
-                               if (txe) {
-                                       ufcon |= S3C2410_UFCON_RESETRX;
-                                       wr_regl(port, S3C2410_UFCON, ufcon);
-                                       rx_enabled(port) = 1;
-                                       goto out;
-                               }
-                               continue;
-                       }
-               }
-
-               /* insert the character into the buffer */
-
-               flag = TTY_NORMAL;
-               port->icount.rx++;
-
-               if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
-                       dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
-                           ch, uerstat);
-
-                       /* check for break */
-                       if (uerstat & S3C2410_UERSTAT_BREAK) {
-                               dbg("break!\n");
-                               port->icount.brk++;
-                               if (uart_handle_break(port))
-                                   goto ignore_char;
-                       }
-
-                       if (uerstat & S3C2410_UERSTAT_FRAME)
-                               port->icount.frame++;
-                       if (uerstat & S3C2410_UERSTAT_OVERRUN)
-                               port->icount.overrun++;
-
-                       uerstat &= port->read_status_mask;
-
-                       if (uerstat & S3C2410_UERSTAT_BREAK)
-                               flag = TTY_BREAK;
-                       else if (uerstat & S3C2410_UERSTAT_PARITY)
-                               flag = TTY_PARITY;
-                       else if (uerstat & ( S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_OVERRUN))
-                               flag = TTY_FRAME;
-               }
-
-               if (uart_handle_sysrq_char(port, ch))
-                       goto ignore_char;
-
-               uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, ch, flag);
-
-       ignore_char:
-               continue;
-       }
-       tty_flip_buffer_push(tty);
-
- out:
-       return IRQ_HANDLED;
-}
-
-static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
-{
-       struct s3c24xx_uart_port *ourport = id;
-       struct uart_port *port = &ourport->port;
-       struct circ_buf *xmit = &port->info->xmit;
-       int count = 256;
-
-       if (port->x_char) {
-               wr_regb(port, S3C2410_UTXH, port->x_char);
-               port->icount.tx++;
-               port->x_char = 0;
-               goto out;
-       }
-
-       /* if there isnt anything more to transmit, or the uart is now
-        * stopped, disable the uart and exit
-       */
-
-       if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
-               s3c24xx_serial_stop_tx(port);
-               goto out;
-       }
-
-       /* try and drain the buffer... */
-
-       while (!uart_circ_empty(xmit) && count-- > 0) {
-               if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
-                       break;
-
-               wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
-               xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
-               port->icount.tx++;
-       }
-
-       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
-               uart_write_wakeup(port);
-
-       if (uart_circ_empty(xmit))
-               s3c24xx_serial_stop_tx(port);
-
- out:
-       return IRQ_HANDLED;
-}
-
-static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-       unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
-       unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
-
-       if (ufcon & S3C2410_UFCON_FIFOMODE) {
-               if ((ufstat & info->tx_fifomask) != 0 ||
-                   (ufstat & info->tx_fifofull))
-                       return 0;
-
-               return 1;
-       }
-
-       return s3c24xx_serial_txempty_nofifo(port);
-}
-
-/* no modem control lines */
-static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
-{
-       unsigned int umstat = rd_regb(port,S3C2410_UMSTAT);
-
-       if (umstat & S3C2410_UMSTAT_CTS)
-               return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
-       else
-               return TIOCM_CAR | TIOCM_DSR;
-}
-
-static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
-{
-       /* todo - possibly remove AFC and do manual CTS */
-}
-
-static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
-{
-       unsigned long flags;
-       unsigned int ucon;
-
-       spin_lock_irqsave(&port->lock, flags);
-
-       ucon = rd_regl(port, S3C2410_UCON);
-
-       if (break_state)
-               ucon |= S3C2410_UCON_SBREAK;
-       else
-               ucon &= ~S3C2410_UCON_SBREAK;
-
-       wr_regl(port, S3C2410_UCON, ucon);
-
-       spin_unlock_irqrestore(&port->lock, flags);
-}
-
-static void s3c24xx_serial_shutdown(struct uart_port *port)
-{
-       struct s3c24xx_uart_port *ourport = to_ourport(port);
-
-       if (ourport->tx_claimed) {
-               free_irq(TX_IRQ(port), ourport);
-               tx_enabled(port) = 0;
-               ourport->tx_claimed = 0;
-       }
-
-       if (ourport->rx_claimed) {
-               free_irq(RX_IRQ(port), ourport);
-               ourport->rx_claimed = 0;
-               rx_enabled(port) = 0;
-       }
-}
-
-
-static int s3c24xx_serial_startup(struct uart_port *port)
-{
-       struct s3c24xx_uart_port *ourport = to_ourport(port);
-       int ret;
-
-       dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
-           port->mapbase, port->membase);
-
-       rx_enabled(port) = 1;
-
-       ret = request_irq(RX_IRQ(port),
-                         s3c24xx_serial_rx_chars, 0,
-                         s3c24xx_serial_portname(port), ourport);
-
-       if (ret != 0) {
-               printk(KERN_ERR "cannot get irq %d\n", RX_IRQ(port));
-               return ret;
-       }
-
-       ourport->rx_claimed = 1;
-
-       dbg("requesting tx irq...\n");
-
-       tx_enabled(port) = 1;
-
-       ret = request_irq(TX_IRQ(port),
-                         s3c24xx_serial_tx_chars, 0,
-                         s3c24xx_serial_portname(port), ourport);
-
-       if (ret) {
-               printk(KERN_ERR "cannot get irq %d\n", TX_IRQ(port));
-               goto err;
-       }
-
-       ourport->tx_claimed = 1;
-
-       dbg("s3c24xx_serial_startup ok\n");
-
-       /* the port reset code should have done the correct
-        * register setup for the port controls */
-
-       return ret;
-
- err:
-       s3c24xx_serial_shutdown(port);
-       return ret;
-}
-
-/* power power management control */
-
-static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
-                             unsigned int old)
-{
-       struct s3c24xx_uart_port *ourport = to_ourport(port);
-
-       switch (level) {
-       case 3:
-               if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
-                       clk_disable(ourport->baudclk);
-
-               clk_disable(ourport->clk);
-               break;
-
-       case 0:
-               clk_enable(ourport->clk);
-
-               if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
-                       clk_enable(ourport->baudclk);
-
-               break;
-       default:
-               printk(KERN_ERR "s3c24xx_serial: unknown pm %d\n", level);
-       }
-}
-
-/* baud rate calculation
- *
- * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
- * of different sources, including the peripheral clock ("pclk") and an
- * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
- * with a programmable extra divisor.
- *
- * The following code goes through the clock sources, and calculates the
- * baud clocks (and the resultant actual baud rates) and then tries to
- * pick the closest one and select that.
- *
-*/
-
-
-#define MAX_CLKS (8)
-
-static struct s3c24xx_uart_clksrc tmp_clksrc = {
-       .name           = "pclk",
-       .min_baud       = 0,
-       .max_baud       = 0,
-       .divisor        = 1,
-};
-
-static inline int
-s3c24xx_serial_getsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-
-       return (info->get_clksrc)(port, c);
-}
-
-static inline int
-s3c24xx_serial_setsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-
-       return (info->set_clksrc)(port, c);
-}
-
-struct baud_calc {
-       struct s3c24xx_uart_clksrc      *clksrc;
-       unsigned int                     calc;
-       unsigned int                     quot;
-       struct clk                      *src;
-};
-
-static int s3c24xx_serial_calcbaud(struct baud_calc *calc,
-                                  struct uart_port *port,
-                                  struct s3c24xx_uart_clksrc *clksrc,
-                                  unsigned int baud)
-{
-       unsigned long rate;
-
-       calc->src = clk_get(port->dev, clksrc->name);
-       if (calc->src == NULL || IS_ERR(calc->src))
-               return 0;
-
-       rate = clk_get_rate(calc->src);
-       rate /= clksrc->divisor;
-
-       calc->clksrc = clksrc;
-       calc->quot = (rate + (8 * baud)) / (16 * baud);
-       calc->calc = (rate / (calc->quot * 16));
-
-       calc->quot--;
-       return 1;
-}
-
-static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
-                                         struct s3c24xx_uart_clksrc **clksrc,
-                                         struct clk **clk,
-                                         unsigned int baud)
-{
-       struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
-       struct s3c24xx_uart_clksrc *clkp;
-       struct baud_calc res[MAX_CLKS];
-       struct baud_calc *resptr, *best, *sptr;
-       int i;
-
-       clkp = cfg->clocks;
-       best = NULL;
-
-       if (cfg->clocks_size < 2) {
-               if (cfg->clocks_size == 0)
-                       clkp = &tmp_clksrc;
-
-               /* check to see if we're sourcing fclk, and if so we're
-                * going to have to update the clock source
-                */
-
-               if (strcmp(clkp->name, "fclk") == 0) {
-                       struct s3c24xx_uart_clksrc src;
-
-                       s3c24xx_serial_getsource(port, &src);
-
-                       /* check that the port already using fclk, and if
-                        * not, then re-select fclk
-                        */
-
-                       if (strcmp(src.name, clkp->name) == 0) {
-                               s3c24xx_serial_setsource(port, clkp);
-                               s3c24xx_serial_getsource(port, &src);
-                       }
-
-                       clkp->divisor = src.divisor;
-               }
-
-               s3c24xx_serial_calcbaud(res, port, clkp, baud);
-               best = res;
-               resptr = best + 1;
-       } else {
-               resptr = res;
-
-               for (i = 0; i < cfg->clocks_size; i++, clkp++) {
-                       if (s3c24xx_serial_calcbaud(resptr, port, clkp, baud))
-                               resptr++;
-               }
-       }
-
-       /* ok, we now need to select the best clock we found */
-
-       if (!best) {
-               unsigned int deviation = (1<<30)|((1<<30)-1);
-               int calc_deviation;
-
-               for (sptr = res; sptr < resptr; sptr++) {
-                       printk(KERN_DEBUG
-                              "found clk %p (%s) quot %d, calc %d\n",
-                              sptr->clksrc, sptr->clksrc->name,
-                              sptr->quot, sptr->calc);
-
-                       calc_deviation = baud - sptr->calc;
-                       if (calc_deviation < 0)
-                               calc_deviation = -calc_deviation;
-
-                       if (calc_deviation < deviation) {
-                               best = sptr;
-                               deviation = calc_deviation;
-                       }
-               }
-
-               printk(KERN_DEBUG "best %p (deviation %d)\n", best, deviation);
-       }
-
-       printk(KERN_DEBUG "selected clock %p (%s) quot %d, calc %d\n",
-              best->clksrc, best->clksrc->name, best->quot, best->calc);
-
-       /* store results to pass back */
-
-       *clksrc = best->clksrc;
-       *clk    = best->src;
-
-       return best->quot;
-}
-
-static void s3c24xx_serial_set_termios(struct uart_port *port,
-                                      struct ktermios *termios,
-                                      struct ktermios *old)
-{
-       struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
-       struct s3c24xx_uart_port *ourport = to_ourport(port);
-       struct s3c24xx_uart_clksrc *clksrc = NULL;
-       struct clk *clk = NULL;
-       unsigned long flags;
-       unsigned int baud, quot;
-       unsigned int ulcon;
-       unsigned int umcon;
-
-       /*
-        * We don't support modem control lines.
-        */
-       termios->c_cflag &= ~(HUPCL | CMSPAR);
-       termios->c_cflag |= CLOCAL;
-
-       /*
-        * Ask the core to calculate the divisor for us.
-        */
-
-       baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
-
-       if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
-               quot = port->custom_divisor;
-       else
-               quot = s3c24xx_serial_getclk(port, &clksrc, &clk, baud);
-
-       /* check to see if we need  to change clock source */
-
-       if (ourport->clksrc != clksrc || ourport->baudclk != clk) {
-               s3c24xx_serial_setsource(port, clksrc);
-
-               if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
-                       clk_disable(ourport->baudclk);
-                       ourport->baudclk  = NULL;
-               }
-
-               clk_enable(clk);
-
-               ourport->clksrc = clksrc;
-               ourport->baudclk = clk;
-       }
-
-       switch (termios->c_cflag & CSIZE) {
-       case CS5:
-               dbg("config: 5bits/char\n");
-               ulcon = S3C2410_LCON_CS5;
-               break;
-       case CS6:
-               dbg("config: 6bits/char\n");
-               ulcon = S3C2410_LCON_CS6;
-               break;
-       case CS7:
-               dbg("config: 7bits/char\n");
-               ulcon = S3C2410_LCON_CS7;
-               break;
-       case CS8:
-       default:
-               dbg("config: 8bits/char\n");
-               ulcon = S3C2410_LCON_CS8;
-               break;
-       }
-
-       /* preserve original lcon IR settings */
-       ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
-
-       if (termios->c_cflag & CSTOPB)
-               ulcon |= S3C2410_LCON_STOPB;
-
-       umcon = (termios->c_cflag & CRTSCTS) ? S3C2410_UMCOM_AFC : 0;
-
-       if (termios->c_cflag & PARENB) {
-               if (termios->c_cflag & PARODD)
-                       ulcon |= S3C2410_LCON_PODD;
-               else
-                       ulcon |= S3C2410_LCON_PEVEN;
-       } else {
-               ulcon |= S3C2410_LCON_PNONE;
-       }
-
-       spin_lock_irqsave(&port->lock, flags);
-
-       dbg("setting ulcon to %08x, brddiv to %d\n", ulcon, quot);
-
-       wr_regl(port, S3C2410_ULCON, ulcon);
-       wr_regl(port, S3C2410_UBRDIV, quot);
-       wr_regl(port, S3C2410_UMCON, umcon);
-
-       dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
-           rd_regl(port, S3C2410_ULCON),
-           rd_regl(port, S3C2410_UCON),
-           rd_regl(port, S3C2410_UFCON));
-
-       /*
-        * Update the per-port timeout.
-        */
-       uart_update_timeout(port, termios->c_cflag, baud);
-
-       /*
-        * Which character status flags are we interested in?
-        */
-       port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
-       if (termios->c_iflag & INPCK)
-               port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
-
-       /*
-        * Which character status flags should we ignore?
-        */
-       port->ignore_status_mask = 0;
-       if (termios->c_iflag & IGNPAR)
-               port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
-       if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
-               port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
-
-       /*
-        * Ignore all characters if CREAD is not set.
-        */
-       if ((termios->c_cflag & CREAD) == 0)
-               port->ignore_status_mask |= RXSTAT_DUMMY_READ;
-
-       spin_unlock_irqrestore(&port->lock, flags);
-}
-
-static const char *s3c24xx_serial_type(struct uart_port *port)
-{
-       switch (port->type) {
-       case PORT_S3C2410:
-               return "S3C2410";
-       case PORT_S3C2440:
-               return "S3C2440";
-       case PORT_S3C2412:
-               return "S3C2412";
-       default:
-               return NULL;
-       }
-}
-
-#define MAP_SIZE (0x100)
-
-static void s3c24xx_serial_release_port(struct uart_port *port)
-{
-       release_mem_region(port->mapbase, MAP_SIZE);
-}
-
-static int s3c24xx_serial_request_port(struct uart_port *port)
-{
-       const char *name = s3c24xx_serial_portname(port);
-       return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
-}
-
-static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-
-       if (flags & UART_CONFIG_TYPE &&
-           s3c24xx_serial_request_port(port) == 0)
-               port->type = info->type;
-}
-
-/*
- * verify the new serial_struct (for TIOCSSERIAL).
- */
-static int
-s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-
-       if (ser->type != PORT_UNKNOWN && ser->type != info->type)
-               return -EINVAL;
-
-       return 0;
-}
-
-
-#ifdef CONFIG_SERIAL_S3C2410_CONSOLE
-
-static struct console s3c24xx_serial_console;
-
-#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
-#else
-#define S3C24XX_SERIAL_CONSOLE NULL
-#endif
-
-static struct uart_ops s3c24xx_serial_ops = {
-       .pm             = s3c24xx_serial_pm,
-       .tx_empty       = s3c24xx_serial_tx_empty,
-       .get_mctrl      = s3c24xx_serial_get_mctrl,
-       .set_mctrl      = s3c24xx_serial_set_mctrl,
-       .stop_tx        = s3c24xx_serial_stop_tx,
-       .start_tx       = s3c24xx_serial_start_tx,
-       .stop_rx        = s3c24xx_serial_stop_rx,
-       .enable_ms      = s3c24xx_serial_enable_ms,
-       .break_ctl      = s3c24xx_serial_break_ctl,
-       .startup        = s3c24xx_serial_startup,
-       .shutdown       = s3c24xx_serial_shutdown,
-       .set_termios    = s3c24xx_serial_set_termios,
-       .type           = s3c24xx_serial_type,
-       .release_port   = s3c24xx_serial_release_port,
-       .request_port   = s3c24xx_serial_request_port,
-       .config_port    = s3c24xx_serial_config_port,
-       .verify_port    = s3c24xx_serial_verify_port,
-};
-
-
-static struct uart_driver s3c24xx_uart_drv = {
-       .owner          = THIS_MODULE,
-       .dev_name       = "s3c2410_serial",
-       .nr             = 3,
-       .cons           = S3C24XX_SERIAL_CONSOLE,
-       .driver_name    = S3C24XX_SERIAL_NAME,
-       .major          = S3C24XX_SERIAL_MAJOR,
-       .minor          = S3C24XX_SERIAL_MINOR,
-};
-
-static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
-       [0] = {
-               .port = {
-                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
-                       .iotype         = UPIO_MEM,
-                       .irq            = IRQ_S3CUART_RX0,
-                       .uartclk        = 0,
-                       .fifosize       = 16,
-                       .ops            = &s3c24xx_serial_ops,
-                       .flags          = UPF_BOOT_AUTOCONF,
-                       .line           = 0,
-               }
-       },
-       [1] = {
-               .port = {
-                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
-                       .iotype         = UPIO_MEM,
-                       .irq            = IRQ_S3CUART_RX1,
-                       .uartclk        = 0,
-                       .fifosize       = 16,
-                       .ops            = &s3c24xx_serial_ops,
-                       .flags          = UPF_BOOT_AUTOCONF,
-                       .line           = 1,
-               }
-       },
-#if NR_PORTS > 2
-
-       [2] = {
-               .port = {
-                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
-                       .iotype         = UPIO_MEM,
-                       .irq            = IRQ_S3CUART_RX2,
-                       .uartclk        = 0,
-                       .fifosize       = 16,
-                       .ops            = &s3c24xx_serial_ops,
-                       .flags          = UPF_BOOT_AUTOCONF,
-                       .line           = 2,
-               }
-       }
-#endif
-};
-
-/* s3c24xx_serial_resetport
- *
- * wrapper to call the specific reset for this port (reset the fifos
- * and the settings)
-*/
-
-static inline int s3c24xx_serial_resetport(struct uart_port * port,
-                                          struct s3c2410_uartcfg *cfg)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-
-       return (info->reset_port)(port, cfg);
-}
-
-/* s3c24xx_serial_init_port
- *
- * initialise a single serial port from the platform device given
- */
-
-static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
-                                   struct s3c24xx_uart_info *info,
-                                   struct platform_device *platdev)
-{
-       struct uart_port *port = &ourport->port;
-       struct s3c2410_uartcfg *cfg;
-       struct resource *res;
-       int ret;
-
-       dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
-
-       if (platdev == NULL)
-               return -ENODEV;
-
-       cfg = s3c24xx_dev_to_cfg(&platdev->dev);
-
-       if (port->mapbase != 0)
-               return 0;
-
-       if (cfg->hwport > 3)
-               return -EINVAL;
-
-       /* setup info for port */
-       port->dev       = &platdev->dev;
-       ourport->info   = info;
-
-       /* copy the info in from provided structure */
-       ourport->port.fifosize = info->fifosize;
-
-       dbg("s3c24xx_serial_init_port: %p (hw %d)...\n", port, cfg->hwport);
-
-       port->uartclk = 1;
-
-       if (cfg->uart_flags & UPF_CONS_FLOW) {
-               dbg("s3c24xx_serial_init_port: enabling flow control\n");
-               port->flags |= UPF_CONS_FLOW;
-       }
-
-       /* sort our the physical and virtual addresses for each UART */
-
-       res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
-       if (res == NULL) {
-               printk(KERN_ERR "failed to find memory resource for uart\n");
-               return -EINVAL;
-       }
-
-       dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
-
-       port->mapbase   = res->start;
-       port->membase   = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART);
-       ret = platform_get_irq(platdev, 0);
-       if (ret < 0)
-               port->irq = 0;
-       else
-               port->irq = ret;
-
-       ourport->clk    = clk_get(&platdev->dev, "uart");
-
-       dbg("port: map=%08x, mem=%08x, irq=%d, clock=%ld\n",
-           port->mapbase, port->membase, port->irq, port->uartclk);
-
-       /* reset the fifos (and setup the uart) */
-       s3c24xx_serial_resetport(port, cfg);
-       return 0;
-}
-
-/* Device driver serial port probe */
-
-static int probe_index = 0;
-
-static int s3c24xx_serial_probe(struct platform_device *dev,
-                               struct s3c24xx_uart_info *info)
-{
-       struct s3c24xx_uart_port *ourport;
-       int ret;
-
-       dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
-
-       ourport = &s3c24xx_serial_ports[probe_index];
-       probe_index++;
-
-       dbg("%s: initialising port %p...\n", __func__, ourport);
-
-       ret = s3c24xx_serial_init_port(ourport, info, dev);
-       if (ret < 0)
-               goto probe_err;
-
-       dbg("%s: adding port\n", __func__);
-       uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
-       platform_set_drvdata(dev, &ourport->port);
-
-       return 0;
-
- probe_err:
-       return ret;
-}
-
-static int s3c24xx_serial_remove(struct platform_device *dev)
-{
-       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
-
-       if (port)
-               uart_remove_one_port(&s3c24xx_uart_drv, port);
-
-       return 0;
-}
-
-/* UART power management code */
-
-#ifdef CONFIG_PM
-
-static int s3c24xx_serial_suspend(struct platform_device *dev, pm_message_t state)
-{
-       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
-
-       if (port)
-               uart_suspend_port(&s3c24xx_uart_drv, port);
-
-       return 0;
-}
-
-static int s3c24xx_serial_resume(struct platform_device *dev)
-{
-       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
-       struct s3c24xx_uart_port *ourport = to_ourport(port);
-
-       if (port) {
-               clk_enable(ourport->clk);
-               s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
-               clk_disable(ourport->clk);
-
-               uart_resume_port(&s3c24xx_uart_drv, port);
-       }
-
-       return 0;
-}
-
-#else
-#define s3c24xx_serial_suspend NULL
-#define s3c24xx_serial_resume  NULL
-#endif
-
-static int s3c24xx_serial_init(struct platform_driver *drv,
-                              struct s3c24xx_uart_info *info)
-{
-       dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
-       return platform_driver_register(drv);
-}
-
-
-/* now comes the code to initialise either the s3c2410 or s3c2440 serial
- * port information
-*/
-
-/* cpu specific variations on the serial port support */
-
-#ifdef CONFIG_CPU_S3C2400
-
-static int s3c2400_serial_getsource(struct uart_port *port,
-                                   struct s3c24xx_uart_clksrc *clk)
-{
-       clk->divisor = 1;
-       clk->name = "pclk";
-
-       return 0;
-}
-
-static int s3c2400_serial_setsource(struct uart_port *port,
-                                   struct s3c24xx_uart_clksrc *clk)
-{
-       return 0;
-}
-
-static int s3c2400_serial_resetport(struct uart_port *port,
-                                   struct s3c2410_uartcfg *cfg)
-{
-       dbg("s3c2400_serial_resetport: port=%p (%08lx), cfg=%p\n",
-           port, port->mapbase, cfg);
-
-       wr_regl(port, S3C2410_UCON,  cfg->ucon);
-       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
-
-       /* reset both fifos */
-
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
-
-       return 0;
-}
-
-static struct s3c24xx_uart_info s3c2400_uart_inf = {
-       .name           = "Samsung S3C2400 UART",
-       .type           = PORT_S3C2400,
-       .fifosize       = 16,
-       .rx_fifomask    = S3C2410_UFSTAT_RXMASK,
-       .rx_fifoshift   = S3C2410_UFSTAT_RXSHIFT,
-       .rx_fifofull    = S3C2410_UFSTAT_RXFULL,
-       .tx_fifofull    = S3C2410_UFSTAT_TXFULL,
-       .tx_fifomask    = S3C2410_UFSTAT_TXMASK,
-       .tx_fifoshift   = S3C2410_UFSTAT_TXSHIFT,
-       .get_clksrc     = s3c2400_serial_getsource,
-       .set_clksrc     = s3c2400_serial_setsource,
-       .reset_port     = s3c2400_serial_resetport,
-};
-
-static int s3c2400_serial_probe(struct platform_device *dev)
-{
-       return s3c24xx_serial_probe(dev, &s3c2400_uart_inf);
-}
-
-static struct platform_driver s3c2400_serial_drv = {
-       .probe          = s3c2400_serial_probe,
-       .remove         = s3c24xx_serial_remove,
-       .suspend        = s3c24xx_serial_suspend,
-       .resume         = s3c24xx_serial_resume,
-       .driver         = {
-               .name   = "s3c2400-uart",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static inline int s3c2400_serial_init(void)
-{
-       return s3c24xx_serial_init(&s3c2400_serial_drv, &s3c2400_uart_inf);
-}
-
-static inline void s3c2400_serial_exit(void)
-{
-       platform_driver_unregister(&s3c2400_serial_drv);
-}
-
-#define s3c2400_uart_inf_at &s3c2400_uart_inf
-#else
-
-static inline int s3c2400_serial_init(void)
-{
-       return 0;
-}
-
-static inline void s3c2400_serial_exit(void)
-{
-}
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
 
-#define s3c2400_uart_inf_at NULL
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+#include <linux/serial.h>
 
-#endif /* CONFIG_CPU_S3C2400 */
+#include <asm/irq.h>
+#include <asm/hardware.h>
 
-/* S3C2410 support */
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
 
-#ifdef CONFIG_CPU_S3C2410
+#include "samsung.h"
 
 static int s3c2410_serial_setsource(struct uart_port *port,
                                    struct s3c24xx_uart_clksrc *clk)
@@ -1323,8 +83,6 @@ static struct s3c24xx_uart_info s3c2410_uart_inf = {
        .reset_port     = s3c2410_serial_resetport,
 };
 
-/* device management */
-
 static int s3c2410_serial_probe(struct platform_device *dev)
 {
        return s3c24xx_serial_probe(dev, &s3c2410_uart_inf);
@@ -1333,612 +91,28 @@ static int s3c2410_serial_probe(struct platform_device *dev)
 static struct platform_driver s3c2410_serial_drv = {
        .probe          = s3c2410_serial_probe,
        .remove         = s3c24xx_serial_remove,
-       .suspend        = s3c24xx_serial_suspend,
-       .resume         = s3c24xx_serial_resume,
        .driver         = {
                .name   = "s3c2410-uart",
                .owner  = THIS_MODULE,
        },
 };
 
-static inline int s3c2410_serial_init(void)
+s3c24xx_console_init(&s3c2410_serial_drv, &s3c2410_uart_inf);
+
+static int __init s3c2410_serial_init(void)
 {
        return s3c24xx_serial_init(&s3c2410_serial_drv, &s3c2410_uart_inf);
 }
 
-static inline void s3c2410_serial_exit(void)
+static void __exit s3c2410_serial_exit(void)
 {
        platform_driver_unregister(&s3c2410_serial_drv);
 }
 
-#define s3c2410_uart_inf_at &s3c2410_uart_inf
-#else
-
-static inline int s3c2410_serial_init(void)
-{
-       return 0;
-}
-
-static inline void s3c2410_serial_exit(void)
-{
-}
-
-#define s3c2410_uart_inf_at NULL
-
-#endif /* CONFIG_CPU_S3C2410 */
-
-#if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2442)
-
-static int s3c2440_serial_setsource(struct uart_port *port,
-                                    struct s3c24xx_uart_clksrc *clk)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-
-       // todo - proper fclk<>nonfclk switch //
-
-       ucon &= ~S3C2440_UCON_CLKMASK;
-
-       if (strcmp(clk->name, "uclk") == 0)
-               ucon |= S3C2440_UCON_UCLK;
-       else if (strcmp(clk->name, "pclk") == 0)
-               ucon |= S3C2440_UCON_PCLK;
-       else if (strcmp(clk->name, "fclk") == 0)
-               ucon |= S3C2440_UCON_FCLK;
-       else {
-               printk(KERN_ERR "unknown clock source %s\n", clk->name);
-               return -EINVAL;
-       }
-
-       wr_regl(port, S3C2410_UCON, ucon);
-       return 0;
-}
-
-
-static int s3c2440_serial_getsource(struct uart_port *port,
-                                   struct s3c24xx_uart_clksrc *clk)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-       unsigned long ucon0, ucon1, ucon2;
-
-       switch (ucon & S3C2440_UCON_CLKMASK) {
-       case S3C2440_UCON_UCLK:
-               clk->divisor = 1;
-               clk->name = "uclk";
-               break;
-
-       case S3C2440_UCON_PCLK:
-       case S3C2440_UCON_PCLK2:
-               clk->divisor = 1;
-               clk->name = "pclk";
-               break;
-
-       case S3C2440_UCON_FCLK:
-               /* the fun of calculating the uart divisors on
-                * the s3c2440 */
-
-               ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
-               ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
-               ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
-
-               printk("ucons: %08lx, %08lx, %08lx\n", ucon0, ucon1, ucon2);
-
-               ucon0 &= S3C2440_UCON0_DIVMASK;
-               ucon1 &= S3C2440_UCON1_DIVMASK;
-               ucon2 &= S3C2440_UCON2_DIVMASK;
-
-               if (ucon0 != 0) {
-                       clk->divisor = ucon0 >> S3C2440_UCON_DIVSHIFT;
-                       clk->divisor += 6;
-               } else if (ucon1 != 0) {
-                       clk->divisor = ucon1 >> S3C2440_UCON_DIVSHIFT;
-                       clk->divisor += 21;
-               } else if (ucon2 != 0) {
-                       clk->divisor = ucon2 >> S3C2440_UCON_DIVSHIFT;
-                       clk->divisor += 36;
-               } else {
-                       /* manual calims 44, seems to be 9 */
-                       clk->divisor = 9;
-               }
-
-               clk->name = "fclk";
-               break;
-       }
-
-       return 0;
-}
-
-static int s3c2440_serial_resetport(struct uart_port *port,
-                                   struct s3c2410_uartcfg *cfg)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-
-       dbg("s3c2440_serial_resetport: port=%p (%08lx), cfg=%p\n",
-           port, port->mapbase, cfg);
-
-       /* ensure we don't change the clock settings... */
-
-       ucon &= (S3C2440_UCON0_DIVMASK | (3<<10));
-
-       wr_regl(port, S3C2410_UCON,  ucon | cfg->ucon);
-       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
-
-       /* reset both fifos */
-
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
-
-       return 0;
-}
-
-static struct s3c24xx_uart_info s3c2440_uart_inf = {
-       .name           = "Samsung S3C2440 UART",
-       .type           = PORT_S3C2440,
-       .fifosize       = 64,
-       .rx_fifomask    = S3C2440_UFSTAT_RXMASK,
-       .rx_fifoshift   = S3C2440_UFSTAT_RXSHIFT,
-       .rx_fifofull    = S3C2440_UFSTAT_RXFULL,
-       .tx_fifofull    = S3C2440_UFSTAT_TXFULL,
-       .tx_fifomask    = S3C2440_UFSTAT_TXMASK,
-       .tx_fifoshift   = S3C2440_UFSTAT_TXSHIFT,
-       .get_clksrc     = s3c2440_serial_getsource,
-       .set_clksrc     = s3c2440_serial_setsource,
-       .reset_port     = s3c2440_serial_resetport,
-};
-
-/* device management */
-
-static int s3c2440_serial_probe(struct platform_device *dev)
-{
-       dbg("s3c2440_serial_probe: dev=%p\n", dev);
-       return s3c24xx_serial_probe(dev, &s3c2440_uart_inf);
-}
-
-static struct platform_driver s3c2440_serial_drv = {
-       .probe          = s3c2440_serial_probe,
-       .remove         = s3c24xx_serial_remove,
-       .suspend        = s3c24xx_serial_suspend,
-       .resume         = s3c24xx_serial_resume,
-       .driver         = {
-               .name   = "s3c2440-uart",
-               .owner  = THIS_MODULE,
-       },
-};
-
-
-static inline int s3c2440_serial_init(void)
-{
-       return s3c24xx_serial_init(&s3c2440_serial_drv, &s3c2440_uart_inf);
-}
-
-static inline void s3c2440_serial_exit(void)
-{
-       platform_driver_unregister(&s3c2440_serial_drv);
-}
-
-#define s3c2440_uart_inf_at &s3c2440_uart_inf
-#else
-
-static inline int s3c2440_serial_init(void)
-{
-       return 0;
-}
-
-static inline void s3c2440_serial_exit(void)
-{
-}
-
-#define s3c2440_uart_inf_at NULL
-#endif /* CONFIG_CPU_S3C2440 */
-
-#if defined(CONFIG_CPU_S3C2412)
-
-static int s3c2412_serial_setsource(struct uart_port *port,
-                                    struct s3c24xx_uart_clksrc *clk)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-
-       ucon &= ~S3C2412_UCON_CLKMASK;
-
-       if (strcmp(clk->name, "uclk") == 0)
-               ucon |= S3C2440_UCON_UCLK;
-       else if (strcmp(clk->name, "pclk") == 0)
-               ucon |= S3C2440_UCON_PCLK;
-       else if (strcmp(clk->name, "usysclk") == 0)
-               ucon |= S3C2412_UCON_USYSCLK;
-       else {
-               printk(KERN_ERR "unknown clock source %s\n", clk->name);
-               return -EINVAL;
-       }
-
-       wr_regl(port, S3C2410_UCON, ucon);
-       return 0;
-}
-
-
-static int s3c2412_serial_getsource(struct uart_port *port,
-                                   struct s3c24xx_uart_clksrc *clk)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-
-       switch (ucon & S3C2412_UCON_CLKMASK) {
-       case S3C2412_UCON_UCLK:
-               clk->divisor = 1;
-               clk->name = "uclk";
-               break;
-
-       case S3C2412_UCON_PCLK:
-       case S3C2412_UCON_PCLK2:
-               clk->divisor = 1;
-               clk->name = "pclk";
-               break;
-
-       case S3C2412_UCON_USYSCLK:
-               clk->divisor = 1;
-               clk->name = "usysclk";
-               break;
-       }
-
-       return 0;
-}
-
-static int s3c2412_serial_resetport(struct uart_port *port,
-                                   struct s3c2410_uartcfg *cfg)
-{
-       unsigned long ucon = rd_regl(port, S3C2410_UCON);
-
-       dbg("%s: port=%p (%08lx), cfg=%p\n",
-           __func__, port, port->mapbase, cfg);
-
-       /* ensure we don't change the clock settings... */
-
-       ucon &= S3C2412_UCON_CLKMASK;
-
-       wr_regl(port, S3C2410_UCON,  ucon | cfg->ucon);
-       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
-
-       /* reset both fifos */
-
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
-       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
-
-       return 0;
-}
-
-static struct s3c24xx_uart_info s3c2412_uart_inf = {
-       .name           = "Samsung S3C2412 UART",
-       .type           = PORT_S3C2412,
-       .fifosize       = 64,
-       .rx_fifomask    = S3C2440_UFSTAT_RXMASK,
-       .rx_fifoshift   = S3C2440_UFSTAT_RXSHIFT,
-       .rx_fifofull    = S3C2440_UFSTAT_RXFULL,
-       .tx_fifofull    = S3C2440_UFSTAT_TXFULL,
-       .tx_fifomask    = S3C2440_UFSTAT_TXMASK,
-       .tx_fifoshift   = S3C2440_UFSTAT_TXSHIFT,
-       .get_clksrc     = s3c2412_serial_getsource,
-       .set_clksrc     = s3c2412_serial_setsource,
-       .reset_port     = s3c2412_serial_resetport,
-};
-
-/* device management */
-
-static int s3c2412_serial_probe(struct platform_device *dev)
-{
-       dbg("s3c2440_serial_probe: dev=%p\n", dev);
-       return s3c24xx_serial_probe(dev, &s3c2412_uart_inf);
-}
-
-static struct platform_driver s3c2412_serial_drv = {
-       .probe          = s3c2412_serial_probe,
-       .remove         = s3c24xx_serial_remove,
-       .suspend        = s3c24xx_serial_suspend,
-       .resume         = s3c24xx_serial_resume,
-       .driver         = {
-               .name   = "s3c2412-uart",
-               .owner  = THIS_MODULE,
-       },
-};
-
-
-static inline int s3c2412_serial_init(void)
-{
-       return s3c24xx_serial_init(&s3c2412_serial_drv, &s3c2412_uart_inf);
-}
-
-static inline void s3c2412_serial_exit(void)
-{
-       platform_driver_unregister(&s3c2412_serial_drv);
-}
-
-#define s3c2412_uart_inf_at &s3c2412_uart_inf
-#else
-
-static inline int s3c2412_serial_init(void)
-{
-       return 0;
-}
-
-static inline void s3c2412_serial_exit(void)
-{
-}
-
-#define s3c2412_uart_inf_at NULL
-#endif /* CONFIG_CPU_S3C2440 */
-
-
-/* module initialisation code */
-
-static int __init s3c24xx_serial_modinit(void)
-{
-       int ret;
-
-       ret = uart_register_driver(&s3c24xx_uart_drv);
-       if (ret < 0) {
-               printk(KERN_ERR "failed to register UART driver\n");
-               return -1;
-       }
-
-       s3c2400_serial_init();
-       s3c2410_serial_init();
-       s3c2412_serial_init();
-       s3c2440_serial_init();
-
-       return 0;
-}
-
-static void __exit s3c24xx_serial_modexit(void)
-{
-       s3c2400_serial_exit();
-       s3c2410_serial_exit();
-       s3c2412_serial_exit();
-       s3c2440_serial_exit();
-
-       uart_unregister_driver(&s3c24xx_uart_drv);
-}
-
-
-module_init(s3c24xx_serial_modinit);
-module_exit(s3c24xx_serial_modexit);
-
-/* Console code */
-
-#ifdef CONFIG_SERIAL_S3C2410_CONSOLE
-
-static struct uart_port *cons_uart;
-
-static int
-s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
-{
-       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
-       unsigned long ufstat, utrstat;
-
-       if (ufcon & S3C2410_UFCON_FIFOMODE) {
-               /* fifo mode - check ammount of data in fifo registers... */
-
-               ufstat = rd_regl(port, S3C2410_UFSTAT);
-               return (ufstat & info->tx_fifofull) ? 0 : 1;
-       }
-
-       /* in non-fifo mode, we go and use the tx buffer empty */
-
-       utrstat = rd_regl(port, S3C2410_UTRSTAT);
-       return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
-}
-
-static void
-s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
-{
-       unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
-       while (!s3c24xx_serial_console_txrdy(port, ufcon))
-               barrier();
-       wr_regb(cons_uart, S3C2410_UTXH, ch);
-}
-
-static void
-s3c24xx_serial_console_write(struct console *co, const char *s,
-                            unsigned int count)
-{
-       uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
-}
-
-static void __init
-s3c24xx_serial_get_options(struct uart_port *port, int *baud,
-                          int *parity, int *bits)
-{
-       struct s3c24xx_uart_clksrc clksrc;
-       struct clk *clk;
-       unsigned int ulcon;
-       unsigned int ucon;
-       unsigned int ubrdiv;
-       unsigned long rate;
-
-       ulcon  = rd_regl(port, S3C2410_ULCON);
-       ucon   = rd_regl(port, S3C2410_UCON);
-       ubrdiv = rd_regl(port, S3C2410_UBRDIV);
-
-       dbg("s3c24xx_serial_get_options: port=%p\n"
-           "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
-           port, ulcon, ucon, ubrdiv);
-
-       if ((ucon & 0xf) != 0) {
-               /* consider the serial port configured if the tx/rx mode set */
-
-               switch (ulcon & S3C2410_LCON_CSMASK) {
-               case S3C2410_LCON_CS5:
-                       *bits = 5;
-                       break;
-               case S3C2410_LCON_CS6:
-                       *bits = 6;
-                       break;
-               case S3C2410_LCON_CS7:
-                       *bits = 7;
-                       break;
-               default:
-               case S3C2410_LCON_CS8:
-                       *bits = 8;
-                       break;
-               }
-
-               switch (ulcon & S3C2410_LCON_PMASK) {
-               case S3C2410_LCON_PEVEN:
-                       *parity = 'e';
-                       break;
-
-               case S3C2410_LCON_PODD:
-                       *parity = 'o';
-                       break;
-
-               case S3C2410_LCON_PNONE:
-               default:
-                       *parity = 'n';
-               }
-
-               /* now calculate the baud rate */
-
-               s3c24xx_serial_getsource(port, &clksrc);
-
-               clk = clk_get(port->dev, clksrc.name);
-               if (!IS_ERR(clk) && clk != NULL)
-                       rate = clk_get_rate(clk) / clksrc.divisor;
-               else
-                       rate = 1;
-
-
-               *baud = rate / ( 16 * (ubrdiv + 1));
-               dbg("calculated baud %d\n", *baud);
-       }
-
-}
-
-/* s3c24xx_serial_init_ports
- *
- * initialise the serial ports from the machine provided initialisation
- * data.
-*/
-
-static int s3c24xx_serial_init_ports(struct s3c24xx_uart_info *info)
-{
-       struct s3c24xx_uart_port *ptr = s3c24xx_serial_ports;
-       struct platform_device **platdev_ptr;
-       int i;
-
-       dbg("s3c24xx_serial_init_ports: initialising ports...\n");
-
-       platdev_ptr = s3c24xx_uart_devs;
-
-       for (i = 0; i < NR_PORTS; i++, ptr++, platdev_ptr++) {
-               s3c24xx_serial_init_port(ptr, info, *platdev_ptr);
-       }
-
-       return 0;
-}
-
-static int __init
-s3c24xx_serial_console_setup(struct console *co, char *options)
-{
-       struct uart_port *port;
-       int baud = 9600;
-       int bits = 8;
-       int parity = 'n';
-       int flow = 'n';
-
-       dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
-           co, co->index, options);
-
-       /* is this a valid port */
-
-       if (co->index == -1 || co->index >= NR_PORTS)
-               co->index = 0;
-
-       port = &s3c24xx_serial_ports[co->index].port;
-
-       /* is the port configured? */
-
-       if (port->mapbase == 0x0) {
-               co->index = 0;
-               port = &s3c24xx_serial_ports[co->index].port;
-       }
-
-       cons_uart = port;
-
-       dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
-
-       /*
-        * Check whether an invalid uart number has been specified, and
-        * if so, search for the first available port that does have
-        * console support.
-        */
-       if (options)
-               uart_parse_options(options, &baud, &parity, &bits, &flow);
-       else
-               s3c24xx_serial_get_options(port, &baud, &parity, &bits);
-
-       dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
-
-       return uart_set_options(port, co, baud, parity, bits, flow);
-}
-
-/* s3c24xx_serial_initconsole
- *
- * initialise the console from one of the uart drivers
-*/
-
-static struct console s3c24xx_serial_console =
-{
-       .name           = S3C24XX_SERIAL_NAME,
-       .device         = uart_console_device,
-       .flags          = CON_PRINTBUFFER,
-       .index          = -1,
-       .write          = s3c24xx_serial_console_write,
-       .setup          = s3c24xx_serial_console_setup
-};
-
-static int s3c24xx_serial_initconsole(void)
-{
-       struct s3c24xx_uart_info *info;
-       struct platform_device *dev = s3c24xx_uart_devs[0];
-
-       dbg("s3c24xx_serial_initconsole\n");
-
-       /* select driver based on the cpu */
-
-       if (dev == NULL) {
-               printk(KERN_ERR "s3c24xx: no devices for console init\n");
-               return 0;
-       }
-
-       if (strcmp(dev->name, "s3c2400-uart") == 0) {
-               info = s3c2400_uart_inf_at;
-       } else if (strcmp(dev->name, "s3c2410-uart") == 0) {
-               info = s3c2410_uart_inf_at;
-       } else if (strcmp(dev->name, "s3c2440-uart") == 0) {
-               info = s3c2440_uart_inf_at;
-       } else if (strcmp(dev->name, "s3c2412-uart") == 0) {
-               info = s3c2412_uart_inf_at;
-       } else {
-               printk(KERN_ERR "s3c24xx: no driver for %s\n", dev->name);
-               return 0;
-       }
-
-       if (info == NULL) {
-               printk(KERN_ERR "s3c24xx: no driver for console\n");
-               return 0;
-       }
-
-       s3c24xx_serial_console.data = &s3c24xx_uart_drv;
-       s3c24xx_serial_init_ports(info);
-
-       register_console(&s3c24xx_serial_console);
-       return 0;
-}
-
-console_initcall(s3c24xx_serial_initconsole);
-
-#endif /* CONFIG_SERIAL_S3C2410_CONSOLE */
+module_init(s3c2410_serial_init);
+module_exit(s3c2410_serial_exit);
 
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
-MODULE_DESCRIPTION("Samsung S3C2410/S3C2440/S3C2412 Serial port driver");
-MODULE_ALIAS("platform:s3c2400-uart");
+MODULE_DESCRIPTION("Samsung S3C2410 SoC Serial port driver");
 MODULE_ALIAS("platform:s3c2410-uart");
-MODULE_ALIAS("platform:s3c2412-uart");
-MODULE_ALIAS("platform:s3c2440-uart");
diff --git a/drivers/serial/s3c2412.c b/drivers/serial/s3c2412.c
new file mode 100644 (file)
index 0000000..ce0c220
--- /dev/null
@@ -0,0 +1,151 @@
+/* linux/drivers/serial/s3c2412.c
+ *
+ * Driver for Samsung S3C2412 and S3C2413 SoC onboard UARTs.
+ *
+ * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+#include <linux/serial.h>
+
+#include <asm/irq.h>
+#include <asm/hardware.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
+
+#include "samsung.h"
+
+static int s3c2412_serial_setsource(struct uart_port *port,
+                                    struct s3c24xx_uart_clksrc *clk)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+
+       ucon &= ~S3C2412_UCON_CLKMASK;
+
+       if (strcmp(clk->name, "uclk") == 0)
+               ucon |= S3C2440_UCON_UCLK;
+       else if (strcmp(clk->name, "pclk") == 0)
+               ucon |= S3C2440_UCON_PCLK;
+       else if (strcmp(clk->name, "usysclk") == 0)
+               ucon |= S3C2412_UCON_USYSCLK;
+       else {
+               printk(KERN_ERR "unknown clock source %s\n", clk->name);
+               return -EINVAL;
+       }
+
+       wr_regl(port, S3C2410_UCON, ucon);
+       return 0;
+}
+
+
+static int s3c2412_serial_getsource(struct uart_port *port,
+                                   struct s3c24xx_uart_clksrc *clk)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+
+       switch (ucon & S3C2412_UCON_CLKMASK) {
+       case S3C2412_UCON_UCLK:
+               clk->divisor = 1;
+               clk->name = "uclk";
+               break;
+
+       case S3C2412_UCON_PCLK:
+       case S3C2412_UCON_PCLK2:
+               clk->divisor = 1;
+               clk->name = "pclk";
+               break;
+
+       case S3C2412_UCON_USYSCLK:
+               clk->divisor = 1;
+               clk->name = "usysclk";
+               break;
+       }
+
+       return 0;
+}
+
+static int s3c2412_serial_resetport(struct uart_port *port,
+                                   struct s3c2410_uartcfg *cfg)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+
+       dbg("%s: port=%p (%08lx), cfg=%p\n",
+           __func__, port, port->mapbase, cfg);
+
+       /* ensure we don't change the clock settings... */
+
+       ucon &= S3C2412_UCON_CLKMASK;
+
+       wr_regl(port, S3C2410_UCON,  ucon | cfg->ucon);
+       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
+
+       /* reset both fifos */
+
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
+
+       return 0;
+}
+
+static struct s3c24xx_uart_info s3c2412_uart_inf = {
+       .name           = "Samsung S3C2412 UART",
+       .type           = PORT_S3C2412,
+       .fifosize       = 64,
+       .rx_fifomask    = S3C2440_UFSTAT_RXMASK,
+       .rx_fifoshift   = S3C2440_UFSTAT_RXSHIFT,
+       .rx_fifofull    = S3C2440_UFSTAT_RXFULL,
+       .tx_fifofull    = S3C2440_UFSTAT_TXFULL,
+       .tx_fifomask    = S3C2440_UFSTAT_TXMASK,
+       .tx_fifoshift   = S3C2440_UFSTAT_TXSHIFT,
+       .get_clksrc     = s3c2412_serial_getsource,
+       .set_clksrc     = s3c2412_serial_setsource,
+       .reset_port     = s3c2412_serial_resetport,
+};
+
+/* device management */
+
+static int s3c2412_serial_probe(struct platform_device *dev)
+{
+       dbg("s3c2440_serial_probe: dev=%p\n", dev);
+       return s3c24xx_serial_probe(dev, &s3c2412_uart_inf);
+}
+
+static struct platform_driver s3c2412_serial_drv = {
+       .probe          = s3c2412_serial_probe,
+       .remove         = s3c24xx_serial_remove,
+       .driver         = {
+               .name   = "s3c2412-uart",
+               .owner  = THIS_MODULE,
+       },
+};
+
+s3c24xx_console_init(&s3c2412_serial_drv, &s3c2412_uart_inf);
+
+static inline int s3c2412_serial_init(void)
+{
+       return s3c24xx_serial_init(&s3c2412_serial_drv, &s3c2412_uart_inf);
+}
+
+static inline void s3c2412_serial_exit(void)
+{
+       platform_driver_unregister(&s3c2412_serial_drv);
+}
+
+module_init(s3c2412_serial_init);
+module_exit(s3c2412_serial_exit);
+
+MODULE_DESCRIPTION("Samsung S3C2412,S3C2413 SoC Serial port driver");
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:s3c2412-uart");
diff --git a/drivers/serial/s3c2440.c b/drivers/serial/s3c2440.c
new file mode 100644 (file)
index 0000000..38f954b
--- /dev/null
@@ -0,0 +1,181 @@
+/* linux/drivers/serial/s3c2440.c
+ *
+ * Driver for Samsung S3C2440 and S3C2442 SoC onboard UARTs.
+ *
+ * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+#include <linux/serial.h>
+
+#include <asm/irq.h>
+#include <asm/hardware.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
+
+#include "samsung.h"
+
+
+static int s3c2440_serial_setsource(struct uart_port *port,
+                                    struct s3c24xx_uart_clksrc *clk)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+
+       /* todo - proper fclk<>nonfclk switch. */
+
+       ucon &= ~S3C2440_UCON_CLKMASK;
+
+       if (strcmp(clk->name, "uclk") == 0)
+               ucon |= S3C2440_UCON_UCLK;
+       else if (strcmp(clk->name, "pclk") == 0)
+               ucon |= S3C2440_UCON_PCLK;
+       else if (strcmp(clk->name, "fclk") == 0)
+               ucon |= S3C2440_UCON_FCLK;
+       else {
+               printk(KERN_ERR "unknown clock source %s\n", clk->name);
+               return -EINVAL;
+       }
+
+       wr_regl(port, S3C2410_UCON, ucon);
+       return 0;
+}
+
+
+static int s3c2440_serial_getsource(struct uart_port *port,
+                                   struct s3c24xx_uart_clksrc *clk)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+       unsigned long ucon0, ucon1, ucon2;
+
+       switch (ucon & S3C2440_UCON_CLKMASK) {
+       case S3C2440_UCON_UCLK:
+               clk->divisor = 1;
+               clk->name = "uclk";
+               break;
+
+       case S3C2440_UCON_PCLK:
+       case S3C2440_UCON_PCLK2:
+               clk->divisor = 1;
+               clk->name = "pclk";
+               break;
+
+       case S3C2440_UCON_FCLK:
+               /* the fun of calculating the uart divisors on
+                * the s3c2440 */
+
+               ucon0 = __raw_readl(S3C24XX_VA_UART0 + S3C2410_UCON);
+               ucon1 = __raw_readl(S3C24XX_VA_UART1 + S3C2410_UCON);
+               ucon2 = __raw_readl(S3C24XX_VA_UART2 + S3C2410_UCON);
+
+               printk("ucons: %08lx, %08lx, %08lx\n", ucon0, ucon1, ucon2);
+
+               ucon0 &= S3C2440_UCON0_DIVMASK;
+               ucon1 &= S3C2440_UCON1_DIVMASK;
+               ucon2 &= S3C2440_UCON2_DIVMASK;
+
+               if (ucon0 != 0) {
+                       clk->divisor = ucon0 >> S3C2440_UCON_DIVSHIFT;
+                       clk->divisor += 6;
+               } else if (ucon1 != 0) {
+                       clk->divisor = ucon1 >> S3C2440_UCON_DIVSHIFT;
+                       clk->divisor += 21;
+               } else if (ucon2 != 0) {
+                       clk->divisor = ucon2 >> S3C2440_UCON_DIVSHIFT;
+                       clk->divisor += 36;
+               } else {
+                       /* manual calims 44, seems to be 9 */
+                       clk->divisor = 9;
+               }
+
+               clk->name = "fclk";
+               break;
+       }
+
+       return 0;
+}
+
+static int s3c2440_serial_resetport(struct uart_port *port,
+                                   struct s3c2410_uartcfg *cfg)
+{
+       unsigned long ucon = rd_regl(port, S3C2410_UCON);
+
+       dbg("s3c2440_serial_resetport: port=%p (%08lx), cfg=%p\n",
+           port, port->mapbase, cfg);
+
+       /* ensure we don't change the clock settings... */
+
+       ucon &= (S3C2440_UCON0_DIVMASK | (3<<10));
+
+       wr_regl(port, S3C2410_UCON,  ucon | cfg->ucon);
+       wr_regl(port, S3C2410_ULCON, cfg->ulcon);
+
+       /* reset both fifos */
+
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
+       wr_regl(port, S3C2410_UFCON, cfg->ufcon);
+
+       return 0;
+}
+
+static struct s3c24xx_uart_info s3c2440_uart_inf = {
+       .name           = "Samsung S3C2440 UART",
+       .type           = PORT_S3C2440,
+       .fifosize       = 64,
+       .rx_fifomask    = S3C2440_UFSTAT_RXMASK,
+       .rx_fifoshift   = S3C2440_UFSTAT_RXSHIFT,
+       .rx_fifofull    = S3C2440_UFSTAT_RXFULL,
+       .tx_fifofull    = S3C2440_UFSTAT_TXFULL,
+       .tx_fifomask    = S3C2440_UFSTAT_TXMASK,
+       .tx_fifoshift   = S3C2440_UFSTAT_TXSHIFT,
+       .get_clksrc     = s3c2440_serial_getsource,
+       .set_clksrc     = s3c2440_serial_setsource,
+       .reset_port     = s3c2440_serial_resetport,
+};
+
+/* device management */
+
+static int s3c2440_serial_probe(struct platform_device *dev)
+{
+       dbg("s3c2440_serial_probe: dev=%p\n", dev);
+       return s3c24xx_serial_probe(dev, &s3c2440_uart_inf);
+}
+
+static struct platform_driver s3c2440_serial_drv = {
+       .probe          = s3c2440_serial_probe,
+       .remove         = s3c24xx_serial_remove,
+       .driver         = {
+               .name   = "s3c2440-uart",
+               .owner  = THIS_MODULE,
+       },
+};
+
+s3c24xx_console_init(&s3c2440_serial_drv, &s3c2440_uart_inf);
+
+static int __init s3c2440_serial_init(void)
+{
+       return s3c24xx_serial_init(&s3c2440_serial_drv, &s3c2440_uart_inf);
+}
+
+static void __exit s3c2440_serial_exit(void)
+{
+       platform_driver_unregister(&s3c2440_serial_drv);
+}
+
+module_init(s3c2440_serial_init);
+module_exit(s3c2440_serial_exit);
+
+MODULE_DESCRIPTION("Samsung S3C2440,S3C2442 SoC Serial port driver");
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
+MODULE_LICENSE("GPLi v2");
+MODULE_ALIAS("platform:s3c2440-uart");
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
new file mode 100644 (file)
index 0000000..4a3ecaa
--- /dev/null
@@ -0,0 +1,1317 @@
+/* linux/drivers/serial/samsuing.c
+ *
+ * Driver core for Samsung SoC onboard UARTs.
+ *
+ * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+/* Hote on 2410 error handling
+ *
+ * The s3c2410 manual has a love/hate affair with the contents of the
+ * UERSTAT register in the UART blocks, and keeps marking some of the
+ * error bits as reserved. Having checked with the s3c2410x01,
+ * it copes with BREAKs properly, so I am happy to ignore the RESERVED
+ * feature from the latter versions of the manual.
+ *
+ * If it becomes aparrent that latter versions of the 2410 remove these
+ * bits, then action will have to be taken to differentiate the versions
+ * and change the policy on BREAK
+ *
+ * BJD, 04-Nov-2004
+*/
+
+#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/sysrq.h>
+#include <linux/console.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/serial_core.h>
+#include <linux/serial.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+
+#include <asm/irq.h>
+
+#include <asm/hardware.h>
+
+#include <asm/plat-s3c/regs-serial.h>
+#include <asm/arch/regs-gpio.h>
+
+#include "samsung.h"
+
+/* UART name and device definitions */
+
+#define S3C24XX_SERIAL_NAME    "ttySAC"
+#define S3C24XX_SERIAL_MAJOR   204
+#define S3C24XX_SERIAL_MINOR   64
+
+/* we can support 3 uarts, but not always use them */
+
+#ifdef CONFIG_CPU_S3C2400
+#define NR_PORTS (2)
+#else
+#define NR_PORTS (3)
+#endif
+
+/* port irq numbers */
+
+#define TX_IRQ(port) ((port)->irq + 1)
+#define RX_IRQ(port) ((port)->irq)
+
+/* macros to change one thing to another */
+
+#define tx_enabled(port) ((port)->unused[0])
+#define rx_enabled(port) ((port)->unused[1])
+
+/* flag to ignore all characters comming in */
+#define RXSTAT_DUMMY_READ (0x10000000)
+
+static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
+{
+       return container_of(port, struct s3c24xx_uart_port, port);
+}
+
+/* translate a port to the device name */
+
+static inline const char *s3c24xx_serial_portname(struct uart_port *port)
+{
+       return to_platform_device(port->dev)->name;
+}
+
+static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
+{
+       return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
+}
+
+static void s3c24xx_serial_rx_enable(struct uart_port *port)
+{
+       unsigned long flags;
+       unsigned int ucon, ufcon;
+       int count = 10000;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       while (--count && !s3c24xx_serial_txempty_nofifo(port))
+               udelay(100);
+
+       ufcon = rd_regl(port, S3C2410_UFCON);
+       ufcon |= S3C2410_UFCON_RESETRX;
+       wr_regl(port, S3C2410_UFCON, ufcon);
+
+       ucon = rd_regl(port, S3C2410_UCON);
+       ucon |= S3C2410_UCON_RXIRQMODE;
+       wr_regl(port, S3C2410_UCON, ucon);
+
+       rx_enabled(port) = 1;
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void s3c24xx_serial_rx_disable(struct uart_port *port)
+{
+       unsigned long flags;
+       unsigned int ucon;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       ucon = rd_regl(port, S3C2410_UCON);
+       ucon &= ~S3C2410_UCON_RXIRQMODE;
+       wr_regl(port, S3C2410_UCON, ucon);
+
+       rx_enabled(port) = 0;
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void s3c24xx_serial_stop_tx(struct uart_port *port)
+{
+       if (tx_enabled(port)) {
+               disable_irq(TX_IRQ(port));
+               tx_enabled(port) = 0;
+               if (port->flags & UPF_CONS_FLOW)
+                       s3c24xx_serial_rx_enable(port);
+       }
+}
+
+static void s3c24xx_serial_start_tx(struct uart_port *port)
+{
+       if (!tx_enabled(port)) {
+               if (port->flags & UPF_CONS_FLOW)
+                       s3c24xx_serial_rx_disable(port);
+
+               enable_irq(TX_IRQ(port));
+               tx_enabled(port) = 1;
+       }
+}
+
+
+static void s3c24xx_serial_stop_rx(struct uart_port *port)
+{
+       if (rx_enabled(port)) {
+               dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
+               disable_irq(RX_IRQ(port));
+               rx_enabled(port) = 0;
+       }
+}
+
+static void s3c24xx_serial_enable_ms(struct uart_port *port)
+{
+}
+
+static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
+{
+       return to_ourport(port)->info;
+}
+
+static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
+{
+       if (port->dev == NULL)
+               return NULL;
+
+       return (struct s3c2410_uartcfg *)port->dev->platform_data;
+}
+
+static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
+                                    unsigned long ufstat)
+{
+       struct s3c24xx_uart_info *info = ourport->info;
+
+       if (ufstat & info->rx_fifofull)
+               return info->fifosize;
+
+       return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
+}
+
+
+/* ? - where has parity gone?? */
+#define S3C2410_UERSTAT_PARITY (0x1000)
+
+static irqreturn_t
+s3c24xx_serial_rx_chars(int irq, void *dev_id)
+{
+       struct s3c24xx_uart_port *ourport = dev_id;
+       struct uart_port *port = &ourport->port;
+       struct tty_struct *tty = port->info->tty;
+       unsigned int ufcon, ch, flag, ufstat, uerstat;
+       int max_count = 64;
+
+       while (max_count-- > 0) {
+               ufcon = rd_regl(port, S3C2410_UFCON);
+               ufstat = rd_regl(port, S3C2410_UFSTAT);
+
+               if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
+                       break;
+
+               uerstat = rd_regl(port, S3C2410_UERSTAT);
+               ch = rd_regb(port, S3C2410_URXH);
+
+               if (port->flags & UPF_CONS_FLOW) {
+                       int txe = s3c24xx_serial_txempty_nofifo(port);
+
+                       if (rx_enabled(port)) {
+                               if (!txe) {
+                                       rx_enabled(port) = 0;
+                                       continue;
+                               }
+                       } else {
+                               if (txe) {
+                                       ufcon |= S3C2410_UFCON_RESETRX;
+                                       wr_regl(port, S3C2410_UFCON, ufcon);
+                                       rx_enabled(port) = 1;
+                                       goto out;
+                               }
+                               continue;
+                       }
+               }
+
+               /* insert the character into the buffer */
+
+               flag = TTY_NORMAL;
+               port->icount.rx++;
+
+               if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
+                       dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
+                           ch, uerstat);
+
+                       /* check for break */
+                       if (uerstat & S3C2410_UERSTAT_BREAK) {
+                               dbg("break!\n");
+                               port->icount.brk++;
+                               if (uart_handle_break(port))
+                                   goto ignore_char;
+                       }
+
+                       if (uerstat & S3C2410_UERSTAT_FRAME)
+                               port->icount.frame++;
+                       if (uerstat & S3C2410_UERSTAT_OVERRUN)
+                               port->icount.overrun++;
+
+                       uerstat &= port->read_status_mask;
+
+                       if (uerstat & S3C2410_UERSTAT_BREAK)
+                               flag = TTY_BREAK;
+                       else if (uerstat & S3C2410_UERSTAT_PARITY)
+                               flag = TTY_PARITY;
+                       else if (uerstat & (S3C2410_UERSTAT_FRAME |
+                                           S3C2410_UERSTAT_OVERRUN))
+                               flag = TTY_FRAME;
+               }
+
+               if (uart_handle_sysrq_char(port, ch))
+                       goto ignore_char;
+
+               uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN,
+                                ch, flag);
+
+ ignore_char:
+               continue;
+       }
+       tty_flip_buffer_push(tty);
+
+ out:
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
+{
+       struct s3c24xx_uart_port *ourport = id;
+       struct uart_port *port = &ourport->port;
+       struct circ_buf *xmit = &port->info->xmit;
+       int count = 256;
+
+       if (port->x_char) {
+               wr_regb(port, S3C2410_UTXH, port->x_char);
+               port->icount.tx++;
+               port->x_char = 0;
+               goto out;
+       }
+
+       /* if there isnt anything more to transmit, or the uart is now
+        * stopped, disable the uart and exit
+       */
+
+       if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
+               s3c24xx_serial_stop_tx(port);
+               goto out;
+       }
+
+       /* try and drain the buffer... */
+
+       while (!uart_circ_empty(xmit) && count-- > 0) {
+               if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
+                       break;
+
+               wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
+               xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
+               port->icount.tx++;
+       }
+
+       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+               uart_write_wakeup(port);
+
+       if (uart_circ_empty(xmit))
+               s3c24xx_serial_stop_tx(port);
+
+ out:
+       return IRQ_HANDLED;
+}
+
+static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+       unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
+       unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
+
+       if (ufcon & S3C2410_UFCON_FIFOMODE) {
+               if ((ufstat & info->tx_fifomask) != 0 ||
+                   (ufstat & info->tx_fifofull))
+                       return 0;
+
+               return 1;
+       }
+
+       return s3c24xx_serial_txempty_nofifo(port);
+}
+
+/* no modem control lines */
+static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
+{
+       unsigned int umstat = rd_regb(port, S3C2410_UMSTAT);
+
+       if (umstat & S3C2410_UMSTAT_CTS)
+               return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
+       else
+               return TIOCM_CAR | TIOCM_DSR;
+}
+
+static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
+{
+       /* todo - possibly remove AFC and do manual CTS */
+}
+
+static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
+{
+       unsigned long flags;
+       unsigned int ucon;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       ucon = rd_regl(port, S3C2410_UCON);
+
+       if (break_state)
+               ucon |= S3C2410_UCON_SBREAK;
+       else
+               ucon &= ~S3C2410_UCON_SBREAK;
+
+       wr_regl(port, S3C2410_UCON, ucon);
+
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static void s3c24xx_serial_shutdown(struct uart_port *port)
+{
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+
+       if (ourport->tx_claimed) {
+               free_irq(TX_IRQ(port), ourport);
+               tx_enabled(port) = 0;
+               ourport->tx_claimed = 0;
+       }
+
+       if (ourport->rx_claimed) {
+               free_irq(RX_IRQ(port), ourport);
+               ourport->rx_claimed = 0;
+               rx_enabled(port) = 0;
+       }
+}
+
+
+static int s3c24xx_serial_startup(struct uart_port *port)
+{
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+       int ret;
+
+       dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
+           port->mapbase, port->membase);
+
+       rx_enabled(port) = 1;
+
+       ret = request_irq(RX_IRQ(port),
+                         s3c24xx_serial_rx_chars, 0,
+                         s3c24xx_serial_portname(port), ourport);
+
+       if (ret != 0) {
+               printk(KERN_ERR "cannot get irq %d\n", RX_IRQ(port));
+               return ret;
+       }
+
+       ourport->rx_claimed = 1;
+
+       dbg("requesting tx irq...\n");
+
+       tx_enabled(port) = 1;
+
+       ret = request_irq(TX_IRQ(port),
+                         s3c24xx_serial_tx_chars, 0,
+                         s3c24xx_serial_portname(port), ourport);
+
+       if (ret) {
+               printk(KERN_ERR "cannot get irq %d\n", TX_IRQ(port));
+               goto err;
+       }
+
+       ourport->tx_claimed = 1;
+
+       dbg("s3c24xx_serial_startup ok\n");
+
+       /* the port reset code should have done the correct
+        * register setup for the port controls */
+
+       return ret;
+
+ err:
+       s3c24xx_serial_shutdown(port);
+       return ret;
+}
+
+/* power power management control */
+
+static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
+                             unsigned int old)
+{
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+
+       switch (level) {
+       case 3:
+               if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
+                       clk_disable(ourport->baudclk);
+
+               clk_disable(ourport->clk);
+               break;
+
+       case 0:
+               clk_enable(ourport->clk);
+
+               if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
+                       clk_enable(ourport->baudclk);
+
+               break;
+       default:
+               printk(KERN_ERR "s3c24xx_serial: unknown pm %d\n", level);
+       }
+}
+
+/* baud rate calculation
+ *
+ * The UARTs on the S3C2410/S3C2440 can take their clocks from a number
+ * of different sources, including the peripheral clock ("pclk") and an
+ * external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
+ * with a programmable extra divisor.
+ *
+ * The following code goes through the clock sources, and calculates the
+ * baud clocks (and the resultant actual baud rates) and then tries to
+ * pick the closest one and select that.
+ *
+*/
+
+
+#define MAX_CLKS (8)
+
+static struct s3c24xx_uart_clksrc tmp_clksrc = {
+       .name           = "pclk",
+       .min_baud       = 0,
+       .max_baud       = 0,
+       .divisor        = 1,
+};
+
+static inline int
+s3c24xx_serial_getsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+
+       return (info->get_clksrc)(port, c);
+}
+
+static inline int
+s3c24xx_serial_setsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+
+       return (info->set_clksrc)(port, c);
+}
+
+struct baud_calc {
+       struct s3c24xx_uart_clksrc      *clksrc;
+       unsigned int                     calc;
+       unsigned int                     quot;
+       struct clk                      *src;
+};
+
+static int s3c24xx_serial_calcbaud(struct baud_calc *calc,
+                                  struct uart_port *port,
+                                  struct s3c24xx_uart_clksrc *clksrc,
+                                  unsigned int baud)
+{
+       unsigned long rate;
+
+       calc->src = clk_get(port->dev, clksrc->name);
+       if (calc->src == NULL || IS_ERR(calc->src))
+               return 0;
+
+       rate = clk_get_rate(calc->src);
+       rate /= clksrc->divisor;
+
+       calc->clksrc = clksrc;
+       calc->quot = (rate + (8 * baud)) / (16 * baud);
+       calc->calc = (rate / (calc->quot * 16));
+
+       calc->quot--;
+       return 1;
+}
+
+static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
+                                         struct s3c24xx_uart_clksrc **clksrc,
+                                         struct clk **clk,
+                                         unsigned int baud)
+{
+       struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
+       struct s3c24xx_uart_clksrc *clkp;
+       struct baud_calc res[MAX_CLKS];
+       struct baud_calc *resptr, *best, *sptr;
+       int i;
+
+       clkp = cfg->clocks;
+       best = NULL;
+
+       if (cfg->clocks_size < 2) {
+               if (cfg->clocks_size == 0)
+                       clkp = &tmp_clksrc;
+
+               /* check to see if we're sourcing fclk, and if so we're
+                * going to have to update the clock source
+                */
+
+               if (strcmp(clkp->name, "fclk") == 0) {
+                       struct s3c24xx_uart_clksrc src;
+
+                       s3c24xx_serial_getsource(port, &src);
+
+                       /* check that the port already using fclk, and if
+                        * not, then re-select fclk
+                        */
+
+                       if (strcmp(src.name, clkp->name) == 0) {
+                               s3c24xx_serial_setsource(port, clkp);
+                               s3c24xx_serial_getsource(port, &src);
+                       }
+
+                       clkp->divisor = src.divisor;
+               }
+
+               s3c24xx_serial_calcbaud(res, port, clkp, baud);
+               best = res;
+               resptr = best + 1;
+       } else {
+               resptr = res;
+
+               for (i = 0; i < cfg->clocks_size; i++, clkp++) {
+                       if (s3c24xx_serial_calcbaud(resptr, port, clkp, baud))
+                               resptr++;
+               }
+       }
+
+       /* ok, we now need to select the best clock we found */
+
+       if (!best) {
+               unsigned int deviation = (1<<30)|((1<<30)-1);
+               int calc_deviation;
+
+               for (sptr = res; sptr < resptr; sptr++) {
+                       calc_deviation = baud - sptr->calc;
+                       if (calc_deviation < 0)
+                               calc_deviation = -calc_deviation;
+
+                       if (calc_deviation < deviation) {
+                               best = sptr;
+                               deviation = calc_deviation;
+                       }
+               }
+       }
+
+       /* store results to pass back */
+
+       *clksrc = best->clksrc;
+       *clk    = best->src;
+
+       return best->quot;
+}
+
+static void s3c24xx_serial_set_termios(struct uart_port *port,
+                                      struct ktermios *termios,
+                                      struct ktermios *old)
+{
+       struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+       struct s3c24xx_uart_clksrc *clksrc = NULL;
+       struct clk *clk = NULL;
+       unsigned long flags;
+       unsigned int baud, quot;
+       unsigned int ulcon;
+       unsigned int umcon;
+
+       /*
+        * We don't support modem control lines.
+        */
+       termios->c_cflag &= ~(HUPCL | CMSPAR);
+       termios->c_cflag |= CLOCAL;
+
+       /*
+        * Ask the core to calculate the divisor for us.
+        */
+
+       baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
+
+       if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
+               quot = port->custom_divisor;
+       else
+               quot = s3c24xx_serial_getclk(port, &clksrc, &clk, baud);
+
+       /* check to see if we need  to change clock source */
+
+       if (ourport->clksrc != clksrc || ourport->baudclk != clk) {
+               s3c24xx_serial_setsource(port, clksrc);
+
+               if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
+                       clk_disable(ourport->baudclk);
+                       ourport->baudclk  = NULL;
+               }
+
+               clk_enable(clk);
+
+               ourport->clksrc = clksrc;
+               ourport->baudclk = clk;
+       }
+
+       switch (termios->c_cflag & CSIZE) {
+       case CS5:
+               dbg("config: 5bits/char\n");
+               ulcon = S3C2410_LCON_CS5;
+               break;
+       case CS6:
+               dbg("config: 6bits/char\n");
+               ulcon = S3C2410_LCON_CS6;
+               break;
+       case CS7:
+               dbg("config: 7bits/char\n");
+               ulcon = S3C2410_LCON_CS7;
+               break;
+       case CS8:
+       default:
+               dbg("config: 8bits/char\n");
+               ulcon = S3C2410_LCON_CS8;
+               break;
+       }
+
+       /* preserve original lcon IR settings */
+       ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
+
+       if (termios->c_cflag & CSTOPB)
+               ulcon |= S3C2410_LCON_STOPB;
+
+       umcon = (termios->c_cflag & CRTSCTS) ? S3C2410_UMCOM_AFC : 0;
+
+       if (termios->c_cflag & PARENB) {
+               if (termios->c_cflag & PARODD)
+                       ulcon |= S3C2410_LCON_PODD;
+               else
+                       ulcon |= S3C2410_LCON_PEVEN;
+       } else {
+               ulcon |= S3C2410_LCON_PNONE;
+       }
+
+       spin_lock_irqsave(&port->lock, flags);
+
+       dbg("setting ulcon to %08x, brddiv to %d\n", ulcon, quot);
+
+       wr_regl(port, S3C2410_ULCON, ulcon);
+       wr_regl(port, S3C2410_UBRDIV, quot);
+       wr_regl(port, S3C2410_UMCON, umcon);
+
+       dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
+           rd_regl(port, S3C2410_ULCON),
+           rd_regl(port, S3C2410_UCON),
+           rd_regl(port, S3C2410_UFCON));
+
+       /*
+        * Update the per-port timeout.
+        */
+       uart_update_timeout(port, termios->c_cflag, baud);
+
+       /*
+        * Which character status flags are we interested in?
+        */
+       port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
+       if (termios->c_iflag & INPCK)
+               port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
+
+       /*
+        * Which character status flags should we ignore?
+        */
+       port->ignore_status_mask = 0;
+       if (termios->c_iflag & IGNPAR)
+               port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
+       if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
+               port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
+
+       /*
+        * Ignore all characters if CREAD is not set.
+        */
+       if ((termios->c_cflag & CREAD) == 0)
+               port->ignore_status_mask |= RXSTAT_DUMMY_READ;
+
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+static const char *s3c24xx_serial_type(struct uart_port *port)
+{
+       switch (port->type) {
+       case PORT_S3C2410:
+               return "S3C2410";
+       case PORT_S3C2440:
+               return "S3C2440";
+       case PORT_S3C2412:
+               return "S3C2412";
+       default:
+               return NULL;
+       }
+}
+
+#define MAP_SIZE (0x100)
+
+static void s3c24xx_serial_release_port(struct uart_port *port)
+{
+       release_mem_region(port->mapbase, MAP_SIZE);
+}
+
+static int s3c24xx_serial_request_port(struct uart_port *port)
+{
+       const char *name = s3c24xx_serial_portname(port);
+       return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
+}
+
+static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+
+       if (flags & UART_CONFIG_TYPE &&
+           s3c24xx_serial_request_port(port) == 0)
+               port->type = info->type;
+}
+
+/*
+ * verify the new serial_struct (for TIOCSSERIAL).
+ */
+static int
+s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+
+       if (ser->type != PORT_UNKNOWN && ser->type != info->type)
+               return -EINVAL;
+
+       return 0;
+}
+
+
+#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
+
+static struct console s3c24xx_serial_console;
+
+#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
+#else
+#define S3C24XX_SERIAL_CONSOLE NULL
+#endif
+
+static struct uart_ops s3c24xx_serial_ops = {
+       .pm             = s3c24xx_serial_pm,
+       .tx_empty       = s3c24xx_serial_tx_empty,
+       .get_mctrl      = s3c24xx_serial_get_mctrl,
+       .set_mctrl      = s3c24xx_serial_set_mctrl,
+       .stop_tx        = s3c24xx_serial_stop_tx,
+       .start_tx       = s3c24xx_serial_start_tx,
+       .stop_rx        = s3c24xx_serial_stop_rx,
+       .enable_ms      = s3c24xx_serial_enable_ms,
+       .break_ctl      = s3c24xx_serial_break_ctl,
+       .startup        = s3c24xx_serial_startup,
+       .shutdown       = s3c24xx_serial_shutdown,
+       .set_termios    = s3c24xx_serial_set_termios,
+       .type           = s3c24xx_serial_type,
+       .release_port   = s3c24xx_serial_release_port,
+       .request_port   = s3c24xx_serial_request_port,
+       .config_port    = s3c24xx_serial_config_port,
+       .verify_port    = s3c24xx_serial_verify_port,
+};
+
+
+static struct uart_driver s3c24xx_uart_drv = {
+       .owner          = THIS_MODULE,
+       .dev_name       = "s3c2410_serial",
+       .nr             = 3,
+       .cons           = S3C24XX_SERIAL_CONSOLE,
+       .driver_name    = S3C24XX_SERIAL_NAME,
+       .major          = S3C24XX_SERIAL_MAJOR,
+       .minor          = S3C24XX_SERIAL_MINOR,
+};
+
+static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
+       [0] = {
+               .port = {
+                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
+                       .iotype         = UPIO_MEM,
+                       .irq            = IRQ_S3CUART_RX0,
+                       .uartclk        = 0,
+                       .fifosize       = 16,
+                       .ops            = &s3c24xx_serial_ops,
+                       .flags          = UPF_BOOT_AUTOCONF,
+                       .line           = 0,
+               }
+       },
+       [1] = {
+               .port = {
+                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
+                       .iotype         = UPIO_MEM,
+                       .irq            = IRQ_S3CUART_RX1,
+                       .uartclk        = 0,
+                       .fifosize       = 16,
+                       .ops            = &s3c24xx_serial_ops,
+                       .flags          = UPF_BOOT_AUTOCONF,
+                       .line           = 1,
+               }
+       },
+#if NR_PORTS > 2
+
+       [2] = {
+               .port = {
+                       .lock           = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
+                       .iotype         = UPIO_MEM,
+                       .irq            = IRQ_S3CUART_RX2,
+                       .uartclk        = 0,
+                       .fifosize       = 16,
+                       .ops            = &s3c24xx_serial_ops,
+                       .flags          = UPF_BOOT_AUTOCONF,
+                       .line           = 2,
+               }
+       }
+#endif
+};
+
+/* s3c24xx_serial_resetport
+ *
+ * wrapper to call the specific reset for this port (reset the fifos
+ * and the settings)
+*/
+
+static inline int s3c24xx_serial_resetport(struct uart_port *port,
+                                          struct s3c2410_uartcfg *cfg)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+
+       return (info->reset_port)(port, cfg);
+}
+
+/* s3c24xx_serial_init_port
+ *
+ * initialise a single serial port from the platform device given
+ */
+
+static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
+                                   struct s3c24xx_uart_info *info,
+                                   struct platform_device *platdev)
+{
+       struct uart_port *port = &ourport->port;
+       struct s3c2410_uartcfg *cfg;
+       struct resource *res;
+       int ret;
+
+       dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
+
+       if (platdev == NULL)
+               return -ENODEV;
+
+       cfg = s3c24xx_dev_to_cfg(&platdev->dev);
+
+       if (port->mapbase != 0)
+               return 0;
+
+       if (cfg->hwport > 3)
+               return -EINVAL;
+
+       /* setup info for port */
+       port->dev       = &platdev->dev;
+       ourport->info   = info;
+
+       /* copy the info in from provided structure */
+       ourport->port.fifosize = info->fifosize;
+
+       dbg("s3c24xx_serial_init_port: %p (hw %d)...\n", port, cfg->hwport);
+
+       port->uartclk = 1;
+
+       if (cfg->uart_flags & UPF_CONS_FLOW) {
+               dbg("s3c24xx_serial_init_port: enabling flow control\n");
+               port->flags |= UPF_CONS_FLOW;
+       }
+
+       /* sort our the physical and virtual addresses for each UART */
+
+       res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               printk(KERN_ERR "failed to find memory resource for uart\n");
+               return -EINVAL;
+       }
+
+       dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
+
+       port->mapbase   = res->start;
+       port->membase   = S3C24XX_VA_UART + (res->start - S3C24XX_PA_UART);
+       ret = platform_get_irq(platdev, 0);
+       if (ret < 0)
+               port->irq = 0;
+       else
+               port->irq = ret;
+
+       ourport->clk    = clk_get(&platdev->dev, "uart");
+
+       dbg("port: map=%08x, mem=%08x, irq=%d, clock=%ld\n",
+           port->mapbase, port->membase, port->irq, port->uartclk);
+
+       /* reset the fifos (and setup the uart) */
+       s3c24xx_serial_resetport(port, cfg);
+       return 0;
+}
+
+static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       struct uart_port *port = s3c24xx_dev_to_port(dev);
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+
+       return snprintf(buf, PAGE_SIZE, "* %s\n", ourport->clksrc->name);
+}
+
+static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
+
+/* Device driver serial port probe */
+
+static int probe_index;
+
+int s3c24xx_serial_probe(struct platform_device *dev,
+                        struct s3c24xx_uart_info *info)
+{
+       struct s3c24xx_uart_port *ourport;
+       int ret;
+
+       dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
+
+       ourport = &s3c24xx_serial_ports[probe_index];
+       probe_index++;
+
+       dbg("%s: initialising port %p...\n", __func__, ourport);
+
+       ret = s3c24xx_serial_init_port(ourport, info, dev);
+       if (ret < 0)
+               goto probe_err;
+
+       dbg("%s: adding port\n", __func__);
+       uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
+       platform_set_drvdata(dev, &ourport->port);
+
+       ret = device_create_file(&dev->dev, &dev_attr_clock_source);
+       if (ret < 0)
+               printk(KERN_ERR "%s: failed to add clksrc attr.\n", __func__);
+
+       return 0;
+
+ probe_err:
+       return ret;
+}
+
+EXPORT_SYMBOL_GPL(s3c24xx_serial_probe);
+
+int s3c24xx_serial_remove(struct platform_device *dev)
+{
+       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
+
+       if (port) {
+               device_remove_file(&dev->dev, &dev_attr_clock_source);
+               uart_remove_one_port(&s3c24xx_uart_drv, port);
+       }
+
+       return 0;
+}
+
+EXPORT_SYMBOL_GPL(s3c24xx_serial_remove);
+
+/* UART power management code */
+
+#ifdef CONFIG_PM
+
+static int s3c24xx_serial_suspend(struct platform_device *dev, pm_message_t state)
+{
+       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
+
+       if (port)
+               uart_suspend_port(&s3c24xx_uart_drv, port);
+
+       return 0;
+}
+
+static int s3c24xx_serial_resume(struct platform_device *dev)
+{
+       struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
+       struct s3c24xx_uart_port *ourport = to_ourport(port);
+
+       if (port) {
+               clk_enable(ourport->clk);
+               s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
+               clk_disable(ourport->clk);
+
+               uart_resume_port(&s3c24xx_uart_drv, port);
+       }
+
+       return 0;
+}
+#endif
+
+int s3c24xx_serial_init(struct platform_driver *drv,
+                       struct s3c24xx_uart_info *info)
+{
+       dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
+
+#ifdef CONFIG_PM
+       drv->suspend = s3c24xx_serial_suspend;
+       drv->resume = s3c24xx_serial_resume;
+#endif
+
+       return platform_driver_register(drv);
+}
+
+EXPORT_SYMBOL_GPL(s3c24xx_serial_init);
+
+/* module initialisation code */
+
+static int __init s3c24xx_serial_modinit(void)
+{
+       int ret;
+
+       ret = uart_register_driver(&s3c24xx_uart_drv);
+       if (ret < 0) {
+               printk(KERN_ERR "failed to register UART driver\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static void __exit s3c24xx_serial_modexit(void)
+{
+       uart_unregister_driver(&s3c24xx_uart_drv);
+}
+
+module_init(s3c24xx_serial_modinit);
+module_exit(s3c24xx_serial_modexit);
+
+/* Console code */
+
+#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
+
+static struct uart_port *cons_uart;
+
+static int
+s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
+{
+       struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
+       unsigned long ufstat, utrstat;
+
+       if (ufcon & S3C2410_UFCON_FIFOMODE) {
+               /* fifo mode - check ammount of data in fifo registers... */
+
+               ufstat = rd_regl(port, S3C2410_UFSTAT);
+               return (ufstat & info->tx_fifofull) ? 0 : 1;
+       }
+
+       /* in non-fifo mode, we go and use the tx buffer empty */
+
+       utrstat = rd_regl(port, S3C2410_UTRSTAT);
+       return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
+}
+
+static void
+s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
+{
+       unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
+       while (!s3c24xx_serial_console_txrdy(port, ufcon))
+               barrier();
+       wr_regb(cons_uart, S3C2410_UTXH, ch);
+}
+
+static void
+s3c24xx_serial_console_write(struct console *co, const char *s,
+                            unsigned int count)
+{
+       uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
+}
+
+static void __init
+s3c24xx_serial_get_options(struct uart_port *port, int *baud,
+                          int *parity, int *bits)
+{
+       struct s3c24xx_uart_clksrc clksrc;
+       struct clk *clk;
+       unsigned int ulcon;
+       unsigned int ucon;
+       unsigned int ubrdiv;
+       unsigned long rate;
+
+       ulcon  = rd_regl(port, S3C2410_ULCON);
+       ucon   = rd_regl(port, S3C2410_UCON);
+       ubrdiv = rd_regl(port, S3C2410_UBRDIV);
+
+       dbg("s3c24xx_serial_get_options: port=%p\n"
+           "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
+           port, ulcon, ucon, ubrdiv);
+
+       if ((ucon & 0xf) != 0) {
+               /* consider the serial port configured if the tx/rx mode set */
+
+               switch (ulcon & S3C2410_LCON_CSMASK) {
+               case S3C2410_LCON_CS5:
+                       *bits = 5;
+                       break;
+               case S3C2410_LCON_CS6:
+                       *bits = 6;
+                       break;
+               case S3C2410_LCON_CS7:
+                       *bits = 7;
+                       break;
+               default:
+               case S3C2410_LCON_CS8:
+                       *bits = 8;
+                       break;
+               }
+
+               switch (ulcon & S3C2410_LCON_PMASK) {
+               case S3C2410_LCON_PEVEN:
+                       *parity = 'e';
+                       break;
+
+               case S3C2410_LCON_PODD:
+                       *parity = 'o';
+                       break;
+
+               case S3C2410_LCON_PNONE:
+               default:
+                       *parity = 'n';
+               }
+
+               /* now calculate the baud rate */
+
+               s3c24xx_serial_getsource(port, &clksrc);
+
+               clk = clk_get(port->dev, clksrc.name);
+               if (!IS_ERR(clk) && clk != NULL)
+                       rate = clk_get_rate(clk) / clksrc.divisor;
+               else
+                       rate = 1;
+
+
+               *baud = rate / (16 * (ubrdiv + 1));
+               dbg("calculated baud %d\n", *baud);
+       }
+
+}
+
+/* s3c24xx_serial_init_ports
+ *
+ * initialise the serial ports from the machine provided initialisation
+ * data.
+*/
+
+static int s3c24xx_serial_init_ports(struct s3c24xx_uart_info *info)
+{
+       struct s3c24xx_uart_port *ptr = s3c24xx_serial_ports;
+       struct platform_device **platdev_ptr;
+       int i;
+
+       dbg("s3c24xx_serial_init_ports: initialising ports...\n");
+
+       platdev_ptr = s3c24xx_uart_devs;
+
+       for (i = 0; i < NR_PORTS; i++, ptr++, platdev_ptr++) {
+               s3c24xx_serial_init_port(ptr, info, *platdev_ptr);
+       }
+
+       return 0;
+}
+
+static int __init
+s3c24xx_serial_console_setup(struct console *co, char *options)
+{
+       struct uart_port *port;
+       int baud = 9600;
+       int bits = 8;
+       int parity = 'n';
+       int flow = 'n';
+
+       dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
+           co, co->index, options);
+
+       /* is this a valid port */
+
+       if (co->index == -1 || co->index >= NR_PORTS)
+               co->index = 0;
+
+       port = &s3c24xx_serial_ports[co->index].port;
+
+       /* is the port configured? */
+
+       if (port->mapbase == 0x0) {
+               co->index = 0;
+               port = &s3c24xx_serial_ports[co->index].port;
+       }
+
+       cons_uart = port;
+
+       dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
+
+       /*
+        * Check whether an invalid uart number has been specified, and
+        * if so, search for the first available port that does have
+        * console support.
+        */
+       if (options)
+               uart_parse_options(options, &baud, &parity, &bits, &flow);
+       else
+               s3c24xx_serial_get_options(port, &baud, &parity, &bits);
+
+       dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
+
+       return uart_set_options(port, co, baud, parity, bits, flow);
+}
+
+/* s3c24xx_serial_initconsole
+ *
+ * initialise the console from one of the uart drivers
+*/
+
+static struct console s3c24xx_serial_console = {
+       .name           = S3C24XX_SERIAL_NAME,
+       .device         = uart_console_device,
+       .flags          = CON_PRINTBUFFER,
+       .index          = -1,
+       .write          = s3c24xx_serial_console_write,
+       .setup          = s3c24xx_serial_console_setup
+};
+
+int s3c24xx_serial_initconsole(struct platform_driver *drv,
+                              struct s3c24xx_uart_info *info)
+
+{
+       struct platform_device *dev = s3c24xx_uart_devs[0];
+
+       dbg("s3c24xx_serial_initconsole\n");
+
+       /* select driver based on the cpu */
+
+       if (dev == NULL) {
+               printk(KERN_ERR "s3c24xx: no devices for console init\n");
+               return 0;
+       }
+
+       if (strcmp(dev->name, drv->driver.name) != 0)
+               return 0;
+
+       s3c24xx_serial_console.data = &s3c24xx_uart_drv;
+       s3c24xx_serial_init_ports(info);
+
+       register_console(&s3c24xx_serial_console);
+       return 0;
+}
+
+#endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
+
+MODULE_DESCRIPTION("Samsung SoC Serial port driver");
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/serial/samsung.h b/drivers/serial/samsung.h
new file mode 100644 (file)
index 0000000..5c92ebb
--- /dev/null
@@ -0,0 +1,102 @@
+/* linux/drivers/serial/samsung.h
+ *
+ * Driver for Samsung SoC onboard UARTs.
+ *
+ * Ben Dooks, Copyright (c) 2003-2005,2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+struct s3c24xx_uart_info {
+       char                    *name;
+       unsigned int            type;
+       unsigned int            fifosize;
+       unsigned long           rx_fifomask;
+       unsigned long           rx_fifoshift;
+       unsigned long           rx_fifofull;
+       unsigned long           tx_fifomask;
+       unsigned long           tx_fifoshift;
+       unsigned long           tx_fifofull;
+
+       /* clock source control */
+
+       int (*get_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
+       int (*set_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
+
+       /* uart controls */
+       int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *);
+};
+
+struct s3c24xx_uart_port {
+       unsigned char                   rx_claimed;
+       unsigned char                   tx_claimed;
+
+       struct s3c24xx_uart_info        *info;
+       struct s3c24xx_uart_clksrc      *clksrc;
+       struct clk                      *clk;
+       struct clk                      *baudclk;
+       struct uart_port                port;
+};
+
+/* conversion functions */
+
+#define s3c24xx_dev_to_port(__dev) (struct uart_port *)dev_get_drvdata(__dev)
+#define s3c24xx_dev_to_cfg(__dev) (struct s3c2410_uartcfg *)((__dev)->platform_data)
+
+/* register access controls */
+
+#define portaddr(port, reg) ((port)->membase + (reg))
+
+#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
+#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
+
+#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg))
+#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg))
+
+extern int s3c24xx_serial_probe(struct platform_device *dev,
+                               struct s3c24xx_uart_info *uart);
+
+extern int s3c24xx_serial_remove(struct platform_device *dev);
+
+extern int s3c24xx_serial_initconsole(struct platform_driver *drv,
+                                     struct s3c24xx_uart_info *uart);
+
+extern int s3c24xx_serial_init(struct platform_driver *drv,
+                              struct s3c24xx_uart_info *info);
+
+#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
+
+#define s3c24xx_console_init(__drv, __inf)                     \
+static int __init s3c_serial_console_init(void)                        \
+{                                                              \
+       return s3c24xx_serial_initconsole(__drv, __inf);        \
+}                                                              \
+                                                               \
+console_initcall(s3c_serial_console_init)
+
+#else
+#define s3c24xx_console_init(drv, inf) extern void no_console(void)
+#endif
+
+#ifdef CONFIG_SERIAL_SAMSUNG_DEBUG
+
+extern void printascii(const char *);
+
+static void dbg(const char *fmt, ...)
+{
+       va_list va;
+       char buff[256];
+
+       va_start(va, fmt);
+       vsprintf(buff, fmt, va);
+       va_end(va);
+
+       printascii(buff);
+}
+
+#else
+#define dbg(x...) do { } while (0)
+#endif
index c730d05..54ac7be 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/spi/spi.h>
 #include <linux/workqueue.h>
 #include <linux/delay.h>
+#include <linux/clk.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -250,6 +251,8 @@ struct driver_data {
        int tx_dma_needs_unmap;
        size_t tx_map_len;
        u32 dummy_dma_buf ____cacheline_aligned;
+
+       struct clk *clk;
 };
 
 /* Runtime state */
@@ -855,15 +858,15 @@ static irqreturn_t spi_int(int irq, void *dev_id)
        return drv_data->transfer_handler(drv_data);
 }
 
-static inline u32 spi_speed_hz(u32 data_rate)
+static inline u32 spi_speed_hz(struct driver_data *drv_data, u32 data_rate)
 {
-       return imx_get_perclk2() / (4 << ((data_rate) >> 13));
+       return clk_get_rate(drv_data->clk) / (4 << ((data_rate) >> 13));
 }
 
-static u32 spi_data_rate(u32 speed_hz)
+static u32 spi_data_rate(struct driver_data *drv_data, u32 speed_hz)
 {
        u32 div;
-       u32 quantized_hz = imx_get_perclk2() >> 2;
+       u32 quantized_hz = clk_get_rate(drv_data->clk) >> 2;
 
        for (div = SPI_PERCLK2_DIV_MIN;
                div <= SPI_PERCLK2_DIV_MAX;
@@ -947,7 +950,7 @@ static void pump_transfers(unsigned long data)
        tmp = transfer->speed_hz;
        if (tmp == 0)
                tmp = chip->max_speed_hz;
-       tmp = spi_data_rate(tmp);
+       tmp = spi_data_rate(drv_data, tmp);
        u32_EDIT(control, SPI_CONTROL_DATARATE, tmp);
 
        writel(control, regs + SPI_CONTROL);
@@ -1109,7 +1112,7 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
        msg->actual_length = 0;
 
        /* Per transfer setup check */
-       min_speed_hz = spi_speed_hz(SPI_CONTROL_DATARATE_MIN);
+       min_speed_hz = spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN);
        max_speed_hz = spi->max_speed_hz;
        list_for_each_entry(trans, &msg->transfers, transfer_list) {
                tmp = trans->bits_per_word;
@@ -1176,6 +1179,7 @@ msg_rejected:
    applied and notified to the calling driver. */
 static int setup(struct spi_device *spi)
 {
+       struct driver_data *drv_data = spi_master_get_devdata(spi->master);
        struct spi_imx_chip *chip_info;
        struct chip_data *chip;
        int first_setup = 0;
@@ -1304,14 +1308,14 @@ static int setup(struct spi_device *spi)
        chip->n_bytes = (tmp <= 8) ? 1 : 2;
 
        /* SPI datarate */
-       tmp = spi_data_rate(spi->max_speed_hz);
+       tmp = spi_data_rate(drv_data, spi->max_speed_hz);
        if (tmp == SPI_CONTROL_DATARATE_BAD) {
                status = -EINVAL;
                dev_err(&spi->dev,
                        "setup - "
                        "HW min speed (%d Hz) exceeds required "
                        "max speed (%d Hz)\n",
-                       spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
+                       spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN),
                        spi->max_speed_hz);
                if (first_setup)
                        goto err_first_setup;
@@ -1321,7 +1325,7 @@ static int setup(struct spi_device *spi)
        } else {
                u32_EDIT(chip->control, SPI_CONTROL_DATARATE, tmp);
                /* Actual rounded max_speed_hz */
-               tmp = spi_speed_hz(tmp);
+               tmp = spi_speed_hz(drv_data, tmp);
                spi->max_speed_hz = tmp;
                chip->max_speed_hz = tmp;
        }
@@ -1352,7 +1356,7 @@ static int setup(struct spi_device *spi)
                chip->period & SPI_PERIOD_WAIT,
                spi->mode,
                spi->bits_per_word,
-               spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
+               spi_speed_hz(drv_data, SPI_CONTROL_DATARATE_MIN),
                spi->max_speed_hz);
        return status;
 
@@ -1465,6 +1469,14 @@ static int __init spi_imx_probe(struct platform_device *pdev)
                goto err_no_pdata;
        }
 
+       drv_data->clk = clk_get(&pdev->dev, "perclk2");
+       if (IS_ERR(drv_data->clk)) {
+               dev_err(&pdev->dev, "probe - cannot get get\n");
+               status = PTR_ERR(drv_data->clk);
+               goto err_no_clk;
+       }
+       clk_enable(drv_data->clk);
+
        /* Allocate master with space for drv_data */
        master = spi_alloc_master(dev, sizeof(struct driver_data));
        if (!master) {
@@ -1526,24 +1538,24 @@ static int __init spi_imx_probe(struct platform_device *pdev)
        drv_data->rx_channel = -1;
        if (platform_info->enable_dma) {
                /* Get rx DMA channel */
-               status = imx_dma_request_by_prio(&drv_data->rx_channel,
-                       "spi_imx_rx", DMA_PRIO_HIGH);
-               if (status < 0) {
+               drv_data->rx_channel = imx_dma_request_by_prio("spi_imx_rx",
+                                                              DMA_PRIO_HIGH);
+               if (drv_data->rx_channel < 0) {
                        dev_err(dev,
                                "probe - problem (%d) requesting rx channel\n",
-                               status);
+                               drv_data->rx_channel);
                        goto err_no_rxdma;
                } else
                        imx_dma_setup_handlers(drv_data->rx_channel, NULL,
                                                dma_err_handler, drv_data);
 
                /* Get tx DMA channel */
-               status = imx_dma_request_by_prio(&drv_data->tx_channel,
-                                               "spi_imx_tx", DMA_PRIO_MEDIUM);
-               if (status < 0) {
+               drv_data->tx_channel = imx_dma_request_by_prio("spi_imx_tx",
+                                                              DMA_PRIO_MEDIUM);
+               if (drv_data->tx_channel < 0) {
                        dev_err(dev,
                                "probe - problem (%d) requesting tx channel\n",
-                               status);
+                               drv_data->tx_channel);
                        imx_dma_free(drv_data->rx_channel);
                        goto err_no_txdma;
                } else
@@ -1623,6 +1635,9 @@ err_no_iores:
        spi_master_put(master);
 
 err_no_pdata:
+       clk_disable(drv_data->clk);
+       clk_put(drv_data->clk);
+err_no_clk:
 err_no_mem:
        return status;
 }
@@ -1662,6 +1677,9 @@ static int __exit spi_imx_remove(struct platform_device *pdev)
        if (irq >= 0)
                free_irq(irq, drv_data);
 
+       clk_disable(drv_data->clk);
+       clk_put(drv_data->clk);
+
        /* Release map resources */
        iounmap(drv_data->regs);
        release_resource(drv_data->ioarea);
index f5b60c7..ddbe1a5 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/errno.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/spidev.h>
@@ -464,6 +465,7 @@ static int spidev_open(struct inode *inode, struct file *filp)
        struct spidev_data      *spidev;
        int                     status = -ENXIO;
 
+       lock_kernel();
        mutex_lock(&device_list_lock);
 
        list_for_each_entry(spidev, &device_list, device_entry) {
@@ -489,6 +491,7 @@ static int spidev_open(struct inode *inode, struct file *filp)
                pr_debug("spidev: nothing for minor %d\n", iminor(inode));
 
        mutex_unlock(&device_list_lock);
+       unlock_kernel();
        return status;
 }
 
index bcea8d9..4d74ba3 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/errno.h>
 #include <linux/phonedev.h>
 #include <linux/init.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
@@ -53,6 +54,7 @@ static int phone_open(struct inode *inode, struct file *file)
        if (minor >= PHONE_NUM_DEVICES)
                return -ENODEV;
 
+       lock_kernel();
        mutex_lock(&phone_lock);
        p = phone_device[minor];
        if (p)
@@ -79,6 +81,7 @@ static int phone_open(struct inode *inode, struct file *file)
        fops_put(old_fops);
 end:
        mutex_unlock(&phone_lock);
+       unlock_kernel();
        return err;
 }
 
index 0a12e90..5a7ca2e 100644 (file)
@@ -297,12 +297,17 @@ static int uio_open(struct inode *inode, struct file *filep)
        struct uio_listener *listener;
        int ret = 0;
 
+       lock_kernel();
        idev = idr_find(&uio_idr, iminor(inode));
-       if (!idev)
-               return -ENODEV;
+       if (!idev) {
+               ret = -ENODEV;
+               goto out;
+       }
 
-       if (!try_module_get(idev->owner))
-               return -ENODEV;
+       if (!try_module_get(idev->owner)) {
+               ret = -ENODEV;
+               goto out;
+       }
 
        listener = kmalloc(sizeof(*listener), GFP_KERNEL);
        if (!listener) {
@@ -319,7 +324,7 @@ static int uio_open(struct inode *inode, struct file *filep)
                if (ret)
                        goto err_infoopen;
        }
-
+       unlock_kernel();
        return 0;
 
 err_infoopen:
@@ -329,6 +334,8 @@ err_alloc_listener:
 
        module_put(idev->owner);
 
+out:
+       unlock_kernel();
        return ret;
 }
 
index de17738..9218cca 100644 (file)
@@ -565,6 +565,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
        struct dev_state *ps;
        int ret;
 
+       lock_kernel();
        /* Protect against simultaneous removal or release */
        mutex_lock(&usbfs_mutex);
 
@@ -611,6 +612,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
        if (ret)
                kfree(ps);
        mutex_unlock(&usbfs_mutex);
+       unlock_kernel();
        return ret;
 }
 
index 8133c99..c6a9539 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/rwsem.h>
+#include <linux/smp_lock.h>
 #include <linux/usb.h>
 
 #include "usb.h"
@@ -33,6 +34,7 @@ static int usb_open(struct inode * inode, struct file * file)
        int err = -ENODEV;
        const struct file_operations *old_fops, *new_fops = NULL;
 
+       lock_kernel();
        down_read(&minor_rwsem);
        c = usb_minors[minor];
 
@@ -51,6 +53,7 @@ static int usb_open(struct inode * inode, struct file * file)
        fops_put(old_fops);
  done:
        up_read(&minor_rwsem);
+       unlock_kernel();
        return err;
 }
 
index 6e784d2..d6bab0d 100644 (file)
@@ -118,10 +118,10 @@ config USB_AMD5536UDC
 config USB_GADGET_ATMEL_USBA
        boolean "Atmel USBA"
        select USB_GADGET_DUALSPEED
-       depends on AVR32 || ARCH_AT91CAP9
+       depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL
        help
          USBA is the integrated high-speed USB Device controller on
-         the AT32AP700x and AT91CAP9 processors from Atmel.
+         the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
 
 config USB_ATMEL_USBA
        tristate
@@ -172,7 +172,7 @@ config USB_NET2280
        default USB_GADGET
        select USB_GADGET_SELECTED
 
-config USB_GADGET_PXA2XX
+config USB_GADGET_PXA25X
        boolean "PXA 25x or IXP 4xx"
        depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
        help
@@ -184,19 +184,19 @@ config USB_GADGET_PXA2XX
           zero (for control transfers).
 
           Say "y" to link the driver statically, or "m" to build a
-          dynamically linked module called "pxa2xx_udc" and force all
+          dynamically linked module called "pxa25x_udc" and force all
           gadget drivers to also be dynamically linked.
 
-config USB_PXA2XX
+config USB_PXA25X
        tristate
-       depends on USB_GADGET_PXA2XX
+       depends on USB_GADGET_PXA25X
        default USB_GADGET
        select USB_GADGET_SELECTED
 
 # if there's only one gadget driver, using only two bulk endpoints,
 # don't waste memory for the other endpoints
-config USB_PXA2XX_SMALL
-       depends on USB_GADGET_PXA2XX
+config USB_PXA25X_SMALL
+       depends on USB_GADGET_PXA25X
        bool
        default n if USB_ETH_RNDIS
        default y if USB_ZERO
index 1235725..e258afd 100644 (file)
@@ -8,7 +8,7 @@ endif
 obj-$(CONFIG_USB_DUMMY_HCD)    += dummy_hcd.o
 obj-$(CONFIG_USB_NET2280)      += net2280.o
 obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc.o
-obj-$(CONFIG_USB_PXA2XX)       += pxa2xx_udc.o
+obj-$(CONFIG_USB_PXA25X)       += pxa25x_udc.o
 obj-$(CONFIG_USB_PXA27X)       += pxa27x_udc.o
 obj-$(CONFIG_USB_GOKU)         += goku_udc.o
 obj-$(CONFIG_USB_OMAP)         += omap_udc.o
index 274c60a..b6b2a0a 100644 (file)
@@ -888,7 +888,7 @@ static void pullup(struct at91_udc *udc, int is_on)
                at91_udp_write(udc, AT91_UDP_TXVC, 0);
                if (cpu_is_at91rm9200())
                        gpio_set_value(udc->board.pullup_pin, active);
-               else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
+               else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
                        u32     txvc = at91_udp_read(udc, AT91_UDP_TXVC);
 
                        txvc |= AT91_UDP_TXVC_PUON;
@@ -906,7 +906,7 @@ static void pullup(struct at91_udc *udc, int is_on)
                at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
                if (cpu_is_at91rm9200())
                        gpio_set_value(udc->board.pullup_pin, !active);
-               else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
+               else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || cpu_is_at91sam9g20()) {
                        u32     txvc = at91_udp_read(udc, AT91_UDP_TXVC);
 
                        txvc &= ~AT91_UDP_TXVC_PUON;
index 8d61ea6..4ce3950 100644 (file)
@@ -262,7 +262,7 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
 /* For CDC-incapable hardware, choose the simple cdc subset.
  * Anything that talks bulk (without notable bugs) can do this.
  */
-#ifdef CONFIG_USB_GADGET_PXA2XX
+#ifdef CONFIG_USB_GADGET_PXA25X
 #define        DEV_CONFIG_SUBSET
 #endif
 
index f7f159c..ca5149e 100644 (file)
@@ -29,8 +29,8 @@
 #define        gadget_is_dummy(g)      0
 #endif
 
-#ifdef CONFIG_USB_GADGET_PXA2XX
-#define        gadget_is_pxa(g)        !strcmp("pxa2xx_udc", (g)->name)
+#ifdef CONFIG_USB_GADGET_PXA25X
+#define        gadget_is_pxa(g)        !strcmp("pxa25x_udc", (g)->name)
 #else
 #define        gadget_is_pxa(g)        0
 #endif
index 69b0a27..f132a92 100644 (file)
@@ -1501,7 +1501,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
                }
                break;
 
-#ifndef        CONFIG_USB_GADGET_PXA2XX
+#ifndef        CONFIG_USB_GADGET_PXA25X
        /* PXA automagically handles this request too */
        case USB_REQ_GET_CONFIGURATION:
                if (ctrl->bRequestType != 0x80)
index 881d74c..03a7f49 100644 (file)
@@ -135,13 +135,17 @@ static void use_ep(struct omap_ep *ep, u16 select)
 
        if (ep->bEndpointAddress & USB_DIR_IN)
                num |= UDC_EP_DIR;
-       UDC_EP_NUM_REG = num | select;
+       omap_writew(num | select, UDC_EP_NUM);
        /* when select, MUST deselect later !! */
 }
 
 static inline void deselect_ep(void)
 {
-       UDC_EP_NUM_REG &= ~UDC_EP_SEL;
+       u16 w;
+
+       w = omap_readw(UDC_EP_NUM);
+       w &= ~UDC_EP_SEL;
+       omap_writew(w, UDC_EP_NUM);
        /* 6 wait states before TX will happen */
 }
 
@@ -216,7 +220,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
        ep->has_dma = 0;
        ep->lch = -1;
        use_ep(ep, UDC_EP_SEL);
-       UDC_CTRL_REG = udc->clr_halt;
+       omap_writew(udc->clr_halt, UDC_CTRL);
        ep->ackwait = 0;
        deselect_ep();
 
@@ -232,7 +236,7 @@ static int omap_ep_enable(struct usb_ep *_ep,
        if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC
                        && !ep->has_dma
                        && !(ep->bEndpointAddress & USB_DIR_IN)) {
-               UDC_CTRL_REG = UDC_SET_FIFO_EN;
+               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                ep->ackwait = 1 + ep->double_buf;
        }
 
@@ -259,7 +263,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
        nuke (ep, -ESHUTDOWN);
        ep->ep.maxpacket = ep->maxpacket;
        ep->has_dma = 0;
-       UDC_CTRL_REG = UDC_SET_HALT;
+       omap_writew(UDC_SET_HALT, UDC_CTRL);
        list_del_init(&ep->iso);
        del_timer(&ep->timer);
 
@@ -360,13 +364,13 @@ write_packet(u8 *buf, struct omap_req *req, unsigned max)
        if (likely((((int)buf) & 1) == 0)) {
                wp = (u16 *)buf;
                while (max >= 2) {
-                       UDC_DATA_REG = *wp++;
+                       omap_writew(*wp++, UDC_DATA);
                        max -= 2;
                }
                buf = (u8 *)wp;
        }
        while (max--)
-               *(volatile u8 *)&UDC_DATA_REG = *buf++;
+               omap_writeb(*buf++, UDC_DATA);
        return len;
 }
 
@@ -385,13 +389,13 @@ static int write_fifo(struct omap_ep *ep, struct omap_req *req)
        prefetch(buf);
 
        /* PIO-IN isn't double buffered except for iso */
-       ep_stat = UDC_STAT_FLG_REG;
+       ep_stat = omap_readw(UDC_STAT_FLG);
        if (ep_stat & UDC_FIFO_UNWRITABLE)
                return 0;
 
        count = ep->ep.maxpacket;
        count = write_packet(buf, req, count);
-       UDC_CTRL_REG = UDC_SET_FIFO_EN;
+       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
        ep->ackwait = 1;
 
        /* last packet is often short (sometimes a zlp) */
@@ -425,13 +429,13 @@ read_packet(u8 *buf, struct omap_req *req, unsigned avail)
        if (likely((((int)buf) & 1) == 0)) {
                wp = (u16 *)buf;
                while (avail >= 2) {
-                       *wp++ = UDC_DATA_REG;
+                       *wp++ = omap_readw(UDC_DATA);
                        avail -= 2;
                }
                buf = (u8 *)wp;
        }
        while (avail--)
-               *buf++ = *(volatile u8 *)&UDC_DATA_REG;
+               *buf++ = omap_readb(UDC_DATA);
        return len;
 }
 
@@ -446,7 +450,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
        prefetchw(buf);
 
        for (;;) {
-               u16     ep_stat = UDC_STAT_FLG_REG;
+               u16     ep_stat = omap_readw(UDC_STAT_FLG);
 
                is_last = 0;
                if (ep_stat & FIFO_EMPTY) {
@@ -460,7 +464,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
                if (ep_stat & UDC_FIFO_FULL)
                        avail = ep->ep.maxpacket;
                else  {
-                       avail = UDC_RXFSTAT_REG;
+                       avail = omap_readw(UDC_RXFSTAT);
                        ep->fnf = ep->double_buf;
                }
                count = read_packet(buf, req, avail);
@@ -473,7 +477,7 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
                                req->req.status = -EOVERFLOW;
                                avail -= count;
                                while (avail--)
-                                       (void) *(volatile u8 *)&UDC_DATA_REG;
+                                       omap_readw(UDC_DATA);
                        }
                } else if (req->req.length == req->req.actual)
                        is_last = 1;
@@ -491,32 +495,6 @@ static int read_fifo(struct omap_ep *ep, struct omap_req *req)
 
 /*-------------------------------------------------------------------------*/
 
-static inline dma_addr_t dma_csac(unsigned lch)
-{
-       dma_addr_t      csac;
-
-       /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
-        * read before the DMA controller finished disabling the channel.
-        */
-       csac = OMAP_DMA_CSAC_REG(lch);
-       if (csac == 0)
-               csac = OMAP_DMA_CSAC_REG(lch);
-       return csac;
-}
-
-static inline dma_addr_t dma_cdac(unsigned lch)
-{
-       dma_addr_t      cdac;
-
-       /* omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
-        * read before the DMA controller finished disabling the channel.
-        */
-       cdac = OMAP_DMA_CDAC_REG(lch);
-       if (cdac == 0)
-               cdac = OMAP_DMA_CDAC_REG(lch);
-       return cdac;
-}
-
 static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
 {
        dma_addr_t      end;
@@ -527,7 +505,7 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
        if (cpu_is_omap15xx())
                return 0;
 
-       end = dma_csac(ep->lch);
+       end = omap_get_dma_src_pos(ep->lch);
        if (end == ep->dma_counter)
                return 0;
 
@@ -537,15 +515,11 @@ static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
        return end - start;
 }
 
-#define DMA_DEST_LAST(x) (cpu_is_omap15xx() \
-               ? OMAP_DMA_CSAC_REG(x) /* really: CPC */ \
-               : dma_cdac(x))
-
 static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
 {
        dma_addr_t      end;
 
-       end = DMA_DEST_LAST(ep->lch);
+       end = omap_get_dma_dst_pos(ep->lch);
        if (end == ep->dma_counter)
                return 0;
 
@@ -565,7 +539,7 @@ static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
 
 static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
 {
-       u16             txdma_ctrl;
+       u16             txdma_ctrl, w;
        unsigned        length = req->req.length - req->req.actual;
        const int       sync_mode = cpu_is_omap15xx()
                                ? OMAP_DMA_SYNC_FRAME
@@ -596,14 +570,18 @@ static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
                0, 0);
 
        omap_start_dma(ep->lch);
-       ep->dma_counter = dma_csac(ep->lch);
-       UDC_DMA_IRQ_EN_REG |= UDC_TX_DONE_IE(ep->dma_channel);
-       UDC_TXDMA_REG(ep->dma_channel) = UDC_TXN_START | txdma_ctrl;
+       ep->dma_counter = omap_get_dma_src_pos(ep->lch);
+       w = omap_readw(UDC_DMA_IRQ_EN);
+       w |= UDC_TX_DONE_IE(ep->dma_channel);
+       omap_writew(w, UDC_DMA_IRQ_EN);
+       omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel));
        req->dma_bytes = length;
 }
 
 static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
 {
+       u16 w;
+
        if (status == 0) {
                req->req.actual += req->dma_bytes;
 
@@ -620,7 +598,9 @@ static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
 
        /* tx completion */
        omap_stop_dma(ep->lch);
-       UDC_DMA_IRQ_EN_REG &= ~UDC_TX_DONE_IE(ep->dma_channel);
+       w = omap_readw(UDC_DMA_IRQ_EN);
+       w &= ~UDC_TX_DONE_IE(ep->dma_channel);
+       omap_writew(w, UDC_DMA_IRQ_EN);
        done(ep, req, status);
 }
 
@@ -628,6 +608,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
 {
        unsigned packets = req->req.length - req->req.actual;
        int dma_trigger = 0;
+       u16 w;
 
        if (cpu_is_omap24xx())
                dma_trigger = OMAP24XX_DMA(USB_W2FC_RX0, ep->dma_channel);
@@ -654,12 +635,14 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
        omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
                OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual,
                0, 0);
-       ep->dma_counter = DMA_DEST_LAST(ep->lch);
+       ep->dma_counter = omap_get_dma_dst_pos(ep->lch);
 
-       UDC_RXDMA_REG(ep->dma_channel) = UDC_RXN_STOP | (packets - 1);
-       UDC_DMA_IRQ_EN_REG |= UDC_RX_EOT_IE(ep->dma_channel);
-       UDC_EP_NUM_REG = (ep->bEndpointAddress & 0xf);
-       UDC_CTRL_REG = UDC_SET_FIFO_EN;
+       omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel));
+       w = omap_readw(UDC_DMA_IRQ_EN);
+       w |= UDC_RX_EOT_IE(ep->dma_channel);
+       omap_writew(w, UDC_DMA_IRQ_EN);
+       omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM);
+       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
 
        omap_start_dma(ep->lch);
 }
@@ -667,7 +650,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
 static void
 finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
 {
-       u16     count;
+       u16     count, w;
 
        if (status == 0)
                ep->dma_counter = (u16) (req->req.dma + req->req.actual);
@@ -686,13 +669,15 @@ finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
                return;
 
        /* rx completion */
-       UDC_DMA_IRQ_EN_REG &= ~UDC_RX_EOT_IE(ep->dma_channel);
+       w = omap_readw(UDC_DMA_IRQ_EN);
+       w &= ~UDC_RX_EOT_IE(ep->dma_channel);
+       omap_writew(w, UDC_DMA_IRQ_EN);
        done(ep, req, status);
 }
 
 static void dma_irq(struct omap_udc *udc, u16 irq_src)
 {
-       u16             dman_stat = UDC_DMAN_STAT_REG;
+       u16             dman_stat = omap_readw(UDC_DMAN_STAT);
        struct omap_ep  *ep;
        struct omap_req *req;
 
@@ -706,7 +691,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
                                                struct omap_req, queue);
                        finish_in_dma(ep, req, 0);
                }
-               UDC_IRQ_SRC_REG = UDC_TXN_DONE;
+               omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC);
 
                if (!list_empty (&ep->queue)) {
                        req = container_of(ep->queue.next,
@@ -725,7 +710,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
                                        struct omap_req, queue);
                        finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB);
                }
-               UDC_IRQ_SRC_REG = UDC_RXN_EOT;
+               omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC);
 
                if (!list_empty (&ep->queue)) {
                        req = container_of(ep->queue.next,
@@ -739,7 +724,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
                ep->irqs++;
                /* omap15xx does this unasked... */
                VDBG("%s, RX_CNT irq?\n", ep->ep.name);
-               UDC_IRQ_SRC_REG = UDC_RXN_CNT;
+               omap_writew(UDC_RXN_CNT, UDC_IRQ_SRC);
        }
 }
 
@@ -762,9 +747,9 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
 
        is_in = ep->bEndpointAddress & USB_DIR_IN;
        if (is_in)
-               reg = UDC_TXDMA_CFG_REG;
+               reg = omap_readw(UDC_TXDMA_CFG);
        else
-               reg = UDC_RXDMA_CFG_REG;
+               reg = omap_readw(UDC_RXDMA_CFG);
        reg |= UDC_DMA_REQ;             /* "pulse" activated */
 
        ep->dma_channel = 0;
@@ -792,7 +777,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                status = omap_request_dma(dma_channel,
                        ep->ep.name, dma_error, ep, &ep->lch);
                if (status == 0) {
-                       UDC_TXDMA_CFG_REG = reg;
+                       omap_writew(reg, UDC_TXDMA_CFG);
                        /* EMIFF or SDRC */
                        omap_set_dma_src_burst_mode(ep->lch,
                                                OMAP_DMA_DATA_BURST_4);
@@ -801,7 +786,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                        omap_set_dma_dest_params(ep->lch,
                                OMAP_DMA_PORT_TIPB,
                                OMAP_DMA_AMODE_CONSTANT,
-                               (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
+                               (unsigned long) io_v2p(UDC_DATA_DMA),
                                0, 0);
                }
        } else {
@@ -813,12 +798,12 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
                status = omap_request_dma(dma_channel,
                        ep->ep.name, dma_error, ep, &ep->lch);
                if (status == 0) {
-                       UDC_RXDMA_CFG_REG = reg;
+                       omap_writew(reg, UDC_RXDMA_CFG);
                        /* TIPB */
                        omap_set_dma_src_params(ep->lch,
                                OMAP_DMA_PORT_TIPB,
                                OMAP_DMA_AMODE_CONSTANT,
-                               (unsigned long) io_v2p((u32)&UDC_DATA_DMA_REG),
+                               (unsigned long) io_v2p(UDC_DATA_DMA),
                                0, 0);
                        /* EMIFF or SDRC */
                        omap_set_dma_dest_burst_mode(ep->lch,
@@ -834,7 +819,7 @@ static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
 
                /* channel type P: hw synch (fifo) */
                if (cpu_class_is_omap1() && !cpu_is_omap15xx())
-                       OMAP1_DMA_LCH_CTRL_REG(ep->lch) = 2;
+                       omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P);
        }
 
 just_restart:
@@ -860,7 +845,7 @@ just_restart:
                        (is_in ? write_fifo : read_fifo)(ep, req);
                        deselect_ep();
                        if (!is_in) {
-                               UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                                ep->ackwait = 1 + ep->double_buf;
                        }
                        /* IN: 6 wait states before it'll tx */
@@ -881,7 +866,7 @@ static void dma_channel_release(struct omap_ep *ep)
        else
                req = NULL;
 
-       active = ((1 << 7) & OMAP_DMA_CCR_REG(ep->lch)) != 0;
+       active = omap_get_dma_active_status(ep->lch);
 
        DBG("%s release %s %cxdma%d %p\n", ep->ep.name,
                        active ? "active" : "idle",
@@ -894,23 +879,25 @@ static void dma_channel_release(struct omap_ep *ep)
 
        /* wait till current packet DMA finishes, and fifo empties */
        if (ep->bEndpointAddress & USB_DIR_IN) {
-               UDC_TXDMA_CFG_REG = (UDC_TXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
+               omap_writew((omap_readw(UDC_TXDMA_CFG) & ~mask) | UDC_DMA_REQ,
+                                       UDC_TXDMA_CFG);
 
                if (req) {
                        finish_in_dma(ep, req, -ECONNRESET);
 
                        /* clear FIFO; hosts probably won't empty it */
                        use_ep(ep, UDC_EP_SEL);
-                       UDC_CTRL_REG = UDC_CLR_EP;
+                       omap_writew(UDC_CLR_EP, UDC_CTRL);
                        deselect_ep();
                }
-               while (UDC_TXDMA_CFG_REG & mask)
+               while (omap_readw(UDC_TXDMA_CFG) & mask)
                        udelay(10);
        } else {
-               UDC_RXDMA_CFG_REG = (UDC_RXDMA_CFG_REG & ~mask) | UDC_DMA_REQ;
+               omap_writew((omap_readw(UDC_RXDMA_CFG) & ~mask) | UDC_DMA_REQ,
+                                       UDC_RXDMA_CFG);
 
                /* dma empties the fifo */
-               while (UDC_RXDMA_CFG_REG & mask)
+               while (omap_readw(UDC_RXDMA_CFG) & mask)
                        udelay(10);
                if (req)
                        finish_out_dma(ep, req, -ECONNRESET, 0);
@@ -997,9 +984,13 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
        req->req.actual = 0;
 
        /* maybe kickstart non-iso i/o queues */
-       if (is_iso)
-               UDC_IRQ_EN_REG |= UDC_SOF_IE;
-       else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) {
+       if (is_iso) {
+               u16 w;
+
+               w = omap_readw(UDC_IRQ_EN);
+               w |= UDC_SOF_IE;
+               omap_writew(w, UDC_IRQ_EN);
+       } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) {
                int     is_in;
 
                if (ep->bEndpointAddress == 0) {
@@ -1017,23 +1008,23 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
                                 * requests to non-control endpoints
                                 */
                                if (udc->ep0_set_config) {
-                                       u16     irq_en = UDC_IRQ_EN_REG;
+                                       u16     irq_en = omap_readw(UDC_IRQ_EN);
 
                                        irq_en |= UDC_DS_CHG_IE | UDC_EP0_IE;
                                        if (!udc->ep0_reset_config)
                                                irq_en |= UDC_EPN_RX_IE
                                                        | UDC_EPN_TX_IE;
-                                       UDC_IRQ_EN_REG = irq_en;
+                                       omap_writew(irq_en, UDC_IRQ_EN);
                                }
 
                                /* STATUS for zero length DATA stages is
                                 * always an IN ... even for IN transfers,
                                 * a weird case which seem to stall OMAP.
                                 */
-                               UDC_EP_NUM_REG = (UDC_EP_SEL|UDC_EP_DIR);
-                               UDC_CTRL_REG = UDC_CLR_EP;
-                               UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                               UDC_EP_NUM_REG = UDC_EP_DIR;
+                               omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM);
+                               omap_writew(UDC_CLR_EP, UDC_CTRL);
+                               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                               omap_writew(UDC_EP_DIR, UDC_EP_NUM);
 
                                /* cleanup */
                                udc->ep0_pending = 0;
@@ -1042,11 +1033,11 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
                        /* non-empty DATA stage */
                        } else if (is_in) {
-                               UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR;
+                               omap_writew(UDC_EP_SEL | UDC_EP_DIR, UDC_EP_NUM);
                        } else {
                                if (udc->ep0_setup)
                                        goto irq_wait;
-                               UDC_EP_NUM_REG = UDC_EP_SEL;
+                               omap_writew(UDC_EP_SEL, UDC_EP_NUM);
                        }
                } else {
                        is_in = ep->bEndpointAddress & USB_DIR_IN;
@@ -1062,7 +1053,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
                                req = NULL;
                        deselect_ep();
                        if (!is_in) {
-                               UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                                ep->ackwait = 1 + ep->double_buf;
                        }
                        /* IN: 6 wait states before it'll tx */
@@ -1130,9 +1121,9 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
                else if (value) {
                        if (ep->udc->ep0_set_config) {
                                WARN("error changing config?\n");
-                               UDC_SYSCON2_REG = UDC_CLR_CFG;
+                               omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
                        }
-                       UDC_SYSCON2_REG = UDC_STALL_CMD;
+                       omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
                        ep->udc->ep0_pending = 0;
                        status = 0;
                } else /* NOP */
@@ -1159,8 +1150,8 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
                                channel = 0;
 
                        use_ep(ep, UDC_EP_SEL);
-                       if (UDC_STAT_FLG_REG & UDC_NON_ISO_FIFO_EMPTY) {
-                               UDC_CTRL_REG = UDC_SET_HALT;
+                       if (omap_readw(UDC_STAT_FLG) & UDC_NON_ISO_FIFO_EMPTY) {
+                               omap_writew(UDC_SET_HALT, UDC_CTRL);
                                status = 0;
                        } else
                                status = -EAGAIN;
@@ -1170,10 +1161,10 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value)
                                dma_channel_claim(ep, channel);
                } else {
                        use_ep(ep, 0);
-                       UDC_CTRL_REG = ep->udc->clr_halt;
+                       omap_writew(ep->udc->clr_halt, UDC_CTRL);
                        ep->ackwait = 0;
                        if (!(ep->bEndpointAddress & USB_DIR_IN)) {
-                               UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                                ep->ackwait = 1 + ep->double_buf;
                        }
                }
@@ -1205,7 +1196,7 @@ static struct usb_ep_ops omap_ep_ops = {
 
 static int omap_get_frame(struct usb_gadget *gadget)
 {
-       u16     sof = UDC_SOF_REG;
+       u16     sof = omap_readw(UDC_SOF);
        return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC;
 }
 
@@ -1224,7 +1215,7 @@ static int omap_wakeup(struct usb_gadget *gadget)
                 */
                if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) {
                        DBG("remote wakeup...\n");
-                       UDC_SYSCON2_REG = UDC_RMT_WKP;
+                       omap_writew(UDC_RMT_WKP, UDC_SYSCON2);
                        retval = 0;
                }
 
@@ -1247,12 +1238,12 @@ omap_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
 
        udc = container_of(gadget, struct omap_udc, gadget);
        spin_lock_irqsave(&udc->lock, flags);
-       syscon1 = UDC_SYSCON1_REG;
+       syscon1 = omap_readw(UDC_SYSCON1);
        if (is_selfpowered)
                syscon1 |= UDC_SELF_PWR;
        else
                syscon1 &= ~UDC_SELF_PWR;
-       UDC_SYSCON1_REG = syscon1;
+       omap_writew(syscon1, UDC_SYSCON1);
        spin_unlock_irqrestore(&udc->lock, flags);
 
        return 0;
@@ -1265,18 +1256,36 @@ static int can_pullup(struct omap_udc *udc)
 
 static void pullup_enable(struct omap_udc *udc)
 {
-       UDC_SYSCON1_REG |= UDC_PULLUP_EN;
-       if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx())
-               OTG_CTRL_REG |= OTG_BSESSVLD;
-       UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
+       u16 w;
+
+       w = omap_readw(UDC_SYSCON1);
+       w |= UDC_PULLUP_EN;
+       omap_writew(w, UDC_SYSCON1);
+       if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) {
+               u32 l;
+
+               l = omap_readl(OTG_CTRL);
+               l |= OTG_BSESSVLD;
+               omap_writel(l, OTG_CTRL);
+       }
+       omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN);
 }
 
 static void pullup_disable(struct omap_udc *udc)
 {
-       if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx())
-               OTG_CTRL_REG &= ~OTG_BSESSVLD;
-       UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
-       UDC_SYSCON1_REG &= ~UDC_PULLUP_EN;
+       u16 w;
+
+       if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) {
+               u32 l;
+
+               l = omap_readl(OTG_CTRL);
+               l &= ~OTG_BSESSVLD;
+               omap_writel(l, OTG_CTRL);
+       }
+       omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN);
+       w = omap_readw(UDC_SYSCON1);
+       w &= ~UDC_PULLUP_EN;
+       omap_writew(w, UDC_SYSCON1);
 }
 
 static struct omap_udc *udc;
@@ -1304,6 +1313,7 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active)
 {
        struct omap_udc *udc;
        unsigned long   flags;
+       u32 l;
 
        udc = container_of(gadget, struct omap_udc, gadget);
        spin_lock_irqsave(&udc->lock, flags);
@@ -1311,10 +1321,12 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active)
        udc->vbus_active = (is_active != 0);
        if (cpu_is_omap15xx()) {
                /* "software" detect, ignored if !VBUS_MODE_1510 */
+               l = omap_readl(FUNC_MUX_CTRL_0);
                if (is_active)
-                       FUNC_MUX_CTRL_0_REG |= VBUS_CTRL_1510;
+                       l |= VBUS_CTRL_1510;
                else
-                       FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510;
+                       l &= ~VBUS_CTRL_1510;
+               omap_writel(l, FUNC_MUX_CTRL_0);
        }
        if (udc->dc_clk != NULL && is_active) {
                if (!udc->clk_requested) {
@@ -1384,9 +1396,9 @@ static void nuke(struct omap_ep *ep, int status)
                dma_channel_release(ep);
 
        use_ep(ep, 0);
-       UDC_CTRL_REG = UDC_CLR_EP;
+       omap_writew(UDC_CLR_EP, UDC_CTRL);
        if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC)
-               UDC_CTRL_REG = UDC_SET_HALT;
+               omap_writew(UDC_SET_HALT, UDC_CTRL);
 
        while (!list_empty(&ep->queue)) {
                req = list_entry(ep->queue.next, struct omap_req, queue);
@@ -1414,8 +1426,8 @@ static void update_otg(struct omap_udc *udc)
        if (!gadget_is_otg(&udc->gadget))
                return;
 
-       if (OTG_CTRL_REG & OTG_ID)
-               devstat = UDC_DEVSTAT_REG;
+       if (omap_readl(OTG_CTRL) & OTG_ID)
+               devstat = omap_readw(UDC_DEVSTAT);
        else
                devstat = 0;
 
@@ -1426,9 +1438,14 @@ static void update_otg(struct omap_udc *udc)
        /* Enable HNP early, avoiding races on suspend irq path.
         * ASSUMES OTG state machine B_BUS_REQ input is true.
         */
-       if (udc->gadget.b_hnp_enable)
-               OTG_CTRL_REG = (OTG_CTRL_REG | OTG_B_HNPEN | OTG_B_BUSREQ)
-                               & ~OTG_PULLUP;
+       if (udc->gadget.b_hnp_enable) {
+               u32 l;
+
+               l = omap_readl(OTG_CTRL);
+               l |= OTG_B_HNPEN | OTG_B_BUSREQ;
+               l &= ~OTG_PULLUP;
+               omap_writel(l, OTG_CTRL);
+       }
 }
 
 static void ep0_irq(struct omap_udc *udc, u16 irq_src)
@@ -1446,7 +1463,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
 
                nuke(ep0, 0);
                if (ack) {
-                       UDC_IRQ_SRC_REG = ack;
+                       omap_writew(ack, UDC_IRQ_SRC);
                        irq_src = UDC_SETUP;
                }
        }
@@ -1466,9 +1483,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
        if (irq_src & UDC_EP0_TX) {
                int     stat;
 
-               UDC_IRQ_SRC_REG = UDC_EP0_TX;
-               UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR;
-               stat = UDC_STAT_FLG_REG;
+               omap_writew(UDC_EP0_TX, UDC_IRQ_SRC);
+               omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
+               stat = omap_readw(UDC_STAT_FLG);
                if (stat & UDC_ACK) {
                        if (udc->ep0_in) {
                                /* write next IN packet from response,
@@ -1476,26 +1493,26 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
                                 */
                                if (req)
                                        stat = write_fifo(ep0, req);
-                               UDC_EP_NUM_REG = UDC_EP_DIR;
+                               omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                                if (!req && udc->ep0_pending) {
-                                       UDC_EP_NUM_REG = UDC_EP_SEL;
-                                       UDC_CTRL_REG = UDC_CLR_EP;
-                                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                                       UDC_EP_NUM_REG = 0;
+                                       omap_writew(UDC_EP_SEL, UDC_EP_NUM);
+                                       omap_writew(UDC_CLR_EP, UDC_CTRL);
+                                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                                       omap_writew(0, UDC_EP_NUM);
                                        udc->ep0_pending = 0;
                                } /* else:  6 wait states before it'll tx */
                        } else {
                                /* ack status stage of OUT transfer */
-                               UDC_EP_NUM_REG = UDC_EP_DIR;
+                               omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                                if (req)
                                        done(ep0, req, 0);
                        }
                        req = NULL;
                } else if (stat & UDC_STALL) {
-                       UDC_CTRL_REG = UDC_CLR_HALT;
-                       UDC_EP_NUM_REG = UDC_EP_DIR;
+                       omap_writew(UDC_CLR_HALT, UDC_CTRL);
+                       omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                } else {
-                       UDC_EP_NUM_REG = UDC_EP_DIR;
+                       omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                }
        }
 
@@ -1503,9 +1520,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
        if (irq_src & UDC_EP0_RX) {
                int     stat;
 
-               UDC_IRQ_SRC_REG = UDC_EP0_RX;
-               UDC_EP_NUM_REG = UDC_EP_SEL;
-               stat = UDC_STAT_FLG_REG;
+               omap_writew(UDC_EP0_RX, UDC_IRQ_SRC);
+               omap_writew(UDC_EP_SEL, UDC_EP_NUM);
+               stat = omap_readw(UDC_STAT_FLG);
                if (stat & UDC_ACK) {
                        if (!udc->ep0_in) {
                                stat = 0;
@@ -1513,34 +1530,35 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
                                 * reactiviting the fifo; stall on errors.
                                 */
                                if (!req || (stat = read_fifo(ep0, req)) < 0) {
-                                       UDC_SYSCON2_REG = UDC_STALL_CMD;
+                                       omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
                                        udc->ep0_pending = 0;
                                        stat = 0;
                                } else if (stat == 0)
-                                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                               UDC_EP_NUM_REG = 0;
+                                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                               omap_writew(0, UDC_EP_NUM);
 
                                /* activate status stage */
                                if (stat == 1) {
                                        done(ep0, req, 0);
                                        /* that may have STALLed ep0... */
-                                       UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR;
-                                       UDC_CTRL_REG = UDC_CLR_EP;
-                                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                                       UDC_EP_NUM_REG = UDC_EP_DIR;
+                                       omap_writew(UDC_EP_SEL | UDC_EP_DIR,
+                                                       UDC_EP_NUM);
+                                       omap_writew(UDC_CLR_EP, UDC_CTRL);
+                                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                                       omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                                        udc->ep0_pending = 0;
                                }
                        } else {
                                /* ack status stage of IN transfer */
-                               UDC_EP_NUM_REG = 0;
+                               omap_writew(0, UDC_EP_NUM);
                                if (req)
                                        done(ep0, req, 0);
                        }
                } else if (stat & UDC_STALL) {
-                       UDC_CTRL_REG = UDC_CLR_HALT;
-                       UDC_EP_NUM_REG = 0;
+                       omap_writew(UDC_CLR_HALT, UDC_CTRL);
+                       omap_writew(0, UDC_EP_NUM);
                } else {
-                       UDC_EP_NUM_REG = 0;
+                       omap_writew(0, UDC_EP_NUM);
                }
        }
 
@@ -1555,14 +1573,14 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
 
                /* read the (latest) SETUP message */
                do {
-                       UDC_EP_NUM_REG = UDC_SETUP_SEL;
+                       omap_writew(UDC_SETUP_SEL, UDC_EP_NUM);
                        /* two bytes at a time */
-                       u.word[0] = UDC_DATA_REG;
-                       u.word[1] = UDC_DATA_REG;
-                       u.word[2] = UDC_DATA_REG;
-                       u.word[3] = UDC_DATA_REG;
-                       UDC_EP_NUM_REG = 0;
-               } while (UDC_IRQ_SRC_REG & UDC_SETUP);
+                       u.word[0] = omap_readw(UDC_DATA);
+                       u.word[1] = omap_readw(UDC_DATA);
+                       u.word[2] = omap_readw(UDC_DATA);
+                       u.word[3] = omap_readw(UDC_DATA);
+                       omap_writew(0, UDC_EP_NUM);
+               } while (omap_readw(UDC_IRQ_SRC) & UDC_SETUP);
 
 #define        w_value         le16_to_cpu(u.r.wValue)
 #define        w_index         le16_to_cpu(u.r.wIndex)
@@ -1593,9 +1611,9 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
                         * later if it fails the request.
                         */
                        if (udc->ep0_reset_config)
-                               UDC_SYSCON2_REG = UDC_CLR_CFG;
+                               omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
                        else
-                               UDC_SYSCON2_REG = UDC_DEV_CFG;
+                               omap_writew(UDC_DEV_CFG, UDC_SYSCON2);
                        update_otg(udc);
                        goto delegate;
                case USB_REQ_CLEAR_FEATURE:
@@ -1613,10 +1631,10 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
                                                || !ep->desc)
                                        goto do_stall;
                                use_ep(ep, 0);
-                               UDC_CTRL_REG = udc->clr_halt;
+                               omap_writew(udc->clr_halt, UDC_CTRL);
                                ep->ackwait = 0;
                                if (!(ep->bEndpointAddress & USB_DIR_IN)) {
-                                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                                        ep->ackwait = 1 + ep->double_buf;
                                }
                                /* NOTE:  assumes the host behaves sanely,
@@ -1649,15 +1667,15 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src)
                        }
                        use_ep(ep, 0);
                        /* can't halt if fifo isn't empty... */
-                       UDC_CTRL_REG = UDC_CLR_EP;
-                       UDC_CTRL_REG = UDC_SET_HALT;
+                       omap_writew(UDC_CLR_EP, UDC_CTRL);
+                       omap_writew(UDC_SET_HALT, UDC_CTRL);
                        VDBG("%s halted by host\n", ep->name);
 ep0out_status_stage:
                        status = 0;
-                       UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR;
-                       UDC_CTRL_REG = UDC_CLR_EP;
-                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                       UDC_EP_NUM_REG = UDC_EP_DIR;
+                       omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
+                       omap_writew(UDC_CLR_EP, UDC_CTRL);
+                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                       omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                        udc->ep0_pending = 0;
                        break;
                case USB_REQ_GET_STATUS:
@@ -1694,10 +1712,10 @@ intf_status:
 
 zero_status:
                        /* return two zero bytes */
-                       UDC_EP_NUM_REG = UDC_EP_SEL|UDC_EP_DIR;
-                       UDC_DATA_REG = 0;
-                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
-                       UDC_EP_NUM_REG = UDC_EP_DIR;
+                       omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM);
+                       omap_writew(0, UDC_DATA);
+                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
+                       omap_writew(UDC_EP_DIR, UDC_EP_NUM);
                        status = 0;
                        VDBG("GET_STATUS, interface %d\n", w_index);
                        /* next, status stage */
@@ -1706,8 +1724,8 @@ zero_status:
 delegate:
                        /* activate the ep0out fifo right away */
                        if (!udc->ep0_in && w_length) {
-                               UDC_EP_NUM_REG = 0;
-                               UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                               omap_writew(0, UDC_EP_NUM);
+                               omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                        }
 
                        /* gadget drivers see class/vendor specific requests,
@@ -1748,9 +1766,9 @@ do_stall:
                                if (udc->ep0_reset_config)
                                        WARN("error resetting config?\n");
                                else
-                                       UDC_SYSCON2_REG = UDC_CLR_CFG;
+                                       omap_writew(UDC_CLR_CFG, UDC_SYSCON2);
                        }
-                       UDC_SYSCON2_REG = UDC_STALL_CMD;
+                       omap_writew(UDC_STALL_CMD, UDC_SYSCON2);
                        udc->ep0_pending = 0;
                }
        }
@@ -1764,7 +1782,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
 {
        u16     devstat, change;
 
-       devstat = UDC_DEVSTAT_REG;
+       devstat = omap_readw(UDC_DEVSTAT);
        change = devstat ^ udc->devstat;
        udc->devstat = devstat;
 
@@ -1804,7 +1822,8 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
                                INFO("USB reset done, gadget %s\n",
                                        udc->driver->driver.name);
                                /* ep0 traffic is legal from now on */
-                               UDC_IRQ_EN_REG = UDC_DS_CHG_IE | UDC_EP0_IE;
+                               omap_writew(UDC_DS_CHG_IE | UDC_EP0_IE,
+                                               UDC_IRQ_EN);
                        }
                        change &= ~UDC_USB_RESET;
                }
@@ -1848,7 +1867,7 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
                VDBG("devstat %03x, ignore change %03x\n",
                        devstat,  change);
 
-       UDC_IRQ_SRC_REG = UDC_DS_CHG;
+       omap_writew(UDC_DS_CHG, UDC_IRQ_SRC);
 }
 
 static irqreturn_t omap_udc_irq(int irq, void *_udc)
@@ -1859,7 +1878,7 @@ static irqreturn_t omap_udc_irq(int irq, void *_udc)
        unsigned long   flags;
 
        spin_lock_irqsave(&udc->lock, flags);
-       irq_src = UDC_IRQ_SRC_REG;
+       irq_src = omap_readw(UDC_IRQ_SRC);
 
        /* Device state change (usb ch9 stuff) */
        if (irq_src & UDC_DS_CHG) {
@@ -1882,7 +1901,7 @@ static irqreturn_t omap_udc_irq(int irq, void *_udc)
                irq_src &= ~(UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT);
        }
 
-       irq_src &= ~(UDC_SOF|UDC_EPN_TX|UDC_EPN_RX);
+       irq_src &= ~(UDC_IRQ_SOF | UDC_EPN_TX|UDC_EPN_RX);
        if (irq_src)
                DBG("udc_irq, unhandled %03x\n", irq_src);
        spin_unlock_irqrestore(&udc->lock, flags);
@@ -1903,7 +1922,7 @@ static void pio_out_timer(unsigned long _ep)
        spin_lock_irqsave(&ep->udc->lock, flags);
        if (!list_empty(&ep->queue) && ep->ackwait) {
                use_ep(ep, UDC_EP_SEL);
-               stat_flg = UDC_STAT_FLG_REG;
+               stat_flg = omap_readw(UDC_STAT_FLG);
 
                if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN)
                                || (ep->double_buf && HALF_FULL(stat_flg)))) {
@@ -1913,8 +1932,8 @@ static void pio_out_timer(unsigned long _ep)
                        req = container_of(ep->queue.next,
                                        struct omap_req, queue);
                        (void) read_fifo(ep, req);
-                       UDC_EP_NUM_REG = ep->bEndpointAddress;
-                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                       omap_writew(ep->bEndpointAddress, UDC_EP_NUM);
+                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                        ep->ackwait = 1 + ep->double_buf;
                } else
                        deselect_ep();
@@ -1934,20 +1953,20 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
        unsigned long   flags;
 
        spin_lock_irqsave(&udc->lock, flags);
-       epn_stat = UDC_EPN_STAT_REG;
-       irq_src = UDC_IRQ_SRC_REG;
+       epn_stat = omap_readw(UDC_EPN_STAT);
+       irq_src = omap_readw(UDC_IRQ_SRC);
 
        /* handle OUT first, to avoid some wasteful NAKs */
        if (irq_src & UDC_EPN_RX) {
                epnum = (epn_stat >> 8) & 0x0f;
-               UDC_IRQ_SRC_REG = UDC_EPN_RX;
+               omap_writew(UDC_EPN_RX, UDC_IRQ_SRC);
                status = IRQ_HANDLED;
                ep = &udc->ep[epnum];
                ep->irqs++;
 
-               UDC_EP_NUM_REG = epnum | UDC_EP_SEL;
+               omap_writew(epnum | UDC_EP_SEL, UDC_EP_NUM);
                ep->fnf = 0;
-               if ((UDC_STAT_FLG_REG & UDC_ACK)) {
+               if (omap_readw(UDC_STAT_FLG) & UDC_ACK) {
                        ep->ackwait--;
                        if (!list_empty(&ep->queue)) {
                                int stat;
@@ -1959,15 +1978,15 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
                        }
                }
                /* min 6 clock delay before clearing EP_SEL ... */
-               epn_stat = UDC_EPN_STAT_REG;
-               epn_stat = UDC_EPN_STAT_REG;
-               UDC_EP_NUM_REG = epnum;
+               epn_stat = omap_readw(UDC_EPN_STAT);
+               epn_stat = omap_readw(UDC_EPN_STAT);
+               omap_writew(epnum, UDC_EP_NUM);
 
                /* enabling fifo _after_ clearing ACK, contrary to docs,
                 * reduces lossage; timer still needed though (sigh).
                 */
                if (ep->fnf) {
-                       UDC_CTRL_REG = UDC_SET_FIFO_EN;
+                       omap_writew(UDC_SET_FIFO_EN, UDC_CTRL);
                        ep->ackwait = 1 + ep->double_buf;
                }
                mod_timer(&ep->timer, PIO_OUT_TIMEOUT);
@@ -1976,13 +1995,13 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
        /* then IN transfers */
        else if (irq_src & UDC_EPN_TX) {
                epnum = epn_stat & 0x0f;
-               UDC_IRQ_SRC_REG = UDC_EPN_TX;
+               omap_writew(UDC_EPN_TX, UDC_IRQ_SRC);
                status = IRQ_HANDLED;
                ep = &udc->ep[16 + epnum];
                ep->irqs++;
 
-               UDC_EP_NUM_REG = epnum | UDC_EP_DIR | UDC_EP_SEL;
-               if ((UDC_STAT_FLG_REG & UDC_ACK)) {
+               omap_writew(epnum | UDC_EP_DIR | UDC_EP_SEL, UDC_EP_NUM);
+               if (omap_readw(UDC_STAT_FLG) & UDC_ACK) {
                        ep->ackwait = 0;
                        if (!list_empty(&ep->queue)) {
                                req = container_of(ep->queue.next,
@@ -1991,9 +2010,9 @@ static irqreturn_t omap_udc_pio_irq(int irq, void *_dev)
                        }
                }
                /* min 6 clock delay before clearing EP_SEL ... */
-               epn_stat = UDC_EPN_STAT_REG;
-               epn_stat = UDC_EPN_STAT_REG;
-               UDC_EP_NUM_REG = epnum | UDC_EP_DIR;
+               epn_stat = omap_readw(UDC_EPN_STAT);
+               epn_stat = omap_readw(UDC_EPN_STAT);
+               omap_writew(epnum | UDC_EP_DIR, UDC_EP_NUM);
                /* then 6 clocks before it'd tx */
        }
 
@@ -2021,7 +2040,7 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
                req = list_entry(ep->queue.next, struct omap_req, queue);
 
                use_ep(ep, UDC_EP_SEL);
-               stat = UDC_STAT_FLG_REG;
+               stat = omap_readw(UDC_STAT_FLG);
 
                /* NOTE: like the other controller drivers, this isn't
                 * currently reporting lost or damaged frames.
@@ -2053,9 +2072,14 @@ static irqreturn_t omap_udc_iso_irq(int irq, void *_dev)
                if (!list_empty(&ep->queue))
                        pending = 1;
        }
-       if (!pending)
-               UDC_IRQ_EN_REG &= ~UDC_SOF_IE;
-       UDC_IRQ_SRC_REG = UDC_SOF;
+       if (!pending) {
+               u16 w;
+
+               w = omap_readw(UDC_IRQ_EN);
+               w &= ~UDC_SOF_IE;
+               omap_writew(w, UDC_IRQ_EN);
+       }
+       omap_writew(UDC_IRQ_SOF, UDC_IRQ_SRC);
 
        spin_unlock_irqrestore(&udc->lock, flags);
        return IRQ_HANDLED;
@@ -2104,7 +2128,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
                if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
                        continue;
                use_ep(ep, 0);
-               UDC_CTRL_REG = UDC_SET_HALT;
+               omap_writew(UDC_SET_HALT, UDC_CTRL);
        }
        udc->ep0_pending = 0;
        udc->ep[0].irqs = 0;
@@ -2128,7 +2152,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
        }
        DBG("bound to driver %s\n", driver->driver.name);
 
-       UDC_IRQ_SRC_REG = UDC_IRQ_SRC_MASK;
+       omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
 
        /* connect to bus through transceiver */
        if (udc->transceiver) {
@@ -2225,7 +2249,7 @@ static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
        else
                buf[0] = 0;
 
-       stat_flg = UDC_STAT_FLG_REG;
+       stat_flg = omap_readw(UDC_STAT_FLG);
        seq_printf(s,
                "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n",
                ep->name, buf,
@@ -2292,11 +2316,11 @@ static int proc_otg_show(struct seq_file *s)
                trans = CONTROL_DEVCONF_REG;
        } else {
                ctrl_name = "tranceiver_ctrl";
-               trans = USB_TRANSCEIVER_CTRL_REG;
+               trans = omap_readw(USB_TRANSCEIVER_CTRL);
        }
        seq_printf(s, "\nOTG rev %d.%d, %s %05x\n",
                tmp >> 4, tmp & 0xf, ctrl_name, trans);
-       tmp = OTG_SYSCON_1_REG;
+       tmp = omap_readw(OTG_SYSCON_1);
        seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s,"
                        FOURBITS "\n", tmp,
                trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R),
@@ -2308,7 +2332,7 @@ static int proc_otg_show(struct seq_file *s)
                (tmp & HST_IDLE_EN) ? " !host" : "",
                (tmp & DEV_IDLE_EN) ? " !dev" : "",
                (tmp & OTG_RESET_DONE) ? " reset_done" : " reset_active");
-       tmp = OTG_SYSCON_2_REG;
+       tmp = omap_readl(OTG_SYSCON_2);
        seq_printf(s, "otg_syscon2 %08x%s" EIGHTBITS
                        " b_ase_brst=%d hmc=%d\n", tmp,
                (tmp & OTG_EN) ? " otg_en" : "",
@@ -2323,7 +2347,7 @@ static int proc_otg_show(struct seq_file *s)
                (tmp & HMC_TLLATTACH) ? " tllattach" : "",
                B_ASE_BRST(tmp),
                OTG_HMC(tmp));
-       tmp = OTG_CTRL_REG;
+       tmp = omap_readl(OTG_CTRL);
        seq_printf(s, "otg_ctrl    %06x" EIGHTBITS EIGHTBITS "%s\n", tmp,
                (tmp & OTG_ASESSVLD) ? " asess" : "",
                (tmp & OTG_BSESSEND) ? " bsess_end" : "",
@@ -2343,13 +2367,13 @@ static int proc_otg_show(struct seq_file *s)
                (tmp & OTG_PU_VBUS) ? " pu_vb" : "",
                (tmp & OTG_PU_ID) ? " pu_id" : ""
                );
-       tmp = OTG_IRQ_EN_REG;
+       tmp = omap_readw(OTG_IRQ_EN);
        seq_printf(s, "otg_irq_en  %04x" "\n", tmp);
-       tmp = OTG_IRQ_SRC_REG;
+       tmp = omap_readw(OTG_IRQ_SRC);
        seq_printf(s, "otg_irq_src %04x" "\n", tmp);
-       tmp = OTG_OUTCTRL_REG;
+       tmp = omap_readw(OTG_OUTCTRL);
        seq_printf(s, "otg_outctrl %04x" "\n", tmp);
-       tmp = OTG_TEST_REG;
+       tmp = omap_readw(OTG_TEST);
        seq_printf(s, "otg_test    %04x" "\n", tmp);
        return 0;
 }
@@ -2370,7 +2394,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
                driver_desc,
                use_dma ?  " (dma)" : "");
 
-       tmp = UDC_REV_REG & 0xff;
+       tmp = omap_readw(UDC_REV) & 0xff;
        seq_printf(s,
                "UDC rev %d.%d, fifo mode %d, gadget %s\n"
                "hmc %d, transceiver %s\n",
@@ -2384,16 +2408,16 @@ static int proc_udc_show(struct seq_file *s, void *_)
                                ? "external" : "(none)"));
        if (cpu_class_is_omap1()) {
                seq_printf(s, "ULPD control %04x req %04x status %04x\n",
-                       __REG16(ULPD_CLOCK_CTRL),
-                       __REG16(ULPD_SOFT_REQ),
-                       __REG16(ULPD_STATUS_REQ));
+                       omap_readw(ULPD_CLOCK_CTRL),
+                       omap_readw(ULPD_SOFT_REQ),
+                       omap_readw(ULPD_STATUS_REQ));
        }
 
        /* OTG controller registers */
        if (!cpu_is_omap15xx())
                proc_otg_show(s);
 
-       tmp = UDC_SYSCON1_REG;
+       tmp = omap_readw(UDC_SYSCON1);
        seq_printf(s, "\nsyscon1     %04x" EIGHTBITS "\n", tmp,
                (tmp & UDC_CFG_LOCK) ? " cfg_lock" : "",
                (tmp & UDC_DATA_ENDIAN) ? " data_endian" : "",
@@ -2412,7 +2436,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
                return 0;
        }
 
-       tmp = UDC_DEVSTAT_REG;
+       tmp = omap_readw(UDC_DEVSTAT);
        seq_printf(s, "devstat     %04x" EIGHTBITS "%s%s\n", tmp,
                (tmp & UDC_B_HNP_ENABLE) ? " b_hnp" : "",
                (tmp & UDC_A_HNP_SUPPORT) ? " a_hnp" : "",
@@ -2424,20 +2448,20 @@ static int proc_udc_show(struct seq_file *s, void *_)
                (tmp & UDC_ADD) ? " ADD" : "",
                (tmp & UDC_DEF) ? " DEF" : "",
                (tmp & UDC_ATT) ? " ATT" : "");
-       seq_printf(s, "sof         %04x\n", UDC_SOF_REG);
-       tmp = UDC_IRQ_EN_REG;
+       seq_printf(s, "sof         %04x\n", omap_readw(UDC_SOF));
+       tmp = omap_readw(UDC_IRQ_EN);
        seq_printf(s, "irq_en      %04x" FOURBITS "%s\n", tmp,
                (tmp & UDC_SOF_IE) ? " sof" : "",
                (tmp & UDC_EPN_RX_IE) ? " epn_rx" : "",
                (tmp & UDC_EPN_TX_IE) ? " epn_tx" : "",
                (tmp & UDC_DS_CHG_IE) ? " ds_chg" : "",
                (tmp & UDC_EP0_IE) ? " ep0" : "");
-       tmp = UDC_IRQ_SRC_REG;
+       tmp = omap_readw(UDC_IRQ_SRC);
        seq_printf(s, "irq_src     %04x" EIGHTBITS "%s%s\n", tmp,
                (tmp & UDC_TXN_DONE) ? " txn_done" : "",
                (tmp & UDC_RXN_CNT) ? " rxn_cnt" : "",
                (tmp & UDC_RXN_EOT) ? " rxn_eot" : "",
-               (tmp & UDC_SOF) ? " sof" : "",
+               (tmp & UDC_IRQ_SOF) ? " sof" : "",
                (tmp & UDC_EPN_RX) ? " epn_rx" : "",
                (tmp & UDC_EPN_TX) ? " epn_tx" : "",
                (tmp & UDC_DS_CHG) ? " ds_chg" : "",
@@ -2447,7 +2471,7 @@ static int proc_udc_show(struct seq_file *s, void *_)
        if (use_dma) {
                unsigned i;
 
-               tmp = UDC_DMA_IRQ_EN_REG;
+               tmp = omap_readw(UDC_DMA_IRQ_EN);
                seq_printf(s, "dma_irq_en  %04x%s" EIGHTBITS "\n", tmp,
                        (tmp & UDC_TX_DONE_IE(3)) ? " tx2_done" : "",
                        (tmp & UDC_RX_CNT_IE(3)) ? " rx2_cnt" : "",
@@ -2461,29 +2485,29 @@ static int proc_udc_show(struct seq_file *s, void *_)
                        (tmp & UDC_RX_CNT_IE(1)) ? " rx0_cnt" : "",
                        (tmp & UDC_RX_EOT_IE(1)) ? " rx0_eot" : "");
 
-               tmp = UDC_RXDMA_CFG_REG;
+               tmp = omap_readw(UDC_RXDMA_CFG);
                seq_printf(s, "rxdma_cfg   %04x\n", tmp);
                if (tmp) {
                        for (i = 0; i < 3; i++) {
                                if ((tmp & (0x0f << (i * 4))) == 0)
                                        continue;
                                seq_printf(s, "rxdma[%d]    %04x\n", i,
-                                               UDC_RXDMA_REG(i + 1));
+                                               omap_readw(UDC_RXDMA(i + 1)));
                        }
                }
-               tmp = UDC_TXDMA_CFG_REG;
+               tmp = omap_readw(UDC_TXDMA_CFG);
                seq_printf(s, "txdma_cfg   %04x\n", tmp);
                if (tmp) {
                        for (i = 0; i < 3; i++) {
                                if (!(tmp & (0x0f << (i * 4))))
                                        continue;
                                seq_printf(s, "txdma[%d]    %04x\n", i,
-                                               UDC_TXDMA_REG(i + 1));
+                                               omap_readw(UDC_TXDMA(i + 1)));
                        }
                }
        }
 
-       tmp = UDC_DEVSTAT_REG;
+       tmp = omap_readw(UDC_DEVSTAT);
        if (tmp & UDC_ATT) {
                proc_ep_show(s, &udc->ep[0]);
                if (tmp & UDC_ADD) {
@@ -2535,7 +2559,7 @@ static inline void remove_proc_file(void) {}
  * buffer space among the endpoints we'll be operating.
  *
  * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when
- * UDC_SYSCON_1_REG.CFG_LOCK is set can now work.  We won't use that
+ * UDC_SYSCON_1.CFG_LOCK is set can now work.  We won't use that
  * capability yet though.
  */
 static unsigned __init
@@ -2597,9 +2621,9 @@ omap_ep_setup(char *name, u8 addr, u8 type,
                name, addr, epn_rxtx, maxp, dbuf ? "x2" : "", buf);
 
        if (addr & USB_DIR_IN)
-               UDC_EP_TX_REG(addr & 0xf) = epn_rxtx;
+               omap_writew(epn_rxtx, UDC_EP_TX(addr & 0xf));
        else
-               UDC_EP_RX_REG(addr) = epn_rxtx;
+               omap_writew(epn_rxtx, UDC_EP_RX(addr));
 
        /* next endpoint's buffer starts after this one's */
        buf += maxp;
@@ -2638,15 +2662,15 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
        unsigned        tmp, buf;
 
        /* abolish any previous hardware state */
-       UDC_SYSCON1_REG = 0;
-       UDC_IRQ_EN_REG = 0;
-       UDC_IRQ_SRC_REG = UDC_IRQ_SRC_MASK;
-       UDC_DMA_IRQ_EN_REG = 0;
-       UDC_RXDMA_CFG_REG = 0;
-       UDC_TXDMA_CFG_REG = 0;
+       omap_writew(0, UDC_SYSCON1);
+       omap_writew(0, UDC_IRQ_EN);
+       omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC);
+       omap_writew(0, UDC_DMA_IRQ_EN);
+       omap_writew(0, UDC_RXDMA_CFG);
+       omap_writew(0, UDC_TXDMA_CFG);
 
        /* UDC_PULLUP_EN gates the chip clock */
-       // OTG_SYSCON_1_REG |= DEV_IDLE_EN;
+       // OTG_SYSCON_1 |= DEV_IDLE_EN;
 
        udc = kzalloc(sizeof(*udc), GFP_KERNEL);
        if (!udc)
@@ -2677,8 +2701,8 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
 
        /* initially disable all non-ep0 endpoints */
        for (tmp = 1; tmp < 15; tmp++) {
-               UDC_EP_RX_REG(tmp) = 0;
-               UDC_EP_TX_REG(tmp) = 0;
+               omap_writew(0, UDC_EP_RX(tmp));
+               omap_writew(0, UDC_EP_TX(tmp));
        }
 
 #define OMAP_BULK_EP(name,addr) \
@@ -2763,7 +2787,7 @@ omap_udc_setup(struct platform_device *odev, struct otg_transceiver *xceiv)
                ERR("unsupported fifo_mode #%d\n", fifo_mode);
                return -ENODEV;
        }
-       UDC_SYSCON1_REG = UDC_CFG_LOCK|UDC_SELF_PWR;
+       omap_writew(UDC_CFG_LOCK|UDC_SELF_PWR, UDC_SYSCON1);
        INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf);
        return 0;
 }
@@ -2807,7 +2831,7 @@ static int __init omap_udc_probe(struct platform_device *pdev)
        }
 
        INFO("OMAP UDC rev %d.%d%s\n",
-               UDC_REV_REG >> 4, UDC_REV_REG & 0xf,
+               omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf,
                config->otg ? ", Mini-AB" : "");
 
        /* use the mode given to us by board init code */
@@ -2822,12 +2846,12 @@ static int __init omap_udc_probe(struct platform_device *pdev)
                         * know when to turn PULLUP_EN on/off; and that
                         * means we always "need" the 48MHz clock.
                         */
-                       u32 tmp = FUNC_MUX_CTRL_0_REG;
-
-                       FUNC_MUX_CTRL_0_REG &= ~VBUS_CTRL_1510;
+                       u32 tmp = omap_readl(FUNC_MUX_CTRL_0);
+                       tmp &= ~VBUS_CTRL_1510;
+                       omap_writel(tmp, FUNC_MUX_CTRL_0);
                        tmp |= VBUS_MODE_1510;
                        tmp &= ~VBUS_CTRL_1510;
-                       FUNC_MUX_CTRL_0_REG = tmp;
+                       omap_writel(tmp, FUNC_MUX_CTRL_0);
                }
        } else {
                /* The transceiver may package some GPIO logic or handle
@@ -2907,7 +2931,7 @@ known:
 #endif
 
        /* starting with omap1710 es2.0, clear toggle is a separate bit */
-       if (UDC_REV_REG >= 0x61)
+       if (omap_readw(UDC_REV) >= 0x61)
                udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE;
        else
                udc->clr_halt = UDC_RESET_EP;
@@ -3005,7 +3029,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
                put_device(udc->transceiver->dev);
                udc->transceiver = NULL;
        }
-       UDC_SYSCON1_REG = 0;
+       omap_writew(0, UDC_SYSCON1);
 
        remove_proc_file();
 
@@ -3036,7 +3060,7 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
  *
  * REVISIT we should probably reject suspend requests when there's a host
  * session active, rather than disconnecting, at least on boards that can
- * report VBUS irqs (UDC_DEVSTAT_REG.UDC_ATT).  And in any case, we need to
+ * report VBUS irqs (UDC_DEVSTAT.UDC_ATT).  And in any case, we need to
  * make host resumes and VBUS detection trigger OMAP wakeup events; that
  * may involve talking to an external transceiver (e.g. isp1301).
  */
@@ -3045,7 +3069,7 @@ static int omap_udc_suspend(struct platform_device *dev, pm_message_t message)
 {
        u32     devstat;
 
-       devstat = UDC_DEVSTAT_REG;
+       devstat = omap_readw(UDC_DEVSTAT);
 
        /* we're requesting 48 MHz clock if the pullup is enabled
         * (== we're attached to the host) and we're not suspended,
index c6b9cbc..8522bbb 100644 (file)
@@ -8,23 +8,22 @@
 /*
  * USB device/endpoint management registers
  */
-#define UDC_REG(offset)              __REG16(UDC_BASE + (offset))
 
-#define        UDC_REV_REG                     UDC_REG(0x0)    /* Revision */
-#define        UDC_EP_NUM_REG                  UDC_REG(0x4)    /* Which endpoint */
+#define        UDC_REV                         (UDC_BASE + 0x0)        /* Revision */
+#define        UDC_EP_NUM                      (UDC_BASE + 0x4)        /* Which endpoint */
 #      define  UDC_SETUP_SEL           (1 << 6)
 #      define  UDC_EP_SEL              (1 << 5)
 #      define  UDC_EP_DIR              (1 << 4)
        /* low 4 bits for endpoint number */
-#define        UDC_DATA_REG                    UDC_REG(0x08)   /* Endpoint FIFO */
-#define        UDC_CTRL_REG                    UDC_REG(0x0C)   /* Endpoint control */
+#define        UDC_DATA                        (UDC_BASE + 0x08)       /* Endpoint FIFO */
+#define        UDC_CTRL                        (UDC_BASE + 0x0C)       /* Endpoint control */
 #      define  UDC_CLR_HALT            (1 << 7)
 #      define  UDC_SET_HALT            (1 << 6)
 #      define  UDC_CLRDATA_TOGGLE      (1 << 3)
 #      define  UDC_SET_FIFO_EN         (1 << 2)
 #      define  UDC_CLR_EP              (1 << 1)
 #      define  UDC_RESET_EP            (1 << 0)
-#define        UDC_STAT_FLG_REG                UDC_REG(0x10)   /* Endpoint status */
+#define        UDC_STAT_FLG                    (UDC_BASE + 0x10)       /* Endpoint status */
 #      define  UDC_NO_RXPACKET         (1 << 15)
 #      define  UDC_MISS_IN             (1 << 14)
 #      define  UDC_DATA_FLUSH          (1 << 13)
@@ -38,8 +37,8 @@
 #      define  UDC_FIFO_EN             (1 << 2)
 #      define  UDC_NON_ISO_FIFO_EMPTY  (1 << 1)
 #      define  UDC_NON_ISO_FIFO_FULL   (1 << 0)
-#define        UDC_RXFSTAT_REG                 UDC_REG(0x14)   /* OUT bytecount */
-#define        UDC_SYSCON1_REG                 UDC_REG(0x18)   /* System config 1 */
+#define        UDC_RXFSTAT                     (UDC_BASE + 0x14)       /* OUT bytecount */
+#define        UDC_SYSCON1                     (UDC_BASE + 0x18)       /* System config 1 */
 #      define  UDC_CFG_LOCK            (1 << 8)
 #      define  UDC_DATA_ENDIAN         (1 << 7)
 #      define  UDC_DMA_ENDIAN          (1 << 6)
 #      define  UDC_SELF_PWR            (1 << 2)
 #      define  UDC_SOFF_DIS            (1 << 1)
 #      define  UDC_PULLUP_EN           (1 << 0)
-#define        UDC_SYSCON2_REG                 UDC_REG(0x1C)   /* System config 2 */
+#define        UDC_SYSCON2                     (UDC_BASE + 0x1C)       /* System config 2 */
 #      define  UDC_RMT_WKP             (1 << 6)
 #      define  UDC_STALL_CMD           (1 << 5)
 #      define  UDC_DEV_CFG             (1 << 3)
 #      define  UDC_CLR_CFG             (1 << 2)
-#define        UDC_DEVSTAT_REG                 UDC_REG(0x20)   /* Device status */
+#define        UDC_DEVSTAT                     (UDC_BASE + 0x20)       /* Device status */
 #      define  UDC_B_HNP_ENABLE        (1 << 9)
 #      define  UDC_A_HNP_SUPPORT       (1 << 8)
 #      define  UDC_A_ALT_HNP_SUPPORT   (1 << 7)
 #      define  UDC_ADD                 (1 << 2)
 #      define  UDC_DEF                 (1 << 1)
 #      define  UDC_ATT                 (1 << 0)
-#define        UDC_SOF_REG                     UDC_REG(0x24)   /* Start of frame */
+#define        UDC_SOF                         (UDC_BASE + 0x24)       /* Start of frame */
 #      define  UDC_FT_LOCK             (1 << 12)
 #      define  UDC_TS_OK               (1 << 11)
 #      define  UDC_TS                  0x03ff
-#define        UDC_IRQ_EN_REG                  UDC_REG(0x28)   /* Interrupt enable */
+#define        UDC_IRQ_EN                      (UDC_BASE + 0x28)       /* Interrupt enable */
 #      define  UDC_SOF_IE              (1 << 7)
 #      define  UDC_EPN_RX_IE           (1 << 5)
 #      define  UDC_EPN_TX_IE           (1 << 4)
 #      define  UDC_DS_CHG_IE           (1 << 3)
 #      define  UDC_EP0_IE              (1 << 0)
-#define        UDC_DMA_IRQ_EN_REG              UDC_REG(0x2C)   /* DMA irq enable */
+#define        UDC_DMA_IRQ_EN                  (UDC_BASE + 0x2C)       /* DMA irq enable */
        /* rx/tx dma channels numbered 1-3 not 0-2 */
 #      define  UDC_TX_DONE_IE(n)       (1 << (4 * (n) - 2))
 #      define  UDC_RX_CNT_IE(n)        (1 << (4 * (n) - 3))
 #      define  UDC_RX_EOT_IE(n)        (1 << (4 * (n) - 4))
-#define        UDC_IRQ_SRC_REG                 UDC_REG(0x30)   /* Interrupt source */
+#define        UDC_IRQ_SRC                     (UDC_BASE + 0x30)       /* Interrupt source */
 #      define  UDC_TXN_DONE            (1 << 10)
 #      define  UDC_RXN_CNT             (1 << 9)
 #      define  UDC_RXN_EOT             (1 << 8)
-#      define  UDC_SOF                 (1 << 7)
+#      define  UDC_IRQ_SOF             (1 << 7)
 #      define  UDC_EPN_RX              (1 << 5)
 #      define  UDC_EPN_TX              (1 << 4)
 #      define  UDC_DS_CHG              (1 << 3)
 #      define  UDC_EP0_RX              (1 << 1)
 #      define  UDC_EP0_TX              (1 << 0)
 #      define  UDC_IRQ_SRC_MASK        0x7bf
-#define        UDC_EPN_STAT_REG                UDC_REG(0x34)   /* EP irq status */
-#define        UDC_DMAN_STAT_REG               UDC_REG(0x38)   /* DMA irq status */
+#define        UDC_EPN_STAT                    (UDC_BASE + 0x34)       /* EP irq status */
+#define        UDC_DMAN_STAT                   (UDC_BASE + 0x38)       /* DMA irq status */
 #      define  UDC_DMA_RX_SB           (1 << 12)
 #      define  UDC_DMA_RX_SRC(x)       (((x)>>8) & 0xf)
 #      define  UDC_DMA_TX_SRC(x)       (((x)>>0) & 0xf)
 
 
 /* DMA configuration registers:  up to three channels in each direction.  */
-#define        UDC_RXDMA_CFG_REG               UDC_REG(0x40)   /* 3 eps for RX DMA */
+#define        UDC_RXDMA_CFG                   (UDC_BASE + 0x40)       /* 3 eps for RX DMA */
 #      define  UDC_DMA_REQ             (1 << 12)
-#define        UDC_TXDMA_CFG_REG               UDC_REG(0x44)   /* 3 eps for TX DMA */
-#define        UDC_DATA_DMA_REG                UDC_REG(0x48)   /* rx/tx fifo addr */
+#define        UDC_TXDMA_CFG                   (UDC_BASE + 0x44)       /* 3 eps for TX DMA */
+#define        UDC_DATA_DMA                    (UDC_BASE + 0x48)       /* rx/tx fifo addr */
 
 /* rx/tx dma control, numbering channels 1-3 not 0-2 */
-#define        UDC_TXDMA_REG(chan)             UDC_REG(0x50 - 4 + 4 * (chan))
+#define        UDC_TXDMA(chan)                 (UDC_BASE + 0x50 - 4 + 4 * (chan))
 #      define UDC_TXN_EOT              (1 << 15)       /* bytes vs packets */
 #      define UDC_TXN_START            (1 << 14)       /* start transfer */
 #      define UDC_TXN_TSC              0x03ff          /* units in xfer */
-#define        UDC_RXDMA_REG(chan)             UDC_REG(0x60 - 4 + 4 * (chan))
+#define        UDC_RXDMA(chan)                 (UDC_BASE + 0x60 - 4 + 4 * (chan))
 #      define UDC_RXN_STOP             (1 << 15)       /* enable EOT irq */
 #      define UDC_RXN_TC               0x00ff          /* packets in xfer */
 
 
 /*
  * Endpoint configuration registers (used before CFG_LOCK is set)
- * UDC_EP_TX_REG(0) is unused
+ * UDC_EP_TX(0) is unused
  */
-#define        UDC_EP_RX_REG(endpoint)         UDC_REG(0x80 + (endpoint)*4)
+#define        UDC_EP_RX(endpoint)             (UDC_BASE + 0x80 + (endpoint)*4)
 #      define  UDC_EPN_RX_VALID        (1 << 15)
 #      define  UDC_EPN_RX_DB           (1 << 14)
        /* buffer size in bits 13, 12 */
 #      define  UDC_EPN_RX_ISO          (1 << 11)
        /* buffer pointer in low 11 bits */
-#define        UDC_EP_TX_REG(endpoint)         UDC_REG(0xc0 + (endpoint)*4)
-       /* same bitfields as in RX_REG */
+#define        UDC_EP_TX(endpoint)             (UDC_BASE + 0xc0 + (endpoint)*4)
+       /* same bitfields as in RX */
 
 /*-------------------------------------------------------------------------*/
 
@@ -195,14 +194,14 @@ struct omap_udc {
 
 /*-------------------------------------------------------------------------*/
 
-#define        MOD_CONF_CTRL_0_REG     __REG32(MOD_CONF_CTRL_0)
-#define        VBUS_W2FC_1510          (1 << 17)       /* 0 gpio0, 1 dvdd2 pin */
+/* MOD_CONF_CTRL_0 */
+#define VBUS_W2FC_1510         (1 << 17)       /* 0 gpio0, 1 dvdd2 pin */
 
-#define        FUNC_MUX_CTRL_0_REG     __REG32(FUNC_MUX_CTRL_0)
+/* FUNC_MUX_CTRL_0 */
 #define        VBUS_CTRL_1510          (1 << 19)       /* 1 connected (software) */
 #define        VBUS_MODE_1510          (1 << 18)       /* 0 hardware, 1 software */
 
-#define        HMC_1510        ((MOD_CONF_CTRL_0_REG >> 1) & 0x3f)
-#define        HMC_1610        (OTG_SYSCON_2_REG & 0x3f)
+#define        HMC_1510        ((omap_readl(MOD_CONF_CTRL_0) >> 1) & 0x3f)
+#define        HMC_1610        (omap_readl(OTG_SYSCON_2) & 0x3f)
 #define        HMC             (cpu_is_omap15xx() ? HMC_1510 : HMC_1610)
 
index 76be75e..ec8f2eb 100644 (file)
@@ -462,6 +462,7 @@ printer_open(struct inode *inode, struct file *fd)
        unsigned long           flags;
        int                     ret = -EBUSY;
 
+       lock_kernel();
        dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev);
 
        spin_lock_irqsave(&dev->lock, flags);
@@ -477,7 +478,7 @@ printer_open(struct inode *inode, struct file *fd)
        spin_unlock_irqrestore(&dev->lock, flags);
 
        DBG(dev, "printer_open returned %x\n", ret);
-
+       unlock_kernel();
        return ret;
 }
 
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
new file mode 100644 (file)
index 0000000..031dceb
--- /dev/null
@@ -0,0 +1,2388 @@
+/*
+ * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
+ *
+ * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
+ * Copyright (C) 2003 Robert Schwebel, Pengutronix
+ * Copyright (C) 2003 Benedikt Spranger, Pengutronix
+ * Copyright (C) 2003 David Brownell
+ * Copyright (C) 2003 Joshua Wise
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+/* #define VERBOSE_DEBUG */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/ioport.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/timer.h>
+#include <linux/list.h>
+#include <linux/interrupt.h>
+#include <linux/mm.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+#include <linux/io.h>
+
+#include <asm/byteorder.h>
+#include <asm/dma.h>
+#include <asm/gpio.h>
+#include <asm/system.h>
+#include <asm/mach-types.h>
+#include <asm/unaligned.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+
+/*
+ * This driver is PXA25x only.  Grab the right register definitions.
+ */
+#ifdef CONFIG_ARCH_PXA
+#include <asm/arch/pxa25x-udc.h>
+#endif
+
+#include <asm/mach/udc_pxa2xx.h>
+
+
+/*
+ * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
+ * series processors.  The UDC for the IXP 4xx series is very similar.
+ * There are fifteen endpoints, in addition to ep0.
+ *
+ * Such controller drivers work with a gadget driver.  The gadget driver
+ * returns descriptors, implements configuration and data protocols used
+ * by the host to interact with this device, and allocates endpoints to
+ * the different protocol interfaces.  The controller driver virtualizes
+ * usb hardware so that the gadget drivers will be more portable.
+ *
+ * This UDC hardware wants to implement a bit too much USB protocol, so
+ * it constrains the sorts of USB configuration change events that work.
+ * The errata for these chips are misleading; some "fixed" bugs from
+ * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
+ *
+ * Note that the UDC hardware supports DMA (except on IXP) but that's
+ * not used here.  IN-DMA (to host) is simple enough, when the data is
+ * suitably aligned (16 bytes) ... the network stack doesn't do that,
+ * other software can.  OUT-DMA is buggy in most chip versions, as well
+ * as poorly designed (data toggle not automatic).  So this driver won't
+ * bother using DMA.  (Mostly-working IN-DMA support was available in
+ * kernels before 2.6.23, but was never enabled or well tested.)
+ */
+
+#define        DRIVER_VERSION  "30-June-2007"
+#define        DRIVER_DESC     "PXA 25x USB Device Controller driver"
+
+
+static const char driver_name [] = "pxa25x_udc";
+
+static const char ep0name [] = "ep0";
+
+
+#ifdef CONFIG_ARCH_IXP4XX
+
+/* cpu-specific register addresses are compiled in to this code */
+#ifdef CONFIG_ARCH_PXA
+#error "Can't configure both IXP and PXA"
+#endif
+
+/* IXP doesn't yet support <linux/clk.h> */
+#define clk_get(dev,name)      NULL
+#define clk_enable(clk)                do { } while (0)
+#define clk_disable(clk)       do { } while (0)
+#define clk_put(clk)           do { } while (0)
+
+#endif
+
+#include "pxa25x_udc.h"
+
+
+#ifdef CONFIG_USB_PXA25X_SMALL
+#define SIZE_STR       " (small)"
+#else
+#define SIZE_STR       ""
+#endif
+
+/* ---------------------------------------------------------------------------
+ *     endpoint related parts of the api to the usb controller hardware,
+ *     used by gadget driver; and the inner talker-to-hardware core.
+ * ---------------------------------------------------------------------------
+ */
+
+static void pxa25x_ep_fifo_flush (struct usb_ep *ep);
+static void nuke (struct pxa25x_ep *, int status);
+
+/* one GPIO should be used to detect VBUS from the host */
+static int is_vbus_present(void)
+{
+       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
+
+       if (mach->gpio_vbus) {
+               int value = gpio_get_value(mach->gpio_vbus);
+               return mach->gpio_vbus_inverted ? !value : value;
+       }
+       if (mach->udc_is_connected)
+               return mach->udc_is_connected();
+       return 1;
+}
+
+/* one GPIO should control a D+ pullup, so host sees this device (or not) */
+static void pullup_off(void)
+{
+       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
+
+       if (mach->gpio_pullup)
+               gpio_set_value(mach->gpio_pullup, 0);
+       else if (mach->udc_command)
+               mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
+}
+
+static void pullup_on(void)
+{
+       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
+
+       if (mach->gpio_pullup)
+               gpio_set_value(mach->gpio_pullup, 1);
+       else if (mach->udc_command)
+               mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
+}
+
+static void pio_irq_enable(int bEndpointAddress)
+{
+        bEndpointAddress &= 0xf;
+        if (bEndpointAddress < 8)
+                UICR0 &= ~(1 << bEndpointAddress);
+        else {
+                bEndpointAddress -= 8;
+                UICR1 &= ~(1 << bEndpointAddress);
+       }
+}
+
+static void pio_irq_disable(int bEndpointAddress)
+{
+        bEndpointAddress &= 0xf;
+        if (bEndpointAddress < 8)
+                UICR0 |= 1 << bEndpointAddress;
+        else {
+                bEndpointAddress -= 8;
+                UICR1 |= 1 << bEndpointAddress;
+        }
+}
+
+/* The UDCCR reg contains mask and interrupt status bits,
+ * so using '|=' isn't safe as it may ack an interrupt.
+ */
+#define UDCCR_MASK_BITS         (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
+
+static inline void udc_set_mask_UDCCR(int mask)
+{
+       UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
+}
+
+static inline void udc_clear_mask_UDCCR(int mask)
+{
+       UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
+}
+
+static inline void udc_ack_int_UDCCR(int mask)
+{
+       /* udccr contains the bits we dont want to change */
+       __u32 udccr = UDCCR & UDCCR_MASK_BITS;
+
+       UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
+}
+
+/*
+ * endpoint enable/disable
+ *
+ * we need to verify the descriptors used to enable endpoints.  since pxa25x
+ * endpoint configurations are fixed, and are pretty much always enabled,
+ * there's not a lot to manage here.
+ *
+ * because pxa25x can't selectively initialize bulk (or interrupt) endpoints,
+ * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
+ * for a single interface (with only the default altsetting) and for gadget
+ * drivers that don't halt endpoints (not reset by set_interface).  that also
+ * means that if you use ISO, you must violate the USB spec rule that all
+ * iso endpoints must be in non-default altsettings.
+ */
+static int pxa25x_ep_enable (struct usb_ep *_ep,
+               const struct usb_endpoint_descriptor *desc)
+{
+       struct pxa25x_ep        *ep;
+       struct pxa25x_udc       *dev;
+
+       ep = container_of (_ep, struct pxa25x_ep, ep);
+       if (!_ep || !desc || ep->desc || _ep->name == ep0name
+                       || desc->bDescriptorType != USB_DT_ENDPOINT
+                       || ep->bEndpointAddress != desc->bEndpointAddress
+                       || ep->fifo_size < le16_to_cpu
+                                               (desc->wMaxPacketSize)) {
+               DMSG("%s, bad ep or descriptor\n", __func__);
+               return -EINVAL;
+       }
+
+       /* xfer types must match, except that interrupt ~= bulk */
+       if (ep->bmAttributes != desc->bmAttributes
+                       && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
+                       && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
+               DMSG("%s, %s type mismatch\n", __func__, _ep->name);
+               return -EINVAL;
+       }
+
+       /* hardware _could_ do smaller, but driver doesn't */
+       if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
+                               && le16_to_cpu (desc->wMaxPacketSize)
+                                               != BULK_FIFO_SIZE)
+                       || !desc->wMaxPacketSize) {
+               DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
+               return -ERANGE;
+       }
+
+       dev = ep->dev;
+       if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
+               DMSG("%s, bogus device state\n", __func__);
+               return -ESHUTDOWN;
+       }
+
+       ep->desc = desc;
+       ep->stopped = 0;
+       ep->pio_irqs = 0;
+       ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
+
+       /* flush fifo (mostly for OUT buffers) */
+       pxa25x_ep_fifo_flush (_ep);
+
+       /* ... reset halt state too, if we could ... */
+
+       DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
+       return 0;
+}
+
+static int pxa25x_ep_disable (struct usb_ep *_ep)
+{
+       struct pxa25x_ep        *ep;
+       unsigned long           flags;
+
+       ep = container_of (_ep, struct pxa25x_ep, ep);
+       if (!_ep || !ep->desc) {
+               DMSG("%s, %s not enabled\n", __func__,
+                       _ep ? ep->ep.name : NULL);
+               return -EINVAL;
+       }
+       local_irq_save(flags);
+
+       nuke (ep, -ESHUTDOWN);
+
+       /* flush fifo (mostly for IN buffers) */
+       pxa25x_ep_fifo_flush (_ep);
+
+       ep->desc = NULL;
+       ep->stopped = 1;
+
+       local_irq_restore(flags);
+       DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
+       return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+/* for the pxa25x, these can just wrap kmalloc/kfree.  gadget drivers
+ * must still pass correctly initialized endpoints, since other controller
+ * drivers may care about how it's currently set up (dma issues etc).
+ */
+
+/*
+ *     pxa25x_ep_alloc_request - allocate a request data structure
+ */
+static struct usb_request *
+pxa25x_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
+{
+       struct pxa25x_request *req;
+
+       req = kzalloc(sizeof(*req), gfp_flags);
+       if (!req)
+               return NULL;
+
+       INIT_LIST_HEAD (&req->queue);
+       return &req->req;
+}
+
+
+/*
+ *     pxa25x_ep_free_request - deallocate a request data structure
+ */
+static void
+pxa25x_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
+{
+       struct pxa25x_request   *req;
+
+       req = container_of (_req, struct pxa25x_request, req);
+       WARN_ON (!list_empty (&req->queue));
+       kfree(req);
+}
+
+/*-------------------------------------------------------------------------*/
+
+/*
+ *     done - retire a request; caller blocked irqs
+ */
+static void done(struct pxa25x_ep *ep, struct pxa25x_request *req, int status)
+{
+       unsigned                stopped = ep->stopped;
+
+       list_del_init(&req->queue);
+
+       if (likely (req->req.status == -EINPROGRESS))
+               req->req.status = status;
+       else
+               status = req->req.status;
+
+       if (status && status != -ESHUTDOWN)
+               DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n",
+                       ep->ep.name, &req->req, status,
+                       req->req.actual, req->req.length);
+
+       /* don't modify queue heads during completion callback */
+       ep->stopped = 1;
+       req->req.complete(&ep->ep, &req->req);
+       ep->stopped = stopped;
+}
+
+
+static inline void ep0_idle (struct pxa25x_udc *dev)
+{
+       dev->ep0state = EP0_IDLE;
+}
+
+static int
+write_packet(volatile u32 *uddr, struct pxa25x_request *req, unsigned max)
+{
+       u8              *buf;
+       unsigned        length, count;
+
+       buf = req->req.buf + req->req.actual;
+       prefetch(buf);
+
+       /* how big will this packet be? */
+       length = min(req->req.length - req->req.actual, max);
+       req->req.actual += length;
+
+       count = length;
+       while (likely(count--))
+               *uddr = *buf++;
+
+       return length;
+}
+
+/*
+ * write to an IN endpoint fifo, as many packets as possible.
+ * irqs will use this to write the rest later.
+ * caller guarantees at least one packet buffer is ready (or a zlp).
+ */
+static int
+write_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
+{
+       unsigned                max;
+
+       max = le16_to_cpu(ep->desc->wMaxPacketSize);
+       do {
+               unsigned        count;
+               int             is_last, is_short;
+
+               count = write_packet(ep->reg_uddr, req, max);
+
+               /* last packet is usually short (or a zlp) */
+               if (unlikely (count != max))
+                       is_last = is_short = 1;
+               else {
+                       if (likely(req->req.length != req->req.actual)
+                                       || req->req.zero)
+                               is_last = 0;
+                       else
+                               is_last = 1;
+                       /* interrupt/iso maxpacket may not fill the fifo */
+                       is_short = unlikely (max < ep->fifo_size);
+               }
+
+               DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n",
+                       ep->ep.name, count,
+                       is_last ? "/L" : "", is_short ? "/S" : "",
+                       req->req.length - req->req.actual, req);
+
+               /* let loose that packet. maybe try writing another one,
+                * double buffering might work.  TSP, TPC, and TFS
+                * bit values are the same for all normal IN endpoints.
+                */
+               *ep->reg_udccs = UDCCS_BI_TPC;
+               if (is_short)
+                       *ep->reg_udccs = UDCCS_BI_TSP;
+
+               /* requests complete when all IN data is in the FIFO */
+               if (is_last) {
+                       done (ep, req, 0);
+                       if (list_empty(&ep->queue))
+                               pio_irq_disable (ep->bEndpointAddress);
+                       return 1;
+               }
+
+               // TODO experiment: how robust can fifo mode tweaking be?
+               // double buffering is off in the default fifo mode, which
+               // prevents TFS from being set here.
+
+       } while (*ep->reg_udccs & UDCCS_BI_TFS);
+       return 0;
+}
+
+/* caller asserts req->pending (ep0 irq status nyet cleared); starts
+ * ep0 data stage.  these chips want very simple state transitions.
+ */
+static inline
+void ep0start(struct pxa25x_udc *dev, u32 flags, const char *tag)
+{
+       UDCCS0 = flags|UDCCS0_SA|UDCCS0_OPR;
+       USIR0 = USIR0_IR0;
+       dev->req_pending = 0;
+       DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
+               __func__, tag, UDCCS0, flags);
+}
+
+static int
+write_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
+{
+       unsigned        count;
+       int             is_short;
+
+       count = write_packet(&UDDR0, req, EP0_FIFO_SIZE);
+       ep->dev->stats.write.bytes += count;
+
+       /* last packet "must be" short (or a zlp) */
+       is_short = (count != EP0_FIFO_SIZE);
+
+       DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
+               req->req.length - req->req.actual, req);
+
+       if (unlikely (is_short)) {
+               if (ep->dev->req_pending)
+                       ep0start(ep->dev, UDCCS0_IPR, "short IN");
+               else
+                       UDCCS0 = UDCCS0_IPR;
+
+               count = req->req.length;
+               done (ep, req, 0);
+               ep0_idle(ep->dev);
+#ifndef CONFIG_ARCH_IXP4XX
+#if 1
+               /* This seems to get rid of lost status irqs in some cases:
+                * host responds quickly, or next request involves config
+                * change automagic, or should have been hidden, or ...
+                *
+                * FIXME get rid of all udelays possible...
+                */
+               if (count >= EP0_FIFO_SIZE) {
+                       count = 100;
+                       do {
+                               if ((UDCCS0 & UDCCS0_OPR) != 0) {
+                                       /* clear OPR, generate ack */
+                                       UDCCS0 = UDCCS0_OPR;
+                                       break;
+                               }
+                               count--;
+                               udelay(1);
+                       } while (count);
+               }
+#endif
+#endif
+       } else if (ep->dev->req_pending)
+               ep0start(ep->dev, 0, "IN");
+       return is_short;
+}
+
+
+/*
+ * read_fifo -  unload packet(s) from the fifo we use for usb OUT
+ * transfers and put them into the request.  caller should have made
+ * sure there's at least one packet ready.
+ *
+ * returns true if the request completed because of short packet or the
+ * request buffer having filled (and maybe overran till end-of-packet).
+ */
+static int
+read_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
+{
+       for (;;) {
+               u32             udccs;
+               u8              *buf;
+               unsigned        bufferspace, count, is_short;
+
+               /* make sure there's a packet in the FIFO.
+                * UDCCS_{BO,IO}_RPC are all the same bit value.
+                * UDCCS_{BO,IO}_RNE are all the same bit value.
+                */
+               udccs = *ep->reg_udccs;
+               if (unlikely ((udccs & UDCCS_BO_RPC) == 0))
+                       break;
+               buf = req->req.buf + req->req.actual;
+               prefetchw(buf);
+               bufferspace = req->req.length - req->req.actual;
+
+               /* read all bytes from this packet */
+               if (likely (udccs & UDCCS_BO_RNE)) {
+                       count = 1 + (0x0ff & *ep->reg_ubcr);
+                       req->req.actual += min (count, bufferspace);
+               } else /* zlp */
+                       count = 0;
+               is_short = (count < ep->ep.maxpacket);
+               DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n",
+                       ep->ep.name, udccs, count,
+                       is_short ? "/S" : "",
+                       req, req->req.actual, req->req.length);
+               while (likely (count-- != 0)) {
+                       u8      byte = (u8) *ep->reg_uddr;
+
+                       if (unlikely (bufferspace == 0)) {
+                               /* this happens when the driver's buffer
+                                * is smaller than what the host sent.
+                                * discard the extra data.
+                                */
+                               if (req->req.status != -EOVERFLOW)
+                                       DMSG("%s overflow %d\n",
+                                               ep->ep.name, count);
+                               req->req.status = -EOVERFLOW;
+                       } else {
+                               *buf++ = byte;
+                               bufferspace--;
+                       }
+               }
+               *ep->reg_udccs =  UDCCS_BO_RPC;
+               /* RPC/RSP/RNE could now reflect the other packet buffer */
+
+               /* iso is one request per packet */
+               if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
+                       if (udccs & UDCCS_IO_ROF)
+                               req->req.status = -EHOSTUNREACH;
+                       /* more like "is_done" */
+                       is_short = 1;
+               }
+
+               /* completion */
+               if (is_short || req->req.actual == req->req.length) {
+                       done (ep, req, 0);
+                       if (list_empty(&ep->queue))
+                               pio_irq_disable (ep->bEndpointAddress);
+                       return 1;
+               }
+
+               /* finished that packet.  the next one may be waiting... */
+       }
+       return 0;
+}
+
+/*
+ * special ep0 version of the above.  no UBCR0 or double buffering; status
+ * handshaking is magic.  most device protocols don't need control-OUT.
+ * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
+ * protocols do use them.
+ */
+static int
+read_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
+{
+       u8              *buf, byte;
+       unsigned        bufferspace;
+
+       buf = req->req.buf + req->req.actual;
+       bufferspace = req->req.length - req->req.actual;
+
+       while (UDCCS0 & UDCCS0_RNE) {
+               byte = (u8) UDDR0;
+
+               if (unlikely (bufferspace == 0)) {
+                       /* this happens when the driver's buffer
+                        * is smaller than what the host sent.
+                        * discard the extra data.
+                        */
+                       if (req->req.status != -EOVERFLOW)
+                               DMSG("%s overflow\n", ep->ep.name);
+                       req->req.status = -EOVERFLOW;
+               } else {
+                       *buf++ = byte;
+                       req->req.actual++;
+                       bufferspace--;
+               }
+       }
+
+       UDCCS0 = UDCCS0_OPR | UDCCS0_IPR;
+
+       /* completion */
+       if (req->req.actual >= req->req.length)
+               return 1;
+
+       /* finished that packet.  the next one may be waiting... */
+       return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int
+pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
+{
+       struct pxa25x_request   *req;
+       struct pxa25x_ep        *ep;
+       struct pxa25x_udc       *dev;
+       unsigned long           flags;
+
+       req = container_of(_req, struct pxa25x_request, req);
+       if (unlikely (!_req || !_req->complete || !_req->buf
+                       || !list_empty(&req->queue))) {
+               DMSG("%s, bad params\n", __func__);
+               return -EINVAL;
+       }
+
+       ep = container_of(_ep, struct pxa25x_ep, ep);
+       if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
+               DMSG("%s, bad ep\n", __func__);
+               return -EINVAL;
+       }
+
+       dev = ep->dev;
+       if (unlikely (!dev->driver
+                       || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
+               DMSG("%s, bogus device state\n", __func__);
+               return -ESHUTDOWN;
+       }
+
+       /* iso is always one packet per request, that's the only way
+        * we can report per-packet status.  that also helps with dma.
+        */
+       if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
+                       && req->req.length > le16_to_cpu
+                                               (ep->desc->wMaxPacketSize)))
+               return -EMSGSIZE;
+
+       DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
+               _ep->name, _req, _req->length, _req->buf);
+
+       local_irq_save(flags);
+
+       _req->status = -EINPROGRESS;
+       _req->actual = 0;
+
+       /* kickstart this i/o queue? */
+       if (list_empty(&ep->queue) && !ep->stopped) {
+               if (ep->desc == NULL/* ep0 */) {
+                       unsigned        length = _req->length;
+
+                       switch (dev->ep0state) {
+                       case EP0_IN_DATA_PHASE:
+                               dev->stats.write.ops++;
+                               if (write_ep0_fifo(ep, req))
+                                       req = NULL;
+                               break;
+
+                       case EP0_OUT_DATA_PHASE:
+                               dev->stats.read.ops++;
+                               /* messy ... */
+                               if (dev->req_config) {
+                                       DBG(DBG_VERBOSE, "ep0 config ack%s\n",
+                                               dev->has_cfr ?  "" : " raced");
+                                       if (dev->has_cfr)
+                                               UDCCFR = UDCCFR_AREN|UDCCFR_ACM
+                                                       |UDCCFR_MB1;
+                                       done(ep, req, 0);
+                                       dev->ep0state = EP0_END_XFER;
+                                       local_irq_restore (flags);
+                                       return 0;
+                               }
+                               if (dev->req_pending)
+                                       ep0start(dev, UDCCS0_IPR, "OUT");
+                               if (length == 0 || ((UDCCS0 & UDCCS0_RNE) != 0
+                                               && read_ep0_fifo(ep, req))) {
+                                       ep0_idle(dev);
+                                       done(ep, req, 0);
+                                       req = NULL;
+                               }
+                               break;
+
+                       default:
+                               DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
+                               local_irq_restore (flags);
+                               return -EL2HLT;
+                       }
+               /* can the FIFO can satisfy the request immediately? */
+               } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
+                       if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
+                                       && write_fifo(ep, req))
+                               req = NULL;
+               } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
+                               && read_fifo(ep, req)) {
+                       req = NULL;
+               }
+
+               if (likely (req && ep->desc))
+                       pio_irq_enable(ep->bEndpointAddress);
+       }
+
+       /* pio or dma irq handler advances the queue. */
+       if (likely(req != NULL))
+               list_add_tail(&req->queue, &ep->queue);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+
+/*
+ *     nuke - dequeue ALL requests
+ */
+static void nuke(struct pxa25x_ep *ep, int status)
+{
+       struct pxa25x_request *req;
+
+       /* called with irqs blocked */
+       while (!list_empty(&ep->queue)) {
+               req = list_entry(ep->queue.next,
+                               struct pxa25x_request,
+                               queue);
+               done(ep, req, status);
+       }
+       if (ep->desc)
+               pio_irq_disable (ep->bEndpointAddress);
+}
+
+
+/* dequeue JUST ONE request */
+static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
+{
+       struct pxa25x_ep        *ep;
+       struct pxa25x_request   *req;
+       unsigned long           flags;
+
+       ep = container_of(_ep, struct pxa25x_ep, ep);
+       if (!_ep || ep->ep.name == ep0name)
+               return -EINVAL;
+
+       local_irq_save(flags);
+
+       /* make sure it's actually queued on this endpoint */
+       list_for_each_entry (req, &ep->queue, queue) {
+               if (&req->req == _req)
+                       break;
+       }
+       if (&req->req != _req) {
+               local_irq_restore(flags);
+               return -EINVAL;
+       }
+
+       done(ep, req, -ECONNRESET);
+
+       local_irq_restore(flags);
+       return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int pxa25x_ep_set_halt(struct usb_ep *_ep, int value)
+{
+       struct pxa25x_ep        *ep;
+       unsigned long           flags;
+
+       ep = container_of(_ep, struct pxa25x_ep, ep);
+       if (unlikely (!_ep
+                       || (!ep->desc && ep->ep.name != ep0name))
+                       || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
+               DMSG("%s, bad ep\n", __func__);
+               return -EINVAL;
+       }
+       if (value == 0) {
+               /* this path (reset toggle+halt) is needed to implement
+                * SET_INTERFACE on normal hardware.  but it can't be
+                * done from software on the PXA UDC, and the hardware
+                * forgets to do it as part of SET_INTERFACE automagic.
+                */
+               DMSG("only host can clear %s halt\n", _ep->name);
+               return -EROFS;
+       }
+
+       local_irq_save(flags);
+
+       if ((ep->bEndpointAddress & USB_DIR_IN) != 0
+                       && ((*ep->reg_udccs & UDCCS_BI_TFS) == 0
+                          || !list_empty(&ep->queue))) {
+               local_irq_restore(flags);
+               return -EAGAIN;
+       }
+
+       /* FST bit is the same for control, bulk in, bulk out, interrupt in */
+       *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF;
+
+       /* ep0 needs special care */
+       if (!ep->desc) {
+               start_watchdog(ep->dev);
+               ep->dev->req_pending = 0;
+               ep->dev->ep0state = EP0_STALL;
+
+       /* and bulk/intr endpoints like dropping stalls too */
+       } else {
+               unsigned i;
+               for (i = 0; i < 1000; i += 20) {
+                       if (*ep->reg_udccs & UDCCS_BI_SST)
+                               break;
+                       udelay(20);
+               }
+       }
+       local_irq_restore(flags);
+
+       DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
+       return 0;
+}
+
+static int pxa25x_ep_fifo_status(struct usb_ep *_ep)
+{
+       struct pxa25x_ep        *ep;
+
+       ep = container_of(_ep, struct pxa25x_ep, ep);
+       if (!_ep) {
+               DMSG("%s, bad ep\n", __func__);
+               return -ENODEV;
+       }
+       /* pxa can't report unclaimed bytes from IN fifos */
+       if ((ep->bEndpointAddress & USB_DIR_IN) != 0)
+               return -EOPNOTSUPP;
+       if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
+                       || (*ep->reg_udccs & UDCCS_BO_RFS) == 0)
+               return 0;
+       else
+               return (*ep->reg_ubcr & 0xfff) + 1;
+}
+
+static void pxa25x_ep_fifo_flush(struct usb_ep *_ep)
+{
+       struct pxa25x_ep        *ep;
+
+       ep = container_of(_ep, struct pxa25x_ep, ep);
+       if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
+               DMSG("%s, bad ep\n", __func__);
+               return;
+       }
+
+       /* toggle and halt bits stay unchanged */
+
+       /* for OUT, just read and discard the FIFO contents. */
+       if ((ep->bEndpointAddress & USB_DIR_IN) == 0) {
+               while (((*ep->reg_udccs) & UDCCS_BO_RNE) != 0)
+                       (void) *ep->reg_uddr;
+               return;
+       }
+
+       /* most IN status is the same, but ISO can't stall */
+       *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
+               | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
+                       ? 0 : UDCCS_BI_SST;
+}
+
+
+static struct usb_ep_ops pxa25x_ep_ops = {
+       .enable         = pxa25x_ep_enable,
+       .disable        = pxa25x_ep_disable,
+
+       .alloc_request  = pxa25x_ep_alloc_request,
+       .free_request   = pxa25x_ep_free_request,
+
+       .queue          = pxa25x_ep_queue,
+       .dequeue        = pxa25x_ep_dequeue,
+
+       .set_halt       = pxa25x_ep_set_halt,
+       .fifo_status    = pxa25x_ep_fifo_status,
+       .fifo_flush     = pxa25x_ep_fifo_flush,
+};
+
+
+/* ---------------------------------------------------------------------------
+ *     device-scoped parts of the api to the usb controller hardware
+ * ---------------------------------------------------------------------------
+ */
+
+static int pxa25x_udc_get_frame(struct usb_gadget *_gadget)
+{
+       return ((UFNRH & 0x07) << 8) | (UFNRL & 0xff);
+}
+
+static int pxa25x_udc_wakeup(struct usb_gadget *_gadget)
+{
+       /* host may not have enabled remote wakeup */
+       if ((UDCCS0 & UDCCS0_DRWF) == 0)
+               return -EHOSTUNREACH;
+       udc_set_mask_UDCCR(UDCCR_RSM);
+       return 0;
+}
+
+static void stop_activity(struct pxa25x_udc *, struct usb_gadget_driver *);
+static void udc_enable (struct pxa25x_udc *);
+static void udc_disable(struct pxa25x_udc *);
+
+/* We disable the UDC -- and its 48 MHz clock -- whenever it's not
+ * in active use.
+ */
+static int pullup(struct pxa25x_udc *udc)
+{
+       int is_active = udc->vbus && udc->pullup && !udc->suspended;
+       DMSG("%s\n", is_active ? "active" : "inactive");
+       if (is_active) {
+               if (!udc->active) {
+                       udc->active = 1;
+                       /* Enable clock for USB device */
+                       clk_enable(udc->clk);
+                       udc_enable(udc);
+               }
+       } else {
+               if (udc->active) {
+                       if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
+                               DMSG("disconnect %s\n", udc->driver
+                                       ? udc->driver->driver.name
+                                       : "(no driver)");
+                               stop_activity(udc, udc->driver);
+                       }
+                       udc_disable(udc);
+                       /* Disable clock for USB device */
+                       clk_disable(udc->clk);
+                       udc->active = 0;
+               }
+
+       }
+       return 0;
+}
+
+/* VBUS reporting logically comes from a transceiver */
+static int pxa25x_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
+{
+       struct pxa25x_udc       *udc;
+
+       udc = container_of(_gadget, struct pxa25x_udc, gadget);
+       udc->vbus = (is_active != 0);
+       DMSG("vbus %s\n", is_active ? "supplied" : "inactive");
+       pullup(udc);
+       return 0;
+}
+
+/* drivers may have software control over D+ pullup */
+static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active)
+{
+       struct pxa25x_udc       *udc;
+
+       udc = container_of(_gadget, struct pxa25x_udc, gadget);
+
+       /* not all boards support pullup control */
+       if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
+               return -EOPNOTSUPP;
+
+       udc->pullup = (is_active != 0);
+       pullup(udc);
+       return 0;
+}
+
+static const struct usb_gadget_ops pxa25x_udc_ops = {
+       .get_frame      = pxa25x_udc_get_frame,
+       .wakeup         = pxa25x_udc_wakeup,
+       .vbus_session   = pxa25x_udc_vbus_session,
+       .pullup         = pxa25x_udc_pullup,
+
+       // .vbus_draw ... boards may consume current from VBUS, up to
+       // 100-500mA based on config.  the 500uA suspend ceiling means
+       // that exclusively vbus-powered PXA designs violate USB specs.
+};
+
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_USB_GADGET_DEBUG_FS
+
+static int
+udc_seq_show(struct seq_file *m, void *_d)
+{
+       struct pxa25x_udc       *dev = m->private;
+       unsigned long           flags;
+       int                     i;
+       u32                     tmp;
+
+       local_irq_save(flags);
+
+       /* basic device status */
+       seq_printf(m, DRIVER_DESC "\n"
+               "%s version: %s\nGadget driver: %s\nHost %s\n\n",
+               driver_name, DRIVER_VERSION SIZE_STR "(pio)",
+               dev->driver ? dev->driver->driver.name : "(none)",
+               is_vbus_present() ? "full speed" : "disconnected");
+
+       /* registers for device and ep0 */
+       seq_printf(m,
+               "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
+               UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
+
+       tmp = UDCCR;
+       seq_printf(m,
+               "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
+               (tmp & UDCCR_REM) ? " rem" : "",
+               (tmp & UDCCR_RSTIR) ? " rstir" : "",
+               (tmp & UDCCR_SRM) ? " srm" : "",
+               (tmp & UDCCR_SUSIR) ? " susir" : "",
+               (tmp & UDCCR_RESIR) ? " resir" : "",
+               (tmp & UDCCR_RSM) ? " rsm" : "",
+               (tmp & UDCCR_UDA) ? " uda" : "",
+               (tmp & UDCCR_UDE) ? " ude" : "");
+
+       tmp = UDCCS0;
+       seq_printf(m,
+               "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
+               (tmp & UDCCS0_SA) ? " sa" : "",
+               (tmp & UDCCS0_RNE) ? " rne" : "",
+               (tmp & UDCCS0_FST) ? " fst" : "",
+               (tmp & UDCCS0_SST) ? " sst" : "",
+               (tmp & UDCCS0_DRWF) ? " dwrf" : "",
+               (tmp & UDCCS0_FTF) ? " ftf" : "",
+               (tmp & UDCCS0_IPR) ? " ipr" : "",
+               (tmp & UDCCS0_OPR) ? " opr" : "");
+
+       if (dev->has_cfr) {
+               tmp = UDCCFR;
+               seq_printf(m,
+                       "udccfr %02X =%s%s\n", tmp,
+                       (tmp & UDCCFR_AREN) ? " aren" : "",
+                       (tmp & UDCCFR_ACM) ? " acm" : "");
+       }
+
+       if (!is_vbus_present() || !dev->driver)
+               goto done;
+
+       seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
+               dev->stats.write.bytes, dev->stats.write.ops,
+               dev->stats.read.bytes, dev->stats.read.ops,
+               dev->stats.irqs);
+
+       /* dump endpoint queues */
+       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
+               struct pxa25x_ep        *ep = &dev->ep [i];
+               struct pxa25x_request   *req;
+
+               if (i != 0) {
+                       const struct usb_endpoint_descriptor    *desc;
+
+                       desc = ep->desc;
+                       if (!desc)
+                               continue;
+                       tmp = *dev->ep [i].reg_udccs;
+                       seq_printf(m,
+                               "%s max %d %s udccs %02x irqs %lu\n",
+                               ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
+                               "pio", tmp, ep->pio_irqs);
+                       /* TODO translate all five groups of udccs bits! */
+
+               } else /* ep0 should only have one transfer queued */
+                       seq_printf(m, "ep0 max 16 pio irqs %lu\n",
+                               ep->pio_irqs);
+
+               if (list_empty(&ep->queue)) {
+                       seq_printf(m, "\t(nothing queued)\n");
+                       continue;
+               }
+               list_for_each_entry(req, &ep->queue, queue) {
+                       seq_printf(m,
+                                       "\treq %p len %d/%d buf %p\n",
+                                       &req->req, req->req.actual,
+                                       req->req.length, req->req.buf);
+               }
+       }
+
+done:
+       local_irq_restore(flags);
+       return 0;
+}
+
+static int
+udc_debugfs_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, udc_seq_show, inode->i_private);
+}
+
+static const struct file_operations debug_fops = {
+       .open           = udc_debugfs_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .owner          = THIS_MODULE,
+};
+
+#define create_debug_files(dev) \
+       do { \
+               dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
+                       S_IRUGO, NULL, dev, &debug_fops); \
+       } while (0)
+#define remove_debug_files(dev) \
+       do { \
+               if (dev->debugfs_udc) \
+                       debugfs_remove(dev->debugfs_udc); \
+       } while (0)
+
+#else  /* !CONFIG_USB_GADGET_DEBUG_FILES */
+
+#define create_debug_files(dev) do {} while (0)
+#define remove_debug_files(dev) do {} while (0)
+
+#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
+
+/*-------------------------------------------------------------------------*/
+
+/*
+ *     udc_disable - disable USB device controller
+ */
+static void udc_disable(struct pxa25x_udc *dev)
+{
+       /* block all irqs */
+       udc_set_mask_UDCCR(UDCCR_SRM|UDCCR_REM);
+       UICR0 = UICR1 = 0xff;
+       UFNRH = UFNRH_SIM;
+
+       /* if hardware supports it, disconnect from usb */
+       pullup_off();
+
+       udc_clear_mask_UDCCR(UDCCR_UDE);
+
+       ep0_idle (dev);
+       dev->gadget.speed = USB_SPEED_UNKNOWN;
+}
+
+
+/*
+ *     udc_reinit - initialize software state
+ */
+static void udc_reinit(struct pxa25x_udc *dev)
+{
+       u32     i;
+
+       /* device/ep0 records init */
+       INIT_LIST_HEAD (&dev->gadget.ep_list);
+       INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
+       dev->ep0state = EP0_IDLE;
+
+       /* basic endpoint records init */
+       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
+               struct pxa25x_ep *ep = &dev->ep[i];
+
+               if (i != 0)
+                       list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
+
+               ep->desc = NULL;
+               ep->stopped = 0;
+               INIT_LIST_HEAD (&ep->queue);
+               ep->pio_irqs = 0;
+       }
+
+       /* the rest was statically initialized, and is read-only */
+}
+
+/* until it's enabled, this UDC should be completely invisible
+ * to any USB host.
+ */
+static void udc_enable (struct pxa25x_udc *dev)
+{
+       udc_clear_mask_UDCCR(UDCCR_UDE);
+
+       /* try to clear these bits before we enable the udc */
+       udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
+
+       ep0_idle(dev);
+       dev->gadget.speed = USB_SPEED_UNKNOWN;
+       dev->stats.irqs = 0;
+
+       /*
+        * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
+        * - enable UDC
+        * - if RESET is already in progress, ack interrupt
+        * - unmask reset interrupt
+        */
+       udc_set_mask_UDCCR(UDCCR_UDE);
+       if (!(UDCCR & UDCCR_UDA))
+               udc_ack_int_UDCCR(UDCCR_RSTIR);
+
+       if (dev->has_cfr /* UDC_RES2 is defined */) {
+               /* pxa255 (a0+) can avoid a set_config race that could
+                * prevent gadget drivers from configuring correctly
+                */
+               UDCCFR = UDCCFR_ACM | UDCCFR_MB1;
+       } else {
+               /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
+                * which could result in missing packets and interrupts.
+                * supposedly one bit per endpoint, controlling whether it
+                * double buffers or not; ACM/AREN bits fit into the holes.
+                * zero bits (like USIR0_IRx) disable double buffering.
+                */
+               UDC_RES1 = 0x00;
+               UDC_RES2 = 0x00;
+       }
+
+       /* enable suspend/resume and reset irqs */
+       udc_clear_mask_UDCCR(UDCCR_SRM | UDCCR_REM);
+
+       /* enable ep0 irqs */
+       UICR0 &= ~UICR0_IM0;
+
+       /* if hardware supports it, pullup D+ and wait for reset */
+       pullup_on();
+}
+
+
+/* when a driver is successfully registered, it will receive
+ * control requests including set_configuration(), which enables
+ * non-control requests.  then usb traffic follows until a
+ * disconnect is reported.  then a host may connect again, or
+ * the driver might get unbound.
+ */
+int usb_gadget_register_driver(struct usb_gadget_driver *driver)
+{
+       struct pxa25x_udc       *dev = the_controller;
+       int                     retval;
+
+       if (!driver
+                       || driver->speed < USB_SPEED_FULL
+                       || !driver->bind
+                       || !driver->disconnect
+                       || !driver->setup)
+               return -EINVAL;
+       if (!dev)
+               return -ENODEV;
+       if (dev->driver)
+               return -EBUSY;
+
+       /* first hook up the driver ... */
+       dev->driver = driver;
+       dev->gadget.dev.driver = &driver->driver;
+       dev->pullup = 1;
+
+       retval = device_add (&dev->gadget.dev);
+       if (retval) {
+fail:
+               dev->driver = NULL;
+               dev->gadget.dev.driver = NULL;
+               return retval;
+       }
+       retval = driver->bind(&dev->gadget);
+       if (retval) {
+               DMSG("bind to driver %s --> error %d\n",
+                               driver->driver.name, retval);
+               device_del (&dev->gadget.dev);
+               goto fail;
+       }
+
+       /* ... then enable host detection and ep0; and we're ready
+        * for set_configuration as well as eventual disconnect.
+        */
+       DMSG("registered gadget driver '%s'\n", driver->driver.name);
+       pullup(dev);
+       dump_state(dev);
+       return 0;
+}
+EXPORT_SYMBOL(usb_gadget_register_driver);
+
+static void
+stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
+{
+       int i;
+
+       /* don't disconnect drivers more than once */
+       if (dev->gadget.speed == USB_SPEED_UNKNOWN)
+               driver = NULL;
+       dev->gadget.speed = USB_SPEED_UNKNOWN;
+
+       /* prevent new request submissions, kill any outstanding requests  */
+       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
+               struct pxa25x_ep *ep = &dev->ep[i];
+
+               ep->stopped = 1;
+               nuke(ep, -ESHUTDOWN);
+       }
+       del_timer_sync(&dev->timer);
+
+       /* report disconnect; the driver is already quiesced */
+       if (driver)
+               driver->disconnect(&dev->gadget);
+
+       /* re-init driver-visible data structures */
+       udc_reinit(dev);
+}
+
+int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
+{
+       struct pxa25x_udc       *dev = the_controller;
+
+       if (!dev)
+               return -ENODEV;
+       if (!driver || driver != dev->driver || !driver->unbind)
+               return -EINVAL;
+
+       local_irq_disable();
+       dev->pullup = 0;
+       pullup(dev);
+       stop_activity(dev, driver);
+       local_irq_enable();
+
+       driver->unbind(&dev->gadget);
+       dev->gadget.dev.driver = NULL;
+       dev->driver = NULL;
+
+       device_del (&dev->gadget.dev);
+
+       DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
+       dump_state(dev);
+       return 0;
+}
+EXPORT_SYMBOL(usb_gadget_unregister_driver);
+
+
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_ARCH_LUBBOCK
+
+/* Lubbock has separate connect and disconnect irqs.  More typical designs
+ * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
+ */
+
+static irqreturn_t
+lubbock_vbus_irq(int irq, void *_dev)
+{
+       struct pxa25x_udc       *dev = _dev;
+       int                     vbus;
+
+       dev->stats.irqs++;
+       switch (irq) {
+       case LUBBOCK_USB_IRQ:
+               vbus = 1;
+               disable_irq(LUBBOCK_USB_IRQ);
+               enable_irq(LUBBOCK_USB_DISC_IRQ);
+               break;
+       case LUBBOCK_USB_DISC_IRQ:
+               vbus = 0;
+               disable_irq(LUBBOCK_USB_DISC_IRQ);
+               enable_irq(LUBBOCK_USB_IRQ);
+               break;
+       default:
+               return IRQ_NONE;
+       }
+
+       pxa25x_udc_vbus_session(&dev->gadget, vbus);
+       return IRQ_HANDLED;
+}
+
+#endif
+
+static irqreturn_t udc_vbus_irq(int irq, void *_dev)
+{
+       struct pxa25x_udc       *dev = _dev;
+       int                     vbus = gpio_get_value(dev->mach->gpio_vbus);
+
+       if (dev->mach->gpio_vbus_inverted)
+               vbus = !vbus;
+
+       pxa25x_udc_vbus_session(&dev->gadget, vbus);
+       return IRQ_HANDLED;
+}
+
+
+/*-------------------------------------------------------------------------*/
+
+static inline void clear_ep_state (struct pxa25x_udc *dev)
+{
+       unsigned i;
+
+       /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
+        * fifos, and pending transactions mustn't be continued in any case.
+        */
+       for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
+               nuke(&dev->ep[i], -ECONNABORTED);
+}
+
+static void udc_watchdog(unsigned long _dev)
+{
+       struct pxa25x_udc       *dev = (void *)_dev;
+
+       local_irq_disable();
+       if (dev->ep0state == EP0_STALL
+                       && (UDCCS0 & UDCCS0_FST) == 0
+                       && (UDCCS0 & UDCCS0_SST) == 0) {
+               UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
+               DBG(DBG_VERBOSE, "ep0 re-stall\n");
+               start_watchdog(dev);
+       }
+       local_irq_enable();
+}
+
+static void handle_ep0 (struct pxa25x_udc *dev)
+{
+       u32                     udccs0 = UDCCS0;
+       struct pxa25x_ep        *ep = &dev->ep [0];
+       struct pxa25x_request   *req;
+       union {
+               struct usb_ctrlrequest  r;
+               u8                      raw [8];
+               u32                     word [2];
+       } u;
+
+       if (list_empty(&ep->queue))
+               req = NULL;
+       else
+               req = list_entry(ep->queue.next, struct pxa25x_request, queue);
+
+       /* clear stall status */
+       if (udccs0 & UDCCS0_SST) {
+               nuke(ep, -EPIPE);
+               UDCCS0 = UDCCS0_SST;
+               del_timer(&dev->timer);
+               ep0_idle(dev);
+       }
+
+       /* previous request unfinished?  non-error iff back-to-back ... */
+       if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
+               nuke(ep, 0);
+               del_timer(&dev->timer);
+               ep0_idle(dev);
+       }
+
+       switch (dev->ep0state) {
+       case EP0_IDLE:
+               /* late-breaking status? */
+               udccs0 = UDCCS0;
+
+               /* start control request? */
+               if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
+                               == (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
+                       int i;
+
+                       nuke (ep, -EPROTO);
+
+                       /* read SETUP packet */
+                       for (i = 0; i < 8; i++) {
+                               if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
+bad_setup:
+                                       DMSG("SETUP %d!\n", i);
+                                       goto stall;
+                               }
+                               u.raw [i] = (u8) UDDR0;
+                       }
+                       if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
+                               goto bad_setup;
+
+got_setup:
+                       DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
+                               u.r.bRequestType, u.r.bRequest,
+                               le16_to_cpu(u.r.wValue),
+                               le16_to_cpu(u.r.wIndex),
+                               le16_to_cpu(u.r.wLength));
+
+                       /* cope with automagic for some standard requests. */
+                       dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
+                                               == USB_TYPE_STANDARD;
+                       dev->req_config = 0;
+                       dev->req_pending = 1;
+                       switch (u.r.bRequest) {
+                       /* hardware restricts gadget drivers here! */
+                       case USB_REQ_SET_CONFIGURATION:
+                               if (u.r.bRequestType == USB_RECIP_DEVICE) {
+                                       /* reflect hardware's automagic
+                                        * up to the gadget driver.
+                                        */
+config_change:
+                                       dev->req_config = 1;
+                                       clear_ep_state(dev);
+                                       /* if !has_cfr, there's no synch
+                                        * else use AREN (later) not SA|OPR
+                                        * USIR0_IR0 acts edge sensitive
+                                        */
+                               }
+                               break;
+                       /* ... and here, even more ... */
+                       case USB_REQ_SET_INTERFACE:
+                               if (u.r.bRequestType == USB_RECIP_INTERFACE) {
+                                       /* udc hardware is broken by design:
+                                        *  - altsetting may only be zero;
+                                        *  - hw resets all interfaces' eps;
+                                        *  - ep reset doesn't include halt(?).
+                                        */
+                                       DMSG("broken set_interface (%d/%d)\n",
+                                               le16_to_cpu(u.r.wIndex),
+                                               le16_to_cpu(u.r.wValue));
+                                       goto config_change;
+                               }
+                               break;
+                       /* hardware was supposed to hide this */
+                       case USB_REQ_SET_ADDRESS:
+                               if (u.r.bRequestType == USB_RECIP_DEVICE) {
+                                       ep0start(dev, 0, "address");
+                                       return;
+                               }
+                               break;
+                       }
+
+                       if (u.r.bRequestType & USB_DIR_IN)
+                               dev->ep0state = EP0_IN_DATA_PHASE;
+                       else
+                               dev->ep0state = EP0_OUT_DATA_PHASE;
+
+                       i = dev->driver->setup(&dev->gadget, &u.r);
+                       if (i < 0) {
+                               /* hardware automagic preventing STALL... */
+                               if (dev->req_config) {
+                                       /* hardware sometimes neglects to tell
+                                        * tell us about config change events,
+                                        * so later ones may fail...
+                                        */
+                                       WARN("config change %02x fail %d?\n",
+                                               u.r.bRequest, i);
+                                       return;
+                                       /* TODO experiment:  if has_cfr,
+                                        * hardware didn't ACK; maybe we
+                                        * could actually STALL!
+                                        */
+                               }
+                               DBG(DBG_VERBOSE, "protocol STALL, "
+                                       "%02x err %d\n", UDCCS0, i);
+stall:
+                               /* the watchdog timer helps deal with cases
+                                * where udc seems to clear FST wrongly, and
+                                * then NAKs instead of STALLing.
+                                */
+                               ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
+                               start_watchdog(dev);
+                               dev->ep0state = EP0_STALL;
+
+                       /* deferred i/o == no response yet */
+                       } else if (dev->req_pending) {
+                               if (likely(dev->ep0state == EP0_IN_DATA_PHASE
+                                               || dev->req_std || u.r.wLength))
+                                       ep0start(dev, 0, "defer");
+                               else
+                                       ep0start(dev, UDCCS0_IPR, "defer/IPR");
+                       }
+
+                       /* expect at least one data or status stage irq */
+                       return;
+
+               } else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
+                               == (UDCCS0_OPR|UDCCS0_SA))) {
+                       unsigned i;
+
+                       /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
+                        * still observed on a pxa255 a0.
+                        */
+                       DBG(DBG_VERBOSE, "e131\n");
+                       nuke(ep, -EPROTO);
+
+                       /* read SETUP data, but don't trust it too much */
+                       for (i = 0; i < 8; i++)
+                               u.raw [i] = (u8) UDDR0;
+                       if ((u.r.bRequestType & USB_RECIP_MASK)
+                                       > USB_RECIP_OTHER)
+                               goto stall;
+                       if (u.word [0] == 0 && u.word [1] == 0)
+                               goto stall;
+                       goto got_setup;
+               } else {
+                       /* some random early IRQ:
+                        * - we acked FST
+                        * - IPR cleared
+                        * - OPR got set, without SA (likely status stage)
+                        */
+                       UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
+               }
+               break;
+       case EP0_IN_DATA_PHASE:                 /* GET_DESCRIPTOR etc */
+               if (udccs0 & UDCCS0_OPR) {
+                       UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
+                       DBG(DBG_VERBOSE, "ep0in premature status\n");
+                       if (req)
+                               done(ep, req, 0);
+                       ep0_idle(dev);
+               } else /* irq was IPR clearing */ {
+                       if (req) {
+                               /* this IN packet might finish the request */
+                               (void) write_ep0_fifo(ep, req);
+                       } /* else IN token before response was written */
+               }
+               break;
+       case EP0_OUT_DATA_PHASE:                /* SET_DESCRIPTOR etc */
+               if (udccs0 & UDCCS0_OPR) {
+                       if (req) {
+                               /* this OUT packet might finish the request */
+                               if (read_ep0_fifo(ep, req))
+                                       done(ep, req, 0);
+                               /* else more OUT packets expected */
+                       } /* else OUT token before read was issued */
+               } else /* irq was IPR clearing */ {
+                       DBG(DBG_VERBOSE, "ep0out premature status\n");
+                       if (req)
+                               done(ep, req, 0);
+                       ep0_idle(dev);
+               }
+               break;
+       case EP0_END_XFER:
+               if (req)
+                       done(ep, req, 0);
+               /* ack control-IN status (maybe in-zlp was skipped)
+                * also appears after some config change events.
+                */
+               if (udccs0 & UDCCS0_OPR)
+                       UDCCS0 = UDCCS0_OPR;
+               ep0_idle(dev);
+               break;
+       case EP0_STALL:
+               UDCCS0 = UDCCS0_FST;
+               break;
+       }
+       USIR0 = USIR0_IR0;
+}
+
+static void handle_ep(struct pxa25x_ep *ep)
+{
+       struct pxa25x_request   *req;
+       int                     is_in = ep->bEndpointAddress & USB_DIR_IN;
+       int                     completed;
+       u32                     udccs, tmp;
+
+       do {
+               completed = 0;
+               if (likely (!list_empty(&ep->queue)))
+                       req = list_entry(ep->queue.next,
+                                       struct pxa25x_request, queue);
+               else
+                       req = NULL;
+
+               // TODO check FST handling
+
+               udccs = *ep->reg_udccs;
+               if (unlikely(is_in)) {  /* irq from TPC, SST, or (ISO) TUR */
+                       tmp = UDCCS_BI_TUR;
+                       if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
+                               tmp |= UDCCS_BI_SST;
+                       tmp &= udccs;
+                       if (likely (tmp))
+                               *ep->reg_udccs = tmp;
+                       if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
+                               completed = write_fifo(ep, req);
+
+               } else {        /* irq from RPC (or for ISO, ROF) */
+                       if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
+                               tmp = UDCCS_BO_SST | UDCCS_BO_DME;
+                       else
+                               tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
+                       tmp &= udccs;
+                       if (likely(tmp))
+                               *ep->reg_udccs = tmp;
+
+                       /* fifos can hold packets, ready for reading... */
+                       if (likely(req)) {
+                               completed = read_fifo(ep, req);
+                       } else
+                               pio_irq_disable (ep->bEndpointAddress);
+               }
+               ep->pio_irqs++;
+       } while (completed);
+}
+
+/*
+ *     pxa25x_udc_irq - interrupt handler
+ *
+ * avoid delays in ep0 processing. the control handshaking isn't always
+ * under software control (pxa250c0 and the pxa255 are better), and delays
+ * could cause usb protocol errors.
+ */
+static irqreturn_t
+pxa25x_udc_irq(int irq, void *_dev)
+{
+       struct pxa25x_udc       *dev = _dev;
+       int                     handled;
+
+       dev->stats.irqs++;
+       do {
+               u32             udccr = UDCCR;
+
+               handled = 0;
+
+               /* SUSpend Interrupt Request */
+               if (unlikely(udccr & UDCCR_SUSIR)) {
+                       udc_ack_int_UDCCR(UDCCR_SUSIR);
+                       handled = 1;
+                       DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
+                               ? "" : "+disconnect");
+
+                       if (!is_vbus_present())
+                               stop_activity(dev, dev->driver);
+                       else if (dev->gadget.speed != USB_SPEED_UNKNOWN
+                                       && dev->driver
+                                       && dev->driver->suspend)
+                               dev->driver->suspend(&dev->gadget);
+                       ep0_idle (dev);
+               }
+
+               /* RESume Interrupt Request */
+               if (unlikely(udccr & UDCCR_RESIR)) {
+                       udc_ack_int_UDCCR(UDCCR_RESIR);
+                       handled = 1;
+                       DBG(DBG_VERBOSE, "USB resume\n");
+
+                       if (dev->gadget.speed != USB_SPEED_UNKNOWN
+                                       && dev->driver
+                                       && dev->driver->resume
+                                       && is_vbus_present())
+                               dev->driver->resume(&dev->gadget);
+               }
+
+               /* ReSeT Interrupt Request - USB reset */
+               if (unlikely(udccr & UDCCR_RSTIR)) {
+                       udc_ack_int_UDCCR(UDCCR_RSTIR);
+                       handled = 1;
+
+                       if ((UDCCR & UDCCR_UDA) == 0) {
+                               DBG(DBG_VERBOSE, "USB reset start\n");
+
+                               /* reset driver and endpoints,
+                                * in case that's not yet done
+                                */
+                               stop_activity (dev, dev->driver);
+
+                       } else {
+                               DBG(DBG_VERBOSE, "USB reset end\n");
+                               dev->gadget.speed = USB_SPEED_FULL;
+                               memset(&dev->stats, 0, sizeof dev->stats);
+                               /* driver and endpoints are still reset */
+                       }
+
+               } else {
+                       u32     usir0 = USIR0 & ~UICR0;
+                       u32     usir1 = USIR1 & ~UICR1;
+                       int     i;
+
+                       if (unlikely (!usir0 && !usir1))
+                               continue;
+
+                       DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
+
+                       /* control traffic */
+                       if (usir0 & USIR0_IR0) {
+                               dev->ep[0].pio_irqs++;
+                               handle_ep0(dev);
+                               handled = 1;
+                       }
+
+                       /* endpoint data transfers */
+                       for (i = 0; i < 8; i++) {
+                               u32     tmp = 1 << i;
+
+                               if (i && (usir0 & tmp)) {
+                                       handle_ep(&dev->ep[i]);
+                                       USIR0 |= tmp;
+                                       handled = 1;
+                               }
+                               if (usir1 & tmp) {
+                                       handle_ep(&dev->ep[i+8]);
+                                       USIR1 |= tmp;
+                                       handled = 1;
+                               }
+                       }
+               }
+
+               /* we could also ask for 1 msec SOF (SIR) interrupts */
+
+       } while (handled);
+       return IRQ_HANDLED;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static void nop_release (struct device *dev)
+{
+       DMSG("%s %s\n", __func__, dev->bus_id);
+}
+
+/* this uses load-time allocation and initialization (instead of
+ * doing it at run-time) to save code, eliminate fault paths, and
+ * be more obviously correct.
+ */
+static struct pxa25x_udc memory = {
+       .gadget = {
+               .ops            = &pxa25x_udc_ops,
+               .ep0            = &memory.ep[0].ep,
+               .name           = driver_name,
+               .dev = {
+                       .bus_id         = "gadget",
+                       .release        = nop_release,
+               },
+       },
+
+       /* control endpoint */
+       .ep[0] = {
+               .ep = {
+                       .name           = ep0name,
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = EP0_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .reg_udccs      = &UDCCS0,
+               .reg_uddr       = &UDDR0,
+       },
+
+       /* first group of endpoints */
+       .ep[1] = {
+               .ep = {
+                       .name           = "ep1in-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 1,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS1,
+               .reg_uddr       = &UDDR1,
+       },
+       .ep[2] = {
+               .ep = {
+                       .name           = "ep2out-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = 2,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS2,
+               .reg_ubcr       = &UBCR2,
+               .reg_uddr       = &UDDR2,
+       },
+#ifndef CONFIG_USB_PXA25X_SMALL
+       .ep[3] = {
+               .ep = {
+                       .name           = "ep3in-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 3,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS3,
+               .reg_uddr       = &UDDR3,
+       },
+       .ep[4] = {
+               .ep = {
+                       .name           = "ep4out-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = 4,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS4,
+               .reg_ubcr       = &UBCR4,
+               .reg_uddr       = &UDDR4,
+       },
+       .ep[5] = {
+               .ep = {
+                       .name           = "ep5in-int",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = INT_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = INT_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 5,
+               .bmAttributes   = USB_ENDPOINT_XFER_INT,
+               .reg_udccs      = &UDCCS5,
+               .reg_uddr       = &UDDR5,
+       },
+
+       /* second group of endpoints */
+       .ep[6] = {
+               .ep = {
+                       .name           = "ep6in-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 6,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS6,
+               .reg_uddr       = &UDDR6,
+       },
+       .ep[7] = {
+               .ep = {
+                       .name           = "ep7out-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = 7,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS7,
+               .reg_ubcr       = &UBCR7,
+               .reg_uddr       = &UDDR7,
+       },
+       .ep[8] = {
+               .ep = {
+                       .name           = "ep8in-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 8,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS8,
+               .reg_uddr       = &UDDR8,
+       },
+       .ep[9] = {
+               .ep = {
+                       .name           = "ep9out-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = 9,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS9,
+               .reg_ubcr       = &UBCR9,
+               .reg_uddr       = &UDDR9,
+       },
+       .ep[10] = {
+               .ep = {
+                       .name           = "ep10in-int",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = INT_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = INT_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 10,
+               .bmAttributes   = USB_ENDPOINT_XFER_INT,
+               .reg_udccs      = &UDCCS10,
+               .reg_uddr       = &UDDR10,
+       },
+
+       /* third group of endpoints */
+       .ep[11] = {
+               .ep = {
+                       .name           = "ep11in-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 11,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS11,
+               .reg_uddr       = &UDDR11,
+       },
+       .ep[12] = {
+               .ep = {
+                       .name           = "ep12out-bulk",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = BULK_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = BULK_FIFO_SIZE,
+               .bEndpointAddress = 12,
+               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
+               .reg_udccs      = &UDCCS12,
+               .reg_ubcr       = &UBCR12,
+               .reg_uddr       = &UDDR12,
+       },
+       .ep[13] = {
+               .ep = {
+                       .name           = "ep13in-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 13,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS13,
+               .reg_uddr       = &UDDR13,
+       },
+       .ep[14] = {
+               .ep = {
+                       .name           = "ep14out-iso",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = ISO_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = ISO_FIFO_SIZE,
+               .bEndpointAddress = 14,
+               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
+               .reg_udccs      = &UDCCS14,
+               .reg_ubcr       = &UBCR14,
+               .reg_uddr       = &UDDR14,
+       },
+       .ep[15] = {
+               .ep = {
+                       .name           = "ep15in-int",
+                       .ops            = &pxa25x_ep_ops,
+                       .maxpacket      = INT_FIFO_SIZE,
+               },
+               .dev            = &memory,
+               .fifo_size      = INT_FIFO_SIZE,
+               .bEndpointAddress = USB_DIR_IN | 15,
+               .bmAttributes   = USB_ENDPOINT_XFER_INT,
+               .reg_udccs      = &UDCCS15,
+               .reg_uddr       = &UDDR15,
+       },
+#endif /* !CONFIG_USB_PXA25X_SMALL */
+};
+
+#define CP15R0_VENDOR_MASK     0xffffe000
+
+#if    defined(CONFIG_ARCH_PXA)
+#define CP15R0_XSCALE_VALUE    0x69052000      /* intel/arm/xscale */
+
+#elif  defined(CONFIG_ARCH_IXP4XX)
+#define CP15R0_XSCALE_VALUE    0x69054000      /* intel/arm/ixp4xx */
+
+#endif
+
+#define CP15R0_PROD_MASK       0x000003f0
+#define PXA25x                 0x00000100      /* and PXA26x */
+#define PXA210                 0x00000120
+
+#define CP15R0_REV_MASK                0x0000000f
+
+#define CP15R0_PRODREV_MASK    (CP15R0_PROD_MASK | CP15R0_REV_MASK)
+
+#define PXA255_A0              0x00000106      /* or PXA260_B1 */
+#define PXA250_C0              0x00000105      /* or PXA26x_B0 */
+#define PXA250_B2              0x00000104
+#define PXA250_B1              0x00000103      /* or PXA260_A0 */
+#define PXA250_B0              0x00000102
+#define PXA250_A1              0x00000101
+#define PXA250_A0              0x00000100
+
+#define PXA210_C0              0x00000125
+#define PXA210_B2              0x00000124
+#define PXA210_B1              0x00000123
+#define PXA210_B0              0x00000122
+#define IXP425_A0              0x000001c1
+#define IXP425_B0              0x000001f1
+#define IXP465_AD              0x00000200
+
+/*
+ *     probe - binds to the platform device
+ */
+static int __init pxa25x_udc_probe(struct platform_device *pdev)
+{
+       struct pxa25x_udc *dev = &memory;
+       int retval, vbus_irq, irq;
+       u32 chiprev;
+
+       /* insist on Intel/ARM/XScale */
+       asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
+       if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
+               pr_err("%s: not XScale!\n", driver_name);
+               return -ENODEV;
+       }
+
+       /* trigger chiprev-specific logic */
+       switch (chiprev & CP15R0_PRODREV_MASK) {
+#if    defined(CONFIG_ARCH_PXA)
+       case PXA255_A0:
+               dev->has_cfr = 1;
+               break;
+       case PXA250_A0:
+       case PXA250_A1:
+               /* A0/A1 "not released"; ep 13, 15 unusable */
+               /* fall through */
+       case PXA250_B2: case PXA210_B2:
+       case PXA250_B1: case PXA210_B1:
+       case PXA250_B0: case PXA210_B0:
+               /* OUT-DMA is broken ... */
+               /* fall through */
+       case PXA250_C0: case PXA210_C0:
+               break;
+#elif  defined(CONFIG_ARCH_IXP4XX)
+       case IXP425_A0:
+       case IXP425_B0:
+       case IXP465_AD:
+               dev->has_cfr = 1;
+               break;
+#endif
+       default:
+               pr_err("%s: unrecognized processor: %08x\n",
+                       driver_name, chiprev);
+               /* iop3xx, ixp4xx, ... */
+               return -ENODEV;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0)
+               return -ENODEV;
+
+       dev->clk = clk_get(&pdev->dev, "UDCCLK");
+       if (IS_ERR(dev->clk)) {
+               retval = PTR_ERR(dev->clk);
+               goto err_clk;
+       }
+
+       pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
+               dev->has_cfr ? "" : " (!cfr)",
+               SIZE_STR "(pio)"
+               );
+
+       /* other non-static parts of init */
+       dev->dev = &pdev->dev;
+       dev->mach = pdev->dev.platform_data;
+
+       if (dev->mach->gpio_vbus) {
+               if ((retval = gpio_request(dev->mach->gpio_vbus,
+                               "pxa25x_udc GPIO VBUS"))) {
+                       dev_dbg(&pdev->dev,
+                               "can't get vbus gpio %d, err: %d\n",
+                               dev->mach->gpio_vbus, retval);
+                       goto err_gpio_vbus;
+               }
+               gpio_direction_input(dev->mach->gpio_vbus);
+               vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
+       } else
+               vbus_irq = 0;
+
+       if (dev->mach->gpio_pullup) {
+               if ((retval = gpio_request(dev->mach->gpio_pullup,
+                               "pca25x_udc GPIO PULLUP"))) {
+                       dev_dbg(&pdev->dev,
+                               "can't get pullup gpio %d, err: %d\n",
+                               dev->mach->gpio_pullup, retval);
+                       goto err_gpio_pullup;
+               }
+               gpio_direction_output(dev->mach->gpio_pullup, 0);
+       }
+
+       init_timer(&dev->timer);
+       dev->timer.function = udc_watchdog;
+       dev->timer.data = (unsigned long) dev;
+
+       device_initialize(&dev->gadget.dev);
+       dev->gadget.dev.parent = &pdev->dev;
+       dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
+
+       the_controller = dev;
+       platform_set_drvdata(pdev, dev);
+
+       udc_disable(dev);
+       udc_reinit(dev);
+
+       dev->vbus = is_vbus_present();
+
+       /* irq setup after old hardware state is cleaned up */
+       retval = request_irq(irq, pxa25x_udc_irq,
+                       IRQF_DISABLED, driver_name, dev);
+       if (retval != 0) {
+               pr_err("%s: can't get irq %d, err %d\n",
+                       driver_name, irq, retval);
+               goto err_irq1;
+       }
+       dev->got_irq = 1;
+
+#ifdef CONFIG_ARCH_LUBBOCK
+       if (machine_is_lubbock()) {
+               retval = request_irq(LUBBOCK_USB_DISC_IRQ,
+                               lubbock_vbus_irq,
+                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
+                               driver_name, dev);
+               if (retval != 0) {
+                       pr_err("%s: can't get irq %i, err %d\n",
+                               driver_name, LUBBOCK_USB_DISC_IRQ, retval);
+lubbock_fail0:
+                       goto err_irq_lub;
+               }
+               retval = request_irq(LUBBOCK_USB_IRQ,
+                               lubbock_vbus_irq,
+                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
+                               driver_name, dev);
+               if (retval != 0) {
+                       pr_err("%s: can't get irq %i, err %d\n",
+                               driver_name, LUBBOCK_USB_IRQ, retval);
+                       free_irq(LUBBOCK_USB_DISC_IRQ, dev);
+                       goto lubbock_fail0;
+               }
+       } else
+#endif
+       if (vbus_irq) {
+               retval = request_irq(vbus_irq, udc_vbus_irq,
+                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
+                               IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+                               driver_name, dev);
+               if (retval != 0) {
+                       pr_err("%s: can't get irq %i, err %d\n",
+                               driver_name, vbus_irq, retval);
+                       goto err_vbus_irq;
+               }
+       }
+       create_debug_files(dev);
+
+       return 0;
+
+ err_vbus_irq:
+#ifdef CONFIG_ARCH_LUBBOCK
+       free_irq(LUBBOCK_USB_DISC_IRQ, dev);
+ err_irq_lub:
+#endif
+       free_irq(irq, dev);
+ err_irq1:
+       if (dev->mach->gpio_pullup)
+               gpio_free(dev->mach->gpio_pullup);
+ err_gpio_pullup:
+       if (dev->mach->gpio_vbus)
+               gpio_free(dev->mach->gpio_vbus);
+ err_gpio_vbus:
+       clk_put(dev->clk);
+ err_clk:
+       return retval;
+}
+
+static void pxa25x_udc_shutdown(struct platform_device *_dev)
+{
+       pullup_off();
+}
+
+static int __exit pxa25x_udc_remove(struct platform_device *pdev)
+{
+       struct pxa25x_udc *dev = platform_get_drvdata(pdev);
+
+       if (dev->driver)
+               return -EBUSY;
+
+       dev->pullup = 0;
+       pullup(dev);
+
+       remove_debug_files(dev);
+
+       if (dev->got_irq) {
+               free_irq(platform_get_irq(pdev, 0), dev);
+               dev->got_irq = 0;
+       }
+#ifdef CONFIG_ARCH_LUBBOCK
+       if (machine_is_lubbock()) {
+               free_irq(LUBBOCK_USB_DISC_IRQ, dev);
+               free_irq(LUBBOCK_USB_IRQ, dev);
+       }
+#endif
+       if (dev->mach->gpio_vbus) {
+               free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
+               gpio_free(dev->mach->gpio_vbus);
+       }
+       if (dev->mach->gpio_pullup)
+               gpio_free(dev->mach->gpio_pullup);
+
+       clk_put(dev->clk);
+
+       platform_set_drvdata(pdev, NULL);
+       the_controller = NULL;
+       return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_PM
+
+/* USB suspend (controlled by the host) and system suspend (controlled
+ * by the PXA) don't necessarily work well together.  If USB is active,
+ * the 48 MHz clock is required; so the system can't enter 33 MHz idle
+ * mode, or any deeper PM saving state.
+ *
+ * For now, we punt and forcibly disconnect from the USB host when PXA
+ * enters any suspend state.  While we're disconnected, we always disable
+ * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
+ * Boards without software pullup control shouldn't use those states.
+ * VBUS IRQs should probably be ignored so that the PXA device just acts
+ * "dead" to USB hosts until system resume.
+ */
+static int pxa25x_udc_suspend(struct platform_device *dev, pm_message_t state)
+{
+       struct pxa25x_udc       *udc = platform_get_drvdata(dev);
+       unsigned long flags;
+
+       if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
+               WARN("USB host won't detect disconnect!\n");
+       udc->suspended = 1;
+
+       local_irq_save(flags);
+       pullup(udc);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+static int pxa25x_udc_resume(struct platform_device *dev)
+{
+       struct pxa25x_udc       *udc = platform_get_drvdata(dev);
+       unsigned long flags;
+
+       udc->suspended = 0;
+       local_irq_save(flags);
+       pullup(udc);
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+#else
+#define        pxa25x_udc_suspend      NULL
+#define        pxa25x_udc_resume       NULL
+#endif
+
+/*-------------------------------------------------------------------------*/
+
+static struct platform_driver udc_driver = {
+       .shutdown       = pxa25x_udc_shutdown,
+       .remove         = __exit_p(pxa25x_udc_remove),
+       .suspend        = pxa25x_udc_suspend,
+       .resume         = pxa25x_udc_resume,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "pxa25x-udc",
+       },
+};
+
+static int __init udc_init(void)
+{
+       pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
+       return platform_driver_probe(&udc_driver, pxa25x_udc_probe);
+}
+module_init(udc_init);
+
+static void __exit udc_exit(void)
+{
+       platform_driver_unregister(&udc_driver);
+}
+module_exit(udc_exit);
+
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pxa25x-udc");
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
new file mode 100644 (file)
index 0000000..4d11ece
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Intel PXA25x on-chip full speed USB device controller
+ *
+ * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
+ * Copyright (C) 2003 David Brownell
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __LINUX_USB_GADGET_PXA25X_H
+#define __LINUX_USB_GADGET_PXA25X_H
+
+#include <linux/types.h>
+
+/*-------------------------------------------------------------------------*/
+
+/* pxa25x has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
+#define UFNRH_SIR      (1 << 7)        /* SOF interrupt request */
+#define UFNRH_SIM      (1 << 6)        /* SOF interrupt mask */
+#define UFNRH_IPE14    (1 << 5)        /* ISO packet error, ep14 */
+#define UFNRH_IPE9     (1 << 4)        /* ISO packet error, ep9 */
+#define UFNRH_IPE4     (1 << 3)        /* ISO packet error, ep4 */
+
+/* pxa255 has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
+#define        UDCCFR          UDC_RES2        /* UDC Control Function Register */
+#define UDCCFR_AREN    (1 << 7)        /* ACK response enable (now) */
+#define UDCCFR_ACM     (1 << 2)        /* ACK control mode (wait for AREN) */
+
+/* latest pxa255 errata define new "must be one" bits in UDCCFR */
+#define        UDCCFR_MB1      (0xff & ~(UDCCFR_AREN|UDCCFR_ACM))
+
+/*-------------------------------------------------------------------------*/
+
+struct pxa25x_udc;
+
+struct pxa25x_ep {
+       struct usb_ep                           ep;
+       struct pxa25x_udc                       *dev;
+
+       const struct usb_endpoint_descriptor    *desc;
+       struct list_head                        queue;
+       unsigned long                           pio_irqs;
+
+       unsigned short                          fifo_size;
+       u8                                      bEndpointAddress;
+       u8                                      bmAttributes;
+
+       unsigned                                stopped : 1;
+       unsigned                                dma_fixup : 1;
+
+       /* UDCCS = UDC Control/Status for this EP
+        * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
+        * UDDR = UDC Endpoint Data Register (the fifo)
+        * DRCM = DMA Request Channel Map
+        */
+       volatile u32                            *reg_udccs;
+       volatile u32                            *reg_ubcr;
+       volatile u32                            *reg_uddr;
+};
+
+struct pxa25x_request {
+       struct usb_request                      req;
+       struct list_head                        queue;
+};
+
+enum ep0_state {
+       EP0_IDLE,
+       EP0_IN_DATA_PHASE,
+       EP0_OUT_DATA_PHASE,
+       EP0_END_XFER,
+       EP0_STALL,
+};
+
+#define EP0_FIFO_SIZE  ((unsigned)16)
+#define BULK_FIFO_SIZE ((unsigned)64)
+#define ISO_FIFO_SIZE  ((unsigned)256)
+#define INT_FIFO_SIZE  ((unsigned)8)
+
+struct udc_stats {
+       struct ep0stats {
+               unsigned long           ops;
+               unsigned long           bytes;
+       } read, write;
+       unsigned long                   irqs;
+};
+
+#ifdef CONFIG_USB_PXA25X_SMALL
+/* when memory's tight, SMALL config saves code+data.  */
+#define        PXA_UDC_NUM_ENDPOINTS   3
+#endif
+
+#ifndef        PXA_UDC_NUM_ENDPOINTS
+#define        PXA_UDC_NUM_ENDPOINTS   16
+#endif
+
+struct pxa25x_udc {
+       struct usb_gadget                       gadget;
+       struct usb_gadget_driver                *driver;
+
+       enum ep0_state                          ep0state;
+       struct udc_stats                        stats;
+       unsigned                                got_irq : 1,
+                                               vbus : 1,
+                                               pullup : 1,
+                                               has_cfr : 1,
+                                               req_pending : 1,
+                                               req_std : 1,
+                                               req_config : 1,
+                                               suspended : 1,
+                                               active : 1;
+
+#define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
+       struct timer_list                       timer;
+
+       struct device                           *dev;
+       struct clk                              *clk;
+       struct pxa2xx_udc_mach_info             *mach;
+       u64                                     dma_mask;
+       struct pxa25x_ep                        ep [PXA_UDC_NUM_ENDPOINTS];
+
+#ifdef CONFIG_USB_GADGET_DEBUG_FS
+       struct dentry                           *debugfs_udc;
+#endif
+};
+
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_ARCH_LUBBOCK
+#include <asm/arch/lubbock.h>
+/* lubbock can also report usb connect/disconnect irqs */
+#endif
+
+static struct pxa25x_udc *the_controller;
+
+/*-------------------------------------------------------------------------*/
+
+/*
+ * Debugging support vanishes in non-debug builds.  DBG_NORMAL should be
+ * mostly silent during normal use/testing, with no timing side-effects.
+ */
+#define DBG_NORMAL     1       /* error paths, device state transitions */
+#define DBG_VERBOSE    2       /* add some success path trace info */
+#define DBG_NOISY      3       /* ... even more: request level */
+#define DBG_VERY_NOISY 4       /* ... even more: packet level */
+
+#define DMSG(stuff...) pr_debug("udc: " stuff)
+
+#ifdef DEBUG
+
+static int is_vbus_present(void);
+
+static const char *state_name[] = {
+       "EP0_IDLE",
+       "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
+       "EP0_END_XFER", "EP0_STALL"
+};
+
+#ifdef VERBOSE_DEBUG
+#    define UDC_DEBUG DBG_VERBOSE
+#else
+#    define UDC_DEBUG DBG_NORMAL
+#endif
+
+static void __maybe_unused
+dump_udccr(const char *label)
+{
+       u32     udccr = UDCCR;
+       DMSG("%s %02X =%s%s%s%s%s%s%s%s\n",
+               label, udccr,
+               (udccr & UDCCR_REM) ? " rem" : "",
+               (udccr & UDCCR_RSTIR) ? " rstir" : "",
+               (udccr & UDCCR_SRM) ? " srm" : "",
+               (udccr & UDCCR_SUSIR) ? " susir" : "",
+               (udccr & UDCCR_RESIR) ? " resir" : "",
+               (udccr & UDCCR_RSM) ? " rsm" : "",
+               (udccr & UDCCR_UDA) ? " uda" : "",
+               (udccr & UDCCR_UDE) ? " ude" : "");
+}
+
+static void __maybe_unused
+dump_udccs0(const char *label)
+{
+       u32             udccs0 = UDCCS0;
+
+       DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n",
+               label, state_name[the_controller->ep0state], udccs0,
+               (udccs0 & UDCCS0_SA) ? " sa" : "",
+               (udccs0 & UDCCS0_RNE) ? " rne" : "",
+               (udccs0 & UDCCS0_FST) ? " fst" : "",
+               (udccs0 & UDCCS0_SST) ? " sst" : "",
+               (udccs0 & UDCCS0_DRWF) ? " dwrf" : "",
+               (udccs0 & UDCCS0_FTF) ? " ftf" : "",
+               (udccs0 & UDCCS0_IPR) ? " ipr" : "",
+               (udccs0 & UDCCS0_OPR) ? " opr" : "");
+}
+
+static void __maybe_unused
+dump_state(struct pxa25x_udc *dev)
+{
+       u32             tmp;
+       unsigned        i;
+
+       DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
+               is_vbus_present() ? "host " : "disconnected",
+               state_name[dev->ep0state],
+               UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
+       dump_udccr("udccr");
+       if (dev->has_cfr) {
+               tmp = UDCCFR;
+               DMSG("udccfr %02X =%s%s\n", tmp,
+                       (tmp & UDCCFR_AREN) ? " aren" : "",
+                       (tmp & UDCCFR_ACM) ? " acm" : "");
+       }
+
+       if (!dev->driver) {
+               DMSG("no gadget driver bound\n");
+               return;
+       } else
+               DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
+
+       if (!is_vbus_present())
+               return;
+
+       dump_udccs0 ("udccs0");
+       DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n",
+               dev->stats.write.bytes, dev->stats.write.ops,
+               dev->stats.read.bytes, dev->stats.read.ops);
+
+       for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
+               if (dev->ep [i].desc == NULL)
+                       continue;
+               DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
+       }
+}
+
+#else
+
+#define        dump_udccr(x)   do{}while(0)
+#define        dump_udccs0(x)  do{}while(0)
+#define        dump_state(x)   do{}while(0)
+
+#define UDC_DEBUG ((unsigned)0)
+
+#endif
+
+#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
+
+#define ERR(stuff...)          pr_err("udc: " stuff)
+#define WARN(stuff...)         pr_warning("udc: " stuff)
+#define INFO(stuff...)         pr_info("udc: " stuff)
+
+
+#endif /* __LINUX_USB_GADGET_PXA25X_H */
index e02bfd4..9c0e82e 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/usb.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
-
+#include <asm/arch/pxa2xx-regs.h> /* FIXME: for PSSR */
 #include <asm/arch/udc.h>
 
 #include "pxa27x_udc.h"
@@ -2360,18 +2360,19 @@ static int pxa_udc_resume(struct platform_device *_dev)
         * Software must configure the USB OTG pad, UDC, and UHC
         * to the state they were in before entering sleep mode.
         */
-       PSSR |= PSSR_OTGPH;
+       if (cpu_is_pxa27x())
+               PSSR |= PSSR_OTGPH;
 
        return 0;
 }
 #endif
 
 /* work with hotplug and coldplug */
-MODULE_ALIAS("platform:pxa2xx-udc");
+MODULE_ALIAS("platform:pxa27x-udc");
 
 static struct platform_driver udc_driver = {
        .driver         = {
-               .name   = "pxa2xx-udc",
+               .name   = "pxa27x-udc",
                .owner  = THIS_MODULE,
        },
        .remove         = __exit_p(pxa_udc_remove),
index 97453db..1d1b793 100644 (file)
@@ -484,12 +484,4 @@ static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
 #define ep_warn(ep, fmt, arg...) \
        dev_warn(ep->dev->dev, "%s:%s:" fmt, EPNAME(ep), __func__, ## arg)
 
-/*
- * Cannot include pxa-regs.h, as register names are similar.
- * So PSSR is redefined here. This should be removed once UDC registers will
- * be gone from pxa-regs.h.
- */
-#define PSSR           __REG(0x40F00004)       /* Power Manager Sleep Status */
-#define PSSR_OTGPH     (1 << 6)                /* OTG Peripheral Hold */
-
 #endif /* __LINUX_USB_GADGET_PXA27X_H */
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
deleted file mode 100644 (file)
index 08f699b..0000000
+++ /dev/null
@@ -1,2383 +0,0 @@
-/*
- * linux/drivers/usb/gadget/pxa2xx_udc.c
- * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
- *
- * Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
- * Copyright (C) 2003 Robert Schwebel, Pengutronix
- * Copyright (C) 2003 Benedikt Spranger, Pengutronix
- * Copyright (C) 2003 David Brownell
- * Copyright (C) 2003 Joshua Wise
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/device.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/delay.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/timer.h>
-#include <linux/list.h>
-#include <linux/interrupt.h>
-#include <linux/mm.h>
-#include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
-#include <linux/irq.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/seq_file.h>
-#include <linux/debugfs.h>
-
-#include <asm/byteorder.h>
-#include <asm/dma.h>
-#include <asm/gpio.h>
-#include <asm/io.h>
-#include <asm/system.h>
-#include <asm/mach-types.h>
-#include <asm/unaligned.h>
-#include <asm/hardware.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-
-#include <asm/mach/udc_pxa2xx.h>
-
-
-/*
- * This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
- * series processors.  The UDC for the IXP 4xx series is very similar.
- * There are fifteen endpoints, in addition to ep0.
- *
- * Such controller drivers work with a gadget driver.  The gadget driver
- * returns descriptors, implements configuration and data protocols used
- * by the host to interact with this device, and allocates endpoints to
- * the different protocol interfaces.  The controller driver virtualizes
- * usb hardware so that the gadget drivers will be more portable.
- *
- * This UDC hardware wants to implement a bit too much USB protocol, so
- * it constrains the sorts of USB configuration change events that work.
- * The errata for these chips are misleading; some "fixed" bugs from
- * pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
- *
- * Note that the UDC hardware supports DMA (except on IXP) but that's
- * not used here.  IN-DMA (to host) is simple enough, when the data is
- * suitably aligned (16 bytes) ... the network stack doesn't do that,
- * other software can.  OUT-DMA is buggy in most chip versions, as well
- * as poorly designed (data toggle not automatic).  So this driver won't
- * bother using DMA.  (Mostly-working IN-DMA support was available in
- * kernels before 2.6.23, but was never enabled or well tested.)
- */
-
-#define        DRIVER_VERSION  "30-June-2007"
-#define        DRIVER_DESC     "PXA 25x USB Device Controller driver"
-
-
-static const char driver_name [] = "pxa2xx_udc";
-
-static const char ep0name [] = "ep0";
-
-
-#ifdef CONFIG_ARCH_IXP4XX
-
-/* cpu-specific register addresses are compiled in to this code */
-#ifdef CONFIG_ARCH_PXA
-#error "Can't configure both IXP and PXA"
-#endif
-
-/* IXP doesn't yet support <linux/clk.h> */
-#define clk_get(dev,name)      NULL
-#define clk_enable(clk)                do { } while (0)
-#define clk_disable(clk)       do { } while (0)
-#define clk_put(clk)           do { } while (0)
-
-#endif
-
-#include "pxa2xx_udc.h"
-
-
-#ifdef CONFIG_USB_PXA2XX_SMALL
-#define SIZE_STR       " (small)"
-#else
-#define SIZE_STR       ""
-#endif
-
-/* ---------------------------------------------------------------------------
- *     endpoint related parts of the api to the usb controller hardware,
- *     used by gadget driver; and the inner talker-to-hardware core.
- * ---------------------------------------------------------------------------
- */
-
-static void pxa2xx_ep_fifo_flush (struct usb_ep *ep);
-static void nuke (struct pxa2xx_ep *, int status);
-
-/* one GPIO should be used to detect VBUS from the host */
-static int is_vbus_present(void)
-{
-       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
-
-       if (mach->gpio_vbus) {
-               int value = gpio_get_value(mach->gpio_vbus);
-               return mach->gpio_vbus_inverted ? !value : value;
-       }
-       if (mach->udc_is_connected)
-               return mach->udc_is_connected();
-       return 1;
-}
-
-/* one GPIO should control a D+ pullup, so host sees this device (or not) */
-static void pullup_off(void)
-{
-       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
-
-       if (mach->gpio_pullup)
-               gpio_set_value(mach->gpio_pullup, 0);
-       else if (mach->udc_command)
-               mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
-}
-
-static void pullup_on(void)
-{
-       struct pxa2xx_udc_mach_info             *mach = the_controller->mach;
-
-       if (mach->gpio_pullup)
-               gpio_set_value(mach->gpio_pullup, 1);
-       else if (mach->udc_command)
-               mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
-}
-
-static void pio_irq_enable(int bEndpointAddress)
-{
-        bEndpointAddress &= 0xf;
-        if (bEndpointAddress < 8)
-                UICR0 &= ~(1 << bEndpointAddress);
-        else {
-                bEndpointAddress -= 8;
-                UICR1 &= ~(1 << bEndpointAddress);
-       }
-}
-
-static void pio_irq_disable(int bEndpointAddress)
-{
-        bEndpointAddress &= 0xf;
-        if (bEndpointAddress < 8)
-                UICR0 |= 1 << bEndpointAddress;
-        else {
-                bEndpointAddress -= 8;
-                UICR1 |= 1 << bEndpointAddress;
-        }
-}
-
-/* The UDCCR reg contains mask and interrupt status bits,
- * so using '|=' isn't safe as it may ack an interrupt.
- */
-#define UDCCR_MASK_BITS         (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
-
-static inline void udc_set_mask_UDCCR(int mask)
-{
-       UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
-}
-
-static inline void udc_clear_mask_UDCCR(int mask)
-{
-       UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
-}
-
-static inline void udc_ack_int_UDCCR(int mask)
-{
-       /* udccr contains the bits we dont want to change */
-       __u32 udccr = UDCCR & UDCCR_MASK_BITS;
-
-       UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
-}
-
-/*
- * endpoint enable/disable
- *
- * we need to verify the descriptors used to enable endpoints.  since pxa2xx
- * endpoint configurations are fixed, and are pretty much always enabled,
- * there's not a lot to manage here.
- *
- * because pxa2xx can't selectively initialize bulk (or interrupt) endpoints,
- * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
- * for a single interface (with only the default altsetting) and for gadget
- * drivers that don't halt endpoints (not reset by set_interface).  that also
- * means that if you use ISO, you must violate the USB spec rule that all
- * iso endpoints must be in non-default altsettings.
- */
-static int pxa2xx_ep_enable (struct usb_ep *_ep,
-               const struct usb_endpoint_descriptor *desc)
-{
-       struct pxa2xx_ep        *ep;
-       struct pxa2xx_udc       *dev;
-
-       ep = container_of (_ep, struct pxa2xx_ep, ep);
-       if (!_ep || !desc || ep->desc || _ep->name == ep0name
-                       || desc->bDescriptorType != USB_DT_ENDPOINT
-                       || ep->bEndpointAddress != desc->bEndpointAddress
-                       || ep->fifo_size < le16_to_cpu
-                                               (desc->wMaxPacketSize)) {
-               DMSG("%s, bad ep or descriptor\n", __func__);
-               return -EINVAL;
-       }
-
-       /* xfer types must match, except that interrupt ~= bulk */
-       if (ep->bmAttributes != desc->bmAttributes
-                       && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
-                       && desc->bmAttributes != USB_ENDPOINT_XFER_INT) {
-               DMSG("%s, %s type mismatch\n", __func__, _ep->name);
-               return -EINVAL;
-       }
-
-       /* hardware _could_ do smaller, but driver doesn't */
-       if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
-                               && le16_to_cpu (desc->wMaxPacketSize)
-                                               != BULK_FIFO_SIZE)
-                       || !desc->wMaxPacketSize) {
-               DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
-               return -ERANGE;
-       }
-
-       dev = ep->dev;
-       if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
-               DMSG("%s, bogus device state\n", __func__);
-               return -ESHUTDOWN;
-       }
-
-       ep->desc = desc;
-       ep->stopped = 0;
-       ep->pio_irqs = 0;
-       ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
-
-       /* flush fifo (mostly for OUT buffers) */
-       pxa2xx_ep_fifo_flush (_ep);
-
-       /* ... reset halt state too, if we could ... */
-
-       DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
-       return 0;
-}
-
-static int pxa2xx_ep_disable (struct usb_ep *_ep)
-{
-       struct pxa2xx_ep        *ep;
-       unsigned long           flags;
-
-       ep = container_of (_ep, struct pxa2xx_ep, ep);
-       if (!_ep || !ep->desc) {
-               DMSG("%s, %s not enabled\n", __func__,
-                       _ep ? ep->ep.name : NULL);
-               return -EINVAL;
-       }
-       local_irq_save(flags);
-
-       nuke (ep, -ESHUTDOWN);
-
-       /* flush fifo (mostly for IN buffers) */
-       pxa2xx_ep_fifo_flush (_ep);
-
-       ep->desc = NULL;
-       ep->stopped = 1;
-
-       local_irq_restore(flags);
-       DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
-       return 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* for the pxa2xx, these can just wrap kmalloc/kfree.  gadget drivers
- * must still pass correctly initialized endpoints, since other controller
- * drivers may care about how it's currently set up (dma issues etc).
- */
-
-/*
- *     pxa2xx_ep_alloc_request - allocate a request data structure
- */
-static struct usb_request *
-pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
-{
-       struct pxa2xx_request *req;
-
-       req = kzalloc(sizeof(*req), gfp_flags);
-       if (!req)
-               return NULL;
-
-       INIT_LIST_HEAD (&req->queue);
-       return &req->req;
-}
-
-
-/*
- *     pxa2xx_ep_free_request - deallocate a request data structure
- */
-static void
-pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
-{
-       struct pxa2xx_request   *req;
-
-       req = container_of (_req, struct pxa2xx_request, req);
-       WARN_ON (!list_empty (&req->queue));
-       kfree(req);
-}
-
-/*-------------------------------------------------------------------------*/
-
-/*
- *     done - retire a request; caller blocked irqs
- */
-static void done(struct pxa2xx_ep *ep, struct pxa2xx_request *req, int status)
-{
-       unsigned                stopped = ep->stopped;
-
-       list_del_init(&req->queue);
-
-       if (likely (req->req.status == -EINPROGRESS))
-               req->req.status = status;
-       else
-               status = req->req.status;
-
-       if (status && status != -ESHUTDOWN)
-               DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n",
-                       ep->ep.name, &req->req, status,
-                       req->req.actual, req->req.length);
-
-       /* don't modify queue heads during completion callback */
-       ep->stopped = 1;
-       req->req.complete(&ep->ep, &req->req);
-       ep->stopped = stopped;
-}
-
-
-static inline void ep0_idle (struct pxa2xx_udc *dev)
-{
-       dev->ep0state = EP0_IDLE;
-}
-
-static int
-write_packet(volatile u32 *uddr, struct pxa2xx_request *req, unsigned max)
-{
-       u8              *buf;
-       unsigned        length, count;
-
-       buf = req->req.buf + req->req.actual;
-       prefetch(buf);
-
-       /* how big will this packet be? */
-       length = min(req->req.length - req->req.actual, max);
-       req->req.actual += length;
-
-       count = length;
-       while (likely(count--))
-               *uddr = *buf++;
-
-       return length;
-}
-
-/*
- * write to an IN endpoint fifo, as many packets as possible.
- * irqs will use this to write the rest later.
- * caller guarantees at least one packet buffer is ready (or a zlp).
- */
-static int
-write_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
-{
-       unsigned                max;
-
-       max = le16_to_cpu(ep->desc->wMaxPacketSize);
-       do {
-               unsigned        count;
-               int             is_last, is_short;
-
-               count = write_packet(ep->reg_uddr, req, max);
-
-               /* last packet is usually short (or a zlp) */
-               if (unlikely (count != max))
-                       is_last = is_short = 1;
-               else {
-                       if (likely(req->req.length != req->req.actual)
-                                       || req->req.zero)
-                               is_last = 0;
-                       else
-                               is_last = 1;
-                       /* interrupt/iso maxpacket may not fill the fifo */
-                       is_short = unlikely (max < ep->fifo_size);
-               }
-
-               DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n",
-                       ep->ep.name, count,
-                       is_last ? "/L" : "", is_short ? "/S" : "",
-                       req->req.length - req->req.actual, req);
-
-               /* let loose that packet. maybe try writing another one,
-                * double buffering might work.  TSP, TPC, and TFS
-                * bit values are the same for all normal IN endpoints.
-                */
-               *ep->reg_udccs = UDCCS_BI_TPC;
-               if (is_short)
-                       *ep->reg_udccs = UDCCS_BI_TSP;
-
-               /* requests complete when all IN data is in the FIFO */
-               if (is_last) {
-                       done (ep, req, 0);
-                       if (list_empty(&ep->queue))
-                               pio_irq_disable (ep->bEndpointAddress);
-                       return 1;
-               }
-
-               // TODO experiment: how robust can fifo mode tweaking be?
-               // double buffering is off in the default fifo mode, which
-               // prevents TFS from being set here.
-
-       } while (*ep->reg_udccs & UDCCS_BI_TFS);
-       return 0;
-}
-
-/* caller asserts req->pending (ep0 irq status nyet cleared); starts
- * ep0 data stage.  these chips want very simple state transitions.
- */
-static inline
-void ep0start(struct pxa2xx_udc *dev, u32 flags, const char *tag)
-{
-       UDCCS0 = flags|UDCCS0_SA|UDCCS0_OPR;
-       USIR0 = USIR0_IR0;
-       dev->req_pending = 0;
-       DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
-               __func__, tag, UDCCS0, flags);
-}
-
-static int
-write_ep0_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
-{
-       unsigned        count;
-       int             is_short;
-
-       count = write_packet(&UDDR0, req, EP0_FIFO_SIZE);
-       ep->dev->stats.write.bytes += count;
-
-       /* last packet "must be" short (or a zlp) */
-       is_short = (count != EP0_FIFO_SIZE);
-
-       DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
-               req->req.length - req->req.actual, req);
-
-       if (unlikely (is_short)) {
-               if (ep->dev->req_pending)
-                       ep0start(ep->dev, UDCCS0_IPR, "short IN");
-               else
-                       UDCCS0 = UDCCS0_IPR;
-
-               count = req->req.length;
-               done (ep, req, 0);
-               ep0_idle(ep->dev);
-#ifndef CONFIG_ARCH_IXP4XX
-#if 1
-               /* This seems to get rid of lost status irqs in some cases:
-                * host responds quickly, or next request involves config
-                * change automagic, or should have been hidden, or ...
-                *
-                * FIXME get rid of all udelays possible...
-                */
-               if (count >= EP0_FIFO_SIZE) {
-                       count = 100;
-                       do {
-                               if ((UDCCS0 & UDCCS0_OPR) != 0) {
-                                       /* clear OPR, generate ack */
-                                       UDCCS0 = UDCCS0_OPR;
-                                       break;
-                               }
-                               count--;
-                               udelay(1);
-                       } while (count);
-               }
-#endif
-#endif
-       } else if (ep->dev->req_pending)
-               ep0start(ep->dev, 0, "IN");
-       return is_short;
-}
-
-
-/*
- * read_fifo -  unload packet(s) from the fifo we use for usb OUT
- * transfers and put them into the request.  caller should have made
- * sure there's at least one packet ready.
- *
- * returns true if the request completed because of short packet or the
- * request buffer having filled (and maybe overran till end-of-packet).
- */
-static int
-read_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
-{
-       for (;;) {
-               u32             udccs;
-               u8              *buf;
-               unsigned        bufferspace, count, is_short;
-
-               /* make sure there's a packet in the FIFO.
-                * UDCCS_{BO,IO}_RPC are all the same bit value.
-                * UDCCS_{BO,IO}_RNE are all the same bit value.
-                */
-               udccs = *ep->reg_udccs;
-               if (unlikely ((udccs & UDCCS_BO_RPC) == 0))
-                       break;
-               buf = req->req.buf + req->req.actual;
-               prefetchw(buf);
-               bufferspace = req->req.length - req->req.actual;
-
-               /* read all bytes from this packet */
-               if (likely (udccs & UDCCS_BO_RNE)) {
-                       count = 1 + (0x0ff & *ep->reg_ubcr);
-                       req->req.actual += min (count, bufferspace);
-               } else /* zlp */
-                       count = 0;
-               is_short = (count < ep->ep.maxpacket);
-               DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n",
-                       ep->ep.name, udccs, count,
-                       is_short ? "/S" : "",
-                       req, req->req.actual, req->req.length);
-               while (likely (count-- != 0)) {
-                       u8      byte = (u8) *ep->reg_uddr;
-
-                       if (unlikely (bufferspace == 0)) {
-                               /* this happens when the driver's buffer
-                                * is smaller than what the host sent.
-                                * discard the extra data.
-                                */
-                               if (req->req.status != -EOVERFLOW)
-                                       DMSG("%s overflow %d\n",
-                                               ep->ep.name, count);
-                               req->req.status = -EOVERFLOW;
-                       } else {
-                               *buf++ = byte;
-                               bufferspace--;
-                       }
-               }
-               *ep->reg_udccs =  UDCCS_BO_RPC;
-               /* RPC/RSP/RNE could now reflect the other packet buffer */
-
-               /* iso is one request per packet */
-               if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
-                       if (udccs & UDCCS_IO_ROF)
-                               req->req.status = -EHOSTUNREACH;
-                       /* more like "is_done" */
-                       is_short = 1;
-               }
-
-               /* completion */
-               if (is_short || req->req.actual == req->req.length) {
-                       done (ep, req, 0);
-                       if (list_empty(&ep->queue))
-                               pio_irq_disable (ep->bEndpointAddress);
-                       return 1;
-               }
-
-               /* finished that packet.  the next one may be waiting... */
-       }
-       return 0;
-}
-
-/*
- * special ep0 version of the above.  no UBCR0 or double buffering; status
- * handshaking is magic.  most device protocols don't need control-OUT.
- * CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
- * protocols do use them.
- */
-static int
-read_ep0_fifo (struct pxa2xx_ep *ep, struct pxa2xx_request *req)
-{
-       u8              *buf, byte;
-       unsigned        bufferspace;
-
-       buf = req->req.buf + req->req.actual;
-       bufferspace = req->req.length - req->req.actual;
-
-       while (UDCCS0 & UDCCS0_RNE) {
-               byte = (u8) UDDR0;
-
-               if (unlikely (bufferspace == 0)) {
-                       /* this happens when the driver's buffer
-                        * is smaller than what the host sent.
-                        * discard the extra data.
-                        */
-                       if (req->req.status != -EOVERFLOW)
-                               DMSG("%s overflow\n", ep->ep.name);
-                       req->req.status = -EOVERFLOW;
-               } else {
-                       *buf++ = byte;
-                       req->req.actual++;
-                       bufferspace--;
-               }
-       }
-
-       UDCCS0 = UDCCS0_OPR | UDCCS0_IPR;
-
-       /* completion */
-       if (req->req.actual >= req->req.length)
-               return 1;
-
-       /* finished that packet.  the next one may be waiting... */
-       return 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static int
-pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
-{
-       struct pxa2xx_request   *req;
-       struct pxa2xx_ep        *ep;
-       struct pxa2xx_udc       *dev;
-       unsigned long           flags;
-
-       req = container_of(_req, struct pxa2xx_request, req);
-       if (unlikely (!_req || !_req->complete || !_req->buf
-                       || !list_empty(&req->queue))) {
-               DMSG("%s, bad params\n", __func__);
-               return -EINVAL;
-       }
-
-       ep = container_of(_ep, struct pxa2xx_ep, ep);
-       if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
-               DMSG("%s, bad ep\n", __func__);
-               return -EINVAL;
-       }
-
-       dev = ep->dev;
-       if (unlikely (!dev->driver
-                       || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
-               DMSG("%s, bogus device state\n", __func__);
-               return -ESHUTDOWN;
-       }
-
-       /* iso is always one packet per request, that's the only way
-        * we can report per-packet status.  that also helps with dma.
-        */
-       if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
-                       && req->req.length > le16_to_cpu
-                                               (ep->desc->wMaxPacketSize)))
-               return -EMSGSIZE;
-
-       DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
-               _ep->name, _req, _req->length, _req->buf);
-
-       local_irq_save(flags);
-
-       _req->status = -EINPROGRESS;
-       _req->actual = 0;
-
-       /* kickstart this i/o queue? */
-       if (list_empty(&ep->queue) && !ep->stopped) {
-               if (ep->desc == NULL/* ep0 */) {
-                       unsigned        length = _req->length;
-
-                       switch (dev->ep0state) {
-                       case EP0_IN_DATA_PHASE:
-                               dev->stats.write.ops++;
-                               if (write_ep0_fifo(ep, req))
-                                       req = NULL;
-                               break;
-
-                       case EP0_OUT_DATA_PHASE:
-                               dev->stats.read.ops++;
-                               /* messy ... */
-                               if (dev->req_config) {
-                                       DBG(DBG_VERBOSE, "ep0 config ack%s\n",
-                                               dev->has_cfr ?  "" : " raced");
-                                       if (dev->has_cfr)
-                                               UDCCFR = UDCCFR_AREN|UDCCFR_ACM
-                                                       |UDCCFR_MB1;
-                                       done(ep, req, 0);
-                                       dev->ep0state = EP0_END_XFER;
-                                       local_irq_restore (flags);
-                                       return 0;
-                               }
-                               if (dev->req_pending)
-                                       ep0start(dev, UDCCS0_IPR, "OUT");
-                               if (length == 0 || ((UDCCS0 & UDCCS0_RNE) != 0
-                                               && read_ep0_fifo(ep, req))) {
-                                       ep0_idle(dev);
-                                       done(ep, req, 0);
-                                       req = NULL;
-                               }
-                               break;
-
-                       default:
-                               DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
-                               local_irq_restore (flags);
-                               return -EL2HLT;
-                       }
-               /* can the FIFO can satisfy the request immediately? */
-               } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
-                       if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
-                                       && write_fifo(ep, req))
-                               req = NULL;
-               } else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
-                               && read_fifo(ep, req)) {
-                       req = NULL;
-               }
-
-               if (likely (req && ep->desc))
-                       pio_irq_enable(ep->bEndpointAddress);
-       }
-
-       /* pio or dma irq handler advances the queue. */
-       if (likely(req != NULL))
-               list_add_tail(&req->queue, &ep->queue);
-       local_irq_restore(flags);
-
-       return 0;
-}
-
-
-/*
- *     nuke - dequeue ALL requests
- */
-static void nuke(struct pxa2xx_ep *ep, int status)
-{
-       struct pxa2xx_request *req;
-
-       /* called with irqs blocked */
-       while (!list_empty(&ep->queue)) {
-               req = list_entry(ep->queue.next,
-                               struct pxa2xx_request,
-                               queue);
-               done(ep, req, status);
-       }
-       if (ep->desc)
-               pio_irq_disable (ep->bEndpointAddress);
-}
-
-
-/* dequeue JUST ONE request */
-static int pxa2xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
-{
-       struct pxa2xx_ep        *ep;
-       struct pxa2xx_request   *req;
-       unsigned long           flags;
-
-       ep = container_of(_ep, struct pxa2xx_ep, ep);
-       if (!_ep || ep->ep.name == ep0name)
-               return -EINVAL;
-
-       local_irq_save(flags);
-
-       /* make sure it's actually queued on this endpoint */
-       list_for_each_entry (req, &ep->queue, queue) {
-               if (&req->req == _req)
-                       break;
-       }
-       if (&req->req != _req) {
-               local_irq_restore(flags);
-               return -EINVAL;
-       }
-
-       done(ep, req, -ECONNRESET);
-
-       local_irq_restore(flags);
-       return 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static int pxa2xx_ep_set_halt(struct usb_ep *_ep, int value)
-{
-       struct pxa2xx_ep        *ep;
-       unsigned long           flags;
-
-       ep = container_of(_ep, struct pxa2xx_ep, ep);
-       if (unlikely (!_ep
-                       || (!ep->desc && ep->ep.name != ep0name))
-                       || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
-               DMSG("%s, bad ep\n", __func__);
-               return -EINVAL;
-       }
-       if (value == 0) {
-               /* this path (reset toggle+halt) is needed to implement
-                * SET_INTERFACE on normal hardware.  but it can't be
-                * done from software on the PXA UDC, and the hardware
-                * forgets to do it as part of SET_INTERFACE automagic.
-                */
-               DMSG("only host can clear %s halt\n", _ep->name);
-               return -EROFS;
-       }
-
-       local_irq_save(flags);
-
-       if ((ep->bEndpointAddress & USB_DIR_IN) != 0
-                       && ((*ep->reg_udccs & UDCCS_BI_TFS) == 0
-                          || !list_empty(&ep->queue))) {
-               local_irq_restore(flags);
-               return -EAGAIN;
-       }
-
-       /* FST bit is the same for control, bulk in, bulk out, interrupt in */
-       *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF;
-
-       /* ep0 needs special care */
-       if (!ep->desc) {
-               start_watchdog(ep->dev);
-               ep->dev->req_pending = 0;
-               ep->dev->ep0state = EP0_STALL;
-
-       /* and bulk/intr endpoints like dropping stalls too */
-       } else {
-               unsigned i;
-               for (i = 0; i < 1000; i += 20) {
-                       if (*ep->reg_udccs & UDCCS_BI_SST)
-                               break;
-                       udelay(20);
-               }
-       }
-       local_irq_restore(flags);
-
-       DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
-       return 0;
-}
-
-static int pxa2xx_ep_fifo_status(struct usb_ep *_ep)
-{
-       struct pxa2xx_ep        *ep;
-
-       ep = container_of(_ep, struct pxa2xx_ep, ep);
-       if (!_ep) {
-               DMSG("%s, bad ep\n", __func__);
-               return -ENODEV;
-       }
-       /* pxa can't report unclaimed bytes from IN fifos */
-       if ((ep->bEndpointAddress & USB_DIR_IN) != 0)
-               return -EOPNOTSUPP;
-       if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
-                       || (*ep->reg_udccs & UDCCS_BO_RFS) == 0)
-               return 0;
-       else
-               return (*ep->reg_ubcr & 0xfff) + 1;
-}
-
-static void pxa2xx_ep_fifo_flush(struct usb_ep *_ep)
-{
-       struct pxa2xx_ep        *ep;
-
-       ep = container_of(_ep, struct pxa2xx_ep, ep);
-       if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
-               DMSG("%s, bad ep\n", __func__);
-               return;
-       }
-
-       /* toggle and halt bits stay unchanged */
-
-       /* for OUT, just read and discard the FIFO contents. */
-       if ((ep->bEndpointAddress & USB_DIR_IN) == 0) {
-               while (((*ep->reg_udccs) & UDCCS_BO_RNE) != 0)
-                       (void) *ep->reg_uddr;
-               return;
-       }
-
-       /* most IN status is the same, but ISO can't stall */
-       *ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
-               | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
-                       ? 0 : UDCCS_BI_SST;
-}
-
-
-static struct usb_ep_ops pxa2xx_ep_ops = {
-       .enable         = pxa2xx_ep_enable,
-       .disable        = pxa2xx_ep_disable,
-
-       .alloc_request  = pxa2xx_ep_alloc_request,
-       .free_request   = pxa2xx_ep_free_request,
-
-       .queue          = pxa2xx_ep_queue,
-       .dequeue        = pxa2xx_ep_dequeue,
-
-       .set_halt       = pxa2xx_ep_set_halt,
-       .fifo_status    = pxa2xx_ep_fifo_status,
-       .fifo_flush     = pxa2xx_ep_fifo_flush,
-};
-
-
-/* ---------------------------------------------------------------------------
- *     device-scoped parts of the api to the usb controller hardware
- * ---------------------------------------------------------------------------
- */
-
-static int pxa2xx_udc_get_frame(struct usb_gadget *_gadget)
-{
-       return ((UFNRH & 0x07) << 8) | (UFNRL & 0xff);
-}
-
-static int pxa2xx_udc_wakeup(struct usb_gadget *_gadget)
-{
-       /* host may not have enabled remote wakeup */
-       if ((UDCCS0 & UDCCS0_DRWF) == 0)
-               return -EHOSTUNREACH;
-       udc_set_mask_UDCCR(UDCCR_RSM);
-       return 0;
-}
-
-static void stop_activity(struct pxa2xx_udc *, struct usb_gadget_driver *);
-static void udc_enable (struct pxa2xx_udc *);
-static void udc_disable(struct pxa2xx_udc *);
-
-/* We disable the UDC -- and its 48 MHz clock -- whenever it's not
- * in active use.
- */
-static int pullup(struct pxa2xx_udc *udc)
-{
-       int is_active = udc->vbus && udc->pullup && !udc->suspended;
-       DMSG("%s\n", is_active ? "active" : "inactive");
-       if (is_active) {
-               if (!udc->active) {
-                       udc->active = 1;
-                       /* Enable clock for USB device */
-                       clk_enable(udc->clk);
-                       udc_enable(udc);
-               }
-       } else {
-               if (udc->active) {
-                       if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
-                               DMSG("disconnect %s\n", udc->driver
-                                       ? udc->driver->driver.name
-                                       : "(no driver)");
-                               stop_activity(udc, udc->driver);
-                       }
-                       udc_disable(udc);
-                       /* Disable clock for USB device */
-                       clk_disable(udc->clk);
-                       udc->active = 0;
-               }
-
-       }
-       return 0;
-}
-
-/* VBUS reporting logically comes from a transceiver */
-static int pxa2xx_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
-{
-       struct pxa2xx_udc       *udc;
-
-       udc = container_of(_gadget, struct pxa2xx_udc, gadget);
-       udc->vbus = (is_active != 0);
-       DMSG("vbus %s\n", is_active ? "supplied" : "inactive");
-       pullup(udc);
-       return 0;
-}
-
-/* drivers may have software control over D+ pullup */
-static int pxa2xx_udc_pullup(struct usb_gadget *_gadget, int is_active)
-{
-       struct pxa2xx_udc       *udc;
-
-       udc = container_of(_gadget, struct pxa2xx_udc, gadget);
-
-       /* not all boards support pullup control */
-       if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
-               return -EOPNOTSUPP;
-
-       udc->pullup = (is_active != 0);
-       pullup(udc);
-       return 0;
-}
-
-static const struct usb_gadget_ops pxa2xx_udc_ops = {
-       .get_frame      = pxa2xx_udc_get_frame,
-       .wakeup         = pxa2xx_udc_wakeup,
-       .vbus_session   = pxa2xx_udc_vbus_session,
-       .pullup         = pxa2xx_udc_pullup,
-
-       // .vbus_draw ... boards may consume current from VBUS, up to
-       // 100-500mA based on config.  the 500uA suspend ceiling means
-       // that exclusively vbus-powered PXA designs violate USB specs.
-};
-
-/*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_USB_GADGET_DEBUG_FS
-
-static int
-udc_seq_show(struct seq_file *m, void *_d)
-{
-       struct pxa2xx_udc       *dev = m->private;
-       unsigned long           flags;
-       int                     i;
-       u32                     tmp;
-
-       local_irq_save(flags);
-
-       /* basic device status */
-       seq_printf(m, DRIVER_DESC "\n"
-               "%s version: %s\nGadget driver: %s\nHost %s\n\n",
-               driver_name, DRIVER_VERSION SIZE_STR "(pio)",
-               dev->driver ? dev->driver->driver.name : "(none)",
-               is_vbus_present() ? "full speed" : "disconnected");
-
-       /* registers for device and ep0 */
-       seq_printf(m,
-               "uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
-               UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
-
-       tmp = UDCCR;
-       seq_printf(m,
-               "udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
-               (tmp & UDCCR_REM) ? " rem" : "",
-               (tmp & UDCCR_RSTIR) ? " rstir" : "",
-               (tmp & UDCCR_SRM) ? " srm" : "",
-               (tmp & UDCCR_SUSIR) ? " susir" : "",
-               (tmp & UDCCR_RESIR) ? " resir" : "",
-               (tmp & UDCCR_RSM) ? " rsm" : "",
-               (tmp & UDCCR_UDA) ? " uda" : "",
-               (tmp & UDCCR_UDE) ? " ude" : "");
-
-       tmp = UDCCS0;
-       seq_printf(m,
-               "udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
-               (tmp & UDCCS0_SA) ? " sa" : "",
-               (tmp & UDCCS0_RNE) ? " rne" : "",
-               (tmp & UDCCS0_FST) ? " fst" : "",
-               (tmp & UDCCS0_SST) ? " sst" : "",
-               (tmp & UDCCS0_DRWF) ? " dwrf" : "",
-               (tmp & UDCCS0_FTF) ? " ftf" : "",
-               (tmp & UDCCS0_IPR) ? " ipr" : "",
-               (tmp & UDCCS0_OPR) ? " opr" : "");
-
-       if (dev->has_cfr) {
-               tmp = UDCCFR;
-               seq_printf(m,
-                       "udccfr %02X =%s%s\n", tmp,
-                       (tmp & UDCCFR_AREN) ? " aren" : "",
-                       (tmp & UDCCFR_ACM) ? " acm" : "");
-       }
-
-       if (!is_vbus_present() || !dev->driver)
-               goto done;
-
-       seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
-               dev->stats.write.bytes, dev->stats.write.ops,
-               dev->stats.read.bytes, dev->stats.read.ops,
-               dev->stats.irqs);
-
-       /* dump endpoint queues */
-       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
-               struct pxa2xx_ep        *ep = &dev->ep [i];
-               struct pxa2xx_request   *req;
-
-               if (i != 0) {
-                       const struct usb_endpoint_descriptor    *desc;
-
-                       desc = ep->desc;
-                       if (!desc)
-                               continue;
-                       tmp = *dev->ep [i].reg_udccs;
-                       seq_printf(m,
-                               "%s max %d %s udccs %02x irqs %lu\n",
-                               ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
-                               "pio", tmp, ep->pio_irqs);
-                       /* TODO translate all five groups of udccs bits! */
-
-               } else /* ep0 should only have one transfer queued */
-                       seq_printf(m, "ep0 max 16 pio irqs %lu\n",
-                               ep->pio_irqs);
-
-               if (list_empty(&ep->queue)) {
-                       seq_printf(m, "\t(nothing queued)\n");
-                       continue;
-               }
-               list_for_each_entry(req, &ep->queue, queue) {
-                       seq_printf(m,
-                                       "\treq %p len %d/%d buf %p\n",
-                                       &req->req, req->req.actual,
-                                       req->req.length, req->req.buf);
-               }
-       }
-
-done:
-       local_irq_restore(flags);
-       return 0;
-}
-
-static int
-udc_debugfs_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, udc_seq_show, inode->i_private);
-}
-
-static const struct file_operations debug_fops = {
-       .open           = udc_debugfs_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-       .owner          = THIS_MODULE,
-};
-
-#define create_debug_files(dev) \
-       do { \
-               dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
-                       S_IRUGO, NULL, dev, &debug_fops); \
-       } while (0)
-#define remove_debug_files(dev) \
-       do { \
-               if (dev->debugfs_udc) \
-                       debugfs_remove(dev->debugfs_udc); \
-       } while (0)
-
-#else  /* !CONFIG_USB_GADGET_DEBUG_FILES */
-
-#define create_debug_files(dev) do {} while (0)
-#define remove_debug_files(dev) do {} while (0)
-
-#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
-
-/*-------------------------------------------------------------------------*/
-
-/*
- *     udc_disable - disable USB device controller
- */
-static void udc_disable(struct pxa2xx_udc *dev)
-{
-       /* block all irqs */
-       udc_set_mask_UDCCR(UDCCR_SRM|UDCCR_REM);
-       UICR0 = UICR1 = 0xff;
-       UFNRH = UFNRH_SIM;
-
-       /* if hardware supports it, disconnect from usb */
-       pullup_off();
-
-       udc_clear_mask_UDCCR(UDCCR_UDE);
-
-       ep0_idle (dev);
-       dev->gadget.speed = USB_SPEED_UNKNOWN;
-}
-
-
-/*
- *     udc_reinit - initialize software state
- */
-static void udc_reinit(struct pxa2xx_udc *dev)
-{
-       u32     i;
-
-       /* device/ep0 records init */
-       INIT_LIST_HEAD (&dev->gadget.ep_list);
-       INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
-       dev->ep0state = EP0_IDLE;
-
-       /* basic endpoint records init */
-       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
-               struct pxa2xx_ep *ep = &dev->ep[i];
-
-               if (i != 0)
-                       list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
-
-               ep->desc = NULL;
-               ep->stopped = 0;
-               INIT_LIST_HEAD (&ep->queue);
-               ep->pio_irqs = 0;
-       }
-
-       /* the rest was statically initialized, and is read-only */
-}
-
-/* until it's enabled, this UDC should be completely invisible
- * to any USB host.
- */
-static void udc_enable (struct pxa2xx_udc *dev)
-{
-       udc_clear_mask_UDCCR(UDCCR_UDE);
-
-       /* try to clear these bits before we enable the udc */
-       udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
-
-       ep0_idle(dev);
-       dev->gadget.speed = USB_SPEED_UNKNOWN;
-       dev->stats.irqs = 0;
-
-       /*
-        * sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
-        * - enable UDC
-        * - if RESET is already in progress, ack interrupt
-        * - unmask reset interrupt
-        */
-       udc_set_mask_UDCCR(UDCCR_UDE);
-       if (!(UDCCR & UDCCR_UDA))
-               udc_ack_int_UDCCR(UDCCR_RSTIR);
-
-       if (dev->has_cfr /* UDC_RES2 is defined */) {
-               /* pxa255 (a0+) can avoid a set_config race that could
-                * prevent gadget drivers from configuring correctly
-                */
-               UDCCFR = UDCCFR_ACM | UDCCFR_MB1;
-       } else {
-               /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
-                * which could result in missing packets and interrupts.
-                * supposedly one bit per endpoint, controlling whether it
-                * double buffers or not; ACM/AREN bits fit into the holes.
-                * zero bits (like USIR0_IRx) disable double buffering.
-                */
-               UDC_RES1 = 0x00;
-               UDC_RES2 = 0x00;
-       }
-
-       /* enable suspend/resume and reset irqs */
-       udc_clear_mask_UDCCR(UDCCR_SRM | UDCCR_REM);
-
-       /* enable ep0 irqs */
-       UICR0 &= ~UICR0_IM0;
-
-       /* if hardware supports it, pullup D+ and wait for reset */
-       pullup_on();
-}
-
-
-/* when a driver is successfully registered, it will receive
- * control requests including set_configuration(), which enables
- * non-control requests.  then usb traffic follows until a
- * disconnect is reported.  then a host may connect again, or
- * the driver might get unbound.
- */
-int usb_gadget_register_driver(struct usb_gadget_driver *driver)
-{
-       struct pxa2xx_udc       *dev = the_controller;
-       int                     retval;
-
-       if (!driver
-                       || driver->speed < USB_SPEED_FULL
-                       || !driver->bind
-                       || !driver->disconnect
-                       || !driver->setup)
-               return -EINVAL;
-       if (!dev)
-               return -ENODEV;
-       if (dev->driver)
-               return -EBUSY;
-
-       /* first hook up the driver ... */
-       dev->driver = driver;
-       dev->gadget.dev.driver = &driver->driver;
-       dev->pullup = 1;
-
-       retval = device_add (&dev->gadget.dev);
-       if (retval) {
-fail:
-               dev->driver = NULL;
-               dev->gadget.dev.driver = NULL;
-               return retval;
-       }
-       retval = driver->bind(&dev->gadget);
-       if (retval) {
-               DMSG("bind to driver %s --> error %d\n",
-                               driver->driver.name, retval);
-               device_del (&dev->gadget.dev);
-               goto fail;
-       }
-
-       /* ... then enable host detection and ep0; and we're ready
-        * for set_configuration as well as eventual disconnect.
-        */
-       DMSG("registered gadget driver '%s'\n", driver->driver.name);
-       pullup(dev);
-       dump_state(dev);
-       return 0;
-}
-EXPORT_SYMBOL(usb_gadget_register_driver);
-
-static void
-stop_activity(struct pxa2xx_udc *dev, struct usb_gadget_driver *driver)
-{
-       int i;
-
-       /* don't disconnect drivers more than once */
-       if (dev->gadget.speed == USB_SPEED_UNKNOWN)
-               driver = NULL;
-       dev->gadget.speed = USB_SPEED_UNKNOWN;
-
-       /* prevent new request submissions, kill any outstanding requests  */
-       for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
-               struct pxa2xx_ep *ep = &dev->ep[i];
-
-               ep->stopped = 1;
-               nuke(ep, -ESHUTDOWN);
-       }
-       del_timer_sync(&dev->timer);
-
-       /* report disconnect; the driver is already quiesced */
-       if (driver)
-               driver->disconnect(&dev->gadget);
-
-       /* re-init driver-visible data structures */
-       udc_reinit(dev);
-}
-
-int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
-{
-       struct pxa2xx_udc       *dev = the_controller;
-
-       if (!dev)
-               return -ENODEV;
-       if (!driver || driver != dev->driver || !driver->unbind)
-               return -EINVAL;
-
-       local_irq_disable();
-       dev->pullup = 0;
-       pullup(dev);
-       stop_activity(dev, driver);
-       local_irq_enable();
-
-       driver->unbind(&dev->gadget);
-       dev->gadget.dev.driver = NULL;
-       dev->driver = NULL;
-
-       device_del (&dev->gadget.dev);
-
-       DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
-       dump_state(dev);
-       return 0;
-}
-EXPORT_SYMBOL(usb_gadget_unregister_driver);
-
-
-/*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_ARCH_LUBBOCK
-
-/* Lubbock has separate connect and disconnect irqs.  More typical designs
- * use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
- */
-
-static irqreturn_t
-lubbock_vbus_irq(int irq, void *_dev)
-{
-       struct pxa2xx_udc       *dev = _dev;
-       int                     vbus;
-
-       dev->stats.irqs++;
-       switch (irq) {
-       case LUBBOCK_USB_IRQ:
-               vbus = 1;
-               disable_irq(LUBBOCK_USB_IRQ);
-               enable_irq(LUBBOCK_USB_DISC_IRQ);
-               break;
-       case LUBBOCK_USB_DISC_IRQ:
-               vbus = 0;
-               disable_irq(LUBBOCK_USB_DISC_IRQ);
-               enable_irq(LUBBOCK_USB_IRQ);
-               break;
-       default:
-               return IRQ_NONE;
-       }
-
-       pxa2xx_udc_vbus_session(&dev->gadget, vbus);
-       return IRQ_HANDLED;
-}
-
-#endif
-
-static irqreturn_t udc_vbus_irq(int irq, void *_dev)
-{
-       struct pxa2xx_udc       *dev = _dev;
-       int                     vbus = gpio_get_value(dev->mach->gpio_vbus);
-
-       if (dev->mach->gpio_vbus_inverted)
-               vbus = !vbus;
-
-       pxa2xx_udc_vbus_session(&dev->gadget, vbus);
-       return IRQ_HANDLED;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static inline void clear_ep_state (struct pxa2xx_udc *dev)
-{
-       unsigned i;
-
-       /* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
-        * fifos, and pending transactions mustn't be continued in any case.
-        */
-       for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
-               nuke(&dev->ep[i], -ECONNABORTED);
-}
-
-static void udc_watchdog(unsigned long _dev)
-{
-       struct pxa2xx_udc       *dev = (void *)_dev;
-
-       local_irq_disable();
-       if (dev->ep0state == EP0_STALL
-                       && (UDCCS0 & UDCCS0_FST) == 0
-                       && (UDCCS0 & UDCCS0_SST) == 0) {
-               UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
-               DBG(DBG_VERBOSE, "ep0 re-stall\n");
-               start_watchdog(dev);
-       }
-       local_irq_enable();
-}
-
-static void handle_ep0 (struct pxa2xx_udc *dev)
-{
-       u32                     udccs0 = UDCCS0;
-       struct pxa2xx_ep        *ep = &dev->ep [0];
-       struct pxa2xx_request   *req;
-       union {
-               struct usb_ctrlrequest  r;
-               u8                      raw [8];
-               u32                     word [2];
-       } u;
-
-       if (list_empty(&ep->queue))
-               req = NULL;
-       else
-               req = list_entry(ep->queue.next, struct pxa2xx_request, queue);
-
-       /* clear stall status */
-       if (udccs0 & UDCCS0_SST) {
-               nuke(ep, -EPIPE);
-               UDCCS0 = UDCCS0_SST;
-               del_timer(&dev->timer);
-               ep0_idle(dev);
-       }
-
-       /* previous request unfinished?  non-error iff back-to-back ... */
-       if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
-               nuke(ep, 0);
-               del_timer(&dev->timer);
-               ep0_idle(dev);
-       }
-
-       switch (dev->ep0state) {
-       case EP0_IDLE:
-               /* late-breaking status? */
-               udccs0 = UDCCS0;
-
-               /* start control request? */
-               if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
-                               == (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
-                       int i;
-
-                       nuke (ep, -EPROTO);
-
-                       /* read SETUP packet */
-                       for (i = 0; i < 8; i++) {
-                               if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
-bad_setup:
-                                       DMSG("SETUP %d!\n", i);
-                                       goto stall;
-                               }
-                               u.raw [i] = (u8) UDDR0;
-                       }
-                       if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
-                               goto bad_setup;
-
-got_setup:
-                       DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
-                               u.r.bRequestType, u.r.bRequest,
-                               le16_to_cpu(u.r.wValue),
-                               le16_to_cpu(u.r.wIndex),
-                               le16_to_cpu(u.r.wLength));
-
-                       /* cope with automagic for some standard requests. */
-                       dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
-                                               == USB_TYPE_STANDARD;
-                       dev->req_config = 0;
-                       dev->req_pending = 1;
-                       switch (u.r.bRequest) {
-                       /* hardware restricts gadget drivers here! */
-                       case USB_REQ_SET_CONFIGURATION:
-                               if (u.r.bRequestType == USB_RECIP_DEVICE) {
-                                       /* reflect hardware's automagic
-                                        * up to the gadget driver.
-                                        */
-config_change:
-                                       dev->req_config = 1;
-                                       clear_ep_state(dev);
-                                       /* if !has_cfr, there's no synch
-                                        * else use AREN (later) not SA|OPR
-                                        * USIR0_IR0 acts edge sensitive
-                                        */
-                               }
-                               break;
-                       /* ... and here, even more ... */
-                       case USB_REQ_SET_INTERFACE:
-                               if (u.r.bRequestType == USB_RECIP_INTERFACE) {
-                                       /* udc hardware is broken by design:
-                                        *  - altsetting may only be zero;
-                                        *  - hw resets all interfaces' eps;
-                                        *  - ep reset doesn't include halt(?).
-                                        */
-                                       DMSG("broken set_interface (%d/%d)\n",
-                                               le16_to_cpu(u.r.wIndex),
-                                               le16_to_cpu(u.r.wValue));
-                                       goto config_change;
-                               }
-                               break;
-                       /* hardware was supposed to hide this */
-                       case USB_REQ_SET_ADDRESS:
-                               if (u.r.bRequestType == USB_RECIP_DEVICE) {
-                                       ep0start(dev, 0, "address");
-                                       return;
-                               }
-                               break;
-                       }
-
-                       if (u.r.bRequestType & USB_DIR_IN)
-                               dev->ep0state = EP0_IN_DATA_PHASE;
-                       else
-                               dev->ep0state = EP0_OUT_DATA_PHASE;
-
-                       i = dev->driver->setup(&dev->gadget, &u.r);
-                       if (i < 0) {
-                               /* hardware automagic preventing STALL... */
-                               if (dev->req_config) {
-                                       /* hardware sometimes neglects to tell
-                                        * tell us about config change events,
-                                        * so later ones may fail...
-                                        */
-                                       WARN("config change %02x fail %d?\n",
-                                               u.r.bRequest, i);
-                                       return;
-                                       /* TODO experiment:  if has_cfr,
-                                        * hardware didn't ACK; maybe we
-                                        * could actually STALL!
-                                        */
-                               }
-                               DBG(DBG_VERBOSE, "protocol STALL, "
-                                       "%02x err %d\n", UDCCS0, i);
-stall:
-                               /* the watchdog timer helps deal with cases
-                                * where udc seems to clear FST wrongly, and
-                                * then NAKs instead of STALLing.
-                                */
-                               ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
-                               start_watchdog(dev);
-                               dev->ep0state = EP0_STALL;
-
-                       /* deferred i/o == no response yet */
-                       } else if (dev->req_pending) {
-                               if (likely(dev->ep0state == EP0_IN_DATA_PHASE
-                                               || dev->req_std || u.r.wLength))
-                                       ep0start(dev, 0, "defer");
-                               else
-                                       ep0start(dev, UDCCS0_IPR, "defer/IPR");
-                       }
-
-                       /* expect at least one data or status stage irq */
-                       return;
-
-               } else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
-                               == (UDCCS0_OPR|UDCCS0_SA))) {
-                       unsigned i;
-
-                       /* pxa210/250 erratum 131 for B0/B1 says RNE lies.
-                        * still observed on a pxa255 a0.
-                        */
-                       DBG(DBG_VERBOSE, "e131\n");
-                       nuke(ep, -EPROTO);
-
-                       /* read SETUP data, but don't trust it too much */
-                       for (i = 0; i < 8; i++)
-                               u.raw [i] = (u8) UDDR0;
-                       if ((u.r.bRequestType & USB_RECIP_MASK)
-                                       > USB_RECIP_OTHER)
-                               goto stall;
-                       if (u.word [0] == 0 && u.word [1] == 0)
-                               goto stall;
-                       goto got_setup;
-               } else {
-                       /* some random early IRQ:
-                        * - we acked FST
-                        * - IPR cleared
-                        * - OPR got set, without SA (likely status stage)
-                        */
-                       UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
-               }
-               break;
-       case EP0_IN_DATA_PHASE:                 /* GET_DESCRIPTOR etc */
-               if (udccs0 & UDCCS0_OPR) {
-                       UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
-                       DBG(DBG_VERBOSE, "ep0in premature status\n");
-                       if (req)
-                               done(ep, req, 0);
-                       ep0_idle(dev);
-               } else /* irq was IPR clearing */ {
-                       if (req) {
-                               /* this IN packet might finish the request */
-                               (void) write_ep0_fifo(ep, req);
-                       } /* else IN token before response was written */
-               }
-               break;
-       case EP0_OUT_DATA_PHASE:                /* SET_DESCRIPTOR etc */
-               if (udccs0 & UDCCS0_OPR) {
-                       if (req) {
-                               /* this OUT packet might finish the request */
-                               if (read_ep0_fifo(ep, req))
-                                       done(ep, req, 0);
-                               /* else more OUT packets expected */
-                       } /* else OUT token before read was issued */
-               } else /* irq was IPR clearing */ {
-                       DBG(DBG_VERBOSE, "ep0out premature status\n");
-                       if (req)
-                               done(ep, req, 0);
-                       ep0_idle(dev);
-               }
-               break;
-       case EP0_END_XFER:
-               if (req)
-                       done(ep, req, 0);
-               /* ack control-IN status (maybe in-zlp was skipped)
-                * also appears after some config change events.
-                */
-               if (udccs0 & UDCCS0_OPR)
-                       UDCCS0 = UDCCS0_OPR;
-               ep0_idle(dev);
-               break;
-       case EP0_STALL:
-               UDCCS0 = UDCCS0_FST;
-               break;
-       }
-       USIR0 = USIR0_IR0;
-}
-
-static void handle_ep(struct pxa2xx_ep *ep)
-{
-       struct pxa2xx_request   *req;
-       int                     is_in = ep->bEndpointAddress & USB_DIR_IN;
-       int                     completed;
-       u32                     udccs, tmp;
-
-       do {
-               completed = 0;
-               if (likely (!list_empty(&ep->queue)))
-                       req = list_entry(ep->queue.next,
-                                       struct pxa2xx_request, queue);
-               else
-                       req = NULL;
-
-               // TODO check FST handling
-
-               udccs = *ep->reg_udccs;
-               if (unlikely(is_in)) {  /* irq from TPC, SST, or (ISO) TUR */
-                       tmp = UDCCS_BI_TUR;
-                       if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
-                               tmp |= UDCCS_BI_SST;
-                       tmp &= udccs;
-                       if (likely (tmp))
-                               *ep->reg_udccs = tmp;
-                       if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
-                               completed = write_fifo(ep, req);
-
-               } else {        /* irq from RPC (or for ISO, ROF) */
-                       if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
-                               tmp = UDCCS_BO_SST | UDCCS_BO_DME;
-                       else
-                               tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
-                       tmp &= udccs;
-                       if (likely(tmp))
-                               *ep->reg_udccs = tmp;
-
-                       /* fifos can hold packets, ready for reading... */
-                       if (likely(req)) {
-                               completed = read_fifo(ep, req);
-                       } else
-                               pio_irq_disable (ep->bEndpointAddress);
-               }
-               ep->pio_irqs++;
-       } while (completed);
-}
-
-/*
- *     pxa2xx_udc_irq - interrupt handler
- *
- * avoid delays in ep0 processing. the control handshaking isn't always
- * under software control (pxa250c0 and the pxa255 are better), and delays
- * could cause usb protocol errors.
- */
-static irqreturn_t
-pxa2xx_udc_irq(int irq, void *_dev)
-{
-       struct pxa2xx_udc       *dev = _dev;
-       int                     handled;
-
-       dev->stats.irqs++;
-       do {
-               u32             udccr = UDCCR;
-
-               handled = 0;
-
-               /* SUSpend Interrupt Request */
-               if (unlikely(udccr & UDCCR_SUSIR)) {
-                       udc_ack_int_UDCCR(UDCCR_SUSIR);
-                       handled = 1;
-                       DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
-                               ? "" : "+disconnect");
-
-                       if (!is_vbus_present())
-                               stop_activity(dev, dev->driver);
-                       else if (dev->gadget.speed != USB_SPEED_UNKNOWN
-                                       && dev->driver
-                                       && dev->driver->suspend)
-                               dev->driver->suspend(&dev->gadget);
-                       ep0_idle (dev);
-               }
-
-               /* RESume Interrupt Request */
-               if (unlikely(udccr & UDCCR_RESIR)) {
-                       udc_ack_int_UDCCR(UDCCR_RESIR);
-                       handled = 1;
-                       DBG(DBG_VERBOSE, "USB resume\n");
-
-                       if (dev->gadget.speed != USB_SPEED_UNKNOWN
-                                       && dev->driver
-                                       && dev->driver->resume
-                                       && is_vbus_present())
-                               dev->driver->resume(&dev->gadget);
-               }
-
-               /* ReSeT Interrupt Request - USB reset */
-               if (unlikely(udccr & UDCCR_RSTIR)) {
-                       udc_ack_int_UDCCR(UDCCR_RSTIR);
-                       handled = 1;
-
-                       if ((UDCCR & UDCCR_UDA) == 0) {
-                               DBG(DBG_VERBOSE, "USB reset start\n");
-
-                               /* reset driver and endpoints,
-                                * in case that's not yet done
-                                */
-                               stop_activity (dev, dev->driver);
-
-                       } else {
-                               DBG(DBG_VERBOSE, "USB reset end\n");
-                               dev->gadget.speed = USB_SPEED_FULL;
-                               memset(&dev->stats, 0, sizeof dev->stats);
-                               /* driver and endpoints are still reset */
-                       }
-
-               } else {
-                       u32     usir0 = USIR0 & ~UICR0;
-                       u32     usir1 = USIR1 & ~UICR1;
-                       int     i;
-
-                       if (unlikely (!usir0 && !usir1))
-                               continue;
-
-                       DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
-
-                       /* control traffic */
-                       if (usir0 & USIR0_IR0) {
-                               dev->ep[0].pio_irqs++;
-                               handle_ep0(dev);
-                               handled = 1;
-                       }
-
-                       /* endpoint data transfers */
-                       for (i = 0; i < 8; i++) {
-                               u32     tmp = 1 << i;
-
-                               if (i && (usir0 & tmp)) {
-                                       handle_ep(&dev->ep[i]);
-                                       USIR0 |= tmp;
-                                       handled = 1;
-                               }
-                               if (usir1 & tmp) {
-                                       handle_ep(&dev->ep[i+8]);
-                                       USIR1 |= tmp;
-                                       handled = 1;
-                               }
-                       }
-               }
-
-               /* we could also ask for 1 msec SOF (SIR) interrupts */
-
-       } while (handled);
-       return IRQ_HANDLED;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static void nop_release (struct device *dev)
-{
-       DMSG("%s %s\n", __func__, dev->bus_id);
-}
-
-/* this uses load-time allocation and initialization (instead of
- * doing it at run-time) to save code, eliminate fault paths, and
- * be more obviously correct.
- */
-static struct pxa2xx_udc memory = {
-       .gadget = {
-               .ops            = &pxa2xx_udc_ops,
-               .ep0            = &memory.ep[0].ep,
-               .name           = driver_name,
-               .dev = {
-                       .bus_id         = "gadget",
-                       .release        = nop_release,
-               },
-       },
-
-       /* control endpoint */
-       .ep[0] = {
-               .ep = {
-                       .name           = ep0name,
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = EP0_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .reg_udccs      = &UDCCS0,
-               .reg_uddr       = &UDDR0,
-       },
-
-       /* first group of endpoints */
-       .ep[1] = {
-               .ep = {
-                       .name           = "ep1in-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 1,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS1,
-               .reg_uddr       = &UDDR1,
-       },
-       .ep[2] = {
-               .ep = {
-                       .name           = "ep2out-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = 2,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS2,
-               .reg_ubcr       = &UBCR2,
-               .reg_uddr       = &UDDR2,
-       },
-#ifndef CONFIG_USB_PXA2XX_SMALL
-       .ep[3] = {
-               .ep = {
-                       .name           = "ep3in-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 3,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS3,
-               .reg_uddr       = &UDDR3,
-       },
-       .ep[4] = {
-               .ep = {
-                       .name           = "ep4out-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = 4,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS4,
-               .reg_ubcr       = &UBCR4,
-               .reg_uddr       = &UDDR4,
-       },
-       .ep[5] = {
-               .ep = {
-                       .name           = "ep5in-int",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = INT_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = INT_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 5,
-               .bmAttributes   = USB_ENDPOINT_XFER_INT,
-               .reg_udccs      = &UDCCS5,
-               .reg_uddr       = &UDDR5,
-       },
-
-       /* second group of endpoints */
-       .ep[6] = {
-               .ep = {
-                       .name           = "ep6in-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 6,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS6,
-               .reg_uddr       = &UDDR6,
-       },
-       .ep[7] = {
-               .ep = {
-                       .name           = "ep7out-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = 7,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS7,
-               .reg_ubcr       = &UBCR7,
-               .reg_uddr       = &UDDR7,
-       },
-       .ep[8] = {
-               .ep = {
-                       .name           = "ep8in-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 8,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS8,
-               .reg_uddr       = &UDDR8,
-       },
-       .ep[9] = {
-               .ep = {
-                       .name           = "ep9out-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = 9,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS9,
-               .reg_ubcr       = &UBCR9,
-               .reg_uddr       = &UDDR9,
-       },
-       .ep[10] = {
-               .ep = {
-                       .name           = "ep10in-int",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = INT_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = INT_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 10,
-               .bmAttributes   = USB_ENDPOINT_XFER_INT,
-               .reg_udccs      = &UDCCS10,
-               .reg_uddr       = &UDDR10,
-       },
-
-       /* third group of endpoints */
-       .ep[11] = {
-               .ep = {
-                       .name           = "ep11in-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 11,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS11,
-               .reg_uddr       = &UDDR11,
-       },
-       .ep[12] = {
-               .ep = {
-                       .name           = "ep12out-bulk",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = BULK_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = BULK_FIFO_SIZE,
-               .bEndpointAddress = 12,
-               .bmAttributes   = USB_ENDPOINT_XFER_BULK,
-               .reg_udccs      = &UDCCS12,
-               .reg_ubcr       = &UBCR12,
-               .reg_uddr       = &UDDR12,
-       },
-       .ep[13] = {
-               .ep = {
-                       .name           = "ep13in-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 13,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS13,
-               .reg_uddr       = &UDDR13,
-       },
-       .ep[14] = {
-               .ep = {
-                       .name           = "ep14out-iso",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = ISO_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = ISO_FIFO_SIZE,
-               .bEndpointAddress = 14,
-               .bmAttributes   = USB_ENDPOINT_XFER_ISOC,
-               .reg_udccs      = &UDCCS14,
-               .reg_ubcr       = &UBCR14,
-               .reg_uddr       = &UDDR14,
-       },
-       .ep[15] = {
-               .ep = {
-                       .name           = "ep15in-int",
-                       .ops            = &pxa2xx_ep_ops,
-                       .maxpacket      = INT_FIFO_SIZE,
-               },
-               .dev            = &memory,
-               .fifo_size      = INT_FIFO_SIZE,
-               .bEndpointAddress = USB_DIR_IN | 15,
-               .bmAttributes   = USB_ENDPOINT_XFER_INT,
-               .reg_udccs      = &UDCCS15,
-               .reg_uddr       = &UDDR15,
-       },
-#endif /* !CONFIG_USB_PXA2XX_SMALL */
-};
-
-#define CP15R0_VENDOR_MASK     0xffffe000
-
-#if    defined(CONFIG_ARCH_PXA)
-#define CP15R0_XSCALE_VALUE    0x69052000      /* intel/arm/xscale */
-
-#elif  defined(CONFIG_ARCH_IXP4XX)
-#define CP15R0_XSCALE_VALUE    0x69054000      /* intel/arm/ixp4xx */
-
-#endif
-
-#define CP15R0_PROD_MASK       0x000003f0
-#define PXA25x                 0x00000100      /* and PXA26x */
-#define PXA210                 0x00000120
-
-#define CP15R0_REV_MASK                0x0000000f
-
-#define CP15R0_PRODREV_MASK    (CP15R0_PROD_MASK | CP15R0_REV_MASK)
-
-#define PXA255_A0              0x00000106      /* or PXA260_B1 */
-#define PXA250_C0              0x00000105      /* or PXA26x_B0 */
-#define PXA250_B2              0x00000104
-#define PXA250_B1              0x00000103      /* or PXA260_A0 */
-#define PXA250_B0              0x00000102
-#define PXA250_A1              0x00000101
-#define PXA250_A0              0x00000100
-
-#define PXA210_C0              0x00000125
-#define PXA210_B2              0x00000124
-#define PXA210_B1              0x00000123
-#define PXA210_B0              0x00000122
-#define IXP425_A0              0x000001c1
-#define IXP425_B0              0x000001f1
-#define IXP465_AD              0x00000200
-
-/*
- *     probe - binds to the platform device
- */
-static int __init pxa2xx_udc_probe(struct platform_device *pdev)
-{
-       struct pxa2xx_udc *dev = &memory;
-       int retval, vbus_irq, irq;
-       u32 chiprev;
-
-       /* insist on Intel/ARM/XScale */
-       asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
-       if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
-               pr_err("%s: not XScale!\n", driver_name);
-               return -ENODEV;
-       }
-
-       /* trigger chiprev-specific logic */
-       switch (chiprev & CP15R0_PRODREV_MASK) {
-#if    defined(CONFIG_ARCH_PXA)
-       case PXA255_A0:
-               dev->has_cfr = 1;
-               break;
-       case PXA250_A0:
-       case PXA250_A1:
-               /* A0/A1 "not released"; ep 13, 15 unusable */
-               /* fall through */
-       case PXA250_B2: case PXA210_B2:
-       case PXA250_B1: case PXA210_B1:
-       case PXA250_B0: case PXA210_B0:
-               /* OUT-DMA is broken ... */
-               /* fall through */
-       case PXA250_C0: case PXA210_C0:
-               break;
-#elif  defined(CONFIG_ARCH_IXP4XX)
-       case IXP425_A0:
-       case IXP425_B0:
-       case IXP465_AD:
-               dev->has_cfr = 1;
-               break;
-#endif
-       default:
-               pr_err("%s: unrecognized processor: %08x\n",
-                       driver_name, chiprev);
-               /* iop3xx, ixp4xx, ... */
-               return -ENODEV;
-       }
-
-       irq = platform_get_irq(pdev, 0);
-       if (irq < 0)
-               return -ENODEV;
-
-       dev->clk = clk_get(&pdev->dev, "UDCCLK");
-       if (IS_ERR(dev->clk)) {
-               retval = PTR_ERR(dev->clk);
-               goto err_clk;
-       }
-
-       pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
-               dev->has_cfr ? "" : " (!cfr)",
-               SIZE_STR "(pio)"
-               );
-
-       /* other non-static parts of init */
-       dev->dev = &pdev->dev;
-       dev->mach = pdev->dev.platform_data;
-
-       if (dev->mach->gpio_vbus) {
-               if ((retval = gpio_request(dev->mach->gpio_vbus,
-                               "pxa2xx_udc GPIO VBUS"))) {
-                       dev_dbg(&pdev->dev,
-                               "can't get vbus gpio %d, err: %d\n",
-                               dev->mach->gpio_vbus, retval);
-                       goto err_gpio_vbus;
-               }
-               gpio_direction_input(dev->mach->gpio_vbus);
-               vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
-       } else
-               vbus_irq = 0;
-
-       if (dev->mach->gpio_pullup) {
-               if ((retval = gpio_request(dev->mach->gpio_pullup,
-                               "pca2xx_udc GPIO PULLUP"))) {
-                       dev_dbg(&pdev->dev,
-                               "can't get pullup gpio %d, err: %d\n",
-                               dev->mach->gpio_pullup, retval);
-                       goto err_gpio_pullup;
-               }
-               gpio_direction_output(dev->mach->gpio_pullup, 0);
-       }
-
-       init_timer(&dev->timer);
-       dev->timer.function = udc_watchdog;
-       dev->timer.data = (unsigned long) dev;
-
-       device_initialize(&dev->gadget.dev);
-       dev->gadget.dev.parent = &pdev->dev;
-       dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
-
-       the_controller = dev;
-       platform_set_drvdata(pdev, dev);
-
-       udc_disable(dev);
-       udc_reinit(dev);
-
-       dev->vbus = is_vbus_present();
-
-       /* irq setup after old hardware state is cleaned up */
-       retval = request_irq(irq, pxa2xx_udc_irq,
-                       IRQF_DISABLED, driver_name, dev);
-       if (retval != 0) {
-               pr_err("%s: can't get irq %d, err %d\n",
-                       driver_name, irq, retval);
-               goto err_irq1;
-       }
-       dev->got_irq = 1;
-
-#ifdef CONFIG_ARCH_LUBBOCK
-       if (machine_is_lubbock()) {
-               retval = request_irq(LUBBOCK_USB_DISC_IRQ,
-                               lubbock_vbus_irq,
-                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
-                               driver_name, dev);
-               if (retval != 0) {
-                       pr_err("%s: can't get irq %i, err %d\n",
-                               driver_name, LUBBOCK_USB_DISC_IRQ, retval);
-lubbock_fail0:
-                       goto err_irq_lub;
-               }
-               retval = request_irq(LUBBOCK_USB_IRQ,
-                               lubbock_vbus_irq,
-                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
-                               driver_name, dev);
-               if (retval != 0) {
-                       pr_err("%s: can't get irq %i, err %d\n",
-                               driver_name, LUBBOCK_USB_IRQ, retval);
-                       free_irq(LUBBOCK_USB_DISC_IRQ, dev);
-                       goto lubbock_fail0;
-               }
-       } else
-#endif
-       if (vbus_irq) {
-               retval = request_irq(vbus_irq, udc_vbus_irq,
-                               IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
-                               IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-                               driver_name, dev);
-               if (retval != 0) {
-                       pr_err("%s: can't get irq %i, err %d\n",
-                               driver_name, vbus_irq, retval);
-                       goto err_vbus_irq;
-               }
-       }
-       create_debug_files(dev);
-
-       return 0;
-
- err_vbus_irq:
-#ifdef CONFIG_ARCH_LUBBOCK
-       free_irq(LUBBOCK_USB_DISC_IRQ, dev);
- err_irq_lub:
-#endif
-       free_irq(irq, dev);
- err_irq1:
-       if (dev->mach->gpio_pullup)
-               gpio_free(dev->mach->gpio_pullup);
- err_gpio_pullup:
-       if (dev->mach->gpio_vbus)
-               gpio_free(dev->mach->gpio_vbus);
- err_gpio_vbus:
-       clk_put(dev->clk);
- err_clk:
-       return retval;
-}
-
-static void pxa2xx_udc_shutdown(struct platform_device *_dev)
-{
-       pullup_off();
-}
-
-static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
-{
-       struct pxa2xx_udc *dev = platform_get_drvdata(pdev);
-
-       if (dev->driver)
-               return -EBUSY;
-
-       dev->pullup = 0;
-       pullup(dev);
-
-       remove_debug_files(dev);
-
-       if (dev->got_irq) {
-               free_irq(platform_get_irq(pdev, 0), dev);
-               dev->got_irq = 0;
-       }
-#ifdef CONFIG_ARCH_LUBBOCK
-       if (machine_is_lubbock()) {
-               free_irq(LUBBOCK_USB_DISC_IRQ, dev);
-               free_irq(LUBBOCK_USB_IRQ, dev);
-       }
-#endif
-       if (dev->mach->gpio_vbus) {
-               free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
-               gpio_free(dev->mach->gpio_vbus);
-       }
-       if (dev->mach->gpio_pullup)
-               gpio_free(dev->mach->gpio_pullup);
-
-       clk_put(dev->clk);
-
-       platform_set_drvdata(pdev, NULL);
-       the_controller = NULL;
-       return 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_PM
-
-/* USB suspend (controlled by the host) and system suspend (controlled
- * by the PXA) don't necessarily work well together.  If USB is active,
- * the 48 MHz clock is required; so the system can't enter 33 MHz idle
- * mode, or any deeper PM saving state.
- *
- * For now, we punt and forcibly disconnect from the USB host when PXA
- * enters any suspend state.  While we're disconnected, we always disable
- * the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
- * Boards without software pullup control shouldn't use those states.
- * VBUS IRQs should probably be ignored so that the PXA device just acts
- * "dead" to USB hosts until system resume.
- */
-static int pxa2xx_udc_suspend(struct platform_device *dev, pm_message_t state)
-{
-       struct pxa2xx_udc       *udc = platform_get_drvdata(dev);
-       unsigned long flags;
-
-       if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
-               WARN("USB host won't detect disconnect!\n");
-       udc->suspended = 1;
-
-       local_irq_save(flags);
-       pullup(udc);
-       local_irq_restore(flags);
-
-       return 0;
-}
-
-static int pxa2xx_udc_resume(struct platform_device *dev)
-{
-       struct pxa2xx_udc       *udc = platform_get_drvdata(dev);
-       unsigned long flags;
-
-       udc->suspended = 0;
-       local_irq_save(flags);
-       pullup(udc);
-       local_irq_restore(flags);
-
-       return 0;
-}
-
-#else
-#define        pxa2xx_udc_suspend      NULL
-#define        pxa2xx_udc_resume       NULL
-#endif
-
-/*-------------------------------------------------------------------------*/
-
-static struct platform_driver udc_driver = {
-       .shutdown       = pxa2xx_udc_shutdown,
-       .remove         = __exit_p(pxa2xx_udc_remove),
-       .suspend        = pxa2xx_udc_suspend,
-       .resume         = pxa2xx_udc_resume,
-       .driver         = {
-               .owner  = THIS_MODULE,
-               .name   = "pxa2xx-udc",
-       },
-};
-
-static int __init udc_init(void)
-{
-       pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
-       return platform_driver_probe(&udc_driver, pxa2xx_udc_probe);
-}
-module_init(udc_init);
-
-static void __exit udc_exit(void)
-{
-       platform_driver_unregister(&udc_driver);
-}
-module_exit(udc_exit);
-
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:pxa2xx-udc");
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
deleted file mode 100644 (file)
index e2c19e8..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * linux/drivers/usb/gadget/pxa2xx_udc.h
- * Intel PXA2xx on-chip full speed USB device controller
- *
- * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
- * Copyright (C) 2003 David Brownell
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#ifndef __LINUX_USB_GADGET_PXA2XX_H
-#define __LINUX_USB_GADGET_PXA2XX_H
-
-#include <linux/types.h>
-
-/*-------------------------------------------------------------------------*/
-
-/* pxa2xx has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
-#define UFNRH_SIR      (1 << 7)        /* SOF interrupt request */
-#define UFNRH_SIM      (1 << 6)        /* SOF interrupt mask */
-#define UFNRH_IPE14    (1 << 5)        /* ISO packet error, ep14 */
-#define UFNRH_IPE9     (1 << 4)        /* ISO packet error, ep9 */
-#define UFNRH_IPE4     (1 << 3)        /* ISO packet error, ep4 */
-
-/* pxa255 has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
-#define        UDCCFR          UDC_RES2        /* UDC Control Function Register */
-#define UDCCFR_AREN    (1 << 7)        /* ACK response enable (now) */
-#define UDCCFR_ACM     (1 << 2)        /* ACK control mode (wait for AREN) */
-
-/* latest pxa255 errata define new "must be one" bits in UDCCFR */
-#define        UDCCFR_MB1      (0xff & ~(UDCCFR_AREN|UDCCFR_ACM))
-
-/*-------------------------------------------------------------------------*/
-
-struct pxa2xx_udc;
-
-struct pxa2xx_ep {
-       struct usb_ep                           ep;
-       struct pxa2xx_udc                       *dev;
-
-       const struct usb_endpoint_descriptor    *desc;
-       struct list_head                        queue;
-       unsigned long                           pio_irqs;
-
-       unsigned short                          fifo_size;
-       u8                                      bEndpointAddress;
-       u8                                      bmAttributes;
-
-       unsigned                                stopped : 1;
-       unsigned                                dma_fixup : 1;
-
-       /* UDCCS = UDC Control/Status for this EP
-        * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
-        * UDDR = UDC Endpoint Data Register (the fifo)
-        * DRCM = DMA Request Channel Map
-        */
-       volatile u32                            *reg_udccs;
-       volatile u32                            *reg_ubcr;
-       volatile u32                            *reg_uddr;
-};
-
-struct pxa2xx_request {
-       struct usb_request                      req;
-       struct list_head                        queue;
-};
-
-enum ep0_state {
-       EP0_IDLE,
-       EP0_IN_DATA_PHASE,
-       EP0_OUT_DATA_PHASE,
-       EP0_END_XFER,
-       EP0_STALL,
-};
-
-#define EP0_FIFO_SIZE  ((unsigned)16)
-#define BULK_FIFO_SIZE ((unsigned)64)
-#define ISO_FIFO_SIZE  ((unsigned)256)
-#define INT_FIFO_SIZE  ((unsigned)8)
-
-struct udc_stats {
-       struct ep0stats {
-               unsigned long           ops;
-               unsigned long           bytes;
-       } read, write;
-       unsigned long                   irqs;
-};
-
-#ifdef CONFIG_USB_PXA2XX_SMALL
-/* when memory's tight, SMALL config saves code+data.  */
-#define        PXA_UDC_NUM_ENDPOINTS   3
-#endif
-
-#ifndef        PXA_UDC_NUM_ENDPOINTS
-#define        PXA_UDC_NUM_ENDPOINTS   16
-#endif
-
-struct pxa2xx_udc {
-       struct usb_gadget                       gadget;
-       struct usb_gadget_driver                *driver;
-
-       enum ep0_state                          ep0state;
-       struct udc_stats                        stats;
-       unsigned                                got_irq : 1,
-                                               vbus : 1,
-                                               pullup : 1,
-                                               has_cfr : 1,
-                                               req_pending : 1,
-                                               req_std : 1,
-                                               req_config : 1,
-                                               suspended : 1,
-                                               active : 1;
-
-#define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
-       struct timer_list                       timer;
-
-       struct device                           *dev;
-       struct clk                              *clk;
-       struct pxa2xx_udc_mach_info             *mach;
-       u64                                     dma_mask;
-       struct pxa2xx_ep                        ep [PXA_UDC_NUM_ENDPOINTS];
-
-#ifdef CONFIG_USB_GADGET_DEBUG_FS
-       struct dentry                           *debugfs_udc;
-#endif
-};
-
-/*-------------------------------------------------------------------------*/
-
-#ifdef CONFIG_ARCH_LUBBOCK
-#include <asm/arch/lubbock.h>
-/* lubbock can also report usb connect/disconnect irqs */
-#endif
-
-static struct pxa2xx_udc *the_controller;
-
-/*-------------------------------------------------------------------------*/
-
-/*
- * Debugging support vanishes in non-debug builds.  DBG_NORMAL should be
- * mostly silent during normal use/testing, with no timing side-effects.
- */
-#define DBG_NORMAL     1       /* error paths, device state transitions */
-#define DBG_VERBOSE    2       /* add some success path trace info */
-#define DBG_NOISY      3       /* ... even more: request level */
-#define DBG_VERY_NOISY 4       /* ... even more: packet level */
-
-#define DMSG(stuff...) pr_debug("udc: " stuff)
-
-#ifdef DEBUG
-
-static int is_vbus_present(void);
-
-static const char *state_name[] = {
-       "EP0_IDLE",
-       "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
-       "EP0_END_XFER", "EP0_STALL"
-};
-
-#ifdef VERBOSE_DEBUG
-#    define UDC_DEBUG DBG_VERBOSE
-#else
-#    define UDC_DEBUG DBG_NORMAL
-#endif
-
-static void __maybe_unused
-dump_udccr(const char *label)
-{
-       u32     udccr = UDCCR;
-       DMSG("%s %02X =%s%s%s%s%s%s%s%s\n",
-               label, udccr,
-               (udccr & UDCCR_REM) ? " rem" : "",
-               (udccr & UDCCR_RSTIR) ? " rstir" : "",
-               (udccr & UDCCR_SRM) ? " srm" : "",
-               (udccr & UDCCR_SUSIR) ? " susir" : "",
-               (udccr & UDCCR_RESIR) ? " resir" : "",
-               (udccr & UDCCR_RSM) ? " rsm" : "",
-               (udccr & UDCCR_UDA) ? " uda" : "",
-               (udccr & UDCCR_UDE) ? " ude" : "");
-}
-
-static void __maybe_unused
-dump_udccs0(const char *label)
-{
-       u32             udccs0 = UDCCS0;
-
-       DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n",
-               label, state_name[the_controller->ep0state], udccs0,
-               (udccs0 & UDCCS0_SA) ? " sa" : "",
-               (udccs0 & UDCCS0_RNE) ? " rne" : "",
-               (udccs0 & UDCCS0_FST) ? " fst" : "",
-               (udccs0 & UDCCS0_SST) ? " sst" : "",
-               (udccs0 & UDCCS0_DRWF) ? " dwrf" : "",
-               (udccs0 & UDCCS0_FTF) ? " ftf" : "",
-               (udccs0 & UDCCS0_IPR) ? " ipr" : "",
-               (udccs0 & UDCCS0_OPR) ? " opr" : "");
-}
-
-static void __maybe_unused
-dump_state(struct pxa2xx_udc *dev)
-{
-       u32             tmp;
-       unsigned        i;
-
-       DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
-               is_vbus_present() ? "host " : "disconnected",
-               state_name[dev->ep0state],
-               UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
-       dump_udccr("udccr");
-       if (dev->has_cfr) {
-               tmp = UDCCFR;
-               DMSG("udccfr %02X =%s%s\n", tmp,
-                       (tmp & UDCCFR_AREN) ? " aren" : "",
-                       (tmp & UDCCFR_ACM) ? " acm" : "");
-       }
-
-       if (!dev->driver) {
-               DMSG("no gadget driver bound\n");
-               return;
-       } else
-               DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
-
-       if (!is_vbus_present())
-               return;
-
-       dump_udccs0 ("udccs0");
-       DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n",
-               dev->stats.write.bytes, dev->stats.write.ops,
-               dev->stats.read.bytes, dev->stats.read.ops);
-
-       for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
-               if (dev->ep [i].desc == NULL)
-                       continue;
-               DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
-       }
-}
-
-#else
-
-#define        dump_udccr(x)   do{}while(0)
-#define        dump_udccs0(x)  do{}while(0)
-#define        dump_state(x)   do{}while(0)
-
-#define UDC_DEBUG ((unsigned)0)
-
-#endif
-
-#define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
-
-#define ERR(stuff...)          pr_err("udc: " stuff)
-#define WARN(stuff...)         pr_warning("udc: " stuff)
-#define INFO(stuff...)         pr_info("udc: " stuff)
-
-
-#endif /* __LINUX_USB_GADGET_PXA2XX_H */
index 3a7c24c..a19a4f8 100644 (file)
@@ -169,13 +169,16 @@ static void start_hnp(struct ohci_hcd *ohci)
 {
        const unsigned  port = ohci_to_hcd(ohci)->self.otg_port - 1;
        unsigned long   flags;
+       u32 l;
 
        otg_start_hnp(ohci->transceiver);
 
        local_irq_save(flags);
        ohci->transceiver->state = OTG_STATE_A_SUSPEND;
        writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
-       OTG_CTRL_REG &= ~OTG_A_BUSREQ;
+       l = omap_readl(OTG_CTRL);
+       l &= ~OTG_A_BUSREQ;
+       omap_writel(l, OTG_CTRL);
        local_irq_restore(flags);
 }
 
index d4ee27d..127b157 100644 (file)
@@ -27,6 +27,7 @@
 #include <asm/mach-types.h>
 #include <asm/hardware.h>
 #include <asm/arch/pxa-regs.h>
+#include <asm/arch/pxa2xx-regs.h> /* FIXME: for PSSR */
 #include <asm/arch/ohci.h>
 
 #define PXA_UHC_MAX_PORTNUM    3
@@ -104,7 +105,7 @@ static int pxa27x_start_hc(struct device *dev)
        UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
 
        /* Clear any OTG Pin Hold */
-       if (PSSR & PSSR_OTGPH)
+       if (cpu_is_pxa27x() && (PSSR & PSSR_OTGPH))
                PSSR |= PSSR_OTGPH;
 
        return 0;
index 4914553..293a462 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/poll.h>
 #include <linux/compat.h>
 #include <linux/mm.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -527,14 +528,17 @@ static int mon_bin_open(struct inode *inode, struct file *file)
        size_t size;
        int rc;
 
+       lock_kernel();
        mutex_lock(&mon_lock);
        if ((mbus = mon_bus_lookup(iminor(inode))) == NULL) {
                mutex_unlock(&mon_lock);
+               unlock_kernel();
                return -ENODEV;
        }
        if (mbus != &mon_bus0 && mbus->u_bus == NULL) {
                printk(KERN_ERR TAG ": consistency error on open\n");
                mutex_unlock(&mon_lock);
+               unlock_kernel();
                return -ENODEV;
        }
 
@@ -568,6 +572,7 @@ static int mon_bin_open(struct inode *inode, struct file *file)
 
        file->private_data = rp;
        mutex_unlock(&mon_lock);
+       unlock_kernel();
        return 0;
 
 err_allocbuff:
@@ -576,6 +581,7 @@ err_allocvec:
        kfree(rp);
 err_alloc:
        mutex_unlock(&mon_lock);
+       unlock_kernel();
        return rc;
 }
 
index e0c5f96..9b887ef 100644 (file)
@@ -7,7 +7,7 @@ menu "Graphics support"
 
 source "drivers/char/agp/Kconfig"
 
-source "drivers/char/drm/Kconfig"
+source "drivers/gpu/drm/Kconfig"
 
 config VGASTATE
        tristate
index dcd8073..30bf7f2 100644 (file)
@@ -112,3 +112,10 @@ config BACKLIGHT_CARILLO_RANCH
        help
          If you have a Intel LE80578 (Carillo Ranch) say Y to enable the
          backlight driver.
+
+config BACKLIGHT_PWM
+       tristate "Generic PWM based Backlight Driver"
+       depends on BACKLIGHT_CLASS_DEVICE && HAVE_PWM
+       help
+         If you have a LCD backlight adjustable by PWM, say Y to enable
+         this driver.
index 33f6c7c..b51a7cd 100644 (file)
@@ -10,3 +10,4 @@ obj-$(CONFIG_BACKLIGHT_LOCOMO)        += locomolcd.o
 obj-$(CONFIG_BACKLIGHT_OMAP1)  += omap1_bl.o
 obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
 obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
+obj-$(CONFIG_BACKLIGHT_PWM)    += pwm_bl.o
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
new file mode 100644 (file)
index 0000000..6338d0e
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * linux/drivers/video/backlight/pwm_bl.c
+ *
+ * simple PWM based backlight control, board code has to setup
+ * 1) pin configuration so PWM waveforms can output
+ * 2) platform_data casts to the PWM id (0/1/2/3 on PXA)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/fb.h>
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/pwm.h>
+#include <linux/pwm_backlight.h>
+
+struct pwm_bl_data {
+       struct pwm_device       *pwm;
+       unsigned int            period;
+       int                     (*notify)(int brightness);
+};
+
+static int pwm_backlight_update_status(struct backlight_device *bl)
+{
+       struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
+       int brightness = bl->props.brightness;
+       int max = bl->props.max_brightness;
+
+       if (bl->props.power != FB_BLANK_UNBLANK)
+               brightness = 0;
+
+       if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+               brightness = 0;
+
+       if (pb->notify)
+               brightness = pb->notify(brightness);
+
+       if (brightness == 0) {
+               pwm_config(pb->pwm, 0, pb->period);
+               pwm_disable(pb->pwm);
+       } else {
+               pwm_config(pb->pwm, brightness * pb->period / max, pb->period);
+               pwm_enable(pb->pwm);
+       }
+       return 0;
+}
+
+static int pwm_backlight_get_brightness(struct backlight_device *bl)
+{
+       return bl->props.brightness;
+}
+
+static struct backlight_ops pwm_backlight_ops = {
+       .update_status  = pwm_backlight_update_status,
+       .get_brightness = pwm_backlight_get_brightness,
+};
+
+static int pwm_backlight_probe(struct platform_device *pdev)
+{
+       struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
+       struct backlight_device *bl;
+       struct pwm_bl_data *pb;
+       int ret;
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->init) {
+               ret = data->init(&pdev->dev);
+               if (ret < 0)
+                       return ret;
+       }
+
+       pb = kzalloc(sizeof(*pb), GFP_KERNEL);
+       if (!pb) {
+               ret = -ENOMEM;
+               goto err_alloc;
+       }
+
+       pb->period = data->pwm_period_ns;
+       pb->notify = data->notify;
+
+       pb->pwm = pwm_request(data->pwm_id, "backlight");
+       if (IS_ERR(pb->pwm)) {
+               dev_err(&pdev->dev, "unable to request PWM for backlight\n");
+               ret = PTR_ERR(pb->pwm);
+               goto err_pwm;
+       }
+
+       bl = backlight_device_register(pdev->name, &pdev->dev,
+                       pb, &pwm_backlight_ops);
+       if (IS_ERR(bl)) {
+               dev_err(&pdev->dev, "failed to register backlight\n");
+               ret = PTR_ERR(bl);
+               goto err_bl;
+       }
+
+       bl->props.max_brightness = data->max_brightness;
+       bl->props.brightness = data->dft_brightness;
+       backlight_update_status(bl);
+
+       platform_set_drvdata(pdev, bl);
+       return 0;
+
+err_bl:
+       pwm_free(pb->pwm);
+err_pwm:
+       kfree(pb);
+err_alloc:
+       if (data->exit)
+               data->exit(&pdev->dev);
+       return ret;
+}
+
+static int pwm_backlight_remove(struct platform_device *pdev)
+{
+       struct platform_pwm_backlight_data *data = pdev->dev.platform_data;
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+       struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
+
+       backlight_device_unregister(bl);
+       pwm_config(pb->pwm, 0, pb->period);
+       pwm_disable(pb->pwm);
+       pwm_free(pb->pwm);
+       kfree(pb);
+       if (data->exit)
+               data->exit(&pdev->dev);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int pwm_backlight_suspend(struct platform_device *pdev,
+                                pm_message_t state)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+       struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
+
+       pwm_config(pb->pwm, 0, pb->period);
+       pwm_disable(pb->pwm);
+       return 0;
+}
+
+static int pwm_backlight_resume(struct platform_device *pdev)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+
+       backlight_update_status(bl);
+       return 0;
+}
+#else
+#define pwm_backlight_suspend  NULL
+#define pwm_backlight_resume   NULL
+#endif
+
+static struct platform_driver pwm_backlight_driver = {
+       .driver         = {
+               .name   = "pwm-backlight",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = pwm_backlight_probe,
+       .remove         = pwm_backlight_remove,
+       .suspend        = pwm_backlight_suspend,
+       .resume         = pwm_backlight_resume,
+};
+
+static int __init pwm_backlight_init(void)
+{
+       return platform_driver_register(&pwm_backlight_driver);
+}
+module_init(pwm_backlight_init);
+
+static void __exit pwm_backlight_exit(void)
+{
+       platform_driver_unregister(&pwm_backlight_driver);
+}
+module_exit(pwm_backlight_exit);
+
+MODULE_DESCRIPTION("PWM based Backlight Driver");
+MODULE_LICENSE("GPL");
index 776f7fc..33ebdb1 100644 (file)
@@ -1326,20 +1326,27 @@ fb_open(struct inode *inode, struct file *file)
 
        if (fbidx >= FB_MAX)
                return -ENODEV;
+       lock_kernel();
 #ifdef CONFIG_KMOD
        if (!(info = registered_fb[fbidx]))
                try_to_load(fbidx);
 #endif /* CONFIG_KMOD */
-       if (!(info = registered_fb[fbidx]))
-               return -ENODEV;
-       if (!try_module_get(info->fbops->owner))
-               return -ENODEV;
+       if (!(info = registered_fb[fbidx])) {
+               res = -ENODEV;
+               goto out;
+       }
+       if (!try_module_get(info->fbops->owner)) {
+               res = -ENODEV;
+               goto out;
+       }
        file->private_data = info;
        if (info->fbops->fb_open) {
                res = info->fbops->fb_open(info,1);
                if (res)
                        module_put(info->fbops->owner);
        }
+out:
+       unlock_kernel();
        return res;
 }
 
index fafe7db..d074626 100644 (file)
@@ -1792,11 +1792,49 @@ failed:
        return ret;
 }
 
+static int __devexit pxafb_remove(struct platform_device *dev)
+{
+       struct pxafb_info *fbi = platform_get_drvdata(dev);
+       struct resource *r;
+       int irq;
+       struct fb_info *info;
+
+       if (!fbi)
+               return 0;
+
+       info = &fbi->fb;
+
+       unregister_framebuffer(info);
+
+       pxafb_disable_controller(fbi);
+
+       if (fbi->fb.cmap.len)
+               fb_dealloc_cmap(&fbi->fb.cmap);
+
+       irq = platform_get_irq(dev, 0);
+       free_irq(irq, fbi);
+
+       dma_free_writecombine(&dev->dev, fbi->map_size,
+                                       fbi->map_cpu, fbi->map_dma);
+
+       iounmap(fbi->mmio_base);
+
+       r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       release_mem_region(r->start, r->end - r->start + 1);
+
+       clk_put(fbi->clk);
+       kfree(fbi);
+
+       return 0;
+}
+
 static struct platform_driver pxafb_driver = {
        .probe          = pxafb_probe,
+       .remove         = pxafb_remove,
        .suspend        = pxafb_suspend,
        .resume         = pxafb_resume,
        .driver         = {
+               .owner  = THIS_MODULE,
                .name   = "pxa2xx-fb",
        },
 };
@@ -1809,7 +1847,13 @@ static int __init pxafb_init(void)
        return platform_driver_register(&pxafb_driver);
 }
 
+static void __exit pxafb_exit(void)
+{
+       platform_driver_unregister(&pxafb_driver);
+}
+
 module_init(pxafb_init);
+module_exit(pxafb_exit);
 
 MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
 MODULE_LICENSE("GPL");
index 4fb1624..f5252c2 100644 (file)
@@ -21,8 +21,7 @@
 
 #include <asm/io.h>
 #include <asm/mtrr.h>
-
-#include <setup_arch.h>
+#include <asm/visws/sgivw.h>
 
 #define INCLUDE_TIMING_TABLE_DATA
 #define DBE_REG_BASE par->regs
index 619a6f8..47ed39b 100644 (file)
@@ -18,6 +18,7 @@
  * frame buffer.
  */
 
+#include <linux/console.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/fb.h>
@@ -42,37 +43,68 @@ struct xenfb_info {
        struct xenfb_page       *page;
        unsigned long           *mfns;
        int                     update_wanted; /* XENFB_TYPE_UPDATE wanted */
+       int                     feature_resize; /* XENFB_TYPE_RESIZE ok */
+       struct xenfb_resize     resize;         /* protected by resize_lock */
+       int                     resize_dpy;     /* ditto */
+       spinlock_t              resize_lock;
 
        struct xenbus_device    *xbdev;
 };
 
-static u32 xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
+#define XENFB_DEFAULT_FB_LEN (XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8)
 
+enum { KPARAM_MEM, KPARAM_WIDTH, KPARAM_HEIGHT, KPARAM_CNT };
+static int video[KPARAM_CNT] = { 2, XENFB_WIDTH, XENFB_HEIGHT };
+module_param_array(video, int, NULL, 0);
+MODULE_PARM_DESC(video,
+       "Video memory size in MB, width, height in pixels (default 2,800,600)");
+
+static void xenfb_make_preferred_console(void);
 static int xenfb_remove(struct xenbus_device *);
-static void xenfb_init_shared_page(struct xenfb_info *);
+static void xenfb_init_shared_page(struct xenfb_info *, struct fb_info *);
 static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
 static void xenfb_disconnect_backend(struct xenfb_info *);
 
+static void xenfb_send_event(struct xenfb_info *info,
+                            union xenfb_out_event *event)
+{
+       u32 prod;
+
+       prod = info->page->out_prod;
+       /* caller ensures !xenfb_queue_full() */
+       mb();                   /* ensure ring space available */
+       XENFB_OUT_RING_REF(info->page, prod) = *event;
+       wmb();                  /* ensure ring contents visible */
+       info->page->out_prod = prod + 1;
+
+       notify_remote_via_irq(info->irq);
+}
+
 static void xenfb_do_update(struct xenfb_info *info,
                            int x, int y, int w, int h)
 {
        union xenfb_out_event event;
-       u32 prod;
 
+       memset(&event, 0, sizeof(event));
        event.type = XENFB_TYPE_UPDATE;
        event.update.x = x;
        event.update.y = y;
        event.update.width = w;
        event.update.height = h;
 
-       prod = info->page->out_prod;
        /* caller ensures !xenfb_queue_full() */
-       mb();                   /* ensure ring space available */
-       XENFB_OUT_RING_REF(info->page, prod) = event;
-       wmb();                  /* ensure ring contents visible */
-       info->page->out_prod = prod + 1;
+       xenfb_send_event(info, &event);
+}
 
-       notify_remote_via_irq(info->irq);
+static void xenfb_do_resize(struct xenfb_info *info)
+{
+       union xenfb_out_event event;
+
+       memset(&event, 0, sizeof(event));
+       event.resize = info->resize;
+
+       /* caller ensures !xenfb_queue_full() */
+       xenfb_send_event(info, &event);
 }
 
 static int xenfb_queue_full(struct xenfb_info *info)
@@ -84,12 +116,28 @@ static int xenfb_queue_full(struct xenfb_info *info)
        return prod - cons == XENFB_OUT_RING_LEN;
 }
 
+static void xenfb_handle_resize_dpy(struct xenfb_info *info)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&info->resize_lock, flags);
+       if (info->resize_dpy) {
+               if (!xenfb_queue_full(info)) {
+                       info->resize_dpy = 0;
+                       xenfb_do_resize(info);
+               }
+       }
+       spin_unlock_irqrestore(&info->resize_lock, flags);
+}
+
 static void xenfb_refresh(struct xenfb_info *info,
                          int x1, int y1, int w, int h)
 {
        unsigned long flags;
-       int y2 = y1 + h - 1;
        int x2 = x1 + w - 1;
+       int y2 = y1 + h - 1;
+
+       xenfb_handle_resize_dpy(info);
 
        if (!info->update_wanted)
                return;
@@ -222,6 +270,57 @@ static ssize_t xenfb_write(struct fb_info *p, const char __user *buf,
        return res;
 }
 
+static int
+xenfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+       struct xenfb_info *xenfb_info;
+       int required_mem_len;
+
+       xenfb_info = info->par;
+
+       if (!xenfb_info->feature_resize) {
+               if (var->xres == video[KPARAM_WIDTH] &&
+                   var->yres == video[KPARAM_HEIGHT] &&
+                   var->bits_per_pixel == xenfb_info->page->depth) {
+                       return 0;
+               }
+               return -EINVAL;
+       }
+
+       /* Can't resize past initial width and height */
+       if (var->xres > video[KPARAM_WIDTH] || var->yres > video[KPARAM_HEIGHT])
+               return -EINVAL;
+
+       required_mem_len = var->xres * var->yres * xenfb_info->page->depth / 8;
+       if (var->bits_per_pixel == xenfb_info->page->depth &&
+           var->xres <= info->fix.line_length / (XENFB_DEPTH / 8) &&
+           required_mem_len <= info->fix.smem_len) {
+               var->xres_virtual = var->xres;
+               var->yres_virtual = var->yres;
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int xenfb_set_par(struct fb_info *info)
+{
+       struct xenfb_info *xenfb_info;
+       unsigned long flags;
+
+       xenfb_info = info->par;
+
+       spin_lock_irqsave(&xenfb_info->resize_lock, flags);
+       xenfb_info->resize.type = XENFB_TYPE_RESIZE;
+       xenfb_info->resize.width = info->var.xres;
+       xenfb_info->resize.height = info->var.yres;
+       xenfb_info->resize.stride = info->fix.line_length;
+       xenfb_info->resize.depth = info->var.bits_per_pixel;
+       xenfb_info->resize.offset = 0;
+       xenfb_info->resize_dpy = 1;
+       spin_unlock_irqrestore(&xenfb_info->resize_lock, flags);
+       return 0;
+}
+
 static struct fb_ops xenfb_fb_ops = {
        .owner          = THIS_MODULE,
        .fb_read        = fb_sys_read,
@@ -230,6 +329,8 @@ static struct fb_ops xenfb_fb_ops = {
        .fb_fillrect    = xenfb_fillrect,
        .fb_copyarea    = xenfb_copyarea,
        .fb_imageblit   = xenfb_imageblit,
+       .fb_check_var   = xenfb_check_var,
+       .fb_set_par     = xenfb_set_par,
 };
 
 static irqreturn_t xenfb_event_handler(int rq, void *dev_id)
@@ -258,6 +359,8 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
 {
        struct xenfb_info *info;
        struct fb_info *fb_info;
+       int fb_size;
+       int val;
        int ret;
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -265,18 +368,35 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
                xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
                return -ENOMEM;
        }
+
+       /* Limit kernel param videoram amount to what is in xenstore */
+       if (xenbus_scanf(XBT_NIL, dev->otherend, "videoram", "%d", &val) == 1) {
+               if (val < video[KPARAM_MEM])
+                       video[KPARAM_MEM] = val;
+       }
+
+       /* If requested res does not fit in available memory, use default */
+       fb_size = video[KPARAM_MEM] * 1024 * 1024;
+       if (video[KPARAM_WIDTH] * video[KPARAM_HEIGHT] * XENFB_DEPTH / 8
+           > fb_size) {
+               video[KPARAM_WIDTH] = XENFB_WIDTH;
+               video[KPARAM_HEIGHT] = XENFB_HEIGHT;
+               fb_size = XENFB_DEFAULT_FB_LEN;
+       }
+
        dev->dev.driver_data = info;
        info->xbdev = dev;
        info->irq = -1;
        info->x1 = info->y1 = INT_MAX;
        spin_lock_init(&info->dirty_lock);
+       spin_lock_init(&info->resize_lock);
 
-       info->fb = vmalloc(xenfb_mem_len);
+       info->fb = vmalloc(fb_size);
        if (info->fb == NULL)
                goto error_nomem;
-       memset(info->fb, 0, xenfb_mem_len);
+       memset(info->fb, 0, fb_size);
 
-       info->nr_pages = (xenfb_mem_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
        info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
        if (!info->mfns)
@@ -287,8 +407,6 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        if (!info->page)
                goto error_nomem;
 
-       xenfb_init_shared_page(info);
-
        /* abusing framebuffer_alloc() to allocate pseudo_palette */
        fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
        if (fb_info == NULL)
@@ -301,9 +419,9 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        fb_info->screen_base = info->fb;
 
        fb_info->fbops = &xenfb_fb_ops;
-       fb_info->var.xres_virtual = fb_info->var.xres = info->page->width;
-       fb_info->var.yres_virtual = fb_info->var.yres = info->page->height;
-       fb_info->var.bits_per_pixel = info->page->depth;
+       fb_info->var.xres_virtual = fb_info->var.xres = video[KPARAM_WIDTH];
+       fb_info->var.yres_virtual = fb_info->var.yres = video[KPARAM_HEIGHT];
+       fb_info->var.bits_per_pixel = XENFB_DEPTH;
 
        fb_info->var.red = (struct fb_bitfield){16, 8, 0};
        fb_info->var.green = (struct fb_bitfield){8, 8, 0};
@@ -315,9 +433,9 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        fb_info->var.vmode = FB_VMODE_NONINTERLACED;
 
        fb_info->fix.visual = FB_VISUAL_TRUECOLOR;
-       fb_info->fix.line_length = info->page->line_length;
+       fb_info->fix.line_length = fb_info->var.xres * XENFB_DEPTH / 8;
        fb_info->fix.smem_start = 0;
-       fb_info->fix.smem_len = xenfb_mem_len;
+       fb_info->fix.smem_len = fb_size;
        strcpy(fb_info->fix.id, "xen");
        fb_info->fix.type = FB_TYPE_PACKED_PIXELS;
        fb_info->fix.accel = FB_ACCEL_NONE;
@@ -334,6 +452,8 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        fb_info->fbdefio = &xenfb_defio;
        fb_deferred_io_init(fb_info);
 
+       xenfb_init_shared_page(info, fb_info);
+
        ret = register_framebuffer(fb_info);
        if (ret) {
                fb_deferred_io_cleanup(fb_info);
@@ -348,6 +468,7 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        if (ret < 0)
                goto error;
 
+       xenfb_make_preferred_console();
        return 0;
 
  error_nomem:
@@ -358,12 +479,34 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
        return ret;
 }
 
+static __devinit void
+xenfb_make_preferred_console(void)
+{
+       struct console *c;
+
+       if (console_set_on_cmdline)
+               return;
+
+       acquire_console_sem();
+       for (c = console_drivers; c; c = c->next) {
+               if (!strcmp(c->name, "tty") && c->index == 0)
+                       break;
+       }
+       release_console_sem();
+       if (c) {
+               unregister_console(c);
+               c->flags |= CON_CONSDEV;
+               c->flags &= ~CON_PRINTBUFFER; /* don't print again */
+               register_console(c);
+       }
+}
+
 static int xenfb_resume(struct xenbus_device *dev)
 {
        struct xenfb_info *info = dev->dev.driver_data;
 
        xenfb_disconnect_backend(info);
-       xenfb_init_shared_page(info);
+       xenfb_init_shared_page(info, info->fb_info);
        return xenfb_connect_backend(dev, info);
 }
 
@@ -391,20 +534,23 @@ static unsigned long vmalloc_to_mfn(void *address)
        return pfn_to_mfn(vmalloc_to_pfn(address));
 }
 
-static void xenfb_init_shared_page(struct xenfb_info *info)
+static void xenfb_init_shared_page(struct xenfb_info *info,
+                                  struct fb_info *fb_info)
 {
        int i;
+       int epd = PAGE_SIZE / sizeof(info->mfns[0]);
 
        for (i = 0; i < info->nr_pages; i++)
                info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
 
-       info->page->pd[0] = vmalloc_to_mfn(info->mfns);
-       info->page->pd[1] = 0;
-       info->page->width = XENFB_WIDTH;
-       info->page->height = XENFB_HEIGHT;
-       info->page->depth = XENFB_DEPTH;
-       info->page->line_length = (info->page->depth / 8) * info->page->width;
-       info->page->mem_length = xenfb_mem_len;
+       for (i = 0; i * epd < info->nr_pages; i++)
+               info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
+
+       info->page->width = fb_info->var.xres;
+       info->page->height = fb_info->var.yres;
+       info->page->depth = fb_info->var.bits_per_pixel;
+       info->page->line_length = fb_info->fix.line_length;
+       info->page->mem_length = fb_info->fix.smem_len;
        info->page->in_cons = info->page->in_prod = 0;
        info->page->out_cons = info->page->out_prod = 0;
 }
@@ -504,6 +650,11 @@ InitWait:
                        val = 0;
                if (val)
                        info->update_wanted = 1;
+
+               if (xenbus_scanf(XBT_NIL, dev->otherend,
+                                "feature-resize", "%d", &val) < 0)
+                       val = 0;
+               info->feature_resize = val;
                break;
 
        case XenbusStateClosing:
@@ -547,4 +698,6 @@ static void __exit xenfb_cleanup(void)
 module_init(xenfb_init);
 module_exit(xenfb_cleanup);
 
+MODULE_DESCRIPTION("Xen virtual framebuffer device frontend");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("xen:vfb");
index 37af04f..363286c 100644 (file)
@@ -1,4 +1,4 @@
-obj-y  += grant-table.o features.o events.o
+obj-y  += grant-table.o features.o events.o manage.o
 obj-y  += xenbus/
 obj-$(CONFIG_XEN_XENCOMM)      += xencomm.o
 obj-$(CONFIG_XEN_BALLOON)      += balloon.o
index ab25ba6..591bc29 100644 (file)
@@ -225,7 +225,7 @@ static int increase_reservation(unsigned long nr_pages)
                page = balloon_next_page(page);
        }
 
-       reservation.extent_start = (unsigned long)frame_list;
+       set_xen_guest_handle(reservation.extent_start, frame_list);
        reservation.nr_extents   = nr_pages;
        rc = HYPERVISOR_memory_op(
                XENMEM_populate_physmap, &reservation);
@@ -321,7 +321,7 @@ static int decrease_reservation(unsigned long nr_pages)
                balloon_append(pfn_to_page(pfn));
        }
 
-       reservation.extent_start = (unsigned long)frame_list;
+       set_xen_guest_handle(reservation.extent_start, frame_list);
        reservation.nr_extents   = nr_pages;
        ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
        BUG_ON(ret != nr_pages);
@@ -368,7 +368,7 @@ static void balloon_process(struct work_struct *work)
 }
 
 /* Resets the Xen limit, sets new target, and kicks off processing. */
-void balloon_set_new_target(unsigned long target)
+static void balloon_set_new_target(unsigned long target)
 {
        /* No need for lock. Not read-modify-write updates. */
        balloon_stats.hard_limit   = ~0UL;
@@ -483,7 +483,7 @@ static int dealloc_pte_fn(
                .extent_order = 0,
                .domid        = DOMID_SELF
        };
-       reservation.extent_start = (unsigned long)&mfn;
+       set_xen_guest_handle(reservation.extent_start, &mfn);
        set_pte_at(&init_mm, addr, pte, __pte_ma(0ull));
        set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY);
        ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
@@ -519,7 +519,7 @@ static struct page **alloc_empty_pages_and_pagevec(int nr_pages)
                                .extent_order = 0,
                                .domid        = DOMID_SELF
                        };
-                       reservation.extent_start = (unsigned long)&gmfn;
+                       set_xen_guest_handle(reservation.extent_start, &gmfn);
                        ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
                                                   &reservation);
                        if (ret == 1)
index 76e5b73..332dd63 100644 (file)
@@ -355,7 +355,7 @@ static void unbind_from_irq(unsigned int irq)
 
        spin_lock(&irq_mapping_update_lock);
 
-       if (VALID_EVTCHN(evtchn) && (--irq_bindcount[irq] == 0)) {
+       if ((--irq_bindcount[irq] == 0) && VALID_EVTCHN(evtchn)) {
                close.port = evtchn;
                if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
                        BUG();
@@ -375,7 +375,7 @@ static void unbind_from_irq(unsigned int irq)
                evtchn_to_irq[evtchn] = -1;
                irq_info[irq] = IRQ_UNBOUND;
 
-               dynamic_irq_init(irq);
+               dynamic_irq_cleanup(irq);
        }
 
        spin_unlock(&irq_mapping_update_lock);
@@ -557,6 +557,33 @@ out:
        put_cpu();
 }
 
+/* Rebind a new event channel to an existing irq. */
+void rebind_evtchn_irq(int evtchn, int irq)
+{
+       /* Make sure the irq is masked, since the new event channel
+          will also be masked. */
+       disable_irq(irq);
+
+       spin_lock(&irq_mapping_update_lock);
+
+       /* After resume the irq<->evtchn mappings are all cleared out */
+       BUG_ON(evtchn_to_irq[evtchn] != -1);
+       /* Expect irq to have been bound before,
+          so the bindcount should be non-0 */
+       BUG_ON(irq_bindcount[irq] == 0);
+
+       evtchn_to_irq[evtchn] = irq;
+       irq_info[irq] = mk_irq_info(IRQT_EVTCHN, 0, evtchn);
+
+       spin_unlock(&irq_mapping_update_lock);
+
+       /* new event channels are always bound to cpu 0 */
+       irq_set_affinity(irq, cpumask_of_cpu(0));
+
+       /* Unmask the event channel. */
+       enable_irq(irq);
+}
+
 /* Rebind an evtchn so that it gets delivered to a specific cpu */
 static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
 {
@@ -647,6 +674,89 @@ static int retrigger_dynirq(unsigned int irq)
        return ret;
 }
 
+static void restore_cpu_virqs(unsigned int cpu)
+{
+       struct evtchn_bind_virq bind_virq;
+       int virq, irq, evtchn;
+
+       for (virq = 0; virq < NR_VIRQS; virq++) {
+               if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1)
+                       continue;
+
+               BUG_ON(irq_info[irq].type != IRQT_VIRQ);
+               BUG_ON(irq_info[irq].index != virq);
+
+               /* Get a new binding from Xen. */
+               bind_virq.virq = virq;
+               bind_virq.vcpu = cpu;
+               if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
+                                               &bind_virq) != 0)
+                       BUG();
+               evtchn = bind_virq.port;
+
+               /* Record the new mapping. */
+               evtchn_to_irq[evtchn] = irq;
+               irq_info[irq] = mk_irq_info(IRQT_VIRQ, virq, evtchn);
+               bind_evtchn_to_cpu(evtchn, cpu);
+
+               /* Ready for use. */
+               unmask_evtchn(evtchn);
+       }
+}
+
+static void restore_cpu_ipis(unsigned int cpu)
+{
+       struct evtchn_bind_ipi bind_ipi;
+       int ipi, irq, evtchn;
+
+       for (ipi = 0; ipi < XEN_NR_IPIS; ipi++) {
+               if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1)
+                       continue;
+
+               BUG_ON(irq_info[irq].type != IRQT_IPI);
+               BUG_ON(irq_info[irq].index != ipi);
+
+               /* Get a new binding from Xen. */
+               bind_ipi.vcpu = cpu;
+               if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
+                                               &bind_ipi) != 0)
+                       BUG();
+               evtchn = bind_ipi.port;
+
+               /* Record the new mapping. */
+               evtchn_to_irq[evtchn] = irq;
+               irq_info[irq] = mk_irq_info(IRQT_IPI, ipi, evtchn);
+               bind_evtchn_to_cpu(evtchn, cpu);
+
+               /* Ready for use. */
+               unmask_evtchn(evtchn);
+
+       }
+}
+
+void xen_irq_resume(void)
+{
+       unsigned int cpu, irq, evtchn;
+
+       init_evtchn_cpu_bindings();
+
+       /* New event-channel space is not 'live' yet. */
+       for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
+               mask_evtchn(evtchn);
+
+       /* No IRQ <-> event-channel mappings. */
+       for (irq = 0; irq < NR_IRQS; irq++)
+               irq_info[irq].evtchn = 0; /* zap event-channel binding */
+
+       for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
+               evtchn_to_irq[evtchn] = -1;
+
+       for_each_possible_cpu(cpu) {
+               restore_cpu_virqs(cpu);
+               restore_cpu_ipis(cpu);
+       }
+}
+
 static struct irq_chip xen_dynamic_chip __read_mostly = {
        .name           = "xen-dyn",
        .mask           = disable_dynirq,
index 52b6b41..e9e1116 100644 (file)
@@ -471,14 +471,14 @@ static int gnttab_map(unsigned int start_idx, unsigned int end_idx)
        return 0;
 }
 
-static int gnttab_resume(void)
+int gnttab_resume(void)
 {
        if (max_nr_grant_frames() < nr_grant_frames)
                return -ENOSYS;
        return gnttab_map(0, nr_grant_frames - 1);
 }
 
-static int gnttab_suspend(void)
+int gnttab_suspend(void)
 {
        arch_gnttab_unmap_shared(shared, nr_grant_frames);
        return 0;
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
new file mode 100644 (file)
index 0000000..5b546e3
--- /dev/null
@@ -0,0 +1,252 @@
+/*
+ * Handle extern requests for shutdown, reboot and sysrq
+ */
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/reboot.h>
+#include <linux/sysrq.h>
+#include <linux/stop_machine.h>
+#include <linux/freezer.h>
+
+#include <xen/xenbus.h>
+#include <xen/grant_table.h>
+#include <xen/events.h>
+#include <xen/hvc-console.h>
+#include <xen/xen-ops.h>
+
+#include <asm/xen/hypercall.h>
+#include <asm/xen/page.h>
+
+enum shutdown_state {
+       SHUTDOWN_INVALID = -1,
+       SHUTDOWN_POWEROFF = 0,
+       SHUTDOWN_SUSPEND = 2,
+       /* Code 3 is SHUTDOWN_CRASH, which we don't use because the domain can only
+          report a crash, not be instructed to crash!
+          HALT is the same as POWEROFF, as far as we're concerned.  The tools use
+          the distinction when we return the reason code to them.  */
+        SHUTDOWN_HALT = 4,
+};
+
+/* Ignore multiple shutdown requests. */
+static enum shutdown_state shutting_down = SHUTDOWN_INVALID;
+
+#ifdef CONFIG_PM_SLEEP
+static int xen_suspend(void *data)
+{
+       int *cancelled = data;
+       int err;
+
+       BUG_ON(!irqs_disabled());
+
+       load_cr3(swapper_pg_dir);
+
+       err = device_power_down(PMSG_SUSPEND);
+       if (err) {
+               printk(KERN_ERR "xen_suspend: device_power_down failed: %d\n",
+                      err);
+               return err;
+       }
+
+       xen_mm_pin_all();
+       gnttab_suspend();
+       xen_pre_suspend();
+
+       /*
+        * This hypercall returns 1 if suspend was cancelled
+        * or the domain was merely checkpointed, and 0 if it
+        * is resuming in a new domain.
+        */
+       *cancelled = HYPERVISOR_suspend(virt_to_mfn(xen_start_info));
+
+       xen_post_suspend(*cancelled);
+       gnttab_resume();
+       xen_mm_unpin_all();
+
+       device_power_up();
+
+       if (!*cancelled) {
+               xen_irq_resume();
+               xen_console_resume();
+       }
+
+       return 0;
+}
+
+static void do_suspend(void)
+{
+       int err;
+       int cancelled = 1;
+
+       shutting_down = SHUTDOWN_SUSPEND;
+
+#ifdef CONFIG_PREEMPT
+       /* If the kernel is preemptible, we need to freeze all the processes
+          to prevent them from being in the middle of a pagetable update
+          during suspend. */
+       err = freeze_processes();
+       if (err) {
+               printk(KERN_ERR "xen suspend: freeze failed %d\n", err);
+               return;
+       }
+#endif
+
+       err = device_suspend(PMSG_SUSPEND);
+       if (err) {
+               printk(KERN_ERR "xen suspend: device_suspend %d\n", err);
+               goto out;
+       }
+
+       printk("suspending xenbus...\n");
+       /* XXX use normal device tree? */
+       xenbus_suspend();
+
+       err = stop_machine_run(xen_suspend, &cancelled, 0);
+       if (err) {
+               printk(KERN_ERR "failed to start xen_suspend: %d\n", err);
+               goto out;
+       }
+
+       if (!cancelled)
+               xenbus_resume();
+       else
+               xenbus_suspend_cancel();
+
+       device_resume();
+
+       /* Make sure timer events get retriggered on all CPUs */
+       clock_was_set();
+out:
+#ifdef CONFIG_PREEMPT
+       thaw_processes();
+#endif
+       shutting_down = SHUTDOWN_INVALID;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static void shutdown_handler(struct xenbus_watch *watch,
+                            const char **vec, unsigned int len)
+{
+       char *str;
+       struct xenbus_transaction xbt;
+       int err;
+
+       if (shutting_down != SHUTDOWN_INVALID)
+               return;
+
+ again:
+       err = xenbus_transaction_start(&xbt);
+       if (err)
+               return;
+
+       str = (char *)xenbus_read(xbt, "control", "shutdown", NULL);
+       /* Ignore read errors and empty reads. */
+       if (XENBUS_IS_ERR_READ(str)) {
+               xenbus_transaction_end(xbt, 1);
+               return;
+       }
+
+       xenbus_write(xbt, "control", "shutdown", "");
+
+       err = xenbus_transaction_end(xbt, 0);
+       if (err == -EAGAIN) {
+               kfree(str);
+               goto again;
+       }
+
+       if (strcmp(str, "poweroff") == 0 ||
+           strcmp(str, "halt") == 0) {
+               shutting_down = SHUTDOWN_POWEROFF;
+               orderly_poweroff(false);
+       } else if (strcmp(str, "reboot") == 0) {
+               shutting_down = SHUTDOWN_POWEROFF; /* ? */
+               ctrl_alt_del();
+#ifdef CONFIG_PM_SLEEP
+       } else if (strcmp(str, "suspend") == 0) {
+               do_suspend();
+#endif
+       } else {
+               printk(KERN_INFO "Ignoring shutdown request: %s\n", str);
+               shutting_down = SHUTDOWN_INVALID;
+       }
+
+       kfree(str);
+}
+
+static void sysrq_handler(struct xenbus_watch *watch, const char **vec,
+                         unsigned int len)
+{
+       char sysrq_key = '\0';
+       struct xenbus_transaction xbt;
+       int err;
+
+ again:
+       err = xenbus_transaction_start(&xbt);
+       if (err)
+               return;
+       if (!xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key)) {
+               printk(KERN_ERR "Unable to read sysrq code in "
+                      "control/sysrq\n");
+               xenbus_transaction_end(xbt, 1);
+               return;
+       }
+
+       if (sysrq_key != '\0')
+               xenbus_printf(xbt, "control", "sysrq", "%c", '\0');
+
+       err = xenbus_transaction_end(xbt, 0);
+       if (err == -EAGAIN)
+               goto again;
+
+       if (sysrq_key != '\0')
+               handle_sysrq(sysrq_key, NULL);
+}
+
+static struct xenbus_watch shutdown_watch = {
+       .node = "control/shutdown",
+       .callback = shutdown_handler
+};
+
+static struct xenbus_watch sysrq_watch = {
+       .node = "control/sysrq",
+       .callback = sysrq_handler
+};
+
+static int setup_shutdown_watcher(void)
+{
+       int err;
+
+       err = register_xenbus_watch(&shutdown_watch);
+       if (err) {
+               printk(KERN_ERR "Failed to set shutdown watcher\n");
+               return err;
+       }
+
+       err = register_xenbus_watch(&sysrq_watch);
+       if (err) {
+               printk(KERN_ERR "Failed to set sysrq watcher\n");
+               return err;
+       }
+
+       return 0;
+}
+
+static int shutdown_event(struct notifier_block *notifier,
+                         unsigned long event,
+                         void *data)
+{
+       setup_shutdown_watcher();
+       return NOTIFY_DONE;
+}
+
+static int __init setup_shutdown_event(void)
+{
+       static struct notifier_block xenstore_notifier = {
+               .notifier_call = shutdown_event
+       };
+       register_xenstore_notifier(&xenstore_notifier);
+
+       return 0;
+}
+
+subsys_initcall(setup_shutdown_event);
index 0f86b0f..9678b3e 100644 (file)
@@ -117,7 +117,7 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev,
        char *path;
 
        va_start(ap, pathfmt);
-       path = kvasprintf(GFP_KERNEL, pathfmt, ap);
+       path = kvasprintf(GFP_NOIO | __GFP_HIGH, pathfmt, ap);
        va_end(ap);
 
        if (!path) {
index 6efbe3f..090c61e 100644 (file)
@@ -203,7 +203,6 @@ int xb_read(void *data, unsigned len)
 int xb_init_comms(void)
 {
        struct xenstore_domain_interface *intf = xen_store_interface;
-       int err;
 
        if (intf->req_prod != intf->req_cons)
                printk(KERN_ERR "XENBUS request ring is not quiescent "
@@ -216,18 +215,20 @@ int xb_init_comms(void)
                intf->rsp_cons = intf->rsp_prod;
        }
 
-       if (xenbus_irq)
-               unbind_from_irqhandler(xenbus_irq, &xb_waitq);
+       if (xenbus_irq) {
+               /* Already have an irq; assume we're resuming */
+               rebind_evtchn_irq(xen_store_evtchn, xenbus_irq);
+       } else {
+               int err;
+               err = bind_evtchn_to_irqhandler(xen_store_evtchn, wake_waiting,
+                                               0, "xenbus", &xb_waitq);
+               if (err <= 0) {
+                       printk(KERN_ERR "XENBUS request irq failed %i\n", err);
+                       return err;
+               }
 
-       err = bind_evtchn_to_irqhandler(
-               xen_store_evtchn, wake_waiting,
-               0, "xenbus", &xb_waitq);
-       if (err <= 0) {
-               printk(KERN_ERR "XENBUS request irq failed %i\n", err);
-               return err;
+               xenbus_irq = err;
        }
 
-       xenbus_irq = err;
-
        return 0;
 }
index 227d53b..7f2f91c 100644 (file)
@@ -283,9 +283,9 @@ static char *join(const char *dir, const char *name)
        char *buffer;
 
        if (strlen(name) == 0)
-               buffer = kasprintf(GFP_KERNEL, "%s", dir);
+               buffer = kasprintf(GFP_NOIO | __GFP_HIGH, "%s", dir);
        else
-               buffer = kasprintf(GFP_KERNEL, "%s/%s", dir, name);
+               buffer = kasprintf(GFP_NOIO | __GFP_HIGH, "%s/%s", dir, name);
        return (!buffer) ? ERR_PTR(-ENOMEM) : buffer;
 }
 
@@ -297,7 +297,7 @@ static char **split(char *strings, unsigned int len, unsigned int *num)
        *num = count_strings(strings, len);
 
        /* Transfer to one big alloc for easy freeing. */
-       ret = kmalloc(*num * sizeof(char *) + len, GFP_KERNEL);
+       ret = kmalloc(*num * sizeof(char *) + len, GFP_NOIO | __GFP_HIGH);
        if (!ret) {
                kfree(strings);
                return ERR_PTR(-ENOMEM);
@@ -751,7 +751,7 @@ static int process_msg(void)
        }
 
 
-       msg = kmalloc(sizeof(*msg), GFP_KERNEL);
+       msg = kmalloc(sizeof(*msg), GFP_NOIO | __GFP_HIGH);
        if (msg == NULL) {
                err = -ENOMEM;
                goto out;
@@ -763,7 +763,7 @@ static int process_msg(void)
                goto out;
        }
 
-       body = kmalloc(msg->hdr.len + 1, GFP_KERNEL);
+       body = kmalloc(msg->hdr.len + 1, GFP_NOIO | __GFP_HIGH);
        if (body == NULL) {
                kfree(msg);
                err = -ENOMEM;
index 2694648..313b2e0 100644 (file)
@@ -930,7 +930,7 @@ config PROC_KCORE
 
 config PROC_VMCORE
         bool "/proc/vmcore support (EXPERIMENTAL)"
-        depends on PROC_FS && EXPERIMENTAL && CRASH_DUMP
+        depends on PROC_FS && CRASH_DUMP
        default y
         help
         Exports the dump image of crashed kernel in ELF format.
index 1e7a11b..277b079 100644 (file)
@@ -19,6 +19,7 @@ else
 obj-y +=       no-block.o
 endif
 
+obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o
 obj-$(CONFIG_INOTIFY)          += inotify.o
 obj-$(CONFIG_INOTIFY_USER)     += inotify_user.o
 obj-$(CONFIG_EPOLL)            += eventpoll.o
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
new file mode 100644 (file)
index 0000000..63e2ee6
--- /dev/null
@@ -0,0 +1,719 @@
+/*
+ * bio-integrity.c - bio data integrity extensions
+ *
+ * Copyright (C) 2007, 2008 Oracle Corporation
+ * Written by: Martin K. Petersen <martin.petersen@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
+ * USA.
+ *
+ */
+
+#include <linux/blkdev.h>
+#include <linux/mempool.h>
+#include <linux/bio.h>
+#include <linux/workqueue.h>
+
+static struct kmem_cache *bio_integrity_slab __read_mostly;
+static struct workqueue_struct *kintegrityd_wq;
+
+/**
+ * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio
+ * @bio:       bio to attach integrity metadata to
+ * @gfp_mask:  Memory allocation mask
+ * @nr_vecs:   Number of integrity metadata scatter-gather elements
+ * @bs:                bio_set to allocate from
+ *
+ * Description: This function prepares a bio for attaching integrity
+ * metadata.  nr_vecs specifies the maximum number of pages containing
+ * integrity metadata that can be attached.
+ */
+struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
+                                                        gfp_t gfp_mask,
+                                                        unsigned int nr_vecs,
+                                                        struct bio_set *bs)
+{
+       struct bio_integrity_payload *bip;
+       struct bio_vec *iv;
+       unsigned long idx;
+
+       BUG_ON(bio == NULL);
+
+       bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
+       if (unlikely(bip == NULL)) {
+               printk(KERN_ERR "%s: could not alloc bip\n", __func__);
+               return NULL;
+       }
+
+       memset(bip, 0, sizeof(*bip));
+
+       iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, bs);
+       if (unlikely(iv == NULL)) {
+               printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__);
+               mempool_free(bip, bs->bio_integrity_pool);
+               return NULL;
+       }
+
+       bip->bip_pool = idx;
+       bip->bip_vec = iv;
+       bip->bip_bio = bio;
+       bio->bi_integrity = bip;
+
+       return bip;
+}
+EXPORT_SYMBOL(bio_integrity_alloc_bioset);
+
+/**
+ * bio_integrity_alloc - Allocate integrity payload and attach it to bio
+ * @bio:       bio to attach integrity metadata to
+ * @gfp_mask:  Memory allocation mask
+ * @nr_vecs:   Number of integrity metadata scatter-gather elements
+ *
+ * Description: This function prepares a bio for attaching integrity
+ * metadata.  nr_vecs specifies the maximum number of pages containing
+ * integrity metadata that can be attached.
+ */
+struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
+                                                 gfp_t gfp_mask,
+                                                 unsigned int nr_vecs)
+{
+       return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set);
+}
+EXPORT_SYMBOL(bio_integrity_alloc);
+
+/**
+ * bio_integrity_free - Free bio integrity payload
+ * @bio:       bio containing bip to be freed
+ * @bs:                bio_set this bio was allocated from
+ *
+ * Description: Used to free the integrity portion of a bio. Usually
+ * called from bio_free().
+ */
+void bio_integrity_free(struct bio *bio, struct bio_set *bs)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+
+       BUG_ON(bip == NULL);
+
+       /* A cloned bio doesn't own the integrity metadata */
+       if (!bio_flagged(bio, BIO_CLONED) && bip->bip_buf != NULL)
+               kfree(bip->bip_buf);
+
+       mempool_free(bip->bip_vec, bs->bvec_pools[bip->bip_pool]);
+       mempool_free(bip, bs->bio_integrity_pool);
+
+       bio->bi_integrity = NULL;
+}
+EXPORT_SYMBOL(bio_integrity_free);
+
+/**
+ * bio_integrity_add_page - Attach integrity metadata
+ * @bio:       bio to update
+ * @page:      page containing integrity metadata
+ * @len:       number of bytes of integrity metadata in page
+ * @offset:    start offset within page
+ *
+ * Description: Attach a page containing integrity metadata to bio.
+ */
+int bio_integrity_add_page(struct bio *bio, struct page *page,
+                          unsigned int len, unsigned int offset)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+       struct bio_vec *iv;
+
+       if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_pool)) {
+               printk(KERN_ERR "%s: bip_vec full\n", __func__);
+               return 0;
+       }
+
+       iv = bip_vec_idx(bip, bip->bip_vcnt);
+       BUG_ON(iv == NULL);
+       BUG_ON(iv->bv_page != NULL);
+
+       iv->bv_page = page;
+       iv->bv_len = len;
+       iv->bv_offset = offset;
+       bip->bip_vcnt++;
+
+       return len;
+}
+EXPORT_SYMBOL(bio_integrity_add_page);
+
+/**
+ * bio_integrity_enabled - Check whether integrity can be passed
+ * @bio:       bio to check
+ *
+ * Description: Determines whether bio_integrity_prep() can be called
+ * on this bio or not. bio data direction and target device must be
+ * set prior to calling.  The functions honors the write_generate and
+ * read_verify flags in sysfs.
+ */
+int bio_integrity_enabled(struct bio *bio)
+{
+       /* Already protected? */
+       if (bio_integrity(bio))
+               return 0;
+
+       return bdev_integrity_enabled(bio->bi_bdev, bio_data_dir(bio));
+}
+EXPORT_SYMBOL(bio_integrity_enabled);
+
+/**
+ * bio_integrity_hw_sectors - Convert 512b sectors to hardware ditto
+ * @bi:                blk_integrity profile for device
+ * @sectors:   Number of 512 sectors to convert
+ *
+ * Description: The block layer calculates everything in 512 byte
+ * sectors but integrity metadata is done in terms of the hardware
+ * sector size of the storage device.  Convert the block layer sectors
+ * to physical sectors.
+ */
+static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
+                                                   unsigned int sectors)
+{
+       /* At this point there are only 512b or 4096b DIF/EPP devices */
+       if (bi->sector_size == 4096)
+               return sectors >>= 3;
+
+       return sectors;
+}
+
+/**
+ * bio_integrity_tag_size - Retrieve integrity tag space
+ * @bio:       bio to inspect
+ *
+ * Description: Returns the maximum number of tag bytes that can be
+ * attached to this bio. Filesystems can use this to determine how
+ * much metadata to attach to an I/O.
+ */
+unsigned int bio_integrity_tag_size(struct bio *bio)
+{
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+
+       BUG_ON(bio->bi_size == 0);
+
+       return bi->tag_size * (bio->bi_size / bi->sector_size);
+}
+EXPORT_SYMBOL(bio_integrity_tag_size);
+
+int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len, int set)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+       unsigned int nr_sectors;
+
+       BUG_ON(bip->bip_buf == NULL);
+
+       if (bi->tag_size == 0)
+               return -1;
+
+       nr_sectors = bio_integrity_hw_sectors(bi,
+                                       DIV_ROUND_UP(len, bi->tag_size));
+
+       if (nr_sectors * bi->tuple_size > bip->bip_size) {
+               printk(KERN_ERR "%s: tag too big for bio: %u > %u\n",
+                      __func__, nr_sectors * bi->tuple_size, bip->bip_size);
+               return -1;
+       }
+
+       if (set)
+               bi->set_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
+       else
+               bi->get_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
+
+       return 0;
+}
+
+/**
+ * bio_integrity_set_tag - Attach a tag buffer to a bio
+ * @bio:       bio to attach buffer to
+ * @tag_buf:   Pointer to a buffer containing tag data
+ * @len:       Length of the included buffer
+ *
+ * Description: Use this function to tag a bio by leveraging the extra
+ * space provided by devices formatted with integrity protection.  The
+ * size of the integrity buffer must be <= to the size reported by
+ * bio_integrity_tag_size().
+ */
+int bio_integrity_set_tag(struct bio *bio, void *tag_buf, unsigned int len)
+{
+       BUG_ON(bio_data_dir(bio) != WRITE);
+
+       return bio_integrity_tag(bio, tag_buf, len, 1);
+}
+EXPORT_SYMBOL(bio_integrity_set_tag);
+
+/**
+ * bio_integrity_get_tag - Retrieve a tag buffer from a bio
+ * @bio:       bio to retrieve buffer from
+ * @tag_buf:   Pointer to a buffer for the tag data
+ * @len:       Length of the target buffer
+ *
+ * Description: Use this function to retrieve the tag buffer from a
+ * completed I/O. The size of the integrity buffer must be <= to the
+ * size reported by bio_integrity_tag_size().
+ */
+int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
+{
+       BUG_ON(bio_data_dir(bio) != READ);
+
+       return bio_integrity_tag(bio, tag_buf, len, 0);
+}
+EXPORT_SYMBOL(bio_integrity_get_tag);
+
+/**
+ * bio_integrity_generate - Generate integrity metadata for a bio
+ * @bio:       bio to generate integrity metadata for
+ *
+ * Description: Generates integrity metadata for a bio by calling the
+ * block device's generation callback function.  The bio must have a
+ * bip attached with enough room to accommodate the generated
+ * integrity metadata.
+ */
+static void bio_integrity_generate(struct bio *bio)
+{
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+       struct blk_integrity_exchg bix;
+       struct bio_vec *bv;
+       sector_t sector = bio->bi_sector;
+       unsigned int i, sectors, total;
+       void *prot_buf = bio->bi_integrity->bip_buf;
+
+       total = 0;
+       bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
+       bix.sector_size = bi->sector_size;
+
+       bio_for_each_segment(bv, bio, i) {
+               void *kaddr = kmap_atomic(bv->bv_page, KM_USER0);
+               bix.data_buf = kaddr + bv->bv_offset;
+               bix.data_size = bv->bv_len;
+               bix.prot_buf = prot_buf;
+               bix.sector = sector;
+
+               bi->generate_fn(&bix);
+
+               sectors = bv->bv_len / bi->sector_size;
+               sector += sectors;
+               prot_buf += sectors * bi->tuple_size;
+               total += sectors * bi->tuple_size;
+               BUG_ON(total > bio->bi_integrity->bip_size);
+
+               kunmap_atomic(kaddr, KM_USER0);
+       }
+}
+
+/**
+ * bio_integrity_prep - Prepare bio for integrity I/O
+ * @bio:       bio to prepare
+ *
+ * Description: Allocates a buffer for integrity metadata, maps the
+ * pages and attaches them to a bio.  The bio must have data
+ * direction, target device and start sector set priot to calling.  In
+ * the WRITE case, integrity metadata will be generated using the
+ * block device's integrity function.  In the READ case, the buffer
+ * will be prepared for DMA and a suitable end_io handler set up.
+ */
+int bio_integrity_prep(struct bio *bio)
+{
+       struct bio_integrity_payload *bip;
+       struct blk_integrity *bi;
+       struct request_queue *q;
+       void *buf;
+       unsigned long start, end;
+       unsigned int len, nr_pages;
+       unsigned int bytes, offset, i;
+       unsigned int sectors;
+
+       bi = bdev_get_integrity(bio->bi_bdev);
+       q = bdev_get_queue(bio->bi_bdev);
+       BUG_ON(bi == NULL);
+       BUG_ON(bio_integrity(bio));
+
+       sectors = bio_integrity_hw_sectors(bi, bio_sectors(bio));
+
+       /* Allocate kernel buffer for protection data */
+       len = sectors * blk_integrity_tuple_size(bi);
+       buf = kmalloc(len, GFP_NOIO | __GFP_NOFAIL | q->bounce_gfp);
+       if (unlikely(buf == NULL)) {
+               printk(KERN_ERR "could not allocate integrity buffer\n");
+               return -EIO;
+       }
+
+       end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       start = ((unsigned long) buf) >> PAGE_SHIFT;
+       nr_pages = end - start;
+
+       /* Allocate bio integrity payload and integrity vectors */
+       bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
+       if (unlikely(bip == NULL)) {
+               printk(KERN_ERR "could not allocate data integrity bioset\n");
+               kfree(buf);
+               return -EIO;
+       }
+
+       bip->bip_buf = buf;
+       bip->bip_size = len;
+       bip->bip_sector = bio->bi_sector;
+
+       /* Map it */
+       offset = offset_in_page(buf);
+       for (i = 0 ; i < nr_pages ; i++) {
+               int ret;
+               bytes = PAGE_SIZE - offset;
+
+               if (len <= 0)
+                       break;
+
+               if (bytes > len)
+                       bytes = len;
+
+               ret = bio_integrity_add_page(bio, virt_to_page(buf),
+                                            bytes, offset);
+
+               if (ret == 0)
+                       return 0;
+
+               if (ret < bytes)
+                       break;
+
+               buf += bytes;
+               len -= bytes;
+               offset = 0;
+       }
+
+       /* Install custom I/O completion handler if read verify is enabled */
+       if (bio_data_dir(bio) == READ) {
+               bip->bip_end_io = bio->bi_end_io;
+               bio->bi_end_io = bio_integrity_endio;
+       }
+
+       /* Auto-generate integrity metadata if this is a write */
+       if (bio_data_dir(bio) == WRITE)
+               bio_integrity_generate(bio);
+
+       return 0;
+}
+EXPORT_SYMBOL(bio_integrity_prep);
+
+/**
+ * bio_integrity_verify - Verify integrity metadata for a bio
+ * @bio:       bio to verify
+ *
+ * Description: This function is called to verify the integrity of a
+ * bio.         The data in the bio io_vec is compared to the integrity
+ * metadata returned by the HBA.
+ */
+static int bio_integrity_verify(struct bio *bio)
+{
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+       struct blk_integrity_exchg bix;
+       struct bio_vec *bv;
+       sector_t sector = bio->bi_integrity->bip_sector;
+       unsigned int i, sectors, total, ret;
+       void *prot_buf = bio->bi_integrity->bip_buf;
+
+       ret = total = 0;
+       bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
+       bix.sector_size = bi->sector_size;
+
+       bio_for_each_segment(bv, bio, i) {
+               void *kaddr = kmap_atomic(bv->bv_page, KM_USER0);
+               bix.data_buf = kaddr + bv->bv_offset;
+               bix.data_size = bv->bv_len;
+               bix.prot_buf = prot_buf;
+               bix.sector = sector;
+
+               ret = bi->verify_fn(&bix);
+
+               if (ret) {
+                       kunmap_atomic(kaddr, KM_USER0);
+                       break;
+               }
+
+               sectors = bv->bv_len / bi->sector_size;
+               sector += sectors;
+               prot_buf += sectors * bi->tuple_size;
+               total += sectors * bi->tuple_size;
+               BUG_ON(total > bio->bi_integrity->bip_size);
+
+               kunmap_atomic(kaddr, KM_USER0);
+       }
+
+       return ret;
+}
+
+/**
+ * bio_integrity_verify_fn - Integrity I/O completion worker
+ * @work:      Work struct stored in bio to be verified
+ *
+ * Description: This workqueue function is called to complete a READ
+ * request.  The function verifies the transferred integrity metadata
+ * and then calls the original bio end_io function.
+ */
+static void bio_integrity_verify_fn(struct work_struct *work)
+{
+       struct bio_integrity_payload *bip =
+               container_of(work, struct bio_integrity_payload, bip_work);
+       struct bio *bio = bip->bip_bio;
+       int error = bip->bip_error;
+
+       if (bio_integrity_verify(bio)) {
+               clear_bit(BIO_UPTODATE, &bio->bi_flags);
+               error = -EIO;
+       }
+
+       /* Restore original bio completion handler */
+       bio->bi_end_io = bip->bip_end_io;
+
+       if (bio->bi_end_io)
+               bio->bi_end_io(bio, error);
+}
+
+/**
+ * bio_integrity_endio - Integrity I/O completion function
+ * @bio:       Protected bio
+ * @error:     Pointer to errno
+ *
+ * Description: Completion for integrity I/O
+ *
+ * Normally I/O completion is done in interrupt context.  However,
+ * verifying I/O integrity is a time-consuming task which must be run
+ * in process context. This function postpones completion
+ * accordingly.
+ */
+void bio_integrity_endio(struct bio *bio, int error)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+
+       BUG_ON(bip->bip_bio != bio);
+
+       bip->bip_error = error;
+       INIT_WORK(&bip->bip_work, bio_integrity_verify_fn);
+       queue_work(kintegrityd_wq, &bip->bip_work);
+}
+EXPORT_SYMBOL(bio_integrity_endio);
+
+/**
+ * bio_integrity_mark_head - Advance bip_vec skip bytes
+ * @bip:       Integrity vector to advance
+ * @skip:      Number of bytes to advance it
+ */
+void bio_integrity_mark_head(struct bio_integrity_payload *bip,
+                            unsigned int skip)
+{
+       struct bio_vec *iv;
+       unsigned int i;
+
+       bip_for_each_vec(iv, bip, i) {
+               if (skip == 0) {
+                       bip->bip_idx = i;
+                       return;
+               } else if (skip >= iv->bv_len) {
+                       skip -= iv->bv_len;
+               } else { /* skip < iv->bv_len) */
+                       iv->bv_offset += skip;
+                       iv->bv_len -= skip;
+                       bip->bip_idx = i;
+                       return;
+               }
+       }
+}
+
+/**
+ * bio_integrity_mark_tail - Truncate bip_vec to be len bytes long
+ * @bip:       Integrity vector to truncate
+ * @len:       New length of integrity vector
+ */
+void bio_integrity_mark_tail(struct bio_integrity_payload *bip,
+                            unsigned int len)
+{
+       struct bio_vec *iv;
+       unsigned int i;
+
+       bip_for_each_vec(iv, bip, i) {
+               if (len == 0) {
+                       bip->bip_vcnt = i;
+                       return;
+               } else if (len >= iv->bv_len) {
+                       len -= iv->bv_len;
+               } else { /* len < iv->bv_len) */
+                       iv->bv_len = len;
+                       len = 0;
+               }
+       }
+}
+
+/**
+ * bio_integrity_advance - Advance integrity vector
+ * @bio:       bio whose integrity vector to update
+ * @bytes_done:        number of data bytes that have been completed
+ *
+ * Description: This function calculates how many integrity bytes the
+ * number of completed data bytes correspond to and advances the
+ * integrity vector accordingly.
+ */
+void bio_integrity_advance(struct bio *bio, unsigned int bytes_done)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+       unsigned int nr_sectors;
+
+       BUG_ON(bip == NULL);
+       BUG_ON(bi == NULL);
+
+       nr_sectors = bio_integrity_hw_sectors(bi, bytes_done >> 9);
+       bio_integrity_mark_head(bip, nr_sectors * bi->tuple_size);
+}
+EXPORT_SYMBOL(bio_integrity_advance);
+
+/**
+ * bio_integrity_trim - Trim integrity vector
+ * @bio:       bio whose integrity vector to update
+ * @offset:    offset to first data sector
+ * @sectors:   number of data sectors
+ *
+ * Description: Used to trim the integrity vector in a cloned bio.
+ * The ivec will be advanced corresponding to 'offset' data sectors
+ * and the length will be truncated corresponding to 'len' data
+ * sectors.
+ */
+void bio_integrity_trim(struct bio *bio, unsigned int offset,
+                       unsigned int sectors)
+{
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+       struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
+       unsigned int nr_sectors;
+
+       BUG_ON(bip == NULL);
+       BUG_ON(bi == NULL);
+       BUG_ON(!bio_flagged(bio, BIO_CLONED));
+
+       nr_sectors = bio_integrity_hw_sectors(bi, sectors);
+       bip->bip_sector = bip->bip_sector + offset;
+       bio_integrity_mark_head(bip, offset * bi->tuple_size);
+       bio_integrity_mark_tail(bip, sectors * bi->tuple_size);
+}
+EXPORT_SYMBOL(bio_integrity_trim);
+
+/**
+ * bio_integrity_split - Split integrity metadata
+ * @bio:       Protected bio
+ * @bp:                Resulting bio_pair
+ * @sectors:   Offset
+ *
+ * Description: Splits an integrity page into a bio_pair.
+ */
+void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
+{
+       struct blk_integrity *bi;
+       struct bio_integrity_payload *bip = bio->bi_integrity;
+       unsigned int nr_sectors;
+
+       if (bio_integrity(bio) == 0)
+               return;
+
+       bi = bdev_get_integrity(bio->bi_bdev);
+       BUG_ON(bi == NULL);
+       BUG_ON(bip->bip_vcnt != 1);
+
+       nr_sectors = bio_integrity_hw_sectors(bi, sectors);
+
+       bp->bio1.bi_integrity = &bp->bip1;
+       bp->bio2.bi_integrity = &bp->bip2;
+
+       bp->iv1 = bip->bip_vec[0];
+       bp->iv2 = bip->bip_vec[0];
+
+       bp->bip1.bip_vec = &bp->iv1;
+       bp->bip2.bip_vec = &bp->iv2;
+
+       bp->iv1.bv_len = sectors * bi->tuple_size;
+       bp->iv2.bv_offset += sectors * bi->tuple_size;
+       bp->iv2.bv_len -= sectors * bi->tuple_size;
+
+       bp->bip1.bip_sector = bio->bi_integrity->bip_sector;
+       bp->bip2.bip_sector = bio->bi_integrity->bip_sector + nr_sectors;
+
+       bp->bip1.bip_vcnt = bp->bip2.bip_vcnt = 1;
+       bp->bip1.bip_idx = bp->bip2.bip_idx = 0;
+}
+EXPORT_SYMBOL(bio_integrity_split);
+
+/**
+ * bio_integrity_clone - Callback for cloning bios with integrity metadata
+ * @bio:       New bio
+ * @bio_src:   Original bio
+ * @bs:                bio_set to allocate bip from
+ *
+ * Description:        Called to allocate a bip when cloning a bio
+ */
+int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
+                       struct bio_set *bs)
+{
+       struct bio_integrity_payload *bip_src = bio_src->bi_integrity;
+       struct bio_integrity_payload *bip;
+
+       BUG_ON(bip_src == NULL);
+
+       bip = bio_integrity_alloc_bioset(bio, GFP_NOIO, bip_src->bip_vcnt, bs);
+
+       if (bip == NULL)
+               return -EIO;
+
+       memcpy(bip->bip_vec, bip_src->bip_vec,
+              bip_src->bip_vcnt * sizeof(struct bio_vec));
+
+       bip->bip_sector = bip_src->bip_sector;
+       bip->bip_vcnt = bip_src->bip_vcnt;
+       bip->bip_idx = bip_src->bip_idx;
+
+       return 0;
+}
+EXPORT_SYMBOL(bio_integrity_clone);
+
+int bioset_integrity_create(struct bio_set *bs, int pool_size)
+{
+       bs->bio_integrity_pool = mempool_create_slab_pool(pool_size,
+                                                         bio_integrity_slab);
+       if (!bs->bio_integrity_pool)
+               return -1;
+
+       return 0;
+}
+EXPORT_SYMBOL(bioset_integrity_create);
+
+void bioset_integrity_free(struct bio_set *bs)
+{
+       if (bs->bio_integrity_pool)
+               mempool_destroy(bs->bio_integrity_pool);
+}
+EXPORT_SYMBOL(bioset_integrity_free);
+
+void __init bio_integrity_init_slab(void)
+{
+       bio_integrity_slab = KMEM_CACHE(bio_integrity_payload,
+                                       SLAB_HWCACHE_ALIGN|SLAB_PANIC);
+}
+EXPORT_SYMBOL(bio_integrity_init_slab);
+
+static int __init integrity_init(void)
+{
+       kintegrityd_wq = create_workqueue("kintegrityd");
+
+       if (!kintegrityd_wq)
+               panic("Failed to create kintegrityd\n");
+
+       return 0;
+}
+subsys_initcall(integrity_init);
index 7856257..88322b0 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
 #include <linux/blktrace_api.h>
 #include <scsi/sg.h>           /* for struct sg_iovec */
 
-#define BIO_POOL_SIZE 2
-
 static struct kmem_cache *bio_slab __read_mostly;
 
-#define BIOVEC_NR_POOLS 6
-
-/*
- * a small number of entries is fine, not going to be performance critical.
- * basically we just need to survive
- */
-#define BIO_SPLIT_ENTRIES 2
 mempool_t *bio_split_pool __read_mostly;
 
-struct biovec_slab {
-       int nr_vecs;
-       char *name; 
-       struct kmem_cache *slab;
-};
-
 /*
  * if you change this list, also change bvec_alloc or things will
  * break badly! cannot be bigger than what you can fit into an
@@ -59,24 +44,18 @@ static struct biovec_slab bvec_slabs[BIOVEC_NR_POOLS] __read_mostly = {
 };
 #undef BV
 
-/*
- * bio_set is used to allow other portions of the IO system to
- * allocate their own private memory pools for bio and iovec structures.
- * These memory pools in turn all allocate from the bio_slab
- * and the bvec_slabs[].
- */
-struct bio_set {
-       mempool_t *bio_pool;
-       mempool_t *bvec_pools[BIOVEC_NR_POOLS];
-};
-
 /*
  * fs_bio_set is the bio_set containing bio and iovec memory pools used by
  * IO code that does not need private memory pools.
  */
-static struct bio_set *fs_bio_set;
+struct bio_set *fs_bio_set;
+
+unsigned int bvec_nr_vecs(unsigned short idx)
+{
+       return bvec_slabs[idx].nr_vecs;
+}
 
-static inline struct bio_vec *bvec_alloc_bs(gfp_t gfp_mask, int nr, unsigned long *idx, struct bio_set *bs)
+struct bio_vec *bvec_alloc_bs(gfp_t gfp_mask, int nr, unsigned long *idx, struct bio_set *bs)
 {
        struct bio_vec *bvl;
 
@@ -117,6 +96,9 @@ void bio_free(struct bio *bio, struct bio_set *bio_set)
                mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]);
        }
 
+       if (bio_integrity(bio))
+               bio_integrity_free(bio, bio_set);
+
        mempool_free(bio, bio_set->bio_pool);
 }
 
@@ -275,9 +257,19 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
 {
        struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set);
 
-       if (b) {
-               b->bi_destructor = bio_fs_destructor;
-               __bio_clone(b, bio);
+       if (!b)
+               return NULL;
+
+       b->bi_destructor = bio_fs_destructor;
+       __bio_clone(b, bio);
+
+       if (bio_integrity(bio)) {
+               int ret;
+
+               ret = bio_integrity_clone(b, bio, fs_bio_set);
+
+               if (ret < 0)
+                       return NULL;
        }
 
        return b;
@@ -333,10 +325,19 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
                if (page == prev->bv_page &&
                    offset == prev->bv_offset + prev->bv_len) {
                        prev->bv_len += len;
-                       if (q->merge_bvec_fn &&
-                           q->merge_bvec_fn(q, bio, prev) < len) {
-                               prev->bv_len -= len;
-                               return 0;
+
+                       if (q->merge_bvec_fn) {
+                               struct bvec_merge_data bvm = {
+                                       .bi_bdev = bio->bi_bdev,
+                                       .bi_sector = bio->bi_sector,
+                                       .bi_size = bio->bi_size,
+                                       .bi_rw = bio->bi_rw,
+                               };
+
+                               if (q->merge_bvec_fn(q, &bvm, prev) < len) {
+                                       prev->bv_len -= len;
+                                       return 0;
+                               }
                        }
 
                        goto done;
@@ -377,11 +378,18 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
         * queue to get further control
         */
        if (q->merge_bvec_fn) {
+               struct bvec_merge_data bvm = {
+                       .bi_bdev = bio->bi_bdev,
+                       .bi_sector = bio->bi_sector,
+                       .bi_size = bio->bi_size,
+                       .bi_rw = bio->bi_rw,
+               };
+
                /*
                 * merge_bvec_fn() returns number of bytes it can accept
                 * at this offset
                 */
-               if (q->merge_bvec_fn(q, bio, bvec) < len) {
+               if (q->merge_bvec_fn(q, &bvm, bvec) < len) {
                        bvec->bv_page = NULL;
                        bvec->bv_len = 0;
                        bvec->bv_offset = 0;
@@ -1249,6 +1257,9 @@ struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)
        bp->bio1.bi_private = bi;
        bp->bio2.bi_private = pool;
 
+       if (bio_integrity(bi))
+               bio_integrity_split(bi, bp, first_sectors);
+
        return bp;
 }
 
@@ -1290,6 +1301,7 @@ void bioset_free(struct bio_set *bs)
        if (bs->bio_pool)
                mempool_destroy(bs->bio_pool);
 
+       bioset_integrity_free(bs);
        biovec_free_pools(bs);
 
        kfree(bs);
@@ -1306,6 +1318,9 @@ struct bio_set *bioset_create(int bio_pool_size, int bvec_pool_size)
        if (!bs->bio_pool)
                goto bad;
 
+       if (bioset_integrity_create(bs, bio_pool_size))
+               goto bad;
+
        if (!biovec_create_pools(bs, bvec_pool_size))
                return bs;
 
@@ -1332,6 +1347,7 @@ static int __init init_bio(void)
 {
        bio_slab = KMEM_CACHE(bio, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
 
+       bio_integrity_init_slab();
        biovec_init_slabs();
 
        fs_bio_set = bioset_create(BIO_POOL_SIZE, 2);
index 68e510b..3cb7cda 100644 (file)
@@ -373,6 +373,8 @@ static int chrdev_open(struct inode *inode, struct file *filp)
                        return -ENXIO;
                new = container_of(kobj, struct cdev, kobj);
                spin_lock(&cdev_lock);
+               /* Check i_cdev again in case somebody beat us to it while
+                  we dropped the lock. */
                p = inode->i_cdev;
                if (!p) {
                        inode->i_cdev = p = new;
@@ -392,11 +394,8 @@ static int chrdev_open(struct inode *inode, struct file *filp)
                cdev_put(p);
                return -ENXIO;
        }
-       if (filp->f_op->open) {
-               lock_kernel();
+       if (filp->f_op->open)
                ret = filp->f_op->open(inode,filp);
-               unlock_kernel();
-       }
        if (ret)
                cdev_put(p);
        return ret;
index 86b4d5f..22857c6 100644 (file)
@@ -612,7 +612,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
                if (retval < 0)
                        return (loff_t)retval;
        }
-       return remote_llseek(file, offset, origin);
+       return generic_file_llseek_unlocked(file, offset, origin);
 }
 
 struct file_system_type cifs_fs_type = {
index ebbcf38..f976f30 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/poll.h>
 #include <linux/signal.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/dlm.h>
 #include <linux/dlm_device.h>
 
@@ -618,13 +619,17 @@ static int device_open(struct inode *inode, struct file *file)
        struct dlm_user_proc *proc;
        struct dlm_ls *ls;
 
+       lock_kernel();
        ls = dlm_find_lockspace_device(iminor(inode));
-       if (!ls)
+       if (!ls) {
+               unlock_kernel();
                return -ENOENT;
+       }
 
        proc = kzalloc(sizeof(struct dlm_user_proc), GFP_KERNEL);
        if (!proc) {
                dlm_put_lockspace(ls);
+               unlock_kernel();
                return -ENOMEM;
        }
 
@@ -636,6 +641,7 @@ static int device_open(struct inode *inode, struct file *file)
        spin_lock_init(&proc->locks_spin);
        init_waitqueue_head(&proc->wait);
        file->private_data = proc;
+       unlock_kernel();
 
        return 0;
 }
@@ -870,6 +876,7 @@ static unsigned int device_poll(struct file *file, poll_table *wait)
 
 static int ctl_device_open(struct inode *inode, struct file *file)
 {
+       cycle_kernel_lock();
        file->private_data = NULL;
        return 0;
 }
index 2258b8f..24749bf 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/security.h>
 #include <linux/compat.h>
 #include <linux/fs_stack.h>
+#include <linux/smp_lock.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -277,9 +278,11 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
        int rc = 0;
        struct file *lower_file = NULL;
 
+       lock_kernel();
        lower_file = ecryptfs_file_to_lower(file);
        if (lower_file->f_op && lower_file->f_op->fasync)
                rc = lower_file->f_op->fasync(fd, lower_file, flag);
+       unlock_kernel();
        return rc;
 }
 
index fda2547..3a9ecac 100644 (file)
@@ -61,7 +61,7 @@ void fat_cache_destroy(void)
 
 static inline struct fat_cache *fat_cache_alloc(struct inode *inode)
 {
-       return kmem_cache_alloc(fat_cache_cachep, GFP_KERNEL);
+       return kmem_cache_alloc(fat_cache_cachep, GFP_NOFS);
 }
 
 static inline void fat_cache_free(struct fat_cache *cache)
index 486725e..34541d0 100644 (file)
@@ -472,7 +472,7 @@ static int __fat_readdir(struct inode *inode, struct file *filp, void *dirent,
        loff_t cpos;
        int ret = 0;
 
-       lock_kernel();
+       lock_super(sb);
 
        cpos = filp->f_pos;
        /* Fake . and .. for the root directory. */
@@ -654,7 +654,7 @@ FillFailed:
        if (unicode)
                __putname(unicode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        return ret;
 }
 
index 771326b..c672df4 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/mount.h>
 #include <linux/time.h>
 #include <linux/msdos_fs.h>
-#include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
 #include <linux/writeback.h>
 #include <linux/backing-dev.h>
@@ -242,9 +241,7 @@ void fat_truncate(struct inode *inode)
 
        nr_clusters = (inode->i_size + (cluster_size - 1)) >> sbi->cluster_bits;
 
-       lock_kernel();
        fat_free(inode, nr_clusters);
-       unlock_kernel();
        fat_flush_inodes(inode->i_sb, inode, NULL);
 }
 
@@ -310,8 +307,6 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
        int error = 0;
        unsigned int ia_valid;
 
-       lock_kernel();
-
        /*
         * Expand the file. Since inode_setattr() updates ->i_size
         * before calling the ->truncate(), but FAT needs to fill the
@@ -366,7 +361,6 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)
 
        error = inode_setattr(inode, attr);
 out:
-       unlock_kernel();
        return error;
 }
 EXPORT_SYMBOL_GPL(fat_setattr);
index 4e0a3dd..46a4508 100644 (file)
@@ -440,14 +440,13 @@ static void fat_delete_inode(struct inode *inode)
 
 static void fat_clear_inode(struct inode *inode)
 {
-       struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+       struct super_block *sb = inode->i_sb;
+       struct msdos_sb_info *sbi = MSDOS_SB(sb);
 
-       lock_kernel();
        spin_lock(&sbi->inode_hash_lock);
        fat_cache_inval_inode(inode);
        hlist_del_init(&MSDOS_I(inode)->i_fat_hash);
        spin_unlock(&sbi->inode_hash_lock);
-       unlock_kernel();
 }
 
 static void fat_write_super(struct super_block *sb)
@@ -485,7 +484,7 @@ static struct kmem_cache *fat_inode_cachep;
 static struct inode *fat_alloc_inode(struct super_block *sb)
 {
        struct msdos_inode_info *ei;
-       ei = kmem_cache_alloc(fat_inode_cachep, GFP_KERNEL);
+       ei = kmem_cache_alloc(fat_inode_cachep, GFP_NOFS);
        if (!ei)
                return NULL;
        return &ei->vfs_inode;
@@ -567,7 +566,7 @@ retry:
        if (inode->i_ino == MSDOS_ROOT_INO || !i_pos)
                return 0;
 
-       lock_kernel();
+       lock_super(sb);
        bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits);
        if (!bh) {
                printk(KERN_ERR "FAT: unable to read inode block "
@@ -579,7 +578,7 @@ retry:
        if (i_pos != MSDOS_I(inode)->i_pos) {
                spin_unlock(&sbi->inode_hash_lock);
                brelse(bh);
-               unlock_kernel();
+               unlock_super(sb);
                goto retry;
        }
 
@@ -606,7 +605,7 @@ retry:
                err = sync_dirty_buffer(bh);
        brelse(bh);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        return err;
 }
 
@@ -736,6 +735,7 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
 
 static struct dentry *fat_get_parent(struct dentry *child)
 {
+       struct super_block *sb = child->d_sb;
        struct buffer_head *bh;
        struct msdos_dir_entry *de;
        loff_t i_pos;
@@ -743,14 +743,14 @@ static struct dentry *fat_get_parent(struct dentry *child)
        struct inode *inode;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = fat_get_dotdot_entry(child->d_inode, &bh, &de, &i_pos);
        if (err) {
                parent = ERR_PTR(err);
                goto out;
        }
-       inode = fat_build_inode(child->d_sb, de, i_pos);
+       inode = fat_build_inode(sb, de, i_pos);
        brelse(bh);
        if (IS_ERR(inode)) {
                parent = ERR_CAST(inode);
@@ -762,7 +762,7 @@ static struct dentry *fat_get_parent(struct dentry *child)
                parent = ERR_PTR(-ENOMEM);
        }
 out:
-       unlock_kernel();
+       unlock_super(sb);
 
        return parent;
 }
@@ -1172,6 +1172,12 @@ int fat_fill_super(struct super_block *sb, void *data, int silent,
        long error;
        char buf[50];
 
+       /*
+        * GFP_KERNEL is ok here, because while we do hold the
+        * supeblock lock, memory pressure can't call back into
+        * the filesystem, since we're only just about to mount
+        * it and have no inodes etc active!
+        */
        sbi = kzalloc(sizeof(struct msdos_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
index bfd7765..330a7d7 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/fdtable.h>
 #include <linux/capability.h>
 #include <linux/dnotify.h>
-#include <linux/smp_lock.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/security.h>
@@ -227,7 +226,6 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
        if (error)
                return error;
 
-       lock_kernel();
        if ((arg ^ filp->f_flags) & FASYNC) {
                if (filp->f_op && filp->f_op->fasync) {
                        error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
@@ -238,7 +236,6 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
 
        filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
  out:
-       unlock_kernel();
        return error;
 }
 
index e1b7d52..24dd594 100644 (file)
@@ -62,11 +62,11 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin)
                error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
                                           &i_gh);
                if (!error) {
-                       error = remote_llseek(file, offset, origin);
+                       error = generic_file_llseek_unlocked(file, offset, origin);
                        gfs2_glock_dq_uninit(&i_gh);
                }
        } else
-               error = remote_llseek(file, offset, origin);
+               error = generic_file_llseek_unlocked(file, offset, origin);
 
        return error;
 }
index 05ff4f1..1f7f295 100644 (file)
@@ -214,7 +214,7 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
 
        dentry->d_op = &msdos_dentry_operations;
 
-       lock_kernel();
+       lock_super(sb);
        res = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
        if (res == -ENOENT)
                goto add;
@@ -232,7 +232,7 @@ add:
        if (dentry)
                dentry->d_op = &msdos_dentry_operations;
 out:
-       unlock_kernel();
+       unlock_super(sb);
        if (!res)
                return dentry;
        return ERR_PTR(res);
@@ -286,7 +286,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, int mode,
        unsigned char msdos_name[MSDOS_NAME];
        int err, is_hid;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
                                msdos_name, &MSDOS_SB(sb)->options);
@@ -315,7 +315,7 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, int mode,
 
        d_instantiate(dentry, inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        if (!err)
                err = fat_flush_inodes(sb, dir, inode);
        return err;
@@ -324,11 +324,12 @@ out:
 /***** Remove a directory */
 static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
 {
+       struct super_block *sb = dir->i_sb;
        struct inode *inode = dentry->d_inode;
        struct fat_slot_info sinfo;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
        /*
         * Check whether the directory is not in use, then check
         * whether it is empty.
@@ -349,9 +350,9 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
        inode->i_ctime = CURRENT_TIME_SEC;
        fat_detach(inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        if (!err)
-               err = fat_flush_inodes(inode->i_sb, dir, inode);
+               err = fat_flush_inodes(sb, dir, inode);
 
        return err;
 }
@@ -366,7 +367,7 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        struct timespec ts;
        int err, is_hid, cluster;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
                                msdos_name, &MSDOS_SB(sb)->options);
@@ -404,14 +405,14 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 
        d_instantiate(dentry, inode);
 
-       unlock_kernel();
+       unlock_super(sb);
        fat_flush_inodes(sb, dir, inode);
        return 0;
 
 out_free:
        fat_free_clusters(dir, cluster);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        return err;
 }
 
@@ -419,10 +420,11 @@ out:
 static int msdos_unlink(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = dentry->d_inode;
+       struct super_block *sb= inode->i_sb;
        struct fat_slot_info sinfo;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
        err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
        if (err)
                goto out;
@@ -434,9 +436,9 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry)
        inode->i_ctime = CURRENT_TIME_SEC;
        fat_detach(inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        if (!err)
-               err = fat_flush_inodes(inode->i_sb, dir, inode);
+               err = fat_flush_inodes(sb, dir, inode);
 
        return err;
 }
@@ -618,10 +620,11 @@ error_inode:
 static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
                        struct inode *new_dir, struct dentry *new_dentry)
 {
+       struct super_block *sb = old_dir->i_sb;
        unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
        int err, is_hid;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = msdos_format_name(old_dentry->d_name.name,
                                old_dentry->d_name.len, old_msdos_name,
@@ -640,9 +643,9 @@ static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
        err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
                              new_dir, new_msdos_name, new_dentry, is_hid);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        if (!err)
-               err = fat_flush_inodes(old_dir->i_sb, old_dir, new_dir);
+               err = fat_flush_inodes(sb, old_dir, new_dir);
        return err;
 }
 
index 4fc302c..4f6f763 100644 (file)
@@ -750,7 +750,7 @@ struct proc_fs_info {
        const char *str;
 };
 
-static void show_sb_opts(struct seq_file *m, struct super_block *sb)
+static int show_sb_opts(struct seq_file *m, struct super_block *sb)
 {
        static const struct proc_fs_info fs_info[] = {
                { MS_SYNCHRONOUS, ",sync" },
@@ -764,6 +764,8 @@ static void show_sb_opts(struct seq_file *m, struct super_block *sb)
                if (sb->s_flags & fs_infop->flag)
                        seq_puts(m, fs_infop->str);
        }
+
+       return security_sb_show_options(m, sb);
 }
 
 static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
@@ -806,11 +808,14 @@ static int show_vfsmnt(struct seq_file *m, void *v)
        seq_putc(m, ' ');
        show_type(m, mnt->mnt_sb);
        seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
-       show_sb_opts(m, mnt->mnt_sb);
+       err = show_sb_opts(m, mnt->mnt_sb);
+       if (err)
+               goto out;
        show_mnt_opts(m, mnt);
        if (mnt->mnt_sb->s_op->show_options)
                err = mnt->mnt_sb->s_op->show_options(m, mnt);
        seq_puts(m, " 0 0\n");
+out:
        return err;
 }
 
@@ -865,10 +870,13 @@ static int show_mountinfo(struct seq_file *m, void *v)
        seq_putc(m, ' ');
        mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
        seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
-       show_sb_opts(m, sb);
+       err = show_sb_opts(m, sb);
+       if (err)
+               goto out;
        if (sb->s_op->show_options)
                err = sb->s_op->show_options(m, mnt);
        seq_putc(m, '\n');
+out:
        return err;
 }
 
index 2b145de..6a7d901 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 
 #include <linux/ncp_fs.h>
 #include "ncplib_kernel.h"
@@ -281,9 +282,18 @@ static int ncp_release(struct inode *inode, struct file *file) {
        return 0;
 }
 
+static loff_t ncp_remote_llseek(struct file *file, loff_t offset, int origin)
+{
+       loff_t ret;
+       lock_kernel();
+       ret = generic_file_llseek_unlocked(file, offset, origin);
+       unlock_kernel();
+       return ret;
+}
+
 const struct file_operations ncp_file_operations =
 {
-       .llseek         = remote_llseek,
+       .llseek         = ncp_remote_llseek,
        .read           = ncp_file_read,
        .write          = ncp_file_write,
        .ioctl          = ncp_ioctl,
index d84a3d8..4e98a56 100644 (file)
@@ -170,6 +170,7 @@ force_reval:
 
 static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
 {
+       loff_t loff;
        /* origin == SEEK_END => we must revalidate the cached file length */
        if (origin == SEEK_END) {
                struct inode *inode = filp->f_mapping->host;
@@ -177,7 +178,10 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
                if (retval < 0)
                        return (loff_t)retval;
        }
-       return remote_llseek(filp, offset, origin);
+       lock_kernel();  /* BKL needed? */
+       loff = generic_file_llseek_unlocked(filp, offset, origin);
+       unlock_kernel();
+       return loff;
 }
 
 /*
index c021280..bd7e0f3 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
 #include <linux/mutex.h>
+#include <linux/smp_lock.h>
 #include <linux/reboot.h>
 #include <asm/uaccess.h>
 
@@ -619,10 +620,12 @@ static int ocfs2_control_open(struct inode *inode, struct file *file)
                return -ENOMEM;
        p->op_this_node = -1;
 
+       lock_kernel();
        mutex_lock(&ocfs2_control_lock);
        file->private_data = p;
        list_add(&p->op_list, &ocfs2_control_private_list);
        mutex_unlock(&ocfs2_control_lock);
+       unlock_kernel();
 
        return 0;
 }
index 3b45537..58c3e6a 100644 (file)
@@ -233,7 +233,7 @@ static int check_mem_permission(struct task_struct *task)
         */
        if (task->parent == current && (task->ptrace & PT_PTRACED) &&
            task_is_stopped_or_traced(task) &&
-           ptrace_may_attach(task))
+           ptrace_may_access(task, PTRACE_MODE_ATTACH))
                return 0;
 
        /*
@@ -251,7 +251,8 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
        task_lock(task);
        if (task->mm != mm)
                goto out;
-       if (task->mm != current->mm && __ptrace_may_attach(task) < 0)
+       if (task->mm != current->mm &&
+           __ptrace_may_access(task, PTRACE_MODE_READ) < 0)
                goto out;
        task_unlock(task);
        return mm;
@@ -518,7 +519,7 @@ static int proc_fd_access_allowed(struct inode *inode)
         */
        task = get_proc_task(inode);
        if (task) {
-               allowed = ptrace_may_attach(task);
+               allowed = ptrace_may_access(task, PTRACE_MODE_READ);
                put_task_struct(task);
        }
        return allowed;
@@ -904,7 +905,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
        if (!task)
                goto out_no_task;
 
-       if (!ptrace_may_attach(task))
+       if (!ptrace_may_access(task, PTRACE_MODE_READ))
                goto out;
 
        ret = -ENOMEM;
index 7e277f2..c652d46 100644 (file)
@@ -123,6 +123,11 @@ static int uptime_read_proc(char *page, char **start, off_t off,
        return proc_calc_metrics(page, start, off, count, eof, len);
 }
 
+int __attribute__((weak)) arch_report_meminfo(char *page)
+{
+       return 0;
+}
+
 static int meminfo_read_proc(char *page, char **start, off_t off,
                                 int count, int *eof, void *data)
 {
@@ -221,6 +226,8 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
 
                len += hugetlb_report_meminfo(page + len);
 
+       len += arch_report_meminfo(page + len);
+
        return proc_calc_metrics(page, start, off, count, eof, len);
 #undef K
 }
@@ -472,6 +479,13 @@ static const struct file_operations proc_vmalloc_operations = {
 };
 #endif
 
+#ifndef arch_irq_stat_cpu
+#define arch_irq_stat_cpu(cpu) 0
+#endif
+#ifndef arch_irq_stat
+#define arch_irq_stat() 0
+#endif
+
 static int show_stat(struct seq_file *p, void *v)
 {
        int i;
@@ -509,7 +523,9 @@ static int show_stat(struct seq_file *p, void *v)
                        sum += temp;
                        per_irq_sum[j] += temp;
                }
+               sum += arch_irq_stat_cpu(i);
        }
+       sum += arch_irq_stat();
 
        seq_printf(p, "cpu  %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
                (unsigned long long)cputime64_to_clock_t(user),
index c492449..164bd9f 100644 (file)
@@ -210,7 +210,7 @@ static int show_map(struct seq_file *m, void *v)
        dev_t dev = 0;
        int len;
 
-       if (maps_protect && !ptrace_may_attach(task))
+       if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
                return -EACCES;
 
        if (file) {
@@ -646,7 +646,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
                goto out;
 
        ret = -EACCES;
-       if (!ptrace_may_attach(task))
+       if (!ptrace_may_access(task, PTRACE_MODE_READ))
                goto out_task;
 
        ret = -EINVAL;
@@ -747,7 +747,7 @@ static int show_numa_map_checked(struct seq_file *m, void *v)
        struct proc_maps_private *priv = m->private;
        struct task_struct *task = priv->task;
 
-       if (maps_protect && !ptrace_may_attach(task))
+       if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
                return -EACCES;
 
        return show_numa_map(m, v);
index 4b4f9cc..5d84e71 100644 (file)
@@ -113,7 +113,7 @@ static int show_map(struct seq_file *m, void *_vml)
        struct proc_maps_private *priv = m->private;
        struct task_struct *task = priv->task;
 
-       if (maps_protect && !ptrace_may_attach(task))
+       if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
                return -EACCES;
 
        return nommu_vma_show(m, vml->vma);
index 9590b90..78f613c 100644 (file)
@@ -45,6 +45,7 @@ const struct file_operations ramfs_file_operations = {
        .mmap           = generic_file_mmap,
        .fsync          = simple_sync_file,
        .splice_read    = generic_file_splice_read,
+       .splice_write   = generic_file_splice_write,
        .llseek         = generic_file_llseek,
 };
 
index 0989bc2..52312ec 100644 (file)
@@ -43,6 +43,7 @@ const struct file_operations ramfs_file_operations = {
        .aio_write              = generic_file_aio_write,
        .fsync                  = simple_sync_file,
        .splice_read            = generic_file_splice_read,
+       .splice_write           = generic_file_splice_write,
        .llseek                 = generic_file_llseek,
 };
 
index f0d1240..9ba495d 100644 (file)
@@ -31,12 +31,12 @@ const struct file_operations generic_ro_fops = {
 
 EXPORT_SYMBOL(generic_ro_fops);
 
-loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
+loff_t
+generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
 {
        loff_t retval;
        struct inode *inode = file->f_mapping->host;
 
-       mutex_lock(&inode->i_mutex);
        switch (origin) {
                case SEEK_END:
                        offset += inode->i_size;
@@ -46,42 +46,26 @@ loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
        }
        retval = -EINVAL;
        if (offset>=0 && offset<=inode->i_sb->s_maxbytes) {
+               /* Special lock needed here? */
                if (offset != file->f_pos) {
                        file->f_pos = offset;
                        file->f_version = 0;
                }
                retval = offset;
        }
-       mutex_unlock(&inode->i_mutex);
        return retval;
 }
+EXPORT_SYMBOL(generic_file_llseek_unlocked);
 
-EXPORT_SYMBOL(generic_file_llseek);
-
-loff_t remote_llseek(struct file *file, loff_t offset, int origin)
+loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
 {
-       loff_t retval;
-
-       lock_kernel();
-       switch (origin) {
-               case SEEK_END:
-                       offset += i_size_read(file->f_path.dentry->d_inode);
-                       break;
-               case SEEK_CUR:
-                       offset += file->f_pos;
-       }
-       retval = -EINVAL;
-       if (offset>=0 && offset<=file->f_path.dentry->d_inode->i_sb->s_maxbytes) {
-               if (offset != file->f_pos) {
-                       file->f_pos = offset;
-                       file->f_version = 0;
-               }
-               retval = offset;
-       }
-       unlock_kernel();
-       return retval;
+       loff_t n;
+       mutex_lock(&file->f_dentry->d_inode->i_mutex);
+       n = generic_file_llseek_unlocked(file, offset, origin);
+       mutex_unlock(&file->f_dentry->d_inode->i_mutex);
+       return n;
 }
-EXPORT_SYMBOL(remote_llseek);
+EXPORT_SYMBOL(generic_file_llseek);
 
 loff_t no_llseek(struct file *file, loff_t offset, int origin)
 {
index efbe29a..2294783 100644 (file)
@@ -422,9 +422,18 @@ smb_file_permission(struct inode *inode, int mask, struct nameidata *nd)
        return error;
 }
 
+static loff_t smb_remote_llseek(struct file *file, loff_t offset, int origin)
+{
+       loff_t ret;
+       lock_kernel();
+       ret = generic_file_llseek_unlocked(file, offset, origin);
+       unlock_kernel();
+       return ret;
+}
+
 const struct file_operations smb_file_operations =
 {
-       .llseek         = remote_llseek,
+       .llseek         = smb_remote_llseek,
        .read           = do_sync_read,
        .aio_read       = smb_file_aio_read,
        .write          = do_sync_write,
index aa5f6f6..3994421 100644 (file)
@@ -379,13 +379,22 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
                                lock_page(page);
 
                        /*
-                        * page was truncated, stop here. if this isn't the
-                        * first page, we'll just complete what we already
-                        * added
+                        * Page was truncated, or invalidated by the
+                        * filesystem.  Redo the find/create, but this time the
+                        * page is kept locked, so there's no chance of another
+                        * race with truncate/invalidate.
                         */
                        if (!page->mapping) {
                                unlock_page(page);
-                               break;
+                               page = find_or_create_page(mapping, index,
+                                               mapping_gfp_mask(mapping));
+
+                               if (!page) {
+                                       error = -ENOMEM;
+                                       break;
+                               }
+                               page_cache_release(pages[page_nr]);
+                               pages[page_nr] = page;
                        }
                        /*
                         * page was already under io and is now done, great
index a352272..b546ba6 100644 (file)
@@ -645,7 +645,7 @@ static int vfat_add_entry(struct inode *dir, struct qstr *qname, int is_dir,
        if (len == 0)
                return -ENOENT;
 
-       slots = kmalloc(sizeof(*slots) * MSDOS_SLOTS, GFP_KERNEL);
+       slots = kmalloc(sizeof(*slots) * MSDOS_SLOTS, GFP_NOFS);
        if (slots == NULL)
                return -ENOMEM;
 
@@ -687,7 +687,7 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
        struct dentry *alias;
        int err, table;
 
-       lock_kernel();
+       lock_super(sb);
        table = (MSDOS_SB(sb)->options.name_check == 's') ? 2 : 0;
        dentry->d_op = &vfat_dentry_ops[table];
 
@@ -699,7 +699,7 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
        inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
        brelse(sinfo.bh);
        if (IS_ERR(inode)) {
-               unlock_kernel();
+               unlock_super(sb);
                return ERR_CAST(inode);
        }
        alias = d_find_alias(inode);
@@ -708,13 +708,13 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
                        dput(alias);
                else {
                        iput(inode);
-                       unlock_kernel();
+                       unlock_super(sb);
                        return alias;
                }
 
        }
 error:
-       unlock_kernel();
+       unlock_super(sb);
        dentry->d_op = &vfat_dentry_ops[table];
        dentry->d_time = dentry->d_parent->d_inode->i_version;
        dentry = d_splice_alias(inode, dentry);
@@ -734,7 +734,7 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, int mode,
        struct timespec ts;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
 
        ts = CURRENT_TIME_SEC;
        err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo);
@@ -755,17 +755,18 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, int mode,
        dentry->d_time = dentry->d_parent->d_inode->i_version;
        d_instantiate(dentry, inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        return err;
 }
 
 static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = dentry->d_inode;
+       struct super_block *sb = dir->i_sb;
        struct fat_slot_info sinfo;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = fat_dir_empty(inode);
        if (err)
@@ -783,7 +784,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
        inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
        fat_detach(inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
 
        return err;
 }
@@ -791,10 +792,11 @@ out:
 static int vfat_unlink(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = dentry->d_inode;
+       struct super_block *sb = dir->i_sb;
        struct fat_slot_info sinfo;
        int err;
 
-       lock_kernel();
+       lock_super(sb);
 
        err = vfat_find(dir, &dentry->d_name, &sinfo);
        if (err)
@@ -807,7 +809,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)
        inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
        fat_detach(inode);
 out:
-       unlock_kernel();
+       unlock_super(sb);
 
        return err;
 }
@@ -820,7 +822,7 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        struct timespec ts;
        int err, cluster;
 
-       lock_kernel();
+       lock_super(sb);
 
        ts = CURRENT_TIME_SEC;
        cluster = fat_alloc_new_dir(dir, &ts);
@@ -849,13 +851,13 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        dentry->d_time = dentry->d_parent->d_inode->i_version;
        d_instantiate(dentry, inode);
 
-       unlock_kernel();
+       unlock_super(sb);
        return 0;
 
 out_free:
        fat_free_clusters(dir, cluster);
 out:
-       unlock_kernel();
+       unlock_super(sb);
        return err;
 }
 
@@ -869,11 +871,12 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
        struct timespec ts;
        loff_t dotdot_i_pos, new_i_pos;
        int err, is_dir, update_dotdot, corrupt = 0;
+       struct super_block *sb = old_dir->i_sb;
 
        old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
        old_inode = old_dentry->d_inode;
        new_inode = new_dentry->d_inode;
-       lock_kernel();
+       lock_super(sb);
        err = vfat_find(old_dir, &old_dentry->d_name, &old_sinfo);
        if (err)
                goto out;
@@ -951,7 +954,7 @@ out:
        brelse(sinfo.bh);
        brelse(dotdot_bh);
        brelse(old_sinfo.bh);
-       unlock_kernel();
+       unlock_super(sb);
 
        return err;
 
index b522887..bdca155 100644 (file)
@@ -4,5 +4,6 @@ header-y += sound/
 header-y += mtd/
 header-y += rdma/
 header-y += video/
+header-y += drm/
 
 header-y += asm-$(ARCH)/
index c2b13c2..2001e81 100644 (file)
 #define        AT91_PMC_PCSR           (AT91_PMC + 0x18)       /* Peripheral Clock Status Register */
 
 #define        AT91_CKGR_UCKR          (AT91_PMC + 0x1C)       /* UTMI Clock Register [SAM9RL, CAP9] */
+#define                AT91_PMC_UPLLEN         (1   << 16)             /* UTMI PLL Enable */
+#define                AT91_PMC_UPLLCOUNT      (0xf << 20)             /* UTMI PLL Start-up Time */
+#define                AT91_PMC_BIASEN         (1   << 24)             /* UTMI BIAS Enable */
+#define                AT91_PMC_BIASCOUNT      (0xf << 28)             /* UTMI PLL Start-up Time */
 
 #define        AT91_CKGR_MOR           (AT91_PMC + 0x20)       /* Main Oscillator Register [not on SAM9RL] */
 #define                AT91_PMC_MOSCEN         (1    << 0)             /* Main Oscillator Enable */
-#define                AT91_PMC_OSCBYPASS      (1    << 1)             /* Oscillator Bypass [AT91SAM926x only] */
+#define                AT91_PMC_OSCBYPASS      (1    << 1)             /* Oscillator Bypass [SAM9x, CAP9] */
 #define                AT91_PMC_OSCOUNT        (0xff << 8)             /* Main Oscillator Start-up Time */
 
 #define        AT91_CKGR_MCFR          (AT91_PMC + 0x24)       /* Main Clock Frequency Register */
 #define                AT91_PMC_LOCKA          (1 <<  1)               /* PLLA Lock */
 #define                AT91_PMC_LOCKB          (1 <<  2)               /* PLLB Lock */
 #define                AT91_PMC_MCKRDY         (1 <<  3)               /* Master Clock */
+#define                AT91_PMC_LOCKU          (1 <<  6)               /* UPLL Lock [AT91CAP9 only] */
 #define                AT91_PMC_PCK0RDY        (1 <<  8)               /* Programmable Clock 0 */
 #define                AT91_PMC_PCK1RDY        (1 <<  9)               /* Programmable Clock 1 */
 #define                AT91_PMC_PCK2RDY        (1 << 10)               /* Programmable Clock 2 */
index bac83ad..6f14d90 100644 (file)
 #define AT91CAP9_ROM_SIZE      (32 * SZ_1K)    /* Internal ROM size (32Kb) */
 
 #define AT91CAP9_LCDC_BASE     0x00500000      /* LCD Controller */
-#define AT91CAP9_UDPHS_BASE    0x00600000      /* USB High Speed Device Port */
+#define AT91CAP9_UDPHS_FIFO    0x00600000      /* USB High Speed Device Port */
 #define AT91CAP9_UHP_BASE      0x00700000      /* USB Host controller */
 
 #define CONFIG_DRAM_BASE       AT91_CHIPSELECT_6
index a641686..ddbd487 100644 (file)
 #define AT91_MPBS0_SFR         (AT91_MATRIX + 0x114)   /* MPBlock Slave 0 Special Function Register */
 #define AT91_MPBS1_SFR         (AT91_MATRIX + 0x11C)   /* MPBlock Slave 1 Special Function Register */
 
+#define AT91_MATRIX_UDPHS      (AT91_MATRIX + 0x118)   /* USBHS Special Function Register [AT91CAP9 only] */
+#define                AT91_MATRIX_SELECT_UDPHS        (0 << 31)       /* select High Speed UDP */
+#define                AT91_MATRIX_SELECT_UDP          (1 << 31)       /* select standard UDP */
+#define                AT91_MATRIX_UDPHS_BYPASS_LOCK   (1 << 30)       /* bypass lock bit */
+
 #define AT91_MATRIX_EBICSA     (AT91_MATRIX + 0x120)   /* EBI Chip Select Assignment Register */
 #define                AT91_MATRIX_EBI_CS1A            (1 << 1)        /* Chip Select 1 Assignment */
 #define                        AT91_MATRIX_EBI_CS1A_SMC                (0 << 1)
index c8934fe..889872a 100644 (file)
@@ -6,6 +6,8 @@
  * Common definitions.
  * Based on AT91SAM9260 datasheet revision A (Preliminary).
  *
+ * Includes also definitions for AT91SAM9XE and AT91SAM9G families
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
 #define AT91SAM9XE_FLASH_BASE  0x00200000      /* Internal FLASH base address */
 #define AT91SAM9XE_SRAM_BASE   0x00300000      /* Internal SRAM base address */
 
+#define AT91SAM9G20_ROM_BASE   0x00100000      /* Internal ROM base address */
+#define AT91SAM9G20_ROM_SIZE   SZ_32K          /* Internal ROM size (32Kb) */
+
+#define AT91SAM9G20_SRAM0_BASE 0x00200000      /* Internal SRAM 0 base address */
+#define AT91SAM9G20_SRAM0_SIZE SZ_16K          /* Internal SRAM 0 size (16Kb) */
+#define AT91SAM9G20_SRAM1_BASE 0x00300000      /* Internal SRAM 1 base address */
+#define AT91SAM9G20_SRAM1_SIZE SZ_16K          /* Internal SRAM 1 size (16Kb) */
+
+#define AT91SAM9G20_UHP_BASE   0x00500000      /* USB Host controller */
 
 #endif
index 16d2832..622e56f 100644 (file)
 #define AT91SAM9RL_ROM_SIZE    (2 * SZ_16K)    /* Internal ROM size (32Kb) */
 
 #define AT91SAM9RL_LCDC_BASE   0x00500000      /* LCD Controller */
-#define AT91SAM9RL_UDPHS_BASE  0x00600000      /* USB Device HS controller */
+#define AT91SAM9RL_UDPHS_FIFO  0x00600000      /* USB Device HS controller */
 
 #endif
index dc189f0..94de788 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/i2c.h>
 #include <linux/leds.h>
 #include <linux/spi/spi.h>
+#include <linux/usb/atmel_usba_udc.h>
 
  /* USB Device */
 struct at91_udc_data {
@@ -45,6 +46,9 @@ struct at91_udc_data {
 };
 extern void __init at91_add_device_udc(struct at91_udc_data *data);
 
+ /* USB High Speed Device */
+extern void __init at91_add_device_usba(struct usba_platform_data *data);
+
  /* Compact Flash */
 struct at91_cf_data {
        u8      irq_pin;                /* I/O IRQ */
@@ -73,7 +77,7 @@ struct at91_eth_data {
 };
 extern void __init at91_add_device_eth(struct at91_eth_data *data);
 
-#if defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9263) || defined(CONFIG_ARCH_AT91CAP9)
+#if defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9263) || defined(CONFIG_ARCH_AT91SAM9G20) || defined(CONFIG_ARCH_AT91CAP9)
 #define eth_platform_data      at91_eth_data
 #endif
 
index 7145166..52df794 100644 (file)
@@ -21,6 +21,7 @@
 #define ARCH_ID_AT91SAM9260    0x019803a0
 #define ARCH_ID_AT91SAM9261    0x019703a0
 #define ARCH_ID_AT91SAM9263    0x019607a0
+#define ARCH_ID_AT91SAM9G20    0x019905a0
 #define ARCH_ID_AT91SAM9RL64   0x019b03a0
 #define ARCH_ID_AT91CAP9       0x039A03A0
 
@@ -63,6 +64,12 @@ static inline unsigned long at91_arch_identify(void)
 #define cpu_is_at91sam9260()   (0)
 #endif
 
+#ifdef CONFIG_ARCH_AT91SAM9G20
+#define cpu_is_at91sam9g20()   (at91_cpu_identify() == ARCH_ID_AT91SAM9G20)
+#else
+#define cpu_is_at91sam9g20()   (0)
+#endif
+
 #ifdef CONFIG_ARCH_AT91SAM9261
 #define cpu_is_at91sam9261()   (at91_cpu_identify() == ARCH_ID_AT91SAM9261)
 #else
index 2c826d8..016a3a3 100644 (file)
@@ -18,7 +18,7 @@
 
 #if defined(CONFIG_ARCH_AT91RM9200)
 #include <asm/arch/at91rm9200.h>
-#elif defined(CONFIG_ARCH_AT91SAM9260)
+#elif defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9G20)
 #include <asm/arch/at91sam9260.h>
 #elif defined(CONFIG_ARCH_AT91SAM9261)
 #include <asm/arch/at91sam9261.h>
index f1933b0..298d831 100644 (file)
 
 #define CLOCK_TICK_RATE                (AT91_SLOW_CLOCK)
 
-#elif defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9261)
+#elif defined(CONFIG_ARCH_AT91SAM9260)
+
+#if defined(CONFIG_MACH_USB_A9260) || defined(CONFIG_MACH_QIL_A9260)
+#define AT91SAM9_MASTER_CLOCK  90000000
+#else
+#define AT91SAM9_MASTER_CLOCK  99300000
+#endif
+
+#define CLOCK_TICK_RATE                (AT91SAM9_MASTER_CLOCK/16)
+
+#elif defined(CONFIG_ARCH_AT91SAM9261)
 
 #define AT91SAM9_MASTER_CLOCK  99300000
 #define CLOCK_TICK_RATE                (AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9263)
 
+#if defined(CONFIG_MACH_USB_A9263)
+#define AT91SAM9_MASTER_CLOCK  90000000
+#else
 #define AT91SAM9_MASTER_CLOCK  99959500
+#endif
+
 #define CLOCK_TICK_RATE                (AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9RL)
 #define AT91SAM9_MASTER_CLOCK  100000000
 #define CLOCK_TICK_RATE                (AT91SAM9_MASTER_CLOCK/16)
 
+#elif defined(CONFIG_ARCH_AT91SAM9G20)
+
+#define AT91SAM9_MASTER_CLOCK  132096000
+#define CLOCK_TICK_RATE                (AT91SAM9_MASTER_CLOCK/16)
+
 #elif defined(CONFIG_ARCH_AT91CAP9)
 
 #define AT91CAP9_MASTER_CLOCK  100000000
index daad8ee..74610c2 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <asm/arch/memory.h>
 
-#ifdef CONFIG_ARCH_FOOTBRIDGE
 /*   Virtual      Physical     Size
  * 0xff800000  0x40000000      1MB     X-Bus
  * 0xff000000  0x7c000000      1MB     PCI I/O space
 #define PCIMEM_SIZE            0x01000000
 #define PCIMEM_BASE            0xf0000000
 
-#elif defined(CONFIG_ARCH_CO285)
-/*
- * This is the COEBSA285 cut-down mapping
- */
-#define PCIMEM_SIZE            0x80000000
-#define PCIMEM_BASE            0x80000000
-
-#define WFLUSH_SIZE            0x01000000
-#define WFLUSH_BASE            0x7d000000
-
-#define ARMCSR_SIZE            0x00100000
-#define ARMCSR_BASE            0x7cf00000
-
-#define XBUS_SIZE              0x00020000
-#define XBUS_BASE              0x7cee0000
-
-#define PCIO_SIZE              0x00010000
-#define PCIO_BASE              0x7ced0000
-
-#else
-
-#error "Undefined footbridge architecture"
-
-#endif
-
 #define XBUS_LEDS              ((volatile unsigned char *)(XBUS_BASE + 0x12000))
 #define XBUS_LED_AMBER         (1 << 0)
 #define XBUS_LED_GREEN         (1 << 1)
index cbd7ae6..9019a3b 100644 (file)
@@ -42,8 +42,6 @@ extern unsigned long __bus_to_virt(unsigned long);
 
 #endif
 
-#if defined(CONFIG_ARCH_FOOTBRIDGE)
-
 /* Task size and page offset at 3GB */
 #define TASK_SIZE              UL(0xbf000000)
 #define PAGE_OFFSET            UL(0xc0000000)
@@ -53,23 +51,6 @@ extern unsigned long __bus_to_virt(unsigned long);
  */
 #define FLUSH_BASE             0xf9000000
 
-#elif defined(CONFIG_ARCH_CO285)
-
-/* Task size and page offset at 1.5GB */
-#define TASK_SIZE              UL(0x5f000000)
-#define PAGE_OFFSET            UL(0x60000000)
-
-/*
- * Cache flushing area.
- */
-#define FLUSH_BASE             0x7e000000
-
-#else
-
-#error "Undefined footbridge architecture"
-
-#endif
-
 /*
  * Physical DRAM offset.
  */
index 0259820..e487d7e 100644 (file)
@@ -7,8 +7,4 @@
  */
 
 
-#ifdef CONFIG_ARCH_FOOTBRIDGE
 #define VMALLOC_END       (PAGE_OFFSET + 0x30000000)
-#else
-#define VMALLOC_END       (PAGE_OFFSET + 0x20000000)
-#endif
index adffb6a..6542ca5 100644 (file)
  */
 extern void imx_gpio_mode( int gpio_mode );
 
-/* get frequencies in Hz */
-extern unsigned int imx_get_system_clk(void);
-extern unsigned int imx_get_mcu_clk(void);
-extern unsigned int imx_get_perclk1(void); /* UART[12], Timer[12], PWM */
-extern unsigned int imx_get_perclk2(void); /* LCD, SD, SPI[12]         */
-extern unsigned int imx_get_perclk3(void); /* SSI                      */
-extern unsigned int imx_get_hclk(void);    /* SDRAM, CSI, Memory Stick,*/
-                                           /* I2C, DMA                 */
 #endif
 
 #define MAXIRQNUM                       62
index 5b1066d..44d89c3 100644 (file)
@@ -88,7 +88,7 @@ int imx_dma_request(imx_dmach_t dma_ch, const char *name);
 
 void imx_dma_free(imx_dmach_t dma_ch);
 
-int imx_dma_request_by_prio(imx_dmach_t *pdma_ch, const char *name, imx_dma_prio prio);
+imx_dmach_t imx_dma_request_by_prio(const char *name, imx_dma_prio prio);
 
 
 #endif /* _ASM_ARCH_IMX_DMA_H */
index 3a685e1..d54eb1d 100644 (file)
@@ -4,6 +4,8 @@
 #define IMXUART_HAVE_RTSCTS (1<<0)
 
 struct imxuart_platform_data {
+       int (*init)(struct platform_device *pdev);
+       void (*exit)(struct platform_device *pdev);
        unsigned int flags;
 };
 
index 2e15da5..d79846f 100644 (file)
@@ -1,3 +1,3 @@
 #ifndef _IOP13XX_DMA_H
-#define _IOP13XX_DMA_H_
+#define _IOP13XX_DMA_H
 #endif
diff --git a/include/asm-arm/arch-iop32x/gpio.h b/include/asm-arm/arch-iop32x/gpio.h
new file mode 100644 (file)
index 0000000..708f4ec
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __ASM_ARCH_IOP32X_GPIO_H
+#define __ASM_ARCH_IOP32X_GPIO_H
+
+#include <asm/hardware/iop3xx-gpio.h>
+
+#endif
diff --git a/include/asm-arm/arch-iop33x/gpio.h b/include/asm-arm/arch-iop33x/gpio.h
new file mode 100644 (file)
index 0000000..ddd55bb
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __ASM_ARCH_IOP33X_GPIO_H
+#define __ASM_ARCH_IOP33X_GPIO_H
+
+#include <asm/hardware/iop3xx-gpio.h>
+
+#endif
diff --git a/include/asm-arm/arch-ixp4xx/fsg.h b/include/asm-arm/arch-ixp4xx/fsg.h
new file mode 100644 (file)
index 0000000..c0100cc
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * include/asm-arm/arch-ixp4xx/fsg.h
+ *
+ * Freecom FSG-3 platform specific definitions
+ *
+ * Author: Rod Whitby <rod@whitby.id.au>
+ * Author: Tomasz Chmielewski <mangoo@wpkg.org>
+ * Maintainers: http://www.nslu2-linux.org
+ *
+ * Based on coyote.h by
+ * Copyright 2004 (c) MontaVista, Software, Inc.
+ *
+ * This file is licensed under  the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_HARDWARE_H__
+#error "Do not include this directly, instead #include <asm/hardware.h>"
+#endif
+
+#define FSG_SDA_PIN            12
+#define FSG_SCL_PIN            13
+
+/*
+ * FSG PCI IRQs
+ */
+#define FSG_PCI_MAX_DEV                3
+#define FSG_PCI_IRQ_LINES      3
+
+
+/* PCI controller GPIO to IRQ pin mappings */
+#define FSG_PCI_INTA_PIN       6
+#define FSG_PCI_INTB_PIN       7
+#define FSG_PCI_INTC_PIN       5
+
+/* Buttons */
+
+#define FSG_SB_GPIO            4       /* sync button */
+#define FSG_RB_GPIO            9       /* reset button */
+#define FSG_UB_GPIO            10      /* usb button */
+
+/* LEDs */
+
+#define FSG_LED_WLAN_BIT       0
+#define FSG_LED_WAN_BIT                1
+#define FSG_LED_SATA_BIT       2
+#define FSG_LED_USB_BIT                4
+#define FSG_LED_RING_BIT       5
+#define FSG_LED_SYNC_BIT       7
index 73e8dc3..fa723a6 100644 (file)
@@ -45,5 +45,6 @@
 #include "nslu2.h"
 #include "nas100d.h"
 #include "dsmg600.h"
+#include "fsg.h"
 
 #endif  /* _ASM_ARCH_HARDWARE_H */
index 1180160..674af4a 100644 (file)
 #define        IRQ_DSMG600_PCI_INTE    IRQ_IXP4XX_GPIO7
 #define        IRQ_DSMG600_PCI_INTF    IRQ_IXP4XX_GPIO6
 
+/*
+ * Freecom FSG-3 Board IRQs
+ */
+#define        IRQ_FSG_PCI_INTA        IRQ_IXP4XX_GPIO6
+#define        IRQ_FSG_PCI_INTB        IRQ_IXP4XX_GPIO7
+#define        IRQ_FSG_PCI_INTC        IRQ_IXP4XX_GPIO5
+
 #endif
diff --git a/include/asm-arm/arch-kirkwood/debug-macro.S b/include/asm-arm/arch-kirkwood/debug-macro.S
new file mode 100644 (file)
index 0000000..f55fb8a
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * include/asm-arm/arch-kirkwood/debug-macro.S
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <asm/arch/kirkwood.h>
+
+       .macro  addruart,rx
+       mrc     p15, 0, \rx, c1, c0
+       tst     \rx, #1                                 @ MMU enabled?
+       ldreq   \rx, =KIRKWOOD_REGS_PHYS_BASE
+       ldrne   \rx, =KIRKWOOD_REGS_VIRT_BASE
+       orr     \rx, \rx, #0x00012000
+       .endm
+
+#define UART_SHIFT     2
+#include <asm/hardware/debug-8250.S>
diff --git a/include/asm-arm/arch-kirkwood/dma.h b/include/asm-arm/arch-kirkwood/dma.h
new file mode 100644 (file)
index 0000000..40a8c17
--- /dev/null
@@ -0,0 +1 @@
+/* empty */
diff --git a/include/asm-arm/arch-kirkwood/entry-macro.S b/include/asm-arm/arch-kirkwood/entry-macro.S
new file mode 100644 (file)
index 0000000..fc6a43d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * include/asm-arm/arch-kirkwood/entry-macro.S
+ *
+ * Low-level IRQ helper macros for Marvell Kirkwood platforms
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/arch/kirkwood.h>
+
+       .macro  disable_fiq
+       .endm
+
+       .macro  arch_ret_to_user, tmp1, tmp2
+       .endm
+
+       .macro  get_irqnr_preamble, base, tmp
+       ldr     \base, =IRQ_VIRT_BASE
+       .endm
+
+       .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+       @ check low interrupts
+       ldr     \irqstat, [\base, #IRQ_CAUSE_LOW_OFF]
+       ldr     \tmp, [\base, #IRQ_MASK_LOW_OFF]
+       mov     \irqnr, #31
+       ands    \irqstat, \irqstat, \tmp
+       bne     1001f
+
+       @ if no low interrupts set, check high interrupts
+       ldr     \irqstat, [\base, #IRQ_CAUSE_HIGH_OFF]
+       ldr     \tmp, [\base, #IRQ_MASK_HIGH_OFF]
+       mov     \irqnr, #63
+       ands    \irqstat, \irqstat, \tmp
+
+       @ find first active interrupt source
+1001:  clzne   \irqstat, \irqstat
+       subne   \irqnr, \irqnr, \irqstat
+       .endm
diff --git a/include/asm-arm/arch-kirkwood/hardware.h b/include/asm-arm/arch-kirkwood/hardware.h
new file mode 100644 (file)
index 0000000..e695719
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * include/asm-arm/arch-kirkwood/hardware.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_ARCH_HARDWARE_H
+#define __ASM_ARCH_HARDWARE_H
+
+#include "kirkwood.h"
+
+#define pcibios_assign_all_busses()    1
+
+#define PCIBIOS_MIN_IO                 0x00001000
+#define PCIBIOS_MIN_MEM                        0x01000000
+#define PCIMEM_BASE                    KIRKWOOD_PCIE_MEM_PHYS_BASE /* mem base for VGA */
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/io.h b/include/asm-arm/arch-kirkwood/io.h
new file mode 100644 (file)
index 0000000..0ef6e95
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * include/asm-arm/arch-kirkwood/io.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IO_H
+#define __ASM_ARCH_IO_H
+
+#include "kirkwood.h"
+
+#define IO_SPACE_LIMIT         0xffffffff
+
+static inline void __iomem *__io(unsigned long addr)
+{
+       return (void __iomem *)((addr - KIRKWOOD_PCIE_IO_PHYS_BASE)
+                                       + KIRKWOOD_PCIE_IO_VIRT_BASE);
+}
+
+#define __io(a)                        __io(a)
+#define __mem_pci(a)           (a)
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/irqs.h b/include/asm-arm/arch-kirkwood/irqs.h
new file mode 100644 (file)
index 0000000..2e7b5da
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * include/asm-arm/arch-kirkwood/irqs.h
+ *
+ * IRQ definitions for Marvell Kirkwood SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IRQS_H
+#define __ASM_ARCH_IRQS_H
+
+#include "kirkwood.h"  /* need GPIO_MAX */
+
+/*
+ * Low Interrupt Controller
+ */
+#define IRQ_KIRKWOOD_HIGH_SUM  0
+#define IRQ_KIRKWOOD_BRIDGE    1
+#define IRQ_KIRKWOOD_HOST2CPU  2
+#define IRQ_KIRKWOOD_CPU2HOST  3
+#define IRQ_KIRKWOOD_XOR_00    5
+#define IRQ_KIRKWOOD_XOR_01    6
+#define IRQ_KIRKWOOD_XOR_10    7
+#define IRQ_KIRKWOOD_XOR_11    8
+#define IRQ_KIRKWOOD_PCIE      9
+#define IRQ_KIRKWOOD_GE00_SUM  11
+#define IRQ_KIRKWOOD_GE01_SUM  15
+#define IRQ_KIRKWOOD_USB       19
+#define IRQ_KIRKWOOD_SATA      21
+#define IRQ_KIRKWOOD_CRYPTO    22
+#define IRQ_KIRKWOOD_SPI       23
+#define IRQ_KIRKWOOD_I2S       24
+#define IRQ_KIRKWOOD_TS_0      26
+#define IRQ_KIRKWOOD_SDIO      28
+#define IRQ_KIRKWOOD_TWSI      29
+#define IRQ_KIRKWOOD_AVB       30
+#define IRQ_KIRKWOOD_TDMI      31
+
+/*
+ * High Interrupt Controller
+ */
+#define IRQ_KIRKWOOD_UART_0    33
+#define IRQ_KIRKWOOD_UART_1    34
+#define IRQ_KIRKWOOD_GPIO_LOW_0_7      35
+#define IRQ_KIRKWOOD_GPIO_LOW_8_15     36
+#define IRQ_KIRKWOOD_GPIO_LOW_16_23    37
+#define IRQ_KIRKWOOD_GPIO_LOW_24_31    38
+#define IRQ_KIRKWOOD_GPIO_HIGH_0_7     39
+#define IRQ_KIRKWOOD_GPIO_HIGH_8_15    40
+#define IRQ_KIRKWOOD_GPIO_HIGH_16_23   41
+
+/*
+ * KIRKWOOD General Purpose Pins
+ */
+#define IRQ_KIRKWOOD_GPIO_START        64
+#define NR_GPIO_IRQS           GPIO_MAX
+
+#define NR_IRQS                        (IRQ_KIRKWOOD_GPIO_START + NR_GPIO_IRQS)
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/kirkwood.h b/include/asm-arm/arch-kirkwood/kirkwood.h
new file mode 100644 (file)
index 0000000..bb31b31
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * include/asm-arm/arch-kirkwood/kirkwood.h
+ *
+ * Generic definitions for Marvell Kirkwood SoC flavors:
+ *  88F6180, 88F6192 and 88F6281.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_KIRKWOOD_H
+#define __ASM_ARCH_KIRKWOOD_H
+
+/*
+ * Marvell Kirkwood address maps.
+ *
+ * phys
+ * e0000000    PCIe Memory space
+ * f1000000    on-chip peripheral registers
+ * f2000000    PCIe I/O space
+ * f3000000    NAND controller address window
+ *
+ * virt                phys            size
+ * fee00000    f1000000        1M      on-chip peripheral registers
+ * fef00000    f2000000        1M      PCIe I/O space
+ */
+
+#define KIRKWOOD_NAND_MEM_PHYS_BASE    0xf3000000
+#define KIRKWOOD_NAND_MEM_SIZE         SZ_64K /* 1K is sufficient, but 64K
+                                               * is the minimal window size
+                                               */
+
+#define KIRKWOOD_PCIE_IO_PHYS_BASE     0xf2000000
+#define KIRKWOOD_PCIE_IO_VIRT_BASE     0xfef00000
+#define KIRKWOOD_PCIE_IO_BUS_BASE      0x00000000
+#define KIRKWOOD_PCIE_IO_SIZE          SZ_1M
+
+#define KIRKWOOD_REGS_PHYS_BASE                0xf1000000
+#define KIRKWOOD_REGS_VIRT_BASE                0xfee00000
+#define KIRKWOOD_REGS_SIZE             SZ_1M
+
+#define KIRKWOOD_PCIE_MEM_PHYS_BASE    0xe0000000
+#define KIRKWOOD_PCIE_MEM_SIZE         SZ_128M
+
+/*
+ * MBUS bridge registers.
+ */
+#define BRIDGE_VIRT_BASE       (KIRKWOOD_REGS_VIRT_BASE | 0x20000)
+#define  CPU_CONTROL           (BRIDGE_VIRT_BASE | 0x0104)
+#define   CPU_RESET            0x00000002
+#define  RSTOUTn_MASK          (BRIDGE_VIRT_BASE | 0x0108)
+#define   SOFT_RESET_OUT_EN    0x00000004
+#define  SYSTEM_SOFT_RESET     (BRIDGE_VIRT_BASE | 0x010c)
+#define   SOFT_RESET           0x00000001
+#define  BRIDGE_CAUSE          (BRIDGE_VIRT_BASE | 0x0110)
+#define  BRIDGE_MASK           (BRIDGE_VIRT_BASE | 0x0114)
+#define   BRIDGE_INT_TIMER0    0x0002
+#define   BRIDGE_INT_TIMER1    0x0004
+#define   BRIDGE_INT_TIMER1_CLR        (~0x0004)
+#define  IRQ_VIRT_BASE         (BRIDGE_VIRT_BASE | 0x0200)
+#define   IRQ_CAUSE_LOW_OFF    0x0000
+#define   IRQ_MASK_LOW_OFF     0x0004
+#define   IRQ_CAUSE_HIGH_OFF   0x0010
+#define   IRQ_MASK_HIGH_OFF    0x0014
+#define  TIMER_VIRT_BASE       (BRIDGE_VIRT_BASE | 0x0300)
+#define  L2_CONFIG_REG         (BRIDGE_VIRT_BASE | 0x0128)
+#define   L2_WRITETHROUGH      0x00000010
+
+/*
+ * Register Map
+ */
+#define DDR_VIRT_BASE          (KIRKWOOD_REGS_VIRT_BASE | 0x00000)
+#define  DDR_WINDOW_CPU_BASE   (DDR_VIRT_BASE | 0x1500)
+
+#define DEV_BUS_PHYS_BASE      (KIRKWOOD_REGS_PHYS_BASE | 0x10000)
+#define DEV_BUS_VIRT_BASE      (KIRKWOOD_REGS_VIRT_BASE | 0x10000)
+#define  SAMPLE_AT_RESET       (DEV_BUS_VIRT_BASE | 0x0030)
+#define  DEVICE_ID             (DEV_BUS_VIRT_BASE | 0x0034)
+#define  RTC_PHYS_BASE         (DEV_BUS_PHYS_BASE | 0x0300)
+#define  SPI_PHYS_BASE         (DEV_BUS_PHYS_BASE | 0x0600)
+#define  UART0_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2000)
+#define  UART0_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2000)
+#define  UART1_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2100)
+#define  UART1_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2100)
+
+#define PCIE_VIRT_BASE         (KIRKWOOD_REGS_VIRT_BASE | 0x40000)
+
+#define USB_PHYS_BASE          (KIRKWOOD_REGS_PHYS_BASE | 0x50000)
+
+#define GE00_PHYS_BASE         (KIRKWOOD_REGS_PHYS_BASE | 0x70000)
+#define GE01_PHYS_BASE         (KIRKWOOD_REGS_PHYS_BASE | 0x74000)
+
+#define SATA_PHYS_BASE         (KIRKWOOD_REGS_PHYS_BASE | 0x80000)
+
+
+#define GPIO_MAX               50
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/memory.h b/include/asm-arm/arch-kirkwood/memory.h
new file mode 100644 (file)
index 0000000..e5108f4
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * include/asm-arm/arch-kirkwood/memory.h
+ */
+
+#ifndef __ASM_ARCH_MEMORY_H
+#define __ASM_ARCH_MEMORY_H
+
+#define PHYS_OFFSET            UL(0x00000000)
+
+#define __virt_to_bus(x)       __virt_to_phys(x)
+#define __bus_to_virt(x)       __phys_to_virt(x)
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/system.h b/include/asm-arm/arch-kirkwood/system.h
new file mode 100644 (file)
index 0000000..8dde7e3
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * include/asm-arm/arch-kirkwood/system.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_SYSTEM_H
+#define __ASM_ARCH_SYSTEM_H
+
+#include <asm/arch/hardware.h>
+#include <asm/arch/kirkwood.h>
+
+static inline void arch_idle(void)
+{
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode)
+{
+       /*
+        * Enable soft reset to assert RSTOUTn.
+        */
+       writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
+
+       /*
+        * Assert soft reset.
+        */
+       writel(SOFT_RESET, SYSTEM_SOFT_RESET);
+
+       while (1)
+               ;
+}
+
+
+#endif
diff --git a/include/asm-arm/arch-kirkwood/timex.h b/include/asm-arm/arch-kirkwood/timex.h
new file mode 100644 (file)
index 0000000..82122e1
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * include/asm-arm/arch-kirkwood/timex.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#define CLOCK_TICK_RATE                (100 * HZ)
+
+#define KIRKWOOD_TCLK          166666667
diff --git a/include/asm-arm/arch-kirkwood/uncompress.h b/include/asm-arm/arch-kirkwood/uncompress.h
new file mode 100644 (file)
index 0000000..a9062b6
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * include/asm-arm/arch-kirkwood/uncompress.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/serial_reg.h>
+#include <asm/arch/kirkwood.h>
+
+#define SERIAL_BASE    ((unsigned char *)UART0_PHYS_BASE)
+
+static void putc(const char c)
+{
+       unsigned char *base = SERIAL_BASE;
+       int i;
+
+       for (i = 0; i < 0x1000; i++) {
+               if (base[UART_LSR << 2] & UART_LSR_THRE)
+                       break;
+               barrier();
+       }
+
+       base[UART_TX << 2] = c;
+}
+
+static void flush(void)
+{
+       unsigned char *base = SERIAL_BASE;
+       unsigned char mask;
+       int i;
+
+       mask = UART_LSR_TEMT | UART_LSR_THRE;
+
+       for (i = 0; i < 0x1000; i++) {
+               if ((base[UART_LSR << 2] & mask) == mask)
+                       break;
+               barrier();
+       }
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
diff --git a/include/asm-arm/arch-kirkwood/vmalloc.h b/include/asm-arm/arch-kirkwood/vmalloc.h
new file mode 100644 (file)
index 0000000..41852c6
--- /dev/null
@@ -0,0 +1,5 @@
+/*
+ * include/asm-arm/arch-kirkwood/vmalloc.h
+ */
+
+#define VMALLOC_END    0xfe800000
diff --git a/include/asm-arm/arch-loki/debug-macro.S b/include/asm-arm/arch-loki/debug-macro.S
new file mode 100644 (file)
index 0000000..585502e
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * include/asm-arm/arch-loki/debug-macro.S
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <asm/arch/loki.h>
+
+       .macro  addruart,rx
+       mrc     p15, 0, \rx, c1, c0
+       tst     \rx, #1                                 @ MMU enabled?
+       ldreq   \rx, =LOKI_REGS_PHYS_BASE
+       ldrne   \rx, =LOKI_REGS_VIRT_BASE
+       orr     \rx, \rx, #0x00012000
+       .endm
+
+#define UART_SHIFT     2
+#include <asm/hardware/debug-8250.S>
diff --git a/include/asm-arm/arch-loki/dma.h b/include/asm-arm/arch-loki/dma.h
new file mode 100644 (file)
index 0000000..40a8c17
--- /dev/null
@@ -0,0 +1 @@
+/* empty */
diff --git a/include/asm-arm/arch-loki/entry-macro.S b/include/asm-arm/arch-loki/entry-macro.S
new file mode 100644 (file)
index 0000000..693257c
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * include/asm-arm/arch-loki/entry-macro.S
+ *
+ * Low-level IRQ helper macros for Marvell Loki (88RC8480) platforms
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/arch/loki.h>
+
+       .macro  disable_fiq
+       .endm
+
+       .macro  arch_ret_to_user, tmp1, tmp2
+       .endm
+
+       .macro  get_irqnr_preamble, base, tmp
+       ldr     \base, =IRQ_VIRT_BASE
+       .endm
+
+       .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+       ldr     \irqstat, [\base, #IRQ_CAUSE_OFF]
+       ldr     \tmp, [\base, #IRQ_MASK_OFF]
+       mov     \irqnr, #0
+       ands    \irqstat, \irqstat, \tmp
+       clzne   \irqnr, \irqstat
+       rsbne   \irqnr, \irqnr, #31
+       .endm
diff --git a/include/asm-arm/arch-loki/hardware.h b/include/asm-arm/arch-loki/hardware.h
new file mode 100644 (file)
index 0000000..f65b01c
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * include/asm-arm/arch-loki/hardware.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_ARCH_HARDWARE_H
+#define __ASM_ARCH_HARDWARE_H
+
+#include "loki.h"
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/io.h b/include/asm-arm/arch-loki/io.h
new file mode 100644 (file)
index 0000000..e7418a9
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * include/asm-arm/arch-loki/io.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IO_H
+#define __ASM_ARCH_IO_H
+
+#include "loki.h"
+
+#define IO_SPACE_LIMIT         0xffffffff
+
+static inline void __iomem *__io(unsigned long addr)
+{
+       return (void __iomem *)((addr - LOKI_PCIE0_IO_PHYS_BASE)
+                                       + LOKI_PCIE0_IO_VIRT_BASE);
+}
+
+#define __io(a)                        __io(a)
+#define __mem_pci(a)           (a)
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/irqs.h b/include/asm-arm/arch-loki/irqs.h
new file mode 100644 (file)
index 0000000..7e49714
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * include/asm-arm/arch-loki/irqs.h
+ *
+ * IRQ definitions for Marvell Loki (88RC8480) SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IRQS_H
+#define __ASM_ARCH_IRQS_H
+
+#include "loki.h"      /* need GPIO_MAX */
+
+/*
+ * Interrupt Controller
+ */
+#define IRQ_LOKI_PCIE_A_CPU_DRBL       0
+#define IRQ_LOKI_CPU_PCIE_A_DRBL       1
+#define IRQ_LOKI_PCIE_B_CPU_DRBL       2
+#define IRQ_LOKI_CPU_PCIE_B_DRBL       3
+#define IRQ_LOKI_COM_A_ERR             6
+#define IRQ_LOKI_COM_A_IN              7
+#define IRQ_LOKI_COM_A_OUT             8
+#define IRQ_LOKI_COM_B_ERR             9
+#define IRQ_LOKI_COM_B_IN              10
+#define IRQ_LOKI_COM_B_OUT             11
+#define IRQ_LOKI_DMA_A                 12
+#define IRQ_LOKI_DMA_B                 13
+#define IRQ_LOKI_SAS_A                 14
+#define IRQ_LOKI_SAS_B                 15
+#define IRQ_LOKI_DDR                   16
+#define IRQ_LOKI_XOR                   17
+#define IRQ_LOKI_BRIDGE                        18
+#define IRQ_LOKI_PCIE_A_ERR            20
+#define IRQ_LOKI_PCIE_A_INT            21
+#define IRQ_LOKI_PCIE_B_ERR            22
+#define IRQ_LOKI_PCIE_B_INT            23
+#define IRQ_LOKI_GBE_A_INT             24
+#define IRQ_LOKI_GBE_B_INT             25
+#define IRQ_LOKI_DEV_ERR               26
+#define IRQ_LOKI_UART0                 27
+#define IRQ_LOKI_UART1                 28
+#define IRQ_LOKI_TWSI                  29
+#define IRQ_LOKI_GPIO_23_0             30
+#define IRQ_LOKI_GPIO_25_24            31
+
+/*
+ * Loki General Purpose Pins
+ */
+#define IRQ_LOKI_GPIO_START    32
+#define NR_GPIO_IRQS           GPIO_MAX
+
+#define NR_IRQS                        (IRQ_LOKI_GPIO_START + NR_GPIO_IRQS)
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/loki.h b/include/asm-arm/arch-loki/loki.h
new file mode 100644 (file)
index 0000000..5dd05ee
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * include/asm-arm/arch-loki/loki.h
+ *
+ * Generic definitions for Marvell Loki (88RC8480) SoC flavors
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_LOKI_H
+#define __ASM_ARCH_LOKI_H
+
+/*
+ * Marvell Loki (88RC8480) address maps.
+ *
+ * phys
+ * d0000000    on-chip peripheral registers
+ * e0000000    PCIe 0 Memory space
+ * e8000000    PCIe 1 Memory space
+ * f0000000    PCIe 0 I/O space
+ * f0100000    PCIe 1 I/O space
+ *
+ * virt                phys            size
+ * fed00000    d0000000        1M      on-chip peripheral registers
+ * fee00000    f0000000        64K     PCIe 0 I/O space
+ * fef00000    f0100000        64K     PCIe 1 I/O space
+ */
+
+#define LOKI_REGS_PHYS_BASE            0xd0000000
+#define LOKI_REGS_VIRT_BASE            0xfed00000
+#define LOKI_REGS_SIZE                 SZ_1M
+
+#define LOKI_PCIE0_IO_PHYS_BASE                0xf0000000
+#define LOKI_PCIE0_IO_VIRT_BASE                0xfee00000
+#define LOKI_PCIE0_IO_BUS_BASE         0x00000000
+#define LOKI_PCIE0_IO_SIZE             SZ_64K
+
+#define LOKI_PCIE1_IO_PHYS_BASE                0xf0100000
+#define LOKI_PCIE1_IO_VIRT_BASE                0xfef00000
+#define LOKI_PCIE1_IO_BUS_BASE         0x00000000
+#define LOKI_PCIE1_IO_SIZE             SZ_64K
+
+#define LOKI_PCIE0_MEM_PHYS_BASE       0xe0000000
+#define LOKI_PCIE0_MEM_SIZE            SZ_128M
+
+#define LOKI_PCIE1_MEM_PHYS_BASE       0xe8000000
+#define LOKI_PCIE1_MEM_SIZE            SZ_128M
+
+/*
+ * Register Map
+ */
+#define DEV_BUS_PHYS_BASE      (LOKI_REGS_PHYS_BASE | 0x10000)
+#define DEV_BUS_VIRT_BASE      (LOKI_REGS_VIRT_BASE | 0x10000)
+#define  UART0_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2000)
+#define  UART0_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2000)
+#define  UART1_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2100)
+#define  UART1_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2100)
+
+#define BRIDGE_VIRT_BASE       (LOKI_REGS_VIRT_BASE | 0x20000)
+#define  BRIDGE_REG(x)         (BRIDGE_VIRT_BASE | (x))
+#define  RSTOUTn_MASK          (BRIDGE_VIRT_BASE | 0x0108)
+#define   SOFT_RESET_OUT_EN    0x00000004
+#define  SYSTEM_SOFT_RESET     (BRIDGE_VIRT_BASE | 0x010c)
+#define   SOFT_RESET           0x00000001
+#define  BRIDGE_CAUSE          (BRIDGE_VIRT_BASE | 0x0110)
+#define  BRIDGE_MASK           (BRIDGE_VIRT_BASE | 0x0114)
+#define   BRIDGE_INT_TIMER0    0x0002
+#define   BRIDGE_INT_TIMER1    0x0004
+#define   BRIDGE_INT_TIMER1_CLR        0x0004
+#define  IRQ_VIRT_BASE         (BRIDGE_VIRT_BASE | 0x0200)
+#define   IRQ_CAUSE_OFF                0x0000
+#define   IRQ_MASK_OFF         0x0004
+#define  TIMER_VIRT_BASE       (BRIDGE_VIRT_BASE | 0x0300)
+
+#define PCIE0_VIRT_BASE                (LOKI_REGS_VIRT_BASE | 0x30000)
+
+#define PCIE1_VIRT_BASE                (LOKI_REGS_VIRT_BASE | 0x40000)
+
+#define SAS0_PHYS_BASE         (LOKI_REGS_PHYS_BASE | 0x80000)
+
+#define SAS1_PHYS_BASE         (LOKI_REGS_PHYS_BASE | 0x90000)
+
+#define GE0_PHYS_BASE          (LOKI_REGS_PHYS_BASE | 0xa0000)
+#define GE0_VIRT_BASE          (LOKI_REGS_VIRT_BASE | 0xa0000)
+
+#define GE1_PHYS_BASE          (LOKI_REGS_PHYS_BASE | 0xb0000)
+#define GE1_VIRT_BASE          (LOKI_REGS_VIRT_BASE | 0xb0000)
+
+#define DDR_VIRT_BASE          (LOKI_REGS_VIRT_BASE | 0xf0000)
+#define DDR_REG(x)             (DDR_VIRT_BASE | (x))
+
+
+#define GPIO_MAX               8
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/memory.h b/include/asm-arm/arch-loki/memory.h
new file mode 100644 (file)
index 0000000..835101e
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * include/asm-arm/arch-loki/memory.h
+ */
+
+#ifndef __ASM_ARCH_MEMORY_H
+#define __ASM_ARCH_MEMORY_H
+
+#define PHYS_OFFSET            UL(0x00000000)
+
+#define __virt_to_bus(x)       __virt_to_phys(x)
+#define __bus_to_virt(x)       __phys_to_virt(x)
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/system.h b/include/asm-arm/arch-loki/system.h
new file mode 100644 (file)
index 0000000..a3568ac
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * include/asm-arm/arch-loki/system.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_SYSTEM_H
+#define __ASM_ARCH_SYSTEM_H
+
+#include <asm/arch/hardware.h>
+#include <asm/arch/loki.h>
+
+static inline void arch_idle(void)
+{
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode)
+{
+       /*
+        * Enable soft reset to assert RSTOUTn.
+        */
+       writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
+
+       /*
+        * Assert soft reset.
+        */
+       writel(SOFT_RESET, SYSTEM_SOFT_RESET);
+
+       while (1)
+               ;
+}
+
+
+#endif
diff --git a/include/asm-arm/arch-loki/timex.h b/include/asm-arm/arch-loki/timex.h
new file mode 100644 (file)
index 0000000..940014f
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * include/asm-arm/arch-loki/timex.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#define CLOCK_TICK_RATE                (100 * HZ)
+
+#define LOKI_TCLK              180000000
diff --git a/include/asm-arm/arch-loki/uncompress.h b/include/asm-arm/arch-loki/uncompress.h
new file mode 100644 (file)
index 0000000..89a0cf8
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * include/asm-arm/arch-loki/uncompress.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/serial_reg.h>
+#include <asm/arch/loki.h>
+
+#define SERIAL_BASE    ((unsigned char *)UART0_PHYS_BASE)
+
+static void putc(const char c)
+{
+       unsigned char *base = SERIAL_BASE;
+       int i;
+
+       for (i = 0; i < 0x1000; i++) {
+               if (base[UART_LSR << 2] & UART_LSR_THRE)
+                       break;
+               barrier();
+       }
+
+       base[UART_TX << 2] = c;
+}
+
+static void flush(void)
+{
+       unsigned char *base = SERIAL_BASE;
+       unsigned char mask;
+       int i;
+
+       mask = UART_LSR_TEMT | UART_LSR_THRE;
+
+       for (i = 0; i < 0x1000; i++) {
+               if ((base[UART_LSR << 2] & mask) == mask)
+                       break;
+               barrier();
+       }
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
diff --git a/include/asm-arm/arch-loki/vmalloc.h b/include/asm-arm/arch-loki/vmalloc.h
new file mode 100644 (file)
index 0000000..f5be062
--- /dev/null
@@ -0,0 +1,5 @@
+/*
+ * include/asm-arm/arch-loki/vmalloc.h
+ */
+
+#define VMALLOC_END    0xfe800000
index 565430c..e62a108 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #ifndef __ASM_ARCH_MSM_IRQS_H
+#define __ASM_ARCH_MSM_IRQS_H
 
 /* MSM ARM11 Interrupt Numbers */
 /* See 80-VE113-1 A, pp219-221     */
index 154b23f..8724487 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #ifndef __ASM_ARCH_MSM_TIMEX_H
+#define __ASM_ARCH_MSM_TIMEX_H
 
 #define CLOCK_TICK_RATE                1000000
 
diff --git a/include/asm-arm/arch-mv78xx0/debug-macro.S b/include/asm-arm/arch-mv78xx0/debug-macro.S
new file mode 100644 (file)
index 0000000..d0595bd
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * include/asm-arm/arch-mv78xx0/debug-macro.S
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <asm/arch/mv78xx0.h>
+
+       .macro  addruart,rx
+       mrc     p15, 0, \rx, c1, c0
+       tst     \rx, #1                                 @ MMU enabled?
+       ldreq   \rx, =MV78XX0_REGS_PHYS_BASE
+       ldrne   \rx, =MV78XX0_REGS_VIRT_BASE
+       orr     \rx, \rx, #0x00012000
+       .endm
+
+#define UART_SHIFT     2
+#include <asm/hardware/debug-8250.S>
diff --git a/include/asm-arm/arch-mv78xx0/dma.h b/include/asm-arm/arch-mv78xx0/dma.h
new file mode 100644 (file)
index 0000000..40a8c17
--- /dev/null
@@ -0,0 +1 @@
+/* empty */
diff --git a/include/asm-arm/arch-mv78xx0/entry-macro.S b/include/asm-arm/arch-mv78xx0/entry-macro.S
new file mode 100644 (file)
index 0000000..e9a606b
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * include/asm-arm/arch-mv78xx0/entry-macro.S
+ *
+ * Low-level IRQ helper macros for Marvell MV78xx0 platforms
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/arch/mv78xx0.h>
+
+       .macro  disable_fiq
+       .endm
+
+       .macro  arch_ret_to_user, tmp1, tmp2
+       .endm
+
+       .macro  get_irqnr_preamble, base, tmp
+       ldr     \base, =IRQ_VIRT_BASE
+       .endm
+
+       .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+       @ check low interrupts
+       ldr     \irqstat, [\base, #IRQ_CAUSE_LOW_OFF]
+       ldr     \tmp, [\base, #IRQ_MASK_LOW_OFF]
+       mov     \irqnr, #31
+       ands    \irqstat, \irqstat, \tmp
+
+       @ if no low interrupts set, check high interrupts
+       ldreq   \irqstat, [\base, #IRQ_CAUSE_HIGH_OFF]
+       ldreq   \tmp, [\base, #IRQ_MASK_HIGH_OFF]
+       moveq   \irqnr, #63
+       andeqs  \irqstat, \irqstat, \tmp
+
+       @ find first active interrupt source
+       clzne   \irqstat, \irqstat
+       subne   \irqnr, \irqnr, \irqstat
+       .endm
diff --git a/include/asm-arm/arch-mv78xx0/hardware.h b/include/asm-arm/arch-mv78xx0/hardware.h
new file mode 100644 (file)
index 0000000..8e17926
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * include/asm-arm/arch-mv78xx0/hardware.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_HARDWARE_H
+#define __ASM_ARCH_HARDWARE_H
+
+#include "mv78xx0.h"
+
+#define pcibios_assign_all_busses()    1
+
+#define PCIBIOS_MIN_IO                 0x00001000
+#define PCIBIOS_MIN_MEM                        0x01000000
+#define PCIMEM_BASE                    MV78XX0_PCIE_MEM_PHYS_BASE /* mem base for VGA */
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/io.h b/include/asm-arm/arch-mv78xx0/io.h
new file mode 100644 (file)
index 0000000..415d4c9
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * include/asm-arm/arch-mv78xx0/io.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IO_H
+#define __ASM_ARCH_IO_H
+
+#include "mv78xx0.h"
+
+#define IO_SPACE_LIMIT         0xffffffff
+
+static inline void __iomem *__io(unsigned long addr)
+{
+       return (void __iomem *)((addr - MV78XX0_PCIE_IO_PHYS_BASE(0))
+                                       + MV78XX0_PCIE_IO_VIRT_BASE(0));
+}
+
+#define __io(a)                        __io(a)
+#define __mem_pci(a)           (a)
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/irqs.h b/include/asm-arm/arch-mv78xx0/irqs.h
new file mode 100644 (file)
index 0000000..7593045
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * include/asm-arm/arch-mv78xx0/irqs.h
+ *
+ * IRQ definitions for Marvell MV78xx0 SoCs
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_IRQS_H
+#define __ASM_ARCH_IRQS_H
+
+#include "mv78xx0.h"   /* need GPIO_MAX */
+
+/*
+ * MV78xx0 Low Interrupt Controller
+ */
+#define IRQ_MV78XX0_ERR                0
+#define IRQ_MV78XX0_SPI                1
+#define IRQ_MV78XX0_I2C_0      2
+#define IRQ_MV78XX0_I2C_1      3
+#define IRQ_MV78XX0_IDMA_0     4
+#define IRQ_MV78XX0_IDMA_1     5
+#define IRQ_MV78XX0_IDMA_2     6
+#define IRQ_MV78XX0_IDMA_3     7
+#define IRQ_MV78XX0_TIMER_0    8
+#define IRQ_MV78XX0_TIMER_1    9
+#define IRQ_MV78XX0_TIMER_2    10
+#define IRQ_MV78XX0_TIMER_3    11
+#define IRQ_MV78XX0_UART_0     12
+#define IRQ_MV78XX0_UART_1     13
+#define IRQ_MV78XX0_UART_2     14
+#define IRQ_MV78XX0_UART_3     15
+#define IRQ_MV78XX0_USB_0      16
+#define IRQ_MV78XX0_USB_1      17
+#define IRQ_MV78XX0_USB_2      18
+#define IRQ_MV78XX0_CRYPTO     19
+#define IRQ_MV78XX0_SDIO_0     20
+#define IRQ_MV78XX0_SDIO_1     21
+#define IRQ_MV78XX0_XOR_0      22
+#define IRQ_MV78XX0_XOR_1      23
+#define IRQ_MV78XX0_I2S_0      24
+#define IRQ_MV78XX0_I2S_1      25
+#define IRQ_MV78XX0_SATA       26
+#define IRQ_MV78XX0_TDMI       27
+
+/*
+ * MV78xx0 High Interrupt Controller
+ */
+#define IRQ_MV78XX0_PCIE_00    32
+#define IRQ_MV78XX0_PCIE_01    33
+#define IRQ_MV78XX0_PCIE_02    34
+#define IRQ_MV78XX0_PCIE_03    35
+#define IRQ_MV78XX0_PCIE_10    36
+#define IRQ_MV78XX0_PCIE_11    37
+#define IRQ_MV78XX0_PCIE_12    38
+#define IRQ_MV78XX0_PCIE_13    39
+#define IRQ_MV78XX0_GE00_SUM   40
+#define IRQ_MV78XX0_GE00_RX    41
+#define IRQ_MV78XX0_GE00_TX    42
+#define IRQ_MV78XX0_GE00_MISC  43
+#define IRQ_MV78XX0_GE01_SUM   44
+#define IRQ_MV78XX0_GE01_RX    45
+#define IRQ_MV78XX0_GE01_TX    46
+#define IRQ_MV78XX0_GE01_MISC  47
+#define IRQ_MV78XX0_GE10_SUM   48
+#define IRQ_MV78XX0_GE10_RX    49
+#define IRQ_MV78XX0_GE10_TX    50
+#define IRQ_MV78XX0_GE10_MISC  51
+#define IRQ_MV78XX0_GE11_SUM   52
+#define IRQ_MV78XX0_GE11_RX    53
+#define IRQ_MV78XX0_GE11_TX    54
+#define IRQ_MV78XX0_GE11_MISC  55
+#define IRQ_MV78XX0_GPIO_0_7   56
+#define IRQ_MV78XX0_GPIO_8_15  57
+#define IRQ_MV78XX0_GPIO_16_23 58
+#define IRQ_MV78XX0_GPIO_24_31 59
+#define IRQ_MV78XX0_DB_IN      60
+#define IRQ_MV78XX0_DB_OUT     61
+
+/*
+ * MV78XX0 General Purpose Pins
+ */
+#define IRQ_MV78XX0_GPIO_START 64
+#define NR_GPIO_IRQS           GPIO_MAX
+
+#define NR_IRQS                        (IRQ_MV78XX0_GPIO_START + NR_GPIO_IRQS)
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/memory.h b/include/asm-arm/arch-mv78xx0/memory.h
new file mode 100644 (file)
index 0000000..721a6b1
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * include/asm-arm/arch-mv78xx0/memory.h
+ */
+
+#ifndef __ASM_ARCH_MEMORY_H
+#define __ASM_ARCH_MEMORY_H
+
+#define PHYS_OFFSET            UL(0x00000000)
+
+#define __virt_to_bus(x)       __virt_to_phys(x)
+#define __bus_to_virt(x)       __phys_to_virt(x)
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/mv78xx0.h b/include/asm-arm/arch-mv78xx0/mv78xx0.h
new file mode 100644 (file)
index 0000000..9f5d83c
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * include/asm-arm/arch-mv78xx0/mv78xx0.h
+ *
+ * Generic definitions for Marvell MV78xx0 SoC flavors:
+ *  MV781x0 and MV782x0.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_MV78XX0_H
+#define __ASM_ARCH_MV78XX0_H
+
+/*
+ * Marvell MV78xx0 address maps.
+ *
+ * phys
+ * c0000000    PCIe Memory space
+ * f0800000    PCIe #0 I/O space
+ * f0900000    PCIe #1 I/O space
+ * f0a00000    PCIe #2 I/O space
+ * f0b00000    PCIe #3 I/O space
+ * f0c00000    PCIe #4 I/O space
+ * f0d00000    PCIe #5 I/O space
+ * f0e00000    PCIe #6 I/O space
+ * f0f00000    PCIe #7 I/O space
+ * f1000000    on-chip peripheral registers
+ *
+ * virt                phys            size
+ * fe400000    f102x000        16K     core-specific peripheral registers
+ * fe700000    f0800000        1M      PCIe #0 I/O space
+ * fe800000    f0900000        1M      PCIe #1 I/O space
+ * fe900000    f0a00000        1M      PCIe #2 I/O space
+ * fea00000    f0b00000        1M      PCIe #3 I/O space
+ * feb00000    f0c00000        1M      PCIe #4 I/O space
+ * fec00000    f0d00000        1M      PCIe #5 I/O space
+ * fed00000    f0e00000        1M      PCIe #6 I/O space
+ * fee00000    f0f00000        1M      PCIe #7 I/O space
+ * fef00000    f1000000        1M      on-chip peripheral registers
+ */
+#define MV78XX0_CORE0_REGS_PHYS_BASE   0xf1020000
+#define MV78XX0_CORE1_REGS_PHYS_BASE   0xf1024000
+#define MV78XX0_CORE_REGS_VIRT_BASE    0xfe400000
+#define MV78XX0_CORE_REGS_SIZE         SZ_16K
+
+#define MV78XX0_PCIE_IO_PHYS_BASE(i)   (0xf0800000 + ((i) << 20))
+#define MV78XX0_PCIE_IO_VIRT_BASE(i)   (0xfe700000 + ((i) << 20))
+#define MV78XX0_PCIE_IO_SIZE           SZ_1M
+
+#define MV78XX0_REGS_PHYS_BASE         0xf1000000
+#define MV78XX0_REGS_VIRT_BASE         0xfef00000
+#define MV78XX0_REGS_SIZE              SZ_1M
+
+#define MV78XX0_PCIE_MEM_PHYS_BASE     0xc0000000
+#define MV78XX0_PCIE_MEM_SIZE          0x30000000
+
+/*
+ * Core-specific peripheral registers.
+ */
+#define BRIDGE_VIRT_BASE       (MV78XX0_CORE_REGS_VIRT_BASE)
+#define  CPU_CONTROL           (BRIDGE_VIRT_BASE | 0x0104)
+#define   L2_WRITETHROUGH      0x00020000
+#define  RSTOUTn_MASK          (BRIDGE_VIRT_BASE | 0x0108)
+#define   SOFT_RESET_OUT_EN    0x00000004
+#define  SYSTEM_SOFT_RESET     (BRIDGE_VIRT_BASE | 0x010c)
+#define   SOFT_RESET           0x00000001
+#define  BRIDGE_CAUSE          (BRIDGE_VIRT_BASE | 0x0110)
+#define  BRIDGE_MASK           (BRIDGE_VIRT_BASE | 0x0114)
+#define   BRIDGE_INT_TIMER0    0x0002
+#define   BRIDGE_INT_TIMER1    0x0004
+#define   BRIDGE_INT_TIMER1_CLR        (~0x0004)
+#define  IRQ_VIRT_BASE         (BRIDGE_VIRT_BASE | 0x0200)
+#define   IRQ_CAUSE_LOW_OFF    0x0004
+#define   IRQ_CAUSE_HIGH_OFF   0x0008
+#define   IRQ_MASK_LOW_OFF     0x0010
+#define   IRQ_MASK_HIGH_OFF    0x0014
+#define  TIMER_VIRT_BASE       (BRIDGE_VIRT_BASE | 0x0300)
+
+/*
+ * Register Map
+ */
+#define DDR_VIRT_BASE          (MV78XX0_REGS_VIRT_BASE | 0x00000)
+#define  DDR_WINDOW_CPU0_BASE  (DDR_VIRT_BASE | 0x1500)
+#define  DDR_WINDOW_CPU1_BASE  (DDR_VIRT_BASE | 0x1700)
+
+#define DEV_BUS_PHYS_BASE      (MV78XX0_REGS_PHYS_BASE | 0x10000)
+#define DEV_BUS_VIRT_BASE      (MV78XX0_REGS_VIRT_BASE | 0x10000)
+#define  SAMPLE_AT_RESET_LOW   (DEV_BUS_VIRT_BASE | 0x0030)
+#define  SAMPLE_AT_RESET_HIGH  (DEV_BUS_VIRT_BASE | 0x0034)
+#define  UART0_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2000)
+#define  UART0_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2000)
+#define  UART1_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2100)
+#define  UART1_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2100)
+#define  UART2_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2200)
+#define  UART2_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2200)
+#define  UART3_PHYS_BASE       (DEV_BUS_PHYS_BASE | 0x2300)
+#define  UART3_VIRT_BASE       (DEV_BUS_VIRT_BASE | 0x2300)
+
+#define GE10_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x30000)
+#define GE11_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x34000)
+
+#define PCIE00_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x40000)
+#define PCIE01_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x44000)
+#define PCIE02_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x48000)
+#define PCIE03_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x4c000)
+
+#define USB0_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x50000)
+#define USB1_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x51000)
+#define USB2_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x52000)
+
+#define GE00_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x70000)
+#define GE01_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0x74000)
+
+#define PCIE10_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x80000)
+#define PCIE11_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x84000)
+#define PCIE12_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x88000)
+#define PCIE13_VIRT_BASE       (MV78XX0_REGS_VIRT_BASE | 0x8c000)
+
+#define SATA_PHYS_BASE         (MV78XX0_REGS_PHYS_BASE | 0xa0000)
+
+
+#define GPIO_MAX               32
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/system.h b/include/asm-arm/arch-mv78xx0/system.h
new file mode 100644 (file)
index 0000000..7eb47d3
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * include/asm-arm/arch-mv78xx0/system.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARCH_SYSTEM_H
+#define __ASM_ARCH_SYSTEM_H
+
+#include <asm/arch/hardware.h>
+#include <asm/arch/mv78xx0.h>
+
+static inline void arch_idle(void)
+{
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode)
+{
+       /*
+        * Enable soft reset to assert RSTOUTn.
+        */
+       writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
+
+       /*
+        * Assert soft reset.
+        */
+       writel(SOFT_RESET, SYSTEM_SOFT_RESET);
+
+       while (1)
+               ;
+}
+
+
+#endif
diff --git a/include/asm-arm/arch-mv78xx0/timex.h b/include/asm-arm/arch-mv78xx0/timex.h
new file mode 100644 (file)
index 0000000..a854b1c
--- /dev/null
@@ -0,0 +1,9 @@
+/*
+ * include/asm-arm/arch-mv78xx0/timex.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#define CLOCK_TICK_RATE                (100 * HZ)
diff --git a/include/asm-arm/arch-mv78xx0/uncompress.h b/include/asm-arm/arch-mv78xx0/uncompress.h
new file mode 100644 (file)
index 0000000..3bfe0a2
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * include/asm-arm/arch-mv78xx0/uncompress.h
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/serial_reg.h>
+#include <asm/arch/mv78xx0.h>
+
+#define SERIAL_BASE    ((unsigned char *)UART0_PHYS_BASE)
+
+static void putc(const char c)
+{
+       unsigned char *base = SERIAL_BASE;
+       int i;
+
+       for (i = 0; i < 0x1000; i++) {
+               if (base[UART_LSR << 2] & UART_LSR_THRE)
+                       break;
+               barrier();
+       }
+
+       base[UART_TX << 2] = c;
+}
+
+static void flush(void)
+{
+       unsigned char *base = SERIAL_BASE;
+       unsigned char mask;
+       int i;
+
+       mask = UART_LSR_TEMT | UART_LSR_THRE;
+
+       for (i = 0; i < 0x1000; i++) {
+               if ((base[UART_LSR << 2] & mask) == mask)
+                       break;
+               barrier();
+       }
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
diff --git a/include/asm-arm/arch-mv78xx0/vmalloc.h b/include/asm-arm/arch-mv78xx0/vmalloc.h
new file mode 100644 (file)
index 0000000..f2c5121
--- /dev/null
@@ -0,0 +1,5 @@
+/*
+ * include/asm-arm/arch-mv78xx0/vmalloc.h
+ */
+
+#define VMALLOC_END    0xfe000000
diff --git a/include/asm-arm/arch-mxc/board-mx27ads.h b/include/asm-arm/arch-mxc/board-mx27ads.h
new file mode 100644 (file)
index 0000000..61e66da
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __ASM_ARCH_MXC_BOARD_MX27ADS_H__
+#define __ASM_ARCH_MXC_BOARD_MX27ADS_H__
+
+/* external interrupt multiplexer */
+#define MXC_EXP_IO_BASE                (MXC_GPIO_BASE + MXC_MAX_GPIO_LINES)
+
+#define MXC_VIRTUAL_INTS_BASE  (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES)
+#define MXC_SDIO1_CARD_IRQ     MXC_VIRTUAL_INTS_BASE
+#define MXC_SDIO2_CARD_IRQ     (MXC_VIRTUAL_INTS_BASE + 1)
+#define MXC_SDIO3_CARD_IRQ     (MXC_VIRTUAL_INTS_BASE + 2)
+
+#define MXC_MAX_BOARD_INTS      (MXC_MAX_EXP_IO_LINES + \
+                               MXC_MAX_VIRTUAL_INTS)
+
+/*
+ * MXC UART EVB board level configurations
+ */
+
+#define MXC_LL_EXTUART_PADDR   (CS4_BASE_ADDR + 0x20000)
+#define MXC_LL_EXTUART_VADDR   (CS4_BASE_ADDR_VIRT + 0x20000)
+#define MXC_LL_EXTUART_16BIT_BUS
+
+#define MXC_LL_UART_PADDR       UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR       AIPI_IO_ADDRESS(UART1_BASE_ADDR)
+
+/*
+ * @name Memory Size parameters
+ */
+
+/*
+ * Size of SDRAM memory
+ */
+#define SDRAM_MEM_SIZE          SZ_128M
+
+/*
+ * PBC Controller parameters
+ */
+
+/*
+ * Base address of PBC controller, CS4
+ */
+#define PBC_BASE_ADDRESS        0xEB000000
+#define PBC_REG_ADDR(offset)    (PBC_BASE_ADDRESS + (offset))
+
+/*
+ * PBC Interupt name definitions
+ */
+#define PBC_GPIO1_0  0
+#define PBC_GPIO1_1  1
+#define PBC_GPIO1_2  2
+#define PBC_GPIO1_3  3
+#define PBC_GPIO1_4  4
+#define PBC_GPIO1_5  5
+
+#define PBC_INTR_MAX_NUM 6
+#define PBC_INTR_SHARED_MAX_NUM 8
+
+/* When the PBC address connection is fixed in h/w, defined as 1 */
+#define PBC_ADDR_SH             0
+
+/* Offsets for the PBC Controller register */
+/*
+ * PBC Board version register offset
+ */
+#define PBC_VERSION_REG         PBC_REG_ADDR(0x00000 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 1 set address.
+ */
+#define PBC_BCTRL1_SET_REG      PBC_REG_ADDR(0x00008 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 1 clear address.
+ */
+#define PBC_BCTRL1_CLEAR_REG    PBC_REG_ADDR(0x0000C >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 2 set address.
+ */
+#define PBC_BCTRL2_SET_REG      PBC_REG_ADDR(0x00010 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 2 clear address.
+ */
+#define PBC_BCTRL2_CLEAR_REG    PBC_REG_ADDR(0x00014 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 3 set address.
+ */
+#define PBC_BCTRL3_SET_REG      PBC_REG_ADDR(0x00018 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 3 clear address.
+ */
+#define PBC_BCTRL3_CLEAR_REG    PBC_REG_ADDR(0x0001C >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 3 set address.
+ */
+#define PBC_BCTRL4_SET_REG      PBC_REG_ADDR(0x00020 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 4 clear address.
+ */
+#define PBC_BCTRL4_CLEAR_REG    PBC_REG_ADDR(0x00024 >> PBC_ADDR_SH)
+/*PBC_ADDR_SH
+ * PBC Board status register 1.
+ */
+#define PBC_BSTAT1_REG          PBC_REG_ADDR(0x00028 >> PBC_ADDR_SH)
+/*
+ * PBC Board interrupt status register.
+ */
+#define PBC_INTSTATUS_REG       PBC_REG_ADDR(0x0002C >> PBC_ADDR_SH)
+/*
+ * PBC Board interrupt current status register.
+ */
+#define PBC_INTCURR_STATUS_REG  PBC_REG_ADDR(0x00034 >> PBC_ADDR_SH)
+/*
+ * PBC Interrupt mask register set address.
+ */
+#define PBC_INTMASK_SET_REG     PBC_REG_ADDR(0x00038 >> PBC_ADDR_SH)
+/*
+ * PBC Interrupt mask register clear address.
+ */
+#define PBC_INTMASK_CLEAR_REG   PBC_REG_ADDR(0x0003C >> PBC_ADDR_SH)
+/*
+ * External UART A.
+ */
+#define PBC_SC16C652_UARTA_REG  PBC_REG_ADDR(0x20000 >> PBC_ADDR_SH)
+/*
+ * UART 4 Expanding Signal Status.
+ */
+#define PBC_UART_STATUS_REG     PBC_REG_ADDR(0x22000 >> PBC_ADDR_SH)
+/*
+ * UART 4 Expanding Signal Control Set.
+ */
+#define PBC_UCTRL_SET_REG       PBC_REG_ADDR(0x24000 >> PBC_ADDR_SH)
+/*
+ * UART 4 Expanding Signal Control Clear.
+ */
+#define PBC_UCTRL_CLR_REG       PBC_REG_ADDR(0x26000 >> PBC_ADDR_SH)
+/*
+ * Ethernet Controller IO base address.
+ */
+#define PBC_CS8900A_IOBASE_REG  PBC_REG_ADDR(0x40000 >> PBC_ADDR_SH)
+/*
+ * Ethernet Controller Memory base address.
+ */
+#define PBC_CS8900A_MEMBASE_REG PBC_REG_ADDR(0x42000 >> PBC_ADDR_SH)
+/*
+ * Ethernet Controller DMA base address.
+ */
+#define PBC_CS8900A_DMABASE_REG PBC_REG_ADDR(0x44000 >> PBC_ADDR_SH)
+
+/* PBC Board Version Register bit definition */
+#define PBC_VERSION_ADS         0x8000 /* Bit15=1 means version for ads */
+#define PBC_VERSION_EVB_REVB    0x4000 /* BIT14=1 means version for evb revb */
+
+/* PBC Board Control Register 1 bit definitions */
+#define PBC_BCTRL1_ERST         0x0001 /* Ethernet Reset */
+#define PBC_BCTRL1_URST         0x0002 /* Reset External UART controller */
+#define PBC_BCTRL1_FRST         0x0004 /* FEC Reset */
+#define PBC_BCTRL1_ESLEEP       0x0010 /* Enable ethernet Sleep */
+#define PBC_BCTRL1_LCDON        0x0800 /* Enable the LCD */
+
+/* PBC Board Control Register 2 bit definitions */
+#define PBC_BCTRL2_VCC_EN       0x0004 /*   Enable VCC */
+#define PBC_BCTRL2_VPP_EN       0x0008 /*   Enable Vpp */
+#define PBC_BCTRL2_ATAFEC_EN    0X0010
+#define PBC_BCTRL2_ATAFEC_SEL   0X0020
+#define PBC_BCTRL2_ATA_EN       0X0040
+#define PBC_BCTRL2_IRDA_SD      0X0080
+#define PBC_BCTRL2_IRDA_EN      0X0100
+#define PBC_BCTRL2_CCTL10       0X0200
+#define PBC_BCTRL2_CCTL11       0X0400
+
+/* PBC Board Control Register 3 bit definitions */
+#define PBC_BCTRL3_HSH_EN       0X0020
+#define PBC_BCTRL3_FSH_MOD      0X0040
+#define PBC_BCTRL3_OTG_HS_EN    0X0080
+#define PBC_BCTRL3_OTG_VBUS_EN  0X0100
+#define PBC_BCTRL3_FSH_VBUS_EN  0X0200
+#define PBC_BCTRL3_USB_OTG_ON   0X0800
+#define PBC_BCTRL3_USB_FSH_ON   0X1000
+
+/* PBC Board Control Register 4 bit definitions */
+#define PBC_BCTRL4_REGEN_SEL    0X0001
+#define PBC_BCTRL4_USER_OFF     0X0002
+#define PBC_BCTRL4_VIB_EN       0X0004
+#define PBC_BCTRL4_PWRGT1_EN    0X0008
+#define PBC_BCTRL4_PWRGT2_EN    0X0010
+#define PBC_BCTRL4_STDBY_PRI    0X0020
+
+#ifndef __ASSEMBLY__
+/*
+ * Enumerations for SD cards and memory stick card. This corresponds to
+ * the card EN bits in the IMR: SD1_EN | MS_EN | SD3_EN | SD2_EN.
+ */
+enum mxc_card_no {
+       MXC_CARD_SD2 = 0,
+       MXC_CARD_SD3,
+       MXC_CARD_MS,
+       MXC_CARD_SD1,
+       MXC_CARD_MIN = MXC_CARD_SD2,
+       MXC_CARD_MAX = MXC_CARD_SD1,
+};
+#endif
+
+#define MXC_CPLD_VER_1_50       0x01
+
+/*
+ * PBC BSTAT Register bit definitions
+ */
+#define PBC_BSTAT_PRI_INT       0X0001
+#define PBC_BSTAT_USB_BYP       0X0002
+#define PBC_BSTAT_ATA_IOCS16    0X0004
+#define PBC_BSTAT_ATA_CBLID     0X0008
+#define PBC_BSTAT_ATA_DASP      0X0010
+#define PBC_BSTAT_PWR_RDY       0X0020
+#define PBC_BSTAT_SD3_WP        0X0100
+#define PBC_BSTAT_SD2_WP        0X0200
+#define PBC_BSTAT_SD1_WP        0X0400
+#define PBC_BSTAT_SD3_DET       0X0800
+#define PBC_BSTAT_SD2_DET       0X1000
+#define PBC_BSTAT_SD1_DET       0X2000
+#define PBC_BSTAT_MS_DET        0X4000
+#define PBC_BSTAT_SD3_DET_BIT   11
+#define PBC_BSTAT_SD2_DET_BIT   12
+#define PBC_BSTAT_SD1_DET_BIT   13
+#define PBC_BSTAT_MS_DET_BIT    14
+#define MXC_BSTAT_BIT(n)        ((n == MXC_CARD_SD2) ? PBC_BSTAT_SD2_DET : \
+                                ((n == MXC_CARD_SD3) ? PBC_BSTAT_SD3_DET : \
+                                ((n == MXC_CARD_SD1) ? PBC_BSTAT_SD1_DET : \
+                                ((n == MXC_CARD_MS) ? PBC_BSTAT_MS_DET : \
+                                       0x0))))
+
+/*
+ * PBC UART Control Register bit definitions
+ */
+#define PBC_UCTRL_DCE_DCD       0X0001
+#define PBC_UCTRL_DCE_DSR       0X0002
+#define PBC_UCTRL_DCE_RI        0X0004
+#define PBC_UCTRL_DTE_DTR       0X0100
+
+/*
+ * PBC UART Status Register bit definitions
+ */
+#define PBC_USTAT_DTE_DCD       0X0001
+#define PBC_USTAT_DTE_DSR       0X0002
+#define PBC_USTAT_DTE_RI        0X0004
+#define PBC_USTAT_DCE_DTR       0X0100
+
+/*
+ * PBC Interupt mask register bit definitions
+ */
+#define PBC_INTR_SD3_R_EN_BIT   4
+#define PBC_INTR_SD2_R_EN_BIT   0
+#define PBC_INTR_SD1_R_EN_BIT   6
+#define PBC_INTR_MS_R_EN_BIT    5
+#define PBC_INTR_SD3_EN_BIT     13
+#define PBC_INTR_SD2_EN_BIT     12
+#define PBC_INTR_MS_EN_BIT      14
+#define PBC_INTR_SD1_EN_BIT     15
+
+#define PBC_INTR_SD2_R_EN       0x0001
+#define PBC_INTR_LOW_BAT        0X0002
+#define PBC_INTR_OTG_FSOVER     0X0004
+#define PBC_INTR_FSH_OVER       0X0008
+#define PBC_INTR_SD3_R_EN       0x0010
+#define PBC_INTR_MS_R_EN        0x0020
+#define PBC_INTR_SD1_R_EN       0x0040
+#define PBC_INTR_FEC_INT        0X0080
+#define PBC_INTR_ENET_INT       0X0100
+#define PBC_INTR_OTGFS_INT      0X0200
+#define PBC_INTR_XUART_INT      0X0400
+#define PBC_INTR_CCTL12         0X0800
+#define PBC_INTR_SD2_EN         0x1000
+#define PBC_INTR_SD3_EN         0x2000
+#define PBC_INTR_MS_EN          0x4000
+#define PBC_INTR_SD1_EN         0x8000
+
+
+
+/* For interrupts like xuart, enet etc */
+#define EXPIO_PARENT_INT        IOMUX_TO_IRQ(MX27_PIN_TIN)
+#define MXC_MAX_EXP_IO_LINES    16
+
+/*
+ * This corresponds to PBC_INTMASK_SET_REG at offset 0x38.
+ *
+ */
+#define EXPIO_INT_LOW_BAT       (MXC_EXP_IO_BASE + 1)
+#define EXPIO_INT_OTG_FS_OVR    (MXC_EXP_IO_BASE + 2)
+#define EXPIO_INT_FSH_OVR       (MXC_EXP_IO_BASE + 3)
+#define EXPIO_INT_RES4          (MXC_EXP_IO_BASE + 4)
+#define EXPIO_INT_RES5          (MXC_EXP_IO_BASE + 5)
+#define EXPIO_INT_RES6          (MXC_EXP_IO_BASE + 6)
+#define EXPIO_INT_FEC           (MXC_EXP_IO_BASE + 7)
+#define EXPIO_INT_ENET_INT      (MXC_EXP_IO_BASE + 8)
+#define EXPIO_INT_OTG_FS_INT    (MXC_EXP_IO_BASE + 9)
+#define EXPIO_INT_XUART_INTA    (MXC_EXP_IO_BASE + 10)
+#define EXPIO_INT_CCTL12_INT    (MXC_EXP_IO_BASE + 11)
+#define EXPIO_INT_SD2_EN        (MXC_EXP_IO_BASE + 12)
+#define EXPIO_INT_SD3_EN        (MXC_EXP_IO_BASE + 13)
+#define EXPIO_INT_MS_EN         (MXC_EXP_IO_BASE + 14)
+#define EXPIO_INT_SD1_EN        (MXC_EXP_IO_BASE + 15)
+
+/*
+ * This is System IRQ used by CS8900A for interrupt generation
+ * taken from platform.h
+ */
+#define CS8900AIRQ              EXPIO_INT_ENET_INT
+/* This is I/O Base address used to access registers of CS8900A on MXC ADS */
+#define CS8900A_BASE_ADDRESS    (PBC_CS8900A_IOBASE_REG + 0x300)
+
+#define MXC_PMIC_INT_LINE       IOMUX_TO_IRQ(MX27_PIN_TOUT)
+
+/*
+* This is used to detect if the CPLD version is for mx27 evb board rev-a
+*/
+#define PBC_CPLD_VERSION_IS_REVA() \
+       ((__raw_readw(PBC_VERSION_REG) & \
+       (PBC_VERSION_ADS | PBC_VERSION_EVB_REVB))\
+       == 0)
+
+/* This is used to active or inactive ata signal in CPLD .
+ *  It is dependent with hardware
+ */
+#define PBC_ATA_SIGNAL_ACTIVE() \
+       __raw_writew(           \
+               PBC_BCTRL2_ATAFEC_EN|PBC_BCTRL2_ATAFEC_SEL|PBC_BCTRL2_ATA_EN, \
+               PBC_BCTRL2_CLEAR_REG)
+
+#define PBC_ATA_SIGNAL_INACTIVE() \
+       __raw_writew(  \
+               PBC_BCTRL2_ATAFEC_EN|PBC_BCTRL2_ATAFEC_SEL|PBC_BCTRL2_ATA_EN, \
+               PBC_BCTRL2_SET_REG)
+
+#define MXC_BD_LED1             (1 << 5)
+#define MXC_BD_LED2             (1 << 6)
+#define MXC_BD_LED_ON(led) \
+       __raw_writew(led, PBC_BCTRL1_SET_REG)
+#define MXC_BD_LED_OFF(led) \
+       __raw_writew(led, PBC_BCTRL1_CLEAR_REG)
+
+/* to determine the correct external crystal reference */
+#define CKIH_27MHZ_BIT_SET      (1 << 3)
+
+#endif                         /* __ASM_ARCH_MXC_BOARD_MX27ADS_H__ */
index 8590127..1bc6fb0 100644 (file)
 
 #define MXC_MAX_EXP_IO_LINES   16
 
+/* mandatory for CONFIG_LL_DEBUG */
+
+#define MXC_LL_UART_PADDR      UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR      AIPS1_IO_ADDRESS(UART1_BASE_ADDR)
+
 #endif /* __ASM_ARCH_MXC_BOARD_MX31ADS_H__ */
diff --git a/include/asm-arm/arch-mxc/board-mx31lite.h b/include/asm-arm/arch-mxc/board-mx31lite.h
new file mode 100644 (file)
index 0000000..e4e5cf5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_ARCH_MXC_BOARD_MX31LITE_H__
+#define __ASM_ARCH_MXC_BOARD_MX31LITE_H__
+
+#define MXC_MAX_EXP_IO_LINES   16
+
+
+/*
+ * Memory Size parameters
+ */
+
+/*
+ * Size of SDRAM memory
+ */
+#define SDRAM_MEM_SIZE         SZ_128M
+/*
+ * Size of MBX buffer memory
+ */
+#define MXC_MBX_MEM_SIZE       SZ_16M
+/*
+ * Size of memory available to kernel
+ */
+#define MEM_SIZE               (SDRAM_MEM_SIZE - MXC_MBX_MEM_SIZE)
+
+#define MXC_LL_UART_PADDR      UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR      AIPS1_IO_ADDRESS(UART1_BASE_ADDR)
+
+#endif /* __ASM_ARCH_MXC_BOARD_MX31ADS_H__ */
+
diff --git a/include/asm-arm/arch-mxc/board-pcm037.h b/include/asm-arm/arch-mxc/board-pcm037.h
new file mode 100644 (file)
index 0000000..82232ba
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (C) 2008 Sascha Hauer, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __ASM_ARCH_MXC_BOARD_PCM037_H__
+#define __ASM_ARCH_MXC_BOARD_PCM037_H__
+
+/* mandatory for CONFIG_LL_DEBUG */
+
+#define MXC_LL_UART_PADDR      UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR      AIPS1_IO_ADDRESS(UART1_BASE_ADDR)
+
+#endif /* __ASM_ARCH_MXC_BOARD_PCM037_H__ */
diff --git a/include/asm-arm/arch-mxc/board-pcm038.h b/include/asm-arm/arch-mxc/board-pcm038.h
new file mode 100644 (file)
index 0000000..750c62a
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_MXC_BOARD_PCM038_H__
+#define __ASM_ARCH_MXC_BOARD_PCM038_H__
+
+/* mandatory for CONFIG_LL_DEBUG */
+
+#define MXC_LL_UART_PADDR      UART1_BASE_ADDR
+#define MXC_LL_UART_VADDR      (AIPI_BASE_ADDR_VIRT + 0x0A000)
+
+#ifndef __ASSEMBLY__
+/*
+ * This CPU module needs a baseboard to work. After basic initializing
+ * its own devices, it calls baseboard's init function.
+ * TODO: Add your own baseboard init function and call it from
+ * inside pcm038_init().
+ *
+ * This example here is for the development board. Refer pcm970-baseboard.c
+ */
+
+extern void pcm970_baseboard_init(void);
+
+#endif
+
+#endif /* __ASM_ARCH_MXC_BOARD_PCM038_H__ */
diff --git a/include/asm-arm/arch-mxc/clock.h b/include/asm-arm/arch-mxc/clock.h
new file mode 100644 (file)
index 0000000..24caa2b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_MXC_CLOCK_H__
+#define __ASM_ARCH_MXC_CLOCK_H__
+
+#ifndef __ASSEMBLY__
+#include <linux/list.h>
+
+struct module;
+
+struct clk {
+       struct list_head node;
+       struct module *owner;
+       const char *name;
+       int id;
+       /* Source clock this clk depends on */
+       struct clk *parent;
+       /* Secondary clock to enable/disable with this clock */
+       struct clk *secondary;
+       /* Reference count of clock enable/disable */
+       __s8 usecount;
+       /* Register bit position for clock's enable/disable control. */
+       u8 enable_shift;
+       /* Register address for clock's enable/disable control. */
+       u32 enable_reg;
+       u32 flags;
+       /* get the current clock rate (always a fresh value) */
+       unsigned long (*get_rate) (struct clk *);
+       /* Function ptr to set the clock to a new rate. The rate must match a
+          supported rate returned from round_rate. Leave blank if clock is not
+          programmable */
+       int (*set_rate) (struct clk *, unsigned long);
+       /* Function ptr to round the requested clock rate to the nearest
+          supported rate that is less than or equal to the requested rate. */
+       unsigned long (*round_rate) (struct clk *, unsigned long);
+       /* Function ptr to enable the clock. Leave blank if clock can not
+          be gated. */
+       int (*enable) (struct clk *);
+       /* Function ptr to disable the clock. Leave blank if clock can not
+          be gated. */
+       void (*disable) (struct clk *);
+       /* Function ptr to set the parent clock of the clock. */
+       int (*set_parent) (struct clk *, struct clk *);
+};
+
+int clk_register(struct clk *clk);
+void clk_unregister(struct clk *clk);
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ASM_ARCH_MXC_CLOCK_H__ */
index 23b4350..a6d2e24 100644 (file)
 #ifndef __ASM_ARCH_MXC_COMMON_H__
 #define __ASM_ARCH_MXC_COMMON_H__
 
-struct sys_timer;
-
 extern void mxc_map_io(void);
 extern void mxc_init_irq(void);
-extern struct sys_timer mxc_timer;
+extern void mxc_timer_init(const char *clk_timer);
+extern int mxc_clocks_init(unsigned long fref);
+extern int mxc_register_gpios(void);
 
 #endif
diff --git a/include/asm-arm/arch-mxc/debug-macro.S b/include/asm-arm/arch-mxc/debug-macro.S
new file mode 100644 (file)
index 0000000..575087f
--- /dev/null
@@ -0,0 +1,49 @@
+/* linux/include/asm-arm/arch-imx/debug-macro.S
+ *
+ * Debugging macro include header
+ *
+ *  Copyright (C) 1994-1999 Russell King
+ *  Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <asm/arch/hardware.h>
+
+#ifdef CONFIG_MACH_MX31ADS
+#include <asm/arch/board-mx31ads.h>
+#endif
+#ifdef CONFIG_MACH_PCM037
+#include <asm/arch/board-pcm037.h>
+#endif
+#ifdef CONFIG_MACH_MX31LITE
+#include <asm/arch/board-mx31lite.h>
+#endif
+#ifdef CONFIG_MACH_MX27ADS
+#include <asm/arch/board-mx27ads.h>
+#endif
+#ifdef CONFIG_MACH_PCM038
+#include <asm/arch/board-pcm038.h>
+#endif
+               .macro  addruart,rx
+               mrc     p15, 0, \rx, c1, c0
+               tst     \rx, #1                 @ MMU enabled?
+               ldreq   \rx, =MXC_LL_UART_PADDR @ physical
+               ldrne   \rx, =MXC_LL_UART_VADDR @ virtual
+               .endm
+
+               .macro  senduart,rd,rx
+               str     \rd, [\rx, #0x40]       @ TXDATA
+               .endm
+
+               .macro  waituart,rd,rx
+               .endm
+
+               .macro  busyuart,rd,rx
+1002:          ldr     \rd, [\rx, #0x98]       @ SR2
+               tst     \rd, #1 << 3            @ TXDC
+               beq     1002b                   @ wait until transmit done
+               .endm
diff --git a/include/asm-arm/arch-mxc/gpio.h b/include/asm-arm/arch-mxc/gpio.h
new file mode 100644 (file)
index 0000000..d393e15
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_MXC_GPIO_H__
+#define __ASM_ARCH_MXC_GPIO_H__
+
+#include <asm/hardware.h>
+#include <asm-generic/gpio.h>
+
+/* use gpiolib dispatchers */
+#define gpio_get_value         __gpio_get_value
+#define gpio_set_value         __gpio_set_value
+#define gpio_cansleep          __gpio_cansleep
+
+#define gpio_to_irq(gpio)      (MXC_MAX_INT_LINES + (gpio))
+#define irq_to_gpio(irq)       ((irq) - MXC_MAX_INT_LINES)
+
+struct mxc_gpio_port {
+       void __iomem *base;
+       int irq;
+       int virtual_irq_start;
+       struct gpio_chip chip;
+};
+
+int mxc_gpio_init(struct mxc_gpio_port*, int);
+
+#endif
index e87ff06..37cddba 100644 (file)
@@ -1,11 +1,20 @@
 /*
- *  Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
  */
 
 #ifndef __ASM_ARCH_MXC_HARDWARE_H__
 # include <asm/arch/mx31.h>
 #endif
 
-#include <asm/arch/mxc.h>
-
-/*
- * ---------------------------------------------------------------------------
- * Board specific defines
- * ---------------------------------------------------------------------------
- */
-#ifdef CONFIG_MACH_MX31ADS
-# include <asm/arch/board-mx31ads.h>
+#ifdef CONFIG_ARCH_MX2
+# ifdef CONFIG_MACH_MX27
+#  include <asm/arch/mx27.h>
+# endif
 #endif
 
+#include <asm/arch/mxc.h>
+
 #endif /* __ASM_ARCH_MXC_HARDWARE_H__ */
diff --git a/include/asm-arm/arch-mxc/iim.h b/include/asm-arm/arch-mxc/iim.h
new file mode 100644 (file)
index 0000000..315bffa
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_MXC_IIM_H__
+#define __ASM_ARCH_MXC_IIM_H__
+
+/* Register offsets */
+#define MXC_IIMSTAT             0x0000
+#define MXC_IIMSTATM            0x0004
+#define MXC_IIMERR              0x0008
+#define MXC_IIMEMASK            0x000C
+#define MXC_IIMFCTL             0x0010
+#define MXC_IIMUA               0x0014
+#define MXC_IIMLA               0x0018
+#define MXC_IIMSDAT             0x001C
+#define MXC_IIMPREV             0x0020
+#define MXC_IIMSREV             0x0024
+#define MXC_IIMPRG_P            0x0028
+#define MXC_IIMSCS0             0x002C
+#define MXC_IIMSCS1             0x0030
+#define MXC_IIMSCS2             0x0034
+#define MXC_IIMSCS3             0x0038
+#define MXC_IIMFBAC0            0x0800
+#define MXC_IIMJAC              0x0804
+#define MXC_IIMHWV1             0x0808
+#define MXC_IIMHWV2             0x080C
+#define MXC_IIMHAB0             0x0810
+#define MXC_IIMHAB1             0x0814
+/* Definitions for i.MX27 TO2 */
+#define MXC_IIMMAC              0x0814
+#define MXC_IIMPREV_FUSE        0x0818
+#define MXC_IIMSREV_FUSE        0x081C
+#define MXC_IIMSJC_CHALL_0      0x0820
+#define MXC_IIMSJC_CHALL_7      0x083C
+#define MXC_IIMFB0UC17          0x0840
+#define MXC_IIMFB0UC255         0x0BFC
+#define MXC_IIMFBAC1            0x0C00
+/* Definitions for i.MX27 TO2 */
+#define MXC_IIMSUID             0x0C04
+#define MXC_IIMKEY0             0x0C04
+#define MXC_IIMKEY20            0x0C54
+#define MXC_IIMSJC_RESP_0       0x0C58
+#define MXC_IIMSJC_RESP_7       0x0C74
+#define MXC_IIMFB1UC30          0x0C78
+#define MXC_IIMFB1UC255         0x0FFC
+
+/* Bit definitions */
+
+#define MXC_IIMHWV1_WLOCK               (0x1 << 7)
+#define MXC_IIMHWV1_MCU_ENDIAN          (0x1 << 6)
+#define MXC_IIMHWV1_DSP_ENDIAN          (0x1 << 5)
+#define MXC_IIMHWV1_BOOT_INT            (0x1 << 4)
+#define MXC_IIMHWV1_SCC_DISABLE         (0x1 << 3)
+#define MXC_IIMHWV1_HANTRO_DISABLE      (0x1 << 2)
+#define MXC_IIMHWV1_MEMSTICK_DIS        (0x1 << 1)
+
+#define MXC_IIMHWV2_WLOCK               (0x1 << 7)
+#define MXC_IIMHWV2_BP_SDMA             (0x1 << 6)
+#define MXC_IIMHWV2_SCM_DCM             (0x1 << 5)
+
+#endif /* __ASM_ARCH_MXC_IIM_H__ */
diff --git a/include/asm-arm/arch-mxc/imx-uart.h b/include/asm-arm/arch-mxc/imx-uart.h
new file mode 100644 (file)
index 0000000..83fb72c
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef ASMARM_ARCH_UART_H
+#define ASMARM_ARCH_UART_H
+
+#define IMXUART_HAVE_RTSCTS (1<<0)
+
+struct imxuart_platform_data {
+       int (*init)(struct platform_device *pdev);
+       int (*exit)(struct platform_device *pdev);
+       unsigned int flags;
+};
+
+int __init imx_init_uart(int uart_no, struct imxuart_platform_data *pdata);
+
+#endif
diff --git a/include/asm-arm/arch-mxc/iomux-mx1-mx2.h b/include/asm-arm/arch-mxc/iomux-mx1-mx2.h
new file mode 100644 (file)
index 0000000..076d37b
--- /dev/null
@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef _MXC_GPIO_MX1_MX2_H
+#define _MXC_GPIO_MX1_MX2_H
+
+#include <linux/io.h>
+
+#define MXC_GPIO_ALLOC_MODE_NORMAL     0
+#define MXC_GPIO_ALLOC_MODE_NO_ALLOC   1
+#define MXC_GPIO_ALLOC_MODE_TRY_ALLOC  2
+#define MXC_GPIO_ALLOC_MODE_ALLOC_ONLY 4
+#define MXC_GPIO_ALLOC_MODE_RELEASE    8
+
+/*
+ *  GPIO Module and I/O Multiplexer
+ *  x = 0..3 for reg_A, reg_B, reg_C, reg_D
+ */
+#define VA_GPIO_BASE   IO_ADDRESS(GPIO_BASE_ADDR)
+#define MXC_DDIR(x)    (0x00 + ((x) << 8))
+#define MXC_OCR1(x)    (0x04 + ((x) << 8))
+#define MXC_OCR2(x)    (0x08 + ((x) << 8))
+#define MXC_ICONFA1(x) (0x0c + ((x) << 8))
+#define MXC_ICONFA2(x) (0x10 + ((x) << 8))
+#define MXC_ICONFB1(x) (0x14 + ((x) << 8))
+#define MXC_ICONFB2(x) (0x18 + ((x) << 8))
+#define MXC_DR(x)      (0x1c + ((x) << 8))
+#define MXC_GIUS(x)    (0x20 + ((x) << 8))
+#define MXC_SSR(x)     (0x24 + ((x) << 8))
+#define MXC_ICR1(x)    (0x28 + ((x) << 8))
+#define MXC_ICR2(x)    (0x2c + ((x) << 8))
+#define MXC_IMR(x)     (0x30 + ((x) << 8))
+#define MXC_ISR(x)     (0x34 + ((x) << 8))
+#define MXC_GPR(x)     (0x38 + ((x) << 8))
+#define MXC_SWR(x)     (0x3c + ((x) << 8))
+#define MXC_PUEN(x)    (0x40 + ((x) << 8))
+
+#ifdef CONFIG_ARCH_MX1
+# define GPIO_PORT_MAX  3
+#endif
+#ifdef CONFIG_ARCH_MX2
+# define GPIO_PORT_MAX  5
+#endif
+
+#ifndef GPIO_PORT_MAX
+# error "GPIO config port count unknown!"
+#endif
+
+#define GPIO_PIN_MASK 0x1f
+
+#define GPIO_PORT_SHIFT 5
+#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT)
+
+#define GPIO_PORTA (0 << GPIO_PORT_SHIFT)
+#define GPIO_PORTB (1 << GPIO_PORT_SHIFT)
+#define GPIO_PORTC (2 << GPIO_PORT_SHIFT)
+#define GPIO_PORTD (3 << GPIO_PORT_SHIFT)
+#define GPIO_PORTE (4 << GPIO_PORT_SHIFT)
+#define GPIO_PORTF (5 << GPIO_PORT_SHIFT)
+
+#define GPIO_OUT   (1 << 8)
+#define GPIO_IN    (0 << 8)
+#define GPIO_PUEN  (1 << 9)
+
+#define GPIO_PF    (1 << 10)
+#define GPIO_AF    (1 << 11)
+
+#define GPIO_OCR_SHIFT 12
+#define GPIO_OCR_MASK (3 << GPIO_OCR_SHIFT)
+#define GPIO_AIN   (0 << GPIO_OCR_SHIFT)
+#define GPIO_BIN   (1 << GPIO_OCR_SHIFT)
+#define GPIO_CIN   (2 << GPIO_OCR_SHIFT)
+#define GPIO_GPIO  (3 << GPIO_OCR_SHIFT)
+
+#define GPIO_AOUT_SHIFT 14
+#define GPIO_AOUT_MASK (3 << GPIO_AOUT_SHIFT)
+#define GPIO_AOUT     (0 << GPIO_AOUT_SHIFT)
+#define GPIO_AOUT_ISR (1 << GPIO_AOUT_SHIFT)
+#define GPIO_AOUT_0   (2 << GPIO_AOUT_SHIFT)
+#define GPIO_AOUT_1   (3 << GPIO_AOUT_SHIFT)
+
+#define GPIO_BOUT_SHIFT 16
+#define GPIO_BOUT_MASK (3 << GPIO_BOUT_SHIFT)
+#define GPIO_BOUT      (0 << GPIO_BOUT_SHIFT)
+#define GPIO_BOUT_ISR  (1 << GPIO_BOUT_SHIFT)
+#define GPIO_BOUT_0    (2 << GPIO_BOUT_SHIFT)
+#define GPIO_BOUT_1    (3 << GPIO_BOUT_SHIFT)
+
+extern void mxc_gpio_mode(int gpio_mode);
+extern int mxc_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
+                                       int alloc_mode, const char *label);
+
+/*-------------------------------------------------------------------------*/
+
+/* assignements for GPIO alternate/primary functions */
+
+/* FIXME: This list is not completed. The correct directions are
+ * missing on some (many) pins
+ */
+#ifdef CONFIG_ARCH_MX1
+#define PA0_AIN_SPI2_CLK     (GPIO_GIUS | GPIO_PORTA | GPIO_OUT | 0)
+#define PA0_AF_ETMTRACESYNC  (GPIO_PORTA | GPIO_AF | 0)
+#define PA1_AOUT_SPI2_RXD    (GPIO_GIUS | GPIO_PORTA | GPIO_IN | 1)
+#define PA1_PF_TIN           (GPIO_PORTA | GPIO_PF | 1)
+#define PA2_PF_PWM0          (GPIO_PORTA | GPIO_OUT | GPIO_PF | 2)
+#define PA3_PF_CSI_MCLK      (GPIO_PORTA | GPIO_PF | 3)
+#define PA4_PF_CSI_D0        (GPIO_PORTA | GPIO_PF | 4)
+#define PA5_PF_CSI_D1        (GPIO_PORTA | GPIO_PF | 5)
+#define PA6_PF_CSI_D2        (GPIO_PORTA | GPIO_PF | 6)
+#define PA7_PF_CSI_D3        (GPIO_PORTA | GPIO_PF | 7)
+#define PA8_PF_CSI_D4        (GPIO_PORTA | GPIO_PF | 8)
+#define PA9_PF_CSI_D5        (GPIO_PORTA | GPIO_PF | 9)
+#define PA10_PF_CSI_D6       (GPIO_PORTA | GPIO_PF | 10)
+#define PA11_PF_CSI_D7       (GPIO_PORTA | GPIO_PF | 11)
+#define PA12_PF_CSI_VSYNC    (GPIO_PORTA | GPIO_PF | 12)
+#define PA13_PF_CSI_HSYNC    (GPIO_PORTA | GPIO_PF | 13)
+#define PA14_PF_CSI_PIXCLK   (GPIO_PORTA | GPIO_PF | 14)
+#define PA15_PF_I2C_SDA      (GPIO_PORTA | GPIO_OUT | GPIO_PF | 15)
+#define PA16_PF_I2C_SCL      (GPIO_PORTA | GPIO_OUT | GPIO_PF | 16)
+#define PA17_AF_ETMTRACEPKT4 (GPIO_PORTA | GPIO_AF | 17)
+#define PA17_AIN_SPI2_SS     (GPIO_GIUS | GPIO_PORTA | GPIO_OUT | 17)
+#define PA18_AF_ETMTRACEPKT5 (GPIO_PORTA | GPIO_AF | 18)
+#define PA19_AF_ETMTRACEPKT6 (GPIO_PORTA | GPIO_AF | 19)
+#define PA20_AF_ETMTRACEPKT7 (GPIO_PORTA | GPIO_AF | 20)
+#define PA21_PF_A0           (GPIO_PORTA | GPIO_PF | 21)
+#define PA22_PF_CS4          (GPIO_PORTA | GPIO_PF | 22)
+#define PA23_PF_CS5          (GPIO_PORTA | GPIO_PF | 23)
+#define PA24_PF_A16          (GPIO_PORTA | GPIO_PF | 24)
+#define PA24_AF_ETMTRACEPKT0 (GPIO_PORTA | GPIO_AF | 24)
+#define PA25_PF_A17          (GPIO_PORTA | GPIO_PF | 25)
+#define PA25_AF_ETMTRACEPKT1 (GPIO_PORTA | GPIO_AF | 25)
+#define PA26_PF_A18          (GPIO_PORTA | GPIO_PF | 26)
+#define PA26_AF_ETMTRACEPKT2 (GPIO_PORTA | GPIO_AF | 26)
+#define PA27_PF_A19          (GPIO_PORTA | GPIO_PF | 27)
+#define PA27_AF_ETMTRACEPKT3 (GPIO_PORTA | GPIO_AF | 27)
+#define PA28_PF_A20          (GPIO_PORTA | GPIO_PF | 28)
+#define PA28_AF_ETMPIPESTAT0 (GPIO_PORTA | GPIO_AF | 28)
+#define PA29_PF_A21          (GPIO_PORTA | GPIO_PF | 29)
+#define PA29_AF_ETMPIPESTAT1 (GPIO_PORTA | GPIO_AF | 29)
+#define PA30_PF_A22          (GPIO_PORTA | GPIO_PF | 30)
+#define PA30_AF_ETMPIPESTAT2 (GPIO_PORTA | GPIO_AF | 30)
+#define PA31_PF_A23          (GPIO_PORTA | GPIO_PF | 31)
+#define PA31_AF_ETMTRACECLK  (GPIO_PORTA | GPIO_AF | 31)
+#define PB8_PF_SD_DAT0       (GPIO_PORTB | GPIO_PF | GPIO_PUEN | 8)
+#define PB8_AF_MS_PIO        (GPIO_PORTB | GPIO_AF | 8)
+#define PB9_PF_SD_DAT1       (GPIO_PORTB | GPIO_PF | GPIO_PUEN  | 9)
+#define PB9_AF_MS_PI1        (GPIO_PORTB | GPIO_AF | 9)
+#define PB10_PF_SD_DAT2      (GPIO_PORTB | GPIO_PF | GPIO_PUEN  | 10)
+#define PB10_AF_MS_SCLKI     (GPIO_PORTB | GPIO_AF | 10)
+#define PB11_PF_SD_DAT3      (GPIO_PORTB | GPIO_PF | 11)
+#define PB11_AF_MS_SDIO      (GPIO_PORTB | GPIO_AF | 11)
+#define PB12_PF_SD_CLK       (GPIO_PORTB | GPIO_PF | 12)
+#define PB12_AF_MS_SCLK0     (GPIO_PORTB | GPIO_AF | 12)
+#define PB13_PF_SD_CMD       (GPIO_PORTB | GPIO_PF | GPIO_PUEN | 13)
+#define PB13_AF_MS_BS        (GPIO_PORTB | GPIO_AF | 13)
+#define PB14_AF_SSI_RXFS     (GPIO_PORTB | GPIO_AF | 14)
+#define PB15_AF_SSI_RXCLK    (GPIO_PORTB | GPIO_AF | 15)
+#define PB16_AF_SSI_RXDAT    (GPIO_PORTB | GPIO_IN | GPIO_AF | 16)
+#define PB17_AF_SSI_TXDAT    (GPIO_PORTB | GPIO_OUT | GPIO_AF | 17)
+#define PB18_AF_SSI_TXFS     (GPIO_PORTB | GPIO_AF | 18)
+#define PB19_AF_SSI_TXCLK    (GPIO_PORTB | GPIO_AF | 19)
+#define PB20_PF_USBD_AFE     (GPIO_PORTB | GPIO_PF | 20)
+#define PB21_PF_USBD_OE      (GPIO_PORTB | GPIO_PF | 21)
+#define PB22_PFUSBD_RCV      (GPIO_PORTB | GPIO_PF | 22)
+#define PB23_PF_USBD_SUSPND  (GPIO_PORTB | GPIO_PF | 23)
+#define PB24_PF_USBD_VP      (GPIO_PORTB | GPIO_PF | 24)
+#define PB25_PF_USBD_VM      (GPIO_PORTB | GPIO_PF | 25)
+#define PB26_PF_USBD_VPO     (GPIO_PORTB | GPIO_PF | 26)
+#define PB27_PF_USBD_VMO     (GPIO_PORTB | GPIO_PF | 27)
+#define PB28_PF_UART2_CTS    (GPIO_PORTB | GPIO_OUT | GPIO_PF | 28)
+#define PB29_PF_UART2_RTS    (GPIO_PORTB | GPIO_IN | GPIO_PF | 29)
+#define PB30_PF_UART2_TXD    (GPIO_PORTB | GPIO_OUT | GPIO_PF | 30)
+#define PB31_PF_UART2_RXD    (GPIO_PORTB | GPIO_IN | GPIO_PF | 31)
+#define PC3_PF_SSI_RXFS      (GPIO_PORTC | GPIO_PF | 3)
+#define PC4_PF_SSI_RXCLK     (GPIO_PORTC | GPIO_PF | 4)
+#define PC5_PF_SSI_RXDAT     (GPIO_PORTC | GPIO_IN | GPIO_PF | 5)
+#define PC6_PF_SSI_TXDAT     (GPIO_PORTC | GPIO_OUT | GPIO_PF | 6)
+#define PC7_PF_SSI_TXFS      (GPIO_PORTC | GPIO_PF | 7)
+#define PC8_PF_SSI_TXCLK     (GPIO_PORTC | GPIO_PF | 8)
+#define PC9_PF_UART1_CTS     (GPIO_PORTC | GPIO_OUT | GPIO_PF | 9)
+#define PC10_PF_UART1_RTS    (GPIO_PORTC | GPIO_IN | GPIO_PF | 10)
+#define PC11_PF_UART1_TXD    (GPIO_PORTC | GPIO_OUT | GPIO_PF | 11)
+#define PC12_PF_UART1_RXD    (GPIO_PORTC | GPIO_IN | GPIO_PF | 12)
+#define PC13_PF_SPI1_SPI_RDY (GPIO_PORTC | GPIO_PF | 13)
+#define PC14_PF_SPI1_SCLK    (GPIO_PORTC | GPIO_PF | 14)
+#define PC15_PF_SPI1_SS      (GPIO_PORTC | GPIO_PF | 15)
+#define PC16_PF_SPI1_MISO    (GPIO_PORTC | GPIO_PF | 16)
+#define PC17_PF_SPI1_MOSI    (GPIO_PORTC | GPIO_PF | 17)
+#define PC24_BIN_UART3_RI    (GPIO_GIUS | GPIO_PORTC | GPIO_OUT | GPIO_BIN | 24)
+#define PC25_BIN_UART3_DSR   (GPIO_GIUS | GPIO_PORTC | GPIO_OUT | GPIO_BIN | 25)
+#define PC26_AOUT_UART3_DTR  (GPIO_GIUS | GPIO_PORTC | GPIO_IN | 26)
+#define PC27_BIN_UART3_DCD   (GPIO_GIUS | GPIO_PORTC | GPIO_OUT | GPIO_BIN | 27)
+#define PC28_BIN_UART3_CTS   (GPIO_GIUS | GPIO_PORTC | GPIO_OUT | GPIO_BIN | 28)
+#define PC29_AOUT_UART3_RTS  (GPIO_GIUS | GPIO_PORTC | GPIO_IN | 29)
+#define PC30_BIN_UART3_TX    (GPIO_GIUS | GPIO_PORTC | GPIO_BIN | 30)
+#define PC31_AOUT_UART3_RX   (GPIO_GIUS | GPIO_PORTC | GPIO_IN | 31)
+#define PD6_PF_LSCLK         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 6)
+#define PD7_PF_REV           (GPIO_PORTD | GPIO_PF | 7)
+#define PD7_AF_UART2_DTR     (GPIO_GIUS | GPIO_PORTD | GPIO_IN | GPIO_AF | 7)
+#define PD7_AIN_SPI2_SCLK    (GPIO_GIUS | GPIO_PORTD | GPIO_AIN | 7)
+#define PD8_PF_CLS           (GPIO_PORTD | GPIO_PF | 8)
+#define PD8_AF_UART2_DCD     (GPIO_PORTD | GPIO_OUT | GPIO_AF | 8)
+#define PD8_AIN_SPI2_SS      (GPIO_GIUS | GPIO_PORTD | GPIO_AIN | 8)
+#define PD9_PF_PS            (GPIO_PORTD | GPIO_PF | 9)
+#define PD9_AF_UART2_RI      (GPIO_PORTD | GPIO_OUT | GPIO_AF | 9)
+#define PD9_AOUT_SPI2_RXD    (GPIO_GIUS | GPIO_PORTD | GPIO_IN | 9)
+#define PD10_PF_SPL_SPR      (GPIO_PORTD | GPIO_OUT | GPIO_PF | 10)
+#define PD10_AF_UART2_DSR    (GPIO_PORTD | GPIO_OUT | GPIO_AF | 10)
+#define PD10_AIN_SPI2_TXD    (GPIO_GIUS | GPIO_PORTD | GPIO_OUT | 10)
+#define PD11_PF_CONTRAST     (GPIO_PORTD | GPIO_OUT | GPIO_PF | 11)
+#define PD12_PF_ACD_OE       (GPIO_PORTD | GPIO_OUT | GPIO_PF | 12)
+#define PD13_PF_LP_HSYNC     (GPIO_PORTD | GPIO_OUT | GPIO_PF | 13)
+#define PD14_PF_FLM_VSYNC    (GPIO_PORTD | GPIO_OUT | GPIO_PF | 14)
+#define PD15_PF_LD0          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 15)
+#define PD16_PF_LD1          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 16)
+#define PD17_PF_LD2          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 17)
+#define PD18_PF_LD3          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 18)
+#define PD19_PF_LD4          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 19)
+#define PD20_PF_LD5          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 20)
+#define PD21_PF_LD6          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 21)
+#define PD22_PF_LD7          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 22)
+#define PD23_PF_LD8          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 23)
+#define PD24_PF_LD9          (GPIO_PORTD | GPIO_OUT | GPIO_PF | 24)
+#define PD25_PF_LD10         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 25)
+#define PD26_PF_LD11         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 26)
+#define PD27_PF_LD12         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 27)
+#define PD28_PF_LD13         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 28)
+#define PD29_PF_LD14         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 29)
+#define PD30_PF_LD15         (GPIO_PORTD | GPIO_OUT | GPIO_PF | 30)
+#define PD31_PF_TMR2OUT      (GPIO_PORTD | GPIO_PF | 31)
+#define PD31_BIN_SPI2_TXD    (GPIO_GIUS | GPIO_PORTD | GPIO_BIN | 31)
+#endif
+
+#ifdef CONFIG_ARCH_MX2
+#define PA5_PF_LSCLK           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 5)
+#define PA6_PF_LD0             (GPIO_PORTA | GPIO_OUT | GPIO_PF | 6)
+#define PA7_PF_LD1             (GPIO_PORTA | GPIO_OUT | GPIO_PF | 7)
+#define PA8_PF_LD2             (GPIO_PORTA | GPIO_OUT | GPIO_PF | 8)
+#define PA9_PF_LD3             (GPIO_PORTA | GPIO_OUT | GPIO_PF | 9)
+#define PA10_PF_LD4            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 10)
+#define PA11_PF_LD5            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 11)
+#define PA12_PF_LD6            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 12)
+#define PA13_PF_LD7            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 13)
+#define PA14_PF_LD8            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 14)
+#define PA15_PF_LD9            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 15)
+#define PA16_PF_LD10           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 16)
+#define PA17_PF_LD11           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 17)
+#define PA18_PF_LD12           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 18)
+#define PA19_PF_LD13           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 19)
+#define PA20_PF_LD14           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 20)
+#define PA21_PF_LD15           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 21)
+#define PA22_PF_LD16           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 22)
+#define PA23_PF_LD17           (GPIO_PORTA | GPIO_OUT | GPIO_PF | 23)
+#define PA24_PF_REV            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 24)
+#define PA25_PF_CLS            (GPIO_PORTA | GPIO_OUT | GPIO_PF | 25)
+#define PA26_PF_PS             (GPIO_PORTA | GPIO_OUT | GPIO_PF | 26)
+#define PA27_PF_SPL_SPR                (GPIO_PORTA | GPIO_OUT | GPIO_PF | 27)
+#define PA28_PF_HSYNC          (GPIO_PORTA | GPIO_OUT | GPIO_PF | 28)
+#define PA29_PF_VSYNC          (GPIO_PORTA | GPIO_OUT | GPIO_PF | 29)
+#define PA30_PF_CONTRAST       (GPIO_PORTA | GPIO_OUT | GPIO_PF | 30)
+#define PA31_PF_OE_ACD         (GPIO_PORTA | GPIO_OUT | GPIO_PF | 31)
+#define PB10_PF_CSI_D0         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 10)
+#define PB10_AF_UART6_TXD      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 10)
+#define PB11_PF_CSI_D1         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 11)
+#define PB11_AF_UART6_RXD      (GPIO_PORTB | GPIO_IN  | GPIO_AF | 11)
+#define PB12_PF_CSI_D2         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 12)
+#define PB12_AF_UART6_CTS      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 12)
+#define PB13_PF_CSI_D3         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 13)
+#define PB13_AF_UART6_RTS      (GPIO_PORTB | GPIO_IN  | GPIO_AF | 13)
+#define PB14_PF_CSI_D4         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 14)
+#define PB15_PF_CSI_MCLK       (GPIO_PORTB | GPIO_OUT | GPIO_PF | 15)
+#define PB16_PF_CSI_PIXCLK     (GPIO_PORTB | GPIO_OUT | GPIO_PF | 16)
+#define PB17_PF_CSI_D5         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 17)
+#define PB18_PF_CSI_D6         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 18)
+#define PB18_AF_UART5_TXD      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 18)
+#define PB19_PF_CSI_D7         (GPIO_PORTB | GPIO_OUT | GPIO_PF | 19)
+#define PB19_AF_UART5_RXD      (GPIO_PORTB | GPIO_IN  | GPIO_AF | 19)
+#define PB20_PF_CSI_VSYNC      (GPIO_PORTB | GPIO_OUT | GPIO_PF | 20)
+#define PB20_AF_UART5_CTS      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 20)
+#define PB21_PF_CSI_HSYNC      (GPIO_PORTB | GPIO_OUT | GPIO_PF | 21)
+#define PB21_AF_UART5_RTS      (GPIO_PORTB | GPIO_IN  | GPIO_AF | 21)
+#define PB26_AF_UART4_RTS      (GPIO_PORTB | GPIO_IN  | GPIO_PF | 26)
+#define PB28_AF_UART4_TXD      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 28)
+#define PB29_AF_UART4_CTS      (GPIO_PORTB | GPIO_OUT | GPIO_AF | 29)
+#define PB31_AF_UART4_RXD      (GPIO_PORTB | GPIO_IN  | GPIO_AF | 31)
+#define PC5_PF_I2C2_SDA                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 5)
+#define PC6_PF_I2C2_SCL                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 6)
+#define PC16_PF_SSI4_FS                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 16)
+#define PC17_PF_SSI4_RXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 17)
+#define PC18_PF_SSI4_TXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 18)
+#define PC19_PF_SSI4_CLK       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 19)
+#define PC20_PF_SSI1_FS                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 20)
+#define PC21_PF_SSI1_RXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 21)
+#define PC22_PF_SSI1_TXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 22)
+#define PC23_PF_SSI1_CLK       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 23)
+#define PC24_PF_SSI2_FS                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 24)
+#define PC25_PF_SSI2_RXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 25)
+#define PC26_PF_SSI2_TXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 26)
+#define PC27_PF_SSI2_CLK       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 27)
+#define PC28_PF_SSI3_FS                (GPIO_PORTC | GPIO_IN  | GPIO_PF | 28)
+#define PC29_PF_SSI3_RXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 29)
+#define PC30_PF_SSI3_TXD       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 30)
+#define PC31_PF_SSI3_CLK       (GPIO_PORTC | GPIO_IN  | GPIO_PF | 31)
+#define PD0_AIN_FEC_TXD0       (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 0)
+#define PD1_AIN_FEC_TXD1       (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 1)
+#define PD2_AIN_FEC_TXD2       (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 2)
+#define PD3_AIN_FEC_TXD3       (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 3)
+#define PD4_AOUT_FEC_RX_ER     (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 4)
+#define PD5_AOUT_FEC_RXD1      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 5)
+#define PD6_AOUT_FEC_RXD2      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 6)
+#define PD7_AOUT_FEC_RXD3      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 7)
+#define PD8_AF_FEC_MDIO                (GPIO_PORTD | GPIO_IN | GPIO_AF | 8)
+#define PD9_AIN_FEC_MDC                (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 9)
+#define PD10_AOUT_FEC_CRS      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 10)
+#define PD11_AOUT_FEC_TX_CLK   (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 11)
+#define PD12_AOUT_FEC_RXD0     (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 12)
+#define PD13_AOUT_FEC_RX_DV    (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 13)
+#define PD14_AOUT_FEC_CLR      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 14)
+#define PD15_AOUT_FEC_COL      (GPIO_PORTD | GPIO_IN | GPIO_AOUT | 15)
+#define PD16_AIN_FEC_TX_ER     (GPIO_PORTD | GPIO_OUT | GPIO_AIN | 16)
+#define PD17_PF_I2C_DATA       (GPIO_PORTD | GPIO_OUT | GPIO_PF | 17)
+#define PD18_PF_I2C_CLK                (GPIO_PORTD | GPIO_OUT | GPIO_PF | 18)
+#define PD25_PF_CSPI1_RDY      (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 25)
+#define PD26_PF_CSPI1_SS2      (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 26)
+#define PD27_PF_CSPI1_SS1      (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 27)
+#define PD28_PF_CSPI1_SS0      (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 28)
+#define PD29_PF_CSPI1_SCLK     (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 29)
+#define PD30_PF_CSPI1_MISO     (GPIO_PORTD | GPIO_IN | GPIO_PF  | 30)
+#define PD31_PF_CSPI1_MOSI     (GPIO_PORTD | GPIO_OUT | GPIO_PF  | 31)
+#define PF23_AIN_FEC_TX_EN     (GPIO_PORTF | GPIO_OUT | GPIO_AIN | 23)
+#define PE3_PF_UART2_CTS       (GPIO_PORTE | GPIO_OUT | GPIO_PF | 3)
+#define PE4_PF_UART2_RTS       (GPIO_PORTE | GPIO_IN  | GPIO_PF | 4)
+#define PE6_PF_UART2_TXD       (GPIO_PORTE | GPIO_OUT | GPIO_PF | 6)
+#define PE7_PF_UART2_RXD       (GPIO_PORTE | GPIO_IN  | GPIO_PF | 7)
+#define PE8_PF_UART3_TXD       (GPIO_PORTE | GPIO_OUT | GPIO_PF | 8)
+#define PE9_PF_UART3_RXD       (GPIO_PORTE | GPIO_IN  | GPIO_PF | 9)
+#define PE10_PF_UART3_CTS      (GPIO_PORTE | GPIO_OUT | GPIO_PF | 10)
+#define PE11_PF_UART3_RTS      (GPIO_PORTE | GPIO_IN  | GPIO_PF | 11)
+#define PE12_PF_UART1_TXD      (GPIO_PORTE | GPIO_OUT | GPIO_PF | 12)
+#define PE13_PF_UART1_RXD      (GPIO_PORTE | GPIO_IN  | GPIO_PF | 13)
+#define PE14_PF_UART1_CTS      (GPIO_PORTE | GPIO_OUT | GPIO_PF | 14)
+#define PE15_PF_UART1_RTS      (GPIO_PORTE | GPIO_IN  | GPIO_PF | 15)
+#define PE18_AF_CSPI3_MISO     (GPIO_PORTE | GPIO_IN  | GPIO_AF | 18)
+#define PE21_AF_CSPI3_SS       (GPIO_PORTE | GPIO_OUT | GPIO_AF | 21)
+#define PE22_AF_CSPI3_MOSI     (GPIO_PORTE | GPIO_OUT | GPIO_AF | 22)
+#define PE23_AF_CSPI3_SCLK     (GPIO_PORTE | GPIO_OUT | GPIO_AF | 23)
+#endif
+
+/* decode irq number to use with IMR(x), ISR(x) and friends */
+#define IRQ_TO_REG(irq) ((irq - MXC_MAX_INT_LINES) >> 5)
+
+#define IRQ_GPIOA(x)  (MXC_MAX_INT_LINES + x)
+#define IRQ_GPIOB(x)  (IRQ_GPIOA(32) + x)
+#define IRQ_GPIOC(x)  (IRQ_GPIOB(32) + x)
+#define IRQ_GPIOD(x)  (IRQ_GPIOC(32) + x)
+
+#endif /* _MXC_GPIO_MX1_MX2_H */
diff --git a/include/asm-arm/arch-mxc/iomux-mx3.h b/include/asm-arm/arch-mxc/iomux-mx3.h
new file mode 100644 (file)
index 0000000..7509e76
--- /dev/null
@@ -0,0 +1,501 @@
+/*
+ * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#ifndef __MACH_MX31_IOMUX_H__
+#define __MACH_MX31_IOMUX_H__
+
+#include <linux/types.h>
+
+/*
+ * various IOMUX output functions
+ */
+
+#define        IOMUX_OCONFIG_GPIO (0 << 4)     /* used as GPIO */
+#define        IOMUX_OCONFIG_FUNC (1 << 4)     /* used as function */
+#define        IOMUX_OCONFIG_ALT1 (2 << 4)     /* used as alternate function 1 */
+#define        IOMUX_OCONFIG_ALT2 (3 << 4)     /* used as alternate function 2 */
+#define        IOMUX_OCONFIG_ALT3 (4 << 4)     /* used as alternate function 3 */
+#define        IOMUX_OCONFIG_ALT4 (5 << 4)     /* used as alternate function 4 */
+#define        IOMUX_OCONFIG_ALT5 (6 << 4)     /* used as alternate function 5 */
+#define        IOMUX_OCONFIG_ALT6 (7 << 4)     /* used as alternate function 6 */
+#define        IOMUX_ICONFIG_NONE  0           /* not configured for input */
+#define        IOMUX_ICONFIG_GPIO  1           /* used as GPIO */
+#define        IOMUX_ICONFIG_FUNC  2           /* used as function */
+#define        IOMUX_ICONFIG_ALT1  4           /* used as alternate function 1 */
+#define        IOMUX_ICONFIG_ALT2  8           /* used as alternate function 2 */
+
+#define IOMUX_CONFIG_GPIO (IOMUX_OCONFIG_GPIO | IOMUX_ICONFIG_GPIO)
+#define IOMUX_CONFIG_FUNC (IOMUX_OCONFIG_FUNC | IOMUX_ICONFIG_FUNC)
+#define IOMUX_CONFIG_ALT1 (IOMUX_OCONFIG_ALT1 | IOMUX_ICONFIG_ALT1)
+#define IOMUX_CONFIG_ALT2 (IOMUX_OCONFIG_ALT2 | IOMUX_ICONFIG_ALT2)
+
+/*
+ * various IOMUX pad functions
+ */
+enum iomux_pad_config {
+       PAD_CTL_NOLOOPBACK      = 0x0 << 9,
+       PAD_CTL_LOOPBACK        = 0x1 << 9,
+       PAD_CTL_PKE_NONE        = 0x0 << 8,
+       PAD_CTL_PKE_ENABLE      = 0x1 << 8,
+       PAD_CTL_PUE_KEEPER      = 0x0 << 7,
+       PAD_CTL_PUE_PUD         = 0x1 << 7,
+       PAD_CTL_100K_PD         = 0x0 << 5,
+       PAD_CTL_100K_PU         = 0x1 << 5,
+       PAD_CTL_47K_PU          = 0x2 << 5,
+       PAD_CTL_22K_PU          = 0x3 << 5,
+       PAD_CTL_HYS_CMOS        = 0x0 << 4,
+       PAD_CTL_HYS_SCHMITZ     = 0x1 << 4,
+       PAD_CTL_ODE_CMOS        = 0x0 << 3,
+       PAD_CTL_ODE_OpenDrain   = 0x1 << 3,
+       PAD_CTL_DRV_NORMAL      = 0x0 << 1,
+       PAD_CTL_DRV_HIGH        = 0x1 << 1,
+       PAD_CTL_DRV_MAX         = 0x2 << 1,
+       PAD_CTL_SRE_SLOW        = 0x0 << 0,
+       PAD_CTL_SRE_FAST        = 0x1 << 0
+};
+
+/*
+ * various IOMUX general purpose functions
+ */
+enum iomux_gp_func {
+       MUX_PGP_FIRI                    = 1 << 0,
+       MUX_DDR_MODE                    = 1 << 1,
+       MUX_PGP_CSPI_BB                 = 1 << 2,
+       MUX_PGP_ATA_1                   = 1 << 3,
+       MUX_PGP_ATA_2                   = 1 << 4,
+       MUX_PGP_ATA_3                   = 1 << 5,
+       MUX_PGP_ATA_4                   = 1 << 6,
+       MUX_PGP_ATA_5                   = 1 << 7,
+       MUX_PGP_ATA_6                   = 1 << 8,
+       MUX_PGP_ATA_7                   = 1 << 9,
+       MUX_PGP_ATA_8                   = 1 << 10,
+       MUX_PGP_UH2                     = 1 << 11,
+       MUX_SDCTL_CSD0_SEL              = 1 << 12,
+       MUX_SDCTL_CSD1_SEL              = 1 << 13,
+       MUX_CSPI1_UART3                 = 1 << 14,
+       MUX_EXTDMAREQ2_MBX_SEL          = 1 << 15,
+       MUX_TAMPER_DETECT_EN            = 1 << 16,
+       MUX_PGP_USB_4WIRE               = 1 << 17,
+       MUX_PGB_USB_COMMON              = 1 << 18,
+       MUX_SDHC_MEMSTICK1              = 1 << 19,
+       MUX_SDHC_MEMSTICK2              = 1 << 20,
+       MUX_PGP_SPLL_BYP                = 1 << 21,
+       MUX_PGP_UPLL_BYP                = 1 << 22,
+       MUX_PGP_MSHC1_CLK_SEL           = 1 << 23,
+       MUX_PGP_MSHC2_CLK_SEL           = 1 << 24,
+       MUX_CSPI3_UART5_SEL             = 1 << 25,
+       MUX_PGP_ATA_9                   = 1 << 26,
+       MUX_PGP_USB_SUSPEND             = 1 << 27,
+       MUX_PGP_USB_OTG_LOOPBACK        = 1 << 28,
+       MUX_PGP_USB_HS1_LOOPBACK        = 1 << 29,
+       MUX_PGP_USB_HS2_LOOPBACK        = 1 << 30,
+       MUX_CLKO_DDR_MODE               = 1 << 31,
+};
+
+/*
+ * This function enables/disables the general purpose function for a particular
+ * signal.
+ */
+void iomux_config_gpr(enum iomux_gp_func , bool);
+
+/*
+ * set the mode for a IOMUX pin.
+ */
+int mxc_iomux_mode(unsigned int);
+
+/*
+ * This function enables/disables the general purpose function for a particular
+ * signal.
+ */
+void mxc_iomux_set_gpr(enum iomux_gp_func, bool);
+
+#define IOMUX_PADNUM_MASK      0x1ff
+#define IOMUX_GPIONUM_SHIFT    9
+#define IOMUX_GPIONUM_MASK     (0xff << IOMUX_GPIONUM_SHIFT)
+#define IOMUX_MODE_SHIFT       17
+#define IOMUX_MODE_MASK        (0xff << IOMUX_MODE_SHIFT)
+
+#define IOMUX_PIN(gpionum, padnum) \
+       (((gpionum << IOMUX_GPIONUM_SHIFT) & IOMUX_GPIONUM_MASK) | \
+        (padnum & IOMUX_PADNUM_MASK))
+
+#define IOMUX_MODE(pin, mode) (pin | mode << IOMUX_MODE_SHIFT)
+
+#define IOMUX_TO_GPIO(iomux_pin) \
+       ((iomux_pin & IOMUX_GPIONUM_MASK) >> IOMUX_GPIONUM_SHIFT)
+#define IOMUX_TO_IRQ(iomux_pin) \
+       (((iomux_pin & IOMUX_GPIONUM_MASK) >> IOMUX_GPIONUM_SHIFT) + \
+       MXC_GPIO_INT_BASE)
+
+/*
+ * This enumeration is constructed based on the Section
+ * "sw_pad_ctl & sw_mux_ctl details" of the MX31 IC Spec. Each enumerated
+ * value is constructed based on the rules described above.
+ */
+
+enum iomux_pins {
+       MX31_PIN_TTM_PAD        = IOMUX_PIN(0xff,   0),
+       MX31_PIN_CSPI3_SPI_RDY  = IOMUX_PIN(0xff,   1),
+       MX31_PIN_CSPI3_SCLK     = IOMUX_PIN(0xff,   2),
+       MX31_PIN_CSPI3_MISO     = IOMUX_PIN(0xff,   3),
+       MX31_PIN_CSPI3_MOSI     = IOMUX_PIN(0xff,   4),
+       MX31_PIN_CLKSS          = IOMUX_PIN(0xff,   5),
+       MX31_PIN_CE_CONTROL     = IOMUX_PIN(0xff,   6),
+       MX31_PIN_ATA_RESET_B    = IOMUX_PIN(95,     7),
+       MX31_PIN_ATA_DMACK      = IOMUX_PIN(94,     8),
+       MX31_PIN_ATA_DIOW       = IOMUX_PIN(93,     9),
+       MX31_PIN_ATA_DIOR       = IOMUX_PIN(92,    10),
+       MX31_PIN_ATA_CS1        = IOMUX_PIN(91,    11),
+       MX31_PIN_ATA_CS0        = IOMUX_PIN(90,    12),
+       MX31_PIN_SD1_DATA3      = IOMUX_PIN(63,    13),
+       MX31_PIN_SD1_DATA2      = IOMUX_PIN(62,    14),
+       MX31_PIN_SD1_DATA1      = IOMUX_PIN(61,    15),
+       MX31_PIN_SD1_DATA0      = IOMUX_PIN(60,    16),
+       MX31_PIN_SD1_CLK        = IOMUX_PIN(59,    17),
+       MX31_PIN_SD1_CMD        = IOMUX_PIN(58,    18),
+       MX31_PIN_D3_SPL         = IOMUX_PIN(0xff,  19),
+       MX31_PIN_D3_CLS         = IOMUX_PIN(0xff,  20),
+       MX31_PIN_D3_REV         = IOMUX_PIN(0xff,  21),
+       MX31_PIN_CONTRAST       = IOMUX_PIN(0xff,  22),
+       MX31_PIN_VSYNC3         = IOMUX_PIN(0xff,  23),
+       MX31_PIN_READ           = IOMUX_PIN(0xff,  24),
+       MX31_PIN_WRITE          = IOMUX_PIN(0xff,  25),
+       MX31_PIN_PAR_RS         = IOMUX_PIN(0xff,  26),
+       MX31_PIN_SER_RS         = IOMUX_PIN(89,    27),
+       MX31_PIN_LCS1           = IOMUX_PIN(88,    28),
+       MX31_PIN_LCS0           = IOMUX_PIN(87,    29),
+       MX31_PIN_SD_D_CLK       = IOMUX_PIN(86,    30),
+       MX31_PIN_SD_D_IO        = IOMUX_PIN(85,    31),
+       MX31_PIN_SD_D_I         = IOMUX_PIN(84,    32),
+       MX31_PIN_DRDY0          = IOMUX_PIN(0xff,  33),
+       MX31_PIN_FPSHIFT        = IOMUX_PIN(0xff,  34),
+       MX31_PIN_HSYNC          = IOMUX_PIN(0xff,  35),
+       MX31_PIN_VSYNC0         = IOMUX_PIN(0xff,  36),
+       MX31_PIN_LD17           = IOMUX_PIN(0xff,  37),
+       MX31_PIN_LD16           = IOMUX_PIN(0xff,  38),
+       MX31_PIN_LD15           = IOMUX_PIN(0xff,  39),
+       MX31_PIN_LD14           = IOMUX_PIN(0xff,  40),
+       MX31_PIN_LD13           = IOMUX_PIN(0xff,  41),
+       MX31_PIN_LD12           = IOMUX_PIN(0xff,  42),
+       MX31_PIN_LD11           = IOMUX_PIN(0xff,  43),
+       MX31_PIN_LD10           = IOMUX_PIN(0xff,  44),
+       MX31_PIN_LD9            = IOMUX_PIN(0xff,  45),
+       MX31_PIN_LD8            = IOMUX_PIN(0xff,  46),
+       MX31_PIN_LD7            = IOMUX_PIN(0xff,  47),
+       MX31_PIN_LD6            = IOMUX_PIN(0xff,  48),
+       MX31_PIN_LD5            = IOMUX_PIN(0xff,  49),
+       MX31_PIN_LD4            = IOMUX_PIN(0xff,  50),
+       MX31_PIN_LD3            = IOMUX_PIN(0xff,  51),
+       MX31_PIN_LD2            = IOMUX_PIN(0xff,  52),
+       MX31_PIN_LD1            = IOMUX_PIN(0xff,  53),
+       MX31_PIN_LD0            = IOMUX_PIN(0xff,  54),
+       MX31_PIN_USBH2_DATA1    = IOMUX_PIN(0xff,  55),
+       MX31_PIN_USBH2_DATA0    = IOMUX_PIN(0xff,  56),
+       MX31_PIN_USBH2_NXT      = IOMUX_PIN(0xff,  57),
+       MX31_PIN_USBH2_STP      = IOMUX_PIN(0xff,  58),
+       MX31_PIN_USBH2_DIR      = IOMUX_PIN(0xff,  59),
+       MX31_PIN_USBH2_CLK      = IOMUX_PIN(0xff,  60),
+       MX31_PIN_USBOTG_DATA7   = IOMUX_PIN(0xff,  61),
+       MX31_PIN_USBOTG_DATA6   = IOMUX_PIN(0xff,  62),
+       MX31_PIN_USBOTG_DATA5   = IOMUX_PIN(0xff,  63),
+       MX31_PIN_USBOTG_DATA4   = IOMUX_PIN(0xff,  64),
+       MX31_PIN_USBOTG_DATA3   = IOMUX_PIN(0xff,  65),
+       MX31_PIN_USBOTG_DATA2   = IOMUX_PIN(0xff,  66),
+       MX31_PIN_USBOTG_DATA1   = IOMUX_PIN(0xff,  67),
+       MX31_PIN_USBOTG_DATA0   = IOMUX_PIN(0xff,  68),
+       MX31_PIN_USBOTG_NXT     = IOMUX_PIN(0xff,  69),
+       MX31_PIN_USBOTG_STP     = IOMUX_PIN(0xff,  70),
+       MX31_PIN_USBOTG_DIR     = IOMUX_PIN(0xff,  71),
+       MX31_PIN_USBOTG_CLK     = IOMUX_PIN(0xff,  72),
+       MX31_PIN_USB_BYP        = IOMUX_PIN(31,    73),
+       MX31_PIN_USB_OC         = IOMUX_PIN(30,    74),
+       MX31_PIN_USB_PWR        = IOMUX_PIN(29,    75),
+       MX31_PIN_SJC_MOD        = IOMUX_PIN(0xff,  76),
+       MX31_PIN_DE_B           = IOMUX_PIN(0xff,  77),
+       MX31_PIN_TRSTB          = IOMUX_PIN(0xff,  78),
+       MX31_PIN_TDO            = IOMUX_PIN(0xff,  79),
+       MX31_PIN_TDI            = IOMUX_PIN(0xff,  80),
+       MX31_PIN_TMS            = IOMUX_PIN(0xff,  81),
+       MX31_PIN_TCK            = IOMUX_PIN(0xff,  82),
+       MX31_PIN_RTCK           = IOMUX_PIN(0xff,  83),
+       MX31_PIN_KEY_COL7       = IOMUX_PIN(57,    84),
+       MX31_PIN_KEY_COL6       = IOMUX_PIN(56,    85),
+       MX31_PIN_KEY_COL5       = IOMUX_PIN(55,    86),
+       MX31_PIN_KEY_COL4       = IOMUX_PIN(54,    87),
+       MX31_PIN_KEY_COL3       = IOMUX_PIN(0xff,  88),
+       MX31_PIN_KEY_COL2       = IOMUX_PIN(0xff,  89),
+       MX31_PIN_KEY_COL1       = IOMUX_PIN(0xff,  90),
+       MX31_PIN_KEY_COL0       = IOMUX_PIN(0xff,  91),
+       MX31_PIN_KEY_ROW7       = IOMUX_PIN(53,    92),
+       MX31_PIN_KEY_ROW6       = IOMUX_PIN(52,    93),
+       MX31_PIN_KEY_ROW5       = IOMUX_PIN(51,    94),
+       MX31_PIN_KEY_ROW4       = IOMUX_PIN(50,    95),
+       MX31_PIN_KEY_ROW3       = IOMUX_PIN(0xff,  96),
+       MX31_PIN_KEY_ROW2       = IOMUX_PIN(0xff,  97),
+       MX31_PIN_KEY_ROW1       = IOMUX_PIN(0xff,  98),
+       MX31_PIN_KEY_ROW0       = IOMUX_PIN(0xff,  99),
+       MX31_PIN_BATT_LINE      = IOMUX_PIN(49,   100),
+       MX31_PIN_CTS2           = IOMUX_PIN(0xff, 101),
+       MX31_PIN_RTS2           = IOMUX_PIN(0xff, 102),
+       MX31_PIN_TXD2           = IOMUX_PIN(28,   103),
+       MX31_PIN_RXD2           = IOMUX_PIN(27,   104),
+       MX31_PIN_DTR_DCE2       = IOMUX_PIN(48,   105),
+       MX31_PIN_DCD_DTE1       = IOMUX_PIN(47,   106),
+       MX31_PIN_RI_DTE1        = IOMUX_PIN(46,   107),
+       MX31_PIN_DSR_DTE1       = IOMUX_PIN(45,   108),
+       MX31_PIN_DTR_DTE1       = IOMUX_PIN(44,   109),
+       MX31_PIN_DCD_DCE1       = IOMUX_PIN(43,   110),
+       MX31_PIN_RI_DCE1        = IOMUX_PIN(42,   111),
+       MX31_PIN_DSR_DCE1       = IOMUX_PIN(41,   112),
+       MX31_PIN_DTR_DCE1       = IOMUX_PIN(40,   113),
+       MX31_PIN_CTS1           = IOMUX_PIN(39,   114),
+       MX31_PIN_RTS1           = IOMUX_PIN(38,   115),
+       MX31_PIN_TXD1           = IOMUX_PIN(37,   116),
+       MX31_PIN_RXD1           = IOMUX_PIN(36,   117),
+       MX31_PIN_CSPI2_SPI_RDY  = IOMUX_PIN(0xff, 118),
+       MX31_PIN_CSPI2_SCLK     = IOMUX_PIN(0xff, 119),
+       MX31_PIN_CSPI2_SS2      = IOMUX_PIN(0xff, 120),
+       MX31_PIN_CSPI2_SS1      = IOMUX_PIN(0xff, 121),
+       MX31_PIN_CSPI2_SS0      = IOMUX_PIN(0xff, 122),
+       MX31_PIN_CSPI2_MISO     = IOMUX_PIN(0xff, 123),
+       MX31_PIN_CSPI2_MOSI     = IOMUX_PIN(0xff, 124),
+       MX31_PIN_CSPI1_SPI_RDY  = IOMUX_PIN(0xff, 125),
+       MX31_PIN_CSPI1_SCLK     = IOMUX_PIN(0xff, 126),
+       MX31_PIN_CSPI1_SS2      = IOMUX_PIN(0xff, 127),
+       MX31_PIN_CSPI1_SS1      = IOMUX_PIN(0xff, 128),
+       MX31_PIN_CSPI1_SS0      = IOMUX_PIN(0xff, 129),
+       MX31_PIN_CSPI1_MISO     = IOMUX_PIN(0xff, 130),
+       MX31_PIN_CSPI1_MOSI     = IOMUX_PIN(0xff, 131),
+       MX31_PIN_SFS6           = IOMUX_PIN(26,   132),
+       MX31_PIN_SCK6           = IOMUX_PIN(25,   133),
+       MX31_PIN_SRXD6          = IOMUX_PIN(24,   134),
+       MX31_PIN_STXD6          = IOMUX_PIN(23,   135),
+       MX31_PIN_SFS5           = IOMUX_PIN(0xff, 136),
+       MX31_PIN_SCK5           = IOMUX_PIN(0xff, 137),
+       MX31_PIN_SRXD5          = IOMUX_PIN(22,   138),
+       MX31_PIN_STXD5          = IOMUX_PIN(21,   139),
+       MX31_PIN_SFS4           = IOMUX_PIN(0xff, 140),
+       MX31_PIN_SCK4           = IOMUX_PIN(0xff, 141),
+       MX31_PIN_SRXD4          = IOMUX_PIN(20,   142),
+       MX31_PIN_STXD4          = IOMUX_PIN(19,   143),
+       MX31_PIN_SFS3           = IOMUX_PIN(0xff, 144),
+       MX31_PIN_SCK3           = IOMUX_PIN(0xff, 145),
+       MX31_PIN_SRXD3          = IOMUX_PIN(18,   146),
+       MX31_PIN_STXD3          = IOMUX_PIN(17,   147),
+       MX31_PIN_I2C_DAT        = IOMUX_PIN(0xff, 148),
+       MX31_PIN_I2C_CLK        = IOMUX_PIN(0xff, 149),
+       MX31_PIN_CSI_PIXCLK     = IOMUX_PIN(83,   150),
+       MX31_PIN_CSI_HSYNC      = IOMUX_PIN(82,   151),
+       MX31_PIN_CSI_VSYNC      = IOMUX_PIN(81,   152),
+       MX31_PIN_CSI_MCLK       = IOMUX_PIN(80,   153),
+       MX31_PIN_CSI_D15        = IOMUX_PIN(79,   154),
+       MX31_PIN_CSI_D14        = IOMUX_PIN(78,   155),
+       MX31_PIN_CSI_D13        = IOMUX_PIN(77,   156),
+       MX31_PIN_CSI_D12        = IOMUX_PIN(76,   157),
+       MX31_PIN_CSI_D11        = IOMUX_PIN(75,   158),
+       MX31_PIN_CSI_D10        = IOMUX_PIN(74,   159),
+       MX31_PIN_CSI_D9         = IOMUX_PIN(73,   160),
+       MX31_PIN_CSI_D8         = IOMUX_PIN(72,   161),
+       MX31_PIN_CSI_D7         = IOMUX_PIN(71,   162),
+       MX31_PIN_CSI_D6         = IOMUX_PIN(70,   163),
+       MX31_PIN_CSI_D5         = IOMUX_PIN(69,   164),
+       MX31_PIN_CSI_D4         = IOMUX_PIN(68,   165),
+       MX31_PIN_M_GRANT        = IOMUX_PIN(0xff, 166),
+       MX31_PIN_M_REQUEST      = IOMUX_PIN(0xff, 167),
+       MX31_PIN_PC_POE         = IOMUX_PIN(0xff, 168),
+       MX31_PIN_PC_RW_B        = IOMUX_PIN(0xff, 169),
+       MX31_PIN_IOIS16         = IOMUX_PIN(0xff, 170),
+       MX31_PIN_PC_RST         = IOMUX_PIN(0xff, 171),
+       MX31_PIN_PC_BVD2        = IOMUX_PIN(0xff, 172),
+       MX31_PIN_PC_BVD1        = IOMUX_PIN(0xff, 173),
+       MX31_PIN_PC_VS2         = IOMUX_PIN(0xff, 174),
+       MX31_PIN_PC_VS1         = IOMUX_PIN(0xff, 175),
+       MX31_PIN_PC_PWRON       = IOMUX_PIN(0xff, 176),
+       MX31_PIN_PC_READY       = IOMUX_PIN(0xff, 177),
+       MX31_PIN_PC_WAIT_B      = IOMUX_PIN(0xff, 178),
+       MX31_PIN_PC_CD2_B       = IOMUX_PIN(0xff, 179),
+       MX31_PIN_PC_CD1_B       = IOMUX_PIN(0xff, 180),
+       MX31_PIN_D0             = IOMUX_PIN(0xff, 181),
+       MX31_PIN_D1             = IOMUX_PIN(0xff, 182),
+       MX31_PIN_D2             = IOMUX_PIN(0xff, 183),
+       MX31_PIN_D3             = IOMUX_PIN(0xff, 184),
+       MX31_PIN_D4             = IOMUX_PIN(0xff, 185),
+       MX31_PIN_D5             = IOMUX_PIN(0xff, 186),
+       MX31_PIN_D6             = IOMUX_PIN(0xff, 187),
+       MX31_PIN_D7             = IOMUX_PIN(0xff, 188),
+       MX31_PIN_D8             = IOMUX_PIN(0xff, 189),
+       MX31_PIN_D9             = IOMUX_PIN(0xff, 190),
+       MX31_PIN_D10            = IOMUX_PIN(0xff, 191),
+       MX31_PIN_D11            = IOMUX_PIN(0xff, 192),
+       MX31_PIN_D12            = IOMUX_PIN(0xff, 193),
+       MX31_PIN_D13            = IOMUX_PIN(0xff, 194),
+       MX31_PIN_D14            = IOMUX_PIN(0xff, 195),
+       MX31_PIN_D15            = IOMUX_PIN(0xff, 196),
+       MX31_PIN_NFRB           = IOMUX_PIN(16,   197),
+       MX31_PIN_NFCE_B         = IOMUX_PIN(15,   198),
+       MX31_PIN_NFWP_B         = IOMUX_PIN(14,   199),
+       MX31_PIN_NFCLE          = IOMUX_PIN(13,   200),
+       MX31_PIN_NFALE          = IOMUX_PIN(12,   201),
+       MX31_PIN_NFRE_B         = IOMUX_PIN(11,   202),
+       MX31_PIN_NFWE_B         = IOMUX_PIN(10,   203),
+       MX31_PIN_SDQS3          = IOMUX_PIN(0xff, 204),
+       MX31_PIN_SDQS2          = IOMUX_PIN(0xff, 205),
+       MX31_PIN_SDQS1          = IOMUX_PIN(0xff, 206),
+       MX31_PIN_SDQS0          = IOMUX_PIN(0xff, 207),
+       MX31_PIN_SDCLK_B        = IOMUX_PIN(0xff, 208),
+       MX31_PIN_SDCLK          = IOMUX_PIN(0xff, 209),
+       MX31_PIN_SDCKE1         = IOMUX_PIN(0xff, 210),
+       MX31_PIN_SDCKE0         = IOMUX_PIN(0xff, 211),
+       MX31_PIN_SDWE           = IOMUX_PIN(0xff, 212),
+       MX31_PIN_CAS            = IOMUX_PIN(0xff, 213),
+       MX31_PIN_RAS            = IOMUX_PIN(0xff, 214),
+       MX31_PIN_RW             = IOMUX_PIN(0xff, 215),
+       MX31_PIN_BCLK           = IOMUX_PIN(0xff, 216),
+       MX31_PIN_LBA            = IOMUX_PIN(0xff, 217),
+       MX31_PIN_ECB            = IOMUX_PIN(0xff, 218),
+       MX31_PIN_CS5            = IOMUX_PIN(0xff, 219),
+       MX31_PIN_CS4            = IOMUX_PIN(0xff, 220),
+       MX31_PIN_CS3            = IOMUX_PIN(0xff, 221),
+       MX31_PIN_CS2            = IOMUX_PIN(0xff, 222),
+       MX31_PIN_CS1            = IOMUX_PIN(0xff, 223),
+       MX31_PIN_CS0            = IOMUX_PIN(0xff, 224),
+       MX31_PIN_OE             = IOMUX_PIN(0xff, 225),
+       MX31_PIN_EB1            = IOMUX_PIN(0xff, 226),
+       MX31_PIN_EB0            = IOMUX_PIN(0xff, 227),
+       MX31_PIN_DQM3           = IOMUX_PIN(0xff, 228),
+       MX31_PIN_DQM2           = IOMUX_PIN(0xff, 229),
+       MX31_PIN_DQM1           = IOMUX_PIN(0xff, 230),
+       MX31_PIN_DQM0           = IOMUX_PIN(0xff, 231),
+       MX31_PIN_SD31           = IOMUX_PIN(0xff, 232),
+       MX31_PIN_SD30           = IOMUX_PIN(0xff, 233),
+       MX31_PIN_SD29           = IOMUX_PIN(0xff, 234),
+       MX31_PIN_SD28           = IOMUX_PIN(0xff, 235),
+       MX31_PIN_SD27           = IOMUX_PIN(0xff, 236),
+       MX31_PIN_SD26           = IOMUX_PIN(0xff, 237),
+       MX31_PIN_SD25           = IOMUX_PIN(0xff, 238),
+       MX31_PIN_SD24           = IOMUX_PIN(0xff, 239),
+       MX31_PIN_SD23           = IOMUX_PIN(0xff, 240),
+       MX31_PIN_SD22           = IOMUX_PIN(0xff, 241),
+       MX31_PIN_SD21           = IOMUX_PIN(0xff, 242),
+       MX31_PIN_SD20           = IOMUX_PIN(0xff, 243),
+       MX31_PIN_SD19           = IOMUX_PIN(0xff, 244),
+       MX31_PIN_SD18           = IOMUX_PIN(0xff, 245),
+       MX31_PIN_SD17           = IOMUX_PIN(0xff, 246),
+       MX31_PIN_SD16           = IOMUX_PIN(0xff, 247),
+       MX31_PIN_SD15           = IOMUX_PIN(0xff, 248),
+       MX31_PIN_SD14           = IOMUX_PIN(0xff, 249),
+       MX31_PIN_SD13           = IOMUX_PIN(0xff, 250),
+       MX31_PIN_SD12           = IOMUX_PIN(0xff, 251),
+       MX31_PIN_SD11           = IOMUX_PIN(0xff, 252),
+       MX31_PIN_SD10           = IOMUX_PIN(0xff, 253),
+       MX31_PIN_SD9            = IOMUX_PIN(0xff, 254),
+       MX31_PIN_SD8            = IOMUX_PIN(0xff, 255),
+       MX31_PIN_SD7            = IOMUX_PIN(0xff, 256),
+       MX31_PIN_SD6            = IOMUX_PIN(0xff, 257),
+       MX31_PIN_SD5            = IOMUX_PIN(0xff, 258),
+       MX31_PIN_SD4            = IOMUX_PIN(0xff, 259),
+       MX31_PIN_SD3            = IOMUX_PIN(0xff, 260),
+       MX31_PIN_SD2            = IOMUX_PIN(0xff, 261),
+       MX31_PIN_SD1            = IOMUX_PIN(0xff, 262),
+       MX31_PIN_SD0            = IOMUX_PIN(0xff, 263),
+       MX31_PIN_SDBA0          = IOMUX_PIN(0xff, 264),
+       MX31_PIN_SDBA1          = IOMUX_PIN(0xff, 265),
+       MX31_PIN_A25            = IOMUX_PIN(0xff, 266),
+       MX31_PIN_A24            = IOMUX_PIN(0xff, 267),
+       MX31_PIN_A23            = IOMUX_PIN(0xff, 268),
+       MX31_PIN_A22            = IOMUX_PIN(0xff, 269),
+       MX31_PIN_A21            = IOMUX_PIN(0xff, 270),
+       MX31_PIN_A20            = IOMUX_PIN(0xff, 271),
+       MX31_PIN_A19            = IOMUX_PIN(0xff, 272),
+       MX31_PIN_A18            = IOMUX_PIN(0xff, 273),
+       MX31_PIN_A17            = IOMUX_PIN(0xff, 274),
+       MX31_PIN_A16            = IOMUX_PIN(0xff, 275),
+       MX31_PIN_A14            = IOMUX_PIN(0xff, 276),
+       MX31_PIN_A15            = IOMUX_PIN(0xff, 277),
+       MX31_PIN_A13            = IOMUX_PIN(0xff, 278),
+       MX31_PIN_A12            = IOMUX_PIN(0xff, 279),
+       MX31_PIN_A11            = IOMUX_PIN(0xff, 280),
+       MX31_PIN_MA10           = IOMUX_PIN(0xff, 281),
+       MX31_PIN_A10            = IOMUX_PIN(0xff, 282),
+       MX31_PIN_A9             = IOMUX_PIN(0xff, 283),
+       MX31_PIN_A8             = IOMUX_PIN(0xff, 284),
+       MX31_PIN_A7             = IOMUX_PIN(0xff, 285),
+       MX31_PIN_A6             = IOMUX_PIN(0xff, 286),
+       MX31_PIN_A5             = IOMUX_PIN(0xff, 287),
+       MX31_PIN_A4             = IOMUX_PIN(0xff, 288),
+       MX31_PIN_A3             = IOMUX_PIN(0xff, 289),
+       MX31_PIN_A2             = IOMUX_PIN(0xff, 290),
+       MX31_PIN_A1             = IOMUX_PIN(0xff, 291),
+       MX31_PIN_A0             = IOMUX_PIN(0xff, 292),
+       MX31_PIN_VPG1           = IOMUX_PIN(0xff, 293),
+       MX31_PIN_VPG0           = IOMUX_PIN(0xff, 294),
+       MX31_PIN_DVFS1          = IOMUX_PIN(0xff, 295),
+       MX31_PIN_DVFS0          = IOMUX_PIN(0xff, 296),
+       MX31_PIN_VSTBY          = IOMUX_PIN(0xff, 297),
+       MX31_PIN_POWER_FAIL     = IOMUX_PIN(0xff, 298),
+       MX31_PIN_CKIL           = IOMUX_PIN(0xff, 299),
+       MX31_PIN_BOOT_MODE4     = IOMUX_PIN(0xff, 300),
+       MX31_PIN_BOOT_MODE3     = IOMUX_PIN(0xff, 301),
+       MX31_PIN_BOOT_MODE2     = IOMUX_PIN(0xff, 302),
+       MX31_PIN_BOOT_MODE1     = IOMUX_PIN(0xff, 303),
+       MX31_PIN_BOOT_MODE0     = IOMUX_PIN(0xff, 304),
+       MX31_PIN_CLKO           = IOMUX_PIN(0xff, 305),
+       MX31_PIN_POR_B          = IOMUX_PIN(0xff, 306),
+       MX31_PIN_RESET_IN_B     = IOMUX_PIN(0xff, 307),
+       MX31_PIN_CKIH           = IOMUX_PIN(0xff, 308),
+       MX31_PIN_SIMPD0         = IOMUX_PIN(35,   309),
+       MX31_PIN_SRX0           = IOMUX_PIN(34,   310),
+       MX31_PIN_STX0           = IOMUX_PIN(33,   311),
+       MX31_PIN_SVEN0          = IOMUX_PIN(32,   312),
+       MX31_PIN_SRST0          = IOMUX_PIN(67,   313),
+       MX31_PIN_SCLK0          = IOMUX_PIN(66,   314),
+       MX31_PIN_GPIO3_1        = IOMUX_PIN(65,   315),
+       MX31_PIN_GPIO3_0        = IOMUX_PIN(64,   316),
+       MX31_PIN_GPIO1_6        = IOMUX_PIN( 6,   317),
+       MX31_PIN_GPIO1_5        = IOMUX_PIN( 5,   318),
+       MX31_PIN_GPIO1_4        = IOMUX_PIN( 4,   319),
+       MX31_PIN_GPIO1_3        = IOMUX_PIN( 3,   320),
+       MX31_PIN_GPIO1_2        = IOMUX_PIN( 2,   321),
+       MX31_PIN_GPIO1_1        = IOMUX_PIN( 1,   322),
+       MX31_PIN_GPIO1_0        = IOMUX_PIN( 0,   323),
+       MX31_PIN_PWMO           = IOMUX_PIN( 9,   324),
+       MX31_PIN_WATCHDOG_RST   = IOMUX_PIN(0xff, 325),
+       MX31_PIN_COMPARE        = IOMUX_PIN( 8,   326),
+       MX31_PIN_CAPTURE        = IOMUX_PIN( 7,   327),
+};
+
+/*
+ * Convenience values for use with mxc_iomux_mode()
+ *
+ * Format here is MX31_PIN_(pin name)__(function)
+ */
+#define MX31_PIN_CSPI3_MOSI__RXD3      IOMUX_MODE(MX31_PIN_CSPI3_MOSI, IOMUX_CONFIG_ALT1)
+#define MX31_PIN_CSPI3_MISO__TXD3      IOMUX_MODE(MX31_PIN_CSPI3_MISO, IOMUX_CONFIG_ALT1)
+#define MX31_PIN_CTS1__CTS1            IOMUX_MODE(MX31_PIN_CTS1, IOMUX_CONFIG_FUNC)
+#define MX31_PIN_RTS1__RTS1            IOMUX_MODE(MX31_PIN_RTS1, IOMUX_CONFIG_FUNC)
+#define MX31_PIN_TXD1__TXD1            IOMUX_MODE(MX31_PIN_TXD1, IOMUX_CONFIG_FUNC)
+#define MX31_PIN_RXD1__RXD1            IOMUX_MODE(MX31_PIN_RXD1, IOMUX_CONFIG_FUNC)
+
+/*
+ * This function configures the pad value for a IOMUX pin.
+ */
+void mxc_iomux_set_pad(enum iomux_pins, u32);
+
+#endif
+
index b2c5205..f416130 100644 (file)
 
 #include <asm/hardware.h>
 
-#define MXC_IRQ_TO_EXPIO(irq)  ((irq) - MXC_EXP_IO_BASE)
-
-#define MXC_IRQ_TO_GPIO(irq)   ((irq) - MXC_GPIO_INT_BASE)
-#define MXC_GPIO_TO_IRQ(x)     (MXC_GPIO_INT_BASE + x)
-
-/* Number of normal interrupts */
-#define NR_IRQS                (MXC_MAX_INT_LINES + \
-                       MXC_MAX_GPIO_LINES + \
-                       MXC_MAX_VIRTUAL_INTS)
-
-/* Number of fast interrupts */
-#define NR_FIQS                MXC_MAX_INTS
-
 #endif /* __ASM_ARCH_MXC_IRQS_H__ */
diff --git a/include/asm-arm/arch-mxc/mx27.h b/include/asm-arm/arch-mxc/mx27.h
new file mode 100644 (file)
index 0000000..212ecc2
--- /dev/null
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+#ifndef __ASM_ARCH_MXC_MX27_H__
+#define __ASM_ARCH_MXC_MX27_H__
+
+#ifndef __ASM_ARCH_MXC_HARDWARE_H__
+#error "Do not include directly."
+#endif
+
+/* IRAM */
+#define IRAM_BASE_ADDR          0xFFFF4C00     /* internal ram */
+
+/* Register offests */
+#define AIPI_BASE_ADDR          0x10000000
+#define AIPI_BASE_ADDR_VIRT     0xF4000000
+#define AIPI_SIZE               SZ_1M
+
+#define DMA_BASE_ADDR           (AIPI_BASE_ADDR + 0x01000)
+#define WDOG_BASE_ADDR          (AIPI_BASE_ADDR + 0x02000)
+#define GPT1_BASE_ADDR          (AIPI_BASE_ADDR + 0x03000)
+#define GPT2_BASE_ADDR          (AIPI_BASE_ADDR + 0x04000)
+#define GPT3_BASE_ADDR          (AIPI_BASE_ADDR + 0x05000)
+#define PWM_BASE_ADDR           (AIPI_BASE_ADDR + 0x06000)
+#define RTC_BASE_ADDR           (AIPI_BASE_ADDR + 0x07000)
+#define KPP_BASE_ADDR           (AIPI_BASE_ADDR + 0x08000)
+#define OWIRE_BASE_ADDR         (AIPI_BASE_ADDR + 0x09000)
+#define UART1_BASE_ADDR         (AIPI_BASE_ADDR + 0x0A000)
+#define UART2_BASE_ADDR         (AIPI_BASE_ADDR + 0x0B000)
+#define UART3_BASE_ADDR         (AIPI_BASE_ADDR + 0x0C000)
+#define UART4_BASE_ADDR         (AIPI_BASE_ADDR + 0x0D000)
+#define CSPI1_BASE_ADDR         (AIPI_BASE_ADDR + 0x0E000)
+#define CSPI2_BASE_ADDR         (AIPI_BASE_ADDR + 0x0F000)
+#define SSI1_BASE_ADDR          (AIPI_BASE_ADDR + 0x10000)
+#define SSI2_BASE_ADDR          (AIPI_BASE_ADDR + 0x11000)
+#define I2C_BASE_ADDR           (AIPI_BASE_ADDR + 0x12000)
+#define SDHC1_BASE_ADDR         (AIPI_BASE_ADDR + 0x13000)
+#define SDHC2_BASE_ADDR         (AIPI_BASE_ADDR + 0x14000)
+#define GPIO_BASE_ADDR          (AIPI_BASE_ADDR + 0x15000)
+#define AUDMUX_BASE_ADDR        (AIPI_BASE_ADDR + 0x16000)
+
+#define CSPI3_BASE_ADDR         (AIPI_BASE_ADDR + 0x17000)
+#define MSHC_BASE_ADDR          (AIPI_BASE_ADDR + 0x18000)
+#define GPT5_BASE_ADDR          (AIPI_BASE_ADDR + 0x19000)
+#define GPT4_BASE_ADDR          (AIPI_BASE_ADDR + 0x1A000)
+#define UART5_BASE_ADDR         (AIPI_BASE_ADDR + 0x1B000)
+#define UART6_BASE_ADDR         (AIPI_BASE_ADDR + 0x1C000)
+#define I2C2_BASE_ADDR          (AIPI_BASE_ADDR + 0x1D000)
+#define SDHC3_BASE_ADDR         (AIPI_BASE_ADDR + 0x1E000)
+#define GPT6_BASE_ADDR          (AIPI_BASE_ADDR + 0x1F000)
+
+#define LCDC_BASE_ADDR          (AIPI_BASE_ADDR + 0x21000)
+#define SLCDC_BASE_ADDR         (AIPI_BASE_ADDR + 0x22000)
+#define VPU_BASE_ADDR           (AIPI_BASE_ADDR + 0x23000)
+#define USBOTG_BASE_ADDR        (AIPI_BASE_ADDR + 0x24000)
+/* for mx27*/
+#define OTG_BASE_ADDR           USBOTG_BASE_ADDR
+#define SAHARA_BASE_ADDR        (AIPI_BASE_ADDR + 0x25000)
+#define EMMA_BASE_ADDR          (AIPI_BASE_ADDR + 0x26400)
+#define CCM_BASE_ADDR           (AIPI_BASE_ADDR + 0x27000)
+#define SYSCTRL_BASE_ADDR       (AIPI_BASE_ADDR + 0x27800)
+#define IIM_BASE_ADDR           (AIPI_BASE_ADDR + 0x28000)
+
+#define RTIC_BASE_ADDR          (AIPI_BASE_ADDR + 0x2A000)
+#define FEC_BASE_ADDR           (AIPI_BASE_ADDR + 0x2B000)
+#define SCC_BASE_ADDR           (AIPI_BASE_ADDR + 0x2C000)
+#define ETB_BASE_ADDR           (AIPI_BASE_ADDR + 0x3B000)
+#define ETB_RAM_BASE_ADDR       (AIPI_BASE_ADDR + 0x3C000)
+
+#define JAM_BASE_ADDR           (AIPI_BASE_ADDR + 0x3E000)
+#define MAX_BASE_ADDR           (AIPI_BASE_ADDR + 0x3F000)
+
+/* ROMP and AVIC */
+#define ROMP_BASE_ADDR          0x10041000
+
+#define AVIC_BASE_ADDR          0x10040000
+
+#define SAHB1_BASE_ADDR         0x80000000
+#define SAHB1_BASE_ADDR_VIRT    0xF4100000
+#define SAHB1_SIZE              SZ_1M
+
+#define CSI_BASE_ADDR           (SAHB1_BASE_ADDR + 0x0000)
+#define ATA_BASE_ADDR           (SAHB1_BASE_ADDR + 0x1000)
+
+/* NAND, SDRAM, WEIM, M3IF, EMI controllers */
+#define X_MEMC_BASE_ADDR        0xD8000000
+#define X_MEMC_BASE_ADDR_VIRT   0xF4200000
+#define X_MEMC_SIZE             SZ_1M
+
+#define NFC_BASE_ADDR           (X_MEMC_BASE_ADDR)
+#define SDRAMC_BASE_ADDR        (X_MEMC_BASE_ADDR + 0x1000)
+#define WEIM_BASE_ADDR          (X_MEMC_BASE_ADDR + 0x2000)
+#define M3IF_BASE_ADDR          (X_MEMC_BASE_ADDR + 0x3000)
+#define PCMCIA_CTL_BASE_ADDR    (X_MEMC_BASE_ADDR + 0x4000)
+
+/* Memory regions and CS */
+#define SDRAM_BASE_ADDR                0xA0000000
+#define CSD1_BASE_ADDR         0xB0000000
+
+#define CS0_BASE_ADDR           0xC0000000
+#define CS1_BASE_ADDR           0xC8000000
+#define CS2_BASE_ADDR           0xD0000000
+#define CS3_BASE_ADDR           0xD2000000
+#define CS4_BASE_ADDR           0xD4000000
+#define CS5_BASE_ADDR           0xD6000000
+#define PCMCIA_MEM_BASE_ADDR    0xDC000000
+
+/*
+ * This macro defines the physical to virtual address mapping for all the
+ * peripheral modules. It is used by passing in the physical address as x
+ * and returning the virtual address. If the physical address is not mapped,
+ * it returns 0xDEADBEEF
+ */
+#define IO_ADDRESS(x)   \
+       (((x >= AIPI_BASE_ADDR) && (x < (AIPI_BASE_ADDR + AIPI_SIZE))) ? \
+               AIPI_IO_ADDRESS(x) : \
+       ((x >= SAHB1_BASE_ADDR) && (x < (SAHB1_BASE_ADDR + SAHB1_SIZE))) ? \
+               SAHB1_IO_ADDRESS(x) : \
+       ((x >= X_MEMC_BASE_ADDR) && (x < (X_MEMC_BASE_ADDR + X_MEMC_SIZE))) ? \
+               X_MEMC_IO_ADDRESS(x) : 0xDEADBEEF)
+
+/* define the address mapping macros: in physical address order */
+#define AIPI_IO_ADDRESS(x)  \
+       (((x) - AIPI_BASE_ADDR) + AIPI_BASE_ADDR_VIRT)
+
+#define AVIC_IO_ADDRESS(x)     AIPI_IO_ADDRESS(x)
+
+#define SAHB1_IO_ADDRESS(x)  \
+       (((x) - SAHB1_BASE_ADDR) + SAHB1_BASE_ADDR_VIRT)
+
+#define CS4_IO_ADDRESS(x)  \
+       (((x) - CS4_BASE_ADDR) + CS4_BASE_ADDR_VIRT)
+
+#define X_MEMC_IO_ADDRESS(x)  \
+       (((x) - X_MEMC_BASE_ADDR) + X_MEMC_BASE_ADDR_VIRT)
+
+#define PCMCIA_IO_ADDRESS(x) \
+       (((x) - X_MEMC_BASE_ADDR) + X_MEMC_BASE_ADDR_VIRT)
+
+/* fixed interrput numbers */
+#define MXC_INT_CCM            63
+#define MXC_INT_IIM            62
+#define MXC_INT_LCDC           61
+#define MXC_INT_SLCDC          60
+#define MXC_INT_SAHARA         59
+#define MXC_INT_SCC_SCM                58
+#define MXC_INT_SCC_SMN                57
+#define MXC_INT_USB3           56
+#define MXC_INT_USB2           55
+#define MXC_INT_USB1           54
+#define MXC_INT_VPU            53
+#define MXC_INT_EMMAPP         52
+#define MXC_INT_EMMAPRP                51
+#define MXC_INT_FEC            50
+#define MXC_INT_UART5          49
+#define MXC_INT_UART6          48
+#define MXC_INT_DMACH15                47
+#define MXC_INT_DMACH14                46
+#define MXC_INT_DMACH13                45
+#define MXC_INT_DMACH12                44
+#define MXC_INT_DMACH11                43
+#define MXC_INT_DMACH10                42
+#define MXC_INT_DMACH9         41
+#define MXC_INT_DMACH8         40
+#define MXC_INT_DMACH7         39
+#define MXC_INT_DMACH6         38
+#define MXC_INT_DMACH5         37
+#define MXC_INT_DMACH4         36
+#define MXC_INT_DMACH3         35
+#define MXC_INT_DMACH2         34
+#define MXC_INT_DMACH1         33
+#define MXC_INT_DMACH0         32
+#define MXC_INT_CSI            31
+#define MXC_INT_ATA            30
+#define MXC_INT_NANDFC         29
+#define MXC_INT_PCMCIA         28
+#define MXC_INT_WDOG           27
+#define MXC_INT_GPT1           26
+#define MXC_INT_GPT2           25
+#define MXC_INT_GPT3           24
+#define MXC_INT_GPT            INT_GPT1
+#define MXC_INT_PWM            23
+#define MXC_INT_RTC            22
+#define MXC_INT_KPP            21
+#define MXC_INT_UART1          20
+#define MXC_INT_UART2          19
+#define MXC_INT_UART3          18
+#define MXC_INT_UART4          17
+#define MXC_INT_CSPI1          16
+#define MXC_INT_CSPI2          15
+#define MXC_INT_SSI1           14
+#define MXC_INT_SSI2           13
+#define MXC_INT_I2C            12
+#define MXC_INT_SDHC1          11
+#define MXC_INT_SDHC2          10
+#define MXC_INT_SDHC3          9
+#define MXC_INT_GPIO           8
+#define MXC_INT_SDHC           7
+#define MXC_INT_CSPI3          6
+#define MXC_INT_RTIC           5
+#define MXC_INT_GPT4           4
+#define MXC_INT_GPT5           3
+#define MXC_INT_GPT6           2
+#define MXC_INT_I2C2           1
+
+/* fixed DMA request numbers */
+#define DMA_REQ_NFC             37
+#define DMA_REQ_SDHC3           36
+#define DMA_REQ_UART6_RX        35
+#define DMA_REQ_UART6_TX        34
+#define DMA_REQ_UART5_RX        33
+#define DMA_REQ_UART5_TX        32
+#define DMA_REQ_CSI_RX          31
+#define DMA_REQ_CSI_STAT        30
+#define DMA_REQ_ATA_RCV         29
+#define DMA_REQ_ATA_TX          28
+#define DMA_REQ_UART1_TX        27
+#define DMA_REQ_UART1_RX        26
+#define DMA_REQ_UART2_TX        25
+#define DMA_REQ_UART2_RX        24
+#define DMA_REQ_UART3_TX        23
+#define DMA_REQ_UART3_RX        22
+#define DMA_REQ_UART4_TX        21
+#define DMA_REQ_UART4_RX        20
+#define DMA_REQ_CSPI1_TX        19
+#define DMA_REQ_CSPI1_RX        18
+#define DMA_REQ_CSPI2_TX        17
+#define DMA_REQ_CSPI2_RX        16
+#define DMA_REQ_SSI1_TX1        15
+#define DMA_REQ_SSI1_RX1        14
+#define DMA_REQ_SSI1_TX0        13
+#define DMA_REQ_SSI1_RX0        12
+#define DMA_REQ_SSI2_TX1        11
+#define DMA_REQ_SSI2_RX1        10
+#define DMA_REQ_SSI2_TX0        9
+#define DMA_REQ_SSI2_RX0        8
+#define DMA_REQ_SDHC1           7
+#define DMA_REQ_SDHC2           6
+#define DMA_REQ_MSHC            4
+#define DMA_REQ_EXT             3
+#define DMA_REQ_CSPI3_TX        2
+#define DMA_REQ_CSPI3_RX        1
+
+/* silicon revisions specific to i.MX27 */
+#define CHIP_REV_1_0           0x00
+#define CHIP_REV_2_0           0x01
+
+#ifndef __ASSEMBLY__
+extern int mx27_revision(void);
+#endif
+
+/* gpio and gpio based interrupt handling */
+#define GPIO_DR                        0x1C
+#define GPIO_GDIR              0x00
+#define GPIO_PSR               0x24
+#define GPIO_ICR1              0x28
+#define GPIO_ICR2              0x2C
+#define GPIO_IMR               0x30
+#define GPIO_ISR               0x34
+#define GPIO_INT_LOW_LEV       0x3
+#define GPIO_INT_HIGH_LEV      0x2
+#define GPIO_INT_RISE_EDGE     0x0
+#define GPIO_INT_FALL_EDGE     0x1
+#define GPIO_INT_NONE          0x4
+
+/* Mandatory defines used globally */
+
+/* this is an i.MX27 CPU */
+#define cpu_is_mx27()          (1)
+
+/* this CPU supports up to 192 GPIOs (don't forget the baseboard!) */
+#define ARCH_NR_GPIOS          (192 + 16)
+
+/* OS clock tick rate */
+#define CLOCK_TICK_RATE         13300000
+
+/* Start of RAM */
+#define PHYS_OFFSET            SDRAM_BASE_ADDR
+
+/* max interrupt lines count */
+#define NR_IRQS                        256
+
+/* count of internal interrupt sources */
+#define MXC_MAX_INT_LINES      64
+
+#endif /* __ASM_ARCH_MXC_MX27_H__ */
index 36a1af4..a7373e4 100644 (file)
 #define MXC_MAX_GPIO_LINES      (GPIO_NUM_PIN * GPIO_PORT_NUM)
 #define MXC_MAX_VIRTUAL_INTS   16
 
+#define NR_IRQS (MXC_MAX_INT_LINES + MXC_MAX_GPIO_LINES + MXC_MAX_VIRTUAL_INTS)
+
 /*!
  * Number of GPIO port as defined in the IC Spec
  */
 #define SYSTEM_REV_MIN         CHIP_REV_1_0
 #define SYSTEM_REV_NUM         3
 
+/* gpio and gpio based interrupt handling */
+#define GPIO_DR                        0x00
+#define GPIO_GDIR              0x04
+#define GPIO_PSR               0x08
+#define GPIO_ICR1              0x0C
+#define GPIO_ICR2              0x10
+#define GPIO_IMR               0x14
+#define GPIO_ISR               0x18
+#define GPIO_INT_LOW_LEV       0x0
+#define GPIO_INT_HIGH_LEV      0x1
+#define GPIO_INT_RISE_EDGE     0x2
+#define GPIO_INT_FALL_EDGE     0x3
+#define GPIO_INT_NONE          0x4
+
+/* Mandatory defines used globally */
+
+/* this CPU supports up to 96 GPIOs */
+#define ARCH_NR_GPIOS          96
+
 #if !defined(__ASSEMBLY__) && !defined(__MXC_BOOT_UNCOMPRESS)
 
 /* this is a i.MX31 CPU */
index 146d3f6..332eda4 100644 (file)
@@ -1,11 +1,20 @@
 /*
  * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
  */
 
 #ifndef __ASM_ARCH_MXC_H__
 # define cpu_is_mx31() (0)
 #endif
 
-/*
- *****************************************
- * GPT  Register definitions             *
- *****************************************
- */
-#define MXC_GPT_GPTCR          IO_ADDRESS(GPT1_BASE_ADDR + 0x00)
-#define MXC_GPT_GPTPR          IO_ADDRESS(GPT1_BASE_ADDR + 0x04)
-#define MXC_GPT_GPTSR          IO_ADDRESS(GPT1_BASE_ADDR + 0x08)
-#define MXC_GPT_GPTIR          IO_ADDRESS(GPT1_BASE_ADDR + 0x0C)
-#define MXC_GPT_GPTOCR1                IO_ADDRESS(GPT1_BASE_ADDR + 0x10)
-#define MXC_GPT_GPTOCR2                IO_ADDRESS(GPT1_BASE_ADDR + 0x14)
-#define MXC_GPT_GPTOCR3                IO_ADDRESS(GPT1_BASE_ADDR + 0x18)
-#define MXC_GPT_GPTICR1                IO_ADDRESS(GPT1_BASE_ADDR + 0x1C)
-#define MXC_GPT_GPTICR2                IO_ADDRESS(GPT1_BASE_ADDR + 0x20)
-#define MXC_GPT_GPTCNT         IO_ADDRESS(GPT1_BASE_ADDR + 0x24)
-
-/* GPT Control register bit definitions */
-#define GPTCR_FO3                      (1 << 31)
-#define GPTCR_FO2                      (1 << 30)
-#define GPTCR_FO1                      (1 << 29)
-
-#define GPTCR_OM3_SHIFT                        26
-#define GPTCR_OM3_MASK                 (7 << GPTCR_OM3_SHIFT)
-#define GPTCR_OM3_DISCONNECTED         (0 << GPTCR_OM3_SHIFT)
-#define GPTCR_OM3_TOGGLE               (1 << GPTCR_OM3_SHIFT)
-#define GPTCR_OM3_CLEAR                        (2 << GPTCR_OM3_SHIFT)
-#define GPTCR_OM3_SET                  (3 << GPTCR_OM3_SHIFT)
-#define GPTCR_OM3_GENERATE_LOW         (7 << GPTCR_OM3_SHIFT)
-
-#define GPTCR_OM2_SHIFT                        23
-#define GPTCR_OM2_MASK                 (7 << GPTCR_OM2_SHIFT)
-#define GPTCR_OM2_DISCONNECTED         (0 << GPTCR_OM2_SHIFT)
-#define GPTCR_OM2_TOGGLE               (1 << GPTCR_OM2_SHIFT)
-#define GPTCR_OM2_CLEAR                        (2 << GPTCR_OM2_SHIFT)
-#define GPTCR_OM2_SET                  (3 << GPTCR_OM2_SHIFT)
-#define GPTCR_OM2_GENERATE_LOW         (7 << GPTCR_OM2_SHIFT)
-
-#define GPTCR_OM1_SHIFT                        20
-#define GPTCR_OM1_MASK                 (7 << GPTCR_OM1_SHIFT)
-#define GPTCR_OM1_DISCONNECTED         (0 << GPTCR_OM1_SHIFT)
-#define GPTCR_OM1_TOGGLE               (1 << GPTCR_OM1_SHIFT)
-#define GPTCR_OM1_CLEAR                        (2 << GPTCR_OM1_SHIFT)
-#define GPTCR_OM1_SET                  (3 << GPTCR_OM1_SHIFT)
-#define GPTCR_OM1_GENERATE_LOW         (7 << GPTCR_OM1_SHIFT)
-
-#define GPTCR_IM2_SHIFT                        18
-#define GPTCR_IM2_MASK                 (3 << GPTCR_IM2_SHIFT)
-#define GPTCR_IM2_CAPTURE_DISABLE      (0 << GPTCR_IM2_SHIFT)
-#define GPTCR_IM2_CAPTURE_RISING       (1 << GPTCR_IM2_SHIFT)
-#define GPTCR_IM2_CAPTURE_FALLING      (2 << GPTCR_IM2_SHIFT)
-#define GPTCR_IM2_CAPTURE_BOTH         (3 << GPTCR_IM2_SHIFT)
-
-#define GPTCR_IM1_SHIFT                        16
-#define GPTCR_IM1_MASK                 (3 << GPTCR_IM1_SHIFT)
-#define GPTCR_IM1_CAPTURE_DISABLE      (0 << GPTCR_IM1_SHIFT)
-#define GPTCR_IM1_CAPTURE_RISING       (1 << GPTCR_IM1_SHIFT)
-#define GPTCR_IM1_CAPTURE_FALLING      (2 << GPTCR_IM1_SHIFT)
-#define GPTCR_IM1_CAPTURE_BOTH         (3 << GPTCR_IM1_SHIFT)
-
-#define GPTCR_SWR                      (1 << 15)
-#define GPTCR_FRR                      (1 << 9)
-
-#define GPTCR_CLKSRC_SHIFT             6
-#define GPTCR_CLKSRC_MASK              (7 << GPTCR_CLKSRC_SHIFT)
-#define GPTCR_CLKSRC_NOCLOCK           (0 << GPTCR_CLKSRC_SHIFT)
-#define GPTCR_CLKSRC_HIGHFREQ          (2 << GPTCR_CLKSRC_SHIFT)
-#define GPTCR_CLKSRC_CLKIN             (3 << GPTCR_CLKSRC_SHIFT)
-#define GPTCR_CLKSRC_CLK32K            (7 << GPTCR_CLKSRC_SHIFT)
-
-#define GPTCR_STOPEN                   (1 << 5)
-#define GPTCR_DOZEN                    (1 << 4)
-#define GPTCR_WAITEN                   (1 << 3)
-#define GPTCR_DBGEN                    (1 << 2)
-
-#define GPTCR_ENMOD                    (1 << 1)
-#define GPTCR_ENABLE                   (1 << 0)
-
-#define GPTSR_OF1                      (1 << 0)
-#define GPTSR_OF2                      (1 << 1)
-#define GPTSR_OF3                      (1 << 2)
-#define GPTSR_IF1                      (1 << 3)
-#define GPTSR_IF2                      (1 << 4)
-#define GPTSR_ROV                      (1 << 5)
-
-#define GPTIR_OF1IE                    GPTSR_OF1
-#define GPTIR_OF2IE                    GPTSR_OF2
-#define GPTIR_OF3IE                    GPTSR_OF3
-#define GPTIR_IF1IE                    GPTSR_IF1
-#define GPTIR_IF2IE                    GPTSR_IF2
-#define GPTIR_ROVIE                    GPTSR_ROV
-
-/*
- *****************************************
- * AVIC Registers                        *
- *****************************************
- */
-#define AVIC_BASE              IO_ADDRESS(AVIC_BASE_ADDR)
-#define AVIC_INTCNTL           (AVIC_BASE + 0x00)      /* int control reg */
-#define AVIC_NIMASK            (AVIC_BASE + 0x04)      /* int mask reg */
-#define AVIC_INTENNUM          (AVIC_BASE + 0x08)      /* int enable number reg */
-#define AVIC_INTDISNUM         (AVIC_BASE + 0x0C)      /* int disable number reg */
-#define AVIC_INTENABLEH                (AVIC_BASE + 0x10)      /* int enable reg high */
-#define AVIC_INTENABLEL                (AVIC_BASE + 0x14)      /* int enable reg low */
-#define AVIC_INTTYPEH          (AVIC_BASE + 0x18)      /* int type reg high */
-#define AVIC_INTTYPEL          (AVIC_BASE + 0x1C)      /* int type reg low */
-#define AVIC_NIPRIORITY7       (AVIC_BASE + 0x20)      /* norm int priority lvl7 */
-#define AVIC_NIPRIORITY6       (AVIC_BASE + 0x24)      /* norm int priority lvl6 */
-#define AVIC_NIPRIORITY5       (AVIC_BASE + 0x28)      /* norm int priority lvl5 */
-#define AVIC_NIPRIORITY4       (AVIC_BASE + 0x2C)      /* norm int priority lvl4 */
-#define AVIC_NIPRIORITY3       (AVIC_BASE + 0x30)      /* norm int priority lvl3 */
-#define AVIC_NIPRIORITY2       (AVIC_BASE + 0x34)      /* norm int priority lvl2 */
-#define AVIC_NIPRIORITY1       (AVIC_BASE + 0x38)      /* norm int priority lvl1 */
-#define AVIC_NIPRIORITY0       (AVIC_BASE + 0x3C)      /* norm int priority lvl0 */
-#define AVIC_NIVECSR           (AVIC_BASE + 0x40)      /* norm int vector/status */
-#define AVIC_FIVECSR           (AVIC_BASE + 0x44)      /* fast int vector/status */
-#define AVIC_INTSRCH           (AVIC_BASE + 0x48)      /* int source reg high */
-#define AVIC_INTSRCL           (AVIC_BASE + 0x4C)      /* int source reg low */
-#define AVIC_INTFRCH           (AVIC_BASE + 0x50)      /* int force reg high */
-#define AVIC_INTFRCL           (AVIC_BASE + 0x54)      /* int force reg low */
-#define AVIC_NIPNDH            (AVIC_BASE + 0x58)      /* norm int pending high */
-#define AVIC_NIPNDL            (AVIC_BASE + 0x5C)      /* norm int pending low */
-#define AVIC_FIPNDH            (AVIC_BASE + 0x60)      /* fast int pending high */
-#define AVIC_FIPNDL            (AVIC_BASE + 0x64)      /* fast int pending low */
-
-#define SYSTEM_PREV_REG                IO_ADDRESS(IIM_BASE_ADDR + 0x20)
-#define SYSTEM_SREV_REG                IO_ADDRESS(IIM_BASE_ADDR + 0x24)
-#define IIM_PROD_REV_SH                3
-#define IIM_PROD_REV_LEN       5
+#ifndef CONFIG_MACH_MX27
+# define cpu_is_mx27() (0)
+#endif
 
 #endif /*  __ASM_ARCH_MXC_H__ */
diff --git a/include/asm-arm/arch-mxc/mxc_timer.h b/include/asm-arm/arch-mxc/mxc_timer.h
new file mode 100644 (file)
index 0000000..6cb11f4
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * mxc_timer.h
+ *
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * Platform independent (i.MX1, i.MX2, i.MX3) definition for timer handling.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __PLAT_MXC_TIMER_H
+#define __PLAT_MXC_TIMER_H
+
+#include <linux/clk.h>
+#include <asm/hardware.h>
+
+#ifdef CONFIG_ARCH_IMX
+#define TIMER_BASE             IO_ADDRESS(TIM1_BASE_ADDR)
+#define TIMER_INTERRUPT                TIM1_INT
+
+#define TCTL_VAL               TCTL_CLK_PCLK1
+#define TCTL_IRQEN             (1<<4)
+#define TCTL_FRR               (1<<8)
+#define TCTL_CLK_PCLK1         (1<<1)
+#define TCTL_CLK_PCLK1_4       (2<<1)
+#define TCTL_CLK_TIN           (3<<1)
+#define TCTL_CLK_32            (4<<1)
+
+#define MXC_TCTL   0x00
+#define MXC_TPRER  0x04
+#define MXC_TCMP   0x08
+#define MXC_TCR    0x0c
+#define MXC_TCN    0x10
+#define MXC_TSTAT  0x14
+#define TSTAT_CAPT             (1<<1)
+#define TSTAT_COMP             (1<<0)
+
+static inline void gpt_irq_disable(void)
+{
+       unsigned int tmp;
+
+       tmp = __raw_readl(TIMER_BASE + MXC_TCTL);
+       __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL);
+}
+
+static inline void gpt_irq_enable(void)
+{
+       __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN,
+                               TIMER_BASE + MXC_TCTL);
+}
+
+static void gpt_irq_acknowledge(void)
+{
+       __raw_writel(0, TIMER_BASE + MXC_TSTAT);
+}
+#endif /* CONFIG_ARCH_IMX */
+
+#ifdef CONFIG_ARCH_MX2
+#define TIMER_BASE             IO_ADDRESS(GPT1_BASE_ADDR)
+#define TIMER_INTERRUPT                MXC_INT_GPT1
+
+#define MXC_TCTL   0x00
+#define TCTL_VAL               TCTL_CLK_PCLK1
+#define TCTL_CLK_PCLK1         (1<<1)
+#define TCTL_CLK_PCLK1_4       (2<<1)
+#define TCTL_IRQEN             (1<<4)
+#define TCTL_FRR               (1<<8)
+#define MXC_TPRER  0x04
+#define MXC_TCMP   0x08
+#define MXC_TCR    0x0c
+#define MXC_TCN    0x10
+#define MXC_TSTAT  0x14
+#define TSTAT_CAPT             (1<<1)
+#define TSTAT_COMP             (1<<0)
+
+static inline void gpt_irq_disable(void)
+{
+       unsigned int tmp;
+
+       tmp = __raw_readl(TIMER_BASE + MXC_TCTL);
+       __raw_writel(tmp & ~TCTL_IRQEN, TIMER_BASE + MXC_TCTL);
+}
+
+static inline void gpt_irq_enable(void)
+{
+       __raw_writel(__raw_readl(TIMER_BASE + MXC_TCTL) | TCTL_IRQEN,
+                               TIMER_BASE + MXC_TCTL);
+}
+
+static void gpt_irq_acknowledge(void)
+{
+       __raw_writel(TSTAT_CAPT | TSTAT_COMP, TIMER_BASE + MXC_TSTAT);
+}
+#endif /* CONFIG_ARCH_MX2 */
+
+#ifdef CONFIG_ARCH_MX3
+#define TIMER_BASE             IO_ADDRESS(GPT1_BASE_ADDR)
+#define TIMER_INTERRUPT                MXC_INT_GPT
+
+#define MXC_TCTL   0x00
+#define TCTL_VAL               (TCTL_CLK_IPG | TCTL_WAITEN)
+#define TCTL_CLK_IPG           (1<<6)
+#define TCTL_FRR               (1<<9)
+#define TCTL_WAITEN            (1<<3)
+
+#define MXC_TPRER  0x04
+#define MXC_TSTAT  0x08
+#define TSTAT_OF1              (1<<0)
+#define TSTAT_OF2              (1<<1)
+#define TSTAT_OF3              (1<<2)
+#define TSTAT_IF1              (1<<3)
+#define TSTAT_IF2              (1<<4)
+#define TSTAT_ROV              (1<<5)
+#define MXC_IR     0x0c
+#define MXC_TCMP   0x10
+#define MXC_TCMP2  0x14
+#define MXC_TCMP3  0x18
+#define MXC_TCR    0x1c
+#define MXC_TCN    0x24
+
+static inline void gpt_irq_disable(void)
+{
+       __raw_writel(0, TIMER_BASE + MXC_IR);
+}
+
+static inline void gpt_irq_enable(void)
+{
+       __raw_writel(1<<0, TIMER_BASE + MXC_IR);
+}
+
+static inline void gpt_irq_acknowledge(void)
+{
+       __raw_writel(TSTAT_OF1, TIMER_BASE + MXC_TSTAT);
+}
+#endif /* CONFIG_ARCH_MX3 */
+
+#define TCTL_SWR               (1<<15)
+#define TCTL_CC                        (1<<10)
+#define TCTL_OM                        (1<<9)
+#define TCTL_CAP_RIS           (1<<6)
+#define TCTL_CAP_FAL           (2<<6)
+#define TCTL_CAP_RIS_FAL       (3<<6)
+#define TCTL_CAP_ENA           (1<<5)
+#define TCTL_TEN               (1<<0)
+
+#endif
index 0b7b346..0dca11c 100644 (file)
         __REGGET(var, reg ## _ ## field) / __REGSHIFT(reg ## _ ## field)
 
 #  define REGGETIM_IDX(var, reg, field, idx)                           \
-        __REGGET(var, reg ## _ ## field((idx))) /                      \
+        __REGGET(var, reg ## _ ## field((idx))) /                      \
         __REGSHIFT(reg ## _ ## field((idx)))
 
 #else
 
 #  define __REG(x)     io_p2v(x)
-#  define __REG2(x, y) io_p2v((x) + (y))
+#  define __REG2(x, y) io_p2v((x) + 4 * (y))
 
 #endif
 
index e9c65ce..c7db900 100644 (file)
@@ -36,9 +36,4 @@
 
 #define TWL4030_IRQNUM                 INT_24XX_SYS_NIRQ
 
-/* TWL4030 Primary Interrupt Handler (PIH) interrupts */
-#define IH_TWL4030_BASE                        IH_BOARD_BASE
-#define IH_TWL4030_END                 (IH_TWL4030_BASE+8)
-#define NR_IRQS                                (IH_TWL4030_END)
-
 #endif /* __ASM_ARCH_OMAP_2430SDP_H */
index 0f64044..c5d0f32 100644 (file)
 /* In OMAP1710 H3 the Ethernet is directly connected to CS1 */
 #define OMAP1710_ETHR_START            0x04000300
 
-#define MAXIRQNUM                      (IH_BOARD_BASE)
-#define MAXFIQNUM                      MAXIRQNUM
-#define MAXSWINUM                      MAXIRQNUM
-
-#define NR_IRQS                                (MAXIRQNUM + 1)
-
 extern void h3_mmc_init(void);
 extern void h3_mmc_slot_cover_handler(void *arg, int state);
 
index 56d2c98..9ca03de 100644 (file)
@@ -36,9 +36,6 @@
 #define OMAP1510P1_EMIFS_PRI_VALUE             0x00
 #define OMAP1510P1_EMIFF_PRI_VALUE             0x00
 
-#define NR_FPGA_IRQS           24
-#define NR_IRQS                 (IH_BOARD_BASE + NR_FPGA_IRQS)
-
 #ifndef __ASSEMBLY__
 void fpga_write(unsigned char val, int reg);
 unsigned char fpga_read(int reg);
index eb74420..d7429cb 100644 (file)
 #define OMAP_SDRAM_DEVICE              D256M_1X16_4B
 #endif
 
-#define MAXIRQNUM              IH_BOARD_BASE
-#define MAXFIQNUM              MAXIRQNUM
-#define MAXSWINUM              MAXIRQNUM
-
-#define NR_IRQS                        (MAXIRQNUM + 1)
-
 #endif
index 12a5e4d..4c7b351 100644 (file)
@@ -33,12 +33,24 @@ struct dpll_data {
        void __iomem            *mult_div1_reg;
        u32                     mult_mask;
        u32                     div1_mask;
+       u16                     last_rounded_m;
+       u8                      last_rounded_n;
+       unsigned long           last_rounded_rate;
+       unsigned int            rate_tolerance;
+       u16                     max_multiplier;
+       u8                      max_divider;
+       u32                     max_tolerance;
 #  if defined(CONFIG_ARCH_OMAP3)
+       u8                      modes;
        void __iomem            *control_reg;
        u32                     enable_mask;
        u8                      auto_recal_bit;
        u8                      recal_en_bit;
        u8                      recal_st_bit;
+       void __iomem            *autoidle_reg;
+       u32                     autoidle_mask;
+       void __iomem            *idlest_reg;
+       u8                      idlest_bit;
 #  endif
 };
 
@@ -66,11 +78,14 @@ struct clk {
        void __iomem            *clksel_reg;
        u32                     clksel_mask;
        const struct clksel     *clksel;
-       const struct dpll_data  *dpll_data;
+       struct dpll_data        *dpll_data;
 #else
        __u8                    rate_offset;
        __u8                    src_offset;
 #endif
+#if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS)
+       struct dentry           *dent;  /* For visible tree hierarchy */
+#endif
 };
 
 struct cpufreq_frequency_table;
index 36a3b62..8ac0307 100644 (file)
@@ -47,8 +47,23 @@ static inline int omap_register_i2c_bus(int bus_id, u32 clkrate,
 }
 #endif
 
+/* IO bases for various OMAP processors */
+struct omap_globals {
+       void __iomem    *tap;           /* Control module ID code */
+       void __iomem    *sdrc;          /* SDRAM Controller */
+       void __iomem    *sms;           /* SDRAM Memory Scheduler */
+       void __iomem    *ctrl;          /* System Control Module */
+       void __iomem    *prm;           /* Power and Reset Management */
+       void __iomem    *cm;            /* Clock Management */
+};
+
 void omap2_set_globals_242x(void);
 void omap2_set_globals_243x(void);
 void omap2_set_globals_343x(void);
 
+/* These get called from omap2_set_globals_xxxx(), do not call these */
+void omap2_set_globals_memory(struct omap_globals *);
+void omap2_set_globals_control(struct omap_globals *);
+void omap2_set_globals_prcm(struct omap_globals *);
+
 #endif /* __ARCH_ARM_MACH_OMAP_COMMON_H */
index 59c0686..987553e 100644 (file)
 
 #ifndef __ASSEMBLY__
 #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
-extern void omap_ctrl_base_set(u32 base);
-extern u32 omap_ctrl_base_get(void);
+extern void __iomem *omap_ctrl_base_get(void);
 extern u8 omap_ctrl_readb(u16 offset);
 extern u16 omap_ctrl_readw(u16 offset);
 extern u32 omap_ctrl_readl(u16 offset);
@@ -176,7 +175,6 @@ extern void omap_ctrl_writeb(u8 val, u16 offset);
 extern void omap_ctrl_writew(u16 val, u16 offset);
 extern void omap_ctrl_writel(u32 val, u16 offset);
 #else
-#define omap_ctrl_base_set(x)          WARN_ON(1)
 #define omap_ctrl_base_get()           0
 #define omap_ctrl_readb(x)             0
 #define omap_ctrl_readw(x)             0
index e8a4cf5..52db09f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * OMAP cpu type detection
  *
- * Copyright (C) 2004 Nokia Corporation
+ * Copyright (C) 2004, 2008 Nokia Corporation
  *
  * Written by Tony Lindgren <tony.lindgren@nokia.com>
  *
 #ifndef __ASM_ARCH_OMAP_CPU_H
 #define __ASM_ARCH_OMAP_CPU_H
 
+struct omap_chip_id {
+       u8 oc;
+};
+
+#define OMAP_CHIP_INIT(x)      { .oc = x }
+
 extern unsigned int system_rev;
 
 #define omap2_cpu_rev()                ((system_rev >> 12) & 0x0f)
@@ -345,6 +351,33 @@ IS_OMAP_TYPE(3430, 0x3430)
 #define OMAP2430_REV_ES1_0     0x24300000
 #define OMAP3430_REV_ES1_0     0x34300000
 #define OMAP3430_REV_ES2_0     0x34301000
+#define OMAP3430_REV_ES2_1     0x34302000
+#define OMAP3430_REV_ES2_2     0x34303000
+
+/*
+ * omap_chip bits
+ *
+ * CHIP_IS_OMAP{2420,2430,3430} indicate that a particular structure is
+ * valid on all chips of that type.  CHIP_IS_OMAP3430ES{1,2} indicates
+ * something that is only valid on that particular ES revision.
+ *
+ * These bits may be ORed together to indicate structures that are
+ * available on multiple chip types.
+ *
+ * To test whether a particular structure matches the current OMAP chip type,
+ * use omap_chip_is().
+ *
+ */
+#define CHIP_IS_OMAP2420       (1 << 0)
+#define CHIP_IS_OMAP2430       (1 << 1)
+#define CHIP_IS_OMAP3430       (1 << 2)
+#define CHIP_IS_OMAP3430ES1    (1 << 3)
+#define CHIP_IS_OMAP3430ES2    (1 << 4)
+
+#define CHIP_IS_OMAP24XX       (CHIP_IS_OMAP2420 | CHIP_IS_OMAP2430)
+
+int omap_chip_is(struct omap_chip_id oci);
+
 
 /*
  * Macro to detect device type i.e. EMU/HS/TST/GP/BAD
@@ -362,6 +395,8 @@ IS_OMAP_TYPE(3430, 0x3430)
 #define is_device_type_gp()    (get_device_type() == DEVICE_TYPE_GP)
 #define is_device_type_bad()   (get_device_type() == DEVICE_TYPE_BAD)
 
-#endif
+void omap2_check_revision(void);
+
+#endif    /* defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) */
 
 #endif
index 24acf09..f4dcb95 100644 (file)
 #define __ASM_ARCH_DMA_H
 
 /* Hardware registers for omap1 */
-#define OMAP_DMA_BASE                  (0xfffed800)
-#define OMAP_DMA_GCR                   (OMAP_DMA_BASE + 0x400)
-#define OMAP_DMA_GSCR                  (OMAP_DMA_BASE + 0x404)
-#define OMAP_DMA_GRST                  (OMAP_DMA_BASE + 0x408)
-#define OMAP_DMA_HW_ID                 (OMAP_DMA_BASE + 0x442)
-#define OMAP_DMA_PCH2_ID               (OMAP_DMA_BASE + 0x444)
-#define OMAP_DMA_PCH0_ID               (OMAP_DMA_BASE + 0x446)
-#define OMAP_DMA_PCH1_ID               (OMAP_DMA_BASE + 0x448)
-#define OMAP_DMA_PCHG_ID               (OMAP_DMA_BASE + 0x44a)
-#define OMAP_DMA_PCHD_ID               (OMAP_DMA_BASE + 0x44c)
-#define OMAP_DMA_CAPS_0_U              (OMAP_DMA_BASE + 0x44e)
-#define OMAP_DMA_CAPS_0_L              (OMAP_DMA_BASE + 0x450)
-#define OMAP_DMA_CAPS_1_U              (OMAP_DMA_BASE + 0x452)
-#define OMAP_DMA_CAPS_1_L              (OMAP_DMA_BASE + 0x454)
-#define OMAP_DMA_CAPS_2                        (OMAP_DMA_BASE + 0x456)
-#define OMAP_DMA_CAPS_3                        (OMAP_DMA_BASE + 0x458)
-#define OMAP_DMA_CAPS_4                        (OMAP_DMA_BASE + 0x45a)
-#define OMAP_DMA_PCH2_SR               (OMAP_DMA_BASE + 0x460)
-#define OMAP_DMA_PCH0_SR               (OMAP_DMA_BASE + 0x480)
-#define OMAP_DMA_PCH1_SR               (OMAP_DMA_BASE + 0x482)
-#define OMAP_DMA_PCHD_SR               (OMAP_DMA_BASE + 0x4c0)
-
-/* Hardware registers for omap2 */
-#if defined(CONFIG_ARCH_OMAP3)
-#define OMAP_DMA4_BASE                 (L4_34XX_BASE + 0x56000)
-#else  /* CONFIG_ARCH_OMAP2 */
-#define OMAP_DMA4_BASE                 (L4_24XX_BASE + 0x56000)
-#endif
-
-#define OMAP_DMA4_REVISION             (OMAP_DMA4_BASE + 0x00)
-#define OMAP_DMA4_GCR_REG              (OMAP_DMA4_BASE + 0x78)
-#define OMAP_DMA4_IRQSTATUS_L0         (OMAP_DMA4_BASE + 0x08)
-#define OMAP_DMA4_IRQSTATUS_L1         (OMAP_DMA4_BASE + 0x0c)
-#define OMAP_DMA4_IRQSTATUS_L2         (OMAP_DMA4_BASE + 0x10)
-#define OMAP_DMA4_IRQSTATUS_L3         (OMAP_DMA4_BASE + 0x14)
-#define OMAP_DMA4_IRQENABLE_L0         (OMAP_DMA4_BASE + 0x18)
-#define OMAP_DMA4_IRQENABLE_L1         (OMAP_DMA4_BASE + 0x1c)
-#define OMAP_DMA4_IRQENABLE_L2         (OMAP_DMA4_BASE + 0x20)
-#define OMAP_DMA4_IRQENABLE_L3         (OMAP_DMA4_BASE + 0x24)
-#define OMAP_DMA4_SYSSTATUS            (OMAP_DMA4_BASE + 0x28)
-#define OMAP_DMA4_OCP_SYSCONFIG                (OMAP_DMA4_BASE + 0x2c)
-#define OMAP_DMA4_CAPS_0               (OMAP_DMA4_BASE + 0x64)
-#define OMAP_DMA4_CAPS_2               (OMAP_DMA4_BASE + 0x6c)
-#define OMAP_DMA4_CAPS_3               (OMAP_DMA4_BASE + 0x70)
-#define OMAP_DMA4_CAPS_4               (OMAP_DMA4_BASE + 0x74)
-
-#ifdef CONFIG_ARCH_OMAP1
-
-#define OMAP_LOGICAL_DMA_CH_COUNT      17
+#define OMAP1_DMA_BASE                 (0xfffed800)
+
+#define OMAP1_DMA_GCR                  0x400
+#define OMAP1_DMA_GSCR                 0x404
+#define OMAP1_DMA_GRST                 0x408
+#define OMAP1_DMA_HW_ID                        0x442
+#define OMAP1_DMA_PCH2_ID              0x444
+#define OMAP1_DMA_PCH0_ID              0x446
+#define OMAP1_DMA_PCH1_ID              0x448
+#define OMAP1_DMA_PCHG_ID              0x44a
+#define OMAP1_DMA_PCHD_ID              0x44c
+#define OMAP1_DMA_CAPS_0_U             0x44e
+#define OMAP1_DMA_CAPS_0_L             0x450
+#define OMAP1_DMA_CAPS_1_U             0x452
+#define OMAP1_DMA_CAPS_1_L             0x454
+#define OMAP1_DMA_CAPS_2               0x456
+#define OMAP1_DMA_CAPS_3               0x458
+#define OMAP1_DMA_CAPS_4               0x45a
+#define OMAP1_DMA_PCH2_SR              0x460
+#define OMAP1_DMA_PCH0_SR              0x480
+#define OMAP1_DMA_PCH1_SR              0x482
+#define OMAP1_DMA_PCHD_SR              0x4c0
+
+/* Hardware registers for omap2 and omap3 */
+#define OMAP24XX_DMA4_BASE             (L4_24XX_BASE + 0x56000)
+#define OMAP34XX_DMA4_BASE             (L4_34XX_BASE + 0x56000)
+
+#define OMAP_DMA4_REVISION             0x00
+#define OMAP_DMA4_GCR                  0x78
+#define OMAP_DMA4_IRQSTATUS_L0         0x08
+#define OMAP_DMA4_IRQSTATUS_L1         0x0c
+#define OMAP_DMA4_IRQSTATUS_L2         0x10
+#define OMAP_DMA4_IRQSTATUS_L3         0x14
+#define OMAP_DMA4_IRQENABLE_L0         0x18
+#define OMAP_DMA4_IRQENABLE_L1         0x1c
+#define OMAP_DMA4_IRQENABLE_L2         0x20
+#define OMAP_DMA4_IRQENABLE_L3         0x24
+#define OMAP_DMA4_SYSSTATUS            0x28
+#define OMAP_DMA4_OCP_SYSCONFIG                0x2c
+#define OMAP_DMA4_CAPS_0               0x64
+#define OMAP_DMA4_CAPS_2               0x6c
+#define OMAP_DMA4_CAPS_3               0x70
+#define OMAP_DMA4_CAPS_4               0x74
+
+#define OMAP1_LOGICAL_DMA_CH_COUNT     17
+#define OMAP_DMA4_LOGICAL_DMA_CH_COUNT 32      /* REVISIT: Is this 32 + 2? */
 
 /* Common channel specific registers for omap1 */
-#define OMAP_DMA_CSDP_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x00)
-#define OMAP_DMA_CCR_REG(n)            __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x02)
-#define OMAP_DMA_CICR_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x04)
-#define OMAP_DMA_CSR_REG(n)            __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x06)
-#define OMAP_DMA_CEN_REG(n)            __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x10)
-#define OMAP_DMA_CFN_REG(n)            __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x12)
-#define OMAP_DMA_CSFI_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x14)
-#define OMAP_DMA_CSEI_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x16)
-#define OMAP_DMA_CSAC_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x18)
-#define OMAP_DMA_CDAC_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x1a)
-#define OMAP_DMA_CDEI_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x1c)
-#define OMAP_DMA_CDFI_REG(n)           __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x1e)
-#define OMAP_DMA_CLNK_CTRL_REG(n)      __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x28)
-
-#else
-
-#define OMAP_LOGICAL_DMA_CH_COUNT      32      /* REVISIT: Is this 32 + 2? */
+#define OMAP1_DMA_CH_BASE(n)           (0x40 * (n) + 0x00)
+#define OMAP1_DMA_CSDP(n)              (0x40 * (n) + 0x00)
+#define OMAP1_DMA_CCR(n)               (0x40 * (n) + 0x02)
+#define OMAP1_DMA_CICR(n)              (0x40 * (n) + 0x04)
+#define OMAP1_DMA_CSR(n)               (0x40 * (n) + 0x06)
+#define OMAP1_DMA_CEN(n)               (0x40 * (n) + 0x10)
+#define OMAP1_DMA_CFN(n)               (0x40 * (n) + 0x12)
+#define OMAP1_DMA_CSFI(n)              (0x40 * (n) + 0x14)
+#define OMAP1_DMA_CSEI(n)              (0x40 * (n) + 0x16)
+#define OMAP1_DMA_CPC(n)               (0x40 * (n) + 0x18)     /* 15xx only */
+#define OMAP1_DMA_CSAC(n)              (0x40 * (n) + 0x18)
+#define OMAP1_DMA_CDAC(n)              (0x40 * (n) + 0x1a)
+#define OMAP1_DMA_CDEI(n)              (0x40 * (n) + 0x1c)
+#define OMAP1_DMA_CDFI(n)              (0x40 * (n) + 0x1e)
+#define OMAP1_DMA_CLNK_CTRL(n)         (0x40 * (n) + 0x28)
 
 /* Common channel specific registers for omap2 */
-#define OMAP_DMA_CCR_REG(n)            __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x80)
-#define OMAP_DMA_CLNK_CTRL_REG(n)      __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x84)
-#define OMAP_DMA_CICR_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x88)
-#define OMAP_DMA_CSR_REG(n)            __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x8c)
-#define OMAP_DMA_CSDP_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x90)
-#define OMAP_DMA_CEN_REG(n)            __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x94)
-#define OMAP_DMA_CFN_REG(n)            __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x98)
-#define OMAP_DMA_CSEI_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xa4)
-#define OMAP_DMA_CSFI_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xa8)
-#define OMAP_DMA_CDEI_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xac)
-#define OMAP_DMA_CDFI_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xb0)
-#define OMAP_DMA_CSAC_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xb4)
-#define OMAP_DMA_CDAC_REG(n)           __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xb8)
-
-#endif
+#define OMAP_DMA4_CH_BASE(n)           (0x60 * (n) + 0x80)
+#define OMAP_DMA4_CCR(n)               (0x60 * (n) + 0x80)
+#define OMAP_DMA4_CLNK_CTRL(n)         (0x60 * (n) + 0x84)
+#define OMAP_DMA4_CICR(n)              (0x60 * (n) + 0x88)
+#define OMAP_DMA4_CSR(n)               (0x60 * (n) + 0x8c)
+#define OMAP_DMA4_CSDP(n)              (0x60 * (n) + 0x90)
+#define OMAP_DMA4_CEN(n)               (0x60 * (n) + 0x94)
+#define OMAP_DMA4_CFN(n)               (0x60 * (n) + 0x98)
+#define OMAP_DMA4_CSEI(n)              (0x60 * (n) + 0xa4)
+#define OMAP_DMA4_CSFI(n)              (0x60 * (n) + 0xa8)
+#define OMAP_DMA4_CDEI(n)              (0x60 * (n) + 0xac)
+#define OMAP_DMA4_CDFI(n)              (0x60 * (n) + 0xb0)
+#define OMAP_DMA4_CSAC(n)              (0x60 * (n) + 0xb4)
+#define OMAP_DMA4_CDAC(n)              (0x60 * (n) + 0xb8)
 
 /* Channel specific registers only on omap1 */
-#define OMAP1_DMA_CSSA_L_REG(n)                __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x08)
-#define OMAP1_DMA_CSSA_U_REG(n)                __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x0a)
-#define OMAP1_DMA_CDSA_L_REG(n)                __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x0c)
-#define OMAP1_DMA_CDSA_U_REG(n)                __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x0e)
-#define OMAP1_DMA_COLOR_L_REG(n)       __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x20)
-#define OMAP1_DMA_CCR2_REG(n)          __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x24)
-#define OMAP1_DMA_COLOR_U_REG(n)       __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x22)
-#define OMAP1_DMA_LCH_CTRL_REG(n)      __REG16(OMAP_DMA_BASE + 0x40 * (n) + 0x2a)
+#define OMAP1_DMA_CSSA_L(n)            (0x40 * (n) + 0x08)
+#define OMAP1_DMA_CSSA_U(n)            (0x40 * (n) + 0x0a)
+#define OMAP1_DMA_CDSA_L(n)            (0x40 * (n) + 0x0c)
+#define OMAP1_DMA_CDSA_U(n)            (0x40 * (n) + 0x0e)
+#define OMAP1_DMA_COLOR_L(n)           (0x40 * (n) + 0x20)
+#define OMAP1_DMA_COLOR_U(n)           (0x40 * (n) + 0x22)
+#define OMAP1_DMA_CCR2(n)              (0x40 * (n) + 0x24)
+#define OMAP1_DMA_LCH_CTRL(n)          (0x40 * (n) + 0x2a)     /* not on 15xx */
+#define OMAP1_DMA_CCEN(n)              0
+#define OMAP1_DMA_CCFN(n)              0
 
 /* Channel specific registers only on omap2 */
-#define OMAP2_DMA_CSSA_REG(n)          __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0x9c)
-#define OMAP2_DMA_CDSA_REG(n)          __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xa0)
-#define OMAP2_DMA_CCEN_REG(n)          __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xbc)
-#define OMAP2_DMA_CCFN_REG(n)          __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xc0)
-#define OMAP2_DMA_COLOR_REG(n)         __REG32(OMAP_DMA4_BASE + 0x60 * (n) + 0xc4)
+#define OMAP_DMA4_CSSA(n)              (0x60 * (n) + 0x9c)
+#define OMAP_DMA4_CDSA(n)              (0x60 * (n) + 0xa0)
+#define OMAP_DMA4_CCEN(n)              (0x60 * (n) + 0xbc)
+#define OMAP_DMA4_CCFN(n)              (0x60 * (n) + 0xc0)
+#define OMAP_DMA4_COLOR(n)             (0x60 * (n) + 0xc4)
+
+/* Dummy defines to keep multi-omap compiles happy */
+#define OMAP1_DMA_REVISION             0
+#define OMAP1_DMA_IRQSTATUS_L0         0
+#define OMAP1_DMA_IRQENABLE_L0         0
+#define OMAP1_DMA_OCP_SYSCONFIG                0
+#define OMAP_DMA4_HW_ID                        0
+#define OMAP_DMA4_CAPS_0_L             0
+#define OMAP_DMA4_CAPS_0_U             0
+#define OMAP_DMA4_CAPS_1_L             0
+#define OMAP_DMA4_CAPS_1_U             0
+#define OMAP_DMA4_GSCR                 0
+#define OMAP_DMA4_CPC(n)               0
+
+#define OMAP_DMA4_LCH_CTRL(n)          0
+#define OMAP_DMA4_COLOR_L(n)           0
+#define OMAP_DMA4_COLOR_U(n)           0
+#define OMAP_DMA4_CCR2(n)              0
+#define OMAP1_DMA_CSSA(n)              0
+#define OMAP1_DMA_CDSA(n)              0
+#define OMAP_DMA4_CSSA_L(n)            0
+#define OMAP_DMA4_CSSA_U(n)            0
+#define OMAP_DMA4_CDSA_L(n)            0
+#define OMAP_DMA4_CDSA_U(n)            0
 
 /*----------------------------------------------------------------------------*/
 
 #define OMAP24XX_DMA_GPMC              4       /* S_DMA_3 */
 #define OMAP24XX_DMA_GFX               5       /* S_DMA_4 */
 #define OMAP24XX_DMA_DSS               6       /* S_DMA_5 */
-#define OMAP24XX_DMA_VLYNQ_TX          7       /* S_DMA_6 */
+#define OMAP242X_DMA_VLYNQ_TX          7       /* S_DMA_6 */
+#define OMAP24XX_DMA_EXT_DMAREQ2       7       /* S_DMA_6 */
 #define OMAP24XX_DMA_CWT               8       /* S_DMA_7 */
 #define OMAP24XX_DMA_AES_TX            9       /* S_DMA_8 */
 #define OMAP24XX_DMA_AES_RX            10      /* S_DMA_9 */
 #define OMAP24XX_DMA_DES_TX            11      /* S_DMA_10 */
 #define OMAP24XX_DMA_DES_RX            12      /* S_DMA_11 */
 #define OMAP24XX_DMA_SHA1MD5_RX                13      /* S_DMA_12 */
-#define OMAP24XX_DMA_EXT_DMAREQ2       14      /* S_DMA_13 */
-#define OMAP24XX_DMA_EXT_DMAREQ3       15      /* S_DMA_14 */
-#define OMAP24XX_DMA_EXT_DMAREQ4       16      /* S_DMA_15 */
-#define OMAP24XX_DMA_EAC_AC_RD         17      /* S_DMA_16 */
-#define OMAP24XX_DMA_EAC_AC_WR         18      /* S_DMA_17 */
-#define OMAP24XX_DMA_EAC_MD_UL_RD      19      /* S_DMA_18 */
-#define OMAP24XX_DMA_EAC_MD_UL_WR      20      /* S_DMA_19 */
-#define OMAP24XX_DMA_EAC_MD_DL_RD      21      /* S_DMA_20 */
-#define OMAP24XX_DMA_EAC_MD_DL_WR      22      /* S_DMA_21 */
-#define OMAP24XX_DMA_EAC_BT_UL_RD      23      /* S_DMA_22 */
-#define OMAP24XX_DMA_EAC_BT_UL_WR      24      /* S_DMA_23 */
-#define OMAP24XX_DMA_EAC_BT_DL_RD      25      /* S_DMA_24 */
-#define OMAP24XX_DMA_EAC_BT_DL_WR      26      /* S_DMA_25 */
+#define OMAP34XX_DMA_SHA2MD5_RX                13      /* S_DMA_12 */
+#define OMAP242X_DMA_EXT_DMAREQ2       14      /* S_DMA_13 */
+#define OMAP242X_DMA_EXT_DMAREQ3       15      /* S_DMA_14 */
+#define OMAP242X_DMA_EXT_DMAREQ4       16      /* S_DMA_15 */
+#define OMAP242X_DMA_EAC_AC_RD         17      /* S_DMA_16 */
+#define OMAP242X_DMA_EAC_AC_WR         18      /* S_DMA_17 */
+#define OMAP242X_DMA_EAC_MD_UL_RD      19      /* S_DMA_18 */
+#define OMAP242X_DMA_EAC_MD_UL_WR      20      /* S_DMA_19 */
+#define OMAP242X_DMA_EAC_MD_DL_RD      21      /* S_DMA_20 */
+#define OMAP242X_DMA_EAC_MD_DL_WR      22      /* S_DMA_21 */
+#define OMAP242X_DMA_EAC_BT_UL_RD      23      /* S_DMA_22 */
+#define OMAP242X_DMA_EAC_BT_UL_WR      24      /* S_DMA_23 */
+#define OMAP242X_DMA_EAC_BT_DL_RD      25      /* S_DMA_24 */
+#define OMAP242X_DMA_EAC_BT_DL_WR      26      /* S_DMA_25 */
+#define OMAP243X_DMA_EXT_DMAREQ3       14      /* S_DMA_13 */
+#define OMAP24XX_DMA_SPI3_TX0          15      /* S_DMA_14 */
+#define OMAP24XX_DMA_SPI3_RX0          16      /* S_DMA_15 */
+#define OMAP24XX_DMA_MCBSP3_TX         17      /* S_DMA_16 */
+#define OMAP24XX_DMA_MCBSP3_RX         18      /* S_DMA_17 */
+#define OMAP24XX_DMA_MCBSP4_TX         19      /* S_DMA_18 */
+#define OMAP24XX_DMA_MCBSP4_RX         20      /* S_DMA_19 */
+#define OMAP24XX_DMA_MCBSP5_TX         21      /* S_DMA_20 */
+#define OMAP24XX_DMA_MCBSP5_RX         22      /* S_DMA_21 */
+#define OMAP24XX_DMA_SPI3_TX1          23      /* S_DMA_22 */
+#define OMAP24XX_DMA_SPI3_RX1          24      /* S_DMA_23 */
+#define OMAP243X_DMA_EXT_DMAREQ4       25      /* S_DMA_24 */
+#define OMAP243X_DMA_EXT_DMAREQ5       26      /* S_DMA_25 */
+#define OMAP34XX_DMA_I2C3_TX           25      /* S_DMA_24 */
+#define OMAP34XX_DMA_I2C3_RX           26      /* S_DMA_25 */
 #define OMAP24XX_DMA_I2C1_TX           27      /* S_DMA_26 */
 #define OMAP24XX_DMA_I2C1_RX           28      /* S_DMA_27 */
 #define OMAP24XX_DMA_I2C2_TX           29      /* S_DMA_28 */
 #define OMAP24XX_DMA_I2C2_RX           30      /* S_DMA_29 */
-#define OMAP24XX_DMA_MCBSP1_TX         31      /* SDMA_30 */
-#define OMAP24XX_DMA_MCBSP1_RX         32      /* SDMA_31 */
-#define OMAP24XX_DMA_MCBSP2_TX         33      /* SDMA_32 */
-#define OMAP24XX_DMA_MCBSP2_RX         34      /* SDMA_33 */
-#define OMAP24XX_DMA_SPI1_TX0          35      /* SDMA_34 */
-#define OMAP24XX_DMA_SPI1_RX0          36      /* SDMA_35 */
-#define OMAP24XX_DMA_SPI1_TX1          37      /* SDMA_36 */
-#define OMAP24XX_DMA_SPI1_RX1          38      /* SDMA_37 */
-#define OMAP24XX_DMA_SPI1_TX2          39      /* SDMA_38 */
-#define OMAP24XX_DMA_SPI1_RX2          40      /* SDMA_39 */
-#define OMAP24XX_DMA_SPI1_TX3          41      /* SDMA_40 */
-#define OMAP24XX_DMA_SPI1_RX3          42      /* SDMA_41 */
-#define OMAP24XX_DMA_SPI2_TX0          43      /* SDMA_42 */
-#define OMAP24XX_DMA_SPI2_RX0          44      /* SDMA_43 */
-#define OMAP24XX_DMA_SPI2_TX1          45      /* SDMA_44 */
-#define OMAP24XX_DMA_SPI2_RX1          46      /* SDMA_45 */
-
-#define OMAP24XX_DMA_UART1_TX          49      /* SDMA_48 */
-#define OMAP24XX_DMA_UART1_RX          50      /* SDMA_49 */
-#define OMAP24XX_DMA_UART2_TX          51      /* SDMA_50 */
-#define OMAP24XX_DMA_UART2_RX          52      /* SDMA_51 */
-#define OMAP24XX_DMA_UART3_TX          53      /* SDMA_52 */
-#define OMAP24XX_DMA_UART3_RX          54      /* SDMA_53 */
-#define OMAP24XX_DMA_USB_W2FC_TX0      55      /* SDMA_54 */
-#define OMAP24XX_DMA_USB_W2FC_RX0      56      /* SDMA_55 */
-#define OMAP24XX_DMA_USB_W2FC_TX1      57      /* SDMA_56 */
-#define OMAP24XX_DMA_USB_W2FC_RX1      58      /* SDMA_57 */
-#define OMAP24XX_DMA_USB_W2FC_TX2      59      /* SDMA_58 */
-#define OMAP24XX_DMA_USB_W2FC_RX2      60      /* SDMA_59 */
-#define OMAP24XX_DMA_MMC1_TX           61      /* SDMA_60 */
-#define OMAP24XX_DMA_MMC1_RX           62      /* SDMA_61 */
-#define OMAP24XX_DMA_MS                        63      /* SDMA_62 */
-#define OMAP24XX_DMA_EXT_DMAREQ5       64      /* S_DMA_63 */
+#define OMAP24XX_DMA_MCBSP1_TX         31      /* S_DMA_30 */
+#define OMAP24XX_DMA_MCBSP1_RX         32      /* S_DMA_31 */
+#define OMAP24XX_DMA_MCBSP2_TX         33      /* S_DMA_32 */
+#define OMAP24XX_DMA_MCBSP2_RX         34      /* S_DMA_33 */
+#define OMAP24XX_DMA_SPI1_TX0          35      /* S_DMA_34 */
+#define OMAP24XX_DMA_SPI1_RX0          36      /* S_DMA_35 */
+#define OMAP24XX_DMA_SPI1_TX1          37      /* S_DMA_36 */
+#define OMAP24XX_DMA_SPI1_RX1          38      /* S_DMA_37 */
+#define OMAP24XX_DMA_SPI1_TX2          39      /* S_DMA_38 */
+#define OMAP24XX_DMA_SPI1_RX2          40      /* S_DMA_39 */
+#define OMAP24XX_DMA_SPI1_TX3          41      /* S_DMA_40 */
+#define OMAP24XX_DMA_SPI1_RX3          42      /* S_DMA_41 */
+#define OMAP24XX_DMA_SPI2_TX0          43      /* S_DMA_42 */
+#define OMAP24XX_DMA_SPI2_RX0          44      /* S_DMA_43 */
+#define OMAP24XX_DMA_SPI2_TX1          45      /* S_DMA_44 */
+#define OMAP24XX_DMA_SPI2_RX1          46      /* S_DMA_45 */
+#define OMAP24XX_DMA_MMC2_TX           47      /* S_DMA_46 */
+#define OMAP24XX_DMA_MMC2_RX           48      /* S_DMA_47 */
+#define OMAP24XX_DMA_UART1_TX          49      /* S_DMA_48 */
+#define OMAP24XX_DMA_UART1_RX          50      /* S_DMA_49 */
+#define OMAP24XX_DMA_UART2_TX          51      /* S_DMA_50 */
+#define OMAP24XX_DMA_UART2_RX          52      /* S_DMA_51 */
+#define OMAP24XX_DMA_UART3_TX          53      /* S_DMA_52 */
+#define OMAP24XX_DMA_UART3_RX          54      /* S_DMA_53 */
+#define OMAP24XX_DMA_USB_W2FC_TX0      55      /* S_DMA_54 */
+#define OMAP24XX_DMA_USB_W2FC_RX0      56      /* S_DMA_55 */
+#define OMAP24XX_DMA_USB_W2FC_TX1      57      /* S_DMA_56 */
+#define OMAP24XX_DMA_USB_W2FC_RX1      58      /* S_DMA_57 */
+#define OMAP24XX_DMA_USB_W2FC_TX2      59      /* S_DMA_58 */
+#define OMAP24XX_DMA_USB_W2FC_RX2      60      /* S_DMA_59 */
+#define OMAP24XX_DMA_MMC1_TX           61      /* S_DMA_60 */
+#define OMAP24XX_DMA_MMC1_RX           62      /* S_DMA_61 */
+#define OMAP24XX_DMA_MS                        63      /* S_DMA_62 */
+#define OMAP242X_DMA_EXT_DMAREQ5       64      /* S_DMA_63 */
+#define OMAP243X_DMA_EXT_DMAREQ6       64      /* S_DMA_63 */
+#define OMAP34XX_DMA_EXT_DMAREQ3       64      /* S_DMA_63 */
+#define OMAP34XX_DMA_AES2_TX           65      /* S_DMA_64 */
+#define OMAP34XX_DMA_AES2_RX           66      /* S_DMA_65 */
+#define OMAP34XX_DMA_DES2_TX           67      /* S_DMA_66 */
+#define OMAP34XX_DMA_DES2_RX           68      /* S_DMA_67 */
+#define OMAP34XX_DMA_SHA1MD5_RX                69      /* S_DMA_68 */
+#define OMAP34XX_DMA_SPI4_TX0          70      /* S_DMA_69 */
+#define OMAP34XX_DMA_SPI4_RX0          71      /* S_DMA_70 */
+#define OMAP34XX_DSS_DMA0              72      /* S_DMA_71 */
+#define OMAP34XX_DSS_DMA1              73      /* S_DMA_72 */
+#define OMAP34XX_DSS_DMA2              74      /* S_DMA_73 */
+#define OMAP34XX_DSS_DMA3              75      /* S_DMA_74 */
+#define OMAP34XX_DMA_MMC3_TX           77      /* S_DMA_76 */
+#define OMAP34XX_DMA_MMC3_RX           78      /* S_DMA_77 */
+#define OMAP34XX_DMA_USIM_TX           79      /* S_DMA_78 */
+#define OMAP34XX_DMA_USIM_RX           80      /* S_DMA_79 */
 
 /*----------------------------------------------------------------------------*/
 
@@ -358,6 +413,11 @@ enum omap_dma_burst_mode {
        OMAP_DMA_DATA_BURST_16,
 };
 
+enum end_type {
+       OMAP_DMA_LITTLE_ENDIAN = 0,
+       OMAP_DMA_BIG_ENDIAN
+};
+
 enum omap_dma_color_mode {
        OMAP_DMA_COLOR_DIS = 0,
        OMAP_DMA_CONSTANT_FILL,
@@ -370,24 +430,34 @@ enum omap_dma_write_mode {
        OMAP_DMA_WRITE_LAST_NON_POSTED
 };
 
+enum omap_dma_channel_mode {
+       OMAP_DMA_LCH_2D = 0,
+       OMAP_DMA_LCH_G,
+       OMAP_DMA_LCH_P,
+       OMAP_DMA_LCH_PD
+};
+
 struct omap_dma_channel_params {
        int data_type;          /* data type 8,16,32 */
        int elem_count;         /* number of elements in a frame */
        int frame_count;        /* number of frames in a element */
 
        int src_port;           /* Only on OMAP1 REVISIT: Is this needed? */
-       int src_amode;          /* constant , post increment, indexed , double indexed */
+       int src_amode;          /* constant, post increment, indexed,
+                                       double indexed */
        unsigned long src_start;        /* source address : physical */
        int src_ei;             /* source element index */
        int src_fi;             /* source frame index */
 
        int dst_port;           /* Only on OMAP1 REVISIT: Is this needed? */
-       int dst_amode;          /* constant , post increment, indexed , double indexed */
+       int dst_amode;          /* constant, post increment, indexed,
+                                       double indexed */
        unsigned long dst_start;        /* source address : physical */
        int dst_ei;             /* source element index */
        int dst_fi;             /* source frame index */
 
-       int trigger;            /* trigger attached if the channel is synchronized */
+       int trigger;            /* trigger attached if the channel is
+                                       synchronized */
        int sync_mode;          /* sycn on element, frame , block or packet */
        int src_or_dst_synch;   /* source synch(1) or destination synch(0) */
 
@@ -404,8 +474,8 @@ struct omap_dma_channel_params {
 
 extern void omap_set_dma_priority(int lch, int dst_port, int priority);
 extern int omap_request_dma(int dev_id, const char *dev_name,
-                           void (* callback)(int lch, u16 ch_status, void *data),
-                           void *data, int *dma_ch);
+                       void (*callback)(int lch, u16 ch_status, void *data),
+                       void *data, int *dma_ch);
 extern void omap_enable_dma_irq(int ch, u16 irq_bits);
 extern void omap_disable_dma_irq(int ch, u16 irq_bits);
 extern void omap_free_dma(int ch);
@@ -418,6 +488,7 @@ extern void omap_set_dma_transfer_params(int lch, int data_type,
 extern void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode,
                                    u32 color);
 extern void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode);
+extern void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode);
 
 extern void omap_set_dma_src_params(int lch, int src_port, int src_amode,
                                    unsigned long src_start,
@@ -436,23 +507,26 @@ extern void omap_set_dma_dest_burst_mode(int lch,
                                         enum omap_dma_burst_mode burst_mode);
 
 extern void omap_set_dma_params(int lch,
-                               struct omap_dma_channel_params * params);
+                               struct omap_dma_channel_params *params);
 
-extern void omap_dma_link_lch (int lch_head, int lch_queue);
-extern void omap_dma_unlink_lch (int lch_head, int lch_queue);
+extern void omap_dma_link_lch(int lch_head, int lch_queue);
+extern void omap_dma_unlink_lch(int lch_head, int lch_queue);
 
 extern int omap_set_dma_callback(int lch,
-                       void (* callback)(int lch, u16 ch_status, void *data),
+                       void (*callback)(int lch, u16 ch_status, void *data),
                        void *data);
 extern dma_addr_t omap_get_dma_src_pos(int lch);
 extern dma_addr_t omap_get_dma_dst_pos(int lch);
-extern int omap_get_dma_src_addr_counter(int lch);
 extern void omap_clear_dma(int lch);
+extern int omap_get_dma_active_status(int lch);
 extern int omap_dma_running(void);
 extern void omap_dma_set_global_params(int arb_rate, int max_fifo_depth,
                                       int tparams);
 extern int omap_dma_set_prio_lch(int lch, unsigned char read_prio,
                                 unsigned char write_prio);
+extern void omap_set_dma_dst_endian_type(int lch, enum end_type etype);
+extern void omap_set_dma_src_endian_type(int lch, enum end_type etype);
+extern int omap_get_dma_index(int lch, int *ei, int *fi);
 
 /* Chaining APIs */
 #ifndef CONFIG_ARCH_OMAP1
@@ -478,7 +552,7 @@ extern int omap_dma_chain_status(int chain_id);
 #endif
 
 /* LCD DMA functions */
-extern int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
+extern int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
                                void *data);
 extern void omap_free_lcd_dma(void);
 extern void omap_setup_lcd_dma(void);
index fefb276..02b29e8 100644 (file)
@@ -66,6 +66,7 @@ void omap_dm_timer_stop(struct omap_dm_timer *timer);
 
 void omap_dm_timer_set_source(struct omap_dm_timer *timer, int source);
 void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, unsigned int value);
+void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, unsigned int value);
 void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, unsigned int match);
 void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger);
 void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler);
index 6a883e0..f420881 100644 (file)
@@ -169,30 +169,29 @@ struct h2p2_dbg_fpga {
 #define OMAP1510_INT_FPGA              (IH_GPIO_BASE + 13)
 
 /* IRQ Numbers for interrupts muxed through the FPGA */
-#define OMAP1510_IH_FPGA_BASE          IH_BOARD_BASE
-#define OMAP1510_INT_FPGA_ATN          (OMAP1510_IH_FPGA_BASE + 0)
-#define OMAP1510_INT_FPGA_ACK          (OMAP1510_IH_FPGA_BASE + 1)
-#define OMAP1510_INT_FPGA2             (OMAP1510_IH_FPGA_BASE + 2)
-#define OMAP1510_INT_FPGA3             (OMAP1510_IH_FPGA_BASE + 3)
-#define OMAP1510_INT_FPGA4             (OMAP1510_IH_FPGA_BASE + 4)
-#define OMAP1510_INT_FPGA5             (OMAP1510_IH_FPGA_BASE + 5)
-#define OMAP1510_INT_FPGA6             (OMAP1510_IH_FPGA_BASE + 6)
-#define OMAP1510_INT_FPGA7             (OMAP1510_IH_FPGA_BASE + 7)
-#define OMAP1510_INT_FPGA8             (OMAP1510_IH_FPGA_BASE + 8)
-#define OMAP1510_INT_FPGA9             (OMAP1510_IH_FPGA_BASE + 9)
-#define OMAP1510_INT_FPGA10            (OMAP1510_IH_FPGA_BASE + 10)
-#define OMAP1510_INT_FPGA11            (OMAP1510_IH_FPGA_BASE + 11)
-#define OMAP1510_INT_FPGA12            (OMAP1510_IH_FPGA_BASE + 12)
-#define OMAP1510_INT_ETHER             (OMAP1510_IH_FPGA_BASE + 13)
-#define OMAP1510_INT_FPGAUART1         (OMAP1510_IH_FPGA_BASE + 14)
-#define OMAP1510_INT_FPGAUART2         (OMAP1510_IH_FPGA_BASE + 15)
-#define OMAP1510_INT_FPGA_TS           (OMAP1510_IH_FPGA_BASE + 16)
-#define OMAP1510_INT_FPGA17            (OMAP1510_IH_FPGA_BASE + 17)
-#define OMAP1510_INT_FPGA_CAM          (OMAP1510_IH_FPGA_BASE + 18)
-#define OMAP1510_INT_FPGA_RTC_A                (OMAP1510_IH_FPGA_BASE + 19)
-#define OMAP1510_INT_FPGA_RTC_B                (OMAP1510_IH_FPGA_BASE + 20)
-#define OMAP1510_INT_FPGA_CD           (OMAP1510_IH_FPGA_BASE + 21)
-#define OMAP1510_INT_FPGA22            (OMAP1510_IH_FPGA_BASE + 22)
-#define OMAP1510_INT_FPGA23            (OMAP1510_IH_FPGA_BASE + 23)
+#define OMAP1510_INT_FPGA_ATN          (OMAP_FPGA_IRQ_BASE + 0)
+#define OMAP1510_INT_FPGA_ACK          (OMAP_FPGA_IRQ_BASE + 1)
+#define OMAP1510_INT_FPGA2             (OMAP_FPGA_IRQ_BASE + 2)
+#define OMAP1510_INT_FPGA3             (OMAP_FPGA_IRQ_BASE + 3)
+#define OMAP1510_INT_FPGA4             (OMAP_FPGA_IRQ_BASE + 4)
+#define OMAP1510_INT_FPGA5             (OMAP_FPGA_IRQ_BASE + 5)
+#define OMAP1510_INT_FPGA6             (OMAP_FPGA_IRQ_BASE + 6)
+#define OMAP1510_INT_FPGA7             (OMAP_FPGA_IRQ_BASE + 7)
+#define OMAP1510_INT_FPGA8             (OMAP_FPGA_IRQ_BASE + 8)
+#define OMAP1510_INT_FPGA9             (OMAP_FPGA_IRQ_BASE + 9)
+#define OMAP1510_INT_FPGA10            (OMAP_FPGA_IRQ_BASE + 10)
+#define OMAP1510_INT_FPGA11            (OMAP_FPGA_IRQ_BASE + 11)
+#define OMAP1510_INT_FPGA12            (OMAP_FPGA_IRQ_BASE + 12)
+#define OMAP1510_INT_ETHER             (OMAP_FPGA_IRQ_BASE + 13)
+#define OMAP1510_INT_FPGAUART1         (OMAP_FPGA_IRQ_BASE + 14)
+#define OMAP1510_INT_FPGAUART2         (OMAP_FPGA_IRQ_BASE + 15)
+#define OMAP1510_INT_FPGA_TS           (OMAP_FPGA_IRQ_BASE + 16)
+#define OMAP1510_INT_FPGA17            (OMAP_FPGA_IRQ_BASE + 17)
+#define OMAP1510_INT_FPGA_CAM          (OMAP_FPGA_IRQ_BASE + 18)
+#define OMAP1510_INT_FPGA_RTC_A                (OMAP_FPGA_IRQ_BASE + 19)
+#define OMAP1510_INT_FPGA_RTC_B                (OMAP_FPGA_IRQ_BASE + 20)
+#define OMAP1510_INT_FPGA_CD           (OMAP_FPGA_IRQ_BASE + 21)
+#define OMAP1510_INT_FPGA22            (OMAP_FPGA_IRQ_BASE + 22)
+#define OMAP1510_INT_FPGA23            (OMAP_FPGA_IRQ_BASE + 23)
 
 #endif
index 91d85b3..45fdfcc 100644 (file)
 #include "omap1510.h"
 #include "omap24xx.h"
 #include "omap16xx.h"
+#include "omap34xx.h"
 
 #ifndef __ASSEMBLER__
 
index 160578e..0b13557 100644 (file)
@@ -60,6 +60,7 @@
 #define IO_SIZE                0x40000
 #define IO_VIRT                (IO_PHYS - IO_OFFSET)
 #define IO_ADDRESS(pa) ((pa) - IO_OFFSET)
+#define OMAP1_IO_ADDRESS(pa)   ((pa) - IO_OFFSET)
 #define io_p2v(pa)     ((pa) - IO_OFFSET)
 #define io_v2p(va)     ((va) + IO_OFFSET)
 
@@ -91,6 +92,7 @@
 
 #define IO_OFFSET      0x90000000
 #define IO_ADDRESS(pa) ((pa) + IO_OFFSET)      /* Works for L3 and L4 */
+#define OMAP2_IO_ADDRESS(pa)   ((pa) + IO_OFFSET)      /* Works for L3 and L4 */
 #define io_p2v(pa)     ((pa) + IO_OFFSET)      /* Works for L3 and L4 */
 #define io_v2p(va)     ((va) - IO_OFFSET)      /* Works for L3 and L4 */
 
 
 #define IO_OFFSET              0x90000000
 #define IO_ADDRESS(pa)         ((pa) + IO_OFFSET)/* Works for L3 and L4 */
+#define OMAP2_IO_ADDRESS(pa)   ((pa) + IO_OFFSET)/* Works for L3 and L4 */
 #define io_p2v(pa)             ((pa) + IO_OFFSET)/* Works for L3 and L4 */
 #define io_v2p(va)             ((va) - IO_OFFSET)/* Works for L3 and L4 */
 
 #define omap_writew(v,a)       (*(volatile unsigned short *)IO_ADDRESS(a) = (v))
 #define omap_writel(v,a)       (*(volatile unsigned int   *)IO_ADDRESS(a) = (v))
 
-/* 16 bit uses LDRH/STRH, base +/- offset_8 */
-typedef struct { volatile u16 offset[256]; } __regbase16;
-#define __REGV16(vaddr)                ((__regbase16 *)((vaddr)&~0xff)) \
-                                       ->offset[((vaddr)&0xff)>>1]
-#define __REG16(paddr)          __REGV16(io_p2v(paddr))
-
-/* 8/32 bit uses LDR/STR, base +/- offset_12 */
-typedef struct { volatile u8 offset[4096]; } __regbase8;
-#define __REGV8(vaddr)         ((__regbase8  *)((vaddr)&~4095)) \
-                                       ->offset[((vaddr)&4095)>>0]
-#define __REG8(paddr)          __REGV8(io_p2v(paddr))
-
-typedef struct { volatile u32 offset[4096]; } __regbase32;
-#define __REGV32(vaddr)                ((__regbase32 *)((vaddr)&~4095)) \
-                                       ->offset[((vaddr)&4095)>>2]
-#define __REG32(paddr)         __REGV32(io_p2v(paddr))
-
 extern void omap1_map_common_io(void);
 extern void omap1_init_common_hw(void);
 
 extern void omap2_map_common_io(void);
 extern void omap2_init_common_hw(void);
 
-#else
-
-#define __REG8(paddr)          io_p2v(paddr)
-#define __REG16(paddr)         io_p2v(paddr)
-#define __REG32(paddr)         io_p2v(paddr)
-
 #endif
 
 #endif
index 8797365..7464c69 100644 (file)
 #define OMAP_MAX_GPIO_LINES    192
 #define IH_GPIO_BASE           (128 + IH2_BASE)
 #define IH_MPUIO_BASE          (OMAP_MAX_GPIO_LINES + IH_GPIO_BASE)
-#define IH_BOARD_BASE          (16 + IH_MPUIO_BASE)
+#define OMAP_IRQ_END           (IH_MPUIO_BASE + 16)
+
+/* External FPGA handles interrupts on Innovator boards */
+#define        OMAP_FPGA_IRQ_BASE      (OMAP_IRQ_END)
+#ifdef CONFIG_MACH_OMAP_INNOVATOR
+#define OMAP_FPGA_NR_IRQS      24
+#else
+#define OMAP_FPGA_NR_IRQS      0
+#endif
+#define OMAP_FPGA_IRQ_END      (OMAP_FPGA_IRQ_BASE + OMAP_FPGA_NR_IRQS)
+
+/* External TWL4030 can handle interrupts on 2430 and 34xx boards */
+#define        TWL4030_IRQ_BASE        (OMAP_FPGA_IRQ_END)
+#ifdef CONFIG_TWL4030_CORE
+#define        TWL4030_BASE_NR_IRQS    8
+#define        TWL4030_PWR_NR_IRQS     8
+#else
+#define        TWL4030_BASE_NR_IRQS    0
+#define        TWL4030_PWR_NR_IRQS     0
+#endif
+#define TWL4030_IRQ_END                (TWL4030_IRQ_BASE + TWL4030_BASE_NR_IRQS)
+#define TWL4030_PWR_IRQ_BASE   TWL4030_IRQ_END
+#define        TWL4030_PWR_IRQ_END     (TWL4030_PWR_IRQ_BASE + TWL4030_PWR_NR_IRQS)
+
+/* External TWL4030 gpio interrupts are optional */
+#define TWL4030_GPIO_IRQ_BASE  TWL4030_PWR_IRQ_END
+#ifdef CONFIG_TWL4030_GPIO
+#define TWL4030_GPIO_NR_IRQS   18
+#else
+#define        TWL4030_GPIO_NR_IRQS    0
+#endif
+#define TWL4030_GPIO_IRQ_END   (TWL4030_GPIO_IRQ_BASE + TWL4030_GPIO_NR_IRQS)
+
+/* Total number of interrupts depends on the enabled blocks above */
+#define NR_IRQS                        TWL4030_GPIO_IRQ_END
 
 #define OMAP_IRQ_BIT(irq)      (1 << ((irq) % 32))
 
 extern void omap_init_irq(void);
 #endif
 
-/*
- * The definition of NR_IRQS is in board-specific header file, which is
- * included via hardware.h
- */
 #include <asm/hardware.h>
 
-#ifndef NR_IRQS
-#define NR_IRQS                 IH_BOARD_BASE
-#endif
-
 #endif
index c7a0cc1..26c78f6 100644 (file)
 #ifndef __ASM_ARCH_OMAP_MCBSP_H
 #define __ASM_ARCH_OMAP_MCBSP_H
 
+#include <linux/completion.h>
+#include <linux/spinlock.h>
+
 #include <asm/hardware.h>
+#include <asm/arch/clock.h>
 
 #define OMAP730_MCBSP1_BASE    0xfffb1000
 #define OMAP730_MCBSP2_BASE    0xfffb1800
@@ -40,6 +44,9 @@
 #define OMAP24XX_MCBSP1_BASE   0x48074000
 #define OMAP24XX_MCBSP2_BASE   0x48076000
 
+#define OMAP34XX_MCBSP1_BASE   0x48074000
+#define OMAP34XX_MCBSP2_BASE   0x49022000
+
 #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730)
 
 #define OMAP_MCBSP_REG_DRR2    0x00
@@ -74,7 +81,8 @@
 #define OMAP_MCBSP_REG_XCERG   0x3A
 #define OMAP_MCBSP_REG_XCERH   0x3C
 
-#define OMAP_MAX_MCBSP_COUNT 3
+#define OMAP_MAX_MCBSP_COUNT   3
+#define MAX_MCBSP_CLOCKS       3
 
 #define AUDIO_MCBSP_DATAWRITE  (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
 #define AUDIO_MCBSP_DATAREAD   (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
 #define OMAP_MCBSP_REG_XCERG   0x74
 #define OMAP_MCBSP_REG_XCERH   0x78
 
-#define OMAP_MAX_MCBSP_COUNT 2
+#define OMAP_MAX_MCBSP_COUNT   2
+#define MAX_MCBSP_CLOCKS       2
 
 #define AUDIO_MCBSP_DATAWRITE  (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
 #define AUDIO_MCBSP_DATAREAD   (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
@@ -298,6 +307,55 @@ struct omap_mcbsp_spi_cfg {
        omap_mcbsp_word_length          word_length;
 };
 
+/* Platform specific configuration */
+struct omap_mcbsp_ops {
+       void (*request)(unsigned int);
+       void (*free)(unsigned int);
+       int (*check)(unsigned int);
+};
+
+struct omap_mcbsp_platform_data {
+       u32 virt_base;
+       u8 dma_rx_sync, dma_tx_sync;
+       u16 rx_irq, tx_irq;
+       struct omap_mcbsp_ops *ops;
+       char const *clk_name;
+};
+
+struct omap_mcbsp {
+       struct device *dev;
+       u32 io_base;
+       u8 id;
+       u8 free;
+       omap_mcbsp_word_length rx_word_length;
+       omap_mcbsp_word_length tx_word_length;
+
+       omap_mcbsp_io_type_t io_type; /* IRQ or poll */
+       /* IRQ based TX/RX */
+       int rx_irq;
+       int tx_irq;
+
+       /* DMA stuff */
+       u8 dma_rx_sync;
+       short dma_rx_lch;
+       u8 dma_tx_sync;
+       short dma_tx_lch;
+
+       /* Completion queues */
+       struct completion tx_irq_completion;
+       struct completion rx_irq_completion;
+       struct completion tx_dma_completion;
+       struct completion rx_dma_completion;
+
+       /* Protect the field .free, while checking if the mcbsp is in use */
+       spinlock_t lock;
+       struct omap_mcbsp_platform_data *pdata;
+       struct clk *clk;
+};
+
+int omap_mcbsp_init(void);
+void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
+                                       int size);
 void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
 int omap_mcbsp_request(unsigned int id);
 void omap_mcbsp_free(unsigned int id);
diff --git a/include/asm-arm/arch-omap/omap34xx.h b/include/asm-arm/arch-omap/omap34xx.h
new file mode 100644 (file)
index 0000000..aa30c6d
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * include/asm-arm/arch-omap/omap34xx.h
+ *
+ * This file contains the processor specific definitions of the TI OMAP34XX.
+ *
+ * Copyright (C) 2007 Texas Instruments.
+ * Copyright (C) 2007 Nokia Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __ASM_ARCH_OMAP34XX_H
+#define __ASM_ARCH_OMAP34XX_H
+
+/*
+ * Please place only base defines here and put the rest in device
+ * specific headers.
+ */
+
+#define L4_34XX_BASE           0x48000000
+#define L4_WK_34XX_BASE                0x48300000
+#define L4_WK_OMAP_BASE                L4_WK_34XX_BASE
+#define L4_PER_34XX_BASE       0x49000000
+#define L4_PER_OMAP_BASE       L4_PER_34XX_BASE
+#define L4_EMU_34XX_BASE       0x54000000
+#define L4_EMU_BASE            L4_EMU_34XX_BASE
+#define L3_34XX_BASE           0x68000000
+#define L3_OMAP_BASE           L3_34XX_BASE
+
+#define OMAP3430_32KSYNCT_BASE 0x48320000
+#define OMAP3430_CM_BASE       0x48004800
+#define OMAP3430_PRM_BASE      0x48306800
+#define OMAP343X_SMS_BASE      0x6C000000
+#define OMAP343X_SDRC_BASE     0x6D000000
+#define OMAP34XX_GPMC_BASE     0x6E000000
+#define OMAP343X_SCM_BASE      0x48002000
+#define OMAP343X_CTRL_BASE     OMAP343X_SCM_BASE
+
+#define OMAP34XX_IC_BASE       0x48200000
+#define OMAP34XX_IVA_INTC_BASE 0x40000000
+#define OMAP34XX_HSUSB_OTG_BASE        (L4_34XX_BASE + 0xAB000)
+#define OMAP34XX_HSUSB_HOST_BASE       (L4_34XX_BASE + 0x64000)
+#define OMAP34XX_USBTLL_BASE   (L4_34XX_BASE + 0x62000)
+
+
+#if defined(CONFIG_ARCH_OMAP3430)
+
+#define OMAP2_32KSYNCT_BASE            OMAP3430_32KSYNCT_BASE
+#define OMAP2_CM_BASE                  OMAP3430_CM_BASE
+#define OMAP2_PRM_BASE                 OMAP3430_PRM_BASE
+#define OMAP2_VA_IC_BASE               IO_ADDRESS(OMAP34XX_IC_BASE)
+
+#endif
+
+#define OMAP34XX_DSP_BASE      0x58000000
+#define OMAP34XX_DSP_MEM_BASE  (OMAP34XX_DSP_BASE + 0x0)
+#define OMAP34XX_DSP_IPI_BASE  (OMAP34XX_DSP_BASE + 0x1000000)
+#define OMAP34XX_DSP_MMU_BASE  (OMAP34XX_DSP_BASE + 0x2000000)
+#endif /* __ASM_ARCH_OMAP34XX_H */
+
index bb9bb3f..be59f4a 100644 (file)
@@ -11,6 +11,7 @@
 #ifndef __ARCH_ARM_OMAP_SRAM_H
 #define __ARCH_ARM_OMAP_SRAM_H
 
+extern int __init omap_sram_init(void);
 extern void * omap_sram_push(void * start, unsigned long size);
 extern void omap_sram_reprogram_clock(u32 dpllctl, u32 ckctl);
 
@@ -21,17 +22,35 @@ extern void omap2_sram_reprogram_sdrc(u32 perf_level, u32 dll_val,
 extern u32 omap2_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
 
 /* Do not use these */
-extern void sram_reprogram_clock(u32 ckctl, u32 dpllctl);
-extern unsigned long sram_reprogram_clock_sz;
+extern void omap1_sram_reprogram_clock(u32 ckctl, u32 dpllctl);
+extern unsigned long omap1_sram_reprogram_clock_sz;
 
-extern void sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
-                         u32 base_cs, u32 force_unlock);
-extern unsigned long sram_ddr_init_sz;
+extern void omap24xx_sram_reprogram_clock(u32 ckctl, u32 dpllctl);
+extern unsigned long omap24xx_sram_reprogram_clock_sz;
 
-extern u32 sram_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val, int bypass);
-extern unsigned long sram_set_prcm_sz;
+extern void omap242x_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
+                                               u32 base_cs, u32 force_unlock);
+extern unsigned long omap242x_sram_ddr_init_sz;
 
-extern void sram_reprogram_sdrc(u32 perf_level, u32 dll_val, u32 mem_type);
-extern unsigned long sram_reprogram_sdrc_sz;
+extern u32 omap242x_sram_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val,
+                                               int bypass);
+extern unsigned long omap242x_sram_set_prcm_sz;
+
+extern void omap242x_sram_reprogram_sdrc(u32 perf_level, u32 dll_val,
+                                               u32 mem_type);
+extern unsigned long omap242x_sram_reprogram_sdrc_sz;
+
+
+extern void omap243x_sram_ddr_init(u32 *slow_dll_ctrl, u32 fast_dll_ctrl,
+                                               u32 base_cs, u32 force_unlock);
+extern unsigned long omap243x_sram_ddr_init_sz;
+
+extern u32 omap243x_sram_set_prcm(u32 dpll_ctrl_val, u32 sdrc_rfr_val,
+                                               int bypass);
+extern unsigned long omap243x_sram_set_prcm_sz;
+
+extern void omap243x_sram_reprogram_sdrc(u32 perf_level, u32 dll_val,
+                                               u32 mem_type);
+extern unsigned long omap243x_sram_reprogram_sdrc_sz;
 
 #endif
index 8ded218..65a9c82 100644 (file)
 #ifndef        __ASSEMBLER__
 
 /* EMIF Slow Interface Configuration Register */
-#define        OMAP_EMIFS_CONFIG_REG   __REG32(EMIFS_CONFIG)
-
 #define OMAP_EMIFS_CONFIG_FR           (1 << 4)
 #define OMAP_EMIFS_CONFIG_PDE          (1 << 3)
 #define OMAP_EMIFS_CONFIG_PWD_EN       (1 << 2)
 #define OMAP_EMIFS_CONFIG_BM           (1 << 1)
 #define OMAP_EMIFS_CONFIG_WP           (1 << 0)
 
-#define EMIFS_CCS(n)           __REG32(EMIFS_CS0_CONFIG + (4 * (n)))
-#define EMIFS_ACS(n)           __REG32(EMIFS_ACS0 + (4 * (n)))
+#define EMIFS_CCS(n)           (EMIFS_CS0_CONFIG + (4 * (n)))
+#define EMIFS_ACS(n)           (EMIFS_ACS0 + (4 * (n)))
 
 /* Almost all documentation for chip and board memory maps assumes
  * BM is clear.  Most devel boards have a switch to control booting
  */
 static inline u32 omap_cs0_phys(void)
 {
-       return (OMAP_EMIFS_CONFIG_REG & OMAP_EMIFS_CONFIG_BM)
+       return (omap_readl(EMIFS_CONFIG) & OMAP_EMIFS_CONFIG_BM)
                        ?  OMAP_CS3_PHYS : 0;
 }
 
 static inline u32 omap_cs3_phys(void)
 {
-       return (OMAP_EMIFS_CONFIG_REG & OMAP_EMIFS_CONFIG_BM)
+       return (omap_readl(EMIFS_CONFIG) & OMAP_EMIFS_CONFIG_BM)
                        ? 0 : OMAP_CS3_PHYS;
 }
 
index 2147d18..ddf1861 100644 (file)
 /*
  * OTG and transceiver registers, for OMAPs starting with ARM926
  */
-#define OTG_REG32(offset)              __REG32(OTG_BASE + (offset))
-#define OTG_REG16(offset)              __REG16(OTG_BASE + (offset))
-
-#define OTG_REV_REG                    OTG_REG32(0x00)
-#define OTG_SYSCON_1_REG               OTG_REG32(0x04)
+#define OTG_REV                                (OTG_BASE + 0x00)
+#define OTG_SYSCON_1                   (OTG_BASE + 0x04)
 #      define   USB2_TRX_MODE(w)       (((w)>>24)&0x07)
 #      define   USB1_TRX_MODE(w)       (((w)>>20)&0x07)
 #      define   USB0_TRX_MODE(w)       (((w)>>16)&0x07)
@@ -47,7 +44,7 @@
 #      define   DEV_IDLE_EN            (1 << 13)
 #      define   OTG_RESET_DONE         (1 << 2)
 #      define   OTG_SOFT_RESET         (1 << 1)
-#define OTG_SYSCON_2_REG               OTG_REG32(0x08)
+#define OTG_SYSCON_2                   (OTG_BASE + 0x08)
 #      define   OTG_EN                 (1 << 31)
 #      define   USBX_SYNCHRO           (1 << 30)
 #      define   OTG_MST16              (1 << 29)
@@ -65,7 +62,7 @@
 #      define   HMC_TLLSPEED           (1 << 7)
 #      define   HMC_TLLATTACH          (1 << 6)
 #      define   OTG_HMC(w)             (((w)>>0)&0x3f)
-#define OTG_CTRL_REG                   OTG_REG32(0x0c)
+#define OTG_CTRL                       (OTG_BASE + 0x0c)
 #      define   OTG_USB2_EN            (1 << 29)
 #      define   OTG_USB2_DP            (1 << 28)
 #      define   OTG_USB2_DM            (1 << 27)
@@ -92,7 +89,7 @@
 #      define   OTG_PD_VBUS            (1 << 2)
 #      define   OTG_PU_VBUS            (1 << 1)
 #      define   OTG_PU_ID              (1 << 0)
-#define OTG_IRQ_EN_REG                 OTG_REG16(0x10)
+#define OTG_IRQ_EN                     (OTG_BASE + 0x10)       /* 16-bit */
 #      define   DRIVER_SWITCH          (1 << 15)
 #      define   A_VBUS_ERR             (1 << 13)
 #      define   A_REQ_TMROUT           (1 << 12)
 #      define   B_SRP_DONE             (1 << 8)
 #      define   B_SRP_STARTED          (1 << 7)
 #      define   OPRT_CHG               (1 << 0)
-#define OTG_IRQ_SRC_REG                        OTG_REG16(0x14)
+#define OTG_IRQ_SRC                    (OTG_BASE + 0x14)       /* 16-bit */
        // same bits as in IRQ_EN
-#define OTG_OUTCTRL_REG                        OTG_REG16(0x18)
+#define OTG_OUTCTRL                    (OTG_BASE + 0x18)       /* 16-bit */
 #      define   OTGVPD                 (1 << 14)
 #      define   OTGVPU                 (1 << 13)
 #      define   OTGPUID                (1 << 12)
 #      define   USB0VDR                (1 << 2)
 #      define   USB0PDEN               (1 << 1)
 #      define   USB0PUEN               (1 << 0)
-#define OTG_TEST_REG                   OTG_REG16(0x20)
-#define OTG_VENDOR_CODE_REG            OTG_REG32(0xfc)
+#define OTG_TEST                       (OTG_BASE + 0x20)       /* 16-bit */
+#define OTG_VENDOR_CODE                        (OTG_BASE + 0xfc)       /* 16-bit */
 
 /*-------------------------------------------------------------------------*/
 
 /* OMAP1 */
-#define        USB_TRANSCEIVER_CTRL_REG        __REG32(0xfffe1000 + 0x0064)
+#define        USB_TRANSCEIVER_CTRL            (0xfffe1000 + 0x0064)
 #      define  CONF_USB2_UNI_R         (1 << 8)
 #      define  CONF_USB1_UNI_R         (1 << 7)
 #      define  CONF_USB_PORT0_R(x)     (((x)>>4)&0x7)
index 50f8c88..59f1bc9 100644 (file)
@@ -14,7 +14,6 @@
 #include "orion5x.h"
 
 #define IO_SPACE_LIMIT         0xffffffff
-#define IO_SPACE_REMAP         ORION5X_PCI_SYS_IO_BASE
 
 static inline void __iomem *
 __arch_ioremap(unsigned long paddr, size_t size, unsigned int mtype)
@@ -53,15 +52,12 @@ static inline void __iomem *__io(unsigned long addr)
 /*****************************************************************************
  * Helpers to access Orion registers
  ****************************************************************************/
-#define orion5x_read(r)                __raw_readl(r)
-#define orion5x_write(r, val)  __raw_writel(val, r)
-
 /*
  * These are not preempt-safe.  Locks, if needed, must be taken
  * care of by the caller.
  */
-#define orion5x_setbits(r, mask)       orion5x_write((r), orion5x_read(r) | (mask))
-#define orion5x_clrbits(r, mask)       orion5x_write((r), orion5x_read(r) & ~(mask))
+#define orion5x_setbits(r, mask)       writel(readl(r) | (mask), (r))
+#define orion5x_clrbits(r, mask)       writel(readl(r) & ~(mask), (r))
 
 
 #endif
index 206ddd7..10257f5 100644 (file)
@@ -2,7 +2,7 @@
  * include/asm-arm/arch-orion5x/orion5x.h
  *
  * Generic definitions of Orion SoC flavors:
- *  Orion-1, Orion-NAS, Orion-VoIP, and Orion-2.
+ *  Orion-1, Orion-VoIP, Orion-NAS, and Orion-2.
  *
  * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  *
 /*******************************************************************************
  * Supported Devices & Revisions
  ******************************************************************************/
-/* Orion-1 (88F5181) */
+/* Orion-1 (88F5181) and Orion-VoIP (88F5181L) */
 #define MV88F5181_DEV_ID       0x5181
 #define MV88F5181_REV_B1       3
+#define MV88F5181L_REV_A0      8
+#define MV88F5181L_REV_A1      9
 /* Orion-NAS (88F5182) */
 #define MV88F5182_DEV_ID       0x5182
 #define MV88F5182_REV_A2       2
 #define BRIDGE_MASK            ORION5X_BRIDGE_REG(0x114)
 #define  BRIDGE_INT_TIMER0     0x0002
 #define  BRIDGE_INT_TIMER1     0x0004
+#define  BRIDGE_INT_TIMER1_CLR (~0x0004)
 #define MAIN_IRQ_CAUSE         ORION5X_BRIDGE_REG(0x200)
 #define MAIN_IRQ_MASK          ORION5X_BRIDGE_REG(0x204)
 
index 5c13d4f..7548ced 100644 (file)
@@ -8,23 +8,38 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <linux/serial_reg.h>
 #include <asm/arch/orion5x.h>
 
-#define MV_UART_THR    ((volatile unsigned char *)(UART0_PHYS_BASE + 0x0))
-#define MV_UART_LSR    ((volatile unsigned char *)(UART0_PHYS_BASE + 0x14))
-
-#define LSR_THRE       0x20
+#define SERIAL_BASE    ((unsigned char *)UART0_PHYS_BASE)
 
 static void putc(const char c)
 {
-       int j = 0x1000;
-       while (--j && !(*MV_UART_LSR & LSR_THRE))
+       unsigned char *base = SERIAL_BASE;
+       int i;
+
+       for (i = 0; i < 0x1000; i++) {
+               if (base[UART_LSR << 2] & UART_LSR_THRE)
+                       break;
                barrier();
-       *MV_UART_THR = c;
+       }
+
+       base[UART_TX << 2] = c;
 }
 
 static void flush(void)
 {
+       unsigned char *base = SERIAL_BASE;
+       unsigned char mask;
+       int i;
+
+       mask = UART_LSR_TEMT | UART_LSR_THRE;
+
+       for (i = 0; i < 0x1000; i++) {
+               if ((base[UART_LSR << 2] & mask) == mask)
+                       break;
+               barrier();
+       }
 }
 
 /*
index 52bbe3b..f82f96d 100644 (file)
@@ -12,4 +12,6 @@ typedef struct {
        void *priv;
 } pxa2xx_audio_ops_t;
 
+extern void pxa_set_ac97_info(pxa2xx_audio_ops_t *ops);
+
 #endif
index e25558f..d9af6da 100644 (file)
@@ -191,15 +191,6 @@ extern int pxa_gpio_get_value(unsigned gpio);
  */
 extern void pxa_gpio_set_value(unsigned gpio, int value);
 
-/*
- * Routine to enable or disable CKEN
- */
-static inline void __deprecated pxa_set_cken(int clock, int enable)
-{
-       extern void __pxa_set_cken(int clock, int enable);
-       __pxa_set_cken(clock, enable);
-}
-
 /*
  * return current memory and LCD clock frequency in units of 10kHz
  */
index 99f4f42..0a50c3c 100644 (file)
@@ -16,4 +16,8 @@ struct pxaficp_platform_data {
 
 extern void pxa_set_ficp_info(struct pxaficp_platform_data *info);
 
+#if defined(CONFIG_PXA25x) || defined(CONFIG_PXA27x)
+void pxa2xx_transceiver_mode(struct device *dev, int mode);
+#endif
+
 #endif
index 4b2ea1e..dce9308 100644 (file)
 #define SMC_REG_BASE   __REG(0x40500500)  /* Secondary Modem Codec */
 
 
-/*
- * USB Device Controller
- * PXA25x and PXA27x USB device controller registers are different.
- */
-#if defined(CONFIG_PXA25x)
-
-#define UDC_RES1       __REG(0x40600004)  /* UDC Undocumented - Reserved1 */
-#define UDC_RES2       __REG(0x40600008)  /* UDC Undocumented - Reserved2 */
-#define UDC_RES3       __REG(0x4060000C)  /* UDC Undocumented - Reserved3 */
-
-#define UDCCR          __REG(0x40600000)  /* UDC Control Register */
-#define UDCCR_UDE      (1 << 0)        /* UDC enable */
-#define UDCCR_UDA      (1 << 1)        /* UDC active */
-#define UDCCR_RSM      (1 << 2)        /* Device resume */
-#define UDCCR_RESIR    (1 << 3)        /* Resume interrupt request */
-#define UDCCR_SUSIR    (1 << 4)        /* Suspend interrupt request */
-#define UDCCR_SRM      (1 << 5)        /* Suspend/resume interrupt mask */
-#define UDCCR_RSTIR    (1 << 6)        /* Reset interrupt request */
-#define UDCCR_REM      (1 << 7)        /* Reset interrupt mask */
-
-#define UDCCS0         __REG(0x40600010)  /* UDC Endpoint 0 Control/Status Register */
-#define UDCCS0_OPR     (1 << 0)        /* OUT packet ready */
-#define UDCCS0_IPR     (1 << 1)        /* IN packet ready */
-#define UDCCS0_FTF     (1 << 2)        /* Flush Tx FIFO */
-#define UDCCS0_DRWF    (1 << 3)        /* Device remote wakeup feature */
-#define UDCCS0_SST     (1 << 4)        /* Sent stall */
-#define UDCCS0_FST     (1 << 5)        /* Force stall */
-#define UDCCS0_RNE     (1 << 6)        /* Receive FIFO no empty */
-#define UDCCS0_SA      (1 << 7)        /* Setup active */
-
-/* Bulk IN - Endpoint 1,6,11 */
-#define UDCCS1         __REG(0x40600014)  /* UDC Endpoint 1 (IN) Control/Status Register */
-#define UDCCS6         __REG(0x40600028)  /* UDC Endpoint 6 (IN) Control/Status Register */
-#define UDCCS11                __REG(0x4060003C)  /* UDC Endpoint 11 (IN) Control/Status Register */
-
-#define UDCCS_BI_TFS   (1 << 0)        /* Transmit FIFO service */
-#define UDCCS_BI_TPC   (1 << 1)        /* Transmit packet complete */
-#define UDCCS_BI_FTF   (1 << 2)        /* Flush Tx FIFO */
-#define UDCCS_BI_TUR   (1 << 3)        /* Transmit FIFO underrun */
-#define UDCCS_BI_SST   (1 << 4)        /* Sent stall */
-#define UDCCS_BI_FST   (1 << 5)        /* Force stall */
-#define UDCCS_BI_TSP   (1 << 7)        /* Transmit short packet */
-
-/* Bulk OUT - Endpoint 2,7,12 */
-#define UDCCS2         __REG(0x40600018)  /* UDC Endpoint 2 (OUT) Control/Status Register */
-#define UDCCS7         __REG(0x4060002C)  /* UDC Endpoint 7 (OUT) Control/Status Register */
-#define UDCCS12                __REG(0x40600040)  /* UDC Endpoint 12 (OUT) Control/Status Register */
-
-#define UDCCS_BO_RFS   (1 << 0)        /* Receive FIFO service */
-#define UDCCS_BO_RPC   (1 << 1)        /* Receive packet complete */
-#define UDCCS_BO_DME   (1 << 3)        /* DMA enable */
-#define UDCCS_BO_SST   (1 << 4)        /* Sent stall */
-#define UDCCS_BO_FST   (1 << 5)        /* Force stall */
-#define UDCCS_BO_RNE   (1 << 6)        /* Receive FIFO not empty */
-#define UDCCS_BO_RSP   (1 << 7)        /* Receive short packet */
-
-/* Isochronous IN - Endpoint 3,8,13 */
-#define UDCCS3         __REG(0x4060001C)  /* UDC Endpoint 3 (IN) Control/Status Register */
-#define UDCCS8         __REG(0x40600030)  /* UDC Endpoint 8 (IN) Control/Status Register */
-#define UDCCS13                __REG(0x40600044)  /* UDC Endpoint 13 (IN) Control/Status Register */
-
-#define UDCCS_II_TFS   (1 << 0)        /* Transmit FIFO service */
-#define UDCCS_II_TPC   (1 << 1)        /* Transmit packet complete */
-#define UDCCS_II_FTF   (1 << 2)        /* Flush Tx FIFO */
-#define UDCCS_II_TUR   (1 << 3)        /* Transmit FIFO underrun */
-#define UDCCS_II_TSP   (1 << 7)        /* Transmit short packet */
-
-/* Isochronous OUT - Endpoint 4,9,14 */
-#define UDCCS4         __REG(0x40600020)  /* UDC Endpoint 4 (OUT) Control/Status Register */
-#define UDCCS9         __REG(0x40600034)  /* UDC Endpoint 9 (OUT) Control/Status Register */
-#define UDCCS14                __REG(0x40600048)  /* UDC Endpoint 14 (OUT) Control/Status Register */
-
-#define UDCCS_IO_RFS   (1 << 0)        /* Receive FIFO service */
-#define UDCCS_IO_RPC   (1 << 1)        /* Receive packet complete */
-#define UDCCS_IO_ROF   (1 << 2)        /* Receive overflow */
-#define UDCCS_IO_DME   (1 << 3)        /* DMA enable */
-#define UDCCS_IO_RNE   (1 << 6)        /* Receive FIFO not empty */
-#define UDCCS_IO_RSP   (1 << 7)        /* Receive short packet */
-
-/* Interrupt IN - Endpoint 5,10,15 */
-#define UDCCS5         __REG(0x40600024)  /* UDC Endpoint 5 (Interrupt) Control/Status Register */
-#define UDCCS10                __REG(0x40600038)  /* UDC Endpoint 10 (Interrupt) Control/Status Register */
-#define UDCCS15                __REG(0x4060004C)  /* UDC Endpoint 15 (Interrupt) Control/Status Register */
-
-#define UDCCS_INT_TFS  (1 << 0)        /* Transmit FIFO service */
-#define UDCCS_INT_TPC  (1 << 1)        /* Transmit packet complete */
-#define UDCCS_INT_FTF  (1 << 2)        /* Flush Tx FIFO */
-#define UDCCS_INT_TUR  (1 << 3)        /* Transmit FIFO underrun */
-#define UDCCS_INT_SST  (1 << 4)        /* Sent stall */
-#define UDCCS_INT_FST  (1 << 5)        /* Force stall */
-#define UDCCS_INT_TSP  (1 << 7)        /* Transmit short packet */
-
-#define UFNRH          __REG(0x40600060)  /* UDC Frame Number Register High */
-#define UFNRL          __REG(0x40600064)  /* UDC Frame Number Register Low */
-#define UBCR2          __REG(0x40600068)  /* UDC Byte Count Reg 2 */
-#define UBCR4          __REG(0x4060006c)  /* UDC Byte Count Reg 4 */
-#define UBCR7          __REG(0x40600070)  /* UDC Byte Count Reg 7 */
-#define UBCR9          __REG(0x40600074)  /* UDC Byte Count Reg 9 */
-#define UBCR12         __REG(0x40600078)  /* UDC Byte Count Reg 12 */
-#define UBCR14         __REG(0x4060007c)  /* UDC Byte Count Reg 14 */
-#define UDDR0          __REG(0x40600080)  /* UDC Endpoint 0 Data Register */
-#define UDDR1          __REG(0x40600100)  /* UDC Endpoint 1 Data Register */
-#define UDDR2          __REG(0x40600180)  /* UDC Endpoint 2 Data Register */
-#define UDDR3          __REG(0x40600200)  /* UDC Endpoint 3 Data Register */
-#define UDDR4          __REG(0x40600400)  /* UDC Endpoint 4 Data Register */
-#define UDDR5          __REG(0x406000A0)  /* UDC Endpoint 5 Data Register */
-#define UDDR6          __REG(0x40600600)  /* UDC Endpoint 6 Data Register */
-#define UDDR7          __REG(0x40600680)  /* UDC Endpoint 7 Data Register */
-#define UDDR8          __REG(0x40600700)  /* UDC Endpoint 8 Data Register */
-#define UDDR9          __REG(0x40600900)  /* UDC Endpoint 9 Data Register */
-#define UDDR10         __REG(0x406000C0)  /* UDC Endpoint 10 Data Register */
-#define UDDR11         __REG(0x40600B00)  /* UDC Endpoint 11 Data Register */
-#define UDDR12         __REG(0x40600B80)  /* UDC Endpoint 12 Data Register */
-#define UDDR13         __REG(0x40600C00)  /* UDC Endpoint 13 Data Register */
-#define UDDR14         __REG(0x40600E00)  /* UDC Endpoint 14 Data Register */
-#define UDDR15         __REG(0x406000E0)  /* UDC Endpoint 15 Data Register */
-
-#define UICR0          __REG(0x40600050)  /* UDC Interrupt Control Register 0 */
-
-#define UICR0_IM0      (1 << 0)        /* Interrupt mask ep 0 */
-#define UICR0_IM1      (1 << 1)        /* Interrupt mask ep 1 */
-#define UICR0_IM2      (1 << 2)        /* Interrupt mask ep 2 */
-#define UICR0_IM3      (1 << 3)        /* Interrupt mask ep 3 */
-#define UICR0_IM4      (1 << 4)        /* Interrupt mask ep 4 */
-#define UICR0_IM5      (1 << 5)        /* Interrupt mask ep 5 */
-#define UICR0_IM6      (1 << 6)        /* Interrupt mask ep 6 */
-#define UICR0_IM7      (1 << 7)        /* Interrupt mask ep 7 */
-
-#define UICR1          __REG(0x40600054)  /* UDC Interrupt Control Register 1 */
-
-#define UICR1_IM8      (1 << 0)        /* Interrupt mask ep 8 */
-#define UICR1_IM9      (1 << 1)        /* Interrupt mask ep 9 */
-#define UICR1_IM10     (1 << 2)        /* Interrupt mask ep 10 */
-#define UICR1_IM11     (1 << 3)        /* Interrupt mask ep 11 */
-#define UICR1_IM12     (1 << 4)        /* Interrupt mask ep 12 */
-#define UICR1_IM13     (1 << 5)        /* Interrupt mask ep 13 */
-#define UICR1_IM14     (1 << 6)        /* Interrupt mask ep 14 */
-#define UICR1_IM15     (1 << 7)        /* Interrupt mask ep 15 */
-
-#define USIR0          __REG(0x40600058)  /* UDC Status Interrupt Register 0 */
-
-#define USIR0_IR0      (1 << 0)        /* Interrupt request ep 0 */
-#define USIR0_IR1      (1 << 1)        /* Interrupt request ep 1 */
-#define USIR0_IR2      (1 << 2)        /* Interrupt request ep 2 */
-#define USIR0_IR3      (1 << 3)        /* Interrupt request ep 3 */
-#define USIR0_IR4      (1 << 4)        /* Interrupt request ep 4 */
-#define USIR0_IR5      (1 << 5)        /* Interrupt request ep 5 */
-#define USIR0_IR6      (1 << 6)        /* Interrupt request ep 6 */
-#define USIR0_IR7      (1 << 7)        /* Interrupt request ep 7 */
-
-#define USIR1          __REG(0x4060005C)  /* UDC Status Interrupt Register 1 */
-
-#define USIR1_IR8      (1 << 0)        /* Interrupt request ep 8 */
-#define USIR1_IR9      (1 << 1)        /* Interrupt request ep 9 */
-#define USIR1_IR10     (1 << 2)        /* Interrupt request ep 10 */
-#define USIR1_IR11     (1 << 3)        /* Interrupt request ep 11 */
-#define USIR1_IR12     (1 << 4)        /* Interrupt request ep 12 */
-#define USIR1_IR13     (1 << 5)        /* Interrupt request ep 13 */
-#define USIR1_IR14     (1 << 6)        /* Interrupt request ep 14 */
-#define USIR1_IR15     (1 << 7)        /* Interrupt request ep 15 */
-
-#elif defined(CONFIG_PXA27x)
-
-#define UDCCR           __REG(0x40600000) /* UDC Control Register */
-#define UDCCR_OEN      (1 << 31)       /* On-the-Go Enable */
-#define UDCCR_AALTHNP  (1 << 30)       /* A-device Alternate Host Negotiation
-                                          Protocol Port Support */
-#define UDCCR_AHNP     (1 << 29)       /* A-device Host Negotiation Protocol
-                                          Support */
-#define UDCCR_BHNP     (1 << 28)       /* B-device Host Negotiation Protocol
-                                          Enable */
-#define UDCCR_DWRE     (1 << 16)       /* Device Remote Wake-up Enable */
-#define UDCCR_ACN      (0x03 << 11)    /* Active UDC configuration Number */
-#define UDCCR_ACN_S    11
-#define UDCCR_AIN      (0x07 << 8)     /* Active UDC interface Number */
-#define UDCCR_AIN_S    8
-#define UDCCR_AAISN    (0x07 << 5)     /* Active UDC Alternate Interface
-                                          Setting Number */
-#define UDCCR_AAISN_S  5
-#define UDCCR_SMAC     (1 << 4)        /* Switch Endpoint Memory to Active
-                                          Configuration */
-#define UDCCR_EMCE     (1 << 3)        /* Endpoint Memory Configuration
-                                          Error */
-#define UDCCR_UDR      (1 << 2)        /* UDC Resume */
-#define UDCCR_UDA      (1 << 1)        /* UDC Active */
-#define UDCCR_UDE      (1 << 0)        /* UDC Enable */
-
-#define UDCICR0         __REG(0x40600004) /* UDC Interrupt Control Register0 */
-#define UDCICR1         __REG(0x40600008) /* UDC Interrupt Control Register1 */
-#define UDCICR_FIFOERR (1 << 1)        /* FIFO Error interrupt for EP */
-#define UDCICR_PKTCOMPL (1 << 0)       /* Packet Complete interrupt for EP */
-
-#define UDC_INT_FIFOERROR  (0x2)
-#define UDC_INT_PACKETCMP  (0x1)
-
-#define UDCICR_INT(n,intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
-#define UDCICR1_IECC   (1 << 31)       /* IntEn - Configuration Change */
-#define UDCICR1_IESOF  (1 << 30)       /* IntEn - Start of Frame */
-#define UDCICR1_IERU   (1 << 29)       /* IntEn - Resume */
-#define UDCICR1_IESU   (1 << 28)       /* IntEn - Suspend */
-#define UDCICR1_IERS   (1 << 27)       /* IntEn - Reset */
-
-#define UDCISR0         __REG(0x4060000C) /* UDC Interrupt Status Register 0 */
-#define UDCISR1         __REG(0x40600010) /* UDC Interrupt Status Register 1 */
-#define UDCISR_INT(n,intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
-#define UDCISR1_IRCC   (1 << 31)       /* IntReq - Configuration Change */
-#define UDCISR1_IRSOF  (1 << 30)       /* IntReq - Start of Frame */
-#define UDCISR1_IRRU   (1 << 29)       /* IntReq - Resume */
-#define UDCISR1_IRSU   (1 << 28)       /* IntReq - Suspend */
-#define UDCISR1_IRRS   (1 << 27)       /* IntReq - Reset */
-
-#define UDCFNR          __REG(0x40600014) /* UDC Frame Number Register */
-#define UDCOTGICR      __REG(0x40600018) /* UDC On-The-Go interrupt control */
-#define UDCOTGICR_IESF (1 << 24)       /* OTG SET_FEATURE command recvd */
-#define UDCOTGICR_IEXR (1 << 17)       /* Extra Transciever Interrupt
-                                          Rising Edge Interrupt Enable */
-#define UDCOTGICR_IEXF (1 << 16)       /* Extra Transciever Interrupt
-                                          Falling Edge Interrupt Enable */
-#define UDCOTGICR_IEVV40R (1 << 9)     /* OTG Vbus Valid 4.0V Rising Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IEVV40F (1 << 8)     /* OTG Vbus Valid 4.0V Falling Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IEVV44R (1 << 7)     /* OTG Vbus Valid 4.4V Rising Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IEVV44F (1 << 6)     /* OTG Vbus Valid 4.4V Falling Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IESVR        (1 << 5)        /* OTG Session Valid Rising Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IESVF        (1 << 4)        /* OTG Session Valid Falling Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IESDR        (1 << 3)        /* OTG A-Device SRP Detect Rising
-                                          Edge Interrupt Enable */
-#define UDCOTGICR_IESDF        (1 << 2)        /* OTG A-Device SRP Detect Falling
-                                          Edge Interrupt Enable */
-#define UDCOTGICR_IEIDR        (1 << 1)        /* OTG ID Change Rising Edge
-                                          Interrupt Enable */
-#define UDCOTGICR_IEIDF        (1 << 0)        /* OTG ID Change Falling Edge
-                                          Interrupt Enable */
-
-#define UP2OCR           __REG(0x40600020)  /* USB Port 2 Output Control register */
-
-#define UP2OCR_CPVEN   (1 << 0)        /* Charge Pump Vbus Enable */
-#define UP2OCR_CPVPE   (1 << 1)        /* Charge Pump Vbus Pulse Enable */
-#define UP2OCR_DPPDE   (1 << 2)        /* Host Port 2 Transceiver D+ Pull Down Enable */
-#define UP2OCR_DMPDE   (1 << 3)        /* Host Port 2 Transceiver D- Pull Down Enable */
-#define UP2OCR_DPPUE   (1 << 4)        /* Host Port 2 Transceiver D+ Pull Up Enable */
-#define UP2OCR_DMPUE   (1 << 5)        /* Host Port 2 Transceiver D- Pull Up Enable */
-#define UP2OCR_DPPUBE  (1 << 6)        /* Host Port 2 Transceiver D+ Pull Up Bypass Enable */
-#define UP2OCR_DMPUBE  (1 << 7)        /* Host Port 2 Transceiver D- Pull Up Bypass Enable */
-#define UP2OCR_EXSP            (1 << 8)        /* External Transceiver Speed Control */
-#define UP2OCR_EXSUS   (1 << 9)        /* External Transceiver Speed Enable */
-#define UP2OCR_IDON            (1 << 10)       /* OTG ID Read Enable */
-#define UP2OCR_HXS             (1 << 16)       /* Host Port 2 Transceiver Output Select */
-#define UP2OCR_HXOE            (1 << 17)       /* Host Port 2 Transceiver Output Enable */
-#define UP2OCR_SEOS            (1 << 24)       /* Single-Ended Output Select */
-
-#define UDCCSN(x)      __REG2(0x40600100, (x) << 2)
-#define UDCCSR0         __REG(0x40600100) /* UDC Control/Status register - Endpoint 0 */
-#define UDCCSR0_SA     (1 << 7)        /* Setup Active */
-#define UDCCSR0_RNE    (1 << 6)        /* Receive FIFO Not Empty */
-#define UDCCSR0_FST    (1 << 5)        /* Force Stall */
-#define UDCCSR0_SST    (1 << 4)        /* Sent Stall */
-#define UDCCSR0_DME    (1 << 3)        /* DMA Enable */
-#define UDCCSR0_FTF    (1 << 2)        /* Flush Transmit FIFO */
-#define UDCCSR0_IPR    (1 << 1)        /* IN Packet Ready */
-#define UDCCSR0_OPC    (1 << 0)        /* OUT Packet Complete */
-
-#define UDCCSRA         __REG(0x40600104) /* UDC Control/Status register - Endpoint A */
-#define UDCCSRB         __REG(0x40600108) /* UDC Control/Status register - Endpoint B */
-#define UDCCSRC         __REG(0x4060010C) /* UDC Control/Status register - Endpoint C */
-#define UDCCSRD         __REG(0x40600110) /* UDC Control/Status register - Endpoint D */
-#define UDCCSRE         __REG(0x40600114) /* UDC Control/Status register - Endpoint E */
-#define UDCCSRF         __REG(0x40600118) /* UDC Control/Status register - Endpoint F */
-#define UDCCSRG         __REG(0x4060011C) /* UDC Control/Status register - Endpoint G */
-#define UDCCSRH         __REG(0x40600120) /* UDC Control/Status register - Endpoint H */
-#define UDCCSRI         __REG(0x40600124) /* UDC Control/Status register - Endpoint I */
-#define UDCCSRJ         __REG(0x40600128) /* UDC Control/Status register - Endpoint J */
-#define UDCCSRK         __REG(0x4060012C) /* UDC Control/Status register - Endpoint K */
-#define UDCCSRL         __REG(0x40600130) /* UDC Control/Status register - Endpoint L */
-#define UDCCSRM         __REG(0x40600134) /* UDC Control/Status register - Endpoint M */
-#define UDCCSRN         __REG(0x40600138) /* UDC Control/Status register - Endpoint N */
-#define UDCCSRP         __REG(0x4060013C) /* UDC Control/Status register - Endpoint P */
-#define UDCCSRQ         __REG(0x40600140) /* UDC Control/Status register - Endpoint Q */
-#define UDCCSRR         __REG(0x40600144) /* UDC Control/Status register - Endpoint R */
-#define UDCCSRS         __REG(0x40600148) /* UDC Control/Status register - Endpoint S */
-#define UDCCSRT         __REG(0x4060014C) /* UDC Control/Status register - Endpoint T */
-#define UDCCSRU         __REG(0x40600150) /* UDC Control/Status register - Endpoint U */
-#define UDCCSRV         __REG(0x40600154) /* UDC Control/Status register - Endpoint V */
-#define UDCCSRW         __REG(0x40600158) /* UDC Control/Status register - Endpoint W */
-#define UDCCSRX         __REG(0x4060015C) /* UDC Control/Status register - Endpoint X */
-
-#define UDCCSR_DPE     (1 << 9)        /* Data Packet Error */
-#define UDCCSR_FEF     (1 << 8)        /* Flush Endpoint FIFO */
-#define UDCCSR_SP      (1 << 7)        /* Short Packet Control/Status */
-#define UDCCSR_BNE     (1 << 6)        /* Buffer Not Empty (IN endpoints) */
-#define UDCCSR_BNF     (1 << 6)        /* Buffer Not Full (OUT endpoints) */
-#define UDCCSR_FST     (1 << 5)        /* Force STALL */
-#define UDCCSR_SST     (1 << 4)        /* Sent STALL */
-#define UDCCSR_DME     (1 << 3)        /* DMA Enable */
-#define UDCCSR_TRN     (1 << 2)        /* Tx/Rx NAK */
-#define UDCCSR_PC      (1 << 1)        /* Packet Complete */
-#define UDCCSR_FS      (1 << 0)        /* FIFO needs service */
-
-#define UDCBCN(x)      __REG2(0x40600200, (x)<<2)
-#define UDCBCR0         __REG(0x40600200) /* Byte Count Register - EP0 */
-#define UDCBCRA         __REG(0x40600204) /* Byte Count Register - EPA */
-#define UDCBCRB         __REG(0x40600208) /* Byte Count Register - EPB */
-#define UDCBCRC         __REG(0x4060020C) /* Byte Count Register - EPC */
-#define UDCBCRD         __REG(0x40600210) /* Byte Count Register - EPD */
-#define UDCBCRE         __REG(0x40600214) /* Byte Count Register - EPE */
-#define UDCBCRF         __REG(0x40600218) /* Byte Count Register - EPF */
-#define UDCBCRG         __REG(0x4060021C) /* Byte Count Register - EPG */
-#define UDCBCRH         __REG(0x40600220) /* Byte Count Register - EPH */
-#define UDCBCRI         __REG(0x40600224) /* Byte Count Register - EPI */
-#define UDCBCRJ         __REG(0x40600228) /* Byte Count Register - EPJ */
-#define UDCBCRK         __REG(0x4060022C) /* Byte Count Register - EPK */
-#define UDCBCRL         __REG(0x40600230) /* Byte Count Register - EPL */
-#define UDCBCRM         __REG(0x40600234) /* Byte Count Register - EPM */
-#define UDCBCRN         __REG(0x40600238) /* Byte Count Register - EPN */
-#define UDCBCRP         __REG(0x4060023C) /* Byte Count Register - EPP */
-#define UDCBCRQ         __REG(0x40600240) /* Byte Count Register - EPQ */
-#define UDCBCRR         __REG(0x40600244) /* Byte Count Register - EPR */
-#define UDCBCRS         __REG(0x40600248) /* Byte Count Register - EPS */
-#define UDCBCRT         __REG(0x4060024C) /* Byte Count Register - EPT */
-#define UDCBCRU         __REG(0x40600250) /* Byte Count Register - EPU */
-#define UDCBCRV         __REG(0x40600254) /* Byte Count Register - EPV */
-#define UDCBCRW         __REG(0x40600258) /* Byte Count Register - EPW */
-#define UDCBCRX         __REG(0x4060025C) /* Byte Count Register - EPX */
-
-#define UDCDN(x)       __REG2(0x40600300, (x)<<2)
-#define PHYS_UDCDN(x)  (0x40600300 + ((x)<<2))
-#define PUDCDN(x)      (volatile u32 *)(io_p2v(PHYS_UDCDN((x))))
-#define UDCDR0          __REG(0x40600300) /* Data Register - EP0 */
-#define UDCDRA          __REG(0x40600304) /* Data Register - EPA */
-#define UDCDRB          __REG(0x40600308) /* Data Register - EPB */
-#define UDCDRC          __REG(0x4060030C) /* Data Register - EPC */
-#define UDCDRD          __REG(0x40600310) /* Data Register - EPD */
-#define UDCDRE          __REG(0x40600314) /* Data Register - EPE */
-#define UDCDRF          __REG(0x40600318) /* Data Register - EPF */
-#define UDCDRG          __REG(0x4060031C) /* Data Register - EPG */
-#define UDCDRH          __REG(0x40600320) /* Data Register - EPH */
-#define UDCDRI          __REG(0x40600324) /* Data Register - EPI */
-#define UDCDRJ          __REG(0x40600328) /* Data Register - EPJ */
-#define UDCDRK          __REG(0x4060032C) /* Data Register - EPK */
-#define UDCDRL          __REG(0x40600330) /* Data Register - EPL */
-#define UDCDRM          __REG(0x40600334) /* Data Register - EPM */
-#define UDCDRN          __REG(0x40600338) /* Data Register - EPN */
-#define UDCDRP          __REG(0x4060033C) /* Data Register - EPP */
-#define UDCDRQ          __REG(0x40600340) /* Data Register - EPQ */
-#define UDCDRR          __REG(0x40600344) /* Data Register - EPR */
-#define UDCDRS          __REG(0x40600348) /* Data Register - EPS */
-#define UDCDRT          __REG(0x4060034C) /* Data Register - EPT */
-#define UDCDRU          __REG(0x40600350) /* Data Register - EPU */
-#define UDCDRV          __REG(0x40600354) /* Data Register - EPV */
-#define UDCDRW          __REG(0x40600358) /* Data Register - EPW */
-#define UDCDRX          __REG(0x4060035C) /* Data Register - EPX */
-
-#define UDCCN(x)       __REG2(0x40600400, (x)<<2)
-#define UDCCRA          __REG(0x40600404) /* Configuration register EPA */
-#define UDCCRB          __REG(0x40600408) /* Configuration register EPB */
-#define UDCCRC          __REG(0x4060040C) /* Configuration register EPC */
-#define UDCCRD          __REG(0x40600410) /* Configuration register EPD */
-#define UDCCRE          __REG(0x40600414) /* Configuration register EPE */
-#define UDCCRF          __REG(0x40600418) /* Configuration register EPF */
-#define UDCCRG          __REG(0x4060041C) /* Configuration register EPG */
-#define UDCCRH          __REG(0x40600420) /* Configuration register EPH */
-#define UDCCRI          __REG(0x40600424) /* Configuration register EPI */
-#define UDCCRJ          __REG(0x40600428) /* Configuration register EPJ */
-#define UDCCRK          __REG(0x4060042C) /* Configuration register EPK */
-#define UDCCRL          __REG(0x40600430) /* Configuration register EPL */
-#define UDCCRM          __REG(0x40600434) /* Configuration register EPM */
-#define UDCCRN          __REG(0x40600438) /* Configuration register EPN */
-#define UDCCRP          __REG(0x4060043C) /* Configuration register EPP */
-#define UDCCRQ          __REG(0x40600440) /* Configuration register EPQ */
-#define UDCCRR          __REG(0x40600444) /* Configuration register EPR */
-#define UDCCRS          __REG(0x40600448) /* Configuration register EPS */
-#define UDCCRT          __REG(0x4060044C) /* Configuration register EPT */
-#define UDCCRU          __REG(0x40600450) /* Configuration register EPU */
-#define UDCCRV          __REG(0x40600454) /* Configuration register EPV */
-#define UDCCRW          __REG(0x40600458) /* Configuration register EPW */
-#define UDCCRX          __REG(0x4060045C) /* Configuration register EPX */
-
-#define UDCCONR_CN     (0x03 << 25)    /* Configuration Number */
-#define UDCCONR_CN_S   (25)
-#define UDCCONR_IN     (0x07 << 22)    /* Interface Number */
-#define UDCCONR_IN_S   (22)
-#define UDCCONR_AISN   (0x07 << 19)    /* Alternate Interface Number */
-#define UDCCONR_AISN_S (19)
-#define UDCCONR_EN     (0x0f << 15)    /* Endpoint Number */
-#define UDCCONR_EN_S   (15)
-#define UDCCONR_ET     (0x03 << 13)    /* Endpoint Type: */
-#define UDCCONR_ET_S   (13)
-#define UDCCONR_ET_INT (0x03 << 13)    /*   Interrupt */
-#define UDCCONR_ET_BULK        (0x02 << 13)    /*   Bulk */
-#define UDCCONR_ET_ISO (0x01 << 13)    /*   Isochronous */
-#define UDCCONR_ET_NU  (0x00 << 13)    /*   Not used */
-#define UDCCONR_ED     (1 << 12)       /* Endpoint Direction */
-#define UDCCONR_MPS    (0x3ff << 2)    /* Maximum Packet Size */
-#define UDCCONR_MPS_S  (2)
-#define UDCCONR_DE     (1 << 1)        /* Double Buffering Enable */
-#define UDCCONR_EE     (1 << 0)        /* Endpoint Enable */
-
-
-#define UDC_INT_FIFOERROR  (0x2)
-#define UDC_INT_PACKETCMP  (0x1)
-
-#define UDC_FNR_MASK     (0x7ff)
-
-#define UDCCSR_WR_MASK   (UDCCSR_DME|UDCCSR_FST)
-#define UDC_BCR_MASK    (0x3ff)
-#endif
-
 /*
  * Fast Infrared Communication Port
  */
 #endif
 
 /*
- * Power Manager
+ * Power Manager - see pxa2xx-regs.h
  */
 
-#define PMCR           __REG(0x40F00000)  /* Power Manager Control Register */
-#define PSSR           __REG(0x40F00004)  /* Power Manager Sleep Status Register */
-#define PSPR           __REG(0x40F00008)  /* Power Manager Scratch Pad Register */
-#define PWER           __REG(0x40F0000C)  /* Power Manager Wake-up Enable Register */
-#define PRER           __REG(0x40F00010)  /* Power Manager GPIO Rising-Edge Detect Enable Register */
-#define PFER           __REG(0x40F00014)  /* Power Manager GPIO Falling-Edge Detect Enable Register */
-#define PEDR           __REG(0x40F00018)  /* Power Manager GPIO Edge Detect Status Register */
-#define PCFR           __REG(0x40F0001C)  /* Power Manager General Configuration Register */
-#define PGSR0          __REG(0x40F00020)  /* Power Manager GPIO Sleep State Register for GP[31-0] */
-#define PGSR1          __REG(0x40F00024)  /* Power Manager GPIO Sleep State Register for GP[63-32] */
-#define PGSR2          __REG(0x40F00028)  /* Power Manager GPIO Sleep State Register for GP[84-64] */
-#define PGSR3          __REG(0x40F0002C)  /* Power Manager GPIO Sleep State Register for GP[118-96] */
-#define RCSR           __REG(0x40F00030)  /* Reset Controller Status Register */
-
-#define PSLR           __REG(0x40F00034)       /* Power Manager Sleep Config Register */
-#define PSTR           __REG(0x40F00038)       /*Power Manager Standby Config Register */
-#define PSNR           __REG(0x40F0003C)       /*Power Manager Sense Config Register */
-#define PVCR           __REG(0x40F00040)       /*Power Manager VoltageControl Register */
-#define PKWR           __REG(0x40F00050)       /* Power Manager KB Wake-up Enable Reg */
-#define PKSR           __REG(0x40F00054)       /* Power Manager KB Level-Detect Register */
-#define PCMD(x)        __REG2(0x40F00080, (x)<<2)
-#define PCMD0  __REG(0x40F00080 + 0 * 4)
-#define PCMD1  __REG(0x40F00080 + 1 * 4)
-#define PCMD2  __REG(0x40F00080 + 2 * 4)
-#define PCMD3  __REG(0x40F00080 + 3 * 4)
-#define PCMD4  __REG(0x40F00080 + 4 * 4)
-#define PCMD5  __REG(0x40F00080 + 5 * 4)
-#define PCMD6  __REG(0x40F00080 + 6 * 4)
-#define PCMD7  __REG(0x40F00080 + 7 * 4)
-#define PCMD8  __REG(0x40F00080 + 8 * 4)
-#define PCMD9  __REG(0x40F00080 + 9 * 4)
-#define PCMD10 __REG(0x40F00080 + 10 * 4)
-#define PCMD11 __REG(0x40F00080 + 11 * 4)
-#define PCMD12 __REG(0x40F00080 + 12 * 4)
-#define PCMD13 __REG(0x40F00080 + 13 * 4)
-#define PCMD14 __REG(0x40F00080 + 14 * 4)
-#define PCMD15 __REG(0x40F00080 + 15 * 4)
-#define PCMD16 __REG(0x40F00080 + 16 * 4)
-#define PCMD17 __REG(0x40F00080 + 17 * 4)
-#define PCMD18 __REG(0x40F00080 + 18 * 4)
-#define PCMD19 __REG(0x40F00080 + 19 * 4)
-#define PCMD20 __REG(0x40F00080 + 20 * 4)
-#define PCMD21 __REG(0x40F00080 + 21 * 4)
-#define PCMD22 __REG(0x40F00080 + 22 * 4)
-#define PCMD23 __REG(0x40F00080 + 23 * 4)
-#define PCMD24 __REG(0x40F00080 + 24 * 4)
-#define PCMD25 __REG(0x40F00080 + 25 * 4)
-#define PCMD26 __REG(0x40F00080 + 26 * 4)
-#define PCMD27 __REG(0x40F00080 + 27 * 4)
-#define PCMD28 __REG(0x40F00080 + 28 * 4)
-#define PCMD29 __REG(0x40F00080 + 29 * 4)
-#define PCMD30 __REG(0x40F00080 + 30 * 4)
-#define PCMD31 __REG(0x40F00080 + 31 * 4)
-
-#define PCMD_MBC       (1<<12)
-#define PCMD_DCE       (1<<11)
-#define PCMD_LC        (1<<10)
-/* FIXME:  PCMD_SQC need be checked.   */
-#define PCMD_SQC       (3<<8)  /* currently only bit 8 is changeable,
-                                  bit 9 should be 0 all day. */
-#define PVCR_VCSA      (0x1<<14)
-#define PVCR_CommandDelay (0xf80)
-#define PCFR_PI2C_EN   (0x1 << 6)
-
-#define PSSR_OTGPH     (1 << 6)        /* OTG Peripheral control Hold */
-#define PSSR_RDH       (1 << 5)        /* Read Disable Hold */
-#define PSSR_PH                (1 << 4)        /* Peripheral Control Hold */
-#define PSSR_STS       (1 << 3)        /* Standby Mode Status */
-#define PSSR_VFS       (1 << 2)        /* VDD Fault Status */
-#define PSSR_BFS       (1 << 1)        /* Battery Fault Status */
-#define PSSR_SSS       (1 << 0)        /* Software Sleep Status */
-
-#define PSLR_SL_ROD    (1 << 20)       /* Sleep-Mode/Depp-Sleep Mode nRESET_OUT Disable */
-
-#define PCFR_RO                (1 << 15)       /* RDH Override */
-#define PCFR_PO                (1 << 14)       /* PH Override */
-#define PCFR_GPROD     (1 << 12)       /* GPIO nRESET_OUT Disable */
-#define PCFR_L1_EN     (1 << 11)       /* Sleep Mode L1 converter Enable */
-#define PCFR_FVC       (1 << 10)       /* Frequency/Voltage Change */
-#define PCFR_DC_EN     (1 << 7)        /* Sleep/deep-sleep DC-DC Converter Enable */
-#define PCFR_PI2CEN    (1 << 6)        /* Enable PI2C controller */
-#define PCFR_GPR_EN    (1 << 4)        /* nRESET_GPIO Pin Enable */
-#define PCFR_DS                (1 << 3)        /* Deep Sleep Mode */
-#define PCFR_FS                (1 << 2)        /* Float Static Chip Selects */
-#define PCFR_FP                (1 << 1)        /* Float PCMCIA controls */
-#define PCFR_OPDE      (1 << 0)        /* 3.6864 MHz oscillator power-down enable */
-
-#define RCSR_GPR       (1 << 3)        /* GPIO Reset */
-#define RCSR_SMR       (1 << 2)        /* Sleep Mode */
-#define RCSR_WDR       (1 << 1)        /* Watchdog Reset */
-#define RCSR_HWR       (1 << 0)        /* Hardware Reset */
-
-#define PWER_GPIO(Nb)  (1 << Nb)       /* GPIO [0..15] wake-up enable     */
-#define PWER_GPIO0     PWER_GPIO (0)   /* GPIO  [0] wake-up enable        */
-#define PWER_GPIO1     PWER_GPIO (1)   /* GPIO  [1] wake-up enable        */
-#define PWER_GPIO2     PWER_GPIO (2)   /* GPIO  [2] wake-up enable        */
-#define PWER_GPIO3     PWER_GPIO (3)   /* GPIO  [3] wake-up enable        */
-#define PWER_GPIO4     PWER_GPIO (4)   /* GPIO  [4] wake-up enable        */
-#define PWER_GPIO5     PWER_GPIO (5)   /* GPIO  [5] wake-up enable        */
-#define PWER_GPIO6     PWER_GPIO (6)   /* GPIO  [6] wake-up enable        */
-#define PWER_GPIO7     PWER_GPIO (7)   /* GPIO  [7] wake-up enable        */
-#define PWER_GPIO8     PWER_GPIO (8)   /* GPIO  [8] wake-up enable        */
-#define PWER_GPIO9     PWER_GPIO (9)   /* GPIO  [9] wake-up enable        */
-#define PWER_GPIO10    PWER_GPIO (10)  /* GPIO [10] wake-up enable        */
-#define PWER_GPIO11    PWER_GPIO (11)  /* GPIO [11] wake-up enable        */
-#define PWER_GPIO12    PWER_GPIO (12)  /* GPIO [12] wake-up enable        */
-#define PWER_GPIO13    PWER_GPIO (13)  /* GPIO [13] wake-up enable        */
-#define PWER_GPIO14    PWER_GPIO (14)  /* GPIO [14] wake-up enable        */
-#define PWER_GPIO15    PWER_GPIO (15)  /* GPIO [15] wake-up enable        */
-#define PWER_RTC       0x80000000      /* RTC alarm wake-up enable        */
-
 /*
  * SSP Serial Port Registers - see include/asm-arm/arch-pxa/regs-ssp.h
  */
  */
 
 /*
- * Core Clock
+ * Core Clock - see include/asm-arm/arch-pxa/pxa2xx-regs.h
  */
 
-#define CCCR           __REG(0x41300000)  /* Core Clock Configuration Register */
-#define CKEN           __REG(0x41300004)  /* Clock Enable Register */
-#define OSCC           __REG(0x41300008)  /* Oscillator Configuration Register */
-#define CCSR           __REG(0x4130000C)  /* Core Clock Status Register */
-
-#define CCCR_N_MASK    0x0380          /* Run Mode Frequency to Turbo Mode Frequency Multiplier */
-#define CCCR_M_MASK    0x0060          /* Memory Frequency to Run Mode Frequency Multiplier */
-#define CCCR_L_MASK    0x001f          /* Crystal Frequency to Memory Frequency Multiplier */
-
-#define CKEN_AC97CONF   (31)    /* AC97 Controller Configuration */
-#define CKEN_CAMERA    (24)    /* Camera Interface Clock Enable */
-#define CKEN_SSP1      (23)    /* SSP1 Unit Clock Enable */
-#define CKEN_MEMC      (22)    /* Memory Controller Clock Enable */
-#define CKEN_MEMSTK    (21)    /* Memory Stick Host Controller */
-#define CKEN_IM                (20)    /* Internal Memory Clock Enable */
-#define CKEN_KEYPAD    (19)    /* Keypad Interface Clock Enable */
-#define CKEN_USIM      (18)    /* USIM Unit Clock Enable */
-#define CKEN_MSL       (17)    /* MSL Unit Clock Enable */
-#define CKEN_LCD       (16)    /* LCD Unit Clock Enable */
-#define CKEN_PWRI2C    (15)    /* PWR I2C Unit Clock Enable */
-#define CKEN_I2C       (14)    /* I2C Unit Clock Enable */
-#define CKEN_FICP      (13)    /* FICP Unit Clock Enable */
-#define CKEN_MMC       (12)    /* MMC Unit Clock Enable */
-#define CKEN_USB       (11)    /* USB Unit Clock Enable */
-#define CKEN_ASSP      (10)    /* ASSP (SSP3) Clock Enable */
-#define CKEN_USBHOST   (10)    /* USB Host Unit Clock Enable */
-#define CKEN_OSTIMER   (9)     /* OS Timer Unit Clock Enable */
-#define CKEN_NSSP      (9)     /* NSSP (SSP2) Clock Enable */
-#define CKEN_I2S       (8)     /* I2S Unit Clock Enable */
-#define CKEN_BTUART    (7)     /* BTUART Unit Clock Enable */
-#define CKEN_FFUART    (6)     /* FFUART Unit Clock Enable */
-#define CKEN_STUART    (5)     /* STUART Unit Clock Enable */
-#define CKEN_HWUART    (4)     /* HWUART Unit Clock Enable */
-#define CKEN_SSP3      (4)     /* SSP3 Unit Clock Enable */
-#define CKEN_SSP       (3)     /* SSP Unit Clock Enable */
-#define CKEN_SSP2      (3)     /* SSP2 Unit Clock Enable */
-#define CKEN_AC97      (2)     /* AC97 Unit Clock Enable */
-#define CKEN_PWM1      (1)     /* PWM1 Clock Enable */
-#define CKEN_PWM0      (0)     /* PWM0 Clock Enable */
-
-#define OSCC_OON       (1 << 1)        /* 32.768kHz OON (write-once only bit) */
-#define OSCC_OOK       (1 << 0)        /* 32.768kHz OOK (read-only bit) */
-
 #ifdef CONFIG_PXA27x
 
 /* Camera Interface */
diff --git a/include/asm-arm/arch-pxa/pxa25x-udc.h b/include/asm-arm/arch-pxa/pxa25x-udc.h
new file mode 100644 (file)
index 0000000..8403059
--- /dev/null
@@ -0,0 +1,163 @@
+#ifndef _ASM_ARCH_PXA25X_UDC_H
+#define _ASM_ARCH_PXA25X_UDC_H
+
+#ifdef _ASM_ARCH_PXA27X_UDC_H
+#error You can't include both PXA25x and PXA27x UDC support
+#endif
+
+#define UDC_RES1       __REG(0x40600004)  /* UDC Undocumented - Reserved1 */
+#define UDC_RES2       __REG(0x40600008)  /* UDC Undocumented - Reserved2 */
+#define UDC_RES3       __REG(0x4060000C)  /* UDC Undocumented - Reserved3 */
+
+#define UDCCR          __REG(0x40600000)  /* UDC Control Register */
+#define UDCCR_UDE      (1 << 0)        /* UDC enable */
+#define UDCCR_UDA      (1 << 1)        /* UDC active */
+#define UDCCR_RSM      (1 << 2)        /* Device resume */
+#define UDCCR_RESIR    (1 << 3)        /* Resume interrupt request */
+#define UDCCR_SUSIR    (1 << 4)        /* Suspend interrupt request */
+#define UDCCR_SRM      (1 << 5)        /* Suspend/resume interrupt mask */
+#define UDCCR_RSTIR    (1 << 6)        /* Reset interrupt request */
+#define UDCCR_REM      (1 << 7)        /* Reset interrupt mask */
+
+#define UDCCS0         __REG(0x40600010)  /* UDC Endpoint 0 Control/Status Register */
+#define UDCCS0_OPR     (1 << 0)        /* OUT packet ready */
+#define UDCCS0_IPR     (1 << 1)        /* IN packet ready */
+#define UDCCS0_FTF     (1 << 2)        /* Flush Tx FIFO */
+#define UDCCS0_DRWF    (1 << 3)        /* Device remote wakeup feature */
+#define UDCCS0_SST     (1 << 4)        /* Sent stall */
+#define UDCCS0_FST     (1 << 5)        /* Force stall */
+#define UDCCS0_RNE     (1 << 6)        /* Receive FIFO no empty */
+#define UDCCS0_SA      (1 << 7)        /* Setup active */
+
+/* Bulk IN - Endpoint 1,6,11 */
+#define UDCCS1         __REG(0x40600014)  /* UDC Endpoint 1 (IN) Control/Status Register */
+#define UDCCS6         __REG(0x40600028)  /* UDC Endpoint 6 (IN) Control/Status Register */
+#define UDCCS11                __REG(0x4060003C)  /* UDC Endpoint 11 (IN) Control/Status Register */
+
+#define UDCCS_BI_TFS   (1 << 0)        /* Transmit FIFO service */
+#define UDCCS_BI_TPC   (1 << 1)        /* Transmit packet complete */
+#define UDCCS_BI_FTF   (1 << 2)        /* Flush Tx FIFO */
+#define UDCCS_BI_TUR   (1 << 3)        /* Transmit FIFO underrun */
+#define UDCCS_BI_SST   (1 << 4)        /* Sent stall */
+#define UDCCS_BI_FST   (1 << 5)        /* Force stall */
+#define UDCCS_BI_TSP   (1 << 7)        /* Transmit short packet */
+
+/* Bulk OUT - Endpoint 2,7,12 */
+#define UDCCS2         __REG(0x40600018)  /* UDC Endpoint 2 (OUT) Control/Status Register */
+#define UDCCS7         __REG(0x4060002C)  /* UDC Endpoint 7 (OUT) Control/Status Register */
+#define UDCCS12                __REG(0x40600040)  /* UDC Endpoint 12 (OUT) Control/Status Register */
+
+#define UDCCS_BO_RFS   (1 << 0)        /* Receive FIFO service */
+#define UDCCS_BO_RPC   (1 << 1)        /* Receive packet complete */
+#define UDCCS_BO_DME   (1 << 3)        /* DMA enable */
+#define UDCCS_BO_SST   (1 << 4)        /* Sent stall */
+#define UDCCS_BO_FST   (1 << 5)        /* Force stall */
+#define UDCCS_BO_RNE   (1 << 6)        /* Receive FIFO not empty */
+#define UDCCS_BO_RSP   (1 << 7)        /* Receive short packet */
+
+/* Isochronous IN - Endpoint 3,8,13 */
+#define UDCCS3         __REG(0x4060001C)  /* UDC Endpoint 3 (IN) Control/Status Register */
+#define UDCCS8         __REG(0x40600030)  /* UDC Endpoint 8 (IN) Control/Status Register */
+#define UDCCS13                __REG(0x40600044)  /* UDC Endpoint 13 (IN) Control/Status Register */
+
+#define UDCCS_II_TFS   (1 << 0)        /* Transmit FIFO service */
+#define UDCCS_II_TPC   (1 << 1)        /* Transmit packet complete */
+#define UDCCS_II_FTF   (1 << 2)        /* Flush Tx FIFO */
+#define UDCCS_II_TUR   (1 << 3)        /* Transmit FIFO underrun */
+#define UDCCS_II_TSP   (1 << 7)        /* Transmit short packet */
+
+/* Isochronous OUT - Endpoint 4,9,14 */
+#define UDCCS4         __REG(0x40600020)  /* UDC Endpoint 4 (OUT) Control/Status Register */
+#define UDCCS9         __REG(0x40600034)  /* UDC Endpoint 9 (OUT) Control/Status Register */
+#define UDCCS14                __REG(0x40600048)  /* UDC Endpoint 14 (OUT) Control/Status Register */
+
+#define UDCCS_IO_RFS   (1 << 0)        /* Receive FIFO service */
+#define UDCCS_IO_RPC   (1 << 1)        /* Receive packet complete */
+#define UDCCS_IO_ROF   (1 << 2)        /* Receive overflow */
+#define UDCCS_IO_DME   (1 << 3)        /* DMA enable */
+#define UDCCS_IO_RNE   (1 << 6)        /* Receive FIFO not empty */
+#define UDCCS_IO_RSP   (1 << 7)        /* Receive short packet */
+
+/* Interrupt IN - Endpoint 5,10,15 */
+#define UDCCS5         __REG(0x40600024)  /* UDC Endpoint 5 (Interrupt) Control/Status Register */
+#define UDCCS10                __REG(0x40600038)  /* UDC Endpoint 10 (Interrupt) Control/Status Register */
+#define UDCCS15                __REG(0x4060004C)  /* UDC Endpoint 15 (Interrupt) Control/Status Register */
+
+#define UDCCS_INT_TFS  (1 << 0)        /* Transmit FIFO service */
+#define UDCCS_INT_TPC  (1 << 1)        /* Transmit packet complete */
+#define UDCCS_INT_FTF  (1 << 2)        /* Flush Tx FIFO */
+#define UDCCS_INT_TUR  (1 << 3)        /* Transmit FIFO underrun */
+#define UDCCS_INT_SST  (1 << 4)        /* Sent stall */
+#define UDCCS_INT_FST  (1 << 5)        /* Force stall */
+#define UDCCS_INT_TSP  (1 << 7)        /* Transmit short packet */
+
+#define UFNRH          __REG(0x40600060)  /* UDC Frame Number Register High */
+#define UFNRL          __REG(0x40600064)  /* UDC Frame Number Register Low */
+#define UBCR2          __REG(0x40600068)  /* UDC Byte Count Reg 2 */
+#define UBCR4          __REG(0x4060006c)  /* UDC Byte Count Reg 4 */
+#define UBCR7          __REG(0x40600070)  /* UDC Byte Count Reg 7 */
+#define UBCR9          __REG(0x40600074)  /* UDC Byte Count Reg 9 */
+#define UBCR12         __REG(0x40600078)  /* UDC Byte Count Reg 12 */
+#define UBCR14         __REG(0x4060007c)  /* UDC Byte Count Reg 14 */
+#define UDDR0          __REG(0x40600080)  /* UDC Endpoint 0 Data Register */
+#define UDDR1          __REG(0x40600100)  /* UDC Endpoint 1 Data Register */
+#define UDDR2          __REG(0x40600180)  /* UDC Endpoint 2 Data Register */
+#define UDDR3          __REG(0x40600200)  /* UDC Endpoint 3 Data Register */
+#define UDDR4          __REG(0x40600400)  /* UDC Endpoint 4 Data Register */
+#define UDDR5          __REG(0x406000A0)  /* UDC Endpoint 5 Data Register */
+#define UDDR6          __REG(0x40600600)  /* UDC Endpoint 6 Data Register */
+#define UDDR7          __REG(0x40600680)  /* UDC Endpoint 7 Data Register */
+#define UDDR8          __REG(0x40600700)  /* UDC Endpoint 8 Data Register */
+#define UDDR9          __REG(0x40600900)  /* UDC Endpoint 9 Data Register */
+#define UDDR10         __REG(0x406000C0)  /* UDC Endpoint 10 Data Register */
+#define UDDR11         __REG(0x40600B00)  /* UDC Endpoint 11 Data Register */
+#define UDDR12         __REG(0x40600B80)  /* UDC Endpoint 12 Data Register */
+#define UDDR13         __REG(0x40600C00)  /* UDC Endpoint 13 Data Register */
+#define UDDR14         __REG(0x40600E00)  /* UDC Endpoint 14 Data Register */
+#define UDDR15         __REG(0x406000E0)  /* UDC Endpoint 15 Data Register */
+
+#define UICR0          __REG(0x40600050)  /* UDC Interrupt Control Register 0 */
+
+#define UICR0_IM0      (1 << 0)        /* Interrupt mask ep 0 */
+#define UICR0_IM1      (1 << 1)        /* Interrupt mask ep 1 */
+#define UICR0_IM2      (1 << 2)        /* Interrupt mask ep 2 */
+#define UICR0_IM3      (1 << 3)        /* Interrupt mask ep 3 */
+#define UICR0_IM4      (1 << 4)        /* Interrupt mask ep 4 */
+#define UICR0_IM5      (1 << 5)        /* Interrupt mask ep 5 */
+#define UICR0_IM6      (1 << 6)        /* Interrupt mask ep 6 */
+#define UICR0_IM7      (1 << 7)        /* Interrupt mask ep 7 */
+
+#define UICR1          __REG(0x40600054)  /* UDC Interrupt Control Register 1 */
+
+#define UICR1_IM8      (1 << 0)        /* Interrupt mask ep 8 */
+#define UICR1_IM9      (1 << 1)        /* Interrupt mask ep 9 */
+#define UICR1_IM10     (1 << 2)        /* Interrupt mask ep 10 */
+#define UICR1_IM11     (1 << 3)        /* Interrupt mask ep 11 */
+#define UICR1_IM12     (1 << 4)        /* Interrupt mask ep 12 */
+#define UICR1_IM13     (1 << 5)        /* Interrupt mask ep 13 */
+#define UICR1_IM14     (1 << 6)        /* Interrupt mask ep 14 */
+#define UICR1_IM15     (1 << 7)        /* Interrupt mask ep 15 */
+
+#define USIR0          __REG(0x40600058)  /* UDC Status Interrupt Register 0 */
+
+#define USIR0_IR0      (1 << 0)        /* Interrupt request ep 0 */
+#define USIR0_IR1      (1 << 1)        /* Interrupt request ep 1 */
+#define USIR0_IR2      (1 << 2)        /* Interrupt request ep 2 */
+#define USIR0_IR3      (1 << 3)        /* Interrupt request ep 3 */
+#define USIR0_IR4      (1 << 4)        /* Interrupt request ep 4 */
+#define USIR0_IR5      (1 << 5)        /* Interrupt request ep 5 */
+#define USIR0_IR6      (1 << 6)        /* Interrupt request ep 6 */
+#define USIR0_IR7      (1 << 7)        /* Interrupt request ep 7 */
+
+#define USIR1          __REG(0x4060005C)  /* UDC Status Interrupt Register 1 */
+
+#define USIR1_IR8      (1 << 0)        /* Interrupt request ep 8 */
+#define USIR1_IR9      (1 << 1)        /* Interrupt request ep 9 */
+#define USIR1_IR10     (1 << 2)        /* Interrupt request ep 10 */
+#define USIR1_IR11     (1 << 3)        /* Interrupt request ep 11 */
+#define USIR1_IR12     (1 << 4)        /* Interrupt request ep 12 */
+#define USIR1_IR13     (1 << 5)        /* Interrupt request ep 13 */
+#define USIR1_IR14     (1 << 6)        /* Interrupt request ep 14 */
+#define USIR1_IR15     (1 << 7)        /* Interrupt request ep 15 */
+
+#endif
diff --git a/include/asm-arm/arch-pxa/pxa27x-udc.h b/include/asm-arm/arch-pxa/pxa27x-udc.h
new file mode 100644 (file)
index 0000000..bc1cf7d
--- /dev/null
@@ -0,0 +1,257 @@
+#ifndef _ASM_ARCH_PXA27X_UDC_H
+#define _ASM_ARCH_PXA27X_UDC_H
+
+#ifdef _ASM_ARCH_PXA25X_UDC_H
+#error You cannot include both PXA25x and PXA27x UDC support
+#endif
+
+#define UDCCR           __REG(0x40600000) /* UDC Control Register */
+#define UDCCR_OEN      (1 << 31)       /* On-the-Go Enable */
+#define UDCCR_AALTHNP  (1 << 30)       /* A-device Alternate Host Negotiation
+                                          Protocol Port Support */
+#define UDCCR_AHNP     (1 << 29)       /* A-device Host Negotiation Protocol
+                                          Support */
+#define UDCCR_BHNP     (1 << 28)       /* B-device Host Negotiation Protocol
+                                          Enable */
+#define UDCCR_DWRE     (1 << 16)       /* Device Remote Wake-up Enable */
+#define UDCCR_ACN      (0x03 << 11)    /* Active UDC configuration Number */
+#define UDCCR_ACN_S    11
+#define UDCCR_AIN      (0x07 << 8)     /* Active UDC interface Number */
+#define UDCCR_AIN_S    8
+#define UDCCR_AAISN    (0x07 << 5)     /* Active UDC Alternate Interface
+                                          Setting Number */
+#define UDCCR_AAISN_S  5
+#define UDCCR_SMAC     (1 << 4)        /* Switch Endpoint Memory to Active
+                                          Configuration */
+#define UDCCR_EMCE     (1 << 3)        /* Endpoint Memory Configuration
+                                          Error */
+#define UDCCR_UDR      (1 << 2)        /* UDC Resume */
+#define UDCCR_UDA      (1 << 1)        /* UDC Active */
+#define UDCCR_UDE      (1 << 0)        /* UDC Enable */
+
+#define UDCICR0         __REG(0x40600004) /* UDC Interrupt Control Register0 */
+#define UDCICR1         __REG(0x40600008) /* UDC Interrupt Control Register1 */
+#define UDCICR_FIFOERR (1 << 1)        /* FIFO Error interrupt for EP */
+#define UDCICR_PKTCOMPL (1 << 0)       /* Packet Complete interrupt for EP */
+
+#define UDC_INT_FIFOERROR  (0x2)
+#define UDC_INT_PACKETCMP  (0x1)
+
+#define UDCICR_INT(n,intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
+#define UDCICR1_IECC   (1 << 31)       /* IntEn - Configuration Change */
+#define UDCICR1_IESOF  (1 << 30)       /* IntEn - Start of Frame */
+#define UDCICR1_IERU   (1 << 29)       /* IntEn - Resume */
+#define UDCICR1_IESU   (1 << 28)       /* IntEn - Suspend */
+#define UDCICR1_IERS   (1 << 27)       /* IntEn - Reset */
+
+#define UDCISR0         __REG(0x4060000C) /* UDC Interrupt Status Register 0 */
+#define UDCISR1         __REG(0x40600010) /* UDC Interrupt Status Register 1 */
+#define UDCISR_INT(n,intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
+#define UDCISR1_IRCC   (1 << 31)       /* IntReq - Configuration Change */
+#define UDCISR1_IRSOF  (1 << 30)       /* IntReq - Start of Frame */
+#define UDCISR1_IRRU   (1 << 29)       /* IntReq - Resume */
+#define UDCISR1_IRSU   (1 << 28)       /* IntReq - Suspend */
+#define UDCISR1_IRRS   (1 << 27)       /* IntReq - Reset */
+
+#define UDCFNR          __REG(0x40600014) /* UDC Frame Number Register */
+#define UDCOTGICR      __REG(0x40600018) /* UDC On-The-Go interrupt control */
+#define UDCOTGICR_IESF (1 << 24)       /* OTG SET_FEATURE command recvd */
+#define UDCOTGICR_IEXR (1 << 17)       /* Extra Transciever Interrupt
+                                          Rising Edge Interrupt Enable */
+#define UDCOTGICR_IEXF (1 << 16)       /* Extra Transciever Interrupt
+                                          Falling Edge Interrupt Enable */
+#define UDCOTGICR_IEVV40R (1 << 9)     /* OTG Vbus Valid 4.0V Rising Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IEVV40F (1 << 8)     /* OTG Vbus Valid 4.0V Falling Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IEVV44R (1 << 7)     /* OTG Vbus Valid 4.4V Rising Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IEVV44F (1 << 6)     /* OTG Vbus Valid 4.4V Falling Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IESVR        (1 << 5)        /* OTG Session Valid Rising Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IESVF        (1 << 4)        /* OTG Session Valid Falling Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IESDR        (1 << 3)        /* OTG A-Device SRP Detect Rising
+                                          Edge Interrupt Enable */
+#define UDCOTGICR_IESDF        (1 << 2)        /* OTG A-Device SRP Detect Falling
+                                          Edge Interrupt Enable */
+#define UDCOTGICR_IEIDR        (1 << 1)        /* OTG ID Change Rising Edge
+                                          Interrupt Enable */
+#define UDCOTGICR_IEIDF        (1 << 0)        /* OTG ID Change Falling Edge
+                                          Interrupt Enable */
+
+#define UP2OCR           __REG(0x40600020)  /* USB Port 2 Output Control register */
+#define UP3OCR           __REG(0x40600024)  /* USB Port 2 Output Control register */
+
+#define UP2OCR_CPVEN   (1 << 0)        /* Charge Pump Vbus Enable */
+#define UP2OCR_CPVPE   (1 << 1)        /* Charge Pump Vbus Pulse Enable */
+#define UP2OCR_DPPDE   (1 << 2)        /* Host Port 2 Transceiver D+ Pull Down Enable */
+#define UP2OCR_DMPDE   (1 << 3)        /* Host Port 2 Transceiver D- Pull Down Enable */
+#define UP2OCR_DPPUE   (1 << 4)        /* Host Port 2 Transceiver D+ Pull Up Enable */
+#define UP2OCR_DMPUE   (1 << 5)        /* Host Port 2 Transceiver D- Pull Up Enable */
+#define UP2OCR_DPPUBE  (1 << 6)        /* Host Port 2 Transceiver D+ Pull Up Bypass Enable */
+#define UP2OCR_DMPUBE  (1 << 7)        /* Host Port 2 Transceiver D- Pull Up Bypass Enable */
+#define UP2OCR_EXSP            (1 << 8)        /* External Transceiver Speed Control */
+#define UP2OCR_EXSUS   (1 << 9)        /* External Transceiver Speed Enable */
+#define UP2OCR_IDON            (1 << 10)       /* OTG ID Read Enable */
+#define UP2OCR_HXS             (1 << 16)       /* Host Port 2 Transceiver Output Select */
+#define UP2OCR_HXOE            (1 << 17)       /* Host Port 2 Transceiver Output Enable */
+#define UP2OCR_SEOS            (1 << 24)       /* Single-Ended Output Select */
+
+#define UDCCSN(x)      __REG2(0x40600100, (x) << 2)
+#define UDCCSR0         __REG(0x40600100) /* UDC Control/Status register - Endpoint 0 */
+#define UDCCSR0_SA     (1 << 7)        /* Setup Active */
+#define UDCCSR0_RNE    (1 << 6)        /* Receive FIFO Not Empty */
+#define UDCCSR0_FST    (1 << 5)        /* Force Stall */
+#define UDCCSR0_SST    (1 << 4)        /* Sent Stall */
+#define UDCCSR0_DME    (1 << 3)        /* DMA Enable */
+#define UDCCSR0_FTF    (1 << 2)        /* Flush Transmit FIFO */
+#define UDCCSR0_IPR    (1 << 1)        /* IN Packet Ready */
+#define UDCCSR0_OPC    (1 << 0)        /* OUT Packet Complete */
+
+#define UDCCSRA         __REG(0x40600104) /* UDC Control/Status register - Endpoint A */
+#define UDCCSRB         __REG(0x40600108) /* UDC Control/Status register - Endpoint B */
+#define UDCCSRC         __REG(0x4060010C) /* UDC Control/Status register - Endpoint C */
+#define UDCCSRD         __REG(0x40600110) /* UDC Control/Status register - Endpoint D */
+#define UDCCSRE         __REG(0x40600114) /* UDC Control/Status register - Endpoint E */
+#define UDCCSRF         __REG(0x40600118) /* UDC Control/Status register - Endpoint F */
+#define UDCCSRG         __REG(0x4060011C) /* UDC Control/Status register - Endpoint G */
+#define UDCCSRH         __REG(0x40600120) /* UDC Control/Status register - Endpoint H */
+#define UDCCSRI         __REG(0x40600124) /* UDC Control/Status register - Endpoint I */
+#define UDCCSRJ         __REG(0x40600128) /* UDC Control/Status register - Endpoint J */
+#define UDCCSRK         __REG(0x4060012C) /* UDC Control/Status register - Endpoint K */
+#define UDCCSRL         __REG(0x40600130) /* UDC Control/Status register - Endpoint L */
+#define UDCCSRM         __REG(0x40600134) /* UDC Control/Status register - Endpoint M */
+#define UDCCSRN         __REG(0x40600138) /* UDC Control/Status register - Endpoint N */
+#define UDCCSRP         __REG(0x4060013C) /* UDC Control/Status register - Endpoint P */
+#define UDCCSRQ         __REG(0x40600140) /* UDC Control/Status register - Endpoint Q */
+#define UDCCSRR         __REG(0x40600144) /* UDC Control/Status register - Endpoint R */
+#define UDCCSRS         __REG(0x40600148) /* UDC Control/Status register - Endpoint S */
+#define UDCCSRT         __REG(0x4060014C) /* UDC Control/Status register - Endpoint T */
+#define UDCCSRU         __REG(0x40600150) /* UDC Control/Status register - Endpoint U */
+#define UDCCSRV         __REG(0x40600154) /* UDC Control/Status register - Endpoint V */
+#define UDCCSRW         __REG(0x40600158) /* UDC Control/Status register - Endpoint W */
+#define UDCCSRX         __REG(0x4060015C) /* UDC Control/Status register - Endpoint X */
+
+#define UDCCSR_DPE     (1 << 9)        /* Data Packet Error */
+#define UDCCSR_FEF     (1 << 8)        /* Flush Endpoint FIFO */
+#define UDCCSR_SP      (1 << 7)        /* Short Packet Control/Status */
+#define UDCCSR_BNE     (1 << 6)        /* Buffer Not Empty (IN endpoints) */
+#define UDCCSR_BNF     (1 << 6)        /* Buffer Not Full (OUT endpoints) */
+#define UDCCSR_FST     (1 << 5)        /* Force STALL */
+#define UDCCSR_SST     (1 << 4)        /* Sent STALL */
+#define UDCCSR_DME     (1 << 3)        /* DMA Enable */
+#define UDCCSR_TRN     (1 << 2)        /* Tx/Rx NAK */
+#define UDCCSR_PC      (1 << 1)        /* Packet Complete */
+#define UDCCSR_FS      (1 << 0)        /* FIFO needs service */
+
+#define UDCBCN(x)      __REG2(0x40600200, (x)<<2)
+#define UDCBCR0         __REG(0x40600200) /* Byte Count Register - EP0 */
+#define UDCBCRA         __REG(0x40600204) /* Byte Count Register - EPA */
+#define UDCBCRB         __REG(0x40600208) /* Byte Count Register - EPB */
+#define UDCBCRC         __REG(0x4060020C) /* Byte Count Register - EPC */
+#define UDCBCRD         __REG(0x40600210) /* Byte Count Register - EPD */
+#define UDCBCRE         __REG(0x40600214) /* Byte Count Register - EPE */
+#define UDCBCRF         __REG(0x40600218) /* Byte Count Register - EPF */
+#define UDCBCRG         __REG(0x4060021C) /* Byte Count Register - EPG */
+#define UDCBCRH         __REG(0x40600220) /* Byte Count Register - EPH */
+#define UDCBCRI         __REG(0x40600224) /* Byte Count Register - EPI */
+#define UDCBCRJ         __REG(0x40600228) /* Byte Count Register - EPJ */
+#define UDCBCRK         __REG(0x4060022C) /* Byte Count Register - EPK */
+#define UDCBCRL         __REG(0x40600230) /* Byte Count Register - EPL */
+#define UDCBCRM         __REG(0x40600234) /* Byte Count Register - EPM */
+#define UDCBCRN         __REG(0x40600238) /* Byte Count Register - EPN */
+#define UDCBCRP         __REG(0x4060023C) /* Byte Count Register - EPP */
+#define UDCBCRQ         __REG(0x40600240) /* Byte Count Register - EPQ */
+#define UDCBCRR         __REG(0x40600244) /* Byte Count Register - EPR */
+#define UDCBCRS         __REG(0x40600248) /* Byte Count Register - EPS */
+#define UDCBCRT         __REG(0x4060024C) /* Byte Count Register - EPT */
+#define UDCBCRU         __REG(0x40600250) /* Byte Count Register - EPU */
+#define UDCBCRV         __REG(0x40600254) /* Byte Count Register - EPV */
+#define UDCBCRW         __REG(0x40600258) /* Byte Count Register - EPW */
+#define UDCBCRX         __REG(0x4060025C) /* Byte Count Register - EPX */
+
+#define UDCDN(x)       __REG2(0x40600300, (x)<<2)
+#define PHYS_UDCDN(x)  (0x40600300 + ((x)<<2))
+#define PUDCDN(x)      (volatile u32 *)(io_p2v(PHYS_UDCDN((x))))
+#define UDCDR0          __REG(0x40600300) /* Data Register - EP0 */
+#define UDCDRA          __REG(0x40600304) /* Data Register - EPA */
+#define UDCDRB          __REG(0x40600308) /* Data Register - EPB */
+#define UDCDRC          __REG(0x4060030C) /* Data Register - EPC */
+#define UDCDRD          __REG(0x40600310) /* Data Register - EPD */
+#define UDCDRE          __REG(0x40600314) /* Data Register - EPE */
+#define UDCDRF          __REG(0x40600318) /* Data Register - EPF */
+#define UDCDRG          __REG(0x4060031C) /* Data Register - EPG */
+#define UDCDRH          __REG(0x40600320) /* Data Register - EPH */
+#define UDCDRI          __REG(0x40600324) /* Data Register - EPI */
+#define UDCDRJ          __REG(0x40600328) /* Data Register - EPJ */
+#define UDCDRK          __REG(0x4060032C) /* Data Register - EPK */
+#define UDCDRL          __REG(0x40600330) /* Data Register - EPL */
+#define UDCDRM          __REG(0x40600334) /* Data Register - EPM */
+#define UDCDRN          __REG(0x40600338) /* Data Register - EPN */
+#define UDCDRP          __REG(0x4060033C) /* Data Register - EPP */
+#define UDCDRQ          __REG(0x40600340) /* Data Register - EPQ */
+#define UDCDRR          __REG(0x40600344) /* Data Register - EPR */
+#define UDCDRS          __REG(0x40600348) /* Data Register - EPS */
+#define UDCDRT          __REG(0x4060034C) /* Data Register - EPT */
+#define UDCDRU          __REG(0x40600350) /* Data Register - EPU */
+#define UDCDRV          __REG(0x40600354) /* Data Register - EPV */
+#define UDCDRW          __REG(0x40600358) /* Data Register - EPW */
+#define UDCDRX          __REG(0x4060035C) /* Data Register - EPX */
+
+#define UDCCN(x)       __REG2(0x40600400, (x)<<2)
+#define UDCCRA          __REG(0x40600404) /* Configuration register EPA */
+#define UDCCRB          __REG(0x40600408) /* Configuration register EPB */
+#define UDCCRC          __REG(0x4060040C) /* Configuration register EPC */
+#define UDCCRD          __REG(0x40600410) /* Configuration register EPD */
+#define UDCCRE          __REG(0x40600414) /* Configuration register EPE */
+#define UDCCRF          __REG(0x40600418) /* Configuration register EPF */
+#define UDCCRG          __REG(0x4060041C) /* Configuration register EPG */
+#define UDCCRH          __REG(0x40600420) /* Configuration register EPH */
+#define UDCCRI          __REG(0x40600424) /* Configuration register EPI */
+#define UDCCRJ          __REG(0x40600428) /* Configuration register EPJ */
+#define UDCCRK          __REG(0x4060042C) /* Configuration register EPK */
+#define UDCCRL          __REG(0x40600430) /* Configuration register EPL */
+#define UDCCRM          __REG(0x40600434) /* Configuration register EPM */
+#define UDCCRN          __REG(0x40600438) /* Configuration register EPN */
+#define UDCCRP          __REG(0x4060043C) /* Configuration register EPP */
+#define UDCCRQ          __REG(0x40600440) /* Configuration register EPQ */
+#define UDCCRR          __REG(0x40600444) /* Configuration register EPR */
+#define UDCCRS          __REG(0x40600448) /* Configuration register EPS */
+#define UDCCRT          __REG(0x4060044C) /* Configuration register EPT */
+#define UDCCRU          __REG(0x40600450) /* Configuration register EPU */
+#define UDCCRV          __REG(0x40600454) /* Configuration register EPV */
+#define UDCCRW          __REG(0x40600458) /* Configuration register EPW */
+#define UDCCRX          __REG(0x4060045C) /* Configuration register EPX */
+
+#define UDCCONR_CN     (0x03 << 25)    /* Configuration Number */
+#define UDCCONR_CN_S   (25)
+#define UDCCONR_IN     (0x07 << 22)    /* Interface Number */
+#define UDCCONR_IN_S   (22)
+#define UDCCONR_AISN   (0x07 << 19)    /* Alternate Interface Number */
+#define UDCCONR_AISN_S (19)
+#define UDCCONR_EN     (0x0f << 15)    /* Endpoint Number */
+#define UDCCONR_EN_S   (15)
+#define UDCCONR_ET     (0x03 << 13)    /* Endpoint Type: */
+#define UDCCONR_ET_S   (13)
+#define UDCCONR_ET_INT (0x03 << 13)    /*   Interrupt */
+#define UDCCONR_ET_BULK        (0x02 << 13)    /*   Bulk */
+#define UDCCONR_ET_ISO (0x01 << 13)    /*   Isochronous */
+#define UDCCONR_ET_NU  (0x00 << 13)    /*   Not used */
+#define UDCCONR_ED     (1 << 12)       /* Endpoint Direction */
+#define UDCCONR_MPS    (0x3ff << 2)    /* Maximum Packet Size */
+#define UDCCONR_MPS_S  (2)
+#define UDCCONR_DE     (1 << 1)        /* Double Buffering Enable */
+#define UDCCONR_EE     (1 << 0)        /* Endpoint Enable */
+
+
+#define UDC_INT_FIFOERROR  (0x2)
+#define UDC_INT_PACKETCMP  (0x1)
+
+#define UDC_FNR_MASK     (0x7ff)
+
+#define UDCCSR_WR_MASK   (UDCCSR_DME|UDCCSR_FST)
+#define UDC_BCR_MASK    (0x3ff)
+
+#endif
index b81cd63..6ef1dd0 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __ASM_ARCH_PXA2XX_GPIO_H
 #define __ASM_ARCH_PXA2XX_GPIO_H
 
+#warning Please use mfp-pxa2[57]x.h instead of pxa2xx-gpio.h
+
 /* GPIO alternate function assignments */
 
 #define GPIO1_RST              1       /* reset */
index 9553b54..73e0a32 100644 (file)
 
 #endif
 
+
+/*
+ * Power Manager
+ */
+
+#define PMCR           __REG(0x40F00000)  /* Power Manager Control Register */
+#define PSSR           __REG(0x40F00004)  /* Power Manager Sleep Status Register */
+#define PSPR           __REG(0x40F00008)  /* Power Manager Scratch Pad Register */
+#define PWER           __REG(0x40F0000C)  /* Power Manager Wake-up Enable Register */
+#define PRER           __REG(0x40F00010)  /* Power Manager GPIO Rising-Edge Detect Enable Register */
+#define PFER           __REG(0x40F00014)  /* Power Manager GPIO Falling-Edge Detect Enable Register */
+#define PEDR           __REG(0x40F00018)  /* Power Manager GPIO Edge Detect Status Register */
+#define PCFR           __REG(0x40F0001C)  /* Power Manager General Configuration Register */
+#define PGSR0          __REG(0x40F00020)  /* Power Manager GPIO Sleep State Register for GP[31-0] */
+#define PGSR1          __REG(0x40F00024)  /* Power Manager GPIO Sleep State Register for GP[63-32] */
+#define PGSR2          __REG(0x40F00028)  /* Power Manager GPIO Sleep State Register for GP[84-64] */
+#define PGSR3          __REG(0x40F0002C)  /* Power Manager GPIO Sleep State Register for GP[118-96] */
+#define RCSR           __REG(0x40F00030)  /* Reset Controller Status Register */
+
+#define PSLR           __REG(0x40F00034)       /* Power Manager Sleep Config Register */
+#define PSTR           __REG(0x40F00038)       /* Power Manager Standby Config Register */
+#define PSNR           __REG(0x40F0003C)       /* Power Manager Sense Config Register */
+#define PVCR           __REG(0x40F00040)       /* Power Manager VoltageControl Register */
+#define PKWR           __REG(0x40F00050)       /* Power Manager KB Wake-up Enable Reg */
+#define PKSR           __REG(0x40F00054)       /* Power Manager KB Level-Detect Register */
+#define PCMD(x)        __REG2(0x40F00080, (x)<<2)
+#define PCMD0  __REG(0x40F00080 + 0 * 4)
+#define PCMD1  __REG(0x40F00080 + 1 * 4)
+#define PCMD2  __REG(0x40F00080 + 2 * 4)
+#define PCMD3  __REG(0x40F00080 + 3 * 4)
+#define PCMD4  __REG(0x40F00080 + 4 * 4)
+#define PCMD5  __REG(0x40F00080 + 5 * 4)
+#define PCMD6  __REG(0x40F00080 + 6 * 4)
+#define PCMD7  __REG(0x40F00080 + 7 * 4)
+#define PCMD8  __REG(0x40F00080 + 8 * 4)
+#define PCMD9  __REG(0x40F00080 + 9 * 4)
+#define PCMD10 __REG(0x40F00080 + 10 * 4)
+#define PCMD11 __REG(0x40F00080 + 11 * 4)
+#define PCMD12 __REG(0x40F00080 + 12 * 4)
+#define PCMD13 __REG(0x40F00080 + 13 * 4)
+#define PCMD14 __REG(0x40F00080 + 14 * 4)
+#define PCMD15 __REG(0x40F00080 + 15 * 4)
+#define PCMD16 __REG(0x40F00080 + 16 * 4)
+#define PCMD17 __REG(0x40F00080 + 17 * 4)
+#define PCMD18 __REG(0x40F00080 + 18 * 4)
+#define PCMD19 __REG(0x40F00080 + 19 * 4)
+#define PCMD20 __REG(0x40F00080 + 20 * 4)
+#define PCMD21 __REG(0x40F00080 + 21 * 4)
+#define PCMD22 __REG(0x40F00080 + 22 * 4)
+#define PCMD23 __REG(0x40F00080 + 23 * 4)
+#define PCMD24 __REG(0x40F00080 + 24 * 4)
+#define PCMD25 __REG(0x40F00080 + 25 * 4)
+#define PCMD26 __REG(0x40F00080 + 26 * 4)
+#define PCMD27 __REG(0x40F00080 + 27 * 4)
+#define PCMD28 __REG(0x40F00080 + 28 * 4)
+#define PCMD29 __REG(0x40F00080 + 29 * 4)
+#define PCMD30 __REG(0x40F00080 + 30 * 4)
+#define PCMD31 __REG(0x40F00080 + 31 * 4)
+
+#define PCMD_MBC       (1<<12)
+#define PCMD_DCE       (1<<11)
+#define PCMD_LC        (1<<10)
+/* FIXME:  PCMD_SQC need be checked.   */
+#define PCMD_SQC       (3<<8)  /* currently only bit 8 is changeable,
+                                  bit 9 should be 0 all day. */
+#define PVCR_VCSA      (0x1<<14)
+#define PVCR_CommandDelay (0xf80)
+#define PCFR_PI2C_EN   (0x1 << 6)
+
+#define PSSR_OTGPH     (1 << 6)        /* OTG Peripheral control Hold */
+#define PSSR_RDH       (1 << 5)        /* Read Disable Hold */
+#define PSSR_PH                (1 << 4)        /* Peripheral Control Hold */
+#define PSSR_STS       (1 << 3)        /* Standby Mode Status */
+#define PSSR_VFS       (1 << 2)        /* VDD Fault Status */
+#define PSSR_BFS       (1 << 1)        /* Battery Fault Status */
+#define PSSR_SSS       (1 << 0)        /* Software Sleep Status */
+
+#define PSLR_SL_ROD    (1 << 20)       /* Sleep-Mode/Depp-Sleep Mode nRESET_OUT Disable */
+
+#define PCFR_RO                (1 << 15)       /* RDH Override */
+#define PCFR_PO                (1 << 14)       /* PH Override */
+#define PCFR_GPROD     (1 << 12)       /* GPIO nRESET_OUT Disable */
+#define PCFR_L1_EN     (1 << 11)       /* Sleep Mode L1 converter Enable */
+#define PCFR_FVC       (1 << 10)       /* Frequency/Voltage Change */
+#define PCFR_DC_EN     (1 << 7)        /* Sleep/deep-sleep DC-DC Converter Enable */
+#define PCFR_PI2CEN    (1 << 6)        /* Enable PI2C controller */
+#define PCFR_GPR_EN    (1 << 4)        /* nRESET_GPIO Pin Enable */
+#define PCFR_DS                (1 << 3)        /* Deep Sleep Mode */
+#define PCFR_FS                (1 << 2)        /* Float Static Chip Selects */
+#define PCFR_FP                (1 << 1)        /* Float PCMCIA controls */
+#define PCFR_OPDE      (1 << 0)        /* 3.6864 MHz oscillator power-down enable */
+
+#define RCSR_GPR       (1 << 3)        /* GPIO Reset */
+#define RCSR_SMR       (1 << 2)        /* Sleep Mode */
+#define RCSR_WDR       (1 << 1)        /* Watchdog Reset */
+#define RCSR_HWR       (1 << 0)        /* Hardware Reset */
+
+#define PWER_GPIO(Nb)  (1 << Nb)       /* GPIO [0..15] wake-up enable     */
+#define PWER_GPIO0     PWER_GPIO (0)   /* GPIO  [0] wake-up enable        */
+#define PWER_GPIO1     PWER_GPIO (1)   /* GPIO  [1] wake-up enable        */
+#define PWER_GPIO2     PWER_GPIO (2)   /* GPIO  [2] wake-up enable        */
+#define PWER_GPIO3     PWER_GPIO (3)   /* GPIO  [3] wake-up enable        */
+#define PWER_GPIO4     PWER_GPIO (4)   /* GPIO  [4] wake-up enable        */
+#define PWER_GPIO5     PWER_GPIO (5)   /* GPIO  [5] wake-up enable        */
+#define PWER_GPIO6     PWER_GPIO (6)   /* GPIO  [6] wake-up enable        */
+#define PWER_GPIO7     PWER_GPIO (7)   /* GPIO  [7] wake-up enable        */
+#define PWER_GPIO8     PWER_GPIO (8)   /* GPIO  [8] wake-up enable        */
+#define PWER_GPIO9     PWER_GPIO (9)   /* GPIO  [9] wake-up enable        */
+#define PWER_GPIO10    PWER_GPIO (10)  /* GPIO [10] wake-up enable        */
+#define PWER_GPIO11    PWER_GPIO (11)  /* GPIO [11] wake-up enable        */
+#define PWER_GPIO12    PWER_GPIO (12)  /* GPIO [12] wake-up enable        */
+#define PWER_GPIO13    PWER_GPIO (13)  /* GPIO [13] wake-up enable        */
+#define PWER_GPIO14    PWER_GPIO (14)  /* GPIO [14] wake-up enable        */
+#define PWER_GPIO15    PWER_GPIO (15)  /* GPIO [15] wake-up enable        */
+#define PWER_RTC       0x80000000      /* RTC alarm wake-up enable        */
+
+/*
+ * PXA2xx specific Core clock definitions
+ */
+#define CCCR           __REG(0x41300000)  /* Core Clock Configuration Register */
+#define CCSR           __REG(0x4130000C)  /* Core Clock Status Register */
+#define CKEN           __REG(0x41300004)  /* Clock Enable Register */
+#define OSCC           __REG(0x41300008)  /* Oscillator Configuration Register */
+
+#define CCCR_N_MASK    0x0380  /* Run Mode Frequency to Turbo Mode Frequency Multiplier */
+#define CCCR_M_MASK    0x0060  /* Memory Frequency to Run Mode Frequency Multiplier */
+#define CCCR_L_MASK    0x001f  /* Crystal Frequency to Memory Frequency Multiplier */
+
+#define CKEN_AC97CONF   (31)    /* AC97 Controller Configuration */
+#define CKEN_CAMERA    (24)    /* Camera Interface Clock Enable */
+#define CKEN_SSP1      (23)    /* SSP1 Unit Clock Enable */
+#define CKEN_MEMC      (22)    /* Memory Controller Clock Enable */
+#define CKEN_MEMSTK    (21)    /* Memory Stick Host Controller */
+#define CKEN_IM                (20)    /* Internal Memory Clock Enable */
+#define CKEN_KEYPAD    (19)    /* Keypad Interface Clock Enable */
+#define CKEN_USIM      (18)    /* USIM Unit Clock Enable */
+#define CKEN_MSL       (17)    /* MSL Unit Clock Enable */
+#define CKEN_LCD       (16)    /* LCD Unit Clock Enable */
+#define CKEN_PWRI2C    (15)    /* PWR I2C Unit Clock Enable */
+#define CKEN_I2C       (14)    /* I2C Unit Clock Enable */
+#define CKEN_FICP      (13)    /* FICP Unit Clock Enable */
+#define CKEN_MMC       (12)    /* MMC Unit Clock Enable */
+#define CKEN_USB       (11)    /* USB Unit Clock Enable */
+#define CKEN_ASSP      (10)    /* ASSP (SSP3) Clock Enable */
+#define CKEN_USBHOST   (10)    /* USB Host Unit Clock Enable */
+#define CKEN_OSTIMER   (9)     /* OS Timer Unit Clock Enable */
+#define CKEN_NSSP      (9)     /* NSSP (SSP2) Clock Enable */
+#define CKEN_I2S       (8)     /* I2S Unit Clock Enable */
+#define CKEN_BTUART    (7)     /* BTUART Unit Clock Enable */
+#define CKEN_FFUART    (6)     /* FFUART Unit Clock Enable */
+#define CKEN_STUART    (5)     /* STUART Unit Clock Enable */
+#define CKEN_HWUART    (4)     /* HWUART Unit Clock Enable */
+#define CKEN_SSP3      (4)     /* SSP3 Unit Clock Enable */
+#define CKEN_SSP       (3)     /* SSP Unit Clock Enable */
+#define CKEN_SSP2      (3)     /* SSP2 Unit Clock Enable */
+#define CKEN_AC97      (2)     /* AC97 Unit Clock Enable */
+#define CKEN_PWM1      (1)     /* PWM1 Clock Enable */
+#define CKEN_PWM0      (0)     /* PWM0 Clock Enable */
+
+#define OSCC_OON       (1 << 1)        /* 32.768kHz OON (write-once only bit) */
+#define OSCC_OOK       (1 << 0)        /* 32.768kHz OOK (read-only bit) */
+
 #endif
index 9aa6c2e..ba7e132 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <asm/proc-fns.h>
 #include "hardware.h"
+#include "pxa2xx-regs.h"
 #include "pxa-regs.h"
 
 static inline void arch_idle(void)
index 4881b80..de577de 100644 (file)
@@ -15,7 +15,6 @@ struct platform_mmc_slot {
 
 extern struct platform_mmc_slot zylonite_mmc_slot[];
 
-extern int gpio_backlight;
 extern int gpio_eth_irq;
 
 extern int wm9713_irq;
index b4da08d..6bd2295 100644 (file)
@@ -126,7 +126,7 @@ static inline unsigned sz __in##fnsuffix (unsigned int port)                \
        return (unsigned sz)value;                                              \
 }
 
-static inline void __iomem *__ioaddr(unsigned int port)
+static inline void __iomem *__deprecated __ioaddr(unsigned int port)
 {
        void __iomem *ret;
        if (__PORT_PCIO(port))
@@ -232,8 +232,7 @@ DECLARE_IO(int,l,"")
        result;                                                                 \
 })
 
-#define __ioaddrc(port)                \
-       ((__PORT_PCIO(port) ? PCIO_BASE : IO_BASE) + ((port) << 2))
+#define __ioaddrc(port)                __ioaddr(port)
 
 #define inb(p)         (__builtin_constant_p((p)) ? __inbc(p)    : __inb(p))
 #define inw(p)         (__builtin_constant_p((p)) ? __inwc(p)    : __inw(p))
index 7583895..18e10d2 100644 (file)
@@ -1,68 +1,18 @@
-/*
- * linux/include/asm-arm/arch-s3c2410/gpio.h
+/* linux/include/asm-arm/arch-s3c2410/gpio.h
  *
- * S3C2410 GPIO wrappers for arch-neutral GPIO calls
+ * Copyright (c) 2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>
  *
- * Written by Philipp Zabel <philipp.zabel@gmail.com>
+ * S3C2410 - GPIO lib support
  *
  * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#ifndef __ASM_ARCH_S3C2410_GPIO_H
-#define __ASM_ARCH_S3C2410_GPIO_H
-
-#include <asm/irq.h>
-#include <asm/hardware.h>
-#include <asm/arch/regs-gpio.h>
-
-static inline int gpio_request(unsigned gpio, const char *label)
-{
-       return 0;
-}
-
-static inline void gpio_free(unsigned gpio)
-{
-       return;
-}
-
-static inline int gpio_direction_input(unsigned gpio)
-{
-       s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_INPUT);
-       return 0;
-}
-
-static inline int gpio_direction_output(unsigned gpio, int value)
-{
-       s3c2410_gpio_cfgpin(gpio, S3C2410_GPIO_OUTPUT);
-       /* REVISIT can we write the value first, to avoid glitching? */
-       s3c2410_gpio_setpin(gpio, value);
-       return 0;
-}
-
-#define gpio_get_value(gpio)           s3c2410_gpio_getpin(gpio)
-#define gpio_set_value(gpio,value)     s3c2410_gpio_setpin(gpio, value)
-
-#include <asm-generic/gpio.h>                  /* cansleep wrappers */
-
-#ifdef CONFIG_CPU_S3C2400
-#define gpio_to_irq(gpio)              s3c2400_gpio_getirq(gpio)
-#else
-#define gpio_to_irq(gpio)              s3c2410_gpio_getirq(gpio)
-#endif
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
 
-/* FIXME implement irq_to_gpio() */
+#define gpio_get_value __gpio_get_value
+#define gpio_set_value __gpio_set_value
+#define gpio_cansleep  __gpio_cansleep
 
-#endif
+#include <asm-generic/gpio.h>
index ecae9e7..3766135 100644 (file)
@@ -189,6 +189,8 @@ s3c2410_get_pll(unsigned int pllval, unsigned int baseclk)
 #define S3C2412_CLKSRC_I2SCLK_MPLL             (1<<9)
 #define S3C2412_CLKSRC_USBCLK_HCLK             (1<<10)
 #define S3C2412_CLKSRC_CAMCLK_HCLK             (1<<11)
+#define S3C2412_CLKSRC_UREFCLK_EXTCLK  (1<<12)
+#define S3C2412_CLKSRC_EREFCLK_EXTCLK  (1<<14)
 
 #endif /* CONFIG_CPU_S3C2412 | CONFIG_CPU_S3C2413 */
 
index fce8328..911393b 100644 (file)
 #define PLD(code...)
 #endif
 
+/*
+ * This can be used to enable code to cacheline align the destination
+ * pointer when bulk writing to memory.  Experiments on StrongARM and
+ * XScale didn't show this a worthwhile thing to do when the cache is not
+ * set to write-allocate (this would need further testing on XScale when WA
+ * is used).
+ *
+ * On Feroceon there is much to gain however, regardless of cache mode.
+ */
+#ifdef CONFIG_CPU_FEROCEON
+#define CALGN(code...) code
+#else
+#define CALGN(code...)
+#endif
+
 /*
  * Enable and disable interrupts
  */
index 759a97b..70b0fe7 100644 (file)
 #endif
 
 #if defined(CONFIG_CPU_FEROCEON)
-# ifdef _CACHE
-#  define MULTI_CACHE 1
-# else
-#  define _CACHE feroceon
-# endif
+# define MULTI_CACHE 1
 #endif
 
 #if defined(CONFIG_CPU_V6)
@@ -410,6 +406,13 @@ extern void flush_dcache_page(struct page *);
 
 extern void __flush_dcache_page(struct address_space *mapping, struct page *page);
 
+static inline void __flush_icache_all(void)
+{
+       asm("mcr        p15, 0, %0, c7, c5, 0   @ invalidate I-cache\n"
+           :
+           : "r" (0));
+}
+
 #define ARCH_HAS_FLUSH_ANON_PAGE
 static inline void flush_anon_page(struct vm_area_struct *vma,
                         struct page *page, unsigned long vmaddr)
diff --git a/include/asm-arm/dyntick.h b/include/asm-arm/dyntick.h
deleted file mode 100644 (file)
index 19fab2d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _ASMARM_DYNTICK_H
-#define _ASMARM_DYNTICK_H
-
-#include <asm/mach/time.h>
-
-#endif /* _ASMARM_DYNTICK_H */
index 684fe06..5e22881 100644 (file)
 
 #define MAX_ECARDS     9
 
-typedef enum {                         /* Cards address space          */
-       ECARD_IOC,
-       ECARD_MEMC,
-       ECARD_EASI
-} card_type_t;
-
-typedef enum {                         /* Speed for ECARD_IOC space    */
-       ECARD_SLOW       = 0,
-       ECARD_MEDIUM     = 1,
-       ECARD_FAST       = 2,
-       ECARD_SYNC       = 3
-} card_speed_t;
-
 struct ecard_id {                      /* Card ID structure            */
        unsigned short  manufacturer;
        unsigned short  product;
@@ -189,16 +176,6 @@ struct in_chunk_dir {
        } d;
 };
 
-/*
- * ecard_claim: claim an expansion card entry
- */
-#define ecard_claim(ec) ((ec)->claimed = 1)
-
-/*
- * ecard_release: release an expansion card entry
- */
-#define ecard_release(ec) ((ec)->claimed = 0)
-
 /*
  * Read a chunk from an expansion card
  * cd : where to put read data
@@ -208,18 +185,6 @@ struct in_chunk_dir {
  */
 extern int ecard_readchunk (struct in_chunk_dir *cd, struct expansion_card *ec, int id, int num);
 
-/*
- * Obtain the address of a card.  This returns the "old style" address
- * and should no longer be used.
- */
-static inline unsigned int __deprecated
-ecard_address(struct expansion_card *ec, card_type_t type, card_speed_t speed)
-{
-       extern unsigned int __ecard_address(struct expansion_card *,
-                                           card_type_t, card_speed_t);
-       return __ecard_address(ec, type, speed);
-}
-
 /*
  * Request and release ecard resources
  */
diff --git a/include/asm-arm/ftrace.h b/include/asm-arm/ftrace.h
new file mode 100644 (file)
index 0000000..584ef9a
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _ASM_ARM_FTRACE
+#define _ASM_ARM_FTRACE
+
+#ifdef CONFIG_FTRACE
+#define MCOUNT_ADDR            ((long)(mcount))
+#define MCOUNT_INSN_SIZE       4 /* sizeof mcount call */
+
+#ifndef __ASSEMBLY__
+extern void mcount(void);
+#endif
+
+#endif
+
+#endif /* _ASM_ARM_FTRACE */
diff --git a/include/asm-arm/hardware/iop3xx-gpio.h b/include/asm-arm/hardware/iop3xx-gpio.h
new file mode 100644 (file)
index 0000000..0c9331f
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * linux/include/asm-arm/hardware/iop3xx-gpio.h
+ *
+ * IOP3xx GPIO wrappers
+ *
+ * Copyright (c) 2008 Arnaud Patard <arnaud.patard@rtp-net.org>
+ * Based on IXP4XX gpio.h file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef __ASM_ARM_HARDWARE_IOP3XX_GPIO_H
+#define __ASM_ARM_HARDWARE_IOP3XX_GPIO_H
+
+#include <asm/hardware.h>
+#include <asm-generic/gpio.h>
+
+#define IOP3XX_N_GPIOS 8
+
+static inline int gpio_get_value(unsigned gpio)
+{
+       if (gpio > IOP3XX_N_GPIOS)
+               return __gpio_get_value(gpio);
+
+       return gpio_line_get(gpio);
+}
+
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+       if (gpio > IOP3XX_N_GPIOS) {
+               __gpio_set_value(gpio, value);
+               return;
+       }
+       gpio_line_set(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned gpio)
+{
+       if (gpio < IOP3XX_N_GPIOS)
+               return 0;
+       else
+               return __gpio_cansleep(gpio);
+}
+
+/*
+ * The GPIOs are not generating any interrupt
+ * Note : manuals are not clear about this
+ */
+static inline int gpio_to_irq(int gpio)
+{
+       return -EINVAL;
+}
+
+static inline int irq_to_gpio(int gpio)
+{
+       return -EINVAL;
+}
+
+#endif
+
index 98d594a..f1a08a5 100644 (file)
@@ -6,15 +6,4 @@
 
 #include <asm/mach/irq.h>
 
-#if defined(CONFIG_NO_IDLE_HZ)
-# include <asm/dyntick.h>
-# define handle_dynamic_tick(action)                                   \
-       if (!(action->flags & IRQF_TIMER) && system_timer->dyn_tick) {  \
-               write_seqlock(&xtime_lock);                             \
-               if (system_timer->dyn_tick->state & DYN_TICK_ENABLED)   \
-                       system_timer->dyn_tick->handler(irq, NULL);     \
-               write_sequnlock(&xtime_lock);                           \
-       }
-#endif
-
 #endif
index 47fe34d..c8986bb 100644 (file)
@@ -14,8 +14,6 @@
 
 #define KEXEC_ARCH KEXEC_ARCH_ARM
 
-#define KEXEC_BOOT_PARAMS_SIZE 1536
-
 #define KEXEC_ARM_ATAGS_OFFSET  0x1000
 #define KEXEC_ARM_ZIMAGE_OFFSET 0x8000
 
index c042194..b1a3787 100644 (file)
@@ -59,6 +59,7 @@ struct kprobe_ctlblk {
 };
 
 void arch_remove_kprobe(struct kprobe *);
+void kretprobe_trampoline(void);
 
 int kprobe_trap_handler(struct pt_regs *regs, unsigned int instr);
 int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr);
index 5dc3570..2fd36ea 100644 (file)
@@ -41,30 +41,8 @@ struct sys_timer {
 #ifndef CONFIG_GENERIC_TIME
        unsigned long           (*offset)(void);
 #endif
-
-#ifdef CONFIG_NO_IDLE_HZ
-       struct dyn_tick_timer   *dyn_tick;
-#endif
-};
-
-#ifdef CONFIG_NO_IDLE_HZ
-
-#define DYN_TICK_ENABLED       (1 << 1)
-
-struct dyn_tick_timer {
-       spinlock_t      lock;
-       unsigned int    state;                  /* Current state */
-       int             (*enable)(void);        /* Enables dynamic tick */
-       int             (*disable)(void);       /* Disables dynamic tick */
-       void            (*reprogram)(unsigned long); /* Reprograms the timer */
-       int             (*handler)(int, void *);
 };
 
-void timer_dyn_reprogram(void);
-#else
-#define timer_dyn_reprogram()  do { } while (0)
-#endif
-
 extern struct sys_timer *system_timer;
 extern void timer_tick(void);
 
index 6913d02..91b9dfd 100644 (file)
@@ -97,6 +97,11 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,
 #ifdef CONFIG_MMU
        unsigned int cpu = smp_processor_id();
 
+#ifdef CONFIG_SMP
+       /* check for possible thread migration */
+       if (!cpus_empty(next->cpu_vm_mask) && !cpu_isset(cpu, next->cpu_vm_mask))
+               __flush_icache_all();
+#endif
        if (!cpu_test_and_set(cpu, next->cpu_vm_mask) || prev != next) {
                check_context(next);
                cpu_switch_mm(next->pgd, next);
diff --git a/include/asm-arm/plat-orion/cache-feroceon-l2.h b/include/asm-arm/plat-orion/cache-feroceon-l2.h
new file mode 100644 (file)
index 0000000..ba4e016
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * include/asm-arm/plat-orion/cache-feroceon-l2.h
+ *
+ * Copyright (C) 2008 Marvell Semiconductor
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+extern void __init feroceon_l2_init(int l2_wt_override);
index ffd3852..ad4ce94 100644 (file)
@@ -18,6 +18,7 @@ struct orion_nand_data {
        u8 ale;         /* address line number connected to ALE */
        u8 cle;         /* address line number connected to CLE */
        u8 width;       /* buswidth */
+       u8 chip_delay;
 };
 
 
index 6434ac6..e61b7bd 100644 (file)
@@ -14,6 +14,7 @@
 u32 orion_pcie_dev_id(void __iomem *base);
 u32 orion_pcie_rev(void __iomem *base);
 int orion_pcie_link_up(void __iomem *base);
+int orion_pcie_x4_mode(void __iomem *base);
 int orion_pcie_get_local_bus_nr(void __iomem *base);
 void orion_pcie_set_local_bus_nr(void __iomem *base, int nr);
 void orion_pcie_setup(void __iomem *base,
index 8b0d594..b5bc692 100644 (file)
 #define S3C2410_TCFG1_MUX0_TCLK0  (4<<0)
 #define S3C2410_TCFG1_MUX0_MASK          (15<<0)
 
+#define S3C2410_TCFG1_MUX_DIV2   (0<<0)
+#define S3C2410_TCFG1_MUX_DIV4   (1<<0)
+#define S3C2410_TCFG1_MUX_DIV8   (2<<0)
+#define S3C2410_TCFG1_MUX_DIV16   (3<<0)
+#define S3C2410_TCFG1_MUX_TCLK    (4<<0)
+#define S3C2410_TCFG1_MUX_MASK   (15<<0)
+
+#define S3C2410_TCFG1_SHIFT(x)   ((x) * 4)
+
 /* for each timer, we have an count buffer, an compare buffer and
  * an observation buffer
 */
index f9d6f03..badaac9 100644 (file)
@@ -21,6 +21,8 @@ extern struct s3c24xx_uart_resources s3c2410_uart_resources[];
 extern struct platform_device *s3c24xx_uart_devs[];
 extern struct platform_device *s3c24xx_uart_src[];
 
+extern struct platform_device s3c_device_timer[];
+
 extern struct platform_device s3c_device_usb;
 extern struct platform_device s3c_device_lcd;
 extern struct platform_device s3c_device_wdt;
@@ -36,11 +38,6 @@ extern struct platform_device s3c_device_spi1;
 
 extern struct platform_device s3c_device_nand;
 
-extern struct platform_device s3c_device_timer0;
-extern struct platform_device s3c_device_timer1;
-extern struct platform_device s3c_device_timer2;
-extern struct platform_device s3c_device_timer3;
-
 extern struct platform_device s3c_device_usbgadget;
 
 /* s3c2440 specific devices */
diff --git a/include/asm-arm/rtc.h b/include/asm-arm/rtc.h
deleted file mode 100644 (file)
index 1a5c923..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- *  linux/include/asm-arm/rtc.h
- *
- *  Copyright (C) 2003 Deep Blue Solutions Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#ifndef ASMARM_RTC_H
-#define ASMARM_RTC_H
-
-struct module;
-
-struct rtc_ops {
-       struct module   *owner;
-       int             (*open)(void);
-       void            (*release)(void);
-       int             (*ioctl)(unsigned int, unsigned long);
-
-       int             (*read_time)(struct rtc_time *);
-       int             (*set_time)(struct rtc_time *);
-       int             (*read_alarm)(struct rtc_wkalrm *);
-       int             (*set_alarm)(struct rtc_wkalrm *);
-       int             (*proc)(char *buf);
-};
-
-void rtc_next_alarm_time(struct rtc_time *, struct rtc_time *, struct rtc_time *);
-void rtc_update(unsigned long, unsigned long);
-int register_rtc(struct rtc_ops *);
-void unregister_rtc(struct rtc_ops *);
-
-static inline int rtc_periodic_alarm(struct rtc_time *tm)
-{
-       return  (tm->tm_year == -1) ||
-               ((unsigned)tm->tm_mon >= 12) ||
-               ((unsigned)(tm->tm_mday - 1) >= 31) ||
-               ((unsigned)tm->tm_hour > 23) ||
-               ((unsigned)tm->tm_min > 59) ||
-               ((unsigned)tm->tm_sec > 59);
-}
-
-#endif
index 8c6bc1b..909656c 100644 (file)
@@ -39,6 +39,7 @@
 #define TLB_V6_D_ASID  (1 << 17)
 #define TLB_V6_I_ASID  (1 << 18)
 
+#define TLB_L2CLEAN_FR (1 << 29)               /* Feroceon */
 #define TLB_DCLEAN     (1 << 30)
 #define TLB_WB         (1 << 31)
 
@@ -51,6 +52,7 @@
  *       v4    - ARMv4 without write buffer
  *       v4wb  - ARMv4 with write buffer without I TLB flush entry instruction
  *       v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
+ *       fr    - Feroceon (v4wbi with non-outer-cacheable page table walks)
  *       v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
  */
 #undef _TLB
 # define v4wbi_always_flags    (-1UL)
 #endif
 
+#define fr_tlb_flags   (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
+                        TLB_V4_I_FULL | TLB_V4_D_FULL | \
+                        TLB_V4_I_PAGE | TLB_V4_D_PAGE)
+
+#ifdef CONFIG_CPU_TLB_FEROCEON
+# define fr_possible_flags     fr_tlb_flags
+# define fr_always_flags       fr_tlb_flags
+# ifdef _TLB
+#  define MULTI_TLB 1
+# else
+#  define _TLB v4wbi
+# endif
+#else
+# define fr_possible_flags     0
+# define fr_always_flags       (-1UL)
+#endif
+
 #define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
                         TLB_V4_I_FULL | TLB_V4_D_FULL | \
                         TLB_V4_D_PAGE)
@@ -245,12 +264,14 @@ extern struct cpu_tlb_fns cpu_tlb;
 #define possible_tlb_flags     (v3_possible_flags | \
                                 v4_possible_flags | \
                                 v4wbi_possible_flags | \
+                                fr_possible_flags | \
                                 v4wb_possible_flags | \
                                 v6wbi_possible_flags)
 
 #define always_tlb_flags       (v3_always_flags & \
                                 v4_always_flags & \
                                 v4wbi_always_flags & \
+                                fr_always_flags & \
                                 v4wb_always_flags & \
                                 v6wbi_always_flags)
 
@@ -417,6 +438,11 @@ static inline void flush_pmd_entry(pmd_t *pmd)
        if (tlb_flag(TLB_DCLEAN))
                asm("mcr        p15, 0, %0, c7, c10, 1  @ flush_pmd"
                        : : "r" (pmd) : "cc");
+
+       if (tlb_flag(TLB_L2CLEAN_FR))
+               asm("mcr        p15, 1, %0, c15, c9, 1  @ L2 flush_pmd"
+                       : : "r" (pmd) : "cc");
+
        if (tlb_flag(TLB_WB))
                dsb();
 }
@@ -428,6 +454,10 @@ static inline void clean_pmd_entry(pmd_t *pmd)
        if (tlb_flag(TLB_DCLEAN))
                asm("mcr        p15, 0, %0, c7, c10, 1  @ flush_pmd"
                        : : "r" (pmd) : "cc");
+
+       if (tlb_flag(TLB_L2CLEAN_FR))
+               asm("mcr        p15, 1, %0, c15, c9, 1  @ L2 flush_pmd"
+                       : : "r" (pmd) : "cc");
 }
 
 #undef tlb_flag
index a4e2d28..b4cddfa 100644 (file)
@@ -8,6 +8,12 @@
 
 #define GPIO_PIN_NONE  (-1)
 
+/*
+ * Clock rates for various on-board oscillators. The number of entries
+ * in this array is chip-dependent.
+ */
+extern unsigned long at32_board_osc_rates[];
+  
 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
 void at32_add_system_devices(void);
 
@@ -36,7 +42,8 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
 struct atmel_lcdfb_info;
 struct platform_device *
 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
-                    unsigned long fbmem_start, unsigned long fbmem_len);
+                    unsigned long fbmem_start, unsigned long fbmem_len,
+                    unsigned int pin_config);
 
 struct usba_platform_data;
 struct platform_device *
@@ -73,6 +80,7 @@ struct platform_device *at32_add_device_twi(unsigned int id,
 struct platform_device *at32_add_device_mci(unsigned int id);
 struct platform_device *at32_add_device_ac97c(unsigned int id);
 struct platform_device *at32_add_device_abdac(unsigned int id);
+struct platform_device *at32_add_device_psif(unsigned int id);
 
 struct cf_platform_data {
        int     detect_pin;
index 5e75d85..bc40e3d 100644 (file)
 void setup_platform(void);
 void setup_board(void);
 
-/* Called by setup_platform */
-void at32_clock_init(void);
-void at32_portmux_init(void);
-
 void at32_setup_serial_console(unsigned int usart_id);
 
 #endif /* __ASM_AVR32_AT32AP_INIT_H__ */
index 356e430..979b355 100644 (file)
@@ -19,6 +19,7 @@
 
 #ifndef __ASSEMBLY__
 extern void cpu_enter_idle(void);
+extern void cpu_enter_standby(unsigned long sdramc_base);
 
 extern bool disable_idle_sleep;
 
@@ -43,6 +44,8 @@ static inline void cpu_idle_sleep(void)
        else
                cpu_enter_idle();
 }
+
+void intc_set_suspend_handler(unsigned long offset);
 #endif
 
 #endif /* __ASM_AVR32_ARCH_PM_H */
diff --git a/include/asm-avr32/arch-at32ap/sram.h b/include/asm-avr32/arch-at32ap/sram.h
new file mode 100644 (file)
index 0000000..4838dae
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Simple SRAM allocator
+ *
+ * Copyright (C) 2008 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_AVR32_ARCH_SRAM_H
+#define __ASM_AVR32_ARCH_SRAM_H
+
+#include <linux/genalloc.h>
+
+extern struct gen_pool *sram_pool;
+
+static inline unsigned long sram_alloc(size_t len)
+{
+       if (!sram_pool)
+               return 0UL;
+
+       return gen_pool_alloc(sram_pool, len);
+}
+
+static inline void sram_free(unsigned long addr, size_t len)
+{
+       return gen_pool_free(sram_pool, addr, len);
+}
+
+#endif /* __ASM_AVR32_ARCH_SRAM_H */
index c37c391..27ff234 100644 (file)
@@ -13,7 +13,6 @@
 #define __ASM_AVR32_MMU_CONTEXT_H
 
 #include <asm/tlbflush.h>
-#include <asm/pgalloc.h>
 #include <asm/sysreg.h>
 #include <asm-generic/mm_hooks.h>
 
index 0f5f134..a32a023 100644 (file)
@@ -5,4 +5,6 @@
 
 #define PCI_DMA_BUS_IS_PHYS    (1)
 
+#include <asm-generic/pci-dma-compat.h>
+
 #endif /* __ASM_AVR32_PCI_H__ */
index 51fc1f6..6408213 100644 (file)
@@ -8,65 +8,79 @@
 #ifndef __ASM_AVR32_PGALLOC_H
 #define __ASM_AVR32_PGALLOC_H
 
-#include <asm/processor.h>
-#include <linux/threads.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
+#include <linux/quicklist.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
 
-#define pmd_populate_kernel(mm, pmd, pte) \
-       set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
+#define QUICK_PGD      0       /* Preserve kernel mappings over free */
+#define QUICK_PT       1       /* Zero on free */
 
-static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
+static inline void pmd_populate_kernel(struct mm_struct *mm,
+                                      pmd_t *pmd, pte_t *pte)
+{
+       set_pmd(pmd, __pmd((unsigned long)pte));
+}
+
+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
                                    pgtable_t pte)
 {
-       set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
+       set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
 #define pmd_pgtable(pmd) pmd_page(pmd)
 
+static inline void pgd_ctor(void *x)
+{
+       pgd_t *pgd = x;
+
+       memcpy(pgd + USER_PTRS_PER_PGD,
+               swapper_pg_dir + USER_PTRS_PER_PGD,
+               (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
+}
+
 /*
  * Allocate and free page tables
  */
-static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
+static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
-       return kcalloc(USER_PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL);
+       return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
 }
 
 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
 {
-       kfree(pgd);
+       quicklist_free(QUICK_PGD, NULL, pgd);
 }
 
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
                                          unsigned long address)
 {
-       pte_t *pte;
-
-       pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
-
-       return pte;
+       return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
                                         unsigned long address)
 {
-       struct page *pte;
+       struct page *page;
+       void *pg;
 
-       pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
-       if (!pte)
+       pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
+       if (!pg)
                return NULL;
-       pgtable_page_ctor(pte);
-       return pte;
+
+       page = virt_to_page(pg);
+       pgtable_page_ctor(page);
+
+       return page;
 }
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
-       free_page((unsigned long)pte);
+       quicklist_free(QUICK_PT, NULL, pte);
 }
 
 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
        pgtable_page_dtor(pte);
-       __free_page(pte);
+       quicklist_free_page(QUICK_PT, NULL, pte);
 }
 
 #define __pte_free_tlb(tlb,pte)                                \
@@ -75,6 +89,10 @@ do {                                                 \
        tlb_remove_page((tlb), pte);                    \
 } while (0)
 
-#define check_pgt_cache() do { } while(0)
+static inline void check_pgt_cache(void)
+{
+       quicklist_trim(QUICK_PGD, NULL, 25, 16);
+       quicklist_trim(QUICK_PT, NULL, 25, 16);
+}
 
 #endif /* __ASM_AVR32_PGALLOC_H */
index c0e5e29..fecdda1 100644 (file)
@@ -129,13 +129,6 @@ extern struct page *empty_zero_page;
 
 #define _PAGE_FLAGS_CACHE_MASK (_PAGE_CACHABLE | _PAGE_BUFFER | _PAGE_WT)
 
-/* TODO: Check for saneness */
-/* User-mode page table flags (to be set in a pgd or pmd entry) */
-#define _PAGE_TABLE            (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
-                                | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
-/* Kernel-mode page table flags */
-#define _KERNPG_TABLE          (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
-                                | _PAGE_ACCESSED | _PAGE_DIRTY)
 /* Flags that may be modified by software */
 #define _PAGE_CHG_MASK         (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY \
                                 | _PAGE_FLAGS_CACHE_MASK)
@@ -262,10 +255,14 @@ static inline pte_t pte_mkspecial(pte_t pte)
 }
 
 #define pmd_none(x)    (!pmd_val(x))
-#define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
-#define pmd_clear(xp)  do { set_pmd(xp, __pmd(0)); } while (0)
-#define        pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER))      \
-                        != _KERNPG_TABLE)
+#define pmd_present(x) (pmd_val(x))
+
+static inline void pmd_clear(pmd_t *pmdp)
+{
+       set_pmd(pmdp, __pmd(0));
+}
+
+#define        pmd_bad(x)      (pmd_val(x) & ~PAGE_MASK)
 
 /*
  * Permanent address of a page. We don't support highmem, so this is
@@ -303,19 +300,16 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 
 #define page_pte(page) page_pte_prot(page, __pgprot(0))
 
-#define pmd_page_vaddr(pmd)                                    \
-       ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
-
-#define pmd_page(pmd)  (phys_to_page(pmd_val(pmd)))
+#define pmd_page_vaddr(pmd)    pmd_val(pmd)
+#define pmd_page(pmd)          (virt_to_page(pmd_val(pmd)))
 
 /* to find an entry in a page-table-directory. */
-#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
-#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
-#define pgd_offset_current(address)                            \
-       ((pgd_t *)__mfsr(SYSREG_PTBR) + pgd_index(address))
+#define pgd_index(address)     (((address) >> PGDIR_SHIFT)     \
+                                & (PTRS_PER_PGD - 1))
+#define pgd_offset(mm, address)        ((mm)->pgd + pgd_index(address))
 
 /* to find an entry in a kernel page-table-directory */
-#define pgd_offset_k(address) pgd_offset(&init_mm, address)
+#define pgd_offset_k(address)  pgd_offset(&init_mm, address)
 
 /* Find an entry in the third-level page table.. */
 #define pte_index(address)                             \
index 07049f6..df68631 100644 (file)
@@ -88,6 +88,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_MEMDIE             6
 #define TIF_RESTORE_SIGMASK    7       /* restore signal mask in do_signal */
 #define TIF_CPU_GOING_TO_SLEEP 8       /* CPU is entering sleep 0 mode */
+#define TIF_FREEZE             29
 #define TIF_DEBUG              30      /* debugging enabled */
 #define TIF_USERSPACE          31      /* true if FS sets userspace */
 
index 5bc7c88..bf90a78 100644 (file)
@@ -26,7 +26,6 @@ extern void flush_tlb_mm(struct mm_struct *mm);
 extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
                            unsigned long end);
 extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
-extern void __flush_tlb_page(unsigned long asid, unsigned long page);
 
 extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
 
index 44ef329..4fce3db 100644 (file)
@@ -197,6 +197,63 @@ static inline int pmd_none_or_clear_bad(pmd_t *pmd)
 }
 #endif /* CONFIG_MMU */
 
+static inline pte_t __ptep_modify_prot_start(struct mm_struct *mm,
+                                            unsigned long addr,
+                                            pte_t *ptep)
+{
+       /*
+        * Get the current pte state, but zero it out to make it
+        * non-present, preventing the hardware from asynchronously
+        * updating it.
+        */
+       return ptep_get_and_clear(mm, addr, ptep);
+}
+
+static inline void __ptep_modify_prot_commit(struct mm_struct *mm,
+                                            unsigned long addr,
+                                            pte_t *ptep, pte_t pte)
+{
+       /*
+        * The pte is non-present, so there's no hardware state to
+        * preserve.
+        */
+       set_pte_at(mm, addr, ptep, pte);
+}
+
+#ifndef __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
+/*
+ * Start a pte protection read-modify-write transaction, which
+ * protects against asynchronous hardware modifications to the pte.
+ * The intention is not to prevent the hardware from making pte
+ * updates, but to prevent any updates it may make from being lost.
+ *
+ * This does not protect against other software modifications of the
+ * pte; the appropriate pte lock must be held over the transation.
+ *
+ * Note that this interface is intended to be batchable, meaning that
+ * ptep_modify_prot_commit may not actually update the pte, but merely
+ * queue the update to be done at some later time.  The update must be
+ * actually committed before the pte lock is released, however.
+ */
+static inline pte_t ptep_modify_prot_start(struct mm_struct *mm,
+                                          unsigned long addr,
+                                          pte_t *ptep)
+{
+       return __ptep_modify_prot_start(mm, addr, ptep);
+}
+
+/*
+ * Commit an update to a pte, leaving any hardware-controlled bits in
+ * the PTE unmodified.
+ */
+static inline void ptep_modify_prot_commit(struct mm_struct *mm,
+                                          unsigned long addr,
+                                          pte_t *ptep, pte_t pte)
+{
+       __ptep_modify_prot_commit(mm, addr, ptep, pte);
+}
+#endif /* __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION */
+
 /*
  * A facility to provide lazy MMU batching.  This allows PTE updates and
  * page invalidations to be delayed until a call to leave lazy MMU mode
index a6aea79..54bbf6e 100644 (file)
@@ -60,7 +60,8 @@
 #ifndef node_to_cpumask_ptr
 
 #define        node_to_cpumask_ptr(v, node)                                    \
-               cpumask_t _##v = node_to_cpumask(node), *v = &_##v
+               cpumask_t _##v = node_to_cpumask(node);                 \
+               const cpumask_t *v = &_##v
 
 #define node_to_cpumask_ptr_next(v, node)                              \
                          _##v = node_to_cpumask(node)
index f054778..bf2851f 100644 (file)
@@ -67,6 +67,8 @@
                *(.rodata1)                                             \
        }                                                               \
                                                                        \
+       BUG_TABLE                                                       \
+                                                                       \
        /* PCI quirks */                                                \
        .pci_fixup        : AT(ADDR(.pci_fixup) - LOAD_OFFSET) {        \
                VMLINUX_SYMBOL(__start_pci_fixups_early) = .;           \
@@ -93,6 +95,8 @@
                VMLINUX_SYMBOL(__end_rio_route_ops) = .;                \
        }                                                               \
                                                                        \
+       TRACEDATA                                                       \
+                                                                       \
        /* Kernel symbol table: Normal symbols */                       \
        __ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {         \
                VMLINUX_SYMBOL(__start___ksymtab) = .;                  \
                .stab.indexstr 0 : { *(.stab.indexstr) }                \
                .comment 0 : { *(.comment) }
 
+#ifdef CONFIG_GENERIC_BUG
 #define BUG_TABLE                                                      \
        . = ALIGN(8);                                                   \
        __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) {             \
                *(__bug_table)                                          \
                __stop___bug_table = .;                                 \
        }
+#else
+#define BUG_TABLE
+#endif
+
+#ifdef CONFIG_PM_TRACE
+#define TRACEDATA                                                      \
+       . = ALIGN(4);                                                   \
+       .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {               \
+               __tracedata_start = .;                                  \
+               *(.tracedata)                                           \
+               __tracedata_end = .;                                    \
+       }
+#else
+#define TRACEDATA
+#endif
 
 #define NOTES                                                          \
        .notes : AT(ADDR(.notes) - LOAD_OFFSET) {                       \
index dae4eca..892b7f1 100644 (file)
@@ -204,6 +204,14 @@ typedef struct     psc_i2s {
        u32     psc_i2sudf;
 } psc_i2s_t;
 
+#define PSC_I2SCFG_OFFSET      0x08
+#define PSC_I2SMASK_OFFSET     0x0C
+#define PSC_I2SPCR_OFFSET      0x10
+#define PSC_I2SSTAT_OFFSET     0x14
+#define PSC_I2SEVENT_OFFSET    0x18
+#define PSC_I2SRXTX_OFFSET     0x1C
+#define PSC_I2SUDF_OFFSET      0x20
+
 /* I2S Config Register. */
 #define PSC_I2SCFG_RT_MASK     (3 << 30)
 #define PSC_I2SCFG_RT_FIFO1    (0 << 30)
diff --git a/include/asm-powerpc/ftrace.h b/include/asm-powerpc/ftrace.h
new file mode 100644 (file)
index 0000000..de92132
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _ASM_POWERPC_FTRACE
+#define _ASM_POWERPC_FTRACE
+
+#ifdef CONFIG_FTRACE
+#define MCOUNT_ADDR            ((long)(_mcount))
+#define MCOUNT_INSN_SIZE       4 /* sizeof mcount call */
+
+#ifndef __ASSEMBLY__
+extern void _mcount(void);
+#endif
+
+#endif
+
+#endif /* _ASM_POWERPC_FTRACE */
index ad8c9f7..f75a5fc 100644 (file)
@@ -59,6 +59,11 @@ extern void iseries_handle_interrupts(void);
                get_paca()->hard_enabled = 0;   \
        } while(0)
 
+static inline int irqs_disabled_flags(unsigned long flags)
+{
+       return flags == 0;
+}
+
 #else
 
 #if defined(CONFIG_BOOKE)
@@ -113,6 +118,11 @@ static inline void local_irq_save_ptr(unsigned long *flags)
 #define hard_irq_enable()      local_irq_enable()
 #define hard_irq_disable()     local_irq_disable()
 
+static inline int irqs_disabled_flags(unsigned long flags)
+{
+       return (flags & MSR_EE) == 0;
+}
+
 #endif /* CONFIG_PPC64 */
 
 /*
index 13c9805..09f3125 100644 (file)
@@ -8,6 +8,9 @@ header-y += ucontext.h
 header-y += vtoc.h
 header-y += zcrypt.h
 header-y += kvm.h
+header-y += schid.h
+header-y += chsc.h
 
 unifdef-y += cmb.h
 unifdef-y += debug.h
+unifdef-y += chpid.h
index 41d028c..1ac80d6 100644 (file)
@@ -13,7 +13,7 @@
 
 typedef void (*adapter_int_handler_t)(void *, void *);
 
-void *s390_register_adapter_interrupt(adapter_int_handler_t, void *);
-void s390_unregister_adapter_interrupt(void *);
+void *s390_register_adapter_interrupt(adapter_int_handler_t, void *, u8);
+void s390_unregister_adapter_interrupt(void *, u8);
 
 #endif /* _ASM_S390_AIRQ_H */
index 066aa70..ba007d8 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
+#include <asm/fcx.h>
 
 /* structs from asm/cio.h */
 struct irb;
@@ -157,6 +158,17 @@ extern int ccw_device_start_timeout_key(struct ccw_device *, struct ccw1 *,
 extern int ccw_device_resume(struct ccw_device *);
 extern int ccw_device_halt(struct ccw_device *, unsigned long);
 extern int ccw_device_clear(struct ccw_device *, unsigned long);
+int ccw_device_tm_start_key(struct ccw_device *cdev, struct tcw *tcw,
+                           unsigned long intparm, u8 lpm, u8 key);
+int ccw_device_tm_start_key(struct ccw_device *, struct tcw *,
+                           unsigned long, u8, u8);
+int ccw_device_tm_start_timeout_key(struct ccw_device *, struct tcw *,
+                           unsigned long, u8, u8, int);
+int ccw_device_tm_start(struct ccw_device *, struct tcw *,
+                           unsigned long, u8);
+int ccw_device_tm_start_timeout(struct ccw_device *, struct tcw *,
+                           unsigned long, u8, int);
+int ccw_device_tm_intrg(struct ccw_device *cdev);
 
 extern int ccw_device_set_online(struct ccw_device *cdev);
 extern int ccw_device_set_offline(struct ccw_device *cdev);
index b203336..606844d 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <linux/string.h>
 #include <asm/types.h>
-#include <asm/cio.h>
 
 #define __MAX_CHPID 255
 
@@ -41,6 +40,9 @@ static inline void chp_id_next(struct chp_id *chpid)
        }
 }
 
+#ifdef __KERNEL__
+#include <asm/cio.h>
+
 static inline int chp_id_is_valid(struct chp_id *chpid)
 {
        return (chpid->cssid <= __MAX_CSSID);
@@ -49,5 +51,6 @@ static inline int chp_id_is_valid(struct chp_id *chpid)
 
 #define chp_id_for_each(c) \
        for (chp_id_init(c); chp_id_is_valid(c); chp_id_next(c))
+#endif /* __KERNEL */
 
 #endif /* _ASM_S390_CHPID_H */
diff --git a/include/asm-s390/chsc.h b/include/asm-s390/chsc.h
new file mode 100644 (file)
index 0000000..d38d0cf
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * ioctl interface for /dev/chsc
+ *
+ * Copyright 2008 IBM Corp.
+ * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
+ */
+
+#ifndef _ASM_CHSC_H
+#define _ASM_CHSC_H
+
+#include <asm/chpid.h>
+#include <asm/schid.h>
+
+struct chsc_async_header {
+       __u16 length;
+       __u16 code;
+       __u32 cmd_dependend;
+       __u32 key : 4;
+       __u32 : 28;
+       struct subchannel_id sid;
+} __attribute__ ((packed));
+
+struct chsc_async_area {
+       struct chsc_async_header header;
+       __u8 data[PAGE_SIZE - 16 /* size of chsc_async_header */];
+} __attribute__ ((packed));
+
+
+struct chsc_response_struct {
+       __u16 length;
+       __u16 code;
+       __u32 parms;
+       __u8 data[PAGE_SIZE - 8];
+} __attribute__ ((packed));
+
+struct chsc_chp_cd {
+       struct chp_id chpid;
+       int m;
+       int fmt;
+       struct chsc_response_struct cpcb;
+};
+
+struct chsc_cu_cd {
+       __u16 cun;
+       __u8 cssid;
+       int m;
+       int fmt;
+       struct chsc_response_struct cucb;
+};
+
+struct chsc_sch_cud {
+       struct subchannel_id schid;
+       int fmt;
+       struct chsc_response_struct scub;
+};
+
+struct conf_id {
+       int m;
+       __u8 cssid;
+       __u8 ssid;
+};
+
+struct chsc_conf_info {
+       struct conf_id id;
+       int fmt;
+       struct chsc_response_struct scid;
+};
+
+struct ccl_parm_chpid {
+       int m;
+       struct chp_id chp;
+};
+
+struct ccl_parm_cssids {
+       __u8 f_cssid;
+       __u8 l_cssid;
+};
+
+struct chsc_comp_list {
+       struct {
+               enum {
+                       CCL_CU_ON_CHP = 1,
+                       CCL_CHP_TYPE_CAP = 2,
+                       CCL_CSS_IMG = 4,
+                       CCL_CSS_IMG_CONF_CHAR = 5,
+                       CCL_IOP_CHP = 6,
+               } ctype;
+               int fmt;
+               struct ccl_parm_chpid chpid;
+               struct ccl_parm_cssids cssids;
+       } req;
+       struct chsc_response_struct sccl;
+};
+
+struct chsc_dcal {
+       struct {
+               enum {
+                       DCAL_CSS_IID_PN = 4,
+               } atype;
+               __u32 list_parm[2];
+               int fmt;
+       } req;
+       struct chsc_response_struct sdcal;
+};
+
+struct chsc_cpd_info {
+       struct chp_id chpid;
+       int m;
+       int fmt;
+       int rfmt;
+       int c;
+       struct chsc_response_struct chpdb;
+};
+
+#define CHSC_IOCTL_MAGIC 'c'
+
+#define CHSC_START _IOWR(CHSC_IOCTL_MAGIC, 0x81, struct chsc_async_area)
+#define CHSC_INFO_CHANNEL_PATH _IOWR(CHSC_IOCTL_MAGIC, 0x82, \
+                                   struct chsc_chp_cd)
+#define CHSC_INFO_CU _IOWR(CHSC_IOCTL_MAGIC, 0x83, struct chsc_cu_cd)
+#define CHSC_INFO_SCH_CU _IOWR(CHSC_IOCTL_MAGIC, 0x84, struct chsc_sch_cud)
+#define CHSC_INFO_CI _IOWR(CHSC_IOCTL_MAGIC, 0x85, struct chsc_conf_info)
+#define CHSC_INFO_CCL _IOWR(CHSC_IOCTL_MAGIC, 0x86, struct chsc_comp_list)
+#define CHSC_INFO_CPD _IOWR(CHSC_IOCTL_MAGIC, 0x87, struct chsc_cpd_info)
+#define CHSC_INFO_DCAL _IOWR(CHSC_IOCTL_MAGIC, 0x88, struct chsc_dcal)
+
+#endif
index 0818ecd..6dccb07 100644 (file)
@@ -16,7 +16,7 @@
 #define __MAX_CSSID 0
 
 /**
- * struct scsw - subchannel status word
+ * struct cmd_scsw - command-mode subchannel status word
  * @key: subchannel key
  * @sctl: suspend control
  * @eswf: esw format
@@ -38,7 +38,7 @@
  * @cstat: subchannel status
  * @count: residual count
  */
-struct scsw {
+struct cmd_scsw {
        __u32 key  : 4;
        __u32 sctl : 1;
        __u32 eswf : 1;
@@ -61,6 +61,114 @@ struct scsw {
        __u32 count : 16;
 } __attribute__ ((packed));
 
+/**
+ * struct tm_scsw - transport-mode subchannel status word
+ * @key: subchannel key
+ * @eswf: esw format
+ * @cc: deferred condition code
+ * @fmt: format
+ * @x: IRB-format control
+ * @q: interrogate-complete
+ * @ectl: extended control
+ * @pno: path not operational
+ * @fctl: function control
+ * @actl: activity control
+ * @stctl: status control
+ * @tcw: TCW address
+ * @dstat: device status
+ * @cstat: subchannel status
+ * @fcxs: FCX status
+ * @schxs: subchannel-extended status
+ */
+struct tm_scsw {
+       u32 key:4;
+       u32 :1;
+       u32 eswf:1;
+       u32 cc:2;
+       u32 fmt:3;
+       u32 x:1;
+       u32 q:1;
+       u32 :1;
+       u32 ectl:1;
+       u32 pno:1;
+       u32 :1;
+       u32 fctl:3;
+       u32 actl:7;
+       u32 stctl:5;
+       u32 tcw;
+       u32 dstat:8;
+       u32 cstat:8;
+       u32 fcxs:8;
+       u32 schxs:8;
+} __attribute__ ((packed));
+
+/**
+ * union scsw - subchannel status word
+ * @cmd: command-mode SCSW
+ * @tm: transport-mode SCSW
+ */
+union scsw {
+       struct cmd_scsw cmd;
+       struct tm_scsw tm;
+} __attribute__ ((packed));
+
+int scsw_is_tm(union scsw *scsw);
+u32 scsw_key(union scsw *scsw);
+u32 scsw_eswf(union scsw *scsw);
+u32 scsw_cc(union scsw *scsw);
+u32 scsw_ectl(union scsw *scsw);
+u32 scsw_pno(union scsw *scsw);
+u32 scsw_fctl(union scsw *scsw);
+u32 scsw_actl(union scsw *scsw);
+u32 scsw_stctl(union scsw *scsw);
+u32 scsw_dstat(union scsw *scsw);
+u32 scsw_cstat(union scsw *scsw);
+int scsw_is_solicited(union scsw *scsw);
+int scsw_is_valid_key(union scsw *scsw);
+int scsw_is_valid_eswf(union scsw *scsw);
+int scsw_is_valid_cc(union scsw *scsw);
+int scsw_is_valid_ectl(union scsw *scsw);
+int scsw_is_valid_pno(union scsw *scsw);
+int scsw_is_valid_fctl(union scsw *scsw);
+int scsw_is_valid_actl(union scsw *scsw);
+int scsw_is_valid_stctl(union scsw *scsw);
+int scsw_is_valid_dstat(union scsw *scsw);
+int scsw_is_valid_cstat(union scsw *scsw);
+int scsw_cmd_is_valid_key(union scsw *scsw);
+int scsw_cmd_is_valid_sctl(union scsw *scsw);
+int scsw_cmd_is_valid_eswf(union scsw *scsw);
+int scsw_cmd_is_valid_cc(union scsw *scsw);
+int scsw_cmd_is_valid_fmt(union scsw *scsw);
+int scsw_cmd_is_valid_pfch(union scsw *scsw);
+int scsw_cmd_is_valid_isic(union scsw *scsw);
+int scsw_cmd_is_valid_alcc(union scsw *scsw);
+int scsw_cmd_is_valid_ssi(union scsw *scsw);
+int scsw_cmd_is_valid_zcc(union scsw *scsw);
+int scsw_cmd_is_valid_ectl(union scsw *scsw);
+int scsw_cmd_is_valid_pno(union scsw *scsw);
+int scsw_cmd_is_valid_fctl(union scsw *scsw);
+int scsw_cmd_is_valid_actl(union scsw *scsw);
+int scsw_cmd_is_valid_stctl(union scsw *scsw);
+int scsw_cmd_is_valid_dstat(union scsw *scsw);
+int scsw_cmd_is_valid_cstat(union scsw *scsw);
+int scsw_cmd_is_solicited(union scsw *scsw);
+int scsw_tm_is_valid_key(union scsw *scsw);
+int scsw_tm_is_valid_eswf(union scsw *scsw);
+int scsw_tm_is_valid_cc(union scsw *scsw);
+int scsw_tm_is_valid_fmt(union scsw *scsw);
+int scsw_tm_is_valid_x(union scsw *scsw);
+int scsw_tm_is_valid_q(union scsw *scsw);
+int scsw_tm_is_valid_ectl(union scsw *scsw);
+int scsw_tm_is_valid_pno(union scsw *scsw);
+int scsw_tm_is_valid_fctl(union scsw *scsw);
+int scsw_tm_is_valid_actl(union scsw *scsw);
+int scsw_tm_is_valid_stctl(union scsw *scsw);
+int scsw_tm_is_valid_dstat(union scsw *scsw);
+int scsw_tm_is_valid_cstat(union scsw *scsw);
+int scsw_tm_is_valid_fcxs(union scsw *scsw);
+int scsw_tm_is_valid_schxs(union scsw *scsw);
+int scsw_tm_is_solicited(union scsw *scsw);
+
 #define SCSW_FCTL_CLEAR_FUNC    0x1
 #define SCSW_FCTL_HALT_FUNC     0x2
 #define SCSW_FCTL_START_FUNC    0x4
@@ -303,7 +411,7 @@ struct esw3 {
  * if applicable).
  */
 struct irb {
-       struct scsw scsw;
+       union scsw scsw;
        union {
                struct esw0 esw0;
                struct esw1 esw1;
index b3ac262..3cad569 100644 (file)
 typedef s390_fp_regs elf_fpregset_t;
 typedef s390_regs elf_gregset_t;
 
+typedef s390_fp_regs compat_elf_fpregset_t;
+typedef s390_compat_regs compat_elf_gregset_t;
+
 #include <linux/sched.h>       /* for task_struct */
 #include <asm/system.h>                /* for save_access_regs */
 #include <asm/mmu_context.h>
@@ -123,6 +126,10 @@ typedef s390_regs elf_gregset_t;
 #define elf_check_arch(x) \
        (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
          && (x)->e_ident[EI_CLASS] == ELF_CLASS) 
+#define compat_elf_check_arch(x) \
+       (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
+        && (x)->e_ident[EI_CLASS] == ELF_CLASS)
+#define compat_start_thread    start_thread31
 
 /* For SVR4/S390 the function pointer to be registered with `atexit` is
    passed in R14. */
@@ -131,6 +138,7 @@ typedef s390_regs elf_gregset_t;
                _r->gprs[14] = 0; \
        } while (0)
 
+#define CORE_DUMP_USE_REGSET
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE      4096
 
@@ -140,44 +148,6 @@ typedef s390_regs elf_gregset_t;
    that it will "exec", and that there is sufficient room for the brk.  */
 #define ELF_ET_DYN_BASE                (STACK_TOP / 3 * 2)
 
-/* Wow, the "main" arch needs arch dependent functions too.. :) */
-
-/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
-   now struct_user_regs, they are different) */
-
-static inline int dump_regs(struct pt_regs *ptregs, elf_gregset_t *regs)
-{
-       memcpy(&regs->psw, &ptregs->psw, sizeof(regs->psw)+sizeof(regs->gprs));
-       save_access_regs(regs->acrs);
-       regs->orig_gpr2 = ptregs->orig_gpr2;
-       return 1;
-}
-
-#define ELF_CORE_COPY_REGS(pr_reg, regs) dump_regs(regs, &pr_reg);
-
-static inline int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
-{
-       struct pt_regs *ptregs = task_pt_regs(tsk);
-       memcpy(&regs->psw, &ptregs->psw, sizeof(regs->psw)+sizeof(regs->gprs));
-       memcpy(regs->acrs, tsk->thread.acrs, sizeof(regs->acrs));
-       regs->orig_gpr2 = ptregs->orig_gpr2;
-       return 1;
-}
-
-#define ELF_CORE_COPY_TASK_REGS(tsk, regs) dump_task_regs(tsk, regs)
-
-static inline int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
-{
-       if (tsk == current)
-               save_fp_regs(fpregs);
-       else
-               memcpy(fpregs, &tsk->thread.fp_regs, sizeof(elf_fpregset_t));
-       return 1;
-}
-
-#define ELF_CORE_COPY_FPREGS(tsk, fpregs) dump_task_fpu(tsk, fpregs)
-
-
 /* This yields a mask that user programs can use to figure out what
    instruction set this CPU supports. */
 
@@ -204,7 +174,10 @@ do {                                                       \
                set_personality(PER_SVR4);              \
        else if (current->personality != PER_LINUX32)   \
                set_personality(PER_LINUX);             \
-       clear_thread_flag(TIF_31BIT);                   \
+       if ((ex).e_ident[EI_CLASS] == ELFCLASS32)       \
+               set_thread_flag(TIF_31BIT);             \
+       else                                            \
+               clear_thread_flag(TIF_31BIT);           \
 } while (0)
 #endif /* __s390x__ */
 
index b498f19..80ef58c 100644 (file)
@@ -122,7 +122,7 @@ struct etr_aib {
 } __attribute__ ((packed,aligned(8)));
 
 /* ETR interruption parameter */
-struct etr_interruption_parameter {
+struct etr_irq_parm {
        unsigned int _pad0      : 8;
        unsigned int pc0        : 1;    /* port 0 state change */
        unsigned int pc1        : 1;    /* port 1 state change */
@@ -213,7 +213,46 @@ static inline int etr_ptff(void *ptff_block, unsigned int func)
 #define ETR_PTFF_SGS   0x43    /* set gross steering rate */
 
 /* Functions needed by the machine check handler */
-extern void etr_switch_to_local(void);
-extern void etr_sync_check(void);
+void etr_switch_to_local(void);
+void etr_sync_check(void);
+
+/* STP interruption parameter */
+struct stp_irq_parm {
+       unsigned int _pad0      : 14;
+       unsigned int tsc        : 1;    /* Timing status change */
+       unsigned int lac        : 1;    /* Link availability change */
+       unsigned int tcpc       : 1;    /* Time control parameter change */
+       unsigned int _pad2      : 15;
+} __attribute__ ((packed));
+
+#define STP_OP_SYNC    1
+#define STP_OP_CTRL    3
+
+struct stp_sstpi {
+       unsigned int rsvd0;
+       unsigned int rsvd1 : 8;
+       unsigned int stratum : 8;
+       unsigned int vbits : 16;
+       unsigned int leaps : 16;
+       unsigned int tmd : 4;
+       unsigned int ctn : 4;
+       unsigned int rsvd2 : 3;
+       unsigned int c : 1;
+       unsigned int tst : 4;
+       unsigned int tzo : 16;
+       unsigned int dsto : 16;
+       unsigned int ctrl : 16;
+       unsigned int rsvd3 : 16;
+       unsigned int tto;
+       unsigned int rsvd4;
+       unsigned int ctnid[3];
+       unsigned int rsvd5;
+       unsigned int todoff[4];
+       unsigned int rsvd6[48];
+} __attribute__ ((packed));
+
+/* Functions needed by the machine check handler */
+void stp_sync_check(void);
+void stp_island_check(void);
 
 #endif /* __S390_ETR_H */
diff --git a/include/asm-s390/fcx.h b/include/asm-s390/fcx.h
new file mode 100644 (file)
index 0000000..8be1f3a
--- /dev/null
@@ -0,0 +1,311 @@
+/*
+ *  Functions for assembling fcx enabled I/O control blocks.
+ *
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#ifndef _ASM_S390_FCX_H
+#define _ASM_S390_FCX_H _ASM_S390_FCX_H
+
+#include <linux/types.h>
+
+#define TCW_FORMAT_DEFAULT             0
+#define TCW_TIDAW_FORMAT_DEFAULT       0
+#define TCW_FLAGS_INPUT_TIDA           1 << (23 - 5)
+#define TCW_FLAGS_TCCB_TIDA            1 << (23 - 6)
+#define TCW_FLAGS_OUTPUT_TIDA          1 << (23 - 7)
+#define TCW_FLAGS_TIDAW_FORMAT(x)      ((x) & 3) << (23 - 9)
+#define TCW_FLAGS_GET_TIDAW_FORMAT(x)  (((x) >> (23 - 9)) & 3)
+
+/**
+ * struct tcw - Transport Control Word (TCW)
+ * @format: TCW format
+ * @flags: TCW flags
+ * @tccbl: Transport-Command-Control-Block Length
+ * @r: Read Operations
+ * @w: Write Operations
+ * @output: Output-Data Address
+ * @input: Input-Data Address
+ * @tsb: Transport-Status-Block Address
+ * @tccb: Transport-Command-Control-Block Address
+ * @output_count: Output Count
+ * @input_count: Input Count
+ * @intrg: Interrogate TCW Address
+ */
+struct tcw {
+       u32 format:2;
+       u32 :6;
+       u32 flags:24;
+       u32 :8;
+       u32 tccbl:6;
+       u32 r:1;
+       u32 w:1;
+       u32 :16;
+       u64 output;
+       u64 input;
+       u64 tsb;
+       u64 tccb;
+       u32 output_count;
+       u32 input_count;
+       u32 :32;
+       u32 :32;
+       u32 :32;
+       u32 intrg;
+} __attribute__ ((packed, aligned(64)));
+
+#define TIDAW_FLAGS_LAST               1 << (7 - 0)
+#define TIDAW_FLAGS_SKIP               1 << (7 - 1)
+#define TIDAW_FLAGS_DATA_INT           1 << (7 - 2)
+#define TIDAW_FLAGS_TTIC               1 << (7 - 3)
+#define TIDAW_FLAGS_INSERT_CBC         1 << (7 - 4)
+
+/**
+ * struct tidaw - Transport-Indirect-Addressing Word (TIDAW)
+ * @flags: TIDAW flags. Can be an arithmetic OR of the following constants:
+ * %TIDAW_FLAGS_LAST, %TIDAW_FLAGS_SKIP, %TIDAW_FLAGS_DATA_INT,
+ * %TIDAW_FLAGS_TTIC, %TIDAW_FLAGS_INSERT_CBC
+ * @count: Count
+ * @addr: Address
+ */
+struct tidaw {
+       u32 flags:8;
+       u32 :24;
+       u32 count;
+       u64 addr;
+} __attribute__ ((packed, aligned(16)));
+
+/**
+ * struct tsa_iostat - I/O-Status Transport-Status Area (IO-Stat TSA)
+ * @dev_time: Device Time
+ * @def_time: Defer Time
+ * @queue_time: Queue Time
+ * @dev_busy_time: Device-Busy Time
+ * @dev_act_time: Device-Active-Only Time
+ * @sense: Sense Data (if present)
+ */
+struct tsa_iostat {
+       u32 dev_time;
+       u32 def_time;
+       u32 queue_time;
+       u32 dev_busy_time;
+       u32 dev_act_time;
+       u8 sense[32];
+} __attribute__ ((packed));
+
+/**
+ * struct tsa_ddpcs - Device-Detected-Program-Check Transport-Status Area (DDPC TSA)
+ * @rc: Reason Code
+ * @rcq: Reason Code Qualifier
+ * @sense: Sense Data (if present)
+ */
+struct tsa_ddpc {
+       u32 :24;
+       u32 rc:8;
+       u8 rcq[16];
+       u8 sense[32];
+} __attribute__ ((packed));
+
+#define TSA_INTRG_FLAGS_CU_STATE_VALID         1 << (7 - 0)
+#define TSA_INTRG_FLAGS_DEV_STATE_VALID                1 << (7 - 1)
+#define TSA_INTRG_FLAGS_OP_STATE_VALID         1 << (7 - 2)
+
+/**
+ * struct tsa_intrg - Interrogate Transport-Status Area (Intrg. TSA)
+ * @format: Format
+ * @flags: Flags. Can be an arithmetic OR of the following constants:
+ * %TSA_INTRG_FLAGS_CU_STATE_VALID, %TSA_INTRG_FLAGS_DEV_STATE_VALID,
+ * %TSA_INTRG_FLAGS_OP_STATE_VALID
+ * @cu_state: Controle-Unit State
+ * @dev_state: Device State
+ * @op_state: Operation State
+ * @sd_info: State-Dependent Information
+ * @dl_id: Device-Level Identifier
+ * @dd_data: Device-Dependent Data
+ */
+struct tsa_intrg {
+       u32 format:8;
+       u32 flags:8;
+       u32 cu_state:8;
+       u32 dev_state:8;
+       u32 op_state:8;
+       u32 :24;
+       u8 sd_info[12];
+       u32 dl_id;
+       u8 dd_data[28];
+} __attribute__ ((packed));
+
+#define TSB_FORMAT_NONE                0
+#define TSB_FORMAT_IOSTAT      1
+#define TSB_FORMAT_DDPC                2
+#define TSB_FORMAT_INTRG       3
+
+#define TSB_FLAGS_DCW_OFFSET_VALID     1 << (7 - 0)
+#define TSB_FLAGS_COUNT_VALID          1 << (7 - 1)
+#define TSB_FLAGS_CACHE_MISS           1 << (7 - 2)
+#define TSB_FLAGS_TIME_VALID           1 << (7 - 3)
+#define TSB_FLAGS_FORMAT(x)            ((x) & 7)
+#define TSB_FORMAT(t)                  ((t)->flags & 7)
+
+/**
+ * struct tsb - Transport-Status Block (TSB)
+ * @length: Length
+ * @flags: Flags. Can be an arithmetic OR of the following constants:
+ * %TSB_FLAGS_DCW_OFFSET_VALID, %TSB_FLAGS_COUNT_VALID, %TSB_FLAGS_CACHE_MISS,
+ * %TSB_FLAGS_TIME_VALID
+ * @dcw_offset: DCW Offset
+ * @count: Count
+ * @tsa: Transport-Status-Area
+ */
+struct tsb {
+       u32 length:8;
+       u32 flags:8;
+       u32 dcw_offset:16;
+       u32 count;
+       u32 :32;
+       union {
+               struct tsa_iostat iostat;
+               struct tsa_ddpc ddpc;
+               struct tsa_intrg intrg;
+       } __attribute__ ((packed)) tsa;
+} __attribute__ ((packed, aligned(8)));
+
+#define DCW_INTRG_FORMAT_DEFAULT       0
+
+#define DCW_INTRG_RC_UNSPECIFIED       0
+#define DCW_INTRG_RC_TIMEOUT           1
+
+#define DCW_INTRG_RCQ_UNSPECIFIED      0
+#define DCW_INTRG_RCQ_PRIMARY          1
+#define DCW_INTRG_RCQ_SECONDARY                2
+
+#define DCW_INTRG_FLAGS_MPM            1 < (7 - 0)
+#define DCW_INTRG_FLAGS_PPR            1 < (7 - 1)
+#define DCW_INTRG_FLAGS_CRIT           1 < (7 - 2)
+
+/**
+ * struct dcw_intrg_data - Interrogate DCW data
+ * @format: Format. Should be %DCW_INTRG_FORMAT_DEFAULT
+ * @rc: Reason Code. Can be one of %DCW_INTRG_RC_UNSPECIFIED,
+ * %DCW_INTRG_RC_TIMEOUT
+ * @rcq: Reason Code Qualifier: Can be one of %DCW_INTRG_RCQ_UNSPECIFIED,
+ * %DCW_INTRG_RCQ_PRIMARY, %DCW_INTRG_RCQ_SECONDARY
+ * @lpm: Logical-Path Mask
+ * @pam: Path-Available Mask
+ * @pim: Path-Installed Mask
+ * @timeout: Timeout
+ * @flags: Flags. Can be an arithmetic OR of %DCW_INTRG_FLAGS_MPM,
+ * %DCW_INTRG_FLAGS_PPR, %DCW_INTRG_FLAGS_CRIT
+ * @time: Time
+ * @prog_id: Program Identifier
+ * @prog_data: Program-Dependent Data
+ */
+struct dcw_intrg_data {
+       u32 format:8;
+       u32 rc:8;
+       u32 rcq:8;
+       u32 lpm:8;
+       u32 pam:8;
+       u32 pim:8;
+       u32 timeout:16;
+       u32 flags:8;
+       u32 :24;
+       u32 :32;
+       u64 time;
+       u64 prog_id;
+       u8  prog_data[0];
+} __attribute__ ((packed));
+
+#define DCW_FLAGS_CC           1 << (7 - 1)
+
+#define DCW_CMD_WRITE          0x01
+#define DCW_CMD_READ           0x02
+#define DCW_CMD_CONTROL                0x03
+#define DCW_CMD_SENSE          0x04
+#define DCW_CMD_SENSE_ID       0xe4
+#define DCW_CMD_INTRG          0x40
+
+/**
+ * struct dcw - Device-Command Word (DCW)
+ * @cmd: Command Code. Can be one of %DCW_CMD_WRITE, %DCW_CMD_READ,
+ * %DCW_CMD_CONTROL, %DCW_CMD_SENSE, %DCW_CMD_SENSE_ID, %DCW_CMD_INTRG
+ * @flags: Flags. Can be an arithmetic OR of %DCW_FLAGS_CC
+ * @cd_count: Control-Data Count
+ * @count: Count
+ * @cd: Control Data
+ */
+struct dcw {
+       u32 cmd:8;
+       u32 flags:8;
+       u32 :8;
+       u32 cd_count:8;
+       u32 count;
+       u8 cd[0];
+} __attribute__ ((packed));
+
+#define TCCB_FORMAT_DEFAULT    0x7f
+#define TCCB_MAX_DCW           30
+#define TCCB_MAX_SIZE          (sizeof(struct tccb_tcah) + \
+                                TCCB_MAX_DCW * sizeof(struct dcw) + \
+                                sizeof(struct tccb_tcat))
+#define TCCB_SAC_DEFAULT       0xf901
+#define TCCB_SAC_INTRG         0xf902
+
+/**
+ * struct tccb_tcah - Transport-Command-Area Header (TCAH)
+ * @format: Format. Should be %TCCB_FORMAT_DEFAULT
+ * @tcal: Transport-Command-Area Length
+ * @sac: Service-Action Code. Can be one of %TCCB_SAC_DEFAULT, %TCCB_SAC_INTRG
+ * @prio: Priority
+ */
+struct tccb_tcah {
+       u32 format:8;
+       u32 :24;
+       u32 :24;
+       u32 tcal:8;
+       u32 sac:16;
+       u32 :8;
+       u32 prio:8;
+       u32 :32;
+} __attribute__ ((packed));
+
+/**
+ * struct tccb_tcat - Transport-Command-Area Trailer (TCAT)
+ * @count: Transport Count
+ */
+struct tccb_tcat {
+       u32 :32;
+       u32 count;
+} __attribute__ ((packed));
+
+/**
+ * struct tccb - (partial) Transport-Command-Control Block (TCCB)
+ * @tcah: TCAH
+ * @tca: Transport-Command Area
+ */
+struct tccb {
+       struct tccb_tcah tcah;
+       u8 tca[0];
+} __attribute__ ((packed, aligned(8)));
+
+struct tcw *tcw_get_intrg(struct tcw *tcw);
+void *tcw_get_data(struct tcw *tcw);
+struct tccb *tcw_get_tccb(struct tcw *tcw);
+struct tsb *tcw_get_tsb(struct tcw *tcw);
+
+void tcw_init(struct tcw *tcw, int r, int w);
+void tcw_finalize(struct tcw *tcw, int num_tidaws);
+
+void tcw_set_intrg(struct tcw *tcw, struct tcw *intrg_tcw);
+void tcw_set_data(struct tcw *tcw, void *data, int use_tidal);
+void tcw_set_tccb(struct tcw *tcw, struct tccb *tccb);
+void tcw_set_tsb(struct tcw *tcw, struct tsb *tsb);
+
+void tccb_init(struct tccb *tccb, size_t tccb_size, u32 sac);
+void tsb_init(struct tsb *tsb);
+struct dcw *tccb_add_dcw(struct tccb *tccb, size_t tccb_size, u8 cmd, u8 flags,
+                        void *cd, u8 cd_count, u32 count);
+struct tidaw *tcw_add_tidaw(struct tcw *tcw, int num_tidaws, u8 flags,
+                           void *addr, u32 count);
+
+#endif /* _ASM_S390_FCX_H */
index c1b2e50..eaca6df 100644 (file)
@@ -56,15 +56,19 @@ struct ipl_block_fcp {
        u8  scp_data[];
 } __attribute__((packed));
 
+#define DIAG308_VMPARM_SIZE    64
+
 struct ipl_block_ccw {
-       u8  load_param[8];
+       u8  load_parm[8];
        u8  reserved1[84];
        u8  reserved2[2];
        u16 devno;
        u8  vm_flags;
        u8  reserved3[3];
        u32 vm_parm_len;
-       u8  reserved4[80];
+       u8  nss_name[8];
+       u8  vm_parm[DIAG308_VMPARM_SIZE];
+       u8  reserved4[8];
 } __attribute__((packed));
 
 struct ipl_parameter_block {
@@ -73,7 +77,7 @@ struct ipl_parameter_block {
                struct ipl_block_fcp fcp;
                struct ipl_block_ccw ccw;
        } ipl_info;
-} __attribute__((packed));
+} __attribute__((packed,aligned(4096)));
 
 /*
  * IPL validity flags
@@ -86,6 +90,8 @@ extern void do_reipl(void);
 extern void do_halt(void);
 extern void do_poff(void);
 extern void ipl_save_parameters(void);
+extern void ipl_update_parameters(void);
+extern void get_ipl_vmparm(char *);
 
 enum {
        IPL_DEVNO_VALID         = 1,
@@ -147,6 +153,11 @@ enum diag308_flags {
        DIAG308_FLAGS_LP_VALID  = 0x80,
 };
 
+enum diag308_vm_flags {
+       DIAG308_VM_FLAGS_NSS_VALID      = 0x80,
+       DIAG308_VM_FLAGS_VP_VALID       = 0x40,
+};
+
 enum diag308_rc {
        DIAG308_RC_OK   = 1,
 };
diff --git a/include/asm-s390/isc.h b/include/asm-s390/isc.h
new file mode 100644 (file)
index 0000000..34bb891
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef _ASM_S390_ISC_H
+#define _ASM_S390_ISC_H
+
+#include <linux/types.h>
+
+/*
+ * I/O interruption subclasses used by drivers.
+ * Please add all used iscs here so that it is possible to distribute
+ * isc usage between drivers.
+ * Reminder: 0 is highest priority, 7 lowest.
+ */
+#define MAX_ISC 7
+
+/* Regular I/O interrupts. */
+#define IO_SCH_ISC 3                   /* regular I/O subchannels */
+#define CONSOLE_ISC 1                  /* console I/O subchannel */
+#define CHSC_SCH_ISC 7                 /* CHSC subchannels */
+/* Adapter interrupts. */
+#define QDIO_AIRQ_ISC IO_SCH_ISC       /* I/O subchannel in qdio mode */
+
+/* Functions for registration of I/O interruption subclasses */
+void isc_register(unsigned int isc);
+void isc_unregister(unsigned int isc);
+
+#endif /* _ASM_S390_ISC_H */
diff --git a/include/asm-s390/itcw.h b/include/asm-s390/itcw.h
new file mode 100644 (file)
index 0000000..a9bc5c3
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  Functions for incremental construction of fcx enabled I/O control blocks.
+ *
+ *    Copyright IBM Corp. 2008
+ *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
+ */
+
+#ifndef _ASM_S390_ITCW_H
+#define _ASM_S390_ITCW_H _ASM_S390_ITCW_H
+
+#include <linux/types.h>
+#include <asm/fcx.h>
+
+#define ITCW_OP_READ   0
+#define ITCW_OP_WRITE  1
+
+struct itcw;
+
+struct tcw *itcw_get_tcw(struct itcw *itcw);
+size_t itcw_calc_size(int intrg, int max_tidaws, int intrg_max_tidaws);
+struct itcw *itcw_init(void *buffer, size_t size, int op, int intrg,
+                      int max_tidaws, int intrg_max_tidaws);
+struct dcw *itcw_add_dcw(struct itcw *itcw, u8 cmd, u8 flags, void *cd,
+                        u8 cd_count, u32 count);
+struct tidaw *itcw_add_tidaw(struct itcw *itcw, u8 flags, void *addr,
+                            u32 count);
+void itcw_set_data(struct itcw *itcw, void *addr, int use_tidal);
+void itcw_finalize(struct itcw *itcw);
+
+#endif /* _ASM_S390_ITCW_H */
index bd0ea19..0bdb704 100644 (file)
@@ -29,6 +29,7 @@
  * the S390 page table tree.
  */
 #ifndef __ASSEMBLY__
+#include <linux/sched.h>
 #include <linux/mm_types.h>
 #include <asm/bitops.h>
 #include <asm/bug.h>
index a00f79d..4af80af 100644 (file)
@@ -143,11 +143,19 @@ struct stack_frame {
 /*
  * Do necessary setup to start up a new thread.
  */
-#define start_thread(regs, new_psw, new_stackp) do {            \
+#define start_thread(regs, new_psw, new_stackp) do {           \
        set_fs(USER_DS);                                        \
        regs->psw.mask  = psw_user_bits;                        \
-        regs->psw.addr  = new_psw | PSW_ADDR_AMODE;             \
-        regs->gprs[15]  = new_stackp ;                          \
+       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;             \
+       regs->gprs[15]  = new_stackp;                           \
+} while (0)
+
+#define start_thread31(regs, new_psw, new_stackp) do {         \
+       set_fs(USER_DS);                                        \
+       regs->psw.mask  = psw_user32_bits;                      \
+       regs->psw.addr  = new_psw | PSW_ADDR_AMODE;             \
+       regs->gprs[15]  = new_stackp;                           \
+       crst_table_downgrade(current->mm, 1UL << 31);           \
 } while (0)
 
 /* Forward declaration, a strange C thing */
@@ -328,16 +336,6 @@ extern void (*s390_base_mcck_handler_fn)(void);
 extern void (*s390_base_pgm_handler_fn)(void);
 extern void (*s390_base_ext_handler_fn)(void);
 
-/*
- * CPU idle notifier chain.
- */
-#define S390_CPU_IDLE          0
-#define S390_CPU_NOT_IDLE      1
-
-struct notifier_block;
-int register_idle_notifier(struct notifier_block *nb);
-int unregister_idle_notifier(struct notifier_block *nb);
-
 #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
 
 #endif
index d7d4e2e..af2c9ac 100644 (file)
@@ -215,6 +215,12 @@ typedef struct
         unsigned long addr;
 } __attribute__ ((aligned(8))) psw_t;
 
+typedef struct
+{
+       __u32   mask;
+       __u32   addr;
+} __attribute__ ((aligned(8))) psw_compat_t;
+
 #ifndef __s390x__
 
 #define PSW_MASK_PER           0x40000000UL
@@ -292,6 +298,15 @@ typedef struct
        unsigned long orig_gpr2;
 } s390_regs;
 
+typedef struct
+{
+       psw_compat_t    psw;
+       __u32           gprs[NUM_GPRS];
+       __u32           acrs[NUM_ACRS];
+       __u32           orig_gpr2;
+} s390_compat_regs;
+
+
 #ifdef __KERNEL__
 #include <asm/setup.h>
 #include <asm/page.h>
diff --git a/include/asm-s390/schid.h b/include/asm-s390/schid.h
new file mode 100644 (file)
index 0000000..5017ffa
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef ASM_SCHID_H
+#define ASM_SCHID_H
+
+struct subchannel_id {
+       __u32 cssid : 8;
+       __u32 : 4;
+       __u32 m : 1;
+       __u32 ssid : 2;
+       __u32 one : 1;
+       __u32 sch_no : 16;
+} __attribute__ ((packed, aligned(4)));
+
+
+/* Helper function for sane state of pre-allocated subchannel_id. */
+static inline void
+init_subchannel_id(struct subchannel_id *schid)
+{
+       memset(schid, 0, sizeof(struct subchannel_id));
+       schid->one = 1;
+}
+
+static inline int
+schid_equal(struct subchannel_id *schid1, struct subchannel_id *schid2)
+{
+       return !memcmp(schid1, schid2, sizeof(struct subchannel_id));
+}
+
+#endif /* ASM_SCHID_H */
index b5f2843..fed7bee 100644 (file)
@@ -45,9 +45,9 @@ struct sclp_cpu_info {
 int sclp_get_cpu_info(struct sclp_cpu_info *info);
 int sclp_cpu_configure(u8 cpu);
 int sclp_cpu_deconfigure(u8 cpu);
-void sclp_read_info_early(void);
 void sclp_facilities_detect(void);
-unsigned long long sclp_memory_detect(void);
+unsigned long long sclp_get_rnmax(void);
+unsigned long long sclp_get_rzm(void);
 int sclp_sdias_blk_count(void);
 int sclp_sdias_copy(void *dest, int blk_num, int nr_blks);
 int sclp_chp_configure(struct chp_id chpid);
index ba69674..f09ee3f 100644 (file)
@@ -8,14 +8,16 @@
 #ifndef _ASM_S390_SETUP_H
 #define _ASM_S390_SETUP_H
 
-#define COMMAND_LINE_SIZE      896
+#define COMMAND_LINE_SIZE      1024
+
+#define ARCH_COMMAND_LINE_SIZE 896
 
 #ifdef __KERNEL__
 
 #include <asm/types.h>
 
 #define PARMAREA               0x10400
-#define MEMORY_CHUNKS          16      /* max 0x7fff */
+#define MEMORY_CHUNKS          256
 
 #ifndef __ASSEMBLY__
 
 struct mem_chunk {
        unsigned long addr;
        unsigned long size;
-       unsigned long type;
+       int type;
 };
 
 extern struct mem_chunk memory_chunk[];
 extern unsigned long real_memory_size;
 
+void detect_memory_layout(struct mem_chunk chunk[]);
+
 #ifdef CONFIG_S390_SWITCH_AMODE
 extern unsigned int switch_amode;
 #else
@@ -61,7 +65,6 @@ extern unsigned long machine_flags;
 
 #define MACHINE_FLAG_VM                (1UL << 0)
 #define MACHINE_FLAG_IEEE      (1UL << 1)
-#define MACHINE_FLAG_P390      (1UL << 2)
 #define MACHINE_FLAG_CSP       (1UL << 3)
 #define MACHINE_FLAG_MVPG      (1UL << 4)
 #define MACHINE_FLAG_DIAG44    (1UL << 5)
@@ -97,7 +100,6 @@ extern unsigned long machine_flags;
 #define MACHINE_HAS_PFMF       (machine_flags & MACHINE_FLAG_PFMF)
 #endif /* __s390x__ */
 
-#define MACHINE_HAS_SCLP       (!MACHINE_IS_P390)
 #define ZFCPDUMP_HSA_SIZE      (32UL<<20)
 
 /*
index 06dfdab..545d219 100644 (file)
@@ -1,15 +1,15 @@
 #ifndef _ASM_S390_SPARSEMEM_H
 #define _ASM_S390_SPARSEMEM_H
 
-#define SECTION_SIZE_BITS      25
-
 #ifdef CONFIG_64BIT
 
+#define SECTION_SIZE_BITS      28
 #define MAX_PHYSADDR_BITS      42
 #define MAX_PHYSMEM_BITS       42
 
 #else
 
+#define SECTION_SIZE_BITS      25
 #define MAX_PHYSADDR_BITS      31
 #define MAX_PHYSMEM_BITS       31
 
index adb3486..d98d79e 100644 (file)
@@ -48,6 +48,18 @@ extern int del_virt_timer(struct vtimer_list *timer);
 extern void init_cpu_vtimer(void);
 extern void vtime_init(void);
 
+#ifdef CONFIG_VIRT_TIMER
+
+extern void vtime_start_cpu_timer(void);
+extern void vtime_stop_cpu_timer(void);
+
+#else
+
+static inline void vtime_start_cpu_timer(void) { }
+static inline void vtime_stop_cpu_timer(void) { }
+
+#endif /* CONFIG_VIRT_TIMER */
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_S390_TIMER_H */
index f228f1b..00d3bbd 100644 (file)
@@ -29,7 +29,7 @@
 
 #define ZCRYPT_VERSION 2
 #define ZCRYPT_RELEASE 1
-#define ZCRYPT_VARIANT 0
+#define ZCRYPT_VARIANT 1
 
 #include <linux/ioctl.h>
 #include <linux/compiler.h>
diff --git a/include/asm-sparc64/ftrace.h b/include/asm-sparc64/ftrace.h
new file mode 100644 (file)
index 0000000..d27716c
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _ASM_SPARC64_FTRACE
+#define _ASM_SPARC64_FTRACE
+
+#ifdef CONFIG_MCOUNT
+#define MCOUNT_ADDR            ((long)(_mcount))
+#define MCOUNT_INSN_SIZE       4 /* sizeof mcount call */
+
+#ifndef __ASSEMBLY__
+extern void _mcount(void);
+#endif
+
+#endif
+
+#endif /* _ASM_SPARC64_FTRACE */
index 14411c9..635d764 100644 (file)
@@ -28,6 +28,7 @@
 #include <asm/numa.h>
 #include <asm/processor.h>
 #include <asm/mmu.h>
+#include <asm/mpspec.h>
 
 #define COMPILER_DEPENDENT_INT64   long long
 #define COMPILER_DEPENDENT_UINT64  unsigned long long
@@ -160,9 +161,7 @@ struct bootnode;
 #ifdef CONFIG_ACPI_NUMA
 extern int acpi_numa;
 extern int acpi_scan_nodes(unsigned long start, unsigned long end);
-#ifdef CONFIG_X86_64
-# define NR_NODE_MEMBLKS (MAX_NUMNODES*2)
-#endif
+#define NR_NODE_MEMBLKS (MAX_NUMNODES*2)
 extern void acpi_fake_nodes(const struct bootnode *fake_nodes,
                                   int num_nodes);
 #else
index 1f6a9ca..f6aa18e 100644 (file)
@@ -72,6 +72,8 @@ static inline void alternatives_smp_module_del(struct module *mod) {}
 static inline void alternatives_smp_switch(int smp) {}
 #endif /* CONFIG_SMP */
 
+const unsigned char *const *find_nop_table(void);
+
 /*
  * Alternative instructions for different CPU types or capabilities.
  *
diff --git a/include/asm-x86/amd_iommu.h b/include/asm-x86/amd_iommu.h
new file mode 100644 (file)
index 0000000..30a1204
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
+ * Author: Joerg Roedel <joerg.roedel@amd.com>
+ *         Leo Duran <leo.duran@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#ifndef _ASM_X86_AMD_IOMMU_H
+#define _ASM_X86_AMD_IOMMU_H
+
+#ifdef CONFIG_AMD_IOMMU
+extern int amd_iommu_init(void);
+extern int amd_iommu_init_dma_ops(void);
+extern void amd_iommu_detect(void);
+#else
+static inline int amd_iommu_init(void) { return -ENODEV; }
+static inline void amd_iommu_detect(void) { }
+#endif
+
+#endif
diff --git a/include/asm-x86/amd_iommu_types.h b/include/asm-x86/amd_iommu_types.h
new file mode 100644 (file)
index 0000000..7bfcb47
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2007-2008 Advanced Micro Devices, Inc.
+ * Author: Joerg Roedel <joerg.roedel@amd.com>
+ *         Leo Duran <leo.duran@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#ifndef __AMD_IOMMU_TYPES_H__
+#define __AMD_IOMMU_TYPES_H__
+
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+
+/*
+ * some size calculation constants
+ */
+#define DEV_TABLE_ENTRY_SIZE           256
+#define ALIAS_TABLE_ENTRY_SIZE         2
+#define RLOOKUP_TABLE_ENTRY_SIZE       (sizeof(void *))
+
+/* helper macros */
+#define LOW_U32(x) ((x) & ((1ULL << 32)-1))
+#define HIGH_U32(x) (LOW_U32((x) >> 32))
+
+/* Length of the MMIO region for the AMD IOMMU */
+#define MMIO_REGION_LENGTH       0x4000
+
+/* Capability offsets used by the driver */
+#define MMIO_CAP_HDR_OFFSET    0x00
+#define MMIO_RANGE_OFFSET      0x0c
+
+/* Masks, shifts and macros to parse the device range capability */
+#define MMIO_RANGE_LD_MASK     0xff000000
+#define MMIO_RANGE_FD_MASK     0x00ff0000
+#define MMIO_RANGE_BUS_MASK    0x0000ff00
+#define MMIO_RANGE_LD_SHIFT    24
+#define MMIO_RANGE_FD_SHIFT    16
+#define MMIO_RANGE_BUS_SHIFT   8
+#define MMIO_GET_LD(x)  (((x) & MMIO_RANGE_LD_MASK) >> MMIO_RANGE_LD_SHIFT)
+#define MMIO_GET_FD(x)  (((x) & MMIO_RANGE_FD_MASK) >> MMIO_RANGE_FD_SHIFT)
+#define MMIO_GET_BUS(x) (((x) & MMIO_RANGE_BUS_MASK) >> MMIO_RANGE_BUS_SHIFT)
+
+/* Flag masks for the AMD IOMMU exclusion range */
+#define MMIO_EXCL_ENABLE_MASK 0x01ULL
+#define MMIO_EXCL_ALLOW_MASK  0x02ULL
+
+/* Used offsets into the MMIO space */
+#define MMIO_DEV_TABLE_OFFSET   0x0000
+#define MMIO_CMD_BUF_OFFSET     0x0008
+#define MMIO_EVT_BUF_OFFSET     0x0010
+#define MMIO_CONTROL_OFFSET     0x0018
+#define MMIO_EXCL_BASE_OFFSET   0x0020
+#define MMIO_EXCL_LIMIT_OFFSET  0x0028
+#define MMIO_CMD_HEAD_OFFSET   0x2000
+#define MMIO_CMD_TAIL_OFFSET   0x2008
+#define MMIO_EVT_HEAD_OFFSET   0x2010
+#define MMIO_EVT_TAIL_OFFSET   0x2018
+#define MMIO_STATUS_OFFSET     0x2020
+
+/* feature control bits */
+#define CONTROL_IOMMU_EN        0x00ULL
+#define CONTROL_HT_TUN_EN       0x01ULL
+#define CONTROL_EVT_LOG_EN      0x02ULL
+#define CONTROL_EVT_INT_EN      0x03ULL
+#define CONTROL_COMWAIT_EN      0x04ULL
+#define CONTROL_PASSPW_EN       0x08ULL
+#define CONTROL_RESPASSPW_EN    0x09ULL
+#define CONTROL_COHERENT_EN     0x0aULL
+#define CONTROL_ISOC_EN         0x0bULL
+#define CONTROL_CMDBUF_EN       0x0cULL
+#define CONTROL_PPFLOG_EN       0x0dULL
+#define CONTROL_PPFINT_EN       0x0eULL
+
+/* command specific defines */
+#define CMD_COMPL_WAIT          0x01
+#define CMD_INV_DEV_ENTRY       0x02
+#define CMD_INV_IOMMU_PAGES     0x03
+
+#define CMD_COMPL_WAIT_STORE_MASK      0x01
+#define CMD_INV_IOMMU_PAGES_SIZE_MASK  0x01
+#define CMD_INV_IOMMU_PAGES_PDE_MASK   0x02
+
+#define CMD_INV_IOMMU_ALL_PAGES_ADDRESS        0x7fffffffffffffffULL
+
+/* macros and definitions for device table entries */
+#define DEV_ENTRY_VALID         0x00
+#define DEV_ENTRY_TRANSLATION   0x01
+#define DEV_ENTRY_IR            0x3d
+#define DEV_ENTRY_IW            0x3e
+#define DEV_ENTRY_EX            0x67
+#define DEV_ENTRY_SYSMGT1       0x68
+#define DEV_ENTRY_SYSMGT2       0x69
+#define DEV_ENTRY_INIT_PASS     0xb8
+#define DEV_ENTRY_EINT_PASS     0xb9
+#define DEV_ENTRY_NMI_PASS      0xba
+#define DEV_ENTRY_LINT0_PASS    0xbe
+#define DEV_ENTRY_LINT1_PASS    0xbf
+
+/* constants to configure the command buffer */
+#define CMD_BUFFER_SIZE    8192
+#define CMD_BUFFER_ENTRIES 512
+#define MMIO_CMD_SIZE_SHIFT 56
+#define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT)
+
+#define PAGE_MODE_1_LEVEL 0x01
+#define PAGE_MODE_2_LEVEL 0x02
+#define PAGE_MODE_3_LEVEL 0x03
+
+#define IOMMU_PDE_NL_0   0x000ULL
+#define IOMMU_PDE_NL_1   0x200ULL
+#define IOMMU_PDE_NL_2   0x400ULL
+#define IOMMU_PDE_NL_3   0x600ULL
+
+#define IOMMU_PTE_L2_INDEX(address) (((address) >> 30) & 0x1ffULL)
+#define IOMMU_PTE_L1_INDEX(address) (((address) >> 21) & 0x1ffULL)
+#define IOMMU_PTE_L0_INDEX(address) (((address) >> 12) & 0x1ffULL)
+
+#define IOMMU_MAP_SIZE_L1 (1ULL << 21)
+#define IOMMU_MAP_SIZE_L2 (1ULL << 30)
+#define IOMMU_MAP_SIZE_L3 (1ULL << 39)
+
+#define IOMMU_PTE_P  (1ULL << 0)
+#define IOMMU_PTE_U  (1ULL << 59)
+#define IOMMU_PTE_FC (1ULL << 60)
+#define IOMMU_PTE_IR (1ULL << 61)
+#define IOMMU_PTE_IW (1ULL << 62)
+
+#define IOMMU_L1_PDE(address) \
+       ((address) | IOMMU_PDE_NL_1 | IOMMU_PTE_P | IOMMU_PTE_IR | IOMMU_PTE_IW)
+#define IOMMU_L2_PDE(address) \
+       ((address) | IOMMU_PDE_NL_2 | IOMMU_PTE_P | IOMMU_PTE_IR | IOMMU_PTE_IW)
+
+#define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL)
+#define IOMMU_PTE_PRESENT(pte) ((pte) & IOMMU_PTE_P)
+#define IOMMU_PTE_PAGE(pte) (phys_to_virt((pte) & IOMMU_PAGE_MASK))
+#define IOMMU_PTE_MODE(pte) (((pte) >> 9) & 0x07)
+
+#define IOMMU_PROT_MASK 0x03
+#define IOMMU_PROT_IR 0x01
+#define IOMMU_PROT_IW 0x02
+
+/* IOMMU capabilities */
+#define IOMMU_CAP_IOTLB   24
+#define IOMMU_CAP_NPCACHE 26
+
+#define MAX_DOMAIN_ID 65536
+
+struct protection_domain {
+       spinlock_t lock;
+       u16 id;
+       int mode;
+       u64 *pt_root;
+       void *priv;
+};
+
+struct dma_ops_domain {
+       struct list_head list;
+       struct protection_domain domain;
+       unsigned long aperture_size;
+       unsigned long next_bit;
+       unsigned long *bitmap;
+       u64 **pte_pages;
+};
+
+struct amd_iommu {
+       struct list_head list;
+       spinlock_t lock;
+
+       u16 devid;
+       u16 cap_ptr;
+
+       u64 mmio_phys;
+       u8 *mmio_base;
+       u32 cap;
+       u16 first_device;
+       u16 last_device;
+       u64 exclusion_start;
+       u64 exclusion_length;
+
+       u8 *cmd_buf;
+       u32 cmd_buf_size;
+
+       int need_sync;
+
+       struct dma_ops_domain *default_dom;
+};
+
+extern struct list_head amd_iommu_list;
+
+struct dev_table_entry {
+       u32 data[8];
+};
+
+struct unity_map_entry {
+       struct list_head list;
+       u16 devid_start;
+       u16 devid_end;
+       u64 address_start;
+       u64 address_end;
+       int prot;
+};
+
+extern struct list_head amd_iommu_unity_map;
+
+/* data structures for device handling */
+extern struct dev_table_entry *amd_iommu_dev_table;
+extern u16 *amd_iommu_alias_table;
+extern struct amd_iommu **amd_iommu_rlookup_table;
+
+extern unsigned amd_iommu_aperture_order;
+
+extern u16 amd_iommu_last_bdf;
+
+/* data structures for protection domain handling */
+extern struct protection_domain **amd_iommu_pd_table;
+extern unsigned long *amd_iommu_pd_alloc_bitmap;
+
+extern int amd_iommu_isolate;
+
+static inline void print_devid(u16 devid, int nl)
+{
+       int bus = devid >> 8;
+       int dev = devid >> 3 & 0x1f;
+       int fn  = devid & 0x07;
+
+       printk("%02x:%02x.%x", bus, dev, fn);
+       if (nl)
+               printk("\n");
+}
+
+#endif
index be9639a..4e2c1e5 100644 (file)
@@ -36,15 +36,11 @@ extern void generic_apic_probe(void);
 #ifdef CONFIG_X86_LOCAL_APIC
 
 extern int apic_verbosity;
-extern int timer_over_8254;
 extern int local_apic_timer_c2_ok;
-extern int local_apic_timer_disabled;
 
-extern int apic_runs_main_timer;
 extern int ioapic_force;
-extern int disable_apic;
-extern int disable_apic_timer;
 
+extern int disable_apic;
 /*
  * Basic functions accessing APICs.
  */
@@ -125,16 +121,22 @@ extern void enable_NMI_through_LVT0(void);
  */
 #ifdef CONFIG_X86_64
 extern void early_init_lapic_mapping(void);
+extern int apic_is_clustered_box(void);
+#else
+static inline int apic_is_clustered_box(void)
+{
+       return 0;
+}
 #endif
 
 extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask);
 extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask);
 
-extern int apic_is_clustered_box(void);
 
 #else /* !CONFIG_X86_LOCAL_APIC */
 static inline void lapic_shutdown(void) { }
 #define local_apic_timer_c2_ok         1
+static inline void init_apic_mappings(void) { }
 
 #endif /* !CONFIG_X86_LOCAL_APIC */
 
index 90dec0c..9722032 100644 (file)
@@ -1,37 +1,40 @@
 #ifndef _ASM_X86_ASM_H
 #define _ASM_X86_ASM_H
 
-#ifdef CONFIG_X86_32
-/* 32 bits */
-
-# define _ASM_PTR      " .long "
-# define _ASM_ALIGN    " .balign 4 "
-# define _ASM_MOV_UL   " movl "
-
-# define _ASM_INC      " incl "
-# define _ASM_DEC      " decl "
-# define _ASM_ADD      " addl "
-# define _ASM_SUB      " subl "
-# define _ASM_XADD     " xaddl "
-
+#ifdef __ASSEMBLY__
+# define __ASM_FORM(x) x
+# define __ASM_EX_SEC  .section __ex_table
 #else
-/* 64 bits */
+# define __ASM_FORM(x) " " #x " "
+# define __ASM_EX_SEC  " .section __ex_table,\"a\"\n"
+#endif
 
-# define _ASM_PTR      " .quad "
-# define _ASM_ALIGN    " .balign 8 "
-# define _ASM_MOV_UL   " movq "
-
-# define _ASM_INC      " incq "
-# define _ASM_DEC      " decq "
-# define _ASM_ADD      " addq "
-# define _ASM_SUB      " subq "
-# define _ASM_XADD     " xaddq "
-
-#endif /* CONFIG_X86_32 */
+#ifdef CONFIG_X86_32
+# define __ASM_SEL(a,b) __ASM_FORM(a)
+#else
+# define __ASM_SEL(a,b) __ASM_FORM(b)
+#endif
+
+#define __ASM_SIZE(inst)       __ASM_SEL(inst##l, inst##q)
+#define __ASM_REG(reg)         __ASM_SEL(e##reg, r##reg)
+
+#define _ASM_PTR       __ASM_SEL(.long, .quad)
+#define _ASM_ALIGN     __ASM_SEL(.balign 4, .balign 8)
+#define _ASM_MOV_UL    __ASM_SIZE(mov)
+
+#define _ASM_INC       __ASM_SIZE(inc)
+#define _ASM_DEC       __ASM_SIZE(dec)
+#define _ASM_ADD       __ASM_SIZE(add)
+#define _ASM_SUB       __ASM_SIZE(sub)
+#define _ASM_XADD      __ASM_SIZE(xadd)
+#define _ASM_AX                __ASM_REG(ax)
+#define _ASM_BX                __ASM_REG(bx)
+#define _ASM_CX                __ASM_REG(cx)
+#define _ASM_DX                __ASM_REG(dx)
 
 /* Exception table entry */
 # define _ASM_EXTABLE(from,to) \
-       " .section __ex_table,\"a\"\n" \
+       __ASM_EX_SEC    \
        _ASM_ALIGN "\n" \
        _ASM_PTR #from "," #to "\n" \
        " .previous\n"
index 3e0cd7d..a009519 100644 (file)
  * resource counting etc..
  */
 
-#ifdef CONFIG_SMP
-#define LOCK "lock ; "
-#else
-#define LOCK ""
-#endif
-
 /*
  * Make sure gcc doesn't try to be clever and move things around
  * on us. We need to use _exactly_ the address the user gave us,
@@ -431,6 +425,32 @@ static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
        return c != (u);
 }
 
+/**
+ * atomic_inc_short - increment of a short integer
+ * @v: pointer to type int
+ *
+ * Atomically adds 1 to @v
+ * Returns the new value of @u
+ */
+static inline short int atomic_inc_short(short int *v)
+{
+       asm(LOCK_PREFIX "addw $1, %0" : "+m" (*v));
+       return *v;
+}
+
+/**
+ * atomic_or_long - OR of two long integers
+ * @v1: pointer to type unsigned long
+ * @v2: pointer to type unsigned long
+ *
+ * Atomically ORs @v1 and @v2
+ * Returns the result of the OR
+ */
+static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
+{
+       asm(LOCK_PREFIX "orq %1, %0" : "+m" (*v1) : "r" (v2));
+}
+
 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
 
 /* These are x86-specific, used by some header files */
index b4a46b7..0033e50 100644 (file)
@@ -14,4 +14,6 @@ static inline unsigned int get_bios_ebda(void)
        return address; /* 0 means none */
 }
 
+void reserve_ebda_region(void);
+
 #endif /* _MACH_BIOS_EBDA_H */
index ee4b3ea..96b1829 100644 (file)
 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
 /* Technically wrong, but this avoids compilation errors on some gcc
    versions. */
-#define ADDR "=m" (*(volatile long *) addr)
+#define BITOP_ADDR(x) "=m" (*(volatile long *) (x))
 #else
-#define ADDR "+m" (*(volatile long *) addr)
+#define BITOP_ADDR(x) "+m" (*(volatile long *) (x))
 #endif
 
+#define ADDR                           BITOP_ADDR(addr)
+
+/*
+ * We do the locked ops that don't return the old value as
+ * a mask operation on a byte.
+ */
+#define IS_IMMEDIATE(nr)               (__builtin_constant_p(nr))
+#define CONST_MASK_ADDR(nr, addr)      BITOP_ADDR((void *)(addr) + ((nr)>>3))
+#define CONST_MASK(nr)                 (1 << ((nr) & 7))
+
 /**
  * set_bit - Atomically set a bit in memory
  * @nr: the bit to set
  * Note that @nr may be almost arbitrarily large; this function is not
  * restricted to acting on a single-word quantity.
  */
-static inline void set_bit(int nr, volatile void *addr)
+static inline void set_bit(unsigned int nr, volatile unsigned long *addr)
 {
-       asm volatile(LOCK_PREFIX "bts %1,%0" : ADDR : "Ir" (nr) : "memory");
+       if (IS_IMMEDIATE(nr)) {
+               asm volatile(LOCK_PREFIX "orb %1,%0"
+                       : CONST_MASK_ADDR(nr, addr)
+                       : "iq" ((u8)CONST_MASK(nr))
+                       : "memory");
+       } else {
+               asm volatile(LOCK_PREFIX "bts %1,%0"
+                       : BITOP_ADDR(addr) : "Ir" (nr) : "memory");
+       }
 }
 
 /**
@@ -57,7 +75,7 @@ static inline void set_bit(int nr, volatile void *addr)
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void __set_bit(int nr, volatile void *addr)
+static inline void __set_bit(int nr, volatile unsigned long *addr)
 {
        asm volatile("bts %1,%0" : ADDR : "Ir" (nr) : "memory");
 }
@@ -72,9 +90,17 @@ static inline void __set_bit(int nr, volatile void *addr)
  * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
  * in order to ensure changes are visible on other processors.
  */
-static inline void clear_bit(int nr, volatile void *addr)
+static inline void clear_bit(int nr, volatile unsigned long *addr)
 {
-       asm volatile(LOCK_PREFIX "btr %1,%0" : ADDR : "Ir" (nr));
+       if (IS_IMMEDIATE(nr)) {
+               asm volatile(LOCK_PREFIX "andb %1,%0"
+                       : CONST_MASK_ADDR(nr, addr)
+                       : "iq" ((u8)~CONST_MASK(nr)));
+       } else {
+               asm volatile(LOCK_PREFIX "btr %1,%0"
+                       : BITOP_ADDR(addr)
+                       : "Ir" (nr));
+       }
 }
 
 /*
@@ -85,13 +111,13 @@ static inline void clear_bit(int nr, volatile void *addr)
  * clear_bit() is atomic and implies release semantics before the memory
  * operation. It can be used for an unlock.
  */
-static inline void clear_bit_unlock(unsigned nr, volatile void *addr)
+static inline void clear_bit_unlock(unsigned nr, volatile unsigned long *addr)
 {
        barrier();
        clear_bit(nr, addr);
 }
 
-static inline void __clear_bit(int nr, volatile void *addr)
+static inline void __clear_bit(int nr, volatile unsigned long *addr)
 {
        asm volatile("btr %1,%0" : ADDR : "Ir" (nr));
 }
@@ -108,7 +134,7 @@ static inline void __clear_bit(int nr, volatile void *addr)
  * No memory barrier is required here, because x86 cannot reorder stores past
  * older loads. Same principle as spin_unlock.
  */
-static inline void __clear_bit_unlock(unsigned nr, volatile void *addr)
+static inline void __clear_bit_unlock(unsigned nr, volatile unsigned long *addr)
 {
        barrier();
        __clear_bit(nr, addr);
@@ -126,7 +152,7 @@ static inline void __clear_bit_unlock(unsigned nr, volatile void *addr)
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void __change_bit(int nr, volatile void *addr)
+static inline void __change_bit(int nr, volatile unsigned long *addr)
 {
        asm volatile("btc %1,%0" : ADDR : "Ir" (nr));
 }
@@ -140,7 +166,7 @@ static inline void __change_bit(int nr, volatile void *addr)
  * Note that @nr may be almost arbitrarily large; this function is not
  * restricted to acting on a single-word quantity.
  */
-static inline void change_bit(int nr, volatile void *addr)
+static inline void change_bit(int nr, volatile unsigned long *addr)
 {
        asm volatile(LOCK_PREFIX "btc %1,%0" : ADDR : "Ir" (nr));
 }
@@ -153,7 +179,7 @@ static inline void change_bit(int nr, volatile void *addr)
  * This operation is atomic and cannot be reordered.
  * It also implies a memory barrier.
  */
-static inline int test_and_set_bit(int nr, volatile void *addr)
+static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -170,7 +196,7 @@ static inline int test_and_set_bit(int nr, volatile void *addr)
  *
  * This is the same as test_and_set_bit on x86.
  */
-static inline int test_and_set_bit_lock(int nr, volatile void *addr)
+static inline int test_and_set_bit_lock(int nr, volatile unsigned long *addr)
 {
        return test_and_set_bit(nr, addr);
 }
@@ -184,7 +210,7 @@ static inline int test_and_set_bit_lock(int nr, volatile void *addr)
  * If two examples of this operation race, one can appear to succeed
  * but actually fail.  You must protect multiple accesses with a lock.
  */
-static inline int __test_and_set_bit(int nr, volatile void *addr)
+static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -203,7 +229,7 @@ static inline int __test_and_set_bit(int nr, volatile void *addr)
  * This operation is atomic and cannot be reordered.
  * It also implies a memory barrier.
  */
-static inline int test_and_clear_bit(int nr, volatile void *addr)
+static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -223,7 +249,7 @@ static inline int test_and_clear_bit(int nr, volatile void *addr)
  * If two examples of this operation race, one can appear to succeed
  * but actually fail.  You must protect multiple accesses with a lock.
  */
-static inline int __test_and_clear_bit(int nr, volatile void *addr)
+static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -235,7 +261,7 @@ static inline int __test_and_clear_bit(int nr, volatile void *addr)
 }
 
 /* WARNING: non atomic and it can be reordered! */
-static inline int __test_and_change_bit(int nr, volatile void *addr)
+static inline int __test_and_change_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -255,7 +281,7 @@ static inline int __test_and_change_bit(int nr, volatile void *addr)
  * This operation is atomic and cannot be reordered.
  * It also implies a memory barrier.
  */
-static inline int test_and_change_bit(int nr, volatile void *addr)
+static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
 {
        int oldbit;
 
@@ -266,13 +292,13 @@ static inline int test_and_change_bit(int nr, volatile void *addr)
        return oldbit;
 }
 
-static inline int constant_test_bit(int nr, const volatile void *addr)
+static inline int constant_test_bit(int nr, const volatile unsigned long *addr)
 {
        return ((1UL << (nr % BITS_PER_LONG)) &
                (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 }
 
-static inline int variable_test_bit(int nr, volatile const void *addr)
+static inline int variable_test_bit(int nr, volatile const unsigned long *addr)
 {
        int oldbit;
 
index f62f473..ae22bdf 100644 (file)
@@ -11,6 +11,7 @@
 
 /* setup data types */
 #define SETUP_NONE                     0
+#define SETUP_E820_EXT                 1
 
 /* extensible setup data list node */
 struct setup_data {
@@ -40,6 +41,7 @@ struct setup_header {
        __u8    type_of_loader;
        __u8    loadflags;
 #define LOADED_HIGH    (1<<0)
+#define QUIET_FLAG     (1<<5)
 #define KEEP_SEGMENTS  (1<<6)
 #define CAN_USE_HEAP   (1<<7)
        __u16   setup_move_size;
index d9b26b9..17463cc 100644 (file)
@@ -93,6 +93,39 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
        return old;
 }
 
+/*
+ * Always use locked operations when touching memory shared with a
+ * hypervisor, since the system may be SMP even if the guest kernel
+ * isn't.
+ */
+static inline unsigned long __sync_cmpxchg(volatile void *ptr,
+                                          unsigned long old,
+                                          unsigned long new, int size)
+{
+       unsigned long prev;
+       switch (size) {
+       case 1:
+               asm volatile("lock; cmpxchgb %b1,%2"
+                            : "=a"(prev)
+                            : "q"(new), "m"(*__xg(ptr)), "0"(old)
+                            : "memory");
+               return prev;
+       case 2:
+               asm volatile("lock; cmpxchgw %w1,%2"
+                            : "=a"(prev)
+                            : "r"(new), "m"(*__xg(ptr)), "0"(old)
+                            : "memory");
+               return prev;
+       case 4:
+               asm volatile("lock; cmpxchgl %1,%2"
+                            : "=a"(prev)
+                            : "r"(new), "m"(*__xg(ptr)), "0"(old)
+                            : "memory");
+               return prev;
+       }
+       return old;
+}
+
 static inline unsigned long __cmpxchg_local(volatile void *ptr,
                                            unsigned long old,
                                            unsigned long new, int size)
@@ -139,6 +172,10 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
        ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
                                             (unsigned long)(n),        \
                                             sizeof(*(ptr))))
+#define sync_cmpxchg(ptr, o, n)                                                \
+       ((__typeof__(*(ptr)))__sync_cmpxchg((ptr), (unsigned long)(o),  \
+                                           (unsigned long)(n),         \
+                                           sizeof(*(ptr))))
 #define cmpxchg64_local(ptr, o, n)                                     \
 ({                                                                     \
        BUILD_BUG_ON(sizeof(*(ptr)) != 8);                              \
index 0d609c8..75ef959 100644 (file)
@@ -74,8 +74,8 @@
 #define X86_FEATURE_ARCH_PERFMON (3*32+11) /* Intel Architectural PerfMon */
 #define X86_FEATURE_PEBS       (3*32+12)  /* Precise-Event Based Sampling */
 #define X86_FEATURE_BTS                (3*32+13)  /* Branch Trace Store */
-/* 14 free */
-/* 15 free */
+#define X86_FEATURE_SYSCALL32  (3*32+14)  /* syscall in ia32 userspace */
+#define X86_FEATURE_SYSENTER32 (3*32+15)  /* sysenter in ia32 userspace */
 #define X86_FEATURE_REP_GOOD   (3*32+16) /* rep microcode works well on this CPU */
 #define X86_FEATURE_MFENCE_RDTSC (3*32+17) /* Mfence synchronizes RDTSC */
 #define X86_FEATURE_LFENCE_RDTSC (3*32+18) /* Lfence synchronizes RDTSC */
 /* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
 #define X86_FEATURE_LAHF_LM    (6*32+ 0) /* LAHF/SAHF in long mode */
 #define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
+#define X86_FEATURE_IBS                (6*32+ 10) /* Instruction Based Sampling */
 
 /*
  * Auxiliary flags: Linux defined - For features scattered in various
@@ -142,11 +143,11 @@ extern const char * const x86_power_flags[32];
 #define clear_cpu_cap(c, bit)  clear_bit(bit, (unsigned long *)((c)->x86_capability))
 #define setup_clear_cpu_cap(bit) do { \
        clear_cpu_cap(&boot_cpu_data, bit);     \
-       set_bit(bit, cleared_cpu_caps);         \
+       set_bit(bit, (unsigned long *)cleared_cpu_caps); \
 } while (0)
 #define setup_force_cpu_cap(bit) do { \
        set_cpu_cap(&boot_cpu_data, bit);       \
-       clear_bit(bit, cleared_cpu_caps);       \
+       clear_bit(bit, (unsigned long *)cleared_cpu_caps);      \
 } while (0)
 
 #define cpu_has_fpu            boot_cpu_has(X86_FEATURE_FPU)
index d2526d3..7515c19 100644 (file)
@@ -1,5 +1,39 @@
+#ifndef _X86_CURRENT_H
+#define _X86_CURRENT_H
+
 #ifdef CONFIG_X86_32
-# include "current_32.h"
-#else
-# include "current_64.h"
-#endif
+#include <linux/compiler.h>
+#include <asm/percpu.h>
+
+struct task_struct;
+
+DECLARE_PER_CPU(struct task_struct *, current_task);
+static __always_inline struct task_struct *get_current(void)
+{
+       return x86_read_percpu(current_task);
+}
+
+#else /* X86_32 */
+
+#ifndef __ASSEMBLY__
+#include <asm/pda.h>
+
+struct task_struct;
+
+static __always_inline struct task_struct *get_current(void)
+{
+       return read_pda(pcurrent);
+}
+
+#else /* __ASSEMBLY__ */
+
+#include <asm/asm-offsets.h>
+#define GET_CURRENT(reg) movq %gs:(pda_pcurrent),reg
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* X86_32 */
+
+#define current get_current()
+
+#endif /* X86_CURRENT_H */
diff --git a/include/asm-x86/current_32.h b/include/asm-x86/current_32.h
deleted file mode 100644 (file)
index 5af9bdb..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _I386_CURRENT_H
-#define _I386_CURRENT_H
-
-#include <linux/compiler.h>
-#include <asm/percpu.h>
-
-struct task_struct;
-
-DECLARE_PER_CPU(struct task_struct *, current_task);
-static __always_inline struct task_struct *get_current(void)
-{
-       return x86_read_percpu(current_task);
-}
-
-#define current get_current()
-
-#endif /* !(_I386_CURRENT_H) */
diff --git a/include/asm-x86/current_64.h b/include/asm-x86/current_64.h
deleted file mode 100644 (file)
index 2d368ed..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _X86_64_CURRENT_H
-#define _X86_64_CURRENT_H
-
-#if !defined(__ASSEMBLY__)
-struct task_struct;
-
-#include <asm/pda.h>
-
-static inline struct task_struct *get_current(void)
-{
-       struct task_struct *t = read_pda(pcurrent);
-       return t;
-}
-
-#define current get_current()
-
-#else
-
-#ifndef ASM_OFFSET_H
-#include <asm/asm-offsets.h>
-#endif
-
-#define GET_CURRENT(reg) movq %gs:(pda_pcurrent),reg
-
-#endif
-
-#endif /* !(_X86_64_CURRENT_H) */
index 28bddbc..a44c4dc 100644 (file)
@@ -29,11 +29,17 @@ static inline void fill_ldt(struct desc_struct *desc,
 extern struct desc_ptr idt_descr;
 extern gate_desc idt_table[];
 
+struct gdt_page {
+       struct desc_struct gdt[GDT_ENTRIES];
+} __attribute__((aligned(PAGE_SIZE)));
+DECLARE_PER_CPU(struct gdt_page, gdt_page);
+
+static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
+{
+       return per_cpu(gdt_page, cpu).gdt;
+}
+
 #ifdef CONFIG_X86_64
-extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
-extern struct desc_ptr cpu_gdt_descr[];
-/* the cpu gdt accessor */
-#define get_cpu_gdt_table(x) ((struct desc_struct *)cpu_gdt_descr[x].address)
 
 static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
                             unsigned dpl, unsigned ist, unsigned seg)
@@ -51,16 +57,6 @@ static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
 }
 
 #else
-struct gdt_page {
-       struct desc_struct gdt[GDT_ENTRIES];
-} __attribute__((aligned(PAGE_SIZE)));
-DECLARE_PER_CPU(struct gdt_page, gdt_page);
-
-static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
-{
-       return per_cpu(gdt_page, cpu).gdt;
-}
-
 static inline void pack_gate(gate_desc *gate, unsigned char type,
                             unsigned long base, unsigned dpl, unsigned flags,
                             unsigned short seg)
@@ -311,6 +307,28 @@ static inline void set_intr_gate(unsigned int n, void *addr)
        _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
 }
 
+#define SYS_VECTOR_FREE                0
+#define SYS_VECTOR_ALLOCED     1
+
+extern int first_system_vector;
+extern char system_vectors[];
+
+static inline void alloc_system_vector(int vector)
+{
+       if (system_vectors[vector] == SYS_VECTOR_FREE) {
+               system_vectors[vector] = SYS_VECTOR_ALLOCED;
+               if (first_system_vector > vector)
+                       first_system_vector = vector;
+       } else
+               BUG();
+}
+
+static inline void alloc_intr_gate(unsigned int n, void *addr)
+{
+       alloc_system_vector(n);
+       set_intr_gate(n, addr);
+}
+
 /*
  * This routine sets up an interrupt gate at directory privilege level 3.
  */
index eccb4ea..f7bacf3 100644 (file)
@@ -75,10 +75,14 @@ struct ldttss_desc64 {
 typedef struct gate_struct64 gate_desc;
 typedef struct ldttss_desc64 ldt_desc;
 typedef struct ldttss_desc64 tss_desc;
+#define gate_offset(g) ((g).offset_low | ((unsigned long)(g).offset_middle << 16) | ((unsigned long)(g).offset_high << 32))
+#define gate_segment(g) ((g).segment)
 #else
 typedef struct desc_struct gate_desc;
 typedef struct desc_struct ldt_desc;
 typedef struct desc_struct tss_desc;
+#define gate_offset(g)         (((g).b & 0xffff0000) | ((g).a & 0x0000ffff))
+#define gate_segment(g)                ((g).a >> 16)
 #endif
 
 struct desc_ptr {
index 4edf751..58a8657 100644 (file)
@@ -3,12 +3,6 @@
 
 #include <asm/io.h>
 
-#ifdef CONFIG_X86_32
-
-#define dmi_alloc alloc_bootmem
-
-#else /* CONFIG_X86_32 */
-
 #define DMI_MAX_DATA 2048
 
 extern int dmi_alloc_index;
@@ -25,8 +19,6 @@ static inline void *dmi_alloc(unsigned len)
        return dmi_alloc_data + idx;
 }
 
-#endif
-
 /* Use early IO mappings for DMI because it's initialized early */
 #define dmi_ioremap early_ioremap
 #define dmi_iounmap early_iounmap
index b3cbb0c..0bfe250 100644 (file)
@@ -1,5 +1,61 @@
-#ifdef CONFIG_X86_32
-# include "dwarf2_32.h"
+#ifndef _DWARF2_H
+#define _DWARF2_H
+
+#ifndef __ASSEMBLY__
+#warning "asm/dwarf2.h should be only included in pure assembly files"
+#endif
+
+/*
+   Macros for dwarf2 CFI unwind table entries.
+   See "as.info" for details on these pseudo ops. Unfortunately
+   they are only supported in very new binutils, so define them
+   away for older version.
+ */
+
+#ifdef CONFIG_AS_CFI
+
+#define CFI_STARTPROC .cfi_startproc
+#define CFI_ENDPROC .cfi_endproc
+#define CFI_DEF_CFA .cfi_def_cfa
+#define CFI_DEF_CFA_REGISTER .cfi_def_cfa_register
+#define CFI_DEF_CFA_OFFSET .cfi_def_cfa_offset
+#define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset
+#define CFI_OFFSET .cfi_offset
+#define CFI_REL_OFFSET .cfi_rel_offset
+#define CFI_REGISTER .cfi_register
+#define CFI_RESTORE .cfi_restore
+#define CFI_REMEMBER_STATE .cfi_remember_state
+#define CFI_RESTORE_STATE .cfi_restore_state
+#define CFI_UNDEFINED .cfi_undefined
+
+#ifdef CONFIG_AS_CFI_SIGNAL_FRAME
+#define CFI_SIGNAL_FRAME .cfi_signal_frame
+#else
+#define CFI_SIGNAL_FRAME
+#endif
+
 #else
-# include "dwarf2_64.h"
+
+/* Due to the structure of pre-exisiting code, don't use assembler line
+   comment character # to ignore the arguments. Instead, use a dummy macro. */
+.macro ignore a=0, b=0, c=0, d=0
+.endm
+
+#define CFI_STARTPROC  ignore
+#define CFI_ENDPROC    ignore
+#define CFI_DEF_CFA    ignore
+#define CFI_DEF_CFA_REGISTER   ignore
+#define CFI_DEF_CFA_OFFSET     ignore
+#define CFI_ADJUST_CFA_OFFSET  ignore
+#define CFI_OFFSET     ignore
+#define CFI_REL_OFFSET ignore
+#define CFI_REGISTER   ignore
+#define CFI_RESTORE    ignore
+#define CFI_REMEMBER_STATE ignore
+#define CFI_RESTORE_STATE ignore
+#define CFI_UNDEFINED ignore
+#define CFI_SIGNAL_FRAME ignore
+
+#endif
+
 #endif
diff --git a/include/asm-x86/dwarf2_32.h b/include/asm-x86/dwarf2_32.h
deleted file mode 100644 (file)
index 6d66398..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#ifndef _DWARF2_H
-#define _DWARF2_H
-
-#ifndef __ASSEMBLY__
-#warning "asm/dwarf2.h should be only included in pure assembly files"
-#endif
-
-/*
-   Macros for dwarf2 CFI unwind table entries.
-   See "as.info" for details on these pseudo ops. Unfortunately
-   they are only supported in very new binutils, so define them
-   away for older version.
- */
-
-#ifdef CONFIG_UNWIND_INFO
-
-#define CFI_STARTPROC .cfi_startproc
-#define CFI_ENDPROC .cfi_endproc
-#define CFI_DEF_CFA .cfi_def_cfa
-#define CFI_DEF_CFA_REGISTER .cfi_def_cfa_register
-#define CFI_DEF_CFA_OFFSET .cfi_def_cfa_offset
-#define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset
-#define CFI_OFFSET .cfi_offset
-#define CFI_REL_OFFSET .cfi_rel_offset
-#define CFI_REGISTER .cfi_register
-#define CFI_RESTORE .cfi_restore
-#define CFI_REMEMBER_STATE .cfi_remember_state
-#define CFI_RESTORE_STATE .cfi_restore_state
-#define CFI_UNDEFINED .cfi_undefined
-
-#ifdef CONFIG_AS_CFI_SIGNAL_FRAME
-#define CFI_SIGNAL_FRAME .cfi_signal_frame
-#else
-#define CFI_SIGNAL_FRAME
-#endif
-
-#else
-
-/* Due to the structure of pre-exisiting code, don't use assembler line
-   comment character # to ignore the arguments. Instead, use a dummy macro. */
-.macro ignore a=0, b=0, c=0, d=0
-.endm
-
-#define CFI_STARTPROC  ignore
-#define CFI_ENDPROC    ignore
-#define CFI_DEF_CFA    ignore
-#define CFI_DEF_CFA_REGISTER   ignore
-#define CFI_DEF_CFA_OFFSET     ignore
-#define CFI_ADJUST_CFA_OFFSET  ignore
-#define CFI_OFFSET     ignore
-#define CFI_REL_OFFSET ignore
-#define CFI_REGISTER   ignore
-#define CFI_RESTORE    ignore
-#define CFI_REMEMBER_STATE ignore
-#define CFI_RESTORE_STATE ignore
-#define CFI_UNDEFINED ignore
-#define CFI_SIGNAL_FRAME ignore
-
-#endif
-
-#endif
diff --git a/include/asm-x86/dwarf2_64.h b/include/asm-x86/dwarf2_64.h
deleted file mode 100644 (file)
index c950519..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef _DWARF2_H
-#define _DWARF2_H 1
-
-#ifndef __ASSEMBLY__
-#warning "asm/dwarf2.h should be only included in pure assembly files"
-#endif
-
-/*
-   Macros for dwarf2 CFI unwind table entries.
-   See "as.info" for details on these pseudo ops. Unfortunately
-   they are only supported in very new binutils, so define them
-   away for older version.
- */
-
-#ifdef CONFIG_AS_CFI
-
-#define CFI_STARTPROC .cfi_startproc
-#define CFI_ENDPROC .cfi_endproc
-#define CFI_DEF_CFA .cfi_def_cfa
-#define CFI_DEF_CFA_REGISTER .cfi_def_cfa_register
-#define CFI_DEF_CFA_OFFSET .cfi_def_cfa_offset
-#define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset
-#define CFI_OFFSET .cfi_offset
-#define CFI_REL_OFFSET .cfi_rel_offset
-#define CFI_REGISTER .cfi_register
-#define CFI_RESTORE .cfi_restore
-#define CFI_REMEMBER_STATE .cfi_remember_state
-#define CFI_RESTORE_STATE .cfi_restore_state
-#define CFI_UNDEFINED .cfi_undefined
-#ifdef CONFIG_AS_CFI_SIGNAL_FRAME
-#define CFI_SIGNAL_FRAME .cfi_signal_frame
-#else
-#define CFI_SIGNAL_FRAME
-#endif
-
-#else
-
-/* use assembler line comment character # to ignore the arguments. */
-#define CFI_STARTPROC  #
-#define CFI_ENDPROC    #
-#define CFI_DEF_CFA    #
-#define CFI_DEF_CFA_REGISTER   #
-#define CFI_DEF_CFA_OFFSET     #
-#define CFI_ADJUST_CFA_OFFSET  #
-#define CFI_OFFSET     #
-#define CFI_REL_OFFSET #
-#define CFI_REGISTER   #
-#define CFI_RESTORE    #
-#define CFI_REMEMBER_STATE     #
-#define CFI_RESTORE_STATE      #
-#define CFI_UNDEFINED  #
-#define CFI_SIGNAL_FRAME       #
-
-#endif
-
-#endif
index 7004251..33e793e 100644 (file)
@@ -2,6 +2,41 @@
 #define __ASM_E820_H
 #define E820MAP        0x2d0           /* our map */
 #define E820MAX        128             /* number of entries in E820MAP */
+
+/*
+ * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the
+ * constrained space in the zeropage.  If we have more nodes than
+ * that, and if we've booted off EFI firmware, then the EFI tables
+ * passed us from the EFI firmware can list more nodes.  Size our
+ * internal memory map tables to have room for these additional
+ * nodes, based on up to three entries per node for which the
+ * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT),
+ * plus E820MAX, allowing space for the possible duplicate E820
+ * entries that might need room in the same arrays, prior to the
+ * call to sanitize_e820_map() to remove duplicates.  The allowance
+ * of three memory map entries per node is "enough" entries for
+ * the initial hardware platform motivating this mechanism to make
+ * use of additional EFI map entries.  Future platforms may want
+ * to allow more than three entries per node or otherwise refine
+ * this size.
+ */
+
+/*
+ * Odd: 'make headers_check' complains about numa.h if I try
+ * to collapse the next two #ifdef lines to a single line:
+ *     #if defined(__KERNEL__) && defined(CONFIG_EFI)
+ */
+#ifdef __KERNEL__
+#ifdef CONFIG_EFI
+#include <linux/numa.h>
+#define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES)
+#else  /* ! CONFIG_EFI */
+#define E820_X_MAX E820MAX
+#endif
+#else  /* ! __KERNEL__ */
+#define E820_X_MAX E820MAX
+#endif
+
 #define E820NR 0x1e8           /* # entries in E820MAP */
 
 #define E820_RAM       1
@@ -9,6 +44,9 @@
 #define E820_ACPI      3
 #define E820_NVS       4
 
+/* reserved RAM used by kernel itself */
+#define E820_RESERVED_KERN        128
+
 #ifndef __ASSEMBLY__
 struct e820entry {
        __u64 addr;     /* start of memory segment */
@@ -18,22 +56,79 @@ struct e820entry {
 
 struct e820map {
        __u32 nr_map;
-       struct e820entry map[E820MAX];
+       struct e820entry map[E820_X_MAX];
 };
+
+/* see comment in arch/x86/kernel/e820.c */
+extern struct e820map e820;
+extern struct e820map e820_saved;
+
+extern int e820_any_mapped(u64 start, u64 end, unsigned type);
+extern int e820_all_mapped(u64 start, u64 end, unsigned type);
+extern void e820_add_region(u64 start, u64 size, int type);
+extern void e820_print_map(char *who);
+extern int
+sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, int *pnr_map);
+extern u64 e820_update_range(u64 start, u64 size, unsigned old_type,
+                              unsigned new_type);
+extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type,
+                            int checktype);
+extern void update_e820(void);
+extern void e820_setup_gap(void);
+extern int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
+                       unsigned long start_addr, unsigned long long end_addr);
+struct setup_data;
+extern void parse_e820_ext(struct setup_data *data, unsigned long pa_data);
+
+#if defined(CONFIG_X86_64) || \
+       (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
+extern void e820_mark_nosave_regions(unsigned long limit_pfn);
+#else
+static inline void e820_mark_nosave_regions(unsigned long limit_pfn)
+{
+}
+#endif
+
+extern unsigned long end_user_pfn;
+
+extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
+extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
+extern void reserve_early(u64 start, u64 end, char *name);
+extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
+extern void free_early(u64 start, u64 end);
+extern void early_res_to_bootmem(u64 start, u64 end);
+extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
+
+extern unsigned long e820_end_of_ram_pfn(void);
+extern unsigned long e820_end_of_low_ram_pfn(void);
+extern int e820_find_active_region(const struct e820entry *ei,
+                                 unsigned long start_pfn,
+                                 unsigned long last_pfn,
+                                 unsigned long *ei_startpfn,
+                                 unsigned long *ei_endpfn);
+extern void e820_register_active_regions(int nid, unsigned long start_pfn,
+                                        unsigned long end_pfn);
+extern u64 e820_hole_size(u64 start, u64 end);
+extern void finish_e820_parsing(void);
+extern void e820_reserve_resources(void);
+extern void setup_memory_map(void);
+extern char *default_machine_specific_memory_setup(void);
+extern char *machine_specific_memory_setup(void);
+extern char *memory_setup(void);
+
 #endif /* __ASSEMBLY__ */
 
 #define ISA_START_ADDRESS      0xa0000
 #define ISA_END_ADDRESS                0x100000
+#define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
 
 #define BIOS_BEGIN             0x000a0000
 #define BIOS_END               0x00100000
 
 #ifdef __KERNEL__
-#ifdef CONFIG_X86_32
-# include "e820_32.h"
-#else
-# include "e820_64.h"
-#endif
+#include <linux/ioport.h>
+
+#define HIGH_MEMORY    (1024*1024)
 #endif /* __KERNEL__ */
 
 #endif  /* __ASM_E820_H */
diff --git a/include/asm-x86/e820_32.h b/include/asm-x86/e820_32.h
deleted file mode 100644 (file)
index a9f7c6e..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * structures and definitions for the int 15, ax=e820 memory map
- * scheme.
- *
- * In a nutshell, arch/i386/boot/setup.S populates a scratch table
- * in the empty_zero_block that contains a list of usable address/size
- * duples.   In arch/i386/kernel/setup.c, this information is
- * transferred into the e820map, and in arch/i386/mm/init.c, that
- * new information is used to mark pages reserved or not.
- *
- */
-#ifndef __E820_HEADER
-#define __E820_HEADER
-
-#include <linux/ioport.h>
-
-#define HIGH_MEMORY    (1024*1024)
-
-#ifndef __ASSEMBLY__
-
-extern struct e820map e820;
-extern void update_e820(void);
-
-extern int e820_all_mapped(unsigned long start, unsigned long end,
-                          unsigned type);
-extern int e820_any_mapped(u64 start, u64 end, unsigned type);
-extern void propagate_e820_map(void);
-extern void register_bootmem_low_pages(unsigned long max_low_pfn);
-extern void add_memory_region(unsigned long long start,
-                             unsigned long long size, int type);
-extern void update_memory_range(u64 start, u64 size, unsigned old_type,
-                               unsigned new_type);
-extern void e820_register_memory(void);
-extern void limit_regions(unsigned long long size);
-extern void print_memory_map(char *who);
-extern void init_iomem_resources(struct resource *code_resource,
-                                struct resource *data_resource,
-                                struct resource *bss_resource);
-
-#if defined(CONFIG_PM) && defined(CONFIG_HIBERNATION)
-extern void e820_mark_nosave_regions(void);
-#else
-static inline void e820_mark_nosave_regions(void)
-{
-}
-#endif
-
-
-#endif/*!__ASSEMBLY__*/
-#endif/*__E820_HEADER*/
diff --git a/include/asm-x86/e820_64.h b/include/asm-x86/e820_64.h
deleted file mode 100644 (file)
index 71c4d68..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * structures and definitions for the int 15, ax=e820 memory map
- * scheme.
- *
- * In a nutshell, setup.S populates a scratch table in the
- * empty_zero_block that contains a list of usable address/size
- * duples.  setup.c, this information is transferred into the e820map,
- * and in init.c/numa.c, that new information is used to mark pages
- * reserved or not.
- */
-#ifndef __E820_HEADER
-#define __E820_HEADER
-
-#include <linux/ioport.h>
-
-#ifndef __ASSEMBLY__
-extern unsigned long find_e820_area(unsigned long start, unsigned long end,
-                                   unsigned long size, unsigned long align);
-extern unsigned long find_e820_area_size(unsigned long start,
-                                        unsigned long *sizep,
-                                        unsigned long align);
-extern void add_memory_region(unsigned long start, unsigned long size,
-                             int type);
-extern void update_memory_range(u64 start, u64 size, unsigned old_type,
-                               unsigned new_type);
-extern void setup_memory_region(void);
-extern void contig_e820_setup(void);
-extern unsigned long e820_end_of_ram(void);
-extern void e820_reserve_resources(void);
-extern void e820_mark_nosave_regions(void);
-extern int e820_any_mapped(unsigned long start, unsigned long end,
-                          unsigned type);
-extern int e820_all_mapped(unsigned long start, unsigned long end,
-                          unsigned type);
-extern int e820_any_non_reserved(unsigned long start, unsigned long end);
-extern int is_memory_any_valid(unsigned long start, unsigned long end);
-extern int e820_all_non_reserved(unsigned long start, unsigned long end);
-extern int is_memory_all_valid(unsigned long start, unsigned long end);
-extern unsigned long e820_hole_size(unsigned long start, unsigned long end);
-
-extern void e820_setup_gap(void);
-extern void e820_register_active_regions(int nid, unsigned long start_pfn,
-                                        unsigned long end_pfn);
-
-extern void finish_e820_parsing(void);
-
-extern struct e820map e820;
-extern void update_e820(void);
-
-extern void reserve_early(unsigned long start, unsigned long end, char *name);
-extern void free_early(unsigned long start, unsigned long end);
-extern void early_res_to_bootmem(unsigned long start, unsigned long end);
-
-#endif/*!__ASSEMBLY__*/
-
-#endif/*__E820_HEADER*/
index d53004b..7ed2bd7 100644 (file)
@@ -90,7 +90,7 @@ extern void *efi_ioremap(unsigned long addr, unsigned long size);
 
 #endif /* CONFIG_X86_32 */
 
-extern void efi_reserve_bootmem(void);
+extern void efi_reserve_early(void);
 extern void efi_call_phys_prelog(void);
 extern void efi_call_phys_epilog(void);
 
index 8f232dc..7be4733 100644 (file)
@@ -83,9 +83,9 @@ extern unsigned int vdso_enabled;
        (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
 
 #include <asm/processor.h>
+#include <asm/system.h>
 
 #ifdef CONFIG_X86_32
-#include <asm/system.h>                /* for savesegment */
 #include <asm/desc.h>
 
 #define elf_check_arch(x)      elf_check_arch_ia32(x)
index 5bd2069..44d4f82 100644 (file)
@@ -7,7 +7,62 @@
 # include "fixmap_64.h"
 #endif
 
+extern int fixmaps_set;
+
+void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
+void native_set_fixmap(enum fixed_addresses idx,
+                      unsigned long phys, pgprot_t flags);
+
+#ifndef CONFIG_PARAVIRT
+static inline void __set_fixmap(enum fixed_addresses idx,
+                               unsigned long phys, pgprot_t flags)
+{
+       native_set_fixmap(idx, phys, flags);
+}
+#endif
+
+#define set_fixmap(idx, phys)                          \
+       __set_fixmap(idx, phys, PAGE_KERNEL)
+
+/*
+ * Some hardware wants to get fixmapped without caching.
+ */
+#define set_fixmap_nocache(idx, phys)                  \
+       __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
+
 #define clear_fixmap(idx)                      \
        __set_fixmap(idx, 0, __pgprot(0))
 
+#define __fix_to_virt(x)       (FIXADDR_TOP - ((x) << PAGE_SHIFT))
+#define __virt_to_fix(x)       ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
+
+extern void __this_fixmap_does_not_exist(void);
+
+/*
+ * 'index to address' translation. If anyone tries to use the idx
+ * directly without translation, we catch the bug with a NULL-deference
+ * kernel oops. Illegal ranges of incoming indices are caught too.
+ */
+static __always_inline unsigned long fix_to_virt(const unsigned int idx)
+{
+       /*
+        * this branch gets completely eliminated after inlining,
+        * except when someone tries to use fixaddr indices in an
+        * illegal way. (such as mixing up address types or using
+        * out-of-range indices).
+        *
+        * If it doesn't get removed, the linker will complain
+        * loudly with a reasonably clear error message..
+        */
+       if (idx >= __end_of_fixed_addresses)
+               __this_fixmap_does_not_exist();
+
+       return __fix_to_virt(idx);
+}
+
+static inline unsigned long virt_to_fix(const unsigned long vaddr)
+{
+       BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
+       return __virt_to_fix(vaddr);
+}
 #endif
index 4b96148..aae2f05 100644 (file)
@@ -79,10 +79,6 @@ enum fixed_addresses {
        FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
        FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
 #endif
-#ifdef CONFIG_ACPI
-       FIX_ACPI_BEGIN,
-       FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
-#endif
 #ifdef CONFIG_PCI_MMCONFIG
        FIX_PCIE_MCFG,
 #endif
@@ -103,23 +99,18 @@ enum fixed_addresses {
                        (__end_of_permanent_fixed_addresses & 511),
        FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_NESTING - 1,
        FIX_WP_TEST,
+#ifdef CONFIG_ACPI
+       FIX_ACPI_BEGIN,
+       FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
+#endif
 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
        FIX_OHCI1394_BASE,
 #endif
        __end_of_fixed_addresses
 };
 
-extern void __set_fixmap(enum fixed_addresses idx,
-                        unsigned long phys, pgprot_t flags);
 extern void reserve_top_address(unsigned long reserve);
 
-#define set_fixmap(idx, phys)                          \
-       __set_fixmap(idx, phys, PAGE_KERNEL)
-/*
- * Some hardware wants to get fixmapped without caching.
- */
-#define set_fixmap_nocache(idx, phys)                  \
-       __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
 
 #define FIXADDR_TOP    ((unsigned long)__FIXADDR_TOP)
 
@@ -128,38 +119,5 @@ extern void reserve_top_address(unsigned long reserve);
 #define FIXADDR_START          (FIXADDR_TOP - __FIXADDR_SIZE)
 #define FIXADDR_BOOT_START     (FIXADDR_TOP - __FIXADDR_BOOT_SIZE)
 
-#define __fix_to_virt(x)       (FIXADDR_TOP - ((x) << PAGE_SHIFT))
-#define __virt_to_fix(x)       ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
-
-extern void __this_fixmap_does_not_exist(void);
-
-/*
- * 'index to address' translation. If anyone tries to use the idx
- * directly without tranlation, we catch the bug with a NULL-deference
- * kernel oops. Illegal ranges of incoming indices are caught too.
- */
-static __always_inline unsigned long fix_to_virt(const unsigned int idx)
-{
-       /*
-        * this branch gets completely eliminated after inlining,
-        * except when someone tries to use fixaddr indices in an
-        * illegal way. (such as mixing up address types or using
-        * out-of-range indices).
-        *
-        * If it doesn't get removed, the linker will complain
-        * loudly with a reasonably clear error message..
-        */
-       if (idx >= __end_of_fixed_addresses)
-               __this_fixmap_does_not_exist();
-
-       return __fix_to_virt(idx);
-}
-
-static inline unsigned long virt_to_fix(const unsigned long vaddr)
-{
-       BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
-       return __virt_to_fix(vaddr);
-}
-
 #endif /* !__ASSEMBLY__ */
 #endif
index 355d26a..00f3d74 100644 (file)
@@ -12,6 +12,7 @@
 #define _ASM_FIXMAP_64_H
 
 #include <linux/kernel.h>
+#include <asm/acpi.h>
 #include <asm/apicdef.h>
 #include <asm/page.h>
 #include <asm/vsyscall.h>
@@ -39,30 +40,38 @@ enum fixed_addresses {
        VSYSCALL_HPET,
        FIX_DBGP_BASE,
        FIX_EARLYCON_MEM_BASE,
-       FIX_HPET_BASE,
        FIX_APIC_BASE,  /* local (CPU) APIC) -- required for SMP or not */
        FIX_IO_APIC_BASE_0,
        FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
        FIX_EFI_IO_MAP_LAST_PAGE,
        FIX_EFI_IO_MAP_FIRST_PAGE = FIX_EFI_IO_MAP_LAST_PAGE
                                  + MAX_EFI_IO_PAGES - 1,
+#ifdef CONFIG_PARAVIRT
+       FIX_PARAVIRT_BOOTMAP,
+#endif
+#ifdef CONFIG_ACPI
+       FIX_ACPI_BEGIN,
+       FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
+#endif
 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
        FIX_OHCI1394_BASE,
 #endif
+       __end_of_permanent_fixed_addresses,
+       /*
+        * 256 temporary boot-time mappings, used by early_ioremap(),
+        * before ioremap() is functional.
+        *
+        * We round it up to the next 512 pages boundary so that we
+        * can have a single pgd entry and a single pte table:
+        */
+#define NR_FIX_BTMAPS          64
+#define FIX_BTMAPS_NESTING     4
+       FIX_BTMAP_END = __end_of_permanent_fixed_addresses + 512 -
+                       (__end_of_permanent_fixed_addresses & 511),
+       FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS*FIX_BTMAPS_NESTING - 1,
        __end_of_fixed_addresses
 };
 
-extern void __set_fixmap(enum fixed_addresses idx,
-                        unsigned long phys, pgprot_t flags);
-
-#define set_fixmap(idx, phys)                  \
-       __set_fixmap(idx, phys, PAGE_KERNEL)
-/*
- * Some hardware wants to get fixmapped without caching.
- */
-#define set_fixmap_nocache(idx, phys)                  \
-       __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
-
 #define FIXADDR_TOP    (VSYSCALL_END-PAGE_SIZE)
 #define FIXADDR_SIZE   (__end_of_fixed_addresses << PAGE_SHIFT)
 #define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
@@ -71,30 +80,4 @@ extern void __set_fixmap(enum fixed_addresses idx,
 #define FIXADDR_USER_START     ((unsigned long)VSYSCALL32_VSYSCALL)
 #define FIXADDR_USER_END       (FIXADDR_USER_START + PAGE_SIZE)
 
-#define __fix_to_virt(x)       (FIXADDR_TOP - ((x) << PAGE_SHIFT))
-
-extern void __this_fixmap_does_not_exist(void);
-
-/*
- * 'index to address' translation. If anyone tries to use the idx
- * directly without translation, we catch the bug with a NULL-deference
- * kernel oops. Illegal ranges of incoming indices are caught too.
- */
-static __always_inline unsigned long fix_to_virt(const unsigned int idx)
-{
-       /*
-        * this branch gets completely eliminated after inlining,
-        * except when someone tries to use fixaddr indices in an
-        * illegal way. (such as mixing up address types or using
-        * out-of-range indices).
-        *
-        * If it doesn't get removed, the linker will complain
-        * loudly with a reasonably clear error message..
-        */
-       if (idx >= __end_of_fixed_addresses)
-               __this_fixmap_does_not_exist();
-
-       return __fix_to_virt(idx);
-}
-
 #endif
diff --git a/include/asm-x86/ftrace.h b/include/asm-x86/ftrace.h
new file mode 100644 (file)
index 0000000..c184441
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _ASM_X86_FTRACE
+#define _ASM_SPARC64_FTRACE
+
+#ifdef CONFIG_FTRACE
+#define MCOUNT_ADDR            ((long)(mcount))
+#define MCOUNT_INSN_SIZE       5 /* sizeof mcount call */
+
+#ifndef __ASSEMBLY__
+extern void mcount(void);
+#endif
+
+#endif /* CONFIG_FTRACE */
+
+#endif /* _ASM_X86_FTRACE */
index 90958ed..33b9aee 100644 (file)
@@ -1,34 +1,72 @@
-#ifndef _ASM_X8664_IOMMU_H
-#define _ASM_X8664_IOMMU_H 1
-
-extern void pci_iommu_shutdown(void);
-extern void no_iommu_init(void);
-extern int force_iommu, no_iommu;
-extern int iommu_detected;
-#ifdef CONFIG_GART_IOMMU
-extern void gart_iommu_init(void);
-extern void gart_iommu_shutdown(void);
-extern void __init gart_parse_options(char *);
-extern void early_gart_iommu_check(void);
-extern void gart_iommu_hole_init(void);
+#ifndef _ASM_X8664_GART_H
+#define _ASM_X8664_GART_H 1
+
+#include <asm/e820.h>
+#include <asm/iommu.h>
+
+extern void set_up_gart_resume(u32, u32);
+
 extern int fallback_aper_order;
 extern int fallback_aper_force;
-extern int gart_iommu_aperture;
-extern int gart_iommu_aperture_allowed;
-extern int gart_iommu_aperture_disabled;
 extern int fix_aperture;
-#else
-#define gart_iommu_aperture 0
-#define gart_iommu_aperture_allowed 0
 
-static inline void early_gart_iommu_check(void)
+/* PTE bits. */
+#define GPTE_VALID     1
+#define GPTE_COHERENT  2
+
+/* Aperture control register bits. */
+#define GARTEN         (1<<0)
+#define DISGARTCPU     (1<<4)
+#define DISGARTIO      (1<<5)
+
+/* GART cache control register bits. */
+#define INVGART                (1<<0)
+#define GARTPTEERR     (1<<1)
+
+/* K8 On-cpu GART registers */
+#define AMD64_GARTAPERTURECTL  0x90
+#define AMD64_GARTAPERTUREBASE 0x94
+#define AMD64_GARTTABLEBASE    0x98
+#define AMD64_GARTCACHECTL     0x9c
+#define AMD64_GARTEN           (1<<0)
+
+static inline void enable_gart_translation(struct pci_dev *dev, u64 addr)
 {
+       u32 tmp, ctl;
+
+        /* address of the mappings table */
+        addr >>= 12;
+        tmp = (u32) addr<<4;
+        tmp &= ~0xf;
+        pci_write_config_dword(dev, AMD64_GARTTABLEBASE, tmp);
+
+        /* Enable GART translation for this hammer. */
+        pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &ctl);
+        ctl |= GARTEN;
+        ctl &= ~(DISGARTCPU | DISGARTIO);
+        pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl);
 }
 
-static inline void gart_iommu_shutdown(void)
+static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
 {
-}
+       if (!aper_base)
+               return 0;
 
-#endif
+       if (aper_base + aper_size > 0x100000000ULL) {
+               printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n");
+               return 0;
+       }
+       if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
+               printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n");
+               return 0;
+       }
+       if (aper_size < min_size) {
+               printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n",
+                                aper_size>>20, min_size>>20);
+               return 0;
+       }
+
+       return 1;
+}
 
 #endif
index 1de931b..0f85046 100644 (file)
@@ -44,4 +44,6 @@ DECLARE_PER_CPU(int, x2apic_extra_bits);
 extern void uv_cpu_init(void);
 extern int uv_wakeup_secondary(int phys_apicid, unsigned int start_rip);
 
+extern void setup_apic_routing(void);
+
 #endif
index 314434d..000787d 100644 (file)
@@ -3,3 +3,9 @@
 #else
 # include "hardirq_64.h"
 #endif
+
+extern u64 arch_irq_stat_cpu(unsigned int cpu);
+#define arch_irq_stat_cpu      arch_irq_stat_cpu
+
+extern u64 arch_irq_stat(void);
+#define arch_irq_stat          arch_irq_stat
index e153f3b..4514b16 100644 (file)
@@ -74,6 +74,9 @@ struct page *kmap_atomic_to_page(void *ptr);
 
 #define flush_cache_kmaps()    do { } while (0)
 
+extern void add_highpages_with_active_regions(int nid, unsigned long start_pfn,
+                                       unsigned long end_pfn);
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_HIGHMEM_H */
index 6a9b4ac..82f1ac6 100644 (file)
@@ -86,8 +86,8 @@ extern void hpet_unregister_irq_handler(rtc_irq_handler handler);
 #else /* CONFIG_HPET_TIMER */
 
 static inline int hpet_enable(void) { return 0; }
-static inline unsigned long hpet_readl(unsigned long a) { return 0; }
 static inline int is_hpet_enabled(void) { return 0; }
+#define hpet_readl(a) 0
 
 #endif
 #endif /* ASM_X86_HPET_H */
index bf02539..18f067c 100644 (file)
@@ -1,5 +1,106 @@
+#ifndef _ASM_HW_IRQ_H
+#define _ASM_HW_IRQ_H
+
+/*
+ * (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
+ *
+ * moved some of the old arch/i386/kernel/irq.h to here. VY
+ *
+ * IRQ/IPI changes taken from work by Thomas Radke
+ * <tomsoft@informatik.tu-chemnitz.de>
+ *
+ * hacked by Andi Kleen for x86-64.
+ * unified by tglx
+ */
+
+#include <asm/irq_vectors.h>
+
+#ifndef __ASSEMBLY__
+
+#include <linux/percpu.h>
+#include <linux/profile.h>
+#include <linux/smp.h>
+
+#include <asm/atomic.h>
+#include <asm/irq.h>
+#include <asm/sections.h>
+
+#define platform_legacy_irq(irq)       ((irq) < 16)
+
+/* Interrupt handlers registered during init_IRQ */
+extern void apic_timer_interrupt(void);
+extern void error_interrupt(void);
+extern void spurious_interrupt(void);
+extern void thermal_interrupt(void);
+extern void reschedule_interrupt(void);
+
+extern void invalidate_interrupt(void);
+extern void invalidate_interrupt0(void);
+extern void invalidate_interrupt1(void);
+extern void invalidate_interrupt2(void);
+extern void invalidate_interrupt3(void);
+extern void invalidate_interrupt4(void);
+extern void invalidate_interrupt5(void);
+extern void invalidate_interrupt6(void);
+extern void invalidate_interrupt7(void);
+
+extern void irq_move_cleanup_interrupt(void);
+extern void threshold_interrupt(void);
+
+extern void call_function_interrupt(void);
+
+/* PIC specific functions */
+extern void disable_8259A_irq(unsigned int irq);
+extern void enable_8259A_irq(unsigned int irq);
+extern int i8259A_irq_pending(unsigned int irq);
+extern void make_8259A_irq(unsigned int irq);
+extern void init_8259A(int aeoi);
+
+/* IOAPIC */
+#define IO_APIC_IRQ(x) (((x) >= 16) || ((1<<(x)) & io_apic_irqs))
+extern unsigned long io_apic_irqs;
+
+extern void init_VISWS_APIC_irqs(void);
+extern void setup_IO_APIC(void);
+extern void disable_IO_APIC(void);
+extern void print_IO_APIC(void);
+extern int IO_APIC_get_PCI_irq_vector(int bus, int slot, int fn);
+extern void setup_ioapic_dest(void);
+
+#ifdef CONFIG_X86_64
+extern void enable_IO_APIC(void);
+#endif
+
+/* IPI functions */
+extern void send_IPI_self(int vector);
+extern void send_IPI(int dest, int vector);
+
+/* Statistics */
+extern atomic_t irq_err_count;
+extern atomic_t irq_mis_count;
+
+/* EISA */
+extern void eisa_set_level_irq(unsigned int irq);
+
+/* Voyager functions */
+extern asmlinkage void vic_cpi_interrupt(void);
+extern asmlinkage void vic_sys_interrupt(void);
+extern asmlinkage void vic_cmn_interrupt(void);
+extern asmlinkage void qic_timer_interrupt(void);
+extern asmlinkage void qic_invalidate_interrupt(void);
+extern asmlinkage void qic_reschedule_interrupt(void);
+extern asmlinkage void qic_enable_irq_interrupt(void);
+extern asmlinkage void qic_call_function_interrupt(void);
+
 #ifdef CONFIG_X86_32
-# include "hw_irq_32.h"
+extern void (*const interrupt[NR_IRQS])(void);
 #else
-# include "hw_irq_64.h"
+typedef int vector_irq_t[NR_VECTORS];
+DECLARE_PER_CPU(vector_irq_t, vector_irq);
+extern spinlock_t vector_lock;
+#endif
+extern void setup_vector_irq(int cpu);
+
+#endif /* !ASSEMBLY_ */
+
 #endif
diff --git a/include/asm-x86/hw_irq_32.h b/include/asm-x86/hw_irq_32.h
deleted file mode 100644 (file)
index ea88054..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef _ASM_HW_IRQ_H
-#define _ASM_HW_IRQ_H
-
-/*
- *     linux/include/asm/hw_irq.h
- *
- *     (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
- *
- *     moved some of the old arch/i386/kernel/irq.h to here. VY
- *
- *     IRQ/IPI changes taken from work by Thomas Radke
- *     <tomsoft@informatik.tu-chemnitz.de>
- */
-
-#include <linux/profile.h>
-#include <asm/atomic.h>
-#include <asm/irq.h>
-#include <asm/sections.h>
-
-#define NMI_VECTOR             0x02
-
-/*
- * Various low-level irq details needed by irq.c, process.c,
- * time.c, io_apic.c and smp.c
- *
- * Interrupt entry/exit code at both C and assembly level
- */
-
-extern void (*const interrupt[NR_IRQS])(void);
-
-#ifdef CONFIG_SMP
-void reschedule_interrupt(void);
-void invalidate_interrupt(void);
-void call_function_interrupt(void);
-#endif
-
-#ifdef CONFIG_X86_LOCAL_APIC
-void apic_timer_interrupt(void);
-void error_interrupt(void);
-void spurious_interrupt(void);
-void thermal_interrupt(void);
-#define platform_legacy_irq(irq)       ((irq) < 16)
-#endif
-
-void disable_8259A_irq(unsigned int irq);
-void enable_8259A_irq(unsigned int irq);
-int i8259A_irq_pending(unsigned int irq);
-void make_8259A_irq(unsigned int irq);
-void init_8259A(int aeoi);
-void send_IPI_self(int vector);
-void init_VISWS_APIC_irqs(void);
-void setup_IO_APIC(void);
-void disable_IO_APIC(void);
-void print_IO_APIC(void);
-int IO_APIC_get_PCI_irq_vector(int bus, int slot, int fn);
-void send_IPI(int dest, int vector);
-void setup_ioapic_dest(void);
-
-extern unsigned long io_apic_irqs;
-
-extern atomic_t irq_err_count;
-extern atomic_t irq_mis_count;
-
-#define IO_APIC_IRQ(x) (((x) >= 16) || ((1<<(x)) & io_apic_irqs))
-
-#endif /* _ASM_HW_IRQ_H */
diff --git a/include/asm-x86/hw_irq_64.h b/include/asm-x86/hw_irq_64.h
deleted file mode 100644 (file)
index 0062ef3..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-#ifndef _ASM_HW_IRQ_H
-#define _ASM_HW_IRQ_H
-
-/*
- *     linux/include/asm/hw_irq.h
- *
- *     (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
- *
- *     moved some of the old arch/i386/kernel/irq.h to here. VY
- *
- *     IRQ/IPI changes taken from work by Thomas Radke
- *     <tomsoft@informatik.tu-chemnitz.de>
- *
- *     hacked by Andi Kleen for x86-64.
- */
-
-#ifndef __ASSEMBLY__
-#include <asm/atomic.h>
-#include <asm/irq.h>
-#include <linux/profile.h>
-#include <linux/smp.h>
-#include <linux/percpu.h>
-#endif
-
-#define NMI_VECTOR             0x02
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR  0x20
-
-#define IA32_SYSCALL_VECTOR    0x80
-
-
-/* Reserve the lowest usable priority level 0x20 - 0x2f for triggering
- * cleanup after irq migration.
- */
-#define IRQ_MOVE_CLEANUP_VECTOR        FIRST_EXTERNAL_VECTOR
-
-/*
- * Vectors 0x30-0x3f are used for ISA interrupts.
- */
-#define IRQ0_VECTOR            (FIRST_EXTERNAL_VECTOR + 0x10)
-#define IRQ1_VECTOR            (IRQ0_VECTOR + 1)
-#define IRQ2_VECTOR            (IRQ0_VECTOR + 2)
-#define IRQ3_VECTOR            (IRQ0_VECTOR + 3)
-#define IRQ4_VECTOR            (IRQ0_VECTOR + 4)
-#define IRQ5_VECTOR            (IRQ0_VECTOR + 5)
-#define IRQ6_VECTOR            (IRQ0_VECTOR + 6)
-#define IRQ7_VECTOR            (IRQ0_VECTOR + 7)
-#define IRQ8_VECTOR            (IRQ0_VECTOR + 8)
-#define IRQ9_VECTOR            (IRQ0_VECTOR + 9)
-#define IRQ10_VECTOR           (IRQ0_VECTOR + 10)
-#define IRQ11_VECTOR           (IRQ0_VECTOR + 11)
-#define IRQ12_VECTOR           (IRQ0_VECTOR + 12)
-#define IRQ13_VECTOR           (IRQ0_VECTOR + 13)
-#define IRQ14_VECTOR           (IRQ0_VECTOR + 14)
-#define IRQ15_VECTOR           (IRQ0_VECTOR + 15)
-
-/*
- * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
- *
- *  some of the following vectors are 'rare', they are merged
- *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
- *  TLB, reschedule and local APIC vectors are performance-critical.
- */
-#define SPURIOUS_APIC_VECTOR   0xff
-#define ERROR_APIC_VECTOR      0xfe
-#define RESCHEDULE_VECTOR      0xfd
-#define CALL_FUNCTION_VECTOR   0xfc
-/* fb free - please don't readd KDB here because it's useless
-   (hint - think what a NMI bit does to a vector) */
-#define THERMAL_APIC_VECTOR    0xfa
-#define THRESHOLD_APIC_VECTOR   0xf9
-/* f8 free */
-#define INVALIDATE_TLB_VECTOR_END      0xf7
-#define INVALIDATE_TLB_VECTOR_START    0xf0    /* f0-f7 used for TLB flush */
-
-#define NUM_INVALIDATE_TLB_VECTORS     8
-
-/*
- * Local APIC timer IRQ vector is on a different priority level,
- * to work around the 'lost local interrupt if more than 2 IRQ
- * sources per level' errata.
- */
-#define LOCAL_TIMER_VECTOR     0xef
-
-/*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
- * we start at 0x41 to spread out vectors evenly between priority
- * levels. (0x80 is the syscall vector)
- */
-#define FIRST_DEVICE_VECTOR    (IRQ15_VECTOR + 2)
-#define FIRST_SYSTEM_VECTOR    0xef   /* duplicated in irq.h */
-
-
-#ifndef __ASSEMBLY__
-
-/* Interrupt handlers registered during init_IRQ */
-void apic_timer_interrupt(void);
-void spurious_interrupt(void);
-void error_interrupt(void);
-void reschedule_interrupt(void);
-void call_function_interrupt(void);
-void irq_move_cleanup_interrupt(void);
-void invalidate_interrupt0(void);
-void invalidate_interrupt1(void);
-void invalidate_interrupt2(void);
-void invalidate_interrupt3(void);
-void invalidate_interrupt4(void);
-void invalidate_interrupt5(void);
-void invalidate_interrupt6(void);
-void invalidate_interrupt7(void);
-void thermal_interrupt(void);
-void threshold_interrupt(void);
-void i8254_timer_resume(void);
-
-typedef int vector_irq_t[NR_VECTORS];
-DECLARE_PER_CPU(vector_irq_t, vector_irq);
-extern void __setup_vector_irq(int cpu);
-extern spinlock_t vector_lock;
-
-/*
- * Various low-level irq details needed by irq.c, process.c,
- * time.c, io_apic.c and smp.c
- *
- * Interrupt entry/exit code at both C and assembly level
- */
-
-extern void disable_8259A_irq(unsigned int irq);
-extern void enable_8259A_irq(unsigned int irq);
-extern int i8259A_irq_pending(unsigned int irq);
-extern void make_8259A_irq(unsigned int irq);
-extern void init_8259A(int aeoi);
-extern void send_IPI_self(int vector);
-extern void init_VISWS_APIC_irqs(void);
-extern void setup_IO_APIC(void);
-extern void enable_IO_APIC(void);
-extern void disable_IO_APIC(void);
-extern void print_IO_APIC(void);
-extern int IO_APIC_get_PCI_irq_vector(int bus, int slot, int fn);
-extern void send_IPI(int dest, int vector);
-extern void setup_ioapic_dest(void);
-extern void native_init_IRQ(void);
-
-extern unsigned long io_apic_irqs;
-
-extern atomic_t irq_err_count;
-extern atomic_t irq_mis_count;
-
-#define IO_APIC_IRQ(x) (((x) >= 16) || ((1<<(x)) & io_apic_irqs))
-
-#include <asm/ptrace.h>
-
-#define IRQ_NAME2(nr) nr##_interrupt(void)
-#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
-
-/*
- *     SMP has a few special interrupts for IPI messages
- */
-
-#define BUILD_IRQ(nr)                          \
-       asmlinkage void IRQ_NAME(nr);           \
-       asm("\n.p2align\n"                      \
-           "IRQ" #nr "_interrupt:\n\t"         \
-           "push $~(" #nr ") ; "               \
-           "jmp common_interrupt");
-
-#define platform_legacy_irq(irq)       ((irq) < 16)
-
-#endif
-
-#endif /* _ASM_HW_IRQ_H */
index 45d4df3..2f98df9 100644 (file)
@@ -55,4 +55,6 @@ static inline void outb_pic(unsigned char value, unsigned int port)
        udelay(2);
 }
 
+extern struct irq_chip i8259A_chip;
+
 #endif /* __ASM_I8259_H__ */
index d5b11f6..bf5d629 100644 (file)
@@ -3,6 +3,76 @@
 
 #define ARCH_HAS_IOREMAP_WC
 
+#include <linux/compiler.h>
+
+/*
+ * early_ioremap() and early_iounmap() are for temporary early boot-time
+ * mappings, before the real ioremap() is functional.
+ * A boot-time mapping is currently limited to at most 16 pages.
+ */
+#ifndef __ASSEMBLY__
+extern void early_ioremap_init(void);
+extern void early_ioremap_clear(void);
+extern void early_ioremap_reset(void);
+extern void *early_ioremap(unsigned long offset, unsigned long size);
+extern void early_iounmap(void *addr, unsigned long size);
+extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
+#endif
+
+#define build_mmio_read(name, size, type, reg, barrier) \
+static inline type name(const volatile void __iomem *addr) \
+{ type ret; asm volatile("mov" size " %1,%0":"=" reg (ret) \
+:"m" (*(volatile type __force *)addr) barrier); return ret; }
+
+#define build_mmio_write(name, size, type, reg, barrier) \
+static inline void name(type val, volatile void __iomem *addr) \
+{ asm volatile("mov" size " %0,%1": :reg (val), \
+"m" (*(volatile type __force *)addr) barrier); }
+
+build_mmio_read(readb, "b", unsigned char, "q", :"memory")
+build_mmio_read(readw, "w", unsigned short, "r", :"memory")
+build_mmio_read(readl, "l", unsigned int, "r", :"memory")
+
+build_mmio_read(__readb, "b", unsigned char, "q", )
+build_mmio_read(__readw, "w", unsigned short, "r", )
+build_mmio_read(__readl, "l", unsigned int, "r", )
+
+build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
+build_mmio_write(writew, "w", unsigned short, "r", :"memory")
+build_mmio_write(writel, "l", unsigned int, "r", :"memory")
+
+build_mmio_write(__writeb, "b", unsigned char, "q", )
+build_mmio_write(__writew, "w", unsigned short, "r", )
+build_mmio_write(__writel, "l", unsigned int, "r", )
+
+#define readb_relaxed(a) __readb(a)
+#define readw_relaxed(a) __readw(a)
+#define readl_relaxed(a) __readl(a)
+#define __raw_readb __readb
+#define __raw_readw __readw
+#define __raw_readl __readl
+
+#define __raw_writeb __writeb
+#define __raw_writew __writew
+#define __raw_writel __writel
+
+#define mmiowb() barrier()
+
+#ifdef CONFIG_X86_64
+build_mmio_read(readq, "q", unsigned long, "r", :"memory")
+build_mmio_read(__readq, "q", unsigned long, "r", )
+build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
+build_mmio_write(__writeq, "q", unsigned long, "r", )
+
+#define readq_relaxed(a) __readq(a)
+#define __raw_readq __readq
+#define __raw_writeq writeq
+
+/* Let people know we have them */
+#define readq readq
+#define writeq writeq
+#endif
+
 #ifdef CONFIG_X86_32
 # include "io_32.h"
 #else
@@ -16,4 +86,17 @@ extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
                                unsigned long prot_val);
 extern void __iomem *ioremap_wc(unsigned long offset, unsigned long size);
 
+/*
+ * early_ioremap() and early_iounmap() are for temporary early boot-time
+ * mappings, before the real ioremap() is functional.
+ * A boot-time mapping is currently limited to at most 16 pages.
+ */
+extern void early_ioremap_init(void);
+extern void early_ioremap_clear(void);
+extern void early_ioremap_reset(void);
+extern void *early_ioremap(unsigned long offset, unsigned long size);
+extern void early_iounmap(void *addr, unsigned long size);
+extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
+
+
 #endif /* _ASM_X86_IO_H */
index 049e81e..4df44ed 100644 (file)
@@ -121,18 +121,6 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
 
 extern void iounmap(volatile void __iomem *addr);
 
-/*
- * early_ioremap() and early_iounmap() are for temporary early boot-time
- * mappings, before the real ioremap() is functional.
- * A boot-time mapping is currently limited to at most 16 pages.
- */
-extern void early_ioremap_init(void);
-extern void early_ioremap_clear(void);
-extern void early_ioremap_reset(void);
-extern void *early_ioremap(unsigned long offset, unsigned long size);
-extern void early_iounmap(void *addr, unsigned long size);
-extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
-
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
  */
@@ -149,55 +137,6 @@ extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
 #define virt_to_bus virt_to_phys
 #define bus_to_virt phys_to_virt
 
-/*
- * readX/writeX() are used to access memory mapped devices. On some
- * architectures the memory mapped IO stuff needs to be accessed
- * differently. On the x86 architecture, we just read/write the
- * memory location directly.
- */
-
-static inline unsigned char readb(const volatile void __iomem *addr)
-{
-       return *(volatile unsigned char __force *)addr;
-}
-
-static inline unsigned short readw(const volatile void __iomem *addr)
-{
-       return *(volatile unsigned short __force *)addr;
-}
-
-static inline unsigned int readl(const volatile void __iomem *addr)
-{
-       return *(volatile unsigned int __force *) addr;
-}
-
-#define readb_relaxed(addr) readb(addr)
-#define readw_relaxed(addr) readw(addr)
-#define readl_relaxed(addr) readl(addr)
-#define __raw_readb readb
-#define __raw_readw readw
-#define __raw_readl readl
-
-static inline void writeb(unsigned char b, volatile void __iomem *addr)
-{
-       *(volatile unsigned char __force *)addr = b;
-}
-
-static inline void writew(unsigned short b, volatile void __iomem *addr)
-{
-       *(volatile unsigned short __force *)addr = b;
-}
-
-static inline void writel(unsigned int b, volatile void __iomem *addr)
-{
-       *(volatile unsigned int __force *)addr = b;
-}
-#define __raw_writeb writeb
-#define __raw_writew writew
-#define __raw_writel writel
-
-#define mmiowb()
-
 static inline void
 memset_io(volatile void __iomem *addr, unsigned char val, int count)
 {
index 0930bed..ddd8058 100644 (file)
@@ -204,77 +204,6 @@ extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
 #define virt_to_bus virt_to_phys
 #define bus_to_virt phys_to_virt
 
-/*
- * readX/writeX() are used to access memory mapped devices. On some
- * architectures the memory mapped IO stuff needs to be accessed
- * differently. On the x86 architecture, we just read/write the
- * memory location directly.
- */
-
-static inline __u8 __readb(const volatile void __iomem *addr)
-{
-       return *(__force volatile __u8 *)addr;
-}
-
-static inline __u16 __readw(const volatile void __iomem *addr)
-{
-       return *(__force volatile __u16 *)addr;
-}
-
-static __always_inline __u32 __readl(const volatile void __iomem *addr)
-{
-       return *(__force volatile __u32 *)addr;
-}
-
-static inline __u64 __readq(const volatile void __iomem *addr)
-{
-       return *(__force volatile __u64 *)addr;
-}
-
-#define readb(x) __readb(x)
-#define readw(x) __readw(x)
-#define readl(x) __readl(x)
-#define readq(x) __readq(x)
-#define readb_relaxed(a) readb(a)
-#define readw_relaxed(a) readw(a)
-#define readl_relaxed(a) readl(a)
-#define readq_relaxed(a) readq(a)
-#define __raw_readb readb
-#define __raw_readw readw
-#define __raw_readl readl
-#define __raw_readq readq
-
-#define mmiowb()
-
-static inline void __writel(__u32 b, volatile void __iomem *addr)
-{
-       *(__force volatile __u32 *)addr = b;
-}
-
-static inline void __writeq(__u64 b, volatile void __iomem *addr)
-{
-       *(__force volatile __u64 *)addr = b;
-}
-
-static inline void __writeb(__u8 b, volatile void __iomem *addr)
-{
-       *(__force volatile __u8 *)addr = b;
-}
-
-static inline void __writew(__u16 b, volatile void __iomem *addr)
-{
-       *(__force volatile __u16 *)addr = b;
-}
-
-#define writeq(val, addr) __writeq((val), (addr))
-#define writel(val, addr) __writel((val), (addr))
-#define writew(val, addr) __writew((val), (addr))
-#define writeb(val, addr) __writeb((val), (addr))
-#define __raw_writeb writeb
-#define __raw_writew writew
-#define __raw_writel writel
-#define __raw_writeq writeq
-
 void __memcpy_fromio(void *, unsigned long, unsigned);
 void __memcpy_toio(unsigned long, const void *, unsigned);
 
index d593e14..14f82bb 100644 (file)
  * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar
  */
 
+/* I/O Unit Redirection Table */
+#define IO_APIC_REDIR_VECTOR_MASK      0x000FF
+#define IO_APIC_REDIR_DEST_LOGICAL     0x00800
+#define IO_APIC_REDIR_DEST_PHYSICAL    0x00000
+#define IO_APIC_REDIR_SEND_PENDING     (1 << 12)
+#define IO_APIC_REDIR_REMOTE_IRR       (1 << 14)
+#define IO_APIC_REDIR_LEVEL_TRIGGER    (1 << 15)
+#define IO_APIC_REDIR_MASKED           (1 << 16)
+
 /*
  * The structure of the IO-APIC:
  */
@@ -112,21 +121,32 @@ extern int nr_ioapic_registers[MAX_IO_APICS];
 
 #define MP_MAX_IOAPIC_PIN 127
 
-struct mp_ioapic_routing {
-       int apic_id;
-       int gsi_base;
-       int gsi_end;
-       DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
+struct mp_config_ioapic {
+       unsigned long mp_apicaddr;
+       unsigned int mp_apicid;
+       unsigned char mp_type;
+       unsigned char mp_apicver;
+       unsigned char mp_flags;
+};
+
+struct mp_config_intsrc {
+       unsigned int mp_dstapic;
+       unsigned char mp_type;
+       unsigned char mp_irqtype;
+       unsigned short mp_irqflag;
+       unsigned char mp_srcbus;
+       unsigned char mp_srcbusirq;
+       unsigned char mp_dstirq;
 };
 
 /* I/O APIC entries */
-extern struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
+extern struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
 
 /* # of MP IRQ source entries */
 extern int mp_irq_entries;
 
 /* MP IRQ source entries */
-extern struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
+extern struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
 
 /* non-0 if default (table-less) MP configuration */
 extern int mpc_default_type;
@@ -137,6 +157,9 @@ extern int sis_apic_bug;
 /* 1 if "noapic" boot option passed */
 extern int skip_ioapic_setup;
 
+/* 1 if the timer IRQ uses the '8259A Virtual Wire' mode */
+extern int timer_through_8259;
+
 static inline void disable_ioapic_setup(void)
 {
        skip_ioapic_setup = 1;
@@ -162,6 +185,8 @@ extern void ioapic_init_mappings(void);
 
 #else  /* !CONFIG_X86_IO_APIC */
 #define io_apic_assign_pci_irqs 0
+static const int timer_through_8259 = 0;
+static inline void ioapic_init_mappings(void) { }
 #endif
 
 #endif
index 07862fd..068c9a4 100644 (file)
@@ -1,29 +1,34 @@
-#ifndef _ASM_X8664_GART_H
-#define _ASM_X8664_GART_H 1
+#ifndef _ASM_X8664_IOMMU_H
+#define _ASM_X8664_IOMMU_H 1
 
 extern void pci_iommu_shutdown(void);
 extern void no_iommu_init(void);
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
-#ifdef CONFIG_IOMMU
+
+#ifdef CONFIG_GART_IOMMU
+extern int gart_iommu_aperture;
+extern int gart_iommu_aperture_allowed;
+extern int gart_iommu_aperture_disabled;
+
+extern void early_gart_iommu_check(void);
 extern void gart_iommu_init(void);
 extern void gart_iommu_shutdown(void);
 extern void __init gart_parse_options(char *);
-extern void iommu_hole_init(void);
-extern int fallback_aper_order;
-extern int fallback_aper_force;
-extern int iommu_aperture;
-extern int iommu_aperture_allowed;
-extern int iommu_aperture_disabled;
-extern int fix_aperture;
+extern void gart_iommu_hole_init(void);
+
 #else
-#define iommu_aperture 0
-#define iommu_aperture_allowed 0
+#define gart_iommu_aperture            0
+#define gart_iommu_aperture_allowed    0
+#define gart_iommu_aperture_disabled   1
 
-static inline void gart_iommu_shutdown(void)
+static inline void early_gart_iommu_check(void)
 {
 }
 
+static inline void gart_iommu_shutdown(void)
+{
+}
 #endif
 
 #endif
index ecc80f3..196d63c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <asm/hw_irq.h>
 #include <asm/apic.h>
+#include <asm/smp.h>
 
 /*
  * the following functions deal with sending IPIs between CPUs.
index 7ba9054..1a29257 100644 (file)
@@ -1,5 +1,50 @@
-#ifdef CONFIG_X86_32
-# include "irq_32.h"
+#ifndef _ASM_IRQ_H
+#define _ASM_IRQ_H
+/*
+ *     (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
+ *
+ *     IRQ/IPI changes taken from work by Thomas Radke
+ *     <tomsoft@informatik.tu-chemnitz.de>
+ */
+
+#include <asm/apicdef.h>
+#include <asm/irq_vectors.h>
+
+static inline int irq_canonicalize(int irq)
+{
+       return ((irq == 2) ? 9 : irq);
+}
+
+#ifdef CONFIG_X86_LOCAL_APIC
+# define ARCH_HAS_NMI_WATCHDOG
+#endif
+
+#ifdef CONFIG_4KSTACKS
+  extern void irq_ctx_init(int cpu);
+  extern void irq_ctx_exit(int cpu);
+# define __ARCH_HAS_DO_SOFTIRQ
 #else
-# include "irq_64.h"
+# define irq_ctx_init(cpu) do { } while (0)
+# define irq_ctx_exit(cpu) do { } while (0)
+# ifdef CONFIG_X86_64
+#  define __ARCH_HAS_DO_SOFTIRQ
+# endif
+#endif
+
+#ifdef CONFIG_IRQBALANCE
+extern int irqbalance_disable(char *str);
+#endif
+
+#ifdef CONFIG_HOTPLUG_CPU
+#include <linux/cpumask.h>
+extern void fixup_irqs(cpumask_t map);
 #endif
+
+extern unsigned int do_IRQ(struct pt_regs *regs);
+extern void init_IRQ(void);
+extern void native_init_IRQ(void);
+
+/* Interrupt vector management */
+extern DECLARE_BITMAP(used_vectors, NR_VECTORS);
+
+#endif /* _ASM_IRQ_H */
diff --git a/include/asm-x86/irq_32.h b/include/asm-x86/irq_32.h
deleted file mode 100644 (file)
index 0b79f31..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef _ASM_IRQ_H
-#define _ASM_IRQ_H
-
-/*
- *     linux/include/asm/irq.h
- *
- *     (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
- *
- *     IRQ/IPI changes taken from work by Thomas Radke
- *     <tomsoft@informatik.tu-chemnitz.de>
- */
-
-#include <linux/sched.h>
-/* include comes from machine specific directory */
-#include "irq_vectors.h"
-#include <asm/thread_info.h>
-
-static inline int irq_canonicalize(int irq)
-{
-       return ((irq == 2) ? 9 : irq);
-}
-
-#ifdef CONFIG_X86_LOCAL_APIC
-# define ARCH_HAS_NMI_WATCHDOG         /* See include/linux/nmi.h */
-#endif
-
-#ifdef CONFIG_4KSTACKS
-  extern void irq_ctx_init(int cpu);
-  extern void irq_ctx_exit(int cpu);
-# define __ARCH_HAS_DO_SOFTIRQ
-#else
-# define irq_ctx_init(cpu) do { } while (0)
-# define irq_ctx_exit(cpu) do { } while (0)
-#endif
-
-#ifdef CONFIG_IRQBALANCE
-extern int irqbalance_disable(char *str);
-#endif
-
-#ifdef CONFIG_HOTPLUG_CPU
-extern void fixup_irqs(cpumask_t map);
-#endif
-
-unsigned int do_IRQ(struct pt_regs *regs);
-void init_IRQ(void);
-void __init native_init_IRQ(void);
-
-/* Interrupt vector management */
-extern DECLARE_BITMAP(used_vectors, NR_VECTORS);
-
-#endif /* _ASM_IRQ_H */
diff --git a/include/asm-x86/irq_64.h b/include/asm-x86/irq_64.h
deleted file mode 100644 (file)
index 083d35a..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef _ASM_IRQ_H
-#define _ASM_IRQ_H
-
-/*
- *     linux/include/asm/irq.h
- *
- *     (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
- *
- *     IRQ/IPI changes taken from work by Thomas Radke
- *     <tomsoft@informatik.tu-chemnitz.de>
- */
-
-#define TIMER_IRQ 0
-
-/*
- * 16 8259A IRQ's, 208 potential APIC interrupt sources.
- * Right now the APIC is mostly only used for SMP.
- * 256 vectors is an architectural limit. (we can have
- * more than 256 devices theoretically, but they will
- * have to use shared interrupts)
- * Since vectors 0x00-0x1f are used/reserved for the CPU,
- * the usable vector space is 0x20-0xff (224 vectors)
- */
-
-/*
- * The maximum number of vectors supported by x86_64 processors
- * is limited to 256. For processors other than x86_64, NR_VECTORS
- * should be changed accordingly.
- */
-#define NR_VECTORS 256
-
-#define FIRST_SYSTEM_VECTOR    0xef   /* duplicated in hw_irq.h */
-
-#define NR_IRQS (NR_VECTORS + (32 * NR_CPUS))
-#define NR_IRQ_VECTORS NR_IRQS
-
-static inline int irq_canonicalize(int irq)
-{
-       return ((irq == 2) ? 9 : irq);
-}
-
-#define ARCH_HAS_NMI_WATCHDOG          /* See include/linux/nmi.h */
-
-#ifdef CONFIG_HOTPLUG_CPU
-#include <linux/cpumask.h>
-extern void fixup_irqs(cpumask_t map);
-#endif
-
-#define __ARCH_HAS_DO_SOFTIRQ 1
-
-#endif /* _ASM_IRQ_H */
diff --git a/include/asm-x86/irq_vectors.h b/include/asm-x86/irq_vectors.h
new file mode 100644 (file)
index 0000000..0ac864e
--- /dev/null
@@ -0,0 +1,169 @@
+#ifndef _ASM_IRQ_VECTORS_H
+#define _ASM_IRQ_VECTORS_H
+
+#include <linux/threads.h>
+
+#define NMI_VECTOR             0x02
+
+/*
+ * IDT vectors usable for external interrupt sources start
+ * at 0x20:
+ */
+#define FIRST_EXTERNAL_VECTOR  0x20
+
+#ifdef CONFIG_X86_32
+# define SYSCALL_VECTOR                0x80
+#else
+# define IA32_SYSCALL_VECTOR   0x80
+#endif
+
+/*
+ * Reserve the lowest usable priority level 0x20 - 0x2f for triggering
+ * cleanup after irq migration on 64 bit.
+ */
+#define IRQ_MOVE_CLEANUP_VECTOR        FIRST_EXTERNAL_VECTOR
+
+/*
+ * Vectors 0x20-0x2f are used for ISA interrupts on 32 bit.
+ * Vectors 0x30-0x3f are used for ISA interrupts on 64 bit.
+ */
+#ifdef CONFIG_X86_32
+#define IRQ0_VECTOR            (FIRST_EXTERNAL_VECTOR)
+#else
+#define IRQ0_VECTOR            (FIRST_EXTERNAL_VECTOR + 0x10)
+#endif
+#define IRQ1_VECTOR            (IRQ0_VECTOR + 1)
+#define IRQ2_VECTOR            (IRQ0_VECTOR + 2)
+#define IRQ3_VECTOR            (IRQ0_VECTOR + 3)
+#define IRQ4_VECTOR            (IRQ0_VECTOR + 4)
+#define IRQ5_VECTOR            (IRQ0_VECTOR + 5)
+#define IRQ6_VECTOR            (IRQ0_VECTOR + 6)
+#define IRQ7_VECTOR            (IRQ0_VECTOR + 7)
+#define IRQ8_VECTOR            (IRQ0_VECTOR + 8)
+#define IRQ9_VECTOR            (IRQ0_VECTOR + 9)
+#define IRQ10_VECTOR           (IRQ0_VECTOR + 10)
+#define IRQ11_VECTOR           (IRQ0_VECTOR + 11)
+#define IRQ12_VECTOR           (IRQ0_VECTOR + 12)
+#define IRQ13_VECTOR           (IRQ0_VECTOR + 13)
+#define IRQ14_VECTOR           (IRQ0_VECTOR + 14)
+#define IRQ15_VECTOR           (IRQ0_VECTOR + 15)
+
+/*
+ * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
+ *
+ *  some of the following vectors are 'rare', they are merged
+ *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
+ *  TLB, reschedule and local APIC vectors are performance-critical.
+ *
+ *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
+ */
+#ifdef CONFIG_X86_32
+
+# define SPURIOUS_APIC_VECTOR          0xff
+# define ERROR_APIC_VECTOR             0xfe
+# define INVALIDATE_TLB_VECTOR         0xfd
+# define RESCHEDULE_VECTOR             0xfc
+# define CALL_FUNCTION_VECTOR          0xfb
+# define THERMAL_APIC_VECTOR           0xf0
+
+#else
+
+#define SPURIOUS_APIC_VECTOR           0xff
+#define ERROR_APIC_VECTOR              0xfe
+#define RESCHEDULE_VECTOR              0xfd
+#define CALL_FUNCTION_VECTOR           0xfc
+#define THERMAL_APIC_VECTOR            0xfa
+#define THRESHOLD_APIC_VECTOR          0xf9
+#define INVALIDATE_TLB_VECTOR_END      0xf7
+#define INVALIDATE_TLB_VECTOR_START    0xf0    /* f0-f7 used for TLB flush */
+
+#define NUM_INVALIDATE_TLB_VECTORS     8
+
+#endif
+
+/*
+ * Local APIC timer IRQ vector is on a different priority level,
+ * to work around the 'lost local interrupt if more than 2 IRQ
+ * sources per level' errata.
+ */
+#define LOCAL_TIMER_VECTOR     0xef
+
+/*
+ * First APIC vector available to drivers: (vectors 0x30-0xee) we
+ * start at 0x31(0x41) to spread out vectors evenly between priority
+ * levels. (0x80 is the syscall vector)
+ */
+#ifdef CONFIG_X86_32
+# define FIRST_DEVICE_VECTOR   0x31
+#else
+# define FIRST_DEVICE_VECTOR   (IRQ15_VECTOR + 2)
+#endif
+
+#define NR_VECTORS             256
+
+#define FPU_IRQ                        13
+
+#define        FIRST_VM86_IRQ          3
+#define LAST_VM86_IRQ          15
+#define invalid_vm86_irq(irq)  ((irq) < 3 || (irq) > 15)
+
+#if !defined(CONFIG_X86_VOYAGER)
+
+# if defined(CONFIG_X86_IO_APIC) || defined(CONFIG_PARAVIRT) || defined(CONFIG_X86_VISWS)
+
+#  define NR_IRQS              224
+
+#  if (224 >= 32 * NR_CPUS)
+#   define NR_IRQ_VECTORS      NR_IRQS
+#  else
+#   define NR_IRQ_VECTORS      (32 * NR_CPUS)
+#  endif
+
+# else /* IO_APIC || PARAVIRT */
+
+#  define NR_IRQS              16
+#  define NR_IRQ_VECTORS       NR_IRQS
+
+# endif
+
+#else /* !VISWS && !VOYAGER */
+
+# define NR_IRQS               224
+# define NR_IRQ_VECTORS                NR_IRQS
+
+#endif /* VISWS */
+
+/* Voyager specific defines */
+/* These define the CPIs we use in linux */
+#define VIC_CPI_LEVEL0                 0
+#define VIC_CPI_LEVEL1                 1
+/* now the fake CPIs */
+#define VIC_TIMER_CPI                  2
+#define VIC_INVALIDATE_CPI             3
+#define VIC_RESCHEDULE_CPI             4
+#define VIC_ENABLE_IRQ_CPI             5
+#define VIC_CALL_FUNCTION_CPI          6
+
+/* Now the QIC CPIs:  Since we don't need the two initial levels,
+ * these are 2 less than the VIC CPIs */
+#define QIC_CPI_OFFSET                 1
+#define QIC_TIMER_CPI                  (VIC_TIMER_CPI - QIC_CPI_OFFSET)
+#define QIC_INVALIDATE_CPI             (VIC_INVALIDATE_CPI - QIC_CPI_OFFSET)
+#define QIC_RESCHEDULE_CPI             (VIC_RESCHEDULE_CPI - QIC_CPI_OFFSET)
+#define QIC_ENABLE_IRQ_CPI             (VIC_ENABLE_IRQ_CPI - QIC_CPI_OFFSET)
+#define QIC_CALL_FUNCTION_CPI          (VIC_CALL_FUNCTION_CPI - QIC_CPI_OFFSET)
+
+#define VIC_START_FAKE_CPI             VIC_TIMER_CPI
+#define VIC_END_FAKE_CPI               VIC_CALL_FUNCTION_CPI
+
+/* this is the SYS_INT CPI. */
+#define VIC_SYS_INT                    8
+#define VIC_CMN_INT                    15
+
+/* This is the boot CPI for alternate processors.  It gets overwritten
+ * by the above once the system has activated all available processors */
+#define VIC_CPU_BOOT_CPI               VIC_CPI_LEVEL0
+#define VIC_CPU_BOOT_ERRATA_CPI                (VIC_CPI_LEVEL0 + 8)
+
+
+#endif /* _ASM_IRQ_VECTORS_H */
index c242527..424acb4 100644 (file)
@@ -111,14 +111,35 @@ static inline unsigned long __raw_local_irq_save(void)
 #define DISABLE_INTERRUPTS(x)  cli
 
 #ifdef CONFIG_X86_64
+#define SWAPGS swapgs
+/*
+ * Currently paravirt can't handle swapgs nicely when we
+ * don't have a stack we can rely on (such as a user space
+ * stack).  So we either find a way around these or just fault
+ * and emulate if a guest tries to call swapgs directly.
+ *
+ * Either way, this is a good way to document that we don't
+ * have a reliable stack. x86_64 only.
+ */
+#define SWAPGS_UNSAFE_STACK    swapgs
+
+#define PARAVIRT_ADJUST_EXCEPTION_FRAME        /*  */
+
 #define INTERRUPT_RETURN       iretq
-#define ENABLE_INTERRUPTS_SYSCALL_RET                  \
-                       movq    %gs:pda_oldrsp, %rsp;   \
-                       swapgs;                         \
-                       sysretq;
+#define USERGS_SYSRET64                                \
+       swapgs;                                 \
+       sysretq;
+#define USERGS_SYSRET32                                \
+       swapgs;                                 \
+       sysretl
+#define ENABLE_INTERRUPTS_SYSEXIT32            \
+       swapgs;                                 \
+       sti;                                    \
+       sysexit
+
 #else
 #define INTERRUPT_RETURN               iret
-#define ENABLE_INTERRUPTS_SYSCALL_RET  sti; sysexit
+#define ENABLE_INTERRUPTS_SYSEXIT      sti; sysexit
 #define GET_CR0_INTO_EAX               movl %cr0, %eax
 #endif
 
@@ -169,18 +190,6 @@ static inline void trace_hardirqs_fixup(void)
 #else
 
 #ifdef CONFIG_X86_64
-/*
- * Currently paravirt can't handle swapgs nicely when we
- * don't have a stack we can rely on (such as a user space
- * stack).  So we either find a way around these or just fault
- * and emulate if a guest tries to call swapgs directly.
- *
- * Either way, this is a good way to document that we don't
- * have a reliable stack. x86_64 only.
- */
-#define SWAPGS_UNSAFE_STACK    swapgs
-#define ARCH_TRACE_IRQS_ON             call trace_hardirqs_on_thunk
-#define ARCH_TRACE_IRQS_OFF            call trace_hardirqs_off_thunk
 #define ARCH_LOCKDEP_SYS_EXIT          call lockdep_sys_exit_thunk
 #define ARCH_LOCKDEP_SYS_EXIT_IRQ      \
        TRACE_IRQS_ON; \
@@ -192,24 +201,6 @@ static inline void trace_hardirqs_fixup(void)
        TRACE_IRQS_OFF;
 
 #else
-#define ARCH_TRACE_IRQS_ON                     \
-       pushl %eax;                             \
-       pushl %ecx;                             \
-       pushl %edx;                             \
-       call trace_hardirqs_on;                 \
-       popl %edx;                              \
-       popl %ecx;                              \
-       popl %eax;
-
-#define ARCH_TRACE_IRQS_OFF                    \
-       pushl %eax;                             \
-       pushl %ecx;                             \
-       pushl %edx;                             \
-       call trace_hardirqs_off;                \
-       popl %edx;                              \
-       popl %ecx;                              \
-       popl %eax;
-
 #define ARCH_LOCKDEP_SYS_EXIT                  \
        pushl %eax;                             \
        pushl %ecx;                             \
@@ -223,8 +214,8 @@ static inline void trace_hardirqs_fixup(void)
 #endif
 
 #ifdef CONFIG_TRACE_IRQFLAGS
-#  define TRACE_IRQS_ON                ARCH_TRACE_IRQS_ON
-#  define TRACE_IRQS_OFF       ARCH_TRACE_IRQS_OFF
+#  define TRACE_IRQS_ON                call trace_hardirqs_on_thunk;
+#  define TRACE_IRQS_OFF       call trace_hardirqs_off_thunk;
 #else
 #  define TRACE_IRQS_ON
 #  define TRACE_IRQS_OFF
index 8327907..017c8c1 100644 (file)
@@ -81,7 +81,7 @@ static inline int multi_timer_check(int apic, int irq)
 
 static inline int apicid_to_node(int logical_apicid)
 {
-       return (0);
+       return apicid_2_node[hard_smp_processor_id()];
 }
 
 static inline int cpu_present_to_apicid(int mps_cpu)
diff --git a/include/asm-x86/mach-bigsmp/mach_mpspec.h b/include/asm-x86/mach-bigsmp/mach_mpspec.h
deleted file mode 100644 (file)
index 6b5dadc..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __ASM_MACH_MPSPEC_H
-#define __ASM_MACH_MPSPEC_H
-
-#define MAX_IRQ_SOURCES 256
-
-#define MAX_MP_BUSSES 32
-
-#endif /* __ASM_MACH_MPSPEC_H */
diff --git a/include/asm-x86/mach-default/irq_vectors.h b/include/asm-x86/mach-default/irq_vectors.h
deleted file mode 100644 (file)
index 881c63c..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * This file should contain #defines for all of the interrupt vector
- * numbers used by this architecture.
- *
- * In addition, there are some standard defines:
- *
- *     FIRST_EXTERNAL_VECTOR:
- *             The first free place for external interrupts
- *
- *     SYSCALL_VECTOR:
- *             The IRQ vector a syscall makes the user to kernel transition
- *             under.
- *
- *     TIMER_IRQ:
- *             The IRQ number the timer interrupt comes in at.
- *
- *     NR_IRQS:
- *             The total number of interrupt vectors (including all the
- *             architecture specific interrupts) needed.
- *
- */                    
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR  0x20
-
-#define SYSCALL_VECTOR         0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/*
- * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
- *
- *  some of the following vectors are 'rare', they are merged
- *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
- *  TLB, reschedule and local APIC vectors are performance-critical.
- *
- *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
- */
-#define SPURIOUS_APIC_VECTOR   0xff
-#define ERROR_APIC_VECTOR      0xfe
-#define INVALIDATE_TLB_VECTOR  0xfd
-#define RESCHEDULE_VECTOR      0xfc
-#define CALL_FUNCTION_VECTOR   0xfb
-
-#define THERMAL_APIC_VECTOR    0xf0
-/*
- * Local APIC timer IRQ vector is on a different priority level,
- * to work around the 'lost local interrupt if more than 2 IRQ
- * sources per level' errata.
- */
-#define LOCAL_TIMER_VECTOR     0xef
-
-/*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
- * we start at 0x31 to spread out vectors evenly between priority
- * levels. (0x80 is the syscall vector)
- */
-#define FIRST_DEVICE_VECTOR    0x31
-#define FIRST_SYSTEM_VECTOR    0xef
-
-#define TIMER_IRQ 0
-
-/*
- * 16 8259A IRQ's, 208 potential APIC interrupt sources.
- * Right now the APIC is mostly only used for SMP.
- * 256 vectors is an architectural limit. (we can have
- * more than 256 devices theoretically, but they will
- * have to use shared interrupts)
- * Since vectors 0x00-0x1f are used/reserved for the CPU,
- * the usable vector space is 0x20-0xff (224 vectors)
- */
-
-/*
- * The maximum number of vectors supported by i386 processors
- * is limited to 256. For processors other than i386, NR_VECTORS
- * should be changed accordingly.
- */
-#define NR_VECTORS 256
-
-#include "irq_vectors_limits.h"
-
-#define FPU_IRQ                        13
-
-#define        FIRST_VM86_IRQ          3
-#define LAST_VM86_IRQ          15
-#define invalid_vm86_irq(irq)  ((irq) < 3 || (irq) > 15)
-
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff --git a/include/asm-x86/mach-default/irq_vectors_limits.h b/include/asm-x86/mach-default/irq_vectors_limits.h
deleted file mode 100644 (file)
index a90c7a6..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef _ASM_IRQ_VECTORS_LIMITS_H
-#define _ASM_IRQ_VECTORS_LIMITS_H
-
-#if defined(CONFIG_X86_IO_APIC) || defined(CONFIG_PARAVIRT)
-#define NR_IRQS 224
-# if (224 >= 32 * NR_CPUS)
-# define NR_IRQ_VECTORS NR_IRQS
-# else
-# define NR_IRQ_VECTORS (32 * NR_CPUS)
-# endif
-#else
-#define NR_IRQS 16
-#define NR_IRQ_VECTORS NR_IRQS
-#endif
-
-#endif /* _ASM_IRQ_VECTORS_LIMITS_H */
index 21003b5..0b2cde5 100644 (file)
@@ -77,7 +77,11 @@ static inline void setup_apic_routing(void)
 
 static inline int apicid_to_node(int logical_apicid)
 {
+#ifdef CONFIG_SMP
+       return apicid_2_node[hard_smp_processor_id()];
+#else
        return 0;
+#endif
 }
 #endif
 
index 605e3cc..3884620 100644 (file)
@@ -1,7 +1,3 @@
 /* Hook to call BIOS initialisation function */
 
 /* no action for generic */
-
-#ifndef ARCH_SETUP
-#define ARCH_SETUP
-#endif
index 56d0e1f..56d001b 100644 (file)
@@ -3,7 +3,9 @@
 
 static inline void smpboot_clear_io_apic_irqs(void)
 {
+#ifdef CONFIG_X86_IO_APIC
        io_apic_irqs = 0;
+#endif
 }
 
 static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
@@ -35,17 +37,23 @@ static inline void smpboot_restore_warm_reset_vector(void)
 
 static inline void __init smpboot_setup_io_apic(void)
 {
+#ifdef CONFIG_X86_IO_APIC
        /*
         * Here we can be sure that there is an IO-APIC in the system. Let's
         * go and set it up:
         */
        if (!skip_ioapic_setup && nr_ioapics)
                setup_IO_APIC();
-       else
+       else {
                nr_ioapics = 0;
+               localise_nmi_watchdog();
+       }
+#endif
 }
 
 static inline void smpboot_clear_io_apic(void)
 {
+#ifdef CONFIG_X86_IO_APIC
        nr_ioapics = 0;
+#endif
 }
diff --git a/include/asm-x86/mach-es7000/mach_mpspec.h b/include/asm-x86/mach-es7000/mach_mpspec.h
deleted file mode 100644 (file)
index b1f5039..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __ASM_MACH_MPSPEC_H
-#define __ASM_MACH_MPSPEC_H
-
-#define MAX_IRQ_SOURCES 256
-
-#define MAX_MP_BUSSES 256
-
-#endif /* __ASM_MACH_MPSPEC_H */
index 0d0b5ba..586cadb 100644 (file)
@@ -1,7 +1,10 @@
 #ifndef _MACH_MPPARSE_H
 #define _MACH_MPPARSE_H 1
 
-int mps_oem_check(struct mp_config_table *mpc, char *oem, char *productid); 
-int acpi_madt_oem_check(char *oem_id, char *oem_table_id); 
+
+extern int mps_oem_check(struct mp_config_table *mpc, char *oem,
+                        char *productid);
+
+extern int acpi_madt_oem_check(char *oem_id, char *oem_table_id);
 
 #endif
index 75a56e5..d802465 100644 (file)
@@ -20,8 +20,14 @@ static inline cpumask_t target_cpus(void)
 #define INT_DELIVERY_MODE dest_LowestPrio
 #define INT_DEST_MODE 0     /* physical delivery on LOCAL quad */
  
-#define check_apicid_used(bitmap, apicid) physid_isset(apicid, bitmap)
-#define check_apicid_present(bit) physid_isset(bit, phys_cpu_present_map)
+static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
+{
+       return physid_isset(apicid, bitmap);
+}
+static inline unsigned long check_apicid_present(int bit)
+{
+       return physid_isset(bit, phys_cpu_present_map);
+}
 #define apicid_cluster(apicid) (apicid & 0xF0)
 
 static inline int apic_id_registered(void)
@@ -77,11 +83,6 @@ static inline int cpu_present_to_apicid(int mps_cpu)
                return BAD_APICID;
 }
 
-static inline int generate_logical_apicid(int quad, int phys_apicid)
-{
-       return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
-}
-
 static inline int apicid_to_node(int logical_apicid) 
 {
        return logical_apicid >> 4;
@@ -95,30 +96,6 @@ static inline physid_mask_t apicid_to_cpu_present(int logical_apicid)
        return physid_mask_of_physid(cpu + 4*node);
 }
 
-struct mpc_config_translation {
-       unsigned char mpc_type;
-       unsigned char trans_len;
-       unsigned char trans_type;
-       unsigned char trans_quad;
-       unsigned char trans_global;
-       unsigned char trans_local;
-       unsigned short trans_reserved;
-};
-
-static inline int mpc_apic_id(struct mpc_config_processor *m, 
-                       struct mpc_config_translation *translation_record)
-{
-       int quad = translation_record->trans_quad;
-       int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
-
-       printk("Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
-              m->mpc_apicid,
-              (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
-              (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
-              m->mpc_apicver, quad, logical_apicid);
-       return logical_apicid;
-}
-
 extern void *xquad_portio;
 
 static inline void setup_portio_remap(void)
index 459b124..626aef6 100644 (file)
@@ -1,14 +1,7 @@
 #ifndef __ASM_MACH_MPPARSE_H
 #define __ASM_MACH_MPPARSE_H
 
-extern void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
-                            struct mpc_config_translation *translation);
-extern void mpc_oem_pci_bus(struct mpc_config_bus *m,
-       struct mpc_config_translation *translation);
-
-/* Hook from generic ACPI tables.c */
-static inline void acpi_madt_oem_check(char *oem_id, char *oem_table_id)
-{
-}
+extern void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
+                               char *productid);
 
 #endif /* __ASM_MACH_MPPARSE_H */
diff --git a/include/asm-x86/mach-numaq/mach_mpspec.h b/include/asm-x86/mach-numaq/mach_mpspec.h
deleted file mode 100644 (file)
index dffb098..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __ASM_MACH_MPSPEC_H
-#define __ASM_MACH_MPSPEC_H
-
-#define MAX_IRQ_SOURCES 512
-
-#define MAX_MP_BUSSES 32
-
-#endif /* __ASM_MACH_MPSPEC_H */
diff --git a/include/asm-x86/mach-summit/mach_mpspec.h b/include/asm-x86/mach-summit/mach_mpspec.h
deleted file mode 100644 (file)
index bd76552..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef __ASM_MACH_MPSPEC_H
-#define __ASM_MACH_MPSPEC_H
-
-#define MAX_IRQ_SOURCES 256
-
-/* Maximum 256 PCI busses, plus 1 ISA bus in each of 4 cabinets. */
-#define MAX_MP_BUSSES 260
-
-#endif /* __ASM_MACH_MPSPEC_H */
diff --git a/include/asm-x86/mach-visws/cobalt.h b/include/asm-x86/mach-visws/cobalt.h
deleted file mode 100644 (file)
index 9952588..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#ifndef __I386_SGI_COBALT_H
-#define __I386_SGI_COBALT_H
-
-#include <asm/fixmap.h>
-
-/*
- * Cobalt SGI Visual Workstation system ASIC
- */ 
-
-#define CO_CPU_NUM_PHYS 0x1e00
-#define CO_CPU_TAB_PHYS (CO_CPU_NUM_PHYS + 2)
-
-#define CO_CPU_MAX 4
-
-#define        CO_CPU_PHYS             0xc2000000
-#define        CO_APIC_PHYS            0xc4000000
-
-/* see set_fixmap() and asm/fixmap.h */
-#define        CO_CPU_VADDR            (fix_to_virt(FIX_CO_CPU))
-#define        CO_APIC_VADDR           (fix_to_virt(FIX_CO_APIC))
-
-/* Cobalt CPU registers -- relative to CO_CPU_VADDR, use co_cpu_*() */
-#define        CO_CPU_REV              0x08
-#define        CO_CPU_CTRL             0x10
-#define        CO_CPU_STAT             0x20
-#define        CO_CPU_TIMEVAL          0x30
-
-/* CO_CPU_CTRL bits */
-#define        CO_CTRL_TIMERUN         0x04            /* 0 == disabled */
-#define        CO_CTRL_TIMEMASK        0x08            /* 0 == unmasked */
-
-/* CO_CPU_STATUS bits */
-#define        CO_STAT_TIMEINTR        0x02    /* (r) 1 == int pend, (w) 0 == clear */
-
-/* CO_CPU_TIMEVAL value */
-#define        CO_TIME_HZ              100000000       /* Cobalt core rate */
-
-/* Cobalt APIC registers -- relative to CO_APIC_VADDR, use co_apic_*() */
-#define        CO_APIC_HI(n)           (((n) * 0x10) + 4)
-#define        CO_APIC_LO(n)           ((n) * 0x10)
-#define        CO_APIC_ID              0x0ffc
-
-/* CO_APIC_ID bits */
-#define        CO_APIC_ENABLE          0x00000100
-
-/* CO_APIC_LO bits */
-#define        CO_APIC_MASK            0x00010000      /* 0 = enabled */
-#define        CO_APIC_LEVEL           0x00008000      /* 0 = edge */
-
-/*
- * Where things are physically wired to Cobalt
- * #defines with no board _<type>_<rev>_ are common to all (thus far)
- */
-#define        CO_APIC_IDE0            4
-#define CO_APIC_IDE1           2               /* Only on 320 */
-
-#define        CO_APIC_8259            12              /* serial, floppy, par-l-l */
-
-/* Lithium PCI Bridge A -- "the one with 82557 Ethernet" */
-#define        CO_APIC_PCIA_BASE0      0 /* and 1 */   /* slot 0, line 0 */
-#define        CO_APIC_PCIA_BASE123    5 /* and 6 */   /* slot 0, line 1 */
-
-#define        CO_APIC_PIIX4_USB       7               /* this one is weird */
-
-/* Lithium PCI Bridge B -- "the one with PIIX4" */
-#define        CO_APIC_PCIB_BASE0      8 /* and 9-12 *//* slot 0, line 0 */
-#define        CO_APIC_PCIB_BASE123    13 /* 14.15 */  /* slot 0, line 1 */
-
-#define        CO_APIC_VIDOUT0         16
-#define        CO_APIC_VIDOUT1         17
-#define        CO_APIC_VIDIN0          18
-#define        CO_APIC_VIDIN1          19
-
-#define        CO_APIC_LI_AUDIO        22
-
-#define        CO_APIC_AS              24
-#define        CO_APIC_RE              25
-
-#define CO_APIC_CPU            28              /* Timer and Cache interrupt */
-#define        CO_APIC_NMI             29
-#define        CO_APIC_LAST            CO_APIC_NMI
-
-/*
- * This is how irqs are assigned on the Visual Workstation.
- * Legacy devices get irq's 1-15 (system clock is 0 and is CO_APIC_CPU).
- * All other devices (including PCI) go to Cobalt and are irq's 16 on up.
- */
-#define        CO_IRQ_APIC0    16                      /* irq of apic entry 0 */
-#define        IS_CO_APIC(irq) ((irq) >= CO_IRQ_APIC0)
-#define        CO_IRQ(apic)    (CO_IRQ_APIC0 + (apic)) /* apic ent to irq */
-#define        CO_APIC(irq)    ((irq) - CO_IRQ_APIC0)  /* irq to apic ent */
-#define CO_IRQ_IDE0    14                      /* knowledge of... */
-#define CO_IRQ_IDE1    15                      /* ... ide driver defaults! */
-#define        CO_IRQ_8259     CO_IRQ(CO_APIC_8259)
-
-#ifdef CONFIG_X86_VISWS_APIC
-static inline void co_cpu_write(unsigned long reg, unsigned long v)
-{
-       *((volatile unsigned long *)(CO_CPU_VADDR+reg))=v;
-}
-
-static inline unsigned long co_cpu_read(unsigned long reg)
-{
-       return *((volatile unsigned long *)(CO_CPU_VADDR+reg));
-}            
-             
-static inline void co_apic_write(unsigned long reg, unsigned long v)
-{
-       *((volatile unsigned long *)(CO_APIC_VADDR+reg))=v;
-}            
-             
-static inline unsigned long co_apic_read(unsigned long reg)
-{
-       return *((volatile unsigned long *)(CO_APIC_VADDR+reg));
-}
-#endif
-
-extern char visws_board_type;
-
-#define        VISWS_320       0
-#define        VISWS_540       1
-
-extern char visws_board_rev;
-
-#endif /* __I386_SGI_COBALT_H */
diff --git a/include/asm-x86/mach-visws/irq_vectors.h b/include/asm-x86/mach-visws/irq_vectors.h
deleted file mode 100644 (file)
index cb572d8..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR  0x20
-
-#define SYSCALL_VECTOR         0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/*
- * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
- *
- *  some of the following vectors are 'rare', they are merged
- *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
- *  TLB, reschedule and local APIC vectors are performance-critical.
- *
- *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
- */
-#define SPURIOUS_APIC_VECTOR   0xff
-#define ERROR_APIC_VECTOR      0xfe
-#define INVALIDATE_TLB_VECTOR  0xfd
-#define RESCHEDULE_VECTOR      0xfc
-#define CALL_FUNCTION_VECTOR   0xfb
-
-#define THERMAL_APIC_VECTOR    0xf0
-/*
- * Local APIC timer IRQ vector is on a different priority level,
- * to work around the 'lost local interrupt if more than 2 IRQ
- * sources per level' errata.
- */
-#define LOCAL_TIMER_VECTOR     0xef
-
-/*
- * First APIC vector available to drivers: (vectors 0x30-0xee)
- * we start at 0x31 to spread out vectors evenly between priority
- * levels. (0x80 is the syscall vector)
- */
-#define FIRST_DEVICE_VECTOR    0x31
-#define FIRST_SYSTEM_VECTOR    0xef
-
-#define TIMER_IRQ 0
-
-/*
- * IRQ definitions
- */
-#define NR_VECTORS 256
-#define NR_IRQS 224
-#define NR_IRQ_VECTORS NR_IRQS
-
-#define FPU_IRQ                        13
-
-#define        FIRST_VM86_IRQ          3
-#define LAST_VM86_IRQ          15
-#define invalid_vm86_irq(irq)  ((irq) < 3 || (irq) > 15)
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff --git a/include/asm-x86/mach-visws/lithium.h b/include/asm-x86/mach-visws/lithium.h
deleted file mode 100644 (file)
index dfcd4f0..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef __I386_SGI_LITHIUM_H
-#define __I386_SGI_LITHIUM_H
-
-#include <asm/fixmap.h>
-
-/*
- * Lithium is the SGI Visual Workstation I/O ASIC
- */
-
-#define        LI_PCI_A_PHYS           0xfc000000      /* Enet is dev 3 */
-#define        LI_PCI_B_PHYS           0xfd000000      /* PIIX4 is here */
-
-/* see set_fixmap() and asm/fixmap.h */
-#define LI_PCIA_VADDR   (fix_to_virt(FIX_LI_PCIA))
-#define LI_PCIB_VADDR   (fix_to_virt(FIX_LI_PCIB))
-
-/* Not a standard PCI? (not in linux/pci.h) */
-#define        LI_PCI_BUSNUM   0x44                    /* lo8: primary, hi8: sub */
-#define LI_PCI_INTEN    0x46
-
-/* LI_PCI_INTENT bits */
-#define        LI_INTA_0       0x0001
-#define        LI_INTA_1       0x0002
-#define        LI_INTA_2       0x0004
-#define        LI_INTA_3       0x0008
-#define        LI_INTA_4       0x0010
-#define        LI_INTB         0x0020
-#define        LI_INTC         0x0040
-#define        LI_INTD         0x0080
-
-/* More special purpose macros... */
-static inline void li_pcia_write16(unsigned long reg, unsigned short v)
-{
-       *((volatile unsigned short *)(LI_PCIA_VADDR+reg))=v;
-}
-
-static inline unsigned short li_pcia_read16(unsigned long reg)
-{
-        return *((volatile unsigned short *)(LI_PCIA_VADDR+reg));
-}
-
-static inline void li_pcib_write16(unsigned long reg, unsigned short v)
-{
-       *((volatile unsigned short *)(LI_PCIB_VADDR+reg))=v;
-}
-
-static inline unsigned short li_pcib_read16(unsigned long reg)
-{
-       return *((volatile unsigned short *)(LI_PCIB_VADDR+reg));
-}
-
-#endif
-
index a9ef33a..6943e7a 100644 (file)
@@ -1,103 +1 @@
-#ifndef __ASM_MACH_APIC_H
-#define __ASM_MACH_APIC_H
-
-#include <mach_apicdef.h>
-#include <asm/smp.h>
-
-#define APIC_DFR_VALUE (APIC_DFR_FLAT)
-
-#define no_balance_irq (0)
-#define esr_disable (0)
-
-#define INT_DELIVERY_MODE dest_LowestPrio
-#define INT_DEST_MODE 1     /* logical delivery broadcast to all procs */
-
-#ifdef CONFIG_SMP
- #define TARGET_CPUS cpu_online_map
-#else
- #define TARGET_CPUS cpumask_of_cpu(0)
-#endif
-
-#define check_apicid_used(bitmap, apicid)      physid_isset(apicid, bitmap)
-#define check_apicid_present(bit)              physid_isset(bit, phys_cpu_present_map)
-
-static inline int apic_id_registered(void)
-{
-       return physid_isset(GET_APIC_ID(read_apic_id()), phys_cpu_present_map);
-}
-
-/*
- * Set up the logical destination ID.
- *
- * Intel recommends to set DFR, LDR and TPR before enabling
- * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
- * document number 292116).  So here it goes...
- */
-static inline void init_apic_ldr(void)
-{
-       unsigned long val;
-
-       apic_write_around(APIC_DFR, APIC_DFR_VALUE);
-       val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
-       val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
-       apic_write_around(APIC_LDR, val);
-}
-
-static inline void summit_check(char *oem, char *productid) 
-{
-}
-
-static inline void setup_apic_routing(void)
-{
-}
-
-static inline int apicid_to_node(int logical_apicid)
-{
-       return 0;
-}
-
-/* Mapping from cpu number to logical apicid */
-static inline int cpu_to_logical_apicid(int cpu)
-{
-       return 1 << cpu;
-}
-
-static inline int cpu_present_to_apicid(int mps_cpu)
-{
-       if (mps_cpu < get_physical_broadcast())
-               return mps_cpu;
-       else
-               return BAD_APICID;
-}
-
-static inline physid_mask_t apicid_to_cpu_present(int apicid)
-{
-       return physid_mask_of_physid(apicid);
-}
-
-#define WAKE_SECONDARY_VIA_INIT
-
-static inline void setup_portio_remap(void)
-{
-}
-
-static inline void enable_apic_mode(void)
-{
-}
-
-static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)
-{
-       return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
-}
-
-static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
-{
-       return cpus_addr(cpumask)[0];
-}
-
-static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
-{
-       return cpuid_apic >> index_msb;
-}
-
-#endif /* __ASM_MACH_APIC_H */
+#include "../mach-default/mach_apic.h"
index 826cfa9..42711d1 100644 (file)
@@ -1,12 +1 @@
-#ifndef __ASM_MACH_APICDEF_H
-#define __ASM_MACH_APICDEF_H
-
-#define         APIC_ID_MASK            (0xF<<24)
-
-static inline unsigned get_apic_id(unsigned long x)
-{
-               return (((x)>>24)&0xF);
-}
-#define         GET_APIC_ID(x)  get_apic_id(x)
-
-#endif
+#include "../mach-default/mach_apicdef.h"
diff --git a/include/asm-x86/mach-visws/piix4.h b/include/asm-x86/mach-visws/piix4.h
deleted file mode 100644 (file)
index 83ea4f4..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#ifndef __I386_SGI_PIIX_H
-#define __I386_SGI_PIIX_H
-
-/*
- * PIIX4 as used on SGI Visual Workstations
- */
-
-#define        PIIX_PM_START           0x0F80
-
-#define        SIO_GPIO_START          0x0FC0
-
-#define        SIO_PM_START            0x0FC8
-
-#define        PMBASE                  PIIX_PM_START
-#define        GPIREG0                 (PMBASE+0x30)
-#define        GPIREG(x)               (GPIREG0+((x)/8))
-#define        GPIBIT(x)               (1 << ((x)%8))
-
-#define        PIIX_GPI_BD_ID1         18
-#define        PIIX_GPI_BD_ID2         19
-#define        PIIX_GPI_BD_ID3         20
-#define        PIIX_GPI_BD_ID4         21
-#define        PIIX_GPI_BD_REG         GPIREG(PIIX_GPI_BD_ID1)
-#define        PIIX_GPI_BD_MASK        (GPIBIT(PIIX_GPI_BD_ID1) | \
-                               GPIBIT(PIIX_GPI_BD_ID2) | \
-                               GPIBIT(PIIX_GPI_BD_ID3) | \
-                               GPIBIT(PIIX_GPI_BD_ID4) )
-
-#define        PIIX_GPI_BD_SHIFT       (PIIX_GPI_BD_ID1 % 8)
-
-#define        SIO_INDEX               0x2e
-#define        SIO_DATA                0x2f
-
-#define        SIO_DEV_SEL             0x7
-#define        SIO_DEV_ENB             0x30
-#define        SIO_DEV_MSB             0x60
-#define        SIO_DEV_LSB             0x61
-
-#define        SIO_GP_DEV              0x7
-
-#define        SIO_GP_BASE             SIO_GPIO_START
-#define        SIO_GP_MSB              (SIO_GP_BASE>>8)
-#define        SIO_GP_LSB              (SIO_GP_BASE&0xff)
-
-#define        SIO_GP_DATA1            (SIO_GP_BASE+0)
-
-#define        SIO_PM_DEV              0x8
-
-#define        SIO_PM_BASE             SIO_PM_START
-#define        SIO_PM_MSB              (SIO_PM_BASE>>8)
-#define        SIO_PM_LSB              (SIO_PM_BASE&0xff)
-#define        SIO_PM_INDEX            (SIO_PM_BASE+0)
-#define        SIO_PM_DATA             (SIO_PM_BASE+1)
-
-#define        SIO_PM_FER2             0x1
-
-#define        SIO_PM_GP_EN            0x80
-
-
-
-/*
- * This is the dev/reg where generating a config cycle will
- * result in a PCI special cycle.
- */
-#define SPECIAL_DEV            0xff
-#define SPECIAL_REG            0x00
-
-/*
- * PIIX4 needs to see a special cycle with the following data
- * to be convinced the processor has gone into the stop grant
- * state.  PIIX4 insists on seeing this before it will power
- * down a system.
- */
-#define PIIX_SPECIAL_STOP              0x00120002
-
-#define PIIX4_RESET_PORT       0xcf9
-#define PIIX4_RESET_VAL                0x6
-
-#define PMSTS_PORT             0xf80   // 2 bytes      PM Status
-#define PMEN_PORT              0xf82   // 2 bytes      PM Enable
-#define        PMCNTRL_PORT            0xf84   // 2 bytes      PM Control
-
-#define PM_SUSPEND_ENABLE      0x2000  // start sequence to suspend state
-
-/*
- * PMSTS and PMEN I/O bit definitions.
- * (Bits are the same in both registers)
- */
-#define PM_STS_RSM             (1<<15) // Resume Status
-#define PM_STS_PWRBTNOR                (1<<11) // Power Button Override
-#define PM_STS_RTC             (1<<10) // RTC status
-#define PM_STS_PWRBTN          (1<<8)  // Power Button Pressed?
-#define PM_STS_GBL             (1<<5)  // Global Status
-#define PM_STS_BM              (1<<4)  // Bus Master Status
-#define PM_STS_TMROF           (1<<0)  // Timer Overflow Status.
-
-/*
- * Stop clock GPI register
- */
-#define PIIX_GPIREG0                   (0xf80 + 0x30)
-
-/*
- * Stop clock GPI bit in GPIREG0
- */
-#define        PIIX_GPI_STPCLK         0x4     // STPCLK signal routed back in
-
-#endif
index 33f700e..fa4766c 100644 (file)
@@ -1,8 +1 @@
-/* Hook to call BIOS initialisation function */
-
-extern unsigned long sgivwfb_mem_phys;
-extern unsigned long sgivwfb_mem_size;
-
-/* no action for visws */
-
-#define ARCH_SETUP
+#include "../mach-default/setup_arch.h"
index c9b83e3..e4433ca 100644 (file)
@@ -1,28 +1 @@
-static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
-{
-       CMOS_WRITE(0xa, 0xf);
-       local_flush_tlb();
-       Dprintk("1.\n");
-       *((volatile unsigned short *) TRAMPOLINE_HIGH) = start_eip >> 4;
-       Dprintk("2.\n");
-       *((volatile unsigned short *) TRAMPOLINE_LOW) = start_eip & 0xf;
-       Dprintk("3.\n");
-}
-
-/* for visws do nothing for any of these */
-
-static inline void smpboot_clear_io_apic_irqs(void)
-{
-}
-
-static inline void smpboot_restore_warm_reset_vector(void)
-{
-}
-
-static inline void smpboot_setup_io_apic(void)
-{
-}
-
-static inline void smpboot_clear_io_apic(void)
-{
-}
+#include "../mach-default/smpboot_hooks.h"
diff --git a/include/asm-x86/mach-voyager/irq_vectors.h b/include/asm-x86/mach-voyager/irq_vectors.h
deleted file mode 100644 (file)
index 165421f..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8 -*- */
-
-/* Copyright (C) 2002
- *
- * Author: James.Bottomley@HansenPartnership.com
- *
- * linux/arch/i386/voyager/irq_vectors.h
- *
- * This file provides definitions for the VIC and QIC CPIs
- */
-
-#ifndef _ASM_IRQ_VECTORS_H
-#define _ASM_IRQ_VECTORS_H
-
-/*
- * IDT vectors usable for external interrupt sources start
- * at 0x20:
- */
-#define FIRST_EXTERNAL_VECTOR  0x20
-
-#define SYSCALL_VECTOR         0x80
-
-/*
- * Vectors 0x20-0x2f are used for ISA interrupts.
- */
-
-/* These define the CPIs we use in linux */
-#define VIC_CPI_LEVEL0                 0
-#define VIC_CPI_LEVEL1                 1
-/* now the fake CPIs */
-#define VIC_TIMER_CPI                  2
-#define VIC_INVALIDATE_CPI             3
-#define VIC_RESCHEDULE_CPI             4
-#define VIC_ENABLE_IRQ_CPI             5
-#define VIC_CALL_FUNCTION_CPI          6
-
-/* Now the QIC CPIs:  Since we don't need the two initial levels,
- * these are 2 less than the VIC CPIs */
-#define QIC_CPI_OFFSET                 1
-#define QIC_TIMER_CPI                  (VIC_TIMER_CPI - QIC_CPI_OFFSET)
-#define QIC_INVALIDATE_CPI             (VIC_INVALIDATE_CPI - QIC_CPI_OFFSET)
-#define QIC_RESCHEDULE_CPI             (VIC_RESCHEDULE_CPI - QIC_CPI_OFFSET)
-#define QIC_ENABLE_IRQ_CPI             (VIC_ENABLE_IRQ_CPI - QIC_CPI_OFFSET)
-#define QIC_CALL_FUNCTION_CPI          (VIC_CALL_FUNCTION_CPI - QIC_CPI_OFFSET)
-
-#define VIC_START_FAKE_CPI             VIC_TIMER_CPI
-#define VIC_END_FAKE_CPI               VIC_CALL_FUNCTION_CPI
-
-/* this is the SYS_INT CPI. */
-#define VIC_SYS_INT                    8
-#define VIC_CMN_INT                    15
-
-/* This is the boot CPI for alternate processors.  It gets overwritten
- * by the above once the system has activated all available processors */
-#define VIC_CPU_BOOT_CPI               VIC_CPI_LEVEL0
-#define VIC_CPU_BOOT_ERRATA_CPI                (VIC_CPI_LEVEL0 + 8)
-
-#define NR_VECTORS 256
-#define NR_IRQS 224
-#define NR_IRQ_VECTORS NR_IRQS
-
-#define FPU_IRQ                                13
-
-#define        FIRST_VM86_IRQ          3
-#define LAST_VM86_IRQ          15
-#define invalid_vm86_irq(irq)  ((irq) < 3 || (irq) > 15)
-
-#ifndef __ASSEMBLY__
-extern asmlinkage void vic_cpi_interrupt(void);
-extern asmlinkage void vic_sys_interrupt(void);
-extern asmlinkage void vic_cmn_interrupt(void);
-extern asmlinkage void qic_timer_interrupt(void);
-extern asmlinkage void qic_invalidate_interrupt(void);
-extern asmlinkage void qic_reschedule_interrupt(void);
-extern asmlinkage void qic_enable_irq_interrupt(void);
-extern asmlinkage void qic_call_function_interrupt(void);
-#endif /* !__ASSEMBLY__ */
-
-#endif /* _ASM_IRQ_VECTORS_H */
diff --git a/include/asm-x86/mmconfig.h b/include/asm-x86/mmconfig.h
new file mode 100644 (file)
index 0000000..95beda0
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _ASM_MMCONFIG_H
+#define _ASM_MMCONFIG_H
+
+#ifdef CONFIG_PCI_MMCONFIG
+extern void __cpuinit fam10h_check_enable_mmcfg(void);
+extern void __init check_enable_amd_mmconf_dmi(void);
+#else
+static inline void fam10h_check_enable_mmcfg(void) { }
+static inline void check_enable_amd_mmconf_dmi(void) { }
+#endif
+
+#endif
index 6598450..fac5701 100644 (file)
@@ -1,5 +1,37 @@
+#ifndef __ASM_X86_MMU_CONTEXT_H
+#define __ASM_X86_MMU_CONTEXT_H
+
+#include <asm/desc.h>
+#include <asm/atomic.h>
+#include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+#include <asm/paravirt.h>
+#ifndef CONFIG_PARAVIRT
+#include <asm-generic/mm_hooks.h>
+
+static inline void paravirt_activate_mm(struct mm_struct *prev,
+                                       struct mm_struct *next)
+{
+}
+#endif /* !CONFIG_PARAVIRT */
+
+/*
+ * Used for LDT copy/destruction.
+ */
+int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
+void destroy_context(struct mm_struct *mm);
+
 #ifdef CONFIG_X86_32
 # include "mmu_context_32.h"
 #else
 # include "mmu_context_64.h"
 #endif
+
+#define activate_mm(prev, next)                        \
+do {                                           \
+       paravirt_activate_mm((prev), (next));   \
+       switch_mm((prev), (next), NULL);        \
+} while (0);
+
+
+#endif /* __ASM_X86_MMU_CONTEXT_H */
index 9756ae0..824fc57 100644 (file)
@@ -1,28 +1,6 @@
 #ifndef __I386_SCHED_H
 #define __I386_SCHED_H
 
-#include <asm/desc.h>
-#include <asm/atomic.h>
-#include <asm/pgalloc.h>
-#include <asm/tlbflush.h>
-#include <asm/paravirt.h>
-#ifndef CONFIG_PARAVIRT
-#include <asm-generic/mm_hooks.h>
-
-static inline void paravirt_activate_mm(struct mm_struct *prev,
-                                       struct mm_struct *next)
-{
-}
-#endif /* !CONFIG_PARAVIRT */
-
-
-/*
- * Used for LDT copy/destruction.
- */
-int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
-void destroy_context(struct mm_struct *mm);
-
-
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
 #ifdef CONFIG_SMP
@@ -75,10 +53,4 @@ static inline void switch_mm(struct mm_struct *prev,
 #define deactivate_mm(tsk, mm)                 \
        asm("movl %0,%%gs": :"r" (0));
 
-#define activate_mm(prev, next)                        \
-do {                                           \
-       paravirt_activate_mm((prev), (next));   \
-       switch_mm((prev), (next), NULL);        \
-} while (0);
-
 #endif
index ca44c71..c700063 100644 (file)
@@ -1,21 +1,7 @@
 #ifndef __X86_64_MMU_CONTEXT_H
 #define __X86_64_MMU_CONTEXT_H
 
-#include <asm/desc.h>
-#include <asm/atomic.h>
-#include <asm/pgalloc.h>
 #include <asm/pda.h>
-#include <asm/pgtable.h>
-#include <asm/tlbflush.h>
-#ifndef CONFIG_PARAVIRT
-#include <asm-generic/mm_hooks.h>
-#endif
-
-/*
- * possibly do the LDT unload here?
- */
-int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
-void destroy_context(struct mm_struct *mm);
 
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
@@ -65,8 +51,4 @@ do {                                          \
        asm volatile("movl %0,%%fs"::"r"(0));   \
 } while (0)
 
-#define activate_mm(prev, next)                        \
-       switch_mm((prev), (next), NULL)
-
-
 #endif
index cb2cad0..b2298a2 100644 (file)
 extern struct pglist_data *node_data[];
 #define NODE_DATA(nid) (node_data[nid])
 
-#ifdef CONFIG_X86_NUMAQ
-       #include <asm/numaq.h>
-#elif defined(CONFIG_ACPI_SRAT)/* summit or generic arch */
-       #include <asm/srat.h>
-#endif
+#include <asm/numaq.h>
+/* summit or generic arch */
+#include <asm/srat.h>
 
 extern int get_memcfg_numa_flat(void);
 /*
@@ -26,28 +24,20 @@ extern int get_memcfg_numa_flat(void);
  */
 static inline void get_memcfg_numa(void)
 {
-#ifdef CONFIG_X86_NUMAQ
+
        if (get_memcfg_numaq())
                return;
-#elif defined(CONFIG_ACPI_SRAT)
        if (get_memcfg_from_srat())
                return;
-#endif
-
        get_memcfg_numa_flat();
 }
 
 extern int early_pfn_to_nid(unsigned long pfn);
-extern void numa_kva_reserve(void);
 
 #else /* !CONFIG_NUMA */
 
 #define get_memcfg_numa get_memcfg_numa_flat
-#define get_zholes_size(n) (0)
 
-static inline void numa_kva_reserve(void)
-{
-}
 #endif /* CONFIG_NUMA */
 
 #ifdef CONFIG_DISCONTIGMEM
@@ -55,14 +45,14 @@ static inline void numa_kva_reserve(void)
 /*
  * generic node memory support, the following assumptions apply:
  *
- * 1) memory comes in 256Mb contigious chunks which are either present or not
+ * 1) memory comes in 64Mb contigious chunks which are either present or not
  * 2) we will not have more than 64Gb in total
  *
  * for now assume that 64Gb is max amount of RAM for whole system
  *    64Gb / 4096bytes/page = 16777216 pages
  */
 #define MAX_NR_PAGES 16777216
-#define MAX_ELEMENTS 256
+#define MAX_ELEMENTS 1024
 #define PAGES_PER_ELEMENT (MAX_NR_PAGES/MAX_ELEMENTS)
 
 extern s8 physnode_map[];
@@ -87,9 +77,6 @@ static inline int pfn_to_nid(unsigned long pfn)
        __pgdat->node_start_pfn + __pgdat->node_spanned_pages;          \
 })
 
-#ifdef CONFIG_X86_NUMAQ            /* we have contiguous memory on NUMA-Q */
-#define pfn_valid(pfn)          ((pfn) < num_physpages)
-#else
 static inline int pfn_valid(int pfn)
 {
        int nid = pfn_to_nid(pfn);
@@ -98,7 +85,6 @@ static inline int pfn_valid(int pfn)
                return (pfn < node_end_pfn(nid));
        return 0;
 }
-#endif /* CONFIG_X86_NUMAQ */
 
 #endif /* CONFIG_DISCONTIGMEM */
 
index 57a991b..b6995e5 100644 (file)
@@ -13,6 +13,12 @@ extern int apic_version[MAX_APICS];
 extern u8 apicid_2_node[];
 extern int pic_mode;
 
+#ifdef CONFIG_X86_NUMAQ
+extern int mp_bus_id_to_node[MAX_MP_BUSSES];
+extern int mp_bus_id_to_local[MAX_MP_BUSSES];
+extern int quad_local_to_mp_bus_id [NR_CPUS/4][4];
+#endif
+
 #define MAX_APICID 256
 
 #else
@@ -21,26 +27,30 @@ extern int pic_mode;
 /* Each PCI slot may be a combo card with its own bus.  4 IRQ pins per slot. */
 #define MAX_IRQ_SOURCES (MAX_MP_BUSSES * 4)
 
+#endif
+
 extern void early_find_smp_config(void);
 extern void early_get_smp_config(void);
 
-#endif
-
 #if defined(CONFIG_MCA) || defined(CONFIG_EISA)
 extern int mp_bus_id_to_type[MAX_MP_BUSSES];
 #endif
 
 extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
 
-extern int mp_bus_id_to_pci_bus[MAX_MP_BUSSES];
-
 extern unsigned int boot_cpu_physical_apicid;
+extern unsigned int max_physical_apicid;
 extern int smp_found_config;
 extern int mpc_default_type;
 extern unsigned long mp_lapic_addr;
 
 extern void find_smp_config(void);
 extern void get_smp_config(void);
+#ifdef CONFIG_X86_MPPARSE
+extern void early_reserve_e820_mpc_new(void);
+#else
+static inline void early_reserve_e820_mpc_new(void) { }
+#endif
 
 void __cpuinit generic_processor_info(int apicid, int version);
 #ifdef CONFIG_ACPI
@@ -49,6 +59,17 @@ extern void mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger,
                                   u32 gsi);
 extern void mp_config_acpi_legacy_irqs(void);
 extern int mp_register_gsi(u32 gsi, int edge_level, int active_high_low);
+#ifdef CONFIG_X86_IO_APIC
+extern int mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
+                               u32 gsi, int triggering, int polarity);
+#else
+static inline int
+mp_config_acpi_gsi(unsigned char number, unsigned int devfn, u8 pin,
+                  u32 gsi, int triggering, int polarity)
+{
+       return 0;
+}
+#endif
 #endif /* CONFIG_ACPI */
 
 #define PHYSID_ARRAY_SIZE      BITS_TO_LONGS(MAX_APICS)
@@ -101,6 +122,7 @@ typedef struct physid_mask physid_mask_t;
                __physid_mask;                                          \
        })
 
+/* Note: will create very large stack frames if physid_mask_t is big */
 #define physid_mask_of_physid(physid)                                  \
        ({                                                              \
                physid_mask_t __physid_mask = PHYSID_MASK_NONE;         \
@@ -108,6 +130,12 @@ typedef struct physid_mask physid_mask_t;
                __physid_mask;                                          \
        })
 
+static inline void physid_set_mask_of_physid(int physid, physid_mask_t *map)
+{
+       physids_clear(*map);
+       physid_set(physid, *map);
+}
+
 #define PHYSID_MASK_ALL                { {[0 ... PHYSID_ARRAY_SIZE-1] = ~0UL} }
 #define PHYSID_MASK_NONE       { {[0 ... PHYSID_ARRAY_SIZE-1] = 0UL} }
 
index dc6ef85..38d1e73 100644 (file)
 # define MAX_MPC_ENTRY 1024
 # define MAX_APICS      256
 #else
-/*
- * A maximum of 255 APICs with the current APIC ID architecture.
- */
-# define MAX_APICS 255
+# if NR_CPUS <= 255
+#  define MAX_APICS     255
+# else
+#  define MAX_APICS   32768
+# endif
 #endif
 
 struct intel_mp_floating {
index 09413ad..44bce77 100644 (file)
 #define MSR_K8_TOP_MEM2                        0xc001001d
 #define MSR_K8_SYSCFG                  0xc0010010
 #define MSR_K8_HWCR                    0xc0010015
-#define MSR_K8_ENABLE_C1E              0xc0010055
+#define MSR_K8_INT_PENDING_MSG         0xc0010055
+/* C1E active bits in int pending message */
+#define K8_INTP_C1E_ACTIVE_MASK                0x18000000
 #define MSR_K8_TSEG_ADDR               0xc0010112
 #define K8_MTRRFIXRANGE_DRAM_ENABLE    0x00040000 /* MtrrFixDramEn bit    */
 #define K8_MTRRFIXRANGE_DRAM_MODIFY    0x00080000 /* MtrrFixDramModEn bit */
index 2b5f2c9..ca110ee 100644 (file)
@@ -66,7 +66,7 @@ static inline unsigned long long native_read_msr_safe(unsigned int msr,
 static inline void native_write_msr(unsigned int msr,
                                    unsigned low, unsigned high)
 {
-       asm volatile("wrmsr" : : "c" (msr), "a"(low), "d" (high));
+       asm volatile("wrmsr" : : "c" (msr), "a"(low), "d" (high) : "memory");
 }
 
 static inline int native_write_msr_safe(unsigned int msr,
@@ -81,7 +81,8 @@ static inline int native_write_msr_safe(unsigned int msr,
                     _ASM_EXTABLE(2b, 3b)
                     : "=a" (err)
                     : "c" (msr), "0" (low), "d" (high),
-                    "i" (-EFAULT));
+                      "i" (-EFAULT)
+                    : "memory");
        return err;
 }
 
index 1e36302..21f8d02 100644 (file)
  */
 int do_nmi_callback(struct pt_regs *regs, int cpu);
 
-#ifdef CONFIG_PM
-
-/** Replace the PM callback routine for NMI. */
-struct pm_dev *set_nmi_pm_callback(pm_callback callback);
-
-/** Unset the PM callback routine back to the default. */
-void unset_nmi_pm_callback(struct pm_dev *dev);
-
-#else
-
-static inline struct pm_dev *set_nmi_pm_callback(pm_callback callback)
-{
-       return 0;
-}
-
-static inline void unset_nmi_pm_callback(struct pm_dev *dev)
-{
-}
-
-#endif /* CONFIG_PM */
-
 #ifdef CONFIG_X86_64
 extern void default_do_nmi(struct pt_regs *);
-extern void die_nmi(char *str, struct pt_regs *regs, int do_panic);
-extern void nmi_watchdog_default(void);
-#else
-#define nmi_watchdog_default() do {} while (0)
 #endif
 
+extern void die_nmi(char *str, struct pt_regs *regs, int do_panic);
 extern int check_nmi_watchdog(void);
 extern int nmi_watchdog_enabled;
-extern int unknown_nmi_panic;
 extern int avail_to_resrv_perfctr_nmi_bit(unsigned int);
 extern int avail_to_resrv_perfctr_nmi(unsigned int);
 extern int reserve_perfctr_nmi(unsigned int);
@@ -62,12 +37,10 @@ extern int nmi_watchdog_tick(struct pt_regs *regs, unsigned reason);
 
 extern atomic_t nmi_active;
 extern unsigned int nmi_watchdog;
-#define NMI_DISABLED    -1
 #define NMI_NONE       0
 #define NMI_IO_APIC    1
 #define NMI_LOCAL_APIC 2
 #define NMI_INVALID    3
-#define NMI_DEFAULT    NMI_DISABLED
 
 struct ctl_table;
 struct file;
@@ -78,6 +51,24 @@ extern int unknown_nmi_panic;
 void __trigger_all_cpu_backtrace(void);
 #define trigger_all_cpu_backtrace() __trigger_all_cpu_backtrace()
 
+static inline void localise_nmi_watchdog(void)
+{
+       if (nmi_watchdog == NMI_IO_APIC)
+               nmi_watchdog = NMI_LOCAL_APIC;
+}
+
+/* check if nmi_watchdog is active (ie was specified at boot) */
+static inline int nmi_watchdog_active(void)
+{
+       /*
+        * actually it should be:
+        *      return (nmi_watchdog == NMI_LOCAL_APIC ||
+        *              nmi_watchdog == NMI_IO_APIC)
+        * but since they are power of two we could use a
+        * cheaper way --cvg
+        */
+       return nmi_watchdog & 0x3;
+}
 #endif
 
 void lapic_watchdog_stop(void);
index 03d0f7a..220d7b7 100644 (file)
@@ -2,14 +2,10 @@
 #define _ASM_X86_32_NUMA_H 1
 
 extern int pxm_to_nid(int pxm);
+extern void numa_remove_cpu(int cpu);
 
 #ifdef CONFIG_NUMA
-extern void __init remap_numa_kva(void);
-extern void set_highmem_pages_init(int);
-#else
-static inline void remap_numa_kva(void)
-{
-}
+extern void set_highmem_pages_init(void);
 #endif
 
 #endif /* _ASM_X86_32_NUMA_H */
index 22e87c9..3830094 100644 (file)
@@ -14,32 +14,30 @@ extern int compute_hash_shift(struct bootnode *nodes, int numblks,
 
 #define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
 
-extern void numa_add_cpu(int cpu);
 extern void numa_init_array(void);
 extern int numa_off;
 
-extern void numa_set_node(int cpu, int node);
 extern void srat_reserve_add_area(int nodeid);
 extern int hotadd_percent;
 
 extern s16 apicid_to_node[MAX_LOCAL_APIC];
 
-extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
 extern unsigned long numa_free_all_bootmem(void);
 extern void setup_node_bootmem(int nodeid, unsigned long start,
                               unsigned long end);
 
 #ifdef CONFIG_NUMA
 extern void __init init_cpu_to_node(void);
-
-static inline void clear_node_cpumask(int cpu)
-{
-       clear_bit(cpu, (unsigned long *)&node_to_cpumask_map[cpu_to_node(cpu)]);
-}
-
+extern void __cpuinit numa_set_node(int cpu, int node);
+extern void __cpuinit numa_clear_node(int cpu);
+extern void __cpuinit numa_add_cpu(int cpu);
+extern void __cpuinit numa_remove_cpu(int cpu);
 #else
-#define init_cpu_to_node() do {} while (0)
-#define clear_node_cpumask(cpu) do {} while (0)
+static inline void init_cpu_to_node(void)              { }
+static inline void numa_set_node(int cpu, int node)    { }
+static inline void numa_clear_node(int cpu)            { }
+static inline void numa_add_cpu(int cpu, int node)     { }
+static inline void numa_remove_cpu(int cpu)            { }
 #endif
 
 #endif
index 94b86c3..34b92d5 100644 (file)
@@ -28,6 +28,7 @@
 
 #ifdef CONFIG_X86_NUMAQ
 
+extern int found_numaq;
 extern int get_memcfg_numaq(void);
 
 /*
@@ -156,9 +157,12 @@ struct sys_cfg_data {
        struct          eachquadmem eq[MAX_NUMNODES];   /* indexed by quad id */
 };
 
-static inline unsigned long *get_zholes_size(int nid)
+void numaq_tsc_disable(void);
+
+#else
+static inline int get_memcfg_numaq(void)
 {
-       return NULL;
+       return 0;
 }
 #endif /* CONFIG_X86_NUMAQ */
 #endif /* NUMAQ_H */
index dc936dd..28d7b45 100644 (file)
 
 #ifndef __ASSEMBLY__
 
+typedef struct { pgdval_t pgd; } pgd_t;
+typedef struct { pgprotval_t pgprot; } pgprot_t;
+
 extern int page_is_ram(unsigned long pagenr);
 extern int devmem_is_allowed(unsigned long pagenr);
+extern void map_devmem(unsigned long pfn, unsigned long size,
+                      pgprot_t vma_prot);
+extern void unmap_devmem(unsigned long pfn, unsigned long size,
+                        pgprot_t vma_prot);
 
+extern unsigned long max_low_pfn_mapped;
 extern unsigned long max_pfn_mapped;
 
 struct page;
@@ -74,9 +82,6 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
        alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
 
-typedef struct { pgdval_t pgd; } pgd_t;
-typedef struct { pgprotval_t pgprot; } pgprot_t;
-
 static inline pgd_t native_make_pgd(pgdval_t val)
 {
        return (pgd_t) { val };
@@ -160,6 +165,7 @@ static inline pteval_t native_pte_val(pte_t pte)
 #endif
 
 #define pte_val(x)     native_pte_val(x)
+#define pte_flags(x)   native_pte_val(x)
 #define __pte(x)       native_make_pte(x)
 
 #endif /* CONFIG_PARAVIRT */
index ccf0ba3..ab85287 100644 (file)
  */
 #define __PAGE_OFFSET          _AC(CONFIG_PAGE_OFFSET, UL)
 
+#ifdef CONFIG_4KSTACKS
+#define THREAD_ORDER   0
+#else
+#define THREAD_ORDER   1
+#endif
+#define THREAD_SIZE    (PAGE_SIZE << THREAD_ORDER)
+
+
 #ifdef CONFIG_X86_PAE
 /* 44=32+12, the limit we can fit into an unsigned long pfn */
 #define __PHYSICAL_MASK_SHIFT  44
@@ -84,6 +92,13 @@ extern int sysctl_legacy_va_layout;
 #define VMALLOC_RESERVE                ((unsigned long)__VMALLOC_RESERVE)
 #define MAXMEM                 (-__PAGE_OFFSET - __VMALLOC_RESERVE)
 
+extern void find_low_pfn_range(void);
+extern unsigned long init_memory_mapping(unsigned long start,
+                                        unsigned long end);
+extern void initmem_init(unsigned long, unsigned long);
+extern void setup_bootmem_allocator(void);
+
+
 #ifdef CONFIG_X86_USE_3DNOW
 #include <asm/mmx.h>
 
index 6ea7285..c6916c8 100644 (file)
 #define PUD_PAGE_SIZE          (_AC(1, UL) << PUD_SHIFT)
 #define PUD_PAGE_MASK          (~(PUD_PAGE_SIZE-1))
 
-#define __PAGE_OFFSET           _AC(0xffff810000000000, UL)
+/*
+ * Set __PAGE_OFFSET to the most negative possible address +
+ * PGDIR_SIZE*16 (pgd slot 272).  The gap is to allow a space for a
+ * hypervisor to fit.  Choosing 16 slots here is arbitrary, but it's
+ * what Xen requires.
+ */
+#define __PAGE_OFFSET           _AC(0xffff880000000000, UL)
 
 #define __PHYSICAL_START       CONFIG_PHYSICAL_START
 #define __KERNEL_ALIGN         0x200000
@@ -58,7 +64,8 @@
 void clear_page(void *page);
 void copy_page(void *to, void *from);
 
-extern unsigned long end_pfn;
+/* duplicated to the one in bootmem.h */
+extern unsigned long max_pfn;
 extern unsigned long phys_base;
 
 extern unsigned long __phys_addr(unsigned long);
@@ -83,10 +90,15 @@ typedef struct { pteval_t pte; } pte_t;
 extern unsigned long init_memory_mapping(unsigned long start,
                                         unsigned long end);
 
+extern void initmem_init(unsigned long start_pfn, unsigned long end_pfn);
+
+extern void init_extra_mapping_uc(unsigned long phys, unsigned long size);
+extern void init_extra_mapping_wb(unsigned long phys, unsigned long size);
+
 #endif /* !__ASSEMBLY__ */
 
 #ifdef CONFIG_FLATMEM
-#define pfn_valid(pfn)          ((pfn) < end_pfn)
+#define pfn_valid(pfn)          ((pfn) < max_pfn)
 #endif
 
 
index 0f13b94..ef5e8ec 100644 (file)
@@ -84,7 +84,7 @@ struct pv_time_ops {
        int (*set_wallclock)(unsigned long);
 
        unsigned long long (*sched_clock)(void);
-       unsigned long (*get_cpu_khz)(void);
+       unsigned long (*get_tsc_khz)(void);
 };
 
 struct pv_cpu_ops {
@@ -115,6 +115,9 @@ struct pv_cpu_ops {
        void (*set_ldt)(const void *desc, unsigned entries);
        unsigned long (*store_tr)(void);
        void (*load_tls)(struct thread_struct *t, unsigned int cpu);
+#ifdef CONFIG_X86_64
+       void (*load_gs_index)(unsigned int idx);
+#endif
        void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
                                const void *desc);
        void (*write_gdt_entry)(struct desc_struct *,
@@ -141,8 +144,32 @@ struct pv_cpu_ops {
        u64 (*read_pmc)(int counter);
        unsigned long long (*read_tscp)(unsigned int *aux);
 
-       /* These two are jmp to, not actually called. */
-       void (*irq_enable_syscall_ret)(void);
+       /*
+        * Atomically enable interrupts and return to userspace.  This
+        * is only ever used to return to 32-bit processes; in a
+        * 64-bit kernel, it's used for 32-on-64 compat processes, but
+        * never native 64-bit processes.  (Jump, not call.)
+        */
+       void (*irq_enable_sysexit)(void);
+
+       /*
+        * Switch to usermode gs and return to 64-bit usermode using
+        * sysret.  Only used in 64-bit kernels to return to 64-bit
+        * processes.  Usermode register state, including %rsp, must
+        * already be restored.
+        */
+       void (*usergs_sysret64)(void);
+
+       /*
+        * Switch to usermode gs and return to 32-bit usermode using
+        * sysret.  Used to return to 32-on-64 compat processes.
+        * Other usermode register state, including %esp, must already
+        * be restored.
+        */
+       void (*usergs_sysret32)(void);
+
+       /* Normal iret.  Jump to this with the standard iret stack
+          frame set up. */
        void (*iret)(void);
 
        void (*swapgs)(void);
@@ -165,6 +192,10 @@ struct pv_irq_ops {
        void (*irq_enable)(void);
        void (*safe_halt)(void);
        void (*halt)(void);
+
+#ifdef CONFIG_X86_64
+       void (*adjust_exception_frame)(void);
+#endif
 };
 
 struct pv_apic_ops {
@@ -219,7 +250,14 @@ struct pv_mmu_ops {
        void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
                                 unsigned long va);
 
-       /* Hooks for allocating/releasing pagetable pages */
+       /* Hooks for allocating and freeing a pagetable top-level */
+       int  (*pgd_alloc)(struct mm_struct *mm);
+       void (*pgd_free)(struct mm_struct *mm, pgd_t *pgd);
+
+       /*
+        * Hooks for allocating/releasing pagetable pages when they're
+        * attached to a pagetable
+        */
        void (*alloc_pte)(struct mm_struct *mm, u32 pfn);
        void (*alloc_pmd)(struct mm_struct *mm, u32 pfn);
        void (*alloc_pmd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
@@ -238,7 +276,13 @@ struct pv_mmu_ops {
        void (*pte_update_defer)(struct mm_struct *mm,
                                 unsigned long addr, pte_t *ptep);
 
+       pte_t (*ptep_modify_prot_start)(struct mm_struct *mm, unsigned long addr,
+                                       pte_t *ptep);
+       void (*ptep_modify_prot_commit)(struct mm_struct *mm, unsigned long addr,
+                                       pte_t *ptep, pte_t pte);
+
        pteval_t (*pte_val)(pte_t);
+       pteval_t (*pte_flags)(pte_t);
        pte_t (*make_pte)(pteval_t pte);
 
        pgdval_t (*pgd_val)(pgd_t);
@@ -273,6 +317,13 @@ struct pv_mmu_ops {
 #endif
 
        struct pv_lazy_ops lazy_mode;
+
+       /* dom0 ops */
+
+       /* Sometimes the physical address is a pfn, and sometimes its
+          an mfn.  We can tell which is which from the index. */
+       void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
+                          unsigned long phys, pgprot_t flags);
 };
 
 /* This contains all the paravirt structures: we get a convenient
@@ -439,10 +490,17 @@ int paravirt_disable_iospace(void);
 #define VEXTRA_CLOBBERS         , "rax", "r8", "r9", "r10", "r11"
 #endif
 
+#ifdef CONFIG_PARAVIRT_DEBUG
+#define PVOP_TEST_NULL(op)     BUG_ON(op == NULL)
+#else
+#define PVOP_TEST_NULL(op)     ((void)op)
+#endif
+
 #define __PVOP_CALL(rettype, op, pre, post, ...)                       \
        ({                                                              \
                rettype __ret;                                          \
                PVOP_CALL_ARGS;                                 \
+               PVOP_TEST_NULL(op);                                     \
                /* This is 32-bit specific, but is okay in 64-bit */    \
                /* since this condition will never hold */              \
                if (sizeof(rettype) > sizeof(unsigned long)) {          \
@@ -471,6 +529,7 @@ int paravirt_disable_iospace(void);
 #define __PVOP_VCALL(op, pre, post, ...)                               \
        ({                                                              \
                PVOP_VCALL_ARGS;                                        \
+               PVOP_TEST_NULL(op);                                     \
                asm volatile(pre                                        \
                             paravirt_alt(PARAVIRT_CALL)                \
                             post                                       \
@@ -720,7 +779,7 @@ static inline unsigned long long paravirt_sched_clock(void)
 {
        return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
 }
-#define calculate_cpu_khz() (pv_time_ops.get_cpu_khz())
+#define calibrate_tsc() (pv_time_ops.get_tsc_khz())
 
 static inline unsigned long long paravirt_read_pmc(int counter)
 {
@@ -789,6 +848,13 @@ static inline void load_TLS(struct thread_struct *t, unsigned cpu)
        PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
 }
 
+#ifdef CONFIG_X86_64
+static inline void load_gs_index(unsigned int gs)
+{
+       PVOP_VCALL1(pv_cpu_ops.load_gs_index, gs);
+}
+#endif
+
 static inline void write_ldt_entry(struct desc_struct *dt, int entry,
                                   const void *desc)
 {
@@ -912,6 +978,16 @@ static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
        PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, &cpumask, mm, va);
 }
 
+static inline int paravirt_pgd_alloc(struct mm_struct *mm)
+{
+       return PVOP_CALL1(int, pv_mmu_ops.pgd_alloc, mm);
+}
+
+static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+       PVOP_VCALL2(pv_mmu_ops.pgd_free, mm, pgd);
+}
+
 static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned pfn)
 {
        PVOP_VCALL2(pv_mmu_ops.alloc_pte, mm, pfn);
@@ -996,6 +1072,20 @@ static inline pteval_t pte_val(pte_t pte)
        return ret;
 }
 
+static inline pteval_t pte_flags(pte_t pte)
+{
+       pteval_t ret;
+
+       if (sizeof(pteval_t) > sizeof(long))
+               ret = PVOP_CALL2(pteval_t, pv_mmu_ops.pte_flags,
+                                pte.pte, (u64)pte.pte >> 32);
+       else
+               ret = PVOP_CALL1(pteval_t, pv_mmu_ops.pte_flags,
+                                pte.pte);
+
+       return ret;
+}
+
 static inline pgd_t __pgd(pgdval_t val)
 {
        pgdval_t ret;
@@ -1024,6 +1114,29 @@ static inline pgdval_t pgd_val(pgd_t pgd)
        return ret;
 }
 
+#define  __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
+static inline pte_t ptep_modify_prot_start(struct mm_struct *mm, unsigned long addr,
+                                          pte_t *ptep)
+{
+       pteval_t ret;
+
+       ret = PVOP_CALL3(pteval_t, pv_mmu_ops.ptep_modify_prot_start,
+                        mm, addr, ptep);
+
+       return (pte_t) { .pte = ret };
+}
+
+static inline void ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
+                                          pte_t *ptep, pte_t pte)
+{
+       if (sizeof(pteval_t) > sizeof(long))
+               /* 5 arg words */
+               pv_mmu_ops.ptep_modify_prot_commit(mm, addr, ptep, pte);
+       else
+               PVOP_VCALL4(pv_mmu_ops.ptep_modify_prot_commit,
+                           mm, addr, ptep, pte.pte);
+}
+
 static inline void set_pte(pte_t *ptep, pte_t pte)
 {
        if (sizeof(pteval_t) > sizeof(long))
@@ -1252,6 +1365,12 @@ static inline void arch_flush_lazy_mmu_mode(void)
        }
 }
 
+static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
+                               unsigned long phys, pgprot_t flags)
+{
+       pv_mmu_ops.set_fixmap(idx, phys, flags);
+}
+
 void _paravirt_nop(void);
 #define paravirt_nop   ((void *)_paravirt_nop)
 
@@ -1374,54 +1493,86 @@ static inline unsigned long __raw_local_irq_save(void)
 #define PV_RESTORE_REGS popq %rdx; popq %rcx; popq %rdi; popq %rax
 #define PARA_PATCH(struct, off)        ((PARAVIRT_PATCH_##struct + (off)) / 8)
 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
+#define PARA_INDIRECT(addr)    *addr(%rip)
 #else
 #define PV_SAVE_REGS   pushl %eax; pushl %edi; pushl %ecx; pushl %edx
 #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
 #define PARA_PATCH(struct, off)        ((PARAVIRT_PATCH_##struct + (off)) / 4)
 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
+#define PARA_INDIRECT(addr)    *%cs:addr
 #endif
 
 #define INTERRUPT_RETURN                                               \
        PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE,       \
-                 jmp *%cs:pv_cpu_ops+PV_CPU_iret)
+                 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_iret))
 
 #define DISABLE_INTERRUPTS(clobbers)                                   \
        PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
-                 PV_SAVE_REGS;                 \
-                 call *%cs:pv_irq_ops+PV_IRQ_irq_disable;              \
+                 PV_SAVE_REGS;                                         \
+                 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_disable);    \
                  PV_RESTORE_REGS;)                     \
 
 #define ENABLE_INTERRUPTS(clobbers)                                    \
        PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers,  \
-                 PV_SAVE_REGS;                 \
-                 call *%cs:pv_irq_ops+PV_IRQ_irq_enable;               \
+                 PV_SAVE_REGS;                                         \
+                 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_irq_enable);     \
                  PV_RESTORE_REGS;)
 
-#define ENABLE_INTERRUPTS_SYSCALL_RET                                  \
-       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
+#define USERGS_SYSRET32                                                        \
+       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret32),       \
                  CLBR_NONE,                                            \
-                 jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
-
+                 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret32))
 
 #ifdef CONFIG_X86_32
-#define GET_CR0_INTO_EAX                       \
-       push %ecx; push %edx;                   \
-       call *pv_cpu_ops+PV_CPU_read_cr0;       \
+#define GET_CR0_INTO_EAX                               \
+       push %ecx; push %edx;                           \
+       call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
        pop %edx; pop %ecx
-#else
+
+#define ENABLE_INTERRUPTS_SYSEXIT                                      \
+       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit),    \
+                 CLBR_NONE,                                            \
+                 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
+
+
+#else  /* !CONFIG_X86_32 */
+
+/*
+ * If swapgs is used while the userspace stack is still current,
+ * there's no way to call a pvop.  The PV replacement *must* be
+ * inlined, or the swapgs instruction must be trapped and emulated.
+ */
+#define SWAPGS_UNSAFE_STACK                                            \
+       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE,     \
+                 swapgs)
+
 #define SWAPGS                                                         \
        PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE,     \
                  PV_SAVE_REGS;                                         \
-                 call *pv_cpu_ops+PV_CPU_swapgs;                       \
+                 call PARA_INDIRECT(pv_cpu_ops+PV_CPU_swapgs);         \
                  PV_RESTORE_REGS                                       \
                 )
 
-#define GET_CR2_INTO_RCX                       \
-       call *pv_mmu_ops+PV_MMU_read_cr2;       \
-       movq %rax, %rcx;                        \
+#define GET_CR2_INTO_RCX                               \
+       call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr2); \
+       movq %rax, %rcx;                                \
        xorq %rax, %rax;
 
-#endif
+#define PARAVIRT_ADJUST_EXCEPTION_FRAME                                        \
+       PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_adjust_exception_frame), \
+                 CLBR_NONE,                                            \
+                 call PARA_INDIRECT(pv_irq_ops+PV_IRQ_adjust_exception_frame))
+
+#define USERGS_SYSRET64                                                        \
+       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_usergs_sysret64),       \
+                 CLBR_NONE,                                            \
+                 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_usergs_sysret64))
+
+#define ENABLE_INTERRUPTS_SYSEXIT32                                    \
+       PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit),    \
+                 CLBR_NONE,                                            \
+                 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
+#endif /* CONFIG_X86_32 */
 
 #endif /* __ASSEMBLY__ */
 #endif /* CONFIG_PARAVIRT */
index 88f60cc..7edc473 100644 (file)
@@ -1,14 +1,13 @@
-
 #ifndef _ASM_PAT_H
-#define _ASM_PAT_H 1
+#define _ASM_PAT_H
 
 #include <linux/types.h>
 
 #ifdef CONFIG_X86_PAT
-extern int pat_wc_enabled;
+extern int pat_enabled;
 extern void validate_pat_support(struct cpuinfo_x86 *c);
 #else
-static const int pat_wc_enabled = 0;
+static const int pat_enabled;
 static inline void validate_pat_support(struct cpuinfo_x86 *c) { }
 #endif
 
@@ -21,4 +20,3 @@ extern int free_memtype(u64 start, u64 end);
 extern void pat_disable(char *reason);
 
 #endif
-
index 30bbde0..2db14cf 100644 (file)
@@ -18,6 +18,8 @@ struct pci_sysdata {
 #endif
 };
 
+extern int pci_routeirq;
+
 /* scan a bus after allocating a pci_sysdata for it */
 extern struct pci_bus *pci_scan_bus_on_node(int busno, struct pci_ops *ops,
                                            int node);
index 8c4c3a0..a50d468 100644 (file)
@@ -18,12 +18,14 @@ struct pci_dev;
 #define PCI_DMA_BUS_IS_PHYS    (1)
 
 /* pci_unmap_{page,single} is a nop so... */
-#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
-#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
-#define pci_unmap_addr(PTR, ADDR_NAME)         (0)
-#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL)        do { } while (0)
-#define pci_unmap_len(PTR, LEN_NAME)           (0)
-#define pci_unmap_len_set(PTR, LEN_NAME, VAL)  do { } while (0)
+#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)      dma_addr_t ADDR_NAME[0];
+#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)        unsigned LEN_NAME[0];
+#define pci_unmap_addr(PTR, ADDR_NAME) sizeof((PTR)->ADDR_NAME)
+#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
+       do { break; } while (pci_unmap_addr(PTR, ADDR_NAME))
+#define pci_unmap_len(PTR, LEN_NAME)           sizeof((PTR)->LEN_NAME)
+#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
+       do { break; } while (pci_unmap_len(PTR, LEN_NAME))
 
 
 #endif /* __KERNEL__ */
index 101fb9e..b34e9a7 100644 (file)
@@ -22,6 +22,8 @@ struct x8664_pda {
                                           offset 40!!! */
 #endif
        char *irqstackptr;
+       short nodenumber;               /* number of current node (32k max) */
+       short in_bootmem;               /* pda lives in bootmem */
        unsigned int __softirq_pending;
        unsigned int __nmi_count;       /* number of NMI on this CPUs */
        short mmu_state;
@@ -37,8 +39,7 @@ struct x8664_pda {
        unsigned irq_spurious_count;
 } ____cacheline_aligned_in_smp;
 
-extern struct x8664_pda *_cpu_pda[];
-extern struct x8664_pda boot_cpu_pda[];
+extern struct x8664_pda **_cpu_pda;
 extern void pda_init(int);
 
 #define cpu_pda(i) (_cpu_pda[i])
index 736fc3b..912a3a1 100644 (file)
@@ -143,4 +143,50 @@ do {                                                       \
 #define x86_or_percpu(var, val) percpu_to_op("or", per_cpu__##var, val)
 #endif /* !__ASSEMBLY__ */
 #endif /* !CONFIG_X86_64 */
+
+#ifdef CONFIG_SMP
+
+/*
+ * Define the "EARLY_PER_CPU" macros.  These are used for some per_cpu
+ * variables that are initialized and accessed before there are per_cpu
+ * areas allocated.
+ */
+
+#define        DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)                  \
+       DEFINE_PER_CPU(_type, _name) = _initvalue;                      \
+       __typeof__(_type) _name##_early_map[NR_CPUS] __initdata =       \
+                               { [0 ... NR_CPUS-1] = _initvalue };     \
+       __typeof__(_type) *_name##_early_ptr = _name##_early_map
+
+#define EXPORT_EARLY_PER_CPU_SYMBOL(_name)                     \
+       EXPORT_PER_CPU_SYMBOL(_name)
+
+#define DECLARE_EARLY_PER_CPU(_type, _name)                    \
+       DECLARE_PER_CPU(_type, _name);                          \
+       extern __typeof__(_type) *_name##_early_ptr;            \
+       extern __typeof__(_type)  _name##_early_map[]
+
+#define        early_per_cpu_ptr(_name) (_name##_early_ptr)
+#define        early_per_cpu_map(_name, _idx) (_name##_early_map[_idx])
+#define        early_per_cpu(_name, _cpu)                              \
+       (early_per_cpu_ptr(_name) ?                             \
+               early_per_cpu_ptr(_name)[_cpu] :                \
+               per_cpu(_name, _cpu))
+
+#else  /* !CONFIG_SMP */
+#define        DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)          \
+       DEFINE_PER_CPU(_type, _name) = _initvalue
+
+#define EXPORT_EARLY_PER_CPU_SYMBOL(_name)                     \
+       EXPORT_PER_CPU_SYMBOL(_name)
+
+#define DECLARE_EARLY_PER_CPU(_type, _name)                    \
+       DECLARE_PER_CPU(_type, _name)
+
+#define        early_per_cpu(_name, _cpu) per_cpu(_name, _cpu)
+#define        early_per_cpu_ptr(_name) NULL
+/* no early_per_cpu_map() */
+
+#endif /* !CONFIG_SMP */
+
 #endif /* _ASM_X86_PERCPU_H_ */
index 91e4641..d63ea43 100644 (file)
@@ -5,9 +5,13 @@
 #include <linux/mm.h>          /* for struct page */
 #include <linux/pagemap.h>
 
+static inline int  __paravirt_pgd_alloc(struct mm_struct *mm) { return 0; }
+
 #ifdef CONFIG_PARAVIRT
 #include <asm/paravirt.h>
 #else
+#define paravirt_pgd_alloc(mm) __paravirt_pgd_alloc(mm)
+static inline void paravirt_pgd_free(struct mm_struct *mm, pgd_t *pgd) {}
 static inline void paravirt_alloc_pte(struct mm_struct *mm, unsigned long pfn) {}
 static inline void paravirt_alloc_pmd(struct mm_struct *mm, unsigned long pfn) {}
 static inline void paravirt_alloc_pmd_clone(unsigned long pfn, unsigned long clonepfn,
index 97c271b..49cbd76 100644 (file)
 #define _PAGE_BIT_PAT_LARGE    12      /* On 2MB or 1GB pages */
 #define _PAGE_BIT_NX           63       /* No execute: only valid after cpuid check */
 
-/*
- * Note: we use _AC(1, L) instead of _AC(1, UL) so that we get a
- * sign-extended value on 32-bit with all 1's in the upper word,
- * which preserves the upper pte values on 64-bit ptes:
- */
-#define _PAGE_PRESENT  (_AC(1, L)<<_PAGE_BIT_PRESENT)
-#define _PAGE_RW       (_AC(1, L)<<_PAGE_BIT_RW)
-#define _PAGE_USER     (_AC(1, L)<<_PAGE_BIT_USER)
-#define _PAGE_PWT      (_AC(1, L)<<_PAGE_BIT_PWT)
-#define _PAGE_PCD      (_AC(1, L)<<_PAGE_BIT_PCD)
-#define _PAGE_ACCESSED (_AC(1, L)<<_PAGE_BIT_ACCESSED)
-#define _PAGE_DIRTY    (_AC(1, L)<<_PAGE_BIT_DIRTY)
-#define _PAGE_PSE      (_AC(1, L)<<_PAGE_BIT_PSE)      /* 2MB page */
-#define _PAGE_GLOBAL   (_AC(1, L)<<_PAGE_BIT_GLOBAL)   /* Global TLB entry */
-#define _PAGE_UNUSED1  (_AC(1, L)<<_PAGE_BIT_UNUSED1)
-#define _PAGE_UNUSED2  (_AC(1, L)<<_PAGE_BIT_UNUSED2)
-#define _PAGE_UNUSED3  (_AC(1, L)<<_PAGE_BIT_UNUSED3)
-#define _PAGE_PAT      (_AC(1, L)<<_PAGE_BIT_PAT)
-#define _PAGE_PAT_LARGE (_AC(1, L)<<_PAGE_BIT_PAT_LARGE)
+#define _PAGE_PRESENT  (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
+#define _PAGE_RW       (_AT(pteval_t, 1) << _PAGE_BIT_RW)
+#define _PAGE_USER     (_AT(pteval_t, 1) << _PAGE_BIT_USER)
+#define _PAGE_PWT      (_AT(pteval_t, 1) << _PAGE_BIT_PWT)
+#define _PAGE_PCD      (_AT(pteval_t, 1) << _PAGE_BIT_PCD)
+#define _PAGE_ACCESSED (_AT(pteval_t, 1) << _PAGE_BIT_ACCESSED)
+#define _PAGE_DIRTY    (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
+#define _PAGE_PSE      (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
+#define _PAGE_GLOBAL   (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
+#define _PAGE_UNUSED1  (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
+#define _PAGE_UNUSED2  (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED2)
+#define _PAGE_UNUSED3  (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
+#define _PAGE_PAT      (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
+#define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
 
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
-#define _PAGE_NX       (_AC(1, ULL) << _PAGE_BIT_NX)
+#define _PAGE_NX       (_AT(pteval_t, 1) << _PAGE_BIT_NX)
 #else
-#define _PAGE_NX       0
+#define _PAGE_NX       (_AT(pteval_t, 0))
 #endif
 
 /* If _PAGE_PRESENT is clear, we use these: */
 #define PAGE_READONLY_EXEC     __pgprot(_PAGE_PRESENT | _PAGE_USER |   \
                                         _PAGE_ACCESSED)
 
-#ifdef CONFIG_X86_32
-#define _PAGE_KERNEL_EXEC \
-       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
-#define _PAGE_KERNEL (_PAGE_KERNEL_EXEC | _PAGE_NX)
-
-#ifndef __ASSEMBLY__
-extern pteval_t __PAGE_KERNEL, __PAGE_KERNEL_EXEC;
-#endif /* __ASSEMBLY__ */
-#else
 #define __PAGE_KERNEL_EXEC                                             \
-       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
+       (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
 #define __PAGE_KERNEL          (__PAGE_KERNEL_EXEC | _PAGE_NX)
-#endif
 
 #define __PAGE_KERNEL_RO               (__PAGE_KERNEL & ~_PAGE_RW)
 #define __PAGE_KERNEL_RX               (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
@@ -106,26 +91,22 @@ extern pteval_t __PAGE_KERNEL, __PAGE_KERNEL_EXEC;
 #define __PAGE_KERNEL_VSYSCALL         (__PAGE_KERNEL_RX | _PAGE_USER)
 #define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
 #define __PAGE_KERNEL_LARGE            (__PAGE_KERNEL | _PAGE_PSE)
+#define __PAGE_KERNEL_LARGE_NOCACHE    (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
 #define __PAGE_KERNEL_LARGE_EXEC       (__PAGE_KERNEL_EXEC | _PAGE_PSE)
 
-#ifdef CONFIG_X86_32
-# define MAKE_GLOBAL(x)                        __pgprot((x))
-#else
-# define MAKE_GLOBAL(x)                        __pgprot((x) | _PAGE_GLOBAL)
-#endif
-
-#define PAGE_KERNEL                    MAKE_GLOBAL(__PAGE_KERNEL)
-#define PAGE_KERNEL_RO                 MAKE_GLOBAL(__PAGE_KERNEL_RO)
-#define PAGE_KERNEL_EXEC               MAKE_GLOBAL(__PAGE_KERNEL_EXEC)
-#define PAGE_KERNEL_RX                 MAKE_GLOBAL(__PAGE_KERNEL_RX)
-#define PAGE_KERNEL_WC                 MAKE_GLOBAL(__PAGE_KERNEL_WC)
-#define PAGE_KERNEL_NOCACHE            MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
-#define PAGE_KERNEL_UC_MINUS           MAKE_GLOBAL(__PAGE_KERNEL_UC_MINUS)
-#define PAGE_KERNEL_EXEC_NOCACHE       MAKE_GLOBAL(__PAGE_KERNEL_EXEC_NOCACHE)
-#define PAGE_KERNEL_LARGE              MAKE_GLOBAL(__PAGE_KERNEL_LARGE)
-#define PAGE_KERNEL_LARGE_EXEC         MAKE_GLOBAL(__PAGE_KERNEL_LARGE_EXEC)
-#define PAGE_KERNEL_VSYSCALL           MAKE_GLOBAL(__PAGE_KERNEL_VSYSCALL)
-#define PAGE_KERNEL_VSYSCALL_NOCACHE   MAKE_GLOBAL(__PAGE_KERNEL_VSYSCALL_NOCACHE)
+#define PAGE_KERNEL                    __pgprot(__PAGE_KERNEL)
+#define PAGE_KERNEL_RO                 __pgprot(__PAGE_KERNEL_RO)
+#define PAGE_KERNEL_EXEC               __pgprot(__PAGE_KERNEL_EXEC)
+#define PAGE_KERNEL_RX                 __pgprot(__PAGE_KERNEL_RX)
+#define PAGE_KERNEL_WC                 __pgprot(__PAGE_KERNEL_WC)
+#define PAGE_KERNEL_NOCACHE            __pgprot(__PAGE_KERNEL_NOCACHE)
+#define PAGE_KERNEL_UC_MINUS           __pgprot(__PAGE_KERNEL_UC_MINUS)
+#define PAGE_KERNEL_EXEC_NOCACHE       __pgprot(__PAGE_KERNEL_EXEC_NOCACHE)
+#define PAGE_KERNEL_LARGE              __pgprot(__PAGE_KERNEL_LARGE)
+#define PAGE_KERNEL_LARGE_NOCACHE      __pgprot(__PAGE_KERNEL_LARGE_NOCACHE)
+#define PAGE_KERNEL_LARGE_EXEC         __pgprot(__PAGE_KERNEL_LARGE_EXEC)
+#define PAGE_KERNEL_VSYSCALL           __pgprot(__PAGE_KERNEL_VSYSCALL)
+#define PAGE_KERNEL_VSYSCALL_NOCACHE   __pgprot(__PAGE_KERNEL_VSYSCALL_NOCACHE)
 
 /*         xwr */
 #define __P000 PAGE_NONE
@@ -164,37 +145,37 @@ extern struct list_head pgd_list;
  */
 static inline int pte_dirty(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_DIRTY;
+       return pte_flags(pte) & _PAGE_DIRTY;
 }
 
 static inline int pte_young(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_ACCESSED;
+       return pte_flags(pte) & _PAGE_ACCESSED;
 }
 
 static inline int pte_write(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_RW;
+       return pte_flags(pte) & _PAGE_RW;
 }
 
 static inline int pte_file(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_FILE;
+       return pte_flags(pte) & _PAGE_FILE;
 }
 
 static inline int pte_huge(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_PSE;
+       return pte_flags(pte) & _PAGE_PSE;
 }
 
 static inline int pte_global(pte_t pte)
 {
-       return pte_val(pte) & _PAGE_GLOBAL;
+       return pte_flags(pte) & _PAGE_GLOBAL;
 }
 
 static inline int pte_exec(pte_t pte)
 {
-       return !(pte_val(pte) & _PAGE_NX);
+       return !(pte_flags(pte) & _PAGE_NX);
 }
 
 static inline int pte_special(pte_t pte)
@@ -210,22 +191,22 @@ static inline int pmd_large(pmd_t pte)
 
 static inline pte_t pte_mkclean(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_DIRTY);
+       return __pte(pte_val(pte) & ~_PAGE_DIRTY);
 }
 
 static inline pte_t pte_mkold(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_ACCESSED);
+       return __pte(pte_val(pte) & ~_PAGE_ACCESSED);
 }
 
 static inline pte_t pte_wrprotect(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_RW);
+       return __pte(pte_val(pte) & ~_PAGE_RW);
 }
 
 static inline pte_t pte_mkexec(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
+       return __pte(pte_val(pte) & ~_PAGE_NX);
 }
 
 static inline pte_t pte_mkdirty(pte_t pte)
@@ -250,7 +231,7 @@ static inline pte_t pte_mkhuge(pte_t pte)
 
 static inline pte_t pte_clrhuge(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_PSE);
+       return __pte(pte_val(pte) & ~_PAGE_PSE);
 }
 
 static inline pte_t pte_mkglobal(pte_t pte)
@@ -260,7 +241,7 @@ static inline pte_t pte_mkglobal(pte_t pte)
 
 static inline pte_t pte_clrglobal(pte_t pte)
 {
-       return __pte(pte_val(pte) & ~(pteval_t)_PAGE_GLOBAL);
+       return __pte(pte_val(pte) & ~_PAGE_GLOBAL);
 }
 
 static inline pte_t pte_mkspecial(pte_t pte)
@@ -305,7 +286,7 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
        return __pgprot(preservebits | addbits);
 }
 
-#define pte_pgprot(x) __pgprot(pte_val(x) & ~PTE_MASK)
+#define pte_pgprot(x) __pgprot(pte_flags(x) & ~PTE_MASK)
 
 #define canon_pgprot(p) __pgprot(pgprot_val(p) & __supported_pte_mask)
 
@@ -318,6 +299,9 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
                               unsigned long size, pgprot_t *vma_prot);
 #endif
 
+/* Install a pte for a particular vaddr in kernel space. */
+void set_pte_vaddr(unsigned long vaddr, pte_t pte);
+
 #ifdef CONFIG_PARAVIRT
 #include <asm/paravirt.h>
 #else  /* !CONFIG_PARAVIRT */
@@ -359,6 +343,26 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 # include "pgtable_64.h"
 #endif
 
+/*
+ * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
+ *
+ * this macro returns the index of the entry in the pgd page which would
+ * control the given virtual address
+ */
+#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+
+/*
+ * pgd_offset() returns a (pgd_t *)
+ * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
+ */
+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
+/*
+ * a shortcut which implies the use of the kernel's pgd, instead
+ * of a process's
+ */
+#define pgd_offset_k(address) pgd_offset(&init_mm, (address))
+
+
 #define KERNEL_PGD_BOUNDARY    pgd_index(PAGE_OFFSET)
 #define KERNEL_PGD_PTRS                (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
 
@@ -369,8 +373,15 @@ enum {
        PG_LEVEL_4K,
        PG_LEVEL_2M,
        PG_LEVEL_1G,
+       PG_LEVEL_NUM
 };
 
+#ifdef CONFIG_PROC_FS
+extern void update_page_count(int level, unsigned long pages);
+#else
+static inline void update_page_count(int level, unsigned long pages) { }
+#endif
+
 /*
  * Helper function that returns the kernel pagetable entry controlling
  * the virtual address 'address'. NULL means no pagetable entry present.
@@ -420,6 +431,8 @@ static inline void native_set_pte_at(struct mm_struct *mm, unsigned long addr,
  * race with other CPU's that might be updating the dirty
  * bit at the same time.
  */
+struct vm_area_struct;
+
 #define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 extern int ptep_set_access_flags(struct vm_area_struct *vma,
                                 unsigned long address, pte_t *ptep,
index 32ca031..ec871c4 100644 (file)
@@ -113,26 +113,6 @@ extern unsigned long pg0[];
  */
 #define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
 
-/*
- * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
- *
- * this macro returns the index of the entry in the pgd page which would
- * control the given virtual address
- */
-#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
-#define pgd_index_k(addr) pgd_index((addr))
-
-/*
- * pgd_offset() returns a (pgd_t *)
- * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
- */
-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
-
-/*
- * a shortcut which implies the use of the kernel's pgd, instead
- * of a process's
- */
-#define pgd_offset_k(address) pgd_offset(&init_mm, (address))
 
 static inline int pud_large(pud_t pud) { return 0; }
 
index 1cc50d2..fa7208b 100644 (file)
@@ -70,6 +70,9 @@ extern void paging_init(void);
 
 struct mm_struct;
 
+void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
+
+
 static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
                                    pte_t *ptep)
 {
@@ -190,12 +193,9 @@ static inline int pmd_bad(pmd_t pmd)
 #define pgd_page_vaddr(pgd)                                            \
        ((unsigned long)__va((unsigned long)pgd_val((pgd)) & PTE_MASK))
 #define pgd_page(pgd)          (pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
-#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
-#define pgd_offset(mm, address)        ((mm)->pgd + pgd_index((address)))
-#define pgd_offset_k(address) (init_level4_pgt + pgd_index((address)))
 #define pgd_present(pgd) (pgd_val(pgd) & _PAGE_PRESENT)
 static inline int pgd_large(pgd_t pgd) { return 0; }
-#define mk_kernel_pgd(address) ((pgd_t){ (address) | _KERNPG_TABLE })
+#define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
 
 /* PUD - Level3 access */
 /* to find an entry in a page-table-directory. */
index 199cab1..092b39b 100644 (file)
 #define CX86_ARR_BASE  0xc4
 #define CX86_RCR_BASE  0xdc
 
+#ifdef CONFIG_VM86
+#define X86_VM_MASK    X86_EFLAGS_VM
+#else
+#define X86_VM_MASK    0 /* No VM86 support */
+#endif
+
 #endif /* __ASM_I386_PROCESSOR_FLAGS_H */
index 5591052..7f73827 100644 (file)
@@ -153,7 +153,7 @@ static inline int hlt_works(int cpu)
 
 extern void cpu_detect(struct cpuinfo_x86 *c);
 
-extern void identify_cpu(struct cpuinfo_x86 *);
+extern void early_cpu_init(void);
 extern void identify_boot_cpu(void);
 extern void identify_secondary_cpu(struct cpuinfo_x86 *);
 extern void print_cpu_info(struct cpuinfo_x86 *);
@@ -262,16 +262,12 @@ struct tss_struct {
        unsigned long           io_bitmap_max;
        struct thread_struct    *io_bitmap_owner;
 
-       /*
-        * Pad the TSS to be cacheline-aligned (size is 0x100):
-        */
-       unsigned long           __cacheline_filler[35];
        /*
         * .. and then another 0x100 bytes for the emergency kernel stack:
         */
        unsigned long           stack[64];
 
-} __attribute__((packed));
+} ____cacheline_aligned;
 
 DECLARE_PER_CPU(struct tss_struct, init_tss);
 
@@ -535,7 +531,6 @@ static inline void load_sp0(struct tss_struct *tss,
 }
 
 #define set_iopl_mask native_set_iopl_mask
-#define SWAPGS swapgs
 #endif /* CONFIG_PARAVIRT */
 
 /*
index 6c8b41b..3dd458c 100644 (file)
@@ -14,8 +14,6 @@ extern void ia32_syscall(void);
 extern void ia32_cstar_target(void);
 extern void ia32_sysenter_target(void);
 
-extern void reserve_bootmem_generic(unsigned long phys, unsigned len);
-
 extern void syscall32_cpu_init(void);
 
 extern void check_efer(void);
index 9f922b0..8a71db8 100644 (file)
@@ -3,7 +3,12 @@
 
 #include <linux/compiler.h>    /* For __user */
 #include <asm/ptrace-abi.h>
+#include <asm/processor-flags.h>
 
+#ifdef __KERNEL__
+#include <asm/ds.h>            /* the DS BTS struct is used for ptrace too */
+#include <asm/segment.h>
+#endif
 
 #ifndef __ASSEMBLY__
 
@@ -55,9 +60,6 @@ struct pt_regs {
        unsigned long ss;
 };
 
-#include <asm/vm86.h>
-#include <asm/segment.h>
-
 #endif /* __KERNEL__ */
 
 #else /* __i386__ */
index e63741f..206f355 100644 (file)
@@ -14,8 +14,8 @@ struct machine_ops {
 
 extern struct machine_ops machine_ops;
 
-void machine_real_restart(unsigned char *code, int length);
 void native_machine_crash_shutdown(struct pt_regs *regs);
 void native_machine_shutdown(void);
+void machine_real_restart(const unsigned char *code, int length);
 
 #endif /* _ASM_REBOOT_H */
index 7400d3a..adec887 100644 (file)
 
 #if defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
 # define NEED_PAE      (1<<(X86_FEATURE_PAE & 31))
-# define NEED_CX8      (1<<(X86_FEATURE_CX8 & 31))
 #else
 # define NEED_PAE      0
+#endif
+
+#ifdef CONFIG_X86_CMPXCHG64
+# define NEED_CX8      (1<<(X86_FEATURE_CX8 & 31))
+#else
 # define NEED_CX8      0
 #endif
 
@@ -38,7 +42,7 @@
 #endif
 
 #ifdef CONFIG_X86_64
-#define NEED_PSE       (1<<(X86_FEATURE_PSE & 31))
+#define NEED_PSE       0
 #define NEED_MSR       (1<<(X86_FEATURE_MSR & 31))
 #define NEED_PGE       (1<<(X86_FEATURE_PGE & 31))
 #define NEED_FXSR      (1<<(X86_FEATURE_FXSR & 31))
index 2557514..8d9f0b4 100644 (file)
@@ -6,7 +6,7 @@
 #define TRACE_RESUME(user)                                     \
 do {                                                           \
        if (pm_trace_enabled) {                                 \
-               void *tracedata;                                \
+               const void *tracedata;                          \
                asm volatile(_ASM_MOV_UL " $1f,%0\n"            \
                             ".section .tracedata,\"a\"\n"      \
                             "1:\t.word %c1\n\t"                \
index 18da19e..36e71c5 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef _ASM_SECCOMP_H
+#define _ASM_SECCOMP_H
 
 #include <linux/thread_info.h>
 
index 553af65..76cfe69 100644 (file)
@@ -1,4 +1,5 @@
 #ifndef _ASM_SECCOMP_H
+#define _ASM_SECCOMP_H
 
 #include <linux/thread_info.h>
 
index ed5131d..dfc8601 100644 (file)
 #define GDT_ENTRY_TLS_MAX      (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
 
 #define GDT_ENTRY_DEFAULT_USER_CS      14
-#define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS * 8 + 3)
 
 #define GDT_ENTRY_DEFAULT_USER_DS      15
-#define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS * 8 + 3)
 
 #define GDT_ENTRY_KERNEL_BASE  12
 
 #define GDT_ENTRY_KERNEL_CS            (GDT_ENTRY_KERNEL_BASE + 0)
-#define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
 
 #define GDT_ENTRY_KERNEL_DS            (GDT_ENTRY_KERNEL_BASE + 1)
-#define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
 
 #define GDT_ENTRY_TSS                  (GDT_ENTRY_KERNEL_BASE + 4)
 #define GDT_ENTRY_LDT                  (GDT_ENTRY_KERNEL_BASE + 5)
 #else
 #include <asm/cache.h>
 
-#define __KERNEL_CS    0x10
-#define __KERNEL_DS    0x18
+#define GDT_ENTRY_KERNEL32_CS 1
+#define GDT_ENTRY_KERNEL_CS 2
+#define GDT_ENTRY_KERNEL_DS 3
 
-#define __KERNEL32_CS   0x08
+#define __KERNEL32_CS   (GDT_ENTRY_KERNEL32_CS * 8)
 
 /*
  * we cannot use the same code segment descriptor for user and kernel
  * The segment offset needs to contain a RPL. Grr. -AK
  * GDT layout to get 64bit syscall right (sysret hardcodes gdt offsets)
  */
-
-#define __USER32_CS   0x23   /* 4*8+3 */
-#define __USER_DS     0x2b   /* 5*8+3 */
-#define __USER_CS     0x33   /* 6*8+3 */
+#define GDT_ENTRY_DEFAULT_USER32_CS 4
+#define GDT_ENTRY_DEFAULT_USER_DS 5
+#define GDT_ENTRY_DEFAULT_USER_CS 6
+#define __USER32_CS   (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
 #define __USER32_DS    __USER_DS
 
 #define GDT_ENTRY_TSS 8        /* needs two entries */
 
 #endif
 
+#define __KERNEL_CS    (GDT_ENTRY_KERNEL_CS * 8)
+#define __KERNEL_DS    (GDT_ENTRY_KERNEL_DS * 8)
+#define __USER_DS     (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
+#define __USER_CS     (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
 #ifndef CONFIG_PARAVIRT
 #define get_kernel_rpl()  0
 #endif
index fa6763a..90ab222 100644 (file)
@@ -8,7 +8,25 @@
 /* Interrupt control for vSMPowered x86_64 systems */
 void vsmp_init(void);
 
-char *machine_specific_memory_setup(void);
+#ifdef CONFIG_X86_VISWS
+extern void visws_early_detect(void);
+extern int is_visws_box(void);
+#else
+static inline void visws_early_detect(void) { }
+static inline int is_visws_box(void) { return 0; }
+#endif
+
+/*
+ * Any setup quirks to be performed?
+ */
+extern int (*arch_time_init_quirk)(void);
+extern int (*arch_pre_intr_init_quirk)(void);
+extern int (*arch_intr_init_quirk)(void);
+extern int (*arch_trap_init_quirk)(void);
+extern char * (*arch_memory_setup_quirk)(void);
+extern int (*mach_get_smp_config_quirk)(unsigned int early);
+extern int (*mach_find_smp_config_quirk)(unsigned int reserve);
+
 #ifndef CONFIG_PARAVIRT
 #define paravirt_post_allocator_init() do {} while (0)
 #endif
@@ -43,26 +61,23 @@ char *machine_specific_memory_setup(void);
  */
 extern struct boot_params boot_params;
 
-#ifdef __i386__
 /*
  * Do NOT EVER look at the BIOS memory size location.
  * It does not work on many machines.
  */
 #define LOWMEMSIZE()   (0x9f000)
 
-struct e820entry;
-
-char * __init machine_specific_memory_setup(void);
-char *memory_setup(void);
+#ifdef __i386__
 
-int __init copy_e820_map(struct e820entry *biosmap, int nr_map);
-int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map);
-void __init add_memory_region(unsigned long long start,
-                             unsigned long long size, int type);
+void __init i386_start_kernel(void);
+extern void probe_roms(void);
 
+extern unsigned long init_pg_tables_start;
 extern unsigned long init_pg_tables_end;
 
-
+#else
+void __init x86_64_start_kernel(char *real_mode);
+void __init x86_64_start_reservations(char *real_mode_data);
 
 #endif /* __i386__ */
 #endif /* _SETUP */
index 1ebaa5c..2e221f1 100644 (file)
@@ -29,21 +29,12 @@ extern int smp_num_siblings;
 extern unsigned int num_processors;
 extern cpumask_t cpu_initialized;
 
-#ifdef CONFIG_SMP
-extern u16 x86_cpu_to_apicid_init[];
-extern u16 x86_bios_cpu_apicid_init[];
-extern void *x86_cpu_to_apicid_early_ptr;
-extern void *x86_bios_cpu_apicid_early_ptr;
-#else
-#define x86_cpu_to_apicid_early_ptr NULL
-#define x86_bios_cpu_apicid_early_ptr NULL
-#endif
-
 DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
 DECLARE_PER_CPU(cpumask_t, cpu_core_map);
 DECLARE_PER_CPU(u16, cpu_llc_id);
-DECLARE_PER_CPU(u16, x86_cpu_to_apicid);
-DECLARE_PER_CPU(u16, x86_bios_cpu_apicid);
+
+DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
+DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
 
 /* Static state in head.S used to set up a CPU */
 extern struct {
@@ -118,8 +109,6 @@ int native_cpu_up(unsigned int cpunum);
 extern int __cpu_disable(void);
 extern void __cpu_die(unsigned int cpu);
 
-extern void prefill_possible_map(void);
-
 void smp_store_cpu_info(int id);
 #define cpu_physical_id(cpu)   per_cpu(x86_cpu_to_apicid, cpu)
 
@@ -130,6 +119,14 @@ static inline int num_booting_cpus(void)
 }
 #endif /* CONFIG_SMP */
 
+#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_CPU)
+extern void prefill_possible_map(void);
+#else
+static inline void prefill_possible_map(void)
+{
+}
+#endif
+
 extern unsigned disabled_cpus __cpuinitdata;
 
 #ifdef CONFIG_X86_32_SMP
@@ -197,11 +194,9 @@ static inline int hard_smp_processor_id(void)
 #endif /* CONFIG_X86_LOCAL_APIC */
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void cpu_exit_clear(void);
 extern void cpu_uninit(void);
 #endif
 
-extern void smp_alloc_memory(void);
 extern void lock_ipi_call_lock(void);
 extern void unlock_ipi_call_lock(void);
 #endif /* __ASSEMBLY__ */
index f4bba13..774c919 100644 (file)
 #ifndef _ASM_SRAT_H_
 #define _ASM_SRAT_H_
 
-#ifndef CONFIG_ACPI_SRAT
-#error CONFIG_ACPI_SRAT not defined, and srat.h header has been included
-#endif
-
+#ifdef CONFIG_ACPI_NUMA
 extern int get_memcfg_from_srat(void);
-extern unsigned long *get_zholes_size(int);
+#else
+static inline int get_memcfg_from_srat(void)
+{
+       return 0;
+}
+#endif
 
 #endif /* _ASM_SRAT_H_ */
index b49369a..193578c 100644 (file)
@@ -29,81 +29,116 @@ extern char *strchr(const char *s, int c);
 #define __HAVE_ARCH_STRLEN
 extern size_t strlen(const char *s);
 
-static __always_inline void * __memcpy(void * to, const void * from, size_t n)
+static __always_inline void *__memcpy(void *to, const void *from, size_t n)
 {
-int d0, d1, d2;
-__asm__ __volatile__(
-       "rep ; movsl\n\t"
-       "movl %4,%%ecx\n\t"
-       "andl $3,%%ecx\n\t"
-       "jz 1f\n\t"
-       "rep ; movsb\n\t"
-       "1:"
-       : "=&c" (d0), "=&D" (d1), "=&S" (d2)
-       : "0" (n/4), "g" (n), "1" ((long) to), "2" ((long) from)
-       : "memory");
-return (to);
+       int d0, d1, d2;
+       asm volatile("rep ; movsl\n\t"
+                    "movl %4,%%ecx\n\t"
+                    "andl $3,%%ecx\n\t"
+                    "jz 1f\n\t"
+                    "rep ; movsb\n\t"
+                    "1:"
+                    : "=&c" (d0), "=&D" (d1), "=&S" (d2)
+                    : "0" (n / 4), "g" (n), "1" ((long)to), "2" ((long)from)
+                    : "memory");
+       return to;
 }
 
 /*
  * This looks ugly, but the compiler can optimize it totally,
  * as the count is constant.
  */
-static __always_inline void * __constant_memcpy(void * to, const void * from, size_t n)
+static __always_inline void *__constant_memcpy(void *to, const void *from,
+                                              size_t n)
 {
        long esi, edi;
-       if (!n) return to;
-#if 1  /* want to do small copies with non-string ops? */
+       if (!n)
+               return to;
+
        switch (n) {
-               case 1: *(char*)to = *(char*)from; return to;
-               case 2: *(short*)to = *(short*)from; return to;
-               case 4: *(int*)to = *(int*)from; return to;
-#if 1  /* including those doable with two moves? */
-               case 3: *(short*)to = *(short*)from;
-                       *((char*)to+2) = *((char*)from+2); return to;
-               case 5: *(int*)to = *(int*)from;
-                       *((char*)to+4) = *((char*)from+4); return to;
-               case 6: *(int*)to = *(int*)from;
-                       *((short*)to+2) = *((short*)from+2); return to;
-               case 8: *(int*)to = *(int*)from;
-                       *((int*)to+1) = *((int*)from+1); return to;
-#endif
+       case 1:
+               *(char *)to = *(char *)from;
+               return to;
+       case 2:
+               *(short *)to = *(short *)from;
+               return to;
+       case 4:
+               *(int *)to = *(int *)from;
+               return to;
+
+       case 3:
+               *(short *)to = *(short *)from;
+               *((char *)to + 2) = *((char *)from + 2);
+               return to;
+       case 5:
+               *(int *)to = *(int *)from;
+               *((char *)to + 4) = *((char *)from + 4);
+               return to;
+       case 6:
+               *(int *)to = *(int *)from;
+               *((short *)to + 2) = *((short *)from + 2);
+               return to;
+       case 8:
+               *(int *)to = *(int *)from;
+               *((int *)to + 1) = *((int *)from + 1);
+               return to;
        }
-#endif
-       esi = (long) from;
-       edi = (long) to;
-       if (n >= 5*4) {
+
+       esi = (long)from;
+       edi = (long)to;
+       if (n >= 5 * 4) {
                /* large block: use rep prefix */
                int ecx;
-               __asm__ __volatile__(
-                       "rep ; movsl"
-                       : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
-                       : "0" (n/4), "1" (edi),"2" (esi)
-                       : "memory"
+               asm volatile("rep ; movsl"
+                            : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
+                            : "0" (n / 4), "1" (edi), "2" (esi)
+                            : "memory"
                );
        } else {
                /* small block: don't clobber ecx + smaller code */
-               if (n >= 4*4) __asm__ __volatile__("movsl"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-               if (n >= 3*4) __asm__ __volatile__("movsl"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-               if (n >= 2*4) __asm__ __volatile__("movsl"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-               if (n >= 1*4) __asm__ __volatile__("movsl"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
+               if (n >= 4 * 4)
+                       asm volatile("movsl"
+                                    : "=&D"(edi), "=&S"(esi)
+                                    : "0"(edi), "1"(esi)
+                                    : "memory");
+               if (n >= 3 * 4)
+                       asm volatile("movsl"
+                                    : "=&D"(edi), "=&S"(esi)
+                                    : "0"(edi), "1"(esi)
+                                    : "memory");
+               if (n >= 2 * 4)
+                       asm volatile("movsl"
+                                    : "=&D"(edi), "=&S"(esi)
+                                    : "0"(edi), "1"(esi)
+                                    : "memory");
+               if (n >= 1 * 4)
+                       asm volatile("movsl"
+                                    : "=&D"(edi), "=&S"(esi)
+                                    : "0"(edi), "1"(esi)
+                                    : "memory");
        }
        switch (n % 4) {
                /* tail */
-               case 0: return to;
-               case 1: __asm__ __volatile__("movsb"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-                       return to;
-               case 2: __asm__ __volatile__("movsw"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-                       return to;
-               default: __asm__ __volatile__("movsw\n\tmovsb"
-                       :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
-                       return to;
+       case 0:
+               return to;
+       case 1:
+               asm volatile("movsb"
+                            : "=&D"(edi), "=&S"(esi)
+                            : "0"(edi), "1"(esi)
+                            : "memory");
+               return to;
+       case 2:
+               asm volatile("movsw"
+                            : "=&D"(edi), "=&S"(esi)
+                            : "0"(edi), "1"(esi)
+                            : "memory");
+               return to;
+       default:
+               asm volatile("movsw\n\tmovsb"
+                            : "=&D"(edi), "=&S"(esi)
+                            : "0"(edi), "1"(esi)
+                            : "memory");
+               return to;
        }
 }
 
@@ -117,87 +152,86 @@ static __always_inline void * __constant_memcpy(void * to, const void * from, si
  *     This CPU favours 3DNow strongly (eg AMD Athlon)
  */
 
-static inline void * __constant_memcpy3d(void * to, const void * from, size_t len)
+static inline void *__constant_memcpy3d(void *to, const void *from, size_t len)
 {
        if (len < 512)
                return __constant_memcpy(to, from, len);
        return _mmx_memcpy(to, from, len);
 }
 
-static __inline__ void *__memcpy3d(void *to, const void *from, size_t len)
+static inline void *__memcpy3d(void *to, const void *from, size_t len)
 {
        if (len < 512)
                return __memcpy(to, from, len);
        return _mmx_memcpy(to, from, len);
 }
 
-#define memcpy(t, f, n) \
-(__builtin_constant_p(n) ? \
__constant_memcpy3d((t),(f),(n)) : \
__memcpy3d((t),(f),(n)))
+#define memcpy(t, f, n)                                \
+       (__builtin_constant_p((n))              \
       ? __constant_memcpy3d((t), (f), (n))   \
       : __memcpy3d((t), (f), (n)))
 
 #else
 
 /*
  *     No 3D Now!
  */
-#define memcpy(t, f, n) \
-(__builtin_constant_p(n) ? \
__constant_memcpy((t),(f),(n)) : \
__memcpy((t),(f),(n)))
+
+#define memcpy(t, f, n)                                \
+       (__builtin_constant_p((n))              \
       ? __constant_memcpy((t), (f), (n))     \
       : __memcpy((t), (f), (n)))
 
 #endif
 
 #define __HAVE_ARCH_MEMMOVE
-void *memmove(void * dest,const void * src, size_t n);
+void *memmove(void *dest, const void *src, size_t n);
 
 #define memcmp __builtin_memcmp
 
 #define __HAVE_ARCH_MEMCHR
-extern void *memchr(const void * cs,int c,size_t count);
+extern void *memchr(const void *cs, int c, size_t count);
 
-static inline void * __memset_generic(void * s, char c,size_t count)
+static inline void *__memset_generic(void *s, char c, size_t count)
 {
-int d0, d1;
-__asm__ __volatile__(
-       "rep\n\t"
-       "stosb"
-       : "=&c" (d0), "=&D" (d1)
-       :"a" (c),"1" (s),"0" (count)
-       :"memory");
-return s;
+       int d0, d1;
+       asm volatile("rep\n\t"
+                    "stosb"
+                    : "=&c" (d0), "=&D" (d1)
+                    : "a" (c), "1" (s), "0" (count)
+                    : "memory");
+       return s;
 }
 
 /* we might want to write optimized versions of these later */
-#define __constant_count_memset(s,c,count) __memset_generic((s),(c),(count))
+#define __constant_count_memset(s, c, count) __memset_generic((s), (c), (count))
 
 /*
- * memset(x,0,y) is a reasonably common thing to do, so we want to fill
+ * memset(x, 0, y) is a reasonably common thing to do, so we want to fill
  * things 32 bits at a time even when we don't know the size of the
  * area at compile-time..
  */
-static __always_inline void * __constant_c_memset(void * s, unsigned long c, size_t count)
+static __always_inline
+void *__constant_c_memset(void *s, unsigned long c, size_t count)
 {
-int d0, d1;
-__asm__ __volatile__(
-       "rep ; stosl\n\t"
-       "testb $2,%b3\n\t"
-       "je 1f\n\t"
-       "stosw\n"
-       "1:\ttestb $1,%b3\n\t"
-       "je 2f\n\t"
-       "stosb\n"
-       "2:"
-       :"=&c" (d0), "=&D" (d1)
-       :"a" (c), "q" (count), "0" (count/4), "1" ((long) s)
-       :"memory");
-return (s);    
+       int d0, d1;
+       asm volatile("rep ; stosl\n\t"
+                    "testb $2,%b3\n\t"
+                    "je 1f\n\t"
+                    "stosw\n"
+                    "1:\ttestb $1,%b3\n\t"
+                    "je 2f\n\t"
+                    "stosb\n"
+                    "2:"
+                    : "=&c" (d0), "=&D" (d1)
+                    : "a" (c), "q" (count), "0" (count/4), "1" ((long)s)
+                    : "memory");
+       return s;
 }
 
 /* Added by Gertjan van Wingerde to make minix and sysv module work */
 #define __HAVE_ARCH_STRNLEN
-extern size_t strnlen(const char * s, size_t count);
+extern size_t strnlen(const char *s, size_t count);
 /* end of additional stuff */
 
 #define __HAVE_ARCH_STRSTR
@@ -207,66 +241,85 @@ extern char *strstr(const char *cs, const char *ct);
  * This looks horribly ugly, but the compiler can optimize it totally,
  * as we by now know that both pattern and count is constant..
  */
-static __always_inline void * __constant_c_and_count_memset(void * s, unsigned long pattern, size_t count)
+static __always_inline
+void *__constant_c_and_count_memset(void *s, unsigned long pattern,
+                                   size_t count)
 {
        switch (count) {
+       case 0:
+               return s;
+       case 1:
+               *(unsigned char *)s = pattern & 0xff;
+               return s;
+       case 2:
+               *(unsigned short *)s = pattern & 0xffff;
+               return s;
+       case 3:
+               *(unsigned short *)s = pattern & 0xffff;
+               *((unsigned char *)s + 2) = pattern & 0xff;
+               return s;
+       case 4:
+               *(unsigned long *)s = pattern;
+               return s;
+       }
+
+#define COMMON(x)                                                      \
+       asm volatile("rep ; stosl"                                      \
+                    x                                                  \
+                    : "=&c" (d0), "=&D" (d1)                           \
+                    : "a" (eax), "0" (count/4), "1" ((long)s)  \
+                    : "memory")
+
+       {
+               int d0, d1;
+#if __GNUC__ == 4 && __GNUC_MINOR__ == 0
+               /* Workaround for broken gcc 4.0 */
+               register unsigned long eax asm("%eax") = pattern;
+#else
+               unsigned long eax = pattern;
+#endif
+
+               switch (count % 4) {
                case 0:
+                       COMMON("");
                        return s;
                case 1:
-                       *(unsigned char *)s = pattern & 0xff;
+                       COMMON("\n\tstosb");
                        return s;
                case 2:
-                       *(unsigned short *)s = pattern & 0xffff;
+                       COMMON("\n\tstosw");
                        return s;
-               case 3:
-                       *(unsigned short *)s = pattern & 0xffff;
-                       *(2+(unsigned char *)s) = pattern & 0xff;
-                       return s;
-               case 4:
-                       *(unsigned long *)s = pattern;
+               default:
+                       COMMON("\n\tstosw\n\tstosb");
                        return s;
+               }
        }
-#define COMMON(x) \
-__asm__  __volatile__( \
-       "rep ; stosl" \
-       x \
-       : "=&c" (d0), "=&D" (d1) \
-       : "a" (pattern),"0" (count/4),"1" ((long) s) \
-       : "memory")
-{
-       int d0, d1;
-       switch (count % 4) {
-               case 0: COMMON(""); return s;
-               case 1: COMMON("\n\tstosb"); return s;
-               case 2: COMMON("\n\tstosw"); return s;
-               default: COMMON("\n\tstosw\n\tstosb"); return s;
-       }
-}
-  
+
 #undef COMMON
 }
 
-#define __constant_c_x_memset(s, c, count) \
-(__builtin_constant_p(count) ? \
__constant_c_and_count_memset((s),(c),(count)) : \
__constant_c_memset((s),(c),(count)))
+#define __constant_c_x_memset(s, c, count)                     \
+       (__builtin_constant_p(count)                            \
       ? __constant_c_and_count_memset((s), (c), (count))     \
       : __constant_c_memset((s), (c), (count)))
 
-#define __memset(s, c, count) \
-(__builtin_constant_p(count) ? \
__constant_count_memset((s),(c),(count)) : \
__memset_generic((s),(c),(count)))
+#define __memset(s, c, count)                          \
+       (__builtin_constant_p(count)                    \
       ? __constant_count_memset((s), (c), (count))   \
       : __memset_generic((s), (c), (count)))
 
 #define __HAVE_ARCH_MEMSET
-#define memset(s, c, count) \
-(__builtin_constant_p(c) ? \
- __constant_c_x_memset((s),(0x01010101UL*(unsigned char)(c)),(count)) : \
- __memset((s),(c),(count)))
+#define memset(s, c, count)                                            \
+       (__builtin_constant_p(c)                                        \
+        ? __constant_c_x_memset((s), (0x01010101UL * (unsigned char)(c)), \
+                                (count))                               \
+        : __memset((s), (c), (count)))
 
 /*
  * find the first occurrence of byte 'c', or 1 past the area if none
  */
 #define __HAVE_ARCH_MEMSCAN
-extern void *memscan(void * addr, int c, size_t size);
+extern void *memscan(void *addr, int c, size_t size);
 
 #endif /* __KERNEL__ */
 
index 24e1c08..8675c67 100644 (file)
@@ -3,6 +3,9 @@
  * Based on code
  * Copyright 2001 Patrick Mochel <mochel@osdl.org>
  */
+#ifndef __ASM_X86_32_SUSPEND_H
+#define __ASM_X86_32_SUSPEND_H
+
 #include <asm/desc.h>
 #include <asm/i387.h>
 
@@ -44,3 +47,5 @@ static inline void acpi_save_register_state(unsigned long return_point)
 /* routines for saving/restoring kernel state */
 extern int acpi_save_state_mem(void);
 #endif
+
+#endif /* __ASM_X86_32_SUSPEND_H */
index a2f04cd..983ce37 100644 (file)
@@ -136,7 +136,7 @@ __asm__ __volatile__ ("movw %%dx,%1\n\t" \
 #define set_base(ldt, base) _set_base(((char *)&(ldt)) , (base))
 #define set_limit(ldt, limit) _set_limit(((char *)&(ldt)) , ((limit)-1))
 
-extern void load_gs_index(unsigned);
+extern void native_load_gs_index(unsigned);
 
 /*
  * Load a segment. Fall back on loading the zero
@@ -153,14 +153,14 @@ extern void load_gs_index(unsigned);
                     "jmp 2b\n"                 \
                     ".previous\n"              \
                     _ASM_EXTABLE(1b,3b)        \
-                    : :"r" (value), "r" (0))
+                    : :"r" (value), "r" (0) : "memory")
 
 
 /*
  * Save a segment register away
  */
 #define savesegment(seg, value)                                \
-       asm volatile("mov %%" #seg ",%0":"=rm" (value))
+       asm("mov %%" #seg ",%0":"=r" (value) : : "memory")
 
 static inline unsigned long get_limit(unsigned long segment)
 {
@@ -282,6 +282,7 @@ static inline void native_wbinvd(void)
 #ifdef CONFIG_X86_64
 #define read_cr8()     (native_read_cr8())
 #define write_cr8(x)   (native_write_cr8(x))
+#define load_gs_index   native_load_gs_index
 #endif
 
 /* Clear the 'TS' bit */
@@ -289,7 +290,7 @@ static inline void native_wbinvd(void)
 
 #endif/* CONFIG_PARAVIRT */
 
-#define stts() write_cr0(8 | read_cr0())
+#define stts() write_cr0(read_cr0() | X86_CR0_TS)
 
 #endif /* __KERNEL__ */
 
@@ -303,7 +304,6 @@ static inline void clflush(volatile void *__p)
 void disable_hlt(void);
 void enable_hlt(void);
 
-extern int es7000_plat;
 void cpu_idle_wait(void);
 
 extern unsigned long arch_align_stack(unsigned long sp);
index 77244f1..895339d 100644 (file)
@@ -1,9 +1,253 @@
+/* thread_info.h: low-level thread information
+ *
+ * Copyright (C) 2002  David Howells (dhowells@redhat.com)
+ * - Incorporating suggestions made by Linus Torvalds and Dave Miller
+ */
+
 #ifndef _ASM_X86_THREAD_INFO_H
+#define _ASM_X86_THREAD_INFO_H
+
+#include <linux/compiler.h>
+#include <asm/page.h>
+#include <asm/types.h>
+
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct shares the supervisor stack pages
+ */
+#ifndef __ASSEMBLY__
+struct task_struct;
+struct exec_domain;
+#include <asm/processor.h>
+
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
+       struct exec_domain      *exec_domain;   /* execution domain */
+       unsigned long           flags;          /* low level flags */
+       __u32                   status;         /* thread synchronous flags */
+       __u32                   cpu;            /* current CPU */
+       int                     preempt_count;  /* 0 => preemptable,
+                                                  <0 => BUG */
+       mm_segment_t            addr_limit;
+       struct restart_block    restart_block;
+       void __user             *sysenter_return;
+#ifdef CONFIG_X86_32
+       unsigned long           previous_esp;   /* ESP of the previous stack in
+                                                  case of nested (IRQ) stacks
+                                               */
+       __u8                    supervisor_stack[0];
+#endif
+};
+
+#define INIT_THREAD_INFO(tsk)                  \
+{                                              \
+       .task           = &tsk,                 \
+       .exec_domain    = &default_exec_domain, \
+       .flags          = 0,                    \
+       .cpu            = 0,                    \
+       .preempt_count  = 1,                    \
+       .addr_limit     = KERNEL_DS,            \
+       .restart_block = {                      \
+               .fn = do_no_restart_syscall,    \
+       },                                      \
+}
+
+#define init_thread_info       (init_thread_union.thread_info)
+#define init_stack             (init_thread_union.stack)
+
+#else /* !__ASSEMBLY__ */
+
+#include <asm/asm-offsets.h>
+
+#endif
+
+/*
+ * thread information flags
+ * - these are process state flags that various assembly files
+ *   may need to access
+ * - pending work-to-be-done flags are in LSW
+ * - other flags in MSW
+ * Warning: layout of LSW is hardcoded in entry.S
+ */
+#define TIF_SYSCALL_TRACE      0       /* syscall trace active */
+#define TIF_SIGPENDING         2       /* signal pending */
+#define TIF_NEED_RESCHED       3       /* rescheduling necessary */
+#define TIF_SINGLESTEP         4       /* reenable singlestep on user return*/
+#define TIF_IRET               5       /* force IRET */
 #ifdef CONFIG_X86_32
-# include "thread_info_32.h"
+#define TIF_SYSCALL_EMU                6       /* syscall emulation active */
+#endif
+#define TIF_SYSCALL_AUDIT      7       /* syscall auditing active */
+#define TIF_SECCOMP            8       /* secure computing */
+#define TIF_MCE_NOTIFY         10      /* notify userspace of an MCE */
+#define TIF_HRTICK_RESCHED     11      /* reprogram hrtick timer */
+#define TIF_NOTSC              16      /* TSC is not accessible in userland */
+#define TIF_IA32               17      /* 32bit process */
+#define TIF_FORK               18      /* ret_from_fork */
+#define TIF_ABI_PENDING                19
+#define TIF_MEMDIE             20
+#define TIF_DEBUG              21      /* uses debug registers */
+#define TIF_IO_BITMAP          22      /* uses I/O bitmap */
+#define TIF_FREEZE             23      /* is freezing for suspend */
+#define TIF_FORCED_TF          24      /* true if TF in eflags artificially */
+#define TIF_DEBUGCTLMSR                25      /* uses thread_struct.debugctlmsr */
+#define TIF_DS_AREA_MSR                26      /* uses thread_struct.ds_area_msr */
+#define TIF_BTS_TRACE_TS       27      /* record scheduling event timestamps */
+
+#define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
+#define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
+#define _TIF_SINGLESTEP                (1 << TIF_SINGLESTEP)
+#define _TIF_NEED_RESCHED      (1 << TIF_NEED_RESCHED)
+#define _TIF_IRET              (1 << TIF_IRET)
+#ifdef CONFIG_X86_32
+#define _TIF_SYSCALL_EMU       (1 << TIF_SYSCALL_EMU)
 #else
-# include "thread_info_64.h"
+#define _TIF_SYSCALL_EMU       0
 #endif
+#define _TIF_SYSCALL_AUDIT     (1 << TIF_SYSCALL_AUDIT)
+#define _TIF_SECCOMP           (1 << TIF_SECCOMP)
+#define _TIF_MCE_NOTIFY                (1 << TIF_MCE_NOTIFY)
+#define _TIF_HRTICK_RESCHED    (1 << TIF_HRTICK_RESCHED)
+#define _TIF_NOTSC             (1 << TIF_NOTSC)
+#define _TIF_IA32              (1 << TIF_IA32)
+#define _TIF_FORK              (1 << TIF_FORK)
+#define _TIF_ABI_PENDING       (1 << TIF_ABI_PENDING)
+#define _TIF_DEBUG             (1 << TIF_DEBUG)
+#define _TIF_IO_BITMAP         (1 << TIF_IO_BITMAP)
+#define _TIF_FREEZE            (1 << TIF_FREEZE)
+#define _TIF_FORCED_TF         (1 << TIF_FORCED_TF)
+#define _TIF_DEBUGCTLMSR       (1 << TIF_DEBUGCTLMSR)
+#define _TIF_DS_AREA_MSR       (1 << TIF_DS_AREA_MSR)
+#define _TIF_BTS_TRACE_TS      (1 << TIF_BTS_TRACE_TS)
+
+/* work to do on interrupt/exception return */
+#define _TIF_WORK_MASK                                                 \
+       (0x0000FFFF &                                                   \
+        ~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP|       \
+        _TIF_SECCOMP|_TIF_SYSCALL_EMU))
+
+/* work to do on any return to user space */
+#define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP)
+
+/* Only used for 64 bit */
+#define _TIF_DO_NOTIFY_MASK                                            \
+       (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED)
+
+/* flags to check in __switch_to() */
+#define _TIF_WORK_CTXSW                                                        \
+       (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_BTS_TRACE_TS| \
+                                                               _TIF_NOTSC)
+
+#define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
+#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
+
+#define PREEMPT_ACTIVE         0x10000000
+
+/* thread information allocation */
+#ifdef CONFIG_DEBUG_STACK_USAGE
+#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
+#else
+#define THREAD_FLAGS GFP_KERNEL
+#endif
+
+#define alloc_thread_info(tsk)                                         \
+       ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
+
+#ifdef CONFIG_X86_32
+
+#define STACK_WARN     (THREAD_SIZE/8)
+/*
+ * macros/functions for gaining access to the thread information structure
+ *
+ * preempt_count needs to be 1 initially, until the scheduler is functional.
+ */
+#ifndef __ASSEMBLY__
+
+
+/* how to get the current stack pointer from C */
+register unsigned long current_stack_pointer asm("esp") __used;
+
+/* how to get the thread information struct from C */
+static inline struct thread_info *current_thread_info(void)
+{
+       return (struct thread_info *)
+               (current_stack_pointer & ~(THREAD_SIZE - 1));
+}
+
+#else /* !__ASSEMBLY__ */
+
+/* how to get the thread information struct from ASM */
+#define GET_THREAD_INFO(reg)    \
+       movl $-THREAD_SIZE, reg; \
+       andl %esp, reg
+
+/* use this one if reg already contains %esp */
+#define GET_THREAD_INFO_WITH_ESP(reg) \
+       andl $-THREAD_SIZE, reg
+
+#endif
+
+#else /* X86_32 */
+
+#include <asm/pda.h>
+
+/*
+ * macros/functions for gaining access to the thread information structure
+ * preempt_count needs to be 1 initially, until the scheduler is functional.
+ */
+#ifndef __ASSEMBLY__
+static inline struct thread_info *current_thread_info(void)
+{
+       struct thread_info *ti;
+       ti = (void *)(read_pda(kernelstack) + PDA_STACKOFFSET - THREAD_SIZE);
+       return ti;
+}
+
+/* do not use in interrupt context */
+static inline struct thread_info *stack_thread_info(void)
+{
+       struct thread_info *ti;
+       asm("andq %%rsp,%0; " : "=r" (ti) : "0" (~(THREAD_SIZE - 1)));
+       return ti;
+}
+
+#else /* !__ASSEMBLY__ */
+
+/* how to get the thread information struct from ASM */
+#define GET_THREAD_INFO(reg) \
+       movq %gs:pda_kernelstack,reg ; \
+       subq $(THREAD_SIZE-PDA_STACKOFFSET),reg
+
+#endif
+
+#endif /* !X86_32 */
+
+/*
+ * Thread-synchronous status.
+ *
+ * This is different from the flags in that nobody else
+ * ever touches our thread-synchronous status, so we don't
+ * have to worry about atomic accesses.
+ */
+#define TS_USEDFPU             0x0001  /* FPU was used by this task
+                                          this quantum (SMP) */
+#define TS_COMPAT              0x0002  /* 32bit syscall active (64BIT)*/
+#define TS_POLLING             0x0004  /* true if in idle loop
+                                          and not sleeping */
+#define TS_RESTORE_SIGMASK     0x0008  /* restore signal mask in do_signal() */
+
+#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
+
+#ifndef __ASSEMBLY__
+#define HAVE_SET_RESTORE_SIGMASK       1
+static inline void set_restore_sigmask(void)
+{
+       struct thread_info *ti = current_thread_info();
+       ti->status |= TS_RESTORE_SIGMASK;
+       set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags);
+}
+#endif /* !__ASSEMBLY__ */
 
 #ifndef __ASSEMBLY__
 extern void arch_task_cache_init(void);
diff --git a/include/asm-x86/thread_info_32.h b/include/asm-x86/thread_info_32.h
deleted file mode 100644 (file)
index b633882..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/* thread_info.h: i386 low-level thread information
- *
- * Copyright (C) 2002  David Howells (dhowells@redhat.com)
- * - Incorporating suggestions made by Linus Torvalds and Dave Miller
- */
-
-#ifndef _ASM_THREAD_INFO_H
-#define _ASM_THREAD_INFO_H
-
-#ifdef __KERNEL__
-
-#include <linux/compiler.h>
-#include <asm/page.h>
-
-#ifndef __ASSEMBLY__
-#include <asm/processor.h>
-#endif
-
-/*
- * low level task data that entry.S needs immediate access to
- * - this struct should fit entirely inside of one cache line
- * - this struct shares the supervisor stack pages
- * - if the contents of this structure are changed,
- *   the assembly constants must also be changed
- */
-#ifndef __ASSEMBLY__
-
-struct thread_info {
-       struct task_struct      *task;          /* main task structure */
-       struct exec_domain      *exec_domain;   /* execution domain */
-       unsigned long           flags;          /* low level flags */
-       unsigned long           status;         /* thread-synchronous flags */
-       __u32                   cpu;            /* current CPU */
-       int                     preempt_count;  /* 0 => preemptable,
-                                                  <0 => BUG */
-       mm_segment_t            addr_limit;     /* thread address space:
-                                                  0-0xBFFFFFFF user-thread
-                                                  0-0xFFFFFFFF kernel-thread
-                                               */
-       void                    *sysenter_return;
-       struct restart_block    restart_block;
-       unsigned long           previous_esp;   /* ESP of the previous stack in
-                                                  case of nested (IRQ) stacks
-                                               */
-       __u8                    supervisor_stack[0];
-};
-
-#else /* !__ASSEMBLY__ */
-
-#include <asm/asm-offsets.h>
-
-#endif
-
-#define PREEMPT_ACTIVE         0x10000000
-#ifdef CONFIG_4KSTACKS
-#define THREAD_SIZE            (4096)
-#else
-#define THREAD_SIZE            (8192)
-#endif
-
-#define STACK_WARN             (THREAD_SIZE/8)
-/*
- * macros/functions for gaining access to the thread information structure
- *
- * preempt_count needs to be 1 initially, until the scheduler is functional.
- */
-#ifndef __ASSEMBLY__
-
-#define INIT_THREAD_INFO(tsk)                  \
-{                                              \
-       .task           = &tsk,                 \
-       .exec_domain    = &default_exec_domain, \
-       .flags          = 0,                    \
-       .cpu            = 0,                    \
-       .preempt_count  = 1,                    \
-       .addr_limit     = KERNEL_DS,            \
-       .restart_block = {                      \
-               .fn = do_no_restart_syscall,    \
-       },                                      \
-}
-
-#define init_thread_info       (init_thread_union.thread_info)
-#define init_stack             (init_thread_union.stack)
-
-
-/* how to get the current stack pointer from C */
-register unsigned long current_stack_pointer asm("esp") __used;
-
-/* how to get the thread information struct from C */
-static inline struct thread_info *current_thread_info(void)
-{
-       return (struct thread_info *)
-               (current_stack_pointer & ~(THREAD_SIZE - 1));
-}
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define alloc_thread_info(tsk) ((struct thread_info *)                 \
-       __get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(THREAD_SIZE)))
-#else
-#define alloc_thread_info(tsk) ((struct thread_info *)                 \
-       __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE)))
-#endif
-
-#else /* !__ASSEMBLY__ */
-
-/* how to get the thread information struct from ASM */
-#define GET_THREAD_INFO(reg)    \
-       movl $-THREAD_SIZE, reg; \
-       andl %esp, reg
-
-/* use this one if reg already contains %esp */
-#define GET_THREAD_INFO_WITH_ESP(reg) \
-       andl $-THREAD_SIZE, reg
-
-#endif
-
-/*
- * thread information flags
- * - these are process state flags that various
- *   assembly files may need to access
- * - pending work-to-be-done flags are in LSW
- * - other flags in MSW
- */
-#define TIF_SYSCALL_TRACE      0       /* syscall trace active */
-#define TIF_SIGPENDING         1       /* signal pending */
-#define TIF_NEED_RESCHED       2       /* rescheduling necessary */
-#define TIF_SINGLESTEP         3       /* restore singlestep on return to
-                                          user mode */
-#define TIF_IRET               4       /* return with iret */
-#define TIF_SYSCALL_EMU                5       /* syscall emulation active */
-#define TIF_SYSCALL_AUDIT      6       /* syscall auditing active */
-#define TIF_SECCOMP            7       /* secure computing */
-#define TIF_HRTICK_RESCHED     9       /* reprogram hrtick timer */
-#define TIF_MEMDIE             16
-#define TIF_DEBUG              17      /* uses debug registers */
-#define TIF_IO_BITMAP          18      /* uses I/O bitmap */
-#define TIF_FREEZE             19      /* is freezing for suspend */
-#define TIF_NOTSC              20      /* TSC is not accessible in userland */
-#define TIF_FORCED_TF          21      /* true if TF in eflags artificially */
-#define TIF_DEBUGCTLMSR                22      /* uses thread_struct.debugctlmsr */
-#define TIF_DS_AREA_MSR        23      /* uses thread_struct.ds_area_msr */
-#define TIF_BTS_TRACE_TS        24      /* record scheduling event timestamps */
-
-#define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
-#define _TIF_NEED_RESCHED      (1 << TIF_NEED_RESCHED)
-#define _TIF_SINGLESTEP                (1 << TIF_SINGLESTEP)
-#define _TIF_IRET              (1 << TIF_IRET)
-#define _TIF_SYSCALL_EMU       (1 << TIF_SYSCALL_EMU)
-#define _TIF_SYSCALL_AUDIT     (1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP           (1 << TIF_SECCOMP)
-#define _TIF_HRTICK_RESCHED    (1 << TIF_HRTICK_RESCHED)
-#define _TIF_DEBUG             (1 << TIF_DEBUG)
-#define _TIF_IO_BITMAP         (1 << TIF_IO_BITMAP)
-#define _TIF_FREEZE            (1 << TIF_FREEZE)
-#define _TIF_NOTSC             (1 << TIF_NOTSC)
-#define _TIF_FORCED_TF         (1 << TIF_FORCED_TF)
-#define _TIF_DEBUGCTLMSR       (1 << TIF_DEBUGCTLMSR)
-#define _TIF_DS_AREA_MSR       (1 << TIF_DS_AREA_MSR)
-#define _TIF_BTS_TRACE_TS      (1 << TIF_BTS_TRACE_TS)
-
-/* work to do on interrupt/exception return */
-#define _TIF_WORK_MASK                                                 \
-       (0x0000FFFF & ~(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT |       \
-                       _TIF_SECCOMP | _TIF_SYSCALL_EMU))
-/* work to do on any return to u-space */
-#define _TIF_ALLWORK_MASK      (0x0000FFFF & ~_TIF_SECCOMP)
-
-/* flags to check in __switch_to() */
-#define _TIF_WORK_CTXSW                                                \
-       (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUGCTLMSR |       \
-        _TIF_DS_AREA_MSR | _TIF_BTS_TRACE_TS)
-#define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
-#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW | _TIF_DEBUG)
-
-
-/*
- * Thread-synchronous status.
- *
- * This is different from the flags in that nobody else
- * ever touches our thread-synchronous status, so we don't
- * have to worry about atomic accesses.
- */
-#define TS_USEDFPU             0x0001  /* FPU was used by this task
-                                          this quantum (SMP) */
-#define TS_POLLING             0x0002  /* True if in idle loop
-                                          and not sleeping */
-#define TS_RESTORE_SIGMASK     0x0004  /* restore signal mask in do_signal() */
-
-#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
-
-#ifndef __ASSEMBLY__
-#define HAVE_SET_RESTORE_SIGMASK       1
-static inline void set_restore_sigmask(void)
-{
-       struct thread_info *ti = current_thread_info();
-       ti->status |= TS_RESTORE_SIGMASK;
-       set_bit(TIF_SIGPENDING, &ti->flags);
-}
-#endif /* !__ASSEMBLY__ */
-
-#endif /* __KERNEL__ */
-
-#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-x86/thread_info_64.h b/include/asm-x86/thread_info_64.h
deleted file mode 100644 (file)
index cb69f70..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/* thread_info.h: x86_64 low-level thread information
- *
- * Copyright (C) 2002  David Howells (dhowells@redhat.com)
- * - Incorporating suggestions made by Linus Torvalds and Dave Miller
- */
-
-#ifndef _ASM_THREAD_INFO_H
-#define _ASM_THREAD_INFO_H
-
-#ifdef __KERNEL__
-
-#include <asm/page.h>
-#include <asm/types.h>
-#include <asm/pda.h>
-
-/*
- * low level task data that entry.S needs immediate access to
- * - this struct should fit entirely inside of one cache line
- * - this struct shares the supervisor stack pages
- */
-#ifndef __ASSEMBLY__
-struct task_struct;
-struct exec_domain;
-#include <asm/processor.h>
-
-struct thread_info {
-       struct task_struct      *task;          /* main task structure */
-       struct exec_domain      *exec_domain;   /* execution domain */
-       __u32                   flags;          /* low level flags */
-       __u32                   status;         /* thread synchronous flags */
-       __u32                   cpu;            /* current CPU */
-       int                     preempt_count;  /* 0 => preemptable,
-                                                  <0 => BUG */
-       mm_segment_t            addr_limit;
-       struct restart_block    restart_block;
-#ifdef CONFIG_IA32_EMULATION
-       void __user             *sysenter_return;
-#endif
-};
-#endif
-
-/*
- * macros/functions for gaining access to the thread information structure
- * preempt_count needs to be 1 initially, until the scheduler is functional.
- */
-#ifndef __ASSEMBLY__
-#define INIT_THREAD_INFO(tsk)                  \
-{                                              \
-       .task          = &tsk,                  \
-       .exec_domain   = &default_exec_domain,  \
-       .flags         = 0,                     \
-       .cpu           = 0,                     \
-       .preempt_count = 1,                     \
-       .addr_limit     = KERNEL_DS,            \
-       .restart_block = {                      \
-               .fn = do_no_restart_syscall,    \
-       },                                      \
-}
-
-#define init_thread_info       (init_thread_union.thread_info)
-#define init_stack             (init_thread_union.stack)
-
-static inline struct thread_info *current_thread_info(void)
-{
-       struct thread_info *ti;
-       ti = (void *)(read_pda(kernelstack) + PDA_STACKOFFSET - THREAD_SIZE);
-       return ti;
-}
-
-/* do not use in interrupt context */
-static inline struct thread_info *stack_thread_info(void)
-{
-       struct thread_info *ti;
-       asm("andq %%rsp,%0; " : "=r" (ti) : "0" (~(THREAD_SIZE - 1)));
-       return ti;
-}
-
-/* thread information allocation */
-#ifdef CONFIG_DEBUG_STACK_USAGE
-#define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
-#else
-#define THREAD_FLAGS GFP_KERNEL
-#endif
-
-#define alloc_thread_info(tsk)                                         \
-       ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
-
-#else /* !__ASSEMBLY__ */
-
-/* how to get the thread information struct from ASM */
-#define GET_THREAD_INFO(reg) \
-       movq %gs:pda_kernelstack,reg ; \
-       subq $(THREAD_SIZE-PDA_STACKOFFSET),reg
-
-#endif
-
-/*
- * thread information flags
- * - these are process state flags that various assembly files
- *   may need to access
- * - pending work-to-be-done flags are in LSW
- * - other flags in MSW
- * Warning: layout of LSW is hardcoded in entry.S
- */
-#define TIF_SYSCALL_TRACE      0       /* syscall trace active */
-#define TIF_SIGPENDING         2       /* signal pending */
-#define TIF_NEED_RESCHED       3       /* rescheduling necessary */
-#define TIF_SINGLESTEP         4       /* reenable singlestep on user return*/
-#define TIF_IRET               5       /* force IRET */
-#define TIF_SYSCALL_AUDIT      7       /* syscall auditing active */
-#define TIF_SECCOMP            8       /* secure computing */
-#define TIF_MCE_NOTIFY         10      /* notify userspace of an MCE */
-#define TIF_HRTICK_RESCHED     11      /* reprogram hrtick timer */
-/* 16 free */
-#define TIF_IA32               17      /* 32bit process */
-#define TIF_FORK               18      /* ret_from_fork */
-#define TIF_ABI_PENDING                19
-#define TIF_MEMDIE             20
-#define TIF_DEBUG              21      /* uses debug registers */
-#define TIF_IO_BITMAP          22      /* uses I/O bitmap */
-#define TIF_FREEZE             23      /* is freezing for suspend */
-#define TIF_FORCED_TF          24      /* true if TF in eflags artificially */
-#define TIF_DEBUGCTLMSR                25      /* uses thread_struct.debugctlmsr */
-#define TIF_DS_AREA_MSR                26      /* uses thread_struct.ds_area_msr */
-#define TIF_BTS_TRACE_TS       27      /* record scheduling event timestamps */
-#define TIF_NOTSC              28      /* TSC is not accessible in userland */
-
-#define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
-#define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
-#define _TIF_SINGLESTEP                (1 << TIF_SINGLESTEP)
-#define _TIF_NEED_RESCHED      (1 << TIF_NEED_RESCHED)
-#define _TIF_IRET              (1 << TIF_IRET)
-#define _TIF_SYSCALL_AUDIT     (1 << TIF_SYSCALL_AUDIT)
-#define _TIF_SECCOMP           (1 << TIF_SECCOMP)
-#define _TIF_MCE_NOTIFY                (1 << TIF_MCE_NOTIFY)
-#define _TIF_HRTICK_RESCHED    (1 << TIF_HRTICK_RESCHED)
-#define _TIF_IA32              (1 << TIF_IA32)
-#define _TIF_FORK              (1 << TIF_FORK)
-#define _TIF_ABI_PENDING       (1 << TIF_ABI_PENDING)
-#define _TIF_DEBUG             (1 << TIF_DEBUG)
-#define _TIF_IO_BITMAP         (1 << TIF_IO_BITMAP)
-#define _TIF_FREEZE            (1 << TIF_FREEZE)
-#define _TIF_FORCED_TF         (1 << TIF_FORCED_TF)
-#define _TIF_DEBUGCTLMSR       (1 << TIF_DEBUGCTLMSR)
-#define _TIF_DS_AREA_MSR       (1 << TIF_DS_AREA_MSR)
-#define _TIF_BTS_TRACE_TS      (1 << TIF_BTS_TRACE_TS)
-#define _TIF_NOTSC             (1 << TIF_NOTSC)
-
-/* work to do on interrupt/exception return */
-#define _TIF_WORK_MASK                                                 \
-       (0x0000FFFF &                                                   \
-        ~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP|_TIF_SECCOMP))
-/* work to do on any return to user space */
-#define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP)
-
-#define _TIF_DO_NOTIFY_MASK                                            \
-       (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED)
-
-/* flags to check in __switch_to() */
-#define _TIF_WORK_CTXSW                                                        \
-       (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_BTS_TRACE_TS|_TIF_NOTSC)
-#define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
-#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
-
-#define PREEMPT_ACTIVE     0x10000000
-
-/*
- * Thread-synchronous status.
- *
- * This is different from the flags in that nobody else
- * ever touches our thread-synchronous status, so we don't
- * have to worry about atomic accesses.
- */
-#define TS_USEDFPU             0x0001  /* FPU was used by this task
-                                          this quantum (SMP) */
-#define TS_COMPAT              0x0002  /* 32bit syscall active */
-#define TS_POLLING             0x0004  /* true if in idle loop
-                                          and not sleeping */
-#define TS_RESTORE_SIGMASK     0x0008  /* restore signal mask in do_signal() */
-
-#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
-
-#ifndef __ASSEMBLY__
-#define HAVE_SET_RESTORE_SIGMASK       1
-static inline void set_restore_sigmask(void)
-{
-       struct thread_info *ti = current_thread_info();
-       ti->status |= TS_RESTORE_SIGMASK;
-       set_bit(TIF_SIGPENDING, &ti->flags);
-}
-#endif /* !__ASSEMBLY__ */
-
-#endif /* __KERNEL__ */
-
-#endif /* _ASM_THREAD_INFO_H */
index bce72d7..a17fa47 100644 (file)
@@ -56,4 +56,6 @@ static inline int native_set_wallclock(unsigned long nowtime)
 
 #endif /* CONFIG_PARAVIRT */
 
+extern unsigned long __init calibrate_cpu(void);
+
 #endif
index 4f6fcb0..fb2a4dd 100644 (file)
@@ -7,14 +7,14 @@
 #define TICK_SIZE (tick_nsec / 1000)
 
 unsigned long long native_sched_clock(void);
-unsigned long native_calculate_cpu_khz(void);
+unsigned long native_calibrate_tsc(void);
 
 extern int timer_ack;
 extern int no_timer_check;
 extern int recalibrate_cpu_khz(void);
 
 #ifndef CONFIG_PARAVIRT
-#define calculate_cpu_khz() native_calculate_cpu_khz()
+#define calibrate_tsc() native_calibrate_tsc()
 #endif
 
 /* Accelerators for sched_clock()
index dcf3f81..90ac771 100644 (file)
 # endif
 #endif
 
+/* Node not present */
+#define NUMA_NO_NODE   (-1)
+
 #ifdef CONFIG_NUMA
 #include <linux/cpumask.h>
 #include <asm/mpspec.h>
 
-/* Mappings between logical cpu number and node number */
 #ifdef CONFIG_X86_32
-extern int cpu_to_node_map[];
-#else
-/* Returns the number of the current Node. */
-#define numa_node_id()         (early_cpu_to_node(raw_smp_processor_id()))
-#endif
-
-DECLARE_PER_CPU(int, x86_cpu_to_node_map);
-
-#ifdef CONFIG_SMP
-extern int x86_cpu_to_node_map_init[];
-extern void *x86_cpu_to_node_map_early_ptr;
-#else
-#define x86_cpu_to_node_map_early_ptr NULL
-#endif
 
+/* Mappings between node number and cpus on that node. */
 extern cpumask_t node_to_cpumask_map[];
 
-#define NUMA_NO_NODE   (-1)
+/* Mappings between logical cpu number and node number */
+extern int cpu_to_node_map[];
 
 /* Returns the number of the node containing CPU 'cpu' */
-#ifdef CONFIG_X86_32
-#define early_cpu_to_node(cpu) cpu_to_node(cpu)
 static inline int cpu_to_node(int cpu)
 {
        return cpu_to_node_map[cpu];
 }
+#define early_cpu_to_node(cpu) cpu_to_node(cpu)
 
-#else /* CONFIG_X86_64 */
-
-#ifdef CONFIG_SMP
-static inline int early_cpu_to_node(int cpu)
+/* Returns a bitmask of CPUs on Node 'node'.
+ *
+ * Side note: this function creates the returned cpumask on the stack
+ * so with a high NR_CPUS count, excessive stack space is used.  The
+ * node_to_cpumask_ptr function should be used whenever possible.
+ */
+static inline cpumask_t node_to_cpumask(int node)
 {
-       int *cpu_to_node_map = x86_cpu_to_node_map_early_ptr;
-
-       if (cpu_to_node_map)
-               return cpu_to_node_map[cpu];
-       else if (per_cpu_offset(cpu))
-               return per_cpu(x86_cpu_to_node_map, cpu);
-       else
-               return NUMA_NO_NODE;
+       return node_to_cpumask_map[node];
 }
-#else
-#define        early_cpu_to_node(cpu)  cpu_to_node(cpu)
-#endif
 
+#else /* CONFIG_X86_64 */
+
+/* Mappings between node number and cpus on that node. */
+extern cpumask_t *node_to_cpumask_map;
+
+/* Mappings between logical cpu number and node number */
+DECLARE_EARLY_PER_CPU(int, x86_cpu_to_node_map);
+
+/* Returns the number of the current Node. */
+#define numa_node_id()         read_pda(nodenumber)
+
+#ifdef CONFIG_DEBUG_PER_CPU_MAPS
+extern int cpu_to_node(int cpu);
+extern int early_cpu_to_node(int cpu);
+extern const cpumask_t *_node_to_cpumask_ptr(int node);
+extern cpumask_t node_to_cpumask(int node);
+
+#else  /* !CONFIG_DEBUG_PER_CPU_MAPS */
+
+/* Returns the number of the node containing CPU 'cpu' */
 static inline int cpu_to_node(int cpu)
 {
-#ifdef CONFIG_DEBUG_PER_CPU_MAPS
-       if (x86_cpu_to_node_map_early_ptr) {
-               printk("KERN_NOTICE cpu_to_node(%d): usage too early!\n",
-                      (int)cpu);
-               dump_stack();
-               return ((int *)x86_cpu_to_node_map_early_ptr)[cpu];
-       }
-#endif
        return per_cpu(x86_cpu_to_node_map, cpu);
 }
 
-#ifdef CONFIG_NUMA
+/* Same function but used if called before per_cpu areas are setup */
+static inline int early_cpu_to_node(int cpu)
+{
+       if (early_per_cpu_ptr(x86_cpu_to_node_map))
+               return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
+
+       return per_cpu(x86_cpu_to_node_map, cpu);
+}
 
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
+static inline const cpumask_t *_node_to_cpumask_ptr(int node)
+{
+       return &node_to_cpumask_map[node];
+}
+
+/* Returns a bitmask of CPUs on Node 'node'. */
+static inline cpumask_t node_to_cpumask(int node)
+{
+       return node_to_cpumask_map[node];
+}
+
+#endif /* !CONFIG_DEBUG_PER_CPU_MAPS */
+
+/* Replace default node_to_cpumask_ptr with optimized version */
 #define node_to_cpumask_ptr(v, node)           \
-               cpumask_t *v = &(node_to_cpumask_map[node])
+               const cpumask_t *v = _node_to_cpumask_ptr(node)
 
 #define node_to_cpumask_ptr_next(v, node)      \
-                          v = &(node_to_cpumask_map[node])
-#endif
+                          v = _node_to_cpumask_ptr(node)
 
 #endif /* CONFIG_X86_64 */
 
@@ -117,20 +131,6 @@ static inline int cpu_to_node(int cpu)
  */
 #define parent_node(node) (node)
 
-/* Returns a bitmask of CPUs on Node 'node'. */
-static inline cpumask_t node_to_cpumask(int node)
-{
-       return node_to_cpumask_map[node];
-}
-
-/* Returns the number of the first CPU on Node 'node'. */
-static inline int node_to_first_cpu(int node)
-{
-       cpumask_t mask = node_to_cpumask(node);
-
-       return first_cpu(mask);
-}
-
 #define pcibus_to_node(bus) __pcibus_to_node(bus)
 #define pcibus_to_cpumask(bus) __pcibus_to_cpumask(bus)
 
@@ -180,12 +180,44 @@ extern int __node_distance(int, int);
 #define node_distance(a, b) __node_distance(a, b)
 #endif
 
-#else /* CONFIG_NUMA */
+#else /* !CONFIG_NUMA */
 
+#define numa_node_id()         0
+#define        cpu_to_node(cpu)        0
+#define        early_cpu_to_node(cpu)  0
+
+static inline const cpumask_t *_node_to_cpumask_ptr(int node)
+{
+       return &cpu_online_map;
+}
+static inline cpumask_t node_to_cpumask(int node)
+{
+       return cpu_online_map;
+}
+static inline int node_to_first_cpu(int node)
+{
+       return first_cpu(cpu_online_map);
+}
+
+/* Replace default node_to_cpumask_ptr with optimized version */
+#define node_to_cpumask_ptr(v, node)           \
+               const cpumask_t *v = _node_to_cpumask_ptr(node)
+
+#define node_to_cpumask_ptr_next(v, node)      \
+                          v = _node_to_cpumask_ptr(node)
 #endif
 
 #include <asm-generic/topology.h>
 
+#ifdef CONFIG_NUMA
+/* Returns the number of the first CPU on Node 'node'. */
+static inline int node_to_first_cpu(int node)
+{
+       node_to_cpumask_ptr(mask, node);
+       return first_cpu(*mask);
+}
+#endif
+
 extern cpumask_t cpu_coregroup_map(int cpu);
 
 #ifdef ENABLE_TOPO_DEFINES
@@ -193,6 +225,9 @@ extern cpumask_t cpu_coregroup_map(int cpu);
 #define topology_core_id(cpu)                  (cpu_data(cpu).cpu_core_id)
 #define topology_core_siblings(cpu)            (per_cpu(cpu_core_map, cpu))
 #define topology_thread_siblings(cpu)          (per_cpu(cpu_sibling_map, cpu))
+
+/* indicates that pointers to the topology cpumask_t maps are valid */
+#define arch_provides_topology_pointers                yes
 #endif
 
 static inline void arch_fix_phys_package_id(int num, u32 slot)
@@ -220,4 +255,4 @@ static inline void set_mp_bus_to_node(int busnum, int node)
 }
 #endif
 
-#endif
+#endif /* _ASM_X86_TOPOLOGY_H */
index 548873a..cb6f6ee 100644 (file)
@@ -48,7 +48,6 @@ static __always_inline cycles_t vget_cycles(void)
 extern void tsc_init(void);
 extern void mark_tsc_unstable(char *reason);
 extern int unsynchronized_tsc(void);
-extern void init_tsc_clocksource(void);
 int check_tsc_unstable(void);
 
 /*
@@ -58,7 +57,6 @@ int check_tsc_unstable(void);
 extern void check_tsc_sync_source(int cpu);
 extern void check_tsc_sync_target(void);
 
-extern void tsc_calibrate(void);
 extern int notsc_setup(char *);
 
 #endif
index 9fefd29..f6fa4d8 100644 (file)
@@ -1,5 +1,453 @@
+#ifndef _ASM_UACCES_H_
+#define _ASM_UACCES_H_
+/*
+ * User space memory access functions
+ */
+#include <linux/errno.h>
+#include <linux/compiler.h>
+#include <linux/thread_info.h>
+#include <linux/prefetch.h>
+#include <linux/string.h>
+#include <asm/asm.h>
+#include <asm/page.h>
+
+#define VERIFY_READ 0
+#define VERIFY_WRITE 1
+
+/*
+ * The fs value determines whether argument validity checking should be
+ * performed or not.  If get_fs() == USER_DS, checking is performed, with
+ * get_fs() == KERNEL_DS, checking is bypassed.
+ *
+ * For historical reasons, these macros are grossly misnamed.
+ */
+
+#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
+
+#define KERNEL_DS      MAKE_MM_SEG(-1UL)
+#define USER_DS                MAKE_MM_SEG(PAGE_OFFSET)
+
+#define get_ds()       (KERNEL_DS)
+#define get_fs()       (current_thread_info()->addr_limit)
+#define set_fs(x)      (current_thread_info()->addr_limit = (x))
+
+#define segment_eq(a, b)       ((a).seg == (b).seg)
+
+#define __addr_ok(addr)                                        \
+       ((unsigned long __force)(addr) <                \
+        (current_thread_info()->addr_limit.seg))
+
+/*
+ * Test whether a block of memory is a valid user space address.
+ * Returns 0 if the range is valid, nonzero otherwise.
+ *
+ * This is equivalent to the following test:
+ * (u33)addr + (u33)size >= (u33)current->addr_limit.seg (u65 for x86_64)
+ *
+ * This needs 33-bit (65-bit for x86_64) arithmetic. We have a carry...
+ */
+
+#define __range_not_ok(addr, size)                                     \
+({                                                                     \
+       unsigned long flag, roksum;                                     \
+       __chk_user_ptr(addr);                                           \
+       asm("add %3,%1 ; sbb %0,%0 ; cmp %1,%4 ; sbb $0,%0"             \
+           : "=&r" (flag), "=r" (roksum)                               \
+           : "1" (addr), "g" ((long)(size)),                           \
+             "rm" (current_thread_info()->addr_limit.seg));            \
+       flag;                                                           \
+})
+
+/**
+ * access_ok: - Checks if a user space pointer is valid
+ * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
+ *        %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
+ *        to write to a block, it is always safe to read from it.
+ * @addr: User space pointer to start of block to check
+ * @size: Size of block to check
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * Checks if a pointer to a block of memory in user space is valid.
+ *
+ * Returns true (nonzero) if the memory block may be valid, false (zero)
+ * if it is definitely invalid.
+ *
+ * Note that, depending on architecture, this function probably just
+ * checks that the pointer is in the user space range - after calling
+ * this function, memory access functions may still return -EFAULT.
+ */
+#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue.  No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry {
+       unsigned long insn, fixup;
+};
+
+extern int fixup_exception(struct pt_regs *regs);
+
+/*
+ * These are the main single-value transfer routines.  They automatically
+ * use the right size if we just have the right pointer type.
+ *
+ * This gets kind of ugly. We want to return _two_ values in "get_user()"
+ * and yet we don't want to do any pointers, because that is too much
+ * of a performance impact. Thus we have a few rather ugly macros here,
+ * and hide all the ugliness from the user.
+ *
+ * The "__xxx" versions of the user access functions are versions that
+ * do not verify the address space, that must have been done previously
+ * with a separate "access_ok()" call (this is used when we do multiple
+ * accesses to the same area of user memory).
+ */
+
+extern int __get_user_1(void);
+extern int __get_user_2(void);
+extern int __get_user_4(void);
+extern int __get_user_8(void);
+extern int __get_user_bad(void);
+
+#define __get_user_x(size, ret, x, ptr)                      \
+       asm volatile("call __get_user_" #size         \
+                    : "=a" (ret),"=d" (x)            \
+                    : "0" (ptr))                     \
+
+/* Careful: we have to cast the result to the type of the pointer
+ * for sign reasons */
+
+/**
+ * get_user: - Get a simple variable from user space.
+ * @x:   Variable to store result.
+ * @ptr: Source address, in user space.
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * This macro copies a single simple variable from user space to kernel
+ * space.  It supports simple types like char and int, but not larger
+ * data types like structures or arrays.
+ *
+ * @ptr must have pointer-to-simple-variable type, and the result of
+ * dereferencing @ptr must be assignable to @x without a cast.
+ *
+ * Returns zero on success, or -EFAULT on error.
+ * On error, the variable @x is set to zero.
+ */
+#ifdef CONFIG_X86_32
+#define __get_user_8(__ret_gu, __val_gu, ptr)                          \
+               __get_user_x(X, __ret_gu, __val_gu, ptr)
+#else
+#define __get_user_8(__ret_gu, __val_gu, ptr)                          \
+               __get_user_x(8, __ret_gu, __val_gu, ptr)
+#endif
+
+#define get_user(x, ptr)                                               \
+({                                                                     \
+       int __ret_gu;                                                   \
+       unsigned long __val_gu;                                         \
+       __chk_user_ptr(ptr);                                            \
+       switch (sizeof(*(ptr))) {                                       \
+       case 1:                                                         \
+               __get_user_x(1, __ret_gu, __val_gu, ptr);               \
+               break;                                                  \
+       case 2:                                                         \
+               __get_user_x(2, __ret_gu, __val_gu, ptr);               \
+               break;                                                  \
+       case 4:                                                         \
+               __get_user_x(4, __ret_gu, __val_gu, ptr);               \
+               break;                                                  \
+       case 8:                                                         \
+               __get_user_8(__ret_gu, __val_gu, ptr);                  \
+               break;                                                  \
+       default:                                                        \
+               __get_user_x(X, __ret_gu, __val_gu, ptr);               \
+               break;                                                  \
+       }                                                               \
+       (x) = (__typeof__(*(ptr)))__val_gu;                             \
+       __ret_gu;                                                       \
+})
+
+#define __put_user_x(size, x, ptr, __ret_pu)                   \
+       asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
+                    :"0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
+
+
+
+#ifdef CONFIG_X86_32
+#define __put_user_u64(x, addr, err)                                   \
+       asm volatile("1:        movl %%eax,0(%2)\n"                     \
+                    "2:        movl %%edx,4(%2)\n"                     \
+                    "3:\n"                                             \
+                    ".section .fixup,\"ax\"\n"                         \
+                    "4:        movl %3,%0\n"                           \
+                    "  jmp 3b\n"                                       \
+                    ".previous\n"                                      \
+                    _ASM_EXTABLE(1b, 4b)                               \
+                    _ASM_EXTABLE(2b, 4b)                               \
+                    : "=r" (err)                                       \
+                    : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
+
+#define __put_user_x8(x, ptr, __ret_pu)                                \
+       asm volatile("call __put_user_8" : "=a" (__ret_pu)      \
+                    : "A" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
+#else
+#define __put_user_u64(x, ptr, retval) \
+       __put_user_asm(x, ptr, retval, "q", "", "Zr", -EFAULT)
+#define __put_user_x8(x, ptr, __ret_pu) __put_user_x(8, x, ptr, __ret_pu)
+#endif
+
+extern void __put_user_bad(void);
+
+/*
+ * Strange magic calling convention: pointer in %ecx,
+ * value in %eax(:%edx), return value in %eax. clobbers %rbx
+ */
+extern void __put_user_1(void);
+extern void __put_user_2(void);
+extern void __put_user_4(void);
+extern void __put_user_8(void);
+
+#ifdef CONFIG_X86_WP_WORKS_OK
+
+/**
+ * put_user: - Write a simple value into user space.
+ * @x:   Value to copy to user space.
+ * @ptr: Destination address, in user space.
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * This macro copies a single simple value from kernel space to user
+ * space.  It supports simple types like char and int, but not larger
+ * data types like structures or arrays.
+ *
+ * @ptr must have pointer-to-simple-variable type, and @x must be assignable
+ * to the result of dereferencing @ptr.
+ *
+ * Returns zero on success, or -EFAULT on error.
+ */
+#define put_user(x, ptr)                                       \
+({                                                             \
+       int __ret_pu;                                           \
+       __typeof__(*(ptr)) __pu_val;                            \
+       __chk_user_ptr(ptr);                                    \
+       __pu_val = x;                                           \
+       switch (sizeof(*(ptr))) {                               \
+       case 1:                                                 \
+               __put_user_x(1, __pu_val, ptr, __ret_pu);       \
+               break;                                          \
+       case 2:                                                 \
+               __put_user_x(2, __pu_val, ptr, __ret_pu);       \
+               break;                                          \
+       case 4:                                                 \
+               __put_user_x(4, __pu_val, ptr, __ret_pu);       \
+               break;                                          \
+       case 8:                                                 \
+               __put_user_x8(__pu_val, ptr, __ret_pu);         \
+               break;                                          \
+       default:                                                \
+               __put_user_x(X, __pu_val, ptr, __ret_pu);       \
+               break;                                          \
+       }                                                       \
+       __ret_pu;                                               \
+})
+
+#define __put_user_size(x, ptr, size, retval, errret)                  \
+do {                                                                   \
+       retval = 0;                                                     \
+       __chk_user_ptr(ptr);                                            \
+       switch (size) {                                                 \
+       case 1:                                                         \
+               __put_user_asm(x, ptr, retval, "b", "b", "iq", errret); \
+               break;                                                  \
+       case 2:                                                         \
+               __put_user_asm(x, ptr, retval, "w", "w", "ir", errret); \
+               break;                                                  \
+       case 4:                                                         \
+               __put_user_asm(x, ptr, retval, "l", "k",  "ir", errret);\
+               break;                                                  \
+       case 8:                                                         \
+               __put_user_u64((__typeof__(*ptr))(x), ptr, retval);     \
+               break;                                                  \
+       default:                                                        \
+               __put_user_bad();                                       \
+       }                                                               \
+} while (0)
+
+#else
+
+#define __put_user_size(x, ptr, size, retval, errret)                  \
+do {                                                                   \
+       __typeof__(*(ptr))__pus_tmp = x;                                \
+       retval = 0;                                                     \
+                                                                       \
+       if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, size) != 0))    \
+               retval = errret;                                        \
+} while (0)
+
+#define put_user(x, ptr)                                       \
+({                                                             \
+       int __ret_pu;                                           \
+       __typeof__(*(ptr))__pus_tmp = x;                        \
+       __ret_pu = 0;                                           \
+       if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp,         \
+                                      sizeof(*(ptr))) != 0))   \
+               __ret_pu = -EFAULT;                             \
+       __ret_pu;                                               \
+})
+#endif
+
+#ifdef CONFIG_X86_32
+#define __get_user_asm_u64(x, ptr, retval, errret)     (x) = __get_user_bad()
+#else
+#define __get_user_asm_u64(x, ptr, retval, errret) \
+        __get_user_asm(x, ptr, retval, "q", "", "=r", errret)
+#endif
+
+#define __get_user_size(x, ptr, size, retval, errret)                  \
+do {                                                                   \
+       retval = 0;                                                     \
+       __chk_user_ptr(ptr);                                            \
+       switch (size) {                                                 \
+       case 1:                                                         \
+               __get_user_asm(x, ptr, retval, "b", "b", "=q", errret); \
+               break;                                                  \
+       case 2:                                                         \
+               __get_user_asm(x, ptr, retval, "w", "w", "=r", errret); \
+               break;                                                  \
+       case 4:                                                         \
+               __get_user_asm(x, ptr, retval, "l", "k", "=r", errret); \
+               break;                                                  \
+       case 8:                                                         \
+               __get_user_asm_u64(x, ptr, retval, errret);             \
+               break;                                                  \
+       default:                                                        \
+               (x) = __get_user_bad();                                 \
+       }                                                               \
+} while (0)
+
+#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret)      \
+       asm volatile("1:        mov"itype" %2,%"rtype"1\n"              \
+                    "2:\n"                                             \
+                    ".section .fixup,\"ax\"\n"                         \
+                    "3:        mov %3,%0\n"                            \
+                    "  xor"itype" %"rtype"1,%"rtype"1\n"               \
+                    "  jmp 2b\n"                                       \
+                    ".previous\n"                                      \
+                    _ASM_EXTABLE(1b, 3b)                               \
+                    : "=r" (err), ltype(x)                             \
+                    : "m" (__m(addr)), "i" (errret), "0" (err))
+
+#define __put_user_nocheck(x, ptr, size)                       \
+({                                                             \
+       long __pu_err;                                          \
+       __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
+       __pu_err;                                               \
+})
+
+#define __get_user_nocheck(x, ptr, size)                               \
+({                                                                     \
+       long __gu_err;                                                  \
+       unsigned long __gu_val;                                         \
+       __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT);    \
+       (x) = (__force __typeof__(*(ptr)))__gu_val;                     \
+       __gu_err;                                                       \
+})
+
+/* FIXME: this hack is definitely wrong -AK */
+struct __large_struct { unsigned long buf[100]; };
+#define __m(x) (*(struct __large_struct __user *)(x))
+
+/*
+ * Tell gcc we read from memory instead of writing: this is because
+ * we do not write to any memory gcc knows about, so there are no
+ * aliasing issues.
+ */
+#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret)      \
+       asm volatile("1:        mov"itype" %"rtype"1,%2\n"              \
+                    "2:\n"                                             \
+                    ".section .fixup,\"ax\"\n"                         \
+                    "3:        mov %3,%0\n"                            \
+                    "  jmp 2b\n"                                       \
+                    ".previous\n"                                      \
+                    _ASM_EXTABLE(1b, 3b)                               \
+                    : "=r"(err)                                        \
+                    : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
+/**
+ * __get_user: - Get a simple variable from user space, with less checking.
+ * @x:   Variable to store result.
+ * @ptr: Source address, in user space.
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * This macro copies a single simple variable from user space to kernel
+ * space.  It supports simple types like char and int, but not larger
+ * data types like structures or arrays.
+ *
+ * @ptr must have pointer-to-simple-variable type, and the result of
+ * dereferencing @ptr must be assignable to @x without a cast.
+ *
+ * Caller must check the pointer with access_ok() before calling this
+ * function.
+ *
+ * Returns zero on success, or -EFAULT on error.
+ * On error, the variable @x is set to zero.
+ */
+
+#define __get_user(x, ptr)                                             \
+       __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
+/**
+ * __put_user: - Write a simple value into user space, with less checking.
+ * @x:   Value to copy to user space.
+ * @ptr: Destination address, in user space.
+ *
+ * Context: User context only.  This function may sleep.
+ *
+ * This macro copies a single simple value from kernel space to user
+ * space.  It supports simple types like char and int, but not larger
+ * data types like structures or arrays.
+ *
+ * @ptr must have pointer-to-simple-variable type, and @x must be assignable
+ * to the result of dereferencing @ptr.
+ *
+ * Caller must check the pointer with access_ok() before calling this
+ * function.
+ *
+ * Returns zero on success, or -EFAULT on error.
+ */
+
+#define __put_user(x, ptr)                                             \
+       __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
+
+#define __get_user_unaligned __get_user
+#define __put_user_unaligned __put_user
+
+/*
+ * movsl can be slow when source and dest are not both 8-byte aligned
+ */
+#ifdef CONFIG_X86_INTEL_USERCOPY
+extern struct movsl_mask {
+       int mask;
+} ____cacheline_aligned_in_smp movsl_mask;
+#endif
+
+#define ARCH_HAS_NOCACHE_UACCESS 1
+
 #ifdef CONFIG_X86_32
 # include "uaccess_32.h"
 #else
+# define ARCH_HAS_SEARCH_EXTABLE
 # include "uaccess_64.h"
 #endif
+
+#endif
index 8e7595c..6fdef39 100644 (file)
 #include <asm/asm.h>
 #include <asm/page.h>
 
-#define VERIFY_READ 0
-#define VERIFY_WRITE 1
-
-/*
- * The fs value determines whether argument validity checking should be
- * performed or not.  If get_fs() == USER_DS, checking is performed, with
- * get_fs() == KERNEL_DS, checking is bypassed.
- *
- * For historical reasons, these macros are grossly misnamed.
- */
-
-#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
-
-
-#define KERNEL_DS      MAKE_MM_SEG(0xFFFFFFFFUL)
-#define USER_DS                MAKE_MM_SEG(PAGE_OFFSET)
-
-#define get_ds()       (KERNEL_DS)
-#define get_fs()       (current_thread_info()->addr_limit)
-#define set_fs(x)      (current_thread_info()->addr_limit = (x))
-
-#define segment_eq(a, b)       ((a).seg == (b).seg)
-
-/*
- * movsl can be slow when source and dest are not both 8-byte aligned
- */
-#ifdef CONFIG_X86_INTEL_USERCOPY
-extern struct movsl_mask {
-       int mask;
-} ____cacheline_aligned_in_smp movsl_mask;
-#endif
-
-#define __addr_ok(addr)                                        \
-       ((unsigned long __force)(addr) <                \
-        (current_thread_info()->addr_limit.seg))
-
-/*
- * Test whether a block of memory is a valid user space address.
- * Returns 0 if the range is valid, nonzero otherwise.
- *
- * This is equivalent to the following test:
- * (u33)addr + (u33)size >= (u33)current->addr_limit.seg
- *
- * This needs 33-bit arithmetic. We have a carry...
- */
-#define __range_ok(addr, size)                                         \
-({                                                                     \
-       unsigned long flag, roksum;                                     \
-       __chk_user_ptr(addr);                                           \
-       asm("addl %3,%1 ; sbbl %0,%0; cmpl %1,%4; sbbl $0,%0"           \
-           :"=&r" (flag), "=r" (roksum)                                \
-           :"1" (addr), "g" ((int)(size)),                             \
-           "rm" (current_thread_info()->addr_limit.seg));              \
-       flag;                                                           \
-})
-
-/**
- * access_ok: - Checks if a user space pointer is valid
- * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
- *        %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
- *        to write to a block, it is always safe to read from it.
- * @addr: User space pointer to start of block to check
- * @size: Size of block to check
- *
- * Context: User context only.  This function may sleep.
- *
- * Checks if a pointer to a block of memory in user space is valid.
- *
- * Returns true (nonzero) if the memory block may be valid, false (zero)
- * if it is definitely invalid.
- *
- * Note that, depending on architecture, this function probably just
- * checks that the pointer is in the user space range - after calling
- * this function, memory access functions may still return -EFAULT.
- */
-#define access_ok(type, addr, size) (likely(__range_ok(addr, size) == 0))
-
-/*
- * The exception table consists of pairs of addresses: the first is the
- * address of an instruction that is allowed to fault, and the second is
- * the address at which the program should continue.  No registers are
- * modified, so it is entirely up to the continuation code to figure out
- * what to do.
- *
- * All the routines below use bits of fixup code that are out of line
- * with the main instruction path.  This means when everything is well,
- * we don't even have to jump over them.  Further, they do not intrude
- * on our cache or tlb entries.
- */
-
-struct exception_table_entry {
-       unsigned long insn, fixup;
-};
-
-extern int fixup_exception(struct pt_regs *regs);
-
-/*
- * These are the main single-value transfer routines.  They automatically
- * use the right size if we just have the right pointer type.
- *
- * This gets kind of ugly. We want to return _two_ values in "get_user()"
- * and yet we don't want to do any pointers, because that is too much
- * of a performance impact. Thus we have a few rather ugly macros here,
- * and hide all the ugliness from the user.
- *
- * The "__xxx" versions of the user access functions are versions that
- * do not verify the address space, that must have been done previously
- * with a separate "access_ok()" call (this is used when we do multiple
- * accesses to the same area of user memory).
- */
-
-extern void __get_user_1(void);
-extern void __get_user_2(void);
-extern void __get_user_4(void);
-
-#define __get_user_x(size, ret, x, ptr)              \
-       asm volatile("call __get_user_" #size \
-                    :"=a" (ret),"=d" (x)     \
-                    :"0" (ptr))
-
-
-/* Careful: we have to cast the result to the type of the pointer
- * for sign reasons */
-
-/**
- * get_user: - Get a simple variable from user space.
- * @x:   Variable to store result.
- * @ptr: Source address, in user space.
- *
- * Context: User context only.  This function may sleep.
- *
- * This macro copies a single simple variable from user space to kernel
- * space.  It supports simple types like char and int, but not larger
- * data types like structures or arrays.
- *
- * @ptr must have pointer-to-simple-variable type, and the result of
- * dereferencing @ptr must be assignable to @x without a cast.
- *
- * Returns zero on success, or -EFAULT on error.
- * On error, the variable @x is set to zero.
- */
-#define get_user(x, ptr)                                               \
-({                                                                     \
-       int __ret_gu;                                                   \
-       unsigned long __val_gu;                                         \
-       __chk_user_ptr(ptr);                                            \
-       switch (sizeof(*(ptr))) {                                       \
-       case 1:                                                         \
-               __get_user_x(1, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       case 2:                                                         \
-               __get_user_x(2, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       case 4:                                                         \
-               __get_user_x(4, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       default:                                                        \
-               __get_user_x(X, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       }                                                               \
-       (x) = (__typeof__(*(ptr)))__val_gu;                             \
-       __ret_gu;                                                       \
-})
-
-extern void __put_user_bad(void);
-
-/*
- * Strange magic calling convention: pointer in %ecx,
- * value in %eax(:%edx), return value in %eax, no clobbers.
- */
-extern void __put_user_1(void);
-extern void __put_user_2(void);
-extern void __put_user_4(void);
-extern void __put_user_8(void);
-
-#define __put_user_1(x, ptr)                                   \
-       asm volatile("call __put_user_1" : "=a" (__ret_pu)      \
-                    : "0" ((typeof(*(ptr)))(x)), "c" (ptr))
-
-#define __put_user_2(x, ptr)                                   \
-       asm volatile("call __put_user_2" : "=a" (__ret_pu)      \
-                    : "0" ((typeof(*(ptr)))(x)), "c" (ptr))
-
-#define __put_user_4(x, ptr)                                   \
-       asm volatile("call __put_user_4" : "=a" (__ret_pu)      \
-                    : "0" ((typeof(*(ptr)))(x)), "c" (ptr))
-
-#define __put_user_8(x, ptr)                                   \
-       asm volatile("call __put_user_8" : "=a" (__ret_pu)      \
-                    : "A" ((typeof(*(ptr)))(x)), "c" (ptr))
-
-#define __put_user_X(x, ptr)                                   \
-       asm volatile("call __put_user_X" : "=a" (__ret_pu)      \
-                    : "c" (ptr))
-
-/**
- * put_user: - Write a simple value into user space.
- * @x:   Value to copy to user space.
- * @ptr: Destination address, in user space.
- *
- * Context: User context only.  This function may sleep.
- *
- * This macro copies a single simple value from kernel space to user
- * space.  It supports simple types like char and int, but not larger
- * data types like structures or arrays.
- *
- * @ptr must have pointer-to-simple-variable type, and @x must be assignable
- * to the result of dereferencing @ptr.
- *
- * Returns zero on success, or -EFAULT on error.
- */
-#ifdef CONFIG_X86_WP_WORKS_OK
-
-#define put_user(x, ptr)                                       \
-({                                                             \
-       int __ret_pu;                                           \
-       __typeof__(*(ptr)) __pu_val;                            \
-       __chk_user_ptr(ptr);                                    \
-       __pu_val = x;                                           \
-       switch (sizeof(*(ptr))) {                               \
-       case 1:                                                 \
-               __put_user_1(__pu_val, ptr);                    \
-               break;                                          \
-       case 2:                                                 \
-               __put_user_2(__pu_val, ptr);                    \
-               break;                                          \
-       case 4:                                                 \
-               __put_user_4(__pu_val, ptr);                    \
-               break;                                          \
-       case 8:                                                 \
-               __put_user_8(__pu_val, ptr);                    \
-               break;                                          \
-       default:                                                \
-               __put_user_X(__pu_val, ptr);                    \
-               break;                                          \
-       }                                                       \
-       __ret_pu;                                               \
-})
-
-#else
-#define put_user(x, ptr)                                       \
-({                                                             \
-       int __ret_pu;                                           \
-       __typeof__(*(ptr))__pus_tmp = x;                        \
-       __ret_pu = 0;                                           \
-       if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp,         \
-                                      sizeof(*(ptr))) != 0))   \
-               __ret_pu = -EFAULT;                             \
-       __ret_pu;                                               \
-})
-
-
-#endif
-
-/**
- * __get_user: - Get a simple variable from user space, with less checking.
- * @x:   Variable to store result.
- * @ptr: Source address, in user space.
- *
- * Context: User context only.  This function may sleep.
- *
- * This macro copies a single simple variable from user space to kernel
- * space.  It supports simple types like char and int, but not larger
- * data types like structures or arrays.
- *
- * @ptr must have pointer-to-simple-variable type, and the result of
- * dereferencing @ptr must be assignable to @x without a cast.
- *
- * Caller must check the pointer with access_ok() before calling this
- * function.
- *
- * Returns zero on success, or -EFAULT on error.
- * On error, the variable @x is set to zero.
- */
-#define __get_user(x, ptr)                             \
-       __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
-
-
-/**
- * __put_user: - Write a simple value into user space, with less checking.
- * @x:   Value to copy to user space.
- * @ptr: Destination address, in user space.
- *
- * Context: User context only.  This function may sleep.
- *
- * This macro copies a single simple value from kernel space to user
- * space.  It supports simple types like char and int, but not larger
- * data types like structures or arrays.
- *
- * @ptr must have pointer-to-simple-variable type, and @x must be assignable
- * to the result of dereferencing @ptr.
- *
- * Caller must check the pointer with access_ok() before calling this
- * function.
- *
- * Returns zero on success, or -EFAULT on error.
- */
-#define __put_user(x, ptr)                                             \
-       __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
-
-#define __put_user_nocheck(x, ptr, size)                       \
-({                                                             \
-       long __pu_err;                                          \
-       __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
-       __pu_err;                                               \
-})
-
-
-#define __put_user_u64(x, addr, err)                                   \
-       asm volatile("1:        movl %%eax,0(%2)\n"                     \
-                    "2:        movl %%edx,4(%2)\n"                     \
-                    "3:\n"                                             \
-                    ".section .fixup,\"ax\"\n"                         \
-                    "4:        movl %3,%0\n"                           \
-                    "  jmp 3b\n"                                       \
-                    ".previous\n"                                      \
-                    _ASM_EXTABLE(1b, 4b)                               \
-                    _ASM_EXTABLE(2b, 4b)                               \
-                    : "=r" (err)                                       \
-                    : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
-
-#ifdef CONFIG_X86_WP_WORKS_OK
-
-#define __put_user_size(x, ptr, size, retval, errret)                  \
-do {                                                                   \
-       retval = 0;                                                     \
-       __chk_user_ptr(ptr);                                            \
-       switch (size) {                                                 \
-       case 1:                                                         \
-               __put_user_asm(x, ptr, retval, "b", "b", "iq", errret); \
-               break;                                                  \
-       case 2:                                                         \
-               __put_user_asm(x, ptr, retval, "w", "w", "ir", errret); \
-               break;                                                  \
-       case 4:                                                         \
-               __put_user_asm(x, ptr, retval, "l", "",  "ir", errret); \
-               break;                                                  \
-       case 8:                                                         \
-               __put_user_u64((__typeof__(*ptr))(x), ptr, retval);     \
-               break;                                                  \
-       default:                                                        \
-               __put_user_bad();                                       \
-       }                                                               \
-} while (0)
-
-#else
-
-#define __put_user_size(x, ptr, size, retval, errret)                  \
-do {                                                                   \
-       __typeof__(*(ptr))__pus_tmp = x;                                \
-       retval = 0;                                                     \
-                                                                       \
-       if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, size) != 0))    \
-               retval = errret;                                        \
-} while (0)
-
-#endif
-struct __large_struct { unsigned long buf[100]; };
-#define __m(x) (*(struct __large_struct __user *)(x))
-
-/*
- * Tell gcc we read from memory instead of writing: this is because
- * we do not write to any memory gcc knows about, so there are no
- * aliasing issues.
- */
-#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret)      \
-       asm volatile("1:        mov"itype" %"rtype"1,%2\n"              \
-                    "2:\n"                                             \
-                    ".section .fixup,\"ax\"\n"                         \
-                    "3:        movl %3,%0\n"                           \
-                    "  jmp 2b\n"                                       \
-                    ".previous\n"                                      \
-                    _ASM_EXTABLE(1b, 3b)                               \
-                    : "=r"(err)                                        \
-                    : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
-
-
-#define __get_user_nocheck(x, ptr, size)                               \
-({                                                                     \
-       long __gu_err;                                                  \
-       unsigned long __gu_val;                                         \
-       __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT);    \
-       (x) = (__typeof__(*(ptr)))__gu_val;                             \
-       __gu_err;                                                       \
-})
-
-extern long __get_user_bad(void);
-
-#define __get_user_size(x, ptr, size, retval, errret)                  \
-do {                                                                   \
-       retval = 0;                                                     \
-       __chk_user_ptr(ptr);                                            \
-       switch (size) {                                                 \
-       case 1:                                                         \
-               __get_user_asm(x, ptr, retval, "b", "b", "=q", errret); \
-               break;                                                  \
-       case 2:                                                         \
-               __get_user_asm(x, ptr, retval, "w", "w", "=r", errret); \
-               break;                                                  \
-       case 4:                                                         \
-               __get_user_asm(x, ptr, retval, "l", "", "=r", errret);  \
-               break;                                                  \
-       default:                                                        \
-               (x) = __get_user_bad();                                 \
-       }                                                               \
-} while (0)
-
-#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret)      \
-       asm volatile("1:        mov"itype" %2,%"rtype"1\n"              \
-                    "2:\n"                                             \
-                    ".section .fixup,\"ax\"\n"                         \
-                    "3:        movl %3,%0\n"                           \
-                    "  xor"itype" %"rtype"1,%"rtype"1\n"               \
-                    "  jmp 2b\n"                                       \
-                    ".previous\n"                                      \
-                    _ASM_EXTABLE(1b, 3b)                               \
-                    : "=r" (err), ltype (x)                            \
-                    : "m" (__m(addr)), "i" (errret), "0" (err))
-
-
 unsigned long __must_check __copy_to_user_ll
                (void __user *to, const void *from, unsigned long n);
 unsigned long __must_check __copy_from_user_ll
@@ -576,8 +156,6 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
        return __copy_from_user_ll(to, from, n);
 }
 
-#define ARCH_HAS_NOCACHE_UACCESS
-
 static __always_inline unsigned long __copy_from_user_nocache(void *to,
                                const void __user *from, unsigned long n)
 {
index b8a2f43..515d4dc 100644 (file)
@@ -9,265 +9,6 @@
 #include <linux/prefetch.h>
 #include <asm/page.h>
 
-#define VERIFY_READ 0
-#define VERIFY_WRITE 1
-
-/*
- * The fs value determines whether argument validity checking should be
- * performed or not.  If get_fs() == USER_DS, checking is performed, with
- * get_fs() == KERNEL_DS, checking is bypassed.
- *
- * For historical reasons, these macros are grossly misnamed.
- */
-
-#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
-
-#define KERNEL_DS      MAKE_MM_SEG(0xFFFFFFFFFFFFFFFFUL)
-#define USER_DS                MAKE_MM_SEG(PAGE_OFFSET)
-
-#define get_ds()       (KERNEL_DS)
-#define get_fs()       (current_thread_info()->addr_limit)
-#define set_fs(x)      (current_thread_info()->addr_limit = (x))
-
-#define segment_eq(a, b)       ((a).seg == (b).seg)
-
-#define __addr_ok(addr) (!((unsigned long)(addr) &                     \
-                          (current_thread_info()->addr_limit.seg)))
-
-/*
- * Uhhuh, this needs 65-bit arithmetic. We have a carry..
- */
-#define __range_not_ok(addr, size)                                     \
-({                                                                     \
-       unsigned long flag, roksum;                                     \
-       __chk_user_ptr(addr);                                           \
-       asm("# range_ok\n\r"                                            \
-           "addq %3,%1 ; sbbq %0,%0 ; cmpq %1,%4 ; sbbq $0,%0"         \
-           : "=&r" (flag), "=r" (roksum)                               \
-           : "1" (addr), "g" ((long)(size)),                           \
-             "g" (current_thread_info()->addr_limit.seg));             \
-       flag;                                                           \
-})
-
-#define access_ok(type, addr, size) (__range_not_ok(addr, size) == 0)
-
-/*
- * The exception table consists of pairs of addresses: the first is the
- * address of an instruction that is allowed to fault, and the second is
- * the address at which the program should continue.  No registers are
- * modified, so it is entirely up to the continuation code to figure out
- * what to do.
- *
- * All the routines below use bits of fixup code that are out of line
- * with the main instruction path.  This means when everything is well,
- * we don't even have to jump over them.  Further, they do not intrude
- * on our cache or tlb entries.
- */
-
-struct exception_table_entry {
-       unsigned long insn, fixup;
-};
-
-extern int fixup_exception(struct pt_regs *regs);
-
-#define ARCH_HAS_SEARCH_EXTABLE
-
-/*
- * These are the main single-value transfer routines.  They automatically
- * use the right size if we just have the right pointer type.
- *
- * This gets kind of ugly. We want to return _two_ values in "get_user()"
- * and yet we don't want to do any pointers, because that is too much
- * of a performance impact. Thus we have a few rather ugly macros here,
- * and hide all the ugliness from the user.
- *
- * The "__xxx" versions of the user access functions are versions that
- * do not verify the address space, that must have been done previously
- * with a separate "access_ok()" call (this is used when we do multiple
- * accesses to the same area of user memory).
- */
-
-#define __get_user_x(size, ret, x, ptr)                      \
-       asm volatile("call __get_user_" #size         \
-                    : "=a" (ret),"=d" (x)            \
-                    : "c" (ptr)                      \
-                    : "r8")
-
-/* Careful: we have to cast the result to the type of the pointer
- * for sign reasons */
-
-#define get_user(x, ptr)                                               \
-({                                                                     \
-       unsigned long __val_gu;                                         \
-       int __ret_gu;                                                   \
-       __chk_user_ptr(ptr);                                            \
-       switch (sizeof(*(ptr))) {                                       \
-       case 1:                                                         \
-               __get_user_x(1, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       case 2:                                                         \
-               __get_user_x(2, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       case 4:                                                         \
-               __get_user_x(4, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       case 8:                                                         \
-               __get_user_x(8, __ret_gu, __val_gu, ptr);               \
-               break;                                                  \
-       default:                                                        \
-               __get_user_bad();                                       \
-               break;                                                  \
-       }                                                               \
-       (x) = (__force typeof(*(ptr)))__val_gu;                         \
-       __ret_gu;                                                       \
-})
-
-extern void __put_user_1(void);
-extern void __put_user_2(void);
-extern void __put_user_4(void);
-extern void __put_user_8(void);
-extern void __put_user_bad(void);
-
-#define __put_user_x(size, ret, x, ptr)                                        \
-       asm volatile("call __put_user_" #size                           \
-                    :"=a" (ret)                                        \
-                    :"c" (ptr),"d" (x)                                 \
-                    :"r8")
-
-#define put_user(x, ptr)                                               \
-       __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
-
-#define __get_user(x, ptr)                                             \
-       __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
-#define __put_user(x, ptr)                                             \
-       __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
-
-#define __get_user_unaligned __get_user
-#define __put_user_unaligned __put_user
-
-#define __put_user_nocheck(x, ptr, size)               \
-({                                                     \
-       int __pu_err;                                   \
-       __put_user_size((x), (ptr), (size), __pu_err);  \
-       __pu_err;                                       \
-})
-
-
-#define __put_user_check(x, ptr, size)                         \
-({                                                             \
-       int __pu_err;                                           \
-       typeof(*(ptr)) __user *__pu_addr = (ptr);               \
-       switch (size) {                                         \
-       case 1:                                                 \
-               __put_user_x(1, __pu_err, x, __pu_addr);        \
-               break;                                          \
-       case 2:                                                 \
-               __put_user_x(2, __pu_err, x, __pu_addr);        \
-               break;                                          \
-       case 4:                                                 \
-               __put_user_x(4, __pu_err, x, __pu_addr);        \
-               break;                                          \
-       case 8:                                                 \
-               __put_user_x(8, __pu_err, x, __pu_addr);        \
-               break;                                          \
-       default:                                                \
-               __put_user_bad();                               \
-       }                                                       \
-       __pu_err;                                               \
-})
-
-#define __put_user_size(x, ptr, size, retval)                          \
-do {                                                                   \
-       retval = 0;                                                     \
-       __chk_user_ptr(ptr);                                            \
-       switch (size) {                                                 \
-       case 1:                                                         \
-               __put_user_asm(x, ptr, retval, "b", "b", "iq", -EFAULT);\
-               break;                                                  \
-       case 2:                                                         \
-               __put_user_asm(x, ptr, retval, "w", "w", "ir", -EFAULT);\
-               break;                                                  \
-       case 4:                                                         \
-               __put_user_asm(x, ptr, retval, "l", "k", "ir", -EFAULT);\
-               break;                                                  \
-       case 8:                                                         \
-               __put_user_asm(x, ptr, retval, "q", "", "Zr", -EFAULT); \
-               break;                                                  \
-       default:                                                        \
-               __put_user_bad();                                       \
-       }                                                               \
-} while (0)
-
-/* FIXME: this hack is definitely wrong -AK */
-struct __large_struct { unsigned long buf[100]; };
-#define __m(x) (*(struct __large_struct __user *)(x))
-
-/*
- * Tell gcc we read from memory instead of writing: this is because
- * we do not write to any memory gcc knows about, so there are no
- * aliasing issues.
- */
-#define __put_user_asm(x, addr, err, itype, rtype, ltype, errno)       \
-       asm volatile("1:        mov"itype" %"rtype"1,%2\n"              \
-                    "2:\n"                                             \
-                    ".section .fixup, \"ax\"\n"                        \
-                    "3:        mov %3,%0\n"                            \
-                    "  jmp 2b\n"                                       \
-                    ".previous\n"                                      \
-                    _ASM_EXTABLE(1b, 3b)                               \
-                    : "=r"(err)                                        \
-                    : ltype (x), "m" (__m(addr)), "i" (errno), "0" (err))
-
-
-#define __get_user_nocheck(x, ptr, size)                       \
-({                                                             \
-       int __gu_err;                                           \
-       unsigned long __gu_val;                                 \
-       __get_user_size(__gu_val, (ptr), (size), __gu_err);     \
-       (x) = (__force typeof(*(ptr)))__gu_val;                 \
-       __gu_err;                                               \
-})
-
-extern int __get_user_1(void);
-extern int __get_user_2(void);
-extern int __get_user_4(void);
-extern int __get_user_8(void);
-extern int __get_user_bad(void);
-
-#define __get_user_size(x, ptr, size, retval)                          \
-do {                                                                   \
-       retval = 0;                                                     \
-       __chk_user_ptr(ptr);                                            \
-       switch (size) {                                                 \
-       case 1:                                                         \
-               __get_user_asm(x, ptr, retval, "b", "b", "=q", -EFAULT);\
-               break;                                                  \
-       case 2:                                                         \
-               __get_user_asm(x, ptr, retval, "w", "w", "=r", -EFAULT);\
-               break;                                                  \
-       case 4:                                                         \
-               __get_user_asm(x, ptr, retval, "l", "k", "=r", -EFAULT);\
-               break;                                                  \
-       case 8:                                                         \
-               __get_user_asm(x, ptr, retval, "q", "", "=r", -EFAULT); \
-               break;                                                  \
-       default:                                                        \
-               (x) = __get_user_bad();                                 \
-       }                                                               \
-} while (0)
-
-#define __get_user_asm(x, addr, err, itype, rtype, ltype, errno)       \
-       asm volatile("1:        mov"itype" %2,%"rtype"1\n"              \
-                    "2:\n"                                             \
-                    ".section .fixup, \"ax\"\n"                        \
-                    "3:        mov %3,%0\n"                            \
-                    "  xor"itype" %"rtype"1,%"rtype"1\n"               \
-                    "  jmp 2b\n"                                       \
-                    ".previous\n"                                      \
-                    _ASM_EXTABLE(1b, 3b)                               \
-                    : "=r" (err), ltype (x)                            \
-                    : "m" (__m(addr)), "i"(errno), "0"(err))
-
 /*
  * Copy To/From Userspace
  */
@@ -437,7 +178,6 @@ __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
        return copy_user_generic((__force void *)dst, src, size);
 }
 
-#define ARCH_HAS_NOCACHE_UACCESS 1
 extern long __copy_user_nocache(void *dst, const void __user *src,
                                unsigned size, int zerorest);
 
@@ -455,4 +195,7 @@ static inline int __copy_from_user_inatomic_nocache(void *dst,
        return __copy_user_nocache(dst, src, size, 0);
 }
 
+unsigned long
+copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
+
 #endif /* __X86_64_UACCESS_H */
index fe26e36..9c1a4a3 100644 (file)
@@ -290,7 +290,7 @@ __SYSCALL(__NR_rt_sigtimedwait, sys_rt_sigtimedwait)
 #define __NR_rt_sigqueueinfo                   129
 __SYSCALL(__NR_rt_sigqueueinfo, sys_rt_sigqueueinfo)
 #define __NR_rt_sigsuspend                     130
-__SYSCALL(__NR_rt_sigsuspend, stub_rt_sigsuspend)
+__SYSCALL(__NR_rt_sigsuspend, sys_rt_sigsuspend)
 #define __NR_sigaltstack                       131
 __SYSCALL(__NR_sigaltstack, stub_sigaltstack)
 #define __NR_utime                             132
diff --git a/include/asm-x86/uv/uv_bau.h b/include/asm-x86/uv/uv_bau.h
new file mode 100644 (file)
index 0000000..91ac0df
--- /dev/null
@@ -0,0 +1,337 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * SGI UV Broadcast Assist Unit definitions
+ *
+ * Copyright (C) 2008 Silicon Graphics, Inc. All rights reserved.
+ */
+
+#ifndef __ASM_X86_UV_BAU__
+#define __ASM_X86_UV_BAU__
+
+#include <linux/bitmap.h>
+#define BITSPERBYTE 8
+
+/*
+ * Broadcast Assist Unit messaging structures
+ *
+ * Selective Broadcast activations are induced by software action
+ * specifying a particular 8-descriptor "set" via a 6-bit index written
+ * to an MMR.
+ * Thus there are 64 unique 512-byte sets of SB descriptors - one set for
+ * each 6-bit index value. These descriptor sets are mapped in sequence
+ * starting with set 0 located at the address specified in the
+ * BAU_SB_DESCRIPTOR_BASE register, set 1 is located at BASE + 512,
+ * set 2 is at BASE + 2*512, set 3 at BASE + 3*512, and so on.
+ *
+ * We will use 31 sets, one for sending BAU messages from each of the 32
+ * cpu's on the node.
+ *
+ * TLB shootdown will use the first of the 8 descriptors of each set.
+ * Each of the descriptors is 64 bytes in size (8*64 = 512 bytes in a set).
+ */
+
+#define UV_ITEMS_PER_DESCRIPTOR                8
+#define UV_CPUS_PER_ACT_STATUS         32
+#define UV_ACT_STATUS_MASK             0x3
+#define UV_ACT_STATUS_SIZE             2
+#define UV_ACTIVATION_DESCRIPTOR_SIZE  32
+#define UV_DISTRIBUTION_SIZE           256
+#define UV_SW_ACK_NPENDING             8
+#define UV_BAU_MESSAGE                 200
+/*
+ * Messaging irq; see irq_64.h and include/asm-x86/hw_irq_64.h
+ * To be dynamically allocated in the future
+ */
+#define UV_NET_ENDPOINT_INTD           0x38
+#define UV_DESC_BASE_PNODE_SHIFT       49
+#define UV_PAYLOADQ_PNODE_SHIFT                49
+#define UV_PTC_BASENAME                        "sgi_uv/ptc_statistics"
+#define uv_physnodeaddr(x)             ((__pa((unsigned long)(x)) & uv_mmask))
+
+/*
+ * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1
+ */
+#define DESC_STATUS_IDLE               0
+#define DESC_STATUS_ACTIVE             1
+#define DESC_STATUS_DESTINATION_TIMEOUT        2
+#define DESC_STATUS_SOURCE_TIMEOUT     3
+
+/*
+ * source side threshholds at which message retries print a warning
+ */
+#define SOURCE_TIMEOUT_LIMIT           20
+#define DESTINATION_TIMEOUT_LIMIT      20
+
+/*
+ * number of entries in the destination side payload queue
+ */
+#define DEST_Q_SIZE                    17
+/*
+ * number of destination side software ack resources
+ */
+#define DEST_NUM_RESOURCES             8
+#define MAX_CPUS_PER_NODE              32
+/*
+ * completion statuses for sending a TLB flush message
+ */
+#define        FLUSH_RETRY                     1
+#define        FLUSH_GIVEUP                    2
+#define        FLUSH_COMPLETE                  3
+
+/*
+ * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor)
+ * If the 'multilevel' flag in the header portion of the descriptor
+ * has been set to 0, then endpoint multi-unicast mode is selected.
+ * The distribution specification (32 bytes) is interpreted as a 256-bit
+ * distribution vector. Adjacent bits correspond to consecutive even numbered
+ * nodeIDs. The result of adding the index of a given bit to the 15-bit
+ * 'base_dest_nodeid' field of the header corresponds to the
+ * destination nodeID associated with that specified bit.
+ */
+struct bau_target_nodemask {
+       unsigned long bits[BITS_TO_LONGS(256)];
+};
+
+/*
+ * mask of cpu's on a node
+ * (during initialization we need to check that unsigned long has
+ *  enough bits for max. cpu's per node)
+ */
+struct bau_local_cpumask {
+       unsigned long bits;
+};
+
+/*
+ * Payload: 16 bytes (128 bits) (bytes 0x20-0x2f of descriptor)
+ * only 12 bytes (96 bits) of the payload area are usable.
+ * An additional 3 bytes (bits 27:4) of the header address are carried
+ * to the next bytes of the destination payload queue.
+ * And an additional 2 bytes of the header Suppl_A field are also
+ * carried to the destination payload queue.
+ * But the first byte of the Suppl_A becomes bits 127:120 (the 16th byte)
+ * of the destination payload queue, which is written by the hardware
+ * with the s/w ack resource bit vector.
+ * [ effective message contents (16 bytes (128 bits) maximum), not counting
+ *   the s/w ack bit vector  ]
+ */
+
+/*
+ * The payload is software-defined for INTD transactions
+ */
+struct bau_msg_payload {
+       unsigned long address;          /* signifies a page or all TLB's
+                                               of the cpu */
+       /* 64 bits */
+       unsigned short sending_cpu;     /* filled in by sender */
+       /* 16 bits */
+       unsigned short acknowledge_count;/* filled in by destination */
+       /* 16 bits */
+       unsigned int reserved1:32;      /* not usable */
+};
+
+
+/*
+ * Message header:  16 bytes (128 bits) (bytes 0x30-0x3f of descriptor)
+ * see table 4.2.3.0.1 in broacast_assist spec.
+ */
+struct bau_msg_header {
+       int dest_subnodeid:6;   /* must be zero */
+       /* bits 5:0 */
+       int base_dest_nodeid:15; /* nasid>>1 (pnode) of first bit in node_map */
+       /* bits 20:6 */
+       int command:8;          /* message type */
+       /* bits 28:21 */
+                               /* 0x38: SN3net EndPoint Message */
+       int rsvd_1:3;           /* must be zero */
+       /* bits 31:29 */
+                               /* int will align on 32 bits */
+       int rsvd_2:9;           /* must be zero */
+       /* bits 40:32 */
+                               /* Suppl_A is 56-41 */
+       int payload_2a:8;       /* becomes byte 16 of msg */
+       /* bits 48:41 */        /* not currently using */
+       int payload_2b:8;       /* becomes byte 17 of msg */
+       /* bits 56:49 */        /* not currently using */
+                               /* Address field (96:57) is never used as an
+                                  address (these are address bits 42:3) */
+       int rsvd_3:1;           /* must be zero */
+       /* bit 57 */
+                               /* address bits 27:4 are payload */
+                               /* these 24 bits become bytes 12-14 of msg */
+       int replied_to:1;       /* sent as 0 by the source to byte 12 */
+       /* bit 58 */
+
+       int payload_1a:5;       /* not currently used */
+       /* bits 63:59 */
+       int payload_1b:8;       /* not currently used */
+       /* bits 71:64 */
+       int payload_1c:8;       /* not currently used */
+       /* bits 79:72 */
+       int payload_1d:2;       /* not currently used */
+       /* bits 81:80 */
+
+       int rsvd_4:7;           /* must be zero */
+       /* bits 88:82 */
+       int sw_ack_flag:1;      /* software acknowledge flag */
+       /* bit 89 */
+                               /* INTD trasactions at destination are to
+                                  wait for software acknowledge */
+       int rsvd_5:6;           /* must be zero */
+       /* bits 95:90 */
+       int rsvd_6:5;           /* must be zero */
+       /* bits 100:96 */
+       int int_both:1;         /* if 1, interrupt both sockets on the blade */
+       /* bit 101*/
+       int fairness:3;         /* usually zero */
+       /* bits 104:102 */
+       int multilevel:1;       /* multi-level multicast format */
+       /* bit 105 */
+                               /* 0 for TLB: endpoint multi-unicast messages */
+       int chaining:1;         /* next descriptor is part of this activation*/
+       /* bit 106 */
+       int rsvd_7:21;          /* must be zero */
+       /* bits 127:107 */
+};
+
+/*
+ * The activation descriptor:
+ * The format of the message to send, plus all accompanying control
+ * Should be 64 bytes
+ */
+struct bau_desc {
+       struct bau_target_nodemask distribution;
+       /*
+        * message template, consisting of header and payload:
+        */
+       struct bau_msg_header header;
+       struct bau_msg_payload payload;
+};
+/*
+ *   -payload--    ---------header------
+ *   bytes 0-11    bits 41-56  bits 58-81
+ *       A           B  (2)      C (3)
+ *
+ *            A/B/C are moved to:
+ *       A            C          B
+ *   bytes 0-11  bytes 12-14  bytes 16-17  (byte 15 filled in by hw as vector)
+ *   ------------payload queue-----------
+ */
+
+/*
+ * The payload queue on the destination side is an array of these.
+ * With BAU_MISC_CONTROL set for software acknowledge mode, the messages
+ * are 32 bytes (2 micropackets) (256 bits) in length, but contain only 17
+ * bytes of usable data, including the sw ack vector in byte 15 (bits 127:120)
+ * (12 bytes come from bau_msg_payload, 3 from payload_1, 2 from
+ *  sw_ack_vector and payload_2)
+ * "Enabling Software Acknowledgment mode (see Section 4.3.3 Software
+ *  Acknowledge Processing) also selects 32 byte (17 bytes usable) payload
+ *  operation."
+ */
+struct bau_payload_queue_entry {
+       unsigned long address;          /* signifies a page or all TLB's
+                                               of the cpu */
+       /* 64 bits, bytes 0-7 */
+
+       unsigned short sending_cpu;     /* cpu that sent the message */
+       /* 16 bits, bytes 8-9 */
+
+       unsigned short acknowledge_count; /* filled in by destination */
+       /* 16 bits, bytes 10-11 */
+
+       unsigned short replied_to:1;    /* sent as 0 by the source */
+       /* 1 bit */
+       unsigned short unused1:7;       /* not currently using */
+       /* 7 bits: byte 12) */
+
+       unsigned char unused2[2];       /* not currently using */
+       /* bytes 13-14 */
+
+       unsigned char sw_ack_vector;    /* filled in by the hardware */
+       /* byte 15 (bits 127:120) */
+
+       unsigned char unused4[3];       /* not currently using bytes 17-19 */
+       /* bytes 17-19 */
+
+       int number_of_cpus;             /* filled in at destination */
+       /* 32 bits, bytes 20-23 (aligned) */
+
+       unsigned char unused5[8];       /* not using */
+       /* bytes 24-31 */
+};
+
+/*
+ * one for every slot in the destination payload queue
+ */
+struct bau_msg_status {
+       struct bau_local_cpumask seen_by;       /* map of cpu's */
+};
+
+/*
+ * one for every slot in the destination software ack resources
+ */
+struct bau_sw_ack_status {
+       struct bau_payload_queue_entry *msg;    /* associated message */
+       int watcher;                            /* cpu monitoring, or -1 */
+};
+
+/*
+ * one on every node and per-cpu; to locate the software tables
+ */
+struct bau_control {
+       struct bau_desc *descriptor_base;
+       struct bau_payload_queue_entry *bau_msg_head;
+       struct bau_payload_queue_entry *va_queue_first;
+       struct bau_payload_queue_entry *va_queue_last;
+       struct bau_msg_status *msg_statuses;
+       int *watching; /* pointer to array */
+};
+
+/*
+ * This structure is allocated per_cpu for UV TLB shootdown statistics.
+ */
+struct ptc_stats {
+       unsigned long ptc_i;    /* number of IPI-style flushes */
+       unsigned long requestor;        /* number of nodes this cpu sent to */
+       unsigned long requestee;        /* times cpu was remotely requested */
+       unsigned long alltlb;   /* times all tlb's on this cpu were flushed */
+       unsigned long onetlb;   /* times just one tlb on this cpu was flushed */
+       unsigned long s_retry;  /* retries on source side timeouts */
+       unsigned long d_retry;  /* retries on destination side timeouts */
+       unsigned long sflush;   /* cycles spent in uv_flush_tlb_others */
+       unsigned long dflush;   /* cycles spent on destination side */
+       unsigned long retriesok; /* successes on retries */
+       unsigned long nomsg;    /* interrupts with no message */
+       unsigned long multmsg;  /* interrupts with multiple messages */
+       unsigned long ntargeted;/* nodes targeted */
+};
+
+static inline int bau_node_isset(int node, struct bau_target_nodemask *dstp)
+{
+       return constant_test_bit(node, &dstp->bits[0]);
+}
+static inline void bau_node_set(int node, struct bau_target_nodemask *dstp)
+{
+       __set_bit(node, &dstp->bits[0]);
+}
+static inline void bau_nodes_clear(struct bau_target_nodemask *dstp, int nbits)
+{
+       bitmap_zero(&dstp->bits[0], nbits);
+}
+
+static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits)
+{
+       bitmap_zero(&dstp->bits, nbits);
+}
+
+#define cpubit_isset(cpu, bau_local_cpumask) \
+       test_bit((cpu), (bau_local_cpumask).bits)
+
+extern int uv_flush_tlb_others(cpumask_t *, struct mm_struct *, unsigned long);
+extern void uv_bau_message_intr1(void);
+extern void uv_bau_timeout_intr1(void);
+
+#endif /* __ASM_X86_UV_BAU__ */
index 26b9240..a4ef26e 100644 (file)
@@ -5,7 +5,7 @@
  *
  * SGI UV architectural definitions
  *
- * Copyright (C) 2007 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved.
  */
 
 #ifndef __ASM_X86_UV_HUB_H__
 /*
  * Addressing Terminology
  *
- *     NASID - network ID of a router, Mbrick or Cbrick. Nasid values of
- *             routers always have low bit of 1, C/MBricks have low bit
- *             equal to 0. Most addressing macros that target UV hub chips
- *             right shift the NASID by 1 to exclude the always-zero bit.
+ *     M       - The low M bits of a physical address represent the offset
+ *               into the blade local memory. RAM memory on a blade is physically
+ *               contiguous (although various IO spaces may punch holes in
+ *               it)..
  *
- *     SNASID - NASID right shifted by 1 bit.
+ *     N       - Number of bits in the node portion of a socket physical
+ *               address.
+ *
+ *     NASID   - network ID of a router, Mbrick or Cbrick. Nasid values of
+ *               routers always have low bit of 1, C/MBricks have low bit
+ *               equal to 0. Most addressing macros that target UV hub chips
+ *               right shift the NASID by 1 to exclude the always-zero bit.
+ *               NASIDs contain up to 15 bits.
+ *
+ *     GNODE   - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
+ *               of nasids.
+ *
+ *     PNODE   - the low N bits of the GNODE. The PNODE is the most useful variant
+ *               of the nasid for socket usage.
+ *
+ *
+ *  NumaLink Global Physical Address Format:
+ *  +--------------------------------+---------------------+
+ *  |00..000|      GNODE             |      NodeOffset     |
+ *  +--------------------------------+---------------------+
+ *          |<-------53 - M bits --->|<--------M bits ----->
+ *
+ *     M - number of node offset bits (35 .. 40)
  *
  *
  *  Memory/UV-HUB Processor Socket Address Format:
- *  +--------+---------------+---------------------+
- *  |00..0000|    SNASID     |      NodeOffset     |
- *  +--------+---------------+---------------------+
- *           <--- N bits --->|<--------M bits ----->
+ *  +----------------+---------------+---------------------+
+ *  |00..000000000000|   PNODE       |      NodeOffset     |
+ *  +----------------+---------------+---------------------+
+ *                   <--- N bits --->|<--------M bits ----->
  *
- *     M number of node offset bits (35 .. 40)
- *     N number of SNASID bits (0 .. 10)
+ *     M number of node offset bits (35 .. 40)
+ *     N - number of PNODE bits (0 .. 10)
  *
  *             Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
  *             The actual values are configuration dependent and are set at
- *             boot time
+ *             boot time. M & N values are set by the hardware/BIOS at boot.
+ *
  *
  * APICID format
  *     NOTE!!!!!! This is the current format of the APICID. However, code
  *
  *             1111110000000000
  *             5432109876543210
- *             nnnnnnnnnnlc0cch
+ *             pppppppppplc0cch
  *             sssssssssss
  *
- *                     n  = snasid bits
+ *                     p  = pnode bits
  *                     l =  socket number on board
  *                     c  = core
  *                     h  = hyperthread
- *                     s  = bits that are in the socket CSR
+ *                     s  = bits that are in the SOCKET_ID CSR
  *
  *     Note: Processor only supports 12 bits in the APICID register. The ACPI
  *           tables hold all 16 bits. Software needs to be aware of this.
@@ -74,7 +97,7 @@
  * This value is also the value of the maximum number of non-router NASIDs
  * in the numalink fabric.
  *
- * NOTE: a brick may be 1 or 2 OS nodes. Don't get these confused.
+ * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
  */
 #define UV_MAX_NUMALINK_BLADES 16384
 
  */
 struct uv_hub_info_s {
        unsigned long   global_mmr_base;
-       unsigned short  local_nasid;
-       unsigned short  gnode_upper;
+       unsigned long   gpa_mask;
+       unsigned long   gnode_upper;
+       unsigned long   lowmem_remap_top;
+       unsigned long   lowmem_remap_base;
+       unsigned short  pnode;
+       unsigned short  pnode_mask;
        unsigned short  coherency_domain_number;
        unsigned short  numa_blade_id;
        unsigned char   blade_processor_id;
@@ -112,83 +139,126 @@ DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
  * Local & Global MMR space macros.
  *     Note: macros are intended to be used ONLY by inline functions
  *     in this file - not by other kernel code.
+ *             n -  NASID (full 15-bit global nasid)
+ *             g -  GNODE (full 15-bit global nasid, right shifted 1)
+ *             p -  PNODE (local part of nsids, right shifted 1)
  */
-#define UV_SNASID(n)                   ((n) >> 1)
-#define UV_NASID(n)                    ((n) << 1)
+#define UV_NASID_TO_PNODE(n)           (((n) >> 1) & uv_hub_info->pnode_mask)
+#define UV_PNODE_TO_NASID(p)           (((p) << 1) | uv_hub_info->gnode_upper)
 
 #define UV_LOCAL_MMR_BASE              0xf4000000UL
 #define UV_GLOBAL_MMR32_BASE           0xf8000000UL
 #define UV_GLOBAL_MMR64_BASE           (uv_hub_info->global_mmr_base)
+#define UV_LOCAL_MMR_SIZE              (64UL * 1024 * 1024)
+#define UV_GLOBAL_MMR32_SIZE           (64UL * 1024 * 1024)
 
-#define UV_GLOBAL_MMR32_SNASID_MASK    0x3ff
-#define UV_GLOBAL_MMR32_SNASID_SHIFT   15
-#define UV_GLOBAL_MMR64_SNASID_SHIFT   26
+#define UV_GLOBAL_MMR32_PNODE_SHIFT    15
+#define UV_GLOBAL_MMR64_PNODE_SHIFT    26
 
-#define UV_GLOBAL_MMR32_NASID_BITS(n)                                  \
-               (((UV_SNASID(n) & UV_GLOBAL_MMR32_SNASID_MASK)) <<      \
-               (UV_GLOBAL_MMR32_SNASID_SHIFT))
+#define UV_GLOBAL_MMR32_PNODE_BITS(p)  ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
 
-#define UV_GLOBAL_MMR64_NASID_BITS(n)                                  \
-       ((unsigned long)UV_SNASID(n) << UV_GLOBAL_MMR64_SNASID_SHIFT)
+#define UV_GLOBAL_MMR64_PNODE_BITS(p)                                  \
+       ((unsigned long)(p) << UV_GLOBAL_MMR64_PNODE_SHIFT)
+
+#define UV_APIC_PNODE_SHIFT    6
+
+/*
+ * Macros for converting between kernel virtual addresses, socket local physical
+ * addresses, and UV global physical addresses.
+ *     Note: use the standard __pa() & __va() macros for converting
+ *           between socket virtual and socket physical addresses.
+ */
+
+/* socket phys RAM --> UV global physical address */
+static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
+{
+       if (paddr < uv_hub_info->lowmem_remap_top)
+               paddr += uv_hub_info->lowmem_remap_base;
+       return paddr | uv_hub_info->gnode_upper;
+}
+
+
+/* socket virtual --> UV global physical address */
+static inline unsigned long uv_gpa(void *v)
+{
+       return __pa(v) | uv_hub_info->gnode_upper;
+}
+
+/* socket virtual --> UV global physical address */
+static inline void *uv_vgpa(void *v)
+{
+       return (void *)uv_gpa(v);
+}
+
+/* UV global physical address --> socket virtual */
+static inline void *uv_va(unsigned long gpa)
+{
+       return __va(gpa & uv_hub_info->gpa_mask);
+}
+
+/* pnode, offset --> socket virtual */
+static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
+{
+       return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
+}
 
-#define UV_APIC_NASID_SHIFT    6
 
 /*
- * Extract a NASID from an APICID (full apicid, not processor subset)
+ * Extract a PNODE from an APICID (full apicid, not processor subset)
  */
-static inline int uv_apicid_to_nasid(int apicid)
+static inline int uv_apicid_to_pnode(int apicid)
 {
-       return (UV_NASID(apicid >> UV_APIC_NASID_SHIFT));
+       return (apicid >> UV_APIC_PNODE_SHIFT);
 }
 
 /*
  * Access global MMRs using the low memory MMR32 space. This region supports
  * faster MMR access but not all MMRs are accessible in this space.
  */
-static inline unsigned long *uv_global_mmr32_address(int nasid,
+static inline unsigned long *uv_global_mmr32_address(int pnode,
                                unsigned long offset)
 {
        return __va(UV_GLOBAL_MMR32_BASE |
-                      UV_GLOBAL_MMR32_NASID_BITS(nasid) | offset);
+                      UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
 }
 
-static inline void uv_write_global_mmr32(int nasid, unsigned long offset,
+static inline void uv_write_global_mmr32(int pnode, unsigned long offset,
                                 unsigned long val)
 {
-       *uv_global_mmr32_address(nasid, offset) = val;
+       *uv_global_mmr32_address(pnode, offset) = val;
 }
 
-static inline unsigned long uv_read_global_mmr32(int nasid,
+static inline unsigned long uv_read_global_mmr32(int pnode,
                                                 unsigned long offset)
 {
-       return *uv_global_mmr32_address(nasid, offset);
+       return *uv_global_mmr32_address(pnode, offset);
 }
 
 /*
  * Access Global MMR space using the MMR space located at the top of physical
  * memory.
  */
-static inline unsigned long *uv_global_mmr64_address(int nasid,
+static inline unsigned long *uv_global_mmr64_address(int pnode,
                                unsigned long offset)
 {
        return __va(UV_GLOBAL_MMR64_BASE |
-                      UV_GLOBAL_MMR64_NASID_BITS(nasid) | offset);
+                   UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
 }
 
-static inline void uv_write_global_mmr64(int nasid, unsigned long offset,
+static inline void uv_write_global_mmr64(int pnode, unsigned long offset,
                                unsigned long val)
 {
-       *uv_global_mmr64_address(nasid, offset) = val;
+       *uv_global_mmr64_address(pnode, offset) = val;
 }
 
-static inline unsigned long uv_read_global_mmr64(int nasid,
+static inline unsigned long uv_read_global_mmr64(int pnode,
                                                 unsigned long offset)
 {
-       return *uv_global_mmr64_address(nasid, offset);
+       return *uv_global_mmr64_address(pnode, offset);
 }
 
 /*
- * Access node local MMRs. Faster than using global space but only local MMRs
+ * Access hub local MMRs. Faster than using global space but only local MMRs
  * are accessible.
  */
 static inline unsigned long *uv_local_mmr_address(unsigned long offset)
@@ -207,15 +277,15 @@ static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
 }
 
 /*
- * Structures and definitions for converting between cpu, node, and blade
+ * Structures and definitions for converting between cpu, node, pnode, and blade
  * numbers.
  */
 struct uv_blade_info {
-       unsigned short  nr_posible_cpus;
+       unsigned short  nr_possible_cpus;
        unsigned short  nr_online_cpus;
-       unsigned short  nasid;
+       unsigned short  pnode;
 };
-struct uv_blade_info *uv_blade_info;
+extern struct uv_blade_info *uv_blade_info;
 extern short *uv_node_to_blade;
 extern short *uv_cpu_to_blade;
 extern short uv_possible_blades;
@@ -244,16 +314,16 @@ static inline int uv_node_to_blade_id(int nid)
        return uv_node_to_blade[nid];
 }
 
-/* Convert a blade id to the NASID of the blade */
-static inline int uv_blade_to_nasid(int bid)
+/* Convert a blade id to the PNODE of the blade */
+static inline int uv_blade_to_pnode(int bid)
 {
-       return uv_blade_info[bid].nasid;
+       return uv_blade_info[bid].pnode;
 }
 
 /* Determine the number of possible cpus on a blade */
 static inline int uv_blade_nr_possible_cpus(int bid)
 {
-       return uv_blade_info[bid].nr_posible_cpus;
+       return uv_blade_info[bid].nr_possible_cpus;
 }
 
 /* Determine the number of online cpus on a blade */
@@ -262,16 +332,16 @@ static inline int uv_blade_nr_online_cpus(int bid)
        return uv_blade_info[bid].nr_online_cpus;
 }
 
-/* Convert a cpu id to the NASID of the blade containing the cpu */
-static inline int uv_cpu_to_nasid(int cpu)
+/* Convert a cpu id to the PNODE of the blade containing the cpu */
+static inline int uv_cpu_to_pnode(int cpu)
 {
-       return uv_blade_info[uv_cpu_to_blade_id(cpu)].nasid;
+       return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
 }
 
-/* Convert a node number to the NASID of the blade */
-static inline int uv_node_to_nasid(int nid)
+/* Convert a linux node number to the PNODE of the blade */
+static inline int uv_node_to_pnode(int nid)
 {
-       return uv_blade_info[uv_node_to_blade_id(nid)].nasid;
+       return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
 }
 
 /* Maximum possible number of blades */
index 3b69fe6..151fd7f 100644 (file)
 #ifndef __ASM_X86_UV_MMRS__
 #define __ASM_X86_UV_MMRS__
 
-/*
- *       AUTO GENERATED - Do not edit
- */
+#define UV_MMR_ENABLE          (1UL << 63)
+
+/* ========================================================================= */
+/*                           UVH_BAU_DATA_CONFIG                             */
+/* ========================================================================= */
+#define UVH_BAU_DATA_CONFIG 0x61680UL
+#define UVH_BAU_DATA_CONFIG_32 0x0438
+
+#define UVH_BAU_DATA_CONFIG_VECTOR_SHFT 0
+#define UVH_BAU_DATA_CONFIG_VECTOR_MASK 0x00000000000000ffUL
+#define UVH_BAU_DATA_CONFIG_DM_SHFT 8
+#define UVH_BAU_DATA_CONFIG_DM_MASK 0x0000000000000700UL
+#define UVH_BAU_DATA_CONFIG_DESTMODE_SHFT 11
+#define UVH_BAU_DATA_CONFIG_DESTMODE_MASK 0x0000000000000800UL
+#define UVH_BAU_DATA_CONFIG_STATUS_SHFT 12
+#define UVH_BAU_DATA_CONFIG_STATUS_MASK 0x0000000000001000UL
+#define UVH_BAU_DATA_CONFIG_P_SHFT 13
+#define UVH_BAU_DATA_CONFIG_P_MASK 0x0000000000002000UL
+#define UVH_BAU_DATA_CONFIG_T_SHFT 15
+#define UVH_BAU_DATA_CONFIG_T_MASK 0x0000000000008000UL
+#define UVH_BAU_DATA_CONFIG_M_SHFT 16
+#define UVH_BAU_DATA_CONFIG_M_MASK 0x0000000000010000UL
+#define UVH_BAU_DATA_CONFIG_APIC_ID_SHFT 32
+#define UVH_BAU_DATA_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
+
+union uvh_bau_data_config_u {
+    unsigned long      v;
+    struct uvh_bau_data_config_s {
+       unsigned long   vector_  :  8;  /* RW */
+       unsigned long   dm       :  3;  /* RW */
+       unsigned long   destmode :  1;  /* RW */
+       unsigned long   status   :  1;  /* RO */
+       unsigned long   p        :  1;  /* RO */
+       unsigned long   rsvd_14  :  1;  /*    */
+       unsigned long   t        :  1;  /* RO */
+       unsigned long   m        :  1;  /* RW */
+       unsigned long   rsvd_17_31: 15;  /*    */
+       unsigned long   apic_id  : 32;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                           UVH_EVENT_OCCURRED0                             */
+/* ========================================================================= */
+#define UVH_EVENT_OCCURRED0 0x70000UL
+#define UVH_EVENT_OCCURRED0_32 0x005e8
+
+#define UVH_EVENT_OCCURRED0_LB_HCERR_SHFT 0
+#define UVH_EVENT_OCCURRED0_LB_HCERR_MASK 0x0000000000000001UL
+#define UVH_EVENT_OCCURRED0_GR0_HCERR_SHFT 1
+#define UVH_EVENT_OCCURRED0_GR0_HCERR_MASK 0x0000000000000002UL
+#define UVH_EVENT_OCCURRED0_GR1_HCERR_SHFT 2
+#define UVH_EVENT_OCCURRED0_GR1_HCERR_MASK 0x0000000000000004UL
+#define UVH_EVENT_OCCURRED0_LH_HCERR_SHFT 3
+#define UVH_EVENT_OCCURRED0_LH_HCERR_MASK 0x0000000000000008UL
+#define UVH_EVENT_OCCURRED0_RH_HCERR_SHFT 4
+#define UVH_EVENT_OCCURRED0_RH_HCERR_MASK 0x0000000000000010UL
+#define UVH_EVENT_OCCURRED0_XN_HCERR_SHFT 5
+#define UVH_EVENT_OCCURRED0_XN_HCERR_MASK 0x0000000000000020UL
+#define UVH_EVENT_OCCURRED0_SI_HCERR_SHFT 6
+#define UVH_EVENT_OCCURRED0_SI_HCERR_MASK 0x0000000000000040UL
+#define UVH_EVENT_OCCURRED0_LB_AOERR0_SHFT 7
+#define UVH_EVENT_OCCURRED0_LB_AOERR0_MASK 0x0000000000000080UL
+#define UVH_EVENT_OCCURRED0_GR0_AOERR0_SHFT 8
+#define UVH_EVENT_OCCURRED0_GR0_AOERR0_MASK 0x0000000000000100UL
+#define UVH_EVENT_OCCURRED0_GR1_AOERR0_SHFT 9
+#define UVH_EVENT_OCCURRED0_GR1_AOERR0_MASK 0x0000000000000200UL
+#define UVH_EVENT_OCCURRED0_LH_AOERR0_SHFT 10
+#define UVH_EVENT_OCCURRED0_LH_AOERR0_MASK 0x0000000000000400UL
+#define UVH_EVENT_OCCURRED0_RH_AOERR0_SHFT 11
+#define UVH_EVENT_OCCURRED0_RH_AOERR0_MASK 0x0000000000000800UL
+#define UVH_EVENT_OCCURRED0_XN_AOERR0_SHFT 12
+#define UVH_EVENT_OCCURRED0_XN_AOERR0_MASK 0x0000000000001000UL
+#define UVH_EVENT_OCCURRED0_SI_AOERR0_SHFT 13
+#define UVH_EVENT_OCCURRED0_SI_AOERR0_MASK 0x0000000000002000UL
+#define UVH_EVENT_OCCURRED0_LB_AOERR1_SHFT 14
+#define UVH_EVENT_OCCURRED0_LB_AOERR1_MASK 0x0000000000004000UL
+#define UVH_EVENT_OCCURRED0_GR0_AOERR1_SHFT 15
+#define UVH_EVENT_OCCURRED0_GR0_AOERR1_MASK 0x0000000000008000UL
+#define UVH_EVENT_OCCURRED0_GR1_AOERR1_SHFT 16
+#define UVH_EVENT_OCCURRED0_GR1_AOERR1_MASK 0x0000000000010000UL
+#define UVH_EVENT_OCCURRED0_LH_AOERR1_SHFT 17
+#define UVH_EVENT_OCCURRED0_LH_AOERR1_MASK 0x0000000000020000UL
+#define UVH_EVENT_OCCURRED0_RH_AOERR1_SHFT 18
+#define UVH_EVENT_OCCURRED0_RH_AOERR1_MASK 0x0000000000040000UL
+#define UVH_EVENT_OCCURRED0_XN_AOERR1_SHFT 19
+#define UVH_EVENT_OCCURRED0_XN_AOERR1_MASK 0x0000000000080000UL
+#define UVH_EVENT_OCCURRED0_SI_AOERR1_SHFT 20
+#define UVH_EVENT_OCCURRED0_SI_AOERR1_MASK 0x0000000000100000UL
+#define UVH_EVENT_OCCURRED0_RH_VPI_INT_SHFT 21
+#define UVH_EVENT_OCCURRED0_RH_VPI_INT_MASK 0x0000000000200000UL
+#define UVH_EVENT_OCCURRED0_SYSTEM_SHUTDOWN_INT_SHFT 22
+#define UVH_EVENT_OCCURRED0_SYSTEM_SHUTDOWN_INT_MASK 0x0000000000400000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_0_SHFT 23
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_0_MASK 0x0000000000800000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_1_SHFT 24
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_1_MASK 0x0000000001000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_2_SHFT 25
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_2_MASK 0x0000000002000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_3_SHFT 26
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_3_MASK 0x0000000004000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_4_SHFT 27
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_4_MASK 0x0000000008000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_5_SHFT 28
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_5_MASK 0x0000000010000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_6_SHFT 29
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_6_MASK 0x0000000020000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_7_SHFT 30
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_7_MASK 0x0000000040000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_8_SHFT 31
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_8_MASK 0x0000000080000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_9_SHFT 32
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_9_MASK 0x0000000100000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_10_SHFT 33
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_10_MASK 0x0000000200000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_11_SHFT 34
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_11_MASK 0x0000000400000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_12_SHFT 35
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_12_MASK 0x0000000800000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_13_SHFT 36
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_13_MASK 0x0000001000000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_14_SHFT 37
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_14_MASK 0x0000002000000000UL
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_15_SHFT 38
+#define UVH_EVENT_OCCURRED0_LB_IRQ_INT_15_MASK 0x0000004000000000UL
+#define UVH_EVENT_OCCURRED0_L1_NMI_INT_SHFT 39
+#define UVH_EVENT_OCCURRED0_L1_NMI_INT_MASK 0x0000008000000000UL
+#define UVH_EVENT_OCCURRED0_STOP_CLOCK_SHFT 40
+#define UVH_EVENT_OCCURRED0_STOP_CLOCK_MASK 0x0000010000000000UL
+#define UVH_EVENT_OCCURRED0_ASIC_TO_L1_SHFT 41
+#define UVH_EVENT_OCCURRED0_ASIC_TO_L1_MASK 0x0000020000000000UL
+#define UVH_EVENT_OCCURRED0_L1_TO_ASIC_SHFT 42
+#define UVH_EVENT_OCCURRED0_L1_TO_ASIC_MASK 0x0000040000000000UL
+#define UVH_EVENT_OCCURRED0_LTC_INT_SHFT 43
+#define UVH_EVENT_OCCURRED0_LTC_INT_MASK 0x0000080000000000UL
+#define UVH_EVENT_OCCURRED0_LA_SEQ_TRIGGER_SHFT 44
+#define UVH_EVENT_OCCURRED0_LA_SEQ_TRIGGER_MASK 0x0000100000000000UL
+#define UVH_EVENT_OCCURRED0_IPI_INT_SHFT 45
+#define UVH_EVENT_OCCURRED0_IPI_INT_MASK 0x0000200000000000UL
+#define UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT 46
+#define UVH_EVENT_OCCURRED0_EXTIO_INT0_MASK 0x0000400000000000UL
+#define UVH_EVENT_OCCURRED0_EXTIO_INT1_SHFT 47
+#define UVH_EVENT_OCCURRED0_EXTIO_INT1_MASK 0x0000800000000000UL
+#define UVH_EVENT_OCCURRED0_EXTIO_INT2_SHFT 48
+#define UVH_EVENT_OCCURRED0_EXTIO_INT2_MASK 0x0001000000000000UL
+#define UVH_EVENT_OCCURRED0_EXTIO_INT3_SHFT 49
+#define UVH_EVENT_OCCURRED0_EXTIO_INT3_MASK 0x0002000000000000UL
+#define UVH_EVENT_OCCURRED0_PROFILE_INT_SHFT 50
+#define UVH_EVENT_OCCURRED0_PROFILE_INT_MASK 0x0004000000000000UL
+#define UVH_EVENT_OCCURRED0_RTC0_SHFT 51
+#define UVH_EVENT_OCCURRED0_RTC0_MASK 0x0008000000000000UL
+#define UVH_EVENT_OCCURRED0_RTC1_SHFT 52
+#define UVH_EVENT_OCCURRED0_RTC1_MASK 0x0010000000000000UL
+#define UVH_EVENT_OCCURRED0_RTC2_SHFT 53
+#define UVH_EVENT_OCCURRED0_RTC2_MASK 0x0020000000000000UL
+#define UVH_EVENT_OCCURRED0_RTC3_SHFT 54
+#define UVH_EVENT_OCCURRED0_RTC3_MASK 0x0040000000000000UL
+#define UVH_EVENT_OCCURRED0_BAU_DATA_SHFT 55
+#define UVH_EVENT_OCCURRED0_BAU_DATA_MASK 0x0080000000000000UL
+#define UVH_EVENT_OCCURRED0_POWER_MANAGEMENT_REQ_SHFT 56
+#define UVH_EVENT_OCCURRED0_POWER_MANAGEMENT_REQ_MASK 0x0100000000000000UL
+union uvh_event_occurred0_u {
+    unsigned long      v;
+    struct uvh_event_occurred0_s {
+       unsigned long   lb_hcerr             :  1;  /* RW, W1C */
+       unsigned long   gr0_hcerr            :  1;  /* RW, W1C */
+       unsigned long   gr1_hcerr            :  1;  /* RW, W1C */
+       unsigned long   lh_hcerr             :  1;  /* RW, W1C */
+       unsigned long   rh_hcerr             :  1;  /* RW, W1C */
+       unsigned long   xn_hcerr             :  1;  /* RW, W1C */
+       unsigned long   si_hcerr             :  1;  /* RW, W1C */
+       unsigned long   lb_aoerr0            :  1;  /* RW, W1C */
+       unsigned long   gr0_aoerr0           :  1;  /* RW, W1C */
+       unsigned long   gr1_aoerr0           :  1;  /* RW, W1C */
+       unsigned long   lh_aoerr0            :  1;  /* RW, W1C */
+       unsigned long   rh_aoerr0            :  1;  /* RW, W1C */
+       unsigned long   xn_aoerr0            :  1;  /* RW, W1C */
+       unsigned long   si_aoerr0            :  1;  /* RW, W1C */
+       unsigned long   lb_aoerr1            :  1;  /* RW, W1C */
+       unsigned long   gr0_aoerr1           :  1;  /* RW, W1C */
+       unsigned long   gr1_aoerr1           :  1;  /* RW, W1C */
+       unsigned long   lh_aoerr1            :  1;  /* RW, W1C */
+       unsigned long   rh_aoerr1            :  1;  /* RW, W1C */
+       unsigned long   xn_aoerr1            :  1;  /* RW, W1C */
+       unsigned long   si_aoerr1            :  1;  /* RW, W1C */
+       unsigned long   rh_vpi_int           :  1;  /* RW, W1C */
+       unsigned long   system_shutdown_int  :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_0         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_1         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_2         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_3         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_4         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_5         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_6         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_7         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_8         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_9         :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_10        :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_11        :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_12        :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_13        :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_14        :  1;  /* RW, W1C */
+       unsigned long   lb_irq_int_15        :  1;  /* RW, W1C */
+       unsigned long   l1_nmi_int           :  1;  /* RW, W1C */
+       unsigned long   stop_clock           :  1;  /* RW, W1C */
+       unsigned long   asic_to_l1           :  1;  /* RW, W1C */
+       unsigned long   l1_to_asic           :  1;  /* RW, W1C */
+       unsigned long   ltc_int              :  1;  /* RW, W1C */
+       unsigned long   la_seq_trigger       :  1;  /* RW, W1C */
+       unsigned long   ipi_int              :  1;  /* RW, W1C */
+       unsigned long   extio_int0           :  1;  /* RW, W1C */
+       unsigned long   extio_int1           :  1;  /* RW, W1C */
+       unsigned long   extio_int2           :  1;  /* RW, W1C */
+       unsigned long   extio_int3           :  1;  /* RW, W1C */
+       unsigned long   profile_int          :  1;  /* RW, W1C */
+       unsigned long   rtc0                 :  1;  /* RW, W1C */
+       unsigned long   rtc1                 :  1;  /* RW, W1C */
+       unsigned long   rtc2                 :  1;  /* RW, W1C */
+       unsigned long   rtc3                 :  1;  /* RW, W1C */
+       unsigned long   bau_data             :  1;  /* RW, W1C */
+       unsigned long   power_management_req :  1;  /* RW, W1C */
+       unsigned long   rsvd_57_63           :  7;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                        UVH_EVENT_OCCURRED0_ALIAS                          */
+/* ========================================================================= */
+#define UVH_EVENT_OCCURRED0_ALIAS 0x0000000000070008UL
+#define UVH_EVENT_OCCURRED0_ALIAS_32 0x005f0
+
+/* ========================================================================= */
+/*                               UVH_INT_CMPB                                */
+/* ========================================================================= */
+#define UVH_INT_CMPB 0x22080UL
+
+#define UVH_INT_CMPB_REAL_TIME_CMPB_SHFT 0
+#define UVH_INT_CMPB_REAL_TIME_CMPB_MASK 0x00ffffffffffffffUL
+
+union uvh_int_cmpb_u {
+    unsigned long      v;
+    struct uvh_int_cmpb_s {
+       unsigned long   real_time_cmpb : 56;  /* RW */
+       unsigned long   rsvd_56_63     :  8;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                               UVH_INT_CMPC                                */
+/* ========================================================================= */
+#define UVH_INT_CMPC 0x22100UL
+
+#define UVH_INT_CMPC_REAL_TIME_CMPC_SHFT 0
+#define UVH_INT_CMPC_REAL_TIME_CMPC_MASK 0x00ffffffffffffffUL
+
+union uvh_int_cmpc_u {
+    unsigned long      v;
+    struct uvh_int_cmpc_s {
+       unsigned long   real_time_cmpc : 56;  /* RW */
+       unsigned long   rsvd_56_63     :  8;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                               UVH_INT_CMPD                                */
+/* ========================================================================= */
+#define UVH_INT_CMPD 0x22180UL
 
- #define UV_MMR_ENABLE         (1UL << 63)
+#define UVH_INT_CMPD_REAL_TIME_CMPD_SHFT 0
+#define UVH_INT_CMPD_REAL_TIME_CMPD_MASK 0x00ffffffffffffffUL
+
+union uvh_int_cmpd_u {
+    unsigned long      v;
+    struct uvh_int_cmpd_s {
+       unsigned long   real_time_cmpd : 56;  /* RW */
+       unsigned long   rsvd_56_63     :  8;  /*    */
+    } s;
+};
 
 /* ========================================================================= */
 /*                               UVH_IPI_INT                                 */
 /* ========================================================================= */
 #define UVH_IPI_INT 0x60500UL
-#define UVH_IPI_INT_32 0x0360
+#define UVH_IPI_INT_32 0x0348
 
 #define UVH_IPI_INT_VECTOR_SHFT 0
 #define UVH_IPI_INT_VECTOR_MASK 0x00000000000000ffUL
@@ -51,7 +324,7 @@ union uvh_ipi_int_u {
 /*                   UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST                     */
 /* ========================================================================= */
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST 0x320050UL
-#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST_32 0x009f0
+#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST_32 0x009c0
 
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST_ADDRESS_SHFT 4
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST_ADDRESS_MASK 0x000007fffffffff0UL
@@ -73,7 +346,7 @@ union uvh_lb_bau_intd_payload_queue_first_u {
 /*                    UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST                     */
 /* ========================================================================= */
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST 0x320060UL
-#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST_32 0x009f8
+#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST_32 0x009c8
 
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST_ADDRESS_SHFT 4
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST_ADDRESS_MASK 0x000007fffffffff0UL
@@ -91,7 +364,7 @@ union uvh_lb_bau_intd_payload_queue_last_u {
 /*                    UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL                     */
 /* ========================================================================= */
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL 0x320070UL
-#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL_32 0x00a00
+#define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL_32 0x009d0
 
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL_ADDRESS_SHFT 4
 #define UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL_ADDRESS_MASK 0x000007fffffffff0UL
@@ -109,6 +382,7 @@ union uvh_lb_bau_intd_payload_queue_tail_u {
 /*                   UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE                    */
 /* ========================================================================= */
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE 0x320080UL
+#define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_32 0x0a68
 
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_PENDING_0_SHFT 0
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_PENDING_0_MASK 0x0000000000000001UL
@@ -169,12 +443,13 @@ union uvh_lb_bau_intd_software_acknowledge_u {
 /*                UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS                 */
 /* ========================================================================= */
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS 0x0000000000320088UL
+#define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS_32 0x0a70
 
 /* ========================================================================= */
 /*                     UVH_LB_BAU_SB_ACTIVATION_CONTROL                      */
 /* ========================================================================= */
 #define UVH_LB_BAU_SB_ACTIVATION_CONTROL 0x320020UL
-#define UVH_LB_BAU_SB_ACTIVATION_CONTROL_32 0x009d8
+#define UVH_LB_BAU_SB_ACTIVATION_CONTROL_32 0x009a8
 
 #define UVH_LB_BAU_SB_ACTIVATION_CONTROL_INDEX_SHFT 0
 #define UVH_LB_BAU_SB_ACTIVATION_CONTROL_INDEX_MASK 0x000000000000003fUL
@@ -197,7 +472,7 @@ union uvh_lb_bau_sb_activation_control_u {
 /*                    UVH_LB_BAU_SB_ACTIVATION_STATUS_0                      */
 /* ========================================================================= */
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_0 0x320030UL
-#define UVH_LB_BAU_SB_ACTIVATION_STATUS_0_32 0x009e0
+#define UVH_LB_BAU_SB_ACTIVATION_STATUS_0_32 0x009b0
 
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_0_STATUS_SHFT 0
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_0_STATUS_MASK 0xffffffffffffffffUL
@@ -213,7 +488,7 @@ union uvh_lb_bau_sb_activation_status_0_u {
 /*                    UVH_LB_BAU_SB_ACTIVATION_STATUS_1                      */
 /* ========================================================================= */
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_1 0x320040UL
-#define UVH_LB_BAU_SB_ACTIVATION_STATUS_1_32 0x009e8
+#define UVH_LB_BAU_SB_ACTIVATION_STATUS_1_32 0x009b8
 
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_1_STATUS_SHFT 0
 #define UVH_LB_BAU_SB_ACTIVATION_STATUS_1_STATUS_MASK 0xffffffffffffffffUL
@@ -229,7 +504,7 @@ union uvh_lb_bau_sb_activation_status_1_u {
 /*                      UVH_LB_BAU_SB_DESCRIPTOR_BASE                        */
 /* ========================================================================= */
 #define UVH_LB_BAU_SB_DESCRIPTOR_BASE 0x320010UL
-#define UVH_LB_BAU_SB_DESCRIPTOR_BASE_32 0x009d0
+#define UVH_LB_BAU_SB_DESCRIPTOR_BASE_32 0x009a0
 
 #define UVH_LB_BAU_SB_DESCRIPTOR_BASE_PAGE_ADDRESS_SHFT 12
 #define UVH_LB_BAU_SB_DESCRIPTOR_BASE_PAGE_ADDRESS_MASK 0x000007fffffff000UL
@@ -247,6 +522,334 @@ union uvh_lb_bau_sb_descriptor_base_u {
     } s;
 };
 
+/* ========================================================================= */
+/*                      UVH_LB_MCAST_AOERR0_RPT_ENABLE                       */
+/* ========================================================================= */
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE 0x50b20UL
+
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_SHFT 0
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_MASK 0x0000000000000001UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_SHFT 1
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_MASK 0x0000000000000002UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_SHFT 2
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_MASK 0x0000000000000004UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_SHFT 3
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_MASK 0x0000000000000008UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_SHFT 4
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_MASK 0x0000000000000010UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_SHFT 5
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_MASK 0x0000000000000020UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_SHFT 6
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_MASK 0x0000000000000040UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_SHFT 7
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_MASK 0x0000000000000080UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_SHFT 8
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_MASK 0x0000000000000100UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_SHFT 9
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_MASK 0x0000000000000200UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_SHFT 10
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_MASK 0x0000000000000400UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_SHFT 11
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_MASK 0x0000000000000800UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_SHFT 12
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_MASK 0x0000000000001000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_SHFT 13
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_MASK 0x0000000000002000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_SHFT 14
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_MASK 0x0000000000004000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_SHFT 15
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_MASK 0x0000000000008000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_SHFT 16
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_MASK 0x0000000000010000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_SHFT 17
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_MASK 0x0000000000020000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_SHFT 18
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_MASK 0x0000000000040000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_SHFT 19
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_MASK 0x0000000000080000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_SHFT 20
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_MASK 0x0000000000100000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_SHFT 21
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_MASK 0x0000000000200000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_SHFT 22
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_MASK 0x0000000000400000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_SHFT 23
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_MASK 0x0000000000800000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_SHFT 24
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_MASK 0x0000000001000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_SHFT 25
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_MASK 0x0000000002000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_SHFT 26
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_MASK 0x0000000004000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_SHFT 27
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_MASK 0x0000000008000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_SHFT 28
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_MASK 0x0000000010000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_SHFT 29
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_MASK 0x0000000020000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_SHFT 30
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_MASK 0x0000000040000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_SHFT 31
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_MASK 0x0000000080000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_SHFT 32
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_MASK 0x0000000100000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_SHFT 33
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_MASK 0x0000000200000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_SHFT 34
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_MASK 0x0000000400000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_SHFT 35
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_MASK 0x0000000800000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_SHFT 36
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_MASK 0x0000001000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_SHFT 37
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_MASK 0x0000002000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_SHFT 38
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_MASK 0x0000004000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_SHFT 39
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_MASK 0x0000008000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_SHFT 40
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_MASK 0x0000010000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_SHFT 41
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_MASK 0x0000020000000000UL
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_SHFT 42
+#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_MASK 0x0000040000000000UL
+
+union uvh_lb_mcast_aoerr0_rpt_enable_u {
+    unsigned long      v;
+    struct uvh_lb_mcast_aoerr0_rpt_enable_s {
+       unsigned long   mcast_obese_msg                         :  1;  /* RW */
+       unsigned long   mcast_data_sb_err                       :  1;  /* RW */
+       unsigned long   mcast_nack_buff_parity                  :  1;  /* RW */
+       unsigned long   mcast_timeout                           :  1;  /* RW */
+       unsigned long   mcast_inactive_reply                    :  1;  /* RW */
+       unsigned long   mcast_upgrade_error                     :  1;  /* RW */
+       unsigned long   mcast_reg_count_underflow               :  1;  /* RW */
+       unsigned long   mcast_rep_obese_msg                     :  1;  /* RW */
+       unsigned long   ucache_req_runt_msg                     :  1;  /* RW */
+       unsigned long   ucache_req_obese_msg                    :  1;  /* RW */
+       unsigned long   ucache_req_data_sb_err                  :  1;  /* RW */
+       unsigned long   ucache_rep_runt_msg                     :  1;  /* RW */
+       unsigned long   ucache_rep_obese_msg                    :  1;  /* RW */
+       unsigned long   ucache_rep_data_sb_err                  :  1;  /* RW */
+       unsigned long   ucache_rep_command_err                  :  1;  /* RW */
+       unsigned long   ucache_pend_timeout                     :  1;  /* RW */
+       unsigned long   macc_req_runt_msg                       :  1;  /* RW */
+       unsigned long   macc_req_obese_msg                      :  1;  /* RW */
+       unsigned long   macc_req_data_sb_err                    :  1;  /* RW */
+       unsigned long   macc_rep_runt_msg                       :  1;  /* RW */
+       unsigned long   macc_rep_obese_msg                      :  1;  /* RW */
+       unsigned long   macc_rep_data_sb_err                    :  1;  /* RW */
+       unsigned long   macc_amo_timeout                        :  1;  /* RW */
+       unsigned long   macc_put_timeout                        :  1;  /* RW */
+       unsigned long   macc_spurious_event                     :  1;  /* RW */
+       unsigned long   ioh_destination_table_parity            :  1;  /* RW */
+       unsigned long   get_had_error_reply                     :  1;  /* RW */
+       unsigned long   get_timeout                             :  1;  /* RW */
+       unsigned long   lock_manager_had_error_reply            :  1;  /* RW */
+       unsigned long   put_had_error_reply                     :  1;  /* RW */
+       unsigned long   put_timeout                             :  1;  /* RW */
+       unsigned long   sb_activation_overrun                   :  1;  /* RW */
+       unsigned long   completed_gb_activation_had_error_reply :  1;  /* RW */
+       unsigned long   completed_gb_activation_timeout         :  1;  /* RW */
+       unsigned long   descriptor_buffer_0_parity              :  1;  /* RW */
+       unsigned long   descriptor_buffer_1_parity              :  1;  /* RW */
+       unsigned long   socket_destination_table_parity         :  1;  /* RW */
+       unsigned long   bau_reply_payload_corruption            :  1;  /* RW */
+       unsigned long   io_port_destination_table_parity        :  1;  /* RW */
+       unsigned long   intd_soft_ack_timeout                   :  1;  /* RW */
+       unsigned long   int_rep_obese_msg                       :  1;  /* RW */
+       unsigned long   int_rep_command_err                     :  1;  /* RW */
+       unsigned long   int_timeout                             :  1;  /* RW */
+       unsigned long   rsvd_43_63                              : 21;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                          UVH_LOCAL_INT0_CONFIG                            */
+/* ========================================================================= */
+#define UVH_LOCAL_INT0_CONFIG 0x61000UL
+
+#define UVH_LOCAL_INT0_CONFIG_VECTOR_SHFT 0
+#define UVH_LOCAL_INT0_CONFIG_VECTOR_MASK 0x00000000000000ffUL
+#define UVH_LOCAL_INT0_CONFIG_DM_SHFT 8
+#define UVH_LOCAL_INT0_CONFIG_DM_MASK 0x0000000000000700UL
+#define UVH_LOCAL_INT0_CONFIG_DESTMODE_SHFT 11
+#define UVH_LOCAL_INT0_CONFIG_DESTMODE_MASK 0x0000000000000800UL
+#define UVH_LOCAL_INT0_CONFIG_STATUS_SHFT 12
+#define UVH_LOCAL_INT0_CONFIG_STATUS_MASK 0x0000000000001000UL
+#define UVH_LOCAL_INT0_CONFIG_P_SHFT 13
+#define UVH_LOCAL_INT0_CONFIG_P_MASK 0x0000000000002000UL
+#define UVH_LOCAL_INT0_CONFIG_T_SHFT 15
+#define UVH_LOCAL_INT0_CONFIG_T_MASK 0x0000000000008000UL
+#define UVH_LOCAL_INT0_CONFIG_M_SHFT 16
+#define UVH_LOCAL_INT0_CONFIG_M_MASK 0x0000000000010000UL
+#define UVH_LOCAL_INT0_CONFIG_APIC_ID_SHFT 32
+#define UVH_LOCAL_INT0_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
+
+union uvh_local_int0_config_u {
+    unsigned long      v;
+    struct uvh_local_int0_config_s {
+       unsigned long   vector_  :  8;  /* RW */
+       unsigned long   dm       :  3;  /* RW */
+       unsigned long   destmode :  1;  /* RW */
+       unsigned long   status   :  1;  /* RO */
+       unsigned long   p        :  1;  /* RO */
+       unsigned long   rsvd_14  :  1;  /*    */
+       unsigned long   t        :  1;  /* RO */
+       unsigned long   m        :  1;  /* RW */
+       unsigned long   rsvd_17_31: 15;  /*    */
+       unsigned long   apic_id  : 32;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                          UVH_LOCAL_INT0_ENABLE                            */
+/* ========================================================================= */
+#define UVH_LOCAL_INT0_ENABLE 0x65000UL
+
+#define UVH_LOCAL_INT0_ENABLE_LB_HCERR_SHFT 0
+#define UVH_LOCAL_INT0_ENABLE_LB_HCERR_MASK 0x0000000000000001UL
+#define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_SHFT 1
+#define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_MASK 0x0000000000000002UL
+#define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_SHFT 2
+#define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_MASK 0x0000000000000004UL
+#define UVH_LOCAL_INT0_ENABLE_LH_HCERR_SHFT 3
+#define UVH_LOCAL_INT0_ENABLE_LH_HCERR_MASK 0x0000000000000008UL
+#define UVH_LOCAL_INT0_ENABLE_RH_HCERR_SHFT 4
+#define UVH_LOCAL_INT0_ENABLE_RH_HCERR_MASK 0x0000000000000010UL
+#define UVH_LOCAL_INT0_ENABLE_XN_HCERR_SHFT 5
+#define UVH_LOCAL_INT0_ENABLE_XN_HCERR_MASK 0x0000000000000020UL
+#define UVH_LOCAL_INT0_ENABLE_SI_HCERR_SHFT 6
+#define UVH_LOCAL_INT0_ENABLE_SI_HCERR_MASK 0x0000000000000040UL
+#define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_SHFT 7
+#define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_MASK 0x0000000000000080UL
+#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_SHFT 8
+#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_MASK 0x0000000000000100UL
+#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_SHFT 9
+#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_MASK 0x0000000000000200UL
+#define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_SHFT 10
+#define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_MASK 0x0000000000000400UL
+#define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_SHFT 11
+#define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_MASK 0x0000000000000800UL
+#define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_SHFT 12
+#define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_MASK 0x0000000000001000UL
+#define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_SHFT 13
+#define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_MASK 0x0000000000002000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_SHFT 14
+#define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_MASK 0x0000000000004000UL
+#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_SHFT 15
+#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_MASK 0x0000000000008000UL
+#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_SHFT 16
+#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_MASK 0x0000000000010000UL
+#define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_SHFT 17
+#define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_MASK 0x0000000000020000UL
+#define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_SHFT 18
+#define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_MASK 0x0000000000040000UL
+#define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_SHFT 19
+#define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_MASK 0x0000000000080000UL
+#define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_SHFT 20
+#define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_MASK 0x0000000000100000UL
+#define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_SHFT 21
+#define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_MASK 0x0000000000200000UL
+#define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_SHFT 22
+#define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_MASK 0x0000000000400000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_SHFT 23
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_MASK 0x0000000000800000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_SHFT 24
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_MASK 0x0000000001000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_SHFT 25
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_MASK 0x0000000002000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_SHFT 26
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_MASK 0x0000000004000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_SHFT 27
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_MASK 0x0000000008000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_SHFT 28
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_MASK 0x0000000010000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_SHFT 29
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_MASK 0x0000000020000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_SHFT 30
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_MASK 0x0000000040000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_SHFT 31
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_MASK 0x0000000080000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_SHFT 32
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_MASK 0x0000000100000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_SHFT 33
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_MASK 0x0000000200000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_SHFT 34
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_MASK 0x0000000400000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_SHFT 35
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_MASK 0x0000000800000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_SHFT 36
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_MASK 0x0000001000000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_SHFT 37
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_MASK 0x0000002000000000UL
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_SHFT 38
+#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_MASK 0x0000004000000000UL
+#define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_SHFT 39
+#define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_MASK 0x0000008000000000UL
+#define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_SHFT 40
+#define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_MASK 0x0000010000000000UL
+#define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_SHFT 41
+#define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_MASK 0x0000020000000000UL
+#define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_SHFT 42
+#define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_MASK 0x0000040000000000UL
+#define UVH_LOCAL_INT0_ENABLE_LTC_INT_SHFT 43
+#define UVH_LOCAL_INT0_ENABLE_LTC_INT_MASK 0x0000080000000000UL
+#define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_SHFT 44
+#define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_MASK 0x0000100000000000UL
+
+union uvh_local_int0_enable_u {
+    unsigned long      v;
+    struct uvh_local_int0_enable_s {
+       unsigned long   lb_hcerr            :  1;  /* RW */
+       unsigned long   gr0_hcerr           :  1;  /* RW */
+       unsigned long   gr1_hcerr           :  1;  /* RW */
+       unsigned long   lh_hcerr            :  1;  /* RW */
+       unsigned long   rh_hcerr            :  1;  /* RW */
+       unsigned long   xn_hcerr            :  1;  /* RW */
+       unsigned long   si_hcerr            :  1;  /* RW */
+       unsigned long   lb_aoerr0           :  1;  /* RW */
+       unsigned long   gr0_aoerr0          :  1;  /* RW */
+       unsigned long   gr1_aoerr0          :  1;  /* RW */
+       unsigned long   lh_aoerr0           :  1;  /* RW */
+       unsigned long   rh_aoerr0           :  1;  /* RW */
+       unsigned long   xn_aoerr0           :  1;  /* RW */
+       unsigned long   si_aoerr0           :  1;  /* RW */
+       unsigned long   lb_aoerr1           :  1;  /* RW */
+       unsigned long   gr0_aoerr1          :  1;  /* RW */
+       unsigned long   gr1_aoerr1          :  1;  /* RW */
+       unsigned long   lh_aoerr1           :  1;  /* RW */
+       unsigned long   rh_aoerr1           :  1;  /* RW */
+       unsigned long   xn_aoerr1           :  1;  /* RW */
+       unsigned long   si_aoerr1           :  1;  /* RW */
+       unsigned long   rh_vpi_int          :  1;  /* RW */
+       unsigned long   system_shutdown_int :  1;  /* RW */
+       unsigned long   lb_irq_int_0        :  1;  /* RW */
+       unsigned long   lb_irq_int_1        :  1;  /* RW */
+       unsigned long   lb_irq_int_2        :  1;  /* RW */
+       unsigned long   lb_irq_int_3        :  1;  /* RW */
+       unsigned long   lb_irq_int_4        :  1;  /* RW */
+       unsigned long   lb_irq_int_5        :  1;  /* RW */
+       unsigned long   lb_irq_int_6        :  1;  /* RW */
+       unsigned long   lb_irq_int_7        :  1;  /* RW */
+       unsigned long   lb_irq_int_8        :  1;  /* RW */
+       unsigned long   lb_irq_int_9        :  1;  /* RW */
+       unsigned long   lb_irq_int_10       :  1;  /* RW */
+       unsigned long   lb_irq_int_11       :  1;  /* RW */
+       unsigned long   lb_irq_int_12       :  1;  /* RW */
+       unsigned long   lb_irq_int_13       :  1;  /* RW */
+       unsigned long   lb_irq_int_14       :  1;  /* RW */
+       unsigned long   lb_irq_int_15       :  1;  /* RW */
+       unsigned long   l1_nmi_int          :  1;  /* RW */
+       unsigned long   stop_clock          :  1;  /* RW */
+       unsigned long   asic_to_l1          :  1;  /* RW */
+       unsigned long   l1_to_asic          :  1;  /* RW */
+       unsigned long   ltc_int             :  1;  /* RW */
+       unsigned long   la_seq_trigger      :  1;  /* RW */
+       unsigned long   rsvd_45_63          : 19;  /*    */
+    } s;
+};
+
 /* ========================================================================= */
 /*                               UVH_NODE_ID                                 */
 /* ========================================================================= */
@@ -283,6 +886,93 @@ union uvh_node_id_u {
     } s;
 };
 
+/* ========================================================================= */
+/*                          UVH_NODE_PRESENT_TABLE                           */
+/* ========================================================================= */
+#define UVH_NODE_PRESENT_TABLE 0x1400UL
+#define UVH_NODE_PRESENT_TABLE_DEPTH 16
+
+#define UVH_NODE_PRESENT_TABLE_NODES_SHFT 0
+#define UVH_NODE_PRESENT_TABLE_NODES_MASK 0xffffffffffffffffUL
+
+union uvh_node_present_table_u {
+    unsigned long      v;
+    struct uvh_node_present_table_s {
+       unsigned long   nodes : 64;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR                  */
+/* ========================================================================= */
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR 0x16000d0UL
+
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_SHFT 24
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_0_MMR_DEST_BASE_MASK 0x00003fffff000000UL
+
+union uvh_rh_gam_alias210_redirect_config_0_mmr_u {
+    unsigned long      v;
+    struct uvh_rh_gam_alias210_redirect_config_0_mmr_s {
+       unsigned long   rsvd_0_23 : 24;  /*    */
+       unsigned long   dest_base : 22;  /* RW */
+       unsigned long   rsvd_46_63: 18;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR                  */
+/* ========================================================================= */
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR 0x16000e0UL
+
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR_DEST_BASE_SHFT 24
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_1_MMR_DEST_BASE_MASK 0x00003fffff000000UL
+
+union uvh_rh_gam_alias210_redirect_config_1_mmr_u {
+    unsigned long      v;
+    struct uvh_rh_gam_alias210_redirect_config_1_mmr_s {
+       unsigned long   rsvd_0_23 : 24;  /*    */
+       unsigned long   dest_base : 22;  /* RW */
+       unsigned long   rsvd_46_63: 18;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR                  */
+/* ========================================================================= */
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR 0x16000f0UL
+
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR_DEST_BASE_SHFT 24
+#define UVH_RH_GAM_ALIAS210_REDIRECT_CONFIG_2_MMR_DEST_BASE_MASK 0x00003fffff000000UL
+
+union uvh_rh_gam_alias210_redirect_config_2_mmr_u {
+    unsigned long      v;
+    struct uvh_rh_gam_alias210_redirect_config_2_mmr_s {
+       unsigned long   rsvd_0_23 : 24;  /*    */
+       unsigned long   dest_base : 22;  /* RW */
+       unsigned long   rsvd_46_63: 18;  /*    */
+    } s;
+};
+
+/* ========================================================================= */
+/*                    UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR                      */
+/* ========================================================================= */
+#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR 0x1600020UL
+
+#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_SHFT 26
+#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffffc000000UL
+#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63
+#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_MASK 0x8000000000000000UL
+
+union uvh_rh_gam_cfg_overlay_config_mmr_u {
+    unsigned long      v;
+    struct uvh_rh_gam_cfg_overlay_config_mmr_s {
+       unsigned long   rsvd_0_25: 26;  /*    */
+       unsigned long   base   : 20;  /* RW */
+       unsigned long   rsvd_46_62: 17;  /*    */
+       unsigned long   enable :  1;  /* RW */
+    } s;
+};
+
 /* ========================================================================= */
 /*                    UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR                      */
 /* ========================================================================= */
@@ -290,8 +980,8 @@ union uvh_node_id_u {
 
 #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_SHFT 28
 #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffff0000000UL
-#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_SHFT 46
-#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_MASK 0x0000400000000000UL
+#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_SHFT 48
+#define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_GR4_MASK 0x0001000000000000UL
 #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_SHFT 52
 #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_N_GRU_MASK 0x00f0000000000000UL
 #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63
@@ -302,14 +992,41 @@ union uvh_rh_gam_gru_overlay_config_mmr_u {
     struct uvh_rh_gam_gru_overlay_config_mmr_s {
        unsigned long   rsvd_0_27: 28;  /*    */
        unsigned long   base   : 18;  /* RW */
+       unsigned long   rsvd_46_47:  2;  /*    */
        unsigned long   gr4    :  1;  /* RW */
-       unsigned long   rsvd_47_51:  5;  /*    */
+       unsigned long   rsvd_49_51:  3;  /*    */
        unsigned long   n_gru  :  4;  /* RW */
        unsigned long   rsvd_56_62:  7;  /*    */
        unsigned long   enable :  1;  /* RW */
     } s;
 };
 
+/* ========================================================================= */
+/*                   UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR                     */
+/* ========================================================================= */
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR 0x1600030UL
+
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_SHFT 30
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003fffc0000000UL
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_M_IO_SHFT 46
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_M_IO_MASK 0x000fc00000000000UL
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_N_IO_SHFT 52
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_N_IO_MASK 0x00f0000000000000UL
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63
+#define UVH_RH_GAM_MMIOH_OVERLAY_CONFIG_MMR_ENABLE_MASK 0x8000000000000000UL
+
+union uvh_rh_gam_mmioh_overlay_config_mmr_u {
+    unsigned long      v;
+    struct uvh_rh_gam_mmioh_overlay_config_mmr_s {
+       unsigned long   rsvd_0_29: 30;  /*    */
+       unsigned long   base   : 16;  /* RW */
+       unsigned long   m_io   :  6;  /* RW */
+       unsigned long   n_io   :  4;  /* RW */
+       unsigned long   rsvd_56_62:  7;  /*    */
+       unsigned long   enable :  1;  /* RW */
+    } s;
+};
+
 /* ========================================================================= */
 /*                    UVH_RH_GAM_MMR_OVERLAY_CONFIG_MMR                      */
 /* ========================================================================= */
@@ -336,7 +1053,7 @@ union uvh_rh_gam_mmr_overlay_config_mmr_u {
 /* ========================================================================= */
 /*                                 UVH_RTC                                   */
 /* ========================================================================= */
-#define UVH_RTC 0x28000UL
+#define UVH_RTC 0x340000UL
 
 #define UVH_RTC_REAL_TIME_CLOCK_SHFT 0
 #define UVH_RTC_REAL_TIME_CLOCK_MASK 0x00ffffffffffffffUL
@@ -349,6 +1066,139 @@ union uvh_rtc_u {
     } s;
 };
 
+/* ========================================================================= */
+/*                           UVH_RTC1_INT_CONFIG                             */
+/* ========================================================================= */
+#define UVH_RTC1_INT_CONFIG 0x615c0UL
+
+#define UVH_RTC1_INT_CONFIG_VECTOR_SHFT 0
+#define UVH_RTC1_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
+#define UVH_RTC1_INT_CONFIG_DM_SHFT 8
+#define UVH_RTC1_INT_CONFIG_DM_MASK 0x0000000000000700UL
+#define UVH_RTC1_INT_CONFIG_DESTMODE_SHFT 11
+#define UVH_RTC1_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
+#define UVH_RTC1_INT_CONFIG_STATUS_SHFT 12
+#define UVH_RTC1_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
+#define UVH_RTC1_INT_CONFIG_P_SHFT 13
+#define UVH_RTC1_INT_CONFIG_P_MASK 0x0000000000002000UL
+#define UVH_RTC1_INT_CONFIG_T_SHFT 15
+#define UVH_RTC1_INT_CONFIG_T_MASK 0x0000000000008000UL
+#define UVH_RTC1_INT_CONFIG_M_SHFT 16
+#define UVH_RTC1_INT_CONFIG_M_MASK 0x0000000000010000UL
+#define UVH_RTC1_INT_CONFIG_APIC_ID_SHFT 32
+#define UVH_RTC1_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
+
+union uvh_rtc1_int_config_u {
+    unsigned long      v;
+    struct uvh_rtc1_int_config_s {
+       unsigned long   vector_  :  8;  /* RW */
+       unsigned long   dm       :  3;  /* RW */
+       unsigned long   destmode :  1;  /* RW */
+       unsigned long   status   :  1;  /* RO */
+       unsigned long   p        :  1;  /* RO */
+       unsigned long   rsvd_14  :  1;  /*    */
+       unsigned long   t        :  1;  /* RO */
+       unsigned long   m        :  1;  /* RW */
+       unsigned long   rsvd_17_31: 15;  /*    */
+       unsigned long   apic_id  : 32;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                           UVH_RTC2_INT_CONFIG                             */
+/* ========================================================================= */
+#define UVH_RTC2_INT_CONFIG 0x61600UL
+
+#define UVH_RTC2_INT_CONFIG_VECTOR_SHFT 0
+#define UVH_RTC2_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
+#define UVH_RTC2_INT_CONFIG_DM_SHFT 8
+#define UVH_RTC2_INT_CONFIG_DM_MASK 0x0000000000000700UL
+#define UVH_RTC2_INT_CONFIG_DESTMODE_SHFT 11
+#define UVH_RTC2_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
+#define UVH_RTC2_INT_CONFIG_STATUS_SHFT 12
+#define UVH_RTC2_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
+#define UVH_RTC2_INT_CONFIG_P_SHFT 13
+#define UVH_RTC2_INT_CONFIG_P_MASK 0x0000000000002000UL
+#define UVH_RTC2_INT_CONFIG_T_SHFT 15
+#define UVH_RTC2_INT_CONFIG_T_MASK 0x0000000000008000UL
+#define UVH_RTC2_INT_CONFIG_M_SHFT 16
+#define UVH_RTC2_INT_CONFIG_M_MASK 0x0000000000010000UL
+#define UVH_RTC2_INT_CONFIG_APIC_ID_SHFT 32
+#define UVH_RTC2_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
+
+union uvh_rtc2_int_config_u {
+    unsigned long      v;
+    struct uvh_rtc2_int_config_s {
+       unsigned long   vector_  :  8;  /* RW */
+       unsigned long   dm       :  3;  /* RW */
+       unsigned long   destmode :  1;  /* RW */
+       unsigned long   status   :  1;  /* RO */
+       unsigned long   p        :  1;  /* RO */
+       unsigned long   rsvd_14  :  1;  /*    */
+       unsigned long   t        :  1;  /* RO */
+       unsigned long   m        :  1;  /* RW */
+       unsigned long   rsvd_17_31: 15;  /*    */
+       unsigned long   apic_id  : 32;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                           UVH_RTC3_INT_CONFIG                             */
+/* ========================================================================= */
+#define UVH_RTC3_INT_CONFIG 0x61640UL
+
+#define UVH_RTC3_INT_CONFIG_VECTOR_SHFT 0
+#define UVH_RTC3_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
+#define UVH_RTC3_INT_CONFIG_DM_SHFT 8
+#define UVH_RTC3_INT_CONFIG_DM_MASK 0x0000000000000700UL
+#define UVH_RTC3_INT_CONFIG_DESTMODE_SHFT 11
+#define UVH_RTC3_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
+#define UVH_RTC3_INT_CONFIG_STATUS_SHFT 12
+#define UVH_RTC3_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
+#define UVH_RTC3_INT_CONFIG_P_SHFT 13
+#define UVH_RTC3_INT_CONFIG_P_MASK 0x0000000000002000UL
+#define UVH_RTC3_INT_CONFIG_T_SHFT 15
+#define UVH_RTC3_INT_CONFIG_T_MASK 0x0000000000008000UL
+#define UVH_RTC3_INT_CONFIG_M_SHFT 16
+#define UVH_RTC3_INT_CONFIG_M_MASK 0x0000000000010000UL
+#define UVH_RTC3_INT_CONFIG_APIC_ID_SHFT 32
+#define UVH_RTC3_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
+
+union uvh_rtc3_int_config_u {
+    unsigned long      v;
+    struct uvh_rtc3_int_config_s {
+       unsigned long   vector_  :  8;  /* RW */
+       unsigned long   dm       :  3;  /* RW */
+       unsigned long   destmode :  1;  /* RW */
+       unsigned long   status   :  1;  /* RO */
+       unsigned long   p        :  1;  /* RO */
+       unsigned long   rsvd_14  :  1;  /*    */
+       unsigned long   t        :  1;  /* RO */
+       unsigned long   m        :  1;  /* RW */
+       unsigned long   rsvd_17_31: 15;  /*    */
+       unsigned long   apic_id  : 32;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                            UVH_RTC_INC_RATIO                              */
+/* ========================================================================= */
+#define UVH_RTC_INC_RATIO 0x350000UL
+
+#define UVH_RTC_INC_RATIO_FRACTION_SHFT 0
+#define UVH_RTC_INC_RATIO_FRACTION_MASK 0x00000000000fffffUL
+#define UVH_RTC_INC_RATIO_RATIO_SHFT 20
+#define UVH_RTC_INC_RATIO_RATIO_MASK 0x0000000000700000UL
+
+union uvh_rtc_inc_ratio_u {
+    unsigned long      v;
+    struct uvh_rtc_inc_ratio_s {
+       unsigned long   fraction : 20;  /* RW */
+       unsigned long   ratio    :  3;  /* RW */
+       unsigned long   rsvd_23_63: 41;  /*    */
+    } s;
+};
+
 /* ========================================================================= */
 /*                          UVH_SI_ADDR_MAP_CONFIG                           */
 /* ========================================================================= */
@@ -369,5 +1219,77 @@ union uvh_si_addr_map_config_u {
     } s;
 };
 
+/* ========================================================================= */
+/*                       UVH_SI_ALIAS0_OVERLAY_CONFIG                        */
+/* ========================================================================= */
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG 0xc80008UL
+
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_BASE_SHFT 24
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_M_ALIAS_SHFT 48
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_ENABLE_SHFT 63
+#define UVH_SI_ALIAS0_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
+
+union uvh_si_alias0_overlay_config_u {
+    unsigned long      v;
+    struct uvh_si_alias0_overlay_config_s {
+       unsigned long   rsvd_0_23: 24;  /*    */
+       unsigned long   base    :  8;  /* RW */
+       unsigned long   rsvd_32_47: 16;  /*    */
+       unsigned long   m_alias :  5;  /* RW */
+       unsigned long   rsvd_53_62: 10;  /*    */
+       unsigned long   enable  :  1;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                       UVH_SI_ALIAS1_OVERLAY_CONFIG                        */
+/* ========================================================================= */
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG 0xc80010UL
+
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_BASE_SHFT 24
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_M_ALIAS_SHFT 48
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_ENABLE_SHFT 63
+#define UVH_SI_ALIAS1_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
+
+union uvh_si_alias1_overlay_config_u {
+    unsigned long      v;
+    struct uvh_si_alias1_overlay_config_s {
+       unsigned long   rsvd_0_23: 24;  /*    */
+       unsigned long   base    :  8;  /* RW */
+       unsigned long   rsvd_32_47: 16;  /*    */
+       unsigned long   m_alias :  5;  /* RW */
+       unsigned long   rsvd_53_62: 10;  /*    */
+       unsigned long   enable  :  1;  /* RW */
+    } s;
+};
+
+/* ========================================================================= */
+/*                       UVH_SI_ALIAS2_OVERLAY_CONFIG                        */
+/* ========================================================================= */
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG 0xc80018UL
+
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_BASE_SHFT 24
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_BASE_MASK 0x00000000ff000000UL
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_M_ALIAS_SHFT 48
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_M_ALIAS_MASK 0x001f000000000000UL
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_ENABLE_SHFT 63
+#define UVH_SI_ALIAS2_OVERLAY_CONFIG_ENABLE_MASK 0x8000000000000000UL
+
+union uvh_si_alias2_overlay_config_u {
+    unsigned long      v;
+    struct uvh_si_alias2_overlay_config_s {
+       unsigned long   rsvd_0_23: 24;  /*    */
+       unsigned long   base    :  8;  /* RW */
+       unsigned long   rsvd_32_47: 16;  /*    */
+       unsigned long   m_alias :  5;  /* RW */
+       unsigned long   rsvd_53_62: 10;  /*    */
+       unsigned long   enable  :  1;  /* RW */
+    } s;
+};
+
 
 #endif /* __ASM_X86_UV_MMRS__ */
diff --git a/include/asm-x86/visws/cobalt.h b/include/asm-x86/visws/cobalt.h
new file mode 100644 (file)
index 0000000..9952588
--- /dev/null
@@ -0,0 +1,125 @@
+#ifndef __I386_SGI_COBALT_H
+#define __I386_SGI_COBALT_H
+
+#include <asm/fixmap.h>
+
+/*
+ * Cobalt SGI Visual Workstation system ASIC
+ */ 
+
+#define CO_CPU_NUM_PHYS 0x1e00
+#define CO_CPU_TAB_PHYS (CO_CPU_NUM_PHYS + 2)
+
+#define CO_CPU_MAX 4
+
+#define        CO_CPU_PHYS             0xc2000000
+#define        CO_APIC_PHYS            0xc4000000
+
+/* see set_fixmap() and asm/fixmap.h */
+#define        CO_CPU_VADDR            (fix_to_virt(FIX_CO_CPU))
+#define        CO_APIC_VADDR           (fix_to_virt(FIX_CO_APIC))
+
+/* Cobalt CPU registers -- relative to CO_CPU_VADDR, use co_cpu_*() */
+#define        CO_CPU_REV              0x08
+#define        CO_CPU_CTRL             0x10
+#define        CO_CPU_STAT             0x20
+#define        CO_CPU_TIMEVAL          0x30
+
+/* CO_CPU_CTRL bits */
+#define        CO_CTRL_TIMERUN         0x04            /* 0 == disabled */
+#define        CO_CTRL_TIMEMASK        0x08            /* 0 == unmasked */
+
+/* CO_CPU_STATUS bits */
+#define        CO_STAT_TIMEINTR        0x02    /* (r) 1 == int pend, (w) 0 == clear */
+
+/* CO_CPU_TIMEVAL value */
+#define        CO_TIME_HZ              100000000       /* Cobalt core rate */
+
+/* Cobalt APIC registers -- relative to CO_APIC_VADDR, use co_apic_*() */
+#define        CO_APIC_HI(n)           (((n) * 0x10) + 4)
+#define        CO_APIC_LO(n)           ((n) * 0x10)
+#define        CO_APIC_ID              0x0ffc
+
+/* CO_APIC_ID bits */
+#define        CO_APIC_ENABLE          0x00000100
+
+/* CO_APIC_LO bits */
+#define        CO_APIC_MASK            0x00010000      /* 0 = enabled */
+#define        CO_APIC_LEVEL           0x00008000      /* 0 = edge */
+
+/*
+ * Where things are physically wired to Cobalt
+ * #defines with no board _<type>_<rev>_ are common to all (thus far)
+ */
+#define        CO_APIC_IDE0            4
+#define CO_APIC_IDE1           2               /* Only on 320 */
+
+#define        CO_APIC_8259            12              /* serial, floppy, par-l-l */
+
+/* Lithium PCI Bridge A -- "the one with 82557 Ethernet" */
+#define        CO_APIC_PCIA_BASE0      0 /* and 1 */   /* slot 0, line 0 */
+#define        CO_APIC_PCIA_BASE123    5 /* and 6 */   /* slot 0, line 1 */
+
+#define        CO_APIC_PIIX4_USB       7               /* this one is weird */
+
+/* Lithium PCI Bridge B -- "the one with PIIX4" */
+#define        CO_APIC_PCIB_BASE0      8 /* and 9-12 *//* slot 0, line 0 */
+#define        CO_APIC_PCIB_BASE123    13 /* 14.15 */  /* slot 0, line 1 */
+
+#define        CO_APIC_VIDOUT0         16
+#define        CO_APIC_VIDOUT1         17
+#define        CO_APIC_VIDIN0          18
+#define        CO_APIC_VIDIN1          19
+
+#define        CO_APIC_LI_AUDIO        22
+
+#define        CO_APIC_AS              24
+#define        CO_APIC_RE              25
+
+#define CO_APIC_CPU            28              /* Timer and Cache interrupt */
+#define        CO_APIC_NMI             29
+#define        CO_APIC_LAST            CO_APIC_NMI
+
+/*
+ * This is how irqs are assigned on the Visual Workstation.
+ * Legacy devices get irq's 1-15 (system clock is 0 and is CO_APIC_CPU).
+ * All other devices (including PCI) go to Cobalt and are irq's 16 on up.
+ */
+#define        CO_IRQ_APIC0    16                      /* irq of apic entry 0 */
+#define        IS_CO_APIC(irq) ((irq) >= CO_IRQ_APIC0)
+#define        CO_IRQ(apic)    (CO_IRQ_APIC0 + (apic)) /* apic ent to irq */
+#define        CO_APIC(irq)    ((irq) - CO_IRQ_APIC0)  /* irq to apic ent */
+#define CO_IRQ_IDE0    14                      /* knowledge of... */
+#define CO_IRQ_IDE1    15                      /* ... ide driver defaults! */
+#define        CO_IRQ_8259     CO_IRQ(CO_APIC_8259)
+
+#ifdef CONFIG_X86_VISWS_APIC
+static inline void co_cpu_write(unsigned long reg, unsigned long v)
+{
+       *((volatile unsigned long *)(CO_CPU_VADDR+reg))=v;
+}
+
+static inline unsigned long co_cpu_read(unsigned long reg)
+{
+       return *((volatile unsigned long *)(CO_CPU_VADDR+reg));
+}            
+             
+static inline void co_apic_write(unsigned long reg, unsigned long v)
+{
+       *((volatile unsigned long *)(CO_APIC_VADDR+reg))=v;
+}            
+             
+static inline unsigned long co_apic_read(unsigned long reg)
+{
+       return *((volatile unsigned long *)(CO_APIC_VADDR+reg));
+}
+#endif
+
+extern char visws_board_type;
+
+#define        VISWS_320       0
+#define        VISWS_540       1
+
+extern char visws_board_rev;
+
+#endif /* __I386_SGI_COBALT_H */
diff --git a/include/asm-x86/visws/lithium.h b/include/asm-x86/visws/lithium.h
new file mode 100644 (file)
index 0000000..dfcd4f0
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef __I386_SGI_LITHIUM_H
+#define __I386_SGI_LITHIUM_H
+
+#include <asm/fixmap.h>
+
+/*
+ * Lithium is the SGI Visual Workstation I/O ASIC
+ */
+
+#define        LI_PCI_A_PHYS           0xfc000000      /* Enet is dev 3 */
+#define        LI_PCI_B_PHYS           0xfd000000      /* PIIX4 is here */
+
+/* see set_fixmap() and asm/fixmap.h */
+#define LI_PCIA_VADDR   (fix_to_virt(FIX_LI_PCIA))
+#define LI_PCIB_VADDR   (fix_to_virt(FIX_LI_PCIB))
+
+/* Not a standard PCI? (not in linux/pci.h) */
+#define        LI_PCI_BUSNUM   0x44                    /* lo8: primary, hi8: sub */
+#define LI_PCI_INTEN    0x46
+
+/* LI_PCI_INTENT bits */
+#define        LI_INTA_0       0x0001
+#define        LI_INTA_1       0x0002
+#define        LI_INTA_2       0x0004
+#define        LI_INTA_3       0x0008
+#define        LI_INTA_4       0x0010
+#define        LI_INTB         0x0020
+#define        LI_INTC         0x0040
+#define        LI_INTD         0x0080
+
+/* More special purpose macros... */
+static inline void li_pcia_write16(unsigned long reg, unsigned short v)
+{
+       *((volatile unsigned short *)(LI_PCIA_VADDR+reg))=v;
+}
+
+static inline unsigned short li_pcia_read16(unsigned long reg)
+{
+        return *((volatile unsigned short *)(LI_PCIA_VADDR+reg));
+}
+
+static inline void li_pcib_write16(unsigned long reg, unsigned short v)
+{
+       *((volatile unsigned short *)(LI_PCIB_VADDR+reg))=v;
+}
+
+static inline unsigned short li_pcib_read16(unsigned long reg)
+{
+       return *((volatile unsigned short *)(LI_PCIB_VADDR+reg));
+}
+
+#endif
+
diff --git a/include/asm-x86/visws/piix4.h b/include/asm-x86/visws/piix4.h
new file mode 100644 (file)
index 0000000..83ea4f4
--- /dev/null
@@ -0,0 +1,107 @@
+#ifndef __I386_SGI_PIIX_H
+#define __I386_SGI_PIIX_H
+
+/*
+ * PIIX4 as used on SGI Visual Workstations
+ */
+
+#define        PIIX_PM_START           0x0F80
+
+#define        SIO_GPIO_START          0x0FC0
+
+#define        SIO_PM_START            0x0FC8
+
+#define        PMBASE                  PIIX_PM_START
+#define        GPIREG0                 (PMBASE+0x30)
+#define        GPIREG(x)               (GPIREG0+((x)/8))
+#define        GPIBIT(x)               (1 << ((x)%8))
+
+#define        PIIX_GPI_BD_ID1         18
+#define        PIIX_GPI_BD_ID2         19
+#define        PIIX_GPI_BD_ID3         20
+#define        PIIX_GPI_BD_ID4         21
+#define        PIIX_GPI_BD_REG         GPIREG(PIIX_GPI_BD_ID1)
+#define        PIIX_GPI_BD_MASK        (GPIBIT(PIIX_GPI_BD_ID1) | \
+                               GPIBIT(PIIX_GPI_BD_ID2) | \
+                               GPIBIT(PIIX_GPI_BD_ID3) | \
+                               GPIBIT(PIIX_GPI_BD_ID4) )
+
+#define        PIIX_GPI_BD_SHIFT       (PIIX_GPI_BD_ID1 % 8)
+
+#define        SIO_INDEX               0x2e
+#define        SIO_DATA                0x2f
+
+#define        SIO_DEV_SEL             0x7
+#define        SIO_DEV_ENB             0x30
+#define        SIO_DEV_MSB             0x60
+#define        SIO_DEV_LSB             0x61
+
+#define        SIO_GP_DEV              0x7
+
+#define        SIO_GP_BASE             SIO_GPIO_START
+#define        SIO_GP_MSB              (SIO_GP_BASE>>8)
+#define        SIO_GP_LSB              (SIO_GP_BASE&0xff)
+
+#define        SIO_GP_DATA1            (SIO_GP_BASE+0)
+
+#define        SIO_PM_DEV              0x8
+
+#define        SIO_PM_BASE             SIO_PM_START
+#define        SIO_PM_MSB              (SIO_PM_BASE>>8)
+#define        SIO_PM_LSB              (SIO_PM_BASE&0xff)
+#define        SIO_PM_INDEX            (SIO_PM_BASE+0)
+#define        SIO_PM_DATA             (SIO_PM_BASE+1)
+
+#define        SIO_PM_FER2             0x1
+
+#define        SIO_PM_GP_EN            0x80
+
+
+
+/*
+ * This is the dev/reg where generating a config cycle will
+ * result in a PCI special cycle.
+ */
+#define SPECIAL_DEV            0xff
+#define SPECIAL_REG            0x00
+
+/*
+ * PIIX4 needs to see a special cycle with the following data
+ * to be convinced the processor has gone into the stop grant
+ * state.  PIIX4 insists on seeing this before it will power
+ * down a system.
+ */
+#define PIIX_SPECIAL_STOP              0x00120002
+
+#define PIIX4_RESET_PORT       0xcf9
+#define PIIX4_RESET_VAL                0x6
+
+#define PMSTS_PORT             0xf80   // 2 bytes      PM Status
+#define PMEN_PORT              0xf82   // 2 bytes      PM Enable
+#define        PMCNTRL_PORT            0xf84   // 2 bytes      PM Control
+
+#define PM_SUSPEND_ENABLE      0x2000  // start sequence to suspend state
+
+/*
+ * PMSTS and PMEN I/O bit definitions.
+ * (Bits are the same in both registers)
+ */
+#define PM_STS_RSM             (1<<15) // Resume Status
+#define PM_STS_PWRBTNOR                (1<<11) // Power Button Override
+#define PM_STS_RTC             (1<<10) // RTC status
+#define PM_STS_PWRBTN          (1<<8)  // Power Button Pressed?
+#define PM_STS_GBL             (1<<5)  // Global Status
+#define PM_STS_BM              (1<<4)  // Bus Master Status
+#define PM_STS_TMROF           (1<<0)  // Timer Overflow Status.
+
+/*
+ * Stop clock GPI register
+ */
+#define PIIX_GPIREG0                   (0xf80 + 0x30)
+
+/*
+ * Stop clock GPI bit in GPIREG0
+ */
+#define        PIIX_GPI_STPCLK         0x4     // STPCLK signal routed back in
+
+#endif
diff --git a/include/asm-x86/visws/sgivw.h b/include/asm-x86/visws/sgivw.h
new file mode 100644 (file)
index 0000000..5fbf63e
--- /dev/null
@@ -0,0 +1,5 @@
+/*
+ * Frame buffer position and size:
+ */
+extern unsigned long sgivwfb_mem_phys;
+extern unsigned long sgivwfb_mem_size;
index 074b357..5ce3513 100644 (file)
 
 #include <asm/processor-flags.h>
 
-#ifdef CONFIG_VM86
-#define X86_VM_MASK    X86_EFLAGS_VM
-#else
-#define X86_VM_MASK    0 /* No VM86 support */
-#endif
-
 #define BIOSSEG                0x0f000
 
 #define CPU_086                0
@@ -121,7 +115,6 @@ struct vm86plus_info_struct {
        unsigned long is_vm86pus:1;           /* for vm86 internal use */
        unsigned char vm86dbg_intxxtab[32];   /* for debugger */
 };
-
 struct vm86plus_struct {
        struct vm86_regs regs;
        unsigned long flags;
@@ -133,6 +126,9 @@ struct vm86plus_struct {
 };
 
 #ifdef __KERNEL__
+
+#include <asm/ptrace.h>
+
 /*
  * This is the (kernel) stack-layout when we have done a "SAVE_ALL" from vm86
  * mode - the main change is that the old segment descriptors aren't
@@ -141,7 +137,6 @@ struct vm86plus_struct {
  * at the end of the structure. Look at ptrace.h to see the "normal"
  * setup. For user space layout see 'struct vm86_regs' above.
  */
-#include <asm/ptrace.h>
 
 struct kernel_vm86_regs {
 /*
index 4781881..c3118c3 100644 (file)
@@ -50,7 +50,7 @@ extern void __init vmi_time_init(void);
 extern unsigned long vmi_get_wallclock(void);
 extern int vmi_set_wallclock(unsigned long now);
 extern unsigned long long vmi_sched_clock(void);
-extern unsigned long vmi_cpu_khz(void);
+extern unsigned long vmi_tsc_khz(void);
 
 #ifdef CONFIG_X86_LOCAL_APIC
 extern void __devinit vmi_time_bsp_init(void);
index 17b3700..6b66ff9 100644 (file)
@@ -24,7 +24,8 @@ enum vsyscall_num {
        ((unused, __section__ (".vsyscall_gtod_data"),aligned(16)))
 #define __section_vsyscall_clock __attribute__ \
        ((unused, __section__ (".vsyscall_clock"),aligned(16)))
-#define __vsyscall_fn __attribute__ ((unused,__section__(".vsyscall_fn")))
+#define __vsyscall_fn \
+       __attribute__ ((unused, __section__(".vsyscall_fn"))) notrace
 
 #define VGETCPU_RDTSCP 1
 #define VGETCPU_LSL    2
index c2ccd99..2a4f9b4 100644 (file)
@@ -176,9 +176,9 @@ HYPERVISOR_fpu_taskswitch(int set)
 }
 
 static inline int
-HYPERVISOR_sched_op(int cmd, unsigned long arg)
+HYPERVISOR_sched_op(int cmd, void *arg)
 {
-       return _hypercall2(int, sched_op, cmd, arg);
+       return _hypercall2(int, sched_op_new, cmd, arg);
 }
 
 static inline long
@@ -314,6 +314,13 @@ HYPERVISOR_nmi_op(unsigned long op, unsigned long arg)
        return _hypercall2(int, nmi_op, op, arg);
 }
 
+static inline void
+MULTI_fpu_taskswitch(struct multicall_entry *mcl, int set)
+{
+       mcl->op = __HYPERVISOR_fpu_taskswitch;
+       mcl->args[0] = set;
+}
+
 static inline void
 MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
                        pte_t new_val, unsigned long flags)
index e11f240..377c045 100644 (file)
@@ -26,15 +26,20 @@ typedef struct xpaddr {
 #define FOREIGN_FRAME_BIT      (1UL<<31)
 #define FOREIGN_FRAME(m)       ((m) | FOREIGN_FRAME_BIT)
 
-extern unsigned long *phys_to_machine_mapping;
+/* Maximum amount of memory we can handle in a domain in pages */
+#define MAX_DOMAIN_PAGES                                               \
+    ((unsigned long)((u64)CONFIG_XEN_MAX_DOMAIN_MEMORY * 1024 * 1024 * 1024 / PAGE_SIZE))
+
+
+extern unsigned long get_phys_to_machine(unsigned long pfn);
+extern void set_phys_to_machine(unsigned long pfn, unsigned long mfn);
 
 static inline unsigned long pfn_to_mfn(unsigned long pfn)
 {
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return pfn;
 
-       return phys_to_machine_mapping[(unsigned int)(pfn)] &
-               ~FOREIGN_FRAME_BIT;
+       return get_phys_to_machine(pfn) & ~FOREIGN_FRAME_BIT;
 }
 
 static inline int phys_to_machine_mapping_valid(unsigned long pfn)
@@ -42,7 +47,7 @@ static inline int phys_to_machine_mapping_valid(unsigned long pfn)
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return 1;
 
-       return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
+       return get_phys_to_machine(pfn) != INVALID_P2M_ENTRY;
 }
 
 static inline unsigned long mfn_to_pfn(unsigned long mfn)
@@ -106,20 +111,12 @@ static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
        unsigned long pfn = mfn_to_pfn(mfn);
        if ((pfn < max_mapnr)
            && !xen_feature(XENFEAT_auto_translated_physmap)
-           && (phys_to_machine_mapping[pfn] != mfn))
+           && (get_phys_to_machine(pfn) != mfn))
                return max_mapnr; /* force !pfn_valid() */
+       /* XXX fixme; not true with sparsemem */
        return pfn;
 }
 
-static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
-{
-       if (xen_feature(XENFEAT_auto_translated_physmap)) {
-               BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
-               return;
-       }
-       phys_to_machine_mapping[pfn] = mfn;
-}
-
 /* VIRT <-> MACHINE conversion */
 #define virt_to_machine(v)     (phys_to_machine(XPADDR(__pa(v))))
 #define virt_to_mfn(v)         (pfn_to_mfn(PFN_DOWN(__pa(v))))
index 067b5c1..921b458 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef ASM_X86__XOR_32_H
+#define ASM_X86__XOR_32_H
+
 /*
  * Optimized RAID-5 checksumming functions for MMX and SSE.
  *
@@ -881,3 +884,5 @@ do {                                                        \
    deals with a load to a line that is being prefetched.  */
 #define XOR_SELECT_TEMPLATE(FASTEST)                   \
        (cpu_has_xmm ? &xor_block_pIII_sse : FASTEST)
+
+#endif /* ASM_X86__XOR_32_H */
index 24957e3..2d3a18d 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef ASM_X86__XOR_64_H
+#define ASM_X86__XOR_64_H
+
 /*
  * Optimized RAID-5 checksumming functions for MMX and SSE.
  *
@@ -354,3 +357,5 @@ do {                                                \
    We may also be able to load into the L1 only depending on how the cpu
    deals with a load to a line that is being prefetched.  */
 #define XOR_SELECT_TEMPLATE(FASTEST) (&xor_block_sse)
+
+#endif /* ASM_X86__XOR_64_H */
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
new file mode 100644 (file)
index 0000000..d12498e
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Hash: Hash algorithms under the crypto API
+ * 
+ * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_HASH_H
+#define _CRYPTO_HASH_H
+
+#include <linux/crypto.h>
+
+struct crypto_ahash {
+       struct crypto_tfm base;
+};
+
+static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)
+{
+       return (struct crypto_ahash *)tfm;
+}
+
+static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name,
+                                                     u32 type, u32 mask)
+{
+       type &= ~CRYPTO_ALG_TYPE_MASK;
+       mask &= ~CRYPTO_ALG_TYPE_MASK;
+       type |= CRYPTO_ALG_TYPE_AHASH;
+       mask |= CRYPTO_ALG_TYPE_AHASH_MASK;
+
+       return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask));
+}
+
+static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)
+{
+       return &tfm->base;
+}
+
+static inline void crypto_free_ahash(struct crypto_ahash *tfm)
+{
+       crypto_free_tfm(crypto_ahash_tfm(tfm));
+}
+
+static inline unsigned int crypto_ahash_alignmask(
+       struct crypto_ahash *tfm)
+{
+       return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm));
+}
+
+static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm)
+{
+       return &crypto_ahash_tfm(tfm)->crt_ahash;
+}
+
+static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm)
+{
+       return crypto_ahash_crt(tfm)->digestsize;
+}
+
+static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm)
+{
+       return crypto_tfm_get_flags(crypto_ahash_tfm(tfm));
+}
+
+static inline void crypto_ahash_set_flags(struct crypto_ahash *tfm, u32 flags)
+{
+       crypto_tfm_set_flags(crypto_ahash_tfm(tfm), flags);
+}
+
+static inline void crypto_ahash_clear_flags(struct crypto_ahash *tfm, u32 flags)
+{
+       crypto_tfm_clear_flags(crypto_ahash_tfm(tfm), flags);
+}
+
+static inline struct crypto_ahash *crypto_ahash_reqtfm(
+       struct ahash_request *req)
+{
+       return __crypto_ahash_cast(req->base.tfm);
+}
+
+static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm)
+{
+       return crypto_ahash_crt(tfm)->reqsize;
+}
+
+static inline int crypto_ahash_setkey(struct crypto_ahash *tfm,
+                                     const u8 *key, unsigned int keylen)
+{
+       struct ahash_tfm *crt = crypto_ahash_crt(tfm);
+
+       return crt->setkey(tfm, key, keylen);
+}
+
+static inline int crypto_ahash_digest(struct ahash_request *req)
+{
+       struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req));
+       return crt->digest(req);
+}
+
+static inline void ahash_request_set_tfm(struct ahash_request *req,
+                                        struct crypto_ahash *tfm)
+{
+       req->base.tfm = crypto_ahash_tfm(tfm);
+}
+
+static inline struct ahash_request *ahash_request_alloc(
+       struct crypto_ahash *tfm, gfp_t gfp)
+{
+       struct ahash_request *req;
+
+       req = kmalloc(sizeof(struct ahash_request) +
+                     crypto_ahash_reqsize(tfm), gfp);
+
+       if (likely(req))
+               ahash_request_set_tfm(req, tfm);
+
+       return req;
+}
+
+static inline void ahash_request_free(struct ahash_request *req)
+{
+       kfree(req);
+}
+
+static inline struct ahash_request *ahash_request_cast(
+       struct crypto_async_request *req)
+{
+       return container_of(req, struct ahash_request, base);
+}
+
+static inline void ahash_request_set_callback(struct ahash_request *req,
+                                             u32 flags,
+                                             crypto_completion_t complete,
+                                             void *data)
+{
+       req->base.complete = complete;
+       req->base.data = data;
+       req->base.flags = flags;
+}
+
+static inline void ahash_request_set_crypt(struct ahash_request *req,
+                                          struct scatterlist *src, u8 *result,
+                                          unsigned int nbytes)
+{
+       req->src = src;
+       req->nbytes = nbytes;
+       req->result = result;
+}
+
+#endif /* _CRYPTO_HASH_H */
diff --git a/include/crypto/internal/hash.h b/include/crypto/internal/hash.h
new file mode 100644 (file)
index 0000000..917ae57
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Hash algorithms.
+ * 
+ * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option) 
+ * any later version.
+ *
+ */
+
+#ifndef _CRYPTO_INTERNAL_HASH_H
+#define _CRYPTO_INTERNAL_HASH_H
+
+#include <crypto/algapi.h>
+#include <crypto/hash.h>
+
+struct ahash_request;
+struct scatterlist;
+
+struct crypto_hash_walk {
+       char *data;
+
+       unsigned int offset;
+       unsigned int alignmask;
+
+       struct page *pg;
+       unsigned int entrylen;
+
+       unsigned int total;
+       struct scatterlist *sg;
+
+       unsigned int flags;
+};
+
+extern const struct crypto_type crypto_ahash_type;
+
+int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
+int crypto_hash_walk_first(struct ahash_request *req,
+                          struct crypto_hash_walk *walk);
+
+static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
+{
+       return crypto_tfm_ctx(&tfm->base);
+}
+
+static inline struct ahash_alg *crypto_ahash_alg(
+       struct crypto_ahash *tfm)
+{
+       return &crypto_ahash_tfm(tfm)->__crt_alg->cra_ahash;
+}
+
+static inline int ahash_enqueue_request(struct crypto_queue *queue,
+                                            struct ahash_request *request)
+{
+       return crypto_enqueue_request(queue, &request->base);
+}
+
+static inline struct ahash_request *ahash_dequeue_request(
+       struct crypto_queue *queue)
+{
+       return ahash_request_cast(crypto_dequeue_request(queue));
+}
+
+static inline void *ahash_request_ctx(struct ahash_request *req)
+{
+       return req->__ctx;
+}
+
+static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
+                                         struct crypto_ahash *tfm)
+{
+       return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
+}
+
+#endif /* _CRYPTO_INTERNAL_HASH_H */
+
diff --git a/include/drm/Kbuild b/include/drm/Kbuild
new file mode 100644 (file)
index 0000000..82b6983
--- /dev/null
@@ -0,0 +1,10 @@
+unifdef-y += drm.h drm_sarea.h
+unifdef-y += i810_drm.h
+unifdef-y += i830_drm.h
+unifdef-y += i915_drm.h
+unifdef-y += mga_drm.h
+unifdef-y += r128_drm.h
+unifdef-y += radeon_drm.h
+unifdef-y += sis_drm.h
+unifdef-y += savage_drm.h
+unifdef-y += via_drm.h
diff --git a/include/drm/drm.h b/include/drm/drm.h
new file mode 100644 (file)
index 0000000..38d3c6b
--- /dev/null
@@ -0,0 +1,694 @@
+/**
+ * \file drm.h
+ * Header for the Direct Rendering Manager
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ *
+ * \par Acknowledgments:
+ * Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic \c cmpxchg.
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_H_
+#define _DRM_H_
+
+#if defined(__linux__)
+#if defined(__KERNEL__)
+#endif
+#include <asm/ioctl.h>         /* For _IO* macros */
+#define DRM_IOCTL_NR(n)                _IOC_NR(n)
+#define DRM_IOC_VOID           _IOC_NONE
+#define DRM_IOC_READ           _IOC_READ
+#define DRM_IOC_WRITE          _IOC_WRITE
+#define DRM_IOC_READWRITE      _IOC_READ|_IOC_WRITE
+#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) && defined(IN_MODULE)
+/* Prevent name collision when including sys/ioccom.h */
+#undef ioctl
+#include <sys/ioccom.h>
+#define ioctl(a,b,c)           xf86ioctl(a,b,c)
+#else
+#include <sys/ioccom.h>
+#endif                         /* __FreeBSD__ && xf86ioctl */
+#define DRM_IOCTL_NR(n)                ((n) & 0xff)
+#define DRM_IOC_VOID           IOC_VOID
+#define DRM_IOC_READ           IOC_OUT
+#define DRM_IOC_WRITE          IOC_IN
+#define DRM_IOC_READWRITE      IOC_INOUT
+#define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
+#endif
+
+#define DRM_MAJOR       226
+#define DRM_MAX_MINOR   15
+
+#define DRM_NAME       "drm"     /**< Name in kernel, /dev, and /proc */
+#define DRM_MIN_ORDER  5         /**< At least 2^5 bytes = 32 bytes */
+#define DRM_MAX_ORDER  22        /**< Up to 2^22 bytes = 4MB */
+#define DRM_RAM_PERCENT 10       /**< How much system ram can we lock? */
+
+#define _DRM_LOCK_HELD 0x80000000U /**< Hardware lock is held */
+#define _DRM_LOCK_CONT 0x40000000U /**< Hardware lock is contended */
+#define _DRM_LOCK_IS_HELD(lock)           ((lock) & _DRM_LOCK_HELD)
+#define _DRM_LOCK_IS_CONT(lock)           ((lock) & _DRM_LOCK_CONT)
+#define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
+
+typedef unsigned int drm_handle_t;
+typedef unsigned int drm_context_t;
+typedef unsigned int drm_drawable_t;
+typedef unsigned int drm_magic_t;
+
+/**
+ * Cliprect.
+ *
+ * \warning: If you change this structure, make sure you change
+ * XF86DRIClipRectRec in the server as well
+ *
+ * \note KW: Actually it's illegal to change either for
+ * backwards-compatibility reasons.
+ */
+struct drm_clip_rect {
+       unsigned short x1;
+       unsigned short y1;
+       unsigned short x2;
+       unsigned short y2;
+};
+
+/**
+ * Drawable information.
+ */
+struct drm_drawable_info {
+       unsigned int num_rects;
+       struct drm_clip_rect *rects;
+};
+
+/**
+ * Texture region,
+ */
+struct drm_tex_region {
+       unsigned char next;
+       unsigned char prev;
+       unsigned char in_use;
+       unsigned char padding;
+       unsigned int age;
+};
+
+/**
+ * Hardware lock.
+ *
+ * The lock structure is a simple cache-line aligned integer.  To avoid
+ * processor bus contention on a multiprocessor system, there should not be any
+ * other data stored in the same cache line.
+ */
+struct drm_hw_lock {
+       __volatile__ unsigned int lock;         /**< lock variable */
+       char padding[60];                       /**< Pad to cache line */
+};
+
+/**
+ * DRM_IOCTL_VERSION ioctl argument type.
+ *
+ * \sa drmGetVersion().
+ */
+struct drm_version {
+       int version_major;        /**< Major version */
+       int version_minor;        /**< Minor version */
+       int version_patchlevel;   /**< Patch level */
+       size_t name_len;          /**< Length of name buffer */
+       char __user *name;        /**< Name of driver */
+       size_t date_len;          /**< Length of date buffer */
+       char __user *date;        /**< User-space buffer to hold date */
+       size_t desc_len;          /**< Length of desc buffer */
+       char __user *desc;        /**< User-space buffer to hold desc */
+};
+
+/**
+ * DRM_IOCTL_GET_UNIQUE ioctl argument type.
+ *
+ * \sa drmGetBusid() and drmSetBusId().
+ */
+struct drm_unique {
+       size_t unique_len;        /**< Length of unique */
+       char __user *unique;      /**< Unique name for driver instantiation */
+};
+
+struct drm_list {
+       int count;                /**< Length of user-space structures */
+       struct drm_version __user *version;
+};
+
+struct drm_block {
+       int unused;
+};
+
+/**
+ * DRM_IOCTL_CONTROL ioctl argument type.
+ *
+ * \sa drmCtlInstHandler() and drmCtlUninstHandler().
+ */
+struct drm_control {
+       enum {
+               DRM_ADD_COMMAND,
+               DRM_RM_COMMAND,
+               DRM_INST_HANDLER,
+               DRM_UNINST_HANDLER
+       } func;
+       int irq;
+};
+
+/**
+ * Type of memory to map.
+ */
+enum drm_map_type {
+       _DRM_FRAME_BUFFER = 0,    /**< WC (no caching), no core dump */
+       _DRM_REGISTERS = 1,       /**< no caching, no core dump */
+       _DRM_SHM = 2,             /**< shared, cached */
+       _DRM_AGP = 3,             /**< AGP/GART */
+       _DRM_SCATTER_GATHER = 4,  /**< Scatter/gather memory for PCI DMA */
+       _DRM_CONSISTENT = 5,      /**< Consistent memory for PCI DMA */
+};
+
+/**
+ * Memory mapping flags.
+ */
+enum drm_map_flags {
+       _DRM_RESTRICTED = 0x01,      /**< Cannot be mapped to user-virtual */
+       _DRM_READ_ONLY = 0x02,
+       _DRM_LOCKED = 0x04,          /**< shared, cached, locked */
+       _DRM_KERNEL = 0x08,          /**< kernel requires access */
+       _DRM_WRITE_COMBINING = 0x10, /**< use write-combining if available */
+       _DRM_CONTAINS_LOCK = 0x20,   /**< SHM page that contains lock */
+       _DRM_REMOVABLE = 0x40,       /**< Removable mapping */
+       _DRM_DRIVER = 0x80           /**< Managed by driver */
+};
+
+struct drm_ctx_priv_map {
+       unsigned int ctx_id;     /**< Context requesting private mapping */
+       void *handle;            /**< Handle of map */
+};
+
+/**
+ * DRM_IOCTL_GET_MAP, DRM_IOCTL_ADD_MAP and DRM_IOCTL_RM_MAP ioctls
+ * argument type.
+ *
+ * \sa drmAddMap().
+ */
+struct drm_map {
+       unsigned long offset;    /**< Requested physical address (0 for SAREA)*/
+       unsigned long size;      /**< Requested physical size (bytes) */
+       enum drm_map_type type;  /**< Type of memory to map */
+       enum drm_map_flags flags;        /**< Flags */
+       void *handle;            /**< User-space: "Handle" to pass to mmap() */
+                                /**< Kernel-space: kernel-virtual address */
+       int mtrr;                /**< MTRR slot used */
+       /*   Private data */
+};
+
+/**
+ * DRM_IOCTL_GET_CLIENT ioctl argument type.
+ */
+struct drm_client {
+       int idx;                /**< Which client desired? */
+       int auth;               /**< Is client authenticated? */
+       unsigned long pid;      /**< Process ID */
+       unsigned long uid;      /**< User ID */
+       unsigned long magic;    /**< Magic */
+       unsigned long iocs;     /**< Ioctl count */
+};
+
+enum drm_stat_type {
+       _DRM_STAT_LOCK,
+       _DRM_STAT_OPENS,
+       _DRM_STAT_CLOSES,
+       _DRM_STAT_IOCTLS,
+       _DRM_STAT_LOCKS,
+       _DRM_STAT_UNLOCKS,
+       _DRM_STAT_VALUE,        /**< Generic value */
+       _DRM_STAT_BYTE,         /**< Generic byte counter (1024bytes/K) */
+       _DRM_STAT_COUNT,        /**< Generic non-byte counter (1000/k) */
+
+       _DRM_STAT_IRQ,          /**< IRQ */
+       _DRM_STAT_PRIMARY,      /**< Primary DMA bytes */
+       _DRM_STAT_SECONDARY,    /**< Secondary DMA bytes */
+       _DRM_STAT_DMA,          /**< DMA */
+       _DRM_STAT_SPECIAL,      /**< Special DMA (e.g., priority or polled) */
+       _DRM_STAT_MISSED        /**< Missed DMA opportunity */
+           /* Add to the *END* of the list */
+};
+
+/**
+ * DRM_IOCTL_GET_STATS ioctl argument type.
+ */
+struct drm_stats {
+       unsigned long count;
+       struct {
+               unsigned long value;
+               enum drm_stat_type type;
+       } data[15];
+};
+
+/**
+ * Hardware locking flags.
+ */
+enum drm_lock_flags {
+       _DRM_LOCK_READY = 0x01,      /**< Wait until hardware is ready for DMA */
+       _DRM_LOCK_QUIESCENT = 0x02,  /**< Wait until hardware quiescent */
+       _DRM_LOCK_FLUSH = 0x04,      /**< Flush this context's DMA queue first */
+       _DRM_LOCK_FLUSH_ALL = 0x08,  /**< Flush all DMA queues first */
+       /* These *HALT* flags aren't supported yet
+          -- they will be used to support the
+          full-screen DGA-like mode. */
+       _DRM_HALT_ALL_QUEUES = 0x10, /**< Halt all current and future queues */
+       _DRM_HALT_CUR_QUEUES = 0x20  /**< Halt all current queues */
+};
+
+/**
+ * DRM_IOCTL_LOCK, DRM_IOCTL_UNLOCK and DRM_IOCTL_FINISH ioctl argument type.
+ *
+ * \sa drmGetLock() and drmUnlock().
+ */
+struct drm_lock {
+       int context;
+       enum drm_lock_flags flags;
+};
+
+/**
+ * DMA flags
+ *
+ * \warning
+ * These values \e must match xf86drm.h.
+ *
+ * \sa drm_dma.
+ */
+enum drm_dma_flags {
+       /* Flags for DMA buffer dispatch */
+       _DRM_DMA_BLOCK = 0x01,        /**<
+                                      * Block until buffer dispatched.
+                                      *
+                                      * \note The buffer may not yet have
+                                      * been processed by the hardware --
+                                      * getting a hardware lock with the
+                                      * hardware quiescent will ensure
+                                      * that the buffer has been
+                                      * processed.
+                                      */
+       _DRM_DMA_WHILE_LOCKED = 0x02, /**< Dispatch while lock held */
+       _DRM_DMA_PRIORITY = 0x04,     /**< High priority dispatch */
+
+       /* Flags for DMA buffer request */
+       _DRM_DMA_WAIT = 0x10,         /**< Wait for free buffers */
+       _DRM_DMA_SMALLER_OK = 0x20,   /**< Smaller-than-requested buffers OK */
+       _DRM_DMA_LARGER_OK = 0x40     /**< Larger-than-requested buffers OK */
+};
+
+/**
+ * DRM_IOCTL_ADD_BUFS and DRM_IOCTL_MARK_BUFS ioctl argument type.
+ *
+ * \sa drmAddBufs().
+ */
+struct drm_buf_desc {
+       int count;               /**< Number of buffers of this size */
+       int size;                /**< Size in bytes */
+       int low_mark;            /**< Low water mark */
+       int high_mark;           /**< High water mark */
+       enum {
+               _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
+               _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
+               _DRM_SG_BUFFER = 0x04,  /**< Scatter/gather memory buffer */
+               _DRM_FB_BUFFER = 0x08,  /**< Buffer is in frame buffer */
+               _DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
+       } flags;
+       unsigned long agp_start; /**<
+                                 * Start address of where the AGP buffers are
+                                 * in the AGP aperture
+                                 */
+};
+
+/**
+ * DRM_IOCTL_INFO_BUFS ioctl argument type.
+ */
+struct drm_buf_info {
+       int count;              /**< Entries in list */
+       struct drm_buf_desc __user *list;
+};
+
+/**
+ * DRM_IOCTL_FREE_BUFS ioctl argument type.
+ */
+struct drm_buf_free {
+       int count;
+       int __user *list;
+};
+
+/**
+ * Buffer information
+ *
+ * \sa drm_buf_map.
+ */
+struct drm_buf_pub {
+       int idx;                       /**< Index into the master buffer list */
+       int total;                     /**< Buffer size */
+       int used;                      /**< Amount of buffer in use (for DMA) */
+       void __user *address;          /**< Address of buffer */
+};
+
+/**
+ * DRM_IOCTL_MAP_BUFS ioctl argument type.
+ */
+struct drm_buf_map {
+       int count;              /**< Length of the buffer list */
+       void __user *virtual;           /**< Mmap'd area in user-virtual */
+       struct drm_buf_pub __user *list;        /**< Buffer information */
+};
+
+/**
+ * DRM_IOCTL_DMA ioctl argument type.
+ *
+ * Indices here refer to the offset into the buffer list in drm_buf_get.
+ *
+ * \sa drmDMA().
+ */
+struct drm_dma {
+       int context;                      /**< Context handle */
+       int send_count;                   /**< Number of buffers to send */
+       int __user *send_indices;         /**< List of handles to buffers */
+       int __user *send_sizes;           /**< Lengths of data to send */
+       enum drm_dma_flags flags;         /**< Flags */
+       int request_count;                /**< Number of buffers requested */
+       int request_size;                 /**< Desired size for buffers */
+       int __user *request_indices;      /**< Buffer information */
+       int __user *request_sizes;
+       int granted_count;                /**< Number of buffers granted */
+};
+
+enum drm_ctx_flags {
+       _DRM_CONTEXT_PRESERVED = 0x01,
+       _DRM_CONTEXT_2DONLY = 0x02
+};
+
+/**
+ * DRM_IOCTL_ADD_CTX ioctl argument type.
+ *
+ * \sa drmCreateContext() and drmDestroyContext().
+ */
+struct drm_ctx {
+       drm_context_t handle;
+       enum drm_ctx_flags flags;
+};
+
+/**
+ * DRM_IOCTL_RES_CTX ioctl argument type.
+ */
+struct drm_ctx_res {
+       int count;
+       struct drm_ctx __user *contexts;
+};
+
+/**
+ * DRM_IOCTL_ADD_DRAW and DRM_IOCTL_RM_DRAW ioctl argument type.
+ */
+struct drm_draw {
+       drm_drawable_t handle;
+};
+
+/**
+ * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
+ */
+typedef enum {
+       DRM_DRAWABLE_CLIPRECTS,
+} drm_drawable_info_type_t;
+
+struct drm_update_draw {
+       drm_drawable_t handle;
+       unsigned int type;
+       unsigned int num;
+       unsigned long long data;
+};
+
+/**
+ * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
+ */
+struct drm_auth {
+       drm_magic_t magic;
+};
+
+/**
+ * DRM_IOCTL_IRQ_BUSID ioctl argument type.
+ *
+ * \sa drmGetInterruptFromBusID().
+ */
+struct drm_irq_busid {
+       int irq;        /**< IRQ number */
+       int busnum;     /**< bus number */
+       int devnum;     /**< device number */
+       int funcnum;    /**< function number */
+};
+
+enum drm_vblank_seq_type {
+       _DRM_VBLANK_ABSOLUTE = 0x0,     /**< Wait for specific vblank sequence number */
+       _DRM_VBLANK_RELATIVE = 0x1,     /**< Wait for given number of vblanks */
+       _DRM_VBLANK_NEXTONMISS = 0x10000000,    /**< If missed, wait for next vblank */
+       _DRM_VBLANK_SECONDARY = 0x20000000,     /**< Secondary display controller */
+       _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */
+};
+
+#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
+#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \
+                               _DRM_VBLANK_NEXTONMISS)
+
+struct drm_wait_vblank_request {
+       enum drm_vblank_seq_type type;
+       unsigned int sequence;
+       unsigned long signal;
+};
+
+struct drm_wait_vblank_reply {
+       enum drm_vblank_seq_type type;
+       unsigned int sequence;
+       long tval_sec;
+       long tval_usec;
+};
+
+/**
+ * DRM_IOCTL_WAIT_VBLANK ioctl argument type.
+ *
+ * \sa drmWaitVBlank().
+ */
+union drm_wait_vblank {
+       struct drm_wait_vblank_request request;
+       struct drm_wait_vblank_reply reply;
+};
+
+/**
+ * DRM_IOCTL_AGP_ENABLE ioctl argument type.
+ *
+ * \sa drmAgpEnable().
+ */
+struct drm_agp_mode {
+       unsigned long mode;     /**< AGP mode */
+};
+
+/**
+ * DRM_IOCTL_AGP_ALLOC and DRM_IOCTL_AGP_FREE ioctls argument type.
+ *
+ * \sa drmAgpAlloc() and drmAgpFree().
+ */
+struct drm_agp_buffer {
+       unsigned long size;     /**< In bytes -- will round to page boundary */
+       unsigned long handle;   /**< Used for binding / unbinding */
+       unsigned long type;     /**< Type of memory to allocate */
+       unsigned long physical; /**< Physical used by i810 */
+};
+
+/**
+ * DRM_IOCTL_AGP_BIND and DRM_IOCTL_AGP_UNBIND ioctls argument type.
+ *
+ * \sa drmAgpBind() and drmAgpUnbind().
+ */
+struct drm_agp_binding {
+       unsigned long handle;   /**< From drm_agp_buffer */
+       unsigned long offset;   /**< In bytes -- will round to page boundary */
+};
+
+/**
+ * DRM_IOCTL_AGP_INFO ioctl argument type.
+ *
+ * \sa drmAgpVersionMajor(), drmAgpVersionMinor(), drmAgpGetMode(),
+ * drmAgpBase(), drmAgpSize(), drmAgpMemoryUsed(), drmAgpMemoryAvail(),
+ * drmAgpVendorId() and drmAgpDeviceId().
+ */
+struct drm_agp_info {
+       int agp_version_major;
+       int agp_version_minor;
+       unsigned long mode;
+       unsigned long aperture_base;    /* physical address */
+       unsigned long aperture_size;    /* bytes */
+       unsigned long memory_allowed;   /* bytes */
+       unsigned long memory_used;
+
+       /* PCI information */
+       unsigned short id_vendor;
+       unsigned short id_device;
+};
+
+/**
+ * DRM_IOCTL_SG_ALLOC ioctl argument type.
+ */
+struct drm_scatter_gather {
+       unsigned long size;     /**< In bytes -- will round to page boundary */
+       unsigned long handle;   /**< Used for mapping / unmapping */
+};
+
+/**
+ * DRM_IOCTL_SET_VERSION ioctl argument type.
+ */
+struct drm_set_version {
+       int drm_di_major;
+       int drm_di_minor;
+       int drm_dd_major;
+       int drm_dd_minor;
+};
+
+#define DRM_IOCTL_BASE                 'd'
+#define DRM_IO(nr)                     _IO(DRM_IOCTL_BASE,nr)
+#define DRM_IOR(nr,type)               _IOR(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOW(nr,type)               _IOW(DRM_IOCTL_BASE,nr,type)
+#define DRM_IOWR(nr,type)              _IOWR(DRM_IOCTL_BASE,nr,type)
+
+#define DRM_IOCTL_VERSION              DRM_IOWR(0x00, struct drm_version)
+#define DRM_IOCTL_GET_UNIQUE           DRM_IOWR(0x01, struct drm_unique)
+#define DRM_IOCTL_GET_MAGIC            DRM_IOR( 0x02, struct drm_auth)
+#define DRM_IOCTL_IRQ_BUSID            DRM_IOWR(0x03, struct drm_irq_busid)
+#define DRM_IOCTL_GET_MAP               DRM_IOWR(0x04, struct drm_map)
+#define DRM_IOCTL_GET_CLIENT            DRM_IOWR(0x05, struct drm_client)
+#define DRM_IOCTL_GET_STATS             DRM_IOR( 0x06, struct drm_stats)
+#define DRM_IOCTL_SET_VERSION          DRM_IOWR(0x07, struct drm_set_version)
+
+#define DRM_IOCTL_SET_UNIQUE           DRM_IOW( 0x10, struct drm_unique)
+#define DRM_IOCTL_AUTH_MAGIC           DRM_IOW( 0x11, struct drm_auth)
+#define DRM_IOCTL_BLOCK                        DRM_IOWR(0x12, struct drm_block)
+#define DRM_IOCTL_UNBLOCK              DRM_IOWR(0x13, struct drm_block)
+#define DRM_IOCTL_CONTROL              DRM_IOW( 0x14, struct drm_control)
+#define DRM_IOCTL_ADD_MAP              DRM_IOWR(0x15, struct drm_map)
+#define DRM_IOCTL_ADD_BUFS             DRM_IOWR(0x16, struct drm_buf_desc)
+#define DRM_IOCTL_MARK_BUFS            DRM_IOW( 0x17, struct drm_buf_desc)
+#define DRM_IOCTL_INFO_BUFS            DRM_IOWR(0x18, struct drm_buf_info)
+#define DRM_IOCTL_MAP_BUFS             DRM_IOWR(0x19, struct drm_buf_map)
+#define DRM_IOCTL_FREE_BUFS            DRM_IOW( 0x1a, struct drm_buf_free)
+
+#define DRM_IOCTL_RM_MAP               DRM_IOW( 0x1b, struct drm_map)
+
+#define DRM_IOCTL_SET_SAREA_CTX                DRM_IOW( 0x1c, struct drm_ctx_priv_map)
+#define DRM_IOCTL_GET_SAREA_CTX        DRM_IOWR(0x1d, struct drm_ctx_priv_map)
+
+#define DRM_IOCTL_ADD_CTX              DRM_IOWR(0x20, struct drm_ctx)
+#define DRM_IOCTL_RM_CTX               DRM_IOWR(0x21, struct drm_ctx)
+#define DRM_IOCTL_MOD_CTX              DRM_IOW( 0x22, struct drm_ctx)
+#define DRM_IOCTL_GET_CTX              DRM_IOWR(0x23, struct drm_ctx)
+#define DRM_IOCTL_SWITCH_CTX           DRM_IOW( 0x24, struct drm_ctx)
+#define DRM_IOCTL_NEW_CTX              DRM_IOW( 0x25, struct drm_ctx)
+#define DRM_IOCTL_RES_CTX              DRM_IOWR(0x26, struct drm_ctx_res)
+#define DRM_IOCTL_ADD_DRAW             DRM_IOWR(0x27, struct drm_draw)
+#define DRM_IOCTL_RM_DRAW              DRM_IOWR(0x28, struct drm_draw)
+#define DRM_IOCTL_DMA                  DRM_IOWR(0x29, struct drm_dma)
+#define DRM_IOCTL_LOCK                 DRM_IOW( 0x2a, struct drm_lock)
+#define DRM_IOCTL_UNLOCK               DRM_IOW( 0x2b, struct drm_lock)
+#define DRM_IOCTL_FINISH               DRM_IOW( 0x2c, struct drm_lock)
+
+#define DRM_IOCTL_AGP_ACQUIRE          DRM_IO(  0x30)
+#define DRM_IOCTL_AGP_RELEASE          DRM_IO(  0x31)
+#define DRM_IOCTL_AGP_ENABLE           DRM_IOW( 0x32, struct drm_agp_mode)
+#define DRM_IOCTL_AGP_INFO             DRM_IOR( 0x33, struct drm_agp_info)
+#define DRM_IOCTL_AGP_ALLOC            DRM_IOWR(0x34, struct drm_agp_buffer)
+#define DRM_IOCTL_AGP_FREE             DRM_IOW( 0x35, struct drm_agp_buffer)
+#define DRM_IOCTL_AGP_BIND             DRM_IOW( 0x36, struct drm_agp_binding)
+#define DRM_IOCTL_AGP_UNBIND           DRM_IOW( 0x37, struct drm_agp_binding)
+
+#define DRM_IOCTL_SG_ALLOC             DRM_IOWR(0x38, struct drm_scatter_gather)
+#define DRM_IOCTL_SG_FREE              DRM_IOW( 0x39, struct drm_scatter_gather)
+
+#define DRM_IOCTL_WAIT_VBLANK          DRM_IOWR(0x3a, union drm_wait_vblank)
+
+#define DRM_IOCTL_UPDATE_DRAW          DRM_IOW(0x3f, struct drm_update_draw)
+
+/**
+ * Device specific ioctls should only be in their respective headers
+ * The device specific ioctl range is from 0x40 to 0x99.
+ * Generic IOCTLS restart at 0xA0.
+ *
+ * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
+ * drmCommandReadWrite().
+ */
+#define DRM_COMMAND_BASE                0x40
+#define DRM_COMMAND_END                        0xA0
+
+/* typedef area */
+#ifndef __KERNEL__
+typedef struct drm_clip_rect drm_clip_rect_t;
+typedef struct drm_drawable_info drm_drawable_info_t;
+typedef struct drm_tex_region drm_tex_region_t;
+typedef struct drm_hw_lock drm_hw_lock_t;
+typedef struct drm_version drm_version_t;
+typedef struct drm_unique drm_unique_t;
+typedef struct drm_list drm_list_t;
+typedef struct drm_block drm_block_t;
+typedef struct drm_control drm_control_t;
+typedef enum drm_map_type drm_map_type_t;
+typedef enum drm_map_flags drm_map_flags_t;
+typedef struct drm_ctx_priv_map drm_ctx_priv_map_t;
+typedef struct drm_map drm_map_t;
+typedef struct drm_client drm_client_t;
+typedef enum drm_stat_type drm_stat_type_t;
+typedef struct drm_stats drm_stats_t;
+typedef enum drm_lock_flags drm_lock_flags_t;
+typedef struct drm_lock drm_lock_t;
+typedef enum drm_dma_flags drm_dma_flags_t;
+typedef struct drm_buf_desc drm_buf_desc_t;
+typedef struct drm_buf_info drm_buf_info_t;
+typedef struct drm_buf_free drm_buf_free_t;
+typedef struct drm_buf_pub drm_buf_pub_t;
+typedef struct drm_buf_map drm_buf_map_t;
+typedef struct drm_dma drm_dma_t;
+typedef union drm_wait_vblank drm_wait_vblank_t;
+typedef struct drm_agp_mode drm_agp_mode_t;
+typedef enum drm_ctx_flags drm_ctx_flags_t;
+typedef struct drm_ctx drm_ctx_t;
+typedef struct drm_ctx_res drm_ctx_res_t;
+typedef struct drm_draw drm_draw_t;
+typedef struct drm_update_draw drm_update_draw_t;
+typedef struct drm_auth drm_auth_t;
+typedef struct drm_irq_busid drm_irq_busid_t;
+typedef enum drm_vblank_seq_type drm_vblank_seq_type_t;
+
+typedef struct drm_agp_buffer drm_agp_buffer_t;
+typedef struct drm_agp_binding drm_agp_binding_t;
+typedef struct drm_agp_info drm_agp_info_t;
+typedef struct drm_scatter_gather drm_scatter_gather_t;
+typedef struct drm_set_version drm_set_version_t;
+#endif
+
+#endif
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
new file mode 100644 (file)
index 0000000..0764b66
--- /dev/null
@@ -0,0 +1,1153 @@
+/**
+ * \file drmP.h
+ * Private header for Direct Rendering Manager
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_P_H_
+#define _DRM_P_H_
+
+/* If you want the memory alloc debug functionality, change define below */
+/* #define DEBUG_MEMORY */
+
+#ifdef __KERNEL__
+#ifdef __alpha__
+/* add include of current.h so that "current" is defined
+ * before static inline funcs in wait.h. Doing this so we
+ * can build the DRM (part of PI DRI). 4/21/2000 S + B */
+#include <asm/current.h>
+#endif                         /* __alpha__ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/miscdevice.h>
+#include <linux/fs.h>
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+#include <linux/file.h>
+#include <linux/pci.h>
+#include <linux/jiffies.h>
+#include <linux/smp_lock.h>    /* For (un)lock_kernel */
+#include <linux/dma-mapping.h>
+#include <linux/mm.h>
+#include <linux/cdev.h>
+#include <linux/mutex.h>
+#if defined(__alpha__) || defined(__powerpc__)
+#include <asm/pgtable.h>       /* For pte_wrprotect */
+#endif
+#include <asm/io.h>
+#include <asm/mman.h>
+#include <asm/uaccess.h>
+#ifdef CONFIG_MTRR
+#include <asm/mtrr.h>
+#endif
+#if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
+#include <linux/types.h>
+#include <linux/agp_backend.h>
+#endif
+#include <linux/workqueue.h>
+#include <linux/poll.h>
+#include <asm/pgalloc.h>
+#include "drm.h"
+
+#include <linux/idr.h>
+
+#define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
+#define __OS_HAS_MTRR (defined(CONFIG_MTRR))
+
+struct drm_file;
+struct drm_device;
+
+#include "drm_os_linux.h"
+#include "drm_hashtab.h"
+
+/***********************************************************************/
+/** \name DRM template customization defaults */
+/*@{*/
+
+/* driver capabilities and requirements mask */
+#define DRIVER_USE_AGP     0x1
+#define DRIVER_REQUIRE_AGP 0x2
+#define DRIVER_USE_MTRR    0x4
+#define DRIVER_PCI_DMA     0x8
+#define DRIVER_SG          0x10
+#define DRIVER_HAVE_DMA    0x20
+#define DRIVER_HAVE_IRQ    0x40
+#define DRIVER_IRQ_SHARED  0x80
+#define DRIVER_IRQ_VBL     0x100
+#define DRIVER_DMA_QUEUE   0x200
+#define DRIVER_FB_DMA      0x400
+#define DRIVER_IRQ_VBL2    0x800
+
+/***********************************************************************/
+/** \name Begin the DRM... */
+/*@{*/
+
+#define DRM_DEBUG_CODE 2         /**< Include debugging code if > 1, then
+                                    also include looping detection. */
+
+#define DRM_MAGIC_HASH_ORDER  4  /**< Size of key hash table. Must be power of 2. */
+#define DRM_KERNEL_CONTEXT    0         /**< Change drm_resctx if changed */
+#define DRM_RESERVED_CONTEXTS 1         /**< Change drm_resctx if changed */
+#define DRM_LOOPING_LIMIT     5000000
+#define DRM_TIME_SLICE       (HZ/20)  /**< Time slice for GLXContexts */
+#define DRM_LOCK_SLICE       1 /**< Time slice for lock, in jiffies */
+
+#define DRM_FLAG_DEBUG   0x01
+
+#define DRM_MEM_DMA       0
+#define DRM_MEM_SAREA     1
+#define DRM_MEM_DRIVER    2
+#define DRM_MEM_MAGIC     3
+#define DRM_MEM_IOCTLS    4
+#define DRM_MEM_MAPS      5
+#define DRM_MEM_VMAS      6
+#define DRM_MEM_BUFS      7
+#define DRM_MEM_SEGS      8
+#define DRM_MEM_PAGES     9
+#define DRM_MEM_FILES    10
+#define DRM_MEM_QUEUES   11
+#define DRM_MEM_CMDS     12
+#define DRM_MEM_MAPPINGS  13
+#define DRM_MEM_BUFLISTS  14
+#define DRM_MEM_AGPLISTS  15
+#define DRM_MEM_TOTALAGP  16
+#define DRM_MEM_BOUNDAGP  17
+#define DRM_MEM_CTXBITMAP 18
+#define DRM_MEM_STUB      19
+#define DRM_MEM_SGLISTS   20
+#define DRM_MEM_CTXLIST   21
+#define DRM_MEM_MM        22
+#define DRM_MEM_HASHTAB   23
+
+#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
+#define DRM_MAP_HASH_OFFSET 0x10000000
+
+/*@}*/
+
+/***********************************************************************/
+/** \name Macros to make printk easier */
+/*@{*/
+
+/**
+ * Error output.
+ *
+ * \param fmt printf() like format string.
+ * \param arg arguments
+ */
+#define DRM_ERROR(fmt, arg...) \
+       printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
+
+/**
+ * Memory error output.
+ *
+ * \param area memory area where the error occurred.
+ * \param fmt printf() like format string.
+ * \param arg arguments
+ */
+#define DRM_MEM_ERROR(area, fmt, arg...) \
+       printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
+              drm_mem_stats[area].name , ##arg)
+
+#define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
+
+/**
+ * Debug output.
+ *
+ * \param fmt printf() like format string.
+ * \param arg arguments
+ */
+#if DRM_DEBUG_CODE
+#define DRM_DEBUG(fmt, arg...)                                         \
+       do {                                                            \
+               if ( drm_debug )                        \
+                       printk(KERN_DEBUG                               \
+                              "[" DRM_NAME ":%s] " fmt ,       \
+                              __func__ , ##arg);                       \
+       } while (0)
+#else
+#define DRM_DEBUG(fmt, arg...)          do { } while (0)
+#endif
+
+#define DRM_PROC_LIMIT (PAGE_SIZE-80)
+
+#define DRM_PROC_PRINT(fmt, arg...)                                    \
+   len += sprintf(&buf[len], fmt , ##arg);                             \
+   if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
+
+#define DRM_PROC_PRINT_RET(ret, fmt, arg...)                           \
+   len += sprintf(&buf[len], fmt , ##arg);                             \
+   if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
+
+/*@}*/
+
+/***********************************************************************/
+/** \name Internal types and structures */
+/*@{*/
+
+#define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
+
+#define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
+#define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
+#define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
+
+#define DRM_IF_VERSION(maj, min) (maj << 16 | min)
+/**
+ * Get the private SAREA mapping.
+ *
+ * \param _dev DRM device.
+ * \param _ctx context number.
+ * \param _map output mapping.
+ */
+#define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {      \
+       (_map) = (_dev)->context_sareas[_ctx];          \
+} while(0)
+
+/**
+ * Test that the hardware lock is held by the caller, returning otherwise.
+ *
+ * \param dev DRM device.
+ * \param filp file pointer of the caller.
+ */
+#define LOCK_TEST_WITH_RETURN( dev, file_priv )                                \
+do {                                                                   \
+       if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||           \
+            dev->lock.file_priv != file_priv ) {                       \
+               DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
+                          __func__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
+                          dev->lock.file_priv, file_priv );            \
+               return -EINVAL;                                         \
+       }                                                               \
+} while (0)
+
+/**
+ * Copy and IOCTL return string to user space
+ */
+#define DRM_COPY( name, value )                                                \
+       len = strlen( value );                                          \
+       if ( len > name##_len ) len = name##_len;                       \
+       name##_len = strlen( value );                                   \
+       if ( len && name ) {                                            \
+               if ( copy_to_user( name, value, len ) )                 \
+                       return -EFAULT;                                 \
+       }
+
+/**
+ * Ioctl function type.
+ *
+ * \param inode device inode.
+ * \param file_priv DRM file private pointer.
+ * \param cmd command.
+ * \param arg argument.
+ */
+typedef int drm_ioctl_t(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+
+typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
+                              unsigned long arg);
+
+#define DRM_AUTH       0x1
+#define        DRM_MASTER      0x2
+#define DRM_ROOT_ONLY  0x4
+
+struct drm_ioctl_desc {
+       unsigned int cmd;
+       drm_ioctl_t *func;
+       int flags;
+};
+
+/**
+ * Creates a driver or general drm_ioctl_desc array entry for the given
+ * ioctl, for use by drm_ioctl().
+ */
+#define DRM_IOCTL_DEF(ioctl, func, flags) \
+       [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
+
+struct drm_magic_entry {
+       struct list_head head;
+       struct drm_hash_item hash_item;
+       struct drm_file *priv;
+};
+
+struct drm_vma_entry {
+       struct list_head head;
+       struct vm_area_struct *vma;
+       pid_t pid;
+};
+
+/**
+ * DMA buffer.
+ */
+struct drm_buf {
+       int idx;                       /**< Index into master buflist */
+       int total;                     /**< Buffer size */
+       int order;                     /**< log-base-2(total) */
+       int used;                      /**< Amount of buffer in use (for DMA) */
+       unsigned long offset;          /**< Byte offset (used internally) */
+       void *address;                 /**< Address of buffer */
+       unsigned long bus_address;     /**< Bus address of buffer */
+       struct drm_buf *next;          /**< Kernel-only: used for free list */
+       __volatile__ int waiting;      /**< On kernel DMA queue */
+       __volatile__ int pending;      /**< On hardware DMA queue */
+       wait_queue_head_t dma_wait;    /**< Processes waiting */
+       struct drm_file *file_priv;    /**< Private of holding file descr */
+       int context;                   /**< Kernel queue for this buffer */
+       int while_locked;              /**< Dispatch this buffer while locked */
+       enum {
+               DRM_LIST_NONE = 0,
+               DRM_LIST_FREE = 1,
+               DRM_LIST_WAIT = 2,
+               DRM_LIST_PEND = 3,
+               DRM_LIST_PRIO = 4,
+               DRM_LIST_RECLAIM = 5
+       } list;                        /**< Which list we're on */
+
+       int dev_priv_size;               /**< Size of buffer private storage */
+       void *dev_private;               /**< Per-buffer private storage */
+};
+
+/** bufs is one longer than it has to be */
+struct drm_waitlist {
+       int count;                      /**< Number of possible buffers */
+       struct drm_buf **bufs;          /**< List of pointers to buffers */
+       struct drm_buf **rp;                    /**< Read pointer */
+       struct drm_buf **wp;                    /**< Write pointer */
+       struct drm_buf **end;           /**< End pointer */
+       spinlock_t read_lock;
+       spinlock_t write_lock;
+};
+
+struct drm_freelist {
+       int initialized;               /**< Freelist in use */
+       atomic_t count;                /**< Number of free buffers */
+       struct drm_buf *next;          /**< End pointer */
+
+       wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
+       int low_mark;                  /**< Low water mark */
+       int high_mark;                 /**< High water mark */
+       atomic_t wfh;                  /**< If waiting for high mark */
+       spinlock_t lock;
+};
+
+typedef struct drm_dma_handle {
+       dma_addr_t busaddr;
+       void *vaddr;
+       size_t size;
+} drm_dma_handle_t;
+
+/**
+ * Buffer entry.  There is one of this for each buffer size order.
+ */
+struct drm_buf_entry {
+       int buf_size;                   /**< size */
+       int buf_count;                  /**< number of buffers */
+       struct drm_buf *buflist;                /**< buffer list */
+       int seg_count;
+       int page_order;
+       struct drm_dma_handle **seglist;
+
+       struct drm_freelist freelist;
+};
+
+/** File private data */
+struct drm_file {
+       int authenticated;
+       int master;
+       pid_t pid;
+       uid_t uid;
+       drm_magic_t magic;
+       unsigned long ioctl_count;
+       struct list_head lhead;
+       struct drm_minor *minor;
+       int remove_auth_on_close;
+       unsigned long lock_count;
+       struct file *filp;
+       void *driver_priv;
+};
+
+/** Wait queue */
+struct drm_queue {
+       atomic_t use_count;             /**< Outstanding uses (+1) */
+       atomic_t finalization;          /**< Finalization in progress */
+       atomic_t block_count;           /**< Count of processes waiting */
+       atomic_t block_read;            /**< Queue blocked for reads */
+       wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
+       atomic_t block_write;           /**< Queue blocked for writes */
+       wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
+       atomic_t total_queued;          /**< Total queued statistic */
+       atomic_t total_flushed;         /**< Total flushes statistic */
+       atomic_t total_locks;           /**< Total locks statistics */
+       enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
+       struct drm_waitlist waitlist;   /**< Pending buffers */
+       wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
+};
+
+/**
+ * Lock data.
+ */
+struct drm_lock_data {
+       struct drm_hw_lock *hw_lock;    /**< Hardware lock */
+       /** Private of lock holder's file (NULL=kernel) */
+       struct drm_file *file_priv;
+       wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
+       unsigned long lock_time;        /**< Time of last lock in jiffies */
+       spinlock_t spinlock;
+       uint32_t kernel_waiters;
+       uint32_t user_waiters;
+       int idle_has_lock;
+};
+
+/**
+ * DMA data.
+ */
+struct drm_device_dma {
+
+       struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
+       int buf_count;                  /**< total number of buffers */
+       struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
+       int seg_count;
+       int page_count;                 /**< number of pages */
+       unsigned long *pagelist;        /**< page list */
+       unsigned long byte_count;
+       enum {
+               _DRM_DMA_USE_AGP = 0x01,
+               _DRM_DMA_USE_SG = 0x02,
+               _DRM_DMA_USE_FB = 0x04,
+               _DRM_DMA_USE_PCI_RO = 0x08
+       } flags;
+
+};
+
+/**
+ * AGP memory entry.  Stored as a doubly linked list.
+ */
+struct drm_agp_mem {
+       unsigned long handle;           /**< handle */
+       DRM_AGP_MEM *memory;
+       unsigned long bound;            /**< address */
+       int pages;
+       struct list_head head;
+};
+
+/**
+ * AGP data.
+ *
+ * \sa drm_agp_init() and drm_device::agp.
+ */
+struct drm_agp_head {
+       DRM_AGP_KERN agp_info;          /**< AGP device information */
+       struct list_head memory;
+       unsigned long mode;             /**< AGP mode */
+       struct agp_bridge_data *bridge;
+       int enabled;                    /**< whether the AGP bus as been enabled */
+       int acquired;                   /**< whether the AGP device has been acquired */
+       unsigned long base;
+       int agp_mtrr;
+       int cant_use_aperture;
+       unsigned long page_mask;
+};
+
+/**
+ * Scatter-gather memory.
+ */
+struct drm_sg_mem {
+       unsigned long handle;
+       void *virtual;
+       int pages;
+       struct page **pagelist;
+       dma_addr_t *busaddr;
+};
+
+struct drm_sigdata {
+       int context;
+       struct drm_hw_lock *lock;
+};
+
+
+/*
+ * Generic memory manager structs
+ */
+
+struct drm_mm_node {
+       struct list_head fl_entry;
+       struct list_head ml_entry;
+       int free;
+       unsigned long start;
+       unsigned long size;
+       struct drm_mm *mm;
+       void *private;
+};
+
+struct drm_mm {
+       struct list_head fl_entry;
+       struct list_head ml_entry;
+};
+
+
+/**
+ * Mappings list
+ */
+struct drm_map_list {
+       struct list_head head;          /**< list head */
+       struct drm_hash_item hash;
+       struct drm_map *map;                    /**< mapping */
+       uint64_t user_token;
+};
+
+typedef struct drm_map drm_local_map_t;
+
+/**
+ * Context handle list
+ */
+struct drm_ctx_list {
+       struct list_head head;          /**< list head */
+       drm_context_t handle;           /**< context handle */
+       struct drm_file *tag;           /**< associated fd private data */
+};
+
+struct drm_vbl_sig {
+       struct list_head head;
+       unsigned int sequence;
+       struct siginfo info;
+       struct task_struct *task;
+};
+
+/* location of GART table */
+#define DRM_ATI_GART_MAIN 1
+#define DRM_ATI_GART_FB   2
+
+#define DRM_ATI_GART_PCI 1
+#define DRM_ATI_GART_PCIE 2
+#define DRM_ATI_GART_IGP 3
+
+struct drm_ati_pcigart_info {
+       int gart_table_location;
+       int gart_reg_if;
+       void *addr;
+       dma_addr_t bus_addr;
+       dma_addr_t table_mask;
+       struct drm_dma_handle *table_handle;
+       drm_local_map_t mapping;
+       int table_size;
+};
+
+/**
+ * DRM driver structure. This structure represent the common code for
+ * a family of cards. There will one drm_device for each card present
+ * in this family
+ */
+struct drm_driver {
+       int (*load) (struct drm_device *, unsigned long flags);
+       int (*firstopen) (struct drm_device *);
+       int (*open) (struct drm_device *, struct drm_file *);
+       void (*preclose) (struct drm_device *, struct drm_file *file_priv);
+       void (*postclose) (struct drm_device *, struct drm_file *);
+       void (*lastclose) (struct drm_device *);
+       int (*unload) (struct drm_device *);
+       int (*suspend) (struct drm_device *, pm_message_t state);
+       int (*resume) (struct drm_device *);
+       int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
+       void (*dma_ready) (struct drm_device *);
+       int (*dma_quiescent) (struct drm_device *);
+       int (*context_ctor) (struct drm_device *dev, int context);
+       int (*context_dtor) (struct drm_device *dev, int context);
+       int (*kernel_context_switch) (struct drm_device *dev, int old,
+                                     int new);
+       void (*kernel_context_switch_unlock) (struct drm_device *dev);
+       int (*vblank_wait) (struct drm_device *dev, unsigned int *sequence);
+       int (*vblank_wait2) (struct drm_device *dev, unsigned int *sequence);
+       int (*dri_library_name) (struct drm_device *dev, char *buf);
+
+       /**
+        * Called by \c drm_device_is_agp.  Typically used to determine if a
+        * card is really attached to AGP or not.
+        *
+        * \param dev  DRM device handle
+        *
+        * \returns
+        * One of three values is returned depending on whether or not the
+        * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
+        * (return of 1), or may or may not be AGP (return of 2).
+        */
+       int (*device_is_agp) (struct drm_device *dev);
+
+       /* these have to be filled in */
+
+       irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
+       void (*irq_preinstall) (struct drm_device *dev);
+       void (*irq_postinstall) (struct drm_device *dev);
+       void (*irq_uninstall) (struct drm_device *dev);
+       void (*reclaim_buffers) (struct drm_device *dev,
+                                struct drm_file * file_priv);
+       void (*reclaim_buffers_locked) (struct drm_device *dev,
+                                       struct drm_file *file_priv);
+       void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
+                                           struct drm_file *file_priv);
+       unsigned long (*get_map_ofs) (struct drm_map * map);
+       unsigned long (*get_reg_ofs) (struct drm_device *dev);
+       void (*set_version) (struct drm_device *dev,
+                            struct drm_set_version *sv);
+
+       int major;
+       int minor;
+       int patchlevel;
+       char *name;
+       char *desc;
+       char *date;
+
+       u32 driver_features;
+       int dev_priv_size;
+       struct drm_ioctl_desc *ioctls;
+       int num_ioctls;
+       struct file_operations fops;
+       struct pci_driver pci_driver;
+};
+
+#define DRM_MINOR_UNASSIGNED 0
+#define DRM_MINOR_LEGACY 1
+
+/**
+ * DRM minor structure. This structure represents a drm minor number.
+ */
+struct drm_minor {
+       int index;                      /**< Minor device number */
+       int type;                       /**< Control or render */
+       dev_t device;                   /**< Device number for mknod */
+       struct device kdev;             /**< Linux device */
+       struct drm_device *dev;
+       struct proc_dir_entry *dev_root;  /**< proc directory entry */
+};
+
+/**
+ * DRM device structure. This structure represent a complete card that
+ * may contain multiple heads.
+ */
+struct drm_device {
+       char *unique;                   /**< Unique identifier: e.g., busid */
+       int unique_len;                 /**< Length of unique field */
+       char *devname;                  /**< For /proc/interrupts */
+       int if_version;                 /**< Highest interface version set */
+
+       int blocked;                    /**< Blocked due to VC switch? */
+
+       /** \name Locks */
+       /*@{ */
+       spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
+       struct mutex struct_mutex;      /**< For others */
+       /*@} */
+
+       /** \name Usage Counters */
+       /*@{ */
+       int open_count;                 /**< Outstanding files open */
+       atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
+       atomic_t vma_count;             /**< Outstanding vma areas open */
+       int buf_use;                    /**< Buffers in use -- cannot alloc */
+       atomic_t buf_alloc;             /**< Buffer allocation in progress */
+       /*@} */
+
+       /** \name Performance counters */
+       /*@{ */
+       unsigned long counters;
+       enum drm_stat_type types[15];
+       atomic_t counts[15];
+       /*@} */
+
+       /** \name Authentication */
+       /*@{ */
+       struct list_head filelist;
+       struct drm_open_hash magiclist; /**< magic hash table */
+       struct list_head magicfree;
+       /*@} */
+
+       /** \name Memory management */
+       /*@{ */
+       struct list_head maplist;       /**< Linked list of regions */
+       int map_count;                  /**< Number of mappable regions */
+       struct drm_open_hash map_hash;  /**< User token hash table for maps */
+
+       /** \name Context handle management */
+       /*@{ */
+       struct list_head ctxlist;       /**< Linked list of context handles */
+       int ctx_count;                  /**< Number of context handles */
+       struct mutex ctxlist_mutex;     /**< For ctxlist */
+
+       struct idr ctx_idr;
+
+       struct list_head vmalist;       /**< List of vmas (for debugging) */
+       struct drm_lock_data lock;      /**< Information on hardware lock */
+       /*@} */
+
+       /** \name DMA queues (contexts) */
+       /*@{ */
+       int queue_count;                /**< Number of active DMA queues */
+       int queue_reserved;               /**< Number of reserved DMA queues */
+       int queue_slots;                /**< Actual length of queuelist */
+       struct drm_queue **queuelist;   /**< Vector of pointers to DMA queues */
+       struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
+       /*@} */
+
+       /** \name Context support */
+       /*@{ */
+       int irq;                        /**< Interrupt used by board */
+       int irq_enabled;                /**< True if irq handler is enabled */
+       __volatile__ long context_flag; /**< Context swapping flag */
+       __volatile__ long interrupt_flag; /**< Interruption handler flag */
+       __volatile__ long dma_flag;     /**< DMA dispatch flag */
+       struct timer_list timer;        /**< Timer for delaying ctx switch */
+       wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
+       int last_checked;               /**< Last context checked for DMA */
+       int last_context;               /**< Last current context */
+       unsigned long last_switch;      /**< jiffies at last context switch */
+       /*@} */
+
+       struct work_struct work;
+       /** \name VBLANK IRQ support */
+       /*@{ */
+
+       wait_queue_head_t vbl_queue;    /**< VBLANK wait queue */
+       atomic_t vbl_received;
+       atomic_t vbl_received2;         /**< number of secondary VBLANK interrupts */
+       spinlock_t vbl_lock;
+       struct list_head vbl_sigs;              /**< signal list to send on VBLANK */
+       struct list_head vbl_sigs2;     /**< signals to send on secondary VBLANK */
+       unsigned int vbl_pending;
+       spinlock_t tasklet_lock;        /**< For drm_locked_tasklet */
+       void (*locked_tasklet_func)(struct drm_device *dev);
+
+       /*@} */
+       cycles_t ctx_start;
+       cycles_t lck_start;
+
+       struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
+       wait_queue_head_t buf_readers;  /**< Processes waiting to read */
+       wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
+
+       struct drm_agp_head *agp;       /**< AGP data */
+
+       struct pci_dev *pdev;           /**< PCI device structure */
+       int pci_vendor;                 /**< PCI vendor id */
+       int pci_device;                 /**< PCI device id */
+#ifdef __alpha__
+       struct pci_controller *hose;
+#endif
+       struct drm_sg_mem *sg;  /**< Scatter gather memory */
+       void *dev_private;              /**< device private data */
+       struct drm_sigdata sigdata;        /**< For block_all_signals */
+       sigset_t sigmask;
+
+       struct drm_driver *driver;
+       drm_local_map_t *agp_buffer_map;
+       unsigned int agp_buffer_token;
+       struct drm_minor *primary;              /**< render type primary screen head */
+
+       /** \name Drawable information */
+       /*@{ */
+       spinlock_t drw_lock;
+       struct idr drw_idr;
+       /*@} */
+};
+
+static __inline__ int drm_core_check_feature(struct drm_device *dev,
+                                            int feature)
+{
+       return ((dev->driver->driver_features & feature) ? 1 : 0);
+}
+
+#ifdef __alpha__
+#define drm_get_pci_domain(dev) dev->hose->index
+#else
+#define drm_get_pci_domain(dev) 0
+#endif
+
+#if __OS_HAS_AGP
+static inline int drm_core_has_AGP(struct drm_device *dev)
+{
+       return drm_core_check_feature(dev, DRIVER_USE_AGP);
+}
+#else
+#define drm_core_has_AGP(dev) (0)
+#endif
+
+#if __OS_HAS_MTRR
+static inline int drm_core_has_MTRR(struct drm_device *dev)
+{
+       return drm_core_check_feature(dev, DRIVER_USE_MTRR);
+}
+
+#define DRM_MTRR_WC            MTRR_TYPE_WRCOMB
+
+static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
+                              unsigned int flags)
+{
+       return mtrr_add(offset, size, flags, 1);
+}
+
+static inline int drm_mtrr_del(int handle, unsigned long offset,
+                              unsigned long size, unsigned int flags)
+{
+       return mtrr_del(handle, offset, size);
+}
+
+#else
+#define drm_core_has_MTRR(dev) (0)
+
+#define DRM_MTRR_WC            0
+
+static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
+                              unsigned int flags)
+{
+       return 0;
+}
+
+static inline int drm_mtrr_del(int handle, unsigned long offset,
+                              unsigned long size, unsigned int flags)
+{
+       return 0;
+}
+#endif
+
+/******************************************************************/
+/** \name Internal function definitions */
+/*@{*/
+
+                               /* Driver support (drm_drv.h) */
+extern int drm_init(struct drm_driver *driver);
+extern void drm_exit(struct drm_driver *driver);
+extern int drm_ioctl(struct inode *inode, struct file *filp,
+                    unsigned int cmd, unsigned long arg);
+extern long drm_compat_ioctl(struct file *filp,
+                            unsigned int cmd, unsigned long arg);
+extern int drm_lastclose(struct drm_device *dev);
+
+                               /* Device support (drm_fops.h) */
+extern int drm_open(struct inode *inode, struct file *filp);
+extern int drm_stub_open(struct inode *inode, struct file *filp);
+extern int drm_fasync(int fd, struct file *filp, int on);
+extern int drm_release(struct inode *inode, struct file *filp);
+
+                               /* Mapping support (drm_vm.h) */
+extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
+extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
+extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
+extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
+
+                               /* Memory management support (drm_memory.h) */
+#include "drm_memory.h"
+extern void drm_mem_init(void);
+extern int drm_mem_info(char *buf, char **start, off_t offset,
+                       int request, int *eof, void *data);
+extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
+
+extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
+extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
+extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
+extern int drm_unbind_agp(DRM_AGP_MEM * handle);
+
+                               /* Misc. IOCTL support (drm_ioctl.h) */
+extern int drm_irq_by_busid(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv);
+extern int drm_getunique(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int drm_setunique(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int drm_getmap(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_getclient(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int drm_getstats(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_setversion(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv);
+extern int drm_noop(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+
+                               /* Context IOCTL support (drm_context.h) */
+extern int drm_resctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_addctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_modctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_getctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_switchctx(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int drm_newctx(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_rmctx(struct drm_device *dev, void *data,
+                    struct drm_file *file_priv);
+
+extern int drm_ctxbitmap_init(struct drm_device *dev);
+extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
+extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
+
+extern int drm_setsareactx(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+extern int drm_getsareactx(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+
+                               /* Drawable IOCTL support (drm_drawable.h) */
+extern int drm_adddraw(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+extern int drm_rmdraw(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_update_drawable_info(struct drm_device *dev, void *data,
+                                   struct drm_file *file_priv);
+extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
+                                                 drm_drawable_t id);
+extern void drm_drawable_free_all(struct drm_device *dev);
+
+                               /* Authentication IOCTL support (drm_auth.h) */
+extern int drm_getmagic(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_authmagic(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+
+                               /* Locking IOCTL support (drm_lock.h) */
+extern int drm_lock(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv);
+extern int drm_unlock(struct drm_device *dev, void *data,
+                     struct drm_file *file_priv);
+extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
+extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
+extern void drm_idlelock_take(struct drm_lock_data *lock_data);
+extern void drm_idlelock_release(struct drm_lock_data *lock_data);
+
+/*
+ * These are exported to drivers so that they can implement fencing using
+ * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
+ */
+
+extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
+
+                               /* Buffer management support (drm_bufs.h) */
+extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
+extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
+extern int drm_addmap(struct drm_device *dev, unsigned int offset,
+                     unsigned int size, enum drm_map_type type,
+                     enum drm_map_flags flags, drm_local_map_t ** map_ptr);
+extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
+                           struct drm_file *file_priv);
+extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
+extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
+extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+extern int drm_addbufs(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+extern int drm_infobufs(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_markbufs(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_freebufs(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_mapbufs(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+extern int drm_order(unsigned long size);
+extern unsigned long drm_get_resource_start(struct drm_device *dev,
+                                           unsigned int resource);
+extern unsigned long drm_get_resource_len(struct drm_device *dev,
+                                         unsigned int resource);
+
+                               /* DMA support (drm_dma.h) */
+extern int drm_dma_setup(struct drm_device *dev);
+extern void drm_dma_takedown(struct drm_device *dev);
+extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
+extern void drm_core_reclaim_buffers(struct drm_device *dev,
+                                    struct drm_file *filp);
+
+                               /* IRQ support (drm_irq.h) */
+extern int drm_control(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
+extern int drm_irq_uninstall(struct drm_device *dev);
+extern void drm_driver_irq_preinstall(struct drm_device *dev);
+extern void drm_driver_irq_postinstall(struct drm_device *dev);
+extern void drm_driver_irq_uninstall(struct drm_device *dev);
+
+extern int drm_wait_vblank(struct drm_device *dev, void *data,
+                          struct drm_file *file_priv);
+extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
+extern void drm_vbl_send_signals(struct drm_device *dev);
+extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
+
+                               /* AGP/GART support (drm_agpsupport.h) */
+extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
+extern int drm_agp_acquire(struct drm_device *dev);
+extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
+                                struct drm_file *file_priv);
+extern int drm_agp_release(struct drm_device *dev);
+extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
+                                struct drm_file *file_priv);
+extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
+extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
+                               struct drm_file *file_priv);
+extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
+extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
+extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_priv);
+extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
+extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
+extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
+                         struct drm_file *file_priv);
+extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
+extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
+extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
+extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
+extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
+
+                               /* Stub support (drm_stub.h) */
+extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
+                      struct drm_driver *driver);
+extern int drm_put_dev(struct drm_device *dev);
+extern int drm_put_minor(struct drm_minor **minor);
+extern unsigned int drm_debug;
+
+extern struct class *drm_class;
+extern struct proc_dir_entry *drm_proc_root;
+
+extern struct idr drm_minors_idr;
+
+extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
+
+                               /* Proc support (drm_proc.h) */
+extern int drm_proc_init(struct drm_minor *minor, int minor_id,
+                        struct proc_dir_entry *root);
+extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
+
+                               /* Scatter Gather Support (drm_scatter.h) */
+extern void drm_sg_cleanup(struct drm_sg_mem * entry);
+extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
+                       struct drm_file *file_priv);
+extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
+extern int drm_sg_free(struct drm_device *dev, void *data,
+                      struct drm_file *file_priv);
+
+                              /* ATI PCIGART support (ati_pcigart.h) */
+extern int drm_ati_pcigart_init(struct drm_device *dev,
+                               struct drm_ati_pcigart_info * gart_info);
+extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
+                                  struct drm_ati_pcigart_info * gart_info);
+
+extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
+                                      size_t align, dma_addr_t maxaddr);
+extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
+extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
+
+                              /* sysfs support (drm_sysfs.c) */
+struct drm_sysfs_class;
+extern struct class *drm_sysfs_create(struct module *owner, char *name);
+extern void drm_sysfs_destroy(void);
+extern int drm_sysfs_device_add(struct drm_minor *minor);
+extern void drm_sysfs_device_remove(struct drm_minor *minor);
+
+/*
+ * Basic memory manager support (drm_mm.c)
+ */
+extern struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
+                                      unsigned long size,
+                                      unsigned alignment);
+extern void drm_mm_put_block(struct drm_mm_node * cur);
+extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
+                                        unsigned alignment, int best_match);
+extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
+extern void drm_mm_takedown(struct drm_mm *mm);
+extern int drm_mm_clean(struct drm_mm *mm);
+extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
+extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
+extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
+
+extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
+extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
+
+static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
+                                                  unsigned int token)
+{
+       struct drm_map_list *_entry;
+       list_for_each_entry(_entry, &dev->maplist, head)
+           if (_entry->user_token == token)
+               return _entry->map;
+       return NULL;
+}
+
+static __inline__ int drm_device_is_agp(struct drm_device *dev)
+{
+       if (dev->driver->device_is_agp != NULL) {
+               int err = (*dev->driver->device_is_agp) (dev);
+
+               if (err != 2) {
+                       return err;
+               }
+       }
+
+       return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
+}
+
+static __inline__ int drm_device_is_pcie(struct drm_device *dev)
+{
+       return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
+}
+
+static __inline__ void drm_core_dropmap(struct drm_map *map)
+{
+}
+
+#ifndef DEBUG_MEMORY
+/** Wrapper around kmalloc() */
+static __inline__ void *drm_alloc(size_t size, int area)
+{
+       return kmalloc(size, GFP_KERNEL);
+}
+
+/** Wrapper around kfree() */
+static __inline__ void drm_free(void *pt, size_t size, int area)
+{
+       kfree(pt);
+}
+
+/** Wrapper around kcalloc() */
+static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
+{
+       return kcalloc(nmemb, size, GFP_KERNEL);
+}
+#else
+extern void *drm_alloc(size_t size, int area);
+extern void drm_free(void *pt, size_t size, int area);
+extern void *drm_calloc(size_t nmemb, size_t size, int area);
+#endif
+
+/*@}*/
+
+#endif                         /* __KERNEL__ */
+#endif
diff --git a/include/drm/drm_core.h b/include/drm/drm_core.h
new file mode 100644 (file)
index 0000000..3167390
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 Jon Smirl <jonsmirl@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#define CORE_AUTHOR            "Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl"
+
+#define CORE_NAME              "drm"
+#define CORE_DESC              "DRM shared core routines"
+#define CORE_DATE              "20060810"
+
+#define DRM_IF_MAJOR   1
+#define DRM_IF_MINOR   3
+
+#define CORE_MAJOR     1
+#define CORE_MINOR     1
+#define CORE_PATCHLEVEL 0
diff --git a/include/drm/drm_hashtab.h b/include/drm/drm_hashtab.h
new file mode 100644 (file)
index 0000000..cd2b189
--- /dev/null
@@ -0,0 +1,67 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ **************************************************************************/
+/*
+ * Simple open hash tab implementation.
+ *
+ * Authors:
+ * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#ifndef DRM_HASHTAB_H
+#define DRM_HASHTAB_H
+
+#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
+
+struct drm_hash_item {
+       struct hlist_node head;
+       unsigned long key;
+};
+
+struct drm_open_hash {
+       unsigned int size;
+       unsigned int order;
+       unsigned int fill;
+       struct hlist_head *table;
+       int use_vmalloc;
+};
+
+
+extern int drm_ht_create(struct drm_open_hash *ht, unsigned int order);
+extern int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
+extern int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
+                                    unsigned long seed, int bits, int shift,
+                                    unsigned long add);
+extern int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
+
+extern void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
+extern int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
+extern int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
+extern void drm_ht_remove(struct drm_open_hash *ht);
+
+
+#endif
diff --git a/include/drm/drm_memory.h b/include/drm/drm_memory.h
new file mode 100644 (file)
index 0000000..63e425b
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * \file drm_memory.h
+ * Memory management wrappers for DRM
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+#include "drmP.h"
+
+/**
+ * Cut down version of drm_memory_debug.h, which used to be called
+ * drm_memory.h.
+ */
+
+#if __OS_HAS_AGP
+
+#include <linux/vmalloc.h>
+
+#ifdef HAVE_PAGE_AGP
+#include <asm/agp.h>
+#else
+# ifdef __powerpc__
+#  define PAGE_AGP     __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
+# else
+#  define PAGE_AGP     PAGE_KERNEL
+# endif
+#endif
+
+#else                          /* __OS_HAS_AGP */
+
+#endif
diff --git a/include/drm/drm_memory_debug.h b/include/drm/drm_memory_debug.h
new file mode 100644 (file)
index 0000000..6463271
--- /dev/null
@@ -0,0 +1,309 @@
+/**
+ * \file drm_memory_debug.h
+ * Memory management wrappers for DRM.
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+
+typedef struct drm_mem_stats {
+       const char *name;
+       int succeed_count;
+       int free_count;
+       int fail_count;
+       unsigned long bytes_allocated;
+       unsigned long bytes_freed;
+} drm_mem_stats_t;
+
+static DEFINE_SPINLOCK(drm_mem_lock);
+static unsigned long drm_ram_available = 0;    /* In pages */
+static unsigned long drm_ram_used = 0;
+static drm_mem_stats_t drm_mem_stats[] =
+{
+       [DRM_MEM_DMA] = {"dmabufs"},
+       [DRM_MEM_SAREA] = {"sareas"},
+       [DRM_MEM_DRIVER] = {"driver"},
+       [DRM_MEM_MAGIC] = {"magic"},
+       [DRM_MEM_IOCTLS] = {"ioctltab"},
+       [DRM_MEM_MAPS] = {"maplist"},
+       [DRM_MEM_VMAS] = {"vmalist"},
+       [DRM_MEM_BUFS] = {"buflist"},
+       [DRM_MEM_SEGS] = {"seglist"},
+       [DRM_MEM_PAGES] = {"pagelist"},
+       [DRM_MEM_FILES] = {"files"},
+       [DRM_MEM_QUEUES] = {"queues"},
+       [DRM_MEM_CMDS] = {"commands"},
+       [DRM_MEM_MAPPINGS] = {"mappings"},
+       [DRM_MEM_BUFLISTS] = {"buflists"},
+       [DRM_MEM_AGPLISTS] = {"agplist"},
+       [DRM_MEM_SGLISTS] = {"sglist"},
+       [DRM_MEM_TOTALAGP] = {"totalagp"},
+       [DRM_MEM_BOUNDAGP] = {"boundagp"},
+       [DRM_MEM_CTXBITMAP] = {"ctxbitmap"},
+       [DRM_MEM_CTXLIST] = {"ctxlist"},
+       [DRM_MEM_STUB] = {"stub"},
+       {NULL, 0,}              /* Last entry must be null */
+};
+
+void drm_mem_init (void) {
+       drm_mem_stats_t *mem;
+       struct sysinfo si;
+
+       for (mem = drm_mem_stats; mem->name; ++mem) {
+               mem->succeed_count = 0;
+               mem->free_count = 0;
+               mem->fail_count = 0;
+               mem->bytes_allocated = 0;
+               mem->bytes_freed = 0;
+       }
+
+       si_meminfo(&si);
+       drm_ram_available = si.totalram;
+       drm_ram_used = 0;
+}
+
+/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
+
+static int drm__mem_info (char *buf, char **start, off_t offset,
+                          int request, int *eof, void *data) {
+       drm_mem_stats_t *pt;
+       int len = 0;
+
+       if (offset > DRM_PROC_LIMIT) {
+               *eof = 1;
+               return 0;
+       }
+
+       *eof = 0;
+       *start = &buf[offset];
+
+       DRM_PROC_PRINT("                  total counts                  "
+                      " |    outstanding  \n");
+       DRM_PROC_PRINT("type       alloc freed fail     bytes      freed"
+                      " | allocs      bytes\n\n");
+       DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB         |\n",
+                      "system", 0, 0, 0,
+                      drm_ram_available << (PAGE_SHIFT - 10));
+       DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu kB         |\n",
+                      "locked", 0, 0, 0, drm_ram_used >> 10);
+       DRM_PROC_PRINT("\n");
+       for (pt = drm_mem_stats; pt->name; pt++) {
+               DRM_PROC_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
+                              pt->name,
+                              pt->succeed_count,
+                              pt->free_count,
+                              pt->fail_count,
+                              pt->bytes_allocated,
+                              pt->bytes_freed,
+                              pt->succeed_count - pt->free_count,
+                              (long)pt->bytes_allocated
+                              - (long)pt->bytes_freed);
+       }
+
+       if (len > request + offset)
+               return request;
+       *eof = 1;
+       return len - offset;
+}
+
+int drm_mem_info (char *buf, char **start, off_t offset,
+                  int len, int *eof, void *data) {
+       int ret;
+
+       spin_lock(&drm_mem_lock);
+       ret = drm__mem_info (buf, start, offset, len, eof, data);
+       spin_unlock(&drm_mem_lock);
+       return ret;
+}
+
+void *drm_alloc (size_t size, int area) {
+       void *pt;
+
+       if (!size) {
+               DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
+               return NULL;
+       }
+
+       if (!(pt = kmalloc(size, GFP_KERNEL))) {
+               spin_lock(&drm_mem_lock);
+               ++drm_mem_stats[area].fail_count;
+               spin_unlock(&drm_mem_lock);
+               return NULL;
+       }
+       spin_lock(&drm_mem_lock);
+       ++drm_mem_stats[area].succeed_count;
+       drm_mem_stats[area].bytes_allocated += size;
+       spin_unlock(&drm_mem_lock);
+       return pt;
+}
+
+void *drm_calloc (size_t nmemb, size_t size, int area) {
+       void *addr;
+
+       addr = drm_alloc (nmemb * size, area);
+       if (addr != NULL)
+               memset((void *)addr, 0, size * nmemb);
+
+       return addr;
+}
+
+void *drm_realloc (void *oldpt, size_t oldsize, size_t size, int area) {
+       void *pt;
+
+       if (!(pt = drm_alloc (size, area)))
+               return NULL;
+       if (oldpt && oldsize) {
+               memcpy(pt, oldpt, oldsize);
+               drm_free (oldpt, oldsize, area);
+       }
+       return pt;
+}
+
+void drm_free (void *pt, size_t size, int area) {
+       int alloc_count;
+       int free_count;
+
+       if (!pt)
+               DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
+       else
+               kfree(pt);
+       spin_lock(&drm_mem_lock);
+       drm_mem_stats[area].bytes_freed += size;
+       free_count = ++drm_mem_stats[area].free_count;
+       alloc_count = drm_mem_stats[area].succeed_count;
+       spin_unlock(&drm_mem_lock);
+       if (free_count > alloc_count) {
+               DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
+                             free_count, alloc_count);
+       }
+}
+
+#if __OS_HAS_AGP
+
+DRM_AGP_MEM *drm_alloc_agp (drm_device_t *dev, int pages, u32 type) {
+       DRM_AGP_MEM *handle;
+
+       if (!pages) {
+               DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
+               return NULL;
+       }
+
+       if ((handle = drm_agp_allocate_memory (pages, type))) {
+               spin_lock(&drm_mem_lock);
+               ++drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
+               drm_mem_stats[DRM_MEM_TOTALAGP].bytes_allocated
+                   += pages << PAGE_SHIFT;
+               spin_unlock(&drm_mem_lock);
+               return handle;
+       }
+       spin_lock(&drm_mem_lock);
+       ++drm_mem_stats[DRM_MEM_TOTALAGP].fail_count;
+       spin_unlock(&drm_mem_lock);
+       return NULL;
+}
+
+int drm_free_agp (DRM_AGP_MEM * handle, int pages) {
+       int alloc_count;
+       int free_count;
+       int retval = -EINVAL;
+
+       if (!handle) {
+               DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
+                             "Attempt to free NULL AGP handle\n");
+               return retval;
+       }
+
+       if (drm_agp_free_memory (handle)) {
+               spin_lock(&drm_mem_lock);
+               free_count = ++drm_mem_stats[DRM_MEM_TOTALAGP].free_count;
+               alloc_count = drm_mem_stats[DRM_MEM_TOTALAGP].succeed_count;
+               drm_mem_stats[DRM_MEM_TOTALAGP].bytes_freed
+                   += pages << PAGE_SHIFT;
+               spin_unlock(&drm_mem_lock);
+               if (free_count > alloc_count) {
+                       DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
+                                     "Excess frees: %d frees, %d allocs\n",
+                                     free_count, alloc_count);
+               }
+               return 0;
+       }
+       return retval;
+}
+
+int drm_bind_agp (DRM_AGP_MEM * handle, unsigned int start) {
+       int retcode = -EINVAL;
+
+       if (!handle) {
+               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+                             "Attempt to bind NULL AGP handle\n");
+               return retcode;
+       }
+
+       if (!(retcode = drm_agp_bind_memory (handle, start))) {
+               spin_lock(&drm_mem_lock);
+               ++drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
+               drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_allocated
+                   += handle->page_count << PAGE_SHIFT;
+               spin_unlock(&drm_mem_lock);
+               return retcode;
+       }
+       spin_lock(&drm_mem_lock);
+       ++drm_mem_stats[DRM_MEM_BOUNDAGP].fail_count;
+       spin_unlock(&drm_mem_lock);
+       return retcode;
+}
+
+int drm_unbind_agp (DRM_AGP_MEM * handle) {
+       int alloc_count;
+       int free_count;
+       int retcode = -EINVAL;
+
+       if (!handle) {
+               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+                             "Attempt to unbind NULL AGP handle\n");
+               return retcode;
+       }
+
+       if ((retcode = drm_agp_unbind_memory (handle)))
+               return retcode;
+       spin_lock(&drm_mem_lock);
+       free_count = ++drm_mem_stats[DRM_MEM_BOUNDAGP].free_count;
+       alloc_count = drm_mem_stats[DRM_MEM_BOUNDAGP].succeed_count;
+       drm_mem_stats[DRM_MEM_BOUNDAGP].bytes_freed
+           += handle->page_count << PAGE_SHIFT;
+       spin_unlock(&drm_mem_lock);
+       if (free_count > alloc_count) {
+               DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+                             "Excess frees: %d frees, %d allocs\n",
+                             free_count, alloc_count);
+       }
+       return retcode;
+}
+#endif
diff --git a/include/drm/drm_os_linux.h b/include/drm/drm_os_linux.h
new file mode 100644 (file)
index 0000000..8dbd257
--- /dev/null
@@ -0,0 +1,108 @@
+/**
+ * \file drm_os_linux.h
+ * OS abstraction macros.
+ */
+
+#include <linux/interrupt.h>   /* For task queue support */
+#include <linux/delay.h>
+
+/** Current process ID */
+#define DRM_CURRENTPID                 task_pid_nr(current)
+#define DRM_SUSER(p)                   capable(CAP_SYS_ADMIN)
+#define DRM_UDELAY(d)                  udelay(d)
+/** Read a byte from a MMIO region */
+#define DRM_READ8(map, offset)         readb(((void __iomem *)(map)->handle) + (offset))
+/** Read a word from a MMIO region */
+#define DRM_READ16(map, offset)         readw(((void __iomem *)(map)->handle) + (offset))
+/** Read a dword from a MMIO region */
+#define DRM_READ32(map, offset)                readl(((void __iomem *)(map)->handle) + (offset))
+/** Write a byte into a MMIO region */
+#define DRM_WRITE8(map, offset, val)   writeb(val, ((void __iomem *)(map)->handle) + (offset))
+/** Write a word into a MMIO region */
+#define DRM_WRITE16(map, offset, val)   writew(val, ((void __iomem *)(map)->handle) + (offset))
+/** Write a dword into a MMIO region */
+#define DRM_WRITE32(map, offset, val)  writel(val, ((void __iomem *)(map)->handle) + (offset))
+/** Read memory barrier */
+#define DRM_READMEMORYBARRIER()                rmb()
+/** Write memory barrier */
+#define DRM_WRITEMEMORYBARRIER()       wmb()
+/** Read/write memory barrier */
+#define DRM_MEMORYBARRIER()            mb()
+
+/** IRQ handler arguments and return type and values */
+#define DRM_IRQ_ARGS           int irq, void *arg
+
+/** AGP types */
+#if __OS_HAS_AGP
+#define DRM_AGP_MEM            struct agp_memory
+#define DRM_AGP_KERN           struct agp_kern_info
+#else
+/* define some dummy types for non AGP supporting kernels */
+struct no_agp_kern {
+       unsigned long aper_base;
+       unsigned long aper_size;
+};
+#define DRM_AGP_MEM             int
+#define DRM_AGP_KERN            struct no_agp_kern
+#endif
+
+#if !(__OS_HAS_MTRR)
+static __inline__ int mtrr_add(unsigned long base, unsigned long size,
+                              unsigned int type, char increment)
+{
+       return -ENODEV;
+}
+
+static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
+{
+       return -ENODEV;
+}
+
+#define MTRR_TYPE_WRCOMB     1
+
+#endif
+
+/** Other copying of data to kernel space */
+#define DRM_COPY_FROM_USER(arg1, arg2, arg3)           \
+       copy_from_user(arg1, arg2, arg3)
+/** Other copying of data from kernel space */
+#define DRM_COPY_TO_USER(arg1, arg2, arg3)             \
+       copy_to_user(arg1, arg2, arg3)
+/* Macros for copyfrom user, but checking readability only once */
+#define DRM_VERIFYAREA_READ( uaddr, size )             \
+       (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
+#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
+       __copy_from_user(arg1, arg2, arg3)
+#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)   \
+       __copy_to_user(arg1, arg2, arg3)
+#define DRM_GET_USER_UNCHECKED(val, uaddr)             \
+       __get_user(val, uaddr)
+
+#define DRM_HZ HZ
+
+#define DRM_WAIT_ON( ret, queue, timeout, condition )          \
+do {                                                           \
+       DECLARE_WAITQUEUE(entry, current);                      \
+       unsigned long end = jiffies + (timeout);                \
+       add_wait_queue(&(queue), &entry);                       \
+                                                               \
+       for (;;) {                                              \
+               __set_current_state(TASK_INTERRUPTIBLE);        \
+               if (condition)                                  \
+                       break;                                  \
+               if (time_after_eq(jiffies, end)) {              \
+                       ret = -EBUSY;                           \
+                       break;                                  \
+               }                                               \
+               schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
+               if (signal_pending(current)) {                  \
+                       ret = -EINTR;                           \
+                       break;                                  \
+               }                                               \
+       }                                                       \
+       __set_current_state(TASK_RUNNING);                      \
+       remove_wait_queue(&(queue), &entry);                    \
+} while (0)
+
+#define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
+#define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )
diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h
new file mode 100644 (file)
index 0000000..135bd19
--- /dev/null
@@ -0,0 +1,415 @@
+/*
+   This file is auto-generated from the drm_pciids.txt in the DRM CVS
+   Please contact dri-devel@lists.sf.net to add new cards to this list
+*/
+#define radeon_PCI_IDS \
+       {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \
+       {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
+       {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x414A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x414B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
+       {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP}, \
+       {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
+       {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
+       {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
+       {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
+       {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4E47, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
+       {0x1002, 0x4E48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
+       {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
+       {0x1002, 0x5145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
+       {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
+       {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|RADEON_SINGLE_CRTC}, \
+       {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
+       {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
+       {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
+       {0x1002, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
+       {0x1002, 0x5158, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
+       {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
+       {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
+       {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
+       {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5657, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \
+       {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5954, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5955, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5974, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5975, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
+       {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
+       {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
+       {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
+       {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
+       {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
+       {0x1002, 0x5a61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5a62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS480|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
+       {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|RADEON_IS_MOBILITY}, \
+       {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x710A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x710B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x710C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x710E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x710F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7143, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x714F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x715E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x715F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7181, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7183, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7186, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7187, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7188, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x718A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x718B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x718C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x718D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x718F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7193, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7196, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x719B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x719F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71C7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71CD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71CE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71D2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71D4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71D5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71D6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x71DE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV530|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7210, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV515|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7244, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7245, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7247, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7248, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7249, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x724F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7280, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7281, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7283, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7284, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R580|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7287, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7289, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x728B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x728C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV570|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7290, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7291, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7293, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7297, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV560|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
+       {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
+       {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
+       {0, 0, 0}
+
+#define r128_PCI_IDS \
+       {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4d46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5041, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5043, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5044, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5045, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5046, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5047, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5048, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5049, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x504F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5054, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5245, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5247, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x524b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x524c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x534d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define mga_PCI_IDS \
+       {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
+       {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
+       {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
+       {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
+       {0, 0, 0}
+
+#define mach64_PCI_IDS \
+       {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4750, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4751, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4742, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4744, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c42, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x474c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x474f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4752, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4753, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x474d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x474e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define sisdrv_PCI_IDS \
+       {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1039, 0x5300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1039, 0x6300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1039, 0x6330, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
+       {0x1039, 0x6351, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
+       {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
+       {0, 0, 0}
+
+#define tdfx_PCI_IDS \
+       {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x121a, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x121a, 0x0005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define viadrv_PCI_IDS \
+       {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x3118, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
+       {0x1106, 0x3122, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x7205, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x3108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x3344, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
+       {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
+       {0, 0, 0}
+
+#define i810_PCI_IDS \
+       {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define i830_PCI_IDS \
+       {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define gamma_PCI_IDS \
+       {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
+
+#define savage_PCI_IDS \
+       {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
+       {0x5333, 0x8a21, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
+       {0x5333, 0x8a22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE4}, \
+       {0x5333, 0x8a23, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE4}, \
+       {0x5333, 0x8c10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
+       {0x5333, 0x8c11, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
+       {0x5333, 0x8c12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
+       {0x5333, 0x8c13, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE_MX}, \
+       {0x5333, 0x8c22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c24, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8c2f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SUPERSAVAGE}, \
+       {0x5333, 0x8a25, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGE}, \
+       {0x5333, 0x8a26, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGE}, \
+       {0x5333, 0x8d01, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
+       {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
+       {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
+       {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
+       {0, 0, 0}
+
+#define ffb_PCI_IDS \
+       {0, 0, 0}
+
+#define i915_PCI_IDS \
+       {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x258a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x27a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x27ae, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2972, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2982, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2992, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x29a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x29b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x29c2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x29d2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2a02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2a12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2a42, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
+       {0, 0, 0}
diff --git a/include/drm/drm_sarea.h b/include/drm/drm_sarea.h
new file mode 100644 (file)
index 0000000..4800373
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+ * \file drm_sarea.h
+ * \brief SAREA definitions
+ *
+ * \author Michel Dänzer <michel@daenzer.net>
+ */
+
+/*
+ * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DRM_SAREA_H_
+#define _DRM_SAREA_H_
+
+#include "drm.h"
+
+/* SAREA area needs to be at least a page */
+#if defined(__alpha__)
+#define SAREA_MAX                       0x2000
+#elif defined(__ia64__)
+#define SAREA_MAX                       0x10000        /* 64kB */
+#else
+/* Intel 830M driver needs at least 8k SAREA */
+#define SAREA_MAX                       0x2000
+#endif
+
+/** Maximum number of drawables in the SAREA */
+#define SAREA_MAX_DRAWABLES            256
+
+#define SAREA_DRAWABLE_CLAIMED_ENTRY    0x80000000
+
+/** SAREA drawable */
+struct drm_sarea_drawable {
+       unsigned int stamp;
+       unsigned int flags;
+};
+
+/** SAREA frame */
+struct drm_sarea_frame {
+       unsigned int x;
+       unsigned int y;
+       unsigned int width;
+       unsigned int height;
+       unsigned int fullscreen;
+};
+
+/** SAREA */
+struct drm_sarea {
+    /** first thing is always the DRM locking structure */
+       struct drm_hw_lock lock;
+    /** \todo Use readers/writer lock for drm_sarea::drawable_lock */
+       struct drm_hw_lock drawable_lock;
+       struct drm_sarea_drawable drawableTable[SAREA_MAX_DRAWABLES];   /**< drawables */
+       struct drm_sarea_frame frame;   /**< frame */
+       drm_context_t dummy_context;
+};
+
+#ifndef __KERNEL__
+typedef struct drm_sarea_drawable drm_sarea_drawable_t;
+typedef struct drm_sarea_frame drm_sarea_frame_t;
+typedef struct drm_sarea drm_sarea_t;
+#endif
+
+#endif                         /* _DRM_SAREA_H_ */
diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h
new file mode 100644 (file)
index 0000000..08ecf83
--- /dev/null
@@ -0,0 +1,176 @@
+/**************************************************************************
+ *
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ **************************************************************************/
+/*
+ * Simple memory MANager interface that keeps track on allocate regions on a
+ * per "owner" basis. All regions associated with an "owner" can be released
+ * with a simple call. Typically if the "owner" exists. The owner is any
+ * "unsigned long" identifier. Can typically be a pointer to a file private
+ * struct or a context identifier.
+ *
+ * Authors:
+ * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
+ */
+
+#ifndef DRM_SMAN_H
+#define DRM_SMAN_H
+
+#include "drmP.h"
+#include "drm_hashtab.h"
+
+/*
+ * A class that is an abstration of a simple memory allocator.
+ * The sman implementation provides a default such allocator
+ * using the drm_mm.c implementation. But the user can replace it.
+ * See the SiS implementation, which may use the SiS FB kernel module
+ * for memory management.
+ */
+
+struct drm_sman_mm {
+       /* private info. If allocated, needs to be destroyed by the destroy
+          function */
+       void *private;
+
+       /* Allocate a memory block with given size and alignment.
+          Return an opaque reference to the memory block */
+
+       void *(*allocate) (void *private, unsigned long size,
+                          unsigned alignment);
+
+       /* Free a memory block. "ref" is the opaque reference that we got from
+          the "alloc" function */
+
+       void (*free) (void *private, void *ref);
+
+       /* Free all resources associated with this allocator */
+
+       void (*destroy) (void *private);
+
+       /* Return a memory offset from the opaque reference returned from the
+          "alloc" function */
+
+       unsigned long (*offset) (void *private, void *ref);
+};
+
+struct drm_memblock_item {
+       struct list_head owner_list;
+       struct drm_hash_item user_hash;
+       void *mm_info;
+       struct drm_sman_mm *mm;
+       struct drm_sman *sman;
+};
+
+struct drm_sman {
+       struct drm_sman_mm *mm;
+       int num_managers;
+       struct drm_open_hash owner_hash_tab;
+       struct drm_open_hash user_hash_tab;
+       struct list_head owner_items;
+};
+
+/*
+ * Take down a memory manager. This function should only be called after a
+ * successful init and after a call to drm_sman_cleanup.
+ */
+
+extern void drm_sman_takedown(struct drm_sman * sman);
+
+/*
+ * Allocate structures for a manager.
+ * num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
+ * user_order is the log2 of the number of buckets in the user hash table.
+ *         set this to approximately log2 of the max number of memory regions
+ *         that will be allocated for _all_ pools together.
+ * owner_order is the log2 of the number of buckets in the owner hash table.
+ *         set this to approximately log2 of
+ *         the number of client file connections that will
+ *         be using the manager.
+ *
+ */
+
+extern int drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
+                        unsigned int user_order, unsigned int owner_order);
+
+/*
+ * Initialize a drm_mm.c allocator. Should be called only once for each
+ * manager unless a customized allogator is used.
+ */
+
+extern int drm_sman_set_range(struct drm_sman * sman, unsigned int manager,
+                             unsigned long start, unsigned long size);
+
+/*
+ * Initialize a customized allocator for one of the managers.
+ * (See the SiS module). The object pointed to by "allocator" is copied,
+ * so it can be destroyed after this call.
+ */
+
+extern int drm_sman_set_manager(struct drm_sman * sman, unsigned int mananger,
+                               struct drm_sman_mm * allocator);
+
+/*
+ * Allocate a memory block. Aligment is not implemented yet.
+ */
+
+extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman,
+                                               unsigned int manager,
+                                               unsigned long size,
+                                               unsigned alignment,
+                                               unsigned long owner);
+/*
+ * Free a memory block identified by its user hash key.
+ */
+
+extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key);
+
+/*
+ * returns 1 iff there are no stale memory blocks associated with this owner.
+ * Typically called to determine if we need to idle the hardware and call
+ * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all
+ * resources associated with owner.
+ */
+
+extern int drm_sman_owner_clean(struct drm_sman * sman, unsigned long owner);
+
+/*
+ * Frees all stale memory blocks associated with this owner. Note that this
+ * requires that the hardware is finished with all blocks, so the graphics engine
+ * should be idled before this call is made. This function also frees
+ * any resources associated with "owner" and should be called when owner
+ * is not going to be referenced anymore.
+ */
+
+extern void drm_sman_owner_cleanup(struct drm_sman * sman, unsigned long owner);
+
+/*
+ * Frees all stale memory blocks associated with the memory manager.
+ * See idling above.
+ */
+
+extern void drm_sman_cleanup(struct drm_sman * sman);
+
+#endif
diff --git a/include/drm/i810_drm.h b/include/drm/i810_drm.h
new file mode 100644 (file)
index 0000000..7a10bb6
--- /dev/null
@@ -0,0 +1,281 @@
+#ifndef _I810_DRM_H_
+#define _I810_DRM_H_
+
+/* WARNING: These defines must be the same as what the Xserver uses.
+ * if you change them, you must change the defines in the Xserver.
+ */
+
+#ifndef _I810_DEFINES_
+#define _I810_DEFINES_
+
+#define I810_DMA_BUF_ORDER             12
+#define I810_DMA_BUF_SZ                (1<<I810_DMA_BUF_ORDER)
+#define I810_DMA_BUF_NR                256
+#define I810_NR_SAREA_CLIPRECTS        8
+
+/* Each region is a minimum of 64k, and there are at most 64 of them.
+ */
+#define I810_NR_TEX_REGIONS 64
+#define I810_LOG_MIN_TEX_REGION_SIZE 16
+#endif
+
+#define I810_UPLOAD_TEX0IMAGE  0x1     /* handled clientside */
+#define I810_UPLOAD_TEX1IMAGE  0x2     /* handled clientside */
+#define I810_UPLOAD_CTX        0x4
+#define I810_UPLOAD_BUFFERS    0x8
+#define I810_UPLOAD_TEX0       0x10
+#define I810_UPLOAD_TEX1       0x20
+#define I810_UPLOAD_CLIPRECTS  0x40
+
+/* Indices into buf.Setup where various bits of state are mirrored per
+ * context and per buffer.  These can be fired at the card as a unit,
+ * or in a piecewise fashion as required.
+ */
+
+/* Destbuffer state
+ *    - backbuffer linear offset and pitch -- invarient in the current dri
+ *    - zbuffer linear offset and pitch -- also invarient
+ *    - drawing origin in back and depth buffers.
+ *
+ * Keep the depth/back buffer state here to accommodate private buffers
+ * in the future.
+ */
+#define I810_DESTREG_DI0  0    /* CMD_OP_DESTBUFFER_INFO (2 dwords) */
+#define I810_DESTREG_DI1  1
+#define I810_DESTREG_DV0  2    /* GFX_OP_DESTBUFFER_VARS (2 dwords) */
+#define I810_DESTREG_DV1  3
+#define I810_DESTREG_DR0  4    /* GFX_OP_DRAWRECT_INFO (4 dwords) */
+#define I810_DESTREG_DR1  5
+#define I810_DESTREG_DR2  6
+#define I810_DESTREG_DR3  7
+#define I810_DESTREG_DR4  8
+#define I810_DEST_SETUP_SIZE 10
+
+/* Context state
+ */
+#define I810_CTXREG_CF0   0    /* GFX_OP_COLOR_FACTOR */
+#define I810_CTXREG_CF1   1
+#define I810_CTXREG_ST0   2    /* GFX_OP_STIPPLE */
+#define I810_CTXREG_ST1   3
+#define I810_CTXREG_VF    4    /* GFX_OP_VERTEX_FMT */
+#define I810_CTXREG_MT    5    /* GFX_OP_MAP_TEXELS */
+#define I810_CTXREG_MC0   6    /* GFX_OP_MAP_COLOR_STAGES - stage 0 */
+#define I810_CTXREG_MC1   7    /* GFX_OP_MAP_COLOR_STAGES - stage 1 */
+#define I810_CTXREG_MC2   8    /* GFX_OP_MAP_COLOR_STAGES - stage 2 */
+#define I810_CTXREG_MA0   9    /* GFX_OP_MAP_ALPHA_STAGES - stage 0 */
+#define I810_CTXREG_MA1   10   /* GFX_OP_MAP_ALPHA_STAGES - stage 1 */
+#define I810_CTXREG_MA2   11   /* GFX_OP_MAP_ALPHA_STAGES - stage 2 */
+#define I810_CTXREG_SDM   12   /* GFX_OP_SRC_DEST_MONO */
+#define I810_CTXREG_FOG   13   /* GFX_OP_FOG_COLOR */
+#define I810_CTXREG_B1    14   /* GFX_OP_BOOL_1 */
+#define I810_CTXREG_B2    15   /* GFX_OP_BOOL_2 */
+#define I810_CTXREG_LCS   16   /* GFX_OP_LINEWIDTH_CULL_SHADE_MODE */
+#define I810_CTXREG_PV    17   /* GFX_OP_PV_RULE -- Invarient! */
+#define I810_CTXREG_ZA    18   /* GFX_OP_ZBIAS_ALPHAFUNC */
+#define I810_CTXREG_AA    19   /* GFX_OP_ANTIALIAS */
+#define I810_CTX_SETUP_SIZE 20
+
+/* Texture state (per tex unit)
+ */
+#define I810_TEXREG_MI0  0     /* GFX_OP_MAP_INFO (4 dwords) */
+#define I810_TEXREG_MI1  1
+#define I810_TEXREG_MI2  2
+#define I810_TEXREG_MI3  3
+#define I810_TEXREG_MF   4     /* GFX_OP_MAP_FILTER */
+#define I810_TEXREG_MLC  5     /* GFX_OP_MAP_LOD_CTL */
+#define I810_TEXREG_MLL  6     /* GFX_OP_MAP_LOD_LIMITS */
+#define I810_TEXREG_MCS  7     /* GFX_OP_MAP_COORD_SETS ??? */
+#define I810_TEX_SETUP_SIZE 8
+
+/* Flags for clear ioctl
+ */
+#define I810_FRONT   0x1
+#define I810_BACK    0x2
+#define I810_DEPTH   0x4
+
+typedef enum _drm_i810_init_func {
+       I810_INIT_DMA = 0x01,
+       I810_CLEANUP_DMA = 0x02,
+       I810_INIT_DMA_1_4 = 0x03
+} drm_i810_init_func_t;
+
+/* This is the init structure after v1.2 */
+typedef struct _drm_i810_init {
+       drm_i810_init_func_t func;
+       unsigned int mmio_offset;
+       unsigned int buffers_offset;
+       int sarea_priv_offset;
+       unsigned int ring_start;
+       unsigned int ring_end;
+       unsigned int ring_size;
+       unsigned int front_offset;
+       unsigned int back_offset;
+       unsigned int depth_offset;
+       unsigned int overlay_offset;
+       unsigned int overlay_physical;
+       unsigned int w;
+       unsigned int h;
+       unsigned int pitch;
+       unsigned int pitch_bits;
+} drm_i810_init_t;
+
+/* This is the init structure prior to v1.2 */
+typedef struct _drm_i810_pre12_init {
+       drm_i810_init_func_t func;
+       unsigned int mmio_offset;
+       unsigned int buffers_offset;
+       int sarea_priv_offset;
+       unsigned int ring_start;
+       unsigned int ring_end;
+       unsigned int ring_size;
+       unsigned int front_offset;
+       unsigned int back_offset;
+       unsigned int depth_offset;
+       unsigned int w;
+       unsigned int h;
+       unsigned int pitch;
+       unsigned int pitch_bits;
+} drm_i810_pre12_init_t;
+
+/* Warning: If you change the SAREA structure you must change the Xserver
+ * structure as well */
+
+typedef struct _drm_i810_tex_region {
+       unsigned char next, prev;       /* indices to form a circular LRU  */
+       unsigned char in_use;   /* owned by a client, or free? */
+       int age;                /* tracked by clients to update local LRU's */
+} drm_i810_tex_region_t;
+
+typedef struct _drm_i810_sarea {
+       unsigned int ContextState[I810_CTX_SETUP_SIZE];
+       unsigned int BufferState[I810_DEST_SETUP_SIZE];
+       unsigned int TexState[2][I810_TEX_SETUP_SIZE];
+       unsigned int dirty;
+
+       unsigned int nbox;
+       struct drm_clip_rect boxes[I810_NR_SAREA_CLIPRECTS];
+
+       /* Maintain an LRU of contiguous regions of texture space.  If
+        * you think you own a region of texture memory, and it has an
+        * age different to the one you set, then you are mistaken and
+        * it has been stolen by another client.  If global texAge
+        * hasn't changed, there is no need to walk the list.
+        *
+        * These regions can be used as a proxy for the fine-grained
+        * texture information of other clients - by maintaining them
+        * in the same lru which is used to age their own textures,
+        * clients have an approximate lru for the whole of global
+        * texture space, and can make informed decisions as to which
+        * areas to kick out.  There is no need to choose whether to
+        * kick out your own texture or someone else's - simply eject
+        * them all in LRU order.
+        */
+
+       drm_i810_tex_region_t texList[I810_NR_TEX_REGIONS + 1];
+       /* Last elt is sentinal */
+       int texAge;             /* last time texture was uploaded */
+       int last_enqueue;       /* last time a buffer was enqueued */
+       int last_dispatch;      /* age of the most recently dispatched buffer */
+       int last_quiescent;     /*  */
+       int ctxOwner;           /* last context to upload state */
+
+       int vertex_prim;
+
+       int pf_enabled;         /* is pageflipping allowed? */
+       int pf_active;
+       int pf_current_page;    /* which buffer is being displayed? */
+} drm_i810_sarea_t;
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the Xserver file (xf86drmMga.h)
+ */
+
+/* i810 specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_I810_INIT          0x00
+#define DRM_I810_VERTEX                0x01
+#define DRM_I810_CLEAR         0x02
+#define DRM_I810_FLUSH         0x03
+#define DRM_I810_GETAGE                0x04
+#define DRM_I810_GETBUF                0x05
+#define DRM_I810_SWAP          0x06
+#define DRM_I810_COPY          0x07
+#define DRM_I810_DOCOPY                0x08
+#define DRM_I810_OV0INFO       0x09
+#define DRM_I810_FSTATUS       0x0a
+#define DRM_I810_OV0FLIP       0x0b
+#define DRM_I810_MC            0x0c
+#define DRM_I810_RSTATUS       0x0d
+#define DRM_I810_FLIP          0x0e
+
+#define DRM_IOCTL_I810_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_I810_INIT, drm_i810_init_t)
+#define DRM_IOCTL_I810_VERTEX          DRM_IOW( DRM_COMMAND_BASE + DRM_I810_VERTEX, drm_i810_vertex_t)
+#define DRM_IOCTL_I810_CLEAR           DRM_IOW( DRM_COMMAND_BASE + DRM_I810_CLEAR, drm_i810_clear_t)
+#define DRM_IOCTL_I810_FLUSH           DRM_IO(  DRM_COMMAND_BASE + DRM_I810_FLUSH)
+#define DRM_IOCTL_I810_GETAGE          DRM_IO(  DRM_COMMAND_BASE + DRM_I810_GETAGE)
+#define DRM_IOCTL_I810_GETBUF          DRM_IOWR(DRM_COMMAND_BASE + DRM_I810_GETBUF, drm_i810_dma_t)
+#define DRM_IOCTL_I810_SWAP            DRM_IO(  DRM_COMMAND_BASE + DRM_I810_SWAP)
+#define DRM_IOCTL_I810_COPY            DRM_IOW( DRM_COMMAND_BASE + DRM_I810_COPY, drm_i810_copy_t)
+#define DRM_IOCTL_I810_DOCOPY          DRM_IO(  DRM_COMMAND_BASE + DRM_I810_DOCOPY)
+#define DRM_IOCTL_I810_OV0INFO         DRM_IOR( DRM_COMMAND_BASE + DRM_I810_OV0INFO, drm_i810_overlay_t)
+#define DRM_IOCTL_I810_FSTATUS         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FSTATUS)
+#define DRM_IOCTL_I810_OV0FLIP         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_OV0FLIP)
+#define DRM_IOCTL_I810_MC              DRM_IOW( DRM_COMMAND_BASE + DRM_I810_MC, drm_i810_mc_t)
+#define DRM_IOCTL_I810_RSTATUS         DRM_IO ( DRM_COMMAND_BASE + DRM_I810_RSTATUS)
+#define DRM_IOCTL_I810_FLIP             DRM_IO ( DRM_COMMAND_BASE + DRM_I810_FLIP)
+
+typedef struct _drm_i810_clear {
+       int clear_color;
+       int clear_depth;
+       int flags;
+} drm_i810_clear_t;
+
+/* These may be placeholders if we have more cliprects than
+ * I810_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
+ * false, indicating that the buffer will be dispatched again with a
+ * new set of cliprects.
+ */
+typedef struct _drm_i810_vertex {
+       int idx;                /* buffer index */
+       int used;               /* nr bytes in use */
+       int discard;            /* client is finished with the buffer? */
+} drm_i810_vertex_t;
+
+typedef struct _drm_i810_copy_t {
+       int idx;                /* buffer index */
+       int used;               /* nr bytes in use */
+       void *address;          /* Address to copy from */
+} drm_i810_copy_t;
+
+#define PR_TRIANGLES         (0x0<<18)
+#define PR_TRISTRIP_0        (0x1<<18)
+#define PR_TRISTRIP_1        (0x2<<18)
+#define PR_TRIFAN            (0x3<<18)
+#define PR_POLYGON           (0x4<<18)
+#define PR_LINES             (0x5<<18)
+#define PR_LINESTRIP         (0x6<<18)
+#define PR_RECTS             (0x7<<18)
+#define PR_MASK              (0x7<<18)
+
+typedef struct drm_i810_dma {
+       void *virtual;
+       int request_idx;
+       int request_size;
+       int granted;
+} drm_i810_dma_t;
+
+typedef struct _drm_i810_overlay_t {
+       unsigned int offset;    /* Address of the Overlay Regs */
+       unsigned int physical;
+} drm_i810_overlay_t;
+
+typedef struct _drm_i810_mc {
+       int idx;                /* buffer index */
+       int used;               /* nr bytes in use */
+       int num_blocks;         /* number of GFXBlocks */
+       int *length;            /* List of lengths for GFXBlocks (FUTURE) */
+       unsigned int last_render;       /* Last Render Request */
+} drm_i810_mc_t;
+
+#endif                         /* _I810_DRM_H_ */
diff --git a/include/drm/i830_drm.h b/include/drm/i830_drm.h
new file mode 100644 (file)
index 0000000..4b00d2d
--- /dev/null
@@ -0,0 +1,342 @@
+#ifndef _I830_DRM_H_
+#define _I830_DRM_H_
+
+/* WARNING: These defines must be the same as what the Xserver uses.
+ * if you change them, you must change the defines in the Xserver.
+ *
+ * KW: Actually, you can't ever change them because doing so would
+ * break backwards compatibility.
+ */
+
+#ifndef _I830_DEFINES_
+#define _I830_DEFINES_
+
+#define I830_DMA_BUF_ORDER             12
+#define I830_DMA_BUF_SZ                        (1<<I830_DMA_BUF_ORDER)
+#define I830_DMA_BUF_NR                        256
+#define I830_NR_SAREA_CLIPRECTS                8
+
+/* Each region is a minimum of 64k, and there are at most 64 of them.
+ */
+#define I830_NR_TEX_REGIONS 64
+#define I830_LOG_MIN_TEX_REGION_SIZE 16
+
+/* KW: These aren't correct but someone set them to two and then
+ * released the module.  Now we can't change them as doing so would
+ * break backwards compatibility.
+ */
+#define I830_TEXTURE_COUNT     2
+#define I830_TEXBLEND_COUNT    I830_TEXTURE_COUNT
+
+#define I830_TEXBLEND_SIZE     12      /* (4 args + op) * 2 + COLOR_FACTOR */
+
+#define I830_UPLOAD_CTX                        0x1
+#define I830_UPLOAD_BUFFERS            0x2
+#define I830_UPLOAD_CLIPRECTS          0x4
+#define I830_UPLOAD_TEX0_IMAGE         0x100   /* handled clientside */
+#define I830_UPLOAD_TEX0_CUBE          0x200   /* handled clientside */
+#define I830_UPLOAD_TEX1_IMAGE         0x400   /* handled clientside */
+#define I830_UPLOAD_TEX1_CUBE          0x800   /* handled clientside */
+#define I830_UPLOAD_TEX2_IMAGE         0x1000  /* handled clientside */
+#define I830_UPLOAD_TEX2_CUBE          0x2000  /* handled clientside */
+#define I830_UPLOAD_TEX3_IMAGE         0x4000  /* handled clientside */
+#define I830_UPLOAD_TEX3_CUBE          0x8000  /* handled clientside */
+#define I830_UPLOAD_TEX_N_IMAGE(n)     (0x100 << (n * 2))
+#define I830_UPLOAD_TEX_N_CUBE(n)      (0x200 << (n * 2))
+#define I830_UPLOAD_TEXIMAGE_MASK      0xff00
+#define I830_UPLOAD_TEX0                       0x10000
+#define I830_UPLOAD_TEX1                       0x20000
+#define I830_UPLOAD_TEX2                       0x40000
+#define I830_UPLOAD_TEX3                       0x80000
+#define I830_UPLOAD_TEX_N(n)           (0x10000 << (n))
+#define I830_UPLOAD_TEX_MASK           0xf0000
+#define I830_UPLOAD_TEXBLEND0          0x100000
+#define I830_UPLOAD_TEXBLEND1          0x200000
+#define I830_UPLOAD_TEXBLEND2          0x400000
+#define I830_UPLOAD_TEXBLEND3          0x800000
+#define I830_UPLOAD_TEXBLEND_N(n)      (0x100000 << (n))
+#define I830_UPLOAD_TEXBLEND_MASK      0xf00000
+#define I830_UPLOAD_TEX_PALETTE_N(n)    (0x1000000 << (n))
+#define I830_UPLOAD_TEX_PALETTE_SHARED 0x4000000
+#define I830_UPLOAD_STIPPLE            0x8000000
+
+/* Indices into buf.Setup where various bits of state are mirrored per
+ * context and per buffer.  These can be fired at the card as a unit,
+ * or in a piecewise fashion as required.
+ */
+
+/* Destbuffer state
+ *    - backbuffer linear offset and pitch -- invarient in the current dri
+ *    - zbuffer linear offset and pitch -- also invarient
+ *    - drawing origin in back and depth buffers.
+ *
+ * Keep the depth/back buffer state here to accommodate private buffers
+ * in the future.
+ */
+
+#define I830_DESTREG_CBUFADDR 0
+#define I830_DESTREG_DBUFADDR 1
+#define I830_DESTREG_DV0 2
+#define I830_DESTREG_DV1 3
+#define I830_DESTREG_SENABLE 4
+#define I830_DESTREG_SR0 5
+#define I830_DESTREG_SR1 6
+#define I830_DESTREG_SR2 7
+#define I830_DESTREG_DR0 8
+#define I830_DESTREG_DR1 9
+#define I830_DESTREG_DR2 10
+#define I830_DESTREG_DR3 11
+#define I830_DESTREG_DR4 12
+#define I830_DEST_SETUP_SIZE 13
+
+/* Context state
+ */
+#define I830_CTXREG_STATE1             0
+#define I830_CTXREG_STATE2             1
+#define I830_CTXREG_STATE3             2
+#define I830_CTXREG_STATE4             3
+#define I830_CTXREG_STATE5             4
+#define I830_CTXREG_IALPHAB            5
+#define I830_CTXREG_STENCILTST         6
+#define I830_CTXREG_ENABLES_1          7
+#define I830_CTXREG_ENABLES_2          8
+#define I830_CTXREG_AA                 9
+#define I830_CTXREG_FOGCOLOR           10
+#define I830_CTXREG_BLENDCOLR0         11
+#define I830_CTXREG_BLENDCOLR          12      /* Dword 1 of 2 dword command */
+#define I830_CTXREG_VF                 13
+#define I830_CTXREG_VF2                        14
+#define I830_CTXREG_MCSB0              15
+#define I830_CTXREG_MCSB1              16
+#define I830_CTX_SETUP_SIZE            17
+
+/* 1.3: Stipple state
+ */
+#define I830_STPREG_ST0 0
+#define I830_STPREG_ST1 1
+#define I830_STP_SETUP_SIZE 2
+
+/* Texture state (per tex unit)
+ */
+
+#define I830_TEXREG_MI0        0       /* GFX_OP_MAP_INFO (6 dwords) */
+#define I830_TEXREG_MI1        1
+#define I830_TEXREG_MI2        2
+#define I830_TEXREG_MI3        3
+#define I830_TEXREG_MI4        4
+#define I830_TEXREG_MI5        5
+#define I830_TEXREG_MF 6       /* GFX_OP_MAP_FILTER */
+#define I830_TEXREG_MLC        7       /* GFX_OP_MAP_LOD_CTL */
+#define I830_TEXREG_MLL        8       /* GFX_OP_MAP_LOD_LIMITS */
+#define I830_TEXREG_MCS        9       /* GFX_OP_MAP_COORD_SETS */
+#define I830_TEX_SETUP_SIZE 10
+
+#define I830_TEXREG_TM0LI      0       /* load immediate 2 texture map n */
+#define I830_TEXREG_TM0S0      1
+#define I830_TEXREG_TM0S1      2
+#define I830_TEXREG_TM0S2      3
+#define I830_TEXREG_TM0S3      4
+#define I830_TEXREG_TM0S4      5
+#define I830_TEXREG_NOP0       6       /* noop */
+#define I830_TEXREG_NOP1       7       /* noop */
+#define I830_TEXREG_NOP2       8       /* noop */
+#define __I830_TEXREG_MCS      9       /* GFX_OP_MAP_COORD_SETS -- shared */
+#define __I830_TEX_SETUP_SIZE   10
+
+#define I830_FRONT   0x1
+#define I830_BACK    0x2
+#define I830_DEPTH   0x4
+
+#endif                         /* _I830_DEFINES_ */
+
+typedef struct _drm_i830_init {
+       enum {
+               I830_INIT_DMA = 0x01,
+               I830_CLEANUP_DMA = 0x02
+       } func;
+       unsigned int mmio_offset;
+       unsigned int buffers_offset;
+       int sarea_priv_offset;
+       unsigned int ring_start;
+       unsigned int ring_end;
+       unsigned int ring_size;
+       unsigned int front_offset;
+       unsigned int back_offset;
+       unsigned int depth_offset;
+       unsigned int w;
+       unsigned int h;
+       unsigned int pitch;
+       unsigned int pitch_bits;
+       unsigned int back_pitch;
+       unsigned int depth_pitch;
+       unsigned int cpp;
+} drm_i830_init_t;
+
+/* Warning: If you change the SAREA structure you must change the Xserver
+ * structure as well */
+
+typedef struct _drm_i830_tex_region {
+       unsigned char next, prev;       /* indices to form a circular LRU  */
+       unsigned char in_use;   /* owned by a client, or free? */
+       int age;                /* tracked by clients to update local LRU's */
+} drm_i830_tex_region_t;
+
+typedef struct _drm_i830_sarea {
+       unsigned int ContextState[I830_CTX_SETUP_SIZE];
+       unsigned int BufferState[I830_DEST_SETUP_SIZE];
+       unsigned int TexState[I830_TEXTURE_COUNT][I830_TEX_SETUP_SIZE];
+       unsigned int TexBlendState[I830_TEXBLEND_COUNT][I830_TEXBLEND_SIZE];
+       unsigned int TexBlendStateWordsUsed[I830_TEXBLEND_COUNT];
+       unsigned int Palette[2][256];
+       unsigned int dirty;
+
+       unsigned int nbox;
+       struct drm_clip_rect boxes[I830_NR_SAREA_CLIPRECTS];
+
+       /* Maintain an LRU of contiguous regions of texture space.  If
+        * you think you own a region of texture memory, and it has an
+        * age different to the one you set, then you are mistaken and
+        * it has been stolen by another client.  If global texAge
+        * hasn't changed, there is no need to walk the list.
+        *
+        * These regions can be used as a proxy for the fine-grained
+        * texture information of other clients - by maintaining them
+        * in the same lru which is used to age their own textures,
+        * clients have an approximate lru for the whole of global
+        * texture space, and can make informed decisions as to which
+        * areas to kick out.  There is no need to choose whether to
+        * kick out your own texture or someone else's - simply eject
+        * them all in LRU order.
+        */
+
+       drm_i830_tex_region_t texList[I830_NR_TEX_REGIONS + 1];
+       /* Last elt is sentinal */
+       int texAge;             /* last time texture was uploaded */
+       int last_enqueue;       /* last time a buffer was enqueued */
+       int last_dispatch;      /* age of the most recently dispatched buffer */
+       int last_quiescent;     /*  */
+       int ctxOwner;           /* last context to upload state */
+
+       int vertex_prim;
+
+       int pf_enabled;         /* is pageflipping allowed? */
+       int pf_active;
+       int pf_current_page;    /* which buffer is being displayed? */
+
+       int perf_boxes;         /* performance boxes to be displayed */
+
+       /* Here's the state for texunits 2,3:
+        */
+       unsigned int TexState2[I830_TEX_SETUP_SIZE];
+       unsigned int TexBlendState2[I830_TEXBLEND_SIZE];
+       unsigned int TexBlendStateWordsUsed2;
+
+       unsigned int TexState3[I830_TEX_SETUP_SIZE];
+       unsigned int TexBlendState3[I830_TEXBLEND_SIZE];
+       unsigned int TexBlendStateWordsUsed3;
+
+       unsigned int StippleState[I830_STP_SETUP_SIZE];
+} drm_i830_sarea_t;
+
+/* Flags for perf_boxes
+ */
+#define I830_BOX_RING_EMPTY    0x1     /* populated by kernel */
+#define I830_BOX_FLIP          0x2     /* populated by kernel */
+#define I830_BOX_WAIT          0x4     /* populated by kernel & client */
+#define I830_BOX_TEXTURE_LOAD  0x8     /* populated by kernel */
+#define I830_BOX_LOST_CONTEXT  0x10    /* populated by client */
+
+/* I830 specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_I830_INIT  0x00
+#define DRM_I830_VERTEX        0x01
+#define DRM_I830_CLEAR 0x02
+#define DRM_I830_FLUSH 0x03
+#define DRM_I830_GETAGE        0x04
+#define DRM_I830_GETBUF        0x05
+#define DRM_I830_SWAP  0x06
+#define DRM_I830_COPY  0x07
+#define DRM_I830_DOCOPY        0x08
+#define DRM_I830_FLIP  0x09
+#define DRM_I830_IRQ_EMIT      0x0a
+#define DRM_I830_IRQ_WAIT      0x0b
+#define DRM_I830_GETPARAM      0x0c
+#define DRM_I830_SETPARAM      0x0d
+
+#define DRM_IOCTL_I830_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_INIT, drm_i830_init_t)
+#define DRM_IOCTL_I830_VERTEX          DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_VERTEX, drm_i830_vertex_t)
+#define DRM_IOCTL_I830_CLEAR           DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_CLEAR, drm_i830_clear_t)
+#define DRM_IOCTL_I830_FLUSH           DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_FLUSH)
+#define DRM_IOCTL_I830_GETAGE          DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_GETAGE)
+#define DRM_IOCTL_I830_GETBUF          DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_GETBUF, drm_i830_dma_t)
+#define DRM_IOCTL_I830_SWAP            DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_SWAP)
+#define DRM_IOCTL_I830_COPY            DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_COPY, drm_i830_copy_t)
+#define DRM_IOCTL_I830_DOCOPY          DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_DOCOPY)
+#define DRM_IOCTL_I830_FLIP            DRM_IO ( DRM_COMMAND_BASE + DRM_IOCTL_I830_FLIP)
+#define DRM_IOCTL_I830_IRQ_EMIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_IRQ_EMIT, drm_i830_irq_emit_t)
+#define DRM_IOCTL_I830_IRQ_WAIT         DRM_IOW( DRM_COMMAND_BASE + DRM_IOCTL_I830_IRQ_WAIT, drm_i830_irq_wait_t)
+#define DRM_IOCTL_I830_GETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_GETPARAM, drm_i830_getparam_t)
+#define DRM_IOCTL_I830_SETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_IOCTL_I830_SETPARAM, drm_i830_setparam_t)
+
+typedef struct _drm_i830_clear {
+       int clear_color;
+       int clear_depth;
+       int flags;
+       unsigned int clear_colormask;
+       unsigned int clear_depthmask;
+} drm_i830_clear_t;
+
+/* These may be placeholders if we have more cliprects than
+ * I830_NR_SAREA_CLIPRECTS.  In that case, the client sets discard to
+ * false, indicating that the buffer will be dispatched again with a
+ * new set of cliprects.
+ */
+typedef struct _drm_i830_vertex {
+       int idx;                /* buffer index */
+       int used;               /* nr bytes in use */
+       int discard;            /* client is finished with the buffer? */
+} drm_i830_vertex_t;
+
+typedef struct _drm_i830_copy_t {
+       int idx;                /* buffer index */
+       int used;               /* nr bytes in use */
+       void __user *address;   /* Address to copy from */
+} drm_i830_copy_t;
+
+typedef struct drm_i830_dma {
+       void __user *virtual;
+       int request_idx;
+       int request_size;
+       int granted;
+} drm_i830_dma_t;
+
+/* 1.3: Userspace can request & wait on irq's:
+ */
+typedef struct drm_i830_irq_emit {
+       int __user *irq_seq;
+} drm_i830_irq_emit_t;
+
+typedef struct drm_i830_irq_wait {
+       int irq_seq;
+} drm_i830_irq_wait_t;
+
+/* 1.3: New ioctl to query kernel params:
+ */
+#define I830_PARAM_IRQ_ACTIVE            1
+
+typedef struct drm_i830_getparam {
+       int param;
+       int __user *value;
+} drm_i830_getparam_t;
+
+/* 1.3: New ioctl to set kernel params:
+ */
+#define I830_SETPARAM_USE_MI_BATCHBUFFER_START            1
+
+typedef struct drm_i830_setparam {
+       int param;
+       int value;
+} drm_i830_setparam_t;
+
+#endif                         /* _I830_DRM_H_ */
diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h
new file mode 100644 (file)
index 0000000..05c66cf
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _I915_DRM_H_
+#define _I915_DRM_H_
+
+/* Please note that modifications to all structs defined here are
+ * subject to backwards-compatibility constraints.
+ */
+
+#include "drm.h"
+
+/* Each region is a minimum of 16k, and there are at most 255 of them.
+ */
+#define I915_NR_TEX_REGIONS 255        /* table size 2k - maximum due to use
+                                * of chars for next/prev indices */
+#define I915_LOG_MIN_TEX_REGION_SIZE 14
+
+typedef struct _drm_i915_init {
+       enum {
+               I915_INIT_DMA = 0x01,
+               I915_CLEANUP_DMA = 0x02,
+               I915_RESUME_DMA = 0x03
+       } func;
+       unsigned int mmio_offset;
+       int sarea_priv_offset;
+       unsigned int ring_start;
+       unsigned int ring_end;
+       unsigned int ring_size;
+       unsigned int front_offset;
+       unsigned int back_offset;
+       unsigned int depth_offset;
+       unsigned int w;
+       unsigned int h;
+       unsigned int pitch;
+       unsigned int pitch_bits;
+       unsigned int back_pitch;
+       unsigned int depth_pitch;
+       unsigned int cpp;
+       unsigned int chipset;
+} drm_i915_init_t;
+
+typedef struct _drm_i915_sarea {
+       struct drm_tex_region texList[I915_NR_TEX_REGIONS + 1];
+       int last_upload;        /* last time texture was uploaded */
+       int last_enqueue;       /* last time a buffer was enqueued */
+       int last_dispatch;      /* age of the most recently dispatched buffer */
+       int ctxOwner;           /* last context to upload state */
+       int texAge;
+       int pf_enabled;         /* is pageflipping allowed? */
+       int pf_active;
+       int pf_current_page;    /* which buffer is being displayed? */
+       int perf_boxes;         /* performance boxes to be displayed */
+       int width, height;      /* screen size in pixels */
+
+       drm_handle_t front_handle;
+       int front_offset;
+       int front_size;
+
+       drm_handle_t back_handle;
+       int back_offset;
+       int back_size;
+
+       drm_handle_t depth_handle;
+       int depth_offset;
+       int depth_size;
+
+       drm_handle_t tex_handle;
+       int tex_offset;
+       int tex_size;
+       int log_tex_granularity;
+       int pitch;
+       int rotation;           /* 0, 90, 180 or 270 */
+       int rotated_offset;
+       int rotated_size;
+       int rotated_pitch;
+       int virtualX, virtualY;
+
+       unsigned int front_tiled;
+       unsigned int back_tiled;
+       unsigned int depth_tiled;
+       unsigned int rotated_tiled;
+       unsigned int rotated2_tiled;
+
+       int pipeA_x;
+       int pipeA_y;
+       int pipeA_w;
+       int pipeA_h;
+       int pipeB_x;
+       int pipeB_y;
+       int pipeB_w;
+       int pipeB_h;
+} drm_i915_sarea_t;
+
+/* Flags for perf_boxes
+ */
+#define I915_BOX_RING_EMPTY    0x1
+#define I915_BOX_FLIP          0x2
+#define I915_BOX_WAIT          0x4
+#define I915_BOX_TEXTURE_LOAD  0x8
+#define I915_BOX_LOST_CONTEXT  0x10
+
+/* I915 specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_I915_INIT          0x00
+#define DRM_I915_FLUSH         0x01
+#define DRM_I915_FLIP          0x02
+#define DRM_I915_BATCHBUFFER   0x03
+#define DRM_I915_IRQ_EMIT      0x04
+#define DRM_I915_IRQ_WAIT      0x05
+#define DRM_I915_GETPARAM      0x06
+#define DRM_I915_SETPARAM      0x07
+#define DRM_I915_ALLOC         0x08
+#define DRM_I915_FREE          0x09
+#define DRM_I915_INIT_HEAP     0x0a
+#define DRM_I915_CMDBUFFER     0x0b
+#define DRM_I915_DESTROY_HEAP  0x0c
+#define DRM_I915_SET_VBLANK_PIPE       0x0d
+#define DRM_I915_GET_VBLANK_PIPE       0x0e
+#define DRM_I915_VBLANK_SWAP   0x0f
+#define DRM_I915_HWS_ADDR      0x11
+
+#define DRM_IOCTL_I915_INIT            DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
+#define DRM_IOCTL_I915_FLUSH           DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
+#define DRM_IOCTL_I915_FLIP            DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLIP)
+#define DRM_IOCTL_I915_BATCHBUFFER     DRM_IOW( DRM_COMMAND_BASE + DRM_I915_BATCHBUFFER, drm_i915_batchbuffer_t)
+#define DRM_IOCTL_I915_IRQ_EMIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_IRQ_EMIT, drm_i915_irq_emit_t)
+#define DRM_IOCTL_I915_IRQ_WAIT         DRM_IOW( DRM_COMMAND_BASE + DRM_I915_IRQ_WAIT, drm_i915_irq_wait_t)
+#define DRM_IOCTL_I915_GETPARAM         DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GETPARAM, drm_i915_getparam_t)
+#define DRM_IOCTL_I915_SETPARAM         DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SETPARAM, drm_i915_setparam_t)
+#define DRM_IOCTL_I915_ALLOC            DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_ALLOC, drm_i915_mem_alloc_t)
+#define DRM_IOCTL_I915_FREE             DRM_IOW( DRM_COMMAND_BASE + DRM_I915_FREE, drm_i915_mem_free_t)
+#define DRM_IOCTL_I915_INIT_HEAP        DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT_HEAP, drm_i915_mem_init_heap_t)
+#define DRM_IOCTL_I915_CMDBUFFER       DRM_IOW( DRM_COMMAND_BASE + DRM_I915_CMDBUFFER, drm_i915_cmdbuffer_t)
+#define DRM_IOCTL_I915_DESTROY_HEAP    DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t)
+#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
+#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
+#define DRM_IOCTL_I915_VBLANK_SWAP     DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_VBLANK_SWAP, drm_i915_vblank_swap_t)
+
+/* Allow drivers to submit batchbuffers directly to hardware, relying
+ * on the security mechanisms provided by hardware.
+ */
+typedef struct _drm_i915_batchbuffer {
+       int start;              /* agp offset */
+       int used;               /* nr bytes in use */
+       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
+       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
+       int num_cliprects;      /* mulitpass with multiple cliprects? */
+       struct drm_clip_rect __user *cliprects; /* pointer to userspace cliprects */
+} drm_i915_batchbuffer_t;
+
+/* As above, but pass a pointer to userspace buffer which can be
+ * validated by the kernel prior to sending to hardware.
+ */
+typedef struct _drm_i915_cmdbuffer {
+       char __user *buf;       /* pointer to userspace command buffer */
+       int sz;                 /* nr bytes in buf */
+       int DR1;                /* hw flags for GFX_OP_DRAWRECT_INFO */
+       int DR4;                /* window origin for GFX_OP_DRAWRECT_INFO */
+       int num_cliprects;      /* mulitpass with multiple cliprects? */
+       struct drm_clip_rect __user *cliprects; /* pointer to userspace cliprects */
+} drm_i915_cmdbuffer_t;
+
+/* Userspace can request & wait on irq's:
+ */
+typedef struct drm_i915_irq_emit {
+       int __user *irq_seq;
+} drm_i915_irq_emit_t;
+
+typedef struct drm_i915_irq_wait {
+       int irq_seq;
+} drm_i915_irq_wait_t;
+
+/* Ioctl to query kernel params:
+ */
+#define I915_PARAM_IRQ_ACTIVE            1
+#define I915_PARAM_ALLOW_BATCHBUFFER     2
+#define I915_PARAM_LAST_DISPATCH         3
+
+typedef struct drm_i915_getparam {
+       int param;
+       int __user *value;
+} drm_i915_getparam_t;
+
+/* Ioctl to set kernel params:
+ */
+#define I915_SETPARAM_USE_MI_BATCHBUFFER_START            1
+#define I915_SETPARAM_TEX_LRU_LOG_GRANULARITY             2
+#define I915_SETPARAM_ALLOW_BATCHBUFFER                   3
+
+typedef struct drm_i915_setparam {
+       int param;
+       int value;
+} drm_i915_setparam_t;
+
+/* A memory manager for regions of shared memory:
+ */
+#define I915_MEM_REGION_AGP 1
+
+typedef struct drm_i915_mem_alloc {
+       int region;
+       int alignment;
+       int size;
+       int __user *region_offset;      /* offset from start of fb or agp */
+} drm_i915_mem_alloc_t;
+
+typedef struct drm_i915_mem_free {
+       int region;
+       int region_offset;
+} drm_i915_mem_free_t;
+
+typedef struct drm_i915_mem_init_heap {
+       int region;
+       int size;
+       int start;
+} drm_i915_mem_init_heap_t;
+
+/* Allow memory manager to be torn down and re-initialized (eg on
+ * rotate):
+ */
+typedef struct drm_i915_mem_destroy_heap {
+       int region;
+} drm_i915_mem_destroy_heap_t;
+
+/* Allow X server to configure which pipes to monitor for vblank signals
+ */
+#define        DRM_I915_VBLANK_PIPE_A  1
+#define        DRM_I915_VBLANK_PIPE_B  2
+
+typedef struct drm_i915_vblank_pipe {
+       int pipe;
+} drm_i915_vblank_pipe_t;
+
+/* Schedule buffer swap at given vertical blank:
+ */
+typedef struct drm_i915_vblank_swap {
+       drm_drawable_t drawable;
+       enum drm_vblank_seq_type seqtype;
+       unsigned int sequence;
+} drm_i915_vblank_swap_t;
+
+typedef struct drm_i915_hws_addr {
+       uint64_t addr;
+} drm_i915_hws_addr_t;
+
+#endif                         /* _I915_DRM_H_ */
diff --git a/include/drm/mga_drm.h b/include/drm/mga_drm.h
new file mode 100644 (file)
index 0000000..944b50a
--- /dev/null
@@ -0,0 +1,417 @@
+/* mga_drm.h -- Public header for the Matrox g200/g400 driver -*- linux-c -*-
+ * Created: Tue Jan 25 01:50:01 1999 by jhartmann@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Jeff Hartmann <jhartmann@valinux.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ *
+ * Rewritten by:
+ *    Gareth Hughes <gareth@valinux.com>
+ */
+
+#ifndef __MGA_DRM_H__
+#define __MGA_DRM_H__
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the Xserver file (mga_sarea.h)
+ */
+
+#ifndef __MGA_SAREA_DEFINES__
+#define __MGA_SAREA_DEFINES__
+
+/* WARP pipe flags
+ */
+#define MGA_F                  0x1     /* fog */
+#define MGA_A                  0x2     /* alpha */
+#define MGA_S                  0x4     /* specular */
+#define MGA_T2                 0x8     /* multitexture */
+
+#define MGA_WARP_TGZ           0
+#define MGA_WARP_TGZF          (MGA_F)
+#define MGA_WARP_TGZA          (MGA_A)
+#define MGA_WARP_TGZAF         (MGA_F|MGA_A)
+#define MGA_WARP_TGZS          (MGA_S)
+#define MGA_WARP_TGZSF         (MGA_S|MGA_F)
+#define MGA_WARP_TGZSA         (MGA_S|MGA_A)
+#define MGA_WARP_TGZSAF                (MGA_S|MGA_F|MGA_A)
+#define MGA_WARP_T2GZ          (MGA_T2)
+#define MGA_WARP_T2GZF         (MGA_T2|MGA_F)
+#define MGA_WARP_T2GZA         (MGA_T2|MGA_A)
+#define MGA_WARP_T2GZAF                (MGA_T2|MGA_A|MGA_F)
+#define MGA_WARP_T2GZS         (MGA_T2|MGA_S)
+#define MGA_WARP_T2GZSF                (MGA_T2|MGA_S|MGA_F)
+#define MGA_WARP_T2GZSA                (MGA_T2|MGA_S|MGA_A)
+#define MGA_WARP_T2GZSAF       (MGA_T2|MGA_S|MGA_F|MGA_A)
+
+#define MGA_MAX_G200_PIPES     8       /* no multitex */
+#define MGA_MAX_G400_PIPES     16
+#define MGA_MAX_WARP_PIPES     MGA_MAX_G400_PIPES
+#define MGA_WARP_UCODE_SIZE    32768   /* in bytes */
+
+#define MGA_CARD_TYPE_G200     1
+#define MGA_CARD_TYPE_G400     2
+#define MGA_CARD_TYPE_G450     3       /* not currently used */
+#define MGA_CARD_TYPE_G550     4
+
+#define MGA_FRONT              0x1
+#define MGA_BACK               0x2
+#define MGA_DEPTH              0x4
+
+/* What needs to be changed for the current vertex dma buffer?
+ */
+#define MGA_UPLOAD_CONTEXT     0x1
+#define MGA_UPLOAD_TEX0                0x2
+#define MGA_UPLOAD_TEX1                0x4
+#define MGA_UPLOAD_PIPE                0x8
+#define MGA_UPLOAD_TEX0IMAGE   0x10    /* handled client-side */
+#define MGA_UPLOAD_TEX1IMAGE   0x20    /* handled client-side */
+#define MGA_UPLOAD_2D          0x40
+#define MGA_WAIT_AGE           0x80    /* handled client-side */
+#define MGA_UPLOAD_CLIPRECTS   0x100   /* handled client-side */
+#if 0
+#define MGA_DMA_FLUSH          0x200   /* set when someone gets the lock
+                                          quiescent */
+#endif
+
+/* 32 buffers of 64k each, total 2 meg.
+ */
+#define MGA_BUFFER_SIZE                (1 << 16)
+#define MGA_NUM_BUFFERS                128
+
+/* Keep these small for testing.
+ */
+#define MGA_NR_SAREA_CLIPRECTS 8
+
+/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
+ * regions, subject to a minimum region size of (1<<16) == 64k.
+ *
+ * Clients may subdivide regions internally, but when sharing between
+ * clients, the region size is the minimum granularity.
+ */
+
+#define MGA_CARD_HEAP                  0
+#define MGA_AGP_HEAP                   1
+#define MGA_NR_TEX_HEAPS               2
+#define MGA_NR_TEX_REGIONS             16
+#define MGA_LOG_MIN_TEX_REGION_SIZE    16
+
+#define  DRM_MGA_IDLE_RETRY          2048
+
+#endif                         /* __MGA_SAREA_DEFINES__ */
+
+/* Setup registers for 3D context
+ */
+typedef struct {
+       unsigned int dstorg;
+       unsigned int maccess;
+       unsigned int plnwt;
+       unsigned int dwgctl;
+       unsigned int alphactrl;
+       unsigned int fogcolor;
+       unsigned int wflag;
+       unsigned int tdualstage0;
+       unsigned int tdualstage1;
+       unsigned int fcol;
+       unsigned int stencil;
+       unsigned int stencilctl;
+} drm_mga_context_regs_t;
+
+/* Setup registers for 2D, X server
+ */
+typedef struct {
+       unsigned int pitch;
+} drm_mga_server_regs_t;
+
+/* Setup registers for each texture unit
+ */
+typedef struct {
+       unsigned int texctl;
+       unsigned int texctl2;
+       unsigned int texfilter;
+       unsigned int texbordercol;
+       unsigned int texorg;
+       unsigned int texwidth;
+       unsigned int texheight;
+       unsigned int texorg1;
+       unsigned int texorg2;
+       unsigned int texorg3;
+       unsigned int texorg4;
+} drm_mga_texture_regs_t;
+
+/* General aging mechanism
+ */
+typedef struct {
+       unsigned int head;      /* Position of head pointer          */
+       unsigned int wrap;      /* Primary DMA wrap count            */
+} drm_mga_age_t;
+
+typedef struct _drm_mga_sarea {
+       /* The channel for communication of state information to the kernel
+        * on firing a vertex dma buffer.
+        */
+       drm_mga_context_regs_t context_state;
+       drm_mga_server_regs_t server_state;
+       drm_mga_texture_regs_t tex_state[2];
+       unsigned int warp_pipe;
+       unsigned int dirty;
+       unsigned int vertsize;
+
+       /* The current cliprects, or a subset thereof.
+        */
+       struct drm_clip_rect boxes[MGA_NR_SAREA_CLIPRECTS];
+       unsigned int nbox;
+
+       /* Information about the most recently used 3d drawable.  The
+        * client fills in the req_* fields, the server fills in the
+        * exported_ fields and puts the cliprects into boxes, above.
+        *
+        * The client clears the exported_drawable field before
+        * clobbering the boxes data.
+        */
+       unsigned int req_drawable;      /* the X drawable id */
+       unsigned int req_draw_buffer;   /* MGA_FRONT or MGA_BACK */
+
+       unsigned int exported_drawable;
+       unsigned int exported_index;
+       unsigned int exported_stamp;
+       unsigned int exported_buffers;
+       unsigned int exported_nfront;
+       unsigned int exported_nback;
+       int exported_back_x, exported_front_x, exported_w;
+       int exported_back_y, exported_front_y, exported_h;
+       struct drm_clip_rect exported_boxes[MGA_NR_SAREA_CLIPRECTS];
+
+       /* Counters for aging textures and for client-side throttling.
+        */
+       unsigned int status[4];
+       unsigned int last_wrap;
+
+       drm_mga_age_t last_frame;
+       unsigned int last_enqueue;      /* last time a buffer was enqueued */
+       unsigned int last_dispatch;     /* age of the most recently dispatched buffer */
+       unsigned int last_quiescent;    /*  */
+
+       /* LRU lists for texture memory in agp space and on the card.
+        */
+       struct drm_tex_region texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS + 1];
+       unsigned int texAge[MGA_NR_TEX_HEAPS];
+
+       /* Mechanism to validate card state.
+        */
+       int ctxOwner;
+} drm_mga_sarea_t;
+
+/* MGA specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_MGA_INIT     0x00
+#define DRM_MGA_FLUSH    0x01
+#define DRM_MGA_RESET    0x02
+#define DRM_MGA_SWAP     0x03
+#define DRM_MGA_CLEAR    0x04
+#define DRM_MGA_VERTEX   0x05
+#define DRM_MGA_INDICES  0x06
+#define DRM_MGA_ILOAD    0x07
+#define DRM_MGA_BLIT     0x08
+#define DRM_MGA_GETPARAM 0x09
+
+/* 3.2:
+ * ioctls for operating on fences.
+ */
+#define DRM_MGA_SET_FENCE      0x0a
+#define DRM_MGA_WAIT_FENCE     0x0b
+#define DRM_MGA_DMA_BOOTSTRAP  0x0c
+
+#define DRM_IOCTL_MGA_INIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INIT, drm_mga_init_t)
+#define DRM_IOCTL_MGA_FLUSH    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_FLUSH, drm_lock_t)
+#define DRM_IOCTL_MGA_RESET    DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_RESET)
+#define DRM_IOCTL_MGA_SWAP     DRM_IO(  DRM_COMMAND_BASE + DRM_MGA_SWAP)
+#define DRM_IOCTL_MGA_CLEAR    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_CLEAR, drm_mga_clear_t)
+#define DRM_IOCTL_MGA_VERTEX   DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_VERTEX, drm_mga_vertex_t)
+#define DRM_IOCTL_MGA_INDICES  DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_INDICES, drm_mga_indices_t)
+#define DRM_IOCTL_MGA_ILOAD    DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_ILOAD, drm_mga_iload_t)
+#define DRM_IOCTL_MGA_BLIT     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_BLIT, drm_mga_blit_t)
+#define DRM_IOCTL_MGA_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_GETPARAM, drm_mga_getparam_t)
+#define DRM_IOCTL_MGA_SET_FENCE     DRM_IOW( DRM_COMMAND_BASE + DRM_MGA_SET_FENCE, uint32_t)
+#define DRM_IOCTL_MGA_WAIT_FENCE    DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_WAIT_FENCE, uint32_t)
+#define DRM_IOCTL_MGA_DMA_BOOTSTRAP DRM_IOWR(DRM_COMMAND_BASE + DRM_MGA_DMA_BOOTSTRAP, drm_mga_dma_bootstrap_t)
+
+typedef struct _drm_mga_warp_index {
+       int installed;
+       unsigned long phys_addr;
+       int size;
+} drm_mga_warp_index_t;
+
+typedef struct drm_mga_init {
+       enum {
+               MGA_INIT_DMA = 0x01,
+               MGA_CLEANUP_DMA = 0x02
+       } func;
+
+       unsigned long sarea_priv_offset;
+
+       int chipset;
+       int sgram;
+
+       unsigned int maccess;
+
+       unsigned int fb_cpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+
+       unsigned int depth_cpp;
+       unsigned int depth_offset, depth_pitch;
+
+       unsigned int texture_offset[MGA_NR_TEX_HEAPS];
+       unsigned int texture_size[MGA_NR_TEX_HEAPS];
+
+       unsigned long fb_offset;
+       unsigned long mmio_offset;
+       unsigned long status_offset;
+       unsigned long warp_offset;
+       unsigned long primary_offset;
+       unsigned long buffers_offset;
+} drm_mga_init_t;
+
+typedef struct drm_mga_dma_bootstrap {
+       /**
+        * \name AGP texture region
+        *
+        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, these fields will
+        * be filled in with the actual AGP texture settings.
+        *
+        * \warning
+        * If these fields are non-zero, but dma_mga_dma_bootstrap::agp_mode
+        * is zero, it means that PCI memory (most likely through the use of
+        * an IOMMU) is being used for "AGP" textures.
+        */
+       /*@{ */
+       unsigned long texture_handle; /**< Handle used to map AGP textures. */
+       uint32_t texture_size;        /**< Size of the AGP texture region. */
+       /*@} */
+
+       /**
+        * Requested size of the primary DMA region.
+        *
+        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
+        * filled in with the actual AGP mode.  If AGP was not available
+        */
+       uint32_t primary_size;
+
+       /**
+        * Requested number of secondary DMA buffers.
+        *
+        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
+        * filled in with the actual number of secondary DMA buffers
+        * allocated.  Particularly when PCI DMA is used, this may be
+        * (subtantially) less than the number requested.
+        */
+       uint32_t secondary_bin_count;
+
+       /**
+        * Requested size of each secondary DMA buffer.
+        *
+        * While the kernel \b is free to reduce
+        * dma_mga_dma_bootstrap::secondary_bin_count, it is \b not allowed
+        * to reduce dma_mga_dma_bootstrap::secondary_bin_size.
+        */
+       uint32_t secondary_bin_size;
+
+       /**
+        * Bit-wise mask of AGPSTAT2_* values.  Currently only \c AGPSTAT2_1X,
+        * \c AGPSTAT2_2X, and \c AGPSTAT2_4X are supported.  If this value is
+        * zero, it means that PCI DMA should be used, even if AGP is
+        * possible.
+        *
+        * On return from the DRM_MGA_DMA_BOOTSTRAP ioctl, this field will be
+        * filled in with the actual AGP mode.  If AGP was not available
+        * (i.e., PCI DMA was used), this value will be zero.
+        */
+       uint32_t agp_mode;
+
+       /**
+        * Desired AGP GART size, measured in megabytes.
+        */
+       uint8_t agp_size;
+} drm_mga_dma_bootstrap_t;
+
+typedef struct drm_mga_clear {
+       unsigned int flags;
+       unsigned int clear_color;
+       unsigned int clear_depth;
+       unsigned int color_mask;
+       unsigned int depth_mask;
+} drm_mga_clear_t;
+
+typedef struct drm_mga_vertex {
+       int idx;                /* buffer to queue */
+       int used;               /* bytes in use */
+       int discard;            /* client finished with buffer?  */
+} drm_mga_vertex_t;
+
+typedef struct drm_mga_indices {
+       int idx;                /* buffer to queue */
+       unsigned int start;
+       unsigned int end;
+       int discard;            /* client finished with buffer?  */
+} drm_mga_indices_t;
+
+typedef struct drm_mga_iload {
+       int idx;
+       unsigned int dstorg;
+       unsigned int length;
+} drm_mga_iload_t;
+
+typedef struct _drm_mga_blit {
+       unsigned int planemask;
+       unsigned int srcorg;
+       unsigned int dstorg;
+       int src_pitch, dst_pitch;
+       int delta_sx, delta_sy;
+       int delta_dx, delta_dy;
+       int height, ydir;       /* flip image vertically */
+       int source_pitch, dest_pitch;
+} drm_mga_blit_t;
+
+/* 3.1: An ioctl to get parameters that aren't available to the 3d
+ * client any other way.
+ */
+#define MGA_PARAM_IRQ_NR            1
+
+/* 3.2: Query the actual card type.  The DDX only distinguishes between
+ * G200 chips and non-G200 chips, which it calls G400.  It turns out that
+ * there are some very sublte differences between the G4x0 chips and the G550
+ * chips.  Using this parameter query, a client-side driver can detect the
+ * difference between a G4x0 and a G550.
+ */
+#define MGA_PARAM_CARD_TYPE         2
+
+typedef struct drm_mga_getparam {
+       int param;
+       void __user *value;
+} drm_mga_getparam_t;
+
+#endif
diff --git a/include/drm/r128_drm.h b/include/drm/r128_drm.h
new file mode 100644 (file)
index 0000000..8d8878b
--- /dev/null
@@ -0,0 +1,326 @@
+/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*-
+ * Created: Wed Apr  5 19:24:19 2000 by kevin@precisioninsight.com
+ */
+/*
+ * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Gareth Hughes <gareth@valinux.com>
+ *    Kevin E. Martin <martin@valinux.com>
+ */
+
+#ifndef __R128_DRM_H__
+#define __R128_DRM_H__
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the X server file (r128_sarea.h)
+ */
+#ifndef __R128_SAREA_DEFINES__
+#define __R128_SAREA_DEFINES__
+
+/* What needs to be changed for the current vertex buffer?
+ */
+#define R128_UPLOAD_CONTEXT            0x001
+#define R128_UPLOAD_SETUP              0x002
+#define R128_UPLOAD_TEX0               0x004
+#define R128_UPLOAD_TEX1               0x008
+#define R128_UPLOAD_TEX0IMAGES         0x010
+#define R128_UPLOAD_TEX1IMAGES         0x020
+#define R128_UPLOAD_CORE               0x040
+#define R128_UPLOAD_MASKS              0x080
+#define R128_UPLOAD_WINDOW             0x100
+#define R128_UPLOAD_CLIPRECTS          0x200   /* handled client-side */
+#define R128_REQUIRE_QUIESCENCE                0x400
+#define R128_UPLOAD_ALL                        0x7ff
+
+#define R128_FRONT                     0x1
+#define R128_BACK                      0x2
+#define R128_DEPTH                     0x4
+
+/* Primitive types
+ */
+#define R128_POINTS                    0x1
+#define R128_LINES                     0x2
+#define R128_LINE_STRIP                        0x3
+#define R128_TRIANGLES                 0x4
+#define R128_TRIANGLE_FAN              0x5
+#define R128_TRIANGLE_STRIP            0x6
+
+/* Vertex/indirect buffer size
+ */
+#define R128_BUFFER_SIZE               16384
+
+/* Byte offsets for indirect buffer data
+ */
+#define R128_INDEX_PRIM_OFFSET         20
+#define R128_HOSTDATA_BLIT_OFFSET      32
+
+/* Keep these small for testing.
+ */
+#define R128_NR_SAREA_CLIPRECTS                12
+
+/* There are 2 heaps (local/AGP).  Each region within a heap is a
+ *  minimum of 64k, and there are at most 64 of them per heap.
+ */
+#define R128_LOCAL_TEX_HEAP            0
+#define R128_AGP_TEX_HEAP              1
+#define R128_NR_TEX_HEAPS              2
+#define R128_NR_TEX_REGIONS            64
+#define R128_LOG_TEX_GRANULARITY       16
+
+#define R128_NR_CONTEXT_REGS           12
+
+#define R128_MAX_TEXTURE_LEVELS                11
+#define R128_MAX_TEXTURE_UNITS         2
+
+#endif                         /* __R128_SAREA_DEFINES__ */
+
+typedef struct {
+       /* Context state - can be written in one large chunk */
+       unsigned int dst_pitch_offset_c;
+       unsigned int dp_gui_master_cntl_c;
+       unsigned int sc_top_left_c;
+       unsigned int sc_bottom_right_c;
+       unsigned int z_offset_c;
+       unsigned int z_pitch_c;
+       unsigned int z_sten_cntl_c;
+       unsigned int tex_cntl_c;
+       unsigned int misc_3d_state_cntl_reg;
+       unsigned int texture_clr_cmp_clr_c;
+       unsigned int texture_clr_cmp_msk_c;
+       unsigned int fog_color_c;
+
+       /* Texture state */
+       unsigned int tex_size_pitch_c;
+       unsigned int constant_color_c;
+
+       /* Setup state */
+       unsigned int pm4_vc_fpu_setup;
+       unsigned int setup_cntl;
+
+       /* Mask state */
+       unsigned int dp_write_mask;
+       unsigned int sten_ref_mask_c;
+       unsigned int plane_3d_mask_c;
+
+       /* Window state */
+       unsigned int window_xy_offset;
+
+       /* Core state */
+       unsigned int scale_3d_cntl;
+} drm_r128_context_regs_t;
+
+/* Setup registers for each texture unit
+ */
+typedef struct {
+       unsigned int tex_cntl;
+       unsigned int tex_combine_cntl;
+       unsigned int tex_size_pitch;
+       unsigned int tex_offset[R128_MAX_TEXTURE_LEVELS];
+       unsigned int tex_border_color;
+} drm_r128_texture_regs_t;
+
+typedef struct drm_r128_sarea {
+       /* The channel for communication of state information to the kernel
+        * on firing a vertex buffer.
+        */
+       drm_r128_context_regs_t context_state;
+       drm_r128_texture_regs_t tex_state[R128_MAX_TEXTURE_UNITS];
+       unsigned int dirty;
+       unsigned int vertsize;
+       unsigned int vc_format;
+
+       /* The current cliprects, or a subset thereof.
+        */
+       struct drm_clip_rect boxes[R128_NR_SAREA_CLIPRECTS];
+       unsigned int nbox;
+
+       /* Counters for client-side throttling of rendering clients.
+        */
+       unsigned int last_frame;
+       unsigned int last_dispatch;
+
+       struct drm_tex_region tex_list[R128_NR_TEX_HEAPS][R128_NR_TEX_REGIONS + 1];
+       unsigned int tex_age[R128_NR_TEX_HEAPS];
+       int ctx_owner;
+       int pfAllowPageFlip;    /* number of 3d windows (0,1,2 or more) */
+       int pfCurrentPage;      /* which buffer is being displayed? */
+} drm_r128_sarea_t;
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the Xserver file (xf86drmR128.h)
+ */
+
+/* Rage 128 specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_R128_INIT       0x00
+#define DRM_R128_CCE_START  0x01
+#define DRM_R128_CCE_STOP   0x02
+#define DRM_R128_CCE_RESET  0x03
+#define DRM_R128_CCE_IDLE   0x04
+/* 0x05 not used */
+#define DRM_R128_RESET      0x06
+#define DRM_R128_SWAP       0x07
+#define DRM_R128_CLEAR      0x08
+#define DRM_R128_VERTEX     0x09
+#define DRM_R128_INDICES    0x0a
+#define DRM_R128_BLIT       0x0b
+#define DRM_R128_DEPTH      0x0c
+#define DRM_R128_STIPPLE    0x0d
+/* 0x0e not used */
+#define DRM_R128_INDIRECT   0x0f
+#define DRM_R128_FULLSCREEN 0x10
+#define DRM_R128_CLEAR2     0x11
+#define DRM_R128_GETPARAM   0x12
+#define DRM_R128_FLIP       0x13
+
+#define DRM_IOCTL_R128_INIT       DRM_IOW( DRM_COMMAND_BASE + DRM_R128_INIT, drm_r128_init_t)
+#define DRM_IOCTL_R128_CCE_START  DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_START)
+#define DRM_IOCTL_R128_CCE_STOP   DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CCE_STOP, drm_r128_cce_stop_t)
+#define DRM_IOCTL_R128_CCE_RESET  DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_RESET)
+#define DRM_IOCTL_R128_CCE_IDLE   DRM_IO(  DRM_COMMAND_BASE + DRM_R128_CCE_IDLE)
+/* 0x05 not used */
+#define DRM_IOCTL_R128_RESET      DRM_IO(  DRM_COMMAND_BASE + DRM_R128_RESET)
+#define DRM_IOCTL_R128_SWAP       DRM_IO(  DRM_COMMAND_BASE + DRM_R128_SWAP)
+#define DRM_IOCTL_R128_CLEAR      DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CLEAR, drm_r128_clear_t)
+#define DRM_IOCTL_R128_VERTEX     DRM_IOW( DRM_COMMAND_BASE + DRM_R128_VERTEX, drm_r128_vertex_t)
+#define DRM_IOCTL_R128_INDICES    DRM_IOW( DRM_COMMAND_BASE + DRM_R128_INDICES, drm_r128_indices_t)
+#define DRM_IOCTL_R128_BLIT       DRM_IOW( DRM_COMMAND_BASE + DRM_R128_BLIT, drm_r128_blit_t)
+#define DRM_IOCTL_R128_DEPTH      DRM_IOW( DRM_COMMAND_BASE + DRM_R128_DEPTH, drm_r128_depth_t)
+#define DRM_IOCTL_R128_STIPPLE    DRM_IOW( DRM_COMMAND_BASE + DRM_R128_STIPPLE, drm_r128_stipple_t)
+/* 0x0e not used */
+#define DRM_IOCTL_R128_INDIRECT   DRM_IOWR(DRM_COMMAND_BASE + DRM_R128_INDIRECT, drm_r128_indirect_t)
+#define DRM_IOCTL_R128_FULLSCREEN DRM_IOW( DRM_COMMAND_BASE + DRM_R128_FULLSCREEN, drm_r128_fullscreen_t)
+#define DRM_IOCTL_R128_CLEAR2     DRM_IOW( DRM_COMMAND_BASE + DRM_R128_CLEAR2, drm_r128_clear2_t)
+#define DRM_IOCTL_R128_GETPARAM   DRM_IOWR( DRM_COMMAND_BASE + DRM_R128_GETPARAM, drm_r128_getparam_t)
+#define DRM_IOCTL_R128_FLIP       DRM_IO(  DRM_COMMAND_BASE + DRM_R128_FLIP)
+
+typedef struct drm_r128_init {
+       enum {
+               R128_INIT_CCE = 0x01,
+               R128_CLEANUP_CCE = 0x02
+       } func;
+       unsigned long sarea_priv_offset;
+       int is_pci;
+       int cce_mode;
+       int cce_secure;
+       int ring_size;
+       int usec_timeout;
+
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+       unsigned int span_offset;
+
+       unsigned long fb_offset;
+       unsigned long mmio_offset;
+       unsigned long ring_offset;
+       unsigned long ring_rptr_offset;
+       unsigned long buffers_offset;
+       unsigned long agp_textures_offset;
+} drm_r128_init_t;
+
+typedef struct drm_r128_cce_stop {
+       int flush;
+       int idle;
+} drm_r128_cce_stop_t;
+
+typedef struct drm_r128_clear {
+       unsigned int flags;
+       unsigned int clear_color;
+       unsigned int clear_depth;
+       unsigned int color_mask;
+       unsigned int depth_mask;
+} drm_r128_clear_t;
+
+typedef struct drm_r128_vertex {
+       int prim;
+       int idx;                /* Index of vertex buffer */
+       int count;              /* Number of vertices in buffer */
+       int discard;            /* Client finished with buffer? */
+} drm_r128_vertex_t;
+
+typedef struct drm_r128_indices {
+       int prim;
+       int idx;
+       int start;
+       int end;
+       int discard;            /* Client finished with buffer? */
+} drm_r128_indices_t;
+
+typedef struct drm_r128_blit {
+       int idx;
+       int pitch;
+       int offset;
+       int format;
+       unsigned short x, y;
+       unsigned short width, height;
+} drm_r128_blit_t;
+
+typedef struct drm_r128_depth {
+       enum {
+               R128_WRITE_SPAN = 0x01,
+               R128_WRITE_PIXELS = 0x02,
+               R128_READ_SPAN = 0x03,
+               R128_READ_PIXELS = 0x04
+       } func;
+       int n;
+       int __user *x;
+       int __user *y;
+       unsigned int __user *buffer;
+       unsigned char __user *mask;
+} drm_r128_depth_t;
+
+typedef struct drm_r128_stipple {
+       unsigned int __user *mask;
+} drm_r128_stipple_t;
+
+typedef struct drm_r128_indirect {
+       int idx;
+       int start;
+       int end;
+       int discard;
+} drm_r128_indirect_t;
+
+typedef struct drm_r128_fullscreen {
+       enum {
+               R128_INIT_FULLSCREEN = 0x01,
+               R128_CLEANUP_FULLSCREEN = 0x02
+       } func;
+} drm_r128_fullscreen_t;
+
+/* 2.3: An ioctl to get parameters that aren't available to the 3d
+ * client any other way.
+ */
+#define R128_PARAM_IRQ_NR            1
+
+typedef struct drm_r128_getparam {
+       int param;
+       void __user *value;
+} drm_r128_getparam_t;
+
+#endif
diff --git a/include/drm/radeon_drm.h b/include/drm/radeon_drm.h
new file mode 100644 (file)
index 0000000..73ff51f
--- /dev/null
@@ -0,0 +1,749 @@
+/* radeon_drm.h -- Public header for the radeon driver -*- linux-c -*-
+ *
+ * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
+ * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Kevin E. Martin <martin@valinux.com>
+ *    Gareth Hughes <gareth@valinux.com>
+ *    Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifndef __RADEON_DRM_H__
+#define __RADEON_DRM_H__
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the X server file (radeon_sarea.h)
+ */
+#ifndef __RADEON_SAREA_DEFINES__
+#define __RADEON_SAREA_DEFINES__
+
+/* Old style state flags, required for sarea interface (1.1 and 1.2
+ * clears) and 1.2 drm_vertex2 ioctl.
+ */
+#define RADEON_UPLOAD_CONTEXT          0x00000001
+#define RADEON_UPLOAD_VERTFMT          0x00000002
+#define RADEON_UPLOAD_LINE             0x00000004
+#define RADEON_UPLOAD_BUMPMAP          0x00000008
+#define RADEON_UPLOAD_MASKS            0x00000010
+#define RADEON_UPLOAD_VIEWPORT         0x00000020
+#define RADEON_UPLOAD_SETUP            0x00000040
+#define RADEON_UPLOAD_TCL              0x00000080
+#define RADEON_UPLOAD_MISC             0x00000100
+#define RADEON_UPLOAD_TEX0             0x00000200
+#define RADEON_UPLOAD_TEX1             0x00000400
+#define RADEON_UPLOAD_TEX2             0x00000800
+#define RADEON_UPLOAD_TEX0IMAGES       0x00001000
+#define RADEON_UPLOAD_TEX1IMAGES       0x00002000
+#define RADEON_UPLOAD_TEX2IMAGES       0x00004000
+#define RADEON_UPLOAD_CLIPRECTS                0x00008000      /* handled client-side */
+#define RADEON_REQUIRE_QUIESCENCE      0x00010000
+#define RADEON_UPLOAD_ZBIAS            0x00020000      /* version 1.2 and newer */
+#define RADEON_UPLOAD_ALL              0x003effff
+#define RADEON_UPLOAD_CONTEXT_ALL       0x003e01ff
+
+/* New style per-packet identifiers for use in cmd_buffer ioctl with
+ * the RADEON_EMIT_PACKET command.  Comments relate new packets to old
+ * state bits and the packet size:
+ */
+#define RADEON_EMIT_PP_MISC                         0  /* context/7 */
+#define RADEON_EMIT_PP_CNTL                         1  /* context/3 */
+#define RADEON_EMIT_RB3D_COLORPITCH                 2  /* context/1 */
+#define RADEON_EMIT_RE_LINE_PATTERN                 3  /* line/2 */
+#define RADEON_EMIT_SE_LINE_WIDTH                   4  /* line/1 */
+#define RADEON_EMIT_PP_LUM_MATRIX                   5  /* bumpmap/1 */
+#define RADEON_EMIT_PP_ROT_MATRIX_0                 6  /* bumpmap/2 */
+#define RADEON_EMIT_RB3D_STENCILREFMASK             7  /* masks/3 */
+#define RADEON_EMIT_SE_VPORT_XSCALE                 8  /* viewport/6 */
+#define RADEON_EMIT_SE_CNTL                         9  /* setup/2 */
+#define RADEON_EMIT_SE_CNTL_STATUS                  10 /* setup/1 */
+#define RADEON_EMIT_RE_MISC                         11 /* misc/1 */
+#define RADEON_EMIT_PP_TXFILTER_0                   12 /* tex0/6 */
+#define RADEON_EMIT_PP_BORDER_COLOR_0               13 /* tex0/1 */
+#define RADEON_EMIT_PP_TXFILTER_1                   14 /* tex1/6 */
+#define RADEON_EMIT_PP_BORDER_COLOR_1               15 /* tex1/1 */
+#define RADEON_EMIT_PP_TXFILTER_2                   16 /* tex2/6 */
+#define RADEON_EMIT_PP_BORDER_COLOR_2               17 /* tex2/1 */
+#define RADEON_EMIT_SE_ZBIAS_FACTOR                 18 /* zbias/2 */
+#define RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT           19 /* tcl/11 */
+#define RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED   20 /* material/17 */
+#define R200_EMIT_PP_TXCBLEND_0                     21 /* tex0/4 */
+#define R200_EMIT_PP_TXCBLEND_1                     22 /* tex1/4 */
+#define R200_EMIT_PP_TXCBLEND_2                     23 /* tex2/4 */
+#define R200_EMIT_PP_TXCBLEND_3                     24 /* tex3/4 */
+#define R200_EMIT_PP_TXCBLEND_4                     25 /* tex4/4 */
+#define R200_EMIT_PP_TXCBLEND_5                     26 /* tex5/4 */
+#define R200_EMIT_PP_TXCBLEND_6                     27 /* /4 */
+#define R200_EMIT_PP_TXCBLEND_7                     28 /* /4 */
+#define R200_EMIT_TCL_LIGHT_MODEL_CTL_0             29 /* tcl/7 */
+#define R200_EMIT_TFACTOR_0                         30 /* tf/7 */
+#define R200_EMIT_VTX_FMT_0                         31 /* vtx/5 */
+#define R200_EMIT_VAP_CTL                           32 /* vap/1 */
+#define R200_EMIT_MATRIX_SELECT_0                   33 /* msl/5 */
+#define R200_EMIT_TEX_PROC_CTL_2                    34 /* tcg/5 */
+#define R200_EMIT_TCL_UCP_VERT_BLEND_CTL            35 /* tcl/1 */
+#define R200_EMIT_PP_TXFILTER_0                     36 /* tex0/6 */
+#define R200_EMIT_PP_TXFILTER_1                     37 /* tex1/6 */
+#define R200_EMIT_PP_TXFILTER_2                     38 /* tex2/6 */
+#define R200_EMIT_PP_TXFILTER_3                     39 /* tex3/6 */
+#define R200_EMIT_PP_TXFILTER_4                     40 /* tex4/6 */
+#define R200_EMIT_PP_TXFILTER_5                     41 /* tex5/6 */
+#define R200_EMIT_PP_TXOFFSET_0                     42 /* tex0/1 */
+#define R200_EMIT_PP_TXOFFSET_1                     43 /* tex1/1 */
+#define R200_EMIT_PP_TXOFFSET_2                     44 /* tex2/1 */
+#define R200_EMIT_PP_TXOFFSET_3                     45 /* tex3/1 */
+#define R200_EMIT_PP_TXOFFSET_4                     46 /* tex4/1 */
+#define R200_EMIT_PP_TXOFFSET_5                     47 /* tex5/1 */
+#define R200_EMIT_VTE_CNTL                          48 /* vte/1 */
+#define R200_EMIT_OUTPUT_VTX_COMP_SEL               49 /* vtx/1 */
+#define R200_EMIT_PP_TAM_DEBUG3                     50 /* tam/1 */
+#define R200_EMIT_PP_CNTL_X                         51 /* cst/1 */
+#define R200_EMIT_RB3D_DEPTHXY_OFFSET               52 /* cst/1 */
+#define R200_EMIT_RE_AUX_SCISSOR_CNTL               53 /* cst/1 */
+#define R200_EMIT_RE_SCISSOR_TL_0                   54 /* cst/2 */
+#define R200_EMIT_RE_SCISSOR_TL_1                   55 /* cst/2 */
+#define R200_EMIT_RE_SCISSOR_TL_2                   56 /* cst/2 */
+#define R200_EMIT_SE_VAP_CNTL_STATUS                57 /* cst/1 */
+#define R200_EMIT_SE_VTX_STATE_CNTL                 58 /* cst/1 */
+#define R200_EMIT_RE_POINTSIZE                      59 /* cst/1 */
+#define R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0       60 /* cst/4 */
+#define R200_EMIT_PP_CUBIC_FACES_0                  61
+#define R200_EMIT_PP_CUBIC_OFFSETS_0                62
+#define R200_EMIT_PP_CUBIC_FACES_1                  63
+#define R200_EMIT_PP_CUBIC_OFFSETS_1                64
+#define R200_EMIT_PP_CUBIC_FACES_2                  65
+#define R200_EMIT_PP_CUBIC_OFFSETS_2                66
+#define R200_EMIT_PP_CUBIC_FACES_3                  67
+#define R200_EMIT_PP_CUBIC_OFFSETS_3                68
+#define R200_EMIT_PP_CUBIC_FACES_4                  69
+#define R200_EMIT_PP_CUBIC_OFFSETS_4                70
+#define R200_EMIT_PP_CUBIC_FACES_5                  71
+#define R200_EMIT_PP_CUBIC_OFFSETS_5                72
+#define RADEON_EMIT_PP_TEX_SIZE_0                   73
+#define RADEON_EMIT_PP_TEX_SIZE_1                   74
+#define RADEON_EMIT_PP_TEX_SIZE_2                   75
+#define R200_EMIT_RB3D_BLENDCOLOR                   76
+#define R200_EMIT_TCL_POINT_SPRITE_CNTL             77
+#define RADEON_EMIT_PP_CUBIC_FACES_0                78
+#define RADEON_EMIT_PP_CUBIC_OFFSETS_T0             79
+#define RADEON_EMIT_PP_CUBIC_FACES_1                80
+#define RADEON_EMIT_PP_CUBIC_OFFSETS_T1             81
+#define RADEON_EMIT_PP_CUBIC_FACES_2                82
+#define RADEON_EMIT_PP_CUBIC_OFFSETS_T2             83
+#define R200_EMIT_PP_TRI_PERF_CNTL                  84
+#define R200_EMIT_PP_AFS_0                          85
+#define R200_EMIT_PP_AFS_1                          86
+#define R200_EMIT_ATF_TFACTOR                       87
+#define R200_EMIT_PP_TXCTLALL_0                     88
+#define R200_EMIT_PP_TXCTLALL_1                     89
+#define R200_EMIT_PP_TXCTLALL_2                     90
+#define R200_EMIT_PP_TXCTLALL_3                     91
+#define R200_EMIT_PP_TXCTLALL_4                     92
+#define R200_EMIT_PP_TXCTLALL_5                     93
+#define R200_EMIT_VAP_PVS_CNTL                      94
+#define RADEON_MAX_STATE_PACKETS                    95
+
+/* Commands understood by cmd_buffer ioctl.  More can be added but
+ * obviously these can't be removed or changed:
+ */
+#define RADEON_CMD_PACKET      1       /* emit one of the register packets above */
+#define RADEON_CMD_SCALARS     2       /* emit scalar data */
+#define RADEON_CMD_VECTORS     3       /* emit vector data */
+#define RADEON_CMD_DMA_DISCARD 4       /* discard current dma buf */
+#define RADEON_CMD_PACKET3     5       /* emit hw packet */
+#define RADEON_CMD_PACKET3_CLIP 6      /* emit hw packet wrapped in cliprects */
+#define RADEON_CMD_SCALARS2     7      /* r200 stopgap */
+#define RADEON_CMD_WAIT         8      /* emit hw wait commands -- note:
+                                        *  doesn't make the cpu wait, just
+                                        *  the graphics hardware */
+#define RADEON_CMD_VECLINEAR   9       /* another r200 stopgap */
+
+typedef union {
+       int i;
+       struct {
+               unsigned char cmd_type, pad0, pad1, pad2;
+       } header;
+       struct {
+               unsigned char cmd_type, packet_id, pad0, pad1;
+       } packet;
+       struct {
+               unsigned char cmd_type, offset, stride, count;
+       } scalars;
+       struct {
+               unsigned char cmd_type, offset, stride, count;
+       } vectors;
+       struct {
+               unsigned char cmd_type, addr_lo, addr_hi, count;
+       } veclinear;
+       struct {
+               unsigned char cmd_type, buf_idx, pad0, pad1;
+       } dma;
+       struct {
+               unsigned char cmd_type, flags, pad0, pad1;
+       } wait;
+} drm_radeon_cmd_header_t;
+
+#define RADEON_WAIT_2D  0x1
+#define RADEON_WAIT_3D  0x2
+
+/* Allowed parameters for R300_CMD_PACKET3
+ */
+#define R300_CMD_PACKET3_CLEAR         0
+#define R300_CMD_PACKET3_RAW           1
+
+/* Commands understood by cmd_buffer ioctl for R300.
+ * The interface has not been stabilized, so some of these may be removed
+ * and eventually reordered before stabilization.
+ */
+#define R300_CMD_PACKET0               1
+#define R300_CMD_VPU                   2       /* emit vertex program upload */
+#define R300_CMD_PACKET3               3       /* emit a packet3 */
+#define R300_CMD_END3D                 4       /* emit sequence ending 3d rendering */
+#define R300_CMD_CP_DELAY              5
+#define R300_CMD_DMA_DISCARD           6
+#define R300_CMD_WAIT                  7
+#      define R300_WAIT_2D             0x1
+#      define R300_WAIT_3D             0x2
+/* these two defines are DOING IT WRONG - however
+ * we have userspace which relies on using these.
+ * The wait interface is backwards compat new 
+ * code should use the NEW_WAIT defines below
+ * THESE ARE NOT BIT FIELDS
+ */
+#      define R300_WAIT_2D_CLEAN       0x3
+#      define R300_WAIT_3D_CLEAN       0x4
+
+#      define R300_NEW_WAIT_2D_3D      0x3
+#      define R300_NEW_WAIT_2D_2D_CLEAN        0x4
+#      define R300_NEW_WAIT_3D_3D_CLEAN        0x6
+#      define R300_NEW_WAIT_2D_2D_CLEAN_3D_3D_CLEAN    0x8
+
+#define R300_CMD_SCRATCH               8
+#define R300_CMD_R500FP                 9
+
+typedef union {
+       unsigned int u;
+       struct {
+               unsigned char cmd_type, pad0, pad1, pad2;
+       } header;
+       struct {
+               unsigned char cmd_type, count, reglo, reghi;
+       } packet0;
+       struct {
+               unsigned char cmd_type, count, adrlo, adrhi;
+       } vpu;
+       struct {
+               unsigned char cmd_type, packet, pad0, pad1;
+       } packet3;
+       struct {
+               unsigned char cmd_type, packet;
+               unsigned short count;   /* amount of packet2 to emit */
+       } delay;
+       struct {
+               unsigned char cmd_type, buf_idx, pad0, pad1;
+       } dma;
+       struct {
+               unsigned char cmd_type, flags, pad0, pad1;
+       } wait;
+       struct {
+               unsigned char cmd_type, reg, n_bufs, flags;
+       } scratch;
+       struct {
+               unsigned char cmd_type, count, adrlo, adrhi_flags;
+       } r500fp;
+} drm_r300_cmd_header_t;
+
+#define RADEON_FRONT                   0x1
+#define RADEON_BACK                    0x2
+#define RADEON_DEPTH                   0x4
+#define RADEON_STENCIL                 0x8
+#define RADEON_CLEAR_FASTZ             0x80000000
+#define RADEON_USE_HIERZ               0x40000000
+#define RADEON_USE_COMP_ZBUF           0x20000000
+
+#define R500FP_CONSTANT_TYPE  (1 << 1)
+#define R500FP_CONSTANT_CLAMP (1 << 2)
+
+/* Primitive types
+ */
+#define RADEON_POINTS                  0x1
+#define RADEON_LINES                   0x2
+#define RADEON_LINE_STRIP              0x3
+#define RADEON_TRIANGLES               0x4
+#define RADEON_TRIANGLE_FAN            0x5
+#define RADEON_TRIANGLE_STRIP          0x6
+
+/* Vertex/indirect buffer size
+ */
+#define RADEON_BUFFER_SIZE             65536
+
+/* Byte offsets for indirect buffer data
+ */
+#define RADEON_INDEX_PRIM_OFFSET       20
+
+#define RADEON_SCRATCH_REG_OFFSET      32
+
+#define RADEON_NR_SAREA_CLIPRECTS      12
+
+/* There are 2 heaps (local/GART).  Each region within a heap is a
+ * minimum of 64k, and there are at most 64 of them per heap.
+ */
+#define RADEON_LOCAL_TEX_HEAP          0
+#define RADEON_GART_TEX_HEAP           1
+#define RADEON_NR_TEX_HEAPS            2
+#define RADEON_NR_TEX_REGIONS          64
+#define RADEON_LOG_TEX_GRANULARITY     16
+
+#define RADEON_MAX_TEXTURE_LEVELS      12
+#define RADEON_MAX_TEXTURE_UNITS       3
+
+#define RADEON_MAX_SURFACES            8
+
+/* Blits have strict offset rules.  All blit offset must be aligned on
+ * a 1K-byte boundary.
+ */
+#define RADEON_OFFSET_SHIFT             10
+#define RADEON_OFFSET_ALIGN             (1 << RADEON_OFFSET_SHIFT)
+#define RADEON_OFFSET_MASK              (RADEON_OFFSET_ALIGN - 1)
+
+#endif                         /* __RADEON_SAREA_DEFINES__ */
+
+typedef struct {
+       unsigned int red;
+       unsigned int green;
+       unsigned int blue;
+       unsigned int alpha;
+} radeon_color_regs_t;
+
+typedef struct {
+       /* Context state */
+       unsigned int pp_misc;   /* 0x1c14 */
+       unsigned int pp_fog_color;
+       unsigned int re_solid_color;
+       unsigned int rb3d_blendcntl;
+       unsigned int rb3d_depthoffset;
+       unsigned int rb3d_depthpitch;
+       unsigned int rb3d_zstencilcntl;
+
+       unsigned int pp_cntl;   /* 0x1c38 */
+       unsigned int rb3d_cntl;
+       unsigned int rb3d_coloroffset;
+       unsigned int re_width_height;
+       unsigned int rb3d_colorpitch;
+       unsigned int se_cntl;
+
+       /* Vertex format state */
+       unsigned int se_coord_fmt;      /* 0x1c50 */
+
+       /* Line state */
+       unsigned int re_line_pattern;   /* 0x1cd0 */
+       unsigned int re_line_state;
+
+       unsigned int se_line_width;     /* 0x1db8 */
+
+       /* Bumpmap state */
+       unsigned int pp_lum_matrix;     /* 0x1d00 */
+
+       unsigned int pp_rot_matrix_0;   /* 0x1d58 */
+       unsigned int pp_rot_matrix_1;
+
+       /* Mask state */
+       unsigned int rb3d_stencilrefmask;       /* 0x1d7c */
+       unsigned int rb3d_ropcntl;
+       unsigned int rb3d_planemask;
+
+       /* Viewport state */
+       unsigned int se_vport_xscale;   /* 0x1d98 */
+       unsigned int se_vport_xoffset;
+       unsigned int se_vport_yscale;
+       unsigned int se_vport_yoffset;
+       unsigned int se_vport_zscale;
+       unsigned int se_vport_zoffset;
+
+       /* Setup state */
+       unsigned int se_cntl_status;    /* 0x2140 */
+
+       /* Misc state */
+       unsigned int re_top_left;       /* 0x26c0 */
+       unsigned int re_misc;
+} drm_radeon_context_regs_t;
+
+typedef struct {
+       /* Zbias state */
+       unsigned int se_zbias_factor;   /* 0x1dac */
+       unsigned int se_zbias_constant;
+} drm_radeon_context2_regs_t;
+
+/* Setup registers for each texture unit
+ */
+typedef struct {
+       unsigned int pp_txfilter;
+       unsigned int pp_txformat;
+       unsigned int pp_txoffset;
+       unsigned int pp_txcblend;
+       unsigned int pp_txablend;
+       unsigned int pp_tfactor;
+       unsigned int pp_border_color;
+} drm_radeon_texture_regs_t;
+
+typedef struct {
+       unsigned int start;
+       unsigned int finish;
+       unsigned int prim:8;
+       unsigned int stateidx:8;
+       unsigned int numverts:16;       /* overloaded as offset/64 for elt prims */
+       unsigned int vc_format; /* vertex format */
+} drm_radeon_prim_t;
+
+typedef struct {
+       drm_radeon_context_regs_t context;
+       drm_radeon_texture_regs_t tex[RADEON_MAX_TEXTURE_UNITS];
+       drm_radeon_context2_regs_t context2;
+       unsigned int dirty;
+} drm_radeon_state_t;
+
+typedef struct {
+       /* The channel for communication of state information to the
+        * kernel on firing a vertex buffer with either of the
+        * obsoleted vertex/index ioctls.
+        */
+       drm_radeon_context_regs_t context_state;
+       drm_radeon_texture_regs_t tex_state[RADEON_MAX_TEXTURE_UNITS];
+       unsigned int dirty;
+       unsigned int vertsize;
+       unsigned int vc_format;
+
+       /* The current cliprects, or a subset thereof.
+        */
+       struct drm_clip_rect boxes[RADEON_NR_SAREA_CLIPRECTS];
+       unsigned int nbox;
+
+       /* Counters for client-side throttling of rendering clients.
+        */
+       unsigned int last_frame;
+       unsigned int last_dispatch;
+       unsigned int last_clear;
+
+       struct drm_tex_region tex_list[RADEON_NR_TEX_HEAPS][RADEON_NR_TEX_REGIONS +
+                                                      1];
+       unsigned int tex_age[RADEON_NR_TEX_HEAPS];
+       int ctx_owner;
+       int pfState;            /* number of 3d windows (0,1,2ormore) */
+       int pfCurrentPage;      /* which buffer is being displayed? */
+       int crtc2_base;         /* CRTC2 frame offset */
+       int tiling_enabled;     /* set by drm, read by 2d + 3d clients */
+} drm_radeon_sarea_t;
+
+/* WARNING: If you change any of these defines, make sure to change the
+ * defines in the Xserver file (xf86drmRadeon.h)
+ *
+ * KW: actually it's illegal to change any of this (backwards compatibility).
+ */
+
+/* Radeon specific ioctls
+ * The device specific ioctl range is 0x40 to 0x79.
+ */
+#define DRM_RADEON_CP_INIT    0x00
+#define DRM_RADEON_CP_START   0x01
+#define DRM_RADEON_CP_STOP    0x02
+#define DRM_RADEON_CP_RESET   0x03
+#define DRM_RADEON_CP_IDLE    0x04
+#define DRM_RADEON_RESET      0x05
+#define DRM_RADEON_FULLSCREEN 0x06
+#define DRM_RADEON_SWAP       0x07
+#define DRM_RADEON_CLEAR      0x08
+#define DRM_RADEON_VERTEX     0x09
+#define DRM_RADEON_INDICES    0x0A
+#define DRM_RADEON_NOT_USED
+#define DRM_RADEON_STIPPLE    0x0C
+#define DRM_RADEON_INDIRECT   0x0D
+#define DRM_RADEON_TEXTURE    0x0E
+#define DRM_RADEON_VERTEX2    0x0F
+#define DRM_RADEON_CMDBUF     0x10
+#define DRM_RADEON_GETPARAM   0x11
+#define DRM_RADEON_FLIP       0x12
+#define DRM_RADEON_ALLOC      0x13
+#define DRM_RADEON_FREE       0x14
+#define DRM_RADEON_INIT_HEAP  0x15
+#define DRM_RADEON_IRQ_EMIT   0x16
+#define DRM_RADEON_IRQ_WAIT   0x17
+#define DRM_RADEON_CP_RESUME  0x18
+#define DRM_RADEON_SETPARAM   0x19
+#define DRM_RADEON_SURF_ALLOC 0x1a
+#define DRM_RADEON_SURF_FREE  0x1b
+
+#define DRM_IOCTL_RADEON_CP_INIT    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_INIT, drm_radeon_init_t)
+#define DRM_IOCTL_RADEON_CP_START   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_START)
+#define DRM_IOCTL_RADEON_CP_STOP    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CP_STOP, drm_radeon_cp_stop_t)
+#define DRM_IOCTL_RADEON_CP_RESET   DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_RESET)
+#define DRM_IOCTL_RADEON_CP_IDLE    DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_IDLE)
+#define DRM_IOCTL_RADEON_RESET      DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_RESET)
+#define DRM_IOCTL_RADEON_FULLSCREEN DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_FULLSCREEN, drm_radeon_fullscreen_t)
+#define DRM_IOCTL_RADEON_SWAP       DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_SWAP)
+#define DRM_IOCTL_RADEON_CLEAR      DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CLEAR, drm_radeon_clear_t)
+#define DRM_IOCTL_RADEON_VERTEX     DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_VERTEX, drm_radeon_vertex_t)
+#define DRM_IOCTL_RADEON_INDICES    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_INDICES, drm_radeon_indices_t)
+#define DRM_IOCTL_RADEON_STIPPLE    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_STIPPLE, drm_radeon_stipple_t)
+#define DRM_IOCTL_RADEON_INDIRECT   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_INDIRECT, drm_radeon_indirect_t)
+#define DRM_IOCTL_RADEON_TEXTURE    DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_TEXTURE, drm_radeon_texture_t)
+#define DRM_IOCTL_RADEON_VERTEX2    DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_VERTEX2, drm_radeon_vertex2_t)
+#define DRM_IOCTL_RADEON_CMDBUF     DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_CMDBUF, drm_radeon_cmd_buffer_t)
+#define DRM_IOCTL_RADEON_GETPARAM   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_GETPARAM, drm_radeon_getparam_t)
+#define DRM_IOCTL_RADEON_FLIP       DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_FLIP)
+#define DRM_IOCTL_RADEON_ALLOC      DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_ALLOC, drm_radeon_mem_alloc_t)
+#define DRM_IOCTL_RADEON_FREE       DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_FREE, drm_radeon_mem_free_t)
+#define DRM_IOCTL_RADEON_INIT_HEAP  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_INIT_HEAP, drm_radeon_mem_init_heap_t)
+#define DRM_IOCTL_RADEON_IRQ_EMIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_RADEON_IRQ_EMIT, drm_radeon_irq_emit_t)
+#define DRM_IOCTL_RADEON_IRQ_WAIT   DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_IRQ_WAIT, drm_radeon_irq_wait_t)
+#define DRM_IOCTL_RADEON_CP_RESUME  DRM_IO(  DRM_COMMAND_BASE + DRM_RADEON_CP_RESUME)
+#define DRM_IOCTL_RADEON_SETPARAM   DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SETPARAM, drm_radeon_setparam_t)
+#define DRM_IOCTL_RADEON_SURF_ALLOC DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_ALLOC, drm_radeon_surface_alloc_t)
+#define DRM_IOCTL_RADEON_SURF_FREE  DRM_IOW( DRM_COMMAND_BASE + DRM_RADEON_SURF_FREE, drm_radeon_surface_free_t)
+
+typedef struct drm_radeon_init {
+       enum {
+               RADEON_INIT_CP = 0x01,
+               RADEON_CLEANUP_CP = 0x02,
+               RADEON_INIT_R200_CP = 0x03,
+               RADEON_INIT_R300_CP = 0x04
+       } func;
+       unsigned long sarea_priv_offset;
+       int is_pci;
+       int cp_mode;
+       int gart_size;
+       int ring_size;
+       int usec_timeout;
+
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+
+       unsigned long fb_offset;
+       unsigned long mmio_offset;
+       unsigned long ring_offset;
+       unsigned long ring_rptr_offset;
+       unsigned long buffers_offset;
+       unsigned long gart_textures_offset;
+} drm_radeon_init_t;
+
+typedef struct drm_radeon_cp_stop {
+       int flush;
+       int idle;
+} drm_radeon_cp_stop_t;
+
+typedef struct drm_radeon_fullscreen {
+       enum {
+               RADEON_INIT_FULLSCREEN = 0x01,
+               RADEON_CLEANUP_FULLSCREEN = 0x02
+       } func;
+} drm_radeon_fullscreen_t;
+
+#define CLEAR_X1       0
+#define CLEAR_Y1       1
+#define CLEAR_X2       2
+#define CLEAR_Y2       3
+#define CLEAR_DEPTH    4
+
+typedef union drm_radeon_clear_rect {
+       float f[5];
+       unsigned int ui[5];
+} drm_radeon_clear_rect_t;
+
+typedef struct drm_radeon_clear {
+       unsigned int flags;
+       unsigned int clear_color;
+       unsigned int clear_depth;
+       unsigned int color_mask;
+       unsigned int depth_mask;        /* misnamed field:  should be stencil */
+       drm_radeon_clear_rect_t __user *depth_boxes;
+} drm_radeon_clear_t;
+
+typedef struct drm_radeon_vertex {
+       int prim;
+       int idx;                /* Index of vertex buffer */
+       int count;              /* Number of vertices in buffer */
+       int discard;            /* Client finished with buffer? */
+} drm_radeon_vertex_t;
+
+typedef struct drm_radeon_indices {
+       int prim;
+       int idx;
+       int start;
+       int end;
+       int discard;            /* Client finished with buffer? */
+} drm_radeon_indices_t;
+
+/* v1.2 - obsoletes drm_radeon_vertex and drm_radeon_indices
+ *      - allows multiple primitives and state changes in a single ioctl
+ *      - supports driver change to emit native primitives
+ */
+typedef struct drm_radeon_vertex2 {
+       int idx;                /* Index of vertex buffer */
+       int discard;            /* Client finished with buffer? */
+       int nr_states;
+       drm_radeon_state_t __user *state;
+       int nr_prims;
+       drm_radeon_prim_t __user *prim;
+} drm_radeon_vertex2_t;
+
+/* v1.3 - obsoletes drm_radeon_vertex2
+ *      - allows arbitarily large cliprect list
+ *      - allows updating of tcl packet, vector and scalar state
+ *      - allows memory-efficient description of state updates
+ *      - allows state to be emitted without a primitive
+ *           (for clears, ctx switches)
+ *      - allows more than one dma buffer to be referenced per ioctl
+ *      - supports tcl driver
+ *      - may be extended in future versions with new cmd types, packets
+ */
+typedef struct drm_radeon_cmd_buffer {
+       int bufsz;
+       char __user *buf;
+       int nbox;
+       struct drm_clip_rect __user *boxes;
+} drm_radeon_cmd_buffer_t;
+
+typedef struct drm_radeon_tex_image {
+       unsigned int x, y;      /* Blit coordinates */
+       unsigned int width, height;
+       const void __user *data;
+} drm_radeon_tex_image_t;
+
+typedef struct drm_radeon_texture {
+       unsigned int offset;
+       int pitch;
+       int format;
+       int width;              /* Texture image coordinates */
+       int height;
+       drm_radeon_tex_image_t __user *image;
+} drm_radeon_texture_t;
+
+typedef struct drm_radeon_stipple {
+       unsigned int __user *mask;
+} drm_radeon_stipple_t;
+
+typedef struct drm_radeon_indirect {
+       int idx;
+       int start;
+       int end;
+       int discard;
+} drm_radeon_indirect_t;
+
+/* enum for card type parameters */
+#define RADEON_CARD_PCI 0
+#define RADEON_CARD_AGP 1
+#define RADEON_CARD_PCIE 2
+
+/* 1.3: An ioctl to get parameters that aren't available to the 3d
+ * client any other way.
+ */
+#define RADEON_PARAM_GART_BUFFER_OFFSET    1   /* card offset of 1st GART buffer */
+#define RADEON_PARAM_LAST_FRAME            2
+#define RADEON_PARAM_LAST_DISPATCH         3
+#define RADEON_PARAM_LAST_CLEAR            4
+/* Added with DRM version 1.6. */
+#define RADEON_PARAM_IRQ_NR                5
+#define RADEON_PARAM_GART_BASE             6   /* card offset of GART base */
+/* Added with DRM version 1.8. */
+#define RADEON_PARAM_REGISTER_HANDLE       7   /* for drmMap() */
+#define RADEON_PARAM_STATUS_HANDLE         8
+#define RADEON_PARAM_SAREA_HANDLE          9
+#define RADEON_PARAM_GART_TEX_HANDLE       10
+#define RADEON_PARAM_SCRATCH_OFFSET        11
+#define RADEON_PARAM_CARD_TYPE             12
+#define RADEON_PARAM_VBLANK_CRTC           13   /* VBLANK CRTC */
+#define RADEON_PARAM_FB_LOCATION           14   /* FB location */
+#define RADEON_PARAM_NUM_GB_PIPES          15   /* num GB pipes */
+
+typedef struct drm_radeon_getparam {
+       int param;
+       void __user *value;
+} drm_radeon_getparam_t;
+
+/* 1.6: Set up a memory manager for regions of shared memory:
+ */
+#define RADEON_MEM_REGION_GART 1
+#define RADEON_MEM_REGION_FB   2
+
+typedef struct drm_radeon_mem_alloc {
+       int region;
+       int alignment;
+       int size;
+       int __user *region_offset;      /* offset from start of fb or GART */
+} drm_radeon_mem_alloc_t;
+
+typedef struct drm_radeon_mem_free {
+       int region;
+       int region_offset;
+} drm_radeon_mem_free_t;
+
+typedef struct drm_radeon_mem_init_heap {
+       int region;
+       int size;
+       int start;
+} drm_radeon_mem_init_heap_t;
+
+/* 1.6: Userspace can request & wait on irq's:
+ */
+typedef struct drm_radeon_irq_emit {
+       int __user *irq_seq;
+} drm_radeon_irq_emit_t;
+
+typedef struct drm_radeon_irq_wait {
+       int irq_seq;
+} drm_radeon_irq_wait_t;
+
+/* 1.10: Clients tell the DRM where they think the framebuffer is located in
+ * the card's address space, via a new generic ioctl to set parameters
+ */
+
+typedef struct drm_radeon_setparam {
+       unsigned int param;
+       int64_t value;
+} drm_radeon_setparam_t;
+
+#define RADEON_SETPARAM_FB_LOCATION    1       /* determined framebuffer location */
+#define RADEON_SETPARAM_SWITCH_TILING  2       /* enable/disable color tiling */
+#define RADEON_SETPARAM_PCIGART_LOCATION 3     /* PCI Gart Location */
+#define RADEON_SETPARAM_NEW_MEMMAP 4           /* Use new memory map */
+#define RADEON_SETPARAM_PCIGART_TABLE_SIZE 5    /* PCI GART Table Size */
+#define RADEON_SETPARAM_VBLANK_CRTC 6           /* VBLANK CRTC */
+/* 1.14: Clients can allocate/free a surface
+ */
+typedef struct drm_radeon_surface_alloc {
+       unsigned int address;
+       unsigned int size;
+       unsigned int flags;
+} drm_radeon_surface_alloc_t;
+
+typedef struct drm_radeon_surface_free {
+       unsigned int address;
+} drm_radeon_surface_free_t;
+
+#define        DRM_RADEON_VBLANK_CRTC1         1
+#define        DRM_RADEON_VBLANK_CRTC2         2
+
+#endif
diff --git a/include/drm/savage_drm.h b/include/drm/savage_drm.h
new file mode 100644 (file)
index 0000000..8a576ef
--- /dev/null
@@ -0,0 +1,210 @@
+/* savage_drm.h -- Public header for the savage driver
+ *
+ * Copyright 2004  Felix Kuehling
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __SAVAGE_DRM_H__
+#define __SAVAGE_DRM_H__
+
+#ifndef __SAVAGE_SAREA_DEFINES__
+#define __SAVAGE_SAREA_DEFINES__
+
+/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
+ * regions, subject to a minimum region size of (1<<16) == 64k.
+ *
+ * Clients may subdivide regions internally, but when sharing between
+ * clients, the region size is the minimum granularity.
+ */
+
+#define SAVAGE_CARD_HEAP               0
+#define SAVAGE_AGP_HEAP                        1
+#define SAVAGE_NR_TEX_HEAPS            2
+#define SAVAGE_NR_TEX_REGIONS          16
+#define SAVAGE_LOG_MIN_TEX_REGION_SIZE 16
+
+#endif                         /* __SAVAGE_SAREA_DEFINES__ */
+
+typedef struct _drm_savage_sarea {
+       /* LRU lists for texture memory in agp space and on the card.
+        */
+       struct drm_tex_region texList[SAVAGE_NR_TEX_HEAPS][SAVAGE_NR_TEX_REGIONS +
+                                                     1];
+       unsigned int texAge[SAVAGE_NR_TEX_HEAPS];
+
+       /* Mechanism to validate card state.
+        */
+       int ctxOwner;
+} drm_savage_sarea_t, *drm_savage_sarea_ptr;
+
+/* Savage-specific ioctls
+ */
+#define DRM_SAVAGE_BCI_INIT            0x00
+#define DRM_SAVAGE_BCI_CMDBUF           0x01
+#define DRM_SAVAGE_BCI_EVENT_EMIT      0x02
+#define DRM_SAVAGE_BCI_EVENT_WAIT      0x03
+
+#define DRM_IOCTL_SAVAGE_INIT          DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_INIT, drm_savage_init_t)
+#define DRM_IOCTL_SAVAGE_CMDBUF                DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_CMDBUF, drm_savage_cmdbuf_t)
+#define DRM_IOCTL_SAVAGE_EVENT_EMIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_SAVAGE_BCI_EVENT_EMIT, drm_savage_event_emit_t)
+#define DRM_IOCTL_SAVAGE_EVENT_WAIT    DRM_IOW( DRM_COMMAND_BASE + DRM_SAVAGE_BCI_EVENT_WAIT, drm_savage_event_wait_t)
+
+#define SAVAGE_DMA_PCI 1
+#define SAVAGE_DMA_AGP 3
+typedef struct drm_savage_init {
+       enum {
+               SAVAGE_INIT_BCI = 1,
+               SAVAGE_CLEANUP_BCI = 2
+       } func;
+       unsigned int sarea_priv_offset;
+
+       /* some parameters */
+       unsigned int cob_size;
+       unsigned int bci_threshold_lo, bci_threshold_hi;
+       unsigned int dma_type;
+
+       /* frame buffer layout */
+       unsigned int fb_bpp;
+       unsigned int front_offset, front_pitch;
+       unsigned int back_offset, back_pitch;
+       unsigned int depth_bpp;
+       unsigned int depth_offset, depth_pitch;
+
+       /* local textures */
+       unsigned int texture_offset;
+       unsigned int texture_size;
+
+       /* physical locations of non-permanent maps */
+       unsigned long status_offset;
+       unsigned long buffers_offset;
+       unsigned long agp_textures_offset;
+       unsigned long cmd_dma_offset;
+} drm_savage_init_t;
+
+typedef union drm_savage_cmd_header drm_savage_cmd_header_t;
+typedef struct drm_savage_cmdbuf {
+       /* command buffer in client's address space */
+       drm_savage_cmd_header_t __user *cmd_addr;
+       unsigned int size;      /* size of the command buffer in 64bit units */
+
+       unsigned int dma_idx;   /* DMA buffer index to use */
+       int discard;            /* discard DMA buffer when done */
+       /* vertex buffer in client's address space */
+       unsigned int __user *vb_addr;
+       unsigned int vb_size;   /* size of client vertex buffer in bytes */
+       unsigned int vb_stride; /* stride of vertices in 32bit words */
+       /* boxes in client's address space */
+       struct drm_clip_rect __user *box_addr;
+       unsigned int nbox;      /* number of clipping boxes */
+} drm_savage_cmdbuf_t;
+
+#define SAVAGE_WAIT_2D  0x1    /* wait for 2D idle before updating event tag */
+#define SAVAGE_WAIT_3D  0x2    /* wait for 3D idle before updating event tag */
+#define SAVAGE_WAIT_IRQ 0x4    /* emit or wait for IRQ, not implemented yet */
+typedef struct drm_savage_event {
+       unsigned int count;
+       unsigned int flags;
+} drm_savage_event_emit_t, drm_savage_event_wait_t;
+
+/* Commands for the cmdbuf ioctl
+ */
+#define SAVAGE_CMD_STATE       0       /* a range of state registers */
+#define SAVAGE_CMD_DMA_PRIM    1       /* vertices from DMA buffer */
+#define SAVAGE_CMD_VB_PRIM     2       /* vertices from client vertex buffer */
+#define SAVAGE_CMD_DMA_IDX     3       /* indexed vertices from DMA buffer */
+#define SAVAGE_CMD_VB_IDX      4       /* indexed vertices client vertex buffer */
+#define SAVAGE_CMD_CLEAR       5       /* clear buffers */
+#define SAVAGE_CMD_SWAP                6       /* swap buffers */
+
+/* Primitive types
+*/
+#define SAVAGE_PRIM_TRILIST    0       /* triangle list */
+#define SAVAGE_PRIM_TRISTRIP   1       /* triangle strip */
+#define SAVAGE_PRIM_TRIFAN     2       /* triangle fan */
+#define SAVAGE_PRIM_TRILIST_201        3       /* reorder verts for correct flat
+                                        * shading on s3d */
+
+/* Skip flags (vertex format)
+ */
+#define SAVAGE_SKIP_Z          0x01
+#define SAVAGE_SKIP_W          0x02
+#define SAVAGE_SKIP_C0         0x04
+#define SAVAGE_SKIP_C1         0x08
+#define SAVAGE_SKIP_S0         0x10
+#define SAVAGE_SKIP_T0         0x20
+#define SAVAGE_SKIP_ST0                0x30
+#define SAVAGE_SKIP_S1         0x40
+#define SAVAGE_SKIP_T1         0x80
+#define SAVAGE_SKIP_ST1                0xc0
+#define SAVAGE_SKIP_ALL_S3D    0x3f
+#define SAVAGE_SKIP_ALL_S4     0xff
+
+/* Buffer names for clear command
+ */
+#define SAVAGE_FRONT           0x1
+#define SAVAGE_BACK            0x2
+#define SAVAGE_DEPTH           0x4
+
+/* 64-bit command header
+ */
+union drm_savage_cmd_header {
+       struct {
+               unsigned char cmd;      /* command */
+               unsigned char pad0;
+               unsigned short pad1;
+               unsigned short pad2;
+               unsigned short pad3;
+       } cmd;                  /* generic */
+       struct {
+               unsigned char cmd;
+               unsigned char global;   /* need idle engine? */
+               unsigned short count;   /* number of consecutive registers */
+               unsigned short start;   /* first register */
+               unsigned short pad3;
+       } state;                /* SAVAGE_CMD_STATE */
+       struct {
+               unsigned char cmd;
+               unsigned char prim;     /* primitive type */
+               unsigned short skip;    /* vertex format (skip flags) */
+               unsigned short count;   /* number of vertices */
+               unsigned short start;   /* first vertex in DMA/vertex buffer */
+       } prim;                 /* SAVAGE_CMD_DMA_PRIM, SAVAGE_CMD_VB_PRIM */
+       struct {
+               unsigned char cmd;
+               unsigned char prim;
+               unsigned short skip;
+               unsigned short count;   /* number of indices that follow */
+               unsigned short pad3;
+       } idx;                  /* SAVAGE_CMD_DMA_IDX, SAVAGE_CMD_VB_IDX */
+       struct {
+               unsigned char cmd;
+               unsigned char pad0;
+               unsigned short pad1;
+               unsigned int flags;
+       } clear0;               /* SAVAGE_CMD_CLEAR */
+       struct {
+               unsigned int mask;
+               unsigned int value;
+       } clear1;               /* SAVAGE_CMD_CLEAR data */
+};
+
+#endif
diff --git a/include/drm/sis_drm.h b/include/drm/sis_drm.h
new file mode 100644 (file)
index 0000000..30f7b38
--- /dev/null
@@ -0,0 +1,67 @@
+/* sis_drv.h -- Private header for sis driver -*- linux-c -*- */
+/*
+ * Copyright 2005 Eric Anholt
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef __SIS_DRM_H__
+#define __SIS_DRM_H__
+
+/* SiS specific ioctls */
+#define NOT_USED_0_3
+#define DRM_SIS_FB_ALLOC       0x04
+#define DRM_SIS_FB_FREE                0x05
+#define NOT_USED_6_12
+#define DRM_SIS_AGP_INIT       0x13
+#define DRM_SIS_AGP_ALLOC      0x14
+#define DRM_SIS_AGP_FREE       0x15
+#define DRM_SIS_FB_INIT                0x16
+
+#define DRM_IOCTL_SIS_FB_ALLOC         DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_FB_ALLOC, drm_sis_mem_t)
+#define DRM_IOCTL_SIS_FB_FREE          DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_FB_FREE, drm_sis_mem_t)
+#define DRM_IOCTL_SIS_AGP_INIT         DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_AGP_INIT, drm_sis_agp_t)
+#define DRM_IOCTL_SIS_AGP_ALLOC                DRM_IOWR(DRM_COMMAND_BASE + DRM_SIS_AGP_ALLOC, drm_sis_mem_t)
+#define DRM_IOCTL_SIS_AGP_FREE         DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_AGP_FREE, drm_sis_mem_t)
+#define DRM_IOCTL_SIS_FB_INIT          DRM_IOW( DRM_COMMAND_BASE + DRM_SIS_FB_INIT, drm_sis_fb_t)
+/*
+#define DRM_IOCTL_SIS_FLIP             DRM_IOW( 0x48, drm_sis_flip_t)
+#define DRM_IOCTL_SIS_FLIP_INIT                DRM_IO(  0x49)
+#define DRM_IOCTL_SIS_FLIP_FINAL       DRM_IO(  0x50)
+*/
+
+typedef struct {
+       int context;
+       unsigned int offset;
+       unsigned int size;
+       unsigned long free;
+} drm_sis_mem_t;
+
+typedef struct {
+       unsigned int offset, size;
+} drm_sis_agp_t;
+
+typedef struct {
+       unsigned int offset, size;
+} drm_sis_fb_t;
+
+#endif                         /* __SIS_DRM_H__ */
diff --git a/include/drm/via_drm.h b/include/drm/via_drm.h
new file mode 100644 (file)
index 0000000..a3b5c10
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#ifndef _VIA_DRM_H_
+#define _VIA_DRM_H_
+
+/* WARNING: These defines must be the same as what the Xserver uses.
+ * if you change them, you must change the defines in the Xserver.
+ */
+
+#ifndef _VIA_DEFINES_
+#define _VIA_DEFINES_
+
+#ifndef __KERNEL__
+#include "via_drmclient.h"
+#endif
+
+#define VIA_NR_SAREA_CLIPRECTS         8
+#define VIA_NR_XVMC_PORTS               10
+#define VIA_NR_XVMC_LOCKS               5
+#define VIA_MAX_CACHELINE_SIZE          64
+#define XVMCLOCKPTR(saPriv,lockNo)                                     \
+       ((volatile struct drm_hw_lock *)(((((unsigned long) (saPriv)->XvMCLockArea) + \
+                                     (VIA_MAX_CACHELINE_SIZE - 1)) &   \
+                                    ~(VIA_MAX_CACHELINE_SIZE - 1)) +   \
+                                   VIA_MAX_CACHELINE_SIZE*(lockNo)))
+
+/* Each region is a minimum of 64k, and there are at most 64 of them.
+ */
+#define VIA_NR_TEX_REGIONS 64
+#define VIA_LOG_MIN_TEX_REGION_SIZE 16
+#endif
+
+#define VIA_UPLOAD_TEX0IMAGE  0x1      /* handled clientside */
+#define VIA_UPLOAD_TEX1IMAGE  0x2      /* handled clientside */
+#define VIA_UPLOAD_CTX        0x4
+#define VIA_UPLOAD_BUFFERS    0x8
+#define VIA_UPLOAD_TEX0       0x10
+#define VIA_UPLOAD_TEX1       0x20
+#define VIA_UPLOAD_CLIPRECTS  0x40
+#define VIA_UPLOAD_ALL        0xff
+
+/* VIA specific ioctls */
+#define DRM_VIA_ALLOCMEM       0x00
+#define DRM_VIA_FREEMEM                0x01
+#define DRM_VIA_AGP_INIT       0x02
+#define DRM_VIA_FB_INIT                0x03
+#define DRM_VIA_MAP_INIT       0x04
+#define DRM_VIA_DEC_FUTEX       0x05
+#define NOT_USED
+#define DRM_VIA_DMA_INIT       0x07
+#define DRM_VIA_CMDBUFFER      0x08
+#define DRM_VIA_FLUSH          0x09
+#define DRM_VIA_PCICMD         0x0a
+#define DRM_VIA_CMDBUF_SIZE    0x0b
+#define NOT_USED
+#define DRM_VIA_WAIT_IRQ        0x0d
+#define DRM_VIA_DMA_BLIT        0x0e
+#define DRM_VIA_BLIT_SYNC       0x0f
+
+#define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, drm_via_mem_t)
+#define DRM_IOCTL_VIA_FREEMEM    DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, drm_via_mem_t)
+#define DRM_IOCTL_VIA_AGP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_AGP_INIT, drm_via_agp_t)
+#define DRM_IOCTL_VIA_FB_INIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, drm_via_fb_t)
+#define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, drm_via_init_t)
+#define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_DEC_FUTEX, drm_via_futex_t)
+#define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, drm_via_dma_init_t)
+#define DRM_IOCTL_VIA_CMDBUFFER          DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
+#define DRM_IOCTL_VIA_FLUSH      DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
+#define DRM_IOCTL_VIA_PCICMD     DRM_IOW( DRM_COMMAND_BASE + DRM_VIA_PCICMD, drm_via_cmdbuffer_t)
+#define DRM_IOCTL_VIA_CMDBUF_SIZE DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_CMDBUF_SIZE, \
+                                           drm_via_cmdbuf_size_t)
+#define DRM_IOCTL_VIA_WAIT_IRQ    DRM_IOWR( DRM_COMMAND_BASE + DRM_VIA_WAIT_IRQ, drm_via_irqwait_t)
+#define DRM_IOCTL_VIA_DMA_BLIT    DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_DMA_BLIT, drm_via_dmablit_t)
+#define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
+
+/* Indices into buf.Setup where various bits of state are mirrored per
+ * context and per buffer.  These can be fired at the card as a unit,
+ * or in a piecewise fashion as required.
+ */
+
+#define VIA_TEX_SETUP_SIZE 8
+
+/* Flags for clear ioctl
+ */
+#define VIA_FRONT   0x1
+#define VIA_BACK    0x2
+#define VIA_DEPTH   0x4
+#define VIA_STENCIL 0x8
+#define VIA_MEM_VIDEO   0      /* matches drm constant */
+#define VIA_MEM_AGP     1      /* matches drm constant */
+#define VIA_MEM_SYSTEM  2
+#define VIA_MEM_MIXED   3
+#define VIA_MEM_UNKNOWN 4
+
+typedef struct {
+       uint32_t offset;
+       uint32_t size;
+} drm_via_agp_t;
+
+typedef struct {
+       uint32_t offset;
+       uint32_t size;
+} drm_via_fb_t;
+
+typedef struct {
+       uint32_t context;
+       uint32_t type;
+       uint32_t size;
+       unsigned long index;
+       unsigned long offset;
+} drm_via_mem_t;
+
+typedef struct _drm_via_init {
+       enum {
+               VIA_INIT_MAP = 0x01,
+               VIA_CLEANUP_MAP = 0x02
+       } func;
+
+       unsigned long sarea_priv_offset;
+       unsigned long fb_offset;
+       unsigned long mmio_offset;
+       unsigned long agpAddr;
+} drm_via_init_t;
+
+typedef struct _drm_via_futex {
+       enum {
+               VIA_FUTEX_WAIT = 0x00,
+               VIA_FUTEX_WAKE = 0X01
+       } func;
+       uint32_t ms;
+       uint32_t lock;
+       uint32_t val;
+} drm_via_futex_t;
+
+typedef struct _drm_via_dma_init {
+       enum {
+               VIA_INIT_DMA = 0x01,
+               VIA_CLEANUP_DMA = 0x02,
+               VIA_DMA_INITIALIZED = 0x03
+       } func;
+
+       unsigned long offset;
+       unsigned long size;
+       unsigned long reg_pause_addr;
+} drm_via_dma_init_t;
+
+typedef struct _drm_via_cmdbuffer {
+       char __user *buf;
+       unsigned long size;
+} drm_via_cmdbuffer_t;
+
+/* Warning: If you change the SAREA structure you must change the Xserver
+ * structure as well */
+
+typedef struct _drm_via_tex_region {
+       unsigned char next, prev;       /* indices to form a circular LRU  */
+       unsigned char inUse;    /* owned by a client, or free? */
+       int age;                /* tracked by clients to update local LRU's */
+} drm_via_tex_region_t;
+
+typedef struct _drm_via_sarea {
+       unsigned int dirty;
+       unsigned int nbox;
+       struct drm_clip_rect boxes[VIA_NR_SAREA_CLIPRECTS];
+       drm_via_tex_region_t texList[VIA_NR_TEX_REGIONS + 1];
+       int texAge;             /* last time texture was uploaded */
+       int ctxOwner;           /* last context to upload state */
+       int vertexPrim;
+
+       /*
+        * Below is for XvMC.
+        * We want the lock integers alone on, and aligned to, a cache line.
+        * Therefore this somewhat strange construct.
+        */
+
+       char XvMCLockArea[VIA_MAX_CACHELINE_SIZE * (VIA_NR_XVMC_LOCKS + 1)];
+
+       unsigned int XvMCDisplaying[VIA_NR_XVMC_PORTS];
+       unsigned int XvMCSubPicOn[VIA_NR_XVMC_PORTS];
+       unsigned int XvMCCtxNoGrabbed;  /* Last context to hold decoder */
+
+       /* Used by the 3d driver only at this point, for pageflipping:
+        */
+       unsigned int pfCurrentOffset;
+} drm_via_sarea_t;
+
+typedef struct _drm_via_cmdbuf_size {
+       enum {
+               VIA_CMDBUF_SPACE = 0x01,
+               VIA_CMDBUF_LAG = 0x02
+       } func;
+       int wait;
+       uint32_t size;
+} drm_via_cmdbuf_size_t;
+
+typedef enum {
+       VIA_IRQ_ABSOLUTE = 0x0,
+       VIA_IRQ_RELATIVE = 0x1,
+       VIA_IRQ_SIGNAL = 0x10000000,
+       VIA_IRQ_FORCE_SEQUENCE = 0x20000000
+} via_irq_seq_type_t;
+
+#define VIA_IRQ_FLAGS_MASK 0xF0000000
+
+enum drm_via_irqs {
+       drm_via_irq_hqv0 = 0,
+       drm_via_irq_hqv1,
+       drm_via_irq_dma0_dd,
+       drm_via_irq_dma0_td,
+       drm_via_irq_dma1_dd,
+       drm_via_irq_dma1_td,
+       drm_via_irq_num
+};
+
+struct drm_via_wait_irq_request {
+       unsigned irq;
+       via_irq_seq_type_t type;
+       uint32_t sequence;
+       uint32_t signal;
+};
+
+typedef union drm_via_irqwait {
+       struct drm_via_wait_irq_request request;
+       struct drm_wait_vblank_reply reply;
+} drm_via_irqwait_t;
+
+typedef struct drm_via_blitsync {
+       uint32_t sync_handle;
+       unsigned engine;
+} drm_via_blitsync_t;
+
+/* - * Below,"flags" is currently unused but will be used for possible future
+ * extensions like kernel space bounce buffers for bad alignments and
+ * blit engine busy-wait polling for better latency in the absence of
+ * interrupts.
+ */
+
+typedef struct drm_via_dmablit {
+       uint32_t num_lines;
+       uint32_t line_length;
+
+       uint32_t fb_addr;
+       uint32_t fb_stride;
+
+       unsigned char *mem_addr;
+       uint32_t mem_stride;
+
+       uint32_t flags;
+       int to_fb;
+
+       drm_via_blitsync_t sync;
+} drm_via_dmablit_t;
+
+#endif                         /* _VIA_DRM_H_ */
index 41f7ce7..0601075 100644 (file)
@@ -82,6 +82,7 @@ char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
 int early_acpi_boot_init(void);
 int acpi_boot_init (void);
 int acpi_boot_table_init (void);
+int acpi_mps_check (void);
 int acpi_numa_init (void);
 
 int acpi_table_init (void);
@@ -250,6 +251,11 @@ static inline int acpi_boot_table_init(void)
        return 0;
 }
 
+static inline int acpi_mps_check(void)
+{
+       return 0;
+}
+
 static inline int acpi_check_resource_conflict(struct resource *res)
 {
        return 0;
index 61c15ea..0933a14 100644 (file)
@@ -64,6 +64,7 @@ struct bio_vec {
 
 struct bio_set;
 struct bio;
+struct bio_integrity_payload;
 typedef void (bio_end_io_t) (struct bio *, int);
 typedef void (bio_destructor_t) (struct bio *);
 
@@ -112,6 +113,9 @@ struct bio {
        atomic_t                bi_cnt;         /* pin count */
 
        void                    *bi_private;
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+       struct bio_integrity_payload *bi_integrity;  /* data integrity */
+#endif
 
        bio_destructor_t        *bi_destructor; /* destructor */
 };
@@ -271,6 +275,29 @@ static inline void *bio_data(struct bio *bio)
  */
 #define bio_get(bio)   atomic_inc(&(bio)->bi_cnt)
 
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+/*
+ * bio integrity payload
+ */
+struct bio_integrity_payload {
+       struct bio              *bip_bio;       /* parent bio */
+       struct bio_vec          *bip_vec;       /* integrity data vector */
+
+       sector_t                bip_sector;     /* virtual start sector */
+
+       void                    *bip_buf;       /* generated integrity data */
+       bio_end_io_t            *bip_end_io;    /* saved I/O completion fn */
+
+       int                     bip_error;      /* saved I/O error */
+       unsigned int            bip_size;
+
+       unsigned short          bip_pool;       /* pool the ivec came from */
+       unsigned short          bip_vcnt;       /* # of integrity bio_vecs */
+       unsigned short          bip_idx;        /* current bip_vec index */
+
+       struct work_struct      bip_work;       /* I/O completion */
+};
+#endif /* CONFIG_BLK_DEV_INTEGRITY */
 
 /*
  * A bio_pair is used when we need to split a bio.
@@ -283,10 +310,14 @@ static inline void *bio_data(struct bio *bio)
  *   in bio2.bi_private
  */
 struct bio_pair {
-       struct bio      bio1, bio2;
-       struct bio_vec  bv1, bv2;
-       atomic_t        cnt;
-       int             error;
+       struct bio                      bio1, bio2;
+       struct bio_vec                  bv1, bv2;
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+       struct bio_integrity_payload    bip1, bip2;
+       struct bio_vec                  iv1, iv2;
+#endif
+       atomic_t                        cnt;
+       int                             error;
 };
 extern struct bio_pair *bio_split(struct bio *bi, mempool_t *pool,
                                  int first_sectors);
@@ -333,6 +364,39 @@ extern struct bio *bio_copy_user_iov(struct request_queue *, struct sg_iovec *,
                                     int, int);
 extern int bio_uncopy_user(struct bio *);
 void zero_fill_bio(struct bio *bio);
+extern struct bio_vec *bvec_alloc_bs(gfp_t, int, unsigned long *, struct bio_set *);
+extern unsigned int bvec_nr_vecs(unsigned short idx);
+
+/*
+ * bio_set is used to allow other portions of the IO system to
+ * allocate their own private memory pools for bio and iovec structures.
+ * These memory pools in turn all allocate from the bio_slab
+ * and the bvec_slabs[].
+ */
+#define BIO_POOL_SIZE 2
+#define BIOVEC_NR_POOLS 6
+
+struct bio_set {
+       mempool_t *bio_pool;
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+       mempool_t *bio_integrity_pool;
+#endif
+       mempool_t *bvec_pools[BIOVEC_NR_POOLS];
+};
+
+struct biovec_slab {
+       int nr_vecs;
+       char *name;
+       struct kmem_cache *slab;
+};
+
+extern struct bio_set *fs_bio_set;
+
+/*
+ * a small number of entries is fine, not going to be performance critical.
+ * basically we just need to survive
+ */
+#define BIO_SPLIT_ENTRIES 2
 
 #ifdef CONFIG_HIGHMEM
 /*
@@ -381,5 +445,63 @@ static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
        __bio_kmap_irq((bio), (bio)->bi_idx, (flags))
 #define bio_kunmap_irq(buf,flags)      __bio_kunmap_irq(buf, flags)
 
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+
+#define bip_vec_idx(bip, idx)  (&(bip->bip_vec[(idx)]))
+#define bip_vec(bip)           bip_vec_idx(bip, 0)
+
+#define __bip_for_each_vec(bvl, bip, i, start_idx)                     \
+       for (bvl = bip_vec_idx((bip), (start_idx)), i = (start_idx);    \
+            i < (bip)->bip_vcnt;                                       \
+            bvl++, i++)
+
+#define bip_for_each_vec(bvl, bip, i)                                  \
+       __bip_for_each_vec(bvl, bip, i, (bip)->bip_idx)
+
+static inline int bio_integrity(struct bio *bio)
+{
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+       return bio->bi_integrity != NULL;
+#else
+       return 0;
+#endif
+}
+
+extern struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *, gfp_t, unsigned int, struct bio_set *);
+extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
+extern void bio_integrity_free(struct bio *, struct bio_set *);
+extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
+extern int bio_integrity_enabled(struct bio *bio);
+extern int bio_integrity_set_tag(struct bio *, void *, unsigned int);
+extern int bio_integrity_get_tag(struct bio *, void *, unsigned int);
+extern int bio_integrity_prep(struct bio *);
+extern void bio_integrity_endio(struct bio *, int);
+extern void bio_integrity_advance(struct bio *, unsigned int);
+extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int);
+extern void bio_integrity_split(struct bio *, struct bio_pair *, int);
+extern int bio_integrity_clone(struct bio *, struct bio *, struct bio_set *);
+extern int bioset_integrity_create(struct bio_set *, int);
+extern void bioset_integrity_free(struct bio_set *);
+extern void bio_integrity_init_slab(void);
+
+#else /* CONFIG_BLK_DEV_INTEGRITY */
+
+#define bio_integrity(a)               (0)
+#define bioset_integrity_create(a, b)  (0)
+#define bio_integrity_prep(a)          (0)
+#define bio_integrity_enabled(a)       (0)
+#define bio_integrity_clone(a, b, c)   (0)
+#define bioset_integrity_free(a)       do { } while (0)
+#define bio_integrity_free(a, b)       do { } while (0)
+#define bio_integrity_endio(a, b)      do { } while (0)
+#define bio_integrity_advance(a, b)    do { } while (0)
+#define bio_integrity_trim(a, b, c)    do { } while (0)
+#define bio_integrity_split(a, b, c)   do { } while (0)
+#define bio_integrity_set_tag(a, b, c) do { } while (0)
+#define bio_integrity_get_tag(a, b, c) do { } while (0)
+#define bio_integrity_init_slab(a)     do { } while (0)
+
+#endif /* CONFIG_BLK_DEV_INTEGRITY */
+
 #endif /* CONFIG_BLOCK */
 #endif /* __LINUX_BIO_H */
index d2a1b71..1ffd8bf 100644 (file)
@@ -23,7 +23,6 @@
 struct scsi_ioctl_command;
 
 struct request_queue;
-typedef struct request_queue request_queue_t __deprecated;
 struct elevator_queue;
 typedef struct elevator_queue elevator_t;
 struct request_pm_state;
@@ -34,12 +33,6 @@ struct sg_io_hdr;
 #define BLKDEV_MIN_RQ  4
 #define BLKDEV_MAX_RQ  128     /* Default maximum */
 
-int put_io_context(struct io_context *ioc);
-void exit_io_context(void);
-struct io_context *get_io_context(gfp_t gfp_flags, int node);
-struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
-void copy_io_context(struct io_context **pdst, struct io_context **psrc);
-
 struct request;
 typedef void (rq_end_io_fn)(struct request *, int);
 
@@ -113,6 +106,7 @@ enum rq_flag_bits {
        __REQ_ALLOCED,          /* request came from our alloc pool */
        __REQ_RW_META,          /* metadata io request */
        __REQ_COPY_USER,        /* contains copies of user pages */
+       __REQ_INTEGRITY,        /* integrity metadata has been remapped */
        __REQ_NR_BITS,          /* stops here */
 };
 
@@ -135,6 +129,7 @@ enum rq_flag_bits {
 #define REQ_ALLOCED    (1 << __REQ_ALLOCED)
 #define REQ_RW_META    (1 << __REQ_RW_META)
 #define REQ_COPY_USER  (1 << __REQ_COPY_USER)
+#define REQ_INTEGRITY  (1 << __REQ_INTEGRITY)
 
 #define BLK_MAX_CDB    16
 
@@ -259,7 +254,14 @@ typedef int (prep_rq_fn) (struct request_queue *, struct request *);
 typedef void (unplug_fn) (struct request_queue *);
 
 struct bio_vec;
-typedef int (merge_bvec_fn) (struct request_queue *, struct bio *, struct bio_vec *);
+struct bvec_merge_data {
+       struct block_device *bi_bdev;
+       sector_t bi_sector;
+       unsigned bi_size;
+       unsigned long bi_rw;
+};
+typedef int (merge_bvec_fn) (struct request_queue *, struct bvec_merge_data *,
+                            struct bio_vec *);
 typedef void (prepare_flush_fn) (struct request_queue *, struct request *);
 typedef void (softirq_done_fn)(struct request *);
 typedef int (dma_drain_needed_fn)(struct request *);
@@ -426,6 +428,32 @@ static inline void queue_flag_set_unlocked(unsigned int flag,
        __set_bit(flag, &q->queue_flags);
 }
 
+static inline int queue_flag_test_and_clear(unsigned int flag,
+                                           struct request_queue *q)
+{
+       WARN_ON_ONCE(!queue_is_locked(q));
+
+       if (test_bit(flag, &q->queue_flags)) {
+               __clear_bit(flag, &q->queue_flags);
+               return 1;
+       }
+
+       return 0;
+}
+
+static inline int queue_flag_test_and_set(unsigned int flag,
+                                         struct request_queue *q)
+{
+       WARN_ON_ONCE(!queue_is_locked(q));
+
+       if (!test_bit(flag, &q->queue_flags)) {
+               __set_bit(flag, &q->queue_flags);
+               return 0;
+       }
+
+       return 1;
+}
+
 static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
 {
        WARN_ON_ONCE(!queue_is_locked(q));
@@ -676,7 +704,6 @@ extern int blk_execute_rq(struct request_queue *, struct gendisk *,
                          struct request *, int);
 extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
                                  struct request *, int, rq_end_io_fn *);
-extern int blk_verify_command(unsigned char *, int);
 extern void blk_unplug(struct request_queue *q);
 
 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
@@ -749,6 +776,7 @@ extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
 extern void blk_queue_hardsect_size(struct request_queue *, unsigned short);
 extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
 extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
+extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
 extern int blk_queue_dma_drain(struct request_queue *q,
                               dma_drain_needed_fn *dma_drain_needed,
                               void *buf, unsigned int size);
@@ -802,6 +830,15 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
 
 extern int blkdev_issue_flush(struct block_device *, sector_t *);
 
+/*
+* command filter functions
+*/
+extern int blk_verify_command(struct file *file, unsigned char *cmd);
+extern int blk_cmd_filter_verify_command(struct blk_scsi_cmd_filter *filter,
+                                        unsigned char *cmd, mode_t *f_mode);
+extern int blk_register_filter(struct gendisk *disk);
+extern void blk_unregister_filter(struct gendisk *disk);
+
 #define MAX_PHYS_SEGMENTS 128
 #define MAX_HW_SEGMENTS 128
 #define SAFE_MAX_SECTORS 255
@@ -865,28 +902,116 @@ void kblockd_flush_work(struct work_struct *work);
 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
        MODULE_ALIAS("block-major-" __stringify(major) "-*")
 
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
 
-#else /* CONFIG_BLOCK */
-/*
- * stubs for when the block layer is configured out
- */
-#define buffer_heads_over_limit 0
+#define INTEGRITY_FLAG_READ    2       /* verify data integrity on read */
+#define INTEGRITY_FLAG_WRITE   4       /* generate data integrity on write */
 
-static inline long nr_blockdev_pages(void)
+struct blk_integrity_exchg {
+       void                    *prot_buf;
+       void                    *data_buf;
+       sector_t                sector;
+       unsigned int            data_size;
+       unsigned short          sector_size;
+       const char              *disk_name;
+};
+
+typedef void (integrity_gen_fn) (struct blk_integrity_exchg *);
+typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *);
+typedef void (integrity_set_tag_fn) (void *, void *, unsigned int);
+typedef void (integrity_get_tag_fn) (void *, void *, unsigned int);
+
+struct blk_integrity {
+       integrity_gen_fn        *generate_fn;
+       integrity_vrfy_fn       *verify_fn;
+       integrity_set_tag_fn    *set_tag_fn;
+       integrity_get_tag_fn    *get_tag_fn;
+
+       unsigned short          flags;
+       unsigned short          tuple_size;
+       unsigned short          sector_size;
+       unsigned short          tag_size;
+
+       const char              *name;
+
+       struct kobject          kobj;
+};
+
+extern int blk_integrity_register(struct gendisk *, struct blk_integrity *);
+extern void blk_integrity_unregister(struct gendisk *);
+extern int blk_integrity_compare(struct block_device *, struct block_device *);
+extern int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
+extern int blk_rq_count_integrity_sg(struct request *);
+
+static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi)
 {
+       if (bi)
+               return bi->tuple_size;
+
        return 0;
 }
 
-static inline void exit_io_context(void)
+static inline struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
 {
+       return bdev->bd_disk->integrity;
 }
 
-struct io_context;
-static inline int put_io_context(struct io_context *ioc)
+static inline unsigned int bdev_get_tag_size(struct block_device *bdev)
 {
-       return 1;
+       struct blk_integrity *bi = bdev_get_integrity(bdev);
+
+       if (bi)
+               return bi->tag_size;
+
+       return 0;
+}
+
+static inline int bdev_integrity_enabled(struct block_device *bdev, int rw)
+{
+       struct blk_integrity *bi = bdev_get_integrity(bdev);
+
+       if (bi == NULL)
+               return 0;
+
+       if (rw == READ && bi->verify_fn != NULL &&
+           (bi->flags & INTEGRITY_FLAG_READ))
+               return 1;
+
+       if (rw == WRITE && bi->generate_fn != NULL &&
+           (bi->flags & INTEGRITY_FLAG_WRITE))
+               return 1;
+
+       return 0;
 }
 
+static inline int blk_integrity_rq(struct request *rq)
+{
+       return bio_integrity(rq->bio);
+}
+
+#else /* CONFIG_BLK_DEV_INTEGRITY */
+
+#define blk_integrity_rq(rq)                   (0)
+#define blk_rq_count_integrity_sg(a)           (0)
+#define blk_rq_map_integrity_sg(a, b)          (0)
+#define bdev_get_integrity(a)                  (0)
+#define bdev_get_tag_size(a)                   (0)
+#define blk_integrity_compare(a, b)            (0)
+#define blk_integrity_register(a, b)           (0)
+#define blk_integrity_unregister(a)            do { } while (0);
+
+#endif /* CONFIG_BLK_DEV_INTEGRITY */
+
+#else /* CONFIG_BLOCK */
+/*
+ * stubs for when the block layer is configured out
+ */
+#define buffer_heads_over_limit 0
+
+static inline long nr_blockdev_pages(void)
+{
+       return 0;
+}
 
 #endif /* CONFIG_BLOCK */
 
index e3ef903..d084b8d 100644 (file)
@@ -129,6 +129,7 @@ struct blk_trace {
        u32 dev;
        struct dentry *dir;
        struct dentry *dropped_file;
+       struct dentry *msg_file;
        atomic_t dropped;
 };
 
index 686895b..a1d9b79 100644 (file)
@@ -84,6 +84,8 @@ extern int reserve_bootmem(unsigned long addr, unsigned long size, int flags);
        __alloc_bootmem_low(x, PAGE_SIZE, 0)
 #endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
 
+extern int reserve_bootmem_generic(unsigned long addr, unsigned long size,
+                                  int flags);
 extern unsigned long free_all_bootmem(void);
 extern unsigned long free_all_bootmem_node(pg_data_t *pgdat);
 extern void *__alloc_bootmem_node(pg_data_t *pgdat,
index a4f27fb..248e6e3 100644 (file)
@@ -108,6 +108,8 @@ struct console {
        struct   console *next;
 };
 
+extern int console_set_on_cmdline;
+
 extern int add_preferred_console(char *name, int idx, char *options);
 extern int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options);
 extern void register_console(struct console *);
index 425824b..c43dc47 100644 (file)
  */
 #define CRYPTO_ALG_TYPE_MASK           0x0000000f
 #define CRYPTO_ALG_TYPE_CIPHER         0x00000001
-#define CRYPTO_ALG_TYPE_DIGEST         0x00000002
-#define CRYPTO_ALG_TYPE_HASH           0x00000003
+#define CRYPTO_ALG_TYPE_COMPRESS       0x00000002
+#define CRYPTO_ALG_TYPE_AEAD           0x00000003
 #define CRYPTO_ALG_TYPE_BLKCIPHER      0x00000004
 #define CRYPTO_ALG_TYPE_ABLKCIPHER     0x00000005
 #define CRYPTO_ALG_TYPE_GIVCIPHER      0x00000006
-#define CRYPTO_ALG_TYPE_COMPRESS       0x00000008
-#define CRYPTO_ALG_TYPE_AEAD           0x00000009
+#define CRYPTO_ALG_TYPE_DIGEST         0x00000008
+#define CRYPTO_ALG_TYPE_HASH           0x00000009
+#define CRYPTO_ALG_TYPE_AHASH          0x0000000a
 
 #define CRYPTO_ALG_TYPE_HASH_MASK      0x0000000e
+#define CRYPTO_ALG_TYPE_AHASH_MASK     0x0000000c
 #define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
 
 #define CRYPTO_ALG_LARVAL              0x00000010
@@ -102,6 +104,7 @@ struct crypto_async_request;
 struct crypto_aead;
 struct crypto_blkcipher;
 struct crypto_hash;
+struct crypto_ahash;
 struct crypto_tfm;
 struct crypto_type;
 struct aead_givcrypt_request;
@@ -131,6 +134,16 @@ struct ablkcipher_request {
        void *__ctx[] CRYPTO_MINALIGN_ATTR;
 };
 
+struct ahash_request {
+       struct crypto_async_request base;
+
+       unsigned int nbytes;
+       struct scatterlist *src;
+       u8                 *result;
+
+       void *__ctx[] CRYPTO_MINALIGN_ATTR;
+};
+
 /**
  *     struct aead_request - AEAD request
  *     @base: Common attributes for async crypto requests
@@ -195,6 +208,17 @@ struct ablkcipher_alg {
        unsigned int ivsize;
 };
 
+struct ahash_alg {
+       int (*init)(struct ahash_request *req);
+       int (*update)(struct ahash_request *req);
+       int (*final)(struct ahash_request *req);
+       int (*digest)(struct ahash_request *req);
+       int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
+                       unsigned int keylen);
+
+       unsigned int digestsize;
+};
+
 struct aead_alg {
        int (*setkey)(struct crypto_aead *tfm, const u8 *key,
                      unsigned int keylen);
@@ -272,6 +296,7 @@ struct compress_alg {
 #define cra_cipher     cra_u.cipher
 #define cra_digest     cra_u.digest
 #define cra_hash       cra_u.hash
+#define cra_ahash      cra_u.ahash
 #define cra_compress   cra_u.compress
 
 struct crypto_alg {
@@ -298,6 +323,7 @@ struct crypto_alg {
                struct cipher_alg cipher;
                struct digest_alg digest;
                struct hash_alg hash;
+               struct ahash_alg ahash;
                struct compress_alg compress;
        } cra_u;
 
@@ -383,6 +409,18 @@ struct hash_tfm {
        unsigned int digestsize;
 };
 
+struct ahash_tfm {
+       int (*init)(struct ahash_request *req);
+       int (*update)(struct ahash_request *req);
+       int (*final)(struct ahash_request *req);
+       int (*digest)(struct ahash_request *req);
+       int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
+                       unsigned int keylen);
+
+       unsigned int digestsize;
+       unsigned int reqsize;
+};
+
 struct compress_tfm {
        int (*cot_compress)(struct crypto_tfm *tfm,
                            const u8 *src, unsigned int slen,
@@ -397,6 +435,7 @@ struct compress_tfm {
 #define crt_blkcipher  crt_u.blkcipher
 #define crt_cipher     crt_u.cipher
 #define crt_hash       crt_u.hash
+#define crt_ahash      crt_u.ahash
 #define crt_compress   crt_u.compress
 
 struct crypto_tfm {
@@ -409,6 +448,7 @@ struct crypto_tfm {
                struct blkcipher_tfm blkcipher;
                struct cipher_tfm cipher;
                struct hash_tfm hash;
+               struct ahash_tfm ahash;
                struct compress_tfm compress;
        } crt_u;
        
index 54552d2..fd832c6 100644 (file)
@@ -41,6 +41,7 @@ static inline void ndelay(unsigned long x)
 #define ndelay(x) ndelay(x)
 #endif
 
+extern unsigned long lpj_fine;
 void calibrate_delay(void);
 void msleep(unsigned int msecs);
 unsigned long msleep_interruptible(unsigned int msecs);
index a5f359a..807373d 100644 (file)
@@ -287,7 +287,6 @@ efi_guid_unparse(efi_guid_t *guid, char *out)
 extern void efi_init (void);
 extern void *efi_get_pal_addr (void);
 extern void efi_map_pal_code (void);
-extern void efi_map_memmap(void);
 extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
 extern void efi_gettimeofday (struct timespec *ts);
 extern void efi_enter_virtual_mode (void);     /* switch EFI to virtual mode, if possible */
@@ -295,14 +294,11 @@ extern u64 efi_get_iobase (void);
 extern u32 efi_mem_type (unsigned long phys_addr);
 extern u64 efi_mem_attributes (unsigned long phys_addr);
 extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
-extern int efi_mem_attribute_range (unsigned long phys_addr, unsigned long size,
-                                   u64 attr);
 extern int __init efi_uart_console_only (void);
 extern void efi_initialize_iomem_resources(struct resource *code_resource,
                struct resource *data_resource, struct resource *bss_resource);
 extern unsigned long efi_get_time(void);
 extern int efi_set_rtc_mmss(unsigned long nowtime);
-extern int is_available_memory(efi_memory_desc_t * md);
 extern struct efi_memory_map memmap;
 
 /**
diff --git a/include/linux/firmware-map.h b/include/linux/firmware-map.h
new file mode 100644 (file)
index 0000000..acbdbcc
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * include/linux/firmware-map.h:
+ *  Copyright (C) 2008 SUSE LINUX Products GmbH
+ *  by Bernhard Walle <bwalle@suse.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2.0 as published by
+ * the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#ifndef _LINUX_FIRMWARE_MAP_H
+#define _LINUX_FIRMWARE_MAP_H
+
+#include <linux/list.h>
+#include <linux/kobject.h>
+
+/*
+ * provide a dummy interface if CONFIG_FIRMWARE_MEMMAP is disabled
+ */
+#ifdef CONFIG_FIRMWARE_MEMMAP
+
+/**
+ * Adds a firmware mapping entry. This function uses kmalloc() for memory
+ * allocation. Use firmware_map_add_early() if you want to use the bootmem
+ * allocator.
+ *
+ * That function must be called before late_initcall.
+ *
+ * @start: Start of the memory range.
+ * @end:   End of the memory range (inclusive).
+ * @type:  Type of the memory range.
+ *
+ * Returns 0 on success, or -ENOMEM if no memory could be allocated.
+ */
+int firmware_map_add(resource_size_t start, resource_size_t end,
+                    const char *type);
+
+/**
+ * Adds a firmware mapping entry. This function uses the bootmem allocator
+ * for memory allocation. Use firmware_map_add() if you want to use kmalloc().
+ *
+ * That function must be called before late_initcall.
+ *
+ * @start: Start of the memory range.
+ * @end:   End of the memory range (inclusive).
+ * @type:  Type of the memory range.
+ *
+ * Returns 0 on success, or -ENOMEM if no memory could be allocated.
+ */
+int firmware_map_add_early(resource_size_t start, resource_size_t end,
+                          const char *type);
+
+#else /* CONFIG_FIRMWARE_MEMMAP */
+
+static inline int firmware_map_add(resource_size_t start, resource_size_t end,
+                                  const char *type)
+{
+       return 0;
+}
+
+static inline int firmware_map_add_early(resource_size_t start,
+                                        resource_size_t end, const char *type)
+{
+       return 0;
+}
+
+#endif /* CONFIG_FIRMWARE_MEMMAP */
+
+#endif /* _LINUX_FIRMWARE_MAP_H */
index d8e2762..faac13e 100644 (file)
@@ -1870,7 +1870,8 @@ extern void
 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
-extern loff_t remote_llseek(struct file *file, loff_t offset, int origin);
+extern loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset,
+                       int origin);
 extern int generic_file_open(struct inode * inode, struct file * filp);
 extern int nonseekable_open(struct inode * inode, struct file * filp);
 
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
new file mode 100644 (file)
index 0000000..f368d04
--- /dev/null
@@ -0,0 +1,144 @@
+#ifndef _LINUX_FTRACE_H
+#define _LINUX_FTRACE_H
+
+#ifdef CONFIG_FTRACE
+
+#include <linux/linkage.h>
+#include <linux/fs.h>
+
+extern int ftrace_enabled;
+extern int
+ftrace_enable_sysctl(struct ctl_table *table, int write,
+                    struct file *filp, void __user *buffer, size_t *lenp,
+                    loff_t *ppos);
+
+typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
+
+struct ftrace_ops {
+       ftrace_func_t     func;
+       struct ftrace_ops *next;
+};
+
+/*
+ * The ftrace_ops must be a static and should also
+ * be read_mostly.  These functions do modify read_mostly variables
+ * so use them sparely. Never free an ftrace_op or modify the
+ * next pointer after it has been registered. Even after unregistering
+ * it, the next pointer may still be used internally.
+ */
+int register_ftrace_function(struct ftrace_ops *ops);
+int unregister_ftrace_function(struct ftrace_ops *ops);
+void clear_ftrace_function(void);
+
+extern void ftrace_stub(unsigned long a0, unsigned long a1);
+
+#else /* !CONFIG_FTRACE */
+# define register_ftrace_function(ops) do { } while (0)
+# define unregister_ftrace_function(ops) do { } while (0)
+# define clear_ftrace_function(ops) do { } while (0)
+#endif /* CONFIG_FTRACE */
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+# define FTRACE_HASHBITS       10
+# define FTRACE_HASHSIZE       (1<<FTRACE_HASHBITS)
+
+enum {
+       FTRACE_FL_FREE          = (1 << 0),
+       FTRACE_FL_FAILED        = (1 << 1),
+       FTRACE_FL_FILTER        = (1 << 2),
+       FTRACE_FL_ENABLED       = (1 << 3),
+       FTRACE_FL_NOTRACE       = (1 << 4),
+       FTRACE_FL_CONVERTED     = (1 << 5),
+       FTRACE_FL_FROZEN        = (1 << 6),
+};
+
+struct dyn_ftrace {
+       struct hlist_node node;
+       unsigned long     ip; /* address of mcount call-site */
+       unsigned long     flags;
+};
+
+int ftrace_force_update(void);
+void ftrace_set_filter(unsigned char *buf, int len, int reset);
+
+/* defined in arch */
+extern int ftrace_ip_converted(unsigned long ip);
+extern unsigned char *ftrace_nop_replace(void);
+extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
+extern int ftrace_dyn_arch_init(void *data);
+extern int ftrace_mcount_set(unsigned long *data);
+extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
+                             unsigned char *new_code);
+extern int ftrace_update_ftrace_func(ftrace_func_t func);
+extern void ftrace_caller(void);
+extern void ftrace_call(void);
+extern void mcount_call(void);
+
+extern int skip_trace(unsigned long ip);
+
+void ftrace_disable_daemon(void);
+void ftrace_enable_daemon(void);
+
+#else
+# define skip_trace(ip)                                ({ 0; })
+# define ftrace_force_update()                 ({ 0; })
+# define ftrace_set_filter(buf, len, reset)    do { } while (0)
+# define ftrace_disable_daemon()               do { } while (0)
+# define ftrace_enable_daemon()                        do { } while (0)
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
+/* totally disable ftrace - can not re-enable after this */
+void ftrace_kill(void);
+void ftrace_kill_atomic(void);
+
+static inline void tracer_disable(void)
+{
+#ifdef CONFIG_FTRACE
+       ftrace_enabled = 0;
+#endif
+}
+
+#ifdef CONFIG_FRAME_POINTER
+/* TODO: need to fix this for ARM */
+# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
+# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
+# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
+# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
+# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
+# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
+# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
+#else
+# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
+# define CALLER_ADDR1 0UL
+# define CALLER_ADDR2 0UL
+# define CALLER_ADDR3 0UL
+# define CALLER_ADDR4 0UL
+# define CALLER_ADDR5 0UL
+# define CALLER_ADDR6 0UL
+#endif
+
+#ifdef CONFIG_IRQSOFF_TRACER
+  extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
+  extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
+#else
+# define time_hardirqs_on(a0, a1)              do { } while (0)
+# define time_hardirqs_off(a0, a1)             do { } while (0)
+#endif
+
+#ifdef CONFIG_PREEMPT_TRACER
+  extern void trace_preempt_on(unsigned long a0, unsigned long a1);
+  extern void trace_preempt_off(unsigned long a0, unsigned long a1);
+#else
+# define trace_preempt_on(a0, a1)              do { } while (0)
+# define trace_preempt_off(a0, a1)             do { } while (0)
+#endif
+
+#ifdef CONFIG_TRACING
+extern void
+ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
+#else
+static inline void
+ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
+#endif
+
+#endif /* _LINUX_FTRACE_H */
index ae7aec3..e878741 100644 (file)
@@ -110,6 +110,14 @@ struct hd_struct {
 #define GENHD_FL_SUPPRESS_PARTITION_INFO       32
 #define GENHD_FL_FAIL                          64
 
+#define BLK_SCSI_MAX_CMDS      (256)
+#define BLK_SCSI_CMD_PER_LONG  (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
+
+struct blk_scsi_cmd_filter {
+       unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
+       unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
+       struct kobject kobj;
+};
 
 struct gendisk {
        int major;                      /* major number of driver */
@@ -120,6 +128,7 @@ struct gendisk {
        struct hd_struct **part;        /* [indexed by minor] */
        struct block_device_operations *fops;
        struct request_queue *queue;
+       struct blk_scsi_cmd_filter cmd_filter;
        void *private_data;
        sector_t capacity;
 
@@ -141,6 +150,9 @@ struct gendisk {
        struct disk_stats dkstats;
 #endif
        struct work_struct async_notify;
+#ifdef  CONFIG_BLK_DEV_INTEGRITY
+       struct blk_integrity *integrity;
+#endif
 };
 
 /* 
index f1fc747..a86186d 100644 (file)
@@ -285,12 +285,11 @@ enum
 struct softirq_action
 {
        void    (*action)(struct softirq_action *);
-       void    *data;
 };
 
 asmlinkage void do_softirq(void);
 asmlinkage void __do_softirq(void);
-extern void open_softirq(int nr, void (*action)(struct softirq_action*), void *data);
+extern void open_softirq(int nr, void (*action)(struct softirq_action *));
 extern void softirq_init(void);
 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
 extern void raise_softirq_irqoff(unsigned int nr);
index 2b7a118..08b987b 100644 (file)
@@ -99,4 +99,22 @@ static inline struct io_context *ioc_task_link(struct io_context *ioc)
        return NULL;
 }
 
+#ifdef CONFIG_BLOCK
+int put_io_context(struct io_context *ioc);
+void exit_io_context(void);
+struct io_context *get_io_context(gfp_t gfp_flags, int node);
+struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
+void copy_io_context(struct io_context **pdst, struct io_context **psrc);
+#else
+static inline void exit_io_context(void)
+{
+}
+
+struct io_context;
+static inline int put_io_context(struct io_context *ioc)
+{
+       return 1;
+}
+#endif
+
 #endif
index e600c4e..2b1c2e5 100644 (file)
 #define _LINUX_TRACE_IRQFLAGS_H
 
 #ifdef CONFIG_TRACE_IRQFLAGS
-  extern void trace_hardirqs_on(void);
-  extern void trace_hardirqs_off(void);
   extern void trace_softirqs_on(unsigned long ip);
   extern void trace_softirqs_off(unsigned long ip);
+  extern void trace_hardirqs_on(void);
+  extern void trace_hardirqs_off(void);
 # define trace_hardirq_context(p)      ((p)->hardirq_context)
 # define trace_softirq_context(p)      ((p)->softirq_context)
 # define trace_hardirqs_enabled(p)     ((p)->hardirqs_enabled)
 # define INIT_TRACE_IRQFLAGS
 #endif
 
+#if defined(CONFIG_IRQSOFF_TRACER) || \
+       defined(CONFIG_PREEMPT_TRACER)
+ extern void stop_critical_timings(void);
+ extern void start_critical_timings(void);
+#else
+# define stop_critical_timings() do { } while (0)
+# define start_critical_timings() do { } while (0)
+#endif
+
 #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
 
 #include <asm/irqflags.h>
index 2e70006..f9cd7a5 100644 (file)
@@ -187,9 +187,6 @@ asmlinkage int vprintk(const char *fmt, va_list args)
        __attribute__ ((format (printf, 1, 0)));
 asmlinkage int printk(const char * fmt, ...)
        __attribute__ ((format (printf, 1, 2))) __cold;
-extern int log_buf_get_len(void);
-extern int log_buf_read(int idx);
-extern int log_buf_copy(char *dest, int idx, int len);
 
 extern int printk_ratelimit_jiffies;
 extern int printk_ratelimit_burst;
@@ -205,9 +202,6 @@ static inline int vprintk(const char *s, va_list args) { return 0; }
 static inline int printk(const char *s, ...)
        __attribute__ ((format (printf, 1, 2)));
 static inline int __cold printk(const char *s, ...) { return 0; }
-static inline int log_buf_get_len(void) { return 0; }
-static inline int log_buf_read(int idx) { return 0; }
-static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
 static inline int printk_ratelimit(void) { return 0; }
 static inline int __printk_ratelimit(int ratelimit_jiffies, \
                                     int ratelimit_burst) { return 0; }
@@ -216,7 +210,7 @@ static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
                { return false; }
 #endif
 
-extern void __attribute__((format(printf, 1, 2)))
+extern void asmlinkage __attribute__((format(printf, 1, 2)))
        early_printk(const char *fmt, ...);
 
 unsigned long int_sqrt(unsigned long);
index e8ffce8..cf9f40a 100644 (file)
@@ -1,11 +1,11 @@
 #ifndef _LINUX_KERNEL_STAT_H
 #define _LINUX_KERNEL_STAT_H
 
-#include <asm/irq.h>
 #include <linux/smp.h>
 #include <linux/threads.h>
 #include <linux/percpu.h>
 #include <linux/cpumask.h>
+#include <asm/irq.h>
 #include <asm/cputime.h>
 
 /*
index 1036631..04a3556 100644 (file)
@@ -259,6 +259,10 @@ void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
 struct jprobe;
 struct kretprobe;
 
+static inline struct kprobe *get_kprobe(void *addr)
+{
+       return NULL;
+}
 static inline struct kprobe *kprobe_running(void)
 {
        return NULL;
index 2119610..56ba373 100644 (file)
@@ -1,8 +1,11 @@
 #ifndef _LINUX_LINKAGE_H
 #define _LINUX_LINKAGE_H
 
+#include <linux/compiler.h>
 #include <asm/linkage.h>
 
+#define notrace __attribute__((no_instrument_function))
+
 #ifdef __cplusplus
 #define CPP_ASMLINKAGE extern "C"
 #else
@@ -17,6 +20,9 @@
 # define asmregparm
 #endif
 
+#define __page_aligned_data    __section(.data.page_aligned) __aligned(PAGE_SIZE)
+#define __page_aligned_bss     __section(.bss.page_aligned) __aligned(PAGE_SIZE)
+
 /*
  * This is used by architectures to keep arguments on the stack
  * untouched by the compiler by keeping them live until the end.
index 4c4d236..2486eb4 100644 (file)
@@ -182,6 +182,9 @@ struct lock_list {
  * We record lock dependency chains, so that we can cache them:
  */
 struct lock_chain {
+       u8                              irq_context;
+       u8                              depth;
+       u16                             base;
        struct list_head                entry;
        u64                             chain_key;
 };
@@ -275,14 +278,6 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
                lockdep_init_map(&(lock)->dep_map, #lock, \
                                 (lock)->dep_map.key, sub)
 
-/*
- * To initialize a lockdep_map statically use this macro.
- * Note that _name must not be NULL.
- */
-#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
-       { .name = (_name), .key = (void *)(_key), }
-
-
 /*
  * Acquire a lock.
  *
index 430f6ad..1290653 100644 (file)
@@ -44,8 +44,8 @@ struct marker {
                                 */
        char state;             /* Marker state. */
        char ptype;             /* probe type : 0 : single, 1 : multi */
-       void (*call)(const struct marker *mdata,        /* Probe wrapper */
-               void *call_private, const char *fmt, ...);
+                               /* Probe wrapper */
+       void (*call)(const struct marker *mdata, void *call_private, ...);
        struct marker_probe_closure single;
        struct marker_probe_closure *multi;
 } __attribute__((aligned(8)));
@@ -58,8 +58,12 @@ struct marker {
  * Make sure the alignment of the structure in the __markers section will
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
+ *
+ * The "generic" argument controls which marker enabling mechanism must be used.
+ * If generic is true, a variable read is used.
+ * If generic is false, immediate values are used.
  */
-#define __trace_mark(name, call_private, format, args...)              \
+#define __trace_mark(generic, name, call_private, format, args...)     \
        do {                                                            \
                static const char __mstrtab_##name[]                    \
                __attribute__((section("__markers_strings")))           \
@@ -72,15 +76,14 @@ struct marker {
                __mark_check_format(format, ## args);                   \
                if (unlikely(__mark_##name.state)) {                    \
                        (*__mark_##name.call)                           \
-                               (&__mark_##name, call_private,          \
-                               format, ## args);                       \
+                               (&__mark_##name, call_private, ## args);\
                }                                                       \
        } while (0)
 
 extern void marker_update_probe_range(struct marker *begin,
        struct marker *end);
 #else /* !CONFIG_MARKERS */
-#define __trace_mark(name, call_private, format, args...) \
+#define __trace_mark(generic, name, call_private, format, args...) \
                __mark_check_format(format, ## args)
 static inline void marker_update_probe_range(struct marker *begin,
        struct marker *end)
@@ -88,15 +91,30 @@ static inline void marker_update_probe_range(struct marker *begin,
 #endif /* CONFIG_MARKERS */
 
 /**
- * trace_mark - Marker
+ * trace_mark - Marker using code patching
  * @name: marker name, not quoted.
  * @format: format string
  * @args...: variable argument list
  *
- * Places a marker.
+ * Places a marker using optimized code patching technique (imv_read())
+ * to be enabled when immediate values are present.
  */
 #define trace_mark(name, format, args...) \
-       __trace_mark(name, NULL, format, ## args)
+       __trace_mark(0, name, NULL, format, ## args)
+
+/**
+ * _trace_mark - Marker using variable read
+ * @name: marker name, not quoted.
+ * @format: format string
+ * @args...: variable argument list
+ *
+ * Places a marker using a standard memory read (_imv_read()) to be
+ * enabled. Should be used for markers in code paths where instruction
+ * modification based enabling is not welcome. (__init and __exit functions,
+ * lockdep, some traps, printk).
+ */
+#define _trace_mark(name, format, args...) \
+       __trace_mark(1, name, NULL, format, ## args)
 
 /**
  * MARK_NOARGS - Format string for a marker with no argument.
@@ -117,9 +135,9 @@ static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
 extern marker_probe_func __mark_empty_function;
 
 extern void marker_probe_cb(const struct marker *mdata,
-       void *call_private, const char *fmt, ...);
+       void *call_private, ...);
 extern void marker_probe_cb_noarg(const struct marker *mdata,
-       void *call_private, const char *fmt, ...);
+       void *call_private, ...);
 
 /*
  * Connect a probe to a marker.
index 6891844..2128ef7 100644 (file)
@@ -999,8 +999,8 @@ extern void free_area_init_node(int nid, pg_data_t *pgdat,
 extern void free_area_init_nodes(unsigned long *max_zone_pfn);
 extern void add_active_range(unsigned int nid, unsigned long start_pfn,
                                        unsigned long end_pfn);
-extern void shrink_active_range(unsigned int nid, unsigned long old_end_pfn,
-                                               unsigned long new_end_pfn);
+extern void remove_active_range(unsigned int nid, unsigned long start_pfn,
+                                       unsigned long end_pfn);
 extern void push_node_boundaries(unsigned int nid, unsigned long start_pfn,
                                        unsigned long end_pfn);
 extern void remove_all_active_ranges(void);
@@ -1012,6 +1012,8 @@ extern unsigned long find_min_pfn_with_active_regions(void);
 extern unsigned long find_max_pfn_with_active_regions(void);
 extern void free_bootmem_with_active_regions(int nid,
                                                unsigned long max_low_pfn);
+typedef int (*work_fn_t)(unsigned long, unsigned long, void *);
+extern void work_with_active_regions(int nid, work_fn_t work_fn, void *data);
 extern void sparse_memory_present_with_active_regions(int nid);
 #ifndef CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID
 extern int early_pfn_to_nid(unsigned long pfn);
@@ -1025,6 +1027,7 @@ extern void mem_init(void);
 extern void show_mem(void);
 extern void si_meminfo(struct sysinfo * val);
 extern void si_meminfo_node(struct sysinfo *val, int nid);
+extern int after_bootmem;
 
 #ifdef CONFIG_NUMA
 extern void setup_per_cpu_pageset(void);
diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
new file mode 100644 (file)
index 0000000..61d19e1
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef MMIOTRACE_H
+#define MMIOTRACE_H
+
+#include <linux/types.h>
+#include <linux/list.h>
+
+struct kmmio_probe;
+struct pt_regs;
+
+typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *,
+                               struct pt_regs *, unsigned long addr);
+typedef void (*kmmio_post_handler_t)(struct kmmio_probe *,
+                               unsigned long condition, struct pt_regs *);
+
+struct kmmio_probe {
+       struct list_head list; /* kmmio internal list */
+       unsigned long addr; /* start location of the probe point */
+       unsigned long len; /* length of the probe region */
+       kmmio_pre_handler_t pre_handler; /* Called before addr is executed. */
+       kmmio_post_handler_t post_handler; /* Called after addr is executed */
+       void *private;
+};
+
+/* kmmio is active by some kmmio_probes? */
+static inline int is_kmmio_active(void)
+{
+       extern unsigned int kmmio_count;
+       return kmmio_count;
+}
+
+extern int register_kmmio_probe(struct kmmio_probe *p);
+extern void unregister_kmmio_probe(struct kmmio_probe *p);
+
+/* Called from page fault handler. */
+extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
+
+/* Called from ioremap.c */
+#ifdef CONFIG_MMIOTRACE
+extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
+                                                       void __iomem *addr);
+extern void mmiotrace_iounmap(volatile void __iomem *addr);
+#else
+static inline void mmiotrace_ioremap(resource_size_t offset,
+                                       unsigned long size, void __iomem *addr)
+{
+}
+
+static inline void mmiotrace_iounmap(volatile void __iomem *addr)
+{
+}
+#endif /* CONFIG_MMIOTRACE_HOOKS */
+
+enum mm_io_opcode {
+       MMIO_READ = 0x1,     /* struct mmiotrace_rw */
+       MMIO_WRITE = 0x2,    /* struct mmiotrace_rw */
+       MMIO_PROBE = 0x3,    /* struct mmiotrace_map */
+       MMIO_UNPROBE = 0x4,  /* struct mmiotrace_map */
+       MMIO_MARKER = 0x5,   /* raw char data */
+       MMIO_UNKNOWN_OP = 0x6, /* struct mmiotrace_rw */
+};
+
+struct mmiotrace_rw {
+       resource_size_t phys;   /* PCI address of register */
+       unsigned long value;
+       unsigned long pc;       /* optional program counter */
+       int map_id;
+       unsigned char opcode;   /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */
+       unsigned char width;    /* size of register access in bytes */
+};
+
+struct mmiotrace_map {
+       resource_size_t phys;   /* base address in PCI space */
+       unsigned long virt;     /* base virtual address */
+       unsigned long len;      /* mapping size */
+       int map_id;
+       unsigned char opcode;   /* MMIO_PROBE or MMIO_UNPROBE */
+};
+
+/* in kernel/trace/trace_mmiotrace.c */
+extern void enable_mmiotrace(void);
+extern void disable_mmiotrace(void);
+extern void mmio_trace_rw(struct mmiotrace_rw *rw);
+extern void mmio_trace_mapping(struct mmiotrace_map *map);
+
+#endif /* MMIOTRACE_H */
index 69b2342..c4db582 100644 (file)
@@ -159,6 +159,15 @@ struct ap_device_id {
 
 #define AP_DEVICE_ID_MATCH_DEVICE_TYPE         0x01
 
+/* s390 css bus devices (subchannels) */
+struct css_device_id {
+       __u8 match_flags;
+       __u8 type; /* subchannel type */
+       __u16 pad2;
+       __u32 pad3;
+       kernel_ulong_t driver_data;
+};
+
 #define ACPI_ID_LEN    16 /* only 9 bytes needed here, 16 bytes are used */
                           /* to workaround crosscompile issues */
 
index f31debf..0d2a4e7 100644 (file)
@@ -157,6 +157,7 @@ PAGEFLAG(Active, active) __CLEARPAGEFLAG(Active, active)
 __PAGEFLAG(Slab, slab)
 PAGEFLAG(Checked, owner_priv_1)                /* Used by some filesystems */
 PAGEFLAG(Pinned, owner_priv_1) TESTSCFLAG(Pinned, owner_priv_1) /* Xen */
+PAGEFLAG(SavePinned, dirty);                                   /* Xen */
 PAGEFLAG(Reserved, reserved) __CLEARPAGEFLAG(Reserved, reserved)
 PAGEFLAG(Private, private) __CLEARPAGEFLAG(Private, private)
        __SETPAGEFLAG(Private, private)
index e875905..e8c0612 100644 (file)
 
 #include <linux/types.h>
 
-/* Macro to aid the definition of ranges of bits */
-#define PB_range(name, required_bits) \
-       name, name ## _end = (name + required_bits) - 1
-
 /* Bit indices that affect a whole block of pages */
 enum pageblock_bits {
-       PB_range(PB_migrate, 3), /* 3 bits required for migrate types */
+       PB_migrate,
+       PB_migrate_end = PB_migrate + 3 - 1,
+                       /* 3 bits required for migrate types */
        NR_PAGEBLOCK_BITS
 };
 
index 23f0c54..72b1a10 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/linkage.h>
 #include <linux/list.h>
 
-#ifdef CONFIG_DEBUG_PREEMPT
+#if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_PREEMPT_TRACER)
   extern void add_preempt_count(int val);
   extern void sub_preempt_count(int val);
 #else
@@ -52,6 +52,34 @@ do { \
        preempt_check_resched(); \
 } while (0)
 
+/* For debugging and tracer internals only! */
+#define add_preempt_count_notrace(val)                 \
+       do { preempt_count() += (val); } while (0)
+#define sub_preempt_count_notrace(val)                 \
+       do { preempt_count() -= (val); } while (0)
+#define inc_preempt_count_notrace() add_preempt_count_notrace(1)
+#define dec_preempt_count_notrace() sub_preempt_count_notrace(1)
+
+#define preempt_disable_notrace() \
+do { \
+       inc_preempt_count_notrace(); \
+       barrier(); \
+} while (0)
+
+#define preempt_enable_no_resched_notrace() \
+do { \
+       barrier(); \
+       dec_preempt_count_notrace(); \
+} while (0)
+
+/* preempt_check_resched is OK to trace */
+#define preempt_enable_notrace() \
+do { \
+       preempt_enable_no_resched_notrace(); \
+       barrier(); \
+       preempt_check_resched(); \
+} while (0)
+
 #else
 
 #define preempt_disable()              do { } while (0)
@@ -59,6 +87,10 @@ do { \
 #define preempt_enable()               do { } while (0)
 #define preempt_check_resched()                do { } while (0)
 
+#define preempt_disable_notrace()              do { } while (0)
+#define preempt_enable_no_resched_notrace()    do { } while (0)
+#define preempt_enable_notrace()               do { } while (0)
+
 #endif
 
 #ifdef CONFIG_PREEMPT_NOTIFIERS
index f98501b..c6f5f9d 100644 (file)
@@ -95,8 +95,12 @@ extern void __ptrace_link(struct task_struct *child,
                          struct task_struct *new_parent);
 extern void __ptrace_unlink(struct task_struct *child);
 extern void ptrace_untrace(struct task_struct *child);
-extern int ptrace_may_attach(struct task_struct *task);
-extern int __ptrace_may_attach(struct task_struct *task);
+#define PTRACE_MODE_READ   1
+#define PTRACE_MODE_ATTACH 2
+/* Returns 0 on success, -errno on denial. */
+extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
+/* Returns true on success, false on denial. */
+extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
 
 static inline int ptrace_reparented(struct task_struct *child)
 {
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
new file mode 100644 (file)
index 0000000..3945f80
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __LINUX_PWM_H
+#define __LINUX_PWM_H
+
+struct pwm_device;
+
+/*
+ * pwm_request - request a PWM device
+ */
+struct pwm_device *pwm_request(int pwm_id, const char *label);
+
+/*
+ * pwm_free - free a PWM device
+ */
+void pwm_free(struct pwm_device *pwm);
+
+/*
+ * pwm_config - change a PWM device configuration
+ */
+int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
+
+/*
+ * pwm_enable - start a PWM output toggling
+ */
+int pwm_enable(struct pwm_device *pwm);
+
+/*
+ * pwm_disable - stop a PWM output toggling
+ */
+void pwm_disable(struct pwm_device *pwm);
+
+#endif /* __ASM_ARCH_PWM_H */
diff --git a/include/linux/pwm_backlight.h b/include/linux/pwm_backlight.h
new file mode 100644 (file)
index 0000000..7a9754c
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Generic PWM backlight driver data - see drivers/video/backlight/pwm_bl.c
+ */
+#ifndef __LINUX_PWM_BACKLIGHT_H
+#define __LINUX_PWM_BACKLIGHT_H
+
+struct platform_pwm_backlight_data {
+       int pwm_id;
+       unsigned int max_brightness;
+       unsigned int dft_brightness;
+       unsigned int pwm_period_ns;
+       int (*init)(struct device *dev);
+       int (*notify)(int brightness);
+       void (*exit)(struct device *dev);
+};
+
+#endif
index f3f4f28..c9ba2fd 100644 (file)
@@ -8,7 +8,7 @@ extern int pm_trace_enabled;
 
 struct device;
 extern void set_trace_device(struct device *);
-extern void generate_resume_trace(void *tracedata, unsigned int user);
+extern void generate_resume_trace(const void *tracedata, unsigned int user);
 
 #define TRACE_DEVICE(dev) do { \
        if (pm_trace_enabled) \
index c5d3f84..2134917 100644 (file)
@@ -134,7 +134,6 @@ extern unsigned long nr_running(void);
 extern unsigned long nr_uninterruptible(void);
 extern unsigned long nr_active(void);
 extern unsigned long nr_iowait(void);
-extern unsigned long weighted_cpuload(const int cpu);
 
 struct seq_file;
 struct cfs_rq;
@@ -246,6 +245,8 @@ extern asmlinkage void schedule_tail(struct task_struct *prev);
 extern void init_idle(struct task_struct *idle, int cpu);
 extern void init_idle_bootup_task(struct task_struct *idle);
 
+extern int runqueue_is_locked(void);
+
 extern cpumask_t nohz_cpu_mask;
 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
 extern int select_nohz_load_balancer(int cpu);
@@ -784,6 +785,8 @@ struct sched_domain {
        unsigned int balance_interval;  /* initialise to 1. units in ms. */
        unsigned int nr_balance_failed; /* initialise to 0 */
 
+       u64 last_update;
+
 #ifdef CONFIG_SCHEDSTATS
        /* load_balance() stats */
        unsigned int lb_count[CPU_MAX_IDLE_TYPES];
@@ -823,23 +826,6 @@ extern int arch_reinit_sched_domains(void);
 
 #endif /* CONFIG_SMP */
 
-/*
- * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
- * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
- * task of nice 0 or enough lower priority tasks to bring up the
- * weighted_cpuload
- */
-static inline int above_background_load(void)
-{
-       unsigned long cpu;
-
-       for_each_online_cpu(cpu) {
-               if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
-                       return 1;
-       }
-       return 0;
-}
-
 struct io_context;                     /* See blkdev.h */
 #define NGROUPS_SMALL          32
 #define NGROUPS_PER_BLOCK      ((unsigned int)(PAGE_SIZE / sizeof(gid_t)))
@@ -921,8 +907,8 @@ struct sched_class {
        void (*set_cpus_allowed)(struct task_struct *p,
                                 const cpumask_t *newmask);
 
-       void (*join_domain)(struct rq *rq);
-       void (*leave_domain)(struct rq *rq);
+       void (*rq_online)(struct rq *rq);
+       void (*rq_offline)(struct rq *rq);
 
        void (*switched_from) (struct rq *this_rq, struct task_struct *task,
                               int running);
@@ -1039,6 +1025,7 @@ struct task_struct {
 #endif
 
        int prio, static_prio, normal_prio;
+       unsigned int rt_priority;
        const struct sched_class *sched_class;
        struct sched_entity se;
        struct sched_rt_entity rt;
@@ -1122,7 +1109,6 @@ struct task_struct {
        int __user *set_child_tid;              /* CLONE_CHILD_SETTID */
        int __user *clear_child_tid;            /* CLONE_CHILD_CLEARTID */
 
-       unsigned int rt_priority;
        cputime_t utime, stime, utimescaled, stimescaled;
        cputime_t gtime;
        cputime_t prev_utime, prev_stime;
@@ -1141,12 +1127,12 @@ struct task_struct {
        gid_t gid,egid,sgid,fsgid;
        struct group_info *group_info;
        kernel_cap_t   cap_effective, cap_inheritable, cap_permitted, cap_bset;
-       unsigned securebits;
        struct user_struct *user;
+       unsigned securebits;
 #ifdef CONFIG_KEYS
+       unsigned char jit_keyring;      /* default keyring to attach requested keys to */
        struct key *request_key_auth;   /* assumed request_key authority */
        struct key *thread_keyring;     /* keyring private to this thread */
-       unsigned char jit_keyring;      /* default keyring to attach requested keys to */
 #endif
        char comm[TASK_COMM_LEN]; /* executable name excluding path
                                     - access with [gs]et_task_comm (which lock
@@ -1233,8 +1219,8 @@ struct task_struct {
 # define MAX_LOCK_DEPTH 48UL
        u64 curr_chain_key;
        int lockdep_depth;
-       struct held_lock held_locks[MAX_LOCK_DEPTH];
        unsigned int lockdep_recursion;
+       struct held_lock held_locks[MAX_LOCK_DEPTH];
 #endif
 
 /* journalling filesystem info */
@@ -1262,10 +1248,6 @@ struct task_struct {
        u64 acct_vm_mem1;       /* accumulated virtual memory usage */
        cputime_t acct_stimexpd;/* stime since last update */
 #endif
-#ifdef CONFIG_NUMA
-       struct mempolicy *mempolicy;
-       short il_next;
-#endif
 #ifdef CONFIG_CPUSETS
        nodemask_t mems_allowed;
        int cpuset_mems_generation;
@@ -1284,6 +1266,10 @@ struct task_struct {
 #endif
        struct list_head pi_state_list;
        struct futex_pi_state *pi_state_cache;
+#endif
+#ifdef CONFIG_NUMA
+       struct mempolicy *mempolicy;
+       short il_next;
 #endif
        atomic_t fs_excl;       /* holding fs exclusive resources */
        struct rcu_head rcu;
@@ -1504,6 +1490,7 @@ static inline void put_task_struct(struct task_struct *t)
 #define PF_SWAPWRITE   0x00800000      /* Allowed to write to swap */
 #define PF_SPREAD_PAGE 0x01000000      /* Spread page cache over cpuset */
 #define PF_SPREAD_SLAB 0x02000000      /* Spread some slab caches over cpuset */
+#define PF_THREAD_BOUND        0x04000000      /* Thread bound to specific cpu */
 #define PF_MEMPOLICY   0x10000000      /* Non-default NUMA mempolicy */
 #define PF_MUTEX_TESTER        0x20000000      /* Thread belongs to the rt mutex tester */
 #define PF_FREEZER_SKIP        0x40000000      /* Freezer should not count it as freezeable */
@@ -1573,13 +1560,28 @@ static inline void sched_clock_idle_sleep_event(void)
 static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
 {
 }
-#else
+
+#ifdef CONFIG_NO_HZ
+static inline void sched_clock_tick_stop(int cpu)
+{
+}
+
+static inline void sched_clock_tick_start(int cpu)
+{
+}
+#endif
+
+#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
 extern void sched_clock_init(void);
 extern u64 sched_clock_cpu(int cpu);
 extern void sched_clock_tick(void);
 extern void sched_clock_idle_sleep_event(void);
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
+#ifdef CONFIG_NO_HZ
+extern void sched_clock_tick_stop(int cpu);
+extern void sched_clock_tick_start(int cpu);
 #endif
+#endif /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
 
 /*
  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
@@ -1622,6 +1624,7 @@ extern unsigned int sysctl_sched_child_runs_first;
 extern unsigned int sysctl_sched_features;
 extern unsigned int sysctl_sched_migration_cost;
 extern unsigned int sysctl_sched_nr_migrate;
+extern unsigned int sysctl_sched_shares_ratelimit;
 
 int sched_nr_latency_handler(struct ctl_table *table, int write,
                struct file *file, void __user *buffer, size_t *length,
@@ -1655,6 +1658,8 @@ extern int can_nice(const struct task_struct *p, const int nice);
 extern int task_curr(const struct task_struct *p);
 extern int idle_cpu(int cpu);
 extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
+extern int sched_setscheduler_nocheck(struct task_struct *, int,
+                                     struct sched_param *);
 extern struct task_struct *idle_task(int cpu);
 extern struct task_struct *curr_task(int cpu);
 extern void set_curr_task(int cpu, struct task_struct *p);
@@ -2131,6 +2136,18 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm)
 }
 #endif
 
+#ifdef CONFIG_TRACING
+extern void
+__trace_special(void *__tr, void *__data,
+               unsigned long arg1, unsigned long arg2, unsigned long arg3);
+#else
+static inline void
+__trace_special(void *__tr, void *__data,
+               unsigned long arg1, unsigned long arg2, unsigned long arg3)
+{
+}
+#endif
+
 extern long sched_setaffinity(pid_t pid, const cpumask_t *new_mask);
 extern long sched_getaffinity(pid_t pid, cpumask_t *mask);
 
@@ -2225,6 +2242,8 @@ static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p)
 }
 #endif /* CONFIG_MM_OWNER */
 
+#define TASK_STATE_TO_CHAR_STR "RSDTtZX"
+
 #endif /* __KERNEL__ */
 
 #endif
index 50737c7..31c8851 100644 (file)
@@ -46,7 +46,8 @@ struct audit_krule;
  */
 extern int cap_capable(struct task_struct *tsk, int cap);
 extern int cap_settime(struct timespec *ts, struct timezone *tz);
-extern int cap_ptrace(struct task_struct *parent, struct task_struct *child);
+extern int cap_ptrace(struct task_struct *parent, struct task_struct *child,
+                     unsigned int mode);
 extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
 extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
 extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -79,6 +80,7 @@ struct xfrm_selector;
 struct xfrm_policy;
 struct xfrm_state;
 struct xfrm_user_sec_ctx;
+struct seq_file;
 
 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
 extern int cap_netlink_recv(struct sk_buff *skb, int cap);
@@ -289,10 +291,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     Update module state after a successful pivot.
  *     @old_path contains the path for the old root.
  *     @new_path contains the path for the new root.
- * @sb_get_mnt_opts:
- *     Get the security relevant mount options used for a superblock
- *     @sb the superblock to get security mount options from
- *     @opts binary data structure containing all lsm mount data
  * @sb_set_mnt_opts:
  *     Set the security relevant mount options used for a superblock
  *     @sb the superblock to set security mount options for
@@ -1170,6 +1168,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     attributes would be changed by the execve.
  *     @parent contains the task_struct structure for parent process.
  *     @child contains the task_struct structure for child process.
+ *     @mode contains the PTRACE_MODE flags indicating the form of access.
  *     Return 0 if permission is granted.
  * @capget:
  *     Get the @effective, @inheritable, and @permitted capability sets for
@@ -1240,11 +1239,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @pages contains the number of pages.
  *     Return 0 if permission is granted.
  *
- * @register_security:
- *     allow module stacking.
- *     @name contains the name of the security module being stacked.
- *     @ops contains a pointer to the struct security_operations of the module to stack.
- *
  * @secid_to_secctx:
  *     Convert secid to security context.
  *     @secid contains the security ID.
@@ -1295,7 +1289,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
 struct security_operations {
        char name[SECURITY_NAME_MAX + 1];
 
-       int (*ptrace) (struct task_struct *parent, struct task_struct *child);
+       int (*ptrace) (struct task_struct *parent, struct task_struct *child,
+                      unsigned int mode);
        int (*capget) (struct task_struct *target,
                       kernel_cap_t *effective,
                       kernel_cap_t *inheritable, kernel_cap_t *permitted);
@@ -1328,6 +1323,7 @@ struct security_operations {
        void (*sb_free_security) (struct super_block *sb);
        int (*sb_copy_data) (char *orig, char *copy);
        int (*sb_kern_mount) (struct super_block *sb, void *data);
+       int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
        int (*sb_statfs) (struct dentry *dentry);
        int (*sb_mount) (char *dev_name, struct path *path,
                         char *type, unsigned long flags, void *data);
@@ -1343,8 +1339,6 @@ struct security_operations {
                             struct path *new_path);
        void (*sb_post_pivotroot) (struct path *old_path,
                                   struct path *new_path);
-       int (*sb_get_mnt_opts) (const struct super_block *sb,
-                               struct security_mnt_opts *opts);
        int (*sb_set_mnt_opts) (struct super_block *sb,
                                struct security_mnt_opts *opts);
        void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
@@ -1472,10 +1466,6 @@ struct security_operations {
        int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
        int (*netlink_recv) (struct sk_buff *skb, int cap);
 
-       /* allow module stacking */
-       int (*register_security) (const char *name,
-                                 struct security_operations *ops);
-
        void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
 
        int (*getprocattr) (struct task_struct *p, char *name, char **value);
@@ -1565,7 +1555,6 @@ struct security_operations {
 extern int security_init(void);
 extern int security_module_enable(struct security_operations *ops);
 extern int register_security(struct security_operations *ops);
-extern int mod_reg_security(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
                                             struct dentry *parent, void *data,
                                             const struct file_operations *fops);
@@ -1573,7 +1562,8 @@ extern struct dentry *securityfs_create_dir(const char *name, struct dentry *par
 extern void securityfs_remove(struct dentry *dentry);
 
 /* Security operations */
-int security_ptrace(struct task_struct *parent, struct task_struct *child);
+int security_ptrace(struct task_struct *parent, struct task_struct *child,
+                   unsigned int mode);
 int security_capget(struct task_struct *target,
                    kernel_cap_t *effective,
                    kernel_cap_t *inheritable,
@@ -1606,6 +1596,7 @@ int security_sb_alloc(struct super_block *sb);
 void security_sb_free(struct super_block *sb);
 int security_sb_copy_data(char *orig, char *copy);
 int security_sb_kern_mount(struct super_block *sb, void *data);
+int security_sb_show_options(struct seq_file *m, struct super_block *sb);
 int security_sb_statfs(struct dentry *dentry);
 int security_sb_mount(char *dev_name, struct path *path,
                      char *type, unsigned long flags, void *data);
@@ -1617,8 +1608,6 @@ void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *d
 void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
 int security_sb_pivotroot(struct path *old_path, struct path *new_path);
 void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
-int security_sb_get_mnt_opts(const struct super_block *sb,
-                               struct security_mnt_opts *opts);
 int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
 void security_sb_clone_mnt_opts(const struct super_block *oldsb,
                                struct super_block *newsb);
@@ -1755,9 +1744,11 @@ static inline int security_init(void)
        return 0;
 }
 
-static inline int security_ptrace(struct task_struct *parent, struct task_struct *child)
+static inline int security_ptrace(struct task_struct *parent,
+                                 struct task_struct *child,
+                                 unsigned int mode)
 {
-       return cap_ptrace(parent, child);
+       return cap_ptrace(parent, child, mode);
 }
 
 static inline int security_capget(struct task_struct *target,
@@ -1881,6 +1872,12 @@ static inline int security_sb_kern_mount(struct super_block *sb, void *data)
        return 0;
 }
 
+static inline int security_sb_show_options(struct seq_file *m,
+                                          struct super_block *sb)
+{
+       return 0;
+}
+
 static inline int security_sb_statfs(struct dentry *dentry)
 {
        return 0;
@@ -1927,12 +1924,6 @@ static inline int security_sb_pivotroot(struct path *old_path,
 static inline void security_sb_post_pivotroot(struct path *old_path,
                                              struct path *new_path)
 { }
-static inline int security_sb_get_mnt_opts(const struct super_block *sb,
-                                          struct security_mnt_opts *opts)
-{
-       security_init_mnt_opts(opts);
-       return 0;
-}
 
 static inline int security_sb_set_mnt_opts(struct super_block *sb,
                                           struct security_mnt_opts *opts)
index aab3a4c..813be59 100644 (file)
@@ -27,11 +27,24 @@ static inline int reacquire_kernel_lock(struct task_struct *task)
 extern void __lockfunc lock_kernel(void)       __acquires(kernel_lock);
 extern void __lockfunc unlock_kernel(void)     __releases(kernel_lock);
 
+/*
+ * Various legacy drivers don't really need the BKL in a specific
+ * function, but they *do* need to know that the BKL became available.
+ * This function just avoids wrapping a bunch of lock/unlock pairs
+ * around code which doesn't really need it.
+ */
+static inline void cycle_kernel_lock(void)
+{
+       lock_kernel();
+       unlock_kernel();
+}
+
 #else
 
 #define lock_kernel()                          do { } while(0)
 #define unlock_kernel()                                do { } while(0)
 #define release_kernel_lock(task)              do { } while(0)
+#define cycle_kernel_lock()                    do { } while(0)
 #define reacquire_kernel_lock(task)            0
 #define kernel_locked()                                1
 
index f462439..bd91987 100644 (file)
@@ -105,6 +105,8 @@ extern int vm_highmem_is_dirtyable;
 extern int block_dump;
 extern int laptop_mode;
 
+extern unsigned long determine_dirtyable_memory(void);
+
 extern int dirty_ratio_handler(struct ctl_table *table, int write,
                struct file *filp, void __user *buffer, size_t *lenp,
                loff_t *ppos);
diff --git a/include/pcmcia/bulkmem.h b/include/pcmcia/bulkmem.h
deleted file mode 100644 (file)
index 6bc7472..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * bulkmem.h -- Definitions for bulk memory services
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * The initial developer of the original code is David A. Hinds
- * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
- * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
- *
- * (C) 1999            David A. Hinds
- */
-
-#ifndef _LINUX_BULKMEM_H
-#define _LINUX_BULKMEM_H
-
-/* For GetFirstRegion and GetNextRegion */
-typedef struct region_info_t {
-    u_int              Attributes;
-    u_int              CardOffset;
-    u_int              RegionSize;
-    u_int              AccessSpeed;
-    u_int              BlockSize;
-    u_int              PartMultiple;
-    u_char             JedecMfr, JedecInfo;
-    memory_handle_t    next;
-} region_info_t;
-
-#define REGION_TYPE            0x0001
-#define REGION_TYPE_CM         0x0000
-#define REGION_TYPE_AM         0x0001
-#define REGION_PREFETCH                0x0008
-#define REGION_CACHEABLE       0x0010
-#define REGION_BAR_MASK                0xe000
-#define REGION_BAR_SHIFT       13
-
-int pcmcia_get_first_region(struct pcmcia_device *handle, region_info_t *rgn);
-int pcmcia_get_next_region(struct pcmcia_device *handle, region_info_t *rgn);
-
-#endif /* _LINUX_BULKMEM_H */
index d3bbb19..e2e10c1 100644 (file)
@@ -595,7 +595,7 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
 int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
 int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse);
 
-int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_t *info);
+int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned int *count);
 
 /* ... but use these wrappers instead */
 #define pcmcia_get_first_tuple(p_dev, tuple) \
index 87a260e..45d84b2 100644 (file)
@@ -373,9 +373,6 @@ struct pcmcia_socket;
 
 int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, conf_reg_t *reg);
 int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, config_info_t *config);
-int pcmcia_get_first_window(window_handle_t *win, win_req_t *req);
-int pcmcia_get_next_window(window_handle_t *win, win_req_t *req);
-int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status);
 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
 int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
index 9a6bcc4..f402a0f 100644 (file)
@@ -21,7 +21,8 @@
 #include <sys/types.h>
 #endif
 
-#if defined(__arm__) || defined(__mips__) || defined(__avr32__)
+#if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
+       defined(__bfin__)
 /* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
 typedef u_int   ioaddr_t;
 #else
@@ -33,9 +34,6 @@ typedef u_int event_t;
 typedef u_char cisdata_t;
 typedef u_short        page_t;
 
-struct pcmcia_device;
-typedef struct pcmcia_device *client_handle_t;
-
 struct window_t;
 typedef struct window_t *window_handle_t;
 
index f047a1f..b316027 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/mod_devicetable.h>
 #endif
 
-#include <pcmcia/bulkmem.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/device_id.h>
 
@@ -51,6 +50,24 @@ typedef struct mtd_info_t {
     u_int              CardOffset;
 } mtd_info_t;
 
+typedef struct region_info_t {
+    u_int              Attributes;
+    u_int              CardOffset;
+    u_int              RegionSize;
+    u_int              AccessSpeed;
+    u_int              BlockSize;
+    u_int              PartMultiple;
+    u_char             JedecMfr, JedecInfo;
+    memory_handle_t    next;
+} region_info_t;
+#define REGION_TYPE            0x0001
+#define REGION_TYPE_CM         0x0000
+#define REGION_TYPE_AM         0x0001
+#define REGION_PREFETCH                0x0008
+#define REGION_CACHEABLE       0x0010
+#define REGION_BAR_MASK                0xe000
+#define REGION_BAR_SHIFT       13
+
 typedef union ds_ioctl_arg_t {
     adjust_t           adjust;
     config_info_t      config;
index f95dca0..ed919dd 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
-#include <pcmcia/bulkmem.h>
 #ifdef CONFIG_CARDBUS
 #include <linux/pci.h>
 #endif
@@ -136,8 +135,14 @@ struct pccard_resource_ops {
        struct resource* (*find_mem)    (unsigned long base, unsigned long num,
                                         unsigned long align, int low,
                                         struct pcmcia_socket *s);
-       int     (*adjust_resource)      (struct pcmcia_socket *s,
-                                        adjust_t *adj);
+       int     (*add_io)               (struct pcmcia_socket *s,
+                                        unsigned int action,
+                                        unsigned long r_start,
+                                        unsigned long r_end);
+       int     (*add_mem)              (struct pcmcia_socket *s,
+                                        unsigned int action,
+                                        unsigned long r_start,
+                                        unsigned long r_end);
        int     (*init)                 (struct pcmcia_socket *s);
        void    (*exit)                 (struct pcmcia_socket *s);
 };
@@ -245,7 +250,6 @@ struct pcmcia_socket {
 
        struct task_struct              *thread;
        struct completion               thread_done;
-       wait_queue_head_t               thread_wait;
        spinlock_t                      thread_lock;    /* protects thread_events */
        unsigned int                    thread_events;
 
diff --git a/include/pcmcia/version.h b/include/pcmcia/version.h
deleted file mode 100644 (file)
index 5ad9c5e..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/* version.h 1.94 2000/10/03 17:55:48 (David Hinds) */
-
-/* This file will be removed, please don't include it */
diff --git a/include/sound/ad1843.h b/include/sound/ad1843.h
new file mode 100644 (file)
index 0000000..b236a9d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
+ * Copyright 2008 Thomas Bogendoerfer <tsbogend@franken.de>
+ */
+
+#ifndef __SOUND_AD1843_H
+#define __SOUND_AD1843_H
+
+struct snd_ad1843 {
+       void *chip;
+       int (*read)(void *chip, int reg);
+       int (*write)(void *chip, int reg, int val);
+};
+
+#define AD1843_GAIN_RECLEV 0
+#define AD1843_GAIN_LINE   1
+#define AD1843_GAIN_LINE_2 2
+#define AD1843_GAIN_MIC    3
+#define AD1843_GAIN_PCM_0  4
+#define AD1843_GAIN_PCM_1  5
+#define AD1843_GAIN_SIZE   (AD1843_GAIN_PCM_1+1)
+
+int ad1843_get_gain_max(struct snd_ad1843 *ad1843, int id);
+int ad1843_get_gain(struct snd_ad1843 *ad1843, int id);
+int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval);
+int ad1843_get_recsrc(struct snd_ad1843 *ad1843);
+int ad1843_set_recsrc(struct snd_ad1843 *ad1843, int newsrc);
+void ad1843_setup_dac(struct snd_ad1843 *ad1843,
+                     unsigned int id,
+                     unsigned int framerate,
+                     snd_pcm_format_t fmt,
+                     unsigned int channels);
+void ad1843_shutdown_dac(struct snd_ad1843 *ad1843,
+                        unsigned int id);
+void ad1843_setup_adc(struct snd_ad1843 *ad1843,
+                     unsigned int framerate,
+                     snd_pcm_format_t fmt,
+                     unsigned int channels);
+void ad1843_shutdown_adc(struct snd_ad1843 *ad1843);
+int ad1843_init(struct snd_ad1843 *ad1843);
+
+#endif /* __SOUND_AD1843_H */
index 3dc1291..4721b4b 100644 (file)
@@ -129,9 +129,6 @@ int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn);
 #define snd_ctl_unregister_ioctl_compat(fcn)
 #endif
 
-int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *control);
-int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file, struct snd_ctl_elem_value *control);
-
 static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
 {
        return id->numid - kctl->id.numid;
index 695ee53..558b962 100644 (file)
@@ -412,13 +412,13 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
 
 #endif /* CONFIG_SND_DEBUG */
 
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
 /**
  * snd_printdd - debug printk
  * @format: format string
  *
  * Works like snd_printk() for debugging purposes.
- * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
+ * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
  */
 #define snd_printdd(format, args...) snd_printk(format, ##args)
 #else
@@ -442,7 +442,7 @@ struct snd_pci_quirk {
        unsigned short subvendor;       /* PCI subvendor ID */
        unsigned short subdevice;       /* PCI subdevice ID */
        int value;                      /* value */
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        const char *name;               /* name of the device (optional) */
 #endif
 };
@@ -450,7 +450,7 @@ struct snd_pci_quirk {
 #define _SND_PCI_QUIRK_ID(vend,dev) \
        .subvendor = (vend), .subdevice = (dev)
 #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
 #define SND_PCI_QUIRK(vend,dev,xname,val) \
        {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
 #else
index e8d1f3e..9264753 100644 (file)
 #define CS4236_RIGHT_WAVE      0x1c    /* right wavetable serial port volume */
 #define CS4236_VERSION         0x9c    /* chip version and ID */
 
+/* definitions for extended registers - OPTI93X */
+#define OPTi931_AUX_LEFT_INPUT 0x10
+#define OPTi931_AUX_RIGHT_INPUT        0x11
+#define OPTi93X_MIC_LEFT_INPUT 0x14
+#define OPTi93X_MIC_RIGHT_INPUT        0x15
+#define OPTi93X_OUT_LEFT       0x16
+#define OPTi93X_OUT_RIGHT      0x17
+
 #endif /* __SOUND_CS4231_REGS_H */
index 66055d7..f0785f9 100644 (file)
@@ -58,6 +58,7 @@
 /* compatible, but clones */
 #define CS4231_HW_INTERWAVE     0x1000 /* InterWave chip */
 #define CS4231_HW_OPL3SA2       0x1101 /* OPL3-SA2 chip, similar to cs4231 */
+#define CS4231_HW_OPTI93X      0x1102  /* Opti 930/931/933 */
 
 /* defines for codec.hwshare */
 #define CS4231_HWSHARE_IRQ     (1<<0)
@@ -120,6 +121,8 @@ unsigned char snd_cs4236_ext_in(struct snd_cs4231 *chip, unsigned char reg);
 void snd_cs4231_mce_up(struct snd_cs4231 *chip);
 void snd_cs4231_mce_down(struct snd_cs4231 *chip);
 
+void snd_cs4231_overrange(struct snd_cs4231 *chip);
+
 irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id);
 
 const char *snd_cs4231_chip_id(struct snd_cs4231 *chip);
index 7b7b9b1..10ee28e 100644 (file)
@@ -1670,6 +1670,7 @@ struct snd_emu_chip_details {
        unsigned char spi_dac;      /* SPI interface for DAC */
        unsigned char i2c_adc;      /* I2C interface for ADC */
        unsigned char adc_1361t;    /* Use Philips 1361T ADC */
+       unsigned char invert_shared_spdif; /* analog/digital switch inverted */
        const char *driver;
        const char *name;
        const char *id;         /* for backward compatibility - can be NULL if not needed */
index f023c1b..3d9afb6 100644 (file)
@@ -105,7 +105,7 @@ int snd_seq_event_port_attach(int client, struct snd_seq_port_callback *pcbp,
                              int cap, int type, int midi_channels, int midi_voices, char *portname);
 int snd_seq_event_port_detach(int client, int port);
 
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
 void snd_seq_autoload_lock(void);
 void snd_seq_autoload_unlock(void);
 #else
index a105b01..3030fdc 100644 (file)
 {      .id = snd_soc_dapm_adc, .name = wname, .sname = stname, .reg = wreg, \
        .shift = wshift, .invert = winvert}
 
+/* generic register modifier widget */
+#define SND_SOC_DAPM_REG(wid, wname, wreg, wshift, wmask, won_val, woff_val) \
+{      .id = wid, .name = wname, .kcontrols = NULL, .num_kcontrols = 0, \
+       .reg = -((wreg) + 1), .shift = wshift, .mask = wmask, \
+       .on_val = won_val, .off_val = woff_val, .event = dapm_reg_event, \
+       .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD}
+
 /* dapm kcontrol types */
 #define SOC_DAPM_SINGLE(xname, reg, shift, max, invert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
@@ -193,6 +200,7 @@ struct snd_soc_dapm_widget;
 enum snd_soc_dapm_type;
 struct snd_soc_dapm_path;
 struct snd_soc_dapm_pin;
+struct snd_soc_dapm_route;
 
 /* dapm controls */
 int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
@@ -205,25 +213,32 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
 int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
        const struct snd_soc_dapm_widget *widget);
+int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
+       const struct snd_soc_dapm_widget *widget,
+       int num);
 
 /* dapm path setup */
-int snd_soc_dapm_connect_input(struct snd_soc_codec *codec,
+int  __deprecated snd_soc_dapm_connect_input(struct snd_soc_codec *codec,
        const char *sink_name, const char *control_name, const char *src_name);
 int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec);
 void snd_soc_dapm_free(struct snd_soc_device *socdev);
+int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
+                           const struct snd_soc_dapm_route *route, int num);
 
 /* dapm events */
 int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
        int event);
-int snd_soc_dapm_device_event(struct snd_soc_device *socdev, int event);
+int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
+       enum snd_soc_bias_level level);
 
 /* dapm sys fs - used by the core */
 int snd_soc_dapm_sys_add(struct device *dev);
 
-/* dapm audio endpoint control */
-int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
-       char *pin, int status);
-int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec);
+/* dapm audio pin control and status */
+int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin);
+int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin);
+int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin);
+int snd_soc_dapm_sync(struct snd_soc_codec *codec);
 
 /* dapm widget types */
 enum snd_soc_dapm_type {
@@ -245,6 +260,18 @@ enum snd_soc_dapm_type {
        snd_soc_dapm_post,                      /* machine specific post widget - exec last */
 };
 
+/*
+ * DAPM audio route definition.
+ *
+ * Defines an audio route originating at source via control and finishing
+ * at sink.
+ */
+struct snd_soc_dapm_route {
+       const char *sink;
+       const char *control;
+       const char *source;
+};
+
 /* dapm audio path between two widgets */
 struct snd_soc_dapm_path {
        char *name;
@@ -277,6 +304,9 @@ struct snd_soc_dapm_widget {
        unsigned char shift;                    /* bits to shift */
        unsigned int saved_value;               /* widget saved value */
        unsigned int value;                             /* widget current value */
+       unsigned int mask;                      /* non-shifted mask */
+       unsigned int on_val;                    /* on state value */
+       unsigned int off_val;                   /* off state value */
        unsigned char power:1;                  /* block power status */
        unsigned char invert:1;                 /* invert the power bit */
        unsigned char active:1;                 /* active stream on DAC, ADC's */
index d3c8c03..1890d87 100644 (file)
        .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
        .private_value = (reg_left) | ((shift) << 8)  | \
                ((max) << 12) | ((invert) << 20) | ((reg_right) << 24) }
+#define SOC_DOUBLE_S8_TLV(xname, reg, min, max, tlv_array) \
+{      .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
+       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
+                 SNDRV_CTL_ELEM_ACCESS_READWRITE, \
+       .tlv.p  = (tlv_array), \
+       .info   = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
+       .put    = snd_soc_put_volsw_s8, \
+       .private_value = (reg) | (((signed char)max) << 16) | \
+                        (((signed char)min) << 24) }
 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
 {      .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
        .mask = xmask, .texts = xtexts }
        .info = snd_soc_info_volsw, \
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
+#define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmask, xinvert,\
+        xhandler_get, xhandler_put, tlv_array) \
+{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
+       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
+                SNDRV_CTL_ELEM_ACCESS_READWRITE,\
+       .tlv.p = (tlv_array), \
+       .info = snd_soc_info_volsw, \
+       .get = xhandler_get, .put = xhandler_put, \
+       .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_bool_ext, \
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = (unsigned long)&xenum }
 
+/*
+ * Bias levels
+ *
+ * @ON:      Bias is fully on for audio playback and capture operations.
+ * @PREPARE: Prepare for audio operations. Called before DAPM switching for
+ *           stream start and stop operations.
+ * @STANDBY: Low power standby state when no playback/capture operations are
+ *           in progress. NOTE: The transition time between STANDBY and ON
+ *           should be as fast as possible and no longer than 10ms.
+ * @OFF:     Power Off. No restrictions on transition times.
+ */
+enum snd_soc_bias_level {
+       SND_SOC_BIAS_ON,
+       SND_SOC_BIAS_PREPARE,
+       SND_SOC_BIAS_STANDBY,
+       SND_SOC_BIAS_OFF,
+};
+
 /*
  * Digital Audio Interface (DAI) types
  */
@@ -185,8 +221,7 @@ struct snd_soc_pcm_stream;
 struct snd_soc_ops;
 struct snd_soc_dai_mode;
 struct snd_soc_pcm_runtime;
-struct snd_soc_codec_dai;
-struct snd_soc_cpu_dai;
+struct snd_soc_dai;
 struct snd_soc_codec;
 struct snd_soc_machine_config;
 struct soc_enum;
@@ -221,6 +256,27 @@ int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
        struct snd_ac97_bus_ops *ops, int num);
 void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
 
+/* Digital Audio Interface clocking API.*/
+int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
+       unsigned int freq, int dir);
+
+int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
+       int div_id, int div);
+
+int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
+       int pll_id, unsigned int freq_in, unsigned int freq_out);
+
+/* Digital Audio interface formatting */
+int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
+
+int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
+       unsigned int mask, int slots);
+
+int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
+
+/* Digital Audio Interface mute */
+int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute);
+
 /*
  *Controls
  */
@@ -249,6 +305,12 @@ int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
+int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_info *uinfo);
+int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol);
+int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol);
 
 /* SoC PCM stream information */
 struct snd_soc_pcm_stream {
@@ -272,87 +334,45 @@ struct snd_soc_ops {
        int (*trigger)(struct snd_pcm_substream *, int);
 };
 
-/* ASoC codec DAI ops */
-struct snd_soc_codec_ops {
-       /* codec DAI clocking configuration */
-       int (*set_sysclk)(struct snd_soc_codec_dai *codec_dai,
+/* ASoC DAI ops */
+struct snd_soc_dai_ops {
+       /* DAI clocking configuration */
+       int (*set_sysclk)(struct snd_soc_dai *dai,
                int clk_id, unsigned int freq, int dir);
-       int (*set_pll)(struct snd_soc_codec_dai *codec_dai,
+       int (*set_pll)(struct snd_soc_dai *dai,
                int pll_id, unsigned int freq_in, unsigned int freq_out);
-       int (*set_clkdiv)(struct snd_soc_codec_dai *codec_dai,
-               int div_id, int div);
+       int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div);
 
-       /* CPU DAI format configuration */
-       int (*set_fmt)(struct snd_soc_codec_dai *codec_dai,
-               unsigned int fmt);
-       int (*set_tdm_slot)(struct snd_soc_codec_dai *codec_dai,
+       /* DAI format configuration */
+       int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt);
+       int (*set_tdm_slot)(struct snd_soc_dai *dai,
                unsigned int mask, int slots);
-       int (*set_tristate)(struct snd_soc_codec_dai *, int tristate);
+       int (*set_tristate)(struct snd_soc_dai *dai, int tristate);
 
        /* digital mute */
-       int (*digital_mute)(struct snd_soc_codec_dai *, int mute);
-};
-
-/* ASoC cpu DAI ops */
-struct snd_soc_cpu_ops {
-       /* CPU DAI clocking configuration */
-       int (*set_sysclk)(struct snd_soc_cpu_dai *cpu_dai,
-               int clk_id, unsigned int freq, int dir);
-       int (*set_clkdiv)(struct snd_soc_cpu_dai *cpu_dai,
-               int div_id, int div);
-       int (*set_pll)(struct snd_soc_cpu_dai *cpu_dai,
-               int pll_id, unsigned int freq_in, unsigned int freq_out);
-
-       /* CPU DAI format configuration */
-       int (*set_fmt)(struct snd_soc_cpu_dai *cpu_dai,
-               unsigned int fmt);
-       int (*set_tdm_slot)(struct snd_soc_cpu_dai *cpu_dai,
-               unsigned int mask, int slots);
-       int (*set_tristate)(struct snd_soc_cpu_dai *, int tristate);
-};
-
-/* SoC Codec DAI */
-struct snd_soc_codec_dai {
-       char *name;
-       int id;
-       unsigned char type;
-
-       /* DAI capabilities */
-       struct snd_soc_pcm_stream playback;
-       struct snd_soc_pcm_stream capture;
-
-       /* DAI runtime info */
-       struct snd_soc_codec *codec;
-       unsigned int active;
-       unsigned char pop_wait:1;
-
-       /* ops */
-       struct snd_soc_ops ops;
-       struct snd_soc_codec_ops dai_ops;
-
-       /* DAI private data */
-       void *private_data;
+       int (*digital_mute)(struct snd_soc_dai *dai, int mute);
 };
 
-/* SoC CPU DAI */
-struct snd_soc_cpu_dai {
-
+/* SoC  DAI (Digital Audio Interface) */
+struct snd_soc_dai {
        /* DAI description */
        char *name;
        unsigned int id;
        unsigned char type;
 
        /* DAI callbacks */
-       int (*probe)(struct platform_device *pdev);
-       void (*remove)(struct platform_device *pdev);
+       int (*probe)(struct platform_device *pdev,
+                    struct snd_soc_dai *dai);
+       void (*remove)(struct platform_device *pdev,
+                      struct snd_soc_dai *dai);
        int (*suspend)(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai);
+               struct snd_soc_dai *dai);
        int (*resume)(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai);
+               struct snd_soc_dai *dai);
 
        /* ops */
        struct snd_soc_ops ops;
-       struct snd_soc_cpu_ops dai_ops;
+       struct snd_soc_dai_ops dai_ops;
 
        /* DAI capabilities */
        struct snd_soc_pcm_stream capture;
@@ -360,7 +380,9 @@ struct snd_soc_cpu_dai {
 
        /* DAI runtime info */
        struct snd_pcm_runtime *runtime;
-       unsigned char active:1;
+       struct snd_soc_codec *codec;
+       unsigned int active;
+       unsigned char pop_wait:1;
        void *dma_data;
 
        /* DAI private data */
@@ -374,7 +396,8 @@ struct snd_soc_codec {
        struct mutex mutex;
 
        /* callbacks */
-       int (*dapm_event)(struct snd_soc_codec *codec, int event);
+       int (*set_bias_level)(struct snd_soc_codec *,
+                             enum snd_soc_bias_level level);
 
        /* runtime */
        struct snd_card *card;
@@ -396,12 +419,12 @@ struct snd_soc_codec {
        /* dapm */
        struct list_head dapm_widgets;
        struct list_head dapm_paths;
-       unsigned int dapm_state;
-       unsigned int suspend_dapm_state;
+       enum snd_soc_bias_level bias_level;
+       enum snd_soc_bias_level suspend_bias_level;
        struct delayed_work delayed_work;
 
        /* codec DAI's */
-       struct snd_soc_codec_dai *dai;
+       struct snd_soc_dai *dai;
        unsigned int num_dai;
 };
 
@@ -420,12 +443,12 @@ struct snd_soc_platform {
        int (*probe)(struct platform_device *pdev);
        int (*remove)(struct platform_device *pdev);
        int (*suspend)(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai);
+               struct snd_soc_dai *dai);
        int (*resume)(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai);
+               struct snd_soc_dai *dai);
 
        /* pcm creation and destruction */
-       int (*pcm_new)(struct snd_card *, struct snd_soc_codec_dai *,
+       int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
                struct snd_pcm *);
        void (*pcm_free)(struct snd_pcm *);
 
@@ -439,8 +462,8 @@ struct snd_soc_dai_link  {
        char *stream_name;              /* Stream name */
 
        /* DAI */
-       struct snd_soc_codec_dai *codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai;
+       struct snd_soc_dai *codec_dai;
+       struct snd_soc_dai *cpu_dai;
 
        /* machine stream operations */
        struct snd_soc_ops *ops;
@@ -467,7 +490,8 @@ struct snd_soc_machine {
        int (*resume_post)(struct platform_device *pdev);
 
        /* callbacks */
-       int (*dapm_event)(struct snd_soc_machine *, int event);
+       int (*set_bias_level)(struct snd_soc_machine *,
+                             enum snd_soc_bias_level level);
 
        /* CPU <--> Codec DAI links  */
        struct snd_soc_dai_link *dai_link;
@@ -482,6 +506,7 @@ struct snd_soc_device {
        struct snd_soc_codec *codec;
        struct snd_soc_codec_device *codec_dev;
        struct delayed_work delayed_work;
+       struct work_struct deferred_resume_work;
        void *codec_data;
 };
 
index 2e564bf..110d5dc 100644 (file)
@@ -15,8 +15,6 @@
  *                           features support
  */
 
-/* $Id: uda1341.h,v 1.8 2005/11/17 14:17:21 tiwai Exp $ */
-
 #define UDA1341_ALSA_NAME "snd-uda1341"
 
 /*
index ed6fb2e..6b78aff 100644 (file)
@@ -1,3 +1,3 @@
-/* include/version.h.  Generated by alsa/ksync script.  */
-#define CONFIG_SND_VERSION "1.0.16"
+/* include/version.h */
+#define CONFIG_SND_VERSION "1.0.17"
 #define CONFIG_SND_DATE ""
index acd8e06..67c4436 100644 (file)
@@ -32,6 +32,7 @@ void unbind_from_irqhandler(unsigned int irq, void *dev_id);
 
 void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
 int resend_irq_on_evtchn(unsigned int irq);
+void rebind_evtchn_irq(int evtchn, int irq);
 
 static inline void notify_remote_via_evtchn(int port)
 {
@@ -40,4 +41,7 @@ static inline void notify_remote_via_evtchn(int port)
 }
 
 extern void notify_remote_via_irq(int irq);
+
+extern void xen_irq_resume(void);
+
 #endif /* _XEN_EVENTS_H */
index 4662048..a40f1cd 100644 (file)
@@ -51,6 +51,9 @@ struct gnttab_free_callback {
        u16 count;
 };
 
+int gnttab_suspend(void);
+int gnttab_resume(void);
+
 int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
                                int readonly);
 
index 21c0ecf..98b79bc 100644 (file)
@@ -3,4 +3,13 @@
 
 extern struct console xenboot_console;
 
+#ifdef CONFIG_HVC_XEN
+void xen_console_resume(void);
+#else
+static inline void xen_console_resume(void) { }
+#endif
+
+void xen_raw_console_write(const char *str);
+void xen_raw_printk(const char *fmt, ...);
+
 #endif /* XEN_HVC_CONSOLE_H */
index a64d3df..7a8262c 100644 (file)
  */
 #define XEN_ELFNOTE_BSD_SYMTAB    11
 
+/*
+ * The lowest address the hypervisor hole can begin at (numeric).
+ *
+ * This must not be set higher than HYPERVISOR_VIRT_START. Its presence
+ * also indicates to the hypervisor that the kernel can deal with the
+ * hole starting at a higher address.
+ */
+#define XEN_ELFNOTE_HV_START_LOW  12
+
+/*
+ * List of maddr_t-sized mask/value pairs describing how to recognize
+ * (non-present) L1 page table entries carrying valid MFNs (numeric).
+ */
+#define XEN_ELFNOTE_L1_MFN_VALID  13
+
+/*
+ * Whether or not the guest supports cooperative suspend cancellation.
+ */
+#define XEN_ELFNOTE_SUSPEND_CANCEL 14
+
 #endif /* __XEN_PUBLIC_ELFNOTE_H__ */
 
 /*
index d73228d..f51b641 100644 (file)
@@ -38,6 +38,9 @@
  */
 #define XENFEAT_pae_pgdir_above_4gb        4
 
+/* x86: Does this Xen host support the MMU_PT_UPDATE_PRESERVE_AD hypercall? */
+#define XENFEAT_mmu_pt_update_preserve_ad  5
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
index 5a934dd..974a51e 100644 (file)
@@ -49,11 +49,27 @@ struct xenfb_update {
        int32_t height;         /* rect height */
 };
 
+/*
+ * Framebuffer resize notification event
+ * Capable backend sets feature-resize in xenstore.
+ */
+#define XENFB_TYPE_RESIZE 3
+
+struct xenfb_resize {
+       uint8_t type;           /* XENFB_TYPE_RESIZE */
+       int32_t width;          /* width in pixels */
+       int32_t height;         /* height in pixels */
+       int32_t stride;         /* stride in bytes */
+       int32_t depth;          /* depth in bits */
+       int32_t offset;         /* start offset within framebuffer */
+};
+
 #define XENFB_OUT_EVENT_SIZE 40
 
 union xenfb_out_event {
        uint8_t type;
        struct xenfb_update update;
+       struct xenfb_resize resize;
        char pad[XENFB_OUT_EVENT_SIZE];
 };
 
@@ -105,15 +121,18 @@ struct xenfb_page {
         * Each directory page holds PAGE_SIZE / sizeof(*pd)
         * framebuffer pages, and can thus map up to PAGE_SIZE *
         * PAGE_SIZE / sizeof(*pd) bytes.  With PAGE_SIZE == 4096 and
-        * sizeof(unsigned long) == 4, that's 4 Megs.  Two directory
-        * pages should be enough for a while.
+        * sizeof(unsigned long) == 4/8, that's 4 Megs 32 bit and 2
+        * Megs 64 bit.  256 directories give enough room for a 512
+        * Meg framebuffer with a max resolution of 12,800x10,240.
+        * Should be enough for a while with room leftover for
+        * expansion.
         */
-       unsigned long pd[2];
+       unsigned long pd[256];
 };
 
 /*
- * Wart: xenkbd needs to know resolution.  Put it here until a better
- * solution is found, but don't leak it to the backend.
+ * Wart: xenkbd needs to know default resolution.  Put it here until a
+ * better solution is found, but don't leak it to the backend.
  */
 #ifdef __KERNEL__
 #define XENFB_WIDTH 800
index fb97f42..8066c78 100644 (file)
@@ -49,6 +49,7 @@ struct xenkbd_motion {
        uint8_t type;           /* XENKBD_TYPE_MOTION */
        int32_t rel_x;          /* relative X motion */
        int32_t rel_y;          /* relative Y motion */
+       int32_t rel_z;          /* relative Z motion (wheel) */
 };
 
 struct xenkbd_key {
@@ -61,6 +62,7 @@ struct xenkbd_position {
        uint8_t type;           /* XENKBD_TYPE_POS */
        int32_t abs_x;          /* absolute X position (in FB pixels) */
        int32_t abs_y;          /* absolute Y position (in FB pixels) */
+       int32_t rel_z;          /* relative Z motion (wheel) */
 };
 
 #define XENKBD_IN_EVENT_SIZE 40
index da76846..af36ead 100644 (file)
@@ -29,7 +29,7 @@ struct xen_memory_reservation {
      *   OUT: GMFN bases of extents that were allocated
      *   (NB. This command also updates the mach_to_phys translation table)
      */
-    ulong extent_start;
+    GUEST_HANDLE(ulong) extent_start;
 
     /* Number of extents, and size/alignment of each (2^extent_order pages). */
     unsigned long  nr_extents;
@@ -50,6 +50,7 @@ struct xen_memory_reservation {
     domid_t        domid;
 
 };
+DEFINE_GUEST_HANDLE_STRUCT(xen_memory_reservation);
 
 /*
  * Returns the maximum machine frame number of mapped RAM in this system.
@@ -85,7 +86,7 @@ struct xen_machphys_mfn_list {
      * any large discontiguities in the machine address space, 2MB gaps in
      * the machphys table will be represented by an MFN base of zero.
      */
-    ulong extent_start;
+    GUEST_HANDLE(ulong) extent_start;
 
     /*
      * Number of extents written to the above array. This will be smaller
@@ -93,6 +94,7 @@ struct xen_machphys_mfn_list {
      */
     unsigned int nr_extents;
 };
+DEFINE_GUEST_HANDLE_STRUCT(xen_machphys_mfn_list);
 
 /*
  * Sets the GPFN at which a particular page appears in the specified guest's
@@ -115,6 +117,7 @@ struct xen_add_to_physmap {
     /* GPFN where the source mapping page should appear. */
     unsigned long gpfn;
 };
+DEFINE_GUEST_HANDLE_STRUCT(xen_add_to_physmap);
 
 /*
  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
@@ -129,13 +132,14 @@ struct xen_translate_gpfn_list {
     unsigned long nr_gpfns;
 
     /* List of GPFNs to translate. */
-    ulong gpfn_list;
+    GUEST_HANDLE(ulong) gpfn_list;
 
     /*
      * Output list to contain MFN translations. May be the same as the input
      * list (in which case each input GPFN is overwritten with the output MFN).
      */
-    ulong mfn_list;
+    GUEST_HANDLE(ulong) mfn_list;
 };
+DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list);
 
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
index 819a033..2befa3e 100644 (file)
  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
  *             The frame must belong to the FD, if one is specified.
  * val      -- Value to write into the mapping entry.
+ *
+ * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
+ * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
+ * with those in @val.
  */
-#define MMU_NORMAL_PT_UPDATE     0 /* checked '*ptr = val'. ptr is MA.       */
-#define MMU_MACHPHYS_UPDATE      1 /* ptr = MA of frame to modify entry for  */
+#define MMU_NORMAL_PT_UPDATE      0 /* checked '*ptr = val'. ptr is MA.       */
+#define MMU_MACHPHYS_UPDATE       1 /* ptr = MA of frame to modify entry for  */
+#define MMU_PT_UPDATE_PRESERVE_AD 2 /* atomically: *ptr = val | (*ptr&(A|D)) */
 
 /*
  * MMU EXTENDED OPERATIONS
index 10ddfe0..a706d6a 100644 (file)
@@ -5,4 +5,10 @@
 
 DECLARE_PER_CPU(struct vcpu_info *, xen_vcpu);
 
+void xen_pre_suspend(void);
+void xen_post_suspend(int suspend_cancelled);
+
+void xen_mm_pin_all(void);
+void xen_mm_unpin_all(void);
+
 #endif /* INCLUDE_XEN_OPS_H */
index ecb3822..7963e3f 100644 (file)
@@ -8,7 +8,9 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/timex.h>
+#include <linux/smp.h>
 
+unsigned long lpj_fine;
 unsigned long preset_lpj;
 static int __init lpj_setup(char *str)
 {
@@ -33,9 +35,9 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
        unsigned long pre_start, start, post_start;
        unsigned long pre_end, end, post_end;
        unsigned long start_jiffies;
-       unsigned long tsc_rate_min, tsc_rate_max;
-       unsigned long good_tsc_sum = 0;
-       unsigned long good_tsc_count = 0;
+       unsigned long timer_rate_min, timer_rate_max;
+       unsigned long good_timer_sum = 0;
+       unsigned long good_timer_count = 0;
        int i;
 
        if (read_current_timer(&pre_start) < 0 )
@@ -79,22 +81,24 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
                }
                read_current_timer(&post_end);
 
-               tsc_rate_max = (post_end - pre_start) / DELAY_CALIBRATION_TICKS;
-               tsc_rate_min = (pre_end - post_start) / DELAY_CALIBRATION_TICKS;
+               timer_rate_max = (post_end - pre_start) /
+                                       DELAY_CALIBRATION_TICKS;
+               timer_rate_min = (pre_end - post_start) /
+                                       DELAY_CALIBRATION_TICKS;
 
                /*
-                * If the upper limit and lower limit of the tsc_rate is
+                * If the upper limit and lower limit of the timer_rate is
                 * >= 12.5% apart, redo calibration.
                 */
                if (pre_start != 0 && pre_end != 0 &&
-                   (tsc_rate_max - tsc_rate_min) < (tsc_rate_max >> 3)) {
-                       good_tsc_count++;
-                       good_tsc_sum += tsc_rate_max;
+                   (timer_rate_max - timer_rate_min) < (timer_rate_max >> 3)) {
+                       good_timer_count++;
+                       good_timer_sum += timer_rate_max;
                }
        }
 
-       if (good_tsc_count)
-               return (good_tsc_sum/good_tsc_count);
+       if (good_timer_count)
+               return (good_timer_sum/good_timer_count);
 
        printk(KERN_WARNING "calibrate_delay_direct() failed to get a good "
               "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n");
@@ -108,6 +112,10 @@ static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;}
  * This is the number of bits of precision for the loops_per_jiffy.  Each
  * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
  * better than 1%
+ * For the boot cpu we can skip the delay calibration and assign it a value
+ * calculated based on the timer frequency.
+ * For the rest of the CPUs we cannot assume that the timer frequency is same as
+ * the cpu frequency, hence do the calibration for those.
  */
 #define LPS_PREC 8
 
@@ -118,20 +126,20 @@ void __cpuinit calibrate_delay(void)
 
        if (preset_lpj) {
                loops_per_jiffy = preset_lpj;
-               printk("Calibrating delay loop (skipped)... "
-                       "%lu.%02lu BogoMIPS preset\n",
-                       loops_per_jiffy/(500000/HZ),
-                       (loops_per_jiffy/(5000/HZ)) % 100);
+               printk(KERN_INFO
+                       "Calibrating delay loop (skipped) preset value.. ");
+       } else if ((smp_processor_id() == 0) && lpj_fine) {
+               loops_per_jiffy = lpj_fine;
+               printk(KERN_INFO
+                       "Calibrating delay loop (skipped), "
+                       "value calculated using timer frequency.. ");
        } else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
-               printk("Calibrating delay using timer specific routine.. ");
-               printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
-                       loops_per_jiffy/(500000/HZ),
-                       (loops_per_jiffy/(5000/HZ)) % 100,
-                       loops_per_jiffy);
+               printk(KERN_INFO
+                       "Calibrating delay using timer specific routine.. ");
        } else {
                loops_per_jiffy = (1<<12);
 
-               printk(KERN_DEBUG "Calibrating delay loop... ");
+               printk(KERN_INFO "Calibrating delay loop... ");
                while ((loops_per_jiffy <<= 1) != 0) {
                        /* wait for "start of" clock tick */
                        ticks = jiffies;
@@ -161,12 +169,8 @@ void __cpuinit calibrate_delay(void)
                        if (jiffies != ticks)   /* longer than 1 tick */
                                loops_per_jiffy &= ~loopbit;
                }
-
-               /* Round the value and print it */
-               printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
-                       loops_per_jiffy/(500000/HZ),
-                       (loops_per_jiffy/(5000/HZ)) % 100,
-                       loops_per_jiffy);
        }
-
+       printk(KERN_INFO "%lu.%02lu BogoMIPS (lpj=%lu)\n",
+                       loops_per_jiffy/(500000/HZ),
+                       (loops_per_jiffy/(5000/HZ)) % 100, loops_per_jiffy);
 }
index 1c9938a..f6328e1 100644 (file)
@@ -3,7 +3,7 @@
 #
 
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
-           exit.o itimer.o time.o softirq.o resource.o \
+           cpu.o exit.o itimer.o time.o softirq.o resource.o \
            sysctl.o capability.o ptrace.o timer.o user.o \
            signal.o sys.o kmod.o workqueue.o pid.o \
            rcupdate.o extable.o params.o posix-timers.o \
@@ -11,6 +11,18 @@ obj-y     = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
            hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
            notifier.o ksysfs.o pm_qos_params.o sched_clock.o
 
+CFLAGS_REMOVE_sched.o = -mno-spe
+
+ifdef CONFIG_FTRACE
+# Do not trace debug files and internal ftrace files
+CFLAGS_REMOVE_lockdep.o = -pg
+CFLAGS_REMOVE_lockdep_proc.o = -pg
+CFLAGS_REMOVE_mutex-debug.o = -pg
+CFLAGS_REMOVE_rtmutex-debug.o = -pg
+CFLAGS_REMOVE_cgroup-debug.o = -pg
+CFLAGS_REMOVE_sched_clock.o = -pg
+endif
+
 obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
 obj-y += time/
@@ -27,7 +39,7 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
 obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
 obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
-obj-$(CONFIG_SMP) += cpu.o spinlock.o
+obj-$(CONFIG_SMP) += spinlock.o
 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
 obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
 obj-$(CONFIG_UID16) += uid16.o
@@ -69,6 +81,9 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
 obj-$(CONFIG_MARKERS) += marker.o
 obj-$(CONFIG_LATENCYTOP) += latencytop.o
+obj-$(CONFIG_FTRACE) += trace/
+obj-$(CONFIG_TRACING) += trace/
+obj-$(CONFIG_SMP) += sched_cpupri.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
index c77bc3a..b11f06d 100644 (file)
 #include <linux/stop_machine.h>
 #include <linux/mutex.h>
 
+/*
+ * Represents all cpu's present in the system
+ * In systems capable of hotplug, this map could dynamically grow
+ * as new cpu's are detected in the system via any platform specific
+ * method, such as ACPI for e.g.
+ */
+cpumask_t cpu_present_map __read_mostly;
+EXPORT_SYMBOL(cpu_present_map);
+
+#ifndef CONFIG_SMP
+
+/*
+ * Represents all cpu's that are currently online.
+ */
+cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL;
+EXPORT_SYMBOL(cpu_online_map);
+
+cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL;
+EXPORT_SYMBOL(cpu_possible_map);
+
+#else /* CONFIG_SMP */
+
 /* Serializes the updates to cpu_online_map, cpu_present_map */
 static DEFINE_MUTEX(cpu_add_remove_lock);
 
@@ -403,3 +425,5 @@ out:
        cpu_maps_update_done();
 }
 #endif /* CONFIG_PM_SLEEP_SMP */
+
+#endif /* CONFIG_SMP */
index 798b3ab..459d601 100644 (file)
@@ -1194,6 +1194,15 @@ static int cpuset_can_attach(struct cgroup_subsys *ss,
 
        if (cpus_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed))
                return -ENOSPC;
+       if (tsk->flags & PF_THREAD_BOUND) {
+               cpumask_t mask;
+
+               mutex_lock(&callback_mutex);
+               mask = cs->cpus_allowed;
+               mutex_unlock(&callback_mutex);
+               if (!cpus_equal(tsk->cpus_allowed, mask))
+                       return -EINVAL;
+       }
 
        return security_task_setscheduler(tsk, 0, NULL);
 }
@@ -1207,11 +1216,14 @@ static void cpuset_attach(struct cgroup_subsys *ss,
        struct mm_struct *mm;
        struct cpuset *cs = cgroup_cs(cont);
        struct cpuset *oldcs = cgroup_cs(oldcont);
+       int err;
 
        mutex_lock(&callback_mutex);
        guarantee_online_cpus(cs, &cpus);
-       set_cpus_allowed_ptr(tsk, &cpus);
+       err = set_cpus_allowed_ptr(tsk, &cpus);
        mutex_unlock(&callback_mutex);
+       if (err)
+               return;
 
        from = oldcs->mems_allowed;
        to = cs->mems_allowed;
index 8f6185e..ceb2587 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/personality.h>
 #include <linux/tty.h>
 #include <linux/mnt_namespace.h>
+#include <linux/iocontext.h>
 #include <linux/key.h>
 #include <linux/security.h>
 #include <linux/cpu.h>
index 19908b2..4bd2f51 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/sem.h>
 #include <linux/file.h>
 #include <linux/fdtable.h>
+#include <linux/iocontext.h>
 #include <linux/key.h>
 #include <linux/binfmts.h>
 #include <linux/mman.h>
@@ -909,7 +910,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 
        rt_mutex_init_task(p);
 
-#ifdef CONFIG_TRACE_IRQFLAGS
+#ifdef CONFIG_PROVE_LOCKING
        DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
        DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
 #endif
index ab80515..27a83ee 100644 (file)
@@ -1086,7 +1086,7 @@ ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
 }
 EXPORT_SYMBOL_GPL(hrtimer_get_remaining);
 
-#if defined(CONFIG_NO_IDLE_HZ) || defined(CONFIG_NO_HZ)
+#ifdef CONFIG_NO_HZ
 /**
  * hrtimer_get_next_event - get the time until next expiry event
  *
@@ -1677,7 +1677,7 @@ void __init hrtimers_init(void)
                          (void *)(long)smp_processor_id());
        register_cpu_notifier(&hrtimers_nb);
 #ifdef CONFIG_HIGH_RES_TIMERS
-       open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq, NULL);
+       open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
 #endif
 }
 
index bd1b9ea..97747cd 100644 (file)
@@ -180,6 +180,7 @@ void kthread_bind(struct task_struct *k, unsigned int cpu)
        set_task_cpu(k, cpu);
        k->cpus_allowed = cpumask_of_cpu(cpu);
        k->rt.nr_cpus_allowed = 1;
+       k->flags |= PF_THREAD_BOUND;
 }
 EXPORT_SYMBOL(kthread_bind);
 
index 81a4e4a..d38a643 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/irqflags.h>
 #include <linux/utsname.h>
 #include <linux/hash.h>
+#include <linux/ftrace.h>
 
 #include <asm/sections.h>
 
@@ -81,6 +82,8 @@ static int graph_lock(void)
                __raw_spin_unlock(&lockdep_lock);
                return 0;
        }
+       /* prevent any recursions within lockdep from causing deadlocks */
+       current->lockdep_recursion++;
        return 1;
 }
 
@@ -89,6 +92,7 @@ static inline int graph_unlock(void)
        if (debug_locks && !__raw_spin_is_locked(&lockdep_lock))
                return DEBUG_LOCKS_WARN_ON(1);
 
+       current->lockdep_recursion--;
        __raw_spin_unlock(&lockdep_lock);
        return 0;
 }
@@ -982,7 +986,7 @@ check_noncircular(struct lock_class *source, unsigned int depth)
        return 1;
 }
 
-#ifdef CONFIG_TRACE_IRQFLAGS
+#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
 /*
  * Forwards and backwards subgraph searching, for the purposes of
  * proving that two subgraphs can be connected by a new dependency
@@ -1458,7 +1462,14 @@ out_bug:
 }
 
 unsigned long nr_lock_chains;
-static struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
+struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
+int nr_chain_hlocks;
+static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
+
+struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
+{
+       return lock_classes + chain_hlocks[chain->base + i];
+}
 
 /*
  * Look up a dependency chain. If the key is not present yet then
@@ -1466,10 +1477,15 @@ static struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
  * validated. If the key is already hashed, return 0.
  * (On return with 1 graph_lock is held.)
  */
-static inline int lookup_chain_cache(u64 chain_key, struct lock_class *class)
+static inline int lookup_chain_cache(struct task_struct *curr,
+                                    struct held_lock *hlock,
+                                    u64 chain_key)
 {
+       struct lock_class *class = hlock->class;
        struct list_head *hash_head = chainhashentry(chain_key);
        struct lock_chain *chain;
+       struct held_lock *hlock_curr, *hlock_next;
+       int i, j, n, cn;
 
        if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
                return 0;
@@ -1517,6 +1533,32 @@ cache_hit:
        }
        chain = lock_chains + nr_lock_chains++;
        chain->chain_key = chain_key;
+       chain->irq_context = hlock->irq_context;
+       /* Find the first held_lock of current chain */
+       hlock_next = hlock;
+       for (i = curr->lockdep_depth - 1; i >= 0; i--) {
+               hlock_curr = curr->held_locks + i;
+               if (hlock_curr->irq_context != hlock_next->irq_context)
+                       break;
+               hlock_next = hlock;
+       }
+       i++;
+       chain->depth = curr->lockdep_depth + 1 - i;
+       cn = nr_chain_hlocks;
+       while (cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS) {
+               n = cmpxchg(&nr_chain_hlocks, cn, cn + chain->depth);
+               if (n == cn)
+                       break;
+               cn = n;
+       }
+       if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
+               chain->base = cn;
+               for (j = 0; j < chain->depth - 1; j++, i++) {
+                       int lock_id = curr->held_locks[i].class - lock_classes;
+                       chain_hlocks[chain->base + j] = lock_id;
+               }
+               chain_hlocks[chain->base + j] = class - lock_classes;
+       }
        list_add_tail_rcu(&chain->entry, hash_head);
        debug_atomic_inc(&chain_lookup_misses);
        inc_chains();
@@ -1538,7 +1580,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
         * graph_lock for us)
         */
        if (!hlock->trylock && (hlock->check == 2) &&
-                       lookup_chain_cache(chain_key, hlock->class)) {
+           lookup_chain_cache(curr, hlock, chain_key)) {
                /*
                 * Check whether last held lock:
                 *
@@ -1680,7 +1722,7 @@ valid_state(struct task_struct *curr, struct held_lock *this,
 static int mark_lock(struct task_struct *curr, struct held_lock *this,
                     enum lock_usage_bit new_bit);
 
-#ifdef CONFIG_TRACE_IRQFLAGS
+#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
 
 /*
  * print irq inversion bug:
@@ -2013,11 +2055,13 @@ void early_boot_irqs_on(void)
 /*
  * Hardirqs will be enabled:
  */
-void trace_hardirqs_on(void)
+void trace_hardirqs_on_caller(unsigned long a0)
 {
        struct task_struct *curr = current;
        unsigned long ip;
 
+       time_hardirqs_on(CALLER_ADDR0, a0);
+
        if (unlikely(!debug_locks || current->lockdep_recursion))
                return;
 
@@ -2055,16 +2099,23 @@ void trace_hardirqs_on(void)
        curr->hardirq_enable_event = ++curr->irq_events;
        debug_atomic_inc(&hardirqs_on_events);
 }
+EXPORT_SYMBOL(trace_hardirqs_on_caller);
 
+void trace_hardirqs_on(void)
+{
+       trace_hardirqs_on_caller(CALLER_ADDR0);
+}
 EXPORT_SYMBOL(trace_hardirqs_on);
 
 /*
  * Hardirqs were disabled:
  */
-void trace_hardirqs_off(void)
+void trace_hardirqs_off_caller(unsigned long a0)
 {
        struct task_struct *curr = current;
 
+       time_hardirqs_off(CALLER_ADDR0, a0);
+
        if (unlikely(!debug_locks || current->lockdep_recursion))
                return;
 
@@ -2082,7 +2133,12 @@ void trace_hardirqs_off(void)
        } else
                debug_atomic_inc(&redundant_hardirqs_off);
 }
+EXPORT_SYMBOL(trace_hardirqs_off_caller);
 
+void trace_hardirqs_off(void)
+{
+       trace_hardirqs_off_caller(CALLER_ADDR0);
+}
 EXPORT_SYMBOL(trace_hardirqs_off);
 
 /*
@@ -2246,7 +2302,7 @@ static inline int separate_irq_context(struct task_struct *curr,
  * Mark a lock with a usage bit, and validate the state transition:
  */
 static int mark_lock(struct task_struct *curr, struct held_lock *this,
-                    enum lock_usage_bit new_bit)
+                            enum lock_usage_bit new_bit)
 {
        unsigned int new_mask = 1 << new_bit, ret = 1;
 
@@ -2650,7 +2706,8 @@ __lock_release(struct lockdep_map *lock, int nested, unsigned long ip)
  */
 static void check_flags(unsigned long flags)
 {
-#if defined(CONFIG_DEBUG_LOCKDEP) && defined(CONFIG_TRACE_IRQFLAGS)
+#if defined(CONFIG_PROVE_LOCKING) && defined(CONFIG_DEBUG_LOCKDEP) && \
+    defined(CONFIG_TRACE_IRQFLAGS)
        if (!debug_locks)
                return;
 
@@ -2686,7 +2743,7 @@ static void check_flags(unsigned long flags)
  * and also avoid lockdep recursion:
  */
 void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
-                 int trylock, int read, int check, unsigned long ip)
+                         int trylock, int read, int check, unsigned long ip)
 {
        unsigned long flags;
 
@@ -2708,7 +2765,8 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 
 EXPORT_SYMBOL_GPL(lock_acquire);
 
-void lock_release(struct lockdep_map *lock, int nested, unsigned long ip)
+void lock_release(struct lockdep_map *lock, int nested,
+                         unsigned long ip)
 {
        unsigned long flags;
 
index 8ce09bc..c3600a0 100644 (file)
@@ -23,6 +23,8 @@
 #define MAX_LOCKDEP_CHAINS_BITS        14
 #define MAX_LOCKDEP_CHAINS     (1UL << MAX_LOCKDEP_CHAINS_BITS)
 
+#define MAX_LOCKDEP_CHAIN_HLOCKS (MAX_LOCKDEP_CHAINS*5)
+
 /*
  * Stack-trace: tightly packed array of stack backtrace
  * addresses. Protected by the hash_lock.
 #define MAX_STACK_TRACE_ENTRIES        262144UL
 
 extern struct list_head all_lock_classes;
+extern struct lock_chain lock_chains[];
 
 extern void
 get_usage_chars(struct lock_class *class, char *c1, char *c2, char *c3, char *c4);
 
 extern const char * __get_key_name(struct lockdep_subclass_key *key, char *str);
 
+struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i);
+
 extern unsigned long nr_lock_classes;
 extern unsigned long nr_list_entries;
 extern unsigned long nr_lock_chains;
+extern int nr_chain_hlocks;
 extern unsigned long nr_stack_trace_entries;
 
 extern unsigned int nr_hardirq_chains;
index dc5d296..9b0e940 100644 (file)
@@ -139,7 +139,7 @@ static int l_show(struct seq_file *m, void *v)
 
        list_for_each_entry(entry, &class->locks_after, entry) {
                if (entry->distance == 1) {
-                       seq_printf(m, " -> [%p] ", entry->class);
+                       seq_printf(m, " -> [%p] ", entry->class->key);
                        print_name(m, entry->class);
                        seq_puts(m, "\n");
                }
@@ -178,6 +178,95 @@ static const struct file_operations proc_lockdep_operations = {
        .release        = seq_release,
 };
 
+#ifdef CONFIG_PROVE_LOCKING
+static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       struct lock_chain *chain;
+
+       (*pos)++;
+
+       if (v == SEQ_START_TOKEN)
+               chain = m->private;
+       else {
+               chain = v;
+
+               if (*pos < nr_lock_chains)
+                       chain = lock_chains + *pos;
+               else
+                       chain = NULL;
+       }
+
+       return chain;
+}
+
+static void *lc_start(struct seq_file *m, loff_t *pos)
+{
+       if (*pos == 0)
+               return SEQ_START_TOKEN;
+
+       if (*pos < nr_lock_chains)
+               return lock_chains + *pos;
+
+       return NULL;
+}
+
+static void lc_stop(struct seq_file *m, void *v)
+{
+}
+
+static int lc_show(struct seq_file *m, void *v)
+{
+       struct lock_chain *chain = v;
+       struct lock_class *class;
+       int i;
+
+       if (v == SEQ_START_TOKEN) {
+               seq_printf(m, "all lock chains:\n");
+               return 0;
+       }
+
+       seq_printf(m, "irq_context: %d\n", chain->irq_context);
+
+       for (i = 0; i < chain->depth; i++) {
+               class = lock_chain_get_class(chain, i);
+               seq_printf(m, "[%p] ", class->key);
+               print_name(m, class);
+               seq_puts(m, "\n");
+       }
+       seq_puts(m, "\n");
+
+       return 0;
+}
+
+static const struct seq_operations lockdep_chains_ops = {
+       .start  = lc_start,
+       .next   = lc_next,
+       .stop   = lc_stop,
+       .show   = lc_show,
+};
+
+static int lockdep_chains_open(struct inode *inode, struct file *file)
+{
+       int res = seq_open(file, &lockdep_chains_ops);
+       if (!res) {
+               struct seq_file *m = file->private_data;
+
+               if (nr_lock_chains)
+                       m->private = lock_chains;
+               else
+                       m->private = NULL;
+       }
+       return res;
+}
+
+static const struct file_operations proc_lockdep_chains_operations = {
+       .open           = lockdep_chains_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+#endif /* CONFIG_PROVE_LOCKING */
+
 static void lockdep_stats_debug_show(struct seq_file *m)
 {
 #ifdef CONFIG_DEBUG_LOCKDEP
@@ -294,6 +383,8 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
 #ifdef CONFIG_PROVE_LOCKING
        seq_printf(m, " dependency chains:             %11lu [max: %lu]\n",
                        nr_lock_chains, MAX_LOCKDEP_CHAINS);
+       seq_printf(m, " dependency chain hlocks:       %11d [max: %lu]\n",
+                       nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
 #endif
 
 #ifdef CONFIG_TRACE_IRQFLAGS
@@ -661,6 +752,10 @@ static const struct file_operations proc_lock_stat_operations = {
 static int __init lockdep_proc_init(void)
 {
        proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
+#ifdef CONFIG_PROVE_LOCKING
+       proc_create("lockdep_chains", S_IRUSR, NULL,
+                   &proc_lockdep_chains_operations);
+#endif
        proc_create("lockdep_stats", S_IRUSR, NULL,
                    &proc_lockdep_stats_operations);
 
index b5a9fe1..1abfb92 100644 (file)
@@ -55,8 +55,8 @@ static DEFINE_MUTEX(markers_mutex);
 struct marker_entry {
        struct hlist_node hlist;
        char *format;
-       void (*call)(const struct marker *mdata,        /* Probe wrapper */
-               void *call_private, const char *fmt, ...);
+                       /* Probe wrapper */
+       void (*call)(const struct marker *mdata, void *call_private, ...);
        struct marker_probe_closure single;
        struct marker_probe_closure *multi;
        int refcount;   /* Number of times armed. 0 if disarmed. */
@@ -91,15 +91,13 @@ EXPORT_SYMBOL_GPL(__mark_empty_function);
  * marker_probe_cb Callback that prepares the variable argument list for probes.
  * @mdata: pointer of type struct marker
  * @call_private: caller site private data
- * @fmt: format string
  * @...:  Variable argument list.
  *
  * Since we do not use "typical" pointer based RCU in the 1 argument case, we
  * need to put a full smp_rmb() in this branch. This is why we do not use
  * rcu_dereference() for the pointer read.
  */
-void marker_probe_cb(const struct marker *mdata, void *call_private,
-       const char *fmt, ...)
+void marker_probe_cb(const struct marker *mdata, void *call_private, ...)
 {
        va_list args;
        char ptype;
@@ -120,8 +118,9 @@ void marker_probe_cb(const struct marker *mdata, void *call_private,
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
-               va_start(args, fmt);
-               func(mdata->single.probe_private, call_private, fmt, &args);
+               va_start(args, call_private);
+               func(mdata->single.probe_private, call_private, mdata->format,
+                       &args);
                va_end(args);
        } else {
                struct marker_probe_closure *multi;
@@ -136,9 +135,9 @@ void marker_probe_cb(const struct marker *mdata, void *call_private,
                smp_read_barrier_depends();
                multi = mdata->multi;
                for (i = 0; multi[i].func; i++) {
-                       va_start(args, fmt);
-                       multi[i].func(multi[i].probe_private, call_private, fmt,
-                               &args);
+                       va_start(args, call_private);
+                       multi[i].func(multi[i].probe_private, call_private,
+                               mdata->format, &args);
                        va_end(args);
                }
        }
@@ -150,13 +149,11 @@ EXPORT_SYMBOL_GPL(marker_probe_cb);
  * marker_probe_cb Callback that does not prepare the variable argument list.
  * @mdata: pointer of type struct marker
  * @call_private: caller site private data
- * @fmt: format string
  * @...:  Variable argument list.
  *
  * Should be connected to markers "MARK_NOARGS".
  */
-void marker_probe_cb_noarg(const struct marker *mdata,
-       void *call_private, const char *fmt, ...)
+void marker_probe_cb_noarg(const struct marker *mdata, void *call_private, ...)
 {
        va_list args;   /* not initialized */
        char ptype;
@@ -172,7 +169,8 @@ void marker_probe_cb_noarg(const struct marker *mdata,
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
-               func(mdata->single.probe_private, call_private, fmt, &args);
+               func(mdata->single.probe_private, call_private, mdata->format,
+                       &args);
        } else {
                struct marker_probe_closure *multi;
                int i;
@@ -186,8 +184,8 @@ void marker_probe_cb_noarg(const struct marker *mdata,
                smp_read_barrier_depends();
                multi = mdata->multi;
                for (i = 0; multi[i].func; i++)
-                       multi[i].func(multi[i].probe_private, call_private, fmt,
-                               &args);
+                       multi[i].func(multi[i].probe_private, call_private,
+                               mdata->format, &args);
        }
        preempt_enable();
 }
index 3aaa06c..1d94160 100644 (file)
@@ -79,8 +79,8 @@ void debug_mutex_unlock(struct mutex *lock)
        if (unlikely(!debug_locks))
                return;
 
-       DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
        DEBUG_LOCKS_WARN_ON(lock->magic != lock);
+       DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
        DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
        DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
 }
index d046a34..bcdc9ac 100644 (file)
@@ -165,10 +165,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
                 * got a signal? (This code gets eliminated in the
                 * TASK_UNINTERRUPTIBLE case.)
                 */
-               if (unlikely((state == TASK_INTERRUPTIBLE &&
-                                       signal_pending(task)) ||
-                             (state == TASK_KILLABLE &&
-                                       fatal_signal_pending(task)))) {
+               if (unlikely(signal_pending_state(state, task))) {
                        mutex_remove_waiter(lock, &waiter,
                                            task_thread_info(task));
                        mutex_release(&lock->dep_map, 1, ip);
index 0afe32b..8cb7570 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <linux/pm_qos_params.h>
 #include <linux/sched.h>
+#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/time.h>
@@ -358,15 +359,19 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp)
        int ret;
        long pm_qos_class;
 
+       lock_kernel();
        pm_qos_class = find_pm_qos_object_by_minor(iminor(inode));
        if (pm_qos_class >= 0) {
                filp->private_data = (void *)pm_qos_class;
                sprintf(name, "process_%d", current->pid);
                ret = pm_qos_add_requirement(pm_qos_class, name,
                                        PM_QOS_DEFAULT_VALUE);
-               if (ret >= 0)
+               if (ret >= 0) {
+                       unlock_kernel();
                        return 0;
+               }
        }
+       unlock_kernel();
 
        return -EPERM;
 }
index e2129e8..07ad9e7 100644 (file)
@@ -38,7 +38,7 @@
 /*
  * Architectures can override it:
  */
-void __attribute__((weak)) early_printk(const char *fmt, ...)
+void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...)
 {
 }
 
@@ -75,6 +75,8 @@ EXPORT_SYMBOL(oops_in_progress);
 static DECLARE_MUTEX(console_sem);
 static DECLARE_MUTEX(secondary_console_sem);
 struct console *console_drivers;
+EXPORT_SYMBOL_GPL(console_drivers);
+
 /*
  * This is used for debugging the mess that is the VT code by
  * keeping track if we have the console semaphore held. It's
@@ -121,6 +123,8 @@ struct console_cmdline
 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
 static int selected_console = -1;
 static int preferred_console = -1;
+int console_set_on_cmdline;
+EXPORT_SYMBOL(console_set_on_cmdline);
 
 /* Flag: console code may call schedule() */
 static int console_may_schedule;
@@ -231,7 +235,7 @@ static inline void boot_delay_msec(void)
 /*
  * Return the number of unread characters in the log buffer.
  */
-int log_buf_get_len(void)
+static int log_buf_get_len(void)
 {
        return logged_chars;
 }
@@ -267,19 +271,6 @@ int log_buf_copy(char *dest, int idx, int len)
        return ret;
 }
 
-/*
- * Extract a single character from the log buffer.
- */
-int log_buf_read(int idx)
-{
-       char ret;
-
-       if (log_buf_copy(&ret, idx, 1) == 1)
-               return ret;
-       else
-               return -1;
-}
-
 /*
  * Commands to do_syslog:
  *
@@ -665,18 +656,17 @@ static int acquire_console_semaphore_for_printk(unsigned int cpu)
        spin_unlock(&logbuf_lock);
        return retval;
 }
-
-static const char printk_recursion_bug_msg [] =
-                       KERN_CRIT "BUG: recent printk recursion!\n";
-static int printk_recursion_bug;
+static const char recursion_bug_msg [] =
+               KERN_CRIT "BUG: recent printk recursion!\n";
+static int recursion_bug;
+       static int new_text_line = 1;
+static char printk_buf[1024];
 
 asmlinkage int vprintk(const char *fmt, va_list args)
 {
-       static int log_level_unknown = 1;
-       static char printk_buf[1024];
-
-       unsigned long flags;
        int printed_len = 0;
+       int current_log_level = default_message_loglevel;
+       unsigned long flags;
        int this_cpu;
        char *p;
 
@@ -699,7 +689,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
                 * it can be printed at the next appropriate moment:
                 */
                if (!oops_in_progress) {
-                       printk_recursion_bug = 1;
+                       recursion_bug = 1;
                        goto out_restore_irqs;
                }
                zap_locks();
@@ -709,70 +699,62 @@ asmlinkage int vprintk(const char *fmt, va_list args)
        spin_lock(&logbuf_lock);
        printk_cpu = this_cpu;
 
-       if (printk_recursion_bug) {
-               printk_recursion_bug = 0;
-               strcpy(printk_buf, printk_recursion_bug_msg);
-               printed_len = sizeof(printk_recursion_bug_msg);
+       if (recursion_bug) {
+               recursion_bug = 0;
+               strcpy(printk_buf, recursion_bug_msg);
+               printed_len = sizeof(recursion_bug_msg);
        }
        /* Emit the output into the temporary buffer */
        printed_len += vscnprintf(printk_buf + printed_len,
                                  sizeof(printk_buf) - printed_len, fmt, args);
 
+
        /*
         * Copy the output into log_buf.  If the caller didn't provide
         * appropriate log level tags, we insert them here
         */
        for (p = printk_buf; *p; p++) {
-               if (log_level_unknown) {
-                        /* log_level_unknown signals the start of a new line */
+               if (new_text_line) {
+                       /* If a token, set current_log_level and skip over */
+                       if (p[0] == '<' && p[1] >= '0' && p[1] <= '7' &&
+                           p[2] == '>') {
+                               current_log_level = p[1] - '0';
+                               p += 3;
+                               printed_len -= 3;
+                       }
+
+                       /* Always output the token */
+                       emit_log_char('<');
+                       emit_log_char(current_log_level + '0');
+                       emit_log_char('>');
+                       printed_len += 3;
+                       new_text_line = 0;
+
                        if (printk_time) {
-                               int loglev_char;
+                               /* Follow the token with the time */
                                char tbuf[50], *tp;
                                unsigned tlen;
                                unsigned long long t;
                                unsigned long nanosec_rem;
 
-                               /*
-                                * force the log level token to be
-                                * before the time output.
-                                */
-                               if (p[0] == '<' && p[1] >='0' &&
-                                  p[1] <= '7' && p[2] == '>') {
-                                       loglev_char = p[1];
-                                       p += 3;
-                                       printed_len -= 3;
-                               } else {
-                                       loglev_char = default_message_loglevel
-                                               + '0';
-                               }
                                t = cpu_clock(printk_cpu);
                                nanosec_rem = do_div(t, 1000000000);
-                               tlen = sprintf(tbuf,
-                                               "<%c>[%5lu.%06lu] ",
-                                               loglev_char,
-                                               (unsigned long)t,
-                                               nanosec_rem/1000);
+                               tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+                                               (unsigned long) t,
+                                               nanosec_rem / 1000);
 
                                for (tp = tbuf; tp < tbuf + tlen; tp++)
                                        emit_log_char(*tp);
                                printed_len += tlen;
-                       } else {
-                               if (p[0] != '<' || p[1] < '0' ||
-                                  p[1] > '7' || p[2] != '>') {
-                                       emit_log_char('<');
-                                       emit_log_char(default_message_loglevel
-                                               + '0');
-                                       emit_log_char('>');
-                                       printed_len += 3;
-                               }
                        }
-                       log_level_unknown = 0;
+
                        if (!*p)
                                break;
                }
+
                emit_log_char(*p);
                if (*p == '\n')
-                       log_level_unknown = 1;
+                       new_text_line = 1;
        }
 
        /*
@@ -890,6 +872,7 @@ static int __init console_setup(char *str)
        *s = 0;
 
        __add_preferred_console(buf, idx, options, brl_options);
+       console_set_on_cmdline = 1;
        return 1;
 }
 __setup("console=", console_setup);
@@ -1041,7 +1024,9 @@ void release_console_sem(void)
                _log_end = log_end;
                con_start = log_end;            /* Flush */
                spin_unlock(&logbuf_lock);
+               stop_critical_timings();        /* don't trace print latency */
                call_console_drivers(_con_start, _log_end);
+               start_critical_timings();
                local_irq_restore(flags);
        }
        console_locked = 0;
@@ -1172,8 +1157,11 @@ void register_console(struct console *console)
                        console->index = 0;
                if (console->setup == NULL ||
                    console->setup(console, NULL) == 0) {
-                       console->flags |= CON_ENABLED | CON_CONSDEV;
-                       preferred_console = 0;
+                       console->flags |= CON_ENABLED;
+                       if (console->device) {
+                               console->flags |= CON_CONSDEV;
+                               preferred_console = 0;
+                       }
                }
        }
 
index 6c19e94..e337390 100644 (file)
@@ -121,7 +121,7 @@ int ptrace_check_attach(struct task_struct *child, int kill)
        return ret;
 }
 
-int __ptrace_may_attach(struct task_struct *task)
+int __ptrace_may_access(struct task_struct *task, unsigned int mode)
 {
        /* May we inspect the given task?
         * This check is used both for attaching with ptrace
@@ -148,16 +148,16 @@ int __ptrace_may_attach(struct task_struct *task)
        if (!dumpable && !capable(CAP_SYS_PTRACE))
                return -EPERM;
 
-       return security_ptrace(current, task);
+       return security_ptrace(current, task, mode);
 }
 
-int ptrace_may_attach(struct task_struct *task)
+bool ptrace_may_access(struct task_struct *task, unsigned int mode)
 {
        int err;
        task_lock(task);
-       err = __ptrace_may_attach(task);
+       err = __ptrace_may_access(task, mode);
        task_unlock(task);
-       return !err;
+       return (!err ? true : false);
 }
 
 int ptrace_attach(struct task_struct *task)
@@ -195,7 +195,7 @@ repeat:
        /* the same process cannot be attached many times */
        if (task->ptrace & PT_PTRACED)
                goto bad;
-       retval = __ptrace_may_attach(task);
+       retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
        if (retval)
                goto bad;
 
@@ -494,7 +494,8 @@ int ptrace_traceme(void)
         */
        task_lock(current);
        if (!(current->ptrace & PT_PTRACED)) {
-               ret = security_ptrace(current->parent, current);
+               ret = security_ptrace(current->parent, current,
+                                     PTRACE_MODE_ATTACH);
                /*
                 * Set the ptrace bit in the process ptrace flags.
                 */
index a38895a..65c0906 100644 (file)
@@ -543,7 +543,7 @@ static void __cpuinit rcu_online_cpu(int cpu)
 
        rcu_init_percpu_data(cpu, &rcu_ctrlblk, rdp);
        rcu_init_percpu_data(cpu, &rcu_bh_ctrlblk, bh_rdp);
-       open_softirq(RCU_SOFTIRQ, rcu_process_callbacks, NULL);
+       open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
 }
 
 static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
index 41d275a..9bf4456 100644 (file)
@@ -1119,7 +1119,7 @@ void __init __rcu_init(void)
        for_each_online_cpu(cpu)
                rcu_cpu_notify(&rcu_nb, CPU_UP_PREPARE, (void *)(long) cpu);
 
-       open_softirq(RCU_SOFTIRQ, rcu_process_callbacks, NULL);
+       open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
 }
 
 /*
index 4e2f603..99e6d85 100644 (file)
 #include <linux/bootmem.h>
 #include <linux/debugfs.h>
 #include <linux/ctype.h>
+#include <linux/ftrace.h>
 
 #include <asm/tlb.h>
 #include <asm/irq_regs.h>
 
+#include "sched_cpupri.h"
+
 /*
  * Convert user-nice values [ -20 ... 0 ... 19 ]
  * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
@@ -289,15 +292,15 @@ struct task_group root_task_group;
 static DEFINE_PER_CPU(struct sched_entity, init_sched_entity);
 /* Default task group's cfs_rq on each cpu */
 static DEFINE_PER_CPU(struct cfs_rq, init_cfs_rq) ____cacheline_aligned_in_smp;
-#endif
+#endif /* CONFIG_FAIR_GROUP_SCHED */
 
 #ifdef CONFIG_RT_GROUP_SCHED
 static DEFINE_PER_CPU(struct sched_rt_entity, init_sched_rt_entity);
 static DEFINE_PER_CPU(struct rt_rq, init_rt_rq) ____cacheline_aligned_in_smp;
-#endif
-#else
+#endif /* CONFIG_RT_GROUP_SCHED */
+#else /* !CONFIG_FAIR_GROUP_SCHED */
 #define root_task_group init_task_group
-#endif
+#endif /* CONFIG_FAIR_GROUP_SCHED */
 
 /* task_group_lock serializes add/remove of task groups and also changes to
  * a task group's cpu shares.
@@ -307,9 +310,9 @@ static DEFINE_SPINLOCK(task_group_lock);
 #ifdef CONFIG_FAIR_GROUP_SCHED
 #ifdef CONFIG_USER_SCHED
 # define INIT_TASK_GROUP_LOAD  (2*NICE_0_LOAD)
-#else
+#else /* !CONFIG_USER_SCHED */
 # define INIT_TASK_GROUP_LOAD  NICE_0_LOAD
-#endif
+#endif /* CONFIG_USER_SCHED */
 
 /*
  * A weight of 0 or 1 can cause arithmetics problems.
@@ -363,6 +366,10 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
 #else
 
 static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
+static inline struct task_group *task_group(struct task_struct *p)
+{
+       return NULL;
+}
 
 #endif /* CONFIG_GROUP_SCHED */
 
@@ -373,6 +380,7 @@ struct cfs_rq {
 
        u64 exec_clock;
        u64 min_vruntime;
+       u64 pair_start;
 
        struct rb_root tasks_timeline;
        struct rb_node *rb_leftmost;
@@ -401,6 +409,31 @@ struct cfs_rq {
         */
        struct list_head leaf_cfs_rq_list;
        struct task_group *tg;  /* group that "owns" this runqueue */
+
+#ifdef CONFIG_SMP
+       /*
+        * the part of load.weight contributed by tasks
+        */
+       unsigned long task_weight;
+
+       /*
+        *   h_load = weight * f(tg)
+        *
+        * Where f(tg) is the recursive weight fraction assigned to
+        * this group.
+        */
+       unsigned long h_load;
+
+       /*
+        * this cpu's part of tg->shares
+        */
+       unsigned long shares;
+
+       /*
+        * load.weight at the time we set shares
+        */
+       unsigned long rq_weight;
+#endif
 #endif
 };
 
@@ -452,6 +485,9 @@ struct root_domain {
         */
        cpumask_t rto_mask;
        atomic_t rto_count;
+#ifdef CONFIG_SMP
+       struct cpupri cpupri;
+#endif
 };
 
 /*
@@ -526,6 +562,9 @@ struct rq {
        int push_cpu;
        /* cpu of this runqueue: */
        int cpu;
+       int online;
+
+       unsigned long avg_load_per_task;
 
        struct task_struct *migration_thread;
        struct list_head migration_queue;
@@ -607,6 +646,24 @@ static inline void update_rq_clock(struct rq *rq)
 # define const_debug static const
 #endif
 
+/**
+ * runqueue_is_locked
+ *
+ * Returns true if the current cpu runqueue is locked.
+ * This interface allows printk to be called with the runqueue lock
+ * held and know whether or not it is OK to wake up the klogd.
+ */
+int runqueue_is_locked(void)
+{
+       int cpu = get_cpu();
+       struct rq *rq = cpu_rq(cpu);
+       int ret;
+
+       ret = spin_is_locked(&rq->lock);
+       put_cpu();
+       return ret;
+}
+
 /*
  * Debugging: various feature bits
  */
@@ -748,6 +805,12 @@ late_initcall(sched_init_debug);
  */
 const_debug unsigned int sysctl_sched_nr_migrate = 32;
 
+/*
+ * ratelimit for updating the group shares.
+ * default: 0.5ms
+ */
+const_debug unsigned int sysctl_sched_shares_ratelimit = 500000;
+
 /*
  * period over which we measure -rt task cpu usage in us.
  * default: 1s
@@ -775,82 +838,6 @@ static inline u64 global_rt_runtime(void)
        return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
 }
 
-unsigned long long time_sync_thresh = 100000;
-
-static DEFINE_PER_CPU(unsigned long long, time_offset);
-static DEFINE_PER_CPU(unsigned long long, prev_cpu_time);
-
-/*
- * Global lock which we take every now and then to synchronize
- * the CPUs time. This method is not warp-safe, but it's good
- * enough to synchronize slowly diverging time sources and thus
- * it's good enough for tracing:
- */
-static DEFINE_SPINLOCK(time_sync_lock);
-static unsigned long long prev_global_time;
-
-static unsigned long long __sync_cpu_clock(unsigned long long time, int cpu)
-{
-       /*
-        * We want this inlined, to not get tracer function calls
-        * in this critical section:
-        */
-       spin_acquire(&time_sync_lock.dep_map, 0, 0, _THIS_IP_);
-       __raw_spin_lock(&time_sync_lock.raw_lock);
-
-       if (time < prev_global_time) {
-               per_cpu(time_offset, cpu) += prev_global_time - time;
-               time = prev_global_time;
-       } else {
-               prev_global_time = time;
-       }
-
-       __raw_spin_unlock(&time_sync_lock.raw_lock);
-       spin_release(&time_sync_lock.dep_map, 1, _THIS_IP_);
-
-       return time;
-}
-
-static unsigned long long __cpu_clock(int cpu)
-{
-       unsigned long long now;
-
-       /*
-        * Only call sched_clock() if the scheduler has already been
-        * initialized (some code might call cpu_clock() very early):
-        */
-       if (unlikely(!scheduler_running))
-               return 0;
-
-       now = sched_clock_cpu(cpu);
-
-       return now;
-}
-
-/*
- * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
- * clock constructed from sched_clock():
- */
-unsigned long long cpu_clock(int cpu)
-{
-       unsigned long long prev_cpu_time, time, delta_time;
-       unsigned long flags;
-
-       local_irq_save(flags);
-       prev_cpu_time = per_cpu(prev_cpu_time, cpu);
-       time = __cpu_clock(cpu) + per_cpu(time_offset, cpu);
-       delta_time = time-prev_cpu_time;
-
-       if (unlikely(delta_time > time_sync_thresh)) {
-               time = __sync_cpu_clock(time, cpu);
-               per_cpu(prev_cpu_time, cpu) = time;
-       }
-       local_irq_restore(flags);
-
-       return time;
-}
-EXPORT_SYMBOL_GPL(cpu_clock);
-
 #ifndef prepare_arch_switch
 # define prepare_arch_switch(next)     do { } while (0)
 #endif
@@ -1313,15 +1300,15 @@ void wake_up_idle_cpu(int cpu)
        if (!tsk_is_polling(rq->idle))
                smp_send_reschedule(cpu);
 }
-#endif
+#endif /* CONFIG_NO_HZ */
 
-#else
+#else /* !CONFIG_SMP */
 static void __resched_task(struct task_struct *p, int tif_bit)
 {
        assert_spin_locked(&task_rq(p)->lock);
        set_tsk_thread_flag(p, tif_bit);
 }
-#endif
+#endif /* CONFIG_SMP */
 
 #if BITS_PER_LONG == 32
 # define WMULT_CONST   (~0UL)
@@ -1336,6 +1323,9 @@ static void __resched_task(struct task_struct *p, int tif_bit)
  */
 #define SRR(x, y) (((x) + (1UL << ((y) - 1))) >> (y))
 
+/*
+ * delta *= weight / lw
+ */
 static unsigned long
 calc_delta_mine(unsigned long delta_exec, unsigned long weight,
                struct load_weight *lw)
@@ -1363,12 +1353,6 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
        return (unsigned long)min(tmp, (u64)(unsigned long)LONG_MAX);
 }
 
-static inline unsigned long
-calc_delta_fair(unsigned long delta_exec, struct load_weight *lw)
-{
-       return calc_delta_mine(delta_exec, NICE_0_LOAD, lw);
-}
-
 static inline void update_load_add(struct load_weight *lw, unsigned long inc)
 {
        lw->weight += inc;
@@ -1479,17 +1463,211 @@ static inline void dec_cpu_load(struct rq *rq, unsigned long load)
 #ifdef CONFIG_SMP
 static unsigned long source_load(int cpu, int type);
 static unsigned long target_load(int cpu, int type);
-static unsigned long cpu_avg_load_per_task(int cpu);
 static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd);
-#else /* CONFIG_SMP */
+
+static unsigned long cpu_avg_load_per_task(int cpu)
+{
+       struct rq *rq = cpu_rq(cpu);
+
+       if (rq->nr_running)
+               rq->avg_load_per_task = rq->load.weight / rq->nr_running;
+
+       return rq->avg_load_per_task;
+}
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
+
+typedef void (*tg_visitor)(struct task_group *, int, struct sched_domain *);
+
+/*
+ * Iterate the full tree, calling @down when first entering a node and @up when
+ * leaving it for the final time.
+ */
+static void
+walk_tg_tree(tg_visitor down, tg_visitor up, int cpu, struct sched_domain *sd)
+{
+       struct task_group *parent, *child;
+
+       rcu_read_lock();
+       parent = &root_task_group;
+down:
+       (*down)(parent, cpu, sd);
+       list_for_each_entry_rcu(child, &parent->children, siblings) {
+               parent = child;
+               goto down;
+
+up:
+               continue;
+       }
+       (*up)(parent, cpu, sd);
+
+       child = parent;
+       parent = parent->parent;
+       if (parent)
+               goto up;
+       rcu_read_unlock();
+}
+
+static void __set_se_shares(struct sched_entity *se, unsigned long shares);
+
+/*
+ * Calculate and set the cpu's group shares.
+ */
+static void
+__update_group_shares_cpu(struct task_group *tg, int cpu,
+                         unsigned long sd_shares, unsigned long sd_rq_weight)
+{
+       int boost = 0;
+       unsigned long shares;
+       unsigned long rq_weight;
+
+       if (!tg->se[cpu])
+               return;
+
+       rq_weight = tg->cfs_rq[cpu]->load.weight;
+
+       /*
+        * If there are currently no tasks on the cpu pretend there is one of
+        * average load so that when a new task gets to run here it will not
+        * get delayed by group starvation.
+        */
+       if (!rq_weight) {
+               boost = 1;
+               rq_weight = NICE_0_LOAD;
+       }
+
+       if (unlikely(rq_weight > sd_rq_weight))
+               rq_weight = sd_rq_weight;
+
+       /*
+        *           \Sum shares * rq_weight
+        * shares =  -----------------------
+        *               \Sum rq_weight
+        *
+        */
+       shares = (sd_shares * rq_weight) / (sd_rq_weight + 1);
+
+       /*
+        * record the actual number of shares, not the boosted amount.
+        */
+       tg->cfs_rq[cpu]->shares = boost ? 0 : shares;
+       tg->cfs_rq[cpu]->rq_weight = rq_weight;
+
+       if (shares < MIN_SHARES)
+               shares = MIN_SHARES;
+       else if (shares > MAX_SHARES)
+               shares = MAX_SHARES;
+
+       __set_se_shares(tg->se[cpu], shares);
+}
+
+/*
+ * Re-compute the task group their per cpu shares over the given domain.
+ * This needs to be done in a bottom-up fashion because the rq weight of a
+ * parent group depends on the shares of its child groups.
+ */
+static void
+tg_shares_up(struct task_group *tg, int cpu, struct sched_domain *sd)
+{
+       unsigned long rq_weight = 0;
+       unsigned long shares = 0;
+       int i;
+
+       for_each_cpu_mask(i, sd->span) {
+               rq_weight += tg->cfs_rq[i]->load.weight;
+               shares += tg->cfs_rq[i]->shares;
+       }
+
+       if ((!shares && rq_weight) || shares > tg->shares)
+               shares = tg->shares;
+
+       if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE))
+               shares = tg->shares;
+
+       if (!rq_weight)
+               rq_weight = cpus_weight(sd->span) * NICE_0_LOAD;
+
+       for_each_cpu_mask(i, sd->span) {
+               struct rq *rq = cpu_rq(i);
+               unsigned long flags;
+
+               spin_lock_irqsave(&rq->lock, flags);
+               __update_group_shares_cpu(tg, i, shares, rq_weight);
+               spin_unlock_irqrestore(&rq->lock, flags);
+       }
+}
+
+/*
+ * Compute the cpu's hierarchical load factor for each task group.
+ * This needs to be done in a top-down fashion because the load of a child
+ * group is a fraction of its parents load.
+ */
+static void
+tg_load_down(struct task_group *tg, int cpu, struct sched_domain *sd)
+{
+       unsigned long load;
+
+       if (!tg->parent) {
+               load = cpu_rq(cpu)->load.weight;
+       } else {
+               load = tg->parent->cfs_rq[cpu]->h_load;
+               load *= tg->cfs_rq[cpu]->shares;
+               load /= tg->parent->cfs_rq[cpu]->load.weight + 1;
+       }
+
+       tg->cfs_rq[cpu]->h_load = load;
+}
+
+static void
+tg_nop(struct task_group *tg, int cpu, struct sched_domain *sd)
+{
+}
+
+static void update_shares(struct sched_domain *sd)
+{
+       u64 now = cpu_clock(raw_smp_processor_id());
+       s64 elapsed = now - sd->last_update;
+
+       if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) {
+               sd->last_update = now;
+               walk_tg_tree(tg_nop, tg_shares_up, 0, sd);
+       }
+}
+
+static void update_shares_locked(struct rq *rq, struct sched_domain *sd)
+{
+       spin_unlock(&rq->lock);
+       update_shares(sd);
+       spin_lock(&rq->lock);
+}
+
+static void update_h_load(int cpu)
 {
+       walk_tg_tree(tg_load_down, tg_nop, cpu, NULL);
 }
+
+#else
+
+static inline void update_shares(struct sched_domain *sd)
+{
+}
+
+static inline void update_shares_locked(struct rq *rq, struct sched_domain *sd)
+{
+}
+
 #endif
 
-#endif /* CONFIG_SMP */
+#endif
+
+#ifdef CONFIG_FAIR_GROUP_SCHED
+static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
+{
+#ifdef CONFIG_SMP
+       cfs_rq->shares = shares;
+#endif
+}
+#endif
 
 #include "sched_stats.h"
 #include "sched_idletask.c"
@@ -1500,27 +1678,17 @@ static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
 #endif
 
 #define sched_class_highest (&rt_sched_class)
+#define for_each_class(class) \
+   for (class = sched_class_highest; class; class = class->next)
 
-static inline void inc_load(struct rq *rq, const struct task_struct *p)
-{
-       update_load_add(&rq->load, p->se.load.weight);
-}
-
-static inline void dec_load(struct rq *rq, const struct task_struct *p)
-{
-       update_load_sub(&rq->load, p->se.load.weight);
-}
-
-static void inc_nr_running(struct task_struct *p, struct rq *rq)
+static void inc_nr_running(struct rq *rq)
 {
        rq->nr_running++;
-       inc_load(rq, p);
 }
 
-static void dec_nr_running(struct task_struct *p, struct rq *rq)
+static void dec_nr_running(struct rq *rq)
 {
        rq->nr_running--;
-       dec_load(rq, p);
 }
 
 static void set_load_weight(struct task_struct *p)
@@ -1544,6 +1712,12 @@ static void set_load_weight(struct task_struct *p)
        p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO];
 }
 
+static void update_avg(u64 *avg, u64 sample)
+{
+       s64 diff = sample - *avg;
+       *avg += diff >> 3;
+}
+
 static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
 {
        sched_info_queued(p);
@@ -1553,6 +1727,13 @@ static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
 
 static void dequeue_task(struct rq *rq, struct task_struct *p, int sleep)
 {
+       if (sleep && p->se.last_wakeup) {
+               update_avg(&p->se.avg_overlap,
+                          p->se.sum_exec_runtime - p->se.last_wakeup);
+               p->se.last_wakeup = 0;
+       }
+
+       sched_info_dequeued(p);
        p->sched_class->dequeue_task(rq, p, sleep);
        p->se.on_rq = 0;
 }
@@ -1612,7 +1793,7 @@ static void activate_task(struct rq *rq, struct task_struct *p, int wakeup)
                rq->nr_uninterruptible--;
 
        enqueue_task(rq, p, wakeup);
-       inc_nr_running(p, rq);
+       inc_nr_running(rq);
 }
 
 /*
@@ -1624,7 +1805,7 @@ static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep)
                rq->nr_uninterruptible++;
 
        dequeue_task(rq, p, sleep);
-       dec_nr_running(p, rq);
+       dec_nr_running(rq);
 }
 
 /**
@@ -1636,12 +1817,6 @@ inline int task_curr(const struct task_struct *p)
        return cpu_curr(task_cpu(p)) == p;
 }
 
-/* Used instead of source_load when we know the type == 0 */
-unsigned long weighted_cpuload(const int cpu)
-{
-       return cpu_rq(cpu)->load.weight;
-}
-
 static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
        set_task_rq(p, cpu);
@@ -1670,6 +1845,12 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p,
 
 #ifdef CONFIG_SMP
 
+/* Used instead of source_load when we know the type == 0 */
+static unsigned long weighted_cpuload(const int cpu)
+{
+       return cpu_rq(cpu)->load.weight;
+}
+
 /*
  * Is this task likely cache-hot:
  */
@@ -1880,7 +2061,7 @@ static unsigned long source_load(int cpu, int type)
        struct rq *rq = cpu_rq(cpu);
        unsigned long total = weighted_cpuload(cpu);
 
-       if (type == 0)
+       if (type == 0 || !sched_feat(LB_BIAS))
                return total;
 
        return min(rq->cpu_load[type-1], total);
@@ -1895,24 +2076,12 @@ static unsigned long target_load(int cpu, int type)
        struct rq *rq = cpu_rq(cpu);
        unsigned long total = weighted_cpuload(cpu);
 
-       if (type == 0)
+       if (type == 0 || !sched_feat(LB_BIAS))
                return total;
 
        return max(rq->cpu_load[type-1], total);
 }
 
-/*
- * Return the average load per task on the cpu's run queue
- */
-static unsigned long cpu_avg_load_per_task(int cpu)
-{
-       struct rq *rq = cpu_rq(cpu);
-       unsigned long total = weighted_cpuload(cpu);
-       unsigned long n = rq->nr_running;
-
-       return n ? total / n : SCHED_LOAD_SCALE;
-}
-
 /*
  * find_idlest_group finds and returns the least busy CPU group within the
  * domain.
@@ -2019,6 +2188,9 @@ static int sched_balance_self(int cpu, int flag)
                        sd = tmp;
        }
 
+       if (sd)
+               update_shares(sd);
+
        while (sd) {
                cpumask_t span, tmpmask;
                struct sched_group *group;
@@ -2085,6 +2257,22 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
        if (!sched_feat(SYNC_WAKEUPS))
                sync = 0;
 
+#ifdef CONFIG_SMP
+       if (sched_feat(LB_WAKEUP_UPDATE)) {
+               struct sched_domain *sd;
+
+               this_cpu = raw_smp_processor_id();
+               cpu = task_cpu(p);
+
+               for_each_domain(this_cpu, sd) {
+                       if (cpu_isset(cpu, sd->span)) {
+                               update_shares(sd);
+                               break;
+                       }
+               }
+       }
+#endif
+
        smp_wmb();
        rq = task_rq_lock(p, &flags);
        old_state = p->state;
@@ -2131,7 +2319,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
                        }
                }
        }
-#endif
+#endif /* CONFIG_SCHEDSTATS */
 
 out_activate:
 #endif /* CONFIG_SMP */
@@ -2149,6 +2337,9 @@ out_activate:
        success = 1;
 
 out_running:
+       trace_mark(kernel_sched_wakeup,
+               "pid %d state %ld ## rq %p task %p rq->curr %p",
+               p->pid, p->state, rq, p, rq->curr);
        check_preempt_curr(rq, p);
 
        p->state = TASK_RUNNING;
@@ -2157,6 +2348,8 @@ out_running:
                p->sched_class->task_wake_up(rq, p);
 #endif
 out:
+       current->se.last_wakeup = current->se.sum_exec_runtime;
+
        task_rq_unlock(rq, &flags);
 
        return success;
@@ -2277,8 +2470,11 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
                 * management (if any):
                 */
                p->sched_class->task_new(rq, p);
-               inc_nr_running(p, rq);
+               inc_nr_running(rq);
        }
+       trace_mark(kernel_sched_wakeup_new,
+               "pid %d state %ld ## rq %p task %p rq->curr %p",
+               p->pid, p->state, rq, p, rq->curr);
        check_preempt_curr(rq, p);
 #ifdef CONFIG_SMP
        if (p->sched_class->task_wake_up)
@@ -2331,7 +2527,7 @@ fire_sched_out_preempt_notifiers(struct task_struct *curr,
                notifier->ops->sched_out(notifier, next);
 }
 
-#else
+#else /* !CONFIG_PREEMPT_NOTIFIERS */
 
 static void fire_sched_in_preempt_notifiers(struct task_struct *curr)
 {
@@ -2343,7 +2539,7 @@ fire_sched_out_preempt_notifiers(struct task_struct *curr,
 {
 }
 
-#endif
+#endif /* CONFIG_PREEMPT_NOTIFIERS */
 
 /**
  * prepare_task_switch - prepare to switch tasks
@@ -2451,6 +2647,11 @@ context_switch(struct rq *rq, struct task_struct *prev,
        struct mm_struct *mm, *oldmm;
 
        prepare_task_switch(rq, prev, next);
+       trace_mark(kernel_sched_schedule,
+               "prev_pid %d next_pid %d prev_state %ld "
+               "## rq %p prev %p next %p",
+               prev->pid, next->pid, prev->state,
+               rq, prev, next);
        mm = next->mm;
        oldmm = prev->active_mm;
        /*
@@ -2785,7 +2986,7 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
              enum cpu_idle_type idle, int *all_pinned,
              int *this_best_prio, struct rq_iterator *iterator)
 {
-       int loops = 0, pulled = 0, pinned = 0, skip_for_load;
+       int loops = 0, pulled = 0, pinned = 0;
        struct task_struct *p;
        long rem_load_move = max_load_move;
 
@@ -2801,14 +3002,8 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
 next:
        if (!p || loops++ > sysctl_sched_nr_migrate)
                goto out;
-       /*
-        * To help distribute high priority tasks across CPUs we don't
-        * skip a task if it will be the highest priority task (i.e. smallest
-        * prio value) on its new queue regardless of its load weight
-        */
-       skip_for_load = (p->se.load.weight >> 1) > rem_load_move +
-                                                        SCHED_LOAD_SCALE_FUZZ;
-       if ((skip_for_load && p->prio >= *this_best_prio) ||
+
+       if ((p->se.load.weight >> 1) > rem_load_move ||
            !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) {
                p = iterator->next(iterator->arg);
                goto next;
@@ -2863,6 +3058,10 @@ static int move_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
                                max_load_move - total_load_moved,
                                sd, idle, all_pinned, &this_best_prio);
                class = class->next;
+
+               if (idle == CPU_NEWLY_IDLE && this_rq->nr_running)
+                       break;
+
        } while (class && max_load_move > total_load_moved);
 
        return total_load_moved > 0;
@@ -2939,6 +3138,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
        max_load = this_load = total_load = total_pwr = 0;
        busiest_load_per_task = busiest_nr_running = 0;
        this_load_per_task = this_nr_running = 0;
+
        if (idle == CPU_NOT_IDLE)
                load_idx = sd->busy_idx;
        else if (idle == CPU_NEWLY_IDLE)
@@ -2953,6 +3153,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
                int __group_imb = 0;
                unsigned int balance_cpu = -1, first_idle_cpu = 0;
                unsigned long sum_nr_running, sum_weighted_load;
+               unsigned long sum_avg_load_per_task;
+               unsigned long avg_load_per_task;
 
                local_group = cpu_isset(this_cpu, group->cpumask);
 
@@ -2961,6 +3163,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
 
                /* Tally up the load of all CPUs in the group */
                sum_weighted_load = sum_nr_running = avg_load = 0;
+               sum_avg_load_per_task = avg_load_per_task = 0;
+
                max_cpu_load = 0;
                min_cpu_load = ~0UL;
 
@@ -2994,6 +3198,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
                        avg_load += load;
                        sum_nr_running += rq->nr_running;
                        sum_weighted_load += weighted_cpuload(i);
+
+                       sum_avg_load_per_task += cpu_avg_load_per_task(i);
                }
 
                /*
@@ -3015,7 +3221,20 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
                avg_load = sg_div_cpu_power(group,
                                avg_load * SCHED_LOAD_SCALE);
 
-               if ((max_cpu_load - min_cpu_load) > SCHED_LOAD_SCALE)
+
+               /*
+                * Consider the group unbalanced when the imbalance is larger
+                * than the average weight of two tasks.
+                *
+                * APZ: with cgroup the avg task weight can vary wildly and
+                *      might not be a suitable number - should we keep a
+                *      normalized nr_running number somewhere that negates
+                *      the hierarchy?
+                */
+               avg_load_per_task = sg_div_cpu_power(group,
+                               sum_avg_load_per_task * SCHED_LOAD_SCALE);
+
+               if ((max_cpu_load - min_cpu_load) > 2*avg_load_per_task)
                        __group_imb = 1;
 
                group_capacity = group->__cpu_power / SCHED_LOAD_SCALE;
@@ -3156,9 +3375,9 @@ small_imbalance:
                        if (busiest_load_per_task > this_load_per_task)
                                imbn = 1;
                } else
-                       this_load_per_task = SCHED_LOAD_SCALE;
+                       this_load_per_task = cpu_avg_load_per_task(this_cpu);
 
-               if (max_load - this_load + SCHED_LOAD_SCALE_FUZZ >=
+               if (max_load - this_load + 2*busiest_load_per_task >=
                                        busiest_load_per_task * imbn) {
                        *imbalance = busiest_load_per_task;
                        return busiest;
@@ -3284,6 +3503,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
        schedstat_inc(sd, lb_count[idle]);
 
 redo:
+       update_shares(sd);
        group = find_busiest_group(sd, this_cpu, &imbalance, idle, &sd_idle,
                                   cpus, balance);
 
@@ -3386,8 +3606,9 @@ redo:
 
        if (!ld_moved && !sd_idle && sd->flags & SD_SHARE_CPUPOWER &&
            !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE))
-               return -1;
-       return ld_moved;
+               ld_moved = -1;
+
+       goto out;
 
 out_balanced:
        schedstat_inc(sd, lb_balanced[idle]);
@@ -3402,8 +3623,13 @@ out_one_pinned:
 
        if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER &&
            !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE))
-               return -1;
-       return 0;
+               ld_moved = -1;
+       else
+               ld_moved = 0;
+out:
+       if (ld_moved)
+               update_shares(sd);
+       return ld_moved;
 }
 
 /*
@@ -3438,6 +3664,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd,
 
        schedstat_inc(sd, lb_count[CPU_NEWLY_IDLE]);
 redo:
+       update_shares_locked(this_rq, sd);
        group = find_busiest_group(sd, this_cpu, &imbalance, CPU_NEWLY_IDLE,
                                   &sd_idle, cpus, NULL);
        if (!group) {
@@ -3481,6 +3708,7 @@ redo:
        } else
                sd->nr_balance_failed = 0;
 
+       update_shares_locked(this_rq, sd);
        return ld_moved;
 
 out_balanced:
@@ -3672,6 +3900,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
        /* Earliest time when we have to do rebalance again */
        unsigned long next_balance = jiffies + 60*HZ;
        int update_next_balance = 0;
+       int need_serialize;
        cpumask_t tmp;
 
        for_each_domain(cpu, sd) {
@@ -3689,8 +3918,9 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
                if (interval > HZ*NR_CPUS/10)
                        interval = HZ*NR_CPUS/10;
 
+               need_serialize = sd->flags & SD_SERIALIZE;
 
-               if (sd->flags & SD_SERIALIZE) {
+               if (need_serialize) {
                        if (!spin_trylock(&balancing))
                                goto out;
                }
@@ -3706,7 +3936,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
                        }
                        sd->last_balance = jiffies;
                }
-               if (sd->flags & SD_SERIALIZE)
+               if (need_serialize)
                        spin_unlock(&balancing);
 out:
                if (time_after(next_balance, sd->last_balance + interval)) {
@@ -4021,26 +4251,44 @@ void scheduler_tick(void)
 #endif
 }
 
-#if defined(CONFIG_PREEMPT) && defined(CONFIG_DEBUG_PREEMPT)
+#if defined(CONFIG_PREEMPT) && (defined(CONFIG_DEBUG_PREEMPT) || \
+                               defined(CONFIG_PREEMPT_TRACER))
+
+static inline unsigned long get_parent_ip(unsigned long addr)
+{
+       if (in_lock_functions(addr)) {
+               addr = CALLER_ADDR2;
+               if (in_lock_functions(addr))
+                       addr = CALLER_ADDR3;
+       }
+       return addr;
+}
 
 void __kprobes add_preempt_count(int val)
 {
+#ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Underflow?
         */
        if (DEBUG_LOCKS_WARN_ON((preempt_count() < 0)))
                return;
+#endif
        preempt_count() += val;
+#ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Spinlock count overflowing soon?
         */
        DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >=
                                PREEMPT_MASK - 10);
+#endif
+       if (preempt_count() == val)
+               trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
 }
 EXPORT_SYMBOL(add_preempt_count);
 
 void __kprobes sub_preempt_count(int val)
 {
+#ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Underflow?
         */
@@ -4052,7 +4300,10 @@ void __kprobes sub_preempt_count(int val)
        if (DEBUG_LOCKS_WARN_ON((val < PREEMPT_MASK) &&
                        !(preempt_count() & PREEMPT_MASK)))
                return;
+#endif
 
+       if (preempt_count() == val)
+               trace_preempt_on(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
        preempt_count() -= val;
 }
 EXPORT_SYMBOL(sub_preempt_count);
@@ -4070,6 +4321,7 @@ static noinline void __schedule_bug(struct task_struct *prev)
                prev->comm, prev->pid, preempt_count());
 
        debug_show_held_locks(prev);
+       print_modules();
        if (irqs_disabled())
                print_irqtrace_events(prev);
 
@@ -4143,7 +4395,7 @@ asmlinkage void __sched schedule(void)
        struct task_struct *prev, *next;
        unsigned long *switch_count;
        struct rq *rq;
-       int cpu;
+       int cpu, hrtick = sched_feat(HRTICK);
 
 need_resched:
        preempt_disable();
@@ -4158,7 +4410,8 @@ need_resched_nonpreemptible:
 
        schedule_debug(prev);
 
-       hrtick_clear(rq);
+       if (hrtick)
+               hrtick_clear(rq);
 
        /*
         * Do the rq-clock update outside the rq lock:
@@ -4204,7 +4457,8 @@ need_resched_nonpreemptible:
        } else
                spin_unlock_irq(&rq->lock);
 
-       hrtick_set(rq);
+       if (hrtick)
+               hrtick_set(rq);
 
        if (unlikely(reacquire_kernel_lock(current) < 0))
                goto need_resched_nonpreemptible;
@@ -4586,10 +4840,8 @@ void set_user_nice(struct task_struct *p, long nice)
                goto out_unlock;
        }
        on_rq = p->se.on_rq;
-       if (on_rq) {
+       if (on_rq)
                dequeue_task(rq, p, 0);
-               dec_load(rq, p);
-       }
 
        p->static_prio = NICE_TO_PRIO(nice);
        set_load_weight(p);
@@ -4599,7 +4851,6 @@ void set_user_nice(struct task_struct *p, long nice)
 
        if (on_rq) {
                enqueue_task(rq, p, 0);
-               inc_load(rq, p);
                /*
                 * If the task increased its priority or is running and
                 * lowered its priority, then reschedule its CPU:
@@ -4744,16 +4995,8 @@ __setscheduler(struct rq *rq, struct task_struct *p, int policy, int prio)
        set_load_weight(p);
 }
 
-/**
- * sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
- * @p: the task in question.
- * @policy: new policy.
- * @param: structure containing the new RT priority.
- *
- * NOTE that the task may be already dead.
- */
-int sched_setscheduler(struct task_struct *p, int policy,
-                      struct sched_param *param)
+static int __sched_setscheduler(struct task_struct *p, int policy,
+                               struct sched_param *param, bool user)
 {
        int retval, oldprio, oldpolicy = -1, on_rq, running;
        unsigned long flags;
@@ -4785,7 +5028,7 @@ recheck:
        /*
         * Allow unprivileged RT tasks to decrease priority:
         */
-       if (!capable(CAP_SYS_NICE)) {
+       if (user && !capable(CAP_SYS_NICE)) {
                if (rt_policy(policy)) {
                        unsigned long rlim_rtprio;
 
@@ -4821,7 +5064,8 @@ recheck:
         * Do not allow realtime tasks into groups that have no runtime
         * assigned.
         */
-       if (rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0)
+       if (user
+           && rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0)
                return -EPERM;
 #endif
 
@@ -4870,8 +5114,39 @@ recheck:
 
        return 0;
 }
+
+/**
+ * sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
+ * @p: the task in question.
+ * @policy: new policy.
+ * @param: structure containing the new RT priority.
+ *
+ * NOTE that the task may be already dead.
+ */
+int sched_setscheduler(struct task_struct *p, int policy,
+                      struct sched_param *param)
+{
+       return __sched_setscheduler(p, policy, param, true);
+}
 EXPORT_SYMBOL_GPL(sched_setscheduler);
 
+/**
+ * sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace.
+ * @p: the task in question.
+ * @policy: new policy.
+ * @param: structure containing the new RT priority.
+ *
+ * Just like sched_setscheduler, only don't bother checking if the
+ * current context has permission.  For example, this is needed in
+ * stop_machine(): we create temporary high priority worker threads,
+ * but our caller might not have that capability.
+ */
+int sched_setscheduler_nocheck(struct task_struct *p, int policy,
+                              struct sched_param *param)
+{
+       return __sched_setscheduler(p, policy, param, false);
+}
+
 static int
 do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
 {
@@ -5070,24 +5345,6 @@ asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
        return sched_setaffinity(pid, &new_mask);
 }
 
-/*
- * Represents all cpu's present in the system
- * In systems capable of hotplug, this map could dynamically grow
- * as new cpu's are detected in the system via any platform specific
- * method, such as ACPI for e.g.
- */
-
-cpumask_t cpu_present_map __read_mostly;
-EXPORT_SYMBOL(cpu_present_map);
-
-#ifndef CONFIG_SMP
-cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL;
-EXPORT_SYMBOL(cpu_online_map);
-
-cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL;
-EXPORT_SYMBOL(cpu_possible_map);
-#endif
-
 long sched_getaffinity(pid_t pid, cpumask_t *mask)
 {
        struct task_struct *p;
@@ -5384,7 +5641,7 @@ out_unlock:
        return retval;
 }
 
-static const char stat_nam[] = "RSDTtZX";
+static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
 
 void sched_show_task(struct task_struct *p)
 {
@@ -5571,6 +5828,12 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask)
                goto out;
        }
 
+       if (unlikely((p->flags & PF_THREAD_BOUND) && p != current &&
+                    !cpus_equal(p->cpus_allowed, *new_mask))) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        if (p->sched_class->set_cpus_allowed)
                p->sched_class->set_cpus_allowed(p, new_mask);
        else {
@@ -6060,6 +6323,36 @@ static void unregister_sched_domain_sysctl(void)
 }
 #endif
 
+static void set_rq_online(struct rq *rq)
+{
+       if (!rq->online) {
+               const struct sched_class *class;
+
+               cpu_set(rq->cpu, rq->rd->online);
+               rq->online = 1;
+
+               for_each_class(class) {
+                       if (class->rq_online)
+                               class->rq_online(rq);
+               }
+       }
+}
+
+static void set_rq_offline(struct rq *rq)
+{
+       if (rq->online) {
+               const struct sched_class *class;
+
+               for_each_class(class) {
+                       if (class->rq_offline)
+                               class->rq_offline(rq);
+               }
+
+               cpu_clear(rq->cpu, rq->rd->online);
+               rq->online = 0;
+       }
+}
+
 /*
  * migration_call - callback that gets triggered when a CPU is added.
  * Here we can start up the necessary migration thread for the new CPU.
@@ -6097,7 +6390,8 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
                spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpu_isset(cpu, rq->rd->span));
-                       cpu_set(cpu, rq->rd->online);
+
+                       set_rq_online(rq);
                }
                spin_unlock_irqrestore(&rq->lock, flags);
                break;
@@ -6158,7 +6452,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
                spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpu_isset(cpu, rq->rd->span));
-                       cpu_clear(cpu, rq->rd->online);
+                       set_rq_offline(rq);
                }
                spin_unlock_irqrestore(&rq->lock, flags);
                break;
@@ -6192,6 +6486,28 @@ void __init migration_init(void)
 
 #ifdef CONFIG_SCHED_DEBUG
 
+static inline const char *sd_level_to_string(enum sched_domain_level lvl)
+{
+       switch (lvl) {
+       case SD_LV_NONE:
+                       return "NONE";
+       case SD_LV_SIBLING:
+                       return "SIBLING";
+       case SD_LV_MC:
+                       return "MC";
+       case SD_LV_CPU:
+                       return "CPU";
+       case SD_LV_NODE:
+                       return "NODE";
+       case SD_LV_ALLNODES:
+                       return "ALLNODES";
+       case SD_LV_MAX:
+                       return "MAX";
+
+       }
+       return "MAX";
+}
+
 static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
                                  cpumask_t *groupmask)
 {
@@ -6211,7 +6527,8 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
                return -1;
        }
 
-       printk(KERN_CONT "span %s\n", str);
+       printk(KERN_CONT "span %s level %s\n",
+               str, sd_level_to_string(sd->level));
 
        if (!cpu_isset(cpu, sd->span)) {
                printk(KERN_ERR "ERROR: domain->span does not contain "
@@ -6295,9 +6612,9 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
        }
        kfree(groupmask);
 }
-#else
+#else /* !CONFIG_SCHED_DEBUG */
 # define sched_domain_debug(sd, cpu) do { } while (0)
-#endif
+#endif /* CONFIG_SCHED_DEBUG */
 
 static int sd_degenerate(struct sched_domain *sd)
 {
@@ -6357,20 +6674,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
 static void rq_attach_root(struct rq *rq, struct root_domain *rd)
 {
        unsigned long flags;
-       const struct sched_class *class;
 
        spin_lock_irqsave(&rq->lock, flags);
 
        if (rq->rd) {
                struct root_domain *old_rd = rq->rd;
 
-               for (class = sched_class_highest; class; class = class->next) {
-                       if (class->leave_domain)
-                               class->leave_domain(rq);
-               }
+               if (cpu_isset(rq->cpu, old_rd->online))
+                       set_rq_offline(rq);
 
                cpu_clear(rq->cpu, old_rd->span);
-               cpu_clear(rq->cpu, old_rd->online);
 
                if (atomic_dec_and_test(&old_rd->refcount))
                        kfree(old_rd);
@@ -6381,12 +6694,7 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd)
 
        cpu_set(rq->cpu, rd->span);
        if (cpu_isset(rq->cpu, cpu_online_map))
-               cpu_set(rq->cpu, rd->online);
-
-       for (class = sched_class_highest; class; class = class->next) {
-               if (class->join_domain)
-                       class->join_domain(rq);
-       }
+               set_rq_online(rq);
 
        spin_unlock_irqrestore(&rq->lock, flags);
 }
@@ -6397,6 +6705,8 @@ static void init_rootdomain(struct root_domain *rd)
 
        cpus_clear(rd->span);
        cpus_clear(rd->online);
+
+       cpupri_init(&rd->cpupri);
 }
 
 static void init_defrootdomain(void)
@@ -6539,9 +6849,9 @@ static int find_next_best_node(int node, nodemask_t *used_nodes)
 
        min_val = INT_MAX;
 
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                /* Start at @node */
-               n = (node + i) % MAX_NUMNODES;
+               n = (node + i) % nr_node_ids;
 
                if (!nr_cpus_node(n))
                        continue;
@@ -6591,7 +6901,7 @@ static void sched_domain_node_span(int node, cpumask_t *span)
                cpus_or(*span, *span, *nodemask);
        }
 }
-#endif
+#endif /* CONFIG_NUMA */
 
 int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
 
@@ -6610,7 +6920,7 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg,
                *sg = &per_cpu(sched_group_cpus, cpu);
        return cpu;
 }
-#endif
+#endif /* CONFIG_SCHED_SMT */
 
 /*
  * multi-core sched-domains:
@@ -6618,7 +6928,7 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg,
 #ifdef CONFIG_SCHED_MC
 static DEFINE_PER_CPU(struct sched_domain, core_domains);
 static DEFINE_PER_CPU(struct sched_group, sched_group_core);
-#endif
+#endif /* CONFIG_SCHED_MC */
 
 #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT)
 static int
@@ -6720,7 +7030,7 @@ static void init_numa_sched_groups_power(struct sched_group *group_head)
                sg = sg->next;
        } while (sg != group_head);
 }
-#endif
+#endif /* CONFIG_NUMA */
 
 #ifdef CONFIG_NUMA
 /* Free memory allocated for various sched_group structures */
@@ -6735,7 +7045,7 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask)
                if (!sched_group_nodes)
                        continue;
 
-               for (i = 0; i < MAX_NUMNODES; i++) {
+               for (i = 0; i < nr_node_ids; i++) {
                        struct sched_group *oldsg, *sg = sched_group_nodes[i];
 
                        *nodemask = node_to_cpumask(i);
@@ -6757,11 +7067,11 @@ next_sg:
                sched_group_nodes_bycpu[cpu] = NULL;
        }
 }
-#else
+#else /* !CONFIG_NUMA */
 static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask)
 {
 }
-#endif
+#endif /* CONFIG_NUMA */
 
 /*
  * Initialize sched groups cpu_power.
@@ -6928,7 +7238,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
        /*
         * Allocate the per-node list of sched groups
         */
-       sched_group_nodes = kcalloc(MAX_NUMNODES, sizeof(struct sched_group *),
+       sched_group_nodes = kcalloc(nr_node_ids, sizeof(struct sched_group *),
                                    GFP_KERNEL);
        if (!sched_group_nodes) {
                printk(KERN_WARNING "Can not alloc sched group node list\n");
@@ -7067,7 +7377,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
 #endif
 
        /* Set up physical groups */
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                SCHED_CPUMASK_VAR(nodemask, allmasks);
                SCHED_CPUMASK_VAR(send_covered, allmasks);
 
@@ -7091,7 +7401,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
                                        send_covered, tmpmask);
        }
 
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                /* Set up node groups */
                struct sched_group *sg, *prev;
                SCHED_CPUMASK_VAR(nodemask, allmasks);
@@ -7130,9 +7440,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
                cpus_or(*covered, *covered, *nodemask);
                prev = sg;
 
-               for (j = 0; j < MAX_NUMNODES; j++) {
+               for (j = 0; j < nr_node_ids; j++) {
                        SCHED_CPUMASK_VAR(notcovered, allmasks);
-                       int n = (i + j) % MAX_NUMNODES;
+                       int n = (i + j) % nr_node_ids;
                        node_to_cpumask_ptr(pnodemask, n);
 
                        cpus_complement(*notcovered, *covered);
@@ -7185,7 +7495,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
        }
 
 #ifdef CONFIG_NUMA
-       for (i = 0; i < MAX_NUMNODES; i++)
+       for (i = 0; i < nr_node_ids; i++)
                init_numa_sched_groups_power(sched_group_nodes[i]);
 
        if (sd_allnodes) {
@@ -7470,7 +7780,7 @@ int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls)
 #endif
        return err;
 }
-#endif
+#endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */
 
 /*
  * Force a reinitialization of the sched domains hierarchy. The domains
@@ -7481,21 +7791,28 @@ int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls)
 static int update_sched_domains(struct notifier_block *nfb,
                                unsigned long action, void *hcpu)
 {
+       int cpu = (int)(long)hcpu;
+
        switch (action) {
-       case CPU_UP_PREPARE:
-       case CPU_UP_PREPARE_FROZEN:
        case CPU_DOWN_PREPARE:
        case CPU_DOWN_PREPARE_FROZEN:
+               disable_runtime(cpu_rq(cpu));
+               /* fall-through */
+       case CPU_UP_PREPARE:
+       case CPU_UP_PREPARE_FROZEN:
                detach_destroy_domains(&cpu_online_map);
                free_sched_domains();
                return NOTIFY_OK;
 
-       case CPU_UP_CANCELED:
-       case CPU_UP_CANCELED_FROZEN:
+
        case CPU_DOWN_FAILED:
        case CPU_DOWN_FAILED_FROZEN:
        case CPU_ONLINE:
        case CPU_ONLINE_FROZEN:
+               enable_runtime(cpu_rq(cpu));
+               /* fall-through */
+       case CPU_UP_CANCELED:
+       case CPU_UP_CANCELED_FROZEN:
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
                /*
@@ -7695,8 +8012,8 @@ void __init sched_init(void)
 
                root_task_group.cfs_rq = (struct cfs_rq **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
-#endif
-#endif
+#endif /* CONFIG_USER_SCHED */
+#endif /* CONFIG_FAIR_GROUP_SCHED */
 #ifdef CONFIG_RT_GROUP_SCHED
                init_task_group.rt_se = (struct sched_rt_entity **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
@@ -7710,8 +8027,8 @@ void __init sched_init(void)
 
                root_task_group.rt_rq = (struct rt_rq **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
-#endif
-#endif
+#endif /* CONFIG_USER_SCHED */
+#endif /* CONFIG_RT_GROUP_SCHED */
        }
 
 #ifdef CONFIG_SMP
@@ -7727,8 +8044,8 @@ void __init sched_init(void)
 #ifdef CONFIG_USER_SCHED
        init_rt_bandwidth(&root_task_group.rt_bandwidth,
                        global_rt_period(), RUNTIME_INF);
-#endif
-#endif
+#endif /* CONFIG_USER_SCHED */
+#endif /* CONFIG_RT_GROUP_SCHED */
 
 #ifdef CONFIG_GROUP_SCHED
        list_add(&init_task_group.list, &task_groups);
@@ -7738,8 +8055,8 @@ void __init sched_init(void)
        INIT_LIST_HEAD(&root_task_group.children);
        init_task_group.parent = &root_task_group;
        list_add(&init_task_group.siblings, &root_task_group.children);
-#endif
-#endif
+#endif /* CONFIG_USER_SCHED */
+#endif /* CONFIG_GROUP_SCHED */
 
        for_each_possible_cpu(i) {
                struct rq *rq;
@@ -7819,6 +8136,7 @@ void __init sched_init(void)
                rq->next_balance = jiffies;
                rq->push_cpu = 0;
                rq->cpu = i;
+               rq->online = 0;
                rq->migration_thread = NULL;
                INIT_LIST_HEAD(&rq->migration_queue);
                rq_attach_root(rq, &def_root_domain);
@@ -7834,7 +8152,7 @@ void __init sched_init(void)
 #endif
 
 #ifdef CONFIG_SMP
-       open_softirq(SCHED_SOFTIRQ, run_rebalance_domains, NULL);
+       open_softirq(SCHED_SOFTIRQ, run_rebalance_domains);
 #endif
 
 #ifdef CONFIG_RT_MUTEXES
@@ -8058,7 +8376,7 @@ static inline void unregister_fair_sched_group(struct task_group *tg, int cpu)
 {
        list_del_rcu(&tg->cfs_rq[cpu]->leaf_cfs_rq_list);
 }
-#else
+#else /* !CONFG_FAIR_GROUP_SCHED */
 static inline void free_fair_sched_group(struct task_group *tg)
 {
 }
@@ -8076,7 +8394,7 @@ static inline void register_fair_sched_group(struct task_group *tg, int cpu)
 static inline void unregister_fair_sched_group(struct task_group *tg, int cpu)
 {
 }
-#endif
+#endif /* CONFIG_FAIR_GROUP_SCHED */
 
 #ifdef CONFIG_RT_GROUP_SCHED
 static void free_rt_sched_group(struct task_group *tg)
@@ -8147,7 +8465,7 @@ static inline void unregister_rt_sched_group(struct task_group *tg, int cpu)
 {
        list_del_rcu(&tg->rt_rq[cpu]->leaf_rt_rq_list);
 }
-#else
+#else /* !CONFIG_RT_GROUP_SCHED */
 static inline void free_rt_sched_group(struct task_group *tg)
 {
 }
@@ -8165,7 +8483,7 @@ static inline void register_rt_sched_group(struct task_group *tg, int cpu)
 static inline void unregister_rt_sched_group(struct task_group *tg, int cpu)
 {
 }
-#endif
+#endif /* CONFIG_RT_GROUP_SCHED */
 
 #ifdef CONFIG_GROUP_SCHED
 static void free_sched_group(struct task_group *tg)
@@ -8276,17 +8594,14 @@ void sched_move_task(struct task_struct *tsk)
 
        task_rq_unlock(rq, &flags);
 }
-#endif
+#endif /* CONFIG_GROUP_SCHED */
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-static void set_se_shares(struct sched_entity *se, unsigned long shares)
+static void __set_se_shares(struct sched_entity *se, unsigned long shares)
 {
        struct cfs_rq *cfs_rq = se->cfs_rq;
-       struct rq *rq = cfs_rq->rq;
        int on_rq;
 
-       spin_lock_irq(&rq->lock);
-
        on_rq = se->on_rq;
        if (on_rq)
                dequeue_entity(cfs_rq, se, 0);
@@ -8296,8 +8611,17 @@ static void set_se_shares(struct sched_entity *se, unsigned long shares)
 
        if (on_rq)
                enqueue_entity(cfs_rq, se, 0);
+}
 
-       spin_unlock_irq(&rq->lock);
+static void set_se_shares(struct sched_entity *se, unsigned long shares)
+{
+       struct cfs_rq *cfs_rq = se->cfs_rq;
+       struct rq *rq = cfs_rq->rq;
+       unsigned long flags;
+
+       spin_lock_irqsave(&rq->lock, flags);
+       __set_se_shares(se, shares);
+       spin_unlock_irqrestore(&rq->lock, flags);
 }
 
 static DEFINE_MUTEX(shares_mutex);
@@ -8336,8 +8660,13 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
         * w/o tripping rebalance_share or load_balance_fair.
         */
        tg->shares = shares;
-       for_each_possible_cpu(i)
+       for_each_possible_cpu(i) {
+               /*
+                * force a rebalance
+                */
+               cfs_rq_set_shares(tg->cfs_rq[i], 0);
                set_se_shares(tg->se[i], shares);
+       }
 
        /*
         * Enable load balance activity on this group, by inserting it back on
@@ -8376,7 +8705,7 @@ static unsigned long to_ratio(u64 period, u64 runtime)
 #ifdef CONFIG_CGROUP_SCHED
 static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
 {
-       struct task_group *tgi, *parent = tg ? tg->parent : NULL;
+       struct task_group *tgi, *parent = tg->parent;
        unsigned long total = 0;
 
        if (!parent) {
@@ -8400,7 +8729,7 @@ static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
        }
        rcu_read_unlock();
 
-       return total + to_ratio(period, runtime) <
+       return total + to_ratio(period, runtime) <=
                to_ratio(ktime_to_ns(parent->rt_bandwidth.rt_period),
                                parent->rt_bandwidth.rt_runtime);
 }
@@ -8520,16 +8849,21 @@ long sched_group_rt_period(struct task_group *tg)
 
 static int sched_rt_global_constraints(void)
 {
+       struct task_group *tg = &root_task_group;
+       u64 rt_runtime, rt_period;
        int ret = 0;
 
+       rt_period = ktime_to_ns(tg->rt_bandwidth.rt_period);
+       rt_runtime = tg->rt_bandwidth.rt_runtime;
+
        mutex_lock(&rt_constraints_mutex);
-       if (!__rt_schedulable(NULL, 1, 0))
+       if (!__rt_schedulable(tg, rt_period, rt_runtime))
                ret = -EINVAL;
        mutex_unlock(&rt_constraints_mutex);
 
        return ret;
 }
-#else
+#else /* !CONFIG_RT_GROUP_SCHED */
 static int sched_rt_global_constraints(void)
 {
        unsigned long flags;
@@ -8547,7 +8881,7 @@ static int sched_rt_global_constraints(void)
 
        return 0;
 }
-#endif
+#endif /* CONFIG_RT_GROUP_SCHED */
 
 int sched_rt_handler(struct ctl_table *table, int write,
                struct file *filp, void __user *buffer, size_t *lenp,
@@ -8655,7 +8989,7 @@ static u64 cpu_shares_read_u64(struct cgroup *cgrp, struct cftype *cft)
 
        return (u64) tg->shares;
 }
-#endif
+#endif /* CONFIG_FAIR_GROUP_SCHED */
 
 #ifdef CONFIG_RT_GROUP_SCHED
 static int cpu_rt_runtime_write(struct cgroup *cgrp, struct cftype *cft,
@@ -8679,7 +9013,7 @@ static u64 cpu_rt_period_read_uint(struct cgroup *cgrp, struct cftype *cft)
 {
        return sched_group_rt_period(cgroup_tg(cgrp));
 }
-#endif
+#endif /* CONFIG_RT_GROUP_SCHED */
 
 static struct cftype cpu_files[] = {
 #ifdef CONFIG_FAIR_GROUP_SCHED
index ce05271..22ed55d 100644 (file)
@@ -3,6 +3,9 @@
  *
  *  Copyright (C) 2008 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
  *
+ *  Updates and enhancements:
+ *    Copyright (C) 2008 Red Hat, Inc. Steven Rostedt <srostedt@redhat.com>
+ *
  * Based on code by:
  *   Ingo Molnar <mingo@redhat.com>
  *   Guillaume Chazarain <guichaz@gmail.com>
 
 #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
 
+#define MULTI_SHIFT 15
+/* Max is double, Min is 1/2 */
+#define MAX_MULTI (2LL << MULTI_SHIFT)
+#define MIN_MULTI (1LL << (MULTI_SHIFT-1))
+
 struct sched_clock_data {
        /*
         * Raw spinlock - this is a special case: this might be called
@@ -40,11 +48,15 @@ struct sched_clock_data {
         */
        raw_spinlock_t          lock;
 
-       unsigned long           prev_jiffies;
+       unsigned long           tick_jiffies;
        u64                     prev_raw;
        u64                     tick_raw;
        u64                     tick_gtod;
        u64                     clock;
+       s64                     multi;
+#ifdef CONFIG_NO_HZ
+       int                     check_max;
+#endif
 };
 
 static DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_clock_data, sched_clock_data);
@@ -71,41 +83,91 @@ void sched_clock_init(void)
                struct sched_clock_data *scd = cpu_sdc(cpu);
 
                scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
-               scd->prev_jiffies = now_jiffies;
+               scd->tick_jiffies = now_jiffies;
                scd->prev_raw = 0;
                scd->tick_raw = 0;
                scd->tick_gtod = ktime_now;
                scd->clock = ktime_now;
+               scd->multi = 1 << MULTI_SHIFT;
+#ifdef CONFIG_NO_HZ
+               scd->check_max = 1;
+#endif
        }
 
        sched_clock_running = 1;
 }
 
+#ifdef CONFIG_NO_HZ
+/*
+ * The dynamic ticks makes the delta jiffies inaccurate. This
+ * prevents us from checking the maximum time update.
+ * Disable the maximum check during stopped ticks.
+ */
+void sched_clock_tick_stop(int cpu)
+{
+       struct sched_clock_data *scd = cpu_sdc(cpu);
+
+       scd->check_max = 0;
+}
+
+void sched_clock_tick_start(int cpu)
+{
+       struct sched_clock_data *scd = cpu_sdc(cpu);
+
+       scd->check_max = 1;
+}
+
+static int check_max(struct sched_clock_data *scd)
+{
+       return scd->check_max;
+}
+#else
+static int check_max(struct sched_clock_data *scd)
+{
+       return 1;
+}
+#endif /* CONFIG_NO_HZ */
+
 /*
  * update the percpu scd from the raw @now value
  *
  *  - filter out backward motion
  *  - use jiffies to generate a min,max window to clip the raw values
  */
-static void __update_sched_clock(struct sched_clock_data *scd, u64 now)
+static void __update_sched_clock(struct sched_clock_data *scd, u64 now, u64 *time)
 {
        unsigned long now_jiffies = jiffies;
-       long delta_jiffies = now_jiffies - scd->prev_jiffies;
+       long delta_jiffies = now_jiffies - scd->tick_jiffies;
        u64 clock = scd->clock;
        u64 min_clock, max_clock;
        s64 delta = now - scd->prev_raw;
 
        WARN_ON_ONCE(!irqs_disabled());
-       min_clock = scd->tick_gtod + delta_jiffies * TICK_NSEC;
+
+       /*
+        * At schedule tick the clock can be just under the gtod. We don't
+        * want to push it too prematurely.
+        */
+       min_clock = scd->tick_gtod + (delta_jiffies * TICK_NSEC);
+       if (min_clock > TICK_NSEC)
+               min_clock -= TICK_NSEC / 2;
 
        if (unlikely(delta < 0)) {
                clock++;
                goto out;
        }
 
-       max_clock = min_clock + TICK_NSEC;
+       /*
+        * The clock must stay within a jiffie of the gtod.
+        * But since we may be at the start of a jiffy or the end of one
+        * we add another jiffy buffer.
+        */
+       max_clock = scd->tick_gtod + (2 + delta_jiffies) * TICK_NSEC;
+
+       delta *= scd->multi;
+       delta >>= MULTI_SHIFT;
 
-       if (unlikely(clock + delta > max_clock)) {
+       if (unlikely(clock + delta > max_clock) && check_max(scd)) {
                if (clock < max_clock)
                        clock = max_clock;
                else
@@ -118,9 +180,12 @@ static void __update_sched_clock(struct sched_clock_data *scd, u64 now)
        if (unlikely(clock < min_clock))
                clock = min_clock;
 
-       scd->prev_raw = now;
-       scd->prev_jiffies = now_jiffies;
-       scd->clock = clock;
+       if (time)
+               *time = clock;
+       else {
+               scd->prev_raw = now;
+               scd->clock = clock;
+       }
 }
 
 static void lock_double_clock(struct sched_clock_data *data1,
@@ -160,25 +225,30 @@ u64 sched_clock_cpu(int cpu)
                now -= my_scd->tick_raw;
                now += scd->tick_raw;
 
-               now -= my_scd->tick_gtod;
-               now += scd->tick_gtod;
+               now += my_scd->tick_gtod;
+               now -= scd->tick_gtod;
 
                __raw_spin_unlock(&my_scd->lock);
+
+               __update_sched_clock(scd, now, &clock);
+
+               __raw_spin_unlock(&scd->lock);
+
        } else {
                __raw_spin_lock(&scd->lock);
+               __update_sched_clock(scd, now, NULL);
+               clock = scd->clock;
+               __raw_spin_unlock(&scd->lock);
        }
 
-       __update_sched_clock(scd, now);
-       clock = scd->clock;
-
-       __raw_spin_unlock(&scd->lock);
-
        return clock;
 }
 
 void sched_clock_tick(void)
 {
        struct sched_clock_data *scd = this_scd();
+       unsigned long now_jiffies = jiffies;
+       s64 mult, delta_gtod, delta_raw;
        u64 now, now_gtod;
 
        if (unlikely(!sched_clock_running))
@@ -186,18 +256,33 @@ void sched_clock_tick(void)
 
        WARN_ON_ONCE(!irqs_disabled());
 
-       now = sched_clock();
        now_gtod = ktime_to_ns(ktime_get());
+       now = sched_clock();
 
        __raw_spin_lock(&scd->lock);
-       __update_sched_clock(scd, now);
+       __update_sched_clock(scd, now, NULL);
        /*
         * update tick_gtod after __update_sched_clock() because that will
         * already observe 1 new jiffy; adding a new tick_gtod to that would
         * increase the clock 2 jiffies.
         */
+       delta_gtod = now_gtod - scd->tick_gtod;
+       delta_raw = now - scd->tick_raw;
+
+       if ((long)delta_raw > 0) {
+               mult = delta_gtod << MULTI_SHIFT;
+               do_div(mult, delta_raw);
+               scd->multi = mult;
+               if (scd->multi > MAX_MULTI)
+                       scd->multi = MAX_MULTI;
+               else if (scd->multi < MIN_MULTI)
+                       scd->multi = MIN_MULTI;
+       } else
+               scd->multi = 1 << MULTI_SHIFT;
+
        scd->tick_raw = now;
        scd->tick_gtod = now_gtod;
+       scd->tick_jiffies = now_jiffies;
        __raw_spin_unlock(&scd->lock);
 }
 
@@ -227,6 +312,7 @@ void sched_clock_idle_wakeup_event(u64 delta_ns)
        __raw_spin_lock(&scd->lock);
        scd->prev_raw = now;
        scd->clock += delta_ns;
+       scd->multi = 1 << MULTI_SHIFT;
        __raw_spin_unlock(&scd->lock);
 
        touch_softlockup_watchdog();
@@ -244,3 +330,16 @@ unsigned long long __attribute__((weak)) sched_clock(void)
 {
        return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
 }
+
+unsigned long long cpu_clock(int cpu)
+{
+       unsigned long long clock;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       clock = sched_clock_cpu(cpu);
+       local_irq_restore(flags);
+
+       return clock;
+}
+EXPORT_SYMBOL_GPL(cpu_clock);
diff --git a/kernel/sched_cpupri.c b/kernel/sched_cpupri.c
new file mode 100644 (file)
index 0000000..52154fe
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ *  kernel/sched_cpupri.c
+ *
+ *  CPU priority management
+ *
+ *  Copyright (C) 2007-2008 Novell
+ *
+ *  Author: Gregory Haskins <ghaskins@novell.com>
+ *
+ *  This code tracks the priority of each CPU so that global migration
+ *  decisions are easy to calculate.  Each CPU can be in a state as follows:
+ *
+ *                 (INVALID), IDLE, NORMAL, RT1, ... RT99
+ *
+ *  going from the lowest priority to the highest.  CPUs in the INVALID state
+ *  are not eligible for routing.  The system maintains this state with
+ *  a 2 dimensional bitmap (the first for priority class, the second for cpus
+ *  in that class).  Therefore a typical application without affinity
+ *  restrictions can find a suitable CPU with O(1) complexity (e.g. two bit
+ *  searches).  For tasks with affinity restrictions, the algorithm has a
+ *  worst case complexity of O(min(102, nr_domcpus)), though the scenario that
+ *  yields the worst case search is fairly contrived.
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ */
+
+#include "sched_cpupri.h"
+
+/* Convert between a 140 based task->prio, and our 102 based cpupri */
+static int convert_prio(int prio)
+{
+       int cpupri;
+
+       if (prio == CPUPRI_INVALID)
+               cpupri = CPUPRI_INVALID;
+       else if (prio == MAX_PRIO)
+               cpupri = CPUPRI_IDLE;
+       else if (prio >= MAX_RT_PRIO)
+               cpupri = CPUPRI_NORMAL;
+       else
+               cpupri = MAX_RT_PRIO - prio + 1;
+
+       return cpupri;
+}
+
+#define for_each_cpupri_active(array, idx)                    \
+  for (idx = find_first_bit(array, CPUPRI_NR_PRIORITIES);     \
+       idx < CPUPRI_NR_PRIORITIES;                            \
+       idx = find_next_bit(array, CPUPRI_NR_PRIORITIES, idx+1))
+
+/**
+ * cpupri_find - find the best (lowest-pri) CPU in the system
+ * @cp: The cpupri context
+ * @p: The task
+ * @lowest_mask: A mask to fill in with selected CPUs
+ *
+ * Note: This function returns the recommended CPUs as calculated during the
+ * current invokation.  By the time the call returns, the CPUs may have in
+ * fact changed priorities any number of times.  While not ideal, it is not
+ * an issue of correctness since the normal rebalancer logic will correct
+ * any discrepancies created by racing against the uncertainty of the current
+ * priority configuration.
+ *
+ * Returns: (int)bool - CPUs were found
+ */
+int cpupri_find(struct cpupri *cp, struct task_struct *p,
+               cpumask_t *lowest_mask)
+{
+       int                  idx      = 0;
+       int                  task_pri = convert_prio(p->prio);
+
+       for_each_cpupri_active(cp->pri_active, idx) {
+               struct cpupri_vec *vec  = &cp->pri_to_cpu[idx];
+               cpumask_t mask;
+
+               if (idx >= task_pri)
+                       break;
+
+               cpus_and(mask, p->cpus_allowed, vec->mask);
+
+               if (cpus_empty(mask))
+                       continue;
+
+               *lowest_mask = mask;
+               return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * cpupri_set - update the cpu priority setting
+ * @cp: The cpupri context
+ * @cpu: The target cpu
+ * @pri: The priority (INVALID-RT99) to assign to this CPU
+ *
+ * Note: Assumes cpu_rq(cpu)->lock is locked
+ *
+ * Returns: (void)
+ */
+void cpupri_set(struct cpupri *cp, int cpu, int newpri)
+{
+       int                 *currpri = &cp->cpu_to_pri[cpu];
+       int                  oldpri  = *currpri;
+       unsigned long        flags;
+
+       newpri = convert_prio(newpri);
+
+       BUG_ON(newpri >= CPUPRI_NR_PRIORITIES);
+
+       if (newpri == oldpri)
+               return;
+
+       /*
+        * If the cpu was currently mapped to a different value, we
+        * first need to unmap the old value
+        */
+       if (likely(oldpri != CPUPRI_INVALID)) {
+               struct cpupri_vec *vec  = &cp->pri_to_cpu[oldpri];
+
+               spin_lock_irqsave(&vec->lock, flags);
+
+               vec->count--;
+               if (!vec->count)
+                       clear_bit(oldpri, cp->pri_active);
+               cpu_clear(cpu, vec->mask);
+
+               spin_unlock_irqrestore(&vec->lock, flags);
+       }
+
+       if (likely(newpri != CPUPRI_INVALID)) {
+               struct cpupri_vec *vec = &cp->pri_to_cpu[newpri];
+
+               spin_lock_irqsave(&vec->lock, flags);
+
+               cpu_set(cpu, vec->mask);
+               vec->count++;
+               if (vec->count == 1)
+                       set_bit(newpri, cp->pri_active);
+
+               spin_unlock_irqrestore(&vec->lock, flags);
+       }
+
+       *currpri = newpri;
+}
+
+/**
+ * cpupri_init - initialize the cpupri structure
+ * @cp: The cpupri context
+ *
+ * Returns: (void)
+ */
+void cpupri_init(struct cpupri *cp)
+{
+       int i;
+
+       memset(cp, 0, sizeof(*cp));
+
+       for (i = 0; i < CPUPRI_NR_PRIORITIES; i++) {
+               struct cpupri_vec *vec = &cp->pri_to_cpu[i];
+
+               spin_lock_init(&vec->lock);
+               vec->count = 0;
+               cpus_clear(vec->mask);
+       }
+
+       for_each_possible_cpu(i)
+               cp->cpu_to_pri[i] = CPUPRI_INVALID;
+}
+
+
diff --git a/kernel/sched_cpupri.h b/kernel/sched_cpupri.h
new file mode 100644 (file)
index 0000000..f25811b
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef _LINUX_CPUPRI_H
+#define _LINUX_CPUPRI_H
+
+#include <linux/sched.h>
+
+#define CPUPRI_NR_PRIORITIES   (MAX_RT_PRIO + 2)
+#define CPUPRI_NR_PRI_WORDS    BITS_TO_LONGS(CPUPRI_NR_PRIORITIES)
+
+#define CPUPRI_INVALID -1
+#define CPUPRI_IDLE     0
+#define CPUPRI_NORMAL   1
+/* values 2-101 are RT priorities 0-99 */
+
+struct cpupri_vec {
+       spinlock_t lock;
+       int        count;
+       cpumask_t  mask;
+};
+
+struct cpupri {
+       struct cpupri_vec pri_to_cpu[CPUPRI_NR_PRIORITIES];
+       long              pri_active[CPUPRI_NR_PRI_WORDS];
+       int               cpu_to_pri[NR_CPUS];
+};
+
+#ifdef CONFIG_SMP
+int  cpupri_find(struct cpupri *cp,
+                struct task_struct *p, cpumask_t *lowest_mask);
+void cpupri_set(struct cpupri *cp, int cpu, int pri);
+void cpupri_init(struct cpupri *cp);
+#else
+#define cpupri_set(cp, cpu, pri) do { } while (0)
+#define cpupri_init() do { } while (0)
+#endif
+
+#endif /* _LINUX_CPUPRI_H */
index 8bb7130..bbe6b31 100644 (file)
@@ -119,9 +119,7 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
        struct sched_entity *last;
        unsigned long flags;
 
-#if !defined(CONFIG_CGROUP_SCHED) || !defined(CONFIG_USER_SCHED)
-       SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
-#else
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED)
        char path[128] = "";
        struct cgroup *cgroup = NULL;
        struct task_group *tg = cfs_rq->tg;
@@ -133,6 +131,8 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
                cgroup_path(cgroup, path, sizeof(path));
 
        SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, path);
+#else
+       SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
 #endif
 
        SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "exec_clock",
@@ -162,11 +162,64 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
        SEQ_printf(m, "  .%-30s: %ld\n", "nr_running", cfs_rq->nr_running);
        SEQ_printf(m, "  .%-30s: %ld\n", "load", cfs_rq->load.weight);
 #ifdef CONFIG_SCHEDSTATS
-       SEQ_printf(m, "  .%-30s: %d\n", "bkl_count",
-                       rq->bkl_count);
+#define P(n) SEQ_printf(m, "  .%-30s: %d\n", #n, rq->n);
+
+       P(yld_exp_empty);
+       P(yld_act_empty);
+       P(yld_both_empty);
+       P(yld_count);
+
+       P(sched_switch);
+       P(sched_count);
+       P(sched_goidle);
+
+       P(ttwu_count);
+       P(ttwu_local);
+
+       P(bkl_count);
+
+#undef P
 #endif
        SEQ_printf(m, "  .%-30s: %ld\n", "nr_spread_over",
                        cfs_rq->nr_spread_over);
+#ifdef CONFIG_FAIR_GROUP_SCHED
+#ifdef CONFIG_SMP
+       SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
+#endif
+#endif
+}
+
+void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
+{
+#if defined(CONFIG_CGROUP_SCHED) && defined(CONFIG_RT_GROUP_SCHED)
+       char path[128] = "";
+       struct cgroup *cgroup = NULL;
+       struct task_group *tg = rt_rq->tg;
+
+       if (tg)
+               cgroup = tg->css.cgroup;
+
+       if (cgroup)
+               cgroup_path(cgroup, path, sizeof(path));
+
+       SEQ_printf(m, "\nrt_rq[%d]:%s\n", cpu, path);
+#else
+       SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
+#endif
+
+
+#define P(x) \
+       SEQ_printf(m, "  .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
+#define PN(x) \
+       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
+
+       P(rt_nr_running);
+       P(rt_throttled);
+       PN(rt_time);
+       PN(rt_runtime);
+
+#undef PN
+#undef P
 }
 
 static void print_cpu(struct seq_file *m, int cpu)
@@ -208,6 +261,7 @@ static void print_cpu(struct seq_file *m, int cpu)
 #undef PN
 
        print_cfs_stats(m, cpu);
+       print_rt_stats(m, cpu);
 
        print_rq(m, rq, cpu);
 }
index 08ae848..f2aa987 100644 (file)
@@ -63,13 +63,13 @@ unsigned int __read_mostly sysctl_sched_compat_yield;
 
 /*
  * SCHED_OTHER wake-up granularity.
- * (default: 10 msec * (1 + ilog(ncpus)), units: nanoseconds)
+ * (default: 5 msec * (1 + ilog(ncpus)), units: nanoseconds)
  *
  * This option delays the preemption effects of decoupled workloads
  * and reduces their over-scheduling. Synchronous workloads will still
  * have immediate wakeup/sleep latencies.
  */
-unsigned int sysctl_sched_wakeup_granularity = 10000000UL;
+unsigned int sysctl_sched_wakeup_granularity = 5000000UL;
 
 const_debug unsigned int sysctl_sched_migration_cost = 500000UL;
 
@@ -333,6 +333,34 @@ int sched_nr_latency_handler(struct ctl_table *table, int write,
 }
 #endif
 
+/*
+ * delta *= w / rw
+ */
+static inline unsigned long
+calc_delta_weight(unsigned long delta, struct sched_entity *se)
+{
+       for_each_sched_entity(se) {
+               delta = calc_delta_mine(delta,
+                               se->load.weight, &cfs_rq_of(se)->load);
+       }
+
+       return delta;
+}
+
+/*
+ * delta *= rw / w
+ */
+static inline unsigned long
+calc_delta_fair(unsigned long delta, struct sched_entity *se)
+{
+       for_each_sched_entity(se) {
+               delta = calc_delta_mine(delta,
+                               cfs_rq_of(se)->load.weight, &se->load);
+       }
+
+       return delta;
+}
+
 /*
  * The idea is to set a period in which each task runs once.
  *
@@ -362,47 +390,80 @@ static u64 __sched_period(unsigned long nr_running)
  */
 static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
-       u64 slice = __sched_period(cfs_rq->nr_running);
-
-       for_each_sched_entity(se) {
-               cfs_rq = cfs_rq_of(se);
-
-               slice *= se->load.weight;
-               do_div(slice, cfs_rq->load.weight);
-       }
-
-
-       return slice;
+       return calc_delta_weight(__sched_period(cfs_rq->nr_running), se);
 }
 
 /*
  * We calculate the vruntime slice of a to be inserted task
  *
- * vs = s/w = p/rw
+ * vs = s*rw/w = p
  */
 static u64 sched_vslice_add(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
        unsigned long nr_running = cfs_rq->nr_running;
-       unsigned long weight;
-       u64 vslice;
 
        if (!se->on_rq)
                nr_running++;
 
-       vslice = __sched_period(nr_running);
+       return __sched_period(nr_running);
+}
+
+/*
+ * The goal of calc_delta_asym() is to be asymmetrically around NICE_0_LOAD, in
+ * that it favours >=0 over <0.
+ *
+ *   -20         |
+ *               |
+ *     0 --------+-------
+ *             .'
+ *    19     .'
+ *
+ */
+static unsigned long
+calc_delta_asym(unsigned long delta, struct sched_entity *se)
+{
+       struct load_weight lw = {
+               .weight = NICE_0_LOAD,
+               .inv_weight = 1UL << (WMULT_SHIFT-NICE_0_SHIFT)
+       };
 
        for_each_sched_entity(se) {
-               cfs_rq = cfs_rq_of(se);
+               struct load_weight *se_lw = &se->load;
+               unsigned long rw = cfs_rq_of(se)->load.weight;
+
+#ifdef CONFIG_FAIR_SCHED_GROUP
+               struct cfs_rq *cfs_rq = se->my_q;
+               struct task_group *tg = NULL
+
+               if (cfs_rq)
+                       tg = cfs_rq->tg;
+
+               if (tg && tg->shares < NICE_0_LOAD) {
+                       /*
+                        * scale shares to what it would have been had
+                        * tg->weight been NICE_0_LOAD:
+                        *
+                        *   weight = 1024 * shares / tg->weight
+                        */
+                       lw.weight *= se->load.weight;
+                       lw.weight /= tg->shares;
+
+                       lw.inv_weight = 0;
+
+                       se_lw = &lw;
+                       rw += lw.weight - se->load.weight;
+               } else
+#endif
 
-               weight = cfs_rq->load.weight;
-               if (!se->on_rq)
-                       weight += se->load.weight;
+               if (se->load.weight < NICE_0_LOAD) {
+                       se_lw = &lw;
+                       rw += NICE_0_LOAD - se->load.weight;
+               }
 
-               vslice *= NICE_0_LOAD;
-               do_div(vslice, weight);
+               delta = calc_delta_mine(delta, rw, se_lw);
        }
 
-       return vslice;
+       return delta;
 }
 
 /*
@@ -419,11 +480,7 @@ __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr,
 
        curr->sum_exec_runtime += delta_exec;
        schedstat_add(cfs_rq, exec_clock, delta_exec);
-       delta_exec_weighted = delta_exec;
-       if (unlikely(curr->load.weight != NICE_0_LOAD)) {
-               delta_exec_weighted = calc_delta_fair(delta_exec_weighted,
-                                                       &curr->load);
-       }
+       delta_exec_weighted = calc_delta_fair(delta_exec, curr);
        curr->vruntime += delta_exec_weighted;
 }
 
@@ -510,10 +567,27 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
  * Scheduling class queueing methods:
  */
 
+#if defined CONFIG_SMP && defined CONFIG_FAIR_GROUP_SCHED
+static void
+add_cfs_task_weight(struct cfs_rq *cfs_rq, unsigned long weight)
+{
+       cfs_rq->task_weight += weight;
+}
+#else
+static inline void
+add_cfs_task_weight(struct cfs_rq *cfs_rq, unsigned long weight)
+{
+}
+#endif
+
 static void
 account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
        update_load_add(&cfs_rq->load, se->load.weight);
+       if (!parent_entity(se))
+               inc_cpu_load(rq_of(cfs_rq), se->load.weight);
+       if (entity_is_task(se))
+               add_cfs_task_weight(cfs_rq, se->load.weight);
        cfs_rq->nr_running++;
        se->on_rq = 1;
        list_add(&se->group_node, &cfs_rq->tasks);
@@ -523,6 +597,10 @@ static void
 account_entity_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
        update_load_sub(&cfs_rq->load, se->load.weight);
+       if (!parent_entity(se))
+               dec_cpu_load(rq_of(cfs_rq), se->load.weight);
+       if (entity_is_task(se))
+               add_cfs_task_weight(cfs_rq, -se->load.weight);
        cfs_rq->nr_running--;
        se->on_rq = 0;
        list_del_init(&se->group_node);
@@ -609,8 +687,17 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
 
        if (!initial) {
                /* sleeps upto a single latency don't count. */
-               if (sched_feat(NEW_FAIR_SLEEPERS))
-                       vruntime -= sysctl_sched_latency;
+               if (sched_feat(NEW_FAIR_SLEEPERS)) {
+                       unsigned long thresh = sysctl_sched_latency;
+
+                       /*
+                        * convert the sleeper threshold into virtual time
+                        */
+                       if (sched_feat(NORMALIZED_SLEEPER))
+                               thresh = calc_delta_fair(thresh, se);
+
+                       vruntime -= thresh;
+               }
 
                /* ensure we never gain time by being placed backwards. */
                vruntime = max_vruntime(se->vruntime, vruntime);
@@ -639,21 +726,6 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
                __enqueue_entity(cfs_rq, se);
 }
 
-static void update_avg(u64 *avg, u64 sample)
-{
-       s64 diff = sample - *avg;
-       *avg += diff >> 3;
-}
-
-static void update_avg_stats(struct cfs_rq *cfs_rq, struct sched_entity *se)
-{
-       if (!se->last_wakeup)
-               return;
-
-       update_avg(&se->avg_overlap, se->sum_exec_runtime - se->last_wakeup);
-       se->last_wakeup = 0;
-}
-
 static void
 dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
 {
@@ -664,7 +736,6 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
 
        update_stats_dequeue(cfs_rq, se);
        if (sleep) {
-               update_avg_stats(cfs_rq, se);
 #ifdef CONFIG_SCHEDSTATS
                if (entity_is_task(se)) {
                        struct task_struct *tsk = task_of(se);
@@ -726,17 +797,16 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
        se->prev_sum_exec_runtime = se->sum_exec_runtime;
 }
 
-static int
-wakeup_preempt_entity(struct sched_entity *curr, struct sched_entity *se);
-
 static struct sched_entity *
 pick_next(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
-       if (!cfs_rq->next)
-               return se;
+       struct rq *rq = rq_of(cfs_rq);
+       u64 pair_slice = rq->clock - cfs_rq->pair_start;
 
-       if (wakeup_preempt_entity(cfs_rq->next, se) != 0)
+       if (!cfs_rq->next || pair_slice > sched_slice(cfs_rq, cfs_rq->next)) {
+               cfs_rq->pair_start = rq->clock;
                return se;
+       }
 
        return cfs_rq->next;
 }
@@ -835,7 +905,7 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
                hrtick_start(rq, delta, requeue);
        }
 }
-#else
+#else /* !CONFIG_SCHED_HRTICK */
 static inline void
 hrtick_start_fair(struct rq *rq, struct task_struct *p)
 {
@@ -976,7 +1046,7 @@ static int wake_idle(int cpu, struct task_struct *p)
        }
        return cpu;
 }
-#else
+#else /* !ARCH_HAS_SCHED_WAKE_IDLE*/
 static inline int wake_idle(int cpu, struct task_struct *p)
 {
        return cpu;
@@ -987,6 +1057,89 @@ static inline int wake_idle(int cpu, struct task_struct *p)
 
 static const struct sched_class fair_sched_class;
 
+#ifdef CONFIG_FAIR_GROUP_SCHED
+/*
+ * effective_load() calculates the load change as seen from the root_task_group
+ *
+ * Adding load to a group doesn't make a group heavier, but can cause movement
+ * of group shares between cpus. Assuming the shares were perfectly aligned one
+ * can calculate the shift in shares.
+ *
+ * The problem is that perfectly aligning the shares is rather expensive, hence
+ * we try to avoid doing that too often - see update_shares(), which ratelimits
+ * this change.
+ *
+ * We compensate this by not only taking the current delta into account, but
+ * also considering the delta between when the shares were last adjusted and
+ * now.
+ *
+ * We still saw a performance dip, some tracing learned us that between
+ * cgroup:/ and cgroup:/foo balancing the number of affine wakeups increased
+ * significantly. Therefore try to bias the error in direction of failing
+ * the affine wakeup.
+ *
+ */
+static long effective_load(struct task_group *tg, int cpu,
+               long wl, long wg)
+{
+       struct sched_entity *se = tg->se[cpu];
+       long more_w;
+
+       if (!tg->parent)
+               return wl;
+
+       /*
+        * By not taking the decrease of shares on the other cpu into
+        * account our error leans towards reducing the affine wakeups.
+        */
+       if (!wl && sched_feat(ASYM_EFF_LOAD))
+               return wl;
+
+       /*
+        * Instead of using this increment, also add the difference
+        * between when the shares were last updated and now.
+        */
+       more_w = se->my_q->load.weight - se->my_q->rq_weight;
+       wl += more_w;
+       wg += more_w;
+
+       for_each_sched_entity(se) {
+#define D(n) (likely(n) ? (n) : 1)
+
+               long S, rw, s, a, b;
+
+               S = se->my_q->tg->shares;
+               s = se->my_q->shares;
+               rw = se->my_q->rq_weight;
+
+               a = S*(rw + wl);
+               b = S*rw + s*wg;
+
+               wl = s*(a-b)/D(b);
+               /*
+                * Assume the group is already running and will
+                * thus already be accounted for in the weight.
+                *
+                * That is, moving shares between CPUs, does not
+                * alter the group weight.
+                */
+               wg = 0;
+#undef D
+       }
+
+       return wl;
+}
+
+#else
+
+static inline unsigned long effective_load(struct task_group *tg, int cpu,
+               unsigned long wl, unsigned long wg)
+{
+       return wl;
+}
+
+#endif
+
 static int
 wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq,
            struct task_struct *p, int prev_cpu, int this_cpu, int sync,
@@ -994,8 +1147,10 @@ wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq,
            unsigned int imbalance)
 {
        struct task_struct *curr = this_rq->curr;
+       struct task_group *tg;
        unsigned long tl = this_load;
        unsigned long tl_per_task;
+       unsigned long weight;
        int balanced;
 
        if (!(this_sd->flags & SD_WAKE_AFFINE) || !sched_feat(AFFINE_WAKEUPS))
@@ -1006,19 +1161,28 @@ wake_affine(struct rq *rq, struct sched_domain *this_sd, struct rq *this_rq,
         * effect of the currently running task from the load
         * of the current CPU:
         */
-       if (sync)
-               tl -= current->se.load.weight;
+       if (sync) {
+               tg = task_group(current);
+               weight = current->se.load.weight;
+
+               tl += effective_load(tg, this_cpu, -weight, -weight);
+               load += effective_load(tg, prev_cpu, 0, -weight);
+       }
 
-       balanced = 100*(tl + p->se.load.weight) <= imbalance*load;
+       tg = task_group(p);
+       weight = p->se.load.weight;
+
+       balanced = 100*(tl + effective_load(tg, this_cpu, weight, weight)) <=
+               imbalance*(load + effective_load(tg, prev_cpu, 0, weight));
 
        /*
         * If the currently running task will sleep within
         * a reasonable amount of time then attract this newly
         * woken task:
         */
-       if (sync && balanced && curr->sched_class == &fair_sched_class) {
+       if (sync && balanced) {
                if (curr->se.avg_overlap < sysctl_sched_migration_cost &&
-                               p->se.avg_overlap < sysctl_sched_migration_cost)
+                   p->se.avg_overlap < sysctl_sched_migration_cost)
                        return 1;
        }
 
@@ -1111,11 +1275,13 @@ static unsigned long wakeup_gran(struct sched_entity *se)
        unsigned long gran = sysctl_sched_wakeup_granularity;
 
        /*
-        * More easily preempt - nice tasks, while not making
-        * it harder for + nice tasks.
+        * More easily preempt - nice tasks, while not making it harder for
+        * + nice tasks.
         */
-       if (unlikely(se->load.weight > NICE_0_LOAD))
-               gran = calc_delta_fair(gran, &se->load);
+       if (sched_feat(ASYM_GRAN))
+               gran = calc_delta_asym(sysctl_sched_wakeup_granularity, se);
+       else
+               gran = calc_delta_fair(sysctl_sched_wakeup_granularity, se);
 
        return gran;
 }
@@ -1177,7 +1343,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p)
                return;
        }
 
-       se->last_wakeup = se->sum_exec_runtime;
        if (unlikely(se == pse))
                return;
 
@@ -1275,23 +1440,18 @@ __load_balance_iterator(struct cfs_rq *cfs_rq, struct list_head *next)
        struct task_struct *p = NULL;
        struct sched_entity *se;
 
-       if (next == &cfs_rq->tasks)
-               return NULL;
-
-       /* Skip over entities that are not tasks */
-       do {
+       while (next != &cfs_rq->tasks) {
                se = list_entry(next, struct sched_entity, group_node);
                next = next->next;
-       } while (next != &cfs_rq->tasks && !entity_is_task(se));
 
-       if (next == &cfs_rq->tasks)
-               return NULL;
+               /* Skip over entities that are not tasks */
+               if (entity_is_task(se)) {
+                       p = task_of(se);
+                       break;
+               }
+       }
 
        cfs_rq->balance_iterator = next;
-
-       if (entity_is_task(se))
-               p = task_of(se);
-
        return p;
 }
 
@@ -1309,75 +1469,82 @@ static struct task_struct *load_balance_next_fair(void *arg)
        return __load_balance_iterator(cfs_rq, cfs_rq->balance_iterator);
 }
 
-#ifdef CONFIG_FAIR_GROUP_SCHED
-static int cfs_rq_best_prio(struct cfs_rq *cfs_rq)
+static unsigned long
+__load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
+               unsigned long max_load_move, struct sched_domain *sd,
+               enum cpu_idle_type idle, int *all_pinned, int *this_best_prio,
+               struct cfs_rq *cfs_rq)
 {
-       struct sched_entity *curr;
-       struct task_struct *p;
-
-       if (!cfs_rq->nr_running || !first_fair(cfs_rq))
-               return MAX_PRIO;
-
-       curr = cfs_rq->curr;
-       if (!curr)
-               curr = __pick_next_entity(cfs_rq);
+       struct rq_iterator cfs_rq_iterator;
 
-       p = task_of(curr);
+       cfs_rq_iterator.start = load_balance_start_fair;
+       cfs_rq_iterator.next = load_balance_next_fair;
+       cfs_rq_iterator.arg = cfs_rq;
 
-       return p->prio;
+       return balance_tasks(this_rq, this_cpu, busiest,
+                       max_load_move, sd, idle, all_pinned,
+                       this_best_prio, &cfs_rq_iterator);
 }
-#endif
 
+#ifdef CONFIG_FAIR_GROUP_SCHED
 static unsigned long
 load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
                  unsigned long max_load_move,
                  struct sched_domain *sd, enum cpu_idle_type idle,
                  int *all_pinned, int *this_best_prio)
 {
-       struct cfs_rq *busy_cfs_rq;
        long rem_load_move = max_load_move;
-       struct rq_iterator cfs_rq_iterator;
-
-       cfs_rq_iterator.start = load_balance_start_fair;
-       cfs_rq_iterator.next = load_balance_next_fair;
+       int busiest_cpu = cpu_of(busiest);
+       struct task_group *tg;
 
-       for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
-#ifdef CONFIG_FAIR_GROUP_SCHED
-               struct cfs_rq *this_cfs_rq;
-               long imbalance;
-               unsigned long maxload;
+       rcu_read_lock();
+       update_h_load(busiest_cpu);
 
-               this_cfs_rq = cpu_cfs_rq(busy_cfs_rq, this_cpu);
+       list_for_each_entry(tg, &task_groups, list) {
+               struct cfs_rq *busiest_cfs_rq = tg->cfs_rq[busiest_cpu];
+               unsigned long busiest_h_load = busiest_cfs_rq->h_load;
+               unsigned long busiest_weight = busiest_cfs_rq->load.weight;
+               u64 rem_load, moved_load;
 
-               imbalance = busy_cfs_rq->load.weight - this_cfs_rq->load.weight;
-               /* Don't pull if this_cfs_rq has more load than busy_cfs_rq */
-               if (imbalance <= 0)
+               /*
+                * empty group
+                */
+               if (!busiest_cfs_rq->task_weight)
                        continue;
 
-               /* Don't pull more than imbalance/2 */
-               imbalance /= 2;
-               maxload = min(rem_load_move, imbalance);
+               rem_load = (u64)rem_load_move * busiest_weight;
+               rem_load = div_u64(rem_load, busiest_h_load + 1);
 
-               *this_best_prio = cfs_rq_best_prio(this_cfs_rq);
-#else
-# define maxload rem_load_move
-#endif
-               /*
-                * pass busy_cfs_rq argument into
-                * load_balance_[start|next]_fair iterators
-                */
-               cfs_rq_iterator.arg = busy_cfs_rq;
-               rem_load_move -= balance_tasks(this_rq, this_cpu, busiest,
-                                              maxload, sd, idle, all_pinned,
-                                              this_best_prio,
-                                              &cfs_rq_iterator);
+               moved_load = __load_balance_fair(this_rq, this_cpu, busiest,
+                               rem_load, sd, idle, all_pinned, this_best_prio,
+                               tg->cfs_rq[busiest_cpu]);
+
+               if (!moved_load)
+                       continue;
+
+               moved_load *= busiest_h_load;
+               moved_load = div_u64(moved_load, busiest_weight + 1);
 
-               if (rem_load_move <= 0)
+               rem_load_move -= moved_load;
+               if (rem_load_move < 0)
                        break;
        }
+       rcu_read_unlock();
 
        return max_load_move - rem_load_move;
 }
+#else
+static unsigned long
+load_balance_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
+                 unsigned long max_load_move,
+                 struct sched_domain *sd, enum cpu_idle_type idle,
+                 int *all_pinned, int *this_best_prio)
+{
+       return __load_balance_fair(this_rq, this_cpu, busiest,
+                       max_load_move, sd, idle, all_pinned,
+                       this_best_prio, &busiest->cfs);
+}
+#endif
 
 static int
 move_one_task_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
@@ -1402,7 +1569,7 @@ move_one_task_fair(struct rq *this_rq, int this_cpu, struct rq *busiest,
 
        return 0;
 }
-#endif
+#endif /* CONFIG_SMP */
 
 /*
  * scheduler tick hitting a task of our scheduling class:
index 1c7283c..862b06b 100644 (file)
@@ -1,4 +1,5 @@
 SCHED_FEAT(NEW_FAIR_SLEEPERS, 1)
+SCHED_FEAT(NORMALIZED_SLEEPER, 1)
 SCHED_FEAT(WAKEUP_PREEMPT, 1)
 SCHED_FEAT(START_DEBIT, 1)
 SCHED_FEAT(AFFINE_WAKEUPS, 1)
@@ -6,5 +7,7 @@ SCHED_FEAT(CACHE_HOT_BUDDY, 1)
 SCHED_FEAT(SYNC_WAKEUPS, 1)
 SCHED_FEAT(HRTICK, 1)
 SCHED_FEAT(DOUBLE_TICK, 0)
-SCHED_FEAT(NORMALIZED_SLEEPER, 1)
-SCHED_FEAT(DEADLINE, 1)
+SCHED_FEAT(ASYM_GRAN, 1)
+SCHED_FEAT(LB_BIAS, 0)
+SCHED_FEAT(LB_WAKEUP_UPDATE, 1)
+SCHED_FEAT(ASYM_EFF_LOAD, 1)
index 0f3c191..47ceac9 100644 (file)
@@ -12,6 +12,9 @@ static inline int rt_overloaded(struct rq *rq)
 
 static inline void rt_set_overload(struct rq *rq)
 {
+       if (!rq->online)
+               return;
+
        cpu_set(rq->cpu, rq->rd->rto_mask);
        /*
         * Make sure the mask is visible before we set
@@ -26,6 +29,9 @@ static inline void rt_set_overload(struct rq *rq)
 
 static inline void rt_clear_overload(struct rq *rq)
 {
+       if (!rq->online)
+               return;
+
        /* the order here really doesn't matter */
        atomic_dec(&rq->rd->rto_count);
        cpu_clear(rq->cpu, rq->rd->rto_mask);
@@ -155,7 +161,7 @@ static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
        return &rt_rq->tg->rt_bandwidth;
 }
 
-#else
+#else /* !CONFIG_RT_GROUP_SCHED */
 
 static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
 {
@@ -220,49 +226,10 @@ static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
        return &def_rt_bandwidth;
 }
 
-#endif
-
-static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
-{
-       int i, idle = 1;
-       cpumask_t span;
-
-       if (rt_b->rt_runtime == RUNTIME_INF)
-               return 1;
-
-       span = sched_rt_period_mask();
-       for_each_cpu_mask(i, span) {
-               int enqueue = 0;
-               struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
-               struct rq *rq = rq_of_rt_rq(rt_rq);
-
-               spin_lock(&rq->lock);
-               if (rt_rq->rt_time) {
-                       u64 runtime;
-
-                       spin_lock(&rt_rq->rt_runtime_lock);
-                       runtime = rt_rq->rt_runtime;
-                       rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
-                       if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
-                               rt_rq->rt_throttled = 0;
-                               enqueue = 1;
-                       }
-                       if (rt_rq->rt_time || rt_rq->rt_nr_running)
-                               idle = 0;
-                       spin_unlock(&rt_rq->rt_runtime_lock);
-               } else if (rt_rq->rt_nr_running)
-                       idle = 0;
-
-               if (enqueue)
-                       sched_rt_rq_enqueue(rt_rq);
-               spin_unlock(&rq->lock);
-       }
-
-       return idle;
-}
+#endif /* CONFIG_RT_GROUP_SCHED */
 
 #ifdef CONFIG_SMP
-static int balance_runtime(struct rt_rq *rt_rq)
+static int do_balance_runtime(struct rt_rq *rt_rq)
 {
        struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
        struct root_domain *rd = cpu_rq(smp_processor_id())->rd;
@@ -281,6 +248,9 @@ static int balance_runtime(struct rt_rq *rt_rq)
                        continue;
 
                spin_lock(&iter->rt_runtime_lock);
+               if (iter->rt_runtime == RUNTIME_INF)
+                       goto next;
+
                diff = iter->rt_runtime - iter->rt_time;
                if (diff > 0) {
                        do_div(diff, weight);
@@ -294,13 +264,163 @@ static int balance_runtime(struct rt_rq *rt_rq)
                                break;
                        }
                }
+next:
                spin_unlock(&iter->rt_runtime_lock);
        }
        spin_unlock(&rt_b->rt_runtime_lock);
 
        return more;
 }
-#endif
+
+static void __disable_runtime(struct rq *rq)
+{
+       struct root_domain *rd = rq->rd;
+       struct rt_rq *rt_rq;
+
+       if (unlikely(!scheduler_running))
+               return;
+
+       for_each_leaf_rt_rq(rt_rq, rq) {
+               struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
+               s64 want;
+               int i;
+
+               spin_lock(&rt_b->rt_runtime_lock);
+               spin_lock(&rt_rq->rt_runtime_lock);
+               if (rt_rq->rt_runtime == RUNTIME_INF ||
+                               rt_rq->rt_runtime == rt_b->rt_runtime)
+                       goto balanced;
+               spin_unlock(&rt_rq->rt_runtime_lock);
+
+               want = rt_b->rt_runtime - rt_rq->rt_runtime;
+
+               for_each_cpu_mask(i, rd->span) {
+                       struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
+                       s64 diff;
+
+                       if (iter == rt_rq)
+                               continue;
+
+                       spin_lock(&iter->rt_runtime_lock);
+                       if (want > 0) {
+                               diff = min_t(s64, iter->rt_runtime, want);
+                               iter->rt_runtime -= diff;
+                               want -= diff;
+                       } else {
+                               iter->rt_runtime -= want;
+                               want -= want;
+                       }
+                       spin_unlock(&iter->rt_runtime_lock);
+
+                       if (!want)
+                               break;
+               }
+
+               spin_lock(&rt_rq->rt_runtime_lock);
+               BUG_ON(want);
+balanced:
+               rt_rq->rt_runtime = RUNTIME_INF;
+               spin_unlock(&rt_rq->rt_runtime_lock);
+               spin_unlock(&rt_b->rt_runtime_lock);
+       }
+}
+
+static void disable_runtime(struct rq *rq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&rq->lock, flags);
+       __disable_runtime(rq);
+       spin_unlock_irqrestore(&rq->lock, flags);
+}
+
+static void __enable_runtime(struct rq *rq)
+{
+       struct rt_rq *rt_rq;
+
+       if (unlikely(!scheduler_running))
+               return;
+
+       for_each_leaf_rt_rq(rt_rq, rq) {
+               struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
+
+               spin_lock(&rt_b->rt_runtime_lock);
+               spin_lock(&rt_rq->rt_runtime_lock);
+               rt_rq->rt_runtime = rt_b->rt_runtime;
+               rt_rq->rt_time = 0;
+               spin_unlock(&rt_rq->rt_runtime_lock);
+               spin_unlock(&rt_b->rt_runtime_lock);
+       }
+}
+
+static void enable_runtime(struct rq *rq)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&rq->lock, flags);
+       __enable_runtime(rq);
+       spin_unlock_irqrestore(&rq->lock, flags);
+}
+
+static int balance_runtime(struct rt_rq *rt_rq)
+{
+       int more = 0;
+
+       if (rt_rq->rt_time > rt_rq->rt_runtime) {
+               spin_unlock(&rt_rq->rt_runtime_lock);
+               more = do_balance_runtime(rt_rq);
+               spin_lock(&rt_rq->rt_runtime_lock);
+       }
+
+       return more;
+}
+#else /* !CONFIG_SMP */
+static inline int balance_runtime(struct rt_rq *rt_rq)
+{
+       return 0;
+}
+#endif /* CONFIG_SMP */
+
+static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
+{
+       int i, idle = 1;
+       cpumask_t span;
+
+       if (rt_b->rt_runtime == RUNTIME_INF)
+               return 1;
+
+       span = sched_rt_period_mask();
+       for_each_cpu_mask(i, span) {
+               int enqueue = 0;
+               struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
+               struct rq *rq = rq_of_rt_rq(rt_rq);
+
+               spin_lock(&rq->lock);
+               if (rt_rq->rt_time) {
+                       u64 runtime;
+
+                       spin_lock(&rt_rq->rt_runtime_lock);
+                       if (rt_rq->rt_throttled)
+                               balance_runtime(rt_rq);
+                       runtime = rt_rq->rt_runtime;
+                       rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
+                       if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
+                               rt_rq->rt_throttled = 0;
+                               enqueue = 1;
+                       }
+                       if (rt_rq->rt_time || rt_rq->rt_nr_running)
+                               idle = 0;
+                       spin_unlock(&rt_rq->rt_runtime_lock);
+               } else if (rt_rq->rt_nr_running)
+                       idle = 0;
+
+               if (enqueue)
+                       sched_rt_rq_enqueue(rt_rq);
+               spin_unlock(&rq->lock);
+       }
+
+       return idle;
+}
 
 static inline int rt_se_prio(struct sched_rt_entity *rt_se)
 {
@@ -327,18 +447,10 @@ static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
        if (sched_rt_runtime(rt_rq) >= sched_rt_period(rt_rq))
                return 0;
 
-#ifdef CONFIG_SMP
-       if (rt_rq->rt_time > runtime) {
-               int more;
-
-               spin_unlock(&rt_rq->rt_runtime_lock);
-               more = balance_runtime(rt_rq);
-               spin_lock(&rt_rq->rt_runtime_lock);
-
-               if (more)
-                       runtime = sched_rt_runtime(rt_rq);
-       }
-#endif
+       balance_runtime(rt_rq);
+       runtime = sched_rt_runtime(rt_rq);
+       if (runtime == RUNTIME_INF)
+               return 0;
 
        if (rt_rq->rt_time > runtime) {
                rt_rq->rt_throttled = 1;
@@ -392,12 +504,21 @@ void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
        WARN_ON(!rt_prio(rt_se_prio(rt_se)));
        rt_rq->rt_nr_running++;
 #if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
-       if (rt_se_prio(rt_se) < rt_rq->highest_prio)
+       if (rt_se_prio(rt_se) < rt_rq->highest_prio) {
+               struct rq *rq = rq_of_rt_rq(rt_rq);
+
                rt_rq->highest_prio = rt_se_prio(rt_se);
+#ifdef CONFIG_SMP
+               if (rq->online)
+                       cpupri_set(&rq->rd->cpupri, rq->cpu,
+                                  rt_se_prio(rt_se));
+#endif
+       }
 #endif
 #ifdef CONFIG_SMP
        if (rt_se->nr_cpus_allowed > 1) {
                struct rq *rq = rq_of_rt_rq(rt_rq);
+
                rq->rt.rt_nr_migratory++;
        }
 
@@ -417,6 +538,10 @@ void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
 static inline
 void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
 {
+#ifdef CONFIG_SMP
+       int highest_prio = rt_rq->highest_prio;
+#endif
+
        WARN_ON(!rt_prio(rt_se_prio(rt_se)));
        WARN_ON(!rt_rq->rt_nr_running);
        rt_rq->rt_nr_running--;
@@ -440,6 +565,14 @@ void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
                rq->rt.rt_nr_migratory--;
        }
 
+       if (rt_rq->highest_prio != highest_prio) {
+               struct rq *rq = rq_of_rt_rq(rt_rq);
+
+               if (rq->online)
+                       cpupri_set(&rq->rd->cpupri, rq->cpu,
+                                  rt_rq->highest_prio);
+       }
+
        update_rt_migration(rq_of_rt_rq(rt_rq));
 #endif /* CONFIG_SMP */
 #ifdef CONFIG_RT_GROUP_SCHED
@@ -455,6 +588,7 @@ static void __enqueue_rt_entity(struct sched_rt_entity *rt_se)
        struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
        struct rt_prio_array *array = &rt_rq->active;
        struct rt_rq *group_rq = group_rt_rq(rt_se);
+       struct list_head *queue = array->queue + rt_se_prio(rt_se);
 
        /*
         * Don't enqueue the group if its throttled, or when empty.
@@ -465,7 +599,11 @@ static void __enqueue_rt_entity(struct sched_rt_entity *rt_se)
        if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running))
                return;
 
-       list_add_tail(&rt_se->run_list, array->queue + rt_se_prio(rt_se));
+       if (rt_se->nr_cpus_allowed == 1)
+               list_add(&rt_se->run_list, queue);
+       else
+               list_add_tail(&rt_se->run_list, queue);
+
        __set_bit(rt_se_prio(rt_se), array->bitmap);
 
        inc_rt_tasks(rt_se, rt_rq);
@@ -532,6 +670,8 @@ static void enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup)
                rt_se->timeout = 0;
 
        enqueue_rt_entity(rt_se);
+
+       inc_cpu_load(rq, p->se.load.weight);
 }
 
 static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep)
@@ -540,6 +680,8 @@ static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep)
 
        update_curr_rt(rq);
        dequeue_rt_entity(rt_se);
+
+       dec_cpu_load(rq, p->se.load.weight);
 }
 
 /*
@@ -550,10 +692,12 @@ static
 void requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se)
 {
        struct rt_prio_array *array = &rt_rq->active;
-       struct list_head *queue = array->queue + rt_se_prio(rt_se);
 
-       if (on_rt_rq(rt_se))
-               list_move_tail(&rt_se->run_list, queue);
+       if (on_rt_rq(rt_se)) {
+               list_del_init(&rt_se->run_list);
+               list_add_tail(&rt_se->run_list,
+                             array->queue + rt_se_prio(rt_se));
+       }
 }
 
 static void requeue_task_rt(struct rq *rq, struct task_struct *p)
@@ -616,8 +760,37 @@ static int select_task_rq_rt(struct task_struct *p, int sync)
  */
 static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p)
 {
-       if (p->prio < rq->curr->prio)
+       if (p->prio < rq->curr->prio) {
                resched_task(rq->curr);
+               return;
+       }
+
+#ifdef CONFIG_SMP
+       /*
+        * If:
+        *
+        * - the newly woken task is of equal priority to the current task
+        * - the newly woken task is non-migratable while current is migratable
+        * - current will be preempted on the next reschedule
+        *
+        * we should check to see if current can readily move to a different
+        * cpu.  If so, we will reschedule to allow the push logic to try
+        * to move current somewhere else, making room for our non-migratable
+        * task.
+        */
+       if((p->prio == rq->curr->prio)
+          && p->rt.nr_cpus_allowed == 1
+          && rq->curr->rt.nr_cpus_allowed != 1) {
+               cpumask_t mask;
+
+               if (cpupri_find(&rq->rd->cpupri, rq->curr, &mask))
+                       /*
+                        * There appears to be other cpus that can accept
+                        * current, so lets reschedule to try and push it away
+                        */
+                       resched_task(rq->curr);
+       }
+#endif
 }
 
 static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq,
@@ -720,73 +893,6 @@ static struct task_struct *pick_next_highest_task_rt(struct rq *rq, int cpu)
 
 static DEFINE_PER_CPU(cpumask_t, local_cpu_mask);
 
-static int find_lowest_cpus(struct task_struct *task, cpumask_t *lowest_mask)
-{
-       int       lowest_prio = -1;
-       int       lowest_cpu  = -1;
-       int       count       = 0;
-       int       cpu;
-
-       cpus_and(*lowest_mask, task_rq(task)->rd->online, task->cpus_allowed);
-
-       /*
-        * Scan each rq for the lowest prio.
-        */
-       for_each_cpu_mask(cpu, *lowest_mask) {
-               struct rq *rq = cpu_rq(cpu);
-
-               /* We look for lowest RT prio or non-rt CPU */
-               if (rq->rt.highest_prio >= MAX_RT_PRIO) {
-                       /*
-                        * if we already found a low RT queue
-                        * and now we found this non-rt queue
-                        * clear the mask and set our bit.
-                        * Otherwise just return the queue as is
-                        * and the count==1 will cause the algorithm
-                        * to use the first bit found.
-                        */
-                       if (lowest_cpu != -1) {
-                               cpus_clear(*lowest_mask);
-                               cpu_set(rq->cpu, *lowest_mask);
-                       }
-                       return 1;
-               }
-
-               /* no locking for now */
-               if ((rq->rt.highest_prio > task->prio)
-                   && (rq->rt.highest_prio >= lowest_prio)) {
-                       if (rq->rt.highest_prio > lowest_prio) {
-                               /* new low - clear old data */
-                               lowest_prio = rq->rt.highest_prio;
-                               lowest_cpu = cpu;
-                               count = 0;
-                       }
-                       count++;
-               } else
-                       cpu_clear(cpu, *lowest_mask);
-       }
-
-       /*
-        * Clear out all the set bits that represent
-        * runqueues that were of higher prio than
-        * the lowest_prio.
-        */
-       if (lowest_cpu > 0) {
-               /*
-                * Perhaps we could add another cpumask op to
-                * zero out bits. Like cpu_zero_bits(cpumask, nrbits);
-                * Then that could be optimized to use memset and such.
-                */
-               for_each_cpu_mask(cpu, *lowest_mask) {
-                       if (cpu >= lowest_cpu)
-                               break;
-                       cpu_clear(cpu, *lowest_mask);
-               }
-       }
-
-       return count;
-}
-
 static inline int pick_optimal_cpu(int this_cpu, cpumask_t *mask)
 {
        int first;
@@ -808,17 +914,12 @@ static int find_lowest_rq(struct task_struct *task)
        cpumask_t *lowest_mask = &__get_cpu_var(local_cpu_mask);
        int this_cpu = smp_processor_id();
        int cpu      = task_cpu(task);
-       int count    = find_lowest_cpus(task, lowest_mask);
 
-       if (!count)
-               return -1; /* No targets found */
+       if (task->rt.nr_cpus_allowed == 1)
+               return -1; /* No other targets possible */
 
-       /*
-        * There is no sense in performing an optimal search if only one
-        * target is found.
-        */
-       if (count == 1)
-               return first_cpu(*lowest_mask);
+       if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
+               return -1; /* No targets found */
 
        /*
         * At this point we have built a mask of cpus representing the
@@ -1163,17 +1264,25 @@ static void set_cpus_allowed_rt(struct task_struct *p,
 }
 
 /* Assumes rq->lock is held */
-static void join_domain_rt(struct rq *rq)
+static void rq_online_rt(struct rq *rq)
 {
        if (rq->rt.overloaded)
                rt_set_overload(rq);
+
+       __enable_runtime(rq);
+
+       cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio);
 }
 
 /* Assumes rq->lock is held */
-static void leave_domain_rt(struct rq *rq)
+static void rq_offline_rt(struct rq *rq)
 {
        if (rq->rt.overloaded)
                rt_clear_overload(rq);
+
+       __disable_runtime(rq);
+
+       cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
 }
 
 /*
@@ -1336,8 +1445,8 @@ static const struct sched_class rt_sched_class = {
        .load_balance           = load_balance_rt,
        .move_one_task          = move_one_task_rt,
        .set_cpus_allowed       = set_cpus_allowed_rt,
-       .join_domain            = join_domain_rt,
-       .leave_domain           = leave_domain_rt,
+       .rq_online              = rq_online_rt,
+       .rq_offline             = rq_offline_rt,
        .pre_schedule           = pre_schedule_rt,
        .post_schedule          = post_schedule_rt,
        .task_wake_up           = task_wake_up_rt,
@@ -1350,3 +1459,17 @@ static const struct sched_class rt_sched_class = {
        .prio_changed           = prio_changed_rt,
        .switched_to            = switched_to_rt,
 };
+
+#ifdef CONFIG_SCHED_DEBUG
+extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
+
+static void print_rt_stats(struct seq_file *m, int cpu)
+{
+       struct rt_rq *rt_rq;
+
+       rcu_read_lock();
+       for_each_leaf_rt_rq(rt_rq, cpu_rq(cpu))
+               print_rt_rq(m, cpu, rt_rq);
+       rcu_read_unlock();
+}
+#endif /* CONFIG_SCHED_DEBUG */
index 80179ef..8385d43 100644 (file)
@@ -118,6 +118,13 @@ rq_sched_info_depart(struct rq *rq, unsigned long long delta)
        if (rq)
                rq->rq_sched_info.cpu_time += delta;
 }
+
+static inline void
+rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
+{
+       if (rq)
+               rq->rq_sched_info.run_delay += delta;
+}
 # define schedstat_inc(rq, field)      do { (rq)->field++; } while (0)
 # define schedstat_add(rq, field, amt) do { (rq)->field += (amt); } while (0)
 # define schedstat_set(var, val)       do { var = (val); } while (0)
@@ -126,6 +133,9 @@ static inline void
 rq_sched_info_arrive(struct rq *rq, unsigned long long delta)
 {}
 static inline void
+rq_sched_info_dequeued(struct rq *rq, unsigned long long delta)
+{}
+static inline void
 rq_sched_info_depart(struct rq *rq, unsigned long long delta)
 {}
 # define schedstat_inc(rq, field)      do { } while (0)
@@ -134,6 +144,11 @@ rq_sched_info_depart(struct rq *rq, unsigned long long delta)
 #endif
 
 #if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
+static inline void sched_info_reset_dequeued(struct task_struct *t)
+{
+       t->sched_info.last_queued = 0;
+}
+
 /*
  * Called when a process is dequeued from the active array and given
  * the cpu.  We should note that with the exception of interactive
@@ -143,15 +158,22 @@ rq_sched_info_depart(struct rq *rq, unsigned long long delta)
  * active queue, thus delaying tasks in the expired queue from running;
  * see scheduler_tick()).
  *
- * This function is only called from sched_info_arrive(), rather than
- * dequeue_task(). Even though a task may be queued and dequeued multiple
- * times as it is shuffled about, we're really interested in knowing how
- * long it was from the *first* time it was queued to the time that it
- * finally hit a cpu.
+ * Though we are interested in knowing how long it was from the *first* time a
+ * task was queued to the time that it finally hit a cpu, we call this routine
+ * from dequeue_task() to account for possible rq->clock skew across cpus. The
+ * delta taken on each cpu would annul the skew.
  */
 static inline void sched_info_dequeued(struct task_struct *t)
 {
-       t->sched_info.last_queued = 0;
+       unsigned long long now = task_rq(t)->clock, delta = 0;
+
+       if (unlikely(sched_info_on()))
+               if (t->sched_info.last_queued)
+                       delta = now - t->sched_info.last_queued;
+       sched_info_reset_dequeued(t);
+       t->sched_info.run_delay += delta;
+
+       rq_sched_info_dequeued(task_rq(t), delta);
 }
 
 /*
@@ -165,7 +187,7 @@ static void sched_info_arrive(struct task_struct *t)
 
        if (t->sched_info.last_queued)
                delta = now - t->sched_info.last_queued;
-       sched_info_dequeued(t);
+       sched_info_reset_dequeued(t);
        t->sched_info.run_delay += delta;
        t->sched_info.last_arrival = now;
        t->sched_info.pcount++;
@@ -242,7 +264,9 @@ sched_info_switch(struct task_struct *prev, struct task_struct *next)
                __sched_info_switch(prev, next);
 }
 #else
-#define sched_info_queued(t)           do { } while (0)
-#define sched_info_switch(t, next)     do { } while (0)
+#define sched_info_queued(t)                   do { } while (0)
+#define sched_info_reset_dequeued(t)   do { } while (0)
+#define sched_info_dequeued(t)                 do { } while (0)
+#define sched_info_switch(t, next)             do { } while (0)
 #endif /* CONFIG_SCHEDSTATS || CONFIG_TASK_DELAY_ACCT */
 
index 5c2942e..aaaeae8 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/sched.h>
 #include <linux/semaphore.h>
 #include <linux/spinlock.h>
+#include <linux/ftrace.h>
 
 static noinline void __down(struct semaphore *sem);
 static noinline int __down_interruptible(struct semaphore *sem);
index 36e0617..3e9e896 100644 (file)
@@ -131,23 +131,17 @@ void _local_bh_enable(void)
 
 EXPORT_SYMBOL(_local_bh_enable);
 
-void local_bh_enable(void)
+static inline void _local_bh_enable_ip(unsigned long ip)
 {
+       WARN_ON_ONCE(in_irq() || irqs_disabled());
 #ifdef CONFIG_TRACE_IRQFLAGS
-       unsigned long flags;
-
-       WARN_ON_ONCE(in_irq());
-#endif
-       WARN_ON_ONCE(irqs_disabled());
-
-#ifdef CONFIG_TRACE_IRQFLAGS
-       local_irq_save(flags);
+       local_irq_disable();
 #endif
        /*
         * Are softirqs going to be turned on now:
         */
        if (softirq_count() == SOFTIRQ_OFFSET)
-               trace_softirqs_on((unsigned long)__builtin_return_address(0));
+               trace_softirqs_on(ip);
        /*
         * Keep preemption disabled until we are done with
         * softirq processing:
@@ -159,40 +153,20 @@ void local_bh_enable(void)
 
        dec_preempt_count();
 #ifdef CONFIG_TRACE_IRQFLAGS
-       local_irq_restore(flags);
+       local_irq_enable();
 #endif
        preempt_check_resched();
 }
+
+void local_bh_enable(void)
+{
+       _local_bh_enable_ip((unsigned long)__builtin_return_address(0));
+}
 EXPORT_SYMBOL(local_bh_enable);
 
 void local_bh_enable_ip(unsigned long ip)
 {
-#ifdef CONFIG_TRACE_IRQFLAGS
-       unsigned long flags;
-
-       WARN_ON_ONCE(in_irq());
-
-       local_irq_save(flags);
-#endif
-       /*
-        * Are softirqs going to be turned on now:
-        */
-       if (softirq_count() == SOFTIRQ_OFFSET)
-               trace_softirqs_on(ip);
-       /*
-        * Keep preemption disabled until we are done with
-        * softirq processing:
-        */
-       sub_preempt_count(SOFTIRQ_OFFSET - 1);
-
-       if (unlikely(!in_interrupt() && local_softirq_pending()))
-               do_softirq();
-
-       dec_preempt_count();
-#ifdef CONFIG_TRACE_IRQFLAGS
-       local_irq_restore(flags);
-#endif
-       preempt_check_resched();
+       _local_bh_enable_ip(ip);
 }
 EXPORT_SYMBOL(local_bh_enable_ip);
 
@@ -347,9 +321,8 @@ void raise_softirq(unsigned int nr)
        local_irq_restore(flags);
 }
 
-void open_softirq(int nr, void (*action)(struct softirq_action*), void *data)
+void open_softirq(int nr, void (*action)(struct softirq_action *))
 {
-       softirq_vec[nr].data = data;
        softirq_vec[nr].action = action;
 }
 
@@ -360,10 +333,8 @@ struct tasklet_head
        struct tasklet_struct **tail;
 };
 
-/* Some compilers disobey section attribute on statics when not
-   initialized -- RR */
-static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec) = { NULL };
-static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec) = { NULL };
+static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
+static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
 
 void __tasklet_schedule(struct tasklet_struct *t)
 {
@@ -503,8 +474,8 @@ void __init softirq_init(void)
                        &per_cpu(tasklet_hi_vec, cpu).head;
        }
 
-       open_softirq(TASKLET_SOFTIRQ, tasklet_action, NULL);
-       open_softirq(HI_SOFTIRQ, tasklet_hi_action, NULL);
+       open_softirq(TASKLET_SOFTIRQ, tasklet_action);
+       open_softirq(HI_SOFTIRQ, tasklet_hi_action);
 }
 
 static int ksoftirqd(void * __bind_cpu)
@@ -645,7 +616,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
 
                p = per_cpu(ksoftirqd, hotcpu);
                per_cpu(ksoftirqd, hotcpu) = NULL;
-               sched_setscheduler(p, SCHED_FIFO, &param);
+               sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
                kthread_stop(p);
                takeover_tasklets(hotcpu);
                break;
index ae28c82..a1fb54c 100644 (file)
@@ -436,7 +436,7 @@ int __lockfunc _spin_trylock_bh(spinlock_t *lock)
 }
 EXPORT_SYMBOL(_spin_trylock_bh);
 
-int in_lock_functions(unsigned long addr)
+notrace int in_lock_functions(unsigned long addr)
 {
        /* Linker adds these: start and end of __lockfunc functions */
        extern char __lock_text_start[], __lock_text_end[];
index b7350bb..ba9b205 100644 (file)
@@ -187,7 +187,7 @@ struct task_struct *__stop_machine_run(int (*fn)(void *), void *data,
                struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 
                /* One high-prio thread per cpu.  We'll do this one. */
-               sched_setscheduler(p, SCHED_FIFO, &param);
+               sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
                kthread_bind(p, cpu);
                wake_up_process(p);
                wait_for_completion(&smdata.done);
index 2911665..0d562d6 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/nfs_fs.h>
 #include <linux/acpi.h>
 #include <linux/reboot.h>
+#include <linux/ftrace.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -132,8 +133,6 @@ extern int sysctl_userprocess_debug;
 extern int spin_retry;
 #endif
 
-extern int sysctl_hz_timer;
-
 #ifdef CONFIG_BSD_PROCESS_ACCT
 extern int acct_parm[];
 #endif
@@ -264,6 +263,14 @@ static struct ctl_table kern_table[] = {
                .extra1         = &min_wakeup_granularity_ns,
                .extra2         = &max_wakeup_granularity_ns,
        },
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "sched_shares_ratelimit",
+               .data           = &sysctl_sched_shares_ratelimit,
+               .maxlen         = sizeof(unsigned int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec,
+       },
        {
                .ctl_name       = CTL_UNNUMBERED,
                .procname       = "sched_child_runs_first",
@@ -455,6 +462,16 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
+#ifdef CONFIG_FTRACE
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "ftrace_enabled",
+               .data           = &ftrace_enabled,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = &ftrace_enable_sysctl,
+       },
+#endif
 #ifdef CONFIG_KMOD
        {
                .ctl_name       = KERN_MODPROBE,
@@ -562,16 +579,6 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
-#endif
-#ifdef CONFIG_NO_IDLE_HZ
-       {
-               .ctl_name       = KERN_HZ_TIMER,
-               .procname       = "hz_timer",
-               .data           = &sysctl_hz_timer,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
-       },
 #endif
        {
                .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
index 57a1f02..67f80c2 100644 (file)
@@ -30,6 +30,7 @@
 struct tick_device tick_broadcast_device;
 static cpumask_t tick_broadcast_mask;
 static DEFINE_SPINLOCK(tick_broadcast_lock);
+static int tick_broadcast_force;
 
 #ifdef CONFIG_TICK_ONESHOT
 static void tick_broadcast_clear_oneshot(int cpu);
@@ -232,10 +233,11 @@ static void tick_do_broadcast_on_off(void *why)
                                                     CLOCK_EVT_MODE_SHUTDOWN);
                }
                if (*reason == CLOCK_EVT_NOTIFY_BROADCAST_FORCE)
-                       dev->features |= CLOCK_EVT_FEAT_DUMMY;
+                       tick_broadcast_force = 1;
                break;
        case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
-               if (cpu_isset(cpu, tick_broadcast_mask)) {
+               if (!tick_broadcast_force &&
+                   cpu_isset(cpu, tick_broadcast_mask)) {
                        cpu_clear(cpu, tick_broadcast_mask);
                        if (td->mode == TICKDEV_MODE_PERIODIC)
                                tick_setup_periodic(dev, 0);
index b854a89..d63008b 100644 (file)
@@ -276,6 +276,7 @@ void tick_nohz_stop_sched_tick(void)
                        ts->tick_stopped = 1;
                        ts->idle_jiffies = last_jiffies;
                        rcu_enter_nohz();
+                       sched_clock_tick_stop(cpu);
                }
 
                /*
@@ -375,6 +376,7 @@ void tick_nohz_restart_sched_tick(void)
        select_nohz_load_balancer(0);
        now = ktime_get();
        tick_do_update_jiffies64(now);
+       sched_clock_tick_start(cpu);
        cpu_clear(cpu, nohz_cpu_mask);
 
        /*
index ceacc66..03bc7f1 100644 (file)
@@ -812,7 +812,7 @@ static inline void __run_timers(struct tvec_base *base)
        spin_unlock_irq(&base->lock);
 }
 
-#if defined(CONFIG_NO_IDLE_HZ) || defined(CONFIG_NO_HZ)
+#ifdef CONFIG_NO_HZ
 /*
  * Find out when the next timer event is due to happen. This
  * is used on S/390 to stop all activity when a cpus is idle.
@@ -947,14 +947,6 @@ unsigned long get_next_timer_interrupt(unsigned long now)
 
        return cmp_next_hrtimer_event(now, expires);
 }
-
-#ifdef CONFIG_NO_IDLE_HZ
-unsigned long next_timer_interrupt(void)
-{
-       return get_next_timer_interrupt(jiffies);
-}
-#endif
-
 #endif
 
 #ifndef CONFIG_VIRT_CPU_ACCOUNTING
@@ -1502,7 +1494,7 @@ void __init init_timers(void)
 
        BUG_ON(err == NOTIFY_BAD);
        register_cpu_notifier(&timers_nb);
-       open_softirq(TIMER_SOFTIRQ, run_timer_softirq, NULL);
+       open_softirq(TIMER_SOFTIRQ, run_timer_softirq);
 }
 
 /**
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
new file mode 100644 (file)
index 0000000..263e9e6
--- /dev/null
@@ -0,0 +1,135 @@
+#
+# Architectures that offer an FTRACE implementation should select HAVE_FTRACE:
+#
+config HAVE_FTRACE
+       bool
+
+config HAVE_DYNAMIC_FTRACE
+       bool
+
+config TRACER_MAX_TRACE
+       bool
+
+config TRACING
+       bool
+       select DEBUG_FS
+       select STACKTRACE
+
+config FTRACE
+       bool "Kernel Function Tracer"
+       depends on HAVE_FTRACE
+       select FRAME_POINTER
+       select TRACING
+       select CONTEXT_SWITCH_TRACER
+       help
+         Enable the kernel to trace every kernel function. This is done
+         by using a compiler feature to insert a small, 5-byte No-Operation
+         instruction to the beginning of every kernel function, which NOP
+         sequence is then dynamically patched into a tracer call when
+         tracing is enabled by the administrator. If it's runtime disabled
+         (the bootup default), then the overhead of the instructions is very
+         small and not measurable even in micro-benchmarks.
+
+config IRQSOFF_TRACER
+       bool "Interrupts-off Latency Tracer"
+       default n
+       depends on TRACE_IRQFLAGS_SUPPORT
+       depends on GENERIC_TIME
+       depends on HAVE_FTRACE
+       select TRACE_IRQFLAGS
+       select TRACING
+       select TRACER_MAX_TRACE
+       help
+         This option measures the time spent in irqs-off critical
+         sections, with microsecond accuracy.
+
+         The default measurement method is a maximum search, which is
+         disabled by default and can be runtime (re-)started
+         via:
+
+             echo 0 > /debugfs/tracing/tracing_max_latency
+
+         (Note that kernel size and overhead increases with this option
+         enabled. This option and the preempt-off timing option can be
+         used together or separately.)
+
+config PREEMPT_TRACER
+       bool "Preemption-off Latency Tracer"
+       default n
+       depends on GENERIC_TIME
+       depends on PREEMPT
+       depends on HAVE_FTRACE
+       select TRACING
+       select TRACER_MAX_TRACE
+       help
+         This option measures the time spent in preemption off critical
+         sections, with microsecond accuracy.
+
+         The default measurement method is a maximum search, which is
+         disabled by default and can be runtime (re-)started
+         via:
+
+             echo 0 > /debugfs/tracing/tracing_max_latency
+
+         (Note that kernel size and overhead increases with this option
+         enabled. This option and the irqs-off timing option can be
+         used together or separately.)
+
+config SYSPROF_TRACER
+       bool "Sysprof Tracer"
+       depends on X86
+       select TRACING
+       help
+         This tracer provides the trace needed by the 'Sysprof' userspace
+         tool.
+
+config SCHED_TRACER
+       bool "Scheduling Latency Tracer"
+       depends on HAVE_FTRACE
+       select TRACING
+       select CONTEXT_SWITCH_TRACER
+       select TRACER_MAX_TRACE
+       help
+         This tracer tracks the latency of the highest priority task
+         to be scheduled in, starting from the point it has woken up.
+
+config CONTEXT_SWITCH_TRACER
+       bool "Trace process context switches"
+       depends on HAVE_FTRACE
+       select TRACING
+       select MARKERS
+       help
+         This tracer gets called from the context switch and records
+         all switching of tasks.
+
+config DYNAMIC_FTRACE
+       bool "enable/disable ftrace tracepoints dynamically"
+       depends on FTRACE
+       depends on HAVE_DYNAMIC_FTRACE
+       default y
+       help
+         This option will modify all the calls to ftrace dynamically
+        (will patch them out of the binary image and replaces them
+        with a No-Op instruction) as they are called. A table is
+        created to dynamically enable them again.
+
+        This way a CONFIG_FTRACE kernel is slightly larger, but otherwise
+        has native performance as long as no tracing is active.
+
+        The changes to the code are done by a kernel thread that
+        wakes up once a second and checks to see if any ftrace calls
+        were made. If so, it runs stop_machine (stops all CPUS)
+        and modifies the code to jump over the call to ftrace.
+
+config FTRACE_SELFTEST
+       bool
+
+config FTRACE_STARTUP_TEST
+       bool "Perform a startup test on ftrace"
+       depends on TRACING
+       select FTRACE_SELFTEST
+       help
+         This option performs a series of startup tests on ftrace. On bootup
+         a series of tests are made to verify that the tracer is
+         functioning properly. It will do tests on all the configured
+         tracers of ftrace.
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
new file mode 100644 (file)
index 0000000..71d17de
--- /dev/null
@@ -0,0 +1,24 @@
+
+# Do not instrument the tracer itself:
+
+ifdef CONFIG_FTRACE
+ORIG_CFLAGS := $(KBUILD_CFLAGS)
+KBUILD_CFLAGS = $(subst -pg,,$(ORIG_CFLAGS))
+
+# selftest needs instrumentation
+CFLAGS_trace_selftest_dynamic.o = -pg
+obj-y += trace_selftest_dynamic.o
+endif
+
+obj-$(CONFIG_FTRACE) += libftrace.o
+
+obj-$(CONFIG_TRACING) += trace.o
+obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o
+obj-$(CONFIG_SYSPROF_TRACER) += trace_sysprof.o
+obj-$(CONFIG_FTRACE) += trace_functions.o
+obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
+obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
+obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
+obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
+
+libftrace-y := ftrace.o
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
new file mode 100644 (file)
index 0000000..4231a3d
--- /dev/null
@@ -0,0 +1,1727 @@
+/*
+ * Infrastructure for profiling code inserted by 'gcc -pg'.
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2004-2008 Ingo Molnar <mingo@redhat.com>
+ *
+ * Originally ported from the -rt patch by:
+ *   Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
+ *
+ * Based on code in the latency_tracer, that is:
+ *
+ *  Copyright (C) 2004-2006 Ingo Molnar
+ *  Copyright (C) 2004 William Lee Irwin III
+ */
+
+#include <linux/stop_machine.h>
+#include <linux/clocksource.h>
+#include <linux/kallsyms.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+#include <linux/hardirq.h>
+#include <linux/kthread.h>
+#include <linux/uaccess.h>
+#include <linux/kprobes.h>
+#include <linux/ftrace.h>
+#include <linux/sysctl.h>
+#include <linux/ctype.h>
+#include <linux/hash.h>
+#include <linux/list.h>
+
+#include <asm/ftrace.h>
+
+#include "trace.h"
+
+/* ftrace_enabled is a method to turn ftrace on or off */
+int ftrace_enabled __read_mostly;
+static int last_ftrace_enabled;
+
+/*
+ * ftrace_disabled is set when an anomaly is discovered.
+ * ftrace_disabled is much stronger than ftrace_enabled.
+ */
+static int ftrace_disabled __read_mostly;
+
+static DEFINE_SPINLOCK(ftrace_lock);
+static DEFINE_MUTEX(ftrace_sysctl_lock);
+
+static struct ftrace_ops ftrace_list_end __read_mostly =
+{
+       .func = ftrace_stub,
+};
+
+static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end;
+ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
+
+static void ftrace_list_func(unsigned long ip, unsigned long parent_ip)
+{
+       struct ftrace_ops *op = ftrace_list;
+
+       /* in case someone actually ports this to alpha! */
+       read_barrier_depends();
+
+       while (op != &ftrace_list_end) {
+               /* silly alpha */
+               read_barrier_depends();
+               op->func(ip, parent_ip);
+               op = op->next;
+       };
+}
+
+/**
+ * clear_ftrace_function - reset the ftrace function
+ *
+ * This NULLs the ftrace function and in essence stops
+ * tracing.  There may be lag
+ */
+void clear_ftrace_function(void)
+{
+       ftrace_trace_function = ftrace_stub;
+}
+
+static int __register_ftrace_function(struct ftrace_ops *ops)
+{
+       /* Should never be called by interrupts */
+       spin_lock(&ftrace_lock);
+
+       ops->next = ftrace_list;
+       /*
+        * We are entering ops into the ftrace_list but another
+        * CPU might be walking that list. We need to make sure
+        * the ops->next pointer is valid before another CPU sees
+        * the ops pointer included into the ftrace_list.
+        */
+       smp_wmb();
+       ftrace_list = ops;
+
+       if (ftrace_enabled) {
+               /*
+                * For one func, simply call it directly.
+                * For more than one func, call the chain.
+                */
+               if (ops->next == &ftrace_list_end)
+                       ftrace_trace_function = ops->func;
+               else
+                       ftrace_trace_function = ftrace_list_func;
+       }
+
+       spin_unlock(&ftrace_lock);
+
+       return 0;
+}
+
+static int __unregister_ftrace_function(struct ftrace_ops *ops)
+{
+       struct ftrace_ops **p;
+       int ret = 0;
+
+       spin_lock(&ftrace_lock);
+
+       /*
+        * If we are removing the last function, then simply point
+        * to the ftrace_stub.
+        */
+       if (ftrace_list == ops && ops->next == &ftrace_list_end) {
+               ftrace_trace_function = ftrace_stub;
+               ftrace_list = &ftrace_list_end;
+               goto out;
+       }
+
+       for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next)
+               if (*p == ops)
+                       break;
+
+       if (*p != ops) {
+               ret = -1;
+               goto out;
+       }
+
+       *p = (*p)->next;
+
+       if (ftrace_enabled) {
+               /* If we only have one func left, then call that directly */
+               if (ftrace_list == &ftrace_list_end ||
+                   ftrace_list->next == &ftrace_list_end)
+                       ftrace_trace_function = ftrace_list->func;
+       }
+
+ out:
+       spin_unlock(&ftrace_lock);
+
+       return ret;
+}
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+
+static struct task_struct *ftraced_task;
+
+enum {
+       FTRACE_ENABLE_CALLS             = (1 << 0),
+       FTRACE_DISABLE_CALLS            = (1 << 1),
+       FTRACE_UPDATE_TRACE_FUNC        = (1 << 2),
+       FTRACE_ENABLE_MCOUNT            = (1 << 3),
+       FTRACE_DISABLE_MCOUNT           = (1 << 4),
+};
+
+static int ftrace_filtered;
+static int tracing_on;
+static int frozen_record_count;
+
+static struct hlist_head ftrace_hash[FTRACE_HASHSIZE];
+
+static DEFINE_PER_CPU(int, ftrace_shutdown_disable_cpu);
+
+static DEFINE_SPINLOCK(ftrace_shutdown_lock);
+static DEFINE_MUTEX(ftraced_lock);
+static DEFINE_MUTEX(ftrace_regex_lock);
+
+struct ftrace_page {
+       struct ftrace_page      *next;
+       unsigned long           index;
+       struct dyn_ftrace       records[];
+};
+
+#define ENTRIES_PER_PAGE \
+  ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace))
+
+/* estimate from running different kernels */
+#define NR_TO_INIT             10000
+
+static struct ftrace_page      *ftrace_pages_start;
+static struct ftrace_page      *ftrace_pages;
+
+static int ftraced_trigger;
+static int ftraced_suspend;
+static int ftraced_stop;
+
+static int ftrace_record_suspend;
+
+static struct dyn_ftrace *ftrace_free_records;
+
+
+#ifdef CONFIG_KPROBES
+static inline void freeze_record(struct dyn_ftrace *rec)
+{
+       if (!(rec->flags & FTRACE_FL_FROZEN)) {
+               rec->flags |= FTRACE_FL_FROZEN;
+               frozen_record_count++;
+       }
+}
+
+static inline void unfreeze_record(struct dyn_ftrace *rec)
+{
+       if (rec->flags & FTRACE_FL_FROZEN) {
+               rec->flags &= ~FTRACE_FL_FROZEN;
+               frozen_record_count--;
+       }
+}
+
+static inline int record_frozen(struct dyn_ftrace *rec)
+{
+       return rec->flags & FTRACE_FL_FROZEN;
+}
+#else
+# define freeze_record(rec)                    ({ 0; })
+# define unfreeze_record(rec)                  ({ 0; })
+# define record_frozen(rec)                    ({ 0; })
+#endif /* CONFIG_KPROBES */
+
+int skip_trace(unsigned long ip)
+{
+       unsigned long fl;
+       struct dyn_ftrace *rec;
+       struct hlist_node *t;
+       struct hlist_head *head;
+
+       if (frozen_record_count == 0)
+               return 0;
+
+       head = &ftrace_hash[hash_long(ip, FTRACE_HASHBITS)];
+       hlist_for_each_entry_rcu(rec, t, head, node) {
+               if (rec->ip == ip) {
+                       if (record_frozen(rec)) {
+                               if (rec->flags & FTRACE_FL_FAILED)
+                                       return 1;
+
+                               if (!(rec->flags & FTRACE_FL_CONVERTED))
+                                       return 1;
+
+                               if (!tracing_on || !ftrace_enabled)
+                                       return 1;
+
+                               if (ftrace_filtered) {
+                                       fl = rec->flags & (FTRACE_FL_FILTER |
+                                                          FTRACE_FL_NOTRACE);
+                                       if (!fl || (fl & FTRACE_FL_NOTRACE))
+                                               return 1;
+                               }
+                       }
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+static inline int
+ftrace_ip_in_hash(unsigned long ip, unsigned long key)
+{
+       struct dyn_ftrace *p;
+       struct hlist_node *t;
+       int found = 0;
+
+       hlist_for_each_entry_rcu(p, t, &ftrace_hash[key], node) {
+               if (p->ip == ip) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       return found;
+}
+
+static inline void
+ftrace_add_hash(struct dyn_ftrace *node, unsigned long key)
+{
+       hlist_add_head_rcu(&node->node, &ftrace_hash[key]);
+}
+
+/* called from kstop_machine */
+static inline void ftrace_del_hash(struct dyn_ftrace *node)
+{
+       hlist_del(&node->node);
+}
+
+static void ftrace_free_rec(struct dyn_ftrace *rec)
+{
+       /* no locking, only called from kstop_machine */
+
+       rec->ip = (unsigned long)ftrace_free_records;
+       ftrace_free_records = rec;
+       rec->flags |= FTRACE_FL_FREE;
+}
+
+static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
+{
+       struct dyn_ftrace *rec;
+
+       /* First check for freed records */
+       if (ftrace_free_records) {
+               rec = ftrace_free_records;
+
+               if (unlikely(!(rec->flags & FTRACE_FL_FREE))) {
+                       WARN_ON_ONCE(1);
+                       ftrace_free_records = NULL;
+                       ftrace_disabled = 1;
+                       ftrace_enabled = 0;
+                       return NULL;
+               }
+
+               ftrace_free_records = (void *)rec->ip;
+               memset(rec, 0, sizeof(*rec));
+               return rec;
+       }
+
+       if (ftrace_pages->index == ENTRIES_PER_PAGE) {
+               if (!ftrace_pages->next)
+                       return NULL;
+               ftrace_pages = ftrace_pages->next;
+       }
+
+       return &ftrace_pages->records[ftrace_pages->index++];
+}
+
+static void
+ftrace_record_ip(unsigned long ip)
+{
+       struct dyn_ftrace *node;
+       unsigned long flags;
+       unsigned long key;
+       int resched;
+       int atomic;
+       int cpu;
+
+       if (!ftrace_enabled || ftrace_disabled)
+               return;
+
+       resched = need_resched();
+       preempt_disable_notrace();
+
+       /*
+        * We simply need to protect against recursion.
+        * Use the the raw version of smp_processor_id and not
+        * __get_cpu_var which can call debug hooks that can
+        * cause a recursive crash here.
+        */
+       cpu = raw_smp_processor_id();
+       per_cpu(ftrace_shutdown_disable_cpu, cpu)++;
+       if (per_cpu(ftrace_shutdown_disable_cpu, cpu) != 1)
+               goto out;
+
+       if (unlikely(ftrace_record_suspend))
+               goto out;
+
+       key = hash_long(ip, FTRACE_HASHBITS);
+
+       WARN_ON_ONCE(key >= FTRACE_HASHSIZE);
+
+       if (ftrace_ip_in_hash(ip, key))
+               goto out;
+
+       atomic = irqs_disabled();
+
+       spin_lock_irqsave(&ftrace_shutdown_lock, flags);
+
+       /* This ip may have hit the hash before the lock */
+       if (ftrace_ip_in_hash(ip, key))
+               goto out_unlock;
+
+       node = ftrace_alloc_dyn_node(ip);
+       if (!node)
+               goto out_unlock;
+
+       node->ip = ip;
+
+       ftrace_add_hash(node, key);
+
+       ftraced_trigger = 1;
+
+ out_unlock:
+       spin_unlock_irqrestore(&ftrace_shutdown_lock, flags);
+ out:
+       per_cpu(ftrace_shutdown_disable_cpu, cpu)--;
+
+       /* prevent recursion with scheduler */
+       if (resched)
+               preempt_enable_no_resched_notrace();
+       else
+               preempt_enable_notrace();
+}
+
+#define FTRACE_ADDR ((long)(ftrace_caller))
+
+static int
+__ftrace_replace_code(struct dyn_ftrace *rec,
+                     unsigned char *old, unsigned char *new, int enable)
+{
+       unsigned long ip, fl;
+
+       ip = rec->ip;
+
+       if (ftrace_filtered && enable) {
+               /*
+                * If filtering is on:
+                *
+                * If this record is set to be filtered and
+                * is enabled then do nothing.
+                *
+                * If this record is set to be filtered and
+                * it is not enabled, enable it.
+                *
+                * If this record is not set to be filtered
+                * and it is not enabled do nothing.
+                *
+                * If this record is set not to trace then
+                * do nothing.
+                *
+                * If this record is set not to trace and
+                * it is enabled then disable it.
+                *
+                * If this record is not set to be filtered and
+                * it is enabled, disable it.
+                */
+
+               fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |
+                                  FTRACE_FL_ENABLED);
+
+               if ((fl ==  (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
+                   (fl ==  (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||
+                   !fl || (fl == FTRACE_FL_NOTRACE))
+                       return 0;
+
+               /*
+                * If it is enabled disable it,
+                * otherwise enable it!
+                */
+               if (fl & FTRACE_FL_ENABLED) {
+                       /* swap new and old */
+                       new = old;
+                       old = ftrace_call_replace(ip, FTRACE_ADDR);
+                       rec->flags &= ~FTRACE_FL_ENABLED;
+               } else {
+                       new = ftrace_call_replace(ip, FTRACE_ADDR);
+                       rec->flags |= FTRACE_FL_ENABLED;
+               }
+       } else {
+
+               if (enable) {
+                       /*
+                        * If this record is set not to trace and is
+                        * not enabled, do nothing.
+                        */
+                       fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
+                       if (fl == FTRACE_FL_NOTRACE)
+                               return 0;
+
+                       new = ftrace_call_replace(ip, FTRACE_ADDR);
+               } else
+                       old = ftrace_call_replace(ip, FTRACE_ADDR);
+
+               if (enable) {
+                       if (rec->flags & FTRACE_FL_ENABLED)
+                               return 0;
+                       rec->flags |= FTRACE_FL_ENABLED;
+               } else {
+                       if (!(rec->flags & FTRACE_FL_ENABLED))
+                               return 0;
+                       rec->flags &= ~FTRACE_FL_ENABLED;
+               }
+       }
+
+       return ftrace_modify_code(ip, old, new);
+}
+
+static void ftrace_replace_code(int enable)
+{
+       int i, failed;
+       unsigned char *new = NULL, *old = NULL;
+       struct dyn_ftrace *rec;
+       struct ftrace_page *pg;
+
+       if (enable)
+               old = ftrace_nop_replace();
+       else
+               new = ftrace_nop_replace();
+
+       for (pg = ftrace_pages_start; pg; pg = pg->next) {
+               for (i = 0; i < pg->index; i++) {
+                       rec = &pg->records[i];
+
+                       /* don't modify code that has already faulted */
+                       if (rec->flags & FTRACE_FL_FAILED)
+                               continue;
+
+                       /* ignore updates to this record's mcount site */
+                       if (get_kprobe((void *)rec->ip)) {
+                               freeze_record(rec);
+                               continue;
+                       } else {
+                               unfreeze_record(rec);
+                       }
+
+                       failed = __ftrace_replace_code(rec, old, new, enable);
+                       if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
+                               rec->flags |= FTRACE_FL_FAILED;
+                               if ((system_state == SYSTEM_BOOTING) ||
+                                   !core_kernel_text(rec->ip)) {
+                                       ftrace_del_hash(rec);
+                                       ftrace_free_rec(rec);
+                               }
+                       }
+               }
+       }
+}
+
+static void ftrace_shutdown_replenish(void)
+{
+       if (ftrace_pages->next)
+               return;
+
+       /* allocate another page */
+       ftrace_pages->next = (void *)get_zeroed_page(GFP_KERNEL);
+}
+
+static int
+ftrace_code_disable(struct dyn_ftrace *rec)
+{
+       unsigned long ip;
+       unsigned char *nop, *call;
+       int failed;
+
+       ip = rec->ip;
+
+       nop = ftrace_nop_replace();
+       call = ftrace_call_replace(ip, MCOUNT_ADDR);
+
+       failed = ftrace_modify_code(ip, call, nop);
+       if (failed) {
+               rec->flags |= FTRACE_FL_FAILED;
+               return 0;
+       }
+       return 1;
+}
+
+static int __ftrace_update_code(void *ignore);
+
+static int __ftrace_modify_code(void *data)
+{
+       unsigned long addr;
+       int *command = data;
+
+       if (*command & FTRACE_ENABLE_CALLS) {
+               /*
+                * Update any recorded ips now that we have the
+                * machine stopped
+                */
+               __ftrace_update_code(NULL);
+               ftrace_replace_code(1);
+               tracing_on = 1;
+       } else if (*command & FTRACE_DISABLE_CALLS) {
+               ftrace_replace_code(0);
+               tracing_on = 0;
+       }
+
+       if (*command & FTRACE_UPDATE_TRACE_FUNC)
+               ftrace_update_ftrace_func(ftrace_trace_function);
+
+       if (*command & FTRACE_ENABLE_MCOUNT) {
+               addr = (unsigned long)ftrace_record_ip;
+               ftrace_mcount_set(&addr);
+       } else if (*command & FTRACE_DISABLE_MCOUNT) {
+               addr = (unsigned long)ftrace_stub;
+               ftrace_mcount_set(&addr);
+       }
+
+       return 0;
+}
+
+static void ftrace_run_update_code(int command)
+{
+       stop_machine_run(__ftrace_modify_code, &command, NR_CPUS);
+}
+
+void ftrace_disable_daemon(void)
+{
+       /* Stop the daemon from calling kstop_machine */
+       mutex_lock(&ftraced_lock);
+       ftraced_stop = 1;
+       mutex_unlock(&ftraced_lock);
+
+       ftrace_force_update();
+}
+
+void ftrace_enable_daemon(void)
+{
+       mutex_lock(&ftraced_lock);
+       ftraced_stop = 0;
+       mutex_unlock(&ftraced_lock);
+
+       ftrace_force_update();
+}
+
+static ftrace_func_t saved_ftrace_func;
+
+static void ftrace_startup(void)
+{
+       int command = 0;
+
+       if (unlikely(ftrace_disabled))
+               return;
+
+       mutex_lock(&ftraced_lock);
+       ftraced_suspend++;
+       if (ftraced_suspend == 1)
+               command |= FTRACE_ENABLE_CALLS;
+
+       if (saved_ftrace_func != ftrace_trace_function) {
+               saved_ftrace_func = ftrace_trace_function;
+               command |= FTRACE_UPDATE_TRACE_FUNC;
+       }
+
+       if (!command || !ftrace_enabled)
+               goto out;
+
+       ftrace_run_update_code(command);
+ out:
+       mutex_unlock(&ftraced_lock);
+}
+
+static void ftrace_shutdown(void)
+{
+       int command = 0;
+
+       if (unlikely(ftrace_disabled))
+               return;
+
+       mutex_lock(&ftraced_lock);
+       ftraced_suspend--;
+       if (!ftraced_suspend)
+               command |= FTRACE_DISABLE_CALLS;
+
+       if (saved_ftrace_func != ftrace_trace_function) {
+               saved_ftrace_func = ftrace_trace_function;
+               command |= FTRACE_UPDATE_TRACE_FUNC;
+       }
+
+       if (!command || !ftrace_enabled)
+               goto out;
+
+       ftrace_run_update_code(command);
+ out:
+       mutex_unlock(&ftraced_lock);
+}
+
+static void ftrace_startup_sysctl(void)
+{
+       int command = FTRACE_ENABLE_MCOUNT;
+
+       if (unlikely(ftrace_disabled))
+               return;
+
+       mutex_lock(&ftraced_lock);
+       /* Force update next time */
+       saved_ftrace_func = NULL;
+       /* ftraced_suspend is true if we want ftrace running */
+       if (ftraced_suspend)
+               command |= FTRACE_ENABLE_CALLS;
+
+       ftrace_run_update_code(command);
+       mutex_unlock(&ftraced_lock);
+}
+
+static void ftrace_shutdown_sysctl(void)
+{
+       int command = FTRACE_DISABLE_MCOUNT;
+
+       if (unlikely(ftrace_disabled))
+               return;
+
+       mutex_lock(&ftraced_lock);
+       /* ftraced_suspend is true if ftrace is running */
+       if (ftraced_suspend)
+               command |= FTRACE_DISABLE_CALLS;
+
+       ftrace_run_update_code(command);
+       mutex_unlock(&ftraced_lock);
+}
+
+static cycle_t         ftrace_update_time;
+static unsigned long   ftrace_update_cnt;
+unsigned long          ftrace_update_tot_cnt;
+
+static int __ftrace_update_code(void *ignore)
+{
+       int i, save_ftrace_enabled;
+       cycle_t start, stop;
+       struct dyn_ftrace *p;
+       struct hlist_node *t, *n;
+       struct hlist_head *head, temp_list;
+
+       /* Don't be recording funcs now */
+       ftrace_record_suspend++;
+       save_ftrace_enabled = ftrace_enabled;
+       ftrace_enabled = 0;
+
+       start = ftrace_now(raw_smp_processor_id());
+       ftrace_update_cnt = 0;
+
+       /* No locks needed, the machine is stopped! */
+       for (i = 0; i < FTRACE_HASHSIZE; i++) {
+               INIT_HLIST_HEAD(&temp_list);
+               head = &ftrace_hash[i];
+
+               /* all CPUS are stopped, we are safe to modify code */
+               hlist_for_each_entry_safe(p, t, n, head, node) {
+                       /* Skip over failed records which have not been
+                        * freed. */
+                       if (p->flags & FTRACE_FL_FAILED)
+                               continue;
+
+                       /* Unconverted records are always at the head of the
+                        * hash bucket. Once we encounter a converted record,
+                        * simply skip over to the next bucket. Saves ftraced
+                        * some processor cycles (ftrace does its bid for
+                        * global warming :-p ). */
+                       if (p->flags & (FTRACE_FL_CONVERTED))
+                               break;
+
+                       /* Ignore updates to this record's mcount site.
+                        * Reintroduce this record at the head of this
+                        * bucket to attempt to "convert" it again if
+                        * the kprobe on it is unregistered before the
+                        * next run. */
+                       if (get_kprobe((void *)p->ip)) {
+                               ftrace_del_hash(p);
+                               INIT_HLIST_NODE(&p->node);
+                               hlist_add_head(&p->node, &temp_list);
+                               freeze_record(p);
+                               continue;
+                       } else {
+                               unfreeze_record(p);
+                       }
+
+                       /* convert record (i.e, patch mcount-call with NOP) */
+                       if (ftrace_code_disable(p)) {
+                               p->flags |= FTRACE_FL_CONVERTED;
+                               ftrace_update_cnt++;
+                       } else {
+                               if ((system_state == SYSTEM_BOOTING) ||
+                                   !core_kernel_text(p->ip)) {
+                                       ftrace_del_hash(p);
+                                       ftrace_free_rec(p);
+                               }
+                       }
+               }
+
+               hlist_for_each_entry_safe(p, t, n, &temp_list, node) {
+                       hlist_del(&p->node);
+                       INIT_HLIST_NODE(&p->node);
+                       hlist_add_head(&p->node, head);
+               }
+       }
+
+       stop = ftrace_now(raw_smp_processor_id());
+       ftrace_update_time = stop - start;
+       ftrace_update_tot_cnt += ftrace_update_cnt;
+       ftraced_trigger = 0;
+
+       ftrace_enabled = save_ftrace_enabled;
+       ftrace_record_suspend--;
+
+       return 0;
+}
+
+static int ftrace_update_code(void)
+{
+       if (unlikely(ftrace_disabled) ||
+           !ftrace_enabled || !ftraced_trigger)
+               return 0;
+
+       stop_machine_run(__ftrace_update_code, NULL, NR_CPUS);
+
+       return 1;
+}
+
+static int ftraced(void *ignore)
+{
+       unsigned long usecs;
+
+       while (!kthread_should_stop()) {
+
+               set_current_state(TASK_INTERRUPTIBLE);
+
+               /* check once a second */
+               schedule_timeout(HZ);
+
+               if (unlikely(ftrace_disabled))
+                       continue;
+
+               mutex_lock(&ftrace_sysctl_lock);
+               mutex_lock(&ftraced_lock);
+               if (!ftraced_suspend && !ftraced_stop &&
+                   ftrace_update_code()) {
+                       usecs = nsecs_to_usecs(ftrace_update_time);
+                       if (ftrace_update_tot_cnt > 100000) {
+                               ftrace_update_tot_cnt = 0;
+                               pr_info("hm, dftrace overflow: %lu change%s"
+                                       " (%lu total) in %lu usec%s\n",
+                                       ftrace_update_cnt,
+                                       ftrace_update_cnt != 1 ? "s" : "",
+                                       ftrace_update_tot_cnt,
+                                       usecs, usecs != 1 ? "s" : "");
+                               ftrace_disabled = 1;
+                               WARN_ON_ONCE(1);
+                       }
+               }
+               mutex_unlock(&ftraced_lock);
+               mutex_unlock(&ftrace_sysctl_lock);
+
+               ftrace_shutdown_replenish();
+       }
+       __set_current_state(TASK_RUNNING);
+       return 0;
+}
+
+static int __init ftrace_dyn_table_alloc(void)
+{
+       struct ftrace_page *pg;
+       int cnt;
+       int i;
+
+       /* allocate a few pages */
+       ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL);
+       if (!ftrace_pages_start)
+               return -1;
+
+       /*
+        * Allocate a few more pages.
+        *
+        * TODO: have some parser search vmlinux before
+        *   final linking to find all calls to ftrace.
+        *   Then we can:
+        *    a) know how many pages to allocate.
+        *     and/or
+        *    b) set up the table then.
+        *
+        *  The dynamic code is still necessary for
+        *  modules.
+        */
+
+       pg = ftrace_pages = ftrace_pages_start;
+
+       cnt = NR_TO_INIT / ENTRIES_PER_PAGE;
+
+       for (i = 0; i < cnt; i++) {
+               pg->next = (void *)get_zeroed_page(GFP_KERNEL);
+
+               /* If we fail, we'll try later anyway */
+               if (!pg->next)
+                       break;
+
+               pg = pg->next;
+       }
+
+       return 0;
+}
+
+enum {
+       FTRACE_ITER_FILTER      = (1 << 0),
+       FTRACE_ITER_CONT        = (1 << 1),
+       FTRACE_ITER_NOTRACE     = (1 << 2),
+       FTRACE_ITER_FAILURES    = (1 << 3),
+};
+
+#define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
+
+struct ftrace_iterator {
+       loff_t                  pos;
+       struct ftrace_page      *pg;
+       unsigned                idx;
+       unsigned                flags;
+       unsigned char           buffer[FTRACE_BUFF_MAX+1];
+       unsigned                buffer_idx;
+       unsigned                filtered;
+};
+
+static void *
+t_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       struct ftrace_iterator *iter = m->private;
+       struct dyn_ftrace *rec = NULL;
+
+       (*pos)++;
+
+ retry:
+       if (iter->idx >= iter->pg->index) {
+               if (iter->pg->next) {
+                       iter->pg = iter->pg->next;
+                       iter->idx = 0;
+                       goto retry;
+               }
+       } else {
+               rec = &iter->pg->records[iter->idx++];
+               if ((!(iter->flags & FTRACE_ITER_FAILURES) &&
+                    (rec->flags & FTRACE_FL_FAILED)) ||
+
+                   ((iter->flags & FTRACE_ITER_FAILURES) &&
+                    (!(rec->flags & FTRACE_FL_FAILED) ||
+                     (rec->flags & FTRACE_FL_FREE))) ||
+
+                   ((iter->flags & FTRACE_ITER_FILTER) &&
+                    !(rec->flags & FTRACE_FL_FILTER)) ||
+
+                   ((iter->flags & FTRACE_ITER_NOTRACE) &&
+                    !(rec->flags & FTRACE_FL_NOTRACE))) {
+                       rec = NULL;
+                       goto retry;
+               }
+       }
+
+       iter->pos = *pos;
+
+       return rec;
+}
+
+static void *t_start(struct seq_file *m, loff_t *pos)
+{
+       struct ftrace_iterator *iter = m->private;
+       void *p = NULL;
+       loff_t l = -1;
+
+       if (*pos != iter->pos) {
+               for (p = t_next(m, p, &l); p && l < *pos; p = t_next(m, p, &l))
+                       ;
+       } else {
+               l = *pos;
+               p = t_next(m, p, &l);
+       }
+
+       return p;
+}
+
+static void t_stop(struct seq_file *m, void *p)
+{
+}
+
+static int t_show(struct seq_file *m, void *v)
+{
+       struct dyn_ftrace *rec = v;
+       char str[KSYM_SYMBOL_LEN];
+
+       if (!rec)
+               return 0;
+
+       kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
+
+       seq_printf(m, "%s\n", str);
+
+       return 0;
+}
+
+static struct seq_operations show_ftrace_seq_ops = {
+       .start = t_start,
+       .next = t_next,
+       .stop = t_stop,
+       .show = t_show,
+};
+
+static int
+ftrace_avail_open(struct inode *inode, struct file *file)
+{
+       struct ftrace_iterator *iter;
+       int ret;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+       if (!iter)
+               return -ENOMEM;
+
+       iter->pg = ftrace_pages_start;
+       iter->pos = -1;
+
+       ret = seq_open(file, &show_ftrace_seq_ops);
+       if (!ret) {
+               struct seq_file *m = file->private_data;
+
+               m->private = iter;
+       } else {
+               kfree(iter);
+       }
+
+       return ret;
+}
+
+int ftrace_avail_release(struct inode *inode, struct file *file)
+{
+       struct seq_file *m = (struct seq_file *)file->private_data;
+       struct ftrace_iterator *iter = m->private;
+
+       seq_release(inode, file);
+       kfree(iter);
+
+       return 0;
+}
+
+static int
+ftrace_failures_open(struct inode *inode, struct file *file)
+{
+       int ret;
+       struct seq_file *m;
+       struct ftrace_iterator *iter;
+
+       ret = ftrace_avail_open(inode, file);
+       if (!ret) {
+               m = (struct seq_file *)file->private_data;
+               iter = (struct ftrace_iterator *)m->private;
+               iter->flags = FTRACE_ITER_FAILURES;
+       }
+
+       return ret;
+}
+
+
+static void ftrace_filter_reset(int enable)
+{
+       struct ftrace_page *pg;
+       struct dyn_ftrace *rec;
+       unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
+       unsigned i;
+
+       /* keep kstop machine from running */
+       preempt_disable();
+       if (enable)
+               ftrace_filtered = 0;
+       pg = ftrace_pages_start;
+       while (pg) {
+               for (i = 0; i < pg->index; i++) {
+                       rec = &pg->records[i];
+                       if (rec->flags & FTRACE_FL_FAILED)
+                               continue;
+                       rec->flags &= ~type;
+               }
+               pg = pg->next;
+       }
+       preempt_enable();
+}
+
+static int
+ftrace_regex_open(struct inode *inode, struct file *file, int enable)
+{
+       struct ftrace_iterator *iter;
+       int ret = 0;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+       if (!iter)
+               return -ENOMEM;
+
+       mutex_lock(&ftrace_regex_lock);
+       if ((file->f_mode & FMODE_WRITE) &&
+           !(file->f_flags & O_APPEND))
+               ftrace_filter_reset(enable);
+
+       if (file->f_mode & FMODE_READ) {
+               iter->pg = ftrace_pages_start;
+               iter->pos = -1;
+               iter->flags = enable ? FTRACE_ITER_FILTER :
+                       FTRACE_ITER_NOTRACE;
+
+               ret = seq_open(file, &show_ftrace_seq_ops);
+               if (!ret) {
+                       struct seq_file *m = file->private_data;
+                       m->private = iter;
+               } else
+                       kfree(iter);
+       } else
+               file->private_data = iter;
+       mutex_unlock(&ftrace_regex_lock);
+
+       return ret;
+}
+
+static int
+ftrace_filter_open(struct inode *inode, struct file *file)
+{
+       return ftrace_regex_open(inode, file, 1);
+}
+
+static int
+ftrace_notrace_open(struct inode *inode, struct file *file)
+{
+       return ftrace_regex_open(inode, file, 0);
+}
+
+static ssize_t
+ftrace_regex_read(struct file *file, char __user *ubuf,
+                      size_t cnt, loff_t *ppos)
+{
+       if (file->f_mode & FMODE_READ)
+               return seq_read(file, ubuf, cnt, ppos);
+       else
+               return -EPERM;
+}
+
+static loff_t
+ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
+{
+       loff_t ret;
+
+       if (file->f_mode & FMODE_READ)
+               ret = seq_lseek(file, offset, origin);
+       else
+               file->f_pos = ret = 1;
+
+       return ret;
+}
+
+enum {
+       MATCH_FULL,
+       MATCH_FRONT_ONLY,
+       MATCH_MIDDLE_ONLY,
+       MATCH_END_ONLY,
+};
+
+static void
+ftrace_match(unsigned char *buff, int len, int enable)
+{
+       char str[KSYM_SYMBOL_LEN];
+       char *search = NULL;
+       struct ftrace_page *pg;
+       struct dyn_ftrace *rec;
+       int type = MATCH_FULL;
+       unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
+       unsigned i, match = 0, search_len = 0;
+
+       for (i = 0; i < len; i++) {
+               if (buff[i] == '*') {
+                       if (!i) {
+                               search = buff + i + 1;
+                               type = MATCH_END_ONLY;
+                               search_len = len - (i + 1);
+                       } else {
+                               if (type == MATCH_END_ONLY) {
+                                       type = MATCH_MIDDLE_ONLY;
+                               } else {
+                                       match = i;
+                                       type = MATCH_FRONT_ONLY;
+                               }
+                               buff[i] = 0;
+                               break;
+                       }
+               }
+       }
+
+       /* keep kstop machine from running */
+       preempt_disable();
+       if (enable)
+               ftrace_filtered = 1;
+       pg = ftrace_pages_start;
+       while (pg) {
+               for (i = 0; i < pg->index; i++) {
+                       int matched = 0;
+                       char *ptr;
+
+                       rec = &pg->records[i];
+                       if (rec->flags & FTRACE_FL_FAILED)
+                               continue;
+                       kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
+                       switch (type) {
+                       case MATCH_FULL:
+                               if (strcmp(str, buff) == 0)
+                                       matched = 1;
+                               break;
+                       case MATCH_FRONT_ONLY:
+                               if (memcmp(str, buff, match) == 0)
+                                       matched = 1;
+                               break;
+                       case MATCH_MIDDLE_ONLY:
+                               if (strstr(str, search))
+                                       matched = 1;
+                               break;
+                       case MATCH_END_ONLY:
+                               ptr = strstr(str, search);
+                               if (ptr && (ptr[search_len] == 0))
+                                       matched = 1;
+                               break;
+                       }
+                       if (matched)
+                               rec->flags |= flag;
+               }
+               pg = pg->next;
+       }
+       preempt_enable();
+}
+
+static ssize_t
+ftrace_regex_write(struct file *file, const char __user *ubuf,
+                  size_t cnt, loff_t *ppos, int enable)
+{
+       struct ftrace_iterator *iter;
+       char ch;
+       size_t read = 0;
+       ssize_t ret;
+
+       if (!cnt || cnt < 0)
+               return 0;
+
+       mutex_lock(&ftrace_regex_lock);
+
+       if (file->f_mode & FMODE_READ) {
+               struct seq_file *m = file->private_data;
+               iter = m->private;
+       } else
+               iter = file->private_data;
+
+       if (!*ppos) {
+               iter->flags &= ~FTRACE_ITER_CONT;
+               iter->buffer_idx = 0;
+       }
+
+       ret = get_user(ch, ubuf++);
+       if (ret)
+               goto out;
+       read++;
+       cnt--;
+
+       if (!(iter->flags & ~FTRACE_ITER_CONT)) {
+               /* skip white space */
+               while (cnt && isspace(ch)) {
+                       ret = get_user(ch, ubuf++);
+                       if (ret)
+                               goto out;
+                       read++;
+                       cnt--;
+               }
+
+               if (isspace(ch)) {
+                       file->f_pos += read;
+                       ret = read;
+                       goto out;
+               }
+
+               iter->buffer_idx = 0;
+       }
+
+       while (cnt && !isspace(ch)) {
+               if (iter->buffer_idx < FTRACE_BUFF_MAX)
+                       iter->buffer[iter->buffer_idx++] = ch;
+               else {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               ret = get_user(ch, ubuf++);
+               if (ret)
+                       goto out;
+               read++;
+               cnt--;
+       }
+
+       if (isspace(ch)) {
+               iter->filtered++;
+               iter->buffer[iter->buffer_idx] = 0;
+               ftrace_match(iter->buffer, iter->buffer_idx, enable);
+               iter->buffer_idx = 0;
+       } else
+               iter->flags |= FTRACE_ITER_CONT;
+
+
+       file->f_pos += read;
+
+       ret = read;
+ out:
+       mutex_unlock(&ftrace_regex_lock);
+
+       return ret;
+}
+
+static ssize_t
+ftrace_filter_write(struct file *file, const char __user *ubuf,
+                   size_t cnt, loff_t *ppos)
+{
+       return ftrace_regex_write(file, ubuf, cnt, ppos, 1);
+}
+
+static ssize_t
+ftrace_notrace_write(struct file *file, const char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       return ftrace_regex_write(file, ubuf, cnt, ppos, 0);
+}
+
+static void
+ftrace_set_regex(unsigned char *buf, int len, int reset, int enable)
+{
+       if (unlikely(ftrace_disabled))
+               return;
+
+       mutex_lock(&ftrace_regex_lock);
+       if (reset)
+               ftrace_filter_reset(enable);
+       if (buf)
+               ftrace_match(buf, len, enable);
+       mutex_unlock(&ftrace_regex_lock);
+}
+
+/**
+ * ftrace_set_filter - set a function to filter on in ftrace
+ * @buf - the string that holds the function filter text.
+ * @len - the length of the string.
+ * @reset - non zero to reset all filters before applying this filter.
+ *
+ * Filters denote which functions should be enabled when tracing is enabled.
+ * If @buf is NULL and reset is set, all functions will be enabled for tracing.
+ */
+void ftrace_set_filter(unsigned char *buf, int len, int reset)
+{
+       ftrace_set_regex(buf, len, reset, 1);
+}
+
+/**
+ * ftrace_set_notrace - set a function to not trace in ftrace
+ * @buf - the string that holds the function notrace text.
+ * @len - the length of the string.
+ * @reset - non zero to reset all filters before applying this filter.
+ *
+ * Notrace Filters denote which functions should not be enabled when tracing
+ * is enabled. If @buf is NULL and reset is set, all functions will be enabled
+ * for tracing.
+ */
+void ftrace_set_notrace(unsigned char *buf, int len, int reset)
+{
+       ftrace_set_regex(buf, len, reset, 0);
+}
+
+static int
+ftrace_regex_release(struct inode *inode, struct file *file, int enable)
+{
+       struct seq_file *m = (struct seq_file *)file->private_data;
+       struct ftrace_iterator *iter;
+
+       mutex_lock(&ftrace_regex_lock);
+       if (file->f_mode & FMODE_READ) {
+               iter = m->private;
+
+               seq_release(inode, file);
+       } else
+               iter = file->private_data;
+
+       if (iter->buffer_idx) {
+               iter->filtered++;
+               iter->buffer[iter->buffer_idx] = 0;
+               ftrace_match(iter->buffer, iter->buffer_idx, enable);
+       }
+
+       mutex_lock(&ftrace_sysctl_lock);
+       mutex_lock(&ftraced_lock);
+       if (iter->filtered && ftraced_suspend && ftrace_enabled)
+               ftrace_run_update_code(FTRACE_ENABLE_CALLS);
+       mutex_unlock(&ftraced_lock);
+       mutex_unlock(&ftrace_sysctl_lock);
+
+       kfree(iter);
+       mutex_unlock(&ftrace_regex_lock);
+       return 0;
+}
+
+static int
+ftrace_filter_release(struct inode *inode, struct file *file)
+{
+       return ftrace_regex_release(inode, file, 1);
+}
+
+static int
+ftrace_notrace_release(struct inode *inode, struct file *file)
+{
+       return ftrace_regex_release(inode, file, 0);
+}
+
+static ssize_t
+ftraced_read(struct file *filp, char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       /* don't worry about races */
+       char *buf = ftraced_stop ? "disabled\n" : "enabled\n";
+       int r = strlen(buf);
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+ftraced_write(struct file *filp, const char __user *ubuf,
+                     size_t cnt, loff_t *ppos)
+{
+       char buf[64];
+       long val;
+       int ret;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       if (strncmp(buf, "enable", 6) == 0)
+               val = 1;
+       else if (strncmp(buf, "disable", 7) == 0)
+               val = 0;
+       else {
+               buf[cnt] = 0;
+
+               ret = strict_strtoul(buf, 10, &val);
+               if (ret < 0)
+                       return ret;
+
+               val = !!val;
+       }
+
+       if (val)
+               ftrace_enable_daemon();
+       else
+               ftrace_disable_daemon();
+
+       filp->f_pos += cnt;
+
+       return cnt;
+}
+
+static struct file_operations ftrace_avail_fops = {
+       .open = ftrace_avail_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = ftrace_avail_release,
+};
+
+static struct file_operations ftrace_failures_fops = {
+       .open = ftrace_failures_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = ftrace_avail_release,
+};
+
+static struct file_operations ftrace_filter_fops = {
+       .open = ftrace_filter_open,
+       .read = ftrace_regex_read,
+       .write = ftrace_filter_write,
+       .llseek = ftrace_regex_lseek,
+       .release = ftrace_filter_release,
+};
+
+static struct file_operations ftrace_notrace_fops = {
+       .open = ftrace_notrace_open,
+       .read = ftrace_regex_read,
+       .write = ftrace_notrace_write,
+       .llseek = ftrace_regex_lseek,
+       .release = ftrace_notrace_release,
+};
+
+static struct file_operations ftraced_fops = {
+       .open = tracing_open_generic,
+       .read = ftraced_read,
+       .write = ftraced_write,
+};
+
+/**
+ * ftrace_force_update - force an update to all recording ftrace functions
+ */
+int ftrace_force_update(void)
+{
+       int ret = 0;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       mutex_lock(&ftrace_sysctl_lock);
+       mutex_lock(&ftraced_lock);
+
+       /*
+        * If ftraced_trigger is not set, then there is nothing
+        * to update.
+        */
+       if (ftraced_trigger && !ftrace_update_code())
+               ret = -EBUSY;
+
+       mutex_unlock(&ftraced_lock);
+       mutex_unlock(&ftrace_sysctl_lock);
+
+       return ret;
+}
+
+static void ftrace_force_shutdown(void)
+{
+       struct task_struct *task;
+       int command = FTRACE_DISABLE_CALLS | FTRACE_UPDATE_TRACE_FUNC;
+
+       mutex_lock(&ftraced_lock);
+       task = ftraced_task;
+       ftraced_task = NULL;
+       ftraced_suspend = -1;
+       ftrace_run_update_code(command);
+       mutex_unlock(&ftraced_lock);
+
+       if (task)
+               kthread_stop(task);
+}
+
+static __init int ftrace_init_debugfs(void)
+{
+       struct dentry *d_tracer;
+       struct dentry *entry;
+
+       d_tracer = tracing_init_dentry();
+
+       entry = debugfs_create_file("available_filter_functions", 0444,
+                                   d_tracer, NULL, &ftrace_avail_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'available_filter_functions' entry\n");
+
+       entry = debugfs_create_file("failures", 0444,
+                                   d_tracer, NULL, &ftrace_failures_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'failures' entry\n");
+
+       entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
+                                   NULL, &ftrace_filter_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'set_ftrace_filter' entry\n");
+
+       entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer,
+                                   NULL, &ftrace_notrace_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'set_ftrace_notrace' entry\n");
+
+       entry = debugfs_create_file("ftraced_enabled", 0644, d_tracer,
+                                   NULL, &ftraced_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'ftraced_enabled' entry\n");
+       return 0;
+}
+
+fs_initcall(ftrace_init_debugfs);
+
+static int __init ftrace_dynamic_init(void)
+{
+       struct task_struct *p;
+       unsigned long addr;
+       int ret;
+
+       addr = (unsigned long)ftrace_record_ip;
+
+       stop_machine_run(ftrace_dyn_arch_init, &addr, NR_CPUS);
+
+       /* ftrace_dyn_arch_init places the return code in addr */
+       if (addr) {
+               ret = (int)addr;
+               goto failed;
+       }
+
+       ret = ftrace_dyn_table_alloc();
+       if (ret)
+               goto failed;
+
+       p = kthread_run(ftraced, NULL, "ftraced");
+       if (IS_ERR(p)) {
+               ret = -1;
+               goto failed;
+       }
+
+       last_ftrace_enabled = ftrace_enabled = 1;
+       ftraced_task = p;
+
+       return 0;
+
+ failed:
+       ftrace_disabled = 1;
+       return ret;
+}
+
+core_initcall(ftrace_dynamic_init);
+#else
+# define ftrace_startup()              do { } while (0)
+# define ftrace_shutdown()             do { } while (0)
+# define ftrace_startup_sysctl()       do { } while (0)
+# define ftrace_shutdown_sysctl()      do { } while (0)
+# define ftrace_force_shutdown()       do { } while (0)
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
+/**
+ * ftrace_kill_atomic - kill ftrace from critical sections
+ *
+ * This function should be used by panic code. It stops ftrace
+ * but in a not so nice way. If you need to simply kill ftrace
+ * from a non-atomic section, use ftrace_kill.
+ */
+void ftrace_kill_atomic(void)
+{
+       ftrace_disabled = 1;
+       ftrace_enabled = 0;
+#ifdef CONFIG_DYNAMIC_FTRACE
+       ftraced_suspend = -1;
+#endif
+       clear_ftrace_function();
+}
+
+/**
+ * ftrace_kill - totally shutdown ftrace
+ *
+ * This is a safety measure. If something was detected that seems
+ * wrong, calling this function will keep ftrace from doing
+ * any more modifications, and updates.
+ * used when something went wrong.
+ */
+void ftrace_kill(void)
+{
+       mutex_lock(&ftrace_sysctl_lock);
+       ftrace_disabled = 1;
+       ftrace_enabled = 0;
+
+       clear_ftrace_function();
+       mutex_unlock(&ftrace_sysctl_lock);
+
+       /* Try to totally disable ftrace */
+       ftrace_force_shutdown();
+}
+
+/**
+ * register_ftrace_function - register a function for profiling
+ * @ops - ops structure that holds the function for profiling.
+ *
+ * Register a function to be called by all functions in the
+ * kernel.
+ *
+ * Note: @ops->func and all the functions it calls must be labeled
+ *       with "notrace", otherwise it will go into a
+ *       recursive loop.
+ */
+int register_ftrace_function(struct ftrace_ops *ops)
+{
+       int ret;
+
+       if (unlikely(ftrace_disabled))
+               return -1;
+
+       mutex_lock(&ftrace_sysctl_lock);
+       ret = __register_ftrace_function(ops);
+       ftrace_startup();
+       mutex_unlock(&ftrace_sysctl_lock);
+
+       return ret;
+}
+
+/**
+ * unregister_ftrace_function - unresgister a function for profiling.
+ * @ops - ops structure that holds the function to unregister
+ *
+ * Unregister a function that was added to be called by ftrace profiling.
+ */
+int unregister_ftrace_function(struct ftrace_ops *ops)
+{
+       int ret;
+
+       mutex_lock(&ftrace_sysctl_lock);
+       ret = __unregister_ftrace_function(ops);
+       ftrace_shutdown();
+       mutex_unlock(&ftrace_sysctl_lock);
+
+       return ret;
+}
+
+int
+ftrace_enable_sysctl(struct ctl_table *table, int write,
+                    struct file *file, void __user *buffer, size_t *lenp,
+                    loff_t *ppos)
+{
+       int ret;
+
+       if (unlikely(ftrace_disabled))
+               return -ENODEV;
+
+       mutex_lock(&ftrace_sysctl_lock);
+
+       ret  = proc_dointvec(table, write, file, buffer, lenp, ppos);
+
+       if (ret || !write || (last_ftrace_enabled == ftrace_enabled))
+               goto out;
+
+       last_ftrace_enabled = ftrace_enabled;
+
+       if (ftrace_enabled) {
+
+               ftrace_startup_sysctl();
+
+               /* we are starting ftrace again */
+               if (ftrace_list != &ftrace_list_end) {
+                       if (ftrace_list->next == &ftrace_list_end)
+                               ftrace_trace_function = ftrace_list->func;
+                       else
+                               ftrace_trace_function = ftrace_list_func;
+               }
+
+       } else {
+               /* stopping ftrace calls (just send to ftrace_stub) */
+               ftrace_trace_function = ftrace_stub;
+
+               ftrace_shutdown_sysctl();
+       }
+
+ out:
+       mutex_unlock(&ftrace_sysctl_lock);
+       return ret;
+}
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
new file mode 100644 (file)
index 0000000..868e121
--- /dev/null
@@ -0,0 +1,3161 @@
+/*
+ * ring buffer based function tracer
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
+ *
+ * Originally taken from the RT patch by:
+ *    Arnaldo Carvalho de Melo <acme@redhat.com>
+ *
+ * Based on code from the latency_tracer, that is:
+ *  Copyright (C) 2004-2006 Ingo Molnar
+ *  Copyright (C) 2004 William Lee Irwin III
+ */
+#include <linux/utsrelease.h>
+#include <linux/kallsyms.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+#include <linux/pagemap.h>
+#include <linux/hardirq.h>
+#include <linux/linkage.h>
+#include <linux/uaccess.h>
+#include <linux/ftrace.h>
+#include <linux/module.h>
+#include <linux/percpu.h>
+#include <linux/ctype.h>
+#include <linux/init.h>
+#include <linux/poll.h>
+#include <linux/gfp.h>
+#include <linux/fs.h>
+#include <linux/kprobes.h>
+#include <linux/writeback.h>
+
+#include <linux/stacktrace.h>
+
+#include "trace.h"
+
+unsigned long __read_mostly    tracing_max_latency = (cycle_t)ULONG_MAX;
+unsigned long __read_mostly    tracing_thresh;
+
+static unsigned long __read_mostly     tracing_nr_buffers;
+static cpumask_t __read_mostly         tracing_buffer_mask;
+
+#define for_each_tracing_cpu(cpu)      \
+       for_each_cpu_mask(cpu, tracing_buffer_mask)
+
+static int trace_alloc_page(void);
+static int trace_free_page(void);
+
+static int tracing_disabled = 1;
+
+static unsigned long tracing_pages_allocated;
+
+long
+ns2usecs(cycle_t nsec)
+{
+       nsec += 500;
+       do_div(nsec, 1000);
+       return nsec;
+}
+
+cycle_t ftrace_now(int cpu)
+{
+       return cpu_clock(cpu);
+}
+
+/*
+ * The global_trace is the descriptor that holds the tracing
+ * buffers for the live tracing. For each CPU, it contains
+ * a link list of pages that will store trace entries. The
+ * page descriptor of the pages in the memory is used to hold
+ * the link list by linking the lru item in the page descriptor
+ * to each of the pages in the buffer per CPU.
+ *
+ * For each active CPU there is a data field that holds the
+ * pages for the buffer for that CPU. Each CPU has the same number
+ * of pages allocated for its buffer.
+ */
+static struct trace_array      global_trace;
+
+static DEFINE_PER_CPU(struct trace_array_cpu, global_trace_cpu);
+
+/*
+ * The max_tr is used to snapshot the global_trace when a maximum
+ * latency is reached. Some tracers will use this to store a maximum
+ * trace while it continues examining live traces.
+ *
+ * The buffers for the max_tr are set up the same as the global_trace.
+ * When a snapshot is taken, the link list of the max_tr is swapped
+ * with the link list of the global_trace and the buffers are reset for
+ * the global_trace so the tracing can continue.
+ */
+static struct trace_array      max_tr;
+
+static DEFINE_PER_CPU(struct trace_array_cpu, max_data);
+
+/* tracer_enabled is used to toggle activation of a tracer */
+static int                     tracer_enabled = 1;
+
+/* function tracing enabled */
+int                            ftrace_function_enabled;
+
+/*
+ * trace_nr_entries is the number of entries that is allocated
+ * for a buffer. Note, the number of entries is always rounded
+ * to ENTRIES_PER_PAGE.
+ */
+static unsigned long           trace_nr_entries = 65536UL;
+
+/* trace_types holds a link list of available tracers. */
+static struct tracer           *trace_types __read_mostly;
+
+/* current_trace points to the tracer that is currently active */
+static struct tracer           *current_trace __read_mostly;
+
+/*
+ * max_tracer_type_len is used to simplify the allocating of
+ * buffers to read userspace tracer names. We keep track of
+ * the longest tracer name registered.
+ */
+static int                     max_tracer_type_len;
+
+/*
+ * trace_types_lock is used to protect the trace_types list.
+ * This lock is also used to keep user access serialized.
+ * Accesses from userspace will grab this lock while userspace
+ * activities happen inside the kernel.
+ */
+static DEFINE_MUTEX(trace_types_lock);
+
+/* trace_wait is a waitqueue for tasks blocked on trace_poll */
+static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
+
+/* trace_flags holds iter_ctrl options */
+unsigned long trace_flags = TRACE_ITER_PRINT_PARENT;
+
+static notrace void no_trace_init(struct trace_array *tr)
+{
+       int cpu;
+
+       ftrace_function_enabled = 0;
+       if(tr->ctrl)
+               for_each_online_cpu(cpu)
+                       tracing_reset(tr->data[cpu]);
+       tracer_enabled = 0;
+}
+
+/* dummy trace to disable tracing */
+static struct tracer no_tracer __read_mostly = {
+       .name           = "none",
+       .init           = no_trace_init
+};
+
+
+/**
+ * trace_wake_up - wake up tasks waiting for trace input
+ *
+ * Simply wakes up any task that is blocked on the trace_wait
+ * queue. These is used with trace_poll for tasks polling the trace.
+ */
+void trace_wake_up(void)
+{
+       /*
+        * The runqueue_is_locked() can fail, but this is the best we
+        * have for now:
+        */
+       if (!(trace_flags & TRACE_ITER_BLOCK) && !runqueue_is_locked())
+               wake_up(&trace_wait);
+}
+
+#define ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct trace_entry))
+
+static int __init set_nr_entries(char *str)
+{
+       unsigned long nr_entries;
+       int ret;
+
+       if (!str)
+               return 0;
+       ret = strict_strtoul(str, 0, &nr_entries);
+       /* nr_entries can not be zero */
+       if (ret < 0 || nr_entries == 0)
+               return 0;
+       trace_nr_entries = nr_entries;
+       return 1;
+}
+__setup("trace_entries=", set_nr_entries);
+
+unsigned long nsecs_to_usecs(unsigned long nsecs)
+{
+       return nsecs / 1000;
+}
+
+/*
+ * trace_flag_type is an enumeration that holds different
+ * states when a trace occurs. These are:
+ *  IRQS_OFF   - interrupts were disabled
+ *  NEED_RESCED - reschedule is requested
+ *  HARDIRQ    - inside an interrupt handler
+ *  SOFTIRQ    - inside a softirq handler
+ */
+enum trace_flag_type {
+       TRACE_FLAG_IRQS_OFF             = 0x01,
+       TRACE_FLAG_NEED_RESCHED         = 0x02,
+       TRACE_FLAG_HARDIRQ              = 0x04,
+       TRACE_FLAG_SOFTIRQ              = 0x08,
+};
+
+/*
+ * TRACE_ITER_SYM_MASK masks the options in trace_flags that
+ * control the output of kernel symbols.
+ */
+#define TRACE_ITER_SYM_MASK \
+       (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
+
+/* These must match the bit postions in trace_iterator_flags */
+static const char *trace_options[] = {
+       "print-parent",
+       "sym-offset",
+       "sym-addr",
+       "verbose",
+       "raw",
+       "hex",
+       "bin",
+       "block",
+       "stacktrace",
+       "sched-tree",
+       NULL
+};
+
+/*
+ * ftrace_max_lock is used to protect the swapping of buffers
+ * when taking a max snapshot. The buffers themselves are
+ * protected by per_cpu spinlocks. But the action of the swap
+ * needs its own lock.
+ *
+ * This is defined as a raw_spinlock_t in order to help
+ * with performance when lockdep debugging is enabled.
+ */
+static raw_spinlock_t ftrace_max_lock =
+       (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+
+/*
+ * Copy the new maximum trace into the separate maximum-trace
+ * structure. (this way the maximum trace is permanently saved,
+ * for later retrieval via /debugfs/tracing/latency_trace)
+ */
+static void
+__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
+{
+       struct trace_array_cpu *data = tr->data[cpu];
+
+       max_tr.cpu = cpu;
+       max_tr.time_start = data->preempt_timestamp;
+
+       data = max_tr.data[cpu];
+       data->saved_latency = tracing_max_latency;
+
+       memcpy(data->comm, tsk->comm, TASK_COMM_LEN);
+       data->pid = tsk->pid;
+       data->uid = tsk->uid;
+       data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
+       data->policy = tsk->policy;
+       data->rt_priority = tsk->rt_priority;
+
+       /* record this tasks comm */
+       tracing_record_cmdline(current);
+}
+
+#define CHECK_COND(cond)                       \
+       if (unlikely(cond)) {                   \
+               tracing_disabled = 1;           \
+               WARN_ON(1);                     \
+               return -1;                      \
+       }
+
+/**
+ * check_pages - integrity check of trace buffers
+ *
+ * As a safty measure we check to make sure the data pages have not
+ * been corrupted.
+ */
+int check_pages(struct trace_array_cpu *data)
+{
+       struct page *page, *tmp;
+
+       CHECK_COND(data->trace_pages.next->prev != &data->trace_pages);
+       CHECK_COND(data->trace_pages.prev->next != &data->trace_pages);
+
+       list_for_each_entry_safe(page, tmp, &data->trace_pages, lru) {
+               CHECK_COND(page->lru.next->prev != &page->lru);
+               CHECK_COND(page->lru.prev->next != &page->lru);
+       }
+
+       return 0;
+}
+
+/**
+ * head_page - page address of the first page in per_cpu buffer.
+ *
+ * head_page returns the page address of the first page in
+ * a per_cpu buffer. This also preforms various consistency
+ * checks to make sure the buffer has not been corrupted.
+ */
+void *head_page(struct trace_array_cpu *data)
+{
+       struct page *page;
+
+       if (list_empty(&data->trace_pages))
+               return NULL;
+
+       page = list_entry(data->trace_pages.next, struct page, lru);
+       BUG_ON(&page->lru == &data->trace_pages);
+
+       return page_address(page);
+}
+
+/**
+ * trace_seq_printf - sequence printing of trace information
+ * @s: trace sequence descriptor
+ * @fmt: printf format string
+ *
+ * The tracer may use either sequence operations or its own
+ * copy to user routines. To simplify formating of a trace
+ * trace_seq_printf is used to store strings into a special
+ * buffer (@s). Then the output may be either used by
+ * the sequencer or pulled into another buffer.
+ */
+int
+trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
+{
+       int len = (PAGE_SIZE - 1) - s->len;
+       va_list ap;
+       int ret;
+
+       if (!len)
+               return 0;
+
+       va_start(ap, fmt);
+       ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
+       va_end(ap);
+
+       /* If we can't write it all, don't bother writing anything */
+       if (ret >= len)
+               return 0;
+
+       s->len += ret;
+
+       return len;
+}
+
+/**
+ * trace_seq_puts - trace sequence printing of simple string
+ * @s: trace sequence descriptor
+ * @str: simple string to record
+ *
+ * The tracer may use either the sequence operations or its own
+ * copy to user routines. This function records a simple string
+ * into a special buffer (@s) for later retrieval by a sequencer
+ * or other mechanism.
+ */
+static int
+trace_seq_puts(struct trace_seq *s, const char *str)
+{
+       int len = strlen(str);
+
+       if (len > ((PAGE_SIZE - 1) - s->len))
+               return 0;
+
+       memcpy(s->buffer + s->len, str, len);
+       s->len += len;
+
+       return len;
+}
+
+static int
+trace_seq_putc(struct trace_seq *s, unsigned char c)
+{
+       if (s->len >= (PAGE_SIZE - 1))
+               return 0;
+
+       s->buffer[s->len++] = c;
+
+       return 1;
+}
+
+static int
+trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
+{
+       if (len > ((PAGE_SIZE - 1) - s->len))
+               return 0;
+
+       memcpy(s->buffer + s->len, mem, len);
+       s->len += len;
+
+       return len;
+}
+
+#define HEX_CHARS 17
+static const char hex2asc[] = "0123456789abcdef";
+
+static int
+trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
+{
+       unsigned char hex[HEX_CHARS];
+       unsigned char *data = mem;
+       unsigned char byte;
+       int i, j;
+
+       BUG_ON(len >= HEX_CHARS);
+
+#ifdef __BIG_ENDIAN
+       for (i = 0, j = 0; i < len; i++) {
+#else
+       for (i = len-1, j = 0; i >= 0; i--) {
+#endif
+               byte = data[i];
+
+               hex[j++] = hex2asc[byte & 0x0f];
+               hex[j++] = hex2asc[byte >> 4];
+       }
+       hex[j++] = ' ';
+
+       return trace_seq_putmem(s, hex, j);
+}
+
+static void
+trace_seq_reset(struct trace_seq *s)
+{
+       s->len = 0;
+       s->readpos = 0;
+}
+
+ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
+{
+       int len;
+       int ret;
+
+       if (s->len <= s->readpos)
+               return -EBUSY;
+
+       len = s->len - s->readpos;
+       if (cnt > len)
+               cnt = len;
+       ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
+       if (ret)
+               return -EFAULT;
+
+       s->readpos += len;
+       return cnt;
+}
+
+static void
+trace_print_seq(struct seq_file *m, struct trace_seq *s)
+{
+       int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
+
+       s->buffer[len] = 0;
+       seq_puts(m, s->buffer);
+
+       trace_seq_reset(s);
+}
+
+/*
+ * flip the trace buffers between two trace descriptors.
+ * This usually is the buffers between the global_trace and
+ * the max_tr to record a snapshot of a current trace.
+ *
+ * The ftrace_max_lock must be held.
+ */
+static void
+flip_trace(struct trace_array_cpu *tr1, struct trace_array_cpu *tr2)
+{
+       struct list_head flip_pages;
+
+       INIT_LIST_HEAD(&flip_pages);
+
+       memcpy(&tr1->trace_head_idx, &tr2->trace_head_idx,
+               sizeof(struct trace_array_cpu) -
+               offsetof(struct trace_array_cpu, trace_head_idx));
+
+       check_pages(tr1);
+       check_pages(tr2);
+       list_splice_init(&tr1->trace_pages, &flip_pages);
+       list_splice_init(&tr2->trace_pages, &tr1->trace_pages);
+       list_splice_init(&flip_pages, &tr2->trace_pages);
+       BUG_ON(!list_empty(&flip_pages));
+       check_pages(tr1);
+       check_pages(tr2);
+}
+
+/**
+ * update_max_tr - snapshot all trace buffers from global_trace to max_tr
+ * @tr: tracer
+ * @tsk: the task with the latency
+ * @cpu: The cpu that initiated the trace.
+ *
+ * Flip the buffers between the @tr and the max_tr and record information
+ * about which task was the cause of this latency.
+ */
+void
+update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
+{
+       struct trace_array_cpu *data;
+       int i;
+
+       WARN_ON_ONCE(!irqs_disabled());
+       __raw_spin_lock(&ftrace_max_lock);
+       /* clear out all the previous traces */
+       for_each_tracing_cpu(i) {
+               data = tr->data[i];
+               flip_trace(max_tr.data[i], data);
+               tracing_reset(data);
+       }
+
+       __update_max_tr(tr, tsk, cpu);
+       __raw_spin_unlock(&ftrace_max_lock);
+}
+
+/**
+ * update_max_tr_single - only copy one trace over, and reset the rest
+ * @tr - tracer
+ * @tsk - task with the latency
+ * @cpu - the cpu of the buffer to copy.
+ *
+ * Flip the trace of a single CPU buffer between the @tr and the max_tr.
+ */
+void
+update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
+{
+       struct trace_array_cpu *data = tr->data[cpu];
+       int i;
+
+       WARN_ON_ONCE(!irqs_disabled());
+       __raw_spin_lock(&ftrace_max_lock);
+       for_each_tracing_cpu(i)
+               tracing_reset(max_tr.data[i]);
+
+       flip_trace(max_tr.data[cpu], data);
+       tracing_reset(data);
+
+       __update_max_tr(tr, tsk, cpu);
+       __raw_spin_unlock(&ftrace_max_lock);
+}
+
+/**
+ * register_tracer - register a tracer with the ftrace system.
+ * @type - the plugin for the tracer
+ *
+ * Register a new plugin tracer.
+ */
+int register_tracer(struct tracer *type)
+{
+       struct tracer *t;
+       int len;
+       int ret = 0;
+
+       if (!type->name) {
+               pr_info("Tracer must have a name\n");
+               return -1;
+       }
+
+       mutex_lock(&trace_types_lock);
+       for (t = trace_types; t; t = t->next) {
+               if (strcmp(type->name, t->name) == 0) {
+                       /* already found */
+                       pr_info("Trace %s already registered\n",
+                               type->name);
+                       ret = -1;
+                       goto out;
+               }
+       }
+
+#ifdef CONFIG_FTRACE_STARTUP_TEST
+       if (type->selftest) {
+               struct tracer *saved_tracer = current_trace;
+               struct trace_array_cpu *data;
+               struct trace_array *tr = &global_trace;
+               int saved_ctrl = tr->ctrl;
+               int i;
+               /*
+                * Run a selftest on this tracer.
+                * Here we reset the trace buffer, and set the current
+                * tracer to be this tracer. The tracer can then run some
+                * internal tracing to verify that everything is in order.
+                * If we fail, we do not register this tracer.
+                */
+               for_each_tracing_cpu(i) {
+                       data = tr->data[i];
+                       if (!head_page(data))
+                               continue;
+                       tracing_reset(data);
+               }
+               current_trace = type;
+               tr->ctrl = 0;
+               /* the test is responsible for initializing and enabling */
+               pr_info("Testing tracer %s: ", type->name);
+               ret = type->selftest(type, tr);
+               /* the test is responsible for resetting too */
+               current_trace = saved_tracer;
+               tr->ctrl = saved_ctrl;
+               if (ret) {
+                       printk(KERN_CONT "FAILED!\n");
+                       goto out;
+               }
+               /* Only reset on passing, to avoid touching corrupted buffers */
+               for_each_tracing_cpu(i) {
+                       data = tr->data[i];
+                       if (!head_page(data))
+                               continue;
+                       tracing_reset(data);
+               }
+               printk(KERN_CONT "PASSED\n");
+       }
+#endif
+
+       type->next = trace_types;
+       trace_types = type;
+       len = strlen(type->name);
+       if (len > max_tracer_type_len)
+               max_tracer_type_len = len;
+
+ out:
+       mutex_unlock(&trace_types_lock);
+
+       return ret;
+}
+
+void unregister_tracer(struct tracer *type)
+{
+       struct tracer **t;
+       int len;
+
+       mutex_lock(&trace_types_lock);
+       for (t = &trace_types; *t; t = &(*t)->next) {
+               if (*t == type)
+                       goto found;
+       }
+       pr_info("Trace %s not registered\n", type->name);
+       goto out;
+
+ found:
+       *t = (*t)->next;
+       if (strlen(type->name) != max_tracer_type_len)
+               goto out;
+
+       max_tracer_type_len = 0;
+       for (t = &trace_types; *t; t = &(*t)->next) {
+               len = strlen((*t)->name);
+               if (len > max_tracer_type_len)
+                       max_tracer_type_len = len;
+       }
+ out:
+       mutex_unlock(&trace_types_lock);
+}
+
+void tracing_reset(struct trace_array_cpu *data)
+{
+       data->trace_idx = 0;
+       data->overrun = 0;
+       data->trace_head = data->trace_tail = head_page(data);
+       data->trace_head_idx = 0;
+       data->trace_tail_idx = 0;
+}
+
+#define SAVED_CMDLINES 128
+static unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
+static unsigned map_cmdline_to_pid[SAVED_CMDLINES];
+static char saved_cmdlines[SAVED_CMDLINES][TASK_COMM_LEN];
+static int cmdline_idx;
+static DEFINE_SPINLOCK(trace_cmdline_lock);
+
+/* temporary disable recording */
+atomic_t trace_record_cmdline_disabled __read_mostly;
+
+static void trace_init_cmdlines(void)
+{
+       memset(&map_pid_to_cmdline, -1, sizeof(map_pid_to_cmdline));
+       memset(&map_cmdline_to_pid, -1, sizeof(map_cmdline_to_pid));
+       cmdline_idx = 0;
+}
+
+void trace_stop_cmdline_recording(void);
+
+static void trace_save_cmdline(struct task_struct *tsk)
+{
+       unsigned map;
+       unsigned idx;
+
+       if (!tsk->pid || unlikely(tsk->pid > PID_MAX_DEFAULT))
+               return;
+
+       /*
+        * It's not the end of the world if we don't get
+        * the lock, but we also don't want to spin
+        * nor do we want to disable interrupts,
+        * so if we miss here, then better luck next time.
+        */
+       if (!spin_trylock(&trace_cmdline_lock))
+               return;
+
+       idx = map_pid_to_cmdline[tsk->pid];
+       if (idx >= SAVED_CMDLINES) {
+               idx = (cmdline_idx + 1) % SAVED_CMDLINES;
+
+               map = map_cmdline_to_pid[idx];
+               if (map <= PID_MAX_DEFAULT)
+                       map_pid_to_cmdline[map] = (unsigned)-1;
+
+               map_pid_to_cmdline[tsk->pid] = idx;
+
+               cmdline_idx = idx;
+       }
+
+       memcpy(&saved_cmdlines[idx], tsk->comm, TASK_COMM_LEN);
+
+       spin_unlock(&trace_cmdline_lock);
+}
+
+static char *trace_find_cmdline(int pid)
+{
+       char *cmdline = "<...>";
+       unsigned map;
+
+       if (!pid)
+               return "<idle>";
+
+       if (pid > PID_MAX_DEFAULT)
+               goto out;
+
+       map = map_pid_to_cmdline[pid];
+       if (map >= SAVED_CMDLINES)
+               goto out;
+
+       cmdline = saved_cmdlines[map];
+
+ out:
+       return cmdline;
+}
+
+void tracing_record_cmdline(struct task_struct *tsk)
+{
+       if (atomic_read(&trace_record_cmdline_disabled))
+               return;
+
+       trace_save_cmdline(tsk);
+}
+
+static inline struct list_head *
+trace_next_list(struct trace_array_cpu *data, struct list_head *next)
+{
+       /*
+        * Roundrobin - but skip the head (which is not a real page):
+        */
+       next = next->next;
+       if (unlikely(next == &data->trace_pages))
+               next = next->next;
+       BUG_ON(next == &data->trace_pages);
+
+       return next;
+}
+
+static inline void *
+trace_next_page(struct trace_array_cpu *data, void *addr)
+{
+       struct list_head *next;
+       struct page *page;
+
+       page = virt_to_page(addr);
+
+       next = trace_next_list(data, &page->lru);
+       page = list_entry(next, struct page, lru);
+
+       return page_address(page);
+}
+
+static inline struct trace_entry *
+tracing_get_trace_entry(struct trace_array *tr, struct trace_array_cpu *data)
+{
+       unsigned long idx, idx_next;
+       struct trace_entry *entry;
+
+       data->trace_idx++;
+       idx = data->trace_head_idx;
+       idx_next = idx + 1;
+
+       BUG_ON(idx * TRACE_ENTRY_SIZE >= PAGE_SIZE);
+
+       entry = data->trace_head + idx * TRACE_ENTRY_SIZE;
+
+       if (unlikely(idx_next >= ENTRIES_PER_PAGE)) {
+               data->trace_head = trace_next_page(data, data->trace_head);
+               idx_next = 0;
+       }
+
+       if (data->trace_head == data->trace_tail &&
+           idx_next == data->trace_tail_idx) {
+               /* overrun */
+               data->overrun++;
+               data->trace_tail_idx++;
+               if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
+                       data->trace_tail =
+                               trace_next_page(data, data->trace_tail);
+                       data->trace_tail_idx = 0;
+               }
+       }
+
+       data->trace_head_idx = idx_next;
+
+       return entry;
+}
+
+static inline void
+tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags)
+{
+       struct task_struct *tsk = current;
+       unsigned long pc;
+
+       pc = preempt_count();
+
+       entry->preempt_count    = pc & 0xff;
+       entry->pid              = (tsk) ? tsk->pid : 0;
+       entry->t                = ftrace_now(raw_smp_processor_id());
+       entry->flags = (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
+               ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
+               ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
+               (need_resched() ? TRACE_FLAG_NEED_RESCHED : 0);
+}
+
+void
+trace_function(struct trace_array *tr, struct trace_array_cpu *data,
+              unsigned long ip, unsigned long parent_ip, unsigned long flags)
+{
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, flags);
+       entry->type             = TRACE_FN;
+       entry->fn.ip            = ip;
+       entry->fn.parent_ip     = parent_ip;
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+}
+
+void
+ftrace(struct trace_array *tr, struct trace_array_cpu *data,
+       unsigned long ip, unsigned long parent_ip, unsigned long flags)
+{
+       if (likely(!atomic_read(&data->disabled)))
+               trace_function(tr, data, ip, parent_ip, flags);
+}
+
+#ifdef CONFIG_MMIOTRACE
+void __trace_mmiotrace_rw(struct trace_array *tr, struct trace_array_cpu *data,
+                                               struct mmiotrace_rw *rw)
+{
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, 0);
+       entry->type             = TRACE_MMIO_RW;
+       entry->mmiorw           = *rw;
+
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+
+       trace_wake_up();
+}
+
+void __trace_mmiotrace_map(struct trace_array *tr, struct trace_array_cpu *data,
+                                               struct mmiotrace_map *map)
+{
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, 0);
+       entry->type             = TRACE_MMIO_MAP;
+       entry->mmiomap          = *map;
+
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+
+       trace_wake_up();
+}
+#endif
+
+void __trace_stack(struct trace_array *tr,
+                  struct trace_array_cpu *data,
+                  unsigned long flags,
+                  int skip)
+{
+       struct trace_entry *entry;
+       struct stack_trace trace;
+
+       if (!(trace_flags & TRACE_ITER_STACKTRACE))
+               return;
+
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, flags);
+       entry->type             = TRACE_STACK;
+
+       memset(&entry->stack, 0, sizeof(entry->stack));
+
+       trace.nr_entries        = 0;
+       trace.max_entries       = FTRACE_STACK_ENTRIES;
+       trace.skip              = skip;
+       trace.entries           = entry->stack.caller;
+
+       save_stack_trace(&trace);
+}
+
+void
+__trace_special(void *__tr, void *__data,
+               unsigned long arg1, unsigned long arg2, unsigned long arg3)
+{
+       struct trace_array_cpu *data = __data;
+       struct trace_array *tr = __tr;
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, 0);
+       entry->type             = TRACE_SPECIAL;
+       entry->special.arg1     = arg1;
+       entry->special.arg2     = arg2;
+       entry->special.arg3     = arg3;
+       __trace_stack(tr, data, irq_flags, 4);
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+
+       trace_wake_up();
+}
+
+void
+tracing_sched_switch_trace(struct trace_array *tr,
+                          struct trace_array_cpu *data,
+                          struct task_struct *prev,
+                          struct task_struct *next,
+                          unsigned long flags)
+{
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, flags);
+       entry->type             = TRACE_CTX;
+       entry->ctx.prev_pid     = prev->pid;
+       entry->ctx.prev_prio    = prev->prio;
+       entry->ctx.prev_state   = prev->state;
+       entry->ctx.next_pid     = next->pid;
+       entry->ctx.next_prio    = next->prio;
+       entry->ctx.next_state   = next->state;
+       __trace_stack(tr, data, flags, 5);
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+}
+
+void
+tracing_sched_wakeup_trace(struct trace_array *tr,
+                          struct trace_array_cpu *data,
+                          struct task_struct *wakee,
+                          struct task_struct *curr,
+                          unsigned long flags)
+{
+       struct trace_entry *entry;
+       unsigned long irq_flags;
+
+       raw_local_irq_save(irq_flags);
+       __raw_spin_lock(&data->lock);
+       entry                   = tracing_get_trace_entry(tr, data);
+       tracing_generic_entry_update(entry, flags);
+       entry->type             = TRACE_WAKE;
+       entry->ctx.prev_pid     = curr->pid;
+       entry->ctx.prev_prio    = curr->prio;
+       entry->ctx.prev_state   = curr->state;
+       entry->ctx.next_pid     = wakee->pid;
+       entry->ctx.next_prio    = wakee->prio;
+       entry->ctx.next_state   = wakee->state;
+       __trace_stack(tr, data, flags, 6);
+       __raw_spin_unlock(&data->lock);
+       raw_local_irq_restore(irq_flags);
+
+       trace_wake_up();
+}
+
+void
+ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
+{
+       struct trace_array *tr = &global_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       if (tracing_disabled || current_trace == &no_tracer || !tr->ctrl)
+               return;
+
+       local_irq_save(flags);
+       cpu = raw_smp_processor_id();
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1))
+               __trace_special(tr, data, arg1, arg2, arg3);
+
+       atomic_dec(&data->disabled);
+       local_irq_restore(flags);
+}
+
+#ifdef CONFIG_FTRACE
+static void
+function_trace_call(unsigned long ip, unsigned long parent_ip)
+{
+       struct trace_array *tr = &global_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       if (unlikely(!ftrace_function_enabled))
+               return;
+
+       if (skip_trace(ip))
+               return;
+
+       local_irq_save(flags);
+       cpu = raw_smp_processor_id();
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1))
+               trace_function(tr, data, ip, parent_ip, flags);
+
+       atomic_dec(&data->disabled);
+       local_irq_restore(flags);
+}
+
+static struct ftrace_ops trace_ops __read_mostly =
+{
+       .func = function_trace_call,
+};
+
+void tracing_start_function_trace(void)
+{
+       ftrace_function_enabled = 0;
+       register_ftrace_function(&trace_ops);
+       if (tracer_enabled)
+               ftrace_function_enabled = 1;
+}
+
+void tracing_stop_function_trace(void)
+{
+       ftrace_function_enabled = 0;
+       unregister_ftrace_function(&trace_ops);
+}
+#endif
+
+enum trace_file_type {
+       TRACE_FILE_LAT_FMT      = 1,
+};
+
+static struct trace_entry *
+trace_entry_idx(struct trace_array *tr, struct trace_array_cpu *data,
+               struct trace_iterator *iter, int cpu)
+{
+       struct page *page;
+       struct trace_entry *array;
+
+       if (iter->next_idx[cpu] >= tr->entries ||
+           iter->next_idx[cpu] >= data->trace_idx ||
+           (data->trace_head == data->trace_tail &&
+            data->trace_head_idx == data->trace_tail_idx))
+               return NULL;
+
+       if (!iter->next_page[cpu]) {
+               /* Initialize the iterator for this cpu trace buffer */
+               WARN_ON(!data->trace_tail);
+               page = virt_to_page(data->trace_tail);
+               iter->next_page[cpu] = &page->lru;
+               iter->next_page_idx[cpu] = data->trace_tail_idx;
+       }
+
+       page = list_entry(iter->next_page[cpu], struct page, lru);
+       BUG_ON(&data->trace_pages == &page->lru);
+
+       array = page_address(page);
+
+       WARN_ON(iter->next_page_idx[cpu] >= ENTRIES_PER_PAGE);
+       return &array[iter->next_page_idx[cpu]];
+}
+
+static struct trace_entry *
+find_next_entry(struct trace_iterator *iter, int *ent_cpu)
+{
+       struct trace_array *tr = iter->tr;
+       struct trace_entry *ent, *next = NULL;
+       int next_cpu = -1;
+       int cpu;
+
+       for_each_tracing_cpu(cpu) {
+               if (!head_page(tr->data[cpu]))
+                       continue;
+               ent = trace_entry_idx(tr, tr->data[cpu], iter, cpu);
+               /*
+                * Pick the entry with the smallest timestamp:
+                */
+               if (ent && (!next || ent->t < next->t)) {
+                       next = ent;
+                       next_cpu = cpu;
+               }
+       }
+
+       if (ent_cpu)
+               *ent_cpu = next_cpu;
+
+       return next;
+}
+
+static void trace_iterator_increment(struct trace_iterator *iter)
+{
+       iter->idx++;
+       iter->next_idx[iter->cpu]++;
+       iter->next_page_idx[iter->cpu]++;
+
+       if (iter->next_page_idx[iter->cpu] >= ENTRIES_PER_PAGE) {
+               struct trace_array_cpu *data = iter->tr->data[iter->cpu];
+
+               iter->next_page_idx[iter->cpu] = 0;
+               iter->next_page[iter->cpu] =
+                       trace_next_list(data, iter->next_page[iter->cpu]);
+       }
+}
+
+static void trace_consume(struct trace_iterator *iter)
+{
+       struct trace_array_cpu *data = iter->tr->data[iter->cpu];
+
+       data->trace_tail_idx++;
+       if (data->trace_tail_idx >= ENTRIES_PER_PAGE) {
+               data->trace_tail = trace_next_page(data, data->trace_tail);
+               data->trace_tail_idx = 0;
+       }
+
+       /* Check if we empty it, then reset the index */
+       if (data->trace_head == data->trace_tail &&
+           data->trace_head_idx == data->trace_tail_idx)
+               data->trace_idx = 0;
+}
+
+static void *find_next_entry_inc(struct trace_iterator *iter)
+{
+       struct trace_entry *next;
+       int next_cpu = -1;
+
+       next = find_next_entry(iter, &next_cpu);
+
+       iter->prev_ent = iter->ent;
+       iter->prev_cpu = iter->cpu;
+
+       iter->ent = next;
+       iter->cpu = next_cpu;
+
+       if (next)
+               trace_iterator_increment(iter);
+
+       return next ? iter : NULL;
+}
+
+static void *s_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       struct trace_iterator *iter = m->private;
+       void *last_ent = iter->ent;
+       int i = (int)*pos;
+       void *ent;
+
+       (*pos)++;
+
+       /* can't go backwards */
+       if (iter->idx > i)
+               return NULL;
+
+       if (iter->idx < 0)
+               ent = find_next_entry_inc(iter);
+       else
+               ent = iter;
+
+       while (ent && iter->idx < i)
+               ent = find_next_entry_inc(iter);
+
+       iter->pos = *pos;
+
+       if (last_ent && !ent)
+               seq_puts(m, "\n\nvim:ft=help\n");
+
+       return ent;
+}
+
+static void *s_start(struct seq_file *m, loff_t *pos)
+{
+       struct trace_iterator *iter = m->private;
+       void *p = NULL;
+       loff_t l = 0;
+       int i;
+
+       mutex_lock(&trace_types_lock);
+
+       if (!current_trace || current_trace != iter->trace) {
+               mutex_unlock(&trace_types_lock);
+               return NULL;
+       }
+
+       atomic_inc(&trace_record_cmdline_disabled);
+
+       /* let the tracer grab locks here if needed */
+       if (current_trace->start)
+               current_trace->start(iter);
+
+       if (*pos != iter->pos) {
+               iter->ent = NULL;
+               iter->cpu = 0;
+               iter->idx = -1;
+               iter->prev_ent = NULL;
+               iter->prev_cpu = -1;
+
+               for_each_tracing_cpu(i) {
+                       iter->next_idx[i] = 0;
+                       iter->next_page[i] = NULL;
+               }
+
+               for (p = iter; p && l < *pos; p = s_next(m, p, &l))
+                       ;
+
+       } else {
+               l = *pos - 1;
+               p = s_next(m, p, &l);
+       }
+
+       return p;
+}
+
+static void s_stop(struct seq_file *m, void *p)
+{
+       struct trace_iterator *iter = m->private;
+
+       atomic_dec(&trace_record_cmdline_disabled);
+
+       /* let the tracer release locks here if needed */
+       if (current_trace && current_trace == iter->trace && iter->trace->stop)
+               iter->trace->stop(iter);
+
+       mutex_unlock(&trace_types_lock);
+}
+
+#define KRETPROBE_MSG "[unknown/kretprobe'd]"
+
+#ifdef CONFIG_KRETPROBES
+static inline int kretprobed(unsigned long addr)
+{
+       return addr == (unsigned long)kretprobe_trampoline;
+}
+#else
+static inline int kretprobed(unsigned long addr)
+{
+       return 0;
+}
+#endif /* CONFIG_KRETPROBES */
+
+static int
+seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
+{
+#ifdef CONFIG_KALLSYMS
+       char str[KSYM_SYMBOL_LEN];
+
+       kallsyms_lookup(address, NULL, NULL, NULL, str);
+
+       return trace_seq_printf(s, fmt, str);
+#endif
+       return 1;
+}
+
+static int
+seq_print_sym_offset(struct trace_seq *s, const char *fmt,
+                    unsigned long address)
+{
+#ifdef CONFIG_KALLSYMS
+       char str[KSYM_SYMBOL_LEN];
+
+       sprint_symbol(str, address);
+       return trace_seq_printf(s, fmt, str);
+#endif
+       return 1;
+}
+
+#ifndef CONFIG_64BIT
+# define IP_FMT "%08lx"
+#else
+# define IP_FMT "%016lx"
+#endif
+
+static int
+seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
+{
+       int ret;
+
+       if (!ip)
+               return trace_seq_printf(s, "0");
+
+       if (sym_flags & TRACE_ITER_SYM_OFFSET)
+               ret = seq_print_sym_offset(s, "%s", ip);
+       else
+               ret = seq_print_sym_short(s, "%s", ip);
+
+       if (!ret)
+               return 0;
+
+       if (sym_flags & TRACE_ITER_SYM_ADDR)
+               ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
+       return ret;
+}
+
+static void print_lat_help_header(struct seq_file *m)
+{
+       seq_puts(m, "#                _------=> CPU#            \n");
+       seq_puts(m, "#               / _-----=> irqs-off        \n");
+       seq_puts(m, "#              | / _----=> need-resched    \n");
+       seq_puts(m, "#              || / _---=> hardirq/softirq \n");
+       seq_puts(m, "#              ||| / _--=> preempt-depth   \n");
+       seq_puts(m, "#              |||| /                      \n");
+       seq_puts(m, "#              |||||     delay             \n");
+       seq_puts(m, "#  cmd     pid ||||| time  |   caller      \n");
+       seq_puts(m, "#     \\   /    |||||   \\   |   /           \n");
+}
+
+static void print_func_help_header(struct seq_file *m)
+{
+       seq_puts(m, "#           TASK-PID   CPU#    TIMESTAMP  FUNCTION\n");
+       seq_puts(m, "#              | |      |          |         |\n");
+}
+
+
+static void
+print_trace_header(struct seq_file *m, struct trace_iterator *iter)
+{
+       unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
+       struct trace_array *tr = iter->tr;
+       struct trace_array_cpu *data = tr->data[tr->cpu];
+       struct tracer *type = current_trace;
+       unsigned long total   = 0;
+       unsigned long entries = 0;
+       int cpu;
+       const char *name = "preemption";
+
+       if (type)
+               name = type->name;
+
+       for_each_tracing_cpu(cpu) {
+               if (head_page(tr->data[cpu])) {
+                       total += tr->data[cpu]->trace_idx;
+                       if (tr->data[cpu]->trace_idx > tr->entries)
+                               entries += tr->entries;
+                       else
+                               entries += tr->data[cpu]->trace_idx;
+               }
+       }
+
+       seq_printf(m, "%s latency trace v1.1.5 on %s\n",
+                  name, UTS_RELEASE);
+       seq_puts(m, "-----------------------------------"
+                "---------------------------------\n");
+       seq_printf(m, " latency: %lu us, #%lu/%lu, CPU#%d |"
+                  " (M:%s VP:%d, KP:%d, SP:%d HP:%d",
+                  nsecs_to_usecs(data->saved_latency),
+                  entries,
+                  total,
+                  tr->cpu,
+#if defined(CONFIG_PREEMPT_NONE)
+                  "server",
+#elif defined(CONFIG_PREEMPT_VOLUNTARY)
+                  "desktop",
+#elif defined(CONFIG_PREEMPT)
+                  "preempt",
+#else
+                  "unknown",
+#endif
+                  /* These are reserved for later use */
+                  0, 0, 0, 0);
+#ifdef CONFIG_SMP
+       seq_printf(m, " #P:%d)\n", num_online_cpus());
+#else
+       seq_puts(m, ")\n");
+#endif
+       seq_puts(m, "    -----------------\n");
+       seq_printf(m, "    | task: %.16s-%d "
+                  "(uid:%d nice:%ld policy:%ld rt_prio:%ld)\n",
+                  data->comm, data->pid, data->uid, data->nice,
+                  data->policy, data->rt_priority);
+       seq_puts(m, "    -----------------\n");
+
+       if (data->critical_start) {
+               seq_puts(m, " => started at: ");
+               seq_print_ip_sym(&iter->seq, data->critical_start, sym_flags);
+               trace_print_seq(m, &iter->seq);
+               seq_puts(m, "\n => ended at:   ");
+               seq_print_ip_sym(&iter->seq, data->critical_end, sym_flags);
+               trace_print_seq(m, &iter->seq);
+               seq_puts(m, "\n");
+       }
+
+       seq_puts(m, "\n");
+}
+
+static void
+lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
+{
+       int hardirq, softirq;
+       char *comm;
+
+       comm = trace_find_cmdline(entry->pid);
+
+       trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
+       trace_seq_printf(s, "%d", cpu);
+       trace_seq_printf(s, "%c%c",
+                       (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : '.',
+                       ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
+
+       hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
+       softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
+       if (hardirq && softirq) {
+               trace_seq_putc(s, 'H');
+       } else {
+               if (hardirq) {
+                       trace_seq_putc(s, 'h');
+               } else {
+                       if (softirq)
+                               trace_seq_putc(s, 's');
+                       else
+                               trace_seq_putc(s, '.');
+               }
+       }
+
+       if (entry->preempt_count)
+               trace_seq_printf(s, "%x", entry->preempt_count);
+       else
+               trace_seq_puts(s, ".");
+}
+
+unsigned long preempt_mark_thresh = 100;
+
+static void
+lat_print_timestamp(struct trace_seq *s, unsigned long long abs_usecs,
+                   unsigned long rel_usecs)
+{
+       trace_seq_printf(s, " %4lldus", abs_usecs);
+       if (rel_usecs > preempt_mark_thresh)
+               trace_seq_puts(s, "!: ");
+       else if (rel_usecs > 1)
+               trace_seq_puts(s, "+: ");
+       else
+               trace_seq_puts(s, " : ");
+}
+
+static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
+
+static int
+print_lat_fmt(struct trace_iterator *iter, unsigned int trace_idx, int cpu)
+{
+       struct trace_seq *s = &iter->seq;
+       unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
+       struct trace_entry *next_entry = find_next_entry(iter, NULL);
+       unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
+       struct trace_entry *entry = iter->ent;
+       unsigned long abs_usecs;
+       unsigned long rel_usecs;
+       char *comm;
+       int S, T;
+       int i;
+       unsigned state;
+
+       if (!next_entry)
+               next_entry = entry;
+       rel_usecs = ns2usecs(next_entry->t - entry->t);
+       abs_usecs = ns2usecs(entry->t - iter->tr->time_start);
+
+       if (verbose) {
+               comm = trace_find_cmdline(entry->pid);
+               trace_seq_printf(s, "%16s %5d %d %d %08x %08x [%08lx]"
+                                " %ld.%03ldms (+%ld.%03ldms): ",
+                                comm,
+                                entry->pid, cpu, entry->flags,
+                                entry->preempt_count, trace_idx,
+                                ns2usecs(entry->t),
+                                abs_usecs/1000,
+                                abs_usecs % 1000, rel_usecs/1000,
+                                rel_usecs % 1000);
+       } else {
+               lat_print_generic(s, entry, cpu);
+               lat_print_timestamp(s, abs_usecs, rel_usecs);
+       }
+       switch (entry->type) {
+       case TRACE_FN:
+               seq_print_ip_sym(s, entry->fn.ip, sym_flags);
+               trace_seq_puts(s, " (");
+               if (kretprobed(entry->fn.parent_ip))
+                       trace_seq_puts(s, KRETPROBE_MSG);
+               else
+                       seq_print_ip_sym(s, entry->fn.parent_ip, sym_flags);
+               trace_seq_puts(s, ")\n");
+               break;
+       case TRACE_CTX:
+       case TRACE_WAKE:
+               T = entry->ctx.next_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.next_state] : 'X';
+
+               state = entry->ctx.prev_state ? __ffs(entry->ctx.prev_state) + 1 : 0;
+               S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
+               comm = trace_find_cmdline(entry->ctx.next_pid);
+               trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c %s\n",
+                                entry->ctx.prev_pid,
+                                entry->ctx.prev_prio,
+                                S, entry->type == TRACE_CTX ? "==>" : "  +",
+                                entry->ctx.next_pid,
+                                entry->ctx.next_prio,
+                                T, comm);
+               break;
+       case TRACE_SPECIAL:
+               trace_seq_printf(s, "# %ld %ld %ld\n",
+                                entry->special.arg1,
+                                entry->special.arg2,
+                                entry->special.arg3);
+               break;
+       case TRACE_STACK:
+               for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
+                       if (i)
+                               trace_seq_puts(s, " <= ");
+                       seq_print_ip_sym(s, entry->stack.caller[i], sym_flags);
+               }
+               trace_seq_puts(s, "\n");
+               break;
+       default:
+               trace_seq_printf(s, "Unknown type %d\n", entry->type);
+       }
+       return 1;
+}
+
+static int print_trace_fmt(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
+       struct trace_entry *entry;
+       unsigned long usec_rem;
+       unsigned long long t;
+       unsigned long secs;
+       char *comm;
+       int ret;
+       int S, T;
+       int i;
+
+       entry = iter->ent;
+
+       comm = trace_find_cmdline(iter->ent->pid);
+
+       t = ns2usecs(entry->t);
+       usec_rem = do_div(t, 1000000ULL);
+       secs = (unsigned long)t;
+
+       ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
+       if (!ret)
+               return 0;
+       ret = trace_seq_printf(s, "[%02d] ", iter->cpu);
+       if (!ret)
+               return 0;
+       ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
+       if (!ret)
+               return 0;
+
+       switch (entry->type) {
+       case TRACE_FN:
+               ret = seq_print_ip_sym(s, entry->fn.ip, sym_flags);
+               if (!ret)
+                       return 0;
+               if ((sym_flags & TRACE_ITER_PRINT_PARENT) &&
+                                               entry->fn.parent_ip) {
+                       ret = trace_seq_printf(s, " <-");
+                       if (!ret)
+                               return 0;
+                       if (kretprobed(entry->fn.parent_ip))
+                               ret = trace_seq_puts(s, KRETPROBE_MSG);
+                       else
+                               ret = seq_print_ip_sym(s, entry->fn.parent_ip,
+                                                      sym_flags);
+                       if (!ret)
+                               return 0;
+               }
+               ret = trace_seq_printf(s, "\n");
+               if (!ret)
+                       return 0;
+               break;
+       case TRACE_CTX:
+       case TRACE_WAKE:
+               S = entry->ctx.prev_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.prev_state] : 'X';
+               T = entry->ctx.next_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.next_state] : 'X';
+               ret = trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c\n",
+                                      entry->ctx.prev_pid,
+                                      entry->ctx.prev_prio,
+                                      S,
+                                      entry->type == TRACE_CTX ? "==>" : "  +",
+                                      entry->ctx.next_pid,
+                                      entry->ctx.next_prio,
+                                      T);
+               if (!ret)
+                       return 0;
+               break;
+       case TRACE_SPECIAL:
+               ret = trace_seq_printf(s, "# %ld %ld %ld\n",
+                                entry->special.arg1,
+                                entry->special.arg2,
+                                entry->special.arg3);
+               if (!ret)
+                       return 0;
+               break;
+       case TRACE_STACK:
+               for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
+                       if (i) {
+                               ret = trace_seq_puts(s, " <= ");
+                               if (!ret)
+                                       return 0;
+                       }
+                       ret = seq_print_ip_sym(s, entry->stack.caller[i],
+                                              sym_flags);
+                       if (!ret)
+                               return 0;
+               }
+               ret = trace_seq_puts(s, "\n");
+               if (!ret)
+                       return 0;
+               break;
+       }
+       return 1;
+}
+
+static int print_raw_fmt(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       struct trace_entry *entry;
+       int ret;
+       int S, T;
+
+       entry = iter->ent;
+
+       ret = trace_seq_printf(s, "%d %d %llu ",
+               entry->pid, iter->cpu, entry->t);
+       if (!ret)
+               return 0;
+
+       switch (entry->type) {
+       case TRACE_FN:
+               ret = trace_seq_printf(s, "%x %x\n",
+                                       entry->fn.ip, entry->fn.parent_ip);
+               if (!ret)
+                       return 0;
+               break;
+       case TRACE_CTX:
+       case TRACE_WAKE:
+               S = entry->ctx.prev_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.prev_state] : 'X';
+               T = entry->ctx.next_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.next_state] : 'X';
+               if (entry->type == TRACE_WAKE)
+                       S = '+';
+               ret = trace_seq_printf(s, "%d %d %c %d %d %c\n",
+                                      entry->ctx.prev_pid,
+                                      entry->ctx.prev_prio,
+                                      S,
+                                      entry->ctx.next_pid,
+                                      entry->ctx.next_prio,
+                                      T);
+               if (!ret)
+                       return 0;
+               break;
+       case TRACE_SPECIAL:
+       case TRACE_STACK:
+               ret = trace_seq_printf(s, "# %ld %ld %ld\n",
+                                entry->special.arg1,
+                                entry->special.arg2,
+                                entry->special.arg3);
+               if (!ret)
+                       return 0;
+               break;
+       }
+       return 1;
+}
+
+#define SEQ_PUT_FIELD_RET(s, x)                                \
+do {                                                   \
+       if (!trace_seq_putmem(s, &(x), sizeof(x)))      \
+               return 0;                               \
+} while (0)
+
+#define SEQ_PUT_HEX_FIELD_RET(s, x)                    \
+do {                                                   \
+       if (!trace_seq_putmem_hex(s, &(x), sizeof(x)))  \
+               return 0;                               \
+} while (0)
+
+static int print_hex_fmt(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       unsigned char newline = '\n';
+       struct trace_entry *entry;
+       int S, T;
+
+       entry = iter->ent;
+
+       SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
+       SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
+       SEQ_PUT_HEX_FIELD_RET(s, entry->t);
+
+       switch (entry->type) {
+       case TRACE_FN:
+               SEQ_PUT_HEX_FIELD_RET(s, entry->fn.ip);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
+               break;
+       case TRACE_CTX:
+       case TRACE_WAKE:
+               S = entry->ctx.prev_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.prev_state] : 'X';
+               T = entry->ctx.next_state < sizeof(state_to_char) ?
+                       state_to_char[entry->ctx.next_state] : 'X';
+               if (entry->type == TRACE_WAKE)
+                       S = '+';
+               SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_pid);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_prio);
+               SEQ_PUT_HEX_FIELD_RET(s, S);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_pid);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.next_prio);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->fn.parent_ip);
+               SEQ_PUT_HEX_FIELD_RET(s, T);
+               break;
+       case TRACE_SPECIAL:
+       case TRACE_STACK:
+               SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg1);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg2);
+               SEQ_PUT_HEX_FIELD_RET(s, entry->special.arg3);
+               break;
+       }
+       SEQ_PUT_FIELD_RET(s, newline);
+
+       return 1;
+}
+
+static int print_bin_fmt(struct trace_iterator *iter)
+{
+       struct trace_seq *s = &iter->seq;
+       struct trace_entry *entry;
+
+       entry = iter->ent;
+
+       SEQ_PUT_FIELD_RET(s, entry->pid);
+       SEQ_PUT_FIELD_RET(s, entry->cpu);
+       SEQ_PUT_FIELD_RET(s, entry->t);
+
+       switch (entry->type) {
+       case TRACE_FN:
+               SEQ_PUT_FIELD_RET(s, entry->fn.ip);
+               SEQ_PUT_FIELD_RET(s, entry->fn.parent_ip);
+               break;
+       case TRACE_CTX:
+               SEQ_PUT_FIELD_RET(s, entry->ctx.prev_pid);
+               SEQ_PUT_FIELD_RET(s, entry->ctx.prev_prio);
+               SEQ_PUT_FIELD_RET(s, entry->ctx.prev_state);
+               SEQ_PUT_FIELD_RET(s, entry->ctx.next_pid);
+               SEQ_PUT_FIELD_RET(s, entry->ctx.next_prio);
+               SEQ_PUT_FIELD_RET(s, entry->ctx.next_state);
+               break;
+       case TRACE_SPECIAL:
+       case TRACE_STACK:
+               SEQ_PUT_FIELD_RET(s, entry->special.arg1);
+               SEQ_PUT_FIELD_RET(s, entry->special.arg2);
+               SEQ_PUT_FIELD_RET(s, entry->special.arg3);
+               break;
+       }
+       return 1;
+}
+
+static int trace_empty(struct trace_iterator *iter)
+{
+       struct trace_array_cpu *data;
+       int cpu;
+
+       for_each_tracing_cpu(cpu) {
+               data = iter->tr->data[cpu];
+
+               if (head_page(data) && data->trace_idx &&
+                   (data->trace_tail != data->trace_head ||
+                    data->trace_tail_idx != data->trace_head_idx))
+                       return 0;
+       }
+       return 1;
+}
+
+static int print_trace_line(struct trace_iterator *iter)
+{
+       if (iter->trace && iter->trace->print_line)
+               return iter->trace->print_line(iter);
+
+       if (trace_flags & TRACE_ITER_BIN)
+               return print_bin_fmt(iter);
+
+       if (trace_flags & TRACE_ITER_HEX)
+               return print_hex_fmt(iter);
+
+       if (trace_flags & TRACE_ITER_RAW)
+               return print_raw_fmt(iter);
+
+       if (iter->iter_flags & TRACE_FILE_LAT_FMT)
+               return print_lat_fmt(iter, iter->idx, iter->cpu);
+
+       return print_trace_fmt(iter);
+}
+
+static int s_show(struct seq_file *m, void *v)
+{
+       struct trace_iterator *iter = v;
+
+       if (iter->ent == NULL) {
+               if (iter->tr) {
+                       seq_printf(m, "# tracer: %s\n", iter->trace->name);
+                       seq_puts(m, "#\n");
+               }
+               if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
+                       /* print nothing if the buffers are empty */
+                       if (trace_empty(iter))
+                               return 0;
+                       print_trace_header(m, iter);
+                       if (!(trace_flags & TRACE_ITER_VERBOSE))
+                               print_lat_help_header(m);
+               } else {
+                       if (!(trace_flags & TRACE_ITER_VERBOSE))
+                               print_func_help_header(m);
+               }
+       } else {
+               print_trace_line(iter);
+               trace_print_seq(m, &iter->seq);
+       }
+
+       return 0;
+}
+
+static struct seq_operations tracer_seq_ops = {
+       .start          = s_start,
+       .next           = s_next,
+       .stop           = s_stop,
+       .show           = s_show,
+};
+
+static struct trace_iterator *
+__tracing_open(struct inode *inode, struct file *file, int *ret)
+{
+       struct trace_iterator *iter;
+
+       if (tracing_disabled) {
+               *ret = -ENODEV;
+               return NULL;
+       }
+
+       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+       if (!iter) {
+               *ret = -ENOMEM;
+               goto out;
+       }
+
+       mutex_lock(&trace_types_lock);
+       if (current_trace && current_trace->print_max)
+               iter->tr = &max_tr;
+       else
+               iter->tr = inode->i_private;
+       iter->trace = current_trace;
+       iter->pos = -1;
+
+       /* TODO stop tracer */
+       *ret = seq_open(file, &tracer_seq_ops);
+       if (!*ret) {
+               struct seq_file *m = file->private_data;
+               m->private = iter;
+
+               /* stop the trace while dumping */
+               if (iter->tr->ctrl) {
+                       tracer_enabled = 0;
+                       ftrace_function_enabled = 0;
+               }
+
+               if (iter->trace && iter->trace->open)
+                       iter->trace->open(iter);
+       } else {
+               kfree(iter);
+               iter = NULL;
+       }
+       mutex_unlock(&trace_types_lock);
+
+ out:
+       return iter;
+}
+
+int tracing_open_generic(struct inode *inode, struct file *filp)
+{
+       if (tracing_disabled)
+               return -ENODEV;
+
+       filp->private_data = inode->i_private;
+       return 0;
+}
+
+int tracing_release(struct inode *inode, struct file *file)
+{
+       struct seq_file *m = (struct seq_file *)file->private_data;
+       struct trace_iterator *iter = m->private;
+
+       mutex_lock(&trace_types_lock);
+       if (iter->trace && iter->trace->close)
+               iter->trace->close(iter);
+
+       /* reenable tracing if it was previously enabled */
+       if (iter->tr->ctrl) {
+               tracer_enabled = 1;
+               /*
+                * It is safe to enable function tracing even if it
+                * isn't used
+                */
+               ftrace_function_enabled = 1;
+       }
+       mutex_unlock(&trace_types_lock);
+
+       seq_release(inode, file);
+       kfree(iter);
+       return 0;
+}
+
+static int tracing_open(struct inode *inode, struct file *file)
+{
+       int ret;
+
+       __tracing_open(inode, file, &ret);
+
+       return ret;
+}
+
+static int tracing_lt_open(struct inode *inode, struct file *file)
+{
+       struct trace_iterator *iter;
+       int ret;
+
+       iter = __tracing_open(inode, file, &ret);
+
+       if (!ret)
+               iter->iter_flags |= TRACE_FILE_LAT_FMT;
+
+       return ret;
+}
+
+
+static void *
+t_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       struct tracer *t = m->private;
+
+       (*pos)++;
+
+       if (t)
+               t = t->next;
+
+       m->private = t;
+
+       return t;
+}
+
+static void *t_start(struct seq_file *m, loff_t *pos)
+{
+       struct tracer *t = m->private;
+       loff_t l = 0;
+
+       mutex_lock(&trace_types_lock);
+       for (; t && l < *pos; t = t_next(m, t, &l))
+               ;
+
+       return t;
+}
+
+static void t_stop(struct seq_file *m, void *p)
+{
+       mutex_unlock(&trace_types_lock);
+}
+
+static int t_show(struct seq_file *m, void *v)
+{
+       struct tracer *t = v;
+
+       if (!t)
+               return 0;
+
+       seq_printf(m, "%s", t->name);
+       if (t->next)
+               seq_putc(m, ' ');
+       else
+               seq_putc(m, '\n');
+
+       return 0;
+}
+
+static struct seq_operations show_traces_seq_ops = {
+       .start          = t_start,
+       .next           = t_next,
+       .stop           = t_stop,
+       .show           = t_show,
+};
+
+static int show_traces_open(struct inode *inode, struct file *file)
+{
+       int ret;
+
+       if (tracing_disabled)
+               return -ENODEV;
+
+       ret = seq_open(file, &show_traces_seq_ops);
+       if (!ret) {
+               struct seq_file *m = file->private_data;
+               m->private = trace_types;
+       }
+
+       return ret;
+}
+
+static struct file_operations tracing_fops = {
+       .open           = tracing_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = tracing_release,
+};
+
+static struct file_operations tracing_lt_fops = {
+       .open           = tracing_lt_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = tracing_release,
+};
+
+static struct file_operations show_traces_fops = {
+       .open           = show_traces_open,
+       .read           = seq_read,
+       .release        = seq_release,
+};
+
+/*
+ * Only trace on a CPU if the bitmask is set:
+ */
+static cpumask_t tracing_cpumask = CPU_MASK_ALL;
+
+/*
+ * When tracing/tracing_cpu_mask is modified then this holds
+ * the new bitmask we are about to install:
+ */
+static cpumask_t tracing_cpumask_new;
+
+/*
+ * The tracer itself will not take this lock, but still we want
+ * to provide a consistent cpumask to user-space:
+ */
+static DEFINE_MUTEX(tracing_cpumask_update_lock);
+
+/*
+ * Temporary storage for the character representation of the
+ * CPU bitmask (and one more byte for the newline):
+ */
+static char mask_str[NR_CPUS + 1];
+
+static ssize_t
+tracing_cpumask_read(struct file *filp, char __user *ubuf,
+                    size_t count, loff_t *ppos)
+{
+       int len;
+
+       mutex_lock(&tracing_cpumask_update_lock);
+
+       len = cpumask_scnprintf(mask_str, count, tracing_cpumask);
+       if (count - len < 2) {
+               count = -EINVAL;
+               goto out_err;
+       }
+       len += sprintf(mask_str + len, "\n");
+       count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1);
+
+out_err:
+       mutex_unlock(&tracing_cpumask_update_lock);
+
+       return count;
+}
+
+static ssize_t
+tracing_cpumask_write(struct file *filp, const char __user *ubuf,
+                     size_t count, loff_t *ppos)
+{
+       int err, cpu;
+
+       mutex_lock(&tracing_cpumask_update_lock);
+       err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
+       if (err)
+               goto err_unlock;
+
+       raw_local_irq_disable();
+       __raw_spin_lock(&ftrace_max_lock);
+       for_each_tracing_cpu(cpu) {
+               /*
+                * Increase/decrease the disabled counter if we are
+                * about to flip a bit in the cpumask:
+                */
+               if (cpu_isset(cpu, tracing_cpumask) &&
+                               !cpu_isset(cpu, tracing_cpumask_new)) {
+                       atomic_inc(&global_trace.data[cpu]->disabled);
+               }
+               if (!cpu_isset(cpu, tracing_cpumask) &&
+                               cpu_isset(cpu, tracing_cpumask_new)) {
+                       atomic_dec(&global_trace.data[cpu]->disabled);
+               }
+       }
+       __raw_spin_unlock(&ftrace_max_lock);
+       raw_local_irq_enable();
+
+       tracing_cpumask = tracing_cpumask_new;
+
+       mutex_unlock(&tracing_cpumask_update_lock);
+
+       return count;
+
+err_unlock:
+       mutex_unlock(&tracing_cpumask_update_lock);
+
+       return err;
+}
+
+static struct file_operations tracing_cpumask_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_cpumask_read,
+       .write          = tracing_cpumask_write,
+};
+
+static ssize_t
+tracing_iter_ctrl_read(struct file *filp, char __user *ubuf,
+                      size_t cnt, loff_t *ppos)
+{
+       char *buf;
+       int r = 0;
+       int len = 0;
+       int i;
+
+       /* calulate max size */
+       for (i = 0; trace_options[i]; i++) {
+               len += strlen(trace_options[i]);
+               len += 3; /* "no" and space */
+       }
+
+       /* +2 for \n and \0 */
+       buf = kmalloc(len + 2, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       for (i = 0; trace_options[i]; i++) {
+               if (trace_flags & (1 << i))
+                       r += sprintf(buf + r, "%s ", trace_options[i]);
+               else
+                       r += sprintf(buf + r, "no%s ", trace_options[i]);
+       }
+
+       r += sprintf(buf + r, "\n");
+       WARN_ON(r >= len + 2);
+
+       r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+
+       kfree(buf);
+
+       return r;
+}
+
+static ssize_t
+tracing_iter_ctrl_write(struct file *filp, const char __user *ubuf,
+                       size_t cnt, loff_t *ppos)
+{
+       char buf[64];
+       char *cmp = buf;
+       int neg = 0;
+       int i;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       if (strncmp(buf, "no", 2) == 0) {
+               neg = 1;
+               cmp += 2;
+       }
+
+       for (i = 0; trace_options[i]; i++) {
+               int len = strlen(trace_options[i]);
+
+               if (strncmp(cmp, trace_options[i], len) == 0) {
+                       if (neg)
+                               trace_flags &= ~(1 << i);
+                       else
+                               trace_flags |= (1 << i);
+                       break;
+               }
+       }
+       /*
+        * If no option could be set, return an error:
+        */
+       if (!trace_options[i])
+               return -EINVAL;
+
+       filp->f_pos += cnt;
+
+       return cnt;
+}
+
+static struct file_operations tracing_iter_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_iter_ctrl_read,
+       .write          = tracing_iter_ctrl_write,
+};
+
+static const char readme_msg[] =
+       "tracing mini-HOWTO:\n\n"
+       "# mkdir /debug\n"
+       "# mount -t debugfs nodev /debug\n\n"
+       "# cat /debug/tracing/available_tracers\n"
+       "wakeup preemptirqsoff preemptoff irqsoff ftrace sched_switch none\n\n"
+       "# cat /debug/tracing/current_tracer\n"
+       "none\n"
+       "# echo sched_switch > /debug/tracing/current_tracer\n"
+       "# cat /debug/tracing/current_tracer\n"
+       "sched_switch\n"
+       "# cat /debug/tracing/iter_ctrl\n"
+       "noprint-parent nosym-offset nosym-addr noverbose\n"
+       "# echo print-parent > /debug/tracing/iter_ctrl\n"
+       "# echo 1 > /debug/tracing/tracing_enabled\n"
+       "# cat /debug/tracing/trace > /tmp/trace.txt\n"
+       "echo 0 > /debug/tracing/tracing_enabled\n"
+;
+
+static ssize_t
+tracing_readme_read(struct file *filp, char __user *ubuf,
+                      size_t cnt, loff_t *ppos)
+{
+       return simple_read_from_buffer(ubuf, cnt, ppos,
+                                       readme_msg, strlen(readme_msg));
+}
+
+static struct file_operations tracing_readme_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_readme_read,
+};
+
+static ssize_t
+tracing_ctrl_read(struct file *filp, char __user *ubuf,
+                 size_t cnt, loff_t *ppos)
+{
+       struct trace_array *tr = filp->private_data;
+       char buf[64];
+       int r;
+
+       r = sprintf(buf, "%ld\n", tr->ctrl);
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+tracing_ctrl_write(struct file *filp, const char __user *ubuf,
+                  size_t cnt, loff_t *ppos)
+{
+       struct trace_array *tr = filp->private_data;
+       char buf[64];
+       long val;
+       int ret;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       ret = strict_strtoul(buf, 10, &val);
+       if (ret < 0)
+               return ret;
+
+       val = !!val;
+
+       mutex_lock(&trace_types_lock);
+       if (tr->ctrl ^ val) {
+               if (val)
+                       tracer_enabled = 1;
+               else
+                       tracer_enabled = 0;
+
+               tr->ctrl = val;
+
+               if (current_trace && current_trace->ctrl_update)
+                       current_trace->ctrl_update(tr);
+       }
+       mutex_unlock(&trace_types_lock);
+
+       filp->f_pos += cnt;
+
+       return cnt;
+}
+
+static ssize_t
+tracing_set_trace_read(struct file *filp, char __user *ubuf,
+                      size_t cnt, loff_t *ppos)
+{
+       char buf[max_tracer_type_len+2];
+       int r;
+
+       mutex_lock(&trace_types_lock);
+       if (current_trace)
+               r = sprintf(buf, "%s\n", current_trace->name);
+       else
+               r = sprintf(buf, "\n");
+       mutex_unlock(&trace_types_lock);
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+tracing_set_trace_write(struct file *filp, const char __user *ubuf,
+                       size_t cnt, loff_t *ppos)
+{
+       struct trace_array *tr = &global_trace;
+       struct tracer *t;
+       char buf[max_tracer_type_len+1];
+       int i;
+
+       if (cnt > max_tracer_type_len)
+               cnt = max_tracer_type_len;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       /* strip ending whitespace. */
+       for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
+               buf[i] = 0;
+
+       mutex_lock(&trace_types_lock);
+       for (t = trace_types; t; t = t->next) {
+               if (strcmp(t->name, buf) == 0)
+                       break;
+       }
+       if (!t || t == current_trace)
+               goto out;
+
+       if (current_trace && current_trace->reset)
+               current_trace->reset(tr);
+
+       current_trace = t;
+       if (t->init)
+               t->init(tr);
+
+ out:
+       mutex_unlock(&trace_types_lock);
+
+       filp->f_pos += cnt;
+
+       return cnt;
+}
+
+static ssize_t
+tracing_max_lat_read(struct file *filp, char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       unsigned long *ptr = filp->private_data;
+       char buf[64];
+       int r;
+
+       r = snprintf(buf, sizeof(buf), "%ld\n",
+                    *ptr == (unsigned long)-1 ? -1 : nsecs_to_usecs(*ptr));
+       if (r > sizeof(buf))
+               r = sizeof(buf);
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+tracing_max_lat_write(struct file *filp, const char __user *ubuf,
+                     size_t cnt, loff_t *ppos)
+{
+       long *ptr = filp->private_data;
+       char buf[64];
+       long val;
+       int ret;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       ret = strict_strtoul(buf, 10, &val);
+       if (ret < 0)
+               return ret;
+
+       *ptr = val * 1000;
+
+       return cnt;
+}
+
+static atomic_t tracing_reader;
+
+static int tracing_open_pipe(struct inode *inode, struct file *filp)
+{
+       struct trace_iterator *iter;
+
+       if (tracing_disabled)
+               return -ENODEV;
+
+       /* We only allow for reader of the pipe */
+       if (atomic_inc_return(&tracing_reader) != 1) {
+               atomic_dec(&tracing_reader);
+               return -EBUSY;
+       }
+
+       /* create a buffer to store the information to pass to userspace */
+       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+       if (!iter)
+               return -ENOMEM;
+
+       mutex_lock(&trace_types_lock);
+       iter->tr = &global_trace;
+       iter->trace = current_trace;
+       filp->private_data = iter;
+
+       if (iter->trace->pipe_open)
+               iter->trace->pipe_open(iter);
+       mutex_unlock(&trace_types_lock);
+
+       return 0;
+}
+
+static int tracing_release_pipe(struct inode *inode, struct file *file)
+{
+       struct trace_iterator *iter = file->private_data;
+
+       kfree(iter);
+       atomic_dec(&tracing_reader);
+
+       return 0;
+}
+
+static unsigned int
+tracing_poll_pipe(struct file *filp, poll_table *poll_table)
+{
+       struct trace_iterator *iter = filp->private_data;
+
+       if (trace_flags & TRACE_ITER_BLOCK) {
+               /*
+                * Always select as readable when in blocking mode
+                */
+               return POLLIN | POLLRDNORM;
+       } else {
+               if (!trace_empty(iter))
+                       return POLLIN | POLLRDNORM;
+               poll_wait(filp, &trace_wait, poll_table);
+               if (!trace_empty(iter))
+                       return POLLIN | POLLRDNORM;
+
+               return 0;
+       }
+}
+
+/*
+ * Consumer reader.
+ */
+static ssize_t
+tracing_read_pipe(struct file *filp, char __user *ubuf,
+                 size_t cnt, loff_t *ppos)
+{
+       struct trace_iterator *iter = filp->private_data;
+       struct trace_array_cpu *data;
+       static cpumask_t mask;
+       unsigned long flags;
+#ifdef CONFIG_FTRACE
+       int ftrace_save;
+#endif
+       int cpu;
+       ssize_t sret;
+
+       /* return any leftover data */
+       sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
+       if (sret != -EBUSY)
+               return sret;
+       sret = 0;
+
+       trace_seq_reset(&iter->seq);
+
+       mutex_lock(&trace_types_lock);
+       if (iter->trace->read) {
+               sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
+               if (sret)
+                       goto out;
+       }
+
+       while (trace_empty(iter)) {
+
+               if ((filp->f_flags & O_NONBLOCK)) {
+                       sret = -EAGAIN;
+                       goto out;
+               }
+
+               /*
+                * This is a make-shift waitqueue. The reason we don't use
+                * an actual wait queue is because:
+                *  1) we only ever have one waiter
+                *  2) the tracing, traces all functions, we don't want
+                *     the overhead of calling wake_up and friends
+                *     (and tracing them too)
+                *     Anyway, this is really very primitive wakeup.
+                */
+               set_current_state(TASK_INTERRUPTIBLE);
+               iter->tr->waiter = current;
+
+               mutex_unlock(&trace_types_lock);
+
+               /* sleep for 100 msecs, and try again. */
+               schedule_timeout(HZ/10);
+
+               mutex_lock(&trace_types_lock);
+
+               iter->tr->waiter = NULL;
+
+               if (signal_pending(current)) {
+                       sret = -EINTR;
+                       goto out;
+               }
+
+               if (iter->trace != current_trace)
+                       goto out;
+
+               /*
+                * We block until we read something and tracing is disabled.
+                * We still block if tracing is disabled, but we have never
+                * read anything. This allows a user to cat this file, and
+                * then enable tracing. But after we have read something,
+                * we give an EOF when tracing is again disabled.
+                *
+                * iter->pos will be 0 if we haven't read anything.
+                */
+               if (!tracer_enabled && iter->pos)
+                       break;
+
+               continue;
+       }
+
+       /* stop when tracing is finished */
+       if (trace_empty(iter))
+               goto out;
+
+       if (cnt >= PAGE_SIZE)
+               cnt = PAGE_SIZE - 1;
+
+       /* reset all but tr, trace, and overruns */
+       memset(&iter->seq, 0,
+              sizeof(struct trace_iterator) -
+              offsetof(struct trace_iterator, seq));
+       iter->pos = -1;
+
+       /*
+        * We need to stop all tracing on all CPUS to read the
+        * the next buffer. This is a bit expensive, but is
+        * not done often. We fill all what we can read,
+        * and then release the locks again.
+        */
+
+       cpus_clear(mask);
+       local_irq_save(flags);
+#ifdef CONFIG_FTRACE
+       ftrace_save = ftrace_enabled;
+       ftrace_enabled = 0;
+#endif
+       smp_wmb();
+       for_each_tracing_cpu(cpu) {
+               data = iter->tr->data[cpu];
+
+               if (!head_page(data) || !data->trace_idx)
+                       continue;
+
+               atomic_inc(&data->disabled);
+               cpu_set(cpu, mask);
+       }
+
+       for_each_cpu_mask(cpu, mask) {
+               data = iter->tr->data[cpu];
+               __raw_spin_lock(&data->lock);
+
+               if (data->overrun > iter->last_overrun[cpu])
+                       iter->overrun[cpu] +=
+                               data->overrun - iter->last_overrun[cpu];
+               iter->last_overrun[cpu] = data->overrun;
+       }
+
+       while (find_next_entry_inc(iter) != NULL) {
+               int ret;
+               int len = iter->seq.len;
+
+               ret = print_trace_line(iter);
+               if (!ret) {
+                       /* don't print partial lines */
+                       iter->seq.len = len;
+                       break;
+               }
+
+               trace_consume(iter);
+
+               if (iter->seq.len >= cnt)
+                       break;
+       }
+
+       for_each_cpu_mask(cpu, mask) {
+               data = iter->tr->data[cpu];
+               __raw_spin_unlock(&data->lock);
+       }
+
+       for_each_cpu_mask(cpu, mask) {
+               data = iter->tr->data[cpu];
+               atomic_dec(&data->disabled);
+       }
+#ifdef CONFIG_FTRACE
+       ftrace_enabled = ftrace_save;
+#endif
+       local_irq_restore(flags);
+
+       /* Now copy what we have to the user */
+       sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
+       if (iter->seq.readpos >= iter->seq.len)
+               trace_seq_reset(&iter->seq);
+       if (sret == -EBUSY)
+               sret = 0;
+
+out:
+       mutex_unlock(&trace_types_lock);
+
+       return sret;
+}
+
+static ssize_t
+tracing_entries_read(struct file *filp, char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       struct trace_array *tr = filp->private_data;
+       char buf[64];
+       int r;
+
+       r = sprintf(buf, "%lu\n", tr->entries);
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+tracing_entries_write(struct file *filp, const char __user *ubuf,
+                     size_t cnt, loff_t *ppos)
+{
+       unsigned long val;
+       char buf[64];
+       int i, ret;
+
+       if (cnt >= sizeof(buf))
+               return -EINVAL;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       ret = strict_strtoul(buf, 10, &val);
+       if (ret < 0)
+               return ret;
+
+       /* must have at least 1 entry */
+       if (!val)
+               return -EINVAL;
+
+       mutex_lock(&trace_types_lock);
+
+       if (current_trace != &no_tracer) {
+               cnt = -EBUSY;
+               pr_info("ftrace: set current_tracer to none"
+                       " before modifying buffer size\n");
+               goto out;
+       }
+
+       if (val > global_trace.entries) {
+               long pages_requested;
+               unsigned long freeable_pages;
+
+               /* make sure we have enough memory before mapping */
+               pages_requested =
+                       (val + (ENTRIES_PER_PAGE-1)) / ENTRIES_PER_PAGE;
+
+               /* account for each buffer (and max_tr) */
+               pages_requested *= tracing_nr_buffers * 2;
+
+               /* Check for overflow */
+               if (pages_requested < 0) {
+                       cnt = -ENOMEM;
+                       goto out;
+               }
+
+               freeable_pages = determine_dirtyable_memory();
+
+               /* we only allow to request 1/4 of useable memory */
+               if (pages_requested >
+                   ((freeable_pages + tracing_pages_allocated) / 4)) {
+                       cnt = -ENOMEM;
+                       goto out;
+               }
+
+               while (global_trace.entries < val) {
+                       if (trace_alloc_page()) {
+                               cnt = -ENOMEM;
+                               goto out;
+                       }
+                       /* double check that we don't go over the known pages */
+                       if (tracing_pages_allocated > pages_requested)
+                               break;
+               }
+
+       } else {
+               /* include the number of entries in val (inc of page entries) */
+               while (global_trace.entries > val + (ENTRIES_PER_PAGE - 1))
+                       trace_free_page();
+       }
+
+       /* check integrity */
+       for_each_tracing_cpu(i)
+               check_pages(global_trace.data[i]);
+
+       filp->f_pos += cnt;
+
+       /* If check pages failed, return ENOMEM */
+       if (tracing_disabled)
+               cnt = -ENOMEM;
+ out:
+       max_tr.entries = global_trace.entries;
+       mutex_unlock(&trace_types_lock);
+
+       return cnt;
+}
+
+static struct file_operations tracing_max_lat_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_max_lat_read,
+       .write          = tracing_max_lat_write,
+};
+
+static struct file_operations tracing_ctrl_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_ctrl_read,
+       .write          = tracing_ctrl_write,
+};
+
+static struct file_operations set_tracer_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_set_trace_read,
+       .write          = tracing_set_trace_write,
+};
+
+static struct file_operations tracing_pipe_fops = {
+       .open           = tracing_open_pipe,
+       .poll           = tracing_poll_pipe,
+       .read           = tracing_read_pipe,
+       .release        = tracing_release_pipe,
+};
+
+static struct file_operations tracing_entries_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_entries_read,
+       .write          = tracing_entries_write,
+};
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+
+static ssize_t
+tracing_read_long(struct file *filp, char __user *ubuf,
+                 size_t cnt, loff_t *ppos)
+{
+       unsigned long *p = filp->private_data;
+       char buf[64];
+       int r;
+
+       r = sprintf(buf, "%ld\n", *p);
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static struct file_operations tracing_read_long_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_read_long,
+};
+#endif
+
+static struct dentry *d_tracer;
+
+struct dentry *tracing_init_dentry(void)
+{
+       static int once;
+
+       if (d_tracer)
+               return d_tracer;
+
+       d_tracer = debugfs_create_dir("tracing", NULL);
+
+       if (!d_tracer && !once) {
+               once = 1;
+               pr_warning("Could not create debugfs directory 'tracing'\n");
+               return NULL;
+       }
+
+       return d_tracer;
+}
+
+#ifdef CONFIG_FTRACE_SELFTEST
+/* Let selftest have access to static functions in this file */
+#include "trace_selftest.c"
+#endif
+
+static __init void tracer_init_debugfs(void)
+{
+       struct dentry *d_tracer;
+       struct dentry *entry;
+
+       d_tracer = tracing_init_dentry();
+
+       entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
+                                   &global_trace, &tracing_ctrl_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'tracing_enabled' entry\n");
+
+       entry = debugfs_create_file("iter_ctrl", 0644, d_tracer,
+                                   NULL, &tracing_iter_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'iter_ctrl' entry\n");
+
+       entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
+                                   NULL, &tracing_cpumask_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
+
+       entry = debugfs_create_file("latency_trace", 0444, d_tracer,
+                                   &global_trace, &tracing_lt_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'latency_trace' entry\n");
+
+       entry = debugfs_create_file("trace", 0444, d_tracer,
+                                   &global_trace, &tracing_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'trace' entry\n");
+
+       entry = debugfs_create_file("available_tracers", 0444, d_tracer,
+                                   &global_trace, &show_traces_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'trace' entry\n");
+
+       entry = debugfs_create_file("current_tracer", 0444, d_tracer,
+                                   &global_trace, &set_tracer_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'trace' entry\n");
+
+       entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
+                                   &tracing_max_latency,
+                                   &tracing_max_lat_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'tracing_max_latency' entry\n");
+
+       entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
+                                   &tracing_thresh, &tracing_max_lat_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'tracing_threash' entry\n");
+       entry = debugfs_create_file("README", 0644, d_tracer,
+                                   NULL, &tracing_readme_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs 'README' entry\n");
+
+       entry = debugfs_create_file("trace_pipe", 0644, d_tracer,
+                                   NULL, &tracing_pipe_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'tracing_threash' entry\n");
+
+       entry = debugfs_create_file("trace_entries", 0644, d_tracer,
+                                   &global_trace, &tracing_entries_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'tracing_threash' entry\n");
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+       entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
+                                   &ftrace_update_tot_cnt,
+                                   &tracing_read_long_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'dyn_ftrace_total_info' entry\n");
+#endif
+#ifdef CONFIG_SYSPROF_TRACER
+       init_tracer_sysprof_debugfs(d_tracer);
+#endif
+}
+
+static int trace_alloc_page(void)
+{
+       struct trace_array_cpu *data;
+       struct page *page, *tmp;
+       LIST_HEAD(pages);
+       void *array;
+       unsigned pages_allocated = 0;
+       int i;
+
+       /* first allocate a page for each CPU */
+       for_each_tracing_cpu(i) {
+               array = (void *)__get_free_page(GFP_KERNEL);
+               if (array == NULL) {
+                       printk(KERN_ERR "tracer: failed to allocate page"
+                              "for trace buffer!\n");
+                       goto free_pages;
+               }
+
+               pages_allocated++;
+               page = virt_to_page(array);
+               list_add(&page->lru, &pages);
+
+/* Only allocate if we are actually using the max trace */
+#ifdef CONFIG_TRACER_MAX_TRACE
+               array = (void *)__get_free_page(GFP_KERNEL);
+               if (array == NULL) {
+                       printk(KERN_ERR "tracer: failed to allocate page"
+                              "for trace buffer!\n");
+                       goto free_pages;
+               }
+               pages_allocated++;
+               page = virt_to_page(array);
+               list_add(&page->lru, &pages);
+#endif
+       }
+
+       /* Now that we successfully allocate a page per CPU, add them */
+       for_each_tracing_cpu(i) {
+               data = global_trace.data[i];
+               page = list_entry(pages.next, struct page, lru);
+               list_del_init(&page->lru);
+               list_add_tail(&page->lru, &data->trace_pages);
+               ClearPageLRU(page);
+
+#ifdef CONFIG_TRACER_MAX_TRACE
+               data = max_tr.data[i];
+               page = list_entry(pages.next, struct page, lru);
+               list_del_init(&page->lru);
+               list_add_tail(&page->lru, &data->trace_pages);
+               SetPageLRU(page);
+#endif
+       }
+       tracing_pages_allocated += pages_allocated;
+       global_trace.entries += ENTRIES_PER_PAGE;
+
+       return 0;
+
+ free_pages:
+       list_for_each_entry_safe(page, tmp, &pages, lru) {
+               list_del_init(&page->lru);
+               __free_page(page);
+       }
+       return -ENOMEM;
+}
+
+static int trace_free_page(void)
+{
+       struct trace_array_cpu *data;
+       struct page *page;
+       struct list_head *p;
+       int i;
+       int ret = 0;
+
+       /* free one page from each buffer */
+       for_each_tracing_cpu(i) {
+               data = global_trace.data[i];
+               p = data->trace_pages.next;
+               if (p == &data->trace_pages) {
+                       /* should never happen */
+                       WARN_ON(1);
+                       tracing_disabled = 1;
+                       ret = -1;
+                       break;
+               }
+               page = list_entry(p, struct page, lru);
+               ClearPageLRU(page);
+               list_del(&page->lru);
+               tracing_pages_allocated--;
+               tracing_pages_allocated--;
+               __free_page(page);
+
+               tracing_reset(data);
+
+#ifdef CONFIG_TRACER_MAX_TRACE
+               data = max_tr.data[i];
+               p = data->trace_pages.next;
+               if (p == &data->trace_pages) {
+                       /* should never happen */
+                       WARN_ON(1);
+                       tracing_disabled = 1;
+                       ret = -1;
+                       break;
+               }
+               page = list_entry(p, struct page, lru);
+               ClearPageLRU(page);
+               list_del(&page->lru);
+               __free_page(page);
+
+               tracing_reset(data);
+#endif
+       }
+       global_trace.entries -= ENTRIES_PER_PAGE;
+
+       return ret;
+}
+
+__init static int tracer_alloc_buffers(void)
+{
+       struct trace_array_cpu *data;
+       void *array;
+       struct page *page;
+       int pages = 0;
+       int ret = -ENOMEM;
+       int i;
+
+       /* TODO: make the number of buffers hot pluggable with CPUS */
+       tracing_nr_buffers = num_possible_cpus();
+       tracing_buffer_mask = cpu_possible_map;
+
+       /* Allocate the first page for all buffers */
+       for_each_tracing_cpu(i) {
+               data = global_trace.data[i] = &per_cpu(global_trace_cpu, i);
+               max_tr.data[i] = &per_cpu(max_data, i);
+
+               array = (void *)__get_free_page(GFP_KERNEL);
+               if (array == NULL) {
+                       printk(KERN_ERR "tracer: failed to allocate page"
+                              "for trace buffer!\n");
+                       goto free_buffers;
+               }
+
+               /* set the array to the list */
+               INIT_LIST_HEAD(&data->trace_pages);
+               page = virt_to_page(array);
+               list_add(&page->lru, &data->trace_pages);
+               /* use the LRU flag to differentiate the two buffers */
+               ClearPageLRU(page);
+
+               data->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+               max_tr.data[i]->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+
+/* Only allocate if we are actually using the max trace */
+#ifdef CONFIG_TRACER_MAX_TRACE
+               array = (void *)__get_free_page(GFP_KERNEL);
+               if (array == NULL) {
+                       printk(KERN_ERR "tracer: failed to allocate page"
+                              "for trace buffer!\n");
+                       goto free_buffers;
+               }
+
+               INIT_LIST_HEAD(&max_tr.data[i]->trace_pages);
+               page = virt_to_page(array);
+               list_add(&page->lru, &max_tr.data[i]->trace_pages);
+               SetPageLRU(page);
+#endif
+       }
+
+       /*
+        * Since we allocate by orders of pages, we may be able to
+        * round up a bit.
+        */
+       global_trace.entries = ENTRIES_PER_PAGE;
+       pages++;
+
+       while (global_trace.entries < trace_nr_entries) {
+               if (trace_alloc_page())
+                       break;
+               pages++;
+       }
+       max_tr.entries = global_trace.entries;
+
+       pr_info("tracer: %d pages allocated for %ld entries of %ld bytes\n",
+               pages, trace_nr_entries, (long)TRACE_ENTRY_SIZE);
+       pr_info("   actual entries %ld\n", global_trace.entries);
+
+       tracer_init_debugfs();
+
+       trace_init_cmdlines();
+
+       register_tracer(&no_tracer);
+       current_trace = &no_tracer;
+
+       /* All seems OK, enable tracing */
+       global_trace.ctrl = tracer_enabled;
+       tracing_disabled = 0;
+
+       return 0;
+
+ free_buffers:
+       for (i-- ; i >= 0; i--) {
+               struct page *page, *tmp;
+               struct trace_array_cpu *data = global_trace.data[i];
+
+               if (data) {
+                       list_for_each_entry_safe(page, tmp,
+                                                &data->trace_pages, lru) {
+                               list_del_init(&page->lru);
+                               __free_page(page);
+                       }
+               }
+
+#ifdef CONFIG_TRACER_MAX_TRACE
+               data = max_tr.data[i];
+               if (data) {
+                       list_for_each_entry_safe(page, tmp,
+                                                &data->trace_pages, lru) {
+                               list_del_init(&page->lru);
+                               __free_page(page);
+                       }
+               }
+#endif
+       }
+       return ret;
+}
+fs_initcall(tracer_alloc_buffers);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
new file mode 100644 (file)
index 0000000..f69f867
--- /dev/null
@@ -0,0 +1,339 @@
+#ifndef _LINUX_KERNEL_TRACE_H
+#define _LINUX_KERNEL_TRACE_H
+
+#include <linux/fs.h>
+#include <asm/atomic.h>
+#include <linux/sched.h>
+#include <linux/clocksource.h>
+#include <linux/mmiotrace.h>
+
+enum trace_type {
+       __TRACE_FIRST_TYPE = 0,
+
+       TRACE_FN,
+       TRACE_CTX,
+       TRACE_WAKE,
+       TRACE_STACK,
+       TRACE_SPECIAL,
+       TRACE_MMIO_RW,
+       TRACE_MMIO_MAP,
+
+       __TRACE_LAST_TYPE
+};
+
+/*
+ * Function trace entry - function address and parent function addres:
+ */
+struct ftrace_entry {
+       unsigned long           ip;
+       unsigned long           parent_ip;
+};
+
+/*
+ * Context switch trace entry - which task (and prio) we switched from/to:
+ */
+struct ctx_switch_entry {
+       unsigned int            prev_pid;
+       unsigned char           prev_prio;
+       unsigned char           prev_state;
+       unsigned int            next_pid;
+       unsigned char           next_prio;
+       unsigned char           next_state;
+};
+
+/*
+ * Special (free-form) trace entry:
+ */
+struct special_entry {
+       unsigned long           arg1;
+       unsigned long           arg2;
+       unsigned long           arg3;
+};
+
+/*
+ * Stack-trace entry:
+ */
+
+#define FTRACE_STACK_ENTRIES   8
+
+struct stack_entry {
+       unsigned long           caller[FTRACE_STACK_ENTRIES];
+};
+
+/*
+ * The trace entry - the most basic unit of tracing. This is what
+ * is printed in the end as a single line in the trace output, such as:
+ *
+ *     bash-15816 [01]   235.197585: idle_cpu <- irq_enter
+ */
+struct trace_entry {
+       char                    type;
+       char                    cpu;
+       char                    flags;
+       char                    preempt_count;
+       int                     pid;
+       cycle_t                 t;
+       union {
+               struct ftrace_entry             fn;
+               struct ctx_switch_entry         ctx;
+               struct special_entry            special;
+               struct stack_entry              stack;
+               struct mmiotrace_rw             mmiorw;
+               struct mmiotrace_map            mmiomap;
+       };
+};
+
+#define TRACE_ENTRY_SIZE       sizeof(struct trace_entry)
+
+/*
+ * The CPU trace array - it consists of thousands of trace entries
+ * plus some other descriptor data: (for example which task started
+ * the trace, etc.)
+ */
+struct trace_array_cpu {
+       struct list_head        trace_pages;
+       atomic_t                disabled;
+       raw_spinlock_t          lock;
+       struct lock_class_key   lock_key;
+
+       /* these fields get copied into max-trace: */
+       unsigned                trace_head_idx;
+       unsigned                trace_tail_idx;
+       void                    *trace_head; /* producer */
+       void                    *trace_tail; /* consumer */
+       unsigned long           trace_idx;
+       unsigned long           overrun;
+       unsigned long           saved_latency;
+       unsigned long           critical_start;
+       unsigned long           critical_end;
+       unsigned long           critical_sequence;
+       unsigned long           nice;
+       unsigned long           policy;
+       unsigned long           rt_priority;
+       cycle_t                 preempt_timestamp;
+       pid_t                   pid;
+       uid_t                   uid;
+       char                    comm[TASK_COMM_LEN];
+};
+
+struct trace_iterator;
+
+/*
+ * The trace array - an array of per-CPU trace arrays. This is the
+ * highest level data structure that individual tracers deal with.
+ * They have on/off state as well:
+ */
+struct trace_array {
+       unsigned long           entries;
+       long                    ctrl;
+       int                     cpu;
+       cycle_t                 time_start;
+       struct task_struct      *waiter;
+       struct trace_array_cpu  *data[NR_CPUS];
+};
+
+/*
+ * A specific tracer, represented by methods that operate on a trace array:
+ */
+struct tracer {
+       const char              *name;
+       void                    (*init)(struct trace_array *tr);
+       void                    (*reset)(struct trace_array *tr);
+       void                    (*open)(struct trace_iterator *iter);
+       void                    (*pipe_open)(struct trace_iterator *iter);
+       void                    (*close)(struct trace_iterator *iter);
+       void                    (*start)(struct trace_iterator *iter);
+       void                    (*stop)(struct trace_iterator *iter);
+       ssize_t                 (*read)(struct trace_iterator *iter,
+                                       struct file *filp, char __user *ubuf,
+                                       size_t cnt, loff_t *ppos);
+       void                    (*ctrl_update)(struct trace_array *tr);
+#ifdef CONFIG_FTRACE_STARTUP_TEST
+       int                     (*selftest)(struct tracer *trace,
+                                           struct trace_array *tr);
+#endif
+       int                     (*print_line)(struct trace_iterator *iter);
+       struct tracer           *next;
+       int                     print_max;
+};
+
+struct trace_seq {
+       unsigned char           buffer[PAGE_SIZE];
+       unsigned int            len;
+       unsigned int            readpos;
+};
+
+/*
+ * Trace iterator - used by printout routines who present trace
+ * results to users and which routines might sleep, etc:
+ */
+struct trace_iterator {
+       struct trace_array      *tr;
+       struct tracer           *trace;
+       void                    *private;
+       long                    last_overrun[NR_CPUS];
+       long                    overrun[NR_CPUS];
+
+       /* The below is zeroed out in pipe_read */
+       struct trace_seq        seq;
+       struct trace_entry      *ent;
+       int                     cpu;
+
+       struct trace_entry      *prev_ent;
+       int                     prev_cpu;
+
+       unsigned long           iter_flags;
+       loff_t                  pos;
+       unsigned long           next_idx[NR_CPUS];
+       struct list_head        *next_page[NR_CPUS];
+       unsigned                next_page_idx[NR_CPUS];
+       long                    idx;
+};
+
+void tracing_reset(struct trace_array_cpu *data);
+int tracing_open_generic(struct inode *inode, struct file *filp);
+struct dentry *tracing_init_dentry(void);
+void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
+
+void ftrace(struct trace_array *tr,
+                           struct trace_array_cpu *data,
+                           unsigned long ip,
+                           unsigned long parent_ip,
+                           unsigned long flags);
+void tracing_sched_switch_trace(struct trace_array *tr,
+                               struct trace_array_cpu *data,
+                               struct task_struct *prev,
+                               struct task_struct *next,
+                               unsigned long flags);
+void tracing_record_cmdline(struct task_struct *tsk);
+
+void tracing_sched_wakeup_trace(struct trace_array *tr,
+                               struct trace_array_cpu *data,
+                               struct task_struct *wakee,
+                               struct task_struct *cur,
+                               unsigned long flags);
+void trace_special(struct trace_array *tr,
+                  struct trace_array_cpu *data,
+                  unsigned long arg1,
+                  unsigned long arg2,
+                  unsigned long arg3);
+void trace_function(struct trace_array *tr,
+                   struct trace_array_cpu *data,
+                   unsigned long ip,
+                   unsigned long parent_ip,
+                   unsigned long flags);
+
+void tracing_start_cmdline_record(void);
+void tracing_stop_cmdline_record(void);
+int register_tracer(struct tracer *type);
+void unregister_tracer(struct tracer *type);
+
+extern unsigned long nsecs_to_usecs(unsigned long nsecs);
+
+extern unsigned long tracing_max_latency;
+extern unsigned long tracing_thresh;
+
+void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
+void update_max_tr_single(struct trace_array *tr,
+                         struct task_struct *tsk, int cpu);
+
+extern cycle_t ftrace_now(int cpu);
+
+#ifdef CONFIG_FTRACE
+void tracing_start_function_trace(void);
+void tracing_stop_function_trace(void);
+#else
+# define tracing_start_function_trace()                do { } while (0)
+# define tracing_stop_function_trace()         do { } while (0)
+#endif
+
+#ifdef CONFIG_CONTEXT_SWITCH_TRACER
+typedef void
+(*tracer_switch_func_t)(void *private,
+                       void *__rq,
+                       struct task_struct *prev,
+                       struct task_struct *next);
+
+struct tracer_switch_ops {
+       tracer_switch_func_t            func;
+       void                            *private;
+       struct tracer_switch_ops        *next;
+};
+
+#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+extern unsigned long ftrace_update_tot_cnt;
+#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
+extern int DYN_FTRACE_TEST_NAME(void);
+#endif
+
+#ifdef CONFIG_MMIOTRACE
+extern void __trace_mmiotrace_rw(struct trace_array *tr,
+                               struct trace_array_cpu *data,
+                               struct mmiotrace_rw *rw);
+extern void __trace_mmiotrace_map(struct trace_array *tr,
+                               struct trace_array_cpu *data,
+                               struct mmiotrace_map *map);
+#endif
+
+#ifdef CONFIG_FTRACE_STARTUP_TEST
+#ifdef CONFIG_FTRACE
+extern int trace_selftest_startup_function(struct tracer *trace,
+                                          struct trace_array *tr);
+#endif
+#ifdef CONFIG_IRQSOFF_TRACER
+extern int trace_selftest_startup_irqsoff(struct tracer *trace,
+                                         struct trace_array *tr);
+#endif
+#ifdef CONFIG_PREEMPT_TRACER
+extern int trace_selftest_startup_preemptoff(struct tracer *trace,
+                                            struct trace_array *tr);
+#endif
+#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
+extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
+                                                struct trace_array *tr);
+#endif
+#ifdef CONFIG_SCHED_TRACER
+extern int trace_selftest_startup_wakeup(struct tracer *trace,
+                                        struct trace_array *tr);
+#endif
+#ifdef CONFIG_CONTEXT_SWITCH_TRACER
+extern int trace_selftest_startup_sched_switch(struct tracer *trace,
+                                              struct trace_array *tr);
+#endif
+#ifdef CONFIG_SYSPROF_TRACER
+extern int trace_selftest_startup_sysprof(struct tracer *trace,
+                                              struct trace_array *tr);
+#endif
+#endif /* CONFIG_FTRACE_STARTUP_TEST */
+
+extern void *head_page(struct trace_array_cpu *data);
+extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
+extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
+                                size_t cnt);
+extern long ns2usecs(cycle_t nsec);
+
+extern unsigned long trace_flags;
+
+/*
+ * trace_iterator_flags is an enumeration that defines bit
+ * positions into trace_flags that controls the output.
+ *
+ * NOTE: These bits must match the trace_options array in
+ *       trace.c.
+ */
+enum trace_iterator_flags {
+       TRACE_ITER_PRINT_PARENT         = 0x01,
+       TRACE_ITER_SYM_OFFSET           = 0x02,
+       TRACE_ITER_SYM_ADDR             = 0x04,
+       TRACE_ITER_VERBOSE              = 0x08,
+       TRACE_ITER_RAW                  = 0x10,
+       TRACE_ITER_HEX                  = 0x20,
+       TRACE_ITER_BIN                  = 0x40,
+       TRACE_ITER_BLOCK                = 0x80,
+       TRACE_ITER_STACKTRACE           = 0x100,
+       TRACE_ITER_SCHED_TREE           = 0x200,
+};
+
+#endif /* _LINUX_KERNEL_TRACE_H */
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
new file mode 100644 (file)
index 0000000..3121448
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * ring buffer based function tracer
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
+ *
+ * Based on code from the latency_tracer, that is:
+ *
+ *  Copyright (C) 2004-2006 Ingo Molnar
+ *  Copyright (C) 2004 William Lee Irwin III
+ */
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/ftrace.h>
+#include <linux/fs.h>
+
+#include "trace.h"
+
+static void function_reset(struct trace_array *tr)
+{
+       int cpu;
+
+       tr->time_start = ftrace_now(tr->cpu);
+
+       for_each_online_cpu(cpu)
+               tracing_reset(tr->data[cpu]);
+}
+
+static void start_function_trace(struct trace_array *tr)
+{
+       tr->cpu = get_cpu();
+       function_reset(tr);
+       put_cpu();
+
+       tracing_start_cmdline_record();
+       tracing_start_function_trace();
+}
+
+static void stop_function_trace(struct trace_array *tr)
+{
+       tracing_stop_function_trace();
+       tracing_stop_cmdline_record();
+}
+
+static void function_trace_init(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               start_function_trace(tr);
+}
+
+static void function_trace_reset(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               stop_function_trace(tr);
+}
+
+static void function_trace_ctrl_update(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               start_function_trace(tr);
+       else
+               stop_function_trace(tr);
+}
+
+static struct tracer function_trace __read_mostly =
+{
+       .name        = "ftrace",
+       .init        = function_trace_init,
+       .reset       = function_trace_reset,
+       .ctrl_update = function_trace_ctrl_update,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_function,
+#endif
+};
+
+static __init int init_function_trace(void)
+{
+       return register_tracer(&function_trace);
+}
+
+device_initcall(init_function_trace);
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c
new file mode 100644 (file)
index 0000000..421d6fe
--- /dev/null
@@ -0,0 +1,486 @@
+/*
+ * trace irqs off criticall timings
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
+ *
+ * From code in the latency_tracer, that is:
+ *
+ *  Copyright (C) 2004-2006 Ingo Molnar
+ *  Copyright (C) 2004 William Lee Irwin III
+ */
+#include <linux/kallsyms.h>
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/ftrace.h>
+#include <linux/fs.h>
+
+#include "trace.h"
+
+static struct trace_array              *irqsoff_trace __read_mostly;
+static int                             tracer_enabled __read_mostly;
+
+static DEFINE_PER_CPU(int, tracing_cpu);
+
+static DEFINE_SPINLOCK(max_trace_lock);
+
+enum {
+       TRACER_IRQS_OFF         = (1 << 1),
+       TRACER_PREEMPT_OFF      = (1 << 2),
+};
+
+static int trace_type __read_mostly;
+
+#ifdef CONFIG_PREEMPT_TRACER
+static inline int
+preempt_trace(void)
+{
+       return ((trace_type & TRACER_PREEMPT_OFF) && preempt_count());
+}
+#else
+# define preempt_trace() (0)
+#endif
+
+#ifdef CONFIG_IRQSOFF_TRACER
+static inline int
+irq_trace(void)
+{
+       return ((trace_type & TRACER_IRQS_OFF) &&
+               irqs_disabled());
+}
+#else
+# define irq_trace() (0)
+#endif
+
+/*
+ * Sequence count - we record it when starting a measurement and
+ * skip the latency if the sequence has changed - some other section
+ * did a maximum and could disturb our measurement with serial console
+ * printouts, etc. Truly coinciding maximum latencies should be rare
+ * and what happens together happens separately as well, so this doesnt
+ * decrease the validity of the maximum found:
+ */
+static __cacheline_aligned_in_smp      unsigned long max_sequence;
+
+#ifdef CONFIG_FTRACE
+/*
+ * irqsoff uses its own tracer function to keep the overhead down:
+ */
+static void
+irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip)
+{
+       struct trace_array *tr = irqsoff_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       /*
+        * Does not matter if we preempt. We test the flags
+        * afterward, to see if irqs are disabled or not.
+        * If we preempt and get a false positive, the flags
+        * test will fail.
+        */
+       cpu = raw_smp_processor_id();
+       if (likely(!per_cpu(tracing_cpu, cpu)))
+               return;
+
+       local_save_flags(flags);
+       /* slight chance to get a false positive on tracing_cpu */
+       if (!irqs_disabled_flags(flags))
+               return;
+
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1))
+               trace_function(tr, data, ip, parent_ip, flags);
+
+       atomic_dec(&data->disabled);
+}
+
+static struct ftrace_ops trace_ops __read_mostly =
+{
+       .func = irqsoff_tracer_call,
+};
+#endif /* CONFIG_FTRACE */
+
+/*
+ * Should this new latency be reported/recorded?
+ */
+static int report_latency(cycle_t delta)
+{
+       if (tracing_thresh) {
+               if (delta < tracing_thresh)
+                       return 0;
+       } else {
+               if (delta <= tracing_max_latency)
+                       return 0;
+       }
+       return 1;
+}
+
+static void
+check_critical_timing(struct trace_array *tr,
+                     struct trace_array_cpu *data,
+                     unsigned long parent_ip,
+                     int cpu)
+{
+       unsigned long latency, t0, t1;
+       cycle_t T0, T1, delta;
+       unsigned long flags;
+
+       /*
+        * usecs conversion is slow so we try to delay the conversion
+        * as long as possible:
+        */
+       T0 = data->preempt_timestamp;
+       T1 = ftrace_now(cpu);
+       delta = T1-T0;
+
+       local_save_flags(flags);
+
+       if (!report_latency(delta))
+               goto out;
+
+       spin_lock_irqsave(&max_trace_lock, flags);
+
+       /* check if we are still the max latency */
+       if (!report_latency(delta))
+               goto out_unlock;
+
+       trace_function(tr, data, CALLER_ADDR0, parent_ip, flags);
+
+       latency = nsecs_to_usecs(delta);
+
+       if (data->critical_sequence != max_sequence)
+               goto out_unlock;
+
+       tracing_max_latency = delta;
+       t0 = nsecs_to_usecs(T0);
+       t1 = nsecs_to_usecs(T1);
+
+       data->critical_end = parent_ip;
+
+       update_max_tr_single(tr, current, cpu);
+
+       max_sequence++;
+
+out_unlock:
+       spin_unlock_irqrestore(&max_trace_lock, flags);
+
+out:
+       data->critical_sequence = max_sequence;
+       data->preempt_timestamp = ftrace_now(cpu);
+       tracing_reset(data);
+       trace_function(tr, data, CALLER_ADDR0, parent_ip, flags);
+}
+
+static inline void
+start_critical_timing(unsigned long ip, unsigned long parent_ip)
+{
+       int cpu;
+       struct trace_array *tr = irqsoff_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+
+       if (likely(!tracer_enabled))
+               return;
+
+       cpu = raw_smp_processor_id();
+
+       if (per_cpu(tracing_cpu, cpu))
+               return;
+
+       data = tr->data[cpu];
+
+       if (unlikely(!data) || atomic_read(&data->disabled))
+               return;
+
+       atomic_inc(&data->disabled);
+
+       data->critical_sequence = max_sequence;
+       data->preempt_timestamp = ftrace_now(cpu);
+       data->critical_start = parent_ip ? : ip;
+       tracing_reset(data);
+
+       local_save_flags(flags);
+
+       trace_function(tr, data, ip, parent_ip, flags);
+
+       per_cpu(tracing_cpu, cpu) = 1;
+
+       atomic_dec(&data->disabled);
+}
+
+static inline void
+stop_critical_timing(unsigned long ip, unsigned long parent_ip)
+{
+       int cpu;
+       struct trace_array *tr = irqsoff_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+
+       cpu = raw_smp_processor_id();
+       /* Always clear the tracing cpu on stopping the trace */
+       if (unlikely(per_cpu(tracing_cpu, cpu)))
+               per_cpu(tracing_cpu, cpu) = 0;
+       else
+               return;
+
+       if (!tracer_enabled)
+               return;
+
+       data = tr->data[cpu];
+
+       if (unlikely(!data) || unlikely(!head_page(data)) ||
+           !data->critical_start || atomic_read(&data->disabled))
+               return;
+
+       atomic_inc(&data->disabled);
+
+       local_save_flags(flags);
+       trace_function(tr, data, ip, parent_ip, flags);
+       check_critical_timing(tr, data, parent_ip ? : ip, cpu);
+       data->critical_start = 0;
+       atomic_dec(&data->disabled);
+}
+
+/* start and stop critical timings used to for stoppage (in idle) */
+void start_critical_timings(void)
+{
+       if (preempt_trace() || irq_trace())
+               start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
+}
+
+void stop_critical_timings(void)
+{
+       if (preempt_trace() || irq_trace())
+               stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
+}
+
+#ifdef CONFIG_IRQSOFF_TRACER
+#ifdef CONFIG_PROVE_LOCKING
+void time_hardirqs_on(unsigned long a0, unsigned long a1)
+{
+       if (!preempt_trace() && irq_trace())
+               stop_critical_timing(a0, a1);
+}
+
+void time_hardirqs_off(unsigned long a0, unsigned long a1)
+{
+       if (!preempt_trace() && irq_trace())
+               start_critical_timing(a0, a1);
+}
+
+#else /* !CONFIG_PROVE_LOCKING */
+
+/*
+ * Stubs:
+ */
+
+void early_boot_irqs_off(void)
+{
+}
+
+void early_boot_irqs_on(void)
+{
+}
+
+void trace_softirqs_on(unsigned long ip)
+{
+}
+
+void trace_softirqs_off(unsigned long ip)
+{
+}
+
+inline void print_irqtrace_events(struct task_struct *curr)
+{
+}
+
+/*
+ * We are only interested in hardirq on/off events:
+ */
+void trace_hardirqs_on(void)
+{
+       if (!preempt_trace() && irq_trace())
+               stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
+}
+EXPORT_SYMBOL(trace_hardirqs_on);
+
+void trace_hardirqs_off(void)
+{
+       if (!preempt_trace() && irq_trace())
+               start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
+}
+EXPORT_SYMBOL(trace_hardirqs_off);
+
+void trace_hardirqs_on_caller(unsigned long caller_addr)
+{
+       if (!preempt_trace() && irq_trace())
+               stop_critical_timing(CALLER_ADDR0, caller_addr);
+}
+EXPORT_SYMBOL(trace_hardirqs_on_caller);
+
+void trace_hardirqs_off_caller(unsigned long caller_addr)
+{
+       if (!preempt_trace() && irq_trace())
+               start_critical_timing(CALLER_ADDR0, caller_addr);
+}
+EXPORT_SYMBOL(trace_hardirqs_off_caller);
+
+#endif /* CONFIG_PROVE_LOCKING */
+#endif /*  CONFIG_IRQSOFF_TRACER */
+
+#ifdef CONFIG_PREEMPT_TRACER
+void trace_preempt_on(unsigned long a0, unsigned long a1)
+{
+       stop_critical_timing(a0, a1);
+}
+
+void trace_preempt_off(unsigned long a0, unsigned long a1)
+{
+       start_critical_timing(a0, a1);
+}
+#endif /* CONFIG_PREEMPT_TRACER */
+
+static void start_irqsoff_tracer(struct trace_array *tr)
+{
+       register_ftrace_function(&trace_ops);
+       tracer_enabled = 1;
+}
+
+static void stop_irqsoff_tracer(struct trace_array *tr)
+{
+       tracer_enabled = 0;
+       unregister_ftrace_function(&trace_ops);
+}
+
+static void __irqsoff_tracer_init(struct trace_array *tr)
+{
+       irqsoff_trace = tr;
+       /* make sure that the tracer is visible */
+       smp_wmb();
+
+       if (tr->ctrl)
+               start_irqsoff_tracer(tr);
+}
+
+static void irqsoff_tracer_reset(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               stop_irqsoff_tracer(tr);
+}
+
+static void irqsoff_tracer_ctrl_update(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               start_irqsoff_tracer(tr);
+       else
+               stop_irqsoff_tracer(tr);
+}
+
+static void irqsoff_tracer_open(struct trace_iterator *iter)
+{
+       /* stop the trace while dumping */
+       if (iter->tr->ctrl)
+               stop_irqsoff_tracer(iter->tr);
+}
+
+static void irqsoff_tracer_close(struct trace_iterator *iter)
+{
+       if (iter->tr->ctrl)
+               start_irqsoff_tracer(iter->tr);
+}
+
+#ifdef CONFIG_IRQSOFF_TRACER
+static void irqsoff_tracer_init(struct trace_array *tr)
+{
+       trace_type = TRACER_IRQS_OFF;
+
+       __irqsoff_tracer_init(tr);
+}
+static struct tracer irqsoff_tracer __read_mostly =
+{
+       .name           = "irqsoff",
+       .init           = irqsoff_tracer_init,
+       .reset          = irqsoff_tracer_reset,
+       .open           = irqsoff_tracer_open,
+       .close          = irqsoff_tracer_close,
+       .ctrl_update    = irqsoff_tracer_ctrl_update,
+       .print_max      = 1,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_irqsoff,
+#endif
+};
+# define register_irqsoff(trace) register_tracer(&trace)
+#else
+# define register_irqsoff(trace) do { } while (0)
+#endif
+
+#ifdef CONFIG_PREEMPT_TRACER
+static void preemptoff_tracer_init(struct trace_array *tr)
+{
+       trace_type = TRACER_PREEMPT_OFF;
+
+       __irqsoff_tracer_init(tr);
+}
+
+static struct tracer preemptoff_tracer __read_mostly =
+{
+       .name           = "preemptoff",
+       .init           = preemptoff_tracer_init,
+       .reset          = irqsoff_tracer_reset,
+       .open           = irqsoff_tracer_open,
+       .close          = irqsoff_tracer_close,
+       .ctrl_update    = irqsoff_tracer_ctrl_update,
+       .print_max      = 1,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_preemptoff,
+#endif
+};
+# define register_preemptoff(trace) register_tracer(&trace)
+#else
+# define register_preemptoff(trace) do { } while (0)
+#endif
+
+#if defined(CONFIG_IRQSOFF_TRACER) && \
+       defined(CONFIG_PREEMPT_TRACER)
+
+static void preemptirqsoff_tracer_init(struct trace_array *tr)
+{
+       trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
+
+       __irqsoff_tracer_init(tr);
+}
+
+static struct tracer preemptirqsoff_tracer __read_mostly =
+{
+       .name           = "preemptirqsoff",
+       .init           = preemptirqsoff_tracer_init,
+       .reset          = irqsoff_tracer_reset,
+       .open           = irqsoff_tracer_open,
+       .close          = irqsoff_tracer_close,
+       .ctrl_update    = irqsoff_tracer_ctrl_update,
+       .print_max      = 1,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_preemptirqsoff,
+#endif
+};
+
+# define register_preemptirqsoff(trace) register_tracer(&trace)
+#else
+# define register_preemptirqsoff(trace) do { } while (0)
+#endif
+
+__init static int init_irqsoff_tracer(void)
+{
+       register_irqsoff(irqsoff_tracer);
+       register_preemptoff(preemptoff_tracer);
+       register_preemptirqsoff(preemptirqsoff_tracer);
+
+       return 0;
+}
+device_initcall(init_irqsoff_tracer);
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
new file mode 100644 (file)
index 0000000..b13dc19
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * Memory mapped I/O tracing
+ *
+ * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
+ */
+
+#define DEBUG 1
+
+#include <linux/kernel.h>
+#include <linux/mmiotrace.h>
+#include <linux/pci.h>
+
+#include "trace.h"
+
+struct header_iter {
+       struct pci_dev *dev;
+};
+
+static struct trace_array *mmio_trace_array;
+static bool overrun_detected;
+
+static void mmio_reset_data(struct trace_array *tr)
+{
+       int cpu;
+
+       overrun_detected = false;
+       tr->time_start = ftrace_now(tr->cpu);
+
+       for_each_online_cpu(cpu)
+               tracing_reset(tr->data[cpu]);
+}
+
+static void mmio_trace_init(struct trace_array *tr)
+{
+       pr_debug("in %s\n", __func__);
+       mmio_trace_array = tr;
+       if (tr->ctrl) {
+               mmio_reset_data(tr);
+               enable_mmiotrace();
+       }
+}
+
+static void mmio_trace_reset(struct trace_array *tr)
+{
+       pr_debug("in %s\n", __func__);
+       if (tr->ctrl)
+               disable_mmiotrace();
+       mmio_reset_data(tr);
+       mmio_trace_array = NULL;
+}
+
+static void mmio_trace_ctrl_update(struct trace_array *tr)
+{
+       pr_debug("in %s\n", __func__);
+       if (tr->ctrl) {
+               mmio_reset_data(tr);
+               enable_mmiotrace();
+       } else {
+               disable_mmiotrace();
+       }
+}
+
+static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
+{
+       int ret = 0;
+       int i;
+       resource_size_t start, end;
+       const struct pci_driver *drv = pci_dev_driver(dev);
+
+       /* XXX: incomplete checks for trace_seq_printf() return value */
+       ret += trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x",
+                               dev->bus->number, dev->devfn,
+                               dev->vendor, dev->device, dev->irq);
+       /*
+        * XXX: is pci_resource_to_user() appropriate, since we are
+        * supposed to interpret the __ioremap() phys_addr argument based on
+        * these printed values?
+        */
+       for (i = 0; i < 7; i++) {
+               pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
+               ret += trace_seq_printf(s, " %llx",
+                       (unsigned long long)(start |
+                       (dev->resource[i].flags & PCI_REGION_FLAG_MASK)));
+       }
+       for (i = 0; i < 7; i++) {
+               pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
+               ret += trace_seq_printf(s, " %llx",
+                       dev->resource[i].start < dev->resource[i].end ?
+                       (unsigned long long)(end - start) + 1 : 0);
+       }
+       if (drv)
+               ret += trace_seq_printf(s, " %s\n", drv->name);
+       else
+               ret += trace_seq_printf(s, " \n");
+       return ret;
+}
+
+static void destroy_header_iter(struct header_iter *hiter)
+{
+       if (!hiter)
+               return;
+       pci_dev_put(hiter->dev);
+       kfree(hiter);
+}
+
+static void mmio_pipe_open(struct trace_iterator *iter)
+{
+       struct header_iter *hiter;
+       struct trace_seq *s = &iter->seq;
+
+       trace_seq_printf(s, "VERSION 20070824\n");
+
+       hiter = kzalloc(sizeof(*hiter), GFP_KERNEL);
+       if (!hiter)
+               return;
+
+       hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
+       iter->private = hiter;
+}
+
+/* XXX: This is not called when the pipe is closed! */
+static void mmio_close(struct trace_iterator *iter)
+{
+       struct header_iter *hiter = iter->private;
+       destroy_header_iter(hiter);
+       iter->private = NULL;
+}
+
+static unsigned long count_overruns(struct trace_iterator *iter)
+{
+       int cpu;
+       unsigned long cnt = 0;
+       for_each_online_cpu(cpu) {
+               cnt += iter->overrun[cpu];
+               iter->overrun[cpu] = 0;
+       }
+       return cnt;
+}
+
+static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
+                               char __user *ubuf, size_t cnt, loff_t *ppos)
+{
+       ssize_t ret;
+       struct header_iter *hiter = iter->private;
+       struct trace_seq *s = &iter->seq;
+       unsigned long n;
+
+       n = count_overruns(iter);
+       if (n) {
+               /* XXX: This is later than where events were lost. */
+               trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n);
+               if (!overrun_detected)
+                       pr_warning("mmiotrace has lost events.\n");
+               overrun_detected = true;
+               goto print_out;
+       }
+
+       if (!hiter)
+               return 0;
+
+       mmio_print_pcidev(s, hiter->dev);
+       hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
+
+       if (!hiter->dev) {
+               destroy_header_iter(hiter);
+               iter->private = NULL;
+       }
+
+print_out:
+       ret = trace_seq_to_user(s, ubuf, cnt);
+       return (ret == -EBUSY) ? 0 : ret;
+}
+
+static int mmio_print_rw(struct trace_iterator *iter)
+{
+       struct trace_entry *entry = iter->ent;
+       struct mmiotrace_rw *rw = &entry->mmiorw;
+       struct trace_seq *s     = &iter->seq;
+       unsigned long long t    = ns2usecs(entry->t);
+       unsigned long usec_rem  = do_div(t, 1000000ULL);
+       unsigned secs           = (unsigned long)t;
+       int ret = 1;
+
+       switch (entry->mmiorw.opcode) {
+       case MMIO_READ:
+               ret = trace_seq_printf(s,
+                       "R %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
+                       rw->width, secs, usec_rem, rw->map_id,
+                       (unsigned long long)rw->phys,
+                       rw->value, rw->pc, 0);
+               break;
+       case MMIO_WRITE:
+               ret = trace_seq_printf(s,
+                       "W %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
+                       rw->width, secs, usec_rem, rw->map_id,
+                       (unsigned long long)rw->phys,
+                       rw->value, rw->pc, 0);
+               break;
+       case MMIO_UNKNOWN_OP:
+               ret = trace_seq_printf(s,
+                       "UNKNOWN %lu.%06lu %d 0x%llx %02x,%02x,%02x 0x%lx %d\n",
+                       secs, usec_rem, rw->map_id,
+                       (unsigned long long)rw->phys,
+                       (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
+                       (rw->value >> 0) & 0xff, rw->pc, 0);
+               break;
+       default:
+               ret = trace_seq_printf(s, "rw what?\n");
+               break;
+       }
+       if (ret)
+               return 1;
+       return 0;
+}
+
+static int mmio_print_map(struct trace_iterator *iter)
+{
+       struct trace_entry *entry = iter->ent;
+       struct mmiotrace_map *m = &entry->mmiomap;
+       struct trace_seq *s     = &iter->seq;
+       unsigned long long t    = ns2usecs(entry->t);
+       unsigned long usec_rem  = do_div(t, 1000000ULL);
+       unsigned secs           = (unsigned long)t;
+       int ret = 1;
+
+       switch (entry->mmiorw.opcode) {
+       case MMIO_PROBE:
+               ret = trace_seq_printf(s,
+                       "MAP %lu.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n",
+                       secs, usec_rem, m->map_id,
+                       (unsigned long long)m->phys, m->virt, m->len,
+                       0UL, 0);
+               break;
+       case MMIO_UNPROBE:
+               ret = trace_seq_printf(s,
+                       "UNMAP %lu.%06lu %d 0x%lx %d\n",
+                       secs, usec_rem, m->map_id, 0UL, 0);
+               break;
+       default:
+               ret = trace_seq_printf(s, "map what?\n");
+               break;
+       }
+       if (ret)
+               return 1;
+       return 0;
+}
+
+/* return 0 to abort printing without consuming current entry in pipe mode */
+static int mmio_print_line(struct trace_iterator *iter)
+{
+       switch (iter->ent->type) {
+       case TRACE_MMIO_RW:
+               return mmio_print_rw(iter);
+       case TRACE_MMIO_MAP:
+               return mmio_print_map(iter);
+       default:
+               return 1; /* ignore unknown entries */
+       }
+}
+
+static struct tracer mmio_tracer __read_mostly =
+{
+       .name           = "mmiotrace",
+       .init           = mmio_trace_init,
+       .reset          = mmio_trace_reset,
+       .pipe_open      = mmio_pipe_open,
+       .close          = mmio_close,
+       .read           = mmio_read,
+       .ctrl_update    = mmio_trace_ctrl_update,
+       .print_line     = mmio_print_line,
+};
+
+__init static int init_mmio_trace(void)
+{
+       return register_tracer(&mmio_tracer);
+}
+device_initcall(init_mmio_trace);
+
+void mmio_trace_rw(struct mmiotrace_rw *rw)
+{
+       struct trace_array *tr = mmio_trace_array;
+       struct trace_array_cpu *data = tr->data[smp_processor_id()];
+       __trace_mmiotrace_rw(tr, data, rw);
+}
+
+void mmio_trace_mapping(struct mmiotrace_map *map)
+{
+       struct trace_array *tr = mmio_trace_array;
+       struct trace_array_cpu *data;
+
+       preempt_disable();
+       data = tr->data[smp_processor_id()];
+       __trace_mmiotrace_map(tr, data, map);
+       preempt_enable();
+}
diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c
new file mode 100644 (file)
index 0000000..cb817a2
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * trace context switch
+ *
+ * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
+ *
+ */
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <linux/kallsyms.h>
+#include <linux/uaccess.h>
+#include <linux/marker.h>
+#include <linux/ftrace.h>
+
+#include "trace.h"
+
+static struct trace_array      *ctx_trace;
+static int __read_mostly       tracer_enabled;
+static atomic_t                        sched_ref;
+
+static void
+sched_switch_func(void *private, void *__rq, struct task_struct *prev,
+                       struct task_struct *next)
+{
+       struct trace_array **ptr = private;
+       struct trace_array *tr = *ptr;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       tracing_record_cmdline(prev);
+       tracing_record_cmdline(next);
+
+       if (!tracer_enabled)
+               return;
+
+       local_irq_save(flags);
+       cpu = raw_smp_processor_id();
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1))
+               tracing_sched_switch_trace(tr, data, prev, next, flags);
+
+       atomic_dec(&data->disabled);
+       local_irq_restore(flags);
+}
+
+static notrace void
+sched_switch_callback(void *probe_data, void *call_data,
+                     const char *format, va_list *args)
+{
+       struct task_struct *prev;
+       struct task_struct *next;
+       struct rq *__rq;
+
+       if (!atomic_read(&sched_ref))
+               return;
+
+       /* skip prev_pid %d next_pid %d prev_state %ld */
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, long);
+       __rq = va_arg(*args, typeof(__rq));
+       prev = va_arg(*args, typeof(prev));
+       next = va_arg(*args, typeof(next));
+
+       /*
+        * If tracer_switch_func only points to the local
+        * switch func, it still needs the ptr passed to it.
+        */
+       sched_switch_func(probe_data, __rq, prev, next);
+}
+
+static void
+wakeup_func(void *private, void *__rq, struct task_struct *wakee, struct
+                       task_struct *curr)
+{
+       struct trace_array **ptr = private;
+       struct trace_array *tr = *ptr;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       if (!tracer_enabled)
+               return;
+
+       tracing_record_cmdline(curr);
+
+       local_irq_save(flags);
+       cpu = raw_smp_processor_id();
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1))
+               tracing_sched_wakeup_trace(tr, data, wakee, curr, flags);
+
+       atomic_dec(&data->disabled);
+       local_irq_restore(flags);
+}
+
+static notrace void
+wake_up_callback(void *probe_data, void *call_data,
+                const char *format, va_list *args)
+{
+       struct task_struct *curr;
+       struct task_struct *task;
+       struct rq *__rq;
+
+       if (likely(!tracer_enabled))
+               return;
+
+       /* Skip pid %d state %ld */
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, long);
+       /* now get the meat: "rq %p task %p rq->curr %p" */
+       __rq = va_arg(*args, typeof(__rq));
+       task = va_arg(*args, typeof(task));
+       curr = va_arg(*args, typeof(curr));
+
+       tracing_record_cmdline(task);
+       tracing_record_cmdline(curr);
+
+       wakeup_func(probe_data, __rq, task, curr);
+}
+
+static void sched_switch_reset(struct trace_array *tr)
+{
+       int cpu;
+
+       tr->time_start = ftrace_now(tr->cpu);
+
+       for_each_online_cpu(cpu)
+               tracing_reset(tr->data[cpu]);
+}
+
+static int tracing_sched_register(void)
+{
+       int ret;
+
+       ret = marker_probe_register("kernel_sched_wakeup",
+                       "pid %d state %ld ## rq %p task %p rq->curr %p",
+                       wake_up_callback,
+                       &ctx_trace);
+       if (ret) {
+               pr_info("wakeup trace: Couldn't add marker"
+                       " probe to kernel_sched_wakeup\n");
+               return ret;
+       }
+
+       ret = marker_probe_register("kernel_sched_wakeup_new",
+                       "pid %d state %ld ## rq %p task %p rq->curr %p",
+                       wake_up_callback,
+                       &ctx_trace);
+       if (ret) {
+               pr_info("wakeup trace: Couldn't add marker"
+                       " probe to kernel_sched_wakeup_new\n");
+               goto fail_deprobe;
+       }
+
+       ret = marker_probe_register("kernel_sched_schedule",
+               "prev_pid %d next_pid %d prev_state %ld "
+               "## rq %p prev %p next %p",
+               sched_switch_callback,
+               &ctx_trace);
+       if (ret) {
+               pr_info("sched trace: Couldn't add marker"
+                       " probe to kernel_sched_schedule\n");
+               goto fail_deprobe_wake_new;
+       }
+
+       return ret;
+fail_deprobe_wake_new:
+       marker_probe_unregister("kernel_sched_wakeup_new",
+                               wake_up_callback,
+                               &ctx_trace);
+fail_deprobe:
+       marker_probe_unregister("kernel_sched_wakeup",
+                               wake_up_callback,
+                               &ctx_trace);
+       return ret;
+}
+
+static void tracing_sched_unregister(void)
+{
+       marker_probe_unregister("kernel_sched_schedule",
+                               sched_switch_callback,
+                               &ctx_trace);
+       marker_probe_unregister("kernel_sched_wakeup_new",
+                               wake_up_callback,
+                               &ctx_trace);
+       marker_probe_unregister("kernel_sched_wakeup",
+                               wake_up_callback,
+                               &ctx_trace);
+}
+
+static void tracing_start_sched_switch(void)
+{
+       long ref;
+
+       ref = atomic_inc_return(&sched_ref);
+       if (ref == 1)
+               tracing_sched_register();
+}
+
+static void tracing_stop_sched_switch(void)
+{
+       long ref;
+
+       ref = atomic_dec_and_test(&sched_ref);
+       if (ref)
+               tracing_sched_unregister();
+}
+
+void tracing_start_cmdline_record(void)
+{
+       tracing_start_sched_switch();
+}
+
+void tracing_stop_cmdline_record(void)
+{
+       tracing_stop_sched_switch();
+}
+
+static void start_sched_trace(struct trace_array *tr)
+{
+       sched_switch_reset(tr);
+       tracing_start_cmdline_record();
+       tracer_enabled = 1;
+}
+
+static void stop_sched_trace(struct trace_array *tr)
+{
+       tracer_enabled = 0;
+       tracing_stop_cmdline_record();
+}
+
+static void sched_switch_trace_init(struct trace_array *tr)
+{
+       ctx_trace = tr;
+
+       if (tr->ctrl)
+               start_sched_trace(tr);
+}
+
+static void sched_switch_trace_reset(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               stop_sched_trace(tr);
+}
+
+static void sched_switch_trace_ctrl_update(struct trace_array *tr)
+{
+       /* When starting a new trace, reset the buffers */
+       if (tr->ctrl)
+               start_sched_trace(tr);
+       else
+               stop_sched_trace(tr);
+}
+
+static struct tracer sched_switch_trace __read_mostly =
+{
+       .name           = "sched_switch",
+       .init           = sched_switch_trace_init,
+       .reset          = sched_switch_trace_reset,
+       .ctrl_update    = sched_switch_trace_ctrl_update,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_sched_switch,
+#endif
+};
+
+__init static int init_sched_switch_trace(void)
+{
+       int ret = 0;
+
+       if (atomic_read(&sched_ref))
+               ret = tracing_sched_register();
+       if (ret) {
+               pr_info("error registering scheduler trace\n");
+               return ret;
+       }
+       return register_tracer(&sched_switch_trace);
+}
+device_initcall(init_sched_switch_trace);
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
new file mode 100644 (file)
index 0000000..3c8d61d
--- /dev/null
@@ -0,0 +1,448 @@
+/*
+ * trace task wakeup timings
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
+ *
+ * Based on code from the latency_tracer, that is:
+ *
+ *  Copyright (C) 2004-2006 Ingo Molnar
+ *  Copyright (C) 2004 William Lee Irwin III
+ */
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <linux/kallsyms.h>
+#include <linux/uaccess.h>
+#include <linux/ftrace.h>
+#include <linux/marker.h>
+
+#include "trace.h"
+
+static struct trace_array      *wakeup_trace;
+static int __read_mostly       tracer_enabled;
+
+static struct task_struct      *wakeup_task;
+static int                     wakeup_cpu;
+static unsigned                        wakeup_prio = -1;
+
+static DEFINE_SPINLOCK(wakeup_lock);
+
+static void __wakeup_reset(struct trace_array *tr);
+
+#ifdef CONFIG_FTRACE
+/*
+ * irqsoff uses its own tracer function to keep the overhead down:
+ */
+static void
+wakeup_tracer_call(unsigned long ip, unsigned long parent_ip)
+{
+       struct trace_array *tr = wakeup_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int resched;
+       int cpu;
+
+       if (likely(!wakeup_task))
+               return;
+
+       resched = need_resched();
+       preempt_disable_notrace();
+
+       cpu = raw_smp_processor_id();
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+       if (unlikely(disabled != 1))
+               goto out;
+
+       spin_lock_irqsave(&wakeup_lock, flags);
+
+       if (unlikely(!wakeup_task))
+               goto unlock;
+
+       /*
+        * The task can't disappear because it needs to
+        * wake up first, and we have the wakeup_lock.
+        */
+       if (task_cpu(wakeup_task) != cpu)
+               goto unlock;
+
+       trace_function(tr, data, ip, parent_ip, flags);
+
+ unlock:
+       spin_unlock_irqrestore(&wakeup_lock, flags);
+
+ out:
+       atomic_dec(&data->disabled);
+
+       /*
+        * To prevent recursion from the scheduler, if the
+        * resched flag was set before we entered, then
+        * don't reschedule.
+        */
+       if (resched)
+               preempt_enable_no_resched_notrace();
+       else
+               preempt_enable_notrace();
+}
+
+static struct ftrace_ops trace_ops __read_mostly =
+{
+       .func = wakeup_tracer_call,
+};
+#endif /* CONFIG_FTRACE */
+
+/*
+ * Should this new latency be reported/recorded?
+ */
+static int report_latency(cycle_t delta)
+{
+       if (tracing_thresh) {
+               if (delta < tracing_thresh)
+                       return 0;
+       } else {
+               if (delta <= tracing_max_latency)
+                       return 0;
+       }
+       return 1;
+}
+
+static void notrace
+wakeup_sched_switch(void *private, void *rq, struct task_struct *prev,
+       struct task_struct *next)
+{
+       unsigned long latency = 0, t0 = 0, t1 = 0;
+       struct trace_array **ptr = private;
+       struct trace_array *tr = *ptr;
+       struct trace_array_cpu *data;
+       cycle_t T0, T1, delta;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+
+       if (unlikely(!tracer_enabled))
+               return;
+
+       /*
+        * When we start a new trace, we set wakeup_task to NULL
+        * and then set tracer_enabled = 1. We want to make sure
+        * that another CPU does not see the tracer_enabled = 1
+        * and the wakeup_task with an older task, that might
+        * actually be the same as next.
+        */
+       smp_rmb();
+
+       if (next != wakeup_task)
+               return;
+
+       /* The task we are waiting for is waking up */
+       data = tr->data[wakeup_cpu];
+
+       /* disable local data, not wakeup_cpu data */
+       cpu = raw_smp_processor_id();
+       disabled = atomic_inc_return(&tr->data[cpu]->disabled);
+       if (likely(disabled != 1))
+               goto out;
+
+       spin_lock_irqsave(&wakeup_lock, flags);
+
+       /* We could race with grabbing wakeup_lock */
+       if (unlikely(!tracer_enabled || next != wakeup_task))
+               goto out_unlock;
+
+       trace_function(tr, data, CALLER_ADDR1, CALLER_ADDR2, flags);
+
+       /*
+        * usecs conversion is slow so we try to delay the conversion
+        * as long as possible:
+        */
+       T0 = data->preempt_timestamp;
+       T1 = ftrace_now(cpu);
+       delta = T1-T0;
+
+       if (!report_latency(delta))
+               goto out_unlock;
+
+       latency = nsecs_to_usecs(delta);
+
+       tracing_max_latency = delta;
+       t0 = nsecs_to_usecs(T0);
+       t1 = nsecs_to_usecs(T1);
+
+       update_max_tr(tr, wakeup_task, wakeup_cpu);
+
+out_unlock:
+       __wakeup_reset(tr);
+       spin_unlock_irqrestore(&wakeup_lock, flags);
+out:
+       atomic_dec(&tr->data[cpu]->disabled);
+}
+
+static notrace void
+sched_switch_callback(void *probe_data, void *call_data,
+                     const char *format, va_list *args)
+{
+       struct task_struct *prev;
+       struct task_struct *next;
+       struct rq *__rq;
+
+       /* skip prev_pid %d next_pid %d prev_state %ld */
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, long);
+       __rq = va_arg(*args, typeof(__rq));
+       prev = va_arg(*args, typeof(prev));
+       next = va_arg(*args, typeof(next));
+
+       tracing_record_cmdline(prev);
+
+       /*
+        * If tracer_switch_func only points to the local
+        * switch func, it still needs the ptr passed to it.
+        */
+       wakeup_sched_switch(probe_data, __rq, prev, next);
+}
+
+static void __wakeup_reset(struct trace_array *tr)
+{
+       struct trace_array_cpu *data;
+       int cpu;
+
+       assert_spin_locked(&wakeup_lock);
+
+       for_each_possible_cpu(cpu) {
+               data = tr->data[cpu];
+               tracing_reset(data);
+       }
+
+       wakeup_cpu = -1;
+       wakeup_prio = -1;
+
+       if (wakeup_task)
+               put_task_struct(wakeup_task);
+
+       wakeup_task = NULL;
+}
+
+static void wakeup_reset(struct trace_array *tr)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&wakeup_lock, flags);
+       __wakeup_reset(tr);
+       spin_unlock_irqrestore(&wakeup_lock, flags);
+}
+
+static void
+wakeup_check_start(struct trace_array *tr, struct task_struct *p,
+                  struct task_struct *curr)
+{
+       int cpu = smp_processor_id();
+       unsigned long flags;
+       long disabled;
+
+       if (likely(!rt_task(p)) ||
+                       p->prio >= wakeup_prio ||
+                       p->prio >= curr->prio)
+               return;
+
+       disabled = atomic_inc_return(&tr->data[cpu]->disabled);
+       if (unlikely(disabled != 1))
+               goto out;
+
+       /* interrupts should be off from try_to_wake_up */
+       spin_lock(&wakeup_lock);
+
+       /* check for races. */
+       if (!tracer_enabled || p->prio >= wakeup_prio)
+               goto out_locked;
+
+       /* reset the trace */
+       __wakeup_reset(tr);
+
+       wakeup_cpu = task_cpu(p);
+       wakeup_prio = p->prio;
+
+       wakeup_task = p;
+       get_task_struct(wakeup_task);
+
+       local_save_flags(flags);
+
+       tr->data[wakeup_cpu]->preempt_timestamp = ftrace_now(cpu);
+       trace_function(tr, tr->data[wakeup_cpu],
+                      CALLER_ADDR1, CALLER_ADDR2, flags);
+
+out_locked:
+       spin_unlock(&wakeup_lock);
+out:
+       atomic_dec(&tr->data[cpu]->disabled);
+}
+
+static notrace void
+wake_up_callback(void *probe_data, void *call_data,
+                const char *format, va_list *args)
+{
+       struct trace_array **ptr = probe_data;
+       struct trace_array *tr = *ptr;
+       struct task_struct *curr;
+       struct task_struct *task;
+       struct rq *__rq;
+
+       if (likely(!tracer_enabled))
+               return;
+
+       /* Skip pid %d state %ld */
+       (void)va_arg(*args, int);
+       (void)va_arg(*args, long);
+       /* now get the meat: "rq %p task %p rq->curr %p" */
+       __rq = va_arg(*args, typeof(__rq));
+       task = va_arg(*args, typeof(task));
+       curr = va_arg(*args, typeof(curr));
+
+       tracing_record_cmdline(task);
+       tracing_record_cmdline(curr);
+
+       wakeup_check_start(tr, task, curr);
+}
+
+static void start_wakeup_tracer(struct trace_array *tr)
+{
+       int ret;
+
+       ret = marker_probe_register("kernel_sched_wakeup",
+                       "pid %d state %ld ## rq %p task %p rq->curr %p",
+                       wake_up_callback,
+                       &wakeup_trace);
+       if (ret) {
+               pr_info("wakeup trace: Couldn't add marker"
+                       " probe to kernel_sched_wakeup\n");
+               return;
+       }
+
+       ret = marker_probe_register("kernel_sched_wakeup_new",
+                       "pid %d state %ld ## rq %p task %p rq->curr %p",
+                       wake_up_callback,
+                       &wakeup_trace);
+       if (ret) {
+               pr_info("wakeup trace: Couldn't add marker"
+                       " probe to kernel_sched_wakeup_new\n");
+               goto fail_deprobe;
+       }
+
+       ret = marker_probe_register("kernel_sched_schedule",
+               "prev_pid %d next_pid %d prev_state %ld "
+               "## rq %p prev %p next %p",
+               sched_switch_callback,
+               &wakeup_trace);
+       if (ret) {
+               pr_info("sched trace: Couldn't add marker"
+                       " probe to kernel_sched_schedule\n");
+               goto fail_deprobe_wake_new;
+       }
+
+       wakeup_reset(tr);
+
+       /*
+        * Don't let the tracer_enabled = 1 show up before
+        * the wakeup_task is reset. This may be overkill since
+        * wakeup_reset does a spin_unlock after setting the
+        * wakeup_task to NULL, but I want to be safe.
+        * This is a slow path anyway.
+        */
+       smp_wmb();
+
+       register_ftrace_function(&trace_ops);
+
+       tracer_enabled = 1;
+
+       return;
+fail_deprobe_wake_new:
+       marker_probe_unregister("kernel_sched_wakeup_new",
+                               wake_up_callback,
+                               &wakeup_trace);
+fail_deprobe:
+       marker_probe_unregister("kernel_sched_wakeup",
+                               wake_up_callback,
+                               &wakeup_trace);
+}
+
+static void stop_wakeup_tracer(struct trace_array *tr)
+{
+       tracer_enabled = 0;
+       unregister_ftrace_function(&trace_ops);
+       marker_probe_unregister("kernel_sched_schedule",
+                               sched_switch_callback,
+                               &wakeup_trace);
+       marker_probe_unregister("kernel_sched_wakeup_new",
+                               wake_up_callback,
+                               &wakeup_trace);
+       marker_probe_unregister("kernel_sched_wakeup",
+                               wake_up_callback,
+                               &wakeup_trace);
+}
+
+static void wakeup_tracer_init(struct trace_array *tr)
+{
+       wakeup_trace = tr;
+
+       if (tr->ctrl)
+               start_wakeup_tracer(tr);
+}
+
+static void wakeup_tracer_reset(struct trace_array *tr)
+{
+       if (tr->ctrl) {
+               stop_wakeup_tracer(tr);
+               /* make sure we put back any tasks we are tracing */
+               wakeup_reset(tr);
+       }
+}
+
+static void wakeup_tracer_ctrl_update(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               start_wakeup_tracer(tr);
+       else
+               stop_wakeup_tracer(tr);
+}
+
+static void wakeup_tracer_open(struct trace_iterator *iter)
+{
+       /* stop the trace while dumping */
+       if (iter->tr->ctrl)
+               stop_wakeup_tracer(iter->tr);
+}
+
+static void wakeup_tracer_close(struct trace_iterator *iter)
+{
+       /* forget about any processes we were recording */
+       if (iter->tr->ctrl)
+               start_wakeup_tracer(iter->tr);
+}
+
+static struct tracer wakeup_tracer __read_mostly =
+{
+       .name           = "wakeup",
+       .init           = wakeup_tracer_init,
+       .reset          = wakeup_tracer_reset,
+       .open           = wakeup_tracer_open,
+       .close          = wakeup_tracer_close,
+       .ctrl_update    = wakeup_tracer_ctrl_update,
+       .print_max      = 1,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_wakeup,
+#endif
+};
+
+__init static int init_wakeup_tracer(void)
+{
+       int ret;
+
+       ret = register_tracer(&wakeup_tracer);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+device_initcall(init_wakeup_tracer);
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c
new file mode 100644 (file)
index 0000000..0911b7e
--- /dev/null
@@ -0,0 +1,563 @@
+/* Include in trace.c */
+
+#include <linux/kthread.h>
+#include <linux/delay.h>
+
+static inline int trace_valid_entry(struct trace_entry *entry)
+{
+       switch (entry->type) {
+       case TRACE_FN:
+       case TRACE_CTX:
+       case TRACE_WAKE:
+       case TRACE_STACK:
+       case TRACE_SPECIAL:
+               return 1;
+       }
+       return 0;
+}
+
+static int
+trace_test_buffer_cpu(struct trace_array *tr, struct trace_array_cpu *data)
+{
+       struct trace_entry *entries;
+       struct page *page;
+       int idx = 0;
+       int i;
+
+       BUG_ON(list_empty(&data->trace_pages));
+       page = list_entry(data->trace_pages.next, struct page, lru);
+       entries = page_address(page);
+
+       check_pages(data);
+       if (head_page(data) != entries)
+               goto failed;
+
+       /*
+        * The starting trace buffer always has valid elements,
+        * if any element exists.
+        */
+       entries = head_page(data);
+
+       for (i = 0; i < tr->entries; i++) {
+
+               if (i < data->trace_idx && !trace_valid_entry(&entries[idx])) {
+                       printk(KERN_CONT ".. invalid entry %d ",
+                               entries[idx].type);
+                       goto failed;
+               }
+
+               idx++;
+               if (idx >= ENTRIES_PER_PAGE) {
+                       page = virt_to_page(entries);
+                       if (page->lru.next == &data->trace_pages) {
+                               if (i != tr->entries - 1) {
+                                       printk(KERN_CONT ".. entries buffer mismatch");
+                                       goto failed;
+                               }
+                       } else {
+                               page = list_entry(page->lru.next, struct page, lru);
+                               entries = page_address(page);
+                       }
+                       idx = 0;
+               }
+       }
+
+       page = virt_to_page(entries);
+       if (page->lru.next != &data->trace_pages) {
+               printk(KERN_CONT ".. too many entries");
+               goto failed;
+       }
+
+       return 0;
+
+ failed:
+       /* disable tracing */
+       tracing_disabled = 1;
+       printk(KERN_CONT ".. corrupted trace buffer .. ");
+       return -1;
+}
+
+/*
+ * Test the trace buffer to see if all the elements
+ * are still sane.
+ */
+static int trace_test_buffer(struct trace_array *tr, unsigned long *count)
+{
+       unsigned long flags, cnt = 0;
+       int cpu, ret = 0;
+
+       /* Don't allow flipping of max traces now */
+       raw_local_irq_save(flags);
+       __raw_spin_lock(&ftrace_max_lock);
+       for_each_possible_cpu(cpu) {
+               if (!head_page(tr->data[cpu]))
+                       continue;
+
+               cnt += tr->data[cpu]->trace_idx;
+
+               ret = trace_test_buffer_cpu(tr, tr->data[cpu]);
+               if (ret)
+                       break;
+       }
+       __raw_spin_unlock(&ftrace_max_lock);
+       raw_local_irq_restore(flags);
+
+       if (count)
+               *count = cnt;
+
+       return ret;
+}
+
+#ifdef CONFIG_FTRACE
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+
+#define __STR(x) #x
+#define STR(x) __STR(x)
+
+/* Test dynamic code modification and ftrace filters */
+int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
+                                          struct trace_array *tr,
+                                          int (*func)(void))
+{
+       unsigned long count;
+       int ret;
+       int save_ftrace_enabled = ftrace_enabled;
+       int save_tracer_enabled = tracer_enabled;
+       char *func_name;
+
+       /* The ftrace test PASSED */
+       printk(KERN_CONT "PASSED\n");
+       pr_info("Testing dynamic ftrace: ");
+
+       /* enable tracing, and record the filter function */
+       ftrace_enabled = 1;
+       tracer_enabled = 1;
+
+       /* passed in by parameter to fool gcc from optimizing */
+       func();
+
+       /* update the records */
+       ret = ftrace_force_update();
+       if (ret) {
+               printk(KERN_CONT ".. ftraced failed .. ");
+               return ret;
+       }
+
+       /*
+        * Some archs *cough*PowerPC*cough* add charachters to the
+        * start of the function names. We simply put a '*' to
+        * accomodate them.
+        */
+       func_name = "*" STR(DYN_FTRACE_TEST_NAME);
+
+       /* filter only on our function */
+       ftrace_set_filter(func_name, strlen(func_name), 1);
+
+       /* enable tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* Sleep for a 1/10 of a second */
+       msleep(100);
+
+       /* we should have nothing in the buffer */
+       ret = trace_test_buffer(tr, &count);
+       if (ret)
+               goto out;
+
+       if (count) {
+               ret = -1;
+               printk(KERN_CONT ".. filter did not filter .. ");
+               goto out;
+       }
+
+       /* call our function again */
+       func();
+
+       /* sleep again */
+       msleep(100);
+
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       ftrace_enabled = 0;
+
+       /* check the trace buffer */
+       ret = trace_test_buffer(tr, &count);
+       trace->reset(tr);
+
+       /* we should only have one item */
+       if (!ret && count != 1) {
+               printk(KERN_CONT ".. filter failed count=%ld ..", count);
+               ret = -1;
+               goto out;
+       }
+ out:
+       ftrace_enabled = save_ftrace_enabled;
+       tracer_enabled = save_tracer_enabled;
+
+       /* Enable tracing on all functions again */
+       ftrace_set_filter(NULL, 0, 1);
+
+       return ret;
+}
+#else
+# define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
+#endif /* CONFIG_DYNAMIC_FTRACE */
+/*
+ * Simple verification test of ftrace function tracer.
+ * Enable ftrace, sleep 1/10 second, and then read the trace
+ * buffer to see if all is in order.
+ */
+int
+trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long count;
+       int ret;
+       int save_ftrace_enabled = ftrace_enabled;
+       int save_tracer_enabled = tracer_enabled;
+
+       /* make sure msleep has been recorded */
+       msleep(1);
+
+       /* force the recorded functions to be traced */
+       ret = ftrace_force_update();
+       if (ret) {
+               printk(KERN_CONT ".. ftraced failed .. ");
+               return ret;
+       }
+
+       /* start the tracing */
+       ftrace_enabled = 1;
+       tracer_enabled = 1;
+
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* Sleep for a 1/10 of a second */
+       msleep(100);
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       ftrace_enabled = 0;
+
+       /* check the trace buffer */
+       ret = trace_test_buffer(tr, &count);
+       trace->reset(tr);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+               goto out;
+       }
+
+       ret = trace_selftest_startup_dynamic_tracing(trace, tr,
+                                                    DYN_FTRACE_TEST_NAME);
+
+ out:
+       ftrace_enabled = save_ftrace_enabled;
+       tracer_enabled = save_tracer_enabled;
+
+       /* kill ftrace totally if we failed */
+       if (ret)
+               ftrace_kill();
+
+       return ret;
+}
+#endif /* CONFIG_FTRACE */
+
+#ifdef CONFIG_IRQSOFF_TRACER
+int
+trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long save_max = tracing_max_latency;
+       unsigned long count;
+       int ret;
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* reset the max latency */
+       tracing_max_latency = 0;
+       /* disable interrupts for a bit */
+       local_irq_disable();
+       udelay(100);
+       local_irq_enable();
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check both trace buffers */
+       ret = trace_test_buffer(tr, NULL);
+       if (!ret)
+               ret = trace_test_buffer(&max_tr, &count);
+       trace->reset(tr);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+       }
+
+       tracing_max_latency = save_max;
+
+       return ret;
+}
+#endif /* CONFIG_IRQSOFF_TRACER */
+
+#ifdef CONFIG_PREEMPT_TRACER
+int
+trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long save_max = tracing_max_latency;
+       unsigned long count;
+       int ret;
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* reset the max latency */
+       tracing_max_latency = 0;
+       /* disable preemption for a bit */
+       preempt_disable();
+       udelay(100);
+       preempt_enable();
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check both trace buffers */
+       ret = trace_test_buffer(tr, NULL);
+       if (!ret)
+               ret = trace_test_buffer(&max_tr, &count);
+       trace->reset(tr);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+       }
+
+       tracing_max_latency = save_max;
+
+       return ret;
+}
+#endif /* CONFIG_PREEMPT_TRACER */
+
+#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
+int
+trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long save_max = tracing_max_latency;
+       unsigned long count;
+       int ret;
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+
+       /* reset the max latency */
+       tracing_max_latency = 0;
+
+       /* disable preemption and interrupts for a bit */
+       preempt_disable();
+       local_irq_disable();
+       udelay(100);
+       preempt_enable();
+       /* reverse the order of preempt vs irqs */
+       local_irq_enable();
+
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check both trace buffers */
+       ret = trace_test_buffer(tr, NULL);
+       if (ret)
+               goto out;
+
+       ret = trace_test_buffer(&max_tr, &count);
+       if (ret)
+               goto out;
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+               goto out;
+       }
+
+       /* do the test by disabling interrupts first this time */
+       tracing_max_latency = 0;
+       tr->ctrl = 1;
+       trace->ctrl_update(tr);
+       preempt_disable();
+       local_irq_disable();
+       udelay(100);
+       preempt_enable();
+       /* reverse the order of preempt vs irqs */
+       local_irq_enable();
+
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check both trace buffers */
+       ret = trace_test_buffer(tr, NULL);
+       if (ret)
+               goto out;
+
+       ret = trace_test_buffer(&max_tr, &count);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+               goto out;
+       }
+
+ out:
+       trace->reset(tr);
+       tracing_max_latency = save_max;
+
+       return ret;
+}
+#endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
+
+#ifdef CONFIG_SCHED_TRACER
+static int trace_wakeup_test_thread(void *data)
+{
+       /* Make this a RT thread, doesn't need to be too high */
+       struct sched_param param = { .sched_priority = 5 };
+       struct completion *x = data;
+
+       sched_setscheduler(current, SCHED_FIFO, &param);
+
+       /* Make it know we have a new prio */
+       complete(x);
+
+       /* now go to sleep and let the test wake us up */
+       set_current_state(TASK_INTERRUPTIBLE);
+       schedule();
+
+       /* we are awake, now wait to disappear */
+       while (!kthread_should_stop()) {
+               /*
+                * This is an RT task, do short sleeps to let
+                * others run.
+                */
+               msleep(100);
+       }
+
+       return 0;
+}
+
+int
+trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long save_max = tracing_max_latency;
+       struct task_struct *p;
+       struct completion isrt;
+       unsigned long count;
+       int ret;
+
+       init_completion(&isrt);
+
+       /* create a high prio thread */
+       p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test");
+       if (IS_ERR(p)) {
+               printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
+               return -1;
+       }
+
+       /* make sure the thread is running at an RT prio */
+       wait_for_completion(&isrt);
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* reset the max latency */
+       tracing_max_latency = 0;
+
+       /* sleep to let the RT thread sleep too */
+       msleep(100);
+
+       /*
+        * Yes this is slightly racy. It is possible that for some
+        * strange reason that the RT thread we created, did not
+        * call schedule for 100ms after doing the completion,
+        * and we do a wakeup on a task that already is awake.
+        * But that is extremely unlikely, and the worst thing that
+        * happens in such a case, is that we disable tracing.
+        * Honestly, if this race does happen something is horrible
+        * wrong with the system.
+        */
+
+       wake_up_process(p);
+
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check both trace buffers */
+       ret = trace_test_buffer(tr, NULL);
+       if (!ret)
+               ret = trace_test_buffer(&max_tr, &count);
+
+
+       trace->reset(tr);
+
+       tracing_max_latency = save_max;
+
+       /* kill the thread */
+       kthread_stop(p);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+       }
+
+       return ret;
+}
+#endif /* CONFIG_SCHED_TRACER */
+
+#ifdef CONFIG_CONTEXT_SWITCH_TRACER
+int
+trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long count;
+       int ret;
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* Sleep for a 1/10 of a second */
+       msleep(100);
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check the trace buffer */
+       ret = trace_test_buffer(tr, &count);
+       trace->reset(tr);
+
+       if (!ret && !count) {
+               printk(KERN_CONT ".. no entries found ..");
+               ret = -1;
+       }
+
+       return ret;
+}
+#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
+
+#ifdef CONFIG_SYSPROF_TRACER
+int
+trace_selftest_startup_sysprof(struct tracer *trace, struct trace_array *tr)
+{
+       unsigned long count;
+       int ret;
+
+       /* start the tracing */
+       tr->ctrl = 1;
+       trace->init(tr);
+       /* Sleep for a 1/10 of a second */
+       msleep(100);
+       /* stop the tracing. */
+       tr->ctrl = 0;
+       trace->ctrl_update(tr);
+       /* check the trace buffer */
+       ret = trace_test_buffer(tr, &count);
+       trace->reset(tr);
+
+       return ret;
+}
+#endif /* CONFIG_SYSPROF_TRACER */
diff --git a/kernel/trace/trace_selftest_dynamic.c b/kernel/trace/trace_selftest_dynamic.c
new file mode 100644 (file)
index 0000000..54dd77c
--- /dev/null
@@ -0,0 +1,7 @@
+#include "trace.h"
+
+int DYN_FTRACE_TEST_NAME(void)
+{
+       /* used to call mcount */
+       return 0;
+}
diff --git a/kernel/trace/trace_sysprof.c b/kernel/trace/trace_sysprof.c
new file mode 100644 (file)
index 0000000..2301e1e
--- /dev/null
@@ -0,0 +1,363 @@
+/*
+ * trace stack traces
+ *
+ * Copyright (C) 2004-2008, Soeren Sandmann
+ * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
+ * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
+ */
+#include <linux/kallsyms.h>
+#include <linux/debugfs.h>
+#include <linux/hrtimer.h>
+#include <linux/uaccess.h>
+#include <linux/ftrace.h>
+#include <linux/module.h>
+#include <linux/irq.h>
+#include <linux/fs.h>
+
+#include <asm/stacktrace.h>
+
+#include "trace.h"
+
+static struct trace_array      *sysprof_trace;
+static int __read_mostly       tracer_enabled;
+
+/*
+ * 1 msec sample interval by default:
+ */
+static unsigned long sample_period = 1000000;
+static const unsigned int sample_max_depth = 512;
+
+static DEFINE_MUTEX(sample_timer_lock);
+/*
+ * Per CPU hrtimers that do the profiling:
+ */
+static DEFINE_PER_CPU(struct hrtimer, stack_trace_hrtimer);
+
+struct stack_frame {
+       const void __user       *next_fp;
+       unsigned long           return_address;
+};
+
+static int copy_stack_frame(const void __user *fp, struct stack_frame *frame)
+{
+       int ret;
+
+       if (!access_ok(VERIFY_READ, fp, sizeof(*frame)))
+               return 0;
+
+       ret = 1;
+       pagefault_disable();
+       if (__copy_from_user_inatomic(frame, fp, sizeof(*frame)))
+               ret = 0;
+       pagefault_enable();
+
+       return ret;
+}
+
+struct backtrace_info {
+       struct trace_array_cpu  *data;
+       struct trace_array      *tr;
+       int                     pos;
+};
+
+static void
+backtrace_warning_symbol(void *data, char *msg, unsigned long symbol)
+{
+       /* Ignore warnings */
+}
+
+static void backtrace_warning(void *data, char *msg)
+{
+       /* Ignore warnings */
+}
+
+static int backtrace_stack(void *data, char *name)
+{
+       /* Don't bother with IRQ stacks for now */
+       return -1;
+}
+
+static void backtrace_address(void *data, unsigned long addr, int reliable)
+{
+       struct backtrace_info *info = data;
+
+       if (info->pos < sample_max_depth && reliable) {
+               __trace_special(info->tr, info->data, 1, addr, 0);
+
+               info->pos++;
+       }
+}
+
+const static struct stacktrace_ops backtrace_ops = {
+       .warning                = backtrace_warning,
+       .warning_symbol         = backtrace_warning_symbol,
+       .stack                  = backtrace_stack,
+       .address                = backtrace_address,
+};
+
+static int
+trace_kernel(struct pt_regs *regs, struct trace_array *tr,
+            struct trace_array_cpu *data)
+{
+       struct backtrace_info info;
+       unsigned long bp;
+       char *stack;
+
+       info.tr = tr;
+       info.data = data;
+       info.pos = 1;
+
+       __trace_special(info.tr, info.data, 1, regs->ip, 0);
+
+       stack = ((char *)regs + sizeof(struct pt_regs));
+#ifdef CONFIG_FRAME_POINTER
+       bp = regs->bp;
+#else
+       bp = 0;
+#endif
+
+       dump_trace(NULL, regs, (void *)stack, bp, &backtrace_ops, &info);
+
+       return info.pos;
+}
+
+static void timer_notify(struct pt_regs *regs, int cpu)
+{
+       struct trace_array_cpu *data;
+       struct stack_frame frame;
+       struct trace_array *tr;
+       const void __user *fp;
+       int is_user;
+       int i;
+
+       if (!regs)
+               return;
+
+       tr = sysprof_trace;
+       data = tr->data[cpu];
+       is_user = user_mode(regs);
+
+       if (!current || current->pid == 0)
+               return;
+
+       if (is_user && current->state != TASK_RUNNING)
+               return;
+
+       __trace_special(tr, data, 0, 0, current->pid);
+
+       if (!is_user)
+               i = trace_kernel(regs, tr, data);
+       else
+               i = 0;
+
+       /*
+        * Trace user stack if we are not a kernel thread
+        */
+       if (current->mm && i < sample_max_depth) {
+               regs = (struct pt_regs *)current->thread.sp0 - 1;
+
+               fp = (void __user *)regs->bp;
+
+               __trace_special(tr, data, 2, regs->ip, 0);
+
+               while (i < sample_max_depth) {
+                       frame.next_fp = 0;
+                       frame.return_address = 0;
+                       if (!copy_stack_frame(fp, &frame))
+                               break;
+                       if ((unsigned long)fp < regs->sp)
+                               break;
+
+                       __trace_special(tr, data, 2, frame.return_address,
+                                       (unsigned long)fp);
+                       fp = frame.next_fp;
+
+                       i++;
+               }
+
+       }
+
+       /*
+        * Special trace entry if we overflow the max depth:
+        */
+       if (i == sample_max_depth)
+               __trace_special(tr, data, -1, -1, -1);
+
+       __trace_special(tr, data, 3, current->pid, i);
+}
+
+static enum hrtimer_restart stack_trace_timer_fn(struct hrtimer *hrtimer)
+{
+       /* trace here */
+       timer_notify(get_irq_regs(), smp_processor_id());
+
+       hrtimer_forward_now(hrtimer, ns_to_ktime(sample_period));
+
+       return HRTIMER_RESTART;
+}
+
+static void start_stack_timer(int cpu)
+{
+       struct hrtimer *hrtimer = &per_cpu(stack_trace_hrtimer, cpu);
+
+       hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       hrtimer->function = stack_trace_timer_fn;
+       hrtimer->cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
+
+       hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL);
+}
+
+static void start_stack_timers(void)
+{
+       cpumask_t saved_mask = current->cpus_allowed;
+       int cpu;
+
+       for_each_online_cpu(cpu) {
+               set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu));
+               start_stack_timer(cpu);
+       }
+       set_cpus_allowed_ptr(current, &saved_mask);
+}
+
+static void stop_stack_timer(int cpu)
+{
+       struct hrtimer *hrtimer = &per_cpu(stack_trace_hrtimer, cpu);
+
+       hrtimer_cancel(hrtimer);
+}
+
+static void stop_stack_timers(void)
+{
+       int cpu;
+
+       for_each_online_cpu(cpu)
+               stop_stack_timer(cpu);
+}
+
+static void stack_reset(struct trace_array *tr)
+{
+       int cpu;
+
+       tr->time_start = ftrace_now(tr->cpu);
+
+       for_each_online_cpu(cpu)
+               tracing_reset(tr->data[cpu]);
+}
+
+static void start_stack_trace(struct trace_array *tr)
+{
+       mutex_lock(&sample_timer_lock);
+       stack_reset(tr);
+       start_stack_timers();
+       tracer_enabled = 1;
+       mutex_unlock(&sample_timer_lock);
+}
+
+static void stop_stack_trace(struct trace_array *tr)
+{
+       mutex_lock(&sample_timer_lock);
+       stop_stack_timers();
+       tracer_enabled = 0;
+       mutex_unlock(&sample_timer_lock);
+}
+
+static void stack_trace_init(struct trace_array *tr)
+{
+       sysprof_trace = tr;
+
+       if (tr->ctrl)
+               start_stack_trace(tr);
+}
+
+static void stack_trace_reset(struct trace_array *tr)
+{
+       if (tr->ctrl)
+               stop_stack_trace(tr);
+}
+
+static void stack_trace_ctrl_update(struct trace_array *tr)
+{
+       /* When starting a new trace, reset the buffers */
+       if (tr->ctrl)
+               start_stack_trace(tr);
+       else
+               stop_stack_trace(tr);
+}
+
+static struct tracer stack_trace __read_mostly =
+{
+       .name           = "sysprof",
+       .init           = stack_trace_init,
+       .reset          = stack_trace_reset,
+       .ctrl_update    = stack_trace_ctrl_update,
+#ifdef CONFIG_FTRACE_SELFTEST
+       .selftest    = trace_selftest_startup_sysprof,
+#endif
+};
+
+__init static int init_stack_trace(void)
+{
+       return register_tracer(&stack_trace);
+}
+device_initcall(init_stack_trace);
+
+#define MAX_LONG_DIGITS 22
+
+static ssize_t
+sysprof_sample_read(struct file *filp, char __user *ubuf,
+                   size_t cnt, loff_t *ppos)
+{
+       char buf[MAX_LONG_DIGITS];
+       int r;
+
+       r = sprintf(buf, "%ld\n", nsecs_to_usecs(sample_period));
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
+static ssize_t
+sysprof_sample_write(struct file *filp, const char __user *ubuf,
+                    size_t cnt, loff_t *ppos)
+{
+       char buf[MAX_LONG_DIGITS];
+       unsigned long val;
+
+       if (cnt > MAX_LONG_DIGITS-1)
+               cnt = MAX_LONG_DIGITS-1;
+
+       if (copy_from_user(&buf, ubuf, cnt))
+               return -EFAULT;
+
+       buf[cnt] = 0;
+
+       val = simple_strtoul(buf, NULL, 10);
+       /*
+        * Enforce a minimum sample period of 100 usecs:
+        */
+       if (val < 100)
+               val = 100;
+
+       mutex_lock(&sample_timer_lock);
+       stop_stack_timers();
+       sample_period = val * 1000;
+       start_stack_timers();
+       mutex_unlock(&sample_timer_lock);
+
+       return cnt;
+}
+
+static struct file_operations sysprof_sample_fops = {
+       .read           = sysprof_sample_read,
+       .write          = sysprof_sample_write,
+};
+
+void init_tracer_sysprof_debugfs(struct dentry *d_tracer)
+{
+       struct dentry *entry;
+
+       entry = debugfs_create_file("sysprof_sample_period", 0644,
+                       d_tracer, NULL, &sysprof_sample_fops);
+       if (entry)
+               return;
+       pr_warning("Could not create debugfs 'dyn_ftrace_total_info' entry\n");
+}
index d2099f4..d8b6279 100644 (file)
@@ -634,6 +634,8 @@ config LATENCYTOP
          Enable this option if you want to use the LatencyTOP tool
          to find out which userspace is blocking on what kernel operations.
 
+source kernel/trace/Kconfig
+
 config PROVIDE_OHCI1394_DMA_INIT
        bool "Remote debugging over FireWire early on boot"
        depends on PCI && X86
index 74b0cfb..4b836a5 100644 (file)
@@ -8,6 +8,15 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
         sha1.o irq_regs.o reciprocal_div.o argv_split.o \
         proportions.o prio_heap.o ratelimit.o
 
+ifdef CONFIG_FTRACE
+# Do not profile string.o, since it may be used in early boot or vdso
+CFLAGS_REMOVE_string.o = -pg
+# Also do not profile any debug utilities
+CFLAGS_REMOVE_spinlock_debug.o = -pg
+CFLAGS_REMOVE_list_debug.o = -pg
+CFLAGS_REMOVE_debugobjects.o = -pg
+endif
+
 lib-$(CONFIG_MMU) += ioremap.o
 lib-$(CONFIG_SMP) += cpumask.o
 
index 6c90fb9..3b4dc09 100644 (file)
@@ -7,7 +7,7 @@
 #include <linux/kallsyms.h>
 #include <linux/sched.h>
 
-unsigned int debug_smp_processor_id(void)
+notrace unsigned int debug_smp_processor_id(void)
 {
        unsigned long preempt_count = preempt_count();
        int this_cpu = raw_smp_processor_id();
@@ -37,7 +37,7 @@ unsigned int debug_smp_processor_id(void)
        /*
         * Avoid recursion:
         */
-       preempt_disable();
+       preempt_disable_notrace();
 
        if (!printk_ratelimit())
                goto out_enable;
@@ -49,7 +49,7 @@ unsigned int debug_smp_processor_id(void)
        dump_stack();
 
 out_enable:
-       preempt_enable_no_resched();
+       preempt_enable_no_resched_notrace();
 out:
        return this_cpu;
 }
index 3aa819d..c4de852 100644 (file)
@@ -129,7 +129,7 @@ config MEMORY_HOTPLUG
        bool "Allow for memory hot-add"
        depends on SPARSEMEM || X86_64_ACPI_NUMA
        depends on HOTPLUG && !HIBERNATION && ARCH_ENABLE_MEMORY_HOTPLUG
-       depends on (IA64 || X86 || PPC64 || SUPERH)
+       depends on (IA64 || X86 || PPC64 || SUPERH || S390)
 
 comment "Memory hotplug is currently incompatible with Software Suspend"
        depends on SPARSEMEM && HOTPLUG && HIBERNATION
@@ -199,7 +199,7 @@ config BOUNCE
 config NR_QUICK
        int
        depends on QUICKLIST
-       default "2" if SUPERH
+       default "2" if SUPERH || AVR32
        default "1"
 
 config VIRT_TO_BUS
index ecfaa58..360d9cc 100644 (file)
@@ -47,19 +47,17 @@ static void change_pte_range(struct mm_struct *mm, pmd_t *pmd,
                if (pte_present(oldpte)) {
                        pte_t ptent;
 
-                       /* Avoid an SMP race with hardware updated dirty/clean
-                        * bits by wiping the pte and then setting the new pte
-                        * into place.
-                        */
-                       ptent = ptep_get_and_clear(mm, addr, pte);
+                       ptent = ptep_modify_prot_start(mm, addr, pte);
                        ptent = pte_modify(ptent, newprot);
+
                        /*
                         * Avoid taking write faults for pages we know to be
                         * dirty.
                         */
                        if (dirty_accountable && pte_dirty(ptent))
                                ptent = pte_mkwrite(ptent);
-                       set_pte_at(mm, addr, pte, ptent);
+
+                       ptep_modify_prot_commit(mm, addr, pte, ptent);
 #ifdef CONFIG_MIGRATION
                } else if (!pte_file(oldpte)) {
                        swp_entry_t entry = pte_to_swp_entry(oldpte);
index 789b6ad..b38f700 100644 (file)
@@ -126,8 +126,6 @@ static void background_writeout(unsigned long _min_pages);
 static struct prop_descriptor vm_completions;
 static struct prop_descriptor vm_dirties;
 
-static unsigned long determine_dirtyable_memory(void);
-
 /*
  * couple the period to the dirty_ratio:
  *
@@ -347,7 +345,13 @@ static unsigned long highmem_dirtyable_memory(unsigned long total)
 #endif
 }
 
-static unsigned long determine_dirtyable_memory(void)
+/**
+ * determine_dirtyable_memory - amount of memory that may be used
+ *
+ * Returns the numebr of pages that can currently be freed and used
+ * by the kernel for direct mappings.
+ */
+unsigned long determine_dirtyable_memory(void)
 {
        unsigned long x;
 
index f32fae3..f024b9b 100644 (file)
@@ -2929,6 +2929,18 @@ void __init free_bootmem_with_active_regions(int nid,
        }
 }
 
+void __init work_with_active_regions(int nid, work_fn_t work_fn, void *data)
+{
+       int i;
+       int ret;
+
+       for_each_active_range_index_in_nid(i, nid) {
+               ret = work_fn(early_node_map[i].start_pfn,
+                             early_node_map[i].end_pfn, data);
+               if (ret)
+                       break;
+       }
+}
 /**
  * sparse_memory_present_with_active_regions - Call memory_present for each active range
  * @nid: The node to call memory_present for. If MAX_NUMNODES, all nodes will be used.
@@ -3461,6 +3473,11 @@ void __paginginit free_area_init_node(int nid, struct pglist_data *pgdat,
        calculate_node_totalpages(pgdat, zones_size, zholes_size);
 
        alloc_node_mem_map(pgdat);
+#ifdef CONFIG_FLAT_NODE_MEM_MAP
+       printk(KERN_DEBUG "free_area_init_node: node %d, pgdat %08lx, node_mem_map %08lx\n",
+               nid, (unsigned long)pgdat,
+               (unsigned long)pgdat->node_mem_map);
+#endif
 
        free_area_init_core(pgdat, zones_size, zholes_size);
 }
@@ -3503,7 +3520,7 @@ void __init add_active_range(unsigned int nid, unsigned long start_pfn,
 {
        int i;
 
-       printk(KERN_DEBUG "Entering add_active_range(%d, %lu, %lu) "
+       printk(KERN_DEBUG "Entering add_active_range(%d, %#lx, %#lx) "
                          "%d entries of %d used\n",
                          nid, start_pfn, end_pfn,
                          nr_nodemap_entries, MAX_ACTIVE_REGIONS);
@@ -3547,27 +3564,68 @@ void __init add_active_range(unsigned int nid, unsigned long start_pfn,
 }
 
 /**
- * shrink_active_range - Shrink an existing registered range of PFNs
+ * remove_active_range - Shrink an existing registered range of PFNs
  * @nid: The node id the range is on that should be shrunk
- * @old_end_pfn: The old end PFN of the range
- * @new_end_pfn: The new PFN of the range
+ * @start_pfn: The new PFN of the range
+ * @end_pfn: The new PFN of the range
  *
  * i386 with NUMA use alloc_remap() to store a node_mem_map on a local node.
- * The map is kept at the end physical page range that has already been
- * registered with add_active_range(). This function allows an arch to shrink
- * an existing registered range.
+ * The map is kept near the end physical page range that has already been
+ * registered. This function allows an arch to shrink an existing registered
+ * range.
  */
-void __init shrink_active_range(unsigned int nid, unsigned long old_end_pfn,
-                                               unsigned long new_end_pfn)
+void __init remove_active_range(unsigned int nid, unsigned long start_pfn,
+                               unsigned long end_pfn)
 {
-       int i;
+       int i, j;
+       int removed = 0;
+
+       printk(KERN_DEBUG "remove_active_range (%d, %lu, %lu)\n",
+                         nid, start_pfn, end_pfn);
 
        /* Find the old active region end and shrink */
-       for_each_active_range_index_in_nid(i, nid)
-               if (early_node_map[i].end_pfn == old_end_pfn) {
-                       early_node_map[i].end_pfn = new_end_pfn;
-                       break;
+       for_each_active_range_index_in_nid(i, nid) {
+               if (early_node_map[i].start_pfn >= start_pfn &&
+                   early_node_map[i].end_pfn <= end_pfn) {
+                       /* clear it */
+                       early_node_map[i].start_pfn = 0;
+                       early_node_map[i].end_pfn = 0;
+                       removed = 1;
+                       continue;
+               }
+               if (early_node_map[i].start_pfn < start_pfn &&
+                   early_node_map[i].end_pfn > start_pfn) {
+                       unsigned long temp_end_pfn = early_node_map[i].end_pfn;
+                       early_node_map[i].end_pfn = start_pfn;
+                       if (temp_end_pfn > end_pfn)
+                               add_active_range(nid, end_pfn, temp_end_pfn);
+                       continue;
                }
+               if (early_node_map[i].start_pfn >= start_pfn &&
+                   early_node_map[i].end_pfn > end_pfn &&
+                   early_node_map[i].start_pfn < end_pfn) {
+                       early_node_map[i].start_pfn = end_pfn;
+                       continue;
+               }
+       }
+
+       if (!removed)
+               return;
+
+       /* remove the blank ones */
+       for (i = nr_nodemap_entries - 1; i > 0; i--) {
+               if (early_node_map[i].nid != nid)
+                       continue;
+               if (early_node_map[i].end_pfn)
+                       continue;
+               /* we found it, get rid of it */
+               for (j = i; j < nr_nodemap_entries - 1; j++)
+                       memcpy(&early_node_map[j], &early_node_map[j+1],
+                               sizeof(early_node_map[j]));
+               j = nr_nodemap_entries - 1;
+               memset(&early_node_map[j], 0, sizeof(early_node_map[j]));
+               nr_nodemap_entries--;
+       }
 }
 
 /**
@@ -3611,7 +3669,7 @@ static void __init sort_node_map(void)
 }
 
 /* Find the lowest pfn for a node */
-unsigned long __init find_min_pfn_for_node(unsigned long nid)
+unsigned long __init find_min_pfn_for_node(int nid)
 {
        int i;
        unsigned long min_pfn = ULONG_MAX;
@@ -3622,7 +3680,7 @@ unsigned long __init find_min_pfn_for_node(unsigned long nid)
 
        if (min_pfn == ULONG_MAX) {
                printk(KERN_WARNING
-                       "Could not find start_pfn for node %lu\n", nid);
+                       "Could not find start_pfn for node %d\n", nid);
                return 0;
        }
 
@@ -3878,7 +3936,7 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
        for (i = 0; i < MAX_NR_ZONES; i++) {
                if (i == ZONE_MOVABLE)
                        continue;
-               printk("  %-8s %8lu -> %8lu\n",
+               printk("  %-8s %0#10lx -> %0#10lx\n",
                                zone_names[i],
                                arch_zone_lowest_possible_pfn[i],
                                arch_zone_highest_possible_pfn[i]);
@@ -3894,7 +3952,7 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
        /* Print out the early_node_map[] */
        printk("early_node_map[%d] active PFN ranges\n", nr_nodemap_entries);
        for (i = 0; i < nr_nodemap_entries; i++)
-               printk("  %3d: %8lu -> %8lu\n", early_node_map[i].nid,
+               printk("  %3d: %0#10lx -> %0#10lx\n", early_node_map[i].nid,
                                                early_node_map[i].start_pfn,
                                                early_node_map[i].end_pfn);
 
index 315c392..5f6e2c4 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -431,9 +431,8 @@ static void print_track(const char *s, struct track *t)
        if (!t->addr)
                return;
 
-       printk(KERN_ERR "INFO: %s in ", s);
-       __print_symbol("%s", (unsigned long)t->addr);
-       printk(" age=%lu cpu=%u pid=%d\n", jiffies - t->when, t->cpu, t->pid);
+       printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
+               s, t->addr, jiffies - t->when, t->cpu, t->pid);
 }
 
 static void print_tracking(struct kmem_cache *s, void *object)
index fca23a3..821cb16 100644 (file)
@@ -4585,8 +4585,8 @@ static int __init net_dev_init(void)
 
        dev_boot_phase = 0;
 
-       open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL);
-       open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL);
+       open_softirq(NET_TX_SOFTIRQ, net_tx_action);
+       open_softirq(NET_RX_SOFTIRQ, net_rx_action);
 
        hotcpu_notifier(dev_cpu_callback, 0);
        dst_init();
index b001c36..bccf4d0 100644 (file)
 #include <linux/module.h>
 
 #include <linux/kernel.h>
+#include <linux/smp_lock.h>
 #include <linux/skbuff.h>
 #include <linux/tty.h>
 #include <linux/proc_fs.h>
index e0eab59..e84a70d 100644 (file)
@@ -479,6 +479,7 @@ dev_irnet_open(struct inode *       inode,
   ap = kzalloc(sizeof(*ap), GFP_KERNEL);
   DABORT(ap == NULL, -ENOMEM, FS_ERROR, "Can't allocate struct irnet...\n");
 
+  lock_kernel();
   /* initialize the irnet structure */
   ap->file = file;
 
@@ -500,6 +501,7 @@ dev_irnet_open(struct inode *       inode,
     {
       DERROR(FS_ERROR, "Can't setup IrDA link...\n");
       kfree(ap);
+      unlock_kernel();
       return err;
     }
 
@@ -510,6 +512,7 @@ dev_irnet_open(struct inode *       inode,
   file->private_data = ap;
 
   DEXIT(FS_TRACE, " - ap=0x%p\n", ap);
+  unlock_kernel();
   return 0;
 }
 
index 7b0038f..bda7101 100644 (file)
@@ -1135,8 +1135,7 @@ static void iucv_callback_txdone(struct iucv_path *path,
                if (this)
                        kfree_skb(this);
        }
-       if (!this)
-               printk(KERN_ERR "AF_IUCV msg tag %u not found\n", msg->tag);
+       BUG_ON(!this);
 
        if (sk->sk_state == IUCV_CLOSING) {
                if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) {
@@ -1196,7 +1195,7 @@ static int __init afiucv_init(void)
        }
        cpcmd("QUERY USERID", iucv_userid, sizeof(iucv_userid), &err);
        if (unlikely(err)) {
-               printk(KERN_ERR "AF_IUCV needs the VM userid\n");
+               WARN_ON(err);
                err = -EPROTONOSUPPORT;
                goto out;
        }
@@ -1210,7 +1209,6 @@ static int __init afiucv_init(void)
        err = sock_register(&iucv_sock_family_ops);
        if (err)
                goto out_proto;
-       printk(KERN_INFO "AF_IUCV lowlevel driver initialized\n");
        return 0;
 
 out_proto:
@@ -1226,8 +1224,6 @@ static void __exit afiucv_exit(void)
        sock_unregister(PF_IUCV);
        proto_unregister(&iucv_proto);
        iucv_unregister(&af_iucv_handler, 0);
-
-       printk(KERN_INFO "AF_IUCV lowlevel driver unloaded\n");
 }
 
 module_init(afiucv_init);
index 9189707..7f82b76 100644 (file)
@@ -1559,16 +1559,11 @@ static void iucv_external_interrupt(u16 code)
 
        p = iucv_irq_data[smp_processor_id()];
        if (p->ippathid >= iucv_max_pathid) {
-               printk(KERN_WARNING "iucv_do_int: Got interrupt with "
-                      "pathid %d > max_connections (%ld)\n",
-                      p->ippathid, iucv_max_pathid - 1);
+               WARN_ON(p->ippathid >= iucv_max_pathid);
                iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
                return;
        }
-       if (p->iptype  < 0x01 || p->iptype > 0x09) {
-               printk(KERN_ERR "iucv_do_int: unknown iucv interrupt\n");
-               return;
-       }
+       BUG_ON(p->iptype  < 0x01 || p->iptype > 0x09);
        work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
        if (!work) {
                printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
index 8e44023..ea48b82 100644 (file)
@@ -96,7 +96,8 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
 modname_flags  = $(if $(filter 1,$(words $(modname))),\
                  -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
 
-_c_flags       = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o)
+orig_c_flags   = $(KBUILD_CFLAGS) $(ccflags-y) $(CFLAGS_$(basetarget).o)
+_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
 _a_flags       = $(KBUILD_AFLAGS) $(asflags-y) $(AFLAGS_$(basetarget).o)
 _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
 
index cea4a79..37d5c36 100644 (file)
@@ -304,6 +304,14 @@ static int do_ap_entry(const char *filename,
        return 1;
 }
 
+/* looks like: "css:tN" */
+static int do_css_entry(const char *filename,
+                       struct css_device_id *id, char *alias)
+{
+       sprintf(alias, "css:t%01X", id->type);
+       return 1;
+}
+
 /* Looks like: "serio:tyNprNidNexN" */
 static int do_serio_entry(const char *filename,
                          struct serio_device_id *id, char *alias)
@@ -680,6 +688,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
                do_table(symval, sym->st_size,
                         sizeof(struct ap_device_id), "ap",
                         do_ap_entry, mod);
+       else if (sym_is(symname, "__mod_css_device_table"))
+               do_table(symval, sym->st_size,
+                        sizeof(struct css_device_id), "css",
+                        do_css_entry, mod);
        else if (sym_is(symname, "__mod_serio_device_table"))
                do_table(symval, sym->st_size,
                         sizeof(struct serio_device_id), "serio",
index 49b51f9..62ed471 100644 (file)
@@ -73,17 +73,9 @@ config SECURITY_NETWORK_XFRM
          IPSec.
          If you are unsure how to answer this question, answer N.
 
-config SECURITY_CAPABILITIES
-       bool "Default Linux Capabilities"
-       depends on SECURITY
-       default y
-       help
-         This enables the "default" Linux capabilities functionality.
-         If you are unsure how to answer this question, answer Y.
-
 config SECURITY_FILE_CAPABILITIES
        bool "File POSIX Capabilities (EXPERIMENTAL)"
-       depends on (SECURITY=n || SECURITY_CAPABILITIES!=n) && EXPERIMENTAL
+       depends on EXPERIMENTAL
        default n
        help
          This enables filesystem capabilities, allowing you to give
index 7ef1107..f654260 100644 (file)
@@ -6,16 +6,13 @@ obj-$(CONFIG_KEYS)                    += keys/
 subdir-$(CONFIG_SECURITY_SELINUX)      += selinux
 subdir-$(CONFIG_SECURITY_SMACK)                += smack
 
-# if we don't select a security model, use the default capabilities
-ifneq ($(CONFIG_SECURITY),y)
+# always enable default capabilities
 obj-y          += commoncap.o
-endif
 
 # Object file lists
-obj-$(CONFIG_SECURITY)                 += security.o dummy.o inode.o
+obj-$(CONFIG_SECURITY)                 += security.o capability.o inode.o
 # Must precede capability.o in order to stack properly.
 obj-$(CONFIG_SECURITY_SELINUX)         += selinux/built-in.o
-obj-$(CONFIG_SECURITY_SMACK)           += commoncap.o smack/built-in.o
-obj-$(CONFIG_SECURITY_CAPABILITIES)    += commoncap.o capability.o
-obj-$(CONFIG_SECURITY_ROOTPLUG)                += commoncap.o root_plug.o
+obj-$(CONFIG_SECURITY_SMACK)           += smack/built-in.o
+obj-$(CONFIG_SECURITY_ROOTPLUG)                += root_plug.o
 obj-$(CONFIG_CGROUP_DEVICE)            += device_cgroup.o
index 38ac54e..5b01c0b 100644 (file)
@@ -1,6 +1,8 @@
 /*
  *  Capabilities Linux Security Module
  *
+ *  This is the default security module in case no other module is loaded.
+ *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
  *     the Free Software Foundation; either version 2 of the License, or
  *
  */
 
-#include <linux/init.h>
-#include <linux/kernel.h>
 #include <linux/security.h>
-#include <linux/file.h>
-#include <linux/mm.h>
-#include <linux/mman.h>
-#include <linux/pagemap.h>
-#include <linux/swap.h>
-#include <linux/skbuff.h>
-#include <linux/netlink.h>
-#include <linux/ptrace.h>
-#include <linux/moduleparam.h>
-
-static struct security_operations capability_ops = {
-       .ptrace =                       cap_ptrace,
-       .capget =                       cap_capget,
-       .capset_check =                 cap_capset_check,
-       .capset_set =                   cap_capset_set,
-       .capable =                      cap_capable,
-       .settime =                      cap_settime,
-       .netlink_send =                 cap_netlink_send,
-       .netlink_recv =                 cap_netlink_recv,
-
-       .bprm_apply_creds =             cap_bprm_apply_creds,
-       .bprm_set_security =            cap_bprm_set_security,
-       .bprm_secureexec =              cap_bprm_secureexec,
-
-       .inode_setxattr =               cap_inode_setxattr,
-       .inode_removexattr =            cap_inode_removexattr,
-       .inode_need_killpriv =          cap_inode_need_killpriv,
-       .inode_killpriv =               cap_inode_killpriv,
-
-       .task_setscheduler =            cap_task_setscheduler,
-       .task_setioprio =               cap_task_setioprio,
-       .task_setnice =                 cap_task_setnice,
-       .task_post_setuid =             cap_task_post_setuid,
-       .task_prctl =                   cap_task_prctl,
-       .task_reparent_to_init =        cap_task_reparent_to_init,
-
-       .syslog =                       cap_syslog,
-
-       .vm_enough_memory =             cap_vm_enough_memory,
-};
 
-/* flag to keep track of how we were registered */
-static int secondary;
+static int cap_acct(struct file *file)
+{
+       return 0;
+}
+
+static int cap_sysctl(ctl_table *table, int op)
+{
+       return 0;
+}
+
+static int cap_quotactl(int cmds, int type, int id, struct super_block *sb)
+{
+       return 0;
+}
+
+static int cap_quota_on(struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_bprm_alloc_security(struct linux_binprm *bprm)
+{
+       return 0;
+}
+
+static void cap_bprm_free_security(struct linux_binprm *bprm)
+{
+}
+
+static void cap_bprm_post_apply_creds(struct linux_binprm *bprm)
+{
+}
+
+static int cap_bprm_check_security(struct linux_binprm *bprm)
+{
+       return 0;
+}
+
+static int cap_sb_alloc_security(struct super_block *sb)
+{
+       return 0;
+}
+
+static void cap_sb_free_security(struct super_block *sb)
+{
+}
+
+static int cap_sb_copy_data(char *orig, char *copy)
+{
+       return 0;
+}
+
+static int cap_sb_kern_mount(struct super_block *sb, void *data)
+{
+       return 0;
+}
+
+static int cap_sb_show_options(struct seq_file *m, struct super_block *sb)
+{
+       return 0;
+}
+
+static int cap_sb_statfs(struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_sb_mount(char *dev_name, struct path *path, char *type,
+                       unsigned long flags, void *data)
+{
+       return 0;
+}
+
+static int cap_sb_check_sb(struct vfsmount *mnt, struct path *path)
+{
+       return 0;
+}
+
+static int cap_sb_umount(struct vfsmount *mnt, int flags)
+{
+       return 0;
+}
+
+static void cap_sb_umount_close(struct vfsmount *mnt)
+{
+}
+
+static void cap_sb_umount_busy(struct vfsmount *mnt)
+{
+}
+
+static void cap_sb_post_remount(struct vfsmount *mnt, unsigned long flags,
+                               void *data)
+{
+}
+
+static void cap_sb_post_addmount(struct vfsmount *mnt, struct path *path)
+{
+}
+
+static int cap_sb_pivotroot(struct path *old_path, struct path *new_path)
+{
+       return 0;
+}
+
+static void cap_sb_post_pivotroot(struct path *old_path, struct path *new_path)
+{
+}
+
+static int cap_sb_set_mnt_opts(struct super_block *sb,
+                              struct security_mnt_opts *opts)
+{
+       if (unlikely(opts->num_mnt_opts))
+               return -EOPNOTSUPP;
+       return 0;
+}
+
+static void cap_sb_clone_mnt_opts(const struct super_block *oldsb,
+                                 struct super_block *newsb)
+{
+}
+
+static int cap_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
+{
+       return 0;
+}
+
+static int cap_inode_alloc_security(struct inode *inode)
+{
+       return 0;
+}
+
+static void cap_inode_free_security(struct inode *inode)
+{
+}
+
+static int cap_inode_init_security(struct inode *inode, struct inode *dir,
+                                  char **name, void **value, size_t *len)
+{
+       return -EOPNOTSUPP;
+}
+
+static int cap_inode_create(struct inode *inode, struct dentry *dentry,
+                           int mask)
+{
+       return 0;
+}
+
+static int cap_inode_link(struct dentry *old_dentry, struct inode *inode,
+                         struct dentry *new_dentry)
+{
+       return 0;
+}
+
+static int cap_inode_unlink(struct inode *inode, struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_inode_symlink(struct inode *inode, struct dentry *dentry,
+                            const char *name)
+{
+       return 0;
+}
+
+static int cap_inode_mkdir(struct inode *inode, struct dentry *dentry,
+                          int mask)
+{
+       return 0;
+}
+
+static int cap_inode_rmdir(struct inode *inode, struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_inode_mknod(struct inode *inode, struct dentry *dentry,
+                          int mode, dev_t dev)
+{
+       return 0;
+}
+
+static int cap_inode_rename(struct inode *old_inode, struct dentry *old_dentry,
+                           struct inode *new_inode, struct dentry *new_dentry)
+{
+       return 0;
+}
+
+static int cap_inode_readlink(struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_inode_follow_link(struct dentry *dentry,
+                                struct nameidata *nameidata)
+{
+       return 0;
+}
+
+static int cap_inode_permission(struct inode *inode, int mask,
+                               struct nameidata *nd)
+{
+       return 0;
+}
+
+static int cap_inode_setattr(struct dentry *dentry, struct iattr *iattr)
+{
+       return 0;
+}
+
+static int cap_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
+{
+       return 0;
+}
+
+static void cap_inode_delete(struct inode *ino)
+{
+}
+
+static void cap_inode_post_setxattr(struct dentry *dentry, const char *name,
+                                   const void *value, size_t size, int flags)
+{
+}
+
+static int cap_inode_getxattr(struct dentry *dentry, const char *name)
+{
+       return 0;
+}
+
+static int cap_inode_listxattr(struct dentry *dentry)
+{
+       return 0;
+}
+
+static int cap_inode_getsecurity(const struct inode *inode, const char *name,
+                                void **buffer, bool alloc)
+{
+       return -EOPNOTSUPP;
+}
+
+static int cap_inode_setsecurity(struct inode *inode, const char *name,
+                                const void *value, size_t size, int flags)
+{
+       return -EOPNOTSUPP;
+}
+
+static int cap_inode_listsecurity(struct inode *inode, char *buffer,
+                                 size_t buffer_size)
+{
+       return 0;
+}
+
+static void cap_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+       *secid = 0;
+}
+
+static int cap_file_permission(struct file *file, int mask)
+{
+       return 0;
+}
+
+static int cap_file_alloc_security(struct file *file)
+{
+       return 0;
+}
+
+static void cap_file_free_security(struct file *file)
+{
+}
+
+static int cap_file_ioctl(struct file *file, unsigned int command,
+                         unsigned long arg)
+{
+       return 0;
+}
+
+static int cap_file_mmap(struct file *file, unsigned long reqprot,
+                        unsigned long prot, unsigned long flags,
+                        unsigned long addr, unsigned long addr_only)
+{
+       if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
+               return -EACCES;
+       return 0;
+}
+
+static int cap_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
+                            unsigned long prot)
+{
+       return 0;
+}
+
+static int cap_file_lock(struct file *file, unsigned int cmd)
+{
+       return 0;
+}
+
+static int cap_file_fcntl(struct file *file, unsigned int cmd,
+                         unsigned long arg)
+{
+       return 0;
+}
+
+static int cap_file_set_fowner(struct file *file)
+{
+       return 0;
+}
+
+static int cap_file_send_sigiotask(struct task_struct *tsk,
+                                  struct fown_struct *fown, int sig)
+{
+       return 0;
+}
+
+static int cap_file_receive(struct file *file)
+{
+       return 0;
+}
+
+static int cap_dentry_open(struct file *file)
+{
+       return 0;
+}
+
+static int cap_task_create(unsigned long clone_flags)
+{
+       return 0;
+}
+
+static int cap_task_alloc_security(struct task_struct *p)
+{
+       return 0;
+}
+
+static void cap_task_free_security(struct task_struct *p)
+{
+}
+
+static int cap_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
+{
+       return 0;
+}
+
+static int cap_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
+{
+       return 0;
+}
 
-static int capability_disable;
-module_param_named(disable, capability_disable, int, 0);
+static int cap_task_setpgid(struct task_struct *p, pid_t pgid)
+{
+       return 0;
+}
 
-static int __init capability_init (void)
+static int cap_task_getpgid(struct task_struct *p)
 {
-       if (capability_disable) {
-               printk(KERN_INFO "Capabilities disabled at initialization\n");
-               return 0;
-       }
-       /* register ourselves with the security framework */
-       if (register_security (&capability_ops)) {
-               /* try registering with primary module */
-               if (mod_reg_security (KBUILD_MODNAME, &capability_ops)) {
-                       printk (KERN_INFO "Failure registering capabilities "
-                               "with primary security module.\n");
-                       return -EINVAL;
-               }
-               secondary = 1;
-       }
-       printk (KERN_INFO "Capability LSM initialized%s\n",
-               secondary ? " as secondary" : "");
        return 0;
 }
 
-security_initcall (capability_init);
+static int cap_task_getsid(struct task_struct *p)
+{
+       return 0;
+}
+
+static void cap_task_getsecid(struct task_struct *p, u32 *secid)
+{
+       *secid = 0;
+}
+
+static int cap_task_setgroups(struct group_info *group_info)
+{
+       return 0;
+}
+
+static int cap_task_getioprio(struct task_struct *p)
+{
+       return 0;
+}
+
+static int cap_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
+{
+       return 0;
+}
+
+static int cap_task_getscheduler(struct task_struct *p)
+{
+       return 0;
+}
+
+static int cap_task_movememory(struct task_struct *p)
+{
+       return 0;
+}
+
+static int cap_task_wait(struct task_struct *p)
+{
+       return 0;
+}
+
+static int cap_task_kill(struct task_struct *p, struct siginfo *info,
+                        int sig, u32 secid)
+{
+       return 0;
+}
+
+static void cap_task_to_inode(struct task_struct *p, struct inode *inode)
+{
+}
+
+static int cap_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
+{
+       return 0;
+}
+
+static void cap_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+       *secid = 0;
+}
+
+static int cap_msg_msg_alloc_security(struct msg_msg *msg)
+{
+       return 0;
+}
+
+static void cap_msg_msg_free_security(struct msg_msg *msg)
+{
+}
+
+static int cap_msg_queue_alloc_security(struct msg_queue *msq)
+{
+       return 0;
+}
+
+static void cap_msg_queue_free_security(struct msg_queue *msq)
+{
+}
+
+static int cap_msg_queue_associate(struct msg_queue *msq, int msqflg)
+{
+       return 0;
+}
+
+static int cap_msg_queue_msgctl(struct msg_queue *msq, int cmd)
+{
+       return 0;
+}
+
+static int cap_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
+                               int msgflg)
+{
+       return 0;
+}
+
+static int cap_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
+                               struct task_struct *target, long type, int mode)
+{
+       return 0;
+}
+
+static int cap_shm_alloc_security(struct shmid_kernel *shp)
+{
+       return 0;
+}
+
+static void cap_shm_free_security(struct shmid_kernel *shp)
+{
+}
+
+static int cap_shm_associate(struct shmid_kernel *shp, int shmflg)
+{
+       return 0;
+}
+
+static int cap_shm_shmctl(struct shmid_kernel *shp, int cmd)
+{
+       return 0;
+}
+
+static int cap_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
+                        int shmflg)
+{
+       return 0;
+}
+
+static int cap_sem_alloc_security(struct sem_array *sma)
+{
+       return 0;
+}
+
+static void cap_sem_free_security(struct sem_array *sma)
+{
+}
+
+static int cap_sem_associate(struct sem_array *sma, int semflg)
+{
+       return 0;
+}
+
+static int cap_sem_semctl(struct sem_array *sma, int cmd)
+{
+       return 0;
+}
+
+static int cap_sem_semop(struct sem_array *sma, struct sembuf *sops,
+                        unsigned nsops, int alter)
+{
+       return 0;
+}
+
+#ifdef CONFIG_SECURITY_NETWORK
+static int cap_unix_stream_connect(struct socket *sock, struct socket *other,
+                                  struct sock *newsk)
+{
+       return 0;
+}
+
+static int cap_unix_may_send(struct socket *sock, struct socket *other)
+{
+       return 0;
+}
+
+static int cap_socket_create(int family, int type, int protocol, int kern)
+{
+       return 0;
+}
+
+static int cap_socket_post_create(struct socket *sock, int family, int type,
+                                 int protocol, int kern)
+{
+       return 0;
+}
+
+static int cap_socket_bind(struct socket *sock, struct sockaddr *address,
+                          int addrlen)
+{
+       return 0;
+}
+
+static int cap_socket_connect(struct socket *sock, struct sockaddr *address,
+                             int addrlen)
+{
+       return 0;
+}
+
+static int cap_socket_listen(struct socket *sock, int backlog)
+{
+       return 0;
+}
+
+static int cap_socket_accept(struct socket *sock, struct socket *newsock)
+{
+       return 0;
+}
+
+static void cap_socket_post_accept(struct socket *sock, struct socket *newsock)
+{
+}
+
+static int cap_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
+{
+       return 0;
+}
+
+static int cap_socket_recvmsg(struct socket *sock, struct msghdr *msg,
+                             int size, int flags)
+{
+       return 0;
+}
+
+static int cap_socket_getsockname(struct socket *sock)
+{
+       return 0;
+}
+
+static int cap_socket_getpeername(struct socket *sock)
+{
+       return 0;
+}
+
+static int cap_socket_setsockopt(struct socket *sock, int level, int optname)
+{
+       return 0;
+}
+
+static int cap_socket_getsockopt(struct socket *sock, int level, int optname)
+{
+       return 0;
+}
+
+static int cap_socket_shutdown(struct socket *sock, int how)
+{
+       return 0;
+}
+
+static int cap_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
+{
+       return 0;
+}
+
+static int cap_socket_getpeersec_stream(struct socket *sock,
+                                       char __user *optval,
+                                       int __user *optlen, unsigned len)
+{
+       return -ENOPROTOOPT;
+}
+
+static int cap_socket_getpeersec_dgram(struct socket *sock,
+                                      struct sk_buff *skb, u32 *secid)
+{
+       return -ENOPROTOOPT;
+}
+
+static int cap_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
+{
+       return 0;
+}
+
+static void cap_sk_free_security(struct sock *sk)
+{
+}
+
+static void cap_sk_clone_security(const struct sock *sk, struct sock *newsk)
+{
+}
+
+static void cap_sk_getsecid(struct sock *sk, u32 *secid)
+{
+}
+
+static void cap_sock_graft(struct sock *sk, struct socket *parent)
+{
+}
+
+static int cap_inet_conn_request(struct sock *sk, struct sk_buff *skb,
+                                struct request_sock *req)
+{
+       return 0;
+}
+
+static void cap_inet_csk_clone(struct sock *newsk,
+                              const struct request_sock *req)
+{
+}
+
+static void cap_inet_conn_established(struct sock *sk, struct sk_buff *skb)
+{
+}
+
+static void cap_req_classify_flow(const struct request_sock *req,
+                                 struct flowi *fl)
+{
+}
+#endif /* CONFIG_SECURITY_NETWORK */
+
+#ifdef CONFIG_SECURITY_NETWORK_XFRM
+static int cap_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,
+                                         struct xfrm_user_sec_ctx *sec_ctx)
+{
+       return 0;
+}
+
+static int cap_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx,
+                                         struct xfrm_sec_ctx **new_ctxp)
+{
+       return 0;
+}
+
+static void cap_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx)
+{
+}
+
+static int cap_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx)
+{
+       return 0;
+}
+
+static int cap_xfrm_state_alloc_security(struct xfrm_state *x,
+                                        struct xfrm_user_sec_ctx *sec_ctx,
+                                        u32 secid)
+{
+       return 0;
+}
+
+static void cap_xfrm_state_free_security(struct xfrm_state *x)
+{
+}
+
+static int cap_xfrm_state_delete_security(struct xfrm_state *x)
+{
+       return 0;
+}
+
+static int cap_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 sk_sid, u8 dir)
+{
+       return 0;
+}
+
+static int cap_xfrm_state_pol_flow_match(struct xfrm_state *x,
+                                        struct xfrm_policy *xp,
+                                        struct flowi *fl)
+{
+       return 1;
+}
+
+static int cap_xfrm_decode_session(struct sk_buff *skb, u32 *fl, int ckall)
+{
+       return 0;
+}
+
+#endif /* CONFIG_SECURITY_NETWORK_XFRM */
+static void cap_d_instantiate(struct dentry *dentry, struct inode *inode)
+{
+}
+
+static int cap_getprocattr(struct task_struct *p, char *name, char **value)
+{
+       return -EINVAL;
+}
+
+static int cap_setprocattr(struct task_struct *p, char *name, void *value,
+                          size_t size)
+{
+       return -EINVAL;
+}
+
+static int cap_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
+{
+       return -EOPNOTSUPP;
+}
+
+static int cap_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
+{
+       return -EOPNOTSUPP;
+}
+
+static void cap_release_secctx(char *secdata, u32 seclen)
+{
+}
+
+#ifdef CONFIG_KEYS
+static int cap_key_alloc(struct key *key, struct task_struct *ctx,
+                        unsigned long flags)
+{
+       return 0;
+}
+
+static void cap_key_free(struct key *key)
+{
+}
+
+static int cap_key_permission(key_ref_t key_ref, struct task_struct *context,
+                             key_perm_t perm)
+{
+       return 0;
+}
+
+static int cap_key_getsecurity(struct key *key, char **_buffer)
+{
+       *_buffer = NULL;
+       return 0;
+}
+
+#endif /* CONFIG_KEYS */
+
+#ifdef CONFIG_AUDIT
+static int cap_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
+{
+       return 0;
+}
+
+static int cap_audit_rule_known(struct audit_krule *krule)
+{
+       return 0;
+}
+
+static int cap_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
+                               struct audit_context *actx)
+{
+       return 0;
+}
+
+static void cap_audit_rule_free(void *lsmrule)
+{
+}
+#endif /* CONFIG_AUDIT */
+
+struct security_operations default_security_ops = {
+       .name   = "default",
+};
+
+#define set_to_cap_if_null(ops, function)                              \
+       do {                                                            \
+               if (!ops->function) {                                   \
+                       ops->function = cap_##function;                 \
+                       pr_debug("Had to override the " #function       \
+                                " security operation with the default.\n");\
+                       }                                               \
+       } while (0)
+
+void security_fixup_ops(struct security_operations *ops)
+{
+       set_to_cap_if_null(ops, ptrace);
+       set_to_cap_if_null(ops, capget);
+       set_to_cap_if_null(ops, capset_check);
+       set_to_cap_if_null(ops, capset_set);
+       set_to_cap_if_null(ops, acct);
+       set_to_cap_if_null(ops, capable);
+       set_to_cap_if_null(ops, quotactl);
+       set_to_cap_if_null(ops, quota_on);
+       set_to_cap_if_null(ops, sysctl);
+       set_to_cap_if_null(ops, syslog);
+       set_to_cap_if_null(ops, settime);
+       set_to_cap_if_null(ops, vm_enough_memory);
+       set_to_cap_if_null(ops, bprm_alloc_security);
+       set_to_cap_if_null(ops, bprm_free_security);
+       set_to_cap_if_null(ops, bprm_apply_creds);
+       set_to_cap_if_null(ops, bprm_post_apply_creds);
+       set_to_cap_if_null(ops, bprm_set_security);
+       set_to_cap_if_null(ops, bprm_check_security);
+       set_to_cap_if_null(ops, bprm_secureexec);
+       set_to_cap_if_null(ops, sb_alloc_security);
+       set_to_cap_if_null(ops, sb_free_security);
+       set_to_cap_if_null(ops, sb_copy_data);
+       set_to_cap_if_null(ops, sb_kern_mount);
+       set_to_cap_if_null(ops, sb_show_options);
+       set_to_cap_if_null(ops, sb_statfs);
+       set_to_cap_if_null(ops, sb_mount);
+       set_to_cap_if_null(ops, sb_check_sb);
+       set_to_cap_if_null(ops, sb_umount);
+       set_to_cap_if_null(ops, sb_umount_close);
+       set_to_cap_if_null(ops, sb_umount_busy);
+       set_to_cap_if_null(ops, sb_post_remount);
+       set_to_cap_if_null(ops, sb_post_addmount);
+       set_to_cap_if_null(ops, sb_pivotroot);
+       set_to_cap_if_null(ops, sb_post_pivotroot);
+       set_to_cap_if_null(ops, sb_set_mnt_opts);
+       set_to_cap_if_null(ops, sb_clone_mnt_opts);
+       set_to_cap_if_null(ops, sb_parse_opts_str);
+       set_to_cap_if_null(ops, inode_alloc_security);
+       set_to_cap_if_null(ops, inode_free_security);
+       set_to_cap_if_null(ops, inode_init_security);
+       set_to_cap_if_null(ops, inode_create);
+       set_to_cap_if_null(ops, inode_link);
+       set_to_cap_if_null(ops, inode_unlink);
+       set_to_cap_if_null(ops, inode_symlink);
+       set_to_cap_if_null(ops, inode_mkdir);
+       set_to_cap_if_null(ops, inode_rmdir);
+       set_to_cap_if_null(ops, inode_mknod);
+       set_to_cap_if_null(ops, inode_rename);
+       set_to_cap_if_null(ops, inode_readlink);
+       set_to_cap_if_null(ops, inode_follow_link);
+       set_to_cap_if_null(ops, inode_permission);
+       set_to_cap_if_null(ops, inode_setattr);
+       set_to_cap_if_null(ops, inode_getattr);
+       set_to_cap_if_null(ops, inode_delete);
+       set_to_cap_if_null(ops, inode_setxattr);
+       set_to_cap_if_null(ops, inode_post_setxattr);
+       set_to_cap_if_null(ops, inode_getxattr);
+       set_to_cap_if_null(ops, inode_listxattr);
+       set_to_cap_if_null(ops, inode_removexattr);
+       set_to_cap_if_null(ops, inode_need_killpriv);
+       set_to_cap_if_null(ops, inode_killpriv);
+       set_to_cap_if_null(ops, inode_getsecurity);
+       set_to_cap_if_null(ops, inode_setsecurity);
+       set_to_cap_if_null(ops, inode_listsecurity);
+       set_to_cap_if_null(ops, inode_getsecid);
+       set_to_cap_if_null(ops, file_permission);
+       set_to_cap_if_null(ops, file_alloc_security);
+       set_to_cap_if_null(ops, file_free_security);
+       set_to_cap_if_null(ops, file_ioctl);
+       set_to_cap_if_null(ops, file_mmap);
+       set_to_cap_if_null(ops, file_mprotect);
+       set_to_cap_if_null(ops, file_lock);
+       set_to_cap_if_null(ops, file_fcntl);
+       set_to_cap_if_null(ops, file_set_fowner);
+       set_to_cap_if_null(ops, file_send_sigiotask);
+       set_to_cap_if_null(ops, file_receive);
+       set_to_cap_if_null(ops, dentry_open);
+       set_to_cap_if_null(ops, task_create);
+       set_to_cap_if_null(ops, task_alloc_security);
+       set_to_cap_if_null(ops, task_free_security);
+       set_to_cap_if_null(ops, task_setuid);
+       set_to_cap_if_null(ops, task_post_setuid);
+       set_to_cap_if_null(ops, task_setgid);
+       set_to_cap_if_null(ops, task_setpgid);
+       set_to_cap_if_null(ops, task_getpgid);
+       set_to_cap_if_null(ops, task_getsid);
+       set_to_cap_if_null(ops, task_getsecid);
+       set_to_cap_if_null(ops, task_setgroups);
+       set_to_cap_if_null(ops, task_setnice);
+       set_to_cap_if_null(ops, task_setioprio);
+       set_to_cap_if_null(ops, task_getioprio);
+       set_to_cap_if_null(ops, task_setrlimit);
+       set_to_cap_if_null(ops, task_setscheduler);
+       set_to_cap_if_null(ops, task_getscheduler);
+       set_to_cap_if_null(ops, task_movememory);
+       set_to_cap_if_null(ops, task_wait);
+       set_to_cap_if_null(ops, task_kill);
+       set_to_cap_if_null(ops, task_prctl);
+       set_to_cap_if_null(ops, task_reparent_to_init);
+       set_to_cap_if_null(ops, task_to_inode);
+       set_to_cap_if_null(ops, ipc_permission);
+       set_to_cap_if_null(ops, ipc_getsecid);
+       set_to_cap_if_null(ops, msg_msg_alloc_security);
+       set_to_cap_if_null(ops, msg_msg_free_security);
+       set_to_cap_if_null(ops, msg_queue_alloc_security);
+       set_to_cap_if_null(ops, msg_queue_free_security);
+       set_to_cap_if_null(ops, msg_queue_associate);
+       set_to_cap_if_null(ops, msg_queue_msgctl);
+       set_to_cap_if_null(ops, msg_queue_msgsnd);
+       set_to_cap_if_null(ops, msg_queue_msgrcv);
+       set_to_cap_if_null(ops, shm_alloc_security);
+       set_to_cap_if_null(ops, shm_free_security);
+       set_to_cap_if_null(ops, shm_associate);
+       set_to_cap_if_null(ops, shm_shmctl);
+       set_to_cap_if_null(ops, shm_shmat);
+       set_to_cap_if_null(ops, sem_alloc_security);
+       set_to_cap_if_null(ops, sem_free_security);
+       set_to_cap_if_null(ops, sem_associate);
+       set_to_cap_if_null(ops, sem_semctl);
+       set_to_cap_if_null(ops, sem_semop);
+       set_to_cap_if_null(ops, netlink_send);
+       set_to_cap_if_null(ops, netlink_recv);
+       set_to_cap_if_null(ops, d_instantiate);
+       set_to_cap_if_null(ops, getprocattr);
+       set_to_cap_if_null(ops, setprocattr);
+       set_to_cap_if_null(ops, secid_to_secctx);
+       set_to_cap_if_null(ops, secctx_to_secid);
+       set_to_cap_if_null(ops, release_secctx);
+#ifdef CONFIG_SECURITY_NETWORK
+       set_to_cap_if_null(ops, unix_stream_connect);
+       set_to_cap_if_null(ops, unix_may_send);
+       set_to_cap_if_null(ops, socket_create);
+       set_to_cap_if_null(ops, socket_post_create);
+       set_to_cap_if_null(ops, socket_bind);
+       set_to_cap_if_null(ops, socket_connect);
+       set_to_cap_if_null(ops, socket_listen);
+       set_to_cap_if_null(ops, socket_accept);
+       set_to_cap_if_null(ops, socket_post_accept);
+       set_to_cap_if_null(ops, socket_sendmsg);
+       set_to_cap_if_null(ops, socket_recvmsg);
+       set_to_cap_if_null(ops, socket_getsockname);
+       set_to_cap_if_null(ops, socket_getpeername);
+       set_to_cap_if_null(ops, socket_setsockopt);
+       set_to_cap_if_null(ops, socket_getsockopt);
+       set_to_cap_if_null(ops, socket_shutdown);
+       set_to_cap_if_null(ops, socket_sock_rcv_skb);
+       set_to_cap_if_null(ops, socket_getpeersec_stream);
+       set_to_cap_if_null(ops, socket_getpeersec_dgram);
+       set_to_cap_if_null(ops, sk_alloc_security);
+       set_to_cap_if_null(ops, sk_free_security);
+       set_to_cap_if_null(ops, sk_clone_security);
+       set_to_cap_if_null(ops, sk_getsecid);
+       set_to_cap_if_null(ops, sock_graft);
+       set_to_cap_if_null(ops, inet_conn_request);
+       set_to_cap_if_null(ops, inet_csk_clone);
+       set_to_cap_if_null(ops, inet_conn_established);
+       set_to_cap_if_null(ops, req_classify_flow);
+#endif /* CONFIG_SECURITY_NETWORK */
+#ifdef CONFIG_SECURITY_NETWORK_XFRM
+       set_to_cap_if_null(ops, xfrm_policy_alloc_security);
+       set_to_cap_if_null(ops, xfrm_policy_clone_security);
+       set_to_cap_if_null(ops, xfrm_policy_free_security);
+       set_to_cap_if_null(ops, xfrm_policy_delete_security);
+       set_to_cap_if_null(ops, xfrm_state_alloc_security);
+       set_to_cap_if_null(ops, xfrm_state_free_security);
+       set_to_cap_if_null(ops, xfrm_state_delete_security);
+       set_to_cap_if_null(ops, xfrm_policy_lookup);
+       set_to_cap_if_null(ops, xfrm_state_pol_flow_match);
+       set_to_cap_if_null(ops, xfrm_decode_session);
+#endif /* CONFIG_SECURITY_NETWORK_XFRM */
+#ifdef CONFIG_KEYS
+       set_to_cap_if_null(ops, key_alloc);
+       set_to_cap_if_null(ops, key_free);
+       set_to_cap_if_null(ops, key_permission);
+       set_to_cap_if_null(ops, key_getsecurity);
+#endif /* CONFIG_KEYS */
+#ifdef CONFIG_AUDIT
+       set_to_cap_if_null(ops, audit_rule_init);
+       set_to_cap_if_null(ops, audit_rule_known);
+       set_to_cap_if_null(ops, audit_rule_match);
+       set_to_cap_if_null(ops, audit_rule_free);
+#endif
+}
index 33d3433..0b6537a 100644 (file)
@@ -63,7 +63,8 @@ int cap_settime(struct timespec *ts, struct timezone *tz)
        return 0;
 }
 
-int cap_ptrace (struct task_struct *parent, struct task_struct *child)
+int cap_ptrace (struct task_struct *parent, struct task_struct *child,
+               unsigned int mode)
 {
        /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */
        if (!cap_issubset(child->cap_permitted, parent->cap_permitted) &&
diff --git a/security/dummy.c b/security/dummy.c
deleted file mode 100644 (file)
index b891688..0000000
+++ /dev/null
@@ -1,1251 +0,0 @@
-/*
- * Stub functions for the default security function pointers in case no
- * security model is loaded.
- *
- * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
- * Copyright (C) 2001-2002  Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
- *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- */
-
-#undef DEBUG
-
-#include <linux/capability.h>
-#include <linux/kernel.h>
-#include <linux/mman.h>
-#include <linux/pagemap.h>
-#include <linux/swap.h>
-#include <linux/security.h>
-#include <linux/skbuff.h>
-#include <linux/netlink.h>
-#include <net/sock.h>
-#include <linux/xattr.h>
-#include <linux/hugetlb.h>
-#include <linux/ptrace.h>
-#include <linux/file.h>
-#include <linux/prctl.h>
-#include <linux/securebits.h>
-
-static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
-{
-       return 0;
-}
-
-static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
-                        kernel_cap_t * inheritable, kernel_cap_t * permitted)
-{
-       if (target->euid == 0) {
-               cap_set_full(*permitted);
-               cap_set_init_eff(*effective);
-       } else {
-               cap_clear(*permitted);
-               cap_clear(*effective);
-       }
-
-       cap_clear(*inheritable);
-
-       if (target->fsuid != 0) {
-               *permitted = cap_drop_fs_set(*permitted);
-               *effective = cap_drop_fs_set(*effective);
-       }
-       return 0;
-}
-
-static int dummy_capset_check (struct task_struct *target,
-                              kernel_cap_t * effective,
-                              kernel_cap_t * inheritable,
-                              kernel_cap_t * permitted)
-{
-       return -EPERM;
-}
-
-static void dummy_capset_set (struct task_struct *target,
-                             kernel_cap_t * effective,
-                             kernel_cap_t * inheritable,
-                             kernel_cap_t * permitted)
-{
-       return;
-}
-
-static int dummy_acct (struct file *file)
-{
-       return 0;
-}
-
-static int dummy_capable (struct task_struct *tsk, int cap)
-{
-       if (cap_raised (tsk->cap_effective, cap))
-               return 0;
-       return -EPERM;
-}
-
-static int dummy_sysctl (ctl_table * table, int op)
-{
-       return 0;
-}
-
-static int dummy_quotactl (int cmds, int type, int id, struct super_block *sb)
-{
-       return 0;
-}
-
-static int dummy_quota_on (struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_syslog (int type)
-{
-       if ((type != 3 && type != 10) && current->euid)
-               return -EPERM;
-       return 0;
-}
-
-static int dummy_settime(struct timespec *ts, struct timezone *tz)
-{
-       if (!capable(CAP_SYS_TIME))
-               return -EPERM;
-       return 0;
-}
-
-static int dummy_vm_enough_memory(struct mm_struct *mm, long pages)
-{
-       int cap_sys_admin = 0;
-
-       if (dummy_capable(current, CAP_SYS_ADMIN) == 0)
-               cap_sys_admin = 1;
-       return __vm_enough_memory(mm, pages, cap_sys_admin);
-}
-
-static int dummy_bprm_alloc_security (struct linux_binprm *bprm)
-{
-       return 0;
-}
-
-static void dummy_bprm_free_security (struct linux_binprm *bprm)
-{
-       return;
-}
-
-static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
-{
-       if (bprm->e_uid != current->uid || bprm->e_gid != current->gid) {
-               set_dumpable(current->mm, suid_dumpable);
-
-               if ((unsafe & ~LSM_UNSAFE_PTRACE_CAP) && !capable(CAP_SETUID)) {
-                       bprm->e_uid = current->uid;
-                       bprm->e_gid = current->gid;
-               }
-       }
-
-       current->suid = current->euid = current->fsuid = bprm->e_uid;
-       current->sgid = current->egid = current->fsgid = bprm->e_gid;
-
-       dummy_capget(current, &current->cap_effective, &current->cap_inheritable, &current->cap_permitted);
-}
-
-static void dummy_bprm_post_apply_creds (struct linux_binprm *bprm)
-{
-       return;
-}
-
-static int dummy_bprm_set_security (struct linux_binprm *bprm)
-{
-       return 0;
-}
-
-static int dummy_bprm_check_security (struct linux_binprm *bprm)
-{
-       return 0;
-}
-
-static int dummy_bprm_secureexec (struct linux_binprm *bprm)
-{
-       /* The new userland will simply use the value provided
-          in the AT_SECURE field to decide whether secure mode
-          is required.  Hence, this logic is required to preserve
-          the legacy decision algorithm used by the old userland. */
-       return (current->euid != current->uid ||
-               current->egid != current->gid);
-}
-
-static int dummy_sb_alloc_security (struct super_block *sb)
-{
-       return 0;
-}
-
-static void dummy_sb_free_security (struct super_block *sb)
-{
-       return;
-}
-
-static int dummy_sb_copy_data (char *orig, char *copy)
-{
-       return 0;
-}
-
-static int dummy_sb_kern_mount (struct super_block *sb, void *data)
-{
-       return 0;
-}
-
-static int dummy_sb_statfs (struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_sb_mount (char *dev_name, struct path *path, char *type,
-                          unsigned long flags, void *data)
-{
-       return 0;
-}
-
-static int dummy_sb_check_sb (struct vfsmount *mnt, struct path *path)
-{
-       return 0;
-}
-
-static int dummy_sb_umount (struct vfsmount *mnt, int flags)
-{
-       return 0;
-}
-
-static void dummy_sb_umount_close (struct vfsmount *mnt)
-{
-       return;
-}
-
-static void dummy_sb_umount_busy (struct vfsmount *mnt)
-{
-       return;
-}
-
-static void dummy_sb_post_remount (struct vfsmount *mnt, unsigned long flags,
-                                  void *data)
-{
-       return;
-}
-
-
-static void dummy_sb_post_addmount (struct vfsmount *mnt, struct path *path)
-{
-       return;
-}
-
-static int dummy_sb_pivotroot (struct path *old_path, struct path *new_path)
-{
-       return 0;
-}
-
-static void dummy_sb_post_pivotroot (struct path *old_path, struct path *new_path)
-{
-       return;
-}
-
-static int dummy_sb_get_mnt_opts(const struct super_block *sb,
-                                struct security_mnt_opts *opts)
-{
-       security_init_mnt_opts(opts);
-       return 0;
-}
-
-static int dummy_sb_set_mnt_opts(struct super_block *sb,
-                                struct security_mnt_opts *opts)
-{
-       if (unlikely(opts->num_mnt_opts))
-               return -EOPNOTSUPP;
-       return 0;
-}
-
-static void dummy_sb_clone_mnt_opts(const struct super_block *oldsb,
-                                   struct super_block *newsb)
-{
-       return;
-}
-
-static int dummy_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
-{
-       return 0;
-}
-
-static int dummy_inode_alloc_security (struct inode *inode)
-{
-       return 0;
-}
-
-static void dummy_inode_free_security (struct inode *inode)
-{
-       return;
-}
-
-static int dummy_inode_init_security (struct inode *inode, struct inode *dir,
-                                     char **name, void **value, size_t *len)
-{
-       return -EOPNOTSUPP;
-}
-
-static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
-                              int mask)
-{
-       return 0;
-}
-
-static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
-                            struct dentry *new_dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
-                               const char *name)
-{
-       return 0;
-}
-
-static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
-                             int mask)
-{
-       return 0;
-}
-
-static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
-                             int mode, dev_t dev)
-{
-       return 0;
-}
-
-static int dummy_inode_rename (struct inode *old_inode,
-                              struct dentry *old_dentry,
-                              struct inode *new_inode,
-                              struct dentry *new_dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_readlink (struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_follow_link (struct dentry *dentry,
-                                   struct nameidata *nameidata)
-{
-       return 0;
-}
-
-static int dummy_inode_permission (struct inode *inode, int mask, struct nameidata *nd)
-{
-       return 0;
-}
-
-static int dummy_inode_setattr (struct dentry *dentry, struct iattr *iattr)
-{
-       return 0;
-}
-
-static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
-{
-       return 0;
-}
-
-static void dummy_inode_delete (struct inode *ino)
-{
-       return;
-}
-
-static int dummy_inode_setxattr (struct dentry *dentry, const char *name,
-                                const void *value, size_t size, int flags)
-{
-       if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
-           !capable(CAP_SYS_ADMIN))
-               return -EPERM;
-       return 0;
-}
-
-static void dummy_inode_post_setxattr (struct dentry *dentry, const char *name,
-                                      const void *value, size_t size,
-                                      int flags)
-{
-}
-
-static int dummy_inode_getxattr (struct dentry *dentry, const char *name)
-{
-       return 0;
-}
-
-static int dummy_inode_listxattr (struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_removexattr (struct dentry *dentry, const char *name)
-{
-       if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
-           !capable(CAP_SYS_ADMIN))
-               return -EPERM;
-       return 0;
-}
-
-static int dummy_inode_need_killpriv(struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_killpriv(struct dentry *dentry)
-{
-       return 0;
-}
-
-static int dummy_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
-{
-       return -EOPNOTSUPP;
-}
-
-static int dummy_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
-{
-       return -EOPNOTSUPP;
-}
-
-static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
-{
-       return 0;
-}
-
-static void dummy_inode_getsecid(const struct inode *inode, u32 *secid)
-{
-       *secid = 0;
-}
-
-static int dummy_file_permission (struct file *file, int mask)
-{
-       return 0;
-}
-
-static int dummy_file_alloc_security (struct file *file)
-{
-       return 0;
-}
-
-static void dummy_file_free_security (struct file *file)
-{
-       return;
-}
-
-static int dummy_file_ioctl (struct file *file, unsigned int command,
-                            unsigned long arg)
-{
-       return 0;
-}
-
-static int dummy_file_mmap (struct file *file, unsigned long reqprot,
-                           unsigned long prot,
-                           unsigned long flags,
-                           unsigned long addr,
-                           unsigned long addr_only)
-{
-       if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
-               return -EACCES;
-       return 0;
-}
-
-static int dummy_file_mprotect (struct vm_area_struct *vma,
-                               unsigned long reqprot,
-                               unsigned long prot)
-{
-       return 0;
-}
-
-static int dummy_file_lock (struct file *file, unsigned int cmd)
-{
-       return 0;
-}
-
-static int dummy_file_fcntl (struct file *file, unsigned int cmd,
-                            unsigned long arg)
-{
-       return 0;
-}
-
-static int dummy_file_set_fowner (struct file *file)
-{
-       return 0;
-}
-
-static int dummy_file_send_sigiotask (struct task_struct *tsk,
-                                     struct fown_struct *fown, int sig)
-{
-       return 0;
-}
-
-static int dummy_file_receive (struct file *file)
-{
-       return 0;
-}
-
-static int dummy_dentry_open (struct file *file)
-{
-       return 0;
-}
-
-static int dummy_task_create (unsigned long clone_flags)
-{
-       return 0;
-}
-
-static int dummy_task_alloc_security (struct task_struct *p)
-{
-       return 0;
-}
-
-static void dummy_task_free_security (struct task_struct *p)
-{
-       return;
-}
-
-static int dummy_task_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
-{
-       return 0;
-}
-
-static int dummy_task_post_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
-{
-       dummy_capget(current, &current->cap_effective, &current->cap_inheritable, &current->cap_permitted);
-       return 0;
-}
-
-static int dummy_task_setgid (gid_t id0, gid_t id1, gid_t id2, int flags)
-{
-       return 0;
-}
-
-static int dummy_task_setpgid (struct task_struct *p, pid_t pgid)
-{
-       return 0;
-}
-
-static int dummy_task_getpgid (struct task_struct *p)
-{
-       return 0;
-}
-
-static int dummy_task_getsid (struct task_struct *p)
-{
-       return 0;
-}
-
-static void dummy_task_getsecid (struct task_struct *p, u32 *secid)
-{
-       *secid = 0;
-}
-
-static int dummy_task_setgroups (struct group_info *group_info)
-{
-       return 0;
-}
-
-static int dummy_task_setnice (struct task_struct *p, int nice)
-{
-       return 0;
-}
-
-static int dummy_task_setioprio (struct task_struct *p, int ioprio)
-{
-       return 0;
-}
-
-static int dummy_task_getioprio (struct task_struct *p)
-{
-       return 0;
-}
-
-static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim)
-{
-       return 0;
-}
-
-static int dummy_task_setscheduler (struct task_struct *p, int policy,
-                                   struct sched_param *lp)
-{
-       return 0;
-}
-
-static int dummy_task_getscheduler (struct task_struct *p)
-{
-       return 0;
-}
-
-static int dummy_task_movememory (struct task_struct *p)
-{
-       return 0;
-}
-
-static int dummy_task_wait (struct task_struct *p)
-{
-       return 0;
-}
-
-static int dummy_task_kill (struct task_struct *p, struct siginfo *info,
-                           int sig, u32 secid)
-{
-       return 0;
-}
-
-static int dummy_task_prctl (int option, unsigned long arg2, unsigned long arg3,
-                            unsigned long arg4, unsigned long arg5, long *rc_p)
-{
-       switch (option) {
-       case PR_CAPBSET_READ:
-               *rc_p = (cap_valid(arg2) ? 1 : -EINVAL);
-               break;
-       case PR_GET_KEEPCAPS:
-               *rc_p = issecure(SECURE_KEEP_CAPS);
-               break;
-       case PR_SET_KEEPCAPS:
-               if (arg2 > 1)
-                       *rc_p = -EINVAL;
-               else if (arg2)
-                       current->securebits |= issecure_mask(SECURE_KEEP_CAPS);
-               else
-                       current->securebits &=
-                               ~issecure_mask(SECURE_KEEP_CAPS);
-               break;
-       default:
-               return 0;
-       }
-
-       return 1;
-}
-
-static void dummy_task_reparent_to_init (struct task_struct *p)
-{
-       p->euid = p->fsuid = 0;
-       return;
-}
-
-static void dummy_task_to_inode(struct task_struct *p, struct inode *inode)
-{ }
-
-static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
-{
-       return 0;
-}
-
-static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
-{
-       *secid = 0;
-}
-
-static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
-{
-       return 0;
-}
-
-static void dummy_msg_msg_free_security (struct msg_msg *msg)
-{
-       return;
-}
-
-static int dummy_msg_queue_alloc_security (struct msg_queue *msq)
-{
-       return 0;
-}
-
-static void dummy_msg_queue_free_security (struct msg_queue *msq)
-{
-       return;
-}
-
-static int dummy_msg_queue_associate (struct msg_queue *msq, 
-                                     int msqflg)
-{
-       return 0;
-}
-
-static int dummy_msg_queue_msgctl (struct msg_queue *msq, int cmd)
-{
-       return 0;
-}
-
-static int dummy_msg_queue_msgsnd (struct msg_queue *msq, struct msg_msg *msg,
-                                  int msgflg)
-{
-       return 0;
-}
-
-static int dummy_msg_queue_msgrcv (struct msg_queue *msq, struct msg_msg *msg,
-                                  struct task_struct *target, long type,
-                                  int mode)
-{
-       return 0;
-}
-
-static int dummy_shm_alloc_security (struct shmid_kernel *shp)
-{
-       return 0;
-}
-
-static void dummy_shm_free_security (struct shmid_kernel *shp)
-{
-       return;
-}
-
-static int dummy_shm_associate (struct shmid_kernel *shp, int shmflg)
-{
-       return 0;
-}
-
-static int dummy_shm_shmctl (struct shmid_kernel *shp, int cmd)
-{
-       return 0;
-}
-
-static int dummy_shm_shmat (struct shmid_kernel *shp, char __user *shmaddr,
-                           int shmflg)
-{
-       return 0;
-}
-
-static int dummy_sem_alloc_security (struct sem_array *sma)
-{
-       return 0;
-}
-
-static void dummy_sem_free_security (struct sem_array *sma)
-{
-       return;
-}
-
-static int dummy_sem_associate (struct sem_array *sma, int semflg)
-{
-       return 0;
-}
-
-static int dummy_sem_semctl (struct sem_array *sma, int cmd)
-{
-       return 0;
-}
-
-static int dummy_sem_semop (struct sem_array *sma, 
-                           struct sembuf *sops, unsigned nsops, int alter)
-{
-       return 0;
-}
-
-static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
-{
-       NETLINK_CB(skb).eff_cap = current->cap_effective;
-       return 0;
-}
-
-static int dummy_netlink_recv (struct sk_buff *skb, int cap)
-{
-       if (!cap_raised (NETLINK_CB (skb).eff_cap, cap))
-               return -EPERM;
-       return 0;
-}
-
-#ifdef CONFIG_SECURITY_NETWORK
-static int dummy_unix_stream_connect (struct socket *sock,
-                                     struct socket *other,
-                                     struct sock *newsk)
-{
-       return 0;
-}
-
-static int dummy_unix_may_send (struct socket *sock,
-                               struct socket *other)
-{
-       return 0;
-}
-
-static int dummy_socket_create (int family, int type,
-                               int protocol, int kern)
-{
-       return 0;
-}
-
-static int dummy_socket_post_create (struct socket *sock, int family, int type,
-                                    int protocol, int kern)
-{
-       return 0;
-}
-
-static int dummy_socket_bind (struct socket *sock, struct sockaddr *address,
-                             int addrlen)
-{
-       return 0;
-}
-
-static int dummy_socket_connect (struct socket *sock, struct sockaddr *address,
-                                int addrlen)
-{
-       return 0;
-}
-
-static int dummy_socket_listen (struct socket *sock, int backlog)
-{
-       return 0;
-}
-
-static int dummy_socket_accept (struct socket *sock, struct socket *newsock)
-{
-       return 0;
-}
-
-static void dummy_socket_post_accept (struct socket *sock, 
-                                     struct socket *newsock)
-{
-       return;
-}
-
-static int dummy_socket_sendmsg (struct socket *sock, struct msghdr *msg,
-                                int size)
-{
-       return 0;
-}
-
-static int dummy_socket_recvmsg (struct socket *sock, struct msghdr *msg,
-                                int size, int flags)
-{
-       return 0;
-}
-
-static int dummy_socket_getsockname (struct socket *sock)
-{
-       return 0;
-}
-
-static int dummy_socket_getpeername (struct socket *sock)
-{
-       return 0;
-}
-
-static int dummy_socket_setsockopt (struct socket *sock, int level, int optname)
-{
-       return 0;
-}
-
-static int dummy_socket_getsockopt (struct socket *sock, int level, int optname)
-{
-       return 0;
-}
-
-static int dummy_socket_shutdown (struct socket *sock, int how)
-{
-       return 0;
-}
-
-static int dummy_socket_sock_rcv_skb (struct sock *sk, struct sk_buff *skb)
-{
-       return 0;
-}
-
-static int dummy_socket_getpeersec_stream(struct socket *sock, char __user *optval,
-                                         int __user *optlen, unsigned len)
-{
-       return -ENOPROTOOPT;
-}
-
-static int dummy_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
-{
-       return -ENOPROTOOPT;
-}
-
-static inline int dummy_sk_alloc_security (struct sock *sk, int family, gfp_t priority)
-{
-       return 0;
-}
-
-static inline void dummy_sk_free_security (struct sock *sk)
-{
-}
-
-static inline void dummy_sk_clone_security (const struct sock *sk, struct sock *newsk)
-{
-}
-
-static inline void dummy_sk_getsecid(struct sock *sk, u32 *secid)
-{
-}
-
-static inline void dummy_sock_graft(struct sock* sk, struct socket *parent)
-{
-}
-
-static inline int dummy_inet_conn_request(struct sock *sk,
-                       struct sk_buff *skb, struct request_sock *req)
-{
-       return 0;
-}
-
-static inline void dummy_inet_csk_clone(struct sock *newsk,
-                       const struct request_sock *req)
-{
-}
-
-static inline void dummy_inet_conn_established(struct sock *sk,
-                       struct sk_buff *skb)
-{
-}
-
-static inline void dummy_req_classify_flow(const struct request_sock *req,
-                       struct flowi *fl)
-{
-}
-#endif /* CONFIG_SECURITY_NETWORK */
-
-#ifdef CONFIG_SECURITY_NETWORK_XFRM
-static int dummy_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,
-                                           struct xfrm_user_sec_ctx *sec_ctx)
-{
-       return 0;
-}
-
-static inline int dummy_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx,
-                                          struct xfrm_sec_ctx **new_ctxp)
-{
-       return 0;
-}
-
-static void dummy_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx)
-{
-}
-
-static int dummy_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx)
-{
-       return 0;
-}
-
-static int dummy_xfrm_state_alloc_security(struct xfrm_state *x,
-       struct xfrm_user_sec_ctx *sec_ctx, u32 secid)
-{
-       return 0;
-}
-
-static void dummy_xfrm_state_free_security(struct xfrm_state *x)
-{
-}
-
-static int dummy_xfrm_state_delete_security(struct xfrm_state *x)
-{
-       return 0;
-}
-
-static int dummy_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx,
-                                   u32 sk_sid, u8 dir)
-{
-       return 0;
-}
-
-static int dummy_xfrm_state_pol_flow_match(struct xfrm_state *x,
-                               struct xfrm_policy *xp, struct flowi *fl)
-{
-       return 1;
-}
-
-static int dummy_xfrm_decode_session(struct sk_buff *skb, u32 *fl, int ckall)
-{
-       return 0;
-}
-
-#endif /* CONFIG_SECURITY_NETWORK_XFRM */
-static int dummy_register_security (const char *name, struct security_operations *ops)
-{
-       return -EINVAL;
-}
-
-static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
-{
-       return;
-}
-
-static int dummy_getprocattr(struct task_struct *p, char *name, char **value)
-{
-       return -EINVAL;
-}
-
-static int dummy_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
-{
-       return -EINVAL;
-}
-
-static int dummy_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
-{
-       return -EOPNOTSUPP;
-}
-
-static int dummy_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
-{
-       return -EOPNOTSUPP;
-}
-
-static void dummy_release_secctx(char *secdata, u32 seclen)
-{
-}
-
-#ifdef CONFIG_KEYS
-static inline int dummy_key_alloc(struct key *key, struct task_struct *ctx,
-                                 unsigned long flags)
-{
-       return 0;
-}
-
-static inline void dummy_key_free(struct key *key)
-{
-}
-
-static inline int dummy_key_permission(key_ref_t key_ref,
-                                      struct task_struct *context,
-                                      key_perm_t perm)
-{
-       return 0;
-}
-
-static int dummy_key_getsecurity(struct key *key, char **_buffer)
-{
-       *_buffer = NULL;
-       return 0;
-}
-
-#endif /* CONFIG_KEYS */
-
-#ifdef CONFIG_AUDIT
-static inline int dummy_audit_rule_init(u32 field, u32 op, char *rulestr,
-                                       void **lsmrule)
-{
-       return 0;
-}
-
-static inline int dummy_audit_rule_known(struct audit_krule *krule)
-{
-       return 0;
-}
-
-static inline int dummy_audit_rule_match(u32 secid, u32 field, u32 op,
-                                        void *lsmrule,
-                                        struct audit_context *actx)
-{
-       return 0;
-}
-
-static inline void dummy_audit_rule_free(void *lsmrule)
-{ }
-
-#endif /* CONFIG_AUDIT */
-
-struct security_operations dummy_security_ops = {
-       .name = "dummy",
-};
-
-#define set_to_dummy_if_null(ops, function)                            \
-       do {                                                            \
-               if (!ops->function) {                                   \
-                       ops->function = dummy_##function;               \
-                       pr_debug("Had to override the " #function       \
-                                " security operation with the dummy one.\n");\
-                       }                                               \
-       } while (0)
-
-void security_fixup_ops (struct security_operations *ops)
-{
-       set_to_dummy_if_null(ops, ptrace);
-       set_to_dummy_if_null(ops, capget);
-       set_to_dummy_if_null(ops, capset_check);
-       set_to_dummy_if_null(ops, capset_set);
-       set_to_dummy_if_null(ops, acct);
-       set_to_dummy_if_null(ops, capable);
-       set_to_dummy_if_null(ops, quotactl);
-       set_to_dummy_if_null(ops, quota_on);
-       set_to_dummy_if_null(ops, sysctl);
-       set_to_dummy_if_null(ops, syslog);
-       set_to_dummy_if_null(ops, settime);
-       set_to_dummy_if_null(ops, vm_enough_memory);
-       set_to_dummy_if_null(ops, bprm_alloc_security);
-       set_to_dummy_if_null(ops, bprm_free_security);
-       set_to_dummy_if_null(ops, bprm_apply_creds);
-       set_to_dummy_if_null(ops, bprm_post_apply_creds);
-       set_to_dummy_if_null(ops, bprm_set_security);
-       set_to_dummy_if_null(ops, bprm_check_security);
-       set_to_dummy_if_null(ops, bprm_secureexec);
-       set_to_dummy_if_null(ops, sb_alloc_security);
-       set_to_dummy_if_null(ops, sb_free_security);
-       set_to_dummy_if_null(ops, sb_copy_data);
-       set_to_dummy_if_null(ops, sb_kern_mount);
-       set_to_dummy_if_null(ops, sb_statfs);
-       set_to_dummy_if_null(ops, sb_mount);
-       set_to_dummy_if_null(ops, sb_check_sb);
-       set_to_dummy_if_null(ops, sb_umount);
-       set_to_dummy_if_null(ops, sb_umount_close);
-       set_to_dummy_if_null(ops, sb_umount_busy);
-       set_to_dummy_if_null(ops, sb_post_remount);
-       set_to_dummy_if_null(ops, sb_post_addmount);
-       set_to_dummy_if_null(ops, sb_pivotroot);
-       set_to_dummy_if_null(ops, sb_post_pivotroot);
-       set_to_dummy_if_null(ops, sb_get_mnt_opts);
-       set_to_dummy_if_null(ops, sb_set_mnt_opts);
-       set_to_dummy_if_null(ops, sb_clone_mnt_opts);
-       set_to_dummy_if_null(ops, sb_parse_opts_str);
-       set_to_dummy_if_null(ops, inode_alloc_security);
-       set_to_dummy_if_null(ops, inode_free_security);
-       set_to_dummy_if_null(ops, inode_init_security);
-       set_to_dummy_if_null(ops, inode_create);
-       set_to_dummy_if_null(ops, inode_link);
-       set_to_dummy_if_null(ops, inode_unlink);
-       set_to_dummy_if_null(ops, inode_symlink);
-       set_to_dummy_if_null(ops, inode_mkdir);
-       set_to_dummy_if_null(ops, inode_rmdir);
-       set_to_dummy_if_null(ops, inode_mknod);
-       set_to_dummy_if_null(ops, inode_rename);
-       set_to_dummy_if_null(ops, inode_readlink);
-       set_to_dummy_if_null(ops, inode_follow_link);
-       set_to_dummy_if_null(ops, inode_permission);
-       set_to_dummy_if_null(ops, inode_setattr);
-       set_to_dummy_if_null(ops, inode_getattr);
-       set_to_dummy_if_null(ops, inode_delete);
-       set_to_dummy_if_null(ops, inode_setxattr);
-       set_to_dummy_if_null(ops, inode_post_setxattr);
-       set_to_dummy_if_null(ops, inode_getxattr);
-       set_to_dummy_if_null(ops, inode_listxattr);
-       set_to_dummy_if_null(ops, inode_removexattr);
-       set_to_dummy_if_null(ops, inode_need_killpriv);
-       set_to_dummy_if_null(ops, inode_killpriv);
-       set_to_dummy_if_null(ops, inode_getsecurity);
-       set_to_dummy_if_null(ops, inode_setsecurity);
-       set_to_dummy_if_null(ops, inode_listsecurity);
-       set_to_dummy_if_null(ops, inode_getsecid);
-       set_to_dummy_if_null(ops, file_permission);
-       set_to_dummy_if_null(ops, file_alloc_security);
-       set_to_dummy_if_null(ops, file_free_security);
-       set_to_dummy_if_null(ops, file_ioctl);
-       set_to_dummy_if_null(ops, file_mmap);
-       set_to_dummy_if_null(ops, file_mprotect);
-       set_to_dummy_if_null(ops, file_lock);
-       set_to_dummy_if_null(ops, file_fcntl);
-       set_to_dummy_if_null(ops, file_set_fowner);
-       set_to_dummy_if_null(ops, file_send_sigiotask);
-       set_to_dummy_if_null(ops, file_receive);
-       set_to_dummy_if_null(ops, dentry_open);
-       set_to_dummy_if_null(ops, task_create);
-       set_to_dummy_if_null(ops, task_alloc_security);
-       set_to_dummy_if_null(ops, task_free_security);
-       set_to_dummy_if_null(ops, task_setuid);
-       set_to_dummy_if_null(ops, task_post_setuid);
-       set_to_dummy_if_null(ops, task_setgid);
-       set_to_dummy_if_null(ops, task_setpgid);
-       set_to_dummy_if_null(ops, task_getpgid);
-       set_to_dummy_if_null(ops, task_getsid);
-       set_to_dummy_if_null(ops, task_getsecid);
-       set_to_dummy_if_null(ops, task_setgroups);
-       set_to_dummy_if_null(ops, task_setnice);
-       set_to_dummy_if_null(ops, task_setioprio);
-       set_to_dummy_if_null(ops, task_getioprio);
-       set_to_dummy_if_null(ops, task_setrlimit);
-       set_to_dummy_if_null(ops, task_setscheduler);
-       set_to_dummy_if_null(ops, task_getscheduler);
-       set_to_dummy_if_null(ops, task_movememory);
-       set_to_dummy_if_null(ops, task_wait);
-       set_to_dummy_if_null(ops, task_kill);
-       set_to_dummy_if_null(ops, task_prctl);
-       set_to_dummy_if_null(ops, task_reparent_to_init);
-       set_to_dummy_if_null(ops, task_to_inode);
-       set_to_dummy_if_null(ops, ipc_permission);
-       set_to_dummy_if_null(ops, ipc_getsecid);
-       set_to_dummy_if_null(ops, msg_msg_alloc_security);
-       set_to_dummy_if_null(ops, msg_msg_free_security);
-       set_to_dummy_if_null(ops, msg_queue_alloc_security);
-       set_to_dummy_if_null(ops, msg_queue_free_security);
-       set_to_dummy_if_null(ops, msg_queue_associate);
-       set_to_dummy_if_null(ops, msg_queue_msgctl);
-       set_to_dummy_if_null(ops, msg_queue_msgsnd);
-       set_to_dummy_if_null(ops, msg_queue_msgrcv);
-       set_to_dummy_if_null(ops, shm_alloc_security);
-       set_to_dummy_if_null(ops, shm_free_security);
-       set_to_dummy_if_null(ops, shm_associate);
-       set_to_dummy_if_null(ops, shm_shmctl);
-       set_to_dummy_if_null(ops, shm_shmat);
-       set_to_dummy_if_null(ops, sem_alloc_security);
-       set_to_dummy_if_null(ops, sem_free_security);
-       set_to_dummy_if_null(ops, sem_associate);
-       set_to_dummy_if_null(ops, sem_semctl);
-       set_to_dummy_if_null(ops, sem_semop);
-       set_to_dummy_if_null(ops, netlink_send);
-       set_to_dummy_if_null(ops, netlink_recv);
-       set_to_dummy_if_null(ops, register_security);
-       set_to_dummy_if_null(ops, d_instantiate);
-       set_to_dummy_if_null(ops, getprocattr);
-       set_to_dummy_if_null(ops, setprocattr);
-       set_to_dummy_if_null(ops, secid_to_secctx);
-       set_to_dummy_if_null(ops, secctx_to_secid);
-       set_to_dummy_if_null(ops, release_secctx);
-#ifdef CONFIG_SECURITY_NETWORK
-       set_to_dummy_if_null(ops, unix_stream_connect);
-       set_to_dummy_if_null(ops, unix_may_send);
-       set_to_dummy_if_null(ops, socket_create);
-       set_to_dummy_if_null(ops, socket_post_create);
-       set_to_dummy_if_null(ops, socket_bind);
-       set_to_dummy_if_null(ops, socket_connect);
-       set_to_dummy_if_null(ops, socket_listen);
-       set_to_dummy_if_null(ops, socket_accept);
-       set_to_dummy_if_null(ops, socket_post_accept);
-       set_to_dummy_if_null(ops, socket_sendmsg);
-       set_to_dummy_if_null(ops, socket_recvmsg);
-       set_to_dummy_if_null(ops, socket_getsockname);
-       set_to_dummy_if_null(ops, socket_getpeername);
-       set_to_dummy_if_null(ops, socket_setsockopt);
-       set_to_dummy_if_null(ops, socket_getsockopt);
-       set_to_dummy_if_null(ops, socket_shutdown);
-       set_to_dummy_if_null(ops, socket_sock_rcv_skb);
-       set_to_dummy_if_null(ops, socket_getpeersec_stream);
-       set_to_dummy_if_null(ops, socket_getpeersec_dgram);
-       set_to_dummy_if_null(ops, sk_alloc_security);
-       set_to_dummy_if_null(ops, sk_free_security);
-       set_to_dummy_if_null(ops, sk_clone_security);
-       set_to_dummy_if_null(ops, sk_getsecid);
-       set_to_dummy_if_null(ops, sock_graft);
-       set_to_dummy_if_null(ops, inet_conn_request);
-       set_to_dummy_if_null(ops, inet_csk_clone);
-       set_to_dummy_if_null(ops, inet_conn_established);
-       set_to_dummy_if_null(ops, req_classify_flow);
- #endif        /* CONFIG_SECURITY_NETWORK */
-#ifdef  CONFIG_SECURITY_NETWORK_XFRM
-       set_to_dummy_if_null(ops, xfrm_policy_alloc_security);
-       set_to_dummy_if_null(ops, xfrm_policy_clone_security);
-       set_to_dummy_if_null(ops, xfrm_policy_free_security);
-       set_to_dummy_if_null(ops, xfrm_policy_delete_security);
-       set_to_dummy_if_null(ops, xfrm_state_alloc_security);
-       set_to_dummy_if_null(ops, xfrm_state_free_security);
-       set_to_dummy_if_null(ops, xfrm_state_delete_security);
-       set_to_dummy_if_null(ops, xfrm_policy_lookup);
-       set_to_dummy_if_null(ops, xfrm_state_pol_flow_match);
-       set_to_dummy_if_null(ops, xfrm_decode_session);
-#endif /* CONFIG_SECURITY_NETWORK_XFRM */
-#ifdef CONFIG_KEYS
-       set_to_dummy_if_null(ops, key_alloc);
-       set_to_dummy_if_null(ops, key_free);
-       set_to_dummy_if_null(ops, key_permission);
-       set_to_dummy_if_null(ops, key_getsecurity);
-#endif /* CONFIG_KEYS */
-#ifdef CONFIG_AUDIT
-       set_to_dummy_if_null(ops, audit_rule_init);
-       set_to_dummy_if_null(ops, audit_rule_known);
-       set_to_dummy_if_null(ops, audit_rule_match);
-       set_to_dummy_if_null(ops, audit_rule_free);
-#endif
-}
-
index a41cf42..be0ebec 100644 (file)
@@ -28,9 +28,6 @@
 #include <linux/usb.h>
 #include <linux/moduleparam.h>
 
-/* flag to keep track of how we were registered */
-static int secondary;
-
 /* default is a generic type of usb to serial converter */
 static int vendor_id = 0x0557;
 static int product_id = 0x2008;
@@ -97,13 +94,7 @@ static int __init rootplug_init (void)
        if (register_security (&rootplug_security_ops)) {
                printk (KERN_INFO 
                        "Failure registering Root Plug module with the kernel\n");
-               /* try registering with primary module */
-               if (mod_reg_security (MY_NAME, &rootplug_security_ops)) {
-                       printk (KERN_INFO "Failure registering Root Plug "
-                               " module with primary security module.\n");
                        return -EINVAL;
-               }
-               secondary = 1;
        }
        printk (KERN_INFO "Root Plug module initialized, "
                "vendor_id = %4.4x, product id = %4.4x\n", vendor_id, product_id);
index 59838a9..59f23b5 100644 (file)
@@ -20,8 +20,8 @@
 /* Boot-time LSM user choice */
 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1];
 
-/* things that live in dummy.c */
-extern struct security_operations dummy_security_ops;
+/* things that live in capability.c */
+extern struct security_operations default_security_ops;
 extern void security_fixup_ops(struct security_operations *ops);
 
 struct security_operations *security_ops;      /* Initialized to NULL */
@@ -57,13 +57,8 @@ int __init security_init(void)
 {
        printk(KERN_INFO "Security Framework initialized\n");
 
-       if (verify(&dummy_security_ops)) {
-               printk(KERN_ERR "%s could not verify "
-                      "dummy_security_ops structure.\n", __func__);
-               return -EIO;
-       }
-
-       security_ops = &dummy_security_ops;
+       security_fixup_ops(&default_security_ops);
+       security_ops = &default_security_ops;
        do_security_initcalls();
 
        return 0;
@@ -122,7 +117,7 @@ int register_security(struct security_operations *ops)
                return -EINVAL;
        }
 
-       if (security_ops != &dummy_security_ops)
+       if (security_ops != &default_security_ops)
                return -EAGAIN;
 
        security_ops = ops;
@@ -130,40 +125,12 @@ int register_security(struct security_operations *ops)
        return 0;
 }
 
-/**
- * mod_reg_security - allows security modules to be "stacked"
- * @name: a pointer to a string with the name of the security_options to be registered
- * @ops: a pointer to the struct security_options that is to be registered
- *
- * This function allows security modules to be stacked if the currently loaded
- * security module allows this to happen.  It passes the @name and @ops to the
- * register_security function of the currently loaded security module.
- *
- * The return value depends on the currently loaded security module, with 0 as
- * success.
- */
-int mod_reg_security(const char *name, struct security_operations *ops)
-{
-       if (verify(ops)) {
-               printk(KERN_INFO "%s could not verify "
-                      "security operations.\n", __func__);
-               return -EINVAL;
-       }
-
-       if (ops == security_ops) {
-               printk(KERN_INFO "%s security operations "
-                      "already registered.\n", __func__);
-               return -EINVAL;
-       }
-
-       return security_ops->register_security(name, ops);
-}
-
 /* Security operations */
 
-int security_ptrace(struct task_struct *parent, struct task_struct *child)
+int security_ptrace(struct task_struct *parent, struct task_struct *child,
+                   unsigned int mode)
 {
-       return security_ops->ptrace(parent, child);
+       return security_ops->ptrace(parent, child, mode);
 }
 
 int security_capget(struct task_struct *target,
@@ -291,6 +258,11 @@ int security_sb_kern_mount(struct super_block *sb, void *data)
        return security_ops->sb_kern_mount(sb, data);
 }
 
+int security_sb_show_options(struct seq_file *m, struct super_block *sb)
+{
+       return security_ops->sb_show_options(m, sb);
+}
+
 int security_sb_statfs(struct dentry *dentry)
 {
        return security_ops->sb_statfs(dentry);
@@ -342,12 +314,6 @@ void security_sb_post_pivotroot(struct path *old_path, struct path *new_path)
        security_ops->sb_post_pivotroot(old_path, new_path);
 }
 
-int security_sb_get_mnt_opts(const struct super_block *sb,
-                               struct security_mnt_opts *opts)
-{
-       return security_ops->sb_get_mnt_opts(sb, opts);
-}
-
 int security_sb_set_mnt_opts(struct super_block *sb,
                                struct security_mnt_opts *opts)
 {
@@ -894,7 +860,7 @@ EXPORT_SYMBOL(security_secctx_to_secid);
 
 void security_release_secctx(char *secdata, u32 seclen)
 {
-       return security_ops->release_secctx(secdata, seclen);
+       security_ops->release_secctx(secdata, seclen);
 }
 EXPORT_SYMBOL(security_release_secctx);
 
@@ -1011,12 +977,12 @@ int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
 
 void security_sk_free(struct sock *sk)
 {
-       return security_ops->sk_free_security(sk);
+       security_ops->sk_free_security(sk);
 }
 
 void security_sk_clone(const struct sock *sk, struct sock *newsk)
 {
-       return security_ops->sk_clone_security(sk, newsk);
+       security_ops->sk_clone_security(sk, newsk);
 }
 
 void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
index 1c864c0..91200fe 100644 (file)
@@ -9,7 +9,8 @@
  *           James Morris <jmorris@redhat.com>
  *
  *  Copyright (C) 2001,2002 Networks Associates Technology, Inc.
- *  Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
+ *  Copyright (C) 2003-2008 Red Hat, Inc., James Morris <jmorris@redhat.com>
+ *                                        Eric Paris <eparis@redhat.com>
  *  Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  *                         <dgoeddel@trustedcs.com>
  *  Copyright (C) 2006, 2007 Hewlett-Packard Development Company, L.P.
@@ -42,9 +43,7 @@
 #include <linux/fdtable.h>
 #include <linux/namei.h>
 #include <linux/mount.h>
-#include <linux/ext2_fs.h>
 #include <linux/proc_fs.h>
-#include <linux/kd.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv6.h>
 #include <linux/tty.h>
@@ -53,7 +52,7 @@
 #include <net/tcp.h>           /* struct or_callable used in sock_rcv_skb */
 #include <net/net_namespace.h>
 #include <net/netlabel.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <asm/ioctls.h>
 #include <asm/atomic.h>
 #include <linux/bitops.h>
@@ -104,7 +103,9 @@ int selinux_enforcing;
 
 static int __init enforcing_setup(char *str)
 {
-       selinux_enforcing = simple_strtol(str, NULL, 0);
+       unsigned long enforcing;
+       if (!strict_strtoul(str, 0, &enforcing))
+               selinux_enforcing = enforcing ? 1 : 0;
        return 1;
 }
 __setup("enforcing=", enforcing_setup);
@@ -115,7 +116,9 @@ int selinux_enabled = CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE;
 
 static int __init selinux_enabled_setup(char *str)
 {
-       selinux_enabled = simple_strtol(str, NULL, 0);
+       unsigned long enabled;
+       if (!strict_strtoul(str, 0, &enabled))
+               selinux_enabled = enabled ? 1 : 0;
        return 1;
 }
 __setup("selinux=", selinux_enabled_setup);
@@ -123,13 +126,11 @@ __setup("selinux=", selinux_enabled_setup);
 int selinux_enabled = 1;
 #endif
 
-/* Original (dummy) security module. */
-static struct security_operations *original_ops;
 
-/* Minimal support for a secondary security module,
-   just to allow the use of the dummy or capability modules.
-   The owlsm module can alternatively be used as a secondary
  module as long as CONFIG_OWLSM_FD is not enabled. */
+/*
+ * Minimal support for a secondary security module,
+ * just to allow the use of the capability module.
+ */
 static struct security_operations *secondary_ops;
 
 /* Lists of inode and superblock security structures initialized
@@ -554,13 +555,15 @@ static int selinux_set_mnt_opts(struct super_block *sb,
        struct task_security_struct *tsec = current->security;
        struct superblock_security_struct *sbsec = sb->s_security;
        const char *name = sb->s_type->name;
-       struct inode *inode = sbsec->sb->s_root->d_inode;
-       struct inode_security_struct *root_isec = inode->i_security;
+       struct dentry *root = sb->s_root;
+       struct inode *root_inode = root->d_inode;
+       struct inode_security_struct *root_isec = root_inode->i_security;
        u32 fscontext_sid = 0, context_sid = 0, rootcontext_sid = 0;
        u32 defcontext_sid = 0;
        char **mount_options = opts->mnt_opts;
        int *flags = opts->mnt_opts_flags;
        int num_opts = opts->num_mnt_opts;
+       bool can_xattr = false;
 
        mutex_lock(&sbsec->lock);
 
@@ -594,7 +597,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
         */
        if (sbsec->initialized && (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA)
            && (num_opts == 0))
-               goto out;
+               goto out;
 
        /*
         * parse the mount options, check if they are valid sids.
@@ -664,14 +667,24 @@ static int selinux_set_mnt_opts(struct super_block *sb,
                goto out;
        }
 
-       if (strcmp(sb->s_type->name, "proc") == 0)
+       if (strcmp(name, "proc") == 0)
                sbsec->proc = 1;
 
+       /*
+        * test if the fs supports xattrs, fs_use might make use of this if the
+        * fs has no definition in policy.
+        */
+       if (root_inode->i_op->getxattr) {
+               rc = root_inode->i_op->getxattr(root, XATTR_NAME_SELINUX, NULL, 0);
+               if (rc >= 0 || rc == -ENODATA)
+                       can_xattr = true;
+       }
+
        /* Determine the labeling behavior to use for this filesystem type. */
-       rc = security_fs_use(sb->s_type->name, &sbsec->behavior, &sbsec->sid);
+       rc = security_fs_use(name, &sbsec->behavior, &sbsec->sid, can_xattr);
        if (rc) {
                printk(KERN_WARNING "%s: security_fs_use(%s) returned %d\n",
-                      __func__, sb->s_type->name, rc);
+                      __func__, name, rc);
                goto out;
        }
 
@@ -956,6 +969,57 @@ out_err:
        return rc;
 }
 
+void selinux_write_opts(struct seq_file *m, struct security_mnt_opts *opts)
+{
+       int i;
+       char *prefix;
+
+       for (i = 0; i < opts->num_mnt_opts; i++) {
+               char *has_comma = strchr(opts->mnt_opts[i], ',');
+
+               switch (opts->mnt_opts_flags[i]) {
+               case CONTEXT_MNT:
+                       prefix = CONTEXT_STR;
+                       break;
+               case FSCONTEXT_MNT:
+                       prefix = FSCONTEXT_STR;
+                       break;
+               case ROOTCONTEXT_MNT:
+                       prefix = ROOTCONTEXT_STR;
+                       break;
+               case DEFCONTEXT_MNT:
+                       prefix = DEFCONTEXT_STR;
+                       break;
+               default:
+                       BUG();
+               };
+               /* we need a comma before each option */
+               seq_putc(m, ',');
+               seq_puts(m, prefix);
+               if (has_comma)
+                       seq_putc(m, '\"');
+               seq_puts(m, opts->mnt_opts[i]);
+               if (has_comma)
+                       seq_putc(m, '\"');
+       }
+}
+
+static int selinux_sb_show_options(struct seq_file *m, struct super_block *sb)
+{
+       struct security_mnt_opts opts;
+       int rc;
+
+       rc = selinux_get_mnt_opts(sb, &opts);
+       if (rc)
+               return rc;
+
+       selinux_write_opts(m, &opts);
+
+       security_free_mnt_opts(&opts);
+
+       return rc;
+}
+
 static inline u16 inode_mode_to_security_class(umode_t mode)
 {
        switch (mode & S_IFMT) {
@@ -1682,14 +1746,23 @@ static inline u32 file_to_av(struct file *file)
 
 /* Hook functions begin here. */
 
-static int selinux_ptrace(struct task_struct *parent, struct task_struct *child)
+static int selinux_ptrace(struct task_struct *parent,
+                         struct task_struct *child,
+                         unsigned int mode)
 {
        int rc;
 
-       rc = secondary_ops->ptrace(parent, child);
+       rc = secondary_ops->ptrace(parent, child, mode);
        if (rc)
                return rc;
 
+       if (mode == PTRACE_MODE_READ) {
+               struct task_security_struct *tsec = parent->security;
+               struct task_security_struct *csec = child->security;
+               return avc_has_perm(tsec->sid, csec->sid,
+                                   SECCLASS_FILE, FILE__READ, NULL);
+       }
+
        return task_has_perm(parent, child, PROCESS__PTRACE);
 }
 
@@ -2495,7 +2568,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
        }
 
        if (value && len) {
-               rc = security_sid_to_context(newsid, &context, &clen);
+               rc = security_sid_to_context_force(newsid, &context, &clen);
                if (rc) {
                        kfree(namep);
                        return rc;
@@ -2669,6 +2742,11 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
                return rc;
 
        rc = security_context_to_sid(value, size, &newsid);
+       if (rc == -EINVAL) {
+               if (!capable(CAP_MAC_ADMIN))
+                       return rc;
+               rc = security_context_to_sid_force(value, size, &newsid);
+       }
        if (rc)
                return rc;
 
@@ -2690,7 +2768,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
 }
 
 static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
-                                        const void *value, size_t size,
+                                       const void *value, size_t size,
                                        int flags)
 {
        struct inode *inode = dentry->d_inode;
@@ -2703,10 +2781,11 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
                return;
        }
 
-       rc = security_context_to_sid(value, size, &newsid);
+       rc = security_context_to_sid_force(value, size, &newsid);
        if (rc) {
-               printk(KERN_WARNING "%s:  unable to obtain SID for context "
-                      "%s, rc=%d\n", __func__, (char *)value, -rc);
+               printk(KERN_ERR "SELinux:  unable to map context to SID"
+                      "for (%s, %lu), rc=%d\n",
+                      inode->i_sb->s_id, inode->i_ino, -rc);
                return;
        }
 
@@ -2735,9 +2814,7 @@ static int selinux_inode_removexattr(struct dentry *dentry, const char *name)
 }
 
 /*
- * Copy the in-core inode security context value to the user.  If the
- * getxattr() prior to this succeeded, check to see if we need to
- * canonicalize the value to be finally returned to the user.
+ * Copy the inode security context value to the user.
  *
  * Permission check is handled by selinux_inode_getxattr hook.
  */
@@ -2746,12 +2823,33 @@ static int selinux_inode_getsecurity(const struct inode *inode, const char *name
        u32 size;
        int error;
        char *context = NULL;
+       struct task_security_struct *tsec = current->security;
        struct inode_security_struct *isec = inode->i_security;
 
        if (strcmp(name, XATTR_SELINUX_SUFFIX))
                return -EOPNOTSUPP;
 
-       error = security_sid_to_context(isec->sid, &context, &size);
+       /*
+        * If the caller has CAP_MAC_ADMIN, then get the raw context
+        * value even if it is not defined by current policy; otherwise,
+        * use the in-core value under current policy.
+        * Use the non-auditing forms of the permission checks since
+        * getxattr may be called by unprivileged processes commonly
+        * and lack of permission just means that we fall back to the
+        * in-core context value, not a denial.
+        */
+       error = secondary_ops->capable(current, CAP_MAC_ADMIN);
+       if (!error)
+               error = avc_has_perm_noaudit(tsec->sid, tsec->sid,
+                                            SECCLASS_CAPABILITY2,
+                                            CAPABILITY2__MAC_ADMIN,
+                                            0,
+                                            NULL);
+       if (!error)
+               error = security_sid_to_context_force(isec->sid, &context,
+                                                     &size);
+       else
+               error = security_sid_to_context(isec->sid, &context, &size);
        if (error)
                return error;
        error = size;
@@ -2865,46 +2963,16 @@ static void selinux_file_free_security(struct file *file)
 static int selinux_file_ioctl(struct file *file, unsigned int cmd,
                              unsigned long arg)
 {
-       int error = 0;
-
-       switch (cmd) {
-       case FIONREAD:
-       /* fall through */
-       case FIBMAP:
-       /* fall through */
-       case FIGETBSZ:
-       /* fall through */
-       case EXT2_IOC_GETFLAGS:
-       /* fall through */
-       case EXT2_IOC_GETVERSION:
-               error = file_has_perm(current, file, FILE__GETATTR);
-               break;
-
-       case EXT2_IOC_SETFLAGS:
-       /* fall through */
-       case EXT2_IOC_SETVERSION:
-               error = file_has_perm(current, file, FILE__SETATTR);
-               break;
-
-       /* sys_ioctl() checks */
-       case FIONBIO:
-       /* fall through */
-       case FIOASYNC:
-               error = file_has_perm(current, file, 0);
-               break;
+       u32 av = 0;
 
-       case KDSKBENT:
-       case KDSKBSENT:
-               error = task_has_capability(current, CAP_SYS_TTY_CONFIG);
-               break;
+       if (_IOC_DIR(cmd) & _IOC_WRITE)
+               av |= FILE__WRITE;
+       if (_IOC_DIR(cmd) & _IOC_READ)
+               av |= FILE__READ;
+       if (!av)
+               av = FILE__IOCTL;
 
-       /* default case assumes that the command will go
-        * to the file's ioctl() function.
-        */
-       default:
-               error = file_has_perm(current, file, FILE__IOCTL);
-       }
-       return error;
+       return file_has_perm(current, file, av);
 }
 
 static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
@@ -3663,7 +3731,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
                struct sockaddr_in6 *addr6 = NULL;
                unsigned short snum;
                struct sock *sk = sock->sk;
-               u32 sid, node_perm, addrlen;
+               u32 sid, node_perm;
 
                tsec = current->security;
                isec = SOCK_INODE(sock)->i_security;
@@ -3671,12 +3739,10 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
                if (family == PF_INET) {
                        addr4 = (struct sockaddr_in *)address;
                        snum = ntohs(addr4->sin_port);
-                       addrlen = sizeof(addr4->sin_addr.s_addr);
                        addrp = (char *)&addr4->sin_addr.s_addr;
                } else {
                        addr6 = (struct sockaddr_in6 *)address;
                        snum = ntohs(addr6->sin6_port);
-                       addrlen = sizeof(addr6->sin6_addr.s6_addr);
                        addrp = (char *)&addr6->sin6_addr.s6_addr;
                }
 
@@ -5047,24 +5113,6 @@ static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
        *secid = isec->sid;
 }
 
-/* module stacking operations */
-static int selinux_register_security(const char *name, struct security_operations *ops)
-{
-       if (secondary_ops != original_ops) {
-               printk(KERN_ERR "%s:  There is already a secondary security "
-                      "module registered.\n", __func__);
-               return -EINVAL;
-       }
-
-       secondary_ops = ops;
-
-       printk(KERN_INFO "%s:  Registering secondary module %s\n",
-              __func__,
-              name);
-
-       return 0;
-}
-
 static void selinux_d_instantiate(struct dentry *dentry, struct inode *inode)
 {
        if (inode)
@@ -5153,6 +5201,12 @@ static int selinux_setprocattr(struct task_struct *p,
                        size--;
                }
                error = security_context_to_sid(value, size, &sid);
+               if (error == -EINVAL && !strcmp(name, "fscreate")) {
+                       if (!capable(CAP_MAC_ADMIN))
+                               return error;
+                       error = security_context_to_sid_force(value, size,
+                                                             &sid);
+               }
                if (error)
                        return error;
        }
@@ -5186,12 +5240,12 @@ static int selinux_setprocattr(struct task_struct *p,
                        struct task_struct *g, *t;
                        struct mm_struct *mm = p->mm;
                        read_lock(&tasklist_lock);
-                       do_each_thread(g, t)
+                       do_each_thread(g, t) {
                                if (t->mm == mm && t != p) {
                                        read_unlock(&tasklist_lock);
                                        return -EPERM;
                                }
-                       while_each_thread(g, t);
+                       while_each_thread(g, t);
                        read_unlock(&tasklist_lock);
                }
 
@@ -5343,10 +5397,10 @@ static struct security_operations selinux_ops = {
        .sb_free_security =             selinux_sb_free_security,
        .sb_copy_data =                 selinux_sb_copy_data,
        .sb_kern_mount =                selinux_sb_kern_mount,
+       .sb_show_options =              selinux_sb_show_options,
        .sb_statfs =                    selinux_sb_statfs,
        .sb_mount =                     selinux_mount,
        .sb_umount =                    selinux_umount,
-       .sb_get_mnt_opts =              selinux_get_mnt_opts,
        .sb_set_mnt_opts =              selinux_set_mnt_opts,
        .sb_clone_mnt_opts =            selinux_sb_clone_mnt_opts,
        .sb_parse_opts_str =            selinux_parse_opts_str,
@@ -5378,7 +5432,7 @@ static struct security_operations selinux_ops = {
        .inode_listsecurity =           selinux_inode_listsecurity,
        .inode_need_killpriv =          selinux_inode_need_killpriv,
        .inode_killpriv =               selinux_inode_killpriv,
-       .inode_getsecid =               selinux_inode_getsecid,
+       .inode_getsecid =               selinux_inode_getsecid,
 
        .file_permission =              selinux_file_permission,
        .file_alloc_security =          selinux_file_alloc_security,
@@ -5419,7 +5473,7 @@ static struct security_operations selinux_ops = {
        .task_to_inode =                selinux_task_to_inode,
 
        .ipc_permission =               selinux_ipc_permission,
-       .ipc_getsecid =                 selinux_ipc_getsecid,
+       .ipc_getsecid =                 selinux_ipc_getsecid,
 
        .msg_msg_alloc_security =       selinux_msg_msg_alloc_security,
        .msg_msg_free_security =        selinux_msg_msg_free_security,
@@ -5443,8 +5497,6 @@ static struct security_operations selinux_ops = {
        .sem_semctl =                   selinux_sem_semctl,
        .sem_semop =                    selinux_sem_semop,
 
-       .register_security =            selinux_register_security,
-
        .d_instantiate =                selinux_d_instantiate,
 
        .getprocattr =                  selinux_getprocattr,
@@ -5538,7 +5590,7 @@ static __init int selinux_init(void)
                                            0, SLAB_PANIC, NULL);
        avc_init();
 
-       original_ops = secondary_ops = security_ops;
+       secondary_ops = security_ops;
        if (!secondary_ops)
                panic("SELinux: No initial security operations\n");
        if (register_security(&selinux_ops))
index 6c8b9ef..1bdf973 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * SELinux support for the Audit LSM hooks
  *
- * Most of below header was moved from include/linux/selinux.h which 
+ * Most of below header was moved from include/linux/selinux.h which
  * is released under below copyrights:
  *
  * Author: James Morris <jmorris@redhat.com>
@@ -52,7 +52,7 @@ void selinux_audit_rule_free(void *rule);
  *     -errno on failure.
  */
 int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule,
-                             struct audit_context *actx);
+                            struct audit_context *actx);
 
 /**
  *     selinux_audit_rule_known - check to see if rule contains selinux fields.
index 8e23d7a..7b9769f 100644 (file)
@@ -75,13 +75,12 @@ struct avc_audit_data {
 
 /* Initialize an AVC audit data structure. */
 #define AVC_AUDIT_DATA_INIT(_d,_t) \
-        { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
+       { memset((_d), 0, sizeof(struct avc_audit_data)); (_d)->type = AVC_AUDIT_DATA_##_t; }
 
 /*
  * AVC statistics
  */
-struct avc_cache_stats
-{
+struct avc_cache_stats {
        unsigned int lookups;
        unsigned int hits;
        unsigned int misses;
@@ -97,8 +96,8 @@ struct avc_cache_stats
 void __init avc_init(void);
 
 void avc_audit(u32 ssid, u32 tsid,
-               u16 tclass, u32 requested,
-               struct av_decision *avd, int result, struct avc_audit_data *auditdata);
+              u16 tclass, u32 requested,
+              struct av_decision *avd, int result, struct avc_audit_data *auditdata);
 
 #define AVC_STRICT 1 /* Ignore permissive mode. */
 int avc_has_perm_noaudit(u32 ssid, u32 tsid,
@@ -107,8 +106,8 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
                         struct av_decision *avd);
 
 int avc_has_perm(u32 ssid, u32 tsid,
-                 u16 tclass, u32 requested,
-                 struct avc_audit_data *auditdata);
+                u16 tclass, u32 requested,
+                struct avc_audit_data *auditdata);
 
 u32 avc_policy_seqno(void);
 
@@ -122,7 +121,7 @@ u32 avc_policy_seqno(void);
 #define AVC_CALLBACK_AUDITDENY_DISABLE 128
 
 int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid,
-                                     u16 tclass, u32 perms,
+                                    u16 tclass, u32 perms,
                                     u32 *out_retained),
                     u32 events, u32 ssid, u32 tsid,
                     u16 tclass, u32 perms);
index 032c235..91070ab 100644 (file)
@@ -44,7 +44,6 @@ struct inode_security_struct {
        u16 sclass;             /* security class of this object */
        unsigned char initialized;      /* initialization flag */
        struct mutex lock;
-       unsigned char inherit;  /* inherit SID from parent entry */
 };
 
 struct file_security_struct {
index ad30ac4..44cba2e 100644 (file)
@@ -93,12 +93,17 @@ int security_change_sid(u32 ssid, u32 tsid,
 int security_sid_to_context(u32 sid, char **scontext,
        u32 *scontext_len);
 
+int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
+
 int security_context_to_sid(const char *scontext, u32 scontext_len,
        u32 *out_sid);
 
 int security_context_to_sid_default(const char *scontext, u32 scontext_len,
                                    u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
 
+int security_context_to_sid_force(const char *scontext, u32 scontext_len,
+                                 u32 *sid);
+
 int security_get_user_sids(u32 callsid, char *username,
                           u32 **sids, u32 *nel);
 
@@ -131,7 +136,7 @@ int security_get_allow_unknown(void);
 #define SECURITY_FS_USE_MNTPOINT       6 /* use mountpoint labeling */
 
 int security_fs_use(const char *fstype, unsigned int *behavior,
-       u32 *sid);
+       u32 *sid, bool can_xattr);
 
 int security_genfs_sid(const char *fstype, char *name, u16 sclass,
        u32 *sid);
index b6ccd09..7100072 100644 (file)
@@ -38,7 +38,6 @@
 #include <linux/ipv6.h>
 #include <net/ip.h>
 #include <net/ipv6.h>
-#include <asm/bug.h>
 
 #include "netnode.h"
 #include "objsec.h"
index 90b4cff..fe7fba6 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/ipv6.h>
 #include <net/ip.h>
 #include <net/ipv6.h>
-#include <asm/bug.h>
 
 #include "netport.h"
 #include "objsec.h"
@@ -272,7 +271,7 @@ static __init int sel_netport_init(void)
        }
 
        ret = avc_add_callback(sel_netport_avc_callback, AVC_CALLBACK_RESET,
-                              SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
+                              SECSID_NULL, SECSID_NULL, SECCLASS_NULL, 0);
        if (ret != 0)
                panic("avc_add_callback() failed, error %d\n", ret);
 
index ac1ccc1..69c9dcc 100644 (file)
@@ -27,7 +27,7 @@
 #include <linux/seq_file.h>
 #include <linux/percpu.h>
 #include <linux/audit.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 /* selinuxfs pseudo filesystem for exporting the security policy API.
    Based on the proc code and the fs/nfsd/nfsctl.c code. */
@@ -57,14 +57,18 @@ int selinux_compat_net = SELINUX_COMPAT_NET_VALUE;
 
 static int __init checkreqprot_setup(char *str)
 {
-       selinux_checkreqprot = simple_strtoul(str, NULL, 0) ? 1 : 0;
+       unsigned long checkreqprot;
+       if (!strict_strtoul(str, 0, &checkreqprot))
+               selinux_checkreqprot = checkreqprot ? 1 : 0;
        return 1;
 }
 __setup("checkreqprot=", checkreqprot_setup);
 
 static int __init selinux_compat_net_setup(char *str)
 {
-       selinux_compat_net = simple_strtoul(str, NULL, 0) ? 1 : 0;
+       unsigned long compat_net;
+       if (!strict_strtoul(str, 0, &compat_net))
+               selinux_compat_net = compat_net ? 1 : 0;
        return 1;
 }
 __setup("selinux_compat_net=", selinux_compat_net_setup);
@@ -352,11 +356,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
                length = count;
 
 out1:
-
-       printk(KERN_INFO "SELinux: policy loaded with handle_unknown=%s\n",
-              (security_get_reject_unknown() ? "reject" :
-               (security_get_allow_unknown() ? "allow" : "deny")));
-
        audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
                "policy loaded auid=%u ses=%u",
                audit_get_loginuid(current),
index 9e66263..a1be97f 100644 (file)
@@ -311,7 +311,7 @@ void avtab_hash_eval(struct avtab *h, char *tag)
        }
 
        printk(KERN_DEBUG "SELinux: %s:  %d entries and %d/%d buckets used, "
-              "longest chain length %d sum of chain length^2 %Lu\n",
+              "longest chain length %d sum of chain length^2 %llu\n",
               tag, h->nel, slots_used, h->nslot, max_chain_len,
               chain2_len_sum);
 }
index b9a6f7f..658c2bd 100644 (file)
@@ -28,6 +28,8 @@ struct context {
        u32 role;
        u32 type;
        struct mls_range range;
+       char *str;      /* string representation if context cannot be mapped. */
+       u32 len;        /* length of string in bytes */
 };
 
 static inline void mls_context_init(struct context *c)
@@ -106,20 +108,43 @@ static inline void context_init(struct context *c)
 
 static inline int context_cpy(struct context *dst, struct context *src)
 {
+       int rc;
+
        dst->user = src->user;
        dst->role = src->role;
        dst->type = src->type;
-       return mls_context_cpy(dst, src);
+       if (src->str) {
+               dst->str = kstrdup(src->str, GFP_ATOMIC);
+               if (!dst->str)
+                       return -ENOMEM;
+               dst->len = src->len;
+       } else {
+               dst->str = NULL;
+               dst->len = 0;
+       }
+       rc = mls_context_cpy(dst, src);
+       if (rc) {
+               kfree(dst->str);
+               return rc;
+       }
+       return 0;
 }
 
 static inline void context_destroy(struct context *c)
 {
        c->user = c->role = c->type = 0;
+       kfree(c->str);
+       c->str = NULL;
+       c->len = 0;
        mls_context_destroy(c);
 }
 
 static inline int context_cmp(struct context *c1, struct context *c2)
 {
+       if (c1->len && c2->len)
+               return (c1->len == c2->len && !strcmp(c1->str, c2->str));
+       if (c1->len || c2->len)
+               return 0;
        return ((c1->user == c2->user) &&
                (c1->role == c2->role) &&
                (c1->type == c2->type) &&
index 8b1706b..77d745d 100644 (file)
@@ -239,7 +239,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c)
  * Policy read-lock must be held for sidtab lookup.
  *
  */
-int mls_context_to_sid(char oldc,
+int mls_context_to_sid(struct policydb *pol,
+                      char oldc,
                       char **scontext,
                       struct context *context,
                       struct sidtab *s,
@@ -286,7 +287,7 @@ int mls_context_to_sid(char oldc,
                *p++ = 0;
 
        for (l = 0; l < 2; l++) {
-               levdatum = hashtab_search(policydb.p_levels.table, scontextp);
+               levdatum = hashtab_search(pol->p_levels.table, scontextp);
                if (!levdatum) {
                        rc = -EINVAL;
                        goto out;
@@ -311,7 +312,7 @@ int mls_context_to_sid(char oldc,
                                        *rngptr++ = 0;
                                }
 
-                               catdatum = hashtab_search(policydb.p_cats.table,
+                               catdatum = hashtab_search(pol->p_cats.table,
                                                          scontextp);
                                if (!catdatum) {
                                        rc = -EINVAL;
@@ -327,7 +328,7 @@ int mls_context_to_sid(char oldc,
                                if (rngptr) {
                                        int i;
 
-                                       rngdatum = hashtab_search(policydb.p_cats.table, rngptr);
+                                       rngdatum = hashtab_search(pol->p_cats.table, rngptr);
                                        if (!rngdatum) {
                                                rc = -EINVAL;
                                                goto out;
@@ -395,7 +396,7 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask)
        if (!tmpstr) {
                rc = -ENOMEM;
        } else {
-               rc = mls_context_to_sid(':', &tmpstr, context,
+               rc = mls_context_to_sid(&policydb, ':', &tmpstr, context,
                                        NULL, SECSID_NULL);
                kfree(freestr);
        }
@@ -436,13 +437,13 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
                struct mls_level *usercon_clr = &(usercon->range.level[1]);
 
                /* Honor the user's default level if we can */
-               if (mls_level_between(user_def, fromcon_sen, fromcon_clr)) {
+               if (mls_level_between(user_def, fromcon_sen, fromcon_clr))
                        *usercon_sen = *user_def;
-               } else if (mls_level_between(fromcon_sen, user_def, user_clr)) {
+               else if (mls_level_between(fromcon_sen, user_def, user_clr))
                        *usercon_sen = *fromcon_sen;
-               } else if (mls_level_between(fromcon_clr, user_low, user_def)) {
+               else if (mls_level_between(fromcon_clr, user_low, user_def))
                        *usercon_sen = *user_low;
-               else
+               else
                        return -EINVAL;
 
                /* Lower the clearance of available contexts
index 0fdf625..1276715 100644 (file)
@@ -30,7 +30,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c);
 int mls_range_isvalid(struct policydb *p, struct mls_range *r);
 int mls_level_isvalid(struct policydb *p, struct mls_level *l);
 
-int mls_context_to_sid(char oldc,
+int mls_context_to_sid(struct policydb *p,
+                      char oldc,
                       char **scontext,
                       struct context *context,
                       struct sidtab *s,
index 84f8cc7..2391761 100644 (file)
@@ -1478,7 +1478,8 @@ int policydb_read(struct policydb *p, void *fp)
        struct ocontext *l, *c, *newc;
        struct genfs *genfs_p, *genfs, *newgenfs;
        int i, j, rc;
-       __le32 buf[8];
+       __le32 buf[4];
+       u32 nodebuf[8];
        u32 len, len2, config, nprim, nel, nel2;
        char *policydb_str;
        struct policydb_compat_info *info;
@@ -1749,11 +1750,11 @@ int policydb_read(struct policydb *p, void *fp)
                                        goto bad;
                                break;
                        case OCON_NODE:
-                               rc = next_entry(buf, fp, sizeof(u32) * 2);
+                               rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
                                if (rc < 0)
                                        goto bad;
-                               c->u.node.addr = le32_to_cpu(buf[0]);
-                               c->u.node.mask = le32_to_cpu(buf[1]);
+                               c->u.node.addr = nodebuf[0]; /* network order */
+                               c->u.node.mask = nodebuf[1]; /* network order */
                                rc = context_read_and_validate(&c->context[0], p, fp);
                                if (rc)
                                        goto bad;
@@ -1782,13 +1783,13 @@ int policydb_read(struct policydb *p, void *fp)
                        case OCON_NODE6: {
                                int k;
 
-                               rc = next_entry(buf, fp, sizeof(u32) * 8);
+                               rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
                                if (rc < 0)
                                        goto bad;
                                for (k = 0; k < 4; k++)
-                                       c->u.node6.addr[k] = le32_to_cpu(buf[k]);
+                                       c->u.node6.addr[k] = nodebuf[k];
                                for (k = 0; k < 4; k++)
-                                       c->u.node6.mask[k] = le32_to_cpu(buf[k+4]);
+                                       c->u.node6.mask[k] = nodebuf[k+4];
                                if (context_read_and_validate(&c->context[0], p, fp))
                                        goto bad;
                                break;
index dcc2e1c..8e42da1 100644 (file)
@@ -71,14 +71,6 @@ int selinux_policycap_openperm;
 extern const struct selinux_class_perm selinux_class_perm;
 
 static DEFINE_RWLOCK(policy_rwlock);
-#define POLICY_RDLOCK read_lock(&policy_rwlock)
-#define POLICY_WRLOCK write_lock_irq(&policy_rwlock)
-#define POLICY_RDUNLOCK read_unlock(&policy_rwlock)
-#define POLICY_WRUNLOCK write_unlock_irq(&policy_rwlock)
-
-static DEFINE_MUTEX(load_mutex);
-#define LOAD_LOCK mutex_lock(&load_mutex)
-#define LOAD_UNLOCK mutex_unlock(&load_mutex)
 
 static struct sidtab sidtab;
 struct policydb policydb;
@@ -332,7 +324,7 @@ static int context_struct_compute_av(struct context *scontext,
                goto inval_class;
        if (unlikely(tclass > policydb.p_classes.nprim))
                if (tclass > kdefs->cts_len ||
-                   !kdefs->class_to_string[tclass - 1] ||
+                   !kdefs->class_to_string[tclass] ||
                    !policydb.allow_unknown)
                        goto inval_class;
 
@@ -415,9 +407,19 @@ static int context_struct_compute_av(struct context *scontext,
        return 0;
 
 inval_class:
-       printk(KERN_ERR "SELinux: %s:  unrecognized class %d\n", __func__,
-               tclass);
-       return -EINVAL;
+       if (!tclass || tclass > kdefs->cts_len ||
+           !kdefs->class_to_string[tclass]) {
+               if (printk_ratelimit())
+                       printk(KERN_ERR "SELinux: %s:  unrecognized class %d\n",
+                              __func__, tclass);
+               return -EINVAL;
+       }
+
+       /*
+        * Known to the kernel, but not to the policy.
+        * Handle as a denial (allowed is 0).
+        */
+       return 0;
 }
 
 /*
@@ -429,7 +431,7 @@ int security_permissive_sid(u32 sid)
        u32 type;
        int rc;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        context = sidtab_search(&sidtab, sid);
        BUG_ON(!context);
@@ -441,7 +443,7 @@ int security_permissive_sid(u32 sid)
         */
        rc = ebitmap_get_bit(&policydb.permissive_map, type);
 
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -486,7 +488,7 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
        if (!ss_initialized)
                return 0;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        /*
         * Remap extended Netlink classes for old policy versions.
@@ -543,7 +545,7 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -578,7 +580,7 @@ int security_compute_av(u32 ssid,
                return 0;
        }
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        scontext = sidtab_search(&sidtab, ssid);
        if (!scontext) {
@@ -598,7 +600,7 @@ int security_compute_av(u32 ssid,
        rc = context_struct_compute_av(scontext, tcontext, tclass,
                                       requested, avd);
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -616,6 +618,14 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
        *scontext = NULL;
        *scontext_len = 0;
 
+       if (context->len) {
+               *scontext_len = context->len;
+               *scontext = kstrdup(context->str, GFP_ATOMIC);
+               if (!(*scontext))
+                       return -ENOMEM;
+               return 0;
+       }
+
        /* Compute the size of the context. */
        *scontext_len += strlen(policydb.p_user_val_to_name[context->user - 1]) + 1;
        *scontext_len += strlen(policydb.p_role_val_to_name[context->role - 1]) + 1;
@@ -655,17 +665,8 @@ const char *security_get_initial_sid_context(u32 sid)
        return initial_sid_to_string[sid];
 }
 
-/**
- * security_sid_to_context - Obtain a context for a given SID.
- * @sid: security identifier, SID
- * @scontext: security context
- * @scontext_len: length in bytes
- *
- * Write the string representation of the context associated with @sid
- * into a dynamically allocated string of the correct size.  Set @scontext
- * to point to this string and set @scontext_len to the length of the string.
- */
-int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
+static int security_sid_to_context_core(u32 sid, char **scontext,
+                                       u32 *scontext_len, int force)
 {
        struct context *context;
        int rc = 0;
@@ -692,8 +693,11 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
                rc = -EINVAL;
                goto out;
        }
-       POLICY_RDLOCK;
-       context = sidtab_search(&sidtab, sid);
+       read_lock(&policy_rwlock);
+       if (force)
+               context = sidtab_search_force(&sidtab, sid);
+       else
+               context = sidtab_search(&sidtab, sid);
        if (!context) {
                printk(KERN_ERR "SELinux: %s:  unrecognized SID %d\n",
                        __func__, sid);
@@ -702,59 +706,54 @@ int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
        }
        rc = context_struct_to_string(context, scontext, scontext_len);
 out_unlock:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
 out:
        return rc;
 
 }
 
-static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
-                                       u32 *sid, u32 def_sid, gfp_t gfp_flags)
+/**
+ * security_sid_to_context - Obtain a context for a given SID.
+ * @sid: security identifier, SID
+ * @scontext: security context
+ * @scontext_len: length in bytes
+ *
+ * Write the string representation of the context associated with @sid
+ * into a dynamically allocated string of the correct size.  Set @scontext
+ * to point to this string and set @scontext_len to the length of the string.
+ */
+int security_sid_to_context(u32 sid, char **scontext, u32 *scontext_len)
+{
+       return security_sid_to_context_core(sid, scontext, scontext_len, 0);
+}
+
+int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len)
+{
+       return security_sid_to_context_core(sid, scontext, scontext_len, 1);
+}
+
+/*
+ * Caveat:  Mutates scontext.
+ */
+static int string_to_context_struct(struct policydb *pol,
+                                   struct sidtab *sidtabp,
+                                   char *scontext,
+                                   u32 scontext_len,
+                                   struct context *ctx,
+                                   u32 def_sid)
 {
-       char *scontext2;
-       struct context context;
        struct role_datum *role;
        struct type_datum *typdatum;
        struct user_datum *usrdatum;
        char *scontextp, *p, oldc;
        int rc = 0;
 
-       if (!ss_initialized) {
-               int i;
-
-               for (i = 1; i < SECINITSID_NUM; i++) {
-                       if (!strcmp(initial_sid_to_string[i], scontext)) {
-                               *sid = i;
-                               goto out;
-                       }
-               }
-               *sid = SECINITSID_KERNEL;
-               goto out;
-       }
-       *sid = SECSID_NULL;
-
-       /* Copy the string so that we can modify the copy as we parse it.
-          The string should already by null terminated, but we append a
-          null suffix to the copy to avoid problems with the existing
-          attr package, which doesn't view the null terminator as part
-          of the attribute value. */
-       scontext2 = kmalloc(scontext_len+1, gfp_flags);
-       if (!scontext2) {
-               rc = -ENOMEM;
-               goto out;
-       }
-       memcpy(scontext2, scontext, scontext_len);
-       scontext2[scontext_len] = 0;
-
-       context_init(&context);
-       *sid = SECSID_NULL;
-
-       POLICY_RDLOCK;
+       context_init(ctx);
 
        /* Parse the security context. */
 
        rc = -EINVAL;
-       scontextp = (char *) scontext2;
+       scontextp = (char *) scontext;
 
        /* Extract the user. */
        p = scontextp;
@@ -762,15 +761,15 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
                p++;
 
        if (*p == 0)
-               goto out_unlock;
+               goto out;
 
        *p++ = 0;
 
-       usrdatum = hashtab_search(policydb.p_users.table, scontextp);
+       usrdatum = hashtab_search(pol->p_users.table, scontextp);
        if (!usrdatum)
-               goto out_unlock;
+               goto out;
 
-       context.user = usrdatum->value;
+       ctx->user = usrdatum->value;
 
        /* Extract role. */
        scontextp = p;
@@ -778,14 +777,14 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
                p++;
 
        if (*p == 0)
-               goto out_unlock;
+               goto out;
 
        *p++ = 0;
 
-       role = hashtab_search(policydb.p_roles.table, scontextp);
+       role = hashtab_search(pol->p_roles.table, scontextp);
        if (!role)
-               goto out_unlock;
-       context.role = role->value;
+               goto out;
+       ctx->role = role->value;
 
        /* Extract type. */
        scontextp = p;
@@ -794,33 +793,87 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
        oldc = *p;
        *p++ = 0;
 
-       typdatum = hashtab_search(policydb.p_types.table, scontextp);
+       typdatum = hashtab_search(pol->p_types.table, scontextp);
        if (!typdatum)
-               goto out_unlock;
+               goto out;
 
-       context.type = typdatum->value;
+       ctx->type = typdatum->value;
 
-       rc = mls_context_to_sid(oldc, &p, &context, &sidtab, def_sid);
+       rc = mls_context_to_sid(pol, oldc, &p, ctx, sidtabp, def_sid);
        if (rc)
-               goto out_unlock;
+               goto out;
 
-       if ((p - scontext2) < scontext_len) {
+       if ((p - scontext) < scontext_len) {
                rc = -EINVAL;
-               goto out_unlock;
+               goto out;
        }
 
        /* Check the validity of the new context. */
-       if (!policydb_context_isvalid(&policydb, &context)) {
+       if (!policydb_context_isvalid(pol, ctx)) {
                rc = -EINVAL;
-               goto out_unlock;
+               context_destroy(ctx);
+               goto out;
        }
-       /* Obtain the new sid. */
+       rc = 0;
+out:
+       return rc;
+}
+
+static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
+                                       u32 *sid, u32 def_sid, gfp_t gfp_flags,
+                                       int force)
+{
+       char *scontext2, *str = NULL;
+       struct context context;
+       int rc = 0;
+
+       if (!ss_initialized) {
+               int i;
+
+               for (i = 1; i < SECINITSID_NUM; i++) {
+                       if (!strcmp(initial_sid_to_string[i], scontext)) {
+                               *sid = i;
+                               return 0;
+                       }
+               }
+               *sid = SECINITSID_KERNEL;
+               return 0;
+       }
+       *sid = SECSID_NULL;
+
+       /* Copy the string so that we can modify the copy as we parse it. */
+       scontext2 = kmalloc(scontext_len+1, gfp_flags);
+       if (!scontext2)
+               return -ENOMEM;
+       memcpy(scontext2, scontext, scontext_len);
+       scontext2[scontext_len] = 0;
+
+       if (force) {
+               /* Save another copy for storing in uninterpreted form */
+               str = kstrdup(scontext2, gfp_flags);
+               if (!str) {
+                       kfree(scontext2);
+                       return -ENOMEM;
+               }
+       }
+
+       read_lock(&policy_rwlock);
+       rc = string_to_context_struct(&policydb, &sidtab,
+                                     scontext2, scontext_len,
+                                     &context, def_sid);
+       if (rc == -EINVAL && force) {
+               context.str = str;
+               context.len = scontext_len;
+               str = NULL;
+       } else if (rc)
+               goto out;
        rc = sidtab_context_to_sid(&sidtab, &context, sid);
-out_unlock:
-       POLICY_RDUNLOCK;
-       context_destroy(&context);
-       kfree(scontext2);
+       if (rc)
+               context_destroy(&context);
 out:
+       read_unlock(&policy_rwlock);
+       kfree(scontext2);
+       kfree(str);
        return rc;
 }
 
@@ -838,7 +891,7 @@ out:
 int security_context_to_sid(const char *scontext, u32 scontext_len, u32 *sid)
 {
        return security_context_to_sid_core(scontext, scontext_len,
-                                           sid, SECSID_NULL, GFP_KERNEL);
+                                           sid, SECSID_NULL, GFP_KERNEL, 0);
 }
 
 /**
@@ -855,6 +908,7 @@ int security_context_to_sid(const char *scontext, u32 scontext_len, u32 *sid)
  * The default SID is passed to the MLS layer to be used to allow
  * kernel labeling of the MLS field if the MLS field is not present
  * (for upgrading to MLS without full relabel).
+ * Implicitly forces adding of the context even if it cannot be mapped yet.
  * Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient
  * memory is available, or 0 on success.
  */
@@ -862,7 +916,14 @@ int security_context_to_sid_default(const char *scontext, u32 scontext_len,
                                    u32 *sid, u32 def_sid, gfp_t gfp_flags)
 {
        return security_context_to_sid_core(scontext, scontext_len,
-                                           sid, def_sid, gfp_flags);
+                                           sid, def_sid, gfp_flags, 1);
+}
+
+int security_context_to_sid_force(const char *scontext, u32 scontext_len,
+                                 u32 *sid)
+{
+       return security_context_to_sid_core(scontext, scontext_len,
+                                           sid, SECSID_NULL, GFP_KERNEL, 1);
 }
 
 static int compute_sid_handle_invalid_context(
@@ -922,7 +983,7 @@ static int security_compute_sid(u32 ssid,
 
        context_init(&newcontext);
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        scontext = sidtab_search(&sidtab, ssid);
        if (!scontext) {
@@ -1027,7 +1088,7 @@ static int security_compute_sid(u32 ssid,
        /* Obtain the sid for the context. */
        rc = sidtab_context_to_sid(&sidtab, &newcontext, out_sid);
 out_unlock:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        context_destroy(&newcontext);
 out:
        return rc;
@@ -1110,6 +1171,7 @@ static int validate_classes(struct policydb *p)
        const struct selinux_class_perm *kdefs = &selinux_class_perm;
        const char *def_class, *def_perm, *pol_class;
        struct symtab *perms;
+       bool print_unknown_handle = 0;
 
        if (p->allow_unknown) {
                u32 num_classes = kdefs->cts_len;
@@ -1130,6 +1192,7 @@ static int validate_classes(struct policydb *p)
                                return -EINVAL;
                        if (p->allow_unknown)
                                p->undefined_perms[i-1] = ~0U;
+                       print_unknown_handle = 1;
                        continue;
                }
                pol_class = p->p_class_val_to_name[i-1];
@@ -1159,6 +1222,7 @@ static int validate_classes(struct policydb *p)
                                return -EINVAL;
                        if (p->allow_unknown)
                                p->undefined_perms[class_val-1] |= perm_val;
+                       print_unknown_handle = 1;
                        continue;
                }
                perdatum = hashtab_search(perms->table, def_perm);
@@ -1206,6 +1270,7 @@ static int validate_classes(struct policydb *p)
                                        return -EINVAL;
                                if (p->allow_unknown)
                                        p->undefined_perms[class_val-1] |= (1 << j);
+                               print_unknown_handle = 1;
                                continue;
                        }
                        perdatum = hashtab_search(perms->table, def_perm);
@@ -1223,6 +1288,9 @@ static int validate_classes(struct policydb *p)
                        }
                }
        }
+       if (print_unknown_handle)
+               printk(KERN_INFO "SELinux: the above unknown classes and permissions will be %s\n",
+                       (security_get_allow_unknown() ? "allowed" : "denied"));
        return 0;
 }
 
@@ -1246,9 +1314,12 @@ static inline int convert_context_handle_invalid_context(struct context *context
                char *s;
                u32 len;
 
-               context_struct_to_string(context, &s, &len);
-               printk(KERN_ERR "SELinux:  context %s is invalid\n", s);
-               kfree(s);
+               if (!context_struct_to_string(context, &s, &len)) {
+                       printk(KERN_WARNING
+                      "SELinux:  Context %s would be invalid if enforcing\n",
+                              s);
+                       kfree(s);
+               }
        }
        return rc;
 }
@@ -1280,6 +1351,37 @@ static int convert_context(u32 key,
 
        args = p;
 
+       if (c->str) {
+               struct context ctx;
+               s = kstrdup(c->str, GFP_KERNEL);
+               if (!s) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+               rc = string_to_context_struct(args->newp, NULL, s,
+                                             c->len, &ctx, SECSID_NULL);
+               kfree(s);
+               if (!rc) {
+                       printk(KERN_INFO
+                      "SELinux:  Context %s became valid (mapped).\n",
+                              c->str);
+                       /* Replace string with mapped representation. */
+                       kfree(c->str);
+                       memcpy(c, &ctx, sizeof(*c));
+                       goto out;
+               } else if (rc == -EINVAL) {
+                       /* Retain string representation for later mapping. */
+                       rc = 0;
+                       goto out;
+               } else {
+                       /* Other error condition, e.g. ENOMEM. */
+                       printk(KERN_ERR
+                      "SELinux:   Unable to map context %s, rc = %d.\n",
+                              c->str, -rc);
+                       goto out;
+               }
+       }
+
        rc = context_cpy(&oldc, c);
        if (rc)
                goto out;
@@ -1319,13 +1421,21 @@ static int convert_context(u32 key,
        }
 
        context_destroy(&oldc);
+       rc = 0;
 out:
        return rc;
 bad:
-       context_struct_to_string(&oldc, &s, &len);
+       /* Map old representation to string and save it. */
+       if (context_struct_to_string(&oldc, &s, &len))
+               return -ENOMEM;
        context_destroy(&oldc);
-       printk(KERN_ERR "SELinux:  invalidating context %s\n", s);
-       kfree(s);
+       context_destroy(c);
+       c->str = s;
+       c->len = len;
+       printk(KERN_INFO
+              "SELinux:  Context %s became invalid (unmapped).\n",
+              c->str);
+       rc = 0;
        goto out;
 }
 
@@ -1359,17 +1469,13 @@ int security_load_policy(void *data, size_t len)
        int rc = 0;
        struct policy_file file = { data, len }, *fp = &file;
 
-       LOAD_LOCK;
-
        if (!ss_initialized) {
                avtab_cache_init();
                if (policydb_read(&policydb, fp)) {
-                       LOAD_UNLOCK;
                        avtab_cache_destroy();
                        return -EINVAL;
                }
                if (policydb_load_isids(&policydb, &sidtab)) {
-                       LOAD_UNLOCK;
                        policydb_destroy(&policydb);
                        avtab_cache_destroy();
                        return -EINVAL;
@@ -1378,7 +1484,6 @@ int security_load_policy(void *data, size_t len)
                if (validate_classes(&policydb)) {
                        printk(KERN_ERR
                               "SELinux:  the definition of a class is incorrect\n");
-                       LOAD_UNLOCK;
                        sidtab_destroy(&sidtab);
                        policydb_destroy(&policydb);
                        avtab_cache_destroy();
@@ -1388,7 +1493,6 @@ int security_load_policy(void *data, size_t len)
                policydb_loaded_version = policydb.policyvers;
                ss_initialized = 1;
                seqno = ++latest_granting;
-               LOAD_UNLOCK;
                selinux_complete_init();
                avc_ss_reset(seqno);
                selnl_notify_policyload(seqno);
@@ -1401,12 +1505,13 @@ int security_load_policy(void *data, size_t len)
        sidtab_hash_eval(&sidtab, "sids");
 #endif
 
-       if (policydb_read(&newpolicydb, fp)) {
-               LOAD_UNLOCK;
+       if (policydb_read(&newpolicydb, fp))
                return -EINVAL;
-       }
 
-       sidtab_init(&newsidtab);
+       if (sidtab_init(&newsidtab)) {
+               policydb_destroy(&newpolicydb);
+               return -ENOMEM;
+       }
 
        /* Verify that the kernel defined classes are correct. */
        if (validate_classes(&newpolicydb)) {
@@ -1429,25 +1534,28 @@ int security_load_policy(void *data, size_t len)
                goto err;
        }
 
-       /* Convert the internal representations of contexts
-          in the new SID table and remove invalid SIDs. */
+       /*
+        * Convert the internal representations of contexts
+        * in the new SID table.
+        */
        args.oldp = &policydb;
        args.newp = &newpolicydb;
-       sidtab_map_remove_on_error(&newsidtab, convert_context, &args);
+       rc = sidtab_map(&newsidtab, convert_context, &args);
+       if (rc)
+               goto err;
 
        /* Save the old policydb and SID table to free later. */
        memcpy(&oldpolicydb, &policydb, sizeof policydb);
        sidtab_set(&oldsidtab, &sidtab);
 
        /* Install the new policydb and SID table. */
-       POLICY_WRLOCK;
+       write_lock_irq(&policy_rwlock);
        memcpy(&policydb, &newpolicydb, sizeof policydb);
        sidtab_set(&sidtab, &newsidtab);
        security_load_policycaps();
        seqno = ++latest_granting;
        policydb_loaded_version = policydb.policyvers;
-       POLICY_WRUNLOCK;
-       LOAD_UNLOCK;
+       write_unlock_irq(&policy_rwlock);
 
        /* Free the old policydb and SID table. */
        policydb_destroy(&oldpolicydb);
@@ -1461,7 +1569,6 @@ int security_load_policy(void *data, size_t len)
        return 0;
 
 err:
-       LOAD_UNLOCK;
        sidtab_destroy(&newsidtab);
        policydb_destroy(&newpolicydb);
        return rc;
@@ -1479,7 +1586,7 @@ int security_port_sid(u8 protocol, u16 port, u32 *out_sid)
        struct ocontext *c;
        int rc = 0;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        c = policydb.ocontexts[OCON_PORT];
        while (c) {
@@ -1504,7 +1611,7 @@ int security_port_sid(u8 protocol, u16 port, u32 *out_sid)
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -1518,7 +1625,7 @@ int security_netif_sid(char *name, u32 *if_sid)
        int rc = 0;
        struct ocontext *c;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        c = policydb.ocontexts[OCON_NETIF];
        while (c) {
@@ -1545,7 +1652,7 @@ int security_netif_sid(char *name, u32 *if_sid)
                *if_sid = SECINITSID_NETIF;
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -1577,7 +1684,7 @@ int security_node_sid(u16 domain,
        int rc = 0;
        struct ocontext *c;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        switch (domain) {
        case AF_INET: {
@@ -1632,7 +1739,7 @@ int security_node_sid(u16 domain,
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -1671,7 +1778,9 @@ int security_get_user_sids(u32 fromsid,
        if (!ss_initialized)
                goto out;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
+
+       context_init(&usercon);
 
        fromcon = sidtab_search(&sidtab, fromsid);
        if (!fromcon) {
@@ -1722,7 +1831,7 @@ int security_get_user_sids(u32 fromsid,
        }
 
 out_unlock:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        if (rc || !mynel) {
                kfree(mysids);
                goto out;
@@ -1775,7 +1884,7 @@ int security_genfs_sid(const char *fstype,
        while (path[0] == '/' && path[1] == '/')
                path++;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        for (genfs = policydb.genfs; genfs; genfs = genfs->next) {
                cmp = strcmp(fstype, genfs->fstype);
@@ -1812,7 +1921,7 @@ int security_genfs_sid(const char *fstype,
 
        *sid = c->sid[0];
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -1825,12 +1934,13 @@ out:
 int security_fs_use(
        const char *fstype,
        unsigned int *behavior,
-       u32 *sid)
+       u32 *sid,
+       bool can_xattr)
 {
        int rc = 0;
        struct ocontext *c;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        c = policydb.ocontexts[OCON_FSUSE];
        while (c) {
@@ -1839,6 +1949,7 @@ int security_fs_use(
                c = c->next;
        }
 
+       /* look for labeling behavior defined in policy */
        if (c) {
                *behavior = c->v.behavior;
                if (!c->sid[0]) {
@@ -1849,18 +1960,27 @@ int security_fs_use(
                                goto out;
                }
                *sid = c->sid[0];
+               goto out;
+       }
+
+       /* labeling behavior not in policy, use xattrs if possible */
+       if (can_xattr) {
+               *behavior = SECURITY_FS_USE_XATTR;
+               *sid = SECINITSID_FS;
+               goto out;
+       }
+
+       /* no behavior in policy and can't use xattrs, try GENFS */
+       rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid);
+       if (rc) {
+               *behavior = SECURITY_FS_USE_NONE;
+               rc = 0;
        } else {
-               rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid);
-               if (rc) {
-                       *behavior = SECURITY_FS_USE_NONE;
-                       rc = 0;
-               } else {
-                       *behavior = SECURITY_FS_USE_GENFS;
-               }
+               *behavior = SECURITY_FS_USE_GENFS;
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -1868,7 +1988,7 @@ int security_get_bools(int *len, char ***names, int **values)
 {
        int i, rc = -ENOMEM;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
        *names = NULL;
        *values = NULL;
 
@@ -1898,7 +2018,7 @@ int security_get_bools(int *len, char ***names, int **values)
        }
        rc = 0;
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 err:
        if (*names) {
@@ -1916,7 +2036,7 @@ int security_set_bools(int len, int *values)
        int lenp, seqno = 0;
        struct cond_node *cur;
 
-       POLICY_WRLOCK;
+       write_lock_irq(&policy_rwlock);
 
        lenp = policydb.p_bools.nprim;
        if (len != lenp) {
@@ -1950,7 +2070,7 @@ int security_set_bools(int len, int *values)
        seqno = ++latest_granting;
 
 out:
-       POLICY_WRUNLOCK;
+       write_unlock_irq(&policy_rwlock);
        if (!rc) {
                avc_ss_reset(seqno);
                selnl_notify_policyload(seqno);
@@ -1964,7 +2084,7 @@ int security_get_bool_value(int bool)
        int rc = 0;
        int len;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        len = policydb.p_bools.nprim;
        if (bool >= len) {
@@ -1974,7 +2094,7 @@ int security_get_bool_value(int bool)
 
        rc = policydb.bool_val_to_struct[bool]->state;
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -2029,7 +2149,7 @@ int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid)
 
        context_init(&newcon);
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
        context1 = sidtab_search(&sidtab, sid);
        if (!context1) {
                printk(KERN_ERR "SELinux: %s:  unrecognized SID %d\n",
@@ -2071,7 +2191,7 @@ bad:
        }
 
 out_unlock:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        context_destroy(&newcon);
 out:
        return rc;
@@ -2128,7 +2248,7 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
                return 0;
        }
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        nlbl_ctx = sidtab_search(&sidtab, nlbl_sid);
        if (!nlbl_ctx) {
@@ -2147,7 +2267,7 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
        rc = (mls_context_cmp(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
 
 out_slowpath:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        if (rc == 0)
                /* at present NetLabel SIDs/labels really only carry MLS
                 * information so if the MLS portion of the NetLabel SID
@@ -2177,7 +2297,7 @@ int security_get_classes(char ***classes, int *nclasses)
 {
        int rc = -ENOMEM;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        *nclasses = policydb.p_classes.nprim;
        *classes = kcalloc(*nclasses, sizeof(*classes), GFP_ATOMIC);
@@ -2194,7 +2314,7 @@ int security_get_classes(char ***classes, int *nclasses)
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 
@@ -2216,7 +2336,7 @@ int security_get_permissions(char *class, char ***perms, int *nperms)
        int rc = -ENOMEM, i;
        struct class_datum *match;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        match = hashtab_search(policydb.p_classes.table, class);
        if (!match) {
@@ -2244,11 +2364,11 @@ int security_get_permissions(char *class, char ***perms, int *nperms)
                goto err;
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 
 err:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        for (i = 0; i < *nperms; i++)
                kfree((*perms)[i]);
        kfree(*perms);
@@ -2279,9 +2399,9 @@ int security_policycap_supported(unsigned int req_cap)
 {
        int rc;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
        rc = ebitmap_get_bit(&policydb.policycaps, req_cap);
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
 
        return rc;
 }
@@ -2345,7 +2465,7 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
 
        context_init(&tmprule->au_ctxt);
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        tmprule->au_seqno = latest_granting;
 
@@ -2382,7 +2502,7 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
                break;
        }
 
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
 
        if (rc) {
                selinux_audit_rule_free(tmprule);
@@ -2420,7 +2540,7 @@ int selinux_audit_rule_known(struct audit_krule *rule)
 }
 
 int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
-                             struct audit_context *actx)
+                            struct audit_context *actx)
 {
        struct context *ctxt;
        struct mls_level *level;
@@ -2433,7 +2553,7 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
                return -ENOENT;
        }
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        if (rule->au_seqno < latest_granting) {
                audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
@@ -2527,14 +2647,14 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
        }
 
 out:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return match;
 }
 
 static int (*aurule_callback)(void) = audit_update_lsm_rules;
 
 static int aurule_avc_callback(u32 event, u32 ssid, u32 tsid,
-                               u16 class, u32 perms, u32 *retained)
+                              u16 class, u32 perms, u32 *retained)
 {
        int err = 0;
 
@@ -2615,7 +2735,7 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
                return 0;
        }
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
 
        if (secattr->flags & NETLBL_SECATTR_CACHE) {
                *sid = *(u32 *)secattr->cache->data;
@@ -2660,7 +2780,7 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
        }
 
 netlbl_secattr_to_sid_return:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 netlbl_secattr_to_sid_return_cleanup:
        ebitmap_destroy(&ctx_new.range.level[0].cat);
@@ -2685,7 +2805,7 @@ int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr)
        if (!ss_initialized)
                return 0;
 
-       POLICY_RDLOCK;
+       read_lock(&policy_rwlock);
        ctx = sidtab_search(&sidtab, sid);
        if (ctx == NULL)
                goto netlbl_sid_to_secattr_failure;
@@ -2696,12 +2816,12 @@ int security_netlbl_sid_to_secattr(u32 sid, struct netlbl_lsm_secattr *secattr)
        rc = mls_export_netlbl_cat(ctx, secattr);
        if (rc != 0)
                goto netlbl_sid_to_secattr_failure;
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
 
        return 0;
 
 netlbl_sid_to_secattr_failure:
-       POLICY_RDUNLOCK;
+       read_unlock(&policy_rwlock);
        return rc;
 }
 #endif /* CONFIG_NETLABEL */
index 4a516ff..a81ded1 100644 (file)
 #define SIDTAB_HASH(sid) \
 (sid & SIDTAB_HASH_MASK)
 
-#define INIT_SIDTAB_LOCK(s) spin_lock_init(&s->lock)
-#define SIDTAB_LOCK(s, x) spin_lock_irqsave(&s->lock, x)
-#define SIDTAB_UNLOCK(s, x) spin_unlock_irqrestore(&s->lock, x)
-
 int sidtab_init(struct sidtab *s)
 {
        int i;
@@ -30,7 +26,7 @@ int sidtab_init(struct sidtab *s)
        s->nel = 0;
        s->next_sid = 1;
        s->shutdown = 0;
-       INIT_SIDTAB_LOCK(s);
+       spin_lock_init(&s->lock);
        return 0;
 }
 
@@ -86,7 +82,7 @@ out:
        return rc;
 }
 
-struct context *sidtab_search(struct sidtab *s, u32 sid)
+static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)
 {
        int hvalue;
        struct sidtab_node *cur;
@@ -99,7 +95,10 @@ struct context *sidtab_search(struct sidtab *s, u32 sid)
        while (cur != NULL && sid > cur->sid)
                cur = cur->next;
 
-       if (cur == NULL || sid != cur->sid) {
+       if (force && cur && sid == cur->sid && cur->context.len)
+               return &cur->context;
+
+       if (cur == NULL || sid != cur->sid || cur->context.len) {
                /* Remap invalid SIDs to the unlabeled SID. */
                sid = SECINITSID_UNLABELED;
                hvalue = SIDTAB_HASH(sid);
@@ -113,6 +112,16 @@ struct context *sidtab_search(struct sidtab *s, u32 sid)
        return &cur->context;
 }
 
+struct context *sidtab_search(struct sidtab *s, u32 sid)
+{
+       return sidtab_search_core(s, sid, 0);
+}
+
+struct context *sidtab_search_force(struct sidtab *s, u32 sid)
+{
+       return sidtab_search_core(s, sid, 1);
+}
+
 int sidtab_map(struct sidtab *s,
               int (*apply) (u32 sid,
                             struct context *context,
@@ -138,43 +147,6 @@ out:
        return rc;
 }
 
-void sidtab_map_remove_on_error(struct sidtab *s,
-                               int (*apply) (u32 sid,
-                                             struct context *context,
-                                             void *args),
-                               void *args)
-{
-       int i, ret;
-       struct sidtab_node *last, *cur, *temp;
-
-       if (!s)
-               return;
-
-       for (i = 0; i < SIDTAB_SIZE; i++) {
-               last = NULL;
-               cur = s->htable[i];
-               while (cur != NULL) {
-                       ret = apply(cur->sid, &cur->context, args);
-                       if (ret) {
-                               if (last)
-                                       last->next = cur->next;
-                               else
-                                       s->htable[i] = cur->next;
-                               temp = cur;
-                               cur = cur->next;
-                               context_destroy(&temp->context);
-                               kfree(temp);
-                               s->nel--;
-                       } else {
-                               last = cur;
-                               cur = cur->next;
-                       }
-               }
-       }
-
-       return;
-}
-
 static inline u32 sidtab_search_context(struct sidtab *s,
                                                  struct context *context)
 {
@@ -204,7 +176,7 @@ int sidtab_context_to_sid(struct sidtab *s,
 
        sid = sidtab_search_context(s, context);
        if (!sid) {
-               SIDTAB_LOCK(s, flags);
+               spin_lock_irqsave(&s->lock, flags);
                /* Rescan now that we hold the lock. */
                sid = sidtab_search_context(s, context);
                if (sid)
@@ -215,11 +187,15 @@ int sidtab_context_to_sid(struct sidtab *s,
                        goto unlock_out;
                }
                sid = s->next_sid++;
+               if (context->len)
+                       printk(KERN_INFO
+                      "SELinux:  Context %s is not valid (left unmapped).\n",
+                              context->str);
                ret = sidtab_insert(s, sid, context);
                if (ret)
                        s->next_sid--;
 unlock_out:
-               SIDTAB_UNLOCK(s, flags);
+               spin_unlock_irqrestore(&s->lock, flags);
        }
 
        if (ret)
@@ -284,19 +260,19 @@ void sidtab_set(struct sidtab *dst, struct sidtab *src)
 {
        unsigned long flags;
 
-       SIDTAB_LOCK(src, flags);
+       spin_lock_irqsave(&src->lock, flags);
        dst->htable = src->htable;
        dst->nel = src->nel;
        dst->next_sid = src->next_sid;
        dst->shutdown = 0;
-       SIDTAB_UNLOCK(src, flags);
+       spin_unlock_irqrestore(&src->lock, flags);
 }
 
 void sidtab_shutdown(struct sidtab *s)
 {
        unsigned long flags;
 
-       SIDTAB_LOCK(s, flags);
+       spin_lock_irqsave(&s->lock, flags);
        s->shutdown = 1;
-       SIDTAB_UNLOCK(s, flags);
+       spin_unlock_irqrestore(&s->lock, flags);
 }
index 2fe9dfa..64ea5b1 100644 (file)
@@ -32,6 +32,7 @@ struct sidtab {
 int sidtab_init(struct sidtab *s);
 int sidtab_insert(struct sidtab *s, u32 sid, struct context *context);
 struct context *sidtab_search(struct sidtab *s, u32 sid);
+struct context *sidtab_search_force(struct sidtab *s, u32 sid);
 
 int sidtab_map(struct sidtab *s,
               int (*apply) (u32 sid,
@@ -39,12 +40,6 @@ int sidtab_map(struct sidtab *s,
                             void *args),
               void *args);
 
-void sidtab_map_remove_on_error(struct sidtab *s,
-                               int (*apply) (u32 sid,
-                                             struct context *context,
-                                             void *args),
-                               void *args);
-
 int sidtab_context_to_sid(struct sidtab *s,
                          struct context *context,
                          u32 *sid);
index 4a09293..ee5a51c 100644 (file)
@@ -95,11 +95,12 @@ struct inode_smack *new_inode_smack(char *smack)
  *
  * Do the capability checks, and require read and write.
  */
-static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp)
+static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp,
+                       unsigned int mode)
 {
        int rc;
 
-       rc = cap_ptrace(ptp, ctp);
+       rc = cap_ptrace(ptp, ctp, mode);
        if (rc != 0)
                return rc;
 
@@ -1821,27 +1822,6 @@ static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
        *secid = smack_to_secid(smack);
 }
 
-/* module stacking operations */
-
-/**
- * smack_register_security - stack capability module
- * @name: module name
- * @ops: module operations - ignored
- *
- * Allow the capability module to register.
- */
-static int smack_register_security(const char *name,
-                                  struct security_operations *ops)
-{
-       if (strcmp(name, "capability") != 0)
-               return -EINVAL;
-
-       printk(KERN_INFO "%s:  Registering secondary module %s\n",
-              __func__, name);
-
-       return 0;
-}
-
 /**
  * smack_d_instantiate - Make sure the blob is correct on an inode
  * @opt_dentry: unused
@@ -2672,8 +2652,6 @@ struct security_operations smack_ops = {
        .netlink_send =                 cap_netlink_send,
        .netlink_recv =                 cap_netlink_recv,
 
-       .register_security =            smack_register_security,
-
        .d_instantiate =                smack_d_instantiate,
 
        .getprocattr =                  smack_getprocattr,
index 4247406..a37bee0 100644 (file)
@@ -1,11 +1,9 @@
 # sound/Config.in
 #
 
-menu "Sound"
-       depends on HAS_IOMEM
-
-config SOUND
+menuconfig SOUND
        tristate "Sound card support"
+       depends on HAS_IOMEM
        help
          If you have a sound card in your computer, i.e. if it can say more
          than an occasional beep, say Y.  Be sure to have all the information
@@ -28,22 +26,22 @@ config SOUND
          and read <file:Documentation/sound/oss/README.modules>; the module
          will be called soundcore.
 
+if SOUND
+
 source "sound/oss/dmasound/Kconfig"
 
 if !M68K
 
-menu "Advanced Linux Sound Architecture"
-       depends on SOUND!=n
-
-config SND
+menuconfig SND
        tristate "Advanced Linux Sound Architecture"
-       depends on SOUND
        help
          Say 'Y' or 'M' to enable ALSA (Advanced Linux Sound Architecture),
          the new base sound system.
 
          For more information, see <http://www.alsa-project.org/>
 
+if SND
+
 source "sound/core/Kconfig"
 
 source "sound/drivers/Kconfig"
@@ -58,9 +56,7 @@ source "sound/aoa/Kconfig"
 
 source "sound/arm/Kconfig"
 
-if SPI
 source "sound/spi/Kconfig"
-endif
 
 source "sound/mips/Kconfig"
 
@@ -80,22 +76,20 @@ source "sound/parisc/Kconfig"
 
 source "sound/soc/Kconfig"
 
-endmenu
+endif # SND
 
-menu "Open Sound System"
-       depends on SOUND!=n
-
-config SOUND_PRIME
+menuconfig SOUND_PRIME
        tristate "Open Sound System (DEPRECATED)"
-       depends on SOUND
        help
          Say 'Y' or 'M' to enable Open Sound System drivers.
 
+if SOUND_PRIME
+
 source "sound/oss/Kconfig"
 
-endmenu
+endif # SOUND_PRIME
 
-endif
+endif # !M68K
 
 config AC97_BUS
        tristate
@@ -105,4 +99,4 @@ config AC97_BUS
          sound although they're sharing the AC97 bus. Concerned drivers
          should "select" this.
 
-endmenu
+endif # SOUND
index 5d5813c..c081e18 100644 (file)
@@ -1,18 +1,17 @@
-menu "Apple Onboard Audio driver"
-       depends on SND!=n && PPC_PMAC
-
-config SND_AOA
+menuconfig SND_AOA
        tristate "Apple Onboard Audio driver"
-       depends on SND
+       depends on PPC_PMAC
        select SND_PCM
        ---help---
        This option enables the new driver for the various
        Apple Onboard Audio components.
 
+if SND_AOA
+
 source "sound/aoa/fabrics/Kconfig"
 
 source "sound/aoa/codecs/Kconfig"
 
 source "sound/aoa/soundbus/Kconfig"
 
-endmenu
+endif  # SND_AOA
index d5fbd60..808eb11 100644 (file)
@@ -1,6 +1,5 @@
 config SND_AOA_ONYX
        tristate "support Onyx chip"
-       depends on SND_AOA
        select I2C
        select I2C_POWERMAC
        ---help---
@@ -10,7 +9,6 @@ config SND_AOA_ONYX
 
 #config SND_AOA_TOPAZ
 #      tristate "support Topaz chips"
-#      depends on SND_AOA
 #      ---help---
 #      This option enables support for the Topaz (CS84xx)
 #      codec chips found in the latest Apple machines,
@@ -19,7 +17,6 @@ config SND_AOA_ONYX
 
 config SND_AOA_TAS
        tristate "support TAS chips"
-       depends on SND_AOA
        select I2C
        select I2C_POWERMAC
        ---help---
@@ -29,7 +26,6 @@ config SND_AOA_TAS
 
 config SND_AOA_TOONIE
        tristate "support Toonie chip"
-       depends on SND_AOA
        ---help---
        This option enables support for the toonie codec
        found in the Mac Mini. If you have a Mac Mini and
index 50d7021..3ca475a 100644 (file)
@@ -1,6 +1,5 @@
 config SND_AOA_FABRIC_LAYOUT
        tristate "layout-id fabric"
-       depends on SND_AOA
        select SND_AOA_SOUNDBUS
        select SND_AOA_SOUNDBUS_I2S
        ---help---
index 7368b7d..839d113 100644 (file)
@@ -1,6 +1,5 @@
 config SND_AOA_SOUNDBUS
        tristate "Apple Soundbus support"
-       depends on SOUND
        select SND_PCM
        ---help---
        This option enables the generic driver for the soundbus
index 2e4a5e0..351e19e 100644 (file)
@@ -1,11 +1,19 @@
 # ALSA ARM drivers
 
-menu "ALSA ARM devices"
-       depends on SND!=n && ARM
+menuconfig SND_ARM
+       bool "ARM sound devices"
+       depends on ARM
+       default y
+       help
+         Support for sound devices specific to ARM architectures.
+         Drivers that are implemented on ASoC can be found in
+         "ALSA for SoC audio support" section.
+
+if SND_ARM
 
 config SND_SA11XX_UDA1341
        tristate "SA11xx UDA1341TS driver (iPaq H3600)"
-       depends on ARCH_SA1100 && SND && L3
+       depends on ARCH_SA1100 && L3
        select SND_PCM
        help
          Say Y here if you have a Compaq iPaq H3x00 handheld computer
@@ -16,7 +24,7 @@ config SND_SA11XX_UDA1341
 
 config SND_ARMAACI
        tristate "ARM PrimeCell PL041 AC Link support"
-       depends on SND && ARM_AMBA
+       depends on ARM_AMBA
        select SND_PCM
        select SND_AC97_CODEC
 
@@ -26,11 +34,12 @@ config SND_PXA2XX_PCM
 
 config SND_PXA2XX_AC97
        tristate "AC97 driver for the Intel PXA2xx chip"
-       depends on ARCH_PXA && SND
+       depends on ARCH_PXA
        select SND_PXA2XX_PCM
        select SND_AC97_CODEC
        help
          Say Y or M if you want to support any AC97 codec attached to
          the PXA2xx AC97 interface.
 
-endmenu
+endif  # SND_ARM
+
index 0eff33c..faeddf3 100644 (file)
@@ -21,8 +21,6 @@
  *                              merged HAL layer (patches from Brian)
  */
 
-/* $Id: sa11xx-uda1341.c,v 1.27 2005/12/07 09:13:42 cladisch Exp $ */
-
 /***************************************************************************************************
 *
 * To understand what Alsa Drivers should be doing look at "Writing an Alsa Driver" by Takashi Iwai
index a8d71c6..335d45e 100644 (file)
@@ -1,24 +1,19 @@
 # ALSA soundcard-configuration
 config SND_TIMER
        tristate
-       depends on SND
 
 config SND_PCM
        tristate
        select SND_TIMER
-       depends on SND
 
 config SND_HWDEP
        tristate
-       depends on SND
 
 config SND_RAWMIDI
        tristate
-       depends on SND
 
 config SND_SEQUENCER
        tristate "Sequencer support"
-       depends on SND
        select SND_TIMER
        help
          Say Y or M to enable MIDI sequencer and router support.  This
@@ -44,11 +39,9 @@ config SND_SEQ_DUMMY
 
 config SND_OSSEMUL
        bool
-       depends on SND
 
 config SND_MIXER_OSS
        tristate "OSS Mixer API"
-       depends on SND
        select SND_OSSEMUL
        help
          To enable OSS mixer API emulation (/dev/mixer*), say Y here
@@ -61,7 +54,6 @@ config SND_MIXER_OSS
 
 config SND_PCM_OSS
        tristate "OSS PCM (digital audio) API"
-       depends on SND
        select SND_OSSEMUL
        select SND_PCM
        help
@@ -84,7 +76,7 @@ config SND_PCM_OSS_PLUGINS
 
 config SND_SEQUENCER_OSS
        bool "OSS Sequencer API"
-       depends on SND && SND_SEQUENCER
+       depends on SND_SEQUENCER
        select SND_OSSEMUL
        help
          Say Y here to enable OSS sequencer emulation (both
@@ -98,7 +90,7 @@ config SND_SEQUENCER_OSS
 
 config SND_RTCTIMER
        tristate "RTC Timer support"
-       depends on SND && RTC
+       depends on RTC
        select SND_TIMER
        help
          Say Y here to enable RTC timer support for ALSA.  ALSA uses
@@ -123,7 +115,6 @@ config SND_SEQ_RTCTIMER_DEFAULT
 
 config SND_DYNAMIC_MINORS
        bool "Dynamic device file minor numbers"
-       depends on SND
        help
          If you say Y here, the minor numbers of ALSA device files in
          /dev/snd/ are allocated dynamically.  This allows you to have
@@ -134,7 +125,6 @@ config SND_DYNAMIC_MINORS
 
 config SND_SUPPORT_OLD_API
        bool "Support old ALSA API"
-       depends on SND
        default y
        help
          Say Y here to support the obsolete ALSA PCM API (ver.0.9.0 rc3
@@ -142,7 +132,7 @@ config SND_SUPPORT_OLD_API
 
 config SND_VERBOSE_PROCFS
        bool "Verbose procfs contents"
-       depends on SND && PROC_FS
+       depends on PROC_FS
        default y
        help
          Say Y here to include code for verbose procfs contents (provides
@@ -151,7 +141,6 @@ config SND_VERBOSE_PROCFS
 
 config SND_VERBOSE_PRINTK
        bool "Verbose printk"
-       depends on SND
        help
          Say Y here to enable verbose log messages.  These messages
          will help to identify source file and position containing
@@ -161,16 +150,17 @@ config SND_VERBOSE_PRINTK
 
 config SND_DEBUG
        bool "Debug"
-       depends on SND
        help
          Say Y here to enable ALSA debug code.
 
-config SND_DEBUG_DETECT
-       bool "Debug detection"
+config SND_DEBUG_VERBOSE
+       bool "More verbose debug"
        depends on SND_DEBUG
        help
-         Say Y here to enable extra-verbose log messages printed when
-         detecting devices.
+         Say Y here to enable extra-verbose debugging messages.
+         
+         Let me repeat: it enables EXTRA-VERBOSE DEBUGGING messages.
+         So, say Y only if you are ready to be annoyed.
 
 config SND_PCM_XRUN_DEBUG
        bool "Enable PCM ring buffer overrun/underrun debugging"
@@ -184,4 +174,3 @@ config SND_PCM_XRUN_DEBUG
 
 config SND_VMASTER
        bool
-       depends on SND
index 01a1a5a..281b2e2 100644 (file)
@@ -684,7 +684,8 @@ static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl,
        return result;
 }
 
-int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *control)
+static int snd_ctl_elem_read(struct snd_card *card,
+                            struct snd_ctl_elem_value *control)
 {
        struct snd_kcontrol *kctl;
        struct snd_kcontrol_volatile *vd;
@@ -734,8 +735,8 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
        return result;
 }
 
-int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
-                      struct snd_ctl_elem_value *control)
+static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
+                             struct snd_ctl_elem_value *control)
 {
        struct snd_kcontrol *kctl;
        struct snd_kcontrol_volatile *vd;
index ac05734..5c254d4 100644 (file)
@@ -46,17 +46,24 @@ static char *slots[SNDRV_CARDS];
 module_param_array(slots, charp, NULL, 0444);
 MODULE_PARM_DESC(slots, "Module names assigned to the slots.");
 
-/* return non-zero if the given index is already reserved for another
+/* return non-zero if the given index is reserved for the given
  * module via slots option
  */
-static int module_slot_mismatch(struct module *module, int idx)
+static int module_slot_match(struct module *module, int idx)
 {
+       int match = 1;
 #ifdef MODULE
-       char *s1, *s2;
+       const char *s1, *s2;
+
        if (!module || !module->name || !slots[idx])
                return 0;
-       s1 = slots[idx];
-       s2 = module->name;
+
+       s1 = module->name;
+       s2 = slots[idx];
+       if (*s2 == '!') {
+               match = 0; /* negative match */
+               s2++;
+       }
        /* compare module name strings
         * hyphens are handled as equivalent with underscore
         */
@@ -68,12 +75,12 @@ static int module_slot_mismatch(struct module *module, int idx)
                if (c2 == '-')
                        c2 = '_';
                if (c1 != c2)
-                       return 1;
+                       return !match;
                if (!c1)
                        break;
        }
-#endif
-       return 0;
+#endif /* MODULE */
+       return match;
 }
 
 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
@@ -129,7 +136,7 @@ struct snd_card *snd_card_new(int idx, const char *xid,
                         struct module *module, int extra_size)
 {
        struct snd_card *card;
-       int err;
+       int err, idx2;
 
        if (extra_size < 0)
                extra_size = 0;
@@ -144,35 +151,41 @@ struct snd_card *snd_card_new(int idx, const char *xid,
        err = 0;
        mutex_lock(&snd_card_mutex);
        if (idx < 0) {
-               int idx2;
                for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
                        /* idx == -1 == 0xffff means: take any free slot */
                        if (~snd_cards_lock & idx & 1<<idx2) {
-                               if (module_slot_mismatch(module, idx2))
-                                       continue;
-                               idx = idx2;
-                               if (idx >= snd_ecards_limit)
-                                       snd_ecards_limit = idx + 1;
-                               break;
+                               if (module_slot_match(module, idx2)) {
+                                       idx = idx2;
+                                       break;
+                               }
+                       }
+       }
+       if (idx < 0) {
+               for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
+                       /* idx == -1 == 0xffff means: take any free slot */
+                       if (~snd_cards_lock & idx & 1<<idx2) {
+                               if (!slots[idx2] || !*slots[idx2]) {
+                                       idx = idx2;
+                                       break;
+                               }
                        }
-       } else {
-                if (idx < snd_ecards_limit) {
-                       if (snd_cards_lock & (1 << idx))
-                               err = -EBUSY;   /* invalid */
-               } else {
-                       if (idx < SNDRV_CARDS)
-                               snd_ecards_limit = idx + 1; /* increase the limit */
-                       else
-                               err = -ENODEV;
-               }
        }
-       if (idx < 0 || err < 0) {
+       if (idx < 0)
+               err = -ENODEV;
+       else if (idx < snd_ecards_limit) {
+               if (snd_cards_lock & (1 << idx))
+                       err = -EBUSY;   /* invalid */
+       } else if (idx >= SNDRV_CARDS)
+               err = -ENODEV;
+       if (err < 0) {
                mutex_unlock(&snd_card_mutex);
                snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i), error: %d\n",
                         idx, snd_ecards_limit - 1, err);
                goto __error;
        }
        snd_cards_lock |= 1 << idx;             /* lock it */
+       if (idx >= snd_ecards_limit)
+               snd_ecards_limit = idx + 1; /* increase the limit */
        mutex_unlock(&snd_card_mutex);
        card->number = idx;
        card->module = module;
index 23b7bc0..f5d6d8d 100644 (file)
@@ -79,68 +79,6 @@ struct snd_mem_list {
 #define snd_assert(expr, args...) /**/
 #endif
 
-/*
- *  Hacks
- */
-
-#if defined(__i386__)
-/*
- * A hack to allocate large buffers via dma_alloc_coherent()
- *
- * since dma_alloc_coherent always tries GFP_DMA when the requested
- * pci memory region is below 32bit, it happens quite often that even
- * 2 order of pages cannot be allocated.
- *
- * so in the following, we allocate at first without dma_mask, so that
- * allocation will be done without GFP_DMA.  if the area doesn't match
- * with the requested region, then realloate with the original dma_mask
- * again.
- *
- * Really, we want to move this type of thing into dma_alloc_coherent()
- * so dma_mask doesn't have to be messed with.
- */
-
-static void *snd_dma_hack_alloc_coherent(struct device *dev, size_t size,
-                                        dma_addr_t *dma_handle,
-                                        gfp_t flags)
-{
-       void *ret;
-       u64 dma_mask, coherent_dma_mask;
-
-       if (dev == NULL || !dev->dma_mask)
-               return dma_alloc_coherent(dev, size, dma_handle, flags);
-       dma_mask = *dev->dma_mask;
-       coherent_dma_mask = dev->coherent_dma_mask;
-       *dev->dma_mask = 0xffffffff;    /* do without masking */
-       dev->coherent_dma_mask = 0xffffffff;    /* do without masking */
-       ret = dma_alloc_coherent(dev, size, dma_handle, flags);
-       *dev->dma_mask = dma_mask;      /* restore */
-       dev->coherent_dma_mask = coherent_dma_mask;     /* restore */
-       if (ret) {
-               /* obtained address is out of range? */
-               if (((unsigned long)*dma_handle + size - 1) & ~dma_mask) {
-                       /* reallocate with the proper mask */
-                       dma_free_coherent(dev, size, ret, *dma_handle);
-                       ret = dma_alloc_coherent(dev, size, dma_handle, flags);
-               }
-       } else {
-               /* wish to success now with the proper mask... */
-               if (dma_mask != 0xffffffffUL) {
-                       /* allocation with GFP_ATOMIC to avoid the long stall */
-                       flags &= ~GFP_KERNEL;
-                       flags |= GFP_ATOMIC;
-                       ret = dma_alloc_coherent(dev, size, dma_handle, flags);
-               }
-       }
-       return ret;
-}
-
-/* redefine dma_alloc_coherent for some architectures */
-#undef dma_alloc_coherent
-#define dma_alloc_coherent snd_dma_hack_alloc_coherent
-
-#endif /* arch */
-
 /*
  *
  *  Generic memory allocators
index 61f5d42..c49b9d9 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/file.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/time.h>
 #include <linux/pm_qos_params.h>
 #include <linux/uio.h>
@@ -3249,14 +3250,17 @@ static int snd_pcm_fasync(int fd, struct file * file, int on)
        struct snd_pcm_file * pcm_file;
        struct snd_pcm_substream *substream;
        struct snd_pcm_runtime *runtime;
-       int err;
+       int err = -ENXIO;
 
+       lock_kernel();
        pcm_file = file->private_data;
        substream = pcm_file->substream;
-       snd_assert(substream != NULL, return -ENXIO);
+       snd_assert(substream != NULL, goto out);
        runtime = substream->runtime;
 
        err = fasync_helper(fd, file, on, &runtime->fasync);
+out:
+       unlock_kernel();
        if (err < 0)
                return err;
        return 0;
index 47cfa51..7a1545d 100644 (file)
@@ -148,7 +148,7 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
                return NULL;
        }
        spin_unlock_irqrestore(&clients_lock, flags);
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
        if (!in_interrupt()) {
                static char client_requested[SNDRV_SEQ_GLOBAL_CLIENTS];
                static char card_requested[SNDRV_CARDS];
index 2f00ad2..05410e5 100644 (file)
@@ -124,7 +124,7 @@ static void snd_seq_device_info(struct snd_info_entry *entry,
  * load all registered drivers (called from seq_clientmgr.c)
  */
 
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
 /* avoid auto-loading during module_init() */
 static int snd_seq_in_init;
 void snd_seq_autoload_lock(void)
@@ -140,7 +140,7 @@ void snd_seq_autoload_unlock(void)
 
 void snd_seq_device_load_drivers(void)
 {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
        struct ops_list *ops;
 
        /* Calling request_module during module_init()
@@ -566,7 +566,5 @@ EXPORT_SYMBOL(snd_seq_device_load_drivers);
 EXPORT_SYMBOL(snd_seq_device_new);
 EXPORT_SYMBOL(snd_seq_device_register_driver);
 EXPORT_SYMBOL(snd_seq_device_unregister_driver);
-#ifdef CONFIG_KMOD
 EXPORT_SYMBOL(snd_seq_autoload_lock);
 EXPORT_SYMBOL(snd_seq_autoload_unlock);
-#endif
index 6c8ab48..1003ae3 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/time.h>
 #include <linux/device.h>
 #include <linux/moduleparam.h>
@@ -60,14 +61,14 @@ EXPORT_SYMBOL(snd_ecards_limit);
 static struct snd_minor *snd_minors[SNDRV_OS_MINORS];
 static DEFINE_MUTEX(sound_mutex);
 
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
 
 /**
  * snd_request_card - try to load the card module
  * @card: the card number
  *
  * Tries to load the module "snd-card-X" for the given card number
- * via KMOD.  Returns immediately if already loaded.
+ * via request_module.  Returns immediately if already loaded.
  */
 void snd_request_card(int card)
 {
@@ -92,7 +93,7 @@ static void snd_request_other(int minor)
        request_module(str);
 }
 
-#endif                         /* request_module support */
+#endif /* modular kernel */
 
 /**
  * snd_lookup_minor_data - get user data of a registered device
@@ -121,7 +122,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
 
 EXPORT_SYMBOL(snd_lookup_minor_data);
 
-static int snd_open(struct inode *inode, struct file *file)
+static int __snd_open(struct inode *inode, struct file *file)
 {
        unsigned int minor = iminor(inode);
        struct snd_minor *mptr = NULL;
@@ -132,7 +133,7 @@ static int snd_open(struct inode *inode, struct file *file)
                return -ENODEV;
        mptr = snd_minors[minor];
        if (mptr == NULL) {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
                int dev = SNDRV_MINOR_DEVICE(minor);
                if (dev == SNDRV_MINOR_CONTROL) {
                        /* /dev/aloadC? */
@@ -163,6 +164,18 @@ static int snd_open(struct inode *inode, struct file *file)
        return err;
 }
 
+
+/* BKL pushdown: nasty #ifdef avoidance wrapper */
+static int snd_open(struct inode *inode, struct file *file)
+{
+       int ret;
+
+       lock_kernel();
+       ret = __snd_open(inode, file);
+       unlock_kernel();
+       return ret;
+}
+
 static const struct file_operations snd_fops =
 {
        .owner =        THIS_MODULE,
index 9d8184a..0af337e 100644 (file)
@@ -146,7 +146,7 @@ static struct snd_timer *snd_timer_find(struct snd_timer_id *tid)
        return NULL;
 }
 
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
 
 static void snd_timer_request(struct snd_timer_id *tid)
 {
@@ -259,8 +259,8 @@ int snd_timer_open(struct snd_timer_instance **ti,
        /* open a master instance */
        mutex_lock(&register_mutex);
        timer = snd_timer_find(tid);
-#ifdef CONFIG_KMOD
-       if (timer == NULL) {
+#ifdef CONFIG_MODULES
+       if (!timer) {
                mutex_unlock(&register_mutex);
                snd_timer_request(tid);
                mutex_lock(&register_mutex);
index 602b58e..255fd18 100644 (file)
@@ -1,15 +1,41 @@
-# ALSA generic drivers
+config SND_MPU401_UART
+        tristate
+        select SND_RAWMIDI
 
-menu "Generic devices"
-       depends on SND!=n
+config SND_OPL3_LIB
+       tristate
+       select SND_TIMER
+       select SND_HWDEP
 
+config SND_OPL4_LIB
+       tristate
+       select SND_TIMER
+       select SND_HWDEP
+
+config SND_VX_LIB
+       tristate
+       select SND_HWDEP
+       select SND_PCM
+
+config SND_AC97_CODEC
+       tristate
+       select SND_PCM
+       select AC97_BUS
+       select SND_VMASTER
+
+menuconfig SND_DRIVERS
+       bool "Generic sound devices"
+       default y
+       help
+         Support for generic sound devices.
+  
+if SND_DRIVERS
 
 config SND_PCSP
        tristate "PC-Speaker support (READ HELP!)"
        depends on PCSPKR_PLATFORM && X86_PC && HIGH_RES_TIMERS
        depends on INPUT
        depends on EXPERIMENTAL
-       depends on SND
        select SND_PCM
        help
          If you don't have a sound card in your computer, you can include a
@@ -35,33 +61,8 @@ config SND_PCSP
          Say M if you don't.
          Say Y only if you really know what you do.
 
-config SND_MPU401_UART
-        tristate
-        select SND_RAWMIDI
-
-config SND_OPL3_LIB
-       tristate
-       select SND_TIMER
-       select SND_HWDEP
-
-config SND_OPL4_LIB
-       tristate
-       select SND_TIMER
-       select SND_HWDEP
-
-config SND_VX_LIB
-       tristate
-       select SND_HWDEP
-       select SND_PCM
-
-config SND_AC97_CODEC
-       tristate
-       select SND_PCM
-       select AC97_BUS
-
 config SND_DUMMY
        tristate "Dummy (/dev/null) soundcard"
-       depends on SND
        select SND_PCM
        help
          Say Y here to include the dummy driver.  This driver does
@@ -90,7 +91,6 @@ config SND_VIRMIDI
 
 config SND_MTPAV
        tristate "MOTU MidiTimePiece AV multiport MIDI"
-       depends on SND
        select SND_RAWMIDI
        help
          To use a MOTU MidiTimePiece AV multiport MIDI adapter
@@ -102,7 +102,7 @@ config SND_MTPAV
 
 config SND_MTS64
        tristate "ESI Miditerminal 4140 driver"
-       depends on SND && PARPORT
+       depends on PARPORT
        select SND_RAWMIDI
        help
          The ESI Miditerminal 4140 is a 4 In 4 Out MIDI Interface with 
@@ -115,7 +115,6 @@ config SND_MTS64
 
 config SND_SERIAL_U16550
        tristate "UART16550 serial MIDI driver"
-       depends on SND
        select SND_RAWMIDI
        help
          To include support for MIDI serial port interfaces, say Y here
@@ -131,7 +130,6 @@ config SND_SERIAL_U16550
 
 config SND_MPU401
        tristate "Generic MPU-401 UART driver"
-       depends on SND
        select SND_MPU401_UART
        help
          Say Y here to include support for MIDI ports compatible with
@@ -142,7 +140,7 @@ config SND_MPU401
 
 config SND_PORTMAN2X4
        tristate "Portman 2x4 driver"
-       depends on SND && PARPORT
+       depends on PARPORT
        select SND_RAWMIDI
        help
          Say Y here to include support for Midiman Portman 2x4 parallel
@@ -153,7 +151,7 @@ config SND_PORTMAN2X4
 
 config SND_ML403_AC97CR
        tristate "Xilinx ML403 AC97 Controller Reference"
-       depends on SND && XILINX_VIRTEX
+       depends on XILINX_VIRTEX
        select SND_AC97_CODEC
        help
          Say Y here to include support for the
@@ -163,4 +161,25 @@ config SND_ML403_AC97CR
          To compile this driver as a module, choose M here: the module
          will be called snd-ml403_ac97cr.
 
-endmenu
+config SND_AC97_POWER_SAVE
+       bool "AC97 Power-Saving Mode"
+       depends on SND_AC97_CODEC && EXPERIMENTAL
+       default n
+       help
+         Say Y here to enable the aggressive power-saving support of
+         AC97 codecs.  In this mode, the power-mode is dynamically
+         controlled at each open/close.
+
+         The mode is activated by passing power_save=1 option to
+         snd-ac97-codec driver.  You can toggle it dynamically over
+         sysfs, too.
+
+config SND_AC97_POWER_SAVE_DEFAULT
+       int "Default time-out for AC97 power-save mode"
+       depends on SND_AC97_POWER_SAVE
+       default 0
+       help
+         The default time-out value in seconds for AC97 automatic
+         power-save mode.  0 means to disable the power-save mode.
+
+endif  # SND_DRIVERS
index 1dfe694..efd22e9 100644 (file)
@@ -183,7 +183,7 @@ static int vx_hwdep_dsp_load(struct snd_hwdep *hw,
                kfree(fw);
                return -ENOMEM;
        }
-       if (copy_from_user(fw->data, dsp->image, dsp->length)) {
+       if (copy_from_user((void *)fw->data, dsp->image, dsp->length)) {
                free_fw(fw);
                return -EFAULT;
        }
index e57e9cb..9c3d361 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <asm/unaligned.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
@@ -264,10 +265,7 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
                goto __fail;
        }
        /* write default channel status bytes */
-       buf[0] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 0));
-       buf[1] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 8));
-       buf[2] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 16));
-       buf[3] = ((unsigned char)(SNDRV_PCM_DEFAULT_CON_SPDIF >> 24));
+       put_unaligned_le32(SNDRV_PCM_DEFAULT_CON_SPDIF, buf);
        memset(buf + 4, 0, 24 - 4);
        if (snd_cs8427_send_corudata(device, 0, buf, 24) < 0)
                goto __fail;
index bfa5d2c..1f4942e 100644 (file)
@@ -17,8 +17,6 @@
  * 2002-05-12   Tomas Kasparek  another code cleanup
  */
 
-/* $Id: uda1341.c,v 1.18 2005/11/17 14:17:21 tiwai Exp $ */
-
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/types.h>
index 2639a6a..25347a2 100644 (file)
@@ -21,12 +21,17 @@ config SND_SB16_DSP
         select SND_PCM
         select SND_SB_COMMON
 
-menu "ISA devices"
-       depends on SND!=n && ISA && ISA_DMA_API
+menuconfig SND_ISA
+       bool "ISA sound devices"
+       depends on ISA && ISA_DMA_API
+       default y
+       help
+         Support for sound devices connected via the ISA bus.
+
+if SND_ISA
 
 config SND_ADLIB
        tristate "AdLib FM card"
-       depends on SND
        select SND_OPL3_LIB
        help
          Say Y here to include support for AdLib FM cards.
@@ -36,7 +41,7 @@ config SND_ADLIB
 
 config SND_AD1816A
        tristate "Analog Devices SoundPort AD1816A"
-       depends on SND && PNP && ISA
+       depends on PNP
        select ISAPNP
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -50,7 +55,6 @@ config SND_AD1816A
 
 config SND_AD1848
        tristate "Generic AD1848/CS4248 driver"
-       depends on SND
        select SND_AD1848_LIB
        help
          Say Y here to include support for AD1848 (Analog Devices) or
@@ -64,7 +68,7 @@ config SND_AD1848
 
 config SND_ALS100
        tristate "Avance Logic ALS100/ALS120"
-       depends on SND && PNP && ISA
+       depends on PNP
        select ISAPNP
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -78,7 +82,7 @@ config SND_ALS100
 
 config SND_AZT2320
        tristate "Aztech Systems AZT2320"
-       depends on SND && PNP && ISA
+       depends on PNP
        select ISAPNP
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -92,7 +96,6 @@ config SND_AZT2320
 
 config SND_CMI8330
        tristate "C-Media CMI8330"
-       depends on SND
        select SND_AD1848_LIB
        select SND_SB16_DSP
        help
@@ -104,7 +107,6 @@ config SND_CMI8330
 
 config SND_CS4231
        tristate "Generic Cirrus Logic CS4231 driver"
-       depends on SND
        select SND_MPU401_UART
        select SND_CS4231_LIB
        help
@@ -116,7 +118,6 @@ config SND_CS4231
 
 config SND_CS4232
        tristate "Generic Cirrus Logic CS4232 driver"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_CS4231_LIB
@@ -129,7 +130,6 @@ config SND_CS4232
 
 config SND_CS4236
        tristate "Generic Cirrus Logic CS4236+ driver"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_CS4231_LIB
@@ -142,7 +142,7 @@ config SND_CS4236
 
 config SND_DT019X
        tristate "Diamond Technologies DT-019X, Avance Logic ALS-007"
-       depends on SND && PNP && ISA
+       depends on PNP
        select ISAPNP
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -156,7 +156,7 @@ config SND_DT019X
 
 config SND_ES968
        tristate "Generic ESS ES968 driver"
-       depends on SND && PNP && ISA
+       depends on PNP
        select ISAPNP
        select SND_MPU401_UART
        select SND_SB8_DSP
@@ -168,7 +168,6 @@ config SND_ES968
 
 config SND_ES1688
        tristate "Generic ESS ES688/ES1688 driver"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
@@ -181,7 +180,6 @@ config SND_ES1688
 
 config SND_ES18XX
        tristate "Generic ESS ES18xx driver"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
@@ -193,7 +191,7 @@ config SND_ES18XX
 
 config SND_SC6000
        tristate "Gallant SC-6000, Audio Excel DSP 16"
-       depends on SND && HAS_IOPORT
+       depends on HAS_IOPORT
        select SND_AD1848_LIB
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -204,15 +202,10 @@ config SND_SC6000
          To compile this driver as a module, choose M here: the module
          will be called snd-sc6000.
 
-config SND_GUS_SYNTH
-       tristate
-
 config SND_GUSCLASSIC
        tristate "Gravis UltraSound Classic"
-       depends on SND
        select SND_RAWMIDI
        select SND_PCM
-       select SND_GUS_SYNTH
        help
          Say Y here to include support for Gravis UltraSound Classic
          soundcards.
@@ -222,11 +215,9 @@ config SND_GUSCLASSIC
 
 config SND_GUSEXTREME
        tristate "Gravis UltraSound Extreme"
-       depends on SND
        select SND_HWDEP
        select SND_MPU401_UART
        select SND_PCM
-       select SND_GUS_SYNTH
        help
          Say Y here to include support for Gravis UltraSound Extreme
          soundcards.
@@ -236,10 +227,8 @@ config SND_GUSEXTREME
 
 config SND_GUSMAX
        tristate "Gravis UltraSound MAX"
-       depends on SND
        select SND_RAWMIDI
        select SND_CS4231_LIB
-       select SND_GUS_SYNTH
        help
          Say Y here to include support for Gravis UltraSound MAX
          soundcards.
@@ -249,10 +238,9 @@ config SND_GUSMAX
 
 config SND_INTERWAVE
        tristate "AMD InterWave, Gravis UltraSound PnP"
-       depends on SND && PNP && ISA
+       depends on PNP
        select SND_RAWMIDI
        select SND_CS4231_LIB
-       select SND_GUS_SYNTH
        help
          Say Y here to include support for AMD InterWave based
          soundcards (Gravis UltraSound Plug & Play, STB SoundRage32,
@@ -263,10 +251,9 @@ config SND_INTERWAVE
 
 config SND_INTERWAVE_STB
        tristate "AMD InterWave + TEA6330T (UltraSound 32-Pro)"
-       depends on SND && PNP && ISA
+       depends on PNP
        select SND_RAWMIDI
        select SND_CS4231_LIB
-       select SND_GUS_SYNTH
        help
          Say Y here to include support for AMD InterWave based
          soundcards with a TEA6330T bass and treble regulator
@@ -277,7 +264,6 @@ config SND_INTERWAVE_STB
 
 config SND_OPL3SA2
        tristate "Yamaha OPL3-SA2/SA3"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_CS4231_LIB
@@ -290,7 +276,6 @@ config SND_OPL3SA2
 
 config SND_OPTI92X_AD1848
        tristate "OPTi 82C92x - AD1848"
-       depends on SND
        select SND_OPL3_LIB
        select SND_OPL4_LIB
        select SND_MPU401_UART
@@ -304,7 +289,6 @@ config SND_OPTI92X_AD1848
 
 config SND_OPTI92X_CS4231
        tristate "OPTi 82C92x - CS4231"
-       depends on SND
        select SND_OPL3_LIB
        select SND_OPL4_LIB
        select SND_MPU401_UART
@@ -318,10 +302,9 @@ config SND_OPTI92X_CS4231
 
 config SND_OPTI93X
        tristate "OPTi 82C93x"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
-       select SND_PCM
+       select SND_CS4231_LIB
        help
          Say Y here to include support for soundcards based on Opti
          82C93x chips.
@@ -331,7 +314,6 @@ config SND_OPTI93X
 
 config SND_MIRO
        tristate "Miro miroSOUND PCM1pro/PCM12/PCM20radio driver"
-       depends on SND
        select SND_OPL4_LIB
        select SND_CS4231_LIB
        select SND_MPU401_UART
@@ -345,7 +327,6 @@ config SND_MIRO
 
 config SND_SB8
        tristate "Sound Blaster 1.0/2.0/Pro (8-bit)"
-       depends on SND
        select SND_OPL3_LIB
        select SND_RAWMIDI
        select SND_SB8_DSP
@@ -358,7 +339,6 @@ config SND_SB8
 
 config SND_SB16
        tristate "Sound Blaster 16 (PnP)"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_SB16_DSP
@@ -371,7 +351,6 @@ config SND_SB16
 
 config SND_SBAWE
        tristate "Sound Blaster AWE (32,64) (PnP)"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_SB16_DSP
@@ -402,7 +381,6 @@ config SND_SB16_CSP_FIRMWARE_IN_KERNEL
 
 config SND_SGALAXY
        tristate "Aztech Sound Galaxy"
-       depends on SND
        select SND_AD1848_LIB
        help
          Say Y here to include support for Aztech Sound Galaxy
@@ -413,7 +391,6 @@ config SND_SGALAXY
 
 config SND_SSCAPE
        tristate "Ensoniq SoundScape PnP driver"
-       depends on SND
        select SND_HWDEP
        select SND_MPU401_UART
        select SND_CS4231_LIB
@@ -426,7 +403,6 @@ config SND_SSCAPE
 
 config SND_WAVEFRONT
        tristate "Turtle Beach Maui,Tropez,Tropez+ (Wavefront)"
-       depends on SND
        select FW_LOADER
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -448,4 +424,5 @@ config SND_WAVEFRONT_FIRMWARE_IN_KERNEL
          you need to install the firmware files from the
          alsa-firmware package.
 
-endmenu
+endif  # SND_ISA
+
index 0aa8649..521db70 100644 (file)
@@ -119,6 +119,42 @@ static unsigned char snd_cs4231_original_image[32] =
        0x00,                   /* 1f/31 - cbrl */
 };
 
+static unsigned char snd_opti93x_original_image[32] =
+{
+       0x00,           /* 00/00 - l_mixout_outctrl */
+       0x00,           /* 01/01 - r_mixout_outctrl */
+       0x88,           /* 02/02 - l_cd_inctrl */
+       0x88,           /* 03/03 - r_cd_inctrl */
+       0x88,           /* 04/04 - l_a1/fm_inctrl */
+       0x88,           /* 05/05 - r_a1/fm_inctrl */
+       0x80,           /* 06/06 - l_dac_inctrl */
+       0x80,           /* 07/07 - r_dac_inctrl */
+       0x00,           /* 08/08 - ply_dataform_reg */
+       0x00,           /* 09/09 - if_conf */
+       0x00,           /* 0a/10 - pin_ctrl */
+       0x00,           /* 0b/11 - err_init_reg */
+       0x0a,           /* 0c/12 - id_reg */
+       0x00,           /* 0d/13 - reserved */
+       0x00,           /* 0e/14 - ply_upcount_reg */
+       0x00,           /* 0f/15 - ply_lowcount_reg */
+       0x88,           /* 10/16 - reserved/l_a1_inctrl */
+       0x88,           /* 11/17 - reserved/r_a1_inctrl */
+       0x88,           /* 12/18 - l_line_inctrl */
+       0x88,           /* 13/19 - r_line_inctrl */
+       0x88,           /* 14/20 - l_mic_inctrl */
+       0x88,           /* 15/21 - r_mic_inctrl */
+       0x80,           /* 16/22 - l_out_outctrl */
+       0x80,           /* 17/23 - r_out_outctrl */
+       0x00,           /* 18/24 - reserved */
+       0x00,           /* 19/25 - reserved */
+       0x00,           /* 1a/26 - reserved */
+       0x00,           /* 1b/27 - reserved */
+       0x00,           /* 1c/28 - cap_dataform_reg */
+       0x00,           /* 1d/29 - reserved */
+       0x00,           /* 1e/30 - cap_upcount_reg */
+       0x00            /* 1f/31 - cap_lowcount_reg */
+};
+
 /*
  *  Basic I/O functions
  */
@@ -895,7 +931,7 @@ static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static void snd_cs4231_overrange(struct snd_cs4231 *chip)
+void snd_cs4231_overrange(struct snd_cs4231 *chip)
 {
        unsigned long flags;
        unsigned char res;
@@ -1054,8 +1090,11 @@ static int snd_cs4231_probe(struct snd_cs4231 *chip)
        chip->image[CS4231_IFACE_CTRL] =
            (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
            (chip->single_dma ? CS4231_SINGLE_DMA : 0);
-       chip->image[CS4231_ALT_FEATURE_1] = 0x80;
-       chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
+       if (chip->hardware != CS4231_HW_OPTI93X) {
+               chip->image[CS4231_ALT_FEATURE_1] = 0x80;
+               chip->image[CS4231_ALT_FEATURE_2] =
+                       chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
+       }
        ptr = (unsigned char *) &chip->image;
        snd_cs4231_mce_down(chip);
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1376,6 +1415,7 @@ const char *snd_cs4231_chip_id(struct snd_cs4231 *chip)
        case CS4231_HW_INTERWAVE: return "AMD InterWave";
        case CS4231_HW_OPL3SA2: return chip->card->shortname;
        case CS4231_HW_AD1845: return "AD1845";
+       case CS4231_HW_OPTI93X: return "OPTi 93x";
        default: return "???";
        }
 }
@@ -1401,8 +1441,13 @@ static int snd_cs4231_new(struct snd_card *card,
        chip->rate_constraint = snd_cs4231_xrate;
        chip->set_playback_format = snd_cs4231_playback_format;
        chip->set_capture_format = snd_cs4231_capture_format;
-        memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
-        
+       if (chip->hardware == CS4231_HW_OPTI93X)
+               memcpy(&chip->image, &snd_opti93x_original_image,
+                      sizeof(snd_opti93x_original_image));
+       else
+               memcpy(&chip->image, &snd_cs4231_original_image,
+                      sizeof(snd_cs4231_original_image));
+
         *rchip = chip;
         return 0;
 }
@@ -1790,6 +1835,48 @@ CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
 };
                                         
+static struct snd_kcontrol_new snd_opti93x_controls[] = {
+CS4231_DOUBLE("Master Playback Switch", 0,
+             OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
+CS4231_DOUBLE("Master Playback Volume", 0,
+             OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
+CS4231_DOUBLE("PCM Playback Switch", 0,
+             CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("PCM Playback Volume", 0,
+             CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1),
+CS4231_DOUBLE("FM Playback Switch", 0,
+             CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("FM Playback Volume", 0,
+             CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Line Playback Switch", 0,
+             CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+CS4231_DOUBLE("Line Playback Volume", 0,
+             CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1),
+CS4231_DOUBLE("Mic Playback Switch", 0,
+             OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Mic Playback Volume", 0,
+             OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Mic Boost", 0,
+             CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
+CS4231_DOUBLE("CD Playback Switch", 0,
+             CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("CD Playback Volume", 0,
+             CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Aux Playback Switch", 0,
+             OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Playback Volume", 0,
+             OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Capture Volume", 0,
+             CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
+{
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Capture Source",
+       .info = snd_cs4231_info_mux,
+       .get = snd_cs4231_get_mux,
+       .put = snd_cs4231_put_mux,
+}
+};
+
 int snd_cs4231_mixer(struct snd_cs4231 *chip)
 {
        struct snd_card *card;
@@ -1802,10 +1889,22 @@ int snd_cs4231_mixer(struct snd_cs4231 *chip)
 
        strcpy(card->mixername, chip->pcm->name);
 
-       for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
-               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
-                       return err;
-       }
+       if (chip->hardware == CS4231_HW_OPTI93X)
+               for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
+                       err = snd_ctl_add(card,
+                                       snd_ctl_new1(&snd_opti93x_controls[idx],
+                                                    chip));
+                       if (err < 0)
+                               return err;
+               }
+       else
+               for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
+                       err = snd_ctl_add(card,
+                                       snd_ctl_new1(&snd_cs4231_controls[idx],
+                                                    chip));
+                       if (err < 0)
+                               return err;
+               }
        return 0;
 }
 
@@ -1815,6 +1914,7 @@ EXPORT_SYMBOL(snd_cs4236_ext_out);
 EXPORT_SYMBOL(snd_cs4236_ext_in);
 EXPORT_SYMBOL(snd_cs4231_mce_up);
 EXPORT_SYMBOL(snd_cs4231_mce_down);
+EXPORT_SYMBOL(snd_cs4231_overrange);
 EXPORT_SYMBOL(snd_cs4231_interrupt);
 EXPORT_SYMBOL(snd_cs4231_chip_id);
 EXPORT_SYMBOL(snd_cs4231_create);
index fe1afc1..41c047e 100644 (file)
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <sound/core.h>
-#ifdef CS4231
+#if defined(CS4231) || defined(OPTi93X)
 #include <sound/cs4231.h>
 #else
-#ifndef OPTi93X
 #include <sound/ad1848.h>
-#else
-#include <sound/control.h>
-#include <sound/pcm.h>
-#endif /* OPTi93X */
 #endif /* CS4231 */
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
@@ -109,7 +104,6 @@ module_param(dma2, int, 0444);
 MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
 #endif /* CS4231 || OPTi93X */
 
-#define OPTi9XX_HW_DETECT      0
 #define OPTi9XX_HW_82C928      1
 #define OPTi9XX_HW_82C929      2
 #define OPTi9XX_HW_82C924      3
@@ -123,105 +117,12 @@ MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
 
 #ifdef OPTi93X
 
-#define OPTi93X_INDEX                  0x00
-#define OPTi93X_DATA                   0x01
 #define OPTi93X_STATUS                 0x02
-#define OPTi93X_DDATA                  0x03
 #define OPTi93X_PORT(chip, r)          ((chip)->port + OPTi93X_##r)
 
-#define OPTi93X_MIXOUT_LEFT            0x00
-#define OPTi93X_MIXOUT_RIGHT           0x01
-#define OPTi93X_CD_LEFT_INPUT          0x02
-#define OPTi93X_CD_RIGHT_INPUT         0x03
-#define OPTi930_AUX_LEFT_INPUT         0x04
-#define OPTi930_AUX_RIGHT_INPUT                0x05
-#define OPTi931_FM_LEFT_INPUT          0x04
-#define OPTi931_FM_RIGHT_INPUT         0x05
-#define OPTi93X_DAC_LEFT               0x06
-#define OPTi93X_DAC_RIGHT              0x07
-#define OPTi93X_PLAY_FORMAT            0x08
-#define OPTi93X_IFACE_CONF             0x09
-#define OPTi93X_PIN_CTRL               0x0a
-#define OPTi93X_ERR_INIT               0x0b
-#define OPTi93X_ID                     0x0c
-#define OPTi93X_PLAY_UPR_CNT           0x0e
-#define OPTi93X_PLAY_LWR_CNT           0x0f
-#define OPTi931_AUX_LEFT_INPUT         0x10
-#define OPTi931_AUX_RIGHT_INPUT                0x11
-#define OPTi93X_LINE_LEFT_INPUT                0x12
-#define OPTi93X_LINE_RIGHT_INPUT       0x13
-#define OPTi93X_MIC_LEFT_INPUT         0x14
-#define OPTi93X_MIC_RIGHT_INPUT                0x15
-#define OPTi93X_OUT_LEFT               0x16
-#define OPTi93X_OUT_RIGHT              0x17
-#define OPTi93X_CAPT_FORMAT            0x1c
-#define OPTi93X_CAPT_UPR_CNT           0x1e
-#define OPTi93X_CAPT_LWR_CNT           0x1f
-
-#define OPTi93X_TRD                    0x20
-#define OPTi93X_MCE                    0x40
-#define OPTi93X_INIT                   0x80
-
-#define OPTi93X_MIXOUT_MIC_GAIN                0x20
-#define OPTi93X_MIXOUT_LINE            0x00
-#define OPTi93X_MIXOUT_CD              0x40
-#define OPTi93X_MIXOUT_MIC             0x80
-#define OPTi93X_MIXOUT_MIXER           0xc0
-
-#define OPTi93X_STEREO                 0x10
-#define OPTi93X_LINEAR_8               0x00
-#define OPTi93X_ULAW_8                 0x20
-#define OPTi93X_LINEAR_16_LIT          0x40
-#define OPTi93X_ALAW_8                 0x60
-#define OPTi93X_ADPCM_16               0xa0
-#define OPTi93X_LINEAR_16_BIG          0xc0
-
-#define OPTi93X_CAPTURE_PIO            0x80
-#define OPTi93X_PLAYBACK_PIO           0x40
-#define OPTi93X_AUTOCALIB              0x08
-#define OPTi93X_SINGLE_DMA             0x04
-#define OPTi93X_CAPTURE_ENABLE         0x02
-#define OPTi93X_PLAYBACK_ENABLE                0x01
-
-#define OPTi93X_IRQ_ENABLE             0x02
-
-#define OPTi93X_DMA_REQUEST            0x10
-#define OPTi93X_CALIB_IN_PROGRESS      0x20
-
 #define OPTi93X_IRQ_PLAYBACK           0x04
 #define OPTi93X_IRQ_CAPTURE            0x08
 
-
-struct snd_opti93x {
-       unsigned long port;
-       struct resource *res_port;
-       int irq;
-       int dma1;
-       int dma2;
-
-       struct snd_opti9xx *chip;
-       unsigned short hardware;
-       unsigned char image[32];
-
-       unsigned char mce_bit;
-       unsigned short mode;
-       int mute;
-
-       spinlock_t lock;
-
-       struct snd_card *card;
-       struct snd_pcm *pcm;
-       struct snd_pcm_substream *playback_substream;
-       struct snd_pcm_substream *capture_substream;
-       unsigned int p_dma_size;
-       unsigned int c_dma_size;
-};
-
-#define OPTi93X_MODE_NONE      0x00
-#define OPTi93X_MODE_PLAY      0x01
-#define OPTi93X_MODE_CAPTURE   0x02
-#define OPTi93X_MODE_OPEN      (OPTi93X_MODE_PLAY | OPTi93X_MODE_CAPTURE)
-
 #endif /* OPTi93X */
 
 struct snd_opti9xx {
@@ -234,6 +135,7 @@ struct snd_opti9xx {
        unsigned long mc_base_size;
 #ifdef OPTi93X
        unsigned long mc_indir_index;
+       struct snd_cs4231 *codec;
 #endif /* OPTi93X */
        unsigned long pwd_reg;
 
@@ -491,16 +393,9 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
                break;
 
 #else  /* OPTi93X */
-       case OPTi9XX_HW_82C930:
        case OPTi9XX_HW_82C931:
        case OPTi9XX_HW_82C933:
-               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
-               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
-               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
-                       (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
-                       0x34);
-               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
-               /* 
+               /*
                 * The BTC 1817DW has QS1000 wavetable which is connected
                 * to the serial digital input of the OPTI931.
                 */
@@ -510,6 +405,13 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
                 * or digital input signal.
                 */
                snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
+       case OPTi9XX_HW_82C930: /* FALL THROUGH */
+               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
+               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
+               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
+                       (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
+                       0x34);
+               snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
                break;
 #endif /* OPTi93X */
 
@@ -654,979 +556,23 @@ __skip_mpu:
 
 #ifdef OPTi93X
 
-static unsigned char snd_opti93x_default_image[32] =
-{
-       0x00,           /* 00/00 - l_mixout_outctrl */
-       0x00,           /* 01/01 - r_mixout_outctrl */
-       0x88,           /* 02/02 - l_cd_inctrl */
-       0x88,           /* 03/03 - r_cd_inctrl */
-       0x88,           /* 04/04 - l_a1/fm_inctrl */
-       0x88,           /* 05/05 - r_a1/fm_inctrl */
-       0x80,           /* 06/06 - l_dac_inctrl */
-       0x80,           /* 07/07 - r_dac_inctrl */
-       0x00,           /* 08/08 - ply_dataform_reg */
-       0x00,           /* 09/09 - if_conf */
-       0x00,           /* 0a/10 - pin_ctrl */
-       0x00,           /* 0b/11 - err_init_reg */
-       0x0a,           /* 0c/12 - id_reg */
-       0x00,           /* 0d/13 - reserved */
-       0x00,           /* 0e/14 - ply_upcount_reg */
-       0x00,           /* 0f/15 - ply_lowcount_reg */
-       0x88,           /* 10/16 - reserved/l_a1_inctrl */
-       0x88,           /* 11/17 - reserved/r_a1_inctrl */
-       0x88,           /* 12/18 - l_line_inctrl */
-       0x88,           /* 13/19 - r_line_inctrl */
-       0x88,           /* 14/20 - l_mic_inctrl */
-       0x88,           /* 15/21 - r_mic_inctrl */
-       0x80,           /* 16/22 - l_out_outctrl */
-       0x80,           /* 17/23 - r_out_outctrl */
-       0x00,           /* 18/24 - reserved */
-       0x00,           /* 19/25 - reserved */
-       0x00,           /* 1a/26 - reserved */
-       0x00,           /* 1b/27 - reserved */
-       0x00,           /* 1c/28 - cap_dataform_reg */
-       0x00,           /* 1d/29 - reserved */
-       0x00,           /* 1e/30 - cap_upcount_reg */
-       0x00            /* 1f/31 - cap_lowcount_reg */
-};
-
-
-static int snd_opti93x_busy_wait(struct snd_opti93x *chip)
-{
-       int timeout;
-
-       for (timeout = 250; timeout-- > 0; udelay(10))
-               if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_INIT))
-                       return 0;
-
-       snd_printk("chip still busy.\n");
-       return -EBUSY;
-}
-
-static unsigned char snd_opti93x_in(struct snd_opti93x *chip, unsigned char reg)
-{
-       snd_opti93x_busy_wait(chip);
-       outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
-       return inb(OPTi93X_PORT(chip, DATA));
-}
-
-static void snd_opti93x_out(struct snd_opti93x *chip, unsigned char reg,
-                           unsigned char value)
-{
-       snd_opti93x_busy_wait(chip);
-       outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX));
-       outb(value, OPTi93X_PORT(chip, DATA));
-}
-
-static void snd_opti93x_out_image(struct snd_opti93x *chip, unsigned char reg,
-                                 unsigned char value)
-{
-       snd_opti93x_out(chip, reg, chip->image[reg] = value);
-}
-
-static void snd_opti93x_out_mask(struct snd_opti93x *chip, unsigned char reg,
-                                unsigned char mask, unsigned char value)
-{
-       snd_opti93x_out_image(chip, reg,
-               (chip->image[reg] & ~mask) | (value & mask));
-}
-
-
-static void snd_opti93x_mce_up(struct snd_opti93x *chip)
-{
-       snd_opti93x_busy_wait(chip);
-
-       chip->mce_bit = OPTi93X_MCE;
-       if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE))
-               outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
-}
-
-static void snd_opti93x_mce_down(struct snd_opti93x *chip)
-{
-       snd_opti93x_busy_wait(chip);
-
-       chip->mce_bit = 0;
-       if (inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE)
-               outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX));
-}
-
-#define snd_opti93x_mute_reg(chip, reg, mute)  \
-       snd_opti93x_out(chip, reg, mute ? 0x80 : chip->image[reg]);
-
-static void snd_opti93x_mute(struct snd_opti93x *chip, int mute)
-{
-       mute = mute ? 1 : 0;
-       if (chip->mute == mute)
-               return;
-
-       chip->mute = mute;
-
-       snd_opti93x_mute_reg(chip, OPTi93X_CD_LEFT_INPUT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_CD_RIGHT_INPUT, mute);
-       switch (chip->hardware) {
-       case OPTi9XX_HW_82C930:
-               snd_opti93x_mute_reg(chip, OPTi930_AUX_LEFT_INPUT, mute);
-               snd_opti93x_mute_reg(chip, OPTi930_AUX_RIGHT_INPUT, mute);
-               break;
-       case OPTi9XX_HW_82C931:
-       case OPTi9XX_HW_82C933:
-               snd_opti93x_mute_reg(chip, OPTi931_FM_LEFT_INPUT, mute);
-               snd_opti93x_mute_reg(chip, OPTi931_FM_RIGHT_INPUT, mute);
-               snd_opti93x_mute_reg(chip, OPTi931_AUX_LEFT_INPUT, mute);
-               snd_opti93x_mute_reg(chip, OPTi931_AUX_RIGHT_INPUT, mute);
-       }
-       snd_opti93x_mute_reg(chip, OPTi93X_DAC_LEFT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_DAC_RIGHT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_LINE_LEFT_INPUT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_LINE_RIGHT_INPUT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_MIC_LEFT_INPUT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_MIC_RIGHT_INPUT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_OUT_LEFT, mute);
-       snd_opti93x_mute_reg(chip, OPTi93X_OUT_RIGHT, mute);
-}
-
-
-static unsigned int snd_opti93x_get_count(unsigned char format,
-                                         unsigned int size)
-{
-       switch (format & 0xe0) {
-       case OPTi93X_LINEAR_16_LIT:
-       case OPTi93X_LINEAR_16_BIG:
-               size >>= 1;
-               break;
-       case OPTi93X_ADPCM_16:
-               return size >> 2;
-       }
-       return (format & OPTi93X_STEREO) ? (size >> 1) : size;
-}
-
-static unsigned int rates[] = {  5512,  6615,  8000,  9600, 11025, 16000, 
-                               18900, 22050, 27428, 32000, 33075, 37800,
-                               44100, 48000 };
-#define RATES ARRAY_SIZE(rates)
-
-static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
-       .count = RATES,
-       .list = rates,
-       .mask = 0,
-};
-
-static unsigned char bits[] = {  0x01,  0x0f,  0x00,  0x0e,  0x03,  0x02,
-                                0x05,  0x07,  0x04,  0x06,  0x0d,  0x09,
-                                0x0b,  0x0c};
-
-static unsigned char snd_opti93x_get_freq(unsigned int rate)
-{
-       unsigned int i;
-
-       for (i = 0; i < RATES; i++) {
-               if (rate == rates[i])
-                       return bits[i];
-       }
-       snd_BUG();
-       return bits[RATES-1];
-}
-
-static unsigned char snd_opti93x_get_format(struct snd_opti93x *chip,
-                                           unsigned int format, int channels)
-{
-       unsigned char retval = OPTi93X_LINEAR_8;
-
-       switch (format) {
-       case SNDRV_PCM_FORMAT_MU_LAW:
-               retval = OPTi93X_ULAW_8;
-               break;
-       case SNDRV_PCM_FORMAT_A_LAW:
-               retval = OPTi93X_ALAW_8;
-               break;
-       case SNDRV_PCM_FORMAT_S16_LE:
-               retval = OPTi93X_LINEAR_16_LIT;
-               break;
-       case SNDRV_PCM_FORMAT_S16_BE:
-               retval = OPTi93X_LINEAR_16_BIG;
-               break;
-       case SNDRV_PCM_FORMAT_IMA_ADPCM:
-               retval = OPTi93X_ADPCM_16;
-       }
-       return (channels > 1) ? (retval | OPTi93X_STEREO) : retval;
-}
-
-
-static void snd_opti93x_playback_format(struct snd_opti93x *chip, unsigned char fmt)
-{
-       unsigned char mask;
-
-       snd_opti93x_mute(chip, 1);
-
-       snd_opti93x_mce_up(chip);
-       mask = (chip->mode & OPTi93X_MODE_CAPTURE) ? 0xf0 : 0xff;
-       snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, mask, fmt);
-       snd_opti93x_mce_down(chip);
-
-       snd_opti93x_mute(chip, 0);
-}
-
-static void snd_opti93x_capture_format(struct snd_opti93x *chip, unsigned char fmt)
-{
-       snd_opti93x_mute(chip, 1);
-
-       snd_opti93x_mce_up(chip);
-       if (!(chip->mode & OPTi93X_MODE_PLAY))
-               snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, 0x0f, fmt);
-       else
-               fmt = chip->image[OPTi93X_PLAY_FORMAT] & 0xf0;
-       snd_opti93x_out_image(chip, OPTi93X_CAPT_FORMAT, fmt);
-       snd_opti93x_mce_down(chip);
-
-       snd_opti93x_mute(chip, 0);
-}
-
-
-static int snd_opti93x_open(struct snd_opti93x *chip, unsigned int mode)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&chip->lock, flags);
-
-       if (chip->mode & mode) {
-               spin_unlock_irqrestore(&chip->lock, flags);
-               return -EAGAIN;
-       }
-
-       if (!(chip->mode & OPTi93X_MODE_OPEN)) {
-               outb(0x00, OPTi93X_PORT(chip, STATUS));
-               snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL,
-                       OPTi93X_IRQ_ENABLE, OPTi93X_IRQ_ENABLE);
-               chip->mode = mode;
-       }
-       else
-               chip->mode |= mode;
-
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return 0;
-}
-
-static void snd_opti93x_close(struct snd_opti93x *chip, unsigned int mode)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&chip->lock, flags);
-
-       chip->mode &= ~mode;
-       if (chip->mode & OPTi93X_MODE_OPEN) {
-               spin_unlock_irqrestore(&chip->lock, flags);
-               return;
-       }
-
-       snd_opti93x_mute(chip, 1);
-
-       outb(0, OPTi93X_PORT(chip, STATUS));
-       snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, OPTi93X_IRQ_ENABLE,
-               ~OPTi93X_IRQ_ENABLE);
-
-       snd_opti93x_mce_up(chip);
-       snd_opti93x_out_image(chip, OPTi93X_IFACE_CONF, 0x00);
-       snd_opti93x_mce_down(chip);
-       chip->mode = 0;
-
-       snd_opti93x_mute(chip, 0);
-       spin_unlock_irqrestore(&chip->lock, flags);
-}
-
-static int snd_opti93x_trigger(struct snd_pcm_substream *substream, 
-                              unsigned char what, int cmd)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_STOP:
-       {
-               unsigned int what = 0;
-               struct snd_pcm_substream *s;
-               snd_pcm_group_for_each_entry(s, substream) {
-                       if (s == chip->playback_substream) {
-                               what |= OPTi93X_PLAYBACK_ENABLE;
-                               snd_pcm_trigger_done(s, substream);
-                       } else if (s == chip->capture_substream) {
-                               what |= OPTi93X_CAPTURE_ENABLE;
-                               snd_pcm_trigger_done(s, substream);
-                       }
-               }
-               spin_lock(&chip->lock);
-               if (cmd == SNDRV_PCM_TRIGGER_START) {
-                       snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, what);
-                       if (what & OPTi93X_CAPTURE_ENABLE)
-                               udelay(50);
-               } else
-                       snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, 0x00);
-               spin_unlock(&chip->lock);
-               break;
-       }
-       default:
-               return -EINVAL;
-       }
-       return 0;
-}
-
-static int snd_opti93x_playback_trigger(struct snd_pcm_substream *substream, int cmd)
-{
-       return snd_opti93x_trigger(substream,
-                                  OPTi93X_PLAYBACK_ENABLE, cmd);
-}
-
-static int snd_opti93x_capture_trigger(struct snd_pcm_substream *substream, int cmd)
-{
-       return snd_opti93x_trigger(substream,
-                                  OPTi93X_CAPTURE_ENABLE, cmd);
-}
-
-static int snd_opti93x_hw_params(struct snd_pcm_substream *substream,
-                                struct snd_pcm_hw_params *hw_params)
-{
-       return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
-}
-
-
-static int snd_opti93x_hw_free(struct snd_pcm_substream *substream)
-{
-       snd_pcm_lib_free_pages(substream);
-       return 0;
-}
-
-
-static int snd_opti93x_playback_prepare(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       unsigned long flags;
-       unsigned char format;
-       unsigned int count = snd_pcm_lib_period_bytes(substream);
-       unsigned int size = snd_pcm_lib_buffer_bytes(substream);
-
-       spin_lock_irqsave(&chip->lock, flags);
-
-       chip->p_dma_size = size;
-       snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
-               OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO,
-               ~(OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO));
-
-       snd_dma_program(chip->dma1, runtime->dma_addr, size,
-               DMA_MODE_WRITE | DMA_AUTOINIT);
-
-       format = snd_opti93x_get_freq(runtime->rate);
-       format |= snd_opti93x_get_format(chip, runtime->format,
-               runtime->channels);
-       snd_opti93x_playback_format(chip, format);
-       format = chip->image[OPTi93X_PLAY_FORMAT];
-
-       count = snd_opti93x_get_count(format, count) - 1;
-       snd_opti93x_out_image(chip, OPTi93X_PLAY_LWR_CNT, count);
-       snd_opti93x_out_image(chip, OPTi93X_PLAY_UPR_CNT, count >> 8);
-
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return 0;
-}
-
-static int snd_opti93x_capture_prepare(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       unsigned long flags;
-       unsigned char format;
-       unsigned int count = snd_pcm_lib_period_bytes(substream);
-       unsigned int size = snd_pcm_lib_buffer_bytes(substream);
-
-       spin_lock_irqsave(&chip->lock, flags);
-
-       chip->c_dma_size = size;
-       snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF,
-               OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO, 0);
-
-       snd_dma_program(chip->dma2, runtime->dma_addr, size,
-               DMA_MODE_READ | DMA_AUTOINIT);
-
-       format = snd_opti93x_get_freq(runtime->rate);
-       format |= snd_opti93x_get_format(chip, runtime->format,
-               runtime->channels);
-       snd_opti93x_capture_format(chip, format);
-       format = chip->image[OPTi93X_CAPT_FORMAT];
-
-       count = snd_opti93x_get_count(format, count) - 1;
-       snd_opti93x_out_image(chip, OPTi93X_CAPT_LWR_CNT, count);
-       snd_opti93x_out_image(chip, OPTi93X_CAPT_UPR_CNT, count >> 8);
-
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return 0;
-}
-
-static snd_pcm_uframes_t snd_opti93x_playback_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       size_t ptr;
-
-       if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_PLAYBACK_ENABLE))
-               return 0;
-
-       ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
-       return bytes_to_frames(substream->runtime, ptr);
-}
-
-static snd_pcm_uframes_t snd_opti93x_capture_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       size_t ptr;
-       
-       if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_CAPTURE_ENABLE))
-               return 0;
-
-       ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
-       return bytes_to_frames(substream->runtime, ptr);
-}
-
-
-static void snd_opti93x_overrange(struct snd_opti93x *chip)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&chip->lock, flags);
-
-       if (snd_opti93x_in(chip, OPTi93X_ERR_INIT) & (0x08 | 0x02))
-               chip->capture_substream->runtime->overrange++;
-
-       spin_unlock_irqrestore(&chip->lock, flags);
-}
-
 static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
 {
-       struct snd_opti93x *codec = dev_id;
+       struct snd_cs4231 *codec = dev_id;
+       struct snd_opti9xx *chip = codec->card->private_data;
        unsigned char status;
 
-       status = snd_opti9xx_read(codec->chip, OPTi9XX_MC_REG(11));
+       status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
        if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
                snd_pcm_period_elapsed(codec->playback_substream);
        if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
-               snd_opti93x_overrange(codec);
+               snd_cs4231_overrange(codec);
                snd_pcm_period_elapsed(codec->capture_substream);
        }
        outb(0x00, OPTi93X_PORT(codec, STATUS));
        return IRQ_HANDLED;
 }
 
-
-static struct snd_pcm_hardware snd_opti93x_playback = {
-       .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
-       .formats =              (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
-                                SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
-       .rates =                SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
-       .rate_min =             5512,
-       .rate_max =             48000,
-       .channels_min =         1,
-       .channels_max =         2,
-       .buffer_bytes_max =     (128*1024),
-       .period_bytes_min =     64,
-       .period_bytes_max =     (128*1024),
-       .periods_min =          1,
-       .periods_max =          1024,
-       .fifo_size =            0,
-};
-
-static struct snd_pcm_hardware snd_opti93x_capture = {
-       .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START),
-       .formats =              (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
-                                SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
-       .rates =                SNDRV_PCM_RATE_8000_48000,
-       .rate_min =             5512,
-       .rate_max =             48000,
-       .channels_min =         1,
-       .channels_max =         2,
-       .buffer_bytes_max =     (128*1024),
-       .period_bytes_min =     64,
-       .period_bytes_max =     (128*1024),
-       .periods_min =          1,
-       .periods_max =          1024,
-       .fifo_size =            0,
-};
-
-static int snd_opti93x_playback_open(struct snd_pcm_substream *substream)
-{
-       int error;
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-
-       if ((error = snd_opti93x_open(chip, OPTi93X_MODE_PLAY)) < 0)
-               return error;
-       snd_pcm_set_sync(substream);
-       chip->playback_substream = substream;
-       runtime->hw = snd_opti93x_playback;
-       snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
-       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
-       return error;
-}
-
-static int snd_opti93x_capture_open(struct snd_pcm_substream *substream)
-{
-       int error;
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-
-       if ((error = snd_opti93x_open(chip, OPTi93X_MODE_CAPTURE)) < 0)
-               return error;
-       runtime->hw = snd_opti93x_capture;
-       snd_pcm_set_sync(substream);
-       chip->capture_substream = substream;
-       snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
-       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
-       return error;
-}
-
-static int snd_opti93x_playback_close(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-
-       chip->playback_substream = NULL;
-       snd_opti93x_close(chip, OPTi93X_MODE_PLAY);
-       return 0;
-}
-
-static int snd_opti93x_capture_close(struct snd_pcm_substream *substream)
-{
-       struct snd_opti93x *chip = snd_pcm_substream_chip(substream);
-
-       chip->capture_substream = NULL;
-       snd_opti93x_close(chip, OPTi93X_MODE_CAPTURE);
-       return 0;
-}
-
-
-static void snd_opti93x_init(struct snd_opti93x *chip)
-{
-       unsigned long flags;
-       int i;
-
-       spin_lock_irqsave(&chip->lock, flags);
-       snd_opti93x_mce_up(chip);
-
-       for (i = 0; i < 32; i++)
-               snd_opti93x_out_image(chip, i, snd_opti93x_default_image[i]);
-
-       snd_opti93x_mce_down(chip);
-       spin_unlock_irqrestore(&chip->lock, flags);
-}
-
-static int snd_opti93x_probe(struct snd_opti93x *chip)
-{
-       unsigned long flags;
-       unsigned char val;
-
-       spin_lock_irqsave(&chip->lock, flags);
-       val = snd_opti93x_in(chip, OPTi93X_ID) & 0x0f;
-       spin_unlock_irqrestore(&chip->lock, flags);
-
-       return (val == 0x0a) ? 0 : -ENODEV;
-}
-
-static int snd_opti93x_free(struct snd_opti93x *chip)
-{
-       release_and_free_resource(chip->res_port);
-       if (chip->dma1 >= 0) {
-               disable_dma(chip->dma1);
-               free_dma(chip->dma1);
-       }
-       if (chip->dma2 >= 0) {
-               disable_dma(chip->dma2);
-               free_dma(chip->dma2);
-       }
-       if (chip->irq >= 0) {
-         free_irq(chip->irq, chip);
-       }
-       kfree(chip);
-       return 0;
-}
-
-static int snd_opti93x_dev_free(struct snd_device *device)
-{
-       struct snd_opti93x *chip = device->device_data;
-       return snd_opti93x_free(chip);
-}
-
-static const char *snd_opti93x_chip_id(struct snd_opti93x *codec)
-{
-       switch (codec->hardware) {
-       case OPTi9XX_HW_82C930: return "82C930";
-       case OPTi9XX_HW_82C931: return "82C931";
-       case OPTi9XX_HW_82C933: return "82C933";
-       default:                return "???";
-       }
-}
-
-static int snd_opti93x_create(struct snd_card *card, struct snd_opti9xx *chip,
-                             int dma1, int dma2,
-                             struct snd_opti93x **rcodec)
-{
-       static struct snd_device_ops ops = {
-               .dev_free =     snd_opti93x_dev_free,
-       };
-       int error;
-       struct snd_opti93x *codec;
-
-       *rcodec = NULL;
-       codec = kzalloc(sizeof(*codec), GFP_KERNEL);
-       if (codec == NULL)
-               return -ENOMEM;
-       codec->irq = -1;
-       codec->dma1 = -1;
-       codec->dma2 = -1;
-
-       if ((codec->res_port = request_region(chip->wss_base + 4, 4, "OPTI93x CODEC")) == NULL) {
-               snd_printk(KERN_ERR "opti9xx: can't grab port 0x%lx\n", chip->wss_base + 4);
-               snd_opti93x_free(codec);
-               return -EBUSY;
-       }
-       if (request_dma(dma1, "OPTI93x - 1")) {
-               snd_printk(KERN_ERR "opti9xx: can't grab DMA1 %d\n", dma1);
-               snd_opti93x_free(codec);
-               return -EBUSY;
-       }
-       codec->dma1 = chip->dma1;
-       if (request_dma(dma2, "OPTI93x - 2")) {
-               snd_printk(KERN_ERR "opti9xx: can't grab DMA2 %d\n", dma2);
-               snd_opti93x_free(codec);
-               return -EBUSY;
-       }
-       codec->dma2 = chip->dma2;
-
-       if (request_irq(chip->irq, snd_opti93x_interrupt, IRQF_DISABLED, DEV_NAME" - WSS", codec)) {
-               snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
-               snd_opti93x_free(codec);
-               return -EBUSY;
-       }
-
-       codec->card = card;
-       codec->port = chip->wss_base + 4;
-       codec->irq = chip->irq;
-
-       spin_lock_init(&codec->lock);
-       codec->hardware = chip->hardware;
-       codec->chip = chip;
-
-       if ((error = snd_opti93x_probe(codec))) {
-               snd_opti93x_free(codec);
-               return error;
-       }
-
-       snd_opti93x_init(codec);
-
-       /* Register device */
-       if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
-               snd_opti93x_free(codec);
-               return error;
-       }
-
-       *rcodec = codec;
-       return 0;
-}
-
-static struct snd_pcm_ops snd_opti93x_playback_ops = {
-       .open =         snd_opti93x_playback_open,
-       .close =        snd_opti93x_playback_close,
-       .ioctl =        snd_pcm_lib_ioctl,
-       .hw_params =    snd_opti93x_hw_params,
-       .hw_free =      snd_opti93x_hw_free,
-       .prepare =      snd_opti93x_playback_prepare,
-       .trigger =      snd_opti93x_playback_trigger,
-       .pointer =      snd_opti93x_playback_pointer,
-};
-
-static struct snd_pcm_ops snd_opti93x_capture_ops = {
-       .open =         snd_opti93x_capture_open,
-       .close =        snd_opti93x_capture_close,
-       .ioctl =        snd_pcm_lib_ioctl,
-       .hw_params =    snd_opti93x_hw_params,
-       .hw_free =      snd_opti93x_hw_free,
-       .prepare =      snd_opti93x_capture_prepare,
-       .trigger =      snd_opti93x_capture_trigger,
-       .pointer =      snd_opti93x_capture_pointer,
-};
-
-static int snd_opti93x_pcm(struct snd_opti93x *codec, int device, struct snd_pcm **rpcm)
-{
-       int error;
-       struct snd_pcm *pcm;
-
-       if ((error = snd_pcm_new(codec->card, "OPTi 82C93X", device, 1, 1, &pcm)) < 0)
-               return error;
-
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_opti93x_playback_ops);
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_opti93x_capture_ops);
-
-       pcm->private_data = codec;
-       pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
-
-       strcpy(pcm->name, snd_opti93x_chip_id(codec));
-
-       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
-                                             snd_dma_isa_data(),
-                                             64*1024, codec->dma1 > 3 || codec->dma2 > 3 ? 128*1024 : 64*1024);
-
-       codec->pcm = pcm;
-       if (rpcm)
-               *rpcm = pcm;
-       return 0;
-}
-
-/*
- *  MIXER part
- */
-
-static int snd_opti93x_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       static char *texts[4] = {
-               "Line1", "Aux", "Mic", "Mix"
-       };
-
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 2;
-       uinfo->value.enumerated.items = 4;
-       if (uinfo->value.enumerated.item > 3)
-               uinfo->value.enumerated.item = 3;
-       strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
-       return 0;
-}
-
-static int snd_opti93x_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       
-       spin_lock_irqsave(&chip->lock, flags);
-       ucontrol->value.enumerated.item[0] = (chip->image[OPTi93X_MIXOUT_LEFT] & OPTi93X_MIXOUT_MIXER) >> 6;
-       ucontrol->value.enumerated.item[1] = (chip->image[OPTi93X_MIXOUT_RIGHT] & OPTi93X_MIXOUT_MIXER) >> 6;
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return 0;
-}
-
-static int snd_opti93x_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       unsigned short left, right;
-       int change;
-       
-       if (ucontrol->value.enumerated.item[0] > 3 ||
-           ucontrol->value.enumerated.item[1] > 3)
-               return -EINVAL;
-       left = ucontrol->value.enumerated.item[0] << 6;
-       right = ucontrol->value.enumerated.item[1] << 6;
-       spin_lock_irqsave(&chip->lock, flags);
-       left = (chip->image[OPTi93X_MIXOUT_LEFT] & ~OPTi93X_MIXOUT_MIXER) | left;
-       right = (chip->image[OPTi93X_MIXOUT_RIGHT] & ~OPTi93X_MIXOUT_MIXER) | right;
-       change = left != chip->image[OPTi93X_MIXOUT_LEFT] ||
-                right != chip->image[OPTi93X_MIXOUT_RIGHT];
-       snd_opti93x_out_image(chip, OPTi93X_MIXOUT_LEFT, left);
-       snd_opti93x_out_image(chip, OPTi93X_MIXOUT_RIGHT, right);
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return change;
-}
-
-#if 0
-
-#define OPTi93X_SINGLE(xname, xindex, reg, shift, mask, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_opti93x_info_single, \
-  .get = snd_opti93x_get_single, .put = snd_opti93x_put_single, \
-  .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
-
-static int snd_opti93x_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       int mask = (kcontrol->private_value >> 16) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-
-static int snd_opti93x_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 8) & 0xff;
-       int mask = (kcontrol->private_value >> 16) & 0xff;
-       int invert = (kcontrol->private_value >> 24) & 0xff;
-       
-       spin_lock_irqsave(&chip->lock, flags);
-       ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
-       spin_unlock_irqrestore(&chip->lock, flags);
-       if (invert)
-               ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
-       return 0;
-}
-
-static int snd_opti93x_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 8) & 0xff;
-       int mask = (kcontrol->private_value >> 16) & 0xff;
-       int invert = (kcontrol->private_value >> 24) & 0xff;
-       int change;
-       unsigned short val;
-       
-       val = (ucontrol->value.integer.value[0] & mask);
-       if (invert)
-               val = mask - val;
-       val <<= shift;
-       spin_lock_irqsave(&chip->lock, flags);
-       val = (chip->image[reg] & ~(mask << shift)) | val;
-       change = val != chip->image[reg];
-       snd_opti93x_out(chip, reg, val);
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return change;
-}
-
-#endif /* single */
-
-#define OPTi93X_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_opti93x_info_double, \
-  .get = snd_opti93x_get_double, .put = snd_opti93x_put_double, \
-  .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
-
-#define OPTi93X_DOUBLE_INVERT_INVERT(xctl) \
-       do { xctl.private_value ^= 22; } while (0)
-#define OPTi93X_DOUBLE_CHANGE_REGS(xctl, left_reg, right_reg) \
-       do { xctl.private_value &= ~0x0000ffff; \
-            xctl.private_value |= left_reg | (right_reg << 8); } while (0)
-
-static int snd_opti93x_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 2;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-
-static int snd_opti93x_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       int left_reg = kcontrol->private_value & 0xff;
-       int right_reg = (kcontrol->private_value >> 8) & 0xff;
-       int shift_left = (kcontrol->private_value >> 16) & 0x07;
-       int shift_right = (kcontrol->private_value >> 19) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       
-       spin_lock_irqsave(&chip->lock, flags);
-       ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
-       ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
-       spin_unlock_irqrestore(&chip->lock, flags);
-       if (invert) {
-               ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
-               ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
-       }
-       return 0;
-}
-
-static int snd_opti93x_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       int left_reg = kcontrol->private_value & 0xff;
-       int right_reg = (kcontrol->private_value >> 8) & 0xff;
-       int shift_left = (kcontrol->private_value >> 16) & 0x07;
-       int shift_right = (kcontrol->private_value >> 19) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       int change;
-       unsigned short val1, val2;
-       
-       val1 = ucontrol->value.integer.value[0] & mask;
-       val2 = ucontrol->value.integer.value[1] & mask;
-       if (invert) {
-               val1 = mask - val1;
-               val2 = mask - val2;
-       }
-       val1 <<= shift_left;
-       val2 <<= shift_right;
-       spin_lock_irqsave(&chip->lock, flags);
-       val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
-       val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
-       change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
-       snd_opti93x_out_image(chip, left_reg, val1);
-       snd_opti93x_out_image(chip, right_reg, val2);
-       spin_unlock_irqrestore(&chip->lock, flags);
-       return change;
-}
-
-static struct snd_kcontrol_new snd_opti93x_controls[] __devinitdata = {
-OPTi93X_DOUBLE("Master Playback Switch", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("Master Playback Volume", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1), 
-OPTi93X_DOUBLE("PCM Playback Switch", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("PCM Playback Volume", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 0, 0, 31, 1),
-OPTi93X_DOUBLE("FM Playback Switch", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("FM Playback Volume", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 1, 1, 15, 1),
-OPTi93X_DOUBLE("Line Playback Switch", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("Line Playback Volume", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 1, 1, 15, 1), 
-OPTi93X_DOUBLE("Mic Playback Switch", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("Mic Playback Volume", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1), 
-OPTi93X_DOUBLE("Mic Boost", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 5, 5, 1, 1),
-OPTi93X_DOUBLE("CD Playback Switch", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("CD Playback Volume", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 1, 1, 15, 1),
-OPTi93X_DOUBLE("Aux Playback Switch", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
-OPTi93X_DOUBLE("Aux Playback Volume", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1), 
-OPTi93X_DOUBLE("Capture Volume", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 0, 0, 15, 0),
-{
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "Capture Source",
-       .info = snd_opti93x_info_mux,
-       .get = snd_opti93x_get_mux,
-       .put = snd_opti93x_put_mux,
-}
-};
-                                        
-static int __devinit snd_opti93x_mixer(struct snd_opti93x *chip)
-{
-       struct snd_card *card;
-       struct snd_kcontrol_new knew;
-       int err;
-       unsigned int idx;
-
-       snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
-
-       card = chip->card;
-
-       strcpy(card->mixername, snd_opti93x_chip_id(chip));
-
-       for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
-               knew = snd_opti93x_controls[idx];
-               if (chip->hardware == OPTi9XX_HW_82C930) {
-                       if (strstr(knew.name, "FM"))    /* skip FM controls */
-                               continue;
-                       else if (strcmp(knew.name, "Mic Playback Volume"))
-                               OPTi93X_DOUBLE_INVERT_INVERT(knew);
-                       else if (strstr(knew.name, "Aux"))
-                               OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT);
-                       else if (strcmp(knew.name, "PCM Playback Volume"))
-                               OPTi93X_DOUBLE_INVERT_INVERT(knew);
-                       else if (strcmp(knew.name, "Master Playback Volume"))
-                               OPTi93X_DOUBLE_INVERT_INVERT(knew);
-               }
-               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0)
-                       return err;
-       }
-       return 0;
-}
-
 #endif /* OPTi93X */
 
 static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
@@ -1739,8 +685,16 @@ static void snd_card_opti9xx_free(struct snd_card *card)
 {
        struct snd_opti9xx *chip = card->private_data;
         
-       if (chip)
+       if (chip) {
+#ifdef OPTi93X
+               struct snd_cs4231 *codec = chip->codec;
+               if (codec->irq > 0) {
+                       disable_irq(codec->irq);
+                       free_irq(codec->irq, codec);
+               }
+#endif
                release_and_free_resource(chip->res_mc_base);
+       }
 }
 
 static int __devinit snd_opti9xx_probe(struct snd_card *card)
@@ -1748,11 +702,11 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
        static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
        int error;
        struct snd_opti9xx *chip = card->private_data;
-#if defined(OPTi93X)
-       struct snd_opti93x *codec;
-#elif defined(CS4231)
+#if defined(CS4231) || defined(OPTi93X)
        struct snd_cs4231 *codec;
+#ifdef CS4231
        struct snd_timer *timer;
+#endif
 #else
        struct snd_ad1848 *codec;
 #endif
@@ -1784,26 +738,34 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
        if ((error = snd_opti9xx_configure(chip)))
                return error;
 
-#if defined(OPTi93X)
-       if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec)))
-               return error;
-       if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0)
-               return error;
-       if ((error = snd_opti93x_mixer(codec)) < 0)
-               return error;
-#elif defined(CS4231)
+#if defined(CS4231) || defined(OPTi93X)
        if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
                                       chip->irq, chip->dma1, chip->dma2,
-                                      CS4231_HW_DETECT,
-                                      0,
+#ifdef CS4231
+                                      CS4231_HW_DETECT, 0,
+#else /* OPTi93x */
+                                      CS4231_HW_OPTI93X, CS4231_HWSHARE_IRQ,
+#endif
                                       &codec)) < 0)
                return error;
+#ifdef OPTi93X
+       chip->codec = codec;
+#endif
        if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0)
                return error;
        if ((error = snd_cs4231_mixer(codec)) < 0)
                return error;
+#ifdef CS4231
        if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0)
                return error;
+#else /* OPTI93X */
+       error = request_irq(chip->irq, snd_opti93x_interrupt,
+                           IRQF_DISABLED, DEV_NAME" - WSS", codec);
+       if (error < 0) {
+               snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
+               return error;
+       }
+#endif
 #else
        if ((error = snd_ad1848_create(card, chip->wss_base + 4,
                                       chip->irq, chip->dma1,
index c9d1c98..1098a56 100644 (file)
@@ -34,5 +34,3 @@ ifeq ($(CONFIG_SND_SB16_CSP),y)
   obj-$(CONFIG_SND_SBAWE) += snd-sb16-csp.o
 endif
 obj-$(call sequencer,$(CONFIG_SND_SBAWE)) += snd-emu8000-synth.o
-
-obj-m := $(sort $(obj-m))
index 95eeca1..0bb9b92 100644 (file)
@@ -1939,7 +1939,7 @@ static int __devinit
 wavefront_download_firmware (snd_wavefront_t *dev, char *path)
 
 {
-       unsigned char *buf;
+       const unsigned char *buf;
        int len, err;
        int section_cnt_downloaded = 0;
        const struct firmware *firmware;
index 531f8ba..a9823fa 100644 (file)
@@ -1,15 +1,34 @@
 # ALSA MIPS drivers
 
-menu "ALSA MIPS devices"
-       depends on SND!=n && MIPS
+menuconfig SND_MIPS
+       bool "MIPS sound devices"
+       depends on MIPS
+       default y
+       help
+         Support for sound devices of MIPS architectures.
+
+if SND_MIPS
+
+config SND_SGI_O2
+       tristate "SGI O2 Audio"
+       depends on SGI_IP32
+        help
+                Sound support for the SGI O2 Workstation. 
+
+config SND_SGI_HAL2
+        tristate "SGI HAL2 Audio"
+        depends on SGI_HAS_HAL2
+        help
+                Sound support for the SGI Indy and Indigo2 Workstation.
+
 
 config SND_AU1X00
        tristate "Au1x00 AC97 Port Driver"
-       depends on (SOC_AU1000 || SOC_AU1100 || SOC_AU1500) && SND
+       depends on SOC_AU1000 || SOC_AU1100 || SOC_AU1500
        select SND_PCM
        select SND_AC97_CODEC
        help
          ALSA Sound driver for the Au1x00's AC97 port.
 
-endmenu
+endif  # SND_MIPS
 
index 47afed9..861ec0a 100644 (file)
@@ -3,6 +3,10 @@
 #
 
 snd-au1x00-objs := au1x00.o
+snd-sgi-o2-objs := sgio2audio.o ad1843.o
+snd-sgi-hal2-objs := hal2.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_AU1X00) += snd-au1x00.o
+obj-$(CONFIG_SND_SGI_O2) += snd-sgi-o2.o
+obj-$(CONFIG_SND_SGI_HAL2) += snd-sgi-hal2.o
diff --git a/sound/mips/ad1843.c b/sound/mips/ad1843.c
new file mode 100644 (file)
index 0000000..c624510
--- /dev/null
@@ -0,0 +1,561 @@
+/*
+ *   AD1843 low level driver
+ *
+ *   Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
+ *   Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
+ *
+ *   inspired from vwsnd.c (SGI VW audio driver)
+ *     Copyright 1999 Silicon Graphics, Inc.  All rights reserved.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/errno.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/ad1843.h>
+
+/*
+ * AD1843 bitfield definitions.  All are named as in the AD1843 data
+ * sheet, with ad1843_ prepended and individual bit numbers removed.
+ *
+ * E.g., bits LSS0 through LSS2 become ad1843_LSS.
+ *
+ * Only the bitfields we need are defined.
+ */
+
+struct ad1843_bitfield {
+       char reg;
+       char lo_bit;
+       char nbits;
+};
+
+static const struct ad1843_bitfield
+       ad1843_PDNO   = {  0, 14,  1 }, /* Converter Power-Down Flag */
+       ad1843_INIT   = {  0, 15,  1 }, /* Clock Initialization Flag */
+       ad1843_RIG    = {  2,  0,  4 }, /* Right ADC Input Gain */
+       ad1843_RMGE   = {  2,  4,  1 }, /* Right ADC Mic Gain Enable */
+       ad1843_RSS    = {  2,  5,  3 }, /* Right ADC Source Select */
+       ad1843_LIG    = {  2,  8,  4 }, /* Left ADC Input Gain */
+       ad1843_LMGE   = {  2, 12,  1 }, /* Left ADC Mic Gain Enable */
+       ad1843_LSS    = {  2, 13,  3 }, /* Left ADC Source Select */
+       ad1843_RD2M   = {  3,  0,  5 }, /* Right DAC 2 Mix Gain/Atten */
+       ad1843_RD2MM  = {  3,  7,  1 }, /* Right DAC 2 Mix Mute */
+       ad1843_LD2M   = {  3,  8,  5 }, /* Left DAC 2 Mix Gain/Atten */
+       ad1843_LD2MM  = {  3, 15,  1 }, /* Left DAC 2 Mix Mute */
+       ad1843_RX1M   = {  4,  0,  5 }, /* Right Aux 1 Mix Gain/Atten */
+       ad1843_RX1MM  = {  4,  7,  1 }, /* Right Aux 1 Mix Mute */
+       ad1843_LX1M   = {  4,  8,  5 }, /* Left Aux 1 Mix Gain/Atten */
+       ad1843_LX1MM  = {  4, 15,  1 }, /* Left Aux 1 Mix Mute */
+       ad1843_RX2M   = {  5,  0,  5 }, /* Right Aux 2 Mix Gain/Atten */
+       ad1843_RX2MM  = {  5,  7,  1 }, /* Right Aux 2 Mix Mute */
+       ad1843_LX2M   = {  5,  8,  5 }, /* Left Aux 2 Mix Gain/Atten */
+       ad1843_LX2MM  = {  5, 15,  1 }, /* Left Aux 2 Mix Mute */
+       ad1843_RMCM   = {  7,  0,  5 }, /* Right Mic Mix Gain/Atten */
+       ad1843_RMCMM  = {  7,  7,  1 }, /* Right Mic Mix Mute */
+       ad1843_LMCM   = {  7,  8,  5 }, /* Left Mic Mix Gain/Atten */
+       ad1843_LMCMM  = {  7, 15,  1 }, /* Left Mic Mix Mute */
+       ad1843_HPOS   = {  8,  4,  1 }, /* Headphone Output Voltage Swing */
+       ad1843_HPOM   = {  8,  5,  1 }, /* Headphone Output Mute */
+       ad1843_MPOM   = {  8,  6,  1 }, /* Mono Output Mute */
+       ad1843_RDA1G  = {  9,  0,  6 }, /* Right DAC1 Analog/Digital Gain */
+       ad1843_RDA1GM = {  9,  7,  1 }, /* Right DAC1 Analog Mute */
+       ad1843_LDA1G  = {  9,  8,  6 }, /* Left DAC1 Analog/Digital Gain */
+       ad1843_LDA1GM = {  9, 15,  1 }, /* Left DAC1 Analog Mute */
+       ad1843_RDA2G  = { 10,  0,  6 }, /* Right DAC2 Analog/Digital Gain */
+       ad1843_RDA2GM = { 10,  7,  1 }, /* Right DAC2 Analog Mute */
+       ad1843_LDA2G  = { 10,  8,  6 }, /* Left DAC2 Analog/Digital Gain */
+       ad1843_LDA2GM = { 10, 15,  1 }, /* Left DAC2 Analog Mute */
+       ad1843_RDA1AM = { 11,  7,  1 }, /* Right DAC1 Digital Mute */
+       ad1843_LDA1AM = { 11, 15,  1 }, /* Left DAC1 Digital Mute */
+       ad1843_RDA2AM = { 12,  7,  1 }, /* Right DAC2 Digital Mute */
+       ad1843_LDA2AM = { 12, 15,  1 }, /* Left DAC2 Digital Mute */
+       ad1843_ADLC   = { 15,  0,  2 }, /* ADC Left Sample Rate Source */
+       ad1843_ADRC   = { 15,  2,  2 }, /* ADC Right Sample Rate Source */
+       ad1843_DA1C   = { 15,  8,  2 }, /* DAC1 Sample Rate Source */
+       ad1843_DA2C   = { 15, 10,  2 }, /* DAC2 Sample Rate Source */
+       ad1843_C1C    = { 17,  0, 16 }, /* Clock 1 Sample Rate Select */
+       ad1843_C2C    = { 20,  0, 16 }, /* Clock 2 Sample Rate Select */
+       ad1843_C3C    = { 23,  0, 16 }, /* Clock 3 Sample Rate Select */
+       ad1843_DAADL  = { 25,  4,  2 }, /* Digital ADC Left Source Select */
+       ad1843_DAADR  = { 25,  6,  2 }, /* Digital ADC Right Source Select */
+       ad1843_DAMIX  = { 25, 14,  1 }, /* DAC Digital Mix Enable */
+       ad1843_DRSFLT = { 25, 15,  1 }, /* Digital Reampler Filter Mode */
+       ad1843_ADLF   = { 26,  0,  2 }, /* ADC Left Channel Data Format */
+       ad1843_ADRF   = { 26,  2,  2 }, /* ADC Right Channel Data Format */
+       ad1843_ADTLK  = { 26,  4,  1 }, /* ADC Transmit Lock Mode Select */
+       ad1843_SCF    = { 26,  7,  1 }, /* SCLK Frequency Select */
+       ad1843_DA1F   = { 26,  8,  2 }, /* DAC1 Data Format Select */
+       ad1843_DA2F   = { 26, 10,  2 }, /* DAC2 Data Format Select */
+       ad1843_DA1SM  = { 26, 14,  1 }, /* DAC1 Stereo/Mono Mode Select */
+       ad1843_DA2SM  = { 26, 15,  1 }, /* DAC2 Stereo/Mono Mode Select */
+       ad1843_ADLEN  = { 27,  0,  1 }, /* ADC Left Channel Enable */
+       ad1843_ADREN  = { 27,  1,  1 }, /* ADC Right Channel Enable */
+       ad1843_AAMEN  = { 27,  4,  1 }, /* Analog to Analog Mix Enable */
+       ad1843_ANAEN  = { 27,  7,  1 }, /* Analog Channel Enable */
+       ad1843_DA1EN  = { 27,  8,  1 }, /* DAC1 Enable */
+       ad1843_DA2EN  = { 27,  9,  1 }, /* DAC2 Enable */
+       ad1843_DDMEN  = { 27, 12,  1 }, /* DAC2 to DAC1 Mix  Enable */
+       ad1843_C1EN   = { 28, 11,  1 }, /* Clock Generator 1 Enable */
+       ad1843_C2EN   = { 28, 12,  1 }, /* Clock Generator 2 Enable */
+       ad1843_C3EN   = { 28, 13,  1 }, /* Clock Generator 3 Enable */
+       ad1843_PDNI   = { 28, 15,  1 }; /* Converter Power Down */
+
+/*
+ * The various registers of the AD1843 use three different formats for
+ * specifying gain.  The ad1843_gain structure parameterizes the
+ * formats.
+ */
+
+struct ad1843_gain {
+       int     negative;               /* nonzero if gain is negative. */
+       const struct ad1843_bitfield *lfield;
+       const struct ad1843_bitfield *rfield;
+       const struct ad1843_bitfield *lmute;
+       const struct ad1843_bitfield *rmute;
+};
+
+static const struct ad1843_gain ad1843_gain_RECLEV = {
+       .negative = 0,
+       .lfield   = &ad1843_LIG,
+       .rfield   = &ad1843_RIG
+};
+static const struct ad1843_gain ad1843_gain_LINE = {
+       .negative = 1,
+       .lfield   = &ad1843_LX1M,
+       .rfield   = &ad1843_RX1M,
+       .lmute    = &ad1843_LX1MM,
+       .rmute    = &ad1843_RX1MM
+};
+static const struct ad1843_gain ad1843_gain_LINE_2 = {
+       .negative = 1,
+       .lfield   = &ad1843_LDA2G,
+       .rfield   = &ad1843_RDA2G,
+       .lmute    = &ad1843_LDA2GM,
+       .rmute    = &ad1843_RDA2GM
+};
+static const struct ad1843_gain ad1843_gain_MIC = {
+       .negative = 1,
+       .lfield   = &ad1843_LMCM,
+       .rfield   = &ad1843_RMCM,
+       .lmute    = &ad1843_LMCMM,
+       .rmute    = &ad1843_RMCMM
+};
+static const struct ad1843_gain ad1843_gain_PCM_0 = {
+       .negative = 1,
+       .lfield   = &ad1843_LDA1G,
+       .rfield   = &ad1843_RDA1G,
+       .lmute    = &ad1843_LDA1GM,
+       .rmute    = &ad1843_RDA1GM
+};
+static const struct ad1843_gain ad1843_gain_PCM_1 = {
+       .negative = 1,
+       .lfield   = &ad1843_LD2M,
+       .rfield   = &ad1843_RD2M,
+       .lmute    = &ad1843_LD2MM,
+       .rmute    = &ad1843_RD2MM
+};
+
+static const struct ad1843_gain *ad1843_gain[AD1843_GAIN_SIZE] =
+{
+       &ad1843_gain_RECLEV,
+       &ad1843_gain_LINE,
+       &ad1843_gain_LINE_2,
+       &ad1843_gain_MIC,
+       &ad1843_gain_PCM_0,
+       &ad1843_gain_PCM_1,
+};
+
+/* read the current value of an AD1843 bitfield. */
+
+static int ad1843_read_bits(struct snd_ad1843 *ad1843,
+                           const struct ad1843_bitfield *field)
+{
+       int w;
+
+       w = ad1843->read(ad1843->chip, field->reg);
+       return w >> field->lo_bit & ((1 << field->nbits) - 1);
+}
+
+/*
+ * write a new value to an AD1843 bitfield and return the old value.
+ */
+
+static int ad1843_write_bits(struct snd_ad1843 *ad1843,
+                            const struct ad1843_bitfield *field,
+                            int newval)
+{
+       int w, mask, oldval, newbits;
+
+       w = ad1843->read(ad1843->chip, field->reg);
+       mask = ((1 << field->nbits) - 1) << field->lo_bit;
+       oldval = (w & mask) >> field->lo_bit;
+       newbits = (newval << field->lo_bit) & mask;
+       w = (w & ~mask) | newbits;
+       ad1843->write(ad1843->chip, field->reg, w);
+
+       return oldval;
+}
+
+/*
+ * ad1843_read_multi reads multiple bitfields from the same AD1843
+ * register.  It uses a single read cycle to do it.  (Reading the
+ * ad1843 requires 256 bit times at 12.288 MHz, or nearly 20
+ * microseconds.)
+ *
+ * Called like this.
+ *
+ *  ad1843_read_multi(ad1843, nfields,
+ *                   &ad1843_FIELD1, &val1,
+ *                   &ad1843_FIELD2, &val2, ...);
+ */
+
+static void ad1843_read_multi(struct snd_ad1843 *ad1843, int argcount, ...)
+{
+       va_list ap;
+       const struct ad1843_bitfield *fp;
+       int w = 0, mask, *value, reg = -1;
+
+       va_start(ap, argcount);
+       while (--argcount >= 0) {
+               fp = va_arg(ap, const struct ad1843_bitfield *);
+               value = va_arg(ap, int *);
+               if (reg == -1) {
+                       reg = fp->reg;
+                       w = ad1843->read(ad1843->chip, reg);
+               }
+
+               mask = (1 << fp->nbits) - 1;
+               *value = w >> fp->lo_bit & mask;
+       }
+       va_end(ap);
+}
+
+/*
+ * ad1843_write_multi stores multiple bitfields into the same AD1843
+ * register.  It uses one read and one write cycle to do it.
+ *
+ * Called like this.
+ *
+ *  ad1843_write_multi(ad1843, nfields,
+ *                    &ad1843_FIELD1, val1,
+ *                    &ad1843_FIELF2, val2, ...);
+ */
+
+static void ad1843_write_multi(struct snd_ad1843 *ad1843, int argcount, ...)
+{
+       va_list ap;
+       int reg;
+       const struct ad1843_bitfield *fp;
+       int value;
+       int w, m, mask, bits;
+
+       mask = 0;
+       bits = 0;
+       reg = -1;
+
+       va_start(ap, argcount);
+       while (--argcount >= 0) {
+               fp = va_arg(ap, const struct ad1843_bitfield *);
+               value = va_arg(ap, int);
+               if (reg == -1)
+                       reg = fp->reg;
+               else
+                       BUG_ON(reg != fp->reg);
+               m = ((1 << fp->nbits) - 1) << fp->lo_bit;
+               mask |= m;
+               bits |= (value << fp->lo_bit) & m;
+       }
+       va_end(ap);
+
+       if (~mask & 0xFFFF)
+               w = ad1843->read(ad1843->chip, reg);
+       else
+               w = 0;
+       w = (w & ~mask) | bits;
+       ad1843->write(ad1843->chip, reg, w);
+}
+
+int ad1843_get_gain_max(struct snd_ad1843 *ad1843, int id)
+{
+       const struct ad1843_gain *gp = ad1843_gain[id];
+       int ret;
+
+       ret = (1 << gp->lfield->nbits);
+       if (!gp->lmute)
+               ret -= 1;
+       return ret;
+}
+
+/*
+ * ad1843_get_gain reads the specified register and extracts the gain value
+ * using the supplied gain type.
+ */
+
+int ad1843_get_gain(struct snd_ad1843 *ad1843, int id)
+{
+       int lg, rg, lm, rm;
+       const struct ad1843_gain *gp = ad1843_gain[id];
+       unsigned short mask = (1 << gp->lfield->nbits) - 1;
+
+       ad1843_read_multi(ad1843, 2, gp->lfield, &lg, gp->rfield, &rg);
+       if (gp->negative) {
+               lg = mask - lg;
+               rg = mask - rg;
+       }
+       if (gp->lmute) {
+               ad1843_read_multi(ad1843, 2, gp->lmute, &lm, gp->rmute, &rm);
+               if (lm)
+                       lg = 0;
+               if (rm)
+                       rg = 0;
+       }
+       return lg << 0 | rg << 8;
+}
+
+/*
+ * Set an audio channel's gain.
+ *
+ * Returns the new gain, which may be lower than the old gain.
+ */
+
+int ad1843_set_gain(struct snd_ad1843 *ad1843, int id, int newval)
+{
+       const struct ad1843_gain *gp = ad1843_gain[id];
+       unsigned short mask = (1 << gp->lfield->nbits) - 1;
+
+       int lg = (newval >> 0) & mask;
+       int rg = (newval >> 8) & mask;
+       int lm = (lg == 0) ? 1 : 0;
+       int rm = (rg == 0) ? 1 : 0;
+
+       if (gp->negative) {
+               lg = mask - lg;
+               rg = mask - rg;
+       }
+       if (gp->lmute)
+               ad1843_write_multi(ad1843, 2, gp->lmute, lm, gp->rmute, rm);
+       ad1843_write_multi(ad1843, 2, gp->lfield, lg, gp->rfield, rg);
+       return ad1843_get_gain(ad1843, id);
+}
+
+/* Returns the current recording source */
+
+int ad1843_get_recsrc(struct snd_ad1843 *ad1843)
+{
+       int val = ad1843_read_bits(ad1843, &ad1843_LSS);
+
+       if (val < 0 || val > 2) {
+               val = 2;
+               ad1843_write_multi(ad1843, 2,
+                                  &ad1843_LSS, val, &ad1843_RSS, val);
+       }
+       return val;
+}
+
+/*
+ * Set recording source.
+ *
+ * Returns newsrc on success, -errno on failure.
+ */
+
+int ad1843_set_recsrc(struct snd_ad1843 *ad1843, int newsrc)
+{
+       if (newsrc < 0 || newsrc > 2)
+               return -EINVAL;
+
+       ad1843_write_multi(ad1843, 2, &ad1843_LSS, newsrc, &ad1843_RSS, newsrc);
+       return newsrc;
+}
+
+/* Setup ad1843 for D/A conversion. */
+
+void ad1843_setup_dac(struct snd_ad1843 *ad1843,
+                     unsigned int id,
+                     unsigned int framerate,
+                     snd_pcm_format_t fmt,
+                     unsigned int channels)
+{
+       int ad_fmt = 0, ad_mode = 0;
+
+       switch (fmt) {
+       case SNDRV_PCM_FORMAT_S8:
+               ad_fmt = 0;
+               break;
+       case SNDRV_PCM_FORMAT_U8:
+               ad_fmt = 0;
+               break;
+       case SNDRV_PCM_FORMAT_S16_LE:
+               ad_fmt = 1;
+               break;
+       case SNDRV_PCM_FORMAT_MU_LAW:
+               ad_fmt = 2;
+               break;
+       case SNDRV_PCM_FORMAT_A_LAW:
+               ad_fmt = 3;
+               break;
+       default:
+               break;
+       }
+
+       switch (channels) {
+       case 2:
+               ad_mode = 0;
+               break;
+       case 1:
+               ad_mode = 1;
+               break;
+       default:
+               break;
+       }
+
+       if (id) {
+               ad1843_write_bits(ad1843, &ad1843_C2C, framerate);
+               ad1843_write_multi(ad1843, 2,
+                                  &ad1843_DA2SM, ad_mode,
+                                  &ad1843_DA2F, ad_fmt);
+       } else {
+               ad1843_write_bits(ad1843, &ad1843_C1C, framerate);
+               ad1843_write_multi(ad1843, 2,
+                                  &ad1843_DA1SM, ad_mode,
+                                  &ad1843_DA1F, ad_fmt);
+       }
+}
+
+void ad1843_shutdown_dac(struct snd_ad1843 *ad1843, unsigned int id)
+{
+       if (id)
+               ad1843_write_bits(ad1843, &ad1843_DA2F, 1);
+       else
+               ad1843_write_bits(ad1843, &ad1843_DA1F, 1);
+}
+
+void ad1843_setup_adc(struct snd_ad1843 *ad1843,
+                     unsigned int framerate,
+                     snd_pcm_format_t fmt,
+                     unsigned int channels)
+{
+       int da_fmt = 0;
+
+       switch (fmt) {
+       case SNDRV_PCM_FORMAT_S8:       da_fmt = 0; break;
+       case SNDRV_PCM_FORMAT_U8:       da_fmt = 0; break;
+       case SNDRV_PCM_FORMAT_S16_LE:   da_fmt = 1; break;
+       case SNDRV_PCM_FORMAT_MU_LAW:   da_fmt = 2; break;
+       case SNDRV_PCM_FORMAT_A_LAW:    da_fmt = 3; break;
+       default:                break;
+       }
+
+       ad1843_write_bits(ad1843, &ad1843_C3C, framerate);
+       ad1843_write_multi(ad1843, 2,
+                          &ad1843_ADLF, da_fmt, &ad1843_ADRF, da_fmt);
+}
+
+void ad1843_shutdown_adc(struct snd_ad1843 *ad1843)
+{
+       /* nothing to do */
+}
+
+/*
+ * Fully initialize the ad1843.  As described in the AD1843 data
+ * sheet, section "START-UP SEQUENCE".  The numbered comments are
+ * subsection headings from the data sheet.  See the data sheet, pages
+ * 52-54, for more info.
+ *
+ * return 0 on success, -errno on failure.  */
+
+int ad1843_init(struct snd_ad1843 *ad1843)
+{
+       unsigned long later;
+
+       if (ad1843_read_bits(ad1843, &ad1843_INIT) != 0) {
+               printk(KERN_ERR "ad1843: AD1843 won't initialize\n");
+               return -EIO;
+       }
+
+       ad1843_write_bits(ad1843, &ad1843_SCF, 1);
+
+       /* 4. Put the conversion resources into standby. */
+       ad1843_write_bits(ad1843, &ad1843_PDNI, 0);
+       later = jiffies + msecs_to_jiffies(500);
+
+       while (ad1843_read_bits(ad1843, &ad1843_PDNO)) {
+               if (time_after(jiffies, later)) {
+                       printk(KERN_ERR
+                              "ad1843: AD1843 won't power up\n");
+                       return -EIO;
+               }
+               schedule_timeout_interruptible(5);
+       }
+
+       /* 5. Power up the clock generators and enable clock output pins. */
+       ad1843_write_multi(ad1843, 3,
+                          &ad1843_C1EN, 1,
+                          &ad1843_C2EN, 1,
+                          &ad1843_C3EN, 1);
+
+       /* 6. Configure conversion resources while they are in standby. */
+
+       /* DAC1/2 use clock 1/2 as source, ADC uses clock 3.  Always. */
+       ad1843_write_multi(ad1843, 4,
+                          &ad1843_DA1C, 1,
+                          &ad1843_DA2C, 2,
+                          &ad1843_ADLC, 3,
+                          &ad1843_ADRC, 3);
+
+       /* 7. Enable conversion resources. */
+       ad1843_write_bits(ad1843, &ad1843_ADTLK, 1);
+       ad1843_write_multi(ad1843, 7,
+                          &ad1843_ANAEN, 1,
+                          &ad1843_AAMEN, 1,
+                          &ad1843_DA1EN, 1,
+                          &ad1843_DA2EN, 1,
+                          &ad1843_DDMEN, 1,
+                          &ad1843_ADLEN, 1,
+                          &ad1843_ADREN, 1);
+
+       /* 8. Configure conversion resources while they are enabled. */
+
+       /* set gain to 0 for all channels */
+       ad1843_set_gain(ad1843, AD1843_GAIN_RECLEV, 0);
+       ad1843_set_gain(ad1843, AD1843_GAIN_LINE, 0);
+       ad1843_set_gain(ad1843, AD1843_GAIN_LINE_2, 0);
+       ad1843_set_gain(ad1843, AD1843_GAIN_MIC, 0);
+       ad1843_set_gain(ad1843, AD1843_GAIN_PCM_0, 0);
+       ad1843_set_gain(ad1843, AD1843_GAIN_PCM_1, 0);
+
+       /* Unmute all channels. */
+       /* DAC1 */
+       ad1843_write_multi(ad1843, 2, &ad1843_LDA1GM, 0, &ad1843_RDA1GM, 0);
+       /* DAC2 */
+       ad1843_write_multi(ad1843, 2, &ad1843_LDA2GM, 0, &ad1843_RDA2GM, 0);
+
+       /* Set default recording source to Line In and set
+        * mic gain to +20 dB.
+        */
+       ad1843_set_recsrc(ad1843, 2);
+       ad1843_write_multi(ad1843, 2, &ad1843_LMGE, 1, &ad1843_RMGE, 1);
+
+       /* Set Speaker Out level to +/- 4V and unmute it. */
+       ad1843_write_multi(ad1843, 3,
+                          &ad1843_HPOS, 1,
+                          &ad1843_HPOM, 0,
+                          &ad1843_MPOM, 0);
+
+       return 0;
+}
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
new file mode 100644 (file)
index 0000000..db495be
--- /dev/null
@@ -0,0 +1,947 @@
+/*
+ *  Driver for A2 audio system used in SGI machines
+ *  Copyright (c) 2008 Thomas Bogendoerfer <tsbogend@alpha.fanken.de>
+ *
+ *  Based on OSS code from Ladislav Michl <ladis@linux-mips.org>, which
+ *  was based on code from Ulf Carlsson
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+#include <asm/sgi/hpc3.h>
+#include <asm/sgi/ip22.h>
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/pcm-indirect.h>
+#include <sound/initval.h>
+
+#include "hal2.h"
+
+static int index = SNDRV_DEFAULT_IDX1;  /* Index 0-MAX */
+static char *id = SNDRV_DEFAULT_STR1;   /* ID for this card */
+
+module_param(index, int, 0444);
+MODULE_PARM_DESC(index, "Index value for SGI HAL2 soundcard.");
+module_param(id, charp, 0444);
+MODULE_PARM_DESC(id, "ID string for SGI HAL2 soundcard.");
+MODULE_DESCRIPTION("ALSA driver for SGI HAL2 audio");
+MODULE_AUTHOR("Thomas Bogendoerfer");
+MODULE_LICENSE("GPL");
+
+
+#define H2_BLOCK_SIZE  1024
+#define H2_BUF_SIZE    16384
+
+struct hal2_pbus {
+       struct hpc3_pbus_dmacregs *pbus;
+       int pbusnr;
+       unsigned int ctrl;              /* Current state of pbus->pbdma_ctrl */
+};
+
+struct hal2_desc {
+       struct hpc_dma_desc desc;
+       u32 pad;                        /* padding */
+};
+
+struct hal2_codec {
+       struct snd_pcm_indirect pcm_indirect;
+       struct snd_pcm_substream *substream;
+
+       unsigned char *buffer;
+       dma_addr_t buffer_dma;
+       struct hal2_desc *desc;
+       dma_addr_t desc_dma;
+       int desc_count;
+       struct hal2_pbus pbus;
+       int voices;                     /* mono/stereo */
+       unsigned int sample_rate;
+       unsigned int master;            /* Master frequency */
+       unsigned short mod;             /* MOD value */
+       unsigned short inc;             /* INC value */
+};
+
+#define H2_MIX_OUTPUT_ATT      0
+#define H2_MIX_INPUT_GAIN      1
+
+struct snd_hal2 {
+       struct snd_card *card;
+
+       struct hal2_ctl_regs *ctl_regs; /* HAL2 ctl registers */
+       struct hal2_aes_regs *aes_regs; /* HAL2 aes registers */
+       struct hal2_vol_regs *vol_regs; /* HAL2 vol registers */
+       struct hal2_syn_regs *syn_regs; /* HAL2 syn registers */
+
+       struct hal2_codec dac;
+       struct hal2_codec adc;
+};
+
+#define H2_INDIRECT_WAIT(regs) while (hal2_read(&regs->isr) & H2_ISR_TSTATUS);
+
+#define H2_READ_ADDR(addr)     (addr | (1<<7))
+#define H2_WRITE_ADDR(addr)    (addr)
+
+static inline u32 hal2_read(u32 *reg)
+{
+       return __raw_readl(reg);
+}
+
+static inline void hal2_write(u32 val, u32 *reg)
+{
+       __raw_writel(val, reg);
+}
+
+
+static u32 hal2_i_read32(struct snd_hal2 *hal2, u16 addr)
+{
+       u32 ret;
+       struct hal2_ctl_regs *regs = hal2->ctl_regs;
+
+       hal2_write(H2_READ_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+       ret = hal2_read(&regs->idr0) & 0xffff;
+       hal2_write(H2_READ_ADDR(addr) | 0x1, &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+       ret |= (hal2_read(&regs->idr0) & 0xffff) << 16;
+       return ret;
+}
+
+static void hal2_i_write16(struct snd_hal2 *hal2, u16 addr, u16 val)
+{
+       struct hal2_ctl_regs *regs = hal2->ctl_regs;
+
+       hal2_write(val, &regs->idr0);
+       hal2_write(0, &regs->idr1);
+       hal2_write(0, &regs->idr2);
+       hal2_write(0, &regs->idr3);
+       hal2_write(H2_WRITE_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+}
+
+static void hal2_i_write32(struct snd_hal2 *hal2, u16 addr, u32 val)
+{
+       struct hal2_ctl_regs *regs = hal2->ctl_regs;
+
+       hal2_write(val & 0xffff, &regs->idr0);
+       hal2_write(val >> 16, &regs->idr1);
+       hal2_write(0, &regs->idr2);
+       hal2_write(0, &regs->idr3);
+       hal2_write(H2_WRITE_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+}
+
+static void hal2_i_setbit16(struct snd_hal2 *hal2, u16 addr, u16 bit)
+{
+       struct hal2_ctl_regs *regs = hal2->ctl_regs;
+
+       hal2_write(H2_READ_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+       hal2_write((hal2_read(&regs->idr0) & 0xffff) | bit, &regs->idr0);
+       hal2_write(0, &regs->idr1);
+       hal2_write(0, &regs->idr2);
+       hal2_write(0, &regs->idr3);
+       hal2_write(H2_WRITE_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+}
+
+static void hal2_i_clearbit16(struct snd_hal2 *hal2, u16 addr, u16 bit)
+{
+       struct hal2_ctl_regs *regs = hal2->ctl_regs;
+
+       hal2_write(H2_READ_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+       hal2_write((hal2_read(&regs->idr0) & 0xffff) & ~bit, &regs->idr0);
+       hal2_write(0, &regs->idr1);
+       hal2_write(0, &regs->idr2);
+       hal2_write(0, &regs->idr3);
+       hal2_write(H2_WRITE_ADDR(addr), &regs->iar);
+       H2_INDIRECT_WAIT(regs);
+}
+
+static int hal2_gain_info(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       switch ((int)kcontrol->private_value) {
+       case H2_MIX_OUTPUT_ATT:
+               uinfo->value.integer.max = 31;
+               break;
+       case H2_MIX_INPUT_GAIN:
+               uinfo->value.integer.max = 15;
+               break;
+       }
+       return 0;
+}
+
+static int hal2_gain_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_hal2 *hal2 = snd_kcontrol_chip(kcontrol);
+       u32 tmp;
+       int l, r;
+
+       switch ((int)kcontrol->private_value) {
+       case H2_MIX_OUTPUT_ATT:
+               tmp = hal2_i_read32(hal2, H2I_DAC_C2);
+               if (tmp & H2I_C2_MUTE) {
+                       l = 0;
+                       r = 0;
+               } else {
+                       l = 31 - ((tmp >> H2I_C2_L_ATT_SHIFT) & 31);
+                       r = 31 - ((tmp >> H2I_C2_R_ATT_SHIFT) & 31);
+               }
+               break;
+       case H2_MIX_INPUT_GAIN:
+               tmp = hal2_i_read32(hal2, H2I_ADC_C2);
+               l = (tmp >> H2I_C2_L_GAIN_SHIFT) & 15;
+               r = (tmp >> H2I_C2_R_GAIN_SHIFT) & 15;
+               break;
+       }
+       ucontrol->value.integer.value[0] = l;
+       ucontrol->value.integer.value[1] = r;
+
+       return 0;
+}
+
+static int hal2_gain_put(struct snd_kcontrol *kcontrol,
+                        struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_hal2 *hal2 = snd_kcontrol_chip(kcontrol);
+       u32 old, new;
+       int l, r;
+
+       l = ucontrol->value.integer.value[0];
+       r = ucontrol->value.integer.value[1];
+
+       switch ((int)kcontrol->private_value) {
+       case H2_MIX_OUTPUT_ATT:
+               old = hal2_i_read32(hal2, H2I_DAC_C2);
+               new = old & ~(H2I_C2_L_ATT_M | H2I_C2_R_ATT_M | H2I_C2_MUTE);
+               if (l | r) {
+                       l = 31 - l;
+                       r = 31 - r;
+                       new |= (l << H2I_C2_L_ATT_SHIFT);
+                       new |= (r << H2I_C2_R_ATT_SHIFT);
+               } else
+                       new |= H2I_C2_L_ATT_M | H2I_C2_R_ATT_M | H2I_C2_MUTE;
+               hal2_i_write32(hal2, H2I_DAC_C2, new);
+               break;
+       case H2_MIX_INPUT_GAIN:
+               old = hal2_i_read32(hal2, H2I_ADC_C2);
+               new = old & ~(H2I_C2_L_GAIN_M | H2I_C2_R_GAIN_M);
+               new |= (l << H2I_C2_L_GAIN_SHIFT);
+               new |= (r << H2I_C2_R_GAIN_SHIFT);
+               hal2_i_write32(hal2, H2I_ADC_C2, new);
+               break;
+       }
+       return old != new;
+}
+
+static struct snd_kcontrol_new hal2_ctrl_headphone __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Headphone Playback Volume",
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = H2_MIX_OUTPUT_ATT,
+       .info           = hal2_gain_info,
+       .get            = hal2_gain_get,
+       .put            = hal2_gain_put,
+};
+
+static struct snd_kcontrol_new hal2_ctrl_mic __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Mic Capture Volume",
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = H2_MIX_INPUT_GAIN,
+       .info           = hal2_gain_info,
+       .get            = hal2_gain_get,
+       .put            = hal2_gain_put,
+};
+
+static int __devinit hal2_mixer_create(struct snd_hal2 *hal2)
+{
+       int err;
+
+       /* mute DAC */
+       hal2_i_write32(hal2, H2I_DAC_C2,
+                      H2I_C2_L_ATT_M | H2I_C2_R_ATT_M | H2I_C2_MUTE);
+       /* mute ADC */
+       hal2_i_write32(hal2, H2I_ADC_C2, 0);
+
+       err = snd_ctl_add(hal2->card,
+                         snd_ctl_new1(&hal2_ctrl_headphone, hal2));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(hal2->card,
+                         snd_ctl_new1(&hal2_ctrl_mic, hal2));
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+static irqreturn_t hal2_interrupt(int irq, void *dev_id)
+{
+       struct snd_hal2 *hal2 = dev_id;
+       irqreturn_t ret = IRQ_NONE;
+
+       /* decide what caused this interrupt */
+       if (hal2->dac.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
+               snd_pcm_period_elapsed(hal2->dac.substream);
+               ret = IRQ_HANDLED;
+       }
+       if (hal2->adc.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
+               snd_pcm_period_elapsed(hal2->adc.substream);
+               ret = IRQ_HANDLED;
+       }
+       return ret;
+}
+
+static int hal2_compute_rate(struct hal2_codec *codec, unsigned int rate)
+{
+       unsigned short mod;
+
+       if (44100 % rate < 48000 % rate) {
+               mod = 4 * 44100 / rate;
+               codec->master = 44100;
+       } else {
+               mod = 4 * 48000 / rate;
+               codec->master = 48000;
+       }
+
+       codec->inc = 4;
+       codec->mod = mod;
+       rate = 4 * codec->master / mod;
+
+       return rate;
+}
+
+static void hal2_set_dac_rate(struct snd_hal2 *hal2)
+{
+       unsigned int master = hal2->dac.master;
+       int inc = hal2->dac.inc;
+       int mod = hal2->dac.mod;
+
+       hal2_i_write16(hal2, H2I_BRES1_C1, (master == 44100) ? 1 : 0);
+       hal2_i_write32(hal2, H2I_BRES1_C2,
+                      ((0xffff & (inc - mod - 1)) << 16) | inc);
+}
+
+static void hal2_set_adc_rate(struct snd_hal2 *hal2)
+{
+       unsigned int master = hal2->adc.master;
+       int inc = hal2->adc.inc;
+       int mod = hal2->adc.mod;
+
+       hal2_i_write16(hal2, H2I_BRES2_C1, (master == 44100) ? 1 : 0);
+       hal2_i_write32(hal2, H2I_BRES2_C2,
+                      ((0xffff & (inc - mod - 1)) << 16) | inc);
+}
+
+static void hal2_setup_dac(struct snd_hal2 *hal2)
+{
+       unsigned int fifobeg, fifoend, highwater, sample_size;
+       struct hal2_pbus *pbus = &hal2->dac.pbus;
+
+       /* Now we set up some PBUS information. The PBUS needs information about
+        * what portion of the fifo it will use. If it's receiving or
+        * transmitting, and finally whether the stream is little endian or big
+        * endian. The information is written later, on the start call.
+        */
+       sample_size = 2 * hal2->dac.voices;
+       /* Fifo should be set to hold exactly four samples. Highwater mark
+        * should be set to two samples. */
+       highwater = (sample_size * 2) >> 1;     /* halfwords */
+       fifobeg = 0;                            /* playback is first */
+       fifoend = (sample_size * 4) >> 3;       /* doublewords */
+       pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_LD |
+                    (highwater << 8) | (fifobeg << 16) | (fifoend << 24);
+       /* We disable everything before we do anything at all */
+       pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
+       hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
+       /* Setup the HAL2 for playback */
+       hal2_set_dac_rate(hal2);
+       /* Set endianess */
+       hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECTX);
+       /* Set DMA bus */
+       hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
+       /* We are using 1st Bresenham clock generator for playback */
+       hal2_i_write16(hal2, H2I_DAC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
+                       | (1 << H2I_C1_CLKID_SHIFT)
+                       | (hal2->dac.voices << H2I_C1_DATAT_SHIFT));
+}
+
+static void hal2_setup_adc(struct snd_hal2 *hal2)
+{
+       unsigned int fifobeg, fifoend, highwater, sample_size;
+       struct hal2_pbus *pbus = &hal2->adc.pbus;
+
+       sample_size = 2 * hal2->adc.voices;
+       highwater = (sample_size * 2) >> 1;             /* halfwords */
+       fifobeg = (4 * 4) >> 3;                         /* record is second */
+       fifoend = (4 * 4 + sample_size * 4) >> 3;       /* doublewords */
+       pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_RCV | HPC3_PDMACTRL_LD |
+                    (highwater << 8) | (fifobeg << 16) | (fifoend << 24);
+       pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
+       hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
+       /* Setup the HAL2 for record */
+       hal2_set_adc_rate(hal2);
+       /* Set endianess */
+       hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECR);
+       /* Set DMA bus */
+       hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
+       /* We are using 2nd Bresenham clock generator for record */
+       hal2_i_write16(hal2, H2I_ADC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
+                       | (2 << H2I_C1_CLKID_SHIFT)
+                       | (hal2->adc.voices << H2I_C1_DATAT_SHIFT));
+}
+
+static void hal2_start_dac(struct snd_hal2 *hal2)
+{
+       struct hal2_pbus *pbus = &hal2->dac.pbus;
+
+       pbus->pbus->pbdma_dptr = hal2->dac.desc_dma;
+       pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT;
+       /* enable DAC */
+       hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
+}
+
+static void hal2_start_adc(struct snd_hal2 *hal2)
+{
+       struct hal2_pbus *pbus = &hal2->adc.pbus;
+
+       pbus->pbus->pbdma_dptr = hal2->adc.desc_dma;
+       pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT;
+       /* enable ADC */
+       hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
+}
+
+static inline void hal2_stop_dac(struct snd_hal2 *hal2)
+{
+       hal2->dac.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
+       /* The HAL2 itself may remain enabled safely */
+}
+
+static inline void hal2_stop_adc(struct snd_hal2 *hal2)
+{
+       hal2->adc.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
+}
+
+static int hal2_alloc_dmabuf(struct hal2_codec *codec)
+{
+       struct hal2_desc *desc;
+       dma_addr_t desc_dma, buffer_dma;
+       int count = H2_BUF_SIZE / H2_BLOCK_SIZE;
+       int i;
+
+       codec->buffer = dma_alloc_noncoherent(NULL, H2_BUF_SIZE,
+                                             &buffer_dma, GFP_KERNEL);
+       if (!codec->buffer)
+               return -ENOMEM;
+       desc = dma_alloc_noncoherent(NULL, count * sizeof(struct hal2_desc),
+                                    &desc_dma, GFP_KERNEL);
+       if (!desc) {
+               dma_free_noncoherent(NULL, H2_BUF_SIZE,
+                                    codec->buffer, buffer_dma);
+               return -ENOMEM;
+       }
+       codec->buffer_dma = buffer_dma;
+       codec->desc_dma = desc_dma;
+       codec->desc = desc;
+       for (i = 0; i < count; i++) {
+               desc->desc.pbuf = buffer_dma + i * H2_BLOCK_SIZE;
+               desc->desc.cntinfo = HPCDMA_XIE | H2_BLOCK_SIZE;
+               desc->desc.pnext = (i == count - 1) ?
+                     desc_dma : desc_dma + (i + 1) * sizeof(struct hal2_desc);
+               desc++;
+       }
+       dma_cache_sync(NULL, codec->desc, count * sizeof(struct hal2_desc),
+                      DMA_TO_DEVICE);
+       codec->desc_count = count;
+       return 0;
+}
+
+static void hal2_free_dmabuf(struct hal2_codec *codec)
+{
+       dma_free_noncoherent(NULL, codec->desc_count * sizeof(struct hal2_desc),
+                            codec->desc, codec->desc_dma);
+       dma_free_noncoherent(NULL, H2_BUF_SIZE, codec->buffer,
+                            codec->buffer_dma);
+}
+
+static struct snd_pcm_hardware hal2_pcm_hw = {
+       .info = (SNDRV_PCM_INFO_MMAP |
+                SNDRV_PCM_INFO_MMAP_VALID |
+                SNDRV_PCM_INFO_INTERLEAVED |
+                SNDRV_PCM_INFO_BLOCK_TRANSFER),
+       .formats =          SNDRV_PCM_FMTBIT_S16_BE,
+       .rates =            SNDRV_PCM_RATE_8000_48000,
+       .rate_min =         8000,
+       .rate_max =         48000,
+       .channels_min =     2,
+       .channels_max =     2,
+       .buffer_bytes_max = 65536,
+       .period_bytes_min = 1024,
+       .period_bytes_max = 65536,
+       .periods_min =      2,
+       .periods_max =      1024,
+};
+
+static int hal2_pcm_hw_params(struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *params)
+{
+       int err;
+
+       err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+static int hal2_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       return snd_pcm_lib_free_pages(substream);
+}
+
+static int hal2_playback_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       int err;
+
+       runtime->hw = hal2_pcm_hw;
+
+       err = hal2_alloc_dmabuf(&hal2->dac);
+       if (err)
+               return err;
+       return 0;
+}
+
+static int hal2_playback_close(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+
+       hal2_free_dmabuf(&hal2->dac);
+       return 0;
+}
+
+static int hal2_playback_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct hal2_codec *dac = &hal2->dac;
+
+       dac->voices = runtime->channels;
+       dac->sample_rate = hal2_compute_rate(dac, runtime->rate);
+       memset(&dac->pcm_indirect, 0, sizeof(dac->pcm_indirect));
+       dac->pcm_indirect.hw_buffer_size = H2_BUF_SIZE;
+       dac->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
+       dac->substream = substream;
+       hal2_setup_dac(hal2);
+       return 0;
+}
+
+static int hal2_playback_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               hal2->dac.pcm_indirect.hw_io = hal2->dac.buffer_dma;
+               hal2->dac.pcm_indirect.hw_data = 0;
+               substream->ops->ack(substream);
+               hal2_start_dac(hal2);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               hal2_stop_dac(hal2);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static snd_pcm_uframes_t
+hal2_playback_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct hal2_codec *dac = &hal2->dac;
+
+       return snd_pcm_indirect_playback_pointer(substream, &dac->pcm_indirect,
+                                                dac->pbus.pbus->pbdma_bptr);
+}
+
+static void hal2_playback_transfer(struct snd_pcm_substream *substream,
+                                  struct snd_pcm_indirect *rec, size_t bytes)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       unsigned char *buf = hal2->dac.buffer + rec->hw_data;
+
+       memcpy(buf, substream->runtime->dma_area + rec->sw_data, bytes);
+       dma_cache_sync(NULL, buf, bytes, DMA_TO_DEVICE);
+
+}
+
+static int hal2_playback_ack(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct hal2_codec *dac = &hal2->dac;
+
+       dac->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2;
+       snd_pcm_indirect_playback_transfer(substream,
+                                          &dac->pcm_indirect,
+                                          hal2_playback_transfer);
+       return 0;
+}
+
+static int hal2_capture_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct hal2_codec *adc = &hal2->adc;
+       int err;
+
+       runtime->hw = hal2_pcm_hw;
+
+       err = hal2_alloc_dmabuf(adc);
+       if (err)
+               return err;
+       return 0;
+}
+
+static int hal2_capture_close(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+
+       hal2_free_dmabuf(&hal2->adc);
+       return 0;
+}
+
+static int hal2_capture_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct hal2_codec *adc = &hal2->adc;
+
+       adc->voices = runtime->channels;
+       adc->sample_rate = hal2_compute_rate(adc, runtime->rate);
+       memset(&adc->pcm_indirect, 0, sizeof(adc->pcm_indirect));
+       adc->pcm_indirect.hw_buffer_size = H2_BUF_SIZE;
+       adc->pcm_indirect.hw_queue_size = H2_BUF_SIZE / 2;
+       adc->pcm_indirect.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
+       adc->substream = substream;
+       hal2_setup_adc(hal2);
+       return 0;
+}
+
+static int hal2_capture_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               hal2->adc.pcm_indirect.hw_io = hal2->adc.buffer_dma;
+               hal2->adc.pcm_indirect.hw_data = 0;
+               printk(KERN_DEBUG "buffer_dma %x\n", hal2->adc.buffer_dma);
+               hal2_start_adc(hal2);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               hal2_stop_adc(hal2);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static snd_pcm_uframes_t
+hal2_capture_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct hal2_codec *adc = &hal2->adc;
+
+       return snd_pcm_indirect_capture_pointer(substream, &adc->pcm_indirect,
+                                               adc->pbus.pbus->pbdma_bptr);
+}
+
+static void hal2_capture_transfer(struct snd_pcm_substream *substream,
+                                 struct snd_pcm_indirect *rec, size_t bytes)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       unsigned char *buf = hal2->adc.buffer + rec->hw_data;
+
+       dma_cache_sync(NULL, buf, bytes, DMA_FROM_DEVICE);
+       memcpy(substream->runtime->dma_area + rec->sw_data, buf, bytes);
+}
+
+static int hal2_capture_ack(struct snd_pcm_substream *substream)
+{
+       struct snd_hal2 *hal2 = snd_pcm_substream_chip(substream);
+       struct hal2_codec *adc = &hal2->adc;
+
+       snd_pcm_indirect_capture_transfer(substream,
+                                         &adc->pcm_indirect,
+                                         hal2_capture_transfer);
+       return 0;
+}
+
+static struct snd_pcm_ops hal2_playback_ops = {
+       .open =        hal2_playback_open,
+       .close =       hal2_playback_close,
+       .ioctl =       snd_pcm_lib_ioctl,
+       .hw_params =   hal2_pcm_hw_params,
+       .hw_free =     hal2_pcm_hw_free,
+       .prepare =     hal2_playback_prepare,
+       .trigger =     hal2_playback_trigger,
+       .pointer =     hal2_playback_pointer,
+       .ack =         hal2_playback_ack,
+};
+
+static struct snd_pcm_ops hal2_capture_ops = {
+       .open =        hal2_capture_open,
+       .close =       hal2_capture_close,
+       .ioctl =       snd_pcm_lib_ioctl,
+       .hw_params =   hal2_pcm_hw_params,
+       .hw_free =     hal2_pcm_hw_free,
+       .prepare =     hal2_capture_prepare,
+       .trigger =     hal2_capture_trigger,
+       .pointer =     hal2_capture_pointer,
+       .ack =         hal2_capture_ack,
+};
+
+static int __devinit hal2_pcm_create(struct snd_hal2 *hal2)
+{
+       struct snd_pcm *pcm;
+       int err;
+
+       /* create first pcm device with one outputs and one input */
+       err = snd_pcm_new(hal2->card, "SGI HAL2 Audio", 0, 1, 1, &pcm);
+       if (err < 0)
+               return err;
+
+       pcm->private_data = hal2;
+       strcpy(pcm->name, "SGI HAL2");
+
+       /* set operators */
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                       &hal2_playback_ops);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+                       &hal2_capture_ops);
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
+                                          snd_dma_continuous_data(GFP_KERNEL),
+                                          0, 1024 * 1024);
+
+       return 0;
+}
+
+static int hal2_dev_free(struct snd_device *device)
+{
+       struct snd_hal2 *hal2 = device->device_data;
+
+       free_irq(SGI_HPCDMA_IRQ, hal2);
+       kfree(hal2);
+       return 0;
+}
+
+static struct snd_device_ops hal2_ops = {
+       .dev_free = hal2_dev_free,
+};
+
+static void hal2_init_codec(struct hal2_codec *codec, struct hpc3_regs *hpc3,
+                           int index)
+{
+       codec->pbus.pbusnr = index;
+       codec->pbus.pbus = &hpc3->pbdma[index];
+}
+
+static int hal2_detect(struct snd_hal2 *hal2)
+{
+       unsigned short board, major, minor;
+       unsigned short rev;
+
+       /* reset HAL2 */
+       hal2_write(0, &hal2->ctl_regs->isr);
+
+       /* release reset */
+       hal2_write(H2_ISR_GLOBAL_RESET_N | H2_ISR_CODEC_RESET_N,
+                  &hal2->ctl_regs->isr);
+
+
+       hal2_i_write16(hal2, H2I_RELAY_C, H2I_RELAY_C_STATE);
+       rev = hal2_read(&hal2->ctl_regs->rev);
+       if (rev & H2_REV_AUDIO_PRESENT)
+               return -ENODEV;
+
+       board = (rev & H2_REV_BOARD_M) >> 12;
+       major = (rev & H2_REV_MAJOR_CHIP_M) >> 4;
+       minor = (rev & H2_REV_MINOR_CHIP_M);
+
+       printk(KERN_INFO "SGI HAL2 revision %i.%i.%i\n",
+              board, major, minor);
+
+       return 0;
+}
+
+static int hal2_create(struct snd_card *card, struct snd_hal2 **rchip)
+{
+       struct snd_hal2 *hal2;
+       struct hpc3_regs *hpc3 = hpc3c0;
+       int err;
+
+       hal2 = kzalloc(sizeof(struct snd_hal2), GFP_KERNEL);
+       if (!hal2)
+               return -ENOMEM;
+
+       hal2->card = card;
+
+       if (request_irq(SGI_HPCDMA_IRQ, hal2_interrupt, IRQF_SHARED,
+                       "SGI HAL2", hal2)) {
+               printk(KERN_ERR "HAL2: Can't get irq %d\n", SGI_HPCDMA_IRQ);
+               kfree(hal2);
+               return -EAGAIN;
+       }
+
+       hal2->ctl_regs = (struct hal2_ctl_regs *)hpc3->pbus_extregs[0];
+       hal2->aes_regs = (struct hal2_aes_regs *)hpc3->pbus_extregs[1];
+       hal2->vol_regs = (struct hal2_vol_regs *)hpc3->pbus_extregs[2];
+       hal2->syn_regs = (struct hal2_syn_regs *)hpc3->pbus_extregs[3];
+
+       if (hal2_detect(hal2) < 0) {
+               kfree(hal2);
+               return -ENODEV;
+       }
+
+       hal2_init_codec(&hal2->dac, hpc3, 0);
+       hal2_init_codec(&hal2->adc, hpc3, 1);
+
+       /*
+        * All DMA channel interfaces in HAL2 are designed to operate with
+        * PBUS programmed for 2 cycles in D3, 2 cycles in D4 and 2 cycles
+        * in D5. HAL2 is a 16-bit device which can accept both big and little
+        * endian format. It assumes that even address bytes are on high
+        * portion of PBUS (15:8) and assumes that HPC3 is programmed to
+        * accept a live (unsynchronized) version of P_DREQ_N from HAL2.
+        */
+#define HAL2_PBUS_DMACFG ((0 << HPC3_DMACFG_D3R_SHIFT) | \
+                         (2 << HPC3_DMACFG_D4R_SHIFT) | \
+                         (2 << HPC3_DMACFG_D5R_SHIFT) | \
+                         (0 << HPC3_DMACFG_D3W_SHIFT) | \
+                         (2 << HPC3_DMACFG_D4W_SHIFT) | \
+                         (2 << HPC3_DMACFG_D5W_SHIFT) | \
+                               HPC3_DMACFG_DS16 | \
+                               HPC3_DMACFG_EVENHI | \
+                               HPC3_DMACFG_RTIME | \
+                         (8 << HPC3_DMACFG_BURST_SHIFT) | \
+                               HPC3_DMACFG_DRQLIVE)
+       /*
+        * Ignore what's mentioned in the specification and write value which
+        * works in The Real World (TM)
+        */
+       hpc3->pbus_dmacfg[hal2->dac.pbus.pbusnr][0] = 0x8208844;
+       hpc3->pbus_dmacfg[hal2->adc.pbus.pbusnr][0] = 0x8208844;
+
+       err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, hal2, &hal2_ops);
+       if (err < 0) {
+               free_irq(SGI_HPCDMA_IRQ, hal2);
+               kfree(hal2);
+               return err;
+       }
+       *rchip = hal2;
+       return 0;
+}
+
+static int __devinit hal2_probe(struct platform_device *pdev)
+{
+       struct snd_card *card;
+       struct snd_hal2 *chip;
+       int err;
+
+       card = snd_card_new(index, id, THIS_MODULE, 0);
+       if (card == NULL)
+               return -ENOMEM;
+
+       err = hal2_create(card, &chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       snd_card_set_dev(card, &pdev->dev);
+
+       err = hal2_pcm_create(chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       err = hal2_mixer_create(chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+
+       strcpy(card->driver, "SGI HAL2 Audio");
+       strcpy(card->shortname, "SGI HAL2 Audio");
+       sprintf(card->longname, "%s irq %i",
+               card->shortname,
+               SGI_HPCDMA_IRQ);
+
+       err = snd_card_register(card);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       platform_set_drvdata(pdev, card);
+       return 0;
+}
+
+static int __exit hal2_remove(struct platform_device *pdev)
+{
+       struct snd_card *card = platform_get_drvdata(pdev);
+
+       snd_card_free(card);
+       platform_set_drvdata(pdev, NULL);
+       return 0;
+}
+
+static struct platform_driver hal2_driver = {
+       .probe  = hal2_probe,
+       .remove = __devexit_p(hal2_remove),
+       .driver = {
+               .name   = "sgihal2",
+               .owner  = THIS_MODULE,
+       }
+};
+
+static int __init alsa_card_hal2_init(void)
+{
+       return platform_driver_register(&hal2_driver);
+}
+
+static void __exit alsa_card_hal2_exit(void)
+{
+       platform_driver_unregister(&hal2_driver);
+}
+
+module_init(alsa_card_hal2_init);
+module_exit(alsa_card_hal2_exit);
diff --git a/sound/mips/hal2.h b/sound/mips/hal2.h
new file mode 100644 (file)
index 0000000..f19828b
--- /dev/null
@@ -0,0 +1,245 @@
+#ifndef __HAL2_H
+#define __HAL2_H
+
+/*
+ *  Driver for HAL2 sound processors
+ *  Copyright (c) 1999 Ulf Carlsson <ulfc@bun.falkenberg.se>
+ *  Copyright (c) 2001, 2002, 2003 Ladislav Michl <ladis@linux-mips.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/types.h>
+
+/* Indirect status register */
+
+#define H2_ISR_TSTATUS         0x01    /* RO: transaction status 1=busy */
+#define H2_ISR_USTATUS         0x02    /* RO: utime status bit 1=armed */
+#define H2_ISR_QUAD_MODE       0x04    /* codec mode 0=indigo 1=quad */
+#define H2_ISR_GLOBAL_RESET_N  0x08    /* chip global reset 0=reset */
+#define H2_ISR_CODEC_RESET_N   0x10    /* codec/synth reset 0=reset  */
+
+/* Revision register */
+
+#define H2_REV_AUDIO_PRESENT   0x8000  /* RO: audio present 0=present */
+#define H2_REV_BOARD_M         0x7000  /* RO: bits 14:12, board revision */
+#define H2_REV_MAJOR_CHIP_M    0x00F0  /* RO: bits 7:4, major chip revision */
+#define H2_REV_MINOR_CHIP_M    0x000F  /* RO: bits 3:0, minor chip revision */
+
+/* Indirect address register */
+
+/*
+ * Address of indirect internal register to be accessed. A write to this
+ * register initiates read or write access to the indirect registers in the
+ * HAL2. Note that there af four indirect data registers for write access to
+ * registers larger than 16 byte.
+ */
+
+#define H2_IAR_TYPE_M          0xF000  /* bits 15:12, type of functional */
+                                       /* block the register resides in */
+                                       /* 1=DMA Port */
+                                       /* 9=Global DMA Control */
+                                       /* 2=Bresenham */
+                                       /* 3=Unix Timer */
+#define H2_IAR_NUM_M           0x0F00  /* bits 11:8 instance of the */
+                                       /* blockin which the indirect */
+                                       /* register resides */
+                                       /* If IAR_TYPE_M=DMA Port: */
+                                       /* 1=Synth In */
+                                       /* 2=AES In */
+                                       /* 3=AES Out */
+                                       /* 4=DAC Out */
+                                       /* 5=ADC Out */
+                                       /* 6=Synth Control */
+                                       /* If IAR_TYPE_M=Global DMA Control: */
+                                       /* 1=Control */
+                                       /* If IAR_TYPE_M=Bresenham: */
+                                       /* 1=Bresenham Clock Gen 1 */
+                                       /* 2=Bresenham Clock Gen 2 */
+                                       /* 3=Bresenham Clock Gen 3 */
+                                       /* If IAR_TYPE_M=Unix Timer: */
+                                       /* 1=Unix Timer */
+#define H2_IAR_ACCESS_SELECT   0x0080  /* 1=read 0=write */
+#define H2_IAR_PARAM           0x000C  /* Parameter Select */
+#define H2_IAR_RB_INDEX_M      0x0003  /* Read Back Index */
+                                       /* 00:word0 */
+                                       /* 01:word1 */
+                                       /* 10:word2 */
+                                       /* 11:word3 */
+/*
+ * HAL2 internal addressing
+ *
+ * The HAL2 has "indirect registers" (idr) which are accessed by writing to the
+ * Indirect Data registers. Write the address to the Indirect Address register
+ * to transfer the data.
+ *
+ * We define the H2IR_* to the read address and H2IW_* to the write address and
+ * H2I_* to be fields in whatever register is referred to.
+ *
+ * When we write to indirect registers which are larger than one word (16 bit)
+ * we have to fill more than one indirect register before writing. When we read
+ * back however we have to read several times, each time with different Read
+ * Back Indexes (there are defs for doing this easily).
+ */
+
+/*
+ * Relay Control
+ */
+#define H2I_RELAY_C            0x9100
+#define H2I_RELAY_C_STATE      0x01            /* state of RELAY pin signal */
+
+/* DMA port enable */
+
+#define H2I_DMA_PORT_EN                0x9104
+#define H2I_DMA_PORT_EN_SY_IN  0x01            /* Synth_in DMA port */
+#define H2I_DMA_PORT_EN_AESRX  0x02            /* AES receiver DMA port */
+#define H2I_DMA_PORT_EN_AESTX  0x04            /* AES transmitter DMA port */
+#define H2I_DMA_PORT_EN_CODECTX        0x08            /* CODEC transmit DMA port */
+#define H2I_DMA_PORT_EN_CODECR 0x10            /* CODEC receive DMA port */
+
+#define H2I_DMA_END            0x9108          /* global dma endian select */
+#define H2I_DMA_END_SY_IN      0x01            /* Synth_in DMA port */
+#define H2I_DMA_END_AESRX      0x02            /* AES receiver DMA port */
+#define H2I_DMA_END_AESTX      0x04            /* AES transmitter DMA port */
+#define H2I_DMA_END_CODECTX    0x08            /* CODEC transmit DMA port */
+#define H2I_DMA_END_CODECR     0x10            /* CODEC receive DMA port */
+                                               /* 0=b_end 1=l_end */
+
+#define H2I_DMA_DRV            0x910C          /* global PBUS DMA enable */
+
+#define H2I_SYNTH_C            0x1104          /* Synth DMA control */
+
+#define H2I_AESRX_C            0x1204          /* AES RX dma control */
+
+#define H2I_C_TS_EN            0x20            /* Timestamp enable */
+#define H2I_C_TS_FRMT          0x40            /* Timestamp format */
+#define H2I_C_NAUDIO           0x80            /* Sign extend */
+
+/* AESRX CTL, 16 bit */
+
+#define H2I_AESTX_C            0x1304          /* AES TX DMA control */
+#define H2I_AESTX_C_CLKID_SHIFT        3               /* Bresenham Clock Gen 1-3 */
+#define H2I_AESTX_C_CLKID_M    0x18
+#define H2I_AESTX_C_DATAT_SHIFT        8               /* 1=mono 2=stereo (3=quad) */
+#define H2I_AESTX_C_DATAT_M    0x300
+
+/* CODEC registers */
+
+#define H2I_DAC_C1             0x1404          /* DAC DMA control, 16 bit */
+#define H2I_DAC_C2             0x1408          /* DAC DMA control, 32 bit */
+#define H2I_ADC_C1             0x1504          /* ADC DMA control, 16 bit */
+#define H2I_ADC_C2             0x1508          /* ADC DMA control, 32 bit */
+
+/* Bits in CTL1 register */
+
+#define H2I_C1_DMA_SHIFT       0               /* DMA channel */
+#define H2I_C1_DMA_M           0x7
+#define H2I_C1_CLKID_SHIFT     3               /* Bresenham Clock Gen 1-3 */
+#define H2I_C1_CLKID_M         0x18
+#define H2I_C1_DATAT_SHIFT     8               /* 1=mono 2=stereo (3=quad) */
+#define H2I_C1_DATAT_M         0x300
+
+/* Bits in CTL2 register */
+
+#define H2I_C2_R_GAIN_SHIFT    0               /* right a/d input gain */
+#define H2I_C2_R_GAIN_M                0xf
+#define H2I_C2_L_GAIN_SHIFT    4               /* left a/d input gain */
+#define H2I_C2_L_GAIN_M                0xf0
+#define H2I_C2_R_SEL           0x100           /* right input select */
+#define H2I_C2_L_SEL           0x200           /* left input select */
+#define H2I_C2_MUTE            0x400           /* mute */
+#define H2I_C2_DO1             0x00010000      /* digital output port bit 0 */
+#define H2I_C2_DO2             0x00020000      /* digital output port bit 1 */
+#define H2I_C2_R_ATT_SHIFT     18              /* right d/a output - */
+#define H2I_C2_R_ATT_M         0x007c0000      /* attenuation */
+#define H2I_C2_L_ATT_SHIFT     23              /* left d/a output - */
+#define H2I_C2_L_ATT_M         0x0f800000      /* attenuation */
+
+#define H2I_SYNTH_MAP_C                0x1104          /* synth dma handshake ctrl */
+
+/* Clock generator CTL 1, 16 bit */
+
+#define H2I_BRES1_C1           0x2104
+#define H2I_BRES2_C1           0x2204
+#define H2I_BRES3_C1           0x2304
+
+#define H2I_BRES_C1_SHIFT      0               /* 0=48.0 1=44.1 2=aes_rx */
+#define H2I_BRES_C1_M          0x03
+
+/* Clock generator CTL 2, 32 bit */
+
+#define H2I_BRES1_C2           0x2108
+#define H2I_BRES2_C2           0x2208
+#define H2I_BRES3_C2           0x2308
+
+#define H2I_BRES_C2_INC_SHIFT  0               /* increment value */
+#define H2I_BRES_C2_INC_M      0xffff
+#define H2I_BRES_C2_MOD_SHIFT  16              /* modcontrol value */
+#define H2I_BRES_C2_MOD_M      0xffff0000      /* modctrl=0xffff&(modinc-1) */
+
+/* Unix timer, 64 bit */
+
+#define H2I_UTIME              0x3104
+#define H2I_UTIME_0_LD         0xffff          /* microseconds, LSB's */
+#define H2I_UTIME_1_LD0                0x0f            /* microseconds, MSB's */
+#define H2I_UTIME_1_LD1                0xf0            /* tenths of microseconds */
+#define H2I_UTIME_2_LD         0xffff          /* seconds, LSB's */
+#define H2I_UTIME_3_LD         0xffff          /* seconds, MSB's */
+
+struct hal2_ctl_regs {
+       u32 _unused0[4];
+       u32 isr;                /* 0x10 Status Register */
+       u32 _unused1[3];
+       u32 rev;                /* 0x20 Revision Register */
+       u32 _unused2[3];
+       u32 iar;                /* 0x30 Indirect Address Register */
+       u32 _unused3[3];
+       u32 idr0;               /* 0x40 Indirect Data Register 0 */
+       u32 _unused4[3];
+       u32 idr1;               /* 0x50 Indirect Data Register 1 */
+       u32 _unused5[3];
+       u32 idr2;               /* 0x60 Indirect Data Register 2 */
+       u32 _unused6[3];
+       u32 idr3;               /* 0x70 Indirect Data Register 3 */
+};
+
+struct hal2_aes_regs {
+       u32 rx_stat[2]; /* Status registers */
+       u32 rx_cr[2];           /* Control registers */
+       u32 rx_ud[4];           /* User data window */
+       u32 rx_st[24];          /* Channel status data */
+
+       u32 tx_stat[1]; /* Status register */
+       u32 tx_cr[3];           /* Control registers */
+       u32 tx_ud[4];           /* User data window */
+       u32 tx_st[24];          /* Channel status data */
+};
+
+struct hal2_vol_regs {
+       u32 right;              /* Right volume */
+       u32 left;               /* Left volume */
+};
+
+struct hal2_syn_regs {
+       u32 _unused0[2];
+       u32 page;               /* DOC Page register */
+       u32 regsel;             /* DOC Register selection */
+       u32 dlow;               /* DOC Data low */
+       u32 dhigh;              /* DOC Data high */
+       u32 irq;                /* IRQ Status */
+       u32 dram;               /* DRAM Access */
+};
+
+#endif /* __HAL2_H */
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
new file mode 100644 (file)
index 0000000..4c63504
--- /dev/null
@@ -0,0 +1,1006 @@
+/*
+ *   Sound driver for Silicon Graphics O2 Workstations A/V board audio.
+ *
+ *   Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
+ *   Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
+ *   Mxier part taken from mace_audio.c:
+ *   Copyright 2007 Thorben Jändling <tj.trevelyan@gmail.com>
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/gfp.h>
+#include <linux/vmalloc.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+#include <asm/ip32/ip32_ints.h>
+#include <asm/ip32/mace.h>
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#define SNDRV_GET_ID
+#include <sound/initval.h>
+#include <sound/ad1843.h>
+
+
+MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
+MODULE_DESCRIPTION("SGI O2 Audio");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Silicon Graphics, O2 Audio}}");
+
+static int index = SNDRV_DEFAULT_IDX1;  /* Index 0-MAX */
+static char *id = SNDRV_DEFAULT_STR1;   /* ID for this card */
+
+module_param(index, int, 0444);
+MODULE_PARM_DESC(index, "Index value for SGI O2 soundcard.");
+module_param(id, charp, 0444);
+MODULE_PARM_DESC(id, "ID string for SGI O2 soundcard.");
+
+
+#define AUDIO_CONTROL_RESET              BIT(0) /* 1: reset audio interface */
+#define AUDIO_CONTROL_CODEC_PRESENT      BIT(1) /* 1: codec detected */
+
+#define CODEC_CONTROL_WORD_SHIFT        0
+#define CODEC_CONTROL_READ              BIT(16)
+#define CODEC_CONTROL_ADDRESS_SHIFT     17
+
+#define CHANNEL_CONTROL_RESET           BIT(10) /* 1: reset channel */
+#define CHANNEL_DMA_ENABLE              BIT(9)  /* 1: enable DMA transfer */
+#define CHANNEL_INT_THRESHOLD_DISABLED  (0 << 5) /* interrupt disabled */
+#define CHANNEL_INT_THRESHOLD_25        (1 << 5) /* int on buffer >25% full */
+#define CHANNEL_INT_THRESHOLD_50        (2 << 5) /* int on buffer >50% full */
+#define CHANNEL_INT_THRESHOLD_75        (3 << 5) /* int on buffer >75% full */
+#define CHANNEL_INT_THRESHOLD_EMPTY     (4 << 5) /* int on buffer empty */
+#define CHANNEL_INT_THRESHOLD_NOT_EMPTY (5 << 5) /* int on buffer !empty */
+#define CHANNEL_INT_THRESHOLD_FULL      (6 << 5) /* int on buffer empty */
+#define CHANNEL_INT_THRESHOLD_NOT_FULL  (7 << 5) /* int on buffer !empty */
+
+#define CHANNEL_RING_SHIFT              12
+#define CHANNEL_RING_SIZE               (1 << CHANNEL_RING_SHIFT)
+#define CHANNEL_RING_MASK               (CHANNEL_RING_SIZE - 1)
+
+#define CHANNEL_LEFT_SHIFT 40
+#define CHANNEL_RIGHT_SHIFT 8
+
+struct snd_sgio2audio_chan {
+       int idx;
+       struct snd_pcm_substream *substream;
+       int pos;
+       snd_pcm_uframes_t size;
+       spinlock_t lock;
+};
+
+/* definition of the chip-specific record */
+struct snd_sgio2audio {
+       struct snd_card *card;
+
+       /* codec */
+       struct snd_ad1843 ad1843;
+       spinlock_t ad1843_lock;
+
+       /* channels */
+       struct snd_sgio2audio_chan channel[3];
+
+       /* resources */
+       void *ring_base;
+       dma_addr_t ring_base_dma;
+};
+
+/* AD1843 access */
+
+/*
+ * read_ad1843_reg returns the current contents of a 16 bit AD1843 register.
+ *
+ * Returns unsigned register value on success, -errno on failure.
+ */
+static int read_ad1843_reg(void *priv, int reg)
+{
+       struct snd_sgio2audio *chip = priv;
+       int val;
+       unsigned long flags;
+
+       spin_lock_irqsave(&chip->ad1843_lock, flags);
+
+       writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
+              CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
+       wmb();
+       val = readq(&mace->perif.audio.codec_control); /* flush bus */
+       udelay(200);
+
+       val = readq(&mace->perif.audio.codec_read);
+
+       spin_unlock_irqrestore(&chip->ad1843_lock, flags);
+       return val;
+}
+
+/*
+ * write_ad1843_reg writes the specified value to a 16 bit AD1843 register.
+ */
+static int write_ad1843_reg(void *priv, int reg, int word)
+{
+       struct snd_sgio2audio *chip = priv;
+       int val;
+       unsigned long flags;
+
+       spin_lock_irqsave(&chip->ad1843_lock, flags);
+
+       writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
+              (word << CODEC_CONTROL_WORD_SHIFT),
+              &mace->perif.audio.codec_control);
+       wmb();
+       val = readq(&mace->perif.audio.codec_control); /* flush bus */
+       udelay(200);
+
+       spin_unlock_irqrestore(&chip->ad1843_lock, flags);
+       return 0;
+}
+
+static int sgio2audio_gain_info(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_info *uinfo)
+{
+       struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = ad1843_get_gain_max(&chip->ad1843,
+                                            (int)kcontrol->private_value);
+       return 0;
+}
+
+static int sgio2audio_gain_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
+       int vol;
+
+       vol = ad1843_get_gain(&chip->ad1843, (int)kcontrol->private_value);
+
+       ucontrol->value.integer.value[0] = (vol >> 8) & 0xFF;
+       ucontrol->value.integer.value[1] = vol & 0xFF;
+
+       return 0;
+}
+
+static int sgio2audio_gain_put(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
+       int newvol, oldvol;
+
+       oldvol = ad1843_get_gain(&chip->ad1843, kcontrol->private_value);
+       newvol = (ucontrol->value.integer.value[0] << 8) |
+               ucontrol->value.integer.value[1];
+
+       newvol = ad1843_set_gain(&chip->ad1843, kcontrol->private_value,
+               newvol);
+
+       return newvol != oldvol;
+}
+
+static int sgio2audio_source_info(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_info *uinfo)
+{
+       static const char *texts[3] = {
+               "Cam Mic", "Mic", "Line"
+       };
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = 3;
+       if (uinfo->value.enumerated.item >= 3)
+               uinfo->value.enumerated.item = 1;
+       strcpy(uinfo->value.enumerated.name,
+              texts[uinfo->value.enumerated.item]);
+       return 0;
+}
+
+static int sgio2audio_source_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
+
+       ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
+       return 0;
+}
+
+static int sgio2audio_source_put(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
+       int newsrc, oldsrc;
+
+       oldsrc = ad1843_get_recsrc(&chip->ad1843);
+       newsrc = ad1843_set_recsrc(&chip->ad1843,
+                                  ucontrol->value.enumerated.item[0]);
+
+       return newsrc != oldsrc;
+}
+
+/* dac1/pcm0 mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_pcm0 __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "PCM Playback Volume",
+       .index          = 0,
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_PCM_0,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+/* dac2/pcm1 mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_pcm1 __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "PCM Playback Volume",
+       .index          = 1,
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_PCM_1,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+/* record level mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_reclevel __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Capture Volume",
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_RECLEV,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+/* record level source control */
+static struct snd_kcontrol_new sgio2audio_ctrl_recsource __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Capture Source",
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .info           = sgio2audio_source_info,
+       .get            = sgio2audio_source_get,
+       .put            = sgio2audio_source_put,
+};
+
+/* line mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_line __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Line Playback Volume",
+       .index          = 0,
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_LINE,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+/* cd mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_cd __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Line Playback Volume",
+       .index          = 1,
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_LINE_2,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+/* mic mixer control */
+static struct snd_kcontrol_new sgio2audio_ctrl_mic __devinitdata = {
+       .iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name           = "Mic Playback Volume",
+       .access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+       .private_value  = AD1843_GAIN_MIC,
+       .info           = sgio2audio_gain_info,
+       .get            = sgio2audio_gain_get,
+       .put            = sgio2audio_gain_put,
+};
+
+
+static int __devinit snd_sgio2audio_new_mixer(struct snd_sgio2audio *chip)
+{
+       int err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_pcm0, chip));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_pcm1, chip));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_reclevel, chip));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_recsource, chip));
+       if (err < 0)
+               return err;
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_line, chip));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_cd, chip));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_add(chip->card,
+                         snd_ctl_new1(&sgio2audio_ctrl_mic, chip));
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+/* low-level audio interface DMA */
+
+/* get data out of bounce buffer, count must be a multiple of 32 */
+/* returns 1 if a period has elapsed */
+static int snd_sgio2audio_dma_pull_frag(struct snd_sgio2audio *chip,
+                                       unsigned int ch, unsigned int count)
+{
+       int ret;
+       unsigned long src_base, src_pos, dst_mask;
+       unsigned char *dst_base;
+       int dst_pos;
+       u64 *src;
+       s16 *dst;
+       u64 x;
+       unsigned long flags;
+       struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
+
+       spin_lock_irqsave(&chip->channel[ch].lock, flags);
+
+       src_base = (unsigned long) chip->ring_base | (ch << CHANNEL_RING_SHIFT);
+       src_pos = readq(&mace->perif.audio.chan[ch].read_ptr);
+       dst_base = runtime->dma_area;
+       dst_pos = chip->channel[ch].pos;
+       dst_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
+
+       /* check if a period has elapsed */
+       chip->channel[ch].size += (count >> 3); /* in frames */
+       ret = chip->channel[ch].size >= runtime->period_size;
+       chip->channel[ch].size %= runtime->period_size;
+
+       while (count) {
+               src = (u64 *)(src_base + src_pos);
+               dst = (s16 *)(dst_base + dst_pos);
+
+               x = *src;
+               dst[0] = (x >> CHANNEL_LEFT_SHIFT) & 0xffff;
+               dst[1] = (x >> CHANNEL_RIGHT_SHIFT) & 0xffff;
+
+               src_pos = (src_pos + sizeof(u64)) & CHANNEL_RING_MASK;
+               dst_pos = (dst_pos + 2 * sizeof(s16)) & dst_mask;
+               count -= sizeof(u64);
+       }
+
+       writeq(src_pos, &mace->perif.audio.chan[ch].read_ptr); /* in bytes */
+       chip->channel[ch].pos = dst_pos;
+
+       spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
+       return ret;
+}
+
+/* put some DMA data in bounce buffer, count must be a multiple of 32 */
+/* returns 1 if a period has elapsed */
+static int snd_sgio2audio_dma_push_frag(struct snd_sgio2audio *chip,
+                                       unsigned int ch, unsigned int count)
+{
+       int ret;
+       s64 l, r;
+       unsigned long dst_base, dst_pos, src_mask;
+       unsigned char *src_base;
+       int src_pos;
+       u64 *dst;
+       s16 *src;
+       unsigned long flags;
+       struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
+
+       spin_lock_irqsave(&chip->channel[ch].lock, flags);
+
+       dst_base = (unsigned long)chip->ring_base | (ch << CHANNEL_RING_SHIFT);
+       dst_pos = readq(&mace->perif.audio.chan[ch].write_ptr);
+       src_base = runtime->dma_area;
+       src_pos = chip->channel[ch].pos;
+       src_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
+
+       /* check if a period has elapsed */
+       chip->channel[ch].size += (count >> 3); /* in frames */
+       ret = chip->channel[ch].size >= runtime->period_size;
+       chip->channel[ch].size %= runtime->period_size;
+
+       while (count) {
+               src = (s16 *)(src_base + src_pos);
+               dst = (u64 *)(dst_base + dst_pos);
+
+               l = src[0]; /* sign extend */
+               r = src[1]; /* sign extend */
+
+               *dst = ((l & 0x00ffffff) << CHANNEL_LEFT_SHIFT) |
+                       ((r & 0x00ffffff) << CHANNEL_RIGHT_SHIFT);
+
+               dst_pos = (dst_pos + sizeof(u64)) & CHANNEL_RING_MASK;
+               src_pos = (src_pos + 2 * sizeof(s16)) & src_mask;
+               count -= sizeof(u64);
+       }
+
+       writeq(dst_pos, &mace->perif.audio.chan[ch].write_ptr); /* in bytes */
+       chip->channel[ch].pos = src_pos;
+
+       spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
+       return ret;
+}
+
+static int snd_sgio2audio_dma_start(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
+       int ch = chan->idx;
+
+       /* reset DMA channel */
+       writeq(CHANNEL_CONTROL_RESET, &mace->perif.audio.chan[ch].control);
+       udelay(10);
+       writeq(0, &mace->perif.audio.chan[ch].control);
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               /* push a full buffer */
+               snd_sgio2audio_dma_push_frag(chip, ch, CHANNEL_RING_SIZE - 32);
+       }
+       /* set DMA to wake on 50% empty and enable interrupt */
+       writeq(CHANNEL_DMA_ENABLE | CHANNEL_INT_THRESHOLD_50,
+              &mace->perif.audio.chan[ch].control);
+       return 0;
+}
+
+static int snd_sgio2audio_dma_stop(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
+
+       writeq(0, &mace->perif.audio.chan[chan->idx].control);
+       return 0;
+}
+
+static irqreturn_t snd_sgio2audio_dma_in_isr(int irq, void *dev_id)
+{
+       struct snd_sgio2audio_chan *chan = dev_id;
+       struct snd_pcm_substream *substream;
+       struct snd_sgio2audio *chip;
+       int count, ch;
+
+       substream = chan->substream;
+       chip = snd_pcm_substream_chip(substream);
+       ch = chan->idx;
+
+       /* empty the ring */
+       count = CHANNEL_RING_SIZE -
+               readq(&mace->perif.audio.chan[ch].depth) - 32;
+       if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
+               snd_pcm_period_elapsed(substream);
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t snd_sgio2audio_dma_out_isr(int irq, void *dev_id)
+{
+       struct snd_sgio2audio_chan *chan = dev_id;
+       struct snd_pcm_substream *substream;
+       struct snd_sgio2audio *chip;
+       int count, ch;
+
+       substream = chan->substream;
+       chip = snd_pcm_substream_chip(substream);
+       ch = chan->idx;
+       /* fill the ring */
+       count = CHANNEL_RING_SIZE -
+               readq(&mace->perif.audio.chan[ch].depth) - 32;
+       if (snd_sgio2audio_dma_push_frag(chip, ch, count))
+               snd_pcm_period_elapsed(substream);
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t snd_sgio2audio_error_isr(int irq, void *dev_id)
+{
+       struct snd_sgio2audio_chan *chan = dev_id;
+       struct snd_pcm_substream *substream;
+
+       substream = chan->substream;
+       snd_sgio2audio_dma_stop(substream);
+       snd_sgio2audio_dma_start(substream);
+       return IRQ_HANDLED;
+}
+
+/* PCM part */
+/* PCM hardware definition */
+static struct snd_pcm_hardware snd_sgio2audio_pcm_hw = {
+       .info = (SNDRV_PCM_INFO_MMAP |
+                SNDRV_PCM_INFO_MMAP_VALID |
+                SNDRV_PCM_INFO_INTERLEAVED |
+                SNDRV_PCM_INFO_BLOCK_TRANSFER),
+       .formats =          SNDRV_PCM_FMTBIT_S16_BE,
+       .rates =            SNDRV_PCM_RATE_8000_48000,
+       .rate_min =         8000,
+       .rate_max =         48000,
+       .channels_min =     2,
+       .channels_max =     2,
+       .buffer_bytes_max = 65536,
+       .period_bytes_min = 32768,
+       .period_bytes_max = 65536,
+       .periods_min =      1,
+       .periods_max =      1024,
+};
+
+/* PCM playback open callback */
+static int snd_sgio2audio_playback1_open(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+
+       runtime->hw = snd_sgio2audio_pcm_hw;
+       runtime->private_data = &chip->channel[1];
+       return 0;
+}
+
+static int snd_sgio2audio_playback2_open(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+
+       runtime->hw = snd_sgio2audio_pcm_hw;
+       runtime->private_data = &chip->channel[2];
+       return 0;
+}
+
+/* PCM capture open callback */
+static int snd_sgio2audio_capture_open(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+
+       runtime->hw = snd_sgio2audio_pcm_hw;
+       runtime->private_data = &chip->channel[0];
+       return 0;
+}
+
+/* PCM close callback */
+static int snd_sgio2audio_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+
+       runtime->private_data = NULL;
+       return 0;
+}
+
+
+/* hw_params callback */
+static int snd_sgio2audio_pcm_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *hw_params)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       int size = params_buffer_bytes(hw_params);
+
+       /* alloc virtual 'dma' area */
+       if (runtime->dma_area)
+               vfree(runtime->dma_area);
+       runtime->dma_area = vmalloc(size);
+       if (runtime->dma_area == NULL)
+               return -ENOMEM;
+       runtime->dma_bytes = size;
+       return 0;
+}
+
+/* hw_free callback */
+static int snd_sgio2audio_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       if (substream->runtime->dma_area)
+               vfree(substream->runtime->dma_area);
+       substream->runtime->dma_area = NULL;
+       return 0;
+}
+
+/* prepare callback */
+static int snd_sgio2audio_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
+       int ch = chan->idx;
+       unsigned long flags;
+
+       spin_lock_irqsave(&chip->channel[ch].lock, flags);
+
+       /* Setup the pseudo-dma transfer pointers.  */
+       chip->channel[ch].pos = 0;
+       chip->channel[ch].size = 0;
+       chip->channel[ch].substream = substream;
+
+       /* set AD1843 format */
+       /* hardware format is always S16_LE */
+       switch (substream->stream) {
+       case SNDRV_PCM_STREAM_PLAYBACK:
+               ad1843_setup_dac(&chip->ad1843,
+                                ch - 1,
+                                runtime->rate,
+                                SNDRV_PCM_FORMAT_S16_LE,
+                                runtime->channels);
+               break;
+       case SNDRV_PCM_STREAM_CAPTURE:
+               ad1843_setup_adc(&chip->ad1843,
+                                runtime->rate,
+                                SNDRV_PCM_FORMAT_S16_LE,
+                                runtime->channels);
+               break;
+       }
+       spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
+       return 0;
+}
+
+/* trigger callback */
+static int snd_sgio2audio_pcm_trigger(struct snd_pcm_substream *substream,
+                                     int cmd)
+{
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               /* start the PCM engine */
+               snd_sgio2audio_dma_start(substream);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               /* stop the PCM engine */
+               snd_sgio2audio_dma_stop(substream);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/* pointer callback */
+static snd_pcm_uframes_t
+snd_sgio2audio_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
+       struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
+
+       /* get the current hardware pointer */
+       return bytes_to_frames(substream->runtime,
+                              chip->channel[chan->idx].pos);
+}
+
+/* get the physical page pointer on the given offset */
+static struct page *snd_sgio2audio_page(struct snd_pcm_substream *substream,
+                                       unsigned long offset)
+{
+       return vmalloc_to_page(substream->runtime->dma_area + offset);
+}
+
+/* operators */
+static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
+       .open =        snd_sgio2audio_playback1_open,
+       .close =       snd_sgio2audio_pcm_close,
+       .ioctl =       snd_pcm_lib_ioctl,
+       .hw_params =   snd_sgio2audio_pcm_hw_params,
+       .hw_free =     snd_sgio2audio_pcm_hw_free,
+       .prepare =     snd_sgio2audio_pcm_prepare,
+       .trigger =     snd_sgio2audio_pcm_trigger,
+       .pointer =     snd_sgio2audio_pcm_pointer,
+       .page =        snd_sgio2audio_page,
+};
+
+static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
+       .open =        snd_sgio2audio_playback2_open,
+       .close =       snd_sgio2audio_pcm_close,
+       .ioctl =       snd_pcm_lib_ioctl,
+       .hw_params =   snd_sgio2audio_pcm_hw_params,
+       .hw_free =     snd_sgio2audio_pcm_hw_free,
+       .prepare =     snd_sgio2audio_pcm_prepare,
+       .trigger =     snd_sgio2audio_pcm_trigger,
+       .pointer =     snd_sgio2audio_pcm_pointer,
+       .page =        snd_sgio2audio_page,
+};
+
+static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
+       .open =        snd_sgio2audio_capture_open,
+       .close =       snd_sgio2audio_pcm_close,
+       .ioctl =       snd_pcm_lib_ioctl,
+       .hw_params =   snd_sgio2audio_pcm_hw_params,
+       .hw_free =     snd_sgio2audio_pcm_hw_free,
+       .prepare =     snd_sgio2audio_pcm_prepare,
+       .trigger =     snd_sgio2audio_pcm_trigger,
+       .pointer =     snd_sgio2audio_pcm_pointer,
+       .page =        snd_sgio2audio_page,
+};
+
+/*
+ *  definitions of capture are omitted here...
+ */
+
+/* create a pcm device */
+static int __devinit snd_sgio2audio_new_pcm(struct snd_sgio2audio *chip)
+{
+       struct snd_pcm *pcm;
+       int err;
+
+       /* create first pcm device with one outputs and one input */
+       err = snd_pcm_new(chip->card, "SGI O2 Audio", 0, 1, 1, &pcm);
+       if (err < 0)
+               return err;
+
+       pcm->private_data = chip;
+       strcpy(pcm->name, "SGI O2 DAC1");
+
+       /* set operators */
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                       &snd_sgio2audio_playback1_ops);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+                       &snd_sgio2audio_capture_ops);
+
+       /* create second  pcm device with one outputs and no input */
+       err = snd_pcm_new(chip->card, "SGI O2 Audio", 1, 1, 0, &pcm);
+       if (err < 0)
+               return err;
+
+       pcm->private_data = chip;
+       strcpy(pcm->name, "SGI O2 DAC2");
+
+       /* set operators */
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                       &snd_sgio2audio_playback2_ops);
+
+       return 0;
+}
+
+static struct {
+       int idx;
+       int irq;
+       irqreturn_t (*isr)(int, void *);
+       const char *desc;
+} snd_sgio2_isr_table[] = {
+       {
+               .idx = 0,
+               .irq = MACEISA_AUDIO1_DMAT_IRQ,
+               .isr = snd_sgio2audio_dma_in_isr,
+               .desc = "Capture DMA Channel 0"
+       }, {
+               .idx = 0,
+               .irq = MACEISA_AUDIO1_OF_IRQ,
+               .isr = snd_sgio2audio_error_isr,
+               .desc = "Capture Overflow"
+       }, {
+               .idx = 1,
+               .irq = MACEISA_AUDIO2_DMAT_IRQ,
+               .isr = snd_sgio2audio_dma_out_isr,
+               .desc = "Playback DMA Channel 1"
+       }, {
+               .idx = 1,
+               .irq = MACEISA_AUDIO2_MERR_IRQ,
+               .isr = snd_sgio2audio_error_isr,
+               .desc = "Memory Error Channel 1"
+       }, {
+               .idx = 2,
+               .irq = MACEISA_AUDIO3_DMAT_IRQ,
+               .isr = snd_sgio2audio_dma_out_isr,
+               .desc = "Playback DMA Channel 2"
+       }, {
+               .idx = 2,
+               .irq = MACEISA_AUDIO3_MERR_IRQ,
+               .isr = snd_sgio2audio_error_isr,
+               .desc = "Memory Error Channel 2"
+       }
+};
+
+/* ALSA driver */
+
+static int snd_sgio2audio_free(struct snd_sgio2audio *chip)
+{
+       int i;
+
+       /* reset interface */
+       writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
+       udelay(1);
+       writeq(0, &mace->perif.audio.control);
+
+       /* release IRQ's */
+       for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++)
+               free_irq(snd_sgio2_isr_table[i].irq,
+                        &chip->channel[snd_sgio2_isr_table[i].idx]);
+
+       dma_free_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
+                         chip->ring_base, chip->ring_base_dma);
+
+       /* release card data */
+       kfree(chip);
+       return 0;
+}
+
+static int snd_sgio2audio_dev_free(struct snd_device *device)
+{
+       struct snd_sgio2audio *chip = device->device_data;
+
+       return snd_sgio2audio_free(chip);
+}
+
+static struct snd_device_ops ops = {
+       .dev_free = snd_sgio2audio_dev_free,
+};
+
+static int __devinit snd_sgio2audio_create(struct snd_card *card,
+                                          struct snd_sgio2audio **rchip)
+{
+       struct snd_sgio2audio *chip;
+       int i, err;
+
+       *rchip = NULL;
+
+       /* check if a codec is attached to the interface */
+       /* (Audio or Audio/Video board present) */
+       if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
+               return -ENOENT;
+
+       chip = kzalloc(sizeof(struct snd_sgio2audio), GFP_KERNEL);
+       if (chip == NULL)
+               return -ENOMEM;
+
+       chip->card = card;
+
+       chip->ring_base = dma_alloc_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
+                                            &chip->ring_base_dma, GFP_USER);
+       if (chip->ring_base == NULL) {
+               printk(KERN_ERR
+                      "sgio2audio: could not allocate ring buffers\n");
+               kfree(chip);
+               return -ENOMEM;
+       }
+
+       spin_lock_init(&chip->ad1843_lock);
+
+       /* initialize channels */
+       for (i = 0; i < 3; i++) {
+               spin_lock_init(&chip->channel[i].lock);
+               chip->channel[i].idx = i;
+       }
+
+       /* allocate IRQs */
+       for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
+               if (request_irq(snd_sgio2_isr_table[i].irq,
+                               snd_sgio2_isr_table[i].isr,
+                               0,
+                               snd_sgio2_isr_table[i].desc,
+                               &chip->channel[snd_sgio2_isr_table[i].idx])) {
+                       snd_sgio2audio_free(chip);
+                       printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
+                              snd_sgio2_isr_table[i].irq);
+                       return -EBUSY;
+               }
+       }
+
+       /* reset the interface */
+       writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
+       udelay(1);
+       writeq(0, &mace->perif.audio.control);
+       msleep_interruptible(1); /* give time to recover */
+
+       /* set ring base */
+       writeq(chip->ring_base_dma, &mace->perif.ctrl.ringbase);
+
+       /* attach the AD1843 codec */
+       chip->ad1843.read = read_ad1843_reg;
+       chip->ad1843.write = write_ad1843_reg;
+       chip->ad1843.chip = chip;
+
+       /* initialize the AD1843 codec */
+       err = ad1843_init(&chip->ad1843);
+       if (err < 0) {
+               snd_sgio2audio_free(chip);
+               return err;
+       }
+
+       err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
+       if (err < 0) {
+               snd_sgio2audio_free(chip);
+               return err;
+       }
+       *rchip = chip;
+       return 0;
+}
+
+static int __devinit snd_sgio2audio_probe(struct platform_device *pdev)
+{
+       struct snd_card *card;
+       struct snd_sgio2audio *chip;
+       int err;
+
+       card = snd_card_new(index, id, THIS_MODULE, 0);
+       if (card == NULL)
+               return -ENOMEM;
+
+       err = snd_sgio2audio_create(card, &chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       snd_card_set_dev(card, &pdev->dev);
+
+       err = snd_sgio2audio_new_pcm(chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       err = snd_sgio2audio_new_mixer(chip);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+
+       strcpy(card->driver, "SGI O2 Audio");
+       strcpy(card->shortname, "SGI O2 Audio");
+       sprintf(card->longname, "%s irq %i-%i",
+               card->shortname,
+               MACEISA_AUDIO1_DMAT_IRQ,
+               MACEISA_AUDIO3_MERR_IRQ);
+
+       err = snd_card_register(card);
+       if (err < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       platform_set_drvdata(pdev, card);
+       return 0;
+}
+
+static int __exit snd_sgio2audio_remove(struct platform_device *pdev)
+{
+       struct snd_card *card = platform_get_drvdata(pdev);
+
+       snd_card_free(card);
+       platform_set_drvdata(pdev, NULL);
+       return 0;
+}
+
+static struct platform_driver sgio2audio_driver = {
+       .probe  = snd_sgio2audio_probe,
+       .remove = __devexit_p(snd_sgio2audio_remove),
+       .driver = {
+               .name   = "sgio2audio",
+               .owner  = THIS_MODULE,
+       }
+};
+
+static int __init alsa_card_sgio2audio_init(void)
+{
+       return platform_driver_register(&sgio2audio_driver);
+}
+
+static void __exit alsa_card_sgio2audio_exit(void)
+{
+       platform_driver_unregister(&sgio2audio_driver);
+}
+
+module_init(alsa_card_sgio2audio_init)
+module_exit(alsa_card_sgio2audio_exit)
index 3be2dc1..3394013 100644 (file)
@@ -7,7 +7,7 @@
 
 config SOUND_BCM_CS4297A
        tristate "Crystal Sound CS4297a (for Swarm)"
-       depends on SOUND_PRIME && SIBYTE_SWARM
+       depends on SIBYTE_SWARM
        help
          The BCM91250A has a Crystal CS4297a on synchronous serial
          port B (in addition to the DB-9 serial port).  Say Y or M
@@ -17,7 +17,7 @@ config SOUND_BCM_CS4297A
 
 config SOUND_VWSND
        tristate "SGI Visual Workstation Sound"
-       depends on SOUND_PRIME && X86_VISWS
+       depends on X86_VISWS
        help
          Say Y or M if you have an SGI Visual Workstation and you want to be
          able to use its on-board audio.  Read
@@ -26,19 +26,18 @@ config SOUND_VWSND
 
 config SOUND_HAL2
        tristate "SGI HAL2 sound (EXPERIMENTAL)"
-       depends on SOUND_PRIME && SGI_IP22 && EXPERIMENTAL
+       depends on SGI_IP22 && EXPERIMENTAL
        help
          Say Y or M if you have an SGI Indy or Indigo2 system and want to be able to
          use its on-board A2 audio system.
 
 config SOUND_AU1550_AC97
        tristate "Au1550/Au1200 AC97 Sound"
-       select SND_AC97_CODEC
-       depends on SOUND_PRIME && (SOC_AU1550 || SOC_AU1200)
+       depends on SOC_AU1550 || SOC_AU1200
 
 config SOUND_TRIDENT
        tristate "Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core"
-       depends on SOUND_PRIME && PCI
+       depends on PCI
        ---help---
          Say Y or M if you have a PCI sound card utilizing the Trident
          4DWave-DX/NX chipset or your mother board chipset has SiS 7018
@@ -79,7 +78,7 @@ config SOUND_TRIDENT
 
 config SOUND_MSNDCLAS
        tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey"
-       depends on SOUND_PRIME && (m || !STANDALONE) && ISA
+       depends on (m || !STANDALONE) && ISA
        help
          Say M here if you have a Turtle Beach MultiSound Classic, Tahiti or
          Monterey (not for the Pinnacle or Fiji).
@@ -143,7 +142,7 @@ config MSNDCLAS_IO
 
 config SOUND_MSNDPIN
        tristate "Support for Turtle Beach MultiSound Pinnacle, Fiji"
-       depends on SOUND_PRIME && (m || !STANDALONE) && ISA
+       depends on (m || !STANDALONE) && ISA
        help
          Say M here if you have a Turtle Beach MultiSound Pinnacle or Fiji.
          See <file:Documentation/sound/oss/MultiSound> for important information
@@ -229,7 +228,7 @@ config MSNDPIN_NONPNP
          configure the card's resources.
 
 comment "MSND Pinnacle DSP section will be configured to above parameters."
-       depends on SOUND_PRIME && SOUND_MSNDPIN=y && MSNDPIN_NONPNP
+       depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
 
 config MSNDPIN_CFG
        hex "MSND Pinnacle config port 250,260,270"
@@ -242,7 +241,7 @@ config MSNDPIN_CFG
          Mode".
 
 comment "Pinnacle-specific Device Configuration (0 disables)"
-       depends on SOUND_PRIME && SOUND_MSNDPIN=y && MSNDPIN_NONPNP
+       depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
 
 config MSNDPIN_MPU_IO
        hex "MSND Pinnacle MPU I/O (e.g. 330)"
@@ -294,7 +293,7 @@ config MSNDPIN_JOYSTICK_IO
 
 config MSND_FIFOSIZE
        int "MSND buffer size (kB)"
-       depends on SOUND_PRIME && (SOUND_MSNDPIN=y || SOUND_MSNDCLAS=y)
+       depends on SOUND_MSNDPIN=y || SOUND_MSNDCLAS=y
        default "128"
        help
          Configures the size of each audio buffer, in kilobytes, for
@@ -302,9 +301,9 @@ config MSND_FIFOSIZE
          and Pinnacle). Larger values reduce the chance of data overruns at
          the expense of overall latency. If unsure, use the default.
 
-config SOUND_OSS
+menuconfig SOUND_OSS
        tristate "OSS sound modules"
-       depends on SOUND_PRIME && ISA_DMA_API && VIRT_TO_BUS
+       depends on ISA_DMA_API && VIRT_TO_BUS
        help
          OSS is the Open Sound System suite of sound card drivers.  They make
          sound programming easier since they provide a common API.  Say Y or
@@ -312,16 +311,16 @@ config SOUND_OSS
          driver for your sound card above, then pick your driver from the
          list below.
 
+if SOUND_OSS
+
 config SOUND_TRACEINIT
        bool "Verbose initialisation"
-       depends on SOUND_OSS
        help
          Verbose soundcard initialization -- affects the format of autoprobe
          and initialization messages at boot time.
 
 config SOUND_DMAP
        bool "Persistent DMA buffers"
-       depends on SOUND_OSS
        ---help---
          Linux can often have problems allocating DMA buffers for ISA sound
          cards on machines with more than 16MB of RAM. This is because ISA
@@ -338,8 +337,6 @@ config SOUND_DMAP
 
 config SOUND_SSCAPE
        tristate "Ensoniq SoundScape support"
-       depends on SOUND_OSS
-       depends on VIRT_TO_BUS
        help
          Answer Y if you have a sound card based on the Ensoniq SoundScape
          chipset. Such cards are being manufactured at least by Ensoniq, Spea
@@ -352,13 +349,11 @@ config SOUND_SSCAPE
 
 config SOUND_VMIDI
        tristate "Loopback MIDI device support"
-       depends on SOUND_OSS
        help
          Support for MIDI loopback on port 1 or 2.
 
 config SOUND_TRIX
        tristate "MediaTrix AudioTrix Pro support"
-       depends on SOUND_OSS
        help
          Answer Y if you have the AudioTriX Pro sound card manufactured
          by MediaTrix.
@@ -382,7 +377,6 @@ config TRIX_BOOT_FILE
 
 config SOUND_MSS
        tristate "Microsoft Sound System support"
-       depends on SOUND_OSS
        ---help---
          Again think carefully before answering Y to this question.  It's
          safe to answer Y if you have the original Windows Sound System card
@@ -414,7 +408,6 @@ config SOUND_MSS
 
 config SOUND_MPU401
        tristate "MPU-401 support (NOT for SB16)"
-       depends on SOUND_OSS
        ---help---
          Be careful with this question.  The MPU401 interface is supported by
          all sound cards.  However, some natively supported cards have their
@@ -430,7 +423,6 @@ config SOUND_MPU401
 
 config SOUND_PAS
        tristate "ProAudioSpectrum 16 support"
-       depends on SOUND_OSS
        ---help---
          Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
          16 or Logitech SoundMan 16 sound card. Answer N if you have some
@@ -452,7 +444,6 @@ config PAS_JOYSTICK
 
 config SOUND_PSS
        tristate "PSS (AD1848, ADSP-2115, ESC614) support"
-       depends on SOUND_OSS
        help
          Answer Y or M if you have an Orchid SW32, Cardinal DSP16, Beethoven
          ADSP-16 or some other card based on the PSS chipset (AD1848 codec +
@@ -495,7 +486,6 @@ config PSS_BOOT_FILE
 
 config SOUND_SB
        tristate "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
-       depends on SOUND_OSS
        ---help---
          Answer Y if you have an original Sound Blaster card made by Creative
          Labs or a 100% hardware compatible clone (like the Thunderboard or
@@ -522,7 +512,6 @@ config SOUND_SB
 
 config SOUND_YM3812
        tristate "Yamaha FM synthesizer (YM3812/OPL-3) support"
-       depends on SOUND_OSS
        ---help---
          Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
          Answering Y is usually a safe and recommended choice, however some
@@ -538,7 +527,6 @@ config SOUND_YM3812
 
 config SOUND_UART6850
        tristate "6850 UART support"
-       depends on SOUND_OSS
        help
          This option enables support for MIDI interfaces based on the 6850
          UART chip. This interface is rarely found on sound cards. It's safe
@@ -549,7 +537,6 @@ config SOUND_UART6850
 
 config SOUND_AEDSP16
        tristate "Gallant Audio Cards (SC-6000 and SC-6600 based)"
-       depends on SOUND_OSS
        ---help---
          Answer Y if you have a Gallant's Audio Excel DSP 16 card. This
          driver supports Audio Excel DSP 16 but not the III nor PnP versions
@@ -630,14 +617,14 @@ endchoice
 
 config SOUND_VIDC
        tristate "VIDC 16-bit sound"
-       depends on ARM && (ARCH_ACORN || ARCH_CLPS7500) && SOUND_OSS
+       depends on ARM && (ARCH_ACORN || ARCH_CLPS7500)
        help
          16-bit support for the VIDC onboard sound hardware found on Acorn
          machines.
 
 config SOUND_WAVEARTIST
        tristate "Netwinder WaveArtist"
-       depends on ARM && SOUND_OSS && ARCH_NETWINDER
+       depends on ARM && ARCH_NETWINDER
        help
          Say Y here to include support for the Rockwell WaveArtist sound
          system.  This driver is mainly for the NetWinder.
@@ -646,9 +633,11 @@ config SOUND_KAHLUA
        tristate "XpressAudio Sound Blaster emulation"
        depends on SOUND_SB
 
+endif  # SOUND_OSS
+
 config SOUND_SH_DAC_AUDIO
        tristate "SuperH DAC audio support"
-       depends on SOUND_PRIME && CPU_SH3
+       depends on CPU_SH3
 
 config SOUND_SH_DAC_AUDIO_CHANNEL
        int "DAC channel"
index a003c0e..95fc5c6 100644 (file)
@@ -211,10 +211,6 @@ static int state_unit = -1;
 static int irq_installed;
 #endif /* MODULE */
 
-/* software implemented recording volume! */
-uint software_input_volume = SW_INPUT_VOLUME_SCALE * SW_INPUT_VOLUME_DEFAULT;
-EXPORT_SYMBOL(software_input_volume);
-
 /* control over who can modify resources shared between play/record */
 static mode_t shared_resource_owner;
 static int shared_resources_initialised;
@@ -1188,7 +1184,7 @@ static struct {
 
 /* publish this function for use by low-level code, if required */
 
-char *get_afmt_string(int afmt)
+static char *get_afmt_string(int afmt)
 {
         switch(afmt) {
             case AFMT_MU_LAW:
@@ -1551,4 +1547,3 @@ EXPORT_SYMBOL(dmasound_catchRadius);
 EXPORT_SYMBOL(dmasound_ulaw2dma8);
 EXPORT_SYMBOL(dmasound_alaw2dma8);
 #endif
-EXPORT_SYMBOL(get_afmt_string) ;
index 202e810..06e9e88 100644 (file)
@@ -710,7 +710,7 @@ static MACHINE machAmiga = {
 /*** Config & Setup **********************************************************/
 
 
-int __init dmasound_paula_init(void)
+static int __init dmasound_paula_init(void)
 {
        int err;
 
index b3379dd..1855b14 100644 (file)
@@ -611,7 +611,7 @@ static MACHINE machQ40 = {
 /*** Config & Setup **********************************************************/
 
 
-int __init dmasound_q40_init(void)
+static int __init dmasound_q40_init(void)
 {
        if (MACH_IS_Q40) {
            dmasound.mach = machQ40;
index ba38d62..e4282d9 100644 (file)
@@ -20,8 +20,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: msnd.c,v 1.17 1999/03/21 16:50:09 andrewtv Exp $
- *
  ********************************************************************/
 
 #include <linux/module.h>
index d0ca582..61b3955 100644 (file)
@@ -24,8 +24,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: msnd.h,v 1.36 1999/03/21 17:05:42 andrewtv Exp $
- *
  ********************************************************************/
 #ifndef __MSND_H
 #define __MSND_H
index 7ffea52..1a17dde 100644 (file)
@@ -24,8 +24,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  * 
- * $Id: msnd_classic.h,v 1.10 1999/03/21 17:36:09 andrewtv Exp $
- *
  ********************************************************************/
 #ifndef __MSND_CLASSIC_H
 #define __MSND_CLASSIC_H
index f1f49eb..bf27e00 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: msnd_pinnacle.c,v 1.8 2000/12/30 00:33:21 sycamore Exp $
- *
  * 12-3-2000  Modified IO port validation  Steve Sycamore
  *
- *
- * $$$: msnd_pinnacle.c,v 1.75 1999/03/21 16:50:09 andrewtv $$$ $
- *
  ********************************************************************/
 
 #include <linux/kernel.h>
index cce9114..c18d66c 100644 (file)
@@ -24,8 +24,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: msnd_pinnacle.h,v 1.11 1999/03/21 17:36:09 andrewtv Exp $
- *
  ********************************************************************/
 #ifndef __MSND_PINNACLE_H
 #define __MSND_PINNACLE_H
index 2c5aaa5..dcbb3f7 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/mutex.h>
 
-#include <asm/mach-visws/cobalt.h>
+#include <asm/visws/cobalt.h>
 
 #include "sound_config.h"
 
index a5a7f9d..9b61d95 100644 (file)
@@ -1,15 +1,20 @@
 # ALSA PA-RISC drivers
 
-menu "GSC devices"
-       depends on SND!=n && GSC
+menuconfig SND_GSC
+       bool "GSC sound devices"
+       depends on GSC
+       default y
+       help
+         Support for GSC sound devices on PA-RISC architectures.
+
+if SND_GSC
 
 config SND_HARMONY
        tristate "Harmony/Vivace sound chip"
-       depends on SND
        select SND_PCM
        help
          Say 'Y' or 'M' to include support for the Harmony/Vivace sound
          chip found in most GSC-based PA-RISC workstations.  It's frequently
          provided as part of the Lasi multi-function IC.
 
-endmenu
+endif  # SND_GSC
index 7e47421..8fe5dac 100644 (file)
@@ -1,11 +1,16 @@
 # ALSA PCI drivers
 
-menu "PCI devices"
-       depends on SND!=n && PCI
+menuconfig SND_PCI
+       bool "PCI sound devices"
+       depends on PCI
+       default y
+       help
+         Support for sound devices connected via the PCI bus.
+
+if SND_PCI
 
 config SND_AD1889
        tristate "Analog Devices AD1889"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated AC97 sound
@@ -17,7 +22,6 @@ config SND_AD1889
 
 config SND_ALS300
        tristate "Avance Logic ALS300/ALS300+"
-       depends on SND
        select SND_PCM
        select SND_AC97_CODEC
        select SND_OPL3_LIB
@@ -29,7 +33,7 @@ config SND_ALS300
 
 config SND_ALS4000
        tristate "Avance Logic ALS4000"
-       depends on SND && ISA_DMA_API
+       depends on ISA_DMA_API
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
@@ -43,7 +47,6 @@ config SND_ALS4000
 
 config SND_ALI5451
        tristate "ALi M5451 PCI Audio Controller"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -57,7 +60,6 @@ config SND_ALI5451
 
 config SND_ATIIXP
        tristate "ATI IXP AC97 Controller"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated AC97 sound
@@ -69,7 +71,6 @@ config SND_ATIIXP
 
 config SND_ATIIXP_MODEM
        tristate "ATI IXP Modem"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated MC97 modem on
@@ -80,7 +81,6 @@ config SND_ATIIXP_MODEM
 
 config SND_AU8810
        tristate "Aureal Advantage"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -95,7 +95,6 @@ config SND_AU8810
 
 config SND_AU8820
        tristate "Aureal Vortex"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -109,7 +108,6 @@ config SND_AU8820
 
 config SND_AU8830
        tristate "Aureal Vortex 2"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -124,7 +122,6 @@ config SND_AU8830
 
 config SND_AW2
        tristate "Emagic Audiowerk 2"
-       depends on SND
        help
          Say Y here to include support for Emagic Audiowerk 2 soundcards.
 
@@ -139,7 +136,7 @@ config SND_AW2
 
 config SND_AZT3328
        tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)"
-       depends on SND && EXPERIMENTAL
+       depends on EXPERIMENTAL
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
@@ -152,7 +149,6 @@ config SND_AZT3328
 
 config SND_BT87X
        tristate "Bt87x Audio Capture"
-       depends on SND
        select SND_PCM
        help
          If you want to record audio from TV cards based on
@@ -174,7 +170,6 @@ config SND_BT87X_OVERCLOCK
 
 config SND_CA0106
        tristate "SB Audigy LS / Live 24bit"
-       depends on SND
        select SND_AC97_CODEC
        select SND_RAWMIDI
        select SND_VMASTER
@@ -187,7 +182,6 @@ config SND_CA0106
 
 config SND_CMIPCI
        tristate "C-Media 8338, 8738, 8768, 8770"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
@@ -201,13 +195,11 @@ config SND_CMIPCI
 
 config SND_OXYGEN_LIB
         tristate
-       depends on SND
        select SND_PCM
        select SND_MPU401_UART
 
 config SND_OXYGEN
        tristate "C-Media 8788 (Oxygen)"
-       depends on SND
        select SND_OXYGEN_LIB
        help
          Say Y here to include support for sound cards based on the
@@ -225,7 +217,6 @@ config SND_OXYGEN
 
 config SND_CS4281
        tristate "Cirrus Logic (Sound Fusion) CS4281"
-       depends on SND
        select SND_OPL3_LIB
        select SND_RAWMIDI
        select SND_AC97_CODEC
@@ -237,7 +228,6 @@ config SND_CS4281
 
 config SND_CS46XX
        tristate "Cirrus Logic (Sound Fusion) CS4280/CS461x/CS462x/CS463x"
-       depends on SND
        select SND_RAWMIDI
        select SND_AC97_CODEC
        help
@@ -258,7 +248,7 @@ config SND_CS46XX_NEW_DSP
 
 config SND_CS5530
        tristate "CS5530 Audio"
-       depends on SND && ISA_DMA_API
+       depends on ISA_DMA_API
        select SND_SB16_DSP
        help
          Say Y here to include support for audio on Cyrix/NatSemi CS5530 chips.
@@ -268,7 +258,7 @@ config SND_CS5530
 
 config SND_CS5535AUDIO
        tristate "CS5535/CS5536 Audio"
-       depends on SND && X86 && !X86_64
+       depends on X86 && !X86_64
        select SND_PCM
        select SND_AC97_CODEC
        help
@@ -286,7 +276,6 @@ config SND_CS5535AUDIO
 
 config SND_DARLA20
        tristate "(Echoaudio) Darla20"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -297,7 +286,6 @@ config SND_DARLA20
 
 config SND_GINA20
        tristate "(Echoaudio) Gina20"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -308,7 +296,6 @@ config SND_GINA20
 
 config SND_LAYLA20
        tristate "(Echoaudio) Layla20"
-       depends on SND
        select FW_LOADER
        select SND_RAWMIDI
        select SND_PCM
@@ -320,7 +307,6 @@ config SND_LAYLA20
 
 config SND_DARLA24
        tristate "(Echoaudio) Darla24"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -331,7 +317,6 @@ config SND_DARLA24
 
 config SND_GINA24
        tristate "(Echoaudio) Gina24"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -342,7 +327,6 @@ config SND_GINA24
 
 config SND_LAYLA24
        tristate "(Echoaudio) Layla24"
-       depends on SND
        select FW_LOADER
        select SND_RAWMIDI
        select SND_PCM
@@ -354,7 +338,6 @@ config SND_LAYLA24
 
 config SND_MONA
        tristate "(Echoaudio) Mona"
-       depends on SND
        select FW_LOADER
        select SND_RAWMIDI
        select SND_PCM
@@ -366,7 +349,6 @@ config SND_MONA
 
 config SND_MIA
        tristate "(Echoaudio) Mia"
-       depends on SND
        select FW_LOADER
        select SND_RAWMIDI
        select SND_PCM
@@ -378,7 +360,6 @@ config SND_MIA
 
 config SND_ECHO3G
        tristate "(Echoaudio) 3G cards"
-       depends on SND
        select FW_LOADER
        select SND_RAWMIDI
        select SND_PCM
@@ -390,7 +371,6 @@ config SND_ECHO3G
 
 config SND_INDIGO
        tristate "(Echoaudio) Indigo"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -401,7 +381,6 @@ config SND_INDIGO
 
 config SND_INDIGOIO
        tristate "(Echoaudio) Indigo IO"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -412,7 +391,6 @@ config SND_INDIGOIO
 
 config SND_INDIGODJ
        tristate "(Echoaudio) Indigo DJ"
-       depends on SND
        select FW_LOADER
        select SND_PCM
        help
@@ -423,7 +401,6 @@ config SND_INDIGODJ
 
 config SND_EMU10K1
        tristate "Emu10k1 (SB Live!, Audigy, E-mu APS)"
-       depends on SND
        select FW_LOADER
        select SND_HWDEP
        select SND_RAWMIDI
@@ -441,7 +418,6 @@ config SND_EMU10K1
 
 config SND_EMU10K1X
        tristate "Emu10k1X (Dell OEM Version)"
-       depends on SND
        select SND_AC97_CODEC
        select SND_RAWMIDI
        help
@@ -453,7 +429,6 @@ config SND_EMU10K1X
 
 config SND_ENS1370
        tristate "(Creative) Ensoniq AudioPCI 1370"
-       depends on SND
        select SND_RAWMIDI
        select SND_PCM
        help
@@ -464,7 +439,6 @@ config SND_ENS1370
 
 config SND_ENS1371
        tristate "(Creative) Ensoniq AudioPCI 1371/1373"
-       depends on SND
        select SND_RAWMIDI
        select SND_AC97_CODEC
        help
@@ -476,7 +450,6 @@ config SND_ENS1371
 
 config SND_ES1938
        tristate "ESS ES1938/1946/1969 (Solo-1)"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_AC97_CODEC
@@ -489,7 +462,6 @@ config SND_ES1938
 
 config SND_ES1968
        tristate "ESS ES1968/1978 (Maestro-1/2/2E)"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -501,7 +473,6 @@ config SND_ES1968
 
 config SND_FM801
        tristate "ForteMedia FM801"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_AC97_CODEC
@@ -528,7 +499,6 @@ config SND_FM801_TEA575X
 
 config SND_HDA_INTEL
        tristate "Intel HD Audio"
-       depends on SND
        select SND_PCM
        select SND_VMASTER
        help
@@ -637,7 +607,6 @@ config SND_HDA_POWER_SAVE_DEFAULT
 
 config SND_HDSP
        tristate "RME Hammerfall DSP Audio"
-       depends on SND
        select SND_HWDEP
        select SND_RAWMIDI
        select SND_PCM
@@ -650,7 +619,6 @@ config SND_HDSP
 
 config SND_HDSPM
        tristate "RME Hammerfall DSP MADI"
-       depends on SND
        select SND_HWDEP
        select SND_RAWMIDI
        select SND_PCM
@@ -663,7 +631,6 @@ config SND_HDSPM
 
 config SND_HIFIER
        tristate "TempoTec HiFier Fantasia"
-       depends on SND
        select SND_OXYGEN_LIB
        help
          Say Y here to include support for the MediaTek/TempoTec HiFier
@@ -674,7 +641,6 @@ config SND_HIFIER
 
 config SND_ICE1712
        tristate "ICEnsemble ICE1712 (Envy24)"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -691,8 +657,7 @@ config SND_ICE1712
 
 config SND_ICE1724
        tristate "ICE/VT1724/1720 (Envy24HT/PT)"
-       depends on SND
-       select SND_MPU401_UART
+       select SND_RAWMIDI
        select SND_AC97_CODEC
        select SND_VMASTER
        help
@@ -709,7 +674,6 @@ config SND_ICE1724
 
 config SND_INTEL8X0
        tristate "Intel/SiS/nVidia/AMD/ALi AC97 Controller"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated AC97 sound
@@ -722,7 +686,6 @@ config SND_INTEL8X0
 
 config SND_INTEL8X0M
        tristate "Intel/SiS/nVidia/AMD MC97 Modem"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated MC97 modem on
@@ -733,7 +696,6 @@ config SND_INTEL8X0M
 
 config SND_KORG1212
        tristate "Korg 1212 IO"
-       depends on SND
        select FW_LOADER if !SND_KORG1212_FIRMWARE_IN_KERNEL
        select SND_PCM
        help
@@ -753,7 +715,6 @@ config SND_KORG1212_FIRMWARE_IN_KERNEL
 
 config SND_MAESTRO3
        tristate "ESS Allegro/Maestro3"
-       depends on SND
        select FW_LOADER if !SND_MAESTRO3_FIRMWARE_IN_KERNEL
        select SND_AC97_CODEC
        help
@@ -774,7 +735,6 @@ config SND_MAESTRO3_FIRMWARE_IN_KERNEL
 
 config SND_MIXART
        tristate "Digigram miXart"
-       depends on SND
        select SND_HWDEP
        select SND_PCM
        help
@@ -786,7 +746,6 @@ config SND_MIXART
 
 config SND_NM256
        tristate "NeoMagic NM256AV/ZX"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for NeoMagic NM256AV/ZX chips.
@@ -796,7 +755,6 @@ config SND_NM256
 
 config SND_PCXHR
        tristate "Digigram PCXHR"
-       depends on SND
        select SND_PCM
        select SND_HWDEP
        help
@@ -807,7 +765,6 @@ config SND_PCXHR
 
 config SND_RIPTIDE
        tristate "Conexant Riptide"
-       depends on SND
        select FW_LOADER
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -820,7 +777,6 @@ config SND_RIPTIDE
 
 config SND_RME32
        tristate "RME Digi32, 32/8, 32 PRO"
-       depends on SND
        select SND_PCM
        help
          Say Y to include support for RME Digi32, Digi32 PRO and
@@ -832,7 +788,6 @@ config SND_RME32
 
 config SND_RME96
        tristate "RME Digi96, 96/8, 96/8 PRO"
-       depends on SND
        select SND_PCM
        help
          Say Y here to include support for RME Digi96, Digi96/8 and
@@ -843,7 +798,6 @@ config SND_RME96
 
 config SND_RME9652
        tristate "RME Digi9652 (Hammerfall)"
-       depends on SND
        select SND_PCM
        help
          Say Y here to include support for RME Hammerfall (RME
@@ -854,7 +808,7 @@ config SND_RME9652
 
 config SND_SIS7019
        tristate "SiS 7019 Audio Accelerator"
-       depends on SND && X86 && !X86_64
+       depends on X86 && !X86_64
        select SND_AC97_CODEC
        help
          Say Y here to include support for the SiS 7019 Audio Accelerator.
@@ -864,7 +818,6 @@ config SND_SIS7019
 
 config SND_SONICVIBES
        tristate "S3 SonicVibes"
-       depends on SND
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_AC97_CODEC
@@ -877,7 +830,6 @@ config SND_SONICVIBES
 
 config SND_TRIDENT
        tristate "Trident 4D-Wave DX/NX; SiS 7018"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -889,7 +841,6 @@ config SND_TRIDENT
 
 config SND_VIA82XX
        tristate "VIA 82C686A/B, 8233/8235 AC97 Controller"
-       depends on SND
        select SND_MPU401_UART
        select SND_AC97_CODEC
        help
@@ -901,7 +852,6 @@ config SND_VIA82XX
 
 config SND_VIA82XX_MODEM
        tristate "VIA 82C686A/B, 8233 based Modems"
-       depends on SND
        select SND_AC97_CODEC
        help
          Say Y here to include support for the integrated MC97 modem on
@@ -912,7 +862,6 @@ config SND_VIA82XX_MODEM
 
 config SND_VIRTUOSO
        tristate "Asus Virtuoso 100/200 (Xonar)"
-       depends on SND
        select SND_OXYGEN_LIB
        help
          Say Y here to include support for sound cards based on the
@@ -923,7 +872,6 @@ config SND_VIRTUOSO
 
 config SND_VX222
        tristate "Digigram VX222"
-       depends on SND
        select SND_VX_LIB
        help
          Say Y here to include support for Digigram VX222 soundcards.
@@ -933,7 +881,6 @@ config SND_VX222
 
 config SND_YMFPCI
        tristate "Yamaha YMF724/740/744/754"
-       depends on SND
        select FW_LOADER if !SND_YMFPCI_FIRMWARE_IN_KERNEL
        select SND_OPL3_LIB
        select SND_MPU401_UART
@@ -954,25 +901,4 @@ config SND_YMFPCI_FIRMWARE_IN_KERNEL
          for the YMFPCI driver.  If you choose N here, you need to
          install the firmware files from the alsa-firmware package.
 
-config SND_AC97_POWER_SAVE
-       bool "AC97 Power-Saving Mode"
-       depends on SND_AC97_CODEC && EXPERIMENTAL
-       default n
-       help
-         Say Y here to enable the aggressive power-saving support of
-         AC97 codecs.  In this mode, the power-mode is dynamically
-         controlled at each open/close.
-
-         The mode is activated by passing power_save=1 option to
-         snd-ac97-codec driver.  You can toggle it dynamically over
-         sysfs, too.
-
-config SND_AC97_POWER_SAVE_DEFAULT
-       int "Default time-out for AC97 power-save mode"
-       depends on SND_AC97_POWER_SAVE
-       default 0
-       help
-         The default time-out value in seconds for AC97 automatic
-         power-save mode.  0 means to disable the power-save mode.
-
-endmenu
+endif  # SND_PCI
index 85ef14b..65b25d2 100644 (file)
@@ -13,7 +13,7 @@ snd-bt87x-objs := bt87x.o
 snd-cmipci-objs := cmipci.o
 snd-cs4281-objs := cs4281.o
 snd-cs5530-objs := cs5530.o
-snd-ens1370-objs := ens1370.o
+snd-ens1370-objs := ens1370.o ak4531_codec.o
 snd-ens1371-objs := ens1371.o
 snd-es1938-objs := es1938.o
 snd-es1968-objs := es1968.o
index 0be48b1..41fa322 100644 (file)
@@ -3,16 +3,8 @@
 # Copyright (c) 2001 by Jaroslav Kysela <perex@perex.cz>
 #
 
-snd-ac97-codec-objs := ac97_codec.o ac97_pcm.o
-
-ifneq ($(CONFIG_PROC_FS),)
-snd-ac97-codec-objs += ac97_proc.o
-endif
-
-snd-ak4531-codec-objs := ak4531_codec.o
+snd-ac97-codec-y := ac97_codec.o ac97_pcm.o
+snd-ac97-codec-$(CONFIG_PROC_FS) += ac97_proc.o
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_AC97_CODEC) += snd-ac97-codec.o
-obj-$(CONFIG_SND_ENS1370) += snd-ak4531-codec.o
-
-obj-m := $(sort $(obj-m))
index 45fd290..07364c0 100644 (file)
@@ -49,8 +49,9 @@ MODULE_PARM_DESC(enable_loopback, "Enable AC97 ADC/DAC Loopback Control");
 
 #ifdef CONFIG_SND_AC97_POWER_SAVE
 static int power_save = CONFIG_SND_AC97_POWER_SAVE_DEFAULT;
-module_param(power_save, bool, 0644);
-MODULE_PARM_DESC(power_save, "Enable AC97 power-saving control");
+module_param(power_save, int, 0644);
+MODULE_PARM_DESC(power_save, "Automatic power-saving timeout "
+                "(in second, 0 = disable).");
 #endif
 /*
 
@@ -2294,9 +2295,11 @@ static void snd_ac97_powerdown(struct snd_ac97 *ac97)
        power |= AC97_PD_PR0 | AC97_PD_PR1;     /* ADC & DAC powerdown */
        snd_ac97_write(ac97, AC97_POWERDOWN, power);
        udelay(100);
-       power |= AC97_PD_PR2 | AC97_PD_PR3;     /* Analog Mixer powerdown */
+       power |= AC97_PD_PR2;   /* Analog Mixer powerdown (Vref on) */
        snd_ac97_write(ac97, AC97_POWERDOWN, power);
        if (ac97_is_power_save_mode(ac97)) {
+               power |= AC97_PD_PR3;   /* Analog Mixer powerdown */
+               snd_ac97_write(ac97, AC97_POWERDOWN, power);
                udelay(100);
                /* AC-link powerdown, internal Clk disable */
                /* FIXME: this may cause click noises on some boards */
@@ -2362,7 +2365,7 @@ int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
                 *  that open/close frequently)
                 */
                schedule_delayed_work(&ac97->power_work,
-                                     msecs_to_jiffies(2000));
+                                     msecs_to_jiffies(power_save * 1000));
        else {
                cancel_delayed_work(&ac97->power_work);
                update_power_regs(ac97);
index 1292dce..0746e9c 100644 (file)
@@ -669,6 +669,7 @@ AC97_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
 AC97_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
 AC97_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
 
+AC97_SINGLE("Master Left Inv Switch", AC97_MASTER, 6, 1, 0),
 AC97_SINGLE("Master ZC Switch", AC97_MASTER, 7, 1, 0),
 AC97_SINGLE("Headphone ZC Switch", AC97_HEADPHONE, 7, 1, 0),
 AC97_SINGLE("Mono ZC Switch", AC97_MASTER_MONO, 7, 1, 0),
@@ -3352,8 +3353,66 @@ AC97_SINGLE("Downmix LFE and Center to Front", 0x5a, 12, 1, 0),
 AC97_SINGLE("Downmix Surround to Front", 0x5a, 11, 1, 0),
 };
 
+static const char *slave_vols_vt1616[] = {
+       "Front Playback Volume",
+       "Surround Playback Volume",
+       "Center Playback Volume",
+       "LFE Playback Volume",
+       NULL
+};
+
+static const char *slave_sws_vt1616[] = {
+       "Front Playback Switch",
+       "Surround Playback Switch",
+       "Center Playback Switch",
+       "LFE Playback Switch",
+       NULL
+};
+
+/* find a mixer control element with the given name */
+static struct snd_kcontrol *snd_ac97_find_mixer_ctl(struct snd_ac97 *ac97,
+                                                   const char *name)
+{
+       struct snd_ctl_elem_id id;
+       memset(&id, 0, sizeof(id));
+       id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+       strcpy(id.name, name);
+       return snd_ctl_find_id(ac97->bus->card, &id);
+}
+
+/* create a virtual master control and add slaves */
+int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,
+                        const unsigned int *tlv, const char **slaves)
+{
+       struct snd_kcontrol *kctl;
+       const char **s;
+       int err;
+
+       kctl = snd_ctl_make_virtual_master(name, tlv);
+       if (!kctl)
+               return -ENOMEM;
+       err = snd_ctl_add(ac97->bus->card, kctl);
+       if (err < 0)
+               return err;
+
+       for (s = slaves; *s; s++) {
+               struct snd_kcontrol *sctl;
+
+               sctl = snd_ac97_find_mixer_ctl(ac97, *s);
+               if (!sctl) {
+                       snd_printdd("Cannot find slave %s, skipped\n", *s);
+                       continue;
+               }
+               err = snd_ctl_add_slave(kctl, sctl);
+               if (err < 0)
+                       return err;
+       }
+       return 0;
+}
+
 static int patch_vt1616_specific(struct snd_ac97 * ac97)
 {
+       struct snd_kcontrol *kctl;
        int err;
 
        if (snd_ac97_try_bit(ac97, 0x5a, 9))
@@ -3361,6 +3420,24 @@ static int patch_vt1616_specific(struct snd_ac97 * ac97)
                        return err;
        if ((err = patch_build_controls(ac97, &snd_ac97_controls_vt1616[1], ARRAY_SIZE(snd_ac97_controls_vt1616) - 1)) < 0)
                return err;
+
+       /* There is already a misnamed master switch.  Rename it.  */
+       kctl = snd_ac97_find_mixer_ctl(ac97, "Master Playback Volume");
+       if (!kctl)
+               return -EINVAL;
+
+       snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Front Playback");
+
+       err = snd_ac97_add_vmaster(ac97, "Master Playback Volume",
+                                  kctl->tlv.p, slave_vols_vt1616);
+       if (err < 0)
+               return err;
+
+       err = snd_ac97_add_vmaster(ac97, "Master Playback Switch",
+                                  NULL, slave_sws_vt1616);
+       if (err < 0)
+               return err;
+
        return 0;
 }
 
@@ -3633,7 +3710,7 @@ static int patch_ucb1400(struct snd_ac97 * ac97)
 {
        ac97->build_ops = &patch_ucb1400_ops;
        /* enable headphone driver and smart low power mode by default */
-       snd_ac97_write(ac97, 0x6a, 0x0050);
-       snd_ac97_write(ac97, 0x6c, 0x0030);
+       snd_ac97_write_cache(ac97, 0x6a, 0x0050);
+       snd_ac97_write_cache(ac97, 0x6c, 0x0030);
        return 0;
 }
diff --git a/sound/pci/ac97/ak4531_codec.c b/sound/pci/ac97/ak4531_codec.c
deleted file mode 100644 (file)
index c0c1633..0000000
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
- *  Universal routines for AK4531 codec
- *
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- *
- */
-
-#include <linux/delay.h>
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/mutex.h>
-
-#include <sound/core.h>
-#include <sound/ak4531_codec.h>
-#include <sound/tlv.h>
-
-MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
-MODULE_DESCRIPTION("Universal routines for AK4531 codec");
-MODULE_LICENSE("GPL");
-
-#ifdef CONFIG_PROC_FS
-static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);
-#else
-#define snd_ak4531_proc_init(card,ak)
-#endif
-
-/*
- *
- */
-#if 0
-
-static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
-{
-       int idx;
-       
-       for (idx = 0; idx < 0x19; idx++)
-               printk("ak4531 0x%x: 0x%x\n", idx, ak4531->regs[idx]);
-}
-
-#endif
-
-/*
- *
- */
-
-#define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_ak4531_info_single, \
-  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
-  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }
-#define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv)    \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
-  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
-  .name = xname, .index = xindex, \
-  .info = snd_ak4531_info_single, \
-  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
-  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \
-  .tlv = { .p = (xtlv) } }
-
-static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 16) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       int val;
-
-       mutex_lock(&ak4531->reg_mutex);
-       val = (ak4531->regs[reg] >> shift) & mask;
-       mutex_unlock(&ak4531->reg_mutex);
-       if (invert) {
-               val = mask - val;
-       }
-       ucontrol->value.integer.value[0] = val;
-       return 0;
-}
-
-static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int reg = kcontrol->private_value & 0xff;
-       int shift = (kcontrol->private_value >> 16) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       int change;
-       int val;
-
-       val = ucontrol->value.integer.value[0] & mask;
-       if (invert) {
-               val = mask - val;
-       }
-       val <<= shift;
-       mutex_lock(&ak4531->reg_mutex);
-       val = (ak4531->regs[reg] & ~(mask << shift)) | val;
-       change = val != ak4531->regs[reg];
-       ak4531->write(ak4531, reg, ak4531->regs[reg] = val);
-       mutex_unlock(&ak4531->reg_mutex);
-       return change;
-}
-
-#define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_ak4531_info_double, \
-  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
-  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }
-#define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
-  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
-  .name = xname, .index = xindex, \
-  .info = snd_ak4531_info_double, \
-  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
-  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \
-  .tlv = { .p = (xtlv) } }
-
-static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 2;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int left_reg = kcontrol->private_value & 0xff;
-       int right_reg = (kcontrol->private_value >> 8) & 0xff;
-       int left_shift = (kcontrol->private_value >> 16) & 0x07;
-       int right_shift = (kcontrol->private_value >> 19) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       int left, right;
-
-       mutex_lock(&ak4531->reg_mutex);
-       left = (ak4531->regs[left_reg] >> left_shift) & mask;
-       right = (ak4531->regs[right_reg] >> right_shift) & mask;
-       mutex_unlock(&ak4531->reg_mutex);
-       if (invert) {
-               left = mask - left;
-               right = mask - right;
-       }
-       ucontrol->value.integer.value[0] = left;
-       ucontrol->value.integer.value[1] = right;
-       return 0;
-}
-
-static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int left_reg = kcontrol->private_value & 0xff;
-       int right_reg = (kcontrol->private_value >> 8) & 0xff;
-       int left_shift = (kcontrol->private_value >> 16) & 0x07;
-       int right_shift = (kcontrol->private_value >> 19) & 0x07;
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-       int invert = (kcontrol->private_value >> 22) & 1;
-       int change;
-       int left, right;
-
-       left = ucontrol->value.integer.value[0] & mask;
-       right = ucontrol->value.integer.value[1] & mask;
-       if (invert) {
-               left = mask - left;
-               right = mask - right;
-       }
-       left <<= left_shift;
-       right <<= right_shift;
-       mutex_lock(&ak4531->reg_mutex);
-       if (left_reg == right_reg) {
-               left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;
-               change = left != ak4531->regs[left_reg];
-               ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
-       } else {
-               left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left;
-               right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right;
-               change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg];
-               ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
-               ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);
-       }
-       mutex_unlock(&ak4531->reg_mutex);
-       return change;
-}
-
-#define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \
-{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_ak4531_info_input_sw, \
-  .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \
-  .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }
-
-static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 4;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
-static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int reg1 = kcontrol->private_value & 0xff;
-       int reg2 = (kcontrol->private_value >> 8) & 0xff;
-       int left_shift = (kcontrol->private_value >> 16) & 0x0f;
-       int right_shift = (kcontrol->private_value >> 24) & 0x0f;
-
-       mutex_lock(&ak4531->reg_mutex);
-       ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;
-       ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;
-       ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;
-       ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;
-       mutex_unlock(&ak4531->reg_mutex);
-       return 0;
-}
-
-static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
-       int reg1 = kcontrol->private_value & 0xff;
-       int reg2 = (kcontrol->private_value >> 8) & 0xff;
-       int left_shift = (kcontrol->private_value >> 16) & 0x0f;
-       int right_shift = (kcontrol->private_value >> 24) & 0x0f;
-       int change;
-       int val1, val2;
-
-       mutex_lock(&ak4531->reg_mutex);
-       val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));
-       val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));
-       val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
-       val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift;
-       val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift;
-       val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift;
-       change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2];
-       ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1);
-       ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2);
-       mutex_unlock(&ak4531->reg_mutex);
-       return change;
-}
-
-static const DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0);
-static const DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0);
-static const DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0);
-
-static struct snd_kcontrol_new snd_ak4531_controls[] = {
-
-AK4531_DOUBLE_TLV("Master Playback Switch", 0,
-                 AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1,
-                 db_scale_master),
-AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),
-
-AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1,
-                 db_scale_mono),
-AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),
-
-AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),
-AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1,
-                 db_scale_input),
-AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),
-AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),
-
-AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),
-AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1,
-                 db_scale_input),
-AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),
-AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),
-
-AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),
-AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1,
-                 db_scale_input),
-AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),
-AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),
-
-AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),
-AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1,
-                 db_scale_input),
-AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),
-AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),
-
-AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),
-AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1,
-                 db_scale_input),
-AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),
-AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),
-
-AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),
-AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input),
-AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),
-AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),
-
-AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),
-AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input),
-AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),
-AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),
-
-AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input),
-AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),
-AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),
-AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),
-
-AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0),
-AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0),
-AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0),
-
-AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),
-AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)
-};
-
-static int snd_ak4531_free(struct snd_ak4531 *ak4531)
-{
-       if (ak4531) {
-               if (ak4531->private_free)
-                       ak4531->private_free(ak4531);
-               kfree(ak4531);
-       }
-       return 0;
-}
-
-static int snd_ak4531_dev_free(struct snd_device *device)
-{
-       struct snd_ak4531 *ak4531 = device->device_data;
-       return snd_ak4531_free(ak4531);
-}
-
-static u8 snd_ak4531_initial_map[0x19 + 1] = {
-       0x9f,           /* 00: Master Volume Lch */
-       0x9f,           /* 01: Master Volume Rch */
-       0x9f,           /* 02: Voice Volume Lch */
-       0x9f,           /* 03: Voice Volume Rch */
-       0x9f,           /* 04: FM Volume Lch */
-       0x9f,           /* 05: FM Volume Rch */
-       0x9f,           /* 06: CD Audio Volume Lch */
-       0x9f,           /* 07: CD Audio Volume Rch */
-       0x9f,           /* 08: Line Volume Lch */
-       0x9f,           /* 09: Line Volume Rch */
-       0x9f,           /* 0a: Aux Volume Lch */
-       0x9f,           /* 0b: Aux Volume Rch */
-       0x9f,           /* 0c: Mono1 Volume */
-       0x9f,           /* 0d: Mono2 Volume */
-       0x9f,           /* 0e: Mic Volume */
-       0x87,           /* 0f: Mono-out Volume */
-       0x00,           /* 10: Output Mixer SW1 */
-       0x00,           /* 11: Output Mixer SW2 */
-       0x00,           /* 12: Lch Input Mixer SW1 */
-       0x00,           /* 13: Rch Input Mixer SW1 */
-       0x00,           /* 14: Lch Input Mixer SW2 */
-       0x00,           /* 15: Rch Input Mixer SW2 */
-       0x00,           /* 16: Reset & Power Down */
-       0x00,           /* 17: Clock Select */
-       0x00,           /* 18: AD Input Select */
-       0x01            /* 19: Mic Amp Setup */
-};
-
-int snd_ak4531_mixer(struct snd_card *card, struct snd_ak4531 *_ak4531,
-                    struct snd_ak4531 **rak4531)
-{
-       unsigned int idx;
-       int err;
-       struct snd_ak4531 *ak4531;
-       static struct snd_device_ops ops = {
-               .dev_free =     snd_ak4531_dev_free,
-       };
-
-       snd_assert(rak4531 != NULL, return -EINVAL);
-       *rak4531 = NULL;
-       snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL);
-       ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
-       if (ak4531 == NULL)
-               return -ENOMEM;
-       *ak4531 = *_ak4531;
-       mutex_init(&ak4531->reg_mutex);
-       if ((err = snd_component_add(card, "AK4531")) < 0) {
-               snd_ak4531_free(ak4531);
-               return err;
-       }
-       strcpy(card->mixername, "Asahi Kasei AK4531");
-       ak4531->write(ak4531, AK4531_RESET, 0x03);      /* no RST, PD */
-       udelay(100);
-       ak4531->write(ak4531, AK4531_CLOCK, 0x00);      /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */
-       for (idx = 0; idx <= 0x19; idx++) {
-               if (idx == AK4531_RESET || idx == AK4531_CLOCK)
-                       continue;
-               ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]);    /* recording source is mixer */
-       }
-       for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) {
-               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) {
-                       snd_ak4531_free(ak4531);
-                       return err;
-               }
-       }
-       snd_ak4531_proc_init(card, ak4531);
-       if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) {
-               snd_ak4531_free(ak4531);
-               return err;
-       }
-
-#if 0
-       snd_ak4531_dump(ak4531);
-#endif
-       *rak4531 = ak4531;
-       return 0;
-}
-
-/*
- * power management
- */
-#ifdef CONFIG_PM
-void snd_ak4531_suspend(struct snd_ak4531 *ak4531)
-{
-       /* mute */
-       ak4531->write(ak4531, AK4531_LMASTER, 0x9f);
-       ak4531->write(ak4531, AK4531_RMASTER, 0x9f);
-       /* powerdown */
-       ak4531->write(ak4531, AK4531_RESET, 0x01);
-}
-
-void snd_ak4531_resume(struct snd_ak4531 *ak4531)
-{
-       int idx;
-
-       /* initialize */
-       ak4531->write(ak4531, AK4531_RESET, 0x03);
-       udelay(100);
-       ak4531->write(ak4531, AK4531_CLOCK, 0x00);
-       /* restore mixer registers */
-       for (idx = 0; idx <= 0x19; idx++) {
-               if (idx == AK4531_RESET || idx == AK4531_CLOCK)
-                       continue;
-               ak4531->write(ak4531, idx, ak4531->regs[idx]);
-       }
-}
-#endif
-
-#ifdef CONFIG_PROC_FS
-/*
- * /proc interface
- */
-
-static void snd_ak4531_proc_read(struct snd_info_entry *entry, 
-                                struct snd_info_buffer *buffer)
-{
-       struct snd_ak4531 *ak4531 = entry->private_data;
-
-       snd_iprintf(buffer, "Asahi Kasei AK4531\n\n");
-       snd_iprintf(buffer, "Recording source   : %s\n"
-                   "MIC gain           : %s\n",
-                   ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer",
-                   ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");
-}
-
-static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531)
-{
-       struct snd_info_entry *entry;
-
-       if (! snd_card_proc_new(card, "ak4531", &entry))
-               snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read);
-}
-#endif
-
-EXPORT_SYMBOL(snd_ak4531_mixer);
-#ifdef CONFIG_PM
-EXPORT_SYMBOL(snd_ak4531_suspend);
-EXPORT_SYMBOL(snd_ak4531_resume);
-#endif
-
-/*
- *  INIT part
- */
-
-static int __init alsa_ak4531_init(void)
-{
-       return 0;
-}
-
-static void __exit alsa_ak4531_exit(void)
-{
-}
-
-module_init(alsa_ak4531_init)
-module_exit(alsa_ak4531_exit)
diff --git a/sound/pci/ak4531_codec.c b/sound/pci/ak4531_codec.c
new file mode 100644 (file)
index 0000000..33d37b1
--- /dev/null
@@ -0,0 +1,490 @@
+/*
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
+ *  Universal routines for AK4531 codec
+ *
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+
+#include <sound/core.h>
+#include <sound/ak4531_codec.h>
+#include <sound/tlv.h>
+
+/*
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
+MODULE_DESCRIPTION("Universal routines for AK4531 codec");
+MODULE_LICENSE("GPL");
+*/
+
+#ifdef CONFIG_PROC_FS
+static void snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531);
+#else
+#define snd_ak4531_proc_init(card,ak)
+#endif
+
+/*
+ *
+ */
+#if 0
+
+static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
+{
+       int idx;
+       
+       for (idx = 0; idx < 0x19; idx++)
+               printk("ak4531 0x%x: 0x%x\n", idx, ak4531->regs[idx]);
+}
+
+#endif
+
+/*
+ *
+ */
+
+#define AK4531_SINGLE(xname, xindex, reg, shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_single, \
+  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
+  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22) }
+#define AK4531_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv)    \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_single, \
+  .get = snd_ak4531_get_single, .put = snd_ak4531_put_single, \
+  .private_value = reg | (shift << 16) | (mask << 24) | (invert << 22), \
+  .tlv = { .p = (xtlv) } }
+
+static int snd_ak4531_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+
+       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = mask;
+       return 0;
+}
+static int snd_ak4531_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int shift = (kcontrol->private_value >> 16) & 0x07;
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+       int invert = (kcontrol->private_value >> 22) & 1;
+       int val;
+
+       mutex_lock(&ak4531->reg_mutex);
+       val = (ak4531->regs[reg] >> shift) & mask;
+       mutex_unlock(&ak4531->reg_mutex);
+       if (invert) {
+               val = mask - val;
+       }
+       ucontrol->value.integer.value[0] = val;
+       return 0;
+}
+
+static int snd_ak4531_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int shift = (kcontrol->private_value >> 16) & 0x07;
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+       int invert = (kcontrol->private_value >> 22) & 1;
+       int change;
+       int val;
+
+       val = ucontrol->value.integer.value[0] & mask;
+       if (invert) {
+               val = mask - val;
+       }
+       val <<= shift;
+       mutex_lock(&ak4531->reg_mutex);
+       val = (ak4531->regs[reg] & ~(mask << shift)) | val;
+       change = val != ak4531->regs[reg];
+       ak4531->write(ak4531, reg, ak4531->regs[reg] = val);
+       mutex_unlock(&ak4531->reg_mutex);
+       return change;
+}
+
+#define AK4531_DOUBLE(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_double, \
+  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
+  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22) }
+#define AK4531_DOUBLE_TLV(xname, xindex, left_reg, right_reg, left_shift, right_shift, mask, invert, xtlv) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_double, \
+  .get = snd_ak4531_get_double, .put = snd_ak4531_put_double, \
+  .private_value = left_reg | (right_reg << 8) | (left_shift << 16) | (right_shift << 19) | (mask << 24) | (invert << 22), \
+  .tlv = { .p = (xtlv) } }
+
+static int snd_ak4531_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+
+       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = mask;
+       return 0;
+}
+static int snd_ak4531_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int left_reg = kcontrol->private_value & 0xff;
+       int right_reg = (kcontrol->private_value >> 8) & 0xff;
+       int left_shift = (kcontrol->private_value >> 16) & 0x07;
+       int right_shift = (kcontrol->private_value >> 19) & 0x07;
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+       int invert = (kcontrol->private_value >> 22) & 1;
+       int left, right;
+
+       mutex_lock(&ak4531->reg_mutex);
+       left = (ak4531->regs[left_reg] >> left_shift) & mask;
+       right = (ak4531->regs[right_reg] >> right_shift) & mask;
+       mutex_unlock(&ak4531->reg_mutex);
+       if (invert) {
+               left = mask - left;
+               right = mask - right;
+       }
+       ucontrol->value.integer.value[0] = left;
+       ucontrol->value.integer.value[1] = right;
+       return 0;
+}
+
+static int snd_ak4531_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int left_reg = kcontrol->private_value & 0xff;
+       int right_reg = (kcontrol->private_value >> 8) & 0xff;
+       int left_shift = (kcontrol->private_value >> 16) & 0x07;
+       int right_shift = (kcontrol->private_value >> 19) & 0x07;
+       int mask = (kcontrol->private_value >> 24) & 0xff;
+       int invert = (kcontrol->private_value >> 22) & 1;
+       int change;
+       int left, right;
+
+       left = ucontrol->value.integer.value[0] & mask;
+       right = ucontrol->value.integer.value[1] & mask;
+       if (invert) {
+               left = mask - left;
+               right = mask - right;
+       }
+       left <<= left_shift;
+       right <<= right_shift;
+       mutex_lock(&ak4531->reg_mutex);
+       if (left_reg == right_reg) {
+               left = (ak4531->regs[left_reg] & ~((mask << left_shift) | (mask << right_shift))) | left | right;
+               change = left != ak4531->regs[left_reg];
+               ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
+       } else {
+               left = (ak4531->regs[left_reg] & ~(mask << left_shift)) | left;
+               right = (ak4531->regs[right_reg] & ~(mask << right_shift)) | right;
+               change = left != ak4531->regs[left_reg] || right != ak4531->regs[right_reg];
+               ak4531->write(ak4531, left_reg, ak4531->regs[left_reg] = left);
+               ak4531->write(ak4531, right_reg, ak4531->regs[right_reg] = right);
+       }
+       mutex_unlock(&ak4531->reg_mutex);
+       return change;
+}
+
+#define AK4531_INPUT_SW(xname, xindex, reg1, reg2, left_shift, right_shift) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
+  .info = snd_ak4531_info_input_sw, \
+  .get = snd_ak4531_get_input_sw, .put = snd_ak4531_put_input_sw, \
+  .private_value = reg1 | (reg2 << 8) | (left_shift << 16) | (right_shift << 24) }
+
+static int snd_ak4531_info_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+       uinfo->count = 4;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 1;
+       return 0;
+}
+static int snd_ak4531_get_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int reg1 = kcontrol->private_value & 0xff;
+       int reg2 = (kcontrol->private_value >> 8) & 0xff;
+       int left_shift = (kcontrol->private_value >> 16) & 0x0f;
+       int right_shift = (kcontrol->private_value >> 24) & 0x0f;
+
+       mutex_lock(&ak4531->reg_mutex);
+       ucontrol->value.integer.value[0] = (ak4531->regs[reg1] >> left_shift) & 1;
+       ucontrol->value.integer.value[1] = (ak4531->regs[reg2] >> left_shift) & 1;
+       ucontrol->value.integer.value[2] = (ak4531->regs[reg1] >> right_shift) & 1;
+       ucontrol->value.integer.value[3] = (ak4531->regs[reg2] >> right_shift) & 1;
+       mutex_unlock(&ak4531->reg_mutex);
+       return 0;
+}
+
+static int snd_ak4531_put_input_sw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_ak4531 *ak4531 = snd_kcontrol_chip(kcontrol);
+       int reg1 = kcontrol->private_value & 0xff;
+       int reg2 = (kcontrol->private_value >> 8) & 0xff;
+       int left_shift = (kcontrol->private_value >> 16) & 0x0f;
+       int right_shift = (kcontrol->private_value >> 24) & 0x0f;
+       int change;
+       int val1, val2;
+
+       mutex_lock(&ak4531->reg_mutex);
+       val1 = ak4531->regs[reg1] & ~((1 << left_shift) | (1 << right_shift));
+       val2 = ak4531->regs[reg2] & ~((1 << left_shift) | (1 << right_shift));
+       val1 |= (ucontrol->value.integer.value[0] & 1) << left_shift;
+       val2 |= (ucontrol->value.integer.value[1] & 1) << left_shift;
+       val1 |= (ucontrol->value.integer.value[2] & 1) << right_shift;
+       val2 |= (ucontrol->value.integer.value[3] & 1) << right_shift;
+       change = val1 != ak4531->regs[reg1] || val2 != ak4531->regs[reg2];
+       ak4531->write(ak4531, reg1, ak4531->regs[reg1] = val1);
+       ak4531->write(ak4531, reg2, ak4531->regs[reg2] = val2);
+       mutex_unlock(&ak4531->reg_mutex);
+       return change;
+}
+
+static const DECLARE_TLV_DB_SCALE(db_scale_master, -6200, 200, 0);
+static const DECLARE_TLV_DB_SCALE(db_scale_mono, -2800, 400, 0);
+static const DECLARE_TLV_DB_SCALE(db_scale_input, -5000, 200, 0);
+
+static struct snd_kcontrol_new snd_ak4531_controls[] __devinitdata = {
+
+AK4531_DOUBLE_TLV("Master Playback Switch", 0,
+                 AK4531_LMASTER, AK4531_RMASTER, 7, 7, 1, 1,
+                 db_scale_master),
+AK4531_DOUBLE("Master Playback Volume", 0, AK4531_LMASTER, AK4531_RMASTER, 0, 0, 0x1f, 1),
+
+AK4531_SINGLE_TLV("Master Mono Playback Switch", 0, AK4531_MONO_OUT, 7, 1, 1,
+                 db_scale_mono),
+AK4531_SINGLE("Master Mono Playback Volume", 0, AK4531_MONO_OUT, 0, 0x07, 1),
+
+AK4531_DOUBLE("PCM Switch", 0, AK4531_LVOICE, AK4531_RVOICE, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("PCM Volume", 0, AK4531_LVOICE, AK4531_RVOICE, 0, 0, 0x1f, 1,
+                 db_scale_input),
+AK4531_DOUBLE("PCM Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 3, 2, 1, 0),
+AK4531_DOUBLE("PCM Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 2, 2, 1, 0),
+
+AK4531_DOUBLE("PCM Switch", 1, AK4531_LFM, AK4531_RFM, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("PCM Volume", 1, AK4531_LFM, AK4531_RFM, 0, 0, 0x1f, 1,
+                 db_scale_input),
+AK4531_DOUBLE("PCM Playback Switch", 1, AK4531_OUT_SW1, AK4531_OUT_SW1, 6, 5, 1, 0),
+AK4531_INPUT_SW("PCM Capture Route", 1, AK4531_LIN_SW1, AK4531_RIN_SW1, 6, 5),
+
+AK4531_DOUBLE("CD Switch", 0, AK4531_LCD, AK4531_RCD, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("CD Volume", 0, AK4531_LCD, AK4531_RCD, 0, 0, 0x1f, 1,
+                 db_scale_input),
+AK4531_DOUBLE("CD Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 2, 1, 1, 0),
+AK4531_INPUT_SW("CD Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 2, 1),
+
+AK4531_DOUBLE("Line Switch", 0, AK4531_LLINE, AK4531_RLINE, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("Line Volume", 0, AK4531_LLINE, AK4531_RLINE, 0, 0, 0x1f, 1,
+                 db_scale_input),
+AK4531_DOUBLE("Line Playback Switch", 0, AK4531_OUT_SW1, AK4531_OUT_SW1, 4, 3, 1, 0),
+AK4531_INPUT_SW("Line Capture Route", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 4, 3),
+
+AK4531_DOUBLE("Aux Switch", 0, AK4531_LAUXA, AK4531_RAUXA, 7, 7, 1, 1),
+AK4531_DOUBLE_TLV("Aux Volume", 0, AK4531_LAUXA, AK4531_RAUXA, 0, 0, 0x1f, 1,
+                 db_scale_input),
+AK4531_DOUBLE("Aux Playback Switch", 0, AK4531_OUT_SW2, AK4531_OUT_SW2, 5, 4, 1, 0),
+AK4531_INPUT_SW("Aux Capture Route", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 4, 3),
+
+AK4531_SINGLE("Mono Switch", 0, AK4531_MONO1, 7, 1, 1),
+AK4531_SINGLE_TLV("Mono Volume", 0, AK4531_MONO1, 0, 0x1f, 1, db_scale_input),
+AK4531_SINGLE("Mono Playback Switch", 0, AK4531_OUT_SW2, 0, 1, 0),
+AK4531_DOUBLE("Mono Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 0, 0, 1, 0),
+
+AK4531_SINGLE("Mono Switch", 1, AK4531_MONO2, 7, 1, 1),
+AK4531_SINGLE_TLV("Mono Volume", 1, AK4531_MONO2, 0, 0x1f, 1, db_scale_input),
+AK4531_SINGLE("Mono Playback Switch", 1, AK4531_OUT_SW2, 1, 1, 0),
+AK4531_DOUBLE("Mono Capture Switch", 1, AK4531_LIN_SW2, AK4531_RIN_SW2, 1, 1, 1, 0),
+
+AK4531_SINGLE_TLV("Mic Volume", 0, AK4531_MIC, 0, 0x1f, 1, db_scale_input),
+AK4531_SINGLE("Mic Switch", 0, AK4531_MIC, 7, 1, 1),
+AK4531_SINGLE("Mic Playback Switch", 0, AK4531_OUT_SW1, 0, 1, 0),
+AK4531_DOUBLE("Mic Capture Switch", 0, AK4531_LIN_SW1, AK4531_RIN_SW1, 0, 0, 1, 0),
+
+AK4531_DOUBLE("Mic Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 7, 7, 1, 0),
+AK4531_DOUBLE("Mono1 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 6, 6, 1, 0),
+AK4531_DOUBLE("Mono2 Bypass Capture Switch", 0, AK4531_LIN_SW2, AK4531_RIN_SW2, 5, 5, 1, 0),
+
+AK4531_SINGLE("AD Input Select", 0, AK4531_AD_IN, 0, 1, 0),
+AK4531_SINGLE("Mic Boost (+30dB)", 0, AK4531_MIC_GAIN, 0, 1, 0)
+};
+
+static int snd_ak4531_free(struct snd_ak4531 *ak4531)
+{
+       if (ak4531) {
+               if (ak4531->private_free)
+                       ak4531->private_free(ak4531);
+               kfree(ak4531);
+       }
+       return 0;
+}
+
+static int snd_ak4531_dev_free(struct snd_device *device)
+{
+       struct snd_ak4531 *ak4531 = device->device_data;
+       return snd_ak4531_free(ak4531);
+}
+
+static u8 snd_ak4531_initial_map[0x19 + 1] = {
+       0x9f,           /* 00: Master Volume Lch */
+       0x9f,           /* 01: Master Volume Rch */
+       0x9f,           /* 02: Voice Volume Lch */
+       0x9f,           /* 03: Voice Volume Rch */
+       0x9f,           /* 04: FM Volume Lch */
+       0x9f,           /* 05: FM Volume Rch */
+       0x9f,           /* 06: CD Audio Volume Lch */
+       0x9f,           /* 07: CD Audio Volume Rch */
+       0x9f,           /* 08: Line Volume Lch */
+       0x9f,           /* 09: Line Volume Rch */
+       0x9f,           /* 0a: Aux Volume Lch */
+       0x9f,           /* 0b: Aux Volume Rch */
+       0x9f,           /* 0c: Mono1 Volume */
+       0x9f,           /* 0d: Mono2 Volume */
+       0x9f,           /* 0e: Mic Volume */
+       0x87,           /* 0f: Mono-out Volume */
+       0x00,           /* 10: Output Mixer SW1 */
+       0x00,           /* 11: Output Mixer SW2 */
+       0x00,           /* 12: Lch Input Mixer SW1 */
+       0x00,           /* 13: Rch Input Mixer SW1 */
+       0x00,           /* 14: Lch Input Mixer SW2 */
+       0x00,           /* 15: Rch Input Mixer SW2 */
+       0x00,           /* 16: Reset & Power Down */
+       0x00,           /* 17: Clock Select */
+       0x00,           /* 18: AD Input Select */
+       0x01            /* 19: Mic Amp Setup */
+};
+
+int __devinit snd_ak4531_mixer(struct snd_card *card,
+                              struct snd_ak4531 *_ak4531,
+                              struct snd_ak4531 **rak4531)
+{
+       unsigned int idx;
+       int err;
+       struct snd_ak4531 *ak4531;
+       static struct snd_device_ops ops = {
+               .dev_free =     snd_ak4531_dev_free,
+       };
+
+       snd_assert(rak4531 != NULL, return -EINVAL);
+       *rak4531 = NULL;
+       snd_assert(card != NULL && _ak4531 != NULL, return -EINVAL);
+       ak4531 = kzalloc(sizeof(*ak4531), GFP_KERNEL);
+       if (ak4531 == NULL)
+               return -ENOMEM;
+       *ak4531 = *_ak4531;
+       mutex_init(&ak4531->reg_mutex);
+       if ((err = snd_component_add(card, "AK4531")) < 0) {
+               snd_ak4531_free(ak4531);
+               return err;
+       }
+       strcpy(card->mixername, "Asahi Kasei AK4531");
+       ak4531->write(ak4531, AK4531_RESET, 0x03);      /* no RST, PD */
+       udelay(100);
+       ak4531->write(ak4531, AK4531_CLOCK, 0x00);      /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off LRCLK2 PLL */
+       for (idx = 0; idx <= 0x19; idx++) {
+               if (idx == AK4531_RESET || idx == AK4531_CLOCK)
+                       continue;
+               ak4531->write(ak4531, idx, ak4531->regs[idx] = snd_ak4531_initial_map[idx]);    /* recording source is mixer */
+       }
+       for (idx = 0; idx < ARRAY_SIZE(snd_ak4531_controls); idx++) {
+               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ak4531_controls[idx], ak4531))) < 0) {
+                       snd_ak4531_free(ak4531);
+                       return err;
+               }
+       }
+       snd_ak4531_proc_init(card, ak4531);
+       if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ak4531, &ops)) < 0) {
+               snd_ak4531_free(ak4531);
+               return err;
+       }
+
+#if 0
+       snd_ak4531_dump(ak4531);
+#endif
+       *rak4531 = ak4531;
+       return 0;
+}
+
+/*
+ * power management
+ */
+#ifdef CONFIG_PM
+void snd_ak4531_suspend(struct snd_ak4531 *ak4531)
+{
+       /* mute */
+       ak4531->write(ak4531, AK4531_LMASTER, 0x9f);
+       ak4531->write(ak4531, AK4531_RMASTER, 0x9f);
+       /* powerdown */
+       ak4531->write(ak4531, AK4531_RESET, 0x01);
+}
+
+void snd_ak4531_resume(struct snd_ak4531 *ak4531)
+{
+       int idx;
+
+       /* initialize */
+       ak4531->write(ak4531, AK4531_RESET, 0x03);
+       udelay(100);
+       ak4531->write(ak4531, AK4531_CLOCK, 0x00);
+       /* restore mixer registers */
+       for (idx = 0; idx <= 0x19; idx++) {
+               if (idx == AK4531_RESET || idx == AK4531_CLOCK)
+                       continue;
+               ak4531->write(ak4531, idx, ak4531->regs[idx]);
+       }
+}
+#endif
+
+#ifdef CONFIG_PROC_FS
+/*
+ * /proc interface
+ */
+
+static void snd_ak4531_proc_read(struct snd_info_entry *entry, 
+                                struct snd_info_buffer *buffer)
+{
+       struct snd_ak4531 *ak4531 = entry->private_data;
+
+       snd_iprintf(buffer, "Asahi Kasei AK4531\n\n");
+       snd_iprintf(buffer, "Recording source   : %s\n"
+                   "MIC gain           : %s\n",
+                   ak4531->regs[AK4531_AD_IN] & 1 ? "external" : "mixer",
+                   ak4531->regs[AK4531_MIC_GAIN] & 1 ? "+30dB" : "+0dB");
+}
+
+static void __devinit
+snd_ak4531_proc_init(struct snd_card *card, struct snd_ak4531 *ak4531)
+{
+       struct snd_info_entry *entry;
+
+       if (! snd_card_proc_new(card, "ak4531", &entry))
+               snd_info_set_text_ops(entry, ak4531, snd_ak4531_proc_read);
+}
+#endif
index bc212f4..e291aa5 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: au88x0_game.c,v 1.9 2003/09/22 03:51:28 mjander Exp $
- *
  *  Manuel Jander.
  *
  *  Based on the work of:
index 5f63af6..22f18f3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
- *  Copyright (C) 2002, 2005, 2006, 2007 by Andreas Mohr <andi AT lisas.de>
+ *  Copyright (C) 2002, 2005 - 2008 by Andreas Mohr <andi AT lisas.de>
  *
  *  Framework borrowed from Bart Hartgers's als4000.c.
  *  Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
  *  (3 weeks' worth of evenings filled with driver work).
  *  (and no, I did NOT go the easy way: to pick up a SB PCI128 for 9 Euros)
  *
+ *  It is quite likely that the AZF3328 chip is the PCI cousin of the
+ *  AZF3318 ("azt1020 pnp", "MM Pro 16") ISA chip, given very similar specs.
+ *
  *  The AZF3328 chip (note: AZF3328, *not* AZT3328, that's just the driver name
- *  for compatibility reasons) has the following features:
+ *  for compatibility reasons) from Azfin (joint-venture of Aztech and Fincitec,
+ *  Fincitec acquired by National Semiconductor in 2002, together with the
+ *  Fincitec-related company ARSmikro) has the following features:
  *
+ *  - compatibility & compliance:
+ *    - Microsoft PC 97 ("PC 97 Hardware Design Guide",
+ *                       http://www.microsoft.com/whdc/archive/pcguides.mspx)
+ *    - Microsoft PC 98 Baseline Audio
+ *    - MPU401 UART
+ *    - Sound Blaster Emulation (DOS Box)
  *  - builtin AC97 conformant codec (SNR over 80dB)
  *    Note that "conformant" != "compliant"!! this chip's mixer register layout
  *    *differs* from the standard AC97 layout:
  *    addresses illegally. So far unfortunately it looks like the very flexible
  *    ALSA AC97 support is still not enough to easily compensate for such a
  *    grave layout violation despite all tweaks and quirks mechanisms it offers.
- *  - builtin genuine OPL3
+ *  - builtin genuine OPL3 - verified to work fine, 20080506
  *  - full duplex 16bit playback/record at independent sampling rate
- *  - MPU401 (+ legacy address support) FIXME: how to enable legacy addr??
+ *  - MPU401 (+ legacy address support, claimed by one official spec sheet)
+ *    FIXME: how to enable legacy addr??
  *  - game port (legacy address support)
- *  - builtin 3D enhancement (said to be YAMAHA Ymersion)
  *  - builtin DirectInput support, helps reduce CPU overhead (interrupt-driven
- *    features supported)
+ *    features supported). - See common term "Digital Enhanced Game Port"...
+ *    (probably DirectInput 3.0 spec - confirm)
+ *  - builtin 3D enhancement (said to be YAMAHA Ymersion)
  *  - built-in General DirectX timer having a 20 bits counter
  *    with 1us resolution (see below!)
- *  - I2S serial port for external DAC
+ *  - I2S serial output port for external DAC
  *  - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
  *  - supports hardware volume control
  *  - single chip low cost solution (128 pin QFP)
  *  - supports programmable Sub-vendor and Sub-system ID
  *    required for Microsoft's logo compliance (FIXME: where?)
+ *    At least the Trident 4D Wave DX has one bit somewhere
+ *    to enable writes to PCI subsystem VID registers, that should be it.
+ *    This might easily be in extended PCI reg space, since PCI168 also has
+ *    some custom data starting at 0x80. What kind of config settings
+ *    are located in our extended PCI space anyway??
  *  - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
  *
  *  Note that this driver now is actually *better* than the Windows driver,
  *  - "timidity -iAv -B2,8 -Os -EFreverb=0"
  *  - "pmidi -p 128:0 jazz.mid"
  *
+ *  OPL3 hardware playback testing, try something like:
+ *  cat /proc/asound/hwdep
+ *  and
+ *  aconnect -o
+ *  Then use
+ *  sbiload -Dhw:x,y --opl3 /usr/share/sounds/opl3/std.o3 ......./drums.o3
+ *  where x,y is the xx-yy number as given in hwdep.
+ *  Then try
+ *  pmidi -p a:b jazz.mid
+ *  where a:b is the client number plus 0 usually, as given by aconnect above.
+ *  Oh, and make sure to unmute the FM mixer control (doh!)
+ *  NOTE: power use during OPL3 playback is _VERY_ high (70W --> 90W!)
+ *  despite no CPU activity, possibly due to hindering ACPI idling somehow.
+ *  Shouldn't be a problem of the AZF3328 chip itself, I'd hope.
+ *  Higher PCM / FM mixer levels seem to conflict (causes crackling),
+ *  at least sometimes.   Maybe even use with hardware sequencer timer above :)
+ *  adplay/adplug-utils might soon offer hardware-based OPL3 playback, too.
+ *
  *  Certain PCI versions of this card are susceptible to DMA traffic underruns
  *  in some systems (resulting in sound crackling/clicking/popping),
  *  probably because they don't have a DMA FIFO buffer or so.
  *  better than a VIA, yet ironically I still get crackling, like many other
  *  people with the same chipset.
  *  Possible remedies:
+ *  - use speaker (amplifier) output instead of headphone output
+ *    (in case crackling is due to overloaded output clipping)
  *  - plug card into a different PCI slot, preferrably one that isn't shared
  *    too much (this helps a lot, but not completely!)
  *  - get rid of PCI VGA card, use AGP instead
  *  - fiddle with PCI latency settings (setpci -v -s BUSID latency_timer=XX)
  *    Not too helpful.
  *  - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS
- * 
+ *
  * BUGS
- *  - full-duplex might *still* be problematic, not fully tested recently
+ *  - full-duplex might *still* be problematic, however a recent test was fine
  *  - (non-bug) "Bass/Treble or 3D settings don't work" - they do get evaluated
  *    if you set PCM output switch to "pre 3D" instead of "post 3D".
  *    If this can't be set, then get a mixer application that Isn't Stupid (tm)
  *    (e.g. kmix, gamix) - unfortunately several are!!
- * 
+ *  - locking is not entirely clean, especially the audio stream activity
+ *    ints --> may be racy
+ *  - an _unconnected_ secondary joystick at the gameport will be reported
+ *    to be "active" (floating values, not precisely -1) due to the way we need
+ *    to read the Digital Enhanced Game Port. Not sure whether it is fixable.
+ *
  * TODO
  *  - test MPU401 MIDI playback etc.
- *  - add some power micro-management (disable various units of the card
- *    as long as they're unused). However this requires I/O ports which I
+ *  - add more power micro-management (disable various units of the card
+ *    as long as they're unused). However this requires more I/O ports which I
  *    haven't figured out yet and which thus might not even exist...
  *    The standard suspend/resume functionality could probably make use of
  *    some improvement, too...
  *  - figure out some cleverly evil scheme to possibly make ALSA AC97 code
  *    fully accept our quite incompatible ""AC97"" mixer and thus save some
  *    code (but I'm not too optimistic that doing this is possible at all)
+ *  - use MMIO (memory-mapped I/O)? Slightly faster access, e.g. for gameport.
  */
 
 #include <asm/io.h>
@@ -138,7 +182,7 @@ MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
 
 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
-#define SUPPORT_JOYSTICK 1
+#define SUPPORT_GAMEPORT 1
 #endif
 
 #define DEBUG_MISC     0
@@ -147,13 +191,14 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
 #define DEBUG_PLAY_REC 0
 #define DEBUG_IO       0
 #define DEBUG_TIMER    0
+#define DEBUG_GAME     0
 #define MIXER_TESTING  0
 
 #if DEBUG_MISC
 #define snd_azf3328_dbgmisc(format, args...) printk(KERN_ERR format, ##args)
 #else
 #define snd_azf3328_dbgmisc(format, args...)
-#endif         
+#endif
 
 #if DEBUG_CALLS
 #define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
@@ -163,25 +208,31 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
 #define snd_azf3328_dbgcalls(format, args...)
 #define snd_azf3328_dbgcallenter()
 #define snd_azf3328_dbgcallleave()
-#endif         
+#endif
 
 #if DEBUG_MIXER
 #define snd_azf3328_dbgmixer(format, args...) printk(format, ##args)
 #else
 #define snd_azf3328_dbgmixer(format, args...)
-#endif         
+#endif
 
 #if DEBUG_PLAY_REC
 #define snd_azf3328_dbgplay(format, args...) printk(KERN_ERR format, ##args)
 #else
 #define snd_azf3328_dbgplay(format, args...)
-#endif         
+#endif
 
 #if DEBUG_MISC
 #define snd_azf3328_dbgtimer(format, args...) printk(KERN_ERR format, ##args)
 #else
 #define snd_azf3328_dbgtimer(format, args...)
-#endif         
+#endif
+
+#if DEBUG_GAME
+#define snd_azf3328_dbggame(format, args...) printk(KERN_ERR format, ##args)
+#else
+#define snd_azf3328_dbggame(format, args...)
+#endif
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
 module_param_array(index, int, NULL, 0444);
@@ -195,51 +246,62 @@ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;        /* Enable this card *
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable AZF3328 soundcard.");
 
-#ifdef SUPPORT_JOYSTICK
-static int joystick[SNDRV_CARDS];
-module_param_array(joystick, bool, NULL, 0444);
-MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard.");
-#endif
-
 static int seqtimer_scaling = 128;
 module_param(seqtimer_scaling, int, 0444);
 MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
 
+struct snd_azf3328_audio_stream {
+       struct snd_pcm_substream *substream;
+       int enabled;
+       int running;
+       unsigned long portbase;
+};
+
+enum snd_azf3328_stream_index {
+  AZF_PLAYBACK = 0,
+  AZF_CAPTURE = 1,
+};
+
 struct snd_azf3328 {
        /* often-used fields towards beginning, then grouped */
-       unsigned long codec_port;
-       unsigned long io2_port;
-       unsigned long mpu_port;
-       unsigned long synth_port;
-       unsigned long mixer_port;
+
+       unsigned long codec_io; /* usually 0xb000, size 128 */
+       unsigned long game_io;  /* usually 0xb400, size 8 */
+       unsigned long mpu_io;   /* usually 0xb800, size 4 */
+       unsigned long opl3_io; /* usually 0xbc00, size 8 */
+       unsigned long mixer_io; /* usually 0xc000, size 64 */
 
        spinlock_t reg_lock;
 
        struct snd_timer *timer;
-       
+
        struct snd_pcm *pcm;
-       struct snd_pcm_substream *playback_substream;
-       struct snd_pcm_substream *capture_substream;
-       unsigned int is_playing;
-       unsigned int is_recording;
+       struct snd_azf3328_audio_stream audio_stream[2];
 
        struct snd_card *card;
        struct snd_rawmidi *rmidi;
 
-#ifdef SUPPORT_JOYSTICK
+#ifdef SUPPORT_GAMEPORT
        struct gameport *gameport;
+       int axes[4];
 #endif
 
        struct pci_dev *pci;
        int irq;
 
+       /* register 0x6a is write-only, thus need to remember setting.
+        * If we need to add more registers here, then we might try to fold this
+        * into some transparent combined shadow register handling with
+        * CONFIG_PM register storage below, but that's slightly difficult. */
+       u16 shadow_reg_codec_6AH;
+
 #ifdef CONFIG_PM
        /* register value containers for power management
         * Note: not always full I/O range preserved (just like Win driver!) */
-       u16 saved_regs_codec [AZF_IO_SIZE_CODEC_PM / 2];
-       u16 saved_regs_io2   [AZF_IO_SIZE_IO2_PM / 2];
-       u16 saved_regs_mpu   [AZF_IO_SIZE_MPU_PM / 2];
-       u16 saved_regs_synth[AZF_IO_SIZE_SYNTH_PM / 2];
+       u16 saved_regs_codec[AZF_IO_SIZE_CODEC_PM / 2];
+       u16 saved_regs_game [AZF_IO_SIZE_GAME_PM / 2];
+       u16 saved_regs_mpu  [AZF_IO_SIZE_MPU_PM / 2];
+       u16 saved_regs_opl3 [AZF_IO_SIZE_OPL3_PM / 2];
        u16 saved_regs_mixer[AZF_IO_SIZE_MIXER_PM / 2];
 #endif
 };
@@ -252,126 +314,166 @@ static const struct pci_device_id snd_azf3328_ids[] = {
 
 MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
 
+
+static int
+snd_azf3328_io_reg_setb(unsigned reg, u8 mask, int do_set)
+{
+       u8 prev = inb(reg), new;
+
+       new = (do_set) ? (prev|mask) : (prev & ~mask);
+       /* we need to always write the new value no matter whether it differs
+        * or not, since some register bits don't indicate their setting */
+       outb(new, reg);
+       if (new != prev)
+               return 1;
+
+       return 0;
+}
+
 static inline void
-snd_azf3328_codec_outb(const struct snd_azf3328 *chip, int reg, u8 value)
+snd_azf3328_codec_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
 {
-       outb(value, chip->codec_port + reg);
+       outb(value, chip->codec_io + reg);
 }
 
 static inline u8
-snd_azf3328_codec_inb(const struct snd_azf3328 *chip, int reg)
+snd_azf3328_codec_inb(const struct snd_azf3328 *chip, unsigned reg)
 {
-       return inb(chip->codec_port + reg);
+       return inb(chip->codec_io + reg);
 }
 
 static inline void
-snd_azf3328_codec_outw(const struct snd_azf3328 *chip, int reg, u16 value)
+snd_azf3328_codec_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
 {
-       outw(value, chip->codec_port + reg);
+       outw(value, chip->codec_io + reg);
 }
 
 static inline u16
-snd_azf3328_codec_inw(const struct snd_azf3328 *chip, int reg)
+snd_azf3328_codec_inw(const struct snd_azf3328 *chip, unsigned reg)
+{
+       return inw(chip->codec_io + reg);
+}
+
+static inline void
+snd_azf3328_codec_outl(const struct snd_azf3328 *chip, unsigned reg, u32 value)
+{
+       outl(value, chip->codec_io + reg);
+}
+
+static inline u32
+snd_azf3328_codec_inl(const struct snd_azf3328 *chip, unsigned reg)
 {
-       return inw(chip->codec_port + reg);
+       return inl(chip->codec_io + reg);
 }
 
 static inline void
-snd_azf3328_codec_outl(const struct snd_azf3328 *chip, int reg, u32 value)
+snd_azf3328_game_outb(const struct snd_azf3328 *chip, unsigned reg, u8 value)
 {
-       outl(value, chip->codec_port + reg);
+       outb(value, chip->game_io + reg);
 }
 
 static inline void
-snd_azf3328_io2_outb(const struct snd_azf3328 *chip, int reg, u8 value)
+snd_azf3328_game_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
 {
-       outb(value, chip->io2_port + reg);
+       outw(value, chip->game_io + reg);
 }
 
 static inline u8
-snd_azf3328_io2_inb(const struct snd_azf3328 *chip, int reg)
+snd_azf3328_game_inb(const struct snd_azf3328 *chip, unsigned reg)
 {
-       return inb(chip->io2_port + reg);
+       return inb(chip->game_io + reg);
+}
+
+static inline u16
+snd_azf3328_game_inw(const struct snd_azf3328 *chip, unsigned reg)
+{
+       return inw(chip->game_io + reg);
 }
 
 static inline void
-snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, int reg, u16 value)
+snd_azf3328_mixer_outw(const struct snd_azf3328 *chip, unsigned reg, u16 value)
 {
-       outw(value, chip->mixer_port + reg);
+       outw(value, chip->mixer_io + reg);
 }
 
 static inline u16
-snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, int reg)
+snd_azf3328_mixer_inw(const struct snd_azf3328 *chip, unsigned reg)
 {
-       return inw(chip->mixer_port + reg);
+       return inw(chip->mixer_io + reg);
 }
 
-static void
-snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip, int reg, int do_mute)
+#define AZF_MUTE_BIT 0x80
+
+static int
+snd_azf3328_mixer_set_mute(const struct snd_azf3328 *chip,
+                          unsigned reg, int do_mute
+)
 {
-       unsigned long portbase = chip->mixer_port + reg + 1;
-       unsigned char oldval;
+       unsigned long portbase = chip->mixer_io + reg + 1;
+       int updated;
 
        /* the mute bit is on the *second* (i.e. right) register of a
         * left/right channel setting */
-       oldval = inb(portbase);
-       if (do_mute)
-               oldval |= 0x80;
-       else
-               oldval &= ~0x80;
-       outb(oldval, portbase);
+       updated = snd_azf3328_io_reg_setb(portbase, AZF_MUTE_BIT, do_mute);
+
+       /* indicate whether it was muted before */
+       return (do_mute) ? !updated : updated;
 }
 
 static void
-snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
+snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip,
+                                        unsigned reg,
+                                        unsigned char dst_vol_left,
+                                        unsigned char dst_vol_right,
+                                        int chan_sel, int delay
+)
 {
-       unsigned long portbase = chip->mixer_port + reg;
+       unsigned long portbase = chip->mixer_io + reg;
        unsigned char curr_vol_left = 0, curr_vol_right = 0;
-       int left_done = 0, right_done = 0;
-       
+       int left_change = 0, right_change = 0;
+
        snd_azf3328_dbgcallenter();
-       if (chan_sel & SET_CHAN_LEFT)
+
+       if (chan_sel & SET_CHAN_LEFT) {
                curr_vol_left  = inb(portbase + 1);
-       else
-               left_done = 1;
-       if (chan_sel & SET_CHAN_RIGHT)
+
+               /* take care of muting flag contained in left channel */
+               if (curr_vol_left & AZF_MUTE_BIT)
+                       dst_vol_left |= AZF_MUTE_BIT;
+               else
+                       dst_vol_left &= ~AZF_MUTE_BIT;
+
+               left_change = (curr_vol_left > dst_vol_left) ? -1 : 1;
+       }
+
+       if (chan_sel & SET_CHAN_RIGHT) {
                curr_vol_right = inb(portbase + 0);
-       else
-               right_done = 1;
-       
-       /* take care of muting flag (0x80) contained in left channel */
-       if (curr_vol_left & 0x80)
-               dst_vol_left |= 0x80;
-       else
-               dst_vol_left &= ~0x80;
+
+               right_change = (curr_vol_right > dst_vol_right) ? -1 : 1;
+       }
 
        do {
-               if (!left_done) {
-                       if (curr_vol_left > dst_vol_left)
-                               curr_vol_left--;
-                       else
-                       if (curr_vol_left < dst_vol_left)
-                               curr_vol_left++;
-                       else
-                           left_done = 1;
-                       outb(curr_vol_left, portbase + 1);
+               if (left_change) {
+                       if (curr_vol_left != dst_vol_left) {
+                               curr_vol_left += left_change;
+                               outb(curr_vol_left, portbase + 1);
+                       } else
+                           left_change = 0;
                }
-               if (!right_done) {
-                       if (curr_vol_right > dst_vol_right)
-                               curr_vol_right--;
-                       else
-                       if (curr_vol_right < dst_vol_right)
-                               curr_vol_right++;
-                       else
-                           right_done = 1;
+               if (right_change) {
+                       if (curr_vol_right != dst_vol_right) {
+                               curr_vol_right += right_change;
+
                        /* during volume change, the right channel is crackling
                         * somewhat more than the left channel, unfortunately.
                         * This seems to be a hardware issue. */
-                       outb(curr_vol_right, portbase + 0);
+                               outb(curr_vol_right, portbase + 0);
+                       } else
+                           right_change = 0;
                }
                if (delay)
                        mdelay(delay);
-       } while ((!left_done) || (!right_done));
+       } while ((left_change) || (right_change));
        snd_azf3328_dbgcallleave();
 }
 
@@ -379,7 +481,7 @@ snd_azf3328_mixer_write_volume_gradually(const struct snd_azf3328 *chip, int reg
  * general mixer element
  */
 struct azf3328_mixer_reg {
-       unsigned int reg;
+       unsigned reg;
        unsigned int lchan_shift, rchan_shift;
        unsigned int mask;
        unsigned int invert: 1;
@@ -544,13 +646,14 @@ snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
                "Mix", "Mic"
        };
        static const char * const texts3[] = {
-                "Mic", "CD", "Video", "Aux",
+               "Mic", "CD", "Video", "Aux",
                "Line", "Mix", "Mix Mono", "Phone"
         };
        static const char * const texts4[] = {
                "pre 3D", "post 3D"
         };
        struct azf3328_mixer_reg reg;
+       const char * const *p = NULL;
 
        snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
@@ -561,18 +664,20 @@ snd_azf3328_info_mixer_enum(struct snd_kcontrol *kcontrol,
        if (reg.reg == IDX_MIXER_ADVCTL2) {
                switch(reg.lchan_shift) {
                case 8: /* modem out sel */
-                       strcpy(uinfo->value.enumerated.name, texts1[uinfo->value.enumerated.item]);
+                       p = texts1;
                        break;
                case 9: /* mono sel source */
-                       strcpy(uinfo->value.enumerated.name, texts2[uinfo->value.enumerated.item]);
+                       p = texts2;
                        break;
                case 15: /* PCM Out Path */
-                       strcpy(uinfo->value.enumerated.name, texts4[uinfo->value.enumerated.item]);
+                       p = texts4;
                        break;
                }
        } else
-               strcpy(uinfo->value.enumerated.name, texts3[uinfo->value.enumerated.item]
-);
+       if (reg.reg == IDX_MIXER_REC_SELECT)
+               p = texts3;
+
+       strcpy(uinfo->value.enumerated.name, p[uinfo->value.enumerated.item]);
         return 0;
 }
 
@@ -583,7 +688,7 @@ snd_azf3328_get_mixer_enum(struct snd_kcontrol *kcontrol,
         struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
        struct azf3328_mixer_reg reg;
         unsigned short val;
-        
+
        snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
        val = snd_azf3328_mixer_inw(chip, reg.reg);
        if (reg.reg == IDX_MIXER_REC_SELECT) {
@@ -605,7 +710,7 @@ snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
         struct snd_azf3328 *chip = snd_kcontrol_chip(kcontrol);
        struct azf3328_mixer_reg reg;
        unsigned int oreg, nreg, val;
-        
+
        snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
        oreg = snd_azf3328_mixer_inw(chip, reg.reg);
        val = oreg;
@@ -631,9 +736,11 @@ snd_azf3328_put_mixer_enum(struct snd_kcontrol *kcontrol,
 static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
        AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
        AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
-       AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
-       AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1),
-       AZF3328_MIXER_SWITCH("Wave 3D Bypass Playback Switch", IDX_MIXER_ADVCTL2, 7, 1),
+       AZF3328_MIXER_SWITCH("PCM Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
+       AZF3328_MIXER_VOL_STEREO("PCM Playback Volume",
+                                       IDX_MIXER_WAVEOUT, 0x1f, 1),
+       AZF3328_MIXER_SWITCH("PCM 3D Bypass Playback Switch",
+                                       IDX_MIXER_ADVCTL2, 7, 1),
        AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
        AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
        AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
@@ -717,15 +824,16 @@ snd_azf3328_mixer_new(struct snd_azf3328 *chip)
        snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
 
        /* mute and zero volume channels */
-       for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); ++idx) {
                snd_azf3328_mixer_outw(chip,
                        snd_azf3328_init_values[idx][0],
                        snd_azf3328_init_values[idx][1]);
        }
-       
+
        /* add mixer controls */
        sw = snd_azf3328_mixer_controls;
-       for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls); idx++, sw++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_mixer_controls);
+                       ++idx, ++sw) {
                if ((err = snd_ctl_add(chip->card, snd_ctl_new1(sw, chip))) < 0)
                        return err;
        }
@@ -757,9 +865,9 @@ snd_azf3328_hw_free(struct snd_pcm_substream *substream)
 }
 
 static void
-snd_azf3328_setfmt(struct snd_azf3328 *chip,
-                              unsigned int reg,
-                              unsigned int bitrate,
+snd_azf3328_codec_setfmt(struct snd_azf3328 *chip,
+                              unsigned reg,
+                              enum azf_freq_t bitrate,
                               unsigned int format_width,
                               unsigned int channels
 )
@@ -769,24 +877,25 @@ snd_azf3328_setfmt(struct snd_azf3328 *chip,
 
        snd_azf3328_dbgcallenter();
        switch (bitrate) {
-       case  4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
-       case  4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
-       case  5512: val |= SOUNDFORMAT_FREQ_5510; break; /* the AZF3328 names it "5510" for some strange reason */
-       case  6620: val |= SOUNDFORMAT_FREQ_6620; break;
-       case  8000: val |= SOUNDFORMAT_FREQ_8000; break;
-       case  9600: val |= SOUNDFORMAT_FREQ_9600; break;
-       case 11025: val |= SOUNDFORMAT_FREQ_11025; break;
-       case 13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
-       case 16000: val |= SOUNDFORMAT_FREQ_16000; break;
-       case 22050: val |= SOUNDFORMAT_FREQ_22050; break;
-       case 32000: val |= SOUNDFORMAT_FREQ_32000; break;
-       case 44100: val |= SOUNDFORMAT_FREQ_44100; break;
-       case 48000: val |= SOUNDFORMAT_FREQ_48000; break;
-       case 66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
+       case AZF_FREQ_4000:  val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
+       case AZF_FREQ_4800:  val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
+       case AZF_FREQ_5512:
+               /* the AZF3328 names it "5510" for some strange reason */
+                            val |= SOUNDFORMAT_FREQ_5510; break;
+       case AZF_FREQ_6620:  val |= SOUNDFORMAT_FREQ_6620; break;
+       case AZF_FREQ_8000:  val |= SOUNDFORMAT_FREQ_8000; break;
+       case AZF_FREQ_9600:  val |= SOUNDFORMAT_FREQ_9600; break;
+       case AZF_FREQ_11025: val |= SOUNDFORMAT_FREQ_11025; break;
+       case AZF_FREQ_13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
+       case AZF_FREQ_16000: val |= SOUNDFORMAT_FREQ_16000; break;
+       case AZF_FREQ_22050: val |= SOUNDFORMAT_FREQ_22050; break;
+       case AZF_FREQ_32000: val |= SOUNDFORMAT_FREQ_32000; break;
        default:
                snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
-               val |= SOUNDFORMAT_FREQ_44100;
-               break;
+               /* fall-through */
+       case AZF_FREQ_44100: val |= SOUNDFORMAT_FREQ_44100; break;
+       case AZF_FREQ_48000: val |= SOUNDFORMAT_FREQ_48000; break;
+       case AZF_FREQ_66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
        }
        /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
        /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
@@ -805,10 +914,10 @@ snd_azf3328_setfmt(struct snd_azf3328 *chip,
                val |= SOUNDFORMAT_FLAG_16BIT;
 
        spin_lock_irqsave(&chip->reg_lock, flags);
-       
+
        /* set bitrate/format */
        snd_azf3328_codec_outw(chip, reg, val);
-       
+
        /* changing the bitrate/format settings switches off the
         * audio output with an annoying click in case of 8/16bit format change
         * (maybe shutting down DAC/ADC?), thus immediately
@@ -830,31 +939,95 @@ snd_azf3328_setfmt(struct snd_azf3328 *chip,
        snd_azf3328_dbgcallleave();
 }
 
+static inline void
+snd_azf3328_codec_setfmt_lowpower(struct snd_azf3328 *chip,
+                           unsigned reg
+)
+{
+       /* choose lowest frequency for low power consumption.
+        * While this will cause louder noise due to rather coarse frequency,
+        * it should never matter since output should always
+        * get disabled properly when idle anyway. */
+       snd_azf3328_codec_setfmt(chip, reg, AZF_FREQ_4000, 8, 1);
+}
+
+static void
+snd_azf3328_codec_reg_6AH_update(struct snd_azf3328 *chip,
+                                       unsigned bitmask,
+                                       int enable
+)
+{
+       if (enable)
+               chip->shadow_reg_codec_6AH &= ~bitmask;
+       else
+               chip->shadow_reg_codec_6AH |= bitmask;
+       snd_azf3328_dbgplay("6AH_update mask 0x%04x enable %d: val 0x%04x\n",
+                       bitmask, enable, chip->shadow_reg_codec_6AH);
+       snd_azf3328_codec_outw(chip, IDX_IO_6AH, chip->shadow_reg_codec_6AH);
+}
+
+static inline void
+snd_azf3328_codec_enable(struct snd_azf3328 *chip, int enable)
+{
+       snd_azf3328_dbgplay("codec_enable %d\n", enable);
+       /* no idea what exactly is being done here, but I strongly assume it's
+        * PM related */
+       snd_azf3328_codec_reg_6AH_update(
+               chip, IO_6A_PAUSE_PLAYBACK_BIT8, enable
+       );
+}
+
+static void
+snd_azf3328_codec_activity(struct snd_azf3328 *chip,
+                               enum snd_azf3328_stream_index stream_type,
+                               int enable
+)
+{
+       int need_change = (chip->audio_stream[stream_type].running != enable);
+
+       snd_azf3328_dbgplay(
+               "codec_activity: type %d, enable %d, need_change %d\n",
+                               stream_type, enable, need_change
+       );
+       if (need_change) {
+               enum snd_azf3328_stream_index other =
+                       (stream_type == AZF_PLAYBACK) ?
+                               AZF_CAPTURE : AZF_PLAYBACK;
+               /* small check to prevent shutting down the other party
+                * in case it's active */
+               if ((enable) || !(chip->audio_stream[other].running))
+                       snd_azf3328_codec_enable(chip, enable);
+
+               /* ...and adjust clock, too
+                * (reduce noise and power consumption) */
+               if (!enable)
+                       snd_azf3328_codec_setfmt_lowpower(
+                               chip,
+                               chip->audio_stream[stream_type].portbase
+                                       + IDX_IO_PLAY_SOUNDFORMAT
+                       );
+       }
+       chip->audio_stream[stream_type].running = enable;
+}
+
 static void
 snd_azf3328_setdmaa(struct snd_azf3328 *chip,
                                long unsigned int addr,
                                 unsigned int count,
                                 unsigned int size,
-                               int do_recording)
+                               enum snd_azf3328_stream_index stream_type
+)
 {
-       unsigned long flags, portbase;
-       unsigned int is_running;
-
        snd_azf3328_dbgcallenter();
-       if (do_recording) {
-               /* access capture registers, i.e. skip playback reg section */
-               portbase = chip->codec_port + 0x20;
-               is_running = chip->is_recording;
-       } else {
-               /* access the playback register section */
-               portbase = chip->codec_port + 0x00;
-               is_running = chip->is_playing;
-       }
+       if (!chip->audio_stream[stream_type].running) {
+               /* AZF3328 uses a two buffer pointer DMA playback approach */
 
-       /* AZF3328 uses a two buffer pointer DMA playback approach */
-       if (!is_running) {
-               unsigned long addr_area2;
-               unsigned long count_areas, count_tmp; /* width 32bit -- overflow!! */
+               unsigned long flags, portbase, addr_area2;
+
+               /* width 32bit (prevent overflow): */
+               unsigned long count_areas, count_tmp;
+
+               portbase = chip->audio_stream[stream_type].portbase;
                count_areas = size/2;
                addr_area2 = addr+count_areas;
                count_areas--; /* max. index */
@@ -884,11 +1057,11 @@ snd_azf3328_playback_prepare(struct snd_pcm_substream *substream)
 
        snd_azf3328_dbgcallenter();
 #if 0
-       snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
+       snd_azf3328_codec_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
                runtime->rate,
                snd_pcm_format_width(runtime->format),
                runtime->channels);
-       snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0);
+       snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, AZF_PLAYBACK);
 #endif
        snd_azf3328_dbgcallleave();
        return 0;
@@ -906,11 +1079,11 @@ snd_azf3328_capture_prepare(struct snd_pcm_substream *substream)
 
        snd_azf3328_dbgcallenter();
 #if 0
-       snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
+       snd_azf3328_codec_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
                runtime->rate,
                snd_pcm_format_width(runtime->format),
                runtime->channels);
-       snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1);
+       snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, AZF_CAPTURE);
 #endif
        snd_azf3328_dbgcallleave();
        return 0;
@@ -923,6 +1096,7 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
        struct snd_pcm_runtime *runtime = substream->runtime;
        int result = 0;
        unsigned int status1;
+       int previously_muted;
 
        snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd);
 
@@ -930,20 +1104,23 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
        case SNDRV_PCM_TRIGGER_START:
                snd_azf3328_dbgplay("START PLAYBACK\n");
 
-               /* mute WaveOut */
-               snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
+               /* mute WaveOut (avoid clicking during setup) */
+               previously_muted =
+                       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
 
-               snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
+               snd_azf3328_codec_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
                        runtime->rate,
                        snd_pcm_format_width(runtime->format),
                        runtime->channels);
 
                spin_lock(&chip->reg_lock);
-               /* stop playback */
+               /* first, remember current value: */
                status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
+
+               /* stop playback */
                status1 &= ~DMA_RESUME;
                snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
-           
+
                /* FIXME: clear interrupts or what??? */
                snd_azf3328_codec_outw(chip, IDX_IO_PLAY_IRQTYPE, 0xffff);
                spin_unlock(&chip->reg_lock);
@@ -951,7 +1128,7 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
                snd_azf3328_setdmaa(chip, runtime->dma_addr,
                        snd_pcm_lib_period_bytes(substream),
                        snd_pcm_lib_buffer_bytes(substream),
-                       0);
+                       AZF_PLAYBACK);
 
                spin_lock(&chip->reg_lock);
 #ifdef WIN9X
@@ -978,30 +1155,35 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
                        DMA_SOMETHING_ELSE);
 #endif
                spin_unlock(&chip->reg_lock);
+               snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 1);
 
                /* now unmute WaveOut */
-               snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
+               if (!previously_muted)
+                       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
 
-               chip->is_playing = 1;
                snd_azf3328_dbgplay("STARTED PLAYBACK\n");
                break;
        case SNDRV_PCM_TRIGGER_RESUME:
                snd_azf3328_dbgplay("RESUME PLAYBACK\n");
                /* resume playback if we were active */
-               if (chip->is_playing)
+               spin_lock(&chip->reg_lock);
+               if (chip->audio_stream[AZF_PLAYBACK].running)
                        snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
                                snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) | DMA_RESUME);
+               spin_unlock(&chip->reg_lock);
                break;
        case SNDRV_PCM_TRIGGER_STOP:
                snd_azf3328_dbgplay("STOP PLAYBACK\n");
 
-               /* mute WaveOut */
-               snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
+               /* mute WaveOut (avoid clicking during setup) */
+               previously_muted =
+                       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
 
                spin_lock(&chip->reg_lock);
-               /* stop playback */
+               /* first, remember current value: */
                status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
 
+               /* stop playback */
                status1 &= ~DMA_RESUME;
                snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
 
@@ -1013,10 +1195,12 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
                status1 &= ~DMA_PLAY_SOMETHING1;
                snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
                spin_unlock(&chip->reg_lock);
-           
+               snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 0);
+
                /* now unmute WaveOut */
-               snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
-               chip->is_playing = 0;
+               if (!previously_muted)
+                       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
+
                snd_azf3328_dbgplay("STOPPED PLAYBACK\n");
                break;
        case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -1035,7 +1219,7 @@ snd_azf3328_playback_trigger(struct snd_pcm_substream *substream, int cmd)
                printk(KERN_ERR "FIXME: unknown trigger mode!\n");
                 return -EINVAL;
        }
-       
+
        snd_azf3328_dbgcallleave();
        return result;
 }
@@ -1057,17 +1241,19 @@ snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
 
                snd_azf3328_dbgplay("START CAPTURE\n");
 
-               snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
+               snd_azf3328_codec_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
                        runtime->rate,
                        snd_pcm_format_width(runtime->format),
                        runtime->channels);
 
                spin_lock(&chip->reg_lock);
-               /* stop recording */
+               /* first, remember current value: */
                status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
+
+               /* stop recording */
                status1 &= ~DMA_RESUME;
                snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
-           
+
                /* FIXME: clear interrupts or what??? */
                snd_azf3328_codec_outw(chip, IDX_IO_REC_IRQTYPE, 0xffff);
                spin_unlock(&chip->reg_lock);
@@ -1075,7 +1261,7 @@ snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
                snd_azf3328_setdmaa(chip, runtime->dma_addr,
                        snd_pcm_lib_period_bytes(substream),
                        snd_pcm_lib_buffer_bytes(substream),
-                       1);
+                       AZF_CAPTURE);
 
                spin_lock(&chip->reg_lock);
 #ifdef WIN9X
@@ -1102,24 +1288,27 @@ snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
                        DMA_SOMETHING_ELSE);
 #endif
                spin_unlock(&chip->reg_lock);
+               snd_azf3328_codec_activity(chip, AZF_CAPTURE, 1);
 
-               chip->is_recording = 1;
                snd_azf3328_dbgplay("STARTED CAPTURE\n");
                break;
        case SNDRV_PCM_TRIGGER_RESUME:
                snd_azf3328_dbgplay("RESUME CAPTURE\n");
                /* resume recording if we were active */
-               if (chip->is_recording)
+               spin_lock(&chip->reg_lock);
+               if (chip->audio_stream[AZF_CAPTURE].running)
                        snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
                                snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS) | DMA_RESUME);
+               spin_unlock(&chip->reg_lock);
                break;
         case SNDRV_PCM_TRIGGER_STOP:
                snd_azf3328_dbgplay("STOP CAPTURE\n");
 
                spin_lock(&chip->reg_lock);
-               /* stop recording */
+               /* first, remember current value: */
                status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
 
+               /* stop recording */
                status1 &= ~DMA_RESUME;
                snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
 
@@ -1129,8 +1318,8 @@ snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
                status1 &= ~DMA_PLAY_SOMETHING1;
                snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
                spin_unlock(&chip->reg_lock);
-           
-               chip->is_recording = 0;
+               snd_azf3328_codec_activity(chip, AZF_CAPTURE, 0);
+
                snd_azf3328_dbgplay("STOPPED CAPTURE\n");
                break;
        case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -1149,7 +1338,7 @@ snd_azf3328_capture_trigger(struct snd_pcm_substream *substream, int cmd)
                printk(KERN_ERR "FIXME: unknown trigger mode!\n");
                 return -EINVAL;
        }
-       
+
        snd_azf3328_dbgcallleave();
        return result;
 }
@@ -1162,11 +1351,11 @@ snd_azf3328_playback_pointer(struct snd_pcm_substream *substream)
        snd_pcm_uframes_t frmres;
 
 #ifdef QUERY_HARDWARE
-       bufptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_START_1);
+       bufptr = snd_azf3328_codec_inl(chip, IDX_IO_PLAY_DMA_START_1);
 #else
        bufptr = substream->runtime->dma_addr;
 #endif
-       result = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS);
+       result = snd_azf3328_codec_inl(chip, IDX_IO_PLAY_DMA_CURRPOS);
 
        /* calculate offset */
        result -= bufptr;
@@ -1183,11 +1372,11 @@ snd_azf3328_capture_pointer(struct snd_pcm_substream *substream)
        snd_pcm_uframes_t frmres;
 
 #ifdef QUERY_HARDWARE
-       bufptr = inl(chip->codec_port+IDX_IO_REC_DMA_START_1);
+       bufptr = snd_azf3328_codec_inl(chip, IDX_IO_REC_DMA_START_1);
 #else
        bufptr = substream->runtime->dma_addr;
 #endif
-       result = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS);
+       result = snd_azf3328_codec_inl(chip, IDX_IO_REC_DMA_CURRPOS);
 
        /* calculate offset */
        result -= bufptr;
@@ -1196,27 +1385,241 @@ snd_azf3328_capture_pointer(struct snd_pcm_substream *substream)
        return frmres;
 }
 
+/******************************************************************/
+
+#ifdef SUPPORT_GAMEPORT
+static inline void
+snd_azf3328_gameport_irq_enable(struct snd_azf3328 *chip, int enable)
+{
+       snd_azf3328_io_reg_setb(
+               chip->game_io+IDX_GAME_HWCONFIG,
+               GAME_HWCFG_IRQ_ENABLE,
+               enable
+       );
+}
+
+static inline void
+snd_azf3328_gameport_legacy_address_enable(struct snd_azf3328 *chip, int enable)
+{
+       snd_azf3328_io_reg_setb(
+               chip->game_io+IDX_GAME_HWCONFIG,
+               GAME_HWCFG_LEGACY_ADDRESS_ENABLE,
+               enable
+       );
+}
+
+static inline void
+snd_azf3328_gameport_axis_circuit_enable(struct snd_azf3328 *chip, int enable)
+{
+       snd_azf3328_codec_reg_6AH_update(
+               chip, IO_6A_SOMETHING2_GAMEPORT, enable
+       );
+}
+
+static inline void
+snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
+{
+       /*
+        * skeleton handler only
+        * (we do not want axis reading in interrupt handler - too much load!)
+        */
+       snd_azf3328_dbggame("gameport irq\n");
+
+        /* this should ACK the gameport IRQ properly, hopefully. */
+       snd_azf3328_game_inw(chip, IDX_GAME_AXIS_VALUE);
+}
+
+static int
+snd_azf3328_gameport_open(struct gameport *gameport, int mode)
+{
+       struct snd_azf3328 *chip = gameport_get_port_data(gameport);
+       int res;
+
+       snd_azf3328_dbggame("gameport_open, mode %d\n", mode);
+       switch (mode) {
+       case GAMEPORT_MODE_COOKED:
+       case GAMEPORT_MODE_RAW:
+               res = 0;
+               break;
+       default:
+               res = -1;
+               break;
+       }
+
+       snd_azf3328_gameport_axis_circuit_enable(chip, (res == 0));
+
+       return res;
+}
+
+static void
+snd_azf3328_gameport_close(struct gameport *gameport)
+{
+       struct snd_azf3328 *chip = gameport_get_port_data(gameport);
+
+       snd_azf3328_dbggame("gameport_close\n");
+       snd_azf3328_gameport_axis_circuit_enable(chip, 0);
+}
+
+static int
+snd_azf3328_gameport_cooked_read(struct gameport *gameport,
+                                int *axes,
+                                int *buttons
+)
+{
+       struct snd_azf3328 *chip = gameport_get_port_data(gameport);
+       int i;
+       u8 val;
+       unsigned long flags;
+
+       snd_assert(chip, return 0);
+
+       spin_lock_irqsave(&chip->reg_lock, flags);
+       val = snd_azf3328_game_inb(chip, IDX_GAME_LEGACY_COMPATIBLE);
+       *buttons = (~(val) >> 4) & 0xf;
+
+       /* ok, this one is a bit dirty: cooked_read is being polled by a timer,
+        * thus we're atomic and cannot actively wait in here
+        * (which would be useful for us since it probably would be better
+        * to trigger a measurement in here, then wait a short amount of
+        * time until it's finished, then read values of _this_ measurement).
+        *
+        * Thus we simply resort to reading values if they're available already
+        * and trigger the next measurement.
+        */
+
+       val = snd_azf3328_game_inb(chip, IDX_GAME_AXES_CONFIG);
+       if (val & GAME_AXES_SAMPLING_READY) {
+               for (i = 0; i < 4; ++i) {
+                       /* configure the axis to read */
+                       val = (i << 4) | 0x0f;
+                       snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
+
+                       chip->axes[i] = snd_azf3328_game_inw(
+                                               chip, IDX_GAME_AXIS_VALUE
+                                       );
+               }
+       }
+
+       /* trigger next axes sampling, to be evaluated the next time we
+        * enter this function */
+
+       /* for some very, very strange reason we cannot enable
+        * Measurement Ready monitoring for all axes here,
+        * at least not when only one joystick connected */
+       val = 0x03; /* we're able to monitor axes 1 and 2 only */
+       snd_azf3328_game_outb(chip, IDX_GAME_AXES_CONFIG, val);
+
+       snd_azf3328_game_outw(chip, IDX_GAME_AXIS_VALUE, 0xffff);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
+
+       for (i = 0; i < 4; i++) {
+               axes[i] = chip->axes[i];
+               if (axes[i] == 0xffff)
+                       axes[i] = -1;
+       }
+
+       snd_azf3328_dbggame("cooked_read: axes %d %d %d %d buttons %d\n",
+               axes[0], axes[1], axes[2], axes[3], *buttons
+       );
+
+       return 0;
+}
+
+static int __devinit
+snd_azf3328_gameport(struct snd_azf3328 *chip, int dev)
+{
+       struct gameport *gp;
+
+       chip->gameport = gp = gameport_allocate_port();
+       if (!gp) {
+               printk(KERN_ERR "azt3328: cannot alloc memory for gameport\n");
+               return -ENOMEM;
+       }
+
+       gameport_set_name(gp, "AZF3328 Gameport");
+       gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
+       gameport_set_dev_parent(gp, &chip->pci->dev);
+       gp->io = chip->game_io;
+       gameport_set_port_data(gp, chip);
+
+       gp->open = snd_azf3328_gameport_open;
+       gp->close = snd_azf3328_gameport_close;
+       gp->fuzz = 16; /* seems ok */
+       gp->cooked_read = snd_azf3328_gameport_cooked_read;
+
+       /* DISABLE legacy address: we don't need it! */
+       snd_azf3328_gameport_legacy_address_enable(chip, 0);
+
+       snd_azf3328_gameport_axis_circuit_enable(chip, 0);
+
+       gameport_register_port(chip->gameport);
+
+       return 0;
+}
+
+static void
+snd_azf3328_gameport_free(struct snd_azf3328 *chip)
+{
+       if (chip->gameport) {
+               gameport_unregister_port(chip->gameport);
+               chip->gameport = NULL;
+       }
+       snd_azf3328_gameport_irq_enable(chip, 0);
+}
+#else
+static inline int
+snd_azf3328_gameport(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
+static inline void
+snd_azf3328_gameport_free(struct snd_azf3328 *chip) { }
+static inline void
+snd_azf3328_gameport_interrupt(struct snd_azf3328 *chip)
+{
+       printk(KERN_WARNING "huh, game port IRQ occurred!?\n");
+}
+#endif /* SUPPORT_GAMEPORT */
+
+/******************************************************************/
+
+static inline void
+snd_azf3328_irq_log_unknown_type(u8 which)
+{
+       snd_azf3328_dbgplay(
+       "azt3328: unknown IRQ type (%x) occurred, please report!\n",
+               which
+       );
+}
+
 static irqreturn_t
 snd_azf3328_interrupt(int irq, void *dev_id)
 {
        struct snd_azf3328 *chip = dev_id;
        u8 status, which;
+#if DEBUG_PLAY_REC
        static unsigned long irq_count;
+#endif
 
        status = snd_azf3328_codec_inb(chip, IDX_IO_IRQSTATUS);
 
         /* fast path out, to ease interrupt sharing */
-       if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_TIMER)))
+       if (!(status &
+               (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_GAMEPORT|IRQ_MPU401|IRQ_TIMER)
+       ))
                return IRQ_NONE; /* must be interrupt for another device */
 
-       snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
-               irq_count,
-               snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
-               snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
-               status);
-               
+       snd_azf3328_dbgplay(
+               "irq_count %ld! IDX_IO_PLAY_FLAGS %04x, "
+               "IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
+                       irq_count++ /* debug-only */,
+                       snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
+                       snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
+                       status
+       );
+
        if (status & IRQ_TIMER) {
-               /* snd_azf3328_dbgplay("timer %ld\n", inl(chip->codec_port+IDX_IO_TIMER_VALUE) & TIMER_VALUE_MASK); */
+               /* snd_azf3328_dbgplay("timer %ld\n",
+                       snd_azf3328_codec_inl(chip, IDX_IO_TIMER_VALUE)
+                               & TIMER_VALUE_MASK
+               ); */
                if (chip->timer)
                        snd_timer_interrupt(chip->timer, chip->timer->sticks);
                /* ACK timer */
@@ -1232,15 +1635,20 @@ snd_azf3328_interrupt(int irq, void *dev_id)
                snd_azf3328_codec_outb(chip, IDX_IO_PLAY_IRQTYPE, which);
                        spin_unlock(&chip->reg_lock);
 
-               if (chip->pcm && chip->playback_substream) {
-                       snd_pcm_period_elapsed(chip->playback_substream);
+               if (chip->pcm && chip->audio_stream[AZF_PLAYBACK].substream) {
+                       snd_pcm_period_elapsed(
+                               chip->audio_stream[AZF_PLAYBACK].substream
+                       );
                        snd_azf3328_dbgplay("PLAY period done (#%x), @ %x\n",
                                which,
-                               inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
+                               snd_azf3328_codec_inl(
+                                       chip, IDX_IO_PLAY_DMA_CURRPOS
+                               )
+                       );
                } else
-                       snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
+                       printk(KERN_WARNING "azt3328: irq handler problem!\n");
                if (which & IRQ_PLAY_SOMETHING)
-                       snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
+                       snd_azf3328_irq_log_unknown_type(which);
        }
        if (status & IRQ_RECORDING) {
                 spin_lock(&chip->reg_lock);
@@ -1249,16 +1657,23 @@ snd_azf3328_interrupt(int irq, void *dev_id)
                snd_azf3328_codec_outb(chip, IDX_IO_REC_IRQTYPE, which);
                spin_unlock(&chip->reg_lock);
 
-               if (chip->pcm && chip->capture_substream) {
-                       snd_pcm_period_elapsed(chip->capture_substream);
+               if (chip->pcm && chip->audio_stream[AZF_CAPTURE].substream) {
+                       snd_pcm_period_elapsed(
+                               chip->audio_stream[AZF_CAPTURE].substream
+                       );
                        snd_azf3328_dbgplay("REC  period done (#%x), @ %x\n",
                                which,
-                               inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
+                               snd_azf3328_codec_inl(
+                                       chip, IDX_IO_REC_DMA_CURRPOS
+                               )
+                       );
                } else
-                       snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
+                       printk(KERN_WARNING "azt3328: irq handler problem!\n");
                if (which & IRQ_REC_SOMETHING)
-                       snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
+                       snd_azf3328_irq_log_unknown_type(which);
        }
+       if (status & IRQ_GAMEPORT)
+               snd_azf3328_gameport_interrupt(chip);
        /* MPU401 has less critical IRQ requirements
         * than timer and playback/recording, right? */
        if (status & IRQ_MPU401) {
@@ -1268,7 +1683,6 @@ snd_azf3328_interrupt(int irq, void *dev_id)
                 * If so, then I don't know how... */
                snd_azf3328_dbgplay("azt3328: MPU401 IRQ\n");
        }
-       irq_count++;
        return IRQ_HANDLED;
 }
 
@@ -1287,8 +1701,8 @@ static const struct snd_pcm_hardware snd_azf3328_playback =
        .rates =                SNDRV_PCM_RATE_5512 |
                                SNDRV_PCM_RATE_8000_48000 |
                                SNDRV_PCM_RATE_KNOT,
-       .rate_min =             4000,
-       .rate_max =             66200,
+       .rate_min =             AZF_FREQ_4000,
+       .rate_max =             AZF_FREQ_66200,
        .channels_min =         1,
        .channels_max =         2,
        .buffer_bytes_max =     65536,
@@ -1315,8 +1729,8 @@ static const struct snd_pcm_hardware snd_azf3328_capture =
        .rates =                SNDRV_PCM_RATE_5512 |
                                SNDRV_PCM_RATE_8000_48000 |
                                SNDRV_PCM_RATE_KNOT,
-       .rate_min =             4000,
-       .rate_max =             66200,
+       .rate_min =             AZF_FREQ_4000,
+       .rate_max =             AZF_FREQ_66200,
        .channels_min =         1,
        .channels_max =         2,
        .buffer_bytes_max =     65536,
@@ -1329,10 +1743,24 @@ static const struct snd_pcm_hardware snd_azf3328_capture =
 
 
 static unsigned int snd_azf3328_fixed_rates[] = {
-       4000, 4800, 5512, 6620, 8000, 9600, 11025, 13240, 16000, 22050, 32000,
-       44100, 48000, 66200 };
+       AZF_FREQ_4000,
+       AZF_FREQ_4800,
+       AZF_FREQ_5512,
+       AZF_FREQ_6620,
+       AZF_FREQ_8000,
+       AZF_FREQ_9600,
+       AZF_FREQ_11025,
+       AZF_FREQ_13240,
+       AZF_FREQ_16000,
+       AZF_FREQ_22050,
+       AZF_FREQ_32000,
+       AZF_FREQ_44100,
+       AZF_FREQ_48000,
+       AZF_FREQ_66200
+};
+
 static struct snd_pcm_hw_constraint_list snd_azf3328_hw_constraints_rates = {
-       .count = ARRAY_SIZE(snd_azf3328_fixed_rates), 
+       .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
        .list = snd_azf3328_fixed_rates,
        .mask = 0,
 };
@@ -1346,7 +1774,7 @@ snd_azf3328_playback_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
 
        snd_azf3328_dbgcallenter();
-       chip->playback_substream = substream;
+       chip->audio_stream[AZF_PLAYBACK].substream = substream;
        runtime->hw = snd_azf3328_playback;
        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
                                   &snd_azf3328_hw_constraints_rates);
@@ -1361,7 +1789,7 @@ snd_azf3328_capture_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
 
        snd_azf3328_dbgcallenter();
-       chip->capture_substream = substream;
+       chip->audio_stream[AZF_CAPTURE].substream = substream;
        runtime->hw = snd_azf3328_capture;
        snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
                                   &snd_azf3328_hw_constraints_rates);
@@ -1375,7 +1803,7 @@ snd_azf3328_playback_close(struct snd_pcm_substream *substream)
        struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
 
        snd_azf3328_dbgcallenter();
-       chip->playback_substream = NULL;
+       chip->audio_stream[AZF_PLAYBACK].substream = NULL;
        snd_azf3328_dbgcallleave();
        return 0;
 }
@@ -1386,7 +1814,7 @@ snd_azf3328_capture_close(struct snd_pcm_substream *substream)
        struct snd_azf3328 *chip = snd_pcm_substream_chip(substream);
 
        snd_azf3328_dbgcallenter();
-       chip->capture_substream = NULL;
+       chip->audio_stream[AZF_CAPTURE].substream = NULL;
        snd_azf3328_dbgcallleave();
        return 0;
 }
@@ -1441,102 +1869,8 @@ snd_azf3328_pcm(struct snd_azf3328 *chip, int device)
 
 /******************************************************************/
 
-#ifdef SUPPORT_JOYSTICK
-static int __devinit
-snd_azf3328_config_joystick(struct snd_azf3328 *chip, int dev)
-{
-       struct gameport *gp;
-       struct resource *r;
-
-       if (!joystick[dev])
-               return -ENODEV;
-
-       if (!(r = request_region(0x200, 8, "AZF3328 gameport"))) {
-               printk(KERN_WARNING "azt3328: cannot reserve joystick ports\n");
-               return -EBUSY;
-       }
-
-       chip->gameport = gp = gameport_allocate_port();
-       if (!gp) {
-               printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n");
-               release_and_free_resource(r);
-               return -ENOMEM;
-       }
-
-       gameport_set_name(gp, "AZF3328 Gameport");
-       gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
-       gameport_set_dev_parent(gp, &chip->pci->dev);
-       gp->io = 0x200;
-       gameport_set_port_data(gp, r);
-
-       snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
-                             snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY);
-
-       gameport_register_port(chip->gameport);
-
-       return 0;
-}
-
-static void
-snd_azf3328_free_joystick(struct snd_azf3328 *chip)
-{
-       if (chip->gameport) {
-               struct resource *r = gameport_get_port_data(chip->gameport);
-
-               gameport_unregister_port(chip->gameport);
-               chip->gameport = NULL;
-               /* disable gameport */
-               snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
-                                     snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
-               release_and_free_resource(r);
-       }
-}
-#else
-static inline int
-snd_azf3328_config_joystick(struct snd_azf3328 *chip, int dev) { return -ENOSYS; }
-static inline void
-snd_azf3328_free_joystick(struct snd_azf3328 *chip) { }
-#endif
-
-/******************************************************************/
-
-static int
-snd_azf3328_free(struct snd_azf3328 *chip)
-{
-        if (chip->irq < 0)
-                goto __end_hw;
-
-       /* reset (close) mixer */
-       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */
-       snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
-
-        /* interrupt setup - mask everything (FIXME!) */
-       /* well, at least we know how to disable the timer IRQ */
-       snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
-
-       if (chip->irq >= 0)
-               synchronize_irq(chip->irq);
-__end_hw:
-       snd_azf3328_free_joystick(chip);
-        if (chip->irq >= 0)
-               free_irq(chip->irq, chip);
-       pci_release_regions(chip->pci);
-       pci_disable_device(chip->pci);
-
-        kfree(chip);
-        return 0;
-}
-
-static int
-snd_azf3328_dev_free(struct snd_device *device)
-{
-       struct snd_azf3328 *chip = device->device_data;
-       return snd_azf3328_free(chip);
-}
-
-/******************************************************************/
-
-/*** NOTE: the physical timer resolution actually is 1024000 ticks per second,
+/*** NOTE: the physical timer resolution actually is 1024000 ticks per second
+ *** (probably derived from main crystal via a divider of 24),
  *** but announcing those attributes to user-space would make programs
  *** configure the timer to a 1 tick value, resulting in an absolutely fatal
  *** timer IRQ storm.
@@ -1564,7 +1898,7 @@ snd_azf3328_timer_start(struct snd_timer *timer)
                delay = 49; /* minimum time is 49 ticks */
        }
        snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay);
-       delay |= TIMER_ENABLE_COUNTDOWN | TIMER_ENABLE_IRQ;
+       delay |= TIMER_COUNTDOWN_ENABLE | TIMER_IRQ_ENABLE;
        spin_lock_irqsave(&chip->reg_lock, flags);
        snd_azf3328_codec_outl(chip, IDX_IO_TIMER_VALUE, delay);
        spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -1582,7 +1916,7 @@ snd_azf3328_timer_stop(struct snd_timer *timer)
        chip = snd_timer_chip(timer);
        spin_lock_irqsave(&chip->reg_lock, flags);
        /* disable timer countdown and interrupt */
-       /* FIXME: should we write TIMER_ACK_IRQ here? */
+       /* FIXME: should we write TIMER_IRQ_ACK here? */
        snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0);
        spin_unlock_irqrestore(&chip->reg_lock, flags);
        snd_azf3328_dbgcallleave();
@@ -1626,9 +1960,10 @@ snd_azf3328_timer(struct snd_azf3328 *chip, int device)
 
        snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
        snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
-       if ((err = snd_timer_new(chip->card, "AZF3328", &tid, &timer)) < 0) {
+
+       err = snd_timer_new(chip->card, "AZF3328", &tid, &timer);
+       if (err < 0)
                goto out;
-       }
 
        strcpy(timer->name, "AZF3328 timer");
        timer->private_data = chip;
@@ -1636,6 +1971,8 @@ snd_azf3328_timer(struct snd_azf3328 *chip, int device)
 
        chip->timer = timer;
 
+       snd_azf3328_timer_stop(timer);
+
        err = 0;
 
 out:
@@ -1645,10 +1982,44 @@ out:
 
 /******************************************************************/
 
+static int
+snd_azf3328_free(struct snd_azf3328 *chip)
+{
+       if (chip->irq < 0)
+               goto __end_hw;
+
+       /* reset (close) mixer:
+        * first mute master volume, then reset
+        */
+       snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
+       snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
+
+       snd_azf3328_timer_stop(chip->timer);
+       snd_azf3328_gameport_free(chip);
+
+       if (chip->irq >= 0)
+               synchronize_irq(chip->irq);
+__end_hw:
+       if (chip->irq >= 0)
+               free_irq(chip->irq, chip);
+       pci_release_regions(chip->pci);
+       pci_disable_device(chip->pci);
+
+       kfree(chip);
+       return 0;
+}
+
+static int
+snd_azf3328_dev_free(struct snd_device *device)
+{
+       struct snd_azf3328 *chip = device->device_data;
+       return snd_azf3328_free(chip);
+}
+
 #if 0
 /* check whether a bit can be modified */
 static void
-snd_azf3328_test_bit(unsigned int reg, int bit)
+snd_azf3328_test_bit(unsigned unsigned reg, int bit)
 {
        unsigned char val, valoff, valon;
 
@@ -1659,42 +2030,74 @@ snd_azf3328_test_bit(unsigned int reg, int bit)
 
        outb(val|(1 << bit), reg);
        valon = inb(reg);
-       
+
        outb(val, reg);
 
-       printk(KERN_ERR "reg %04x bit %d: %02x %02x %02x\n", reg, bit, val, valoff, valon);
+       printk(KERN_ERR "reg %04x bit %d: %02x %02x %02x\n",
+                               reg, bit, val, valoff, valon
+       );
 }
 #endif
 
-#if DEBUG_MISC
-static void
+static inline void
 snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip)
 {
+#if DEBUG_MISC
        u16 tmp;
 
-       snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq);
-
-       snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_inb(chip, 0), snd_azf3328_io2_inb(chip, 1), snd_azf3328_io2_inb(chip, 2), snd_azf3328_io2_inb(chip, 3), snd_azf3328_io2_inb(chip, 4), snd_azf3328_io2_inb(chip, 5));
-
-       for (tmp=0; tmp <= 0x01; tmp += 1)
-               snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
+       snd_azf3328_dbgmisc(
+               "codec_io 0x%lx, game_io 0x%lx, mpu_io 0x%lx, "
+               "opl3_io 0x%lx, mixer_io 0x%lx, irq %d\n",
+               chip->codec_io, chip->game_io, chip->mpu_io,
+               chip->opl3_io, chip->mixer_io, chip->irq
+       );
+
+       snd_azf3328_dbgmisc("game %02x %02x %02x %02x %02x %02x\n",
+               snd_azf3328_game_inb(chip, 0),
+               snd_azf3328_game_inb(chip, 1),
+               snd_azf3328_game_inb(chip, 2),
+               snd_azf3328_game_inb(chip, 3),
+               snd_azf3328_game_inb(chip, 4),
+               snd_azf3328_game_inb(chip, 5)
+       );
+
+       for (tmp = 0; tmp < 0x07; tmp += 1)
+               snd_azf3328_dbgmisc("mpu_io 0x%04x\n", inb(chip->mpu_io + tmp));
+
+       for (tmp = 0; tmp <= 0x07; tmp += 1)
+               snd_azf3328_dbgmisc("0x%02x: game200 0x%04x, game208 0x%04x\n",
+                       tmp, inb(0x200 + tmp), inb(0x208 + tmp));
+
+       for (tmp = 0; tmp <= 0x01; tmp += 1)
+               snd_azf3328_dbgmisc(
+                       "0x%02x: mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, "
+                       "mpu330 0x%04x opl388 0x%04x opl38c 0x%04x\n",
+                               tmp,
+                               inb(0x300 + tmp),
+                               inb(0x310 + tmp),
+                               inb(0x320 + tmp),
+                               inb(0x330 + tmp),
+                               inb(0x388 + tmp),
+                               inb(0x38c + tmp)
+               );
 
        for (tmp = 0; tmp < AZF_IO_SIZE_CODEC; tmp += 2)
-               snd_azf3328_dbgmisc("codec 0x%02x: 0x%04x\n", tmp, snd_azf3328_codec_inw(chip, tmp));
+               snd_azf3328_dbgmisc("codec 0x%02x: 0x%04x\n",
+                       tmp, snd_azf3328_codec_inw(chip, tmp)
+               );
 
        for (tmp = 0; tmp < AZF_IO_SIZE_MIXER; tmp += 2)
-               snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n", tmp, snd_azf3328_mixer_inw(chip, tmp));
+               snd_azf3328_dbgmisc("mixer 0x%02x: 0x%04x\n",
+                       tmp, snd_azf3328_mixer_inw(chip, tmp)
+               );
+#endif /* DEBUG_MISC */
 }
-#else
-static inline void
-snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip) {}
-#endif
 
 static int __devinit
 snd_azf3328_create(struct snd_card *card,
-                                         struct pci_dev *pci,
-                                         unsigned long device_type,
-                                         struct snd_azf3328 ** rchip)
+                  struct pci_dev *pci,
+                  unsigned long device_type,
+                  struct snd_azf3328 **rchip)
 {
        struct snd_azf3328 *chip;
        int err;
@@ -1705,7 +2108,8 @@ snd_azf3328_create(struct snd_card *card,
 
        *rchip = NULL;
 
-       if ((err = pci_enable_device(pci)) < 0)
+       err = pci_enable_device(pci);
+       if (err < 0)
                return err;
 
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -1721,20 +2125,25 @@ snd_azf3328_create(struct snd_card *card,
        /* check if we can restrict PCI DMA transfers to 24 bits */
        if (pci_set_dma_mask(pci, DMA_24BIT_MASK) < 0 ||
            pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) {
-               snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
+               snd_printk(KERN_ERR "architecture does not support "
+                                       "24bit PCI busmaster DMA\n"
+               );
                err = -ENXIO;
                goto out_err;
        }
 
-       if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) {
+       err = pci_request_regions(pci, "Aztech AZF3328");
+       if (err < 0)
                goto out_err;
-       }
 
-       chip->codec_port = pci_resource_start(pci, 0);
-       chip->io2_port   = pci_resource_start(pci, 1);
-       chip->mpu_port   = pci_resource_start(pci, 2);
-       chip->synth_port = pci_resource_start(pci, 3);
-       chip->mixer_port = pci_resource_start(pci, 4);
+       chip->codec_io = pci_resource_start(pci, 0);
+       chip->game_io  = pci_resource_start(pci, 1);
+       chip->mpu_io   = pci_resource_start(pci, 2);
+       chip->opl3_io = pci_resource_start(pci, 3);
+       chip->mixer_io = pci_resource_start(pci, 4);
+
+       chip->audio_stream[AZF_PLAYBACK].portbase = chip->codec_io + 0x00;
+       chip->audio_stream[AZF_CAPTURE].portbase   = chip->codec_io + 0x20;
 
        if (request_irq(pci->irq, snd_azf3328_interrupt,
                        IRQF_SHARED, card->shortname, chip)) {
@@ -1747,29 +2156,29 @@ snd_azf3328_create(struct snd_card *card,
        synchronize_irq(chip->irq);
 
        snd_azf3328_debug_show_ports(chip);
-       
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+
+       err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
+       if (err < 0)
                goto out_err;
-       }
 
        /* create mixer interface & switches */
-       if ((err = snd_azf3328_mixer_new(chip)) < 0)
+       err = snd_azf3328_mixer_new(chip);
+       if (err < 0)
                goto out_err;
 
-#if 0
-       /* set very low bitrate to reduce noise and power consumption? */
-       snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, 5512, 8, 1);
-#endif
+       /* shutdown codecs to save power */
+               /* have snd_azf3328_codec_activity() act properly */
+       chip->audio_stream[AZF_PLAYBACK].running = 1;
+       snd_azf3328_codec_activity(chip, AZF_PLAYBACK, 0);
 
        /* standard chip init stuff */
-       /* default IRQ init value */
+               /* default IRQ init value */
        tmp = DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
 
        spin_lock_irq(&chip->reg_lock);
        snd_azf3328_codec_outb(chip, IDX_IO_PLAY_FLAGS, tmp);
        snd_azf3328_codec_outb(chip, IDX_IO_REC_FLAGS, tmp);
        snd_azf3328_codec_outb(chip, IDX_IO_SOMETHING_FLAGS, tmp);
-       snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); /* disable timer */
        spin_unlock_irq(&chip->reg_lock);
 
        snd_card_set_dev(card, &pci->dev);
@@ -1805,52 +2214,61 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
                return -ENOENT;
        }
 
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0 );
+       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
        if (card == NULL)
                return -ENOMEM;
 
        strcpy(card->driver, "AZF3328");
        strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
 
-        if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) {
+       err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip);
+       if (err < 0)
                goto out_err;
-       }
 
        card->private_data = chip;
 
-       if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401,
-                                       chip->mpu_port, MPU401_INFO_INTEGRATED,
-                                       pci->irq, 0, &chip->rmidi)) < 0) {
-               snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port);
+       err = snd_mpu401_uart_new(
+               card, 0, MPU401_HW_MPU401, chip->mpu_io, MPU401_INFO_INTEGRATED,
+               pci->irq, 0, &chip->rmidi
+       );
+       if (err < 0) {
+               snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
+                               chip->mpu_io
+               );
                goto out_err;
        }
 
-       if ((err = snd_azf3328_timer(chip, 0)) < 0) {
+       err = snd_azf3328_timer(chip, 0);
+       if (err < 0)
                goto out_err;
-       }
 
-       if ((err = snd_azf3328_pcm(chip, 0)) < 0) {
+       err = snd_azf3328_pcm(chip, 0);
+       if (err < 0)
                goto out_err;
-       }
 
-       if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2,
+       if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2,
                            OPL3_HW_AUTO, 1, &opl3) < 0) {
                snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
-                          chip->synth_port, chip->synth_port+2 );
+                          chip->opl3_io, chip->opl3_io+2
+               );
        } else {
-               if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+               /* need to use IDs 1, 2 since ID 0 is snd_azf3328_timer above */
+               err = snd_opl3_timer_new(opl3, 1, 2);
+               if (err < 0)
+                       goto out_err;
+               err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
+               if (err < 0)
                        goto out_err;
-               }
        }
 
        opl3->private_data = chip;
 
        sprintf(card->longname, "%s at 0x%lx, irq %i",
-               card->shortname, chip->codec_port, chip->irq);
+               card->shortname, chip->codec_io, chip->irq);
 
-       if ((err = snd_card_register(card)) < 0) {
+       err = snd_card_register(card);
+       if (err < 0)
                goto out_err;
-       }
 
 #ifdef MODULE
        printk(
@@ -1861,19 +2279,18 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
        1024000 / seqtimer_scaling, seqtimer_scaling);
 #endif
 
-       if (snd_azf3328_config_joystick(chip, dev) < 0)
-               snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
-                             snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
+       snd_azf3328_gameport(chip, dev);
 
        pci_set_drvdata(pci, card);
        dev++;
 
        err = 0;
        goto out;
-       
+
 out_err:
+       snd_printk(KERN_ERR "azf3328: something failed, exiting\n");
        snd_card_free(card);
-       
+
 out:
        snd_azf3328_dbgcallleave();
        return err;
@@ -1894,27 +2311,31 @@ snd_azf3328_suspend(struct pci_dev *pci, pm_message_t state)
 {
        struct snd_card *card = pci_get_drvdata(pci);
        struct snd_azf3328 *chip = card->private_data;
-       int reg;
+       unsigned reg;
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       
+
        snd_pcm_suspend_all(chip->pcm);
 
-       for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; reg++)
-               chip->saved_regs_mixer[reg] = inw(chip->mixer_port + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; ++reg)
+               chip->saved_regs_mixer[reg] = inw(chip->mixer_io + reg * 2);
 
        /* make sure to disable master volume etc. to prevent looping sound */
        snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1);
        snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
-       
-       for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; reg++)
-               chip->saved_regs_codec[reg] = inw(chip->codec_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_IO2_PM / 2; reg++)
-               chip->saved_regs_io2[reg] = inw(chip->io2_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; reg++)
-               chip->saved_regs_mpu[reg] = inw(chip->mpu_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_SYNTH_PM / 2; reg++)
-               chip->saved_regs_synth[reg] = inw(chip->synth_port + reg * 2);
+
+       for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; ++reg)
+               chip->saved_regs_codec[reg] = inw(chip->codec_io + reg * 2);
+
+       /* manually store the one currently relevant write-only reg, too */
+       chip->saved_regs_codec[IDX_IO_6AH / 2] = chip->shadow_reg_codec_6AH;
+
+       for (reg = 0; reg < AZF_IO_SIZE_GAME_PM / 2; ++reg)
+               chip->saved_regs_game[reg] = inw(chip->game_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; ++reg)
+               chip->saved_regs_mpu[reg] = inw(chip->mpu_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_OPL3_PM / 2; ++reg)
+               chip->saved_regs_opl3[reg] = inw(chip->opl3_io + reg * 2);
 
        pci_disable_device(pci);
        pci_save_state(pci);
@@ -1927,7 +2348,7 @@ snd_azf3328_resume(struct pci_dev *pci)
 {
        struct snd_card *card = pci_get_drvdata(pci);
        struct snd_azf3328 *chip = card->private_data;
-       int reg;
+       unsigned reg;
 
        pci_set_power_state(pci, PCI_D0);
        pci_restore_state(pci);
@@ -1939,23 +2360,21 @@ snd_azf3328_resume(struct pci_dev *pci)
        }
        pci_set_master(pci);
 
-       for (reg = 0; reg < AZF_IO_SIZE_IO2_PM / 2; reg++)
-               outw(chip->saved_regs_io2[reg], chip->io2_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; reg++)
-               outw(chip->saved_regs_mpu[reg], chip->mpu_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_SYNTH_PM / 2; reg++)
-               outw(chip->saved_regs_synth[reg], chip->synth_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; reg++)
-               outw(chip->saved_regs_mixer[reg], chip->mixer_port + reg * 2);
-       for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; reg++)
-               outw(chip->saved_regs_codec[reg], chip->codec_port + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_GAME_PM / 2; ++reg)
+               outw(chip->saved_regs_game[reg], chip->game_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_MPU_PM / 2; ++reg)
+               outw(chip->saved_regs_mpu[reg], chip->mpu_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_OPL3_PM / 2; ++reg)
+               outw(chip->saved_regs_opl3[reg], chip->opl3_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_MIXER_PM / 2; ++reg)
+               outw(chip->saved_regs_mixer[reg], chip->mixer_io + reg * 2);
+       for (reg = 0; reg < AZF_IO_SIZE_CODEC_PM / 2; ++reg)
+               outw(chip->saved_regs_codec[reg], chip->codec_io + reg * 2);
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        return 0;
 }
-#endif
-
-
+#endif /* CONFIG_PM */
 
 
 static struct pci_driver driver = {
index 679fa99..7e3e894 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef __SOUND_AZT3328_H
 #define __SOUND_AZT3328_H
 
-/* "PU" == "power-up value", as tested on PCI168 PCI rev. 10 */
+/* "PU" == "power-up value", as tested on PCI168 PCI rev. 10
+ * "WRITE_ONLY"  == register does not indicate actual bit values */
 
 /*** main I/O area port indices ***/
 /* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */
   #define SOUNDFORMAT_XTAL1            0x00
   #define SOUNDFORMAT_XTAL2            0x01
     /* all _SUSPECTED_ values are not used by Windows drivers, so we don't
-     * have any hard facts, only rough measurements */
+     * have any hard facts, only rough measurements.
+     * All we know is that the crystal used on the board has 24.576MHz,
+     * like many soundcards (which results in the frequencies below when
+     * using certain divider values selected by the values below) */
     #define SOUNDFORMAT_FREQ_SUSPECTED_4000    0x0c | SOUNDFORMAT_XTAL1
     #define SOUNDFORMAT_FREQ_SUSPECTED_4800    0x0a | SOUNDFORMAT_XTAL1
     #define SOUNDFORMAT_FREQ_5510              0x0c | SOUNDFORMAT_XTAL2
   #define SOUNDFORMAT_FLAG_16BIT       0x0010
   #define SOUNDFORMAT_FLAG_2CHANNELS   0x0020
 
+/* define frequency helpers, for maximum value safety */
+enum azf_freq_t {
+#define AZF_FREQ(rate) AZF_FREQ_##rate = rate
+  AZF_FREQ(4000),
+  AZF_FREQ(4800),
+  AZF_FREQ(5512),
+  AZF_FREQ(6620),
+  AZF_FREQ(8000),
+  AZF_FREQ(9600),
+  AZF_FREQ(11025),
+  AZF_FREQ(13240),
+  AZF_FREQ(16000),
+  AZF_FREQ(22050),
+  AZF_FREQ(32000),
+  AZF_FREQ(44100),
+  AZF_FREQ(48000),
+  AZF_FREQ(66200),
+#undef AZF_FREQ
+} AZF_FREQUENCIES;
+
 /** recording area (see also: playback bit flag definitions) **/
 #define IDX_IO_REC_FLAGS       0x20 /* ??, PU:0x0000 */
 #define IDX_IO_REC_IRQTYPE     0x22 /* ??, PU:0x0000 */
 
 /** DirectX timer, main interrupt area (FIXME: and something else?) **/ 
 #define IDX_IO_TIMER_VALUE     0x60 /* found this timer area by pure luck :-) */
-  #define TIMER_VALUE_MASK             0x000fffffUL /* timer countdown value; triggers IRQ when timer is finished */
-  #define TIMER_ENABLE_COUNTDOWN       0x01000000UL /* activate the timer countdown */
-  #define TIMER_ENABLE_IRQ             0x02000000UL /* trigger timer IRQ on zero transition */
-  #define TIMER_ACK_IRQ                        0x04000000UL /* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?) had 0x0020 set upon IRQ handler */
+  /* timer countdown value; triggers IRQ when timer is finished */
+  #define TIMER_VALUE_MASK             0x000fffffUL
+  /* activate timer countdown */
+  #define TIMER_COUNTDOWN_ENABLE       0x01000000UL
+  /* trigger timer IRQ on zero transition */
+  #define TIMER_IRQ_ENABLE             0x02000000UL
+  /* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?)
+   * had 0x0020 set upon IRQ handler */
+  #define TIMER_IRQ_ACK                        0x04000000UL
 #define IDX_IO_IRQSTATUS        0x64
-  #define IRQ_PLAYBACK                 0x0001
-  #define IRQ_RECORDING                        0x0002
-  #define IRQ_MPU401                   0x0010
-  #define IRQ_TIMER                    0x0020 /* DirectX timer */
-  #define IRQ_UNKNOWN1                 0x0040 /* probably unused, or possibly I2S port? or gameport IRQ? */
-  #define IRQ_UNKNOWN2                 0x0080 /* probably unused, or possibly I2S port? or gameport IRQ? */
+  /* some IRQ bit in here might also be used to signal a power-management timer
+   * timeout, to request shutdown of the chip (e.g. AD1815JS has such a thing).
+   * Some OPL3 hardware (e.g. in LM4560) has some special timer hardware which
+   * can trigger an OPL3 timer IRQ, so maybe there's such a thing as well... */
+
+  #define IRQ_PLAYBACK 0x0001
+  #define IRQ_RECORDING        0x0002
+  #define IRQ_UNKNOWN1 0x0004 /* most probably I2S port */
+  #define IRQ_GAMEPORT 0x0008 /* Interrupt of Digital(ly) Enhanced Game Port */
+  #define IRQ_MPU401   0x0010
+  #define IRQ_TIMER    0x0020 /* DirectX timer */
+  #define IRQ_UNKNOWN2 0x0040 /* probably unused, or possibly I2S port? */
+  #define IRQ_UNKNOWN3 0x0080 /* probably unused, or possibly I2S port? */
 #define IDX_IO_66H             0x66    /* writing 0xffff returns 0x0000 */
-#define IDX_IO_SOME_VALUE      0x68    /* this is set to e.g. 0x3ff or 0x300, and writable; maybe some buffer limit, but I couldn't find out more, PU:0x00ff */
-#define IDX_IO_6AH             0x6A    /* this WORD can be set to have bits 0x0028 activated (FIXME: correct??); actually inhibits PCM playback!!! maybe power management?? */
-  #define IO_6A_PAUSE_PLAYBACK         0x0200 /* bit 9; sure, this pauses playback, but what the heck is this really about?? */
-#define IDX_IO_6CH             0x6C
-#define IDX_IO_6EH             0x6E    /* writing 0xffff returns 0x83fe */
-/* further I/O indices not saved/restored, so probably not used */
+  /* this is set to e.g. 0x3ff or 0x300, and writable;
+   * maybe some buffer limit, but I couldn't find out more, PU:0x00ff: */
+#define IDX_IO_SOME_VALUE      0x68
+  #define IO_68_RANDOM_TOGGLE1 0x0100  /* toggles randomly */
+  #define IO_68_RANDOM_TOGGLE2 0x0200  /* toggles randomly */
+  /* umm, nope, behaviour of these bits changes depending on what we wrote
+   * to 0x6b!!
+   * And they change upon playback/stop, too:
+   * Writing a value to 0x68 will display this exact value during playback,
+   * too but when stopped it can fall back to a rather different
+   * seemingly random value). Hmm, possibly this is a register which
+   * has a remote shadow which needs proper device supply which only exists
+   * in case playback is active? Or is this driver-induced?
+   */
+
+/* this WORD can be set to have bits 0x0028 activated (FIXME: correct??);
+ * actually inhibits PCM playback!!! maybe power management??: */
+#define IDX_IO_6AH             0x6A /* WRITE_ONLY! */
+  /* bit 5: enabling this will activate permanent counting of bytes 2/3
+   * at gameport I/O (0xb402/3) (equal values each) and cause
+   * gameport legacy I/O at 0x0200 to be _DISABLED_!
+   * Is this Digital Enhanced Game Port Enable??? Or maybe it's Testmode
+   * for Enhanced Digital Gameport (see 4D Wave DX card): */
+  #define IO_6A_SOMETHING1_GAMEPORT    0x0020
+  /* bit 8; sure, this _pauses_ playback (later resumes at same spot!),
+   * but what the heck is this really about??: */
+  #define IO_6A_PAUSE_PLAYBACK_BIT8    0x0100
+  /* bit 9; sure, this _pauses_ playback (later resumes at same spot!),
+   * but what the heck is this really about??: */
+  #define IO_6A_PAUSE_PLAYBACK_BIT9    0x0200
+       /* BIT8 and BIT9 are _NOT_ able to affect OPL3 MIDI playback,
+        * thus it suggests influence on PCM only!!
+        * However OTOH there seems to be no bit anywhere around here
+        * which is able to disable OPL3... */
+  /* bit 10: enabling this actually changes values at legacy gameport
+   * I/O address (0x200); is this enabling of the Digital Enhanced Game Port???
+   * Or maybe this simply switches off the NE558 circuit, since enabling this
+   * still lets us evaluate button states, but not axis states */
+  #define IO_6A_SOMETHING2_GAMEPORT      0x0400
+       /* writing 0x0300: causes quite some crackling during
+        * PC activity such as switching windows (PCI traffic??
+        * --> FIFO/timing settings???) */
+       /* writing 0x0100 plus/or 0x0200 inhibits playback */
+       /* since the Windows .INF file has Flag_Enable_JoyStick and
+        * Flag_Enable_SB_DOS_Emulation directly together, it stands to reason
+        * that some other bit in this same register might be responsible
+        * for SB DOS Emulation activation (note that the file did NOT define
+        * a switch for OPL3!) */
+#define IDX_IO_6CH             0x6C    /* unknown; fully read-writable */
+#define IDX_IO_6EH             0x6E
+       /* writing 0xffff returns 0x83fe (or 0x03fe only).
+        * writing 0x83 (and only 0x83!!) to 0x6f will cause 0x6c to switch
+        * from 0000 to ffff. */
 
+/* further I/O indices not saved/restored and not readable after writing,
+ * so probably not used */
 
-/*** I/O 2 area port indices ***/
+
+/*** Gameport area port indices ***/
 /* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */ 
-#define AZF_IO_SIZE_IO2                0x08
-#define AZF_IO_SIZE_IO2_PM     0x06
+#define AZF_IO_SIZE_GAME               0x08
+#define AZF_IO_SIZE_GAME_PM    0x06
+
+enum {
+       AZF_GAME_LEGACY_IO_PORT = 0x200
+} AZF_GAME_CONFIGS;
+
+#define IDX_GAME_LEGACY_COMPATIBLE     0x00
+       /* in some operation mode, writing anything to this port
+        * triggers an interrupt:
+        * yup, that's in case IDX_GAME_01H has one of the
+        * axis measurement bits enabled
+        * (and of course one needs to have GAME_HWCFG_IRQ_ENABLE, too) */
+
+#define IDX_GAME_AXES_CONFIG            0x01
+       /* NOTE: layout of this register awfully similar (read: "identical??")
+        * to AD1815JS.pdf (p.29) */
+
+  /* enables axis 1 (X axis) measurement: */
+  #define GAME_AXES_ENABLE_1           0x01
+  /* enables axis 2 (Y axis) measurement: */
+  #define GAME_AXES_ENABLE_2           0x02
+  /* enables axis 3 (X axis) measurement: */
+  #define GAME_AXES_ENABLE_3           0x04
+  /* enables axis 4 (Y axis) measurement: */
+  #define GAME_AXES_ENABLE_4           0x08
+  /* selects the current axis to read the measured value of
+   * (at IDX_GAME_AXIS_VALUE):
+   * 00 = axis 1, 01 = axis 2, 10 = axis 3, 11 = axis 4: */
+  #define GAME_AXES_READ_MASK          0x30
+  /* enable to have the latch continuously accept ADC values
+   * (and continuously cause interrupts in case interrupts are enabled);
+   * AD1815JS.pdf says it's ~16ms interval there: */
+  #define GAME_AXES_LATCH_ENABLE       0x40
+  /* joystick data (measured axes) ready for reading: */
+  #define GAME_AXES_SAMPLING_READY     0x80
+
+  /* NOTE: other card specs (SiS960 and others!) state that the
+   * game position latches should be frozen when reading and be freed
+   * (== reset?) after reading!!!
+   * Freezing most likely means disabling 0x40 (GAME_AXES_LATCH_ENABLE),
+   *  but how to free the value? */
+  /* An internet search for "gameport latch ADC" should provide some insight
+   * into how to program such a gameport system. */
+
+  /* writing 0xf0 to 01H once reset both counters to 0, in some special mode!?
+   * yup, in case 6AH 0x20 is not enabled
+   * (and 0x40 is sufficient, 0xf0 is not needed) */
+
+#define IDX_GAME_AXIS_VALUE    0x02
+       /* R: value of currently configured axis (word value!);
+        * W: trigger axis measurement */
+
+#define IDX_GAME_HWCONFIG      0x04
+       /* note: bits 4 to 7 are never set (== 0) when reading!
+        * --> reserved bits? */
+  /* enables IRQ notification upon axes measurement ready: */
+  #define GAME_HWCFG_IRQ_ENABLE                        0x01
+  /* these bits choose a different frequency for the
+   *  internal ADC counter increment.
+   * hmm, seems to be a combo of bits:
+   * 00 --> standard frequency
+   * 10 --> 1/2
+   * 01 --> 1/20
+   * 11 --> 1/200: */
+  #define GAME_HWCFG_ADC_COUNTER_FREQ_MASK     0x06
 
-#define IDX_IO2_LEGACY_ADDR    0x04
-  #define LEGACY_SOMETHING             0x01 /* OPL3?? */
-  #define LEGACY_JOY                   0x08
+  /* enable gameport legacy I/O address (0x200)
+   * I was unable to locate any configurability for a different address: */
+  #define GAME_HWCFG_LEGACY_ADDRESS_ENABLE     0x08
 
+/*** MPU401 ***/
 #define AZF_IO_SIZE_MPU                0x04
 #define AZF_IO_SIZE_MPU_PM     0x04
 
-#define AZF_IO_SIZE_SYNTH      0x08
-#define AZF_IO_SIZE_SYNTH_PM   0x06
+/*** OPL3 synth ***/
+#define AZF_IO_SIZE_OPL3       0x08
+#define AZF_IO_SIZE_OPL3_PM    0x06
+/* hmm, given that a standard OPL3 has 4 registers only,
+ * there might be some enhanced functionality lurking at the end
+ * (especially since register 0x04 has a "non-empty" value 0xfe) */
 
 /*** mixer I/O area port indices ***/
 /* (only 0x22 of 0x40 bytes saved/restored by Windows driver)
index ecbe79b..2f8b28a 100644 (file)
@@ -249,6 +249,11 @@ static struct snd_ca0106_details ca0106_chip_details[] = {
           .name   = "MSI K8N Diamond MB [SB0438]",
           .gpio_type = 2,
           .i2c_adc = 1 } ,
+        /* Another MSI K8N Diamond MB, which has apprently a different SSID */
+        { .serial = 0x10091102,
+          .name   = "MSI K8N Diamond MB",
+          .gpio_type = 2,
+          .i2c_adc = 1 } ,
         /* Shuttle XPC SD31P which has an onboard Creative Labs
          * Sound Blaster Live! 24-bit EAX
          * high-definition 7.1 audio processor".
index 548c9cc..2f283ea 100644 (file)
@@ -1528,6 +1528,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
         .ca0151_chip = 1,
         .spk71 = 1,
         .spdif_bug = 1,
+        .invert_shared_spdif = 1,      /* digital/analog switch swapped */
         .adc_1361t = 1,  /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */
         .ac97_chip = 1} ,
        {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
index fd22120..f34bbfb 100644 (file)
@@ -1578,6 +1578,10 @@ static int snd_emu10k1_shared_spdif_get(struct snd_kcontrol *kcontrol,
                ucontrol->value.integer.value[0] = inl(emu->port + A_IOCFG) & A_IOCFG_GPOUT0 ? 1 : 0;
        else
                ucontrol->value.integer.value[0] = inl(emu->port + HCFG) & HCFG_GPOUT0 ? 1 : 0;
+       if (emu->card_capabilities->invert_shared_spdif)
+               ucontrol->value.integer.value[0] =
+                       !ucontrol->value.integer.value[0];
+               
        return 0;
 }
 
@@ -1586,15 +1590,18 @@ static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
 {
        unsigned long flags;
        struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
-       unsigned int reg, val;
+       unsigned int reg, val, sw;
        int change = 0;
 
+       sw = ucontrol->value.integer.value[0];
+       if (emu->card_capabilities->invert_shared_spdif)
+               sw = !sw;
        spin_lock_irqsave(&emu->reg_lock, flags);
        if ( emu->card_capabilities->i2c_adc) {
                /* Do nothing for Audigy 2 ZS Notebook */
        } else if (emu->audigy) {
                reg = inl(emu->port + A_IOCFG);
-               val = ucontrol->value.integer.value[0] ? A_IOCFG_GPOUT0 : 0;
+               val = sw ? A_IOCFG_GPOUT0 : 0;
                change = (reg & A_IOCFG_GPOUT0) != val;
                if (change) {
                        reg &= ~A_IOCFG_GPOUT0;
@@ -1603,7 +1610,7 @@ static int snd_emu10k1_shared_spdif_put(struct snd_kcontrol *kcontrol,
                }
        }
        reg = inl(emu->port + HCFG);
-       val = ucontrol->value.integer.value[0] ? HCFG_GPOUT0 : 0;
+       val = sw ? HCFG_GPOUT0 : 0;
        change |= (reg & HCFG_GPOUT0) != val;
        if (change) {
                reg &= ~HCFG_GPOUT0;
index 916c1db..7d379f5 100644 (file)
@@ -437,43 +437,49 @@ static void get_single_page_range(struct snd_util_memhdr *hdr,
        *last_page_ret = last_page;
 }
 
+/* release allocated pages */
+static void __synth_free_pages(struct snd_emu10k1 *emu, int first_page,
+                              int last_page)
+{
+       int page;
+
+       for (page = first_page; page <= last_page; page++) {
+               free_page((unsigned long)emu->page_ptr_table[page]);
+               emu->page_addr_table[page] = 0;
+               emu->page_ptr_table[page] = NULL;
+       }
+}
+
 /*
  * allocate kernel pages
  */
 static int synth_alloc_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk)
 {
        int page, first_page, last_page;
-       struct snd_dma_buffer dmab;
 
        emu10k1_memblk_init(blk);
        get_single_page_range(emu->memhdr, blk, &first_page, &last_page);
        /* allocate kernel pages */
        for (page = first_page; page <= last_page; page++) {
-               if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci),
-                                       PAGE_SIZE, &dmab) < 0)
-                       goto __fail;
-               if (! is_valid_page(emu, dmab.addr)) {
-                       snd_dma_free_pages(&dmab);
-                       goto __fail;
+               /* first try to allocate from <4GB zone */
+               struct page *p = alloc_page(GFP_KERNEL | GFP_DMA32 |
+                                           __GFP_NOWARN);
+               if (!p || (page_to_pfn(p) & ~(emu->dma_mask >> PAGE_SHIFT))) {
+                       if (p)
+                               __free_page(p);
+                       /* try to allocate from <16MB zone */
+                       p = alloc_page(GFP_ATOMIC | GFP_DMA |
+                                      __GFP_NORETRY | /* no OOM-killer */
+                                      __GFP_NOWARN);
+               }
+               if (!p) {
+                       __synth_free_pages(emu, first_page, page - 1);
+                       return -ENOMEM;
                }
-               emu->page_addr_table[page] = dmab.addr;
-               emu->page_ptr_table[page] = dmab.area;
+               emu->page_addr_table[page] = page_to_phys(p);
+               emu->page_ptr_table[page] = page_address(p);
        }
        return 0;
-
-__fail:
-       /* release allocated pages */
-       last_page = page - 1;
-       for (page = first_page; page <= last_page; page++) {
-               dmab.area = emu->page_ptr_table[page];
-               dmab.addr = emu->page_addr_table[page];
-               dmab.bytes = PAGE_SIZE;
-               snd_dma_free_pages(&dmab);
-               emu->page_addr_table[page] = 0;
-               emu->page_ptr_table[page] = NULL;
-       }
-
-       return -ENOMEM;
 }
 
 /*
@@ -481,23 +487,10 @@ __fail:
  */
 static int synth_free_pages(struct snd_emu10k1 *emu, struct snd_emu10k1_memblk *blk)
 {
-       int page, first_page, last_page;
-       struct snd_dma_buffer dmab;
+       int first_page, last_page;
 
        get_single_page_range(emu->memhdr, blk, &first_page, &last_page);
-       dmab.dev.type = SNDRV_DMA_TYPE_DEV;
-       dmab.dev.dev = snd_dma_pci_data(emu->pci);
-       for (page = first_page; page <= last_page; page++) {
-               if (emu->page_ptr_table[page] == NULL)
-                       continue;
-               dmab.area = emu->page_ptr_table[page];
-               dmab.addr = emu->page_addr_table[page];
-               dmab.bytes = PAGE_SIZE;
-               snd_dma_free_pages(&dmab);
-               emu->page_addr_table[page] = 0;
-               emu->page_ptr_table[page] = NULL;
-       }
-
+       __synth_free_pages(emu, first_page, last_page);
        return 0;
 }
 
index a6be6e3..d2e1093 100644 (file)
@@ -2335,7 +2335,7 @@ int snd_hda_check_board_config(struct hda_codec *codec,
        if (!tbl)
                return -1;
        if (tbl->value >= 0 && tbl->value < num_configs) {
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
                char tmp[10];
                const char *model = NULL;
                if (models)
index dcd390b..efc6828 100644 (file)
@@ -78,7 +78,7 @@ enum {
 #define AC_VERB_GET_BEEP_CONTROL               0x0f0a
 #define AC_VERB_GET_EAPD_BTLENABLE             0x0f0c
 #define AC_VERB_GET_DIGI_CONVERT_1             0x0f0d
-#define AC_VERB_GET_DIGI_CONVERT_2             0x0f0e
+#define AC_VERB_GET_DIGI_CONVERT_2             0x0f0e /* unused */
 #define AC_VERB_GET_VOLUME_KNOB_CONTROL                0x0f0f
 /* f10-f1a: GPIO */
 #define AC_VERB_GET_GPIO_DATA                  0x0f15
index 2177d9a..6e18a42 100644 (file)
@@ -88,7 +88,7 @@ static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file,
 
 static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
 {
-#ifndef CONFIG_SND_DEBUG_DETECT
+#ifndef CONFIG_SND_DEBUG_VERBOSE
        if (!capable(CAP_SYS_RAWIO))
                return -EACCES;
 #endif
index b3a618e..16715a6 100644 (file)
@@ -55,6 +55,7 @@ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
 static char *model[SNDRV_CARDS];
 static int position_fix[SNDRV_CARDS];
+static int bdl_pos_adj[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
 static int probe_mask[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = -1};
 static int single_cmd;
 static int enable_msi;
@@ -69,7 +70,9 @@ module_param_array(model, charp, NULL, 0444);
 MODULE_PARM_DESC(model, "Use the given board model.");
 module_param_array(position_fix, int, NULL, 0444);
 MODULE_PARM_DESC(position_fix, "Fix DMA pointer "
-                "(0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size).");
+                "(0 = auto, 1 = none, 2 = POSBUF).");
+module_param_array(bdl_pos_adj, int, NULL, 0644);
+MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
 module_param_array(probe_mask, int, NULL, 0444);
 MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
 module_param(single_cmd, bool, 0444);
@@ -197,6 +200,10 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 #define ATIHDMI_NUM_CAPTURE    0
 #define ATIHDMI_NUM_PLAYBACK   1
 
+/* TERA has 4 playback and 3 capture */
+#define TERA_NUM_CAPTURE       3
+#define TERA_NUM_PLAYBACK      4
+
 /* this number is statically defined for simplicity */
 #define MAX_AZX_DEV            16
 
@@ -259,9 +266,8 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
 /* position fix mode */
 enum {
        POS_FIX_AUTO,
-       POS_FIX_NONE,
+       POS_FIX_LPIB,
        POS_FIX_POSBUF,
-       POS_FIX_FIFO,
 };
 
 /* Defines for ATI HD Audio support in SB450 south bridge */
@@ -285,6 +291,7 @@ struct azx_dev {
        u32 *posbuf;            /* position buffer pointer */
 
        unsigned int bufsize;   /* size of the play buffer in bytes */
+       unsigned int period_bytes; /* size of the period in bytes */
        unsigned int frags;     /* number for period in the play buffer */
        unsigned int fifo_size; /* FIFO size */
 
@@ -301,11 +308,11 @@ struct azx_dev {
                                         */
        unsigned char stream_tag;       /* assigned stream */
        unsigned char index;            /* stream index */
-       /* for sanity check of position buffer */
-       unsigned int period_intr;
 
        unsigned int opened :1;
        unsigned int running :1;
+       unsigned int irq_pending :1;
+       unsigned int irq_ignore :1;
 };
 
 /* CORB/RIRB */
@@ -323,6 +330,7 @@ struct azx_rb {
 struct azx {
        struct snd_card *card;
        struct pci_dev *pci;
+       int dev_index;
 
        /* chip type specific */
        int driver_type;
@@ -366,9 +374,13 @@ struct azx {
        unsigned int single_cmd :1;
        unsigned int polling_mode :1;
        unsigned int msi :1;
+       unsigned int irq_pending_warned :1;
 
        /* for debugging */
        unsigned int last_cmd;  /* last issued command (to sync) */
+
+       /* for pending irqs */
+       struct work_struct irq_pending_work;
 };
 
 /* driver types */
@@ -381,6 +393,7 @@ enum {
        AZX_DRIVER_SIS,
        AZX_DRIVER_ULI,
        AZX_DRIVER_NVIDIA,
+       AZX_DRIVER_TERA,
 };
 
 static char *driver_short_names[] __devinitdata = {
@@ -392,6 +405,7 @@ static char *driver_short_names[] __devinitdata = {
        [AZX_DRIVER_SIS] = "HDA SIS966",
        [AZX_DRIVER_ULI] = "HDA ULI M5461",
        [AZX_DRIVER_NVIDIA] = "HDA NVidia",
+       [AZX_DRIVER_TERA] = "HDA Teradici", 
 };
 
 /*
@@ -426,11 +440,6 @@ static char *driver_short_names[] __devinitdata = {
 /* for pcm support */
 #define get_azx_dev(substream) (substream->runtime->private_data)
 
-/* Get the upper 32bit of the given dma_addr_t
- * Compiler should optimize and eliminate the code if dma_addr_t is 32bit
- */
-#define upper_32bit(addr) (sizeof(addr) > 4 ? (u32)((addr) >> 32) : (u32)0)
-
 static int azx_acquire_irq(struct azx *chip, int do_disconnect);
 
 /*
@@ -461,7 +470,7 @@ static void azx_init_cmd_io(struct azx *chip)
        chip->corb.addr = chip->rb.addr;
        chip->corb.buf = (u32 *)chip->rb.area;
        azx_writel(chip, CORBLBASE, (u32)chip->corb.addr);
-       azx_writel(chip, CORBUBASE, upper_32bit(chip->corb.addr));
+       azx_writel(chip, CORBUBASE, upper_32_bits(chip->corb.addr));
 
        /* set the corb size to 256 entries (ULI requires explicitly) */
        azx_writeb(chip, CORBSIZE, 0x02);
@@ -476,7 +485,7 @@ static void azx_init_cmd_io(struct azx *chip)
        chip->rirb.addr = chip->rb.addr + 2048;
        chip->rirb.buf = (u32 *)(chip->rb.area + 2048);
        azx_writel(chip, RIRBLBASE, (u32)chip->rirb.addr);
-       azx_writel(chip, RIRBUBASE, upper_32bit(chip->rirb.addr));
+       azx_writel(chip, RIRBUBASE, upper_32_bits(chip->rirb.addr));
 
        /* set the rirb size to 256 entries (ULI requires explicitly) */
        azx_writeb(chip, RIRBSIZE, 0x02);
@@ -847,7 +856,7 @@ static void azx_init_chip(struct azx *chip)
 
        /* program the position buffer */
        azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
-       azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr));
+       azx_writel(chip, DPUBASE, upper_32_bits(chip->posbuf.addr));
 
        chip->initialized = 1;
 }
@@ -908,6 +917,8 @@ static void azx_init_pci(struct azx *chip)
 }
 
 
+static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev);
+
 /*
  * interrupt handler
  */
@@ -930,11 +941,23 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
                azx_dev = &chip->azx_dev[i];
                if (status & azx_dev->sd_int_sta_mask) {
                        azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK);
-                       if (azx_dev->substream && azx_dev->running) {
-                               azx_dev->period_intr++;
+                       if (!azx_dev->substream || !azx_dev->running)
+                               continue;
+                       /* ignore the first dummy IRQ (due to pos_adj) */
+                       if (azx_dev->irq_ignore) {
+                               azx_dev->irq_ignore = 0;
+                               continue;
+                       }
+                       /* check whether this IRQ is really acceptable */
+                       if (azx_position_ok(chip, azx_dev)) {
+                               azx_dev->irq_pending = 0;
                                spin_unlock(&chip->reg_lock);
                                snd_pcm_period_elapsed(azx_dev->substream);
                                spin_lock(&chip->reg_lock);
+                       } else {
+                               /* bogus IRQ, process it later */
+                               azx_dev->irq_pending = 1;
+                               schedule_work(&chip->irq_pending_work);
                        }
                }
        }
@@ -958,60 +981,108 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
 }
 
 
+/*
+ * set up a BDL entry
+ */
+static int setup_bdle(struct snd_pcm_substream *substream,
+                     struct azx_dev *azx_dev, u32 **bdlp,
+                     int ofs, int size, int with_ioc)
+{
+       struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
+       u32 *bdl = *bdlp;
+
+       while (size > 0) {
+               dma_addr_t addr;
+               int chunk;
+
+               if (azx_dev->frags >= AZX_MAX_BDL_ENTRIES)
+                       return -EINVAL;
+
+               addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
+               /* program the address field of the BDL entry */
+               bdl[0] = cpu_to_le32((u32)addr);
+               bdl[1] = cpu_to_le32(upper_32_bits(addr));
+               /* program the size field of the BDL entry */
+               chunk = PAGE_SIZE - (ofs % PAGE_SIZE);
+               if (size < chunk)
+                       chunk = size;
+               bdl[2] = cpu_to_le32(chunk);
+               /* program the IOC to enable interrupt
+                * only when the whole fragment is processed
+                */
+               size -= chunk;
+               bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
+               bdl += 4;
+               azx_dev->frags++;
+               ofs += chunk;
+       }
+       *bdlp = bdl;
+       return ofs;
+}
+
 /*
  * set up BDL entries
  */
-static int azx_setup_periods(struct snd_pcm_substream *substream,
+static int azx_setup_periods(struct azx *chip,
+                            struct snd_pcm_substream *substream,
                             struct azx_dev *azx_dev)
 {
-       struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
        u32 *bdl;
        int i, ofs, periods, period_bytes;
+       int pos_adj;
 
        /* reset BDL address */
        azx_sd_writel(azx_dev, SD_BDLPL, 0);
        azx_sd_writel(azx_dev, SD_BDLPU, 0);
 
        period_bytes = snd_pcm_lib_period_bytes(substream);
+       azx_dev->period_bytes = period_bytes;
        periods = azx_dev->bufsize / period_bytes;
 
        /* program the initial BDL entries */
        bdl = (u32 *)azx_dev->bdl.area;
        ofs = 0;
        azx_dev->frags = 0;
-       for (i = 0; i < periods; i++) {
-               int size, rest;
-               if (i >= AZX_MAX_BDL_ENTRIES) {
-                       snd_printk(KERN_ERR "Too many BDL entries: "
-                                  "buffer=%d, period=%d\n",
-                                  azx_dev->bufsize, period_bytes);
-                       /* reset */
-                       azx_sd_writel(azx_dev, SD_BDLPL, 0);
-                       azx_sd_writel(azx_dev, SD_BDLPU, 0);
-                       return -EINVAL;
+       azx_dev->irq_ignore = 0;
+       pos_adj = bdl_pos_adj[chip->dev_index];
+       if (pos_adj > 0) {
+               struct snd_pcm_runtime *runtime = substream->runtime;
+               pos_adj = (pos_adj * runtime->rate + 47999) / 48000;
+               if (!pos_adj)
+                       pos_adj = 1;
+               pos_adj = frames_to_bytes(runtime, pos_adj);
+               if (pos_adj >= period_bytes) {
+                       snd_printk(KERN_WARNING "Too big adjustment %d\n",
+                                  bdl_pos_adj[chip->dev_index]);
+                       pos_adj = 0;
+               } else {
+                       ofs = setup_bdle(substream, azx_dev,
+                                        &bdl, ofs, pos_adj, 1);
+                       if (ofs < 0)
+                               goto error;
+                       azx_dev->irq_ignore = 1;
                }
-               rest = period_bytes;
-               do {
-                       dma_addr_t addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
-                       /* program the address field of the BDL entry */
-                       bdl[0] = cpu_to_le32((u32)addr);
-                       bdl[1] = cpu_to_le32(upper_32bit(addr));
-                       /* program the size field of the BDL entry */
-                       size = PAGE_SIZE - (ofs % PAGE_SIZE);
-                       if (rest < size)
-                               size = rest;
-                       bdl[2] = cpu_to_le32(size);
-                       /* program the IOC to enable interrupt
-                        * only when the whole fragment is processed
-                        */
-                       rest -= size;
-                       bdl[3] = rest ? 0 : cpu_to_le32(0x01);
-                       bdl += 4;
-                       azx_dev->frags++;
-                       ofs += size;
-               } while (rest > 0);
+       } else
+               pos_adj = 0;
+       for (i = 0; i < periods; i++) {
+               if (i == periods - 1 && pos_adj)
+                       ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
+                                        period_bytes - pos_adj, 0);
+               else
+                       ofs = setup_bdle(substream, azx_dev, &bdl, ofs,
+                                        period_bytes, 1);
+               if (ofs < 0)
+                       goto error;
        }
        return 0;
+
+ error:
+       snd_printk(KERN_ERR "Too many BDL entries: buffer=%d, period=%d\n",
+                  azx_dev->bufsize, period_bytes);
+       /* reset */
+       azx_sd_writel(azx_dev, SD_BDLPL, 0);
+       azx_sd_writel(azx_dev, SD_BDLPU, 0);
+       return -EINVAL;
 }
 
 /*
@@ -1062,7 +1133,7 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
        /* lower BDL address */
        azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
        /* upper BDL address */
-       azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl.addr));
+       azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
 
        /* enable the position buffer */
        if (chip->position_fix == POS_FIX_POSBUF ||
@@ -1085,7 +1156,7 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
  */
 
 static unsigned int azx_max_codecs[] __devinitdata = {
-       [AZX_DRIVER_ICH] = 3,
+       [AZX_DRIVER_ICH] = 4,           /* Some ICH9 boards use SD3 */
        [AZX_DRIVER_SCH] = 3,
        [AZX_DRIVER_ATI] = 4,
        [AZX_DRIVER_ATIHDMI] = 4,
@@ -1093,6 +1164,7 @@ static unsigned int azx_max_codecs[] __devinitdata = {
        [AZX_DRIVER_SIS] = 3,           /* FIXME: correct? */
        [AZX_DRIVER_ULI] = 3,           /* FIXME: correct? */
        [AZX_DRIVER_NVIDIA] = 3,        /* FIXME: correct? */
+       [AZX_DRIVER_TERA] = 1,
 };
 
 static int __devinit azx_codec_create(struct azx *chip, const char *model,
@@ -1316,7 +1388,7 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
 
        snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
                    azx_dev->bufsize, azx_dev->format_val);
-       if (azx_setup_periods(substream, azx_dev) < 0)
+       if (azx_setup_periods(chip, substream, azx_dev) < 0)
                return -EINVAL;
        azx_setup_controller(chip, azx_dev);
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1421,35 +1493,113 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        return 0;
 }
 
-static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
+static unsigned int azx_get_position(struct azx *chip,
+                                    struct azx_dev *azx_dev)
 {
-       struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
-       struct azx *chip = apcm->chip;
-       struct azx_dev *azx_dev = get_azx_dev(substream);
        unsigned int pos;
 
        if (chip->position_fix == POS_FIX_POSBUF ||
            chip->position_fix == POS_FIX_AUTO) {
                /* use the position buffer */
                pos = le32_to_cpu(*azx_dev->posbuf);
-               if (chip->position_fix == POS_FIX_AUTO &&
-                   azx_dev->period_intr == 1 && !pos) {
-                       printk(KERN_WARNING
-                              "hda-intel: Invalid position buffer, "
-                              "using LPIB read method instead.\n");
-                       chip->position_fix = POS_FIX_NONE;
-                       goto read_lpib;
-               }
        } else {
-       read_lpib:
                /* read LPIB */
                pos = azx_sd_readl(azx_dev, SD_LPIB);
-               if (chip->position_fix == POS_FIX_FIFO)
-                       pos += azx_dev->fifo_size;
        }
        if (pos >= azx_dev->bufsize)
                pos = 0;
-       return bytes_to_frames(substream->runtime, pos);
+       return pos;
+}
+
+static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
+       struct azx *chip = apcm->chip;
+       struct azx_dev *azx_dev = get_azx_dev(substream);
+       return bytes_to_frames(substream->runtime,
+                              azx_get_position(chip, azx_dev));
+}
+
+/*
+ * Check whether the current DMA position is acceptable for updating
+ * periods.  Returns non-zero if it's OK.
+ *
+ * Many HD-audio controllers appear pretty inaccurate about
+ * the update-IRQ timing.  The IRQ is issued before actually the
+ * data is processed.  So, we need to process it afterwords in a
+ * workqueue.
+ */
+static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
+{
+       unsigned int pos;
+
+       pos = azx_get_position(chip, azx_dev);
+       if (chip->position_fix == POS_FIX_AUTO) {
+               if (!pos) {
+                       printk(KERN_WARNING
+                              "hda-intel: Invalid position buffer, "
+                              "using LPIB read method instead.\n");
+                       chip->position_fix = POS_FIX_LPIB;
+                       pos = azx_get_position(chip, azx_dev);
+               } else
+                       chip->position_fix = POS_FIX_POSBUF;
+       }
+
+       if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
+               return 0; /* NG - it's below the period boundary */
+       return 1; /* OK, it's fine */
+}
+
+/*
+ * The work for pending PCM period updates.
+ */
+static void azx_irq_pending_work(struct work_struct *work)
+{
+       struct azx *chip = container_of(work, struct azx, irq_pending_work);
+       int i, pending;
+
+       if (!chip->irq_pending_warned) {
+               printk(KERN_WARNING
+                      "hda-intel: IRQ timing workaround is activated "
+                      "for card #%d. Suggest a bigger bdl_pos_adj.\n",
+                      chip->card->number);
+               chip->irq_pending_warned = 1;
+       }
+
+       for (;;) {
+               pending = 0;
+               spin_lock_irq(&chip->reg_lock);
+               for (i = 0; i < chip->num_streams; i++) {
+                       struct azx_dev *azx_dev = &chip->azx_dev[i];
+                       if (!azx_dev->irq_pending ||
+                           !azx_dev->substream ||
+                           !azx_dev->running)
+                               continue;
+                       if (azx_position_ok(chip, azx_dev)) {
+                               azx_dev->irq_pending = 0;
+                               spin_unlock(&chip->reg_lock);
+                               snd_pcm_period_elapsed(azx_dev->substream);
+                               spin_lock(&chip->reg_lock);
+                       } else
+                               pending++;
+               }
+               spin_unlock_irq(&chip->reg_lock);
+               if (!pending)
+                       return;
+               cond_resched();
+       }
+}
+
+/* clear irq_pending flags and assure no on-going workq */
+static void azx_clear_irq_pending(struct azx *chip)
+{
+       int i;
+
+       spin_lock_irq(&chip->reg_lock);
+       for (i = 0; i < chip->num_streams; i++)
+               chip->azx_dev[i].irq_pending = 0;
+       spin_unlock_irq(&chip->reg_lock);
+       flush_scheduled_work();
 }
 
 static struct snd_pcm_ops azx_pcm_ops = {
@@ -1676,6 +1826,7 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
        int i;
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       azx_clear_irq_pending(chip);
        for (i = 0; i < AZX_MAX_PCMS; i++)
                snd_pcm_suspend_all(chip->pcm[i]);
        if (chip->initialized)
@@ -1732,6 +1883,7 @@ static int azx_free(struct azx *chip)
        int i;
 
        if (chip->initialized) {
+               azx_clear_irq_pending(chip);
                for (i = 0; i < chip->num_streams; i++)
                        azx_stream_stop(chip, &chip->azx_dev[i]);
                azx_stop_chip(chip);
@@ -1770,9 +1922,9 @@ static int azx_dev_free(struct snd_device *device)
  * white/black-listing for position_fix
  */
 static struct snd_pci_quirk position_fix_list[] __devinitdata = {
-       SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE),
-       SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE),
-       SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_NONE),
+       SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
+       SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
+       SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
        {}
 };
 
@@ -1857,12 +2009,25 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
        chip->irq = -1;
        chip->driver_type = driver_type;
        chip->msi = enable_msi;
+       chip->dev_index = dev;
+       INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
 
        chip->position_fix = check_position_fix(chip, position_fix[dev]);
        check_probe_mask(chip, dev);
 
        chip->single_cmd = single_cmd;
 
+       if (bdl_pos_adj[dev] < 0) {
+               switch (chip->driver_type) {
+               case AZX_DRIVER_ICH:
+                       bdl_pos_adj[dev] = 1;
+                       break;
+               default:
+                       bdl_pos_adj[dev] = 32;
+                       break;
+               }
+       }
+
 #if BITS_PER_LONG != 64
        /* Fix up base address on ULI M5461 */
        if (chip->driver_type == AZX_DRIVER_ULI) {
@@ -2089,6 +2254,7 @@ static struct pci_device_id azx_ids[] = {
        { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
        { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
        { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
+       { PCI_DEVICE(0x8086, 0x2911), .driver_data = AZX_DRIVER_ICH },
        { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
        { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
        { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
@@ -2141,6 +2307,8 @@ static struct pci_device_id azx_ids[] = {
        { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
        { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
        { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
+       /* Teradici */
+       { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
        { 0, }
 };
 MODULE_DEVICE_TABLE(pci, azx_ids);
index 5633f77..1e5aff5 100644 (file)
@@ -366,8 +366,6 @@ static void print_digital_conv(struct snd_info_buffer *buffer,
 {
        unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
                                                AC_VERB_GET_DIGI_CONVERT_1, 0);
-       unsigned int digi2 = snd_hda_codec_read(codec, nid, 0,
-                                               AC_VERB_GET_DIGI_CONVERT_2, 0);
        snd_iprintf(buffer, "  Digital:");
        if (digi1 & AC_DIG1_ENABLE)
                snd_iprintf(buffer, " Enabled");
@@ -386,7 +384,8 @@ static void print_digital_conv(struct snd_info_buffer *buffer,
        if (digi1 & AC_DIG1_LEVEL)
                snd_iprintf(buffer, " GenLevel");
        snd_iprintf(buffer, "\n");
-       snd_iprintf(buffer, "  Digital category: 0x%x\n", digi2 & AC_DIG2_CC);
+       snd_iprintf(buffer, "  Digital category: 0x%x\n",
+                   (digi1 >> 8) & AC_DIG2_CC);
 }
 
 static const char *get_pwr_state(u32 state)
index a99e86d..e8003d9 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
-#include <linux/mutex.h>
 
 #include <sound/core.h>
 #include "hda_codec.h"
@@ -64,7 +63,6 @@ struct ad198x_spec {
        /* PCM information */
        struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
 
-       struct mutex amp_mutex; /* PCM volume/mute control mutex */
        unsigned int spdif_route;
 
        /* dynamic controls, init_verbs and input_mux */
@@ -1618,6 +1616,7 @@ static const char *ad1981_models[AD1981_MODELS] = {
 
 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
+       SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
        /* All HP models */
        SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
        SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
@@ -2623,7 +2622,7 @@ static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
 {
        struct ad198x_spec *spec = codec->spec;
        hda_nid_t nid;
-       int idx, err;
+       int i, idx, err;
        char name[32];
 
        if (! pin)
@@ -2631,16 +2630,26 @@ static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
 
        idx = ad1988_pin_idx(pin);
        nid = ad1988_idx_to_dac(codec, idx);
-       /* specify the DAC as the extra output */
-       if (! spec->multiout.hp_nid)
-               spec->multiout.hp_nid = nid;
-       else
-               spec->multiout.extra_out_nid[0] = nid;
-       /* control HP volume/switch on the output mixer amp */
-       sprintf(name, "%s Playback Volume", pfx);
-       if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
-                              HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
-               return err;
+       /* check whether the corresponding DAC was already taken */
+       for (i = 0; i < spec->autocfg.line_outs; i++) {
+               hda_nid_t pin = spec->autocfg.line_out_pins[i];
+               hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
+               if (dac == nid)
+                       break;
+       }
+       if (i >= spec->autocfg.line_outs) {
+               /* specify the DAC as the extra output */
+               if (!spec->multiout.hp_nid)
+                       spec->multiout.hp_nid = nid;
+               else
+                       spec->multiout.extra_out_nid[0] = nid;
+               /* control HP volume/switch on the output mixer amp */
+               sprintf(name, "%s Playback Volume", pfx);
+               err = add_control(spec, AD_CTL_WIDGET_VOL, name,
+                                 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
+               if (err < 0)
+                       return err;
+       }
        nid = ad1988_mixer_nids[idx];
        sprintf(name, "%s Playback Switch", pfx);
        if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
@@ -3177,7 +3186,6 @@ static int patch_ad1884(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -3847,7 +3855,6 @@ static int patch_ad1884a(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -4152,7 +4159,6 @@ static int patch_ad1882(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 6;
index 36fd852..7c1eb23 100644 (file)
@@ -82,7 +82,6 @@ struct conexant_spec {
        /* PCM information */
        struct hda_pcm pcm_rec[2];      /* used in build_pcms() */
 
-       struct mutex amp_mutex; /* PCM volume/mute control mutex */
        unsigned int spdif_route;
 
        /* dynamic controls, init_verbs and input_mux */
@@ -687,7 +686,7 @@ static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
 
 static struct hda_verb cxt5045_init_verbs[] = {
        /* Line in, Mic */
-       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
+       {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
        /* HP, Amp  */
        {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
@@ -907,10 +906,12 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
        SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
        SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
        SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
+       SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
        SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
        SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
        SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
-       SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP_HPSENSE),
+       SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
+                     CXT5045_LAPTOP_HPMICSENSE),
        SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
        SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
        SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
@@ -928,7 +929,6 @@ static int patch_cxt5045(struct hda_codec *codec)
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (!spec)
                return -ENOMEM;
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -963,6 +963,7 @@ static int patch_cxt5045(struct hda_codec *codec)
                codec->patch_ops.init = cxt5045_init;
                break;
        case CXT5045_LAPTOP_MICSENSE:
+               codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
                spec->input_mux = &cxt5045_capture_source;
                spec->num_init_verbs = 2;
                spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
@@ -1007,15 +1008,19 @@ static int patch_cxt5045(struct hda_codec *codec)
 #endif 
        }
 
-       /*
-        * Fix max PCM level to 0 dB
-        * (originall it has 0x2b steps with 0dB offset 0x14)
-        */
-       snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
-                                 (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
-                                 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
-                                 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
-                                 (1 << AC_AMPCAP_MUTE_SHIFT));
+       switch (codec->subsystem_id >> 16) {
+       case 0x103c:
+               /* HP laptop has a really bad sound over 0dB on NID 0x17.
+                * Fix max PCM level to 0 dB
+                * (originall it has 0x2b steps with 0dB offset 0x14)
+                */
+               snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
+                                         (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
+                                         (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
+                                         (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
+                                         (1 << AC_AMPCAP_MUTE_SHIFT));
+               break;
+       }
 
        return 0;
 }
@@ -1477,7 +1482,6 @@ static int patch_cxt5047(struct hda_codec *codec)
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (!spec)
                return -ENOMEM;
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -1736,7 +1740,6 @@ static int patch_cxt5051(struct hda_codec *codec)
        spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (!spec)
                return -ENOMEM;
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        codec->patch_ops = conexant_patch_ops;
index b0a2a26..2807bc8 100644 (file)
@@ -163,6 +163,10 @@ enum {
        ALC662_LENOVO_101E,
        ALC662_ASUS_EEEPC_P701,
        ALC662_ASUS_EEEPC_EP20,
+       ALC663_ASUS_M51VA,
+       ALC663_ASUS_G71V,
+       ALC663_ASUS_H13,
+       ALC663_ASUS_G50V,
        ALC662_AUTO,
        ALC662_MODEL_LAST,
 };
@@ -205,6 +209,7 @@ enum {
        ALC883_MITAC,
        ALC883_CLEVO_M720,
        ALC883_FUJITSU_PI2515,
+       ALC883_3ST_6ch_INTEL,
        ALC883_AUTO,
        ALC883_MODEL_LAST,
 };
@@ -280,6 +285,10 @@ struct alc_spec {
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        struct hda_loopback_check loopback;
 #endif
+
+       /* for PLL fix */
+       hda_nid_t pll_nid;
+       unsigned int pll_coef_idx, pll_coef_bit;
 };
 
 /*
@@ -747,6 +756,38 @@ static struct hda_verb alc_gpio3_init_verbs[] = {
        { }
 };
 
+/*
+ * Fix hardware PLL issue
+ * On some codecs, the analog PLL gating control must be off while
+ * the default value is 1.
+ */
+static void alc_fix_pll(struct hda_codec *codec)
+{
+       struct alc_spec *spec = codec->spec;
+       unsigned int val;
+
+       if (!spec->pll_nid)
+               return;
+       snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
+                           spec->pll_coef_idx);
+       val = snd_hda_codec_read(codec, spec->pll_nid, 0,
+                                AC_VERB_GET_PROC_COEF, 0);
+       snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
+                           spec->pll_coef_idx);
+       snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
+                           val & ~(1 << spec->pll_coef_bit));
+}
+
+static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
+                            unsigned int coef_idx, unsigned int coef_bit)
+{
+       struct alc_spec *spec = codec->spec;
+       spec->pll_nid = nid;
+       spec->pll_coef_idx = coef_idx;
+       spec->pll_coef_bit = coef_bit;
+       alc_fix_pll(codec);
+}
+
 static void alc_sku_automute(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
@@ -776,6 +817,24 @@ static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
        alc_sku_automute(codec);
 }
 
+/* additional initialization for ALC888 variants */
+static void alc888_coef_init(struct hda_codec *codec)
+{
+       unsigned int tmp;
+
+       snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
+       tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
+       snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
+       if ((tmp & 0xf0) == 2)
+               /* alc888S-VC */
+               snd_hda_codec_read(codec, 0x20, 0,
+                                  AC_VERB_SET_PROC_COEF, 0x830);
+        else
+                /* alc888-VB */
+                snd_hda_codec_read(codec, 0x20, 0,
+                                   AC_VERB_SET_PROC_COEF, 0x3030);
+}
+
 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
  *     31 ~ 16 :       Manufacture ID
  *     15 ~ 8  :       SKU ID
@@ -851,8 +910,10 @@ do_sku:
                case 0x10ec0267:
                case 0x10ec0268:
                case 0x10ec0269:
+               case 0x10ec0660:
+               case 0x10ec0662:
+               case 0x10ec0663:
                case 0x10ec0862:
-               case 0x10ec0662:        
                case 0x10ec0889:
                        snd_hda_codec_write(codec, 0x14, 0,
                                            AC_VERB_SET_EAPD_BTLENABLE, 2);
@@ -877,7 +938,6 @@ do_sku:
                case 0x10ec0882:
                case 0x10ec0883:
                case 0x10ec0885:
-               case 0x10ec0888:
                case 0x10ec0889:
                        snd_hda_codec_write(codec, 0x20, 0,
                                            AC_VERB_SET_COEF_INDEX, 7);
@@ -889,6 +949,9 @@ do_sku:
                                            AC_VERB_SET_PROC_COEF,
                                            tmp | 0x2010);
                        break;
+               case 0x10ec0888:
+                       alc888_coef_init(codec);
+                       break;
                case 0x10ec0267:
                case 0x10ec0268:
                        snd_hda_codec_write(codec, 0x20, 0,
@@ -2373,6 +2436,8 @@ static int alc_init(struct hda_codec *codec)
        struct alc_spec *spec = codec->spec;
        unsigned int i;
 
+       alc_fix_pll(codec);
+
        for (i = 0; i < spec->num_init_verbs; i++)
                snd_hda_sequence_write(codec, spec->init_verbs[i]);
 
@@ -3009,6 +3074,7 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
        SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
        SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
+       SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
        SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
        SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
        SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
@@ -5101,7 +5167,7 @@ static struct snd_pci_quirk alc260_cfg_tbl[] = {
        SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
        SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
        SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
-       SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
+       SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
        SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
        SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
        SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
@@ -6127,6 +6193,7 @@ static struct snd_pci_quirk alc882_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
        SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
        SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
+       SND_PCI_QUIRK(0x106b, 0x00a0, "Apple iMac 24''", ALC885_IMAC24),
        SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
        SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
        SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
@@ -6353,7 +6420,9 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
                        continue;
                vref = PIN_IN;
                if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
-                       if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
+                       unsigned int pincap;
+                       pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
+                       if ((pincap >> AC_PINCAP_VREF_SHIFT) &
                            AC_PINCAP_VREF_80)
                                vref = PIN_VREF80;
                }
@@ -6450,8 +6519,9 @@ static int patch_alc882(struct hda_codec *codec)
                case 0x106b1000: /* iMac 24 */
                        board_config = ALC885_IMAC24;
                        break;
-               case 0x106b00a1: /* Macbook */
+               case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
                case 0x106b2c00: /* Macbook Pro rev3 */
+               case 0x106b3600: /* Macbook 3.1 */
                        board_config = ALC885_MBP3;
                        break;
                default:
@@ -6485,14 +6555,20 @@ static int patch_alc882(struct hda_codec *codec)
        if (board_config != ALC882_AUTO)
                setup_preset(spec, &alc882_presets[board_config]);
 
-       spec->stream_name_analog = "ALC882 Analog";
+       if (codec->vendor_id == 0x10ec0885) {
+               spec->stream_name_analog = "ALC885 Analog";
+               spec->stream_name_digital = "ALC885 Digital";
+       } else {
+               spec->stream_name_analog = "ALC882 Analog";
+               spec->stream_name_digital = "ALC882 Digital";
+       }
+
        spec->stream_analog_playback = &alc882_pcm_analog_playback;
        spec->stream_analog_capture = &alc882_pcm_analog_capture;
        /* FIXME: setup DAC5 */
        /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
        spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
 
-       spec->stream_name_digital = "ALC882 Digital";
        spec->stream_digital_playback = &alc882_pcm_digital_playback;
        spec->stream_digital_capture = &alc882_pcm_digital_capture;
 
@@ -6569,6 +6645,16 @@ static struct hda_input_mux alc883_capture_source = {
        },
 };
 
+static struct hda_input_mux alc883_3stack_6ch_intel = {
+       .num_items = 4,
+       .items = {
+               { "Mic", 0x1 },
+               { "Front Mic", 0x0 },
+               { "Line", 0x2 },
+               { "CD", 0x4 },
+       },
+};
+
 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
        .num_items = 2,
        .items = {
@@ -6649,6 +6735,48 @@ static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
        { 6, alc883_3ST_ch6_init },
 };
 
+/*
+ * 2ch mode
+ */
+static struct hda_verb alc883_3ST_ch2_intel_init[] = {
+       { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
+       { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
+       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
+       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
+       { } /* end */
+};
+
+/*
+ * 4ch mode
+ */
+static struct hda_verb alc883_3ST_ch4_intel_init[] = {
+       { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
+       { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
+       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
+       { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
+       { } /* end */
+};
+
+/*
+ * 6ch mode
+ */
+static struct hda_verb alc883_3ST_ch6_intel_init[] = {
+       { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
+       { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
+       { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
+       { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
+       { } /* end */
+};
+
+static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
+       { 2, alc883_3ST_ch2_intel_init },
+       { 4, alc883_3ST_ch4_intel_init },
+       { 6, alc883_3ST_ch6_intel_init },
+};
+
 /*
  * 6ch mode
  */
@@ -6881,15 +7009,54 @@ static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
        { } /* end */
 };
 
+static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
+       HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
+       HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
+       HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
+                             HDA_OUTPUT),
+       HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
+       HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
+       HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
+       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
+       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
+       HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
+       HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
+       HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               /* .name = "Capture Source", */
+               .name = "Input Source",
+               .count = 2,
+               .info = alc883_mux_enum_info,
+               .get = alc883_mux_enum_get,
+               .put = alc883_mux_enum_put,
+       },
+       { } /* end */
+};
+
 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
+       HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
+       HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
        HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -7729,6 +7896,7 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
        [ALC883_MITAC]          = "mitac",
        [ALC883_CLEVO_M720]     = "clevo-m720",
        [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
+       [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
        [ALC883_AUTO]           = "auto",
 };
 
@@ -7786,6 +7954,8 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
        SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
        SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
        SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
+       SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
+       SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
        SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
        {}
 };
@@ -7824,6 +7994,18 @@ static struct alc_config_preset alc883_presets[] = {
                .need_dac_fix = 1,
                .input_mux = &alc883_capture_source,
        },
+       [ALC883_3ST_6ch_INTEL] = {
+               .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
+               .init_verbs = { alc883_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc883_dac_nids),
+               .dac_nids = alc883_dac_nids,
+               .dig_out_nid = ALC883_DIGOUT_NID,
+               .dig_in_nid = ALC883_DIGIN_NID,
+               .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
+               .channel_mode = alc883_3ST_6ch_intel_modes,
+               .need_dac_fix = 1,
+               .input_mux = &alc883_3stack_6ch_intel,
+       },
        [ALC883_6ST_DIG] = {
                .mixers = { alc883_base_mixer, alc883_chmode_mixer },
                .init_verbs = { alc883_init_verbs },
@@ -8145,6 +8327,8 @@ static int patch_alc883(struct hda_codec *codec)
 
        codec->spec = spec;
 
+       alc_fix_pll_init(codec, 0x20, 0x0a, 10);
+
        board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
                                                  alc883_models,
                                                  alc883_cfg_tbl);
@@ -8171,12 +8355,25 @@ static int patch_alc883(struct hda_codec *codec)
        if (board_config != ALC883_AUTO)
                setup_preset(spec, &alc883_presets[board_config]);
 
-       spec->stream_name_analog = "ALC883 Analog";
+       switch (codec->vendor_id) {
+       case 0x10ec0888:
+               spec->stream_name_analog = "ALC888 Analog";
+               spec->stream_name_digital = "ALC888 Digital";
+               break;
+       case 0x10ec0889:
+               spec->stream_name_analog = "ALC889 Analog";
+               spec->stream_name_digital = "ALC889 Digital";
+               break;
+       default:
+               spec->stream_name_analog = "ALC883 Analog";
+               spec->stream_name_digital = "ALC883 Digital";
+               break;
+       }
+
        spec->stream_analog_playback = &alc883_pcm_analog_playback;
        spec->stream_analog_capture = &alc883_pcm_analog_capture;
        spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
 
-       spec->stream_name_digital = "ALC883 Digital";
        spec->stream_digital_playback = &alc883_pcm_digital_playback;
        spec->stream_digital_capture = &alc883_pcm_digital_capture;
 
@@ -8189,6 +8386,9 @@ static int patch_alc883(struct hda_codec *codec)
        codec->patch_ops = alc_patch_ops;
        if (board_config == ALC883_AUTO)
                spec->init_hook = alc883_auto_init;
+       else if (codec->vendor_id == 0x10ec0888)
+               spec->init_hook = alc888_coef_init;
+
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        if (!spec->loopback.amplist)
                spec->loopback.amplist = alc883_loopbacks;
@@ -9522,6 +9722,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
        SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
        SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
        SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
+       SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
+                     ALC262_SONY_ASSAMD),
        SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
        SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
        SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
@@ -9729,6 +9931,8 @@ static int patch_alc262(struct hda_codec *codec)
        }
 #endif
 
+       alc_fix_pll_init(codec, 0x20, 0x0a, 10);
+
        board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
                                                  alc262_models,
                                                  alc262_cfg_tbl);
@@ -10674,12 +10878,18 @@ static int patch_alc268(struct hda_codec *codec)
        if (board_config != ALC268_AUTO)
                setup_preset(spec, &alc268_presets[board_config]);
 
-       spec->stream_name_analog = "ALC268 Analog";
+       if (codec->vendor_id == 0x10ec0267) {
+               spec->stream_name_analog = "ALC267 Analog";
+               spec->stream_name_digital = "ALC267 Digital";
+       } else {
+               spec->stream_name_analog = "ALC268 Analog";
+               spec->stream_name_digital = "ALC268 Digital";
+       }
+
        spec->stream_analog_playback = &alc268_pcm_analog_playback;
        spec->stream_analog_capture = &alc268_pcm_analog_capture;
        spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
 
-       spec->stream_name_digital = "ALC268 Digital";
        spec->stream_digital_playback = &alc268_pcm_digital_playback;
 
        if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
@@ -11033,6 +11243,8 @@ static int patch_alc269(struct hda_codec *codec)
 
        codec->spec = spec;
 
+       alc_fix_pll_init(codec, 0x20, 0x04, 15);
+
        board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
                                                  alc269_models,
                                                  alc269_cfg_tbl);
@@ -12631,6 +12843,12 @@ static struct hda_verb alc861vd_eapd_verbs[] = {
        { }
 };
 
+static struct hda_verb alc660vd_eapd_verbs[] = {
+       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
+       {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
+       { }
+};
+
 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -12786,6 +13004,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
        SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
        SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
+       SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
        SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
        {}
 };
@@ -13168,11 +13387,19 @@ static int patch_alc861vd(struct hda_codec *codec)
        if (board_config != ALC861VD_AUTO)
                setup_preset(spec, &alc861vd_presets[board_config]);
 
-       spec->stream_name_analog = "ALC861VD Analog";
+       if (codec->vendor_id == 0x10ec0660) {
+               spec->stream_name_analog = "ALC660-VD Analog";
+               spec->stream_name_digital = "ALC660-VD Digital";
+               /* always turn on EAPD */
+               spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
+       } else {
+               spec->stream_name_analog = "ALC861VD Analog";
+               spec->stream_name_digital = "ALC861VD Digital";
+       }
+
        spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
        spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
 
-       spec->stream_name_digital = "ALC861VD Digital";
        spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
        spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
 
@@ -13251,6 +13478,23 @@ static struct hda_input_mux alc662_eeepc_capture_source = {
        },
 };
 
+static struct hda_input_mux alc663_capture_source = {
+       .num_items = 3,
+       .items = {
+               { "Mic", 0x0 },
+               { "Front Mic", 0x1 },
+               { "Line", 0x2 },
+       },
+};
+
+static struct hda_input_mux alc663_m51va_capture_source = {
+       .num_items = 2,
+       .items = {
+               { "Ext-Mic", 0x0 },
+               { "D-Mic", 0x9 },
+       },
+};
+
 #define alc662_mux_enum_info alc_mux_enum_info
 #define alc662_mux_enum_get alc_mux_enum_get
 #define alc662_mux_enum_put alc882_mux_enum_put
@@ -13431,6 +13675,44 @@ static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
        { } /* end */
 };
 
+static struct snd_kcontrol_new alc663_m51va_mixer[] = {
+       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
+       { } /* end */
+};
+
+static struct snd_kcontrol_new alc663_g71v_mixer[] = {
+       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
+
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
+       { } /* end */
+};
+
+static struct snd_kcontrol_new alc663_g50v_mixer[] = {
+       HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
+
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
+       HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
+       HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
+       HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
+       { } /* end */
+};
+
 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -13501,6 +13783,11 @@ static struct hda_verb alc662_init_verbs[] = {
        {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
        {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
        {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
+
+       /* always trun on EAPD */
+       {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
+       {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
+
        { }
 };
 
@@ -13571,6 +13858,43 @@ static struct hda_verb alc662_auto_init_verbs[] = {
        { }
 };
 
+static struct hda_verb alc663_m51va_init_verbs[] = {
+       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
+       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
+       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
+
+       {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
+
+       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
+       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
+       {}
+};
+
+static struct hda_verb alc663_g71v_init_verbs[] = {
+       {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
+       /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
+       /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
+
+       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
+       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
+       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
+
+       {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
+       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
+       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
+       {}
+};
+
+static struct hda_verb alc663_g50v_init_verbs[] = {
+       {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
+       {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
+       {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
+
+       {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
+       {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
+       {}
+};
+
 /* capture mixer elements */
 static struct snd_kcontrol_new alc662_capture_mixer[] = {
        HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
@@ -13692,6 +14016,125 @@ static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
        alc662_eeepc_ep20_automute(codec);
 }
 
+static void alc663_m51va_speaker_automute(struct hda_codec *codec)
+{
+       unsigned int present;
+       unsigned char bits;
+
+       present = snd_hda_codec_read(codec, 0x21, 0,
+                                    AC_VERB_GET_PIN_SENSE, 0)
+               & AC_PINSENSE_PRESENCE;
+       bits = present ? HDA_AMP_MUTE : 0;
+       snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, bits);
+}
+
+static void alc663_m51va_mic_automute(struct hda_codec *codec)
+{
+       unsigned int present;
+
+       present = snd_hda_codec_read(codec, 0x18, 0,
+                                    AC_VERB_GET_PIN_SENSE, 0)
+               & AC_PINSENSE_PRESENCE;
+       snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
+                           0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
+       snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
+                           0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
+       snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
+                           0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
+       snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
+                           0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
+}
+
+static void alc663_m51va_unsol_event(struct hda_codec *codec,
+                                          unsigned int res)
+{
+       switch (res >> 26) {
+       case ALC880_HP_EVENT:
+               alc663_m51va_speaker_automute(codec);
+               break;
+       case ALC880_MIC_EVENT:
+               alc663_m51va_mic_automute(codec);
+               break;
+       }
+}
+
+static void alc663_m51va_inithook(struct hda_codec *codec)
+{
+       alc663_m51va_speaker_automute(codec);
+       alc663_m51va_mic_automute(codec);
+}
+
+static void alc663_g71v_hp_automute(struct hda_codec *codec)
+{
+       unsigned int present;
+       unsigned char bits;
+
+       present = snd_hda_codec_read(codec, 0x21, 0,
+                                    AC_VERB_GET_PIN_SENSE, 0)
+               & AC_PINSENSE_PRESENCE;
+       bits = present ? HDA_AMP_MUTE : 0;
+       snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, bits);
+       snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, bits);
+}
+
+static void alc663_g71v_front_automute(struct hda_codec *codec)
+{
+       unsigned int present;
+       unsigned char bits;
+
+       present = snd_hda_codec_read(codec, 0x15, 0,
+                                    AC_VERB_GET_PIN_SENSE, 0)
+               & AC_PINSENSE_PRESENCE;
+       bits = present ? HDA_AMP_MUTE : 0;
+       snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, bits);
+}
+
+static void alc663_g71v_unsol_event(struct hda_codec *codec,
+                                          unsigned int res)
+{
+       switch (res >> 26) {
+       case ALC880_HP_EVENT:
+               alc663_g71v_hp_automute(codec);
+               break;
+       case ALC880_FRONT_EVENT:
+               alc663_g71v_front_automute(codec);
+               break;
+       case ALC880_MIC_EVENT:
+               alc662_eeepc_mic_automute(codec);
+               break;
+       }
+}
+
+static void alc663_g71v_inithook(struct hda_codec *codec)
+{
+       alc663_g71v_front_automute(codec);
+       alc663_g71v_hp_automute(codec);
+       alc662_eeepc_mic_automute(codec);
+}
+
+static void alc663_g50v_unsol_event(struct hda_codec *codec,
+                                          unsigned int res)
+{
+       switch (res >> 26) {
+       case ALC880_HP_EVENT:
+               alc663_m51va_speaker_automute(codec);
+               break;
+       case ALC880_MIC_EVENT:
+               alc662_eeepc_mic_automute(codec);
+               break;
+       }
+}
+
+static void alc663_g50v_inithook(struct hda_codec *codec)
+{
+       alc663_m51va_speaker_automute(codec);
+       alc662_eeepc_mic_automute(codec);
+}
+
 #ifdef CONFIG_SND_HDA_POWER_SAVE
 #define alc662_loopbacks       alc880_loopbacks
 #endif
@@ -13714,14 +14157,24 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
        [ALC662_LENOVO_101E]    = "lenovo-101e",
        [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
        [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
+       [ALC663_ASUS_M51VA] = "m51va",
+       [ALC663_ASUS_G71V] = "g71v",
+       [ALC663_ASUS_H13] = "h13",
+       [ALC663_ASUS_G50V] = "g50v",
        [ALC662_AUTO]           = "auto",
 };
 
 static struct snd_pci_quirk alc662_cfg_tbl[] = {
+       SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
+       SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
+       SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
        SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
        SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
        SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
        SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
+       SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
+       SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
+       SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
        {}
 };
 
@@ -13809,7 +14262,53 @@ static struct alc_config_preset alc662_presets[] = {
                .unsol_event = alc662_eeepc_ep20_unsol_event,
                .init_hook = alc662_eeepc_ep20_inithook,
        },
-
+       [ALC663_ASUS_M51VA] = {
+               .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
+               .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
+               .dac_nids = alc662_dac_nids,
+               .dig_out_nid = ALC662_DIGOUT_NID,
+               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
+               .channel_mode = alc662_3ST_2ch_modes,
+               .input_mux = &alc663_m51va_capture_source,
+               .unsol_event = alc663_m51va_unsol_event,
+               .init_hook = alc663_m51va_inithook,
+       },
+       [ALC663_ASUS_G71V] = {
+               .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
+               .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
+               .dac_nids = alc662_dac_nids,
+               .dig_out_nid = ALC662_DIGOUT_NID,
+               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
+               .channel_mode = alc662_3ST_2ch_modes,
+               .input_mux = &alc662_eeepc_capture_source,
+               .unsol_event = alc663_g71v_unsol_event,
+               .init_hook = alc663_g71v_inithook,
+       },
+       [ALC663_ASUS_H13] = {
+               .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
+               .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
+               .dac_nids = alc662_dac_nids,
+               .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
+               .channel_mode = alc662_3ST_2ch_modes,
+               .input_mux = &alc663_m51va_capture_source,
+               .unsol_event = alc663_m51va_unsol_event,
+               .init_hook = alc663_m51va_inithook,
+       },
+       [ALC663_ASUS_G50V] = {
+               .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
+               .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
+               .num_dacs = ARRAY_SIZE(alc662_dac_nids),
+               .dac_nids = alc662_dac_nids,
+               .dig_out_nid = ALC662_DIGOUT_NID,
+               .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
+               .channel_mode = alc662_3ST_6ch_modes,
+               .input_mux = &alc663_capture_source,
+               .unsol_event = alc663_g50v_unsol_event,
+               .init_hook = alc663_g50v_inithook,
+       },
 };
 
 
@@ -14082,6 +14581,8 @@ static int patch_alc662(struct hda_codec *codec)
 
        codec->spec = spec;
 
+       alc_fix_pll_init(codec, 0x20, 0x04, 15);
+
        board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
                                                  alc662_models,
                                                  alc662_cfg_tbl);
@@ -14108,11 +14609,17 @@ static int patch_alc662(struct hda_codec *codec)
        if (board_config != ALC662_AUTO)
                setup_preset(spec, &alc662_presets[board_config]);
 
-       spec->stream_name_analog = "ALC662 Analog";
+       if (codec->vendor_id == 0x10ec0663) {
+               spec->stream_name_analog = "ALC663 Analog";
+               spec->stream_name_digital = "ALC663 Digital";
+       } else {
+               spec->stream_name_analog = "ALC662 Analog";
+               spec->stream_name_digital = "ALC662 Digital";
+       }
+
        spec->stream_analog_playback = &alc662_pcm_analog_playback;
        spec->stream_analog_capture = &alc662_pcm_analog_capture;
 
-       spec->stream_name_digital = "ALC662 Digital";
        spec->stream_digital_playback = &alc662_pcm_digital_playback;
        spec->stream_digital_capture = &alc662_pcm_digital_capture;
 
@@ -14151,6 +14658,7 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
          .patch = patch_alc883 },
        { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
          .patch = patch_alc662 },
+       { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
        { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
        { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
        { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
index a4f44a0..08cb77f 100644 (file)
@@ -636,21 +636,28 @@ static struct hda_verb stac92hd71bxx_core_init[] = {
        { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
 };
 
+#define HD_DISABLE_PORTF 3
 static struct hda_verb stac92hd71bxx_analog_core_init[] = {
+       /* start of config #1 */
+
+       /* connect port 0f to audio mixer */
+       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
+       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
+       /* unmute right and left channels for node 0x0f */
+       { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
+       /* start of config #2 */
+
        /* set master volume and direct control */
        { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
        /* connect headphone jack to dac1 */
        { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
-       /* connect ports 0d and 0f to audio mixer */
+       /* connect port 0d to audio mixer */
        { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
-       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
-       { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
        /* unmute dac0 input in audio mixer */
        { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
-       /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
+       /* unmute right and left channels for nodes 0x0a, 0xd */
        { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
        {}
 };
 
@@ -818,6 +825,9 @@ static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
        HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
 
+       HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
+       HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
+
        HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
        HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
        { } /* end */
@@ -1317,13 +1327,13 @@ static unsigned int ref92hd71bxx_pin_configs[10] = {
        0x90a000f0, 0x01452050,
 };
 
-static unsigned int dell_m4_1_pin_configs[13] = {
+static unsigned int dell_m4_1_pin_configs[10] = {
        0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
        0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
        0x40f000f0, 0x4f0000f0,
 };
 
-static unsigned int dell_m4_2_pin_configs[13] = {
+static unsigned int dell_m4_2_pin_configs[10] = {
        0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
        0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
        0x40f000f0, 0x044413b0,
@@ -1754,12 +1764,8 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
                      "unknown Dell", STAC_9205_DELL_M42),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
                      "Dell Precision", STAC_9205_DELL_M43),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
-                         "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
                      "Dell Precision", STAC_9205_DELL_M43),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
-                     "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
                      "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
@@ -1770,18 +1776,14 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
                      "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
                      "Dell Precision M4300", STAC_9205_DELL_M43),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
-                     "Dell Precision", STAC_9205_DELL_M43),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
-                     "Dell Inspiron", STAC_9205_DELL_M44),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
-                     "Dell Inspiron", STAC_9205_DELL_M44),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
-                     "Dell Inspiron", STAC_9205_DELL_M44),
-       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
-                     "Dell Inspiron", STAC_9205_DELL_M44),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
                      "unknown Dell", STAC_9205_DELL_M42),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
+                     "Dell Precision", STAC_9205_DELL_M43),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
+                     "Dell Precision", STAC_9205_DELL_M43),
+       SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
+                     "Dell Precision", STAC_9205_DELL_M43),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
                      "Dell Inspiron", STAC_9205_DELL_M44),
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
@@ -3103,13 +3105,16 @@ static int stac92xx_init(struct hda_codec *codec)
                                        0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
                int def_conf = snd_hda_codec_read(codec, spec->pwr_nids[i],
                                        0, AC_VERB_GET_CONFIG_DEFAULT, 0);
+               def_conf = get_defcfg_connect(def_conf);
                /* outputs are only ports capable of power management
                 * any attempts on powering down a input port cause the
                 * referenced VREF to act quirky.
                 */
                if (pinctl & AC_PINCTL_IN_EN)
                        continue;
-               if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED)
+               /* skip any ports that don't have jacks since presence
+                * detection is useless */
+               if (def_conf && def_conf != AC_JACK_PORT_FIXED)
                        continue;
                enable_pin_detect(codec, spec->pwr_nids[i], event | i);
                codec->patch_ops.unsol_event(codec, (event | i) << 26);
@@ -3614,6 +3619,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
 
        codec->spec = spec;
        spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
+       spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
        spec->pin_nids = stac92hd71bxx_pin_nids;
        spec->board_config = snd_hda_check_board_config(codec,
                                                        STAC_92HD71BXX_MODELS,
@@ -3642,6 +3648,19 @@ again:
                spec->mixer = stac92hd71bxx_mixer;
                spec->init = stac92hd71bxx_core_init;
                break;
+       case 0x111d7608: /* 5 Port with Analog Mixer */
+               /* no output amps */
+               spec->num_pwrs = 0;
+               spec->mixer = stac92hd71bxx_analog_mixer;
+
+               /* disable VSW */
+               spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
+               stac92xx_set_config_reg(codec, 0xf, 0x40f000f0);
+               break;
+       case 0x111d7603: /* 6 Port with Analog Mixer */
+               /* no output amps */
+               spec->num_pwrs = 0;
+               /* fallthru */
        default:
                spec->mixer = stac92hd71bxx_analog_mixer;
                spec->init = stac92hd71bxx_analog_core_init;
@@ -3653,22 +3672,19 @@ again:
        /* GPIO0 High = EAPD */
        spec->gpio_mask = 0x01;
        spec->gpio_dir = 0x01;
-       spec->gpio_mask = 0x01;
        spec->gpio_data = 0x01;
 
        spec->mux_nids = stac92hd71bxx_mux_nids;
        spec->adc_nids = stac92hd71bxx_adc_nids;
        spec->dmic_nids = stac92hd71bxx_dmic_nids;
        spec->dmux_nids = stac92hd71bxx_dmux_nids;
+       spec->pwr_nids = stac92hd71bxx_pwr_nids;
 
        spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
        spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
        spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
        spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
 
-       spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
-       spec->pwr_nids = stac92hd71bxx_pwr_nids;
-
        spec->multiout.num_dacs = 1;
        spec->multiout.hp_nid = 0x11;
        spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
@@ -4306,10 +4322,11 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
        { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
        { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
        { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
+       { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
+       { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
        { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
        { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
        { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
-       { .id = 0x111d7608, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
        { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
        { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
        { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
index 43b9e3e..a0c5e00 100644 (file)
@@ -93,9 +93,13 @@ enum {
 #define VT1724_REG_MPU_TXFIFO          0x0a    /*byte ro. number of bytes in TX fifo*/
 #define VT1724_REG_MPU_RXFIFO          0x0b    /*byte ro. number of bytes in RX fifo*/
 
-//are these 2 the wrong way around? they don't seem to be used yet anyway
-#define VT1724_REG_MPU_CTRL            0x0c    /* byte */
-#define VT1724_REG_MPU_DATA            0x0d    /* byte */
+#define VT1724_REG_MPU_DATA            0x0c    /* byte */
+#define VT1724_REG_MPU_CTRL            0x0d    /* byte */
+#define   VT1724_MPU_UART      0x01
+#define   VT1724_MPU_TX_EMPTY  0x02
+#define   VT1724_MPU_TX_FULL   0x04
+#define   VT1724_MPU_RX_EMPTY  0x08
+#define   VT1724_MPU_RX_FULL   0x10
 
 #define VT1724_REG_MPU_FIFO_WM 0x0e    /*byte set the high/low watermarks for RX/TX fifos*/
 #define   VT1724_MPU_RX_FIFO   0x20    //1=rx fifo watermark 0=tx fifo watermark
index 3208901..762fbd7 100644 (file)
@@ -333,6 +333,8 @@ struct snd_ice1712 {
        unsigned int has_spdif: 1;      /* VT1720/4 - has SPDIF I/O */
        unsigned int force_pdma4: 1;    /* VT1720/4 - PDMA4 as non-spdif */
        unsigned int force_rdma1: 1;    /* VT1720/4 - RDMA1 as non-spdif */
+       unsigned int midi_output: 1;    /* VT1720/4: MIDI output triggered */
+       unsigned int midi_input: 1;     /* VT1720/4: MIDI input triggered */
        unsigned int num_total_dacs;    /* total DACs */
        unsigned int num_total_adcs;    /* total ADCs */
        unsigned int cur_rate;          /* current rate */
index 6735090..e596d77 100644 (file)
@@ -32,7 +32,7 @@
 #include <linux/mutex.h>
 #include <sound/core.h>
 #include <sound/info.h>
-#include <sound/mpu401.h>
+#include <sound/rawmidi.h>
 #include <sound/initval.h>
 
 #include <sound/asoundef.h>
@@ -223,30 +223,153 @@ static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
 }
 
 /*
- * MPU401 accessor
+ * MIDI
  */
-static unsigned char snd_vt1724_mpu401_read(struct snd_mpu401 *mpu,
-                                           unsigned long addr)
+
+static void vt1724_midi_clear_rx(struct snd_ice1712 *ice)
+{
+       unsigned int count;
+
+       for (count = inb(ICEREG1724(ice, MPU_RXFIFO)); count > 0; --count)
+               inb(ICEREG1724(ice, MPU_DATA));
+}
+
+static inline struct snd_rawmidi_substream *
+get_rawmidi_substream(struct snd_ice1712 *ice, unsigned int stream)
 {
-       /* fix status bits to the standard position */
-       /* only RX_EMPTY and TX_FULL are checked */
-       if (addr == MPU401C(mpu))
-               return (inb(addr) & 0x0c) << 4;
+       return list_first_entry(&ice->rmidi[0]->streams[stream].substreams,
+                               struct snd_rawmidi_substream, list);
+}
+
+static void vt1724_midi_write(struct snd_ice1712 *ice)
+{
+       struct snd_rawmidi_substream *s;
+       int count, i;
+       u8 buffer[32];
+
+       s = get_rawmidi_substream(ice, SNDRV_RAWMIDI_STREAM_OUTPUT);
+       count = 31 - inb(ICEREG1724(ice, MPU_TXFIFO));
+       if (count > 0) {
+               count = snd_rawmidi_transmit(s, buffer, count);
+               for (i = 0; i < count; ++i)
+                       outb(buffer[i], ICEREG1724(ice, MPU_DATA));
+       }
+}
+
+static void vt1724_midi_read(struct snd_ice1712 *ice)
+{
+       struct snd_rawmidi_substream *s;
+       int count, i;
+       u8 buffer[32];
+
+       s = get_rawmidi_substream(ice, SNDRV_RAWMIDI_STREAM_INPUT);
+       count = inb(ICEREG1724(ice, MPU_RXFIFO));
+       if (count > 0) {
+               count = min(count, 32);
+               for (i = 0; i < count; ++i)
+                       buffer[i] = inb(ICEREG1724(ice, MPU_DATA));
+               snd_rawmidi_receive(s, buffer, count);
+       }
+}
+
+static void vt1724_enable_midi_irq(struct snd_rawmidi_substream *substream,
+                                  u8 flag, int enable)
+{
+       struct snd_ice1712 *ice = substream->rmidi->private_data;
+       u8 mask;
+
+       spin_lock_irq(&ice->reg_lock);
+       mask = inb(ICEREG1724(ice, IRQMASK));
+       if (enable)
+               mask &= ~flag;
        else
-               return inb(addr);
+               mask |= flag;
+       outb(mask, ICEREG1724(ice, IRQMASK));
+       spin_unlock_irq(&ice->reg_lock);
 }
 
-static void snd_vt1724_mpu401_write(struct snd_mpu401 *mpu,
-                                   unsigned char data, unsigned long addr)
+static int vt1724_midi_output_open(struct snd_rawmidi_substream *s)
 {
-       if (addr == MPU401C(mpu)) {
-               if (data == MPU401_ENTER_UART)
-                       outb(0x01, addr);
-               /* what else? */
-       } else
-               outb(data, addr);
+       vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 1);
+       return 0;
+}
+
+static int vt1724_midi_output_close(struct snd_rawmidi_substream *s)
+{
+       vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 0);
+       return 0;
 }
 
+static void vt1724_midi_output_trigger(struct snd_rawmidi_substream *s, int up)
+{
+       struct snd_ice1712 *ice = s->rmidi->private_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ice->reg_lock, flags);
+       if (up) {
+               ice->midi_output = 1;
+               vt1724_midi_write(ice);
+       } else {
+               ice->midi_output = 0;
+       }
+       spin_unlock_irqrestore(&ice->reg_lock, flags);
+}
+
+static void vt1724_midi_output_drain(struct snd_rawmidi_substream *s)
+{
+       struct snd_ice1712 *ice = s->rmidi->private_data;
+       unsigned long timeout;
+
+       /* 32 bytes should be transmitted in less than about 12 ms */
+       timeout = jiffies + msecs_to_jiffies(15);
+       do {
+               if (inb(ICEREG1724(ice, MPU_CTRL)) & VT1724_MPU_TX_EMPTY)
+                       break;
+               schedule_timeout_uninterruptible(1);
+       } while (time_after(timeout, jiffies));
+}
+
+static struct snd_rawmidi_ops vt1724_midi_output_ops = {
+       .open = vt1724_midi_output_open,
+       .close = vt1724_midi_output_close,
+       .trigger = vt1724_midi_output_trigger,
+       .drain = vt1724_midi_output_drain,
+};
+
+static int vt1724_midi_input_open(struct snd_rawmidi_substream *s)
+{
+       vt1724_midi_clear_rx(s->rmidi->private_data);
+       vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_RX, 1);
+       return 0;
+}
+
+static int vt1724_midi_input_close(struct snd_rawmidi_substream *s)
+{
+       vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_RX, 0);
+       return 0;
+}
+
+static void vt1724_midi_input_trigger(struct snd_rawmidi_substream *s, int up)
+{
+       struct snd_ice1712 *ice = s->rmidi->private_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ice->reg_lock, flags);
+       if (up) {
+               ice->midi_input = 1;
+               vt1724_midi_read(ice);
+       } else {
+               ice->midi_input = 0;
+       }
+       spin_unlock_irqrestore(&ice->reg_lock, flags);
+}
+
+static struct snd_rawmidi_ops vt1724_midi_input_ops = {
+       .open = vt1724_midi_input_open,
+       .close = vt1724_midi_input_close,
+       .trigger = vt1724_midi_input_trigger,
+};
+
 
 /*
  *  Interrupt handler
@@ -278,13 +401,10 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
 #endif
                handled = 1;            
                if (status & VT1724_IRQ_MPU_TX) {
-                       if (ice->rmidi[0])
-                               snd_mpu401_uart_interrupt_tx(irq,
-                                       ice->rmidi[0]->private_data);
-                       else /* disable TX to be sure */
-                               outb(inb(ICEREG1724(ice, IRQMASK)) |
-                                    VT1724_IRQ_MPU_TX,
-                                    ICEREG1724(ice, IRQMASK));
+                       spin_lock(&ice->reg_lock);
+                       if (ice->midi_output)
+                               vt1724_midi_write(ice);
+                       spin_unlock(&ice->reg_lock);
                        /* Due to mysterical reasons, MPU_TX is always
                         * generated (and can't be cleared) when a PCM
                         * playback is going.  So let's ignore at the
@@ -293,13 +413,12 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
                        status_mask &= ~VT1724_IRQ_MPU_TX;
                }
                if (status & VT1724_IRQ_MPU_RX) {
-                       if (ice->rmidi[0])
-                               snd_mpu401_uart_interrupt(irq,
-                                       ice->rmidi[0]->private_data);
-                       else /* disable RX to be sure */
-                               outb(inb(ICEREG1724(ice, IRQMASK)) |
-                                    VT1724_IRQ_MPU_RX,
-                                    ICEREG1724(ice, IRQMASK));
+                       spin_lock(&ice->reg_lock);
+                       if (ice->midi_input)
+                               vt1724_midi_read(ice);
+                       else
+                               vt1724_midi_clear_rx(ice);
+                       spin_unlock(&ice->reg_lock);
                }
                /* ack MPU irq */
                outb(status, ICEREG1724(ice, IRQSTAT));
@@ -2425,28 +2544,30 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
 
        if (! c->no_mpu401) {
                if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
-                       struct snd_mpu401 *mpu;
-                       if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
-                                                      ICEREG1724(ice, MPU_CTRL),
-                                                      (MPU401_INFO_INTEGRATED |
-                                                       MPU401_INFO_NO_ACK |
-                                                       MPU401_INFO_TX_IRQ),
-                                                      ice->irq, 0,
-                                                      &ice->rmidi[0])) < 0) {
+                       struct snd_rawmidi *rmidi;
+
+                       err = snd_rawmidi_new(card, "MIDI", 0, 1, 1, &rmidi);
+                       if (err < 0) {
                                snd_card_free(card);
                                return err;
                        }
-                       mpu = ice->rmidi[0]->private_data;
-                       mpu->read = snd_vt1724_mpu401_read;
-                       mpu->write = snd_vt1724_mpu401_write;
-                       /* unmask MPU RX/TX irqs */
-                       outb(inb(ICEREG1724(ice, IRQMASK)) &
-                            ~(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX),
-                            ICEREG1724(ice, IRQMASK));
+                       ice->rmidi[0] = rmidi;
+                       rmidi->private_data = ice;
+                       strcpy(rmidi->name, "ICE1724 MIDI");
+                       rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
+                                           SNDRV_RAWMIDI_INFO_INPUT |
+                                           SNDRV_RAWMIDI_INFO_DUPLEX;
+                       snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
+                                           &vt1724_midi_output_ops);
+                       snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
+                                           &vt1724_midi_input_ops);
+
                        /* set watermarks */
                        outb(VT1724_MPU_RX_FIFO | 0x1,
                             ICEREG1724(ice, MPU_FIFO_WM));
                        outb(0x1, ICEREG1724(ice, MPU_FIFO_WM));
+                       /* set UART mode */
+                       outb(VT1724_MPU_UART, ICEREG1724(ice, MPU_CTRL));
                }
        }
 
index a536c59..f4788de 100644 (file)
@@ -2427,6 +2427,29 @@ snd_m3_amp_enable(struct snd_m3 *chip, int enable)
        outw(0xffff, io + GPIO_MASK);
 }
 
+static void
+snd_m3_hv_init(struct snd_m3 *chip)
+{
+       unsigned long io = chip->iobase;
+       u16 val = GPI_VOL_DOWN | GPI_VOL_UP;
+
+       if (!chip->is_omnibook)
+               return;
+
+       /*
+        * Volume buttons on some HP OmniBook laptops
+        * require some GPIO magic to work correctly.
+        */
+       outw(0xffff, io + GPIO_MASK);
+       outw(0x0000, io + GPIO_DATA);
+
+       outw(~val, io + GPIO_MASK);
+       outw(inw(io + GPIO_DIRECTION) & ~val, io + GPIO_DIRECTION);
+       outw(val, io + GPIO_MASK);
+
+       outw(0xffff, io + GPIO_MASK);
+}
+
 static int
 snd_m3_chip_init(struct snd_m3 *chip)
 {
@@ -2442,21 +2465,6 @@ snd_m3_chip_init(struct snd_m3 *chip)
               DISABLE_LEGACY);
        pci_write_config_word(pcidev, PCI_LEGACY_AUDIO_CTRL, w);
 
-       if (chip->is_omnibook) {
-               /*
-                * Volume buttons on some HP OmniBook laptops don't work
-                * correctly. This makes them work for the most part.
-                *
-                * Volume up and down buttons on the laptop side work.
-                * Fn+cursor_up (volme up) works.
-                * Fn+cursor_down (volume down) doesn't work.
-                * Fn+F7 (mute) works acts as volume up.
-                */
-               outw(~(GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_MASK);
-               outw(inw(io + GPIO_DIRECTION) & ~(GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_DIRECTION);
-               outw((GPI_VOL_DOWN|GPI_VOL_UP), io + GPIO_DATA);
-               outw(0xffff, io + GPIO_MASK);
-       }
        pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
        n &= ~(HV_CTRL_ENABLE | REDUCED_DEBOUNCE | HV_BUTTON_FROM_GD);
        n |= chip->hv_config;
@@ -2642,6 +2650,8 @@ static int m3_resume(struct pci_dev *pci)
        snd_m3_enable_ints(chip);
        snd_m3_amp_enable(chip, 1);
 
+       snd_m3_hv_init(chip);
+
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        return 0;
 }
@@ -2781,6 +2791,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
 
        snd_m3_amp_enable(chip, 1);
 
+       snd_m3_hv_init(chip);
+
        tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
 
        if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
index 7efb838..06d13e7 100644 (file)
@@ -1302,8 +1302,8 @@ snd_nm256_mixer(struct nm256 *chip)
                .read = snd_nm256_ac97_read,
        };
 
-       chip->ac97_regs = kcalloc(sizeof(short),
-                                 ARRAY_SIZE(nm256_ac97_init_val), GFP_KERNEL);
+       chip->ac97_regs = kcalloc(ARRAY_SIZE(nm256_ac97_init_val),
+                                 sizeof(short), GFP_KERNEL);
        if (! chip->ac97_regs)
                return -ENOMEM;
 
index 090dd43..7442460 100644 (file)
@@ -28,7 +28,7 @@
 
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
 MODULE_DESCRIPTION("TempoTec HiFier driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
@@ -62,16 +62,28 @@ static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
                         AK4396_WRITE | (reg << 8) | value);
 }
 
-static void hifier_init(struct oxygen *chip)
+static void update_ak4396_volume(struct oxygen *chip)
+{
+       ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
+       ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
+}
+
+static void hifier_registers_init(struct oxygen *chip)
 {
        struct hifier_data *data = chip->model_data;
 
-       data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
        ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
        ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
        ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
-       ak4396_write(chip, AK4396_LCH_ATT, 0);
-       ak4396_write(chip, AK4396_RCH_ATT, 0);
+       update_ak4396_volume(chip);
+}
+
+static void hifier_init(struct oxygen *chip)
+{
+       struct hifier_data *data = chip->model_data;
+
+       data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
+       hifier_registers_init(chip);
 
        snd_component_add(chip->card, "AK4396");
        snd_component_add(chip->card, "CS5340");
@@ -100,12 +112,6 @@ static void set_ak4396_params(struct oxygen *chip,
        ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
 }
 
-static void update_ak4396_volume(struct oxygen *chip)
-{
-       ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
-       ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
-}
-
 static void update_ak4396_mute(struct oxygen *chip)
 {
        struct hifier_data *data = chip->model_data;
@@ -140,6 +146,7 @@ static const struct oxygen_model model_hifier = {
        .init = hifier_init,
        .control_filter = hifier_control_filter,
        .cleanup = hifier_cleanup,
+       .resume = hifier_registers_init,
        .set_dac_params = set_ak4396_params,
        .set_adc_params = set_cs5340_params,
        .update_dac_volume = update_ak4396_volume,
@@ -180,6 +187,10 @@ static struct pci_driver hifier_driver = {
        .id_table = hifier_ids,
        .probe = hifier_probe,
        .remove = __devexit_p(oxygen_pci_remove),
+#ifdef CONFIG_PM
+       .suspend = oxygen_pci_suspend,
+       .resume = oxygen_pci_resume,
+#endif
 };
 
 static int __init alsa_card_hifier_init(void)
index 63f185c..7c8ae31 100644 (file)
@@ -43,7 +43,7 @@
 
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
 MODULE_DESCRIPTION("C-Media CMI8788 driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8788}}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
@@ -80,6 +80,7 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
 
 struct generic_data {
        u8 ak4396_ctl2;
+       u16 saved_wm8785_registers[2];
 };
 
 static void ak4396_write(struct oxygen *chip, unsigned int codec,
@@ -99,20 +100,35 @@ static void ak4396_write(struct oxygen *chip, unsigned int codec,
 
 static void wm8785_write(struct oxygen *chip, u8 reg, unsigned int value)
 {
+       struct generic_data *data = chip->model_data;
+
        oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
                         OXYGEN_SPI_DATA_LENGTH_2 |
                         OXYGEN_SPI_CLOCK_160 |
                         (3 << OXYGEN_SPI_CODEC_SHIFT) |
                         OXYGEN_SPI_CEN_LATCH_CLOCK_LO,
                         (reg << 9) | value);
+       if (reg < ARRAY_SIZE(data->saved_wm8785_registers))
+               data->saved_wm8785_registers[reg] = value;
 }
 
-static void ak4396_init(struct oxygen *chip)
+static void update_ak4396_volume(struct oxygen *chip)
+{
+       unsigned int i;
+
+       for (i = 0; i < 4; ++i) {
+               ak4396_write(chip, i,
+                            AK4396_LCH_ATT, chip->dac_volume[i * 2]);
+               ak4396_write(chip, i,
+                            AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]);
+       }
+}
+
+static void ak4396_registers_init(struct oxygen *chip)
 {
        struct generic_data *data = chip->model_data;
        unsigned int i;
 
-       data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
        for (i = 0; i < 4; ++i) {
                ak4396_write(chip, i,
                             AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
@@ -120,9 +136,16 @@ static void ak4396_init(struct oxygen *chip)
                             AK4396_CONTROL_2, data->ak4396_ctl2);
                ak4396_write(chip, i,
                             AK4396_CONTROL_3, AK4396_PCM);
-               ak4396_write(chip, i, AK4396_LCH_ATT, 0);
-               ak4396_write(chip, i, AK4396_RCH_ATT, 0);
        }
+       update_ak4396_volume(chip);
+}
+
+static void ak4396_init(struct oxygen *chip)
+{
+       struct generic_data *data = chip->model_data;
+
+       data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
+       ak4396_registers_init(chip);
        snd_component_add(chip->card, "AK4396");
 }
 
@@ -133,12 +156,23 @@ static void ak5385_init(struct oxygen *chip)
        snd_component_add(chip->card, "AK5385");
 }
 
-static void wm8785_init(struct oxygen *chip)
+static void wm8785_registers_init(struct oxygen *chip)
 {
+       struct generic_data *data = chip->model_data;
+
        wm8785_write(chip, WM8785_R7, 0);
-       wm8785_write(chip, WM8785_R0, WM8785_MCR_SLAVE |
-                    WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST);
-       wm8785_write(chip, WM8785_R1, WM8785_WL_24);
+       wm8785_write(chip, WM8785_R0, data->saved_wm8785_registers[0]);
+       wm8785_write(chip, WM8785_R1, data->saved_wm8785_registers[1]);
+}
+
+static void wm8785_init(struct oxygen *chip)
+{
+       struct generic_data *data = chip->model_data;
+
+       data->saved_wm8785_registers[0] = WM8785_MCR_SLAVE |
+               WM8785_OSR_SINGLE | WM8785_FORMAT_LJUST;
+       data->saved_wm8785_registers[1] = WM8785_WL_24;
+       wm8785_registers_init(chip);
        snd_component_add(chip->card, "WM8785");
 }
 
@@ -158,6 +192,12 @@ static void generic_cleanup(struct oxygen *chip)
 {
 }
 
+static void generic_resume(struct oxygen *chip)
+{
+       ak4396_registers_init(chip);
+       wm8785_registers_init(chip);
+}
+
 static void set_ak4396_params(struct oxygen *chip,
                              struct snd_pcm_hw_params *params)
 {
@@ -183,18 +223,6 @@ static void set_ak4396_params(struct oxygen *chip,
        }
 }
 
-static void update_ak4396_volume(struct oxygen *chip)
-{
-       unsigned int i;
-
-       for (i = 0; i < 4; ++i) {
-               ak4396_write(chip, i,
-                            AK4396_LCH_ATT, chip->dac_volume[i * 2]);
-               ak4396_write(chip, i,
-                            AK4396_RCH_ATT, chip->dac_volume[i * 2 + 1]);
-       }
-}
-
 static void update_ak4396_mute(struct oxygen *chip)
 {
        struct generic_data *data = chip->model_data;
@@ -256,6 +284,7 @@ static const struct oxygen_model model_generic = {
        .owner = THIS_MODULE,
        .init = generic_init,
        .cleanup = generic_cleanup,
+       .resume = generic_resume,
        .set_dac_params = set_ak4396_params,
        .set_adc_params = set_wm8785_params,
        .update_dac_volume = update_ak4396_volume,
@@ -283,6 +312,7 @@ static const struct oxygen_model model_meridian = {
        .owner = THIS_MODULE,
        .init = meridian_init,
        .cleanup = generic_cleanup,
+       .resume = ak4396_registers_init,
        .set_dac_params = set_ak4396_params,
        .set_adc_params = set_ak5385_params,
        .update_dac_volume = update_ak4396_volume,
@@ -331,6 +361,10 @@ static struct pci_driver oxygen_driver = {
        .id_table = oxygen_ids,
        .probe = generic_oxygen_probe,
        .remove = __devexit_p(oxygen_pci_remove),
+#ifdef CONFIG_PM
+       .suspend = oxygen_pci_suspend,
+       .resume = oxygen_pci_resume,
+#endif
 };
 
 static int __init alsa_card_oxygen_init(void)
index a71c6e0..74a6448 100644 (file)
@@ -16,6 +16,8 @@
 #define PCM_AC97       5
 #define PCM_COUNT      6
 
+#define OXYGEN_IO_SIZE 0x100
+
 /* model-specific configuration of outputs/inputs */
 #define PLAYBACK_0_TO_I2S      0x001
 #define PLAYBACK_1_TO_SPDIF    0x004
@@ -78,6 +80,12 @@ struct oxygen {
        struct work_struct spdif_input_bits_work;
        struct work_struct gpio_work;
        wait_queue_head_t ac97_waitqueue;
+       union {
+               u8 _8[OXYGEN_IO_SIZE];
+               __le16 _16[OXYGEN_IO_SIZE / 2];
+               __le32 _32[OXYGEN_IO_SIZE / 4];
+       } saved_registers;
+       u16 saved_ac97_registers[2][0x40];
 };
 
 struct oxygen_model {
@@ -89,6 +97,8 @@ struct oxygen_model {
        int (*control_filter)(struct snd_kcontrol_new *template);
        int (*mixer_init)(struct oxygen *chip);
        void (*cleanup)(struct oxygen *chip);
+       void (*suspend)(struct oxygen *chip);
+       void (*resume)(struct oxygen *chip);
        void (*pcm_hardware_filter)(unsigned int channel,
                                    struct snd_pcm_hardware *hardware);
        void (*set_dac_params)(struct oxygen *chip,
@@ -117,6 +127,10 @@ struct oxygen_model {
 int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
                     const struct oxygen_model *model);
 void oxygen_pci_remove(struct pci_dev *pci);
+#ifdef CONFIG_PM
+int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state);
+int oxygen_pci_resume(struct pci_dev *pci);
+#endif
 
 /* oxygen_mixer.c */
 
index 5569606..83f135f 100644 (file)
@@ -44,18 +44,21 @@ EXPORT_SYMBOL(oxygen_read32);
 void oxygen_write8(struct oxygen *chip, unsigned int reg, u8 value)
 {
        outb(value, chip->addr + reg);
+       chip->saved_registers._8[reg] = value;
 }
 EXPORT_SYMBOL(oxygen_write8);
 
 void oxygen_write16(struct oxygen *chip, unsigned int reg, u16 value)
 {
        outw(value, chip->addr + reg);
+       chip->saved_registers._16[reg / 2] = cpu_to_le16(value);
 }
 EXPORT_SYMBOL(oxygen_write16);
 
 void oxygen_write32(struct oxygen *chip, unsigned int reg, u32 value)
 {
        outl(value, chip->addr + reg);
+       chip->saved_registers._32[reg / 4] = cpu_to_le32(value);
 }
 EXPORT_SYMBOL(oxygen_write32);
 
@@ -63,7 +66,10 @@ void oxygen_write8_masked(struct oxygen *chip, unsigned int reg,
                          u8 value, u8 mask)
 {
        u8 tmp = inb(chip->addr + reg);
-       outb((tmp & ~mask) | (value & mask), chip->addr + reg);
+       tmp &= ~mask;
+       tmp |= value & mask;
+       outb(tmp, chip->addr + reg);
+       chip->saved_registers._8[reg] = tmp;
 }
 EXPORT_SYMBOL(oxygen_write8_masked);
 
@@ -71,7 +77,10 @@ void oxygen_write16_masked(struct oxygen *chip, unsigned int reg,
                           u16 value, u16 mask)
 {
        u16 tmp = inw(chip->addr + reg);
-       outw((tmp & ~mask) | (value & mask), chip->addr + reg);
+       tmp &= ~mask;
+       tmp |= value & mask;
+       outw(tmp, chip->addr + reg);
+       chip->saved_registers._16[reg / 2] = cpu_to_le16(tmp);
 }
 EXPORT_SYMBOL(oxygen_write16_masked);
 
@@ -79,7 +88,10 @@ void oxygen_write32_masked(struct oxygen *chip, unsigned int reg,
                           u32 value, u32 mask)
 {
        u32 tmp = inl(chip->addr + reg);
-       outl((tmp & ~mask) | (value & mask), chip->addr + reg);
+       tmp &= ~mask;
+       tmp |= value & mask;
+       outl(tmp, chip->addr + reg);
+       chip->saved_registers._32[reg / 4] = cpu_to_le32(tmp);
 }
 EXPORT_SYMBOL(oxygen_write32_masked);
 
@@ -128,8 +140,10 @@ void oxygen_write_ac97(struct oxygen *chip, unsigned int codec,
                oxygen_write32(chip, OXYGEN_AC97_REGS, reg);
                /* require two "completed" writes, just to be sure */
                if (oxygen_ac97_wait(chip, OXYGEN_AC97_INT_WRITE_DONE) >= 0 &&
-                   ++succeeded >= 2)
+                   ++succeeded >= 2) {
+                       chip->saved_ac97_registers[codec][index / 2] = data;
                        return;
+               }
        }
        snd_printk(KERN_ERR "AC'97 write timeout\n");
 }
index 897697d..22f3785 100644 (file)
@@ -32,7 +32,7 @@
 
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
 MODULE_DESCRIPTION("C-Media CMI8788 helper library");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 
 
 static irqreturn_t oxygen_interrupt(int dummy, void *dev_id)
@@ -173,7 +173,7 @@ static void oxygen_proc_read(struct snd_info_entry *entry,
        int i, j;
 
        snd_iprintf(buffer, "CMI8788\n\n");
-       for (i = 0; i < 0x100; i += 0x10) {
+       for (i = 0; i < OXYGEN_IO_SIZE; i += 0x10) {
                snd_iprintf(buffer, "%02x:", i);
                for (j = 0; j < 0x10; ++j)
                        snd_iprintf(buffer, " %02x", oxygen_read8(chip, i + j));
@@ -314,6 +314,10 @@ static void oxygen_init(struct oxygen *chip)
                                    OXYGEN_SPDIF_LOCK_MASK |
                                    OXYGEN_SPDIF_RATE_MASK);
        oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits);
+       oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
+                      OXYGEN_2WIRE_LENGTH_8 |
+                      OXYGEN_2WIRE_INTERRUPT_MASK |
+                      OXYGEN_2WIRE_SPEED_STANDARD);
        oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK);
        oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0);
        oxygen_write16(chip, OXYGEN_GPIO_INTERRUPT_MASK, 0);
@@ -455,7 +459,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
        }
 
        if (!(pci_resource_flags(pci, 0) & IORESOURCE_IO) ||
-           pci_resource_len(pci, 0) < 0x100) {
+           pci_resource_len(pci, 0) < OXYGEN_IO_SIZE) {
                snd_printk(KERN_ERR "invalid PCI I/O range\n");
                err = -ENXIO;
                goto err_pci_regions;
@@ -534,3 +538,99 @@ void oxygen_pci_remove(struct pci_dev *pci)
        pci_set_drvdata(pci, NULL);
 }
 EXPORT_SYMBOL(oxygen_pci_remove);
+
+#ifdef CONFIG_PM
+int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct oxygen *chip = card->private_data;
+       unsigned int i, saved_interrupt_mask;
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+
+       for (i = 0; i < PCM_COUNT; ++i)
+               if (chip->streams[i])
+                       snd_pcm_suspend(chip->streams[i]);
+
+       if (chip->model->suspend)
+               chip->model->suspend(chip);
+
+       spin_lock_irq(&chip->reg_lock);
+       saved_interrupt_mask = chip->interrupt_mask;
+       chip->interrupt_mask = 0;
+       oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
+       oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
+       spin_unlock_irq(&chip->reg_lock);
+
+       synchronize_irq(chip->irq);
+       flush_scheduled_work();
+       chip->interrupt_mask = saved_interrupt_mask;
+
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       pci_set_power_state(pci, pci_choose_state(pci, state));
+       return 0;
+}
+EXPORT_SYMBOL(oxygen_pci_suspend);
+
+static const u32 registers_to_restore[OXYGEN_IO_SIZE / 32] = {
+       0xffffffff, 0x00ff077f, 0x00011d08, 0x007f00ff,
+       0x00300000, 0x00000fe4, 0x0ff7001f, 0x00000000
+};
+static const u32 ac97_registers_to_restore[2][0x40 / 32] = {
+       { 0x18284fa2, 0x03060000 },
+       { 0x00007fa6, 0x00200000 }
+};
+
+static inline int is_bit_set(const u32 *bitmap, unsigned int bit)
+{
+       return bitmap[bit / 32] & (1 << (bit & 31));
+}
+
+static void oxygen_restore_ac97(struct oxygen *chip, unsigned int codec)
+{
+       unsigned int i;
+
+       oxygen_write_ac97(chip, codec, AC97_RESET, 0);
+       msleep(1);
+       for (i = 1; i < 0x40; ++i)
+               if (is_bit_set(ac97_registers_to_restore[codec], i))
+                       oxygen_write_ac97(chip, codec, i * 2,
+                                         chip->saved_ac97_registers[codec][i]);
+}
+
+int oxygen_pci_resume(struct pci_dev *pci)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct oxygen *chip = card->private_data;
+       unsigned int i;
+
+       pci_set_power_state(pci, PCI_D0);
+       pci_restore_state(pci);
+       if (pci_enable_device(pci) < 0) {
+               snd_printk(KERN_ERR "cannot reenable device");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
+       pci_set_master(pci);
+
+       oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
+       oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
+       for (i = 0; i < OXYGEN_IO_SIZE; ++i)
+               if (is_bit_set(registers_to_restore, i))
+                       oxygen_write8(chip, i, chip->saved_registers._8[i]);
+       if (chip->has_ac97_0)
+               oxygen_restore_ac97(chip, 0);
+       if (chip->has_ac97_1)
+               oxygen_restore_ac97(chip, 1);
+
+       if (chip->model->resume)
+               chip->model->resume(chip);
+
+       oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+EXPORT_SYMBOL(oxygen_pci_resume);
+#endif /* CONFIG_PM */
index b17c405..c4ad65a 100644 (file)
 #include <sound/pcm_params.h>
 #include "oxygen.h"
 
+/* most DMA channels have a 16-bit counter for 32-bit words */
+#define BUFFER_BYTES_MAX               ((1 << 16) * 4)
+/* the multichannel DMA channel has a 24-bit counter */
+#define BUFFER_BYTES_MAX_MULTICH       ((1 << 24) * 4)
+
+#define PERIOD_BYTES_MIN               64
+
+#define DEFAULT_BUFFER_BYTES           (BUFFER_BYTES_MAX / 2)
+#define DEFAULT_BUFFER_BYTES_MULTICH   (1024 * 1024)
+
 static const struct snd_pcm_hardware oxygen_stereo_hardware = {
        .info = SNDRV_PCM_INFO_MMAP |
                SNDRV_PCM_INFO_MMAP_VALID |
@@ -44,11 +54,11 @@ static const struct snd_pcm_hardware oxygen_stereo_hardware = {
        .rate_max = 192000,
        .channels_min = 2,
        .channels_max = 2,
-       .buffer_bytes_max = 256 * 1024,
-       .period_bytes_min = 128,
-       .period_bytes_max = 128 * 1024,
+       .buffer_bytes_max = BUFFER_BYTES_MAX,
+       .period_bytes_min = PERIOD_BYTES_MIN,
+       .period_bytes_max = BUFFER_BYTES_MAX / 2,
        .periods_min = 2,
-       .periods_max = 2048,
+       .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
 };
 static const struct snd_pcm_hardware oxygen_multichannel_hardware = {
        .info = SNDRV_PCM_INFO_MMAP |
@@ -70,11 +80,11 @@ static const struct snd_pcm_hardware oxygen_multichannel_hardware = {
        .rate_max = 192000,
        .channels_min = 2,
        .channels_max = 8,
-       .buffer_bytes_max = 2048 * 1024,
-       .period_bytes_min = 128,
-       .period_bytes_max = 256 * 1024,
+       .buffer_bytes_max = BUFFER_BYTES_MAX_MULTICH,
+       .period_bytes_min = PERIOD_BYTES_MIN,
+       .period_bytes_max = BUFFER_BYTES_MAX_MULTICH / 2,
        .periods_min = 2,
-       .periods_max = 16384,
+       .periods_max = BUFFER_BYTES_MAX_MULTICH / PERIOD_BYTES_MIN,
 };
 static const struct snd_pcm_hardware oxygen_ac97_hardware = {
        .info = SNDRV_PCM_INFO_MMAP |
@@ -88,11 +98,11 @@ static const struct snd_pcm_hardware oxygen_ac97_hardware = {
        .rate_max = 48000,
        .channels_min = 2,
        .channels_max = 2,
-       .buffer_bytes_max = 256 * 1024,
-       .period_bytes_min = 128,
-       .period_bytes_max = 128 * 1024,
+       .buffer_bytes_max = BUFFER_BYTES_MAX,
+       .period_bytes_min = PERIOD_BYTES_MIN,
+       .period_bytes_max = BUFFER_BYTES_MAX / 2,
        .periods_min = 2,
-       .periods_max = 2048,
+       .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
 };
 
 static const struct snd_pcm_hardware *const oxygen_hardware[PCM_COUNT] = {
@@ -155,6 +165,12 @@ static int oxygen_open(struct snd_pcm_substream *substream,
                if (err < 0)
                        return err;
        }
+       if (channel == PCM_MULTICH) {
+               err = snd_pcm_hw_constraint_minmax
+                       (runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 0, 8192000);
+               if (err < 0)
+                       return err;
+       }
        snd_pcm_set_sync(substream);
        chip->streams[channel] = substream;
 
@@ -517,6 +533,7 @@ static int oxygen_trigger(struct snd_pcm_substream *substream, int cmd)
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_STOP:
        case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                pausing = 0;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -663,12 +680,14 @@ int oxygen_pcm_init(struct oxygen *chip)
                        snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
                                                      SNDRV_DMA_TYPE_DEV,
                                                      snd_dma_pci_data(chip->pci),
-                                                     512 * 1024, 2048 * 1024);
+                                                     DEFAULT_BUFFER_BYTES_MULTICH,
+                                                     BUFFER_BYTES_MAX_MULTICH);
                if (ins)
                        snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
                                                      SNDRV_DMA_TYPE_DEV,
                                                      snd_dma_pci_data(chip->pci),
-                                                     128 * 1024, 256 * 1024);
+                                                     DEFAULT_BUFFER_BYTES,
+                                                     BUFFER_BYTES_MAX);
        }
 
        outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF);
@@ -688,7 +707,8 @@ int oxygen_pcm_init(struct oxygen *chip)
                strcpy(pcm->name, "Digital");
                snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
                                                      snd_dma_pci_data(chip->pci),
-                                                     128 * 1024, 256 * 1024);
+                                                     DEFAULT_BUFFER_BYTES,
+                                                     BUFFER_BYTES_MAX);
        }
 
        if (chip->has_ac97_1) {
@@ -718,7 +738,8 @@ int oxygen_pcm_init(struct oxygen *chip)
                strcpy(pcm->name, outs ? "Front Panel" : "Analog 2");
                snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
                                                      snd_dma_pci_data(chip->pci),
-                                                     128 * 1024, 256 * 1024);
+                                                     DEFAULT_BUFFER_BYTES,
+                                                     BUFFER_BYTES_MAX);
        }
        return 0;
 }
index 7f84fa5..9a2c16b 100644 (file)
@@ -79,7 +79,7 @@
 
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
 MODULE_DESCRIPTION("Asus AVx00 driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
@@ -132,6 +132,9 @@ struct xonar_data {
        u8 ext_power_int_reg;
        u8 ext_power_bit;
        u8 has_power;
+       u8 pcm1796_oversampling;
+       u8 cs4398_fm;
+       u8 cs4362a_fm;
 };
 
 static void pcm1796_write(struct oxygen *chip, unsigned int codec,
@@ -159,6 +162,14 @@ static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
        oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
 }
 
+static void xonar_enable_output(struct oxygen *chip)
+{
+       struct xonar_data *data = chip->model_data;
+
+       msleep(data->anti_pop_delay);
+       oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
+}
+
 static void xonar_common_init(struct oxygen *chip)
 {
        struct xonar_data *data = chip->model_data;
@@ -170,32 +181,59 @@ static void xonar_common_init(struct oxygen *chip)
                data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
                                     & data->ext_power_bit);
        }
-       oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
+       oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
+                         GPIO_CS53x1_M_MASK | data->output_enable_bit);
        oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
                              GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
        oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
-       msleep(data->anti_pop_delay);
-       oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
-       oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
+       xonar_enable_output(chip);
 }
 
-static void xonar_d2_init(struct oxygen *chip)
+static void update_pcm1796_volume(struct oxygen *chip)
 {
-       struct xonar_data *data = chip->model_data;
        unsigned int i;
 
-       data->anti_pop_delay = 300;
-       data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
+       for (i = 0; i < 4; ++i) {
+               pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
+               pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
+       }
+}
+
+static void update_pcm1796_mute(struct oxygen *chip)
+{
+       unsigned int i;
+       u8 value;
+
+       value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_LJUST | PCM1796_ATLD;
+       if (chip->dac_mute)
+               value |= PCM1796_MUTE;
+       for (i = 0; i < 4; ++i)
+               pcm1796_write(chip, i, 18, value);
+}
+
+static void pcm1796_init(struct oxygen *chip)
+{
+       struct xonar_data *data = chip->model_data;
+       unsigned int i;
 
        for (i = 0; i < 4; ++i) {
-               pcm1796_write(chip, i, 18, PCM1796_MUTE | PCM1796_DMF_DISABLED |
-                             PCM1796_FMT_24_LJUST | PCM1796_ATLD);
                pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
-               pcm1796_write(chip, i, 20, PCM1796_OS_64);
+               pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
                pcm1796_write(chip, i, 21, 0);
-               pcm1796_write(chip, i, 16, 0x0f); /* set ATL/ATR after ATLD */
-               pcm1796_write(chip, i, 17, 0x0f);
        }
+       update_pcm1796_mute(chip); /* set ATLD before ATL/ATR */
+       update_pcm1796_volume(chip);
+}
+
+static void xonar_d2_init(struct oxygen *chip)
+{
+       struct xonar_data *data = chip->model_data;
+
+       data->anti_pop_delay = 300;
+       data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
+       data->pcm1796_oversampling = PCM1796_OS_64;
+
+       pcm1796_init(chip);
 
        oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
        oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
@@ -217,31 +255,47 @@ static void xonar_d2x_init(struct oxygen *chip)
        xonar_d2_init(chip);
 }
 
-static void xonar_dx_init(struct oxygen *chip)
+static void update_cs4362a_volumes(struct oxygen *chip)
 {
-       struct xonar_data *data = chip->model_data;
+       u8 mute;
 
-       data->anti_pop_delay = 800;
-       data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
-       data->ext_power_reg = OXYGEN_GPI_DATA;
-       data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
-       data->ext_power_bit = GPI_DX_EXT_POWER;
+       mute = chip->dac_mute ? CS4362A_MUTE : 0;
+       cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
+       cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
+       cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
+       cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
+       cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
+       cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
+}
 
-       oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
-                      OXYGEN_2WIRE_LENGTH_8 |
-                      OXYGEN_2WIRE_INTERRUPT_MASK |
-                      OXYGEN_2WIRE_SPEED_FAST);
+static void update_cs43xx_volume(struct oxygen *chip)
+{
+       cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
+       cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
+       update_cs4362a_volumes(chip);
+}
+
+static void update_cs43xx_mute(struct oxygen *chip)
+{
+       u8 reg;
+
+       reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
+       if (chip->dac_mute)
+               reg |= CS4398_MUTE_B | CS4398_MUTE_A;
+       cs4398_write(chip, 4, reg);
+       update_cs4362a_volumes(chip);
+}
+
+static void cs43xx_init(struct oxygen *chip)
+{
+       struct xonar_data *data = chip->model_data;
 
        /* set CPEN (control port mode) and power down */
        cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
        cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
        /* configure */
-       cs4398_write(chip, 2, CS4398_FM_SINGLE |
-                    CS4398_DEM_NONE | CS4398_DIF_LJUST);
+       cs4398_write(chip, 2, data->cs4398_fm);
        cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
-       cs4398_write(chip, 4, CS4398_MUTEP_LOW | CS4398_PAMUTE);
-       cs4398_write(chip, 5, 0xfe);
-       cs4398_write(chip, 6, 0xfe);
        cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
                     CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
        cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
@@ -249,21 +303,35 @@ static void xonar_dx_init(struct oxygen *chip)
                      CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
        cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
        cs4362a_write(chip, 0x05, 0);
-       cs4362a_write(chip, 0x06, CS4362A_FM_SINGLE |
-                     CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
-       cs4362a_write(chip, 0x07, 0x7f | CS4362A_MUTE);
-       cs4362a_write(chip, 0x08, 0x7f | CS4362A_MUTE);
-       cs4362a_write(chip, 0x09, CS4362A_FM_SINGLE |
-                     CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
-       cs4362a_write(chip, 0x0a, 0x7f | CS4362A_MUTE);
-       cs4362a_write(chip, 0x0b, 0x7f | CS4362A_MUTE);
-       cs4362a_write(chip, 0x0c, CS4362A_FM_SINGLE |
-                     CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
-       cs4362a_write(chip, 0x0d, 0x7f | CS4362A_MUTE);
-       cs4362a_write(chip, 0x0e, 0x7f | CS4362A_MUTE);
+       cs4362a_write(chip, 0x06, data->cs4362a_fm);
+       cs4362a_write(chip, 0x09, data->cs4362a_fm);
+       cs4362a_write(chip, 0x0c, data->cs4362a_fm);
+       update_cs43xx_volume(chip);
+       update_cs43xx_mute(chip);
        /* clear power down */
        cs4398_write(chip, 8, CS4398_CPEN);
        cs4362a_write(chip, 0x01, CS4362A_CPEN);
+}
+
+static void xonar_dx_init(struct oxygen *chip)
+{
+       struct xonar_data *data = chip->model_data;
+
+       data->anti_pop_delay = 800;
+       data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
+       data->ext_power_reg = OXYGEN_GPI_DATA;
+       data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
+       data->ext_power_bit = GPI_DX_EXT_POWER;
+       data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
+       data->cs4362a_fm = CS4362A_FM_SINGLE |
+               CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
+
+       oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
+                      OXYGEN_2WIRE_LENGTH_8 |
+                      OXYGEN_2WIRE_INTERRUPT_MASK |
+                      OXYGEN_2WIRE_SPEED_FAST);
+
+       cs43xx_init(chip);
 
        oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
                          GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
@@ -291,37 +359,28 @@ static void xonar_dx_cleanup(struct oxygen *chip)
        oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
 }
 
-static void set_pcm1796_params(struct oxygen *chip,
-                              struct snd_pcm_hw_params *params)
+static void xonar_d2_resume(struct oxygen *chip)
 {
-       unsigned int i;
-       u8 value;
-
-       value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
-       for (i = 0; i < 4; ++i)
-               pcm1796_write(chip, i, 20, value);
+       pcm1796_init(chip);
+       xonar_enable_output(chip);
 }
 
-static void update_pcm1796_volume(struct oxygen *chip)
+static void xonar_dx_resume(struct oxygen *chip)
 {
-       unsigned int i;
-
-       for (i = 0; i < 4; ++i) {
-               pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]);
-               pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]);
-       }
+       cs43xx_init(chip);
+       xonar_enable_output(chip);
 }
 
-static void update_pcm1796_mute(struct oxygen *chip)
+static void set_pcm1796_params(struct oxygen *chip,
+                              struct snd_pcm_hw_params *params)
 {
+       struct xonar_data *data = chip->model_data;
        unsigned int i;
-       u8 value;
 
-       value = PCM1796_FMT_24_LJUST | PCM1796_ATLD;
-       if (chip->dac_mute)
-               value |= PCM1796_MUTE;
+       data->pcm1796_oversampling =
+               params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
        for (i = 0; i < 4; ++i)
-               pcm1796_write(chip, i, 18, value);
+               pcm1796_write(chip, i, 20, data->pcm1796_oversampling);
 }
 
 static void set_cs53x1_params(struct oxygen *chip,
@@ -342,55 +401,24 @@ static void set_cs53x1_params(struct oxygen *chip,
 static void set_cs43xx_params(struct oxygen *chip,
                              struct snd_pcm_hw_params *params)
 {
-       u8 fm_cs4398, fm_cs4362a;
+       struct xonar_data *data = chip->model_data;
 
-       fm_cs4398 = CS4398_DEM_NONE | CS4398_DIF_LJUST;
-       fm_cs4362a = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
+       data->cs4398_fm = CS4398_DEM_NONE | CS4398_DIF_LJUST;
+       data->cs4362a_fm = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
        if (params_rate(params) <= 50000) {
-               fm_cs4398 |= CS4398_FM_SINGLE;
-               fm_cs4362a |= CS4362A_FM_SINGLE;
+               data->cs4398_fm |= CS4398_FM_SINGLE;
+               data->cs4362a_fm |= CS4362A_FM_SINGLE;
        } else if (params_rate(params) <= 100000) {
-               fm_cs4398 |= CS4398_FM_DOUBLE;
-               fm_cs4362a |= CS4362A_FM_DOUBLE;
+               data->cs4398_fm |= CS4398_FM_DOUBLE;
+               data->cs4362a_fm |= CS4362A_FM_DOUBLE;
        } else {
-               fm_cs4398 |= CS4398_FM_QUAD;
-               fm_cs4362a |= CS4362A_FM_QUAD;
+               data->cs4398_fm |= CS4398_FM_QUAD;
+               data->cs4362a_fm |= CS4362A_FM_QUAD;
        }
-       cs4398_write(chip, 2, fm_cs4398);
-       cs4362a_write(chip, 0x06, fm_cs4362a);
-       cs4362a_write(chip, 0x09, fm_cs4362a);
-       cs4362a_write(chip, 0x0c, fm_cs4362a);
-}
-
-static void update_cs4362a_volumes(struct oxygen *chip)
-{
-       u8 mute;
-
-       mute = chip->dac_mute ? CS4362A_MUTE : 0;
-       cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
-       cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
-       cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
-       cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
-       cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
-       cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
-}
-
-static void update_cs43xx_volume(struct oxygen *chip)
-{
-       cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
-       cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
-       update_cs4362a_volumes(chip);
-}
-
-static void update_cs43xx_mute(struct oxygen *chip)
-{
-       u8 reg;
-
-       reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
-       if (chip->dac_mute)
-               reg |= CS4398_MUTE_B | CS4398_MUTE_A;
-       cs4398_write(chip, 4, reg);
-       update_cs4362a_volumes(chip);
+       cs4398_write(chip, 2, data->cs4398_fm);
+       cs4362a_write(chip, 0x06, data->cs4362a_fm);
+       cs4362a_write(chip, 0x09, data->cs4362a_fm);
+       cs4362a_write(chip, 0x0c, data->cs4362a_fm);
 }
 
 static void xonar_gpio_changed(struct oxygen *chip)
@@ -535,6 +563,8 @@ static const struct oxygen_model xonar_models[] = {
                .control_filter = xonar_d2_control_filter,
                .mixer_init = xonar_mixer_init,
                .cleanup = xonar_cleanup,
+               .suspend = xonar_cleanup,
+               .resume = xonar_d2_resume,
                .set_dac_params = set_pcm1796_params,
                .set_adc_params = set_cs53x1_params,
                .update_dac_volume = update_pcm1796_volume,
@@ -563,6 +593,8 @@ static const struct oxygen_model xonar_models[] = {
                .control_filter = xonar_d2_control_filter,
                .mixer_init = xonar_mixer_init,
                .cleanup = xonar_cleanup,
+               .suspend = xonar_cleanup,
+               .resume = xonar_d2_resume,
                .set_dac_params = set_pcm1796_params,
                .set_adc_params = set_cs53x1_params,
                .update_dac_volume = update_pcm1796_volume,
@@ -592,6 +624,8 @@ static const struct oxygen_model xonar_models[] = {
                .control_filter = xonar_dx_control_filter,
                .mixer_init = xonar_dx_mixer_init,
                .cleanup = xonar_dx_cleanup,
+               .suspend = xonar_dx_cleanup,
+               .resume = xonar_dx_resume,
                .set_dac_params = set_cs43xx_params,
                .set_adc_params = set_cs53x1_params,
                .update_dac_volume = update_cs43xx_volume,
@@ -636,6 +670,10 @@ static struct pci_driver xonar_driver = {
        .id_table = xonar_ids,
        .probe = xonar_probe,
        .remove = __devexit_p(oxygen_pci_remove),
+#ifdef CONFIG_PM
+       .suspend = oxygen_pci_suspend,
+       .resume = oxygen_pci_resume,
+#endif
 };
 
 static int __init alsa_card_xonar_init(void)
index 7fdcdc8..2c7e253 100644 (file)
@@ -516,7 +516,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
        int capture_mask = 0;
        int playback_mask = 0;
 
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        struct timeval my_tv1, my_tv2;
        do_gettimeofday(&my_tv1);
 #endif
@@ -623,7 +623,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
 
        mutex_unlock(&mgr->setup_mutex);
 
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        do_gettimeofday(&my_tv2);
        snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
                    (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
index 78aa81f..abe5c59 100644 (file)
@@ -473,7 +473,7 @@ static struct pcxhr_cmd_info pcxhr_dsp_cmds[] = {
 [CMD_AUDIO_LEVEL_ADJUST] =             { 0xc22000, 0, RMH_SSIZE_FIXED },
 };
 
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
 static char* cmd_names[] = {
 [CMD_VERSION] =                                "CMD_VERSION",
 [CMD_SUPPORTED] =                      "CMD_SUPPORTED",
@@ -549,7 +549,7 @@ static int pcxhr_read_rmh_status(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
                                }
                        }
                }
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
                if (rmh->cmd_idx < CMD_LAST_INDEX)
                        snd_printdd("    stat[%d]=%x\n", i, data);
 #endif
@@ -597,7 +597,7 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
                data |= 0x008000;       /* MASK_MORE_THAN_1_WORD_COMMAND */
        else
                data &= 0xff7fff;       /* MASK_1_WORD_COMMAND */
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        if (rmh->cmd_idx < CMD_LAST_INDEX)
                snd_printdd("MSG cmd[0]=%x (%s)\n", data, cmd_names[rmh->cmd_idx]);
 #endif
@@ -624,7 +624,7 @@ static int pcxhr_send_msg_nolock(struct pcxhr_mgr *mgr, struct pcxhr_rmh *rmh)
                for (i=1; i < rmh->cmd_len; i++) {
                        /* send other words */
                        data = rmh->cmd[i];
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
                        if (rmh->cmd_idx < CMD_LAST_INDEX)
                                snd_printdd("    cmd[%d]=%x\n", i, data);
 #endif
@@ -847,7 +847,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
        int state, i, err;
        int audio_mask;
 
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        struct timeval my_tv1, my_tv2;
        do_gettimeofday(&my_tv1);
 #endif
@@ -894,7 +894,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
                if (err)
                        return err;
        }
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        do_gettimeofday(&my_tv2);
        snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n",
                    (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
@@ -951,7 +951,7 @@ static int pcxhr_handle_async_err(struct pcxhr_mgr *mgr, u32 err,
                                  enum pcxhr_async_err_src err_src, int pipe,
                                  int is_capture)
 {
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        static char* err_src_name[] = {
                [PCXHR_ERR_PIPE]        = "Pipe",
                [PCXHR_ERR_STREAM]      = "Stream",
@@ -1169,7 +1169,7 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
                                    mgr->dsp_time_last, dsp_time_new);
                        mgr->dsp_time_err++;
                }
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
                if (dsp_time_diff == 0)
                        snd_printdd("ERROR DSP TIME NO DIFF time(%d)\n", dsp_time_new);
                else if (dsp_time_diff >= (2*PCXHR_GRANULARITY))
@@ -1208,7 +1208,7 @@ irqreturn_t pcxhr_interrupt(int irq, void *dev_id)
                mgr->src_it_dsp = reg;
                tasklet_hi_schedule(&mgr->msg_taskq);
        }
-#ifdef CONFIG_SND_DEBUG_DETECT
+#ifdef CONFIG_SND_DEBUG_VERBOSE
        if (reg & PCXHR_FATAL_DSP_ERR)
                snd_printdd("FATAL DSP ERROR : %x\n", reg);
 #endif
index bbcee2c..a69b420 100644 (file)
@@ -1590,7 +1590,10 @@ static int snd_trident_trigger(struct snd_pcm_substream *substream,
        if (spdif_flag) {
                if (trident->device != TRIDENT_DEVICE_ID_SI7018) {
                        outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS));
-                       outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
+                       val = trident->spdif_pcm_ctrl;
+                       if (!go)
+                               val &= ~(0x28);
+                       outb(val, TRID_REG(trident, NX_SPCTRL_SPCSO + 3));
                } else {
                        outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS));
                        val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN;
index df9b487..3fd7f1b 100644 (file)
@@ -310,181 +310,3 @@ int snd_trident_free_pages(struct snd_trident *trident,
        mutex_unlock(&hdr->block_mutex);
        return 0;
 }
-
-
-/*----------------------------------------------------------------
- * memory allocation using multiple pages (for synth)
- *----------------------------------------------------------------
- * Unlike the DMA allocation above, non-contiguous pages are
- * assigned to TLB.
- *----------------------------------------------------------------*/
-
-/*
- */
-static int synth_alloc_pages(struct snd_trident *hw, struct snd_util_memblk *blk);
-static int synth_free_pages(struct snd_trident *hw, struct snd_util_memblk *blk);
-
-/*
- * allocate a synth sample area
- */
-struct snd_util_memblk *
-snd_trident_synth_alloc(struct snd_trident *hw, unsigned int size)
-{
-       struct snd_util_memblk *blk;
-       struct snd_util_memhdr *hdr = hw->tlb.memhdr; 
-
-       mutex_lock(&hdr->block_mutex);
-       blk = __snd_util_mem_alloc(hdr, size);
-       if (blk == NULL) {
-               mutex_unlock(&hdr->block_mutex);
-               return NULL;
-       }
-       if (synth_alloc_pages(hw, blk)) {
-               __snd_util_mem_free(hdr, blk);
-               mutex_unlock(&hdr->block_mutex);
-               return NULL;
-       }
-       mutex_unlock(&hdr->block_mutex);
-       return blk;
-}
-
-EXPORT_SYMBOL(snd_trident_synth_alloc);
-
-/*
- * free a synth sample area
- */
-int
-snd_trident_synth_free(struct snd_trident *hw, struct snd_util_memblk *blk)
-{
-       struct snd_util_memhdr *hdr = hw->tlb.memhdr; 
-
-       mutex_lock(&hdr->block_mutex);
-       synth_free_pages(hw, blk);
-        __snd_util_mem_free(hdr, blk);
-       mutex_unlock(&hdr->block_mutex);
-       return 0;
-}
-
-EXPORT_SYMBOL(snd_trident_synth_free);
-
-/*
- * reset TLB entry and free kernel page
- */
-static void clear_tlb(struct snd_trident *trident, int page)
-{
-       void *ptr = page_to_ptr(trident, page);
-       dma_addr_t addr = page_to_addr(trident, page);
-       set_silent_tlb(trident, page);
-       if (ptr) {
-               struct snd_dma_buffer dmab;
-               dmab.dev.type = SNDRV_DMA_TYPE_DEV;
-               dmab.dev.dev = snd_dma_pci_data(trident->pci);
-               dmab.area = ptr;
-               dmab.addr = addr;
-               dmab.bytes = ALIGN_PAGE_SIZE;
-               snd_dma_free_pages(&dmab);
-       }
-}
-
-/* check new allocation range */
-static void get_single_page_range(struct snd_util_memhdr *hdr,
-                                 struct snd_util_memblk *blk,
-                                 int *first_page_ret, int *last_page_ret)
-{
-       struct list_head *p;
-       struct snd_util_memblk *q;
-       int first_page, last_page;
-       first_page = firstpg(blk);
-       if ((p = blk->list.prev) != &hdr->block) {
-               q = list_entry(p, struct snd_util_memblk, list);
-               if (lastpg(q) == first_page)
-                       first_page++;  /* first page was already allocated */
-       }
-       last_page = lastpg(blk);
-       if ((p = blk->list.next) != &hdr->block) {
-               q = list_entry(p, struct snd_util_memblk, list);
-               if (firstpg(q) == last_page)
-                       last_page--; /* last page was already allocated */
-       }
-       *first_page_ret = first_page;
-       *last_page_ret = last_page;
-}
-
-/*
- * allocate kernel pages and assign them to TLB
- */
-static int synth_alloc_pages(struct snd_trident *hw, struct snd_util_memblk *blk)
-{
-       int page, first_page, last_page;
-       struct snd_dma_buffer dmab;
-
-       firstpg(blk) = get_aligned_page(blk->offset);
-       lastpg(blk) = get_aligned_page(blk->offset + blk->size - 1);
-       get_single_page_range(hw->tlb.memhdr, blk, &first_page, &last_page);
-
-       /* allocate a kernel page for each Trident page -
-        * fortunately Trident page size and kernel PAGE_SIZE is identical!
-        */
-       for (page = first_page; page <= last_page; page++) {
-               if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(hw->pci),
-                                       ALIGN_PAGE_SIZE, &dmab) < 0)
-                       goto __fail;
-               if (! is_valid_page(dmab.addr)) {
-                       snd_dma_free_pages(&dmab);
-                       goto __fail;
-               }
-               set_tlb_bus(hw, page, (unsigned long)dmab.area, dmab.addr);
-       }
-       return 0;
-
-__fail:
-       /* release allocated pages */
-       last_page = page - 1;
-       for (page = first_page; page <= last_page; page++)
-               clear_tlb(hw, page);
-
-       return -ENOMEM;
-}
-
-/*
- * free pages
- */
-static int synth_free_pages(struct snd_trident *trident, struct snd_util_memblk *blk)
-{
-       int page, first_page, last_page;
-
-       get_single_page_range(trident->tlb.memhdr, blk, &first_page, &last_page);
-       for (page = first_page; page <= last_page; page++)
-               clear_tlb(trident, page);
-
-       return 0;
-}
-
-/*
- * copy_from_user(blk + offset, data, size)
- */
-int snd_trident_synth_copy_from_user(struct snd_trident *trident,
-                                    struct snd_util_memblk *blk,
-                                    int offset, const char __user *data, int size)
-{
-       int page, nextofs, end_offset, temp, temp1;
-
-       offset += blk->offset;
-       end_offset = offset + size;
-       page = get_aligned_page(offset) + 1;
-       do {
-               nextofs = aligned_page_offset(page);
-               temp = nextofs - offset;
-               temp1 = end_offset - offset;
-               if (temp1 < temp)
-                       temp = temp1;
-               if (copy_from_user(offset_ptr(trident, offset), data, temp))
-                       return -EFAULT;
-               offset = nextofs;
-               data += temp;
-               page++;
-       } while (offset < end_offset);
-       return 0;
-}
-
-EXPORT_SYMBOL(snd_trident_synth_copy_from_user);
index b585cc3..6781be9 100644 (file)
@@ -1756,6 +1756,12 @@ static struct ac97_quirk ac97_quirks[] = {
                .name = "ECS L7VMM2",
                .type = AC97_TUNE_HP_ONLY
        },
+       {
+               .subvendor = 0x1019,
+               .subdevice = 0x1841,
+               .name = "ECS K7VTA3",
+               .type = AC97_TUNE_HP_ONLY
+       },
        {
                .subvendor = 0x1849,
                .subdevice = 0x3059,
index 29b3056..7129df5 100644 (file)
@@ -2205,6 +2205,7 @@ static int __devinit snd_ymfpci_memalloc(struct snd_ymfpci *chip)
        for (reg = 0x80; reg < 0xc0; reg += 4)
                snd_ymfpci_writel(chip, reg, 0);
        snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x3fff3fff);
+       snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0x3fff3fff);
        snd_ymfpci_writel(chip, YDSXGR_ZVOUTVOL, 0x3fff3fff);
        snd_ymfpci_writel(chip, YDSXGR_SPDIFOUTVOL, 0x3fff3fff);
        snd_ymfpci_writel(chip, YDSXGR_NATIVEADCINVOL, 0x3fff3fff);
@@ -2324,6 +2325,7 @@ int snd_ymfpci_suspend(struct pci_dev *pci, pm_message_t state)
                chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]);
        chip->saved_ydsxgr_mode = snd_ymfpci_readl(chip, YDSXGR_MODE);
        snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0);
+       snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0);
        snd_ymfpci_disable_dsp(chip);
        pci_disable_device(pci);
        pci_save_state(pci);
index c9fa1a2..7fbb190 100644 (file)
@@ -1,11 +1,16 @@
 # ALSA PCMCIA drivers
 
-menu "PCMCIA devices"
-       depends on SND!=n && PCMCIA
+menuconfig SND_PCMCIA
+       bool "PCMCIA sound devices"
+       depends on PCMCIA
+       default y
+       help
+         Support for sound devices connected via the PCMCIA bus.
+
+if SND_PCMCIA && PCMCIA
 
 config SND_VXPOCKET
        tristate "Digigram VXpocket"
-       depends on SND && PCMCIA
        select SND_VX_LIB
        help
          Say Y here to include support for Digigram VXpocket and
@@ -16,7 +21,6 @@ config SND_VXPOCKET
 
 config SND_PDAUDIOCF
        tristate "Sound Core PDAudioCF"
-       depends on SND && PCMCIA
        select SND_PCM
        help
          Say Y here to include support for Sound Core PDAudioCF
@@ -25,4 +29,5 @@ config SND_PDAUDIOCF
          To compile this driver as a module, choose M here: the module
          will be called snd-pdaudiocf.
 
-endmenu
+endif  # SND_PCMCIA
+
index 157b0b5..99bf2a6 100644 (file)
@@ -151,7 +151,7 @@ static int vxp_load_xilinx_binary(struct vx_core *_chip, const struct firmware *
        unsigned int i;
        int c;
        int regCSUER, regRUER;
-       unsigned char *image;
+       const unsigned char *image;
        unsigned char data;
 
        /* Switch to programmation mode */
index cacb0b1..777de2b 100644 (file)
@@ -1,17 +1,17 @@
 # ALSA PowerMac drivers
 
-menu "ALSA PowerMac devices"
-       depends on SND!=n && PPC
-
-comment "ALSA PowerMac requires I2C"
-       depends on SND && I2C=n
+menuconfig SND_PPC
+       bool "PowerPC sound devices"
+       depends on PPC64 || PPC32
+       default y
+       help
+         Support for sound devices specific to PowerPC architectures.
 
-comment "ALSA PowerMac requires INPUT"
-       depends on SND && INPUT=n
+if SND_PPC
 
 config SND_POWERMAC
        tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)"
-       depends on SND && I2C && INPUT && PPC_PMAC
+       depends on I2C && INPUT && PPC_PMAC
        select SND_PCM
        help
          Say Y here to include support for the integrated sound device.
@@ -32,14 +32,9 @@ config SND_POWERMAC_AUTO_DRC
          Note that you can turn on/off DRC manually even without this
          option.
 
-endmenu
-
-menu "ALSA PowerPC devices"
-       depends on SND!=n && ( PPC64 || PPC32 )
-
 config SND_PS3
        tristate "PS3 Audio support"
-       depends on SND && PS3_PS3AV
+       depends on PS3_PS3AV
        select SND_PCM
        default m
        help
@@ -52,4 +47,5 @@ config SND_PS3_DEFAULT_START_DELAY
        int "Startup delay time in ms"
        depends on SND_PS3
        default "2000"
-endmenu
+
+endif  # SND_PPC
index ca94529..8a5b290 100644 (file)
@@ -249,9 +249,7 @@ int __init snd_pmac_daca_init(struct snd_pmac *chip)
        int i, err;
        struct pmac_daca *mix;
 
-#ifdef CONFIG_KMOD
        request_module("i2c-powermac");
-#endif /* CONFIG_KMOD */
 
        mix = kzalloc(sizeof(*mix), GFP_KERNEL);
        if (! mix)
index 3f8d716..009df8d 100644 (file)
@@ -1350,9 +1350,7 @@ int __init snd_pmac_tumbler_init(struct snd_pmac *chip)
        struct device_node *tas_node, *np;
        char *chipname;
 
-#ifdef CONFIG_KMOD
        request_module("i2c-powermac");
-#endif /* CONFIG_KMOD */
 
        mix = kzalloc(sizeof(*mix), GFP_KERNEL);
        if (! mix)
index b7e08ef..cfc1439 100644 (file)
@@ -1,14 +1,22 @@
 # ALSA SH drivers
 
-menu "SUPERH devices"
-       depends on SND!=n && SUPERH
+menuconfig SND_SUPERH
+       bool "SUPERH sound devices"
+       depends on SUPERH
+       default y
+       help
+         Support for sound devices specific to SUPERH architectures.
+         Drivers that are implemented on ASoC can be found in
+         "ALSA for SoC audio support" section.
+
+if SND_SUPERH
 
 config SND_AICA
        tristate "Dreamcast Yamaha AICA sound"
-       depends on SH_DREAMCAST && SND
+       depends on SH_DREAMCAST
        select SND_PCM
        help
          ALSA Sound driver for the SEGA Dreamcast console.
 
-endmenu
+endif  # SND_SUPERH
 
index 18f28ac..f743530 100644 (file)
@@ -2,15 +2,8 @@
 # SoC audio configuration
 #
 
-menu "System on Chip audio support"
-       depends on SND!=n
-
-config SND_SOC_AC97_BUS
-       bool
-
-config SND_SOC
+menuconfig SND_SOC
        tristate "ALSA for SoC audio support"
-       depends on SND
        select SND_PCM
        ---help---
 
@@ -23,8 +16,15 @@ config SND_SOC
          This ASoC audio support can also be built as a module.  If so, the module
          will be called snd-soc-core.
 
+if SND_SOC
+
+config SND_SOC_AC97_BUS
+       bool
+
 # All the supported Soc's
+source "sound/soc/at32/Kconfig"
 source "sound/soc/at91/Kconfig"
+source "sound/soc/au1x/Kconfig"
 source "sound/soc/pxa/Kconfig"
 source "sound/soc/s3c24xx/Kconfig"
 source "sound/soc/sh/Kconfig"
@@ -35,4 +35,5 @@ source "sound/soc/omap/Kconfig"
 # Supported codecs
 source "sound/soc/codecs/Kconfig"
 
-endmenu
+endif  # SND_SOC
+
index 782db21..933a66d 100644 (file)
@@ -1,4 +1,5 @@
 snd-soc-core-objs := soc-core.o soc-dapm.o
 
 obj-$(CONFIG_SND_SOC)  += snd-soc-core.o
-obj-$(CONFIG_SND_SOC)  += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/ omap/
+obj-$(CONFIG_SND_SOC)  += codecs/ at32/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/
+obj-$(CONFIG_SND_SOC)  += omap/ au1x/
diff --git a/sound/soc/at32/Kconfig b/sound/soc/at32/Kconfig
new file mode 100644 (file)
index 0000000..b0765e8
--- /dev/null
@@ -0,0 +1,34 @@
+config SND_AT32_SOC
+        tristate "SoC Audio for the Atmel AT32 System-on-a-Chip"
+        depends on AVR32 && SND_SOC
+        help
+          Say Y or M if you want to add support for codecs attached to 
+          the AT32 SSC interface.  You will also need to
+          to select the audio interfaces to support below.
+
+
+config SND_AT32_SOC_SSC
+        tristate
+
+
+
+config SND_AT32_SOC_PLAYPAQ
+        tristate "SoC Audio support for PlayPaq with WM8510"
+        depends on SND_AT32_SOC && BOARD_PLAYPAQ
+        select SND_AT32_SOC_SSC
+        select SND_SOC_WM8510
+        help
+          Say Y or M here if you want to add support for SoC audio
+          on the LRS PlayPaq.
+
+
+
+config SND_AT32_SOC_PLAYPAQ_SLAVE
+        bool "Run CODEC on PlayPaq in slave mode"
+        depends on SND_AT32_SOC_PLAYPAQ
+        default n
+        help
+          Say Y if you want to run with the AT32 SSC generating the BCLK
+          and FRAME signals on the PlayPaq.  Unless you want to play
+          with the AT32 as the SSC master, you probably want to say N here,
+          as this will give you better sound quality.
diff --git a/sound/soc/at32/Makefile b/sound/soc/at32/Makefile
new file mode 100644 (file)
index 0000000..c03e55e
--- /dev/null
@@ -0,0 +1,11 @@
+# AT32 Platform Support
+snd-soc-at32-objs := at32-pcm.o
+snd-soc-at32-ssc-objs := at32-ssc.o
+
+obj-$(CONFIG_SND_AT32_SOC) += snd-soc-at32.o
+obj-$(CONFIG_SND_AT32_SOC_SSC) += snd-soc-at32-ssc.o
+
+# AT32 Machine Support
+snd-soc-playpaq-objs := playpaq_wm8510.o
+
+obj-$(CONFIG_SND_AT32_SOC_PLAYPAQ) += snd-soc-playpaq.o
diff --git a/sound/soc/at32/at32-pcm.c b/sound/soc/at32/at32-pcm.c
new file mode 100644 (file)
index 0000000..435f1da
--- /dev/null
@@ -0,0 +1,491 @@
+/* sound/soc/at32/at32-pcm.c
+ * ASoC PCM interface for Atmel AT32 SoC
+ *
+ * Copyright (C) 2008 Long Range Systems
+ *    Geoffrey Wossum <gwossum@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Note that this is basically a port of the sound/soc/at91-pcm.c to
+ * the AVR32 kernel.  Thanks to Frank Mandarino for that code.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/atmel_pdc.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "at32-pcm.h"
+
+
+
+/*--------------------------------------------------------------------------*\
+ * Hardware definition
+\*--------------------------------------------------------------------------*/
+/* TODO: These values were taken from the AT91 platform driver, check
+ *      them against real values for AT32
+ */
+static const struct snd_pcm_hardware at32_pcm_hardware = {
+       .info = (SNDRV_PCM_INFO_MMAP |
+                SNDRV_PCM_INFO_MMAP_VALID |
+                SNDRV_PCM_INFO_INTERLEAVED |
+                SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                SNDRV_PCM_INFO_PAUSE),
+
+       .formats = SNDRV_PCM_FMTBIT_S16,
+       .period_bytes_min = 32,
+       .period_bytes_max = 8192,       /* 512 frames * 16 bytes / frame */
+       .periods_min = 2,
+       .periods_max = 1024,
+       .buffer_bytes_max = 32 * 1024,
+};
+
+
+
+/*--------------------------------------------------------------------------*\
+ * Data types
+\*--------------------------------------------------------------------------*/
+struct at32_runtime_data {
+       struct at32_pcm_dma_params *params;
+       dma_addr_t dma_buffer;  /* physical address of DMA buffer */
+       dma_addr_t dma_buffer_end; /* first address beyond DMA buffer */
+       size_t period_size;
+
+       dma_addr_t period_ptr;  /* physical address of next period */
+       int periods;            /* period index of period_ptr */
+
+       /* Save PDC registers (for power management) */
+       u32 pdc_xpr_save;
+       u32 pdc_xcr_save;
+       u32 pdc_xnpr_save;
+       u32 pdc_xncr_save;
+};
+
+
+
+/*--------------------------------------------------------------------------*\
+ * Helper functions
+\*--------------------------------------------------------------------------*/
+static int at32_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
+{
+       struct snd_pcm_substream *substream = pcm->streams[stream].substream;
+       struct snd_dma_buffer *dmabuf = &substream->dma_buffer;
+       size_t size = at32_pcm_hardware.buffer_bytes_max;
+
+       dmabuf->dev.type = SNDRV_DMA_TYPE_DEV;
+       dmabuf->dev.dev = pcm->card->dev;
+       dmabuf->private_data = NULL;
+       dmabuf->area = dma_alloc_coherent(pcm->card->dev, size,
+                                         &dmabuf->addr, GFP_KERNEL);
+       pr_debug("at32_pcm: preallocate_dma_buffer: "
+                "area=%p, addr=%p, size=%ld\n",
+                (void *)dmabuf->area, (void *)dmabuf->addr, size);
+
+       if (!dmabuf->area)
+               return -ENOMEM;
+
+       dmabuf->bytes = size;
+       return 0;
+}
+
+
+
+/*--------------------------------------------------------------------------*\
+ * ISR
+\*--------------------------------------------------------------------------*/
+static void at32_pcm_dma_irq(u32 ssc_sr, struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *rtd = substream->runtime;
+       struct at32_runtime_data *prtd = rtd->private_data;
+       struct at32_pcm_dma_params *params = prtd->params;
+       static int count;
+
+       count++;
+       if (ssc_sr & params->mask->ssc_endbuf) {
+               pr_warning("at32-pcm: buffer %s on %s (SSC_SR=%#x, count=%d)\n",
+                          substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
+                          "underrun" : "overrun", params->name, ssc_sr, count);
+
+               /* re-start the PDC */
+               ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR,
+                          params->mask->pdc_disable);
+               prtd->period_ptr += prtd->period_size;
+               if (prtd->period_ptr >= prtd->dma_buffer_end)
+                       prtd->period_ptr = prtd->dma_buffer;
+
+
+               ssc_writex(params->ssc->regs, params->pdc->xpr,
+                          prtd->period_ptr);
+               ssc_writex(params->ssc->regs, params->pdc->xcr,
+                          prtd->period_size / params->pdc_xfer_size);
+               ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR,
+                          params->mask->pdc_enable);
+       }
+
+
+       if (ssc_sr & params->mask->ssc_endx) {
+               /* Load the PDC next pointer and counter registers */
+               prtd->period_ptr += prtd->period_size;
+               if (prtd->period_ptr >= prtd->dma_buffer_end)
+                       prtd->period_ptr = prtd->dma_buffer;
+               ssc_writex(params->ssc->regs, params->pdc->xnpr,
+                          prtd->period_ptr);
+               ssc_writex(params->ssc->regs, params->pdc->xncr,
+                          prtd->period_size / params->pdc_xfer_size);
+       }
+
+
+       snd_pcm_period_elapsed(substream);
+}
+
+
+
+/*--------------------------------------------------------------------------*\
+ * PCM operations
+\*--------------------------------------------------------------------------*/
+static int at32_pcm_hw_params(struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *params)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct at32_runtime_data *prtd = runtime->private_data;
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+
+       /* this may get called several times by oss emulation
+        * with different params
+        */
+       snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+       runtime->dma_bytes = params_buffer_bytes(params);
+
+       prtd->params = rtd->dai->cpu_dai->dma_data;
+       prtd->params->dma_intr_handler = at32_pcm_dma_irq;
+
+       prtd->dma_buffer = runtime->dma_addr;
+       prtd->dma_buffer_end = runtime->dma_addr + runtime->dma_bytes;
+       prtd->period_size = params_period_bytes(params);
+
+       pr_debug("hw_params: DMA for %s initialized "
+                "(dma_bytes=%ld, period_size=%ld)\n",
+                prtd->params->name, runtime->dma_bytes, prtd->period_size);
+
+       return 0;
+}
+
+
+
+static int at32_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       struct at32_runtime_data *prtd = substream->runtime->private_data;
+       struct at32_pcm_dma_params *params = prtd->params;
+
+       if (params != NULL) {
+               ssc_writex(params->ssc->regs, SSC_PDC_PTCR,
+                          params->mask->pdc_disable);
+               prtd->params->dma_intr_handler = NULL;
+       }
+
+       return 0;
+}
+
+
+
+static int at32_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct at32_runtime_data *prtd = substream->runtime->private_data;
+       struct at32_pcm_dma_params *params = prtd->params;
+
+       ssc_writex(params->ssc->regs, SSC_IDR,
+                  params->mask->ssc_endx | params->mask->ssc_endbuf);
+       ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR,
+                  params->mask->pdc_disable);
+
+       return 0;
+}
+
+
+static int at32_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_pcm_runtime *rtd = substream->runtime;
+       struct at32_runtime_data *prtd = rtd->private_data;
+       struct at32_pcm_dma_params *params = prtd->params;
+       int ret = 0;
+
+       pr_debug("at32_pcm_trigger: buffer_size = %ld, "
+                "dma_area = %p, dma_bytes = %ld\n",
+                rtd->buffer_size, rtd->dma_area, rtd->dma_bytes);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               prtd->period_ptr = prtd->dma_buffer;
+
+               ssc_writex(params->ssc->regs, params->pdc->xpr,
+                          prtd->period_ptr);
+               ssc_writex(params->ssc->regs, params->pdc->xcr,
+                          prtd->period_size / params->pdc_xfer_size);
+
+               prtd->period_ptr += prtd->period_size;
+               ssc_writex(params->ssc->regs, params->pdc->xnpr,
+                          prtd->period_ptr);
+               ssc_writex(params->ssc->regs, params->pdc->xncr,
+                          prtd->period_size / params->pdc_xfer_size);
+
+               pr_debug("trigger: period_ptr=%lx, xpr=%x, "
+                        "xcr=%d, xnpr=%x, xncr=%d\n",
+                        (unsigned long)prtd->period_ptr,
+                        ssc_readx(params->ssc->regs, params->pdc->xpr),
+                        ssc_readx(params->ssc->regs, params->pdc->xcr),
+                        ssc_readx(params->ssc->regs, params->pdc->xnpr),
+                        ssc_readx(params->ssc->regs, params->pdc->xncr));
+
+               ssc_writex(params->ssc->regs, SSC_IER,
+                          params->mask->ssc_endx | params->mask->ssc_endbuf);
+               ssc_writex(params->ssc->regs, SSC_PDC_PTCR,
+                          params->mask->pdc_enable);
+
+               pr_debug("sr=%x, imr=%x\n",
+                        ssc_readx(params->ssc->regs, SSC_SR),
+                        ssc_readx(params->ssc->regs, SSC_IER));
+               break;          /* SNDRV_PCM_TRIGGER_START */
+
+
+
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR,
+                          params->mask->pdc_disable);
+               break;
+
+
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR,
+                          params->mask->pdc_enable);
+               break;
+
+       default:
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+
+
+static snd_pcm_uframes_t at32_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct at32_runtime_data *prtd = runtime->private_data;
+       struct at32_pcm_dma_params *params = prtd->params;
+       dma_addr_t ptr;
+       snd_pcm_uframes_t x;
+
+       ptr = (dma_addr_t) ssc_readx(params->ssc->regs, params->pdc->xpr);
+       x = bytes_to_frames(runtime, ptr - prtd->dma_buffer);
+
+       if (x == runtime->buffer_size)
+               x = 0;
+
+       return x;
+}
+
+
+
+static int at32_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct at32_runtime_data *prtd;
+       int ret = 0;
+
+       snd_soc_set_runtime_hwparams(substream, &at32_pcm_hardware);
+
+       /* ensure that buffer size is a multiple of period size */
+       ret = snd_pcm_hw_constraint_integer(runtime,
+                                           SNDRV_PCM_HW_PARAM_PERIODS);
+       if (ret < 0)
+               goto out;
+
+       prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
+       if (prtd == NULL) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       runtime->private_data = prtd;
+
+
+out:
+       return ret;
+}
+
+
+
+static int at32_pcm_close(struct snd_pcm_substream *substream)
+{
+       struct at32_runtime_data *prtd = substream->runtime->private_data;
+
+       kfree(prtd);
+       return 0;
+}
+
+
+static int at32_pcm_mmap(struct snd_pcm_substream *substream,
+                        struct vm_area_struct *vma)
+{
+       return remap_pfn_range(vma, vma->vm_start,
+                              substream->dma_buffer.addr >> PAGE_SHIFT,
+                              vma->vm_end - vma->vm_start, vma->vm_page_prot);
+}
+
+
+
+static struct snd_pcm_ops at32_pcm_ops = {
+       .open = at32_pcm_open,
+       .close = at32_pcm_close,
+       .ioctl = snd_pcm_lib_ioctl,
+       .hw_params = at32_pcm_hw_params,
+       .hw_free = at32_pcm_hw_free,
+       .prepare = at32_pcm_prepare,
+       .trigger = at32_pcm_trigger,
+       .pointer = at32_pcm_pointer,
+       .mmap = at32_pcm_mmap,
+};
+
+
+
+/*--------------------------------------------------------------------------*\
+ * ASoC platform driver
+\*--------------------------------------------------------------------------*/
+static u64 at32_pcm_dmamask = 0xffffffff;
+
+static int at32_pcm_new(struct snd_card *card,
+                       struct snd_soc_dai *dai,
+                       struct snd_pcm *pcm)
+{
+       int ret = 0;
+
+       if (!card->dev->dma_mask)
+               card->dev->dma_mask = &at32_pcm_dmamask;
+       if (!card->dev->coherent_dma_mask)
+               card->dev->coherent_dma_mask = 0xffffffff;
+
+       if (dai->playback.channels_min) {
+               ret = at32_pcm_preallocate_dma_buffer(
+                         pcm, SNDRV_PCM_STREAM_PLAYBACK);
+               if (ret)
+                       goto out;
+       }
+
+       if (dai->capture.channels_min) {
+               pr_debug("at32-pcm: Allocating PCM capture DMA buffer\n");
+               ret = at32_pcm_preallocate_dma_buffer(
+                         pcm, SNDRV_PCM_STREAM_CAPTURE);
+               if (ret)
+                       goto out;
+       }
+
+
+out:
+       return ret;
+}
+
+
+
+static void at32_pcm_free_dma_buffers(struct snd_pcm *pcm)
+{
+       struct snd_pcm_substream *substream;
+       struct snd_dma_buffer *buf;
+       int stream;
+
+       for (stream = 0; stream < 2; stream++) {
+               substream = pcm->streams[stream].substream;
+               if (substream == NULL)
+                       continue;
+
+               buf = &substream->dma_buffer;
+               if (!buf->area)
+                       continue;
+               dma_free_coherent(pcm->card->dev, buf->bytes,
+                                 buf->area, buf->addr);
+               buf->area = NULL;
+       }
+}
+
+
+
+#ifdef CONFIG_PM
+static int at32_pcm_suspend(struct platform_device *pdev,
+                           struct snd_soc_dai *dai)
+{
+       struct snd_pcm_runtime *runtime = dai->runtime;
+       struct at32_runtime_data *prtd;
+       struct at32_pcm_dma_params *params;
+
+       if (runtime == NULL)
+               return 0;
+       prtd = runtime->private_data;
+       params = prtd->params;
+
+       /* Disable the PDC and save the PDC registers */
+       ssc_writex(params->ssc->regs, PDC_PTCR, params->mask->pdc_disable);
+
+       prtd->pdc_xpr_save = ssc_readx(params->ssc->regs, params->pdc->xpr);
+       prtd->pdc_xcr_save = ssc_readx(params->ssc->regs, params->pdc->xcr);
+       prtd->pdc_xnpr_save = ssc_readx(params->ssc->regs, params->pdc->xnpr);
+       prtd->pdc_xncr_save = ssc_readx(params->ssc->regs, params->pdc->xncr);
+
+       return 0;
+}
+
+
+
+static int at32_pcm_resume(struct platform_device *pdev,
+                          struct snd_soc_dai *dai)
+{
+       struct snd_pcm_runtime *runtime = dai->runtime;
+       struct at32_runtime_data *prtd;
+       struct at32_pcm_dma_params *params;
+
+       if (runtime == NULL)
+               return 0;
+       prtd = runtime->private_data;
+       params = prtd->params;
+
+       /* Restore the PDC registers and enable the PDC */
+       ssc_writex(params->ssc->regs, params->pdc->xpr, prtd->pdc_xpr_save);
+       ssc_writex(params->ssc->regs, params->pdc->xcr, prtd->pdc_xcr_save);
+       ssc_writex(params->ssc->regs, params->pdc->xnpr, prtd->pdc_xnpr_save);
+       ssc_writex(params->ssc->regs, params->pdc->xncr, prtd->pdc_xncr_save);
+
+       ssc_writex(params->ssc->regs, PDC_PTCR, params->mask->pdc_enable);
+       return 0;
+}
+#else /* CONFIG_PM */
+#  define at32_pcm_suspend     NULL
+#  define at32_pcm_resume      NULL
+#endif /* CONFIG_PM */
+
+
+
+struct snd_soc_platform at32_soc_platform = {
+       .name = "at32-audio",
+       .pcm_ops = &at32_pcm_ops,
+       .pcm_new = at32_pcm_new,
+       .pcm_free = at32_pcm_free_dma_buffers,
+       .suspend = at32_pcm_suspend,
+       .resume = at32_pcm_resume,
+};
+EXPORT_SYMBOL_GPL(at32_soc_platform);
+
+
+
+MODULE_AUTHOR("Geoffrey Wossum <gwossum@acm.org>");
+MODULE_DESCRIPTION("Atmel AT32 PCM module");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/at32/at32-pcm.h b/sound/soc/at32/at32-pcm.h
new file mode 100644 (file)
index 0000000..2a52430
--- /dev/null
@@ -0,0 +1,79 @@
+/* sound/soc/at32/at32-pcm.h
+ * ASoC PCM interface for Atmel AT32 SoC
+ *
+ * Copyright (C) 2008 Long Range Systems
+ *    Geoffrey Wossum <gwossum@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __SOUND_SOC_AT32_AT32_PCM_H
+#define __SOUND_SOC_AT32_AT32_PCM_H __FILE__
+
+#include <linux/atmel-ssc.h>
+
+
+/*
+ * Registers and status bits that are required by the PCM driver
+ * TODO: Is ptcr really used?
+ */
+struct at32_pdc_regs {
+       u32 xpr;                /* PDC RX/TX pointer */
+       u32 xcr;                /* PDC RX/TX counter */
+       u32 xnpr;               /* PDC next RX/TX pointer */
+       u32 xncr;               /* PDC next RX/TX counter */
+       u32 ptcr;               /* PDC transfer control */
+};
+
+
+
+/*
+ * SSC mask info
+ */
+struct at32_ssc_mask {
+       u32 ssc_enable;         /* SSC RX/TX enable */
+       u32 ssc_disable;        /* SSC RX/TX disable */
+       u32 ssc_endx;           /* SSC ENDTX or ENDRX */
+       u32 ssc_endbuf;         /* SSC TXBUFF or RXBUFF */
+       u32 pdc_enable;         /* PDC RX/TX enable */
+       u32 pdc_disable;        /* PDC RX/TX disable */
+};
+
+
+
+/*
+ * This structure, shared between the PCM driver and the interface,
+ * contains all information required by the PCM driver to perform the
+ * PDC DMA operation.  All fields except dma_intr_handler() are initialized
+ * by the interface.  The dms_intr_handler() pointer is set by the PCM
+ * driver and called by the interface SSC interrupt handler if it is
+ * non-NULL.
+ */
+struct at32_pcm_dma_params {
+       char *name;             /* stream identifier */
+       int pdc_xfer_size;      /* PDC counter increment in bytes */
+       struct ssc_device *ssc; /* SSC device for stream */
+       struct at32_pdc_regs *pdc;      /* PDC register info */
+       struct at32_ssc_mask *mask;     /* SSC mask info */
+       struct snd_pcm_substream *substream;
+       void (*dma_intr_handler) (u32, struct snd_pcm_substream *);
+};
+
+
+
+/*
+ * The AT32 ASoC platform driver
+ */
+extern struct snd_soc_platform at32_soc_platform;
+
+
+
+/*
+ * SSC register access (since ssc_writel() / ssc_readl() require literal name)
+ */
+#define ssc_readx(base, reg)            (__raw_readl((base) + (reg)))
+#define ssc_writex(base, reg, value)    __raw_writel((value), (base) + (reg))
+
+#endif /* __SOUND_SOC_AT32_AT32_PCM_H */
diff --git a/sound/soc/at32/at32-ssc.c b/sound/soc/at32/at32-ssc.c
new file mode 100644 (file)
index 0000000..4ef6492
--- /dev/null
@@ -0,0 +1,849 @@
+/* sound/soc/at32/at32-ssc.c
+ * ASoC platform driver for AT32 using SSC as DAI
+ *
+ * Copyright (C) 2008 Long Range Systems
+ *    Geoffrey Wossum <gwossum@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Note that this is basically a port of the sound/soc/at91-ssc.c to
+ * the AVR32 kernel.  Thanks to Frank Mandarino for that code.
+ */
+
+/* #define DEBUG */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/atmel_pdc.h>
+#include <linux/atmel-ssc.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include "at32-pcm.h"
+#include "at32-ssc.h"
+
+
+
+/*-------------------------------------------------------------------------*\
+ * Constants
+\*-------------------------------------------------------------------------*/
+#define NUM_SSC_DEVICES                3
+
+/*
+ * SSC direction masks
+ */
+#define SSC_DIR_MASK_UNUSED    0
+#define SSC_DIR_MASK_PLAYBACK  1
+#define SSC_DIR_MASK_CAPTURE   2
+
+/*
+ * SSC register values that Atmel left out of <linux/atmel-ssc.h>.  These
+ * are expected to be used with SSC_BF
+ */
+/* START bit field values */
+#define SSC_START_CONTINUOUS   0
+#define SSC_START_TX_RX                1
+#define SSC_START_LOW_RF       2
+#define SSC_START_HIGH_RF      3
+#define SSC_START_FALLING_RF   4
+#define SSC_START_RISING_RF    5
+#define SSC_START_LEVEL_RF     6
+#define SSC_START_EDGE_RF      7
+#define SSS_START_COMPARE_0    8
+
+/* CKI bit field values */
+#define SSC_CKI_FALLING                0
+#define SSC_CKI_RISING         1
+
+/* CKO bit field values */
+#define SSC_CKO_NONE           0
+#define SSC_CKO_CONTINUOUS     1
+#define SSC_CKO_TRANSFER       2
+
+/* CKS bit field values */
+#define SSC_CKS_DIV            0
+#define SSC_CKS_CLOCK          1
+#define SSC_CKS_PIN            2
+
+/* FSEDGE bit field values */
+#define SSC_FSEDGE_POSITIVE    0
+#define SSC_FSEDGE_NEGATIVE    1
+
+/* FSOS bit field values */
+#define SSC_FSOS_NONE          0
+#define SSC_FSOS_NEGATIVE      1
+#define SSC_FSOS_POSITIVE      2
+#define SSC_FSOS_LOW           3
+#define SSC_FSOS_HIGH          4
+#define SSC_FSOS_TOGGLE                5
+
+#define START_DELAY            1
+
+
+
+/*-------------------------------------------------------------------------*\
+ * Module data
+\*-------------------------------------------------------------------------*/
+/*
+ * SSC PDC registered required by the PCM DMA engine
+ */
+static struct at32_pdc_regs pdc_tx_reg = {
+       .xpr = SSC_PDC_TPR,
+       .xcr = SSC_PDC_TCR,
+       .xnpr = SSC_PDC_TNPR,
+       .xncr = SSC_PDC_TNCR,
+};
+
+
+
+static struct at32_pdc_regs pdc_rx_reg = {
+       .xpr = SSC_PDC_RPR,
+       .xcr = SSC_PDC_RCR,
+       .xnpr = SSC_PDC_RNPR,
+       .xncr = SSC_PDC_RNCR,
+};
+
+
+
+/*
+ * SSC and PDC status bits for transmit and receive
+ */
+static struct at32_ssc_mask ssc_tx_mask = {
+       .ssc_enable = SSC_BIT(CR_TXEN),
+       .ssc_disable = SSC_BIT(CR_TXDIS),
+       .ssc_endx = SSC_BIT(SR_ENDTX),
+       .ssc_endbuf = SSC_BIT(SR_TXBUFE),
+       .pdc_enable = SSC_BIT(PDC_PTCR_TXTEN),
+       .pdc_disable = SSC_BIT(PDC_PTCR_TXTDIS),
+};
+
+
+
+static struct at32_ssc_mask ssc_rx_mask = {
+       .ssc_enable = SSC_BIT(CR_RXEN),
+       .ssc_disable = SSC_BIT(CR_RXDIS),
+       .ssc_endx = SSC_BIT(SR_ENDRX),
+       .ssc_endbuf = SSC_BIT(SR_RXBUFF),
+       .pdc_enable = SSC_BIT(PDC_PTCR_RXTEN),
+       .pdc_disable = SSC_BIT(PDC_PTCR_RXTDIS),
+};
+
+
+
+/*
+ * DMA parameters for each SSC
+ */
+static struct at32_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
+       {
+        {
+         .name = "SSC0 PCM out",
+         .pdc = &pdc_tx_reg,
+         .mask = &ssc_tx_mask,
+         },
+        {
+         .name = "SSC0 PCM in",
+         .pdc = &pdc_rx_reg,
+         .mask = &ssc_rx_mask,
+         },
+        },
+       {
+        {
+         .name = "SSC1 PCM out",
+         .pdc = &pdc_tx_reg,
+         .mask = &ssc_tx_mask,
+         },
+        {
+         .name = "SSC1 PCM in",
+         .pdc = &pdc_rx_reg,
+         .mask = &ssc_rx_mask,
+         },
+        },
+       {
+        {
+         .name = "SSC2 PCM out",
+         .pdc = &pdc_tx_reg,
+         .mask = &ssc_tx_mask,
+         },
+        {
+         .name = "SSC2 PCM in",
+         .pdc = &pdc_rx_reg,
+         .mask = &ssc_rx_mask,
+         },
+        },
+};
+
+
+
+static struct at32_ssc_info ssc_info[NUM_SSC_DEVICES] = {
+       {
+        .name = "ssc0",
+        .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),
+        .dir_mask = SSC_DIR_MASK_UNUSED,
+        .initialized = 0,
+        },
+       {
+        .name = "ssc1",
+        .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
+        .dir_mask = SSC_DIR_MASK_UNUSED,
+        .initialized = 0,
+        },
+       {
+        .name = "ssc2",
+        .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
+        .dir_mask = SSC_DIR_MASK_UNUSED,
+        .initialized = 0,
+        },
+};
+
+
+
+
+/*-------------------------------------------------------------------------*\
+ * ISR
+\*-------------------------------------------------------------------------*/
+/*
+ * SSC interrupt handler.  Passes PDC interrupts to the DMA interrupt
+ * handler in the PCM driver.
+ */
+static irqreturn_t at32_ssc_interrupt(int irq, void *dev_id)
+{
+       struct at32_ssc_info *ssc_p = dev_id;
+       struct at32_pcm_dma_params *dma_params;
+       u32 ssc_sr;
+       u32 ssc_substream_mask;
+       int i;
+
+       ssc_sr = (ssc_readl(ssc_p->ssc->regs, SR) &
+                 ssc_readl(ssc_p->ssc->regs, IMR));
+
+       /*
+        * Loop through substreams attached to this SSC.  If a DMA-related
+        * interrupt occured on that substream, call the DMA interrupt
+        * handler function, if one has been registered in the dma_param
+        * structure by the PCM driver.
+        */
+       for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) {
+               dma_params = ssc_p->dma_params[i];
+
+               if ((dma_params != NULL) &&
+                   (dma_params->dma_intr_handler != NULL)) {
+                       ssc_substream_mask = (dma_params->mask->ssc_endx |
+                                             dma_params->mask->ssc_endbuf);
+                       if (ssc_sr & ssc_substream_mask) {
+                               dma_params->dma_intr_handler(ssc_sr,
+                                                            dma_params->
+                                                            substream);
+                       }
+               }
+       }
+
+
+       return IRQ_HANDLED;
+}
+
+/*-------------------------------------------------------------------------*\
+ * DAI functions
+\*-------------------------------------------------------------------------*/
+/*
+ * Startup.  Only that one substream allowed in each direction.
+ */
+static int at32_ssc_startup(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct at32_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id];
+       int dir_mask;
+
+       dir_mask = ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+                   SSC_DIR_MASK_PLAYBACK : SSC_DIR_MASK_CAPTURE);
+
+       spin_lock_irq(&ssc_p->lock);
+       if (ssc_p->dir_mask & dir_mask) {
+               spin_unlock_irq(&ssc_p->lock);
+               return -EBUSY;
+       }
+       ssc_p->dir_mask |= dir_mask;
+       spin_unlock_irq(&ssc_p->lock);
+
+       return 0;
+}
+
+
+
+/*
+ * Shutdown.  Clear DMA parameters and shutdown the SSC if there
+ * are no other substreams open.
+ */
+static void at32_ssc_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct at32_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id];
+       struct at32_pcm_dma_params *dma_params;
+       int dir_mask;
+
+       dma_params = ssc_p->dma_params[substream->stream];
+
+       if (dma_params != NULL) {
+               ssc_writel(dma_params->ssc->regs, CR,
+                          dma_params->mask->ssc_disable);
+               pr_debug("%s disabled SSC_SR=0x%08x\n",
+                        (substream->stream ? "receiver" : "transmit"),
+                        ssc_readl(ssc_p->ssc->regs, SR));
+
+               dma_params->ssc = NULL;
+               dma_params->substream = NULL;
+               ssc_p->dma_params[substream->stream] = NULL;
+       }
+
+
+       dir_mask = 1 << substream->stream;
+       spin_lock_irq(&ssc_p->lock);
+       ssc_p->dir_mask &= ~dir_mask;
+       if (!ssc_p->dir_mask) {
+               /* Shutdown the SSC clock */
+               pr_debug("at32-ssc: Stopping user %d clock\n",
+                        ssc_p->ssc->user);
+               clk_disable(ssc_p->ssc->clk);
+
+               if (ssc_p->initialized) {
+                       free_irq(ssc_p->ssc->irq, ssc_p);
+                       ssc_p->initialized = 0;
+               }
+
+               /* Reset the SSC */
+               ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
+
+               /* clear the SSC dividers */
+               ssc_p->cmr_div = 0;
+               ssc_p->tcmr_period = 0;
+               ssc_p->rcmr_period = 0;
+       }
+       spin_unlock_irq(&ssc_p->lock);
+}
+
+
+
+/*
+ * Set the SSC system clock rate
+ */
+static int at32_ssc_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
+                                  int clk_id, unsigned int freq, int dir)
+{
+       /* TODO: What the heck do I do here? */
+       return 0;
+}
+
+
+
+/*
+ * Record DAI format for use by hw_params()
+ */
+static int at32_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai,
+                               unsigned int fmt)
+{
+       struct at32_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
+
+       ssc_p->daifmt = fmt;
+       return 0;
+}
+
+
+
+/*
+ * Record SSC clock dividers for use in hw_params()
+ */
+static int at32_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
+                                  int div_id, int div)
+{
+       struct at32_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
+
+       switch (div_id) {
+       case AT32_SSC_CMR_DIV:
+               /*
+                * The same master clock divider is used for both
+                * transmit and receive, so if a value has already
+                * been set, it must match this value
+                */
+               if (ssc_p->cmr_div == 0)
+                       ssc_p->cmr_div = div;
+               else if (div != ssc_p->cmr_div)
+                       return -EBUSY;
+               break;
+
+       case AT32_SSC_TCMR_PERIOD:
+               ssc_p->tcmr_period = div;
+               break;
+
+       case AT32_SSC_RCMR_PERIOD:
+               ssc_p->rcmr_period = div;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+
+
+/*
+ * Configure the SSC
+ */
+static int at32_ssc_hw_params(struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       int id = rtd->dai->cpu_dai->id;
+       struct at32_ssc_info *ssc_p = &ssc_info[id];
+       struct at32_pcm_dma_params *dma_params;
+       int channels, bits;
+       u32 tfmr, rfmr, tcmr, rcmr;
+       int start_event;
+       int ret;
+
+
+       /*
+        * Currently, there is only one set of dma_params for each direction.
+        * If more are added, this code will have to be changed to select
+        * the proper set
+        */
+       dma_params = &ssc_dma_params[id][substream->stream];
+       dma_params->ssc = ssc_p->ssc;
+       dma_params->substream = substream;
+
+       ssc_p->dma_params[substream->stream] = dma_params;
+
+
+       /*
+        * The cpu_dai->dma_data field is only used to communicate the
+        * appropriate DMA parameters to the PCM driver's hw_params()
+        * function.  It should not be used for other purposes as it
+        * is common to all substreams.
+        */
+       rtd->dai->cpu_dai->dma_data = dma_params;
+
+       channels = params_channels(params);
+
+
+       /*
+        * Determine sample size in bits and the PDC increment
+        */
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S8:
+               bits = 8;
+               dma_params->pdc_xfer_size = 1;
+               break;
+
+       case SNDRV_PCM_FORMAT_S16:
+               bits = 16;
+               dma_params->pdc_xfer_size = 2;
+               break;
+
+       case SNDRV_PCM_FORMAT_S24:
+               bits = 24;
+               dma_params->pdc_xfer_size = 4;
+               break;
+
+       case SNDRV_PCM_FORMAT_S32:
+               bits = 32;
+               dma_params->pdc_xfer_size = 4;
+               break;
+
+       default:
+               pr_warning("at32-ssc: Unsupported PCM format %d",
+                          params_format(params));
+               return -EINVAL;
+       }
+       pr_debug("at32-ssc: bits = %d, pdc_xfer_size = %d, channels = %d\n",
+                bits, dma_params->pdc_xfer_size, channels);
+
+
+       /*
+        * The SSC only supports up to 16-bit samples in I2S format, due
+        * to the size of the Frame Mode Register FSLEN field.
+        */
+       if ((ssc_p->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S)
+               if (bits > 16) {
+                       pr_warning("at32-ssc: "
+                                  "sample size %d is too large for I2S\n",
+                                  bits);
+                       return -EINVAL;
+               }
+
+
+       /*
+        * Compute the SSC register settings
+        */
+       switch (ssc_p->daifmt & (SND_SOC_DAIFMT_FORMAT_MASK |
+                                SND_SOC_DAIFMT_MASTER_MASK)) {
+       case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS:
+               /*
+                * I2S format, SSC provides BCLK and LRS clocks.
+                *
+                * The SSC transmit and receive clocks are generated from the
+                * MCK divider, and the BCLK signal is output on the SSC TK line
+                */
+               pr_debug("at32-ssc: SSC mode is I2S BCLK / FRAME master\n");
+               rcmr = (SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period) |
+                       SSC_BF(RCMR_STTDLY, START_DELAY) |
+                       SSC_BF(RCMR_START, SSC_START_FALLING_RF) |
+                       SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
+                       SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
+                       SSC_BF(RCMR_CKS, SSC_CKS_DIV));
+
+               rfmr = (SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(RFMR_FSOS, SSC_FSOS_NEGATIVE) |
+                       SSC_BF(RFMR_FSLEN, bits - 1) |
+                       SSC_BF(RFMR_DATNB, channels - 1) |
+                       SSC_BIT(RFMR_MSBF) | SSC_BF(RFMR_DATLEN, bits - 1));
+
+               tcmr = (SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period) |
+                       SSC_BF(TCMR_STTDLY, START_DELAY) |
+                       SSC_BF(TCMR_START, SSC_START_FALLING_RF) |
+                       SSC_BF(TCMR_CKI, SSC_CKI_FALLING) |
+                       SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS) |
+                       SSC_BF(TCMR_CKS, SSC_CKS_DIV));
+
+               tfmr = (SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(TFMR_FSOS, SSC_FSOS_NEGATIVE) |
+                       SSC_BF(TFMR_FSLEN, bits - 1) |
+                       SSC_BF(TFMR_DATNB, channels - 1) | SSC_BIT(TFMR_MSBF) |
+                       SSC_BF(TFMR_DATLEN, bits - 1));
+               break;
+
+
+       case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM:
+               /*
+                * I2S format, CODEC supplies BCLK and LRC clock.
+                *
+                * The SSC transmit clock is obtained from the BCLK signal
+                * on the TK line, and the SSC receive clock is generated from
+                * the transmit clock.
+                *
+                * For single channel data, one sample is transferred on the
+                * falling edge of the LRC clock.  For two channel data, one
+                * sample is transferred on both edges of the LRC clock.
+                */
+               pr_debug("at32-ssc: SSC mode is I2S BCLK / FRAME slave\n");
+               start_event = ((channels == 1) ?
+                              SSC_START_FALLING_RF : SSC_START_EDGE_RF);
+
+               rcmr = (SSC_BF(RCMR_STTDLY, START_DELAY) |
+                       SSC_BF(RCMR_START, start_event) |
+                       SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
+                       SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
+                       SSC_BF(RCMR_CKS, SSC_CKS_CLOCK));
+
+               rfmr = (SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) |
+                       SSC_BIT(RFMR_MSBF) | SSC_BF(RFMR_DATLEN, bits - 1));
+
+               tcmr = (SSC_BF(TCMR_STTDLY, START_DELAY) |
+                       SSC_BF(TCMR_START, start_event) |
+                       SSC_BF(TCMR_CKI, SSC_CKI_FALLING) |
+                       SSC_BF(TCMR_CKO, SSC_CKO_NONE) |
+                       SSC_BF(TCMR_CKS, SSC_CKS_PIN));
+
+               tfmr = (SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(TFMR_FSOS, SSC_FSOS_NONE) |
+                       SSC_BIT(TFMR_MSBF) | SSC_BF(TFMR_DATLEN, bits - 1));
+               break;
+
+
+       case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS:
+               /*
+                * DSP/PCM Mode A format, SSC provides BCLK and LRC clocks.
+                *
+                * The SSC transmit and receive clocks are generated from the
+                * MCK divider, and the BCLK signal is output on the SSC TK line
+                */
+               pr_debug("at32-ssc: SSC mode is DSP A BCLK / FRAME master\n");
+               rcmr = (SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period) |
+                       SSC_BF(RCMR_STTDLY, 1) |
+                       SSC_BF(RCMR_START, SSC_START_RISING_RF) |
+                       SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
+                       SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
+                       SSC_BF(RCMR_CKS, SSC_CKS_DIV));
+
+               rfmr = (SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(RFMR_FSOS, SSC_FSOS_POSITIVE) |
+                       SSC_BF(RFMR_DATNB, channels - 1) |
+                       SSC_BIT(RFMR_MSBF) | SSC_BF(RFMR_DATLEN, bits - 1));
+
+               tcmr = (SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period) |
+                       SSC_BF(TCMR_STTDLY, 1) |
+                       SSC_BF(TCMR_START, SSC_START_RISING_RF) |
+                       SSC_BF(TCMR_CKI, SSC_CKI_RISING) |
+                       SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS) |
+                       SSC_BF(TCMR_CKS, SSC_CKS_DIV));
+
+               tfmr = (SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
+                       SSC_BF(TFMR_FSOS, SSC_FSOS_POSITIVE) |
+                       SSC_BF(TFMR_DATNB, channels - 1) |
+                       SSC_BIT(TFMR_MSBF) | SSC_BF(TFMR_DATLEN, bits - 1));
+               break;
+
+
+       case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM:
+       default:
+               pr_warning("at32-ssc: unsupported DAI format 0x%x\n",
+                          ssc_p->daifmt);
+               return -EINVAL;
+               break;
+       }
+       pr_debug("at32-ssc: RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n",
+                rcmr, rfmr, tcmr, tfmr);
+
+
+       if (!ssc_p->initialized) {
+               /* enable peripheral clock */
+               pr_debug("at32-ssc: Starting clock\n");
+               clk_enable(ssc_p->ssc->clk);
+
+               /* Reset the SSC and its PDC registers */
+               ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
+
+               ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0);
+
+               ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0);
+               ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0);
+
+               ret = request_irq(ssc_p->ssc->irq, at32_ssc_interrupt, 0,
+                                 ssc_p->name, ssc_p);
+               if (ret < 0) {
+                       pr_warning("at32-ssc: request irq failed (%d)\n", ret);
+                       pr_debug("at32-ssc: Stopping clock\n");
+                       clk_disable(ssc_p->ssc->clk);
+                       return ret;
+               }
+
+               ssc_p->initialized = 1;
+       }
+
+       /* Set SSC clock mode register */
+       ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->cmr_div);
+
+       /* set receive clock mode and format */
+       ssc_writel(ssc_p->ssc->regs, RCMR, rcmr);
+       ssc_writel(ssc_p->ssc->regs, RFMR, rfmr);
+
+       /* set transmit clock mode and format */
+       ssc_writel(ssc_p->ssc->regs, TCMR, tcmr);
+       ssc_writel(ssc_p->ssc->regs, TFMR, tfmr);
+
+       pr_debug("at32-ssc: SSC initialized\n");
+       return 0;
+}
+
+
+
+static int at32_ssc_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct at32_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id];
+       struct at32_pcm_dma_params *dma_params;
+
+       dma_params = ssc_p->dma_params[substream->stream];
+
+       ssc_writel(dma_params->ssc->regs, CR, dma_params->mask->ssc_enable);
+
+       return 0;
+}
+
+
+
+#ifdef CONFIG_PM
+static int at32_ssc_suspend(struct platform_device *pdev,
+                           struct snd_soc_dai *cpu_dai)
+{
+       struct at32_ssc_info *ssc_p;
+
+       if (!cpu_dai->active)
+               return 0;
+
+       ssc_p = &ssc_info[cpu_dai->id];
+
+       /* Save the status register before disabling transmit and receive */
+       ssc_p->ssc_state.ssc_sr = ssc_readl(ssc_p->ssc->regs, SR);
+       ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_TXDIS) | SSC_BIT(CR_RXDIS));
+
+       /* Save the current interrupt mask, then disable unmasked interrupts */
+       ssc_p->ssc_state.ssc_imr = ssc_readl(ssc_p->ssc->regs, IMR);
+       ssc_writel(ssc_p->ssc->regs, IDR, ssc_p->ssc_state.ssc_imr);
+
+       ssc_p->ssc_state.ssc_cmr = ssc_readl(ssc_p->ssc->regs, CMR);
+       ssc_p->ssc_state.ssc_rcmr = ssc_readl(ssc_p->ssc->regs, RCMR);
+       ssc_p->ssc_state.ssc_rfmr = ssc_readl(ssc_p->ssc->regs, RFMR);
+       ssc_p->ssc_state.ssc_tcmr = ssc_readl(ssc_p->ssc->regs, TCMR);
+       ssc_p->ssc_state.ssc_tfmr = ssc_readl(ssc_p->ssc->regs, TFMR);
+
+       return 0;
+}
+
+
+
+static int at32_ssc_resume(struct platform_device *pdev,
+                          struct snd_soc_dai *cpu_dai)
+{
+       struct at32_ssc_info *ssc_p;
+       u32 cr;
+
+       if (!cpu_dai->active)
+               return 0;
+
+       ssc_p = &ssc_info[cpu_dai->id];
+
+       /* restore SSC register settings */
+       ssc_writel(ssc_p->ssc->regs, TFMR, ssc_p->ssc_state.ssc_tfmr);
+       ssc_writel(ssc_p->ssc->regs, TCMR, ssc_p->ssc_state.ssc_tcmr);
+       ssc_writel(ssc_p->ssc->regs, RFMR, ssc_p->ssc_state.ssc_rfmr);
+       ssc_writel(ssc_p->ssc->regs, RCMR, ssc_p->ssc_state.ssc_rcmr);
+       ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->ssc_state.ssc_cmr);
+
+       /* re-enable interrupts */
+       ssc_writel(ssc_p->ssc->regs, IER, ssc_p->ssc_state.ssc_imr);
+
+       /* Re-enable recieve and transmit as appropriate */
+       cr = 0;
+       cr |=
+           (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_RXEN)) ? SSC_BIT(CR_RXEN) : 0;
+       cr |=
+           (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_TXEN)) ? SSC_BIT(CR_TXEN) : 0;
+       ssc_writel(ssc_p->ssc->regs, CR, cr);
+
+       return 0;
+}
+#else /* CONFIG_PM */
+#  define at32_ssc_suspend     NULL
+#  define at32_ssc_resume      NULL
+#endif /* CONFIG_PM */
+
+
+#define AT32_SSC_RATES \
+    (SNDRV_PCM_RATE_8000  | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+     SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+     SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+
+
+#define AT32_SSC_FORMATS \
+    (SNDRV_PCM_FMTBIT_S8  | SNDRV_PCM_FMTBIT_S16 | \
+     SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_S32)
+
+
+struct snd_soc_dai at32_ssc_dai[NUM_SSC_DEVICES] = {
+       {
+        .name = "at32-ssc0",
+        .id = 0,
+        .type = SND_SOC_DAI_PCM,
+        .suspend = at32_ssc_suspend,
+        .resume = at32_ssc_resume,
+        .playback = {
+                     .channels_min = 1,
+                     .channels_max = 2,
+                     .rates = AT32_SSC_RATES,
+                     .formats = AT32_SSC_FORMATS,
+                     },
+        .capture = {
+                    .channels_min = 1,
+                    .channels_max = 2,
+                    .rates = AT32_SSC_RATES,
+                    .formats = AT32_SSC_FORMATS,
+                    },
+        .ops = {
+                .startup = at32_ssc_startup,
+                .shutdown = at32_ssc_shutdown,
+                .prepare = at32_ssc_prepare,
+                .hw_params = at32_ssc_hw_params,
+                },
+        .dai_ops = {
+                    .set_sysclk = at32_ssc_set_dai_sysclk,
+                    .set_fmt = at32_ssc_set_dai_fmt,
+                    .set_clkdiv = at32_ssc_set_dai_clkdiv,
+                    },
+        .private_data = &ssc_info[0],
+        },
+       {
+        .name = "at32-ssc1",
+        .id = 1,
+        .type = SND_SOC_DAI_PCM,
+        .suspend = at32_ssc_suspend,
+        .resume = at32_ssc_resume,
+        .playback = {
+                     .channels_min = 1,
+                     .channels_max = 2,
+                     .rates = AT32_SSC_RATES,
+                     .formats = AT32_SSC_FORMATS,
+                     },
+        .capture = {
+                    .channels_min = 1,
+                    .channels_max = 2,
+                    .rates = AT32_SSC_RATES,
+                    .formats = AT32_SSC_FORMATS,
+                    },
+        .ops = {
+                .startup = at32_ssc_startup,
+                .shutdown = at32_ssc_shutdown,
+                .prepare = at32_ssc_prepare,
+                .hw_params = at32_ssc_hw_params,
+                },
+        .dai_ops = {
+                    .set_sysclk = at32_ssc_set_dai_sysclk,
+                    .set_fmt = at32_ssc_set_dai_fmt,
+                    .set_clkdiv = at32_ssc_set_dai_clkdiv,
+                    },
+        .private_data = &ssc_info[1],
+        },
+       {
+        .name = "at32-ssc2",
+        .id = 2,
+        .type = SND_SOC_DAI_PCM,
+        .suspend = at32_ssc_suspend,
+        .resume = at32_ssc_resume,
+        .playback = {
+                     .channels_min = 1,
+                     .channels_max = 2,
+                     .rates = AT32_SSC_RATES,
+                     .formats = AT32_SSC_FORMATS,
+                     },
+        .capture = {
+                    .channels_min = 1,
+                    .channels_max = 2,
+                    .rates = AT32_SSC_RATES,
+                    .formats = AT32_SSC_FORMATS,
+                    },
+        .ops = {
+                .startup = at32_ssc_startup,
+                .shutdown = at32_ssc_shutdown,
+                .prepare = at32_ssc_prepare,
+                .hw_params = at32_ssc_hw_params,
+                },
+        .dai_ops = {
+                    .set_sysclk = at32_ssc_set_dai_sysclk,
+                    .set_fmt = at32_ssc_set_dai_fmt,
+                    .set_clkdiv = at32_ssc_set_dai_clkdiv,
+                    },
+        .private_data = &ssc_info[2],
+        },
+};
+EXPORT_SYMBOL_GPL(at32_ssc_dai);
+
+
+MODULE_AUTHOR("Geoffrey Wossum <gwossum@acm.org>");
+MODULE_DESCRIPTION("AT32 SSC ASoC Interface");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/at32/at32-ssc.h b/sound/soc/at32/at32-ssc.h
new file mode 100644 (file)
index 0000000..3c052db
--- /dev/null
@@ -0,0 +1,59 @@
+/* sound/soc/at32/at32-ssc.h
+ * ASoC SSC interface for Atmel AT32 SoC
+ *
+ * Copyright (C) 2008 Long Range Systems
+ *    Geoffrey Wossum <gwossum@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __SOUND_SOC_AT32_AT32_SSC_H
+#define __SOUND_SOC_AT32_AT32_SSC_H __FILE__
+
+#include <linux/types.h>
+#include <linux/atmel-ssc.h>
+
+#include "at32-pcm.h"
+
+
+
+struct at32_ssc_state {
+       u32 ssc_cmr;
+       u32 ssc_rcmr;
+       u32 ssc_rfmr;
+       u32 ssc_tcmr;
+       u32 ssc_tfmr;
+       u32 ssc_sr;
+       u32 ssc_imr;
+};
+
+
+
+struct at32_ssc_info {
+       char *name;
+       struct ssc_device *ssc;
+       spinlock_t lock;        /* lock for dir_mask */
+       unsigned short dir_mask;        /* 0=unused, 1=playback, 2=capture */
+       unsigned short initialized;     /* true if SSC has been initialized */
+       unsigned short daifmt;
+       unsigned short cmr_div;
+       unsigned short tcmr_period;
+       unsigned short rcmr_period;
+       struct at32_pcm_dma_params *dma_params[2];
+       struct at32_ssc_state ssc_state;
+};
+
+
+/* SSC divider ids */
+#define AT32_SSC_CMR_DIV        0      /* MCK divider for BCLK */
+#define AT32_SSC_TCMR_PERIOD    1      /* BCLK divider for transmit FS */
+#define AT32_SSC_RCMR_PERIOD    2      /* BCLK divider for receive FS */
+
+
+extern struct snd_soc_dai at32_ssc_dai[];
+
+
+
+#endif /* __SOUND_SOC_AT32_AT32_SSC_H */
diff --git a/sound/soc/at32/playpaq_wm8510.c b/sound/soc/at32/playpaq_wm8510.c
new file mode 100644 (file)
index 0000000..fee5f8e
--- /dev/null
@@ -0,0 +1,522 @@
+/* sound/soc/at32/playpaq_wm8510.c
+ * ASoC machine driver for PlayPaq using WM8510 codec
+ *
+ * Copyright (C) 2008 Long Range Systems
+ *    Geoffrey Wossum <gwossum@acm.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This code is largely inspired by sound/soc/at91/eti_b1_wm8731.c
+ *
+ * NOTE: If you don't have the AT32 enhanced portmux configured (which
+ * isn't currently in the mainline or Atmel patched kernel), you will
+ * need to set the MCLK pin (PA30) to peripheral A in your board initialization
+ * code.  Something like:
+ *     at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
+ *
+ */
+
+/* #define DEBUG */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/clk.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/arch/at32ap700x.h>
+#include <asm/arch/portmux.h>
+
+#include "../codecs/wm8510.h"
+#include "at32-pcm.h"
+#include "at32-ssc.h"
+
+
+/*-------------------------------------------------------------------------*\
+ * constants
+\*-------------------------------------------------------------------------*/
+#define MCLK_PIN               GPIO_PIN_PA(30)
+#define MCLK_PERIPH            GPIO_PERIPH_A
+
+
+/*-------------------------------------------------------------------------*\
+ * data types
+\*-------------------------------------------------------------------------*/
+/* SSC clocking data */
+struct ssc_clock_data {
+       /* CMR div */
+       unsigned int cmr_div;
+
+       /* Frame period (as needed by xCMR.PERIOD) */
+       unsigned int period;
+
+       /* The SSC clock rate these settings where calculated for */
+       unsigned long ssc_rate;
+};
+
+
+/*-------------------------------------------------------------------------*\
+ * module data
+\*-------------------------------------------------------------------------*/
+static struct clk *_gclk0;
+static struct clk *_pll0;
+
+#define CODEC_CLK (_gclk0)
+
+
+/*-------------------------------------------------------------------------*\
+ * Sound SOC operations
+\*-------------------------------------------------------------------------*/
+#if defined CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE
+static struct ssc_clock_data playpaq_wm8510_calc_ssc_clock(
+       struct snd_pcm_hw_params *params,
+       struct snd_soc_dai *cpu_dai)
+{
+       struct at32_ssc_info *ssc_p = cpu_dai->private_data;
+       struct ssc_device *ssc = ssc_p->ssc;
+       struct ssc_clock_data cd;
+       unsigned int rate, width_bits, channels;
+       unsigned int bitrate, ssc_div;
+       unsigned actual_rate;
+
+
+       /*
+        * Figure out required bitrate
+        */
+       rate = params_rate(params);
+       channels = params_channels(params);
+       width_bits = snd_pcm_format_physical_width(params_format(params));
+       bitrate = rate * width_bits * channels;
+
+
+       /*
+        * Figure out required SSC divider and period for required bitrate
+        */
+       cd.ssc_rate = clk_get_rate(ssc->clk);
+       ssc_div = cd.ssc_rate / bitrate;
+       cd.cmr_div = ssc_div / 2;
+       if (ssc_div & 1) {
+               /* round cmr_div up */
+               cd.cmr_div++;
+       }
+       cd.period = width_bits - 1;
+
+
+       /*
+        * Find actual rate, compare to requested rate
+        */
+       actual_rate = (cd.ssc_rate / (cd.cmr_div * 2)) / (2 * (cd.period + 1));
+       pr_debug("playpaq_wm8510: Request rate = %d, actual rate = %d\n",
+                rate, actual_rate);
+
+
+       return cd;
+}
+#endif /* CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE */
+
+
+
+static int playpaq_wm8510_hw_params(struct snd_pcm_substream *substream,
+                                   struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct at32_ssc_info *ssc_p = cpu_dai->private_data;
+       struct ssc_device *ssc = ssc_p->ssc;
+       unsigned int pll_out = 0, bclk = 0, mclk_div = 0;
+       int ret;
+
+
+       /* Due to difficulties with getting the correct clocks from the AT32's
+        * PLL0, we're going to let the CODEC be in charge of all the clocks
+        */
+#if !defined CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE
+       const unsigned int fmt = (SND_SOC_DAIFMT_I2S |
+                                 SND_SOC_DAIFMT_NB_NF |
+                                 SND_SOC_DAIFMT_CBM_CFM);
+#else
+       struct ssc_clock_data cd;
+       const unsigned int fmt = (SND_SOC_DAIFMT_I2S |
+                                 SND_SOC_DAIFMT_NB_NF |
+                                 SND_SOC_DAIFMT_CBS_CFS);
+#endif
+
+       if (ssc == NULL) {
+               pr_warning("playpaq_wm8510_hw_params: ssc is NULL!\n");
+               return -EINVAL;
+       }
+
+
+       /*
+        * Figure out PLL and BCLK dividers for WM8510
+        */
+       switch (params_rate(params)) {
+       case 48000:
+               pll_out = 12288000;
+               mclk_div = WM8510_MCLKDIV_1;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       case 44100:
+               pll_out = 11289600;
+               mclk_div = WM8510_MCLKDIV_1;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       case 22050:
+               pll_out = 11289600;
+               mclk_div = WM8510_MCLKDIV_2;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       case 16000:
+               pll_out = 12288000;
+               mclk_div = WM8510_MCLKDIV_3;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       case 11025:
+               pll_out = 11289600;
+               mclk_div = WM8510_MCLKDIV_4;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       case 8000:
+               pll_out = 12288000;
+               mclk_div = WM8510_MCLKDIV_6;
+               bclk = WM8510_BCLKDIV_8;
+               break;
+
+       default:
+               pr_warning("playpaq_wm8510: Unsupported sample rate %d\n",
+                          params_rate(params));
+               return -EINVAL;
+       }
+
+
+       /*
+        * set CPU and CODEC DAI configuration
+        */
+       ret = snd_soc_dai_set_fmt(codec_dai, fmt);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: "
+                          "Failed to set CODEC DAI format (%d)\n",
+                          ret);
+               return ret;
+       }
+       ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: "
+                          "Failed to set CPU DAI format (%d)\n",
+                          ret);
+               return ret;
+       }
+
+
+       /*
+        * Set CPU clock configuration
+        */
+#if defined CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE
+       cd = playpaq_wm8510_calc_ssc_clock(params, cpu_dai);
+       pr_debug("playpaq_wm8510: cmr_div = %d, period = %d\n",
+                cd.cmr_div, cd.period);
+       ret = snd_soc_dai_set_clkdiv(cpu_dai, AT32_SSC_CMR_DIV, cd.cmr_div);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: Failed to set CPU CMR_DIV (%d)\n",
+                          ret);
+               return ret;
+       }
+       ret = snd_soc_dai_set_clkdiv(cpu_dai, AT32_SSC_TCMR_PERIOD,
+                                         cd.period);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: "
+                          "Failed to set CPU transmit period (%d)\n",
+                          ret);
+               return ret;
+       }
+#endif /* CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE */
+
+
+       /*
+        * Set CODEC clock configuration
+        */
+       pr_debug("playpaq_wm8510: "
+                "pll_in = %ld, pll_out = %u, bclk = %x, mclk = %x\n",
+                clk_get_rate(CODEC_CLK), pll_out, bclk, mclk_div);
+
+
+#if !defined CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE
+       ret = snd_soc_dai_set_clkdiv(codec_dai, WM8510_BCLKDIV, bclk);
+       if (ret < 0) {
+               pr_warning
+                   ("playpaq_wm8510: Failed to set CODEC DAI BCLKDIV (%d)\n",
+                    ret);
+               return ret;
+       }
+#endif /* CONFIG_SND_AT32_SOC_PLAYPAQ_SLAVE */
+
+
+       ret = snd_soc_dai_set_pll(codec_dai, 0,
+                                        clk_get_rate(CODEC_CLK), pll_out);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: Failed to set CODEC DAI PLL (%d)\n",
+                          ret);
+               return ret;
+       }
+
+
+       ret = snd_soc_dai_set_clkdiv(codec_dai, WM8510_MCLKDIV, mclk_div);
+       if (ret < 0) {
+               pr_warning("playpaq_wm8510: Failed to set CODEC MCLKDIV (%d)\n",
+                          ret);
+               return ret;
+       }
+
+
+       return 0;
+}
+
+
+
+static struct snd_soc_ops playpaq_wm8510_ops = {
+       .hw_params = playpaq_wm8510_hw_params,
+};
+
+
+
+static const struct snd_soc_dapm_widget playpaq_dapm_widgets[] = {
+       SND_SOC_DAPM_MIC("Int Mic", NULL),
+       SND_SOC_DAPM_SPK("Ext Spk", NULL),
+};
+
+
+
+static const char *intercon[][3] = {
+       /* speaker connected to SPKOUT */
+       {"Ext Spk", NULL, "SPKOUTP"},
+       {"Ext Spk", NULL, "SPKOUTN"},
+
+       {"Mic Bias", NULL, "Int Mic"},
+       {"MICN", NULL, "Mic Bias"},
+       {"MICP", NULL, "Mic Bias"},
+
+       /* Terminator */
+       {NULL, NULL, NULL},
+};
+
+
+
+static int playpaq_wm8510_init(struct snd_soc_codec *codec)
+{
+       int i;
+
+       /*
+        * Add DAPM widgets
+        */
+       for (i = 0; i < ARRAY_SIZE(playpaq_dapm_widgets); i++)
+               snd_soc_dapm_new_control(codec, &playpaq_dapm_widgets[i]);
+
+
+
+       /*
+        * Setup audio path interconnects
+        */
+       for (i = 0; intercon[i][0] != NULL; i++) {
+               snd_soc_dapm_connect_input(codec,
+                                          intercon[i][0],
+                                          intercon[i][1], intercon[i][2]);
+       }
+
+
+       /* always connected pins */
+       snd_soc_dapm_enable_pin(codec, "Int Mic");
+       snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       snd_soc_dapm_sync(codec);
+
+
+
+       /* Make CSB show PLL rate */
+       snd_soc_dai_set_clkdiv(codec->dai, WM8510_OPCLKDIV,
+                                      WM8510_OPCLKDIV_1 | 4);
+
+       return 0;
+}
+
+
+
+static struct snd_soc_dai_link playpaq_wm8510_dai = {
+       .name = "WM8510",
+       .stream_name = "WM8510 PCM",
+       .cpu_dai = &at32_ssc_dai[0],
+       .codec_dai = &wm8510_dai,
+       .init = playpaq_wm8510_init,
+       .ops = &playpaq_wm8510_ops,
+};
+
+
+
+static struct snd_soc_machine snd_soc_machine_playpaq = {
+       .name = "LRS_PlayPaq_WM8510",
+       .dai_link = &playpaq_wm8510_dai,
+       .num_links = 1,
+};
+
+
+
+static struct wm8510_setup_data playpaq_wm8510_setup = {
+       .i2c_address = 0x1a,
+};
+
+
+
+static struct snd_soc_device playpaq_wm8510_snd_devdata = {
+       .machine = &snd_soc_machine_playpaq,
+       .platform = &at32_soc_platform,
+       .codec_dev = &soc_codec_dev_wm8510,
+       .codec_data = &playpaq_wm8510_setup,
+};
+
+static struct platform_device *playpaq_snd_device;
+
+
+static int __init playpaq_asoc_init(void)
+{
+       int ret = 0;
+       struct at32_ssc_info *ssc_p = playpaq_wm8510_dai.cpu_dai->private_data;
+       struct ssc_device *ssc = NULL;
+
+
+       /*
+        * Request SSC device
+        */
+       ssc = ssc_request(0);
+       if (IS_ERR(ssc)) {
+               ret = PTR_ERR(ssc);
+               ssc = NULL;
+               goto err_ssc;
+       }
+       ssc_p->ssc = ssc;
+
+
+       /*
+        * Configure MCLK for WM8510
+        */
+       _gclk0 = clk_get(NULL, "gclk0");
+       if (IS_ERR(_gclk0)) {
+               _gclk0 = NULL;
+               goto err_gclk0;
+       }
+       _pll0 = clk_get(NULL, "pll0");
+       if (IS_ERR(_pll0)) {
+               _pll0 = NULL;
+               goto err_pll0;
+       }
+       if (clk_set_parent(_gclk0, _pll0)) {
+               pr_warning("snd-soc-playpaq: "
+                          "Failed to set PLL0 as parent for DAC clock\n");
+               goto err_set_clk;
+       }
+       clk_set_rate(CODEC_CLK, 12000000);
+       clk_enable(CODEC_CLK);
+
+#if defined CONFIG_AT32_ENHANCED_PORTMUX
+       at32_select_periph(MCLK_PIN, MCLK_PERIPH, 0);
+#endif
+
+
+       /*
+        * Create and register platform device
+        */
+       playpaq_snd_device = platform_device_alloc("soc-audio", 0);
+       if (playpaq_snd_device == NULL) {
+               ret = -ENOMEM;
+               goto err_device_alloc;
+       }
+
+       platform_set_drvdata(playpaq_snd_device, &playpaq_wm8510_snd_devdata);
+       playpaq_wm8510_snd_devdata.dev = &playpaq_snd_device->dev;
+
+       ret = platform_device_add(playpaq_snd_device);
+       if (ret) {
+               pr_warning("playpaq_wm8510: platform_device_add failed (%d)\n",
+                          ret);
+               goto err_device_add;
+       }
+
+       return 0;
+
+
+err_device_add:
+       if (playpaq_snd_device != NULL) {
+               platform_device_put(playpaq_snd_device);
+               playpaq_snd_device = NULL;
+       }
+err_device_alloc:
+err_set_clk:
+       if (_pll0 != NULL) {
+               clk_put(_pll0);
+               _pll0 = NULL;
+       }
+err_pll0:
+       if (_gclk0 != NULL) {
+               clk_put(_gclk0);
+               _gclk0 = NULL;
+       }
+err_gclk0:
+       if (ssc != NULL) {
+               ssc_free(ssc);
+               ssc = NULL;
+       }
+err_ssc:
+       return ret;
+}
+
+
+static void __exit playpaq_asoc_exit(void)
+{
+       struct at32_ssc_info *ssc_p = playpaq_wm8510_dai.cpu_dai->private_data;
+       struct ssc_device *ssc;
+
+       if (ssc_p != NULL) {
+               ssc = ssc_p->ssc;
+               if (ssc != NULL)
+                       ssc_free(ssc);
+               ssc_p->ssc = NULL;
+       }
+
+       if (_gclk0 != NULL) {
+               clk_put(_gclk0);
+               _gclk0 = NULL;
+       }
+       if (_pll0 != NULL) {
+               clk_put(_pll0);
+               _pll0 = NULL;
+       }
+
+#if defined CONFIG_AT32_ENHANCED_PORTMUX
+       at32_free_pin(MCLK_PIN);
+#endif
+
+       platform_device_unregister(playpaq_snd_device);
+       playpaq_snd_device = NULL;
+}
+
+module_init(playpaq_asoc_init);
+module_exit(playpaq_asoc_exit);
+
+MODULE_AUTHOR("Geoffrey Wossum <gwossum@acm.org>");
+MODULE_DESCRIPTION("ASoC machine driver for LRS PlayPaq");
+MODULE_LICENSE("GPL");
index 5cb93fd..9051865 100644 (file)
@@ -1,6 +1,6 @@
 config SND_AT91_SOC
        tristate "SoC Audio for the Atmel AT91 System-on-Chip"
-       depends on ARCH_AT91 && SND_SOC
+       depends on ARCH_AT91
        help
          Say Y or M if you want to add support for codecs attached to
          the AT91 SSC interface. You will also need
index ccac6bd..d47492b 100644 (file)
@@ -318,7 +318,7 @@ static int at91_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
 static u64 at91_pcm_dmamask = 0xffffffff;
 
 static int at91_pcm_new(struct snd_card *card,
-       struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
+       struct snd_soc_dai *dai, struct snd_pcm *pcm)
 {
        int ret = 0;
 
@@ -367,7 +367,7 @@ static void at91_pcm_free_dma_buffers(struct snd_pcm *pcm)
 
 #ifdef CONFIG_PM
 static int at91_pcm_suspend(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        struct snd_pcm_runtime *runtime = dai->runtime;
        struct at91_runtime_data *prtd;
@@ -392,7 +392,7 @@ static int at91_pcm_suspend(struct platform_device *pdev,
 }
 
 static int at91_pcm_resume(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        struct snd_pcm_runtime *runtime = dai->runtime;
        struct at91_runtime_data *prtd;
index bc35d00..090e607 100644 (file)
@@ -41,7 +41,7 @@
 #define        DBG(x...)
 #endif
 
-#if defined(CONFIG_ARCH_AT91SAM9260)
+#if defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9G20)
 #define NUM_SSC_DEVICES                1
 #else
 #define NUM_SSC_DEVICES                3
@@ -281,7 +281,7 @@ static void at91_ssc_shutdown(struct snd_pcm_substream *substream)
 /*
  * Record the SSC system clock rate.
  */
-static int at91_ssc_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int at91_ssc_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
                int clk_id, unsigned int freq, int dir)
 {
        /*
@@ -303,7 +303,7 @@ static int at91_ssc_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
 /*
  * Record the DAI format for use in hw_params().
  */
-static int at91_ssc_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int at91_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                unsigned int fmt)
 {
        struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
@@ -315,7 +315,7 @@ static int at91_ssc_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
 /*
  * Record SSC clock dividers for use in hw_params().
  */
-static int at91_ssc_set_dai_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
+static int at91_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
        int div_id, int div)
 {
        struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
@@ -634,7 +634,7 @@ static int at91_ssc_prepare(struct snd_pcm_substream *substream)
 
 #ifdef CONFIG_PM
 static int at91_ssc_suspend(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *cpu_dai)
+       struct snd_soc_dai *cpu_dai)
 {
        struct at91_ssc_info *ssc_p;
 
@@ -662,7 +662,7 @@ static int at91_ssc_suspend(struct platform_device *pdev,
 }
 
 static int at91_ssc_resume(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *cpu_dai)
+       struct snd_soc_dai *cpu_dai)
 {
        struct at91_ssc_info *ssc_p;
 
@@ -700,7 +700,7 @@ static int at91_ssc_resume(struct platform_device *pdev,
 #define AT91_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8     | SNDRV_PCM_FMTBIT_S16_LE |\
                          SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
 
-struct snd_soc_cpu_dai at91_ssc_dai[NUM_SSC_DEVICES] = {
+struct snd_soc_dai at91_ssc_dai[NUM_SSC_DEVICES] = {
        {       .name = "at91-ssc0",
                .id = 0,
                .type = SND_SOC_DAI_PCM,
index b188f97..6b7bf38 100644 (file)
@@ -21,7 +21,7 @@
 #define AT91SSC_TCMR_PERIOD    1 /* BCLK divider for transmit FS */
 #define AT91SSC_RCMR_PERIOD    2 /* BCLK divider for receive FS */
 
-extern struct snd_soc_cpu_dai at91_ssc_dai[];
+extern struct snd_soc_dai at91_ssc_dai[];
 
 #endif /* _AT91_SSC_H */
 
index 1347dcf..d532de9 100644 (file)
@@ -53,18 +53,18 @@ static struct clk *pllb_clk;
 static int eti_b1_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        int ret;
 
        /* cpu clock is the AT91 master clock sent to the SSC */
-       ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, AT91_SYSCLK_MCK,
+       ret = snd_soc_dai_set_sysclk(cpu_dai, AT91_SYSCLK_MCK,
                60000000, SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* codec system clock is supplied by PCK1, set to 12MHz */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8731_SYSCLK,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK,
                12000000, SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
@@ -87,8 +87,8 @@ static int eti_b1_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        int ret;
 
 #ifdef CONFIG_SND_AT91_SOC_ETI_SLAVE
@@ -96,13 +96,13 @@ static int eti_b1_hw_params(struct snd_pcm_substream *substream,
        int cmr_div, period;
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
@@ -141,17 +141,17 @@ static int eti_b1_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set the MCK divider for BCLK */
-       ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, AT91SSC_CMR_DIV, cmr_div);
+       ret = snd_soc_dai_set_clkdiv(cpu_dai, AT91SSC_CMR_DIV, cmr_div);
        if (ret < 0)
                return ret;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                /* set the BCLK divider for DACLRC */
-               ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai,
+               ret = snd_soc_dai_set_clkdiv(cpu_dai,
                                                AT91SSC_TCMR_PERIOD, period);
        } else {
                /* set the BCLK divider for ADCLRC */
-               ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai,
+               ret = snd_soc_dai_set_clkdiv(cpu_dai,
                                                AT91SSC_RCMR_PERIOD, period);
        }
        if (ret < 0)
@@ -163,13 +163,13 @@ static int eti_b1_hw_params(struct snd_pcm_substream *substream,
         */
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
        if (ret < 0)
                return ret;
@@ -191,7 +191,7 @@ static const struct snd_soc_dapm_widget eti_b1_dapm_widgets[] = {
        SND_SOC_DAPM_SPK("Ext Spk", NULL),
 };
 
-static const char *intercon[][3] = {
+static const struct snd_soc_dapm_route intercon[] = {
 
        /* speaker connected to LHPOUT */
        {"Ext Spk", NULL, "LHPOUT"},
@@ -199,9 +199,6 @@ static const char *intercon[][3] = {
        /* mic is connected to Mic Jack, with WM8731 Mic Bias */
        {"MICIN", NULL, "Mic Bias"},
        {"Mic Bias", NULL, "Int Mic"},
-
-       /* terminator */
-       {NULL, NULL, NULL},
 };
 
 /*
@@ -209,30 +206,24 @@ static const char *intercon[][3] = {
  */
 static int eti_b1_wm8731_init(struct snd_soc_codec *codec)
 {
-       int i;
-
        DBG("eti_b1_wm8731_init() called\n");
 
        /* Add specific widgets */
-       for(i = 0; i < ARRAY_SIZE(eti_b1_dapm_widgets); i++) {
-               snd_soc_dapm_new_control(codec, &eti_b1_dapm_widgets[i]);
-       }
+       snd_soc_dapm_new_controls(codec, eti_b1_dapm_widgets,
+                                 ARRAY_SIZE(eti_b1_dapm_widgets));
 
        /* Set up specific audio path interconnects */
-       for(i = 0; intercon[i][0] != NULL; i++) {
-               snd_soc_dapm_connect_input(codec, intercon[i][0],
-                       intercon[i][1], intercon[i][2]);
-       }
+       snd_soc_dapm_add_route(codec, intercon, ARRAY_SIZE(intercon));
 
        /* not connected */
-       snd_soc_dapm_set_endpoint(codec, "RLINEIN", 0);
-       snd_soc_dapm_set_endpoint(codec, "LLINEIN", 0);
+       snd_soc_dapm_disable_pin(codec, "RLINEIN");
+       snd_soc_dapm_disable_pin(codec, "LLINEIN");
 
        /* always connected */
-       snd_soc_dapm_set_endpoint(codec, "Int Mic", 1);
-       snd_soc_dapm_set_endpoint(codec, "Ext Spk", 1);
+       snd_soc_dapm_enable_pin(codec, "Int Mic");
+       snd_soc_dapm_enable_pin(codec, "Ext Spk");
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 
        return 0;
 }
diff --git a/sound/soc/au1x/Kconfig b/sound/soc/au1x/Kconfig
new file mode 100644 (file)
index 0000000..410a893
--- /dev/null
@@ -0,0 +1,32 @@
+##
+## Au1200/Au1550 PSC + DBDMA
+##
+config SND_SOC_AU1XPSC
+       tristate "SoC Audio for Au1200/Au1250/Au1550"
+       depends on SOC_AU1200 || SOC_AU1550
+       help
+         This option enables support for the Programmable Serial
+         Controllers in AC97 and I2S mode, and the Descriptor-Based DMA
+         Controller (DBDMA) as found on the Au1200/Au1250/Au1550 SoC.
+
+config SND_SOC_AU1XPSC_I2S
+       tristate
+
+config SND_SOC_AU1XPSC_AC97
+       tristate
+       select AC97_BUS
+       select SND_AC97_CODEC
+       select SND_SOC_AC97_BUS
+
+
+##
+## Boards
+##
+config SND_SOC_SAMPLE_PSC_AC97
+       tristate "Sample Au12x0/Au1550 PSC AC97 sound machine"
+       depends on SND_SOC_AU1XPSC
+       select SND_SOC_AU1XPSC_AC97
+       select SND_SOC_AC97_CODEC
+       help
+         This is a sample AC97 sound machine for use in Au12x0/Au1550
+         based systems which have audio on PSC1 (e.g. Db1200 demoboard).
diff --git a/sound/soc/au1x/Makefile b/sound/soc/au1x/Makefile
new file mode 100644 (file)
index 0000000..6c6950b
--- /dev/null
@@ -0,0 +1,13 @@
+# Au1200/Au1550 PSC audio
+snd-soc-au1xpsc-dbdma-objs := dbdma2.o
+snd-soc-au1xpsc-i2s-objs := psc-i2s.o
+snd-soc-au1xpsc-ac97-objs := psc-ac97.o
+
+obj-$(CONFIG_SND_SOC_AU1XPSC) += snd-soc-au1xpsc-dbdma.o
+obj-$(CONFIG_SND_SOC_AU1XPSC_I2S) += snd-soc-au1xpsc-i2s.o
+obj-$(CONFIG_SND_SOC_AU1XPSC_AC97) += snd-soc-au1xpsc-ac97.o
+
+# Boards
+snd-soc-sample-ac97-objs := sample-ac97.o
+
+obj-$(CONFIG_SND_SOC_SAMPLE_PSC_AC97) += snd-soc-sample-ac97.o
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
new file mode 100644 (file)
index 0000000..1466d93
--- /dev/null
@@ -0,0 +1,421 @@
+/*
+ * Au12x0/Au1550 PSC ALSA ASoC audio support.
+ *
+ * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
+ *     Manuel Lauss <mano@roarinelk.homelinux.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * DMA glue for Au1x-PSC audio.
+ *
+ * NOTE: all of these drivers can only work with a SINGLE instance
+ *      of a PSC. Multiple independent audio devices are impossible
+ *      with ASoC v1.
+ */
+
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1xxx_dbdma.h>
+#include <asm/mach-au1x00/au1xxx_psc.h>
+
+#include "psc.h"
+
+/*#define PCM_DEBUG*/
+
+#define MSG(x...)      printk(KERN_INFO "au1xpsc_pcm: " x)
+#ifdef PCM_DEBUG
+#define DBG            MSG
+#else
+#define DBG(x...)      do {} while (0)
+#endif
+
+struct au1xpsc_audio_dmadata {
+       /* DDMA control data */
+       unsigned int ddma_id;           /* DDMA direction ID for this PSC */
+       u32 ddma_chan;                  /* DDMA context */
+
+       /* PCM context (for irq handlers) */
+       struct snd_pcm_substream *substream;
+       unsigned long curr_period;      /* current segment DDMA is working on */
+       unsigned long q_period;         /* queue period(s) */
+       unsigned long dma_area;         /* address of queued DMA area */
+       unsigned long dma_area_s;       /* start address of DMA area */
+       unsigned long pos;              /* current byte position being played */
+       unsigned long periods;          /* number of SG segments in total */
+       unsigned long period_bytes;     /* size in bytes of one SG segment */
+
+       /* runtime data */
+       int msbits;
+};
+
+/* instance data. There can be only one, MacLeod!!!! */
+static struct au1xpsc_audio_dmadata *au1xpsc_audio_pcmdma[2];
+
+/*
+ * These settings are somewhat okay, at least on my machine audio plays
+ * almost skip-free. Especially the 64kB buffer seems to help a LOT.
+ */
+#define AU1XPSC_PERIOD_MIN_BYTES       1024
+#define AU1XPSC_BUFFER_MIN_BYTES       65536
+
+#define AU1XPSC_PCM_FMTS                                       \
+       (SNDRV_PCM_FMTBIT_S8     | SNDRV_PCM_FMTBIT_U8 |        \
+        SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |    \
+        SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |    \
+        SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |    \
+        SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE |    \
+        0)
+
+/* PCM hardware DMA capabilities - platform specific */
+static const struct snd_pcm_hardware au1xpsc_pcm_hardware = {
+       .info             = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
+                           SNDRV_PCM_INFO_INTERLEAVED,
+       .formats          = AU1XPSC_PCM_FMTS,
+       .period_bytes_min = AU1XPSC_PERIOD_MIN_BYTES,
+       .period_bytes_max = 4096 * 1024 - 1,
+       .periods_min      = 2,
+       .periods_max      = 4096,       /* 2 to as-much-as-you-like */
+       .buffer_bytes_max = 4096 * 1024 - 1,
+       .fifo_size        = 16,         /* fifo entries of AC97/I2S PSC */
+};
+
+static void au1x_pcm_queue_tx(struct au1xpsc_audio_dmadata *cd)
+{
+       au1xxx_dbdma_put_source_flags(cd->ddma_chan,
+                               (void *)phys_to_virt(cd->dma_area),
+                               cd->period_bytes, DDMA_FLAGS_IE);
+
+       /* update next-to-queue period */
+       ++cd->q_period;
+       cd->dma_area += cd->period_bytes;
+       if (cd->q_period >= cd->periods) {
+               cd->q_period = 0;
+               cd->dma_area = cd->dma_area_s;
+       }
+}
+
+static void au1x_pcm_queue_rx(struct au1xpsc_audio_dmadata *cd)
+{
+       au1xxx_dbdma_put_dest_flags(cd->ddma_chan,
+                               (void *)phys_to_virt(cd->dma_area),
+                               cd->period_bytes, DDMA_FLAGS_IE);
+
+       /* update next-to-queue period */
+       ++cd->q_period;
+       cd->dma_area += cd->period_bytes;
+       if (cd->q_period >= cd->periods) {
+               cd->q_period = 0;
+               cd->dma_area = cd->dma_area_s;
+       }
+}
+
+static void au1x_pcm_dmatx_cb(int irq, void *dev_id)
+{
+       struct au1xpsc_audio_dmadata *cd = dev_id;
+
+       cd->pos += cd->period_bytes;
+       if (++cd->curr_period >= cd->periods) {
+               cd->pos = 0;
+               cd->curr_period = 0;
+       }
+       snd_pcm_period_elapsed(cd->substream);
+       au1x_pcm_queue_tx(cd);
+}
+
+static void au1x_pcm_dmarx_cb(int irq, void *dev_id)
+{
+       struct au1xpsc_audio_dmadata *cd = dev_id;
+
+       cd->pos += cd->period_bytes;
+       if (++cd->curr_period >= cd->periods) {
+               cd->pos = 0;
+               cd->curr_period = 0;
+       }
+       snd_pcm_period_elapsed(cd->substream);
+       au1x_pcm_queue_rx(cd);
+}
+
+static void au1x_pcm_dbdma_free(struct au1xpsc_audio_dmadata *pcd)
+{
+       if (pcd->ddma_chan) {
+               au1xxx_dbdma_stop(pcd->ddma_chan);
+               au1xxx_dbdma_reset(pcd->ddma_chan);
+               au1xxx_dbdma_chan_free(pcd->ddma_chan);
+               pcd->ddma_chan = 0;
+               pcd->msbits = 0;
+       }
+}
+
+/* in case of missing DMA ring or changed TX-source / RX-dest bit widths,
+ * allocate (or reallocate) a 2-descriptor DMA ring with bit depth according
+ * to ALSA-supplied sample depth.  This is due to limitations in the dbdma api
+ * (cannot adjust source/dest widths of already allocated descriptor ring).
+ */
+static int au1x_pcm_dbdma_realloc(struct au1xpsc_audio_dmadata *pcd,
+                                int stype, int msbits)
+{
+       /* DMA only in 8/16/32 bit widths */
+       if (msbits == 24)
+               msbits = 32;
+
+       /* check current config: correct bits and descriptors allocated? */
+       if ((pcd->ddma_chan) && (msbits == pcd->msbits))
+               goto out;       /* all ok! */
+
+       au1x_pcm_dbdma_free(pcd);
+
+       if (stype == PCM_RX)
+               pcd->ddma_chan = au1xxx_dbdma_chan_alloc(pcd->ddma_id,
+                                       DSCR_CMD0_ALWAYS,
+                                       au1x_pcm_dmarx_cb, (void *)pcd);
+       else
+               pcd->ddma_chan = au1xxx_dbdma_chan_alloc(DSCR_CMD0_ALWAYS,
+                                       pcd->ddma_id,
+                                       au1x_pcm_dmatx_cb, (void *)pcd);
+
+       if (!pcd->ddma_chan)
+               return -ENOMEM;;
+
+       au1xxx_dbdma_set_devwidth(pcd->ddma_chan, msbits);
+       au1xxx_dbdma_ring_alloc(pcd->ddma_chan, 2);
+
+       pcd->msbits = msbits;
+
+       au1xxx_dbdma_stop(pcd->ddma_chan);
+       au1xxx_dbdma_reset(pcd->ddma_chan);
+
+out:
+       return 0;
+}
+
+static int au1xpsc_pcm_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct au1xpsc_audio_dmadata *pcd;
+       int stype, ret;
+
+       ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
+       if (ret < 0)
+               goto out;
+
+       stype = SUBSTREAM_TYPE(substream);
+       pcd = au1xpsc_audio_pcmdma[stype];
+
+       DBG("runtime->dma_area = 0x%08lx dma_addr_t = 0x%08lx dma_size = %d "
+           "runtime->min_align %d\n",
+               (unsigned long)runtime->dma_area,
+               (unsigned long)runtime->dma_addr, runtime->dma_bytes,
+               runtime->min_align);
+
+       DBG("bits %d  frags %d  frag_bytes %d  is_rx %d\n", params->msbits,
+               params_periods(params), params_period_bytes(params), stype);
+
+       ret = au1x_pcm_dbdma_realloc(pcd, stype, params->msbits);
+       if (ret) {
+               MSG("DDMA channel (re)alloc failed!\n");
+               goto out;
+       }
+
+       pcd->substream = substream;
+       pcd->period_bytes = params_period_bytes(params);
+       pcd->periods = params_periods(params);
+       pcd->dma_area_s = pcd->dma_area = (unsigned long)runtime->dma_addr;
+       pcd->q_period = 0;
+       pcd->curr_period = 0;
+       pcd->pos = 0;
+
+       ret = 0;
+out:
+       return ret;
+}
+
+static int au1xpsc_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+       snd_pcm_lib_free_pages(substream);
+       return 0;
+}
+
+static int au1xpsc_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct au1xpsc_audio_dmadata *pcd =
+                       au1xpsc_audio_pcmdma[SUBSTREAM_TYPE(substream)];
+
+       au1xxx_dbdma_reset(pcd->ddma_chan);
+
+       if (SUBSTREAM_TYPE(substream) == PCM_RX) {
+               au1x_pcm_queue_rx(pcd);
+               au1x_pcm_queue_rx(pcd);
+       } else {
+               au1x_pcm_queue_tx(pcd);
+               au1x_pcm_queue_tx(pcd);
+       }
+
+       return 0;
+}
+
+static int au1xpsc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       u32 c = au1xpsc_audio_pcmdma[SUBSTREAM_TYPE(substream)]->ddma_chan;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               au1xxx_dbdma_start(c);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+               au1xxx_dbdma_stop(c);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static snd_pcm_uframes_t
+au1xpsc_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       return bytes_to_frames(substream->runtime,
+               au1xpsc_audio_pcmdma[SUBSTREAM_TYPE(substream)]->pos);
+}
+
+static int au1xpsc_pcm_open(struct snd_pcm_substream *substream)
+{
+       snd_soc_set_runtime_hwparams(substream, &au1xpsc_pcm_hardware);
+       return 0;
+}
+
+static int au1xpsc_pcm_close(struct snd_pcm_substream *substream)
+{
+       au1x_pcm_dbdma_free(au1xpsc_audio_pcmdma[SUBSTREAM_TYPE(substream)]);
+       return 0;
+}
+
+struct snd_pcm_ops au1xpsc_pcm_ops = {
+       .open           = au1xpsc_pcm_open,
+       .close          = au1xpsc_pcm_close,
+       .ioctl          = snd_pcm_lib_ioctl,
+       .hw_params      = au1xpsc_pcm_hw_params,
+       .hw_free        = au1xpsc_pcm_hw_free,
+       .prepare        = au1xpsc_pcm_prepare,
+       .trigger        = au1xpsc_pcm_trigger,
+       .pointer        = au1xpsc_pcm_pointer,
+};
+
+static void au1xpsc_pcm_free_dma_buffers(struct snd_pcm *pcm)
+{
+       snd_pcm_lib_preallocate_free_for_all(pcm);
+}
+
+static int au1xpsc_pcm_new(struct snd_card *card,
+                          struct snd_soc_dai *dai,
+                          struct snd_pcm *pcm)
+{
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+               card->dev, AU1XPSC_BUFFER_MIN_BYTES, (4096 * 1024) - 1);
+
+       return 0;
+}
+
+static int au1xpsc_pcm_probe(struct platform_device *pdev)
+{
+       struct resource *r;
+       int ret;
+
+       if (au1xpsc_audio_pcmdma[PCM_TX] || au1xpsc_audio_pcmdma[PCM_RX])
+               return -EBUSY;
+
+       /* TX DMA */
+       au1xpsc_audio_pcmdma[PCM_TX]
+               = kzalloc(sizeof(struct au1xpsc_audio_dmadata), GFP_KERNEL);
+       if (!au1xpsc_audio_pcmdma[PCM_TX])
+               return -ENOMEM;
+
+       r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!r) {
+               ret = -ENODEV;
+               goto out1;
+       }
+       (au1xpsc_audio_pcmdma[PCM_TX])->ddma_id = r->start;
+
+       /* RX DMA */
+       au1xpsc_audio_pcmdma[PCM_RX]
+               = kzalloc(sizeof(struct au1xpsc_audio_dmadata), GFP_KERNEL);
+       if (!au1xpsc_audio_pcmdma[PCM_RX])
+               return -ENOMEM;
+
+       r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!r) {
+               ret = -ENODEV;
+               goto out2;
+       }
+       (au1xpsc_audio_pcmdma[PCM_RX])->ddma_id = r->start;
+
+       return 0;
+
+out2:
+       kfree(au1xpsc_audio_pcmdma[PCM_RX]);
+       au1xpsc_audio_pcmdma[PCM_RX] = NULL;
+out1:
+       kfree(au1xpsc_audio_pcmdma[PCM_TX]);
+       au1xpsc_audio_pcmdma[PCM_TX] = NULL;
+       return ret;
+}
+
+static int au1xpsc_pcm_remove(struct platform_device *pdev)
+{
+       int i;
+
+       for (i = 0; i < 2; i++) {
+               if (au1xpsc_audio_pcmdma[i]) {
+                       au1x_pcm_dbdma_free(au1xpsc_audio_pcmdma[i]);
+                       kfree(au1xpsc_audio_pcmdma[i]);
+                       au1xpsc_audio_pcmdma[i] = NULL;
+               }
+       }
+
+       return 0;
+}
+
+/* au1xpsc audio platform */
+struct snd_soc_platform au1xpsc_soc_platform = {
+       .name           = "au1xpsc-pcm-dbdma",
+       .probe          = au1xpsc_pcm_probe,
+       .remove         = au1xpsc_pcm_remove,
+       .pcm_ops        = &au1xpsc_pcm_ops,
+       .pcm_new        = au1xpsc_pcm_new,
+       .pcm_free       = au1xpsc_pcm_free_dma_buffers,
+};
+EXPORT_SYMBOL_GPL(au1xpsc_soc_platform);
+
+static int __init au1xpsc_audio_dbdma_init(void)
+{
+       au1xpsc_audio_pcmdma[PCM_TX] = NULL;
+       au1xpsc_audio_pcmdma[PCM_RX] = NULL;
+       return 0;
+}
+
+static void __exit au1xpsc_audio_dbdma_exit(void)
+{
+}
+
+module_init(au1xpsc_audio_dbdma_init);
+module_exit(au1xpsc_audio_dbdma_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au12x0/Au1550 PSC Audio DMA driver");
+MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");
diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c
new file mode 100644 (file)
index 0000000..57facba
--- /dev/null
@@ -0,0 +1,387 @@
+/*
+ * Au12x0/Au1550 PSC ALSA ASoC audio support.
+ *
+ * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
+ *     Manuel Lauss <mano@roarinelk.homelinux.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Au1xxx-PSC AC97 glue.
+ *
+ * NOTE: all of these drivers can only work with a SINGLE instance
+ *      of a PSC. Multiple independent audio devices are impossible
+ *      with ASoC v1.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/suspend.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1xxx_psc.h>
+
+#include "psc.h"
+
+#define AC97_DIR       \
+       (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
+
+#define AC97_RATES     \
+       SNDRV_PCM_RATE_8000_48000
+
+#define AC97_FMTS      \
+       (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3BE)
+
+#define AC97PCR_START(stype)   \
+       ((stype) == PCM_TX ? PSC_AC97PCR_TS : PSC_AC97PCR_RS)
+#define AC97PCR_STOP(stype)    \
+       ((stype) == PCM_TX ? PSC_AC97PCR_TP : PSC_AC97PCR_RP)
+#define AC97PCR_CLRFIFO(stype) \
+       ((stype) == PCM_TX ? PSC_AC97PCR_TC : PSC_AC97PCR_RC)
+
+/* instance data. There can be only one, MacLeod!!!! */
+static struct au1xpsc_audio_data *au1xpsc_ac97_workdata;
+
+/* AC97 controller reads codec register */
+static unsigned short au1xpsc_ac97_read(struct snd_ac97 *ac97,
+                                       unsigned short reg)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+       unsigned short data, tmo;
+
+       au_writel(PSC_AC97CDC_RD | PSC_AC97CDC_INDX(reg), AC97_CDC(pscdata));
+       au_sync();
+
+       tmo = 1000;
+       while ((!(au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)) && --tmo)
+               udelay(2);
+
+       if (!tmo)
+               data = 0xffff;
+       else
+               data = au_readl(AC97_CDC(pscdata)) & 0xffff;
+
+       au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
+       au_sync();
+
+       return data;
+}
+
+/* AC97 controller writes to codec register */
+static void au1xpsc_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
+                               unsigned short val)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+       unsigned int tmo;
+
+       au_writel(PSC_AC97CDC_INDX(reg) | (val & 0xffff), AC97_CDC(pscdata));
+       au_sync();
+       tmo = 1000;
+       while ((!(au_readl(AC97_EVNT(pscdata)) & PSC_AC97EVNT_CD)) && --tmo)
+               au_sync();
+
+       au_writel(PSC_AC97EVNT_CD, AC97_EVNT(pscdata));
+       au_sync();
+}
+
+/* AC97 controller asserts a warm reset */
+static void au1xpsc_ac97_warm_reset(struct snd_ac97 *ac97)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+
+       au_writel(PSC_AC97RST_SNC, AC97_RST(pscdata));
+       au_sync();
+       msleep(10);
+       au_writel(0, AC97_RST(pscdata));
+       au_sync();
+}
+
+static void au1xpsc_ac97_cold_reset(struct snd_ac97 *ac97)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+       int i;
+
+       /* disable PSC during cold reset */
+       au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
+       au_sync();
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(pscdata));
+       au_sync();
+
+       /* issue cold reset */
+       au_writel(PSC_AC97RST_RST, AC97_RST(pscdata));
+       au_sync();
+       msleep(500);
+       au_writel(0, AC97_RST(pscdata));
+       au_sync();
+
+       /* enable PSC */
+       au_writel(PSC_CTRL_ENABLE, PSC_CTRL(pscdata));
+       au_sync();
+
+       /* wait for PSC to indicate it's ready */
+       i = 100000;
+       while (!((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_SR)) && (--i))
+               au_sync();
+
+       if (i == 0) {
+               printk(KERN_ERR "au1xpsc-ac97: PSC not ready!\n");
+               return;
+       }
+
+       /* enable the ac97 function */
+       au_writel(pscdata->cfg | PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
+       au_sync();
+
+       /* wait for AC97 core to become ready */
+       i = 100000;
+       while (!((au_readl(AC97_STAT(pscdata)) & PSC_AC97STAT_DR)) && (--i))
+               au_sync();
+       if (i == 0)
+               printk(KERN_ERR "au1xpsc-ac97: AC97 ctrl not ready\n");
+}
+
+/* AC97 controller operations */
+struct snd_ac97_bus_ops soc_ac97_ops = {
+       .read           = au1xpsc_ac97_read,
+       .write          = au1xpsc_ac97_write,
+       .reset          = au1xpsc_ac97_cold_reset,
+       .warm_reset     = au1xpsc_ac97_warm_reset,
+};
+EXPORT_SYMBOL_GPL(soc_ac97_ops);
+
+static int au1xpsc_ac97_hw_params(struct snd_pcm_substream *substream,
+                                 struct snd_pcm_hw_params *params)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+       unsigned long r, stat;
+       int chans, stype = SUBSTREAM_TYPE(substream);
+
+       chans = params_channels(params);
+
+       r = au_readl(AC97_CFG(pscdata));
+       stat = au_readl(AC97_STAT(pscdata));
+
+       /* already active? */
+       if (stat & (PSC_AC97STAT_TB | PSC_AC97STAT_RB)) {
+               /* reject parameters not currently set up */
+               if ((PSC_AC97CFG_GET_LEN(r) != params->msbits) ||
+                   (pscdata->rate != params_rate(params)))
+                       return -EINVAL;
+       } else {
+               /* disable AC97 device controller first */
+               au_writel(r & ~PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
+               au_sync();
+
+               /* set sample bitdepth: REG[24:21]=(BITS-2)/2 */
+               r &= ~PSC_AC97CFG_LEN_MASK;
+               r |= PSC_AC97CFG_SET_LEN(params->msbits);
+
+               /* channels: enable slots for front L/R channel */
+               if (stype == PCM_TX) {
+                       r &= ~PSC_AC97CFG_TXSLOT_MASK;
+                       r |= PSC_AC97CFG_TXSLOT_ENA(3);
+                       r |= PSC_AC97CFG_TXSLOT_ENA(4);
+               } else {
+                       r &= ~PSC_AC97CFG_RXSLOT_MASK;
+                       r |= PSC_AC97CFG_RXSLOT_ENA(3);
+                       r |= PSC_AC97CFG_RXSLOT_ENA(4);
+               }
+
+               /* finally enable the AC97 controller again */
+               au_writel(r | PSC_AC97CFG_DE_ENABLE, AC97_CFG(pscdata));
+               au_sync();
+
+               pscdata->cfg = r;
+               pscdata->rate = params_rate(params);
+       }
+
+       return 0;
+}
+
+static int au1xpsc_ac97_trigger(struct snd_pcm_substream *substream,
+                               int cmd)
+{
+       /* FIXME */
+       struct au1xpsc_audio_data *pscdata = au1xpsc_ac97_workdata;
+       int ret, stype = SUBSTREAM_TYPE(substream);
+
+       ret = 0;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               au_writel(AC97PCR_START(stype), AC97_PCR(pscdata));
+               au_sync();
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+               au_writel(AC97PCR_STOP(stype), AC97_PCR(pscdata));
+               au_sync();
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+static int au1xpsc_ac97_probe(struct platform_device *pdev,
+                             struct snd_soc_dai *dai)
+{
+       int ret;
+       struct resource *r;
+       unsigned long sel;
+
+       if (au1xpsc_ac97_workdata)
+               return -EBUSY;
+
+       au1xpsc_ac97_workdata =
+               kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
+       if (!au1xpsc_ac97_workdata)
+               return -ENOMEM;
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!r) {
+               ret = -ENODEV;
+               goto out0;
+       }
+
+       ret = -EBUSY;
+       au1xpsc_ac97_workdata->ioarea =
+               request_mem_region(r->start, r->end - r->start + 1,
+                                       "au1xpsc_ac97");
+       if (!au1xpsc_ac97_workdata->ioarea)
+               goto out0;
+
+       au1xpsc_ac97_workdata->mmio = ioremap(r->start, 0xffff);
+       if (!au1xpsc_ac97_workdata->mmio)
+               goto out1;
+
+       /* configuration: max dma trigger threshold, enable ac97 */
+        au1xpsc_ac97_workdata->cfg = PSC_AC97CFG_RT_FIFO8 |
+                                     PSC_AC97CFG_TT_FIFO8 |
+                                     PSC_AC97CFG_DE_ENABLE;
+
+       /* preserve PSC clock source set up by platform (dev.platform_data
+        * is already occupied by soc layer)
+        */
+       sel = au_readl(PSC_SEL(au1xpsc_ac97_workdata)) & PSC_SEL_CLK_MASK;
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
+       au_sync();
+       au_writel(0, PSC_SEL(au1xpsc_ac97_workdata));
+       au_sync();
+       au_writel(PSC_SEL_PS_AC97MODE | sel, PSC_SEL(au1xpsc_ac97_workdata));
+       au_sync();
+       /* next up: cold reset.  Dont check for PSC-ready now since
+        * there may not be any codec clock yet.
+        */
+
+       return 0;
+
+out1:
+       release_resource(au1xpsc_ac97_workdata->ioarea);
+       kfree(au1xpsc_ac97_workdata->ioarea);
+out0:
+       kfree(au1xpsc_ac97_workdata);
+       au1xpsc_ac97_workdata = NULL;
+       return ret;
+}
+
+static void au1xpsc_ac97_remove(struct platform_device *pdev,
+                               struct snd_soc_dai *dai)
+{
+       /* disable PSC completely */
+       au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
+       au_sync();
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
+       au_sync();
+
+       iounmap(au1xpsc_ac97_workdata->mmio);
+       release_resource(au1xpsc_ac97_workdata->ioarea);
+       kfree(au1xpsc_ac97_workdata->ioarea);
+       kfree(au1xpsc_ac97_workdata);
+       au1xpsc_ac97_workdata = NULL;
+}
+
+static int au1xpsc_ac97_suspend(struct platform_device *pdev,
+                               struct snd_soc_dai *dai)
+{
+       /* save interesting registers and disable PSC */
+       au1xpsc_ac97_workdata->pm[0] =
+                       au_readl(PSC_SEL(au1xpsc_ac97_workdata));
+
+       au_writel(0, AC97_CFG(au1xpsc_ac97_workdata));
+       au_sync();
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_ac97_workdata));
+       au_sync();
+
+       return 0;
+}
+
+static int au1xpsc_ac97_resume(struct platform_device *pdev,
+                              struct snd_soc_dai *dai)
+{
+       /* restore PSC clock config */
+       au_writel(au1xpsc_ac97_workdata->pm[0] | PSC_SEL_PS_AC97MODE,
+                       PSC_SEL(au1xpsc_ac97_workdata));
+       au_sync();
+
+       /* after this point the ac97 core will cold-reset the codec.
+        * During cold-reset the PSC is reinitialized and the last
+        * configuration set up in hw_params() is restored.
+        */
+       return 0;
+}
+
+struct snd_soc_dai au1xpsc_ac97_dai = {
+       .name                   = "au1xpsc_ac97",
+       .type                   = SND_SOC_DAI_AC97,
+       .probe                  = au1xpsc_ac97_probe,
+       .remove                 = au1xpsc_ac97_remove,
+       .suspend                = au1xpsc_ac97_suspend,
+       .resume                 = au1xpsc_ac97_resume,
+       .playback = {
+               .rates          = AC97_RATES,
+               .formats        = AC97_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .capture = {
+               .rates          = AC97_RATES,
+               .formats        = AC97_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 2,
+       },
+       .ops = {
+               .trigger        = au1xpsc_ac97_trigger,
+               .hw_params      = au1xpsc_ac97_hw_params,
+       },
+};
+EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai);
+
+static int __init au1xpsc_ac97_init(void)
+{
+       au1xpsc_ac97_workdata = NULL;
+       return 0;
+}
+
+static void __exit au1xpsc_ac97_exit(void)
+{
+}
+
+module_init(au1xpsc_ac97_init);
+module_exit(au1xpsc_ac97_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au12x0/Au1550 PSC AC97 ALSA ASoC audio driver");
+MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");
diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c
new file mode 100644 (file)
index 0000000..ba4b5c1
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ * Au12x0/Au1550 PSC ALSA ASoC audio support.
+ *
+ * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
+ *     Manuel Lauss <mano@roarinelk.homelinux.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Au1xxx-PSC I2S glue.
+ *
+ * NOTE: all of these drivers can only work with a SINGLE instance
+ *      of a PSC. Multiple independent audio devices are impossible
+ *      with ASoC v1.
+ * NOTE: so far only PSC slave mode (bit- and frameclock) is supported.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/suspend.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1xxx_psc.h>
+
+#include "psc.h"
+
+/* supported I2S DAI hardware formats */
+#define AU1XPSC_I2S_DAIFMT \
+       (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J |   \
+        SND_SOC_DAIFMT_NB_NF)
+
+/* supported I2S direction */
+#define AU1XPSC_I2S_DIR \
+       (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
+
+#define AU1XPSC_I2S_RATES \
+       SNDRV_PCM_RATE_8000_192000
+
+#define AU1XPSC_I2S_FMTS \
+       (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
+
+#define I2SSTAT_BUSY(stype)    \
+       ((stype) == PCM_TX ? PSC_I2SSTAT_TB : PSC_I2SSTAT_RB)
+#define I2SPCR_START(stype)    \
+       ((stype) == PCM_TX ? PSC_I2SPCR_TS : PSC_I2SPCR_RS)
+#define I2SPCR_STOP(stype)     \
+       ((stype) == PCM_TX ? PSC_I2SPCR_TP : PSC_I2SPCR_RP)
+#define I2SPCR_CLRFIFO(stype)  \
+       ((stype) == PCM_TX ? PSC_I2SPCR_TC : PSC_I2SPCR_RC)
+
+
+/* instance data. There can be only one, MacLeod!!!! */
+static struct au1xpsc_audio_data *au1xpsc_i2s_workdata;
+
+static int au1xpsc_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
+                              unsigned int fmt)
+{
+       struct au1xpsc_audio_data *pscdata = au1xpsc_i2s_workdata;
+       unsigned long ct;
+       int ret;
+
+       ret = -EINVAL;
+
+       ct = pscdata->cfg;
+
+       ct &= ~(PSC_I2SCFG_XM | PSC_I2SCFG_MLJ);        /* left-justified */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               ct |= PSC_I2SCFG_XM;    /* enable I2S mode */
+               break;
+       case SND_SOC_DAIFMT_MSB:
+               break;
+       case SND_SOC_DAIFMT_LSB:
+               ct |= PSC_I2SCFG_MLJ;   /* LSB (right-) justified */
+               break;
+       default:
+               goto out;
+       }
+
+       ct &= ~(PSC_I2SCFG_BI | PSC_I2SCFG_WI);         /* IB-IF */
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               ct |= PSC_I2SCFG_BI | PSC_I2SCFG_WI;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               ct |= PSC_I2SCFG_BI;
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               ct |= PSC_I2SCFG_WI;
+               break;
+       case SND_SOC_DAIFMT_IB_IF:
+               break;
+       default:
+               goto out;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:    /* CODEC master */
+               ct |= PSC_I2SCFG_MS;    /* PSC I2S slave mode */
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:    /* CODEC slave */
+               ct &= ~PSC_I2SCFG_MS;   /* PSC I2S Master mode */
+               break;
+       default:
+               goto out;
+       }
+
+       pscdata->cfg = ct;
+       ret = 0;
+out:
+       return ret;
+}
+
+static int au1xpsc_i2s_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params)
+{
+       struct au1xpsc_audio_data *pscdata = au1xpsc_i2s_workdata;
+
+       int cfgbits;
+       unsigned long stat;
+
+       /* check if the PSC is already streaming data */
+       stat = au_readl(I2S_STAT(pscdata));
+       if (stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB)) {
+               /* reject parameters not currently set up in hardware */
+               cfgbits = au_readl(I2S_CFG(pscdata));
+               if ((PSC_I2SCFG_GET_LEN(cfgbits) != params->msbits) ||
+                   (params_rate(params) != pscdata->rate))
+                       return -EINVAL;
+       } else {
+               /* set sample bitdepth */
+               pscdata->cfg &= ~(0x1f << 4);
+               pscdata->cfg |= PSC_I2SCFG_SET_LEN(params->msbits);
+               /* remember current rate for other stream */
+               pscdata->rate = params_rate(params);
+       }
+       return 0;
+}
+
+/* Configure PSC late:  on my devel systems the codec  is I2S master and
+ * supplies the i2sbitclock __AND__ i2sMclk (!) to the PSC unit.  ASoC
+ * uses aggressive PM and  switches the codec off  when it is not in use
+ * which also means the PSC unit doesn't get any clocks and is therefore
+ * dead. That's why this chunk here gets called from the trigger callback
+ * because I can be reasonably certain the codec is driving the clocks.
+ */
+static int au1xpsc_i2s_configure(struct au1xpsc_audio_data *pscdata)
+{
+       unsigned long tmo;
+
+       /* bring PSC out of sleep, and configure I2S unit */
+       au_writel(PSC_CTRL_ENABLE, PSC_CTRL(pscdata));
+       au_sync();
+
+       tmo = 1000000;
+       while (!(au_readl(I2S_STAT(pscdata)) & PSC_I2SSTAT_SR) && tmo)
+               tmo--;
+
+       if (!tmo)
+               goto psc_err;
+
+       au_writel(0, I2S_CFG(pscdata));
+       au_sync();
+       au_writel(pscdata->cfg | PSC_I2SCFG_DE_ENABLE, I2S_CFG(pscdata));
+       au_sync();
+
+       /* wait for I2S controller to become ready */
+       tmo = 1000000;
+       while (!(au_readl(I2S_STAT(pscdata)) & PSC_I2SSTAT_DR) && tmo)
+               tmo--;
+
+       if (tmo)
+               return 0;
+
+psc_err:
+       au_writel(0, I2S_CFG(pscdata));
+       au_writel(PSC_CTRL_SUSPEND, PSC_CTRL(pscdata));
+       au_sync();
+       return -ETIMEDOUT;
+}
+
+static int au1xpsc_i2s_start(struct au1xpsc_audio_data *pscdata, int stype)
+{
+       unsigned long tmo, stat;
+       int ret;
+
+       ret = 0;
+
+       /* if both TX and RX are idle, configure the PSC  */
+       stat = au_readl(I2S_STAT(pscdata));
+       if (!(stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB))) {
+               ret = au1xpsc_i2s_configure(pscdata);
+               if (ret)
+                       goto out;
+       }
+
+       au_writel(I2SPCR_CLRFIFO(stype), I2S_PCR(pscdata));
+       au_sync();
+       au_writel(I2SPCR_START(stype), I2S_PCR(pscdata));
+       au_sync();
+
+       /* wait for start confirmation */
+       tmo = 1000000;
+       while (!(au_readl(I2S_STAT(pscdata)) & I2SSTAT_BUSY(stype)) && tmo)
+               tmo--;
+
+       if (!tmo) {
+               au_writel(I2SPCR_STOP(stype), I2S_PCR(pscdata));
+               au_sync();
+               ret = -ETIMEDOUT;
+       }
+out:
+       return ret;
+}
+
+static int au1xpsc_i2s_stop(struct au1xpsc_audio_data *pscdata, int stype)
+{
+       unsigned long tmo, stat;
+
+       au_writel(I2SPCR_STOP(stype), I2S_PCR(pscdata));
+       au_sync();
+
+       /* wait for stop confirmation */
+       tmo = 1000000;
+       while ((au_readl(I2S_STAT(pscdata)) & I2SSTAT_BUSY(stype)) && tmo)
+               tmo--;
+
+       /* if both TX and RX are idle, disable PSC */
+       stat = au_readl(I2S_STAT(pscdata));
+       if (!(stat & (PSC_I2SSTAT_RB | PSC_I2SSTAT_RB))) {
+               au_writel(0, I2S_CFG(pscdata));
+               au_sync();
+               au_writel(PSC_CTRL_SUSPEND, PSC_CTRL(pscdata));
+               au_sync();
+       }
+       return 0;
+}
+
+static int au1xpsc_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct au1xpsc_audio_data *pscdata = au1xpsc_i2s_workdata;
+       int ret, stype = SUBSTREAM_TYPE(substream);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               ret = au1xpsc_i2s_start(pscdata, stype);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+               ret = au1xpsc_i2s_stop(pscdata, stype);
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+static int au1xpsc_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
+{
+       struct resource *r;
+       unsigned long sel;
+       int ret;
+
+       if (au1xpsc_i2s_workdata)
+               return -EBUSY;
+
+       au1xpsc_i2s_workdata =
+               kzalloc(sizeof(struct au1xpsc_audio_data), GFP_KERNEL);
+       if (!au1xpsc_i2s_workdata)
+               return -ENOMEM;
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!r) {
+               ret = -ENODEV;
+               goto out0;
+       }
+
+       ret = -EBUSY;
+       au1xpsc_i2s_workdata->ioarea =
+               request_mem_region(r->start, r->end - r->start + 1,
+                                       "au1xpsc_i2s");
+       if (!au1xpsc_i2s_workdata->ioarea)
+               goto out0;
+
+       au1xpsc_i2s_workdata->mmio = ioremap(r->start, 0xffff);
+       if (!au1xpsc_i2s_workdata->mmio)
+               goto out1;
+
+       /* preserve PSC clock source set up by platform (dev.platform_data
+        * is already occupied by soc layer)
+        */
+       sel = au_readl(PSC_SEL(au1xpsc_i2s_workdata)) & PSC_SEL_CLK_MASK;
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata));
+       au_sync();
+       au_writel(PSC_SEL_PS_I2SMODE | sel, PSC_SEL(au1xpsc_i2s_workdata));
+       au_writel(0, I2S_CFG(au1xpsc_i2s_workdata));
+       au_sync();
+
+       /* preconfigure: set max rx/tx fifo depths */
+       au1xpsc_i2s_workdata->cfg |=
+                       PSC_I2SCFG_RT_FIFO8 | PSC_I2SCFG_TT_FIFO8;
+
+       /* don't wait for I2S core to become ready now; clocks may not
+        * be running yet; depending on clock input for PSC a wait might
+        * time out.
+        */
+
+       return 0;
+
+out1:
+       release_resource(au1xpsc_i2s_workdata->ioarea);
+       kfree(au1xpsc_i2s_workdata->ioarea);
+out0:
+       kfree(au1xpsc_i2s_workdata);
+       au1xpsc_i2s_workdata = NULL;
+       return ret;
+}
+
+static void au1xpsc_i2s_remove(struct platform_device *pdev,
+                              struct snd_soc_dai *dai)
+{
+       au_writel(0, I2S_CFG(au1xpsc_i2s_workdata));
+       au_sync();
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata));
+       au_sync();
+
+       iounmap(au1xpsc_i2s_workdata->mmio);
+       release_resource(au1xpsc_i2s_workdata->ioarea);
+       kfree(au1xpsc_i2s_workdata->ioarea);
+       kfree(au1xpsc_i2s_workdata);
+       au1xpsc_i2s_workdata = NULL;
+}
+
+static int au1xpsc_i2s_suspend(struct platform_device *pdev,
+                              struct snd_soc_dai *cpu_dai)
+{
+       /* save interesting register and disable PSC */
+       au1xpsc_i2s_workdata->pm[0] =
+               au_readl(PSC_SEL(au1xpsc_i2s_workdata));
+
+       au_writel(0, I2S_CFG(au1xpsc_i2s_workdata));
+       au_sync();
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata));
+       au_sync();
+
+       return 0;
+}
+
+static int au1xpsc_i2s_resume(struct platform_device *pdev,
+                             struct snd_soc_dai *cpu_dai)
+{
+       /* select I2S mode and PSC clock */
+       au_writel(PSC_CTRL_DISABLE, PSC_CTRL(au1xpsc_i2s_workdata));
+       au_sync();
+       au_writel(0, PSC_SEL(au1xpsc_i2s_workdata));
+       au_sync();
+       au_writel(au1xpsc_i2s_workdata->pm[0],
+                       PSC_SEL(au1xpsc_i2s_workdata));
+       au_sync();
+
+       return 0;
+}
+
+struct snd_soc_dai au1xpsc_i2s_dai = {
+       .name                   = "au1xpsc_i2s",
+       .type                   = SND_SOC_DAI_I2S,
+       .probe                  = au1xpsc_i2s_probe,
+       .remove                 = au1xpsc_i2s_remove,
+       .suspend                = au1xpsc_i2s_suspend,
+       .resume                 = au1xpsc_i2s_resume,
+       .playback = {
+               .rates          = AU1XPSC_I2S_RATES,
+               .formats        = AU1XPSC_I2S_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 8,    /* 2 without external help */
+       },
+       .capture = {
+               .rates          = AU1XPSC_I2S_RATES,
+               .formats        = AU1XPSC_I2S_FMTS,
+               .channels_min   = 2,
+               .channels_max   = 8,    /* 2 without external help */
+       },
+       .ops = {
+               .trigger        = au1xpsc_i2s_trigger,
+               .hw_params      = au1xpsc_i2s_hw_params,
+       },
+       .dai_ops = {
+               .set_fmt        = au1xpsc_i2s_set_fmt,
+       },
+};
+EXPORT_SYMBOL(au1xpsc_i2s_dai);
+
+static int __init au1xpsc_i2s_init(void)
+{
+       au1xpsc_i2s_workdata = NULL;
+       return 0;
+}
+
+static void __exit au1xpsc_i2s_exit(void)
+{
+}
+
+module_init(au1xpsc_i2s_init);
+module_exit(au1xpsc_i2s_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au12x0/Au1550 PSC I2S ALSA ASoC audio driver");
+MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");
diff --git a/sound/soc/au1x/psc.h b/sound/soc/au1x/psc.h
new file mode 100644 (file)
index 0000000..8fdb1a0
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Au12x0/Au1550 PSC ALSA ASoC audio support.
+ *
+ * (c) 2007-2008 MSC Vertriebsges.m.b.H.,
+ *     Manuel Lauss <mano@roarinelk.homelinux.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * NOTE: all of these drivers can only work with a SINGLE instance
+ *      of a PSC. Multiple independent audio devices are impossible
+ *      with ASoC v1.
+ */
+
+#ifndef _AU1X_PCM_H
+#define _AU1X_PCM_H
+
+extern struct snd_soc_dai au1xpsc_ac97_dai;
+extern struct snd_soc_dai au1xpsc_i2s_dai;
+extern struct snd_soc_platform au1xpsc_soc_platform;
+extern struct snd_ac97_bus_ops soc_ac97_ops;
+
+struct au1xpsc_audio_data {
+       void __iomem *mmio;
+
+       unsigned long cfg;
+       unsigned long rate;
+
+       unsigned long pm[2];
+       struct resource *ioarea;
+};
+
+#define PCM_TX 0
+#define PCM_RX 1
+
+#define SUBSTREAM_TYPE(substream) \
+       ((substream)->stream == SNDRV_PCM_STREAM_PLAYBACK ? PCM_TX : PCM_RX)
+
+/* easy access macros */
+#define PSC_CTRL(x)    ((unsigned long)((x)->mmio) + PSC_CTRL_OFFSET)
+#define PSC_SEL(x)     ((unsigned long)((x)->mmio) + PSC_SEL_OFFSET)
+#define I2S_STAT(x)    ((unsigned long)((x)->mmio) + PSC_I2SSTAT_OFFSET)
+#define I2S_CFG(x)     ((unsigned long)((x)->mmio) + PSC_I2SCFG_OFFSET)
+#define I2S_PCR(x)     ((unsigned long)((x)->mmio) + PSC_I2SPCR_OFFSET)
+#define AC97_CFG(x)    ((unsigned long)((x)->mmio) + PSC_AC97CFG_OFFSET)
+#define AC97_CDC(x)    ((unsigned long)((x)->mmio) + PSC_AC97CDC_OFFSET)
+#define AC97_EVNT(x)   ((unsigned long)((x)->mmio) + PSC_AC97EVNT_OFFSET)
+#define AC97_PCR(x)    ((unsigned long)((x)->mmio) + PSC_AC97PCR_OFFSET)
+#define AC97_RST(x)    ((unsigned long)((x)->mmio) + PSC_AC97RST_OFFSET)
+#define AC97_STAT(x)   ((unsigned long)((x)->mmio) + PSC_AC97STAT_OFFSET)
+
+#endif
diff --git a/sound/soc/au1x/sample-ac97.c b/sound/soc/au1x/sample-ac97.c
new file mode 100644 (file)
index 0000000..f75ae7f
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Sample Au12x0/Au1550 PSC AC97 sound machine.
+ *
+ * Copyright (c) 2007-2008 Manuel Lauss <mano@roarinelk.homelinux.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms outlined in the file COPYING at the root of this
+ *  source archive.
+ *
+ * This is a very generic AC97 sound machine driver for boards which
+ * have (AC97) audio at PSC1 (e.g. DB1200 demoboards).
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <asm/mach-au1x00/au1000.h>
+#include <asm/mach-au1x00/au1xxx_psc.h>
+#include <asm/mach-au1x00/au1xxx_dbdma.h>
+
+#include "../codecs/ac97.h"
+#include "psc.h"
+
+static int au1xpsc_sample_ac97_init(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_sync(codec);
+       return 0;
+}
+
+static struct snd_soc_dai_link au1xpsc_sample_ac97_dai = {
+       .name           = "AC97",
+       .stream_name    = "AC97 HiFi",
+       .cpu_dai        = &au1xpsc_ac97_dai,    /* see psc-ac97.c */
+       .codec_dai      = &ac97_dai,            /* see codecs/ac97.c */
+       .init           = au1xpsc_sample_ac97_init,
+       .ops            = NULL,
+};
+
+static struct snd_soc_machine au1xpsc_sample_ac97_machine = {
+       .name           = "Au1xxx PSC AC97 Audio",
+       .dai_link       = &au1xpsc_sample_ac97_dai,
+       .num_links      = 1,
+};
+
+static struct snd_soc_device au1xpsc_sample_ac97_devdata = {
+       .machine        = &au1xpsc_sample_ac97_machine,
+       .platform       = &au1xpsc_soc_platform, /* see dbdma2.c */
+       .codec_dev      = &soc_codec_dev_ac97,
+};
+
+static struct resource au1xpsc_psc1_res[] = {
+       [0] = {
+               .start  = CPHYSADDR(PSC1_BASE_ADDR),
+               .end    = CPHYSADDR(PSC1_BASE_ADDR) + 0x000fffff,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+#ifdef CONFIG_SOC_AU1200
+               .start  = AU1200_PSC1_INT,
+               .end    = AU1200_PSC1_INT,
+#elif defined(CONFIG_SOC_AU1550)
+               .start  = AU1550_PSC1_INT,
+               .end    = AU1550_PSC1_INT,
+#endif
+               .flags  = IORESOURCE_IRQ,
+       },
+       [2] = {
+               .start  = DSCR_CMD0_PSC1_TX,
+               .end    = DSCR_CMD0_PSC1_TX,
+               .flags  = IORESOURCE_DMA,
+       },
+       [3] = {
+               .start  = DSCR_CMD0_PSC1_RX,
+               .end    = DSCR_CMD0_PSC1_RX,
+               .flags  = IORESOURCE_DMA,
+       },
+};
+
+static struct platform_device *au1xpsc_sample_ac97_dev;
+
+static int __init au1xpsc_sample_ac97_load(void)
+{
+       int ret;
+
+#ifdef CONFIG_SOC_AU1200
+       unsigned long io;
+
+       /* modify sys_pinfunc for AC97 on PSC1 */
+       io = au_readl(SYS_PINFUNC);
+       io |= SYS_PINFUNC_P1C;
+       io &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B);
+       au_writel(io, SYS_PINFUNC);
+       au_sync();
+#endif
+
+       ret = -ENOMEM;
+
+       /* setup PSC clock source for AC97 part: external clock provided
+        * by codec.  The psc-ac97.c driver depends on this setting!
+        */
+       au_writel(PSC_SEL_CLK_SERCLK, PSC1_BASE_ADDR + PSC_SEL_OFFSET);
+       au_sync();
+
+       au1xpsc_sample_ac97_dev = platform_device_alloc("soc-audio", -1);
+       if (!au1xpsc_sample_ac97_dev)
+               goto out;
+
+       au1xpsc_sample_ac97_dev->resource =
+               kmemdup(au1xpsc_psc1_res, sizeof(struct resource) *
+                       ARRAY_SIZE(au1xpsc_psc1_res), GFP_KERNEL);
+       au1xpsc_sample_ac97_dev->num_resources = ARRAY_SIZE(au1xpsc_psc1_res);
+       au1xpsc_sample_ac97_dev->id = 1;
+
+       platform_set_drvdata(au1xpsc_sample_ac97_dev,
+                            &au1xpsc_sample_ac97_devdata);
+       au1xpsc_sample_ac97_devdata.dev = &au1xpsc_sample_ac97_dev->dev;
+       ret = platform_device_add(au1xpsc_sample_ac97_dev);
+
+       if (ret) {
+               platform_device_put(au1xpsc_sample_ac97_dev);
+               au1xpsc_sample_ac97_dev = NULL;
+       }
+
+out:
+       return ret;
+}
+
+static void __exit au1xpsc_sample_ac97_exit(void)
+{
+       platform_device_unregister(au1xpsc_sample_ac97_dev);
+}
+
+module_init(au1xpsc_sample_ac97_load);
+module_exit(au1xpsc_sample_ac97_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Au1xxx PSC sample AC97 machine");
+MODULE_AUTHOR("Manuel Lauss <mano@roarinelk.homelinux.net>");
index 3903ab7..1db04a2 100644 (file)
@@ -1,31 +1,37 @@
 config SND_SOC_AC97_CODEC
        tristate
-       depends on SND_SOC
+       select SND_AC97_CODEC
+
+config SND_SOC_AK4535
+       tristate
+
+config SND_SOC_UDA1380
+        tristate
+
+config SND_SOC_WM8510
+       tristate
 
 config SND_SOC_WM8731
        tristate
-       depends on SND_SOC
 
 config SND_SOC_WM8750
        tristate
-       depends on SND_SOC
 
 config SND_SOC_WM8753
        tristate
-       depends on SND_SOC
+
+config SND_SOC_WM8990
+       tristate
 
 config SND_SOC_WM9712
        tristate
-       depends on SND_SOC
 
 config SND_SOC_WM9713
        tristate
-       depends on SND_SOC
 
 # Cirrus Logic CS4270 Codec
 config SND_SOC_CS4270
        tristate
-       depends on SND_SOC
 
 # Cirrus Logic CS4270 Codec Hardware Mute Support
 # Select if you have external muting circuitry attached to your CS4270.
@@ -43,4 +49,4 @@ config SND_SOC_CS4270_VD33_ERRATA
 
 config SND_SOC_TLV320AIC3X
        tristate
-       depends on SND_SOC && I2C
+       depends on I2C
index 4e1314c..d7b97ab 100644 (file)
@@ -1,16 +1,24 @@
 snd-soc-ac97-objs := ac97.o
+snd-soc-ak4535-objs := ak4535.o
+snd-soc-uda1380-objs := uda1380.o
+snd-soc-wm8510-objs := wm8510.o
 snd-soc-wm8731-objs := wm8731.o
 snd-soc-wm8750-objs := wm8750.o
 snd-soc-wm8753-objs := wm8753.o
+snd-soc-wm8990-objs := wm8990.o
 snd-soc-wm9712-objs := wm9712.o
 snd-soc-wm9713-objs := wm9713.o
 snd-soc-cs4270-objs := cs4270.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
 
 obj-$(CONFIG_SND_SOC_AC97_CODEC)       += snd-soc-ac97.o
+obj-$(CONFIG_SND_SOC_AK4535)   += snd-soc-ak4535.o
+obj-$(CONFIG_SND_SOC_UDA1380)  += snd-soc-uda1380.o
+obj-$(CONFIG_SND_SOC_WM8510)   += snd-soc-wm8510.o
 obj-$(CONFIG_SND_SOC_WM8731)   += snd-soc-wm8731.o
 obj-$(CONFIG_SND_SOC_WM8750)   += snd-soc-wm8750.o
 obj-$(CONFIG_SND_SOC_WM8753)   += snd-soc-wm8753.o
+obj-$(CONFIG_SND_SOC_WM8990)   += snd-soc-wm8990.o
 obj-$(CONFIG_SND_SOC_WM9712)   += snd-soc-wm9712.o
 obj-$(CONFIG_SND_SOC_WM9713)   += snd-soc-wm9713.o
 obj-$(CONFIG_SND_SOC_CS4270)   += snd-soc-cs4270.o
index 2a1ffe3..61fd96c 100644 (file)
@@ -10,9 +10,6 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    17th Oct 2005   Initial version.
- *
  * Generic AC97 support.
  */
 
@@ -24,6 +21,7 @@
 #include <sound/ac97_codec.h>
 #include <sound/initval.h>
 #include <sound/soc.h>
+#include "ac97.h"
 
 #define AC97_VERSION "0.6"
 
@@ -43,7 +41,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream)
                SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
                SNDRV_PCM_RATE_48000)
 
-struct snd_soc_codec_dai ac97_dai = {
+struct snd_soc_dai ac97_dai = {
        .name = "AC97 HiFi",
        .type = SND_SOC_DAI_AC97,
        .playback = {
@@ -146,9 +144,34 @@ static int ac97_soc_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int ac97_soc_suspend(struct platform_device *pdev, pm_message_t msg)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_ac97_suspend(socdev->codec->ac97);
+
+       return 0;
+}
+
+static int ac97_soc_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_ac97_resume(socdev->codec->ac97);
+
+       return 0;
+}
+#else
+#define ac97_soc_suspend NULL
+#define ac97_soc_resume NULL
+#endif
+
 struct snd_soc_codec_device soc_codec_dev_ac97 = {
        .probe =        ac97_soc_probe,
        .remove =       ac97_soc_remove,
+       .suspend =      ac97_soc_suspend,
+       .resume =       ac97_soc_resume,
 };
 EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
 
index 2bf6d69..281aa42 100644 (file)
@@ -14,6 +14,6 @@
 #define __LINUX_SND_SOC_AC97_H
 
 extern struct snd_soc_codec_device soc_codec_dev_ac97;
-extern struct snd_soc_codec_dai ac97_dai;
+extern struct snd_soc_dai ac97_dai;
 
 #endif
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
new file mode 100644 (file)
index 0000000..b26003c
--- /dev/null
@@ -0,0 +1,696 @@
+/*
+ * ak4535.c  --  AK4535 ALSA Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.c by Liam Girdwood
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "ak4535.h"
+
+#define AUDIO_NAME "ak4535"
+#define AK4535_VERSION "0.3"
+
+struct snd_soc_codec_device soc_codec_dev_ak4535;
+
+/* codec private data */
+struct ak4535_priv {
+       unsigned int sysclk;
+};
+
+/*
+ * ak4535 register cache
+ */
+static const u16 ak4535_reg[AK4535_CACHEREGNUM] = {
+    0x0000, 0x0080, 0x0000, 0x0003,
+    0x0002, 0x0000, 0x0011, 0x0001,
+    0x0000, 0x0040, 0x0036, 0x0010,
+    0x0000, 0x0000, 0x0057, 0x0000,
+};
+
+/*
+ * read ak4535 register cache
+ */
+static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec,
+       unsigned int reg)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg >= AK4535_CACHEREGNUM)
+               return -1;
+       return cache[reg];
+}
+
+static inline unsigned int ak4535_read(struct snd_soc_codec *codec,
+       unsigned int reg)
+{
+       u8 data;
+       data = reg;
+
+       if (codec->hw_write(codec->control_data, &data, 1) != 1)
+               return -EIO;
+
+       if (codec->hw_read(codec->control_data, &data, 1) != 1)
+               return -EIO;
+
+       return data;
+};
+
+/*
+ * write ak4535 register cache
+ */
+static inline void ak4535_write_reg_cache(struct snd_soc_codec *codec,
+       u16 reg, unsigned int value)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg >= AK4535_CACHEREGNUM)
+               return;
+       cache[reg] = value;
+}
+
+/*
+ * write to the AK4535 register space
+ */
+static int ak4535_write(struct snd_soc_codec *codec, unsigned int reg,
+       unsigned int value)
+{
+       u8 data[2];
+
+       /* data is
+        *   D15..D8 AK4535 register offset
+        *   D7...D0 register data
+        */
+       data[0] = reg & 0xff;
+       data[1] = value & 0xff;
+
+       ak4535_write_reg_cache(codec, reg, value);
+       if (codec->hw_write(codec->control_data, data, 2) == 2)
+               return 0;
+       else
+               return -EIO;
+}
+
+static int ak4535_sync(struct snd_soc_codec *codec)
+{
+       u16 *cache = codec->reg_cache;
+       int i, r = 0;
+
+       for (i = 0; i < AK4535_CACHEREGNUM; i++)
+               r |= ak4535_write(codec, i, cache[i]);
+
+       return r;
+};
+
+static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"};
+static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"};
+static const char *ak4535_hp_out[] = {"Stereo", "Mono"};
+static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"};
+static const char *ak4535_mic_select[] = {"Internal", "External"};
+
+static const struct soc_enum ak4535_enum[] = {
+       SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain),
+       SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out),
+       SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out),
+       SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp),
+       SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select),
+};
+
+static const struct snd_kcontrol_new ak4535_snd_controls[] = {
+       SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0),
+       SOC_ENUM("Mono 1 Output", ak4535_enum[1]),
+       SOC_ENUM("Mono 1 Gain", ak4535_enum[0]),
+       SOC_ENUM("Headphone Output", ak4535_enum[2]),
+       SOC_ENUM("Playback Deemphasis", ak4535_enum[3]),
+       SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0),
+       SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0),
+       SOC_ENUM("Mic Select", ak4535_enum[4]),
+       SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0),
+       SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0),
+       SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0),
+       SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0),
+       SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0),
+       SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0),
+       SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0),
+       SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1),
+       SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1),
+       SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0),
+       SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
+};
+
+/* add non dapm controls */
+static int ak4535_add_controls(struct snd_soc_codec *codec)
+{
+       int err, i;
+
+       for (i = 0; i < ARRAY_SIZE(ak4535_snd_controls); i++) {
+               err = snd_ctl_add(codec->card,
+                       snd_soc_cnew(&ak4535_snd_controls[i], codec, NULL));
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+/* Mono 1 Mixer */
+static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = {
+       SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
+       SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0),
+};
+
+/* Stereo Mixer */
+static const struct snd_kcontrol_new ak4535_stereo_mixer_controls[] = {
+       SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0),
+       SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0),
+       SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0),
+};
+
+/* Input Mixer */
+static const struct snd_kcontrol_new ak4535_input_mixer_controls[] = {
+       SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0),
+       SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0),
+};
+
+/* Input mux */
+static const struct snd_kcontrol_new ak4535_input_mux_control =
+       SOC_DAPM_ENUM("Input Select", ak4535_enum[4]);
+
+/* HP L switch */
+static const struct snd_kcontrol_new ak4535_hpl_control =
+       SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1);
+
+/* HP R switch */
+static const struct snd_kcontrol_new ak4535_hpr_control =
+       SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1);
+
+/* mono 2 switch */
+static const struct snd_kcontrol_new ak4535_mono2_control =
+       SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0);
+
+/* Line out switch */
+static const struct snd_kcontrol_new ak4535_line_control =
+       SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0);
+
+/* ak4535 dapm widgets */
+static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = {
+       SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0,
+               &ak4535_stereo_mixer_controls[0],
+               ARRAY_SIZE(ak4535_stereo_mixer_controls)),
+       SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0,
+               &ak4535_mono1_mixer_controls[0],
+               ARRAY_SIZE(ak4535_mono1_mixer_controls)),
+       SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0,
+               &ak4535_input_mixer_controls[0],
+               ARRAY_SIZE(ak4535_input_mixer_controls)),
+       SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
+               &ak4535_input_mux_control),
+       SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0),
+       SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0,
+               &ak4535_mono2_control),
+       /* speaker powersave bit */
+       SND_SOC_DAPM_PGA("Speaker Enable", AK4535_MODE2, 0, 0, NULL, 0),
+       SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0,
+               &ak4535_line_control),
+       SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_NOPM, 0, 0,
+               &ak4535_hpl_control),
+       SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_NOPM, 0, 0,
+               &ak4535_hpr_control),
+       SND_SOC_DAPM_OUTPUT("LOUT"),
+       SND_SOC_DAPM_OUTPUT("HPL"),
+       SND_SOC_DAPM_OUTPUT("ROUT"),
+       SND_SOC_DAPM_OUTPUT("HPR"),
+       SND_SOC_DAPM_OUTPUT("SPP"),
+       SND_SOC_DAPM_OUTPUT("SPN"),
+       SND_SOC_DAPM_OUTPUT("MOUT1"),
+       SND_SOC_DAPM_OUTPUT("MOUT2"),
+       SND_SOC_DAPM_OUTPUT("MICOUT"),
+       SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 0),
+       SND_SOC_DAPM_PGA("Spk Amp", AK4535_PM2, 3, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("HP R Amp", AK4535_PM2, 1, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("HP L Amp", AK4535_PM2, 2, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("Mic", AK4535_PM1, 1, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("Line Out", AK4535_PM1, 4, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("Mono Out", AK4535_PM1, 3, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("AUX In", AK4535_PM1, 2, 0, NULL, 0),
+
+       SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0),
+       SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0),
+       SND_SOC_DAPM_INPUT("MICIN"),
+       SND_SOC_DAPM_INPUT("MICEXT"),
+       SND_SOC_DAPM_INPUT("AUX"),
+       SND_SOC_DAPM_INPUT("MIN"),
+       SND_SOC_DAPM_INPUT("AIN"),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       /*stereo mixer */
+       {"Stereo Mixer", "Playback Switch", "DAC"},
+       {"Stereo Mixer", "Mic Sidetone Switch", "Mic"},
+       {"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
+
+       /* mono1 mixer */
+       {"Mono1 Mixer", "Mic Sidetone Switch", "Mic"},
+       {"Mono1 Mixer", "Mono Playback Switch", "DAC"},
+
+       /* Mic */
+       {"Mic", NULL, "AIN"},
+       {"Input Mux", "Internal", "Mic Int Bias"},
+       {"Input Mux", "External", "Mic Ext Bias"},
+       {"Mic Int Bias", NULL, "MICIN"},
+       {"Mic Ext Bias", NULL, "MICEXT"},
+       {"MICOUT", NULL, "Input Mux"},
+
+       /* line out */
+       {"LOUT", NULL, "Line Out Enable"},
+       {"ROUT", NULL, "Line Out Enable"},
+       {"Line Out Enable", "Switch", "Line Out"},
+       {"Line Out", NULL, "Stereo Mixer"},
+
+       /* mono1 out */
+       {"MOUT1", NULL, "Mono Out"},
+       {"Mono Out", NULL, "Mono1 Mixer"},
+
+       /* left HP */
+       {"HPL", NULL, "Left HP Enable"},
+       {"Left HP Enable", "Switch", "HP L Amp"},
+       {"HP L Amp", NULL, "Stereo Mixer"},
+
+       /* right HP */
+       {"HPR", NULL, "Right HP Enable"},
+       {"Right HP Enable", "Switch", "HP R Amp"},
+       {"HP R Amp", NULL, "Stereo Mixer"},
+
+       /* speaker */
+       {"SPP", NULL, "Speaker Enable"},
+       {"SPN", NULL, "Speaker Enable"},
+       {"Speaker Enable", "Switch", "Spk Amp"},
+       {"Spk Amp", NULL, "MIN"},
+
+       /* mono 2 */
+       {"MOUT2", NULL, "Mono 2 Enable"},
+       {"Mono 2 Enable", "Switch", "Stereo Mixer"},
+
+       /* Aux In */
+       {"Aux In", NULL, "AUX"},
+
+       /* ADC */
+       {"ADC", NULL, "Input Mixer"},
+       {"Input Mixer", "Mic Capture Switch", "Mic"},
+       {"Input Mixer", "Aux Capture Switch", "Aux In"},
+};
+
+static int ak4535_add_widgets(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_new_controls(codec, ak4535_dapm_widgets,
+                                 ARRAY_SIZE(ak4535_dapm_widgets));
+
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_dapm_new_widgets(codec);
+       return 0;
+}
+
+static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+       int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct ak4535_priv *ak4535 = codec->private_data;
+
+       ak4535->sysclk = freq;
+       return 0;
+}
+
+static int ak4535_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       struct ak4535_priv *ak4535 = codec->private_data;
+       u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
+       int rate = params_rate(params), fs = 256;
+
+       if (rate)
+               fs = ak4535->sysclk / rate;
+
+       /* set fs */
+       switch (fs) {
+       case 1024:
+               mode2 |= (0x2 << 5);
+               break;
+       case 512:
+               mode2 |= (0x1 << 5);
+               break;
+       case 256:
+               break;
+       }
+
+       /* set rate */
+       ak4535_write(codec, AK4535_MODE2, mode2);
+       return 0;
+}
+
+static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
+               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u8 mode1 = 0;
+
+       /* interface format */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               mode1 = 0x0002;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               mode1 = 0x0001;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* use 32 fs for BCLK to save power */
+       mode1 |= 0x4;
+
+       ak4535_write(codec, AK4535_MODE1, mode1);
+       return 0;
+}
+
+static int ak4535_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC) & 0xffdf;
+       if (!mute)
+               ak4535_write(codec, AK4535_DAC, mute_reg);
+       else
+               ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
+       return 0;
+}
+
+static int ak4535_set_bias_level(struct snd_soc_codec *codec,
+       enum snd_soc_bias_level level)
+{
+       u16 i;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               ak4535_mute(codec->dai, 0);
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               ak4535_mute(codec->dai, 1);
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               i = ak4535_read_reg_cache(codec, AK4535_PM1);
+               ak4535_write(codec, AK4535_PM1, i | 0x80);
+               i = ak4535_read_reg_cache(codec, AK4535_PM2);
+               ak4535_write(codec, AK4535_PM2, i & (~0x80));
+               break;
+       case SND_SOC_BIAS_OFF:
+               i = ak4535_read_reg_cache(codec, AK4535_PM1);
+               ak4535_write(codec, AK4535_PM1, i & (~0x80));
+               break;
+       }
+       codec->bias_level = level;
+       return 0;
+}
+
+#define AK4535_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
+               SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
+               SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
+
+struct snd_soc_dai ak4535_dai = {
+       .name = "AK4535",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = AK4535_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = AK4535_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .ops = {
+               .hw_params = ak4535_hw_params,
+       },
+       .dai_ops = {
+               .set_fmt = ak4535_set_dai_fmt,
+               .digital_mute = ak4535_mute,
+               .set_sysclk = ak4535_set_dai_sysclk,
+       },
+};
+EXPORT_SYMBOL_GPL(ak4535_dai);
+
+static int ak4535_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int ak4535_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+       ak4535_sync(codec);
+       ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       ak4535_set_bias_level(codec, codec->suspend_bias_level);
+       return 0;
+}
+
+/*
+ * initialise the AK4535 driver
+ * register the mixer and dsp interfaces with the kernel
+ */
+static int ak4535_init(struct snd_soc_device *socdev)
+{
+       struct snd_soc_codec *codec = socdev->codec;
+       int ret = 0;
+
+       codec->name = "AK4535";
+       codec->owner = THIS_MODULE;
+       codec->read = ak4535_read_reg_cache;
+       codec->write = ak4535_write;
+       codec->set_bias_level = ak4535_set_bias_level;
+       codec->dai = &ak4535_dai;
+       codec->num_dai = 1;
+       codec->reg_cache_size = ARRAY_SIZE(ak4535_reg);
+       codec->reg_cache = kmemdup(ak4535_reg, sizeof(ak4535_reg), GFP_KERNEL);
+
+       if (codec->reg_cache == NULL)
+               return -ENOMEM;
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               printk(KERN_ERR "ak4535: failed to create pcms\n");
+               goto pcm_err;
+       }
+
+       /* power on device */
+       ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       ak4535_add_controls(codec);
+       ak4535_add_widgets(codec);
+       ret = snd_soc_register_card(socdev);
+       if (ret < 0) {
+               printk(KERN_ERR "ak4535: failed to register card\n");
+               goto card_err;
+       }
+
+       return ret;
+
+card_err:
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+pcm_err:
+       kfree(codec->reg_cache);
+
+       return ret;
+}
+
+static struct snd_soc_device *ak4535_socdev;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+
+#define I2C_DRIVERID_AK4535 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver ak4535_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+static int ak4535_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+       struct snd_soc_device *socdev = ak4535_socdev;
+       struct ak4535_setup_data *setup = socdev->codec_data;
+       struct snd_soc_codec *codec = socdev->codec;
+       struct i2c_client *i2c;
+       int ret;
+
+       if (addr != setup->i2c_address)
+               return -ENODEV;
+
+       client_template.adapter = adap;
+       client_template.addr = addr;
+
+       i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
+       if (i2c == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(i2c, codec);
+       codec->control_data = i2c;
+
+       ret = i2c_attach_client(i2c);
+       if (ret < 0) {
+               printk(KERN_ERR "failed to attach codec at addr %x\n", addr);
+               goto err;
+       }
+
+       ret = ak4535_init(socdev);
+       if (ret < 0) {
+               printk(KERN_ERR "failed to initialise AK4535\n");
+               goto err;
+       }
+       return ret;
+
+err:
+       kfree(codec);
+       kfree(i2c);
+       return ret;
+}
+
+static int ak4535_i2c_detach(struct i2c_client *client)
+{
+       struct snd_soc_codec *codec = i2c_get_clientdata(client);
+       i2c_detach_client(client);
+       kfree(codec->reg_cache);
+       kfree(client);
+       return 0;
+}
+
+static int ak4535_i2c_attach(struct i2c_adapter *adap)
+{
+       return i2c_probe(adap, &addr_data, ak4535_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver ak4535_i2c_driver = {
+       .driver = {
+               .name = "AK4535 I2C Codec",
+               .owner = THIS_MODULE,
+       },
+       .id =             I2C_DRIVERID_AK4535,
+       .attach_adapter = ak4535_i2c_attach,
+       .detach_client =  ak4535_i2c_detach,
+       .command =        NULL,
+};
+
+static struct i2c_client client_template = {
+       .name =   "AK4535",
+       .driver = &ak4535_i2c_driver,
+};
+#endif
+
+static int ak4535_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct ak4535_setup_data *setup;
+       struct snd_soc_codec *codec;
+       struct ak4535_priv *ak4535;
+       int ret = 0;
+
+       printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
+
+       setup = socdev->codec_data;
+       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+       if (codec == NULL)
+               return -ENOMEM;
+
+       ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL);
+       if (ak4535 == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+
+       codec->private_data = ak4535;
+       socdev->codec = codec;
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
+       ak4535_socdev = socdev;
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       if (setup->i2c_address) {
+               normal_i2c[0] = setup->i2c_address;
+               codec->hw_write = (hw_write_t)i2c_master_send;
+               codec->hw_read = (hw_read_t)i2c_master_recv;
+               ret = i2c_add_driver(&ak4535_i2c_driver);
+               if (ret != 0)
+                       printk(KERN_ERR "can't add i2c driver");
+       }
+#else
+       /* Add other interfaces here */
+#endif
+       return ret;
+}
+
+/* power down chip */
+static int ak4535_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       if (codec->control_data)
+               ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&ak4535_i2c_driver);
+#endif
+       kfree(codec->private_data);
+       kfree(codec);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_ak4535 = {
+       .probe =        ak4535_probe,
+       .remove =       ak4535_remove,
+       .suspend =      ak4535_suspend,
+       .resume =       ak4535_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_ak4535);
+
+MODULE_DESCRIPTION("Soc AK4535 driver");
+MODULE_AUTHOR("Richard Purdie");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ak4535.h b/sound/soc/codecs/ak4535.h
new file mode 100644 (file)
index 0000000..e9fe30e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * ak4535.h  --  AK4535 Soc Audio driver
+ *
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Author: Richard Purdie <richard@openedhand.com>
+ *
+ * Based on wm8753.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _AK4535_H
+#define _AK4535_H
+
+/* AK4535 register space */
+
+#define AK4535_PM1             0x0
+#define AK4535_PM2             0x1
+#define AK4535_SIG1            0x2
+#define AK4535_SIG2            0x3
+#define AK4535_MODE1           0x4
+#define AK4535_MODE2           0x5
+#define AK4535_DAC             0x6
+#define AK4535_MIC             0x7
+#define AK4535_TIMER           0x8
+#define AK4535_ALC1            0x9
+#define AK4535_ALC2            0xa
+#define AK4535_PGA             0xb
+#define AK4535_LATT            0xc
+#define AK4535_RATT            0xd
+#define AK4535_VOL             0xe
+#define AK4535_STATUS          0xf
+
+#define AK4535_CACHEREGNUM     0x10
+
+struct ak4535_setup_data {
+       unsigned short i2c_address;
+};
+
+extern struct snd_soc_dai ak4535_dai;
+extern struct snd_soc_codec_device soc_codec_dev_ak4535;
+
+#endif
index e73fcfd..9deb8c7 100644 (file)
@@ -201,7 +201,7 @@ static struct {
  * driver what the input settings can be.  This would need to be implemented
  * for stand-alone mode to work.
  */
-static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                 int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -251,7 +251,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
  * data for playback only, but ASoC currently does not support different
  * formats for playback vs. record.
  */
-static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
                              unsigned int format)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -471,7 +471,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
  * board does not have the MUTEA or MUTEB pins connected to such circuitry,
  * then this function will do nothing.
  */
-static int cs4270_mute(struct snd_soc_codec_dai *dai, int mute)
+static int cs4270_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        int reg6;
@@ -667,7 +667,7 @@ error:
 
 #endif /* USE_I2C*/
 
-struct snd_soc_codec_dai cs4270_dai = {
+struct snd_soc_dai cs4270_dai = {
        .name = "CS4270",
        .playback = {
                .stream_name = "Playback",
index 0ced49b..adc6cd9 100644 (file)
@@ -16,7 +16,7 @@
  * The ASoC codec DAI structure for the CS4270.  Assign this structure to
  * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
  */
-extern struct snd_soc_codec_dai cs4270_dai;
+extern struct snd_soc_dai cs4270_dai;
 
 /*
  * The ASoC codec device structure for the CS4270.  Assign this structure
index 09b1661..b1dce5f 100644 (file)
@@ -29,7 +29,7 @@
  *  ---------------------------------------
  *
  *  Hence the machine layer should disable unsupported inputs/outputs by
- *  snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0), etc.
+ *  snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc.
  */
 
 #include <linux/module.h>
@@ -49,7 +49,7 @@
 #include "tlv320aic3x.h"
 
 #define AUDIO_NAME "aic3x"
-#define AIC3X_VERSION "0.1"
+#define AIC3X_VERSION "0.2"
 
 /* codec private data */
 struct aic3x_priv {
@@ -138,6 +138,20 @@ static int aic3x_write(struct snd_soc_codec *codec, unsigned int reg,
                return -EIO;
 }
 
+/*
+ * read from the aic3x register space
+ */
+static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg,
+                     u8 *value)
+{
+       *value = reg & 0xff;
+       if (codec->hw_read(codec->control_data, value, 1) != 1)
+               return -EIO;
+
+       aic3x_write_reg_cache(codec, reg, *value);
+       return 0;
+}
+
 #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_volsw, \
@@ -192,7 +206,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
                }
 
                if (found)
-                       snd_soc_dapm_sync_endpoints(widget->codec);
+                       snd_soc_dapm_sync(widget->codec);
        }
 
        ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
@@ -209,6 +223,8 @@ static const char *aic3x_right_hpcom_mux[] =
     { "differential of HPROUT", "constant VCM", "single-ended",
       "differential of HPLCOM", "external feedback" };
 static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" };
+static const char *aic3x_adc_hpf[] =
+    { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
 
 #define LDAC_ENUM      0
 #define RDAC_ENUM      1
@@ -218,6 +234,7 @@ static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" };
 #define LINE1R_ENUM    5
 #define LINE2L_ENUM    6
 #define LINE2R_ENUM    7
+#define ADC_HPF_ENUM   8
 
 static const struct soc_enum aic3x_enum[] = {
        SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux),
@@ -228,6 +245,7 @@ static const struct soc_enum aic3x_enum[] = {
        SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
        SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
        SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
+       SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf),
 };
 
 static const struct snd_kcontrol_new aic3x_snd_controls[] = {
@@ -278,6 +296,8 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
        /* Input */
        SOC_DOUBLE_R("PGA Capture Volume", LADC_VOL, RADC_VOL, 0, 0x7f, 0),
        SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
+
+       SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]),
 };
 
 /* add non dapm controls */
@@ -441,11 +461,34 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
        SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
                         &aic3x_right_line2_mux_controls),
 
+       /*
+        * Not a real mic bias widget but similar function. This is for dynamic
+        * control of GPIO1 digital mic modulator clock output function when
+        * using digital mic.
+        */
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
+                        AIC3X_GPIO1_REG, 4, 0xf,
+                        AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
+                        AIC3X_GPIO1_FUNC_DISABLED),
+
+       /*
+        * Also similar function like mic bias. Selects digital mic with
+        * configurable oversampling rate instead of ADC converter.
+        */
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
+                        AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
+                        AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
+                        AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
+
        /* Mic Bias */
-       SND_SOC_DAPM_MICBIAS("Mic Bias 2V", MICBIAS_CTRL, 6, 0),
-       SND_SOC_DAPM_MICBIAS("Mic Bias 2.5V", MICBIAS_CTRL, 7, 0),
-       SND_SOC_DAPM_MICBIAS("Mic Bias AVDD", MICBIAS_CTRL, 6, 0),
-       SND_SOC_DAPM_MICBIAS("Mic Bias AVDD", MICBIAS_CTRL, 7, 0),
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V",
+                        MICBIAS_CTRL, 6, 3, 1, 0),
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V",
+                        MICBIAS_CTRL, 6, 3, 2, 0),
+       SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD",
+                        MICBIAS_CTRL, 6, 3, 3, 0),
 
        /* Left PGA to Left Output bypass */
        SND_SOC_DAPM_MIXER("Left PGA Bypass Mixer", SND_SOC_NOPM, 0, 0,
@@ -483,7 +526,7 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
        SND_SOC_DAPM_INPUT("LINE2R"),
 };
 
-static const char *intercon[][3] = {
+static const struct snd_soc_dapm_route intercon[] = {
        /* Left Output */
        {"Left DAC Mux", "DAC_L1", "Left DAC"},
        {"Left DAC Mux", "DAC_L2", "Left DAC"},
@@ -554,6 +597,7 @@ static const char *intercon[][3] = {
        {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
 
        {"Left ADC", NULL, "Left PGA Mixer"},
+       {"Left ADC", NULL, "GPIO1 dmic modclk"},
 
        /* Right Input */
        {"Right Line1R Mux", "single-ended", "LINE1R"},
@@ -567,6 +611,7 @@ static const char *intercon[][3] = {
        {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
 
        {"Right ADC", NULL, "Right PGA Mixer"},
+       {"Right ADC", NULL, "GPIO1 dmic modclk"},
 
        /* Left PGA Bypass */
        {"Left PGA Bypass Mixer", "Line Switch", "Left PGA Mixer"},
@@ -628,101 +673,27 @@ static const char *intercon[][3] = {
        {"Mono Out", NULL, "Right Line2 Bypass Mixer"},
        {"Right HP Out", NULL, "Right Line2 Bypass Mixer"},
 
-       /* terminator */
-       {NULL, NULL, NULL},
+       /*
+        * Logical path between digital mic enable and GPIO1 modulator clock
+        * output function
+        */
+       {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
+       {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
+       {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
 };
 
 static int aic3x_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
+                                 ARRAY_SIZE(aic3x_dapm_widgets));
 
        /* set up audio path interconnects */
-       for (i = 0; intercon[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, intercon[i][0],
-                                          intercon[i][1], intercon[i][2]);
+       snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
 }
 
-struct aic3x_rate_divs {
-       u32 mclk;
-       u32 rate;
-       u32 fsref_reg;
-       u8 sr_reg:4;
-       u8 pllj_reg;
-       u16 plld_reg;
-};
-
-/* AIC3X codec mclk clock divider coefficients */
-static const struct aic3x_rate_divs aic3x_divs[] = {
-       /* 8k */
-       {12000000, 8000, 48000, 0xa, 16, 3840},
-       {19200000, 8000, 48000, 0xa, 10, 2400},
-       {22579200, 8000, 48000, 0xa, 8, 7075},
-       {33868800, 8000, 48000, 0xa, 5, 8049},
-       /* 11.025k */
-       {12000000, 11025, 44100, 0x6, 15, 528},
-       {19200000, 11025, 44100, 0x6, 9, 4080},
-       {22579200, 11025, 44100, 0x6, 8, 0},
-       {33868800, 11025, 44100, 0x6, 5, 3333},
-       /* 16k */
-       {12000000, 16000, 48000, 0x4, 16, 3840},
-       {19200000, 16000, 48000, 0x4, 10, 2400},
-       {22579200, 16000, 48000, 0x4, 8, 7075},
-       {33868800, 16000, 48000, 0x4, 5, 8049},
-       /* 22.05k */
-       {12000000, 22050, 44100, 0x2, 15, 528},
-       {19200000, 22050, 44100, 0x2, 9, 4080},
-       {22579200, 22050, 44100, 0x2, 8, 0},
-       {33868800, 22050, 44100, 0x2, 5, 3333},
-       /* 32k */
-       {12000000, 32000, 48000, 0x1, 16, 3840},
-       {19200000, 32000, 48000, 0x1, 10, 2400},
-       {22579200, 32000, 48000, 0x1, 8, 7075},
-       {33868800, 32000, 48000, 0x1, 5, 8049},
-       /* 44.1k */
-       {12000000, 44100, 44100, 0x0, 15, 528},
-       {19200000, 44100, 44100, 0x0, 9, 4080},
-       {22579200, 44100, 44100, 0x0, 8, 0},
-       {33868800, 44100, 44100, 0x0, 5, 3333},
-       /* 48k */
-       {12000000, 48000, 48000, 0x0, 16, 3840},
-       {19200000, 48000, 48000, 0x0, 10, 2400},
-       {22579200, 48000, 48000, 0x0, 8, 7075},
-       {33868800, 48000, 48000, 0x0, 5, 8049},
-       /* 64k */
-       {12000000, 64000, 96000, 0x1, 16, 3840},
-       {19200000, 64000, 96000, 0x1, 10, 2400},
-       {22579200, 64000, 96000, 0x1, 8, 7075},
-       {33868800, 64000, 96000, 0x1, 5, 8049},
-       /* 88.2k */
-       {12000000, 88200, 88200, 0x0, 15, 528},
-       {19200000, 88200, 88200, 0x0, 9, 4080},
-       {22579200, 88200, 88200, 0x0, 8, 0},
-       {33868800, 88200, 88200, 0x0, 5, 3333},
-       /* 96k */
-       {12000000, 96000, 96000, 0x0, 16, 3840},
-       {19200000, 96000, 96000, 0x0, 10, 2400},
-       {22579200, 96000, 96000, 0x0, 8, 7075},
-       {33868800, 96000, 96000, 0x0, 5, 8049},
-};
-
-static inline int aic3x_get_divs(int mclk, int rate)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(aic3x_divs); i++) {
-               if (aic3x_divs[i].rate == rate && aic3x_divs[i].mclk == mclk)
-                       return i;
-       }
-
-       return 0;
-}
-
 static int aic3x_hw_params(struct snd_pcm_substream *substream,
                           struct snd_pcm_hw_params *params)
 {
@@ -730,49 +701,107 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->codec;
        struct aic3x_priv *aic3x = codec->private_data;
-       int i;
-       u8 data, pll_p, pll_r, pll_j;
-       u16 pll_d;
-
-       i = aic3x_get_divs(aic3x->sysclk, params_rate(params));
+       int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
+       u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
+       u16 pll_d = 1;
 
-       /* Route Left DAC to left channel input and
-        * right DAC to right channel input */
-       data = (LDAC2LCH | RDAC2RCH);
-       switch (aic3x_divs[i].fsref_reg) {
-       case 44100:
-               data |= FSREF_44100;
+       /* select data word length */
+       data =
+           aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
                break;
-       case 48000:
-               data |= FSREF_48000;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               data |= (0x01 << 4);
                break;
-       case 88200:
-               data |= FSREF_44100 | DUAL_RATE_MODE;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               data |= (0x02 << 4);
                break;
-       case 96000:
-               data |= FSREF_48000 | DUAL_RATE_MODE;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               data |= (0x03 << 4);
                break;
        }
+       aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, data);
+
+       /* Fsref can be 44100 or 48000 */
+       fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
+
+       /* Try to find a value for Q which allows us to bypass the PLL and
+        * generate CODEC_CLK directly. */
+       for (pll_q = 2; pll_q < 18; pll_q++)
+               if (aic3x->sysclk / (128 * pll_q) == fsref) {
+                       bypass_pll = 1;
+                       break;
+               }
+
+       if (bypass_pll) {
+               pll_q &= 0xf;
+               aic3x_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
+               aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
+       } else
+               aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
+
+       /* Route Left DAC to left channel input and
+        * right DAC to right channel input */
+       data = (LDAC2LCH | RDAC2RCH);
+       data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
+       if (params_rate(params) >= 64000)
+               data |= DUAL_RATE_MODE;
        aic3x_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
 
        /* codec sample rate select */
-       data = aic3x_divs[i].sr_reg;
+       data = (fsref * 20) / params_rate(params);
+       if (params_rate(params) < 64000)
+               data /= 2;
+       data /= 5;
+       data -= 2;
        data |= (data << 4);
        aic3x_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
 
-       /* Use PLL for generation Fsref by equation:
-        * Fsref = (MCLK * K * R)/(2048 * P);
-        * Fix P = 2 and R = 1 and calculate K, if
-        * K = J.D, i.e. J - an interger portion of K and D is the fractional
-        * one with 4 digits of precision;
-        * Example:
-        * For MCLK = 22.5792 MHz and Fsref = 48kHz:
-        * Select P = 2, R= 1, K = 8.7074, which results in J = 8, D = 7074
+       if (bypass_pll)
+               return 0;
+
+       /* Use PLL
+        * find an apropriate setup for j, d, r and p by iterating over
+        * p and r - j and d are calculated for each fraction.
+        * Up to 128 values are probed, the closest one wins the game.
+        * The sysclk is divided by 1000 to prevent integer overflows.
         */
-       pll_p = 2;
-       pll_r = 1;
-       pll_j = aic3x_divs[i].pllj_reg;
-       pll_d = aic3x_divs[i].plld_reg;
+       codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
+
+       for (r = 1; r <= 16; r++)
+               for (p = 1; p <= 8; p++) {
+                       int clk, tmp = (codec_clk * pll_r * 10) / pll_p;
+                       u8 j = tmp / 10000;
+                       u16 d = tmp % 10000;
+
+                       if (j > 63)
+                               continue;
+
+                       if (d != 0 && aic3x->sysclk < 10000000)
+                               continue;
+
+                       /* This is actually 1000 * ((j + (d/10000)) * r) / p
+                        * The term had to be converted to get rid of the
+                        * division by 10000 */
+                       clk = ((10000 * j * r) + (d * r)) / (10 * p);
+
+                       /* check whether this values get closer than the best
+                        * ones we had before */
+                       if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
+                               pll_j = j; pll_d = d; pll_r = r; pll_p = p;
+                               last_clk = clk;
+                       }
+
+                       /* Early exit for exact matches */
+                       if (clk == codec_clk)
+                               break;
+               }
+
+       if (last_clk == 0) {
+               printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
+               return -EINVAL;
+       }
 
        data = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
        aic3x_write(codec, AIC3X_PLL_PROGA_REG, data | (pll_p << PLLP_SHIFT));
@@ -782,28 +811,10 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
        aic3x_write(codec, AIC3X_PLL_PROGD_REG,
                    (pll_d & 0x3F) << PLLD_LSB_SHIFT);
 
-       /* select data word length */
-       data =
-           aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S16_LE:
-               break;
-       case SNDRV_PCM_FORMAT_S20_3LE:
-               data |= (0x01 << 4);
-               break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-               data |= (0x02 << 4);
-               break;
-       case SNDRV_PCM_FORMAT_S32_LE:
-               data |= (0x03 << 4);
-               break;
-       }
-       aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, data);
-
        return 0;
 }
 
-static int aic3x_mute(struct snd_soc_codec_dai *dai, int mute)
+static int aic3x_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u8 ldac_reg = aic3x_read_reg_cache(codec, LDAC_VOL) & ~MUTE_ON;
@@ -820,31 +831,25 @@ static int aic3x_mute(struct snd_soc_codec_dai *dai, int mute)
        return 0;
 }
 
-static int aic3x_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct aic3x_priv *aic3x = codec->private_data;
 
-       switch (freq) {
-       case 12000000:
-       case 19200000:
-       case 22579200:
-       case 33868800:
-               aic3x->sysclk = freq;
-               return 0;
-       }
-
-       return -EINVAL;
+       aic3x->sysclk = freq;
+       return 0;
 }
 
-static int aic3x_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
                             unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct aic3x_priv *aic3x = codec->private_data;
-       u8 iface_areg = 0;
-       u8 iface_breg = 0;
+       u8 iface_areg, iface_breg;
+
+       iface_areg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
+       iface_breg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
 
        /* set master/slave audio interface */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -883,13 +888,14 @@ static int aic3x_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return 0;
 }
 
-static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
+static int aic3x_set_bias_level(struct snd_soc_codec *codec,
+                               enum snd_soc_bias_level level)
 {
        struct aic3x_priv *aic3x = codec->private_data;
        u8 reg;
 
-       switch (event) {
-       case SNDRV_CTL_POWER_D0:
+       switch (level) {
+       case SND_SOC_BIAS_ON:
                /* all power is driven by DAPM system */
                if (aic3x->master) {
                        /* enable pll */
@@ -898,10 +904,9 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
                                    reg | PLL_ENABLE);
                }
                break;
-       case SNDRV_CTL_POWER_D1:
-       case SNDRV_CTL_POWER_D2:
+       case SND_SOC_BIAS_PREPARE:
                break;
-       case SNDRV_CTL_POWER_D3hot:
+       case SND_SOC_BIAS_STANDBY:
                /*
                 * all power is driven by DAPM system,
                 * so output power is safe if bypass was set
@@ -913,7 +918,7 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
                                    reg & ~PLL_ENABLE);
                }
                break;
-       case SNDRV_CTL_POWER_D3cold:
+       case SND_SOC_BIAS_OFF:
                /* force all power off */
                reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL);
                aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON);
@@ -949,16 +954,43 @@ static int aic3x_dapm_event(struct snd_soc_codec *codec, int event)
                }
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
 
        return 0;
 }
 
+void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state)
+{
+       u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
+       u8 bit = gpio ? 3: 0;
+       u8 val = aic3x_read_reg_cache(codec, reg) & ~(1 << bit);
+       aic3x_write(codec, reg, val | (!!state << bit));
+}
+EXPORT_SYMBOL_GPL(aic3x_set_gpio);
+
+int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
+{
+       u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
+       u8 val, bit = gpio ? 2: 1;
+
+       aic3x_read(codec, reg, &val);
+       return (val >> bit) & 1;
+}
+EXPORT_SYMBOL_GPL(aic3x_get_gpio);
+
+int aic3x_headset_detected(struct snd_soc_codec *codec)
+{
+       u8 val;
+       aic3x_read(codec, AIC3X_RT_IRQ_FLAGS_REG, &val);
+       return (val >> 2) & 1;
+}
+EXPORT_SYMBOL_GPL(aic3x_headset_detected);
+
 #define AIC3X_RATES    SNDRV_PCM_RATE_8000_96000
 #define AIC3X_FORMATS  (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
                         SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
 
-struct snd_soc_codec_dai aic3x_dai = {
+struct snd_soc_dai aic3x_dai = {
        .name = "aic3x",
        .playback = {
                .stream_name = "Playback",
@@ -988,7 +1020,7 @@ static int aic3x_suspend(struct platform_device *pdev, pm_message_t state)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->codec;
 
-       aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+       aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
        return 0;
 }
@@ -1008,7 +1040,7 @@ static int aic3x_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
 
-       aic3x_dapm_event(codec, codec->suspend_dapm_state);
+       aic3x_set_bias_level(codec, codec->suspend_bias_level);
 
        return 0;
 }
@@ -1020,16 +1052,17 @@ static int aic3x_resume(struct platform_device *pdev)
 static int aic3x_init(struct snd_soc_device *socdev)
 {
        struct snd_soc_codec *codec = socdev->codec;
+       struct aic3x_setup_data *setup = socdev->codec_data;
        int reg, ret = 0;
 
        codec->name = "aic3x";
        codec->owner = THIS_MODULE;
        codec->read = aic3x_read_reg_cache;
        codec->write = aic3x_write;
-       codec->dapm_event = aic3x_dapm_event;
+       codec->set_bias_level = aic3x_set_bias_level;
        codec->dai = &aic3x_dai;
        codec->num_dai = 1;
-       codec->reg_cache_size = sizeof(aic3x_reg);
+       codec->reg_cache_size = ARRAY_SIZE(aic3x_reg);
        codec->reg_cache = kmemdup(aic3x_reg, sizeof(aic3x_reg), GFP_KERNEL);
        if (codec->reg_cache == NULL)
                return -ENOMEM;
@@ -1108,7 +1141,11 @@ static int aic3x_init(struct snd_soc_device *socdev)
        aic3x_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
 
        /* off, with power on */
-       aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       /* setup GPIO functions */
+       aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4);
+       aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4);
 
        aic3x_add_controls(codec);
        aic3x_add_widgets(codec);
@@ -1217,6 +1254,12 @@ static struct i2c_client client_template = {
        .name = "AIC3X",
        .driver = &aic3x_i2c_driver,
 };
+
+static int aic3x_i2c_read(struct i2c_client *client, u8 *value, int len)
+{
+       value[0] = i2c_smbus_read_byte_data(client, value[0]);
+       return (len == 1);
+}
 #endif
 
 static int aic3x_probe(struct platform_device *pdev)
@@ -1251,6 +1294,7 @@ static int aic3x_probe(struct platform_device *pdev)
        if (setup->i2c_address) {
                normal_i2c[0] = setup->i2c_address;
                codec->hw_write = (hw_write_t) i2c_master_send;
+               codec->hw_read = (hw_read_t) aic3x_i2c_read;
                ret = i2c_add_driver(&aic3x_i2c_driver);
                if (ret != 0)
                        printk(KERN_ERR "can't add i2c driver");
@@ -1268,7 +1312,7 @@ static int aic3x_remove(struct platform_device *pdev)
 
        /* power down chip */
        if (codec->control_data)
-               aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3);
+               aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
        snd_soc_free_pcms(socdev);
        snd_soc_dapm_free(socdev);
index d0cdeeb..d76c079 100644 (file)
@@ -37,6 +37,8 @@
 #define AIC3X_ASD_INTF_CTRLB           9
 /* Audio overflow status and PLL R value programming register */
 #define AIC3X_OVRF_STATUS_AND_PLLR_REG 11
+/* Audio codec digital filter control register */
+#define AIC3X_CODEC_DFILT_CTRL         12
 
 /* ADC PGA Gain control registers */
 #define LADC_VOL                       15
 #define DACR1_2_RLOPM_VOL              92
 #define LLOPM_CTRL                     86
 #define RLOPM_CTRL                     93
+/* GPIO/IRQ registers */
+#define AIC3X_STICKY_IRQ_FLAGS_REG     96
+#define AIC3X_RT_IRQ_FLAGS_REG         97
+#define AIC3X_GPIO1_REG                        98
+#define AIC3X_GPIO2_REG                        99
+#define AIC3X_GPIOA_REG                        100
+#define AIC3X_GPIOB_REG                        101
 /* Clock generation control register */
 #define AIC3X_CLKGEN_CTRL_REG          102
 
 
 /* PLL registers bitfields */
 #define PLLP_SHIFT             0
+#define PLLQ_SHIFT             3
 #define PLLR_SHIFT             0
 #define PLLJ_SHIFT             2
 #define PLLD_MSB_SHIFT         0
 #define PLLD_LSB_SHIFT         2
 
 /* Clock generation register bits */
+#define CODEC_CLKIN_PLLDIV     0
+#define CODEC_CLKIN_CLKDIV     1
 #define PLL_CLKIN_SHIFT                4
 #define MCLK_SOURCE            0x0
 #define PLL_CLKDIV_SHIFT       0
 /* Default input volume */
 #define DEFAULT_GAIN    0x20
 
+/* GPIO API */
+enum {
+       AIC3X_GPIO1_FUNC_DISABLED               = 0,
+       AIC3X_GPIO1_FUNC_AUDIO_WORDCLK_ADC      = 1,
+       AIC3X_GPIO1_FUNC_CLOCK_MUX              = 2,
+       AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV2         = 3,
+       AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV4         = 4,
+       AIC3X_GPIO1_FUNC_CLOCK_MUX_DIV8         = 5,
+       AIC3X_GPIO1_FUNC_SHORT_CIRCUIT_IRQ      = 6,
+       AIC3X_GPIO1_FUNC_AGC_NOISE_IRQ          = 7,
+       AIC3X_GPIO1_FUNC_INPUT                  = 8,
+       AIC3X_GPIO1_FUNC_OUTPUT                 = 9,
+       AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK     = 10,
+       AIC3X_GPIO1_FUNC_AUDIO_WORDCLK          = 11,
+       AIC3X_GPIO1_FUNC_BUTTON_IRQ             = 12,
+       AIC3X_GPIO1_FUNC_HEADSET_DETECT_IRQ     = 13,
+       AIC3X_GPIO1_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ   = 14,
+       AIC3X_GPIO1_FUNC_ALL_IRQ                = 16
+};
+
+enum {
+       AIC3X_GPIO2_FUNC_DISABLED               = 0,
+       AIC3X_GPIO2_FUNC_HEADSET_DETECT_IRQ     = 2,
+       AIC3X_GPIO2_FUNC_INPUT                  = 3,
+       AIC3X_GPIO2_FUNC_OUTPUT                 = 4,
+       AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT      = 5,
+       AIC3X_GPIO2_FUNC_AUDIO_BITCLK           = 8,
+       AIC3X_GPIO2_FUNC_HEADSET_DETECT_OR_BUTTON_IRQ = 9,
+       AIC3X_GPIO2_FUNC_ALL_IRQ                = 10,
+       AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_OR_AGC_IRQ = 11,
+       AIC3X_GPIO2_FUNC_HEADSET_OR_BUTTON_PRESS_OR_SHORT_CIRCUIT_IRQ = 12,
+       AIC3X_GPIO2_FUNC_SHORT_CIRCUIT_IRQ      = 13,
+       AIC3X_GPIO2_FUNC_AGC_NOISE_IRQ          = 14,
+       AIC3X_GPIO2_FUNC_BUTTON_PRESS_IRQ       = 15
+};
+
+void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state);
+int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio);
+int aic3x_headset_detected(struct snd_soc_codec *codec);
+
 struct aic3x_setup_data {
        unsigned short i2c_address;
+       unsigned int gpio_func[2];
 };
 
-extern struct snd_soc_codec_dai aic3x_dai;
+extern struct snd_soc_dai aic3x_dai;
 extern struct snd_soc_codec_device soc_codec_dev_aic3x;
 
 #endif /* _AIC3X_H */
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
new file mode 100644 (file)
index 0000000..a52d6d9
--- /dev/null
@@ -0,0 +1,852 @@
+/*
+ * uda1380.c - Philips UDA1380 ALSA SoC audio driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Copyright (c) 2007 Philipp Zabel <philipp.zabel@gmail.com>
+ * Improved support for DAPM and audio routing/mixing capabilities,
+ * added TLV support.
+ *
+ * Modified by Richard Purdie <richard@openedhand.com> to fit into SoC
+ * codec model.
+ *
+ * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org>
+ * Copyright 2005 Openedhand Ltd.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/ioctl.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/initval.h>
+#include <sound/info.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/tlv.h>
+
+#include "uda1380.h"
+
+#define UDA1380_VERSION "0.6"
+#define AUDIO_NAME "uda1380"
+
+/*
+ * uda1380 register cache
+ */
+static const u16 uda1380_reg[UDA1380_CACHEREGNUM] = {
+       0x0502, 0x0000, 0x0000, 0x3f3f,
+       0x0202, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0000, 0xff00, 0x0000, 0x4800,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x8000, 0x0002, 0x0000,
+};
+
+/*
+ * read uda1380 register cache
+ */
+static inline unsigned int uda1380_read_reg_cache(struct snd_soc_codec *codec,
+       unsigned int reg)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg == UDA1380_RESET)
+               return 0;
+       if (reg >= UDA1380_CACHEREGNUM)
+               return -1;
+       return cache[reg];
+}
+
+/*
+ * write uda1380 register cache
+ */
+static inline void uda1380_write_reg_cache(struct snd_soc_codec *codec,
+       u16 reg, unsigned int value)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg >= UDA1380_CACHEREGNUM)
+               return;
+       cache[reg] = value;
+}
+
+/*
+ * write to the UDA1380 register space
+ */
+static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
+       unsigned int value)
+{
+       u8 data[3];
+
+       /* data is
+        *   data[0] is register offset
+        *   data[1] is MS byte
+        *   data[2] is LS byte
+        */
+       data[0] = reg;
+       data[1] = (value & 0xff00) >> 8;
+       data[2] = value & 0x00ff;
+
+       uda1380_write_reg_cache(codec, reg, value);
+
+       /* the interpolator & decimator regs must only be written when the
+        * codec DAI is active.
+        */
+       if (!codec->active && (reg >= UDA1380_MVOL))
+               return 0;
+       pr_debug("uda1380: hw write %x val %x\n", reg, value);
+       if (codec->hw_write(codec->control_data, data, 3) == 3) {
+               unsigned int val;
+               i2c_master_send(codec->control_data, data, 1);
+               i2c_master_recv(codec->control_data, data, 2);
+               val = (data[0]<<8) | data[1];
+               if (val != value) {
+                       pr_debug("uda1380: READ BACK VAL %x\n",
+                                       (data[0]<<8) | data[1]);
+                       return -EIO;
+               }
+               return 0;
+       } else
+               return -EIO;
+}
+
+#define uda1380_reset(c)       uda1380_write(c, UDA1380_RESET, 0)
+
+/* declarations of ALSA reg_elem_REAL controls */
+static const char *uda1380_deemp[] = {
+       "None",
+       "32kHz",
+       "44.1kHz",
+       "48kHz",
+       "96kHz",
+};
+static const char *uda1380_input_sel[] = {
+       "Line",
+       "Mic + Line R",
+       "Line L",
+       "Mic",
+};
+static const char *uda1380_output_sel[] = {
+       "DAC",
+       "Analog Mixer",
+};
+static const char *uda1380_spf_mode[] = {
+       "Flat",
+       "Minimum1",
+       "Minimum2",
+       "Maximum"
+};
+static const char *uda1380_capture_sel[] = {
+       "ADC",
+       "Digital Mixer"
+};
+static const char *uda1380_sel_ns[] = {
+       "3rd-order",
+       "5th-order"
+};
+static const char *uda1380_mix_control[] = {
+       "off",
+       "PCM only",
+       "before sound processing",
+       "after sound processing"
+};
+static const char *uda1380_sdet_setting[] = {
+       "3200",
+       "4800",
+       "9600",
+       "19200"
+};
+static const char *uda1380_os_setting[] = {
+       "single-speed",
+       "double-speed (no mixing)",
+       "quad-speed (no mixing)"
+};
+
+static const struct soc_enum uda1380_deemp_enum[] = {
+       SOC_ENUM_SINGLE(UDA1380_DEEMP, 8, 5, uda1380_deemp),
+       SOC_ENUM_SINGLE(UDA1380_DEEMP, 0, 5, uda1380_deemp),
+};
+static const struct soc_enum uda1380_input_sel_enum =
+       SOC_ENUM_SINGLE(UDA1380_ADC, 2, 4, uda1380_input_sel);          /* SEL_MIC, SEL_LNA */
+static const struct soc_enum uda1380_output_sel_enum =
+       SOC_ENUM_SINGLE(UDA1380_PM, 7, 2, uda1380_output_sel);          /* R02_EN_AVC */
+static const struct soc_enum uda1380_spf_enum =
+       SOC_ENUM_SINGLE(UDA1380_MODE, 14, 4, uda1380_spf_mode);         /* M */
+static const struct soc_enum uda1380_capture_sel_enum =
+       SOC_ENUM_SINGLE(UDA1380_IFACE, 6, 2, uda1380_capture_sel);      /* SEL_SOURCE */
+static const struct soc_enum uda1380_sel_ns_enum =
+       SOC_ENUM_SINGLE(UDA1380_MIXER, 14, 2, uda1380_sel_ns);          /* SEL_NS */
+static const struct soc_enum uda1380_mix_enum =
+       SOC_ENUM_SINGLE(UDA1380_MIXER, 12, 4, uda1380_mix_control);     /* MIX, MIX_POS */
+static const struct soc_enum uda1380_sdet_enum =
+       SOC_ENUM_SINGLE(UDA1380_MIXER, 4, 4, uda1380_sdet_setting);     /* SD_VALUE */
+static const struct soc_enum uda1380_os_enum =
+       SOC_ENUM_SINGLE(UDA1380_MIXER, 0, 3, uda1380_os_setting);       /* OS */
+
+/*
+ * from -48 dB in 1.5 dB steps (mute instead of -49.5 dB)
+ */
+static DECLARE_TLV_DB_SCALE(amix_tlv, -4950, 150, 1);
+
+/*
+ * from -78 dB in 1 dB steps (3 dB steps, really. LSB are ignored),
+ * from -66 dB in 0.5 dB steps (2 dB steps, really) and
+ * from -52 dB in 0.25 dB steps
+ */
+static const unsigned int mvol_tlv[] = {
+       TLV_DB_RANGE_HEAD(3),
+       0, 15, TLV_DB_SCALE_ITEM(-8200, 100, 1),
+       16, 43, TLV_DB_SCALE_ITEM(-6600, 50, 0),
+       44, 252, TLV_DB_SCALE_ITEM(-5200, 25, 0),
+};
+
+/*
+ * from -72 dB in 1.5 dB steps (6 dB steps really),
+ * from -66 dB in 0.75 dB steps (3 dB steps really),
+ * from -60 dB in 0.5 dB steps (2 dB steps really) and
+ * from -46 dB in 0.25 dB steps
+ */
+static const unsigned int vc_tlv[] = {
+       TLV_DB_RANGE_HEAD(4),
+       0, 7, TLV_DB_SCALE_ITEM(-7800, 150, 1),
+       8, 15, TLV_DB_SCALE_ITEM(-6600, 75, 0),
+       16, 43, TLV_DB_SCALE_ITEM(-6000, 50, 0),
+       44, 228, TLV_DB_SCALE_ITEM(-4600, 25, 0),
+};
+
+/* from 0 to 6 dB in 2 dB steps if SPF mode != flat */
+static DECLARE_TLV_DB_SCALE(tr_tlv, 0, 200, 0);
+
+/* from 0 to 24 dB in 2 dB steps, if SPF mode == maximum, otherwise cuts
+ * off at 18 dB max) */
+static DECLARE_TLV_DB_SCALE(bb_tlv, 0, 200, 0);
+
+/* from -63 to 24 dB in 0.5 dB steps (-128...48) */
+static DECLARE_TLV_DB_SCALE(dec_tlv, -6400, 50, 1);
+
+/* from 0 to 24 dB in 3 dB steps */
+static DECLARE_TLV_DB_SCALE(pga_tlv, 0, 300, 0);
+
+/* from 0 to 30 dB in 2 dB steps */
+static DECLARE_TLV_DB_SCALE(vga_tlv, 0, 200, 0);
+
+static const struct snd_kcontrol_new uda1380_snd_controls[] = {
+       SOC_DOUBLE_TLV("Analog Mixer Volume", UDA1380_AMIX, 0, 8, 44, 1, amix_tlv),     /* AVCR, AVCL */
+       SOC_DOUBLE_TLV("Master Playback Volume", UDA1380_MVOL, 0, 8, 252, 1, mvol_tlv), /* MVCL, MVCR */
+       SOC_SINGLE_TLV("ADC Playback Volume", UDA1380_MIXVOL, 8, 228, 1, vc_tlv),       /* VC2 */
+       SOC_SINGLE_TLV("PCM Playback Volume", UDA1380_MIXVOL, 0, 228, 1, vc_tlv),       /* VC1 */
+       SOC_ENUM("Sound Processing Filter", uda1380_spf_enum),                          /* M */
+       SOC_DOUBLE_TLV("Tone Control - Treble", UDA1380_MODE, 4, 12, 3, 0, tr_tlv),     /* TRL, TRR */
+       SOC_DOUBLE_TLV("Tone Control - Bass", UDA1380_MODE, 0, 8, 15, 0, bb_tlv),       /* BBL, BBR */
+/**/   SOC_SINGLE("Master Playback Switch", UDA1380_DEEMP, 14, 1, 1),          /* MTM */
+       SOC_SINGLE("ADC Playback Switch", UDA1380_DEEMP, 11, 1, 1),             /* MT2 from decimation filter */
+       SOC_ENUM("ADC Playback De-emphasis", uda1380_deemp_enum[0]),            /* DE2 */
+       SOC_SINGLE("PCM Playback Switch", UDA1380_DEEMP, 3, 1, 1),              /* MT1, from digital data input */
+       SOC_ENUM("PCM Playback De-emphasis", uda1380_deemp_enum[1]),            /* DE1 */
+       SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0),   /* DA_POL_INV */
+       SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum),                          /* SEL_NS */
+       SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum),             /* MIX_POS, MIX */
+       SOC_SINGLE("Silence Switch", UDA1380_MIXER, 7, 1, 0),                   /* SILENCE, force DAC output to silence */
+       SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0),          /* SDET_ON */
+       SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum),                /* SD_VALUE */
+       SOC_ENUM("Oversampling Input", uda1380_os_enum),                        /* OS */
+       SOC_DOUBLE_S8_TLV("ADC Capture Volume", UDA1380_DEC, -128, 48, dec_tlv),        /* ML_DEC, MR_DEC */
+/**/   SOC_SINGLE("ADC Capture Switch", UDA1380_PGA, 15, 1, 1),                /* MT_ADC */
+       SOC_DOUBLE_TLV("Line Capture Volume", UDA1380_PGA, 0, 8, 8, 0, pga_tlv), /* PGA_GAINCTRLL, PGA_GAINCTRLR */
+       SOC_SINGLE("ADC Polarity inverting Switch", UDA1380_ADC, 12, 1, 0),     /* ADCPOL_INV */
+       SOC_SINGLE_TLV("Mic Capture Volume", UDA1380_ADC, 8, 15, 0, vga_tlv),   /* VGA_CTRL */
+       SOC_SINGLE("DC Filter Bypass Switch", UDA1380_ADC, 1, 1, 0),            /* SKIP_DCFIL (before decimator) */
+       SOC_SINGLE("DC Filter Enable Switch", UDA1380_ADC, 0, 1, 0),            /* EN_DCFIL (at output of decimator) */
+       SOC_SINGLE("AGC Timing", UDA1380_AGC, 8, 7, 0),                 /* TODO: enum, see table 62 */
+       SOC_SINGLE("AGC Target level", UDA1380_AGC, 2, 3, 1),                   /* AGC_LEVEL */
+       /* -5.5, -8, -11.5, -14 dBFS */
+       SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0),
+};
+
+/* add non dapm controls */
+static int uda1380_add_controls(struct snd_soc_codec *codec)
+{
+       int err, i;
+
+       for (i = 0; i < ARRAY_SIZE(uda1380_snd_controls); i++) {
+               err = snd_ctl_add(codec->card,
+                       snd_soc_cnew(&uda1380_snd_controls[i], codec, NULL));
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+/* Input mux */
+static const struct snd_kcontrol_new uda1380_input_mux_control =
+       SOC_DAPM_ENUM("Route", uda1380_input_sel_enum);
+
+/* Output mux */
+static const struct snd_kcontrol_new uda1380_output_mux_control =
+       SOC_DAPM_ENUM("Route", uda1380_output_sel_enum);
+
+/* Capture mux */
+static const struct snd_kcontrol_new uda1380_capture_mux_control =
+       SOC_DAPM_ENUM("Route", uda1380_capture_sel_enum);
+
+
+static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
+       SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
+               &uda1380_input_mux_control),
+       SND_SOC_DAPM_MUX("Output Mux", SND_SOC_NOPM, 0, 0,
+               &uda1380_output_mux_control),
+       SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0,
+               &uda1380_capture_mux_control),
+       SND_SOC_DAPM_PGA("Left PGA", UDA1380_PM, 3, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("Right PGA", UDA1380_PM, 1, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("Mic LNA", UDA1380_PM, 4, 0, NULL, 0),
+       SND_SOC_DAPM_ADC("Left ADC", "Left Capture", UDA1380_PM, 2, 0),
+       SND_SOC_DAPM_ADC("Right ADC", "Right Capture", UDA1380_PM, 0, 0),
+       SND_SOC_DAPM_INPUT("VINM"),
+       SND_SOC_DAPM_INPUT("VINL"),
+       SND_SOC_DAPM_INPUT("VINR"),
+       SND_SOC_DAPM_MIXER("Analog Mixer", UDA1380_PM, 6, 0, NULL, 0),
+       SND_SOC_DAPM_OUTPUT("VOUTLHP"),
+       SND_SOC_DAPM_OUTPUT("VOUTRHP"),
+       SND_SOC_DAPM_OUTPUT("VOUTL"),
+       SND_SOC_DAPM_OUTPUT("VOUTR"),
+       SND_SOC_DAPM_DAC("DAC", "Playback", UDA1380_PM, 10, 0),
+       SND_SOC_DAPM_PGA("HeadPhone Driver", UDA1380_PM, 13, 0, NULL, 0),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+
+       /* output mux */
+       {"HeadPhone Driver", NULL, "Output Mux"},
+       {"VOUTR", NULL, "Output Mux"},
+       {"VOUTL", NULL, "Output Mux"},
+
+       {"Analog Mixer", NULL, "VINR"},
+       {"Analog Mixer", NULL, "VINL"},
+       {"Analog Mixer", NULL, "DAC"},
+
+       {"Output Mux", "DAC", "DAC"},
+       {"Output Mux", "Analog Mixer", "Analog Mixer"},
+
+       /* {"DAC", "Digital Mixer", "I2S" } */
+
+       /* headphone driver */
+       {"VOUTLHP", NULL, "HeadPhone Driver"},
+       {"VOUTRHP", NULL, "HeadPhone Driver"},
+
+       /* input mux */
+       {"Left ADC", NULL, "Input Mux"},
+       {"Input Mux", "Mic", "Mic LNA"},
+       {"Input Mux", "Mic + Line R", "Mic LNA"},
+       {"Input Mux", "Line L", "Left PGA"},
+       {"Input Mux", "Line", "Left PGA"},
+
+       /* right input */
+       {"Right ADC", "Mic + Line R", "Right PGA"},
+       {"Right ADC", "Line", "Right PGA"},
+
+       /* inputs */
+       {"Mic LNA", NULL, "VINM"},
+       {"Left PGA", NULL, "VINL"},
+       {"Right PGA", NULL, "VINR"},
+};
+
+static int uda1380_add_widgets(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets,
+                                 ARRAY_SIZE(uda1380_dapm_widgets));
+
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_dapm_new_widgets(codec);
+       return 0;
+}
+
+static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai,
+               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       int iface;
+
+       /* set up DAI based upon fmt */
+       iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
+       iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK);
+
+       /* FIXME: how to select I2S for DATAO and MSB for DATAI correctly? */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               iface |= R01_SFORI_I2S | R01_SFORO_I2S;
+               break;
+       case SND_SOC_DAIFMT_LSB:
+               iface |= R01_SFORI_LSB16 | R01_SFORO_I2S;
+               break;
+       case SND_SOC_DAIFMT_MSB:
+               iface |= R01_SFORI_MSB | R01_SFORO_I2S;
+       }
+
+       if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
+               iface |= R01_SIM;
+
+       uda1380_write(codec, UDA1380_IFACE, iface);
+
+       return 0;
+}
+
+/*
+ * Flush reg cache
+ * We can only write the interpolator and decimator registers
+ * when the DAI is being clocked by the CPU DAI. It's up to the
+ * machine and cpu DAI driver to do this before we are called.
+ */
+static int uda1380_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       int reg, reg_start, reg_end, clk;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               reg_start = UDA1380_MVOL;
+               reg_end = UDA1380_MIXER;
+       } else {
+               reg_start = UDA1380_DEC;
+               reg_end = UDA1380_AGC;
+       }
+
+       /* FIXME disable DAC_CLK */
+       clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+       uda1380_write(codec, UDA1380_CLK, clk & ~R00_DAC_CLK);
+
+       for (reg = reg_start; reg <= reg_end; reg++) {
+               pr_debug("uda1380: flush reg %x val %x:", reg,
+                               uda1380_read_reg_cache(codec, reg));
+               uda1380_write(codec, reg, uda1380_read_reg_cache(codec, reg));
+       }
+
+       /* FIXME enable DAC_CLK */
+       uda1380_write(codec, UDA1380_CLK, clk | R00_DAC_CLK);
+
+       return 0;
+}
+
+static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+
+       /* set WSPLL power and divider if running from this clock */
+       if (clk & R00_DAC_CLK) {
+               int rate = params_rate(params);
+               u16 pm = uda1380_read_reg_cache(codec, UDA1380_PM);
+               clk &= ~0x3; /* clear SEL_LOOP_DIV */
+               switch (rate) {
+               case 6250 ... 12500:
+                       clk |= 0x0;
+                       break;
+               case 12501 ... 25000:
+                       clk |= 0x1;
+                       break;
+               case 25001 ... 50000:
+                       clk |= 0x2;
+                       break;
+               case 50001 ... 100000:
+                       clk |= 0x3;
+                       break;
+               }
+               uda1380_write(codec, UDA1380_PM, R02_PON_PLL | pm);
+       }
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               clk |= R00_EN_DAC | R00_EN_INT;
+       else
+               clk |= R00_EN_ADC | R00_EN_DEC;
+
+       uda1380_write(codec, UDA1380_CLK, clk);
+       return 0;
+}
+
+static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+
+       /* shut down WSPLL power if running from this clock */
+       if (clk & R00_DAC_CLK) {
+               u16 pm = uda1380_read_reg_cache(codec, UDA1380_PM);
+               uda1380_write(codec, UDA1380_PM, ~R02_PON_PLL & pm);
+       }
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               clk &= ~(R00_EN_DAC | R00_EN_INT);
+       else
+               clk &= ~(R00_EN_ADC | R00_EN_DEC);
+
+       uda1380_write(codec, UDA1380_CLK, clk);
+}
+
+static int uda1380_mute(struct snd_soc_dai *codec_dai, int mute)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 mute_reg = uda1380_read_reg_cache(codec, UDA1380_DEEMP) & ~R13_MTM;
+
+       /* FIXME: mute(codec,0) is called when the magician clock is already
+        * set to WSPLL, but for some unknown reason writing to interpolator
+        * registers works only when clocked by SYSCLK */
+       u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
+       uda1380_write(codec, UDA1380_CLK, ~R00_DAC_CLK & clk);
+       if (mute)
+               uda1380_write(codec, UDA1380_DEEMP, mute_reg | R13_MTM);
+       else
+               uda1380_write(codec, UDA1380_DEEMP, mute_reg);
+       uda1380_write(codec, UDA1380_CLK, clk);
+       return 0;
+}
+
+static int uda1380_set_bias_level(struct snd_soc_codec *codec,
+       enum snd_soc_bias_level level)
+{
+       int pm = uda1380_read_reg_cache(codec, UDA1380_PM);
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+       case SND_SOC_BIAS_PREPARE:
+               uda1380_write(codec, UDA1380_PM, R02_PON_BIAS | pm);
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               uda1380_write(codec, UDA1380_PM, R02_PON_BIAS);
+               break;
+       case SND_SOC_BIAS_OFF:
+               uda1380_write(codec, UDA1380_PM, 0x0);
+               break;
+       }
+       codec->bias_level = level;
+       return 0;
+}
+
+#define UDA1380_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
+                      SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
+                      SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
+
+struct snd_soc_dai uda1380_dai[] = {
+{
+       .name = "UDA1380",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = UDA1380_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = UDA1380_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .ops = {
+               .hw_params = uda1380_pcm_hw_params,
+               .shutdown = uda1380_pcm_shutdown,
+               .prepare = uda1380_pcm_prepare,
+       },
+       .dai_ops = {
+               .digital_mute = uda1380_mute,
+               .set_fmt = uda1380_set_dai_fmt,
+       },
+},
+{ /* playback only - dual interface */
+       .name = "UDA1380",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = UDA1380_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,
+       },
+       .ops = {
+               .hw_params = uda1380_pcm_hw_params,
+               .shutdown = uda1380_pcm_shutdown,
+               .prepare = uda1380_pcm_prepare,
+       },
+       .dai_ops = {
+               .digital_mute = uda1380_mute,
+               .set_fmt = uda1380_set_dai_fmt,
+       },
+},
+{ /* capture only - dual interface*/
+       .name = "UDA1380",
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = UDA1380_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,
+       },
+       .ops = {
+               .hw_params = uda1380_pcm_hw_params,
+               .shutdown = uda1380_pcm_shutdown,
+               .prepare = uda1380_pcm_prepare,
+       },
+       .dai_ops = {
+               .set_fmt = uda1380_set_dai_fmt,
+       },
+},
+};
+EXPORT_SYMBOL_GPL(uda1380_dai);
+
+static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int uda1380_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+       int i;
+       u8 data[2];
+       u16 *cache = codec->reg_cache;
+
+       /* Sync reg_cache with the hardware */
+       for (i = 0; i < ARRAY_SIZE(uda1380_reg); i++) {
+               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+               data[1] = cache[i] & 0x00ff;
+               codec->hw_write(codec->control_data, data, 2);
+       }
+       uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       uda1380_set_bias_level(codec, codec->suspend_bias_level);
+       return 0;
+}
+
+/*
+ * initialise the UDA1380 driver
+ * register mixer and dsp interfaces with the kernel
+ */
+static int uda1380_init(struct snd_soc_device *socdev, int dac_clk)
+{
+       struct snd_soc_codec *codec = socdev->codec;
+       int ret = 0;
+
+       codec->name = "UDA1380";
+       codec->owner = THIS_MODULE;
+       codec->read = uda1380_read_reg_cache;
+       codec->write = uda1380_write;
+       codec->set_bias_level = uda1380_set_bias_level;
+       codec->dai = uda1380_dai;
+       codec->num_dai = ARRAY_SIZE(uda1380_dai);
+       codec->reg_cache = kmemdup(uda1380_reg, sizeof(uda1380_reg),
+                                  GFP_KERNEL);
+       if (codec->reg_cache == NULL)
+               return -ENOMEM;
+       codec->reg_cache_size = ARRAY_SIZE(uda1380_reg);
+       codec->reg_cache_step = 1;
+       uda1380_reset(codec);
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               pr_err("uda1380: failed to create pcms\n");
+               goto pcm_err;
+       }
+
+       /* power on device */
+       uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       /* set clock input */
+       switch (dac_clk) {
+       case UDA1380_DAC_CLK_SYSCLK:
+               uda1380_write(codec, UDA1380_CLK, 0);
+               break;
+       case UDA1380_DAC_CLK_WSPLL:
+               uda1380_write(codec, UDA1380_CLK, R00_DAC_CLK);
+               break;
+       }
+
+       /* uda1380 init */
+       uda1380_add_controls(codec);
+       uda1380_add_widgets(codec);
+       ret = snd_soc_register_card(socdev);
+       if (ret < 0) {
+               pr_err("uda1380: failed to register card\n");
+               goto card_err;
+       }
+
+       return ret;
+
+card_err:
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+pcm_err:
+       kfree(codec->reg_cache);
+       return ret;
+}
+
+static struct snd_soc_device *uda1380_socdev;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+
+#define I2C_DRIVERID_UDA1380 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver uda1380_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+
+static int uda1380_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+       struct snd_soc_device *socdev = uda1380_socdev;
+       struct uda1380_setup_data *setup = socdev->codec_data;
+       struct snd_soc_codec *codec = socdev->codec;
+       struct i2c_client *i2c;
+       int ret;
+
+       if (addr != setup->i2c_address)
+               return -ENODEV;
+
+       client_template.adapter = adap;
+       client_template.addr = addr;
+
+       i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
+       if (i2c == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(i2c, codec);
+       codec->control_data = i2c;
+
+       ret = i2c_attach_client(i2c);
+       if (ret < 0) {
+               pr_err("uda1380: failed to attach codec at addr %x\n", addr);
+               goto err;
+       }
+
+       ret = uda1380_init(socdev, setup->dac_clk);
+       if (ret < 0) {
+               pr_err("uda1380: failed to initialise UDA1380\n");
+               goto err;
+       }
+       return ret;
+
+err:
+       kfree(codec);
+       kfree(i2c);
+       return ret;
+}
+
+static int uda1380_i2c_detach(struct i2c_client *client)
+{
+       struct snd_soc_codec *codec = i2c_get_clientdata(client);
+       i2c_detach_client(client);
+       kfree(codec->reg_cache);
+       kfree(client);
+       return 0;
+}
+
+static int uda1380_i2c_attach(struct i2c_adapter *adap)
+{
+       return i2c_probe(adap, &addr_data, uda1380_codec_probe);
+}
+
+static struct i2c_driver uda1380_i2c_driver = {
+       .driver = {
+               .name =  "UDA1380 I2C Codec",
+               .owner = THIS_MODULE,
+       },
+       .id =             I2C_DRIVERID_UDA1380,
+       .attach_adapter = uda1380_i2c_attach,
+       .detach_client =  uda1380_i2c_detach,
+       .command =        NULL,
+};
+
+static struct i2c_client client_template = {
+       .name =   "UDA1380",
+       .driver = &uda1380_i2c_driver,
+};
+#endif
+
+static int uda1380_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct uda1380_setup_data *setup;
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       pr_info("UDA1380 Audio Codec %s", UDA1380_VERSION);
+
+       setup = socdev->codec_data;
+       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+       if (codec == NULL)
+               return -ENOMEM;
+
+       socdev->codec = codec;
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
+       uda1380_socdev = socdev;
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       if (setup->i2c_address) {
+               normal_i2c[0] = setup->i2c_address;
+               codec->hw_write = (hw_write_t)i2c_master_send;
+               ret = i2c_add_driver(&uda1380_i2c_driver);
+               if (ret != 0)
+                       printk(KERN_ERR "can't add i2c driver");
+       }
+#else
+       /* Add other interfaces here */
+#endif
+       return ret;
+}
+
+/* power down chip */
+static int uda1380_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       if (codec->control_data)
+               uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&uda1380_i2c_driver);
+#endif
+       kfree(codec);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_uda1380 = {
+       .probe =        uda1380_probe,
+       .remove =       uda1380_remove,
+       .suspend =      uda1380_suspend,
+       .resume =       uda1380_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_uda1380);
+
+MODULE_AUTHOR("Giorgio Padrin");
+MODULE_DESCRIPTION("Audio support for codec Philips UDA1380");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/uda1380.h b/sound/soc/codecs/uda1380.h
new file mode 100644 (file)
index 0000000..50c603e
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Audio support for Philips UDA1380
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org>
+ */
+
+#ifndef _UDA1380_H
+#define _UDA1380_H
+
+#define UDA1380_CLK    0x00
+#define UDA1380_IFACE  0x01
+#define UDA1380_PM     0x02
+#define UDA1380_AMIX   0x03
+#define UDA1380_HP     0x04
+#define UDA1380_MVOL   0x10
+#define UDA1380_MIXVOL 0x11
+#define UDA1380_MODE   0x12
+#define UDA1380_DEEMP  0x13
+#define UDA1380_MIXER  0x14
+#define UDA1380_INTSTAT        0x18
+#define UDA1380_DEC    0x20
+#define UDA1380_PGA    0x21
+#define UDA1380_ADC    0x22
+#define UDA1380_AGC    0x23
+#define UDA1380_DECSTAT        0x28
+#define UDA1380_RESET  0x7f
+
+#define UDA1380_CACHEREGNUM 0x24
+
+/* Register flags */
+#define R00_EN_ADC     0x0800
+#define R00_EN_DEC     0x0400
+#define R00_EN_DAC     0x0200
+#define R00_EN_INT     0x0100
+#define R00_DAC_CLK    0x0010
+#define R01_SFORI_I2S   0x0000
+#define R01_SFORI_LSB16 0x0100
+#define R01_SFORI_LSB18 0x0200
+#define R01_SFORI_LSB20 0x0300
+#define R01_SFORI_MSB   0x0500
+#define R01_SFORI_MASK  0x0700
+#define R01_SFORO_I2S   0x0000
+#define R01_SFORO_LSB16 0x0001
+#define R01_SFORO_LSB18 0x0002
+#define R01_SFORO_LSB20 0x0003
+#define R01_SFORO_LSB24 0x0004
+#define R01_SFORO_MSB   0x0005
+#define R01_SFORO_MASK  0x0007
+#define R01_SEL_SOURCE  0x0040
+#define R01_SIM                0x0010
+#define R02_PON_PLL    0x8000
+#define R02_PON_HP     0x2000
+#define R02_PON_DAC    0x0400
+#define R02_PON_BIAS   0x0100
+#define R02_EN_AVC     0x0080
+#define R02_PON_AVC    0x0040
+#define R02_PON_LNA    0x0010
+#define R02_PON_PGAL   0x0008
+#define R02_PON_ADCL   0x0004
+#define R02_PON_PGAR   0x0002
+#define R02_PON_ADCR   0x0001
+#define R13_MTM                0x4000
+#define R14_SILENCE    0x0080
+#define R14_SDET_ON    0x0040
+#define R21_MT_ADC     0x8000
+#define R22_SEL_LNA    0x0008
+#define R22_SEL_MIC    0x0004
+#define R22_SKIP_DCFIL 0x0002
+#define R23_AGC_EN     0x0001
+
+struct uda1380_setup_data {
+       unsigned short i2c_address;
+       int            dac_clk;
+#define UDA1380_DAC_CLK_SYSCLK 0
+#define UDA1380_DAC_CLK_WSPLL  1
+};
+
+#define UDA1380_DAI_DUPLEX     0 /* playback and capture on single DAI */
+#define UDA1380_DAI_PLAYBACK   1 /* playback DAI */
+#define UDA1380_DAI_CAPTURE    2 /* capture DAI */
+
+extern struct snd_soc_dai uda1380_dai[3];
+extern struct snd_soc_codec_device soc_codec_dev_uda1380;
+
+#endif /* _UDA1380_H */
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
new file mode 100644 (file)
index 0000000..67325fd
--- /dev/null
@@ -0,0 +1,817 @@
+/*
+ * wm8510.c  --  WM8510 ALSA Soc Audio driver
+ *
+ * Copyright 2006 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include "wm8510.h"
+
+#define AUDIO_NAME "wm8510"
+#define WM8510_VERSION "0.6"
+
+struct snd_soc_codec_device soc_codec_dev_wm8510;
+
+/*
+ * wm8510 register cache
+ * We can't read the WM8510 register space when we are
+ * using 2 wire for device control, so we cache them instead.
+ */
+static const u16 wm8510_reg[WM8510_CACHEREGNUM] = {
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0050, 0x0000, 0x0140, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x00ff,
+       0x0000, 0x0000, 0x0100, 0x00ff,
+       0x0000, 0x0000, 0x012c, 0x002c,
+       0x002c, 0x002c, 0x002c, 0x0000,
+       0x0032, 0x0000, 0x0000, 0x0000,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0038, 0x000b, 0x0032, 0x0000,
+       0x0008, 0x000c, 0x0093, 0x00e9,
+       0x0000, 0x0000, 0x0000, 0x0000,
+       0x0003, 0x0010, 0x0000, 0x0000,
+       0x0000, 0x0002, 0x0001, 0x0000,
+       0x0000, 0x0000, 0x0039, 0x0000,
+       0x0001,
+};
+
+/*
+ * read wm8510 register cache
+ */
+static inline unsigned int wm8510_read_reg_cache(struct snd_soc_codec *codec,
+       unsigned int reg)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg == WM8510_RESET)
+               return 0;
+       if (reg >= WM8510_CACHEREGNUM)
+               return -1;
+       return cache[reg];
+}
+
+/*
+ * write wm8510 register cache
+ */
+static inline void wm8510_write_reg_cache(struct snd_soc_codec *codec,
+       u16 reg, unsigned int value)
+{
+       u16 *cache = codec->reg_cache;
+       if (reg >= WM8510_CACHEREGNUM)
+               return;
+       cache[reg] = value;
+}
+
+/*
+ * write to the WM8510 register space
+ */
+static int wm8510_write(struct snd_soc_codec *codec, unsigned int reg,
+       unsigned int value)
+{
+       u8 data[2];
+
+       /* data is
+        *   D15..D9 WM8510 register offset
+        *   D8...D0 register data
+        */
+       data[0] = (reg << 1) | ((value >> 8) & 0x0001);
+       data[1] = value & 0x00ff;
+
+       wm8510_write_reg_cache(codec, reg, value);
+       if (codec->hw_write(codec->control_data, data, 2) == 2)
+               return 0;
+       else
+               return -EIO;
+}
+
+#define wm8510_reset(c)        wm8510_write(c, WM8510_RESET, 0)
+
+static const char *wm8510_companding[] = { "Off", "NC", "u-law", "A-law" };
+static const char *wm8510_deemp[] = { "None", "32kHz", "44.1kHz", "48kHz" };
+static const char *wm8510_alc[] = { "ALC", "Limiter" };
+
+static const struct soc_enum wm8510_enum[] = {
+       SOC_ENUM_SINGLE(WM8510_COMP, 1, 4, wm8510_companding), /* adc */
+       SOC_ENUM_SINGLE(WM8510_COMP, 3, 4, wm8510_companding), /* dac */
+       SOC_ENUM_SINGLE(WM8510_DAC,  4, 4, wm8510_deemp),
+       SOC_ENUM_SINGLE(WM8510_ALC3,  8, 2, wm8510_alc),
+};
+
+static const struct snd_kcontrol_new wm8510_snd_controls[] = {
+
+SOC_SINGLE("Digital Loopback Switch", WM8510_COMP, 0, 1, 0),
+
+SOC_ENUM("DAC Companding", wm8510_enum[1]),
+SOC_ENUM("ADC Companding", wm8510_enum[0]),
+
+SOC_ENUM("Playback De-emphasis", wm8510_enum[2]),
+SOC_SINGLE("DAC Inversion Switch", WM8510_DAC, 0, 1, 0),
+
+SOC_SINGLE("Master Playback Volume", WM8510_DACVOL, 0, 127, 0),
+
+SOC_SINGLE("High Pass Filter Switch", WM8510_ADC, 8, 1, 0),
+SOC_SINGLE("High Pass Cut Off", WM8510_ADC, 4, 7, 0),
+SOC_SINGLE("ADC Inversion Switch", WM8510_COMP, 0, 1, 0),
+
+SOC_SINGLE("Capture Volume", WM8510_ADCVOL,  0, 127, 0),
+
+SOC_SINGLE("DAC Playback Limiter Switch", WM8510_DACLIM1,  8, 1, 0),
+SOC_SINGLE("DAC Playback Limiter Decay", WM8510_DACLIM1,  4, 15, 0),
+SOC_SINGLE("DAC Playback Limiter Attack", WM8510_DACLIM1,  0, 15, 0),
+
+SOC_SINGLE("DAC Playback Limiter Threshold", WM8510_DACLIM2,  4, 7, 0),
+SOC_SINGLE("DAC Playback Limiter Boost", WM8510_DACLIM2,  0, 15, 0),
+
+SOC_SINGLE("ALC Enable Switch", WM8510_ALC1,  8, 1, 0),
+SOC_SINGLE("ALC Capture Max Gain", WM8510_ALC1,  3, 7, 0),
+SOC_SINGLE("ALC Capture Min Gain", WM8510_ALC1,  0, 7, 0),
+
+SOC_SINGLE("ALC Capture ZC Switch", WM8510_ALC2,  8, 1, 0),
+SOC_SINGLE("ALC Capture Hold", WM8510_ALC2,  4, 7, 0),
+SOC_SINGLE("ALC Capture Target", WM8510_ALC2,  0, 15, 0),
+
+SOC_ENUM("ALC Capture Mode", wm8510_enum[3]),
+SOC_SINGLE("ALC Capture Decay", WM8510_ALC3,  4, 15, 0),
+SOC_SINGLE("ALC Capture Attack", WM8510_ALC3,  0, 15, 0),
+
+SOC_SINGLE("ALC Capture Noise Gate Switch", WM8510_NGATE,  3, 1, 0),
+SOC_SINGLE("ALC Capture Noise Gate Threshold", WM8510_NGATE,  0, 7, 0),
+
+SOC_SINGLE("Capture PGA ZC Switch", WM8510_INPPGA,  7, 1, 0),
+SOC_SINGLE("Capture PGA Volume", WM8510_INPPGA,  0, 63, 0),
+
+SOC_SINGLE("Speaker Playback ZC Switch", WM8510_SPKVOL,  7, 1, 0),
+SOC_SINGLE("Speaker Playback Switch", WM8510_SPKVOL,  6, 1, 1),
+SOC_SINGLE("Speaker Playback Volume", WM8510_SPKVOL,  0, 63, 0),
+SOC_SINGLE("Speaker Boost", WM8510_OUTPUT, 2, 1, 0),
+
+SOC_SINGLE("Capture Boost(+20dB)", WM8510_ADCBOOST,  8, 1, 0),
+SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX, 6, 1, 1),
+};
+
+/* add non dapm controls */
+static int wm8510_add_controls(struct snd_soc_codec *codec)
+{
+       int err, i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8510_snd_controls); i++) {
+               err = snd_ctl_add(codec->card,
+                               snd_soc_cnew(&wm8510_snd_controls[i], codec,
+                                       NULL));
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+/* Speaker Output Mixer */
+static const struct snd_kcontrol_new wm8510_speaker_mixer_controls[] = {
+SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX, 1, 1, 0),
+SOC_DAPM_SINGLE("Aux Playback Switch", WM8510_SPKMIX, 5, 1, 0),
+SOC_DAPM_SINGLE("PCM Playback Switch", WM8510_SPKMIX, 0, 1, 0),
+};
+
+/* Mono Output Mixer */
+static const struct snd_kcontrol_new wm8510_mono_mixer_controls[] = {
+SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_MONOMIX, 1, 1, 0),
+SOC_DAPM_SINGLE("Aux Playback Switch", WM8510_MONOMIX, 2, 1, 0),
+SOC_DAPM_SINGLE("PCM Playback Switch", WM8510_MONOMIX, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new wm8510_boost_controls[] = {
+SOC_DAPM_SINGLE("Mic PGA Switch", WM8510_INPPGA,  6, 1, 0),
+SOC_DAPM_SINGLE("Aux Volume", WM8510_ADCBOOST, 0, 7, 0),
+SOC_DAPM_SINGLE("Mic Volume", WM8510_ADCBOOST, 4, 7, 0),
+};
+
+static const struct snd_kcontrol_new wm8510_micpga_controls[] = {
+SOC_DAPM_SINGLE("MICP Switch", WM8510_INPUT, 0, 1, 0),
+SOC_DAPM_SINGLE("MICN Switch", WM8510_INPUT, 1, 1, 0),
+SOC_DAPM_SINGLE("AUX Switch", WM8510_INPUT, 2, 1, 0),
+};
+
+static const struct snd_soc_dapm_widget wm8510_dapm_widgets[] = {
+SND_SOC_DAPM_MIXER("Speaker Mixer", WM8510_POWER3, 2, 0,
+       &wm8510_speaker_mixer_controls[0],
+       ARRAY_SIZE(wm8510_speaker_mixer_controls)),
+SND_SOC_DAPM_MIXER("Mono Mixer", WM8510_POWER3, 3, 0,
+       &wm8510_mono_mixer_controls[0],
+       ARRAY_SIZE(wm8510_mono_mixer_controls)),
+SND_SOC_DAPM_DAC("DAC", "HiFi Playback", WM8510_POWER3, 0, 0),
+SND_SOC_DAPM_ADC("ADC", "HiFi Capture", WM8510_POWER2, 0, 0),
+SND_SOC_DAPM_PGA("Aux Input", WM8510_POWER1, 6, 0, NULL, 0),
+SND_SOC_DAPM_PGA("SpkN Out", WM8510_POWER3, 5, 0, NULL, 0),
+SND_SOC_DAPM_PGA("SpkP Out", WM8510_POWER3, 6, 0, NULL, 0),
+SND_SOC_DAPM_PGA("Mono Out", WM8510_POWER3, 7, 0, NULL, 0),
+
+SND_SOC_DAPM_PGA("Mic PGA", WM8510_POWER2, 2, 0,
+                &wm8510_micpga_controls[0],
+                ARRAY_SIZE(wm8510_micpga_controls)),
+SND_SOC_DAPM_MIXER("Boost Mixer", WM8510_POWER2, 4, 0,
+       &wm8510_boost_controls[0],
+       ARRAY_SIZE(wm8510_boost_controls)),
+
+SND_SOC_DAPM_MICBIAS("Mic Bias", WM8510_POWER1, 4, 0),
+
+SND_SOC_DAPM_INPUT("MICN"),
+SND_SOC_DAPM_INPUT("MICP"),
+SND_SOC_DAPM_INPUT("AUX"),
+SND_SOC_DAPM_OUTPUT("MONOOUT"),
+SND_SOC_DAPM_OUTPUT("SPKOUTP"),
+SND_SOC_DAPM_OUTPUT("SPKOUTN"),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       /* Mono output mixer */
+       {"Mono Mixer", "PCM Playback Switch", "DAC"},
+       {"Mono Mixer", "Aux Playback Switch", "Aux Input"},
+       {"Mono Mixer", "Line Bypass Switch", "Boost Mixer"},
+
+       /* Speaker output mixer */
+       {"Speaker Mixer", "PCM Playback Switch", "DAC"},
+       {"Speaker Mixer", "Aux Playback Switch", "Aux Input"},
+       {"Speaker Mixer", "Line Bypass Switch", "Boost Mixer"},
+
+       /* Outputs */
+       {"Mono Out", NULL, "Mono Mixer"},
+       {"MONOOUT", NULL, "Mono Out"},
+       {"SpkN Out", NULL, "Speaker Mixer"},
+       {"SpkP Out", NULL, "Speaker Mixer"},
+       {"SPKOUTN", NULL, "SpkN Out"},
+       {"SPKOUTP", NULL, "SpkP Out"},
+
+       /* Microphone PGA */
+       {"Mic PGA", "MICN Switch", "MICN"},
+       {"Mic PGA", "MICP Switch", "MICP"},
+       { "Mic PGA", "AUX Switch", "Aux Input" },
+
+       /* Boost Mixer */
+       {"Boost Mixer", "Mic PGA Switch", "Mic PGA"},
+       {"Boost Mixer", "Mic Volume", "MICP"},
+       {"Boost Mixer", "Aux Volume", "Aux Input"},
+
+       {"ADC", NULL, "Boost Mixer"},
+};
+
+static int wm8510_add_widgets(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_new_controls(codec, wm8510_dapm_widgets,
+                                 ARRAY_SIZE(wm8510_dapm_widgets));
+
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_dapm_new_widgets(codec);
+       return 0;
+}
+
+struct pll_ {
+       unsigned int pre_div:4; /* prescale - 1 */
+       unsigned int n:4;
+       unsigned int k;
+};
+
+static struct pll_ pll_div;
+
+/* The size in bits of the pll divide multiplied by 10
+ * to allow rounding later */
+#define FIXED_PLL_SIZE ((1 << 24) * 10)
+
+static void pll_factors(unsigned int target, unsigned int source)
+{
+       unsigned long long Kpart;
+       unsigned int K, Ndiv, Nmod;
+
+       Ndiv = target / source;
+       if (Ndiv < 6) {
+               source >>= 1;
+               pll_div.pre_div = 1;
+               Ndiv = target / source;
+       } else
+               pll_div.pre_div = 0;
+
+       if ((Ndiv < 6) || (Ndiv > 12))
+               printk(KERN_WARNING
+                       "WM8510 N value %d outwith recommended range!d\n",
+                       Ndiv);
+
+       pll_div.n = Ndiv;
+       Nmod = target % source;
+       Kpart = FIXED_PLL_SIZE * (long long)Nmod;
+
+       do_div(Kpart, source);
+
+       K = Kpart & 0xFFFFFFFF;
+
+       /* Check if we need to round */
+       if ((K % 10) >= 5)
+               K += 5;
+
+       /* Move down to proper range now rounding is done */
+       K /= 10;
+
+       pll_div.k = K;
+}
+
+static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai,
+               int pll_id, unsigned int freq_in, unsigned int freq_out)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 reg;
+
+       if (freq_in == 0 || freq_out == 0) {
+               /* Clock CODEC directly from MCLK */
+               reg = wm8510_read_reg_cache(codec, WM8510_CLOCK);
+               wm8510_write(codec, WM8510_CLOCK, reg & 0x0ff);
+
+               /* Turn off PLL */
+               reg = wm8510_read_reg_cache(codec, WM8510_POWER1);
+               wm8510_write(codec, WM8510_POWER1, reg & 0x1df);
+               return 0;
+       }
+
+       pll_factors(freq_out*8, freq_in);
+
+       wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n);
+       wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18);
+       wm8510_write(codec, WM8510_PLLK2, (pll_div.k >> 9) & 0x1ff);
+       wm8510_write(codec, WM8510_PLLK3, pll_div.k & 0x1ff);
+       reg = wm8510_read_reg_cache(codec, WM8510_POWER1);
+       wm8510_write(codec, WM8510_POWER1, reg | 0x020);
+
+       /* Run CODEC from PLL instead of MCLK */
+       reg = wm8510_read_reg_cache(codec, WM8510_CLOCK);
+       wm8510_write(codec, WM8510_CLOCK, reg | 0x100);
+
+       return 0;
+}
+
+/*
+ * Configure WM8510 clock dividers.
+ */
+static int wm8510_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
+               int div_id, int div)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 reg;
+
+       switch (div_id) {
+       case WM8510_OPCLKDIV:
+               reg = wm8510_read_reg_cache(codec, WM8510_GPIO) & 0x1cf;
+               wm8510_write(codec, WM8510_GPIO, reg | div);
+               break;
+       case WM8510_MCLKDIV:
+               reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1f;
+               wm8510_write(codec, WM8510_CLOCK, reg | div);
+               break;
+       case WM8510_ADCCLK:
+               reg = wm8510_read_reg_cache(codec, WM8510_ADC) & 0x1f7;
+               wm8510_write(codec, WM8510_ADC, reg | div);
+               break;
+       case WM8510_DACCLK:
+               reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0x1f7;
+               wm8510_write(codec, WM8510_DAC, reg | div);
+               break;
+       case WM8510_BCLKDIV:
+               reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1e3;
+               wm8510_write(codec, WM8510_CLOCK, reg | div);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wm8510_set_dai_fmt(struct snd_soc_dai *codec_dai,
+               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 iface = 0;
+       u16 clk = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1fe;
+
+       /* set master/slave audio interface */
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:
+               clk |= 0x0001;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* interface format */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               iface |= 0x0010;
+               break;
+       case SND_SOC_DAIFMT_RIGHT_J:
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               iface |= 0x0008;
+               break;
+       case SND_SOC_DAIFMT_DSP_A:
+               iface |= 0x00018;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* clock inversion */
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF:
+               break;
+       case SND_SOC_DAIFMT_IB_IF:
+               iface |= 0x0180;
+               break;
+       case SND_SOC_DAIFMT_IB_NF:
+               iface |= 0x0100;
+               break;
+       case SND_SOC_DAIFMT_NB_IF:
+               iface |= 0x0080;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       wm8510_write(codec, WM8510_IFACE, iface);
+       wm8510_write(codec, WM8510_CLOCK, clk);
+       return 0;
+}
+
+static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f;
+       u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1;
+
+       /* bit size */
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               iface |= 0x0020;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               iface |= 0x0040;
+               break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               iface |= 0x0060;
+               break;
+       }
+
+       /* filter coefficient */
+       switch (params_rate(params)) {
+       case SNDRV_PCM_RATE_8000:
+               adn |= 0x5 << 1;
+               break;
+       case SNDRV_PCM_RATE_11025:
+               adn |= 0x4 << 1;
+               break;
+       case SNDRV_PCM_RATE_16000:
+               adn |= 0x3 << 1;
+               break;
+       case SNDRV_PCM_RATE_22050:
+               adn |= 0x2 << 1;
+               break;
+       case SNDRV_PCM_RATE_32000:
+               adn |= 0x1 << 1;
+               break;
+       case SNDRV_PCM_RATE_44100:
+       case SNDRV_PCM_RATE_48000:
+               break;
+       }
+
+       wm8510_write(codec, WM8510_IFACE, iface);
+       wm8510_write(codec, WM8510_ADD, adn);
+       return 0;
+}
+
+static int wm8510_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u16 mute_reg = wm8510_read_reg_cache(codec, WM8510_DAC) & 0xffbf;
+
+       if (mute)
+               wm8510_write(codec, WM8510_DAC, mute_reg | 0x40);
+       else
+               wm8510_write(codec, WM8510_DAC, mute_reg);
+       return 0;
+}
+
+/* liam need to make this lower power with dapm */
+static int wm8510_set_bias_level(struct snd_soc_codec *codec,
+       enum snd_soc_bias_level level)
+{
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               wm8510_write(codec, WM8510_POWER1, 0x1ff);
+               wm8510_write(codec, WM8510_POWER2, 0x1ff);
+               wm8510_write(codec, WM8510_POWER3, 0x1ff);
+               break;
+       case SND_SOC_BIAS_PREPARE:
+       case SND_SOC_BIAS_STANDBY:
+               break;
+       case SND_SOC_BIAS_OFF:
+               /* everything off, dac mute, inactive */
+               wm8510_write(codec, WM8510_POWER1, 0x0);
+               wm8510_write(codec, WM8510_POWER2, 0x0);
+               wm8510_write(codec, WM8510_POWER3, 0x0);
+               break;
+       }
+       codec->bias_level = level;
+       return 0;
+}
+
+#define WM8510_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
+               SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
+               SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
+
+#define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
+       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+
+struct snd_soc_dai wm8510_dai = {
+       .name = "WM8510 HiFi",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = WM8510_RATES,
+               .formats = WM8510_FORMATS,},
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = WM8510_RATES,
+               .formats = WM8510_FORMATS,},
+       .ops = {
+               .hw_params = wm8510_pcm_hw_params,
+       },
+       .dai_ops = {
+               .digital_mute = wm8510_mute,
+               .set_fmt = wm8510_set_dai_fmt,
+               .set_clkdiv = wm8510_set_dai_clkdiv,
+               .set_pll = wm8510_set_dai_pll,
+       },
+};
+EXPORT_SYMBOL_GPL(wm8510_dai);
+
+static int wm8510_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int wm8510_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+       int i;
+       u8 data[2];
+       u16 *cache = codec->reg_cache;
+
+       /* Sync reg_cache with the hardware */
+       for (i = 0; i < ARRAY_SIZE(wm8510_reg); i++) {
+               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
+               data[1] = cache[i] & 0x00ff;
+               codec->hw_write(codec->control_data, data, 2);
+       }
+       wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       wm8510_set_bias_level(codec, codec->suspend_bias_level);
+       return 0;
+}
+
+/*
+ * initialise the WM8510 driver
+ * register the mixer and dsp interfaces with the kernel
+ */
+static int wm8510_init(struct snd_soc_device *socdev)
+{
+       struct snd_soc_codec *codec = socdev->codec;
+       int ret = 0;
+
+       codec->name = "WM8510";
+       codec->owner = THIS_MODULE;
+       codec->read = wm8510_read_reg_cache;
+       codec->write = wm8510_write;
+       codec->set_bias_level = wm8510_set_bias_level;
+       codec->dai = &wm8510_dai;
+       codec->num_dai = 1;
+       codec->reg_cache_size = ARRAY_SIZE(wm8510_reg);
+       codec->reg_cache = kmemdup(wm8510_reg, sizeof(wm8510_reg), GFP_KERNEL);
+
+       if (codec->reg_cache == NULL)
+               return -ENOMEM;
+
+       wm8510_reset(codec);
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8510: failed to create pcms\n");
+               goto pcm_err;
+       }
+
+       /* power on device */
+       wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       wm8510_add_controls(codec);
+       wm8510_add_widgets(codec);
+       ret = snd_soc_register_card(socdev);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8510: failed to register card\n");
+               goto card_err;
+       }
+       return ret;
+
+card_err:
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+pcm_err:
+       kfree(codec->reg_cache);
+       return ret;
+}
+
+static struct snd_soc_device *wm8510_socdev;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+
+/*
+ * WM8510 2 wire address is 0x1a
+ */
+#define I2C_DRIVERID_WM8510 0xfefe /* liam -  need a proper id */
+
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8510_i2c_driver;
+static struct i2c_client client_template;
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+
+static int wm8510_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+       struct snd_soc_device *socdev = wm8510_socdev;
+       struct wm8510_setup_data *setup = socdev->codec_data;
+       struct snd_soc_codec *codec = socdev->codec;
+       struct i2c_client *i2c;
+       int ret;
+
+       if (addr != setup->i2c_address)
+               return -ENODEV;
+
+       client_template.adapter = adap;
+       client_template.addr = addr;
+
+       i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
+       if (i2c == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(i2c, codec);
+       codec->control_data = i2c;
+
+       ret = i2c_attach_client(i2c);
+       if (ret < 0) {
+               pr_err("failed to attach codec at addr %x\n", addr);
+               goto err;
+       }
+
+       ret = wm8510_init(socdev);
+       if (ret < 0) {
+               pr_err("failed to initialise WM8510\n");
+               goto err;
+       }
+       return ret;
+
+err:
+       kfree(codec);
+       kfree(i2c);
+       return ret;
+}
+
+static int wm8510_i2c_detach(struct i2c_client *client)
+{
+       struct snd_soc_codec *codec = i2c_get_clientdata(client);
+       i2c_detach_client(client);
+       kfree(codec->reg_cache);
+       kfree(client);
+       return 0;
+}
+
+static int wm8510_i2c_attach(struct i2c_adapter *adap)
+{
+       return i2c_probe(adap, &addr_data, wm8510_codec_probe);
+}
+
+/* corgi i2c codec control layer */
+static struct i2c_driver wm8510_i2c_driver = {
+       .driver = {
+               .name = "WM8510 I2C Codec",
+               .owner = THIS_MODULE,
+       },
+       .id =             I2C_DRIVERID_WM8510,
+       .attach_adapter = wm8510_i2c_attach,
+       .detach_client =  wm8510_i2c_detach,
+       .command =        NULL,
+};
+
+static struct i2c_client client_template = {
+       .name =   "WM8510",
+       .driver = &wm8510_i2c_driver,
+};
+#endif
+
+static int wm8510_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct wm8510_setup_data *setup;
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       pr_info("WM8510 Audio Codec %s", WM8510_VERSION);
+
+       setup = socdev->codec_data;
+       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+       if (codec == NULL)
+               return -ENOMEM;
+
+       socdev->codec = codec;
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
+       wm8510_socdev = socdev;
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       if (setup->i2c_address) {
+               normal_i2c[0] = setup->i2c_address;
+               codec->hw_write = (hw_write_t)i2c_master_send;
+               ret = i2c_add_driver(&wm8510_i2c_driver);
+               if (ret != 0)
+                       printk(KERN_ERR "can't add i2c driver");
+       }
+#else
+       /* Add other interfaces here */
+#endif
+       return ret;
+}
+
+/* power down chip */
+static int wm8510_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       if (codec->control_data)
+               wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&wm8510_i2c_driver);
+#endif
+       kfree(codec);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm8510 = {
+       .probe =        wm8510_probe,
+       .remove =       wm8510_remove,
+       .suspend =      wm8510_suspend,
+       .resume =       wm8510_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8510);
+
+MODULE_DESCRIPTION("ASoC WM8510 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8510.h b/sound/soc/codecs/wm8510.h
new file mode 100644 (file)
index 0000000..f5d2e42
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * wm8510.h  --  WM8510 Soc Audio driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _WM8510_H
+#define _WM8510_H
+
+/* WM8510 register space */
+
+#define WM8510_RESET           0x0
+#define WM8510_POWER1          0x1
+#define WM8510_POWER2          0x2
+#define WM8510_POWER3          0x3
+#define WM8510_IFACE           0x4
+#define WM8510_COMP                    0x5
+#define WM8510_CLOCK           0x6
+#define WM8510_ADD                     0x7
+#define WM8510_GPIO                    0x8
+#define WM8510_DAC                     0xa
+#define WM8510_DACVOL          0xb
+#define WM8510_ADC                     0xe
+#define WM8510_ADCVOL          0xf
+#define WM8510_EQ1                     0x12
+#define WM8510_EQ2                     0x13
+#define WM8510_EQ3                     0x14
+#define WM8510_EQ4                     0x15
+#define WM8510_EQ5                     0x16
+#define WM8510_DACLIM1         0x18
+#define WM8510_DACLIM2         0x19
+#define WM8510_NOTCH1          0x1b
+#define WM8510_NOTCH2          0x1c
+#define WM8510_NOTCH3          0x1d
+#define WM8510_NOTCH4          0x1e
+#define WM8510_ALC1                    0x20
+#define WM8510_ALC2                    0x21
+#define WM8510_ALC3                    0x22
+#define WM8510_NGATE           0x23
+#define WM8510_PLLN                    0x24
+#define WM8510_PLLK1           0x25
+#define WM8510_PLLK2           0x26
+#define WM8510_PLLK3           0x27
+#define WM8510_ATTEN           0x28
+#define WM8510_INPUT           0x2c
+#define WM8510_INPPGA          0x2d
+#define WM8510_ADCBOOST                0x2f
+#define WM8510_OUTPUT          0x31
+#define WM8510_SPKMIX          0x32
+#define WM8510_SPKVOL          0x36
+#define WM8510_MONOMIX         0x38
+
+#define WM8510_CACHEREGNUM     57
+
+/* Clock divider Id's */
+#define WM8510_OPCLKDIV                0
+#define WM8510_MCLKDIV         1
+#define WM8510_ADCCLK          2
+#define WM8510_DACCLK          3
+#define WM8510_BCLKDIV         4
+
+/* DAC clock dividers */
+#define WM8510_DACCLK_F2       (1 << 3)
+#define WM8510_DACCLK_F4       (0 << 3)
+
+/* ADC clock dividers */
+#define WM8510_ADCCLK_F2       (1 << 3)
+#define WM8510_ADCCLK_F4       (0 << 3)
+
+/* PLL Out dividers */
+#define WM8510_OPCLKDIV_1      (0 << 4)
+#define WM8510_OPCLKDIV_2      (1 << 4)
+#define WM8510_OPCLKDIV_3      (2 << 4)
+#define WM8510_OPCLKDIV_4      (3 << 4)
+
+/* BCLK clock dividers */
+#define WM8510_BCLKDIV_1       (0 << 2)
+#define WM8510_BCLKDIV_2       (1 << 2)
+#define WM8510_BCLKDIV_4       (2 << 2)
+#define WM8510_BCLKDIV_8       (3 << 2)
+#define WM8510_BCLKDIV_16      (4 << 2)
+#define WM8510_BCLKDIV_32      (5 << 2)
+
+/* MCLK clock dividers */
+#define WM8510_MCLKDIV_1       (0 << 5)
+#define WM8510_MCLKDIV_1_5     (1 << 5)
+#define WM8510_MCLKDIV_2       (2 << 5)
+#define WM8510_MCLKDIV_3       (3 << 5)
+#define WM8510_MCLKDIV_4       (4 << 5)
+#define WM8510_MCLKDIV_6       (5 << 5)
+#define WM8510_MCLKDIV_8       (6 << 5)
+#define WM8510_MCLKDIV_12      (7 << 5)
+
+struct wm8510_setup_data {
+       unsigned short i2c_address;
+};
+
+extern struct snd_soc_dai wm8510_dai;
+extern struct snd_soc_codec_device soc_codec_dev_wm8510;
+
+#endif
index 0cf9265..369d39c 100644 (file)
 #define AUDIO_NAME "wm8731"
 #define WM8731_VERSION "0.13"
 
-/*
- * Debug
- */
-
-#define WM8731_DEBUG 0
-
-#ifdef WM8731_DEBUG
-#define dbg(format, arg...) \
-       printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)
-#else
-#define dbg(format, arg...) do {} while (0)
-#endif
-#define err(format, arg...) \
-       printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)
-#define info(format, arg...) \
-       printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)
-#define warn(format, arg...) \
-       printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)
-
 struct snd_soc_codec_device soc_codec_dev_wm8731;
 
 /* codec private data */
@@ -193,7 +174,7 @@ SND_SOC_DAPM_INPUT("RLINEIN"),
 SND_SOC_DAPM_INPUT("LLINEIN"),
 };
 
-static const char *intercon[][3] = {
+static const struct snd_soc_dapm_route intercon[] = {
        /* output mixer */
        {"Output Mixer", "Line Bypass Switch", "Line Input"},
        {"Output Mixer", "HiFi Playback Switch", "DAC"},
@@ -214,22 +195,14 @@ static const char *intercon[][3] = {
        {"Line Input", NULL, "LLINEIN"},
        {"Line Input", NULL, "RLINEIN"},
        {"Mic Bias", NULL, "MICIN"},
-
-       /* terminator */
-       {NULL, NULL, NULL},
 };
 
 static int wm8731_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
+                                 ARRAY_SIZE(wm8731_dapm_widgets));
 
-       /* set up audio path interconnects */
-       for (i = 0; intercon[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, intercon[i][0],
-                       intercon[i][1], intercon[i][2]);
+       snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -345,7 +318,7 @@ static void wm8731_shutdown(struct snd_pcm_substream *substream)
        }
 }
 
-static int wm8731_mute(struct snd_soc_codec_dai *dai, int mute)
+static int wm8731_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u16 mute_reg = wm8731_read_reg_cache(codec, WM8731_APDIGI) & 0xfff7;
@@ -357,7 +330,7 @@ static int wm8731_mute(struct snd_soc_codec_dai *dai, int mute)
        return 0;
 }
 
-static int wm8731_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -376,7 +349,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
 }
 
 
-static int wm8731_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -435,29 +408,29 @@ static int wm8731_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return 0;
 }
 
-static int wm8731_dapm_event(struct snd_soc_codec *codec, int event)
+static int wm8731_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
 {
        u16 reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f;
 
-       switch (event) {
-       case SNDRV_CTL_POWER_D0: /* full On */
+       switch (level) {
+       case SND_SOC_BIAS_ON:
                /* vref/mid, osc on, dac unmute */
                wm8731_write(codec, WM8731_PWR, reg);
                break;
-       case SNDRV_CTL_POWER_D1: /* partial On */
-       case SNDRV_CTL_POWER_D2: /* partial On */
+       case SND_SOC_BIAS_PREPARE:
                break;
-       case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+       case SND_SOC_BIAS_STANDBY:
                /* everything off except vref/vmid, */
                wm8731_write(codec, WM8731_PWR, reg | 0x0040);
                break;
-       case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+       case SND_SOC_BIAS_OFF:
                /* everything off, dac mute, inactive */
                wm8731_write(codec, WM8731_ACTIVE, 0x0);
                wm8731_write(codec, WM8731_PWR, 0xffff);
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
        return 0;
 }
 
@@ -470,7 +443,7 @@ static int wm8731_dapm_event(struct snd_soc_codec *codec, int event)
 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
        SNDRV_PCM_FMTBIT_S24_LE)
 
-struct snd_soc_codec_dai wm8731_dai = {
+struct snd_soc_dai wm8731_dai = {
        .name = "WM8731",
        .playback = {
                .stream_name = "Playback",
@@ -503,7 +476,7 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
        struct snd_soc_codec *codec = socdev->codec;
 
        wm8731_write(codec, WM8731_ACTIVE, 0x0);
-       wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+       wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
@@ -521,8 +494,8 @@ static int wm8731_resume(struct platform_device *pdev)
                data[1] = cache[i] & 0x00ff;
                codec->hw_write(codec->control_data, data, 2);
        }
-       wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
-       wm8731_dapm_event(codec, codec->suspend_dapm_state);
+       wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       wm8731_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
@@ -539,10 +512,10 @@ static int wm8731_init(struct snd_soc_device *socdev)
        codec->owner = THIS_MODULE;
        codec->read = wm8731_read_reg_cache;
        codec->write = wm8731_write;
-       codec->dapm_event = wm8731_dapm_event;
+       codec->set_bias_level = wm8731_set_bias_level;
        codec->dai = &wm8731_dai;
        codec->num_dai = 1;
-       codec->reg_cache_size = sizeof(wm8731_reg);
+       codec->reg_cache_size = ARRAY_SIZE(wm8731_reg);
        codec->reg_cache = kmemdup(wm8731_reg, sizeof(wm8731_reg), GFP_KERNEL);
        if (codec->reg_cache == NULL)
                return -ENOMEM;
@@ -557,7 +530,7 @@ static int wm8731_init(struct snd_soc_device *socdev)
        }
 
        /* power on device */
-       wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* set the update bits */
        reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V);
@@ -632,13 +605,13 @@ static int wm8731_codec_probe(struct i2c_adapter *adap, int addr, int kind)
 
        ret = i2c_attach_client(i2c);
        if (ret < 0) {
-               err("failed to attach codec at addr %x\n", addr);
+               pr_err("failed to attach codec at addr %x\n", addr);
                goto err;
        }
 
        ret = wm8731_init(socdev);
        if (ret < 0) {
-               err("failed to initialise WM8731\n");
+               pr_err("failed to initialise WM8731\n");
                goto err;
        }
        return ret;
@@ -689,7 +662,7 @@ static int wm8731_probe(struct platform_device *pdev)
        struct wm8731_priv *wm8731;
        int ret = 0;
 
-       info("WM8731 Audio Codec %s", WM8731_VERSION);
+       pr_info("WM8731 Audio Codec %s", WM8731_VERSION);
 
        setup = socdev->codec_data;
        codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
@@ -730,7 +703,7 @@ static int wm8731_remove(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->codec;
 
        if (codec->control_data)
-               wm8731_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+               wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
        snd_soc_free_pcms(socdev);
        snd_soc_dapm_free(socdev);
index 5bcab6a..99f2e3c 100644 (file)
@@ -38,7 +38,7 @@ struct wm8731_setup_data {
        unsigned short i2c_address;
 };
 
-extern struct snd_soc_codec_dai wm8731_dai;
+extern struct snd_soc_dai wm8731_dai;
 extern struct snd_soc_codec_device soc_codec_dev_wm8731;
 
 #endif
index 16cd5d4..e23cb09 100644 (file)
 #define AUDIO_NAME "WM8750"
 #define WM8750_VERSION "0.12"
 
-/*
- * Debug
- */
-
-#define WM8750_DEBUG 0
-
-#ifdef WM8750_DEBUG
-#define dbg(format, arg...) \
-       printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)
-#else
-#define dbg(format, arg...) do {} while (0)
-#endif
-#define err(format, arg...) \
-       printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)
-#define info(format, arg...) \
-       printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)
-#define warn(format, arg...) \
-       printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)
-
 /* codec private data */
 struct wm8750_priv {
        unsigned int sysclk;
@@ -378,7 +359,7 @@ static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
        SND_SOC_DAPM_INPUT("RINPUT3"),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* left mixer */
        {"Left Mixer", "Playback Switch", "Left DAC"},
        {"Left Mixer", "Left Bypass Switch", "Left Line Mux"},
@@ -470,22 +451,14 @@ static const char *audio_map[][3] = {
        /* ADC */
        {"Left ADC", NULL, "Left ADC Mux"},
        {"Right ADC", NULL, "Right ADC Mux"},
-
-       /* terminator */
-       {NULL, NULL, NULL},
 };
 
 static int wm8750_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
+                                 ARRAY_SIZE(wm8750_dapm_widgets));
 
-       /* set up audio path audio_mapnects */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -563,7 +536,7 @@ static inline int get_coeff(int mclk, int rate)
        return -EINVAL;
 }
 
-static int wm8750_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int wm8750_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -581,7 +554,7 @@ static int wm8750_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
        return -EINVAL;
 }
 
-static int wm8750_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8750_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -674,7 +647,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static int wm8750_mute(struct snd_soc_codec_dai *dai, int mute)
+static int wm8750_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u16 mute_reg = wm8750_read_reg_cache(codec, WM8750_ADCDAC) & 0xfff7;
@@ -686,29 +659,29 @@ static int wm8750_mute(struct snd_soc_codec_dai *dai, int mute)
        return 0;
 }
 
-static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
+static int wm8750_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
 {
        u16 pwr_reg = wm8750_read_reg_cache(codec, WM8750_PWR1) & 0xfe3e;
 
-       switch (event) {
-       case SNDRV_CTL_POWER_D0: /* full On */
+       switch (level) {
+       case SND_SOC_BIAS_ON:
                /* set vmid to 50k and unmute dac */
                wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x00c0);
                break;
-       case SNDRV_CTL_POWER_D1: /* partial On */
-       case SNDRV_CTL_POWER_D2: /* partial On */
+       case SND_SOC_BIAS_PREPARE:
                /* set vmid to 5k for quick power up */
                wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
                break;
-       case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+       case SND_SOC_BIAS_STANDBY:
                /* mute dac and set vmid to 500k, enable VREF */
                wm8750_write(codec, WM8750_PWR1, pwr_reg | 0x0141);
                break;
-       case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+       case SND_SOC_BIAS_OFF:
                wm8750_write(codec, WM8750_PWR1, 0x0001);
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
        return 0;
 }
 
@@ -719,7 +692,7 @@ static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
 #define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
        SNDRV_PCM_FMTBIT_S24_LE)
 
-struct snd_soc_codec_dai wm8750_dai = {
+struct snd_soc_dai wm8750_dai = {
        .name = "WM8750",
        .playback = {
                .stream_name = "Playback",
@@ -748,7 +721,7 @@ static void wm8750_work(struct work_struct *work)
 {
        struct snd_soc_codec *codec =
                container_of(work, struct snd_soc_codec, delayed_work.work);
-       wm8750_dapm_event(codec, codec->dapm_state);
+       wm8750_set_bias_level(codec, codec->bias_level);
 }
 
 static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
@@ -756,7 +729,7 @@ static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->codec;
 
-       wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+       wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
@@ -777,12 +750,12 @@ static int wm8750_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
 
-       wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* charge wm8750 caps */
-       if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
-               wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
-               codec->dapm_state = SNDRV_CTL_POWER_D0;
+       if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
+               wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
+               codec->bias_level = SND_SOC_BIAS_ON;
                schedule_delayed_work(&codec->delayed_work,
                                        msecs_to_jiffies(1000));
        }
@@ -803,10 +776,10 @@ static int wm8750_init(struct snd_soc_device *socdev)
        codec->owner = THIS_MODULE;
        codec->read = wm8750_read_reg_cache;
        codec->write = wm8750_write;
-       codec->dapm_event = wm8750_dapm_event;
+       codec->set_bias_level = wm8750_set_bias_level;
        codec->dai = &wm8750_dai;
        codec->num_dai = 1;
-       codec->reg_cache_size = sizeof(wm8750_reg);
+       codec->reg_cache_size = ARRAY_SIZE(wm8750_reg);
        codec->reg_cache = kmemdup(wm8750_reg, sizeof(wm8750_reg), GFP_KERNEL);
        if (codec->reg_cache == NULL)
                return -ENOMEM;
@@ -821,8 +794,8 @@ static int wm8750_init(struct snd_soc_device *socdev)
        }
 
        /* charge output caps */
-       wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
-       codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+       wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
+       codec->bias_level = SND_SOC_BIAS_STANDBY;
        schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000));
 
        /* set the update bits */
@@ -904,13 +877,13 @@ static int wm8750_codec_probe(struct i2c_adapter *adap, int addr, int kind)
 
        ret = i2c_attach_client(i2c);
        if (ret < 0) {
-               err("failed to attach codec at addr %x\n", addr);
+               pr_err("failed to attach codec at addr %x\n", addr);
                goto err;
        }
 
        ret = wm8750_init(socdev);
        if (ret < 0) {
-       err("failed to initialise WM8750\n");
+               pr_err("failed to initialise WM8750\n");
                goto err;
        }
        return ret;
@@ -961,7 +934,7 @@ static int wm8750_probe(struct platform_device *pdev)
        struct wm8750_priv *wm8750;
        int ret = 0;
 
-       info("WM8750 Audio Codec %s", WM8750_VERSION);
+       pr_info("WM8750 Audio Codec %s", WM8750_VERSION);
        codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
        if (codec == NULL)
                return -ENOMEM;
@@ -1021,7 +994,7 @@ static int wm8750_remove(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->codec;
 
        if (codec->control_data)
-               wm8750_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+               wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
        run_delayed_work(&codec->delayed_work);
        snd_soc_free_pcms(socdev);
        snd_soc_dapm_free(socdev);
index a97a54a..8ef30e6 100644 (file)
@@ -61,7 +61,7 @@ struct wm8750_setup_data {
        unsigned short i2c_address;
 };
 
-extern struct snd_soc_codec_dai wm8750_dai;
+extern struct snd_soc_dai wm8750_dai;
 extern struct snd_soc_codec_device soc_codec_dev_wm8750;
 
 #endif
index fb41826..8604809 100644 (file)
 #define AUDIO_NAME "wm8753"
 #define WM8753_VERSION "0.16"
 
-/*
- * Debug
- */
-
-#define WM8753_DEBUG 0
-
-#ifdef WM8753_DEBUG
-#define dbg(format, arg...) \
-       printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)
-#else
-#define dbg(format, arg...) do {} while (0)
-#endif
-#define err(format, arg...) \
-       printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)
-#define info(format, arg...) \
-       printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)
-#define warn(format, arg...) \
-       printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)
-
 static int caps_charge = 2000;
 module_param(caps_charge, int, 0);
 MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
@@ -260,28 +241,50 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
        return 1;
 }
 
-static const DECLARE_TLV_DB_LINEAR(rec_mix_tlv, -1500, 600);
+static const DECLARE_TLV_DB_SCALE(rec_mix_tlv, -1500, 300, 0);
+static const DECLARE_TLV_DB_SCALE(mic_preamp_tlv, 1200, 600, 0);
+static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
+static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
+static const unsigned int out_tlv[] = {
+       TLV_DB_RANGE_HEAD(2),
+       /* 0000000 - 0101111 = "Analogue mute" */
+       0, 48, TLV_DB_SCALE_ITEM(-25500, 0, 0),
+       48, 127, TLV_DB_SCALE_ITEM(-7300, 100, 0),
+};
+static const DECLARE_TLV_DB_SCALE(mix_tlv, -1500, 300, 0);
+static const DECLARE_TLV_DB_SCALE(voice_mix_tlv, -1200, 300, 0);
+static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0);
 
 static const struct snd_kcontrol_new wm8753_snd_controls[] = {
-SOC_DOUBLE_R("PCM Volume", WM8753_LDAC, WM8753_RDAC, 0, 255, 0),
-
-SOC_DOUBLE_R("ADC Capture Volume", WM8753_LADC, WM8753_RADC, 0, 255, 0),
-
-SOC_DOUBLE_R("Headphone Playback Volume", WM8753_LOUT1V, WM8753_ROUT1V, 0, 127, 0),
-SOC_DOUBLE_R("Speaker Playback Volume", WM8753_LOUT2V, WM8753_ROUT2V, 0, 127, 0),
-
-SOC_SINGLE("Mono Playback Volume", WM8753_MOUTV, 0, 127, 0),
-
-SOC_DOUBLE_R("Bypass Playback Volume", WM8753_LOUTM1, WM8753_ROUTM1, 4, 7, 1),
-SOC_DOUBLE_R("Sidetone Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 4, 7, 1),
-SOC_DOUBLE_R("Voice Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 0, 7, 1),
-
-SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V, WM8753_ROUT1V, 7, 1, 0),
-SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0),
-
-SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1),
-SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1),
-SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1),
+SOC_DOUBLE_R_TLV("PCM Volume", WM8753_LDAC, WM8753_RDAC, 0, 255, 0, dac_tlv),
+
+SOC_DOUBLE_R_TLV("ADC Capture Volume", WM8753_LADC, WM8753_RADC, 0, 255, 0,
+                adc_tlv),
+
+SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8753_LOUT1V, WM8753_ROUT1V,
+                0, 127, 0, out_tlv),
+SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8753_LOUT2V, WM8753_ROUT2V, 0,
+                127, 0, out_tlv),
+
+SOC_SINGLE_TLV("Mono Playback Volume", WM8753_MOUTV, 0, 127, 0, out_tlv),
+
+SOC_DOUBLE_R_TLV("Bypass Playback Volume", WM8753_LOUTM1, WM8753_ROUTM1, 4, 7,
+                1, mix_tlv),
+SOC_DOUBLE_R_TLV("Sidetone Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 4,
+                7, 1, mix_tlv),
+SOC_DOUBLE_R_TLV("Voice Playback Volume", WM8753_LOUTM2, WM8753_ROUTM2, 0, 7,
+                1, voice_mix_tlv),
+
+SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8753_LOUT1V, WM8753_ROUT1V, 7,
+            1, 0),
+SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7,
+            1, 0),
+
+SOC_SINGLE_TLV("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1, mix_tlv),
+SOC_SINGLE_TLV("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1,
+              voice_mix_tlv),
 SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0),
 
 SOC_ENUM("Bass Boost", wm8753_enum[0]),
@@ -291,10 +294,13 @@ SOC_SINGLE("Bass Volume", WM8753_BASS, 0, 15, 1),
 SOC_SINGLE("Treble Volume", WM8753_TREBLE, 0, 15, 1),
 SOC_ENUM("Treble Cut-off", wm8753_enum[2]),
 
-SOC_DOUBLE_TLV("Sidetone Capture Volume", WM8753_RECMIX1, 0, 4, 7, 1, rec_mix_tlv),
-SOC_SINGLE_TLV("Voice Sidetone Capture Volume", WM8753_RECMIX2, 0, 7, 1, rec_mix_tlv),
+SOC_DOUBLE_TLV("Sidetone Capture Volume", WM8753_RECMIX1, 0, 4, 7, 1,
+              rec_mix_tlv),
+SOC_SINGLE_TLV("Voice Sidetone Capture Volume", WM8753_RECMIX2, 0, 7, 1,
+              rec_mix_tlv),
 
-SOC_DOUBLE_R("Capture Volume", WM8753_LINVOL, WM8753_RINVOL, 0, 63, 0),
+SOC_DOUBLE_R_TLV("Capture Volume", WM8753_LINVOL, WM8753_RINVOL, 0, 63, 0,
+                pga_tlv),
 SOC_DOUBLE_R("Capture ZC Switch", WM8753_LINVOL, WM8753_RINVOL, 6, 1, 0),
 SOC_DOUBLE_R("Capture Switch", WM8753_LINVOL, WM8753_RINVOL, 7, 1, 1),
 
@@ -326,8 +332,8 @@ SOC_ENUM("De-emphasis", wm8753_enum[8]),
 SOC_ENUM("Playback Mono Mix", wm8753_enum[9]),
 SOC_ENUM("Playback Phase", wm8753_enum[10]),
 
-SOC_SINGLE("Mic2 Capture Volume", WM8753_INCTL1, 7, 3, 0),
-SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0),
+SOC_SINGLE_TLV("Mic2 Capture Volume", WM8753_INCTL1, 7, 3, 0, mic_preamp_tlv),
+SOC_SINGLE_TLV("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0, mic_preamp_tlv),
 
 SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai),
 
@@ -523,7 +529,7 @@ SND_SOC_DAPM_INPUT("MIC2"),
 SND_SOC_DAPM_VMID("VREF"),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* left mixer */
        {"Left Mixer", "Left Playback Switch", "Left DAC"},
        {"Left Mixer", "Voice Playback Switch", "Voice DAC"},
@@ -674,23 +680,14 @@ static const char *audio_map[][3] = {
 
        /* ACOP */
        {"ACOP", NULL, "ALC Mixer"},
-
-       /* terminator */
-       {NULL, NULL, NULL},
 };
 
 static int wm8753_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
+       snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets,
+                                 ARRAY_SIZE(wm8753_dapm_widgets));
 
-       for (i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]);
-
-       /* set up the WM8753 audio map */
-       for (i = 0; audio_map[i][0] != NULL; i++) {
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
-       }
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -743,7 +740,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
        pll_div->k = K;
 }
 
-static int wm8753_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_set_dai_pll(struct snd_soc_dai *codec_dai,
                int pll_id, unsigned int freq_in, unsigned int freq_out)
 {
        u16 reg, enable;
@@ -866,7 +863,7 @@ static int get_coeff(int mclk, int rate)
 /*
  * Clock after PLL and dividers
  */
-static int wm8753_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -893,7 +890,7 @@ static int wm8753_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
 /*
  * Set's ADC and Voice DAC format.
  */
-static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_vdac_adc_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -963,7 +960,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
 /*
  * Set's PCM dai fmt and BCLK.
  */
-static int wm8753_pcm_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1029,7 +1026,7 @@ static int wm8753_pcm_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return 0;
 }
 
-static int wm8753_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
                int div_id, int div)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1057,7 +1054,7 @@ static int wm8753_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
 /*
  * Set's HiFi DAC format.
  */
-static int wm8753_hdac_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_hdac_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1090,7 +1087,7 @@ static int wm8753_hdac_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
 /*
  * Set's I2S DAI format.
  */
-static int wm8753_i2s_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1198,7 +1195,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static int wm8753_mode1v_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_mode1v_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1213,7 +1210,7 @@ static int wm8753_mode1v_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return wm8753_pcm_set_dai_fmt(codec_dai, fmt);
 }
 
-static int wm8753_mode1h_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_mode1h_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        if (wm8753_hdac_set_dai_fmt(codec_dai, fmt) < 0)
@@ -1221,7 +1218,7 @@ static int wm8753_mode1h_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return wm8753_i2s_set_dai_fmt(codec_dai, fmt);
 }
 
-static int wm8753_mode2_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_mode2_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1236,7 +1233,7 @@ static int wm8753_mode2_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return wm8753_i2s_set_dai_fmt(codec_dai, fmt);
 }
 
-static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -1253,7 +1250,7 @@ static int wm8753_mode3_4_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
        return wm8753_i2s_set_dai_fmt(codec_dai, fmt);
 }
 
-static int wm8753_mute(struct snd_soc_codec_dai *dai, int mute)
+static int wm8753_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u16 mute_reg = wm8753_read_reg_cache(codec, WM8753_DAC) & 0xfff7;
@@ -1274,29 +1271,29 @@ static int wm8753_mute(struct snd_soc_codec_dai *dai, int mute)
        return 0;
 }
 
-static int wm8753_dapm_event(struct snd_soc_codec *codec, int event)
+static int wm8753_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
 {
        u16 pwr_reg = wm8753_read_reg_cache(codec, WM8753_PWR1) & 0xfe3e;
 
-       switch (event) {
-       case SNDRV_CTL_POWER_D0: /* full On */
+       switch (level) {
+       case SND_SOC_BIAS_ON:
                /* set vmid to 50k and unmute dac */
                wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x00c0);
                break;
-       case SNDRV_CTL_POWER_D1: /* partial On */
-       case SNDRV_CTL_POWER_D2: /* partial On */
+       case SND_SOC_BIAS_PREPARE:
                /* set vmid to 5k for quick power up */
                wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x01c1);
                break;
-       case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+       case SND_SOC_BIAS_STANDBY:
                /* mute dac and set vmid to 500k, enable VREF */
                wm8753_write(codec, WM8753_PWR1, pwr_reg | 0x0141);
                break;
-       case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+       case SND_SOC_BIAS_OFF:
                wm8753_write(codec, WM8753_PWR1, 0x0001);
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
        return 0;
 }
 
@@ -1319,7 +1316,7 @@ static int wm8753_dapm_event(struct snd_soc_codec *codec, int event)
  * 3. Voice disabled - HIFI over HIFI
  * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
  */
-static const struct snd_soc_codec_dai wm8753_all_dai[] = {
+static const struct snd_soc_dai wm8753_all_dai[] = {
 /* DAI HiFi mode 1 */
 {      .name = "WM8753 HiFi",
        .id = 1,
@@ -1459,7 +1456,7 @@ static const struct snd_soc_codec_dai wm8753_all_dai[] = {
 },
 };
 
-struct snd_soc_codec_dai wm8753_dai[2];
+struct snd_soc_dai wm8753_dai[2];
 EXPORT_SYMBOL_GPL(wm8753_dai);
 
 static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode)
@@ -1500,7 +1497,7 @@ static void wm8753_work(struct work_struct *work)
 {
        struct snd_soc_codec *codec =
                container_of(work, struct snd_soc_codec, delayed_work.work);
-       wm8753_dapm_event(codec, codec->dapm_state);
+       wm8753_set_bias_level(codec, codec->bias_level);
 }
 
 static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
@@ -1512,7 +1509,7 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
        if (!codec->card)
                return 0;
 
-       wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+       wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
@@ -1537,12 +1534,12 @@ static int wm8753_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
 
-       wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm8753_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* charge wm8753 caps */
-       if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
-               wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2);
-               codec->dapm_state = SNDRV_CTL_POWER_D0;
+       if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
+               wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
+               codec->bias_level = SND_SOC_BIAS_ON;
                schedule_delayed_work(&codec->delayed_work,
                        msecs_to_jiffies(caps_charge));
        }
@@ -1563,10 +1560,10 @@ static int wm8753_init(struct snd_soc_device *socdev)
        codec->owner = THIS_MODULE;
        codec->read = wm8753_read_reg_cache;
        codec->write = wm8753_write;
-       codec->dapm_event = wm8753_dapm_event;
+       codec->set_bias_level = wm8753_set_bias_level;
        codec->dai = wm8753_dai;
        codec->num_dai = 2;
-       codec->reg_cache_size = sizeof(wm8753_reg);
+       codec->reg_cache_size = ARRAY_SIZE(wm8753_reg);
        codec->reg_cache = kmemdup(wm8753_reg, sizeof(wm8753_reg), GFP_KERNEL);
 
        if (codec->reg_cache == NULL)
@@ -1584,8 +1581,8 @@ static int wm8753_init(struct snd_soc_device *socdev)
        }
 
        /* charge output caps */
-       wm8753_dapm_event(codec, SNDRV_CTL_POWER_D2);
-       codec->dapm_state = SNDRV_CTL_POWER_D3hot;
+       wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
+       codec->bias_level = SND_SOC_BIAS_STANDBY;
        schedule_delayed_work(&codec->delayed_work,
                msecs_to_jiffies(caps_charge));
 
@@ -1673,13 +1670,13 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
 
        ret = i2c_attach_client(i2c);
        if (ret < 0) {
-               err("failed to attach codec at addr %x\n", addr);
+               pr_err("failed to attach codec at addr %x\n", addr);
                goto err;
        }
 
        ret = wm8753_init(socdev);
        if (ret < 0) {
-               err("failed to initialise WM8753\n");
+               pr_err("failed to initialise WM8753\n");
                goto err;
        }
 
@@ -1731,7 +1728,7 @@ static int wm8753_probe(struct platform_device *pdev)
        struct wm8753_priv *wm8753;
        int ret = 0;
 
-       info("WM8753 Audio Codec %s", WM8753_VERSION);
+       pr_info("WM8753 Audio Codec %s", WM8753_VERSION);
 
        setup = socdev->codec_data;
        codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
@@ -1792,7 +1789,7 @@ static int wm8753_remove(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->codec;
 
        if (codec->control_data)
-               wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+               wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF);
        run_delayed_work(&codec->delayed_work);
        snd_soc_free_pcms(socdev);
        snd_soc_dapm_free(socdev);
index 95e2a1f..44f5f1f 100644 (file)
@@ -120,7 +120,7 @@ struct wm8753_setup_data {
 #define WM8753_DAI_HIFI                0
 #define WM8753_DAI_VOICE               1
 
-extern struct snd_soc_codec_dai wm8753_dai[2];
+extern struct snd_soc_dai wm8753_dai[2];
 extern struct snd_soc_codec_device soc_codec_dev_wm8753;
 
 #endif
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
new file mode 100644 (file)
index 0000000..3ecce51
--- /dev/null
@@ -0,0 +1,1626 @@
+/*
+ * wm8990.c  --  WM8990 ALSA Soc Audio driver
+ *
+ * Copyright 2008 Wolfson Microelectronics PLC.
+ * Author: Liam Girdwood
+ *         lg@opensource.wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+#include <asm/div64.h>
+
+#include "wm8990.h"
+
+#define AUDIO_NAME "wm8990"
+#define WM8990_VERSION "0.2"
+
+/* codec private data */
+struct wm8990_priv {
+       unsigned int sysclk;
+       unsigned int pcmclk;
+};
+
+/*
+ * wm8990 register cache.  Note that register 0 is not included in the
+ * cache.
+ */
+static const u16 wm8990_reg[] = {
+       0x8990,     /* R0  - Reset */
+       0x0000,     /* R1  - Power Management (1) */
+       0x6000,     /* R2  - Power Management (2) */
+       0x0000,     /* R3  - Power Management (3) */
+       0x4050,     /* R4  - Audio Interface (1) */
+       0x4000,     /* R5  - Audio Interface (2) */
+       0x01C8,     /* R6  - Clocking (1) */
+       0x0000,     /* R7  - Clocking (2) */
+       0x0040,     /* R8  - Audio Interface (3) */
+       0x0040,     /* R9  - Audio Interface (4) */
+       0x0004,     /* R10 - DAC CTRL */
+       0x00C0,     /* R11 - Left DAC Digital Volume */
+       0x00C0,     /* R12 - Right DAC Digital Volume */
+       0x0000,     /* R13 - Digital Side Tone */
+       0x0100,     /* R14 - ADC CTRL */
+       0x00C0,     /* R15 - Left ADC Digital Volume */
+       0x00C0,     /* R16 - Right ADC Digital Volume */
+       0x0000,     /* R17 */
+       0x0000,     /* R18 - GPIO CTRL 1 */
+       0x1000,     /* R19 - GPIO1 & GPIO2 */
+       0x1010,     /* R20 - GPIO3 & GPIO4 */
+       0x1010,     /* R21 - GPIO5 & GPIO6 */
+       0x8000,     /* R22 - GPIOCTRL 2 */
+       0x0800,     /* R23 - GPIO_POL */
+       0x008B,     /* R24 - Left Line Input 1&2 Volume */
+       0x008B,     /* R25 - Left Line Input 3&4 Volume */
+       0x008B,     /* R26 - Right Line Input 1&2 Volume */
+       0x008B,     /* R27 - Right Line Input 3&4 Volume */
+       0x0000,     /* R28 - Left Output Volume */
+       0x0000,     /* R29 - Right Output Volume */
+       0x0066,     /* R30 - Line Outputs Volume */
+       0x0022,     /* R31 - Out3/4 Volume */
+       0x0079,     /* R32 - Left OPGA Volume */
+       0x0079,     /* R33 - Right OPGA Volume */
+       0x0003,     /* R34 - Speaker Volume */
+       0x0003,     /* R35 - ClassD1 */
+       0x0000,     /* R36 */
+       0x0100,     /* R37 - ClassD3 */
+       0x0000,     /* R38 */
+       0x0000,     /* R39 - Input Mixer1 */
+       0x0000,     /* R40 - Input Mixer2 */
+       0x0000,     /* R41 - Input Mixer3 */
+       0x0000,     /* R42 - Input Mixer4 */
+       0x0000,     /* R43 - Input Mixer5 */
+       0x0000,     /* R44 - Input Mixer6 */
+       0x0000,     /* R45 - Output Mixer1 */
+       0x0000,     /* R46 - Output Mixer2 */
+       0x0000,     /* R47 - Output Mixer3 */
+       0x0000,     /* R48 - Output Mixer4 */
+       0x0000,     /* R49 - Output Mixer5 */
+       0x0000,     /* R50 - Output Mixer6 */
+       0x0180,     /* R51 - Out3/4 Mixer */
+       0x0000,     /* R52 - Line Mixer1 */
+       0x0000,     /* R53 - Line Mixer2 */
+       0x0000,     /* R54 - Speaker Mixer */
+       0x0000,     /* R55 - Additional Control */
+       0x0000,     /* R56 - AntiPOP1 */
+       0x0000,     /* R57 - AntiPOP2 */
+       0x0000,     /* R58 - MICBIAS */
+       0x0000,     /* R59 */
+       0x0008,     /* R60 - PLL1 */
+       0x0031,     /* R61 - PLL2 */
+       0x0026,     /* R62 - PLL3 */
+};
+
+/*
+ * read wm8990 register cache
+ */
+static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
+       unsigned int reg)
+{
+       u16 *cache = codec->reg_cache;
+       BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1);
+       return cache[reg];
+}
+
+/*
+ * write wm8990 register cache
+ */
+static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
+       unsigned int reg, unsigned int value)
+{
+       u16 *cache = codec->reg_cache;
+       BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1);
+
+       /* Reset register is uncached */
+       if (reg == 0)
+               return;
+
+       cache[reg] = value;
+}
+
+/*
+ * write to the wm8990 register space
+ */
+static int wm8990_write(struct snd_soc_codec *codec, unsigned int reg,
+       unsigned int value)
+{
+       u8 data[3];
+
+       data[0] = reg & 0xFF;
+       data[1] = (value >> 8) & 0xFF;
+       data[2] = value & 0xFF;
+
+       wm8990_write_reg_cache(codec, reg, value);
+
+       if (codec->hw_write(codec->control_data, data, 3) == 2)
+               return 0;
+       else
+               return -EIO;
+}
+
+#define wm8990_reset(c) wm8990_write(c, WM8990_RESET, 0)
+
+static const DECLARE_TLV_DB_LINEAR(rec_mix_tlv, -1500, 600);
+
+static const DECLARE_TLV_DB_LINEAR(in_pga_tlv, -1650, 3000);
+
+static const DECLARE_TLV_DB_LINEAR(out_mix_tlv, 0, -2100);
+
+static const DECLARE_TLV_DB_LINEAR(out_pga_tlv, -7300, 600);
+
+static const DECLARE_TLV_DB_LINEAR(out_omix_tlv, -600, 0);
+
+static const DECLARE_TLV_DB_LINEAR(out_dac_tlv, -7163, 0);
+
+static const DECLARE_TLV_DB_LINEAR(in_adc_tlv, -7163, 1763);
+
+static const DECLARE_TLV_DB_LINEAR(out_sidetone_tlv, -3600, 0);
+
+static int wm899x_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int ret;
+       u16 val;
+
+       ret = snd_soc_put_volsw(kcontrol, ucontrol);
+       if (ret < 0)
+               return ret;
+
+       /* now hit the volume update bits (always bit 8) */
+       val = wm8990_read_reg_cache(codec, reg);
+       return wm8990_write(codec, reg, val | 0x0100);
+}
+
+#define SOC_WM899X_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert,\
+        tlv_array) {\
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
+       .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
+                 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
+       .tlv.p = (tlv_array), \
+       .info = snd_soc_info_volsw, \
+       .get = snd_soc_get_volsw, .put = wm899x_outpga_put_volsw_vu, \
+       .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
+
+
+static const char *wm8990_digital_sidetone[] =
+       {"None", "Left ADC", "Right ADC", "Reserved"};
+
+static const struct soc_enum wm8990_left_digital_sidetone_enum =
+SOC_ENUM_SINGLE(WM8990_DIGITAL_SIDE_TONE,
+       WM8990_ADC_TO_DACL_SHIFT,
+       WM8990_ADC_TO_DACL_MASK,
+       wm8990_digital_sidetone);
+
+static const struct soc_enum wm8990_right_digital_sidetone_enum =
+SOC_ENUM_SINGLE(WM8990_DIGITAL_SIDE_TONE,
+       WM8990_ADC_TO_DACR_SHIFT,
+       WM8990_ADC_TO_DACR_MASK,
+       wm8990_digital_sidetone);
+
+static const char *wm8990_adcmode[] =
+       {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
+
+static const struct soc_enum wm8990_right_adcmode_enum =
+SOC_ENUM_SINGLE(WM8990_ADC_CTRL,
+       WM8990_ADC_HPF_CUT_SHIFT,
+       WM8990_ADC_HPF_CUT_MASK,
+       wm8990_adcmode);
+
+static const struct snd_kcontrol_new wm8990_snd_controls[] = {
+/* INMIXL */
+SOC_SINGLE("LIN12 PGA Boost", WM8990_INPUT_MIXER3, WM8990_L12MNBST_BIT, 1, 0),
+SOC_SINGLE("LIN34 PGA Boost", WM8990_INPUT_MIXER3, WM8990_L34MNBST_BIT, 1, 0),
+/* INMIXR */
+SOC_SINGLE("RIN12 PGA Boost", WM8990_INPUT_MIXER3, WM8990_R12MNBST_BIT, 1, 0),
+SOC_SINGLE("RIN34 PGA Boost", WM8990_INPUT_MIXER3, WM8990_R34MNBST_BIT, 1, 0),
+
+/* LOMIX */
+SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8990_OUTPUT_MIXER3,
+       WM8990_LLI3LOVOL_SHIFT, WM8990_LLI3LOVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8990_OUTPUT_MIXER3,
+       WM8990_LR12LOVOL_SHIFT, WM8990_LR12LOVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8990_OUTPUT_MIXER3,
+       WM8990_LL12LOVOL_SHIFT, WM8990_LL12LOVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8990_OUTPUT_MIXER5,
+       WM8990_LRI3LOVOL_SHIFT, WM8990_LRI3LOVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8990_OUTPUT_MIXER5,
+       WM8990_LRBLOVOL_SHIFT, WM8990_LRBLOVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8990_OUTPUT_MIXER5,
+       WM8990_LRBLOVOL_SHIFT, WM8990_LRBLOVOL_MASK, 1, out_mix_tlv),
+
+/* ROMIX */
+SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8990_OUTPUT_MIXER4,
+       WM8990_RRI3ROVOL_SHIFT, WM8990_RRI3ROVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8990_OUTPUT_MIXER4,
+       WM8990_RL12ROVOL_SHIFT, WM8990_RL12ROVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8990_OUTPUT_MIXER4,
+       WM8990_RR12ROVOL_SHIFT, WM8990_RR12ROVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8990_OUTPUT_MIXER6,
+       WM8990_RLI3ROVOL_SHIFT, WM8990_RLI3ROVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8990_OUTPUT_MIXER6,
+       WM8990_RLBROVOL_SHIFT, WM8990_RLBROVOL_MASK, 1, out_mix_tlv),
+SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8990_OUTPUT_MIXER6,
+       WM8990_RRBROVOL_SHIFT, WM8990_RRBROVOL_MASK, 1, out_mix_tlv),
+
+/* LOUT */
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8990_LEFT_OUTPUT_VOLUME,
+       WM8990_LOUTVOL_SHIFT, WM8990_LOUTVOL_MASK, 0, out_pga_tlv),
+SOC_SINGLE("LOUT ZC", WM8990_LEFT_OUTPUT_VOLUME, WM8990_LOZC_BIT, 1, 0),
+
+/* ROUT */
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8990_RIGHT_OUTPUT_VOLUME,
+       WM8990_ROUTVOL_SHIFT, WM8990_ROUTVOL_MASK, 0, out_pga_tlv),
+SOC_SINGLE("ROUT ZC", WM8990_RIGHT_OUTPUT_VOLUME, WM8990_ROZC_BIT, 1, 0),
+
+/* LOPGA */
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8990_LEFT_OPGA_VOLUME,
+       WM8990_LOPGAVOL_SHIFT, WM8990_LOPGAVOL_MASK, 0, out_pga_tlv),
+SOC_SINGLE("LOPGA ZC Switch", WM8990_LEFT_OPGA_VOLUME,
+       WM8990_LOPGAZC_BIT, 1, 0),
+
+/* ROPGA */
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8990_RIGHT_OPGA_VOLUME,
+       WM8990_ROPGAVOL_SHIFT, WM8990_ROPGAVOL_MASK, 0, out_pga_tlv),
+SOC_SINGLE("ROPGA ZC Switch", WM8990_RIGHT_OPGA_VOLUME,
+       WM8990_ROPGAZC_BIT, 1, 0),
+
+SOC_SINGLE("LON Mute Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_LONMUTE_BIT, 1, 0),
+SOC_SINGLE("LOP Mute Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_LOPMUTE_BIT, 1, 0),
+SOC_SINGLE("LOP Attenuation Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_LOATTN_BIT, 1, 0),
+SOC_SINGLE("RON Mute Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_RONMUTE_BIT, 1, 0),
+SOC_SINGLE("ROP Mute Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_ROPMUTE_BIT, 1, 0),
+SOC_SINGLE("ROP Attenuation Switch", WM8990_LINE_OUTPUTS_VOLUME,
+       WM8990_ROATTN_BIT, 1, 0),
+
+SOC_SINGLE("OUT3 Mute Switch", WM8990_OUT3_4_VOLUME,
+       WM8990_OUT3MUTE_BIT, 1, 0),
+SOC_SINGLE("OUT3 Attenuation Switch", WM8990_OUT3_4_VOLUME,
+       WM8990_OUT3ATTN_BIT, 1, 0),
+
+SOC_SINGLE("OUT4 Mute Switch", WM8990_OUT3_4_VOLUME,
+       WM8990_OUT4MUTE_BIT, 1, 0),
+SOC_SINGLE("OUT4 Attenuation Switch", WM8990_OUT3_4_VOLUME,
+       WM8990_OUT4ATTN_BIT, 1, 0),
+
+SOC_SINGLE("Speaker Mode Switch", WM8990_CLASSD1,
+       WM8990_CDMODE_BIT, 1, 0),
+
+SOC_SINGLE("Speaker Output Attenuation Volume", WM8990_SPEAKER_VOLUME,
+       WM8990_SPKVOL_SHIFT, WM8990_SPKVOL_MASK, 0),
+SOC_SINGLE("Speaker DC Boost Volume", WM8990_CLASSD3,
+       WM8990_DCGAIN_SHIFT, WM8990_DCGAIN_MASK, 0),
+SOC_SINGLE("Speaker AC Boost Volume", WM8990_CLASSD3,
+       WM8990_ACGAIN_SHIFT, WM8990_ACGAIN_MASK, 0),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume",
+       WM8990_LEFT_DAC_DIGITAL_VOLUME,
+       WM8990_DACL_VOL_SHIFT,
+       WM8990_DACL_VOL_MASK,
+       0,
+       out_dac_tlv),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume",
+       WM8990_RIGHT_DAC_DIGITAL_VOLUME,
+       WM8990_DACR_VOL_SHIFT,
+       WM8990_DACR_VOL_MASK,
+       0,
+       out_dac_tlv),
+
+SOC_ENUM("Left Digital Sidetone", wm8990_left_digital_sidetone_enum),
+SOC_ENUM("Right Digital Sidetone", wm8990_right_digital_sidetone_enum),
+
+SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8990_DIGITAL_SIDE_TONE,
+       WM8990_ADCL_DAC_SVOL_SHIFT, WM8990_ADCL_DAC_SVOL_MASK, 0,
+       out_sidetone_tlv),
+SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8990_DIGITAL_SIDE_TONE,
+       WM8990_ADCR_DAC_SVOL_SHIFT, WM8990_ADCR_DAC_SVOL_MASK, 0,
+       out_sidetone_tlv),
+
+SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8990_ADC_CTRL,
+       WM8990_ADC_HPF_ENA_BIT, 1, 0),
+
+SOC_ENUM("ADC HPF Mode", wm8990_right_adcmode_enum),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume",
+       WM8990_LEFT_ADC_DIGITAL_VOLUME,
+       WM8990_ADCL_VOL_SHIFT,
+       WM8990_ADCL_VOL_MASK,
+       0,
+       in_adc_tlv),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume",
+       WM8990_RIGHT_ADC_DIGITAL_VOLUME,
+       WM8990_ADCR_VOL_SHIFT,
+       WM8990_ADCR_VOL_MASK,
+       0,
+       in_adc_tlv),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN12 Volume",
+       WM8990_LEFT_LINE_INPUT_1_2_VOLUME,
+       WM8990_LIN12VOL_SHIFT,
+       WM8990_LIN12VOL_MASK,
+       0,
+       in_pga_tlv),
+
+SOC_SINGLE("LIN12 ZC Switch", WM8990_LEFT_LINE_INPUT_1_2_VOLUME,
+       WM8990_LI12ZC_BIT, 1, 0),
+
+SOC_SINGLE("LIN12 Mute Switch", WM8990_LEFT_LINE_INPUT_1_2_VOLUME,
+       WM8990_LI12MUTE_BIT, 1, 0),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN34 Volume",
+       WM8990_LEFT_LINE_INPUT_3_4_VOLUME,
+       WM8990_LIN34VOL_SHIFT,
+       WM8990_LIN34VOL_MASK,
+       0,
+       in_pga_tlv),
+
+SOC_SINGLE("LIN34 ZC Switch", WM8990_LEFT_LINE_INPUT_3_4_VOLUME,
+       WM8990_LI34ZC_BIT, 1, 0),
+
+SOC_SINGLE("LIN34 Mute Switch", WM8990_LEFT_LINE_INPUT_3_4_VOLUME,
+       WM8990_LI34MUTE_BIT, 1, 0),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN12 Volume",
+       WM8990_RIGHT_LINE_INPUT_1_2_VOLUME,
+       WM8990_RIN12VOL_SHIFT,
+       WM8990_RIN12VOL_MASK,
+       0,
+       in_pga_tlv),
+
+SOC_SINGLE("RIN12 ZC Switch", WM8990_RIGHT_LINE_INPUT_1_2_VOLUME,
+       WM8990_RI12ZC_BIT, 1, 0),
+
+SOC_SINGLE("RIN12 Mute Switch", WM8990_RIGHT_LINE_INPUT_1_2_VOLUME,
+       WM8990_RI12MUTE_BIT, 1, 0),
+
+SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN34 Volume",
+       WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
+       WM8990_RIN34VOL_SHIFT,
+       WM8990_RIN34VOL_MASK,
+       0,
+       in_pga_tlv),
+
+SOC_SINGLE("RIN34 ZC Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
+       WM8990_RI34ZC_BIT, 1, 0),
+
+SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
+       WM8990_RI34MUTE_BIT, 1, 0),
+
+};
+
+/* add non dapm controls */
+static int wm8990_add_controls(struct snd_soc_codec *codec)
+{
+       int err, i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8990_snd_controls); i++) {
+               err = snd_ctl_add(codec->card,
+                               snd_soc_cnew(&wm8990_snd_controls[i], codec,
+                                       NULL));
+               if (err < 0)
+                       return err;
+       }
+       return 0;
+}
+
+/*
+ * _DAPM_ Controls
+ */
+
+static int inmixer_event(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       u16 reg, fakepower;
+
+       reg = wm8990_read_reg_cache(w->codec, WM8990_POWER_MANAGEMENT_2);
+       fakepower = wm8990_read_reg_cache(w->codec, WM8990_INTDRIVBITS);
+
+       if (fakepower & ((1 << WM8990_INMIXL_PWR_BIT) |
+               (1 << WM8990_AINLMUX_PWR_BIT))) {
+               reg |= WM8990_AINL_ENA;
+       } else {
+               reg &= ~WM8990_AINL_ENA;
+       }
+
+       if (fakepower & ((1 << WM8990_INMIXR_PWR_BIT) |
+               (1 << WM8990_AINRMUX_PWR_BIT))) {
+               reg |= WM8990_AINR_ENA;
+       } else {
+               reg &= ~WM8990_AINL_ENA;
+       }
+       wm8990_write(w->codec, WM8990_POWER_MANAGEMENT_2, reg);
+
+       return 0;
+}
+
+static int outmixer_event(struct snd_soc_dapm_widget *w,
+       struct snd_kcontrol *kcontrol, int event)
+{
+       u32 reg_shift = kcontrol->private_value & 0xfff;
+       int ret = 0;
+       u16 reg;
+
+       switch (reg_shift) {
+       case WM8990_SPEAKER_MIXER | (WM8990_LDSPK_BIT << 8) :
+               reg = wm8990_read_reg_cache(w->codec, WM8990_OUTPUT_MIXER1);
+               if (reg & WM8990_LDLO) {
+                       printk(KERN_WARNING
+                       "Cannot set as Output Mixer 1 LDLO Set\n");
+                       ret = -1;
+               }
+               break;
+       case WM8990_SPEAKER_MIXER | (WM8990_RDSPK_BIT << 8):
+               reg = wm8990_read_reg_cache(w->codec, WM8990_OUTPUT_MIXER2);
+               if (reg & WM8990_RDRO) {
+                       printk(KERN_WARNING
+                       "Cannot set as Output Mixer 2 RDRO Set\n");
+                       ret = -1;
+               }
+               break;
+       case WM8990_OUTPUT_MIXER1 | (WM8990_LDLO_BIT << 8):
+               reg = wm8990_read_reg_cache(w->codec, WM8990_SPEAKER_MIXER);
+               if (reg & WM8990_LDSPK) {
+                       printk(KERN_WARNING
+                       "Cannot set as Speaker Mixer LDSPK Set\n");
+                       ret = -1;
+               }
+               break;
+       case WM8990_OUTPUT_MIXER2 | (WM8990_RDRO_BIT << 8):
+               reg = wm8990_read_reg_cache(w->codec, WM8990_SPEAKER_MIXER);
+               if (reg & WM8990_RDSPK) {
+                       printk(KERN_WARNING
+                       "Cannot set as Speaker Mixer RDSPK Set\n");
+                       ret = -1;
+               }
+               break;
+       }
+
+       return ret;
+}
+
+/* INMIX dB values */
+static const unsigned int in_mix_tlv[] = {
+       TLV_DB_RANGE_HEAD(1),
+       0, 7, TLV_DB_LINEAR_ITEM(-1200, 600),
+};
+
+/* Left In PGA Connections */
+static const struct snd_kcontrol_new wm8990_dapm_lin12_pga_controls[] = {
+SOC_DAPM_SINGLE("LIN1 Switch", WM8990_INPUT_MIXER2, WM8990_LMN1_BIT, 1, 0),
+SOC_DAPM_SINGLE("LIN2 Switch", WM8990_INPUT_MIXER2, WM8990_LMP2_BIT, 1, 0),
+};
+
+static const struct snd_kcontrol_new wm8990_dapm_lin34_pga_controls[] = {
+SOC_DAPM_SINGLE("LIN3 Switch", WM8990_INPUT_MIXER2, WM8990_LMN3_BIT, 1, 0),
+SOC_DAPM_SINGLE("LIN4 Switch", WM8990_INPUT_MIXER2, WM8990_LMP4_BIT, 1, 0),
+};
+
+/* Right In PGA Connections */
+static const struct snd_kcontrol_new wm8990_dapm_rin12_pga_controls[] = {
+SOC_DAPM_SINGLE("RIN1 Switch", WM8990_INPUT_MIXER2, WM8990_RMN1_BIT, 1, 0),
+SOC_DAPM_SINGLE("RIN2 Switch", WM8990_INPUT_MIXER2, WM8990_RMP2_BIT, 1, 0),
+};
+
+static const struct snd_kcontrol_new wm8990_dapm_rin34_pga_controls[] = {
+SOC_DAPM_SINGLE("RIN3 Switch", WM8990_INPUT_MIXER2, WM8990_RMN3_BIT, 1, 0),
+SOC_DAPM_SINGLE("RIN4 Switch", WM8990_INPUT_MIXER2, WM8990_RMP4_BIT, 1, 0),
+};
+
+/* INMIXL */
+static const struct snd_kcontrol_new wm8990_dapm_inmixl_controls[] = {
+SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8990_INPUT_MIXER3,
+       WM8990_LDBVOL_SHIFT, WM8990_LDBVOL_MASK, 0, in_mix_tlv),
+SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8990_INPUT_MIXER5, WM8990_LI2BVOL_SHIFT,
+       7, 0, in_mix_tlv),
+SOC_DAPM_SINGLE("LINPGA12 Switch", WM8990_INPUT_MIXER3, WM8990_L12MNB_BIT,
+       1, 0),
+SOC_DAPM_SINGLE("LINPGA34 Switch", WM8990_INPUT_MIXER3, WM8990_L34MNB_BIT,
+       1, 0),
+};
+
+/* INMIXR */
+static const struct snd_kcontrol_new wm8990_dapm_inmixr_controls[] = {
+SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8990_INPUT_MIXER4,
+       WM8990_RDBVOL_SHIFT, WM8990_RDBVOL_MASK, 0, in_mix_tlv),
+SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8990_INPUT_MIXER6, WM8990_RI2BVOL_SHIFT,
+       7, 0, in_mix_tlv),
+SOC_DAPM_SINGLE("RINPGA12 Switch", WM8990_INPUT_MIXER3, WM8990_L12MNB_BIT,
+       1, 0),
+SOC_DAPM_SINGLE("RINPGA34 Switch", WM8990_INPUT_MIXER3, WM8990_L34MNB_BIT,
+       1, 0),
+};
+
+/* AINLMUX */
+static const char *wm8990_ainlmux[] =
+       {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
+
+static const struct soc_enum wm8990_ainlmux_enum =
+SOC_ENUM_SINGLE(WM8990_INPUT_MIXER1, WM8990_AINLMODE_SHIFT,
+       ARRAY_SIZE(wm8990_ainlmux), wm8990_ainlmux);
+
+static const struct snd_kcontrol_new wm8990_dapm_ainlmux_controls =
+SOC_DAPM_ENUM("Route", wm8990_ainlmux_enum);
+
+/* DIFFINL */
+
+/* AINRMUX */
+static const char *wm8990_ainrmux[] =
+       {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
+
+static const struct soc_enum wm8990_ainrmux_enum =
+SOC_ENUM_SINGLE(WM8990_INPUT_MIXER1, WM8990_AINRMODE_SHIFT,
+       ARRAY_SIZE(wm8990_ainrmux), wm8990_ainrmux);
+
+static const struct snd_kcontrol_new wm8990_dapm_ainrmux_controls =
+SOC_DAPM_ENUM("Route", wm8990_ainrmux_enum);
+
+/* RXVOICE */
+static const struct snd_kcontrol_new wm8990_dapm_rxvoice_controls[] = {
+SOC_DAPM_SINGLE_TLV("LIN4/RXN", WM8990_INPUT_MIXER5, WM8990_LR4BVOL_SHIFT,
+                       WM8990_LR4BVOL_MASK, 0, in_mix_tlv),
+SOC_DAPM_SINGLE_TLV("RIN4/RXP", WM8990_INPUT_MIXER6, WM8990_RL4BVOL_SHIFT,
+                       WM8990_RL4BVOL_MASK, 0, in_mix_tlv),
+};
+
+/* LOMIX */
+static const struct snd_kcontrol_new wm8990_dapm_lomix_controls[] = {
+SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LRBLO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LLBLO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LRI3LO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LLI3LO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LR12LO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LL12LO_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8990_OUTPUT_MIXER1,
+       WM8990_LDLO_BIT, 1, 0),
+};
+
+/* ROMIX */
+static const struct snd_kcontrol_new wm8990_dapm_romix_controls[] = {
+SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RLBRO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RRBRO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RLI3RO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RRI3RO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RL12RO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RR12RO_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8990_OUTPUT_MIXER2,
+       WM8990_RDRO_BIT, 1, 0),
+};
+
+/* LONMIX */
+static const struct snd_kcontrol_new wm8990_dapm_lonmix_controls[] = {
+SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8990_LINE_MIXER1,
+       WM8990_LLOPGALON_BIT, 1, 0),
+SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8990_LINE_MIXER1,
+       WM8990_LROPGALON_BIT, 1, 0),
+SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8990_LINE_MIXER1,
+       WM8990_LOPLON_BIT, 1, 0),
+};
+
+/* LOPMIX */
+static const struct snd_kcontrol_new wm8990_dapm_lopmix_controls[] = {
+SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8990_LINE_MIXER1,
+       WM8990_LR12LOP_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8990_LINE_MIXER1,
+       WM8990_LL12LOP_BIT, 1, 0),
+SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8990_LINE_MIXER1,
+       WM8990_LLOPGALOP_BIT, 1, 0),
+};
+
+/* RONMIX */
+static const struct snd_kcontrol_new wm8990_dapm_ronmix_controls[] = {
+SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8990_LINE_MIXER2,
+       WM8990_RROPGARON_BIT, 1, 0),
+SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8990_LINE_MIXER2,
+       WM8990_RLOPGARON_BIT, 1, 0),
+SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8990_LINE_MIXER2,
+       WM8990_ROPRON_BIT, 1, 0),
+};
+
+/* ROPMIX */
+static const struct snd_kcontrol_new wm8990_dapm_ropmix_controls[] = {
+SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8990_LINE_MIXER2,
+       WM8990_RL12ROP_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8990_LINE_MIXER2,
+       WM8990_RR12ROP_BIT, 1, 0),
+SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8990_LINE_MIXER2,
+       WM8990_RROPGAROP_BIT, 1, 0),
+};
+
+/* OUT3MIX */
+static const struct snd_kcontrol_new wm8990_dapm_out3mix_controls[] = {
+SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8990_OUT3_4_MIXER,
+       WM8990_LI4O3_BIT, 1, 0),
+SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8990_OUT3_4_MIXER,
+       WM8990_LPGAO3_BIT, 1, 0),
+};
+
+/* OUT4MIX */
+static const struct snd_kcontrol_new wm8990_dapm_out4mix_controls[] = {
+SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8990_OUT3_4_MIXER,
+       WM8990_RPGAO4_BIT, 1, 0),
+SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8990_OUT3_4_MIXER,
+       WM8990_RI4O4_BIT, 1, 0),
+};
+
+/* SPKMIX */
+static const struct snd_kcontrol_new wm8990_dapm_spkmix_controls[] = {
+SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8990_SPEAKER_MIXER,
+       WM8990_LI2SPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8990_SPEAKER_MIXER,
+       WM8990_LB2SPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8990_SPEAKER_MIXER,
+       WM8990_LOPGASPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8990_SPEAKER_MIXER,
+       WM8990_LDSPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8990_SPEAKER_MIXER,
+       WM8990_RDSPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8990_SPEAKER_MIXER,
+       WM8990_ROPGASPK_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8990_SPEAKER_MIXER,
+       WM8990_RL12ROP_BIT, 1, 0),
+SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8990_SPEAKER_MIXER,
+       WM8990_RI2SPK_BIT, 1, 0),
+};
+
+static const struct snd_soc_dapm_widget wm8990_dapm_widgets[] = {
+/* Input Side */
+/* Input Lines */
+SND_SOC_DAPM_INPUT("LIN1"),
+SND_SOC_DAPM_INPUT("LIN2"),
+SND_SOC_DAPM_INPUT("LIN3"),
+SND_SOC_DAPM_INPUT("LIN4/RXN"),
+SND_SOC_DAPM_INPUT("RIN3"),
+SND_SOC_DAPM_INPUT("RIN4/RXP"),
+SND_SOC_DAPM_INPUT("RIN1"),
+SND_SOC_DAPM_INPUT("RIN2"),
+SND_SOC_DAPM_INPUT("Internal ADC Source"),
+
+/* DACs */
+SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8990_POWER_MANAGEMENT_2,
+       WM8990_ADCL_ENA_BIT, 0),
+SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8990_POWER_MANAGEMENT_2,
+       WM8990_ADCR_ENA_BIT, 0),
+
+/* Input PGAs */
+SND_SOC_DAPM_MIXER("LIN12 PGA", WM8990_POWER_MANAGEMENT_2, WM8990_LIN12_ENA_BIT,
+       0, &wm8990_dapm_lin12_pga_controls[0],
+       ARRAY_SIZE(wm8990_dapm_lin12_pga_controls)),
+SND_SOC_DAPM_MIXER("LIN34 PGA", WM8990_POWER_MANAGEMENT_2, WM8990_LIN34_ENA_BIT,
+       0, &wm8990_dapm_lin34_pga_controls[0],
+       ARRAY_SIZE(wm8990_dapm_lin34_pga_controls)),
+SND_SOC_DAPM_MIXER("RIN12 PGA", WM8990_POWER_MANAGEMENT_2, WM8990_RIN12_ENA_BIT,
+       0, &wm8990_dapm_rin12_pga_controls[0],
+       ARRAY_SIZE(wm8990_dapm_rin12_pga_controls)),
+SND_SOC_DAPM_MIXER("RIN34 PGA", WM8990_POWER_MANAGEMENT_2, WM8990_RIN34_ENA_BIT,
+       0, &wm8990_dapm_rin34_pga_controls[0],
+       ARRAY_SIZE(wm8990_dapm_rin34_pga_controls)),
+
+/* INMIXL */
+SND_SOC_DAPM_MIXER_E("INMIXL", WM8990_INTDRIVBITS, WM8990_INMIXL_PWR_BIT, 0,
+       &wm8990_dapm_inmixl_controls[0],
+       ARRAY_SIZE(wm8990_dapm_inmixl_controls),
+       inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+/* AINLMUX */
+SND_SOC_DAPM_MUX_E("AILNMUX", WM8990_INTDRIVBITS, WM8990_AINLMUX_PWR_BIT, 0,
+       &wm8990_dapm_ainlmux_controls, inmixer_event,
+       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+/* INMIXR */
+SND_SOC_DAPM_MIXER_E("INMIXR", WM8990_INTDRIVBITS, WM8990_INMIXR_PWR_BIT, 0,
+       &wm8990_dapm_inmixr_controls[0],
+       ARRAY_SIZE(wm8990_dapm_inmixr_controls),
+       inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+/* AINRMUX */
+SND_SOC_DAPM_MUX_E("AIRNMUX", WM8990_INTDRIVBITS, WM8990_AINRMUX_PWR_BIT, 0,
+       &wm8990_dapm_ainrmux_controls, inmixer_event,
+       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+/* Output Side */
+/* DACs */
+SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8990_POWER_MANAGEMENT_3,
+       WM8990_DACL_ENA_BIT, 0),
+SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8990_POWER_MANAGEMENT_3,
+       WM8990_DACR_ENA_BIT, 0),
+
+/* LOMIX */
+SND_SOC_DAPM_MIXER_E("LOMIX", WM8990_POWER_MANAGEMENT_3, WM8990_LOMIX_ENA_BIT,
+       0, &wm8990_dapm_lomix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_lomix_controls),
+       outmixer_event, SND_SOC_DAPM_PRE_REG),
+
+/* LONMIX */
+SND_SOC_DAPM_MIXER("LONMIX", WM8990_POWER_MANAGEMENT_3, WM8990_LON_ENA_BIT, 0,
+       &wm8990_dapm_lonmix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_lonmix_controls)),
+
+/* LOPMIX */
+SND_SOC_DAPM_MIXER("LOPMIX", WM8990_POWER_MANAGEMENT_3, WM8990_LOP_ENA_BIT, 0,
+       &wm8990_dapm_lopmix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_lopmix_controls)),
+
+/* OUT3MIX */
+SND_SOC_DAPM_MIXER("OUT3MIX", WM8990_POWER_MANAGEMENT_1, WM8990_OUT3_ENA_BIT, 0,
+       &wm8990_dapm_out3mix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_out3mix_controls)),
+
+/* SPKMIX */
+SND_SOC_DAPM_MIXER_E("SPKMIX", WM8990_POWER_MANAGEMENT_1, WM8990_SPK_ENA_BIT, 0,
+       &wm8990_dapm_spkmix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_spkmix_controls), outmixer_event,
+       SND_SOC_DAPM_PRE_REG),
+
+/* OUT4MIX */
+SND_SOC_DAPM_MIXER("OUT4MIX", WM8990_POWER_MANAGEMENT_1, WM8990_OUT4_ENA_BIT, 0,
+       &wm8990_dapm_out4mix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_out4mix_controls)),
+
+/* ROPMIX */
+SND_SOC_DAPM_MIXER("ROPMIX", WM8990_POWER_MANAGEMENT_3, WM8990_ROP_ENA_BIT, 0,
+       &wm8990_dapm_ropmix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_ropmix_controls)),
+
+/* RONMIX */
+SND_SOC_DAPM_MIXER("RONMIX", WM8990_POWER_MANAGEMENT_3, WM8990_RON_ENA_BIT, 0,
+       &wm8990_dapm_ronmix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_ronmix_controls)),
+
+/* ROMIX */
+SND_SOC_DAPM_MIXER_E("ROMIX", WM8990_POWER_MANAGEMENT_3, WM8990_ROMIX_ENA_BIT,
+       0, &wm8990_dapm_romix_controls[0],
+       ARRAY_SIZE(wm8990_dapm_romix_controls),
+       outmixer_event, SND_SOC_DAPM_PRE_REG),
+
+/* LOUT PGA */
+SND_SOC_DAPM_PGA("LOUT PGA", WM8990_POWER_MANAGEMENT_1, WM8990_LOUT_ENA_BIT, 0,
+       NULL, 0),
+
+/* ROUT PGA */
+SND_SOC_DAPM_PGA("ROUT PGA", WM8990_POWER_MANAGEMENT_1, WM8990_ROUT_ENA_BIT, 0,
+       NULL, 0),
+
+/* LOPGA */
+SND_SOC_DAPM_PGA("LOPGA", WM8990_POWER_MANAGEMENT_3, WM8990_LOPGA_ENA_BIT, 0,
+       NULL, 0),
+
+/* ROPGA */
+SND_SOC_DAPM_PGA("ROPGA", WM8990_POWER_MANAGEMENT_3, WM8990_ROPGA_ENA_BIT, 0,
+       NULL, 0),
+
+/* MICBIAS */
+SND_SOC_DAPM_MICBIAS("MICBIAS", WM8990_POWER_MANAGEMENT_1,
+       WM8990_MICBIAS_ENA_BIT, 0),
+
+SND_SOC_DAPM_OUTPUT("LON"),
+SND_SOC_DAPM_OUTPUT("LOP"),
+SND_SOC_DAPM_OUTPUT("OUT3"),
+SND_SOC_DAPM_OUTPUT("LOUT"),
+SND_SOC_DAPM_OUTPUT("SPKN"),
+SND_SOC_DAPM_OUTPUT("SPKP"),
+SND_SOC_DAPM_OUTPUT("ROUT"),
+SND_SOC_DAPM_OUTPUT("OUT4"),
+SND_SOC_DAPM_OUTPUT("ROP"),
+SND_SOC_DAPM_OUTPUT("RON"),
+
+SND_SOC_DAPM_OUTPUT("Internal DAC Sink"),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       /* Make DACs turn on when playing even if not mixed into any outputs */
+       {"Internal DAC Sink", NULL, "Left DAC"},
+       {"Internal DAC Sink", NULL, "Right DAC"},
+
+       /* Make ADCs turn on when recording even if not mixed from any inputs */
+       {"Left ADC", NULL, "Internal ADC Source"},
+       {"Right ADC", NULL, "Internal ADC Source"},
+
+       /* Input Side */
+       /* LIN12 PGA */
+       {"LIN12 PGA", "LIN1 Switch", "LIN1"},
+       {"LIN12 PGA", "LIN2 Switch", "LIN2"},
+       /* LIN34 PGA */
+       {"LIN34 PGA", "LIN3 Switch", "LIN3"},
+       {"LIN34 PGA", "LIN4 Switch", "LIN4"},
+       /* INMIXL */
+       {"INMIXL", "Record Left Volume", "LOMIX"},
+       {"INMIXL", "LIN2 Volume", "LIN2"},
+       {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
+       {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
+       /* AILNMUX */
+       {"AILNMUX", "INMIXL Mix", "INMIXL"},
+       {"AILNMUX", "DIFFINL Mix", "LIN12PGA"},
+       {"AILNMUX", "DIFFINL Mix", "LIN34PGA"},
+       {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"},
+       {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"},
+       /* ADC */
+       {"Left ADC", NULL, "AILNMUX"},
+
+       /* RIN12 PGA */
+       {"RIN12 PGA", "RIN1 Switch", "RIN1"},
+       {"RIN12 PGA", "RIN2 Switch", "RIN2"},
+       /* RIN34 PGA */
+       {"RIN34 PGA", "RIN3 Switch", "RIN3"},
+       {"RIN34 PGA", "RIN4 Switch", "RIN4"},
+       /* INMIXL */
+       {"INMIXR", "Record Right Volume", "ROMIX"},
+       {"INMIXR", "RIN2 Volume", "RIN2"},
+       {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
+       {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
+       /* AIRNMUX */
+       {"AIRNMUX", "INMIXR Mix", "INMIXR"},
+       {"AIRNMUX", "DIFFINR Mix", "RIN12PGA"},
+       {"AIRNMUX", "DIFFINR Mix", "RIN34PGA"},
+       {"AIRNMUX", "RXVOICE Mix", "RIN4/RXN"},
+       {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"},
+       /* ADC */
+       {"Right ADC", NULL, "AIRNMUX"},
+
+       /* LOMIX */
+       {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
+       {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"},
+       {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
+       {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
+       {"LOMIX", "LOMIX Right ADC Bypass Switch", "AINRMUX"},
+       {"LOMIX", "LOMIX Left ADC Bypass Switch", "AINLMUX"},
+       {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"},
+
+       /* ROMIX */
+       {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"},
+       {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"},
+       {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
+       {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
+       {"ROMIX", "ROMIX Right ADC Bypass Switch", "AINRMUX"},
+       {"ROMIX", "ROMIX Left ADC Bypass Switch", "AINLMUX"},
+       {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"},
+
+       /* SPKMIX */
+       {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"},
+       {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"},
+       {"SPKMIX", "SPKMIX LADC Bypass Switch", "AINLMUX"},
+       {"SPKMIX", "SPKMIX RADC Bypass Switch", "AINRMUX"},
+       {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"},
+       {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"},
+       {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"},
+       {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"},
+
+       /* LONMIX */
+       {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"},
+       {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"},
+       {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"},
+
+       /* LOPMIX */
+       {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"},
+       {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"},
+       {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
+
+       /* OUT3MIX */
+       {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXP"},
+       {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
+
+       /* OUT4MIX */
+       {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"},
+       {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"},
+
+       /* RONMIX */
+       {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"},
+       {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"},
+       {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"},
+
+       /* ROPMIX */
+       {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"},
+       {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"},
+       {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"},
+
+       /* Out Mixer PGAs */
+       {"LOPGA", NULL, "LOMIX"},
+       {"ROPGA", NULL, "ROMIX"},
+
+       {"LOUT PGA", NULL, "LOMIX"},
+       {"ROUT PGA", NULL, "ROMIX"},
+
+       /* Output Pins */
+       {"LON", NULL, "LONMIX"},
+       {"LOP", NULL, "LOPMIX"},
+       {"OUT", NULL, "OUT3MIX"},
+       {"LOUT", NULL, "LOUT PGA"},
+       {"SPKN", NULL, "SPKMIX"},
+       {"ROUT", NULL, "ROUT PGA"},
+       {"OUT4", NULL, "OUT4MIX"},
+       {"ROP", NULL, "ROPMIX"},
+       {"RON", NULL, "RONMIX"},
+};
+
+static int wm8990_add_widgets(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_new_controls(codec, wm8990_dapm_widgets,
+                                 ARRAY_SIZE(wm8990_dapm_widgets));
+
+       /* set up the WM8990 audio map */
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_dapm_new_widgets(codec);
+       return 0;
+}
+
+/* PLL divisors */
+struct _pll_div {
+       u32 div2;
+       u32 n;
+       u32 k;
+};
+
+/* The size in bits of the pll divide multiplied by 10
+ * to allow rounding later */
+#define FIXED_PLL_SIZE ((1 << 16) * 10)
+
+static void pll_factors(struct _pll_div *pll_div, unsigned int target,
+       unsigned int source)
+{
+       u64 Kpart;
+       unsigned int K, Ndiv, Nmod;
+
+
+       Ndiv = target / source;
+       if (Ndiv < 6) {
+               source >>= 1;
+               pll_div->div2 = 1;
+               Ndiv = target / source;
+       } else
+               pll_div->div2 = 0;
+
+       if ((Ndiv < 6) || (Ndiv > 12))
+               printk(KERN_WARNING
+               "WM8990 N value outwith recommended range! N = %d\n", Ndiv);
+
+       pll_div->n = Ndiv;
+       Nmod = target % source;
+       Kpart = FIXED_PLL_SIZE * (long long)Nmod;
+
+       do_div(Kpart, source);
+
+       K = Kpart & 0xFFFFFFFF;
+
+       /* Check if we need to round */
+       if ((K % 10) >= 5)
+               K += 5;
+
+       /* Move down to proper range now rounding is done */
+       K /= 10;
+
+       pll_div->k = K;
+}
+
+static int wm8990_set_dai_pll(struct snd_soc_dai *codec_dai,
+               int pll_id, unsigned int freq_in, unsigned int freq_out)
+{
+       u16 reg;
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct _pll_div pll_div;
+
+       if (freq_in && freq_out) {
+               pll_factors(&pll_div, freq_out * 4, freq_in);
+
+               /* Turn on PLL */
+               reg = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_2);
+               reg |= WM8990_PLL_ENA;
+               wm8990_write(codec, WM8990_POWER_MANAGEMENT_2, reg);
+
+               /* sysclk comes from PLL */
+               reg = wm8990_read_reg_cache(codec, WM8990_CLOCKING_2);
+               wm8990_write(codec, WM8990_CLOCKING_2, reg | WM8990_SYSCLK_SRC);
+
+               /* set up N , fractional mode and pre-divisor if neccessary */
+               wm8990_write(codec, WM8990_PLL1, pll_div.n | WM8990_SDM |
+                       (pll_div.div2?WM8990_PRESCALE:0));
+               wm8990_write(codec, WM8990_PLL2, (u8)(pll_div.k>>8));
+               wm8990_write(codec, WM8990_PLL3, (u8)(pll_div.k & 0xFF));
+       } else {
+               /* Turn on PLL */
+               reg = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_2);
+               reg &= ~WM8990_PLL_ENA;
+               wm8990_write(codec, WM8990_POWER_MANAGEMENT_2, reg);
+       }
+       return 0;
+}
+
+/*
+ * Clock after PLL and dividers
+ */
+static int wm8990_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+               int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct wm8990_priv *wm8990 = codec->private_data;
+
+       wm8990->sysclk = freq;
+       return 0;
+}
+
+/*
+ * Set's ADC and Voice DAC format.
+ */
+static int wm8990_set_dai_fmt(struct snd_soc_dai *codec_dai,
+               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 audio1, audio3;
+
+       audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1);
+       audio3 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_3);
+
+       /* set master/slave audio interface */
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBS_CFS:
+               audio3 &= ~WM8990_AIF_MSTR1;
+               break;
+       case SND_SOC_DAIFMT_CBM_CFM:
+               audio3 |= WM8990_AIF_MSTR1;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       audio1 &= ~WM8990_AIF_FMT_MASK;
+
+       /* interface format */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               audio1 |= WM8990_AIF_TMF_I2S;
+               audio1 &= ~WM8990_AIF_LRCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_RIGHT_J:
+               audio1 |= WM8990_AIF_TMF_RIGHTJ;
+               audio1 &= ~WM8990_AIF_LRCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               audio1 |= WM8990_AIF_TMF_LEFTJ;
+               audio1 &= ~WM8990_AIF_LRCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_DSP_A:
+               audio1 |= WM8990_AIF_TMF_DSP;
+               audio1 &= ~WM8990_AIF_LRCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_DSP_B:
+               audio1 |= WM8990_AIF_TMF_DSP | WM8990_AIF_LRCLK_INV;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       wm8990_write(codec, WM8990_AUDIO_INTERFACE_1, audio1);
+       wm8990_write(codec, WM8990_AUDIO_INTERFACE_3, audio3);
+       return 0;
+}
+
+static int wm8990_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
+               int div_id, int div)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       u16 reg;
+
+       switch (div_id) {
+       case WM8990_MCLK_DIV:
+               reg = wm8990_read_reg_cache(codec, WM8990_CLOCKING_2) &
+                       ~WM8990_MCLK_DIV_MASK;
+               wm8990_write(codec, WM8990_CLOCKING_2, reg | div);
+               break;
+       case WM8990_DACCLK_DIV:
+               reg = wm8990_read_reg_cache(codec, WM8990_CLOCKING_2) &
+                       ~WM8990_DAC_CLKDIV_MASK;
+               wm8990_write(codec, WM8990_CLOCKING_2, reg | div);
+               break;
+       case WM8990_ADCCLK_DIV:
+               reg = wm8990_read_reg_cache(codec, WM8990_CLOCKING_2) &
+                       ~WM8990_ADC_CLKDIV_MASK;
+               wm8990_write(codec, WM8990_CLOCKING_2, reg | div);
+               break;
+       case WM8990_BCLK_DIV:
+               reg = wm8990_read_reg_cache(codec, WM8990_CLOCKING_1) &
+                       ~WM8990_BCLK_DIV_MASK;
+               wm8990_write(codec, WM8990_CLOCKING_1, reg | div);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/*
+ * Set PCM DAI bit size and sample rate.
+ */
+static int wm8990_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->codec;
+       u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1);
+
+       audio1 &= ~WM8990_AIF_WL_MASK;
+       /* bit size */
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               audio1 |= WM8990_AIF_WL_20BITS;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               audio1 |= WM8990_AIF_WL_24BITS;
+               break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               audio1 |= WM8990_AIF_WL_32BITS;
+               break;
+       }
+
+       wm8990_write(codec, WM8990_AUDIO_INTERFACE_1, audio1);
+       return 0;
+}
+
+static int wm8990_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u16 val;
+
+       val  = wm8990_read_reg_cache(codec, WM8990_DAC_CTRL) & ~WM8990_DAC_MUTE;
+
+       if (mute)
+               wm8990_write(codec, WM8990_DAC_CTRL, val | WM8990_DAC_MUTE);
+       else
+               wm8990_write(codec, WM8990_DAC_CTRL, val);
+
+       return 0;
+}
+
+static int wm8990_set_bias_level(struct snd_soc_codec *codec,
+       enum snd_soc_bias_level level)
+{
+       u16 val;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               if (codec->bias_level == SND_SOC_BIAS_OFF) {
+                       /* Enable all output discharge bits */
+                       wm8990_write(codec, WM8990_ANTIPOP1, WM8990_DIS_LLINE |
+                               WM8990_DIS_RLINE | WM8990_DIS_OUT3 |
+                               WM8990_DIS_OUT4 | WM8990_DIS_LOUT |
+                               WM8990_DIS_ROUT);
+
+                       /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
+                       wm8990_write(codec, WM8990_ANTIPOP2, WM8990_SOFTST |
+                                    WM8990_BUFDCOPEN | WM8990_POBCTRL |
+                                    WM8990_VMIDTOG);
+
+                       /* Delay to allow output caps to discharge */
+                       msleep(msecs_to_jiffies(300));
+
+                       /* Disable VMIDTOG */
+                       wm8990_write(codec, WM8990_ANTIPOP2, WM8990_SOFTST |
+                                    WM8990_BUFDCOPEN | WM8990_POBCTRL);
+
+                       /* disable all output discharge bits */
+                       wm8990_write(codec, WM8990_ANTIPOP1, 0);
+
+                       /* Enable outputs */
+                       wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1b00);
+
+                       msleep(msecs_to_jiffies(50));
+
+                       /* Enable VMID at 2x50k */
+                       wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1f02);
+
+                       msleep(msecs_to_jiffies(100));
+
+                       /* Enable VREF */
+                       wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1f03);
+
+                       msleep(msecs_to_jiffies(600));
+
+                       /* Enable BUFIOEN */
+                       wm8990_write(codec, WM8990_ANTIPOP2, WM8990_SOFTST |
+                                    WM8990_BUFDCOPEN | WM8990_POBCTRL |
+                                    WM8990_BUFIOEN);
+
+                       /* Disable outputs */
+                       wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x3);
+
+                       /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
+                       wm8990_write(codec, WM8990_ANTIPOP2, WM8990_BUFIOEN);
+               } else {
+                       /* ON -> standby */
+
+               }
+               break;
+
+       case SND_SOC_BIAS_OFF:
+               /* Enable POBCTRL and SOFT_ST */
+               wm8990_write(codec, WM8990_ANTIPOP2, WM8990_SOFTST |
+                       WM8990_POBCTRL | WM8990_BUFIOEN);
+
+               /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
+               wm8990_write(codec, WM8990_ANTIPOP2, WM8990_SOFTST |
+                       WM8990_BUFDCOPEN | WM8990_POBCTRL |
+                       WM8990_BUFIOEN);
+
+               /* mute DAC */
+               val = wm8990_read_reg_cache(codec, WM8990_DAC_CTRL);
+               wm8990_write(codec, WM8990_DAC_CTRL, val | WM8990_DAC_MUTE);
+
+               /* Enable any disabled outputs */
+               wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1f03);
+
+               /* Disable VMID */
+               wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x1f01);
+
+               msleep(msecs_to_jiffies(300));
+
+               /* Enable all output discharge bits */
+               wm8990_write(codec, WM8990_ANTIPOP1, WM8990_DIS_LLINE |
+                       WM8990_DIS_RLINE | WM8990_DIS_OUT3 |
+                       WM8990_DIS_OUT4 | WM8990_DIS_LOUT |
+                       WM8990_DIS_ROUT);
+
+               /* Disable VREF */
+               wm8990_write(codec, WM8990_POWER_MANAGEMENT_1, 0x0);
+
+               /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
+               wm8990_write(codec, WM8990_ANTIPOP2, 0x0);
+               break;
+       }
+
+       codec->bias_level = level;
+       return 0;
+}
+
+#define WM8990_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
+       SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
+       SNDRV_PCM_RATE_48000)
+
+#define WM8990_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
+       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+
+/*
+ * The WM8990 supports 2 different and mutually exclusive DAI
+ * configurations.
+ *
+ * 1. ADC/DAC on Primary Interface
+ * 2. ADC on Primary Interface/DAC on secondary
+ */
+struct snd_soc_dai wm8990_dai = {
+/* ADC/DAC on primary */
+       .name = "WM8990 ADC/DAC Primary",
+       .id = 1,
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = WM8990_RATES,
+               .formats = WM8990_FORMATS,},
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = WM8990_RATES,
+               .formats = WM8990_FORMATS,},
+       .ops = {
+               .hw_params = wm8990_hw_params,},
+       .dai_ops = {
+               .digital_mute = wm8990_mute,
+               .set_fmt = wm8990_set_dai_fmt,
+               .set_clkdiv = wm8990_set_dai_clkdiv,
+               .set_pll = wm8990_set_dai_pll,
+               .set_sysclk = wm8990_set_dai_sysclk,
+       },
+};
+EXPORT_SYMBOL_GPL(wm8990_dai);
+
+static int wm8990_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       /* we only need to suspend if we are a valid card */
+       if (!codec->card)
+               return 0;
+
+       wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
+}
+
+static int wm8990_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+       int i;
+       u8 data[2];
+       u16 *cache = codec->reg_cache;
+
+       /* we only need to resume if we are a valid card */
+       if (!codec->card)
+               return 0;
+
+       /* Sync reg_cache with the hardware */
+       for (i = 0; i < ARRAY_SIZE(wm8990_reg); i++) {
+               if (i + 1 == WM8990_RESET)
+                       continue;
+               data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001);
+               data[1] = cache[i] & 0x00ff;
+               codec->hw_write(codec->control_data, data, 2);
+       }
+
+       wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       return 0;
+}
+
+/*
+ * initialise the WM8990 driver
+ * register the mixer and dsp interfaces with the kernel
+ */
+static int wm8990_init(struct snd_soc_device *socdev)
+{
+       struct snd_soc_codec *codec = socdev->codec;
+       u16 reg;
+       int ret = 0;
+
+       codec->name = "WM8990";
+       codec->owner = THIS_MODULE;
+       codec->read = wm8990_read_reg_cache;
+       codec->write = wm8990_write;
+       codec->set_bias_level = wm8990_set_bias_level;
+       codec->dai = &wm8990_dai;
+       codec->num_dai = 2;
+       codec->reg_cache_size = ARRAY_SIZE(wm8990_reg);
+       codec->reg_cache = kmemdup(wm8990_reg, sizeof(wm8990_reg), GFP_KERNEL);
+
+       if (codec->reg_cache == NULL)
+               return -ENOMEM;
+
+       wm8990_reset(codec);
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8990: failed to create pcms\n");
+               goto pcm_err;
+       }
+
+       /* charge output caps */
+       codec->bias_level = SND_SOC_BIAS_OFF;
+       wm8990_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       reg = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_4);
+       wm8990_write(codec, WM8990_AUDIO_INTERFACE_4, reg | WM8990_ALRCGPIO1);
+
+       reg = wm8990_read_reg_cache(codec, WM8990_GPIO1_GPIO2) &
+               ~WM8990_GPIO1_SEL_MASK;
+       wm8990_write(codec, WM8990_GPIO1_GPIO2, reg | 1);
+
+       reg = wm8990_read_reg_cache(codec, WM8990_POWER_MANAGEMENT_2);
+       wm8990_write(codec, WM8990_POWER_MANAGEMENT_2, reg | WM8990_OPCLK_ENA);
+
+       wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
+       wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
+
+       wm8990_add_controls(codec);
+       wm8990_add_widgets(codec);
+       ret = snd_soc_register_card(socdev);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8990: failed to register card\n");
+               goto card_err;
+       }
+       return ret;
+
+card_err:
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+pcm_err:
+       kfree(codec->reg_cache);
+       return ret;
+}
+
+/* If the i2c layer weren't so broken, we could pass this kind of data
+   around */
+static struct snd_soc_device *wm8990_socdev;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+
+/*
+ * WM891 2 wire address is determined by GPIO5
+ * state during powerup.
+ *    low  = 0x34
+ *    high = 0x36
+ */
+static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END };
+
+/* Magic definition of all other variables and things */
+I2C_CLIENT_INSMOD;
+
+static struct i2c_driver wm8990_i2c_driver;
+static struct i2c_client client_template;
+
+static int wm8990_codec_probe(struct i2c_adapter *adap, int addr, int kind)
+{
+       struct snd_soc_device *socdev = wm8990_socdev;
+       struct wm8990_setup_data *setup = socdev->codec_data;
+       struct snd_soc_codec *codec = socdev->codec;
+       struct i2c_client *i2c;
+       int ret;
+
+       if (addr != setup->i2c_address)
+               return -ENODEV;
+
+       client_template.adapter = adap;
+       client_template.addr = addr;
+
+       i2c =  kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
+       if (i2c == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(i2c, codec);
+       codec->control_data = i2c;
+
+       ret = i2c_attach_client(i2c);
+       if (ret < 0) {
+               pr_err("failed to attach codec at addr %x\n", addr);
+               goto err;
+       }
+
+       ret = wm8990_init(socdev);
+       if (ret < 0) {
+               pr_err("failed to initialise WM8990\n");
+               goto err;
+       }
+       return ret;
+
+err:
+       kfree(codec);
+       kfree(i2c);
+       return ret;
+}
+
+static int wm8990_i2c_detach(struct i2c_client *client)
+{
+       struct snd_soc_codec *codec = i2c_get_clientdata(client);
+       i2c_detach_client(client);
+       kfree(codec->reg_cache);
+       kfree(client);
+       return 0;
+}
+
+static int wm8990_i2c_attach(struct i2c_adapter *adap)
+{
+       return i2c_probe(adap, &addr_data, wm8990_codec_probe);
+}
+
+static struct i2c_driver wm8990_i2c_driver = {
+       .driver = {
+               .name = "WM8990 I2C Codec",
+               .owner = THIS_MODULE,
+       },
+       .attach_adapter = wm8990_i2c_attach,
+       .detach_client =  wm8990_i2c_detach,
+       .command =        NULL,
+};
+
+static struct i2c_client client_template = {
+       .name =   "WM8990",
+       .driver = &wm8990_i2c_driver,
+};
+#endif
+
+static int wm8990_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct wm8990_setup_data *setup;
+       struct snd_soc_codec *codec;
+       struct wm8990_priv *wm8990;
+       int ret = 0;
+
+       pr_info("WM8990 Audio Codec %s\n", WM8990_VERSION);
+
+       setup = socdev->codec_data;
+       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+       if (codec == NULL)
+               return -ENOMEM;
+
+       wm8990 = kzalloc(sizeof(struct wm8990_priv), GFP_KERNEL);
+       if (wm8990 == NULL) {
+               kfree(codec);
+               return -ENOMEM;
+       }
+
+       codec->private_data = wm8990;
+       socdev->codec = codec;
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+       wm8990_socdev = socdev;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       if (setup->i2c_address) {
+               normal_i2c[0] = setup->i2c_address;
+               codec->hw_write = (hw_write_t)i2c_master_send;
+               ret = i2c_add_driver(&wm8990_i2c_driver);
+               if (ret != 0)
+                       printk(KERN_ERR "can't add i2c driver");
+       }
+#else
+               /* Add other interfaces here */
+#endif
+       return ret;
+}
+
+/* power down chip */
+static int wm8990_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->codec;
+
+       if (codec->control_data)
+               wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&wm8990_i2c_driver);
+#endif
+       kfree(codec->private_data);
+       kfree(codec);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm8990 = {
+       .probe =        wm8990_probe,
+       .remove =       wm8990_remove,
+       .suspend =      wm8990_suspend,
+       .resume =       wm8990_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8990);
+
+MODULE_DESCRIPTION("ASoC WM8990 driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm8990.h b/sound/soc/codecs/wm8990.h
new file mode 100644 (file)
index 0000000..6bea574
--- /dev/null
@@ -0,0 +1,832 @@
+/*
+ * wm8990.h  --  audio driver for WM8990
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC.
+ * Author: Graeme Gregory
+ *         graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __WM8990REGISTERDEFS_H__
+#define __WM8990REGISTERDEFS_H__
+
+/*
+ * Register values.
+ */
+#define WM8990_RESET                            0x00
+#define WM8990_POWER_MANAGEMENT_1               0x01
+#define WM8990_POWER_MANAGEMENT_2               0x02
+#define WM8990_POWER_MANAGEMENT_3               0x03
+#define WM8990_AUDIO_INTERFACE_1                0x04
+#define WM8990_AUDIO_INTERFACE_2                0x05
+#define WM8990_CLOCKING_1                       0x06
+#define WM8990_CLOCKING_2                       0x07
+#define WM8990_AUDIO_INTERFACE_3                0x08
+#define WM8990_AUDIO_INTERFACE_4                0x09
+#define WM8990_DAC_CTRL                         0x0A
+#define WM8990_LEFT_DAC_DIGITAL_VOLUME          0x0B
+#define WM8990_RIGHT_DAC_DIGITAL_VOLUME         0x0C
+#define WM8990_DIGITAL_SIDE_TONE                0x0D
+#define WM8990_ADC_CTRL                         0x0E
+#define WM8990_LEFT_ADC_DIGITAL_VOLUME          0x0F
+#define WM8990_RIGHT_ADC_DIGITAL_VOLUME         0x10
+#define WM8990_GPIO_CTRL_1                      0x12
+#define WM8990_GPIO1_GPIO2                      0x13
+#define WM8990_GPIO3_GPIO4                      0x14
+#define WM8990_GPIO5_GPIO6                      0x15
+#define WM8990_GPIOCTRL_2                       0x16
+#define WM8990_GPIO_POL                         0x17
+#define WM8990_LEFT_LINE_INPUT_1_2_VOLUME       0x18
+#define WM8990_LEFT_LINE_INPUT_3_4_VOLUME       0x19
+#define WM8990_RIGHT_LINE_INPUT_1_2_VOLUME      0x1A
+#define WM8990_RIGHT_LINE_INPUT_3_4_VOLUME      0x1B
+#define WM8990_LEFT_OUTPUT_VOLUME               0x1C
+#define WM8990_RIGHT_OUTPUT_VOLUME              0x1D
+#define WM8990_LINE_OUTPUTS_VOLUME              0x1E
+#define WM8990_OUT3_4_VOLUME                    0x1F
+#define WM8990_LEFT_OPGA_VOLUME                 0x20
+#define WM8990_RIGHT_OPGA_VOLUME                0x21
+#define WM8990_SPEAKER_VOLUME                   0x22
+#define WM8990_CLASSD1                          0x23
+#define WM8990_CLASSD3                          0x25
+#define WM8990_INPUT_MIXER1                     0x27
+#define WM8990_INPUT_MIXER2                     0x28
+#define WM8990_INPUT_MIXER3                     0x29
+#define WM8990_INPUT_MIXER4                     0x2A
+#define WM8990_INPUT_MIXER5                     0x2B
+#define WM8990_INPUT_MIXER6                     0x2C
+#define WM8990_OUTPUT_MIXER1                    0x2D
+#define WM8990_OUTPUT_MIXER2                    0x2E
+#define WM8990_OUTPUT_MIXER3                    0x2F
+#define WM8990_OUTPUT_MIXER4                    0x30
+#define WM8990_OUTPUT_MIXER5                    0x31
+#define WM8990_OUTPUT_MIXER6                    0x32
+#define WM8990_OUT3_4_MIXER                     0x33
+#define WM8990_LINE_MIXER1                      0x34
+#define WM8990_LINE_MIXER2                      0x35
+#define WM8990_SPEAKER_MIXER                    0x36
+#define WM8990_ADDITIONAL_CONTROL               0x37
+#define WM8990_ANTIPOP1                         0x38
+#define WM8990_ANTIPOP2                         0x39
+#define WM8990_MICBIAS                          0x3A
+#define WM8990_PLL1                             0x3C
+#define WM8990_PLL2                             0x3D
+#define WM8990_PLL3                             0x3E
+#define WM8990_INTDRIVBITS                     0x3F
+
+#define WM8990_REGISTER_COUNT                   60
+#define WM8990_MAX_REGISTER                     0x3F
+
+/*
+ * Field Definitions.
+ */
+
+/*
+ * R0 (0x00) - Reset
+ */
+#define WM8990_SW_RESET_CHIP_ID_MASK            0xFFFF  /* SW_RESET_CHIP_ID */
+
+/*
+ * R1 (0x01) - Power Management (1)
+ */
+#define WM8990_SPK_ENA                          0x1000  /* SPK_ENA */
+#define WM8990_SPK_ENA_BIT                     12
+#define WM8990_OUT3_ENA                         0x0800  /* OUT3_ENA */
+#define WM8990_OUT3_ENA_BIT                    11
+#define WM8990_OUT4_ENA                         0x0400  /* OUT4_ENA */
+#define WM8990_OUT4_ENA_BIT                    10
+#define WM8990_LOUT_ENA                         0x0200  /* LOUT_ENA */
+#define WM8990_LOUT_ENA_BIT                    9
+#define WM8990_ROUT_ENA                         0x0100  /* ROUT_ENA */
+#define WM8990_ROUT_ENA_BIT                    8
+#define WM8990_MICBIAS_ENA                      0x0010  /* MICBIAS_ENA */
+#define WM8990_MICBIAS_ENA_BIT                 4
+#define WM8990_VMID_MODE_MASK                   0x0006  /* VMID_MODE - [2:1] */
+#define WM8990_VREF_ENA                         0x0001  /* VREF_ENA */
+#define WM8990_VREF_ENA_BIT                    0
+
+/*
+ * R2 (0x02) - Power Management (2)
+ */
+#define WM8990_PLL_ENA                          0x8000  /* PLL_ENA */
+#define WM8990_PLL_ENA_BIT                     15
+#define WM8990_TSHUT_ENA                        0x4000  /* TSHUT_ENA */
+#define WM8990_TSHUT_ENA_BIT                   14
+#define WM8990_TSHUT_OPDIS                      0x2000  /* TSHUT_OPDIS */
+#define WM8990_TSHUT_OPDIS_BIT                 13
+#define WM8990_OPCLK_ENA                        0x0800  /* OPCLK_ENA */
+#define WM8990_OPCLK_ENA_BIT                   11
+#define WM8990_AINL_ENA                         0x0200  /* AINL_ENA */
+#define WM8990_AINL_ENA_BIT                    9
+#define WM8990_AINR_ENA                         0x0100  /* AINR_ENA */
+#define WM8990_AINR_ENA_BIT                    8
+#define WM8990_LIN34_ENA                        0x0080  /* LIN34_ENA */
+#define WM8990_LIN34_ENA_BIT                   7
+#define WM8990_LIN12_ENA                        0x0040  /* LIN12_ENA */
+#define WM8990_LIN12_ENA_BIT                   6
+#define WM8990_RIN34_ENA                        0x0020  /* RIN34_ENA */
+#define WM8990_RIN34_ENA_BIT                   5
+#define WM8990_RIN12_ENA                        0x0010  /* RIN12_ENA */
+#define WM8990_RIN12_ENA_BIT                   4
+#define WM8990_ADCL_ENA                         0x0002  /* ADCL_ENA */
+#define WM8990_ADCL_ENA_BIT                    1
+#define WM8990_ADCR_ENA                         0x0001  /* ADCR_ENA */
+#define WM8990_ADCR_ENA_BIT                    0
+
+/*
+ * R3 (0x03) - Power Management (3)
+ */
+#define WM8990_LON_ENA                          0x2000  /* LON_ENA */
+#define WM8990_LON_ENA_BIT                     13
+#define WM8990_LOP_ENA                          0x1000  /* LOP_ENA */
+#define WM8990_LOP_ENA_BIT                     12
+#define WM8990_RON_ENA                          0x0800  /* RON_ENA */
+#define WM8990_RON_ENA_BIT                     11
+#define WM8990_ROP_ENA                          0x0400  /* ROP_ENA */
+#define WM8990_ROP_ENA_BIT                     10
+#define WM8990_LOPGA_ENA                        0x0080  /* LOPGA_ENA */
+#define WM8990_LOPGA_ENA_BIT                   7
+#define WM8990_ROPGA_ENA                        0x0040  /* ROPGA_ENA */
+#define WM8990_ROPGA_ENA_BIT                   6
+#define WM8990_LOMIX_ENA                        0x0020  /* LOMIX_ENA */
+#define WM8990_LOMIX_ENA_BIT                   5
+#define WM8990_ROMIX_ENA                        0x0010  /* ROMIX_ENA */
+#define WM8990_ROMIX_ENA_BIT                   4
+#define WM8990_DACL_ENA                         0x0002  /* DACL_ENA */
+#define WM8990_DACL_ENA_BIT                    1
+#define WM8990_DACR_ENA                         0x0001  /* DACR_ENA */
+#define WM8990_DACR_ENA_BIT                    0
+
+/*
+ * R4 (0x04) - Audio Interface (1)
+ */
+#define WM8990_AIFADCL_SRC                      0x8000  /* AIFADCL_SRC */
+#define WM8990_AIFADCR_SRC                      0x4000  /* AIFADCR_SRC */
+#define WM8990_AIFADC_TDM                       0x2000  /* AIFADC_TDM */
+#define WM8990_AIFADC_TDM_CHAN                  0x1000  /* AIFADC_TDM_CHAN */
+#define WM8990_AIF_BCLK_INV                     0x0100  /* AIF_BCLK_INV */
+#define WM8990_AIF_LRCLK_INV                    0x0080  /* AIF_LRCLK_INV */
+#define WM8990_AIF_WL_MASK                      0x0060  /* AIF_WL - [6:5] */
+#define WM8990_AIF_WL_16BITS                   (0 << 5)
+#define WM8990_AIF_WL_20BITS                   (1 << 5)
+#define WM8990_AIF_WL_24BITS                   (2 << 5)
+#define WM8990_AIF_WL_32BITS                   (3 << 5)
+#define WM8990_AIF_FMT_MASK                     0x0018  /* AIF_FMT - [4:3] */
+#define WM8990_AIF_TMF_RIGHTJ                  (0 << 3)
+#define WM8990_AIF_TMF_LEFTJ                   (1 << 3)
+#define WM8990_AIF_TMF_I2S                     (2 << 3)
+#define WM8990_AIF_TMF_DSP                     (3 << 3)
+
+/*
+ * R5 (0x05) - Audio Interface (2)
+ */
+#define WM8990_DACL_SRC                         0x8000  /* DACL_SRC */
+#define WM8990_DACR_SRC                         0x4000  /* DACR_SRC */
+#define WM8990_AIFDAC_TDM                       0x2000  /* AIFDAC_TDM */
+#define WM8990_AIFDAC_TDM_CHAN                  0x1000  /* AIFDAC_TDM_CHAN */
+#define WM8990_DAC_BOOST_MASK                   0x0C00  /* DAC_BOOST */
+#define WM8990_DAC_COMP                         0x0010  /* DAC_COMP */
+#define WM8990_DAC_COMPMODE                     0x0008  /* DAC_COMPMODE */
+#define WM8990_ADC_COMP                         0x0004  /* ADC_COMP */
+#define WM8990_ADC_COMPMODE                     0x0002  /* ADC_COMPMODE */
+#define WM8990_LOOPBACK                         0x0001  /* LOOPBACK */
+
+/*
+ * R6 (0x06) - Clocking (1)
+ */
+#define WM8990_TOCLK_RATE                       0x8000  /* TOCLK_RATE */
+#define WM8990_TOCLK_ENA                        0x4000  /* TOCLK_ENA */
+#define WM8990_OPCLKDIV_MASK                    0x1E00  /* OPCLKDIV - [12:9] */
+#define WM8990_DCLKDIV_MASK                     0x01C0  /* DCLKDIV - [8:6] */
+#define WM8990_BCLK_DIV_MASK                    0x001E  /* BCLK_DIV - [4:1] */
+#define WM8990_BCLK_DIV_1                      (0x0 << 1)
+#define WM8990_BCLK_DIV_1_5                    (0x1 << 1)
+#define WM8990_BCLK_DIV_2                      (0x2 << 1)
+#define WM8990_BCLK_DIV_3                      (0x3 << 1)
+#define WM8990_BCLK_DIV_4                      (0x4 << 1)
+#define WM8990_BCLK_DIV_5_5                    (0x5 << 1)
+#define WM8990_BCLK_DIV_6                      (0x6 << 1)
+#define WM8990_BCLK_DIV_8                      (0x7 << 1)
+#define WM8990_BCLK_DIV_11                     (0x8 << 1)
+#define WM8990_BCLK_DIV_12                     (0x9 << 1)
+#define WM8990_BCLK_DIV_16                     (0xA << 1)
+#define WM8990_BCLK_DIV_22                     (0xB << 1)
+#define WM8990_BCLK_DIV_24                     (0xC << 1)
+#define WM8990_BCLK_DIV_32                     (0xD << 1)
+#define WM8990_BCLK_DIV_44                     (0xE << 1)
+#define WM8990_BCLK_DIV_48                     (0xF << 1)
+
+/*
+ * R7 (0x07) - Clocking (2)
+ */
+#define WM8990_MCLK_SRC                         0x8000  /* MCLK_SRC */
+#define WM8990_SYSCLK_SRC                       0x4000  /* SYSCLK_SRC */
+#define WM8990_CLK_FORCE                        0x2000  /* CLK_FORCE */
+#define WM8990_MCLK_DIV_MASK                    0x1800  /* MCLK_DIV - [12:11] */
+#define WM8990_MCLK_DIV_1                      (0 << 11)
+#define WM8990_MCLK_DIV_2                      (2 << 11)
+#define WM8990_MCLK_INV                         0x0400  /* MCLK_INV */
+#define WM8990_ADC_CLKDIV_MASK                  0x00E0  /* ADC_CLKDIV */
+#define WM8990_ADC_CLKDIV_1                    (0 << 5)
+#define WM8990_ADC_CLKDIV_1_5                  (1 << 5)
+#define WM8990_ADC_CLKDIV_2                    (2 << 5)
+#define WM8990_ADC_CLKDIV_3                    (3 << 5)
+#define WM8990_ADC_CLKDIV_4                    (4 << 5)
+#define WM8990_ADC_CLKDIV_5_5                  (5 << 5)
+#define WM8990_ADC_CLKDIV_6                    (6 << 5)
+#define WM8990_DAC_CLKDIV_MASK                  0x001C  /* DAC_CLKDIV - [4:2] */
+#define WM8990_DAC_CLKDIV_1                    (0 << 2)
+#define WM8990_DAC_CLKDIV_1_5                  (1 << 2)
+#define WM8990_DAC_CLKDIV_2                    (2 << 2)
+#define WM8990_DAC_CLKDIV_3                    (3 << 2)
+#define WM8990_DAC_CLKDIV_4                    (4 << 2)
+#define WM8990_DAC_CLKDIV_5_5                  (5 << 2)
+#define WM8990_DAC_CLKDIV_6                    (6 << 2)
+
+/*
+ * R8 (0x08) - Audio Interface (3)
+ */
+#define WM8990_AIF_MSTR1                        0x8000  /* AIF_MSTR1 */
+#define WM8990_AIF_MSTR2                        0x4000  /* AIF_MSTR2 */
+#define WM8990_AIF_SEL                          0x2000  /* AIF_SEL */
+#define WM8990_ADCLRC_DIR                       0x0800  /* ADCLRC_DIR */
+#define WM8990_ADCLRC_RATE_MASK                 0x07FF  /* ADCLRC_RATE */
+
+/*
+ * R9 (0x09) - Audio Interface (4)
+ */
+#define WM8990_ALRCGPIO1                        0x8000  /* ALRCGPIO1 */
+#define WM8990_ALRCBGPIO6                       0x4000  /* ALRCBGPIO6 */
+#define WM8990_AIF_TRIS                         0x2000  /* AIF_TRIS */
+#define WM8990_DACLRC_DIR                       0x0800  /* DACLRC_DIR */
+#define WM8990_DACLRC_RATE_MASK                 0x07FF  /* DACLRC_RATE */
+
+/*
+ * R10 (0x0A) - DAC CTRL
+ */
+#define WM8990_AIF_LRCLKRATE                    0x0400  /* AIF_LRCLKRATE */
+#define WM8990_DAC_MONO                         0x0200  /* DAC_MONO */
+#define WM8990_DAC_SB_FILT                      0x0100  /* DAC_SB_FILT */
+#define WM8990_DAC_MUTERATE                     0x0080  /* DAC_MUTERATE */
+#define WM8990_DAC_MUTEMODE                     0x0040  /* DAC_MUTEMODE */
+#define WM8990_DEEMP_MASK                       0x0030  /* DEEMP - [5:4] */
+#define WM8990_DAC_MUTE                         0x0004  /* DAC_MUTE */
+#define WM8990_DACL_DATINV                      0x0002  /* DACL_DATINV */
+#define WM8990_DACR_DATINV                      0x0001  /* DACR_DATINV */
+
+/*
+ * R11 (0x0B) - Left DAC Digital Volume
+ */
+#define WM8990_DAC_VU                           0x0100  /* DAC_VU */
+#define WM8990_DACL_VOL_MASK                    0x00FF  /* DACL_VOL - [7:0] */
+#define WM8990_DACL_VOL_SHIFT                  0
+/*
+ * R12 (0x0C) - Right DAC Digital Volume
+ */
+#define WM8990_DAC_VU                           0x0100  /* DAC_VU */
+#define WM8990_DACR_VOL_MASK                    0x00FF  /* DACR_VOL - [7:0] */
+#define WM8990_DACR_VOL_SHIFT                  0
+/*
+ * R13 (0x0D) - Digital Side Tone
+ */
+#define WM8990_ADCL_DAC_SVOL_MASK               0x0F  /* ADCL_DAC_SVOL */
+#define WM8990_ADCL_DAC_SVOL_SHIFT             9
+#define WM8990_ADCR_DAC_SVOL_MASK               0x0F  /* ADCR_DAC_SVOL */
+#define WM8990_ADCR_DAC_SVOL_SHIFT             5
+#define WM8990_ADC_TO_DACL_MASK                 0x03  /* ADC_TO_DACL - [3:2] */
+#define WM8990_ADC_TO_DACL_SHIFT               2
+#define WM8990_ADC_TO_DACR_MASK                 0x03  /* ADC_TO_DACR - [1:0] */
+#define WM8990_ADC_TO_DACR_SHIFT               0
+
+/*
+ * R14 (0x0E) - ADC CTRL
+ */
+#define WM8990_ADC_HPF_ENA                      0x0100  /* ADC_HPF_ENA */
+#define WM8990_ADC_HPF_ENA_BIT                 8
+#define WM8990_ADC_HPF_CUT_MASK                 0x03  /* ADC_HPF_CUT - [6:5] */
+#define WM8990_ADC_HPF_CUT_SHIFT               5
+#define WM8990_ADCL_DATINV                      0x0002  /* ADCL_DATINV */
+#define WM8990_ADCL_DATINV_BIT                 1
+#define WM8990_ADCR_DATINV                      0x0001  /* ADCR_DATINV */
+#define WM8990_ADCR_DATINV_BIT                 0
+
+/*
+ * R15 (0x0F) - Left ADC Digital Volume
+ */
+#define WM8990_ADC_VU                           0x0100  /* ADC_VU */
+#define WM8990_ADCL_VOL_MASK                    0x00FF  /* ADCL_VOL - [7:0] */
+#define WM8990_ADCL_VOL_SHIFT                  0
+
+/*
+ * R16 (0x10) - Right ADC Digital Volume
+ */
+#define WM8990_ADC_VU                           0x0100  /* ADC_VU */
+#define WM8990_ADCR_VOL_MASK                    0x00FF  /* ADCR_VOL - [7:0] */
+#define WM8990_ADCR_VOL_SHIFT                  0
+
+/*
+ * R18 (0x12) - GPIO CTRL 1
+ */
+#define WM8990_IRQ                              0x1000  /* IRQ */
+#define WM8990_TEMPOK                           0x0800  /* TEMPOK */
+#define WM8990_MICSHRT                          0x0400  /* MICSHRT */
+#define WM8990_MICDET                           0x0200  /* MICDET */
+#define WM8990_PLL_LCK                          0x0100  /* PLL_LCK */
+#define WM8990_GPI8_STATUS                      0x0080  /* GPI8_STATUS */
+#define WM8990_GPI7_STATUS                      0x0040  /* GPI7_STATUS */
+#define WM8990_GPIO6_STATUS                     0x0020  /* GPIO6_STATUS */
+#define WM8990_GPIO5_STATUS                     0x0010  /* GPIO5_STATUS */
+#define WM8990_GPIO4_STATUS                     0x0008  /* GPIO4_STATUS */
+#define WM8990_GPIO3_STATUS                     0x0004  /* GPIO3_STATUS */
+#define WM8990_GPIO2_STATUS                     0x0002  /* GPIO2_STATUS */
+#define WM8990_GPIO1_STATUS                     0x0001  /* GPIO1_STATUS */
+
+/*
+ * R19 (0x13) - GPIO1 & GPIO2
+ */
+#define WM8990_GPIO2_DEB_ENA                    0x8000  /* GPIO2_DEB_ENA */
+#define WM8990_GPIO2_IRQ_ENA                    0x4000  /* GPIO2_IRQ_ENA */
+#define WM8990_GPIO2_PU                         0x2000  /* GPIO2_PU */
+#define WM8990_GPIO2_PD                         0x1000  /* GPIO2_PD */
+#define WM8990_GPIO2_SEL_MASK                   0x0F00  /* GPIO2_SEL - [11:8] */
+#define WM8990_GPIO1_DEB_ENA                    0x0080  /* GPIO1_DEB_ENA */
+#define WM8990_GPIO1_IRQ_ENA                    0x0040  /* GPIO1_IRQ_ENA */
+#define WM8990_GPIO1_PU                         0x0020  /* GPIO1_PU */
+#define WM8990_GPIO1_PD                         0x0010  /* GPIO1_PD */
+#define WM8990_GPIO1_SEL_MASK                   0x000F  /* GPIO1_SEL - [3:0] */
+
+/*
+ * R20 (0x14) - GPIO3 & GPIO4
+ */
+#define WM8990_GPIO4_DEB_ENA                    0x8000  /* GPIO4_DEB_ENA */
+#define WM8990_GPIO4_IRQ_ENA                    0x4000  /* GPIO4_IRQ_ENA */
+#define WM8990_GPIO4_PU                         0x2000  /* GPIO4_PU */
+#define WM8990_GPIO4_PD                         0x1000  /* GPIO4_PD */
+#define WM8990_GPIO4_SEL_MASK                   0x0F00  /* GPIO4_SEL - [11:8] */
+#define WM8990_GPIO3_DEB_ENA                    0x0080  /* GPIO3_DEB_ENA */
+#define WM8990_GPIO3_IRQ_ENA                    0x0040  /* GPIO3_IRQ_ENA */
+#define WM8990_GPIO3_PU                         0x0020  /* GPIO3_PU */
+#define WM8990_GPIO3_PD                         0x0010  /* GPIO3_PD */
+#define WM8990_GPIO3_SEL_MASK                   0x000F  /* GPIO3_SEL - [3:0] */
+
+/*
+ * R21 (0x15) - GPIO5 & GPIO6
+ */
+#define WM8990_GPIO6_DEB_ENA                    0x8000  /* GPIO6_DEB_ENA */
+#define WM8990_GPIO6_IRQ_ENA                    0x4000  /* GPIO6_IRQ_ENA */
+#define WM8990_GPIO6_PU                         0x2000  /* GPIO6_PU */
+#define WM8990_GPIO6_PD                         0x1000  /* GPIO6_PD */
+#define WM8990_GPIO6_SEL_MASK                   0x0F00  /* GPIO6_SEL - [11:8] */
+#define WM8990_GPIO5_DEB_ENA                    0x0080  /* GPIO5_DEB_ENA */
+#define WM8990_GPIO5_IRQ_ENA                    0x0040  /* GPIO5_IRQ_ENA */
+#define WM8990_GPIO5_PU                         0x0020  /* GPIO5_PU */
+#define WM8990_GPIO5_PD                         0x0010  /* GPIO5_PD */
+#define WM8990_GPIO5_SEL_MASK                   0x000F  /* GPIO5_SEL - [3:0] */
+
+/*
+ * R22 (0x16) - GPIOCTRL 2
+ */
+#define WM8990_RD_3W_ENA                        0x8000  /* RD_3W_ENA */
+#define WM8990_MODE_3W4W                        0x4000  /* MODE_3W4W */
+#define WM8990_TEMPOK_IRQ_ENA                   0x0800  /* TEMPOK_IRQ_ENA */
+#define WM8990_MICSHRT_IRQ_ENA                  0x0400  /* MICSHRT_IRQ_ENA */
+#define WM8990_MICDET_IRQ_ENA                   0x0200  /* MICDET_IRQ_ENA */
+#define WM8990_PLL_LCK_IRQ_ENA                  0x0100  /* PLL_LCK_IRQ_ENA */
+#define WM8990_GPI8_DEB_ENA                     0x0080  /* GPI8_DEB_ENA */
+#define WM8990_GPI8_IRQ_ENA                     0x0040  /* GPI8_IRQ_ENA */
+#define WM8990_GPI8_ENA                         0x0010  /* GPI8_ENA */
+#define WM8990_GPI7_DEB_ENA                     0x0008  /* GPI7_DEB_ENA */
+#define WM8990_GPI7_IRQ_ENA                     0x0004  /* GPI7_IRQ_ENA */
+#define WM8990_GPI7_ENA                         0x0001  /* GPI7_ENA */
+
+/*
+ * R23 (0x17) - GPIO_POL
+ */
+#define WM8990_IRQ_INV                          0x1000  /* IRQ_INV */
+#define WM8990_TEMPOK_POL                       0x0800  /* TEMPOK_POL */
+#define WM8990_MICSHRT_POL                      0x0400  /* MICSHRT_POL */
+#define WM8990_MICDET_POL                       0x0200  /* MICDET_POL */
+#define WM8990_PLL_LCK_POL                      0x0100  /* PLL_LCK_POL */
+#define WM8990_GPI8_POL                         0x0080  /* GPI8_POL */
+#define WM8990_GPI7_POL                         0x0040  /* GPI7_POL */
+#define WM8990_GPIO6_POL                        0x0020  /* GPIO6_POL */
+#define WM8990_GPIO5_POL                        0x0010  /* GPIO5_POL */
+#define WM8990_GPIO4_POL                        0x0008  /* GPIO4_POL */
+#define WM8990_GPIO3_POL                        0x0004  /* GPIO3_POL */
+#define WM8990_GPIO2_POL                        0x0002  /* GPIO2_POL */
+#define WM8990_GPIO1_POL                        0x0001  /* GPIO1_POL */
+
+/*
+ * R24 (0x18) - Left Line Input 1&2 Volume
+ */
+#define WM8990_IPVU                             0x0100  /* IPVU */
+#define WM8990_LI12MUTE                         0x0080  /* LI12MUTE */
+#define WM8990_LI12MUTE_BIT                    7
+#define WM8990_LI12ZC                           0x0040  /* LI12ZC */
+#define WM8990_LI12ZC_BIT                      6
+#define WM8990_LIN12VOL_MASK                    0x001F  /* LIN12VOL - [4:0] */
+#define WM8990_LIN12VOL_SHIFT                  0
+/*
+ * R25 (0x19) - Left Line Input 3&4 Volume
+ */
+#define WM8990_IPVU                             0x0100  /* IPVU */
+#define WM8990_LI34MUTE                         0x0080  /* LI34MUTE */
+#define WM8990_LI34MUTE_BIT                    7
+#define WM8990_LI34ZC                           0x0040  /* LI34ZC */
+#define WM8990_LI34ZC_BIT                      6
+#define WM8990_LIN34VOL_MASK                    0x001F  /* LIN34VOL - [4:0] */
+#define WM8990_LIN34VOL_SHIFT                  0
+
+/*
+ * R26 (0x1A) - Right Line Input 1&2 Volume
+ */
+#define WM8990_IPVU                             0x0100  /* IPVU */
+#define WM8990_RI12MUTE                         0x0080  /* RI12MUTE */
+#define WM8990_RI12MUTE_BIT                    7
+#define WM8990_RI12ZC                           0x0040  /* RI12ZC */
+#define WM8990_RI12ZC_BIT                      6
+#define WM8990_RIN12VOL_MASK                    0x001F  /* RIN12VOL - [4:0] */
+#define WM8990_RIN12VOL_SHIFT                  0
+
+/*
+ * R27 (0x1B) - Right Line Input 3&4 Volume
+ */
+#define WM8990_IPVU                             0x0100  /* IPVU */
+#define WM8990_RI34MUTE                         0x0080  /* RI34MUTE */
+#define WM8990_RI34MUTE_BIT                    7
+#define WM8990_RI34ZC                           0x0040  /* RI34ZC */
+#define WM8990_RI34ZC_BIT                      6
+#define WM8990_RIN34VOL_MASK                    0x001F  /* RIN34VOL - [4:0] */
+#define WM8990_RIN34VOL_SHIFT                  0
+
+/*
+ * R28 (0x1C) - Left Output Volume
+ */
+#define WM8990_OPVU                             0x0100  /* OPVU */
+#define WM8990_LOZC                             0x0080  /* LOZC */
+#define WM8990_LOZC_BIT                                7
+#define WM8990_LOUTVOL_MASK                     0x007F  /* LOUTVOL - [6:0] */
+#define WM8990_LOUTVOL_SHIFT                   0
+/*
+ * R29 (0x1D) - Right Output Volume
+ */
+#define WM8990_OPVU                             0x0100  /* OPVU */
+#define WM8990_ROZC                             0x0080  /* ROZC */
+#define WM8990_ROZC_BIT                                7
+#define WM8990_ROUTVOL_MASK                     0x007F  /* ROUTVOL - [6:0] */
+#define WM8990_ROUTVOL_SHIFT                   0
+/*
+ * R30 (0x1E) - Line Outputs Volume
+ */
+#define WM8990_LONMUTE                          0x0040  /* LONMUTE */
+#define WM8990_LONMUTE_BIT                     6
+#define WM8990_LOPMUTE                          0x0020  /* LOPMUTE */
+#define WM8990_LOPMUTE_BIT                     5
+#define WM8990_LOATTN                           0x0010  /* LOATTN */
+#define WM8990_LOATTN_BIT                      4
+#define WM8990_RONMUTE                          0x0004  /* RONMUTE */
+#define WM8990_RONMUTE_BIT                     2
+#define WM8990_ROPMUTE                          0x0002  /* ROPMUTE */
+#define WM8990_ROPMUTE_BIT                     1
+#define WM8990_ROATTN                           0x0001  /* ROATTN */
+#define WM8990_ROATTN_BIT                      0
+
+/*
+ * R31 (0x1F) - Out3/4 Volume
+ */
+#define WM8990_OUT3MUTE                         0x0020  /* OUT3MUTE */
+#define WM8990_OUT3MUTE_BIT                    5
+#define WM8990_OUT3ATTN                         0x0010  /* OUT3ATTN */
+#define WM8990_OUT3ATTN_BIT                    4
+#define WM8990_OUT4MUTE                         0x0002  /* OUT4MUTE */
+#define WM8990_OUT4MUTE_BIT                    1
+#define WM8990_OUT4ATTN                         0x0001  /* OUT4ATTN */
+#define WM8990_OUT4ATTN_BIT                    0
+
+/*
+ * R32 (0x20) - Left OPGA Volume
+ */
+#define WM8990_OPVU                             0x0100  /* OPVU */
+#define WM8990_LOPGAZC                          0x0080  /* LOPGAZC */
+#define WM8990_LOPGAZC_BIT                     7
+#define WM8990_LOPGAVOL_MASK                    0x007F  /* LOPGAVOL - [6:0] */
+#define WM8990_LOPGAVOL_SHIFT                  0
+
+/*
+ * R33 (0x21) - Right OPGA Volume
+ */
+#define WM8990_OPVU                             0x0100  /* OPVU */
+#define WM8990_ROPGAZC                          0x0080  /* ROPGAZC */
+#define WM8990_ROPGAZC_BIT                     7
+#define WM8990_ROPGAVOL_MASK                    0x007F  /* ROPGAVOL - [6:0] */
+#define WM8990_ROPGAVOL_SHIFT                  0
+/*
+ * R34 (0x22) - Speaker Volume
+ */
+#define WM8990_SPKVOL_MASK                      0x0003  /* SPKVOL - [1:0] */
+#define WM8990_SPKVOL_SHIFT                    0
+
+/*
+ * R35 (0x23) - ClassD1
+ */
+#define WM8990_CDMODE                           0x0100  /* CDMODE */
+#define WM8990_CDMODE_BIT                      8
+
+/*
+ * R37 (0x25) - ClassD3
+ */
+#define WM8990_DCGAIN_MASK                      0x0007  /* DCGAIN - [5:3] */
+#define WM8990_DCGAIN_SHIFT                    3
+#define WM8990_ACGAIN_MASK                      0x0007  /* ACGAIN - [2:0] */
+#define WM8990_ACGAIN_SHIFT                    0
+/*
+ * R39 (0x27) - Input Mixer1
+ */
+#define WM8990_AINLMODE_MASK                    0x000C  /* AINLMODE - [3:2] */
+#define WM8990_AINLMODE_SHIFT                  2
+#define WM8990_AINRMODE_MASK                    0x0003  /* AINRMODE - [1:0] */
+#define WM8990_AINRMODE_SHIFT                  0
+
+/*
+ * R40 (0x28) - Input Mixer2
+ */
+#define WM8990_LMP4                            0x0080  /* LMP4 */
+#define WM8990_LMP4_BIT                         7      /* LMP4 */
+#define WM8990_LMN3                             0x0040  /* LMN3 */
+#define WM8990_LMN3_BIT                         6       /* LMN3 */
+#define WM8990_LMP2                             0x0020  /* LMP2 */
+#define WM8990_LMP2_BIT                         5       /* LMP2 */
+#define WM8990_LMN1                             0x0010  /* LMN1 */
+#define WM8990_LMN1_BIT                         4       /* LMN1 */
+#define WM8990_RMP4                             0x0008  /* RMP4 */
+#define WM8990_RMP4_BIT                         3       /* RMP4 */
+#define WM8990_RMN3                             0x0004  /* RMN3 */
+#define WM8990_RMN3_BIT                         2       /* RMN3 */
+#define WM8990_RMP2                             0x0002  /* RMP2 */
+#define WM8990_RMP2_BIT                         1       /* RMP2 */
+#define WM8990_RMN1                             0x0001  /* RMN1 */
+#define WM8990_RMN1_BIT                         0       /* RMN1 */
+
+/*
+ * R41 (0x29) - Input Mixer3
+ */
+#define WM8990_L34MNB                           0x0100  /* L34MNB */
+#define WM8990_L34MNB_BIT                      8
+#define WM8990_L34MNBST                         0x0080  /* L34MNBST */
+#define WM8990_L34MNBST_BIT                    7
+#define WM8990_L12MNB                           0x0020  /* L12MNB */
+#define WM8990_L12MNB_BIT                      5
+#define WM8990_L12MNBST                         0x0010  /* L12MNBST */
+#define WM8990_L12MNBST_BIT                    4
+#define WM8990_LDBVOL_MASK                      0x0007  /* LDBVOL - [2:0] */
+#define WM8990_LDBVOL_SHIFT                    0
+
+/*
+ * R42 (0x2A) - Input Mixer4
+ */
+#define WM8990_R34MNB                           0x0100  /* R34MNB */
+#define WM8990_R34MNB_BIT                      8
+#define WM8990_R34MNBST                         0x0080  /* R34MNBST */
+#define WM8990_R34MNBST_BIT                    7
+#define WM8990_R12MNB                           0x0020  /* R12MNB */
+#define WM8990_R12MNB_BIT                      5
+#define WM8990_R12MNBST                         0x0010  /* R12MNBST */
+#define WM8990_R12MNBST_BIT                    4
+#define WM8990_RDBVOL_MASK                      0x0007  /* RDBVOL - [2:0] */
+#define WM8990_RDBVOL_SHIFT                    0
+
+/*
+ * R43 (0x2B) - Input Mixer5
+ */
+#define WM8990_LI2BVOL_MASK                     0x07  /* LI2BVOL - [8:6] */
+#define WM8990_LI2BVOL_SHIFT                   6
+#define WM8990_LR4BVOL_MASK                     0x07  /* LR4BVOL - [5:3] */
+#define WM8990_LR4BVOL_SHIFT                   3
+#define WM8990_LL4BVOL_MASK                     0x07  /* LL4BVOL - [2:0] */
+#define WM8990_LL4BVOL_SHIFT                   0
+
+/*
+ * R44 (0x2C) - Input Mixer6
+ */
+#define WM8990_RI2BVOL_MASK                     0x07  /* RI2BVOL - [8:6] */
+#define WM8990_RI2BVOL_SHIFT                   6
+#define WM8990_RL4BVOL_MASK                     0x07  /* RL4BVOL - [5:3] */
+#define WM8990_RL4BVOL_SHIFT                   3
+#define WM8990_RR4BVOL_MASK                     0x07  /* RR4BVOL - [2:0] */
+#define WM8990_RR4BVOL_SHIFT                   0
+
+/*
+ * R45 (0x2D) - Output Mixer1
+ */
+#define WM8990_LRBLO                            0x0080  /* LRBLO */
+#define WM8990_LRBLO_BIT                       7
+#define WM8990_LLBLO                            0x0040  /* LLBLO */
+#define WM8990_LLBLO_BIT                       6
+#define WM8990_LRI3LO                           0x0020  /* LRI3LO */
+#define WM8990_LRI3LO_BIT                      5
+#define WM8990_LLI3LO                           0x0010  /* LLI3LO */
+#define WM8990_LLI3LO_BIT                      4
+#define WM8990_LR12LO                           0x0008  /* LR12LO */
+#define WM8990_LR12LO_BIT                      3
+#define WM8990_LL12LO                           0x0004  /* LL12LO */
+#define WM8990_LL12LO_BIT                      2
+#define WM8990_LDLO                             0x0001  /* LDLO */
+#define WM8990_LDLO_BIT                                0
+
+/*
+ * R46 (0x2E) - Output Mixer2
+ */
+#define WM8990_RLBRO                            0x0080  /* RLBRO */
+#define WM8990_RLBRO_BIT                       7
+#define WM8990_RRBRO                            0x0040  /* RRBRO */
+#define WM8990_RRBRO_BIT                       6
+#define WM8990_RLI3RO                           0x0020  /* RLI3RO */
+#define WM8990_RLI3RO_BIT                      5
+#define WM8990_RRI3RO                           0x0010  /* RRI3RO */
+#define WM8990_RRI3RO_BIT                      4
+#define WM8990_RL12RO                           0x0008  /* RL12RO */
+#define WM8990_RL12RO_BIT                      3
+#define WM8990_RR12RO                           0x0004  /* RR12RO */
+#define WM8990_RR12RO_BIT                      2
+#define WM8990_RDRO                             0x0001  /* RDRO */
+#define WM8990_RDRO_BIT                                0
+
+/*
+ * R47 (0x2F) - Output Mixer3
+ */
+#define WM8990_LLI3LOVOL_MASK                   0x07  /* LLI3LOVOL - [8:6] */
+#define WM8990_LLI3LOVOL_SHIFT                 6
+#define WM8990_LR12LOVOL_MASK                   0x07  /* LR12LOVOL - [5:3] */
+#define WM8990_LR12LOVOL_SHIFT                 3
+#define WM8990_LL12LOVOL_MASK                   0x07  /* LL12LOVOL - [2:0] */
+#define WM8990_LL12LOVOL_SHIFT                 0
+
+/*
+ * R48 (0x30) - Output Mixer4
+ */
+#define WM8990_RRI3ROVOL_MASK                   0x07  /* RRI3ROVOL - [8:6] */
+#define WM8990_RRI3ROVOL_SHIFT                 6
+#define WM8990_RL12ROVOL_MASK                   0x07  /* RL12ROVOL - [5:3] */
+#define WM8990_RL12ROVOL_SHIFT                 3
+#define WM8990_RR12ROVOL_MASK                   0x07  /* RR12ROVOL - [2:0] */
+#define WM8990_RR12ROVOL_SHIFT                 0
+
+/*
+ * R49 (0x31) - Output Mixer5
+ */
+#define WM8990_LRI3LOVOL_MASK                   0x07  /* LRI3LOVOL - [8:6] */
+#define WM8990_LRI3LOVOL_SHIFT                 6
+#define WM8990_LRBLOVOL_MASK                    0x07  /* LRBLOVOL - [5:3] */
+#define WM8990_LRBLOVOL_SHIFT                  3
+#define WM8990_LLBLOVOL_MASK                    0x07  /* LLBLOVOL - [2:0] */
+#define WM8990_LLBLOVOL_SHIFT                  0
+
+/*
+ * R50 (0x32) - Output Mixer6
+ */
+#define WM8990_RLI3ROVOL_MASK                   0x07  /* RLI3ROVOL - [8:6] */
+#define WM8990_RLI3ROVOL_SHIFT                 6
+#define WM8990_RLBROVOL_MASK                    0x07  /* RLBROVOL - [5:3] */
+#define WM8990_RLBROVOL_SHIFT                  3
+#define WM8990_RRBROVOL_MASK                    0x07  /* RRBROVOL - [2:0] */
+#define WM8990_RRBROVOL_SHIFT                  0
+
+/*
+ * R51 (0x33) - Out3/4 Mixer
+ */
+#define WM8990_VSEL_MASK                        0x0180  /* VSEL - [8:7] */
+#define WM8990_LI4O3                            0x0020  /* LI4O3 */
+#define WM8990_LI4O3_BIT                       5
+#define WM8990_LPGAO3                           0x0010  /* LPGAO3 */
+#define WM8990_LPGAO3_BIT                      4
+#define WM8990_RI4O4                            0x0002  /* RI4O4 */
+#define WM8990_RI4O4_BIT                       1
+#define WM8990_RPGAO4                           0x0001  /* RPGAO4 */
+#define WM8990_RPGAO4_BIT                      0
+/*
+ * R52 (0x34) - Line Mixer1
+ */
+#define WM8990_LLOPGALON                        0x0040  /* LLOPGALON */
+#define WM8990_LLOPGALON_BIT                   6
+#define WM8990_LROPGALON                        0x0020  /* LROPGALON */
+#define WM8990_LROPGALON_BIT                   5
+#define WM8990_LOPLON                           0x0010  /* LOPLON */
+#define WM8990_LOPLON_BIT                      4
+#define WM8990_LR12LOP                          0x0004  /* LR12LOP */
+#define WM8990_LR12LOP_BIT                     2
+#define WM8990_LL12LOP                          0x0002  /* LL12LOP */
+#define WM8990_LL12LOP_BIT                     1
+#define WM8990_LLOPGALOP                        0x0001  /* LLOPGALOP */
+#define WM8990_LLOPGALOP_BIT                   0
+/*
+ * R53 (0x35) - Line Mixer2
+ */
+#define WM8990_RROPGARON                        0x0040  /* RROPGARON */
+#define WM8990_RROPGARON_BIT                   6
+#define WM8990_RLOPGARON                        0x0020  /* RLOPGARON */
+#define WM8990_RLOPGARON_BIT                   5
+#define WM8990_ROPRON                           0x0010  /* ROPRON */
+#define WM8990_ROPRON_BIT                      4
+#define WM8990_RL12ROP                          0x0004  /* RL12ROP */
+#define WM8990_RL12ROP_BIT                     2
+#define WM8990_RR12ROP                          0x0002  /* RR12ROP */
+#define WM8990_RR12ROP_BIT                     1
+#define WM8990_RROPGAROP                        0x0001  /* RROPGAROP */
+#define WM8990_RROPGAROP_BIT                   0
+
+/*
+ * R54 (0x36) - Speaker Mixer
+ */
+#define WM8990_LB2SPK                           0x0080  /* LB2SPK */
+#define WM8990_LB2SPK_BIT                      7
+#define WM8990_RB2SPK                           0x0040  /* RB2SPK */
+#define WM8990_RB2SPK_BIT                      6
+#define WM8990_LI2SPK                           0x0020  /* LI2SPK */
+#define WM8990_LI2SPK_BIT                      5
+#define WM8990_RI2SPK                           0x0010  /* RI2SPK */
+#define WM8990_RI2SPK_BIT                      4
+#define WM8990_LOPGASPK                         0x0008  /* LOPGASPK */
+#define WM8990_LOPGASPK_BIT                    3
+#define WM8990_ROPGASPK                         0x0004  /* ROPGASPK */
+#define WM8990_ROPGASPK_BIT                    2
+#define WM8990_LDSPK                            0x0002  /* LDSPK */
+#define WM8990_LDSPK_BIT                       1
+#define WM8990_RDSPK                            0x0001  /* RDSPK */
+#define WM8990_RDSPK_BIT                       0
+
+/*
+ * R55 (0x37) - Additional Control
+ */
+#define WM8990_VROI                             0x0001  /* VROI */
+
+/*
+ * R56 (0x38) - AntiPOP1
+ */
+#define WM8990_DIS_LLINE                        0x0020  /* DIS_LLINE */
+#define WM8990_DIS_RLINE                        0x0010  /* DIS_RLINE */
+#define WM8990_DIS_OUT3                         0x0008  /* DIS_OUT3 */
+#define WM8990_DIS_OUT4                         0x0004  /* DIS_OUT4 */
+#define WM8990_DIS_LOUT                         0x0002  /* DIS_LOUT */
+#define WM8990_DIS_ROUT                         0x0001  /* DIS_ROUT */
+
+/*
+ * R57 (0x39) - AntiPOP2
+ */
+#define WM8990_SOFTST                           0x0040  /* SOFTST */
+#define WM8990_BUFIOEN                          0x0008  /* BUFIOEN */
+#define WM8990_BUFDCOPEN                        0x0004  /* BUFDCOPEN */
+#define WM8990_POBCTRL                          0x0002  /* POBCTRL */
+#define WM8990_VMIDTOG                          0x0001  /* VMIDTOG */
+
+/*
+ * R58 (0x3A) - MICBIAS
+ */
+#define WM8990_MCDSCTH_MASK                     0x00C0  /* MCDSCTH - [7:6] */
+#define WM8990_MCDTHR_MASK                      0x0038  /* MCDTHR - [5:3] */
+#define WM8990_MCD                              0x0004  /* MCD */
+#define WM8990_MBSEL                            0x0001  /* MBSEL */
+
+/*
+ * R60 (0x3C) - PLL1
+ */
+#define WM8990_SDM                              0x0080  /* SDM */
+#define WM8990_PRESCALE                         0x0040  /* PRESCALE */
+#define WM8990_PLLN_MASK                        0x000F  /* PLLN - [3:0] */
+
+/*
+ * R61 (0x3D) - PLL2
+ */
+#define WM8990_PLLK1_MASK                       0x00FF  /* PLLK1 - [7:0] */
+
+/*
+ * R62 (0x3E) - PLL3
+ */
+#define WM8990_PLLK2_MASK                       0x00FF  /* PLLK2 - [7:0] */
+
+/*
+ * R63 (0x3F) - Internal Driver Bits
+ */
+#define WM8990_INMIXL_PWR_BIT                  0
+#define WM8990_AINLMUX_PWR_BIT                 1
+#define WM8990_INMIXR_PWR_BIT                  2
+#define WM8990_AINRMUX_PWR_BIT                 3
+
+struct wm8990_setup_data {
+       unsigned short i2c_address;
+};
+
+#define WM8990_MCLK_DIV 0
+#define WM8990_DACCLK_DIV 1
+#define WM8990_ADCCLK_DIV 2
+#define WM8990_BCLK_DIV 3
+
+extern struct snd_soc_dai wm8990_dai;
+extern struct snd_soc_codec_device soc_codec_dev_wm8990;
+
+#endif /* __WM8990REGISTERDEFS_H__ */
+/*------------------------------ END OF FILE ---------------------------------*/
index 76c1e2d..9fc8edd 100644 (file)
@@ -9,9 +9,6 @@
  *  under  the terms of  the GNU General  Public License as published by the
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
- *
- *  Revision history
- *    4th Feb 2006   Initial version.
  */
 
 #include <linux/init.h>
@@ -25,6 +22,7 @@
 #include <sound/initval.h>
 #include <sound/soc.h>
 #include <sound/soc-dapm.h>
+#include "wm9712.h"
 
 #define WM9712_VERSION "0.4"
 
@@ -351,7 +349,7 @@ SND_SOC_DAPM_INPUT("MIC1"),
 SND_SOC_DAPM_INPUT("MIC2"),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* virtual mixer - mixes left & right channels for spk and mono */
        {"AC97 Mixer", NULL, "Left DAC"},
        {"AC97 Mixer", NULL, "Right DAC"},
@@ -446,21 +444,14 @@ static const char *audio_map[][3] = {
        {"Speaker PGA", NULL, "Speaker Mux"},
        {"LOUT2", NULL, "Speaker PGA"},
        {"ROUT2", NULL, "Speaker PGA"},
-
-       {NULL, NULL, NULL},
 };
 
 static int wm9712_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(wm9712_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm9712_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm9712_dapm_widgets,
+                                 ARRAY_SIZE(wm9712_dapm_widgets));
 
-       /* set up audio path connects */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                                          audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -541,7 +532,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream)
                SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
                SNDRV_PCM_RATE_48000)
 
-struct snd_soc_codec_dai wm9712_dai[] = {
+struct snd_soc_dai wm9712_dai[] = {
 {
        .name = "AC97 HiFi",
        .type = SND_SOC_DAI_AC97_BUS,
@@ -574,23 +565,23 @@ struct snd_soc_codec_dai wm9712_dai[] = {
 };
 EXPORT_SYMBOL_GPL(wm9712_dai);
 
-static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
+static int wm9712_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
 {
-       switch (event) {
-       case SNDRV_CTL_POWER_D0: /* full On */
-       case SNDRV_CTL_POWER_D1: /* partial On */
-       case SNDRV_CTL_POWER_D2: /* partial On */
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+       case SND_SOC_BIAS_PREPARE:
                break;
-       case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+       case SND_SOC_BIAS_STANDBY:
                ac97_write(codec, AC97_POWERDOWN, 0x0000);
                break;
-       case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+       case SND_SOC_BIAS_OFF:
                /* disable everything including AC link */
                ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
                ac97_write(codec, AC97_POWERDOWN, 0xffff);
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
        return 0;
 }
 
@@ -598,12 +589,12 @@ static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
 {
        if (try_warm && soc_ac97_ops.warm_reset) {
                soc_ac97_ops.warm_reset(codec->ac97);
-               if (!(ac97_read(codec, 0) & 0x8000))
+               if (ac97_read(codec, 0) == wm9712_reg[0])
                        return 1;
        }
 
        soc_ac97_ops.reset(codec->ac97);
-       if (ac97_read(codec, 0) & 0x8000)
+       if (ac97_read(codec, 0) != wm9712_reg[0])
                goto err;
        return 0;
 
@@ -618,7 +609,7 @@ static int wm9712_soc_suspend(struct platform_device *pdev,
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->codec;
 
-       wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
+       wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
@@ -635,7 +626,7 @@ static int wm9712_soc_resume(struct platform_device *pdev)
                return ret;
        }
 
-       wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        if (ret == 0) {
                /* Sync reg_cache with the hardware after cold reset */
@@ -647,8 +638,8 @@ static int wm9712_soc_resume(struct platform_device *pdev)
                }
        }
 
-       if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
-               wm9712_dapm_event(codec, SNDRV_CTL_POWER_D0);
+       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
+               wm9712_set_bias_level(codec, SND_SOC_BIAS_ON);
 
        return ret;
 }
@@ -682,7 +673,7 @@ static int wm9712_soc_probe(struct platform_device *pdev)
        codec->num_dai = ARRAY_SIZE(wm9712_dai);
        codec->write = ac97_write;
        codec->read = ac97_read;
-       codec->dapm_event = wm9712_dapm_event;
+       codec->set_bias_level = wm9712_set_bias_level;
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
@@ -706,7 +697,7 @@ static int wm9712_soc_probe(struct platform_device *pdev)
        /* set alc mux to none */
        ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
 
-       wm9712_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        wm9712_add_controls(codec);
        wm9712_add_widgets(codec);
        ret = snd_soc_register_card(socdev);
index 719105d..d29e8a1 100644 (file)
@@ -8,7 +8,7 @@
 #define WM9712_DAI_AC97_HIFI   0
 #define WM9712_DAI_AC97_AUX            1
 
-extern struct snd_soc_codec_dai wm9712_dai[2];
+extern struct snd_soc_dai wm9712_dai[2];
 extern struct snd_soc_codec_device soc_codec_dev_wm9712;
 
 #endif
index 1f24116..38d1fe0 100644 (file)
@@ -10,9 +10,6 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    4th Feb 2006   Initial version.
- *
  *  Features:-
  *
  *   o Support for AC97 Codec, Voice DAC and Aux DAC
@@ -456,7 +453,7 @@ SND_SOC_DAPM_INPUT("MIC2B"),
 SND_SOC_DAPM_VMID("VMID"),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* left HP mixer */
        {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
        {"Left HP Mixer", "Voice Playback Switch",   "Voice DAC"},
@@ -607,21 +604,14 @@ static const char *audio_map[][3] = {
        {"Capture Mono Mux", "Stereo", "Capture Mixer"},
        {"Capture Mono Mux", "Left", "Left Capture Source"},
        {"Capture Mono Mux", "Right", "Right Capture Source"},
-
-       {NULL, NULL, NULL},
 };
 
 static int wm9713_add_widgets(struct snd_soc_codec *codec)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(wm9713_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm9713_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm9713_dapm_widgets,
+                                 ARRAY_SIZE(wm9713_dapm_widgets));
 
-       /* set up audio path audio_mapnects */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        snd_soc_dapm_new_widgets(codec);
        return 0;
@@ -799,7 +789,7 @@ static int wm9713_set_pll(struct snd_soc_codec *codec,
        return 0;
 }
 
-static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
+static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai,
                int pll_id, unsigned int freq_in, unsigned int freq_out)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -810,7 +800,7 @@ static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
  * Tristate the PCM DAI lines, tristate can be disabled by calling
  * wm9713_set_dai_fmt()
  */
-static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai,
+static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai,
        int tristate)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -826,7 +816,7 @@ static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai,
  * Configure WM9713 clock dividers.
  * Voice DAC needs 256 FS
  */
-static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
+static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
                int div_id, int div)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -868,7 +858,7 @@ static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
        return 0;
 }
 
-static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -886,7 +876,7 @@ static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
                gpio |= 0x0018;
                break;
        case SND_SOC_DAIFMT_CBS_CFS:
-               reg |= 0x0200;
+               reg |= 0x2000;
                gpio |= 0x001a;
                break;
        case SND_SOC_DAIFMT_CBS_CFM:
@@ -1011,15 +1001,24 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream)
        return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
 }
 
-#define WM9713_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
-               SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
-               SNDRV_PCM_RATE_48000)
+#define WM9713_RATES (SNDRV_PCM_RATE_8000  |   \
+                     SNDRV_PCM_RATE_11025 |    \
+                     SNDRV_PCM_RATE_22050 |    \
+                     SNDRV_PCM_RATE_44100 |    \
+                     SNDRV_PCM_RATE_48000)
+
+#define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000  |       \
+                         SNDRV_PCM_RATE_11025 |        \
+                         SNDRV_PCM_RATE_16000 |        \
+                         SNDRV_PCM_RATE_22050 |        \
+                         SNDRV_PCM_RATE_44100 |        \
+                         SNDRV_PCM_RATE_48000)
 
 #define WM9713_PCM_FORMATS \
        (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
         SNDRV_PCM_FORMAT_S24_LE)
 
-struct snd_soc_codec_dai wm9713_dai[] = {
+struct snd_soc_dai wm9713_dai[] = {
 {
        .name = "AC97 HiFi",
        .type = SND_SOC_DAI_AC97_BUS,
@@ -1061,13 +1060,13 @@ struct snd_soc_codec_dai wm9713_dai[] = {
                .stream_name = "Voice Playback",
                .channels_min = 1,
                .channels_max = 1,
-               .rates = WM9713_RATES,
+               .rates = WM9713_PCM_RATES,
                .formats = WM9713_PCM_FORMATS,},
        .capture = {
                .stream_name = "Voice Capture",
                .channels_min = 1,
                .channels_max = 2,
-               .rates = WM9713_RATES,
+               .rates = WM9713_PCM_RATES,
                .formats = WM9713_PCM_FORMATS,},
        .ops = {
                .hw_params = wm9713_pcm_hw_params,
@@ -1086,44 +1085,44 @@ int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
 {
        if (try_warm && soc_ac97_ops.warm_reset) {
                soc_ac97_ops.warm_reset(codec->ac97);
-               if (!(ac97_read(codec, 0) & 0x8000))
+               if (ac97_read(codec, 0) == wm9713_reg[0])
                        return 1;
        }
 
        soc_ac97_ops.reset(codec->ac97);
-       if (ac97_read(codec, 0) & 0x8000)
+       if (ac97_read(codec, 0) != wm9713_reg[0])
                return -EIO;
        return 0;
 }
 EXPORT_SYMBOL_GPL(wm9713_reset);
 
-static int wm9713_dapm_event(struct snd_soc_codec *codec, int event)
+static int wm9713_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
 {
        u16 reg;
 
-       switch (event) {
-       case SNDRV_CTL_POWER_D0: /* full On */
+       switch (level) {
+       case SND_SOC_BIAS_ON:
                /* enable thermal shutdown */
                reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff;
                ac97_write(codec, AC97_EXTENDED_MID, reg);
                break;
-       case SNDRV_CTL_POWER_D1: /* partial On */
-       case SNDRV_CTL_POWER_D2: /* partial On */
+       case SND_SOC_BIAS_PREPARE:
                break;
-       case SNDRV_CTL_POWER_D3hot: /* Off, with power */
+       case SND_SOC_BIAS_STANDBY:
                /* enable master bias and vmid */
                reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff;
                ac97_write(codec, AC97_EXTENDED_MID, reg);
                ac97_write(codec, AC97_POWERDOWN, 0x0000);
                break;
-       case SNDRV_CTL_POWER_D3cold: /* Off, without power */
+       case SND_SOC_BIAS_OFF:
                /* disable everything including AC link */
                ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
                ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
                ac97_write(codec, AC97_POWERDOWN, 0xffff);
                break;
        }
-       codec->dapm_state = event;
+       codec->bias_level = level;
        return 0;
 }
 
@@ -1160,7 +1159,7 @@ static int wm9713_soc_resume(struct platform_device *pdev)
                return ret;
        }
 
-       wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* do we need to re-start the PLL ? */
        if (wm9713->pll_out)
@@ -1176,8 +1175,8 @@ static int wm9713_soc_resume(struct platform_device *pdev)
                }
        }
 
-       if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
-               wm9713_dapm_event(codec, SNDRV_CTL_POWER_D0);
+       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
+               wm9713_set_bias_level(codec, SND_SOC_BIAS_ON);
 
        return ret;
 }
@@ -1216,7 +1215,7 @@ static int wm9713_soc_probe(struct platform_device *pdev)
        codec->num_dai = ARRAY_SIZE(wm9713_dai);
        codec->write = ac97_write;
        codec->read = ac97_read;
-       codec->dapm_event = wm9713_dapm_event;
+       codec->set_bias_level = wm9713_set_bias_level;
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
@@ -1238,7 +1237,7 @@ static int wm9713_soc_probe(struct platform_device *pdev)
                goto reset_err;
        }
 
-       wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
+       wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* unmute the adc - move to kcontrol */
        reg = ac97_read(codec, AC97_CD) & 0x7fff;
index d357b6c..63b8d81 100644 (file)
@@ -46,7 +46,7 @@
 #define WM9713_DAI_PCM_VOICE   2
 
 extern struct snd_soc_codec_device soc_codec_dev_wm9713;
-extern struct snd_soc_codec_dai wm9713_dai[3];
+extern struct snd_soc_dai wm9713_dai[3];
 
 int wm9713_reset(struct snd_soc_codec *codec,  int try_warm);
 
index 20680c5..8f7e338 100644 (file)
@@ -1,6 +1,6 @@
 config SND_DAVINCI_SOC
        tristate "SoC Audio for the TI DAVINCI chip"
-       depends on ARCH_DAVINCI && SND_SOC
+       depends on ARCH_DAVINCI
        help
          Say Y or M if you want to add support for codecs attached to
          the DAVINCI AC97 or I2S interface. You will also need
index fcd1652..5e2c306 100644 (file)
@@ -33,24 +33,24 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
                         struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        int ret = 0;
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                                         SND_SOC_DAIFMT_CBM_CFM);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
                                       SND_SOC_DAIFMT_IB_NF);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
+       ret = snd_soc_dai_set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
                                            SND_SOC_CLOCK_OUT);
        if (ret < 0)
                return ret;
@@ -71,7 +71,7 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
 };
 
 /* davinci-evm machine audio_mapnections to the codec pins */
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        /* Headphone connected to HPLOUT, HPROUT */
        {"Headphone Jack", NULL, "HPLOUT"},
        {"Headphone Jack", NULL, "HPROUT"},
@@ -90,36 +90,30 @@ static const char *audio_map[][3] = {
        {"LINE2L", NULL, "Line In"},
        {"LINE1R", NULL, "Line In"},
        {"LINE2R", NULL, "Line In"},
-
-       {NULL, NULL, NULL},
 };
 
 /* Logic for a aic3x as connected on a davinci-evm */
 static int evm_aic3x_init(struct snd_soc_codec *codec)
 {
-       int i;
-
        /* Add davinci-evm specific widgets */
-       for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
+                                 ARRAY_SIZE(aic3x_dapm_widgets));
 
        /* Set up davinci-evm specific audio path audio_map */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                                          audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        /* not connected */
-       snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
-       snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
-       snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
+       snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
+       snd_soc_dapm_disable_pin(codec, "HPLCOM");
+       snd_soc_dapm_disable_pin(codec, "HPRCOM");
 
        /* always connected */
-       snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
-       snd_soc_dapm_set_endpoint(codec, "Line Out", 1);
-       snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
-       snd_soc_dapm_set_endpoint(codec, "Line In", 1);
+       snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+       snd_soc_dapm_enable_pin(codec, "Line Out");
+       snd_soc_dapm_enable_pin(codec, "Mic Jack");
+       snd_soc_dapm_enable_pin(codec, "Line In");
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 
        return 0;
 }
index c421774..5ebf1ff 100644 (file)
@@ -147,7 +147,7 @@ static void davinci_mcbsp_stop(struct snd_pcm_substream *substream)
 static int davinci_i2s_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
 
        cpu_dai->dma_data = dev->dma_params[substream->stream];
@@ -155,7 +155,7 @@ static int davinci_i2s_startup(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static int davinci_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                                   unsigned int fmt)
 {
        struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
@@ -295,11 +295,12 @@ static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
        return ret;
 }
 
-static int davinci_i2s_probe(struct platform_device *pdev)
+static int davinci_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
+       struct snd_soc_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
        struct davinci_mcbsp_dev *dev;
        struct resource *mem, *ioarea;
        struct evm_snd_platform_data *pdata;
@@ -356,11 +357,12 @@ err_release_region:
        return ret;
 }
 
-static void davinci_i2s_remove(struct platform_device *pdev)
+static void davinci_i2s_remove(struct platform_device *pdev,
+                              struct snd_soc_dai *dai)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
+       struct snd_soc_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
        struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
        struct resource *mem;
 
@@ -376,7 +378,7 @@ static void davinci_i2s_remove(struct platform_device *pdev)
 
 #define DAVINCI_I2S_RATES      SNDRV_PCM_RATE_8000_96000
 
-struct snd_soc_cpu_dai davinci_i2s_dai = {
+struct snd_soc_dai davinci_i2s_dai = {
        .name = "davinci-i2s",
        .id = 0,
        .type = SND_SOC_DAI_I2S,
index 9592d17..c5b0918 100644 (file)
@@ -12,6 +12,6 @@
 #ifndef _DAVINCI_I2S_H
 #define _DAVINCI_I2S_H
 
-extern struct snd_soc_cpu_dai davinci_i2s_dai;
+extern struct snd_soc_dai davinci_i2s_dai;
 
 #endif
index 6a76927..6a5e56a 100644 (file)
@@ -350,7 +350,7 @@ static void davinci_pcm_free(struct snd_pcm *pcm)
 static u64 davinci_pcm_dmamask = 0xffffffff;
 
 static int davinci_pcm_new(struct snd_card *card,
-                          struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
+                          struct snd_soc_dai *dai, struct snd_pcm *pcm)
 {
        int ret;
 
index 257101f..3368ace 100644 (file)
@@ -1,8 +1,6 @@
-menu "ALSA SoC audio for Freescale SOCs"
-
 config SND_SOC_MPC8610
        bool "ALSA SoC support for the MPC8610 SOC"
-       depends on SND_SOC && MPC8610_HPCD
+       depends on MPC8610_HPCD
        default y if MPC8610
        help
          Say Y if you want to add support for codecs attached to the SSI
@@ -16,5 +14,3 @@ config SND_SOC_MPC8610_HPCD
        default y if MPC8610_HPCD
        help
          Say Y if you want to enable audio on the Freescale MPC8610 HPCD.
-
-endmenu
index 78de716..da2bc59 100644 (file)
@@ -282,7 +282,7 @@ static irqreturn_t fsl_dma_isr(int irq, void *dev_id)
  * once for each .dai_link in the machine driver's snd_soc_machine
  * structure.
  */
-static int fsl_dma_new(struct snd_card *card, struct snd_soc_codec_dai *dai,
+static int fsl_dma_new(struct snd_card *card, struct snd_soc_dai *dai,
        struct snd_pcm *pcm)
 {
        static u64 fsl_dma_dmamask = DMA_BIT_MASK(32);
index 430a6ce..385d4a4 100644 (file)
@@ -126,7 +126,7 @@ struct fsl_dma_link_descriptor {
        u8 res[4];      /* Reserved */
 } __attribute__ ((aligned(32), packed));
 
-/* DMA information needed to create a snd_soc_cpu_dai object
+/* DMA information needed to create a snd_soc_dai object
  *
  * ssi_stx_phys: bus address of SSI STX register to use
  * ssi_srx_phys: bus address of SSI SRX register to use
index f588545..71bff33 100644 (file)
@@ -82,7 +82,7 @@ struct fsl_ssi_private {
        struct device *dev;
        unsigned int playback;
        unsigned int capture;
-       struct snd_soc_cpu_dai cpu_dai;
+       struct snd_soc_dai cpu_dai;
        struct device_attribute dev_attr;
 
        struct {
@@ -479,7 +479,7 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream)
  * @freq: the frequency of the given clock ID, currently ignored
  * @dir: SND_SOC_CLOCK_IN (clock slave) or SND_SOC_CLOCK_OUT (clock master)
  */
-static int fsl_ssi_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int fsl_ssi_set_sysclk(struct snd_soc_dai *cpu_dai,
                              int clk_id, unsigned int freq, int dir)
 {
 
@@ -497,7 +497,7 @@ static int fsl_ssi_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
  *
  * @format: one of SND_SOC_DAIFMT_xxx
  */
-static int fsl_ssi_set_fmt(struct snd_soc_cpu_dai *cpu_dai, unsigned int format)
+static int fsl_ssi_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int format)
 {
        return (format == SND_SOC_DAIFMT_I2S) ? 0 : -EINVAL;
 }
@@ -505,7 +505,7 @@ static int fsl_ssi_set_fmt(struct snd_soc_cpu_dai *cpu_dai, unsigned int format)
 /**
  * fsl_ssi_dai_template: template CPU DAI for the SSI
  */
-static struct snd_soc_cpu_dai fsl_ssi_dai_template = {
+static struct snd_soc_dai fsl_ssi_dai_template = {
        .playback = {
                /* The SSI does not support monaural audio. */
                .channels_min = 2,
@@ -569,15 +569,15 @@ static ssize_t fsl_sysfs_ssi_show(struct device *dev,
 }
 
 /**
- * fsl_ssi_create_dai: create a snd_soc_cpu_dai structure
+ * fsl_ssi_create_dai: create a snd_soc_dai structure
  *
- * This function is called by the machine driver to create a snd_soc_cpu_dai
+ * This function is called by the machine driver to create a snd_soc_dai
  * structure.  The function creates an ssi_private object, which contains
- * the snd_soc_cpu_dai.  It also creates the sysfs statistics device.
+ * the snd_soc_dai.  It also creates the sysfs statistics device.
  */
-struct snd_soc_cpu_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
+struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
 {
-       struct snd_soc_cpu_dai *fsl_ssi_dai;
+       struct snd_soc_dai *fsl_ssi_dai;
        struct fsl_ssi_private *ssi_private;
        int ret = 0;
        struct device_attribute *dev_attr;
@@ -588,7 +588,7 @@ struct snd_soc_cpu_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
                return NULL;
        }
        memcpy(&ssi_private->cpu_dai, &fsl_ssi_dai_template,
-              sizeof(struct snd_soc_cpu_dai));
+              sizeof(struct snd_soc_dai));
 
        fsl_ssi_dai = &ssi_private->cpu_dai;
        dev_attr = &ssi_private->dev_attr;
@@ -623,11 +623,11 @@ struct snd_soc_cpu_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
 EXPORT_SYMBOL_GPL(fsl_ssi_create_dai);
 
 /**
- * fsl_ssi_destroy_dai: destroy the snd_soc_cpu_dai object
+ * fsl_ssi_destroy_dai: destroy the snd_soc_dai object
  *
  * This function undoes the operations of fsl_ssi_create_dai()
  */
-void fsl_ssi_destroy_dai(struct snd_soc_cpu_dai *fsl_ssi_dai)
+void fsl_ssi_destroy_dai(struct snd_soc_dai *fsl_ssi_dai)
 {
        struct fsl_ssi_private *ssi_private =
        container_of(fsl_ssi_dai, struct fsl_ssi_private, cpu_dai);
index c5ce88e..83b44d7 100644 (file)
@@ -217,8 +217,8 @@ struct fsl_ssi_info {
        struct device *dev;
 };
 
-struct snd_soc_cpu_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info);
-void fsl_ssi_destroy_dai(struct snd_soc_cpu_dai *fsl_ssi_dai);
+struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info);
+void fsl_ssi_destroy_dai(struct snd_soc_dai *fsl_ssi_dai);
 
 #endif
 
index a00aac7..4bdc9d8 100644 (file)
@@ -58,9 +58,9 @@ static int mpc8610_hpcd_machine_probe(struct platform_device *sound_device)
                sound_device->dev.platform_data;
 
        /* Program the signal routing between the SSI and the DMA */
-       guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
+       guts_set_dmacr(machine_data->guts, machine_data->dma_id,
                machine_data->dma_channel_id[0], CCSR_GUTS_DMACR_DEV_SSI);
-       guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
+       guts_set_dmacr(machine_data->guts, machine_data->dma_id,
                machine_data->dma_channel_id[1], CCSR_GUTS_DMACR_DEV_SSI);
 
        guts_set_pmuxcr_dma(machine_data->guts, machine_data->dma_id,
@@ -96,62 +96,52 @@ static int mpc8610_hpcd_machine_probe(struct platform_device *sound_device)
 static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct mpc8610_hpcd_data *machine_data =
                rtd->socdev->dev->platform_data;
        int ret = 0;
 
        /* Tell the CPU driver what the serial protocol is. */
-       if (cpu_dai->dai_ops.set_fmt) {
-               ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
-                       machine_data->dai_format);
-               if (ret < 0) {
-                       dev_err(substream->pcm->card->dev,
-                               "could not set CPU driver audio format\n");
-                       return ret;
-               }
+       ret = snd_soc_dai_set_fmt(cpu_dai, machine_data->dai_format);
+       if (ret < 0) {
+               dev_err(substream->pcm->card->dev,
+                       "could not set CPU driver audio format\n");
+               return ret;
        }
 
        /* Tell the codec driver what the serial protocol is. */
-       if (codec_dai->dai_ops.set_fmt) {
-               ret = codec_dai->dai_ops.set_fmt(codec_dai,
-                       machine_data->dai_format);
-               if (ret < 0) {
-                       dev_err(substream->pcm->card->dev,
-                               "could not set codec driver audio format\n");
-                       return ret;
-               }
+       ret = snd_soc_dai_set_fmt(codec_dai, machine_data->dai_format);
+       if (ret < 0) {
+               dev_err(substream->pcm->card->dev,
+                       "could not set codec driver audio format\n");
+               return ret;
        }
 
        /*
         * Tell the CPU driver what the clock frequency is, and whether it's a
         * slave or master.
         */
-       if (cpu_dai->dai_ops.set_sysclk) {
-               ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, 0,
-                       machine_data->clk_frequency,
-                       machine_data->cpu_clk_direction);
-               if (ret < 0) {
-                       dev_err(substream->pcm->card->dev,
-                               "could not set CPU driver clock parameters\n");
-                       return ret;
-               }
+       ret = snd_soc_dai_set_sysclk(cpu_dai, 0,
+                                       machine_data->clk_frequency,
+                                       machine_data->cpu_clk_direction);
+       if (ret < 0) {
+               dev_err(substream->pcm->card->dev,
+                       "could not set CPU driver clock parameters\n");
+               return ret;
        }
 
        /*
         * Tell the codec driver what the MCLK frequency is, and whether it's
         * a slave or master.
         */
-       if (codec_dai->dai_ops.set_sysclk) {
-               ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0,
-                       machine_data->clk_frequency,
-                       machine_data->codec_clk_direction);
-               if (ret < 0) {
-                       dev_err(substream->pcm->card->dev,
-                               "could not set codec driver clock params\n");
-                       return ret;
-               }
+       ret = snd_soc_dai_set_sysclk(codec_dai, 0,
+                                       machine_data->clk_frequency,
+                                       machine_data->codec_clk_direction);
+       if (ret < 0) {
+               dev_err(substream->pcm->card->dev,
+                       "could not set codec driver clock params\n");
+               return ret;
        }
 
        return 0;
@@ -170,9 +160,9 @@ int mpc8610_hpcd_machine_remove(struct platform_device *sound_device)
 
        /* Restore the signal routing */
 
-       guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
+       guts_set_dmacr(machine_data->guts, machine_data->dma_id,
                machine_data->dma_channel_id[0], 0);
-       guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
+       guts_set_dmacr(machine_data->guts, machine_data->dma_id,
                machine_data->dma_channel_id[1], 0);
 
        switch (machine_data->ssi_id) {
@@ -182,7 +172,7 @@ int mpc8610_hpcd_machine_remove(struct platform_device *sound_device)
                break;
        case 1:
                clrsetbits_be32(&machine_data->guts->pmuxcr,
-                       CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
+                       CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_LA);
                break;
        }
 
index 0230d83..aea27e7 100644 (file)
@@ -1,5 +1,3 @@
-menu "SoC Audio for the Texas Instruments OMAP"
-
 config SND_OMAP_SOC
        tristate "SoC Audio for the Texas Instruments OMAP chips"
        depends on ARCH_OMAP && SND_SOC
@@ -15,5 +13,3 @@ config SND_OMAP_SOC_N810
        select SND_SOC_TLV320AIC3X
        help
          Say Y if you want to add support for SoC audio on Nokia N810.
-
-endmenu
index 6533563..02cec96 100644 (file)
 
 #include <asm/mach-types.h>
 #include <asm/arch/hardware.h>
-#include <asm/arch/gpio.h>
+#include <linux/gpio.h>
 #include <asm/arch/mcbsp.h>
 
 #include "omap-mcbsp.h"
 #include "omap-pcm.h"
 #include "../codecs/tlv320aic3x.h"
 
-#define RX44_HEADSET_AMP_GPIO  10
-#define RX44_SPEAKER_AMP_GPIO  101
+#define N810_HEADSET_AMP_GPIO  10
+#define N810_SPEAKER_AMP_GPIO  101
 
 static struct clk *sys_clkout2;
 static struct clk *sys_clkout2_src;
@@ -46,13 +46,26 @@ static struct clk *func96m_clk;
 
 static int n810_spk_func;
 static int n810_jack_func;
+static int n810_dmic_func;
 
 static void n810_ext_control(struct snd_soc_codec *codec)
 {
-       snd_soc_dapm_set_endpoint(codec, "Ext Spk", n810_spk_func);
-       snd_soc_dapm_set_endpoint(codec, "Headphone Jack", n810_jack_func);
+       if (n810_spk_func)
+               snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       else
+               snd_soc_dapm_disable_pin(codec, "Ext Spk");
+
+       if (n810_jack_func)
+               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+       else
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
 
-       snd_soc_dapm_sync_endpoints(codec);
+       if (n810_dmic_func)
+               snd_soc_dapm_enable_pin(codec, "DMic");
+       else
+               snd_soc_dapm_disable_pin(codec, "DMic");
+
+       snd_soc_dapm_sync(codec);
 }
 
 static int n810_startup(struct snd_pcm_substream *substream)
@@ -73,12 +86,12 @@ static int n810_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        int err;
 
        /* Set codec DAI configuration */
-       err = codec_dai->dai_ops.set_fmt(codec_dai,
+       err = snd_soc_dai_set_fmt(codec_dai,
                                         SND_SOC_DAIFMT_I2S |
                                         SND_SOC_DAIFMT_NB_NF |
                                         SND_SOC_DAIFMT_CBM_CFM);
@@ -86,7 +99,7 @@ static int n810_hw_params(struct snd_pcm_substream *substream,
                return err;
 
        /* Set cpu DAI configuration */
-       err = cpu_dai->dai_ops.set_fmt(cpu_dai,
+       err = snd_soc_dai_set_fmt(cpu_dai,
                                       SND_SOC_DAIFMT_I2S |
                                       SND_SOC_DAIFMT_NB_NF |
                                       SND_SOC_DAIFMT_CBM_CFM);
@@ -94,7 +107,7 @@ static int n810_hw_params(struct snd_pcm_substream *substream,
                return err;
 
        /* Set the codec system clock for DAC and ADC */
-       err = codec_dai->dai_ops.set_sysclk(codec_dai, 0, 12000000,
+       err = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000,
                                            SND_SOC_CLOCK_IN);
 
        return err;
@@ -150,13 +163,35 @@ static int n810_set_jack(struct snd_kcontrol *kcontrol,
        return 1;
 }
 
+static int n810_get_input(struct snd_kcontrol *kcontrol,
+                         struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.integer.value[0] = n810_dmic_func;
+
+       return 0;
+}
+
+static int n810_set_input(struct snd_kcontrol *kcontrol,
+                         struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec =  snd_kcontrol_chip(kcontrol);
+
+       if (n810_dmic_func == ucontrol->value.integer.value[0])
+               return 0;
+
+       n810_dmic_func = ucontrol->value.integer.value[0];
+       n810_ext_control(codec);
+
+       return 1;
+}
+
 static int n810_spk_event(struct snd_soc_dapm_widget *w,
                          struct snd_kcontrol *k, int event)
 {
        if (SND_SOC_DAPM_EVENT_ON(event))
-               omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO, 1);
+               gpio_set_value(N810_SPEAKER_AMP_GPIO, 1);
        else
-               omap_set_gpio_dataout(RX44_SPEAKER_AMP_GPIO, 0);
+               gpio_set_value(N810_SPEAKER_AMP_GPIO, 0);
 
        return 0;
 }
@@ -165,9 +200,9 @@ static int n810_jack_event(struct snd_soc_dapm_widget *w,
                           struct snd_kcontrol *k, int event)
 {
        if (SND_SOC_DAPM_EVENT_ON(event))
-               omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO, 1);
+               gpio_set_value(N810_HEADSET_AMP_GPIO, 1);
        else
-               omap_set_gpio_dataout(RX44_HEADSET_AMP_GPIO, 0);
+               gpio_set_value(N810_HEADSET_AMP_GPIO, 0);
 
        return 0;
 }
@@ -175,21 +210,27 @@ static int n810_jack_event(struct snd_soc_dapm_widget *w,
 static const struct snd_soc_dapm_widget aic33_dapm_widgets[] = {
        SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event),
        SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event),
+       SND_SOC_DAPM_MIC("DMic", NULL),
 };
 
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
        {"Headphone Jack", NULL, "HPLOUT"},
        {"Headphone Jack", NULL, "HPROUT"},
 
        {"Ext Spk", NULL, "LLOUT"},
        {"Ext Spk", NULL, "RLOUT"},
+
+       {"DMic Rate 64", NULL, "Mic Bias 2V"},
+       {"Mic Bias 2V", NULL, "DMic"},
 };
 
 static const char *spk_function[] = {"Off", "On"};
 static const char *jack_function[] = {"Off", "Headphone"};
+static const char *input_function[] = {"ADC", "Digital Mic"};
 static const struct soc_enum n810_enum[] = {
        SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
        SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
+       SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
 };
 
 static const struct snd_kcontrol_new aic33_n810_controls[] = {
@@ -197,6 +238,8 @@ static const struct snd_kcontrol_new aic33_n810_controls[] = {
                     n810_get_spk, n810_set_spk),
        SOC_ENUM_EXT("Jack Function", n810_enum[1],
                     n810_get_jack, n810_set_jack),
+       SOC_ENUM_EXT("Input Select",  n810_enum[2],
+                    n810_get_input, n810_set_input),
 };
 
 static int n810_aic33_init(struct snd_soc_codec *codec)
@@ -204,9 +247,9 @@ static int n810_aic33_init(struct snd_soc_codec *codec)
        int i, err;
 
        /* Not connected */
-       snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
-       snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
-       snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
+       snd_soc_dapm_disable_pin(codec, "MONO_LOUT");
+       snd_soc_dapm_disable_pin(codec, "HPLCOM");
+       snd_soc_dapm_disable_pin(codec, "HPRCOM");
 
        /* Add N810 specific controls */
        for (i = 0; i < ARRAY_SIZE(aic33_n810_controls); i++) {
@@ -217,15 +260,13 @@ static int n810_aic33_init(struct snd_soc_codec *codec)
        }
 
        /* Add N810 specific widgets */
-       for (i = 0; i < ARRAY_SIZE(aic33_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &aic33_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, aic33_dapm_widgets,
+                                 ARRAY_SIZE(aic33_dapm_widgets));
 
        /* Set up N810 specific audio path audio_map */
-       for (i = 0; i < ARRAY_SIZE(audio_map); i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 
        return 0;
 }
@@ -250,6 +291,8 @@ static struct snd_soc_machine snd_soc_machine_n810 = {
 /* Audio private data */
 static struct aic3x_setup_data n810_aic33_setup = {
        .i2c_address = 0x18,
+       .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
+       .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
 };
 
 /* Audio subsystem */
@@ -267,7 +310,7 @@ static int __init n810_soc_init(void)
        int err;
        struct device *dev;
 
-       if (!machine_is_nokia_n810())
+       if (!(machine_is_nokia_n810() || machine_is_nokia_n810_wimax()))
                return -ENODEV;
 
        n810_snd_device = platform_device_alloc("soc-audio", -1);
@@ -305,12 +348,12 @@ static int __init n810_soc_init(void)
        clk_set_parent(sys_clkout2_src, func96m_clk);
        clk_set_rate(sys_clkout2, 12000000);
 
-       if (omap_request_gpio(RX44_HEADSET_AMP_GPIO) < 0)
+       if (gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0)
                BUG();
-       if (omap_request_gpio(RX44_SPEAKER_AMP_GPIO) < 0)
+       if (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0)
                BUG();
-       omap_set_gpio_direction(RX44_HEADSET_AMP_GPIO, 0);
-       omap_set_gpio_direction(RX44_SPEAKER_AMP_GPIO, 0);
+       gpio_direction_output(N810_HEADSET_AMP_GPIO, 0);
+       gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0);
 
        return 0;
 err2:
@@ -325,6 +368,9 @@ err1:
 
 static void __exit n810_soc_exit(void)
 {
+       gpio_free(N810_SPEAKER_AMP_GPIO);
+       gpio_free(N810_HEADSET_AMP_GPIO);
+
        platform_device_unregister(n810_snd_device);
 }
 
index 40d87e6..00b0c9d 100644 (file)
@@ -103,7 +103,7 @@ static const unsigned long omap2420_mcbsp_port[][2] = {};
 static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
        int err = 0;
 
@@ -116,7 +116,7 @@ static int omap_mcbsp_dai_startup(struct snd_pcm_substream *substream)
 static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
 
        if (!cpu_dai->active) {
@@ -128,7 +128,7 @@ static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream)
 static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
        int err = 0;
 
@@ -157,7 +157,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
                                    struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
        struct omap_mcbsp_reg_cfg *regs = &mcbsp_data->regs;
        int dma, bus_id = mcbsp_data->bus_id, id = cpu_dai->id;
@@ -223,7 +223,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
  * This must be called before _set_clkdiv and _set_sysclk since McBSP register
  * cache is initialized here
  */
-static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                                      unsigned int fmt)
 {
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
@@ -292,7 +292,7 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
        return 0;
 }
 
-static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
+static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai *cpu_dai,
                                     int div_id, int div)
 {
        struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
@@ -347,7 +347,7 @@ static int omap_mcbsp_dai_set_clks_src(struct omap_mcbsp_data *mcbsp_data,
        return 0;
 }
 
-static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
                                         int clk_id, unsigned int freq,
                                         int dir)
 {
@@ -376,7 +376,7 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
        return err;
 }
 
-struct snd_soc_cpu_dai omap_mcbsp_dai[NUM_LINKS] = {
+struct snd_soc_dai omap_mcbsp_dai[NUM_LINKS] = {
 {
        .name = "omap-mcbsp-dai",
        .id = 0,
index 9965fd4..ed8afb5 100644 (file)
@@ -44,6 +44,6 @@ enum omap_mcbsp_div {
  */
 #define NUM_LINKS      1
 
-extern struct snd_soc_cpu_dai omap_mcbsp_dai[NUM_LINKS];
+extern struct snd_soc_dai omap_mcbsp_dai[NUM_LINKS];
 
 #endif
index 6237020..e092f3d 100644 (file)
@@ -316,7 +316,7 @@ static void omap_pcm_free_dma_buffers(struct snd_pcm *pcm)
        }
 }
 
-int omap_pcm_new(struct snd_card *card, struct snd_soc_codec_dai *dai,
+int omap_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
                 struct snd_pcm *pcm)
 {
        int ret = 0;
index 484f883..12f6ac9 100644 (file)
@@ -1,6 +1,6 @@
 config SND_PXA2XX_SOC
        tristate "SoC Audio for the Intel PXA2xx chip"
-       depends on ARCH_PXA && SND_SOC
+       depends on ARCH_PXA
        help
          Say Y or M if you want to add support for codecs attached to
          the PXA2xx AC97, I2S or SSP interface. You will also need
@@ -62,3 +62,12 @@ config SND_PXA2XX_SOC_E800
        help
          Say Y if you want to add support for SoC audio on the
          Toshiba e800 PDA
+
+config SND_PXA2XX_SOC_EM_X270
+       tristate "SoC Audio support for CompuLab EM-x270"
+       depends on SND_PXA2XX_SOC && MACH_EM_X270
+       select SND_PXA2XX_SOC_AC97
+       select SND_SOC_WM9712
+       help
+         Say Y if you want to add support for SoC audio on
+         CompuLab EM-x270.
index 04e5646..5bc8edf 100644 (file)
@@ -13,10 +13,11 @@ snd-soc-poodle-objs := poodle.o
 snd-soc-tosa-objs := tosa.o
 snd-soc-e800-objs := e800_wm9712.o
 snd-soc-spitz-objs := spitz.o
+snd-soc-em-x270-objs := em-x270.o
 
 obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o
 obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o
 obj-$(CONFIG_SND_PXA2XX_SOC_TOSA) += snd-soc-tosa.o
 obj-$(CONFIG_SND_PXA2XX_SOC_E800) += snd-soc-e800.o
 obj-$(CONFIG_SND_PXA2XX_SOC_SPITZ) += snd-soc-spitz.o
-
+obj-$(CONFIG_SND_PXA2XX_SOC_EM_X270) += snd-soc-em-x270.o
index 7f32a11..c029446 100644 (file)
  *  under  the terms of  the GNU General  Public License as published by the
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
- *
- *  Revision history
- *    30th Nov 2005   Initial version.
- *
  */
 
 #include <linux/module.h>
@@ -54,47 +50,51 @@ static int corgi_spk_func;
 
 static void corgi_ext_control(struct snd_soc_codec *codec)
 {
-       int spk = 0, mic = 0, line = 0, hp = 0, hs = 0;
-
        /* set up jack connection */
        switch (corgi_jack_func) {
        case CORGI_HP:
-               hp = 1;
                /* set = unmute headphone */
                set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
                set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+               snd_soc_dapm_disable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
                break;
        case CORGI_MIC:
-               mic = 1;
                /* reset = mute headphone */
                reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
                reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+               snd_soc_dapm_enable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
                break;
        case CORGI_LINE:
-               line = 1;
                reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
                reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+               snd_soc_dapm_disable_pin(codec, "Mic Jack");
+               snd_soc_dapm_enable_pin(codec, "Line Jack");
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
                break;
        case CORGI_HEADSET:
-               hs = 1;
-               mic = 1;
                reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_L);
                set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_MUTE_R);
+               snd_soc_dapm_enable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_enable_pin(codec, "Headset Jack");
                break;
        }
 
        if (corgi_spk_func == CORGI_SPK_ON)
-               spk = 1;
-
-       /* set the enpoints to their new connetion states */
-       snd_soc_dapm_set_endpoint(codec, "Ext Spk", spk);
-       snd_soc_dapm_set_endpoint(codec, "Mic Jack", mic);
-       snd_soc_dapm_set_endpoint(codec, "Line Jack", line);
-       snd_soc_dapm_set_endpoint(codec, "Headphone Jack", hp);
-       snd_soc_dapm_set_endpoint(codec, "Headset Jack", hs);
+               snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       else
+               snd_soc_dapm_disable_pin(codec, "Ext Spk");
 
        /* signal a DAPM event */
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 }
 
 static int corgi_startup(struct snd_pcm_substream *substream)
@@ -123,8 +123,8 @@ static int corgi_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        unsigned int clk = 0;
        int ret = 0;
 
@@ -143,25 +143,25 @@ static int corgi_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8731_SYSCLK, clk,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK, clk,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* set the I2S system clock as input (unused) */
-       ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
+       ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
@@ -247,7 +247,7 @@ SND_SOC_DAPM_HP("Headset Jack", NULL),
 };
 
 /* Corgi machine audio map (connections to the codec pins) */
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
 
        /* headset Jack  - in = micin, out = LHPOUT*/
        {"Headset Jack", NULL, "LHPOUT"},
@@ -265,8 +265,6 @@ static const char *audio_map[][3] = {
 
        /* Same as the above but no mic bias for line signals */
        {"MICIN", NULL, "Line Jack"},
-
-       {NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
@@ -291,8 +289,8 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
 {
        int i, err;
 
-       snd_soc_dapm_set_endpoint(codec, "LLINEIN", 0);
-       snd_soc_dapm_set_endpoint(codec, "RLINEIN", 0);
+       snd_soc_dapm_disable_pin(codec, "LLINEIN");
+       snd_soc_dapm_disable_pin(codec, "RLINEIN");
 
        /* Add corgi specific controls */
        for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
@@ -303,15 +301,13 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
        }
 
        /* Add corgi specific widgets */
-       for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
+                                 ARRAY_SIZE(wm8731_dapm_widgets));
 
        /* Set up corgi specific audio path audio_map */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
diff --git a/sound/soc/pxa/em-x270.c b/sound/soc/pxa/em-x270.c
new file mode 100644 (file)
index 0000000..02dcac3
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * em-x270.c  --  SoC audio for EM-X270
+ *
+ * Copyright 2007 CompuLab, Ltd.
+ *
+ * Author: Mike Rapoport <mike@compulab.co.il>
+ *
+ * Copied from tosa.c:
+ * Copyright 2005 Wolfson Microelectronics PLC.
+ * Copyright 2005 Openedhand Ltd.
+ *
+ * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ *          Richard Purdie <richard@openedhand.com>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/device.h>
+
+#include <sound/driver.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/mach-types.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/audio.h>
+
+#include "../codecs/wm9712.h"
+#include "pxa2xx-pcm.h"
+#include "pxa2xx-ac97.h"
+
+static struct snd_soc_dai_link em_x270_dai[] = {
+       {
+               .name = "AC97",
+               .stream_name = "AC97 HiFi",
+               .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
+               .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
+       },
+       {
+               .name = "AC97 Aux",
+               .stream_name = "AC97 Aux",
+               .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
+               .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
+       },
+};
+
+static struct snd_soc_machine em_x270 = {
+       .name = "EM-X270",
+       .dai_link = em_x270_dai,
+       .num_links = ARRAY_SIZE(em_x270_dai),
+};
+
+static struct snd_soc_device em_x270_snd_devdata = {
+       .machine = &em_x270,
+       .platform = &pxa2xx_soc_platform,
+       .codec_dev = &soc_codec_dev_wm9712,
+};
+
+static struct platform_device *em_x270_snd_device;
+
+static int __init em_x270_init(void)
+{
+       int ret;
+
+       if (!machine_is_em_x270())
+               return -ENODEV;
+
+       em_x270_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!em_x270_snd_device)
+               return -ENOMEM;
+
+       platform_set_drvdata(em_x270_snd_device, &em_x270_snd_devdata);
+       em_x270_snd_devdata.dev = &em_x270_snd_device->dev;
+       ret = platform_device_add(em_x270_snd_device);
+
+       if (ret)
+               platform_device_put(em_x270_snd_device);
+
+       return ret;
+}
+
+static void __exit em_x270_exit(void)
+{
+       platform_device_unregister(em_x270_snd_device);
+}
+
+module_init(em_x270_init);
+module_exit(em_x270_exit);
+
+/* Module information */
+MODULE_AUTHOR("Mike Rapoport");
+MODULE_DESCRIPTION("ALSA SoC EM-X270");
+MODULE_LICENSE("GPL");
index 7e830b2..65a4e9a 100644 (file)
@@ -48,8 +48,6 @@ static int poodle_spk_func;
 
 static void poodle_ext_control(struct snd_soc_codec *codec)
 {
-       int spk = 0;
-
        /* set up jack connection */
        if (poodle_jack_func == POODLE_HP) {
                /* set = unmute headphone */
@@ -57,23 +55,23 @@ static void poodle_ext_control(struct snd_soc_codec *codec)
                        POODLE_LOCOMO_GPIO_MUTE_L, 1);
                locomo_gpio_write(&poodle_locomo_device.dev,
                        POODLE_LOCOMO_GPIO_MUTE_R, 1);
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
+               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
        } else {
                locomo_gpio_write(&poodle_locomo_device.dev,
                        POODLE_LOCOMO_GPIO_MUTE_L, 0);
                locomo_gpio_write(&poodle_locomo_device.dev,
                        POODLE_LOCOMO_GPIO_MUTE_R, 0);
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
        }
 
-       if (poodle_spk_func == POODLE_SPK_ON)
-               spk = 1;
-
        /* set the enpoints to their new connetion states */
-       snd_soc_dapm_set_endpoint(codec, "Ext Spk", spk);
+       if (poodle_spk_func == POODLE_SPK_ON)
+               snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       else
+               snd_soc_dapm_disable_pin(codec, "Ext Spk");
 
        /* signal a DAPM event */
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 }
 
 static int poodle_startup(struct snd_pcm_substream *substream)
@@ -104,8 +102,8 @@ static int poodle_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        unsigned int clk = 0;
        int ret = 0;
 
@@ -124,25 +122,25 @@ static int poodle_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8731_SYSCLK, clk,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK, clk,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* set the I2S system clock as input (unused) */
-       ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
+       ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
@@ -215,8 +213,8 @@ SND_SOC_DAPM_HP("Headphone Jack", NULL),
 SND_SOC_DAPM_SPK("Ext Spk", poodle_amp_event),
 };
 
-/* Corgi machine audio_mapnections to the codec pins */
-static const char *audio_map[][3] = {
+/* Corgi machine connections to the codec pins */
+static const struct snd_soc_dapm_route audio_map[] = {
 
        /* headphone connected to LHPOUT1, RHPOUT1 */
        {"Headphone Jack", NULL, "LHPOUT"},
@@ -225,8 +223,6 @@ static const char *audio_map[][3] = {
        /* speaker connected to LOUT, ROUT */
        {"Ext Spk", NULL, "ROUT"},
        {"Ext Spk", NULL, "LOUT"},
-
-       {NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Off", "Headphone"};
@@ -250,9 +246,9 @@ static int poodle_wm8731_init(struct snd_soc_codec *codec)
 {
        int i, err;
 
-       snd_soc_dapm_set_endpoint(codec, "LLINEIN", 0);
-       snd_soc_dapm_set_endpoint(codec, "RLINEIN", 0);
-       snd_soc_dapm_set_endpoint(codec, "MICIN", 1);
+       snd_soc_dapm_disable_pin(codec, "LLINEIN");
+       snd_soc_dapm_disable_pin(codec, "RLINEIN");
+       snd_soc_dapm_enable_pin(codec, "MICIN");
 
        /* Add poodle specific controls */
        for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) {
@@ -263,15 +259,13 @@ static int poodle_wm8731_init(struct snd_soc_codec *codec)
        }
 
        /* Add poodle specific widgets */
-       for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
+                                 ARRAY_SIZE(wm8731_dapm_widgets));
 
        /* Set up poodle specific audio path audio_map */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
index 97ec2d9..059af81 100644 (file)
@@ -283,7 +283,7 @@ static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_mic_mono_in = {
 
 #ifdef CONFIG_PM
 static int pxa2xx_ac97_suspend(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        GCR |= GCR_ACLINK_OFF;
        clk_disable(ac97_clk);
@@ -291,7 +291,7 @@ static int pxa2xx_ac97_suspend(struct platform_device *pdev,
 }
 
 static int pxa2xx_ac97_resume(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
        pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
@@ -310,7 +310,8 @@ static int pxa2xx_ac97_resume(struct platform_device *pdev,
 #define pxa2xx_ac97_resume     NULL
 #endif
 
-static int pxa2xx_ac97_probe(struct platform_device *pdev)
+static int pxa2xx_ac97_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
 {
        int ret;
 
@@ -355,7 +356,8 @@ static int pxa2xx_ac97_probe(struct platform_device *pdev)
        return ret;
 }
 
-static void pxa2xx_ac97_remove(struct platform_device *pdev)
+static void pxa2xx_ac97_remove(struct platform_device *pdev,
+                              struct snd_soc_dai *dai)
 {
        GCR |= GCR_ACLINK_OFF;
        free_irq(IRQ_AC97, NULL);
@@ -372,7 +374,7 @@ static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
                                struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                cpu_dai->dma_data = &pxa2xx_ac97_pcm_stereo_out;
@@ -386,7 +388,7 @@ static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                cpu_dai->dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
@@ -400,7 +402,7 @@ static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                return -ENODEV;
@@ -418,7 +420,7 @@ static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
  * There is only 1 physical AC97 interface for pxa2xx, but it
  * has extra fifo's that can be used for aux DACs and ADCs.
  */
-struct snd_soc_cpu_dai pxa_ac97_dai[] = {
+struct snd_soc_dai pxa_ac97_dai[] = {
 {
        .name = "pxa2xx-ac97",
        .id = 0,
index b8ccfee..e390de8 100644 (file)
@@ -14,7 +14,7 @@
 #define PXA2XX_DAI_AC97_AUX            1
 #define PXA2XX_DAI_AC97_MIC            2
 
-extern struct snd_soc_cpu_dai pxa_ac97_dai[3];
+extern struct snd_soc_dai pxa_ac97_dai[3];
 
 /* platform data */
 extern struct snd_ac97_bus_ops pxa2xx_ac97_ops;
index 4250710..8f96d87 100644 (file)
@@ -9,15 +9,13 @@
  *  under  the terms of  the GNU General  Public License as published by the
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
- *
- *  Revision history
- *    12th Aug 2005   Initial version.
  */
 
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/delay.h>
+#include <linux/clk.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/initval.h>
@@ -40,6 +38,7 @@ struct pxa_i2s_port {
        u32 fmt;
 };
 static struct pxa_i2s_port pxa_i2s;
+static struct clk *clk_i2s;
 
 static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_out = {
        .name                   = "I2S PCM Stereo out",
@@ -80,7 +79,11 @@ static struct pxa2xx_gpio gpio_bus[] = {
 static int pxa2xx_i2s_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+
+       clk_i2s = clk_get(NULL, "I2SCLK");
+       if (IS_ERR(clk_i2s))
+               return PTR_ERR(clk_i2s);
 
        if (!cpu_dai->active) {
                SACR0 |= SACR0_RST;
@@ -101,7 +104,7 @@ static int pxa_i2s_wait(void)
        return 0;
 }
 
-static int pxa2xx_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int pxa2xx_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                unsigned int fmt)
 {
        /* interface format */
@@ -127,7 +130,7 @@ static int pxa2xx_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
        return 0;
 }
 
-static int pxa2xx_i2s_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int pxa2xx_i2s_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
                int clk_id, unsigned int freq, int dir)
 {
        if (clk_id != PXA2XX_I2S_SYSCLK)
@@ -143,13 +146,13 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
                                struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        pxa_gpio_mode(gpio_bus[pxa_i2s.master].rx);
        pxa_gpio_mode(gpio_bus[pxa_i2s.master].tx);
        pxa_gpio_mode(gpio_bus[pxa_i2s.master].frm);
        pxa_gpio_mode(gpio_bus[pxa_i2s.master].clk);
-       pxa_set_cken(CKEN_I2S, 1);
+       clk_enable(clk_i2s);
        pxa_i2s_wait();
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -234,13 +237,15 @@ static void pxa2xx_i2s_shutdown(struct snd_pcm_substream *substream)
        if (SACR1 & (SACR1_DREC | SACR1_DRPL)) {
                SACR0 &= ~SACR0_ENB;
                pxa_i2s_wait();
-               pxa_set_cken(CKEN_I2S, 0);
+               clk_disable(clk_i2s);
        }
+
+       clk_put(clk_i2s);
 }
 
 #ifdef CONFIG_PM
 static int pxa2xx_i2s_suspend(struct platform_device *dev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        if (!dai->active)
                return 0;
@@ -258,7 +263,7 @@ static int pxa2xx_i2s_suspend(struct platform_device *dev,
 }
 
 static int pxa2xx_i2s_resume(struct platform_device *pdev,
-       struct snd_soc_cpu_dai *dai)
+       struct snd_soc_dai *dai)
 {
        if (!dai->active)
                return 0;
@@ -283,7 +288,7 @@ static int pxa2xx_i2s_resume(struct platform_device *pdev,
                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
                SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
 
-struct snd_soc_cpu_dai pxa_i2s_dai = {
+struct snd_soc_dai pxa_i2s_dai = {
        .name = "pxa2xx-i2s",
        .id = 0,
        .type = SND_SOC_DAI_I2S,
index 4435bd9..e2def44 100644 (file)
@@ -15,6 +15,6 @@
 /* I2S clock */
 #define PXA2XX_I2S_SYSCLK              0
 
-extern struct snd_soc_cpu_dai pxa_i2s_dai;
+extern struct snd_soc_dai pxa_i2s_dai;
 
 #endif
index 01ad7bf..2df03ee 100644 (file)
@@ -330,7 +330,7 @@ static void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
 
 static u64 pxa2xx_pcm_dmamask = DMA_32BIT_MASK;
 
-int pxa2xx_pcm_new(struct snd_card *card, struct snd_soc_codec_dai *dai,
+int pxa2xx_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
        struct snd_pcm *pcm)
 {
        int ret = 0;
index d8b8372..6438579 100644 (file)
@@ -12,9 +12,6 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    30th Nov 2005   Initial version.
- *
  */
 
 #include <linux/module.h>
@@ -54,60 +51,60 @@ static int spitz_spk_func;
 static void spitz_ext_control(struct snd_soc_codec *codec)
 {
        if (spitz_spk_func == SPITZ_SPK_ON)
-               snd_soc_dapm_set_endpoint(codec, "Ext Spk", 1);
+               snd_soc_dapm_enable_pin(codec, "Ext Spk");
        else
-               snd_soc_dapm_set_endpoint(codec, "Ext Spk", 0);
+               snd_soc_dapm_disable_pin(codec, "Ext Spk");
 
        /* set up jack connection */
        switch (spitz_jack_func) {
        case SPITZ_HP:
                /* enable and unmute hp jack, disable mic bias */
-               snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
                set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
                set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
                break;
        case SPITZ_MIC:
                /* enable mic jack and bias, mute hp */
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_enable_pin(codec, "Mic Jack");
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
                break;
        case SPITZ_LINE:
                /* enable line jack, disable mic bias and mute hp */
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Line Jack", 1);
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(codec, "Mic Jack");
+               snd_soc_dapm_enable_pin(codec, "Line Jack");
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
                break;
        case SPITZ_HEADSET:
                /* enable and unmute headset jack enable mic bias, mute L hp */
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
-               snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Jack", 1);
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_enable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
+               snd_soc_dapm_enable_pin(codec, "Headset Jack");
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
                set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
                break;
        case SPITZ_HP_OFF:
 
                /* jack removed, everything off */
-               snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
-               snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(codec, "Mic Jack");
+               snd_soc_dapm_disable_pin(codec, "Line Jack");
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
                reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
                break;
        }
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 }
 
 static int spitz_startup(struct snd_pcm_substream *substream)
@@ -124,8 +121,8 @@ static int spitz_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        unsigned int clk = 0;
        int ret = 0;
 
@@ -144,25 +141,25 @@ static int spitz_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8750_SYSCLK, clk,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* set the I2S system clock as input (unused) */
-       ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
+       ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
@@ -250,7 +247,7 @@ static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
 };
 
 /* Spitz machine audio_map */
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
 
        /* headphone connected to LOUT1, ROUT1 */
        {"Headphone Jack", NULL, "LOUT1"},
@@ -269,8 +266,6 @@ static const char *audio_map[][3] = {
 
        /* line is connected to input 1 - no bias */
        {"LINPUT1", NULL, "Line Jack"},
-
-       {NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
@@ -296,13 +291,13 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
        int i, err;
 
        /* NC codec pins */
-       snd_soc_dapm_set_endpoint(codec, "RINPUT1", 0);
-       snd_soc_dapm_set_endpoint(codec, "LINPUT2", 0);
-       snd_soc_dapm_set_endpoint(codec, "RINPUT2", 0);
-       snd_soc_dapm_set_endpoint(codec, "LINPUT3", 0);
-       snd_soc_dapm_set_endpoint(codec, "RINPUT3", 0);
-       snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
-       snd_soc_dapm_set_endpoint(codec, "MONO", 0);
+       snd_soc_dapm_disable_pin(codec, "RINPUT1");
+       snd_soc_dapm_disable_pin(codec, "LINPUT2");
+       snd_soc_dapm_disable_pin(codec, "RINPUT2");
+       snd_soc_dapm_disable_pin(codec, "LINPUT3");
+       snd_soc_dapm_disable_pin(codec, "RINPUT3");
+       snd_soc_dapm_disable_pin(codec, "OUT3");
+       snd_soc_dapm_disable_pin(codec, "MONO");
 
        /* Add spitz specific controls */
        for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) {
@@ -313,15 +308,13 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
        }
 
        /* Add spitz specific widgets */
-       for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
+                                 ARRAY_SIZE(wm8750_dapm_widgets));
 
-       /* Set up spitz specific audio path audio_map */
-       for (i = 0; audio_map[i][0] != NULL; i++)
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
+       /* Set up spitz specific audio paths */
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
index 7346d7e..b6edb61 100644 (file)
@@ -12,9 +12,6 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    30th Nov 2005   Initial version.
- *
  * GPIO's
  *  1 - Jack Insertion
  *  5 - Hookswitch (headset answer/hang up switch)
@@ -55,29 +52,31 @@ static int tosa_spk_func;
 
 static void tosa_ext_control(struct snd_soc_codec *codec)
 {
-       int spk = 0, mic_int = 0, hp = 0, hs = 0;
-
        /* set up jack connection */
        switch (tosa_jack_func) {
        case TOSA_HP:
-               hp = 1;
+               snd_soc_dapm_disable_pin(codec, "Mic (Internal)");
+               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
                break;
        case TOSA_MIC_INT:
-               mic_int = 1;
+               snd_soc_dapm_enable_pin(codec, "Mic (Internal)");
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_disable_pin(codec, "Headset Jack");
                break;
        case TOSA_HEADSET:
-               hs = 1;
+               snd_soc_dapm_disable_pin(codec, "Mic (Internal)");
+               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
+               snd_soc_dapm_enable_pin(codec, "Headset Jack");
                break;
        }
 
        if (tosa_spk_func == TOSA_SPK_ON)
-               spk = 1;
+               snd_soc_dapm_enable_pin(codec, "Speaker");
+       else
+               snd_soc_dapm_disable_pin(codec, "Speaker");
 
-       snd_soc_dapm_set_endpoint(codec, "Speaker", spk);
-       snd_soc_dapm_set_endpoint(codec, "Mic (Internal)", mic_int);
-       snd_soc_dapm_set_endpoint(codec, "Headphone Jack", hp);
-       snd_soc_dapm_set_endpoint(codec, "Headset Jack", hs);
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 }
 
 static int tosa_startup(struct snd_pcm_substream *substream)
@@ -154,7 +153,7 @@ SND_SOC_DAPM_SPK("Speaker", NULL),
 };
 
 /* tosa audio map */
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route audio_map[] = {
 
        /* headphone connected to HPOUTL, HPOUTR */
        {"Headphone Jack", NULL, "HPOUTL"},
@@ -173,8 +172,6 @@ static const char *audio_map[][3] = {
        {"Headset Jack", NULL, "HPOUTR"},
        {"LINEINR", NULL, "Mic Bias"},
        {"Mic Bias", NULL, "Headset Jack"},
-
-       {NULL, NULL, NULL},
 };
 
 static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
@@ -196,8 +193,8 @@ static int tosa_ac97_init(struct snd_soc_codec *codec)
 {
        int i, err;
 
-       snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
-       snd_soc_dapm_set_endpoint(codec, "MONOOUT", 0);
+       snd_soc_dapm_disable_pin(codec, "OUT3");
+       snd_soc_dapm_disable_pin(codec, "MONOOUT");
 
        /* add tosa specific controls */
        for (i = 0; i < ARRAY_SIZE(tosa_controls); i++) {
@@ -208,17 +205,13 @@ static int tosa_ac97_init(struct snd_soc_codec *codec)
        }
 
        /* add tosa specific widgets */
-       for (i = 0; i < ARRAY_SIZE(tosa_dapm_widgets); i++) {
-               snd_soc_dapm_new_control(codec, &tosa_dapm_widgets[i]);
-       }
+       snd_soc_dapm_new_controls(codec, tosa_dapm_widgets,
+                                 ARRAY_SIZE(tosa_dapm_widgets));
 
        /* set up tosa specific audio path audio_map */
-       for (i = 0; audio_map[i][0] != NULL; i++) {
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
-       }
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
index 1f6dbfc..b9f2353 100644 (file)
@@ -1,7 +1,6 @@
 config SND_S3C24XX_SOC
        tristate "SoC Audio for the Samsung S3C24XX chips"
-       depends on ARCH_S3C2410 && SND_SOC
-       select SND_PCM
+       depends on ARCH_S3C2410
        help
          Say Y or M if you want to add support for codecs attached to
          the S3C24XX AC97, I2S or SSP interface. You will also need
@@ -16,7 +15,6 @@ config SND_S3C2412_SOC_I2S
 config SND_S3C2443_SOC_AC97
        tristate
        select AC97_BUS
-       select SND_AC97_CODEC
        select SND_SOC_AC97_BUS
        
 config SND_S3C24XX_SOC_NEO1973_WM8753
index 0e9d1c5..4d7a9aa 100644 (file)
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    20th Jan 2007   Initial version.
- *    05th Feb 2007   Rename all to Neo1973
- *
  */
 
 #include <linux/module.h>
@@ -26,6 +22,7 @@
 #include <sound/pcm.h>
 #include <sound/soc.h>
 #include <sound/soc-dapm.h>
+#include <sound/tlv.h>
 
 #include <asm/mach-types.h>
 #include <asm/hardware/scoop.h>
 #include "s3c24xx-pcm.h"
 #include "s3c24xx-i2s.h"
 
+/* Debugging stuff */
+#define S3C24XX_SOC_NEO1973_WM8753_DEBUG 0
+#if S3C24XX_SOC_NEO1973_WM8753_DEBUG
+#define DBG(x...) printk(KERN_DEBUG "s3c24xx-soc-neo1973-wm8753: " x)
+#else
+#define DBG(x...)
+#endif
+
 /* define the scenarios */
 #define NEO_AUDIO_OFF                  0
 #define NEO_GSM_CALL_AUDIO_HANDSET     1
@@ -61,12 +66,14 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
        unsigned int pll_out = 0, bclk = 0;
        int ret = 0;
        unsigned long iis_clkrate;
 
+       DBG("Entered %s\n", __func__);
+
        iis_clkrate = s3c24xx_i2s_get_clockrate();
 
        switch (params_rate(params)) {
@@ -101,44 +108,44 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
        }
 
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai,
+       ret = snd_soc_dai_set_fmt(codec_dai,
                SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
                SND_SOC_DAIFMT_CBM_CFM);
        if (ret < 0)
                return ret;
 
        /* set cpu DAI configuration */
-       ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
+       ret = snd_soc_dai_set_fmt(cpu_dai,
                SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
                SND_SOC_DAIFMT_CBM_CFM);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_MCLK, pll_out,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* set MCLK division for sample rate */
-       ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
+       ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
                S3C2410_IISMOD_32FS);
        if (ret < 0)
                return ret;
 
        /* set codec BCLK division for sample rate */
-       ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
+       ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_BCLKDIV, bclk);
        if (ret < 0)
                return ret;
 
        /* set prescaler division for sample rate */
-       ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
+       ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
                S3C24XX_PRESCALE(4, 4));
        if (ret < 0)
                return ret;
 
        /* codec PLL input is PCLK/4 */
-       ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1,
+       ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL1,
                iis_clkrate / 4, pll_out);
        if (ret < 0)
                return ret;
@@ -149,10 +156,12 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
 static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+
+       DBG("Entered %s\n", __func__);
 
        /* disable the PLL */
-       return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL1, 0, 0);
+       return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0);
 }
 
 /*
@@ -167,11 +176,13 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
        unsigned int pcmdiv = 0;
        int ret = 0;
        unsigned long iis_clkrate;
 
+       DBG("Entered %s\n", __func__);
+
        iis_clkrate = s3c24xx_i2s_get_clockrate();
 
        if (params_rate(params) != 8000)
@@ -183,24 +194,24 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
 
        /* todo: gg check mode (DSP_B) against CSR datasheet */
        /* set codec DAI configuration */
-       ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
                SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
        if (ret < 0)
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = codec_dai->dai_ops.set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
 
        /* set codec PCM division for sample rate */
-       ret = codec_dai->dai_ops.set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
+       ret = snd_soc_dai_set_clkdiv(codec_dai, WM8753_PCMDIV, pcmdiv);
        if (ret < 0)
                return ret;
 
        /* configue and enable PLL for 12.288MHz output */
-       ret = codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2,
+       ret = snd_soc_dai_set_pll(codec_dai, WM8753_PLL2,
                iis_clkrate / 4, 12288000);
        if (ret < 0)
                return ret;
@@ -211,10 +222,12 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
 static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+
+       DBG("Entered %s\n", __func__);
 
        /* disable the PLL */
-       return codec_dai->dai_ops.set_pll(codec_dai, WM8753_PLL2, 0, 0);
+       return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0);
 }
 
 static struct snd_soc_ops neo1973_voice_ops = {
@@ -233,79 +246,81 @@ static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
 
 static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
 {
+       DBG("Entered %s\n", __func__);
+
        switch (neo1973_scenario) {
        case NEO_AUDIO_OFF:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_GSM_CALL_AUDIO_HANDSET:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     1);
+               snd_soc_dapm_enable_pin(codec, "Audio Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_enable_pin(codec, "Call Mic");
                break;
        case NEO_GSM_CALL_AUDIO_HEADSET:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  1);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_enable_pin(codec, "Audio Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line In");
+               snd_soc_dapm_enable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_GSM_CALL_AUDIO_BLUETOOTH:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  1);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_enable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_STEREO_TO_SPEAKERS:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_enable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_STEREO_TO_HEADPHONES:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    1);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_enable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_CAPTURE_HANDSET:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     1);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_enable_pin(codec, "Call Mic");
                break;
        case NEO_CAPTURE_HEADSET:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  1);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_enable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        case NEO_CAPTURE_BLUETOOTH:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
                break;
        default:
-               snd_soc_dapm_set_endpoint(codec, "Audio Out",    0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
-               snd_soc_dapm_set_endpoint(codec, "GSM Line In",  0);
-               snd_soc_dapm_set_endpoint(codec, "Headset Mic",  0);
-               snd_soc_dapm_set_endpoint(codec, "Call Mic",     0);
+               snd_soc_dapm_disable_pin(codec, "Audio Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line Out");
+               snd_soc_dapm_disable_pin(codec, "GSM Line In");
+               snd_soc_dapm_disable_pin(codec, "Headset Mic");
+               snd_soc_dapm_disable_pin(codec, "Call Mic");
        }
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
 
        return 0;
 }
@@ -315,6 +330,8 @@ static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
 
+       DBG("Entered %s\n", __func__);
+
        if (neo1973_scenario == ucontrol->value.integer.value[0])
                return 0;
 
@@ -327,6 +344,8 @@ static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
 
 static void lm4857_write_regs(void)
 {
+       DBG("Entered %s\n", __func__);
+
        if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
                printk(KERN_ERR "lm4857: i2c write failed\n");
 }
@@ -338,6 +357,8 @@ static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
        int shift = (kcontrol->private_value >> 8) & 0x0F;
        int mask = (kcontrol->private_value >> 16) & 0xFF;
 
+       DBG("Entered %s\n", __func__);
+
        ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
        return 0;
 }
@@ -364,6 +385,8 @@ static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
 {
        u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
 
+       DBG("Entered %s\n", __func__);
+
        if (value)
                value -= 5;
 
@@ -376,6 +399,8 @@ static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
 {
        u8 value = ucontrol->value.integer.value[0];
 
+       DBG("Entered %s\n", __func__);
+
        if (value)
                value += 5;
 
@@ -397,8 +422,7 @@ static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
 };
 
 
-/* example machine audio_mapnections */
-static const char *audio_map[][3] = {
+static const struct snd_soc_dapm_route dapm_routes[] = {
 
        /* Connections to the lm4857 amp */
        {"Audio Out", NULL, "LOUT1"},
@@ -421,8 +445,6 @@ static const char *audio_map[][3] = {
 
        /* Connect the ALC pins */
        {"ACIN", NULL, "ACOP"},
-
-       {NULL, NULL, NULL},
 };
 
 static const char *lm4857_mode[] = {
@@ -453,13 +475,16 @@ static const struct soc_enum neo_scenario_enum[] = {
        SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
 };
 
+static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0);
+static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0);
+
 static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
-       SOC_SINGLE_EXT("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
-               lm4857_get_reg, lm4857_set_reg),
-       SOC_SINGLE_EXT("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
-               lm4857_get_reg, lm4857_set_reg),
-       SOC_SINGLE_EXT("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
-               lm4857_get_reg, lm4857_set_reg),
+       SOC_SINGLE_EXT_TLV("Amp Left Playback Volume", LM4857_LVOL, 0, 31, 0,
+               lm4857_get_reg, lm4857_set_reg, stereo_tlv),
+       SOC_SINGLE_EXT_TLV("Amp Right Playback Volume", LM4857_RVOL, 0, 31, 0,
+               lm4857_get_reg, lm4857_set_reg, stereo_tlv),
+       SOC_SINGLE_EXT_TLV("Amp Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
+               lm4857_get_reg, lm4857_set_reg, mono_tlv),
        SOC_ENUM_EXT("Amp Mode", lm4857_mode_enum[0],
                lm4857_get_mode, lm4857_set_mode),
        SOC_ENUM_EXT("Neo Mode", neo_scenario_enum[0],
@@ -483,21 +508,23 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec)
 {
        int i, err;
 
+       DBG("Entered %s\n", __func__);
+
        /* set up NC codec pins */
-       snd_soc_dapm_set_endpoint(codec, "LOUT2", 0);
-       snd_soc_dapm_set_endpoint(codec, "ROUT2", 0);
-       snd_soc_dapm_set_endpoint(codec, "OUT3",  0);
-       snd_soc_dapm_set_endpoint(codec, "OUT4",  0);
-       snd_soc_dapm_set_endpoint(codec, "LINE1", 0);
-       snd_soc_dapm_set_endpoint(codec, "LINE2", 0);
+       snd_soc_dapm_disable_pin(codec, "LOUT2");
+       snd_soc_dapm_disable_pin(codec, "ROUT2");
+       snd_soc_dapm_disable_pin(codec, "OUT3");
+       snd_soc_dapm_disable_pin(codec, "OUT4");
+       snd_soc_dapm_disable_pin(codec, "LINE1");
+       snd_soc_dapm_disable_pin(codec, "LINE2");
 
 
        /* set endpoints to default mode */
        set_scenario_endpoints(codec, NEO_AUDIO_OFF);
 
        /* Add neo1973 specific widgets */
-       for (i = 0; i < ARRAY_SIZE(wm8753_dapm_widgets); i++)
-               snd_soc_dapm_new_control(codec, &wm8753_dapm_widgets[i]);
+       snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets,
+                                 ARRAY_SIZE(wm8753_dapm_widgets));
 
        /* add neo1973 specific controls */
        for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) {
@@ -508,20 +535,18 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec)
                        return err;
        }
 
-       /* set up neo1973 specific audio path audio_mapnects */
-       for (i = 0; audio_map[i][0] != NULL; i++) {
-               snd_soc_dapm_connect_input(codec, audio_map[i][0],
-                       audio_map[i][1], audio_map[i][2]);
-       }
+       /* set up neo1973 specific audio routes */
+       err = snd_soc_dapm_add_routes(codec, dapm_routes,
+                                     ARRAY_SIZE(dapm_routes));
 
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
 /*
  * BT Codec DAI
  */
-static struct snd_soc_cpu_dai bt_dai = {
+static struct snd_soc_dai bt_dai = {
        .name = "Bluetooth",
        .id = 0,
        .type = SND_SOC_DAI_PCM,
@@ -583,6 +608,8 @@ static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind)
 {
        int ret;
 
+       DBG("Entered %s\n", __func__);
+
        client_template.adapter = adap;
        client_template.addr = addr;
 
@@ -606,6 +633,8 @@ exit_err:
 
 static int lm4857_i2c_detach(struct i2c_client *client)
 {
+       DBG("Entered %s\n", __func__);
+
        i2c_detach_client(client);
        kfree(client);
        return 0;
@@ -613,6 +642,8 @@ static int lm4857_i2c_detach(struct i2c_client *client)
 
 static int lm4857_i2c_attach(struct i2c_adapter *adap)
 {
+       DBG("Entered %s\n", __func__);
+
        return i2c_probe(adap, &addr_data, lm4857_amp_probe);
 }
 
@@ -620,6 +651,8 @@ static u8 lm4857_state;
 
 static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
 {
+       DBG("Entered %s\n", __func__);
+
        dev_dbg(&dev->dev, "lm4857_suspend\n");
        lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
        if (lm4857_state) {
@@ -631,6 +664,8 @@ static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
 
 static int lm4857_resume(struct i2c_client *dev)
 {
+       DBG("Entered %s\n", __func__);
+
        if (lm4857_state) {
                lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
                lm4857_write_regs();
@@ -640,6 +675,8 @@ static int lm4857_resume(struct i2c_client *dev)
 
 static void lm4857_shutdown(struct i2c_client *dev)
 {
+       DBG("Entered %s\n", __func__);
+
        dev_dbg(&dev->dev, "lm4857_shutdown\n");
        lm4857_regs[LM4857_CTRL] &= 0xf0;
        lm4857_write_regs();
@@ -671,6 +708,8 @@ static int __init neo1973_init(void)
 {
        int ret;
 
+       DBG("Entered %s\n", __func__);
+
        neo1973_snd_device = platform_device_alloc("soc-audio", -1);
        if (!neo1973_snd_device)
                return -ENOMEM;
@@ -691,6 +730,8 @@ static int __init neo1973_init(void)
 
 static void __exit neo1973_exit(void)
 {
+       DBG("Entered %s\n", __func__);
+
        i2c_del_driver(&lm4857_i2c_driver);
        platform_device_unregister(neo1973_snd_device);
 }
index c4a46dd..ee4676e 100644 (file)
@@ -295,7 +295,7 @@ static inline int s3c2412_snd_is_clkmaster(void)
 /*
  * Set S3C2412 I2S DAI format
  */
-static int s3c2412_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
                               unsigned int fmt)
 {
        u32 iismod;
@@ -500,7 +500,7 @@ EXPORT_SYMBOL_GPL(s3c2412_iis_calc_rate);
 /*
  * Set S3C2412 Clock source
  */
-static int s3c2412_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
                                  int clk_id, unsigned int freq, int dir)
 {
        u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
@@ -528,7 +528,7 @@ static int s3c2412_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
 /*
  * Set S3C2412 Clock dividers
  */
-static int s3c2412_i2s_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
                                  int div_id, int div)
 {
        struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
@@ -601,7 +601,8 @@ struct clk *s3c2412_get_iisclk(void)
 EXPORT_SYMBOL_GPL(s3c2412_get_iisclk);
 
 
-static int s3c2412_i2s_probe(struct platform_device *pdev)
+static int s3c2412_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
 {
        DBG("Entered %s\n", __func__);
 
@@ -647,7 +648,7 @@ static int s3c2412_i2s_probe(struct platform_device *pdev)
 
 #ifdef CONFIG_PM
 static int s3c2412_i2s_suspend(struct platform_device *dev,
-                             struct snd_soc_cpu_dai *dai)
+                             struct snd_soc_dai *dai)
 {
        struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
        u32 iismod;
@@ -675,7 +676,7 @@ static int s3c2412_i2s_suspend(struct platform_device *dev,
 }
 
 static int s3c2412_i2s_resume(struct platform_device *pdev,
-                             struct snd_soc_cpu_dai *dai)
+                             struct snd_soc_dai *dai)
 {
        struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
 
@@ -707,7 +708,7 @@ static int s3c2412_i2s_resume(struct platform_device *pdev,
        SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
        SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
 
-struct snd_soc_cpu_dai s3c2412_i2s_dai = {
+struct snd_soc_dai s3c2412_i2s_dai = {
        .name   = "s3c2412-i2s",
        .id     = 0,
        .type   = SND_SOC_DAI_I2S,
index 27f48e1..aac08a2 100644 (file)
@@ -24,7 +24,7 @@
 
 extern struct clk *s3c2412_get_iisclk(void);
 
-extern struct snd_soc_cpu_dai s3c2412_i2s_dai;
+extern struct snd_soc_dai s3c2412_i2s_dai;
 
 struct s3c2412_rate_calc {
        unsigned int    clk_div;        /* for prescaler */
index e81d9a6..783349b 100644 (file)
@@ -10,9 +10,6 @@
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
  *  published by the Free Software Foundation.
- *
- *  Revision history
- *     21st Mar 2007   Initial Version
  */
 
 #include <linux/init.h>
@@ -212,7 +209,8 @@ static struct s3c24xx_pcm_dma_params s3c2443_ac97_mic_mono_in = {
        .dma_size       = 4,
 };
 
-static int s3c2443_ac97_probe(struct platform_device *pdev)
+static int s3c2443_ac97_probe(struct platform_device *pdev,
+                             struct snd_soc_dai *dai)
 {
        int ret;
        u32 ac_glbctrl;
@@ -263,7 +261,8 @@ static int s3c2443_ac97_probe(struct platform_device *pdev)
        return ret;
 }
 
-static void s3c2443_ac97_remove(struct platform_device *pdev)
+static void s3c2443_ac97_remove(struct platform_device *pdev,
+                               struct snd_soc_dai *dai)
 {
        free_irq(IRQ_S3C244x_AC97, NULL);
        clk_disable(s3c24xx_ac97.ac97_clk);
@@ -275,7 +274,7 @@ static int s3c2443_ac97_hw_params(struct snd_pcm_substream *substream,
                                struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                cpu_dai->dma_data = &s3c2443_ac97_pcm_stereo_out;
@@ -317,7 +316,7 @@ static int s3c2443_ac97_hw_mic_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                return -ENODEV;
@@ -353,7 +352,7 @@ static int s3c2443_ac97_mic_trigger(struct snd_pcm_substream *substream,
                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
 
-struct snd_soc_cpu_dai s3c2443_ac97_dai[] = {
+struct snd_soc_dai s3c2443_ac97_dai[] = {
 {
        .name = "s3c2443-ac97",
        .id = 0,
index bf03e8e..a96dcad 100644 (file)
@@ -26,6 +26,6 @@
 #define IRQ_S3C244x_AC97 IRQ_S3C2443_AC97
 #endif
 
-extern struct snd_soc_cpu_dai s3c2443_ac97_dai[];
+extern struct snd_soc_dai s3c2443_ac97_dai[];
 
 #endif /*S3C24XXAC97_H_*/
index 1ed6afd..3975242 100644 (file)
  *  under  the terms of  the GNU General  Public License as published by the
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
- *
- *
- *  Revision history
- *    11th Dec 2006   Merged with Simtec driver
- *    10th Nov 2006   Initial version.
  */
 
 #include <linux/init.h>
@@ -180,7 +175,7 @@ static void s3c24xx_snd_rxctrl(int on)
 static int s3c24xx_snd_lrsync(void)
 {
        u32 iiscon;
-       unsigned long timeout = jiffies + msecs_to_jiffies(5);
+       int timeout = 50; /* 5ms */
 
        DBG("Entered %s\n", __func__);
 
@@ -189,8 +184,9 @@ static int s3c24xx_snd_lrsync(void)
                if (iiscon & S3C2410_IISCON_LRINDEX)
                        break;
 
-               if (time_after(jiffies, timeout))
+               if (!timeout--)
                        return -ETIMEDOUT;
+               udelay(100);
        }
 
        return 0;
@@ -209,7 +205,7 @@ static inline int s3c24xx_snd_is_clkmaster(void)
 /*
  * Set S3C24xx I2S DAI format
  */
-static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
                unsigned int fmt)
 {
        u32 iismod;
@@ -317,7 +313,7 @@ exit_err:
 /*
  * Set S3C24xx Clock source
  */
-static int s3c24xx_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
        int clk_id, unsigned int freq, int dir)
 {
        u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
@@ -343,7 +339,7 @@ static int s3c24xx_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
 /*
  * Set S3C24xx Clock dividers
  */
-static int s3c24xx_i2s_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
+static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
        int div_id, int div)
 {
        u32 reg;
@@ -381,7 +377,8 @@ u32 s3c24xx_i2s_get_clockrate(void)
 }
 EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
 
-static int s3c24xx_i2s_probe(struct platform_device *pdev)
+static int s3c24xx_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
 {
        DBG("Entered %s\n", __func__);
 
@@ -414,7 +411,7 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev)
 
 #ifdef CONFIG_PM
 static int s3c24xx_i2s_suspend(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai)
+               struct snd_soc_dai *cpu_dai)
 {
        DBG("Entered %s\n", __func__);
 
@@ -429,7 +426,7 @@ static int s3c24xx_i2s_suspend(struct platform_device *pdev,
 }
 
 static int s3c24xx_i2s_resume(struct platform_device *pdev,
-               struct snd_soc_cpu_dai *cpu_dai)
+               struct snd_soc_dai *cpu_dai)
 {
        DBG("Entered %s\n", __func__);
        clk_enable(s3c24xx_i2s.iis_clk);
@@ -452,7 +449,7 @@ static int s3c24xx_i2s_resume(struct platform_device *pdev,
        SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
        SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
 
-struct snd_soc_cpu_dai s3c24xx_i2s_dai = {
+struct snd_soc_dai s3c24xx_i2s_dai = {
        .name = "s3c24xx-i2s",
        .id = 0,
        .type = SND_SOC_DAI_I2S,
index 537b4ec..726d91c 100644 (file)
@@ -32,6 +32,6 @@
 
 u32 s3c24xx_i2s_get_clockrate(void);
 
-extern struct snd_soc_cpu_dai s3c24xx_i2s_dai;
+extern struct snd_soc_dai s3c24xx_i2s_dai;
 
 #endif /*S3C24XXI2S_H_*/
index 7806ae6..cef79b3 100644 (file)
  *  under  the terms of  the GNU General  Public License as published by the
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
- *
- *  Revision history
- *    11th Dec 2006   Merged with Simtec driver
- *    10th Nov 2006   Initial version.
  */
 
 #include <linux/module.h>
@@ -433,7 +429,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
 static u64 s3c24xx_pcm_dmamask = DMA_32BIT_MASK;
 
 static int s3c24xx_pcm_new(struct snd_card *card,
-       struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
+       struct snd_soc_dai *dai, struct snd_pcm *pcm)
 {
        int ret = 0;
 
index b4a5630..8515d6f 100644 (file)
@@ -10,9 +10,6 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    8th Mar 2007   Initial version.
- *
  */
 
 #include <linux/module.h>
index 4c1e013..54bd604 100644 (file)
@@ -3,7 +3,7 @@ menu "SoC Audio support for SuperH"
 
 config SND_SOC_PCM_SH7760
        tristate "SoC Audio support for Renesas SH7760"
-       depends on CPU_SUBTYPE_SH7760 && SND_SOC && SH_DMABRG
+       depends on CPU_SUBTYPE_SH7760 && SH_DMABRG
        help
          Enable this option for SH7760 AC97/I2S audio support.
 
@@ -13,10 +13,9 @@ config SND_SOC_PCM_SH7760
 ##
 
 config SND_SOC_SH4_HAC
+       tristate
        select AC97_BUS
        select SND_SOC_AC97_BUS
-       select SND_AC97_CODEC
-       tristate
 
 config SND_SOC_SH4_SSI
        tristate
index 7a3ce80..9faa126 100644 (file)
@@ -326,7 +326,7 @@ static void camelot_pcm_free(struct snd_pcm *pcm)
 }
 
 static int camelot_pcm_new(struct snd_card *card,
-                          struct snd_soc_codec_dai *dai,
+                          struct snd_soc_dai *dai,
                           struct snd_pcm *pcm)
 {
        /* dont use SNDRV_DMA_TYPE_DEV, since it will oops the SH kernel
index b7b676b..df7bc34 100644 (file)
@@ -266,7 +266,7 @@ static int hac_hw_params(struct snd_pcm_substream *substream,
 #define AC97_FMTS      \
        SNDRV_PCM_FMTBIT_S16_LE
 
-struct snd_soc_cpu_dai sh4_hac_dai[] = {
+struct snd_soc_dai sh4_hac_dai[] = {
 {
        .name                   = "HAC0",
        .id                     = 0,
index 2f91de8..92bfaf4 100644 (file)
 #define IPSEL 0xFE400034
 
 /* platform specific structs can be declared here */
-extern struct snd_soc_cpu_dai sh4_hac_dai[2];
+extern struct snd_soc_dai sh4_hac_dai[2];
 extern struct snd_soc_platform sh7760_soc_platform;
 
 static int machine_init(struct snd_soc_codec *codec)
 {
-       snd_soc_dapm_sync_endpoints(codec);
+       snd_soc_dapm_sync(codec);
        return 0;
 }
 
index 3388bc3..55c3464 100644 (file)
@@ -208,7 +208,7 @@ static int ssi_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static int ssi_set_sysclk(struct snd_soc_cpu_dai *cpu_dai, int clk_id,
+static int ssi_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id,
                          unsigned int freq, int dir)
 {
        struct ssi_priv *ssi = &ssi_cpu_data[cpu_dai->id];
@@ -222,7 +222,7 @@ static int ssi_set_sysclk(struct snd_soc_cpu_dai *cpu_dai, int clk_id,
  * This divider is used to generate the SSI_SCK (I2S bitclock) from the
  * clock at the HAC_BIT_CLK ("oversampling clock") pin.
  */
-static int ssi_set_clkdiv(struct snd_soc_cpu_dai *dai, int did, int div)
+static int ssi_set_clkdiv(struct snd_soc_dai *dai, int did, int div)
 {
        struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
        unsigned long ssicr;
@@ -245,7 +245,7 @@ static int ssi_set_clkdiv(struct snd_soc_cpu_dai *dai, int did, int div)
        return 0;
 }
 
-static int ssi_set_fmt(struct snd_soc_cpu_dai *dai, unsigned int fmt)
+static int ssi_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
        struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
        unsigned long ssicr = SSIREG(SSICR);
@@ -332,7 +332,7 @@ static int ssi_set_fmt(struct snd_soc_cpu_dai *dai, unsigned int fmt)
         SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE |  \
         SNDRV_PCM_FMTBIT_S32_LE  | SNDRV_PCM_FMTBIT_U32_LE)
 
-struct snd_soc_cpu_dai sh4_ssi_dai[] = {
+struct snd_soc_dai sh4_ssi_dai[] = {
 {
        .name                   = "SSI0",
        .id                     = 0,
index e148db9..83f1190 100644 (file)
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    12th Aug 2005   Initial version.
- *    25th Oct 2005   Working Codec, Interface and Platform registration.
- *
  *  TODO:
  *   o Add hw rules to enforce rates, etc.
  *   o More testing with other codecs/machines.
@@ -112,9 +108,9 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
 }
 #endif
 
-static inline const charget_dai_name(int type)
+static inline const char *get_dai_name(int type)
 {
-       switch(type) {
+       switch (type) {
        case SND_SOC_DAI_AC97_BUS:
        case SND_SOC_DAI_AC97:
                return "AC97";
@@ -138,8 +134,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        int ret = 0;
 
        mutex_lock(&pcm_mutex);
@@ -182,9 +178,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        /* Check that the codec and cpu DAI's are compatible */
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                runtime->hw.rate_min =
-                       max(codec_dai->playback.rate_min, cpu_dai->playback.rate_min);
+                       max(codec_dai->playback.rate_min,
+                           cpu_dai->playback.rate_min);
                runtime->hw.rate_max =
-                       min(codec_dai->playback.rate_max, cpu_dai->playback.rate_max);
+                       min(codec_dai->playback.rate_max,
+                           cpu_dai->playback.rate_max);
                runtime->hw.channels_min =
                        max(codec_dai->playback.channels_min,
                                cpu_dai->playback.channels_min);
@@ -197,9 +195,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                        codec_dai->playback.rates & cpu_dai->playback.rates;
        } else {
                runtime->hw.rate_min =
-                       max(codec_dai->capture.rate_min, cpu_dai->capture.rate_min);
+                       max(codec_dai->capture.rate_min,
+                           cpu_dai->capture.rate_min);
                runtime->hw.rate_max =
-                       min(codec_dai->capture.rate_max, cpu_dai->capture.rate_max);
+                       min(codec_dai->capture.rate_max,
+                           cpu_dai->capture.rate_max);
                runtime->hw.channels_min =
                        max(codec_dai->capture.channels_min,
                                cpu_dai->capture.channels_min);
@@ -229,7 +229,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                goto machine_err;
        }
 
-       dbg("asoc: %s <-> %s info:\n",codec_dai->name, cpu_dai->name);
+       dbg("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
        dbg("asoc: rate mask 0x%x\n", runtime->hw.rates);
        dbg("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
                runtime->hw.channels_max);
@@ -272,11 +272,11 @@ static void close_delayed_work(struct work_struct *work)
        struct snd_soc_device *socdev =
                container_of(work, struct snd_soc_device, delayed_work.work);
        struct snd_soc_codec *codec = socdev->codec;
-       struct snd_soc_codec_dai *codec_dai;
+       struct snd_soc_dai *codec_dai;
        int i;
 
        mutex_lock(&pcm_mutex);
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                codec_dai = &codec->dai[i];
 
                dbg("pop wq checking: %s status: %s waiting: %s\n",
@@ -287,12 +287,12 @@ static void close_delayed_work(struct work_struct *work)
                /* are we waiting on this codec DAI stream */
                if (codec_dai->pop_wait == 1) {
 
-                       /* power down the codec to D1 if no longer active */
+                       /* Reduce power if no longer active */
                        if (codec->active == 0) {
                                dbg("pop wq D1 %s %s\n", codec->name,
                                        codec_dai->playback.stream_name);
-                               snd_soc_dapm_device_event(socdev,
-                                       SNDRV_CTL_POWER_D1);
+                               snd_soc_dapm_set_bias_level(socdev,
+                                       SND_SOC_BIAS_PREPARE);
                        }
 
                        codec_dai->pop_wait = 0;
@@ -300,12 +300,12 @@ static void close_delayed_work(struct work_struct *work)
                                codec_dai->playback.stream_name,
                                SND_SOC_DAPM_STREAM_STOP);
 
-                       /* power down the codec power domain if no longer active */
+                       /* Fall into standby if no longer active */
                        if (codec->active == 0) {
                                dbg("pop wq D3 %s %s\n", codec->name,
                                        codec_dai->playback.stream_name);
-                               snd_soc_dapm_device_event(socdev,
-                                       SNDRV_CTL_POWER_D3hot);
+                               snd_soc_dapm_set_bias_level(socdev,
+                                       SND_SOC_BIAS_STANDBY);
                        }
                }
        }
@@ -323,8 +323,8 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        struct snd_soc_codec *codec = socdev->codec;
 
        mutex_lock(&pcm_mutex);
@@ -365,8 +365,8 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
                        SND_SOC_DAPM_STREAM_STOP);
 
                if (codec->active == 0 && codec_dai->pop_wait == 0)
-                       snd_soc_dapm_device_event(socdev,
-                                               SNDRV_CTL_POWER_D3hot);
+                       snd_soc_dapm_set_bias_level(socdev,
+                                               SND_SOC_BIAS_STANDBY);
        }
 
        mutex_unlock(&pcm_mutex);
@@ -384,8 +384,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        struct snd_soc_codec *codec = socdev->codec;
        int ret = 0;
 
@@ -434,14 +434,14 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                else {
                        codec_dai->pop_wait = 0;
                        cancel_delayed_work(&socdev->delayed_work);
-                       if (codec_dai->dai_ops.digital_mute)
-                               codec_dai->dai_ops.digital_mute(codec_dai, 0);
+                       snd_soc_dai_digital_mute(codec_dai, 0);
                }
        } else {
                /* no delayed work - do we need to power up codec */
-               if (codec->dapm_state != SNDRV_CTL_POWER_D0) {
+               if (codec->bias_level != SND_SOC_BIAS_ON) {
 
-                       snd_soc_dapm_device_event(socdev,  SNDRV_CTL_POWER_D1);
+                       snd_soc_dapm_set_bias_level(socdev,
+                                                   SND_SOC_BIAS_PREPARE);
 
                        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                                snd_soc_dapm_stream_event(codec,
@@ -452,9 +452,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                                        codec_dai->capture.stream_name,
                                        SND_SOC_DAPM_STREAM_START);
 
-                       snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D0);
-                       if (codec_dai->dai_ops.digital_mute)
-                               codec_dai->dai_ops.digital_mute(codec_dai, 0);
+                       snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
+                       snd_soc_dai_digital_mute(codec_dai, 0);
 
                } else {
                        /* codec already powered - power on widgets */
@@ -466,8 +465,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                                snd_soc_dapm_stream_event(codec,
                                        codec_dai->capture.stream_name,
                                        SND_SOC_DAPM_STREAM_START);
-                       if (codec_dai->dai_ops.digital_mute)
-                               codec_dai->dai_ops.digital_mute(codec_dai, 0);
+
+                       snd_soc_dai_digital_mute(codec_dai, 0);
                }
        }
 
@@ -488,8 +487,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        int ret = 0;
 
        mutex_lock(&pcm_mutex);
@@ -514,7 +513,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
        if (cpu_dai->ops.hw_params) {
                ret = cpu_dai->ops.hw_params(substream, params);
                if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't set interface %s hw params\n",
+                       printk(KERN_ERR "asoc: interface %s hw params failed\n",
                                cpu_dai->name);
                        goto interface_err;
                }
@@ -523,7 +522,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
        if (platform->pcm_ops->hw_params) {
                ret = platform->pcm_ops->hw_params(substream, params);
                if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't set platform %s hw params\n",
+                       printk(KERN_ERR "asoc: platform %s hw params failed\n",
                                platform->name);
                        goto platform_err;
                }
@@ -542,7 +541,7 @@ interface_err:
                codec_dai->ops.hw_free(substream);
 
 codec_err:
-       if(machine->ops && machine->ops->hw_free)
+       if (machine->ops && machine->ops->hw_free)
                machine->ops->hw_free(substream);
 
        mutex_unlock(&pcm_mutex);
@@ -558,15 +557,15 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        struct snd_soc_codec *codec = socdev->codec;
 
        mutex_lock(&pcm_mutex);
 
        /* apply codec digital mute */
-       if (!codec->active && codec_dai->dai_ops.digital_mute)
-               codec_dai->dai_ops.digital_mute(codec_dai, 1);
+       if (!codec->active)
+               snd_soc_dai_digital_mute(codec_dai, 1);
 
        /* free any machine hw params */
        if (machine->ops && machine->ops->hw_free)
@@ -593,8 +592,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_dai_link *machine = rtd->dai;
        struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_cpu_dai *cpu_dai = machine->cpu_dai;
-       struct snd_soc_codec_dai *codec_dai = machine->codec_dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
        int ret;
 
        if (codec_dai->ops.trigger) {
@@ -631,16 +630,26 @@ static struct snd_pcm_ops soc_pcm_ops = {
 /* powers down audio subsystem for suspend */
 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_machine *machine = socdev->machine;
+       struct snd_soc_platform *platform = socdev->platform;
+       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
        struct snd_soc_codec *codec = socdev->codec;
        int i;
 
+       /* Due to the resume being scheduled into a workqueue we could
+       * suspend before that's finished - wait for it to complete.
+        */
+       snd_power_lock(codec->card);
+       snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
+       snd_power_unlock(codec->card);
+
+       /* we're going to block userspace touching us until resume completes */
+       snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
+
        /* mute any active DAC's */
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
                if (dai->dai_ops.digital_mute && dai->playback.active)
                        dai->dai_ops.digital_mute(dai, 1);
        }
@@ -652,8 +661,8 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
        if (machine->suspend_pre)
                machine->suspend_pre(pdev, state);
 
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai  *cpu_dai = machine->dai_link[i].cpu_dai;
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai  *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
                        cpu_dai->suspend(pdev, cpu_dai);
                if (platform->suspend)
@@ -662,9 +671,9 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
 
        /* close any waiting streams and save state */
        run_delayed_work(&socdev->delayed_work);
-       codec->suspend_dapm_state = codec->dapm_state;
+       codec->suspend_bias_level = codec->bias_level;
 
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                char *stream = codec->dai[i].playback.stream_name;
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
@@ -678,8 +687,8 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
        if (codec_dev->suspend)
                codec_dev->suspend(pdev, state);
 
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
                        cpu_dai->suspend(pdev, cpu_dai);
        }
@@ -690,21 +699,32 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
        return 0;
 }
 
-/* powers up audio subsystem after a suspend */
-static int soc_resume(struct platform_device *pdev)
+/* deferred resume work, so resume can complete before we finished
+ * setting our codec back up, which can be very slow on I2C
+ */
+static void soc_resume_deferred(struct work_struct *work)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
+       struct snd_soc_device *socdev = container_of(work,
+                                                    struct snd_soc_device,
+                                                    deferred_resume_work);
+       struct snd_soc_machine *machine = socdev->machine;
+       struct snd_soc_platform *platform = socdev->platform;
+       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
        struct snd_soc_codec *codec = socdev->codec;
+       struct platform_device *pdev = to_platform_device(socdev->dev);
        int i;
 
+       /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
+        * so userspace apps are blocked from touching us
+        */
+
+       dev_info(socdev->dev, "starting resume work\n");
+
        if (machine->resume_pre)
                machine->resume_pre(pdev);
 
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
                        cpu_dai->resume(pdev, cpu_dai);
        }
@@ -712,8 +732,8 @@ static int soc_resume(struct platform_device *pdev)
        if (codec_dev->resume)
                codec_dev->resume(pdev);
 
-       for(i = 0; i < codec->num_dai; i++) {
-               charstream = codec->dai[i].playback.stream_name;
+       for (i = 0; i < codec->num_dai; i++) {
+               char *stream = codec->dai[i].playback.stream_name;
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
                                SND_SOC_DAPM_STREAM_RESUME);
@@ -723,15 +743,15 @@ static int soc_resume(struct platform_device *pdev)
                                SND_SOC_DAPM_STREAM_RESUME);
        }
 
-       /* unmute any active DAC's */
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
+       /* unmute any active DACs */
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
                if (dai->dai_ops.digital_mute && dai->playback.active)
                        dai->dai_ops.digital_mute(dai, 0);
        }
 
-       for(i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+       for (i = 0; i < machine->num_links; i++) {
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
                        cpu_dai->resume(pdev, cpu_dai);
                if (platform->resume)
@@ -741,6 +761,22 @@ static int soc_resume(struct platform_device *pdev)
        if (machine->resume_post)
                machine->resume_post(pdev);
 
+       dev_info(socdev->dev, "resume work completed\n");
+
+       /* userspace can access us now we are back as we were before */
+       snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
+}
+
+/* powers up audio subsystem after a suspend */
+static int soc_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       dev_info(socdev->dev, "scheduling resume work\n");
+
+       if (!schedule_work(&socdev->deferred_resume_work))
+               dev_err(socdev->dev, "work item may be lost\n");
+
        return 0;
 }
 
@@ -760,33 +796,38 @@ static int soc_probe(struct platform_device *pdev)
 
        if (machine->probe) {
                ret = machine->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        return ret;
        }
 
        for (i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->probe) {
-                       ret = cpu_dai->probe(pdev);
-                       if(ret < 0)
+                       ret = cpu_dai->probe(pdev, cpu_dai);
+                       if (ret < 0)
                                goto cpu_dai_err;
                }
        }
 
        if (codec_dev->probe) {
                ret = codec_dev->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        goto cpu_dai_err;
        }
 
        if (platform->probe) {
                ret = platform->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        goto platform_err;
        }
 
        /* DAPM stream work */
        INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
+#ifdef CONFIG_PM
+       /* deferred resume work */
+       INIT_WORK(&socdev->deferred_resume_work, soc_resume_deferred);
+#endif
+
        return 0;
 
 platform_err:
@@ -795,9 +836,9 @@ platform_err:
 
 cpu_dai_err:
        for (i--; i >= 0; i--) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->remove)
-                       cpu_dai->remove(pdev);
+                       cpu_dai->remove(pdev, cpu_dai);
        }
 
        if (machine->remove)
@@ -824,9 +865,9 @@ static int soc_remove(struct platform_device *pdev)
                codec_dev->remove(pdev);
 
        for (i = 0; i < machine->num_links; i++) {
-               struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
+               struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->remove)
-                       cpu_dai->remove(pdev);
+                       cpu_dai->remove(pdev, cpu_dai);
        }
 
        if (machine->remove)
@@ -852,8 +893,8 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        struct snd_soc_dai_link *dai_link, int num)
 {
        struct snd_soc_codec *codec = socdev->codec;
-       struct snd_soc_codec_dai *codec_dai = dai_link->codec_dai;
-       struct snd_soc_cpu_dai *cpu_dai = dai_link->cpu_dai;
+       struct snd_soc_dai *codec_dai = dai_link->codec_dai;
+       struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
        struct snd_soc_pcm_runtime *rtd;
        struct snd_pcm *pcm;
        char new_name[64];
@@ -868,7 +909,7 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        codec_dai->codec = socdev->codec;
 
        /* check client and interface hw capabilities */
-       sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
+       sprintf(new_name, "%s %s-%s-%d", dai_link->stream_name, codec_dai->name,
                get_dai_name(cpu_dai->type), num);
 
        if (codec_dai->playback.channels_min)
@@ -879,7 +920,8 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
                capture, &pcm);
        if (ret < 0) {
-               printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
+               printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
+                       codec->name);
                kfree(rtd);
                return ret;
        }
@@ -928,8 +970,9 @@ static ssize_t codec_reg_show(struct device *dev,
                step = codec->reg_cache_step;
 
        count += sprintf(buf, "%s registers\n", codec->name);
-       for(i = 0; i < codec->reg_cache_size; i += step)
-               count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
+       for (i = 0; i < codec->reg_cache_size; i += step)
+               count += sprintf(buf + count, "%2x: %4x\n", i,
+                       codec->read(codec, i));
 
        return count;
 }
@@ -1072,7 +1115,7 @@ int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
        strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
 
        /* create the pcms */
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
                if (ret < 0) {
                        printk(KERN_ERR "asoc: can't create pcm %s\n",
@@ -1102,7 +1145,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
        struct snd_soc_machine *machine = socdev->machine;
        int ret = 0, i, ac97 = 0, err = 0;
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                if (socdev->machine->dai_link[i].init) {
                        err = socdev->machine->dai_link[i].init(codec);
                        if (err < 0) {
@@ -1111,7 +1154,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
                                continue;
                        }
                }
-               if (socdev->machine->dai_link[i].codec_dai->type == 
+               if (socdev->machine->dai_link[i].codec_dai->type ==
                        SND_SOC_DAI_AC97_BUS)
                        ac97 = 1;
        }
@@ -1122,7 +1165,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
 
        ret = snd_card_register(codec->card);
        if (ret < 0) {
-               printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
+               printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
                                codec->name);
                goto out;
        }
@@ -1146,7 +1189,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
 
        err = device_create_file(socdev->dev, &dev_attr_codec_reg);
        if (err < 0)
-               printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
+               printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
 
        mutex_unlock(&codec->mutex);
 
@@ -1166,13 +1209,13 @@ void snd_soc_free_pcms(struct snd_soc_device *socdev)
 {
        struct snd_soc_codec *codec = socdev->codec;
 #ifdef CONFIG_SND_SOC_AC97_BUS
-       struct snd_soc_codec_dai *codec_dai;
+       struct snd_soc_dai *codec_dai;
        int i;
 #endif
 
        mutex_lock(&codec->mutex);
 #ifdef CONFIG_SND_SOC_AC97_BUS
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                codec_dai = &codec->dai[i];
                if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
                        soc_ac97_dev_unregister(codec);
@@ -1282,7 +1325,8 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
        for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
                ;
        val = snd_soc_read(codec, e->reg);
-       ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
+       ucontrol->value.enumerated.item[0]
+               = (val >> e->shift_l) & (bitmask - 1);
        if (e->shift_l != e->shift_r)
                ucontrol->value.enumerated.item[1] =
                        (val >> e->shift_r) & (bitmask - 1);
@@ -1576,7 +1620,8 @@ int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
        val = val << shift;
        val2 = val2 << shift;
 
-       if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
+       err = snd_soc_update_bits(codec, reg, val_mask, val);
+       if (err < 0)
                return err;
 
        err = snd_soc_update_bits(codec, reg2, val_mask, val2);
@@ -1584,6 +1629,204 @@ int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
 
+/**
+ * snd_soc_info_volsw_s8 - signed mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_info *uinfo)
+{
+       int max = (signed char)((kcontrol->private_value >> 16) & 0xff);
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = max-min;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
+
+/**
+ * snd_soc_get_volsw_s8 - signed mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+       int val = snd_soc_read(codec, reg);
+
+       ucontrol->value.integer.value[0] =
+               ((signed char)(val & 0xff))-min;
+       ucontrol->value.integer.value[1] =
+               ((signed char)((val >> 8) & 0xff))-min;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
+
+/**
+ * snd_soc_put_volsw_sgn - signed mixer put callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+       unsigned short val;
+
+       val = (ucontrol->value.integer.value[0]+min) & 0xff;
+       val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
+
+       return snd_soc_update_bits(codec, reg, 0xffff, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
+
+/**
+ * snd_soc_dai_set_sysclk - configure DAI system or master clock.
+ * @dai: DAI
+ * @clk_id: DAI specific clock ID
+ * @freq: new clock frequency in Hz
+ * @dir: new clock direction - input/output.
+ *
+ * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
+ */
+int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
+       unsigned int freq, int dir)
+{
+       if (dai->dai_ops.set_sysclk)
+               return dai->dai_ops.set_sysclk(dai, clk_id, freq, dir);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
+
+/**
+ * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
+ * @dai: DAI
+ * @clk_id: DAI specific clock divider ID
+ * @div: new clock divisor.
+ *
+ * Configures the clock dividers. This is used to derive the best DAI bit and
+ * frame clocks from the system or master clock. It's best to set the DAI bit
+ * and frame clocks as low as possible to save system power.
+ */
+int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
+       int div_id, int div)
+{
+       if (dai->dai_ops.set_clkdiv)
+               return dai->dai_ops.set_clkdiv(dai, div_id, div);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
+
+/**
+ * snd_soc_dai_set_pll - configure DAI PLL.
+ * @dai: DAI
+ * @pll_id: DAI specific PLL ID
+ * @freq_in: PLL input clock frequency in Hz
+ * @freq_out: requested PLL output clock frequency in Hz
+ *
+ * Configures and enables PLL to generate output clock based on input clock.
+ */
+int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
+       int pll_id, unsigned int freq_in, unsigned int freq_out)
+{
+       if (dai->dai_ops.set_pll)
+               return dai->dai_ops.set_pll(dai, pll_id, freq_in, freq_out);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
+
+/**
+ * snd_soc_dai_set_fmt - configure DAI hardware audio format.
+ * @dai: DAI
+ * @clk_id: DAI specific clock ID
+ * @fmt: SND_SOC_DAIFMT_ format value.
+ *
+ * Configures the DAI hardware format and clocking.
+ */
+int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+       if (dai->dai_ops.set_fmt)
+               return dai->dai_ops.set_fmt(dai, fmt);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
+
+/**
+ * snd_soc_dai_set_tdm_slot - configure DAI TDM.
+ * @dai: DAI
+ * @mask: DAI specific mask representing used slots.
+ * @slots: Number of slots in use.
+ *
+ * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
+ * specific.
+ */
+int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
+       unsigned int mask, int slots)
+{
+       if (dai->dai_ops.set_sysclk)
+               return dai->dai_ops.set_tdm_slot(dai, mask, slots);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
+
+/**
+ * snd_soc_dai_set_tristate - configure DAI system or master clock.
+ * @dai: DAI
+ * @tristate: tristate enable
+ *
+ * Tristates the DAI so that others can use it.
+ */
+int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
+{
+       if (dai->dai_ops.set_sysclk)
+               return dai->dai_ops.set_tristate(dai, tristate);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
+
+/**
+ * snd_soc_dai_digital_mute - configure DAI system or master clock.
+ * @dai: DAI
+ * @mute: mute enable
+ *
+ * Mutes the DAI DAC.
+ */
+int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
+{
+       if (dai->dai_ops.digital_mute)
+               return dai->dai_ops.digital_mute(dai, mute);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
+
 static int __devinit snd_soc_init(void)
 {
        printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
@@ -1592,7 +1835,7 @@ static int __devinit snd_soc_init(void)
 
 static void snd_soc_exit(void)
 {
-       platform_driver_unregister(&soc_driver);
+       platform_driver_unregister(&soc_driver);
 }
 
 module_init(snd_soc_init);
index af3326c..2c87061 100644 (file)
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    12th Aug 2005   Initial version.
- *    25th Oct 2005   Implemented path power domain.
- *    18th Dec 2005   Implemented machine and stream level power domain.
- *
  *  Features:
  *    o Changes power status of internal codec blocks depending on the
  *      dynamic configuration of codec internal audio paths and active
 #include <sound/initval.h>
 
 /* debug */
-#define DAPM_DEBUG 0
-#if DAPM_DEBUG
+#ifdef DEBUG
 #define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
-#define dbg(format, arg...) printk(format, ## arg)
 #else
 #define dump_dapm(codec, action)
-#define dbg(format, arg...)
-#endif
-
-#define POP_DEBUG 0
-#if POP_DEBUG
-#define POP_TIME 500 /* 500 msecs - change if pop debug is too fast */
-#define pop_wait(time) schedule_timeout_uninterruptible(msecs_to_jiffies(time))
-#define pop_dbg(format, arg...) printk(format, ## arg); pop_wait(POP_TIME)
-#else
-#define pop_dbg(format, arg...)
-#define pop_wait(time)
 #endif
 
 /* dapm power sequences - make this per codec in the future */
@@ -85,6 +67,28 @@ static int dapm_status = 1;
 module_param(dapm_status, int, 0);
 MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
 
+static unsigned int pop_time;
+
+static void pop_wait(void)
+{
+       if (pop_time)
+               schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
+}
+
+static void pop_dbg(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+
+       if (pop_time) {
+               vprintk(fmt, args);
+               pop_wait();
+       }
+
+       va_end(args);
+}
+
 /* create a new dapm widget */
 static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
        const struct snd_soc_dapm_widget *_widget)
@@ -222,11 +226,12 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
        change = old != new;
        if (change) {
                pop_dbg("pop test %s : %s in %d ms\n", widget->name,
-                       widget->power ? "on" : "off", POP_TIME);
+                       widget->power ? "on" : "off", pop_time);
                snd_soc_write(codec, widget->reg, new);
-               pop_wait(POP_TIME);
+               pop_wait();
        }
-       dbg("reg %x old %x new %x change %d\n", widget->reg, old, new, change);
+       pr_debug("reg %x old %x new %x change %d\n", widget->reg,
+                old, new, change);
        return change;
 }
 
@@ -447,6 +452,25 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
        return con;
 }
 
+/*
+ * Handler for generic register modifier widget.
+ */
+int dapm_reg_event(struct snd_soc_dapm_widget *w,
+                  struct snd_kcontrol *kcontrol, int event)
+{
+       unsigned int val;
+
+       if (SND_SOC_DAPM_EVENT_ON(event))
+               val = w->on_val;
+       else
+               val = w->off_val;
+
+       snd_soc_update_bits(w->codec, -(w->reg + 1),
+                           w->mask << w->shift, val << w->shift);
+
+       return 0;
+}
+
 /*
  * Scan each dapm widget for complete audio path.
  * A complete path is a route that has valid endpoints i.e.:-
@@ -565,8 +589,8 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                        /* call any power change event handlers */
                        if (power_change) {
                                if (w->event) {
-                                       dbg("power %s event for %s flags %x\n",
-                                               w->power ? "on" : "off", w->name, w->event_flags);
+                                       pr_debug("power %s event for %s flags %x\n",
+                                                w->power ? "on" : "off", w->name, w->event_flags);
                                        if (power) {
                                                /* power up event */
                                                if (w->event_flags & SND_SOC_DAPM_PRE_PMU) {
@@ -608,7 +632,7 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
        return ret;
 }
 
-#if DAPM_DEBUG
+#ifdef DEBUG
 static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
 {
        struct snd_soc_dapm_widget *w;
@@ -693,8 +717,10 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
                        path->connect = 0; /* old connection must be powered down */
        }
 
-       if (found)
+       if (found) {
                dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
+               dump_dapm(widget->codec, "mux power update");
+       }
 
        return 0;
 }
@@ -730,8 +756,10 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
                break;
        }
 
-       if (found)
+       if (found) {
                dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
+               dump_dapm(widget->codec, "mixer power update");
+       }
 
        return 0;
 }
@@ -768,21 +796,18 @@ static ssize_t dapm_widget_show(struct device *dev,
                }
        }
 
-       switch(codec->dapm_state){
-       case SNDRV_CTL_POWER_D0:
-               state = "D0";
+       switch (codec->bias_level) {
+       case SND_SOC_BIAS_ON:
+               state = "On";
                break;
-       case SNDRV_CTL_POWER_D1:
-               state = "D1";
+       case SND_SOC_BIAS_PREPARE:
+               state = "Prepare";
                break;
-       case SNDRV_CTL_POWER_D2:
-               state = "D2";
+       case SND_SOC_BIAS_STANDBY:
+               state = "Standby";
                break;
-       case SNDRV_CTL_POWER_D3hot:
-               state = "D3hot";
-               break;
-       case SNDRV_CTL_POWER_D3cold:
-               state = "D3cold";
+       case SND_SOC_BIAS_OFF:
+               state = "Off";
                break;
        }
        count += sprintf(buf + count, "PM State: %s\n", state);
@@ -792,20 +817,51 @@ static ssize_t dapm_widget_show(struct device *dev,
 
 static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
 
+/* pop/click delay times */
+static ssize_t dapm_pop_time_show(struct device *dev,
+       struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", pop_time);
+}
+
+static ssize_t dapm_pop_time_store(struct device *dev,
+                                  struct device_attribute *attr,
+                                  const char *buf, size_t count)
+
+{
+       unsigned long val;
+
+       if (strict_strtoul(buf, 10, &val) >= 0)
+               pop_time = val;
+       else
+               printk(KERN_ERR "Unable to parse pop_time setting\n");
+
+       return count;
+}
+
+static DEVICE_ATTR(dapm_pop_time, 0744, dapm_pop_time_show,
+                  dapm_pop_time_store);
+
 int snd_soc_dapm_sys_add(struct device *dev)
 {
        int ret = 0;
 
-       if (dapm_status)
+       if (dapm_status) {
                ret = device_create_file(dev, &dev_attr_dapm_widget);
 
+               if (ret == 0)
+                       ret = device_create_file(dev, &dev_attr_dapm_pop_time);
+       }
+
        return ret;
 }
 
 static void snd_soc_dapm_sys_remove(struct device *dev)
 {
-       if (dapm_status)
+       if (dapm_status) {
+               device_remove_file(dev, &dev_attr_dapm_pop_time);
                device_remove_file(dev, &dev_attr_dapm_widget);
+       }
 }
 
 /* free all dapm widgets and resources */
@@ -826,8 +882,25 @@ static void dapm_free_widgets(struct snd_soc_codec *codec)
        }
 }
 
+static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
+       char *pin, int status)
+{
+       struct snd_soc_dapm_widget *w;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (!strcmp(w->name, pin)) {
+                       pr_debug("dapm: %s: pin %s\n", codec->name, pin);
+                       w->connected = status;
+                       return 0;
+               }
+       }
+
+       pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
+       return -EINVAL;
+}
+
 /**
- * snd_soc_dapm_sync_endpoints - scan and power dapm paths
+ * snd_soc_dapm_sync - scan and power dapm paths
  * @codec: audio codec
  *
  * Walks all dapm audio paths and powers widgets according to their
@@ -835,27 +908,16 @@ static void dapm_free_widgets(struct snd_soc_codec *codec)
  *
  * Returns 0 for success.
  */
-int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec)
+int snd_soc_dapm_sync(struct snd_soc_codec *codec)
 {
-       return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
+       int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
+       dump_dapm(codec, "sync");
+       return ret;
 }
-EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_endpoints);
+EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
 
-/**
- * snd_soc_dapm_connect_input - connect dapm widgets
- * @codec: audio codec
- * @sink: name of target widget
- * @control: mixer control name
- * @source: name of source name
- *
- * Connects 2 dapm widgets together via a named audio path. The sink is
- * the widget receiving the audio signal, whilst the source is the sender
- * of the audio signal.
- *
- * Returns 0 for success else error.
- */
-int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *sink,
-       const char * control, const char *source)
+static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
+       const char *sink, const char *control, const char *source)
 {
        struct snd_soc_dapm_path *path;
        struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
@@ -957,8 +1019,63 @@ err:
        kfree(path);
        return ret;
 }
+
+/**
+ * snd_soc_dapm_connect_input - connect dapm widgets
+ * @codec: audio codec
+ * @sink: name of target widget
+ * @control: mixer control name
+ * @source: name of source name
+ *
+ * Connects 2 dapm widgets together via a named audio path. The sink is
+ * the widget receiving the audio signal, whilst the source is the sender
+ * of the audio signal.
+ *
+ * This function has been deprecated in favour of snd_soc_dapm_add_routes().
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *sink,
+       const char *control, const char *source)
+{
+       return snd_soc_dapm_add_route(codec, sink, control, source);
+}
 EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_input);
 
+/**
+ * snd_soc_dapm_add_routes - Add routes between DAPM widgets
+ * @codec: codec
+ * @route: audio routes
+ * @num: number of routes
+ *
+ * Connects 2 dapm widgets together via a named audio path. The sink is
+ * the widget receiving the audio signal, whilst the source is the sender
+ * of the audio signal.
+ *
+ * Returns 0 for success else error. On error all resources can be freed
+ * with a call to snd_soc_card_free().
+ */
+int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
+                           const struct snd_soc_dapm_route *route, int num)
+{
+       int i, ret;
+
+       for (i = 0; i < num; i++) {
+               ret = snd_soc_dapm_add_route(codec, route->sink,
+                                            route->control, route->source);
+               if (ret < 0) {
+                       printk(KERN_ERR "Failed to add route %s->%s\n",
+                              route->source,
+                              route->sink);
+                       return ret;
+               }
+               route++;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
+
 /**
  * snd_soc_dapm_new_widgets - add new dapm widgets
  * @codec: audio codec
@@ -1233,6 +1350,33 @@ int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
 
+/**
+ * snd_soc_dapm_new_controls - create new dapm controls
+ * @codec: audio codec
+ * @widget: widget array
+ * @num: number of widgets
+ *
+ * Creates new DAPM controls based upon the templates.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
+       const struct snd_soc_dapm_widget *widget,
+       int num)
+{
+       int i, ret;
+
+       for (i = 0; i < num; i++) {
+               ret = snd_soc_dapm_new_control(codec, widget);
+               if (ret < 0)
+                       return ret;
+               widget++;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
+
+
 /**
  * snd_soc_dapm_stream_event - send a stream event to the dapm core
  * @codec: audio codec
@@ -1257,8 +1401,8 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
        {
                if (!w->sname)
                        continue;
-               dbg("widget %s\n %s stream %s event %d\n", w->name, w->sname,
-                       stream, event);
+               pr_debug("widget %s\n %s stream %s event %d\n",
+                        w->name, w->sname, stream, event);
                if (strstr(w->sname, stream)) {
                        switch(event) {
                        case SND_SOC_DAPM_STREAM_START:
@@ -1294,53 +1438,81 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
 
 /**
- * snd_soc_dapm_device_event - send a device event to the dapm core
+ * snd_soc_dapm_set_bias_level - set the bias level for the system
  * @socdev: audio device
- * @event: device event
+ * @level: level to configure
  *
- * Sends a device event to the dapm core. The core then makes any
- * necessary machine or codec power changes..
+ * Configure the bias (power) levels for the SoC audio device.
  *
  * Returns 0 for success else error.
  */
-int snd_soc_dapm_device_event(struct snd_soc_device *socdev, int event)
+int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
+                               enum snd_soc_bias_level level)
 {
        struct snd_soc_codec *codec = socdev->codec;
        struct snd_soc_machine *machine = socdev->machine;
+       int ret = 0;
 
-       if (machine->dapm_event)
-               machine->dapm_event(machine, event);
-       if (codec->dapm_event)
-               codec->dapm_event(codec, event);
-       return 0;
+       if (machine->set_bias_level)
+               ret = machine->set_bias_level(machine, level);
+       if (ret == 0 && codec->set_bias_level)
+               ret = codec->set_bias_level(codec, level);
+
+       return ret;
 }
-EXPORT_SYMBOL_GPL(snd_soc_dapm_device_event);
 
 /**
- * snd_soc_dapm_set_endpoint - set audio endpoint status
+ * snd_soc_dapm_enable_pin - enable pin.
+ * @snd_soc_codec: SoC codec
+ * @pin: pin name
+ *
+ * Enables input/output pin and it's parents or children widgets iff there is
+ * a valid audio route and active audio stream.
+ * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
+ * do any widget power switching.
+ */
+int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin)
+{
+       return snd_soc_dapm_set_pin(codec, pin, 1);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
+
+/**
+ * snd_soc_dapm_disable_pin - disable pin.
+ * @codec: SoC codec
+ * @pin: pin name
+ *
+ * Disables input/output pin and it's parents or children widgets.
+ * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
+ * do any widget power switching.
+ */
+int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin)
+{
+       return snd_soc_dapm_set_pin(codec, pin, 0);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
+
+/**
+ * snd_soc_dapm_get_pin_status - get audio pin status
  * @codec: audio codec
- * @endpoint: audio signal endpoint (or start point)
- * @status: point status
+ * @pin: audio signal pin endpoint (or start point)
  *
- * Set audio endpoint status - connected or disconnected.
+ * Get audio pin status - connected or disconnected.
  *
- * Returns 0 for success else error.
+ * Returns 1 for connected otherwise 0.
  */
-int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
-       char *endpoint, int status)
+int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin)
 {
        struct snd_soc_dapm_widget *w;
 
        list_for_each_entry(w, &codec->dapm_widgets, list) {
-               if (!strcmp(w->name, endpoint)) {
-                       w->connected = status;
-                       return 0;
-               }
+               if (!strcmp(w->name, pin))
+                       return w->connected;
        }
 
-       return -ENODEV;
+       return 0;
 }
-EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
 
 /**
  * snd_soc_dapm_free - free dapm resources
index 46daca1..dcfc1d5 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
@@ -464,6 +465,8 @@ int soundcore_open(struct inode *inode, struct file *file)
        struct sound_unit *s;
        const struct file_operations *new_fops = NULL;
 
+       lock_kernel ();
+
        chain=unit&0x0F;
        if(chain==4 || chain==5)        /* dsp/audio/dsp16 */
        {
@@ -511,9 +514,11 @@ int soundcore_open(struct inode *inode, struct file *file)
                        file->f_op = fops_get(old_fops);
                }
                fops_put(old_fops);
+               unlock_kernel();
                return err;
        }
        spin_unlock(&sound_loader_lock);
+       unlock_kernel();
        return -ENODEV;
 }
 
index 079e22a..d75deba 100644 (file)
@@ -1,11 +1,17 @@
 # ALSA Sparc drivers
 
-menu "ALSA Sparc devices"
-       depends on SND!=n && SPARC
+menuconfig SND_SPARC
+       bool "Sparc sound devices"
+       depends on SPARC
+       default y
+       help
+         Support for sound devices specific to Sun SPARC architectures.
+
+if SND_SPARC
 
 config SND_SUN_AMD7930
        tristate "Sun AMD7930"
-       depends on SBUS && SND
+       depends on SBUS
        select SND_PCM
        help
          Say Y here to include support for AMD7930 sound device on Sun.
@@ -15,7 +21,6 @@ config SND_SUN_AMD7930
 
 config SND_SUN_CS4231
        tristate "Sun CS4231"
-       depends on SND
        select SND_PCM
        help
          Say Y here to include support for CS4231 sound device on Sun.
@@ -25,7 +30,7 @@ config SND_SUN_CS4231
 
 config SND_SUN_DBRI
        tristate "Sun DBRI"
-       depends on SND && SBUS
+       depends on SBUS
        select SND_PCM
        help
          Say Y here to include support for DBRI sound device on Sun.
@@ -33,4 +38,4 @@ config SND_SUN_DBRI
          To compile this driver as a module, choose M here: the module
          will be called snd-sun-dbri.
 
-endmenu
+endif  # SND_SPARC
index 3d00e07..ee2e1b4 100644 (file)
@@ -2490,7 +2490,7 @@ static void dbri_debug_read(struct snd_info_entry *entry,
 }
 #endif
 
-void __devinit snd_dbri_proc(struct snd_card *card)
+static void __devinit snd_dbri_proc(struct snd_card *card)
 {
        struct snd_dbri *dbri = card->private_data;
        struct snd_info_entry *entry;
index 0d08c29..e6485be 100644 (file)
@@ -1,7 +1,13 @@
 #SPI drivers
 
-menu "SPI devices"
-       depends on SND != n
+menuconfig SND_SPI
+       bool "SPI sound devices"
+       depends on SPI
+       default y
+       help
+         Support for sound devices connected via the SPI bus.
+
+if SND_SPI
 
 config SND_AT73C213
        tristate "Atmel AT73C213 DAC driver"
@@ -28,4 +34,5 @@ config SND_AT73C213_TARGET_BITRATE
 
          Set to 48000 Hz by default.
 
-endmenu
+endif  # SND_SPI
+
index 9351b8a..ffcdc8f 100644 (file)
@@ -1,11 +1,16 @@
 # ALSA USB drivers
 
-menu "USB devices"
-       depends on SND!=n && USB!=n
+menuconfig SND_USB
+       bool "USB sound devices"
+       depends on USB
+       default y
+       help
+         Support for sound devices connected via the USB bus.
+
+if SND_USB && USB
 
 config SND_USB_AUDIO
        tristate "USB Audio/MIDI driver"
-       depends on SND && USB
        select SND_HWDEP
        select SND_RAWMIDI
        select SND_PCM
@@ -18,7 +23,7 @@ config SND_USB_AUDIO
 
 config SND_USB_USX2Y
        tristate "Tascam US-122, US-224 and US-428 USB driver"
-       depends on SND && USB && (X86 || PPC || ALPHA)
+       depends on X86 || PPC || ALPHA
        select SND_HWDEP
        select SND_RAWMIDI
        select SND_PCM
@@ -31,7 +36,6 @@ config SND_USB_USX2Y
 
 config SND_USB_CAIAQ
        tristate "Native Instruments USB audio devices"
-       depends on SND && USB
        select SND_HWDEP
        select SND_RAWMIDI
        select SND_PCM
@@ -63,5 +67,5 @@ config SND_USB_CAIAQ_INPUT
           * Native Instruments Kore Controller 2
           * Native Instruments Audio Kontrol 1
 
-endmenu
+endif  # SND_USB
 
index 24970a5..b3a6033 100644 (file)
@@ -637,6 +637,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
        switch (dev->chip.usb_id) {
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
                dev->samplerates |= SNDRV_PCM_RATE_88200;
                dev->samplerates |= SNDRV_PCM_RATE_192000;
                break;
index a972f77..8317508 100644 (file)
 #endif
 
 MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
-MODULE_DESCRIPTION("caiaq USB audio, version 1.3.6");
+MODULE_DESCRIPTION("caiaq USB audio, version 1.3.8");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
                         "{Native Instruments, RigKontrol3},"
                         "{Native Instruments, Kore Controller},"
                         "{Native Instruments, Kore Controller 2},"
-                        "{Native Instruments, Audio Kontrol 1}"
-                        "{Native Instruments, Audio 8 DJ}}");
+                        "{Native Instruments, Audio Kontrol 1},"
+                        "{Native Instruments, Audio 8 DJ},"
+                        "{Native Instruments, Session I/O}}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
 static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -110,6 +111,11 @@ static struct usb_device_id snd_usb_id_table[] = {
                .idVendor =     USB_VID_NATIVEINSTRUMENTS,
                .idProduct =    USB_PID_AUDIO8DJ
        },
+       {
+               .match_flags =  USB_DEVICE_ID_MATCH_DEVICE,
+               .idVendor =     USB_VID_NATIVEINSTRUMENTS,
+               .idProduct =    USB_PID_SESSIONIO
+       },
        { /* terminator */ }
 };
 
index 96a4913..f9fbdba 100644 (file)
@@ -11,6 +11,7 @@
 #define USB_PID_KORECONTROLLER2        0x4712
 #define USB_PID_AK1            0x0815
 #define USB_PID_AUDIO8DJ       0x1978
+#define USB_PID_SESSIONIO      0x1915
 
 #define EP1_BUFSIZE 64
 #define CAIAQ_USB_STR_LEN 0xff
index 410be4a..b8cfb7c 100644 (file)
@@ -819,10 +819,6 @@ static const char *usb_error_string(int err)
                return "device disabled";
        case -EHOSTUNREACH:
                return "device suspended";
-#ifndef CONFIG_USB_EHCI_SPLIT_ISO
-       case -ENOSYS:
-               return "enable CONFIG_USB_EHCI_SPLIT_ISO to play through a hub";
-#endif
        case -EINVAL:
        case -EAGAIN:
        case -EFBIG:
index 82a8d14..9ea726c 100644 (file)
@@ -210,6 +210,11 @@ YAMAHA_DEVICE(0x1042, NULL),
 YAMAHA_DEVICE(0x1043, NULL),
 YAMAHA_DEVICE(0x1044, NULL),
 YAMAHA_DEVICE(0x1045, NULL),
+YAMAHA_INTERFACE(0x104e, 0, NULL),
+YAMAHA_DEVICE(0x104f, NULL),
+YAMAHA_DEVICE(0x1050, NULL),
+YAMAHA_DEVICE(0x1051, NULL),
+YAMAHA_DEVICE(0x1052, NULL),
 YAMAHA_DEVICE(0x2000, "DGP-7"),
 YAMAHA_DEVICE(0x2001, "DGP-5"),
 YAMAHA_DEVICE(0x2002, NULL),
@@ -1379,6 +1384,39 @@ YAMAHA_DEVICE(0x7010, "UB99"),
        }
 },
 
+{
+       /* Roland SonicCell */
+       USB_DEVICE(0x0582, 0x00c2),
+       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
+               .vendor_name = "Roland",
+               .product_name = "SonicCell",
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_COMPOSITE,
+               .data = (const struct snd_usb_audio_quirk[]) {
+                       {
+                               .ifnum = 0,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       {
+                               .ifnum = 1,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       {
+                               .ifnum = 2,
+                               .type = QUIRK_MIDI_FIXED_ENDPOINT,
+                               .data = & (const struct snd_usb_midi_endpoint_info) {
+                                       .out_cables = 0x0001,
+                                       .in_cables  = 0x0001
+                               }
+                       },
+                       {
+                               .ifnum = -1
+                       }
+               }
+       }
+},
+
+
 /* Guillemot devices */
 {
        /*